import { ClientMessage, ServerMessage } from "@graphorin/protocol"; //#region src/transport/types.d.ts /** * Discriminator used by the public client API + diagnostics. * * @stable */ type TransportKind = 'ws' | 'sse'; /** * Stable shape consumed by every transport implementation. * * @stable */ interface TransportOptions { readonly url: string; readonly auth: TransportAuth; readonly fetch?: typeof fetch; readonly WebSocket?: typeof WebSocket; readonly EventSource?: typeof EventSource; /** Per-connection identifier surfaced on diagnostics + reconnects. */ readonly clientId?: string; /** * Resume cursor sent as the `Last-Event-ID` header on (re)connect. * The server replays only events AFTER it from the * buffer - without it every SSE reconnect replays the entire * buffered history. Consumed by the SSE transport; ignored by WS * (whose resubscribe carries the cursor in the RPC). */ readonly lastEventId?: string; } /** * Authentication strategy passed to a transport. The bearer-token * shape is consumed by both transports (WS via the * `Authorization` header on Node SDK clients; SSE via the * `Authorization` header on every fetch); the ticket-provider shape * is only used by the WS browser path (the WebSocket browser API * does not allow custom headers, so the ticket rides the * `Sec-WebSocket-Protocol` header). * * @stable */ type TransportAuth = { readonly kind: 'bearer'; readonly token: string; } | { readonly kind: 'ticket'; readonly ticketProvider: () => Promise; }; /** * Minimal listener surface the transport invokes in lifecycle order: * `onOpen` ⇒ `onFrame*` (zero or more) ⇒ `onClose`. `onError` may * fire at any time before `onClose`. * * @stable */ interface TransportListeners { onOpen(): void; onFrame(frame: ServerMessage): void; onError(error: Error): void; onClose(reason: TransportCloseReason): void; } /** * Discriminator returned via {@link TransportListeners.onClose}. The * client uses the discriminator to decide whether to reconnect. * * @stable */ interface TransportCloseReason { readonly code: number; readonly reason: string; /** True when the close came from a server-side `error` frame. */ readonly wasClean: boolean; /** Optional Graphorin reason discriminator, per `@graphorin/protocol`. */ readonly graphorinReason?: string; } /** * Active transport handle. The client owns the handle and disposes * it via {@link Transport.close} on every cleanup path. * * @stable */ interface Transport { readonly kind: TransportKind; readonly url: string; /** * Send a client → server frame. Throws when the transport is not * in the open state, or when the underlying back-end does not * support send (the SSE transport throws every send via * `TransportFailedError` - clients * should fall back to REST for control-plane operations on SSE). */ send(frame: ClientMessage): void; close(code?: number, reason?: string): void; /** Last server-issued event id observed on this connection. */ readonly lastEventId: string | undefined; } //#endregion export { Transport, TransportAuth, TransportCloseReason, TransportKind, TransportListeners, TransportOptions }; //# sourceMappingURL=types.d.ts.map