astro-md-editor 0.0.1

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 (87) hide show
  1. package/.output/nitro.json +17 -0
  2. package/.output/public/assets/index-Cc7yKB0o.js +19 -0
  3. package/.output/public/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  4. package/.output/public/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  5. package/.output/public/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  6. package/.output/public/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  7. package/.output/public/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  8. package/.output/public/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  9. package/.output/public/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  10. package/.output/public/assets/main-DDBjVFnt.js +17 -0
  11. package/.output/public/assets/styles-ggfdUHMo.css +1 -0
  12. package/.output/public/favicon.ico +0 -0
  13. package/.output/public/logo192.png +0 -0
  14. package/.output/public/logo512.png +0 -0
  15. package/.output/public/manifest.json +25 -0
  16. package/.output/public/robots.txt +3 -0
  17. package/.output/server/__root-C09LBXMv.mjs +40 -0
  18. package/.output/server/_chunks/ssr-renderer.mjs +21 -0
  19. package/.output/server/_libs/ajv-formats.mjs +330 -0
  20. package/.output/server/_libs/ajv.mjs +5484 -0
  21. package/.output/server/_libs/base-ui__react.mjs +8712 -0
  22. package/.output/server/_libs/base-ui__utils.mjs +980 -0
  23. package/.output/server/_libs/class-variance-authority.mjs +44 -0
  24. package/.output/server/_libs/clsx.mjs +16 -0
  25. package/.output/server/_libs/cookie-es.mjs +58 -0
  26. package/.output/server/_libs/croner.mjs +1 -0
  27. package/.output/server/_libs/crossws.mjs +1 -0
  28. package/.output/server/_libs/date-fns.mjs +1716 -0
  29. package/.output/server/_libs/date-fns__tz.mjs +217 -0
  30. package/.output/server/_libs/extend-shallow.mjs +35 -0
  31. package/.output/server/_libs/fast-deep-equal.mjs +38 -0
  32. package/.output/server/_libs/fast-uri.mjs +725 -0
  33. package/.output/server/_libs/floating-ui__core.mjs +663 -0
  34. package/.output/server/_libs/floating-ui__dom.mjs +624 -0
  35. package/.output/server/_libs/floating-ui__react-dom.mjs +279 -0
  36. package/.output/server/_libs/floating-ui__utils.mjs +322 -0
  37. package/.output/server/_libs/gray-matter.mjs +393 -0
  38. package/.output/server/_libs/h3-v2.mjs +276 -0
  39. package/.output/server/_libs/h3.mjs +400 -0
  40. package/.output/server/_libs/hookable.mjs +1 -0
  41. package/.output/server/_libs/is-extendable.mjs +13 -0
  42. package/.output/server/_libs/isbot.mjs +20 -0
  43. package/.output/server/_libs/js-yaml.mjs +2822 -0
  44. package/.output/server/_libs/json-schema-traverse.mjs +91 -0
  45. package/.output/server/_libs/kind-of.mjs +125 -0
  46. package/.output/server/_libs/lucide-react.mjs +177 -0
  47. package/.output/server/_libs/ohash.mjs +1 -0
  48. package/.output/server/_libs/react-day-picker.mjs +2216 -0
  49. package/.output/server/_libs/react-dom.mjs +10779 -0
  50. package/.output/server/_libs/react-resizable-panels.mjs +2024 -0
  51. package/.output/server/_libs/react.mjs +513 -0
  52. package/.output/server/_libs/reselect.mjs +326 -0
  53. package/.output/server/_libs/rou3.mjs +8 -0
  54. package/.output/server/_libs/section-matter.mjs +112 -0
  55. package/.output/server/_libs/seroval-plugins.mjs +58 -0
  56. package/.output/server/_libs/seroval.mjs +1765 -0
  57. package/.output/server/_libs/srvx.mjs +736 -0
  58. package/.output/server/_libs/strip-bom-string.mjs +16 -0
  59. package/.output/server/_libs/tabbable.mjs +342 -0
  60. package/.output/server/_libs/tailwind-merge.mjs +3175 -0
  61. package/.output/server/_libs/tanstack__history.mjs +217 -0
  62. package/.output/server/_libs/tanstack__react-router.mjs +1464 -0
  63. package/.output/server/_libs/tanstack__react-store.mjs +1 -0
  64. package/.output/server/_libs/tanstack__router-core.mjs +4912 -0
  65. package/.output/server/_libs/tanstack__store.mjs +1 -0
  66. package/.output/server/_libs/tiny-invariant.mjs +12 -0
  67. package/.output/server/_libs/tiny-warning.mjs +5 -0
  68. package/.output/server/_libs/ufo.mjs +54 -0
  69. package/.output/server/_libs/unctx.mjs +1 -0
  70. package/.output/server/_libs/unstorage.mjs +1 -0
  71. package/.output/server/_libs/use-sync-external-store.mjs +139 -0
  72. package/.output/server/_libs/zod.mjs +3634 -0
  73. package/.output/server/_libs/zustand.mjs +43 -0
  74. package/.output/server/_ssr/RightSidebar-RSY9M7XF.mjs +218 -0
  75. package/.output/server/_ssr/collections.server-D6U2tEsT.mjs +120 -0
  76. package/.output/server/_ssr/createServerRpc-29xaFZcb.mjs +12 -0
  77. package/.output/server/_ssr/index-BaqV4cZC.mjs +2083 -0
  78. package/.output/server/_ssr/index-sQBM6rwN.mjs +115 -0
  79. package/.output/server/_ssr/index.mjs +1448 -0
  80. package/.output/server/_ssr/router-D4G1DGr3.mjs +155 -0
  81. package/.output/server/_ssr/start-HYkvq4Ni.mjs +4 -0
  82. package/.output/server/_tanstack-start-manifest_v-CYEHh_qB.mjs +4 -0
  83. package/.output/server/index.mjs +451 -0
  84. package/README.md +118 -0
  85. package/index.mjs +21 -0
  86. package/package.json +86 -0
  87. package/scripts/bootstrap-collections.mjs +1201 -0
