type DecodePath = readonly (string | number)[]; export type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject; export interface JsonObject { [key: string]: JsonValue; } declare class BoundaryDecodeError extends Error { readonly path: DecodePath; /** The problem without its location, such as "expected string". */ readonly reason: string; constructor(message: string, path?: DecodePath); } /** One problem found by `decodeBoundaryAll`; `where` reads like `outputs[0].label` ("input" for the root). */ export interface BoundaryIssue { readonly path: DecodePath; readonly where: string; readonly message: string; } /** Every problem `decodeBoundaryAll` found, in schema field order; the message lists them as `where: message; ...`. */ export declare class BoundaryDecodeIssues extends BoundaryDecodeError { readonly issues: readonly BoundaryIssue[]; constructor(issues: readonly BoundaryIssue[]); } export interface BoundaryCursor { readonly value: unknown; readonly path: DecodePath; child(key: string | number, value: unknown): BoundaryCursor; fail(message: string): never; /** * Records a child's failure when decoding with `decodeBoundaryAll` and returns true, so the * caller moves on to the next field; returns false otherwise, and the caller rethrows. */ collect(error: BoundaryDecodeError): boolean; /** The same position without collecting, for schemas that must see the first failure (unions). */ strict(): BoundaryCursor; } export interface BoundarySchema { decode(cursor: BoundaryCursor): T; } type ObjectFields = { [key: string]: BoundarySchema; }; type InferSchema = Schema extends BoundarySchema ? Value : never; type InferObject = { [Key in keyof Fields]: InferSchema; }; declare function decodeJsonValue(current: BoundaryCursor): JsonValue; declare function decodeJsonObject(current: BoundaryCursor): JsonObject; export declare const boundary: { string: BoundarySchema; nonEmptyString: { decode(current: BoundaryCursor): string; }; number: BoundarySchema; boolean: BoundarySchema; json: { decode: typeof decodeJsonValue; }; jsonObject: { decode: typeof decodeJsonObject; }; literal(expected: Value): BoundarySchema; enumeration(...values: Values): BoundarySchema; optional(schema: BoundarySchema): BoundarySchema; nullable(schema: BoundarySchema): BoundarySchema; array(schema: BoundarySchema): BoundarySchema; object(fields: Fields): BoundarySchema>; /** Accepts a decoded value only when `test` holds; otherwise fails with `message`. */ refine(schema: BoundarySchema, test: (value: Value) => boolean, message: string): BoundarySchema; union[]>(...schemas: Schemas): BoundarySchema>; }; export declare function decodeBoundary(value: unknown, schema: BoundarySchema): Value; /** * Like `decodeBoundary`, but reports every problem at once: object fields and array items are all * decoded, an absent required field reads "missing", and a failure throws `BoundaryDecodeIssues`. * Opt-in, for payloads people and agents write by hand. */ export declare function decodeBoundaryAll(value: unknown, schema: BoundarySchema): Value; export {}; //# sourceMappingURL=boundaryDecoder.d.ts.map