actions/action_types.ts

Shared type surface for the action system — context, handler, composable Action tuple.

These types sit above actions/action_spec.ts (pure Zod schemas) and below the dispatchers (actions/register_action_ws.ts, actions/action_rpc.ts). Extracted so the shared protocol actions (e.g. heartbeat_action) can name them without pulling in server-only modules.

Declarations
#

3 declarations

view source

Action
#

actions/action_types.ts view source

Action<TCtx>

A spec paired with its optional handler — the composable unit passed to register_action_ws and create_rpc_client. The server uses both fields; the client reads only spec (the handler is ignored, harmless). Shared fuz_app primitives (e.g. heartbeat_action) export a complete tuple so consumers spread them into both sides' actions array without inventing per-repo ping plumbing.

Left open for future fields (rate_limit, ACL, middleware hooks) so additions attach to the action itself instead of scattering across parallel arrays.

generics

TCtx

spec

handler

Server-side handler. Ignored by the client. Omit for client-only specs.

type WsActionHandler<TCtx>

BaseHandlerContext
#

actions/action_types.ts view source

BaseHandlerContext

Minimum per-request context every server-side WS handler receives.

Consumers extend this with domain-specific fields via the dispatcher's extend_context option. Mirrors the HTTP-side ActionContext and Rust's Ctx<'a> shape (request_id + NotifyFn + CancellationToken).

request_id

JSON-RPC envelope request id — echoed back on the response.

connection_id

Stable per-socket connection id assigned by BackendWebsocketTransport.add_connection — same reference across every message on this socket, also passed to on_socket_open / on_socket_close. Consumers key per-connection domain state on this directly instead of trying to derive it from signals (which are per-message composites of AbortSignal.any([socket, request])).

type Uuid

notify

Send a request-scoped JSON-RPC notification to the originating socket. Not a broadcast — the message only reaches the client whose request triggered this handler.

type (method: string, params: unknown) => void

signal

Fires on socket close OR on a client-initiated cancel notification matching this request's id. Streaming handlers poll for early termination; per-message composite (AbortSignal.any([socket, request])) — not stable across messages.

type AbortSignal

WsActionHandler
#