/** * HTTP transport for Enkaku RPC clients. * * ## Installation * * ```sh * npm install @enkaku/http-fetch * ``` * * @module http-fetch */ import type { AnyClientMessageOf, AnyServerMessageOf, ProtocolDefinition } from '@enkaku/protocol'; import { Transport } from '@enkaku/transport'; import { type Runtime } from '@sozai/runtime'; export type FetchFunction = typeof globalThis.fetch; export declare class ResponseError extends Error { #private; constructor(response: Response); get response(): Response; } export type TransportStreamParams = { url: string; fetch?: FetchFunction; runtime?: Runtime; maxBufferSize?: number; cancelOnAbort?: boolean; }; export type TransportStream = ReadableWritablePair, AnyClientMessageOf> & { controller: ReadableStreamDefaultController>; /** * Send a single client message, rejecting if it could not be delivered. * `ClientTransport.write` calls this instead of writing to `writable`, * because a rejecting WritableStream sink errors its stream permanently. * Calls are serialized: a message issued while an earlier one is still in * flight is only sent once that one settles, so a channel `send` cannot * overtake the `channel` open it belongs to. */ send: (msg: AnyClientMessageOf) => Promise; }; export declare function createTransportStream(params: TransportStreamParams): TransportStream; export type ClientTransportParams = { url: string; fetch?: FetchFunction; runtime?: Runtime; maxBufferSize?: number; cancelOnAbort?: boolean; }; export declare class ClientTransport extends Transport, AnyClientMessageOf> { #private; constructor(params: ClientTransportParams); /** * Bypass the WritableStream sink. A sink that rejects errors its stream * permanently, so routing a failed message through it would let one rejected * event kill every later write. */ write(value: AnyClientMessageOf): Promise; }