/** Callbacks for a single live subscription, keyed by operation id. */ export interface Subscriber { /** Called with `payload.data` for each `next` message. */ next: (data: Record) => void; /** Called on a server `error` message or an unexpected socket close. */ error: (error: Error) => void; /** Called on a server `complete` message. */ complete: () => void; } /** * A user-suppliable transport, modeled on puppeteer's `ConnectionTransport`. * Pass one via {@link ConnectOptions.transport} to send BrowserQL frames over * your own channel instead of the built-in WebSocket. The frames it relays are * graphql-transport-ws envelopes ({@link SUBPROTOCOL}) — the transport is just * the pipe, {@link Transport} does the framing on top. * * The library assigns `onmessage`/`onclose`/`onerror` after the transport is * created; the transport must invoke `onmessage` for every frame it receives, * `onclose` when the connection ends, and `onerror` on a transport error. * `send` transmits one text frame; `close` tears the connection down. */ export interface ConnectionTransport { send(message: string): void; close(): void; onmessage?: (message: string) => void; onclose?: (event?: unknown) => void; onerror?: (error: unknown) => void; } /** * Builds a {@link ConnectionTransport} for a given endpoint URL. Supply one via * {@link ConnectOptions.transport} to override the default WebSocket transport. * The returned promise must resolve only once the connection is open — the * library begins sending frames as soon as it resolves. This is a factory * rather than a single instance because {@link Browser.newPage} invokes it per * page and {@link Transport} assigns `onmessage`/`onclose`/`onerror` on the * returned transport each time — so every page must get a fresh transport * instance. Reusing one instance across pages would overwrite the earlier * pages' handlers and cross-wire their frames, unless the transport itself * multiplexes. */ export type TransportFactory = (url?: string) => ConnectionTransport | Promise; /** * The built-in {@link ConnectionTransport}: a WebSocket via `#platform` (native * in the browser, `ws` in Node so the User-Agent header can be sent). This is * what the library uses whenever no custom `transport` is supplied — connecting * to a WebSocket URL goes through {@link WebSocketTransport.create}, which * negotiates the {@link SUBPROTOCOL} subprotocol. */ export declare class WebSocketTransport implements ConnectionTransport { private readonly ws; onmessage?: (message: string) => void; onclose?: (event?: unknown) => void; onerror?: (error: unknown) => void; /** Opens a WebSocket to `url` and resolves once it is connected. */ static create(url: string, headers?: Record, protocols?: string | string[]): Promise; private constructor(); send(message: string): void; close(): void; } export declare class Transport { #private; private readonly url; private readonly defaultTimeout; private readonly transportFactory; constructor(url: string | undefined, defaultTimeout?: number, transportFactory?: TransportFactory); get closed(): boolean; /** Resolve a per-operation timeout against the transport default. */ operationTimeout(timeout?: number, cushion?: number): number; /** * Subscribe to every raw frame the transport receives — in addition to the * per-operation routing, and including frames with no matching operation * (e.g. server-pushed data over a custom {@link ConnectionTransport}). The * `connection_ack` handshake frame is consumed internally and not delivered. * Returns an unsubscribe function. */ onMessage(listener: (message: string) => void): () => void; /** * Build the transport (via the factory) and send the graphql-transport-ws * `connection_init`. Idempotent: repeated calls return the same in-flight * promise. Resolves once the transport is wired and `connection_init` is * sent; the server's `connection_ack` is consumed asynchronously. Frames ride * a single ordered channel, so operations sent right after `connect()` * resolves still arrive after `connection_init` server-side. */ connect(): Promise; /** * Run a query or mutation and resolve with its `data` object. The operation * emits a single `next` (whose `data` is captured) followed by `complete` * (which resolves); a pre-execution `error` frame or GraphQL `errors` reject * with {@link BrowserQLError}. */ send(query: string, variables?: Record, timeout?: number): Promise; /** * Open a subscription. Returns an unsubscribe function that completes just * this stream. Streamed values and errors are delivered to `handlers`. */ subscribe(query: string, variables: Record, handlers: Subscriber): Promise<() => void>; /** Complete a single operation without tearing down the socket. */ private stop; close(): void; } //# sourceMappingURL=transport.d.ts.map