zod 4.0.0-beta.1 → 4.0.0-beta.20250409T222615
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/LICENSE +1 -1
- package/dist/commonjs/checks.d.ts +1 -0
- package/dist/commonjs/checks.js +32 -0
- package/dist/commonjs/coerce.d.ts +17 -0
- package/dist/commonjs/coerce.js +57 -0
- package/dist/commonjs/compat.d.ts +47 -0
- package/dist/commonjs/compat.js +73 -0
- package/dist/commonjs/errors.d.ts +28 -0
- package/dist/commonjs/errors.js +60 -0
- package/dist/commonjs/external.d.ts +8 -0
- package/dist/commonjs/external.js +67 -0
- package/dist/commonjs/index.d.ts +4 -0
- package/dist/commonjs/index.js +43 -0
- package/dist/commonjs/iso.d.ts +22 -0
- package/dist/commonjs/iso.js +70 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/parse.d.ts +17 -0
- package/dist/commonjs/parse.js +44 -0
- package/dist/commonjs/schemas.d.ts +738 -0
- package/dist/commonjs/schemas.js +1171 -0
- package/dist/esm/checks.d.ts +1 -0
- package/dist/esm/checks.js +1 -0
- package/dist/esm/coerce.d.ts +17 -0
- package/dist/esm/coerce.js +17 -0
- package/dist/esm/compat.d.ts +47 -0
- package/dist/esm/compat.js +33 -0
- package/dist/esm/errors.d.ts +28 -0
- package/dist/esm/errors.js +23 -0
- package/dist/esm/external.d.ts +8 -0
- package/dist/esm/external.js +14 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/iso.d.ts +22 -0
- package/dist/esm/iso.js +30 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parse.d.ts +17 -0
- package/dist/esm/parse.js +8 -0
- package/dist/esm/schemas.d.ts +738 -0
- package/dist/esm/schemas.js +1057 -0
- package/package.json +66 -82
- package/src/checks.ts +30 -0
- package/src/coerce.ts +27 -0
- package/src/compat.ts +74 -0
- package/src/errors.ts +52 -0
- package/src/external.ts +29 -0
- package/src/index.ts +5 -0
- package/src/iso.ts +90 -0
- package/src/parse.ts +32 -0
- package/src/schemas.ts +2324 -0
- package/CHANGELOG.md +0 -160
- package/README.md +0 -1730
- package/lib/.DS_Store +0 -0
- package/lib/PseudoPromise.d.ts +0 -7
- package/lib/PseudoPromise.d.ts.map +0 -1
- package/lib/PseudoPromise.js +0 -17
- package/lib/PseudoPromise.js.map +0 -1
- package/lib/ZodError.d.ts +0 -137
- package/lib/ZodError.d.ts.map +0 -1
- package/lib/ZodError.js +0 -301
- package/lib/ZodError.js.map +0 -1
- package/lib/benchmarks/index.d.ts +0 -2
- package/lib/benchmarks/index.d.ts.map +0 -1
- package/lib/benchmarks/index.js +0 -54
- package/lib/benchmarks/index.js.map +0 -1
- package/lib/benchmarks/object.d.ts +0 -6
- package/lib/benchmarks/object.d.ts.map +0 -1
- package/lib/benchmarks/object.js +0 -71
- package/lib/benchmarks/object.js.map +0 -1
- package/lib/benchmarks/string.d.ts +0 -6
- package/lib/benchmarks/string.d.ts.map +0 -1
- package/lib/benchmarks/string.js +0 -45
- package/lib/benchmarks/string.js.map +0 -1
- package/lib/external.d.ts +0 -4
- package/lib/external.d.ts.map +0 -1
- package/lib/external.js +0 -16
- package/lib/external.js.map +0 -1
- package/lib/helpers/errorUtil.d.ts +0 -10
- package/lib/helpers/errorUtil.d.ts.map +0 -1
- package/lib/helpers/errorUtil.js +0 -13
- package/lib/helpers/errorUtil.js.map +0 -1
- package/lib/helpers/parseUtil.d.ts +0 -74
- package/lib/helpers/parseUtil.d.ts.map +0 -1
- package/lib/helpers/parseUtil.js +0 -179
- package/lib/helpers/parseUtil.js.map +0 -1
- package/lib/helpers/partialUtil.d.ts +0 -18
- package/lib/helpers/partialUtil.d.ts.map +0 -1
- package/lib/helpers/partialUtil.js +0 -3
- package/lib/helpers/partialUtil.js.map +0 -1
- package/lib/helpers/util.d.ts +0 -18
- package/lib/helpers/util.d.ts.map +0 -1
- package/lib/helpers/util.js +0 -87
- package/lib/helpers/util.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -29
- package/lib/index.js.map +0 -1
- package/lib/index.mjs +0 -2808
- package/lib/index.mjs.map +0 -1
- package/lib/types.d.ts +0 -541
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2282
- package/lib/types.js.map +0 -1
package/lib/index.mjs
DELETED
|
@@ -1,2808 +0,0 @@
|
|
|
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) {
|
|
111
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
112
|
-
to[j] = from[i];
|
|
113
|
-
return to;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
var PseudoPromise = /** @class */ (function () {
|
|
117
|
-
function PseudoPromise(promise) {
|
|
118
|
-
this.promise = promise;
|
|
119
|
-
}
|
|
120
|
-
PseudoPromise.prototype.then = function (f) {
|
|
121
|
-
return new PseudoPromise(this.promise.then(f));
|
|
122
|
-
};
|
|
123
|
-
PseudoPromise.all = function (pps) {
|
|
124
|
-
return new PseudoPromise(Promise.all(pps.map(function (v) { return (v instanceof PseudoPromise ? v.promise : v); })));
|
|
125
|
-
};
|
|
126
|
-
return PseudoPromise;
|
|
127
|
-
}());
|
|
128
|
-
|
|
129
|
-
var util;
|
|
130
|
-
(function (util) {
|
|
131
|
-
function assertNever(_x) {
|
|
132
|
-
throw new Error();
|
|
133
|
-
}
|
|
134
|
-
util.assertNever = assertNever;
|
|
135
|
-
util.arrayToEnum = function (items) {
|
|
136
|
-
var e_1, _a;
|
|
137
|
-
var obj = {};
|
|
138
|
-
try {
|
|
139
|
-
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
140
|
-
var item = items_1_1.value;
|
|
141
|
-
obj[item] = item;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
145
|
-
finally {
|
|
146
|
-
try {
|
|
147
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
148
|
-
}
|
|
149
|
-
finally { if (e_1) throw e_1.error; }
|
|
150
|
-
}
|
|
151
|
-
return obj;
|
|
152
|
-
};
|
|
153
|
-
util.getValidEnumValues = function (obj) {
|
|
154
|
-
var e_2, _a;
|
|
155
|
-
var validKeys = Object.keys(obj).filter(function (k) { return typeof obj[obj[k]] !== "number"; });
|
|
156
|
-
var filtered = {};
|
|
157
|
-
try {
|
|
158
|
-
for (var validKeys_1 = __values(validKeys), validKeys_1_1 = validKeys_1.next(); !validKeys_1_1.done; validKeys_1_1 = validKeys_1.next()) {
|
|
159
|
-
var k = validKeys_1_1.value;
|
|
160
|
-
filtered[k] = obj[k];
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
164
|
-
finally {
|
|
165
|
-
try {
|
|
166
|
-
if (validKeys_1_1 && !validKeys_1_1.done && (_a = validKeys_1.return)) _a.call(validKeys_1);
|
|
167
|
-
}
|
|
168
|
-
finally { if (e_2) throw e_2.error; }
|
|
169
|
-
}
|
|
170
|
-
return util.getValues(filtered);
|
|
171
|
-
};
|
|
172
|
-
util.getValues = function (obj) {
|
|
173
|
-
return Object.keys(obj).map(function (e) {
|
|
174
|
-
return obj[e];
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
util.objectValues = function (obj) {
|
|
178
|
-
return Object.keys(obj).map(function (e) {
|
|
179
|
-
return obj[e];
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
util.find = function (arr, checker) {
|
|
183
|
-
var e_3, _a;
|
|
184
|
-
try {
|
|
185
|
-
for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
|
|
186
|
-
var item = arr_1_1.value;
|
|
187
|
-
if (checker(item))
|
|
188
|
-
return item;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
192
|
-
finally {
|
|
193
|
-
try {
|
|
194
|
-
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
|
|
195
|
-
}
|
|
196
|
-
finally { if (e_3) throw e_3.error; }
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
};
|
|
200
|
-
})(util || (util = {}));
|
|
201
|
-
|
|
202
|
-
var ZodIssueCode = util.arrayToEnum([
|
|
203
|
-
"invalid_type",
|
|
204
|
-
"custom",
|
|
205
|
-
"invalid_union",
|
|
206
|
-
"invalid_enum_value",
|
|
207
|
-
"unrecognized_keys",
|
|
208
|
-
"invalid_arguments",
|
|
209
|
-
"invalid_return_type",
|
|
210
|
-
"invalid_date",
|
|
211
|
-
"invalid_string",
|
|
212
|
-
"too_small",
|
|
213
|
-
"too_big",
|
|
214
|
-
"invalid_intersection_types",
|
|
215
|
-
]);
|
|
216
|
-
var quotelessJson = function (obj) {
|
|
217
|
-
var json = JSON.stringify(obj, null, 2);
|
|
218
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
219
|
-
};
|
|
220
|
-
var ZodError = /** @class */ (function () {
|
|
221
|
-
function ZodError(issues) {
|
|
222
|
-
var _this = this;
|
|
223
|
-
this.issues = [];
|
|
224
|
-
this.format = function () {
|
|
225
|
-
var fieldErrors = { _errors: [] };
|
|
226
|
-
var processError = function (error) {
|
|
227
|
-
var e_1, _a;
|
|
228
|
-
try {
|
|
229
|
-
for (var _b = __values(error.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
230
|
-
var issue = _c.value;
|
|
231
|
-
if (issue.code === "invalid_union") {
|
|
232
|
-
issue.unionErrors.map(processError);
|
|
233
|
-
}
|
|
234
|
-
else if (issue.code === "invalid_return_type") {
|
|
235
|
-
processError(issue.returnTypeError);
|
|
236
|
-
}
|
|
237
|
-
else if (issue.code === "invalid_arguments") {
|
|
238
|
-
processError(issue.argumentsError);
|
|
239
|
-
}
|
|
240
|
-
else if (issue.path.length === 0) {
|
|
241
|
-
fieldErrors._errors.push(issue.message);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
var curr = fieldErrors;
|
|
245
|
-
var i = 0;
|
|
246
|
-
while (i < issue.path.length) {
|
|
247
|
-
var el = issue.path[i];
|
|
248
|
-
var terminal = i === issue.path.length - 1;
|
|
249
|
-
if (!terminal) {
|
|
250
|
-
if (typeof el === "string") {
|
|
251
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
252
|
-
}
|
|
253
|
-
else if (typeof el === "number") {
|
|
254
|
-
var errorArray = [];
|
|
255
|
-
errorArray._errors = [];
|
|
256
|
-
curr[el] = curr[el] || errorArray;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
261
|
-
curr[el]._errors.push(issue.message);
|
|
262
|
-
}
|
|
263
|
-
curr = curr[el];
|
|
264
|
-
i++;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
270
|
-
finally {
|
|
271
|
-
try {
|
|
272
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
273
|
-
}
|
|
274
|
-
finally { if (e_1) throw e_1.error; }
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
processError(_this);
|
|
278
|
-
return fieldErrors;
|
|
279
|
-
};
|
|
280
|
-
this.addIssue = function (sub) {
|
|
281
|
-
_this.issues = __spreadArray(__spreadArray([], __read(_this.issues)), [sub]);
|
|
282
|
-
};
|
|
283
|
-
this.addIssues = function (subs) {
|
|
284
|
-
if (subs === void 0) { subs = []; }
|
|
285
|
-
_this.issues = __spreadArray(__spreadArray([], __read(_this.issues)), __read(subs));
|
|
286
|
-
};
|
|
287
|
-
this.flatten = function () {
|
|
288
|
-
var e_2, _a;
|
|
289
|
-
var fieldErrors = {};
|
|
290
|
-
var formErrors = [];
|
|
291
|
-
try {
|
|
292
|
-
for (var _b = __values(_this.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
293
|
-
var sub = _c.value;
|
|
294
|
-
if (sub.path.length > 0) {
|
|
295
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
296
|
-
fieldErrors[sub.path[0]].push(sub.message);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
formErrors.push(sub.message);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
304
|
-
finally {
|
|
305
|
-
try {
|
|
306
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
307
|
-
}
|
|
308
|
-
finally { if (e_2) throw e_2.error; }
|
|
309
|
-
}
|
|
310
|
-
return { formErrors: formErrors, fieldErrors: fieldErrors };
|
|
311
|
-
};
|
|
312
|
-
this.issues = issues;
|
|
313
|
-
}
|
|
314
|
-
Object.defineProperty(ZodError.prototype, "errors", {
|
|
315
|
-
get: function () {
|
|
316
|
-
return this.issues;
|
|
317
|
-
},
|
|
318
|
-
enumerable: false,
|
|
319
|
-
configurable: true
|
|
320
|
-
});
|
|
321
|
-
ZodError.prototype.toString = function () {
|
|
322
|
-
return "ZodError: " + JSON.stringify(this.issues, null, 2);
|
|
323
|
-
};
|
|
324
|
-
Object.defineProperty(ZodError.prototype, "message", {
|
|
325
|
-
get: function () {
|
|
326
|
-
return JSON.stringify(this.issues, null, 2);
|
|
327
|
-
// const errorMessage: string[] = [
|
|
328
|
-
// `${this.issues.length} validation issue(s)`,
|
|
329
|
-
// '',
|
|
330
|
-
// ];
|
|
331
|
-
// for (const err of this.issues) {
|
|
332
|
-
// errorMessage.push(
|
|
333
|
-
// ` Issue #${this.issues.indexOf(err)}: ${err.code} at ${err.path.join(
|
|
334
|
-
// '.',
|
|
335
|
-
// )}`,
|
|
336
|
-
// );
|
|
337
|
-
// errorMessage.push(` ` + err.message);
|
|
338
|
-
// errorMessage.push('');
|
|
339
|
-
// }
|
|
340
|
-
// return errorMessage.join('\n');
|
|
341
|
-
// return quotelessJson(this);
|
|
342
|
-
// .map(({ path, message }) => {
|
|
343
|
-
// return path.length ? `${path.join('./index')}: ${message}` : `${message}`;
|
|
344
|
-
// })
|
|
345
|
-
// .join('\n');
|
|
346
|
-
},
|
|
347
|
-
enumerable: false,
|
|
348
|
-
configurable: true
|
|
349
|
-
});
|
|
350
|
-
Object.defineProperty(ZodError.prototype, "isEmpty", {
|
|
351
|
-
get: function () {
|
|
352
|
-
return this.issues.length === 0;
|
|
353
|
-
},
|
|
354
|
-
enumerable: false,
|
|
355
|
-
configurable: true
|
|
356
|
-
});
|
|
357
|
-
Object.defineProperty(ZodError.prototype, "formErrors", {
|
|
358
|
-
// denormalize = ():DenormalizedError{
|
|
359
|
-
// }
|
|
360
|
-
get: function () {
|
|
361
|
-
return this.flatten();
|
|
362
|
-
},
|
|
363
|
-
enumerable: false,
|
|
364
|
-
configurable: true
|
|
365
|
-
});
|
|
366
|
-
ZodError.create = function (issues) {
|
|
367
|
-
var error = new ZodError(issues);
|
|
368
|
-
return error;
|
|
369
|
-
};
|
|
370
|
-
return ZodError;
|
|
371
|
-
}());
|
|
372
|
-
var defaultErrorMap = function (error, _ctx) {
|
|
373
|
-
var message;
|
|
374
|
-
switch (error.code) {
|
|
375
|
-
case ZodIssueCode.invalid_type:
|
|
376
|
-
if (error.received === "undefined") {
|
|
377
|
-
message = "Required";
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
message = "Expected " + error.expected + ", received " + error.received;
|
|
381
|
-
}
|
|
382
|
-
break;
|
|
383
|
-
case ZodIssueCode.unrecognized_keys:
|
|
384
|
-
message = "Unrecognized key(s) in object: " + error.keys
|
|
385
|
-
.map(function (k) { return "'" + k + "'"; })
|
|
386
|
-
.join(", ");
|
|
387
|
-
break;
|
|
388
|
-
case ZodIssueCode.invalid_union:
|
|
389
|
-
message = "Invalid input";
|
|
390
|
-
break;
|
|
391
|
-
case ZodIssueCode.invalid_enum_value:
|
|
392
|
-
message = "Invalid enum value. Expected " + error.options
|
|
393
|
-
.map(function (val) { return (typeof val === "string" ? "'" + val + "'" : val); })
|
|
394
|
-
.join(" | ") + ", received " + (typeof _ctx.data === "string" ? "'" + _ctx.data + "'" : _ctx.data);
|
|
395
|
-
break;
|
|
396
|
-
case ZodIssueCode.invalid_arguments:
|
|
397
|
-
message = "Invalid function arguments";
|
|
398
|
-
break;
|
|
399
|
-
case ZodIssueCode.invalid_return_type:
|
|
400
|
-
message = "Invalid function return type";
|
|
401
|
-
break;
|
|
402
|
-
case ZodIssueCode.invalid_date:
|
|
403
|
-
message = "Invalid date";
|
|
404
|
-
break;
|
|
405
|
-
// case ZodIssueCode.too_small:
|
|
406
|
-
// const tooShortNoun = _ctx.data === 'string' ? 'characters' : 'items';
|
|
407
|
-
// message = `Too short, should be at least ${error.minimum} ${tooShortNoun}`;
|
|
408
|
-
// break;
|
|
409
|
-
// case ZodIssueCode.too_big:
|
|
410
|
-
// const tooLongNoun = _ctx.data === 'string' ? 'characters' : 'items';
|
|
411
|
-
// message = `Too short, should be at most ${error.maximum} ${tooLongNoun}`;
|
|
412
|
-
// break;
|
|
413
|
-
case ZodIssueCode.invalid_string:
|
|
414
|
-
if (error.validation !== "regex")
|
|
415
|
-
message = "Invalid " + error.validation;
|
|
416
|
-
else
|
|
417
|
-
message = "Invalid";
|
|
418
|
-
break;
|
|
419
|
-
// case ZodIssueCode.invalid_url:
|
|
420
|
-
// message = 'Invalid URL.';
|
|
421
|
-
// break;
|
|
422
|
-
// case ZodIssueCode.invalid_uuid:
|
|
423
|
-
// message = 'Invalid UUID.';
|
|
424
|
-
// break;
|
|
425
|
-
case ZodIssueCode.too_small:
|
|
426
|
-
if (error.type === "array")
|
|
427
|
-
message = "Should have " + (error.inclusive ? "at least" : "more than") + " " + error.minimum + " items";
|
|
428
|
-
else if (error.type === "string")
|
|
429
|
-
message = "Should be " + (error.inclusive ? "at least" : "over") + " " + error.minimum + " characters";
|
|
430
|
-
else if (error.type === "number")
|
|
431
|
-
message = "Value should be greater than " + (error.inclusive ? "or equal to " : "") + error.minimum;
|
|
432
|
-
else
|
|
433
|
-
message = "Invalid input";
|
|
434
|
-
break;
|
|
435
|
-
case ZodIssueCode.too_big:
|
|
436
|
-
if (error.type === "array")
|
|
437
|
-
message = "Should have " + (error.inclusive ? "at most" : "less than") + " " + error.maximum + " items";
|
|
438
|
-
else if (error.type === "string")
|
|
439
|
-
message = "Should be " + (error.inclusive ? "at most" : "under") + " " + error.maximum + " characters long";
|
|
440
|
-
else if (error.type === "number")
|
|
441
|
-
message = "Value should be less than " + (error.inclusive ? "or equal to " : "") + error.maximum;
|
|
442
|
-
else
|
|
443
|
-
message = "Invalid input";
|
|
444
|
-
break;
|
|
445
|
-
case ZodIssueCode.custom:
|
|
446
|
-
message = "Invalid input";
|
|
447
|
-
break;
|
|
448
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
449
|
-
message = "Intersections only support objects";
|
|
450
|
-
break;
|
|
451
|
-
default:
|
|
452
|
-
message = _ctx.defaultError;
|
|
453
|
-
util.assertNever(error);
|
|
454
|
-
}
|
|
455
|
-
return { message: message };
|
|
456
|
-
// return `Invalid input`;
|
|
457
|
-
};
|
|
458
|
-
var overrideErrorMap = defaultErrorMap;
|
|
459
|
-
var setErrorMap = function (map) {
|
|
460
|
-
overrideErrorMap = map;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
var ZodParsedType = util.arrayToEnum([
|
|
464
|
-
"string",
|
|
465
|
-
"nan",
|
|
466
|
-
"number",
|
|
467
|
-
"integer",
|
|
468
|
-
"float",
|
|
469
|
-
"boolean",
|
|
470
|
-
"date",
|
|
471
|
-
"bigint",
|
|
472
|
-
"symbol",
|
|
473
|
-
"function",
|
|
474
|
-
"undefined",
|
|
475
|
-
"null",
|
|
476
|
-
"array",
|
|
477
|
-
"object",
|
|
478
|
-
"unknown",
|
|
479
|
-
"promise",
|
|
480
|
-
"void",
|
|
481
|
-
"never",
|
|
482
|
-
"map",
|
|
483
|
-
"set",
|
|
484
|
-
]);
|
|
485
|
-
var getParsedType = function (data) {
|
|
486
|
-
var t = typeof data;
|
|
487
|
-
switch (t) {
|
|
488
|
-
case "undefined":
|
|
489
|
-
return ZodParsedType.undefined;
|
|
490
|
-
case "string":
|
|
491
|
-
return ZodParsedType.string;
|
|
492
|
-
case "number":
|
|
493
|
-
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
494
|
-
case "boolean":
|
|
495
|
-
return ZodParsedType.boolean;
|
|
496
|
-
case "function":
|
|
497
|
-
return ZodParsedType.function;
|
|
498
|
-
case "bigint":
|
|
499
|
-
return ZodParsedType.bigint;
|
|
500
|
-
case "object":
|
|
501
|
-
if (Array.isArray(data))
|
|
502
|
-
return ZodParsedType.array;
|
|
503
|
-
if (data === null)
|
|
504
|
-
return ZodParsedType.null;
|
|
505
|
-
if (data.then &&
|
|
506
|
-
typeof data.then === "function" &&
|
|
507
|
-
data.catch &&
|
|
508
|
-
typeof data.catch === "function") {
|
|
509
|
-
return ZodParsedType.promise;
|
|
510
|
-
}
|
|
511
|
-
if (data instanceof Map) {
|
|
512
|
-
return ZodParsedType.map;
|
|
513
|
-
}
|
|
514
|
-
if (data instanceof Set) {
|
|
515
|
-
return ZodParsedType.set;
|
|
516
|
-
}
|
|
517
|
-
if (data instanceof Date) {
|
|
518
|
-
return ZodParsedType.date;
|
|
519
|
-
}
|
|
520
|
-
return ZodParsedType.object;
|
|
521
|
-
default:
|
|
522
|
-
return ZodParsedType.unknown;
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
var makeIssue = function (data, path, errorMap, errorData) {
|
|
526
|
-
var fullPath = __spreadArray(__spreadArray([], __read(path)), __read((errorData.path || [])));
|
|
527
|
-
var errorArg = __assign(__assign({}, errorData), { path: fullPath });
|
|
528
|
-
var defaultError = defaultErrorMap(errorArg, {
|
|
529
|
-
data: data,
|
|
530
|
-
defaultError: "Invalid input",
|
|
531
|
-
});
|
|
532
|
-
return __assign(__assign({}, errorData), { path: fullPath, message: errorData.message ||
|
|
533
|
-
errorMap(errorArg, {
|
|
534
|
-
data: data,
|
|
535
|
-
defaultError: defaultError.message,
|
|
536
|
-
}).message });
|
|
537
|
-
};
|
|
538
|
-
var EMPTY_PATH = null;
|
|
539
|
-
var pathToArray = function (path) {
|
|
540
|
-
if (path === null)
|
|
541
|
-
return [];
|
|
542
|
-
var arr = new Array(path.count);
|
|
543
|
-
while (path !== null) {
|
|
544
|
-
arr[path.count - 1] = path.component;
|
|
545
|
-
path = path.parent;
|
|
546
|
-
}
|
|
547
|
-
return arr;
|
|
548
|
-
};
|
|
549
|
-
var pathFromArray = function (arr) {
|
|
550
|
-
var path = null;
|
|
551
|
-
for (var i = 0; i < arr.length; i++) {
|
|
552
|
-
path = { parent: path, component: arr[i], count: i + 1 };
|
|
553
|
-
}
|
|
554
|
-
return path;
|
|
555
|
-
};
|
|
556
|
-
var ParseContext = /** @class */ (function () {
|
|
557
|
-
function ParseContext(path, issues, params) {
|
|
558
|
-
this.path = path;
|
|
559
|
-
this.issues = issues;
|
|
560
|
-
this.params = params;
|
|
561
|
-
}
|
|
562
|
-
ParseContext.prototype.stepInto = function (component) {
|
|
563
|
-
return new ParseContext(this.path === null
|
|
564
|
-
? { parent: null, count: 1, component: component }
|
|
565
|
-
: { parent: this.path, count: this.path.count + 1, component: component }, this.issues, this.params);
|
|
566
|
-
};
|
|
567
|
-
ParseContext.prototype.addIssue = function (data, errorData) {
|
|
568
|
-
var issue = makeIssue(data, pathToArray(this.path), this.params.errorMap, errorData);
|
|
569
|
-
this.issues.push(issue);
|
|
570
|
-
};
|
|
571
|
-
return ParseContext;
|
|
572
|
-
}());
|
|
573
|
-
var createRootContext$1 = function (params) {
|
|
574
|
-
var _a;
|
|
575
|
-
return new ParseContext(EMPTY_PATH, [], {
|
|
576
|
-
async: (_a = params.async) !== null && _a !== void 0 ? _a : false,
|
|
577
|
-
errorMap: params.errorMap || overrideErrorMap,
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
var INVALID = Object.freeze({ valid: false });
|
|
581
|
-
var OK = function (value) { return ({ valid: true, value: value }); };
|
|
582
|
-
var ASYNC = function (promise) {
|
|
583
|
-
return new PseudoPromise(promise);
|
|
584
|
-
};
|
|
585
|
-
var isInvalid = function (x) {
|
|
586
|
-
return x === INVALID;
|
|
587
|
-
};
|
|
588
|
-
var isOk = function (x) {
|
|
589
|
-
return x.valid === true;
|
|
590
|
-
};
|
|
591
|
-
var isAsync = function (x) { return x instanceof PseudoPromise; };
|
|
592
|
-
|
|
593
|
-
var errorUtil;
|
|
594
|
-
(function (errorUtil) {
|
|
595
|
-
errorUtil.errToObj = function (message) {
|
|
596
|
-
return typeof message === "string" ? { message: message } : message || {};
|
|
597
|
-
};
|
|
598
|
-
errorUtil.toString = function (message) {
|
|
599
|
-
return typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
600
|
-
};
|
|
601
|
-
})(errorUtil || (errorUtil = {}));
|
|
602
|
-
|
|
603
|
-
var createTasks = function (ctx) {
|
|
604
|
-
return ctx.params.async ? [] : null;
|
|
605
|
-
};
|
|
606
|
-
var createRootContext = function (params) {
|
|
607
|
-
var _a;
|
|
608
|
-
return new ParseContext(pathFromArray(params.path || []), [], {
|
|
609
|
-
async: (_a = params.async) !== null && _a !== void 0 ? _a : false,
|
|
610
|
-
errorMap: params.errorMap || overrideErrorMap,
|
|
611
|
-
});
|
|
612
|
-
};
|
|
613
|
-
var handleResult = function (ctx, result, parentError) {
|
|
614
|
-
if (isOk(result)) {
|
|
615
|
-
return { success: true, data: result.value };
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
parentError === null || parentError === void 0 ? void 0 : parentError.addIssues(ctx.issues);
|
|
619
|
-
var error = new ZodError(ctx.issues);
|
|
620
|
-
return { success: false, error: error };
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
var ZodType = /** @class */ (function () {
|
|
624
|
-
function ZodType(def) {
|
|
625
|
-
var _this = this;
|
|
626
|
-
this.parse = function (data, params) {
|
|
627
|
-
var result = _this.safeParse(data, params);
|
|
628
|
-
if (result.success)
|
|
629
|
-
return result.data;
|
|
630
|
-
throw result.error;
|
|
631
|
-
};
|
|
632
|
-
this.safeParse = function (data, params) {
|
|
633
|
-
var ctx = createRootContext(__assign(__assign({}, params), { async: false }));
|
|
634
|
-
var result = _this._parseSync(ctx, data, getParsedType(data));
|
|
635
|
-
return handleResult(ctx, result, params === null || params === void 0 ? void 0 : params.parentError);
|
|
636
|
-
};
|
|
637
|
-
this.parseAsync = function (data, params) { return __awaiter(_this, void 0, void 0, function () {
|
|
638
|
-
var result;
|
|
639
|
-
return __generator(this, function (_a) {
|
|
640
|
-
switch (_a.label) {
|
|
641
|
-
case 0: return [4 /*yield*/, this.safeParseAsync(data, params)];
|
|
642
|
-
case 1:
|
|
643
|
-
result = _a.sent();
|
|
644
|
-
if (result.success)
|
|
645
|
-
return [2 /*return*/, result.data];
|
|
646
|
-
throw result.error;
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
}); };
|
|
650
|
-
this.safeParseAsync = function (data, params) { return __awaiter(_this, void 0, void 0, function () {
|
|
651
|
-
var ctx, maybeAsyncResult, result;
|
|
652
|
-
return __generator(this, function (_a) {
|
|
653
|
-
switch (_a.label) {
|
|
654
|
-
case 0:
|
|
655
|
-
ctx = createRootContext(__assign(__assign({}, params), { async: true }));
|
|
656
|
-
maybeAsyncResult = this._parse(ctx, data, getParsedType(data));
|
|
657
|
-
return [4 /*yield*/, (isAsync(maybeAsyncResult)
|
|
658
|
-
? maybeAsyncResult.promise
|
|
659
|
-
: Promise.resolve(maybeAsyncResult))];
|
|
660
|
-
case 1:
|
|
661
|
-
result = _a.sent();
|
|
662
|
-
return [2 /*return*/, handleResult(ctx, result, params === null || params === void 0 ? void 0 : params.parentError)];
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}); };
|
|
666
|
-
/** Alias of safeParseAsync */
|
|
667
|
-
this.spa = this.safeParseAsync;
|
|
668
|
-
this.refine = function (check, message) {
|
|
669
|
-
var getIssueProperties = function (val) {
|
|
670
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
671
|
-
return { message: message };
|
|
672
|
-
}
|
|
673
|
-
else if (typeof message === "function") {
|
|
674
|
-
return message(val);
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
return message;
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
return _this._refinement(function (val, ctx) {
|
|
681
|
-
var result = check(val);
|
|
682
|
-
var setError = function () {
|
|
683
|
-
return ctx.addIssue(__assign({ code: ZodIssueCode.custom }, getIssueProperties(val)));
|
|
684
|
-
};
|
|
685
|
-
if (result instanceof Promise) {
|
|
686
|
-
return result.then(function (data) {
|
|
687
|
-
if (!data) {
|
|
688
|
-
setError();
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
else {
|
|
692
|
-
return true;
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
if (!result) {
|
|
697
|
-
setError();
|
|
698
|
-
return false;
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
return true;
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
};
|
|
705
|
-
this.refinement = function (check, refinementData) {
|
|
706
|
-
return _this._refinement(function (val, ctx) {
|
|
707
|
-
if (!check(val)) {
|
|
708
|
-
ctx.addIssue(typeof refinementData === "function"
|
|
709
|
-
? refinementData(val, ctx)
|
|
710
|
-
: refinementData);
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
return true;
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
};
|
|
718
|
-
this.superRefine = this._refinement;
|
|
719
|
-
this.optional = function () {
|
|
720
|
-
return ZodOptional.create(_this);
|
|
721
|
-
};
|
|
722
|
-
this.nullable = function () {
|
|
723
|
-
return ZodNullable.create(_this);
|
|
724
|
-
};
|
|
725
|
-
this.nullish = function () { return _this.optional().nullable(); };
|
|
726
|
-
this.array = function () { return ZodArray.create(_this); };
|
|
727
|
-
this.isOptional = function () { return _this.safeParse(undefined).success; };
|
|
728
|
-
this.isNullable = function () { return _this.safeParse(null).success; };
|
|
729
|
-
this._def = def;
|
|
730
|
-
this.transform = this.transform.bind(this);
|
|
731
|
-
this.default = this.default.bind(this);
|
|
732
|
-
}
|
|
733
|
-
ZodType.prototype._parseSync = function (_ctx, _data, _parsedType) {
|
|
734
|
-
var result = this._parse(_ctx, _data, _parsedType);
|
|
735
|
-
if (isAsync(result)) {
|
|
736
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
737
|
-
}
|
|
738
|
-
return result;
|
|
739
|
-
};
|
|
740
|
-
ZodType.prototype._refinement = function (refinement) {
|
|
741
|
-
var returnType;
|
|
742
|
-
if (this instanceof ZodEffects) {
|
|
743
|
-
returnType = new ZodEffects(__assign(__assign({}, this._def), { effects: __spreadArray(__spreadArray([], __read((this._def.effects || []))), [
|
|
744
|
-
{ type: "refinement", refinement: refinement },
|
|
745
|
-
]) }));
|
|
746
|
-
}
|
|
747
|
-
else {
|
|
748
|
-
returnType = new ZodEffects({
|
|
749
|
-
schema: this,
|
|
750
|
-
effects: [{ type: "refinement", refinement: refinement }],
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
return returnType;
|
|
754
|
-
};
|
|
755
|
-
ZodType.prototype.or = function (option) {
|
|
756
|
-
return ZodUnion.create([this, option]);
|
|
757
|
-
};
|
|
758
|
-
ZodType.prototype.and = function (incoming) {
|
|
759
|
-
return ZodIntersection.create(this, incoming);
|
|
760
|
-
};
|
|
761
|
-
ZodType.prototype.transform = function (transform) {
|
|
762
|
-
return new ZodEffects({
|
|
763
|
-
schema: this,
|
|
764
|
-
effects: [{ type: "transform", transform: transform }],
|
|
765
|
-
});
|
|
766
|
-
};
|
|
767
|
-
ZodType.prototype.default = function (def) {
|
|
768
|
-
var defaultValueFunc = typeof def === "function" ? def : function () { return def; };
|
|
769
|
-
// if (this instanceof ZodOptional) {
|
|
770
|
-
// return new ZodOptional({
|
|
771
|
-
// ...this._def,
|
|
772
|
-
// defaultValue: defaultValueFunc,
|
|
773
|
-
// }) as any;
|
|
774
|
-
// }
|
|
775
|
-
return new ZodDefault({
|
|
776
|
-
innerType: this,
|
|
777
|
-
defaultValue: defaultValueFunc,
|
|
778
|
-
});
|
|
779
|
-
};
|
|
780
|
-
return ZodType;
|
|
781
|
-
}());
|
|
782
|
-
var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
783
|
-
// from https://stackoverflow.com/a/46181/1550155
|
|
784
|
-
// old version: too slow, didn't support unicode
|
|
785
|
-
// 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;
|
|
786
|
-
// eslint-disable-next-line
|
|
787
|
-
var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
788
|
-
var ZodString = /** @class */ (function (_super) {
|
|
789
|
-
__extends(ZodString, _super);
|
|
790
|
-
function ZodString() {
|
|
791
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
792
|
-
_this._regex = function (regex, validation, message) {
|
|
793
|
-
return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodIssueCode.invalid_string }, errorUtil.errToObj(message)));
|
|
794
|
-
};
|
|
795
|
-
_this.email = function (message) {
|
|
796
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
797
|
-
__assign({ kind: "email" }, errorUtil.errToObj(message)),
|
|
798
|
-
]) }));
|
|
799
|
-
};
|
|
800
|
-
_this.url = function (message) {
|
|
801
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
802
|
-
__assign({ kind: "url" }, errorUtil.errToObj(message)),
|
|
803
|
-
]) }));
|
|
804
|
-
};
|
|
805
|
-
_this.uuid = function (message) {
|
|
806
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
807
|
-
__assign({ kind: "uuid" }, errorUtil.errToObj(message)),
|
|
808
|
-
]) }));
|
|
809
|
-
};
|
|
810
|
-
_this.regex = function (regex, message) {
|
|
811
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
812
|
-
__assign({ kind: "regex", regex: regex }, errorUtil.errToObj(message)),
|
|
813
|
-
]) }));
|
|
814
|
-
};
|
|
815
|
-
_this.min = function (minLength, message) {
|
|
816
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
817
|
-
__assign({ kind: "min", value: minLength }, errorUtil.errToObj(message)),
|
|
818
|
-
]) }));
|
|
819
|
-
};
|
|
820
|
-
_this.max = function (maxLength, message) {
|
|
821
|
-
return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
822
|
-
__assign({ kind: "max", value: maxLength }, errorUtil.errToObj(message)),
|
|
823
|
-
]) }));
|
|
824
|
-
};
|
|
825
|
-
/**
|
|
826
|
-
* Deprecated.
|
|
827
|
-
* Use z.string().min(1) instead.
|
|
828
|
-
*/
|
|
829
|
-
_this.nonempty = function (message) {
|
|
830
|
-
return _this.min(1, errorUtil.errToObj(message));
|
|
831
|
-
};
|
|
832
|
-
return _this;
|
|
833
|
-
}
|
|
834
|
-
ZodString.prototype._parse = function (ctx, data, parsedType) {
|
|
835
|
-
var e_1, _a;
|
|
836
|
-
if (parsedType !== ZodParsedType.string) {
|
|
837
|
-
ctx.addIssue(data, {
|
|
838
|
-
code: ZodIssueCode.invalid_type,
|
|
839
|
-
expected: ZodParsedType.string,
|
|
840
|
-
received: parsedType,
|
|
841
|
-
});
|
|
842
|
-
return INVALID;
|
|
843
|
-
}
|
|
844
|
-
var invalid = false;
|
|
845
|
-
try {
|
|
846
|
-
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
847
|
-
var check = _c.value;
|
|
848
|
-
if (check.kind === "min") {
|
|
849
|
-
if (data.length < check.value) {
|
|
850
|
-
invalid = true;
|
|
851
|
-
ctx.addIssue(data, {
|
|
852
|
-
code: ZodIssueCode.too_small,
|
|
853
|
-
minimum: check.value,
|
|
854
|
-
type: "string",
|
|
855
|
-
inclusive: true,
|
|
856
|
-
message: check.message,
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
else if (check.kind === "max") {
|
|
861
|
-
if (data.length > check.value) {
|
|
862
|
-
invalid = true;
|
|
863
|
-
ctx.addIssue(data, {
|
|
864
|
-
code: ZodIssueCode.too_big,
|
|
865
|
-
maximum: check.value,
|
|
866
|
-
type: "string",
|
|
867
|
-
inclusive: true,
|
|
868
|
-
message: check.message,
|
|
869
|
-
// ...errorUtil.errToObj(this._def.maxLength.message),
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
else if (check.kind === "email") {
|
|
874
|
-
if (!emailRegex.test(data)) {
|
|
875
|
-
invalid = true;
|
|
876
|
-
ctx.addIssue(data, {
|
|
877
|
-
validation: "email",
|
|
878
|
-
code: ZodIssueCode.invalid_string,
|
|
879
|
-
message: check.message,
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
else if (check.kind === "uuid") {
|
|
884
|
-
if (!uuidRegex.test(data)) {
|
|
885
|
-
invalid = true;
|
|
886
|
-
ctx.addIssue(data, {
|
|
887
|
-
validation: "uuid",
|
|
888
|
-
code: ZodIssueCode.invalid_string,
|
|
889
|
-
message: check.message,
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
else if (check.kind === "url") {
|
|
894
|
-
try {
|
|
895
|
-
new URL(data);
|
|
896
|
-
}
|
|
897
|
-
catch (_d) {
|
|
898
|
-
invalid = true;
|
|
899
|
-
ctx.addIssue(data, {
|
|
900
|
-
validation: "url",
|
|
901
|
-
code: ZodIssueCode.invalid_string,
|
|
902
|
-
message: check.message,
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
else if (check.kind === "regex") {
|
|
907
|
-
if (!check.regex.test(data)) {
|
|
908
|
-
invalid = true;
|
|
909
|
-
ctx.addIssue(data, {
|
|
910
|
-
validation: "regex",
|
|
911
|
-
code: ZodIssueCode.invalid_string,
|
|
912
|
-
message: check.message,
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
919
|
-
finally {
|
|
920
|
-
try {
|
|
921
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
922
|
-
}
|
|
923
|
-
finally { if (e_1) throw e_1.error; }
|
|
924
|
-
}
|
|
925
|
-
return invalid ? INVALID : OK(data);
|
|
926
|
-
};
|
|
927
|
-
ZodString.prototype.length = function (len, message) {
|
|
928
|
-
return this.min(len, message).max(len, message);
|
|
929
|
-
};
|
|
930
|
-
Object.defineProperty(ZodString.prototype, "isEmail", {
|
|
931
|
-
get: function () {
|
|
932
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "email"; });
|
|
933
|
-
},
|
|
934
|
-
enumerable: false,
|
|
935
|
-
configurable: true
|
|
936
|
-
});
|
|
937
|
-
Object.defineProperty(ZodString.prototype, "isURL", {
|
|
938
|
-
get: function () {
|
|
939
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "url"; });
|
|
940
|
-
},
|
|
941
|
-
enumerable: false,
|
|
942
|
-
configurable: true
|
|
943
|
-
});
|
|
944
|
-
Object.defineProperty(ZodString.prototype, "isUUID", {
|
|
945
|
-
get: function () {
|
|
946
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "uuid"; });
|
|
947
|
-
},
|
|
948
|
-
enumerable: false,
|
|
949
|
-
configurable: true
|
|
950
|
-
});
|
|
951
|
-
Object.defineProperty(ZodString.prototype, "minLength", {
|
|
952
|
-
get: function () {
|
|
953
|
-
var min = -Infinity;
|
|
954
|
-
this._def.checks.map(function (ch) {
|
|
955
|
-
if (ch.kind === "min") {
|
|
956
|
-
if (min === null || ch.value > min) {
|
|
957
|
-
min = ch.value;
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
return min;
|
|
962
|
-
},
|
|
963
|
-
enumerable: false,
|
|
964
|
-
configurable: true
|
|
965
|
-
});
|
|
966
|
-
Object.defineProperty(ZodString.prototype, "maxLength", {
|
|
967
|
-
get: function () {
|
|
968
|
-
var max = null;
|
|
969
|
-
this._def.checks.map(function (ch) {
|
|
970
|
-
if (ch.kind === "min") {
|
|
971
|
-
if (max === null || ch.value < max) {
|
|
972
|
-
max = ch.value;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
});
|
|
976
|
-
return max;
|
|
977
|
-
},
|
|
978
|
-
enumerable: false,
|
|
979
|
-
configurable: true
|
|
980
|
-
});
|
|
981
|
-
ZodString.create = function () {
|
|
982
|
-
return new ZodString({
|
|
983
|
-
checks: [],
|
|
984
|
-
});
|
|
985
|
-
};
|
|
986
|
-
return ZodString;
|
|
987
|
-
}(ZodType));
|
|
988
|
-
var ZodNumber = /** @class */ (function (_super) {
|
|
989
|
-
__extends(ZodNumber, _super);
|
|
990
|
-
function ZodNumber() {
|
|
991
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
992
|
-
_this.min = function (value, message) {
|
|
993
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
994
|
-
{
|
|
995
|
-
kind: "min",
|
|
996
|
-
value: value,
|
|
997
|
-
inclusive: true,
|
|
998
|
-
message: errorUtil.toString(message),
|
|
999
|
-
},
|
|
1000
|
-
]) }));
|
|
1001
|
-
};
|
|
1002
|
-
_this.max = function (value, message) {
|
|
1003
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1004
|
-
{
|
|
1005
|
-
kind: "max",
|
|
1006
|
-
value: value,
|
|
1007
|
-
inclusive: true,
|
|
1008
|
-
message: errorUtil.toString(message),
|
|
1009
|
-
},
|
|
1010
|
-
]) }));
|
|
1011
|
-
};
|
|
1012
|
-
_this.int = function (message) {
|
|
1013
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1014
|
-
{
|
|
1015
|
-
kind: "int",
|
|
1016
|
-
message: errorUtil.toString(message),
|
|
1017
|
-
},
|
|
1018
|
-
]) }));
|
|
1019
|
-
};
|
|
1020
|
-
_this.positive = function (message) {
|
|
1021
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1022
|
-
{
|
|
1023
|
-
kind: "min",
|
|
1024
|
-
value: 0,
|
|
1025
|
-
inclusive: false,
|
|
1026
|
-
message: errorUtil.toString(message),
|
|
1027
|
-
},
|
|
1028
|
-
]) }));
|
|
1029
|
-
};
|
|
1030
|
-
_this.negative = function (message) {
|
|
1031
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1032
|
-
{
|
|
1033
|
-
kind: "max",
|
|
1034
|
-
value: 0,
|
|
1035
|
-
inclusive: false,
|
|
1036
|
-
message: errorUtil.toString(message),
|
|
1037
|
-
},
|
|
1038
|
-
]) }));
|
|
1039
|
-
};
|
|
1040
|
-
_this.nonpositive = function (message) {
|
|
1041
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1042
|
-
{
|
|
1043
|
-
kind: "max",
|
|
1044
|
-
value: 0,
|
|
1045
|
-
inclusive: true,
|
|
1046
|
-
message: errorUtil.toString(message),
|
|
1047
|
-
},
|
|
1048
|
-
]) }));
|
|
1049
|
-
};
|
|
1050
|
-
_this.nonnegative = function (message) {
|
|
1051
|
-
return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
|
|
1052
|
-
{
|
|
1053
|
-
kind: "min",
|
|
1054
|
-
value: 0,
|
|
1055
|
-
inclusive: true,
|
|
1056
|
-
message: errorUtil.toString(message),
|
|
1057
|
-
},
|
|
1058
|
-
]) }));
|
|
1059
|
-
};
|
|
1060
|
-
return _this;
|
|
1061
|
-
}
|
|
1062
|
-
ZodNumber.prototype._parse = function (ctx, data, parsedType) {
|
|
1063
|
-
var e_2, _a;
|
|
1064
|
-
if (parsedType !== ZodParsedType.number) {
|
|
1065
|
-
ctx.addIssue(data, {
|
|
1066
|
-
code: ZodIssueCode.invalid_type,
|
|
1067
|
-
expected: ZodParsedType.number,
|
|
1068
|
-
received: parsedType,
|
|
1069
|
-
});
|
|
1070
|
-
return INVALID;
|
|
1071
|
-
}
|
|
1072
|
-
var invalid = false;
|
|
1073
|
-
try {
|
|
1074
|
-
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1075
|
-
var check = _c.value;
|
|
1076
|
-
if (check.kind === "int") {
|
|
1077
|
-
if (!Number.isInteger(data)) {
|
|
1078
|
-
invalid = true;
|
|
1079
|
-
ctx.addIssue(data, {
|
|
1080
|
-
code: ZodIssueCode.invalid_type,
|
|
1081
|
-
expected: "integer",
|
|
1082
|
-
received: "float",
|
|
1083
|
-
message: check.message,
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
else if (check.kind === "min") {
|
|
1088
|
-
// const MIN = check.value;
|
|
1089
|
-
var tooSmall = check.inclusive
|
|
1090
|
-
? data < check.value
|
|
1091
|
-
: data <= check.value;
|
|
1092
|
-
if (tooSmall) {
|
|
1093
|
-
invalid = true;
|
|
1094
|
-
ctx.addIssue(data, {
|
|
1095
|
-
code: ZodIssueCode.too_small,
|
|
1096
|
-
minimum: check.value,
|
|
1097
|
-
type: "number",
|
|
1098
|
-
inclusive: check.inclusive,
|
|
1099
|
-
message: check.message,
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
else if (check.kind === "max") {
|
|
1104
|
-
var tooBig = check.inclusive
|
|
1105
|
-
? data > check.value
|
|
1106
|
-
: data >= check.value;
|
|
1107
|
-
if (tooBig) {
|
|
1108
|
-
invalid = true;
|
|
1109
|
-
ctx.addIssue(data, {
|
|
1110
|
-
code: ZodIssueCode.too_big,
|
|
1111
|
-
maximum: check.value,
|
|
1112
|
-
type: "number",
|
|
1113
|
-
inclusive: check.inclusive,
|
|
1114
|
-
message: check.message,
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1121
|
-
finally {
|
|
1122
|
-
try {
|
|
1123
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1124
|
-
}
|
|
1125
|
-
finally { if (e_2) throw e_2.error; }
|
|
1126
|
-
}
|
|
1127
|
-
return invalid ? INVALID : OK(data);
|
|
1128
|
-
};
|
|
1129
|
-
Object.defineProperty(ZodNumber.prototype, "minValue", {
|
|
1130
|
-
get: function () {
|
|
1131
|
-
var e_3, _a;
|
|
1132
|
-
var min = null;
|
|
1133
|
-
try {
|
|
1134
|
-
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1135
|
-
var ch = _c.value;
|
|
1136
|
-
if (ch.kind === "min") {
|
|
1137
|
-
if (min === null || ch.value > min)
|
|
1138
|
-
min = ch.value;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1143
|
-
finally {
|
|
1144
|
-
try {
|
|
1145
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1146
|
-
}
|
|
1147
|
-
finally { if (e_3) throw e_3.error; }
|
|
1148
|
-
}
|
|
1149
|
-
return min;
|
|
1150
|
-
},
|
|
1151
|
-
enumerable: false,
|
|
1152
|
-
configurable: true
|
|
1153
|
-
});
|
|
1154
|
-
Object.defineProperty(ZodNumber.prototype, "maxValue", {
|
|
1155
|
-
get: function () {
|
|
1156
|
-
var e_4, _a;
|
|
1157
|
-
var max = null;
|
|
1158
|
-
try {
|
|
1159
|
-
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1160
|
-
var ch = _c.value;
|
|
1161
|
-
if (ch.kind === "max") {
|
|
1162
|
-
if (max === null || ch.value < max)
|
|
1163
|
-
max = ch.value;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1168
|
-
finally {
|
|
1169
|
-
try {
|
|
1170
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1171
|
-
}
|
|
1172
|
-
finally { if (e_4) throw e_4.error; }
|
|
1173
|
-
}
|
|
1174
|
-
return max;
|
|
1175
|
-
},
|
|
1176
|
-
enumerable: false,
|
|
1177
|
-
configurable: true
|
|
1178
|
-
});
|
|
1179
|
-
Object.defineProperty(ZodNumber.prototype, "isInt", {
|
|
1180
|
-
get: function () {
|
|
1181
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "int"; });
|
|
1182
|
-
},
|
|
1183
|
-
enumerable: false,
|
|
1184
|
-
configurable: true
|
|
1185
|
-
});
|
|
1186
|
-
ZodNumber.create = function () {
|
|
1187
|
-
return new ZodNumber({
|
|
1188
|
-
checks: [],
|
|
1189
|
-
});
|
|
1190
|
-
};
|
|
1191
|
-
return ZodNumber;
|
|
1192
|
-
}(ZodType));
|
|
1193
|
-
var ZodBigInt = /** @class */ (function (_super) {
|
|
1194
|
-
__extends(ZodBigInt, _super);
|
|
1195
|
-
function ZodBigInt() {
|
|
1196
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1197
|
-
}
|
|
1198
|
-
ZodBigInt.prototype._parse = function (ctx, data, parsedType) {
|
|
1199
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
1200
|
-
ctx.addIssue(data, {
|
|
1201
|
-
code: ZodIssueCode.invalid_type,
|
|
1202
|
-
expected: ZodParsedType.bigint,
|
|
1203
|
-
received: parsedType,
|
|
1204
|
-
});
|
|
1205
|
-
return INVALID;
|
|
1206
|
-
}
|
|
1207
|
-
return OK(data);
|
|
1208
|
-
};
|
|
1209
|
-
ZodBigInt.create = function () {
|
|
1210
|
-
return new ZodBigInt({});
|
|
1211
|
-
};
|
|
1212
|
-
return ZodBigInt;
|
|
1213
|
-
}(ZodType));
|
|
1214
|
-
var ZodBoolean = /** @class */ (function (_super) {
|
|
1215
|
-
__extends(ZodBoolean, _super);
|
|
1216
|
-
function ZodBoolean() {
|
|
1217
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1218
|
-
}
|
|
1219
|
-
ZodBoolean.prototype._parse = function (ctx, data, parsedType) {
|
|
1220
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
1221
|
-
ctx.addIssue(data, {
|
|
1222
|
-
code: ZodIssueCode.invalid_type,
|
|
1223
|
-
expected: ZodParsedType.boolean,
|
|
1224
|
-
received: parsedType,
|
|
1225
|
-
});
|
|
1226
|
-
return INVALID;
|
|
1227
|
-
}
|
|
1228
|
-
return OK(data);
|
|
1229
|
-
};
|
|
1230
|
-
ZodBoolean.create = function () {
|
|
1231
|
-
return new ZodBoolean({});
|
|
1232
|
-
};
|
|
1233
|
-
return ZodBoolean;
|
|
1234
|
-
}(ZodType));
|
|
1235
|
-
var ZodDate = /** @class */ (function (_super) {
|
|
1236
|
-
__extends(ZodDate, _super);
|
|
1237
|
-
function ZodDate() {
|
|
1238
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1239
|
-
}
|
|
1240
|
-
ZodDate.prototype._parse = function (ctx, data, parsedType) {
|
|
1241
|
-
if (parsedType !== ZodParsedType.date) {
|
|
1242
|
-
ctx.addIssue(data, {
|
|
1243
|
-
code: ZodIssueCode.invalid_type,
|
|
1244
|
-
expected: ZodParsedType.date,
|
|
1245
|
-
received: parsedType,
|
|
1246
|
-
});
|
|
1247
|
-
return INVALID;
|
|
1248
|
-
}
|
|
1249
|
-
if (isNaN(data.getTime())) {
|
|
1250
|
-
ctx.addIssue(data, {
|
|
1251
|
-
code: ZodIssueCode.invalid_date,
|
|
1252
|
-
});
|
|
1253
|
-
return INVALID;
|
|
1254
|
-
}
|
|
1255
|
-
return OK(new Date(data.getTime()));
|
|
1256
|
-
};
|
|
1257
|
-
ZodDate.create = function () {
|
|
1258
|
-
return new ZodDate({});
|
|
1259
|
-
};
|
|
1260
|
-
return ZodDate;
|
|
1261
|
-
}(ZodType));
|
|
1262
|
-
var ZodUndefined = /** @class */ (function (_super) {
|
|
1263
|
-
__extends(ZodUndefined, _super);
|
|
1264
|
-
function ZodUndefined() {
|
|
1265
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1266
|
-
}
|
|
1267
|
-
ZodUndefined.prototype._parse = function (ctx, data, parsedType) {
|
|
1268
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
1269
|
-
ctx.addIssue(data, {
|
|
1270
|
-
code: ZodIssueCode.invalid_type,
|
|
1271
|
-
expected: ZodParsedType.undefined,
|
|
1272
|
-
received: parsedType,
|
|
1273
|
-
});
|
|
1274
|
-
return INVALID;
|
|
1275
|
-
}
|
|
1276
|
-
return OK(data);
|
|
1277
|
-
};
|
|
1278
|
-
ZodUndefined.create = function () {
|
|
1279
|
-
return new ZodUndefined({});
|
|
1280
|
-
};
|
|
1281
|
-
return ZodUndefined;
|
|
1282
|
-
}(ZodType));
|
|
1283
|
-
var ZodNull = /** @class */ (function (_super) {
|
|
1284
|
-
__extends(ZodNull, _super);
|
|
1285
|
-
function ZodNull() {
|
|
1286
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1287
|
-
}
|
|
1288
|
-
ZodNull.prototype._parse = function (ctx, data, parsedType) {
|
|
1289
|
-
if (parsedType !== ZodParsedType.null) {
|
|
1290
|
-
ctx.addIssue(data, {
|
|
1291
|
-
code: ZodIssueCode.invalid_type,
|
|
1292
|
-
expected: ZodParsedType.null,
|
|
1293
|
-
received: parsedType,
|
|
1294
|
-
});
|
|
1295
|
-
return INVALID;
|
|
1296
|
-
}
|
|
1297
|
-
return OK(data);
|
|
1298
|
-
};
|
|
1299
|
-
ZodNull.create = function () {
|
|
1300
|
-
return new ZodNull({});
|
|
1301
|
-
};
|
|
1302
|
-
return ZodNull;
|
|
1303
|
-
}(ZodType));
|
|
1304
|
-
var ZodAny = /** @class */ (function (_super) {
|
|
1305
|
-
__extends(ZodAny, _super);
|
|
1306
|
-
function ZodAny() {
|
|
1307
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1308
|
-
}
|
|
1309
|
-
ZodAny.prototype._parse = function (_ctx, data, _parsedType) {
|
|
1310
|
-
return OK(data);
|
|
1311
|
-
};
|
|
1312
|
-
ZodAny.create = function () {
|
|
1313
|
-
return new ZodAny({});
|
|
1314
|
-
};
|
|
1315
|
-
return ZodAny;
|
|
1316
|
-
}(ZodType));
|
|
1317
|
-
var ZodUnknown = /** @class */ (function (_super) {
|
|
1318
|
-
__extends(ZodUnknown, _super);
|
|
1319
|
-
function ZodUnknown() {
|
|
1320
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1321
|
-
}
|
|
1322
|
-
ZodUnknown.prototype._parse = function (_ctx, data, _parsedType) {
|
|
1323
|
-
return OK(data);
|
|
1324
|
-
};
|
|
1325
|
-
ZodUnknown.create = function () {
|
|
1326
|
-
return new ZodUnknown({});
|
|
1327
|
-
};
|
|
1328
|
-
return ZodUnknown;
|
|
1329
|
-
}(ZodType));
|
|
1330
|
-
var ZodNever = /** @class */ (function (_super) {
|
|
1331
|
-
__extends(ZodNever, _super);
|
|
1332
|
-
function ZodNever() {
|
|
1333
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1334
|
-
}
|
|
1335
|
-
ZodNever.prototype._parse = function (ctx, data, parsedType) {
|
|
1336
|
-
ctx.addIssue(data, {
|
|
1337
|
-
code: ZodIssueCode.invalid_type,
|
|
1338
|
-
expected: ZodParsedType.never,
|
|
1339
|
-
received: parsedType,
|
|
1340
|
-
});
|
|
1341
|
-
return INVALID;
|
|
1342
|
-
};
|
|
1343
|
-
ZodNever.create = function () {
|
|
1344
|
-
return new ZodNever({});
|
|
1345
|
-
};
|
|
1346
|
-
return ZodNever;
|
|
1347
|
-
}(ZodType));
|
|
1348
|
-
var ZodVoid = /** @class */ (function (_super) {
|
|
1349
|
-
__extends(ZodVoid, _super);
|
|
1350
|
-
function ZodVoid() {
|
|
1351
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1352
|
-
}
|
|
1353
|
-
ZodVoid.prototype._parse = function (ctx, data, parsedType) {
|
|
1354
|
-
if (parsedType !== ZodParsedType.undefined &&
|
|
1355
|
-
parsedType !== ZodParsedType.null) {
|
|
1356
|
-
ctx.addIssue(data, {
|
|
1357
|
-
code: ZodIssueCode.invalid_type,
|
|
1358
|
-
expected: ZodParsedType.void,
|
|
1359
|
-
received: parsedType,
|
|
1360
|
-
});
|
|
1361
|
-
return INVALID;
|
|
1362
|
-
}
|
|
1363
|
-
return OK(data);
|
|
1364
|
-
};
|
|
1365
|
-
ZodVoid.create = function () {
|
|
1366
|
-
return new ZodVoid({});
|
|
1367
|
-
};
|
|
1368
|
-
return ZodVoid;
|
|
1369
|
-
}(ZodType));
|
|
1370
|
-
var parseArray = function (ctx, data, parsedType, def, nonEmpty) {
|
|
1371
|
-
if (parsedType !== ZodParsedType.array) {
|
|
1372
|
-
ctx.addIssue(data, {
|
|
1373
|
-
code: ZodIssueCode.invalid_type,
|
|
1374
|
-
expected: ZodParsedType.array,
|
|
1375
|
-
received: parsedType,
|
|
1376
|
-
});
|
|
1377
|
-
return INVALID;
|
|
1378
|
-
}
|
|
1379
|
-
var invalid = false;
|
|
1380
|
-
if (def.minLength !== null) {
|
|
1381
|
-
if (data.length < def.minLength.value) {
|
|
1382
|
-
invalid = true;
|
|
1383
|
-
ctx.addIssue(data, {
|
|
1384
|
-
code: ZodIssueCode.too_small,
|
|
1385
|
-
minimum: def.minLength.value,
|
|
1386
|
-
type: "array",
|
|
1387
|
-
inclusive: true,
|
|
1388
|
-
message: def.minLength.message,
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
if (def.maxLength !== null) {
|
|
1393
|
-
if (data.length > def.maxLength.value) {
|
|
1394
|
-
invalid = true;
|
|
1395
|
-
ctx.addIssue(data, {
|
|
1396
|
-
code: ZodIssueCode.too_big,
|
|
1397
|
-
maximum: def.maxLength.value,
|
|
1398
|
-
type: "array",
|
|
1399
|
-
inclusive: true,
|
|
1400
|
-
message: def.maxLength.message,
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
if (nonEmpty && data.length < 1) {
|
|
1405
|
-
invalid = true;
|
|
1406
|
-
ctx.addIssue(data, {
|
|
1407
|
-
code: ZodIssueCode.too_small,
|
|
1408
|
-
minimum: 1,
|
|
1409
|
-
type: "array",
|
|
1410
|
-
inclusive: true,
|
|
1411
|
-
// message: this._def.minLength.message,
|
|
1412
|
-
// ...errorUtil.errToObj(this._def.minLength.message),
|
|
1413
|
-
});
|
|
1414
|
-
}
|
|
1415
|
-
if (invalid) {
|
|
1416
|
-
return INVALID;
|
|
1417
|
-
}
|
|
1418
|
-
var tasks = createTasks(ctx);
|
|
1419
|
-
var result = new Array(data.length);
|
|
1420
|
-
var type = def.type;
|
|
1421
|
-
var handleParsed = function (index, parsedItem) {
|
|
1422
|
-
if (isOk(parsedItem)) {
|
|
1423
|
-
result[index] = parsedItem.value;
|
|
1424
|
-
}
|
|
1425
|
-
else if (isInvalid(parsedItem)) {
|
|
1426
|
-
invalid = true;
|
|
1427
|
-
}
|
|
1428
|
-
else {
|
|
1429
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(index, parsed); }));
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
data.forEach(function (item, index) {
|
|
1433
|
-
handleParsed(index, type._parse(ctx.stepInto(index), item, getParsedType(item)));
|
|
1434
|
-
});
|
|
1435
|
-
if (tasks !== null && tasks.length > 0) {
|
|
1436
|
-
return ASYNC(Promise.all(tasks).then(function () { return (invalid ? INVALID : OK(result)); }));
|
|
1437
|
-
}
|
|
1438
|
-
else {
|
|
1439
|
-
return invalid ? INVALID : OK(result);
|
|
1440
|
-
}
|
|
1441
|
-
};
|
|
1442
|
-
var ZodArray = /** @class */ (function (_super) {
|
|
1443
|
-
__extends(ZodArray, _super);
|
|
1444
|
-
function ZodArray() {
|
|
1445
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1446
|
-
_this.min = function (minLength, message) {
|
|
1447
|
-
return new ZodArray(__assign(__assign({}, _this._def), { minLength: { value: minLength, message: errorUtil.toString(message) } }));
|
|
1448
|
-
};
|
|
1449
|
-
_this.max = function (maxLength, message) {
|
|
1450
|
-
return new ZodArray(__assign(__assign({}, _this._def), { maxLength: { value: maxLength, message: errorUtil.toString(message) } }));
|
|
1451
|
-
};
|
|
1452
|
-
_this.length = function (len, message) {
|
|
1453
|
-
return _this.min(len, message).max(len, message);
|
|
1454
|
-
};
|
|
1455
|
-
_this.nonempty = function () {
|
|
1456
|
-
return new ZodNonEmptyArray(__assign({}, _this._def));
|
|
1457
|
-
};
|
|
1458
|
-
return _this;
|
|
1459
|
-
}
|
|
1460
|
-
ZodArray.prototype._parse = function (ctx, data, parsedType) {
|
|
1461
|
-
var nonEmpty = false;
|
|
1462
|
-
return parseArray(ctx, data, parsedType, this._def, nonEmpty);
|
|
1463
|
-
};
|
|
1464
|
-
Object.defineProperty(ZodArray.prototype, "element", {
|
|
1465
|
-
get: function () {
|
|
1466
|
-
return this._def.type;
|
|
1467
|
-
},
|
|
1468
|
-
enumerable: false,
|
|
1469
|
-
configurable: true
|
|
1470
|
-
});
|
|
1471
|
-
ZodArray.create = function (schema) {
|
|
1472
|
-
return new ZodArray({
|
|
1473
|
-
type: schema,
|
|
1474
|
-
minLength: null,
|
|
1475
|
-
maxLength: null,
|
|
1476
|
-
});
|
|
1477
|
-
};
|
|
1478
|
-
return ZodArray;
|
|
1479
|
-
}(ZodType));
|
|
1480
|
-
var ZodNonEmptyArray = /** @class */ (function (_super) {
|
|
1481
|
-
__extends(ZodNonEmptyArray, _super);
|
|
1482
|
-
function ZodNonEmptyArray() {
|
|
1483
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1484
|
-
_this.min = function (minLength, message) {
|
|
1485
|
-
return new ZodNonEmptyArray(__assign(__assign({}, _this._def), { minLength: { value: minLength, message: errorUtil.toString(message) } }));
|
|
1486
|
-
};
|
|
1487
|
-
_this.max = function (maxLength, message) {
|
|
1488
|
-
return new ZodNonEmptyArray(__assign(__assign({}, _this._def), { maxLength: { value: maxLength, message: errorUtil.toString(message) } }));
|
|
1489
|
-
};
|
|
1490
|
-
_this.length = function (len, message) {
|
|
1491
|
-
return _this.min(len, message).max(len, message);
|
|
1492
|
-
};
|
|
1493
|
-
return _this;
|
|
1494
|
-
}
|
|
1495
|
-
ZodNonEmptyArray.prototype._parse = function (ctx, data, parsedType) {
|
|
1496
|
-
var nonEmpty = true;
|
|
1497
|
-
return parseArray(ctx, data, parsedType, this._def, nonEmpty);
|
|
1498
|
-
};
|
|
1499
|
-
ZodNonEmptyArray.create = function (schema) {
|
|
1500
|
-
return new ZodNonEmptyArray({
|
|
1501
|
-
type: schema,
|
|
1502
|
-
minLength: null,
|
|
1503
|
-
maxLength: null,
|
|
1504
|
-
});
|
|
1505
|
-
};
|
|
1506
|
-
return ZodNonEmptyArray;
|
|
1507
|
-
}(ZodType));
|
|
1508
|
-
/////////////////////////////////////////
|
|
1509
|
-
/////////////////////////////////////////
|
|
1510
|
-
////////// //////////
|
|
1511
|
-
////////// ZodObject //////////
|
|
1512
|
-
////////// //////////
|
|
1513
|
-
/////////////////////////////////////////
|
|
1514
|
-
/////////////////////////////////////////
|
|
1515
|
-
var objectUtil;
|
|
1516
|
-
(function (objectUtil) {
|
|
1517
|
-
objectUtil.mergeShapes = function (first, second) {
|
|
1518
|
-
return __assign(__assign({}, first), second);
|
|
1519
|
-
};
|
|
1520
|
-
objectUtil.intersectShapes = function (first, second) {
|
|
1521
|
-
var e_5, _a;
|
|
1522
|
-
var firstKeys = Object.keys(first);
|
|
1523
|
-
var secondKeys = Object.keys(second);
|
|
1524
|
-
var sharedKeys = firstKeys.filter(function (k) { return secondKeys.indexOf(k) !== -1; });
|
|
1525
|
-
var sharedShape = {};
|
|
1526
|
-
try {
|
|
1527
|
-
for (var sharedKeys_1 = __values(sharedKeys), sharedKeys_1_1 = sharedKeys_1.next(); !sharedKeys_1_1.done; sharedKeys_1_1 = sharedKeys_1.next()) {
|
|
1528
|
-
var k = sharedKeys_1_1.value;
|
|
1529
|
-
sharedShape[k] = ZodIntersection.create(first[k], second[k]);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1533
|
-
finally {
|
|
1534
|
-
try {
|
|
1535
|
-
if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
|
|
1536
|
-
}
|
|
1537
|
-
finally { if (e_5) throw e_5.error; }
|
|
1538
|
-
}
|
|
1539
|
-
return __assign(__assign(__assign({}, first), second), sharedShape);
|
|
1540
|
-
};
|
|
1541
|
-
})(objectUtil || (objectUtil = {}));
|
|
1542
|
-
var mergeObjects = function (first) { return function (second) {
|
|
1543
|
-
var mergedShape = objectUtil.mergeShapes(first._def.shape(), second._def.shape());
|
|
1544
|
-
var merged = new ZodObject({
|
|
1545
|
-
// effects: [...(first._def.effects || []), ...(second._def.effects || [])],
|
|
1546
|
-
unknownKeys: first._def.unknownKeys,
|
|
1547
|
-
catchall: first._def.catchall,
|
|
1548
|
-
shape: function () { return mergedShape; },
|
|
1549
|
-
});
|
|
1550
|
-
return merged;
|
|
1551
|
-
}; };
|
|
1552
|
-
var AugmentFactory = function (def) { return function (augmentation) {
|
|
1553
|
-
return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
|
|
1554
|
-
}; };
|
|
1555
|
-
var ZodObject = /** @class */ (function (_super) {
|
|
1556
|
-
__extends(ZodObject, _super);
|
|
1557
|
-
function ZodObject() {
|
|
1558
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1559
|
-
_this._cached = null;
|
|
1560
|
-
_this.strict = function () {
|
|
1561
|
-
return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "strict" }));
|
|
1562
|
-
};
|
|
1563
|
-
_this.strip = function () {
|
|
1564
|
-
return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "strip" }));
|
|
1565
|
-
};
|
|
1566
|
-
_this.passthrough = function () {
|
|
1567
|
-
return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "passthrough" }));
|
|
1568
|
-
};
|
|
1569
|
-
/**
|
|
1570
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
1571
|
-
* If you want to pass through unknown properies, use `.passthrough()` instead.
|
|
1572
|
-
*/
|
|
1573
|
-
_this.nonstrict = _this.passthrough;
|
|
1574
|
-
_this.augment = AugmentFactory(_this._def);
|
|
1575
|
-
_this.extend = AugmentFactory(_this._def);
|
|
1576
|
-
_this.setKey = function (key, schema) {
|
|
1577
|
-
var _a;
|
|
1578
|
-
return _this.augment((_a = {}, _a[key] = schema, _a));
|
|
1579
|
-
};
|
|
1580
|
-
/**
|
|
1581
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
1582
|
-
* inferred type of merged objects. Please
|
|
1583
|
-
* upgrade if you are experiencing issues.
|
|
1584
|
-
*/
|
|
1585
|
-
_this.merge = function (merging) {
|
|
1586
|
-
var mergedShape = objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
|
|
1587
|
-
var merged = new ZodObject({
|
|
1588
|
-
// effects: [], // wipe all refinements
|
|
1589
|
-
unknownKeys: merging._def.unknownKeys,
|
|
1590
|
-
catchall: merging._def.catchall,
|
|
1591
|
-
shape: function () { return mergedShape; },
|
|
1592
|
-
});
|
|
1593
|
-
return merged;
|
|
1594
|
-
};
|
|
1595
|
-
_this.catchall = function (index) {
|
|
1596
|
-
return new ZodObject(__assign(__assign({}, _this._def), { catchall: index }));
|
|
1597
|
-
};
|
|
1598
|
-
_this.pick = function (mask) {
|
|
1599
|
-
var shape = {};
|
|
1600
|
-
Object.keys(mask).map(function (key) {
|
|
1601
|
-
shape[key] = _this.shape[key];
|
|
1602
|
-
});
|
|
1603
|
-
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
|
|
1604
|
-
};
|
|
1605
|
-
_this.omit = function (mask) {
|
|
1606
|
-
var shape = {};
|
|
1607
|
-
Object.keys(_this.shape).map(function (key) {
|
|
1608
|
-
if (Object.keys(mask).indexOf(key) === -1) {
|
|
1609
|
-
shape[key] = _this.shape[key];
|
|
1610
|
-
}
|
|
1611
|
-
});
|
|
1612
|
-
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
|
|
1613
|
-
};
|
|
1614
|
-
_this.partial = function () {
|
|
1615
|
-
var newShape = {};
|
|
1616
|
-
for (var key in _this.shape) {
|
|
1617
|
-
var fieldSchema = _this.shape[key];
|
|
1618
|
-
newShape[key] = fieldSchema.isOptional()
|
|
1619
|
-
? fieldSchema
|
|
1620
|
-
: fieldSchema.optional();
|
|
1621
|
-
}
|
|
1622
|
-
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
|
|
1623
|
-
};
|
|
1624
|
-
_this.deepPartial = function () {
|
|
1625
|
-
var newShape = {};
|
|
1626
|
-
for (var key in _this.shape) {
|
|
1627
|
-
var fieldSchema = _this.shape[key];
|
|
1628
|
-
if (fieldSchema instanceof ZodObject) {
|
|
1629
|
-
newShape[key] = fieldSchema.isOptional()
|
|
1630
|
-
? fieldSchema
|
|
1631
|
-
: fieldSchema.deepPartial().optional();
|
|
1632
|
-
}
|
|
1633
|
-
else {
|
|
1634
|
-
newShape[key] = fieldSchema.isOptional()
|
|
1635
|
-
? fieldSchema
|
|
1636
|
-
: fieldSchema.optional();
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
|
|
1640
|
-
};
|
|
1641
|
-
_this.required = function () {
|
|
1642
|
-
var newShape = {};
|
|
1643
|
-
for (var key in _this.shape) {
|
|
1644
|
-
var fieldSchema = _this.shape[key];
|
|
1645
|
-
var newField = fieldSchema;
|
|
1646
|
-
while (newField instanceof ZodOptional) {
|
|
1647
|
-
newField = newField._def.innerType;
|
|
1648
|
-
}
|
|
1649
|
-
newShape[key] = newField;
|
|
1650
|
-
}
|
|
1651
|
-
return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
|
|
1652
|
-
};
|
|
1653
|
-
return _this;
|
|
1654
|
-
}
|
|
1655
|
-
ZodObject.prototype._getCached = function () {
|
|
1656
|
-
if (this._cached !== null)
|
|
1657
|
-
return this._cached;
|
|
1658
|
-
var shape = this._def.shape();
|
|
1659
|
-
var keys = Object.keys(shape);
|
|
1660
|
-
return (this._cached = { shape: shape, keys: keys });
|
|
1661
|
-
};
|
|
1662
|
-
ZodObject.prototype._parse = function (ctx, data, parsedType) {
|
|
1663
|
-
var e_6, _a, e_7, _b, e_8, _c;
|
|
1664
|
-
if (parsedType !== ZodParsedType.object) {
|
|
1665
|
-
ctx.addIssue(data, {
|
|
1666
|
-
code: ZodIssueCode.invalid_type,
|
|
1667
|
-
expected: ZodParsedType.object,
|
|
1668
|
-
received: parsedType,
|
|
1669
|
-
});
|
|
1670
|
-
return INVALID;
|
|
1671
|
-
}
|
|
1672
|
-
var _d = this._getCached(), shape = _d.shape, shapeKeys = _d.keys;
|
|
1673
|
-
var invalid = false;
|
|
1674
|
-
var tasks = createTasks(ctx);
|
|
1675
|
-
var resultObject = {};
|
|
1676
|
-
var handleParsed = function (key, parsedValue) {
|
|
1677
|
-
if (isOk(parsedValue)) {
|
|
1678
|
-
var value = parsedValue.value;
|
|
1679
|
-
if (typeof value !== "undefined" || key in data) {
|
|
1680
|
-
// key was valid but result was undefined: add it to the result object
|
|
1681
|
-
// only if key was in the input data object - if it wasn't, then it's
|
|
1682
|
-
// an optional key that should not be added
|
|
1683
|
-
resultObject[key] = value;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
else if (isInvalid(parsedValue)) {
|
|
1687
|
-
invalid = true;
|
|
1688
|
-
}
|
|
1689
|
-
else {
|
|
1690
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedValue.promise.then(function (parsed) { return handleParsed(key, parsed); }));
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1693
|
-
try {
|
|
1694
|
-
for (var shapeKeys_1 = __values(shapeKeys), shapeKeys_1_1 = shapeKeys_1.next(); !shapeKeys_1_1.done; shapeKeys_1_1 = shapeKeys_1.next()) {
|
|
1695
|
-
var key = shapeKeys_1_1.value;
|
|
1696
|
-
var keyValidator = shape[key];
|
|
1697
|
-
var value = data[key];
|
|
1698
|
-
handleParsed(key, keyValidator._parse(ctx.stepInto(key), value, getParsedType(value)));
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1702
|
-
finally {
|
|
1703
|
-
try {
|
|
1704
|
-
if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
|
|
1705
|
-
}
|
|
1706
|
-
finally { if (e_6) throw e_6.error; }
|
|
1707
|
-
}
|
|
1708
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
1709
|
-
var unknownKeys = this._def.unknownKeys;
|
|
1710
|
-
if (unknownKeys === "passthrough") {
|
|
1711
|
-
var dataKeys = Object.keys(data);
|
|
1712
|
-
var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
|
|
1713
|
-
try {
|
|
1714
|
-
for (var extraKeys_1 = __values(extraKeys), extraKeys_1_1 = extraKeys_1.next(); !extraKeys_1_1.done; extraKeys_1_1 = extraKeys_1.next()) {
|
|
1715
|
-
var key = extraKeys_1_1.value;
|
|
1716
|
-
resultObject[key] = data[key];
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1720
|
-
finally {
|
|
1721
|
-
try {
|
|
1722
|
-
if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
|
|
1723
|
-
}
|
|
1724
|
-
finally { if (e_7) throw e_7.error; }
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
else if (unknownKeys === "strict") {
|
|
1728
|
-
var dataKeys = Object.keys(data);
|
|
1729
|
-
var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
|
|
1730
|
-
if (extraKeys.length > 0) {
|
|
1731
|
-
invalid = true;
|
|
1732
|
-
ctx.addIssue(data, {
|
|
1733
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
1734
|
-
keys: extraKeys,
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
else if (unknownKeys === "strip") ;
|
|
1739
|
-
else {
|
|
1740
|
-
throw new Error("Internal ZodObject error: invalid unknownKeys value.");
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
else {
|
|
1744
|
-
// run catchall validation
|
|
1745
|
-
var catchall = this._def.catchall;
|
|
1746
|
-
var dataKeys = Object.keys(data);
|
|
1747
|
-
var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
|
|
1748
|
-
try {
|
|
1749
|
-
for (var extraKeys_2 = __values(extraKeys), extraKeys_2_1 = extraKeys_2.next(); !extraKeys_2_1.done; extraKeys_2_1 = extraKeys_2.next()) {
|
|
1750
|
-
var key = extraKeys_2_1.value;
|
|
1751
|
-
var value = data[key];
|
|
1752
|
-
handleParsed(key, catchall._parse(ctx.stepInto(key), value, getParsedType(value)));
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1756
|
-
finally {
|
|
1757
|
-
try {
|
|
1758
|
-
if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
|
|
1759
|
-
}
|
|
1760
|
-
finally { if (e_8) throw e_8.error; }
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
if (tasks !== null && tasks.length > 0) {
|
|
1764
|
-
return ASYNC(Promise.all(tasks).then(function () {
|
|
1765
|
-
return invalid ? INVALID : OK(resultObject);
|
|
1766
|
-
}));
|
|
1767
|
-
}
|
|
1768
|
-
else {
|
|
1769
|
-
return invalid ? INVALID : OK(resultObject);
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
Object.defineProperty(ZodObject.prototype, "shape", {
|
|
1773
|
-
get: function () {
|
|
1774
|
-
return this._def.shape();
|
|
1775
|
-
},
|
|
1776
|
-
enumerable: false,
|
|
1777
|
-
configurable: true
|
|
1778
|
-
});
|
|
1779
|
-
ZodObject.create = function (shape) {
|
|
1780
|
-
return new ZodObject({
|
|
1781
|
-
shape: function () { return shape; },
|
|
1782
|
-
unknownKeys: "strip",
|
|
1783
|
-
catchall: ZodNever.create(),
|
|
1784
|
-
});
|
|
1785
|
-
};
|
|
1786
|
-
ZodObject.strictCreate = function (shape) {
|
|
1787
|
-
return new ZodObject({
|
|
1788
|
-
shape: function () { return shape; },
|
|
1789
|
-
unknownKeys: "strict",
|
|
1790
|
-
catchall: ZodNever.create(),
|
|
1791
|
-
});
|
|
1792
|
-
};
|
|
1793
|
-
ZodObject.lazycreate = function (shape) {
|
|
1794
|
-
return new ZodObject({
|
|
1795
|
-
shape: shape,
|
|
1796
|
-
unknownKeys: "strip",
|
|
1797
|
-
catchall: ZodNever.create(),
|
|
1798
|
-
});
|
|
1799
|
-
};
|
|
1800
|
-
return ZodObject;
|
|
1801
|
-
}(ZodType));
|
|
1802
|
-
// export type toOpts<T> = T extends ZodUnionOptions ? T : never;
|
|
1803
|
-
// export type ZodUnionType<
|
|
1804
|
-
// A extends ZodTypeAny,
|
|
1805
|
-
// B extends ZodTypeAny
|
|
1806
|
-
// > = A extends ZodUnion<infer AOpts>
|
|
1807
|
-
// ? B extends ZodUnion<infer BOpts>
|
|
1808
|
-
// ? ZodUnion<toOpts<[...AOpts, ...BOpts]>>
|
|
1809
|
-
// : ZodUnion<toOpts<[...AOpts, B]>>
|
|
1810
|
-
// : B extends ZodUnion<infer BOpts>
|
|
1811
|
-
// ? ZodUnion<toOpts<[A, ...BOpts]>>
|
|
1812
|
-
// : ZodUnion<toOpts<[A, B]>>;
|
|
1813
|
-
var ZodUnion = /** @class */ (function (_super) {
|
|
1814
|
-
__extends(ZodUnion, _super);
|
|
1815
|
-
function ZodUnion() {
|
|
1816
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1817
|
-
}
|
|
1818
|
-
ZodUnion.prototype._parse = function (ctx, data, parsedType) {
|
|
1819
|
-
var e_9, _a;
|
|
1820
|
-
var options = this._def.options;
|
|
1821
|
-
var noMatch = function (allIssues) {
|
|
1822
|
-
var unionErrors = allIssues.map(function (issues) { return new ZodError(issues); });
|
|
1823
|
-
var nonTypeErrors = unionErrors.filter(function (err) {
|
|
1824
|
-
return err.issues[0].code !== "invalid_type";
|
|
1825
|
-
});
|
|
1826
|
-
if (nonTypeErrors.length === 1) {
|
|
1827
|
-
// TODO encapsulate
|
|
1828
|
-
nonTypeErrors[0].issues.forEach(function (issue) { return ctx.issues.push(issue); });
|
|
1829
|
-
}
|
|
1830
|
-
else {
|
|
1831
|
-
ctx.addIssue(data, {
|
|
1832
|
-
code: ZodIssueCode.invalid_union,
|
|
1833
|
-
unionErrors: unionErrors,
|
|
1834
|
-
});
|
|
1835
|
-
}
|
|
1836
|
-
return INVALID;
|
|
1837
|
-
};
|
|
1838
|
-
if (ctx.params.async) {
|
|
1839
|
-
var contexts_1 = options.map(function () { return new ParseContext(ctx.path, [], ctx.params); });
|
|
1840
|
-
return PseudoPromise.all(options.map(function (option, index) {
|
|
1841
|
-
return option._parse(contexts_1[index], data, parsedType);
|
|
1842
|
-
})).then(function (parsedOptions) {
|
|
1843
|
-
var e_10, _a;
|
|
1844
|
-
try {
|
|
1845
|
-
for (var parsedOptions_1 = __values(parsedOptions), parsedOptions_1_1 = parsedOptions_1.next(); !parsedOptions_1_1.done; parsedOptions_1_1 = parsedOptions_1.next()) {
|
|
1846
|
-
var parsedOption = parsedOptions_1_1.value;
|
|
1847
|
-
if (isOk(parsedOption)) {
|
|
1848
|
-
return parsedOption;
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1853
|
-
finally {
|
|
1854
|
-
try {
|
|
1855
|
-
if (parsedOptions_1_1 && !parsedOptions_1_1.done && (_a = parsedOptions_1.return)) _a.call(parsedOptions_1);
|
|
1856
|
-
}
|
|
1857
|
-
finally { if (e_10) throw e_10.error; }
|
|
1858
|
-
}
|
|
1859
|
-
return noMatch(contexts_1.map(function (ctx) { return ctx.issues; }));
|
|
1860
|
-
});
|
|
1861
|
-
}
|
|
1862
|
-
else {
|
|
1863
|
-
var allIssues = [];
|
|
1864
|
-
try {
|
|
1865
|
-
for (var options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
|
|
1866
|
-
var option = options_1_1.value;
|
|
1867
|
-
var optionCtx = new ParseContext(ctx.path, [], ctx.params);
|
|
1868
|
-
var parsedOption = option._parseSync(optionCtx, data, parsedType);
|
|
1869
|
-
if (isInvalid(parsedOption)) {
|
|
1870
|
-
allIssues.push(optionCtx.issues);
|
|
1871
|
-
}
|
|
1872
|
-
else {
|
|
1873
|
-
return parsedOption;
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
1878
|
-
finally {
|
|
1879
|
-
try {
|
|
1880
|
-
if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
|
|
1881
|
-
}
|
|
1882
|
-
finally { if (e_9) throw e_9.error; }
|
|
1883
|
-
}
|
|
1884
|
-
return noMatch(allIssues);
|
|
1885
|
-
}
|
|
1886
|
-
};
|
|
1887
|
-
Object.defineProperty(ZodUnion.prototype, "options", {
|
|
1888
|
-
get: function () {
|
|
1889
|
-
return this._def.options;
|
|
1890
|
-
},
|
|
1891
|
-
enumerable: false,
|
|
1892
|
-
configurable: true
|
|
1893
|
-
});
|
|
1894
|
-
ZodUnion.create = function (types) {
|
|
1895
|
-
return new ZodUnion({
|
|
1896
|
-
options: types,
|
|
1897
|
-
});
|
|
1898
|
-
};
|
|
1899
|
-
return ZodUnion;
|
|
1900
|
-
}(ZodType));
|
|
1901
|
-
function mergeValues(a, b) {
|
|
1902
|
-
var e_11, _a;
|
|
1903
|
-
var aType = getParsedType(a);
|
|
1904
|
-
var bType = getParsedType(b);
|
|
1905
|
-
if (a === b) {
|
|
1906
|
-
return { valid: true, data: a };
|
|
1907
|
-
}
|
|
1908
|
-
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
1909
|
-
var bKeysSet_1 = new Set(Object.keys(b));
|
|
1910
|
-
var sharedKeys = Object.keys(a).filter(function (key) { return bKeysSet_1.has(key); });
|
|
1911
|
-
var newObj = __assign(__assign({}, a), b);
|
|
1912
|
-
try {
|
|
1913
|
-
for (var sharedKeys_2 = __values(sharedKeys), sharedKeys_2_1 = sharedKeys_2.next(); !sharedKeys_2_1.done; sharedKeys_2_1 = sharedKeys_2.next()) {
|
|
1914
|
-
var key = sharedKeys_2_1.value;
|
|
1915
|
-
var sharedValue = mergeValues(a[key], b[key]);
|
|
1916
|
-
if (!sharedValue.valid) {
|
|
1917
|
-
return { valid: false };
|
|
1918
|
-
}
|
|
1919
|
-
newObj[key] = sharedValue.data;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1923
|
-
finally {
|
|
1924
|
-
try {
|
|
1925
|
-
if (sharedKeys_2_1 && !sharedKeys_2_1.done && (_a = sharedKeys_2.return)) _a.call(sharedKeys_2);
|
|
1926
|
-
}
|
|
1927
|
-
finally { if (e_11) throw e_11.error; }
|
|
1928
|
-
}
|
|
1929
|
-
return { valid: true, data: newObj };
|
|
1930
|
-
}
|
|
1931
|
-
else {
|
|
1932
|
-
return { valid: false };
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
var ZodIntersection = /** @class */ (function (_super) {
|
|
1936
|
-
__extends(ZodIntersection, _super);
|
|
1937
|
-
function ZodIntersection() {
|
|
1938
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1939
|
-
}
|
|
1940
|
-
ZodIntersection.prototype._parse = function (ctx, data, parsedType) {
|
|
1941
|
-
var handleParsed = function (parsedLeft, parsedRight) {
|
|
1942
|
-
if (isInvalid(parsedLeft) || isInvalid(parsedRight)) {
|
|
1943
|
-
return INVALID;
|
|
1944
|
-
}
|
|
1945
|
-
var merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
1946
|
-
if (!merged.valid) {
|
|
1947
|
-
ctx.addIssue(data, {
|
|
1948
|
-
code: ZodIssueCode.invalid_intersection_types,
|
|
1949
|
-
});
|
|
1950
|
-
return INVALID;
|
|
1951
|
-
}
|
|
1952
|
-
return OK(merged.data);
|
|
1953
|
-
};
|
|
1954
|
-
if (ctx.params.async) {
|
|
1955
|
-
return PseudoPromise.all([
|
|
1956
|
-
this._def.left._parse(ctx, data, parsedType),
|
|
1957
|
-
this._def.right._parse(ctx, data, parsedType),
|
|
1958
|
-
]).then(function (_a) {
|
|
1959
|
-
var _b = __read(_a, 2), left = _b[0], right = _b[1];
|
|
1960
|
-
return handleParsed(left, right);
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
else {
|
|
1964
|
-
return handleParsed(this._def.left._parseSync(ctx, data, parsedType), this._def.right._parseSync(ctx, data, parsedType));
|
|
1965
|
-
}
|
|
1966
|
-
};
|
|
1967
|
-
ZodIntersection.create = function (left, right) {
|
|
1968
|
-
return new ZodIntersection({
|
|
1969
|
-
left: left,
|
|
1970
|
-
right: right,
|
|
1971
|
-
});
|
|
1972
|
-
};
|
|
1973
|
-
return ZodIntersection;
|
|
1974
|
-
}(ZodType));
|
|
1975
|
-
var ZodTuple = /** @class */ (function (_super) {
|
|
1976
|
-
__extends(ZodTuple, _super);
|
|
1977
|
-
function ZodTuple() {
|
|
1978
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1979
|
-
}
|
|
1980
|
-
ZodTuple.prototype._parse = function (ctx, data, parsedType) {
|
|
1981
|
-
if (parsedType !== ZodParsedType.array) {
|
|
1982
|
-
ctx.addIssue(data, {
|
|
1983
|
-
code: ZodIssueCode.invalid_type,
|
|
1984
|
-
expected: ZodParsedType.array,
|
|
1985
|
-
received: parsedType,
|
|
1986
|
-
});
|
|
1987
|
-
return INVALID;
|
|
1988
|
-
}
|
|
1989
|
-
if (data.length > this._def.items.length) {
|
|
1990
|
-
ctx.addIssue(data, {
|
|
1991
|
-
code: ZodIssueCode.too_big,
|
|
1992
|
-
maximum: this._def.items.length,
|
|
1993
|
-
inclusive: true,
|
|
1994
|
-
type: "array",
|
|
1995
|
-
});
|
|
1996
|
-
return INVALID;
|
|
1997
|
-
}
|
|
1998
|
-
else if (data.length < this._def.items.length) {
|
|
1999
|
-
ctx.addIssue(data, {
|
|
2000
|
-
code: ZodIssueCode.too_small,
|
|
2001
|
-
minimum: this._def.items.length,
|
|
2002
|
-
inclusive: true,
|
|
2003
|
-
type: "array",
|
|
2004
|
-
});
|
|
2005
|
-
return INVALID;
|
|
2006
|
-
}
|
|
2007
|
-
var tasks = createTasks(ctx);
|
|
2008
|
-
var items = this._def.items;
|
|
2009
|
-
var parseResult = new Array(items.length);
|
|
2010
|
-
var invalid = false;
|
|
2011
|
-
var handleParsed = function (index, parsedItem) {
|
|
2012
|
-
if (isOk(parsedItem)) {
|
|
2013
|
-
parseResult[index] = parsedItem.value;
|
|
2014
|
-
}
|
|
2015
|
-
else if (isInvalid(parsedItem)) {
|
|
2016
|
-
invalid = true;
|
|
2017
|
-
}
|
|
2018
|
-
else {
|
|
2019
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(index, parsed); }));
|
|
2020
|
-
}
|
|
2021
|
-
};
|
|
2022
|
-
items.forEach(function (item, index) {
|
|
2023
|
-
handleParsed(index, item._parse(ctx.stepInto(index), data[index], getParsedType(data[index])));
|
|
2024
|
-
});
|
|
2025
|
-
if (tasks !== null && tasks.length > 0) {
|
|
2026
|
-
return ASYNC(Promise.all(tasks).then(function () { return (invalid ? INVALID : OK(parseResult)); }));
|
|
2027
|
-
}
|
|
2028
|
-
else {
|
|
2029
|
-
return invalid ? INVALID : OK(parseResult);
|
|
2030
|
-
}
|
|
2031
|
-
};
|
|
2032
|
-
Object.defineProperty(ZodTuple.prototype, "items", {
|
|
2033
|
-
get: function () {
|
|
2034
|
-
return this._def.items;
|
|
2035
|
-
},
|
|
2036
|
-
enumerable: false,
|
|
2037
|
-
configurable: true
|
|
2038
|
-
});
|
|
2039
|
-
ZodTuple.create = function (schemas) {
|
|
2040
|
-
return new ZodTuple({
|
|
2041
|
-
items: schemas,
|
|
2042
|
-
});
|
|
2043
|
-
};
|
|
2044
|
-
return ZodTuple;
|
|
2045
|
-
}(ZodType));
|
|
2046
|
-
var ZodRecord = /** @class */ (function (_super) {
|
|
2047
|
-
__extends(ZodRecord, _super);
|
|
2048
|
-
function ZodRecord() {
|
|
2049
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2050
|
-
}
|
|
2051
|
-
ZodRecord.prototype._parse = function (ctx, data, parsedType) {
|
|
2052
|
-
if (parsedType !== ZodParsedType.object) {
|
|
2053
|
-
ctx.addIssue(data, {
|
|
2054
|
-
code: ZodIssueCode.invalid_type,
|
|
2055
|
-
expected: ZodParsedType.object,
|
|
2056
|
-
received: parsedType,
|
|
2057
|
-
});
|
|
2058
|
-
return INVALID;
|
|
2059
|
-
}
|
|
2060
|
-
var tasks = createTasks(ctx);
|
|
2061
|
-
var valueType = this._def.valueType;
|
|
2062
|
-
var parseResult = {};
|
|
2063
|
-
var invalid = false;
|
|
2064
|
-
var handleParsed = function (key, parsedKey) {
|
|
2065
|
-
if (isOk(parsedKey)) {
|
|
2066
|
-
parseResult[key] = parsedKey.value;
|
|
2067
|
-
}
|
|
2068
|
-
else if (isInvalid(parsedKey)) {
|
|
2069
|
-
invalid = true;
|
|
2070
|
-
}
|
|
2071
|
-
else {
|
|
2072
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedKey.promise.then(function (parsed) { return handleParsed(key, parsed); }));
|
|
2073
|
-
}
|
|
2074
|
-
};
|
|
2075
|
-
for (var key in data) {
|
|
2076
|
-
handleParsed(key, valueType._parse(ctx.stepInto(key), data[key], getParsedType(data[key])));
|
|
2077
|
-
}
|
|
2078
|
-
if (tasks !== null && tasks.length > 0) {
|
|
2079
|
-
return ASYNC(Promise.all(tasks).then(function () { return (invalid ? INVALID : OK(parseResult)); }));
|
|
2080
|
-
}
|
|
2081
|
-
else {
|
|
2082
|
-
return invalid ? INVALID : OK(parseResult);
|
|
2083
|
-
}
|
|
2084
|
-
};
|
|
2085
|
-
ZodRecord.create = function (valueType) {
|
|
2086
|
-
return new ZodRecord({
|
|
2087
|
-
valueType: valueType,
|
|
2088
|
-
});
|
|
2089
|
-
};
|
|
2090
|
-
return ZodRecord;
|
|
2091
|
-
}(ZodType));
|
|
2092
|
-
var ZodMap = /** @class */ (function (_super) {
|
|
2093
|
-
__extends(ZodMap, _super);
|
|
2094
|
-
function ZodMap() {
|
|
2095
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2096
|
-
}
|
|
2097
|
-
ZodMap.prototype._parse = function (ctx, data, parsedType) {
|
|
2098
|
-
if (parsedType !== ZodParsedType.map) {
|
|
2099
|
-
ctx.addIssue(data, {
|
|
2100
|
-
code: ZodIssueCode.invalid_type,
|
|
2101
|
-
expected: ZodParsedType.map,
|
|
2102
|
-
received: parsedType,
|
|
2103
|
-
});
|
|
2104
|
-
return INVALID;
|
|
2105
|
-
}
|
|
2106
|
-
var keyType = this._def.keyType;
|
|
2107
|
-
var valueType = this._def.valueType;
|
|
2108
|
-
var dataMap = data;
|
|
2109
|
-
var parseResult = new Map();
|
|
2110
|
-
var tasks = createTasks(ctx);
|
|
2111
|
-
var invalid = false;
|
|
2112
|
-
var handleParsed = function (parsedKey, parsedValue) {
|
|
2113
|
-
if (isAsync(parsedKey) || isAsync(parsedValue)) {
|
|
2114
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(PseudoPromise.all([parsedKey, parsedValue]).promise.then(function (_a) {
|
|
2115
|
-
var _b = __read(_a, 2), k = _b[0], v = _b[1];
|
|
2116
|
-
return handleParsed(k, v);
|
|
2117
|
-
}));
|
|
2118
|
-
}
|
|
2119
|
-
else if (isInvalid(parsedKey) || isInvalid(parsedValue)) {
|
|
2120
|
-
invalid = true;
|
|
2121
|
-
}
|
|
2122
|
-
else {
|
|
2123
|
-
parseResult.set(parsedKey.value, parsedValue.value);
|
|
2124
|
-
}
|
|
2125
|
-
};
|
|
2126
|
-
__spreadArray([], __read(dataMap.entries())).forEach(function (_a, index) {
|
|
2127
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
2128
|
-
var entryCtx = ctx.stepInto(index);
|
|
2129
|
-
var parsedKey = keyType._parse(entryCtx.stepInto("key"), key, getParsedType(key));
|
|
2130
|
-
var parsedValue = valueType._parse(entryCtx.stepInto("value"), value, getParsedType(value));
|
|
2131
|
-
handleParsed(parsedKey, parsedValue);
|
|
2132
|
-
});
|
|
2133
|
-
if (tasks !== null && tasks.length > 0) {
|
|
2134
|
-
return ASYNC(Promise.all(tasks).then(function () { return (invalid ? INVALID : OK(parseResult)); }));
|
|
2135
|
-
}
|
|
2136
|
-
else {
|
|
2137
|
-
return invalid ? INVALID : OK(parseResult);
|
|
2138
|
-
}
|
|
2139
|
-
};
|
|
2140
|
-
ZodMap.create = function (keyType, valueType) {
|
|
2141
|
-
return new ZodMap({
|
|
2142
|
-
valueType: valueType,
|
|
2143
|
-
keyType: keyType,
|
|
2144
|
-
});
|
|
2145
|
-
};
|
|
2146
|
-
return ZodMap;
|
|
2147
|
-
}(ZodType));
|
|
2148
|
-
var ZodSet = /** @class */ (function (_super) {
|
|
2149
|
-
__extends(ZodSet, _super);
|
|
2150
|
-
function ZodSet() {
|
|
2151
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2152
|
-
}
|
|
2153
|
-
ZodSet.prototype._parse = function (ctx, data, parsedType) {
|
|
2154
|
-
if (parsedType !== ZodParsedType.set) {
|
|
2155
|
-
ctx.addIssue(data, {
|
|
2156
|
-
code: ZodIssueCode.invalid_type,
|
|
2157
|
-
expected: ZodParsedType.set,
|
|
2158
|
-
received: parsedType,
|
|
2159
|
-
});
|
|
2160
|
-
return INVALID;
|
|
2161
|
-
}
|
|
2162
|
-
var dataSet = data;
|
|
2163
|
-
var valueType = this._def.valueType;
|
|
2164
|
-
var parsedSet = new Set();
|
|
2165
|
-
var tasks = createTasks(ctx);
|
|
2166
|
-
var invalid = false;
|
|
2167
|
-
var handleParsed = function (parsedItem) {
|
|
2168
|
-
if (isOk(parsedItem)) {
|
|
2169
|
-
parsedSet.add(parsedItem.value);
|
|
2170
|
-
}
|
|
2171
|
-
else if (isInvalid(parsedItem)) {
|
|
2172
|
-
invalid = true;
|
|
2173
|
-
}
|
|
2174
|
-
else {
|
|
2175
|
-
tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(parsed); }));
|
|
2176
|
-
}
|
|
2177
|
-
};
|
|
2178
|
-
__spreadArray([], __read(dataSet.values())).forEach(function (item, i) {
|
|
2179
|
-
return handleParsed(valueType._parse(ctx.stepInto(i), item, getParsedType(item)));
|
|
2180
|
-
});
|
|
2181
|
-
if (tasks !== null && tasks.length > 0) {
|
|
2182
|
-
return ASYNC(Promise.all(tasks).then(function () { return (invalid ? INVALID : OK(parsedSet)); }));
|
|
2183
|
-
}
|
|
2184
|
-
else {
|
|
2185
|
-
return invalid ? INVALID : OK(parsedSet);
|
|
2186
|
-
}
|
|
2187
|
-
};
|
|
2188
|
-
ZodSet.create = function (valueType) {
|
|
2189
|
-
return new ZodSet({
|
|
2190
|
-
valueType: valueType,
|
|
2191
|
-
});
|
|
2192
|
-
};
|
|
2193
|
-
return ZodSet;
|
|
2194
|
-
}(ZodType));
|
|
2195
|
-
var ZodFunction = /** @class */ (function (_super) {
|
|
2196
|
-
__extends(ZodFunction, _super);
|
|
2197
|
-
function ZodFunction() {
|
|
2198
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2199
|
-
_this.args = function () {
|
|
2200
|
-
var items = [];
|
|
2201
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2202
|
-
items[_i] = arguments[_i];
|
|
2203
|
-
}
|
|
2204
|
-
return new ZodFunction(__assign(__assign({}, _this._def), { args: ZodTuple.create(items) }));
|
|
2205
|
-
};
|
|
2206
|
-
_this.returns = function (returnType) {
|
|
2207
|
-
return new ZodFunction(__assign(__assign({}, _this._def), { returns: returnType }));
|
|
2208
|
-
};
|
|
2209
|
-
_this.implement = function (func) {
|
|
2210
|
-
var validatedFunc = _this.parse(func);
|
|
2211
|
-
return validatedFunc;
|
|
2212
|
-
};
|
|
2213
|
-
_this.strictImplement = function (func) {
|
|
2214
|
-
var validatedFunc = _this.parse(func);
|
|
2215
|
-
return validatedFunc;
|
|
2216
|
-
};
|
|
2217
|
-
_this.validate = _this.implement;
|
|
2218
|
-
return _this;
|
|
2219
|
-
}
|
|
2220
|
-
ZodFunction.prototype._parse = function (ctx, data, parsedType) {
|
|
2221
|
-
var _this = this;
|
|
2222
|
-
if (parsedType !== ZodParsedType.function) {
|
|
2223
|
-
ctx.addIssue(data, {
|
|
2224
|
-
code: ZodIssueCode.invalid_type,
|
|
2225
|
-
expected: ZodParsedType.function,
|
|
2226
|
-
received: parsedType,
|
|
2227
|
-
});
|
|
2228
|
-
return INVALID;
|
|
2229
|
-
}
|
|
2230
|
-
var handleArgs = function (args, parsedArgs) {
|
|
2231
|
-
if (!parsedArgs.success) {
|
|
2232
|
-
var issue = makeIssue(args, pathToArray(ctx.path), ctx.params.errorMap, {
|
|
2233
|
-
code: ZodIssueCode.invalid_arguments,
|
|
2234
|
-
argumentsError: parsedArgs.error,
|
|
2235
|
-
});
|
|
2236
|
-
throw new ZodError([issue]);
|
|
2237
|
-
}
|
|
2238
|
-
return parsedArgs.data;
|
|
2239
|
-
};
|
|
2240
|
-
var handleReturns = function (returns, parsedReturns) {
|
|
2241
|
-
if (!parsedReturns.success) {
|
|
2242
|
-
var issue = makeIssue(returns, pathToArray(ctx.path), ctx.params.errorMap, {
|
|
2243
|
-
code: ZodIssueCode.invalid_return_type,
|
|
2244
|
-
returnTypeError: parsedReturns.error,
|
|
2245
|
-
});
|
|
2246
|
-
throw new ZodError([issue]);
|
|
2247
|
-
}
|
|
2248
|
-
return parsedReturns.data;
|
|
2249
|
-
};
|
|
2250
|
-
var params = { errorMap: ctx.params.errorMap };
|
|
2251
|
-
var fn = data;
|
|
2252
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
2253
|
-
return OK(function () {
|
|
2254
|
-
var args = [];
|
|
2255
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2256
|
-
args[_i] = arguments[_i];
|
|
2257
|
-
}
|
|
2258
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
2259
|
-
var parsedArgs, _a, _b, result, _c, _d;
|
|
2260
|
-
return __generator(this, function (_e) {
|
|
2261
|
-
switch (_e.label) {
|
|
2262
|
-
case 0:
|
|
2263
|
-
_a = handleArgs;
|
|
2264
|
-
_b = [args];
|
|
2265
|
-
return [4 /*yield*/, this._def.args.spa(args, params)];
|
|
2266
|
-
case 1:
|
|
2267
|
-
parsedArgs = _a.apply(void 0, _b.concat([_e.sent()]));
|
|
2268
|
-
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs)))];
|
|
2269
|
-
case 2:
|
|
2270
|
-
result = _e.sent();
|
|
2271
|
-
_c = handleReturns;
|
|
2272
|
-
_d = [result];
|
|
2273
|
-
return [4 /*yield*/, this._def.returns.spa(result, params)];
|
|
2274
|
-
case 3: return [2 /*return*/, _c.apply(void 0, _d.concat([_e.sent()]))];
|
|
2275
|
-
}
|
|
2276
|
-
});
|
|
2277
|
-
});
|
|
2278
|
-
});
|
|
2279
|
-
}
|
|
2280
|
-
else {
|
|
2281
|
-
return OK(function () {
|
|
2282
|
-
var args = [];
|
|
2283
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2284
|
-
args[_i] = arguments[_i];
|
|
2285
|
-
}
|
|
2286
|
-
var parsedArgs = handleArgs(args, _this._def.args.safeParse(args, params));
|
|
2287
|
-
var result = fn.apply(void 0, __spreadArray([], __read(parsedArgs)));
|
|
2288
|
-
return handleReturns(result, _this._def.returns.safeParse(result, params));
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
};
|
|
2292
|
-
ZodFunction.prototype.parameters = function () {
|
|
2293
|
-
return this._def.args;
|
|
2294
|
-
};
|
|
2295
|
-
ZodFunction.prototype.returnType = function () {
|
|
2296
|
-
return this._def.returns;
|
|
2297
|
-
};
|
|
2298
|
-
ZodFunction.create = function (args, returns) {
|
|
2299
|
-
return new ZodFunction({
|
|
2300
|
-
args: args || ZodTuple.create([]),
|
|
2301
|
-
returns: returns || ZodUnknown.create(),
|
|
2302
|
-
});
|
|
2303
|
-
};
|
|
2304
|
-
return ZodFunction;
|
|
2305
|
-
}(ZodType));
|
|
2306
|
-
var ZodLazy = /** @class */ (function (_super) {
|
|
2307
|
-
__extends(ZodLazy, _super);
|
|
2308
|
-
function ZodLazy() {
|
|
2309
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2310
|
-
}
|
|
2311
|
-
Object.defineProperty(ZodLazy.prototype, "schema", {
|
|
2312
|
-
get: function () {
|
|
2313
|
-
return this._def.getter();
|
|
2314
|
-
},
|
|
2315
|
-
enumerable: false,
|
|
2316
|
-
configurable: true
|
|
2317
|
-
});
|
|
2318
|
-
ZodLazy.prototype._parse = function (ctx, data, parsedType) {
|
|
2319
|
-
var lazySchema = this._def.getter();
|
|
2320
|
-
return lazySchema._parse(ctx, data, parsedType);
|
|
2321
|
-
};
|
|
2322
|
-
ZodLazy.create = function (getter) {
|
|
2323
|
-
return new ZodLazy({
|
|
2324
|
-
getter: getter,
|
|
2325
|
-
});
|
|
2326
|
-
};
|
|
2327
|
-
return ZodLazy;
|
|
2328
|
-
}(ZodType));
|
|
2329
|
-
var ZodLiteral = /** @class */ (function (_super) {
|
|
2330
|
-
__extends(ZodLiteral, _super);
|
|
2331
|
-
function ZodLiteral() {
|
|
2332
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2333
|
-
}
|
|
2334
|
-
ZodLiteral.prototype._parse = function (ctx, data, _parsedType) {
|
|
2335
|
-
if (data !== this._def.value) {
|
|
2336
|
-
ctx.addIssue(data, {
|
|
2337
|
-
code: ZodIssueCode.invalid_type,
|
|
2338
|
-
expected: this._def.value,
|
|
2339
|
-
received: data,
|
|
2340
|
-
});
|
|
2341
|
-
return INVALID;
|
|
2342
|
-
}
|
|
2343
|
-
return OK(data);
|
|
2344
|
-
};
|
|
2345
|
-
ZodLiteral.create = function (value) {
|
|
2346
|
-
return new ZodLiteral({
|
|
2347
|
-
value: value,
|
|
2348
|
-
});
|
|
2349
|
-
};
|
|
2350
|
-
return ZodLiteral;
|
|
2351
|
-
}(ZodType));
|
|
2352
|
-
var ZodEnum = /** @class */ (function (_super) {
|
|
2353
|
-
__extends(ZodEnum, _super);
|
|
2354
|
-
function ZodEnum() {
|
|
2355
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2356
|
-
}
|
|
2357
|
-
ZodEnum.prototype._parse = function (ctx, data, _parsedType) {
|
|
2358
|
-
if (this._def.values.indexOf(data) === -1) {
|
|
2359
|
-
ctx.addIssue(data, {
|
|
2360
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
2361
|
-
options: this._def.values,
|
|
2362
|
-
});
|
|
2363
|
-
return INVALID;
|
|
2364
|
-
}
|
|
2365
|
-
return OK(data);
|
|
2366
|
-
};
|
|
2367
|
-
Object.defineProperty(ZodEnum.prototype, "options", {
|
|
2368
|
-
get: function () {
|
|
2369
|
-
return this._def.values;
|
|
2370
|
-
},
|
|
2371
|
-
enumerable: false,
|
|
2372
|
-
configurable: true
|
|
2373
|
-
});
|
|
2374
|
-
Object.defineProperty(ZodEnum.prototype, "enum", {
|
|
2375
|
-
get: function () {
|
|
2376
|
-
var e_12, _a;
|
|
2377
|
-
var enumValues = {};
|
|
2378
|
-
try {
|
|
2379
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2380
|
-
var val = _c.value;
|
|
2381
|
-
enumValues[val] = val;
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2385
|
-
finally {
|
|
2386
|
-
try {
|
|
2387
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2388
|
-
}
|
|
2389
|
-
finally { if (e_12) throw e_12.error; }
|
|
2390
|
-
}
|
|
2391
|
-
return enumValues;
|
|
2392
|
-
},
|
|
2393
|
-
enumerable: false,
|
|
2394
|
-
configurable: true
|
|
2395
|
-
});
|
|
2396
|
-
Object.defineProperty(ZodEnum.prototype, "Values", {
|
|
2397
|
-
get: function () {
|
|
2398
|
-
var e_13, _a;
|
|
2399
|
-
var enumValues = {};
|
|
2400
|
-
try {
|
|
2401
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2402
|
-
var val = _c.value;
|
|
2403
|
-
enumValues[val] = val;
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
2407
|
-
finally {
|
|
2408
|
-
try {
|
|
2409
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2410
|
-
}
|
|
2411
|
-
finally { if (e_13) throw e_13.error; }
|
|
2412
|
-
}
|
|
2413
|
-
return enumValues;
|
|
2414
|
-
},
|
|
2415
|
-
enumerable: false,
|
|
2416
|
-
configurable: true
|
|
2417
|
-
});
|
|
2418
|
-
Object.defineProperty(ZodEnum.prototype, "Enum", {
|
|
2419
|
-
get: function () {
|
|
2420
|
-
var e_14, _a;
|
|
2421
|
-
var enumValues = {};
|
|
2422
|
-
try {
|
|
2423
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2424
|
-
var val = _c.value;
|
|
2425
|
-
enumValues[val] = val;
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2429
|
-
finally {
|
|
2430
|
-
try {
|
|
2431
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2432
|
-
}
|
|
2433
|
-
finally { if (e_14) throw e_14.error; }
|
|
2434
|
-
}
|
|
2435
|
-
return enumValues;
|
|
2436
|
-
},
|
|
2437
|
-
enumerable: false,
|
|
2438
|
-
configurable: true
|
|
2439
|
-
});
|
|
2440
|
-
ZodEnum.create = function (values) {
|
|
2441
|
-
return new ZodEnum({
|
|
2442
|
-
values: values,
|
|
2443
|
-
});
|
|
2444
|
-
};
|
|
2445
|
-
return ZodEnum;
|
|
2446
|
-
}(ZodType));
|
|
2447
|
-
var ZodNativeEnum = /** @class */ (function (_super) {
|
|
2448
|
-
__extends(ZodNativeEnum, _super);
|
|
2449
|
-
function ZodNativeEnum() {
|
|
2450
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2451
|
-
}
|
|
2452
|
-
ZodNativeEnum.prototype._parse = function (ctx, data, _parsedType) {
|
|
2453
|
-
var nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
2454
|
-
if (nativeEnumValues.indexOf(data) === -1) {
|
|
2455
|
-
ctx.addIssue(data, {
|
|
2456
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
2457
|
-
options: util.objectValues(nativeEnumValues),
|
|
2458
|
-
});
|
|
2459
|
-
return INVALID;
|
|
2460
|
-
}
|
|
2461
|
-
return OK(data);
|
|
2462
|
-
};
|
|
2463
|
-
ZodNativeEnum.create = function (values) {
|
|
2464
|
-
return new ZodNativeEnum({
|
|
2465
|
-
values: values,
|
|
2466
|
-
});
|
|
2467
|
-
};
|
|
2468
|
-
return ZodNativeEnum;
|
|
2469
|
-
}(ZodType));
|
|
2470
|
-
var ZodPromise = /** @class */ (function (_super) {
|
|
2471
|
-
__extends(ZodPromise, _super);
|
|
2472
|
-
function ZodPromise() {
|
|
2473
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2474
|
-
}
|
|
2475
|
-
ZodPromise.prototype._parse = function (ctx, data, parsedType) {
|
|
2476
|
-
var _this = this;
|
|
2477
|
-
if (parsedType !== ZodParsedType.promise && ctx.params.async === false) {
|
|
2478
|
-
ctx.addIssue(data, {
|
|
2479
|
-
code: ZodIssueCode.invalid_type,
|
|
2480
|
-
expected: ZodParsedType.promise,
|
|
2481
|
-
received: parsedType,
|
|
2482
|
-
});
|
|
2483
|
-
return INVALID;
|
|
2484
|
-
}
|
|
2485
|
-
var promisified = parsedType === ZodParsedType.promise ? data : Promise.resolve(data);
|
|
2486
|
-
return OK(promisified.then(function (data) {
|
|
2487
|
-
return _this._def.type.parseAsync(data, {
|
|
2488
|
-
path: pathToArray(ctx.path),
|
|
2489
|
-
errorMap: ctx.params.errorMap,
|
|
2490
|
-
});
|
|
2491
|
-
}));
|
|
2492
|
-
};
|
|
2493
|
-
ZodPromise.create = function (schema) {
|
|
2494
|
-
return new ZodPromise({
|
|
2495
|
-
type: schema,
|
|
2496
|
-
});
|
|
2497
|
-
};
|
|
2498
|
-
return ZodPromise;
|
|
2499
|
-
}(ZodType));
|
|
2500
|
-
var ZodEffects = /** @class */ (function (_super) {
|
|
2501
|
-
__extends(ZodEffects, _super);
|
|
2502
|
-
function ZodEffects(def) {
|
|
2503
|
-
return _super.call(this, def) || this;
|
|
2504
|
-
// if (def.schema instanceof ZodEffects) {
|
|
2505
|
-
// throw new Error("ZodEffects cannot be nested.");
|
|
2506
|
-
// }
|
|
2507
|
-
}
|
|
2508
|
-
ZodEffects.prototype.innerType = function () {
|
|
2509
|
-
return this._def.schema;
|
|
2510
|
-
};
|
|
2511
|
-
ZodEffects.prototype._parse = function (ctx, data, parsedType) {
|
|
2512
|
-
var isSync = ctx.params.async === false;
|
|
2513
|
-
var effects = this._def.effects || [];
|
|
2514
|
-
var checkCtx = {
|
|
2515
|
-
addIssue: function (arg) {
|
|
2516
|
-
ctx.addIssue(data, arg);
|
|
2517
|
-
},
|
|
2518
|
-
get path() {
|
|
2519
|
-
return pathToArray(ctx.path);
|
|
2520
|
-
},
|
|
2521
|
-
};
|
|
2522
|
-
var invalid = false;
|
|
2523
|
-
var applyEffect = function (acc, effect) {
|
|
2524
|
-
switch (effect.type) {
|
|
2525
|
-
case "refinement":
|
|
2526
|
-
var result = effect.refinement(acc, checkCtx);
|
|
2527
|
-
if (result instanceof Promise) {
|
|
2528
|
-
if (isSync) {
|
|
2529
|
-
throw new Error("You can't use .parse() on a schema containing async refinements. Use .parseAsync instead.");
|
|
2530
|
-
}
|
|
2531
|
-
else {
|
|
2532
|
-
return result.then(function (res) {
|
|
2533
|
-
invalid = invalid || !res;
|
|
2534
|
-
return acc;
|
|
2535
|
-
});
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
else {
|
|
2539
|
-
invalid = invalid || !result;
|
|
2540
|
-
return acc;
|
|
2541
|
-
}
|
|
2542
|
-
case "transform":
|
|
2543
|
-
var transformed = effect.transform(acc);
|
|
2544
|
-
if (transformed instanceof Promise && isSync) {
|
|
2545
|
-
throw new Error("You can't use .parse() on a schema containing async transformations. Use .parseAsync instead.");
|
|
2546
|
-
}
|
|
2547
|
-
return transformed;
|
|
2548
|
-
default:
|
|
2549
|
-
throw new Error("Invalid effect type.");
|
|
2550
|
-
}
|
|
2551
|
-
};
|
|
2552
|
-
if (isSync) {
|
|
2553
|
-
var base = this._def.schema._parseSync(ctx, data, parsedType);
|
|
2554
|
-
if (isOk(base)) {
|
|
2555
|
-
var result = effects.reduce(applyEffect, base.value);
|
|
2556
|
-
return invalid ? INVALID : OK(result);
|
|
2557
|
-
}
|
|
2558
|
-
else {
|
|
2559
|
-
return INVALID;
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
else {
|
|
2563
|
-
var applyAsyncEffects_1 = function (base) {
|
|
2564
|
-
var result = effects.reduce(function (acc, eff) {
|
|
2565
|
-
return acc instanceof Promise
|
|
2566
|
-
? acc.then(function (val) { return applyEffect(val, eff); })
|
|
2567
|
-
: applyEffect(acc, eff);
|
|
2568
|
-
}, base);
|
|
2569
|
-
if (result instanceof Promise) {
|
|
2570
|
-
return ASYNC(result.then(function (val) { return (invalid ? INVALID : OK(val)); }));
|
|
2571
|
-
}
|
|
2572
|
-
else {
|
|
2573
|
-
return invalid ? INVALID : OK(result);
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
var baseResult = this._def.schema._parse(ctx, data, parsedType);
|
|
2577
|
-
if (isOk(baseResult)) {
|
|
2578
|
-
return applyAsyncEffects_1(baseResult.value);
|
|
2579
|
-
}
|
|
2580
|
-
else if (isInvalid(baseResult)) {
|
|
2581
|
-
return INVALID;
|
|
2582
|
-
}
|
|
2583
|
-
else {
|
|
2584
|
-
return ASYNC(baseResult.promise.then(function (base) {
|
|
2585
|
-
if (isInvalid(base))
|
|
2586
|
-
return INVALID;
|
|
2587
|
-
var result = applyAsyncEffects_1(base.value);
|
|
2588
|
-
return isAsync(result) ? result.promise : result;
|
|
2589
|
-
}));
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
};
|
|
2593
|
-
ZodEffects.create = function (schema) {
|
|
2594
|
-
var newTx = new ZodEffects({
|
|
2595
|
-
schema: schema,
|
|
2596
|
-
});
|
|
2597
|
-
return newTx;
|
|
2598
|
-
};
|
|
2599
|
-
return ZodEffects;
|
|
2600
|
-
}(ZodType));
|
|
2601
|
-
var ZodOptional = /** @class */ (function (_super) {
|
|
2602
|
-
__extends(ZodOptional, _super);
|
|
2603
|
-
function ZodOptional() {
|
|
2604
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2605
|
-
}
|
|
2606
|
-
ZodOptional.prototype._parse = function (ctx, data, parsedType) {
|
|
2607
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
2608
|
-
return OK(undefined);
|
|
2609
|
-
}
|
|
2610
|
-
return this._def.innerType._parse(ctx, data, parsedType);
|
|
2611
|
-
};
|
|
2612
|
-
ZodOptional.prototype.unwrap = function () {
|
|
2613
|
-
return this._def.innerType;
|
|
2614
|
-
};
|
|
2615
|
-
ZodOptional.create = function (type) {
|
|
2616
|
-
return new ZodOptional({
|
|
2617
|
-
innerType: type,
|
|
2618
|
-
});
|
|
2619
|
-
};
|
|
2620
|
-
return ZodOptional;
|
|
2621
|
-
}(ZodType));
|
|
2622
|
-
var ZodNullable = /** @class */ (function (_super) {
|
|
2623
|
-
__extends(ZodNullable, _super);
|
|
2624
|
-
function ZodNullable() {
|
|
2625
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2626
|
-
}
|
|
2627
|
-
ZodNullable.prototype._parse = function (ctx, data, parsedType) {
|
|
2628
|
-
if (parsedType === ZodParsedType.null) {
|
|
2629
|
-
return OK(null);
|
|
2630
|
-
}
|
|
2631
|
-
return this._def.innerType._parse(ctx, data, parsedType);
|
|
2632
|
-
};
|
|
2633
|
-
ZodNullable.prototype.unwrap = function () {
|
|
2634
|
-
return this._def.innerType;
|
|
2635
|
-
};
|
|
2636
|
-
ZodNullable.create = function (type) {
|
|
2637
|
-
return new ZodNullable({
|
|
2638
|
-
innerType: type,
|
|
2639
|
-
});
|
|
2640
|
-
};
|
|
2641
|
-
return ZodNullable;
|
|
2642
|
-
}(ZodType));
|
|
2643
|
-
var ZodDefault = /** @class */ (function (_super) {
|
|
2644
|
-
__extends(ZodDefault, _super);
|
|
2645
|
-
function ZodDefault() {
|
|
2646
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2647
|
-
}
|
|
2648
|
-
ZodDefault.prototype._parse = function (ctx, data, parsedType) {
|
|
2649
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
2650
|
-
data = this._def.defaultValue();
|
|
2651
|
-
}
|
|
2652
|
-
return this._def.innerType._parse(ctx, data, getParsedType(data));
|
|
2653
|
-
};
|
|
2654
|
-
ZodDefault.prototype.removeDefault = function () {
|
|
2655
|
-
return this._def.innerType;
|
|
2656
|
-
};
|
|
2657
|
-
ZodDefault.create = function (type) {
|
|
2658
|
-
return new ZodOptional({
|
|
2659
|
-
innerType: type,
|
|
2660
|
-
});
|
|
2661
|
-
};
|
|
2662
|
-
return ZodDefault;
|
|
2663
|
-
}(ZodType));
|
|
2664
|
-
var custom = function (check, params) {
|
|
2665
|
-
if (check)
|
|
2666
|
-
return ZodAny.create().refine(check, params);
|
|
2667
|
-
return ZodAny.create();
|
|
2668
|
-
};
|
|
2669
|
-
var late = {
|
|
2670
|
-
object: ZodObject.lazycreate,
|
|
2671
|
-
};
|
|
2672
|
-
var instanceOfType = function (cls, params) {
|
|
2673
|
-
if (params === void 0) { params = {
|
|
2674
|
-
message: "Input not instance of " + cls.name,
|
|
2675
|
-
}; }
|
|
2676
|
-
return custom(function (data) { return data instanceof cls; }, params);
|
|
2677
|
-
};
|
|
2678
|
-
var stringType = ZodString.create;
|
|
2679
|
-
var numberType = ZodNumber.create;
|
|
2680
|
-
var bigIntType = ZodBigInt.create;
|
|
2681
|
-
var booleanType = ZodBoolean.create;
|
|
2682
|
-
var dateType = ZodDate.create;
|
|
2683
|
-
var undefinedType = ZodUndefined.create;
|
|
2684
|
-
var nullType = ZodNull.create;
|
|
2685
|
-
var anyType = ZodAny.create;
|
|
2686
|
-
var unknownType = ZodUnknown.create;
|
|
2687
|
-
var neverType = ZodNever.create;
|
|
2688
|
-
var voidType = ZodVoid.create;
|
|
2689
|
-
var arrayType = ZodArray.create;
|
|
2690
|
-
var objectType = ZodObject.create;
|
|
2691
|
-
var strictObjectType = ZodObject.strictCreate;
|
|
2692
|
-
var unionType = ZodUnion.create;
|
|
2693
|
-
var intersectionType = ZodIntersection.create;
|
|
2694
|
-
var tupleType = ZodTuple.create;
|
|
2695
|
-
var recordType = ZodRecord.create;
|
|
2696
|
-
var mapType = ZodMap.create;
|
|
2697
|
-
var setType = ZodSet.create;
|
|
2698
|
-
var functionType = ZodFunction.create;
|
|
2699
|
-
var lazyType = ZodLazy.create;
|
|
2700
|
-
var literalType = ZodLiteral.create;
|
|
2701
|
-
var enumType = ZodEnum.create;
|
|
2702
|
-
var nativeEnumType = ZodNativeEnum.create;
|
|
2703
|
-
var promiseType = ZodPromise.create;
|
|
2704
|
-
var effectsType = ZodEffects.create;
|
|
2705
|
-
var optionalType = ZodOptional.create;
|
|
2706
|
-
var nullableType = ZodNullable.create;
|
|
2707
|
-
var ostring = function () { return stringType().optional(); };
|
|
2708
|
-
var onumber = function () { return numberType().optional(); };
|
|
2709
|
-
var oboolean = function () { return booleanType().optional(); };
|
|
2710
|
-
|
|
2711
|
-
var external = /*#__PURE__*/Object.freeze({
|
|
2712
|
-
__proto__: null,
|
|
2713
|
-
ZodParsedType: ZodParsedType,
|
|
2714
|
-
getParsedType: getParsedType,
|
|
2715
|
-
makeIssue: makeIssue,
|
|
2716
|
-
EMPTY_PATH: EMPTY_PATH,
|
|
2717
|
-
pathToArray: pathToArray,
|
|
2718
|
-
pathFromArray: pathFromArray,
|
|
2719
|
-
ParseContext: ParseContext,
|
|
2720
|
-
createRootContext: createRootContext$1,
|
|
2721
|
-
INVALID: INVALID,
|
|
2722
|
-
OK: OK,
|
|
2723
|
-
ASYNC: ASYNC,
|
|
2724
|
-
isInvalid: isInvalid,
|
|
2725
|
-
isOk: isOk,
|
|
2726
|
-
isAsync: isAsync,
|
|
2727
|
-
ZodType: ZodType,
|
|
2728
|
-
ZodString: ZodString,
|
|
2729
|
-
ZodNumber: ZodNumber,
|
|
2730
|
-
ZodBigInt: ZodBigInt,
|
|
2731
|
-
ZodBoolean: ZodBoolean,
|
|
2732
|
-
ZodDate: ZodDate,
|
|
2733
|
-
ZodUndefined: ZodUndefined,
|
|
2734
|
-
ZodNull: ZodNull,
|
|
2735
|
-
ZodAny: ZodAny,
|
|
2736
|
-
ZodUnknown: ZodUnknown,
|
|
2737
|
-
ZodNever: ZodNever,
|
|
2738
|
-
ZodVoid: ZodVoid,
|
|
2739
|
-
ZodArray: ZodArray,
|
|
2740
|
-
ZodNonEmptyArray: ZodNonEmptyArray,
|
|
2741
|
-
get objectUtil () { return objectUtil; },
|
|
2742
|
-
mergeObjects: mergeObjects,
|
|
2743
|
-
ZodObject: ZodObject,
|
|
2744
|
-
ZodUnion: ZodUnion,
|
|
2745
|
-
ZodIntersection: ZodIntersection,
|
|
2746
|
-
ZodTuple: ZodTuple,
|
|
2747
|
-
ZodRecord: ZodRecord,
|
|
2748
|
-
ZodMap: ZodMap,
|
|
2749
|
-
ZodSet: ZodSet,
|
|
2750
|
-
ZodFunction: ZodFunction,
|
|
2751
|
-
ZodLazy: ZodLazy,
|
|
2752
|
-
ZodLiteral: ZodLiteral,
|
|
2753
|
-
ZodEnum: ZodEnum,
|
|
2754
|
-
ZodNativeEnum: ZodNativeEnum,
|
|
2755
|
-
ZodPromise: ZodPromise,
|
|
2756
|
-
ZodEffects: ZodEffects,
|
|
2757
|
-
ZodTransformer: ZodEffects,
|
|
2758
|
-
ZodOptional: ZodOptional,
|
|
2759
|
-
ZodNullable: ZodNullable,
|
|
2760
|
-
ZodDefault: ZodDefault,
|
|
2761
|
-
custom: custom,
|
|
2762
|
-
Schema: ZodType,
|
|
2763
|
-
ZodSchema: ZodType,
|
|
2764
|
-
late: late,
|
|
2765
|
-
any: anyType,
|
|
2766
|
-
array: arrayType,
|
|
2767
|
-
bigint: bigIntType,
|
|
2768
|
-
boolean: booleanType,
|
|
2769
|
-
date: dateType,
|
|
2770
|
-
effect: effectsType,
|
|
2771
|
-
'enum': enumType,
|
|
2772
|
-
'function': functionType,
|
|
2773
|
-
'instanceof': instanceOfType,
|
|
2774
|
-
intersection: intersectionType,
|
|
2775
|
-
lazy: lazyType,
|
|
2776
|
-
literal: literalType,
|
|
2777
|
-
map: mapType,
|
|
2778
|
-
nativeEnum: nativeEnumType,
|
|
2779
|
-
never: neverType,
|
|
2780
|
-
'null': nullType,
|
|
2781
|
-
nullable: nullableType,
|
|
2782
|
-
number: numberType,
|
|
2783
|
-
object: objectType,
|
|
2784
|
-
oboolean: oboolean,
|
|
2785
|
-
onumber: onumber,
|
|
2786
|
-
optional: optionalType,
|
|
2787
|
-
ostring: ostring,
|
|
2788
|
-
promise: promiseType,
|
|
2789
|
-
record: recordType,
|
|
2790
|
-
set: setType,
|
|
2791
|
-
strictObject: strictObjectType,
|
|
2792
|
-
string: stringType,
|
|
2793
|
-
transformer: effectsType,
|
|
2794
|
-
tuple: tupleType,
|
|
2795
|
-
'undefined': undefinedType,
|
|
2796
|
-
union: unionType,
|
|
2797
|
-
unknown: unknownType,
|
|
2798
|
-
'void': voidType,
|
|
2799
|
-
ZodIssueCode: ZodIssueCode,
|
|
2800
|
-
quotelessJson: quotelessJson,
|
|
2801
|
-
ZodError: ZodError,
|
|
2802
|
-
defaultErrorMap: defaultErrorMap,
|
|
2803
|
-
get overrideErrorMap () { return overrideErrorMap; },
|
|
2804
|
-
setErrorMap: setErrorMap
|
|
2805
|
-
});
|
|
2806
|
-
|
|
2807
|
-
export { ASYNC, EMPTY_PATH, INVALID, OK, ParseContext, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodEffects, ZodEnum, ZodError, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNativeEnum, ZodNever, ZodNonEmptyArray, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, createRootContext$1 as createRootContext, custom, dateType as date, defaultErrorMap, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAsync, isInvalid, isOk, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, mergeObjects, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, pathFromArray, pathToArray, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, external as z };
|
|
2808
|
-
//# sourceMappingURL=index.mjs.map
|