@tahanabavi/typefetch 1.1.0 → 1.2.1

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