@karmaniverous/jeeves-meta-openclaw 0.13.2 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -593,6 +593,4294 @@ function registerMetaTools(api, client, descriptor) {
593
593
  }
594
594
  }
595
595
 
596
+ var _a$1;
597
+ function $constructor(name, initializer, params) {
598
+ function init(inst, def) {
599
+ if (!inst._zod) {
600
+ Object.defineProperty(inst, "_zod", {
601
+ value: {
602
+ def,
603
+ constr: _,
604
+ traits: new Set(),
605
+ },
606
+ enumerable: false,
607
+ });
608
+ }
609
+ if (inst._zod.traits.has(name)) {
610
+ return;
611
+ }
612
+ inst._zod.traits.add(name);
613
+ initializer(inst, def);
614
+ // support prototype modifications
615
+ const proto = _.prototype;
616
+ const keys = Object.keys(proto);
617
+ for (let i = 0; i < keys.length; i++) {
618
+ const k = keys[i];
619
+ if (!(k in inst)) {
620
+ inst[k] = proto[k].bind(inst);
621
+ }
622
+ }
623
+ }
624
+ // doesn't work if Parent has a constructor with arguments
625
+ const Parent = params?.Parent ?? Object;
626
+ class Definition extends Parent {
627
+ }
628
+ Object.defineProperty(Definition, "name", { value: name });
629
+ function _(def) {
630
+ var _a;
631
+ const inst = params?.Parent ? new Definition() : this;
632
+ init(inst, def);
633
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
634
+ for (const fn of inst._zod.deferred) {
635
+ fn();
636
+ }
637
+ return inst;
638
+ }
639
+ Object.defineProperty(_, "init", { value: init });
640
+ Object.defineProperty(_, Symbol.hasInstance, {
641
+ value: (inst) => {
642
+ if (params?.Parent && inst instanceof params.Parent)
643
+ return true;
644
+ return inst?._zod?.traits?.has(name);
645
+ },
646
+ });
647
+ Object.defineProperty(_, "name", { value: name });
648
+ return _;
649
+ }
650
+ class $ZodAsyncError extends Error {
651
+ constructor() {
652
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
653
+ }
654
+ }
655
+ class $ZodEncodeError extends Error {
656
+ constructor(name) {
657
+ super(`Encountered unidirectional transform during encode: ${name}`);
658
+ this.name = "ZodEncodeError";
659
+ }
660
+ }
661
+ (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
662
+ const globalConfig = globalThis.__zod_globalConfig;
663
+ function config(newConfig) {
664
+ return globalConfig;
665
+ }
666
+
667
+ function getEnumValues(entries) {
668
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
669
+ const values = Object.entries(entries)
670
+ .filter(([k, _]) => numericValues.indexOf(+k) === -1)
671
+ .map(([_, v]) => v);
672
+ return values;
673
+ }
674
+ function jsonStringifyReplacer(_, value) {
675
+ if (typeof value === "bigint")
676
+ return value.toString();
677
+ return value;
678
+ }
679
+ function cached(getter) {
680
+ return {
681
+ get value() {
682
+ {
683
+ const value = getter();
684
+ Object.defineProperty(this, "value", { value });
685
+ return value;
686
+ }
687
+ },
688
+ };
689
+ }
690
+ function nullish(input) {
691
+ return input === null || input === undefined;
692
+ }
693
+ function cleanRegex(source) {
694
+ const start = source.startsWith("^") ? 1 : 0;
695
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
696
+ return source.slice(start, end);
697
+ }
698
+ const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
699
+ function defineLazy(object, key, getter) {
700
+ let value = undefined;
701
+ Object.defineProperty(object, key, {
702
+ get() {
703
+ if (value === EVALUATING) {
704
+ // Circular reference detected, return undefined to break the cycle
705
+ return undefined;
706
+ }
707
+ if (value === undefined) {
708
+ value = EVALUATING;
709
+ value = getter();
710
+ }
711
+ return value;
712
+ },
713
+ set(v) {
714
+ Object.defineProperty(object, key, {
715
+ value: v,
716
+ // configurable: true,
717
+ });
718
+ // object[key] = v;
719
+ },
720
+ configurable: true,
721
+ });
722
+ }
723
+ function assignProp(target, prop, value) {
724
+ Object.defineProperty(target, prop, {
725
+ value,
726
+ writable: true,
727
+ enumerable: true,
728
+ configurable: true,
729
+ });
730
+ }
731
+ function mergeDefs(...defs) {
732
+ const mergedDescriptors = {};
733
+ for (const def of defs) {
734
+ const descriptors = Object.getOwnPropertyDescriptors(def);
735
+ Object.assign(mergedDescriptors, descriptors);
736
+ }
737
+ return Object.defineProperties({}, mergedDescriptors);
738
+ }
739
+ function esc(str) {
740
+ return JSON.stringify(str);
741
+ }
742
+ function slugify(input) {
743
+ return input
744
+ .toLowerCase()
745
+ .trim()
746
+ .replace(/[^\w\s-]/g, "")
747
+ .replace(/[\s_-]+/g, "-")
748
+ .replace(/^-+|-+$/g, "");
749
+ }
750
+ const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
751
+ function isObject(data) {
752
+ return typeof data === "object" && data !== null && !Array.isArray(data);
753
+ }
754
+ const allowsEval = /* @__PURE__*/ cached(() => {
755
+ // Skip the probe under `jitless`: strict CSPs report the caught `new Function`
756
+ // as a `securitypolicyviolation` even though the throw is swallowed.
757
+ if (globalConfig.jitless) {
758
+ return false;
759
+ }
760
+ // @ts-ignore
761
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
762
+ return false;
763
+ }
764
+ try {
765
+ const F = Function;
766
+ new F("");
767
+ return true;
768
+ }
769
+ catch (_) {
770
+ return false;
771
+ }
772
+ });
773
+ function isPlainObject(o) {
774
+ if (isObject(o) === false)
775
+ return false;
776
+ // modified constructor
777
+ const ctor = o.constructor;
778
+ if (ctor === undefined)
779
+ return true;
780
+ if (typeof ctor !== "function")
781
+ return true;
782
+ // modified prototype
783
+ const prot = ctor.prototype;
784
+ if (isObject(prot) === false)
785
+ return false;
786
+ // ctor doesn't have static `isPrototypeOf`
787
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
788
+ return false;
789
+ }
790
+ return true;
791
+ }
792
+ function shallowClone(o) {
793
+ if (isPlainObject(o))
794
+ return { ...o };
795
+ if (Array.isArray(o))
796
+ return [...o];
797
+ if (o instanceof Map)
798
+ return new Map(o);
799
+ if (o instanceof Set)
800
+ return new Set(o);
801
+ return o;
802
+ }
803
+ const propertyKeyTypes = /* @__PURE__*/ new Set(["string", "number", "symbol"]);
804
+ function escapeRegex(str) {
805
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
806
+ }
807
+ // zod-specific utils
808
+ function clone(inst, def, params) {
809
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
810
+ if (!def || params?.parent)
811
+ cl._zod.parent = inst;
812
+ return cl;
813
+ }
814
+ function normalizeParams(_params) {
815
+ const params = _params;
816
+ if (!params)
817
+ return {};
818
+ if (typeof params === "string")
819
+ return { error: () => params };
820
+ if (params?.message !== undefined) {
821
+ if (params?.error !== undefined)
822
+ throw new Error("Cannot specify both `message` and `error` params");
823
+ params.error = params.message;
824
+ }
825
+ delete params.message;
826
+ if (typeof params.error === "string")
827
+ return { ...params, error: () => params.error };
828
+ return params;
829
+ }
830
+ function optionalKeys(shape) {
831
+ return Object.keys(shape).filter((k) => {
832
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
833
+ });
834
+ }
835
+ function pick(schema, mask) {
836
+ const currDef = schema._zod.def;
837
+ const checks = currDef.checks;
838
+ const hasChecks = checks && checks.length > 0;
839
+ if (hasChecks) {
840
+ throw new Error(".pick() cannot be used on object schemas containing refinements");
841
+ }
842
+ const def = mergeDefs(schema._zod.def, {
843
+ get shape() {
844
+ const newShape = {};
845
+ for (const key in mask) {
846
+ if (!(key in currDef.shape)) {
847
+ throw new Error(`Unrecognized key: "${key}"`);
848
+ }
849
+ if (!mask[key])
850
+ continue;
851
+ newShape[key] = currDef.shape[key];
852
+ }
853
+ assignProp(this, "shape", newShape); // self-caching
854
+ return newShape;
855
+ },
856
+ checks: [],
857
+ });
858
+ return clone(schema, def);
859
+ }
860
+ function omit(schema, mask) {
861
+ const currDef = schema._zod.def;
862
+ const checks = currDef.checks;
863
+ const hasChecks = checks && checks.length > 0;
864
+ if (hasChecks) {
865
+ throw new Error(".omit() cannot be used on object schemas containing refinements");
866
+ }
867
+ const def = mergeDefs(schema._zod.def, {
868
+ get shape() {
869
+ const newShape = { ...schema._zod.def.shape };
870
+ for (const key in mask) {
871
+ if (!(key in currDef.shape)) {
872
+ throw new Error(`Unrecognized key: "${key}"`);
873
+ }
874
+ if (!mask[key])
875
+ continue;
876
+ delete newShape[key];
877
+ }
878
+ assignProp(this, "shape", newShape); // self-caching
879
+ return newShape;
880
+ },
881
+ checks: [],
882
+ });
883
+ return clone(schema, def);
884
+ }
885
+ function extend(schema, shape) {
886
+ if (!isPlainObject(shape)) {
887
+ throw new Error("Invalid input to extend: expected a plain object");
888
+ }
889
+ const checks = schema._zod.def.checks;
890
+ const hasChecks = checks && checks.length > 0;
891
+ if (hasChecks) {
892
+ // Only throw if new shape overlaps with existing shape
893
+ // Use getOwnPropertyDescriptor to check key existence without accessing values
894
+ const existingShape = schema._zod.def.shape;
895
+ for (const key in shape) {
896
+ if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
897
+ throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
898
+ }
899
+ }
900
+ }
901
+ const def = mergeDefs(schema._zod.def, {
902
+ get shape() {
903
+ const _shape = { ...schema._zod.def.shape, ...shape };
904
+ assignProp(this, "shape", _shape); // self-caching
905
+ return _shape;
906
+ },
907
+ });
908
+ return clone(schema, def);
909
+ }
910
+ function safeExtend(schema, shape) {
911
+ if (!isPlainObject(shape)) {
912
+ throw new Error("Invalid input to safeExtend: expected a plain object");
913
+ }
914
+ const def = mergeDefs(schema._zod.def, {
915
+ get shape() {
916
+ const _shape = { ...schema._zod.def.shape, ...shape };
917
+ assignProp(this, "shape", _shape); // self-caching
918
+ return _shape;
919
+ },
920
+ });
921
+ return clone(schema, def);
922
+ }
923
+ function merge(a, b) {
924
+ if (a._zod.def.checks?.length) {
925
+ throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
926
+ }
927
+ const def = mergeDefs(a._zod.def, {
928
+ get shape() {
929
+ const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
930
+ assignProp(this, "shape", _shape); // self-caching
931
+ return _shape;
932
+ },
933
+ get catchall() {
934
+ return b._zod.def.catchall;
935
+ },
936
+ checks: b._zod.def.checks ?? [],
937
+ });
938
+ return clone(a, def);
939
+ }
940
+ function partial(Class, schema, mask) {
941
+ const currDef = schema._zod.def;
942
+ const checks = currDef.checks;
943
+ const hasChecks = checks && checks.length > 0;
944
+ if (hasChecks) {
945
+ throw new Error(".partial() cannot be used on object schemas containing refinements");
946
+ }
947
+ const def = mergeDefs(schema._zod.def, {
948
+ get shape() {
949
+ const oldShape = schema._zod.def.shape;
950
+ const shape = { ...oldShape };
951
+ if (mask) {
952
+ for (const key in mask) {
953
+ if (!(key in oldShape)) {
954
+ throw new Error(`Unrecognized key: "${key}"`);
955
+ }
956
+ if (!mask[key])
957
+ continue;
958
+ // if (oldShape[key]!._zod.optin === "optional") continue;
959
+ shape[key] = Class
960
+ ? new Class({
961
+ type: "optional",
962
+ innerType: oldShape[key],
963
+ })
964
+ : oldShape[key];
965
+ }
966
+ }
967
+ else {
968
+ for (const key in oldShape) {
969
+ // if (oldShape[key]!._zod.optin === "optional") continue;
970
+ shape[key] = Class
971
+ ? new Class({
972
+ type: "optional",
973
+ innerType: oldShape[key],
974
+ })
975
+ : oldShape[key];
976
+ }
977
+ }
978
+ assignProp(this, "shape", shape); // self-caching
979
+ return shape;
980
+ },
981
+ checks: [],
982
+ });
983
+ return clone(schema, def);
984
+ }
985
+ function required(Class, schema, mask) {
986
+ const def = mergeDefs(schema._zod.def, {
987
+ get shape() {
988
+ const oldShape = schema._zod.def.shape;
989
+ const shape = { ...oldShape };
990
+ if (mask) {
991
+ for (const key in mask) {
992
+ if (!(key in shape)) {
993
+ throw new Error(`Unrecognized key: "${key}"`);
994
+ }
995
+ if (!mask[key])
996
+ continue;
997
+ // overwrite with non-optional
998
+ shape[key] = new Class({
999
+ type: "nonoptional",
1000
+ innerType: oldShape[key],
1001
+ });
1002
+ }
1003
+ }
1004
+ else {
1005
+ for (const key in oldShape) {
1006
+ // overwrite with non-optional
1007
+ shape[key] = new Class({
1008
+ type: "nonoptional",
1009
+ innerType: oldShape[key],
1010
+ });
1011
+ }
1012
+ }
1013
+ assignProp(this, "shape", shape); // self-caching
1014
+ return shape;
1015
+ },
1016
+ });
1017
+ return clone(schema, def);
1018
+ }
1019
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
1020
+ function aborted(x, startIndex = 0) {
1021
+ if (x.aborted === true)
1022
+ return true;
1023
+ for (let i = startIndex; i < x.issues.length; i++) {
1024
+ if (x.issues[i]?.continue !== true) {
1025
+ return true;
1026
+ }
1027
+ }
1028
+ return false;
1029
+ }
1030
+ // Checks for explicit abort (continue === false), as opposed to implicit abort (continue === undefined).
1031
+ // Used to respect `abort: true` in .refine() even for checks that have a `when` function.
1032
+ function explicitlyAborted(x, startIndex = 0) {
1033
+ if (x.aborted === true)
1034
+ return true;
1035
+ for (let i = startIndex; i < x.issues.length; i++) {
1036
+ if (x.issues[i]?.continue === false) {
1037
+ return true;
1038
+ }
1039
+ }
1040
+ return false;
1041
+ }
1042
+ function prefixIssues(path, issues) {
1043
+ return issues.map((iss) => {
1044
+ var _a;
1045
+ (_a = iss).path ?? (_a.path = []);
1046
+ iss.path.unshift(path);
1047
+ return iss;
1048
+ });
1049
+ }
1050
+ function unwrapMessage(message) {
1051
+ return typeof message === "string" ? message : message?.message;
1052
+ }
1053
+ function finalizeIssue(iss, ctx, config) {
1054
+ const message = iss.message
1055
+ ? iss.message
1056
+ : (unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
1057
+ unwrapMessage(ctx?.error?.(iss)) ??
1058
+ unwrapMessage(config.customError?.(iss)) ??
1059
+ unwrapMessage(config.localeError?.(iss)) ??
1060
+ "Invalid input");
1061
+ const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
1062
+ rest.path ?? (rest.path = []);
1063
+ rest.message = message;
1064
+ if (ctx?.reportInput) {
1065
+ rest.input = _input;
1066
+ }
1067
+ return rest;
1068
+ }
1069
+ function getLengthableOrigin(input) {
1070
+ if (Array.isArray(input))
1071
+ return "array";
1072
+ if (typeof input === "string")
1073
+ return "string";
1074
+ return "unknown";
1075
+ }
1076
+ function issue(...args) {
1077
+ const [iss, input, inst] = args;
1078
+ if (typeof iss === "string") {
1079
+ return {
1080
+ message: iss,
1081
+ code: "custom",
1082
+ input,
1083
+ inst,
1084
+ };
1085
+ }
1086
+ return { ...iss };
1087
+ }
1088
+
1089
+ const initializer$1 = (inst, def) => {
1090
+ inst.name = "$ZodError";
1091
+ Object.defineProperty(inst, "_zod", {
1092
+ value: inst._zod,
1093
+ enumerable: false,
1094
+ });
1095
+ Object.defineProperty(inst, "issues", {
1096
+ value: def,
1097
+ enumerable: false,
1098
+ });
1099
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
1100
+ Object.defineProperty(inst, "toString", {
1101
+ value: () => inst.message,
1102
+ enumerable: false,
1103
+ });
1104
+ };
1105
+ const $ZodError = $constructor("$ZodError", initializer$1);
1106
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
1107
+ function flattenError(error, mapper = (issue) => issue.message) {
1108
+ const fieldErrors = {};
1109
+ const formErrors = [];
1110
+ for (const sub of error.issues) {
1111
+ if (sub.path.length > 0) {
1112
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1113
+ fieldErrors[sub.path[0]].push(mapper(sub));
1114
+ }
1115
+ else {
1116
+ formErrors.push(mapper(sub));
1117
+ }
1118
+ }
1119
+ return { formErrors, fieldErrors };
1120
+ }
1121
+ function formatError(error, mapper = (issue) => issue.message) {
1122
+ const fieldErrors = { _errors: [] };
1123
+ const processError = (error, path = []) => {
1124
+ for (const issue of error.issues) {
1125
+ if (issue.code === "invalid_union" && issue.errors.length) {
1126
+ issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
1127
+ }
1128
+ else if (issue.code === "invalid_key") {
1129
+ processError({ issues: issue.issues }, [...path, ...issue.path]);
1130
+ }
1131
+ else if (issue.code === "invalid_element") {
1132
+ processError({ issues: issue.issues }, [...path, ...issue.path]);
1133
+ }
1134
+ else {
1135
+ const fullpath = [...path, ...issue.path];
1136
+ if (fullpath.length === 0) {
1137
+ fieldErrors._errors.push(mapper(issue));
1138
+ }
1139
+ else {
1140
+ let curr = fieldErrors;
1141
+ let i = 0;
1142
+ while (i < fullpath.length) {
1143
+ const el = fullpath[i];
1144
+ const terminal = i === fullpath.length - 1;
1145
+ if (!terminal) {
1146
+ curr[el] = curr[el] || { _errors: [] };
1147
+ }
1148
+ else {
1149
+ curr[el] = curr[el] || { _errors: [] };
1150
+ curr[el]._errors.push(mapper(issue));
1151
+ }
1152
+ curr = curr[el];
1153
+ i++;
1154
+ }
1155
+ }
1156
+ }
1157
+ }
1158
+ };
1159
+ processError(error);
1160
+ return fieldErrors;
1161
+ }
1162
+
1163
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
1164
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
1165
+ const result = schema._zod.run({ value, issues: [] }, ctx);
1166
+ if (result instanceof Promise) {
1167
+ throw new $ZodAsyncError();
1168
+ }
1169
+ if (result.issues.length) {
1170
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1171
+ captureStackTrace(e, _params?.callee);
1172
+ throw e;
1173
+ }
1174
+ return result.value;
1175
+ };
1176
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
1177
+ const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
1178
+ let result = schema._zod.run({ value, issues: [] }, ctx);
1179
+ if (result instanceof Promise)
1180
+ result = await result;
1181
+ if (result.issues.length) {
1182
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1183
+ captureStackTrace(e, params?.callee);
1184
+ throw e;
1185
+ }
1186
+ return result.value;
1187
+ };
1188
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
1189
+ const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
1190
+ const result = schema._zod.run({ value, issues: [] }, ctx);
1191
+ if (result instanceof Promise) {
1192
+ throw new $ZodAsyncError();
1193
+ }
1194
+ return result.issues.length
1195
+ ? {
1196
+ success: false,
1197
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
1198
+ }
1199
+ : { success: true, data: result.value };
1200
+ };
1201
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
1202
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
1203
+ const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
1204
+ let result = schema._zod.run({ value, issues: [] }, ctx);
1205
+ if (result instanceof Promise)
1206
+ result = await result;
1207
+ return result.issues.length
1208
+ ? {
1209
+ success: false,
1210
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
1211
+ }
1212
+ : { success: true, data: result.value };
1213
+ };
1214
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
1215
+ const _encode = (_Err) => (schema, value, _ctx) => {
1216
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
1217
+ return _parse(_Err)(schema, value, ctx);
1218
+ };
1219
+ const _decode = (_Err) => (schema, value, _ctx) => {
1220
+ return _parse(_Err)(schema, value, _ctx);
1221
+ };
1222
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
1223
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
1224
+ return _parseAsync(_Err)(schema, value, ctx);
1225
+ };
1226
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
1227
+ return _parseAsync(_Err)(schema, value, _ctx);
1228
+ };
1229
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
1230
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
1231
+ return _safeParse(_Err)(schema, value, ctx);
1232
+ };
1233
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
1234
+ return _safeParse(_Err)(schema, value, _ctx);
1235
+ };
1236
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
1237
+ const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
1238
+ return _safeParseAsync(_Err)(schema, value, ctx);
1239
+ };
1240
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
1241
+ return _safeParseAsync(_Err)(schema, value, _ctx);
1242
+ };
1243
+
1244
+ /**
1245
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1246
+ * (timestamps embedded in the id). Use {@link cuid2} instead.
1247
+ * See https://github.com/paralleldrive/cuid.
1248
+ */
1249
+ const cuid = /^[cC][0-9a-z]{6,}$/;
1250
+ const cuid2 = /^[0-9a-z]+$/;
1251
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
1252
+ const xid = /^[0-9a-vA-V]{20}$/;
1253
+ const ksuid = /^[A-Za-z0-9]{27}$/;
1254
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
1255
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
1256
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
1257
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
1258
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
1259
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
1260
+ *
1261
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
1262
+ const uuid = (version) => {
1263
+ if (!version)
1264
+ return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
1265
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
1266
+ };
1267
+ /** Practical email validation */
1268
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
1269
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
1270
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1271
+ function emoji() {
1272
+ return new RegExp(_emoji$1, "u");
1273
+ }
1274
+ const ipv4 = /^(?:(?: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])$/;
1275
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){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}|:))$/;
1276
+ const cidrv4 = /^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/;
1277
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
1278
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
1279
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
1280
+ const base64url = /^[A-Za-z0-9_-]*$/;
1281
+ const httpProtocol = /^https?$/;
1282
+ // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
1283
+ // E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
1284
+ const e164 = /^\+[1-9]\d{6,14}$/;
1285
+ // const dateSource = `((\\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])))`;
1286
+ const dateSource = `(?:(?:\\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])))`;
1287
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
1288
+ function timeSource(args) {
1289
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
1290
+ const regex = typeof args.precision === "number"
1291
+ ? args.precision === -1
1292
+ ? `${hhmm}`
1293
+ : args.precision === 0
1294
+ ? `${hhmm}:[0-5]\\d`
1295
+ : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
1296
+ : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
1297
+ return regex;
1298
+ }
1299
+ function time$1(args) {
1300
+ return new RegExp(`^${timeSource(args)}$`);
1301
+ }
1302
+ // Adapted from https://stackoverflow.com/a/3143231
1303
+ function datetime$1(args) {
1304
+ const time = timeSource({ precision: args.precision });
1305
+ const opts = ["Z"];
1306
+ if (args.local)
1307
+ opts.push("");
1308
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
1309
+ if (args.offset)
1310
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
1311
+ const timeRegex = `${time}(?:${opts.join("|")})`;
1312
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
1313
+ }
1314
+ const string$1 = (params) => {
1315
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
1316
+ return new RegExp(`^${regex}$`);
1317
+ };
1318
+ // regex for string with no uppercase letters
1319
+ const lowercase = /^[^A-Z]*$/;
1320
+ // regex for string with no lowercase letters
1321
+ const uppercase = /^[^a-z]*$/;
1322
+
1323
+ // import { $ZodType } from "./schemas.js";
1324
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
1325
+ var _a;
1326
+ inst._zod ?? (inst._zod = {});
1327
+ inst._zod.def = def;
1328
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
1329
+ });
1330
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
1331
+ var _a;
1332
+ $ZodCheck.init(inst, def);
1333
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1334
+ const val = payload.value;
1335
+ return !nullish(val) && val.length !== undefined;
1336
+ });
1337
+ inst._zod.onattach.push((inst) => {
1338
+ const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
1339
+ if (def.maximum < curr)
1340
+ inst._zod.bag.maximum = def.maximum;
1341
+ });
1342
+ inst._zod.check = (payload) => {
1343
+ const input = payload.value;
1344
+ const length = input.length;
1345
+ if (length <= def.maximum)
1346
+ return;
1347
+ const origin = getLengthableOrigin(input);
1348
+ payload.issues.push({
1349
+ origin,
1350
+ code: "too_big",
1351
+ maximum: def.maximum,
1352
+ inclusive: true,
1353
+ input,
1354
+ inst,
1355
+ continue: !def.abort,
1356
+ });
1357
+ };
1358
+ });
1359
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
1360
+ var _a;
1361
+ $ZodCheck.init(inst, def);
1362
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1363
+ const val = payload.value;
1364
+ return !nullish(val) && val.length !== undefined;
1365
+ });
1366
+ inst._zod.onattach.push((inst) => {
1367
+ const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
1368
+ if (def.minimum > curr)
1369
+ inst._zod.bag.minimum = def.minimum;
1370
+ });
1371
+ inst._zod.check = (payload) => {
1372
+ const input = payload.value;
1373
+ const length = input.length;
1374
+ if (length >= def.minimum)
1375
+ return;
1376
+ const origin = getLengthableOrigin(input);
1377
+ payload.issues.push({
1378
+ origin,
1379
+ code: "too_small",
1380
+ minimum: def.minimum,
1381
+ inclusive: true,
1382
+ input,
1383
+ inst,
1384
+ continue: !def.abort,
1385
+ });
1386
+ };
1387
+ });
1388
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
1389
+ var _a;
1390
+ $ZodCheck.init(inst, def);
1391
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1392
+ const val = payload.value;
1393
+ return !nullish(val) && val.length !== undefined;
1394
+ });
1395
+ inst._zod.onattach.push((inst) => {
1396
+ const bag = inst._zod.bag;
1397
+ bag.minimum = def.length;
1398
+ bag.maximum = def.length;
1399
+ bag.length = def.length;
1400
+ });
1401
+ inst._zod.check = (payload) => {
1402
+ const input = payload.value;
1403
+ const length = input.length;
1404
+ if (length === def.length)
1405
+ return;
1406
+ const origin = getLengthableOrigin(input);
1407
+ const tooBig = length > def.length;
1408
+ payload.issues.push({
1409
+ origin,
1410
+ ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
1411
+ inclusive: true,
1412
+ exact: true,
1413
+ input: payload.value,
1414
+ inst,
1415
+ continue: !def.abort,
1416
+ });
1417
+ };
1418
+ });
1419
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
1420
+ var _a, _b;
1421
+ $ZodCheck.init(inst, def);
1422
+ inst._zod.onattach.push((inst) => {
1423
+ const bag = inst._zod.bag;
1424
+ bag.format = def.format;
1425
+ if (def.pattern) {
1426
+ bag.patterns ?? (bag.patterns = new Set());
1427
+ bag.patterns.add(def.pattern);
1428
+ }
1429
+ });
1430
+ if (def.pattern)
1431
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
1432
+ def.pattern.lastIndex = 0;
1433
+ if (def.pattern.test(payload.value))
1434
+ return;
1435
+ payload.issues.push({
1436
+ origin: "string",
1437
+ code: "invalid_format",
1438
+ format: def.format,
1439
+ input: payload.value,
1440
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
1441
+ inst,
1442
+ continue: !def.abort,
1443
+ });
1444
+ });
1445
+ else
1446
+ (_b = inst._zod).check ?? (_b.check = () => { });
1447
+ });
1448
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
1449
+ $ZodCheckStringFormat.init(inst, def);
1450
+ inst._zod.check = (payload) => {
1451
+ def.pattern.lastIndex = 0;
1452
+ if (def.pattern.test(payload.value))
1453
+ return;
1454
+ payload.issues.push({
1455
+ origin: "string",
1456
+ code: "invalid_format",
1457
+ format: "regex",
1458
+ input: payload.value,
1459
+ pattern: def.pattern.toString(),
1460
+ inst,
1461
+ continue: !def.abort,
1462
+ });
1463
+ };
1464
+ });
1465
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
1466
+ def.pattern ?? (def.pattern = lowercase);
1467
+ $ZodCheckStringFormat.init(inst, def);
1468
+ });
1469
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
1470
+ def.pattern ?? (def.pattern = uppercase);
1471
+ $ZodCheckStringFormat.init(inst, def);
1472
+ });
1473
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
1474
+ $ZodCheck.init(inst, def);
1475
+ const escapedRegex = escapeRegex(def.includes);
1476
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
1477
+ def.pattern = pattern;
1478
+ inst._zod.onattach.push((inst) => {
1479
+ const bag = inst._zod.bag;
1480
+ bag.patterns ?? (bag.patterns = new Set());
1481
+ bag.patterns.add(pattern);
1482
+ });
1483
+ inst._zod.check = (payload) => {
1484
+ if (payload.value.includes(def.includes, def.position))
1485
+ return;
1486
+ payload.issues.push({
1487
+ origin: "string",
1488
+ code: "invalid_format",
1489
+ format: "includes",
1490
+ includes: def.includes,
1491
+ input: payload.value,
1492
+ inst,
1493
+ continue: !def.abort,
1494
+ });
1495
+ };
1496
+ });
1497
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
1498
+ $ZodCheck.init(inst, def);
1499
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
1500
+ def.pattern ?? (def.pattern = pattern);
1501
+ inst._zod.onattach.push((inst) => {
1502
+ const bag = inst._zod.bag;
1503
+ bag.patterns ?? (bag.patterns = new Set());
1504
+ bag.patterns.add(pattern);
1505
+ });
1506
+ inst._zod.check = (payload) => {
1507
+ if (payload.value.startsWith(def.prefix))
1508
+ return;
1509
+ payload.issues.push({
1510
+ origin: "string",
1511
+ code: "invalid_format",
1512
+ format: "starts_with",
1513
+ prefix: def.prefix,
1514
+ input: payload.value,
1515
+ inst,
1516
+ continue: !def.abort,
1517
+ });
1518
+ };
1519
+ });
1520
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
1521
+ $ZodCheck.init(inst, def);
1522
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
1523
+ def.pattern ?? (def.pattern = pattern);
1524
+ inst._zod.onattach.push((inst) => {
1525
+ const bag = inst._zod.bag;
1526
+ bag.patterns ?? (bag.patterns = new Set());
1527
+ bag.patterns.add(pattern);
1528
+ });
1529
+ inst._zod.check = (payload) => {
1530
+ if (payload.value.endsWith(def.suffix))
1531
+ return;
1532
+ payload.issues.push({
1533
+ origin: "string",
1534
+ code: "invalid_format",
1535
+ format: "ends_with",
1536
+ suffix: def.suffix,
1537
+ input: payload.value,
1538
+ inst,
1539
+ continue: !def.abort,
1540
+ });
1541
+ };
1542
+ });
1543
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
1544
+ $ZodCheck.init(inst, def);
1545
+ inst._zod.check = (payload) => {
1546
+ payload.value = def.tx(payload.value);
1547
+ };
1548
+ });
1549
+
1550
+ class Doc {
1551
+ constructor(args = []) {
1552
+ this.content = [];
1553
+ this.indent = 0;
1554
+ if (this)
1555
+ this.args = args;
1556
+ }
1557
+ indented(fn) {
1558
+ this.indent += 1;
1559
+ fn(this);
1560
+ this.indent -= 1;
1561
+ }
1562
+ write(arg) {
1563
+ if (typeof arg === "function") {
1564
+ arg(this, { execution: "sync" });
1565
+ arg(this, { execution: "async" });
1566
+ return;
1567
+ }
1568
+ const content = arg;
1569
+ const lines = content.split("\n").filter((x) => x);
1570
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1571
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1572
+ for (const line of dedented) {
1573
+ this.content.push(line);
1574
+ }
1575
+ }
1576
+ compile() {
1577
+ const F = Function;
1578
+ const args = this?.args;
1579
+ const content = this?.content ?? [``];
1580
+ const lines = [...content.map((x) => ` ${x}`)];
1581
+ // console.log(lines.join("\n"));
1582
+ return new F(...args, lines.join("\n"));
1583
+ }
1584
+ }
1585
+
1586
+ const version = {
1587
+ major: 4,
1588
+ minor: 4,
1589
+ patch: 3,
1590
+ };
1591
+
1592
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1593
+ var _a;
1594
+ inst ?? (inst = {});
1595
+ inst._zod.def = def; // set _def property
1596
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
1597
+ inst._zod.version = version;
1598
+ const checks = [...(inst._zod.def.checks ?? [])];
1599
+ // if inst is itself a checks.$ZodCheck, run it as a check
1600
+ if (inst._zod.traits.has("$ZodCheck")) {
1601
+ checks.unshift(inst);
1602
+ }
1603
+ for (const ch of checks) {
1604
+ for (const fn of ch._zod.onattach) {
1605
+ fn(inst);
1606
+ }
1607
+ }
1608
+ if (checks.length === 0) {
1609
+ // deferred initializer
1610
+ // inst._zod.parse is not yet defined
1611
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
1612
+ inst._zod.deferred?.push(() => {
1613
+ inst._zod.run = inst._zod.parse;
1614
+ });
1615
+ }
1616
+ else {
1617
+ const runChecks = (payload, checks, ctx) => {
1618
+ let isAborted = aborted(payload);
1619
+ let asyncResult;
1620
+ for (const ch of checks) {
1621
+ if (ch._zod.def.when) {
1622
+ if (explicitlyAborted(payload))
1623
+ continue;
1624
+ const shouldRun = ch._zod.def.when(payload);
1625
+ if (!shouldRun)
1626
+ continue;
1627
+ }
1628
+ else if (isAborted) {
1629
+ continue;
1630
+ }
1631
+ const currLen = payload.issues.length;
1632
+ const _ = ch._zod.check(payload);
1633
+ if (_ instanceof Promise && ctx?.async === false) {
1634
+ throw new $ZodAsyncError();
1635
+ }
1636
+ if (asyncResult || _ instanceof Promise) {
1637
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1638
+ await _;
1639
+ const nextLen = payload.issues.length;
1640
+ if (nextLen === currLen)
1641
+ return;
1642
+ if (!isAborted)
1643
+ isAborted = aborted(payload, currLen);
1644
+ });
1645
+ }
1646
+ else {
1647
+ const nextLen = payload.issues.length;
1648
+ if (nextLen === currLen)
1649
+ continue;
1650
+ if (!isAborted)
1651
+ isAborted = aborted(payload, currLen);
1652
+ }
1653
+ }
1654
+ if (asyncResult) {
1655
+ return asyncResult.then(() => {
1656
+ return payload;
1657
+ });
1658
+ }
1659
+ return payload;
1660
+ };
1661
+ const handleCanaryResult = (canary, payload, ctx) => {
1662
+ // abort if the canary is aborted
1663
+ if (aborted(canary)) {
1664
+ canary.aborted = true;
1665
+ return canary;
1666
+ }
1667
+ // run checks first, then
1668
+ const checkResult = runChecks(payload, checks, ctx);
1669
+ if (checkResult instanceof Promise) {
1670
+ if (ctx.async === false)
1671
+ throw new $ZodAsyncError();
1672
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1673
+ }
1674
+ return inst._zod.parse(checkResult, ctx);
1675
+ };
1676
+ inst._zod.run = (payload, ctx) => {
1677
+ if (ctx.skipChecks) {
1678
+ return inst._zod.parse(payload, ctx);
1679
+ }
1680
+ if (ctx.direction === "backward") {
1681
+ // run canary
1682
+ // initial pass (no checks)
1683
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
1684
+ if (canary instanceof Promise) {
1685
+ return canary.then((canary) => {
1686
+ return handleCanaryResult(canary, payload, ctx);
1687
+ });
1688
+ }
1689
+ return handleCanaryResult(canary, payload, ctx);
1690
+ }
1691
+ // forward
1692
+ const result = inst._zod.parse(payload, ctx);
1693
+ if (result instanceof Promise) {
1694
+ if (ctx.async === false)
1695
+ throw new $ZodAsyncError();
1696
+ return result.then((result) => runChecks(result, checks, ctx));
1697
+ }
1698
+ return runChecks(result, checks, ctx);
1699
+ };
1700
+ }
1701
+ // Lazy initialize ~standard to avoid creating objects for every schema
1702
+ defineLazy(inst, "~standard", () => ({
1703
+ validate: (value) => {
1704
+ try {
1705
+ const r = safeParse$1(inst, value);
1706
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1707
+ }
1708
+ catch (_) {
1709
+ return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
1710
+ }
1711
+ },
1712
+ vendor: "zod",
1713
+ version: 1,
1714
+ }));
1715
+ });
1716
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1717
+ $ZodType.init(inst, def);
1718
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
1719
+ inst._zod.parse = (payload, _) => {
1720
+ if (def.coerce)
1721
+ try {
1722
+ payload.value = String(payload.value);
1723
+ }
1724
+ catch (_) { }
1725
+ if (typeof payload.value === "string")
1726
+ return payload;
1727
+ payload.issues.push({
1728
+ expected: "string",
1729
+ code: "invalid_type",
1730
+ input: payload.value,
1731
+ inst,
1732
+ });
1733
+ return payload;
1734
+ };
1735
+ });
1736
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
1737
+ // check initialization must come first
1738
+ $ZodCheckStringFormat.init(inst, def);
1739
+ $ZodString.init(inst, def);
1740
+ });
1741
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
1742
+ def.pattern ?? (def.pattern = guid);
1743
+ $ZodStringFormat.init(inst, def);
1744
+ });
1745
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
1746
+ if (def.version) {
1747
+ const versionMap = {
1748
+ v1: 1,
1749
+ v2: 2,
1750
+ v3: 3,
1751
+ v4: 4,
1752
+ v5: 5,
1753
+ v6: 6,
1754
+ v7: 7,
1755
+ v8: 8,
1756
+ };
1757
+ const v = versionMap[def.version];
1758
+ if (v === undefined)
1759
+ throw new Error(`Invalid UUID version: "${def.version}"`);
1760
+ def.pattern ?? (def.pattern = uuid(v));
1761
+ }
1762
+ else
1763
+ def.pattern ?? (def.pattern = uuid());
1764
+ $ZodStringFormat.init(inst, def);
1765
+ });
1766
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
1767
+ def.pattern ?? (def.pattern = email);
1768
+ $ZodStringFormat.init(inst, def);
1769
+ });
1770
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
1771
+ $ZodStringFormat.init(inst, def);
1772
+ inst._zod.check = (payload) => {
1773
+ try {
1774
+ // Trim whitespace from input
1775
+ const trimmed = payload.value.trim();
1776
+ // When normalize is off, require :// for http/https URLs
1777
+ // This prevents strings like "http:example.com" or "https:/path" from being silently accepted
1778
+ if (!def.normalize && def.protocol?.source === httpProtocol.source) {
1779
+ if (!/^https?:\/\//i.test(trimmed)) {
1780
+ payload.issues.push({
1781
+ code: "invalid_format",
1782
+ format: "url",
1783
+ note: "Invalid URL format",
1784
+ input: payload.value,
1785
+ inst,
1786
+ continue: !def.abort,
1787
+ });
1788
+ return;
1789
+ }
1790
+ }
1791
+ // @ts-ignore
1792
+ const url = new URL(trimmed);
1793
+ if (def.hostname) {
1794
+ def.hostname.lastIndex = 0;
1795
+ if (!def.hostname.test(url.hostname)) {
1796
+ payload.issues.push({
1797
+ code: "invalid_format",
1798
+ format: "url",
1799
+ note: "Invalid hostname",
1800
+ pattern: def.hostname.source,
1801
+ input: payload.value,
1802
+ inst,
1803
+ continue: !def.abort,
1804
+ });
1805
+ }
1806
+ }
1807
+ if (def.protocol) {
1808
+ def.protocol.lastIndex = 0;
1809
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
1810
+ payload.issues.push({
1811
+ code: "invalid_format",
1812
+ format: "url",
1813
+ note: "Invalid protocol",
1814
+ pattern: def.protocol.source,
1815
+ input: payload.value,
1816
+ inst,
1817
+ continue: !def.abort,
1818
+ });
1819
+ }
1820
+ }
1821
+ // Set the output value based on normalize flag
1822
+ if (def.normalize) {
1823
+ // Use normalized URL
1824
+ payload.value = url.href;
1825
+ }
1826
+ else {
1827
+ // Preserve the original input (trimmed)
1828
+ payload.value = trimmed;
1829
+ }
1830
+ return;
1831
+ }
1832
+ catch (_) {
1833
+ payload.issues.push({
1834
+ code: "invalid_format",
1835
+ format: "url",
1836
+ input: payload.value,
1837
+ inst,
1838
+ continue: !def.abort,
1839
+ });
1840
+ }
1841
+ };
1842
+ });
1843
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
1844
+ def.pattern ?? (def.pattern = emoji());
1845
+ $ZodStringFormat.init(inst, def);
1846
+ });
1847
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
1848
+ def.pattern ?? (def.pattern = nanoid);
1849
+ $ZodStringFormat.init(inst, def);
1850
+ });
1851
+ /**
1852
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1853
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
1854
+ * See https://github.com/paralleldrive/cuid.
1855
+ */
1856
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
1857
+ def.pattern ?? (def.pattern = cuid);
1858
+ $ZodStringFormat.init(inst, def);
1859
+ });
1860
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
1861
+ def.pattern ?? (def.pattern = cuid2);
1862
+ $ZodStringFormat.init(inst, def);
1863
+ });
1864
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
1865
+ def.pattern ?? (def.pattern = ulid);
1866
+ $ZodStringFormat.init(inst, def);
1867
+ });
1868
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
1869
+ def.pattern ?? (def.pattern = xid);
1870
+ $ZodStringFormat.init(inst, def);
1871
+ });
1872
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
1873
+ def.pattern ?? (def.pattern = ksuid);
1874
+ $ZodStringFormat.init(inst, def);
1875
+ });
1876
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
1877
+ def.pattern ?? (def.pattern = datetime$1(def));
1878
+ $ZodStringFormat.init(inst, def);
1879
+ });
1880
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
1881
+ def.pattern ?? (def.pattern = date$1);
1882
+ $ZodStringFormat.init(inst, def);
1883
+ });
1884
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
1885
+ def.pattern ?? (def.pattern = time$1(def));
1886
+ $ZodStringFormat.init(inst, def);
1887
+ });
1888
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
1889
+ def.pattern ?? (def.pattern = duration$1);
1890
+ $ZodStringFormat.init(inst, def);
1891
+ });
1892
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1893
+ def.pattern ?? (def.pattern = ipv4);
1894
+ $ZodStringFormat.init(inst, def);
1895
+ inst._zod.bag.format = `ipv4`;
1896
+ });
1897
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1898
+ def.pattern ?? (def.pattern = ipv6);
1899
+ $ZodStringFormat.init(inst, def);
1900
+ inst._zod.bag.format = `ipv6`;
1901
+ inst._zod.check = (payload) => {
1902
+ try {
1903
+ // @ts-ignore
1904
+ new URL(`http://[${payload.value}]`);
1905
+ // return;
1906
+ }
1907
+ catch {
1908
+ payload.issues.push({
1909
+ code: "invalid_format",
1910
+ format: "ipv6",
1911
+ input: payload.value,
1912
+ inst,
1913
+ continue: !def.abort,
1914
+ });
1915
+ }
1916
+ };
1917
+ });
1918
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
1919
+ def.pattern ?? (def.pattern = cidrv4);
1920
+ $ZodStringFormat.init(inst, def);
1921
+ });
1922
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
1923
+ def.pattern ?? (def.pattern = cidrv6); // not used for validation
1924
+ $ZodStringFormat.init(inst, def);
1925
+ inst._zod.check = (payload) => {
1926
+ const parts = payload.value.split("/");
1927
+ try {
1928
+ if (parts.length !== 2)
1929
+ throw new Error();
1930
+ const [address, prefix] = parts;
1931
+ if (!prefix)
1932
+ throw new Error();
1933
+ const prefixNum = Number(prefix);
1934
+ if (`${prefixNum}` !== prefix)
1935
+ throw new Error();
1936
+ if (prefixNum < 0 || prefixNum > 128)
1937
+ throw new Error();
1938
+ // @ts-ignore
1939
+ new URL(`http://[${address}]`);
1940
+ }
1941
+ catch {
1942
+ payload.issues.push({
1943
+ code: "invalid_format",
1944
+ format: "cidrv6",
1945
+ input: payload.value,
1946
+ inst,
1947
+ continue: !def.abort,
1948
+ });
1949
+ }
1950
+ };
1951
+ });
1952
+ ////////////////////////////// ZodBase64 //////////////////////////////
1953
+ function isValidBase64(data) {
1954
+ if (data === "")
1955
+ return true;
1956
+ // atob ignores whitespace, so reject it up front.
1957
+ if (/\s/.test(data))
1958
+ return false;
1959
+ if (data.length % 4 !== 0)
1960
+ return false;
1961
+ try {
1962
+ // @ts-ignore
1963
+ atob(data);
1964
+ return true;
1965
+ }
1966
+ catch {
1967
+ return false;
1968
+ }
1969
+ }
1970
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1971
+ def.pattern ?? (def.pattern = base64);
1972
+ $ZodStringFormat.init(inst, def);
1973
+ inst._zod.bag.contentEncoding = "base64";
1974
+ inst._zod.check = (payload) => {
1975
+ if (isValidBase64(payload.value))
1976
+ return;
1977
+ payload.issues.push({
1978
+ code: "invalid_format",
1979
+ format: "base64",
1980
+ input: payload.value,
1981
+ inst,
1982
+ continue: !def.abort,
1983
+ });
1984
+ };
1985
+ });
1986
+ ////////////////////////////// ZodBase64 //////////////////////////////
1987
+ function isValidBase64URL(data) {
1988
+ if (!base64url.test(data))
1989
+ return false;
1990
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
1991
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
1992
+ return isValidBase64(padded);
1993
+ }
1994
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1995
+ def.pattern ?? (def.pattern = base64url);
1996
+ $ZodStringFormat.init(inst, def);
1997
+ inst._zod.bag.contentEncoding = "base64url";
1998
+ inst._zod.check = (payload) => {
1999
+ if (isValidBase64URL(payload.value))
2000
+ return;
2001
+ payload.issues.push({
2002
+ code: "invalid_format",
2003
+ format: "base64url",
2004
+ input: payload.value,
2005
+ inst,
2006
+ continue: !def.abort,
2007
+ });
2008
+ };
2009
+ });
2010
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
2011
+ def.pattern ?? (def.pattern = e164);
2012
+ $ZodStringFormat.init(inst, def);
2013
+ });
2014
+ ////////////////////////////// ZodJWT //////////////////////////////
2015
+ function isValidJWT(token, algorithm = null) {
2016
+ try {
2017
+ const tokensParts = token.split(".");
2018
+ if (tokensParts.length !== 3)
2019
+ return false;
2020
+ const [header] = tokensParts;
2021
+ if (!header)
2022
+ return false;
2023
+ // @ts-ignore
2024
+ const parsedHeader = JSON.parse(atob(header));
2025
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
2026
+ return false;
2027
+ if (!parsedHeader.alg)
2028
+ return false;
2029
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
2030
+ return false;
2031
+ return true;
2032
+ }
2033
+ catch {
2034
+ return false;
2035
+ }
2036
+ }
2037
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
2038
+ $ZodStringFormat.init(inst, def);
2039
+ inst._zod.check = (payload) => {
2040
+ if (isValidJWT(payload.value, def.alg))
2041
+ return;
2042
+ payload.issues.push({
2043
+ code: "invalid_format",
2044
+ format: "jwt",
2045
+ input: payload.value,
2046
+ inst,
2047
+ continue: !def.abort,
2048
+ });
2049
+ };
2050
+ });
2051
+ const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
2052
+ $ZodType.init(inst, def);
2053
+ inst._zod.parse = (payload) => payload;
2054
+ });
2055
+ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
2056
+ $ZodType.init(inst, def);
2057
+ inst._zod.parse = (payload, _ctx) => {
2058
+ payload.issues.push({
2059
+ expected: "never",
2060
+ code: "invalid_type",
2061
+ input: payload.value,
2062
+ inst,
2063
+ });
2064
+ return payload;
2065
+ };
2066
+ });
2067
+ function handleArrayResult(result, final, index) {
2068
+ if (result.issues.length) {
2069
+ final.issues.push(...prefixIssues(index, result.issues));
2070
+ }
2071
+ final.value[index] = result.value;
2072
+ }
2073
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
2074
+ $ZodType.init(inst, def);
2075
+ inst._zod.parse = (payload, ctx) => {
2076
+ const input = payload.value;
2077
+ if (!Array.isArray(input)) {
2078
+ payload.issues.push({
2079
+ expected: "array",
2080
+ code: "invalid_type",
2081
+ input,
2082
+ inst,
2083
+ });
2084
+ return payload;
2085
+ }
2086
+ payload.value = Array(input.length);
2087
+ const proms = [];
2088
+ for (let i = 0; i < input.length; i++) {
2089
+ const item = input[i];
2090
+ const result = def.element._zod.run({
2091
+ value: item,
2092
+ issues: [],
2093
+ }, ctx);
2094
+ if (result instanceof Promise) {
2095
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
2096
+ }
2097
+ else {
2098
+ handleArrayResult(result, payload, i);
2099
+ }
2100
+ }
2101
+ if (proms.length) {
2102
+ return Promise.all(proms).then(() => payload);
2103
+ }
2104
+ return payload; //handleArrayResultsAsync(parseResults, final);
2105
+ };
2106
+ });
2107
+ function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
2108
+ const isPresent = key in input;
2109
+ if (result.issues.length) {
2110
+ // For optional-in/out schemas, ignore errors on absent keys.
2111
+ if (isOptionalIn && isOptionalOut && !isPresent) {
2112
+ return;
2113
+ }
2114
+ final.issues.push(...prefixIssues(key, result.issues));
2115
+ }
2116
+ if (!isPresent && !isOptionalIn) {
2117
+ if (!result.issues.length) {
2118
+ final.issues.push({
2119
+ code: "invalid_type",
2120
+ expected: "nonoptional",
2121
+ input: undefined,
2122
+ path: [key],
2123
+ });
2124
+ }
2125
+ return;
2126
+ }
2127
+ if (result.value === undefined) {
2128
+ if (isPresent) {
2129
+ final.value[key] = undefined;
2130
+ }
2131
+ }
2132
+ else {
2133
+ final.value[key] = result.value;
2134
+ }
2135
+ }
2136
+ function normalizeDef(def) {
2137
+ const keys = Object.keys(def.shape);
2138
+ for (const k of keys) {
2139
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
2140
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
2141
+ }
2142
+ }
2143
+ const okeys = optionalKeys(def.shape);
2144
+ return {
2145
+ ...def,
2146
+ keys,
2147
+ keySet: new Set(keys),
2148
+ numKeys: keys.length,
2149
+ optionalKeys: new Set(okeys),
2150
+ };
2151
+ }
2152
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
2153
+ const unrecognized = [];
2154
+ const keySet = def.keySet;
2155
+ const _catchall = def.catchall._zod;
2156
+ const t = _catchall.def.type;
2157
+ const isOptionalIn = _catchall.optin === "optional";
2158
+ const isOptionalOut = _catchall.optout === "optional";
2159
+ for (const key in input) {
2160
+ // skip __proto__ so it can't replace the result prototype via the
2161
+ // assignment setter on the plain {} we build into
2162
+ if (key === "__proto__")
2163
+ continue;
2164
+ if (keySet.has(key))
2165
+ continue;
2166
+ if (t === "never") {
2167
+ unrecognized.push(key);
2168
+ continue;
2169
+ }
2170
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
2171
+ if (r instanceof Promise) {
2172
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
2173
+ }
2174
+ else {
2175
+ handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
2176
+ }
2177
+ }
2178
+ if (unrecognized.length) {
2179
+ payload.issues.push({
2180
+ code: "unrecognized_keys",
2181
+ keys: unrecognized,
2182
+ input,
2183
+ inst,
2184
+ });
2185
+ }
2186
+ if (!proms.length)
2187
+ return payload;
2188
+ return Promise.all(proms).then(() => {
2189
+ return payload;
2190
+ });
2191
+ }
2192
+ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
2193
+ // requires cast because technically $ZodObject doesn't extend
2194
+ $ZodType.init(inst, def);
2195
+ // const sh = def.shape;
2196
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
2197
+ if (!desc?.get) {
2198
+ const sh = def.shape;
2199
+ Object.defineProperty(def, "shape", {
2200
+ get: () => {
2201
+ const newSh = { ...sh };
2202
+ Object.defineProperty(def, "shape", {
2203
+ value: newSh,
2204
+ });
2205
+ return newSh;
2206
+ },
2207
+ });
2208
+ }
2209
+ const _normalized = cached(() => normalizeDef(def));
2210
+ defineLazy(inst._zod, "propValues", () => {
2211
+ const shape = def.shape;
2212
+ const propValues = {};
2213
+ for (const key in shape) {
2214
+ const field = shape[key]._zod;
2215
+ if (field.values) {
2216
+ propValues[key] ?? (propValues[key] = new Set());
2217
+ for (const v of field.values)
2218
+ propValues[key].add(v);
2219
+ }
2220
+ }
2221
+ return propValues;
2222
+ });
2223
+ const isObject$1 = isObject;
2224
+ const catchall = def.catchall;
2225
+ let value;
2226
+ inst._zod.parse = (payload, ctx) => {
2227
+ value ?? (value = _normalized.value);
2228
+ const input = payload.value;
2229
+ if (!isObject$1(input)) {
2230
+ payload.issues.push({
2231
+ expected: "object",
2232
+ code: "invalid_type",
2233
+ input,
2234
+ inst,
2235
+ });
2236
+ return payload;
2237
+ }
2238
+ payload.value = {};
2239
+ const proms = [];
2240
+ const shape = value.shape;
2241
+ for (const key of value.keys) {
2242
+ const el = shape[key];
2243
+ const isOptionalIn = el._zod.optin === "optional";
2244
+ const isOptionalOut = el._zod.optout === "optional";
2245
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
2246
+ if (r instanceof Promise) {
2247
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
2248
+ }
2249
+ else {
2250
+ handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
2251
+ }
2252
+ }
2253
+ if (!catchall) {
2254
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
2255
+ }
2256
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
2257
+ };
2258
+ });
2259
+ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) => {
2260
+ // requires cast because technically $ZodObject doesn't extend
2261
+ $ZodObject.init(inst, def);
2262
+ const superParse = inst._zod.parse;
2263
+ const _normalized = cached(() => normalizeDef(def));
2264
+ const generateFastpass = (shape) => {
2265
+ const doc = new Doc(["shape", "payload", "ctx"]);
2266
+ const normalized = _normalized.value;
2267
+ const parseStr = (key) => {
2268
+ const k = esc(key);
2269
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
2270
+ };
2271
+ doc.write(`const input = payload.value;`);
2272
+ const ids = Object.create(null);
2273
+ let counter = 0;
2274
+ for (const key of normalized.keys) {
2275
+ ids[key] = `key_${counter++}`;
2276
+ }
2277
+ // A: preserve key order {
2278
+ doc.write(`const newResult = {};`);
2279
+ for (const key of normalized.keys) {
2280
+ const id = ids[key];
2281
+ const k = esc(key);
2282
+ const schema = shape[key];
2283
+ const isOptionalIn = schema?._zod?.optin === "optional";
2284
+ const isOptionalOut = schema?._zod?.optout === "optional";
2285
+ doc.write(`const ${id} = ${parseStr(key)};`);
2286
+ if (isOptionalIn && isOptionalOut) {
2287
+ // For optional-in/out schemas, ignore errors on absent keys
2288
+ doc.write(`
2289
+ if (${id}.issues.length) {
2290
+ if (${k} in input) {
2291
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2292
+ ...iss,
2293
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2294
+ })));
2295
+ }
2296
+ }
2297
+
2298
+ if (${id}.value === undefined) {
2299
+ if (${k} in input) {
2300
+ newResult[${k}] = undefined;
2301
+ }
2302
+ } else {
2303
+ newResult[${k}] = ${id}.value;
2304
+ }
2305
+
2306
+ `);
2307
+ }
2308
+ else if (!isOptionalIn) {
2309
+ doc.write(`
2310
+ const ${id}_present = ${k} in input;
2311
+ if (${id}.issues.length) {
2312
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2313
+ ...iss,
2314
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2315
+ })));
2316
+ }
2317
+ if (!${id}_present && !${id}.issues.length) {
2318
+ payload.issues.push({
2319
+ code: "invalid_type",
2320
+ expected: "nonoptional",
2321
+ input: undefined,
2322
+ path: [${k}]
2323
+ });
2324
+ }
2325
+
2326
+ if (${id}_present) {
2327
+ if (${id}.value === undefined) {
2328
+ newResult[${k}] = undefined;
2329
+ } else {
2330
+ newResult[${k}] = ${id}.value;
2331
+ }
2332
+ }
2333
+
2334
+ `);
2335
+ }
2336
+ else {
2337
+ doc.write(`
2338
+ if (${id}.issues.length) {
2339
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2340
+ ...iss,
2341
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2342
+ })));
2343
+ }
2344
+
2345
+ if (${id}.value === undefined) {
2346
+ if (${k} in input) {
2347
+ newResult[${k}] = undefined;
2348
+ }
2349
+ } else {
2350
+ newResult[${k}] = ${id}.value;
2351
+ }
2352
+
2353
+ `);
2354
+ }
2355
+ }
2356
+ doc.write(`payload.value = newResult;`);
2357
+ doc.write(`return payload;`);
2358
+ const fn = doc.compile();
2359
+ return (payload, ctx) => fn(shape, payload, ctx);
2360
+ };
2361
+ let fastpass;
2362
+ const isObject$1 = isObject;
2363
+ const jit = !globalConfig.jitless;
2364
+ const allowsEval$1 = allowsEval;
2365
+ const fastEnabled = jit && allowsEval$1.value; // && !def.catchall;
2366
+ const catchall = def.catchall;
2367
+ let value;
2368
+ inst._zod.parse = (payload, ctx) => {
2369
+ value ?? (value = _normalized.value);
2370
+ const input = payload.value;
2371
+ if (!isObject$1(input)) {
2372
+ payload.issues.push({
2373
+ expected: "object",
2374
+ code: "invalid_type",
2375
+ input,
2376
+ inst,
2377
+ });
2378
+ return payload;
2379
+ }
2380
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
2381
+ // always synchronous
2382
+ if (!fastpass)
2383
+ fastpass = generateFastpass(def.shape);
2384
+ payload = fastpass(payload, ctx);
2385
+ if (!catchall)
2386
+ return payload;
2387
+ return handleCatchall([], input, payload, ctx, value, inst);
2388
+ }
2389
+ return superParse(payload, ctx);
2390
+ };
2391
+ });
2392
+ function handleUnionResults(results, final, inst, ctx) {
2393
+ for (const result of results) {
2394
+ if (result.issues.length === 0) {
2395
+ final.value = result.value;
2396
+ return final;
2397
+ }
2398
+ }
2399
+ const nonaborted = results.filter((r) => !aborted(r));
2400
+ if (nonaborted.length === 1) {
2401
+ final.value = nonaborted[0].value;
2402
+ return nonaborted[0];
2403
+ }
2404
+ final.issues.push({
2405
+ code: "invalid_union",
2406
+ input: final.value,
2407
+ inst,
2408
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
2409
+ });
2410
+ return final;
2411
+ }
2412
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
2413
+ $ZodType.init(inst, def);
2414
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
2415
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
2416
+ defineLazy(inst._zod, "values", () => {
2417
+ if (def.options.every((o) => o._zod.values)) {
2418
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
2419
+ }
2420
+ return undefined;
2421
+ });
2422
+ defineLazy(inst._zod, "pattern", () => {
2423
+ if (def.options.every((o) => o._zod.pattern)) {
2424
+ const patterns = def.options.map((o) => o._zod.pattern);
2425
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
2426
+ }
2427
+ return undefined;
2428
+ });
2429
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
2430
+ inst._zod.parse = (payload, ctx) => {
2431
+ if (first) {
2432
+ return first(payload, ctx);
2433
+ }
2434
+ let async = false;
2435
+ const results = [];
2436
+ for (const option of def.options) {
2437
+ const result = option._zod.run({
2438
+ value: payload.value,
2439
+ issues: [],
2440
+ }, ctx);
2441
+ if (result instanceof Promise) {
2442
+ results.push(result);
2443
+ async = true;
2444
+ }
2445
+ else {
2446
+ if (result.issues.length === 0)
2447
+ return result;
2448
+ results.push(result);
2449
+ }
2450
+ }
2451
+ if (!async)
2452
+ return handleUnionResults(results, payload, inst, ctx);
2453
+ return Promise.all(results).then((results) => {
2454
+ return handleUnionResults(results, payload, inst, ctx);
2455
+ });
2456
+ };
2457
+ });
2458
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
2459
+ $ZodType.init(inst, def);
2460
+ inst._zod.parse = (payload, ctx) => {
2461
+ const input = payload.value;
2462
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
2463
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
2464
+ const async = left instanceof Promise || right instanceof Promise;
2465
+ if (async) {
2466
+ return Promise.all([left, right]).then(([left, right]) => {
2467
+ return handleIntersectionResults(payload, left, right);
2468
+ });
2469
+ }
2470
+ return handleIntersectionResults(payload, left, right);
2471
+ };
2472
+ });
2473
+ function mergeValues(a, b) {
2474
+ // const aType = parse.t(a);
2475
+ // const bType = parse.t(b);
2476
+ if (a === b) {
2477
+ return { valid: true, data: a };
2478
+ }
2479
+ if (a instanceof Date && b instanceof Date && +a === +b) {
2480
+ return { valid: true, data: a };
2481
+ }
2482
+ if (isPlainObject(a) && isPlainObject(b)) {
2483
+ const bKeys = Object.keys(b);
2484
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
2485
+ const newObj = { ...a, ...b };
2486
+ for (const key of sharedKeys) {
2487
+ const sharedValue = mergeValues(a[key], b[key]);
2488
+ if (!sharedValue.valid) {
2489
+ return {
2490
+ valid: false,
2491
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
2492
+ };
2493
+ }
2494
+ newObj[key] = sharedValue.data;
2495
+ }
2496
+ return { valid: true, data: newObj };
2497
+ }
2498
+ if (Array.isArray(a) && Array.isArray(b)) {
2499
+ if (a.length !== b.length) {
2500
+ return { valid: false, mergeErrorPath: [] };
2501
+ }
2502
+ const newArray = [];
2503
+ for (let index = 0; index < a.length; index++) {
2504
+ const itemA = a[index];
2505
+ const itemB = b[index];
2506
+ const sharedValue = mergeValues(itemA, itemB);
2507
+ if (!sharedValue.valid) {
2508
+ return {
2509
+ valid: false,
2510
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
2511
+ };
2512
+ }
2513
+ newArray.push(sharedValue.data);
2514
+ }
2515
+ return { valid: true, data: newArray };
2516
+ }
2517
+ return { valid: false, mergeErrorPath: [] };
2518
+ }
2519
+ function handleIntersectionResults(result, left, right) {
2520
+ // Track which side(s) report each key as unrecognized
2521
+ const unrecKeys = new Map();
2522
+ let unrecIssue;
2523
+ for (const iss of left.issues) {
2524
+ if (iss.code === "unrecognized_keys") {
2525
+ unrecIssue ?? (unrecIssue = iss);
2526
+ for (const k of iss.keys) {
2527
+ if (!unrecKeys.has(k))
2528
+ unrecKeys.set(k, {});
2529
+ unrecKeys.get(k).l = true;
2530
+ }
2531
+ }
2532
+ else {
2533
+ result.issues.push(iss);
2534
+ }
2535
+ }
2536
+ for (const iss of right.issues) {
2537
+ if (iss.code === "unrecognized_keys") {
2538
+ for (const k of iss.keys) {
2539
+ if (!unrecKeys.has(k))
2540
+ unrecKeys.set(k, {});
2541
+ unrecKeys.get(k).r = true;
2542
+ }
2543
+ }
2544
+ else {
2545
+ result.issues.push(iss);
2546
+ }
2547
+ }
2548
+ // Report only keys unrecognized by BOTH sides
2549
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2550
+ if (bothKeys.length && unrecIssue) {
2551
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
2552
+ }
2553
+ if (aborted(result))
2554
+ return result;
2555
+ const merged = mergeValues(left.value, right.value);
2556
+ if (!merged.valid) {
2557
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
2558
+ }
2559
+ result.value = merged.data;
2560
+ return result;
2561
+ }
2562
+ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
2563
+ $ZodType.init(inst, def);
2564
+ const values = getEnumValues(def.entries);
2565
+ const valuesSet = new Set(values);
2566
+ inst._zod.values = valuesSet;
2567
+ inst._zod.pattern = new RegExp(`^(${values
2568
+ .filter((k) => propertyKeyTypes.has(typeof k))
2569
+ .map((o) => (typeof o === "string" ? escapeRegex(o) : o.toString()))
2570
+ .join("|")})$`);
2571
+ inst._zod.parse = (payload, _ctx) => {
2572
+ const input = payload.value;
2573
+ if (valuesSet.has(input)) {
2574
+ return payload;
2575
+ }
2576
+ payload.issues.push({
2577
+ code: "invalid_value",
2578
+ values,
2579
+ input,
2580
+ inst,
2581
+ });
2582
+ return payload;
2583
+ };
2584
+ });
2585
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
2586
+ $ZodType.init(inst, def);
2587
+ inst._zod.optin = "optional";
2588
+ inst._zod.parse = (payload, ctx) => {
2589
+ if (ctx.direction === "backward") {
2590
+ throw new $ZodEncodeError(inst.constructor.name);
2591
+ }
2592
+ const _out = def.transform(payload.value, payload);
2593
+ if (ctx.async) {
2594
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
2595
+ return output.then((output) => {
2596
+ payload.value = output;
2597
+ payload.fallback = true;
2598
+ return payload;
2599
+ });
2600
+ }
2601
+ if (_out instanceof Promise) {
2602
+ throw new $ZodAsyncError();
2603
+ }
2604
+ payload.value = _out;
2605
+ payload.fallback = true;
2606
+ return payload;
2607
+ };
2608
+ });
2609
+ function handleOptionalResult(result, input) {
2610
+ if (input === undefined && (result.issues.length || result.fallback)) {
2611
+ return { issues: [], value: undefined };
2612
+ }
2613
+ return result;
2614
+ }
2615
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
2616
+ $ZodType.init(inst, def);
2617
+ inst._zod.optin = "optional";
2618
+ inst._zod.optout = "optional";
2619
+ defineLazy(inst._zod, "values", () => {
2620
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
2621
+ });
2622
+ defineLazy(inst._zod, "pattern", () => {
2623
+ const pattern = def.innerType._zod.pattern;
2624
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
2625
+ });
2626
+ inst._zod.parse = (payload, ctx) => {
2627
+ if (def.innerType._zod.optin === "optional") {
2628
+ const input = payload.value;
2629
+ const result = def.innerType._zod.run(payload, ctx);
2630
+ if (result instanceof Promise)
2631
+ return result.then((r) => handleOptionalResult(r, input));
2632
+ return handleOptionalResult(result, input);
2633
+ }
2634
+ if (payload.value === undefined) {
2635
+ return payload;
2636
+ }
2637
+ return def.innerType._zod.run(payload, ctx);
2638
+ };
2639
+ });
2640
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
2641
+ // Call parent init - inherits optin/optout = "optional"
2642
+ $ZodOptional.init(inst, def);
2643
+ // Override values/pattern to NOT add undefined
2644
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2645
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2646
+ // Override parse to just delegate (no undefined handling)
2647
+ inst._zod.parse = (payload, ctx) => {
2648
+ return def.innerType._zod.run(payload, ctx);
2649
+ };
2650
+ });
2651
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
2652
+ $ZodType.init(inst, def);
2653
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2654
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2655
+ defineLazy(inst._zod, "pattern", () => {
2656
+ const pattern = def.innerType._zod.pattern;
2657
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
2658
+ });
2659
+ defineLazy(inst._zod, "values", () => {
2660
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
2661
+ });
2662
+ inst._zod.parse = (payload, ctx) => {
2663
+ // Forward direction (decode): allow null to pass through
2664
+ if (payload.value === null)
2665
+ return payload;
2666
+ return def.innerType._zod.run(payload, ctx);
2667
+ };
2668
+ });
2669
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
2670
+ $ZodType.init(inst, def);
2671
+ // inst._zod.qin = "true";
2672
+ inst._zod.optin = "optional";
2673
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2674
+ inst._zod.parse = (payload, ctx) => {
2675
+ if (ctx.direction === "backward") {
2676
+ return def.innerType._zod.run(payload, ctx);
2677
+ }
2678
+ // Forward direction (decode): apply defaults for undefined input
2679
+ if (payload.value === undefined) {
2680
+ payload.value = def.defaultValue;
2681
+ /**
2682
+ * $ZodDefault returns the default value immediately in forward direction.
2683
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
2684
+ return payload;
2685
+ }
2686
+ // Forward direction: continue with default handling
2687
+ const result = def.innerType._zod.run(payload, ctx);
2688
+ if (result instanceof Promise) {
2689
+ return result.then((result) => handleDefaultResult(result, def));
2690
+ }
2691
+ return handleDefaultResult(result, def);
2692
+ };
2693
+ });
2694
+ function handleDefaultResult(payload, def) {
2695
+ if (payload.value === undefined) {
2696
+ payload.value = def.defaultValue;
2697
+ }
2698
+ return payload;
2699
+ }
2700
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
2701
+ $ZodType.init(inst, def);
2702
+ inst._zod.optin = "optional";
2703
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2704
+ inst._zod.parse = (payload, ctx) => {
2705
+ if (ctx.direction === "backward") {
2706
+ return def.innerType._zod.run(payload, ctx);
2707
+ }
2708
+ // Forward direction (decode): apply prefault for undefined input
2709
+ if (payload.value === undefined) {
2710
+ payload.value = def.defaultValue;
2711
+ }
2712
+ return def.innerType._zod.run(payload, ctx);
2713
+ };
2714
+ });
2715
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
2716
+ $ZodType.init(inst, def);
2717
+ defineLazy(inst._zod, "values", () => {
2718
+ const v = def.innerType._zod.values;
2719
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
2720
+ });
2721
+ inst._zod.parse = (payload, ctx) => {
2722
+ const result = def.innerType._zod.run(payload, ctx);
2723
+ if (result instanceof Promise) {
2724
+ return result.then((result) => handleNonOptionalResult(result, inst));
2725
+ }
2726
+ return handleNonOptionalResult(result, inst);
2727
+ };
2728
+ });
2729
+ function handleNonOptionalResult(payload, inst) {
2730
+ if (!payload.issues.length && payload.value === undefined) {
2731
+ payload.issues.push({
2732
+ code: "invalid_type",
2733
+ expected: "nonoptional",
2734
+ input: payload.value,
2735
+ inst,
2736
+ });
2737
+ }
2738
+ return payload;
2739
+ }
2740
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
2741
+ $ZodType.init(inst, def);
2742
+ inst._zod.optin = "optional";
2743
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2744
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2745
+ inst._zod.parse = (payload, ctx) => {
2746
+ if (ctx.direction === "backward") {
2747
+ return def.innerType._zod.run(payload, ctx);
2748
+ }
2749
+ // Forward direction (decode): apply catch logic
2750
+ const result = def.innerType._zod.run(payload, ctx);
2751
+ if (result instanceof Promise) {
2752
+ return result.then((result) => {
2753
+ payload.value = result.value;
2754
+ if (result.issues.length) {
2755
+ payload.value = def.catchValue({
2756
+ ...payload,
2757
+ error: {
2758
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
2759
+ },
2760
+ input: payload.value,
2761
+ });
2762
+ payload.issues = [];
2763
+ payload.fallback = true;
2764
+ }
2765
+ return payload;
2766
+ });
2767
+ }
2768
+ payload.value = result.value;
2769
+ if (result.issues.length) {
2770
+ payload.value = def.catchValue({
2771
+ ...payload,
2772
+ error: {
2773
+ issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
2774
+ },
2775
+ input: payload.value,
2776
+ });
2777
+ payload.issues = [];
2778
+ payload.fallback = true;
2779
+ }
2780
+ return payload;
2781
+ };
2782
+ });
2783
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
2784
+ $ZodType.init(inst, def);
2785
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
2786
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
2787
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2788
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2789
+ inst._zod.parse = (payload, ctx) => {
2790
+ if (ctx.direction === "backward") {
2791
+ const right = def.out._zod.run(payload, ctx);
2792
+ if (right instanceof Promise) {
2793
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
2794
+ }
2795
+ return handlePipeResult(right, def.in, ctx);
2796
+ }
2797
+ const left = def.in._zod.run(payload, ctx);
2798
+ if (left instanceof Promise) {
2799
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
2800
+ }
2801
+ return handlePipeResult(left, def.out, ctx);
2802
+ };
2803
+ });
2804
+ function handlePipeResult(left, next, ctx) {
2805
+ if (left.issues.length) {
2806
+ // prevent further checks
2807
+ left.aborted = true;
2808
+ return left;
2809
+ }
2810
+ return next._zod.run({ value: left.value, issues: left.issues, fallback: left.fallback }, ctx);
2811
+ }
2812
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2813
+ $ZodType.init(inst, def);
2814
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2815
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2816
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2817
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2818
+ inst._zod.parse = (payload, ctx) => {
2819
+ if (ctx.direction === "backward") {
2820
+ return def.innerType._zod.run(payload, ctx);
2821
+ }
2822
+ const result = def.innerType._zod.run(payload, ctx);
2823
+ if (result instanceof Promise) {
2824
+ return result.then(handleReadonlyResult);
2825
+ }
2826
+ return handleReadonlyResult(result);
2827
+ };
2828
+ });
2829
+ function handleReadonlyResult(payload) {
2830
+ payload.value = Object.freeze(payload.value);
2831
+ return payload;
2832
+ }
2833
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
2834
+ $ZodCheck.init(inst, def);
2835
+ $ZodType.init(inst, def);
2836
+ inst._zod.parse = (payload, _) => {
2837
+ return payload;
2838
+ };
2839
+ inst._zod.check = (payload) => {
2840
+ const input = payload.value;
2841
+ const r = def.fn(input);
2842
+ if (r instanceof Promise) {
2843
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
2844
+ }
2845
+ handleRefineResult(r, payload, input, inst);
2846
+ return;
2847
+ };
2848
+ });
2849
+ function handleRefineResult(result, payload, input, inst) {
2850
+ if (!result) {
2851
+ const _iss = {
2852
+ code: "custom",
2853
+ input,
2854
+ inst, // incorporates params.error into issue reporting
2855
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
2856
+ continue: !inst._zod.def.abort,
2857
+ // params: inst._zod.def.params,
2858
+ };
2859
+ if (inst._zod.def.params)
2860
+ _iss.params = inst._zod.def.params;
2861
+ payload.issues.push(issue(_iss));
2862
+ }
2863
+ }
2864
+
2865
+ var _a;
2866
+ class $ZodRegistry {
2867
+ constructor() {
2868
+ this._map = new WeakMap();
2869
+ this._idmap = new Map();
2870
+ }
2871
+ add(schema, ..._meta) {
2872
+ const meta = _meta[0];
2873
+ this._map.set(schema, meta);
2874
+ if (meta && typeof meta === "object" && "id" in meta) {
2875
+ this._idmap.set(meta.id, schema);
2876
+ }
2877
+ return this;
2878
+ }
2879
+ clear() {
2880
+ this._map = new WeakMap();
2881
+ this._idmap = new Map();
2882
+ return this;
2883
+ }
2884
+ remove(schema) {
2885
+ const meta = this._map.get(schema);
2886
+ if (meta && typeof meta === "object" && "id" in meta) {
2887
+ this._idmap.delete(meta.id);
2888
+ }
2889
+ this._map.delete(schema);
2890
+ return this;
2891
+ }
2892
+ get(schema) {
2893
+ // return this._map.get(schema) as any;
2894
+ // inherit metadata
2895
+ const p = schema._zod.parent;
2896
+ if (p) {
2897
+ const pm = { ...(this.get(p) ?? {}) };
2898
+ delete pm.id; // do not inherit id
2899
+ const f = { ...pm, ...this._map.get(schema) };
2900
+ return Object.keys(f).length ? f : undefined;
2901
+ }
2902
+ return this._map.get(schema);
2903
+ }
2904
+ has(schema) {
2905
+ return this._map.has(schema);
2906
+ }
2907
+ }
2908
+ // registries
2909
+ function registry() {
2910
+ return new $ZodRegistry();
2911
+ }
2912
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2913
+ const globalRegistry = globalThis.__zod_globalRegistry;
2914
+
2915
+ // @__NO_SIDE_EFFECTS__
2916
+ function _string(Class, params) {
2917
+ return new Class({
2918
+ type: "string",
2919
+ ...normalizeParams(params),
2920
+ });
2921
+ }
2922
+ // @__NO_SIDE_EFFECTS__
2923
+ function _email(Class, params) {
2924
+ return new Class({
2925
+ type: "string",
2926
+ format: "email",
2927
+ check: "string_format",
2928
+ abort: false,
2929
+ ...normalizeParams(params),
2930
+ });
2931
+ }
2932
+ // @__NO_SIDE_EFFECTS__
2933
+ function _guid(Class, params) {
2934
+ return new Class({
2935
+ type: "string",
2936
+ format: "guid",
2937
+ check: "string_format",
2938
+ abort: false,
2939
+ ...normalizeParams(params),
2940
+ });
2941
+ }
2942
+ // @__NO_SIDE_EFFECTS__
2943
+ function _uuid(Class, params) {
2944
+ return new Class({
2945
+ type: "string",
2946
+ format: "uuid",
2947
+ check: "string_format",
2948
+ abort: false,
2949
+ ...normalizeParams(params),
2950
+ });
2951
+ }
2952
+ // @__NO_SIDE_EFFECTS__
2953
+ function _uuidv4(Class, params) {
2954
+ return new Class({
2955
+ type: "string",
2956
+ format: "uuid",
2957
+ check: "string_format",
2958
+ abort: false,
2959
+ version: "v4",
2960
+ ...normalizeParams(params),
2961
+ });
2962
+ }
2963
+ // @__NO_SIDE_EFFECTS__
2964
+ function _uuidv6(Class, params) {
2965
+ return new Class({
2966
+ type: "string",
2967
+ format: "uuid",
2968
+ check: "string_format",
2969
+ abort: false,
2970
+ version: "v6",
2971
+ ...normalizeParams(params),
2972
+ });
2973
+ }
2974
+ // @__NO_SIDE_EFFECTS__
2975
+ function _uuidv7(Class, params) {
2976
+ return new Class({
2977
+ type: "string",
2978
+ format: "uuid",
2979
+ check: "string_format",
2980
+ abort: false,
2981
+ version: "v7",
2982
+ ...normalizeParams(params),
2983
+ });
2984
+ }
2985
+ // @__NO_SIDE_EFFECTS__
2986
+ function _url(Class, params) {
2987
+ return new Class({
2988
+ type: "string",
2989
+ format: "url",
2990
+ check: "string_format",
2991
+ abort: false,
2992
+ ...normalizeParams(params),
2993
+ });
2994
+ }
2995
+ // @__NO_SIDE_EFFECTS__
2996
+ function _emoji(Class, params) {
2997
+ return new Class({
2998
+ type: "string",
2999
+ format: "emoji",
3000
+ check: "string_format",
3001
+ abort: false,
3002
+ ...normalizeParams(params),
3003
+ });
3004
+ }
3005
+ // @__NO_SIDE_EFFECTS__
3006
+ function _nanoid(Class, params) {
3007
+ return new Class({
3008
+ type: "string",
3009
+ format: "nanoid",
3010
+ check: "string_format",
3011
+ abort: false,
3012
+ ...normalizeParams(params),
3013
+ });
3014
+ }
3015
+ /**
3016
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
3017
+ * (timestamps embedded in the id). Use {@link _cuid2} instead.
3018
+ * See https://github.com/paralleldrive/cuid.
3019
+ */
3020
+ // @__NO_SIDE_EFFECTS__
3021
+ function _cuid(Class, params) {
3022
+ return new Class({
3023
+ type: "string",
3024
+ format: "cuid",
3025
+ check: "string_format",
3026
+ abort: false,
3027
+ ...normalizeParams(params),
3028
+ });
3029
+ }
3030
+ // @__NO_SIDE_EFFECTS__
3031
+ function _cuid2(Class, params) {
3032
+ return new Class({
3033
+ type: "string",
3034
+ format: "cuid2",
3035
+ check: "string_format",
3036
+ abort: false,
3037
+ ...normalizeParams(params),
3038
+ });
3039
+ }
3040
+ // @__NO_SIDE_EFFECTS__
3041
+ function _ulid(Class, params) {
3042
+ return new Class({
3043
+ type: "string",
3044
+ format: "ulid",
3045
+ check: "string_format",
3046
+ abort: false,
3047
+ ...normalizeParams(params),
3048
+ });
3049
+ }
3050
+ // @__NO_SIDE_EFFECTS__
3051
+ function _xid(Class, params) {
3052
+ return new Class({
3053
+ type: "string",
3054
+ format: "xid",
3055
+ check: "string_format",
3056
+ abort: false,
3057
+ ...normalizeParams(params),
3058
+ });
3059
+ }
3060
+ // @__NO_SIDE_EFFECTS__
3061
+ function _ksuid(Class, params) {
3062
+ return new Class({
3063
+ type: "string",
3064
+ format: "ksuid",
3065
+ check: "string_format",
3066
+ abort: false,
3067
+ ...normalizeParams(params),
3068
+ });
3069
+ }
3070
+ // @__NO_SIDE_EFFECTS__
3071
+ function _ipv4(Class, params) {
3072
+ return new Class({
3073
+ type: "string",
3074
+ format: "ipv4",
3075
+ check: "string_format",
3076
+ abort: false,
3077
+ ...normalizeParams(params),
3078
+ });
3079
+ }
3080
+ // @__NO_SIDE_EFFECTS__
3081
+ function _ipv6(Class, params) {
3082
+ return new Class({
3083
+ type: "string",
3084
+ format: "ipv6",
3085
+ check: "string_format",
3086
+ abort: false,
3087
+ ...normalizeParams(params),
3088
+ });
3089
+ }
3090
+ // @__NO_SIDE_EFFECTS__
3091
+ function _cidrv4(Class, params) {
3092
+ return new Class({
3093
+ type: "string",
3094
+ format: "cidrv4",
3095
+ check: "string_format",
3096
+ abort: false,
3097
+ ...normalizeParams(params),
3098
+ });
3099
+ }
3100
+ // @__NO_SIDE_EFFECTS__
3101
+ function _cidrv6(Class, params) {
3102
+ return new Class({
3103
+ type: "string",
3104
+ format: "cidrv6",
3105
+ check: "string_format",
3106
+ abort: false,
3107
+ ...normalizeParams(params),
3108
+ });
3109
+ }
3110
+ // @__NO_SIDE_EFFECTS__
3111
+ function _base64(Class, params) {
3112
+ return new Class({
3113
+ type: "string",
3114
+ format: "base64",
3115
+ check: "string_format",
3116
+ abort: false,
3117
+ ...normalizeParams(params),
3118
+ });
3119
+ }
3120
+ // @__NO_SIDE_EFFECTS__
3121
+ function _base64url(Class, params) {
3122
+ return new Class({
3123
+ type: "string",
3124
+ format: "base64url",
3125
+ check: "string_format",
3126
+ abort: false,
3127
+ ...normalizeParams(params),
3128
+ });
3129
+ }
3130
+ // @__NO_SIDE_EFFECTS__
3131
+ function _e164(Class, params) {
3132
+ return new Class({
3133
+ type: "string",
3134
+ format: "e164",
3135
+ check: "string_format",
3136
+ abort: false,
3137
+ ...normalizeParams(params),
3138
+ });
3139
+ }
3140
+ // @__NO_SIDE_EFFECTS__
3141
+ function _jwt(Class, params) {
3142
+ return new Class({
3143
+ type: "string",
3144
+ format: "jwt",
3145
+ check: "string_format",
3146
+ abort: false,
3147
+ ...normalizeParams(params),
3148
+ });
3149
+ }
3150
+ // @__NO_SIDE_EFFECTS__
3151
+ function _isoDateTime(Class, params) {
3152
+ return new Class({
3153
+ type: "string",
3154
+ format: "datetime",
3155
+ check: "string_format",
3156
+ offset: false,
3157
+ local: false,
3158
+ precision: null,
3159
+ ...normalizeParams(params),
3160
+ });
3161
+ }
3162
+ // @__NO_SIDE_EFFECTS__
3163
+ function _isoDate(Class, params) {
3164
+ return new Class({
3165
+ type: "string",
3166
+ format: "date",
3167
+ check: "string_format",
3168
+ ...normalizeParams(params),
3169
+ });
3170
+ }
3171
+ // @__NO_SIDE_EFFECTS__
3172
+ function _isoTime(Class, params) {
3173
+ return new Class({
3174
+ type: "string",
3175
+ format: "time",
3176
+ check: "string_format",
3177
+ precision: null,
3178
+ ...normalizeParams(params),
3179
+ });
3180
+ }
3181
+ // @__NO_SIDE_EFFECTS__
3182
+ function _isoDuration(Class, params) {
3183
+ return new Class({
3184
+ type: "string",
3185
+ format: "duration",
3186
+ check: "string_format",
3187
+ ...normalizeParams(params),
3188
+ });
3189
+ }
3190
+ // @__NO_SIDE_EFFECTS__
3191
+ function _unknown(Class) {
3192
+ return new Class({
3193
+ type: "unknown",
3194
+ });
3195
+ }
3196
+ // @__NO_SIDE_EFFECTS__
3197
+ function _never(Class, params) {
3198
+ return new Class({
3199
+ type: "never",
3200
+ ...normalizeParams(params),
3201
+ });
3202
+ }
3203
+ // @__NO_SIDE_EFFECTS__
3204
+ function _maxLength(maximum, params) {
3205
+ const ch = new $ZodCheckMaxLength({
3206
+ check: "max_length",
3207
+ ...normalizeParams(params),
3208
+ maximum,
3209
+ });
3210
+ return ch;
3211
+ }
3212
+ // @__NO_SIDE_EFFECTS__
3213
+ function _minLength(minimum, params) {
3214
+ return new $ZodCheckMinLength({
3215
+ check: "min_length",
3216
+ ...normalizeParams(params),
3217
+ minimum,
3218
+ });
3219
+ }
3220
+ // @__NO_SIDE_EFFECTS__
3221
+ function _length(length, params) {
3222
+ return new $ZodCheckLengthEquals({
3223
+ check: "length_equals",
3224
+ ...normalizeParams(params),
3225
+ length,
3226
+ });
3227
+ }
3228
+ // @__NO_SIDE_EFFECTS__
3229
+ function _regex(pattern, params) {
3230
+ return new $ZodCheckRegex({
3231
+ check: "string_format",
3232
+ format: "regex",
3233
+ ...normalizeParams(params),
3234
+ pattern,
3235
+ });
3236
+ }
3237
+ // @__NO_SIDE_EFFECTS__
3238
+ function _lowercase(params) {
3239
+ return new $ZodCheckLowerCase({
3240
+ check: "string_format",
3241
+ format: "lowercase",
3242
+ ...normalizeParams(params),
3243
+ });
3244
+ }
3245
+ // @__NO_SIDE_EFFECTS__
3246
+ function _uppercase(params) {
3247
+ return new $ZodCheckUpperCase({
3248
+ check: "string_format",
3249
+ format: "uppercase",
3250
+ ...normalizeParams(params),
3251
+ });
3252
+ }
3253
+ // @__NO_SIDE_EFFECTS__
3254
+ function _includes(includes, params) {
3255
+ return new $ZodCheckIncludes({
3256
+ check: "string_format",
3257
+ format: "includes",
3258
+ ...normalizeParams(params),
3259
+ includes,
3260
+ });
3261
+ }
3262
+ // @__NO_SIDE_EFFECTS__
3263
+ function _startsWith(prefix, params) {
3264
+ return new $ZodCheckStartsWith({
3265
+ check: "string_format",
3266
+ format: "starts_with",
3267
+ ...normalizeParams(params),
3268
+ prefix,
3269
+ });
3270
+ }
3271
+ // @__NO_SIDE_EFFECTS__
3272
+ function _endsWith(suffix, params) {
3273
+ return new $ZodCheckEndsWith({
3274
+ check: "string_format",
3275
+ format: "ends_with",
3276
+ ...normalizeParams(params),
3277
+ suffix,
3278
+ });
3279
+ }
3280
+ // @__NO_SIDE_EFFECTS__
3281
+ function _overwrite(tx) {
3282
+ return new $ZodCheckOverwrite({
3283
+ check: "overwrite",
3284
+ tx,
3285
+ });
3286
+ }
3287
+ // normalize
3288
+ // @__NO_SIDE_EFFECTS__
3289
+ function _normalize(form) {
3290
+ return _overwrite((input) => input.normalize(form));
3291
+ }
3292
+ // trim
3293
+ // @__NO_SIDE_EFFECTS__
3294
+ function _trim() {
3295
+ return _overwrite((input) => input.trim());
3296
+ }
3297
+ // toLowerCase
3298
+ // @__NO_SIDE_EFFECTS__
3299
+ function _toLowerCase() {
3300
+ return _overwrite((input) => input.toLowerCase());
3301
+ }
3302
+ // toUpperCase
3303
+ // @__NO_SIDE_EFFECTS__
3304
+ function _toUpperCase() {
3305
+ return _overwrite((input) => input.toUpperCase());
3306
+ }
3307
+ // slugify
3308
+ // @__NO_SIDE_EFFECTS__
3309
+ function _slugify() {
3310
+ return _overwrite((input) => slugify(input));
3311
+ }
3312
+ // @__NO_SIDE_EFFECTS__
3313
+ function _array(Class, element, params) {
3314
+ return new Class({
3315
+ type: "array",
3316
+ element,
3317
+ // get element() {
3318
+ // return element;
3319
+ // },
3320
+ ...normalizeParams(params),
3321
+ });
3322
+ }
3323
+ // same as _custom but defaults to abort:false
3324
+ // @__NO_SIDE_EFFECTS__
3325
+ function _refine(Class, fn, _params) {
3326
+ const schema = new Class({
3327
+ type: "custom",
3328
+ check: "custom",
3329
+ fn: fn,
3330
+ ...normalizeParams(_params),
3331
+ });
3332
+ return schema;
3333
+ }
3334
+ // @__NO_SIDE_EFFECTS__
3335
+ function _superRefine(fn, params) {
3336
+ const ch = _check((payload) => {
3337
+ payload.addIssue = (issue$1) => {
3338
+ if (typeof issue$1 === "string") {
3339
+ payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
3340
+ }
3341
+ else {
3342
+ // for Zod 3 backwards compatibility
3343
+ const _issue = issue$1;
3344
+ if (_issue.fatal)
3345
+ _issue.continue = false;
3346
+ _issue.code ?? (_issue.code = "custom");
3347
+ _issue.input ?? (_issue.input = payload.value);
3348
+ _issue.inst ?? (_issue.inst = ch);
3349
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
3350
+ payload.issues.push(issue(_issue));
3351
+ }
3352
+ };
3353
+ return fn(payload.value, payload);
3354
+ }, params);
3355
+ return ch;
3356
+ }
3357
+ // @__NO_SIDE_EFFECTS__
3358
+ function _check(fn, params) {
3359
+ const ch = new $ZodCheck({
3360
+ check: "custom",
3361
+ ...normalizeParams(params),
3362
+ });
3363
+ ch._zod.check = fn;
3364
+ return ch;
3365
+ }
3366
+
3367
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
3368
+ // return {
3369
+ // processor: inputs.processor,
3370
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
3371
+ // target: inputs.target ?? "draft-2020-12",
3372
+ // unrepresentable: inputs.unrepresentable ?? "throw",
3373
+ // };
3374
+ // }
3375
+ function initializeContext(params) {
3376
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
3377
+ let target = params?.target ?? "draft-2020-12";
3378
+ if (target === "draft-4")
3379
+ target = "draft-04";
3380
+ if (target === "draft-7")
3381
+ target = "draft-07";
3382
+ return {
3383
+ processors: params.processors ?? {},
3384
+ metadataRegistry: params?.metadata ?? globalRegistry,
3385
+ target,
3386
+ unrepresentable: params?.unrepresentable ?? "throw",
3387
+ override: params?.override ?? (() => { }),
3388
+ io: params?.io ?? "output",
3389
+ counter: 0,
3390
+ seen: new Map(),
3391
+ cycles: params?.cycles ?? "ref",
3392
+ reused: params?.reused ?? "inline",
3393
+ external: params?.external ?? undefined,
3394
+ };
3395
+ }
3396
+ function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
3397
+ var _a;
3398
+ const def = schema._zod.def;
3399
+ // check for schema in seens
3400
+ const seen = ctx.seen.get(schema);
3401
+ if (seen) {
3402
+ seen.count++;
3403
+ // check if cycle
3404
+ const isCycle = _params.schemaPath.includes(schema);
3405
+ if (isCycle) {
3406
+ seen.cycle = _params.path;
3407
+ }
3408
+ return seen.schema;
3409
+ }
3410
+ // initialize
3411
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
3412
+ ctx.seen.set(schema, result);
3413
+ // custom method overrides default behavior
3414
+ const overrideSchema = schema._zod.toJSONSchema?.();
3415
+ if (overrideSchema) {
3416
+ result.schema = overrideSchema;
3417
+ }
3418
+ else {
3419
+ const params = {
3420
+ ..._params,
3421
+ schemaPath: [..._params.schemaPath, schema],
3422
+ path: _params.path,
3423
+ };
3424
+ if (schema._zod.processJSONSchema) {
3425
+ schema._zod.processJSONSchema(ctx, result.schema, params);
3426
+ }
3427
+ else {
3428
+ const _json = result.schema;
3429
+ const processor = ctx.processors[def.type];
3430
+ if (!processor) {
3431
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
3432
+ }
3433
+ processor(schema, ctx, _json, params);
3434
+ }
3435
+ const parent = schema._zod.parent;
3436
+ if (parent) {
3437
+ // Also set ref if processor didn't (for inheritance)
3438
+ if (!result.ref)
3439
+ result.ref = parent;
3440
+ process(parent, ctx, params);
3441
+ ctx.seen.get(parent).isParent = true;
3442
+ }
3443
+ }
3444
+ // metadata
3445
+ const meta = ctx.metadataRegistry.get(schema);
3446
+ if (meta)
3447
+ Object.assign(result.schema, meta);
3448
+ if (ctx.io === "input" && isTransforming(schema)) {
3449
+ // examples/defaults only apply to output type of pipe
3450
+ delete result.schema.examples;
3451
+ delete result.schema.default;
3452
+ }
3453
+ // set prefault as default
3454
+ if (ctx.io === "input" && "_prefault" in result.schema)
3455
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
3456
+ delete result.schema._prefault;
3457
+ // pulling fresh from ctx.seen in case it was overwritten
3458
+ const _result = ctx.seen.get(schema);
3459
+ return _result.schema;
3460
+ }
3461
+ function extractDefs(ctx, schema
3462
+ // params: EmitParams
3463
+ ) {
3464
+ // iterate over seen map;
3465
+ const root = ctx.seen.get(schema);
3466
+ if (!root)
3467
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
3468
+ // Track ids to detect duplicates across different schemas
3469
+ const idToSchema = new Map();
3470
+ for (const entry of ctx.seen.entries()) {
3471
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3472
+ if (id) {
3473
+ const existing = idToSchema.get(id);
3474
+ if (existing && existing !== entry[0]) {
3475
+ throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
3476
+ }
3477
+ idToSchema.set(id, entry[0]);
3478
+ }
3479
+ }
3480
+ // returns a ref to the schema
3481
+ // defId will be empty if the ref points to an external schema (or #)
3482
+ const makeURI = (entry) => {
3483
+ // comparing the seen objects because sometimes
3484
+ // multiple schemas map to the same seen object.
3485
+ // e.g. lazy
3486
+ // external is configured
3487
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
3488
+ if (ctx.external) {
3489
+ const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
3490
+ // check if schema is in the external registry
3491
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
3492
+ if (externalId) {
3493
+ return { ref: uriGenerator(externalId) };
3494
+ }
3495
+ // otherwise, add to __shared
3496
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
3497
+ entry[1].defId = id; // set defId so it will be reused if needed
3498
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
3499
+ }
3500
+ if (entry[1] === root) {
3501
+ return { ref: "#" };
3502
+ }
3503
+ // self-contained schema
3504
+ const uriPrefix = `#`;
3505
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
3506
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
3507
+ return { defId, ref: defUriPrefix + defId };
3508
+ };
3509
+ // stored cached version in `def` property
3510
+ // remove all properties, set $ref
3511
+ const extractToDef = (entry) => {
3512
+ // if the schema is already a reference, do not extract it
3513
+ if (entry[1].schema.$ref) {
3514
+ return;
3515
+ }
3516
+ const seen = entry[1];
3517
+ const { ref, defId } = makeURI(entry);
3518
+ seen.def = { ...seen.schema };
3519
+ // defId won't be set if the schema is a reference to an external schema
3520
+ // or if the schema is the root schema
3521
+ if (defId)
3522
+ seen.defId = defId;
3523
+ // wipe away all properties except $ref
3524
+ const schema = seen.schema;
3525
+ for (const key in schema) {
3526
+ delete schema[key];
3527
+ }
3528
+ schema.$ref = ref;
3529
+ };
3530
+ // throw on cycles
3531
+ // break cycles
3532
+ if (ctx.cycles === "throw") {
3533
+ for (const entry of ctx.seen.entries()) {
3534
+ const seen = entry[1];
3535
+ if (seen.cycle) {
3536
+ throw new Error("Cycle detected: " +
3537
+ `#/${seen.cycle?.join("/")}/<root>` +
3538
+ '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
3539
+ }
3540
+ }
3541
+ }
3542
+ // extract schemas into $defs
3543
+ for (const entry of ctx.seen.entries()) {
3544
+ const seen = entry[1];
3545
+ // convert root schema to # $ref
3546
+ if (schema === entry[0]) {
3547
+ extractToDef(entry); // this has special handling for the root schema
3548
+ continue;
3549
+ }
3550
+ // extract schemas that are in the external registry
3551
+ if (ctx.external) {
3552
+ const ext = ctx.external.registry.get(entry[0])?.id;
3553
+ if (schema !== entry[0] && ext) {
3554
+ extractToDef(entry);
3555
+ continue;
3556
+ }
3557
+ }
3558
+ // extract schemas with `id` meta
3559
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
3560
+ if (id) {
3561
+ extractToDef(entry);
3562
+ continue;
3563
+ }
3564
+ // break cycles
3565
+ if (seen.cycle) {
3566
+ // any
3567
+ extractToDef(entry);
3568
+ continue;
3569
+ }
3570
+ // extract reused schemas
3571
+ if (seen.count > 1) {
3572
+ if (ctx.reused === "ref") {
3573
+ extractToDef(entry);
3574
+ // biome-ignore lint:
3575
+ continue;
3576
+ }
3577
+ }
3578
+ }
3579
+ }
3580
+ function finalize(ctx, schema) {
3581
+ const root = ctx.seen.get(schema);
3582
+ if (!root)
3583
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
3584
+ // flatten refs - inherit properties from parent schemas
3585
+ const flattenRef = (zodSchema) => {
3586
+ const seen = ctx.seen.get(zodSchema);
3587
+ // already processed
3588
+ if (seen.ref === null)
3589
+ return;
3590
+ const schema = seen.def ?? seen.schema;
3591
+ const _cached = { ...schema };
3592
+ const ref = seen.ref;
3593
+ seen.ref = null; // prevent infinite recursion
3594
+ if (ref) {
3595
+ flattenRef(ref);
3596
+ const refSeen = ctx.seen.get(ref);
3597
+ const refSchema = refSeen.schema;
3598
+ // merge referenced schema into current
3599
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
3600
+ // older drafts can't combine $ref with other properties
3601
+ schema.allOf = schema.allOf ?? [];
3602
+ schema.allOf.push(refSchema);
3603
+ }
3604
+ else {
3605
+ Object.assign(schema, refSchema);
3606
+ }
3607
+ // restore child's own properties (child wins)
3608
+ Object.assign(schema, _cached);
3609
+ const isParentRef = zodSchema._zod.parent === ref;
3610
+ // For parent chain, child is a refinement - remove parent-only properties
3611
+ if (isParentRef) {
3612
+ for (const key in schema) {
3613
+ if (key === "$ref" || key === "allOf")
3614
+ continue;
3615
+ if (!(key in _cached)) {
3616
+ delete schema[key];
3617
+ }
3618
+ }
3619
+ }
3620
+ // When ref was extracted to $defs, remove properties that match the definition
3621
+ if (refSchema.$ref && refSeen.def) {
3622
+ for (const key in schema) {
3623
+ if (key === "$ref" || key === "allOf")
3624
+ continue;
3625
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) {
3626
+ delete schema[key];
3627
+ }
3628
+ }
3629
+ }
3630
+ }
3631
+ // If parent was extracted (has $ref), propagate $ref to this schema
3632
+ // This handles cases like: readonly().meta({id}).describe()
3633
+ // where processor sets ref to innerType but parent should be referenced
3634
+ const parent = zodSchema._zod.parent;
3635
+ if (parent && parent !== ref) {
3636
+ // Ensure parent is processed first so its def has inherited properties
3637
+ flattenRef(parent);
3638
+ const parentSeen = ctx.seen.get(parent);
3639
+ if (parentSeen?.schema.$ref) {
3640
+ schema.$ref = parentSeen.schema.$ref;
3641
+ // De-duplicate with parent's definition
3642
+ if (parentSeen.def) {
3643
+ for (const key in schema) {
3644
+ if (key === "$ref" || key === "allOf")
3645
+ continue;
3646
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) {
3647
+ delete schema[key];
3648
+ }
3649
+ }
3650
+ }
3651
+ }
3652
+ }
3653
+ // execute overrides
3654
+ ctx.override({
3655
+ zodSchema: zodSchema,
3656
+ jsonSchema: schema,
3657
+ path: seen.path ?? [],
3658
+ });
3659
+ };
3660
+ for (const entry of [...ctx.seen.entries()].reverse()) {
3661
+ flattenRef(entry[0]);
3662
+ }
3663
+ const result = {};
3664
+ if (ctx.target === "draft-2020-12") {
3665
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
3666
+ }
3667
+ else if (ctx.target === "draft-07") {
3668
+ result.$schema = "http://json-schema.org/draft-07/schema#";
3669
+ }
3670
+ else if (ctx.target === "draft-04") {
3671
+ result.$schema = "http://json-schema.org/draft-04/schema#";
3672
+ }
3673
+ else if (ctx.target === "openapi-3.0") ;
3674
+ else ;
3675
+ if (ctx.external?.uri) {
3676
+ const id = ctx.external.registry.get(schema)?.id;
3677
+ if (!id)
3678
+ throw new Error("Schema is missing an `id` property");
3679
+ result.$id = ctx.external.uri(id);
3680
+ }
3681
+ Object.assign(result, root.def ?? root.schema);
3682
+ // The `id` in `.meta()` is a Zod-specific registration tag used to extract
3683
+ // schemas into $defs — it is not user-facing JSON Schema metadata. Strip it
3684
+ // from the output body where it would otherwise leak. The id is preserved
3685
+ // implicitly via the $defs key (and via $ref paths).
3686
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
3687
+ if (rootMetaId !== undefined && result.id === rootMetaId)
3688
+ delete result.id;
3689
+ // build defs object
3690
+ const defs = ctx.external?.defs ?? {};
3691
+ for (const entry of ctx.seen.entries()) {
3692
+ const seen = entry[1];
3693
+ if (seen.def && seen.defId) {
3694
+ if (seen.def.id === seen.defId)
3695
+ delete seen.def.id;
3696
+ defs[seen.defId] = seen.def;
3697
+ }
3698
+ }
3699
+ // set definitions in result
3700
+ if (ctx.external) ;
3701
+ else {
3702
+ if (Object.keys(defs).length > 0) {
3703
+ if (ctx.target === "draft-2020-12") {
3704
+ result.$defs = defs;
3705
+ }
3706
+ else {
3707
+ result.definitions = defs;
3708
+ }
3709
+ }
3710
+ }
3711
+ try {
3712
+ // this "finalizes" this schema and ensures all cycles are removed
3713
+ // each call to finalize() is functionally independent
3714
+ // though the seen map is shared
3715
+ const finalized = JSON.parse(JSON.stringify(result));
3716
+ Object.defineProperty(finalized, "~standard", {
3717
+ value: {
3718
+ ...schema["~standard"],
3719
+ jsonSchema: {
3720
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
3721
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors),
3722
+ },
3723
+ },
3724
+ enumerable: false,
3725
+ writable: false,
3726
+ });
3727
+ return finalized;
3728
+ }
3729
+ catch (_err) {
3730
+ throw new Error("Error converting schema to JSON.");
3731
+ }
3732
+ }
3733
+ function isTransforming(_schema, _ctx) {
3734
+ const ctx = _ctx ?? { seen: new Set() };
3735
+ if (ctx.seen.has(_schema))
3736
+ return false;
3737
+ ctx.seen.add(_schema);
3738
+ const def = _schema._zod.def;
3739
+ if (def.type === "transform")
3740
+ return true;
3741
+ if (def.type === "array")
3742
+ return isTransforming(def.element, ctx);
3743
+ if (def.type === "set")
3744
+ return isTransforming(def.valueType, ctx);
3745
+ if (def.type === "lazy")
3746
+ return isTransforming(def.getter(), ctx);
3747
+ if (def.type === "promise" ||
3748
+ def.type === "optional" ||
3749
+ def.type === "nonoptional" ||
3750
+ def.type === "nullable" ||
3751
+ def.type === "readonly" ||
3752
+ def.type === "default" ||
3753
+ def.type === "prefault") {
3754
+ return isTransforming(def.innerType, ctx);
3755
+ }
3756
+ if (def.type === "intersection") {
3757
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
3758
+ }
3759
+ if (def.type === "record" || def.type === "map") {
3760
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
3761
+ }
3762
+ if (def.type === "pipe") {
3763
+ if (_schema._zod.traits.has("$ZodCodec"))
3764
+ return true;
3765
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
3766
+ }
3767
+ if (def.type === "object") {
3768
+ for (const key in def.shape) {
3769
+ if (isTransforming(def.shape[key], ctx))
3770
+ return true;
3771
+ }
3772
+ return false;
3773
+ }
3774
+ if (def.type === "union") {
3775
+ for (const option of def.options) {
3776
+ if (isTransforming(option, ctx))
3777
+ return true;
3778
+ }
3779
+ return false;
3780
+ }
3781
+ if (def.type === "tuple") {
3782
+ for (const item of def.items) {
3783
+ if (isTransforming(item, ctx))
3784
+ return true;
3785
+ }
3786
+ if (def.rest && isTransforming(def.rest, ctx))
3787
+ return true;
3788
+ return false;
3789
+ }
3790
+ return false;
3791
+ }
3792
+ /**
3793
+ * Creates a toJSONSchema method for a schema instance.
3794
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
3795
+ */
3796
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
3797
+ const ctx = initializeContext({ ...params, processors });
3798
+ process(schema, ctx);
3799
+ extractDefs(ctx, schema);
3800
+ return finalize(ctx, schema);
3801
+ };
3802
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
3803
+ const { libraryOptions, target } = params ?? {};
3804
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors });
3805
+ process(schema, ctx);
3806
+ extractDefs(ctx, schema);
3807
+ return finalize(ctx, schema);
3808
+ };
3809
+
3810
+ const formatMap = {
3811
+ guid: "uuid",
3812
+ url: "uri",
3813
+ datetime: "date-time",
3814
+ json_string: "json-string",
3815
+ regex: "", // do not set
3816
+ };
3817
+ // ==================== SIMPLE TYPE PROCESSORS ====================
3818
+ const stringProcessor = (schema, ctx, _json, _params) => {
3819
+ const json = _json;
3820
+ json.type = "string";
3821
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
3822
+ .bag;
3823
+ if (typeof minimum === "number")
3824
+ json.minLength = minimum;
3825
+ if (typeof maximum === "number")
3826
+ json.maxLength = maximum;
3827
+ // custom pattern overrides format
3828
+ if (format) {
3829
+ json.format = formatMap[format] ?? format;
3830
+ if (json.format === "")
3831
+ delete json.format; // empty format is not valid
3832
+ // JSON Schema format: "time" requires a full time with offset or Z
3833
+ // z.iso.time() does not include timezone information, so format: "time" should never be used
3834
+ if (format === "time") {
3835
+ delete json.format;
3836
+ }
3837
+ }
3838
+ if (contentEncoding)
3839
+ json.contentEncoding = contentEncoding;
3840
+ if (patterns && patterns.size > 0) {
3841
+ const regexes = [...patterns];
3842
+ if (regexes.length === 1)
3843
+ json.pattern = regexes[0].source;
3844
+ else if (regexes.length > 1) {
3845
+ json.allOf = [
3846
+ ...regexes.map((regex) => ({
3847
+ ...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
3848
+ ? { type: "string" }
3849
+ : {}),
3850
+ pattern: regex.source,
3851
+ })),
3852
+ ];
3853
+ }
3854
+ }
3855
+ };
3856
+ const neverProcessor = (_schema, _ctx, json, _params) => {
3857
+ json.not = {};
3858
+ };
3859
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
3860
+ // empty schema accepts anything
3861
+ };
3862
+ const enumProcessor = (schema, _ctx, json, _params) => {
3863
+ const def = schema._zod.def;
3864
+ const values = getEnumValues(def.entries);
3865
+ // Number enums can have both string and number values
3866
+ if (values.every((v) => typeof v === "number"))
3867
+ json.type = "number";
3868
+ if (values.every((v) => typeof v === "string"))
3869
+ json.type = "string";
3870
+ json.enum = values;
3871
+ };
3872
+ const customProcessor = (_schema, ctx, _json, _params) => {
3873
+ if (ctx.unrepresentable === "throw") {
3874
+ throw new Error("Custom types cannot be represented in JSON Schema");
3875
+ }
3876
+ };
3877
+ const transformProcessor = (_schema, ctx, _json, _params) => {
3878
+ if (ctx.unrepresentable === "throw") {
3879
+ throw new Error("Transforms cannot be represented in JSON Schema");
3880
+ }
3881
+ };
3882
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
3883
+ const arrayProcessor = (schema, ctx, _json, params) => {
3884
+ const json = _json;
3885
+ const def = schema._zod.def;
3886
+ const { minimum, maximum } = schema._zod.bag;
3887
+ if (typeof minimum === "number")
3888
+ json.minItems = minimum;
3889
+ if (typeof maximum === "number")
3890
+ json.maxItems = maximum;
3891
+ json.type = "array";
3892
+ json.items = process(def.element, ctx, {
3893
+ ...params,
3894
+ path: [...params.path, "items"],
3895
+ });
3896
+ };
3897
+ const objectProcessor = (schema, ctx, _json, params) => {
3898
+ const json = _json;
3899
+ const def = schema._zod.def;
3900
+ json.type = "object";
3901
+ json.properties = {};
3902
+ const shape = def.shape;
3903
+ for (const key in shape) {
3904
+ json.properties[key] = process(shape[key], ctx, {
3905
+ ...params,
3906
+ path: [...params.path, "properties", key],
3907
+ });
3908
+ }
3909
+ // required keys
3910
+ const allKeys = new Set(Object.keys(shape));
3911
+ const requiredKeys = new Set([...allKeys].filter((key) => {
3912
+ const v = def.shape[key]._zod;
3913
+ if (ctx.io === "input") {
3914
+ return v.optin === undefined;
3915
+ }
3916
+ else {
3917
+ return v.optout === undefined;
3918
+ }
3919
+ }));
3920
+ if (requiredKeys.size > 0) {
3921
+ json.required = Array.from(requiredKeys);
3922
+ }
3923
+ // catchall
3924
+ if (def.catchall?._zod.def.type === "never") {
3925
+ // strict
3926
+ json.additionalProperties = false;
3927
+ }
3928
+ else if (!def.catchall) {
3929
+ // regular
3930
+ if (ctx.io === "output")
3931
+ json.additionalProperties = false;
3932
+ }
3933
+ else if (def.catchall) {
3934
+ json.additionalProperties = process(def.catchall, ctx, {
3935
+ ...params,
3936
+ path: [...params.path, "additionalProperties"],
3937
+ });
3938
+ }
3939
+ };
3940
+ const unionProcessor = (schema, ctx, json, params) => {
3941
+ const def = schema._zod.def;
3942
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
3943
+ // This includes both z.xor() and discriminated unions
3944
+ const isExclusive = def.inclusive === false;
3945
+ const options = def.options.map((x, i) => process(x, ctx, {
3946
+ ...params,
3947
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
3948
+ }));
3949
+ if (isExclusive) {
3950
+ json.oneOf = options;
3951
+ }
3952
+ else {
3953
+ json.anyOf = options;
3954
+ }
3955
+ };
3956
+ const intersectionProcessor = (schema, ctx, json, params) => {
3957
+ const def = schema._zod.def;
3958
+ const a = process(def.left, ctx, {
3959
+ ...params,
3960
+ path: [...params.path, "allOf", 0],
3961
+ });
3962
+ const b = process(def.right, ctx, {
3963
+ ...params,
3964
+ path: [...params.path, "allOf", 1],
3965
+ });
3966
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
3967
+ const allOf = [
3968
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
3969
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
3970
+ ];
3971
+ json.allOf = allOf;
3972
+ };
3973
+ const nullableProcessor = (schema, ctx, json, params) => {
3974
+ const def = schema._zod.def;
3975
+ const inner = process(def.innerType, ctx, params);
3976
+ const seen = ctx.seen.get(schema);
3977
+ if (ctx.target === "openapi-3.0") {
3978
+ seen.ref = def.innerType;
3979
+ json.nullable = true;
3980
+ }
3981
+ else {
3982
+ json.anyOf = [inner, { type: "null" }];
3983
+ }
3984
+ };
3985
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
3986
+ const def = schema._zod.def;
3987
+ process(def.innerType, ctx, params);
3988
+ const seen = ctx.seen.get(schema);
3989
+ seen.ref = def.innerType;
3990
+ };
3991
+ const defaultProcessor = (schema, ctx, json, params) => {
3992
+ const def = schema._zod.def;
3993
+ process(def.innerType, ctx, params);
3994
+ const seen = ctx.seen.get(schema);
3995
+ seen.ref = def.innerType;
3996
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
3997
+ };
3998
+ const prefaultProcessor = (schema, ctx, json, params) => {
3999
+ const def = schema._zod.def;
4000
+ process(def.innerType, ctx, params);
4001
+ const seen = ctx.seen.get(schema);
4002
+ seen.ref = def.innerType;
4003
+ if (ctx.io === "input")
4004
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
4005
+ };
4006
+ const catchProcessor = (schema, ctx, json, params) => {
4007
+ const def = schema._zod.def;
4008
+ process(def.innerType, ctx, params);
4009
+ const seen = ctx.seen.get(schema);
4010
+ seen.ref = def.innerType;
4011
+ let catchValue;
4012
+ try {
4013
+ catchValue = def.catchValue(undefined);
4014
+ }
4015
+ catch {
4016
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
4017
+ }
4018
+ json.default = catchValue;
4019
+ };
4020
+ const pipeProcessor = (schema, ctx, _json, params) => {
4021
+ const def = schema._zod.def;
4022
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
4023
+ const innerType = ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
4024
+ process(innerType, ctx, params);
4025
+ const seen = ctx.seen.get(schema);
4026
+ seen.ref = innerType;
4027
+ };
4028
+ const readonlyProcessor = (schema, ctx, json, params) => {
4029
+ const def = schema._zod.def;
4030
+ process(def.innerType, ctx, params);
4031
+ const seen = ctx.seen.get(schema);
4032
+ seen.ref = def.innerType;
4033
+ json.readOnly = true;
4034
+ };
4035
+ const optionalProcessor = (schema, ctx, _json, params) => {
4036
+ const def = schema._zod.def;
4037
+ process(def.innerType, ctx, params);
4038
+ const seen = ctx.seen.get(schema);
4039
+ seen.ref = def.innerType;
4040
+ };
4041
+
4042
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
4043
+ $ZodISODateTime.init(inst, def);
4044
+ ZodStringFormat.init(inst, def);
4045
+ });
4046
+ function datetime(params) {
4047
+ return _isoDateTime(ZodISODateTime, params);
4048
+ }
4049
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
4050
+ $ZodISODate.init(inst, def);
4051
+ ZodStringFormat.init(inst, def);
4052
+ });
4053
+ function date(params) {
4054
+ return _isoDate(ZodISODate, params);
4055
+ }
4056
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
4057
+ $ZodISOTime.init(inst, def);
4058
+ ZodStringFormat.init(inst, def);
4059
+ });
4060
+ function time(params) {
4061
+ return _isoTime(ZodISOTime, params);
4062
+ }
4063
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
4064
+ $ZodISODuration.init(inst, def);
4065
+ ZodStringFormat.init(inst, def);
4066
+ });
4067
+ function duration(params) {
4068
+ return _isoDuration(ZodISODuration, params);
4069
+ }
4070
+
4071
+ const initializer = (inst, issues) => {
4072
+ $ZodError.init(inst, issues);
4073
+ inst.name = "ZodError";
4074
+ Object.defineProperties(inst, {
4075
+ format: {
4076
+ value: (mapper) => formatError(inst, mapper),
4077
+ // enumerable: false,
4078
+ },
4079
+ flatten: {
4080
+ value: (mapper) => flattenError(inst, mapper),
4081
+ // enumerable: false,
4082
+ },
4083
+ addIssue: {
4084
+ value: (issue) => {
4085
+ inst.issues.push(issue);
4086
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
4087
+ },
4088
+ // enumerable: false,
4089
+ },
4090
+ addIssues: {
4091
+ value: (issues) => {
4092
+ inst.issues.push(...issues);
4093
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
4094
+ },
4095
+ // enumerable: false,
4096
+ },
4097
+ isEmpty: {
4098
+ get() {
4099
+ return inst.issues.length === 0;
4100
+ },
4101
+ // enumerable: false,
4102
+ },
4103
+ });
4104
+ // Object.defineProperty(inst, "isEmpty", {
4105
+ // get() {
4106
+ // return inst.issues.length === 0;
4107
+ // },
4108
+ // });
4109
+ };
4110
+ const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, {
4111
+ Parent: Error,
4112
+ });
4113
+ // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
4114
+ // export type ErrorMapCtx = core.$ZodErrorMapCtx;
4115
+
4116
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
4117
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
4118
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
4119
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
4120
+ // Codec functions
4121
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
4122
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
4123
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
4124
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
4125
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
4126
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
4127
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
4128
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
4129
+
4130
+ // Lazy-bind builder methods.
4131
+ //
4132
+ // Builder methods (`.optional`, `.array`, `.refine`, ...) live as
4133
+ // non-enumerable getters on each concrete schema constructor's
4134
+ // prototype. On first access from an instance the getter allocates
4135
+ // `fn.bind(this)` and caches it as an own property on that instance,
4136
+ // so detached usage (`const m = schema.optional; m()`) still works
4137
+ // and the per-instance allocation only happens for methods actually
4138
+ // touched.
4139
+ //
4140
+ // One install per (prototype, group), memoized by `_installedGroups`.
4141
+ const _installedGroups = /* @__PURE__ */ new WeakMap();
4142
+ function _installLazyMethods(inst, group, methods) {
4143
+ const proto = Object.getPrototypeOf(inst);
4144
+ let installed = _installedGroups.get(proto);
4145
+ if (!installed) {
4146
+ installed = new Set();
4147
+ _installedGroups.set(proto, installed);
4148
+ }
4149
+ if (installed.has(group))
4150
+ return;
4151
+ installed.add(group);
4152
+ for (const key in methods) {
4153
+ const fn = methods[key];
4154
+ Object.defineProperty(proto, key, {
4155
+ configurable: true,
4156
+ enumerable: false,
4157
+ get() {
4158
+ const bound = fn.bind(this);
4159
+ Object.defineProperty(this, key, {
4160
+ configurable: true,
4161
+ writable: true,
4162
+ enumerable: true,
4163
+ value: bound,
4164
+ });
4165
+ return bound;
4166
+ },
4167
+ set(v) {
4168
+ Object.defineProperty(this, key, {
4169
+ configurable: true,
4170
+ writable: true,
4171
+ enumerable: true,
4172
+ value: v,
4173
+ });
4174
+ },
4175
+ });
4176
+ }
4177
+ }
4178
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4179
+ $ZodType.init(inst, def);
4180
+ Object.assign(inst["~standard"], {
4181
+ jsonSchema: {
4182
+ input: createStandardJSONSchemaMethod(inst, "input"),
4183
+ output: createStandardJSONSchemaMethod(inst, "output"),
4184
+ },
4185
+ });
4186
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
4187
+ inst.def = def;
4188
+ inst.type = def.type;
4189
+ Object.defineProperty(inst, "_def", { value: def });
4190
+ // Parse-family is intentionally kept as per-instance closures: these are
4191
+ // the hot path AND the most-detached methods (`arr.map(schema.parse)`,
4192
+ // `const { parse } = schema`, etc.). Eager closures here mean callers pay
4193
+ // ~12 closure allocations per schema but get monomorphic call sites and
4194
+ // detached usage that "just works".
4195
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
4196
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
4197
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
4198
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
4199
+ inst.spa = inst.safeParseAsync;
4200
+ inst.encode = (data, params) => encode(inst, data, params);
4201
+ inst.decode = (data, params) => decode(inst, data, params);
4202
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
4203
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
4204
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
4205
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
4206
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
4207
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
4208
+ // All builder methods are placed on the internal prototype as lazy-bind
4209
+ // getters. On first access per-instance, a bound thunk is allocated and
4210
+ // cached as an own property; subsequent accesses skip the getter. This
4211
+ // means: no per-instance allocation for unused methods, full
4212
+ // detachability preserved (`const m = schema.optional; m()` works), and
4213
+ // shared underlying function references across all instances.
4214
+ _installLazyMethods(inst, "ZodType", {
4215
+ check(...chks) {
4216
+ const def = this.def;
4217
+ return this.clone(mergeDefs(def, {
4218
+ checks: [
4219
+ ...(def.checks ?? []),
4220
+ ...chks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
4221
+ ],
4222
+ }), { parent: true });
4223
+ },
4224
+ with(...chks) {
4225
+ return this.check(...chks);
4226
+ },
4227
+ clone(def, params) {
4228
+ return clone(this, def, params);
4229
+ },
4230
+ brand() {
4231
+ return this;
4232
+ },
4233
+ register(reg, meta) {
4234
+ reg.add(this, meta);
4235
+ return this;
4236
+ },
4237
+ refine(check, params) {
4238
+ return this.check(refine(check, params));
4239
+ },
4240
+ superRefine(refinement, params) {
4241
+ return this.check(superRefine(refinement, params));
4242
+ },
4243
+ overwrite(fn) {
4244
+ return this.check(_overwrite(fn));
4245
+ },
4246
+ optional() {
4247
+ return optional(this);
4248
+ },
4249
+ exactOptional() {
4250
+ return exactOptional(this);
4251
+ },
4252
+ nullable() {
4253
+ return nullable(this);
4254
+ },
4255
+ nullish() {
4256
+ return optional(nullable(this));
4257
+ },
4258
+ nonoptional(params) {
4259
+ return nonoptional(this, params);
4260
+ },
4261
+ array() {
4262
+ return array(this);
4263
+ },
4264
+ or(arg) {
4265
+ return union([this, arg]);
4266
+ },
4267
+ and(arg) {
4268
+ return intersection(this, arg);
4269
+ },
4270
+ transform(tx) {
4271
+ return pipe(this, transform(tx));
4272
+ },
4273
+ default(d) {
4274
+ return _default(this, d);
4275
+ },
4276
+ prefault(d) {
4277
+ return prefault(this, d);
4278
+ },
4279
+ catch(params) {
4280
+ return _catch(this, params);
4281
+ },
4282
+ pipe(target) {
4283
+ return pipe(this, target);
4284
+ },
4285
+ readonly() {
4286
+ return readonly(this);
4287
+ },
4288
+ describe(description) {
4289
+ const cl = this.clone();
4290
+ globalRegistry.add(cl, { description });
4291
+ return cl;
4292
+ },
4293
+ meta(...args) {
4294
+ // overloaded: meta() returns the registered metadata, meta(data)
4295
+ // returns a clone with `data` registered. The mapped type picks
4296
+ // up the second overload, so we accept variadic any-args and
4297
+ // return `any` to satisfy both at runtime.
4298
+ if (args.length === 0)
4299
+ return globalRegistry.get(this);
4300
+ const cl = this.clone();
4301
+ globalRegistry.add(cl, args[0]);
4302
+ return cl;
4303
+ },
4304
+ isOptional() {
4305
+ return this.safeParse(undefined).success;
4306
+ },
4307
+ isNullable() {
4308
+ return this.safeParse(null).success;
4309
+ },
4310
+ apply(fn) {
4311
+ return fn(this);
4312
+ },
4313
+ });
4314
+ Object.defineProperty(inst, "description", {
4315
+ get() {
4316
+ return globalRegistry.get(inst)?.description;
4317
+ },
4318
+ configurable: true,
4319
+ });
4320
+ return inst;
4321
+ });
4322
+ /** @internal */
4323
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
4324
+ $ZodString.init(inst, def);
4325
+ ZodType.init(inst, def);
4326
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
4327
+ const bag = inst._zod.bag;
4328
+ inst.format = bag.format ?? null;
4329
+ inst.minLength = bag.minimum ?? null;
4330
+ inst.maxLength = bag.maximum ?? null;
4331
+ _installLazyMethods(inst, "_ZodString", {
4332
+ regex(...args) {
4333
+ return this.check(_regex(...args));
4334
+ },
4335
+ includes(...args) {
4336
+ return this.check(_includes(...args));
4337
+ },
4338
+ startsWith(...args) {
4339
+ return this.check(_startsWith(...args));
4340
+ },
4341
+ endsWith(...args) {
4342
+ return this.check(_endsWith(...args));
4343
+ },
4344
+ min(...args) {
4345
+ return this.check(_minLength(...args));
4346
+ },
4347
+ max(...args) {
4348
+ return this.check(_maxLength(...args));
4349
+ },
4350
+ length(...args) {
4351
+ return this.check(_length(...args));
4352
+ },
4353
+ nonempty(...args) {
4354
+ return this.check(_minLength(1, ...args));
4355
+ },
4356
+ lowercase(params) {
4357
+ return this.check(_lowercase(params));
4358
+ },
4359
+ uppercase(params) {
4360
+ return this.check(_uppercase(params));
4361
+ },
4362
+ trim() {
4363
+ return this.check(_trim());
4364
+ },
4365
+ normalize(...args) {
4366
+ return this.check(_normalize(...args));
4367
+ },
4368
+ toLowerCase() {
4369
+ return this.check(_toLowerCase());
4370
+ },
4371
+ toUpperCase() {
4372
+ return this.check(_toUpperCase());
4373
+ },
4374
+ slugify() {
4375
+ return this.check(_slugify());
4376
+ },
4377
+ });
4378
+ });
4379
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
4380
+ $ZodString.init(inst, def);
4381
+ _ZodString.init(inst, def);
4382
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
4383
+ inst.url = (params) => inst.check(_url(ZodURL, params));
4384
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
4385
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
4386
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
4387
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
4388
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
4389
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
4390
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
4391
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
4392
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
4393
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
4394
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
4395
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
4396
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
4397
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
4398
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
4399
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
4400
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
4401
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
4402
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
4403
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
4404
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
4405
+ // iso
4406
+ inst.datetime = (params) => inst.check(datetime(params));
4407
+ inst.date = (params) => inst.check(date(params));
4408
+ inst.time = (params) => inst.check(time(params));
4409
+ inst.duration = (params) => inst.check(duration(params));
4410
+ });
4411
+ function string(params) {
4412
+ return _string(ZodString, params);
4413
+ }
4414
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
4415
+ $ZodStringFormat.init(inst, def);
4416
+ _ZodString.init(inst, def);
4417
+ });
4418
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
4419
+ // ZodStringFormat.init(inst, def);
4420
+ $ZodEmail.init(inst, def);
4421
+ ZodStringFormat.init(inst, def);
4422
+ });
4423
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
4424
+ // ZodStringFormat.init(inst, def);
4425
+ $ZodGUID.init(inst, def);
4426
+ ZodStringFormat.init(inst, def);
4427
+ });
4428
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
4429
+ // ZodStringFormat.init(inst, def);
4430
+ $ZodUUID.init(inst, def);
4431
+ ZodStringFormat.init(inst, def);
4432
+ });
4433
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
4434
+ // ZodStringFormat.init(inst, def);
4435
+ $ZodURL.init(inst, def);
4436
+ ZodStringFormat.init(inst, def);
4437
+ });
4438
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
4439
+ // ZodStringFormat.init(inst, def);
4440
+ $ZodEmoji.init(inst, def);
4441
+ ZodStringFormat.init(inst, def);
4442
+ });
4443
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
4444
+ // ZodStringFormat.init(inst, def);
4445
+ $ZodNanoID.init(inst, def);
4446
+ ZodStringFormat.init(inst, def);
4447
+ });
4448
+ /**
4449
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
4450
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
4451
+ * See https://github.com/paralleldrive/cuid.
4452
+ */
4453
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
4454
+ // ZodStringFormat.init(inst, def);
4455
+ $ZodCUID.init(inst, def);
4456
+ ZodStringFormat.init(inst, def);
4457
+ });
4458
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
4459
+ // ZodStringFormat.init(inst, def);
4460
+ $ZodCUID2.init(inst, def);
4461
+ ZodStringFormat.init(inst, def);
4462
+ });
4463
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
4464
+ // ZodStringFormat.init(inst, def);
4465
+ $ZodULID.init(inst, def);
4466
+ ZodStringFormat.init(inst, def);
4467
+ });
4468
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
4469
+ // ZodStringFormat.init(inst, def);
4470
+ $ZodXID.init(inst, def);
4471
+ ZodStringFormat.init(inst, def);
4472
+ });
4473
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
4474
+ // ZodStringFormat.init(inst, def);
4475
+ $ZodKSUID.init(inst, def);
4476
+ ZodStringFormat.init(inst, def);
4477
+ });
4478
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
4479
+ // ZodStringFormat.init(inst, def);
4480
+ $ZodIPv4.init(inst, def);
4481
+ ZodStringFormat.init(inst, def);
4482
+ });
4483
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
4484
+ // ZodStringFormat.init(inst, def);
4485
+ $ZodIPv6.init(inst, def);
4486
+ ZodStringFormat.init(inst, def);
4487
+ });
4488
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
4489
+ $ZodCIDRv4.init(inst, def);
4490
+ ZodStringFormat.init(inst, def);
4491
+ });
4492
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
4493
+ $ZodCIDRv6.init(inst, def);
4494
+ ZodStringFormat.init(inst, def);
4495
+ });
4496
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
4497
+ // ZodStringFormat.init(inst, def);
4498
+ $ZodBase64.init(inst, def);
4499
+ ZodStringFormat.init(inst, def);
4500
+ });
4501
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
4502
+ // ZodStringFormat.init(inst, def);
4503
+ $ZodBase64URL.init(inst, def);
4504
+ ZodStringFormat.init(inst, def);
4505
+ });
4506
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
4507
+ // ZodStringFormat.init(inst, def);
4508
+ $ZodE164.init(inst, def);
4509
+ ZodStringFormat.init(inst, def);
4510
+ });
4511
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
4512
+ // ZodStringFormat.init(inst, def);
4513
+ $ZodJWT.init(inst, def);
4514
+ ZodStringFormat.init(inst, def);
4515
+ });
4516
+ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
4517
+ $ZodUnknown.init(inst, def);
4518
+ ZodType.init(inst, def);
4519
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
4520
+ });
4521
+ function unknown() {
4522
+ return _unknown(ZodUnknown);
4523
+ }
4524
+ const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
4525
+ $ZodNever.init(inst, def);
4526
+ ZodType.init(inst, def);
4527
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
4528
+ });
4529
+ function never(params) {
4530
+ return _never(ZodNever, params);
4531
+ }
4532
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
4533
+ $ZodArray.init(inst, def);
4534
+ ZodType.init(inst, def);
4535
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
4536
+ inst.element = def.element;
4537
+ _installLazyMethods(inst, "ZodArray", {
4538
+ min(n, params) {
4539
+ return this.check(_minLength(n, params));
4540
+ },
4541
+ nonempty(params) {
4542
+ return this.check(_minLength(1, params));
4543
+ },
4544
+ max(n, params) {
4545
+ return this.check(_maxLength(n, params));
4546
+ },
4547
+ length(n, params) {
4548
+ return this.check(_length(n, params));
4549
+ },
4550
+ unwrap() {
4551
+ return this.element;
4552
+ },
4553
+ });
4554
+ });
4555
+ function array(element, params) {
4556
+ return _array(ZodArray, element, params);
4557
+ }
4558
+ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
4559
+ $ZodObjectJIT.init(inst, def);
4560
+ ZodType.init(inst, def);
4561
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
4562
+ defineLazy(inst, "shape", () => {
4563
+ return def.shape;
4564
+ });
4565
+ _installLazyMethods(inst, "ZodObject", {
4566
+ keyof() {
4567
+ return _enum(Object.keys(this._zod.def.shape));
4568
+ },
4569
+ catchall(catchall) {
4570
+ return this.clone({ ...this._zod.def, catchall: catchall });
4571
+ },
4572
+ passthrough() {
4573
+ return this.clone({ ...this._zod.def, catchall: unknown() });
4574
+ },
4575
+ loose() {
4576
+ return this.clone({ ...this._zod.def, catchall: unknown() });
4577
+ },
4578
+ strict() {
4579
+ return this.clone({ ...this._zod.def, catchall: never() });
4580
+ },
4581
+ strip() {
4582
+ return this.clone({ ...this._zod.def, catchall: undefined });
4583
+ },
4584
+ extend(incoming) {
4585
+ return extend(this, incoming);
4586
+ },
4587
+ safeExtend(incoming) {
4588
+ return safeExtend(this, incoming);
4589
+ },
4590
+ merge(other) {
4591
+ return merge(this, other);
4592
+ },
4593
+ pick(mask) {
4594
+ return pick(this, mask);
4595
+ },
4596
+ omit(mask) {
4597
+ return omit(this, mask);
4598
+ },
4599
+ partial(...args) {
4600
+ return partial(ZodOptional, this, args[0]);
4601
+ },
4602
+ required(...args) {
4603
+ return required(ZodNonOptional, this, args[0]);
4604
+ },
4605
+ });
4606
+ });
4607
+ function object(shape, params) {
4608
+ const def = {
4609
+ type: "object",
4610
+ shape: shape ?? {},
4611
+ ...normalizeParams(params),
4612
+ };
4613
+ return new ZodObject(def);
4614
+ }
4615
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
4616
+ $ZodUnion.init(inst, def);
4617
+ ZodType.init(inst, def);
4618
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
4619
+ inst.options = def.options;
4620
+ });
4621
+ function union(options, params) {
4622
+ return new ZodUnion({
4623
+ type: "union",
4624
+ options: options,
4625
+ ...normalizeParams(params),
4626
+ });
4627
+ }
4628
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
4629
+ $ZodIntersection.init(inst, def);
4630
+ ZodType.init(inst, def);
4631
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
4632
+ });
4633
+ function intersection(left, right) {
4634
+ return new ZodIntersection({
4635
+ type: "intersection",
4636
+ left: left,
4637
+ right: right,
4638
+ });
4639
+ }
4640
+ const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
4641
+ $ZodEnum.init(inst, def);
4642
+ ZodType.init(inst, def);
4643
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
4644
+ inst.enum = def.entries;
4645
+ inst.options = Object.values(def.entries);
4646
+ const keys = new Set(Object.keys(def.entries));
4647
+ inst.extract = (values, params) => {
4648
+ const newEntries = {};
4649
+ for (const value of values) {
4650
+ if (keys.has(value)) {
4651
+ newEntries[value] = def.entries[value];
4652
+ }
4653
+ else
4654
+ throw new Error(`Key ${value} not found in enum`);
4655
+ }
4656
+ return new ZodEnum({
4657
+ ...def,
4658
+ checks: [],
4659
+ ...normalizeParams(params),
4660
+ entries: newEntries,
4661
+ });
4662
+ };
4663
+ inst.exclude = (values, params) => {
4664
+ const newEntries = { ...def.entries };
4665
+ for (const value of values) {
4666
+ if (keys.has(value)) {
4667
+ delete newEntries[value];
4668
+ }
4669
+ else
4670
+ throw new Error(`Key ${value} not found in enum`);
4671
+ }
4672
+ return new ZodEnum({
4673
+ ...def,
4674
+ checks: [],
4675
+ ...normalizeParams(params),
4676
+ entries: newEntries,
4677
+ });
4678
+ };
4679
+ });
4680
+ function _enum(values, params) {
4681
+ const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
4682
+ return new ZodEnum({
4683
+ type: "enum",
4684
+ entries,
4685
+ ...normalizeParams(params),
4686
+ });
4687
+ }
4688
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
4689
+ $ZodTransform.init(inst, def);
4690
+ ZodType.init(inst, def);
4691
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
4692
+ inst._zod.parse = (payload, _ctx) => {
4693
+ if (_ctx.direction === "backward") {
4694
+ throw new $ZodEncodeError(inst.constructor.name);
4695
+ }
4696
+ payload.addIssue = (issue$1) => {
4697
+ if (typeof issue$1 === "string") {
4698
+ payload.issues.push(issue(issue$1, payload.value, def));
4699
+ }
4700
+ else {
4701
+ // for Zod 3 backwards compatibility
4702
+ const _issue = issue$1;
4703
+ if (_issue.fatal)
4704
+ _issue.continue = false;
4705
+ _issue.code ?? (_issue.code = "custom");
4706
+ _issue.input ?? (_issue.input = payload.value);
4707
+ _issue.inst ?? (_issue.inst = inst);
4708
+ // _issue.continue ??= true;
4709
+ payload.issues.push(issue(_issue));
4710
+ }
4711
+ };
4712
+ const output = def.transform(payload.value, payload);
4713
+ if (output instanceof Promise) {
4714
+ return output.then((output) => {
4715
+ payload.value = output;
4716
+ payload.fallback = true;
4717
+ return payload;
4718
+ });
4719
+ }
4720
+ payload.value = output;
4721
+ payload.fallback = true;
4722
+ return payload;
4723
+ };
4724
+ });
4725
+ function transform(fn) {
4726
+ return new ZodTransform({
4727
+ type: "transform",
4728
+ transform: fn,
4729
+ });
4730
+ }
4731
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
4732
+ $ZodOptional.init(inst, def);
4733
+ ZodType.init(inst, def);
4734
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4735
+ inst.unwrap = () => inst._zod.def.innerType;
4736
+ });
4737
+ function optional(innerType) {
4738
+ return new ZodOptional({
4739
+ type: "optional",
4740
+ innerType: innerType,
4741
+ });
4742
+ }
4743
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
4744
+ $ZodExactOptional.init(inst, def);
4745
+ ZodType.init(inst, def);
4746
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4747
+ inst.unwrap = () => inst._zod.def.innerType;
4748
+ });
4749
+ function exactOptional(innerType) {
4750
+ return new ZodExactOptional({
4751
+ type: "optional",
4752
+ innerType: innerType,
4753
+ });
4754
+ }
4755
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4756
+ $ZodNullable.init(inst, def);
4757
+ ZodType.init(inst, def);
4758
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
4759
+ inst.unwrap = () => inst._zod.def.innerType;
4760
+ });
4761
+ function nullable(innerType) {
4762
+ return new ZodNullable({
4763
+ type: "nullable",
4764
+ innerType: innerType,
4765
+ });
4766
+ }
4767
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
4768
+ $ZodDefault.init(inst, def);
4769
+ ZodType.init(inst, def);
4770
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
4771
+ inst.unwrap = () => inst._zod.def.innerType;
4772
+ inst.removeDefault = inst.unwrap;
4773
+ });
4774
+ function _default(innerType, defaultValue) {
4775
+ return new ZodDefault({
4776
+ type: "default",
4777
+ innerType: innerType,
4778
+ get defaultValue() {
4779
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4780
+ },
4781
+ });
4782
+ }
4783
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
4784
+ $ZodPrefault.init(inst, def);
4785
+ ZodType.init(inst, def);
4786
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
4787
+ inst.unwrap = () => inst._zod.def.innerType;
4788
+ });
4789
+ function prefault(innerType, defaultValue) {
4790
+ return new ZodPrefault({
4791
+ type: "prefault",
4792
+ innerType: innerType,
4793
+ get defaultValue() {
4794
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
4795
+ },
4796
+ });
4797
+ }
4798
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
4799
+ $ZodNonOptional.init(inst, def);
4800
+ ZodType.init(inst, def);
4801
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
4802
+ inst.unwrap = () => inst._zod.def.innerType;
4803
+ });
4804
+ function nonoptional(innerType, params) {
4805
+ return new ZodNonOptional({
4806
+ type: "nonoptional",
4807
+ innerType: innerType,
4808
+ ...normalizeParams(params),
4809
+ });
4810
+ }
4811
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
4812
+ $ZodCatch.init(inst, def);
4813
+ ZodType.init(inst, def);
4814
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
4815
+ inst.unwrap = () => inst._zod.def.innerType;
4816
+ inst.removeCatch = inst.unwrap;
4817
+ });
4818
+ function _catch(innerType, catchValue) {
4819
+ return new ZodCatch({
4820
+ type: "catch",
4821
+ innerType: innerType,
4822
+ catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
4823
+ });
4824
+ }
4825
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
4826
+ $ZodPipe.init(inst, def);
4827
+ ZodType.init(inst, def);
4828
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
4829
+ inst.in = def.in;
4830
+ inst.out = def.out;
4831
+ });
4832
+ function pipe(in_, out) {
4833
+ return new ZodPipe({
4834
+ type: "pipe",
4835
+ in: in_,
4836
+ out: out,
4837
+ // ...util.normalizeParams(params),
4838
+ });
4839
+ }
4840
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
4841
+ $ZodReadonly.init(inst, def);
4842
+ ZodType.init(inst, def);
4843
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
4844
+ inst.unwrap = () => inst._zod.def.innerType;
4845
+ });
4846
+ function readonly(innerType) {
4847
+ return new ZodReadonly({
4848
+ type: "readonly",
4849
+ innerType: innerType,
4850
+ });
4851
+ }
4852
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
4853
+ $ZodCustom.init(inst, def);
4854
+ ZodType.init(inst, def);
4855
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
4856
+ });
4857
+ function refine(fn, _params = {}) {
4858
+ return _refine(ZodCustom, fn, _params);
4859
+ }
4860
+ // superRefine
4861
+ function superRefine(fn, params) {
4862
+ return _superRefine(fn, params);
4863
+ }
4864
+
4865
+ /**
4866
+ * Zod schema for the jeeves-meta OpenClaw plugin configuration.
4867
+ *
4868
+ * This is the source of truth for the plugin configSchema.
4869
+ * The build-time script `scripts/generate-plugin-schema.mjs` derives
4870
+ * the JSON Schema in `openclaw.plugin.json` from this definition.
4871
+ *
4872
+ * @module pluginConfigSchema
4873
+ */
4874
+ /** Zod schema for the jeeves-meta OpenClaw plugin configuration. */
4875
+ const pluginConfigSchema = object({
4876
+ apiUrl: string()
4877
+ .default('http://127.0.0.1:1938')
4878
+ .describe('URL of the jeeves-meta HTTP service. Falls back to JEEVES_META_URL env var.'),
4879
+ configRoot: string()
4880
+ .optional()
4881
+ .describe('Absolute path to the platform config root (e.g. j:/config). Used by @karmaniverous/jeeves core for config directory resolution.'),
4882
+ });
4883
+
596
4884
  /**
597
4885
  * OpenClaw plugin for jeeves-meta.
598
4886
  *
@@ -670,4 +4958,4 @@ function register(api) {
670
4958
  writer.start();
671
4959
  }
672
4960
 
673
- export { register as default };
4961
+ export { register as default, pluginConfigSchema };