AshDispatch.ChannelResolver (AshDispatch v0.5.1)
View SourceCentralized 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.
- If DSL channels are defined (via
dispatchDSL on resources), use those - Otherwise, fall back to
channels/1callback 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.
Resolve channels for an event.
Convert various channel formats to a Channel struct.
Functions
@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.
@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.
@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.
@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.
@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