/** * Versioned, bounded codecs shared by HTTP bodies, loader streams, and WebSocket frames. Plain JSON * remains the zero-configuration fast path; rich wire is explicit and preserves non-JSON values. */ export interface TransportDecodeOptions { readonly maxBytes?: number; } export interface TransportCodec { readonly id: string; readonly version: number; readonly mediaType: string; encode(value: unknown): string; decode(text: string): unknown; } export declare class TransportCodecError extends TypeError { constructor(message: string, options?: ErrorOptions); } /** * Enforce the transport byte cap on already-read text - the same limit (and the same error) the * streaming reader applies during a bounded read. Exported for callers that read a body through a * native, non-streaming path (the typed client's in-process branch) and still owe the cap contract. */ export declare function assertTransportTextBounded(text: string, options: TransportDecodeOptions): void; export declare const plainJsonCodec: TransportCodec; export interface TransportCodecRegistry { readonly fallback: TransportCodec; forContentType(contentType: string | null): TransportCodec; negotiate(accept: string | null): TransportCodec; byIdentity(id: string, version: number): TransportCodec; } export declare function createTransportCodecRegistry(codecs: readonly TransportCodec[], fallback?: TransportCodec): TransportCodecRegistry; export declare const defaultTransportCodecs: TransportCodecRegistry; export declare function encodeTransportResponse(value: unknown, codec?: TransportCodec, init?: ResponseInit): Response; /** * Read a response body into memory, refusing to exceed `maxBytes`. * * Bounded while STREAMING rather than after the fact: the `content-length` shortcut only helps when a * sender declares one, so the loop also counts as it goes and cancels the reader the moment the total * passes the limit. A cap that buffers first and complains afterwards has already spent the memory it * was meant to protect. * * Exported so the client can bound a plain-text body with the same reader it bounds JSON with, rather * than growing a second copy of this loop that could drift from it. */ export declare function readBoundedBytes(response: Response, options: TransportDecodeOptions): Promise; /** * Decode an ALREADY-READ transport body. The counterpart to {@link decodeTransportResponse} for a * caller that obtained the text through its own bounded read - notably the typed client's * in-process path, where the response body is same-process memory that was fully resident before * the read, so the native `Response.text()` is safe and the streaming byte-cap loop would protect * nothing while costing ~23x. The byte cap is still enforced here (identical error), just after * the read instead of during it. */ export declare function decodeTransportText(text: string, contentType: string | null, registry?: TransportCodecRegistry, options?: TransportDecodeOptions): unknown; export declare function decodeTransportResponse(response: Response, registry?: TransportCodecRegistry, options?: TransportDecodeOptions): Promise; export declare function encodeTransportFrame(value: unknown, codec?: TransportCodec): string; export declare function decodeTransportFrame(frame: string, registry?: TransportCodecRegistry, options?: TransportDecodeOptions): unknown; //# sourceMappingURL=transport-codec.d.ts.map