zod 3.13.4 → 3.14.2

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