AshDispatch.Introspection (AshDispatch v0.5.1)

View Source

Central introspection module for discovering all AshDispatch events.

Provides a unified view of events from both inline DSL (defined in resources) and module-based events (standalone event modules).

Usage

# Get all events in the application
events = AshDispatch.Introspection.all_events(:my_app)

# Get resources with dispatch enabled
resources = AshDispatch.Introspection.dispatch_resources(:my_app)

# Find missing templates
missing = AshDispatch.Introspection.all_missing_templates(:my_app)

Summary

Functions

Returns all events across all dispatch-enabled resources and event modules.

Finds all missing templates for events in the application.

Derives the expected module name for an event.

Returns all resources that have the AshDispatch.Resource extension.

Finds missing event modules for inline DSL events.

Finds missing templates for a specific event.

Calculates required templates for an event based on its channels.

Returns the template directory path for an event.

Types

event_info()

@type event_info() :: %{
  source: :inline | :module,
  event_id: String.t(),
  name: atom() | nil,
  resource: module() | nil,
  module: module() | nil,
  domain: atom() | nil,
  channels: [map()],
  content: map() | nil,
  metadata: map() | nil
}

missing_template()

@type missing_template() :: %{
  event_id: String.t(),
  path: String.t(),
  filename: String.t(),
  format: :html | :text,
  transport: atom(),
  variant: atom() | nil,
  locale: String.t() | nil
}

Functions

all_events(otp_app)

@spec all_events(atom()) :: [event_info()]

Returns all events across all dispatch-enabled resources and event modules.

Combines inline DSL events (from resources) and module-based events into a unified list.

Parameters

  • otp_app - The OTP application name

Returns

List of event info maps with unified structure

all_missing_templates(otp_app)

@spec all_missing_templates(atom()) :: [missing_template()]

Finds all missing templates for events in the application.

Checks inline DSL events for missing template files based on their channel definitions.

Parameters

  • otp_app - The OTP application name

Returns

List of missing template info maps

derive_module_name(event_info, otp_app)

@spec derive_module_name(map(), atom()) :: module()

Derives the expected module name for an event.

Uses otp_app as the module prefix (e.g., :my_app → MyApp) and derives the domain from either the event_info or the resource.

Used by both the generator (to create modules) and the transformer (to auto-connect generated modules).

Parameters

  • event_info - Event info map or struct with :domain, :name, and :resource keys
  • otp_app - The OTP application name (used for module prefix)

Returns

Module name atom (e.g., MyApp.Orders.Events.Created.Event)

dispatch_resources(otp_app)

@spec dispatch_resources(atom()) :: [module()]

Returns all resources that have the AshDispatch.Resource extension.

Parameters

  • otp_app - The OTP application name

Returns

List of resource modules with dispatch enabled

missing_event_modules(otp_app)

@spec missing_event_modules(atom()) :: [map()]

Finds missing event modules for inline DSL events.

Returns modules for ALL events that don't have a user-provided module: option. Generated modules provide:

  • Template directory for email/sms transports
  • Fallback callbacks (recipients, content, etc.)
  • A place to add custom logic later

The system uses a hybrid approach: DSL configuration takes precedence, but the generated module provides fallbacks for anything not specified in DSL.

Parameters

  • otp_app - The OTP application name

Returns

List of missing module info maps

missing_templates(event_info, otp_app)

@spec missing_templates(event_info(), atom()) :: [missing_template()]

Finds missing templates for a specific event.

Parameters

  • event_info - Event info map
  • otp_app - The OTP application name

Returns

List of missing template info maps

required_templates(event_info)

@spec required_templates(event_info()) :: [map()]

Calculates required templates for an event based on its channels.

Parameters

Returns

List of required template specs

template_directory(event_info, otp_app)

@spec template_directory(event_info(), atom()) :: String.t()

Returns the template directory path for an event.

Delegates to AshDispatch.TemplateResolver.resolve_template_directory/2 which is the single source of truth for template path resolution.

Resolution Order

  1. Explicit module: If event has module: option, use module-based path
  2. Derived module: Use {App}.{Domain}.Events.{EventName}.Event path

Events are expected to have modules (either explicit or generated via mix ash_dispatch.gen). Templates live in {module_dir}/templates/.

Parameters

  • event_info - Event info map
  • otp_app - The OTP application name

Returns

Path string to the template directory