AshTypescript.TypedChannel.Interception (ash_typescript v0.18.1)

Copy Markdown View Source

Compile-time injection of Phoenix channel event interception for typed channels.

use AshTypescript.TypedChannel arranges (via Spark's handle_before_compile/1) for inject/0 to expand in the channel module right before compilation. When the module is also a Phoenix.Channel, the injected code registers every declared typed-channel event as an intercepted event and defines handle_out/3 clauses that format the broadcast payload through AshTypescript.TypedChannel.PayloadFormatter before pushing — so the wire format matches the generated TypeScript payload types.

Events the module already handles with its own handle_out/3 clause are left alone — the developer's clause owns the push for those events.

When the module is not a Phoenix.Channel, a compile warning is emitted instead: the typed channel DSL only has meaning for the module that actually serves the channel topic.

Interception disables Phoenix's fastlane for the declared events (payloads are encoded per subscriber instead of once per broadcast) — the standard cost of Phoenix.Channel.intercept/1.