Packages
ash_typescript
0.17.2
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.3
0.15.2
retired
0.15.1
retired
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
retired
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.0
0.3.3
0.3.2
0.3.1
0.2.0
0.1.2
0.1.0
Generate type-safe TypeScript clients directly from your Ash resources and actions, ensuring end-to-end type safety between your backend and frontend.
Current section
Files
Jump to
Current section
Files
documentation/dsls/DSL-AshTypescript.TypedChannel.md
<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshTypescript.TypedChannel
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
end
## typed_channel
Configure typed channel subscriptions from Ash PubSub publications.
### Nested DSLs
* [resource](#typed_channel-resource)
* publish
### Options
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`topic`](#typed_channel-topic){: #typed_channel-topic .spark-required} | `String.t` | | The Phoenix channel topic pattern (e.g. "org:*"). |
### typed_channel.resource
```elixir
resource module
```
Declare an Ash resource whose publications this channel subscribes to.
Each `publish` child declares a specific event to intercept.
### Nested DSLs
* [publish](#typed_channel-resource-publish)
### Arguments
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`module`](#typed_channel-resource-module){: #typed_channel-resource-module .spark-required} | `atom` | | The Ash resource module containing the PubSub publications. |
### typed_channel.resource.publish
```elixir
publish event
```
Declare 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`](#typed_channel-resource-publish-event){: #typed_channel-resource-publish-event .spark-required} | `atom \| String.t` | | The event name to intercept (atom or string). |
### Introspection
Target: `AshTypescript.TypedChannel.Dsl.Publication`
### Introspection
Target: `AshTypescript.TypedChannel.Dsl.ChannelResource`
<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>