actions/compile_action_registry.ts

Shared registration loop for action-dispatcher endpoints.

create_rpc_endpoint (HTTP RPC) and register_action_ws (WebSocket) both build a Map<method, RpcAction> from a list of action specs and gate the build on the same checks, in this order (named rather than numbered — "registry-time invariant N" elsewhere in the codebase refers to the RouteAuth cross-axis set in http/auth_shape.ts, a different list):

  • Schema slots — input and output each hold a @fuzdev/fuz_schema schema (assert_validation_schema); a value that is no schema throws naming the action and the slot. Fires for every spec, before the checks that read the schemas.
  • Auth-shape cross-axis invariants — per assert_route_auth_invariants in http/auth_shape.ts: roles imply a required actor, no accountless actor, nothing to gate on unrestricted auth (that set's invariants 1, 3, and 4). Fires for every spec with non-null auth.
  • Auth-shape biconditional — per assert_route_auth_acting_biconditional in http/auth_shape.ts: `auth.actor !== 'none' ⟺ input declares acting?: ActingActor` (that set's invariant 2). Fires for every spec with non-null auth.
  • No auth.required_scope on an action — ActionSpec.auth is the same RouteAuth a route spec carries, so the field parses here, but only apply_route_specs mounts a guard from it and perform_action never reads it. Declaring it on an action would be a security control that silently does nothing, which is the exact shape token scoping was built to refuse. Rejected loudly instead; actions are governed by the per-method scope gate inside perform_action, which derives the same rpc:<method> capability from spec.method rather than trusting a hand-written one.
  • Rate-limit / account axis — rate_limit: 'account' | 'both' requires auth.account === 'required'; without an account on the request there is no key for the per-account bucket.
  • JSON-RPC §4.2 wire validity — request_response specs whose handler will reach the dispatch map must not use a null schema (literal(null)) for input (the wire format forbids "params": null; use a void schema, s.void, for parameterless methods), nor a void schema for output (a response always carries a result, which clients validate against spec.output; use a null schema for methods with nothing to return).
  • Duplicate method names — JSON-RPC keys on method, so every spec in the array must declare a unique method regardless of kind / handler presence.

Pre-consolidation each dispatcher inlined these checks; the comment in actions/register_action_ws.ts literally said "mirrors the HTTP RPC registration check" but nothing kept them mirrored. Centralizing the loop closes the most likely future drift surface.

view source

Declarations
#

2 declarations

ActionRegistryCompileResult
#

actions/compile_action_registry.ts view source

ActionRegistryCompileResult import type {ActionRegistryCompileResult} from '@fuzdev/fuz_app/actions/compile_action_registry.js';

Result returned by compile_action_registry.

action_map

Method → RpcAction lookup for dispatch. Only request_response specs with a handler land here — kind-polymorphic input arrays (the WebSocket dispatcher's actions: ReadonlyArray<Action>) pass remote_notification / handler-less specs through unchanged.

type Map<string, RpcAction>

compile_action_registry
#

actions/compile_action_registry.ts view source

(actions: readonly Action<ActionSpecUnion>[], ctx_label: string): ActionRegistryCompileResult import {compile_action_registry} from '@fuzdev/fuz_app/actions/compile_action_registry.js';

Validate registry-time invariants and build the dispatcher's method → action lookup.

actions

polymorphic action array; HTTP RPC passes RpcAction[] (narrower), WebSocket passes Action[] (kind-polymorphic — handler-less notification specs are accepted)

type readonly Action<ActionSpecUnion>[]

ctx_label

per-spec error-message prefix, e.g. 'RPC action' or 'WS action'. Combined with the spec method as ${ctx_label} "${method}".

type string

returns

ActionRegistryCompileResult

throws

  • Error - on a schema slot holding a value that is no schema, a cross-axis invariant or biconditional violation, rate-limit/account-axis mismatch, JSON-RPC null-input or void-output, or duplicate method.

Depends on
#

Imported by
#