zod 3.13.4 → 3.14.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/README.md +5 -4
- package/lib/ZodError.js +110 -205
- package/lib/benchmarks/discriminatedUnion.js +25 -25
- package/lib/benchmarks/index.js +15 -53
- package/lib/benchmarks/object.js +23 -23
- package/lib/benchmarks/primitives.d.ts +5 -0
- package/lib/benchmarks/primitives.js +78 -0
- package/lib/benchmarks/realworld.d.ts +5 -0
- package/lib/benchmarks/realworld.js +56 -0
- package/lib/benchmarks/string.js +27 -16
- package/lib/benchmarks/union.js +25 -25
- package/lib/helpers/errorUtil.js +2 -6
- package/lib/helpers/parseUtil.d.ts +7 -5
- package/lib/helpers/parseUtil.js +84 -244
- package/lib/helpers/util.js +20 -66
- package/lib/index.js +1 -1
- package/lib/index.mjs +1636 -2167
- package/lib/types.d.ts +6 -4
- package/lib/types.js +1422 -1772
- package/package.json +16 -14
package/lib/index.mjs
CHANGED
|
@@ -1,207 +1,53 @@
|
|
|
1
|
-
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
/* global Reflect, Promise */
|
|
16
|
-
|
|
17
|
-
var extendStatics = function(d, b) {
|
|
18
|
-
extendStatics = Object.setPrototypeOf ||
|
|
19
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
-
return extendStatics(d, b);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function __extends(d, b) {
|
|
25
|
-
if (typeof b !== "function" && b !== null)
|
|
26
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
-
extendStatics(d, b);
|
|
28
|
-
function __() { this.constructor = d; }
|
|
29
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var __assign = function() {
|
|
33
|
-
__assign = Object.assign || function __assign(t) {
|
|
34
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
35
|
-
s = arguments[i];
|
|
36
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
37
|
-
}
|
|
38
|
-
return t;
|
|
39
|
-
};
|
|
40
|
-
return __assign.apply(this, arguments);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
44
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
46
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
47
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
49
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function __generator(thisArg, body) {
|
|
54
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
55
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
56
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
57
|
-
function step(op) {
|
|
58
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
59
|
-
while (_) try {
|
|
60
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
61
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
62
|
-
switch (op[0]) {
|
|
63
|
-
case 0: case 1: t = op; break;
|
|
64
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
65
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
66
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
67
|
-
default:
|
|
68
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
69
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
70
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
71
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
72
|
-
if (t[2]) _.ops.pop();
|
|
73
|
-
_.trys.pop(); continue;
|
|
74
|
-
}
|
|
75
|
-
op = body.call(thisArg, _);
|
|
76
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
77
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function __values(o) {
|
|
82
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
83
|
-
if (m) return m.call(o);
|
|
84
|
-
if (o && typeof o.length === "number") return {
|
|
85
|
-
next: function () {
|
|
86
|
-
if (o && i >= o.length) o = void 0;
|
|
87
|
-
return { value: o && o[i++], done: !o };
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function __read(o, n) {
|
|
94
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
95
|
-
if (!m) return o;
|
|
96
|
-
var i = m.call(o), r, ar = [], e;
|
|
97
|
-
try {
|
|
98
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
99
|
-
}
|
|
100
|
-
catch (error) { e = { error: error }; }
|
|
101
|
-
finally {
|
|
102
|
-
try {
|
|
103
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
104
|
-
}
|
|
105
|
-
finally { if (e) throw e.error; }
|
|
106
|
-
}
|
|
107
|
-
return ar;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function __spreadArray(to, from, pack) {
|
|
111
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
112
|
-
if (ar || !(i in from)) {
|
|
113
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
114
|
-
ar[i] = from[i];
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
1
|
var util;
|
|
121
2
|
(function (util) {
|
|
122
3
|
function assertNever(_x) {
|
|
123
4
|
throw new Error();
|
|
124
5
|
}
|
|
125
6
|
util.assertNever = assertNever;
|
|
126
|
-
util.arrayToEnum =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
131
|
-
var item = items_1_1.value;
|
|
132
|
-
obj[item] = item;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
136
|
-
finally {
|
|
137
|
-
try {
|
|
138
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
139
|
-
}
|
|
140
|
-
finally { if (e_1) throw e_1.error; }
|
|
7
|
+
util.arrayToEnum = (items) => {
|
|
8
|
+
const obj = {};
|
|
9
|
+
for (const item of items) {
|
|
10
|
+
obj[item] = item;
|
|
141
11
|
}
|
|
142
12
|
return obj;
|
|
143
13
|
};
|
|
144
|
-
util.getValidEnumValues =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for (var validKeys_1 = __values(validKeys), validKeys_1_1 = validKeys_1.next(); !validKeys_1_1.done; validKeys_1_1 = validKeys_1.next()) {
|
|
150
|
-
var k = validKeys_1_1.value;
|
|
151
|
-
filtered[k] = obj[k];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
155
|
-
finally {
|
|
156
|
-
try {
|
|
157
|
-
if (validKeys_1_1 && !validKeys_1_1.done && (_a = validKeys_1.return)) _a.call(validKeys_1);
|
|
158
|
-
}
|
|
159
|
-
finally { if (e_2) throw e_2.error; }
|
|
14
|
+
util.getValidEnumValues = (obj) => {
|
|
15
|
+
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
16
|
+
const filtered = {};
|
|
17
|
+
for (const k of validKeys) {
|
|
18
|
+
filtered[k] = obj[k];
|
|
160
19
|
}
|
|
161
20
|
return util.objectValues(filtered);
|
|
162
21
|
};
|
|
163
|
-
util.objectValues =
|
|
22
|
+
util.objectValues = (obj) => {
|
|
164
23
|
return util.objectKeys(obj).map(function (e) {
|
|
165
24
|
return obj[e];
|
|
166
25
|
});
|
|
167
26
|
};
|
|
168
27
|
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
|
169
|
-
?
|
|
170
|
-
:
|
|
171
|
-
|
|
172
|
-
for (
|
|
28
|
+
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
|
29
|
+
: (object) => {
|
|
30
|
+
const keys = [];
|
|
31
|
+
for (const key in object) {
|
|
173
32
|
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
174
33
|
keys.push(key);
|
|
175
34
|
}
|
|
176
35
|
}
|
|
177
36
|
return keys;
|
|
178
37
|
};
|
|
179
|
-
util.find =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var item = arr_1_1.value;
|
|
184
|
-
if (checker(item))
|
|
185
|
-
return item;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
189
|
-
finally {
|
|
190
|
-
try {
|
|
191
|
-
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
|
|
192
|
-
}
|
|
193
|
-
finally { if (e_3) throw e_3.error; }
|
|
38
|
+
util.find = (arr, checker) => {
|
|
39
|
+
for (const item of arr) {
|
|
40
|
+
if (checker(item))
|
|
41
|
+
return item;
|
|
194
42
|
}
|
|
195
43
|
return undefined;
|
|
196
44
|
};
|
|
197
45
|
util.isInteger = typeof Number.isInteger === "function"
|
|
198
|
-
?
|
|
199
|
-
:
|
|
200
|
-
return typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
201
|
-
};
|
|
46
|
+
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
|
47
|
+
: (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
202
48
|
})(util || (util = {}));
|
|
203
49
|
|
|
204
|
-
|
|
50
|
+
const ZodIssueCode = util.arrayToEnum([
|
|
205
51
|
"invalid_type",
|
|
206
52
|
"custom",
|
|
207
53
|
"invalid_union",
|
|
@@ -217,239 +63,195 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
217
63
|
"invalid_intersection_types",
|
|
218
64
|
"not_multiple_of",
|
|
219
65
|
]);
|
|
220
|
-
|
|
221
|
-
|
|
66
|
+
const quotelessJson = (obj) => {
|
|
67
|
+
const json = JSON.stringify(obj, null, 2);
|
|
222
68
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
223
69
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
while (i < issue.path.length) {
|
|
253
|
-
var el = issue.path[i];
|
|
254
|
-
var terminal = i === issue.path.length - 1;
|
|
255
|
-
if (!terminal) {
|
|
256
|
-
if (typeof el === "string") {
|
|
257
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
258
|
-
}
|
|
259
|
-
else if (typeof el === "number") {
|
|
260
|
-
var errorArray = [];
|
|
261
|
-
errorArray._errors = [];
|
|
262
|
-
curr[el] = curr[el] || errorArray;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
70
|
+
class ZodError extends Error {
|
|
71
|
+
constructor(issues) {
|
|
72
|
+
super();
|
|
73
|
+
this.issues = [];
|
|
74
|
+
this.format = () => {
|
|
75
|
+
const fieldErrors = { _errors: [] };
|
|
76
|
+
const processError = (error) => {
|
|
77
|
+
for (const issue of error.issues) {
|
|
78
|
+
if (issue.code === "invalid_union") {
|
|
79
|
+
issue.unionErrors.map(processError);
|
|
80
|
+
}
|
|
81
|
+
else if (issue.code === "invalid_return_type") {
|
|
82
|
+
processError(issue.returnTypeError);
|
|
83
|
+
}
|
|
84
|
+
else if (issue.code === "invalid_arguments") {
|
|
85
|
+
processError(issue.argumentsError);
|
|
86
|
+
}
|
|
87
|
+
else if (issue.path.length === 0) {
|
|
88
|
+
fieldErrors._errors.push(issue.message);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let curr = fieldErrors;
|
|
92
|
+
let i = 0;
|
|
93
|
+
while (i < issue.path.length) {
|
|
94
|
+
const el = issue.path[i];
|
|
95
|
+
const terminal = i === issue.path.length - 1;
|
|
96
|
+
if (!terminal) {
|
|
97
|
+
if (typeof el === "string") {
|
|
266
98
|
curr[el] = curr[el] || { _errors: [] };
|
|
267
|
-
curr[el]._errors.push(issue.message);
|
|
268
99
|
}
|
|
269
|
-
|
|
270
|
-
|
|
100
|
+
else if (typeof el === "number") {
|
|
101
|
+
const errorArray = [];
|
|
102
|
+
errorArray._errors = [];
|
|
103
|
+
curr[el] = curr[el] || errorArray;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
108
|
+
curr[el]._errors.push(issue.message);
|
|
271
109
|
}
|
|
110
|
+
curr = curr[el];
|
|
111
|
+
i++;
|
|
272
112
|
}
|
|
273
113
|
}
|
|
274
114
|
}
|
|
275
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
276
|
-
finally {
|
|
277
|
-
try {
|
|
278
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
279
|
-
}
|
|
280
|
-
finally { if (e_1) throw e_1.error; }
|
|
281
|
-
}
|
|
282
115
|
};
|
|
283
|
-
processError(
|
|
116
|
+
processError(this);
|
|
284
117
|
return fieldErrors;
|
|
285
118
|
};
|
|
286
|
-
|
|
287
|
-
|
|
119
|
+
this.addIssue = (sub) => {
|
|
120
|
+
this.issues = [...this.issues, sub];
|
|
288
121
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
_this.issues = __spreadArray(__spreadArray([], __read(_this.issues), false), __read(subs), false);
|
|
122
|
+
this.addIssues = (subs = []) => {
|
|
123
|
+
this.issues = [...this.issues, ...subs];
|
|
292
124
|
};
|
|
293
|
-
|
|
125
|
+
const actualProto = new.target.prototype;
|
|
294
126
|
if (Object.setPrototypeOf) {
|
|
295
127
|
// eslint-disable-next-line ban/ban
|
|
296
|
-
Object.setPrototypeOf(
|
|
128
|
+
Object.setPrototypeOf(this, actualProto);
|
|
297
129
|
}
|
|
298
130
|
else {
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
enumerable: false,
|
|
310
|
-
configurable: true
|
|
311
|
-
});
|
|
312
|
-
ZodError.prototype.toString = function () {
|
|
131
|
+
this.__proto__ = actualProto;
|
|
132
|
+
}
|
|
133
|
+
this.name = "ZodError";
|
|
134
|
+
this.issues = issues;
|
|
135
|
+
}
|
|
136
|
+
get errors() {
|
|
137
|
+
return this.issues;
|
|
138
|
+
}
|
|
139
|
+
toString() {
|
|
313
140
|
return this.message;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
});
|
|
329
|
-
ZodError.prototype.flatten = function (mapper) {
|
|
330
|
-
var e_2, _a;
|
|
331
|
-
if (mapper === void 0) { mapper = function (issue) { return issue.message; }; }
|
|
332
|
-
var fieldErrors = {};
|
|
333
|
-
var formErrors = [];
|
|
334
|
-
try {
|
|
335
|
-
for (var _b = __values(this.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
336
|
-
var sub = _c.value;
|
|
337
|
-
if (sub.path.length > 0) {
|
|
338
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
339
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
formErrors.push(mapper(sub));
|
|
343
|
-
}
|
|
141
|
+
}
|
|
142
|
+
get message() {
|
|
143
|
+
return JSON.stringify(this.issues, null, 2);
|
|
144
|
+
}
|
|
145
|
+
get isEmpty() {
|
|
146
|
+
return this.issues.length === 0;
|
|
147
|
+
}
|
|
148
|
+
flatten(mapper = (issue) => issue.message) {
|
|
149
|
+
const fieldErrors = {};
|
|
150
|
+
const formErrors = [];
|
|
151
|
+
for (const sub of this.issues) {
|
|
152
|
+
if (sub.path.length > 0) {
|
|
153
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
154
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
344
155
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
finally {
|
|
348
|
-
try {
|
|
349
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
156
|
+
else {
|
|
157
|
+
formErrors.push(mapper(sub));
|
|
350
158
|
}
|
|
351
|
-
finally { if (e_2) throw e_2.error; }
|
|
352
159
|
}
|
|
353
|
-
return { formErrors
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
};
|
|
366
|
-
return ZodError;
|
|
367
|
-
}(Error));
|
|
368
|
-
var defaultErrorMap = function (issue, _ctx) {
|
|
369
|
-
var message;
|
|
160
|
+
return { formErrors, fieldErrors };
|
|
161
|
+
}
|
|
162
|
+
get formErrors() {
|
|
163
|
+
return this.flatten();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
ZodError.create = (issues) => {
|
|
167
|
+
const error = new ZodError(issues);
|
|
168
|
+
return error;
|
|
169
|
+
};
|
|
170
|
+
const defaultErrorMap = (issue, _ctx) => {
|
|
171
|
+
let message;
|
|
370
172
|
switch (issue.code) {
|
|
371
173
|
case ZodIssueCode.invalid_type:
|
|
372
174
|
if (issue.received === "undefined") {
|
|
373
175
|
message = "Required";
|
|
374
176
|
}
|
|
375
177
|
else {
|
|
376
|
-
message =
|
|
178
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
377
179
|
}
|
|
378
180
|
break;
|
|
379
181
|
case ZodIssueCode.unrecognized_keys:
|
|
380
|
-
message =
|
|
381
|
-
.map(
|
|
382
|
-
.join(", ")
|
|
182
|
+
message = `Unrecognized key(s) in object: ${issue.keys
|
|
183
|
+
.map((k) => `'${k}'`)
|
|
184
|
+
.join(", ")}`;
|
|
383
185
|
break;
|
|
384
186
|
case ZodIssueCode.invalid_union:
|
|
385
|
-
message =
|
|
187
|
+
message = `Invalid input`;
|
|
386
188
|
break;
|
|
387
189
|
case ZodIssueCode.invalid_union_discriminator:
|
|
388
|
-
message =
|
|
389
|
-
.map(
|
|
390
|
-
.join(" | ")
|
|
190
|
+
message = `Invalid discriminator value. Expected ${issue.options
|
|
191
|
+
.map((val) => (typeof val === "string" ? `'${val}'` : val))
|
|
192
|
+
.join(" | ")}`;
|
|
391
193
|
break;
|
|
392
194
|
case ZodIssueCode.invalid_enum_value:
|
|
393
|
-
message =
|
|
394
|
-
.map(
|
|
395
|
-
.join(" | ")
|
|
195
|
+
message = `Invalid enum value. Expected ${issue.options
|
|
196
|
+
.map((val) => (typeof val === "string" ? `'${val}'` : val))
|
|
197
|
+
.join(" | ")}`;
|
|
396
198
|
break;
|
|
397
199
|
case ZodIssueCode.invalid_arguments:
|
|
398
|
-
message =
|
|
200
|
+
message = `Invalid function arguments`;
|
|
399
201
|
break;
|
|
400
202
|
case ZodIssueCode.invalid_return_type:
|
|
401
|
-
message =
|
|
203
|
+
message = `Invalid function return type`;
|
|
402
204
|
break;
|
|
403
205
|
case ZodIssueCode.invalid_date:
|
|
404
|
-
message =
|
|
206
|
+
message = `Invalid date`;
|
|
405
207
|
break;
|
|
406
208
|
case ZodIssueCode.invalid_string:
|
|
407
209
|
if (issue.validation !== "regex")
|
|
408
|
-
message =
|
|
210
|
+
message = `Invalid ${issue.validation}`;
|
|
409
211
|
else
|
|
410
212
|
message = "Invalid";
|
|
411
213
|
break;
|
|
412
214
|
case ZodIssueCode.too_small:
|
|
413
215
|
if (issue.type === "array")
|
|
414
|
-
message =
|
|
216
|
+
message = `Array must contain ${issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
415
217
|
else if (issue.type === "string")
|
|
416
|
-
message =
|
|
218
|
+
message = `String must contain ${issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
417
219
|
else if (issue.type === "number")
|
|
418
|
-
message =
|
|
220
|
+
message = `Number must be greater than ${issue.inclusive ? `or equal to ` : ``}${issue.minimum}`;
|
|
419
221
|
else
|
|
420
222
|
message = "Invalid input";
|
|
421
223
|
break;
|
|
422
224
|
case ZodIssueCode.too_big:
|
|
423
225
|
if (issue.type === "array")
|
|
424
|
-
message =
|
|
226
|
+
message = `Array must contain ${issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
425
227
|
else if (issue.type === "string")
|
|
426
|
-
message =
|
|
228
|
+
message = `String must contain ${issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
427
229
|
else if (issue.type === "number")
|
|
428
|
-
message =
|
|
230
|
+
message = `Number must be less than ${issue.inclusive ? `or equal to ` : ``}${issue.maximum}`;
|
|
429
231
|
else
|
|
430
232
|
message = "Invalid input";
|
|
431
233
|
break;
|
|
432
234
|
case ZodIssueCode.custom:
|
|
433
|
-
message =
|
|
235
|
+
message = `Invalid input`;
|
|
434
236
|
break;
|
|
435
237
|
case ZodIssueCode.invalid_intersection_types:
|
|
436
|
-
message =
|
|
238
|
+
message = `Intersection results could not be merged`;
|
|
437
239
|
break;
|
|
438
240
|
case ZodIssueCode.not_multiple_of:
|
|
439
|
-
message =
|
|
241
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
440
242
|
break;
|
|
441
243
|
default:
|
|
442
244
|
message = _ctx.defaultError;
|
|
443
245
|
util.assertNever(issue);
|
|
444
246
|
}
|
|
445
|
-
return { message
|
|
247
|
+
return { message };
|
|
446
248
|
};
|
|
447
|
-
|
|
448
|
-
|
|
249
|
+
let overrideErrorMap = defaultErrorMap;
|
|
250
|
+
const setErrorMap = (map) => {
|
|
449
251
|
overrideErrorMap = map;
|
|
450
252
|
};
|
|
451
253
|
|
|
452
|
-
|
|
254
|
+
const ZodParsedType = util.arrayToEnum([
|
|
453
255
|
"string",
|
|
454
256
|
"nan",
|
|
455
257
|
"number",
|
|
@@ -471,255 +273,174 @@ var ZodParsedType = util.arrayToEnum([
|
|
|
471
273
|
"map",
|
|
472
274
|
"set",
|
|
473
275
|
]);
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
cache.set(data, parsedType);
|
|
477
|
-
return parsedType;
|
|
478
|
-
}
|
|
479
|
-
var getParsedType = function (data, cache) {
|
|
480
|
-
if (cache && cache.has(data))
|
|
481
|
-
return cache.get(data);
|
|
482
|
-
var t = typeof data;
|
|
276
|
+
const getParsedType = (data) => {
|
|
277
|
+
const t = typeof data;
|
|
483
278
|
switch (t) {
|
|
484
279
|
case "undefined":
|
|
485
|
-
return
|
|
280
|
+
return ZodParsedType.undefined;
|
|
486
281
|
case "string":
|
|
487
|
-
return
|
|
282
|
+
return ZodParsedType.string;
|
|
488
283
|
case "number":
|
|
489
|
-
return
|
|
284
|
+
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
490
285
|
case "boolean":
|
|
491
|
-
return
|
|
286
|
+
return ZodParsedType.boolean;
|
|
492
287
|
case "function":
|
|
493
|
-
return
|
|
288
|
+
return ZodParsedType.function;
|
|
494
289
|
case "bigint":
|
|
495
|
-
return
|
|
290
|
+
return ZodParsedType.bigint;
|
|
496
291
|
case "object":
|
|
497
292
|
if (Array.isArray(data)) {
|
|
498
|
-
return
|
|
293
|
+
return ZodParsedType.array;
|
|
499
294
|
}
|
|
500
295
|
if (data === null) {
|
|
501
|
-
return
|
|
296
|
+
return ZodParsedType.null;
|
|
502
297
|
}
|
|
503
298
|
if (data.then &&
|
|
504
299
|
typeof data.then === "function" &&
|
|
505
300
|
data.catch &&
|
|
506
301
|
typeof data.catch === "function") {
|
|
507
|
-
return
|
|
302
|
+
return ZodParsedType.promise;
|
|
508
303
|
}
|
|
509
304
|
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
510
|
-
return
|
|
305
|
+
return ZodParsedType.map;
|
|
511
306
|
}
|
|
512
307
|
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
513
|
-
return
|
|
308
|
+
return ZodParsedType.set;
|
|
514
309
|
}
|
|
515
310
|
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
516
|
-
return
|
|
311
|
+
return ZodParsedType.date;
|
|
517
312
|
}
|
|
518
|
-
return
|
|
313
|
+
return ZodParsedType.object;
|
|
519
314
|
default:
|
|
520
|
-
return
|
|
315
|
+
return ZodParsedType.unknown;
|
|
521
316
|
}
|
|
522
317
|
};
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
318
|
+
const makeIssue = (params) => {
|
|
319
|
+
const { data, path, errorMaps, issueData } = params;
|
|
320
|
+
const fullPath = [...path, ...(issueData.path || [])];
|
|
321
|
+
const fullIssue = {
|
|
322
|
+
...issueData,
|
|
323
|
+
path: fullPath,
|
|
324
|
+
};
|
|
325
|
+
let errorMessage = "";
|
|
326
|
+
const maps = errorMaps
|
|
327
|
+
.filter((m) => !!m)
|
|
531
328
|
.slice()
|
|
532
329
|
.reverse();
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
var map = maps_1_1.value;
|
|
536
|
-
errorMessage = map(fullIssue, { data: data, defaultError: errorMessage }).message;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
540
|
-
finally {
|
|
541
|
-
try {
|
|
542
|
-
if (maps_1_1 && !maps_1_1.done && (_a = maps_1.return)) _a.call(maps_1);
|
|
543
|
-
}
|
|
544
|
-
finally { if (e_1) throw e_1.error; }
|
|
330
|
+
for (const map of maps) {
|
|
331
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
545
332
|
}
|
|
546
|
-
return
|
|
333
|
+
return {
|
|
334
|
+
...issueData,
|
|
335
|
+
path: fullPath,
|
|
336
|
+
message: issueData.message || errorMessage,
|
|
337
|
+
};
|
|
547
338
|
};
|
|
548
|
-
|
|
339
|
+
const EMPTY_PATH = [];
|
|
549
340
|
function addIssueToContext(ctx, issueData) {
|
|
550
|
-
|
|
341
|
+
const issue = makeIssue({
|
|
551
342
|
issueData: issueData,
|
|
552
343
|
data: ctx.data,
|
|
553
344
|
path: ctx.path,
|
|
554
345
|
errorMaps: [
|
|
555
|
-
ctx.contextualErrorMap,
|
|
346
|
+
ctx.common.contextualErrorMap,
|
|
556
347
|
ctx.schemaErrorMap,
|
|
557
348
|
overrideErrorMap,
|
|
558
349
|
defaultErrorMap, // then global default map
|
|
559
|
-
].filter(
|
|
350
|
+
].filter((x) => !!x),
|
|
560
351
|
});
|
|
561
|
-
ctx.issues.push(issue);
|
|
352
|
+
ctx.common.issues.push(issue);
|
|
562
353
|
}
|
|
563
|
-
|
|
564
|
-
|
|
354
|
+
class ParseStatus {
|
|
355
|
+
constructor() {
|
|
565
356
|
this.value = "valid";
|
|
566
357
|
}
|
|
567
|
-
|
|
358
|
+
dirty() {
|
|
568
359
|
if (this.value === "valid")
|
|
569
360
|
this.value = "dirty";
|
|
570
|
-
}
|
|
571
|
-
|
|
361
|
+
}
|
|
362
|
+
abort() {
|
|
572
363
|
if (this.value !== "aborted")
|
|
573
364
|
this.value = "aborted";
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (s.status === "dirty")
|
|
584
|
-
status.dirty();
|
|
585
|
-
arrayValue.push(s.value);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
589
|
-
finally {
|
|
590
|
-
try {
|
|
591
|
-
if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
|
|
592
|
-
}
|
|
593
|
-
finally { if (e_2) throw e_2.error; }
|
|
365
|
+
}
|
|
366
|
+
static mergeArray(status, results) {
|
|
367
|
+
const arrayValue = [];
|
|
368
|
+
for (const s of results) {
|
|
369
|
+
if (s.status === "aborted")
|
|
370
|
+
return INVALID;
|
|
371
|
+
if (s.status === "dirty")
|
|
372
|
+
status.dirty();
|
|
373
|
+
arrayValue.push(s.value);
|
|
594
374
|
}
|
|
595
375
|
return { status: status.value, value: arrayValue };
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
case 0:
|
|
604
|
-
syncPairs = [];
|
|
605
|
-
_e.label = 1;
|
|
606
|
-
case 1:
|
|
607
|
-
_e.trys.push([1, 7, 8, 9]);
|
|
608
|
-
pairs_1 = __values(pairs), pairs_1_1 = pairs_1.next();
|
|
609
|
-
_e.label = 2;
|
|
610
|
-
case 2:
|
|
611
|
-
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
612
|
-
pair = pairs_1_1.value;
|
|
613
|
-
_b = (_a = syncPairs).push;
|
|
614
|
-
_d = {};
|
|
615
|
-
return [4 /*yield*/, pair.key];
|
|
616
|
-
case 3:
|
|
617
|
-
_d.key = _e.sent();
|
|
618
|
-
return [4 /*yield*/, pair.value];
|
|
619
|
-
case 4:
|
|
620
|
-
_b.apply(_a, [(_d.value = _e.sent(),
|
|
621
|
-
_d)]);
|
|
622
|
-
_e.label = 5;
|
|
623
|
-
case 5:
|
|
624
|
-
pairs_1_1 = pairs_1.next();
|
|
625
|
-
return [3 /*break*/, 2];
|
|
626
|
-
case 6: return [3 /*break*/, 9];
|
|
627
|
-
case 7:
|
|
628
|
-
e_3_1 = _e.sent();
|
|
629
|
-
e_3 = { error: e_3_1 };
|
|
630
|
-
return [3 /*break*/, 9];
|
|
631
|
-
case 8:
|
|
632
|
-
try {
|
|
633
|
-
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
634
|
-
}
|
|
635
|
-
finally { if (e_3) throw e_3.error; }
|
|
636
|
-
return [7 /*endfinally*/];
|
|
637
|
-
case 9: return [2 /*return*/, ParseStatus.mergeObjectSync(status, syncPairs)];
|
|
638
|
-
}
|
|
376
|
+
}
|
|
377
|
+
static async mergeObjectAsync(status, pairs) {
|
|
378
|
+
const syncPairs = [];
|
|
379
|
+
for (const pair of pairs) {
|
|
380
|
+
syncPairs.push({
|
|
381
|
+
key: await pair.key,
|
|
382
|
+
value: await pair.value,
|
|
639
383
|
});
|
|
640
|
-
});
|
|
641
|
-
};
|
|
642
|
-
ParseStatus.mergeObjectSync = function (status, pairs) {
|
|
643
|
-
var e_4, _a;
|
|
644
|
-
var finalObject = {};
|
|
645
|
-
try {
|
|
646
|
-
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
647
|
-
var pair = pairs_2_1.value;
|
|
648
|
-
var key = pair.key, value = pair.value;
|
|
649
|
-
if (key.status === "aborted")
|
|
650
|
-
return INVALID;
|
|
651
|
-
if (value.status === "aborted")
|
|
652
|
-
return INVALID;
|
|
653
|
-
if (key.status === "dirty")
|
|
654
|
-
status.dirty();
|
|
655
|
-
if (value.status === "dirty")
|
|
656
|
-
status.dirty();
|
|
657
|
-
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
|
658
|
-
finalObject[key.value] = value.value;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
384
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
385
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
386
|
+
}
|
|
387
|
+
static mergeObjectSync(status, pairs) {
|
|
388
|
+
const finalObject = {};
|
|
389
|
+
for (const pair of pairs) {
|
|
390
|
+
const { key, value } = pair;
|
|
391
|
+
if (key.status === "aborted")
|
|
392
|
+
return INVALID;
|
|
393
|
+
if (value.status === "aborted")
|
|
394
|
+
return INVALID;
|
|
395
|
+
if (key.status === "dirty")
|
|
396
|
+
status.dirty();
|
|
397
|
+
if (value.status === "dirty")
|
|
398
|
+
status.dirty();
|
|
399
|
+
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
|
400
|
+
finalObject[key.value] = value.value;
|
|
666
401
|
}
|
|
667
|
-
finally { if (e_4) throw e_4.error; }
|
|
668
402
|
}
|
|
669
403
|
return { status: status.value, value: finalObject };
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
var INVALID = Object.freeze({
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const INVALID = Object.freeze({
|
|
674
407
|
status: "aborted",
|
|
675
408
|
});
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return x.status === "dirty";
|
|
683
|
-
};
|
|
684
|
-
var isValid = function (x) {
|
|
685
|
-
return x.status === "valid";
|
|
686
|
-
};
|
|
687
|
-
var isAsync = function (x) {
|
|
688
|
-
return typeof Promise !== undefined && x instanceof Promise;
|
|
689
|
-
};
|
|
409
|
+
const DIRTY = (value) => ({ status: "dirty", value });
|
|
410
|
+
const OK = (value) => ({ status: "valid", value });
|
|
411
|
+
const isAborted = (x) => x.status === "aborted";
|
|
412
|
+
const isDirty = (x) => x.status === "dirty";
|
|
413
|
+
const isValid = (x) => x.status === "valid";
|
|
414
|
+
const isAsync = (x) => typeof Promise !== undefined && x instanceof Promise;
|
|
690
415
|
|
|
691
416
|
var errorUtil;
|
|
692
417
|
(function (errorUtil) {
|
|
693
|
-
errorUtil.errToObj =
|
|
694
|
-
|
|
695
|
-
};
|
|
696
|
-
errorUtil.toString = function (message) {
|
|
697
|
-
return typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
698
|
-
};
|
|
418
|
+
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
419
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
699
420
|
})(errorUtil || (errorUtil = {}));
|
|
700
421
|
|
|
701
|
-
|
|
422
|
+
const handleResult = (ctx, result) => {
|
|
702
423
|
if (isValid(result)) {
|
|
703
424
|
return { success: true, data: result.value };
|
|
704
425
|
}
|
|
705
426
|
else {
|
|
706
|
-
if (!ctx.issues.length) {
|
|
427
|
+
if (!ctx.common.issues.length) {
|
|
707
428
|
throw new Error("Validation failed but no issues detected.");
|
|
708
429
|
}
|
|
709
|
-
|
|
710
|
-
return { success: false, error
|
|
430
|
+
const error = new ZodError(ctx.common.issues);
|
|
431
|
+
return { success: false, error };
|
|
711
432
|
}
|
|
712
433
|
};
|
|
713
434
|
function processCreateParams(params) {
|
|
714
435
|
if (!params)
|
|
715
436
|
return {};
|
|
716
|
-
|
|
437
|
+
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
717
438
|
if (errorMap && (invalid_type_error || required_error)) {
|
|
718
|
-
throw new Error(
|
|
439
|
+
throw new Error(`Can't use "invalid" or "required" in conjunction with custom error map.`);
|
|
719
440
|
}
|
|
720
441
|
if (errorMap)
|
|
721
|
-
return { errorMap: errorMap, description
|
|
722
|
-
|
|
442
|
+
return { errorMap: errorMap, description };
|
|
443
|
+
const customMap = (iss, ctx) => {
|
|
723
444
|
if (iss.code !== "invalid_type")
|
|
724
445
|
return { message: ctx.defaultError };
|
|
725
446
|
if (typeof ctx.data === "undefined" && required_error)
|
|
@@ -728,10 +449,10 @@ function processCreateParams(params) {
|
|
|
728
449
|
return { message: params.invalid_type_error };
|
|
729
450
|
return { message: ctx.defaultError };
|
|
730
451
|
};
|
|
731
|
-
return { errorMap: customMap, description
|
|
452
|
+
return { errorMap: customMap, description };
|
|
732
453
|
}
|
|
733
|
-
|
|
734
|
-
|
|
454
|
+
class ZodType {
|
|
455
|
+
constructor(def) {
|
|
735
456
|
/** Alias of safeParseAsync */
|
|
736
457
|
this.spa = this.safeParseAsync;
|
|
737
458
|
this.superRefine = this._refinement;
|
|
@@ -757,99 +478,100 @@ var ZodType = /** @class */ (function () {
|
|
|
757
478
|
this.isOptional = this.isOptional.bind(this);
|
|
758
479
|
this.isNullable = this.isNullable.bind(this);
|
|
759
480
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
481
|
+
get description() {
|
|
482
|
+
return this._def.description;
|
|
483
|
+
}
|
|
484
|
+
_getType(input) {
|
|
485
|
+
return getParsedType(input.data);
|
|
486
|
+
}
|
|
487
|
+
_getOrReturnCtx(input, ctx) {
|
|
488
|
+
return (ctx || {
|
|
489
|
+
common: input.parent.common,
|
|
490
|
+
data: input.data,
|
|
491
|
+
parsedType: getParsedType(input.data),
|
|
492
|
+
schemaErrorMap: this._def.errorMap,
|
|
493
|
+
path: input.path,
|
|
494
|
+
parent: input.parent,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
_processInputParams(input) {
|
|
768
498
|
return {
|
|
769
499
|
status: new ParseStatus(),
|
|
770
|
-
ctx:
|
|
500
|
+
ctx: {
|
|
501
|
+
common: input.parent.common,
|
|
502
|
+
data: input.data,
|
|
503
|
+
parsedType: getParsedType(input.data),
|
|
504
|
+
schemaErrorMap: this._def.errorMap,
|
|
505
|
+
path: input.path,
|
|
506
|
+
parent: input.parent,
|
|
507
|
+
},
|
|
771
508
|
};
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
509
|
+
}
|
|
510
|
+
_parseSync(input) {
|
|
511
|
+
const result = this._parse(input);
|
|
775
512
|
if (isAsync(result)) {
|
|
776
513
|
throw new Error("Synchronous parse encountered promise.");
|
|
777
514
|
}
|
|
778
515
|
return result;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
|
|
516
|
+
}
|
|
517
|
+
_parseAsync(input) {
|
|
518
|
+
const result = this._parse(input);
|
|
782
519
|
return Promise.resolve(result);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
|
|
520
|
+
}
|
|
521
|
+
parse(data, params) {
|
|
522
|
+
const result = this.safeParse(data, params);
|
|
786
523
|
if (result.success)
|
|
787
524
|
return result.data;
|
|
788
525
|
throw result.error;
|
|
789
|
-
}
|
|
790
|
-
|
|
526
|
+
}
|
|
527
|
+
safeParse(data, params) {
|
|
791
528
|
var _a;
|
|
792
|
-
|
|
529
|
+
const ctx = {
|
|
530
|
+
common: {
|
|
531
|
+
issues: [],
|
|
532
|
+
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
533
|
+
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
534
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
535
|
+
},
|
|
793
536
|
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
794
|
-
issues: [],
|
|
795
|
-
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
796
537
|
schemaErrorMap: this._def.errorMap,
|
|
797
|
-
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
798
|
-
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
799
538
|
parent: null,
|
|
800
|
-
data
|
|
539
|
+
data,
|
|
801
540
|
parsedType: getParsedType(data),
|
|
802
541
|
};
|
|
803
|
-
|
|
542
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
804
543
|
return handleResult(ctx, result);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
return
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
parent: null,
|
|
835
|
-
data: data,
|
|
836
|
-
parsedType: getParsedType(data),
|
|
837
|
-
};
|
|
838
|
-
maybeAsyncResult = this._parse({ data: data, path: [], parent: ctx });
|
|
839
|
-
return [4 /*yield*/, (isAsync(maybeAsyncResult)
|
|
840
|
-
? maybeAsyncResult
|
|
841
|
-
: Promise.resolve(maybeAsyncResult))];
|
|
842
|
-
case 1:
|
|
843
|
-
result = _a.sent();
|
|
844
|
-
return [2 /*return*/, handleResult(ctx, result)];
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
});
|
|
848
|
-
};
|
|
849
|
-
ZodType.prototype.refine = function (check, message) {
|
|
850
|
-
var getIssueProperties = function (val) {
|
|
544
|
+
}
|
|
545
|
+
async parseAsync(data, params) {
|
|
546
|
+
const result = await this.safeParseAsync(data, params);
|
|
547
|
+
if (result.success)
|
|
548
|
+
return result.data;
|
|
549
|
+
throw result.error;
|
|
550
|
+
}
|
|
551
|
+
async safeParseAsync(data, params) {
|
|
552
|
+
const ctx = {
|
|
553
|
+
common: {
|
|
554
|
+
issues: [],
|
|
555
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
556
|
+
async: true,
|
|
557
|
+
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
558
|
+
},
|
|
559
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
560
|
+
schemaErrorMap: this._def.errorMap,
|
|
561
|
+
parent: null,
|
|
562
|
+
data,
|
|
563
|
+
parsedType: getParsedType(data),
|
|
564
|
+
};
|
|
565
|
+
const maybeAsyncResult = this._parse({ data, path: [], parent: ctx });
|
|
566
|
+
const result = await (isAsync(maybeAsyncResult)
|
|
567
|
+
? maybeAsyncResult
|
|
568
|
+
: Promise.resolve(maybeAsyncResult));
|
|
569
|
+
return handleResult(ctx, result);
|
|
570
|
+
}
|
|
571
|
+
refine(check, message) {
|
|
572
|
+
const getIssueProperties = (val) => {
|
|
851
573
|
if (typeof message === "string" || typeof message === "undefined") {
|
|
852
|
-
return { message
|
|
574
|
+
return { message };
|
|
853
575
|
}
|
|
854
576
|
else if (typeof message === "function") {
|
|
855
577
|
return message(val);
|
|
@@ -858,13 +580,14 @@ var ZodType = /** @class */ (function () {
|
|
|
858
580
|
return message;
|
|
859
581
|
}
|
|
860
582
|
};
|
|
861
|
-
return this._refinement(
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
583
|
+
return this._refinement((val, ctx) => {
|
|
584
|
+
const result = check(val);
|
|
585
|
+
const setError = () => ctx.addIssue({
|
|
586
|
+
code: ZodIssueCode.custom,
|
|
587
|
+
...getIssueProperties(val),
|
|
588
|
+
});
|
|
866
589
|
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
867
|
-
return result.then(
|
|
590
|
+
return result.then((data) => {
|
|
868
591
|
if (!data) {
|
|
869
592
|
setError();
|
|
870
593
|
return false;
|
|
@@ -882,9 +605,9 @@ var ZodType = /** @class */ (function () {
|
|
|
882
605
|
return true;
|
|
883
606
|
}
|
|
884
607
|
});
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
return this._refinement(
|
|
608
|
+
}
|
|
609
|
+
refinement(check, refinementData) {
|
|
610
|
+
return this._refinement((val, ctx) => {
|
|
888
611
|
if (!check(val)) {
|
|
889
612
|
ctx.addIssue(typeof refinementData === "function"
|
|
890
613
|
? refinementData(val, ctx)
|
|
@@ -895,89 +618,89 @@ var ZodType = /** @class */ (function () {
|
|
|
895
618
|
return true;
|
|
896
619
|
}
|
|
897
620
|
});
|
|
898
|
-
}
|
|
899
|
-
|
|
621
|
+
}
|
|
622
|
+
_refinement(refinement) {
|
|
900
623
|
return new ZodEffects({
|
|
901
624
|
schema: this,
|
|
902
625
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
903
|
-
effect: { type: "refinement", refinement
|
|
626
|
+
effect: { type: "refinement", refinement },
|
|
904
627
|
});
|
|
905
|
-
}
|
|
906
|
-
|
|
628
|
+
}
|
|
629
|
+
optional() {
|
|
907
630
|
return ZodOptional.create(this);
|
|
908
|
-
}
|
|
909
|
-
|
|
631
|
+
}
|
|
632
|
+
nullable() {
|
|
910
633
|
return ZodNullable.create(this);
|
|
911
|
-
}
|
|
912
|
-
|
|
634
|
+
}
|
|
635
|
+
nullish() {
|
|
913
636
|
return this.optional().nullable();
|
|
914
|
-
}
|
|
915
|
-
|
|
637
|
+
}
|
|
638
|
+
array() {
|
|
916
639
|
return ZodArray.create(this);
|
|
917
|
-
}
|
|
918
|
-
|
|
640
|
+
}
|
|
641
|
+
promise() {
|
|
919
642
|
return ZodPromise.create(this);
|
|
920
|
-
}
|
|
921
|
-
|
|
643
|
+
}
|
|
644
|
+
or(option) {
|
|
922
645
|
return ZodUnion.create([this, option]);
|
|
923
|
-
}
|
|
924
|
-
|
|
646
|
+
}
|
|
647
|
+
and(incoming) {
|
|
925
648
|
return ZodIntersection.create(this, incoming);
|
|
926
|
-
}
|
|
927
|
-
|
|
649
|
+
}
|
|
650
|
+
transform(transform) {
|
|
928
651
|
return new ZodEffects({
|
|
929
652
|
schema: this,
|
|
930
653
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
931
|
-
effect: { type: "transform", transform
|
|
654
|
+
effect: { type: "transform", transform },
|
|
932
655
|
});
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
|
|
656
|
+
}
|
|
657
|
+
default(def) {
|
|
658
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
936
659
|
return new ZodDefault({
|
|
937
660
|
innerType: this,
|
|
938
661
|
defaultValue: defaultValueFunc,
|
|
939
662
|
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
940
663
|
});
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
return new This(
|
|
945
|
-
|
|
946
|
-
|
|
664
|
+
}
|
|
665
|
+
describe(description) {
|
|
666
|
+
const This = this.constructor;
|
|
667
|
+
return new This({
|
|
668
|
+
...this._def,
|
|
669
|
+
description,
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
isOptional() {
|
|
947
673
|
return this.safeParse(undefined).success;
|
|
948
|
-
}
|
|
949
|
-
|
|
674
|
+
}
|
|
675
|
+
isNullable() {
|
|
950
676
|
return this.safeParse(null).success;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
680
|
+
const uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
956
681
|
// from https://stackoverflow.com/a/46181/1550155
|
|
957
682
|
// old version: too slow, didn't support unicode
|
|
958
683
|
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
959
684
|
// eslint-disable-next-line
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
685
|
+
const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
686
|
+
class ZodString extends ZodType {
|
|
687
|
+
constructor() {
|
|
688
|
+
super(...arguments);
|
|
689
|
+
this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
|
|
690
|
+
validation,
|
|
691
|
+
code: ZodIssueCode.invalid_string,
|
|
692
|
+
...errorUtil.errToObj(message),
|
|
693
|
+
});
|
|
968
694
|
/**
|
|
969
695
|
* Deprecated.
|
|
970
696
|
* Use z.string().min(1) instead.
|
|
971
697
|
*/
|
|
972
|
-
|
|
973
|
-
return _this.min(1, errorUtil.errToObj(message));
|
|
974
|
-
};
|
|
975
|
-
return _this;
|
|
698
|
+
this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
|
|
976
699
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
700
|
+
_parse(input) {
|
|
701
|
+
const parsedType = this._getType(input);
|
|
702
|
+
if (parsedType !== ZodParsedType.string) {
|
|
703
|
+
const ctx = this._getOrReturnCtx(input);
|
|
981
704
|
addIssueToContext(ctx, {
|
|
982
705
|
code: ZodIssueCode.invalid_type,
|
|
983
706
|
expected: ZodParsedType.string,
|
|
@@ -987,211 +710,202 @@ var ZodString = /** @class */ (function (_super) {
|
|
|
987
710
|
);
|
|
988
711
|
return INVALID;
|
|
989
712
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
713
|
+
const status = new ParseStatus();
|
|
714
|
+
let ctx = undefined;
|
|
715
|
+
for (const check of this._def.checks) {
|
|
716
|
+
if (check.kind === "min") {
|
|
717
|
+
if (input.data.length < check.value) {
|
|
718
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
719
|
+
addIssueToContext(ctx, {
|
|
720
|
+
code: ZodIssueCode.too_small,
|
|
721
|
+
minimum: check.value,
|
|
722
|
+
type: "string",
|
|
723
|
+
inclusive: true,
|
|
724
|
+
message: check.message,
|
|
725
|
+
});
|
|
726
|
+
status.dirty();
|
|
1004
727
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
728
|
+
}
|
|
729
|
+
else if (check.kind === "max") {
|
|
730
|
+
if (input.data.length > check.value) {
|
|
731
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
732
|
+
addIssueToContext(ctx, {
|
|
733
|
+
code: ZodIssueCode.too_big,
|
|
734
|
+
maximum: check.value,
|
|
735
|
+
type: "string",
|
|
736
|
+
inclusive: true,
|
|
737
|
+
message: check.message,
|
|
738
|
+
});
|
|
739
|
+
status.dirty();
|
|
1016
740
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
}
|
|
741
|
+
}
|
|
742
|
+
else if (check.kind === "email") {
|
|
743
|
+
if (!emailRegex.test(input.data)) {
|
|
744
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
745
|
+
addIssueToContext(ctx, {
|
|
746
|
+
validation: "email",
|
|
747
|
+
code: ZodIssueCode.invalid_string,
|
|
748
|
+
message: check.message,
|
|
749
|
+
});
|
|
750
|
+
status.dirty();
|
|
1026
751
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
}
|
|
752
|
+
}
|
|
753
|
+
else if (check.kind === "uuid") {
|
|
754
|
+
if (!uuidRegex.test(input.data)) {
|
|
755
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
756
|
+
addIssueToContext(ctx, {
|
|
757
|
+
validation: "uuid",
|
|
758
|
+
code: ZodIssueCode.invalid_string,
|
|
759
|
+
message: check.message,
|
|
760
|
+
});
|
|
761
|
+
status.dirty();
|
|
1036
762
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}
|
|
763
|
+
}
|
|
764
|
+
else if (check.kind === "cuid") {
|
|
765
|
+
if (!cuidRegex.test(input.data)) {
|
|
766
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
767
|
+
addIssueToContext(ctx, {
|
|
768
|
+
validation: "cuid",
|
|
769
|
+
code: ZodIssueCode.invalid_string,
|
|
770
|
+
message: check.message,
|
|
771
|
+
});
|
|
772
|
+
status.dirty();
|
|
1046
773
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
catch (_e) {
|
|
1052
|
-
addIssueToContext(ctx, {
|
|
1053
|
-
validation: "url",
|
|
1054
|
-
code: ZodIssueCode.invalid_string,
|
|
1055
|
-
message: check.message,
|
|
1056
|
-
});
|
|
1057
|
-
status.dirty();
|
|
1058
|
-
}
|
|
774
|
+
}
|
|
775
|
+
else if (check.kind === "url") {
|
|
776
|
+
try {
|
|
777
|
+
new URL(input.data);
|
|
1059
778
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
});
|
|
1069
|
-
status.dirty();
|
|
1070
|
-
}
|
|
779
|
+
catch (_a) {
|
|
780
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
781
|
+
addIssueToContext(ctx, {
|
|
782
|
+
validation: "url",
|
|
783
|
+
code: ZodIssueCode.invalid_string,
|
|
784
|
+
message: check.message,
|
|
785
|
+
});
|
|
786
|
+
status.dirty();
|
|
1071
787
|
}
|
|
1072
788
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
789
|
+
else if (check.kind === "regex") {
|
|
790
|
+
check.regex.lastIndex = 0;
|
|
791
|
+
const testResult = check.regex.test(input.data);
|
|
792
|
+
if (!testResult) {
|
|
793
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
794
|
+
addIssueToContext(ctx, {
|
|
795
|
+
validation: "regex",
|
|
796
|
+
code: ZodIssueCode.invalid_string,
|
|
797
|
+
message: check.message,
|
|
798
|
+
});
|
|
799
|
+
status.dirty();
|
|
800
|
+
}
|
|
1078
801
|
}
|
|
1079
|
-
finally { if (e_1) throw e_1.error; }
|
|
1080
802
|
}
|
|
1081
|
-
return { status: status.value, value:
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
return new ZodString(
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
return this._addCheck(
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
return this._addCheck(
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
return this._addCheck(
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
return this._addCheck(
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
return this._addCheck(
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
803
|
+
return { status: status.value, value: input.data };
|
|
804
|
+
}
|
|
805
|
+
_addCheck(check) {
|
|
806
|
+
return new ZodString({
|
|
807
|
+
...this._def,
|
|
808
|
+
checks: [...this._def.checks, check],
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
email(message) {
|
|
812
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
813
|
+
}
|
|
814
|
+
url(message) {
|
|
815
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
816
|
+
}
|
|
817
|
+
uuid(message) {
|
|
818
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
819
|
+
}
|
|
820
|
+
cuid(message) {
|
|
821
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
822
|
+
}
|
|
823
|
+
regex(regex, message) {
|
|
824
|
+
return this._addCheck({
|
|
825
|
+
kind: "regex",
|
|
826
|
+
regex: regex,
|
|
827
|
+
...errorUtil.errToObj(message),
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
min(minLength, message) {
|
|
831
|
+
return this._addCheck({
|
|
832
|
+
kind: "min",
|
|
833
|
+
value: minLength,
|
|
834
|
+
...errorUtil.errToObj(message),
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
max(maxLength, message) {
|
|
838
|
+
return this._addCheck({
|
|
839
|
+
kind: "max",
|
|
840
|
+
value: maxLength,
|
|
841
|
+
...errorUtil.errToObj(message),
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
length(len, message) {
|
|
1108
845
|
return this.min(len, message).max(len, message);
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
enumerable: false,
|
|
1129
|
-
configurable: true
|
|
1130
|
-
});
|
|
1131
|
-
Object.defineProperty(ZodString.prototype, "isCUID", {
|
|
1132
|
-
get: function () {
|
|
1133
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "cuid"; });
|
|
1134
|
-
},
|
|
1135
|
-
enumerable: false,
|
|
1136
|
-
configurable: true
|
|
1137
|
-
});
|
|
1138
|
-
Object.defineProperty(ZodString.prototype, "minLength", {
|
|
1139
|
-
get: function () {
|
|
1140
|
-
var min = -Infinity;
|
|
1141
|
-
this._def.checks.map(function (ch) {
|
|
1142
|
-
if (ch.kind === "min") {
|
|
1143
|
-
if (min === null || ch.value > min) {
|
|
1144
|
-
min = ch.value;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
|
-
return min;
|
|
1149
|
-
},
|
|
1150
|
-
enumerable: false,
|
|
1151
|
-
configurable: true
|
|
1152
|
-
});
|
|
1153
|
-
Object.defineProperty(ZodString.prototype, "maxLength", {
|
|
1154
|
-
get: function () {
|
|
1155
|
-
var max = null;
|
|
1156
|
-
this._def.checks.map(function (ch) {
|
|
1157
|
-
if (ch.kind === "max") {
|
|
1158
|
-
if (max === null || ch.value < max) {
|
|
1159
|
-
max = ch.value;
|
|
1160
|
-
}
|
|
846
|
+
}
|
|
847
|
+
get isEmail() {
|
|
848
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
849
|
+
}
|
|
850
|
+
get isURL() {
|
|
851
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
852
|
+
}
|
|
853
|
+
get isUUID() {
|
|
854
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
855
|
+
}
|
|
856
|
+
get isCUID() {
|
|
857
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
858
|
+
}
|
|
859
|
+
get minLength() {
|
|
860
|
+
let min = -Infinity;
|
|
861
|
+
this._def.checks.map((ch) => {
|
|
862
|
+
if (ch.kind === "min") {
|
|
863
|
+
if (min === null || ch.value > min) {
|
|
864
|
+
min = ch.value;
|
|
1161
865
|
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
return min;
|
|
869
|
+
}
|
|
870
|
+
get maxLength() {
|
|
871
|
+
let max = null;
|
|
872
|
+
this._def.checks.map((ch) => {
|
|
873
|
+
if (ch.kind === "max") {
|
|
874
|
+
if (max === null || ch.value < max) {
|
|
875
|
+
max = ch.value;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
return max;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
ZodString.create = (params) => {
|
|
883
|
+
return new ZodString({
|
|
884
|
+
checks: [],
|
|
885
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
886
|
+
...processCreateParams(params),
|
|
1167
887
|
});
|
|
1168
|
-
|
|
1169
|
-
return new ZodString(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString }, processCreateParams(params)));
|
|
1170
|
-
};
|
|
1171
|
-
return ZodString;
|
|
1172
|
-
}(ZodType));
|
|
888
|
+
};
|
|
1173
889
|
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
|
1174
890
|
function floatSafeRemainder(val, step) {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
891
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
892
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
893
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
894
|
+
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
895
|
+
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1180
896
|
return (valInt % stepInt) / Math.pow(10, decCount);
|
|
1181
897
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
1194
|
-
if (ctx.parsedType !== ZodParsedType.number) {
|
|
898
|
+
class ZodNumber extends ZodType {
|
|
899
|
+
constructor() {
|
|
900
|
+
super(...arguments);
|
|
901
|
+
this.min = this.gte;
|
|
902
|
+
this.max = this.lte;
|
|
903
|
+
this.step = this.multipleOf;
|
|
904
|
+
}
|
|
905
|
+
_parse(input) {
|
|
906
|
+
const parsedType = this._getType(input);
|
|
907
|
+
if (parsedType !== ZodParsedType.number) {
|
|
908
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1195
909
|
addIssueToContext(ctx, {
|
|
1196
910
|
code: ZodIssueCode.invalid_type,
|
|
1197
911
|
expected: ZodParsedType.number,
|
|
@@ -1199,214 +913,183 @@ var ZodNumber = /** @class */ (function (_super) {
|
|
|
1199
913
|
});
|
|
1200
914
|
return INVALID;
|
|
1201
915
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
else if (check.kind === "min") {
|
|
1217
|
-
var tooSmall = check.inclusive
|
|
1218
|
-
? ctx.data < check.value
|
|
1219
|
-
: ctx.data <= check.value;
|
|
1220
|
-
if (tooSmall) {
|
|
1221
|
-
addIssueToContext(ctx, {
|
|
1222
|
-
code: ZodIssueCode.too_small,
|
|
1223
|
-
minimum: check.value,
|
|
1224
|
-
type: "number",
|
|
1225
|
-
inclusive: check.inclusive,
|
|
1226
|
-
message: check.message,
|
|
1227
|
-
});
|
|
1228
|
-
status.dirty();
|
|
1229
|
-
}
|
|
916
|
+
let ctx = undefined;
|
|
917
|
+
const status = new ParseStatus();
|
|
918
|
+
for (const check of this._def.checks) {
|
|
919
|
+
if (check.kind === "int") {
|
|
920
|
+
if (!util.isInteger(input.data)) {
|
|
921
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
922
|
+
addIssueToContext(ctx, {
|
|
923
|
+
code: ZodIssueCode.invalid_type,
|
|
924
|
+
expected: "integer",
|
|
925
|
+
received: "float",
|
|
926
|
+
message: check.message,
|
|
927
|
+
});
|
|
928
|
+
status.dirty();
|
|
1230
929
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
}
|
|
930
|
+
}
|
|
931
|
+
else if (check.kind === "min") {
|
|
932
|
+
const tooSmall = check.inclusive
|
|
933
|
+
? input.data < check.value
|
|
934
|
+
: input.data <= check.value;
|
|
935
|
+
if (tooSmall) {
|
|
936
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
937
|
+
addIssueToContext(ctx, {
|
|
938
|
+
code: ZodIssueCode.too_small,
|
|
939
|
+
minimum: check.value,
|
|
940
|
+
type: "number",
|
|
941
|
+
inclusive: check.inclusive,
|
|
942
|
+
message: check.message,
|
|
943
|
+
});
|
|
944
|
+
status.dirty();
|
|
1245
945
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
946
|
+
}
|
|
947
|
+
else if (check.kind === "max") {
|
|
948
|
+
const tooBig = check.inclusive
|
|
949
|
+
? input.data > check.value
|
|
950
|
+
: input.data >= check.value;
|
|
951
|
+
if (tooBig) {
|
|
952
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
953
|
+
addIssueToContext(ctx, {
|
|
954
|
+
code: ZodIssueCode.too_big,
|
|
955
|
+
maximum: check.value,
|
|
956
|
+
type: "number",
|
|
957
|
+
inclusive: check.inclusive,
|
|
958
|
+
message: check.message,
|
|
959
|
+
});
|
|
960
|
+
status.dirty();
|
|
1255
961
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
962
|
+
}
|
|
963
|
+
else if (check.kind === "multipleOf") {
|
|
964
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
965
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
966
|
+
addIssueToContext(ctx, {
|
|
967
|
+
code: ZodIssueCode.not_multiple_of,
|
|
968
|
+
multipleOf: check.value,
|
|
969
|
+
message: check.message,
|
|
970
|
+
});
|
|
971
|
+
status.dirty();
|
|
1258
972
|
}
|
|
1259
973
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
finally {
|
|
1263
|
-
try {
|
|
1264
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
974
|
+
else {
|
|
975
|
+
util.assertNever(check);
|
|
1265
976
|
}
|
|
1266
|
-
finally { if (e_2) throw e_2.error; }
|
|
1267
977
|
}
|
|
1268
|
-
return { status: status.value, value:
|
|
1269
|
-
}
|
|
1270
|
-
|
|
978
|
+
return { status: status.value, value: input.data };
|
|
979
|
+
}
|
|
980
|
+
gte(value, message) {
|
|
1271
981
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1272
|
-
}
|
|
1273
|
-
|
|
982
|
+
}
|
|
983
|
+
gt(value, message) {
|
|
1274
984
|
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1275
|
-
}
|
|
1276
|
-
|
|
985
|
+
}
|
|
986
|
+
lte(value, message) {
|
|
1277
987
|
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1278
|
-
}
|
|
1279
|
-
|
|
988
|
+
}
|
|
989
|
+
lt(value, message) {
|
|
1280
990
|
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
return new ZodNumber(
|
|
991
|
+
}
|
|
992
|
+
setLimit(kind, value, inclusive, message) {
|
|
993
|
+
return new ZodNumber({
|
|
994
|
+
...this._def,
|
|
995
|
+
checks: [
|
|
996
|
+
...this._def.checks,
|
|
1284
997
|
{
|
|
1285
|
-
kind
|
|
1286
|
-
value
|
|
1287
|
-
inclusive
|
|
998
|
+
kind,
|
|
999
|
+
value,
|
|
1000
|
+
inclusive,
|
|
1288
1001
|
message: errorUtil.toString(message),
|
|
1289
1002
|
},
|
|
1290
|
-
],
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1003
|
+
],
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
_addCheck(check) {
|
|
1007
|
+
return new ZodNumber({
|
|
1008
|
+
...this._def,
|
|
1009
|
+
checks: [...this._def.checks, check],
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
int(message) {
|
|
1296
1013
|
return this._addCheck({
|
|
1297
1014
|
kind: "int",
|
|
1298
1015
|
message: errorUtil.toString(message),
|
|
1299
1016
|
});
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1017
|
+
}
|
|
1018
|
+
positive(message) {
|
|
1302
1019
|
return this._addCheck({
|
|
1303
1020
|
kind: "min",
|
|
1304
1021
|
value: 0,
|
|
1305
1022
|
inclusive: false,
|
|
1306
1023
|
message: errorUtil.toString(message),
|
|
1307
1024
|
});
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1025
|
+
}
|
|
1026
|
+
negative(message) {
|
|
1310
1027
|
return this._addCheck({
|
|
1311
1028
|
kind: "max",
|
|
1312
1029
|
value: 0,
|
|
1313
1030
|
inclusive: false,
|
|
1314
1031
|
message: errorUtil.toString(message),
|
|
1315
1032
|
});
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1033
|
+
}
|
|
1034
|
+
nonpositive(message) {
|
|
1318
1035
|
return this._addCheck({
|
|
1319
1036
|
kind: "max",
|
|
1320
1037
|
value: 0,
|
|
1321
1038
|
inclusive: true,
|
|
1322
1039
|
message: errorUtil.toString(message),
|
|
1323
1040
|
});
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1041
|
+
}
|
|
1042
|
+
nonnegative(message) {
|
|
1326
1043
|
return this._addCheck({
|
|
1327
1044
|
kind: "min",
|
|
1328
1045
|
value: 0,
|
|
1329
1046
|
inclusive: true,
|
|
1330
1047
|
message: errorUtil.toString(message),
|
|
1331
1048
|
});
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1049
|
+
}
|
|
1050
|
+
multipleOf(value, message) {
|
|
1334
1051
|
return this._addCheck({
|
|
1335
1052
|
kind: "multipleOf",
|
|
1336
1053
|
value: value,
|
|
1337
1054
|
message: errorUtil.toString(message),
|
|
1338
1055
|
});
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
var ch = _c.value;
|
|
1347
|
-
if (ch.kind === "min") {
|
|
1348
|
-
if (min === null || ch.value > min)
|
|
1349
|
-
min = ch.value;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1354
|
-
finally {
|
|
1355
|
-
try {
|
|
1356
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1357
|
-
}
|
|
1358
|
-
finally { if (e_3) throw e_3.error; }
|
|
1359
|
-
}
|
|
1360
|
-
return min;
|
|
1361
|
-
},
|
|
1362
|
-
enumerable: false,
|
|
1363
|
-
configurable: true
|
|
1364
|
-
});
|
|
1365
|
-
Object.defineProperty(ZodNumber.prototype, "maxValue", {
|
|
1366
|
-
get: function () {
|
|
1367
|
-
var e_4, _a;
|
|
1368
|
-
var max = null;
|
|
1369
|
-
try {
|
|
1370
|
-
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1371
|
-
var ch = _c.value;
|
|
1372
|
-
if (ch.kind === "max") {
|
|
1373
|
-
if (max === null || ch.value < max)
|
|
1374
|
-
max = ch.value;
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1056
|
+
}
|
|
1057
|
+
get minValue() {
|
|
1058
|
+
let min = null;
|
|
1059
|
+
for (const ch of this._def.checks) {
|
|
1060
|
+
if (ch.kind === "min") {
|
|
1061
|
+
if (min === null || ch.value > min)
|
|
1062
|
+
min = ch.value;
|
|
1377
1063
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1064
|
+
}
|
|
1065
|
+
return min;
|
|
1066
|
+
}
|
|
1067
|
+
get maxValue() {
|
|
1068
|
+
let max = null;
|
|
1069
|
+
for (const ch of this._def.checks) {
|
|
1070
|
+
if (ch.kind === "max") {
|
|
1071
|
+
if (max === null || ch.value < max)
|
|
1072
|
+
max = ch.value;
|
|
1384
1073
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1074
|
+
}
|
|
1075
|
+
return max;
|
|
1076
|
+
}
|
|
1077
|
+
get isInt() {
|
|
1078
|
+
return !!this._def.checks.find((ch) => ch.kind === "int");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
ZodNumber.create = (params) => {
|
|
1082
|
+
return new ZodNumber({
|
|
1083
|
+
checks: [],
|
|
1084
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1085
|
+
...processCreateParams(params),
|
|
1396
1086
|
});
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
__extends(ZodBigInt, _super);
|
|
1404
|
-
function ZodBigInt() {
|
|
1405
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1406
|
-
}
|
|
1407
|
-
ZodBigInt.prototype._parse = function (input) {
|
|
1408
|
-
var ctx = this._processInputParams(input).ctx;
|
|
1409
|
-
if (ctx.parsedType !== ZodParsedType.bigint) {
|
|
1087
|
+
};
|
|
1088
|
+
class ZodBigInt extends ZodType {
|
|
1089
|
+
_parse(input) {
|
|
1090
|
+
const parsedType = this._getType(input);
|
|
1091
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
1092
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1410
1093
|
addIssueToContext(ctx, {
|
|
1411
1094
|
code: ZodIssueCode.invalid_type,
|
|
1412
1095
|
expected: ZodParsedType.bigint,
|
|
@@ -1414,21 +1097,20 @@ var ZodBigInt = /** @class */ (function (_super) {
|
|
|
1414
1097
|
});
|
|
1415
1098
|
return INVALID;
|
|
1416
1099
|
}
|
|
1417
|
-
return OK(
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
if (ctx.parsedType !== ZodParsedType.boolean) {
|
|
1100
|
+
return OK(input.data);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
ZodBigInt.create = (params) => {
|
|
1104
|
+
return new ZodBigInt({
|
|
1105
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1106
|
+
...processCreateParams(params),
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
class ZodBoolean extends ZodType {
|
|
1110
|
+
_parse(input) {
|
|
1111
|
+
const parsedType = this._getType(input);
|
|
1112
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
1113
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1432
1114
|
addIssueToContext(ctx, {
|
|
1433
1115
|
code: ZodIssueCode.invalid_type,
|
|
1434
1116
|
expected: ZodParsedType.boolean,
|
|
@@ -1436,21 +1118,20 @@ var ZodBoolean = /** @class */ (function (_super) {
|
|
|
1436
1118
|
});
|
|
1437
1119
|
return INVALID;
|
|
1438
1120
|
}
|
|
1439
|
-
return OK(
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
if (ctx.parsedType !== ZodParsedType.date) {
|
|
1121
|
+
return OK(input.data);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
ZodBoolean.create = (params) => {
|
|
1125
|
+
return new ZodBoolean({
|
|
1126
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1127
|
+
...processCreateParams(params),
|
|
1128
|
+
});
|
|
1129
|
+
};
|
|
1130
|
+
class ZodDate extends ZodType {
|
|
1131
|
+
_parse(input) {
|
|
1132
|
+
const parsedType = this._getType(input);
|
|
1133
|
+
if (parsedType !== ZodParsedType.date) {
|
|
1134
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1454
1135
|
addIssueToContext(ctx, {
|
|
1455
1136
|
code: ZodIssueCode.invalid_type,
|
|
1456
1137
|
expected: ZodParsedType.date,
|
|
@@ -1458,30 +1139,30 @@ var ZodDate = /** @class */ (function (_super) {
|
|
|
1458
1139
|
});
|
|
1459
1140
|
return INVALID;
|
|
1460
1141
|
}
|
|
1461
|
-
if (isNaN(
|
|
1142
|
+
if (isNaN(input.data.getTime())) {
|
|
1143
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1462
1144
|
addIssueToContext(ctx, {
|
|
1463
1145
|
code: ZodIssueCode.invalid_date,
|
|
1464
1146
|
});
|
|
1465
1147
|
return INVALID;
|
|
1466
1148
|
}
|
|
1467
1149
|
return {
|
|
1468
|
-
status:
|
|
1469
|
-
value: new Date(
|
|
1150
|
+
status: "valid",
|
|
1151
|
+
value: new Date(input.data.getTime()),
|
|
1470
1152
|
};
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
if (ctx.parsedType !== ZodParsedType.undefined) {
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
ZodDate.create = (params) => {
|
|
1156
|
+
return new ZodDate({
|
|
1157
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1158
|
+
...processCreateParams(params),
|
|
1159
|
+
});
|
|
1160
|
+
};
|
|
1161
|
+
class ZodUndefined extends ZodType {
|
|
1162
|
+
_parse(input) {
|
|
1163
|
+
const parsedType = this._getType(input);
|
|
1164
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
1165
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1485
1166
|
addIssueToContext(ctx, {
|
|
1486
1167
|
code: ZodIssueCode.invalid_type,
|
|
1487
1168
|
expected: ZodParsedType.undefined,
|
|
@@ -1489,21 +1170,20 @@ var ZodUndefined = /** @class */ (function (_super) {
|
|
|
1489
1170
|
});
|
|
1490
1171
|
return INVALID;
|
|
1491
1172
|
}
|
|
1492
|
-
return OK(
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
if (ctx.parsedType !== ZodParsedType.null) {
|
|
1173
|
+
return OK(input.data);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
ZodUndefined.create = (params) => {
|
|
1177
|
+
return new ZodUndefined({
|
|
1178
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
1179
|
+
...processCreateParams(params),
|
|
1180
|
+
});
|
|
1181
|
+
};
|
|
1182
|
+
class ZodNull extends ZodType {
|
|
1183
|
+
_parse(input) {
|
|
1184
|
+
const parsedType = this._getType(input);
|
|
1185
|
+
if (parsedType !== ZodParsedType.null) {
|
|
1186
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1507
1187
|
addIssueToContext(ctx, {
|
|
1508
1188
|
code: ZodIssueCode.invalid_type,
|
|
1509
1189
|
expected: ZodParsedType.null,
|
|
@@ -1511,74 +1191,69 @@ var ZodNull = /** @class */ (function (_super) {
|
|
|
1511
1191
|
});
|
|
1512
1192
|
return INVALID;
|
|
1513
1193
|
}
|
|
1514
|
-
return OK(
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1194
|
+
return OK(input.data);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
ZodNull.create = (params) => {
|
|
1198
|
+
return new ZodNull({
|
|
1199
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
1200
|
+
...processCreateParams(params),
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
class ZodAny extends ZodType {
|
|
1204
|
+
constructor() {
|
|
1205
|
+
super(...arguments);
|
|
1525
1206
|
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
1526
|
-
|
|
1527
|
-
return _this;
|
|
1207
|
+
this._any = true;
|
|
1528
1208
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1209
|
+
_parse(input) {
|
|
1210
|
+
return OK(input.data);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
ZodAny.create = (params) => {
|
|
1214
|
+
return new ZodAny({
|
|
1215
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
1216
|
+
...processCreateParams(params),
|
|
1217
|
+
});
|
|
1218
|
+
};
|
|
1219
|
+
class ZodUnknown extends ZodType {
|
|
1220
|
+
constructor() {
|
|
1221
|
+
super(...arguments);
|
|
1542
1222
|
// required
|
|
1543
|
-
|
|
1544
|
-
return _this;
|
|
1223
|
+
this._unknown = true;
|
|
1545
1224
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
ZodNever.prototype._parse = function (input) {
|
|
1561
|
-
var ctx = this._processInputParams(input).ctx;
|
|
1225
|
+
_parse(input) {
|
|
1226
|
+
return OK(input.data);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
ZodUnknown.create = (params) => {
|
|
1230
|
+
return new ZodUnknown({
|
|
1231
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
1232
|
+
...processCreateParams(params),
|
|
1233
|
+
});
|
|
1234
|
+
};
|
|
1235
|
+
class ZodNever extends ZodType {
|
|
1236
|
+
_parse(input) {
|
|
1237
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1562
1238
|
addIssueToContext(ctx, {
|
|
1563
1239
|
code: ZodIssueCode.invalid_type,
|
|
1564
1240
|
expected: ZodParsedType.never,
|
|
1565
1241
|
received: ctx.parsedType,
|
|
1566
1242
|
});
|
|
1567
1243
|
return INVALID;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
if (ctx.parsedType !== ZodParsedType.undefined) {
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
ZodNever.create = (params) => {
|
|
1247
|
+
return new ZodNever({
|
|
1248
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
1249
|
+
...processCreateParams(params),
|
|
1250
|
+
});
|
|
1251
|
+
};
|
|
1252
|
+
class ZodVoid extends ZodType {
|
|
1253
|
+
_parse(input) {
|
|
1254
|
+
const parsedType = this._getType(input);
|
|
1255
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
1256
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1582
1257
|
addIssueToContext(ctx, {
|
|
1583
1258
|
code: ZodIssueCode.invalid_type,
|
|
1584
1259
|
expected: ZodParsedType.void,
|
|
@@ -1586,21 +1261,19 @@ var ZodVoid = /** @class */ (function (_super) {
|
|
|
1586
1261
|
});
|
|
1587
1262
|
return INVALID;
|
|
1588
1263
|
}
|
|
1589
|
-
return OK(
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1603
|
-
var def = this._def;
|
|
1264
|
+
return OK(input.data);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
ZodVoid.create = (params) => {
|
|
1268
|
+
return new ZodVoid({
|
|
1269
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
1270
|
+
...processCreateParams(params),
|
|
1271
|
+
});
|
|
1272
|
+
};
|
|
1273
|
+
class ZodArray extends ZodType {
|
|
1274
|
+
_parse(input) {
|
|
1275
|
+
const { ctx, status } = this._processInputParams(input);
|
|
1276
|
+
const def = this._def;
|
|
1604
1277
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
1605
1278
|
addIssueToContext(ctx, {
|
|
1606
1279
|
code: ZodIssueCode.invalid_type,
|
|
@@ -1633,50 +1306,57 @@ var ZodArray = /** @class */ (function (_super) {
|
|
|
1633
1306
|
status.dirty();
|
|
1634
1307
|
}
|
|
1635
1308
|
}
|
|
1636
|
-
if (ctx.async) {
|
|
1637
|
-
return Promise.all(ctx.data.map(
|
|
1309
|
+
if (ctx.common.async) {
|
|
1310
|
+
return Promise.all(ctx.data.map((item, i) => {
|
|
1638
1311
|
return def.type._parseAsync({
|
|
1639
1312
|
parent: ctx,
|
|
1640
|
-
path:
|
|
1313
|
+
path: [...ctx.path, i],
|
|
1641
1314
|
data: item,
|
|
1642
1315
|
});
|
|
1643
|
-
})).then(
|
|
1316
|
+
})).then((result) => {
|
|
1644
1317
|
return ParseStatus.mergeArray(status, result);
|
|
1645
1318
|
});
|
|
1646
1319
|
}
|
|
1647
|
-
|
|
1320
|
+
const result = ctx.data.map((item, i) => {
|
|
1648
1321
|
return def.type._parseSync({
|
|
1649
1322
|
parent: ctx,
|
|
1650
|
-
path:
|
|
1323
|
+
path: [...ctx.path, i],
|
|
1651
1324
|
data: item,
|
|
1652
1325
|
});
|
|
1653
1326
|
});
|
|
1654
1327
|
return ParseStatus.mergeArray(status, result);
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1328
|
+
}
|
|
1329
|
+
get element() {
|
|
1330
|
+
return this._def.type;
|
|
1331
|
+
}
|
|
1332
|
+
min(minLength, message) {
|
|
1333
|
+
return new ZodArray({
|
|
1334
|
+
...this._def,
|
|
1335
|
+
minLength: { value: minLength, message: errorUtil.toString(message) },
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
max(maxLength, message) {
|
|
1339
|
+
return new ZodArray({
|
|
1340
|
+
...this._def,
|
|
1341
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) },
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
length(len, message) {
|
|
1670
1345
|
return this.min(len, message).max(len, message);
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1346
|
+
}
|
|
1347
|
+
nonempty(message) {
|
|
1673
1348
|
return this.min(1, message);
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
ZodArray.create = (schema, params) => {
|
|
1352
|
+
return new ZodArray({
|
|
1353
|
+
type: schema,
|
|
1354
|
+
minLength: null,
|
|
1355
|
+
maxLength: null,
|
|
1356
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
1357
|
+
...processCreateParams(params),
|
|
1358
|
+
});
|
|
1359
|
+
};
|
|
1680
1360
|
/////////////////////////////////////////
|
|
1681
1361
|
/////////////////////////////////////////
|
|
1682
1362
|
////////// //////////
|
|
@@ -1686,23 +1366,33 @@ var ZodArray = /** @class */ (function (_super) {
|
|
|
1686
1366
|
/////////////////////////////////////////
|
|
1687
1367
|
var objectUtil;
|
|
1688
1368
|
(function (objectUtil) {
|
|
1689
|
-
objectUtil.mergeShapes =
|
|
1690
|
-
return
|
|
1369
|
+
objectUtil.mergeShapes = (first, second) => {
|
|
1370
|
+
return {
|
|
1371
|
+
...first,
|
|
1372
|
+
...second, // second overwrites first
|
|
1373
|
+
};
|
|
1691
1374
|
};
|
|
1692
1375
|
})(objectUtil || (objectUtil = {}));
|
|
1693
|
-
|
|
1694
|
-
return
|
|
1695
|
-
|
|
1696
|
-
|
|
1376
|
+
const AugmentFactory = (def) => (augmentation) => {
|
|
1377
|
+
return new ZodObject({
|
|
1378
|
+
...def,
|
|
1379
|
+
shape: () => ({
|
|
1380
|
+
...def.shape(),
|
|
1381
|
+
...augmentation,
|
|
1382
|
+
}),
|
|
1383
|
+
});
|
|
1697
1384
|
};
|
|
1698
1385
|
function deepPartialify(schema) {
|
|
1699
1386
|
if (schema instanceof ZodObject) {
|
|
1700
|
-
|
|
1701
|
-
for (
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
}
|
|
1705
|
-
return new ZodObject(
|
|
1387
|
+
const newShape = {};
|
|
1388
|
+
for (const key in schema.shape) {
|
|
1389
|
+
const fieldSchema = schema.shape[key];
|
|
1390
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
1391
|
+
}
|
|
1392
|
+
return new ZodObject({
|
|
1393
|
+
...schema._def,
|
|
1394
|
+
shape: () => newShape,
|
|
1395
|
+
});
|
|
1706
1396
|
}
|
|
1707
1397
|
else if (schema instanceof ZodArray) {
|
|
1708
1398
|
return ZodArray.create(deepPartialify(schema.element));
|
|
@@ -1714,38 +1404,35 @@ function deepPartialify(schema) {
|
|
|
1714
1404
|
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1715
1405
|
}
|
|
1716
1406
|
else if (schema instanceof ZodTuple) {
|
|
1717
|
-
return ZodTuple.create(schema.items.map(
|
|
1407
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
1718
1408
|
}
|
|
1719
1409
|
else {
|
|
1720
1410
|
return schema;
|
|
1721
1411
|
}
|
|
1722
1412
|
}
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
_this._cached = null;
|
|
1413
|
+
class ZodObject extends ZodType {
|
|
1414
|
+
constructor() {
|
|
1415
|
+
super(...arguments);
|
|
1416
|
+
this._cached = null;
|
|
1728
1417
|
/**
|
|
1729
1418
|
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
1730
1419
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1731
1420
|
*/
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
return _this;
|
|
1421
|
+
this.nonstrict = this.passthrough;
|
|
1422
|
+
this.augment = AugmentFactory(this._def);
|
|
1423
|
+
this.extend = AugmentFactory(this._def);
|
|
1736
1424
|
}
|
|
1737
|
-
|
|
1425
|
+
_getCached() {
|
|
1738
1426
|
if (this._cached !== null)
|
|
1739
1427
|
return this._cached;
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
return (this._cached = { shape
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
1428
|
+
const shape = this._def.shape();
|
|
1429
|
+
const keys = util.objectKeys(shape);
|
|
1430
|
+
return (this._cached = { shape, keys });
|
|
1431
|
+
}
|
|
1432
|
+
_parse(input) {
|
|
1433
|
+
const parsedType = this._getType(input);
|
|
1434
|
+
if (parsedType !== ZodParsedType.object) {
|
|
1435
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1749
1436
|
addIssueToContext(ctx, {
|
|
1750
1437
|
code: ZodIssueCode.invalid_type,
|
|
1751
1438
|
expected: ZodParsedType.object,
|
|
@@ -1753,51 +1440,32 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1753
1440
|
});
|
|
1754
1441
|
return INVALID;
|
|
1755
1442
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1777
|
-
finally {
|
|
1778
|
-
try {
|
|
1779
|
-
if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
|
|
1780
|
-
}
|
|
1781
|
-
finally { if (e_5) throw e_5.error; }
|
|
1443
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1444
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
1445
|
+
const dataKeys = util.objectKeys(ctx.data);
|
|
1446
|
+
const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k));
|
|
1447
|
+
const pairs = [];
|
|
1448
|
+
for (const key of shapeKeys) {
|
|
1449
|
+
const keyValidator = shape[key];
|
|
1450
|
+
const value = ctx.data[key];
|
|
1451
|
+
pairs.push({
|
|
1452
|
+
key: { status: "valid", value: key },
|
|
1453
|
+
value: keyValidator._parse({
|
|
1454
|
+
parent: ctx,
|
|
1455
|
+
data: value,
|
|
1456
|
+
path: [...ctx.path, key],
|
|
1457
|
+
}),
|
|
1458
|
+
alwaysSet: key in ctx.data,
|
|
1459
|
+
});
|
|
1782
1460
|
}
|
|
1783
1461
|
if (this._def.catchall instanceof ZodNever) {
|
|
1784
|
-
|
|
1462
|
+
const unknownKeys = this._def.unknownKeys;
|
|
1785
1463
|
if (unknownKeys === "passthrough") {
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
value: { status: "valid", value: ctx.data[key] },
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1796
|
-
finally {
|
|
1797
|
-
try {
|
|
1798
|
-
if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
|
|
1799
|
-
}
|
|
1800
|
-
finally { if (e_6) throw e_6.error; }
|
|
1464
|
+
for (const key of extraKeys) {
|
|
1465
|
+
pairs.push({
|
|
1466
|
+
key: { status: "valid", value: key },
|
|
1467
|
+
value: { status: "valid", value: ctx.data[key] },
|
|
1468
|
+
});
|
|
1801
1469
|
}
|
|
1802
1470
|
}
|
|
1803
1471
|
else if (unknownKeys === "strict") {
|
|
@@ -1811,321 +1479,302 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1811
1479
|
}
|
|
1812
1480
|
else if (unknownKeys === "strip") ;
|
|
1813
1481
|
else {
|
|
1814
|
-
throw new Error(
|
|
1482
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
1815
1483
|
}
|
|
1816
1484
|
}
|
|
1817
1485
|
else {
|
|
1818
1486
|
// run catchall validation
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
alwaysSet: key in ctx.data,
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1833
|
-
finally {
|
|
1834
|
-
try {
|
|
1835
|
-
if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
|
|
1836
|
-
}
|
|
1837
|
-
finally { if (e_7) throw e_7.error; }
|
|
1487
|
+
const catchall = this._def.catchall;
|
|
1488
|
+
for (const key of extraKeys) {
|
|
1489
|
+
const value = ctx.data[key];
|
|
1490
|
+
pairs.push({
|
|
1491
|
+
key: { status: "valid", value: key },
|
|
1492
|
+
value: catchall._parse({ parent: ctx, path: [...ctx.path, key], data: value } //, ctx.child(key), value, getParsedType(value)
|
|
1493
|
+
),
|
|
1494
|
+
alwaysSet: key in ctx.data,
|
|
1495
|
+
});
|
|
1838
1496
|
}
|
|
1839
1497
|
}
|
|
1840
|
-
if (ctx.async) {
|
|
1498
|
+
if (ctx.common.async) {
|
|
1841
1499
|
return Promise.resolve()
|
|
1842
|
-
.then(
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
1856
|
-
pair = pairs_1_1.value;
|
|
1857
|
-
return [4 /*yield*/, pair.key];
|
|
1858
|
-
case 3:
|
|
1859
|
-
key = _e.sent();
|
|
1860
|
-
_b = (_a = syncPairs).push;
|
|
1861
|
-
_d = {
|
|
1862
|
-
key: key
|
|
1863
|
-
};
|
|
1864
|
-
return [4 /*yield*/, pair.value];
|
|
1865
|
-
case 4:
|
|
1866
|
-
_b.apply(_a, [(_d.value = _e.sent(),
|
|
1867
|
-
_d.alwaysSet = pair.alwaysSet,
|
|
1868
|
-
_d)]);
|
|
1869
|
-
_e.label = 5;
|
|
1870
|
-
case 5:
|
|
1871
|
-
pairs_1_1 = pairs_1.next();
|
|
1872
|
-
return [3 /*break*/, 2];
|
|
1873
|
-
case 6: return [3 /*break*/, 9];
|
|
1874
|
-
case 7:
|
|
1875
|
-
e_8_1 = _e.sent();
|
|
1876
|
-
e_8 = { error: e_8_1 };
|
|
1877
|
-
return [3 /*break*/, 9];
|
|
1878
|
-
case 8:
|
|
1879
|
-
try {
|
|
1880
|
-
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
1881
|
-
}
|
|
1882
|
-
finally { if (e_8) throw e_8.error; }
|
|
1883
|
-
return [7 /*endfinally*/];
|
|
1884
|
-
case 9: return [2 /*return*/, syncPairs];
|
|
1885
|
-
}
|
|
1886
|
-
});
|
|
1887
|
-
}); })
|
|
1888
|
-
.then(function (syncPairs) {
|
|
1500
|
+
.then(async () => {
|
|
1501
|
+
const syncPairs = [];
|
|
1502
|
+
for (const pair of pairs) {
|
|
1503
|
+
const key = await pair.key;
|
|
1504
|
+
syncPairs.push({
|
|
1505
|
+
key,
|
|
1506
|
+
value: await pair.value,
|
|
1507
|
+
alwaysSet: pair.alwaysSet,
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
return syncPairs;
|
|
1511
|
+
})
|
|
1512
|
+
.then((syncPairs) => {
|
|
1889
1513
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1890
1514
|
});
|
|
1891
1515
|
}
|
|
1892
1516
|
else {
|
|
1893
1517
|
return ParseStatus.mergeObjectSync(status, pairs);
|
|
1894
1518
|
}
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
enumerable: false,
|
|
1901
|
-
configurable: true
|
|
1902
|
-
});
|
|
1903
|
-
ZodObject.prototype.strict = function (message) {
|
|
1904
|
-
var _this = this;
|
|
1519
|
+
}
|
|
1520
|
+
get shape() {
|
|
1521
|
+
return this._def.shape();
|
|
1522
|
+
}
|
|
1523
|
+
strict(message) {
|
|
1905
1524
|
errorUtil.errToObj;
|
|
1906
|
-
return new ZodObject(
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1525
|
+
return new ZodObject({
|
|
1526
|
+
...this._def,
|
|
1527
|
+
unknownKeys: "strict",
|
|
1528
|
+
...(message !== undefined
|
|
1529
|
+
? {
|
|
1530
|
+
errorMap: (issue, ctx) => {
|
|
1531
|
+
var _a, _b, _c, _d;
|
|
1532
|
+
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
1533
|
+
if (issue.code === "unrecognized_keys")
|
|
1534
|
+
return {
|
|
1535
|
+
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
|
|
1536
|
+
};
|
|
1912
1537
|
return {
|
|
1913
|
-
message:
|
|
1538
|
+
message: defaultError,
|
|
1914
1539
|
};
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
}
|
|
1540
|
+
},
|
|
1541
|
+
}
|
|
1542
|
+
: {}),
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
strip() {
|
|
1546
|
+
return new ZodObject({
|
|
1547
|
+
...this._def,
|
|
1548
|
+
unknownKeys: "strip",
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
passthrough() {
|
|
1552
|
+
return new ZodObject({
|
|
1553
|
+
...this._def,
|
|
1554
|
+
unknownKeys: "passthrough",
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
setKey(key, schema) {
|
|
1558
|
+
return this.augment({ [key]: schema });
|
|
1559
|
+
}
|
|
1932
1560
|
/**
|
|
1933
1561
|
* Prior to zod@1.0.12 there was a bug in the
|
|
1934
1562
|
* inferred type of merged objects. Please
|
|
1935
1563
|
* upgrade if you are experiencing issues.
|
|
1936
1564
|
*/
|
|
1937
|
-
|
|
1938
|
-
var _this = this;
|
|
1565
|
+
merge(merging) {
|
|
1939
1566
|
// const mergedShape = objectUtil.mergeShapes(
|
|
1940
1567
|
// this._def.shape(),
|
|
1941
1568
|
// merging._def.shape()
|
|
1942
1569
|
// );
|
|
1943
|
-
|
|
1570
|
+
const merged = new ZodObject({
|
|
1944
1571
|
unknownKeys: merging._def.unknownKeys,
|
|
1945
1572
|
catchall: merging._def.catchall,
|
|
1946
|
-
shape:
|
|
1947
|
-
return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
|
|
1948
|
-
},
|
|
1573
|
+
shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1949
1574
|
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1950
1575
|
});
|
|
1951
1576
|
return merged;
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
return new ZodObject(
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
var _this = this;
|
|
1958
|
-
var shape = {};
|
|
1959
|
-
util.objectKeys(mask).map(function (key) {
|
|
1960
|
-
shape[key] = _this.shape[key];
|
|
1577
|
+
}
|
|
1578
|
+
catchall(index) {
|
|
1579
|
+
return new ZodObject({
|
|
1580
|
+
...this._def,
|
|
1581
|
+
catchall: index,
|
|
1961
1582
|
});
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1583
|
+
}
|
|
1584
|
+
pick(mask) {
|
|
1585
|
+
const shape = {};
|
|
1586
|
+
util.objectKeys(mask).map((key) => {
|
|
1587
|
+
shape[key] = this.shape[key];
|
|
1588
|
+
});
|
|
1589
|
+
return new ZodObject({
|
|
1590
|
+
...this._def,
|
|
1591
|
+
shape: () => shape,
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
omit(mask) {
|
|
1595
|
+
const shape = {};
|
|
1596
|
+
util.objectKeys(this.shape).map((key) => {
|
|
1968
1597
|
if (util.objectKeys(mask).indexOf(key) === -1) {
|
|
1969
|
-
shape[key] =
|
|
1598
|
+
shape[key] = this.shape[key];
|
|
1970
1599
|
}
|
|
1971
1600
|
});
|
|
1972
|
-
return new ZodObject(
|
|
1973
|
-
|
|
1974
|
-
|
|
1601
|
+
return new ZodObject({
|
|
1602
|
+
...this._def,
|
|
1603
|
+
shape: () => shape,
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
deepPartial() {
|
|
1975
1607
|
return deepPartialify(this);
|
|
1976
|
-
}
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
var newShape = {};
|
|
1608
|
+
}
|
|
1609
|
+
partial(mask) {
|
|
1610
|
+
const newShape = {};
|
|
1980
1611
|
if (mask) {
|
|
1981
|
-
util.objectKeys(this.shape).map(
|
|
1612
|
+
util.objectKeys(this.shape).map((key) => {
|
|
1982
1613
|
if (util.objectKeys(mask).indexOf(key) === -1) {
|
|
1983
|
-
newShape[key] =
|
|
1614
|
+
newShape[key] = this.shape[key];
|
|
1984
1615
|
}
|
|
1985
1616
|
else {
|
|
1986
|
-
newShape[key] =
|
|
1617
|
+
newShape[key] = this.shape[key].optional();
|
|
1987
1618
|
}
|
|
1988
1619
|
});
|
|
1989
|
-
return new ZodObject(
|
|
1620
|
+
return new ZodObject({
|
|
1621
|
+
...this._def,
|
|
1622
|
+
shape: () => newShape,
|
|
1623
|
+
});
|
|
1990
1624
|
}
|
|
1991
1625
|
else {
|
|
1992
|
-
for (
|
|
1993
|
-
|
|
1626
|
+
for (const key in this.shape) {
|
|
1627
|
+
const fieldSchema = this.shape[key];
|
|
1994
1628
|
newShape[key] = fieldSchema.optional();
|
|
1995
1629
|
}
|
|
1996
1630
|
}
|
|
1997
|
-
return new ZodObject(
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
1631
|
+
return new ZodObject({
|
|
1632
|
+
...this._def,
|
|
1633
|
+
shape: () => newShape,
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
required() {
|
|
1637
|
+
const newShape = {};
|
|
1638
|
+
for (const key in this.shape) {
|
|
1639
|
+
const fieldSchema = this.shape[key];
|
|
1640
|
+
let newField = fieldSchema;
|
|
2004
1641
|
while (newField instanceof ZodOptional) {
|
|
2005
1642
|
newField = newField._def.innerType;
|
|
2006
1643
|
}
|
|
2007
1644
|
newShape[key] = newField;
|
|
2008
1645
|
}
|
|
2009
|
-
return new ZodObject(
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
var result = results_2_1.value;
|
|
2052
|
-
if (result.result.status === "dirty") {
|
|
2053
|
-
// add issues from dirty option
|
|
2054
|
-
(_c = ctx.issues).push.apply(_c, __spreadArray([], __read(result.ctx.issues), false));
|
|
2055
|
-
return result.result;
|
|
2056
|
-
}
|
|
1646
|
+
return new ZodObject({
|
|
1647
|
+
...this._def,
|
|
1648
|
+
shape: () => newShape,
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
ZodObject.create = (shape, params) => {
|
|
1653
|
+
return new ZodObject({
|
|
1654
|
+
shape: () => shape,
|
|
1655
|
+
unknownKeys: "strip",
|
|
1656
|
+
catchall: ZodNever.create(),
|
|
1657
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1658
|
+
...processCreateParams(params),
|
|
1659
|
+
});
|
|
1660
|
+
};
|
|
1661
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
1662
|
+
return new ZodObject({
|
|
1663
|
+
shape: () => shape,
|
|
1664
|
+
unknownKeys: "strict",
|
|
1665
|
+
catchall: ZodNever.create(),
|
|
1666
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1667
|
+
...processCreateParams(params),
|
|
1668
|
+
});
|
|
1669
|
+
};
|
|
1670
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
1671
|
+
return new ZodObject({
|
|
1672
|
+
shape,
|
|
1673
|
+
unknownKeys: "strip",
|
|
1674
|
+
catchall: ZodNever.create(),
|
|
1675
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1676
|
+
...processCreateParams(params),
|
|
1677
|
+
});
|
|
1678
|
+
};
|
|
1679
|
+
class ZodUnion extends ZodType {
|
|
1680
|
+
_parse(input) {
|
|
1681
|
+
const { ctx } = this._processInputParams(input);
|
|
1682
|
+
const options = this._def.options;
|
|
1683
|
+
function handleResults(results) {
|
|
1684
|
+
// return first issue-free validation if it exists
|
|
1685
|
+
for (const result of results) {
|
|
1686
|
+
if (result.result.status === "valid") {
|
|
1687
|
+
return result.result;
|
|
2057
1688
|
}
|
|
2058
1689
|
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
1690
|
+
for (const result of results) {
|
|
1691
|
+
if (result.result.status === "dirty") {
|
|
1692
|
+
// add issues from dirty option
|
|
1693
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
1694
|
+
return result.result;
|
|
2063
1695
|
}
|
|
2064
|
-
finally { if (e_10) throw e_10.error; }
|
|
2065
1696
|
}
|
|
2066
1697
|
// return invalid
|
|
2067
|
-
|
|
1698
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2068
1699
|
addIssueToContext(ctx, {
|
|
2069
1700
|
code: ZodIssueCode.invalid_union,
|
|
2070
|
-
unionErrors
|
|
1701
|
+
unionErrors,
|
|
2071
1702
|
});
|
|
2072
1703
|
return INVALID;
|
|
2073
1704
|
}
|
|
2074
|
-
if (ctx.async) {
|
|
2075
|
-
return Promise.all(options.map(
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
data: ctx.data,
|
|
2085
|
-
path: ctx.path,
|
|
2086
|
-
parent: childCtx,
|
|
2087
|
-
})];
|
|
2088
|
-
case 1: return [2 /*return*/, (_a.result = _b.sent(),
|
|
2089
|
-
_a.ctx = childCtx,
|
|
2090
|
-
_a)];
|
|
2091
|
-
}
|
|
2092
|
-
});
|
|
2093
|
-
}); })).then(handleResults);
|
|
2094
|
-
}
|
|
2095
|
-
else {
|
|
2096
|
-
var optionResults = options.map(function (option) {
|
|
2097
|
-
var childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
1705
|
+
if (ctx.common.async) {
|
|
1706
|
+
return Promise.all(options.map(async (option) => {
|
|
1707
|
+
const childCtx = {
|
|
1708
|
+
...ctx,
|
|
1709
|
+
common: {
|
|
1710
|
+
...ctx.common,
|
|
1711
|
+
issues: [],
|
|
1712
|
+
},
|
|
1713
|
+
parent: null,
|
|
1714
|
+
};
|
|
2098
1715
|
return {
|
|
2099
|
-
result: option.
|
|
1716
|
+
result: await option._parseAsync({
|
|
2100
1717
|
data: ctx.data,
|
|
2101
1718
|
path: ctx.path,
|
|
2102
1719
|
parent: childCtx,
|
|
2103
1720
|
}),
|
|
2104
1721
|
ctx: childCtx,
|
|
2105
1722
|
};
|
|
1723
|
+
})).then(handleResults);
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
let dirty = undefined;
|
|
1727
|
+
const issues = [];
|
|
1728
|
+
for (const option of options) {
|
|
1729
|
+
const childCtx = {
|
|
1730
|
+
...ctx,
|
|
1731
|
+
common: {
|
|
1732
|
+
...ctx.common,
|
|
1733
|
+
issues: [],
|
|
1734
|
+
},
|
|
1735
|
+
parent: null,
|
|
1736
|
+
};
|
|
1737
|
+
const result = option._parseSync({
|
|
1738
|
+
data: ctx.data,
|
|
1739
|
+
path: ctx.path,
|
|
1740
|
+
parent: childCtx,
|
|
1741
|
+
});
|
|
1742
|
+
if (result.status === "valid") {
|
|
1743
|
+
return result;
|
|
1744
|
+
}
|
|
1745
|
+
else if (result.status === "dirty" && !dirty) {
|
|
1746
|
+
dirty = { result, ctx: childCtx };
|
|
1747
|
+
}
|
|
1748
|
+
if (childCtx.common.issues.length) {
|
|
1749
|
+
issues.push(childCtx.common.issues);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
if (dirty) {
|
|
1753
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
1754
|
+
return dirty.result;
|
|
1755
|
+
}
|
|
1756
|
+
const unionErrors = issues.map((issues) => new ZodError(issues));
|
|
1757
|
+
addIssueToContext(ctx, {
|
|
1758
|
+
code: ZodIssueCode.invalid_union,
|
|
1759
|
+
unionErrors,
|
|
2106
1760
|
});
|
|
2107
|
-
return
|
|
1761
|
+
return INVALID;
|
|
2108
1762
|
}
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
1763
|
+
}
|
|
1764
|
+
get options() {
|
|
1765
|
+
return this._def.options;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
ZodUnion.create = (types, params) => {
|
|
1769
|
+
return new ZodUnion({
|
|
1770
|
+
options: types,
|
|
1771
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
1772
|
+
...processCreateParams(params),
|
|
2116
1773
|
});
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
}(ZodType));
|
|
2122
|
-
var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
2123
|
-
__extends(ZodDiscriminatedUnion, _super);
|
|
2124
|
-
function ZodDiscriminatedUnion() {
|
|
2125
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2126
|
-
}
|
|
2127
|
-
ZodDiscriminatedUnion.prototype._parse = function (input) {
|
|
2128
|
-
var ctx = this._processInputParams(input).ctx;
|
|
1774
|
+
};
|
|
1775
|
+
class ZodDiscriminatedUnion extends ZodType {
|
|
1776
|
+
_parse(input) {
|
|
1777
|
+
const { ctx } = this._processInputParams(input);
|
|
2129
1778
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2130
1779
|
addIssueToContext(ctx, {
|
|
2131
1780
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2134,9 +1783,9 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
2134
1783
|
});
|
|
2135
1784
|
return INVALID;
|
|
2136
1785
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
1786
|
+
const discriminator = this.discriminator;
|
|
1787
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
1788
|
+
const option = this.options.get(discriminatorValue);
|
|
2140
1789
|
if (!option) {
|
|
2141
1790
|
addIssueToContext(ctx, {
|
|
2142
1791
|
code: ZodIssueCode.invalid_union_discriminator,
|
|
@@ -2145,7 +1794,7 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
2145
1794
|
});
|
|
2146
1795
|
return INVALID;
|
|
2147
1796
|
}
|
|
2148
|
-
if (ctx.async) {
|
|
1797
|
+
if (ctx.common.async) {
|
|
2149
1798
|
return option._parseAsync({
|
|
2150
1799
|
data: ctx.data,
|
|
2151
1800
|
path: ctx.path,
|
|
@@ -2159,28 +1808,16 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
2159
1808
|
parent: ctx,
|
|
2160
1809
|
});
|
|
2161
1810
|
}
|
|
2162
|
-
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
return Array.from(this.options.keys());
|
|
2173
|
-
},
|
|
2174
|
-
enumerable: false,
|
|
2175
|
-
configurable: true
|
|
2176
|
-
});
|
|
2177
|
-
Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
|
|
2178
|
-
get: function () {
|
|
2179
|
-
return this._def.options;
|
|
2180
|
-
},
|
|
2181
|
-
enumerable: false,
|
|
2182
|
-
configurable: true
|
|
2183
|
-
});
|
|
1811
|
+
}
|
|
1812
|
+
get discriminator() {
|
|
1813
|
+
return this._def.discriminator;
|
|
1814
|
+
}
|
|
1815
|
+
get validDiscriminatorValues() {
|
|
1816
|
+
return Array.from(this.options.keys());
|
|
1817
|
+
}
|
|
1818
|
+
get options() {
|
|
1819
|
+
return this._def.options;
|
|
1820
|
+
}
|
|
2184
1821
|
/**
|
|
2185
1822
|
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2186
1823
|
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
@@ -2189,12 +1826,12 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
2189
1826
|
* @param types an array of object schemas
|
|
2190
1827
|
* @param params
|
|
2191
1828
|
*/
|
|
2192
|
-
|
|
1829
|
+
static create(discriminator, types, params) {
|
|
2193
1830
|
// Get all the valid discriminator values
|
|
2194
|
-
|
|
1831
|
+
const options = new Map();
|
|
2195
1832
|
try {
|
|
2196
|
-
types.forEach(
|
|
2197
|
-
|
|
1833
|
+
types.forEach((type) => {
|
|
1834
|
+
const discriminatorValue = type.shape[discriminator].value;
|
|
2198
1835
|
options.set(discriminatorValue, type);
|
|
2199
1836
|
});
|
|
2200
1837
|
}
|
|
@@ -2205,39 +1842,32 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
2205
1842
|
if (options.size !== types.length) {
|
|
2206
1843
|
throw new Error("Some of the discriminator values are not unique");
|
|
2207
1844
|
}
|
|
2208
|
-
return new ZodDiscriminatedUnion(
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
1845
|
+
return new ZodDiscriminatedUnion({
|
|
1846
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
1847
|
+
discriminator,
|
|
1848
|
+
options,
|
|
1849
|
+
...processCreateParams(params),
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
2212
1853
|
function mergeValues(a, b) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
var bType = getParsedType(b);
|
|
1854
|
+
const aType = getParsedType(a);
|
|
1855
|
+
const bType = getParsedType(b);
|
|
2216
1856
|
if (a === b) {
|
|
2217
1857
|
return { valid: true, data: a };
|
|
2218
1858
|
}
|
|
2219
1859
|
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2220
|
-
|
|
2221
|
-
|
|
1860
|
+
const bKeys = util.objectKeys(b);
|
|
1861
|
+
const sharedKeys = util
|
|
2222
1862
|
.objectKeys(a)
|
|
2223
|
-
.filter(
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
if (!sharedValue.valid) {
|
|
2230
|
-
return { valid: false };
|
|
2231
|
-
}
|
|
2232
|
-
newObj[key] = sharedValue.data;
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
2236
|
-
finally {
|
|
2237
|
-
try {
|
|
2238
|
-
if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
|
|
1863
|
+
.filter((key) => bKeys.indexOf(key) !== -1);
|
|
1864
|
+
const newObj = { ...a, ...b };
|
|
1865
|
+
for (const key of sharedKeys) {
|
|
1866
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
1867
|
+
if (!sharedValue.valid) {
|
|
1868
|
+
return { valid: false };
|
|
2239
1869
|
}
|
|
2240
|
-
|
|
1870
|
+
newObj[key] = sharedValue.data;
|
|
2241
1871
|
}
|
|
2242
1872
|
return { valid: true, data: newObj };
|
|
2243
1873
|
}
|
|
@@ -2245,11 +1875,11 @@ function mergeValues(a, b) {
|
|
|
2245
1875
|
if (a.length !== b.length) {
|
|
2246
1876
|
return { valid: false };
|
|
2247
1877
|
}
|
|
2248
|
-
|
|
2249
|
-
for (
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
1878
|
+
const newArray = [];
|
|
1879
|
+
for (let index = 0; index < a.length; index++) {
|
|
1880
|
+
const itemA = a[index];
|
|
1881
|
+
const itemB = b[index];
|
|
1882
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2253
1883
|
if (!sharedValue.valid) {
|
|
2254
1884
|
return { valid: false };
|
|
2255
1885
|
}
|
|
@@ -2266,18 +1896,14 @@ function mergeValues(a, b) {
|
|
|
2266
1896
|
return { valid: false };
|
|
2267
1897
|
}
|
|
2268
1898
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
}
|
|
2274
|
-
ZodIntersection.prototype._parse = function (input) {
|
|
2275
|
-
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2276
|
-
var handleParsed = function (parsedLeft, parsedRight) {
|
|
1899
|
+
class ZodIntersection extends ZodType {
|
|
1900
|
+
_parse(input) {
|
|
1901
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1902
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2277
1903
|
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2278
1904
|
return INVALID;
|
|
2279
1905
|
}
|
|
2280
|
-
|
|
1906
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2281
1907
|
if (!merged.valid) {
|
|
2282
1908
|
addIssueToContext(ctx, {
|
|
2283
1909
|
code: ZodIssueCode.invalid_intersection_types,
|
|
@@ -2289,7 +1915,7 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
2289
1915
|
}
|
|
2290
1916
|
return { status: status.value, value: merged.data };
|
|
2291
1917
|
};
|
|
2292
|
-
if (ctx.async) {
|
|
1918
|
+
if (ctx.common.async) {
|
|
2293
1919
|
return Promise.all([
|
|
2294
1920
|
this._def.left._parseAsync({
|
|
2295
1921
|
data: ctx.data,
|
|
@@ -2301,10 +1927,7 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
2301
1927
|
path: ctx.path,
|
|
2302
1928
|
parent: ctx,
|
|
2303
1929
|
}),
|
|
2304
|
-
]).then(
|
|
2305
|
-
var _b = __read(_a, 2), left = _b[0], right = _b[1];
|
|
2306
|
-
return handleParsed(left, right);
|
|
2307
|
-
});
|
|
1930
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
2308
1931
|
}
|
|
2309
1932
|
else {
|
|
2310
1933
|
return handleParsed(this._def.left._parseSync({
|
|
@@ -2317,20 +1940,19 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
2317
1940
|
parent: ctx,
|
|
2318
1941
|
}));
|
|
2319
1942
|
}
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
ZodIntersection.create = (left, right, params) => {
|
|
1946
|
+
return new ZodIntersection({
|
|
1947
|
+
left: left,
|
|
1948
|
+
right: right,
|
|
1949
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
1950
|
+
...processCreateParams(params),
|
|
1951
|
+
});
|
|
1952
|
+
};
|
|
1953
|
+
class ZodTuple extends ZodType {
|
|
1954
|
+
_parse(input) {
|
|
1955
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2334
1956
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2335
1957
|
addIssueToContext(ctx, {
|
|
2336
1958
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2348,7 +1970,7 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
2348
1970
|
});
|
|
2349
1971
|
return INVALID;
|
|
2350
1972
|
}
|
|
2351
|
-
|
|
1973
|
+
const rest = this._def.rest;
|
|
2352
1974
|
if (!rest && ctx.data.length > this._def.items.length) {
|
|
2353
1975
|
addIssueToContext(ctx, {
|
|
2354
1976
|
code: ZodIssueCode.too_big,
|
|
@@ -2358,63 +1980,54 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
2358
1980
|
});
|
|
2359
1981
|
status.dirty();
|
|
2360
1982
|
}
|
|
2361
|
-
|
|
2362
|
-
.map(
|
|
2363
|
-
|
|
1983
|
+
const items = ctx.data
|
|
1984
|
+
.map((item, itemIndex) => {
|
|
1985
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2364
1986
|
if (!schema)
|
|
2365
1987
|
return null;
|
|
2366
1988
|
return schema._parse({
|
|
2367
1989
|
data: item,
|
|
2368
|
-
path:
|
|
1990
|
+
path: [...ctx.path, itemIndex],
|
|
2369
1991
|
parent: ctx,
|
|
2370
1992
|
});
|
|
2371
1993
|
})
|
|
2372
|
-
.filter(
|
|
2373
|
-
if (ctx.async) {
|
|
2374
|
-
return Promise.all(items).then(
|
|
1994
|
+
.filter((x) => !!x); // filter nulls
|
|
1995
|
+
if (ctx.common.async) {
|
|
1996
|
+
return Promise.all(items).then((results) => {
|
|
2375
1997
|
return ParseStatus.mergeArray(status, results);
|
|
2376
1998
|
});
|
|
2377
1999
|
}
|
|
2378
2000
|
else {
|
|
2379
2001
|
return ParseStatus.mergeArray(status, items);
|
|
2380
2002
|
}
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
__extends(ZodRecord, _super);
|
|
2399
|
-
function ZodRecord() {
|
|
2400
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2401
|
-
}
|
|
2402
|
-
Object.defineProperty(ZodRecord.prototype, "keySchema", {
|
|
2403
|
-
get: function () {
|
|
2404
|
-
return this._def.keyType;
|
|
2405
|
-
},
|
|
2406
|
-
enumerable: false,
|
|
2407
|
-
configurable: true
|
|
2408
|
-
});
|
|
2409
|
-
Object.defineProperty(ZodRecord.prototype, "valueSchema", {
|
|
2410
|
-
get: function () {
|
|
2411
|
-
return this._def.valueType;
|
|
2412
|
-
},
|
|
2413
|
-
enumerable: false,
|
|
2414
|
-
configurable: true
|
|
2003
|
+
}
|
|
2004
|
+
get items() {
|
|
2005
|
+
return this._def.items;
|
|
2006
|
+
}
|
|
2007
|
+
rest(rest) {
|
|
2008
|
+
return new ZodTuple({
|
|
2009
|
+
...this._def,
|
|
2010
|
+
rest,
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
ZodTuple.create = (schemas, params) => {
|
|
2015
|
+
return new ZodTuple({
|
|
2016
|
+
items: schemas,
|
|
2017
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
2018
|
+
rest: null,
|
|
2019
|
+
...processCreateParams(params),
|
|
2415
2020
|
});
|
|
2416
|
-
|
|
2417
|
-
|
|
2021
|
+
};
|
|
2022
|
+
class ZodRecord extends ZodType {
|
|
2023
|
+
get keySchema() {
|
|
2024
|
+
return this._def.keyType;
|
|
2025
|
+
}
|
|
2026
|
+
get valueSchema() {
|
|
2027
|
+
return this._def.valueType;
|
|
2028
|
+
}
|
|
2029
|
+
_parse(input) {
|
|
2030
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2418
2031
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2419
2032
|
addIssueToContext(ctx, {
|
|
2420
2033
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2423,54 +2036,53 @@ var ZodRecord = /** @class */ (function (_super) {
|
|
|
2423
2036
|
});
|
|
2424
2037
|
return INVALID;
|
|
2425
2038
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
for (
|
|
2039
|
+
const pairs = [];
|
|
2040
|
+
const keyType = this._def.keyType;
|
|
2041
|
+
const valueType = this._def.valueType;
|
|
2042
|
+
for (const key in ctx.data) {
|
|
2430
2043
|
pairs.push({
|
|
2431
2044
|
key: keyType._parse({
|
|
2432
2045
|
data: key,
|
|
2433
|
-
path:
|
|
2046
|
+
path: [...ctx.path, key],
|
|
2434
2047
|
parent: ctx,
|
|
2435
2048
|
}),
|
|
2436
2049
|
value: valueType._parse({
|
|
2437
2050
|
data: ctx.data[key],
|
|
2438
|
-
path:
|
|
2051
|
+
path: [...ctx.path, key],
|
|
2439
2052
|
parent: ctx,
|
|
2440
2053
|
}),
|
|
2441
2054
|
});
|
|
2442
2055
|
}
|
|
2443
|
-
if (ctx.async) {
|
|
2056
|
+
if (ctx.common.async) {
|
|
2444
2057
|
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
2445
2058
|
}
|
|
2446
2059
|
else {
|
|
2447
2060
|
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2448
2061
|
}
|
|
2449
|
-
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
enumerable: false,
|
|
2455
|
-
configurable: true
|
|
2456
|
-
});
|
|
2457
|
-
ZodRecord.create = function (first, second, third) {
|
|
2062
|
+
}
|
|
2063
|
+
get element() {
|
|
2064
|
+
return this._def.valueType;
|
|
2065
|
+
}
|
|
2066
|
+
static create(first, second, third) {
|
|
2458
2067
|
if (second instanceof ZodType) {
|
|
2459
|
-
return new ZodRecord(
|
|
2068
|
+
return new ZodRecord({
|
|
2069
|
+
keyType: first,
|
|
2070
|
+
valueType: second,
|
|
2071
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2072
|
+
...processCreateParams(third),
|
|
2073
|
+
});
|
|
2460
2074
|
}
|
|
2461
|
-
return new ZodRecord(
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
var _this = this;
|
|
2473
|
-
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
2075
|
+
return new ZodRecord({
|
|
2076
|
+
keyType: ZodString.create(),
|
|
2077
|
+
valueType: first,
|
|
2078
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
2079
|
+
...processCreateParams(second),
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
class ZodMap extends ZodType {
|
|
2084
|
+
_parse(input) {
|
|
2085
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2474
2086
|
if (ctx.parsedType !== ZodParsedType.map) {
|
|
2475
2087
|
addIssueToContext(ctx, {
|
|
2476
2088
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2479,77 +2091,28 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
2479
2091
|
});
|
|
2480
2092
|
return INVALID;
|
|
2481
2093
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
2094
|
+
const keyType = this._def.keyType;
|
|
2095
|
+
const valueType = this._def.valueType;
|
|
2096
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
2486
2097
|
return {
|
|
2487
2098
|
key: keyType._parse({
|
|
2488
2099
|
data: key,
|
|
2489
|
-
path:
|
|
2100
|
+
path: [...ctx.path, index, "key"],
|
|
2490
2101
|
parent: ctx,
|
|
2491
2102
|
}),
|
|
2492
2103
|
value: valueType._parse({
|
|
2493
2104
|
data: value,
|
|
2494
|
-
path:
|
|
2105
|
+
path: [...ctx.path, index, "value"],
|
|
2495
2106
|
parent: ctx,
|
|
2496
2107
|
}),
|
|
2497
2108
|
};
|
|
2498
2109
|
});
|
|
2499
|
-
if (ctx.async) {
|
|
2500
|
-
|
|
2501
|
-
return Promise.resolve().then(
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
switch (_b.label) {
|
|
2506
|
-
case 0:
|
|
2507
|
-
_b.trys.push([0, 6, 7, 8]);
|
|
2508
|
-
pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
|
|
2509
|
-
_b.label = 1;
|
|
2510
|
-
case 1:
|
|
2511
|
-
if (!!pairs_3_1.done) return [3 /*break*/, 5];
|
|
2512
|
-
pair = pairs_3_1.value;
|
|
2513
|
-
return [4 /*yield*/, pair.key];
|
|
2514
|
-
case 2:
|
|
2515
|
-
key = _b.sent();
|
|
2516
|
-
return [4 /*yield*/, pair.value];
|
|
2517
|
-
case 3:
|
|
2518
|
-
value = _b.sent();
|
|
2519
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
2520
|
-
return [2 /*return*/, INVALID];
|
|
2521
|
-
}
|
|
2522
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
2523
|
-
status.dirty();
|
|
2524
|
-
}
|
|
2525
|
-
finalMap_1.set(key.value, value.value);
|
|
2526
|
-
_b.label = 4;
|
|
2527
|
-
case 4:
|
|
2528
|
-
pairs_3_1 = pairs_3.next();
|
|
2529
|
-
return [3 /*break*/, 1];
|
|
2530
|
-
case 5: return [3 /*break*/, 8];
|
|
2531
|
-
case 6:
|
|
2532
|
-
e_13_1 = _b.sent();
|
|
2533
|
-
e_13 = { error: e_13_1 };
|
|
2534
|
-
return [3 /*break*/, 8];
|
|
2535
|
-
case 7:
|
|
2536
|
-
try {
|
|
2537
|
-
if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
|
|
2538
|
-
}
|
|
2539
|
-
finally { if (e_13) throw e_13.error; }
|
|
2540
|
-
return [7 /*endfinally*/];
|
|
2541
|
-
case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
|
|
2542
|
-
}
|
|
2543
|
-
});
|
|
2544
|
-
}); });
|
|
2545
|
-
}
|
|
2546
|
-
else {
|
|
2547
|
-
var finalMap = new Map();
|
|
2548
|
-
try {
|
|
2549
|
-
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
2550
|
-
var pair = pairs_2_1.value;
|
|
2551
|
-
var key = pair.key;
|
|
2552
|
-
var value = pair.value;
|
|
2110
|
+
if (ctx.common.async) {
|
|
2111
|
+
const finalMap = new Map();
|
|
2112
|
+
return Promise.resolve().then(async () => {
|
|
2113
|
+
for (const pair of pairs) {
|
|
2114
|
+
const key = await pair.key;
|
|
2115
|
+
const value = await pair.value;
|
|
2553
2116
|
if (key.status === "aborted" || value.status === "aborted") {
|
|
2554
2117
|
return INVALID;
|
|
2555
2118
|
}
|
|
@@ -2558,29 +2121,37 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
2558
2121
|
}
|
|
2559
2122
|
finalMap.set(key.value, value.value);
|
|
2560
2123
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2124
|
+
return { status: status.value, value: finalMap };
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
const finalMap = new Map();
|
|
2129
|
+
for (const pair of pairs) {
|
|
2130
|
+
const key = pair.key;
|
|
2131
|
+
const value = pair.value;
|
|
2132
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
2133
|
+
return INVALID;
|
|
2134
|
+
}
|
|
2135
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
2136
|
+
status.dirty();
|
|
2566
2137
|
}
|
|
2567
|
-
|
|
2138
|
+
finalMap.set(key.value, value.value);
|
|
2568
2139
|
}
|
|
2569
2140
|
return { status: status.value, value: finalMap };
|
|
2570
2141
|
}
|
|
2571
|
-
}
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
2145
|
+
return new ZodMap({
|
|
2146
|
+
valueType,
|
|
2147
|
+
keyType,
|
|
2148
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
2149
|
+
...processCreateParams(params),
|
|
2150
|
+
});
|
|
2151
|
+
};
|
|
2152
|
+
class ZodSet extends ZodType {
|
|
2153
|
+
_parse(input) {
|
|
2154
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2584
2155
|
if (ctx.parsedType !== ZodParsedType.set) {
|
|
2585
2156
|
addIssueToContext(ctx, {
|
|
2586
2157
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2589,7 +2160,7 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2589
2160
|
});
|
|
2590
2161
|
return INVALID;
|
|
2591
2162
|
}
|
|
2592
|
-
|
|
2163
|
+
const def = this._def;
|
|
2593
2164
|
if (def.minSize !== null) {
|
|
2594
2165
|
if (ctx.data.size < def.minSize.value) {
|
|
2595
2166
|
addIssueToContext(ctx, {
|
|
@@ -2614,66 +2185,61 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2614
2185
|
status.dirty();
|
|
2615
2186
|
}
|
|
2616
2187
|
}
|
|
2617
|
-
|
|
2188
|
+
const valueType = this._def.valueType;
|
|
2618
2189
|
function finalizeSet(elements) {
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
if (element.status === "dirty")
|
|
2627
|
-
status.dirty();
|
|
2628
|
-
parsedSet.add(element.value);
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2632
|
-
finally {
|
|
2633
|
-
try {
|
|
2634
|
-
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
2635
|
-
}
|
|
2636
|
-
finally { if (e_14) throw e_14.error; }
|
|
2190
|
+
const parsedSet = new Set();
|
|
2191
|
+
for (const element of elements) {
|
|
2192
|
+
if (element.status === "aborted")
|
|
2193
|
+
return INVALID;
|
|
2194
|
+
if (element.status === "dirty")
|
|
2195
|
+
status.dirty();
|
|
2196
|
+
parsedSet.add(element.value);
|
|
2637
2197
|
}
|
|
2638
2198
|
return { status: status.value, value: parsedSet };
|
|
2639
2199
|
}
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
if (ctx.async) {
|
|
2644
|
-
return Promise.all(elements).then(function (elements) { return finalizeSet(elements); });
|
|
2200
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx }));
|
|
2201
|
+
if (ctx.common.async) {
|
|
2202
|
+
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
2645
2203
|
}
|
|
2646
2204
|
else {
|
|
2647
2205
|
return finalizeSet(elements);
|
|
2648
2206
|
}
|
|
2649
|
-
}
|
|
2650
|
-
|
|
2651
|
-
return new ZodSet(
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2207
|
+
}
|
|
2208
|
+
min(minSize, message) {
|
|
2209
|
+
return new ZodSet({
|
|
2210
|
+
...this._def,
|
|
2211
|
+
minSize: { value: minSize, message: errorUtil.toString(message) },
|
|
2212
|
+
});
|
|
2213
|
+
}
|
|
2214
|
+
max(maxSize, message) {
|
|
2215
|
+
return new ZodSet({
|
|
2216
|
+
...this._def,
|
|
2217
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) },
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
size(size, message) {
|
|
2657
2221
|
return this.min(size, message).max(size, message);
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2222
|
+
}
|
|
2223
|
+
nonempty(message) {
|
|
2660
2224
|
return this.min(1, message);
|
|
2661
|
-
}
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
ZodSet.create = (valueType, params) => {
|
|
2228
|
+
return new ZodSet({
|
|
2229
|
+
valueType,
|
|
2230
|
+
minSize: null,
|
|
2231
|
+
maxSize: null,
|
|
2232
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
2233
|
+
...processCreateParams(params),
|
|
2234
|
+
});
|
|
2235
|
+
};
|
|
2236
|
+
class ZodFunction extends ZodType {
|
|
2237
|
+
constructor() {
|
|
2238
|
+
super(...arguments);
|
|
2239
|
+
this.validate = this.implement;
|
|
2240
|
+
}
|
|
2241
|
+
_parse(input) {
|
|
2242
|
+
const { ctx } = this._processInputParams(input);
|
|
2677
2243
|
if (ctx.parsedType !== ZodParsedType.function) {
|
|
2678
2244
|
addIssueToContext(ctx, {
|
|
2679
2245
|
code: ZodIssueCode.invalid_type,
|
|
@@ -2687,11 +2253,11 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2687
2253
|
data: args,
|
|
2688
2254
|
path: ctx.path,
|
|
2689
2255
|
errorMaps: [
|
|
2690
|
-
ctx.contextualErrorMap,
|
|
2256
|
+
ctx.common.contextualErrorMap,
|
|
2691
2257
|
ctx.schemaErrorMap,
|
|
2692
2258
|
overrideErrorMap,
|
|
2693
2259
|
defaultErrorMap,
|
|
2694
|
-
].filter(
|
|
2260
|
+
].filter((x) => !!x),
|
|
2695
2261
|
issueData: {
|
|
2696
2262
|
code: ZodIssueCode.invalid_arguments,
|
|
2697
2263
|
argumentsError: error,
|
|
@@ -2703,136 +2269,111 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2703
2269
|
data: returns,
|
|
2704
2270
|
path: ctx.path,
|
|
2705
2271
|
errorMaps: [
|
|
2706
|
-
ctx.contextualErrorMap,
|
|
2272
|
+
ctx.common.contextualErrorMap,
|
|
2707
2273
|
ctx.schemaErrorMap,
|
|
2708
2274
|
overrideErrorMap,
|
|
2709
2275
|
defaultErrorMap,
|
|
2710
|
-
].filter(
|
|
2276
|
+
].filter((x) => !!x),
|
|
2711
2277
|
issueData: {
|
|
2712
2278
|
code: ZodIssueCode.invalid_return_type,
|
|
2713
2279
|
returnTypeError: error,
|
|
2714
2280
|
},
|
|
2715
2281
|
});
|
|
2716
2282
|
}
|
|
2717
|
-
|
|
2718
|
-
|
|
2283
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
2284
|
+
const fn = ctx.data;
|
|
2719
2285
|
if (this._def.returns instanceof ZodPromise) {
|
|
2720
|
-
return OK(
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
args
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
return __generator(this, function (_a) {
|
|
2728
|
-
switch (_a.label) {
|
|
2729
|
-
case 0:
|
|
2730
|
-
error = new ZodError([]);
|
|
2731
|
-
return [4 /*yield*/, this._def.args
|
|
2732
|
-
.parseAsync(args, params)
|
|
2733
|
-
.catch(function (e) {
|
|
2734
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
2735
|
-
throw error;
|
|
2736
|
-
})];
|
|
2737
|
-
case 1:
|
|
2738
|
-
parsedArgs = _a.sent();
|
|
2739
|
-
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2740
|
-
case 2:
|
|
2741
|
-
result = _a.sent();
|
|
2742
|
-
return [4 /*yield*/, this._def.returns._def.type
|
|
2743
|
-
.parseAsync(result, params)
|
|
2744
|
-
.catch(function (e) {
|
|
2745
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
2746
|
-
throw error;
|
|
2747
|
-
})];
|
|
2748
|
-
case 3:
|
|
2749
|
-
parsedReturns = _a.sent();
|
|
2750
|
-
return [2 /*return*/, parsedReturns];
|
|
2751
|
-
}
|
|
2752
|
-
});
|
|
2286
|
+
return OK(async (...args) => {
|
|
2287
|
+
const error = new ZodError([]);
|
|
2288
|
+
const parsedArgs = await this._def.args
|
|
2289
|
+
.parseAsync(args, params)
|
|
2290
|
+
.catch((e) => {
|
|
2291
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
2292
|
+
throw error;
|
|
2753
2293
|
});
|
|
2294
|
+
const result = await fn(...parsedArgs);
|
|
2295
|
+
const parsedReturns = await this._def.returns._def.type
|
|
2296
|
+
.parseAsync(result, params)
|
|
2297
|
+
.catch((e) => {
|
|
2298
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
2299
|
+
throw error;
|
|
2300
|
+
});
|
|
2301
|
+
return parsedReturns;
|
|
2754
2302
|
});
|
|
2755
2303
|
}
|
|
2756
2304
|
else {
|
|
2757
|
-
return OK(
|
|
2758
|
-
|
|
2759
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2760
|
-
args[_i] = arguments[_i];
|
|
2761
|
-
}
|
|
2762
|
-
var parsedArgs = _this._def.args.safeParse(args, params);
|
|
2305
|
+
return OK((...args) => {
|
|
2306
|
+
const parsedArgs = this._def.args.safeParse(args, params);
|
|
2763
2307
|
if (!parsedArgs.success) {
|
|
2764
2308
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2765
2309
|
}
|
|
2766
|
-
|
|
2767
|
-
|
|
2310
|
+
const result = fn(...parsedArgs.data);
|
|
2311
|
+
const parsedReturns = this._def.returns.safeParse(result, params);
|
|
2768
2312
|
if (!parsedReturns.success) {
|
|
2769
2313
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2770
2314
|
}
|
|
2771
2315
|
return parsedReturns.data;
|
|
2772
2316
|
});
|
|
2773
2317
|
}
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2318
|
+
}
|
|
2319
|
+
parameters() {
|
|
2776
2320
|
return this._def.args;
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2321
|
+
}
|
|
2322
|
+
returnType() {
|
|
2779
2323
|
return this._def.returns;
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
items
|
|
2785
|
-
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2324
|
+
}
|
|
2325
|
+
args(...items) {
|
|
2326
|
+
return new ZodFunction({
|
|
2327
|
+
...this._def,
|
|
2328
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create()),
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
returns(returnType) {
|
|
2332
|
+
return new ZodFunction({
|
|
2333
|
+
...this._def,
|
|
2334
|
+
returns: returnType,
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
implement(func) {
|
|
2338
|
+
const validatedFunc = this.parse(func);
|
|
2793
2339
|
return validatedFunc;
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2796
|
-
|
|
2340
|
+
}
|
|
2341
|
+
strictImplement(func) {
|
|
2342
|
+
const validatedFunc = this.parse(func);
|
|
2797
2343
|
return validatedFunc;
|
|
2798
|
-
}
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
function ZodLazy() {
|
|
2809
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2810
|
-
}
|
|
2811
|
-
Object.defineProperty(ZodLazy.prototype, "schema", {
|
|
2812
|
-
get: function () {
|
|
2813
|
-
return this._def.getter();
|
|
2814
|
-
},
|
|
2815
|
-
enumerable: false,
|
|
2816
|
-
configurable: true
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
ZodFunction.create = (args, returns, params) => {
|
|
2347
|
+
return new ZodFunction({
|
|
2348
|
+
args: (args
|
|
2349
|
+
? args.rest(ZodUnknown.create())
|
|
2350
|
+
: ZodTuple.create([]).rest(ZodUnknown.create())),
|
|
2351
|
+
returns: returns || ZodUnknown.create(),
|
|
2352
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
2353
|
+
...processCreateParams(params),
|
|
2817
2354
|
});
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2355
|
+
};
|
|
2356
|
+
class ZodLazy extends ZodType {
|
|
2357
|
+
get schema() {
|
|
2358
|
+
return this._def.getter();
|
|
2359
|
+
}
|
|
2360
|
+
_parse(input) {
|
|
2361
|
+
const { ctx } = this._processInputParams(input);
|
|
2362
|
+
const lazySchema = this._def.getter();
|
|
2821
2363
|
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
if (ctx.data !== this._def.value) {
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
ZodLazy.create = (getter, params) => {
|
|
2367
|
+
return new ZodLazy({
|
|
2368
|
+
getter: getter,
|
|
2369
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
2370
|
+
...processCreateParams(params),
|
|
2371
|
+
});
|
|
2372
|
+
};
|
|
2373
|
+
class ZodLiteral extends ZodType {
|
|
2374
|
+
_parse(input) {
|
|
2375
|
+
if (input.data !== this._def.value) {
|
|
2376
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2836
2377
|
addIssueToContext(ctx, {
|
|
2837
2378
|
code: ZodIssueCode.invalid_type,
|
|
2838
2379
|
expected: getParsedType(this._def.value),
|
|
@@ -2840,156 +2381,92 @@ var ZodLiteral = /** @class */ (function (_super) {
|
|
|
2840
2381
|
});
|
|
2841
2382
|
return INVALID;
|
|
2842
2383
|
}
|
|
2843
|
-
return { status:
|
|
2844
|
-
}
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2384
|
+
return { status: "valid", value: input.data };
|
|
2385
|
+
}
|
|
2386
|
+
get value() {
|
|
2387
|
+
return this._def.value;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
ZodLiteral.create = (value, params) => {
|
|
2391
|
+
return new ZodLiteral({
|
|
2392
|
+
value: value,
|
|
2393
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
2394
|
+
...processCreateParams(params),
|
|
2851
2395
|
});
|
|
2852
|
-
|
|
2853
|
-
return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
|
|
2854
|
-
};
|
|
2855
|
-
return ZodLiteral;
|
|
2856
|
-
}(ZodType));
|
|
2396
|
+
};
|
|
2857
2397
|
function createZodEnum(values) {
|
|
2858
2398
|
return new ZodEnum({
|
|
2859
2399
|
values: values,
|
|
2860
2400
|
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
2861
2401
|
});
|
|
2862
2402
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
}
|
|
2868
|
-
ZodEnum.prototype._parse = function (input) {
|
|
2869
|
-
var ctx = this._processInputParams(input).ctx;
|
|
2870
|
-
if (this._def.values.indexOf(ctx.data) === -1) {
|
|
2403
|
+
class ZodEnum extends ZodType {
|
|
2404
|
+
_parse(input) {
|
|
2405
|
+
if (this._def.values.indexOf(input.data) === -1) {
|
|
2406
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2871
2407
|
addIssueToContext(ctx, {
|
|
2872
2408
|
code: ZodIssueCode.invalid_enum_value,
|
|
2873
2409
|
options: this._def.values,
|
|
2874
2410
|
});
|
|
2875
2411
|
return INVALID;
|
|
2876
2412
|
}
|
|
2877
|
-
return OK(
|
|
2878
|
-
}
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
var e_16, _a;
|
|
2911
|
-
var enumValues = {};
|
|
2912
|
-
try {
|
|
2913
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2914
|
-
var val = _c.value;
|
|
2915
|
-
enumValues[val] = val;
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
2919
|
-
finally {
|
|
2920
|
-
try {
|
|
2921
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2922
|
-
}
|
|
2923
|
-
finally { if (e_16) throw e_16.error; }
|
|
2924
|
-
}
|
|
2925
|
-
return enumValues;
|
|
2926
|
-
},
|
|
2927
|
-
enumerable: false,
|
|
2928
|
-
configurable: true
|
|
2929
|
-
});
|
|
2930
|
-
Object.defineProperty(ZodEnum.prototype, "Enum", {
|
|
2931
|
-
get: function () {
|
|
2932
|
-
var e_17, _a;
|
|
2933
|
-
var enumValues = {};
|
|
2934
|
-
try {
|
|
2935
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2936
|
-
var val = _c.value;
|
|
2937
|
-
enumValues[val] = val;
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
2941
|
-
finally {
|
|
2942
|
-
try {
|
|
2943
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2944
|
-
}
|
|
2945
|
-
finally { if (e_17) throw e_17.error; }
|
|
2946
|
-
}
|
|
2947
|
-
return enumValues;
|
|
2948
|
-
},
|
|
2949
|
-
enumerable: false,
|
|
2950
|
-
configurable: true
|
|
2951
|
-
});
|
|
2952
|
-
ZodEnum.create = createZodEnum;
|
|
2953
|
-
return ZodEnum;
|
|
2954
|
-
}(ZodType));
|
|
2955
|
-
var ZodNativeEnum = /** @class */ (function (_super) {
|
|
2956
|
-
__extends(ZodNativeEnum, _super);
|
|
2957
|
-
function ZodNativeEnum() {
|
|
2958
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2959
|
-
}
|
|
2960
|
-
ZodNativeEnum.prototype._parse = function (input) {
|
|
2961
|
-
var ctx = this._processInputParams(input).ctx;
|
|
2962
|
-
var nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
2963
|
-
if (nativeEnumValues.indexOf(ctx.data) === -1) {
|
|
2413
|
+
return OK(input.data);
|
|
2414
|
+
}
|
|
2415
|
+
get options() {
|
|
2416
|
+
return this._def.values;
|
|
2417
|
+
}
|
|
2418
|
+
get enum() {
|
|
2419
|
+
const enumValues = {};
|
|
2420
|
+
for (const val of this._def.values) {
|
|
2421
|
+
enumValues[val] = val;
|
|
2422
|
+
}
|
|
2423
|
+
return enumValues;
|
|
2424
|
+
}
|
|
2425
|
+
get Values() {
|
|
2426
|
+
const enumValues = {};
|
|
2427
|
+
for (const val of this._def.values) {
|
|
2428
|
+
enumValues[val] = val;
|
|
2429
|
+
}
|
|
2430
|
+
return enumValues;
|
|
2431
|
+
}
|
|
2432
|
+
get Enum() {
|
|
2433
|
+
const enumValues = {};
|
|
2434
|
+
for (const val of this._def.values) {
|
|
2435
|
+
enumValues[val] = val;
|
|
2436
|
+
}
|
|
2437
|
+
return enumValues;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
ZodEnum.create = createZodEnum;
|
|
2441
|
+
class ZodNativeEnum extends ZodType {
|
|
2442
|
+
_parse(input) {
|
|
2443
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
2444
|
+
if (nativeEnumValues.indexOf(input.data) === -1) {
|
|
2445
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2964
2446
|
addIssueToContext(ctx, {
|
|
2965
2447
|
code: ZodIssueCode.invalid_enum_value,
|
|
2966
2448
|
options: util.objectValues(nativeEnumValues),
|
|
2967
2449
|
});
|
|
2968
2450
|
return INVALID;
|
|
2969
2451
|
}
|
|
2970
|
-
return OK(
|
|
2971
|
-
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2452
|
+
return OK(input.data);
|
|
2453
|
+
}
|
|
2454
|
+
get enum() {
|
|
2455
|
+
return this._def.values;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
ZodNativeEnum.create = (values, params) => {
|
|
2459
|
+
return new ZodNativeEnum({
|
|
2460
|
+
values: values,
|
|
2461
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
2462
|
+
...processCreateParams(params),
|
|
2978
2463
|
});
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
__extends(ZodPromise, _super);
|
|
2986
|
-
function ZodPromise() {
|
|
2987
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2988
|
-
}
|
|
2989
|
-
ZodPromise.prototype._parse = function (input) {
|
|
2990
|
-
var _this = this;
|
|
2991
|
-
var ctx = this._processInputParams(input).ctx;
|
|
2992
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.async === false) {
|
|
2464
|
+
};
|
|
2465
|
+
class ZodPromise extends ZodType {
|
|
2466
|
+
_parse(input) {
|
|
2467
|
+
const { ctx } = this._processInputParams(input);
|
|
2468
|
+
if (ctx.parsedType !== ZodParsedType.promise &&
|
|
2469
|
+
ctx.common.async === false) {
|
|
2993
2470
|
addIssueToContext(ctx, {
|
|
2994
2471
|
code: ZodIssueCode.invalid_type,
|
|
2995
2472
|
expected: ZodParsedType.promise,
|
|
@@ -2997,38 +2474,36 @@ var ZodPromise = /** @class */ (function (_super) {
|
|
|
2997
2474
|
});
|
|
2998
2475
|
return INVALID;
|
|
2999
2476
|
}
|
|
3000
|
-
|
|
2477
|
+
const promisified = ctx.parsedType === ZodParsedType.promise
|
|
3001
2478
|
? ctx.data
|
|
3002
2479
|
: Promise.resolve(ctx.data);
|
|
3003
|
-
return OK(promisified.then(
|
|
3004
|
-
return
|
|
2480
|
+
return OK(promisified.then((data) => {
|
|
2481
|
+
return this._def.type.parseAsync(data, {
|
|
3005
2482
|
path: ctx.path,
|
|
3006
|
-
errorMap: ctx.contextualErrorMap,
|
|
2483
|
+
errorMap: ctx.common.contextualErrorMap,
|
|
3007
2484
|
});
|
|
3008
2485
|
}));
|
|
3009
|
-
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
ZodEffects.prototype.innerType = function () {
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
ZodPromise.create = (schema, params) => {
|
|
2489
|
+
return new ZodPromise({
|
|
2490
|
+
type: schema,
|
|
2491
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
2492
|
+
...processCreateParams(params),
|
|
2493
|
+
});
|
|
2494
|
+
};
|
|
2495
|
+
class ZodEffects extends ZodType {
|
|
2496
|
+
innerType() {
|
|
3021
2497
|
return this._def.schema;
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
var effect = this._def.effect || null;
|
|
2498
|
+
}
|
|
2499
|
+
_parse(input) {
|
|
2500
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2501
|
+
const effect = this._def.effect || null;
|
|
3027
2502
|
if (effect.type === "preprocess") {
|
|
3028
|
-
|
|
3029
|
-
if (ctx.async) {
|
|
3030
|
-
return Promise.resolve(processed).then(
|
|
3031
|
-
return
|
|
2503
|
+
const processed = effect.transform(ctx.data);
|
|
2504
|
+
if (ctx.common.async) {
|
|
2505
|
+
return Promise.resolve(processed).then((processed) => {
|
|
2506
|
+
return this._def.schema._parseAsync({
|
|
3032
2507
|
data: processed,
|
|
3033
2508
|
path: ctx.path,
|
|
3034
2509
|
parent: ctx,
|
|
@@ -3044,8 +2519,8 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3044
2519
|
}
|
|
3045
2520
|
}
|
|
3046
2521
|
if (effect.type === "refinement") {
|
|
3047
|
-
|
|
3048
|
-
addIssue:
|
|
2522
|
+
const checkCtx = {
|
|
2523
|
+
addIssue: (arg) => {
|
|
3049
2524
|
addIssueToContext(ctx, arg);
|
|
3050
2525
|
if (arg.fatal) {
|
|
3051
2526
|
status.abort();
|
|
@@ -3058,12 +2533,12 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3058
2533
|
return ctx.path;
|
|
3059
2534
|
},
|
|
3060
2535
|
};
|
|
3061
|
-
|
|
3062
|
-
|
|
2536
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2537
|
+
const executeRefinement = (acc
|
|
3063
2538
|
// effect: RefinementEffect<any>
|
|
3064
|
-
) {
|
|
3065
|
-
|
|
3066
|
-
if (ctx.async) {
|
|
2539
|
+
) => {
|
|
2540
|
+
const result = effect.refinement(acc, checkCtx);
|
|
2541
|
+
if (ctx.common.async) {
|
|
3067
2542
|
return Promise.resolve(result);
|
|
3068
2543
|
}
|
|
3069
2544
|
if (result instanceof Promise) {
|
|
@@ -3071,8 +2546,8 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3071
2546
|
}
|
|
3072
2547
|
return acc;
|
|
3073
2548
|
};
|
|
3074
|
-
if (ctx.async === false) {
|
|
3075
|
-
|
|
2549
|
+
if (ctx.common.async === false) {
|
|
2550
|
+
const inner = this._def.schema._parseSync({
|
|
3076
2551
|
data: ctx.data,
|
|
3077
2552
|
path: ctx.path,
|
|
3078
2553
|
parent: ctx,
|
|
@@ -3082,26 +2557,26 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3082
2557
|
if (inner.status === "dirty")
|
|
3083
2558
|
status.dirty();
|
|
3084
2559
|
// return value is ignored
|
|
3085
|
-
|
|
2560
|
+
executeRefinement(inner.value);
|
|
3086
2561
|
return { status: status.value, value: inner.value };
|
|
3087
2562
|
}
|
|
3088
2563
|
else {
|
|
3089
2564
|
return this._def.schema
|
|
3090
2565
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3091
|
-
.then(
|
|
2566
|
+
.then((inner) => {
|
|
3092
2567
|
if (inner.status === "aborted")
|
|
3093
2568
|
return INVALID;
|
|
3094
2569
|
if (inner.status === "dirty")
|
|
3095
2570
|
status.dirty();
|
|
3096
|
-
return
|
|
2571
|
+
return executeRefinement(inner.value).then(() => {
|
|
3097
2572
|
return { status: status.value, value: inner.value };
|
|
3098
2573
|
});
|
|
3099
2574
|
});
|
|
3100
2575
|
}
|
|
3101
2576
|
}
|
|
3102
2577
|
if (effect.type === "transform") {
|
|
3103
|
-
if (ctx.async === false) {
|
|
3104
|
-
|
|
2578
|
+
if (ctx.common.async === false) {
|
|
2579
|
+
const base = this._def.schema._parseSync({
|
|
3105
2580
|
data: ctx.data,
|
|
3106
2581
|
path: ctx.path,
|
|
3107
2582
|
parent: ctx,
|
|
@@ -3112,16 +2587,16 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3112
2587
|
// }
|
|
3113
2588
|
if (!isValid(base))
|
|
3114
2589
|
return base;
|
|
3115
|
-
|
|
2590
|
+
const result = effect.transform(base.value);
|
|
3116
2591
|
if (result instanceof Promise) {
|
|
3117
|
-
throw new Error(
|
|
2592
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3118
2593
|
}
|
|
3119
2594
|
return OK(result);
|
|
3120
2595
|
}
|
|
3121
2596
|
else {
|
|
3122
2597
|
return this._def.schema
|
|
3123
2598
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3124
|
-
.then(
|
|
2599
|
+
.then((base) => {
|
|
3125
2600
|
if (!isValid(base))
|
|
3126
2601
|
return base;
|
|
3127
2602
|
// if (base.status === "aborted") return INVALID;
|
|
@@ -3133,96 +2608,91 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
3133
2608
|
}
|
|
3134
2609
|
}
|
|
3135
2610
|
util.assertNever(effect);
|
|
3136
|
-
}
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
}
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
2614
|
+
return new ZodEffects({
|
|
2615
|
+
schema,
|
|
2616
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2617
|
+
effect,
|
|
2618
|
+
...processCreateParams(params),
|
|
2619
|
+
});
|
|
2620
|
+
};
|
|
2621
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
2622
|
+
return new ZodEffects({
|
|
2623
|
+
schema,
|
|
2624
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
2625
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2626
|
+
...processCreateParams(params),
|
|
2627
|
+
});
|
|
2628
|
+
};
|
|
2629
|
+
class ZodOptional extends ZodType {
|
|
2630
|
+
_parse(input) {
|
|
2631
|
+
const parsedType = this._getType(input);
|
|
2632
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
3153
2633
|
return OK(undefined);
|
|
3154
2634
|
}
|
|
3155
|
-
return this._def.innerType._parse(
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
parent: ctx,
|
|
3159
|
-
});
|
|
3160
|
-
};
|
|
3161
|
-
ZodOptional.prototype.unwrap = function () {
|
|
2635
|
+
return this._def.innerType._parse(input);
|
|
2636
|
+
}
|
|
2637
|
+
unwrap() {
|
|
3162
2638
|
return this._def.innerType;
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
if (ctx.parsedType === ZodParsedType.null) {
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
ZodOptional.create = (type, params) => {
|
|
2642
|
+
return new ZodOptional({
|
|
2643
|
+
innerType: type,
|
|
2644
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
2645
|
+
...processCreateParams(params),
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
class ZodNullable extends ZodType {
|
|
2649
|
+
_parse(input) {
|
|
2650
|
+
const parsedType = this._getType(input);
|
|
2651
|
+
if (parsedType === ZodParsedType.null) {
|
|
3177
2652
|
return OK(null);
|
|
3178
2653
|
}
|
|
3179
|
-
return this._def.innerType._parse(
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
parent: ctx,
|
|
3183
|
-
});
|
|
3184
|
-
};
|
|
3185
|
-
ZodNullable.prototype.unwrap = function () {
|
|
2654
|
+
return this._def.innerType._parse(input);
|
|
2655
|
+
}
|
|
2656
|
+
unwrap() {
|
|
3186
2657
|
return this._def.innerType;
|
|
3187
|
-
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
var data = ctx.data;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
ZodNullable.create = (type, params) => {
|
|
2661
|
+
return new ZodNullable({
|
|
2662
|
+
innerType: type,
|
|
2663
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
2664
|
+
...processCreateParams(params),
|
|
2665
|
+
});
|
|
2666
|
+
};
|
|
2667
|
+
class ZodDefault extends ZodType {
|
|
2668
|
+
_parse(input) {
|
|
2669
|
+
const { ctx } = this._processInputParams(input);
|
|
2670
|
+
let data = ctx.data;
|
|
3201
2671
|
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3202
2672
|
data = this._def.defaultValue();
|
|
3203
2673
|
}
|
|
3204
2674
|
return this._def.innerType._parse({
|
|
3205
|
-
data
|
|
2675
|
+
data,
|
|
3206
2676
|
path: ctx.path,
|
|
3207
2677
|
parent: ctx,
|
|
3208
2678
|
});
|
|
3209
|
-
}
|
|
3210
|
-
|
|
2679
|
+
}
|
|
2680
|
+
removeDefault() {
|
|
3211
2681
|
return this._def.innerType;
|
|
3212
|
-
}
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
ZodDefault.create = (type, params) => {
|
|
2685
|
+
return new ZodOptional({
|
|
2686
|
+
innerType: type,
|
|
2687
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
2688
|
+
...processCreateParams(params),
|
|
2689
|
+
});
|
|
2690
|
+
};
|
|
2691
|
+
class ZodNaN extends ZodType {
|
|
2692
|
+
_parse(input) {
|
|
2693
|
+
const parsedType = this._getType(input);
|
|
2694
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
2695
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3226
2696
|
addIssueToContext(ctx, {
|
|
3227
2697
|
code: ZodIssueCode.invalid_type,
|
|
3228
2698
|
expected: ZodParsedType.nan,
|
|
@@ -3230,19 +2700,21 @@ var ZodNaN = /** @class */ (function (_super) {
|
|
|
3230
2700
|
});
|
|
3231
2701
|
return INVALID;
|
|
3232
2702
|
}
|
|
3233
|
-
return { status:
|
|
3234
|
-
}
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
2703
|
+
return { status: "valid", value: input.data };
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
ZodNaN.create = (params) => {
|
|
2707
|
+
return new ZodNaN({
|
|
2708
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
2709
|
+
...processCreateParams(params),
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
const custom = (check, params) => {
|
|
3241
2713
|
if (check)
|
|
3242
2714
|
return ZodAny.create().refine(check, params);
|
|
3243
2715
|
return ZodAny.create();
|
|
3244
2716
|
};
|
|
3245
|
-
|
|
2717
|
+
const late = {
|
|
3246
2718
|
object: ZodObject.lazycreate,
|
|
3247
2719
|
};
|
|
3248
2720
|
var ZodFirstPartyTypeKind;
|
|
@@ -3279,47 +2751,44 @@ var ZodFirstPartyTypeKind;
|
|
|
3279
2751
|
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3280
2752
|
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
3281
2753
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
var ostring = function () { return stringType().optional(); };
|
|
3321
|
-
var onumber = function () { return numberType().optional(); };
|
|
3322
|
-
var oboolean = function () { return booleanType().optional(); };
|
|
2754
|
+
const instanceOfType = (cls, params = {
|
|
2755
|
+
message: `Input not instance of ${cls.name}`,
|
|
2756
|
+
}) => custom((data) => data instanceof cls, params);
|
|
2757
|
+
const stringType = ZodString.create;
|
|
2758
|
+
const numberType = ZodNumber.create;
|
|
2759
|
+
const nanType = ZodNaN.create;
|
|
2760
|
+
const bigIntType = ZodBigInt.create;
|
|
2761
|
+
const booleanType = ZodBoolean.create;
|
|
2762
|
+
const dateType = ZodDate.create;
|
|
2763
|
+
const undefinedType = ZodUndefined.create;
|
|
2764
|
+
const nullType = ZodNull.create;
|
|
2765
|
+
const anyType = ZodAny.create;
|
|
2766
|
+
const unknownType = ZodUnknown.create;
|
|
2767
|
+
const neverType = ZodNever.create;
|
|
2768
|
+
const voidType = ZodVoid.create;
|
|
2769
|
+
const arrayType = ZodArray.create;
|
|
2770
|
+
const objectType = ZodObject.create;
|
|
2771
|
+
const strictObjectType = ZodObject.strictCreate;
|
|
2772
|
+
const unionType = ZodUnion.create;
|
|
2773
|
+
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
2774
|
+
const intersectionType = ZodIntersection.create;
|
|
2775
|
+
const tupleType = ZodTuple.create;
|
|
2776
|
+
const recordType = ZodRecord.create;
|
|
2777
|
+
const mapType = ZodMap.create;
|
|
2778
|
+
const setType = ZodSet.create;
|
|
2779
|
+
const functionType = ZodFunction.create;
|
|
2780
|
+
const lazyType = ZodLazy.create;
|
|
2781
|
+
const literalType = ZodLiteral.create;
|
|
2782
|
+
const enumType = ZodEnum.create;
|
|
2783
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
2784
|
+
const promiseType = ZodPromise.create;
|
|
2785
|
+
const effectsType = ZodEffects.create;
|
|
2786
|
+
const optionalType = ZodOptional.create;
|
|
2787
|
+
const nullableType = ZodNullable.create;
|
|
2788
|
+
const preprocessType = ZodEffects.createWithPreprocess;
|
|
2789
|
+
const ostring = () => stringType().optional();
|
|
2790
|
+
const onumber = () => numberType().optional();
|
|
2791
|
+
const oboolean = () => booleanType().optional();
|
|
3323
2792
|
|
|
3324
2793
|
var mod = /*#__PURE__*/Object.freeze({
|
|
3325
2794
|
__proto__: null,
|