1 | import type { TypeOf, ZodType } from ".";
|
2 | import { Primitive } from "./helpers/typeAliases";
|
3 | import { util, ZodParsedType } from "./helpers/util";
|
4 | declare type allKeys<T> = T extends any ? keyof T : never;
|
5 | export declare type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
6 | export declare type typeToFlattenedError<T, U = string> = {
|
7 | formErrors: U[];
|
8 | fieldErrors: {
|
9 | [P in allKeys<T>]?: U[];
|
10 | };
|
11 | };
|
12 | export declare const ZodIssueCode: {
|
13 | invalid_type: "invalid_type";
|
14 | invalid_literal: "invalid_literal";
|
15 | custom: "custom";
|
16 | invalid_union: "invalid_union";
|
17 | invalid_union_discriminator: "invalid_union_discriminator";
|
18 | invalid_enum_value: "invalid_enum_value";
|
19 | unrecognized_keys: "unrecognized_keys";
|
20 | invalid_arguments: "invalid_arguments";
|
21 | invalid_return_type: "invalid_return_type";
|
22 | invalid_date: "invalid_date";
|
23 | invalid_string: "invalid_string";
|
24 | too_small: "too_small";
|
25 | too_big: "too_big";
|
26 | invalid_intersection_types: "invalid_intersection_types";
|
27 | not_multiple_of: "not_multiple_of";
|
28 | not_finite: "not_finite";
|
29 | };
|
30 | export declare type ZodIssueCode = keyof typeof ZodIssueCode;
|
31 | export declare type ZodIssueBase = {
|
32 | path: (string | number)[];
|
33 | message?: string;
|
34 | };
|
35 | export interface ZodInvalidTypeIssue extends ZodIssueBase {
|
36 | code: typeof ZodIssueCode.invalid_type;
|
37 | expected: ZodParsedType;
|
38 | received: ZodParsedType;
|
39 | }
|
40 | export interface ZodInvalidLiteralIssue extends ZodIssueBase {
|
41 | code: typeof ZodIssueCode.invalid_literal;
|
42 | expected: unknown;
|
43 | received: unknown;
|
44 | }
|
45 | export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
|
46 | code: typeof ZodIssueCode.unrecognized_keys;
|
47 | keys: string[];
|
48 | }
|
49 | export interface ZodInvalidUnionIssue extends ZodIssueBase {
|
50 | code: typeof ZodIssueCode.invalid_union;
|
51 | unionErrors: ZodError[];
|
52 | }
|
53 | export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
|
54 | code: typeof ZodIssueCode.invalid_union_discriminator;
|
55 | options: Primitive[];
|
56 | }
|
57 | export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
|
58 | received: string | number;
|
59 | code: typeof ZodIssueCode.invalid_enum_value;
|
60 | options: (string | number)[];
|
61 | }
|
62 | export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
|
63 | code: typeof ZodIssueCode.invalid_arguments;
|
64 | argumentsError: ZodError;
|
65 | }
|
66 | export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
67 | code: typeof ZodIssueCode.invalid_return_type;
|
68 | returnTypeError: ZodError;
|
69 | }
|
70 | export interface ZodInvalidDateIssue extends ZodIssueBase {
|
71 | code: typeof ZodIssueCode.invalid_date;
|
72 | }
|
73 | export declare type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "base64" | {
|
74 | includes: string;
|
75 | position?: number;
|
76 | } | {
|
77 | startsWith: string;
|
78 | } | {
|
79 | endsWith: string;
|
80 | };
|
81 | export interface ZodInvalidStringIssue extends ZodIssueBase {
|
82 | code: typeof ZodIssueCode.invalid_string;
|
83 | validation: StringValidation;
|
84 | }
|
85 | export interface ZodTooSmallIssue extends ZodIssueBase {
|
86 | code: typeof ZodIssueCode.too_small;
|
87 | minimum: number | bigint;
|
88 | inclusive: boolean;
|
89 | exact?: boolean;
|
90 | type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
91 | }
|
92 | export interface ZodTooBigIssue extends ZodIssueBase {
|
93 | code: typeof ZodIssueCode.too_big;
|
94 | maximum: number | bigint;
|
95 | inclusive: boolean;
|
96 | exact?: boolean;
|
97 | type: "array" | "string" | "number" | "set" | "date" | "bigint";
|
98 | }
|
99 | export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
|
100 | code: typeof ZodIssueCode.invalid_intersection_types;
|
101 | }
|
102 | export interface ZodNotMultipleOfIssue extends ZodIssueBase {
|
103 | code: typeof ZodIssueCode.not_multiple_of;
|
104 | multipleOf: number | bigint;
|
105 | }
|
106 | export interface ZodNotFiniteIssue extends ZodIssueBase {
|
107 | code: typeof ZodIssueCode.not_finite;
|
108 | }
|
109 | export interface ZodCustomIssue extends ZodIssueBase {
|
110 | code: typeof ZodIssueCode.custom;
|
111 | params?: {
|
112 | [k: string]: any;
|
113 | };
|
114 | }
|
115 | export declare type DenormalizedError = {
|
116 | [k: string]: DenormalizedError | string[];
|
117 | };
|
118 | export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
|
119 | export declare type ZodIssue = ZodIssueOptionalMessage & {
|
120 | fatal?: boolean;
|
121 | message: string;
|
122 | };
|
123 | export declare const quotelessJson: (obj: any) => string;
|
124 | declare type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
|
125 | [K in keyof T]?: ZodFormattedError<T[K]>;
|
126 | } : T extends any[] ? {
|
127 | [k: number]: ZodFormattedError<T[number]>;
|
128 | } : T extends object ? {
|
129 | [K in keyof T]?: ZodFormattedError<T[K]>;
|
130 | } : unknown;
|
131 | export declare type ZodFormattedError<T, U = string> = {
|
132 | _errors: U[];
|
133 | } & recursiveZodFormattedError<NonNullable<T>>;
|
134 | export declare type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
135 | export declare class ZodError<T = any> extends Error {
|
136 | issues: ZodIssue[];
|
137 | get errors(): ZodIssue[];
|
138 | constructor(issues: ZodIssue[]);
|
139 | format(): ZodFormattedError<T>;
|
140 | format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
|
141 | static create: (issues: ZodIssue[]) => ZodError<any>;
|
142 | static assert(value: unknown): asserts value is ZodError;
|
143 | toString(): string;
|
144 | get message(): string;
|
145 | get isEmpty(): boolean;
|
146 | addIssue: (sub: ZodIssue) => void;
|
147 | addIssues: (subs?: ZodIssue[]) => void;
|
148 | flatten(): typeToFlattenedError<T>;
|
149 | flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
150 | get formErrors(): typeToFlattenedError<T, string>;
|
151 | }
|
152 | declare type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
153 | export declare type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
154 | path?: (string | number)[];
|
155 | fatal?: boolean;
|
156 | };
|
157 | export declare type ErrorMapCtx = {
|
158 | defaultError: string;
|
159 | data: any;
|
160 | };
|
161 | export declare type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
|
162 | message: string;
|
163 | };
|
164 | export {};
|