Graphorin API reference v0.1.0
Graphorin API reference / @graphorin/protocol / server-message
server-message
ServerMessage — discriminated union of every frame a Graphorin server may push to a client. Three families share the channel:
- RPC responses (
{ jsonrpc, id, result | error }) — correlate with a previously-issued client request. - Typed push events (
{ kind: 'event', subject, type, payload, eventId }) — the streaming-first data plane; consumers ignore unknowntypestrings per the agent-event extensibility convention. - Asynchronous server frames (
{ kind: 'lifecycle' | 'error' | 'pong' | 'subscribed' | 'unsubscribed' | 'replay-marker' }) — server-initiated messages that do not correlate with a single client RPC id.
Every frame carries the v: '1' literal so future revisions can negotiate forward-compatible additions without a subprotocol bump.
Type Aliases
| Type Alias | Description |
|---|---|
| ServerErrorFrame | - |
| ServerEventFrame | Convenience type aliases for callers that want to reference an individual variant without z.infer<typeof X>. |
| ServerLifecycleFrame | - |
| ServerMessage | Inferred TypeScript union for the ServerMessage discriminator. |
| ServerPongFrame | - |
| ServerReplayMarkerFrame | - |
| ServerRpcFailure | - |
| ServerRpcSuccess | - |
| ServerSubscribedFrame | - |
| ServerUnsubscribedFrame | - |
Variables
| Variable | Description |
|---|---|
| RPC_ERROR_CODES | Stable JSON-RPC error code catalogue used by the server when surfacing routine failures (per JSON-RPC 2.0 § 5.1 + Graphorin extensions). Application-level errors use codes in the implementation-defined range (-32000 … -32099). |
| ServerMessageSchema | Zod schema for every legal server → client frame. Validation runs twice in the server pipeline: first when a route handler enqueues the frame onto the dispatcher's send queue (so a malformed frame never escapes the process), then again on the client side to defend against protocol drift. |
Functions
| Function | Description |
|---|---|
| isErrorFrame | - |
| isEventFrame | Type guard helpers, one per discriminator. The narrow over the ServerMessage union without forcing consumers to memorize the exact field names. |
| isLifecycleFrame | - |
| isPongFrame | - |
| isReplayMarkerFrame | - |
| isRpcFailure | - |
| isRpcSuccess | - |
| isSubscribedFrame | - |
| isUnsubscribedFrame | - |