Spark DSL extension for defining typed Phoenix channel event subscriptions.
Declares which Ash PubSub publications a channel intercepts. For each declared
event, AshTypescript reads the publication's returns type and generates a
typed TypeScript payload type. An event map and typed subscription helper are
also generated for the channel.
The recommended way to get typed payloads is to use transform :some_calc on
publications, pointing to a resource calculation with :auto typing. Ash
auto-derives the returns type from the calculation expression. You can also
use explicit returns: with an anonymous function transform.
Usage
defmodule MyAppWeb.OrgAdminChannel do
use AshTypescript.TypedChannel
@impl true
def join("org_admin:" <> org_id, _payload, socket) do
{:ok, socket}
end
typed_channel do
resource MyApp.Post do
publish :post_created
publish :post_updated
end
resource MyApp.Comment do
publish :comment_created
end
end
endtyped_channel
Configure typed channel subscriptions from Ash PubSub publications.
Nested DSLs
- resource
- publish
Options
| Name | Type | Default | Docs |
|---|---|---|---|
topic | String.t | The Phoenix channel topic pattern (e.g. "org:*"). |
typed_channel.resource
resource moduleDeclare an Ash resource whose publications this channel subscribes to.
Each publish child declares a specific event to intercept.
Nested DSLs
Arguments
| Name | Type | Default | Docs |
|---|---|---|---|
module | atom | The Ash resource module containing the PubSub publications. |
typed_channel.resource.publish
publish eventDeclare a PubSub event to intercept on this channel.
The event name must match the event option (or action name fallback) of
a publication on the resource. The publication must have a returns type
for TypeScript type generation — either auto-derived via transform :calc
or explicitly set via returns:.
Arguments
| Name | Type | Default | Docs |
|---|---|---|---|
event | atom | String.t | The event name to intercept (atom or string). |
Introspection
Target: AshTypescript.TypedChannel.Dsl.Publication