Generates TypeScript types and functions for typed channel event subscriptions.
For each declared event in a typed channel module, introspects the matching
Ash PubSub publication's returns type (auto-derived via transform :calc
or explicitly set) and maps it to a TypeScript type.
Generated Output
Types (emitted into ash_types.ts):
// Branded channel type — only creatable via createOrgChannel
export type OrgChannel = {
readonly __channelType: "OrgChannel";
on(event: string, callback: (payload: unknown) => void): number;
off(event: string, ref: number): void;
};
// Payload types
export type ItemCreatedPayload = string;
// Events map
export type OrgChannelEvents = { item_created: ItemCreatedPayload; };
// Utility types for onOrgChannelMessages / unsubscribeOrgChannel
export type OrgChannelHandlers = { ... };
export type OrgChannelRefs = { ... };Functions (emitted into the typed channels output file, e.g. ash_typed_channels.ts):
// Factory — the only way to obtain an OrgChannel
export function createOrgChannel(socket, suffix: string): OrgChannel { ... }
// Single-event subscription
export function onOrgChannelMessage<E extends keyof OrgChannelEvents>(
channel: OrgChannel, event: E, handler: ...
): number { ... }
// Multi-event subscription
export function onOrgChannelMessages(channel: OrgChannel, handlers: OrgChannelHandlers): OrgChannelRefs { ... }
// Cleanup
export function unsubscribeOrgChannel(channel: OrgChannel, refs: OrgChannelRefs): void { ... }
Summary
Functions
Generates TypeScript subscription helper functions for all configured typed channel modules.
Generates TypeScript type declarations for all configured typed channel modules.
Generates TypeScript subscription helper functions for a single typed channel module.
Generates TypeScript type declarations for a single typed channel module.
Functions
Generates TypeScript subscription helper functions for all configured typed channel modules.
Accepts a list of {module, topic} tuples. Emits, per channel:
createOrgChannelfactory (uses the topic pattern to construct the Phoenix topic string)onOrgChannelMessagesingle-event subscriptiononOrgChannelMessagesmulti-event subscriptionunsubscribeOrgChannelcleanup
Returns only the function bodies without import statements. The caller is
responsible for prepending imports from ash_types.ts.
Generates TypeScript type declarations for all configured typed channel modules.
Accepts a list of {module, topic} tuples. The topic (e.g. "org:*") is used
to generate a branded OrgChannel type that prevents mixing channel instances.
Emits:
- Deduplicated payload type aliases
- Per-channel branded type, events map, handlers type, and refs type
Subscription helper functions are NOT included — use generate_all_channel_functions/1.
Generates TypeScript subscription helper functions for a single typed channel module.
The optional topic causes a create* factory to be emitted and function
signatures to use the branded channel type instead of a structural type.
Generates TypeScript type declarations for a single typed channel module.
The optional topic (e.g. "org:*") causes a branded OrgChannel type to be
emitted. Without a topic only payload aliases, the events map, and utility types
are emitted — useful for isolated unit tests.