Alva.Registry (Alva v0.1.0)

Copy Markdown View Source

Host-app registry boundary for Alva runtime and code generation.

Consolidates introspection across the App, Domain, and Resource levels. Provides cached access to event and signal maps, file upload arguments, and uniqueness verification across domains.

Registry Resolution

The registry is built from the host application's Ash.Info.domains/1. It is cached via :persistent_term in production and rebuilt on every call in dev/test for hot-reload support.

See Alva.Domain for how domains are configured, and Alva.Resource for how events and signals are defined per resource.

Summary

Types

t()

The registry struct holding cached introspection data for a host application.

Functions

Returns the event map for the given domain module by inspecting its resources.

Returns the signal map for the given domain module by inspecting its resources.

Returns the full event name-to-{resource, event} map for the given OTP app.

Returns all Alva.Resource.Event entities defined on the given resource.

Looks up a single event by its string name. Returns {:ok, resource, event} or :error.

Looks up a single signal by its string name. Returns {:ok, resource, signal} or :error.

Collects all file upload arguments from events across the given domain.

Resolves the OTP app name from a socket or endpoint module.

Returns all public field names (attributes, calculations, relationships, aggregates) for the given Ash resource.

Builds or retrieves the cached Alva.Registry struct for the given OTP app. In dev/test the registry is rebuilt on every call; in production it is cached via :persistent_term.

Returns the full signal name-to-{resource, signal} map for the given OTP app.

Returns all Alva.Resource.Signal entities defined on the given resource.

Types

t()

(since 0.1.0)
@type t() :: %Alva.Registry{
  domains: [atom()],
  event_map: %{required(String.t()) => {atom(), Alva.Resource.Event.t()}},
  file_upload_arguments: [term()],
  otp_app: atom() | nil,
  signal_map: %{required(String.t()) => {atom(), Alva.Resource.Signal.t()}}
}

The registry struct holding cached introspection data for a host application.

Functions

alva_event_map(domain)

(since 0.1.0)
@spec alva_event_map(atom()) :: %{
  required(String.t()) => {atom(), Alva.Resource.Event.t()}
}

Returns the event map for the given domain module by inspecting its resources.

alva_signal_map(domain)

(since 0.1.0)
@spec alva_signal_map(atom()) :: %{
  required(String.t()) => {atom(), Alva.Resource.Signal.t()}
}

Returns the signal map for the given domain module by inspecting its resources.

event_map(otp_app)

(since 0.1.0)
@spec event_map(atom()) :: %{
  required(String.t()) => {atom(), Alva.Resource.Event.t()}
}

Returns the full event name-to-{resource, event} map for the given OTP app.

events(resource)

(since 0.1.0)
@spec events(atom()) :: [Alva.Resource.Event.t()]

Returns all Alva.Resource.Event entities defined on the given resource.

fetch_event(otp_app, event_name)

(since 0.1.0)
@spec fetch_event(atom(), String.t()) ::
  {:ok, atom(), Alva.Resource.Event.t()} | :error

Looks up a single event by its string name. Returns {:ok, resource, event} or :error.

fetch_signal(otp_app, signal_name)

(since 0.1.0)
@spec fetch_signal(atom(), String.t()) ::
  {:ok, atom(), Alva.Resource.Signal.t()} | :error

Looks up a single signal by its string name. Returns {:ok, resource, signal} or :error.

file_upload_arguments(domain)

(since 0.1.0)

Collects all file upload arguments from events across the given domain.

otp_app(endpoint)

(since 0.1.0)

Resolves the OTP app name from a socket or endpoint module.

public_fields(resource)

(since 0.1.0)
@spec public_fields(atom()) :: [atom()]

Returns all public field names (attributes, calculations, relationships, aggregates) for the given Ash resource.

registry(otp_app)

(since 0.1.0)
@spec registry(atom()) :: t()

Builds or retrieves the cached Alva.Registry struct for the given OTP app. In dev/test the registry is rebuilt on every call; in production it is cached via :persistent_term.

signal_map(otp_app)

(since 0.1.0)
@spec signal_map(atom()) :: %{
  required(String.t()) => {atom(), Alva.Resource.Signal.t()}
}

Returns the full signal name-to-{resource, signal} map for the given OTP app.

signals(resource)

(since 0.1.0)
@spec signals(atom()) :: [Alva.Resource.Signal.t()]

Returns all Alva.Resource.Signal entities defined on the given resource.

verify_host_app_command_uniqueness!(current_domain, current_event_map)

(since 0.1.0)

verify_host_app_signal_uniqueness!(current_domain, current_signal_map)

(since 0.1.0)