actions/ws_endpoint_spec.ts

WsEndpointSpec — the canonical WebSocket endpoint declaration consumed by create_app_server's ws_endpoints option (mirror of RpcEndpointSpec for HTTP RPC).

Also resolve_ws_endpoints, which fills in the server's allowed_origins and, for a spec that omits them, the actions of the sole RPC endpoint.

Lives in its own module so both server/app_server.ts (which mounts endpoints from these specs) and http/surface.ts (which threads the resolved spec list into surface generation) can import it without a cycle between the two.

view source

Declarations
#

4 declarations

resolve_ws_endpoints
#

actions/ws_endpoint_spec.ts view source

(ws_endpoints: readonly WsEndpointSpec[] | undefined, options: ResolveWsEndpointsOptions): ResolvedWsEndpointSpec[] | undefined import {resolve_ws_endpoints} from '@fuzdev/fuz_app/actions/ws_endpoint_spec.js';

Fill in each WS endpoint spec's omitted allowed_origins (the server's) and actions (the sole RPC endpoint's, through to_ws_actions), so every consumer of the resolved list — the mount, the surface — reads the effective values.

ws_endpoints

the resolved ws_endpoints option

type readonly WsEndpointSpec[] | undefined

options

the server's allowlist and RPC endpoints, the defaults

returns

ResolvedWsEndpointSpec[] | undefined

the specs, each with allowed_origins and actions set

throws

  • Error - when a spec omits `actions` and `rpc_endpoints` does not hold exactly one endpoint — there is no single action set to serve

ResolvedWsEndpointSpec
#

actions/ws_endpoint_spec.ts view source

ResolvedWsEndpointSpec

type WsEndpointSpec & { allowed_origins: readonly RegExp[]; actions: readonly Action<ActionSpecUnion>[]; }

import type {ResolvedWsEndpointSpec} from '@fuzdev/fuz_app/actions/ws_endpoint_spec.js';

A WsEndpointSpec with allowed_origins and actions resolved — its own, or the server's.

path

Hono mount path (e.g. /api/ws).

type string

allowed_origins

Origin allowlist regexes for the upgrade — passed straight to verify_request_source. Defaults to the server's AppServerOptions.allowed_origins, the list the HTTP routes check. Set it only to narrow one endpoint: the auth middleware's origin check runs on the upgrade too, so a request reaches the endpoint only when its origin passes both lists. An empty list throws at assembly.

type readonly RegExp[]

actions

The actions registered on this endpoint. Spread protocol_actions from actions/protocol.ts first to complete the disconnect-detection + per-request cancel pairing with the frontend client.

Omit to serve the actions of the server's sole rpc_endpoints entry — to_ws_actions of its list, the protocol actions first — so one action set (one set of handler closures) runs on both transports. Assembly throws when it is omitted and the server resolves no RPC endpoint or more than one.

type readonly Action<ActionSpecUnion>[]

required_roles?

Roles permitted to upgrade — any-of disjunction, global grants only. Omit (or pass []) to skip the upgrade-time role gate; per-action auth on each spec still applies at dispatch time via perform_action. Pass [ROLE_ADMIN] for an admin-only WS endpoint. Held for the socket's life — see register_action_ws's required_roles.

type readonly string[]

registry?

Existing registry to register connections with. Auto-created when omitted. Either way the mounted registry is reachable on AppServer.ws_endpoints[path] for broadcast / fan-out.

type ConnectionRegistry

max_connections_per_account?

Per-account connection cap for the auto-created registry. See RegisterActionWsOptions.max_connections_per_account — rejected alongside registry, which carries its own cap.

type number | null

default DEFAULT_MAX_CONNECTIONS_PER_ACCOUNT

outbound_queue_bytes?

Byte budget of the frames waiting to be written to one connection, for the auto-created registry. See RegisterActionWsOptions.outbound_queue_bytes — rejected alongside registry, which carries its own budget.

type number

default DEFAULT_WS_OUTBOUND_QUEUE_BYTES

receive_timeout?

Receive silence (ms) past which the server closes a socket with WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT; null keeps silent sockets open. See RegisterActionWsOptions.receive_timeout.

type number | null

default DEFAULT_WS_RECEIVE_TIMEOUT

max_message_bytes?

Cap on one inbound message, in bytes. See RegisterActionWsOptions.max_message_bytes.

type number

default DEFAULT_WS_MAX_MESSAGE_BYTES

on_socket_open?

Called once per socket after the connection is admitted — registered and its credential re-checked — and before the first message dispatches. See RegisterActionWsOptions.on_socket_open.

type (ctx: SocketOpenContext): void | Promise<void>

ctx

returns void | Promise<void>

on_socket_close?

Called once per admitted socket on close, after registry.remove_connection. See RegisterActionWsOptions.on_socket_close.

type (ctx: SocketCloseContext): void | Promise<void>

ctx

returns void | Promise<void>

ResolveWsEndpointsOptions
#

actions/ws_endpoint_spec.ts view source

ResolveWsEndpointsOptions import type {ResolveWsEndpointsOptions} from '@fuzdev/fuz_app/actions/ws_endpoint_spec.js';

What resolve_ws_endpoints fills a spec's omitted fields from.

allowed_origins

The server's allowlist, the default allowed_origins.

type readonly RegExp[]

rpc_endpoints

The server's resolved RPC endpoints — a spec that omits actions serves the sole entry's, through to_ws_actions.

type readonly RpcEndpointSpec[] | undefined

WsEndpointSpec
#

actions/ws_endpoint_spec.ts view source

WsEndpointSpec import type {WsEndpointSpec} from '@fuzdev/fuz_app/actions/ws_endpoint_spec.js';

Declarative description of a WebSocket endpoint to be auto-mounted by create_app_server.

Single source of truth for mount + surface — the same array drives register_action_ws upgrade wiring AND the surface.ws_endpoints slot emitted into AppSurface, so consumers cannot drift their declared actions from what dispatch actually serves.

path

Hono mount path (e.g. /api/ws).

type string

allowed_origins?

Origin allowlist regexes for the upgrade — passed straight to verify_request_source. Defaults to the server's AppServerOptions.allowed_origins, the list the HTTP routes check. Set it only to narrow one endpoint: the auth middleware's origin check runs on the upgrade too, so a request reaches the endpoint only when its origin passes both lists. An empty list throws at assembly.

type readonly RegExp[]

actions?

The actions registered on this endpoint. Spread protocol_actions from actions/protocol.ts first to complete the disconnect-detection + per-request cancel pairing with the frontend client.

Omit to serve the actions of the server's sole rpc_endpoints entry — to_ws_actions of its list, the protocol actions first — so one action set (one set of handler closures) runs on both transports. Assembly throws when it is omitted and the server resolves no RPC endpoint or more than one.

type readonly Action<ActionSpecUnion>[]

required_roles?

Roles permitted to upgrade — any-of disjunction, global grants only. Omit (or pass []) to skip the upgrade-time role gate; per-action auth on each spec still applies at dispatch time via perform_action. Pass [ROLE_ADMIN] for an admin-only WS endpoint. Held for the socket's life — see register_action_ws's required_roles.

type readonly string[]

registry?

Existing registry to register connections with. Auto-created when omitted. Either way the mounted registry is reachable on AppServer.ws_endpoints[path] for broadcast / fan-out.

type ConnectionRegistry

max_connections_per_account?

Per-account connection cap for the auto-created registry. See RegisterActionWsOptions.max_connections_per_account — rejected alongside registry, which carries its own cap.

type number | null

default DEFAULT_MAX_CONNECTIONS_PER_ACCOUNT

outbound_queue_bytes?

Byte budget of the frames waiting to be written to one connection, for the auto-created registry. See RegisterActionWsOptions.outbound_queue_bytes — rejected alongside registry, which carries its own budget.

type number

default DEFAULT_WS_OUTBOUND_QUEUE_BYTES

receive_timeout?

Receive silence (ms) past which the server closes a socket with WS_CLOSE_SERVER_HEARTBEAT_TIMEOUT; null keeps silent sockets open. See RegisterActionWsOptions.receive_timeout.

type number | null

default DEFAULT_WS_RECEIVE_TIMEOUT

max_message_bytes?

Cap on one inbound message, in bytes. See RegisterActionWsOptions.max_message_bytes.

type number

default DEFAULT_WS_MAX_MESSAGE_BYTES

on_socket_open?

Called once per socket after the connection is admitted — registered and its credential re-checked — and before the first message dispatches. See RegisterActionWsOptions.on_socket_open.

type (ctx: SocketOpenContext): void | Promise<void>

ctx

returns void | Promise<void>

on_socket_close?

Called once per admitted socket on close, after registry.remove_connection. See RegisterActionWsOptions.on_socket_close.

type (ctx: SocketCloseContext): void | Promise<void>

ctx

returns void | Promise<void>

Depends on
#

Imported by
#