import type { Bytes, Deserialize, Serialize, StreamReferences } from "@the-link/core"; import type { Context } from "hono"; /** * Streams between HttpServer and HttpClient. * * Messages carry only stream references; the chunks travel over their own * HTTP requests, so a large stream never delays the messages on the WebSocket: * * - a stream the server sends is read by the client with GET `/stream/:id`, * whose response body carries the chunks as frames; * - a stream the client sends is written with one POST `/stream/:id` per * frame, and the server answers each POST only once that chunk is taken, so * the client never sends further than the server reads. * * Each frame is a 4-byte big-endian length followed by the codec's encoding of * `["chunk", value]`, `["end"]`, or `["error", message]`. */ type Frame = readonly ["chunk", unknown] | readonly ["end"] | readonly ["error", string]; export declare function encodeFrame(serialize: Serialize, frame: Frame): Bytes; /** Splits a byte stream into frames, however its bytes were cut in transit. */ export declare function decodeFrames(deserialize: Deserialize, source: ReadableStream): ReadableStream; /** * The server's side: references for streams it sends, and streams for references clients send. */ export declare class ServerStreams implements StreamReferences { private readonly codec; private readonly outgoing; private readonly incoming; constructor(codec: () => { serialize: Serialize; deserialize: Deserialize; }); export(stream: ReadableStream): string; import(id: string): ReadableStream; /** GET `/stream/:id`: the body carries a stream this server sent. */ read(context: Context): Promise; /** POST `/stream/:id`: one frame of a stream a client sends; answered once the chunk is taken. */ write(context: Context): Promise<(Response & import("hono").TypedResponse) | (Response & import("hono").TypedResponse<"The stream frame is invalid", 400, "text">) | (Response & import("hono").TypedResponse)>; private incomingEntry; private expire; /** Hands the next waiting frame to the reader, when it wants one. */ private deliver; } /** * The client's side: references for streams it sends, and streams for references the server sends. */ export declare class ClientStreams implements StreamReferences { private readonly url; private readonly codec; constructor(url: string, codec: () => { serialize: Serialize; deserialize: Deserialize; }); export(stream: ReadableStream): string; import(id: string): ReadableStream; private send; } export {};