zod 3.13.2 → 3.14.0

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,83 +273,72 @@ 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,
@@ -556,149 +347,79 @@ function addIssueToContext(ctx, issueData) {
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
352
  ctx.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
  }
@@ -706,20 +427,20 @@ var handleResult = function (ctx, result) {
706
427
  if (!ctx.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.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,81 @@ 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
+ _processInputParams(input) {
768
485
  return {
769
486
  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 }),
487
+ ctx: {
488
+ ...input.parent,
489
+ data: input.data,
490
+ parsedType: getParsedType(input.data),
491
+ schemaErrorMap: this._def.errorMap,
492
+ path: input.path,
493
+ parent: input.parent,
494
+ },
771
495
  };
772
- };
773
- ZodType.prototype._parseSync = function (input) {
774
- var result = this._parse(input);
496
+ }
497
+ _parseSync(input) {
498
+ const result = this._parse(input);
775
499
  if (isAsync(result)) {
776
500
  throw new Error("Synchronous parse encountered promise.");
777
501
  }
778
502
  return result;
779
- };
780
- ZodType.prototype._parseAsync = function (input) {
781
- var result = this._parse(input);
503
+ }
504
+ _parseAsync(input) {
505
+ const result = this._parse(input);
782
506
  return Promise.resolve(result);
783
- };
784
- ZodType.prototype.parse = function (data, params) {
785
- var result = this.safeParse(data, params);
507
+ }
508
+ parse(data, params) {
509
+ const result = this.safeParse(data, params);
786
510
  if (result.success)
787
511
  return result.data;
788
512
  throw result.error;
789
- };
790
- ZodType.prototype.safeParse = function (data, params) {
513
+ }
514
+ safeParse(data, params) {
791
515
  var _a;
792
- var ctx = {
516
+ const ctx = {
793
517
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
794
518
  issues: [],
795
519
  contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
796
520
  schemaErrorMap: this._def.errorMap,
797
521
  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
522
  parent: null,
800
- data: data,
523
+ data,
801
524
  parsedType: getParsedType(data),
802
525
  };
803
- var result = this._parseSync({ data: data, path: ctx.path, parent: ctx });
526
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
804
527
  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) {
528
+ }
529
+ async parseAsync(data, params) {
530
+ const result = await this.safeParseAsync(data, params);
531
+ if (result.success)
532
+ return result.data;
533
+ throw result.error;
534
+ }
535
+ async safeParseAsync(data, params) {
536
+ const ctx = {
537
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
538
+ issues: [],
539
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
540
+ schemaErrorMap: this._def.errorMap,
541
+ async: true,
542
+ parent: null,
543
+ data,
544
+ parsedType: getParsedType(data),
545
+ };
546
+ const maybeAsyncResult = this._parse({ data, path: [], parent: ctx });
547
+ const result = await (isAsync(maybeAsyncResult)
548
+ ? maybeAsyncResult
549
+ : Promise.resolve(maybeAsyncResult));
550
+ return handleResult(ctx, result);
551
+ }
552
+ refine(check, message) {
553
+ const getIssueProperties = (val) => {
851
554
  if (typeof message === "string" || typeof message === "undefined") {
852
- return { message: message };
555
+ return { message };
853
556
  }
854
557
  else if (typeof message === "function") {
855
558
  return message(val);
@@ -858,13 +561,14 @@ var ZodType = /** @class */ (function () {
858
561
  return message;
859
562
  }
860
563
  };
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
- };
564
+ return this._refinement((val, ctx) => {
565
+ const result = check(val);
566
+ const setError = () => ctx.addIssue({
567
+ code: ZodIssueCode.custom,
568
+ ...getIssueProperties(val),
569
+ });
866
570
  if (typeof Promise !== "undefined" && result instanceof Promise) {
867
- return result.then(function (data) {
571
+ return result.then((data) => {
868
572
  if (!data) {
869
573
  setError();
870
574
  return false;
@@ -882,9 +586,9 @@ var ZodType = /** @class */ (function () {
882
586
  return true;
883
587
  }
884
588
  });
885
- };
886
- ZodType.prototype.refinement = function (check, refinementData) {
887
- return this._refinement(function (val, ctx) {
589
+ }
590
+ refinement(check, refinementData) {
591
+ return this._refinement((val, ctx) => {
888
592
  if (!check(val)) {
889
593
  ctx.addIssue(typeof refinementData === "function"
890
594
  ? refinementData(val, ctx)
@@ -895,88 +599,87 @@ var ZodType = /** @class */ (function () {
895
599
  return true;
896
600
  }
897
601
  });
898
- };
899
- ZodType.prototype._refinement = function (refinement) {
602
+ }
603
+ _refinement(refinement) {
900
604
  return new ZodEffects({
901
605
  schema: this,
902
606
  typeName: ZodFirstPartyTypeKind.ZodEffects,
903
- effect: { type: "refinement", refinement: refinement },
607
+ effect: { type: "refinement", refinement },
904
608
  });
905
- };
906
- ZodType.prototype.optional = function () {
609
+ }
610
+ optional() {
907
611
  return ZodOptional.create(this);
908
- };
909
- ZodType.prototype.nullable = function () {
612
+ }
613
+ nullable() {
910
614
  return ZodNullable.create(this);
911
- };
912
- ZodType.prototype.nullish = function () {
615
+ }
616
+ nullish() {
913
617
  return this.optional().nullable();
914
- };
915
- ZodType.prototype.array = function () {
618
+ }
619
+ array() {
916
620
  return ZodArray.create(this);
917
- };
918
- ZodType.prototype.promise = function () {
621
+ }
622
+ promise() {
919
623
  return ZodPromise.create(this);
920
- };
921
- ZodType.prototype.or = function (option) {
624
+ }
625
+ or(option) {
922
626
  return ZodUnion.create([this, option]);
923
- };
924
- ZodType.prototype.and = function (incoming) {
627
+ }
628
+ and(incoming) {
925
629
  return ZodIntersection.create(this, incoming);
926
- };
927
- ZodType.prototype.transform = function (transform) {
630
+ }
631
+ transform(transform) {
928
632
  return new ZodEffects({
929
633
  schema: this,
930
634
  typeName: ZodFirstPartyTypeKind.ZodEffects,
931
- effect: { type: "transform", transform: transform },
635
+ effect: { type: "transform", transform },
932
636
  });
933
- };
934
- ZodType.prototype.default = function (def) {
935
- var defaultValueFunc = typeof def === "function" ? def : function () { return def; };
637
+ }
638
+ default(def) {
639
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
936
640
  return new ZodDefault({
937
641
  innerType: this,
938
642
  defaultValue: defaultValueFunc,
939
643
  typeName: ZodFirstPartyTypeKind.ZodDefault,
940
644
  });
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 () {
645
+ }
646
+ describe(description) {
647
+ const This = this.constructor;
648
+ return new This({
649
+ ...this._def,
650
+ description,
651
+ });
652
+ }
653
+ isOptional() {
947
654
  return this.safeParse(undefined).success;
948
- };
949
- ZodType.prototype.isNullable = function () {
655
+ }
656
+ isNullable() {
950
657
  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;
658
+ }
659
+ }
660
+ const cuidRegex = /^c[^\s-]{8,}$/i;
661
+ 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
662
  // from https://stackoverflow.com/a/46181/1550155
957
663
  // old version: too slow, didn't support unicode
958
664
  // 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
665
  // 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
- };
666
+ const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
667
+ class ZodString extends ZodType {
668
+ constructor() {
669
+ super(...arguments);
670
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
671
+ validation,
672
+ code: ZodIssueCode.invalid_string,
673
+ ...errorUtil.errToObj(message),
674
+ });
968
675
  /**
969
676
  * Deprecated.
970
677
  * Use z.string().min(1) instead.
971
678
  */
972
- _this.nonempty = function (message) {
973
- return _this.min(1, errorUtil.errToObj(message));
974
- };
975
- return _this;
679
+ this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
976
680
  }
977
- ZodString.prototype._parse = function (input) {
978
- var e_1, _a;
979
- var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
681
+ _parse(input) {
682
+ const { status, ctx } = this._processInputParams(input);
980
683
  if (ctx.parsedType !== ZodParsedType.string) {
981
684
  addIssueToContext(ctx, {
982
685
  code: ZodIssueCode.invalid_type,
@@ -987,210 +690,191 @@ var ZodString = /** @class */ (function (_super) {
987
690
  );
988
691
  return INVALID;
989
692
  }
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
- }
693
+ for (const check of this._def.checks) {
694
+ if (check.kind === "min") {
695
+ if (ctx.data.length < check.value) {
696
+ addIssueToContext(ctx, {
697
+ code: ZodIssueCode.too_small,
698
+ minimum: check.value,
699
+ type: "string",
700
+ inclusive: true,
701
+ message: check.message,
702
+ });
703
+ status.dirty();
1004
704
  }
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
- }
705
+ }
706
+ else if (check.kind === "max") {
707
+ if (ctx.data.length > check.value) {
708
+ addIssueToContext(ctx, {
709
+ code: ZodIssueCode.too_big,
710
+ maximum: check.value,
711
+ type: "string",
712
+ inclusive: true,
713
+ message: check.message,
714
+ });
715
+ status.dirty();
1016
716
  }
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
- }
717
+ }
718
+ else if (check.kind === "email") {
719
+ if (!emailRegex.test(ctx.data)) {
720
+ addIssueToContext(ctx, {
721
+ validation: "email",
722
+ code: ZodIssueCode.invalid_string,
723
+ message: check.message,
724
+ });
725
+ status.dirty();
1026
726
  }
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
- }
727
+ }
728
+ else if (check.kind === "uuid") {
729
+ if (!uuidRegex.test(ctx.data)) {
730
+ addIssueToContext(ctx, {
731
+ validation: "uuid",
732
+ code: ZodIssueCode.invalid_string,
733
+ message: check.message,
734
+ });
735
+ status.dirty();
1036
736
  }
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
- }
737
+ }
738
+ else if (check.kind === "cuid") {
739
+ if (!cuidRegex.test(ctx.data)) {
740
+ addIssueToContext(ctx, {
741
+ validation: "cuid",
742
+ code: ZodIssueCode.invalid_string,
743
+ message: check.message,
744
+ });
745
+ status.dirty();
1046
746
  }
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
- }
747
+ }
748
+ else if (check.kind === "url") {
749
+ try {
750
+ new URL(ctx.data);
1059
751
  }
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
- }
752
+ catch (_a) {
753
+ addIssueToContext(ctx, {
754
+ validation: "url",
755
+ code: ZodIssueCode.invalid_string,
756
+ message: check.message,
757
+ });
758
+ status.dirty();
1071
759
  }
1072
760
  }
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);
761
+ else if (check.kind === "regex") {
762
+ check.regex.lastIndex = 0;
763
+ const testResult = check.regex.test(ctx.data);
764
+ if (!testResult) {
765
+ addIssueToContext(ctx, {
766
+ validation: "regex",
767
+ code: ZodIssueCode.invalid_string,
768
+ message: check.message,
769
+ });
770
+ status.dirty();
771
+ }
1078
772
  }
1079
- finally { if (e_1) throw e_1.error; }
1080
773
  }
1081
774
  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) {
775
+ }
776
+ _addCheck(check) {
777
+ return new ZodString({
778
+ ...this._def,
779
+ checks: [...this._def.checks, check],
780
+ });
781
+ }
782
+ email(message) {
783
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
784
+ }
785
+ url(message) {
786
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
787
+ }
788
+ uuid(message) {
789
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
790
+ }
791
+ cuid(message) {
792
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
793
+ }
794
+ regex(regex, message) {
795
+ return this._addCheck({
796
+ kind: "regex",
797
+ regex: regex,
798
+ ...errorUtil.errToObj(message),
799
+ });
800
+ }
801
+ min(minLength, message) {
802
+ return this._addCheck({
803
+ kind: "min",
804
+ value: minLength,
805
+ ...errorUtil.errToObj(message),
806
+ });
807
+ }
808
+ max(maxLength, message) {
809
+ return this._addCheck({
810
+ kind: "max",
811
+ value: maxLength,
812
+ ...errorUtil.errToObj(message),
813
+ });
814
+ }
815
+ length(len, message) {
1108
816
  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
- }
817
+ }
818
+ get isEmail() {
819
+ return !!this._def.checks.find((ch) => ch.kind === "email");
820
+ }
821
+ get isURL() {
822
+ return !!this._def.checks.find((ch) => ch.kind === "url");
823
+ }
824
+ get isUUID() {
825
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
826
+ }
827
+ get isCUID() {
828
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
829
+ }
830
+ get minLength() {
831
+ let min = -Infinity;
832
+ this._def.checks.map((ch) => {
833
+ if (ch.kind === "min") {
834
+ if (min === null || ch.value > min) {
835
+ min = ch.value;
1146
836
  }
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
- }
837
+ }
838
+ });
839
+ return min;
840
+ }
841
+ get maxLength() {
842
+ let max = null;
843
+ this._def.checks.map((ch) => {
844
+ if (ch.kind === "max") {
845
+ if (max === null || ch.value < max) {
846
+ max = ch.value;
1161
847
  }
1162
- });
1163
- return max;
1164
- },
1165
- enumerable: false,
1166
- configurable: true
848
+ }
849
+ });
850
+ return max;
851
+ }
852
+ }
853
+ ZodString.create = (params) => {
854
+ return new ZodString({
855
+ checks: [],
856
+ typeName: ZodFirstPartyTypeKind.ZodString,
857
+ ...processCreateParams(params),
1167
858
  });
1168
- ZodString.create = function (params) {
1169
- return new ZodString(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString }, processCreateParams(params)));
1170
- };
1171
- return ZodString;
1172
- }(ZodType));
859
+ };
1173
860
  // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
1174
861
  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(".", ""));
862
+ const valDecCount = (val.toString().split(".")[1] || "").length;
863
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
864
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
865
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
866
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1180
867
  return (valInt % stepInt) / Math.pow(10, decCount);
