Foundation.Config (foundation v0.1.0)

Public API for configuration management.

Thin wrapper around ConfigServer that provides a clean, documented interface. All business logic is delegated to the service layer.

Summary

Functions

Check if the configuration service is available.

Get the complete configuration.

Get a configuration value by path.

Get configuration with a default value if path doesn't exist.

Initialize the configuration service.

Initialize the configuration service with options.

Reset configuration to defaults.

Update configuration if the path is updatable, otherwise return error.

Get configuration service status.

Subscribe to configuration change notifications.

Unsubscribe from configuration change notifications.

Get the list of paths that can be updated at runtime.

Update a configuration value at the given path.

Validate a configuration structure.

Types

config_path()

@type config_path() :: [atom()]

config_value()

@type config_value() :: term()

Functions

available?()

@spec available?() :: boolean()

Check if the configuration service is available.

Examples

iex> Foundation.Config.available?()
true

get()

@spec get() :: {:ok, Foundation.Types.Config.t()} | {:error, Foundation.Error.t()}

Get the complete configuration.

Examples

iex> Foundation.Config.get()
{:ok, %Config{...}}

get(path)

@spec get(config_path()) :: {:ok, config_value()} | {:error, Foundation.Error.t()}

Get a configuration value by path.

Examples

iex> Foundation.Config.get([:ai, :provider])
{:ok, :openai}

iex> Foundation.Config.get([:nonexistent, :path])
{:error, %Error{error_type: :config_path_not_found}}

get_with_default(path, default)

@spec get_with_default(config_path(), config_value()) :: config_value()

Get configuration with a default value if path doesn't exist.

Examples

iex> Foundation.Config.get_with_default([:ai, :timeout], 30_000)
30_000

initialize()

@spec initialize() :: :ok | {:error, Foundation.Error.t()}

Initialize the configuration service.

Examples

iex> Foundation.Config.initialize()
:ok

initialize(opts)

@spec initialize(keyword()) :: :ok | {:error, Foundation.Error.t()}

Initialize the configuration service with options.

Examples

iex> Foundation.Config.initialize(cache_size: 1000)
:ok

reset()

@spec reset() :: :ok | {:error, Foundation.Error.t()}

Reset configuration to defaults.

Examples

iex> Foundation.Config.reset()
:ok

safe_update(path, value)

@spec safe_update(config_path(), config_value()) ::
  :ok | {:error, Foundation.Error.t()}

Update configuration if the path is updatable, otherwise return error.

Convenience function that checks updatable paths before attempting update.

Examples

iex> Foundation.Config.safe_update([:dev, :debug_mode], true)
:ok

status()

@spec status() :: {:ok, map()} | {:error, Foundation.Error.t()}

Get configuration service status.

Examples

iex> Foundation.Config.status()
{:ok, %{status: :running, uptime: 12345}}

subscribe()

@spec subscribe() :: :ok | {:error, Foundation.Error.t()}

Subscribe to configuration change notifications.

The calling process will receive messages of the form: {:config_notification, {:config_updated, path, new_value}}

Examples

iex> Foundation.Config.subscribe()
:ok

unsubscribe()

@spec unsubscribe() :: :ok

Unsubscribe from configuration change notifications.

Examples

iex> Foundation.Config.unsubscribe()
:ok

updatable_paths()

@spec updatable_paths() :: [[atom(), ...], ...]

Get the list of paths that can be updated at runtime.

Examples

iex> Foundation.Config.updatable_paths()
[
  [:ai, :planning, :sampling_rate],
  [:dev, :debug_mode],
  ...
]

update(path, value)

@spec update(config_path(), config_value()) :: :ok | {:error, Foundation.Error.t()}

Update a configuration value at the given path.

Only paths returned by updatable_paths/0 can be updated at runtime.

Examples

iex> Foundation.Config.update([:dev, :debug_mode], true)
:ok

iex> Foundation.Config.update([:ai, :provider], :anthropic)
{:error, %Error{error_type: :config_update_forbidden}}

validate(config)

@spec validate(Foundation.Types.Config.t()) :: :ok | {:error, Foundation.Error.t()}

Validate a configuration structure.

Examples

iex> config = %Config{ai: %{provider: :invalid}}
iex> Foundation.Config.validate(config)
{:error, %Error{error_type: :invalid_config_value}}