zod 3.25.0-canary.20250211T214501 → 4.0.0-beta.0

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