modality-kit 0.1.11 → 0.1.13

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