/** A value that does not fit its schema: path is where ("payload.targetSetpoint.scale"), problem is what. */ export declare class SchemaError extends Error { readonly path: string; readonly problem: string; constructor(path: string, problem: string); } export interface Schema { /** What the schema accepts, in the words of an error message: "an integer from 0 to 100", "ON | OFF". */ readonly expects: string; /** The checked value. path names it in the error message. */ parse(input: unknown, path?: string): T; } /** A schema that accepts a missing value; s.object() makes its key optional in the inferred type. */ export interface OptionalSchema extends Schema { readonly optional: true; } export interface EnumSchema extends Schema { readonly values: readonly V[]; } /** The type a schema produces. */ export type Infer = S extends Schema ? T : never; export type Shape = Record>; type OptionalKeys = { [K in keyof S]: S[K] extends OptionalSchema ? K : never; }[keyof S]; export type InferShape = { [K in Exclude>]: Infer; } & { [K in OptionalKeys]?: Infer; }; export interface NumberRules { min?: number; max?: number; /** Greater than, the bound itself excluded. */ gt?: number; integer?: boolean; } export interface Temperature { value: number; scale: "CELSIUS" | "FAHRENHEIT" | "KELVIN"; } export interface TimeInterval { start?: string; end?: string; duration?: string; } /** The error of a value that is not what a schema expects. */ export declare function mismatch(path: string, expects: string, input: unknown): SchemaError; /** The path of a key of the object at path. */ export declare const at: (path: string, key: string) => string; declare function number(rules?: NumberRules): Schema; declare function string(rules?: { min?: number; max?: number; pattern?: RegExp; expects?: string; }): Schema; declare function boolean(): Schema; declare function literal(value: V): Schema; declare function enumeration(...values: V): EnumSchema; /** One of a list too long to print in an error message: expects says what the list is. */ declare function oneOf(values: readonly V[], expects: string): EnumSchema; declare function unknown(): Schema; declare function optional(inner: Schema): OptionalSchema; declare function nullable(inner: Schema): Schema; declare function array(item: Schema, rules?: { min?: number; max?: number; }): Schema; /** * An object with the keys of shape. Keys the shape does not name are kept as they are: a field Alexa adds to a * directive reaches the handler. unknownKeys "reject" is for what a developer writes, where such a key is a typo. */ declare function object(shape: S, rules?: { unknownKeys?: "keep" | "reject"; }): Schema>; declare function temperature(): Schema; declare function dateTime(): Schema; declare function duration(): Schema; declare function timeInterval(): Schema; export declare const s: { string: typeof string; number: typeof number; boolean: typeof boolean; literal: typeof literal; enum: typeof enumeration; oneOf: typeof oneOf; unknown: typeof unknown; optional: typeof optional; nullable: typeof nullable; array: typeof array; object: typeof object; temperature: typeof temperature; dateTime: typeof dateTime; duration: typeof duration; timeInterval: typeof timeInterval; }; export {};