@slicemachine/manager 0.20.8-beta.1 → 0.20.8-beta.2

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