@rspack/core 1.0.0-alpha.0 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/compiled/enhanced-resolve/index.js +11 -11
  2. package/compiled/zod-validation-error/index.d.ts +4 -170
  3. package/compiled/zod-validation-error/index.js +4 -4154
  4. package/dist/Compilation.d.ts +12 -10
  5. package/dist/Compilation.js +13 -10
  6. package/dist/Compiler.d.ts +25 -27
  7. package/dist/Compiler.js +42 -24
  8. package/dist/ContextModuleFactory.d.ts +1 -1
  9. package/dist/ContextModuleFactory.js +1 -1
  10. package/dist/MultiCompiler.d.ts +11 -11
  11. package/dist/MultiCompiler.js +30 -13
  12. package/dist/NormalModule.d.ts +7 -3
  13. package/dist/NormalModule.js +27 -4
  14. package/dist/NormalModuleFactory.d.ts +2 -1
  15. package/dist/NormalModuleFactory.js +2 -1
  16. package/dist/ResolverFactory.d.ts +3 -3
  17. package/dist/ResolverFactory.js +1 -1
  18. package/dist/Stats.d.ts +2 -0
  19. package/dist/Stats.js +6 -0
  20. package/dist/Watching.d.ts +1 -1
  21. package/dist/builtin-loader/swc/index.d.ts +0 -2
  22. package/dist/builtin-loader/swc/index.js +1 -3
  23. package/dist/builtin-loader/swc/types.d.ts +0 -2
  24. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +1 -1
  25. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  26. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +1 -1
  27. package/dist/builtin-plugin/SplitChunksPlugin.js +11 -2
  28. package/dist/config/adapter.js +7 -6
  29. package/dist/config/adapterRuleUse.js +0 -3
  30. package/dist/config/zod.d.ts +585 -162
  31. package/dist/config/zod.js +4 -2
  32. package/dist/exports.d.ts +8 -1
  33. package/dist/exports.js +10 -5
  34. package/dist/lib/Cache.d.ts +3 -3
  35. package/dist/lib/Cache.js +1 -1
  36. package/dist/loader-runner/index.js +9 -5
  37. package/dist/node/nodeConsole.js +26 -3
  38. package/dist/rspack.d.ts +1 -1
  39. package/dist/stats/StatsFactory.d.ts +2 -2
  40. package/dist/stats/StatsFactory.js +12 -12
  41. package/dist/stats/StatsPrinter.d.ts +1 -1
  42. package/dist/stats/StatsPrinter.js +8 -8
  43. package/dist/util/SplitChunkSize.d.ts +5 -0
  44. package/dist/util/SplitChunkSize.js +18 -0
  45. package/package.json +6 -6
  46. package/dist/builtin-loader/swc/preact.d.ts +0 -6
  47. package/dist/builtin-loader/swc/preact.js +0 -15
  48. package/dist/lite-tapable/index.d.ts +0 -146
  49. package/dist/lite-tapable/index.js +0 -752
@@ -31,7 +31,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", ({ value: true }));
33
33
  exports.isValidationErrorLike = exports.isValidationError = exports.toValidationError = exports.fromZodError = exports.ValidationError = void 0;
34
- const zod = __importStar(__nccwpck_require__(762));
34
+ const zod = __importStar(__nccwpck_require__(934));
35
35
  const joinPath_1 = __nccwpck_require__(991);
36
36
  const NonEmptyArray_1 = __nccwpck_require__(355);
37
37
  class ValidationError extends Error {
@@ -151,4160 +151,10 @@ function escapeQuotes(str) {
151
151
 
152
152
  /***/ }),
153
153
 
