/** * Rich-type wire codec: round-trips values that plain JSON silently drops or corrupts, across any * JSON transport (RPC bodies, loader payloads, WebSocket frames). * * `JSON.stringify` turns `undefined` into a missing key, `Date` into a lossy string, `NaN`/`Infinity` * into `null`, loses `-0`, and throws on `BigInt` - and it has no notion of `Map`, `Set`, `RegExp`, * `URL`, `ArrayBuffer`, or typed arrays. It also flattens a shared reference into two copies and throws * on a cycle. A typed client that infers `Date` from the server type then receives a `string` at runtime * is exactly the drift this framework exists to remove. `encode` maps a value to a JSON-safe structure * that `decode` reconstructs exactly - including cycles and preserved reference identity; `stringify` / * `parse` are the drop-in `JSON.*` equivalents. * * The wire form is `{ r, n }`: `r` is the root (an inline value or a `ref`), `n` is a flat table of * container/rich nodes addressed by index. Because every object is interned in `n` and referenced by * index, a shared object is encoded once (and decodes to a single shared instance), and a cycle is a * back-reference rather than infinite recursion. Functions and symbols are rejected, never silently * dropped. Decoding validates every tag and index, so a malformed payload throws {@link WireDecodeError} * rather than producing a corrupt value. * * Not covered by design (matches `JSON`): class identity (a class instance decodes to a plain object * carrying its own enumerable properties), non-enumerable and symbol keys, and getters (read once). */ /** The JSON-safe encoded form produced by {@link encode} and consumed by {@link decode}. */ export interface Wire { /** The root value: an inline primitive/scalar, or a `{ [TAG]: "ref", i }` into {@link Wire.n}. */ readonly r: unknown; /** Interned container and rich-type nodes, addressed by index from `ref`s. */ readonly n: readonly unknown[]; } /** Resource limits applied while reconstructing transport-controlled wire data. */ export interface WireDecodeLimits { /** Maximum number of interned nodes. Default 10,000. */ readonly maxNodes?: number; /** Maximum nesting depth across containers and references. Default 256. */ readonly maxDepth?: number; /** Maximum total object/array/map/set entries visited. Default 100,000. */ readonly maxCollectionEntries?: number; /** Maximum UTF-8 string plus decoded binary bytes materialized. Default 16 MiB. */ readonly maxDecodedBytes?: number; } export declare const DEFAULT_WIRE_DECODE_LIMITS: Readonly>; /** Thrown by {@link encode} for a value it will not encode (a function or a symbol). */ export declare class WireEncodeError extends TypeError { constructor(message: string); } /** Thrown by {@link decode} for a wire value carrying an unknown tag, a bad index, or malformed shape. */ export declare class WireDecodeError extends TypeError { constructor(message: string); } /** Encode any supported value into a JSON-safe {@link Wire} form. */ export declare function encode(value: unknown): Wire; /** Reconstruct the original value from a {@link Wire} form produced by {@link encode}. */ export declare function decode(wire: Wire, limits?: WireDecodeLimits): unknown; /** `encode` + `JSON.stringify` in one call - the rich-type equivalent of `JSON.stringify`. */ export declare function stringify(value: unknown): string; /** `JSON.parse` + `decode` in one call - the rich-type equivalent of `JSON.parse`. */ export declare function parse(text: string, limits?: WireDecodeLimits): unknown; //# sourceMappingURL=wire.d.ts.map