API index and search · Build metadata
Supporting declarations
packages/remote/src/transport.ts. These declarations explain referenced types. Only package-page symbols are package exports.
Transport
export interface Transport {
/** Send a message up to the server. */
send(msg: ClientMsg): void;
/** Register the single handler for incoming server messages. */
onMessage(handler: (msg: ServerMsg) => void): void;
/** Register a handler fired after the connection is RE-established (not the first open) — the
* source uses it to re-`init` + re-subscribe so a dropped/restarted daemon heals. Optional:
* transports without reconnect (mocks, in-process) may omit it. */
onReconnect?(handler: () => void): void;
/** Register a handler fired when the connection is SUSTAINEDLY down — repeated reconnects to the
* same endpoint have failed (a dead/removed follower, READ-ROUTER-DESIGN.md §3). The source uses
* it to re-lease: the router returns a (possibly new) `wsEndpoint`, and a changed one migrates the
* whole session off the dead node. Optional: transports without failover (mocks, in-process,
* fixed endpoints) may omit it. */
onDown?(handler: () => void): void;
/** Tear down the connection. */
close(): void;
}WsTransport
/** A `Transport` over a `WebSocket` (text JSON frames). Messages sent before the socket
* opens are buffered and flushed on open (so `registerQuery`/`mutate` can be called eagerly).
* Reconnects with capped exponential backoff: if the socket drops (e.g. the daemon restarted)
* it reopens and fires `onReconnect` so the source rebuilds its subscriptions. */
export declare class WsTransport implements Transport {
private readonly url;
/** Reads the subprotocols to offer at each (re)connect — in affinity mode, `["rindle.v1", "aff.…"]`
* with the CURRENT ticket (FOLLOWER-AFFINITY-DESIGN.md §5). Undefined ⇒ offer none (today's
* single-daemon behavior, byte-identical). Evaluated per connect so a reconnect presents the
* freshest (or freshly cleared) ticket. */
private readonly subprotocols?;
private ws;
private handler;
private reconnectHandler;
private downHandler;
/** Buffered as PRE-SERIALIZED frames: serialization happens at `send` time so an
* unserializable message (a `bigint` query arg — `JSON.stringify` throws on bigint)
* throws typed INTO ITS CALLER instead of detonating later inside the socket's
* `open` listener, where it would strand every frame queued behind it. */
private readonly pending;
private open;
private everOpened;
private closedByUser;
private attempt;
private reconnectTimer;
/** Failed reconnect attempts after which the connection is declared "down" (fires `onDown`). */
private readonly downThreshold;
/** True once `onDown` has fired for the CURRENT down episode; reset on the next successful open
* so a later outage fires again (but a single episode fires `onDown` exactly once — no re-lease
* storm while a follower is gone). */
private downFired;
constructor(url: string, opts?: {
downThreshold?: number;
subprotocols?: () => string[];
});
private connect;
private scheduleReconnect;
send(msg: ClientMsg): void;
onMessage(handler: (msg: ServerMsg) => void): void;
onReconnect(handler: () => void): void;
onDown(handler: () => void): void;
close(): void;
}