zod 3.17.0 → 3.17.2
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 +1 -2
- package/lib/ZodError.js +1 -2
- package/lib/external.d.ts +1 -0
- package/lib/external.js +4 -0
- package/lib/helpers/parseUtil.d.ts +2 -25
- package/lib/helpers/parseUtil.js +1 -67
- package/lib/helpers/util.d.ts +24 -0
- package/lib/helpers/util.js +66 -1
- package/lib/index.mjs +68 -66
- package/lib/index.umd.js +68 -66
- package/lib/types.js +57 -55
- package/package.json +1 -1
package/lib/ZodError.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { TypeOf, ZodType } from ".";
|
|
2
|
-
import { ZodParsedType } from "./helpers/parseUtil";
|
|
3
2
|
import { Primitive } from "./helpers/typeAliases";
|
|
4
|
-
import { util } from "./helpers/util";
|
|
3
|
+
import { util, ZodParsedType } from "./helpers/util";
|
|
5
4
|
declare type allKeys<T> = T extends any ? keyof T : never;
|
|
6
5
|
export declare type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
|
7
6
|
export declare type typeToFlattenedError<T, U = string> = {
|
package/lib/ZodError.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setErrorMap = exports.overrideErrorMap = exports.defaultErrorMap = exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
|
|
4
|
-
const parseUtil_1 = require("./helpers/parseUtil");
|
|
5
4
|
const util_1 = require("./helpers/util");
|
|
6
5
|
exports.ZodIssueCode = util_1.util.arrayToEnum([
|
|
7
6
|
"invalid_type",
|
|
@@ -134,7 +133,7 @@ const defaultErrorMap = (issue, _ctx) => {
|
|
|
134
133
|
let message;
|
|
135
134
|
switch (issue.code) {
|
|
136
135
|
case exports.ZodIssueCode.invalid_type:
|
|
137
|
-
if (issue.received ===
|
|
136
|
+
if (issue.received === util_1.ZodParsedType.undefined) {
|
|
138
137
|
message = "Required";
|
|
139
138
|
}
|
|
140
139
|
else {
|
package/lib/external.d.ts
CHANGED
package/lib/external.js
CHANGED
|
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ZodParsedType = exports.getParsedType = void 0;
|
|
17
18
|
__exportStar(require("./helpers/parseUtil"), exports);
|
|
18
19
|
__exportStar(require("./helpers/typeAliases"), exports);
|
|
20
|
+
var util_1 = require("./helpers/util");
|
|
21
|
+
Object.defineProperty(exports, "getParsedType", { enumerable: true, get: function () { return util_1.getParsedType; } });
|
|
22
|
+
Object.defineProperty(exports, "ZodParsedType", { enumerable: true, get: function () { return util_1.ZodParsedType; } });
|
|
19
23
|
__exportStar(require("./types"), exports);
|
|
20
24
|
__exportStar(require("./ZodError"), exports);
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
|
|
2
|
-
|
|
3
|
-
function: "function";
|
|
4
|
-
number: "number";
|
|
5
|
-
string: "string";
|
|
6
|
-
nan: "nan";
|
|
7
|
-
integer: "integer";
|
|
8
|
-
float: "float";
|
|
9
|
-
boolean: "boolean";
|
|
10
|
-
date: "date";
|
|
11
|
-
bigint: "bigint";
|
|
12
|
-
symbol: "symbol";
|
|
13
|
-
undefined: "undefined";
|
|
14
|
-
null: "null";
|
|
15
|
-
array: "array";
|
|
16
|
-
object: "object";
|
|
17
|
-
unknown: "unknown";
|
|
18
|
-
promise: "promise";
|
|
19
|
-
void: "void";
|
|
20
|
-
never: "never";
|
|
21
|
-
map: "map";
|
|
22
|
-
set: "set";
|
|
23
|
-
};
|
|
24
|
-
export declare type ZodParsedType = keyof typeof ZodParsedType;
|
|
25
|
-
export declare const getParsedType: (data: any) => ZodParsedType;
|
|
1
|
+
import { type IssueData, type ZodErrorMap, type ZodIssue } from "../ZodError";
|
|
2
|
+
import { type ZodParsedType } from "./util";
|
|
26
3
|
export declare const makeIssue: (params: {
|
|
27
4
|
data: any;
|
|
28
5
|
path: (string | number)[];
|
package/lib/helpers/parseUtil.js
CHANGED
|
@@ -1,73 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue =
|
|
3
|
+
exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
|
|
4
4
|
const ZodError_1 = require("../ZodError");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
exports.ZodParsedType = util_1.util.arrayToEnum([
|
|
7
|
-
"string",
|
|
8
|
-
"nan",
|
|
9
|
-
"number",
|
|
10
|
-
"integer",
|
|
11
|
-
"float",
|
|
12
|
-
"boolean",
|
|
13
|
-
"date",
|
|
14
|
-
"bigint",
|
|
15
|
-
"symbol",
|
|
16
|
-
"function",
|
|
17
|
-
"undefined",
|
|
18
|
-
"null",
|
|
19
|
-
"array",
|
|
20
|
-
"object",
|
|
21
|
-
"unknown",
|
|
22
|
-
"promise",
|
|
23
|
-
"void",
|
|
24
|
-
"never",
|
|
25
|
-
"map",
|
|
26
|
-
"set",
|
|
27
|
-
]);
|
|
28
|
-
const getParsedType = (data) => {
|
|
29
|
-
const t = typeof data;
|
|
30
|
-
switch (t) {
|
|
31
|
-
case "undefined":
|
|
32
|
-
return exports.ZodParsedType.undefined;
|
|
33
|
-
case "string":
|
|
34
|
-
return exports.ZodParsedType.string;
|
|
35
|
-
case "number":
|
|
36
|
-
return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
|
|
37
|
-
case "boolean":
|
|
38
|
-
return exports.ZodParsedType.boolean;
|
|
39
|
-
case "function":
|
|
40
|
-
return exports.ZodParsedType.function;
|
|
41
|
-
case "bigint":
|
|
42
|
-
return exports.ZodParsedType.bigint;
|
|
43
|
-
case "object":
|
|
44
|
-
if (Array.isArray(data)) {
|
|
45
|
-
return exports.ZodParsedType.array;
|
|
46
|
-
}
|
|
47
|
-
if (data === null) {
|
|
48
|
-
return exports.ZodParsedType.null;
|
|
49
|
-
}
|
|
50
|
-
if (data.then &&
|
|
51
|
-
typeof data.then === "function" &&
|
|
52
|
-
data.catch &&
|
|
53
|
-
typeof data.catch === "function") {
|
|
54
|
-
return exports.ZodParsedType.promise;
|
|
55
|
-
}
|
|
56
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
57
|
-
return exports.ZodParsedType.map;
|
|
58
|
-
}
|
|
59
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
60
|
-
return exports.ZodParsedType.set;
|
|
61
|
-
}
|
|
62
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
63
|
-
return exports.ZodParsedType.date;
|
|
64
|
-
}
|
|
65
|
-
return exports.ZodParsedType.object;
|
|
66
|
-
default:
|
|
67
|
-
return exports.ZodParsedType.unknown;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
exports.getParsedType = getParsedType;
|
|
71
5
|
const makeIssue = (params) => {
|
|
72
6
|
const { data, path, errorMaps, issueData } = params;
|
|
73
7
|
const fullPath = [...path, ...(issueData.path || [])];
|
package/lib/helpers/util.d.ts
CHANGED
|
@@ -17,3 +17,27 @@ export declare namespace util {
|
|
|
17
17
|
const isInteger: NumberConstructor["isInteger"];
|
|
18
18
|
function joinValues<T extends any[]>(array: T, separator?: string): string;
|
|
19
19
|
}
|
|
20
|
+
export declare const ZodParsedType: {
|
|
21
|
+
function: "function";
|
|
22
|
+
number: "number";
|
|
23
|
+
string: "string";
|
|
24
|
+
nan: "nan";
|
|
25
|
+
integer: "integer";
|
|
26
|
+
float: "float";
|
|
27
|
+
boolean: "boolean";
|
|
28
|
+
date: "date";
|
|
29
|
+
bigint: "bigint";
|
|
30
|
+
symbol: "symbol";
|
|
31
|
+
undefined: "undefined";
|
|
32
|
+
null: "null";
|
|
33
|
+
array: "array";
|
|
34
|
+
object: "object";
|
|
35
|
+
unknown: "unknown";
|
|
36
|
+
promise: "promise";
|
|
37
|
+
void: "void";
|
|
38
|
+
never: "never";
|
|
39
|
+
map: "map";
|
|
40
|
+
set: "set";
|
|
41
|
+
};
|
|
42
|
+
export declare type ZodParsedType = keyof typeof ZodParsedType;
|
|
43
|
+
export declare const getParsedType: (data: any) => ZodParsedType;
|
package/lib/helpers/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.util = void 0;
|
|
3
|
+
exports.getParsedType = exports.ZodParsedType = exports.util = void 0;
|
|
4
4
|
var util;
|
|
5
5
|
(function (util) {
|
|
6
6
|
function assertNever(_x) {
|
|
@@ -55,3 +55,68 @@ var util;
|
|
|
55
55
|
}
|
|
56
56
|
util.joinValues = joinValues;
|
|
57
57
|
})(util = exports.util || (exports.util = {}));
|
|
58
|
+
exports.ZodParsedType = util.arrayToEnum([
|
|
59
|
+
"string",
|
|
60
|
+
"nan",
|
|
61
|
+
"number",
|
|
62
|
+
"integer",
|
|
63
|
+
"float",
|
|
64
|
+
"boolean",
|
|
65
|
+
"date",
|
|
66
|
+
"bigint",
|
|
67
|
+
"symbol",
|
|
68
|
+
"function",
|
|
69
|
+
"undefined",
|
|
70
|
+
"null",
|
|
71
|
+
"array",
|
|
72
|
+
"object",
|
|
73
|
+
"unknown",
|
|
74
|
+
"promise",
|
|
75
|
+
"void",
|
|
76
|
+
"never",
|
|
77
|
+
"map",
|
|
78
|
+
"set",
|
|
79
|
+
]);
|
|
80
|
+
const getParsedType = (data) => {
|
|
81
|
+
const t = typeof data;
|
|
82
|
+
switch (t) {
|
|
83
|
+
case "undefined":
|
|
84
|
+
return exports.ZodParsedType.undefined;
|
|
85
|
+
case "string":
|
|
86
|
+
return exports.ZodParsedType.string;
|
|
87
|
+
case "number":
|
|
88
|
+
return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
|
|
89
|
+
case "boolean":
|
|
90
|
+
return exports.ZodParsedType.boolean;
|
|
91
|
+
case "function":
|
|
92
|
+
return exports.ZodParsedType.function;
|
|
93
|
+
case "bigint":
|
|
94
|
+
return exports.ZodParsedType.bigint;
|
|
95
|
+
case "object":
|
|
96
|
+
if (Array.isArray(data)) {
|
|
97
|
+
return exports.ZodParsedType.array;
|
|
98
|
+
}
|
|
99
|
+
if (data === null) {
|
|
100
|
+
return exports.ZodParsedType.null;
|
|
101
|
+
}
|
|
102
|
+
if (data.then &&
|
|
103
|
+
typeof data.then === "function" &&
|
|
104
|
+
data.catch &&
|
|
105
|
+
typeof data.catch === "function") {
|
|
106
|
+
return exports.ZodParsedType.promise;
|
|
107
|
+
}
|
|
108
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
109
|
+
return exports.ZodParsedType.map;
|
|
110
|
+
}
|
|
111
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
112
|
+
return exports.ZodParsedType.set;
|
|
113
|
+
}
|
|
114
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
115
|
+
return exports.ZodParsedType.date;
|
|
116
|
+
}
|
|
117
|
+
return exports.ZodParsedType.object;
|
|
118
|
+
default:
|
|
119
|
+
return exports.ZodParsedType.unknown;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
exports.getParsedType = getParsedType;
|
package/lib/index.mjs
CHANGED
|
@@ -52,6 +52,70 @@ var util;
|
|
|
52
52
|
}
|
|
53
53
|
util.joinValues = joinValues;
|
|
54
54
|
})(util || (util = {}));
|
|
55
|
+
const ZodParsedType = util.arrayToEnum([
|
|
56
|
+
"string",
|
|
57
|
+
"nan",
|
|
58
|
+
"number",
|
|
59
|
+
"integer",
|
|
60
|
+
"float",
|
|
61
|
+
"boolean",
|
|
62
|
+
"date",
|
|
63
|
+
"bigint",
|
|
64
|
+
"symbol",
|
|
65
|
+
"function",
|
|
66
|
+
"undefined",
|
|
67
|
+
"null",
|
|
68
|
+
"array",
|
|
69
|
+
"object",
|
|
70
|
+
"unknown",
|
|
71
|
+
"promise",
|
|
72
|
+
"void",
|
|
73
|
+
"never",
|
|
74
|
+
"map",
|
|
75
|
+
"set",
|
|
76
|
+
]);
|
|
77
|
+
const getParsedType = (data) => {
|
|
78
|
+
const t = typeof data;
|
|
79
|
+
switch (t) {
|
|
80
|
+
case "undefined":
|
|
81
|
+
return ZodParsedType.undefined;
|
|
82
|
+
case "string":
|
|
83
|
+
return ZodParsedType.string;
|
|
84
|
+
case "number":
|
|
85
|
+
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
86
|
+
case "boolean":
|
|
87
|
+
return ZodParsedType.boolean;
|
|
88
|
+
case "function":
|
|
89
|
+
return ZodParsedType.function;
|
|
90
|
+
case "bigint":
|
|
91
|
+
return ZodParsedType.bigint;
|
|
92
|
+
case "object":
|
|
93
|
+
if (Array.isArray(data)) {
|
|
94
|
+
return ZodParsedType.array;
|
|
95
|
+
}
|
|
96
|
+
if (data === null) {
|
|
97
|
+
return ZodParsedType.null;
|
|
98
|
+
}
|
|
99
|
+
if (data.then &&
|
|
100
|
+
typeof data.then === "function" &&
|
|
101
|
+
data.catch &&
|
|
102
|
+
typeof data.catch === "function") {
|
|
103
|
+
return ZodParsedType.promise;
|
|
104
|
+
}
|
|
105
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
106
|
+
return ZodParsedType.map;
|
|
107
|
+
}
|
|
108
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
109
|
+
return ZodParsedType.set;
|
|
110
|
+
}
|
|
111
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
112
|
+
return ZodParsedType.date;
|
|
113
|
+
}
|
|
114
|
+
return ZodParsedType.object;
|
|
115
|
+
default:
|
|
116
|
+
return ZodParsedType.unknown;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
55
119
|
|
|
56
120
|
const ZodIssueCode = util.arrayToEnum([
|
|
57
121
|
"invalid_type",
|
|
@@ -259,70 +323,6 @@ const setErrorMap = (map) => {
|
|
|
259
323
|
overrideErrorMap = map;
|
|
260
324
|
};
|
|
261
325
|
|
|
262
|
-
const ZodParsedType = util.arrayToEnum([
|
|
263
|
-
"string",
|
|
264
|
-
"nan",
|
|
265
|
-
"number",
|
|
266
|
-
"integer",
|
|
267
|
-
"float",
|
|
268
|
-
"boolean",
|
|
269
|
-
"date",
|
|
270
|
-
"bigint",
|
|
271
|
-
"symbol",
|
|
272
|
-
"function",
|
|
273
|
-
"undefined",
|
|
274
|
-
"null",
|
|
275
|
-
"array",
|
|
276
|
-
"object",
|
|
277
|
-
"unknown",
|
|
278
|
-
"promise",
|
|
279
|
-
"void",
|
|
280
|
-
"never",
|
|
281
|
-
"map",
|
|
282
|
-
"set",
|
|
283
|
-
]);
|
|
284
|
-
const getParsedType = (data) => {
|
|
285
|
-
const t = typeof data;
|
|
286
|
-
switch (t) {
|
|
287
|
-
case "undefined":
|
|
288
|
-
return ZodParsedType.undefined;
|
|
289
|
-
case "string":
|
|
290
|
-
return ZodParsedType.string;
|
|
291
|
-
case "number":
|
|
292
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
293
|
-
case "boolean":
|
|
294
|
-
return ZodParsedType.boolean;
|
|
295
|
-
case "function":
|
|
296
|
-
return ZodParsedType.function;
|
|
297
|
-
case "bigint":
|
|
298
|
-
return ZodParsedType.bigint;
|
|
299
|
-
case "object":
|
|
300
|
-
if (Array.isArray(data)) {
|
|
301
|
-
return ZodParsedType.array;
|
|
302
|
-
}
|
|
303
|
-
if (data === null) {
|
|
304
|
-
return ZodParsedType.null;
|
|
305
|
-
}
|
|
306
|
-
if (data.then &&
|
|
307
|
-
typeof data.then === "function" &&
|
|
308
|
-
data.catch &&
|
|
309
|
-
typeof data.catch === "function") {
|
|
310
|
-
return ZodParsedType.promise;
|
|
311
|
-
}
|
|
312
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
313
|
-
return ZodParsedType.map;
|
|
314
|
-
}
|
|
315
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
316
|
-
return ZodParsedType.set;
|
|
317
|
-
}
|
|
318
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
319
|
-
return ZodParsedType.date;
|
|
320
|
-
}
|
|
321
|
-
return ZodParsedType.object;
|
|
322
|
-
default:
|
|
323
|
-
return ZodParsedType.unknown;
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
326
|
const makeIssue = (params) => {
|
|
327
327
|
const { data, path, errorMaps, issueData } = params;
|
|
328
328
|
const fullPath = [...path, ...(issueData.path || [])];
|
|
@@ -1603,7 +1603,9 @@ class ZodObject extends ZodType {
|
|
|
1603
1603
|
pick(mask) {
|
|
1604
1604
|
const shape = {};
|
|
1605
1605
|
util.objectKeys(mask).map((key) => {
|
|
1606
|
-
shape
|
|
1606
|
+
// only add to shape if key corresponds to an element of the current shape
|
|
1607
|
+
if (this.shape[key])
|
|
1608
|
+
shape[key] = this.shape[key];
|
|
1607
1609
|
});
|
|
1608
1610
|
return new ZodObject({
|
|
1609
1611
|
...this._def,
|
|
@@ -2821,8 +2823,8 @@ const oboolean = () => booleanType().optional();
|
|
|
2821
2823
|
|
|
2822
2824
|
var mod = /*#__PURE__*/Object.freeze({
|
|
2823
2825
|
__proto__: null,
|
|
2824
|
-
ZodParsedType: ZodParsedType,
|
|
2825
2826
|
getParsedType: getParsedType,
|
|
2827
|
+
ZodParsedType: ZodParsedType,
|
|
2826
2828
|
makeIssue: makeIssue,
|
|
2827
2829
|
EMPTY_PATH: EMPTY_PATH,
|
|
2828
2830
|
addIssueToContext: addIssueToContext,
|
package/lib/index.umd.js
CHANGED
|
@@ -58,6 +58,70 @@
|
|
|
58
58
|
}
|
|
59
59
|
util.joinValues = joinValues;
|
|
60
60
|
})(util || (util = {}));
|
|
61
|
+
const ZodParsedType = util.arrayToEnum([
|
|
62
|
+
"string",
|
|
63
|
+
"nan",
|
|
64
|
+
"number",
|
|
65
|
+
"integer",
|
|
66
|
+
"float",
|
|
67
|
+
"boolean",
|
|
68
|
+
"date",
|
|
69
|
+
"bigint",
|
|
70
|
+
"symbol",
|
|
71
|
+
"function",
|
|
72
|
+
"undefined",
|
|
73
|
+
"null",
|
|
74
|
+
"array",
|
|
75
|
+
"object",
|
|
76
|
+
"unknown",
|
|
77
|
+
"promise",
|
|
78
|
+
"void",
|
|
79
|
+
"never",
|
|
80
|
+
"map",
|
|
81
|
+
"set",
|
|
82
|
+
]);
|
|
83
|
+
const getParsedType = (data) => {
|
|
84
|
+
const t = typeof data;
|
|
85
|
+
switch (t) {
|
|
86
|
+
case "undefined":
|
|
87
|
+
return ZodParsedType.undefined;
|
|
88
|
+
case "string":
|
|
89
|
+
return ZodParsedType.string;
|
|
90
|
+
case "number":
|
|
91
|
+
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
92
|
+
case "boolean":
|
|
93
|
+
return ZodParsedType.boolean;
|
|
94
|
+
case "function":
|
|
95
|
+
return ZodParsedType.function;
|
|
96
|
+
case "bigint":
|
|
97
|
+
return ZodParsedType.bigint;
|
|
98
|
+
case "object":
|
|
99
|
+
if (Array.isArray(data)) {
|
|
100
|
+
return ZodParsedType.array;
|
|
101
|
+
}
|
|
102
|
+
if (data === null) {
|
|
103
|
+
return ZodParsedType.null;
|
|
104
|
+
}
|
|
105
|
+
if (data.then &&
|
|
106
|
+
typeof data.then === "function" &&
|
|
107
|
+
data.catch &&
|
|
108
|
+
typeof data.catch === "function") {
|
|
109
|
+
return ZodParsedType.promise;
|
|
110
|
+
}
|
|
111
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
112
|
+
return ZodParsedType.map;
|
|
113
|
+
}
|
|
114
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
115
|
+
return ZodParsedType.set;
|
|
116
|
+
}
|
|
117
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
118
|
+
return ZodParsedType.date;
|
|
119
|
+
}
|
|
120
|
+
return ZodParsedType.object;
|
|
121
|
+
default:
|
|
122
|
+
return ZodParsedType.unknown;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
61
125
|
|
|
62
126
|
const ZodIssueCode = util.arrayToEnum([
|
|
63
127
|
"invalid_type",
|
|
@@ -265,70 +329,6 @@
|
|
|
265
329
|
exports.overrideErrorMap = map;
|
|
266
330
|
};
|
|
267
331
|
|
|
268
|
-
const ZodParsedType = util.arrayToEnum([
|
|
269
|
-
"string",
|
|
270
|
-
"nan",
|
|
271
|
-
"number",
|
|
272
|
-
"integer",
|
|
273
|
-
"float",
|
|
274
|
-
"boolean",
|
|
275
|
-
"date",
|
|
276
|
-
"bigint",
|
|
277
|
-
"symbol",
|
|
278
|
-
"function",
|
|
279
|
-
"undefined",
|
|
280
|
-
"null",
|
|
281
|
-
"array",
|
|
282
|
-
"object",
|
|
283
|
-
"unknown",
|
|
284
|
-
"promise",
|
|
285
|
-
"void",
|
|
286
|
-
"never",
|
|
287
|
-
"map",
|
|
288
|
-
"set",
|
|
289
|
-
]);
|
|
290
|
-
const getParsedType = (data) => {
|
|
291
|
-
const t = typeof data;
|
|
292
|
-
switch (t) {
|
|
293
|
-
case "undefined":
|
|
294
|
-
return ZodParsedType.undefined;
|
|
295
|
-
case "string":
|
|
296
|
-
return ZodParsedType.string;
|
|
297
|
-
case "number":
|
|
298
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
299
|
-
case "boolean":
|
|
300
|
-
return ZodParsedType.boolean;
|
|
301
|
-
case "function":
|
|
302
|
-
return ZodParsedType.function;
|
|
303
|
-
case "bigint":
|
|
304
|
-
return ZodParsedType.bigint;
|
|
305
|
-
case "object":
|
|
306
|
-
if (Array.isArray(data)) {
|
|
307
|
-
return ZodParsedType.array;
|
|
308
|
-
}
|
|
309
|
-
if (data === null) {
|
|
310
|
-
return ZodParsedType.null;
|
|
311
|
-
}
|
|
312
|
-
if (data.then &&
|
|
313
|
-
typeof data.then === "function" &&
|
|
314
|
-
data.catch &&
|
|
315
|
-
typeof data.catch === "function") {
|
|
316
|
-
return ZodParsedType.promise;
|
|
317
|
-
}
|
|
318
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
319
|
-
return ZodParsedType.map;
|
|
320
|
-
}
|
|
321
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
322
|
-
return ZodParsedType.set;
|
|
323
|
-
}
|
|
324
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
325
|
-
return ZodParsedType.date;
|
|
326
|
-
}
|
|
327
|
-
return ZodParsedType.object;
|
|
328
|
-
default:
|
|
329
|
-
return ZodParsedType.unknown;
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
332
|
const makeIssue = (params) => {
|
|
333
333
|
const { data, path, errorMaps, issueData } = params;
|
|
334
334
|
const fullPath = [...path, ...(issueData.path || [])];
|
|
@@ -1609,7 +1609,9 @@
|
|
|
1609
1609
|
pick(mask) {
|
|
1610
1610
|
const shape = {};
|
|
1611
1611
|
util.objectKeys(mask).map((key) => {
|
|
1612
|
-
shape
|
|
1612
|
+
// only add to shape if key corresponds to an element of the current shape
|
|
1613
|
+
if (this.shape[key])
|
|
1614
|
+
shape[key] = this.shape[key];
|
|
1613
1615
|
});
|
|
1614
1616
|
return new ZodObject({
|
|
1615
1617
|
...this._def,
|
|
@@ -2827,8 +2829,8 @@
|
|
|
2827
2829
|
|
|
2828
2830
|
var mod = /*#__PURE__*/Object.freeze({
|
|
2829
2831
|
__proto__: null,
|
|
2830
|
-
ZodParsedType: ZodParsedType,
|
|
2831
2832
|
getParsedType: getParsedType,
|
|
2833
|
+
ZodParsedType: ZodParsedType,
|
|
2832
2834
|
makeIssue: makeIssue,
|
|
2833
2835
|
EMPTY_PATH: EMPTY_PATH,
|
|
2834
2836
|
addIssueToContext: addIssueToContext,
|
package/lib/types.js
CHANGED
|
@@ -80,13 +80,13 @@ class ZodType {
|
|
|
80
80
|
return this._def.description;
|
|
81
81
|
}
|
|
82
82
|
_getType(input) {
|
|
83
|
-
return (0,
|
|
83
|
+
return (0, util_1.getParsedType)(input.data);
|
|
84
84
|
}
|
|
85
85
|
_getOrReturnCtx(input, ctx) {
|
|
86
86
|
return (ctx || {
|
|
87
87
|
common: input.parent.common,
|
|
88
88
|
data: input.data,
|
|
89
|
-
parsedType: (0,
|
|
89
|
+
parsedType: (0, util_1.getParsedType)(input.data),
|
|
90
90
|
schemaErrorMap: this._def.errorMap,
|
|
91
91
|
path: input.path,
|
|
92
92
|
parent: input.parent,
|
|
@@ -98,7 +98,7 @@ class ZodType {
|
|
|
98
98
|
ctx: {
|
|
99
99
|
common: input.parent.common,
|
|
100
100
|
data: input.data,
|
|
101
|
-
parsedType: (0,
|
|
101
|
+
parsedType: (0, util_1.getParsedType)(input.data),
|
|
102
102
|
schemaErrorMap: this._def.errorMap,
|
|
103
103
|
path: input.path,
|
|
104
104
|
parent: input.parent,
|
|
@@ -134,7 +134,7 @@ class ZodType {
|
|
|
134
134
|
schemaErrorMap: this._def.errorMap,
|
|
135
135
|
parent: null,
|
|
136
136
|
data,
|
|
137
|
-
parsedType: (0,
|
|
137
|
+
parsedType: (0, util_1.getParsedType)(data),
|
|
138
138
|
};
|
|
139
139
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
140
140
|
return handleResult(ctx, result);
|
|
@@ -156,7 +156,7 @@ class ZodType {
|
|
|
156
156
|
schemaErrorMap: this._def.errorMap,
|
|
157
157
|
parent: null,
|
|
158
158
|
data,
|
|
159
|
-
parsedType: (0,
|
|
159
|
+
parsedType: (0, util_1.getParsedType)(data),
|
|
160
160
|
};
|
|
161
161
|
const maybeAsyncResult = this._parse({ data, path: [], parent: ctx });
|
|
162
162
|
const result = await ((0, parseUtil_1.isAsync)(maybeAsyncResult)
|
|
@@ -302,11 +302,11 @@ class ZodString extends ZodType {
|
|
|
302
302
|
}
|
|
303
303
|
_parse(input) {
|
|
304
304
|
const parsedType = this._getType(input);
|
|
305
|
-
if (parsedType !==
|
|
305
|
+
if (parsedType !== util_1.ZodParsedType.string) {
|
|
306
306
|
const ctx = this._getOrReturnCtx(input);
|
|
307
307
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
308
308
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
309
|
-
expected:
|
|
309
|
+
expected: util_1.ZodParsedType.string,
|
|
310
310
|
received: ctx.parsedType,
|
|
311
311
|
}
|
|
312
312
|
//
|
|
@@ -514,11 +514,11 @@ class ZodNumber extends ZodType {
|
|
|
514
514
|
}
|
|
515
515
|
_parse(input) {
|
|
516
516
|
const parsedType = this._getType(input);
|
|
517
|
-
if (parsedType !==
|
|
517
|
+
if (parsedType !== util_1.ZodParsedType.number) {
|
|
518
518
|
const ctx = this._getOrReturnCtx(input);
|
|
519
519
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
520
520
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
521
|
-
expected:
|
|
521
|
+
expected: util_1.ZodParsedType.number,
|
|
522
522
|
received: ctx.parsedType,
|
|
523
523
|
});
|
|
524
524
|
return parseUtil_1.INVALID;
|
|
@@ -699,11 +699,11 @@ ZodNumber.create = (params) => {
|
|
|
699
699
|
class ZodBigInt extends ZodType {
|
|
700
700
|
_parse(input) {
|
|
701
701
|
const parsedType = this._getType(input);
|
|
702
|
-
if (parsedType !==
|
|
702
|
+
if (parsedType !== util_1.ZodParsedType.bigint) {
|
|
703
703
|
const ctx = this._getOrReturnCtx(input);
|
|
704
704
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
705
705
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
706
|
-
expected:
|
|
706
|
+
expected: util_1.ZodParsedType.bigint,
|
|
707
707
|
received: ctx.parsedType,
|
|
708
708
|
});
|
|
709
709
|
return parseUtil_1.INVALID;
|
|
@@ -721,11 +721,11 @@ ZodBigInt.create = (params) => {
|
|
|
721
721
|
class ZodBoolean extends ZodType {
|
|
722
722
|
_parse(input) {
|
|
723
723
|
const parsedType = this._getType(input);
|
|
724
|
-
if (parsedType !==
|
|
724
|
+
if (parsedType !== util_1.ZodParsedType.boolean) {
|
|
725
725
|
const ctx = this._getOrReturnCtx(input);
|
|
726
726
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
727
727
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
728
|
-
expected:
|
|
728
|
+
expected: util_1.ZodParsedType.boolean,
|
|
729
729
|
received: ctx.parsedType,
|
|
730
730
|
});
|
|
731
731
|
return parseUtil_1.INVALID;
|
|
@@ -743,11 +743,11 @@ ZodBoolean.create = (params) => {
|
|
|
743
743
|
class ZodDate extends ZodType {
|
|
744
744
|
_parse(input) {
|
|
745
745
|
const parsedType = this._getType(input);
|
|
746
|
-
if (parsedType !==
|
|
746
|
+
if (parsedType !== util_1.ZodParsedType.date) {
|
|
747
747
|
const ctx = this._getOrReturnCtx(input);
|
|
748
748
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
749
749
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
750
|
-
expected:
|
|
750
|
+
expected: util_1.ZodParsedType.date,
|
|
751
751
|
received: ctx.parsedType,
|
|
752
752
|
});
|
|
753
753
|
return parseUtil_1.INVALID;
|
|
@@ -775,11 +775,11 @@ ZodDate.create = (params) => {
|
|
|
775
775
|
class ZodUndefined extends ZodType {
|
|
776
776
|
_parse(input) {
|
|
777
777
|
const parsedType = this._getType(input);
|
|
778
|
-
if (parsedType !==
|
|
778
|
+
if (parsedType !== util_1.ZodParsedType.undefined) {
|
|
779
779
|
const ctx = this._getOrReturnCtx(input);
|
|
780
780
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
781
781
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
782
|
-
expected:
|
|
782
|
+
expected: util_1.ZodParsedType.undefined,
|
|
783
783
|
received: ctx.parsedType,
|
|
784
784
|
});
|
|
785
785
|
return parseUtil_1.INVALID;
|
|
@@ -797,11 +797,11 @@ ZodUndefined.create = (params) => {
|
|
|
797
797
|
class ZodNull extends ZodType {
|
|
798
798
|
_parse(input) {
|
|
799
799
|
const parsedType = this._getType(input);
|
|
800
|
-
if (parsedType !==
|
|
800
|
+
if (parsedType !== util_1.ZodParsedType.null) {
|
|
801
801
|
const ctx = this._getOrReturnCtx(input);
|
|
802
802
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
803
803
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
804
|
-
expected:
|
|
804
|
+
expected: util_1.ZodParsedType.null,
|
|
805
805
|
received: ctx.parsedType,
|
|
806
806
|
});
|
|
807
807
|
return parseUtil_1.INVALID;
|
|
@@ -855,7 +855,7 @@ class ZodNever extends ZodType {
|
|
|
855
855
|
const ctx = this._getOrReturnCtx(input);
|
|
856
856
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
857
857
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
858
|
-
expected:
|
|
858
|
+
expected: util_1.ZodParsedType.never,
|
|
859
859
|
received: ctx.parsedType,
|
|
860
860
|
});
|
|
861
861
|
return parseUtil_1.INVALID;
|
|
@@ -871,11 +871,11 @@ ZodNever.create = (params) => {
|
|
|
871
871
|
class ZodVoid extends ZodType {
|
|
872
872
|
_parse(input) {
|
|
873
873
|
const parsedType = this._getType(input);
|
|
874
|
-
if (parsedType !==
|
|
874
|
+
if (parsedType !== util_1.ZodParsedType.undefined) {
|
|
875
875
|
const ctx = this._getOrReturnCtx(input);
|
|
876
876
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
877
877
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
878
|
-
expected:
|
|
878
|
+
expected: util_1.ZodParsedType.void,
|
|
879
879
|
received: ctx.parsedType,
|
|
880
880
|
});
|
|
881
881
|
return parseUtil_1.INVALID;
|
|
@@ -894,10 +894,10 @@ class ZodArray extends ZodType {
|
|
|
894
894
|
_parse(input) {
|
|
895
895
|
const { ctx, status } = this._processInputParams(input);
|
|
896
896
|
const def = this._def;
|
|
897
|
-
if (ctx.parsedType !==
|
|
897
|
+
if (ctx.parsedType !== util_1.ZodParsedType.array) {
|
|
898
898
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
899
899
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
900
|
-
expected:
|
|
900
|
+
expected: util_1.ZodParsedType.array,
|
|
901
901
|
received: ctx.parsedType,
|
|
902
902
|
});
|
|
903
903
|
return parseUtil_1.INVALID;
|
|
@@ -1044,11 +1044,11 @@ class ZodObject extends ZodType {
|
|
|
1044
1044
|
}
|
|
1045
1045
|
_parse(input) {
|
|
1046
1046
|
const parsedType = this._getType(input);
|
|
1047
|
-
if (parsedType !==
|
|
1047
|
+
if (parsedType !== util_1.ZodParsedType.object) {
|
|
1048
1048
|
const ctx = this._getOrReturnCtx(input);
|
|
1049
1049
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1050
1050
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1051
|
-
expected:
|
|
1051
|
+
expected: util_1.ZodParsedType.object,
|
|
1052
1052
|
received: ctx.parsedType,
|
|
1053
1053
|
});
|
|
1054
1054
|
return parseUtil_1.INVALID;
|
|
@@ -1198,7 +1198,9 @@ class ZodObject extends ZodType {
|
|
|
1198
1198
|
pick(mask) {
|
|
1199
1199
|
const shape = {};
|
|
1200
1200
|
util_1.util.objectKeys(mask).map((key) => {
|
|
1201
|
-
shape
|
|
1201
|
+
// only add to shape if key corresponds to an element of the current shape
|
|
1202
|
+
if (this.shape[key])
|
|
1203
|
+
shape[key] = this.shape[key];
|
|
1202
1204
|
});
|
|
1203
1205
|
return new ZodObject({
|
|
1204
1206
|
...this._def,
|
|
@@ -1391,10 +1393,10 @@ ZodUnion.create = (types, params) => {
|
|
|
1391
1393
|
class ZodDiscriminatedUnion extends ZodType {
|
|
1392
1394
|
_parse(input) {
|
|
1393
1395
|
const { ctx } = this._processInputParams(input);
|
|
1394
|
-
if (ctx.parsedType !==
|
|
1396
|
+
if (ctx.parsedType !== util_1.ZodParsedType.object) {
|
|
1395
1397
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1396
1398
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1397
|
-
expected:
|
|
1399
|
+
expected: util_1.ZodParsedType.object,
|
|
1398
1400
|
received: ctx.parsedType,
|
|
1399
1401
|
});
|
|
1400
1402
|
return parseUtil_1.INVALID;
|
|
@@ -1468,12 +1470,12 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1468
1470
|
}
|
|
1469
1471
|
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
|
1470
1472
|
function mergeValues(a, b) {
|
|
1471
|
-
const aType = (0,
|
|
1472
|
-
const bType = (0,
|
|
1473
|
+
const aType = (0, util_1.getParsedType)(a);
|
|
1474
|
+
const bType = (0, util_1.getParsedType)(b);
|
|
1473
1475
|
if (a === b) {
|
|
1474
1476
|
return { valid: true, data: a };
|
|
1475
1477
|
}
|
|
1476
|
-
else if (aType ===
|
|
1478
|
+
else if (aType === util_1.ZodParsedType.object && bType === util_1.ZodParsedType.object) {
|
|
1477
1479
|
const bKeys = util_1.util.objectKeys(b);
|
|
1478
1480
|
const sharedKeys = util_1.util
|
|
1479
1481
|
.objectKeys(a)
|
|
@@ -1488,7 +1490,7 @@ function mergeValues(a, b) {
|
|
|
1488
1490
|
}
|
|
1489
1491
|
return { valid: true, data: newObj };
|
|
1490
1492
|
}
|
|
1491
|
-
else if (aType ===
|
|
1493
|
+
else if (aType === util_1.ZodParsedType.array && bType === util_1.ZodParsedType.array) {
|
|
1492
1494
|
if (a.length !== b.length) {
|
|
1493
1495
|
return { valid: false };
|
|
1494
1496
|
}
|
|
@@ -1504,8 +1506,8 @@ function mergeValues(a, b) {
|
|
|
1504
1506
|
}
|
|
1505
1507
|
return { valid: true, data: newArray };
|
|
1506
1508
|
}
|
|
1507
|
-
else if (aType ===
|
|
1508
|
-
bType ===
|
|
1509
|
+
else if (aType === util_1.ZodParsedType.date &&
|
|
1510
|
+
bType === util_1.ZodParsedType.date &&
|
|
1509
1511
|
+a === +b) {
|
|
1510
1512
|
return { valid: true, data: a };
|
|
1511
1513
|
}
|
|
@@ -1571,10 +1573,10 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
1571
1573
|
class ZodTuple extends ZodType {
|
|
1572
1574
|
_parse(input) {
|
|
1573
1575
|
const { status, ctx } = this._processInputParams(input);
|
|
1574
|
-
if (ctx.parsedType !==
|
|
1576
|
+
if (ctx.parsedType !== util_1.ZodParsedType.array) {
|
|
1575
1577
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1576
1578
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1577
|
-
expected:
|
|
1579
|
+
expected: util_1.ZodParsedType.array,
|
|
1578
1580
|
received: ctx.parsedType,
|
|
1579
1581
|
});
|
|
1580
1582
|
return parseUtil_1.INVALID;
|
|
@@ -1643,10 +1645,10 @@ class ZodRecord extends ZodType {
|
|
|
1643
1645
|
}
|
|
1644
1646
|
_parse(input) {
|
|
1645
1647
|
const { status, ctx } = this._processInputParams(input);
|
|
1646
|
-
if (ctx.parsedType !==
|
|
1648
|
+
if (ctx.parsedType !== util_1.ZodParsedType.object) {
|
|
1647
1649
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1648
1650
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1649
|
-
expected:
|
|
1651
|
+
expected: util_1.ZodParsedType.object,
|
|
1650
1652
|
received: ctx.parsedType,
|
|
1651
1653
|
});
|
|
1652
1654
|
return parseUtil_1.INVALID;
|
|
@@ -1691,10 +1693,10 @@ exports.ZodRecord = ZodRecord;
|
|
|
1691
1693
|
class ZodMap extends ZodType {
|
|
1692
1694
|
_parse(input) {
|
|
1693
1695
|
const { status, ctx } = this._processInputParams(input);
|
|
1694
|
-
if (ctx.parsedType !==
|
|
1696
|
+
if (ctx.parsedType !== util_1.ZodParsedType.map) {
|
|
1695
1697
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1696
1698
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1697
|
-
expected:
|
|
1699
|
+
expected: util_1.ZodParsedType.map,
|
|
1698
1700
|
received: ctx.parsedType,
|
|
1699
1701
|
});
|
|
1700
1702
|
return parseUtil_1.INVALID;
|
|
@@ -1753,10 +1755,10 @@ ZodMap.create = (keyType, valueType, params) => {
|
|
|
1753
1755
|
class ZodSet extends ZodType {
|
|
1754
1756
|
_parse(input) {
|
|
1755
1757
|
const { status, ctx } = this._processInputParams(input);
|
|
1756
|
-
if (ctx.parsedType !==
|
|
1758
|
+
if (ctx.parsedType !== util_1.ZodParsedType.set) {
|
|
1757
1759
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1758
1760
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1759
|
-
expected:
|
|
1761
|
+
expected: util_1.ZodParsedType.set,
|
|
1760
1762
|
received: ctx.parsedType,
|
|
1761
1763
|
});
|
|
1762
1764
|
return parseUtil_1.INVALID;
|
|
@@ -1842,10 +1844,10 @@ class ZodFunction extends ZodType {
|
|
|
1842
1844
|
}
|
|
1843
1845
|
_parse(input) {
|
|
1844
1846
|
const { ctx } = this._processInputParams(input);
|
|
1845
|
-
if (ctx.parsedType !==
|
|
1847
|
+
if (ctx.parsedType !== util_1.ZodParsedType.function) {
|
|
1846
1848
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1847
1849
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
1848
|
-
expected:
|
|
1850
|
+
expected: util_1.ZodParsedType.function,
|
|
1849
1851
|
received: ctx.parsedType,
|
|
1850
1852
|
});
|
|
1851
1853
|
return parseUtil_1.INVALID;
|
|
@@ -2060,8 +2062,8 @@ class ZodNativeEnum extends ZodType {
|
|
|
2060
2062
|
_parse(input) {
|
|
2061
2063
|
const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
|
|
2062
2064
|
const ctx = this._getOrReturnCtx(input);
|
|
2063
|
-
if (ctx.parsedType !==
|
|
2064
|
-
ctx.parsedType !==
|
|
2065
|
+
if (ctx.parsedType !== util_1.ZodParsedType.string &&
|
|
2066
|
+
ctx.parsedType !== util_1.ZodParsedType.number) {
|
|
2065
2067
|
const expectedValues = util_1.util.objectValues(nativeEnumValues);
|
|
2066
2068
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2067
2069
|
expected: util_1.util.joinValues(expectedValues),
|
|
@@ -2096,16 +2098,16 @@ ZodNativeEnum.create = (values, params) => {
|
|
|
2096
2098
|
class ZodPromise extends ZodType {
|
|
2097
2099
|
_parse(input) {
|
|
2098
2100
|
const { ctx } = this._processInputParams(input);
|
|
2099
|
-
if (ctx.parsedType !==
|
|
2101
|
+
if (ctx.parsedType !== util_1.ZodParsedType.promise &&
|
|
2100
2102
|
ctx.common.async === false) {
|
|
2101
2103
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2102
2104
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
2103
|
-
expected:
|
|
2105
|
+
expected: util_1.ZodParsedType.promise,
|
|
2104
2106
|
received: ctx.parsedType,
|
|
2105
2107
|
});
|
|
2106
2108
|
return parseUtil_1.INVALID;
|
|
2107
2109
|
}
|
|
2108
|
-
const promisified = ctx.parsedType ===
|
|
2110
|
+
const promisified = ctx.parsedType === util_1.ZodParsedType.promise
|
|
2109
2111
|
? ctx.data
|
|
2110
2112
|
: Promise.resolve(ctx.data);
|
|
2111
2113
|
return (0, parseUtil_1.OK)(promisified.then((data) => {
|
|
@@ -2263,7 +2265,7 @@ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
|
2263
2265
|
class ZodOptional extends ZodType {
|
|
2264
2266
|
_parse(input) {
|
|
2265
2267
|
const parsedType = this._getType(input);
|
|
2266
|
-
if (parsedType ===
|
|
2268
|
+
if (parsedType === util_1.ZodParsedType.undefined) {
|
|
2267
2269
|
return (0, parseUtil_1.OK)(undefined);
|
|
2268
2270
|
}
|
|
2269
2271
|
return this._def.innerType._parse(input);
|
|
@@ -2283,7 +2285,7 @@ ZodOptional.create = (type, params) => {
|
|
|
2283
2285
|
class ZodNullable extends ZodType {
|
|
2284
2286
|
_parse(input) {
|
|
2285
2287
|
const parsedType = this._getType(input);
|
|
2286
|
-
if (parsedType ===
|
|
2288
|
+
if (parsedType === util_1.ZodParsedType.null) {
|
|
2287
2289
|
return (0, parseUtil_1.OK)(null);
|
|
2288
2290
|
}
|
|
2289
2291
|
return this._def.innerType._parse(input);
|
|
@@ -2304,7 +2306,7 @@ class ZodDefault extends ZodType {
|
|
|
2304
2306
|
_parse(input) {
|
|
2305
2307
|
const { ctx } = this._processInputParams(input);
|
|
2306
2308
|
let data = ctx.data;
|
|
2307
|
-
if (ctx.parsedType ===
|
|
2309
|
+
if (ctx.parsedType === util_1.ZodParsedType.undefined) {
|
|
2308
2310
|
data = this._def.defaultValue();
|
|
2309
2311
|
}
|
|
2310
2312
|
return this._def.innerType._parse({
|
|
@@ -2328,11 +2330,11 @@ ZodDefault.create = (type, params) => {
|
|
|
2328
2330
|
class ZodNaN extends ZodType {
|
|
2329
2331
|
_parse(input) {
|
|
2330
2332
|
const parsedType = this._getType(input);
|
|
2331
|
-
if (parsedType !==
|
|
2333
|
+
if (parsedType !== util_1.ZodParsedType.nan) {
|
|
2332
2334
|
const ctx = this._getOrReturnCtx(input);
|
|
2333
2335
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2334
2336
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
2335
|
-
expected:
|
|
2337
|
+
expected: util_1.ZodParsedType.nan,
|
|
2336
2338
|
received: ctx.parsedType,
|
|
2337
2339
|
});
|
|
2338
2340
|
return parseUtil_1.INVALID;
|