better-call 1.0.0-beta.3 → 1.0.0-beta.4

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