PhoenixMicro.Schema.Registry (PhoenixMicro v1.0.0)

Copy Markdown View Source

ETS-backed registry mapping topic names to their schema modules.

Schemas self-register via @after_compile hooks when you use PhoenixMicro.Schema. You can also register programmatically:

PhoenixMicro.Schema.Registry.register(MyApp.Events.PaymentCreated)

The registry stores multiple versions per topic so you can query the history:

PhoenixMicro.Schema.Registry.versions("payments.created")
# => [{1, MyApp.Events.PaymentCreatedV1}, {2, MyApp.Events.PaymentCreated}]

Summary

Functions

Returns all registered schema modules (deduplicated).

Returns a specification to start this module under a supervisor.

Removes all entries (useful in tests).

Returns the latest-version schema module for a topic. Returns {:error, :not_found} if no schema is registered.

Registers a schema module under its declared topic and version. Safe to call multiple times (idempotent).

Returns all registered {version, module} pairs for a topic, oldest first.

Functions

all()

@spec all() :: [module()]

Returns all registered schema modules (deduplicated).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

@spec clear() :: :ok

Removes all entries (useful in tests).

lookup(topic)

@spec lookup(String.t()) :: {:ok, module()} | {:error, :not_found}

Returns the latest-version schema module for a topic. Returns {:error, :not_found} if no schema is registered.

register(schema_module)

@spec register(module()) :: :ok

Registers a schema module under its declared topic and version. Safe to call multiple times (idempotent).

start_link(opts \\ [])

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

versions(topic)

@spec versions(String.t()) :: [{pos_integer(), module()}]

Returns all registered {version, module} pairs for a topic, oldest first.