/** * ParamDescriptors — JSON-to-Zod Converter with TypeScript Inference * * Converts plain JSON-like param descriptors into Zod schemas internally. * Supports string shorthands, object descriptors with constraints, enums, * arrays, and examples for few-shot LLM prompting. * * @example * ```typescript * // String shorthand * { name: 'string' } → z.object({ name: z.string() }) * * // Object descriptor with constraints * { name: { type: 'string', min: 3, max: 100, description: 'Name' } } * * // Enum * { status: { enum: ['active', 'archived'], optional: true } } * * // Examples for LLM few-shot * { cron: { type: 'string', examples: ['0 12 * * *'] } } * ``` * * @internal * @module */ import { type ZodObject, type ZodRawShape } from 'zod'; /** Primitive type strings accepted as shorthand */ type PrimitiveType = 'string' | 'number' | 'boolean'; /** String param descriptor */ export interface StringParamDef { readonly type: 'string'; readonly description?: string; readonly optional?: boolean; readonly min?: number; readonly max?: number; readonly regex?: string; readonly examples?: readonly string[]; } /** Number param descriptor */ export interface NumberParamDef { readonly type: 'number'; readonly description?: string; readonly optional?: boolean; readonly min?: number; readonly max?: number; readonly int?: boolean; readonly examples?: readonly number[]; } /** Boolean param descriptor */ export interface BooleanParamDef { readonly type: 'boolean'; readonly description?: string; readonly optional?: boolean; } /** Enum param descriptor */ export interface EnumParamDef { readonly enum: readonly [V, ...V[]]; readonly description?: string; readonly optional?: boolean; readonly examples?: readonly V[]; } /** Array param descriptor */ export interface ArrayParamDef { readonly array: PrimitiveType; readonly description?: string; readonly optional?: boolean; readonly min?: number; readonly max?: number; } /** Any object-style param descriptor */ export type ObjectParamDef = StringParamDef | NumberParamDef | BooleanParamDef | EnumParamDef | ArrayParamDef; /** Any valid param value: shorthand string or object descriptor */ export type ParamDef = PrimitiveType | ObjectParamDef; /** Map of param names to their definitions */ export type ParamsMap = Record; /** Infer the TypeScript type for a single param descriptor */ type InferSingleParam = T extends 'string' ? string : T extends 'number' ? number : T extends 'boolean' ? boolean : T extends { type: 'string'; } ? string : T extends { type: 'number'; } ? number : T extends { type: 'boolean'; } ? boolean : T extends { enum: readonly (infer V)[]; } ? V : T extends { array: 'string'; } ? string[] : T extends { array: 'number'; } ? number[] : T extends { array: 'boolean'; } ? boolean[] : unknown; /** Check if a param is optional */ type IsOptional = T extends { optional: true; } ? true : T extends PrimitiveType ? false : T extends { optional?: false | undefined; } ? false : false; /** Required keys from a ParamsMap */ type RequiredKeys = { [K in keyof T]: IsOptional extends true ? never : K; }[keyof T]; /** Optional keys from a ParamsMap */ type OptionalKeys = { [K in keyof T]: IsOptional extends true ? K : never; }[keyof T]; /** * Infer the full args type from a ParamsMap. * * Required params become required properties, optional params become * optional properties with `| undefined`. */ export type InferParams = { [K in RequiredKeys]: InferSingleParam; } & { [K in OptionalKeys]?: InferSingleParam; }; /** * Convert a ParamsMap to a Zod object schema. * * @param params - Plain JSON param descriptors * @returns A ZodObject with full validation * * @example * ```typescript * const schema = convertParamsToZod({ * name: 'string', * status: { enum: ['active', 'archived'], optional: true }, * limit: { type: 'number', min: 1, max: 100, optional: true }, * }); * // Equivalent to: * // z.object({ * // name: z.string(), * // status: z.enum(['active','archived']).optional(), * // limit: z.number().min(1).max(100).optional(), * // }) * ``` * * @internal */ export declare function convertParamsToZod(params: ParamsMap): ZodObject; export {}; //# sourceMappingURL=ParamDescriptors.d.ts.map