Synapse.Signal.Registry (Synapse v0.1.1)

View Source

Runtime registry for signal topics and their schemas.

Topics can be declared via application configuration or registered at runtime. An ETS backend provides fast concurrent reads while validations run inside the GenServer process.

Summary

Types

Canonical signal topic

Normalized topic configuration stored in ETS

Functions

Returns a specification to start this module under a supervisor.

Retrieves the stored configuration for a topic.

Lists all registered topics.

Registers a new topic backed by the provided config.

Starts the registry.

Resolves a wire-format type to the registered topic.

Resolves a topic atom to its wire-format type.

Validates a payload against the topic schema and returns the normalized map.

Types

topic()

@type topic() :: atom()

Canonical signal topic

topic_config()

@type topic_config() :: %{
  type: String.t(),
  schema: NimbleOptions.t() | nil,
  raw_schema: keyword() | module() | nil,
  validator: (map() -> map())
}

Normalized topic configuration stored in ETS

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_topic(registry \\ __MODULE__, topic)

@spec get_topic(atom() | pid(), topic()) :: {:ok, topic_config()} | {:error, term()}

Retrieves the stored configuration for a topic.

list_topics(registry \\ __MODULE__)

@spec list_topics(atom() | pid()) :: [topic()]

Lists all registered topics.

register_topic(registry \\ __MODULE__, topic, config)

@spec register_topic(atom() | pid(), topic(), map() | keyword()) ::
  :ok | {:error, term()}

Registers a new topic backed by the provided config.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the registry.

Options:

  • :name - Registry name (defaults to Synapse.Signal.Registry)
  • :topics - Topics to preload instead of application config
  • :domains - Domains to auto-register during startup (defaults to config :synapse, :domains)

topic_from_type(registry \\ __MODULE__, type)

@spec topic_from_type(atom() | pid(), String.t()) :: {:ok, topic()} | :error

Resolves a wire-format type to the registered topic.

type(registry \\ __MODULE__, topic)

@spec type(atom() | pid(), topic()) :: String.t()

Resolves a topic atom to its wire-format type.

unregister_topic(registry \\ __MODULE__, topic)

@spec unregister_topic(atom() | pid(), topic()) :: :ok | {:error, term()}

Unregisters a topic.

validate!(registry \\ __MODULE__, topic, payload)

@spec validate!(atom() | pid(), topic(), map()) :: map()

Validates a payload against the topic schema and returns the normalized map.

Raises KeyError for unknown topics and ArgumentError on validation errors.