1181
868
  }
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;
869
+ class ZodNumber extends ZodType {
870
+ constructor() {
871
+ super(...arguments);
872
+ this.min = this.gte;
873
+ this.max = this.lte;
874
+ this.step = this.multipleOf;
875
+ }
876
+ _parse(input) {
877
+ const { status, ctx } = this._processInputParams(input);
1194
878
  if (ctx.parsedType !== ZodParsedType.number) {
1195
879
  addIssueToContext(ctx, {
1196
880
  code: ZodIssueCode.invalid_type,
@@ -1199,213 +883,175 @@ var ZodNumber = /** @class */ (function (_super) {
1199
883
  });
1200
884
  return INVALID;
1201
885
  }
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
- }
886
+ for (const check of this._def.checks) {
887
+ if (check.kind === "int") {
888
+ if (!util.isInteger(ctx.data)) {
889
+ addIssueToContext(ctx, {
890
+ code: ZodIssueCode.invalid_type,
891
+ expected: "integer",
892
+ received: "float",
893
+ message: check.message,
894
+ });
895
+ status.dirty();
1230
896
  }
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
- }
897
+ }
898
+ else if (check.kind === "min") {
899
+ const tooSmall = check.inclusive
900
+ ? ctx.data < check.value
901
+ : ctx.data <= check.value;
902
+ if (tooSmall) {
903
+ addIssueToContext(ctx, {
904
+ code: ZodIssueCode.too_small,
905
+ minimum: check.value,
906
+ type: "number",
907
+ inclusive: check.inclusive,
908
+ message: check.message,
909
+ });
910
+ status.dirty();
1245
911
  }
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
- }
912
+ }
913
+ else if (check.kind === "max") {
914
+ const tooBig = check.inclusive
915
+ ? ctx.data > check.value
916
+ : ctx.data >= check.value;
917
+ if (tooBig) {
918
+ addIssueToContext(ctx, {
919
+ code: ZodIssueCode.too_big,
920
+ maximum: check.value,
921
+ type: "number",
922
+ inclusive: check.inclusive,
923
+ message: check.message,
924
+ });
925
+ status.dirty();
1255
926
  }
1256
- else {
1257
- util.assertNever(check);
927
+ }
928
+ else if (check.kind === "multipleOf") {
929
+ if (floatSafeRemainder(ctx.data, check.value) !== 0) {
930
+ addIssueToContext(ctx, {
931
+ code: ZodIssueCode.not_multiple_of,
932
+ multipleOf: check.value,
933
+ message: check.message,
934
+ });
935
+ status.dirty();
1258
936
  }
1259
937
  }
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);
938
+ else {
939
+ util.assertNever(check);
1265
940
  }
1266
- finally { if (e_2) throw e_2.error; }
1267
941
  }
1268
942
  return { status: status.value, value: ctx.data };
1269
- };
1270
- ZodNumber.prototype.gte = function (value, message) {
943
+ }
944
+ gte(value, message) {
1271
945
  return this.setLimit("min", value, true, errorUtil.toString(message));
1272
- };
1273
- ZodNumber.prototype.gt = function (value, message) {
946
+ }
947
+ gt(value, message) {
1274
948
  return this.setLimit("min", value, false, errorUtil.toString(message));
1275
- };
1276
- ZodNumber.prototype.lte = function (value, message) {
949
+ }
950
+ lte(value, message) {
1277
951
  return this.setLimit("max", value, true, errorUtil.toString(message));
1278
- };
1279
- ZodNumber.prototype.lt = function (value, message) {
952
+ }
953
+ lt(value, message) {
1280
954
  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), [
955
+ }
956
+ setLimit(kind, value, inclusive, message) {
957
+ return new ZodNumber({
958
+ ...this._def,
959
+ checks: [
960
+ ...this._def.checks,
1284
961
  {
1285
- kind: kind,
1286
- value: value,
1287
- inclusive: inclusive,
962
+ kind,
963
+ value,
964
+ inclusive,
1288
965
  message: errorUtil.toString(message),
1289
966
  },
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) {
967
+ ],
968
+ });
969
+ }
970
+ _addCheck(check) {
971
+ return new ZodNumber({
972
+ ...this._def,
973
+ checks: [...this._def.checks, check],
974
+ });
975
+ }
976
+ int(message) {
1296
977
  return this._addCheck({
1297
978
  kind: "int",
1298
979
  message: errorUtil.toString(message),
1299
980
  });
1300
- };
1301
- ZodNumber.prototype.positive = function (message) {
981
+ }
982
+ positive(message) {
1302
983
  return this._addCheck({
1303
984
  kind: "min",
1304
985
  value: 0,
1305
986
  inclusive: false,
1306
987
  message: errorUtil.toString(message),
1307
988
  });
1308
- };
1309
- ZodNumber.prototype.negative = function (message) {
989
+ }
990
+ negative(message) {
1310
991
  return this._addCheck({
1311
992
  kind: "max",
1312
993
  value: 0,
1313
994
  inclusive: false,
1314
995
  message: errorUtil.toString(message),
1315
996
  });
1316
- };
1317
- ZodNumber.prototype.nonpositive = function (message) {
997
+ }
998
+ nonpositive(message) {
1318
999
  return this._addCheck({
1319
1000
  kind: "max",
1320
1001
  value: 0,
1321
1002
  inclusive: true,
1322
1003
  message: errorUtil.toString(message),
1323
1004
  });
1324
- };
1325
- ZodNumber.prototype.nonnegative = function (message) {
1005
+ }
1006
+ nonnegative(message) {
1326
1007
  return this._addCheck({
1327
1008
  kind: "min",
1328
1009
  value: 0,
1329
1010
  inclusive: true,
1330
1011
  message: errorUtil.toString(message),
1331
1012
  });
1332
- };
1333
- ZodNumber.prototype.multipleOf = function (value, message) {
1013
+ }
1014
+ multipleOf(value, message) {
1334
1015
  return this._addCheck({
1335
1016
  kind: "multipleOf",
1336
1017
  value: value,
1337
1018
  message: errorUtil.toString(message),
1338
1019
  });
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
- }
1020
+ }
1021
+ get minValue() {
1022
+ let min = null;
1023
+ for (const ch of this._def.checks) {
1024
+ if (ch.kind === "min") {
1025
+ if (min === null || ch.value > min)
1026
+ min = ch.value;
1377
1027
  }
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; }
1028
+ }
1029
+ return min;
1030
+ }
1031
+ get maxValue() {
1032
+ let max = null;
1033
+ for (const ch of this._def.checks) {
1034
+ if (ch.kind === "max") {
1035
+ if (max === null || ch.value < max)
1036
+ max = ch.value;
1384
1037
  }
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
1038
+ }
1039
+ return max;
1040
+ }
1041
+ get isInt() {
1042
+ return !!this._def.checks.find((ch) => ch.kind === "int");
1043
+ }
1044
+ }
1045
+ ZodNumber.create = (params) => {
1046
+ return new ZodNumber({
1047
+ checks: [],
1048
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1049
+ ...processCreateParams(params),
1396
1050
  });
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;
1051
+ };
1052
+ class ZodBigInt extends ZodType {
1053
+ _parse(input) {
1054
+ const { ctx } = this._processInputParams(input);
1409
1055
  if (ctx.parsedType !== ZodParsedType.bigint) {
1410
1056
  addIssueToContext(ctx, {
1411
1057
  code: ZodIssueCode.invalid_type,
@@ -1415,19 +1061,17 @@ var ZodBigInt = /** @class */ (function (_super) {
1415
1061
  return INVALID;
1416
1062
  }
1417
1063
  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;
1064
+ }
1065
+ }
1066
+ ZodBigInt.create = (params) => {
1067
+ return new ZodBigInt({
1068
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1069
+ ...processCreateParams(params),
1070
+ });
1071
+ };
1072
+ class ZodBoolean extends ZodType {
1073
+ _parse(input) {
1074
+ const { ctx } = this._processInputParams(input);
1431
1075
  if (ctx.parsedType !== ZodParsedType.boolean) {
1432
1076
  addIssueToContext(ctx, {
1433
1077
  code: ZodIssueCode.invalid_type,
@@ -1437,19 +1081,17 @@ var ZodBoolean = /** @class */ (function (_super) {
1437
1081
  return INVALID;
1438
1082
  }
1439
1083
  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;
1084
+ }
1085
+ }
1086
+ ZodBoolean.create = (params) => {
1087
+ return new ZodBoolean({
1088
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1089
+ ...processCreateParams(params),
1090
+ });
1091
+ };
1092
+ class ZodDate extends ZodType {
1093
+ _parse(input) {
1094
+ const { status, ctx } = this._processInputParams(input);
1453
1095
  if (ctx.parsedType !== ZodParsedType.date) {
1454
1096
  addIssueToContext(ctx, {
1455
1097
  code: ZodIssueCode.invalid_type,
@@ -1468,19 +1110,17 @@ var ZodDate = /** @class */ (function (_super) {
1468
1110
  status: status.value,
1469
1111
  value: new Date(ctx.data.getTime()),
1470
1112
  };
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;
1113
+ }
1114
+ }
1115
+ ZodDate.create = (params) => {
1116
+ return new ZodDate({
1117
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1118
+ ...processCreateParams(params),
1119
+ });
1120
+ };
1121
+ class ZodUndefined extends ZodType {
1122
+ _parse(input) {
1123
+ const { ctx } = this._processInputParams(input);
1484
1124
  if (ctx.parsedType !== ZodParsedType.undefined) {
1485
1125
  addIssueToContext(ctx, {
1486
1126
  code: ZodIssueCode.invalid_type,
@@ -1490,19 +1130,17 @@ var ZodUndefined = /** @class */ (function (_super) {
1490
1130
  return INVALID;
1491
1131
  }
1492
1132
  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;
1133
+ }
1134
+ }
1135
+ ZodUndefined.create = (params) => {
1136
+ return new ZodUndefined({
1137
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1138
+ ...processCreateParams(params),
1139
+ });
1140
+ };
1141
+ class ZodNull extends ZodType {
1142
+ _parse(input) {
1143
+ const { ctx } = this._processInputParams(input);
1506
1144
  if (ctx.parsedType !== ZodParsedType.null) {
1507
1145
  addIssueToContext(ctx, {
1508
1146
  code: ZodIssueCode.invalid_type,
@@ -1512,72 +1150,68 @@ var ZodNull = /** @class */ (function (_super) {
1512
1150
  return INVALID;
1513
1151
  }
1514
1152
  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;
1153
+ }
1154
+ }
1155
+ ZodNull.create = (params) => {
1156
+ return new ZodNull({
1157
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1158
+ ...processCreateParams(params),
1159
+ });
1160
+ };
1161
+ class ZodAny extends ZodType {
1162
+ constructor() {
1163
+ super(...arguments);
1525
1164
  // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
1526
- _this._any = true;
1527
- return _this;
1165
+ this._any = true;
1528
1166
  }
1529
- ZodAny.prototype._parse = function (input) {
1530
- var ctx = this._processInputParams(input).ctx;
1167
+ _parse(input) {
1168
+ const { ctx } = this._processInputParams(input);
1531
1169
  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;
1170
+ }
1171
+ }
1172
+ ZodAny.create = (params) => {
1173
+ return new ZodAny({
1174
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1175
+ ...processCreateParams(params),
1176
+ });
1177
+ };
1178
+ class ZodUnknown extends ZodType {
1179
+ constructor() {
1180
+ super(...arguments);
1542
1181
  // required
1543
- _this._unknown = true;
1544
- return _this;
1182
+ this._unknown = true;
1545
1183
  }
1546
- ZodUnknown.prototype._parse = function (input) {
1547
- var ctx = this._processInputParams(input).ctx;
1184
+ _parse(input) {
1185
+ const { ctx } = this._processInputParams(input);
1548
1186
  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;
1187
+ }
1188
+ }
1189
+ ZodUnknown.create = (params) => {
1190
+ return new ZodUnknown({
1191
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
1192
+ ...processCreateParams(params),
1193
+ });
1194
+ };
1195
+ class ZodNever extends ZodType {
1196
+ _parse(input) {
1197
+ const { ctx } = this._processInputParams(input);
1562
1198
  addIssueToContext(ctx, {
1563
1199
  code: ZodIssueCode.invalid_type,
1564
1200
  expected: ZodParsedType.never,
1565
1201
  received: ctx.parsedType,
1566
1202
  });
1567
1203
  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;
1204
+ }
1205
+ }
1206
+ ZodNever.create = (params) => {
1207
+ return new ZodNever({
1208
+ typeName: ZodFirstPartyTypeKind.ZodNever,
1209
+ ...processCreateParams(params),
1210
+ });
1211
+ };
1212
+ class ZodVoid extends ZodType {
1213
+ _parse(input) {
1214
+ const { ctx } = this._processInputParams(input);
1581
1215
  if (ctx.parsedType !== ZodParsedType.undefined) {
1582
1216
  addIssueToContext(ctx, {
1583
1217
  code: ZodIssueCode.invalid_type,
@@ -1587,20 +1221,18 @@ var ZodVoid = /** @class */ (function (_super) {
1587
1221
  return INVALID;
1588
1222
  }
1589
1223
  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;
1224
+ }
1225
+ }
1226
+ ZodVoid.create = (params) => {
1227
+ return new ZodVoid({
1228
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
1229
+ ...processCreateParams(params),
1230
+ });
1231
+ };
1232
+ class ZodArray extends ZodType {
1233
+ _parse(input) {
1234
+ const { status, ctx } = this._processInputParams(input);
1235
+ const def = this._def;
1604
1236
  if (ctx.parsedType !== ZodParsedType.array) {
1605
1237
  addIssueToContext(ctx, {
1606
1238
  code: ZodIssueCode.invalid_type,
@@ -1634,49 +1266,56 @@ var ZodArray = /** @class */ (function (_super) {
1634
1266
  }
1635
1267
  }
1636
1268
  if (ctx.async) {
1637
- return Promise.all(ctx.data.map(function (item, i) {
1269
+ return Promise.all(ctx.data.map((item, i) => {
1638
1270
  return def.type._parseAsync({
1639
1271
  parent: ctx,
1640
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
1272
+ path: [...ctx.path, i],
1641
1273
  data: item,
1642
1274
  });
1643
- })).then(function (result) {
1275
+ })).then((result) => {
1644
1276
  return ParseStatus.mergeArray(status, result);
1645
1277
  });
1646
1278
  }
1647
- var result = ctx.data.map(function (item, i) {
1279
+ const result = ctx.data.map((item, i) => {
1648
1280
  return def.type._parseSync({
1649
1281
  parent: ctx,
1650
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
1282
+ path: [...ctx.path, i],
1651
1283
  data: item,
1652
1284
  });
1653
1285
  });
1654
1286
  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) {
1287
+ }
1288
+ get element() {
1289
+ return this._def.type;
1290
+ }
1291
+ min(minLength, message) {
1292
+ return new ZodArray({
1293
+ ...this._def,
1294
+ minLength: { value: minLength, message: errorUtil.toString(message) },
1295
+ });
1296
+ }
1297
+ max(maxLength, message) {
1298
+ return new ZodArray({
1299
+ ...this._def,
1300
+ maxLength: { value: maxLength, message: errorUtil.toString(message) },
1301
+ });
1302
+ }
1303
+ length(len, message) {
1670
1304
  return this.min(len, message).max(len, message);
1671
- };
1672
- ZodArray.prototype.nonempty = function (message) {
1305
+ }
1306
+ nonempty(message) {
1673
1307
  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));
1308
+ }
1309
+ }
1310
+ ZodArray.create = (schema, params) => {
1311
+ return new ZodArray({
1312
+ type: schema,
1313
+ minLength: null,
1314
+ maxLength: null,
1315
+ typeName: ZodFirstPartyTypeKind.ZodArray,
1316
+ ...processCreateParams(params),
1317
+ });
1318
+ };
1680
1319
  /////////////////////////////////////////
1681
1320
  /////////////////////////////////////////
1682
1321
  ////////// //////////
@@ -1686,21 +1325,33 @@ var ZodArray = /** @class */ (function (_super) {
1686
1325
  /////////////////////////////////////////
1687
1326
  var objectUtil;
1688
1327
  (function (objectUtil) {
1689
- objectUtil.mergeShapes = function (first, second) {
1690
- return __assign(__assign({}, first), second);
1328
+ objectUtil.mergeShapes = (first, second) => {
1329
+ return {
1330
+ ...first,
1331
+ ...second, // second overwrites first
1332
+ };
1691
1333
  };
1692
1334
  })(objectUtil || (objectUtil = {}));
1693
- var AugmentFactory = function (def) { return function (augmentation) {
1694
- return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
1695
- }; };
1335
+ const AugmentFactory = (def) => (augmentation) => {
1336
+ return new ZodObject({
1337
+ ...def,
1338
+ shape: () => ({
1339
+ ...def.shape(),
1340
+ ...augmentation,
1341
+ }),
1342
+ });
1343
+ };
1696
1344
  function deepPartialify(schema) {
1697
1345
  if (schema instanceof ZodObject) {
1698
- var newShape_1 = {};
1699
- for (var key in schema.shape) {
1700
- var fieldSchema = schema.shape[key];
1701
- newShape_1[key] = ZodOptional.create(deepPartialify(fieldSchema));
1702
- }
1703
- return new ZodObject(__assign(__assign({}, schema._def), { shape: function () { return newShape_1; } }));
1346
+ const newShape = {};
1347
+ for (const key in schema.shape) {
1348
+ const fieldSchema = schema.shape[key];
1349
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
1350
+ }
1351
+ return new ZodObject({
1352
+ ...schema._def,
1353
+ shape: () => newShape,
1354
+ });
1704
1355
  }
1705
1356
  else if (schema instanceof ZodArray) {
1706
1357
  return ZodArray.create(deepPartialify(schema.element));
@@ -1712,37 +1363,33 @@ function deepPartialify(schema) {
1712
1363
  return ZodNullable.create(deepPartialify(schema.unwrap()));
1713
1364
  }
1714
1365
  else if (schema instanceof ZodTuple) {
1715
- return ZodTuple.create(schema.items.map(function (item) { return deepPartialify(item); }));
1366
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
1716
1367
  }
1717
1368
  else {
1718
1369
  return schema;
1719
1370
  }
1720
1371
  }
1721
- var ZodObject = /** @class */ (function (_super) {
1722
- __extends(ZodObject, _super);
1723
- function ZodObject() {
1724
- var _this = _super !== null && _super.apply(this, arguments) || this;
1725
- _this._cached = null;
1372
+ class ZodObject extends ZodType {
1373
+ constructor() {
1374
+ super(...arguments);
1375
+ this._cached = null;
1726
1376
  /**
1727
1377
  * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
1728
1378
  * If you want to pass through unknown properties, use `.passthrough()` instead.
1729
1379
  */
1730
- _this.nonstrict = _this.passthrough;
1731
- _this.augment = AugmentFactory(_this._def);
1732
- _this.extend = AugmentFactory(_this._def);
1733
- return _this;
1380
+ this.nonstrict = this.passthrough;
1381
+ this.augment = AugmentFactory(this._def);
1382
+ this.extend = AugmentFactory(this._def);
1734
1383
  }
1735
- ZodObject.prototype._getCached = function () {
1384
+ _getCached() {
1736
1385
  if (this._cached !== null)
1737
1386
  return this._cached;
1738
- var shape = this._def.shape();
1739
- var keys = util.objectKeys(shape);
1740
- return (this._cached = { shape: shape, keys: keys });
1741
- };
1742
- ZodObject.prototype._parse = function (input) {
1743
- var e_5, _a, e_6, _b, e_7, _c;
1744
- var _this = this;
1745
- var _d = this._processInputParams(input), status = _d.status, ctx = _d.ctx;
1387
+ const shape = this._def.shape();
1388
+ const keys = util.objectKeys(shape);
1389
+ return (this._cached = { shape, keys });
1390
+ }
1391
+ _parse(input) {
1392
+ const { status, ctx } = this._processInputParams(input);
1746
1393
  if (ctx.parsedType !== ZodParsedType.object) {
1747
1394
  addIssueToContext(ctx, {
1748
1395
  code: ZodIssueCode.invalid_type,
@@ -1751,51 +1398,31 @@ var ZodObject = /** @class */ (function (_super) {
1751
1398
  });
1752
1399
  return INVALID;
1753
1400
  }
1754
- var _e = this._getCached(), shape = _e.shape, shapeKeys = _e.keys;
1755
- var dataKeys = util.objectKeys(ctx.data);
1756
- var extraKeys = dataKeys.filter(function (k) { return !shapeKeys.includes(k); });
1757
- var pairs = [];
1758
- try {
1759
- for (var shapeKeys_1 = __values(shapeKeys), shapeKeys_1_1 = shapeKeys_1.next(); !shapeKeys_1_1.done; shapeKeys_1_1 = shapeKeys_1.next()) {
1760
- var key = shapeKeys_1_1.value;
1761
- var keyValidator = shape[key];
1762
- var value = ctx.data[key];
1763
- pairs.push({
1764
- key: { status: "valid", value: key },
1765
- value: keyValidator._parse({
1766
- parent: ctx,
1767
- data: value,
1768
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
1769
- }),
1770
- alwaysSet: key in ctx.data,
1771
- });
1772
- }
1773
- }
1774
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1775
- finally {
1776
- try {
1777
- if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
1778
- }
1779
- finally { if (e_5) throw e_5.error; }
1401
+ const { shape, keys: shapeKeys } = this._getCached();
1402
+ const dataKeys = util.objectKeys(ctx.data);
1403
+ const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k));
1404
+ const pairs = [];
1405
+ for (const key of shapeKeys) {
1406
+ const keyValidator = shape[key];
1407
+ const value = ctx.data[key];
1408
+ pairs.push({
1409
+ key: { status: "valid", value: key },
1410
+ value: keyValidator._parse({
1411
+ parent: ctx,
1412
+ data: value,
1413
+ path: [...ctx.path, key],
1414
+ }),
1415
+ alwaysSet: key in ctx.data,
1416
+ });
1780
1417
  }
1781
1418
  if (this._def.catchall instanceof ZodNever) {
1782
- var unknownKeys = this._def.unknownKeys;
1419
+ const unknownKeys = this._def.unknownKeys;
1783
1420
  if (unknownKeys === "passthrough") {
1784
- try {
1785
- for (var extraKeys_1 = __values(extraKeys), extraKeys_1_1 = extraKeys_1.next(); !extraKeys_1_1.done; extraKeys_1_1 = extraKeys_1.next()) {
1786
- var key = extraKeys_1_1.value;
1787
- pairs.push({
1788
- key: { status: "valid", value: key },
1789
- value: { status: "valid", value: ctx.data[key] },
1790
- });
1791
- }
1792
- }
1793
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1794
- finally {
1795
- try {
1796
- if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
1797
- }
1798
- finally { if (e_6) throw e_6.error; }
1421
+ for (const key of extraKeys) {
1422
+ pairs.push({
1423
+ key: { status: "valid", value: key },
1424
+ value: { status: "valid", value: ctx.data[key] },
1425
+ });
1799
1426
  }
1800
1427
  }
1801
1428
  else if (unknownKeys === "strict") {
@@ -1809,321 +1436,296 @@ var ZodObject = /** @class */ (function (_super) {
1809
1436
  }
1810
1437
  else if (unknownKeys === "strip") ;
1811
1438
  else {
1812
- throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1439
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
1813
1440
  }
1814
1441
  }
1815
1442
  else {
1816
1443
  // run catchall validation
1817
- var catchall = this._def.catchall;
1818
- try {
1819
- for (var extraKeys_2 = __values(extraKeys), extraKeys_2_1 = extraKeys_2.next(); !extraKeys_2_1.done; extraKeys_2_1 = extraKeys_2.next()) {
1820
- var key = extraKeys_2_1.value;
1821
- var value = ctx.data[key];
1822
- pairs.push({
1823
- key: { status: "valid", value: key },
1824
- value: catchall._parse({ parent: ctx, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false), data: value } //, ctx.child(key), value, getParsedType(value)
1825
- ),
1826
- alwaysSet: key in ctx.data,
1827
- });
1828
- }
1829
- }
1830
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1831
- finally {
1832
- try {
1833
- if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
1834
- }
1835
- finally { if (e_7) throw e_7.error; }
1444
+ const catchall = this._def.catchall;
1445
+ for (const key of extraKeys) {
1446
+ const value = ctx.data[key];
1447
+ pairs.push({
1448
+ key: { status: "valid", value: key },
1449
+ value: catchall._parse({ parent: ctx, path: [...ctx.path, key], data: value } //, ctx.child(key), value, getParsedType(value)
1450
+ ),
1451
+ alwaysSet: key in ctx.data,
1452
+ });
1836
1453
  }
1837
1454
  }
1838
1455
  if (ctx.async) {
1839
1456
  return Promise.resolve()
1840
- .then(function () { return __awaiter(_this, void 0, void 0, function () {
1841
- var syncPairs, pairs_1, pairs_1_1, pair, key, _a, _b, e_8_1;
1842
- var e_8, _c, _d;
1843
- return __generator(this, function (_e) {
1844
- switch (_e.label) {
1845
- case 0:
1846
- syncPairs = [];
1847
- _e.label = 1;
1848
- case 1:
1849
- _e.trys.push([1, 7, 8, 9]);
1850
- pairs_1 = __values(pairs), pairs_1_1 = pairs_1.next();
1851
- _e.label = 2;
1852
- case 2:
1853
- if (!!pairs_1_1.done) return [3 /*break*/, 6];
1854
- pair = pairs_1_1.value;
1855
- return [4 /*yield*/, pair.key];
1856
- case 3:
1857
- key = _e.sent();
1858
- _b = (_a = syncPairs).push;
1859
- _d = {
1860
- key: key
1861
- };
1862
- return [4 /*yield*/, pair.value];
1863
- case 4:
1864
- _b.apply(_a, [(_d.value = _e.sent(),
1865
- _d.alwaysSet = pair.alwaysSet,
1866
- _d)]);
1867
- _e.label = 5;
1868
- case 5:
1869
- pairs_1_1 = pairs_1.next();
1870
- return [3 /*break*/, 2];
1871
- case 6: return [3 /*break*/, 9];
1872
- case 7:
1873
- e_8_1 = _e.sent();
1874
- e_8 = { error: e_8_1 };
1875
- return [3 /*break*/, 9];
1876
- case 8:
1877
- try {
1878
- if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
1879
- }
1880
- finally { if (e_8) throw e_8.error; }
1881
- return [7 /*endfinally*/];
1882
- case 9: return [2 /*return*/, syncPairs];
1883
- }
1884
- });
1885
- }); })
1886
- .then(function (syncPairs) {
1457
+ .then(async () => {
1458
+ const syncPairs = [];
1459
+ for (const pair of pairs) {
1460
+ const key = await pair.key;
1461
+ syncPairs.push({
1462
+ key,
1463
+ value: await pair.value,
1464
+ alwaysSet: pair.alwaysSet,
1465
+ });
1466
+ }
1467
+ return syncPairs;
1468
+ })
1469
+ .then((syncPairs) => {
1887
1470
  return ParseStatus.mergeObjectSync(status, syncPairs);
1888
1471
  });
1889
1472
  }
1890
1473
  else {
1891
1474
  return ParseStatus.mergeObjectSync(status, pairs);
1892
1475
  }
1893
- };
1894
- Object.defineProperty(ZodObject.prototype, "shape", {
1895
- get: function () {
1896
- return this._def.shape();
1897
- },
1898
- enumerable: false,
1899
- configurable: true
1900
- });
1901
- ZodObject.prototype.strict = function (message) {
1902
- var _this = this;
1476
+ }
1477
+ get shape() {
1478
+ return this._def.shape();
1479
+ }
1480
+ strict(message) {
1903
1481
  errorUtil.errToObj;
1904
- return new ZodObject(__assign(__assign(__assign({}, this._def), { unknownKeys: "strict" }), (message !== undefined
1905
- ? {
1906
- errorMap: function (issue, ctx) {
1907
- var _a, _b, _c, _d;
1908
- 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;
1909
- if (issue.code === "unrecognized_keys")
1482
+ return new ZodObject({
1483
+ ...this._def,
1484
+ unknownKeys: "strict",
1485
+ ...(message !== undefined
1486
+ ? {
1487
+ errorMap: (issue, ctx) => {
1488
+ var _a, _b, _c, _d;
1489
+ 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;
1490
+ if (issue.code === "unrecognized_keys")
1491
+ return {
1492
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
1493
+ };
1910
1494
  return {
1911
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
1495
+ message: defaultError,
1912
1496
  };
1913
- return {
1914
- message: defaultError,
1915
- };
1916
- },
1917
- }
1918
- : {})));
1919
- };
1920
- ZodObject.prototype.strip = function () {
1921
- return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "strip" }));
1922
- };
1923
- ZodObject.prototype.passthrough = function () {
1924
- return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "passthrough" }));
1925
- };
1926
- ZodObject.prototype.setKey = function (key, schema) {
1927
- var _a;
1928
- return this.augment((_a = {}, _a[key] = schema, _a));
1929
- };
1497
+ },
1498
+ }
1499
+ : {}),
1500
+ });
1501
+ }
1502
+ strip() {
1503
+ return new ZodObject({
1504
+ ...this._def,
1505
+ unknownKeys: "strip",
1506
+ });
1507
+ }
1508
+ passthrough() {
1509
+ return new ZodObject({
1510
+ ...this._def,
1511
+ unknownKeys: "passthrough",
1512
+ });
1513
+ }
1514
+ setKey(key, schema) {
1515
+ return this.augment({ [key]: schema });
1516
+ }
1930
1517
  /**
1931
1518
  * Prior to zod@1.0.12 there was a bug in the
1932
1519
  * inferred type of merged objects. Please
1933
1520
  * upgrade if you are experiencing issues.
1934
1521
  */
1935
- ZodObject.prototype.merge = function (merging) {
1936
- var _this = this;
1522
+ merge(merging) {
1937
1523
  // const mergedShape = objectUtil.mergeShapes(
1938
1524
  // this._def.shape(),
1939
1525
  // merging._def.shape()
1940
1526
  // );
1941
- var merged = new ZodObject({
1527
+ const merged = new ZodObject({
1942
1528
  unknownKeys: merging._def.unknownKeys,
1943
1529
  catchall: merging._def.catchall,
1944
- shape: function () {
1945
- return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
1946
- },
1530
+ shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1947
1531
  typeName: ZodFirstPartyTypeKind.ZodObject,
1948
1532
  });
1949
1533
  return merged;
1950
- };
1951
- ZodObject.prototype.catchall = function (index) {
1952
- return new ZodObject(__assign(__assign({}, this._def), { catchall: index }));
1953
- };
1954
- ZodObject.prototype.pick = function (mask) {
1955
- var _this = this;
1956
- var shape = {};
1957
- util.objectKeys(mask).map(function (key) {
1958
- shape[key] = _this.shape[key];
1534
+ }
1535
+ catchall(index) {
1536
+ return new ZodObject({
1537
+ ...this._def,
1538
+ catchall: index,
1959
1539
  });
1960
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
1961
- };
1962
- ZodObject.prototype.omit = function (mask) {
1963
- var _this = this;
1964
- var shape = {};
1965
- util.objectKeys(this.shape).map(function (key) {
1540
+ }
1541
+ pick(mask) {
1542
+ const shape = {};
1543
+ util.objectKeys(mask).map((key) => {
1544
+ shape[key] = this.shape[key];
1545
+ });
1546
+ return new ZodObject({
1547
+ ...this._def,
1548
+ shape: () => shape,
1549
+ });
1550
+ }
1551
+ omit(mask) {
1552
+ const shape = {};
1553
+ util.objectKeys(this.shape).map((key) => {
1966
1554
  if (util.objectKeys(mask).indexOf(key) === -1) {
1967
- shape[key] = _this.shape[key];
1555
+ shape[key] = this.shape[key];
1968
1556
  }
1969
1557
  });
1970
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
1971
- };
1972
- ZodObject.prototype.deepPartial = function () {
1558
+ return new ZodObject({
1559
+ ...this._def,
1560
+ shape: () => shape,
1561
+ });
1562
+ }
1563
+ deepPartial() {
1973
1564
  return deepPartialify(this);
1974
- };
1975
- ZodObject.prototype.partial = function (mask) {
1976
- var _this = this;
1977
- var newShape = {};
1565
+ }
1566
+ partial(mask) {
1567
+ const newShape = {};
1978
1568
  if (mask) {
1979
- util.objectKeys(this.shape).map(function (key) {
1569
+ util.objectKeys(this.shape).map((key) => {
1980
1570
  if (util.objectKeys(mask).indexOf(key) === -1) {
1981
- newShape[key] = _this.shape[key];
1571
+ newShape[key] = this.shape[key];
1982
1572
  }
1983
1573
  else {
1984
- newShape[key] = _this.shape[key].optional();
1574
+ newShape[key] = this.shape[key].optional();
1985
1575
  }
1986
1576
  });
1987
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
1577
+ return new ZodObject({
1578
+ ...this._def,
1579
+ shape: () => newShape,
1580
+ });
1988
1581
  }
1989
1582
  else {
1990
- for (var key in this.shape) {
1991
- var fieldSchema = this.shape[key];
1583
+ for (const key in this.shape) {
1584
+ const fieldSchema = this.shape[key];
1992
1585
  newShape[key] = fieldSchema.optional();
1993
1586
  }
1994
1587
  }
1995
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
1996
- };
1997
- ZodObject.prototype.required = function () {
1998
- var newShape = {};
1999
- for (var key in this.shape) {
2000
- var fieldSchema = this.shape[key];
2001
- var newField = fieldSchema;
1588
+ return new ZodObject({
1589
+ ...this._def,
1590
+ shape: () => newShape,
1591
+ });
1592
+ }
1593
+ required() {
1594
+ const newShape = {};
1595
+ for (const key in this.shape) {
1596
+ const fieldSchema = this.shape[key];
1597
+ let newField = fieldSchema;
2002
1598
  while (newField instanceof ZodOptional) {
2003
1599
  newField = newField._def.innerType;
2004
1600
  }
2005
1601
  newShape[key] = newField;
2006
1602
  }
2007
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
2008
- };
2009
- ZodObject.create = function (shape, params) {
2010
- return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
2011
- };
2012
- ZodObject.strictCreate = function (shape, params) {
2013
- return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
2014
- };
2015
- ZodObject.lazycreate = function (shape, params) {
2016
- return new ZodObject(__assign({ shape: shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
2017
- };
2018
- return ZodObject;
2019
- }(ZodType));
2020
- var ZodUnion = /** @class */ (function (_super) {
2021
- __extends(ZodUnion, _super);
2022
- function ZodUnion() {
2023
- return _super !== null && _super.apply(this, arguments) || this;
2024
- }
2025
- ZodUnion.prototype._parse = function (input) {
2026
- var _this = this;
2027
- var ctx = this._processInputParams(input).ctx;
2028
- var options = this._def.options;
1603
+ return new ZodObject({
1604
+ ...this._def,
1605
+ shape: () => newShape,
1606
+ });
1607
+ }
1608
+ }
1609
+ ZodObject.create = (shape, params) => {
1610
+ return new ZodObject({
1611
+ shape: () => shape,
1612
+ unknownKeys: "strip",
1613
+ catchall: ZodNever.create(),
1614
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1615
+ ...processCreateParams(params),
1616
+ });
1617
+ };
1618
+ ZodObject.strictCreate = (shape, params) => {
1619
+ return new ZodObject({
1620
+ shape: () => shape,
1621
+ unknownKeys: "strict",
1622
+ catchall: ZodNever.create(),
1623
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1624
+ ...processCreateParams(params),
1625
+ });
1626
+ };
1627
+ ZodObject.lazycreate = (shape, params) => {
1628
+ return new ZodObject({
1629
+ shape,
1630
+ unknownKeys: "strip",
1631
+ catchall: ZodNever.create(),
1632
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1633
+ ...processCreateParams(params),
1634
+ });
1635
+ };
1636
+ class ZodUnion extends ZodType {
1637
+ _parse(input) {
1638
+ const { ctx } = this._processInputParams(input);
1639
+ const options = this._def.options;
2029
1640
  function handleResults(results) {
2030
- var e_9, _a, e_10, _b, _c;
2031
- try {
2032
- // return first issue-free validation if it exists
2033
- for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
2034
- var result = results_1_1.value;
2035
- if (result.result.status === "valid") {
2036
- return result.result;
2037
- }
2038
- }
2039
- }
2040
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
2041
- finally {
2042
- try {
2043
- if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
2044
- }
2045
- finally { if (e_9) throw e_9.error; }
2046
- }
2047
- try {
2048
- for (var results_2 = __values(results), results_2_1 = results_2.next(); !results_2_1.done; results_2_1 = results_2.next()) {
2049
- var result = results_2_1.value;
2050
- if (result.result.status === "dirty") {
2051
- // add issues from dirty option
2052
- (_c = ctx.issues).push.apply(_c, __spreadArray([], __read(result.ctx.issues), false));
2053
- return result.result;
2054
- }
1641
+ // return first issue-free validation if it exists
1642
+ for (const result of results) {
1643
+ if (result.result.status === "valid") {
1644
+ return result.result;
2055
1645
  }
2056
1646
  }
2057
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
2058
- finally {
2059
- try {
2060
- if (results_2_1 && !results_2_1.done && (_b = results_2.return)) _b.call(results_2);
1647
+ for (const result of results) {
1648
+ if (result.result.status === "dirty") {
1649
+ // add issues from dirty option
1650
+ ctx.issues.push(...result.ctx.issues);
1651
+ return result.result;
2061
1652
  }
2062
- finally { if (e_10) throw e_10.error; }
2063
1653
  }
2064
1654
  // return invalid
2065
- var unionErrors = results.map(function (result) { return new ZodError(result.ctx.issues); });
1655
+ const unionErrors = results.map((result) => new ZodError(result.ctx.issues));
2066
1656
  addIssueToContext(ctx, {
2067
1657
  code: ZodIssueCode.invalid_union,
2068
- unionErrors: unionErrors,
1658
+ unionErrors,
2069
1659
  });
2070
1660
  return INVALID;
2071
1661
  }
2072
1662
  if (ctx.async) {
2073
- return Promise.all(options.map(function (option) { return __awaiter(_this, void 0, void 0, function () {
2074
- var childCtx;
2075
- var _a;
2076
- return __generator(this, function (_b) {
2077
- switch (_b.label) {
2078
- case 0:
2079
- childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
2080
- _a = {};
2081
- return [4 /*yield*/, option._parseAsync({
2082
- data: ctx.data,
2083
- path: ctx.path,
2084
- parent: childCtx,
2085
- })];
2086
- case 1: return [2 /*return*/, (_a.result = _b.sent(),
2087
- _a.ctx = childCtx,
2088
- _a)];
2089
- }
2090
- });
2091
- }); })).then(handleResults);
2092
- }
2093
- else {
2094
- var optionResults = options.map(function (option) {
2095
- var childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
1663
+ return Promise.all(options.map(async (option) => {
1664
+ const childCtx = {
1665
+ ...ctx,
1666
+ issues: [],
1667
+ parent: null,
1668
+ };
2096
1669
  return {
2097
- result: option._parseSync({
1670
+ result: await option._parseAsync({
2098
1671
  data: ctx.data,
2099
1672
  path: ctx.path,
2100
1673
  parent: childCtx,
2101
1674
  }),
2102
1675
  ctx: childCtx,
2103
1676
  };
1677
+ })).then(handleResults);
1678
+ }
1679
+ else {
1680
+ let dirty = undefined;
1681
+ const issues = [];
1682
+ for (const option of options) {
1683
+ const childCtx = {
1684
+ ...ctx,
1685
+ issues: [],
1686
+ parent: null,
1687
+ };
1688
+ const result = option._parseSync({
1689
+ data: ctx.data,
1690
+ path: ctx.path,
1691
+ parent: childCtx,
1692
+ });
1693
+ if (result.status === "valid") {
1694
+ return result;
1695
+ }
1696
+ else if (result.status === "dirty" && !dirty) {
1697
+ dirty = { result, ctx: childCtx };
1698
+ }
1699
+ if (childCtx.issues.length) {
1700
+ issues.push(childCtx.issues);
1701
+ }
1702
+ }
1703
+ if (dirty) {
1704
+ ctx.issues.push(...dirty.ctx.issues);
1705
+ return dirty.result;
1706
+ }
1707
+ const unionErrors = issues.map((issues) => new ZodError(issues));
1708
+ addIssueToContext(ctx, {
1709
+ code: ZodIssueCode.invalid_union,
1710
+ unionErrors,
2104
1711
  });
2105
- return handleResults(optionResults);
1712
+ return INVALID;
2106
1713
  }
2107
- };
2108
- Object.defineProperty(ZodUnion.prototype, "options", {
2109
- get: function () {
2110
- return this._def.options;
2111
- },
2112
- enumerable: false,
2113
- configurable: true
1714
+ }
1715
+ get options() {
1716
+ return this._def.options;
1717
+ }
1718
+ }
1719
+ ZodUnion.create = (types, params) => {
1720
+ return new ZodUnion({
1721
+ options: types,
1722
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
1723
+ ...processCreateParams(params),
2114
1724
  });
2115
- ZodUnion.create = function (types, params) {
2116
- return new ZodUnion(__assign({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion }, processCreateParams(params)));
2117
- };
2118
- return ZodUnion;
2119
- }(ZodType));
2120
- var ZodDiscriminatedUnion = /** @class */ (function (_super) {
2121
- __extends(ZodDiscriminatedUnion, _super);
2122
- function ZodDiscriminatedUnion() {
2123
- return _super !== null && _super.apply(this, arguments) || this;
2124
- }
2125
- ZodDiscriminatedUnion.prototype._parse = function (input) {
2126
- var ctx = this._processInputParams(input).ctx;
1725
+ };
1726
+ class ZodDiscriminatedUnion extends ZodType {
1727
+ _parse(input) {
1728
+ const { ctx } = this._processInputParams(input);
2127
1729
  if (ctx.parsedType !== ZodParsedType.object) {
2128
1730
  addIssueToContext(ctx, {
2129
1731
  code: ZodIssueCode.invalid_type,
@@ -2132,9 +1734,9 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
2132
1734
  });
2133
1735
  return INVALID;
2134
1736
  }
2135
- var discriminator = this.discriminator;
2136
- var discriminatorValue = ctx.data[discriminator];
2137
- var option = this.options.get(discriminatorValue);
1737
+ const discriminator = this.discriminator;
1738
+ const discriminatorValue = ctx.data[discriminator];
1739
+ const option = this.options.get(discriminatorValue);
2138
1740
  if (!option) {
2139
1741
  addIssueToContext(ctx, {
2140
1742
  code: ZodIssueCode.invalid_union_discriminator,
@@ -2157,28 +1759,16 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
2157
1759
  parent: ctx,
2158
1760
  });
2159
1761
  }
2160
- };
2161
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "discriminator", {
2162
- get: function () {
2163
- return this._def.discriminator;
2164
- },
2165
- enumerable: false,
2166
- configurable: true
2167
- });
2168
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "validDiscriminatorValues", {
2169
- get: function () {
2170
- return Array.from(this.options.keys());
2171
- },
2172
- enumerable: false,
2173
- configurable: true
2174
- });
2175
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
2176
- get: function () {
2177
- return this._def.options;
2178
- },
2179
- enumerable: false,
2180
- configurable: true
2181
- });
1762
+ }
1763
+ get discriminator() {
1764
+ return this._def.discriminator;
1765
+ }
1766
+ get validDiscriminatorValues() {
1767
+ return Array.from(this.options.keys());
1768
+ }
1769
+ get options() {
1770
+ return this._def.options;
1771
+ }
2182
1772
  /**
2183
1773
  * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2184
1774
  * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
@@ -2187,12 +1777,12 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
2187
1777
  * @param types an array of object schemas
2188
1778
  * @param params
2189
1779
  */
2190
- ZodDiscriminatedUnion.create = function (discriminator, types, params) {
1780
+ static create(discriminator, types, params) {
2191
1781
  // Get all the valid discriminator values
2192
- var options = new Map();
1782
+ const options = new Map();
2193
1783
  try {
2194
- types.forEach(function (type) {
2195
- var discriminatorValue = type.shape[discriminator].value;
1784
+ types.forEach((type) => {
1785
+ const discriminatorValue = type.shape[discriminator].value;
2196
1786
  options.set(discriminatorValue, type);
2197
1787
  });
2198
1788
  }
@@ -2203,39 +1793,32 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
2203
1793
  if (options.size !== types.length) {
2204
1794
  throw new Error("Some of the discriminator values are not unique");
2205
1795
  }
2206
- return new ZodDiscriminatedUnion(__assign({ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion, discriminator: discriminator, options: options }, processCreateParams(params)));
2207
- };
2208
- return ZodDiscriminatedUnion;
2209
- }(ZodType));
1796
+ return new ZodDiscriminatedUnion({
1797
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
1798
+ discriminator,
1799
+ options,
1800
+ ...processCreateParams(params),
1801
+ });
1802
+ }
1803
+ }
2210
1804
  function mergeValues(a, b) {
2211
- var e_11, _a;
2212
- var aType = getParsedType(a);
2213
- var bType = getParsedType(b);
1805
+ const aType = getParsedType(a);
1806
+ const bType = getParsedType(b);
2214
1807
  if (a === b) {
2215
1808
  return { valid: true, data: a };
2216
1809
  }
2217
1810
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2218
- var bKeys_1 = util.objectKeys(b);
2219
- var sharedKeys = util
1811
+ const bKeys = util.objectKeys(b);
1812
+ const sharedKeys = util
2220
1813
  .objectKeys(a)
2221
- .filter(function (key) { return bKeys_1.indexOf(key) !== -1; });
2222
- var newObj = __assign(__assign({}, a), b);
2223
- try {
2224
- for (var sharedKeys_1 = __values(sharedKeys), sharedKeys_1_1 = sharedKeys_1.next(); !sharedKeys_1_1.done; sharedKeys_1_1 = sharedKeys_1.next()) {
2225
- var key = sharedKeys_1_1.value;
2226
- var sharedValue = mergeValues(a[key], b[key]);
2227
- if (!sharedValue.valid) {
2228
- return { valid: false };
2229
- }
2230
- newObj[key] = sharedValue.data;
2231
- }
2232
- }
2233
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
2234
- finally {
2235
- try {
2236
- if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
1814
+ .filter((key) => bKeys.indexOf(key) !== -1);
1815
+ const newObj = { ...a, ...b };
1816
+ for (const key of sharedKeys) {
1817
+ const sharedValue = mergeValues(a[key], b[key]);
1818
+ if (!sharedValue.valid) {
1819
+ return { valid: false };
2237
1820
  }
2238
- finally { if (e_11) throw e_11.error; }
1821
+ newObj[key] = sharedValue.data;
2239
1822
  }
2240
1823
  return { valid: true, data: newObj };
2241
1824
  }
@@ -2243,11 +1826,11 @@ function mergeValues(a, b) {
2243
1826
  if (a.length !== b.length) {
2244
1827
  return { valid: false };
2245
1828
  }
2246
- var newArray = [];
2247
- for (var index = 0; index < a.length; index++) {
2248
- var itemA = a[index];
2249
- var itemB = b[index];
2250
- var sharedValue = mergeValues(itemA, itemB);
1829
+ const newArray = [];
1830
+ for (let index = 0; index < a.length; index++) {
1831
+ const itemA = a[index];
1832
+ const itemB = b[index];
1833
+ const sharedValue = mergeValues(itemA, itemB);
2251
1834
  if (!sharedValue.valid) {
2252
1835
  return { valid: false };
2253
1836
  }
@@ -2264,18 +1847,14 @@ function mergeValues(a, b) {
2264
1847
  return { valid: false };
2265
1848
  }
2266
1849
  }
2267
- var ZodIntersection = /** @class */ (function (_super) {
2268
- __extends(ZodIntersection, _super);
2269
- function ZodIntersection() {
2270
- return _super !== null && _super.apply(this, arguments) || this;
2271
- }
2272
- ZodIntersection.prototype._parse = function (input) {
2273
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2274
- var handleParsed = function (parsedLeft, parsedRight) {
1850
+ class ZodIntersection extends ZodType {
1851
+ _parse(input) {
1852
+ const { status, ctx } = this._processInputParams(input);
1853
+ const handleParsed = (parsedLeft, parsedRight) => {
2275
1854
  if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2276
1855
  return INVALID;
2277
1856
  }
2278
- var merged = mergeValues(parsedLeft.value, parsedRight.value);
1857
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2279
1858
  if (!merged.valid) {
2280
1859
  addIssueToContext(ctx, {
2281
1860
  code: ZodIssueCode.invalid_intersection_types,
@@ -2299,10 +1878,7 @@ var ZodIntersection = /** @class */ (function (_super) {
2299
1878
  path: ctx.path,
2300
1879
  parent: ctx,
2301
1880
  }),
2302
- ]).then(function (_a) {
2303
- var _b = __read(_a, 2), left = _b[0], right = _b[1];
2304
- return handleParsed(left, right);
2305
- });
1881
+ ]).then(([left, right]) => handleParsed(left, right));
2306
1882
  }
2307
1883
  else {
2308
1884
  return handleParsed(this._def.left._parseSync({
@@ -2315,20 +1891,19 @@ var ZodIntersection = /** @class */ (function (_super) {
2315
1891
  parent: ctx,
2316
1892
  }));
2317
1893
  }
2318
- };
2319
- ZodIntersection.create = function (left, right, params) {
2320
- return new ZodIntersection(__assign({ left: left, right: right, typeName: ZodFirstPartyTypeKind.ZodIntersection }, processCreateParams(params)));
2321
- };
2322
- return ZodIntersection;
2323
- }(ZodType));
2324
- var ZodTuple = /** @class */ (function (_super) {
2325
- __extends(ZodTuple, _super);
2326
- function ZodTuple() {
2327
- return _super !== null && _super.apply(this, arguments) || this;
2328
- }
2329
- ZodTuple.prototype._parse = function (input) {
2330
- var _this = this;
2331
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1894
+ }
1895
+ }
1896
+ ZodIntersection.create = (left, right, params) => {
1897
+ return new ZodIntersection({
1898
+ left: left,
1899
+ right: right,
1900
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
1901
+ ...processCreateParams(params),
1902
+ });
1903
+ };
1904
+ class ZodTuple extends ZodType {
1905
+ _parse(input) {
1906
+ const { status, ctx } = this._processInputParams(input);
2332
1907
  if (ctx.parsedType !== ZodParsedType.array) {
2333
1908
  addIssueToContext(ctx, {
2334
1909
  code: ZodIssueCode.invalid_type,
@@ -2346,7 +1921,7 @@ var ZodTuple = /** @class */ (function (_super) {
2346
1921
  });
2347
1922
  return INVALID;
2348
1923
  }
2349
- var rest = this._def.rest;
1924
+ const rest = this._def.rest;
2350
1925
  if (!rest && ctx.data.length > this._def.items.length) {
2351
1926
  addIssueToContext(ctx, {
2352
1927
  code: ZodIssueCode.too_big,
@@ -2356,63 +1931,54 @@ var ZodTuple = /** @class */ (function (_super) {
2356
1931
  });
2357
1932
  status.dirty();
2358
1933
  }
2359
- var items = ctx.data
2360
- .map(function (item, itemIndex) {
2361
- var schema = _this._def.items[itemIndex] || _this._def.rest;
1934
+ const items = ctx.data
1935
+ .map((item, itemIndex) => {
1936
+ const schema = this._def.items[itemIndex] || this._def.rest;
2362
1937
  if (!schema)
2363
1938
  return null;
2364
1939
  return schema._parse({
2365
1940
  data: item,
2366
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [itemIndex], false),
1941
+ path: [...ctx.path, itemIndex],
2367
1942
  parent: ctx,
2368
1943
  });
2369
1944
  })
2370
- .filter(function (x) { return !!x; }); // filter nulls
1945
+ .filter((x) => !!x); // filter nulls
2371
1946
  if (ctx.async) {
2372
- return Promise.all(items).then(function (results) {
1947
+ return Promise.all(items).then((results) => {
2373
1948
  return ParseStatus.mergeArray(status, results);
2374
1949
  });
2375
1950
  }
2376
1951
  else {
2377
1952
  return ParseStatus.mergeArray(status, items);
2378
1953
  }
2379
- };
2380
- Object.defineProperty(ZodTuple.prototype, "items", {
2381
- get: function () {
2382
- return this._def.items;
2383
- },
2384
- enumerable: false,
2385
- configurable: true
2386
- });
2387
- ZodTuple.prototype.rest = function (rest) {
2388
- return new ZodTuple(__assign(__assign({}, this._def), { rest: rest }));
2389
- };
2390
- ZodTuple.create = function (schemas, params) {
2391
- return new ZodTuple(__assign({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null }, processCreateParams(params)));
2392
- };
2393
- return ZodTuple;
2394
- }(ZodType));
2395
- var ZodRecord = /** @class */ (function (_super) {
2396
- __extends(ZodRecord, _super);
2397
- function ZodRecord() {
2398
- return _super !== null && _super.apply(this, arguments) || this;
2399
- }
2400
- Object.defineProperty(ZodRecord.prototype, "keySchema", {
2401
- get: function () {
2402
- return this._def.keyType;
2403
- },
2404
- enumerable: false,
2405
- configurable: true
2406
- });
2407
- Object.defineProperty(ZodRecord.prototype, "valueSchema", {
2408
- get: function () {
2409
- return this._def.valueType;
2410
- },
2411
- enumerable: false,
2412
- configurable: true
1954
+ }
1955
+ get items() {
1956
+ return this._def.items;
1957
+ }
1958
+ rest(rest) {
1959
+ return new ZodTuple({
1960
+ ...this._def,
1961
+ rest,
1962
+ });
1963
+ }
1964
+ }
1965
+ ZodTuple.create = (schemas, params) => {
1966
+ return new ZodTuple({
1967
+ items: schemas,
1968
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
1969
+ rest: null,
1970
+ ...processCreateParams(params),
2413
1971
  });
2414
- ZodRecord.prototype._parse = function (input) {
2415
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1972
+ };
1973
+ class ZodRecord extends ZodType {
1974
+ get keySchema() {
1975
+ return this._def.keyType;
1976
+ }
1977
+ get valueSchema() {
1978
+ return this._def.valueType;
1979
+ }
1980
+ _parse(input) {
1981
+ const { status, ctx } = this._processInputParams(input);
2416
1982
  if (ctx.parsedType !== ZodParsedType.object) {
2417
1983
  addIssueToContext(ctx, {
2418
1984
  code: ZodIssueCode.invalid_type,
@@ -2421,19 +1987,19 @@ var ZodRecord = /** @class */ (function (_super) {
2421
1987
  });
2422
1988
  return INVALID;
2423
1989
  }
2424
- var pairs = [];
2425
- var keyType = this._def.keyType;
2426
- var valueType = this._def.valueType;
2427
- for (var key in ctx.data) {
1990
+ const pairs = [];
1991
+ const keyType = this._def.keyType;
1992
+ const valueType = this._def.valueType;
1993
+ for (const key in ctx.data) {
2428
1994
  pairs.push({
2429
1995
  key: keyType._parse({
2430
1996
  data: key,
2431
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
1997
+ path: [...ctx.path, key],
2432
1998
  parent: ctx,
2433
1999
  }),
2434
2000
  value: valueType._parse({
2435
2001
  data: ctx.data[key],
2436
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
2002
+ path: [...ctx.path, key],
2437
2003
  parent: ctx,
2438
2004
  }),
2439
2005
  });
@@ -2444,31 +2010,30 @@ var ZodRecord = /** @class */ (function (_super) {
2444
2010
  else {
2445
2011
  return ParseStatus.mergeObjectSync(status, pairs);
2446
2012
  }
2447
- };
2448
- Object.defineProperty(ZodRecord.prototype, "element", {
2449
- get: function () {
2450
- return this._def.valueType;
2451
- },
2452
- enumerable: false,
2453
- configurable: true
2454
- });
2455
- ZodRecord.create = function (first, second, third) {
2013
+ }
2014
+ get element() {
2015
+ return this._def.valueType;
2016
+ }
2017
+ static create(first, second, third) {
2456
2018
  if (second instanceof ZodType) {
2457
- return new ZodRecord(__assign({ keyType: first, valueType: second, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(third)));
2019
+ return new ZodRecord({
2020
+ keyType: first,
2021
+ valueType: second,
2022
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2023
+ ...processCreateParams(third),
2024
+ });
2458
2025
  }
2459
- return new ZodRecord(__assign({ keyType: ZodString.create(), valueType: first, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(second)));
2460
- };
2461
- return ZodRecord;
2462
- }(ZodType));
2463
- var ZodMap = /** @class */ (function (_super) {
2464
- __extends(ZodMap, _super);
2465
- function ZodMap() {
2466
- return _super !== null && _super.apply(this, arguments) || this;
2467
- }
2468
- ZodMap.prototype._parse = function (input) {
2469
- var e_12, _a;
2470
- var _this = this;
2471
- var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
2026
+ return new ZodRecord({
2027
+ keyType: ZodString.create(),
2028
+ valueType: first,
2029
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2030
+ ...processCreateParams(second),
2031
+ });
2032
+ }
2033
+ }
2034
+ class ZodMap extends ZodType {
2035
+ _parse(input) {
2036
+ const { status, ctx } = this._processInputParams(input);
2472
2037
  if (ctx.parsedType !== ZodParsedType.map) {
2473
2038
  addIssueToContext(ctx, {
2474
2039
  code: ZodIssueCode.invalid_type,
@@ -2477,77 +2042,28 @@ var ZodMap = /** @class */ (function (_super) {
2477
2042
  });
2478
2043
  return INVALID;
2479
2044
  }
2480
- var keyType = this._def.keyType;
2481
- var valueType = this._def.valueType;
2482
- var pairs = __spreadArray([], __read(ctx.data.entries()), false).map(function (_a, index) {
2483
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
2045
+ const keyType = this._def.keyType;
2046
+ const valueType = this._def.valueType;
2047
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2484
2048
  return {
2485
2049
  key: keyType._parse({
2486
2050
  data: key,
2487
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "key"], false),
2051
+ path: [...ctx.path, index, "key"],
2488
2052
  parent: ctx,
2489
2053
  }),
2490
2054
  value: valueType._parse({
2491
2055
  data: value,
2492
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "value"], false),
2056
+ path: [...ctx.path, index, "value"],
2493
2057
  parent: ctx,
2494
2058
  }),
2495
2059
  };
2496
2060
  });
2497
2061
  if (ctx.async) {
2498
- var finalMap_1 = new Map();
2499
- return Promise.resolve().then(function () { return __awaiter(_this, void 0, void 0, function () {
2500
- var pairs_3, pairs_3_1, pair, key, value, e_13_1;
2501
- var e_13, _a;
2502
- return __generator(this, function (_b) {
2503
- switch (_b.label) {
2504
- case 0:
2505
- _b.trys.push([0, 6, 7, 8]);
2506
- pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
2507
- _b.label = 1;
2508
- case 1:
2509
- if (!!pairs_3_1.done) return [3 /*break*/, 5];
2510
- pair = pairs_3_1.value;
2511
- return [4 /*yield*/, pair.key];
2512
- case 2:
2513
- key = _b.sent();
2514
- return [4 /*yield*/, pair.value];
2515
- case 3:
2516
- value = _b.sent();
2517
- if (key.status === "aborted" || value.status === "aborted") {
2518
- return [2 /*return*/, INVALID];
2519
- }
2520
- if (key.status === "dirty" || value.status === "dirty") {
2521
- status.dirty();
2522
- }
2523
- finalMap_1.set(key.value, value.value);
2524
- _b.label = 4;
2525
- case 4:
2526
- pairs_3_1 = pairs_3.next();
2527
- return [3 /*break*/, 1];
2528
- case 5: return [3 /*break*/, 8];
2529
- case 6:
2530
- e_13_1 = _b.sent();
2531
- e_13 = { error: e_13_1 };
2532
- return [3 /*break*/, 8];
2533
- case 7:
2534
- try {
2535
- if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
2536
- }
2537
- finally { if (e_13) throw e_13.error; }
2538
- return [7 /*endfinally*/];
2539
- case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
2540
- }
2541
- });
2542
- }); });
2543
- }
2544
- else {
2545
- var finalMap = new Map();
2546
- try {
2547
- for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
2548
- var pair = pairs_2_1.value;
2549
- var key = pair.key;
2550
- var value = pair.value;
2062
+ const finalMap = new Map();
2063
+ return Promise.resolve().then(async () => {
2064
+ for (const pair of pairs) {
2065
+ const key = await pair.key;
2066
+ const value = await pair.value;
2551
2067
  if (key.status === "aborted" || value.status === "aborted") {
2552
2068
  return INVALID;
2553
2069
  }
@@ -2556,29 +2072,37 @@ var ZodMap = /** @class */ (function (_super) {
2556
2072
  }
2557
2073
  finalMap.set(key.value, value.value);
2558
2074
  }
2559
- }
2560
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
2561
- finally {
2562
- try {
2563
- if (pairs_2_1 && !pairs_2_1.done && (_a = pairs_2.return)) _a.call(pairs_2);
2075
+ return { status: status.value, value: finalMap };
2076
+ });
2077
+ }
2078
+ else {
2079
+ const finalMap = new Map();
2080
+ for (const pair of pairs) {
2081
+ const key = pair.key;
2082
+ const value = pair.value;
2083
+ if (key.status === "aborted" || value.status === "aborted") {
2084
+ return INVALID;
2085
+ }
2086
+ if (key.status === "dirty" || value.status === "dirty") {
2087
+ status.dirty();
2564
2088
  }
2565
- finally { if (e_12) throw e_12.error; }
2089
+ finalMap.set(key.value, value.value);
2566
2090
  }
2567
2091
  return { status: status.value, value: finalMap };
2568
2092
  }
2569
- };
2570
- ZodMap.create = function (keyType, valueType, params) {
2571
- return new ZodMap(__assign({ valueType: valueType, keyType: keyType, typeName: ZodFirstPartyTypeKind.ZodMap }, processCreateParams(params)));
2572
- };
2573
- return ZodMap;
2574
- }(ZodType));
2575
- var ZodSet = /** @class */ (function (_super) {
2576
- __extends(ZodSet, _super);
2577
- function ZodSet() {
2578
- return _super !== null && _super.apply(this, arguments) || this;
2579
- }
2580
- ZodSet.prototype._parse = function (input) {
2581
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2093
+ }
2094
+ }
2095
+ ZodMap.create = (keyType, valueType, params) => {
2096
+ return new ZodMap({
2097
+ valueType,
2098
+ keyType,
2099
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2100
+ ...processCreateParams(params),
2101
+ });
2102
+ };
2103
+ class ZodSet extends ZodType {
2104
+ _parse(input) {
2105
+ const { status, ctx } = this._processInputParams(input);
2582
2106
  if (ctx.parsedType !== ZodParsedType.set) {
2583
2107
  addIssueToContext(ctx, {
2584
2108
  code: ZodIssueCode.invalid_type,
@@ -2587,7 +2111,7 @@ var ZodSet = /** @class */ (function (_super) {
2587
2111
  });
2588
2112
  return INVALID;
2589
2113
  }
2590
- var def = this._def;
2114
+ const def = this._def;
2591
2115
  if (def.minSize !== null) {
2592
2116
  if (ctx.data.size < def.minSize.value) {
2593
2117
  addIssueToContext(ctx, {
@@ -2612,66 +2136,61 @@ var ZodSet = /** @class */ (function (_super) {
2612
2136
  status.dirty();
2613
2137
  }
2614
2138
  }
2615
- var valueType = this._def.valueType;
2139
+ const valueType = this._def.valueType;
2616
2140
  function finalizeSet(elements) {
2617
- var e_14, _a;
2618
- var parsedSet = new Set();
2619
- try {
2620
- for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
2621
- var element = elements_1_1.value;
2622
- if (element.status === "aborted")
2623
- return INVALID;
2624
- if (element.status === "dirty")
2625
- status.dirty();
2626
- parsedSet.add(element.value);
2627
- }
2628
- }
2629
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
2630
- finally {
2631
- try {
2632
- if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
2633
- }
2634
- finally { if (e_14) throw e_14.error; }
2141
+ const parsedSet = new Set();
2142
+ for (const element of elements) {
2143
+ if (element.status === "aborted")
2144
+ return INVALID;
2145
+ if (element.status === "dirty")
2146
+ status.dirty();
2147
+ parsedSet.add(element.value);
2635
2148
  }
2636
2149
  return { status: status.value, value: parsedSet };
2637
2150
  }
2638
- var elements = __spreadArray([], __read(ctx.data.values()), false).map(function (item, i) {
2639
- return valueType._parse({ data: item, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false), parent: ctx });
2640
- });
2151
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx }));
2641
2152
  if (ctx.async) {
2642
- return Promise.all(elements).then(function (elements) { return finalizeSet(elements); });
2153
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
2643
2154
  }
2644
2155
  else {
2645
2156
  return finalizeSet(elements);
2646
2157
  }
2647
- };
2648
- ZodSet.prototype.min = function (minSize, message) {
2649
- return new ZodSet(__assign(__assign({}, this._def), { minSize: { value: minSize, message: errorUtil.toString(message) } }));
2650
- };
2651
- ZodSet.prototype.max = function (maxSize, message) {
2652
- return new ZodSet(__assign(__assign({}, this._def), { maxSize: { value: maxSize, message: errorUtil.toString(message) } }));
2653
- };
2654
- ZodSet.prototype.size = function (size, message) {
2158
+ }
2159
+ min(minSize, message) {
2160
+ return new ZodSet({
2161
+ ...this._def,
2162
+ minSize: { value: minSize, message: errorUtil.toString(message) },
2163
+ });
2164
+ }
2165
+ max(maxSize, message) {
2166
+ return new ZodSet({
2167
+ ...this._def,
2168
+ maxSize: { value: maxSize, message: errorUtil.toString(message) },
2169
+ });
2170
+ }
2171
+ size(size, message) {
2655
2172
  return this.min(size, message).max(size, message);
2656
- };
2657
- ZodSet.prototype.nonempty = function (message) {
2173
+ }
2174
+ nonempty(message) {
2658
2175
  return this.min(1, message);
2659
- };
2660
- ZodSet.create = function (valueType, params) {
2661
- return new ZodSet(__assign({ valueType: valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet }, processCreateParams(params)));
2662
- };
2663
- return ZodSet;
2664
- }(ZodType));
2665
- var ZodFunction = /** @class */ (function (_super) {
2666
- __extends(ZodFunction, _super);
2667
- function ZodFunction() {
2668
- var _this = _super !== null && _super.apply(this, arguments) || this;
2669
- _this.validate = _this.implement;
2670
- return _this;
2671
- }
2672
- ZodFunction.prototype._parse = function (input) {
2673
- var _this = this;
2674
- var ctx = this._processInputParams(input).ctx;
2176
+ }
2177
+ }
2178
+ ZodSet.create = (valueType, params) => {
2179
+ return new ZodSet({
2180
+ valueType,
2181
+ minSize: null,
2182
+ maxSize: null,
2183
+ typeName: ZodFirstPartyTypeKind.ZodSet,
2184
+ ...processCreateParams(params),
2185
+ });
2186
+ };
2187
+ class ZodFunction extends ZodType {
2188
+ constructor() {
2189
+ super(...arguments);
2190
+ this.validate = this.implement;
2191
+ }
2192
+ _parse(input) {
2193
+ const { ctx } = this._processInputParams(input);
2675
2194
  if (ctx.parsedType !== ZodParsedType.function) {
2676
2195
  addIssueToContext(ctx, {
2677
2196
  code: ZodIssueCode.invalid_type,
@@ -2689,7 +2208,7 @@ var ZodFunction = /** @class */ (function (_super) {
2689
2208
  ctx.schemaErrorMap,
2690
2209
  overrideErrorMap,
2691
2210
  defaultErrorMap,
2692
- ].filter(function (x) { return !!x; }),
2211
+ ].filter((x) => !!x),
2693
2212
  issueData: {
2694
2213
  code: ZodIssueCode.invalid_arguments,
2695
2214
  argumentsError: error,
@@ -2705,132 +2224,106 @@ var ZodFunction = /** @class */ (function (_super) {
2705
2224
  ctx.schemaErrorMap,
2706
2225
  overrideErrorMap,
2707
2226
  defaultErrorMap,
2708
- ].filter(function (x) { return !!x; }),
2227
+ ].filter((x) => !!x),
2709
2228
  issueData: {
2710
2229
  code: ZodIssueCode.invalid_return_type,
2711
2230
  returnTypeError: error,
2712
2231
  },
2713
2232
  });
2714
2233
  }
2715
- var params = { errorMap: ctx.contextualErrorMap };
2716
- var fn = ctx.data;
2234
+ const params = { errorMap: ctx.contextualErrorMap };
2235
+ const fn = ctx.data;
2717
2236
  if (this._def.returns instanceof ZodPromise) {
2718
- return OK(function () {
2719
- var args = [];
2720
- for (var _i = 0; _i < arguments.length; _i++) {
2721
- args[_i] = arguments[_i];
2722
- }
2723
- return __awaiter(_this, void 0, void 0, function () {
2724
- var error, parsedArgs, result, parsedReturns;
2725
- return __generator(this, function (_a) {
2726
- switch (_a.label) {
2727
- case 0:
2728
- error = new ZodError([]);
2729
- return [4 /*yield*/, this._def.args
2730
- .parseAsync(args, params)
2731
- .catch(function (e) {
2732
- error.addIssue(makeArgsIssue(args, e));
2733
- throw error;
2734
- })];
2735
- case 1:
2736
- parsedArgs = _a.sent();
2737
- return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
2738
- case 2:
2739
- result = _a.sent();
2740
- return [4 /*yield*/, this._def
2741
- .returns._def.type
2742
- .parseAsync(result, params)
2743
- .catch(function (e) {
2744
- error.addIssue(makeReturnsIssue(result, e));
2745
- throw error;
2746
- })];
2747
- case 3:
2748
- parsedReturns = _a.sent();
2749
- return [2 /*return*/, parsedReturns];
2750
- }
2751
- });
2237
+ return OK(async (...args) => {
2238
+ const error = new ZodError([]);
2239
+ const parsedArgs = await this._def.args
2240
+ .parseAsync(args, params)
2241
+ .catch((e) => {
2242
+ error.addIssue(makeArgsIssue(args, e));
2243
+ throw error;
2244
+ });
2245
+ const result = await fn(...parsedArgs);
2246
+ const parsedReturns = await this._def.returns._def.type
2247
+ .parseAsync(result, params)
2248
+ .catch((e) => {
2249
+ error.addIssue(makeReturnsIssue(result, e));
2250
+ throw error;
2752
2251
  });
2252
+ return parsedReturns;
2753
2253
  });
2754
2254
  }
2755
2255
  else {
2756
- return OK(function () {
2757
- var args = [];
2758
- for (var _i = 0; _i < arguments.length; _i++) {
2759
- args[_i] = arguments[_i];
2760
- }
2761
- var parsedArgs = _this._def.args.safeParse(args, params);
2256
+ return OK((...args) => {
2257
+ const parsedArgs = this._def.args.safeParse(args, params);
2762
2258
  if (!parsedArgs.success) {
2763
2259
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
2764
2260
  }
2765
- var result = fn.apply(void 0, __spreadArray([], __read(parsedArgs.data), false));
2766
- var parsedReturns = _this._def.returns.safeParse(result, params);
2261
+ const result = fn(...parsedArgs.data);
2262
+ const parsedReturns = this._def.returns.safeParse(result, params);
2767
2263
  if (!parsedReturns.success) {
2768
2264
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2769
2265
  }
2770
2266
  return parsedReturns.data;
2771
2267
  });
2772
2268
  }
2773
- };
2774
- ZodFunction.prototype.parameters = function () {
2269
+ }
2270
+ parameters() {
2775
2271
  return this._def.args;
2776
- };
2777
- ZodFunction.prototype.returnType = function () {
2272
+ }
2273
+ returnType() {
2778
2274
  return this._def.returns;
2779
- };
2780
- ZodFunction.prototype.args = function () {
2781
- var items = [];
2782
- for (var _i = 0; _i < arguments.length; _i++) {
2783
- items[_i] = arguments[_i];
2784
- }
2785
- return new ZodFunction(__assign(__assign({}, this._def), { args: ZodTuple.create(items).rest(ZodUnknown.create()) }));
2786
- };
2787
- ZodFunction.prototype.returns = function (returnType) {
2788
- return new ZodFunction(__assign(__assign({}, this._def), { returns: returnType }));
2789
- };
2790
- ZodFunction.prototype.implement = function (func) {
2791
- var validatedFunc = this.parse(func);
2275
+ }
2276
+ args(...items) {
2277
+ return new ZodFunction({
2278
+ ...this._def,
2279
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
2280
+ });
2281
+ }
2282
+ returns(returnType) {
2283
+ return new ZodFunction({
2284
+ ...this._def,
2285
+ returns: returnType,
2286
+ });
2287
+ }
2288
+ implement(func) {
2289
+ const validatedFunc = this.parse(func);
2792
2290
  return validatedFunc;
2793
- };
2794
- ZodFunction.prototype.strictImplement = function (func) {
2795
- var validatedFunc = this.parse(func);
2291
+ }
2292
+ strictImplement(func) {
2293
+ const validatedFunc = this.parse(func);
2796
2294
  return validatedFunc;
2797
- };
2798
- ZodFunction.create = function (args, returns, params) {
2799
- return new ZodFunction(__assign({ args: (args
2800
- ? args.rest(ZodUnknown.create())
2801
- : ZodTuple.create([]).rest(ZodUnknown.create())), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction }, processCreateParams(params)));
2802
- };
2803
- return ZodFunction;
2804
- }(ZodType));
2805
- var ZodLazy = /** @class */ (function (_super) {
2806
- __extends(ZodLazy, _super);
2807
- function ZodLazy() {
2808
- return _super !== null && _super.apply(this, arguments) || this;
2809
- }
2810
- Object.defineProperty(ZodLazy.prototype, "schema", {
2811
- get: function () {
2812
- return this._def.getter();
2813
- },
2814
- enumerable: false,
2815
- configurable: true
2295
+ }
2296
+ }
2297
+ ZodFunction.create = (args, returns, params) => {
2298
+ return new ZodFunction({
2299
+ args: (args
2300
+ ? args.rest(ZodUnknown.create())
2301
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
2302
+ returns: returns || ZodUnknown.create(),
2303
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
2304
+ ...processCreateParams(params),
2816
2305
  });
2817
- ZodLazy.prototype._parse = function (input) {
2818
- var ctx = this._processInputParams(input).ctx;
2819
- var lazySchema = this._def.getter();
2306
+ };
2307
+ class ZodLazy extends ZodType {
2308
+ get schema() {
2309
+ return this._def.getter();
2310
+ }
2311
+ _parse(input) {
2312
+ const { ctx } = this._processInputParams(input);
2313
+ const lazySchema = this._def.getter();
2820
2314
  return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
2821
- };
2822
- ZodLazy.create = function (getter, params) {
2823
- return new ZodLazy(__assign({ getter: getter, typeName: ZodFirstPartyTypeKind.ZodLazy }, processCreateParams(params)));
2824
- };
2825
- return ZodLazy;
2826
- }(ZodType));
2827
- var ZodLiteral = /** @class */ (function (_super) {
2828
- __extends(ZodLiteral, _super);
2829
- function ZodLiteral() {
2830
- return _super !== null && _super.apply(this, arguments) || this;
2831
- }
2832
- ZodLiteral.prototype._parse = function (input) {
2833
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2315
+ }
2316
+ }
2317
+ ZodLazy.create = (getter, params) => {
2318
+ return new ZodLazy({
2319
+ getter: getter,
2320
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
2321
+ ...processCreateParams(params),
2322
+ });
2323
+ };
2324
+ class ZodLiteral extends ZodType {
2325
+ _parse(input) {
2326
+ const { status, ctx } = this._processInputParams(input);
2834
2327
  if (ctx.data !== this._def.value) {
2835
2328
  addIssueToContext(ctx, {
2836
2329
  code: ZodIssueCode.invalid_type,
@@ -2840,32 +2333,27 @@ var ZodLiteral = /** @class */ (function (_super) {
2840
2333
  return INVALID;
2841
2334
  }
2842
2335
  return { status: status.value, value: ctx.data };
2843
- };
2844
- Object.defineProperty(ZodLiteral.prototype, "value", {
2845
- get: function () {
2846
- return this._def.value;
2847
- },
2848
- enumerable: false,
2849
- configurable: true
2336
+ }
2337
+ get value() {
2338
+ return this._def.value;
2339
+ }
2340
+ }
2341
+ ZodLiteral.create = (value, params) => {
2342
+ return new ZodLiteral({
2343
+ value: value,
2344
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
2345
+ ...processCreateParams(params),
2850
2346
  });
2851
- ZodLiteral.create = function (value, params) {
2852
- return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
2853
- };
2854
- return ZodLiteral;
2855
- }(ZodType));
2347
+ };
2856
2348
  function createZodEnum(values) {
2857
2349
  return new ZodEnum({
2858
2350
  values: values,
2859
2351
  typeName: ZodFirstPartyTypeKind.ZodEnum,
2860
2352
  });
2861
2353
  }
2862
- var ZodEnum = /** @class */ (function (_super) {
2863
- __extends(ZodEnum, _super);
2864
- function ZodEnum() {
2865
- return _super !== null && _super.apply(this, arguments) || this;
2866
- }
2867
- ZodEnum.prototype._parse = function (input) {
2868
- var ctx = this._processInputParams(input).ctx;
2354
+ class ZodEnum extends ZodType {
2355
+ _parse(input) {
2356
+ const { ctx } = this._processInputParams(input);
2869
2357
  if (this._def.values.indexOf(ctx.data) === -1) {
2870
2358
  addIssueToContext(ctx, {
2871
2359
  code: ZodIssueCode.invalid_enum_value,
@@ -2874,91 +2362,37 @@ var ZodEnum = /** @class */ (function (_super) {
2874
2362
  return INVALID;
2875
2363
  }
2876
2364
  return OK(ctx.data);
2877
- };
2878
- Object.defineProperty(ZodEnum.prototype, "options", {
2879
- get: function () {
2880
- return this._def.values;
2881
- },
2882
- enumerable: false,
2883
- configurable: true
2884
- });
2885
- Object.defineProperty(ZodEnum.prototype, "enum", {
2886
- get: function () {
2887
- var e_15, _a;
2888
- var enumValues = {};
2889
- try {
2890
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2891
- var val = _c.value;
2892
- enumValues[val] = val;
2893
- }
2894
- }
2895
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
2896
- finally {
2897
- try {
2898
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2899
- }
2900
- finally { if (e_15) throw e_15.error; }
2901
- }
2902
- return enumValues;
2903
- },
2904
- enumerable: false,
2905
- configurable: true
2906
- });
2907
- Object.defineProperty(ZodEnum.prototype, "Values", {
2908
- get: function () {
2909
- var e_16, _a;
2910
- var enumValues = {};
2911
- try {
2912
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2913
- var val = _c.value;
2914
- enumValues[val] = val;
2915
- }
2916
- }
2917
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
2918
- finally {
2919
- try {
2920
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2921
- }
2922
- finally { if (e_16) throw e_16.error; }
2923
- }
2924
- return enumValues;
2925
- },
2926
- enumerable: false,
2927
- configurable: true
2928
- });
2929
- Object.defineProperty(ZodEnum.prototype, "Enum", {
2930
- get: function () {
2931
- var e_17, _a;
2932
- var enumValues = {};
2933
- try {
2934
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2935
- var val = _c.value;
2936
- enumValues[val] = val;
2937
- }
2938
- }
2939
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
2940
- finally {
2941
- try {
2942
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2943
- }
2944
- finally { if (e_17) throw e_17.error; }
2945
- }
2946
- return enumValues;
2947
- },
2948
- enumerable: false,
2949
- configurable: true
2950
- });
2951
- ZodEnum.create = createZodEnum;
2952
- return ZodEnum;
2953
- }(ZodType));
2954
- var ZodNativeEnum = /** @class */ (function (_super) {
2955
- __extends(ZodNativeEnum, _super);
2956
- function ZodNativeEnum() {
2957
- return _super !== null && _super.apply(this, arguments) || this;
2958
- }
2959
- ZodNativeEnum.prototype._parse = function (input) {
2960
- var ctx = this._processInputParams(input).ctx;
2961
- var nativeEnumValues = util.getValidEnumValues(this._def.values);
2365
+ }
2366
+ get options() {
2367
+ return this._def.values;
2368
+ }
2369
+ get enum() {
2370
+ const enumValues = {};
2371
+ for (const val of this._def.values) {
2372
+ enumValues[val] = val;
2373
+ }
2374
+ return enumValues;
2375
+ }
2376
+ get Values() {
2377
+ const enumValues = {};
2378
+ for (const val of this._def.values) {
2379
+ enumValues[val] = val;
2380
+ }
2381
+ return enumValues;
2382
+ }
2383
+ get Enum() {
2384
+ const enumValues = {};
2385
+ for (const val of this._def.values) {
2386
+ enumValues[val] = val;
2387
+ }
2388
+ return enumValues;
2389
+ }
2390
+ }
2391
+ ZodEnum.create = createZodEnum;
2392
+ class ZodNativeEnum extends ZodType {
2393
+ _parse(input) {
2394
+ const { ctx } = this._processInputParams(input);
2395
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
2962
2396
  if (nativeEnumValues.indexOf(ctx.data) === -1) {
2963
2397
  addIssueToContext(ctx, {
2964
2398
  code: ZodIssueCode.invalid_enum_value,
@@ -2967,20 +2401,21 @@ var ZodNativeEnum = /** @class */ (function (_super) {
2967
2401
  return INVALID;
2968
2402
  }
2969
2403
  return OK(ctx.data);
2970
- };
2971
- ZodNativeEnum.create = function (values, params) {
2972
- return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
2973
- };
2974
- return ZodNativeEnum;
2975
- }(ZodType));
2976
- var ZodPromise = /** @class */ (function (_super) {
2977
- __extends(ZodPromise, _super);
2978
- function ZodPromise() {
2979
- return _super !== null && _super.apply(this, arguments) || this;
2980
- }
2981
- ZodPromise.prototype._parse = function (input) {
2982
- var _this = this;
2983
- var ctx = this._processInputParams(input).ctx;
2404
+ }
2405
+ get enum() {
2406
+ return this._def.values;
2407
+ }
2408
+ }
2409
+ ZodNativeEnum.create = (values, params) => {
2410
+ return new ZodNativeEnum({
2411
+ values: values,
2412
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
2413
+ ...processCreateParams(params),
2414
+ });
2415
+ };
2416
+ class ZodPromise extends ZodType {
2417
+ _parse(input) {
2418
+ const { ctx } = this._processInputParams(input);
2984
2419
  if (ctx.parsedType !== ZodParsedType.promise && ctx.async === false) {
2985
2420
  addIssueToContext(ctx, {
2986
2421
  code: ZodIssueCode.invalid_type,
@@ -2989,38 +2424,36 @@ var ZodPromise = /** @class */ (function (_super) {
2989
2424
  });
2990
2425
  return INVALID;
2991
2426
  }
2992
- var promisified = ctx.parsedType === ZodParsedType.promise
2427
+ const promisified = ctx.parsedType === ZodParsedType.promise
2993
2428
  ? ctx.data
2994
2429
  : Promise.resolve(ctx.data);
2995
- return OK(promisified.then(function (data) {
2996
- return _this._def.type.parseAsync(data, {
2430
+ return OK(promisified.then((data) => {
2431
+ return this._def.type.parseAsync(data, {
2997
2432
  path: ctx.path,
2998
2433
  errorMap: ctx.contextualErrorMap,
2999
2434
  });
3000
2435
  }));
3001
- };
3002
- ZodPromise.create = function (schema, params) {
3003
- return new ZodPromise(__assign({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise }, processCreateParams(params)));
3004
- };
3005
- return ZodPromise;
3006
- }(ZodType));
3007
- var ZodEffects = /** @class */ (function (_super) {
3008
- __extends(ZodEffects, _super);
3009
- function ZodEffects() {
3010
- return _super !== null && _super.apply(this, arguments) || this;
3011
- }
3012
- ZodEffects.prototype.innerType = function () {
2436
+ }
2437
+ }
2438
+ ZodPromise.create = (schema, params) => {
2439
+ return new ZodPromise({
2440
+ type: schema,
2441
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
2442
+ ...processCreateParams(params),
2443
+ });
2444
+ };
2445
+ class ZodEffects extends ZodType {
2446
+ innerType() {
3013
2447
  return this._def.schema;
3014
- };
3015
- ZodEffects.prototype._parse = function (input) {
3016
- var _this = this;
3017
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
3018
- var effect = this._def.effect || null;
2448
+ }
2449
+ _parse(input) {
2450
+ const { status, ctx } = this._processInputParams(input);
2451
+ const effect = this._def.effect || null;
3019
2452
  if (effect.type === "preprocess") {
3020
- var processed = effect.transform(ctx.data);
2453
+ const processed = effect.transform(ctx.data);
3021
2454
  if (ctx.async) {
3022
- return Promise.resolve(processed).then(function (processed) {
3023
- return _this._def.schema._parseAsync({
2455
+ return Promise.resolve(processed).then((processed) => {
2456
+ return this._def.schema._parseAsync({
3024
2457
  data: processed,
3025
2458
  path: ctx.path,
3026
2459
  parent: ctx,
@@ -3036,8 +2469,8 @@ var ZodEffects = /** @class */ (function (_super) {
3036
2469
  }
3037
2470
  }
3038
2471
  if (effect.type === "refinement") {
3039
- var checkCtx_1 = {
3040
- addIssue: function (arg) {
2472
+ const checkCtx = {
2473
+ addIssue: (arg) => {
3041
2474
  addIssueToContext(ctx, arg);
3042
2475
  if (arg.fatal) {
3043
2476
  status.abort();
@@ -3050,11 +2483,11 @@ var ZodEffects = /** @class */ (function (_super) {
3050
2483
  return ctx.path;
3051
2484
  },
3052
2485
  };
3053
- checkCtx_1.addIssue = checkCtx_1.addIssue.bind(checkCtx_1);
3054
- var executeRefinement_1 = function (acc
2486
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
2487
+ const executeRefinement = (acc
3055
2488
  // effect: RefinementEffect<any>
3056
- ) {
3057
- var result = effect.refinement(acc, checkCtx_1);
2489
+ ) => {
2490
+ const result = effect.refinement(acc, checkCtx);
3058
2491
  if (ctx.async) {
3059
2492
  return Promise.resolve(result);
3060
2493
  }
@@ -3064,7 +2497,7 @@ var ZodEffects = /** @class */ (function (_super) {
3064
2497
  return acc;
3065
2498
  };
3066
2499
  if (ctx.async === false) {
3067
- var inner = this._def.schema._parseSync({
2500
+ const inner = this._def.schema._parseSync({
3068
2501
  data: ctx.data,
3069
2502
  path: ctx.path,
3070
2503
  parent: ctx,
@@ -3074,18 +2507,18 @@ var ZodEffects = /** @class */ (function (_super) {
3074
2507
  if (inner.status === "dirty")
3075
2508
  status.dirty();
3076
2509
  // return value is ignored
3077
- executeRefinement_1(inner.value);
2510
+ executeRefinement(inner.value);
3078
2511
  return { status: status.value, value: inner.value };
3079
2512
  }
3080
2513
  else {
3081
2514
  return this._def.schema
3082
2515
  ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3083
- .then(function (inner) {
2516
+ .then((inner) => {
3084
2517
  if (inner.status === "aborted")
3085
2518
  return INVALID;
3086
2519
  if (inner.status === "dirty")
3087
2520
  status.dirty();
3088
- return executeRefinement_1(inner.value).then(function () {
2521
+ return executeRefinement(inner.value).then(() => {
3089
2522
  return { status: status.value, value: inner.value };
3090
2523
  });
3091
2524
  });
@@ -3093,7 +2526,7 @@ var ZodEffects = /** @class */ (function (_super) {
3093
2526
  }
3094
2527
  if (effect.type === "transform") {
3095
2528
  if (ctx.async === false) {
3096
- var base = this._def.schema._parseSync({
2529
+ const base = this._def.schema._parseSync({
3097
2530
  data: ctx.data,
3098
2531
  path: ctx.path,
3099
2532
  parent: ctx,
@@ -3104,16 +2537,16 @@ var ZodEffects = /** @class */ (function (_super) {
3104
2537
  // }
3105
2538
  if (!isValid(base))
3106
2539
  return base;
3107
- var result = effect.transform(base.value);
2540
+ const result = effect.transform(base.value);
3108
2541
  if (result instanceof Promise) {
3109
- throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2542
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3110
2543
  }
3111
2544
  return OK(result);
3112
2545
  }
3113
2546
  else {
3114
2547
  return this._def.schema
3115
2548
  ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3116
- .then(function (base) {
2549
+ .then((base) => {
3117
2550
  if (!isValid(base))
3118
2551
  return base;
3119
2552
  // if (base.status === "aborted") return INVALID;
@@ -3125,22 +2558,27 @@ var ZodEffects = /** @class */ (function (_super) {
3125
2558
  }
3126
2559
  }
3127
2560
  util.assertNever(effect);
3128
- };
3129
- ZodEffects.create = function (schema, effect, params) {
3130
- return new ZodEffects(__assign({ schema: schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: effect }, processCreateParams(params)));
3131
- };
3132
- ZodEffects.createWithPreprocess = function (preprocess, schema, params) {
3133
- return new ZodEffects(__assign({ schema: schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects }, processCreateParams(params)));
3134
- };
3135
- return ZodEffects;
3136
- }(ZodType));
3137
- var ZodOptional = /** @class */ (function (_super) {
3138
- __extends(ZodOptional, _super);
3139
- function ZodOptional() {
3140
- return _super !== null && _super.apply(this, arguments) || this;
3141
- }
3142
- ZodOptional.prototype._parse = function (input) {
3143
- var ctx = this._processInputParams(input).ctx;
2561
+ }
2562
+ }
2563
+ ZodEffects.create = (schema, effect, params) => {
2564
+ return new ZodEffects({
2565
+ schema,
2566
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2567
+ effect,
2568
+ ...processCreateParams(params),
2569
+ });
2570
+ };
2571
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
2572
+ return new ZodEffects({
2573
+ schema,
2574
+ effect: { type: "preprocess", transform: preprocess },
2575
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2576
+ ...processCreateParams(params),
2577
+ });
2578
+ };
2579
+ class ZodOptional extends ZodType {
2580
+ _parse(input) {
2581
+ const { ctx } = this._processInputParams(input);
3144
2582
  if (ctx.parsedType === ZodParsedType.undefined) {
3145
2583
  return OK(undefined);
3146
2584
  }
@@ -3149,22 +2587,21 @@ var ZodOptional = /** @class */ (function (_super) {
3149
2587
  path: ctx.path,
3150
2588
  parent: ctx,
3151
2589
  });
3152
- };
3153
- ZodOptional.prototype.unwrap = function () {
2590
+ }
2591
+ unwrap() {
3154
2592
  return this._def.innerType;
3155
- };
3156
- ZodOptional.create = function (type, params) {
3157
- return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
3158
- };
3159
- return ZodOptional;
3160
- }(ZodType));
3161
- var ZodNullable = /** @class */ (function (_super) {
3162
- __extends(ZodNullable, _super);
3163
- function ZodNullable() {
3164
- return _super !== null && _super.apply(this, arguments) || this;
3165
- }
3166
- ZodNullable.prototype._parse = function (input) {
3167
- var ctx = this._processInputParams(input).ctx;
2593
+ }
2594
+ }
2595
+ ZodOptional.create = (type, params) => {
2596
+ return new ZodOptional({
2597
+ innerType: type,
2598
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
2599
+ ...processCreateParams(params),
2600
+ });
2601
+ };
2602
+ class ZodNullable extends ZodType {
2603
+ _parse(input) {
2604
+ const { ctx } = this._processInputParams(input);
3168
2605
  if (ctx.parsedType === ZodParsedType.null) {
3169
2606
  return OK(null);
3170
2607
  }
@@ -3173,47 +2610,45 @@ var ZodNullable = /** @class */ (function (_super) {
3173
2610
  path: ctx.path,
3174
2611
  parent: ctx,
3175
2612
  });
3176
- };
3177
- ZodNullable.prototype.unwrap = function () {
2613
+ }
2614
+ unwrap() {
3178
2615
  return this._def.innerType;
3179
- };
3180
- ZodNullable.create = function (type, params) {
3181
- return new ZodNullable(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable }, processCreateParams(params)));
3182
- };
3183
- return ZodNullable;
3184
- }(ZodType));
3185
- var ZodDefault = /** @class */ (function (_super) {
3186
- __extends(ZodDefault, _super);
3187
- function ZodDefault() {
3188
- return _super !== null && _super.apply(this, arguments) || this;
3189
- }
3190
- ZodDefault.prototype._parse = function (input) {
3191
- var ctx = this._processInputParams(input).ctx;
3192
- var data = ctx.data;
2616
+ }
2617
+ }
2618
+ ZodNullable.create = (type, params) => {
2619
+ return new ZodNullable({
2620
+ innerType: type,
2621
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
2622
+ ...processCreateParams(params),
2623
+ });
2624
+ };
2625
+ class ZodDefault extends ZodType {
2626
+ _parse(input) {
2627
+ const { ctx } = this._processInputParams(input);
2628
+ let data = ctx.data;
3193
2629
  if (ctx.parsedType === ZodParsedType.undefined) {
3194
2630
  data = this._def.defaultValue();
3195
2631
  }
3196
2632
  return this._def.innerType._parse({
3197
- data: data,
2633
+ data,
3198
2634
  path: ctx.path,
3199
2635
  parent: ctx,
3200
2636
  });
3201
- };
3202
- ZodDefault.prototype.removeDefault = function () {
2637
+ }
2638
+ removeDefault() {
3203
2639
  return this._def.innerType;
3204
- };
3205
- ZodDefault.create = function (type, params) {
3206
- return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
3207
- };
3208
- return ZodDefault;
3209
- }(ZodType));
3210
- var ZodNaN = /** @class */ (function (_super) {
3211
- __extends(ZodNaN, _super);
3212
- function ZodNaN() {
3213
- return _super !== null && _super.apply(this, arguments) || this;
3214
- }
3215
- ZodNaN.prototype._parse = function (input) {
3216
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2640
+ }
2641
+ }
2642
+ ZodDefault.create = (type, params) => {
2643
+ return new ZodOptional({
2644
+ innerType: type,
2645
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
2646
+ ...processCreateParams(params),
2647
+ });
2648
+ };
2649
+ class ZodNaN extends ZodType {
2650
+ _parse(input) {
2651
+ const { status, ctx } = this._processInputParams(input);
3217
2652
  if (ctx.parsedType !== ZodParsedType.nan) {
3218
2653
  addIssueToContext(ctx, {
3219
2654
  code: ZodIssueCode.invalid_type,
@@ -3223,18 +2658,20 @@ var ZodNaN = /** @class */ (function (_super) {
3223
2658
  return INVALID;
3224
2659
  }
3225
2660
  return { status: status.value, value: ctx.data };
3226
- };
3227
- ZodNaN.create = function (params) {
3228
- return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
3229
- };
3230
- return ZodNaN;
3231
- }(ZodType));
3232
- var custom = function (check, params) {
2661
+ }
2662
+ }
2663
+ ZodNaN.create = (params) => {
2664
+ return new ZodNaN({
2665
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
2666
+ ...processCreateParams(params),
2667
+ });
2668
+ };
2669
+ const custom = (check, params) => {
3233
2670
  if (check)
3234
2671
  return ZodAny.create().refine(check, params);
3235
2672
  return ZodAny.create();
3236
2673
  };
3237
- var late = {
2674
+ const late = {
3238
2675
  object: ZodObject.lazycreate,
3239
2676
  };
3240
2677
  var ZodFirstPartyTypeKind;
@@ -3271,47 +2708,44 @@ var ZodFirstPartyTypeKind;
3271
2708
  ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
3272
2709
  ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3273
2710
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3274
- var instanceOfType = function (cls, params) {
3275
- if (params === void 0) { params = {
3276
- message: "Input not instance of ".concat(cls.name),
3277
- }; }
3278
- return custom(function (data) { return data instanceof cls; }, params);
3279
- };
3280
- var stringType = ZodString.create;
3281
- var numberType = ZodNumber.create;
3282
- var nanType = ZodNaN.create;
3283
- var bigIntType = ZodBigInt.create;
3284
- var booleanType = ZodBoolean.create;
3285
- var dateType = ZodDate.create;
3286
- var undefinedType = ZodUndefined.create;
3287
- var nullType = ZodNull.create;
3288
- var anyType = ZodAny.create;
3289
- var unknownType = ZodUnknown.create;
3290
- var neverType = ZodNever.create;
3291
- var voidType = ZodVoid.create;
3292
- var arrayType = ZodArray.create;
3293
- var objectType = ZodObject.create;
3294
- var strictObjectType = ZodObject.strictCreate;
3295
- var unionType = ZodUnion.create;
3296
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
3297
- var intersectionType = ZodIntersection.create;
3298
- var tupleType = ZodTuple.create;
3299
- var recordType = ZodRecord.create;
3300
- var mapType = ZodMap.create;
3301
- var setType = ZodSet.create;
3302
- var functionType = ZodFunction.create;
3303
- var lazyType = ZodLazy.create;
3304
- var literalType = ZodLiteral.create;
3305
- var enumType = ZodEnum.create;
3306
- var nativeEnumType = ZodNativeEnum.create;
3307
- var promiseType = ZodPromise.create;
3308
- var effectsType = ZodEffects.create;
3309
- var optionalType = ZodOptional.create;
3310
- var nullableType = ZodNullable.create;
3311
- var preprocessType = ZodEffects.createWithPreprocess;
3312
- var ostring = function () { return stringType().optional(); };
3313
- var onumber = function () { return numberType().optional(); };
3314
- var oboolean = function () { return booleanType().optional(); };
2711
+ const instanceOfType = (cls, params = {
2712
+ message: `Input not instance of ${cls.name}`,
2713
+ }) => custom((data) => data instanceof cls, params);
2714
+ const stringType = ZodString.create;
2715
+ const numberType = ZodNumber.create;
2716
+ const nanType = ZodNaN.create;
2717
+ const bigIntType = ZodBigInt.create;
2718
+ const booleanType = ZodBoolean.create;
2719
+ const dateType = ZodDate.create;
2720
+ const undefinedType = ZodUndefined.create;
2721
+ const nullType = ZodNull.create;
2722
+ const anyType = ZodAny.create;
2723
+ const unknownType = ZodUnknown.create;
2724
+ const neverType = ZodNever.create;
2725
+ const voidType = ZodVoid.create;
2726
+ const arrayType = ZodArray.create;
2727
+ const objectType = ZodObject.create;
2728
+ const strictObjectType = ZodObject.strictCreate;
2729
+ const unionType = ZodUnion.create;
2730
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
2731
+ const intersectionType = ZodIntersection.create;
2732
+ const tupleType = ZodTuple.create;
2733
+ const recordType = ZodRecord.create;
2734
+ const mapType = ZodMap.create;
2735
+ const setType = ZodSet.create;
2736
+ const functionType = ZodFunction.create;
2737
+ const lazyType = ZodLazy.create;
2738
+ const literalType = ZodLiteral.create;
2739
+ const enumType = ZodEnum.create;
2740
+ const nativeEnumType = ZodNativeEnum.create;
2741
+ const promiseType = ZodPromise.create;
2742
+ const effectsType = ZodEffects.create;
2743
+ const optionalType = ZodOptional.create;
2744
+ const nullableType = ZodNullable.create;
2745
+ const preprocessType = ZodEffects.createWithPreprocess;
2746
+ const ostring = () => stringType().optional();
2747
+ const onumber = () => numberType().optional();
2748
+ const oboolean = () => booleanType().optional();
3315
2749
 
3316
2750
  var mod = /*#__PURE__*/Object.freeze({
3317
2751
  __proto__: null,
@@ -3412,5 +2846,4 @@ var mod = /*#__PURE__*/Object.freeze({
3412
2846
  setErrorMap: setErrorMap
3413
2847
  });
3414
2848
 
3415
- export default mod;
3416
- export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, custom, dateType as date, defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, mod as z };
2849
+ export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, custom, dateType as date, mod as default, defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, mod as z };