WalEx.Config (WalEx v4.8.0)

Copy Markdown View Source

Per-app configuration store backed by Agent.

Each WalEx instance is identified by :name and keeps its config (database credentials, publication, subscriptions, modules, slot settings, etc.) under a registered agent so it can be read by replication processes and updated at runtime via add_config/3, remove_config/3, and replace_config/3.

Summary

Functions

Appends one or more values to a multi-valued config key (:modules or :subscriptions). Duplicates are removed.

Resolves the event-handler modules for an app: combines explicit :modules with the convention-derived modules for each subscription, deduplicates, and keeps only those that actually compile.

Returns a specification to start this module under a supervisor.

Reads stored config for an app.

Shortcut for get_configs(app_name, :database).

Shortcut for get_configs(app_name, :modules).

Returns true if configs is a keyword list with a non-nil entry for key.

Maps each subscription name to its conventional <App>.Events.<Subscription> module atom.

Removes a value from a multi-valued config key (:modules or :subscriptions).

Replaces a single-valued config key (e.g. :password, :hostname, :publication).

Starts the per-app config agent. Expects opts[:configs] to contain a keyword list of user configuration; the agent is registered under the app name.

Converts snake_case (or already-cased) names into CamelCase module-name fragments.

Types

start_opts()

@type start_opts() :: [
  database: binary(),
  hostname: binary(),
  name: binary(),
  password: binary(),
  port: binary(),
  publication: binary(),
  username: binary(),
  webhook_signing_secret: binary(),
  slot_name: binary(),
  durable_slot: boolean(),
  message_middleware: (term(), term() -> :ok),
  event_relay: keyword(),
  modules: [module()],
  subscriptions: [binary()]
]

Functions

add_config(app_name, key, new_values)

Appends one or more values to a multi-valued config key (:modules or :subscriptions). Duplicates are removed.

build_module_names(name, modules, subscriptions)

Resolves the event-handler modules for an app: combines explicit :modules with the convention-derived modules for each subscription, deduplicates, and keeps only those that actually compile.

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_configs(app_name)

Reads stored config for an app.

With one argument returns the full keyword list. With a key atom returns that single value. With a list of keys returns a keyword list of those entries in the requested order.

get_configs(app_name, key)

get_database(app_name)

Shortcut for get_configs(app_name, :database).

get_event_modules(app_name)

Shortcut for get_configs(app_name, :modules).

has_config?(configs, key)

Returns true if configs is a keyword list with a non-nil entry for key.

map_subscriptions_to_modules(subscriptions, name)

Maps each subscription name to its conventional <App>.Events.<Subscription> module atom.

remove_config(app_name, key, new_value)

Removes a value from a multi-valued config key (:modules or :subscriptions).

replace_config(app_name, key, new_value)

Replaces a single-valued config key (e.g. :password, :hostname, :publication).

start_link(opts)

@spec start_link(opts :: start_opts()) :: Agent.on_start()

Starts the per-app config agent. Expects opts[:configs] to contain a keyword list of user configuration; the agent is registered under the app name.

to_module_name(module_name)

Converts snake_case (or already-cased) names into CamelCase module-name fragments.