import * as z from 'zod/v4/core'; import type * as T from '@traversable/registry'; import type { Ctx } from './utils.js'; import type { AnyTypeName } from './typename.js'; import { TypeName } from './typename.js'; export type Index = { path: (keyof any)[]; seen: WeakMap; }; export declare const functorDefaultOptions: { initialIndex: (string | number)[]; namespaceAlias: string; }; export declare namespace Z { type Lookup = Z.Catalog[TypeName[K]]; type Catalog = { [TypeName.any]: Z.Any; [TypeName.bigint]: Z.BigInt; [TypeName.boolean]: Z.Boolean; [TypeName.date]: Z.Date; [TypeName.nan]: Z.NaN; [TypeName.never]: Z.Never; [TypeName.null]: Z.Null; [TypeName.number]: Z.Number; [TypeName.string]: Z.String; [TypeName.symbol]: Z.Symbol; [TypeName.undefined]: Z.Undefined; [TypeName.unknown]: Z.Unknown; [TypeName.void]: Z.Void; [TypeName.int]: Z.Integer; [TypeName.literal]: Z.Literal; [TypeName.file]: Z.File; [TypeName.template_literal]: Z.TemplateLiteral; [TypeName.enum]: Z.Enum; [TypeName.array]: Z.Array; [TypeName.catch]: Z.Catch; [TypeName.default]: Z.Default; [TypeName.lazy]: Z.Lazy; [TypeName.map]: Z.Map; [TypeName.nullable]: Z.Nullable; [TypeName.object]: Z.Object; [TypeName.optional]: Z.Optional; [TypeName.prefault]: Z.Prefault; [TypeName.readonly]: Z.Readonly; [TypeName.record]: Z.Record; [TypeName.set]: Z.Set; [TypeName.tuple]: Z.Tuple; [TypeName.union]: Z.Union; [TypeName.intersection]: Z.Intersection; [TypeName.pipe]: Z.Pipe; [TypeName.custom]: Z.Custom; [TypeName.nonoptional]: Z.NonOptional; [TypeName.success]: Z.Success; [TypeName.transform]: Z.Transform; /** @deprecated */ [TypeName.promise]: Z.Promise; }; type ZodLookup = ZodCatalog[TypeName[K]]; type ZodCatalog = { [TypeName.any]: z.$ZodAny; [TypeName.bigint]: z.$ZodBigInt; [TypeName.boolean]: z.$ZodBoolean; [TypeName.date]: z.$ZodDate; [TypeName.nan]: z.$ZodNaN; [TypeName.never]: z.$ZodNever; [TypeName.null]: z.$ZodNull; [TypeName.number]: z.$ZodNumber; [TypeName.string]: z.$ZodString; [TypeName.symbol]: z.$ZodSymbol; [TypeName.undefined]: z.$ZodUndefined; [TypeName.unknown]: z.$ZodUnknown; [TypeName.void]: z.$ZodVoid; [TypeName.int]: z.$ZodNumber; [TypeName.literal]: z.$ZodLiteral; [TypeName.enum]: z.$ZodEnum; [TypeName.file]: z.$ZodFile; [TypeName.template_literal]: z.$ZodTemplateLiteral; [TypeName.array]: z.$ZodArray; [TypeName.catch]: z.$ZodCatch; [TypeName.default]: z.$ZodDefault; [TypeName.lazy]: z.$ZodLazy; [TypeName.map]: z.$ZodMap; [TypeName.nullable]: z.$ZodNullable; [TypeName.object]: z.$ZodObject<{ [x: string]: T; }>; [TypeName.optional]: z.$ZodOptional; [TypeName.prefault]: z.$ZodPrefault; [TypeName.readonly]: z.$ZodReadonly; [TypeName.record]: z.$ZodRecord; [TypeName.set]: z.$ZodSet; [TypeName.tuple]: z.$ZodTuple<[T, ...T[]], T>; [TypeName.union]: z.$ZodUnion; [TypeName.intersection]: z.$ZodIntersection; [TypeName.pipe]: z.$ZodPipe; [TypeName.custom]: z.$ZodCustom; [TypeName.nonoptional]: z.$ZodNonOptional; [TypeName.success]: z.$ZodSuccess; [TypeName.transform]: z.$ZodTransform; /** @deprecated */ [TypeName.promise]: z.$ZodPromise; }; interface Proto { safeParse(x: unknown): { success: boolean; }; } interface Bag { } interface Never { _zod: { def: { type: TypeName['never']; }; }; } interface Any { _zod: { def: { type: TypeName['any']; }; }; } interface Unknown { _zod: { def: { type: TypeName['unknown']; }; }; } interface Undefined { _zod: { def: { type: TypeName['undefined']; }; }; } interface Null { _zod: { def: { type: TypeName['null']; }; }; } interface Void { _zod: { def: { type: TypeName['void']; }; }; } interface NaN { _zod: { def: { type: TypeName['nan']; }; }; } interface Symbol { _zod: { def: { type: TypeName['symbol']; }; }; } interface Boolean { _zod: { def: { type: TypeName['boolean']; }; }; } interface BigInt { _zod: { def: { type: TypeName['bigint']; }; bag: BigInt.Bag; }; } interface Number { _zod: { def: { type: TypeName['number']; checks?: Number.Check[]; }; bag: Number.Bag; }; isInt: boolean; } interface Integer { _zod: { def: { type: TypeName['int']; checks?: Integer.Check[]; }; bag: NumericBag; }; } interface String extends String.Bag { _zod: { def: { type: TypeName['string']; }; }; } interface Date { _zod: { def: { type: TypeName['date']; }; }; } interface File { _zod: { def: { type: TypeName['file']; }; }; } interface Enum { _zod: { def: { type: TypeName['enum']; entries: N; }; values: globalThis.Set; }; } interface Literal { _zod: { def: { type: TypeName['literal']; values: N[]; }; }; } interface TemplateLiteral { _zod: { def: { type: TypeName['template_literal']; parts: unknown[]; }; pattern: RegExp; }; } interface Optional { _zod: { def: { type: TypeName['optional']; innerType: S; }; }; } interface Nullable { _zod: { def: { type: TypeName['nullable']; innerType: S; }; }; } interface Array { _zod: { def: { type: TypeName['array']; element: S; }; bag: Array.Bag; }; } interface Set { _zod: { def: { type: TypeName['set']; valueType: S; }; }; } interface Map { _zod: { def: { type: TypeName['map']; keyType: S; valueType: S; }; }; } interface Readonly { _zod: { def: { type: TypeName['readonly']; innerType: S; }; }; } interface Object { _zod: { def: { type: TypeName['object']; shape: { [x: string]: S; }; catchall?: S; }; }; } interface Record { _zod: { def: { type: TypeName['record']; keyType: S; valueType: S; }; }; } interface Tuple { _zod: { def: { type: TypeName['tuple']; items: [S, ...S[]]; rest?: S; }; }; } interface Lazy { _zod: { def: { type: TypeName['lazy']; getter(): S; }; }; } interface Intersection { _zod: { def: { type: TypeName['intersection']; left: S; right: S; }; }; } interface Union { _zod: { def: { type: TypeName['union']; options: readonly [S, S, ...S[]]; discriminator?: string; }; }; } interface Catch { _zod: { def: { type: TypeName['catch']; innerType: S; catchValue(ctx: Ctx): unknown; }; }; } interface Custom { _zod: { def: { type: TypeName['custom']; }; }; } interface Default { _zod: { def: { type: TypeName['default']; innerType: S; defaultValue: (ctx: Ctx) => unknown; }; }; } interface Prefault { _zod: { def: { type: TypeName['prefault']; innerType: S; defaultValue: (ctx: Ctx) => unknown; }; }; } interface NonOptional { _zod: { def: { type: TypeName['nonoptional']; innerType: S; }; }; } interface Pipe { _zod: { def: { type: TypeName['pipe']; in: S; out: S; }; }; } interface Transform { _zod: { def: { type: TypeName['transform']; transform: (x: unknown) => S; }; }; } interface Success { _zod: { def: { type: TypeName['success']; innerType: S; }; }; } /** @deprecated */ interface Promise { _zod: { def: { type: TypeName['promise']; innerType: S; }; }; } /** * ## {@link Nullary `Z.Hole`} * * These are our base cases, a.k.a. terminal or "leaf" nodes */ type Nullary = Z.Never | Z.Any | Z.Unknown | Z.Void | Z.Undefined | Z.Null | Z.NaN | Z.Symbol | Z.Boolean | Z.BigInt | Z.Number | Z.Integer | Z.String | Z.Date | Z.File | Z.Literal | Z.TemplateLiteral; type Unary<_> = Z.Enum<_> | Z.Catch<_> | Z.Optional<_> | Z.Nullable<_> | Z.Array<_> | Z.Set<_> | Z.Map<_> | Z.Readonly<_> | Z.Object<_> | Z.Record<_> | Z.Tuple<_> | Z.Lazy<_> | Z.Intersection<_> | Z.Union<_> | Z.Default<_> | Z.Prefault<_> | Z.Success<_> | Z.NonOptional<_> | Z.Pipe<_> | Z.Transform<_> /** @deprecated */ | Z.Promise<_>; /** * ## {@link Hole `Z.Hole`} * * The members of {@link Hole `Z.Hole`} map 1-1 to the corresponding * zod schema, with the important difference that __recursion is "factored out"__. * * If you take a closer look at the type, you'll see what I mean: everywhere * where I would have made a recursive call has been replaced with {@link _ `_`}. */ type Hole<_> = Nullary | Z.Enum<_> | Z.Catch<_> | Z.Optional<_> | Z.Nullable<_> | Z.Array<_> | Z.Set<_> | Z.Map<_> | Z.Readonly<_> | Z.Object<_> | Z.Prefault<_> | Z.Record<_> | Z.Tuple<_> | Z.Lazy<_> | Z.Intersection<_> | Z.Union<_> | Z.Default<_> | Z.Success<_> | Z.NonOptional<_> | Z.Pipe<_> | Z.Transform<_> /** @deprecated */ | Z.Promise<_>; /** * ## {@link Fixpoint `Z.Fixpoint`} * * This (I believe) is our Functor's greatest fix-point. * Similar to {@link Hole `Z.Hole`}, except rather than taking * a type parameter, it "fixes" its value to itself. * * Interestingly, in TypeScript (and I would imagine most languages), * there's no obvious way to implement {@link Fixpoint `Z.Fixpoint`} * in terms of {@link Hole `Z.Hole`}. If you're not sure what I * mean, it might be a useful exercise to try, since it will give you * some intuition for why adding constraints prematurely might cause * us probems down the line. */ type Fixpoint = Nullary | Z.Enum | Z.Catch | Z.Prefault | Z.Optional | Z.Nullable | Z.Array | Z.Set | Z.Map | Z.Readonly | Z.Object | Z.Record | Z.Tuple | Z.Lazy | Z.Intersection | Z.Union | Z.Default | Z.Success | Z.NonOptional | Z.Pipe | Z.Transform /** @deprecated */ | Z.Promise; /** * ## {@link Free `Z.Free`} * * Makes {@link Hole Z.Hole} higher-kinded */ interface Free extends T.HKT { [-1]: Z.Hole; } namespace Integer { interface Check { } } interface NumericBag { minimum?: T; maximum?: T; exclusiveMinimum?: T; exclusiveMaximum?: T; multipleOf?: T; } namespace BigInt { interface Bag extends NumericBag { } } namespace Integer { interface Bag extends NumericBag { } } namespace Number { interface Bag extends NumericBag { } type GTE = { check: 'greater_than'; value: number; inclusive: true; }; type GT = { check: 'greater_than'; value: number; inclusive: false; }; type LTE = { check: 'less_than'; value: number; inclusive: true; }; type LT = { check: 'less_than'; value: number; inclusive: false; }; type Format = { format: string; }; type CheckVariant = GTE | GT | LTE | LT | Format; interface Check { _zod: { def: CheckVariant; }; } } namespace String { interface Bag { minLength?: number; maxLength?: number; } } namespace Array { interface Bag { minimum?: number; maximum?: number; length?: number; } } } export type CompilerAlgebra = { (src: T.Kind, ix: CompilerIndex, input: any): T; }; export interface CompilerIndex { dataPath: (string | number)[]; isOptional: boolean; isProperty: boolean; schemaPath: (keyof any)[]; varName: string; } export declare const defaultIndex: { dataPath: never[]; isOptional: false; isProperty: false; schemaPath: never[]; varName: string; }; export { In as in }; declare function In(x: T): Z.Hole; declare function In(x: T): Z.Hole; export { Out as out }; declare function Out(x: Z.Hole): T; export declare function lift(f: (x: T) => T): Algebra; export declare const map: T.Functor['map']; export declare const Functor: T.Functor.Ix; export declare const CompilerFunctor: T.Functor.Ix; export type Algebra = { (src: Z.Hole, ix?: Index): T; (src: z.$ZodType, ix?: Index): T; (src: Z.Hole, ix?: Index): T; }; export type Fold = (g: (src: Z.Hole, ix: Index, x: z.$ZodType) => T) => Algebra; export declare const fold: (g: (src: Z.Hole, ix: Index, x: z.$ZodType>) => T) => { (src: Z.Hole, ix?: Index | undefined): T; (src: z.$ZodType>, ix?: Index | undefined): T; (src: Z.Hole, ix?: Index | undefined): T; }; export declare const compile: (g: (src: Z.Hole, ix: CompilerIndex, x: z.$ZodType) => T) => (src: z.$ZodType, ix?: CompilerIndex) => T; export type Any = z.$ZodAny | z.$ZodUnion | z.$ZodArray | z.$ZodBigInt | z.$ZodBoolean | z.$ZodCatch | z.$ZodDate | z.$ZodDefault | z.$ZodEnum> | z.$ZodIntersection | z.$ZodLazy | z.$ZodLiteral | z.$ZodMap | z.$ZodNaN | z.$ZodNever | z.$ZodNull | z.$ZodNullable | z.$ZodNumber | z.$ZodObject<{ [x: string]: T; }> | z.$ZodArray | z.$ZodPipe | z.$ZodPromise | z.$ZodReadonly | z.$ZodRecord, T> | z.$ZodSet | z.$ZodString | z.$ZodSymbol | z.$ZodTuple<[T, ...T[]], T | null> | z.$ZodUndefined | z.$ZodUnknown | z.$ZodVoid; export type NullaryTypeName = Z.Nullary['_zod']['def']['type']; export type UnaryTypeName = Z.Unary['_zod']['def']['type']; export declare const nullaryTypeNames: ["any", "bigint", "boolean", "date", "literal", "nan", "never", "null", "number", "string", "symbol", "template_literal", "undefined", "unknown", "void"]; export declare const isNullaryTypeName: (x: unknown) => x is NullaryTypeName; export declare const isNullary: (x: unknown) => x is Z.Nullary; export declare const isUnary: (x: unknown) => x is Z.Unary; //# sourceMappingURL=functor.d.ts.map