AshTypescript.TypedChannel.PayloadFormatter (ash_typescript v0.18.1)

Copy Markdown View Source

Formats typed channel payloads at the websocket boundary.

Ash PubSub broadcasts carry the publication's transform result verbatim (snake_case atom keys), while the generated TypeScript payload types use the configured output_field_formatter — so without intervention the types would not match the wire for multi-word fields.

The interception code injected by use AshTypescript.TypedChannel (see AshTypescript.TypedChannel.Interception) routes intercepted events through this module, which formats the payload with the same type-driven ValueFormatter the RPC pipeline uses before pushing to the client.

Summary

Functions

Formats a broadcast payload for the client using the publication's returns type and the configured output_field_formatter.

Formats payload according to the publication's returns type and pushes it to the socket under event.

Functions

format_payload(resource, event, payload)

@spec format_payload(module(), String.t(), term()) :: term()

Formats a broadcast payload for the client using the publication's returns type and the configured output_field_formatter.

Returns the payload unchanged when the resource has no publication matching event or the publication declares no returns type.

push_formatted(socket, resource, event, payload)

@spec push_formatted(Phoenix.Socket.t(), module(), String.t(), term()) :: :ok

Formats payload according to the publication's returns type and pushes it to the socket under event.