ExESDB.Commanded.Config (ex_esdb_commanded v0.1.0)

Configuration validation and normalization for ExESDB.Commanded.Adapter.

This module provides standardized configuration handling with proper validation, error handling, and normalization to ensure consistent behavior between Commanded and ExESDB systems.

Summary

Functions

Gets the connection timeout from configuration or environment.

Gets the retry attempts from configuration or environment.

Gets the retry backoff from configuration or environment.

Gets the serializer module from configuration or environment.

Gets the store ID from configuration or environment.

Gets the stream prefix from configuration or environment.

Checks if libcluster should be used for node discovery.

Validates and normalizes configuration for ExESDB.Commanded.Adapter.

Validates libcluster topology configuration.

Validates that the serializer module is available and has required functions.

Types

adapter_config()

@type adapter_config() :: map()

config()

@type config() :: Keyword.t()

Functions

connection_timeout(config)

@spec connection_timeout(config()) :: pos_integer()

Gets the connection timeout from configuration or environment.

retry_attempts(config)

@spec retry_attempts(config()) :: non_neg_integer()

Gets the retry attempts from configuration or environment.

retry_backoff(config)

@spec retry_backoff(config()) :: pos_integer()

Gets the retry backoff from configuration or environment.

serializer(config)

@spec serializer(config()) :: module()

Gets the serializer module from configuration or environment.

store_id(config)

@spec store_id(config()) :: atom()

Gets the store ID from configuration or environment.

stream_prefix(config)

@spec stream_prefix(config()) :: String.t()

Gets the stream prefix from configuration or environment.

Stream prefixes cannot contain dashes to avoid conflicts with ExESDB internal naming conventions.

use_libcluster?(config)

@spec use_libcluster?(config()) :: boolean()

Checks if libcluster should be used for node discovery.

validate(config)

@spec validate(config()) :: {:ok, adapter_config()} | {:error, {atom(), term()}}

Validates and normalizes configuration for ExESDB.Commanded.Adapter.

Options

  • :store_id - ExESDB store identifier (required)
  • :stream_prefix - Prefix for all streams (default: "")
  • :serializer - Serialization module (default: Jason)
  • :use_libcluster - Whether to use libcluster for node discovery (default: true)
  • :connection_timeout - Connection timeout in ms (default: 10_000)
  • :retry_attempts - Number of retry attempts for failed operations (default: 3)
  • :retry_backoff - Backoff interval between retries in ms (default: 1_000)

Examples

iex> ExESDB.Commanded.Config.validate([store_id: :my_store])
{:ok, %{store_id: :my_store, stream_prefix: "", ...}}

iex> ExESDB.Commanded.Config.validate([])
{:error, {:missing_required_config, [:store_id]}}

validate_libcluster_config(config)

@spec validate_libcluster_config(config()) :: {:ok, config()} | {:error, term()}

Validates libcluster topology configuration.

validate_serializer(serializer)

@spec validate_serializer(module()) :: {:ok, module()} | {:error, term()}

Validates that the serializer module is available and has required functions.