7.1 KiB
7.1 KiB
@suaveplan/api-ws - Abstract WebSocket engine contract for the Suaveplan API foundation — Connection, ConnectionRegistry, SubscriptionBus, WsBroker, reconnect-token envelope, backpressure + heartbeat policies, cross-tenant capability gate, and a runWsEngineConformance harness. contracts only; concrete engines (api-ws-bun) and brokers (api-ws-broker-redis / -in-memory) plug behind these interfaces.
Stage-1 abstract WebSocket contract for the Suaveplan API plugin system.
Universal contract package. Defines the canonical interfaces every concrete
WebSocket engine (api-ws-bun, future browser shims) and broker
(api-ws-broker-in-memory, api-ws-broker-redis) plugs behind. Ships a
single-host in-memory ConnectionRegistry + SubscriptionBus so the
conformance harness has an executable reference, plus the cross-tenant
capability gate documented in design doc §11.2.
Documentation tree
- backpressure — Per design doc §11.4, every WebSocket connection MUST have a bounded outbound queue. This module owns the abstract poli…
- backpressure — Per design doc §11.4, every WebSocket connection MUST have a bounded outbound queue. This module owns the abstract poli…
- broker — A single-host deployment never needs a broker — the
SubscriptionBusinside that process already sees every connection…- broker — A single-host deployment never needs a broker — the
SubscriptionBusinside that process already sees every connection…
- broker — A single-host deployment never needs a broker — the
- capability-id —
@suaveplan/api-types/capabilitiesowns the closedCapabilityIdunion for the whole API foundation. `@suaveplan/api-…- capability-id —
@suaveplan/api-types/capabilitiesowns the closedCapabilityIdunion for the whole API foundation. `@suaveplan/api-…
- capability-id —
- connection —
@suaveplan/api-ws/connectiondeclares the abstractWsConnectioninterface every concrete engine (api-ws-bun, futu…- connection —
@suaveplan/api-ws/connectiondeclares the abstractWsConnectioninterface every concrete engine (api-ws-bun, futu…
- connection —
- connection-registry — Every plugin endpoint that opens a WebSocket connection registers it with a host-owned
ConnectionRegistry. The regist…- connection-registry — Every plugin endpoint that opens a WebSocket connection registers it with a host-owned
ConnectionRegistry. The regist…
- connection-registry — Every plugin endpoint that opens a WebSocket connection registers it with a host-owned
- envelope —
@suaveplan/api-ws/envelopeowns the canonical Zod schema for every WebSocket frame that flows between the host and a…- envelope —
@suaveplan/api-ws/envelopeowns the canonical Zod schema for every WebSocket frame that flows between the host and a…
- envelope —
- error-codes —
@suaveplan/api-wsowns the abstract WebSocket contract. Every public failure path raises aWsErrorcarrying a stabl…- error-codes —
@suaveplan/api-wsowns the abstract WebSocket contract. Every public failure path raises aWsErrorcarrying a stabl…
- error-codes —
- heartbeat — Every WebSocket connection that the Suaveplan API host accepts is policed by a heartbeat: the engine pings at a fixed c…
- heartbeat — Every WebSocket connection that the Suaveplan API host accepts is policed by a heartbeat: the engine pings at a fixed c…
- reconnect-token — When the host closes a WebSocket connection cleanly (heartbeat failure, deploy, transient network issue), it issues a r…
- reconnect-token — When the host closes a WebSocket connection cleanly (heartbeat failure, deploy, transient network issue), it issues a r…
- subscription-bus —
SubscriptionBusis the broadcast surface every plugin uses to fan a payload out to every subscribed connection on the…- subscription-bus —
SubscriptionBusis the broadcast surface every plugin uses to fan a payload out to every subscribed connection on the…
- subscription-bus —
- testing — Every concrete WebSocket engine and broker the foundation publishes (
api-ws-bun,api-ws-broker-in-memory, `api-ws-b…- conformance — Every concrete WebSocket engine and broker the foundation publishes (
api-ws-bun,api-ws-broker-in-memory, `api-ws-b…
- conformance — Every concrete WebSocket engine and broker the foundation publishes (
Modules
| Subpath | Purpose |
|---|---|
./connection |
WsConnection interface, WsConnectionState, SubscriptionFilter, SubscribeOptions. docs |
./connection-registry |
ConnectionRegistry interface + InMemoryConnectionRegistry with (tenantId) and (topic, tenantId) indices. docs |
./subscription-bus |
SubscriptionBus<Payload> + InMemorySubscriptionBus; cross-tenant capability gate. docs |
./broker |
WsBroker multi-host fan-out contract — publish, subscribe, dispose. docs |
./envelope |
WsEnvelope Zod schema for wire frames; strict mode rejects unknown keys. docs |
./backpressure |
BackpressurePolicy + evaluateBackpressure (default maxQueuedMessages = 256). docs |
./heartbeat |
HeartbeatPolicy + evaluateHeartbeat (default heartbeatMs = 30000, two missed pongs to abort). docs |
./reconnect-token |
HMAC-SHA-256 reconnect-token envelope with 5-minute TTL; Web Crypto. docs |
./capability-id |
WS_CAPABILITY_IDS re-exports for "ws" and "ws.broadcast-cross-tenant". docs |
./error-codes |
WS_CODES registry (8 codes) + WsError + engine throw helpers. docs |
./testing |
runWsEngineConformance harness + inMemoryFactory reference. docs |
Out of scope (this package)
- Concrete engines (
api-ws-bun, browser shims) — . - Concrete brokers (
api-ws-broker-redis,api-ws-broker-in-memory) — Stages 5 / 7. - The
graphql-wsprotocol wiring — that lives inapi-graphqlengine adapters, which read this package'sSubscriptionBus.
Dependencies
@suaveplan/api-types workspace:^—Principal,TenantId,CapabilityId.@suaveplan/error workspace:^—defineCodes+SuaveplanError.@suaveplan/types workspace:^— shared option bundles + clock contract.zod catalog:forms— wire-envelope schema (default-import formimport z from "zod").tslib catalog:build.
No transport dependencies — engines own that.