AshDispatch.ChannelResolver (AshDispatch v0.5.1)

View Source

Centralized channel resolution for AshDispatch events.

Handles the logic for determining which channels an event should dispatch to, with consistent priority rules across all parts of the system.

Priority Rules

Currently: DSL channels take precedence over module callback channels.

  1. If DSL channels are defined (via dispatch DSL on resources), use those
  2. Otherwise, fall back to channels/1 callback on the event module

This can be changed in the future to merge both sources if needed.

Usage

# With event config from DSL introspection
channels = ChannelResolver.resolve(event_id, event_module, context,
  dsl_channels: event_config.channels
)

# Without pre-loaded DSL channels (will look them up)
channels = ChannelResolver.resolve(event_id, event_module, context)

# Just check if event has email channels
has_email? = ChannelResolver.has_transport?(event_id, event_module, context, :email)

Summary

Functions

Get channels from DSL configuration only.

Get channels from event module callback only.

Check if an event has channels of a specific transport type.

Convert various channel formats to a Channel struct.

Functions

get_dsl_channels(event_id, opts)

@spec get_dsl_channels(
  String.t() | nil,
  keyword()
) :: [AshDispatch.Channel.t()]

Get channels from DSL configuration only.

Looks up channels defined via the dispatch DSL on resources.

get_module_channels(event_module, context)

@spec get_module_channels(module() | nil, AshDispatch.Context.t()) :: [
  AshDispatch.Channel.t()
]

Get channels from event module callback only.

Calls the channels/1 callback on the event module if it exists.

has_transport?(event_id, event_module, context, transport, opts \\ [])

@spec has_transport?(
  String.t() | nil,
  module() | nil,
  AshDispatch.Context.t(),
  atom(),
  keyword()
) ::
  boolean()

Check if an event has channels of a specific transport type.

Useful for filtering events to only those with email channels, etc.

resolve(event_id, event_module, context, opts \\ [])

@spec resolve(String.t() | nil, module() | nil, AshDispatch.Context.t(), keyword()) ::
  [
    AshDispatch.Channel.t()
  ]

Resolve channels for an event.

Options

  • :dsl_channels - Pre-loaded DSL channel configs (avoids lookup)
  • :strategy - Resolution strategy: :dsl_first (default) or :merge

Returns

List of %AshDispatch.Channel{} structs.

to_channel_struct(channel)

@spec to_channel_struct(term()) :: AshDispatch.Channel.t()

Convert various channel formats to a Channel struct.

Handles:

  • %AshDispatch.Channel{} - returned as-is
  • %AshDispatch.Dsl.Channel{} - converted to runtime Channel
  • Maps with channel fields
  • Keyword lists with channel fields