@@ -0,0 +1,3634 @@
1
+ var util;
2
+ (function(util2) {
3
+ util2.assertEqual = (_) => {
4
+ };
5
+ function assertIs(_arg) {
6
+ }
7
+ util2.assertIs = assertIs;
8
+ function assertNever(_x) {
9
+ throw new Error();
10
+ }
11
+ util2.assertNever = assertNever;
12
+ util2.arrayToEnum = (items) => {
13
+ const obj = {};
14
+ for (const item of items) {
15
+ obj[item] = item;
16
+ }
17
+ return obj;
18
+ };
19
+ util2.getValidEnumValues = (obj) => {
20
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
21
+ const filtered = {};
22
+ for (const k of validKeys) {
23
+ filtered[k] = obj[k];
24
+ }
25
+ return util2.objectValues(filtered);
26
+ };
27
+ util2.objectValues = (obj) => {
28
+ return util2.objectKeys(obj).map(function(e) {
29
+ return obj[e];
30
+ });
31
+ };
32
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
33
+ const keys = [];
34
+ for (const key in object) {
35
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
36
+ keys.push(key);
37
+ }
38
+ }
39
+ return keys;
40
+ };
41
+ util2.find = (arr, checker) => {
42
+ for (const item of arr) {
43
+ if (checker(item))
44
+ return item;
45
+ }
46
+ return void 0;
47
+ };
48
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
49
+ function joinValues(array, separator = " | ") {
50
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
51
+ }
52
+ util2.joinValues = joinValues;
53
+ util2.jsonStringifyReplacer = (_, value) => {
54
+ if (typeof value === "bigint") {
55
+ return value.toString();
56
+ }
57
+ return value;
58
+ };
59
+ })(util || (util = {}));
60
+ var objectUtil;
61
+ (function(objectUtil2) {
62
+ objectUtil2.mergeShapes = (first, second) => {
63
+ return {
64
+ ...first,
65
+ ...second
66
+ // second overwrites first
67
+ };
68
+ };
69
+ })(objectUtil || (objectUtil = {}));
70
+ const ZodParsedType = util.arrayToEnum([
71
+ "string",
72
+ "nan",
73
+ "number",
74
+ "integer",
75
+ "float",
76
+ "boolean",
77
+ "date",
78
+ "bigint",
79
+ "symbol",
80
+ "function",
81
+ "undefined",
82
+ "null",
83
+ "array",
84
+ "object",
85
+ "unknown",
86
+ "promise",
87
+ "void",
88
+ "never",
89
+ "map",
90
+ "set"
91
+ ]);
92
+ const getParsedType = (data) => {
93
+ const t = typeof data;
94
+ switch (t) {
95
+ case "undefined":
96
+ return ZodParsedType.undefined;
97
+ case "string":
98
+ return ZodParsedType.string;
99
+ case "number":
100
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
101
+ case "boolean":
102
+ return ZodParsedType.boolean;
103
+ case "function":
104
+ return ZodParsedType.function;
105
+ case "bigint":
106
+ return ZodParsedType.bigint;
107
+ case "symbol":
108
+ return ZodParsedType.symbol;
109
+ case "object":
110
+ if (Array.isArray(data)) {
111
+ return ZodParsedType.array;
112
+ }
113
+ if (data === null) {
114
+ return ZodParsedType.null;
115
+ }
116
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
117
+ return ZodParsedType.promise;
118
+ }
119
+ if (typeof Map !== "undefined" && data instanceof Map) {
120
+ return ZodParsedType.map;
121
+ }
122
+ if (typeof Set !== "undefined" && data instanceof Set) {
123
+ return ZodParsedType.set;
124
+ }
125
+ if (typeof Date !== "undefined" && data instanceof Date) {
126
+ return ZodParsedType.date;
127
+ }
128
+ return ZodParsedType.object;
129
+ default:
130
+ return ZodParsedType.unknown;
131
+ }
132
+ };
133
+ const ZodIssueCode = util.arrayToEnum([
134
+ "invalid_type",
135
+ "invalid_literal",
136
+ "custom",
137
+ "invalid_union",
138
+ "invalid_union_discriminator",
139
+ "invalid_enum_value",
140
+ "unrecognized_keys",
141
+ "invalid_arguments",
142
+ "invalid_return_type",
143
+ "invalid_date",
144
+ "invalid_string",
145
+ "too_small",
146
+ "too_big",
147
+ "invalid_intersection_types",
148
+ "not_multiple_of",
149
+ "not_finite"
150
+ ]);
151
+ class ZodError extends Error {
152
+ get errors() {
153
+ return this.issues;
154
+ }
155
+ constructor(issues) {
156
+ super();
157
+ this.issues = [];
158
+ this.addIssue = (sub) => {
159
+ this.issues = [...this.issues, sub];
160
+ };
161
+ this.addIssues = (subs = []) => {
162
+ this.issues = [...this.issues, ...subs];
163
+ };
164
+ const actualProto = new.target.prototype;
165
+ if (Object.setPrototypeOf) {
166
+ Object.setPrototypeOf(this, actualProto);
167
+ } else {
168
+ this.__proto__ = actualProto;
169
+ }
170
+ this.name = "ZodError";
171
+ this.issues = issues;
172
+ }
173
+ format(_mapper) {
174
+ const mapper = _mapper || function(issue) {
175
+ return issue.message;
176
+ };
177
+ const fieldErrors = { _errors: [] };
178
+ const processError = (error) => {
179
+ for (const issue of error.issues) {
180
+ if (issue.code === "invalid_union") {
181
+ issue.unionErrors.map(processError);
182
+ } else if (issue.code === "invalid_return_type") {
183
+ processError(issue.returnTypeError);
184
+ } else if (issue.code === "invalid_arguments") {
185
+ processError(issue.argumentsError);
186
+ } else if (issue.path.length === 0) {
187
+ fieldErrors._errors.push(mapper(issue));
188
+ } else {
189
+ let curr = fieldErrors;
190
+ let i = 0;
191
+ while (i < issue.path.length) {
192
+ const el = issue.path[i];
193
+ const terminal = i === issue.path.length - 1;
194
+ if (!terminal) {
195
+ curr[el] = curr[el] || { _errors: [] };
196
+ } else {
197
+ curr[el] = curr[el] || { _errors: [] };
198
+ curr[el]._errors.push(mapper(issue));
199
+ }
200
+ curr = curr[el];
201
+ i++;
202
+ }
203
+ }
204
+ }
205
+ };
206
+ processError(this);
207
+ return fieldErrors;
208
+ }
209
+ static assert(value) {
210
+ if (!(value instanceof ZodError)) {
211
+ throw new Error(`Not a ZodError: ${value}`);
212
+ }
213
+ }
214
+ toString() {
215
+ return this.message;
216
+ }
217
+ get message() {
218
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
219
+ }
220
+ get isEmpty() {
221
+ return this.issues.length === 0;
222
+ }
223
+ flatten(mapper = (issue) => issue.message) {
224
+ const fieldErrors = {};
225
+ const formErrors = [];
226
+ for (const sub of this.issues) {
227
+ if (sub.path.length > 0) {
228
+ const firstEl = sub.path[0];
229
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
230
+ fieldErrors[firstEl].push(mapper(sub));
231
+ } else {
232
+ formErrors.push(mapper(sub));
233
+ }
234
+ }
235
+ return { formErrors, fieldErrors };
236
+ }
237
+ get formErrors() {
238
+ return this.flatten();
239
+ }
240
+ }
241
+ ZodError.create = (issues) => {
242
+ const error = new ZodError(issues);
243
+ return error;
244
+ };
245
+ const errorMap = (issue, _ctx) => {
246
+ let message;
247
+ switch (issue.code) {
248
+ case ZodIssueCode.invalid_type:
249
+ if (issue.received === ZodParsedType.undefined) {
250
+ message = "Required";
251
+ } else {
252
+ message = `Expected ${issue.expected}, received ${issue.received}`;
253
+ }
254
+ break;
255
+ case ZodIssueCode.invalid_literal:
256
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
257
+ break;
258
+ case ZodIssueCode.unrecognized_keys:
259
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
260
+ break;
261
+ case ZodIssueCode.invalid_union:
262
+ message = `Invalid input`;
263
+ break;
264
+ case ZodIssueCode.invalid_union_discriminator:
265
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
266
+ break;
267
+ case ZodIssueCode.invalid_enum_value:
268
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
269
+ break;
270
+ case ZodIssueCode.invalid_arguments:
271
+ message = `Invalid function arguments`;
272
+ break;
273
+ case ZodIssueCode.invalid_return_type:
274
+ message = `Invalid function return type`;
275
+ break;
276
+ case ZodIssueCode.invalid_date:
277
+ message = `Invalid date`;
278
+ break;
279
+ case ZodIssueCode.invalid_string:
280
+ if (typeof issue.validation === "object") {
281
+ if ("includes" in issue.validation) {
282
+ message = `Invalid input: must include "${issue.validation.includes}"`;
283
+ if (typeof issue.validation.position === "number") {
284
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
285
+ }
286
+ } else if ("startsWith" in issue.validation) {
287
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
288
+ } else if ("endsWith" in issue.validation) {
289
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
290
+ } else {
291
+ util.assertNever(issue.validation);
292
+ }
293
+ } else if (issue.validation !== "regex") {
294
+ message = `Invalid ${issue.validation}`;
295
+ } else {
296
+ message = "Invalid";
297
+ }
298
+ break;
299
+ case ZodIssueCode.too_small:
300
+ if (issue.type === "array")
301
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
302
+ else if (issue.type === "string")
303
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
304
+ else if (issue.type === "number")
305
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
306
+ else if (issue.type === "bigint")
307
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
308
+ else if (issue.type === "date")
309
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
310
+ else
311
+ message = "Invalid input";
312
+ break;
313
+ case ZodIssueCode.too_big:
314
+ if (issue.type === "array")
315
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
316
+ else if (issue.type === "string")
317
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
318
+ else if (issue.type === "number")
319
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
320
+ else if (issue.type === "bigint")
321
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
322
+ else if (issue.type === "date")
323
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
324
+ else
325
+ message = "Invalid input";
326
+ break;
327
+ case ZodIssueCode.custom:
328
+ message = `Invalid input`;
329
+ break;
330
+ case ZodIssueCode.invalid_intersection_types:
331
+ message = `Intersection results could not be merged`;
332
+ break;
333
+ case ZodIssueCode.not_multiple_of:
334
+ message = `Number must be a multiple of ${issue.multipleOf}`;
335
+ break;
336
+ case ZodIssueCode.not_finite:
337
+ message = "Number must be finite";
338
+ break;
339
+ default:
340
+ message = _ctx.defaultError;
341
+ util.assertNever(issue);
342
+ }
343
+ return { message };
344
+ };
345
+ let overrideErrorMap = errorMap;
346
+ function getErrorMap() {
347
+ return overrideErrorMap;
348
+ }
349
+ const makeIssue = (params) => {
350
+ const { data, path, errorMaps, issueData } = params;
351
+ const fullPath = [...path, ...issueData.path || []];
352
+ const fullIssue = {
353
+ ...issueData,
354
+ path: fullPath
355
+ };
356
+ if (issueData.message !== void 0) {
357
+ return {
358
+ ...issueData,
359
+ path: fullPath,
360
+ message: issueData.message
361
+ };
362
+ }
363
+ let errorMessage = "";
364
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
365
+ for (const map of maps) {
366
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
367
+ }
368
+ return {
369
+ ...issueData,
370
+ path: fullPath,
371
+ message: errorMessage
372
+ };
373
+ };
374
+ function addIssueToContext(ctx, issueData) {
375
+ const overrideMap = getErrorMap();
376
+ const issue = makeIssue({
377
+ issueData,
378
+ data: ctx.data,
379
+ path: ctx.path,
380
+ errorMaps: [
381
+ ctx.common.contextualErrorMap,
382
+ // contextual error map is first priority
383
+ ctx.schemaErrorMap,
384
+ // then schema-bound map if available
385
+ overrideMap,
386
+ // then global override map
387
+ overrideMap === errorMap ? void 0 : errorMap
388
+ // then global default map
389
+ ].filter((x) => !!x)
390
+ });
391
+ ctx.common.issues.push(issue);
392
+ }
393
+ class ParseStatus {
394
+ constructor() {
395
+ this.value = "valid";
396
+ }
397
+ dirty() {
398
+ if (this.value === "valid")
399
+ this.value = "dirty";
400
+ }
401
+ abort() {
402
+ if (this.value !== "aborted")
403
+ this.value = "aborted";
404
+ }
405
+ static mergeArray(status, results) {
406
+ const arrayValue = [];
407
+ for (const s of results) {
408
+ if (s.status === "aborted")
409
+ return INVALID;
410
+ if (s.status === "dirty")
411
+ status.dirty();
412
+ arrayValue.push(s.value);
413
+ }
414
+ return { status: status.value, value: arrayValue };
415
+ }
416
+ static async mergeObjectAsync(status, pairs) {
417
+ const syncPairs = [];
418
+ for (const pair of pairs) {
419
+ const key = await pair.key;
420
+ const value = await pair.value;
421
+ syncPairs.push({
422
+ key,
423
+ value
424
+ });
425
+ }
426
+ return ParseStatus.mergeObjectSync(status, syncPairs);
427
+ }
428
+ static mergeObjectSync(status, pairs) {
429
+ const finalObject = {};
430
+ for (const pair of pairs) {
431
+ const { key, value } = pair;
432
+ if (key.status === "aborted")
433
+ return INVALID;
434
+ if (value.status === "aborted")
435
+ return INVALID;
436
+ if (key.status === "dirty")
437
+ status.dirty();
438
+ if (value.status === "dirty")
439
+ status.dirty();
440
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
441
+ finalObject[key.value] = value.value;
442
+ }
443
+ }
444
+ return { status: status.value, value: finalObject };
445
+ }
446
+ }
447
+ const INVALID = Object.freeze({
448
+ status: "aborted"
449
+ });
450
+ const DIRTY = (value) => ({ status: "dirty", value });
451
+ const OK = (value) => ({ status: "valid", value });
452
+ const isAborted = (x) => x.status === "aborted";
453
+ const isDirty = (x) => x.status === "dirty";
454
+ const isValid = (x) => x.status === "valid";
455
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
456
+ var errorUtil;
457
+ (function(errorUtil2) {
458
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
459
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
460
+ })(errorUtil || (errorUtil = {}));
461
+ class ParseInputLazyPath {
462
+ constructor(parent, value, path, key) {
463
+ this._cachedPath = [];
464
+ this.parent = parent;
465
+ this.data = value;
466
+ this._path = path;
467
+ this._key = key;
468
+ }
469
+ get path() {
470
+ if (!this._cachedPath.length) {
471
+ if (Array.isArray(this._key)) {
472
+ this._cachedPath.push(...this._path, ...this._key);
473
+ } else {
474
+ this._cachedPath.push(...this._path, this._key);
475
+ }
476
+ }
477
+ return this._cachedPath;
478
+ }
479
+ }
480
+ const handleResult = (ctx, result) => {
481
+ if (isValid(result)) {
482
+ return { success: true, data: result.value };
483
+ } else {
484
+ if (!ctx.common.issues.length) {
485
+ throw new Error("Validation failed but no issues detected.");
486
+ }
487
+ return {
488
+ success: false,
489
+ get error() {
490
+ if (this._error)
491
+ return this._error;
492
+ const error = new ZodError(ctx.common.issues);
493
+ this._error = error;
494
+ return this._error;
495
+ }
496
+ };
497
+ }
498
+ };
499
+ function processCreateParams(params) {
500
+ if (!params)
501
+ return {};
502
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
503
+ if (errorMap2 && (invalid_type_error || required_error)) {
504
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
505
+ }
506
+ if (errorMap2)
507
+ return { errorMap: errorMap2, description };
508
+ const customMap = (iss, ctx) => {
509
+ const { message } = params;
510
+ if (iss.code === "invalid_enum_value") {
511
+ return { message: message ?? ctx.defaultError };
512
+ }
513
+ if (typeof ctx.data === "undefined") {
514
+ return { message: message ?? required_error ?? ctx.defaultError };
515
+ }
516
+ if (iss.code !== "invalid_type")
517
+ return { message: ctx.defaultError };
518
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
519
+ };
520
+ return { errorMap: customMap, description };
521
+ }
522
+ class ZodType {
523
+ get description() {
524
+ return this._def.description;
525
+ }
526
+ _getType(input) {
527
+ return getParsedType(input.data);
528
+ }
529
+ _getOrReturnCtx(input, ctx) {
530
+ return ctx || {
531
+ common: input.parent.common,
532
+ data: input.data,
533
+ parsedType: getParsedType(input.data),
534
+ schemaErrorMap: this._def.errorMap,
535
+ path: input.path,
536
+ parent: input.parent
537
+ };
538
+ }
539
+ _processInputParams(input) {
540
+ return {
541
+ status: new ParseStatus(),
542
+ ctx: {
543
+ common: input.parent.common,
544
+ data: input.data,
545
+ parsedType: getParsedType(input.data),
546
+ schemaErrorMap: this._def.errorMap,
547
+ path: input.path,
548
+ parent: input.parent
549
+ }
550
+ };
551
+ }
552
+ _parseSync(input) {
553
+ const result = this._parse(input);
554
+ if (isAsync(result)) {
555
+ throw new Error("Synchronous parse encountered promise.");
556
+ }
557
+ return result;
558
+ }
559
+ _parseAsync(input) {
560
+ const result = this._parse(input);
561
+ return Promise.resolve(result);
562
+ }
563
+ parse(data, params) {
564
+ const result = this.safeParse(data, params);
565
+ if (result.success)
566
+ return result.data;
567
+ throw result.error;
568
+ }
569
+ safeParse(data, params) {
570
+ const ctx = {
571
+ common: {
572
+ issues: [],
573
+ async: params?.async ?? false,
574
+ contextualErrorMap: params?.errorMap
575
+ },
576
+ path: params?.path || [],
577
+ schemaErrorMap: this._def.errorMap,
578
+ parent: null,
579
+ data,
580
+ parsedType: getParsedType(data)
581
+ };
582
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
583
+ return handleResult(ctx, result);
584
+ }
585
+ "~validate"(data) {
586
+ const ctx = {
587
+ common: {
588
+ issues: [],
589
+ async: !!this["~standard"].async
590
+ },
591
+ path: [],
592
+ schemaErrorMap: this._def.errorMap,
593
+ parent: null,
594
+ data,
595
+ parsedType: getParsedType(data)
596
+ };
597
+ if (!this["~standard"].async) {
598
+ try {
599
+ const result = this._parseSync({ data, path: [], parent: ctx });
600
+ return isValid(result) ? {
601
+ value: result.value
602
+ } : {
603
+ issues: ctx.common.issues
604
+ };
605
+ } catch (err) {
606
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
607
+ this["~standard"].async = true;
608
+ }
609
+ ctx.common = {
610
+ issues: [],
611
+ async: true
612
+ };
613
+ }
614
+ }
615
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
616
+ value: result.value
617
+ } : {
618
+ issues: ctx.common.issues
619
+ });
620
+ }
621
+ async parseAsync(data, params) {
622
+ const result = await this.safeParseAsync(data, params);
623
+ if (result.success)
624
+ return result.data;
625
+ throw result.error;
626
+ }
627
+ async safeParseAsync(data, params) {
628
+ const ctx = {
629
+ common: {
630
+ issues: [],
631
+ contextualErrorMap: params?.errorMap,
632
+ async: true
633
+ },
634
+ path: params?.path || [],
635
+ schemaErrorMap: this._def.errorMap,
636
+ parent: null,
637
+ data,
638
+ parsedType: getParsedType(data)
639
+ };
640
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
641
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
642
+ return handleResult(ctx, result);
643
+ }
644
+ refine(check, message) {
645
+ const getIssueProperties = (val) => {
646
+ if (typeof message === "string" || typeof message === "undefined") {
647
+ return { message };
648
+ } else if (typeof message === "function") {
649
+ return message(val);
650
+ } else {
651
+ return message;
652
+ }
653
+ };
654
+ return this._refinement((val, ctx) => {
655
+ const result = check(val);
656
+ const setError = () => ctx.addIssue({
657
+ code: ZodIssueCode.custom,
658
+ ...getIssueProperties(val)
659
+ });
660
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
661
+ return result.then((data) => {
662
+ if (!data) {
663
+ setError();
664
+ return false;
665
+ } else {
666
+ return true;
667
+ }
668
+ });
669
+ }
670
+ if (!result) {
671
+ setError();
672
+ return false;
673
+ } else {
674
+ return true;
675
+ }
676
+ });
677
+ }
678
+ refinement(check, refinementData) {
679
+ return this._refinement((val, ctx) => {
680
+ if (!check(val)) {
681
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
682
+ return false;
683
+ } else {
684
+ return true;
685
+ }
686
+ });
687
+ }
688
+ _refinement(refinement) {
689
+ return new ZodEffects({
690
+ schema: this,
691
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
692
+ effect: { type: "refinement", refinement }
693
+ });
694
+ }
695
+ superRefine(refinement) {
696
+ return this._refinement(refinement);
697
+ }
698
+ constructor(def) {
699
+ this.spa = this.safeParseAsync;
700
+ this._def = def;
701
+ this.parse = this.parse.bind(this);
702
+ this.safeParse = this.safeParse.bind(this);
703
+ this.parseAsync = this.parseAsync.bind(this);
704
+ this.safeParseAsync = this.safeParseAsync.bind(this);
705
+ this.spa = this.spa.bind(this);
706
+ this.refine = this.refine.bind(this);
707
+ this.refinement = this.refinement.bind(this);
708
+ this.superRefine = this.superRefine.bind(this);
709
+ this.optional = this.optional.bind(this);
710
+ this.nullable = this.nullable.bind(this);
711
+ this.nullish = this.nullish.bind(this);
712
+ this.array = this.array.bind(this);
713
+ this.promise = this.promise.bind(this);
714
+ this.or = this.or.bind(this);
715
+ this.and = this.and.bind(this);
716
+ this.transform = this.transform.bind(this);
717
+ this.brand = this.brand.bind(this);
718
+ this.default = this.default.bind(this);
719
+ this.catch = this.catch.bind(this);
720
+ this.describe = this.describe.bind(this);
721
+ this.pipe = this.pipe.bind(this);
722
+ this.readonly = this.readonly.bind(this);
723
+ this.isNullable = this.isNullable.bind(this);
724
+ this.isOptional = this.isOptional.bind(this);
725
+ this["~standard"] = {
726
+ version: 1,
727
+ vendor: "zod",
728
+ validate: (data) => this["~validate"](data)
729
+ };
730
+ }
731
+ optional() {
732
+ return ZodOptional.create(this, this._def);
733
+ }
734
+ nullable() {
735
+ return ZodNullable.create(this, this._def);
736
+ }
737
+ nullish() {
738
+ return this.nullable().optional();
739
+ }
740
+ array() {
741
+ return ZodArray.create(this);
742
+ }
743
+ promise() {
744
+ return ZodPromise.create(this, this._def);
745
+ }
746
+ or(option) {
747
+ return ZodUnion.create([this, option], this._def);
748
+ }
749
+ and(incoming) {
750
+ return ZodIntersection.create(this, incoming, this._def);
751
+ }
752
+ transform(transform) {
753
+ return new ZodEffects({
754
+ ...processCreateParams(this._def),
755
+ schema: this,
756
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
757
+ effect: { type: "transform", transform }
758
+ });
759
+ }
760
+ default(def) {
761
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
762
+ return new ZodDefault({
763
+ ...processCreateParams(this._def),
764
+ innerType: this,
765
+ defaultValue: defaultValueFunc,
766
+ typeName: ZodFirstPartyTypeKind.ZodDefault
767
+ });
768
+ }
769
+ brand() {
770
+ return new ZodBranded({
771
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
772
+ type: this,
773
+ ...processCreateParams(this._def)
774
+ });
775
+ }
776
+ catch(def) {
777
+ const catchValueFunc = typeof def === "function" ? def : () => def;
778
+ return new ZodCatch({
779
+ ...processCreateParams(this._def),
780
+ innerType: this,
781
+ catchValue: catchValueFunc,
782
+ typeName: ZodFirstPartyTypeKind.ZodCatch
783
+ });
784
+ }
785
+ describe(description) {
786
+ const This = this.constructor;
787
+ return new This({
788
+ ...this._def,
789
+ description
790
+ });
791
+ }
792
+ pipe(target) {
793
+ return ZodPipeline.create(this, target);
794
+ }
795
+ readonly() {
796
+ return ZodReadonly.create(this);
797
+ }
798
+ isOptional() {
799
+ return this.safeParse(void 0).success;
800
+ }
801
+ isNullable() {
802
+ return this.safeParse(null).success;
803
+ }
804
+ }
805
+ const cuidRegex = /^c[^\s-]{8,}$/i;
806
+ const cuid2Regex = /^[0-9a-z]+$/;
807
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
808
+ 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;
809
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
810
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
811
+ 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)?)??$/;
812
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
813
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
814
+ let emojiRegex;
815
+ 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])$/;
816
+ 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])$/;
817
+ 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]))$/;
818
+ 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])$/;
819
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
820
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
821
+ 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])))`;
822
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
823
+ function timeRegexSource(args) {
824
+ let secondsRegexSource = `[0-5]\\d`;
825
+ if (args.precision) {
826
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
827
+ } else if (args.precision == null) {
828
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
829
+ }
830
+ const secondsQuantifier = args.precision ? "+" : "?";
831
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
832
+ }
833
+ function timeRegex(args) {
834
+ return new RegExp(`^${timeRegexSource(args)}$`);
835
+ }
836
+ function datetimeRegex(args) {
837
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
838
+ const opts = [];
839
+ opts.push(args.local ? `Z?` : `Z`);
840
+ if (args.offset)
841
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
842
+ regex = `${regex}(${opts.join("|")})`;
843
+ return new RegExp(`^${regex}$`);
844
+ }
845
+ function isValidIP(ip, version) {
846
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
847
+ return true;
848
+ }
849
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
850
+ return true;
851
+ }
852
+ return false;
853
+ }
854
+ function isValidJWT(jwt, alg) {
855
+ if (!jwtRegex.test(jwt))
856
+ return false;
857
+ try {
858
+ const [header] = jwt.split(".");
859
+ if (!header)
860
+ return false;
861
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
862
+ const decoded = JSON.parse(atob(base64));
863
+ if (typeof decoded !== "object" || decoded === null)
864
+ return false;
865
+ if ("typ" in decoded && decoded?.typ !== "JWT")
866
+ return false;
867
+ if (!decoded.alg)
868
+ return false;
869
+ if (alg && decoded.alg !== alg)
870
+ return false;
871
+ return true;
872
+ } catch {
873
+ return false;
874
+ }
875
+ }
876
+ function isValidCidr(ip, version) {
877
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
878
+ return true;
879
+ }
880
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
881
+ return true;
882
+ }
883
+ return false;
884
+ }
885
+ class ZodString extends ZodType {
886
+ _parse(input) {
887
+ if (this._def.coerce) {
888
+ input.data = String(input.data);
889
+ }
890
+ const parsedType = this._getType(input);
891
+ if (parsedType !== ZodParsedType.string) {
892
+ const ctx2 = this._getOrReturnCtx(input);
893
+ addIssueToContext(ctx2, {
894
+ code: ZodIssueCode.invalid_type,
895
+ expected: ZodParsedType.string,
896
+ received: ctx2.parsedType
897
+ });
898
+ return INVALID;
899
+ }
900
+ const status = new ParseStatus();
901
+ let ctx = void 0;
902
+ for (const check of this._def.checks) {
903
+ if (check.kind === "min") {
904
+ if (input.data.length < check.value) {
905
+ ctx = this._getOrReturnCtx(input, ctx);
906
+ addIssueToContext(ctx, {
907
+ code: ZodIssueCode.too_small,
908
+ minimum: check.value,
909
+ type: "string",
910
+ inclusive: true,
911
+ exact: false,
912
+ message: check.message
913
+ });
914
+ status.dirty();
915
+ }
916
+ } else if (check.kind === "max") {
917
+ if (input.data.length > check.value) {
918
+ ctx = this._getOrReturnCtx(input, ctx);
919
+ addIssueToContext(ctx, {
920
+ code: ZodIssueCode.too_big,
921
+ maximum: check.value,
922
+ type: "string",
923
+ inclusive: true,
924
+ exact: false,
925
+ message: check.message
926
+ });
927
+ status.dirty();
928
+ }
929
+ } else if (check.kind === "length") {
930
+ const tooBig = input.data.length > check.value;
931
+ const tooSmall = input.data.length < check.value;
932
+ if (tooBig || tooSmall) {
933
+ ctx = this._getOrReturnCtx(input, ctx);
934
+ if (tooBig) {
935
+ addIssueToContext(ctx, {
936
+ code: ZodIssueCode.too_big,
937
+ maximum: check.value,
938
+ type: "string",
939
+ inclusive: true,
940
+ exact: true,
941
+ message: check.message
942
+ });
943
+ } else if (tooSmall) {
944
+ addIssueToContext(ctx, {
945
+ code: ZodIssueCode.too_small,
946
+ minimum: check.value,
947
+ type: "string",
948
+ inclusive: true,
949
+ exact: true,
950
+ message: check.message
951
+ });
952
+ }
953
+ status.dirty();
954
+ }
955
+ } else if (check.kind === "email") {
956
+ if (!emailRegex.test(input.data)) {
957
+ ctx = this._getOrReturnCtx(input, ctx);
958
+ addIssueToContext(ctx, {
959
+ validation: "email",
960
+ code: ZodIssueCode.invalid_string,
961
+ message: check.message
962
+ });
963
+ status.dirty();
964
+ }
965
+ } else if (check.kind === "emoji") {
966
+ if (!emojiRegex) {
967
+ emojiRegex = new RegExp(_emojiRegex, "u");
968
+ }
969
+ if (!emojiRegex.test(input.data)) {
970
+ ctx = this._getOrReturnCtx(input, ctx);
971
+ addIssueToContext(ctx, {
972
+ validation: "emoji",
973
+ code: ZodIssueCode.invalid_string,
974
+ message: check.message
975
+ });
976
+ status.dirty();
977
+ }
978
+ } else if (check.kind === "uuid") {
979
+ if (!uuidRegex.test(input.data)) {
980
+ ctx = this._getOrReturnCtx(input, ctx);
981
+ addIssueToContext(ctx, {
982
+ validation: "uuid",
983
+ code: ZodIssueCode.invalid_string,
984
+ message: check.message
985
+ });
986
+ status.dirty();
987
+ }
988
+ } else if (check.kind === "nanoid") {
989
+ if (!nanoidRegex.test(input.data)) {
990
+ ctx = this._getOrReturnCtx(input, ctx);
991
+ addIssueToContext(ctx, {
992
+ validation: "nanoid",
993
+ code: ZodIssueCode.invalid_string,
994
+ message: check.message
995
+ });
996
+ status.dirty();
997
+ }
998
+ } else if (check.kind === "cuid") {
999
+ if (!cuidRegex.test(input.data)) {
1000
+ ctx = this._getOrReturnCtx(input, ctx);
1001
+ addIssueToContext(ctx, {
1002
+ validation: "cuid",
1003
+ code: ZodIssueCode.invalid_string,
1004
+ message: check.message
1005
+ });
1006
+ status.dirty();
1007
+ }
1008
+ } else if (check.kind === "cuid2") {
1009
+ if (!cuid2Regex.test(input.data)) {
1010
+ ctx = this._getOrReturnCtx(input, ctx);
1011
+ addIssueToContext(ctx, {
1012
+ validation: "cuid2",
1013
+ code: ZodIssueCode.invalid_string,
1014
+ message: check.message
1015
+ });
1016
+ status.dirty();
1017
+ }
1018
+ } else if (check.kind === "ulid") {
1019
+ if (!ulidRegex.test(input.data)) {
1020
+ ctx = this._getOrReturnCtx(input, ctx);
1021
+ addIssueToContext(ctx, {
1022
+ validation: "ulid",
1023
+ code: ZodIssueCode.invalid_string,
1024
+ message: check.message
1025
+ });
1026
+ status.dirty();
1027
+ }
1028
+ } else if (check.kind === "url") {
1029
+ try {
1030
+ new URL(input.data);
1031
+ } catch {
1032
+ ctx = this._getOrReturnCtx(input, ctx);
1033
+ addIssueToContext(ctx, {
1034
+ validation: "url",
1035
+ code: ZodIssueCode.invalid_string,
1036
+ message: check.message
1037
+ });
1038
+ status.dirty();
1039
+ }
1040
+ } else if (check.kind === "regex") {
1041
+ check.regex.lastIndex = 0;
1042
+ const testResult = check.regex.test(input.data);
1043
+ if (!testResult) {
1044
+ ctx = this._getOrReturnCtx(input, ctx);
1045
+ addIssueToContext(ctx, {
1046
+ validation: "regex",
1047
+ code: ZodIssueCode.invalid_string,
1048
+ message: check.message
1049
+ });
1050
+ status.dirty();
1051
+ }
1052
+ } else if (check.kind === "trim") {
1053
+ input.data = input.data.trim();
1054
+ } else if (check.kind === "includes") {
1055
+ if (!input.data.includes(check.value, check.position)) {
1056
+ ctx = this._getOrReturnCtx(input, ctx);
1057
+ addIssueToContext(ctx, {
1058
+ code: ZodIssueCode.invalid_string,
1059
+ validation: { includes: check.value, position: check.position },
1060
+ message: check.message
1061
+ });
1062
+ status.dirty();
1063
+ }
1064
+ } else if (check.kind === "toLowerCase") {
1065
+ input.data = input.data.toLowerCase();
1066
+ } else if (check.kind === "toUpperCase") {
1067
+ input.data = input.data.toUpperCase();
1068
+ } else if (check.kind === "startsWith") {
1069
+ if (!input.data.startsWith(check.value)) {
1070
+ ctx = this._getOrReturnCtx(input, ctx);
1071
+ addIssueToContext(ctx, {
1072
+ code: ZodIssueCode.invalid_string,
1073
+ validation: { startsWith: check.value },
1074
+ message: check.message
1075
+ });
1076
+ status.dirty();
1077
+ }
1078
+ } else if (check.kind === "endsWith") {
1079
+ if (!input.data.endsWith(check.value)) {
1080
+ ctx = this._getOrReturnCtx(input, ctx);
1081
+ addIssueToContext(ctx, {
1082
+ code: ZodIssueCode.invalid_string,
1083
+ validation: { endsWith: check.value },
1084
+ message: check.message
1085
+ });
1086
+ status.dirty();
1087
+ }
1088
+ } else if (check.kind === "datetime") {
1089
+ const regex = datetimeRegex(check);
1090
+ if (!regex.test(input.data)) {
1091
+ ctx = this._getOrReturnCtx(input, ctx);
1092
+ addIssueToContext(ctx, {
1093
+ code: ZodIssueCode.invalid_string,
1094
+ validation: "datetime",
1095
+ message: check.message
1096
+ });
1097
+ status.dirty();
1098
+ }
1099
+ } else if (check.kind === "date") {
1100
+ const regex = dateRegex;
1101
+ if (!regex.test(input.data)) {
1102
+ ctx = this._getOrReturnCtx(input, ctx);
1103
+ addIssueToContext(ctx, {
1104
+ code: ZodIssueCode.invalid_string,
1105
+ validation: "date",
1106
+ message: check.message
1107
+ });
1108
+ status.dirty();
1109
+ }
1110
+ } else if (check.kind === "time") {
1111
+ const regex = timeRegex(check);
1112
+ if (!regex.test(input.data)) {
1113
+ ctx = this._getOrReturnCtx(input, ctx);
1114
+ addIssueToContext(ctx, {
1115
+ code: ZodIssueCode.invalid_string,
1116
+ validation: "time",
1117
+ message: check.message
1118
+ });
1119
+ status.dirty();
1120
+ }
1121
+ } else if (check.kind === "duration") {
1122
+ if (!durationRegex.test(input.data)) {
1123
+ ctx = this._getOrReturnCtx(input, ctx);
1124
+ addIssueToContext(ctx, {
1125
+ validation: "duration",
1126
+ code: ZodIssueCode.invalid_string,
1127
+ message: check.message
1128
+ });
1129
+ status.dirty();
1130
+ }
1131
+ } else if (check.kind === "ip") {
1132
+ if (!isValidIP(input.data, check.version)) {
1133
+ ctx = this._getOrReturnCtx(input, ctx);
1134
+ addIssueToContext(ctx, {
1135
+ validation: "ip",
1136
+ code: ZodIssueCode.invalid_string,
1137
+ message: check.message
1138
+ });
1139
+ status.dirty();
1140
+ }
1141
+ } else if (check.kind === "jwt") {
1142
+ if (!isValidJWT(input.data, check.alg)) {
1143
+ ctx = this._getOrReturnCtx(input, ctx);
1144
+ addIssueToContext(ctx, {
1145
+ validation: "jwt",
1146
+ code: ZodIssueCode.invalid_string,
1147
+ message: check.message
1148
+ });
1149
+ status.dirty();
1150
+ }
1151
+ } else if (check.kind === "cidr") {
1152
+ if (!isValidCidr(input.data, check.version)) {
1153
+ ctx = this._getOrReturnCtx(input, ctx);
1154
+ addIssueToContext(ctx, {
1155
+ validation: "cidr",
1156
+ code: ZodIssueCode.invalid_string,
1157
+ message: check.message
1158
+ });
1159
+ status.dirty();
1160
+ }
1161
+ } else if (check.kind === "base64") {
1162
+ if (!base64Regex.test(input.data)) {
1163
+ ctx = this._getOrReturnCtx(input, ctx);
1164
+ addIssueToContext(ctx, {
1165
+ validation: "base64",
1166
+ code: ZodIssueCode.invalid_string,
1167
+ message: check.message
1168
+ });
1169
+ status.dirty();
1170
+ }
1171
+ } else if (check.kind === "base64url") {
1172
+ if (!base64urlRegex.test(input.data)) {
1173
+ ctx = this._getOrReturnCtx(input, ctx);
1174
+ addIssueToContext(ctx, {
1175
+ validation: "base64url",
1176
+ code: ZodIssueCode.invalid_string,
1177
+ message: check.message
1178
+ });
1179
+ status.dirty();
1180
+ }
1181
+ } else {
1182
+ util.assertNever(check);
1183
+ }
1184
+ }
1185
+ return { status: status.value, value: input.data };
1186
+ }
1187
+ _regex(regex, validation, message) {
1188
+ return this.refinement((data) => regex.test(data), {
1189
+ validation,
1190
+ code: ZodIssueCode.invalid_string,
1191
+ ...errorUtil.errToObj(message)
1192
+ });
1193
+ }
1194
+ _addCheck(check) {
1195
+ return new ZodString({
1196
+ ...this._def,
1197
+ checks: [...this._def.checks, check]
1198
+ });
1199
+ }
1200
+ email(message) {
1201
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1202
+ }
1203
+ url(message) {
1204
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1205
+ }
1206
+ emoji(message) {
1207
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1208
+ }
1209
+ uuid(message) {
1210
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1211
+ }
1212
+ nanoid(message) {
1213
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1214
+ }
1215
+ cuid(message) {
1216
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1217
+ }
1218
+ cuid2(message) {
1219
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1220
+ }
1221
+ ulid(message) {
1222
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1223
+ }
1224
+ base64(message) {
1225
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1226
+ }
1227
+ base64url(message) {
1228
+ return this._addCheck({
1229
+ kind: "base64url",
1230
+ ...errorUtil.errToObj(message)
1231
+ });
1232
+ }
1233
+ jwt(options) {
1234
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1235
+ }
1236
+ ip(options) {
1237
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1238
+ }
1239
+ cidr(options) {
1240
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1241
+ }
1242
+ datetime(options) {
1243
+ if (typeof options === "string") {
1244
+ return this._addCheck({
1245
+ kind: "datetime",
1246
+ precision: null,
1247
+ offset: false,
1248
+ local: false,
1249
+ message: options
1250
+ });
1251
+ }
1252
+ return this._addCheck({
1253
+ kind: "datetime",
1254
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1255
+ offset: options?.offset ?? false,
1256
+ local: options?.local ?? false,
1257
+ ...errorUtil.errToObj(options?.message)
1258
+ });
1259
+ }
1260
+ date(message) {
1261
+ return this._addCheck({ kind: "date", message });
1262
+ }
1263
+ time(options) {
1264
+ if (typeof options === "string") {
1265
+ return this._addCheck({
1266
+ kind: "time",
1267
+ precision: null,
1268
+ message: options
1269
+ });
1270
+ }
1271
+ return this._addCheck({
1272
+ kind: "time",
1273
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1274
+ ...errorUtil.errToObj(options?.message)
1275
+ });
1276
+ }
1277
+ duration(message) {
1278
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1279
+ }
1280
+ regex(regex, message) {
1281
+ return this._addCheck({
1282
+ kind: "regex",
1283
+ regex,
1284
+ ...errorUtil.errToObj(message)
1285
+ });
1286
+ }
1287
+ includes(value, options) {
1288
+ return this._addCheck({
1289
+ kind: "includes",
1290
+ value,
1291
+ position: options?.position,
1292
+ ...errorUtil.errToObj(options?.message)
1293
+ });
1294
+ }
1295
+ startsWith(value, message) {
1296
+ return this._addCheck({
1297
+ kind: "startsWith",
1298
+ value,
1299
+ ...errorUtil.errToObj(message)
1300
+ });
1301
+ }
1302
+ endsWith(value, message) {
1303
+ return this._addCheck({
1304
+ kind: "endsWith",
1305
+ value,
1306
+ ...errorUtil.errToObj(message)
1307
+ });
1308
+ }
1309
+ min(minLength, message) {
1310
+ return this._addCheck({
1311
+ kind: "min",
1312
+ value: minLength,
1313
+ ...errorUtil.errToObj(message)
1314
+ });
1315
+ }
1316
+ max(maxLength, message) {
1317
+ return this._addCheck({
1318
+ kind: "max",
1319
+ value: maxLength,
1320
+ ...errorUtil.errToObj(message)
1321
+ });
1322
+ }
1323
+ length(len, message) {
1324
+ return this._addCheck({
1325
+ kind: "length",
1326
+ value: len,
1327
+ ...errorUtil.errToObj(message)
1328
+ });
1329
+ }
1330
+ /**
1331
+ * Equivalent to `.min(1)`
1332
+ */
1333
+ nonempty(message) {
1334
+ return this.min(1, errorUtil.errToObj(message));
1335
+ }
1336
+ trim() {
1337
+ return new ZodString({
1338
+ ...this._def,
1339
+ checks: [...this._def.checks, { kind: "trim" }]
1340
+ });
1341
+ }
1342
+ toLowerCase() {
1343
+ return new ZodString({
1344
+ ...this._def,
1345
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1346
+ });
1347
+ }
1348
+ toUpperCase() {
1349
+ return new ZodString({
1350
+ ...this._def,
1351
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1352
+ });
1353
+ }
1354
+ get isDatetime() {
1355
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1356
+ }
1357
+ get isDate() {
1358
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1359
+ }
1360
+ get isTime() {
1361
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1362
+ }
1363
+ get isDuration() {
1364
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1365
+ }
1366
+ get isEmail() {
1367
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1368
+ }
1369
+ get isURL() {
1370
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1371
+ }
1372
+ get isEmoji() {
1373
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1374
+ }
1375
+ get isUUID() {
1376
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1377
+ }
1378
+ get isNANOID() {
1379
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1380
+ }
1381
+ get isCUID() {
1382
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1383
+ }
1384
+ get isCUID2() {
1385
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1386
+ }
1387
+ get isULID() {
1388
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1389
+ }
1390
+ get isIP() {
1391
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1392
+ }
1393
+ get isCIDR() {
1394
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1395
+ }
1396
+ get isBase64() {
1397
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1398
+ }
1399
+ get isBase64url() {
1400
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1401
+ }
1402
+ get minLength() {
1403
+ let min = null;
1404
+ for (const ch of this._def.checks) {
1405
+ if (ch.kind === "min") {
1406
+ if (min === null || ch.value > min)
1407
+ min = ch.value;
1408
+ }
1409
+ }
1410
+ return min;
1411
+ }
1412
+ get maxLength() {
1413
+ let max = null;
1414
+ for (const ch of this._def.checks) {
1415
+ if (ch.kind === "max") {
1416
+ if (max === null || ch.value < max)
1417
+ max = ch.value;
1418
+ }
1419
+ }
1420
+ return max;
1421
+ }
1422
+ }
1423
+ ZodString.create = (params) => {
1424
+ return new ZodString({
1425
+ checks: [],
1426
+ typeName: ZodFirstPartyTypeKind.ZodString,
1427
+ coerce: params?.coerce ?? false,
1428
+ ...processCreateParams(params)
1429
+ });
1430
+ };
1431
+ function floatSafeRemainder(val, step) {
1432
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1433
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1434
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1435
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1436
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1437
+ return valInt % stepInt / 10 ** decCount;
1438
+ }
1439
+ class ZodNumber extends ZodType {
1440
+ constructor() {
1441
+ super(...arguments);
1442
+ this.min = this.gte;
1443
+ this.max = this.lte;
1444
+ this.step = this.multipleOf;
1445
+ }
1446
+ _parse(input) {
1447
+ if (this._def.coerce) {
1448
+ input.data = Number(input.data);
1449
+ }
1450
+ const parsedType = this._getType(input);
1451
+ if (parsedType !== ZodParsedType.number) {
1452
+ const ctx2 = this._getOrReturnCtx(input);
1453
+ addIssueToContext(ctx2, {
1454
+ code: ZodIssueCode.invalid_type,
1455
+ expected: ZodParsedType.number,
1456
+ received: ctx2.parsedType
1457
+ });
1458
+ return INVALID;
1459
+ }
1460
+ let ctx = void 0;
1461
+ const status = new ParseStatus();
1462
+ for (const check of this._def.checks) {
1463
+ if (check.kind === "int") {
1464
+ if (!util.isInteger(input.data)) {
1465
+ ctx = this._getOrReturnCtx(input, ctx);
1466
+ addIssueToContext(ctx, {
1467
+ code: ZodIssueCode.invalid_type,
1468
+ expected: "integer",
1469
+ received: "float",
1470
+ message: check.message
1471
+ });
1472
+ status.dirty();
1473
+ }
1474
+ } else if (check.kind === "min") {
1475
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1476
+ if (tooSmall) {
1477
+ ctx = this._getOrReturnCtx(input, ctx);
1478
+ addIssueToContext(ctx, {
1479
+ code: ZodIssueCode.too_small,
1480
+ minimum: check.value,
1481
+ type: "number",
1482
+ inclusive: check.inclusive,
1483
+ exact: false,
1484
+ message: check.message
1485
+ });
1486
+ status.dirty();
1487
+ }
1488
+ } else if (check.kind === "max") {
1489
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1490
+ if (tooBig) {
1491
+ ctx = this._getOrReturnCtx(input, ctx);
1492
+ addIssueToContext(ctx, {
1493
+ code: ZodIssueCode.too_big,
1494
+ maximum: check.value,
1495
+ type: "number",
1496
+ inclusive: check.inclusive,
1497
+ exact: false,
1498
+ message: check.message
1499
+ });
1500
+ status.dirty();
1501
+ }
1502
+ } else if (check.kind === "multipleOf") {
1503
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1504
+ ctx = this._getOrReturnCtx(input, ctx);
1505
+ addIssueToContext(ctx, {
1506
+ code: ZodIssueCode.not_multiple_of,
1507
+ multipleOf: check.value,
1508
+ message: check.message
1509
+ });
1510
+ status.dirty();
1511
+ }
1512
+ } else if (check.kind === "finite") {
1513
+ if (!Number.isFinite(input.data)) {
1514
+ ctx = this._getOrReturnCtx(input, ctx);
1515
+ addIssueToContext(ctx, {
1516
+ code: ZodIssueCode.not_finite,
1517
+ message: check.message
1518
+ });
1519
+ status.dirty();
1520
+ }
1521
+ } else {
1522
+ util.assertNever(check);
1523
+ }
1524
+ }
1525
+ return { status: status.value, value: input.data };
1526
+ }
1527
+ gte(value, message) {
1528
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1529
+ }
1530
+ gt(value, message) {
1531
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1532
+ }
1533
+ lte(value, message) {
1534
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1535
+ }
1536
+ lt(value, message) {
1537
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1538
+ }
1539
+ setLimit(kind, value, inclusive, message) {
1540
+ return new ZodNumber({
1541
+ ...this._def,
1542
+ checks: [
1543
+ ...this._def.checks,
1544
+ {
1545
+ kind,
1546
+ value,
1547
+ inclusive,
1548
+ message: errorUtil.toString(message)
1549
+ }
1550
+ ]
1551
+ });
1552
+ }
1553
+ _addCheck(check) {
1554
+ return new ZodNumber({
1555
+ ...this._def,
1556
+ checks: [...this._def.checks, check]
1557
+ });
1558
+ }
1559
+ int(message) {
1560
+ return this._addCheck({
1561
+ kind: "int",
1562
+ message: errorUtil.toString(message)
1563
+ });
1564
+ }
1565
+ positive(message) {
1566
+ return this._addCheck({
1567
+ kind: "min",
1568
+ value: 0,
1569
+ inclusive: false,
1570
+ message: errorUtil.toString(message)
1571
+ });
1572
+ }
1573
+ negative(message) {
1574
+ return this._addCheck({
1575
+ kind: "max",
1576
+ value: 0,
1577
+ inclusive: false,
1578
+ message: errorUtil.toString(message)
1579
+ });
1580
+ }
1581
+ nonpositive(message) {
1582
+ return this._addCheck({
1583
+ kind: "max",
1584
+ value: 0,
1585
+ inclusive: true,
1586
+ message: errorUtil.toString(message)
1587
+ });
1588
+ }
1589
+ nonnegative(message) {
1590
+ return this._addCheck({
1591
+ kind: "min",
1592
+ value: 0,
1593
+ inclusive: true,
1594
+ message: errorUtil.toString(message)
1595
+ });
1596
+ }
1597
+ multipleOf(value, message) {
1598
+ return this._addCheck({
1599
+ kind: "multipleOf",
1600
+ value,
1601
+ message: errorUtil.toString(message)
1602
+ });
1603
+ }
1604
+ finite(message) {
1605
+ return this._addCheck({
1606
+ kind: "finite",
1607
+ message: errorUtil.toString(message)
1608
+ });
1609
+ }
1610
+ safe(message) {
1611
+ return this._addCheck({
1612
+ kind: "min",
1613
+ inclusive: true,
1614
+ value: Number.MIN_SAFE_INTEGER,
1615
+ message: errorUtil.toString(message)
1616
+ })._addCheck({
1617
+ kind: "max",
1618
+ inclusive: true,
1619
+ value: Number.MAX_SAFE_INTEGER,
1620
+ message: errorUtil.toString(message)
1621
+ });
1622
+ }
1623
+ get minValue() {
1624
+ let min = null;
1625
+ for (const ch of this._def.checks) {
1626
+ if (ch.kind === "min") {
1627
+ if (min === null || ch.value > min)
1628
+ min = ch.value;
1629
+ }
1630
+ }
1631
+ return min;
1632
+ }
1633
+ get maxValue() {
1634
+ let max = null;
1635
+ for (const ch of this._def.checks) {
1636
+ if (ch.kind === "max") {
1637
+ if (max === null || ch.value < max)
1638
+ max = ch.value;
1639
+ }
1640
+ }
1641
+ return max;
1642
+ }
1643
+ get isInt() {
1644
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1645
+ }
1646
+ get isFinite() {
1647
+ let max = null;
1648
+ let min = null;
1649
+ for (const ch of this._def.checks) {
1650
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1651
+ return true;
1652
+ } else if (ch.kind === "min") {
1653
+ if (min === null || ch.value > min)
1654
+ min = ch.value;
1655
+ } else if (ch.kind === "max") {
1656
+ if (max === null || ch.value < max)
1657
+ max = ch.value;
1658
+ }
1659
+ }
1660
+ return Number.isFinite(min) && Number.isFinite(max);
1661
+ }
1662
+ }
1663
+ ZodNumber.create = (params) => {
1664
+ return new ZodNumber({
1665
+ checks: [],
1666
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1667
+ coerce: params?.coerce || false,
1668
+ ...processCreateParams(params)
1669
+ });
1670
+ };
1671
+ class ZodBigInt extends ZodType {
1672
+ constructor() {
1673
+ super(...arguments);
1674
+ this.min = this.gte;
1675
+ this.max = this.lte;
1676
+ }
1677
+ _parse(input) {
1678
+ if (this._def.coerce) {
1679
+ try {
1680
+ input.data = BigInt(input.data);
1681
+ } catch {
1682
+ return this._getInvalidInput(input);
1683
+ }
1684
+ }
1685
+ const parsedType = this._getType(input);
1686
+ if (parsedType !== ZodParsedType.bigint) {
1687
+ return this._getInvalidInput(input);
1688
+ }
1689
+ let ctx = void 0;
1690
+ const status = new ParseStatus();
1691
+ for (const check of this._def.checks) {
1692
+ if (check.kind === "min") {
1693
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1694
+ if (tooSmall) {
1695
+ ctx = this._getOrReturnCtx(input, ctx);
1696
+ addIssueToContext(ctx, {
1697
+ code: ZodIssueCode.too_small,
1698
+ type: "bigint",
1699
+ minimum: check.value,
1700
+ inclusive: check.inclusive,
1701
+ message: check.message
1702
+ });
1703
+ status.dirty();
1704
+ }
1705
+ } else if (check.kind === "max") {
1706
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1707
+ if (tooBig) {
1708
+ ctx = this._getOrReturnCtx(input, ctx);
1709
+ addIssueToContext(ctx, {
1710
+ code: ZodIssueCode.too_big,
1711
+ type: "bigint",
1712
+ maximum: check.value,
1713
+ inclusive: check.inclusive,
1714
+ message: check.message
1715
+ });
1716
+ status.dirty();
1717
+ }
1718
+ } else if (check.kind === "multipleOf") {
1719
+ if (input.data % check.value !== BigInt(0)) {
1720
+ ctx = this._getOrReturnCtx(input, ctx);
1721
+ addIssueToContext(ctx, {
1722
+ code: ZodIssueCode.not_multiple_of,
1723
+ multipleOf: check.value,
1724
+ message: check.message
1725
+ });
1726
+ status.dirty();
1727
+ }
1728
+ } else {
1729
+ util.assertNever(check);
1730
+ }
1731
+ }
1732
+ return { status: status.value, value: input.data };
1733
+ }
1734
+ _getInvalidInput(input) {
1735
+ const ctx = this._getOrReturnCtx(input);
1736
+ addIssueToContext(ctx, {
1737
+ code: ZodIssueCode.invalid_type,
1738
+ expected: ZodParsedType.bigint,
1739
+ received: ctx.parsedType
1740
+ });
1741
+ return INVALID;
1742
+ }
1743
+ gte(value, message) {
1744
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1745
+ }
1746
+ gt(value, message) {
1747
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1748
+ }
1749
+ lte(value, message) {
1750
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1751
+ }
1752
+ lt(value, message) {
1753
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1754
+ }
1755
+ setLimit(kind, value, inclusive, message) {
1756
+ return new ZodBigInt({
1757
+ ...this._def,
1758
+ checks: [
1759
+ ...this._def.checks,
1760
+ {
1761
+ kind,
1762
+ value,
1763
+ inclusive,
1764
+ message: errorUtil.toString(message)
1765
+ }
1766
+ ]
1767
+ });
1768
+ }
1769
+ _addCheck(check) {
1770
+ return new ZodBigInt({
1771
+ ...this._def,
1772
+ checks: [...this._def.checks, check]
1773
+ });
1774
+ }
1775
+ positive(message) {
1776
+ return this._addCheck({
1777
+ kind: "min",
1778
+ value: BigInt(0),
1779
+ inclusive: false,
1780
+ message: errorUtil.toString(message)
1781
+ });
1782
+ }
1783
+ negative(message) {
1784
+ return this._addCheck({
1785
+ kind: "max",
1786
+ value: BigInt(0),
1787
+ inclusive: false,
1788
+ message: errorUtil.toString(message)
1789
+ });
1790
+ }
1791
+ nonpositive(message) {
1792
+ return this._addCheck({
1793
+ kind: "max",
1794
+ value: BigInt(0),
1795
+ inclusive: true,
1796
+ message: errorUtil.toString(message)
1797
+ });
1798
+ }
1799
+ nonnegative(message) {
1800
+ return this._addCheck({
1801
+ kind: "min",
1802
+ value: BigInt(0),
1803
+ inclusive: true,
1804
+ message: errorUtil.toString(message)
1805
+ });
1806
+ }
1807
+ multipleOf(value, message) {
1808
+ return this._addCheck({
1809
+ kind: "multipleOf",
1810
+ value,
1811
+ message: errorUtil.toString(message)
1812
+ });
1813
+ }
1814
+ get minValue() {
1815
+ let min = null;
1816
+ for (const ch of this._def.checks) {
1817
+ if (ch.kind === "min") {
1818
+ if (min === null || ch.value > min)
1819
+ min = ch.value;
1820
+ }
1821
+ }
1822
+ return min;
1823
+ }
1824
+ get maxValue() {
1825
+ let max = null;
1826
+ for (const ch of this._def.checks) {
1827
+ if (ch.kind === "max") {
1828
+ if (max === null || ch.value < max)
1829
+ max = ch.value;
1830
+ }
1831
+ }
1832
+ return max;
1833
+ }
1834
+ }
1835
+ ZodBigInt.create = (params) => {
1836
+ return new ZodBigInt({
1837
+ checks: [],
1838
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1839
+ coerce: params?.coerce ?? false,
1840
+ ...processCreateParams(params)
1841
+ });
1842
+ };
1843
+ class ZodBoolean extends ZodType {
1844
+ _parse(input) {
1845
+ if (this._def.coerce) {
1846
+ input.data = Boolean(input.data);
1847
+ }
1848
+ const parsedType = this._getType(input);
1849
+ if (parsedType !== ZodParsedType.boolean) {
1850
+ const ctx = this._getOrReturnCtx(input);
1851
+ addIssueToContext(ctx, {
1852
+ code: ZodIssueCode.invalid_type,
1853
+ expected: ZodParsedType.boolean,
1854
+ received: ctx.parsedType
1855
+ });
1856
+ return INVALID;
1857
+ }
1858
+ return OK(input.data);
1859
+ }
1860
+ }
1861
+ ZodBoolean.create = (params) => {
1862
+ return new ZodBoolean({
1863
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1864
+ coerce: params?.coerce || false,
1865
+ ...processCreateParams(params)
1866
+ });
1867
+ };
1868
+ class ZodDate extends ZodType {
1869
+ _parse(input) {
1870
+ if (this._def.coerce) {
1871
+ input.data = new Date(input.data);
1872
+ }
1873
+ const parsedType = this._getType(input);
1874
+ if (parsedType !== ZodParsedType.date) {
1875
+ const ctx2 = this._getOrReturnCtx(input);
1876
+ addIssueToContext(ctx2, {
1877
+ code: ZodIssueCode.invalid_type,
1878
+ expected: ZodParsedType.date,
1879
+ received: ctx2.parsedType
1880
+ });
1881
+ return INVALID;
1882
+ }
1883
+ if (Number.isNaN(input.data.getTime())) {
1884
+ const ctx2 = this._getOrReturnCtx(input);
1885
+ addIssueToContext(ctx2, {
1886
+ code: ZodIssueCode.invalid_date
1887
+ });
1888
+ return INVALID;
1889
+ }
1890
+ const status = new ParseStatus();
1891
+ let ctx = void 0;
1892
+ for (const check of this._def.checks) {
1893
+ if (check.kind === "min") {
1894
+ if (input.data.getTime() < check.value) {
1895
+ ctx = this._getOrReturnCtx(input, ctx);
1896
+ addIssueToContext(ctx, {
1897
+ code: ZodIssueCode.too_small,
1898
+ message: check.message,
1899
+ inclusive: true,
1900
+ exact: false,
1901
+ minimum: check.value,
1902
+ type: "date"
1903
+ });
1904
+ status.dirty();
1905
+ }
1906
+ } else if (check.kind === "max") {
1907
+ if (input.data.getTime() > check.value) {
1908
+ ctx = this._getOrReturnCtx(input, ctx);
1909
+ addIssueToContext(ctx, {
1910
+ code: ZodIssueCode.too_big,
1911
+ message: check.message,
1912
+ inclusive: true,
1913
+ exact: false,
1914
+ maximum: check.value,
1915
+ type: "date"
1916
+ });
1917
+ status.dirty();
1918
+ }
1919
+ } else {
1920
+ util.assertNever(check);
1921
+ }
1922
+ }
1923
+ return {
1924
+ status: status.value,
1925
+ value: new Date(input.data.getTime())
1926
+ };
1927
+ }
1928
+ _addCheck(check) {
1929
+ return new ZodDate({
1930
+ ...this._def,
1931
+ checks: [...this._def.checks, check]
1932
+ });
1933
+ }
1934
+ min(minDate, message) {
1935
+ return this._addCheck({
1936
+ kind: "min",
1937
+ value: minDate.getTime(),
1938
+ message: errorUtil.toString(message)
1939
+ });
1940
+ }
1941
+ max(maxDate, message) {
1942
+ return this._addCheck({
1943
+ kind: "max",
1944
+ value: maxDate.getTime(),
1945
+ message: errorUtil.toString(message)
1946
+ });
1947
+ }
1948
+ get minDate() {
1949
+ let min = null;
1950
+ for (const ch of this._def.checks) {
1951
+ if (ch.kind === "min") {
1952
+ if (min === null || ch.value > min)
1953
+ min = ch.value;
1954
+ }
1955
+ }
1956
+ return min != null ? new Date(min) : null;
1957
+ }
1958
+ get maxDate() {
1959
+ let max = null;
1960
+ for (const ch of this._def.checks) {
1961
+ if (ch.kind === "max") {
1962
+ if (max === null || ch.value < max)
1963
+ max = ch.value;
1964
+ }
1965
+ }
1966
+ return max != null ? new Date(max) : null;
1967
+ }
1968
+ }
1969
+ ZodDate.create = (params) => {
1970
+ return new ZodDate({
1971
+ checks: [],
1972
+ coerce: params?.coerce || false,
1973
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1974
+ ...processCreateParams(params)
1975
+ });
1976
+ };
1977
+ class ZodSymbol extends ZodType {
1978
+ _parse(input) {
1979
+ const parsedType = this._getType(input);
1980
+ if (parsedType !== ZodParsedType.symbol) {
1981
+ const ctx = this._getOrReturnCtx(input);
1982
+ addIssueToContext(ctx, {
1983
+ code: ZodIssueCode.invalid_type,
1984
+ expected: ZodParsedType.symbol,
1985
+ received: ctx.parsedType
1986
+ });
1987
+ return INVALID;
1988
+ }
1989
+ return OK(input.data);
1990
+ }
1991
+ }
1992
+ ZodSymbol.create = (params) => {
1993
+ return new ZodSymbol({
1994
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1995
+ ...processCreateParams(params)
1996
+ });
1997
+ };
1998
+ class ZodUndefined extends ZodType {
1999
+ _parse(input) {
2000
+ const parsedType = this._getType(input);
2001
+ if (parsedType !== ZodParsedType.undefined) {
2002
+ const ctx = this._getOrReturnCtx(input);
2003
+ addIssueToContext(ctx, {
2004
+ code: ZodIssueCode.invalid_type,
2005
+ expected: ZodParsedType.undefined,
2006
+ received: ctx.parsedType
2007
+ });
2008
+ return INVALID;
2009
+ }
2010
+ return OK(input.data);
2011
+ }
2012
+ }
2013
+ ZodUndefined.create = (params) => {
2014
+ return new ZodUndefined({
2015
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2016
+ ...processCreateParams(params)
2017
+ });
2018
+ };
2019
+ class ZodNull extends ZodType {
2020
+ _parse(input) {
2021
+ const parsedType = this._getType(input);
2022
+ if (parsedType !== ZodParsedType.null) {
2023
+ const ctx = this._getOrReturnCtx(input);
2024
+ addIssueToContext(ctx, {
2025
+ code: ZodIssueCode.invalid_type,
2026
+ expected: ZodParsedType.null,
2027
+ received: ctx.parsedType
2028
+ });
2029
+ return INVALID;
2030
+ }
2031
+ return OK(input.data);
2032
+ }
2033
+ }
2034
+ ZodNull.create = (params) => {
2035
+ return new ZodNull({
2036
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2037
+ ...processCreateParams(params)
2038
+ });
2039
+ };
2040
+ class ZodAny extends ZodType {
2041
+ constructor() {
2042
+ super(...arguments);
2043
+ this._any = true;
2044
+ }
2045
+ _parse(input) {
2046
+ return OK(input.data);
2047
+ }
2048
+ }
2049
+ ZodAny.create = (params) => {
2050
+ return new ZodAny({
2051
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2052
+ ...processCreateParams(params)
2053
+ });
2054
+ };
2055
+ class ZodUnknown extends ZodType {
2056
+ constructor() {
2057
+ super(...arguments);
2058
+ this._unknown = true;
2059
+ }
2060
+ _parse(input) {
2061
+ return OK(input.data);
2062
+ }
2063
+ }
2064
+ ZodUnknown.create = (params) => {
2065
+ return new ZodUnknown({
2066
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2067
+ ...processCreateParams(params)
2068
+ });
2069
+ };
2070
+ class ZodNever extends ZodType {
2071
+ _parse(input) {
2072
+ const ctx = this._getOrReturnCtx(input);
2073
+ addIssueToContext(ctx, {
2074
+ code: ZodIssueCode.invalid_type,
2075
+ expected: ZodParsedType.never,
2076
+ received: ctx.parsedType
2077
+ });
2078
+ return INVALID;
2079
+ }
2080
+ }
2081
+ ZodNever.create = (params) => {
2082
+ return new ZodNever({
2083
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2084
+ ...processCreateParams(params)
2085
+ });
2086
+ };
2087
+ class ZodVoid extends ZodType {
2088
+ _parse(input) {
2089
+ const parsedType = this._getType(input);
2090
+ if (parsedType !== ZodParsedType.undefined) {
2091
+ const ctx = this._getOrReturnCtx(input);
2092
+ addIssueToContext(ctx, {
2093
+ code: ZodIssueCode.invalid_type,
2094
+ expected: ZodParsedType.void,
2095
+ received: ctx.parsedType
2096
+ });
2097
+ return INVALID;
2098
+ }
2099
+ return OK(input.data);
2100
+ }
2101
+ }
2102
+ ZodVoid.create = (params) => {
2103
+ return new ZodVoid({
2104
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2105
+ ...processCreateParams(params)
2106
+ });
2107
+ };
2108
+ class ZodArray extends ZodType {
2109
+ _parse(input) {
2110
+ const { ctx, status } = this._processInputParams(input);
2111
+ const def = this._def;
2112
+ if (ctx.parsedType !== ZodParsedType.array) {
2113
+ addIssueToContext(ctx, {
2114
+ code: ZodIssueCode.invalid_type,
2115
+ expected: ZodParsedType.array,
2116
+ received: ctx.parsedType
2117
+ });
2118
+ return INVALID;
2119
+ }
2120
+ if (def.exactLength !== null) {
2121
+ const tooBig = ctx.data.length > def.exactLength.value;
2122
+ const tooSmall = ctx.data.length < def.exactLength.value;
2123
+ if (tooBig || tooSmall) {
2124
+ addIssueToContext(ctx, {
2125
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2126
+ minimum: tooSmall ? def.exactLength.value : void 0,
2127
+ maximum: tooBig ? def.exactLength.value : void 0,
2128
+ type: "array",
2129
+ inclusive: true,
2130
+ exact: true,
2131
+ message: def.exactLength.message
2132
+ });
2133
+ status.dirty();
2134
+ }
2135
+ }
2136
+ if (def.minLength !== null) {
2137
+ if (ctx.data.length < def.minLength.value) {
2138
+ addIssueToContext(ctx, {
2139
+ code: ZodIssueCode.too_small,
2140
+ minimum: def.minLength.value,
2141
+ type: "array",
2142
+ inclusive: true,
2143
+ exact: false,
2144
+ message: def.minLength.message
2145
+ });
2146
+ status.dirty();
2147
+ }
2148
+ }
2149
+ if (def.maxLength !== null) {
2150
+ if (ctx.data.length > def.maxLength.value) {
2151
+ addIssueToContext(ctx, {
2152
+ code: ZodIssueCode.too_big,
2153
+ maximum: def.maxLength.value,
2154
+ type: "array",
2155
+ inclusive: true,
2156
+ exact: false,
2157
+ message: def.maxLength.message
2158
+ });
2159
+ status.dirty();
2160
+ }
2161
+ }
2162
+ if (ctx.common.async) {
2163
+ return Promise.all([...ctx.data].map((item, i) => {
2164
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2165
+ })).then((result2) => {
2166
+ return ParseStatus.mergeArray(status, result2);
2167
+ });
2168
+ }
2169
+ const result = [...ctx.data].map((item, i) => {
2170
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2171
+ });
2172
+ return ParseStatus.mergeArray(status, result);
2173
+ }
2174
+ get element() {
2175
+ return this._def.type;
2176
+ }
2177
+ min(minLength, message) {
2178
+ return new ZodArray({
2179
+ ...this._def,
2180
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2181
+ });
2182
+ }
2183
+ max(maxLength, message) {
2184
+ return new ZodArray({
2185
+ ...this._def,
2186
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2187
+ });
2188
+ }
2189
+ length(len, message) {
2190
+ return new ZodArray({
2191
+ ...this._def,
2192
+ exactLength: { value: len, message: errorUtil.toString(message) }
2193
+ });
2194
+ }
2195
+ nonempty(message) {
2196
+ return this.min(1, message);
2197
+ }
2198
+ }
2199
+ ZodArray.create = (schema, params) => {
2200
+ return new ZodArray({
2201
+ type: schema,
2202
+ minLength: null,
2203
+ maxLength: null,
2204
+ exactLength: null,
2205
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2206
+ ...processCreateParams(params)
2207
+ });
2208
+ };
2209
+ function deepPartialify(schema) {
2210
+ if (schema instanceof ZodObject) {
2211
+ const newShape = {};
2212
+ for (const key in schema.shape) {
2213
+ const fieldSchema = schema.shape[key];
2214
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2215
+ }
2216
+ return new ZodObject({
2217
+ ...schema._def,
2218
+ shape: () => newShape
2219
+ });
2220
+ } else if (schema instanceof ZodArray) {
2221
+ return new ZodArray({
2222
+ ...schema._def,
2223
+ type: deepPartialify(schema.element)
2224
+ });
2225
+ } else if (schema instanceof ZodOptional) {
2226
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2227
+ } else if (schema instanceof ZodNullable) {
2228
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2229
+ } else if (schema instanceof ZodTuple) {
2230
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2231
+ } else {
2232
+ return schema;
2233
+ }
2234
+ }
2235
+ class ZodObject extends ZodType {
2236
+ constructor() {
2237
+ super(...arguments);
2238
+ this._cached = null;
2239
+ this.nonstrict = this.passthrough;
2240
+ this.augment = this.extend;
2241
+ }
2242
+ _getCached() {
2243
+ if (this._cached !== null)
2244
+ return this._cached;
2245
+ const shape = this._def.shape();
2246
+ const keys = util.objectKeys(shape);
2247
+ this._cached = { shape, keys };
2248
+ return this._cached;
2249
+ }
2250
+ _parse(input) {
2251
+ const parsedType = this._getType(input);
2252
+ if (parsedType !== ZodParsedType.object) {
2253
+ const ctx2 = this._getOrReturnCtx(input);
2254
+ addIssueToContext(ctx2, {
2255
+ code: ZodIssueCode.invalid_type,
2256
+ expected: ZodParsedType.object,
2257
+ received: ctx2.parsedType
2258
+ });
2259
+ return INVALID;
2260
+ }
2261
+ const { status, ctx } = this._processInputParams(input);
2262
+ const { shape, keys: shapeKeys } = this._getCached();
2263
+ const extraKeys = [];
2264
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2265
+ for (const key in ctx.data) {
2266
+ if (!shapeKeys.includes(key)) {
2267
+ extraKeys.push(key);
2268
+ }
2269
+ }
2270
+ }
2271
+ const pairs = [];
2272
+ for (const key of shapeKeys) {
2273
+ const keyValidator = shape[key];
2274
+ const value = ctx.data[key];
2275
+ pairs.push({
2276
+ key: { status: "valid", value: key },
2277
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2278
+ alwaysSet: key in ctx.data
2279
+ });
2280
+ }
2281
+ if (this._def.catchall instanceof ZodNever) {
2282
+ const unknownKeys = this._def.unknownKeys;
2283
+ if (unknownKeys === "passthrough") {
2284
+ for (const key of extraKeys) {
2285
+ pairs.push({
2286
+ key: { status: "valid", value: key },
2287
+ value: { status: "valid", value: ctx.data[key] }
2288
+ });
2289
+ }
2290
+ } else if (unknownKeys === "strict") {
2291
+ if (extraKeys.length > 0) {
2292
+ addIssueToContext(ctx, {
2293
+ code: ZodIssueCode.unrecognized_keys,
2294
+ keys: extraKeys
2295
+ });
2296
+ status.dirty();
2297
+ }
2298
+ } else if (unknownKeys === "strip") ;
2299
+ else {
2300
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2301
+ }
2302
+ } else {
2303
+ const catchall = this._def.catchall;
2304
+ for (const key of extraKeys) {
2305
+ const value = ctx.data[key];
2306
+ pairs.push({
2307
+ key: { status: "valid", value: key },
2308
+ value: catchall._parse(
2309
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2310
+ //, ctx.child(key), value, getParsedType(value)
2311
+ ),
2312
+ alwaysSet: key in ctx.data
2313
+ });
2314
+ }
2315
+ }
2316
+ if (ctx.common.async) {
2317
+ return Promise.resolve().then(async () => {
2318
+ const syncPairs = [];
2319
+ for (const pair of pairs) {
2320
+ const key = await pair.key;
2321
+ const value = await pair.value;
2322
+ syncPairs.push({
2323
+ key,
2324
+ value,
2325
+ alwaysSet: pair.alwaysSet
2326
+ });
2327
+ }
2328
+ return syncPairs;
2329
+ }).then((syncPairs) => {
2330
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2331
+ });
2332
+ } else {
2333
+ return ParseStatus.mergeObjectSync(status, pairs);
2334
+ }
2335
+ }
2336
+ get shape() {
2337
+ return this._def.shape();
2338
+ }
2339
+ strict(message) {
2340
+ errorUtil.errToObj;
2341
+ return new ZodObject({
2342
+ ...this._def,
2343
+ unknownKeys: "strict",
2344
+ ...message !== void 0 ? {
2345
+ errorMap: (issue, ctx) => {
2346
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2347
+ if (issue.code === "unrecognized_keys")
2348
+ return {
2349
+ message: errorUtil.errToObj(message).message ?? defaultError
2350
+ };
2351
+ return {
2352
+ message: defaultError
2353
+ };
2354
+ }
2355
+ } : {}
2356
+ });
2357
+ }
2358
+ strip() {
2359
+ return new ZodObject({
2360
+ ...this._def,
2361
+ unknownKeys: "strip"
2362
+ });
2363
+ }
2364
+ passthrough() {
2365
+ return new ZodObject({
2366
+ ...this._def,
2367
+ unknownKeys: "passthrough"
2368
+ });
2369
+ }
2370
+ // const AugmentFactory =
2371
+ // <Def extends ZodObjectDef>(def: Def) =>
2372
+ // <Augmentation extends ZodRawShape>(
2373
+ // augmentation: Augmentation
2374
+ // ): ZodObject<
2375
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2376
+ // Def["unknownKeys"],
2377
+ // Def["catchall"]
2378
+ // > => {
2379
+ // return new ZodObject({
2380
+ // ...def,
2381
+ // shape: () => ({
2382
+ // ...def.shape(),
2383
+ // ...augmentation,
2384
+ // }),
2385
+ // }) as any;
2386
+ // };
2387
+ extend(augmentation) {
2388
+ return new ZodObject({
2389
+ ...this._def,
2390
+ shape: () => ({
2391
+ ...this._def.shape(),
2392
+ ...augmentation
2393
+ })
2394
+ });
2395
+ }
2396
+ /**
2397
+ * Prior to zod@1.0.12 there was a bug in the
2398
+ * inferred type of merged objects. Please
2399
+ * upgrade if you are experiencing issues.
2400
+ */
2401
+ merge(merging) {
2402
+ const merged = new ZodObject({
2403
+ unknownKeys: merging._def.unknownKeys,
2404
+ catchall: merging._def.catchall,
2405
+ shape: () => ({
2406
+ ...this._def.shape(),
2407
+ ...merging._def.shape()
2408
+ }),
2409
+ typeName: ZodFirstPartyTypeKind.ZodObject
2410
+ });
2411
+ return merged;
2412
+ }
2413
+ // merge<
2414
+ // Incoming extends AnyZodObject,
2415
+ // Augmentation extends Incoming["shape"],
2416
+ // NewOutput extends {
2417
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2418
+ // ? Augmentation[k]["_output"]
2419
+ // : k extends keyof Output
2420
+ // ? Output[k]
2421
+ // : never;
2422
+ // },
2423
+ // NewInput extends {
2424
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2425
+ // ? Augmentation[k]["_input"]
2426
+ // : k extends keyof Input
2427
+ // ? Input[k]
2428
+ // : never;
2429
+ // }
2430
+ // >(
2431
+ // merging: Incoming
2432
+ // ): ZodObject<
2433
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2434
+ // Incoming["_def"]["unknownKeys"],
2435
+ // Incoming["_def"]["catchall"],
2436
+ // NewOutput,
2437
+ // NewInput
2438
+ // > {
2439
+ // const merged: any = new ZodObject({
2440
+ // unknownKeys: merging._def.unknownKeys,
2441
+ // catchall: merging._def.catchall,
2442
+ // shape: () =>
2443
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2444
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2445
+ // }) as any;
2446
+ // return merged;
2447
+ // }
2448
+ setKey(key, schema) {
2449
+ return this.augment({ [key]: schema });
2450
+ }
2451
+ // merge<Incoming extends AnyZodObject>(
2452
+ // merging: Incoming
2453
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2454
+ // ZodObject<
2455
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2456
+ // Incoming["_def"]["unknownKeys"],
2457
+ // Incoming["_def"]["catchall"]
2458
+ // > {
2459
+ // // const mergedShape = objectUtil.mergeShapes(
2460
+ // // this._def.shape(),
2461
+ // // merging._def.shape()
2462
+ // // );
2463
+ // const merged: any = new ZodObject({
2464
+ // unknownKeys: merging._def.unknownKeys,
2465
+ // catchall: merging._def.catchall,
2466
+ // shape: () =>
2467
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2468
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2469
+ // }) as any;
2470
+ // return merged;
2471
+ // }
2472
+ catchall(index) {
2473
+ return new ZodObject({
2474
+ ...this._def,
2475
+ catchall: index
2476
+ });
2477
+ }
2478
+ pick(mask) {
2479
+ const shape = {};
2480
+ for (const key of util.objectKeys(mask)) {
2481
+ if (mask[key] && this.shape[key]) {
2482
+ shape[key] = this.shape[key];
2483
+ }
2484
+ }
2485
+ return new ZodObject({
2486
+ ...this._def,
2487
+ shape: () => shape
2488
+ });
2489
+ }
2490
+ omit(mask) {
2491
+ const shape = {};
2492
+ for (const key of util.objectKeys(this.shape)) {
2493
+ if (!mask[key]) {
2494
+ shape[key] = this.shape[key];
2495
+ }
2496
+ }
2497
+ return new ZodObject({
2498
+ ...this._def,
2499
+ shape: () => shape
2500
+ });
2501
+ }
2502
+ /**
2503
+ * @deprecated
2504
+ */
2505
+ deepPartial() {
2506
+ return deepPartialify(this);
2507
+ }
2508
+ partial(mask) {
2509
+ const newShape = {};
2510
+ for (const key of util.objectKeys(this.shape)) {
2511
+ const fieldSchema = this.shape[key];
2512
+ if (mask && !mask[key]) {
2513
+ newShape[key] = fieldSchema;
2514
+ } else {
2515
+ newShape[key] = fieldSchema.optional();
2516
+ }
2517
+ }
2518
+ return new ZodObject({
2519
+ ...this._def,
2520
+ shape: () => newShape
2521
+ });
2522
+ }
2523
+ required(mask) {
2524
+ const newShape = {};
2525
+ for (const key of util.objectKeys(this.shape)) {
2526
+ if (mask && !mask[key]) {
2527
+ newShape[key] = this.shape[key];
2528
+ } else {
2529
+ const fieldSchema = this.shape[key];
2530
+ let newField = fieldSchema;
2531
+ while (newField instanceof ZodOptional) {
2532
+ newField = newField._def.innerType;
2533
+ }
2534
+ newShape[key] = newField;
2535
+ }
2536
+ }
2537
+ return new ZodObject({
2538
+ ...this._def,
2539
+ shape: () => newShape
2540
+ });
2541
+ }
2542
+ keyof() {
2543
+ return createZodEnum(util.objectKeys(this.shape));
2544
+ }
2545
+ }
2546
+ ZodObject.create = (shape, params) => {
2547
+ return new ZodObject({
2548
+ shape: () => shape,
2549
+ unknownKeys: "strip",
2550
+ catchall: ZodNever.create(),
2551
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2552
+ ...processCreateParams(params)
2553
+ });
2554
+ };
2555
+ ZodObject.strictCreate = (shape, params) => {
2556
+ return new ZodObject({
2557
+ shape: () => shape,
2558
+ unknownKeys: "strict",
2559
+ catchall: ZodNever.create(),
2560
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2561
+ ...processCreateParams(params)
2562
+ });
2563
+ };
2564
+ ZodObject.lazycreate = (shape, params) => {
2565
+ return new ZodObject({
2566
+ shape,
2567
+ unknownKeys: "strip",
2568
+ catchall: ZodNever.create(),
2569
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2570
+ ...processCreateParams(params)
2571
+ });
2572
+ };
2573
+ class ZodUnion extends ZodType {
2574
+ _parse(input) {
2575
+ const { ctx } = this._processInputParams(input);
2576
+ const options = this._def.options;
2577
+ function handleResults(results) {
2578
+ for (const result of results) {
2579
+ if (result.result.status === "valid") {
2580
+ return result.result;
2581
+ }
2582
+ }
2583
+ for (const result of results) {
2584
+ if (result.result.status === "dirty") {
2585
+ ctx.common.issues.push(...result.ctx.common.issues);
2586
+ return result.result;
2587
+ }
2588
+ }
2589
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2590
+ addIssueToContext(ctx, {
2591
+ code: ZodIssueCode.invalid_union,
2592
+ unionErrors
2593
+ });
2594
+ return INVALID;
2595
+ }
2596
+ if (ctx.common.async) {
2597
+ return Promise.all(options.map(async (option) => {
2598
+ const childCtx = {
2599
+ ...ctx,
2600
+ common: {
2601
+ ...ctx.common,
2602
+ issues: []
2603
+ },
2604
+ parent: null
2605
+ };
2606
+ return {
2607
+ result: await option._parseAsync({
2608
+ data: ctx.data,
2609
+ path: ctx.path,
2610
+ parent: childCtx
2611
+ }),
2612
+ ctx: childCtx
2613
+ };
2614
+ })).then(handleResults);
2615
+ } else {
2616
+ let dirty = void 0;
2617
+ const issues = [];
2618
+ for (const option of options) {
2619
+ const childCtx = {
2620
+ ...ctx,
2621
+ common: {
2622
+ ...ctx.common,
2623
+ issues: []
2624
+ },
2625
+ parent: null
2626
+ };
2627
+ const result = option._parseSync({
2628
+ data: ctx.data,
2629
+ path: ctx.path,
2630
+ parent: childCtx
2631
+ });
2632
+ if (result.status === "valid") {
2633
+ return result;
2634
+ } else if (result.status === "dirty" && !dirty) {
2635
+ dirty = { result, ctx: childCtx };
2636
+ }
2637
+ if (childCtx.common.issues.length) {
2638
+ issues.push(childCtx.common.issues);
2639
+ }
2640
+ }
2641
+ if (dirty) {
2642
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2643
+ return dirty.result;
2644
+ }
2645
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
2646
+ addIssueToContext(ctx, {
2647
+ code: ZodIssueCode.invalid_union,
2648
+ unionErrors
2649
+ });
2650
+ return INVALID;
2651
+ }
2652
+ }
2653
+ get options() {
2654
+ return this._def.options;
2655
+ }
2656
+ }
2657
+ ZodUnion.create = (types, params) => {
2658
+ return new ZodUnion({
2659
+ options: types,
2660
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2661
+ ...processCreateParams(params)
2662
+ });
2663
+ };
2664
+ function mergeValues(a, b) {
2665
+ const aType = getParsedType(a);
2666
+ const bType = getParsedType(b);
2667
+ if (a === b) {
2668
+ return { valid: true, data: a };
2669
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2670
+ const bKeys = util.objectKeys(b);
2671
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2672
+ const newObj = { ...a, ...b };
2673
+ for (const key of sharedKeys) {
2674
+ const sharedValue = mergeValues(a[key], b[key]);
2675
+ if (!sharedValue.valid) {
2676
+ return { valid: false };
2677
+ }
2678
+ newObj[key] = sharedValue.data;
2679
+ }
2680
+ return { valid: true, data: newObj };
2681
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2682
+ if (a.length !== b.length) {
2683
+ return { valid: false };
2684
+ }
2685
+ const newArray = [];
2686
+ for (let index = 0; index < a.length; index++) {
2687
+ const itemA = a[index];
2688
+ const itemB = b[index];
2689
+ const sharedValue = mergeValues(itemA, itemB);
2690
+ if (!sharedValue.valid) {
2691
+ return { valid: false };
2692
+ }
2693
+ newArray.push(sharedValue.data);
2694
+ }
2695
+ return { valid: true, data: newArray };
2696
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
2697
+ return { valid: true, data: a };
2698
+ } else {
2699
+ return { valid: false };
2700
+ }
2701
+ }
2702
+ class ZodIntersection extends ZodType {
2703
+ _parse(input) {
2704
+ const { status, ctx } = this._processInputParams(input);
2705
+ const handleParsed = (parsedLeft, parsedRight) => {
2706
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2707
+ return INVALID;
2708
+ }
2709
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2710
+ if (!merged.valid) {
2711
+ addIssueToContext(ctx, {
2712
+ code: ZodIssueCode.invalid_intersection_types
2713
+ });
2714
+ return INVALID;
2715
+ }
2716
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2717
+ status.dirty();
2718
+ }
2719
+ return { status: status.value, value: merged.data };
2720
+ };
2721
+ if (ctx.common.async) {
2722
+ return Promise.all([
2723
+ this._def.left._parseAsync({
2724
+ data: ctx.data,
2725
+ path: ctx.path,
2726
+ parent: ctx
2727
+ }),
2728
+ this._def.right._parseAsync({
2729
+ data: ctx.data,
2730
+ path: ctx.path,
2731
+ parent: ctx
2732
+ })
2733
+ ]).then(([left, right]) => handleParsed(left, right));
2734
+ } else {
2735
+ return handleParsed(this._def.left._parseSync({
2736
+ data: ctx.data,
2737
+ path: ctx.path,
2738
+ parent: ctx
2739
+ }), this._def.right._parseSync({
2740
+ data: ctx.data,
2741
+ path: ctx.path,
2742
+ parent: ctx
2743
+ }));
2744
+ }
2745
+ }
2746
+ }
2747
+ ZodIntersection.create = (left, right, params) => {
2748
+ return new ZodIntersection({
2749
+ left,
2750
+ right,
2751
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2752
+ ...processCreateParams(params)
2753
+ });
2754
+ };
2755
+ class ZodTuple extends ZodType {
2756
+ _parse(input) {
2757
+ const { status, ctx } = this._processInputParams(input);
2758
+ if (ctx.parsedType !== ZodParsedType.array) {
2759
+ addIssueToContext(ctx, {
2760
+ code: ZodIssueCode.invalid_type,
2761
+ expected: ZodParsedType.array,
2762
+ received: ctx.parsedType
2763
+ });
2764
+ return INVALID;
2765
+ }
2766
+ if (ctx.data.length < this._def.items.length) {
2767
+ addIssueToContext(ctx, {
2768
+ code: ZodIssueCode.too_small,
2769
+ minimum: this._def.items.length,
2770
+ inclusive: true,
2771
+ exact: false,
2772
+ type: "array"
2773
+ });
2774
+ return INVALID;
2775
+ }
2776
+ const rest = this._def.rest;
2777
+ if (!rest && ctx.data.length > this._def.items.length) {
2778
+ addIssueToContext(ctx, {
2779
+ code: ZodIssueCode.too_big,
2780
+ maximum: this._def.items.length,
2781
+ inclusive: true,
2782
+ exact: false,
2783
+ type: "array"
2784
+ });
2785
+ status.dirty();
2786
+ }
2787
+ const items = [...ctx.data].map((item, itemIndex) => {
2788
+ const schema = this._def.items[itemIndex] || this._def.rest;
2789
+ if (!schema)
2790
+ return null;
2791
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2792
+ }).filter((x) => !!x);
2793
+ if (ctx.common.async) {
2794
+ return Promise.all(items).then((results) => {
2795
+ return ParseStatus.mergeArray(status, results);
2796
+ });
2797
+ } else {
2798
+ return ParseStatus.mergeArray(status, items);
2799
+ }
2800
+ }
2801
+ get items() {
2802
+ return this._def.items;
2803
+ }
2804
+ rest(rest) {
2805
+ return new ZodTuple({
2806
+ ...this._def,
2807
+ rest
2808
+ });
2809
+ }
2810
+ }
2811
+ ZodTuple.create = (schemas, params) => {
2812
+ if (!Array.isArray(schemas)) {
2813
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2814
+ }
2815
+ return new ZodTuple({
2816
+ items: schemas,
2817
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2818
+ rest: null,
2819
+ ...processCreateParams(params)
2820
+ });
2821
+ };
2822
+ class ZodRecord extends ZodType {
2823
+ get keySchema() {
2824
+ return this._def.keyType;
2825
+ }
2826
+ get valueSchema() {
2827
+ return this._def.valueType;
2828
+ }
2829
+ _parse(input) {
2830
+ const { status, ctx } = this._processInputParams(input);
2831
+ if (ctx.parsedType !== ZodParsedType.object) {
2832
+ addIssueToContext(ctx, {
2833
+ code: ZodIssueCode.invalid_type,
2834
+ expected: ZodParsedType.object,
2835
+ received: ctx.parsedType
2836
+ });
2837
+ return INVALID;
2838
+ }
2839
+ const pairs = [];
2840
+ const keyType = this._def.keyType;
2841
+ const valueType = this._def.valueType;
2842
+ for (const key in ctx.data) {
2843
+ pairs.push({
2844
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2845
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2846
+ alwaysSet: key in ctx.data
2847
+ });
2848
+ }
2849
+ if (ctx.common.async) {
2850
+ return ParseStatus.mergeObjectAsync(status, pairs);
2851
+ } else {
2852
+ return ParseStatus.mergeObjectSync(status, pairs);
2853
+ }
2854
+ }
2855
+ get element() {
2856
+ return this._def.valueType;
2857
+ }
2858
+ static create(first, second, third) {
2859
+ if (second instanceof ZodType) {
2860
+ return new ZodRecord({
2861
+ keyType: first,
2862
+ valueType: second,
2863
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2864
+ ...processCreateParams(third)
2865
+ });
2866
+ }
2867
+ return new ZodRecord({
2868
+ keyType: ZodString.create(),
2869
+ valueType: first,
2870
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2871
+ ...processCreateParams(second)
2872
+ });
2873
+ }
2874
+ }
2875
+ class ZodMap extends ZodType {
2876
+ get keySchema() {
2877
+ return this._def.keyType;
2878
+ }
2879
+ get valueSchema() {
2880
+ return this._def.valueType;
2881
+ }
2882
+ _parse(input) {
2883
+ const { status, ctx } = this._processInputParams(input);
2884
+ if (ctx.parsedType !== ZodParsedType.map) {
2885
+ addIssueToContext(ctx, {
2886
+ code: ZodIssueCode.invalid_type,
2887
+ expected: ZodParsedType.map,
2888
+ received: ctx.parsedType
2889
+ });
2890
+ return INVALID;
2891
+ }
2892
+ const keyType = this._def.keyType;
2893
+ const valueType = this._def.valueType;
2894
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2895
+ return {
2896
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2897
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2898
+ };
2899
+ });
2900
+ if (ctx.common.async) {
2901
+ const finalMap = /* @__PURE__ */ new Map();
2902
+ return Promise.resolve().then(async () => {
2903
+ for (const pair of pairs) {
2904
+ const key = await pair.key;
2905
+ const value = await pair.value;
2906
+ if (key.status === "aborted" || value.status === "aborted") {
2907
+ return INVALID;
2908
+ }
2909
+ if (key.status === "dirty" || value.status === "dirty") {
2910
+ status.dirty();
2911
+ }
2912
+ finalMap.set(key.value, value.value);
2913
+ }
2914
+ return { status: status.value, value: finalMap };
2915
+ });
2916
+ } else {
2917
+ const finalMap = /* @__PURE__ */ new Map();
2918
+ for (const pair of pairs) {
2919
+ const key = pair.key;
2920
+ const value = pair.value;
2921
+ if (key.status === "aborted" || value.status === "aborted") {
2922
+ return INVALID;
2923
+ }
2924
+ if (key.status === "dirty" || value.status === "dirty") {
2925
+ status.dirty();
2926
+ }
2927
+ finalMap.set(key.value, value.value);
2928
+ }
2929
+ return { status: status.value, value: finalMap };
2930
+ }
2931
+ }
2932
+ }
2933
+ ZodMap.create = (keyType, valueType, params) => {
2934
+ return new ZodMap({
2935
+ valueType,
2936
+ keyType,
2937
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2938
+ ...processCreateParams(params)
2939
+ });
2940
+ };
2941
+ class ZodSet extends ZodType {
2942
+ _parse(input) {
2943
+ const { status, ctx } = this._processInputParams(input);
2944
+ if (ctx.parsedType !== ZodParsedType.set) {
2945
+ addIssueToContext(ctx, {
2946
+ code: ZodIssueCode.invalid_type,
2947
+ expected: ZodParsedType.set,
2948
+ received: ctx.parsedType
2949
+ });
2950
+ return INVALID;
2951
+ }
2952
+ const def = this._def;
2953
+ if (def.minSize !== null) {
2954
+ if (ctx.data.size < def.minSize.value) {
2955
+ addIssueToContext(ctx, {
2956
+ code: ZodIssueCode.too_small,
2957
+ minimum: def.minSize.value,
2958
+ type: "set",
2959
+ inclusive: true,
2960
+ exact: false,
2961
+ message: def.minSize.message
2962
+ });
2963
+ status.dirty();
2964
+ }
2965
+ }
2966
+ if (def.maxSize !== null) {
2967
+ if (ctx.data.size > def.maxSize.value) {
2968
+ addIssueToContext(ctx, {
2969
+ code: ZodIssueCode.too_big,
2970
+ maximum: def.maxSize.value,
2971
+ type: "set",
2972
+ inclusive: true,
2973
+ exact: false,
2974
+ message: def.maxSize.message
2975
+ });
2976
+ status.dirty();
2977
+ }
2978
+ }
2979
+ const valueType = this._def.valueType;
2980
+ function finalizeSet(elements2) {
2981
+ const parsedSet = /* @__PURE__ */ new Set();
2982
+ for (const element of elements2) {
2983
+ if (element.status === "aborted")
2984
+ return INVALID;
2985
+ if (element.status === "dirty")
2986
+ status.dirty();
2987
+ parsedSet.add(element.value);
2988
+ }
2989
+ return { status: status.value, value: parsedSet };
2990
+ }
2991
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2992
+ if (ctx.common.async) {
2993
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
2994
+ } else {
2995
+ return finalizeSet(elements);
2996
+ }
2997
+ }
2998
+ min(minSize, message) {
2999
+ return new ZodSet({
3000
+ ...this._def,
3001
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3002
+ });
3003
+ }
3004
+ max(maxSize, message) {
3005
+ return new ZodSet({
3006
+ ...this._def,
3007
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3008
+ });
3009
+ }
3010
+ size(size, message) {
3011
+ return this.min(size, message).max(size, message);
3012
+ }
3013
+ nonempty(message) {
3014
+ return this.min(1, message);
3015
+ }
3016
+ }
3017
+ ZodSet.create = (valueType, params) => {
3018
+ return new ZodSet({
3019
+ valueType,
3020
+ minSize: null,
3021
+ maxSize: null,
3022
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3023
+ ...processCreateParams(params)
3024
+ });
3025
+ };
3026
+ class ZodLazy extends ZodType {
3027
+ get schema() {
3028
+ return this._def.getter();
3029
+ }
3030
+ _parse(input) {
3031
+ const { ctx } = this._processInputParams(input);
3032
+ const lazySchema = this._def.getter();
3033
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3034
+ }
3035
+ }
3036
+ ZodLazy.create = (getter, params) => {
3037
+ return new ZodLazy({
3038
+ getter,
3039
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3040
+ ...processCreateParams(params)
3041
+ });
3042
+ };
3043
+ class ZodLiteral extends ZodType {
3044
+ _parse(input) {
3045
+ if (input.data !== this._def.value) {
3046
+ const ctx = this._getOrReturnCtx(input);
3047
+ addIssueToContext(ctx, {
3048
+ received: ctx.data,
3049
+ code: ZodIssueCode.invalid_literal,
3050
+ expected: this._def.value
3051
+ });
3052
+ return INVALID;
3053
+ }
3054
+ return { status: "valid", value: input.data };
3055
+ }
3056
+ get value() {
3057
+ return this._def.value;
3058
+ }
3059
+ }
3060
+ ZodLiteral.create = (value, params) => {
3061
+ return new ZodLiteral({
3062
+ value,
3063
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3064
+ ...processCreateParams(params)
3065
+ });
3066
+ };
3067
+ function createZodEnum(values, params) {
3068
+ return new ZodEnum({
3069
+ values,
3070
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3071
+ ...processCreateParams(params)
3072
+ });
3073
+ }
3074
+ class ZodEnum extends ZodType {
3075
+ _parse(input) {
3076
+ if (typeof input.data !== "string") {
3077
+ const ctx = this._getOrReturnCtx(input);
3078
+ const expectedValues = this._def.values;
3079
+ addIssueToContext(ctx, {
3080
+ expected: util.joinValues(expectedValues),
3081
+ received: ctx.parsedType,
3082
+ code: ZodIssueCode.invalid_type
3083
+ });
3084
+ return INVALID;
3085
+ }
3086
+ if (!this._cache) {
3087
+ this._cache = new Set(this._def.values);
3088
+ }
3089
+ if (!this._cache.has(input.data)) {
3090
+ const ctx = this._getOrReturnCtx(input);
3091
+ const expectedValues = this._def.values;
3092
+ addIssueToContext(ctx, {
3093
+ received: ctx.data,
3094
+ code: ZodIssueCode.invalid_enum_value,
3095
+ options: expectedValues
3096
+ });
3097
+ return INVALID;
3098
+ }
3099
+ return OK(input.data);
3100
+ }
3101
+ get options() {
3102
+ return this._def.values;
3103
+ }
3104
+ get enum() {
3105
+ const enumValues = {};
3106
+ for (const val of this._def.values) {
3107
+ enumValues[val] = val;
3108
+ }
3109
+ return enumValues;
3110
+ }
3111
+ get Values() {
3112
+ const enumValues = {};
3113
+ for (const val of this._def.values) {
3114
+ enumValues[val] = val;
3115
+ }
3116
+ return enumValues;
3117
+ }
3118
+ get Enum() {
3119
+ const enumValues = {};
3120
+ for (const val of this._def.values) {
3121
+ enumValues[val] = val;
3122
+ }
3123
+ return enumValues;
3124
+ }
3125
+ extract(values, newDef = this._def) {
3126
+ return ZodEnum.create(values, {
3127
+ ...this._def,
3128
+ ...newDef
3129
+ });
3130
+ }
3131
+ exclude(values, newDef = this._def) {
3132
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3133
+ ...this._def,
3134
+ ...newDef
3135
+ });
3136
+ }
3137
+ }
3138
+ ZodEnum.create = createZodEnum;
3139
+ class ZodNativeEnum extends ZodType {
3140
+ _parse(input) {
3141
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3142
+ const ctx = this._getOrReturnCtx(input);
3143
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3144
+ const expectedValues = util.objectValues(nativeEnumValues);
3145
+ addIssueToContext(ctx, {
3146
+ expected: util.joinValues(expectedValues),
3147
+ received: ctx.parsedType,
3148
+ code: ZodIssueCode.invalid_type
3149
+ });
3150
+ return INVALID;
3151
+ }
3152
+ if (!this._cache) {
3153
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
3154
+ }
3155
+ if (!this._cache.has(input.data)) {
3156
+ const expectedValues = util.objectValues(nativeEnumValues);
3157
+ addIssueToContext(ctx, {
3158
+ received: ctx.data,
3159
+ code: ZodIssueCode.invalid_enum_value,
3160
+ options: expectedValues
3161
+ });
3162
+ return INVALID;
3163
+ }
3164
+ return OK(input.data);
3165
+ }
3166
+ get enum() {
3167
+ return this._def.values;
3168
+ }
3169
+ }
3170
+ ZodNativeEnum.create = (values, params) => {
3171
+ return new ZodNativeEnum({
3172
+ values,
3173
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3174
+ ...processCreateParams(params)
3175
+ });
3176
+ };
3177
+ class ZodPromise extends ZodType {
3178
+ unwrap() {
3179
+ return this._def.type;
3180
+ }
3181
+ _parse(input) {
3182
+ const { ctx } = this._processInputParams(input);
3183
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3184
+ addIssueToContext(ctx, {
3185
+ code: ZodIssueCode.invalid_type,
3186
+ expected: ZodParsedType.promise,
3187
+ received: ctx.parsedType
3188
+ });
3189
+ return INVALID;
3190
+ }
3191
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3192
+ return OK(promisified.then((data) => {
3193
+ return this._def.type.parseAsync(data, {
3194
+ path: ctx.path,
3195
+ errorMap: ctx.common.contextualErrorMap
3196
+ });
3197
+ }));
3198
+ }
3199
+ }
3200
+ ZodPromise.create = (schema, params) => {
3201
+ return new ZodPromise({
3202
+ type: schema,
3203
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3204
+ ...processCreateParams(params)
3205
+ });
3206
+ };
3207
+ class ZodEffects extends ZodType {
3208
+ innerType() {
3209
+ return this._def.schema;
3210
+ }
3211
+ sourceType() {
3212
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3213
+ }
3214
+ _parse(input) {
3215
+ const { status, ctx } = this._processInputParams(input);
3216
+ const effect = this._def.effect || null;
3217
+ const checkCtx = {
3218
+ addIssue: (arg) => {
3219
+ addIssueToContext(ctx, arg);
3220
+ if (arg.fatal) {
3221
+ status.abort();
3222
+ } else {
3223
+ status.dirty();
3224
+ }
3225
+ },
3226
+ get path() {
3227
+ return ctx.path;
3228
+ }
3229
+ };
3230
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3231
+ if (effect.type === "preprocess") {
3232
+ const processed = effect.transform(ctx.data, checkCtx);
3233
+ if (ctx.common.async) {
3234
+ return Promise.resolve(processed).then(async (processed2) => {
3235
+ if (status.value === "aborted")
3236
+ return INVALID;
3237
+ const result = await this._def.schema._parseAsync({
3238
+ data: processed2,
3239
+ path: ctx.path,
3240
+ parent: ctx
3241
+ });
3242
+ if (result.status === "aborted")
3243
+ return INVALID;
3244
+ if (result.status === "dirty")
3245
+ return DIRTY(result.value);
3246
+ if (status.value === "dirty")
3247
+ return DIRTY(result.value);
3248
+ return result;
3249
+ });
3250
+ } else {
3251
+ if (status.value === "aborted")
3252
+ return INVALID;
3253
+ const result = this._def.schema._parseSync({
3254
+ data: processed,
3255
+ path: ctx.path,
3256
+ parent: ctx
3257
+ });
3258
+ if (result.status === "aborted")
3259
+ return INVALID;
3260
+ if (result.status === "dirty")
3261
+ return DIRTY(result.value);
3262
+ if (status.value === "dirty")
3263
+ return DIRTY(result.value);
3264
+ return result;
3265
+ }
3266
+ }
3267
+ if (effect.type === "refinement") {
3268
+ const executeRefinement = (acc) => {
3269
+ const result = effect.refinement(acc, checkCtx);
3270
+ if (ctx.common.async) {
3271
+ return Promise.resolve(result);
3272
+ }
3273
+ if (result instanceof Promise) {
3274
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3275
+ }
3276
+ return acc;
3277
+ };
3278
+ if (ctx.common.async === false) {
3279
+ const inner = this._def.schema._parseSync({
3280
+ data: ctx.data,
3281
+ path: ctx.path,
3282
+ parent: ctx
3283
+ });
3284
+ if (inner.status === "aborted")
3285
+ return INVALID;
3286
+ if (inner.status === "dirty")
3287
+ status.dirty();
3288
+ executeRefinement(inner.value);
3289
+ return { status: status.value, value: inner.value };
3290
+ } else {
3291
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3292
+ if (inner.status === "aborted")
3293
+ return INVALID;
3294
+ if (inner.status === "dirty")
3295
+ status.dirty();
3296
+ return executeRefinement(inner.value).then(() => {
3297
+ return { status: status.value, value: inner.value };
3298
+ });
3299
+ });
3300
+ }
3301
+ }
3302
+ if (effect.type === "transform") {
3303
+ if (ctx.common.async === false) {
3304
+ const base = this._def.schema._parseSync({
3305
+ data: ctx.data,
3306
+ path: ctx.path,
3307
+ parent: ctx
3308
+ });
3309
+ if (!isValid(base))
3310
+ return INVALID;
3311
+ const result = effect.transform(base.value, checkCtx);
3312
+ if (result instanceof Promise) {
3313
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3314
+ }
3315
+ return { status: status.value, value: result };
3316
+ } else {
3317
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3318
+ if (!isValid(base))
3319
+ return INVALID;
3320
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3321
+ status: status.value,
3322
+ value: result
3323
+ }));
3324
+ });
3325
+ }
3326
+ }
3327
+ util.assertNever(effect);
3328
+ }
3329
+ }
3330
+ ZodEffects.create = (schema, effect, params) => {
3331
+ return new ZodEffects({
3332
+ schema,
3333
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3334
+ effect,
3335
+ ...processCreateParams(params)
3336
+ });
3337
+ };
3338
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3339
+ return new ZodEffects({
3340
+ schema,
3341
+ effect: { type: "preprocess", transform: preprocess },
3342
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3343
+ ...processCreateParams(params)
3344
+ });
3345
+ };
3346
+ class ZodOptional extends ZodType {
3347
+ _parse(input) {
3348
+ const parsedType = this._getType(input);
3349
+ if (parsedType === ZodParsedType.undefined) {
3350
+ return OK(void 0);
3351
+ }
3352
+ return this._def.innerType._parse(input);
3353
+ }
3354
+ unwrap() {
3355
+ return this._def.innerType;
3356
+ }
3357
+ }
3358
+ ZodOptional.create = (type, params) => {
3359
+ return new ZodOptional({
3360
+ innerType: type,
3361
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3362
+ ...processCreateParams(params)
3363
+ });
3364
+ };
3365
+ class ZodNullable extends ZodType {
3366
+ _parse(input) {
3367
+ const parsedType = this._getType(input);
3368
+ if (parsedType === ZodParsedType.null) {
3369
+ return OK(null);
3370
+ }
3371
+ return this._def.innerType._parse(input);
3372
+ }
3373
+ unwrap() {
3374
+ return this._def.innerType;
3375
+ }
3376
+ }
3377
+ ZodNullable.create = (type, params) => {
3378
+ return new ZodNullable({
3379
+ innerType: type,
3380
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3381
+ ...processCreateParams(params)
3382
+ });
3383
+ };
3384
+ class ZodDefault extends ZodType {
3385
+ _parse(input) {
3386
+ const { ctx } = this._processInputParams(input);
3387
+ let data = ctx.data;
3388
+ if (ctx.parsedType === ZodParsedType.undefined) {
3389
+ data = this._def.defaultValue();
3390
+ }
3391
+ return this._def.innerType._parse({
3392
+ data,
3393
+ path: ctx.path,
3394
+ parent: ctx
3395
+ });
3396
+ }
3397
+ removeDefault() {
3398
+ return this._def.innerType;
3399
+ }
3400
+ }
3401
+ ZodDefault.create = (type, params) => {
3402
+ return new ZodDefault({
3403
+ innerType: type,
3404
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3405
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3406
+ ...processCreateParams(params)
3407
+ });
3408
+ };
3409
+ class ZodCatch extends ZodType {
3410
+ _parse(input) {
3411
+ const { ctx } = this._processInputParams(input);
3412
+ const newCtx = {
3413
+ ...ctx,
3414
+ common: {
3415
+ ...ctx.common,
3416
+ issues: []
3417
+ }
3418
+ };
3419
+ const result = this._def.innerType._parse({
3420
+ data: newCtx.data,
3421
+ path: newCtx.path,
3422
+ parent: {
3423
+ ...newCtx
3424
+ }
3425
+ });
3426
+ if (isAsync(result)) {
3427
+ return result.then((result2) => {
3428
+ return {
3429
+ status: "valid",
3430
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
3431
+ get error() {
3432
+ return new ZodError(newCtx.common.issues);
3433
+ },
3434
+ input: newCtx.data
3435
+ })
3436
+ };
3437
+ });
3438
+ } else {
3439
+ return {
3440
+ status: "valid",
3441
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3442
+ get error() {
3443
+ return new ZodError(newCtx.common.issues);
3444
+ },
3445
+ input: newCtx.data
3446
+ })
3447
+ };
3448
+ }
3449
+ }
3450
+ removeCatch() {
3451
+ return this._def.innerType;
3452
+ }
3453
+ }
3454
+ ZodCatch.create = (type, params) => {
3455
+ return new ZodCatch({
3456
+ innerType: type,
3457
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3458
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3459
+ ...processCreateParams(params)
3460
+ });
3461
+ };
3462
+ class ZodNaN extends ZodType {
3463
+ _parse(input) {
3464
+ const parsedType = this._getType(input);
3465
+ if (parsedType !== ZodParsedType.nan) {
3466
+ const ctx = this._getOrReturnCtx(input);
3467
+ addIssueToContext(ctx, {
3468
+ code: ZodIssueCode.invalid_type,
3469
+ expected: ZodParsedType.nan,
3470
+ received: ctx.parsedType
3471
+ });
3472
+ return INVALID;
3473
+ }
3474
+ return { status: "valid", value: input.data };
3475
+ }
3476
+ }
3477
+ ZodNaN.create = (params) => {
3478
+ return new ZodNaN({
3479
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3480
+ ...processCreateParams(params)
3481
+ });
3482
+ };
3483
+ class ZodBranded extends ZodType {
3484
+ _parse(input) {
3485
+ const { ctx } = this._processInputParams(input);
3486
+ const data = ctx.data;
3487
+ return this._def.type._parse({
3488
+ data,
3489
+ path: ctx.path,
3490
+ parent: ctx
3491
+ });
3492
+ }
3493
+ unwrap() {
3494
+ return this._def.type;
3495
+ }
3496
+ }
3497
+ class ZodPipeline extends ZodType {
3498
+ _parse(input) {
3499
+ const { status, ctx } = this._processInputParams(input);
3500
+ if (ctx.common.async) {
3501
+ const handleAsync = async () => {
3502
+ const inResult = await this._def.in._parseAsync({
3503
+ data: ctx.data,
3504
+ path: ctx.path,
3505
+ parent: ctx
3506
+ });
3507
+ if (inResult.status === "aborted")
3508
+ return INVALID;
3509
+ if (inResult.status === "dirty") {
3510
+ status.dirty();
3511
+ return DIRTY(inResult.value);
3512
+ } else {
3513
+ return this._def.out._parseAsync({
3514
+ data: inResult.value,
3515
+ path: ctx.path,
3516
+ parent: ctx
3517
+ });
3518
+ }
3519
+ };
3520
+ return handleAsync();
3521
+ } else {
3522
+ const inResult = this._def.in._parseSync({
3523
+ data: ctx.data,
3524
+ path: ctx.path,
3525
+ parent: ctx
3526
+ });
3527
+ if (inResult.status === "aborted")
3528
+ return INVALID;
3529
+ if (inResult.status === "dirty") {
3530
+ status.dirty();
3531
+ return {
3532
+ status: "dirty",
3533
+ value: inResult.value
3534
+ };
3535
+ } else {
3536
+ return this._def.out._parseSync({
3537
+ data: inResult.value,
3538
+ path: ctx.path,
3539
+ parent: ctx
3540
+ });
3541
+ }
3542
+ }
3543
+ }
3544
+ static create(a, b) {
3545
+ return new ZodPipeline({
3546
+ in: a,
3547
+ out: b,
3548
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3549
+ });
3550
+ }
3551
+ }
3552
+ class ZodReadonly extends ZodType {
3553
+ _parse(input) {
3554
+ const result = this._def.innerType._parse(input);
3555
+ const freeze = (data) => {
3556
+ if (isValid(data)) {
3557
+ data.value = Object.freeze(data.value);
3558
+ }
3559
+ return data;
3560
+ };
3561
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3562
+ }
3563
+ unwrap() {
3564
+ return this._def.innerType;
3565
+ }
3566
+ }
3567
+ ZodReadonly.create = (type, params) => {
3568
+ return new ZodReadonly({
3569
+ innerType: type,
3570
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3571
+ ...processCreateParams(params)
3572
+ });
3573
+ };
3574
+ var ZodFirstPartyTypeKind;
3575
+ (function(ZodFirstPartyTypeKind2) {
3576
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3577
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3578
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3579
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3580
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3581
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3582
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3583
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3584
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3585
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3586
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3587
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3588
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3589
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3590
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3591
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3592
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3593
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3594
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3595
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3596
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3597
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3598
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3599
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3600
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3601
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3602
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3603
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3604
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3605
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3606
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3607
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3608
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3609
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3610
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3611
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3612
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3613
+ const stringType = ZodString.create;
3614
+ const unknownType = ZodUnknown.create;
3615
+ ZodNever.create;
3616
+ const arrayType = ZodArray.create;
3617
+ const objectType = ZodObject.create;
3618
+ ZodUnion.create;
3619
+ ZodIntersection.create;
3620
+ ZodTuple.create;
3621
+ const recordType = ZodRecord.create;
3622
+ const literalType = ZodLiteral.create;
3623
+ ZodEnum.create;
3624
+ ZodPromise.create;
3625
+ ZodOptional.create;
3626
+ ZodNullable.create;
3627
+ export {
3628
+ arrayType as a,
3629
+ literalType as l,
3630
+ objectType as o,
3631
+ recordType as r,
3632
+ stringType as s,
3633
+ unknownType as u
3634
+ };