actions/action_event.ts

ActionEvent — state machine for action lifecycle management.

Manages an action through its phases (send_request → receive_response, etc.) and steps (initial → parsed → handling → handled/failed).

view source

Declarations
#

5 declarations

ActionEvent
#

actions/action_event.ts view source

import {ActionEvent} from '@fuzdev/fuz_app/actions/action_event.js';

Action event that manages the lifecycle of an action through its state machine.

generics

ActionEvent<TMethod extends string = string, TPhase extends ActionEventPhase = ActionEventPhase, TStep extends ActionEventStep = ActionEventStep>
TMethod
constraint string
default string
TPhase
constraint ActionEventPhase
TStep
constraint ActionEventStep

environment

type ActionEventEnvironment

readonly

spec

method narrows to TMethod so consumers passing a typed TApi to create_rpc_client get event.spec.method typed as the union of their API's method names rather than plain string. The runtime value comes from lookup_action_spec(method) keyed off the Proxy get trap, so the narrowing matches the dispatched method.

type (RequestResponseActionSpec & { method: TMethod; }) | (RemoteNotificationActionSpec & { method: TMethod; }) | (LocalCallActionSpec & { method: TMethod; })

readonly

constructor

type new <TMethod extends string = string, TPhase extends ActionEventPhase = "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute", TStep extends ActionEventStep = "initial" | ... 3 more ... | "failed">(environment: ActionEventEnvironment, spec: ActionSpecUnion, data: ActionEventDataUnion<...>): ActionEvent<...>

environment

spec

data

toJSON

type (): ActionEventDataUnion<TMethod>

observe

Subscribe a listener fired on every data transition.

type (listener: ActionEventChangeObserver<TMethod>): () => void

listener

called with (new_data, old_data, event) after each mutation

type ActionEventChangeObserver<TMethod>
returns () => void

unsubscribe function

mutates

  • this — adds `listener` to the internal observer set

set_data

Replace the event's data and notify observers.

type (new_data: ActionEventDataUnion<TMethod>): void

new_data

returns void

mutates

  • this — sets `data` and fires every registered observer in insertion order

parse

Parse the event's payload against the action's schemas — spec.input for outgoing and incoming calls, spec.output for a received response.

A received response's result is validated like any other inbound data, except that keys spec.output doesn't declare are dropped rather than refused (safe_parse_dropping_unknown_keys). On success output becomes the parsed value (brands, defaults, and transforms applied); on any other mismatch the event moves to receive_error with an internal_error whose data.reason is ERROR_RESPONSE_OUTPUT_INVALID (the remote broke its contract — not the caller's input), the same path an error response takes.

type (): this

returns this

this for chaining with handle_async / handle_sync

throws

  • Error - if called from a step other than `initial`

mutates

  • this — transitions step from `initial` to `parsed` (or to `failed` / `receive_error` on validation or response error)

handle_async

Execute the handler for the current phase.

type (): Promise<void>

returns Promise<void>

throws

  • Error - if called from a step other than `parsed` (or `failed`, which no-ops). Handler-thrown `ThrownJsonrpcError` is caught and routed through error phases; other throws are wrapped as `internal_error` carrying the thrown message (see `#to_handler_error`).

mutates

  • this — transitions step `parsed → handling → handled`, or to `failed` / `send_error` / `receive_error` on handler throw. No-op when already `failed`.

handle_sync

Execute handler synchronously (only for sync local_call actions).

type (): void

returns void

throws

  • Error - if the spec is not a sync `local_call`, or if called from a step other than `parsed` (or `failed`, which no-ops).

mutates

  • this — transitions step `parsed → handling → handled`, or to `failed` on handler throw. No-op when already `failed`.

transition

Transition to a new phase.

type (phase: "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute"): void

phase

the next phase to transition into

returns void

throws

  • Error - if called from a step other than `handled` (or `failed`, which no-ops), or if the phase transition is illegal for the current phase

mutates

  • this — replaces `data` with a fresh phase-initial record, carrying forward `request` / `response` / `error` / `output` as appropriate for the kind/phase pair

is_complete

type (): boolean

returns boolean

update_progress

type (progress: unknown): void

progress

type unknown
returns void

set_request

type (request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>): void

request

returns void

set_response

type (response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<...>; jsonrpc: "2.0"; id: string | ... 1 more ... | null; } & Record<...>)): void

response

returns void

set_notification

type (notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>): void

notification

returns void

