ExESDB.Config (ex_esdb v0.1.0)

Configuration validation and normalization for ExESDB.

This module provides standardized configuration handling with proper validation, error handling, and normalization to ensure consistent behavior across the system.

Summary

Functions

Gets the data directory from configuration or environment.

Gets the database type from configuration or environment.

Gets the PubSub configuration from configuration or environment.

Gets the reader idle timeout from configuration or environment.

Gets the store ID from configuration or environment.

Gets the timeout from configuration or environment.

Checks if libcluster should be used for node discovery.

Validates and normalizes configuration for ExESDB.

Validates libcluster topology configuration.

Gets the writer idle timeout from configuration or environment.

Types

config()

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

data_dir()

@type data_dir() :: String.t()

db_type()

@type db_type() :: :single | :cluster

idle_ms()

@type idle_ms() :: non_neg_integer()

pub_sub()

@type pub_sub() :: atom()

store_id()

@type store_id() :: atom()

time_out()

@type time_out() :: non_neg_integer()

Functions

data_dir(config)

@spec data_dir(config()) :: data_dir()

Gets the data directory from configuration or environment.

db_type(config)

@spec db_type(config()) :: db_type()

Gets the database type from configuration or environment.

pub_sub(config)

@spec pub_sub(config()) :: pub_sub()

Gets the PubSub configuration from configuration or environment.

reader_idle_ms(config)

@spec reader_idle_ms(config()) :: idle_ms()

Gets the reader idle timeout from configuration or environment.

store_id(config)

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

Gets the store ID from configuration or environment.

timeout(config)

@spec timeout(config()) :: time_out()

Gets the timeout from configuration or environment.

use_libcluster?(config)

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

Checks if libcluster should be used for node discovery.

validate(config)

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

Validates and normalizes configuration for ExESDB.

Options

  • :store_id - Unique identifier for the store (required)
  • :data_dir - Directory for data storage (required)
  • :timeout - Operation timeout in milliseconds (default: 10_000)
  • :db_type - Database type :single or :cluster (default: :single)
  • :pub_sub - PubSub mechanism identifier (default: :native)
  • :writer_idle_ms - Writer idle timeout in milliseconds (default: 10_000)
  • :reader_idle_ms - Reader idle timeout in milliseconds (default: 10_000)
  • :use_libcluster - Whether to use libcluster for node discovery (default: true)

Examples

iex> ExESDB.Config.validate([store_id: :my_store, data_dir: "/tmp/data"])
{:ok, %{store_id: :my_store, data_dir: "/tmp/data", timeout: 10_000, ...}}

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

validate_libcluster_config(config)

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

Validates libcluster topology configuration.

writer_idle_ms(config)

@spec writer_idle_ms(config()) :: idle_ms()

Gets the writer idle timeout from configuration or environment.