zod 3.24.0 → 3.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ZodError.d.ts +16 -16
- package/lib/ZodError.js +3 -3
- package/lib/external.js +5 -1
- package/lib/helpers/errorUtil.d.ts +2 -2
- package/lib/helpers/errorUtil.js +1 -1
- package/lib/helpers/parseUtil.d.ts +11 -11
- package/lib/helpers/parseUtil.js +3 -3
- package/lib/helpers/typeAliases.d.ts +2 -2
- package/lib/helpers/util.d.ts +9 -9
- package/lib/helpers/util.js +2 -2
- package/lib/index.js +5 -1
- package/lib/index.mjs +47 -45
- package/lib/index.umd.js +47 -45
- package/lib/standard-schema.d.ts +1 -1
- package/lib/types.d.ts +129 -220
- package/lib/types.js +42 -40
- package/package.json +2 -2
package/lib/ZodError.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TypeOf, ZodType } from ".";
|
|
2
2
|
import { Primitive } from "./helpers/typeAliases";
|
|
3
3
|
import { util, ZodParsedType } from "./helpers/util";
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
type allKeys<T> = T extends any ? keyof T : never;
|
|
5
|
+
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
|
6
|
+
export type typeToFlattenedError<T, U = string> = {
|
|
7
7
|
formErrors: U[];
|
|
8
8
|
fieldErrors: {
|
|
9
9
|
[P in allKeys<T>]?: U[];
|
|
@@ -27,8 +27,8 @@ export declare const ZodIssueCode: {
|
|
|
27
27
|
not_multiple_of: "not_multiple_of";
|
|
28
28
|
not_finite: "not_finite";
|
|
29
29
|
};
|
|
30
|
-
export
|
|
31
|
-
export
|
|
30
|
+
export type ZodIssueCode = keyof typeof ZodIssueCode;
|
|
31
|
+
export type ZodIssueBase = {
|
|
32
32
|
path: (string | number)[];
|
|
33
33
|
message?: string;
|
|
34
34
|
};
|
|
@@ -70,7 +70,7 @@ export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
|
|
|
70
70
|
export interface ZodInvalidDateIssue extends ZodIssueBase {
|
|
71
71
|
code: typeof ZodIssueCode.invalid_date;
|
|
72
72
|
}
|
|
73
|
-
export
|
|
73
|
+
export type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "cidr" | "base64" | "jwt" | "base64url" | {
|
|
74
74
|
includes: string;
|
|
75
75
|
position?: number;
|
|
76
76
|
} | {
|
|
@@ -112,26 +112,26 @@ export interface ZodCustomIssue extends ZodIssueBase {
|
|
|
112
112
|
[k: string]: any;
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
export
|
|
115
|
+
export type DenormalizedError = {
|
|
116
116
|
[k: string]: DenormalizedError | string[];
|
|
117
117
|
};
|
|
118
|
-
export
|
|
119
|
-
export
|
|
118
|
+
export type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
|
|
119
|
+
export type ZodIssue = ZodIssueOptionalMessage & {
|
|
120
120
|
fatal?: boolean;
|
|
121
121
|
message: string;
|
|
122
122
|
};
|
|
123
123
|
export declare const quotelessJson: (obj: any) => string;
|
|
124
|
-
|
|
124
|
+
type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
|
|
125
125
|
[K in keyof T]?: ZodFormattedError<T[K]>;
|
|
126
126
|
} : T extends any[] ? {
|
|
127
127
|
[k: number]: ZodFormattedError<T[number]>;
|
|
128
128
|
} : T extends object ? {
|
|
129
129
|
[K in keyof T]?: ZodFormattedError<T[K]>;
|
|
130
130
|
} : unknown;
|
|
131
|
-
export
|
|
131
|
+
export type ZodFormattedError<T, U = string> = {
|
|
132
132
|
_errors: U[];
|
|
133
133
|
} & recursiveZodFormattedError<NonNullable<T>>;
|
|
134
|
-
export
|
|
134
|
+
export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
|
|
135
135
|
export declare class ZodError<T = any> extends Error {
|
|
136
136
|
issues: ZodIssue[];
|
|
137
137
|
get errors(): ZodIssue[];
|
|
@@ -149,16 +149,16 @@ export declare class ZodError<T = any> extends Error {
|
|
|
149
149
|
flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
|
|
150
150
|
get formErrors(): typeToFlattenedError<T, string>;
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
export
|
|
152
|
+
type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
|
|
153
|
+
export type IssueData = stripPath<ZodIssueOptionalMessage> & {
|
|
154
154
|
path?: (string | number)[];
|
|
155
155
|
fatal?: boolean;
|
|
156
156
|
};
|
|
157
|
-
export
|
|
157
|
+
export type ErrorMapCtx = {
|
|
158
158
|
defaultError: string;
|
|
159
159
|
data: any;
|
|
160
160
|
};
|
|
161
|
-
export
|
|
161
|
+
export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
|
|
162
162
|
message: string;
|
|
163
163
|
};
|
|
164
164
|
export {};
|
package/lib/ZodError.js
CHANGED
|
@@ -26,6 +26,9 @@ const quotelessJson = (obj) => {
|
|
|
26
26
|
};
|
|
27
27
|
exports.quotelessJson = quotelessJson;
|
|
28
28
|
class ZodError extends Error {
|
|
29
|
+
get errors() {
|
|
30
|
+
return this.issues;
|
|
31
|
+
}
|
|
29
32
|
constructor(issues) {
|
|
30
33
|
super();
|
|
31
34
|
this.issues = [];
|
|
@@ -46,9 +49,6 @@ class ZodError extends Error {
|
|
|
46
49
|
this.name = "ZodError";
|
|
47
50
|
this.issues = issues;
|
|
48
51
|
}
|
|
49
|
-
get errors() {
|
|
50
|
-
return this.issues;
|
|
51
|
-
}
|
|
52
52
|
format(_mapper) {
|
|
53
53
|
const mapper = _mapper ||
|
|
54
54
|
function (issue) {
|
package/lib/external.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -2,8 +2,8 @@ export declare namespace errorUtil {
|
|
|
2
2
|
type ErrMessage = string | {
|
|
3
3
|
message?: string;
|
|
4
4
|
};
|
|
5
|
-
const errToObj: (message?: ErrMessage
|
|
5
|
+
const errToObj: (message?: ErrMessage) => {
|
|
6
6
|
message?: string | undefined;
|
|
7
7
|
};
|
|
8
|
-
const toString: (message?: ErrMessage
|
|
8
|
+
const toString: (message?: ErrMessage) => string | undefined;
|
|
9
9
|
}
|
package/lib/helpers/errorUtil.js
CHANGED
|
@@ -5,4 +5,4 @@ var errorUtil;
|
|
|
5
5
|
(function (errorUtil) {
|
|
6
6
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
7
7
|
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
8
|
-
})(errorUtil
|
|
8
|
+
})(errorUtil || (exports.errorUtil = errorUtil = {}));
|
|
@@ -6,13 +6,13 @@ export declare const makeIssue: (params: {
|
|
|
6
6
|
errorMaps: ZodErrorMap[];
|
|
7
7
|
issueData: IssueData;
|
|
8
8
|
}) => ZodIssue;
|
|
9
|
-
export
|
|
9
|
+
export type ParseParams = {
|
|
10
10
|
path: (string | number)[];
|
|
11
11
|
errorMap: ZodErrorMap;
|
|
12
12
|
async: boolean;
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export
|
|
14
|
+
export type ParsePathComponent = string | number;
|
|
15
|
+
export type ParsePath = ParsePathComponent[];
|
|
16
16
|
export declare const EMPTY_PATH: ParsePath;
|
|
17
17
|
export interface ParseContext {
|
|
18
18
|
readonly common: {
|
|
@@ -26,13 +26,13 @@ export interface ParseContext {
|
|
|
26
26
|
readonly data: any;
|
|
27
27
|
readonly parsedType: ZodParsedType;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export type ParseInput = {
|
|
30
30
|
data: any;
|
|
31
31
|
path: (string | number)[];
|
|
32
32
|
parent: ParseContext;
|
|
33
33
|
};
|
|
34
34
|
export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
|
|
35
|
-
export
|
|
35
|
+
export type ObjectPair = {
|
|
36
36
|
key: SyncParseReturnType<any>;
|
|
37
37
|
value: SyncParseReturnType<any>;
|
|
38
38
|
};
|
|
@@ -55,23 +55,23 @@ export interface ParseResult {
|
|
|
55
55
|
status: "aborted" | "dirty" | "valid";
|
|
56
56
|
data: any;
|
|
57
57
|
}
|
|
58
|
-
export
|
|
58
|
+
export type INVALID = {
|
|
59
59
|
status: "aborted";
|
|
60
60
|
};
|
|
61
61
|
export declare const INVALID: INVALID;
|
|
62
|
-
export
|
|
62
|
+
export type DIRTY<T> = {
|
|
63
63
|
status: "dirty";
|
|
64
64
|
value: T;
|
|
65
65
|
};
|
|
66
66
|
export declare const DIRTY: <T>(value: T) => DIRTY<T>;
|
|
67
|
-
export
|
|
67
|
+
export type OK<T> = {
|
|
68
68
|
status: "valid";
|
|
69
69
|
value: T;
|
|
70
70
|
};
|
|
71
71
|
export declare const OK: <T>(value: T) => OK<T>;
|
|
72
|
-
export
|
|
73
|
-
export
|
|
74
|
-
export
|
|
72
|
+
export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
|
|
73
|
+
export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
|
|
74
|
+
export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
|
|
75
75
|
export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
|
|
76
76
|
export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
|
|
77
77
|
export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T>;
|
package/lib/helpers/parseUtil.js
CHANGED
|
@@ -43,9 +43,9 @@ function addIssueToContext(ctx, issueData) {
|
|
|
43
43
|
data: ctx.data,
|
|
44
44
|
path: ctx.path,
|
|
45
45
|
errorMaps: [
|
|
46
|
-
ctx.common.contextualErrorMap,
|
|
47
|
-
ctx.schemaErrorMap,
|
|
48
|
-
overrideMap,
|
|
46
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
47
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
48
|
+
overrideMap, // then global override map
|
|
49
49
|
overrideMap === en_1.default ? undefined : en_1.default, // then global default map
|
|
50
50
|
].filter((x) => !!x),
|
|
51
51
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
2
|
+
export type Scalars = Primitive | Primitive[];
|
package/lib/helpers/util.d.ts
CHANGED
|
@@ -57,26 +57,26 @@ export declare namespace objectUtil {
|
|
|
57
57
|
export {};
|
|
58
58
|
}
|
|
59
59
|
export declare const ZodParsedType: {
|
|
60
|
-
function: "function";
|
|
61
|
-
number: "number";
|
|
62
60
|
string: "string";
|
|
61
|
+
number: "number";
|
|
62
|
+
bigint: "bigint";
|
|
63
|
+
boolean: "boolean";
|
|
64
|
+
symbol: "symbol";
|
|
65
|
+
undefined: "undefined";
|
|
66
|
+
object: "object";
|
|
67
|
+
function: "function";
|
|
68
|
+
map: "map";
|
|
63
69
|
nan: "nan";
|
|
64
70
|
integer: "integer";
|
|
65
71
|
float: "float";
|
|
66
|
-
boolean: "boolean";
|
|
67
72
|
date: "date";
|
|
68
|
-
bigint: "bigint";
|
|
69
|
-
symbol: "symbol";
|
|
70
|
-
undefined: "undefined";
|
|
71
73
|
null: "null";
|
|
72
74
|
array: "array";
|
|
73
|
-
object: "object";
|
|
74
75
|
unknown: "unknown";
|
|
75
76
|
promise: "promise";
|
|
76
77
|
void: "void";
|
|
77
78
|
never: "never";
|
|
78
|
-
map: "map";
|
|
79
79
|
set: "set";
|
|
80
80
|
};
|
|
81
|
-
export
|
|
81
|
+
export type ZodParsedType = keyof typeof ZodParsedType;
|
|
82
82
|
export declare const getParsedType: (data: any) => ZodParsedType;
|
package/lib/helpers/util.js
CHANGED
|
@@ -63,7 +63,7 @@ var util;
|
|
|
63
63
|
}
|
|
64
64
|
return value;
|
|
65
65
|
};
|
|
66
|
-
})(util
|
|
66
|
+
})(util || (exports.util = util = {}));
|
|
67
67
|
var objectUtil;
|
|
68
68
|
(function (objectUtil) {
|
|
69
69
|
objectUtil.mergeShapes = (first, second) => {
|
|
@@ -72,7 +72,7 @@ var objectUtil;
|
|
|
72
72
|
...second, // second overwrites first
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
|
-
})(objectUtil
|
|
75
|
+
})(objectUtil || (exports.objectUtil = objectUtil = {}));
|
|
76
76
|
exports.ZodParsedType = util.arrayToEnum([
|
|
77
77
|
"string",
|
|
78
78
|
"nan",
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.mjs
CHANGED
|
@@ -160,6 +160,9 @@ const quotelessJson = (obj) => {
|
|
|
160
160
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
161
161
|
};
|
|
162
162
|
class ZodError extends Error {
|
|
163
|
+
get errors() {
|
|
164
|
+
return this.issues;
|
|
165
|
+
}
|
|
163
166
|
constructor(issues) {
|
|
164
167
|
super();
|
|
165
168
|
this.issues = [];
|
|
@@ -180,9 +183,6 @@ class ZodError extends Error {
|
|
|
180
183
|
this.name = "ZodError";
|
|
181
184
|
this.issues = issues;
|
|
182
185
|
}
|
|
183
|
-
get errors() {
|
|
184
|
-
return this.issues;
|
|
185
|
-
}
|
|
186
186
|
format(_mapper) {
|
|
187
187
|
const mapper = _mapper ||
|
|
188
188
|
function (issue) {
|
|
@@ -438,9 +438,9 @@ function addIssueToContext(ctx, issueData) {
|
|
|
438
438
|
data: ctx.data,
|
|
439
439
|
path: ctx.path,
|
|
440
440
|
errorMaps: [
|
|
441
|
-
ctx.common.contextualErrorMap,
|
|
442
|
-
ctx.schemaErrorMap,
|
|
443
|
-
overrideMap,
|
|
441
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
442
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
443
|
+
overrideMap, // then global override map
|
|
444
444
|
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
445
445
|
].filter((x) => !!x),
|
|
446
446
|
});
|
|
@@ -616,40 +616,6 @@ function processCreateParams(params) {
|
|
|
616
616
|
return { errorMap: customMap, description };
|
|
617
617
|
}
|
|
618
618
|
class ZodType {
|
|
619
|
-
constructor(def) {
|
|
620
|
-
/** Alias of safeParseAsync */
|
|
621
|
-
this.spa = this.safeParseAsync;
|
|
622
|
-
this._def = def;
|
|
623
|
-
this.parse = this.parse.bind(this);
|
|
624
|
-
this.safeParse = this.safeParse.bind(this);
|
|
625
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
626
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
627
|
-
this.spa = this.spa.bind(this);
|
|
628
|
-
this.refine = this.refine.bind(this);
|
|
629
|
-
this.refinement = this.refinement.bind(this);
|
|
630
|
-
this.superRefine = this.superRefine.bind(this);
|
|
631
|
-
this.optional = this.optional.bind(this);
|
|
632
|
-
this.nullable = this.nullable.bind(this);
|
|
633
|
-
this.nullish = this.nullish.bind(this);
|
|
634
|
-
this.array = this.array.bind(this);
|
|
635
|
-
this.promise = this.promise.bind(this);
|
|
636
|
-
this.or = this.or.bind(this);
|
|
637
|
-
this.and = this.and.bind(this);
|
|
638
|
-
this.transform = this.transform.bind(this);
|
|
639
|
-
this.brand = this.brand.bind(this);
|
|
640
|
-
this.default = this.default.bind(this);
|
|
641
|
-
this.catch = this.catch.bind(this);
|
|
642
|
-
this.describe = this.describe.bind(this);
|
|
643
|
-
this.pipe = this.pipe.bind(this);
|
|
644
|
-
this.readonly = this.readonly.bind(this);
|
|
645
|
-
this.isNullable = this.isNullable.bind(this);
|
|
646
|
-
this.isOptional = this.isOptional.bind(this);
|
|
647
|
-
this["~standard"] = {
|
|
648
|
-
version: 1,
|
|
649
|
-
vendor: "zod",
|
|
650
|
-
validate: (data) => this["~validate"](data),
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
619
|
get description() {
|
|
654
620
|
return this._def.description;
|
|
655
621
|
}
|
|
@@ -714,7 +680,7 @@ class ZodType {
|
|
|
714
680
|
return handleResult(ctx, result);
|
|
715
681
|
}
|
|
716
682
|
"~validate"(data) {
|
|
717
|
-
var _a, _b
|
|
683
|
+
var _a, _b;
|
|
718
684
|
const ctx = {
|
|
719
685
|
common: {
|
|
720
686
|
issues: [],
|
|
@@ -738,7 +704,7 @@ class ZodType {
|
|
|
738
704
|
};
|
|
739
705
|
}
|
|
740
706
|
catch (err) {
|
|
741
|
-
if ((
|
|
707
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
742
708
|
this["~standard"].async = true;
|
|
743
709
|
}
|
|
744
710
|
ctx.common = {
|
|
@@ -841,6 +807,40 @@ class ZodType {
|
|
|
841
807
|
superRefine(refinement) {
|
|
842
808
|
return this._refinement(refinement);
|
|
843
809
|
}
|
|
810
|
+
constructor(def) {
|
|
811
|
+
/** Alias of safeParseAsync */
|
|
812
|
+
this.spa = this.safeParseAsync;
|
|
813
|
+
this._def = def;
|
|
814
|
+
this.parse = this.parse.bind(this);
|
|
815
|
+
this.safeParse = this.safeParse.bind(this);
|
|
816
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
817
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
818
|
+
this.spa = this.spa.bind(this);
|
|
819
|
+
this.refine = this.refine.bind(this);
|
|
820
|
+
this.refinement = this.refinement.bind(this);
|
|
821
|
+
this.superRefine = this.superRefine.bind(this);
|
|
822
|
+
this.optional = this.optional.bind(this);
|
|
823
|
+
this.nullable = this.nullable.bind(this);
|
|
824
|
+
this.nullish = this.nullish.bind(this);
|
|
825
|
+
this.array = this.array.bind(this);
|
|
826
|
+
this.promise = this.promise.bind(this);
|
|
827
|
+
this.or = this.or.bind(this);
|
|
828
|
+
this.and = this.and.bind(this);
|
|
829
|
+
this.transform = this.transform.bind(this);
|
|
830
|
+
this.brand = this.brand.bind(this);
|
|
831
|
+
this.default = this.default.bind(this);
|
|
832
|
+
this.catch = this.catch.bind(this);
|
|
833
|
+
this.describe = this.describe.bind(this);
|
|
834
|
+
this.pipe = this.pipe.bind(this);
|
|
835
|
+
this.readonly = this.readonly.bind(this);
|
|
836
|
+
this.isNullable = this.isNullable.bind(this);
|
|
837
|
+
this.isOptional = this.isOptional.bind(this);
|
|
838
|
+
this["~standard"] = {
|
|
839
|
+
version: 1,
|
|
840
|
+
vendor: "zod",
|
|
841
|
+
validate: (data) => this["~validate"](data),
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
844
|
optional() {
|
|
845
845
|
return ZodOptional.create(this, this._def);
|
|
846
846
|
}
|
|
@@ -1398,7 +1398,10 @@ class ZodString extends ZodType {
|
|
|
1398
1398
|
}
|
|
1399
1399
|
base64url(message) {
|
|
1400
1400
|
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1401
|
-
return this._addCheck({
|
|
1401
|
+
return this._addCheck({
|
|
1402
|
+
kind: "base64url",
|
|
1403
|
+
...errorUtil.errToObj(message),
|
|
1404
|
+
});
|
|
1402
1405
|
}
|
|
1403
1406
|
jwt(options) {
|
|
1404
1407
|
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
@@ -1499,8 +1502,7 @@ class ZodString extends ZodType {
|
|
|
1499
1502
|
});
|
|
1500
1503
|
}
|
|
1501
1504
|
/**
|
|
1502
|
-
*
|
|
1503
|
-
* @see {@link ZodString.min}
|
|
1505
|
+
* Equivalent to `.min(1)`
|
|
1504
1506
|
*/
|
|
1505
1507
|
nonempty(message) {
|
|
1506
1508
|
return this.min(1, errorUtil.errToObj(message));
|
package/lib/index.umd.js
CHANGED
|
@@ -166,6 +166,9 @@
|
|
|
166
166
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
167
167
|
};
|
|
168
168
|
class ZodError extends Error {
|
|
169
|
+
get errors() {
|
|
170
|
+
return this.issues;
|
|
171
|
+
}
|
|
169
172
|
constructor(issues) {
|
|
170
173
|
super();
|
|
171
174
|
this.issues = [];
|
|
@@ -186,9 +189,6 @@
|
|
|
186
189
|
this.name = "ZodError";
|
|
187
190
|
this.issues = issues;
|
|
188
191
|
}
|
|
189
|
-
get errors() {
|
|
190
|
-
return this.issues;
|
|
191
|
-
}
|
|
192
192
|
format(_mapper) {
|
|
193
193
|
const mapper = _mapper ||
|
|
194
194
|
function (issue) {
|
|
@@ -444,9 +444,9 @@
|
|
|
444
444
|
data: ctx.data,
|
|
445
445
|
path: ctx.path,
|
|
446
446
|
errorMaps: [
|
|
447
|
-
ctx.common.contextualErrorMap,
|
|
448
|
-
ctx.schemaErrorMap,
|
|
449
|
-
overrideMap,
|
|
447
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
448
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
449
|
+
overrideMap, // then global override map
|
|
450
450
|
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
451
451
|
].filter((x) => !!x),
|
|
452
452
|
});
|
|
@@ -622,40 +622,6 @@
|
|
|
622
622
|
return { errorMap: customMap, description };
|
|
623
623
|
}
|
|
624
624
|
class ZodType {
|
|
625
|
-
constructor(def) {
|
|
626
|
-
/** Alias of safeParseAsync */
|
|
627
|
-
this.spa = this.safeParseAsync;
|
|
628
|
-
this._def = def;
|
|
629
|
-
this.parse = this.parse.bind(this);
|
|
630
|
-
this.safeParse = this.safeParse.bind(this);
|
|
631
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
632
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
633
|
-
this.spa = this.spa.bind(this);
|
|
634
|
-
this.refine = this.refine.bind(this);
|
|
635
|
-
this.refinement = this.refinement.bind(this);
|
|
636
|
-
this.superRefine = this.superRefine.bind(this);
|
|
637
|
-
this.optional = this.optional.bind(this);
|
|
638
|
-
this.nullable = this.nullable.bind(this);
|
|
639
|
-
this.nullish = this.nullish.bind(this);
|
|
640
|
-
this.array = this.array.bind(this);
|
|
641
|
-
this.promise = this.promise.bind(this);
|
|
642
|
-
this.or = this.or.bind(this);
|
|
643
|
-
this.and = this.and.bind(this);
|
|
644
|
-
this.transform = this.transform.bind(this);
|
|
645
|
-
this.brand = this.brand.bind(this);
|
|
646
|
-
this.default = this.default.bind(this);
|
|
647
|
-
this.catch = this.catch.bind(this);
|
|
648
|
-
this.describe = this.describe.bind(this);
|
|
649
|
-
this.pipe = this.pipe.bind(this);
|
|
650
|
-
this.readonly = this.readonly.bind(this);
|
|
651
|
-
this.isNullable = this.isNullable.bind(this);
|
|
652
|
-
this.isOptional = this.isOptional.bind(this);
|
|
653
|
-
this["~standard"] = {
|
|
654
|
-
version: 1,
|
|
655
|
-
vendor: "zod",
|
|
656
|
-
validate: (data) => this["~validate"](data),
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
625
|
get description() {
|
|
660
626
|
return this._def.description;
|
|
661
627
|
}
|
|
@@ -720,7 +686,7 @@
|
|
|
720
686
|
return handleResult(ctx, result);
|
|
721
687
|
}
|
|
722
688
|
"~validate"(data) {
|
|
723
|
-
var _a, _b
|
|
689
|
+
var _a, _b;
|
|
724
690
|
const ctx = {
|
|
725
691
|
common: {
|
|
726
692
|
issues: [],
|
|
@@ -744,7 +710,7 @@
|
|
|
744
710
|
};
|
|
745
711
|
}
|
|
746
712
|
catch (err) {
|
|
747
|
-
if ((
|
|
713
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
748
714
|
this["~standard"].async = true;
|
|
749
715
|
}
|
|
750
716
|
ctx.common = {
|
|
@@ -847,6 +813,40 @@
|
|
|
847
813
|
superRefine(refinement) {
|
|
848
814
|
return this._refinement(refinement);
|
|
849
815
|
}
|
|
816
|
+
constructor(def) {
|
|
817
|
+
/** Alias of safeParseAsync */
|
|
818
|
+
this.spa = this.safeParseAsync;
|
|
819
|
+
this._def = def;
|
|
820
|
+
this.parse = this.parse.bind(this);
|
|
821
|
+
this.safeParse = this.safeParse.bind(this);
|
|
822
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
823
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
824
|
+
this.spa = this.spa.bind(this);
|
|
825
|
+
this.refine = this.refine.bind(this);
|
|
826
|
+
this.refinement = this.refinement.bind(this);
|
|
827
|
+
this.superRefine = this.superRefine.bind(this);
|
|
828
|
+
this.optional = this.optional.bind(this);
|
|
829
|
+
this.nullable = this.nullable.bind(this);
|
|
830
|
+
this.nullish = this.nullish.bind(this);
|
|
831
|
+
this.array = this.array.bind(this);
|
|
832
|
+
this.promise = this.promise.bind(this);
|
|
833
|
+
this.or = this.or.bind(this);
|
|
834
|
+
this.and = this.and.bind(this);
|
|
835
|
+
this.transform = this.transform.bind(this);
|
|
836
|
+
this.brand = this.brand.bind(this);
|
|
837
|
+
this.default = this.default.bind(this);
|
|
838
|
+
this.catch = this.catch.bind(this);
|
|
839
|
+
this.describe = this.describe.bind(this);
|
|
840
|
+
this.pipe = this.pipe.bind(this);
|
|
841
|
+
this.readonly = this.readonly.bind(this);
|
|
842
|
+
this.isNullable = this.isNullable.bind(this);
|
|
843
|
+
this.isOptional = this.isOptional.bind(this);
|
|
844
|
+
this["~standard"] = {
|
|
845
|
+
version: 1,
|
|
846
|
+
vendor: "zod",
|
|
847
|
+
validate: (data) => this["~validate"](data),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
850
|
optional() {
|
|
851
851
|
return ZodOptional.create(this, this._def);
|
|
852
852
|
}
|
|
@@ -1404,7 +1404,10 @@
|
|
|
1404
1404
|
}
|
|
1405
1405
|
base64url(message) {
|
|
1406
1406
|
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1407
|
-
return this._addCheck({
|
|
1407
|
+
return this._addCheck({
|
|
1408
|
+
kind: "base64url",
|
|
1409
|
+
...errorUtil.errToObj(message),
|
|
1410
|
+
});
|
|
1408
1411
|
}
|
|
1409
1412
|
jwt(options) {
|
|
1410
1413
|
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
@@ -1505,8 +1508,7 @@
|
|
|
1505
1508
|
});
|
|
1506
1509
|
}
|
|
1507
1510
|
/**
|
|
1508
|
-
*
|
|
1509
|
-
* @see {@link ZodString.min}
|
|
1511
|
+
* Equivalent to `.min(1)`
|
|
1510
1512
|
*/
|
|
1511
1513
|
nonempty(message) {
|
|
1512
1514
|
return this.min(1, errorUtil.errToObj(message));
|
package/lib/standard-schema.d.ts
CHANGED