data

type ({ kind: "request_response"; phase: "send_request"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_request"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_request"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_request"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_request"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: ({ method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_request"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_request"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_request"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_request"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_request"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_response"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_response"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_response"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_response"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_response"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_response"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_response"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_response"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_response"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_response"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_error"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: null; request: ({ method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_error"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: null; request: ({ method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_error"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: ({ method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "send_error"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: ({ method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_error"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_error"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: null; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_error"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "request_response"; phase: "receive_error"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; response: ({ jsonrpc: "2.0"; id: string | number; result: unknown; } & Record<string, unknown>) | ({ error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; jsonrpc: "2.0"; id: string | number | null; } & Record<string, unknown>); notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "send"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "send"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "send"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "send"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "send"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: null; response: null; notification: ({ method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>) | null; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "receive"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "receive"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "receive"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "receive"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "remote_notification"; phase: "receive"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: null; response: null; notification: { method: string; jsonrpc: "2.0"; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>; } & { phase: TPhase; step: TStep; }) | ({ kind: "local_call"; phase: "execute"; step: "initial"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "local_call"; phase: "execute"; step: "parsed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: null; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "local_call"; phase: "execute"; step: "handling"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: null; progress: unknown; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "local_call"; phase: "execute"; step: "handled"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: unknown; error: null; progress: unknown; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; }) | ({ kind: "local_call"; phase: "execute"; step: "failed"; method: TMethod; executor: "frontend" | "backend"; input: unknown; output: null; error: { code: -32700 | -32600 | -32601 | -32602 | -32603 | Branded<number, "JsonrpcServerErrorCode">; message: string; data?: unknown; } & Record<string, unknown>; progress: unknown; request: null; response: null; notification: null; } & { phase: TPhase; step: TStep; })

getter

ActionEventChangeObserver
#

actions/action_event.ts view source

ActionEventChangeObserver<TMethod> import type {ActionEventChangeObserver} from '@fuzdev/fuz_app/actions/action_event.js';

generics

ActionEventChangeObserver<TMethod extends string = string>
TMethod
constraint string
default string

(call)

type (new_data: ActionEventDataUnion<TMethod>, old_data: ActionEventDataUnion<TMethod>, event: ActionEvent<TMethod, "send_request" | ... 7 more ... | "execute", "initial" | ... 3 more ... | "failed">): void

new_data

old_data

event

type ActionEvent<TMethod, "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute", "initial" | "parsed" | "handling" | "handled" | "failed">
returns void

create_action_event
#

actions/action_event.ts view source

<TMethod extends string = string>(environment: ActionEventEnvironment, spec: ActionSpecUnion, input: unknown, initial_phase?: "send_request" | "receive_request" | "send_response" | ... 6 more ... | undefined): ActionEvent<...> import {create_action_event} from '@fuzdev/fuz_app/actions/action_event.js';

Create an action event from a spec and initial input.

environment

spec

input

type unknown

initial_phase?

optional

returns

ActionEvent<TMethod, "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute", "initial" | "parsed" | "handling" | "handled" | "failed">

generics

create_action_event<TMethod extends string = string>
TMethod
constraint string
default string

throws

  • Error - if `initial_phase` is omitted and the executor cannot initiate the action (per `spec.initiator`)

create_action_event_from_json
#

actions/action_event.ts view source

<TMethod extends string = string>(json: ActionEventDataUnion<TMethod>, environment: ActionEventEnvironment): ActionEvent<TMethod, "send_request" | ... 7 more ... | "execute", "initial" | ... 3 more ... | "failed"> import {create_action_event_from_json} from '@fuzdev/fuz_app/actions/action_event.js';

Reconstruct an action event from serialized JSON data.

json

environment

returns

ActionEvent<TMethod, "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute", "initial" | "parsed" | "handling" | "handled" | "failed">

generics

create_action_event_from_json<TMethod extends string = string>
TMethod
constraint string
default string

throws

  • Error - if the JSON's `method` field has no spec registered in `environment`

ERROR_RESPONSE_OUTPUT_INVALID
#

actions/action_event.ts view source

"response_output_invalid" import {ERROR_RESPONSE_OUTPUT_INVALID} from '@fuzdev/fuz_app/actions/action_event.js';

error.data.reason on the internal_error a client reports when a response's result fails spec.output — a remote bug, distinct from the invalid_params / validation_error a caller's own bad input produces.

Depends on
#

Imported by
#