154
- /***/ 872:
155
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
156
-
157
-
158
- Object.defineProperty(exports, "__esModule", ({ value: true }));
159
- exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
160
- const util_1 = __nccwpck_require__(306);
161
- exports.ZodIssueCode = util_1.util.arrayToEnum([
162
- "invalid_type",
163
- "invalid_literal",
164
- "custom",
165
- "invalid_union",
166
- "invalid_union_discriminator",
167
- "invalid_enum_value",
168
- "unrecognized_keys",
169
- "invalid_arguments",
170
- "invalid_return_type",
171
- "invalid_date",
172
- "invalid_string",
173
- "too_small",
174
- "too_big",
175
- "invalid_intersection_types",
176
- "not_multiple_of",
177
- "not_finite",
178
- ]);
179
- const quotelessJson = (obj) => {
180
- const json = JSON.stringify(obj, null, 2);
181
- return json.replace(/"([^"]+)":/g, "$1:");
182
- };
183
- exports.quotelessJson = quotelessJson;
184
- class ZodError extends Error {
185
- constructor(issues) {
186
- super();
187
- this.issues = [];
188
- this.addIssue = (sub) => {
189
- this.issues = [...this.issues, sub];
190
- };
191
- this.addIssues = (subs = []) => {
192
- this.issues = [...this.issues, ...subs];
193
- };
194
- const actualProto = new.target.prototype;
195
- if (Object.setPrototypeOf) {
196
- // eslint-disable-next-line ban/ban
197
- Object.setPrototypeOf(this, actualProto);
198
- }
199
- else {
200
- this.__proto__ = actualProto;
201
- }
202
- this.name = "ZodError";
203
- this.issues = issues;
204
- }
205
- get errors() {
206
- return this.issues;
207
- }
208
- format(_mapper) {
209
- const mapper = _mapper ||
210
- function (issue) {
211
- return issue.message;
212
- };
213
- const fieldErrors = { _errors: [] };
214
- const processError = (error) => {
215
- for (const issue of error.issues) {
216
- if (issue.code === "invalid_union") {
217
- issue.unionErrors.map(processError);
218
- }
219
- else if (issue.code === "invalid_return_type") {
220
- processError(issue.returnTypeError);
221
- }
222
- else if (issue.code === "invalid_arguments") {
223
- processError(issue.argumentsError);
224
- }
225
- else if (issue.path.length === 0) {
226
- fieldErrors._errors.push(mapper(issue));
227
- }
228
- else {
229
- let curr = fieldErrors;
230
- let i = 0;
231
- while (i < issue.path.length) {
232
- const el = issue.path[i];
233
- const terminal = i === issue.path.length - 1;
234
- if (!terminal) {
235
- curr[el] = curr[el] || { _errors: [] };
236
- // if (typeof el === "string") {
237
- // curr[el] = curr[el] || { _errors: [] };
238
- // } else if (typeof el === "number") {
239
- // const errorArray: any = [];
240
- // errorArray._errors = [];
241
- // curr[el] = curr[el] || errorArray;
242
- // }
243
- }
244
- else {
245
- curr[el] = curr[el] || { _errors: [] };
246
- curr[el]._errors.push(mapper(issue));
247
- }
248
- curr = curr[el];
249
- i++;
250
- }
251
- }
252
- }
253
- };
254
- processError(this);
255
- return fieldErrors;
256
- }
257
- toString() {
258
- return this.message;
259
- }
260
- get message() {
261
- return JSON.stringify(this.issues, util_1.util.jsonStringifyReplacer, 2);
262
- }
263
- get isEmpty() {
264
- return this.issues.length === 0;
265
- }
266
- flatten(mapper = (issue) => issue.message) {
267
- const fieldErrors = {};
268
- const formErrors = [];
269
- for (const sub of this.issues) {
270
- if (sub.path.length > 0) {
271
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
272
- fieldErrors[sub.path[0]].push(mapper(sub));
273
- }
274
- else {
275
- formErrors.push(mapper(sub));
276
- }
277
- }
278
- return { formErrors, fieldErrors };
279
- }
280
- get formErrors() {
281
- return this.flatten();
282
- }
283
- }
284
- exports.ZodError = ZodError;
285
- ZodError.create = (issues) => {
286
- const error = new ZodError(issues);
287
- return error;
288
- };
289
-
290
-
291
- /***/ }),
292
-
293
- /***/ 681:
294
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
295
-
296
-
297
- var __importDefault = (this && this.__importDefault) || function (mod) {
298
- return (mod && mod.__esModule) ? mod : { "default": mod };
299
- };
300
- Object.defineProperty(exports, "__esModule", ({ value: true }));
301
- exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0;
302
- const en_1 = __importDefault(__nccwpck_require__(852));
303
- exports.defaultErrorMap = en_1.default;
304
- let overrideErrorMap = en_1.default;
305
- function setErrorMap(map) {
306
- overrideErrorMap = map;
307
- }
308
- exports.setErrorMap = setErrorMap;
309
- function getErrorMap() {
310
- return overrideErrorMap;
311
- }
312
- exports.getErrorMap = getErrorMap;
313
-
314
-
315
- /***/ }),
316
-
317
- /***/ 508:
318
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
319
-
320
-
321
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
322
- if (k2 === undefined) k2 = k;
323
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
324
- }) : (function(o, m, k, k2) {
325
- if (k2 === undefined) k2 = k;
326
- o[k2] = m[k];
327
- }));
328
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
329
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
330
- };
331
- Object.defineProperty(exports, "__esModule", ({ value: true }));
332
- __exportStar(__nccwpck_require__(681), exports);
333
- __exportStar(__nccwpck_require__(749), exports);
334
- __exportStar(__nccwpck_require__(1), exports);
335
- __exportStar(__nccwpck_require__(306), exports);
336
- __exportStar(__nccwpck_require__(763), exports);
337
- __exportStar(__nccwpck_require__(872), exports);
338
-
339
-
340
- /***/ }),
341
-
342
- /***/ 750:
343
- /***/ ((__unused_webpack_module, exports) => {
344
-
345
-
346
- Object.defineProperty(exports, "__esModule", ({ value: true }));
347
- exports.errorUtil = void 0;
348
- var errorUtil;
349
- (function (errorUtil) {
350
- errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
351
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
352
- })(errorUtil = exports.errorUtil || (exports.errorUtil = {}));
353
-
354
-
355
- /***/ }),
356
-
357
- /***/ 749:
358
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
359
-
360
-
361
- var __importDefault = (this && this.__importDefault) || function (mod) {
362
- return (mod && mod.__esModule) ? mod : { "default": mod };
363
- };
364
- Object.defineProperty(exports, "__esModule", ({ value: true }));
365
- exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
366
- const errors_1 = __nccwpck_require__(681);
367
- const en_1 = __importDefault(__nccwpck_require__(852));
368
- const makeIssue = (params) => {
369
- const { data, path, errorMaps, issueData } = params;
370
- const fullPath = [...path, ...(issueData.path || [])];
371
- const fullIssue = {
372
- ...issueData,
373
- path: fullPath,
374
- };
375
- let errorMessage = "";
376
- const maps = errorMaps
377
- .filter((m) => !!m)
378
- .slice()
379
- .reverse();
380
- for (const map of maps) {
381
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
382
- }
383
- return {
384
- ...issueData,
385
- path: fullPath,
386
- message: issueData.message || errorMessage,
387
- };
388
- };
389
- exports.makeIssue = makeIssue;
390
- exports.EMPTY_PATH = [];
391
- function addIssueToContext(ctx, issueData) {
392
- const issue = (0, exports.makeIssue)({
393
- issueData: issueData,
394
- data: ctx.data,
395
- path: ctx.path,
396
- errorMaps: [
397
- ctx.common.contextualErrorMap,
398
- ctx.schemaErrorMap,
399
- (0, errors_1.getErrorMap)(),
400
- en_1.default, // then global default map
401
- ].filter((x) => !!x),
402
- });
403
- ctx.common.issues.push(issue);
404
- }
405
- exports.addIssueToContext = addIssueToContext;
406
- class ParseStatus {
407
- constructor() {
408
- this.value = "valid";
409
- }
410
- dirty() {
411
- if (this.value === "valid")
412
- this.value = "dirty";
413
- }
414
- abort() {
415
- if (this.value !== "aborted")
416
- this.value = "aborted";
417
- }
418
- static mergeArray(status, results) {
419
- const arrayValue = [];
420
- for (const s of results) {
421
- if (s.status === "aborted")
422
- return exports.INVALID;
423
- if (s.status === "dirty")
424
- status.dirty();
425
- arrayValue.push(s.value);
426
- }
427
- return { status: status.value, value: arrayValue };
428
- }
429
- static async mergeObjectAsync(status, pairs) {
430
- const syncPairs = [];
431
- for (const pair of pairs) {
432
- syncPairs.push({
433
- key: await pair.key,
434
- value: await pair.value,
435
- });
436
- }
437
- return ParseStatus.mergeObjectSync(status, syncPairs);
438
- }
439
- static mergeObjectSync(status, pairs) {
440
- const finalObject = {};
441
- for (const pair of pairs) {
442
- const { key, value } = pair;
443
- if (key.status === "aborted")
444
- return exports.INVALID;
445
- if (value.status === "aborted")
446
- return exports.INVALID;
447
- if (key.status === "dirty")
448
- status.dirty();
449
- if (value.status === "dirty")
450
- status.dirty();
451
- if (key.value !== "__proto__" &&
452
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
453
- finalObject[key.value] = value.value;
454
- }
455
- }
456
- return { status: status.value, value: finalObject };
457
- }
458
- }
459
- exports.ParseStatus = ParseStatus;
460
- exports.INVALID = Object.freeze({
461
- status: "aborted",
462
- });
463
- const DIRTY = (value) => ({ status: "dirty", value });
464
- exports.DIRTY = DIRTY;
465
- const OK = (value) => ({ status: "valid", value });
466
- exports.OK = OK;
467
- const isAborted = (x) => x.status === "aborted";
468
- exports.isAborted = isAborted;
469
- const isDirty = (x) => x.status === "dirty";
470
- exports.isDirty = isDirty;
471
- const isValid = (x) => x.status === "valid";
472
- exports.isValid = isValid;
473
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
474
- exports.isAsync = isAsync;
475
-
476
-
477
- /***/ }),
478
-
479
- /***/ 1:
480
- /***/ ((__unused_webpack_module, exports) => {
481
-
482
-
483
- Object.defineProperty(exports, "__esModule", ({ value: true }));
484
-
485
-
486
- /***/ }),
487
-
488
- /***/ 306:
489
- /***/ ((__unused_webpack_module, exports) => {
490
-
491
-
492
- Object.defineProperty(exports, "__esModule", ({ value: true }));
493
- exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
494
- var util;
495
- (function (util) {
496
- util.assertEqual = (val) => val;
497
- function assertIs(_arg) { }
498
- util.assertIs = assertIs;
499
- function assertNever(_x) {
500
- throw new Error();
501
- }
502
- util.assertNever = assertNever;
503
- util.arrayToEnum = (items) => {
504
- const obj = {};
505
- for (const item of items) {
506
- obj[item] = item;
507
- }
508
- return obj;
509
- };
510
- util.getValidEnumValues = (obj) => {
511
- const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
512
- const filtered = {};
513
- for (const k of validKeys) {
514
- filtered[k] = obj[k];
515
- }
516
- return util.objectValues(filtered);
517
- };
518
- util.objectValues = (obj) => {
519
- return util.objectKeys(obj).map(function (e) {
520
- return obj[e];
521
- });
522
- };
523
- util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
524
- ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
525
- : (object) => {
526
- const keys = [];
527
- for (const key in object) {
528
- if (Object.prototype.hasOwnProperty.call(object, key)) {
529
- keys.push(key);
530
- }
531
- }
532
- return keys;
533
- };
534
- util.find = (arr, checker) => {
535
- for (const item of arr) {
536
- if (checker(item))
537
- return item;
538
- }
539
- return undefined;
540
- };
541
- util.isInteger = typeof Number.isInteger === "function"
542
- ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
543
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
544
- function joinValues(array, separator = " | ") {
545
- return array
546
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
547
- .join(separator);
548
- }
549
- util.joinValues = joinValues;
550
- util.jsonStringifyReplacer = (_, value) => {
551
- if (typeof value === "bigint") {
552
- return value.toString();
553
- }
554
- return value;
555
- };
556
- })(util = exports.util || (exports.util = {}));
557
- var objectUtil;
558
- (function (objectUtil) {
559
- objectUtil.mergeShapes = (first, second) => {
560
- return {
561
- ...first,
562
- ...second, // second overwrites first
563
- };
564
- };
565
- })(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
566
- exports.ZodParsedType = util.arrayToEnum([
567
- "string",
568
- "nan",
569
- "number",
570
- "integer",
571
- "float",
572
- "boolean",
573
- "date",
574
- "bigint",
575
- "symbol",
576
- "function",
577
- "undefined",
578
- "null",
579
- "array",
580
- "object",
581
- "unknown",
582
- "promise",
583
- "void",
584
- "never",
585
- "map",
586
- "set",
587
- ]);
588
- const getParsedType = (data) => {
589
- const t = typeof data;
590
- switch (t) {
591
- case "undefined":
592
- return exports.ZodParsedType.undefined;
593
- case "string":
594
- return exports.ZodParsedType.string;
595
- case "number":
596
- return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
597
- case "boolean":
598
- return exports.ZodParsedType.boolean;
599
- case "function":
600
- return exports.ZodParsedType.function;
601
- case "bigint":
602
- return exports.ZodParsedType.bigint;
603
- case "symbol":
604
- return exports.ZodParsedType.symbol;
605
- case "object":
606
- if (Array.isArray(data)) {
607
- return exports.ZodParsedType.array;
608
- }
609
- if (data === null) {
610
- return exports.ZodParsedType.null;
611
- }
612
- if (data.then &&
613
- typeof data.then === "function" &&
614
- data.catch &&
615
- typeof data.catch === "function") {
616
- return exports.ZodParsedType.promise;
617
- }
618
- if (typeof Map !== "undefined" && data instanceof Map) {
619
- return exports.ZodParsedType.map;
620
- }
621
- if (typeof Set !== "undefined" && data instanceof Set) {
622
- return exports.ZodParsedType.set;
623
- }
624
- if (typeof Date !== "undefined" && data instanceof Date) {
625
- return exports.ZodParsedType.date;
626
- }
627
- return exports.ZodParsedType.object;
628
- default:
629
- return exports.ZodParsedType.unknown;
630
- }
631
- };
632
- exports.getParsedType = getParsedType;
633
-
634
-
635
- /***/ }),
636
-
637
- /***/ 762:
638
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
639
-
640
-
641
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
642
- if (k2 === undefined) k2 = k;
643
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
644
- }) : (function(o, m, k, k2) {
645
- if (k2 === undefined) k2 = k;
646
- o[k2] = m[k];
647
- }));
648
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
649
- Object.defineProperty(o, "default", { enumerable: true, value: v });
650
- }) : function(o, v) {
651
- o["default"] = v;
652
- });
653
- var __importStar = (this && this.__importStar) || function (mod) {
654
- if (mod && mod.__esModule) return mod;
655
- var result = {};
656
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
657
- __setModuleDefault(result, mod);
658
- return result;
659
- };
660
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
661
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
662
- };
663
- Object.defineProperty(exports, "__esModule", ({ value: true }));
664
- exports.z = void 0;
665
- const z = __importStar(__nccwpck_require__(508));
666
- exports.z = z;
667
- __exportStar(__nccwpck_require__(508), exports);
668
- exports["default"] = z;
669
-
670
-
671
- /***/ }),
672
-
673
- /***/ 852:
674
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
675
-
676
-
677
- Object.defineProperty(exports, "__esModule", ({ value: true }));
678
- const util_1 = __nccwpck_require__(306);
679
- const ZodError_1 = __nccwpck_require__(872);
680
- const errorMap = (issue, _ctx) => {
681
- let message;
682
- switch (issue.code) {
683
- case ZodError_1.ZodIssueCode.invalid_type:
684
- if (issue.received === util_1.ZodParsedType.undefined) {
685
- message = "Required";
686
- }
687
- else {
688
- message = `Expected ${issue.expected}, received ${issue.received}`;
689
- }
690
- break;
691
- case ZodError_1.ZodIssueCode.invalid_literal:
692
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_1.util.jsonStringifyReplacer)}`;
693
- break;
694
- case ZodError_1.ZodIssueCode.unrecognized_keys:
695
- message = `Unrecognized key(s) in object: ${util_1.util.joinValues(issue.keys, ", ")}`;
696
- break;
697
- case ZodError_1.ZodIssueCode.invalid_union:
698
- message = `Invalid input`;
699
- break;
700
- case ZodError_1.ZodIssueCode.invalid_union_discriminator:
701
- message = `Invalid discriminator value. Expected ${util_1.util.joinValues(issue.options)}`;
702
- break;
703
- case ZodError_1.ZodIssueCode.invalid_enum_value:
704
- message = `Invalid enum value. Expected ${util_1.util.joinValues(issue.options)}, received '${issue.received}'`;
705
- break;
706
- case ZodError_1.ZodIssueCode.invalid_arguments:
707
- message = `Invalid function arguments`;
708
- break;
709
- case ZodError_1.ZodIssueCode.invalid_return_type:
710
- message = `Invalid function return type`;
711
- break;
712
- case ZodError_1.ZodIssueCode.invalid_date:
713
- message = `Invalid date`;
714
- break;
715
- case ZodError_1.ZodIssueCode.invalid_string:
716
- if (typeof issue.validation === "object") {
717
- if ("includes" in issue.validation) {
718
- message = `Invalid input: must include "${issue.validation.includes}"`;
719
- if (typeof issue.validation.position === "number") {
720
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
721
- }
722
- }
723
- else if ("startsWith" in issue.validation) {
724
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
725
- }
726
- else if ("endsWith" in issue.validation) {
727
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
728
- }
729
- else {
730
- util_1.util.assertNever(issue.validation);
731
- }
732
- }
733
- else if (issue.validation !== "regex") {
734
- message = `Invalid ${issue.validation}`;
735
- }
736
- else {
737
- message = "Invalid";
738
- }
739
- break;
740
- case ZodError_1.ZodIssueCode.too_small:
741
- if (issue.type === "array")
742
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
743
- else if (issue.type === "string")
744
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
745
- else if (issue.type === "number")
746
- message = `Number must be ${issue.exact
747
- ? `exactly equal to `
748
- : issue.inclusive
749
- ? `greater than or equal to `
750
- : `greater than `}${issue.minimum}`;
751
- else if (issue.type === "date")
752
- message = `Date must be ${issue.exact
753
- ? `exactly equal to `
754
- : issue.inclusive
755
- ? `greater than or equal to `
756
- : `greater than `}${new Date(Number(issue.minimum))}`;
757
- else
758
- message = "Invalid input";
759
- break;
760
- case ZodError_1.ZodIssueCode.too_big:
761
- if (issue.type === "array")
762
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
763
- else if (issue.type === "string")
764
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
765
- else if (issue.type === "number")
766
- message = `Number must be ${issue.exact
767
- ? `exactly`
768
- : issue.inclusive
769
- ? `less than or equal to`
770
- : `less than`} ${issue.maximum}`;
771
- else if (issue.type === "bigint")
772
- message = `BigInt must be ${issue.exact
773
- ? `exactly`
774
- : issue.inclusive
775
- ? `less than or equal to`
776
- : `less than`} ${issue.maximum}`;
777
- else if (issue.type === "date")
778
- message = `Date must be ${issue.exact
779
- ? `exactly`
780
- : issue.inclusive
781
- ? `smaller than or equal to`
782
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
783
- else
784
- message = "Invalid input";
785
- break;
786
- case ZodError_1.ZodIssueCode.custom:
787
- message = `Invalid input`;
788
- break;
789
- case ZodError_1.ZodIssueCode.invalid_intersection_types:
790
- message = `Intersection results could not be merged`;
791
- break;
792
- case ZodError_1.ZodIssueCode.not_multiple_of:
793
- message = `Number must be a multiple of ${issue.multipleOf}`;
794
- break;
795
- case ZodError_1.ZodIssueCode.not_finite:
796
- message = "Number must be finite";
797
- break;
798
- default:
799
- message = _ctx.defaultError;
800
- util_1.util.assertNever(issue);
801
- }
802
- return { message };
803
- };
804
- exports["default"] = errorMap;
805
-
806
-
807
- /***/ }),
808
-
809
- /***/ 763:
810
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
811
-
812
-
813
- Object.defineProperty(exports, "__esModule", ({ value: true }));
814
- exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
815
- exports.NEVER = exports["void"] = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports["null"] = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports["instanceof"] = exports["function"] = exports["enum"] = exports.effect = exports.discriminatedUnion = void 0;
816
- const errors_1 = __nccwpck_require__(681);
817
- const errorUtil_1 = __nccwpck_require__(750);
818
- const parseUtil_1 = __nccwpck_require__(749);
819
- const util_1 = __nccwpck_require__(306);
820
- const ZodError_1 = __nccwpck_require__(872);
821
- class ParseInputLazyPath {
822
- constructor(parent, value, path, key) {
823
- this._cachedPath = [];
824
- this.parent = parent;
825
- this.data = value;
826
- this._path = path;
827
- this._key = key;
828
- }
829
- get path() {
830
- if (!this._cachedPath.length) {
831
- if (this._key instanceof Array) {
832
- this._cachedPath.push(...this._path, ...this._key);
833
- }
834
- else {
835
- this._cachedPath.push(...this._path, this._key);
836
- }
837
- }
838
- return this._cachedPath;
839
- }
840
- }
841
- const handleResult = (ctx, result) => {
842
- if ((0, parseUtil_1.isValid)(result)) {
843
- return { success: true, data: result.value };
844
- }
845
- else {
846
- if (!ctx.common.issues.length) {
847
- throw new Error("Validation failed but no issues detected.");
848
- }
849
- return {
850
- success: false,
851
- get error() {
852
- if (this._error)
853
- return this._error;
854
- const error = new ZodError_1.ZodError(ctx.common.issues);
855
- this._error = error;
856
- return this._error;
857
- },
858
- };
859
- }
860
- };
861
- function processCreateParams(params) {
862
- if (!params)
863
- return {};
864
- const { errorMap, invalid_type_error, required_error, description } = params;
865
- if (errorMap && (invalid_type_error || required_error)) {
866
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
867
- }
868
- if (errorMap)
869
- return { errorMap: errorMap, description };
870
- const customMap = (iss, ctx) => {
871
- if (iss.code !== "invalid_type")
872
- return { message: ctx.defaultError };
873
- if (typeof ctx.data === "undefined") {
874
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
875
- }
876
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
877
- };
878
- return { errorMap: customMap, description };
879
- }
880
- class ZodType {
881
- constructor(def) {
882
- /** Alias of safeParseAsync */
883
- this.spa = this.safeParseAsync;
884
- this._def = def;
885
- this.parse = this.parse.bind(this);
886
- this.safeParse = this.safeParse.bind(this);
887
- this.parseAsync = this.parseAsync.bind(this);
888
- this.safeParseAsync = this.safeParseAsync.bind(this);
889
- this.spa = this.spa.bind(this);
890
- this.refine = this.refine.bind(this);
891
- this.refinement = this.refinement.bind(this);
892
- this.superRefine = this.superRefine.bind(this);
893
- this.optional = this.optional.bind(this);
894
- this.nullable = this.nullable.bind(this);
895
- this.nullish = this.nullish.bind(this);
896
- this.array = this.array.bind(this);
897
- this.promise = this.promise.bind(this);
898
- this.or = this.or.bind(this);
899
- this.and = this.and.bind(this);
900
- this.transform = this.transform.bind(this);
901
- this.brand = this.brand.bind(this);
902
- this.default = this.default.bind(this);
903
- this.catch = this.catch.bind(this);
904
- this.describe = this.describe.bind(this);
905
- this.pipe = this.pipe.bind(this);
906
- this.readonly = this.readonly.bind(this);
907
- this.isNullable = this.isNullable.bind(this);
908
- this.isOptional = this.isOptional.bind(this);
909
- }
910
- get description() {
911
- return this._def.description;
912
- }
913
- _getType(input) {
914
- return (0, util_1.getParsedType)(input.data);
915
- }
916
- _getOrReturnCtx(input, ctx) {
917
- return (ctx || {
918
- common: input.parent.common,
919
- data: input.data,
920
- parsedType: (0, util_1.getParsedType)(input.data),
921
- schemaErrorMap: this._def.errorMap,
922
- path: input.path,
923
- parent: input.parent,
924
- });
925
- }
926
- _processInputParams(input) {
927
- return {
928
- status: new parseUtil_1.ParseStatus(),
929
- ctx: {
930
- common: input.parent.common,
931
- data: input.data,
932
- parsedType: (0, util_1.getParsedType)(input.data),
933
- schemaErrorMap: this._def.errorMap,
934
- path: input.path,
935
- parent: input.parent,
936
- },
937
- };
938
- }
939
- _parseSync(input) {
940
- const result = this._parse(input);
941
- if ((0, parseUtil_1.isAsync)(result)) {
942
- throw new Error("Synchronous parse encountered promise.");
943
- }
944
- return result;
945
- }
946
- _parseAsync(input) {
947
- const result = this._parse(input);
948
- return Promise.resolve(result);
949
- }
950
- parse(data, params) {
951
- const result = this.safeParse(data, params);
952
- if (result.success)
953
- return result.data;
954
- throw result.error;
955
- }
956
- safeParse(data, params) {
957
- var _a;
958
- const ctx = {
959
- common: {
960
- issues: [],
961
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
962
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
963
- },
964
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
965
- schemaErrorMap: this._def.errorMap,
966
- parent: null,
967
- data,
968
- parsedType: (0, util_1.getParsedType)(data),
969
- };
970
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
971
- return handleResult(ctx, result);
972
- }
973
- async parseAsync(data, params) {
974
- const result = await this.safeParseAsync(data, params);
975
- if (result.success)
976
- return result.data;
977
- throw result.error;
978
- }
979
- async safeParseAsync(data, params) {
980
- const ctx = {
981
- common: {
982
- issues: [],
983
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
984
- async: true,
985
- },
986
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
987
- schemaErrorMap: this._def.errorMap,
988
- parent: null,
989
- data,
990
- parsedType: (0, util_1.getParsedType)(data),
991
- };
992
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
993
- const result = await ((0, parseUtil_1.isAsync)(maybeAsyncResult)
994
- ? maybeAsyncResult
995
- : Promise.resolve(maybeAsyncResult));
996
- return handleResult(ctx, result);
997
- }
998
- refine(check, message) {
999
- const getIssueProperties = (val) => {
1000
- if (typeof message === "string" || typeof message === "undefined") {
1001
- return { message };
1002
- }
1003
- else if (typeof message === "function") {
1004
- return message(val);
1005
- }
1006
- else {
1007
- return message;
1008
- }
1009
- };
1010
- return this._refinement((val, ctx) => {
1011
- const result = check(val);
1012
- const setError = () => ctx.addIssue({
1013
- code: ZodError_1.ZodIssueCode.custom,
1014
- ...getIssueProperties(val),
1015
- });
1016
- if (typeof Promise !== "undefined" && result instanceof Promise) {
1017
- return result.then((data) => {
1018
- if (!data) {
1019
- setError();
1020
- return false;
1021
- }
1022
- else {
1023
- return true;
1024
- }
1025
- });
1026
- }
1027
- if (!result) {
1028
- setError();
1029
- return false;
1030
- }
1031
- else {
1032
- return true;
1033
- }
1034
- });
1035
- }
1036
- refinement(check, refinementData) {
1037
- return this._refinement((val, ctx) => {
1038
- if (!check(val)) {
1039
- ctx.addIssue(typeof refinementData === "function"
1040
- ? refinementData(val, ctx)
1041
- : refinementData);
1042
- return false;
1043
- }
1044
- else {
1045
- return true;
1046
- }
1047
- });
1048
- }
1049
- _refinement(refinement) {
1050
- return new ZodEffects({
1051
- schema: this,
1052
- typeName: ZodFirstPartyTypeKind.ZodEffects,
1053
- effect: { type: "refinement", refinement },
1054
- });
1055
- }
1056
- superRefine(refinement) {
1057
- return this._refinement(refinement);
1058
- }
1059
- optional() {
1060
- return ZodOptional.create(this, this._def);
1061
- }
1062
- nullable() {
1063
- return ZodNullable.create(this, this._def);
1064
- }
1065
- nullish() {
1066
- return this.nullable().optional();
1067
- }
1068
- array() {
1069
- return ZodArray.create(this, this._def);
1070
- }
1071
- promise() {
1072
- return ZodPromise.create(this, this._def);
1073
- }
1074
- or(option) {
1075
- return ZodUnion.create([this, option], this._def);
1076
- }
1077
- and(incoming) {
1078
- return ZodIntersection.create(this, incoming, this._def);
1079
- }
1080
- transform(transform) {
1081
- return new ZodEffects({
1082
- ...processCreateParams(this._def),
1083
- schema: this,
1084
- typeName: ZodFirstPartyTypeKind.ZodEffects,
1085
- effect: { type: "transform", transform },
1086
- });
1087
- }
1088
- default(def) {
1089
- const defaultValueFunc = typeof def === "function" ? def : () => def;
1090
- return new ZodDefault({
1091
- ...processCreateParams(this._def),
1092
- innerType: this,
1093
- defaultValue: defaultValueFunc,
1094
- typeName: ZodFirstPartyTypeKind.ZodDefault,
1095
- });
1096
- }
1097
- brand() {
1098
- return new ZodBranded({
1099
- typeName: ZodFirstPartyTypeKind.ZodBranded,
1100
- type: this,
1101
- ...processCreateParams(this._def),
1102
- });
1103
- }
1104
- catch(def) {
1105
- const catchValueFunc = typeof def === "function" ? def : () => def;
1106
- return new ZodCatch({
1107
- ...processCreateParams(this._def),
1108
- innerType: this,
1109
- catchValue: catchValueFunc,
1110
- typeName: ZodFirstPartyTypeKind.ZodCatch,
1111
- });
1112
- }
1113
- describe(description) {
1114
- const This = this.constructor;
1115
- return new This({
1116
- ...this._def,
1117
- description,
1118
- });
1119
- }
1120
- pipe(target) {
1121
- return ZodPipeline.create(this, target);
1122
- }
1123
- readonly() {
1124
- return ZodReadonly.create(this);
1125
- }
1126
- isOptional() {
1127
- return this.safeParse(undefined).success;
1128
- }
1129
- isNullable() {
1130
- return this.safeParse(null).success;
1131
- }
1132
- }
1133
- exports.ZodType = ZodType;
1134
- exports.Schema = ZodType;
1135
- exports.ZodSchema = ZodType;
1136
- const cuidRegex = /^c[^\s-]{8,}$/i;
1137
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
1138
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
1139
- // const uuidRegex =
1140
- // /^([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;
1141
- const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
1142
- // from https://stackoverflow.com/a/46181/1550155
1143
- // old version: too slow, didn't support unicode
1144
- // 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;
1145
- //old email regex
1146
- // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
1147
- // eslint-disable-next-line
1148
- // const emailRegex =
1149
- // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
1150
- // const emailRegex =
1151
- // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
1152
- // const emailRegex =
1153
- // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
1154
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1155
- // const emailRegex =
1156
- // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
1157
- // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
1158
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1159
- let emojiRegex;
1160
- const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
1161
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
1162
- // Adapted from https://stackoverflow.com/a/3143231
1163
- const datetimeRegex = (args) => {
1164
- if (args.precision) {
1165
- if (args.offset) {
1166
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1167
- }
1168
- else {
1169
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
1170
- }
1171
- }
1172
- else if (args.precision === 0) {
1173
- if (args.offset) {
1174
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1175
- }
1176
- else {
1177
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
1178
- }
1179
- }
1180
- else {
1181
- if (args.offset) {
1182
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1183
- }
1184
- else {
1185
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
1186
- }
1187
- }
1188
- };
1189
- function isValidIP(ip, version) {
1190
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1191
- return true;
1192
- }
1193
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1194
- return true;
1195
- }
1196
- return false;
1197
- }
1198
- class ZodString extends ZodType {
1199
- _parse(input) {
1200
- if (this._def.coerce) {
1201
- input.data = String(input.data);
1202
- }
1203
- const parsedType = this._getType(input);
1204
- if (parsedType !== util_1.ZodParsedType.string) {
1205
- const ctx = this._getOrReturnCtx(input);
1206
- (0, parseUtil_1.addIssueToContext)(ctx, {
1207
- code: ZodError_1.ZodIssueCode.invalid_type,
1208
- expected: util_1.ZodParsedType.string,
1209
- received: ctx.parsedType,
1210
- }
1211
- //
1212
- );
1213
- return parseUtil_1.INVALID;
1214
- }
1215
- const status = new parseUtil_1.ParseStatus();
1216
- let ctx = undefined;
1217
- for (const check of this._def.checks) {
1218
- if (check.kind === "min") {
1219
- if (input.data.length < check.value) {
1220
- ctx = this._getOrReturnCtx(input, ctx);
1221
- (0, parseUtil_1.addIssueToContext)(ctx, {
1222
- code: ZodError_1.ZodIssueCode.too_small,
1223
- minimum: check.value,
1224
- type: "string",
1225
- inclusive: true,
1226
- exact: false,
1227
- message: check.message,
1228
- });
1229
- status.dirty();
1230
- }
1231
- }
1232
- else if (check.kind === "max") {
1233
- if (input.data.length > check.value) {
1234
- ctx = this._getOrReturnCtx(input, ctx);
1235
- (0, parseUtil_1.addIssueToContext)(ctx, {
1236
- code: ZodError_1.ZodIssueCode.too_big,
1237
- maximum: check.value,
1238
- type: "string",
1239
- inclusive: true,
1240
- exact: false,
1241
- message: check.message,
1242
- });
1243
- status.dirty();
1244
- }
1245
- }
1246
- else if (check.kind === "length") {
1247
- const tooBig = input.data.length > check.value;
1248
- const tooSmall = input.data.length < check.value;
1249
- if (tooBig || tooSmall) {
1250
- ctx = this._getOrReturnCtx(input, ctx);
1251
- if (tooBig) {
1252
- (0, parseUtil_1.addIssueToContext)(ctx, {
1253
- code: ZodError_1.ZodIssueCode.too_big,
1254
- maximum: check.value,
1255
- type: "string",
1256
- inclusive: true,
1257
- exact: true,
1258
- message: check.message,
1259
- });
1260
- }
1261
- else if (tooSmall) {
1262
- (0, parseUtil_1.addIssueToContext)(ctx, {
1263
- code: ZodError_1.ZodIssueCode.too_small,
1264
- minimum: check.value,
1265
- type: "string",
1266
- inclusive: true,
1267
- exact: true,
1268
- message: check.message,
1269
- });
1270
- }
1271
- status.dirty();
1272
- }
1273
- }
1274
- else if (check.kind === "email") {
1275
- if (!emailRegex.test(input.data)) {
1276
- ctx = this._getOrReturnCtx(input, ctx);
1277
- (0, parseUtil_1.addIssueToContext)(ctx, {
1278
- validation: "email",
1279
- code: ZodError_1.ZodIssueCode.invalid_string,
1280
- message: check.message,
1281
- });
1282
- status.dirty();
1283
- }
1284
- }
1285
- else if (check.kind === "emoji") {
1286
- if (!emojiRegex) {
1287
- emojiRegex = new RegExp(_emojiRegex, "u");
1288
- }
1289
- if (!emojiRegex.test(input.data)) {
1290
- ctx = this._getOrReturnCtx(input, ctx);
1291
- (0, parseUtil_1.addIssueToContext)(ctx, {
1292
- validation: "emoji",
1293
- code: ZodError_1.ZodIssueCode.invalid_string,
1294
- message: check.message,
1295
- });
1296
- status.dirty();
1297
- }
1298
- }
1299
- else if (check.kind === "uuid") {
1300
- if (!uuidRegex.test(input.data)) {
1301
- ctx = this._getOrReturnCtx(input, ctx);
1302
- (0, parseUtil_1.addIssueToContext)(ctx, {
1303
- validation: "uuid",
1304
- code: ZodError_1.ZodIssueCode.invalid_string,
1305
- message: check.message,
1306
- });
1307
- status.dirty();
1308
- }
1309
- }
1310
- else if (check.kind === "cuid") {
1311
- if (!cuidRegex.test(input.data)) {
1312
- ctx = this._getOrReturnCtx(input, ctx);
1313
- (0, parseUtil_1.addIssueToContext)(ctx, {
1314
- validation: "cuid",
1315
- code: ZodError_1.ZodIssueCode.invalid_string,
1316
- message: check.message,
1317
- });
1318
- status.dirty();
1319
- }
1320
- }
1321
- else if (check.kind === "cuid2") {
1322
- if (!cuid2Regex.test(input.data)) {
1323
- ctx = this._getOrReturnCtx(input, ctx);
1324
- (0, parseUtil_1.addIssueToContext)(ctx, {
1325
- validation: "cuid2",
1326
- code: ZodError_1.ZodIssueCode.invalid_string,
1327
- message: check.message,
1328
- });
1329
- status.dirty();
1330
- }
1331
- }
1332
- else if (check.kind === "ulid") {
1333
- if (!ulidRegex.test(input.data)) {
1334
- ctx = this._getOrReturnCtx(input, ctx);
1335
- (0, parseUtil_1.addIssueToContext)(ctx, {
1336
- validation: "ulid",
1337
- code: ZodError_1.ZodIssueCode.invalid_string,
1338
- message: check.message,
1339
- });
1340
- status.dirty();
1341
- }
1342
- }
1343
- else if (check.kind === "url") {
1344
- try {
1345
- new URL(input.data);
1346
- }
1347
- catch (_a) {
1348
- ctx = this._getOrReturnCtx(input, ctx);
1349
- (0, parseUtil_1.addIssueToContext)(ctx, {
1350
- validation: "url",
1351
- code: ZodError_1.ZodIssueCode.invalid_string,
1352
- message: check.message,
1353
- });
1354
- status.dirty();
1355
- }
1356
- }
1357
- else if (check.kind === "regex") {
1358
- check.regex.lastIndex = 0;
1359
- const testResult = check.regex.test(input.data);
1360
- if (!testResult) {
1361
- ctx = this._getOrReturnCtx(input, ctx);
1362
- (0, parseUtil_1.addIssueToContext)(ctx, {
1363
- validation: "regex",
1364
- code: ZodError_1.ZodIssueCode.invalid_string,
1365
- message: check.message,
1366
- });
1367
- status.dirty();
1368
- }
1369
- }
1370
- else if (check.kind === "trim") {
1371
- input.data = input.data.trim();
1372
- }
1373
- else if (check.kind === "includes") {
1374
- if (!input.data.includes(check.value, check.position)) {
1375
- ctx = this._getOrReturnCtx(input, ctx);
1376
- (0, parseUtil_1.addIssueToContext)(ctx, {
1377
- code: ZodError_1.ZodIssueCode.invalid_string,
1378
- validation: { includes: check.value, position: check.position },
1379
- message: check.message,
1380
- });
1381
- status.dirty();
1382
- }
1383
- }
1384
- else if (check.kind === "toLowerCase") {
1385
- input.data = input.data.toLowerCase();
1386
- }
1387
- else if (check.kind === "toUpperCase") {
1388
- input.data = input.data.toUpperCase();
1389
- }
1390
- else if (check.kind === "startsWith") {
1391
- if (!input.data.startsWith(check.value)) {
1392
- ctx = this._getOrReturnCtx(input, ctx);
1393
- (0, parseUtil_1.addIssueToContext)(ctx, {
1394
- code: ZodError_1.ZodIssueCode.invalid_string,
1395
- validation: { startsWith: check.value },
1396
- message: check.message,
1397
- });
1398
- status.dirty();
1399
- }
1400
- }
1401
- else if (check.kind === "endsWith") {
1402
- if (!input.data.endsWith(check.value)) {
1403
- ctx = this._getOrReturnCtx(input, ctx);
1404
- (0, parseUtil_1.addIssueToContext)(ctx, {
1405
- code: ZodError_1.ZodIssueCode.invalid_string,
1406
- validation: { endsWith: check.value },
1407
- message: check.message,
1408
- });
1409
- status.dirty();
1410
- }
1411
- }
1412
- else if (check.kind === "datetime") {
1413
- const regex = datetimeRegex(check);
1414
- if (!regex.test(input.data)) {
1415
- ctx = this._getOrReturnCtx(input, ctx);
1416
- (0, parseUtil_1.addIssueToContext)(ctx, {
1417
- code: ZodError_1.ZodIssueCode.invalid_string,
1418
- validation: "datetime",
1419
- message: check.message,
1420
- });
1421
- status.dirty();
1422
- }
1423
- }
1424
- else if (check.kind === "ip") {
1425
- if (!isValidIP(input.data, check.version)) {
1426
- ctx = this._getOrReturnCtx(input, ctx);
1427
- (0, parseUtil_1.addIssueToContext)(ctx, {
1428
- validation: "ip",
1429
- code: ZodError_1.ZodIssueCode.invalid_string,
1430
- message: check.message,
1431
- });
1432
- status.dirty();
1433
- }
1434
- }
1435
- else {
1436
- util_1.util.assertNever(check);
1437
- }
1438
- }
1439
- return { status: status.value, value: input.data };
1440
- }
1441
- _regex(regex, validation, message) {
1442
- return this.refinement((data) => regex.test(data), {
1443
- validation,
1444
- code: ZodError_1.ZodIssueCode.invalid_string,
1445
- ...errorUtil_1.errorUtil.errToObj(message),
1446
- });
1447
- }
1448
- _addCheck(check) {
1449
- return new ZodString({
1450
- ...this._def,
1451
- checks: [...this._def.checks, check],
1452
- });
1453
- }
1454
- email(message) {
1455
- return this._addCheck({ kind: "email", ...errorUtil_1.errorUtil.errToObj(message) });
1456
- }
1457
- url(message) {
1458
- return this._addCheck({ kind: "url", ...errorUtil_1.errorUtil.errToObj(message) });
1459
- }
1460
- emoji(message) {
1461
- return this._addCheck({ kind: "emoji", ...errorUtil_1.errorUtil.errToObj(message) });
1462
- }
1463
- uuid(message) {
1464
- return this._addCheck({ kind: "uuid", ...errorUtil_1.errorUtil.errToObj(message) });
1465
- }
1466
- cuid(message) {
1467
- return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
1468
- }
1469
- cuid2(message) {
1470
- return this._addCheck({ kind: "cuid2", ...errorUtil_1.errorUtil.errToObj(message) });
1471
- }
1472
- ulid(message) {
1473
- return this._addCheck({ kind: "ulid", ...errorUtil_1.errorUtil.errToObj(message) });
1474
- }
1475
- ip(options) {
1476
- return this._addCheck({ kind: "ip", ...errorUtil_1.errorUtil.errToObj(options) });
1477
- }
1478
- datetime(options) {
1479
- var _a;
1480
- if (typeof options === "string") {
1481
- return this._addCheck({
1482
- kind: "datetime",
1483
- precision: null,
1484
- offset: false,
1485
- message: options,
1486
- });
1487
- }
1488
- return this._addCheck({
1489
- kind: "datetime",
1490
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1491
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1492
- ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1493
- });
1494
- }
1495
- regex(regex, message) {
1496
- return this._addCheck({
1497
- kind: "regex",
1498
- regex: regex,
1499
- ...errorUtil_1.errorUtil.errToObj(message),
1500
- });
1501
- }
1502
- includes(value, options) {
1503
- return this._addCheck({
1504
- kind: "includes",
1505
- value: value,
1506
- position: options === null || options === void 0 ? void 0 : options.position,
1507
- ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1508
- });
1509
- }
1510
- startsWith(value, message) {
1511
- return this._addCheck({
1512
- kind: "startsWith",
1513
- value: value,
1514
- ...errorUtil_1.errorUtil.errToObj(message),
1515
- });
1516
- }
1517
- endsWith(value, message) {
1518
- return this._addCheck({
1519
- kind: "endsWith",
1520
- value: value,
1521
- ...errorUtil_1.errorUtil.errToObj(message),
1522
- });
1523
- }
1524
- min(minLength, message) {
1525
- return this._addCheck({
1526
- kind: "min",
1527
- value: minLength,
1528
- ...errorUtil_1.errorUtil.errToObj(message),
1529
- });
1530
- }
1531
- max(maxLength, message) {
1532
- return this._addCheck({
1533
- kind: "max",
1534
- value: maxLength,
1535
- ...errorUtil_1.errorUtil.errToObj(message),
1536
- });
1537
- }
1538
- length(len, message) {
1539
- return this._addCheck({
1540
- kind: "length",
1541
- value: len,
1542
- ...errorUtil_1.errorUtil.errToObj(message),
1543
- });
1544
- }
1545
- /**
1546
- * @deprecated Use z.string().min(1) instead.
1547
- * @see {@link ZodString.min}
1548
- */
1549
- nonempty(message) {
1550
- return this.min(1, errorUtil_1.errorUtil.errToObj(message));
1551
- }
1552
- trim() {
1553
- return new ZodString({
1554
- ...this._def,
1555
- checks: [...this._def.checks, { kind: "trim" }],
1556
- });
1557
- }
1558
- toLowerCase() {
1559
- return new ZodString({
1560
- ...this._def,
1561
- checks: [...this._def.checks, { kind: "toLowerCase" }],
1562
- });
1563
- }
1564
- toUpperCase() {
1565
- return new ZodString({
1566
- ...this._def,
1567
- checks: [...this._def.checks, { kind: "toUpperCase" }],
1568
- });
1569
- }
1570
- get isDatetime() {
1571
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
1572
- }
1573
- get isEmail() {
1574
- return !!this._def.checks.find((ch) => ch.kind === "email");
1575
- }
1576
- get isURL() {
1577
- return !!this._def.checks.find((ch) => ch.kind === "url");
1578
- }
1579
- get isEmoji() {
1580
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
1581
- }
1582
- get isUUID() {
1583
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
1584
- }
1585
- get isCUID() {
1586
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
1587
- }
1588
- get isCUID2() {
1589
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1590
- }
1591
- get isULID() {
1592
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
1593
- }
1594
- get isIP() {
1595
- return !!this._def.checks.find((ch) => ch.kind === "ip");
1596
- }
1597
- get minLength() {
1598
- let min = null;
1599
- for (const ch of this._def.checks) {
1600
- if (ch.kind === "min") {
1601
- if (min === null || ch.value > min)
1602
- min = ch.value;
1603
- }
1604
- }
1605
- return min;
1606
- }
1607
- get maxLength() {
1608
- let max = null;
1609
- for (const ch of this._def.checks) {
1610
- if (ch.kind === "max") {
1611
- if (max === null || ch.value < max)
1612
- max = ch.value;
1613
- }
1614
- }
1615
- return max;
1616
- }
1617
- }
1618
- exports.ZodString = ZodString;
1619
- ZodString.create = (params) => {
1620
- var _a;
1621
- return new ZodString({
1622
- checks: [],
1623
- typeName: ZodFirstPartyTypeKind.ZodString,
1624
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1625
- ...processCreateParams(params),
1626
- });
1627
- };
1628
- // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
1629
- function floatSafeRemainder(val, step) {
1630
- const valDecCount = (val.toString().split(".")[1] || "").length;
1631
- const stepDecCount = (step.toString().split(".")[1] || "").length;
1632
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1633
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1634
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1635
- return (valInt % stepInt) / Math.pow(10, decCount);
1636
- }
1637
- class ZodNumber extends ZodType {
1638
- constructor() {
1639
- super(...arguments);
1640
- this.min = this.gte;
1641
- this.max = this.lte;
1642
- this.step = this.multipleOf;
1643
- }
1644
- _parse(input) {
1645
- if (this._def.coerce) {
1646
- input.data = Number(input.data);
1647
- }
1648
- const parsedType = this._getType(input);
1649
- if (parsedType !== util_1.ZodParsedType.number) {
1650
- const ctx = this._getOrReturnCtx(input);
1651
- (0, parseUtil_1.addIssueToContext)(ctx, {
1652
- code: ZodError_1.ZodIssueCode.invalid_type,
1653
- expected: util_1.ZodParsedType.number,
1654
- received: ctx.parsedType,
1655
- });
1656
- return parseUtil_1.INVALID;
1657
- }
1658
- let ctx = undefined;
1659
- const status = new parseUtil_1.ParseStatus();
1660
- for (const check of this._def.checks) {
1661
- if (check.kind === "int") {
1662
- if (!util_1.util.isInteger(input.data)) {
1663
- ctx = this._getOrReturnCtx(input, ctx);
1664
- (0, parseUtil_1.addIssueToContext)(ctx, {
1665
- code: ZodError_1.ZodIssueCode.invalid_type,
1666
- expected: "integer",
1667
- received: "float",
1668
- message: check.message,
1669
- });
1670
- status.dirty();
1671
- }
1672
- }
1673
- else if (check.kind === "min") {
1674
- const tooSmall = check.inclusive
1675
- ? input.data < check.value
1676
- : input.data <= check.value;
1677
- if (tooSmall) {
1678
- ctx = this._getOrReturnCtx(input, ctx);
1679
- (0, parseUtil_1.addIssueToContext)(ctx, {
1680
- code: ZodError_1.ZodIssueCode.too_small,
1681
- minimum: check.value,
1682
- type: "number",
1683
- inclusive: check.inclusive,
1684
- exact: false,
1685
- message: check.message,
1686
- });
1687
- status.dirty();
1688
- }
1689
- }
1690
- else if (check.kind === "max") {
1691
- const tooBig = check.inclusive
1692
- ? input.data > check.value
1693
- : input.data >= check.value;
1694
- if (tooBig) {
1695
- ctx = this._getOrReturnCtx(input, ctx);
1696
- (0, parseUtil_1.addIssueToContext)(ctx, {
1697
- code: ZodError_1.ZodIssueCode.too_big,
1698
- maximum: check.value,
1699
- type: "number",
1700
- inclusive: check.inclusive,
1701
- exact: false,
1702
- message: check.message,
1703
- });
1704
- status.dirty();
1705
- }
1706
- }
1707
- else if (check.kind === "multipleOf") {
1708
- if (floatSafeRemainder(input.data, check.value) !== 0) {
1709
- ctx = this._getOrReturnCtx(input, ctx);
1710
- (0, parseUtil_1.addIssueToContext)(ctx, {
1711
- code: ZodError_1.ZodIssueCode.not_multiple_of,
1712
- multipleOf: check.value,
1713
- message: check.message,
1714
- });
1715
- status.dirty();
1716
- }
1717
- }
1718
- else if (check.kind === "finite") {
1719
- if (!Number.isFinite(input.data)) {
1720
- ctx = this._getOrReturnCtx(input, ctx);
1721
- (0, parseUtil_1.addIssueToContext)(ctx, {
1722
- code: ZodError_1.ZodIssueCode.not_finite,
1723
- message: check.message,
1724
- });
1725
- status.dirty();
1726
- }
1727
- }
1728
- else {
1729
- util_1.util.assertNever(check);
1730
- }
1731
- }
1732
- return { status: status.value, value: input.data };
1733
- }
1734
- gte(value, message) {
1735
- return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
1736
- }
1737
- gt(value, message) {
1738
- return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
1739
- }
1740
- lte(value, message) {
1741
- return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
1742
- }
1743
- lt(value, message) {
1744
- return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
1745
- }
1746
- setLimit(kind, value, inclusive, message) {
1747
- return new ZodNumber({
1748
- ...this._def,
1749
- checks: [
1750
- ...this._def.checks,
1751
- {
1752
- kind,
1753
- value,
1754
- inclusive,
1755
- message: errorUtil_1.errorUtil.toString(message),
1756
- },
1757
- ],
1758
- });
1759
- }
1760
- _addCheck(check) {
1761
- return new ZodNumber({
1762
- ...this._def,
1763
- checks: [...this._def.checks, check],
1764
- });
1765
- }
1766
- int(message) {
1767
- return this._addCheck({
1768
- kind: "int",
1769
- message: errorUtil_1.errorUtil.toString(message),
1770
- });
1771
- }
1772
- positive(message) {
1773
- return this._addCheck({
1774
- kind: "min",
1775
- value: 0,
1776
- inclusive: false,
1777
- message: errorUtil_1.errorUtil.toString(message),
1778
- });
1779
- }
1780
- negative(message) {
1781
- return this._addCheck({
1782
- kind: "max",
1783
- value: 0,
1784
- inclusive: false,
1785
- message: errorUtil_1.errorUtil.toString(message),
1786
- });
1787
- }
1788
- nonpositive(message) {
1789
- return this._addCheck({
1790
- kind: "max",
1791
- value: 0,
1792
- inclusive: true,
1793
- message: errorUtil_1.errorUtil.toString(message),
1794
- });
1795
- }
1796
- nonnegative(message) {
1797
- return this._addCheck({
1798
- kind: "min",
1799
- value: 0,
1800
- inclusive: true,
1801
- message: errorUtil_1.errorUtil.toString(message),
1802
- });
1803
- }
1804
- multipleOf(value, message) {
1805
- return this._addCheck({
1806
- kind: "multipleOf",
1807
- value: value,
1808
- message: errorUtil_1.errorUtil.toString(message),
1809
- });
1810
- }
1811
- finite(message) {
1812
- return this._addCheck({
1813
- kind: "finite",
1814
- message: errorUtil_1.errorUtil.toString(message),
1815
- });
1816
- }
1817
- safe(message) {
1818
- return this._addCheck({
1819
- kind: "min",
1820
- inclusive: true,
1821
- value: Number.MIN_SAFE_INTEGER,
1822
- message: errorUtil_1.errorUtil.toString(message),
1823
- })._addCheck({
1824
- kind: "max",
1825
- inclusive: true,
1826
- value: Number.MAX_SAFE_INTEGER,
1827
- message: errorUtil_1.errorUtil.toString(message),
1828
- });
1829
- }
1830
- get minValue() {
1831
- let min = null;
1832
- for (const ch of this._def.checks) {
1833
- if (ch.kind === "min") {
1834
- if (min === null || ch.value > min)
1835
- min = ch.value;
1836
- }
1837
- }
1838
- return min;
1839
- }
1840
- get maxValue() {
1841
- let max = null;
1842
- for (const ch of this._def.checks) {
1843
- if (ch.kind === "max") {
1844
- if (max === null || ch.value < max)
1845
- max = ch.value;
1846
- }
1847
- }
1848
- return max;
1849
- }
1850
- get isInt() {
1851
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
1852
- (ch.kind === "multipleOf" && util_1.util.isInteger(ch.value)));
1853
- }
1854
- get isFinite() {
1855
- let max = null, min = null;
1856
- for (const ch of this._def.checks) {
1857
- if (ch.kind === "finite" ||
1858
- ch.kind === "int" ||
1859
- ch.kind === "multipleOf") {
1860
- return true;
1861
- }
1862
- else if (ch.kind === "min") {
1863
- if (min === null || ch.value > min)
1864
- min = ch.value;
1865
- }
1866
- else if (ch.kind === "max") {
1867
- if (max === null || ch.value < max)
1868
- max = ch.value;
1869
- }
1870
- }
1871
- return Number.isFinite(min) && Number.isFinite(max);
1872
- }
1873
- }
1874
- exports.ZodNumber = ZodNumber;
1875
- ZodNumber.create = (params) => {
1876
- return new ZodNumber({
1877
- checks: [],
1878
- typeName: ZodFirstPartyTypeKind.ZodNumber,
1879
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1880
- ...processCreateParams(params),
1881
- });
1882
- };
1883
- class ZodBigInt extends ZodType {
1884
- constructor() {
1885
- super(...arguments);
1886
- this.min = this.gte;
1887
- this.max = this.lte;
1888
- }
1889
- _parse(input) {
1890
- if (this._def.coerce) {
1891
- input.data = BigInt(input.data);
1892
- }
1893
- const parsedType = this._getType(input);
1894
- if (parsedType !== util_1.ZodParsedType.bigint) {
1895
- const ctx = this._getOrReturnCtx(input);
1896
- (0, parseUtil_1.addIssueToContext)(ctx, {
1897
- code: ZodError_1.ZodIssueCode.invalid_type,
1898
- expected: util_1.ZodParsedType.bigint,
1899
- received: ctx.parsedType,
1900
- });
1901
- return parseUtil_1.INVALID;
1902
- }
1903
- let ctx = undefined;
1904
- const status = new parseUtil_1.ParseStatus();
1905
- for (const check of this._def.checks) {
1906
- if (check.kind === "min") {
1907
- const tooSmall = check.inclusive
1908
- ? input.data < check.value
1909
- : input.data <= check.value;
1910
- if (tooSmall) {
1911
- ctx = this._getOrReturnCtx(input, ctx);
1912
- (0, parseUtil_1.addIssueToContext)(ctx, {
1913
- code: ZodError_1.ZodIssueCode.too_small,
1914
- type: "bigint",
1915
- minimum: check.value,
1916
- inclusive: check.inclusive,
1917
- message: check.message,
1918
- });
1919
- status.dirty();
1920
- }
1921
- }
1922
- else if (check.kind === "max") {
1923
- const tooBig = check.inclusive
1924
- ? input.data > check.value
1925
- : input.data >= check.value;
1926
- if (tooBig) {
1927
- ctx = this._getOrReturnCtx(input, ctx);
1928
- (0, parseUtil_1.addIssueToContext)(ctx, {
1929
- code: ZodError_1.ZodIssueCode.too_big,
1930
- type: "bigint",
1931
- maximum: check.value,
1932
- inclusive: check.inclusive,
1933
- message: check.message,
1934
- });
1935
- status.dirty();
1936
- }
1937
- }
1938
- else if (check.kind === "multipleOf") {
1939
- if (input.data % check.value !== BigInt(0)) {
1940
- ctx = this._getOrReturnCtx(input, ctx);
1941
- (0, parseUtil_1.addIssueToContext)(ctx, {
1942
- code: ZodError_1.ZodIssueCode.not_multiple_of,
1943
- multipleOf: check.value,
1944
- message: check.message,
1945
- });
1946
- status.dirty();
1947
- }
1948
- }
1949
- else {
1950
- util_1.util.assertNever(check);
1951
- }
1952
- }
1953
- return { status: status.value, value: input.data };
1954
- }
1955
- gte(value, message) {
1956
- return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
1957
- }
1958
- gt(value, message) {
1959
- return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
1960
- }
1961
- lte(value, message) {
1962
- return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
1963
- }
1964
- lt(value, message) {
1965
- return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
1966
- }
1967
- setLimit(kind, value, inclusive, message) {
1968
- return new ZodBigInt({
1969
- ...this._def,
1970
- checks: [
1971
- ...this._def.checks,
1972
- {
1973
- kind,
1974
- value,
1975
- inclusive,
1976
- message: errorUtil_1.errorUtil.toString(message),
1977
- },
1978
- ],
1979
- });
1980
- }
1981
- _addCheck(check) {
1982
- return new ZodBigInt({
1983
- ...this._def,
1984
- checks: [...this._def.checks, check],
1985
- });
1986
- }
1987
- positive(message) {
1988
- return this._addCheck({
1989
- kind: "min",
1990
- value: BigInt(0),
1991
- inclusive: false,
1992
- message: errorUtil_1.errorUtil.toString(message),
1993
- });
1994
- }
1995
- negative(message) {
1996
- return this._addCheck({
1997
- kind: "max",
1998
- value: BigInt(0),
1999
- inclusive: false,
2000
- message: errorUtil_1.errorUtil.toString(message),
2001
- });
2002
- }
2003
- nonpositive(message) {
2004
- return this._addCheck({
2005
- kind: "max",
2006
- value: BigInt(0),
2007
- inclusive: true,
2008
- message: errorUtil_1.errorUtil.toString(message),
2009
- });
2010
- }
2011
- nonnegative(message) {
2012
- return this._addCheck({
2013
- kind: "min",
2014
- value: BigInt(0),
2015
- inclusive: true,
2016
- message: errorUtil_1.errorUtil.toString(message),
2017
- });
2018
- }
2019
- multipleOf(value, message) {
2020
- return this._addCheck({
2021
- kind: "multipleOf",
2022
- value,
2023
- message: errorUtil_1.errorUtil.toString(message),
2024
- });
2025
- }
2026
- get minValue() {
2027
- let min = null;
2028
- for (const ch of this._def.checks) {
2029
- if (ch.kind === "min") {
2030
- if (min === null || ch.value > min)
2031
- min = ch.value;
2032
- }
2033
- }
2034
- return min;
2035
- }
2036
- get maxValue() {
2037
- let max = null;
2038
- for (const ch of this._def.checks) {
2039
- if (ch.kind === "max") {
2040
- if (max === null || ch.value < max)
2041
- max = ch.value;
2042
- }
2043
- }
2044
- return max;
2045
- }
2046
- }
2047
- exports.ZodBigInt = ZodBigInt;
2048
- ZodBigInt.create = (params) => {
2049
- var _a;
2050
- return new ZodBigInt({
2051
- checks: [],
2052
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
2053
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2054
- ...processCreateParams(params),
2055
- });
2056
- };
2057
- class ZodBoolean extends ZodType {
2058
- _parse(input) {
2059
- if (this._def.coerce) {
2060
- input.data = Boolean(input.data);
2061
- }
2062
- const parsedType = this._getType(input);
2063
- if (parsedType !== util_1.ZodParsedType.boolean) {
2064
- const ctx = this._getOrReturnCtx(input);
2065
- (0, parseUtil_1.addIssueToContext)(ctx, {
2066
- code: ZodError_1.ZodIssueCode.invalid_type,
2067
- expected: util_1.ZodParsedType.boolean,
2068
- received: ctx.parsedType,
2069
- });
2070
- return parseUtil_1.INVALID;
2071
- }
2072
- return (0, parseUtil_1.OK)(input.data);
2073
- }
2074
- }
2075
- exports.ZodBoolean = ZodBoolean;
2076
- ZodBoolean.create = (params) => {
2077
- return new ZodBoolean({
2078
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
2079
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2080
- ...processCreateParams(params),
2081
- });
2082
- };
2083
- class ZodDate extends ZodType {
2084
- _parse(input) {
2085
- if (this._def.coerce) {
2086
- input.data = new Date(input.data);
2087
- }
2088
- const parsedType = this._getType(input);
2089
- if (parsedType !== util_1.ZodParsedType.date) {
2090
- const ctx = this._getOrReturnCtx(input);
2091
- (0, parseUtil_1.addIssueToContext)(ctx, {
2092
- code: ZodError_1.ZodIssueCode.invalid_type,
2093
- expected: util_1.ZodParsedType.date,
2094
- received: ctx.parsedType,
2095
- });
2096
- return parseUtil_1.INVALID;
2097
- }
2098
- if (isNaN(input.data.getTime())) {
2099
- const ctx = this._getOrReturnCtx(input);
2100
- (0, parseUtil_1.addIssueToContext)(ctx, {
2101
- code: ZodError_1.ZodIssueCode.invalid_date,
2102
- });
2103
- return parseUtil_1.INVALID;
2104
- }
2105
- const status = new parseUtil_1.ParseStatus();
2106
- let ctx = undefined;
2107
- for (const check of this._def.checks) {
2108
- if (check.kind === "min") {
2109
- if (input.data.getTime() < check.value) {
2110
- ctx = this._getOrReturnCtx(input, ctx);
2111
- (0, parseUtil_1.addIssueToContext)(ctx, {
2112
- code: ZodError_1.ZodIssueCode.too_small,
2113
- message: check.message,
2114
- inclusive: true,
2115
- exact: false,
2116
- minimum: check.value,
2117
- type: "date",
2118
- });
2119
- status.dirty();
2120
- }
2121
- }
2122
- else if (check.kind === "max") {
2123
- if (input.data.getTime() > check.value) {
2124
- ctx = this._getOrReturnCtx(input, ctx);
2125
- (0, parseUtil_1.addIssueToContext)(ctx, {
2126
- code: ZodError_1.ZodIssueCode.too_big,
2127
- message: check.message,
2128
- inclusive: true,
2129
- exact: false,
2130
- maximum: check.value,
2131
- type: "date",
2132
- });
2133
- status.dirty();
2134
- }
2135
- }
2136
- else {
2137
- util_1.util.assertNever(check);
2138
- }
2139
- }
2140
- return {
2141
- status: status.value,
2142
- value: new Date(input.data.getTime()),
2143
- };
2144
- }
2145
- _addCheck(check) {
2146
- return new ZodDate({
2147
- ...this._def,
2148
- checks: [...this._def.checks, check],
2149
- });
2150
- }
2151
- min(minDate, message) {
2152
- return this._addCheck({
2153
- kind: "min",
2154
- value: minDate.getTime(),
2155
- message: errorUtil_1.errorUtil.toString(message),
2156
- });
2157
- }
2158
- max(maxDate, message) {
2159
- return this._addCheck({
2160
- kind: "max",
2161
- value: maxDate.getTime(),
2162
- message: errorUtil_1.errorUtil.toString(message),
2163
- });
2164
- }
2165
- get minDate() {
2166
- let min = null;
2167
- for (const ch of this._def.checks) {
2168
- if (ch.kind === "min") {
2169
- if (min === null || ch.value > min)
2170
- min = ch.value;
2171
- }
2172
- }
2173
- return min != null ? new Date(min) : null;
2174
- }
2175
- get maxDate() {
2176
- let max = null;
2177
- for (const ch of this._def.checks) {
2178
- if (ch.kind === "max") {
2179
- if (max === null || ch.value < max)
2180
- max = ch.value;
2181
- }
2182
- }
2183
- return max != null ? new Date(max) : null;
2184
- }
2185
- }
2186
- exports.ZodDate = ZodDate;
2187
- ZodDate.create = (params) => {
2188
- return new ZodDate({
2189
- checks: [],
2190
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2191
- typeName: ZodFirstPartyTypeKind.ZodDate,
2192
- ...processCreateParams(params),
2193
- });
2194
- };
2195
- class ZodSymbol extends ZodType {
2196
- _parse(input) {
2197
- const parsedType = this._getType(input);
2198
- if (parsedType !== util_1.ZodParsedType.symbol) {
2199
- const ctx = this._getOrReturnCtx(input);
2200
- (0, parseUtil_1.addIssueToContext)(ctx, {
2201
- code: ZodError_1.ZodIssueCode.invalid_type,
2202
- expected: util_1.ZodParsedType.symbol,
2203
- received: ctx.parsedType,
2204
- });
2205
- return parseUtil_1.INVALID;
2206
- }
2207
- return (0, parseUtil_1.OK)(input.data);
2208
- }
2209
- }
2210
- exports.ZodSymbol = ZodSymbol;
2211
- ZodSymbol.create = (params) => {
2212
- return new ZodSymbol({
2213
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
2214
- ...processCreateParams(params),
2215
- });
2216
- };
2217
- class ZodUndefined extends ZodType {
2218
- _parse(input) {
2219
- const parsedType = this._getType(input);
2220
- if (parsedType !== util_1.ZodParsedType.undefined) {
2221
- const ctx = this._getOrReturnCtx(input);
2222
- (0, parseUtil_1.addIssueToContext)(ctx, {
2223
- code: ZodError_1.ZodIssueCode.invalid_type,
2224
- expected: util_1.ZodParsedType.undefined,
2225
- received: ctx.parsedType,
2226
- });
2227
- return parseUtil_1.INVALID;
2228
- }
2229
- return (0, parseUtil_1.OK)(input.data);
2230
- }
2231
- }
2232
- exports.ZodUndefined = ZodUndefined;
2233
- ZodUndefined.create = (params) => {
2234
- return new ZodUndefined({
2235
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
2236
- ...processCreateParams(params),
2237
- });
2238
- };
2239
- class ZodNull extends ZodType {
2240
- _parse(input) {
2241
- const parsedType = this._getType(input);
2242
- if (parsedType !== util_1.ZodParsedType.null) {
2243
- const ctx = this._getOrReturnCtx(input);
2244
- (0, parseUtil_1.addIssueToContext)(ctx, {
2245
- code: ZodError_1.ZodIssueCode.invalid_type,
2246
- expected: util_1.ZodParsedType.null,
2247
- received: ctx.parsedType,
2248
- });
2249
- return parseUtil_1.INVALID;
2250
- }
2251
- return (0, parseUtil_1.OK)(input.data);
2252
- }
2253
- }
2254
- exports.ZodNull = ZodNull;
2255
- ZodNull.create = (params) => {
2256
- return new ZodNull({
2257
- typeName: ZodFirstPartyTypeKind.ZodNull,
2258
- ...processCreateParams(params),
2259
- });
2260
- };
2261
- class ZodAny extends ZodType {
2262
- constructor() {
2263
- super(...arguments);
2264
- // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
2265
- this._any = true;
2266
- }
2267
- _parse(input) {
2268
- return (0, parseUtil_1.OK)(input.data);
2269
- }
2270
- }
2271
- exports.ZodAny = ZodAny;
2272
- ZodAny.create = (params) => {
2273
- return new ZodAny({
2274
- typeName: ZodFirstPartyTypeKind.ZodAny,
2275
- ...processCreateParams(params),
2276
- });
2277
- };
2278
- class ZodUnknown extends ZodType {
2279
- constructor() {
2280
- super(...arguments);
2281
- // required
2282
- this._unknown = true;
2283
- }
2284
- _parse(input) {
2285
- return (0, parseUtil_1.OK)(input.data);
2286
- }
2287
- }
2288
- exports.ZodUnknown = ZodUnknown;
2289
- ZodUnknown.create = (params) => {
2290
- return new ZodUnknown({
2291
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
2292
- ...processCreateParams(params),
2293
- });
2294
- };
2295
- class ZodNever extends ZodType {
2296
- _parse(input) {
2297
- const ctx = this._getOrReturnCtx(input);
2298
- (0, parseUtil_1.addIssueToContext)(ctx, {
2299
- code: ZodError_1.ZodIssueCode.invalid_type,
2300
- expected: util_1.ZodParsedType.never,
2301
- received: ctx.parsedType,
2302
- });
2303
- return parseUtil_1.INVALID;
2304
- }
2305
- }
2306
- exports.ZodNever = ZodNever;
2307
- ZodNever.create = (params) => {
2308
- return new ZodNever({
2309
- typeName: ZodFirstPartyTypeKind.ZodNever,
2310
- ...processCreateParams(params),
2311
- });
2312
- };
2313
- class ZodVoid extends ZodType {
2314
- _parse(input) {
2315
- const parsedType = this._getType(input);
2316
- if (parsedType !== util_1.ZodParsedType.undefined) {
2317
- const ctx = this._getOrReturnCtx(input);
2318
- (0, parseUtil_1.addIssueToContext)(ctx, {
2319
- code: ZodError_1.ZodIssueCode.invalid_type,
2320
- expected: util_1.ZodParsedType.void,
2321
- received: ctx.parsedType,
2322
- });
2323
- return parseUtil_1.INVALID;
2324
- }
2325
- return (0, parseUtil_1.OK)(input.data);
2326
- }
2327
- }
2328
- exports.ZodVoid = ZodVoid;
2329
- ZodVoid.create = (params) => {
2330
- return new ZodVoid({
2331
- typeName: ZodFirstPartyTypeKind.ZodVoid,
2332
- ...processCreateParams(params),
2333
- });
2334
- };
2335
- class ZodArray extends ZodType {
2336
- _parse(input) {
2337
- const { ctx, status } = this._processInputParams(input);
2338
- const def = this._def;
2339
- if (ctx.parsedType !== util_1.ZodParsedType.array) {
2340
- (0, parseUtil_1.addIssueToContext)(ctx, {
2341
- code: ZodError_1.ZodIssueCode.invalid_type,
2342
- expected: util_1.ZodParsedType.array,
2343
- received: ctx.parsedType,
2344
- });
2345
- return parseUtil_1.INVALID;
2346
- }
2347
- if (def.exactLength !== null) {
2348
- const tooBig = ctx.data.length > def.exactLength.value;
2349
- const tooSmall = ctx.data.length < def.exactLength.value;
2350
- if (tooBig || tooSmall) {
2351
- (0, parseUtil_1.addIssueToContext)(ctx, {
2352
- code: tooBig ? ZodError_1.ZodIssueCode.too_big : ZodError_1.ZodIssueCode.too_small,
2353
- minimum: (tooSmall ? def.exactLength.value : undefined),
2354
- maximum: (tooBig ? def.exactLength.value : undefined),
2355
- type: "array",
2356
- inclusive: true,
2357
- exact: true,
2358
- message: def.exactLength.message,
2359
- });
2360
- status.dirty();
2361
- }
2362
- }
2363
- if (def.minLength !== null) {
2364
- if (ctx.data.length < def.minLength.value) {
2365
- (0, parseUtil_1.addIssueToContext)(ctx, {
2366
- code: ZodError_1.ZodIssueCode.too_small,
2367
- minimum: def.minLength.value,
2368
- type: "array",
2369
- inclusive: true,
2370
- exact: false,
2371
- message: def.minLength.message,
2372
- });
2373
- status.dirty();
2374
- }
2375
- }
2376
- if (def.maxLength !== null) {
2377
- if (ctx.data.length > def.maxLength.value) {
2378
- (0, parseUtil_1.addIssueToContext)(ctx, {
2379
- code: ZodError_1.ZodIssueCode.too_big,
2380
- maximum: def.maxLength.value,
2381
- type: "array",
2382
- inclusive: true,
2383
- exact: false,
2384
- message: def.maxLength.message,
2385
- });
2386
- status.dirty();
2387
- }
2388
- }
2389
- if (ctx.common.async) {
2390
- return Promise.all([...ctx.data].map((item, i) => {
2391
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2392
- })).then((result) => {
2393
- return parseUtil_1.ParseStatus.mergeArray(status, result);
2394
- });
2395
- }
2396
- const result = [...ctx.data].map((item, i) => {
2397
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2398
- });
2399
- return parseUtil_1.ParseStatus.mergeArray(status, result);
2400
- }
2401
- get element() {
2402
- return this._def.type;
2403
- }
2404
- min(minLength, message) {
2405
- return new ZodArray({
2406
- ...this._def,
2407
- minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) },
2408
- });
2409
- }
2410
- max(maxLength, message) {
2411
- return new ZodArray({
2412
- ...this._def,
2413
- maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) },
2414
- });
2415
- }
2416
- length(len, message) {
2417
- return new ZodArray({
2418
- ...this._def,
2419
- exactLength: { value: len, message: errorUtil_1.errorUtil.toString(message) },
2420
- });
2421
- }
2422
- nonempty(message) {
2423
- return this.min(1, message);
2424
- }
2425
- }
2426
- exports.ZodArray = ZodArray;
2427
- ZodArray.create = (schema, params) => {
2428
- return new ZodArray({
2429
- type: schema,
2430
- minLength: null,
2431
- maxLength: null,
2432
- exactLength: null,
2433
- typeName: ZodFirstPartyTypeKind.ZodArray,
2434
- ...processCreateParams(params),
2435
- });
2436
- };
2437
- function deepPartialify(schema) {
2438
- if (schema instanceof ZodObject) {
2439
- const newShape = {};
2440
- for (const key in schema.shape) {
2441
- const fieldSchema = schema.shape[key];
2442
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2443
- }
2444
- return new ZodObject({
2445
- ...schema._def,
2446
- shape: () => newShape,
2447
- });
2448
- }
2449
- else if (schema instanceof ZodArray) {
2450
- return new ZodArray({
2451
- ...schema._def,
2452
- type: deepPartialify(schema.element),
2453
- });
2454
- }
2455
- else if (schema instanceof ZodOptional) {
2456
- return ZodOptional.create(deepPartialify(schema.unwrap()));
2457
- }
2458
- else if (schema instanceof ZodNullable) {
2459
- return ZodNullable.create(deepPartialify(schema.unwrap()));
2460
- }
2461
- else if (schema instanceof ZodTuple) {
2462
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2463
- }
2464
- else {
2465
- return schema;
2466
- }
2467
- }
2468
- class ZodObject extends ZodType {
2469
- constructor() {
2470
- super(...arguments);
2471
- this._cached = null;
2472
- /**
2473
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
2474
- * If you want to pass through unknown properties, use `.passthrough()` instead.
2475
- */
2476
- this.nonstrict = this.passthrough;
2477
- // extend<
2478
- // Augmentation extends ZodRawShape,
2479
- // NewOutput extends util.flatten<{
2480
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2481
- // ? Augmentation[k]["_output"]
2482
- // : k extends keyof Output
2483
- // ? Output[k]
2484
- // : never;
2485
- // }>,
2486
- // NewInput extends util.flatten<{
2487
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2488
- // ? Augmentation[k]["_input"]
2489
- // : k extends keyof Input
2490
- // ? Input[k]
2491
- // : never;
2492
- // }>
2493
- // >(
2494
- // augmentation: Augmentation
2495
- // ): ZodObject<
2496
- // extendShape<T, Augmentation>,
2497
- // UnknownKeys,
2498
- // Catchall,
2499
- // NewOutput,
2500
- // NewInput
2501
- // > {
2502
- // return new ZodObject({
2503
- // ...this._def,
2504
- // shape: () => ({
2505
- // ...this._def.shape(),
2506
- // ...augmentation,
2507
- // }),
2508
- // }) as any;
2509
- // }
2510
- /**
2511
- * @deprecated Use `.extend` instead
2512
- * */
2513
- this.augment = this.extend;
2514
- }
2515
- _getCached() {
2516
- if (this._cached !== null)
2517
- return this._cached;
2518
- const shape = this._def.shape();
2519
- const keys = util_1.util.objectKeys(shape);
2520
- return (this._cached = { shape, keys });
2521
- }
2522
- _parse(input) {
2523
- const parsedType = this._getType(input);
2524
- if (parsedType !== util_1.ZodParsedType.object) {
2525
- const ctx = this._getOrReturnCtx(input);
2526
- (0, parseUtil_1.addIssueToContext)(ctx, {
2527
- code: ZodError_1.ZodIssueCode.invalid_type,
2528
- expected: util_1.ZodParsedType.object,
2529
- received: ctx.parsedType,
2530
- });
2531
- return parseUtil_1.INVALID;
2532
- }
2533
- const { status, ctx } = this._processInputParams(input);
2534
- const { shape, keys: shapeKeys } = this._getCached();
2535
- const extraKeys = [];
2536
- if (!(this._def.catchall instanceof ZodNever &&
2537
- this._def.unknownKeys === "strip")) {
2538
- for (const key in ctx.data) {
2539
- if (!shapeKeys.includes(key)) {
2540
- extraKeys.push(key);
2541
- }
2542
- }
2543
- }
2544
- const pairs = [];
2545
- for (const key of shapeKeys) {
2546
- const keyValidator = shape[key];
2547
- const value = ctx.data[key];
2548
- pairs.push({
2549
- key: { status: "valid", value: key },
2550
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2551
- alwaysSet: key in ctx.data,
2552
- });
2553
- }
2554
- if (this._def.catchall instanceof ZodNever) {
2555
- const unknownKeys = this._def.unknownKeys;
2556
- if (unknownKeys === "passthrough") {
2557
- for (const key of extraKeys) {
2558
- pairs.push({
2559
- key: { status: "valid", value: key },
2560
- value: { status: "valid", value: ctx.data[key] },
2561
- });
2562
- }
2563
- }
2564
- else if (unknownKeys === "strict") {
2565
- if (extraKeys.length > 0) {
2566
- (0, parseUtil_1.addIssueToContext)(ctx, {
2567
- code: ZodError_1.ZodIssueCode.unrecognized_keys,
2568
- keys: extraKeys,
2569
- });
2570
- status.dirty();
2571
- }
2572
- }
2573
- else if (unknownKeys === "strip") {
2574
- }
2575
- else {
2576
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2577
- }
2578
- }
2579
- else {
2580
- // run catchall validation
2581
- const catchall = this._def.catchall;
2582
- for (const key of extraKeys) {
2583
- const value = ctx.data[key];
2584
- pairs.push({
2585
- key: { status: "valid", value: key },
2586
- value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
2587
- ),
2588
- alwaysSet: key in ctx.data,
2589
- });
2590
- }
2591
- }
2592
- if (ctx.common.async) {
2593
- return Promise.resolve()
2594
- .then(async () => {
2595
- const syncPairs = [];
2596
- for (const pair of pairs) {
2597
- const key = await pair.key;
2598
- syncPairs.push({
2599
- key,
2600
- value: await pair.value,
2601
- alwaysSet: pair.alwaysSet,
2602
- });
2603
- }
2604
- return syncPairs;
2605
- })
2606
- .then((syncPairs) => {
2607
- return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
2608
- });
2609
- }
2610
- else {
2611
- return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
2612
- }
2613
- }
2614
- get shape() {
2615
- return this._def.shape();
2616
- }
2617
- strict(message) {
2618
- errorUtil_1.errorUtil.errToObj;
2619
- return new ZodObject({
2620
- ...this._def,
2621
- unknownKeys: "strict",
2622
- ...(message !== undefined
2623
- ? {
2624
- errorMap: (issue, ctx) => {
2625
- var _a, _b, _c, _d;
2626
- 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;
2627
- if (issue.code === "unrecognized_keys")
2628
- return {
2629
- message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2630
- };
2631
- return {
2632
- message: defaultError,
2633
- };
2634
- },
2635
- }
2636
- : {}),
2637
- });
2638
- }
2639
- strip() {
2640
- return new ZodObject({
2641
- ...this._def,
2642
- unknownKeys: "strip",
2643
- });
2644
- }
2645
- passthrough() {
2646
- return new ZodObject({
2647
- ...this._def,
2648
- unknownKeys: "passthrough",
2649
- });
2650
- }
2651
- // const AugmentFactory =
2652
- // <Def extends ZodObjectDef>(def: Def) =>
2653
- // <Augmentation extends ZodRawShape>(
2654
- // augmentation: Augmentation
2655
- // ): ZodObject<
2656
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2657
- // Def["unknownKeys"],
2658
- // Def["catchall"]
2659
- // > => {
2660
- // return new ZodObject({
2661
- // ...def,
2662
- // shape: () => ({
2663
- // ...def.shape(),
2664
- // ...augmentation,
2665
- // }),
2666
- // }) as any;
2667
- // };
2668
- extend(augmentation) {
2669
- return new ZodObject({
2670
- ...this._def,
2671
- shape: () => ({
2672
- ...this._def.shape(),
2673
- ...augmentation,
2674
- }),
2675
- });
2676
- }
2677
- /**
2678
- * Prior to zod@1.0.12 there was a bug in the
2679
- * inferred type of merged objects. Please
2680
- * upgrade if you are experiencing issues.
2681
- */
2682
- merge(merging) {
2683
- const merged = new ZodObject({
2684
- unknownKeys: merging._def.unknownKeys,
2685
- catchall: merging._def.catchall,
2686
- shape: () => ({
2687
- ...this._def.shape(),
2688
- ...merging._def.shape(),
2689
- }),
2690
- typeName: ZodFirstPartyTypeKind.ZodObject,
2691
- });
2692
- return merged;
2693
- }
2694
- // merge<
2695
- // Incoming extends AnyZodObject,
2696
- // Augmentation extends Incoming["shape"],
2697
- // NewOutput extends {
2698
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2699
- // ? Augmentation[k]["_output"]
2700
- // : k extends keyof Output
2701
- // ? Output[k]
2702
- // : never;
2703
- // },
2704
- // NewInput extends {
2705
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2706
- // ? Augmentation[k]["_input"]
2707
- // : k extends keyof Input
2708
- // ? Input[k]
2709
- // : never;
2710
- // }
2711
- // >(
2712
- // merging: Incoming
2713
- // ): ZodObject<
2714
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2715
- // Incoming["_def"]["unknownKeys"],
2716
- // Incoming["_def"]["catchall"],
2717
- // NewOutput,
2718
- // NewInput
2719
- // > {
2720
- // const merged: any = new ZodObject({
2721
- // unknownKeys: merging._def.unknownKeys,
2722
- // catchall: merging._def.catchall,
2723
- // shape: () =>
2724
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2725
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2726
- // }) as any;
2727
- // return merged;
2728
- // }
2729
- setKey(key, schema) {
2730
- return this.augment({ [key]: schema });
2731
- }
2732
- // merge<Incoming extends AnyZodObject>(
2733
- // merging: Incoming
2734
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2735
- // ZodObject<
2736
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2737
- // Incoming["_def"]["unknownKeys"],
2738
- // Incoming["_def"]["catchall"]
2739
- // > {
2740
- // // const mergedShape = objectUtil.mergeShapes(
2741
- // // this._def.shape(),
2742
- // // merging._def.shape()
2743
- // // );
2744
- // const merged: any = new ZodObject({
2745
- // unknownKeys: merging._def.unknownKeys,
2746
- // catchall: merging._def.catchall,
2747
- // shape: () =>
2748
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2749
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2750
- // }) as any;
2751
- // return merged;
2752
- // }
2753
- catchall(index) {
2754
- return new ZodObject({
2755
- ...this._def,
2756
- catchall: index,
2757
- });
2758
- }
2759
- pick(mask) {
2760
- const shape = {};
2761
- util_1.util.objectKeys(mask).forEach((key) => {
2762
- if (mask[key] && this.shape[key]) {
2763
- shape[key] = this.shape[key];
2764
- }
2765
- });
2766
- return new ZodObject({
2767
- ...this._def,
2768
- shape: () => shape,
2769
- });
2770
- }
2771
- omit(mask) {
2772
- const shape = {};
2773
- util_1.util.objectKeys(this.shape).forEach((key) => {
2774
- if (!mask[key]) {
2775
- shape[key] = this.shape[key];
2776
- }
2777
- });
2778
- return new ZodObject({
2779
- ...this._def,
2780
- shape: () => shape,
2781
- });
2782
- }
2783
- /**
2784
- * @deprecated
2785
- */
2786
- deepPartial() {
2787
- return deepPartialify(this);
2788
- }
2789
- partial(mask) {
2790
- const newShape = {};
2791
- util_1.util.objectKeys(this.shape).forEach((key) => {
2792
- const fieldSchema = this.shape[key];
2793
- if (mask && !mask[key]) {
2794
- newShape[key] = fieldSchema;
2795
- }
2796
- else {
2797
- newShape[key] = fieldSchema.optional();
2798
- }
2799
- });
2800
- return new ZodObject({
2801
- ...this._def,
2802
- shape: () => newShape,
2803
- });
2804
- }
2805
- required(mask) {
2806
- const newShape = {};
2807
- util_1.util.objectKeys(this.shape).forEach((key) => {
2808
- if (mask && !mask[key]) {
2809
- newShape[key] = this.shape[key];
2810
- }
2811
- else {
2812
- const fieldSchema = this.shape[key];
2813
- let newField = fieldSchema;
2814
- while (newField instanceof ZodOptional) {
2815
- newField = newField._def.innerType;
2816
- }
2817
- newShape[key] = newField;
2818
- }
2819
- });
2820
- return new ZodObject({
2821
- ...this._def,
2822
- shape: () => newShape,
2823
- });
2824
- }
2825
- keyof() {
2826
- return createZodEnum(util_1.util.objectKeys(this.shape));
2827
- }
2828
- }
2829
- exports.ZodObject = ZodObject;
2830
- ZodObject.create = (shape, params) => {
2831
- return new ZodObject({
2832
- shape: () => shape,
2833
- unknownKeys: "strip",
2834
- catchall: ZodNever.create(),
2835
- typeName: ZodFirstPartyTypeKind.ZodObject,
2836
- ...processCreateParams(params),
2837
- });
2838
- };
2839
- ZodObject.strictCreate = (shape, params) => {
2840
- return new ZodObject({
2841
- shape: () => shape,
2842
- unknownKeys: "strict",
2843
- catchall: ZodNever.create(),
2844
- typeName: ZodFirstPartyTypeKind.ZodObject,
2845
- ...processCreateParams(params),
2846
- });
2847
- };
2848
- ZodObject.lazycreate = (shape, params) => {
2849
- return new ZodObject({
2850
- shape,
2851
- unknownKeys: "strip",
2852
- catchall: ZodNever.create(),
2853
- typeName: ZodFirstPartyTypeKind.ZodObject,
2854
- ...processCreateParams(params),
2855
- });
2856
- };
2857
- class ZodUnion extends ZodType {
2858
- _parse(input) {
2859
- const { ctx } = this._processInputParams(input);
2860
- const options = this._def.options;
2861
- function handleResults(results) {
2862
- // return first issue-free validation if it exists
2863
- for (const result of results) {
2864
- if (result.result.status === "valid") {
2865
- return result.result;
2866
- }
2867
- }
2868
- for (const result of results) {
2869
- if (result.result.status === "dirty") {
2870
- // add issues from dirty option
2871
- ctx.common.issues.push(...result.ctx.common.issues);
2872
- return result.result;
2873
- }
2874
- }
2875
- // return invalid
2876
- const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
2877
- (0, parseUtil_1.addIssueToContext)(ctx, {
2878
- code: ZodError_1.ZodIssueCode.invalid_union,
2879
- unionErrors,
2880
- });
2881
- return parseUtil_1.INVALID;
2882
- }
2883
- if (ctx.common.async) {
2884
- return Promise.all(options.map(async (option) => {
2885
- const childCtx = {
2886
- ...ctx,
2887
- common: {
2888
- ...ctx.common,
2889
- issues: [],
2890
- },
2891
- parent: null,
2892
- };
2893
- return {
2894
- result: await option._parseAsync({
2895
- data: ctx.data,
2896
- path: ctx.path,
2897
- parent: childCtx,
2898
- }),
2899
- ctx: childCtx,
2900
- };
2901
- })).then(handleResults);
2902
- }
2903
- else {
2904
- let dirty = undefined;
2905
- const issues = [];
2906
- for (const option of options) {
2907
- const childCtx = {
2908
- ...ctx,
2909
- common: {
2910
- ...ctx.common,
2911
- issues: [],
2912
- },
2913
- parent: null,
2914
- };
2915
- const result = option._parseSync({
2916
- data: ctx.data,
2917
- path: ctx.path,
2918
- parent: childCtx,
2919
- });
2920
- if (result.status === "valid") {
2921
- return result;
2922
- }
2923
- else if (result.status === "dirty" && !dirty) {
2924
- dirty = { result, ctx: childCtx };
2925
- }
2926
- if (childCtx.common.issues.length) {
2927
- issues.push(childCtx.common.issues);
2928
- }
2929
- }
2930
- if (dirty) {
2931
- ctx.common.issues.push(...dirty.ctx.common.issues);
2932
- return dirty.result;
2933
- }
2934
- const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
2935
- (0, parseUtil_1.addIssueToContext)(ctx, {
2936
- code: ZodError_1.ZodIssueCode.invalid_union,
2937
- unionErrors,
2938
- });
2939
- return parseUtil_1.INVALID;
2940
- }
2941
- }
2942
- get options() {
2943
- return this._def.options;
2944
- }
2945
- }
2946
- exports.ZodUnion = ZodUnion;
2947
- ZodUnion.create = (types, params) => {
2948
- return new ZodUnion({
2949
- options: types,
2950
- typeName: ZodFirstPartyTypeKind.ZodUnion,
2951
- ...processCreateParams(params),
2952
- });
2953
- };
2954
- /////////////////////////////////////////////////////
2955
- /////////////////////////////////////////////////////
2956
- ////////// //////////
2957
- ////////// ZodDiscriminatedUnion //////////
2958
- ////////// //////////
2959
- /////////////////////////////////////////////////////
2960
- /////////////////////////////////////////////////////
2961
- const getDiscriminator = (type) => {
2962
- if (type instanceof ZodLazy) {
2963
- return getDiscriminator(type.schema);
2964
- }
2965
- else if (type instanceof ZodEffects) {
2966
- return getDiscriminator(type.innerType());
2967
- }
2968
- else if (type instanceof ZodLiteral) {
2969
- return [type.value];
2970
- }
2971
- else if (type instanceof ZodEnum) {
2972
- return type.options;
2973
- }
2974
- else if (type instanceof ZodNativeEnum) {
2975
- // eslint-disable-next-line ban/ban
2976
- return Object.keys(type.enum);
2977
- }
2978
- else if (type instanceof ZodDefault) {
2979
- return getDiscriminator(type._def.innerType);
2980
- }
2981
- else if (type instanceof ZodUndefined) {
2982
- return [undefined];
2983
- }
2984
- else if (type instanceof ZodNull) {
2985
- return [null];
2986
- }
2987
- else {
2988
- return null;
2989
- }
2990
- };
2991
- class ZodDiscriminatedUnion extends ZodType {
2992
- _parse(input) {
2993
- const { ctx } = this._processInputParams(input);
2994
- if (ctx.parsedType !== util_1.ZodParsedType.object) {
2995
- (0, parseUtil_1.addIssueToContext)(ctx, {
2996
- code: ZodError_1.ZodIssueCode.invalid_type,
2997
- expected: util_1.ZodParsedType.object,
2998
- received: ctx.parsedType,
2999
- });
3000
- return parseUtil_1.INVALID;
3001
- }
3002
- const discriminator = this.discriminator;
3003
- const discriminatorValue = ctx.data[discriminator];
3004
- const option = this.optionsMap.get(discriminatorValue);
3005
- if (!option) {
3006
- (0, parseUtil_1.addIssueToContext)(ctx, {
3007
- code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
3008
- options: Array.from(this.optionsMap.keys()),
3009
- path: [discriminator],
3010
- });
3011
- return parseUtil_1.INVALID;
3012
- }
3013
- if (ctx.common.async) {
3014
- return option._parseAsync({
3015
- data: ctx.data,
3016
- path: ctx.path,
3017
- parent: ctx,
3018
- });
3019
- }
3020
- else {
3021
- return option._parseSync({
3022
- data: ctx.data,
3023
- path: ctx.path,
3024
- parent: ctx,
3025
- });
3026
- }
3027
- }
3028
- get discriminator() {
3029
- return this._def.discriminator;
3030
- }
3031
- get options() {
3032
- return this._def.options;
3033
- }
3034
- get optionsMap() {
3035
- return this._def.optionsMap;
3036
- }
3037
- /**
3038
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3039
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3040
- * have a different value for each object in the union.
3041
- * @param discriminator the name of the discriminator property
3042
- * @param types an array of object schemas
3043
- * @param params
3044
- */
3045
- static create(discriminator, options, params) {
3046
- // Get all the valid discriminator values
3047
- const optionsMap = new Map();
3048
- // try {
3049
- for (const type of options) {
3050
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3051
- if (!discriminatorValues) {
3052
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3053
- }
3054
- for (const value of discriminatorValues) {
3055
- if (optionsMap.has(value)) {
3056
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3057
- }
3058
- optionsMap.set(value, type);
3059
- }
3060
- }
3061
- return new ZodDiscriminatedUnion({
3062
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3063
- discriminator,
3064
- options,
3065
- optionsMap,
3066
- ...processCreateParams(params),
3067
- });
3068
- }
3069
- }
3070
- exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
3071
- function mergeValues(a, b) {
3072
- const aType = (0, util_1.getParsedType)(a);
3073
- const bType = (0, util_1.getParsedType)(b);
3074
- if (a === b) {
3075
- return { valid: true, data: a };
3076
- }
3077
- else if (aType === util_1.ZodParsedType.object && bType === util_1.ZodParsedType.object) {
3078
- const bKeys = util_1.util.objectKeys(b);
3079
- const sharedKeys = util_1.util
3080
- .objectKeys(a)
3081
- .filter((key) => bKeys.indexOf(key) !== -1);
3082
- const newObj = { ...a, ...b };
3083
- for (const key of sharedKeys) {
3084
- const sharedValue = mergeValues(a[key], b[key]);
3085
- if (!sharedValue.valid) {
3086
- return { valid: false };
3087
- }
3088
- newObj[key] = sharedValue.data;
3089
- }
3090
- return { valid: true, data: newObj };
3091
- }
3092
- else if (aType === util_1.ZodParsedType.array && bType === util_1.ZodParsedType.array) {
3093
- if (a.length !== b.length) {
3094
- return { valid: false };
3095
- }
3096
- const newArray = [];
3097
- for (let index = 0; index < a.length; index++) {
3098
- const itemA = a[index];
3099
- const itemB = b[index];
3100
- const sharedValue = mergeValues(itemA, itemB);
3101
- if (!sharedValue.valid) {
3102
- return { valid: false };
3103
- }
3104
- newArray.push(sharedValue.data);
3105
- }
3106
- return { valid: true, data: newArray };
3107
- }
3108
- else if (aType === util_1.ZodParsedType.date &&
3109
- bType === util_1.ZodParsedType.date &&
3110
- +a === +b) {
3111
- return { valid: true, data: a };
3112
- }
3113
- else {
3114
- return { valid: false };
3115
- }
3116
- }
3117
- class ZodIntersection extends ZodType {
3118
- _parse(input) {
3119
- const { status, ctx } = this._processInputParams(input);
3120
- const handleParsed = (parsedLeft, parsedRight) => {
3121
- if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
3122
- return parseUtil_1.INVALID;
3123
- }
3124
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
3125
- if (!merged.valid) {
3126
- (0, parseUtil_1.addIssueToContext)(ctx, {
3127
- code: ZodError_1.ZodIssueCode.invalid_intersection_types,
3128
- });
3129
- return parseUtil_1.INVALID;
3130
- }
3131
- if ((0, parseUtil_1.isDirty)(parsedLeft) || (0, parseUtil_1.isDirty)(parsedRight)) {
3132
- status.dirty();
3133
- }
3134
- return { status: status.value, value: merged.data };
3135
- };
3136
- if (ctx.common.async) {
3137
- return Promise.all([
3138
- this._def.left._parseAsync({
3139
- data: ctx.data,
3140
- path: ctx.path,
3141
- parent: ctx,
3142
- }),
3143
- this._def.right._parseAsync({
3144
- data: ctx.data,
3145
- path: ctx.path,
3146
- parent: ctx,
3147
- }),
3148
- ]).then(([left, right]) => handleParsed(left, right));
3149
- }
3150
- else {
3151
- return handleParsed(this._def.left._parseSync({
3152
- data: ctx.data,
3153
- path: ctx.path,
3154
- parent: ctx,
3155
- }), this._def.right._parseSync({
3156
- data: ctx.data,
3157
- path: ctx.path,
3158
- parent: ctx,
3159
- }));
3160
- }
3161
- }
3162
- }
3163
- exports.ZodIntersection = ZodIntersection;
3164
- ZodIntersection.create = (left, right, params) => {
3165
- return new ZodIntersection({
3166
- left: left,
3167
- right: right,
3168
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
3169
- ...processCreateParams(params),
3170
- });
3171
- };
3172
- class ZodTuple extends ZodType {
3173
- _parse(input) {
3174
- const { status, ctx } = this._processInputParams(input);
3175
- if (ctx.parsedType !== util_1.ZodParsedType.array) {
3176
- (0, parseUtil_1.addIssueToContext)(ctx, {
3177
- code: ZodError_1.ZodIssueCode.invalid_type,
3178
- expected: util_1.ZodParsedType.array,
3179
- received: ctx.parsedType,
3180
- });
3181
- return parseUtil_1.INVALID;
3182
- }
3183
- if (ctx.data.length < this._def.items.length) {
3184
- (0, parseUtil_1.addIssueToContext)(ctx, {
3185
- code: ZodError_1.ZodIssueCode.too_small,
3186
- minimum: this._def.items.length,
3187
- inclusive: true,
3188
- exact: false,
3189
- type: "array",
3190
- });
3191
- return parseUtil_1.INVALID;
3192
- }
3193
- const rest = this._def.rest;
3194
- if (!rest && ctx.data.length > this._def.items.length) {
3195
- (0, parseUtil_1.addIssueToContext)(ctx, {
3196
- code: ZodError_1.ZodIssueCode.too_big,
3197
- maximum: this._def.items.length,
3198
- inclusive: true,
3199
- exact: false,
3200
- type: "array",
3201
- });
3202
- status.dirty();
3203
- }
3204
- const items = [...ctx.data]
3205
- .map((item, itemIndex) => {
3206
- const schema = this._def.items[itemIndex] || this._def.rest;
3207
- if (!schema)
3208
- return null;
3209
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3210
- })
3211
- .filter((x) => !!x); // filter nulls
3212
- if (ctx.common.async) {
3213
- return Promise.all(items).then((results) => {
3214
- return parseUtil_1.ParseStatus.mergeArray(status, results);
3215
- });
3216
- }
3217
- else {
3218
- return parseUtil_1.ParseStatus.mergeArray(status, items);
3219
- }
3220
- }
3221
- get items() {
3222
- return this._def.items;
3223
- }
3224
- rest(rest) {
3225
- return new ZodTuple({
3226
- ...this._def,
3227
- rest,
3228
- });
3229
- }
3230
- }
3231
- exports.ZodTuple = ZodTuple;
3232
- ZodTuple.create = (schemas, params) => {
3233
- if (!Array.isArray(schemas)) {
3234
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3235
- }
3236
- return new ZodTuple({
3237
- items: schemas,
3238
- typeName: ZodFirstPartyTypeKind.ZodTuple,
3239
- rest: null,
3240
- ...processCreateParams(params),
3241
- });
3242
- };
3243
- class ZodRecord extends ZodType {
3244
- get keySchema() {
3245
- return this._def.keyType;
3246
- }
3247
- get valueSchema() {
3248
- return this._def.valueType;
3249
- }
3250
- _parse(input) {
3251
- const { status, ctx } = this._processInputParams(input);
3252
- if (ctx.parsedType !== util_1.ZodParsedType.object) {
3253
- (0, parseUtil_1.addIssueToContext)(ctx, {
3254
- code: ZodError_1.ZodIssueCode.invalid_type,
3255
- expected: util_1.ZodParsedType.object,
3256
- received: ctx.parsedType,
3257
- });
3258
- return parseUtil_1.INVALID;
3259
- }
3260
- const pairs = [];
3261
- const keyType = this._def.keyType;
3262
- const valueType = this._def.valueType;
3263
- for (const key in ctx.data) {
3264
- pairs.push({
3265
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3266
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3267
- });
3268
- }
3269
- if (ctx.common.async) {
3270
- return parseUtil_1.ParseStatus.mergeObjectAsync(status, pairs);
3271
- }
3272
- else {
3273
- return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
3274
- }
3275
- }
3276
- get element() {
3277
- return this._def.valueType;
3278
- }
3279
- static create(first, second, third) {
3280
- if (second instanceof ZodType) {
3281
- return new ZodRecord({
3282
- keyType: first,
3283
- valueType: second,
3284
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3285
- ...processCreateParams(third),
3286
- });
3287
- }
3288
- return new ZodRecord({
3289
- keyType: ZodString.create(),
3290
- valueType: first,
3291
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3292
- ...processCreateParams(second),
3293
- });
3294
- }
3295
- }
3296
- exports.ZodRecord = ZodRecord;
3297
- class ZodMap extends ZodType {
3298
- get keySchema() {
3299
- return this._def.keyType;
3300
- }
3301
- get valueSchema() {
3302
- return this._def.valueType;
3303
- }
3304
- _parse(input) {
3305
- const { status, ctx } = this._processInputParams(input);
3306
- if (ctx.parsedType !== util_1.ZodParsedType.map) {
3307
- (0, parseUtil_1.addIssueToContext)(ctx, {
3308
- code: ZodError_1.ZodIssueCode.invalid_type,
3309
- expected: util_1.ZodParsedType.map,
3310
- received: ctx.parsedType,
3311
- });
3312
- return parseUtil_1.INVALID;
3313
- }
3314
- const keyType = this._def.keyType;
3315
- const valueType = this._def.valueType;
3316
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3317
- return {
3318
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3319
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
3320
- };
3321
- });
3322
- if (ctx.common.async) {
3323
- const finalMap = new Map();
3324
- return Promise.resolve().then(async () => {
3325
- for (const pair of pairs) {
3326
- const key = await pair.key;
3327
- const value = await pair.value;
3328
- if (key.status === "aborted" || value.status === "aborted") {
3329
- return parseUtil_1.INVALID;
3330
- }
3331
- if (key.status === "dirty" || value.status === "dirty") {
3332
- status.dirty();
3333
- }
3334
- finalMap.set(key.value, value.value);
3335
- }
3336
- return { status: status.value, value: finalMap };
3337
- });
3338
- }
3339
- else {
3340
- const finalMap = new Map();
3341
- for (const pair of pairs) {
3342
- const key = pair.key;
3343
- const value = pair.value;
3344
- if (key.status === "aborted" || value.status === "aborted") {
3345
- return parseUtil_1.INVALID;
3346
- }
3347
- if (key.status === "dirty" || value.status === "dirty") {
3348
- status.dirty();
3349
- }
3350
- finalMap.set(key.value, value.value);
3351
- }
3352
- return { status: status.value, value: finalMap };
3353
- }
3354
- }
3355
- }
3356
- exports.ZodMap = ZodMap;
3357
- ZodMap.create = (keyType, valueType, params) => {
3358
- return new ZodMap({
3359
- valueType,
3360
- keyType,
3361
- typeName: ZodFirstPartyTypeKind.ZodMap,
3362
- ...processCreateParams(params),
3363
- });
3364
- };
3365
- class ZodSet extends ZodType {
3366
- _parse(input) {
3367
- const { status, ctx } = this._processInputParams(input);
3368
- if (ctx.parsedType !== util_1.ZodParsedType.set) {
3369
- (0, parseUtil_1.addIssueToContext)(ctx, {
3370
- code: ZodError_1.ZodIssueCode.invalid_type,
3371
- expected: util_1.ZodParsedType.set,
3372
- received: ctx.parsedType,
3373
- });
3374
- return parseUtil_1.INVALID;
3375
- }
3376
- const def = this._def;
3377
- if (def.minSize !== null) {
3378
- if (ctx.data.size < def.minSize.value) {
3379
- (0, parseUtil_1.addIssueToContext)(ctx, {
3380
- code: ZodError_1.ZodIssueCode.too_small,
3381
- minimum: def.minSize.value,
3382
- type: "set",
3383
- inclusive: true,
3384
- exact: false,
3385
- message: def.minSize.message,
3386
- });
3387
- status.dirty();
3388
- }
3389
- }
3390
- if (def.maxSize !== null) {
3391
- if (ctx.data.size > def.maxSize.value) {
3392
- (0, parseUtil_1.addIssueToContext)(ctx, {
3393
- code: ZodError_1.ZodIssueCode.too_big,
3394
- maximum: def.maxSize.value,
3395
- type: "set",
3396
- inclusive: true,
3397
- exact: false,
3398
- message: def.maxSize.message,
3399
- });
3400
- status.dirty();
3401
- }
3402
- }
3403
- const valueType = this._def.valueType;
3404
- function finalizeSet(elements) {
3405
- const parsedSet = new Set();
3406
- for (const element of elements) {
3407
- if (element.status === "aborted")
3408
- return parseUtil_1.INVALID;
3409
- if (element.status === "dirty")
3410
- status.dirty();
3411
- parsedSet.add(element.value);
3412
- }
3413
- return { status: status.value, value: parsedSet };
3414
- }
3415
- const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3416
- if (ctx.common.async) {
3417
- return Promise.all(elements).then((elements) => finalizeSet(elements));
3418
- }
3419
- else {
3420
- return finalizeSet(elements);
3421
- }
3422
- }
3423
- min(minSize, message) {
3424
- return new ZodSet({
3425
- ...this._def,
3426
- minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) },
3427
- });
3428
- }
3429
- max(maxSize, message) {
3430
- return new ZodSet({
3431
- ...this._def,
3432
- maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) },
3433
- });
3434
- }
3435
- size(size, message) {
3436
- return this.min(size, message).max(size, message);
3437
- }
3438
- nonempty(message) {
3439
- return this.min(1, message);
3440
- }
3441
- }
3442
- exports.ZodSet = ZodSet;
3443
- ZodSet.create = (valueType, params) => {
3444
- return new ZodSet({
3445
- valueType,
3446
- minSize: null,
3447
- maxSize: null,
3448
- typeName: ZodFirstPartyTypeKind.ZodSet,
3449
- ...processCreateParams(params),
3450
- });
3451
- };
3452
- class ZodFunction extends ZodType {
3453
- constructor() {
3454
- super(...arguments);
3455
- this.validate = this.implement;
3456
- }
3457
- _parse(input) {
3458
- const { ctx } = this._processInputParams(input);
3459
- if (ctx.parsedType !== util_1.ZodParsedType.function) {
3460
- (0, parseUtil_1.addIssueToContext)(ctx, {
3461
- code: ZodError_1.ZodIssueCode.invalid_type,
3462
- expected: util_1.ZodParsedType.function,
3463
- received: ctx.parsedType,
3464
- });
3465
- return parseUtil_1.INVALID;
3466
- }
3467
- function makeArgsIssue(args, error) {
3468
- return (0, parseUtil_1.makeIssue)({
3469
- data: args,
3470
- path: ctx.path,
3471
- errorMaps: [
3472
- ctx.common.contextualErrorMap,
3473
- ctx.schemaErrorMap,
3474
- (0, errors_1.getErrorMap)(),
3475
- errors_1.defaultErrorMap,
3476
- ].filter((x) => !!x),
3477
- issueData: {
3478
- code: ZodError_1.ZodIssueCode.invalid_arguments,
3479
- argumentsError: error,
3480
- },
3481
- });
3482
- }
3483
- function makeReturnsIssue(returns, error) {
3484
- return (0, parseUtil_1.makeIssue)({
3485
- data: returns,
3486
- path: ctx.path,
3487
- errorMaps: [
3488
- ctx.common.contextualErrorMap,
3489
- ctx.schemaErrorMap,
3490
- (0, errors_1.getErrorMap)(),
3491
- errors_1.defaultErrorMap,
3492
- ].filter((x) => !!x),
3493
- issueData: {
3494
- code: ZodError_1.ZodIssueCode.invalid_return_type,
3495
- returnTypeError: error,
3496
- },
3497
- });
3498
- }
3499
- const params = { errorMap: ctx.common.contextualErrorMap };
3500
- const fn = ctx.data;
3501
- if (this._def.returns instanceof ZodPromise) {
3502
- // Would love a way to avoid disabling this rule, but we need
3503
- // an alias (using an arrow function was what caused 2651).
3504
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3505
- const me = this;
3506
- return (0, parseUtil_1.OK)(async function (...args) {
3507
- const error = new ZodError_1.ZodError([]);
3508
- const parsedArgs = await me._def.args
3509
- .parseAsync(args, params)
3510
- .catch((e) => {
3511
- error.addIssue(makeArgsIssue(args, e));
3512
- throw error;
3513
- });
3514
- const result = await Reflect.apply(fn, this, parsedArgs);
3515
- const parsedReturns = await me._def.returns._def.type
3516
- .parseAsync(result, params)
3517
- .catch((e) => {
3518
- error.addIssue(makeReturnsIssue(result, e));
3519
- throw error;
3520
- });
3521
- return parsedReturns;
3522
- });
3523
- }
3524
- else {
3525
- // Would love a way to avoid disabling this rule, but we need
3526
- // an alias (using an arrow function was what caused 2651).
3527
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3528
- const me = this;
3529
- return (0, parseUtil_1.OK)(function (...args) {
3530
- const parsedArgs = me._def.args.safeParse(args, params);
3531
- if (!parsedArgs.success) {
3532
- throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
3533
- }
3534
- const result = Reflect.apply(fn, this, parsedArgs.data);
3535
- const parsedReturns = me._def.returns.safeParse(result, params);
3536
- if (!parsedReturns.success) {
3537
- throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3538
- }
3539
- return parsedReturns.data;
3540
- });
3541
- }
3542
- }
3543
- parameters() {
3544
- return this._def.args;
3545
- }
3546
- returnType() {
3547
- return this._def.returns;
3548
- }
3549
- args(...items) {
3550
- return new ZodFunction({
3551
- ...this._def,
3552
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
3553
- });
3554
- }
3555
- returns(returnType) {
3556
- return new ZodFunction({
3557
- ...this._def,
3558
- returns: returnType,
3559
- });
3560
- }
3561
- implement(func) {
3562
- const validatedFunc = this.parse(func);
3563
- return validatedFunc;
3564
- }
3565
- strictImplement(func) {
3566
- const validatedFunc = this.parse(func);
3567
- return validatedFunc;
3568
- }
3569
- static create(args, returns, params) {
3570
- return new ZodFunction({
3571
- args: (args
3572
- ? args
3573
- : ZodTuple.create([]).rest(ZodUnknown.create())),
3574
- returns: returns || ZodUnknown.create(),
3575
- typeName: ZodFirstPartyTypeKind.ZodFunction,
3576
- ...processCreateParams(params),
3577
- });
3578
- }
3579
- }
3580
- exports.ZodFunction = ZodFunction;
3581
- class ZodLazy extends ZodType {
3582
- get schema() {
3583
- return this._def.getter();
3584
- }
3585
- _parse(input) {
3586
- const { ctx } = this._processInputParams(input);
3587
- const lazySchema = this._def.getter();
3588
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3589
- }
3590
- }
3591
- exports.ZodLazy = ZodLazy;
3592
- ZodLazy.create = (getter, params) => {
3593
- return new ZodLazy({
3594
- getter: getter,
3595
- typeName: ZodFirstPartyTypeKind.ZodLazy,
3596
- ...processCreateParams(params),
3597
- });
3598
- };
3599
- class ZodLiteral extends ZodType {
3600
- _parse(input) {
3601
- if (input.data !== this._def.value) {
3602
- const ctx = this._getOrReturnCtx(input);
3603
- (0, parseUtil_1.addIssueToContext)(ctx, {
3604
- received: ctx.data,
3605
- code: ZodError_1.ZodIssueCode.invalid_literal,
3606
- expected: this._def.value,
3607
- });
3608
- return parseUtil_1.INVALID;
3609
- }
3610
- return { status: "valid", value: input.data };
3611
- }
3612
- get value() {
3613
- return this._def.value;
3614
- }
3615
- }
3616
- exports.ZodLiteral = ZodLiteral;
3617
- ZodLiteral.create = (value, params) => {
3618
- return new ZodLiteral({
3619
- value: value,
3620
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
3621
- ...processCreateParams(params),
3622
- });
3623
- };
3624
- function createZodEnum(values, params) {
3625
- return new ZodEnum({
3626
- values,
3627
- typeName: ZodFirstPartyTypeKind.ZodEnum,
3628
- ...processCreateParams(params),
3629
- });
3630
- }
3631
- class ZodEnum extends ZodType {
3632
- _parse(input) {
3633
- if (typeof input.data !== "string") {
3634
- const ctx = this._getOrReturnCtx(input);
3635
- const expectedValues = this._def.values;
3636
- (0, parseUtil_1.addIssueToContext)(ctx, {
3637
- expected: util_1.util.joinValues(expectedValues),
3638
- received: ctx.parsedType,
3639
- code: ZodError_1.ZodIssueCode.invalid_type,
3640
- });
3641
- return parseUtil_1.INVALID;
3642
- }
3643
- if (this._def.values.indexOf(input.data) === -1) {
3644
- const ctx = this._getOrReturnCtx(input);
3645
- const expectedValues = this._def.values;
3646
- (0, parseUtil_1.addIssueToContext)(ctx, {
3647
- received: ctx.data,
3648
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
3649
- options: expectedValues,
3650
- });
3651
- return parseUtil_1.INVALID;
3652
- }
3653
- return (0, parseUtil_1.OK)(input.data);
3654
- }
3655
- get options() {
3656
- return this._def.values;
3657
- }
3658
- get enum() {
3659
- const enumValues = {};
3660
- for (const val of this._def.values) {
3661
- enumValues[val] = val;
3662
- }
3663
- return enumValues;
3664
- }
3665
- get Values() {
3666
- const enumValues = {};
3667
- for (const val of this._def.values) {
3668
- enumValues[val] = val;
3669
- }
3670
- return enumValues;
3671
- }
3672
- get Enum() {
3673
- const enumValues = {};
3674
- for (const val of this._def.values) {
3675
- enumValues[val] = val;
3676
- }
3677
- return enumValues;
3678
- }
3679
- extract(values) {
3680
- return ZodEnum.create(values);
3681
- }
3682
- exclude(values) {
3683
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
3684
- }
3685
- }
3686
- exports.ZodEnum = ZodEnum;
3687
- ZodEnum.create = createZodEnum;
3688
- class ZodNativeEnum extends ZodType {
3689
- _parse(input) {
3690
- const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
3691
- const ctx = this._getOrReturnCtx(input);
3692
- if (ctx.parsedType !== util_1.ZodParsedType.string &&
3693
- ctx.parsedType !== util_1.ZodParsedType.number) {
3694
- const expectedValues = util_1.util.objectValues(nativeEnumValues);
3695
- (0, parseUtil_1.addIssueToContext)(ctx, {
3696
- expected: util_1.util.joinValues(expectedValues),
3697
- received: ctx.parsedType,
3698
- code: ZodError_1.ZodIssueCode.invalid_type,
3699
- });
3700
- return parseUtil_1.INVALID;
3701
- }
3702
- if (nativeEnumValues.indexOf(input.data) === -1) {
3703
- const expectedValues = util_1.util.objectValues(nativeEnumValues);
3704
- (0, parseUtil_1.addIssueToContext)(ctx, {
3705
- received: ctx.data,
3706
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
3707
- options: expectedValues,
3708
- });
3709
- return parseUtil_1.INVALID;
3710
- }
3711
- return (0, parseUtil_1.OK)(input.data);
3712
- }
3713
- get enum() {
3714
- return this._def.values;
3715
- }
3716
- }
3717
- exports.ZodNativeEnum = ZodNativeEnum;
3718
- ZodNativeEnum.create = (values, params) => {
3719
- return new ZodNativeEnum({
3720
- values: values,
3721
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3722
- ...processCreateParams(params),
3723
- });
3724
- };
3725
- class ZodPromise extends ZodType {
3726
- unwrap() {
3727
- return this._def.type;
3728
- }
3729
- _parse(input) {
3730
- const { ctx } = this._processInputParams(input);
3731
- if (ctx.parsedType !== util_1.ZodParsedType.promise &&
3732
- ctx.common.async === false) {
3733
- (0, parseUtil_1.addIssueToContext)(ctx, {
3734
- code: ZodError_1.ZodIssueCode.invalid_type,
3735
- expected: util_1.ZodParsedType.promise,
3736
- received: ctx.parsedType,
3737
- });
3738
- return parseUtil_1.INVALID;
3739
- }
3740
- const promisified = ctx.parsedType === util_1.ZodParsedType.promise
3741
- ? ctx.data
3742
- : Promise.resolve(ctx.data);
3743
- return (0, parseUtil_1.OK)(promisified.then((data) => {
3744
- return this._def.type.parseAsync(data, {
3745
- path: ctx.path,
3746
- errorMap: ctx.common.contextualErrorMap,
3747
- });
3748
- }));
3749
- }
3750
- }
3751
- exports.ZodPromise = ZodPromise;
3752
- ZodPromise.create = (schema, params) => {
3753
- return new ZodPromise({
3754
- type: schema,
3755
- typeName: ZodFirstPartyTypeKind.ZodPromise,
3756
- ...processCreateParams(params),
3757
- });
3758
- };
3759
- class ZodEffects extends ZodType {
3760
- innerType() {
3761
- return this._def.schema;
3762
- }
3763
- sourceType() {
3764
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
3765
- ? this._def.schema.sourceType()
3766
- : this._def.schema;
3767
- }
3768
- _parse(input) {
3769
- const { status, ctx } = this._processInputParams(input);
3770
- const effect = this._def.effect || null;
3771
- const checkCtx = {
3772
- addIssue: (arg) => {
3773
- (0, parseUtil_1.addIssueToContext)(ctx, arg);
3774
- if (arg.fatal) {
3775
- status.abort();
3776
- }
3777
- else {
3778
- status.dirty();
3779
- }
3780
- },
3781
- get path() {
3782
- return ctx.path;
3783
- },
3784
- };
3785
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3786
- if (effect.type === "preprocess") {
3787
- const processed = effect.transform(ctx.data, checkCtx);
3788
- if (ctx.common.issues.length) {
3789
- return {
3790
- status: "dirty",
3791
- value: ctx.data,
3792
- };
3793
- }
3794
- if (ctx.common.async) {
3795
- return Promise.resolve(processed).then((processed) => {
3796
- return this._def.schema._parseAsync({
3797
- data: processed,
3798
- path: ctx.path,
3799
- parent: ctx,
3800
- });
3801
- });
3802
- }
3803
- else {
3804
- return this._def.schema._parseSync({
3805
- data: processed,
3806
- path: ctx.path,
3807
- parent: ctx,
3808
- });
3809
- }
3810
- }
3811
- if (effect.type === "refinement") {
3812
- const executeRefinement = (acc
3813
- // effect: RefinementEffect<any>
3814
- ) => {
3815
- const result = effect.refinement(acc, checkCtx);
3816
- if (ctx.common.async) {
3817
- return Promise.resolve(result);
3818
- }
3819
- if (result instanceof Promise) {
3820
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3821
- }
3822
- return acc;
3823
- };
3824
- if (ctx.common.async === false) {
3825
- const inner = this._def.schema._parseSync({
3826
- data: ctx.data,
3827
- path: ctx.path,
3828
- parent: ctx,
3829
- });
3830
- if (inner.status === "aborted")
3831
- return parseUtil_1.INVALID;
3832
- if (inner.status === "dirty")
3833
- status.dirty();
3834
- // return value is ignored
3835
- executeRefinement(inner.value);
3836
- return { status: status.value, value: inner.value };
3837
- }
3838
- else {
3839
- return this._def.schema
3840
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3841
- .then((inner) => {
3842
- if (inner.status === "aborted")
3843
- return parseUtil_1.INVALID;
3844
- if (inner.status === "dirty")
3845
- status.dirty();
3846
- return executeRefinement(inner.value).then(() => {
3847
- return { status: status.value, value: inner.value };
3848
- });
3849
- });
3850
- }
3851
- }
3852
- if (effect.type === "transform") {
3853
- if (ctx.common.async === false) {
3854
- const base = this._def.schema._parseSync({
3855
- data: ctx.data,
3856
- path: ctx.path,
3857
- parent: ctx,
3858
- });
3859
- if (!(0, parseUtil_1.isValid)(base))
3860
- return base;
3861
- const result = effect.transform(base.value, checkCtx);
3862
- if (result instanceof Promise) {
3863
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3864
- }
3865
- return { status: status.value, value: result };
3866
- }
3867
- else {
3868
- return this._def.schema
3869
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3870
- .then((base) => {
3871
- if (!(0, parseUtil_1.isValid)(base))
3872
- return base;
3873
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3874
- });
3875
- }
3876
- }
3877
- util_1.util.assertNever(effect);
3878
- }
3879
- }
3880
- exports.ZodEffects = ZodEffects;
3881
- exports.ZodTransformer = ZodEffects;
3882
- ZodEffects.create = (schema, effect, params) => {
3883
- return new ZodEffects({
3884
- schema,
3885
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3886
- effect,
3887
- ...processCreateParams(params),
3888
- });
3889
- };
3890
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3891
- return new ZodEffects({
3892
- schema,
3893
- effect: { type: "preprocess", transform: preprocess },
3894
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3895
- ...processCreateParams(params),
3896
- });
3897
- };
3898
- class ZodOptional extends ZodType {
3899
- _parse(input) {
3900
- const parsedType = this._getType(input);
3901
- if (parsedType === util_1.ZodParsedType.undefined) {
3902
- return (0, parseUtil_1.OK)(undefined);
3903
- }
3904
- return this._def.innerType._parse(input);
3905
- }
3906
- unwrap() {
3907
- return this._def.innerType;
3908
- }
3909
- }
3910
- exports.ZodOptional = ZodOptional;
3911
- ZodOptional.create = (type, params) => {
3912
- return new ZodOptional({
3913
- innerType: type,
3914
- typeName: ZodFirstPartyTypeKind.ZodOptional,
3915
- ...processCreateParams(params),
3916
- });
3917
- };
3918
- class ZodNullable extends ZodType {
3919
- _parse(input) {
3920
- const parsedType = this._getType(input);
3921
- if (parsedType === util_1.ZodParsedType.null) {
3922
- return (0, parseUtil_1.OK)(null);
3923
- }
3924
- return this._def.innerType._parse(input);
3925
- }
3926
- unwrap() {
3927
- return this._def.innerType;
3928
- }
3929
- }
3930
- exports.ZodNullable = ZodNullable;
3931
- ZodNullable.create = (type, params) => {
3932
- return new ZodNullable({
3933
- innerType: type,
3934
- typeName: ZodFirstPartyTypeKind.ZodNullable,
3935
- ...processCreateParams(params),
3936
- });
3937
- };
3938
- class ZodDefault extends ZodType {
3939
- _parse(input) {
3940
- const { ctx } = this._processInputParams(input);
3941
- let data = ctx.data;
3942
- if (ctx.parsedType === util_1.ZodParsedType.undefined) {
3943
- data = this._def.defaultValue();
3944
- }
3945
- return this._def.innerType._parse({
3946
- data,
3947
- path: ctx.path,
3948
- parent: ctx,
3949
- });
3950
- }
3951
- removeDefault() {
3952
- return this._def.innerType;
3953
- }
3954
- }
3955
- exports.ZodDefault = ZodDefault;
3956
- ZodDefault.create = (type, params) => {
3957
- return new ZodDefault({
3958
- innerType: type,
3959
- typeName: ZodFirstPartyTypeKind.ZodDefault,
3960
- defaultValue: typeof params.default === "function"
3961
- ? params.default
3962
- : () => params.default,
3963
- ...processCreateParams(params),
3964
- });
3965
- };
3966
- class ZodCatch extends ZodType {
3967
- _parse(input) {
3968
- const { ctx } = this._processInputParams(input);
3969
- // newCtx is used to not collect issues from inner types in ctx
3970
- const newCtx = {
3971
- ...ctx,
3972
- common: {
3973
- ...ctx.common,
3974
- issues: [],
3975
- },
3976
- };
3977
- const result = this._def.innerType._parse({
3978
- data: newCtx.data,
3979
- path: newCtx.path,
3980
- parent: {
3981
- ...newCtx,
3982
- },
3983
- });
3984
- if ((0, parseUtil_1.isAsync)(result)) {
3985
- return result.then((result) => {
3986
- return {
3987
- status: "valid",
3988
- value: result.status === "valid"
3989
- ? result.value
3990
- : this._def.catchValue({
3991
- get error() {
3992
- return new ZodError_1.ZodError(newCtx.common.issues);
3993
- },
3994
- input: newCtx.data,
3995
- }),
3996
- };
3997
- });
3998
- }
3999
- else {
4000
- return {
4001
- status: "valid",
4002
- value: result.status === "valid"
4003
- ? result.value
4004
- : this._def.catchValue({
4005
- get error() {
4006
- return new ZodError_1.ZodError(newCtx.common.issues);
4007
- },
4008
- input: newCtx.data,
4009
- }),
4010
- };
4011
- }
4012
- }
4013
- removeCatch() {
4014
- return this._def.innerType;
4015
- }
4016
- }
4017
- exports.ZodCatch = ZodCatch;
4018
- ZodCatch.create = (type, params) => {
4019
- return new ZodCatch({
4020
- innerType: type,
4021
- typeName: ZodFirstPartyTypeKind.ZodCatch,
4022
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
4023
- ...processCreateParams(params),
4024
- });
4025
- };
4026
- class ZodNaN extends ZodType {
4027
- _parse(input) {
4028
- const parsedType = this._getType(input);
4029
- if (parsedType !== util_1.ZodParsedType.nan) {
4030
- const ctx = this._getOrReturnCtx(input);
4031
- (0, parseUtil_1.addIssueToContext)(ctx, {
4032
- code: ZodError_1.ZodIssueCode.invalid_type,
4033
- expected: util_1.ZodParsedType.nan,
4034
- received: ctx.parsedType,
4035
- });
4036
- return parseUtil_1.INVALID;
4037
- }
4038
- return { status: "valid", value: input.data };
4039
- }
4040
- }
4041
- exports.ZodNaN = ZodNaN;
4042
- ZodNaN.create = (params) => {
4043
- return new ZodNaN({
4044
- typeName: ZodFirstPartyTypeKind.ZodNaN,
4045
- ...processCreateParams(params),
4046
- });
4047
- };
4048
- exports.BRAND = Symbol("zod_brand");
4049
- class ZodBranded extends ZodType {
4050
- _parse(input) {
4051
- const { ctx } = this._processInputParams(input);
4052
- const data = ctx.data;
4053
- return this._def.type._parse({
4054
- data,
4055
- path: ctx.path,
4056
- parent: ctx,
4057
- });
4058
- }
4059
- unwrap() {
4060
- return this._def.type;
4061
- }
4062
- }
4063
- exports.ZodBranded = ZodBranded;
4064
- class ZodPipeline extends ZodType {
4065
- _parse(input) {
4066
- const { status, ctx } = this._processInputParams(input);
4067
- if (ctx.common.async) {
4068
- const handleAsync = async () => {
4069
- const inResult = await this._def.in._parseAsync({
4070
- data: ctx.data,
4071
- path: ctx.path,
4072
- parent: ctx,
4073
- });
4074
- if (inResult.status === "aborted")
4075
- return parseUtil_1.INVALID;
4076
- if (inResult.status === "dirty") {
4077
- status.dirty();
4078
- return (0, parseUtil_1.DIRTY)(inResult.value);
4079
- }
4080
- else {
4081
- return this._def.out._parseAsync({
4082
- data: inResult.value,
4083
- path: ctx.path,
4084
- parent: ctx,
4085
- });
4086
- }
4087
- };
4088
- return handleAsync();
4089
- }
4090
- else {
4091
- const inResult = this._def.in._parseSync({
4092
- data: ctx.data,
4093
- path: ctx.path,
4094
- parent: ctx,
4095
- });
4096
- if (inResult.status === "aborted")
4097
- return parseUtil_1.INVALID;
4098
- if (inResult.status === "dirty") {
4099
- status.dirty();
4100
- return {
4101
- status: "dirty",
4102
- value: inResult.value,
4103
- };
4104
- }
4105
- else {
4106
- return this._def.out._parseSync({
4107
- data: inResult.value,
4108
- path: ctx.path,
4109
- parent: ctx,
4110
- });
4111
- }
4112
- }
4113
- }
4114
- static create(a, b) {
4115
- return new ZodPipeline({
4116
- in: a,
4117
- out: b,
4118
- typeName: ZodFirstPartyTypeKind.ZodPipeline,
4119
- });
4120
- }
4121
- }
4122
- exports.ZodPipeline = ZodPipeline;
4123
- class ZodReadonly extends ZodType {
4124
- _parse(input) {
4125
- const result = this._def.innerType._parse(input);
4126
- if ((0, parseUtil_1.isValid)(result)) {
4127
- result.value = Object.freeze(result.value);
4128
- }
4129
- return result;
4130
- }
4131
- }
4132
- exports.ZodReadonly = ZodReadonly;
4133
- ZodReadonly.create = (type, params) => {
4134
- return new ZodReadonly({
4135
- innerType: type,
4136
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
4137
- ...processCreateParams(params),
4138
- });
4139
- };
4140
- const custom = (check, params = {},
4141
- /**
4142
- * @deprecated
4143
- *
4144
- * Pass `fatal` into the params object instead:
4145
- *
4146
- * ```ts
4147
- * z.string().custom((val) => val.length > 5, { fatal: false })
4148
- * ```
4149
- *
4150
- */
4151
- fatal) => {
4152
- if (check)
4153
- return ZodAny.create().superRefine((data, ctx) => {
4154
- var _a, _b;
4155
- if (!check(data)) {
4156
- const p = typeof params === "function"
4157
- ? params(data)
4158
- : typeof params === "string"
4159
- ? { message: params }
4160
- : params;
4161
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4162
- const p2 = typeof p === "string" ? { message: p } : p;
4163
- ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
4164
- }
4165
- });
4166
- return ZodAny.create();
4167
- };
4168
- exports.custom = custom;
4169
- exports.late = {
4170
- object: ZodObject.lazycreate,
4171
- };
4172
- var ZodFirstPartyTypeKind;
4173
- (function (ZodFirstPartyTypeKind) {
4174
- ZodFirstPartyTypeKind["ZodString"] = "ZodString";
4175
- ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
4176
- ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
4177
- ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
4178
- ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
4179
- ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
4180
- ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
4181
- ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
4182
- ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
4183
- ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
4184
- ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
4185
- ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
4186
- ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
4187
- ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
4188
- ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
4189
- ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
4190
- ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4191
- ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
4192
- ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
4193
- ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
4194
- ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
4195
- ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
4196
- ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
4197
- ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
4198
- ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
4199
- ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
4200
- ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
4201
- ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
4202
- ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
4203
- ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
4204
- ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
4205
- ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
4206
- ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
4207
- ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
4208
- ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
4209
- ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
4210
- })(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
4211
- // requires TS 4.4+
4212
- class Class {
4213
- constructor(..._) { }
4214
- }
4215
- const instanceOfType = (
4216
- // const instanceOfType = <T extends new (...args: any[]) => any>(
4217
- cls, params = {
4218
- message: `Input not instance of ${cls.name}`,
4219
- }) => (0, exports.custom)((data) => data instanceof cls, params);
4220
- exports["instanceof"] = instanceOfType;
4221
- const stringType = ZodString.create;
4222
- exports.string = stringType;
4223
- const numberType = ZodNumber.create;
4224
- exports.number = numberType;
4225
- const nanType = ZodNaN.create;
4226
- exports.nan = nanType;
4227
- const bigIntType = ZodBigInt.create;
4228
- exports.bigint = bigIntType;
4229
- const booleanType = ZodBoolean.create;
4230
- exports.boolean = booleanType;
4231
- const dateType = ZodDate.create;
4232
- exports.date = dateType;
4233
- const symbolType = ZodSymbol.create;
4234
- exports.symbol = symbolType;
4235
- const undefinedType = ZodUndefined.create;
4236
- exports.undefined = undefinedType;
4237
- const nullType = ZodNull.create;
4238
- exports["null"] = nullType;
4239
- const anyType = ZodAny.create;
4240
- exports.any = anyType;
4241
- const unknownType = ZodUnknown.create;
4242
- exports.unknown = unknownType;
4243
- const neverType = ZodNever.create;
4244
- exports.never = neverType;
4245
- const voidType = ZodVoid.create;
4246
- exports["void"] = voidType;
4247
- const arrayType = ZodArray.create;
4248
- exports.array = arrayType;
4249
- const objectType = ZodObject.create;
4250
- exports.object = objectType;
4251
- const strictObjectType = ZodObject.strictCreate;
4252
- exports.strictObject = strictObjectType;
4253
- const unionType = ZodUnion.create;
4254
- exports.union = unionType;
4255
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
4256
- exports.discriminatedUnion = discriminatedUnionType;
4257
- const intersectionType = ZodIntersection.create;
4258
- exports.intersection = intersectionType;
4259
- const tupleType = ZodTuple.create;
4260
- exports.tuple = tupleType;
4261
- const recordType = ZodRecord.create;
4262
- exports.record = recordType;
4263
- const mapType = ZodMap.create;
4264
- exports.map = mapType;
4265
- const setType = ZodSet.create;
4266
- exports.set = setType;
4267
- const functionType = ZodFunction.create;
4268
- exports["function"] = functionType;
4269
- const lazyType = ZodLazy.create;
4270
- exports.lazy = lazyType;
4271
- const literalType = ZodLiteral.create;
4272
- exports.literal = literalType;
4273
- const enumType = ZodEnum.create;
4274
- exports["enum"] = enumType;
4275
- const nativeEnumType = ZodNativeEnum.create;
4276
- exports.nativeEnum = nativeEnumType;
4277
- const promiseType = ZodPromise.create;
4278
- exports.promise = promiseType;
4279
- const effectsType = ZodEffects.create;
4280
- exports.effect = effectsType;
4281
- exports.transformer = effectsType;
4282
- const optionalType = ZodOptional.create;
4283
- exports.optional = optionalType;
4284
- const nullableType = ZodNullable.create;
4285
- exports.nullable = nullableType;
4286
- const preprocessType = ZodEffects.createWithPreprocess;
4287
- exports.preprocess = preprocessType;
4288
- const pipelineType = ZodPipeline.create;
4289
- exports.pipeline = pipelineType;
4290
- const ostring = () => stringType().optional();
4291
- exports.ostring = ostring;
4292
- const onumber = () => numberType().optional();
4293
- exports.onumber = onumber;
4294
- const oboolean = () => booleanType().optional();
4295
- exports.oboolean = oboolean;
4296
- exports.coerce = {
4297
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4298
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4299
- boolean: ((arg) => ZodBoolean.create({
4300
- ...arg,
4301
- coerce: true,
4302
- })),
4303
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4304
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
4305
- };
4306
- exports.NEVER = parseUtil_1.INVALID;
154
+ /***/ 934:
155
+ /***/ ((module) => {
4307
156
 
157
+ module.exports = require("../zod");
4308
158
 
4309
159
  /***/ })
4310
160