@kevisual/router 0.0.39 → 0.0.40

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/router.js CHANGED
@@ -78,11 +78,8 @@ class CustomError extends Error {
78
78
  * @param err
79
79
  * @returns
80
80
  */
81
- static isError(err) {
82
- if (err instanceof CustomError || err?.code) {
83
- return true;
84
- }
85
- return false;
81
+ static isError(error) {
82
+ return error instanceof CustomError || (typeof error === 'object' && error !== null && 'code' in error);
86
83
  }
87
84
  parse(e) {
88
85
  if (e) {
@@ -601,8 +598,8 @@ class QueryRouter {
601
598
  setContext(ctx) {
602
599
  this.context = ctx;
603
600
  }
604
- getList() {
605
- return this.routes.map((r) => {
601
+ getList(filter) {
602
+ return this.routes.filter(filter || (() => true)).map((r) => {
606
603
  return pick$1(r, pickValue);
607
604
  });
608
605
  }
@@ -906,370 +903,243 @@ const handleServer = async (req, res) => {
906
903
  return data;
907
904
  };
908
905
 
909
- function getDefaultExportFromCjs (x) {
910
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
906
+ /**
907
+ * RegExp to match cookie-name in RFC 6265 sec 4.1.1
908
+ * This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
909
+ * which has been replaced by the token definition in RFC 7230 appendix B.
910
+ *
911
+ * cookie-name = token
912
+ * token = 1*tchar
913
+ * tchar = "!" / "#" / "$" / "%" / "&" / "'" /
914
+ * "*" / "+" / "-" / "." / "^" / "_" /
915
+ * "`" / "|" / "~" / DIGIT / ALPHA
916
+ *
917
+ * Note: Allowing more characters - https://github.com/jshttp/cookie/issues/191
918
+ * Allow same range as cookie value, except `=`, which delimits end of name.
919
+ */
920
+ const cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
921
+ /**
922
+ * RegExp to match cookie-value in RFC 6265 sec 4.1.1
923
+ *
924
+ * cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
925
+ * cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
926
+ * ; US-ASCII characters excluding CTLs,
927
+ * ; whitespace DQUOTE, comma, semicolon,
928
+ * ; and backslash
929
+ *
930
+ * Allowing more characters: https://github.com/jshttp/cookie/issues/191
931
+ * Comma, backslash, and DQUOTE are not part of the parsing algorithm.
932
+ */
933
+ const cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
934
+ /**
935
+ * RegExp to match domain-value in RFC 6265 sec 4.1.1
936
+ *
937
+ * domain-value = <subdomain>
938
+ * ; defined in [RFC1034], Section 3.5, as
939
+ * ; enhanced by [RFC1123], Section 2.1
940
+ * <subdomain> = <label> | <subdomain> "." <label>
941
+ * <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
942
+ * Labels must be 63 characters or less.
943
+ * 'let-dig' not 'letter' in the first char, per RFC1123
944
+ * <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
945
+ * <let-dig-hyp> = <let-dig> | "-"
946
+ * <let-dig> = <letter> | <digit>
947
+ * <letter> = any one of the 52 alphabetic characters A through Z in
948
+ * upper case and a through z in lower case
949
+ * <digit> = any one of the ten digits 0 through 9
950
+ *
951
+ * Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
952
+ *
953
+ * > (Note that a leading %x2E ("."), if present, is ignored even though that
954
+ * character is not permitted, but a trailing %x2E ("."), if present, will
955
+ * cause the user agent to ignore the attribute.)
956
+ */
957
+ const domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
958
+ /**
959
+ * RegExp to match path-value in RFC 6265 sec 4.1.1
960
+ *
961
+ * path-value = <any CHAR except CTLs or ";">
962
+ * CHAR = %x01-7F
963
+ * ; defined in RFC 5234 appendix B.1
964
+ */
965
+ const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
966
+ const __toString = Object.prototype.toString;
967
+ const NullObject = /* @__PURE__ */ (() => {
968
+ const C = function () { };
969
+ C.prototype = Object.create(null);
970
+ return C;
971
+ })();
972
+ /**
973
+ * Parse a `Cookie` header.
974
+ *
975
+ * Parse the given cookie header string into an object
976
+ * The object has the various cookies as keys(names) => values
977
+ */
978
+ function parseCookie(str, options) {
979
+ const obj = new NullObject();
980
+ const len = str.length;
981
+ // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
982
+ if (len < 2)
983
+ return obj;
984
+ const dec = decode$1;
985
+ let index = 0;
986
+ do {
987
+ const eqIdx = eqIndex(str, index, len);
988
+ if (eqIdx === -1)
989
+ break; // No more cookie pairs.
990
+ const endIdx = endIndex(str, index, len);
991
+ if (eqIdx > endIdx) {
992
+ // backtrack on prior semicolon
993
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
994
+ continue;
995
+ }
996
+ const key = valueSlice(str, index, eqIdx);
997
+ // only assign once
998
+ if (obj[key] === undefined) {
999
+ obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
1000
+ }
1001
+ index = endIdx + 1;
1002
+ } while (index < len);
1003
+ return obj;
911
1004
  }
912
-
913
- var dist = {};
914
-
915
- var hasRequiredDist;
916
-
917
- function requireDist () {
918
- if (hasRequiredDist) return dist;
919
- hasRequiredDist = 1;
920
- Object.defineProperty(dist, "__esModule", { value: true });
921
- dist.parseCookie = parseCookie;
922
- dist.parse = parseCookie;
923
- dist.stringifyCookie = stringifyCookie;
924
- dist.stringifySetCookie = stringifySetCookie;
925
- dist.serialize = stringifySetCookie;
926
- dist.parseSetCookie = parseSetCookie;
927
- dist.stringifySetCookie = stringifySetCookie;
928
- dist.serialize = stringifySetCookie;
929
- /**
930
- * RegExp to match cookie-name in RFC 6265 sec 4.1.1
931
- * This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
932
- * which has been replaced by the token definition in RFC 7230 appendix B.
933
- *
934
- * cookie-name = token
935
- * token = 1*tchar
936
- * tchar = "!" / "#" / "$" / "%" / "&" / "'" /
937
- * "*" / "+" / "-" / "." / "^" / "_" /
938
- * "`" / "|" / "~" / DIGIT / ALPHA
939
- *
940
- * Note: Allowing more characters - https://github.com/jshttp/cookie/issues/191
941
- * Allow same range as cookie value, except `=`, which delimits end of name.
942
- */
943
- const cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
944
- /**
945
- * RegExp to match cookie-value in RFC 6265 sec 4.1.1
946
- *
947
- * cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
948
- * cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
949
- * ; US-ASCII characters excluding CTLs,
950
- * ; whitespace DQUOTE, comma, semicolon,
951
- * ; and backslash
952
- *
953
- * Allowing more characters: https://github.com/jshttp/cookie/issues/191
954
- * Comma, backslash, and DQUOTE are not part of the parsing algorithm.
955
- */
956
- const cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
957
- /**
958
- * RegExp to match domain-value in RFC 6265 sec 4.1.1
959
- *
960
- * domain-value = <subdomain>
961
- * ; defined in [RFC1034], Section 3.5, as
962
- * ; enhanced by [RFC1123], Section 2.1
963
- * <subdomain> = <label> | <subdomain> "." <label>
964
- * <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
965
- * Labels must be 63 characters or less.
966
- * 'let-dig' not 'letter' in the first char, per RFC1123
967
- * <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
968
- * <let-dig-hyp> = <let-dig> | "-"
969
- * <let-dig> = <letter> | <digit>
970
- * <letter> = any one of the 52 alphabetic characters A through Z in
971
- * upper case and a through z in lower case
972
- * <digit> = any one of the ten digits 0 through 9
973
- *
974
- * Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
975
- *
976
- * > (Note that a leading %x2E ("."), if present, is ignored even though that
977
- * character is not permitted, but a trailing %x2E ("."), if present, will
978
- * cause the user agent to ignore the attribute.)
979
- */
980
- const domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
981
- /**
982
- * RegExp to match path-value in RFC 6265 sec 4.1.1
983
- *
984
- * path-value = <any CHAR except CTLs or ";">
985
- * CHAR = %x01-7F
986
- * ; defined in RFC 5234 appendix B.1
987
- */
988
- const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
989
- /**
990
- * RegExp to match max-age-value in RFC 6265 sec 5.6.2
991
- */
992
- const maxAgeRegExp = /^-?\d+$/;
993
- const __toString = Object.prototype.toString;
994
- const NullObject = /* @__PURE__ */ (() => {
995
- const C = function () { };
996
- C.prototype = Object.create(null);
997
- return C;
998
- })();
999
- /**
1000
- * Parse a `Cookie` header.
1001
- *
1002
- * Parse the given cookie header string into an object
1003
- * The object has the various cookies as keys(names) => values
1004
- */
1005
- function parseCookie(str, options) {
1006
- const obj = new NullObject();
1007
- const len = str.length;
1008
- // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
1009
- if (len < 2)
1010
- return obj;
1011
- const dec = options?.decode || decode;
1012
- let index = 0;
1013
- do {
1014
- const eqIdx = eqIndex(str, index, len);
1015
- if (eqIdx === -1)
1016
- break; // No more cookie pairs.
1017
- const endIdx = endIndex(str, index, len);
1018
- if (eqIdx > endIdx) {
1019
- // backtrack on prior semicolon
1020
- index = str.lastIndexOf(";", eqIdx - 1) + 1;
1021
- continue;
1022
- }
1023
- const key = valueSlice(str, index, eqIdx);
1024
- // only assign once
1025
- if (obj[key] === undefined) {
1026
- obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
1027
- }
1028
- index = endIdx + 1;
1029
- } while (index < len);
1030
- return obj;
1031
- }
1032
- /**
1033
- * Stringifies an object into an HTTP `Cookie` header.
1034
- */
1035
- function stringifyCookie(cookie, options) {
1036
- const enc = options?.encode || encodeURIComponent;
1037
- const cookieStrings = [];
1038
- for (const name of Object.keys(cookie)) {
1039
- const val = cookie[name];
1040
- if (val === undefined)
1041
- continue;
1042
- if (!cookieNameRegExp.test(name)) {
1043
- throw new TypeError(`cookie name is invalid: ${name}`);
1044
- }
1045
- const value = enc(val);
1046
- if (!cookieValueRegExp.test(value)) {
1047
- throw new TypeError(`cookie val is invalid: ${val}`);
1048
- }
1049
- cookieStrings.push(`${name}=${value}`);
1050
- }
1051
- return cookieStrings.join("; ");
1052
- }
1053
- function stringifySetCookie(_name, _val, _opts) {
1054
- const cookie = typeof _name === "object"
1055
- ? _name
1056
- : { ..._opts, name: _name, value: String(_val) };
1057
- const options = typeof _val === "object" ? _val : _opts;
1058
- const enc = options?.encode || encodeURIComponent;
1059
- if (!cookieNameRegExp.test(cookie.name)) {
1060
- throw new TypeError(`argument name is invalid: ${cookie.name}`);
1061
- }
1062
- const value = cookie.value ? enc(cookie.value) : "";
1063
- if (!cookieValueRegExp.test(value)) {
1064
- throw new TypeError(`argument val is invalid: ${cookie.value}`);
1065
- }
1066
- let str = cookie.name + "=" + value;
1067
- if (cookie.maxAge !== undefined) {
1068
- if (!Number.isInteger(cookie.maxAge)) {
1069
- throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
1070
- }
1071
- str += "; Max-Age=" + cookie.maxAge;
1072
- }
1073
- if (cookie.domain) {
1074
- if (!domainValueRegExp.test(cookie.domain)) {
1075
- throw new TypeError(`option domain is invalid: ${cookie.domain}`);
1076
- }
1077
- str += "; Domain=" + cookie.domain;
1078
- }
1079
- if (cookie.path) {
1080
- if (!pathValueRegExp.test(cookie.path)) {
1081
- throw new TypeError(`option path is invalid: ${cookie.path}`);
1082
- }
1083
- str += "; Path=" + cookie.path;
1084
- }
1085
- if (cookie.expires) {
1086
- if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
1087
- throw new TypeError(`option expires is invalid: ${cookie.expires}`);
1088
- }
1089
- str += "; Expires=" + cookie.expires.toUTCString();
1090
- }
1091
- if (cookie.httpOnly) {
1092
- str += "; HttpOnly";
1093
- }
1094
- if (cookie.secure) {
1095
- str += "; Secure";
1096
- }
1097
- if (cookie.partitioned) {
1098
- str += "; Partitioned";
1099
- }
1100
- if (cookie.priority) {
1101
- const priority = typeof cookie.priority === "string"
1102
- ? cookie.priority.toLowerCase()
1103
- : undefined;
1104
- switch (priority) {
1105
- case "low":
1106
- str += "; Priority=Low";
1107
- break;
1108
- case "medium":
1109
- str += "; Priority=Medium";
1110
- break;
1111
- case "high":
1112
- str += "; Priority=High";
1113
- break;
1114
- default:
1115
- throw new TypeError(`option priority is invalid: ${cookie.priority}`);
1116
- }
1117
- }
1118
- if (cookie.sameSite) {
1119
- const sameSite = typeof cookie.sameSite === "string"
1120
- ? cookie.sameSite.toLowerCase()
1121
- : cookie.sameSite;
1122
- switch (sameSite) {
1123
- case true:
1124
- case "strict":
1125
- str += "; SameSite=Strict";
1126
- break;
1127
- case "lax":
1128
- str += "; SameSite=Lax";
1129
- break;
1130
- case "none":
1131
- str += "; SameSite=None";
1132
- break;
1133
- default:
1134
- throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
1135
- }
1136
- }
1137
- return str;
1138
- }
1139
- /**
1140
- * Deserialize a `Set-Cookie` header into an object.
1141
- *
1142
- * deserialize('foo=bar; httpOnly')
1143
- * => { name: 'foo', value: 'bar', httpOnly: true }
1144
- */
1145
- function parseSetCookie(str, options) {
1146
- const dec = options?.decode || decode;
1147
- const len = str.length;
1148
- const endIdx = endIndex(str, 0, len);
1149
- const eqIdx = eqIndex(str, 0, endIdx);
1150
- const setCookie = eqIdx === -1
1151
- ? { name: "", value: dec(valueSlice(str, 0, endIdx)) }
1152
- : {
1153
- name: valueSlice(str, 0, eqIdx),
1154
- value: dec(valueSlice(str, eqIdx + 1, endIdx)),
1155
- };
1156
- let index = endIdx + 1;
1157
- while (index < len) {
1158
- const endIdx = endIndex(str, index, len);
1159
- const eqIdx = eqIndex(str, index, endIdx);
1160
- const attr = eqIdx === -1
1161
- ? valueSlice(str, index, endIdx)
1162
- : valueSlice(str, index, eqIdx);
1163
- const val = eqIdx === -1 ? undefined : valueSlice(str, eqIdx + 1, endIdx);
1164
- switch (attr.toLowerCase()) {
1165
- case "httponly":
1166
- setCookie.httpOnly = true;
1167
- break;
1168
- case "secure":
1169
- setCookie.secure = true;
1170
- break;
1171
- case "partitioned":
1172
- setCookie.partitioned = true;
1173
- break;
1174
- case "domain":
1175
- setCookie.domain = val;
1176
- break;
1177
- case "path":
1178
- setCookie.path = val;
1179
- break;
1180
- case "max-age":
1181
- if (val && maxAgeRegExp.test(val))
1182
- setCookie.maxAge = Number(val);
1183
- break;
1184
- case "expires":
1185
- if (!val)
1186
- break;
1187
- const date = new Date(val);
1188
- if (Number.isFinite(date.valueOf()))
1189
- setCookie.expires = date;
1190
- break;
1191
- case "priority":
1192
- if (!val)
1193
- break;
1194
- const priority = val.toLowerCase();
1195
- if (priority === "low" ||
1196
- priority === "medium" ||
1197
- priority === "high") {
1198
- setCookie.priority = priority;
1199
- }
1200
- break;
1201
- case "samesite":
1202
- if (!val)
1203
- break;
1204
- const sameSite = val.toLowerCase();
1205
- if (sameSite === "lax" ||
1206
- sameSite === "strict" ||
1207
- sameSite === "none") {
1208
- setCookie.sameSite = sameSite;
1209
- }
1210
- break;
1211
- }
1212
- index = endIdx + 1;
1213
- }
1214
- return setCookie;
1215
- }
1216
- /**
1217
- * Find the `;` character between `min` and `len` in str.
1218
- */
1219
- function endIndex(str, min, len) {
1220
- const index = str.indexOf(";", min);
1221
- return index === -1 ? len : index;
1222
- }
1223
- /**
1224
- * Find the `=` character between `min` and `max` in str.
1225
- */
1226
- function eqIndex(str, min, max) {
1227
- const index = str.indexOf("=", min);
1228
- return index < max ? index : -1;
1229
- }
1230
- /**
1231
- * Slice out a value between startPod to max.
1232
- */
1233
- function valueSlice(str, min, max) {
1234
- let start = min;
1235
- let end = max;
1236
- do {
1237
- const code = str.charCodeAt(start);
1238
- if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
1239
- break;
1240
- } while (++start < end);
1241
- while (end > start) {
1242
- const code = str.charCodeAt(end - 1);
1243
- if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
1244
- break;
1245
- end--;
1246
- }
1247
- return str.slice(start, end);
1248
- }
1249
- /**
1250
- * URL-decode string value. Optimized to skip native call when no %.
1251
- */
1252
- function decode(str) {
1253
- if (str.indexOf("%") === -1)
1254
- return str;
1255
- try {
1256
- return decodeURIComponent(str);
1257
- }
1258
- catch (e) {
1259
- return str;
1260
- }
1261
- }
1262
- /**
1263
- * Determine if value is a Date.
1264
- */
1265
- function isDate(val) {
1266
- return __toString.call(val) === "[object Date]";
1267
- }
1268
-
1269
- return dist;
1005
+ function stringifySetCookie(_name, _val, _opts) {
1006
+ const cookie = typeof _name === "object"
1007
+ ? _name
1008
+ : { ..._opts, name: _name, value: String(_val) };
1009
+ const options = typeof _val === "object" ? _val : _opts;
1010
+ const enc = options?.encode || encodeURIComponent;
1011
+ if (!cookieNameRegExp.test(cookie.name)) {
1012
+ throw new TypeError(`argument name is invalid: ${cookie.name}`);
1013
+ }
1014
+ const value = cookie.value ? enc(cookie.value) : "";
1015
+ if (!cookieValueRegExp.test(value)) {
1016
+ throw new TypeError(`argument val is invalid: ${cookie.value}`);
1017
+ }
1018
+ let str = cookie.name + "=" + value;
1019
+ if (cookie.maxAge !== undefined) {
1020
+ if (!Number.isInteger(cookie.maxAge)) {
1021
+ throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
1022
+ }
1023
+ str += "; Max-Age=" + cookie.maxAge;
1024
+ }
1025
+ if (cookie.domain) {
1026
+ if (!domainValueRegExp.test(cookie.domain)) {
1027
+ throw new TypeError(`option domain is invalid: ${cookie.domain}`);
1028
+ }
1029
+ str += "; Domain=" + cookie.domain;
1030
+ }
1031
+ if (cookie.path) {
1032
+ if (!pathValueRegExp.test(cookie.path)) {
1033
+ throw new TypeError(`option path is invalid: ${cookie.path}`);
1034
+ }
1035
+ str += "; Path=" + cookie.path;
1036
+ }
1037
+ if (cookie.expires) {
1038
+ if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
1039
+ throw new TypeError(`option expires is invalid: ${cookie.expires}`);
1040
+ }
1041
+ str += "; Expires=" + cookie.expires.toUTCString();
1042
+ }
1043
+ if (cookie.httpOnly) {
1044
+ str += "; HttpOnly";
1045
+ }
1046
+ if (cookie.secure) {
1047
+ str += "; Secure";
1048
+ }
1049
+ if (cookie.partitioned) {
1050
+ str += "; Partitioned";
1051
+ }
1052
+ if (cookie.priority) {
1053
+ const priority = typeof cookie.priority === "string"
1054
+ ? cookie.priority.toLowerCase()
1055
+ : undefined;
1056
+ switch (priority) {
1057
+ case "low":
1058
+ str += "; Priority=Low";
1059
+ break;
1060
+ case "medium":
1061
+ str += "; Priority=Medium";
1062
+ break;
1063
+ case "high":
1064
+ str += "; Priority=High";
1065
+ break;
1066
+ default:
1067
+ throw new TypeError(`option priority is invalid: ${cookie.priority}`);
1068
+ }
1069
+ }
1070
+ if (cookie.sameSite) {
1071
+ const sameSite = typeof cookie.sameSite === "string"
1072
+ ? cookie.sameSite.toLowerCase()
1073
+ : cookie.sameSite;
1074
+ switch (sameSite) {
1075
+ case true:
1076
+ case "strict":
1077
+ str += "; SameSite=Strict";
1078
+ break;
1079
+ case "lax":
1080
+ str += "; SameSite=Lax";
1081
+ break;
1082
+ case "none":
1083
+ str += "; SameSite=None";
1084
+ break;
1085
+ default:
1086
+ throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
1087
+ }
1088
+ }
1089
+ return str;
1090
+ }
1091
+ /**
1092
+ * Find the `;` character between `min` and `len` in str.
1093
+ */
1094
+ function endIndex(str, min, len) {
1095
+ const index = str.indexOf(";", min);
1096
+ return index === -1 ? len : index;
1097
+ }
1098
+ /**
1099
+ * Find the `=` character between `min` and `max` in str.
1100
+ */
1101
+ function eqIndex(str, min, max) {
1102
+ const index = str.indexOf("=", min);
1103
+ return index < max ? index : -1;
1104
+ }
1105
+ /**
1106
+ * Slice out a value between startPod to max.
1107
+ */
1108
+ function valueSlice(str, min, max) {
1109
+ let start = min;
1110
+ let end = max;
1111
+ do {
1112
+ const code = str.charCodeAt(start);
1113
+ if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
1114
+ break;
1115
+ } while (++start < end);
1116
+ while (end > start) {
1117
+ const code = str.charCodeAt(end - 1);
1118
+ if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
1119
+ break;
1120
+ end--;
1121
+ }
1122
+ return str.slice(start, end);
1123
+ }
1124
+ /**
1125
+ * URL-decode string value. Optimized to skip native call when no %.
1126
+ */
1127
+ function decode$1(str) {
1128
+ if (str.indexOf("%") === -1)
1129
+ return str;
1130
+ try {
1131
+ return decodeURIComponent(str);
1132
+ }
1133
+ catch (e) {
1134
+ return str;
1135
+ }
1136
+ }
1137
+ /**
1138
+ * Determine if value is a Date.
1139
+ */
1140
+ function isDate(val) {
1141
+ return __toString.call(val) === "[object Date]";
1270
1142
  }
1271
-
1272
- var distExports = /*@__PURE__*/ requireDist();
1273
1143
 
1274
1144
  // 实现函数
1275
1145
  function createHandleCtx(req, res) {
@@ -1280,7 +1150,7 @@ function createHandleCtx(req, res) {
1280
1150
  // 扩展 res.cookie 方法
1281
1151
  const cookieFn = (name, value, options = {}, end = true) => {
1282
1152
  // 序列化新的 Cookie
1283
- const serializedCookie = distExports.serialize(name, value, options);
1153
+ const serializedCookie = stringifySetCookie(name, value, options);
1284
1154
  cookies.push(serializedCookie); // 将新的 Cookie 添加到数组
1285
1155
  if (end) {
1286
1156
  // 如果设置了 end 参数,则立即设置到响应头
@@ -1288,7 +1158,7 @@ function createHandleCtx(req, res) {
1288
1158
  }
1289
1159
  };
1290
1160
  // 解析请求中的现有 Cookie
1291
- const parsedCookies = distExports.parse(req.headers.cookie || '');
1161
+ const parsedCookies = parseCookie(req.headers.cookie || '');
1292
1162
  handReq.cookies = parsedCookies;
1293
1163
  handRes.cookie = cookieFn;
1294
1164
  // 返回扩展的上下文
@@ -2627,8 +2497,8 @@ class Doc {
2627
2497
 
2628
2498
  const version = {
2629
2499
  major: 4,
2630
- minor: 1,
2631
- patch: 13,
2500
+ minor: 2,
2501
+ patch: 1,
2632
2502
  };
2633
2503
 
2634
2504
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -2698,16 +2568,6 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
2698
2568
  }
2699
2569
  return payload;
2700
2570
  };
2701
- // const handleChecksResult = (
2702
- // checkResult: ParsePayload,
2703
- // originalResult: ParsePayload,
2704
- // ctx: ParseContextInternal
2705
- // ): util.MaybeAsync<ParsePayload> => {
2706
- // // if the checks mutated the value && there are no issues, re-parse the result
2707
- // if (checkResult.value !== originalResult.value && !checkResult.issues.length)
2708
- // return inst._zod.parse(checkResult, ctx);
2709
- // return originalResult;
2710
- // };
2711
2571
  const handleCanaryResult = (canary, payload, ctx) => {
2712
2572
  // abort if the canary is aborted
2713
2573
  if (aborted(canary)) {
@@ -4345,6 +4205,659 @@ function _check(fn, params) {
4345
4205
  return ch;
4346
4206
  }
4347
4207
 
4208
+ // function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
4209
+ // return {
4210
+ // processor: inputs.processor,
4211
+ // metadataRegistry: inputs.metadata ?? globalRegistry,
4212
+ // target: inputs.target ?? "draft-2020-12",
4213
+ // unrepresentable: inputs.unrepresentable ?? "throw",
4214
+ // };
4215
+ // }
4216
+ function initializeContext(params) {
4217
+ // Normalize target: convert old non-hyphenated versions to hyphenated versions
4218
+ let target = params?.target ?? "draft-2020-12";
4219
+ if (target === "draft-4")
4220
+ target = "draft-04";
4221
+ if (target === "draft-7")
4222
+ target = "draft-07";
4223
+ return {
4224
+ processors: params.processors ?? {},
4225
+ metadataRegistry: params?.metadata ?? globalRegistry,
4226
+ target,
4227
+ unrepresentable: params?.unrepresentable ?? "throw",
4228
+ override: params?.override ?? (() => { }),
4229
+ io: params?.io ?? "output",
4230
+ counter: 0,
4231
+ seen: new Map(),
4232
+ cycles: params?.cycles ?? "ref",
4233
+ reused: params?.reused ?? "inline",
4234
+ external: params?.external ?? undefined,
4235
+ };
4236
+ }
4237
+ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
4238
+ var _a;
4239
+ const def = schema._zod.def;
4240
+ // check for schema in seens
4241
+ const seen = ctx.seen.get(schema);
4242
+ if (seen) {
4243
+ seen.count++;
4244
+ // check if cycle
4245
+ const isCycle = _params.schemaPath.includes(schema);
4246
+ if (isCycle) {
4247
+ seen.cycle = _params.path;
4248
+ }
4249
+ return seen.schema;
4250
+ }
4251
+ // initialize
4252
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
4253
+ ctx.seen.set(schema, result);
4254
+ // custom method overrides default behavior
4255
+ const overrideSchema = schema._zod.toJSONSchema?.();
4256
+ if (overrideSchema) {
4257
+ result.schema = overrideSchema;
4258
+ }
4259
+ else {
4260
+ const params = {
4261
+ ..._params,
4262
+ schemaPath: [..._params.schemaPath, schema],
4263
+ path: _params.path,
4264
+ };
4265
+ const parent = schema._zod.parent;
4266
+ if (parent) {
4267
+ // schema was cloned from another schema
4268
+ result.ref = parent;
4269
+ process$1(parent, ctx, params);
4270
+ ctx.seen.get(parent).isParent = true;
4271
+ }
4272
+ else if (schema._zod.processJSONSchema) {
4273
+ schema._zod.processJSONSchema(ctx, result.schema, params);
4274
+ }
4275
+ else {
4276
+ const _json = result.schema;
4277
+ const processor = ctx.processors[def.type];
4278
+ if (!processor) {
4279
+ throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
4280
+ }
4281
+ processor(schema, ctx, _json, params);
4282
+ }
4283
+ }
4284
+ // metadata
4285
+ const meta = ctx.metadataRegistry.get(schema);
4286
+ if (meta)
4287
+ Object.assign(result.schema, meta);
4288
+ if (ctx.io === "input" && isTransforming(schema)) {
4289
+ // examples/defaults only apply to output type of pipe
4290
+ delete result.schema.examples;
4291
+ delete result.schema.default;
4292
+ }
4293
+ // set prefault as default
4294
+ if (ctx.io === "input" && result.schema._prefault)
4295
+ (_a = result.schema).default ?? (_a.default = result.schema._prefault);
4296
+ delete result.schema._prefault;
4297
+ // pulling fresh from ctx.seen in case it was overwritten
4298
+ const _result = ctx.seen.get(schema);
4299
+ return _result.schema;
4300
+ }
4301
+ function extractDefs(ctx, schema
4302
+ // params: EmitParams
4303
+ ) {
4304
+ // iterate over seen map;
4305
+ const root = ctx.seen.get(schema);
4306
+ if (!root)
4307
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
4308
+ // returns a ref to the schema
4309
+ // defId will be empty if the ref points to an external schema (or #)
4310
+ const makeURI = (entry) => {
4311
+ // comparing the seen objects because sometimes
4312
+ // multiple schemas map to the same seen object.
4313
+ // e.g. lazy
4314
+ // external is configured
4315
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
4316
+ if (ctx.external) {
4317
+ const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
4318
+ // check if schema is in the external registry
4319
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
4320
+ if (externalId) {
4321
+ return { ref: uriGenerator(externalId) };
4322
+ }
4323
+ // otherwise, add to __shared
4324
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
4325
+ entry[1].defId = id; // set defId so it will be reused if needed
4326
+ return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
4327
+ }
4328
+ if (entry[1] === root) {
4329
+ return { ref: "#" };
4330
+ }
4331
+ // self-contained schema
4332
+ const uriPrefix = `#`;
4333
+ const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
4334
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
4335
+ return { defId, ref: defUriPrefix + defId };
4336
+ };
4337
+ // stored cached version in `def` property
4338
+ // remove all properties, set $ref
4339
+ const extractToDef = (entry) => {
4340
+ // if the schema is already a reference, do not extract it
4341
+ if (entry[1].schema.$ref) {
4342
+ return;
4343
+ }
4344
+ const seen = entry[1];
4345
+ const { ref, defId } = makeURI(entry);
4346
+ seen.def = { ...seen.schema };
4347
+ // defId won't be set if the schema is a reference to an external schema
4348
+ // or if the schema is the root schema
4349
+ if (defId)
4350
+ seen.defId = defId;
4351
+ // wipe away all properties except $ref
4352
+ const schema = seen.schema;
4353
+ for (const key in schema) {
4354
+ delete schema[key];
4355
+ }
4356
+ schema.$ref = ref;
4357
+ };
4358
+ // throw on cycles
4359
+ // break cycles
4360
+ if (ctx.cycles === "throw") {
4361
+ for (const entry of ctx.seen.entries()) {
4362
+ const seen = entry[1];
4363
+ if (seen.cycle) {
4364
+ throw new Error("Cycle detected: " +
4365
+ `#/${seen.cycle?.join("/")}/<root>` +
4366
+ '\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
4367
+ }
4368
+ }
4369
+ }
4370
+ // extract schemas into $defs
4371
+ for (const entry of ctx.seen.entries()) {
4372
+ const seen = entry[1];
4373
+ // convert root schema to # $ref
4374
+ if (schema === entry[0]) {
4375
+ extractToDef(entry); // this has special handling for the root schema
4376
+ continue;
4377
+ }
4378
+ // extract schemas that are in the external registry
4379
+ if (ctx.external) {
4380
+ const ext = ctx.external.registry.get(entry[0])?.id;
4381
+ if (schema !== entry[0] && ext) {
4382
+ extractToDef(entry);
4383
+ continue;
4384
+ }
4385
+ }
4386
+ // extract schemas with `id` meta
4387
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
4388
+ if (id) {
4389
+ extractToDef(entry);
4390
+ continue;
4391
+ }
4392
+ // break cycles
4393
+ if (seen.cycle) {
4394
+ // any
4395
+ extractToDef(entry);
4396
+ continue;
4397
+ }
4398
+ // extract reused schemas
4399
+ if (seen.count > 1) {
4400
+ if (ctx.reused === "ref") {
4401
+ extractToDef(entry);
4402
+ // biome-ignore lint:
4403
+ continue;
4404
+ }
4405
+ }
4406
+ }
4407
+ }
4408
+ function finalize(ctx, schema) {
4409
+ //
4410
+ // iterate over seen map;
4411
+ const root = ctx.seen.get(schema);
4412
+ if (!root)
4413
+ throw new Error("Unprocessed schema. This is a bug in Zod.");
4414
+ // flatten _refs
4415
+ const flattenRef = (zodSchema) => {
4416
+ const seen = ctx.seen.get(zodSchema);
4417
+ const schema = seen.def ?? seen.schema;
4418
+ const _cached = { ...schema };
4419
+ // already seen
4420
+ if (seen.ref === null) {
4421
+ return;
4422
+ }
4423
+ // flatten ref if defined
4424
+ const ref = seen.ref;
4425
+ seen.ref = null; // prevent recursion
4426
+ if (ref) {
4427
+ flattenRef(ref);
4428
+ // merge referenced schema into current
4429
+ const refSchema = ctx.seen.get(ref).schema;
4430
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
4431
+ schema.allOf = schema.allOf ?? [];
4432
+ schema.allOf.push(refSchema);
4433
+ }
4434
+ else {
4435
+ Object.assign(schema, refSchema);
4436
+ Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
4437
+ }
4438
+ }
4439
+ // execute overrides
4440
+ if (!seen.isParent)
4441
+ ctx.override({
4442
+ zodSchema: zodSchema,
4443
+ jsonSchema: schema,
4444
+ path: seen.path ?? [],
4445
+ });
4446
+ };
4447
+ for (const entry of [...ctx.seen.entries()].reverse()) {
4448
+ flattenRef(entry[0]);
4449
+ }
4450
+ const result = {};
4451
+ if (ctx.target === "draft-2020-12") {
4452
+ result.$schema = "https://json-schema.org/draft/2020-12/schema";
4453
+ }
4454
+ else if (ctx.target === "draft-07") {
4455
+ result.$schema = "http://json-schema.org/draft-07/schema#";
4456
+ }
4457
+ else if (ctx.target === "draft-04") {
4458
+ result.$schema = "http://json-schema.org/draft-04/schema#";
4459
+ }
4460
+ else if (ctx.target === "openapi-3.0") ;
4461
+ else ;
4462
+ if (ctx.external?.uri) {
4463
+ const id = ctx.external.registry.get(schema)?.id;
4464
+ if (!id)
4465
+ throw new Error("Schema is missing an `id` property");
4466
+ result.$id = ctx.external.uri(id);
4467
+ }
4468
+ Object.assign(result, root.def ?? root.schema);
4469
+ // build defs object
4470
+ const defs = ctx.external?.defs ?? {};
4471
+ for (const entry of ctx.seen.entries()) {
4472
+ const seen = entry[1];
4473
+ if (seen.def && seen.defId) {
4474
+ defs[seen.defId] = seen.def;
4475
+ }
4476
+ }
4477
+ // set definitions in result
4478
+ if (ctx.external) ;
4479
+ else {
4480
+ if (Object.keys(defs).length > 0) {
4481
+ if (ctx.target === "draft-2020-12") {
4482
+ result.$defs = defs;
4483
+ }
4484
+ else {
4485
+ result.definitions = defs;
4486
+ }
4487
+ }
4488
+ }
4489
+ try {
4490
+ // this "finalizes" this schema and ensures all cycles are removed
4491
+ // each call to finalize() is functionally independent
4492
+ // though the seen map is shared
4493
+ const finalized = JSON.parse(JSON.stringify(result));
4494
+ Object.defineProperty(finalized, "~standard", {
4495
+ value: {
4496
+ ...schema["~standard"],
4497
+ jsonSchema: {
4498
+ input: createStandardJSONSchemaMethod(schema, "input"),
4499
+ output: createStandardJSONSchemaMethod(schema, "output"),
4500
+ },
4501
+ },
4502
+ enumerable: false,
4503
+ writable: false,
4504
+ });
4505
+ return finalized;
4506
+ }
4507
+ catch (_err) {
4508
+ throw new Error("Error converting schema to JSON.");
4509
+ }
4510
+ }
4511
+ function isTransforming(_schema, _ctx) {
4512
+ const ctx = _ctx ?? { seen: new Set() };
4513
+ if (ctx.seen.has(_schema))
4514
+ return false;
4515
+ ctx.seen.add(_schema);
4516
+ const def = _schema._zod.def;
4517
+ if (def.type === "transform")
4518
+ return true;
4519
+ if (def.type === "array")
4520
+ return isTransforming(def.element, ctx);
4521
+ if (def.type === "set")
4522
+ return isTransforming(def.valueType, ctx);
4523
+ if (def.type === "lazy")
4524
+ return isTransforming(def.getter(), ctx);
4525
+ if (def.type === "promise" ||
4526
+ def.type === "optional" ||
4527
+ def.type === "nonoptional" ||
4528
+ def.type === "nullable" ||
4529
+ def.type === "readonly" ||
4530
+ def.type === "default" ||
4531
+ def.type === "prefault") {
4532
+ return isTransforming(def.innerType, ctx);
4533
+ }
4534
+ if (def.type === "intersection") {
4535
+ return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
4536
+ }
4537
+ if (def.type === "record" || def.type === "map") {
4538
+ return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
4539
+ }
4540
+ if (def.type === "pipe") {
4541
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
4542
+ }
4543
+ if (def.type === "object") {
4544
+ for (const key in def.shape) {
4545
+ if (isTransforming(def.shape[key], ctx))
4546
+ return true;
4547
+ }
4548
+ return false;
4549
+ }
4550
+ if (def.type === "union") {
4551
+ for (const option of def.options) {
4552
+ if (isTransforming(option, ctx))
4553
+ return true;
4554
+ }
4555
+ return false;
4556
+ }
4557
+ if (def.type === "tuple") {
4558
+ for (const item of def.items) {
4559
+ if (isTransforming(item, ctx))
4560
+ return true;
4561
+ }
4562
+ if (def.rest && isTransforming(def.rest, ctx))
4563
+ return true;
4564
+ return false;
4565
+ }
4566
+ return false;
4567
+ }
4568
+ /**
4569
+ * Creates a toJSONSchema method for a schema instance.
4570
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
4571
+ */
4572
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
4573
+ const ctx = initializeContext({ ...params, processors });
4574
+ process$1(schema, ctx);
4575
+ extractDefs(ctx, schema);
4576
+ return finalize(ctx, schema);
4577
+ };
4578
+ const createStandardJSONSchemaMethod = (schema, io) => (params) => {
4579
+ const { libraryOptions, target } = params ?? {};
4580
+ const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
4581
+ process$1(schema, ctx);
4582
+ extractDefs(ctx, schema);
4583
+ return finalize(ctx, schema);
4584
+ };
4585
+
4586
+ const formatMap = {
4587
+ guid: "uuid",
4588
+ url: "uri",
4589
+ datetime: "date-time",
4590
+ json_string: "json-string",
4591
+ regex: "", // do not set
4592
+ };
4593
+ // ==================== SIMPLE TYPE PROCESSORS ====================
4594
+ const stringProcessor = (schema, ctx, _json, _params) => {
4595
+ const json = _json;
4596
+ json.type = "string";
4597
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
4598
+ .bag;
4599
+ if (typeof minimum === "number")
4600
+ json.minLength = minimum;
4601
+ if (typeof maximum === "number")
4602
+ json.maxLength = maximum;
4603
+ // custom pattern overrides format
4604
+ if (format) {
4605
+ json.format = formatMap[format] ?? format;
4606
+ if (json.format === "")
4607
+ delete json.format; // empty format is not valid
4608
+ }
4609
+ if (contentEncoding)
4610
+ json.contentEncoding = contentEncoding;
4611
+ if (patterns && patterns.size > 0) {
4612
+ const regexes = [...patterns];
4613
+ if (regexes.length === 1)
4614
+ json.pattern = regexes[0].source;
4615
+ else if (regexes.length > 1) {
4616
+ json.allOf = [
4617
+ ...regexes.map((regex) => ({
4618
+ ...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
4619
+ ? { type: "string" }
4620
+ : {}),
4621
+ pattern: regex.source,
4622
+ })),
4623
+ ];
4624
+ }
4625
+ }
4626
+ };
4627
+ const numberProcessor = (schema, ctx, _json, _params) => {
4628
+ const json = _json;
4629
+ const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
4630
+ if (typeof format === "string" && format.includes("int"))
4631
+ json.type = "integer";
4632
+ else
4633
+ json.type = "number";
4634
+ if (typeof exclusiveMinimum === "number") {
4635
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
4636
+ json.minimum = exclusiveMinimum;
4637
+ json.exclusiveMinimum = true;
4638
+ }
4639
+ else {
4640
+ json.exclusiveMinimum = exclusiveMinimum;
4641
+ }
4642
+ }
4643
+ if (typeof minimum === "number") {
4644
+ json.minimum = minimum;
4645
+ if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
4646
+ if (exclusiveMinimum >= minimum)
4647
+ delete json.minimum;
4648
+ else
4649
+ delete json.exclusiveMinimum;
4650
+ }
4651
+ }
4652
+ if (typeof exclusiveMaximum === "number") {
4653
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
4654
+ json.maximum = exclusiveMaximum;
4655
+ json.exclusiveMaximum = true;
4656
+ }
4657
+ else {
4658
+ json.exclusiveMaximum = exclusiveMaximum;
4659
+ }
4660
+ }
4661
+ if (typeof maximum === "number") {
4662
+ json.maximum = maximum;
4663
+ if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
4664
+ if (exclusiveMaximum <= maximum)
4665
+ delete json.maximum;
4666
+ else
4667
+ delete json.exclusiveMaximum;
4668
+ }
4669
+ }
4670
+ if (typeof multipleOf === "number")
4671
+ json.multipleOf = multipleOf;
4672
+ };
4673
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
4674
+ json.type = "boolean";
4675
+ };
4676
+ const neverProcessor = (_schema, _ctx, json, _params) => {
4677
+ json.not = {};
4678
+ };
4679
+ const anyProcessor = (_schema, _ctx, _json, _params) => {
4680
+ // empty schema accepts anything
4681
+ };
4682
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {
4683
+ // empty schema accepts anything
4684
+ };
4685
+ const enumProcessor = (schema, _ctx, json, _params) => {
4686
+ const def = schema._zod.def;
4687
+ const values = getEnumValues(def.entries);
4688
+ // Number enums can have both string and number values
4689
+ if (values.every((v) => typeof v === "number"))
4690
+ json.type = "number";
4691
+ if (values.every((v) => typeof v === "string"))
4692
+ json.type = "string";
4693
+ json.enum = values;
4694
+ };
4695
+ const customProcessor = (_schema, ctx, _json, _params) => {
4696
+ if (ctx.unrepresentable === "throw") {
4697
+ throw new Error("Custom types cannot be represented in JSON Schema");
4698
+ }
4699
+ };
4700
+ const transformProcessor = (_schema, ctx, _json, _params) => {
4701
+ if (ctx.unrepresentable === "throw") {
4702
+ throw new Error("Transforms cannot be represented in JSON Schema");
4703
+ }
4704
+ };
4705
+ // ==================== COMPOSITE TYPE PROCESSORS ====================
4706
+ const arrayProcessor = (schema, ctx, _json, params) => {
4707
+ const json = _json;
4708
+ const def = schema._zod.def;
4709
+ const { minimum, maximum } = schema._zod.bag;
4710
+ if (typeof minimum === "number")
4711
+ json.minItems = minimum;
4712
+ if (typeof maximum === "number")
4713
+ json.maxItems = maximum;
4714
+ json.type = "array";
4715
+ json.items = process$1(def.element, ctx, { ...params, path: [...params.path, "items"] });
4716
+ };
4717
+ const objectProcessor = (schema, ctx, _json, params) => {
4718
+ const json = _json;
4719
+ const def = schema._zod.def;
4720
+ json.type = "object";
4721
+ json.properties = {};
4722
+ const shape = def.shape;
4723
+ for (const key in shape) {
4724
+ json.properties[key] = process$1(shape[key], ctx, {
4725
+ ...params,
4726
+ path: [...params.path, "properties", key],
4727
+ });
4728
+ }
4729
+ // required keys
4730
+ const allKeys = new Set(Object.keys(shape));
4731
+ const requiredKeys = new Set([...allKeys].filter((key) => {
4732
+ const v = def.shape[key]._zod;
4733
+ if (ctx.io === "input") {
4734
+ return v.optin === undefined;
4735
+ }
4736
+ else {
4737
+ return v.optout === undefined;
4738
+ }
4739
+ }));
4740
+ if (requiredKeys.size > 0) {
4741
+ json.required = Array.from(requiredKeys);
4742
+ }
4743
+ // catchall
4744
+ if (def.catchall?._zod.def.type === "never") {
4745
+ // strict
4746
+ json.additionalProperties = false;
4747
+ }
4748
+ else if (!def.catchall) {
4749
+ // regular
4750
+ if (ctx.io === "output")
4751
+ json.additionalProperties = false;
4752
+ }
4753
+ else if (def.catchall) {
4754
+ json.additionalProperties = process$1(def.catchall, ctx, {
4755
+ ...params,
4756
+ path: [...params.path, "additionalProperties"],
4757
+ });
4758
+ }
4759
+ };
4760
+ const unionProcessor = (schema, ctx, json, params) => {
4761
+ const def = schema._zod.def;
4762
+ // Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
4763
+ // This includes both z.xor() and discriminated unions
4764
+ const isExclusive = def.inclusive === false;
4765
+ const options = def.options.map((x, i) => process$1(x, ctx, {
4766
+ ...params,
4767
+ path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
4768
+ }));
4769
+ if (isExclusive) {
4770
+ json.oneOf = options;
4771
+ }
4772
+ else {
4773
+ json.anyOf = options;
4774
+ }
4775
+ };
4776
+ const intersectionProcessor = (schema, ctx, json, params) => {
4777
+ const def = schema._zod.def;
4778
+ const a = process$1(def.left, ctx, {
4779
+ ...params,
4780
+ path: [...params.path, "allOf", 0],
4781
+ });
4782
+ const b = process$1(def.right, ctx, {
4783
+ ...params,
4784
+ path: [...params.path, "allOf", 1],
4785
+ });
4786
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
4787
+ const allOf = [
4788
+ ...(isSimpleIntersection(a) ? a.allOf : [a]),
4789
+ ...(isSimpleIntersection(b) ? b.allOf : [b]),
4790
+ ];
4791
+ json.allOf = allOf;
4792
+ };
4793
+ const nullableProcessor = (schema, ctx, json, params) => {
4794
+ const def = schema._zod.def;
4795
+ const inner = process$1(def.innerType, ctx, params);
4796
+ const seen = ctx.seen.get(schema);
4797
+ if (ctx.target === "openapi-3.0") {
4798
+ seen.ref = def.innerType;
4799
+ json.nullable = true;
4800
+ }
4801
+ else {
4802
+ json.anyOf = [inner, { type: "null" }];
4803
+ }
4804
+ };
4805
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
4806
+ const def = schema._zod.def;
4807
+ process$1(def.innerType, ctx, params);
4808
+ const seen = ctx.seen.get(schema);
4809
+ seen.ref = def.innerType;
4810
+ };
4811
+ const defaultProcessor = (schema, ctx, json, params) => {
4812
+ const def = schema._zod.def;
4813
+ process$1(def.innerType, ctx, params);
4814
+ const seen = ctx.seen.get(schema);
4815
+ seen.ref = def.innerType;
4816
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
4817
+ };
4818
+ const prefaultProcessor = (schema, ctx, json, params) => {
4819
+ const def = schema._zod.def;
4820
+ process$1(def.innerType, ctx, params);
4821
+ const seen = ctx.seen.get(schema);
4822
+ seen.ref = def.innerType;
4823
+ if (ctx.io === "input")
4824
+ json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
4825
+ };
4826
+ const catchProcessor = (schema, ctx, json, params) => {
4827
+ const def = schema._zod.def;
4828
+ process$1(def.innerType, ctx, params);
4829
+ const seen = ctx.seen.get(schema);
4830
+ seen.ref = def.innerType;
4831
+ let catchValue;
4832
+ try {
4833
+ catchValue = def.catchValue(undefined);
4834
+ }
4835
+ catch {
4836
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
4837
+ }
4838
+ json.default = catchValue;
4839
+ };
4840
+ const pipeProcessor = (schema, ctx, _json, params) => {
4841
+ const def = schema._zod.def;
4842
+ const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
4843
+ process$1(innerType, ctx, params);
4844
+ const seen = ctx.seen.get(schema);
4845
+ seen.ref = innerType;
4846
+ };
4847
+ const readonlyProcessor = (schema, ctx, json, params) => {
4848
+ const def = schema._zod.def;
4849
+ process$1(def.innerType, ctx, params);
4850
+ const seen = ctx.seen.get(schema);
4851
+ seen.ref = def.innerType;
4852
+ json.readOnly = true;
4853
+ };
4854
+ const optionalProcessor = (schema, ctx, _json, params) => {
4855
+ const def = schema._zod.def;
4856
+ process$1(def.innerType, ctx, params);
4857
+ const seen = ctx.seen.get(schema);
4858
+ seen.ref = def.innerType;
4859
+ };
4860
+
4348
4861
  const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
4349
4862
  $ZodISODateTime.init(inst, def);
4350
4863
  ZodStringFormat.init(inst, def);
@@ -4436,6 +4949,13 @@ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
4436
4949
 
4437
4950
  const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4438
4951
  $ZodType.init(inst, def);
4952
+ Object.assign(inst["~standard"], {
4953
+ jsonSchema: {
4954
+ input: createStandardJSONSchemaMethod(inst, "input"),
4955
+ output: createStandardJSONSchemaMethod(inst, "output"),
4956
+ },
4957
+ });
4958
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
4439
4959
  inst.def = def;
4440
4960
  inst.type = def.type;
4441
4961
  Object.defineProperty(inst, "_def", { value: def });
@@ -4517,6 +5037,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
4517
5037
  const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
4518
5038
  $ZodString.init(inst, def);
4519
5039
  ZodType.init(inst, def);
5040
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
4520
5041
  const bag = inst._zod.bag;
4521
5042
  inst.format = bag.format ?? null;
4522
5043
  inst.minLength = bag.minimum ?? null;
@@ -4674,6 +5195,7 @@ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
4674
5195
  const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
4675
5196
  $ZodNumber.init(inst, def);
4676
5197
  ZodType.init(inst, def);
5198
+ inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
4677
5199
  inst.gt = (value, params) => inst.check(_gt(value, params));
4678
5200
  inst.gte = (value, params) => inst.check(_gte(value, params));
4679
5201
  inst.min = (value, params) => inst.check(_gte(value, params));
@@ -4712,6 +5234,7 @@ function int(params) {
4712
5234
  const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
4713
5235
  $ZodBoolean.init(inst, def);
4714
5236
  ZodType.init(inst, def);
5237
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
4715
5238
  });
4716
5239
  function boolean(params) {
4717
5240
  return _boolean(ZodBoolean, params);
@@ -4719,6 +5242,7 @@ function boolean(params) {
4719
5242
  const ZodAny = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
4720
5243
  $ZodAny.init(inst, def);
4721
5244
  ZodType.init(inst, def);
5245
+ inst._zod.processJSONSchema = (ctx, json, params) => anyProcessor();
4722
5246
  });
4723
5247
  function any() {
4724
5248
  return _any(ZodAny);
@@ -4726,6 +5250,7 @@ function any() {
4726
5250
  const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
4727
5251
  $ZodUnknown.init(inst, def);
4728
5252
  ZodType.init(inst, def);
5253
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
4729
5254
  });
4730
5255
  function unknown() {
4731
5256
  return _unknown(ZodUnknown);
@@ -4733,6 +5258,7 @@ function unknown() {
4733
5258
  const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
4734
5259
  $ZodNever.init(inst, def);
4735
5260
  ZodType.init(inst, def);
5261
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
4736
5262
  });
4737
5263
  function never(params) {
4738
5264
  return _never(ZodNever, params);
@@ -4740,6 +5266,7 @@ function never(params) {
4740
5266
  const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
4741
5267
  $ZodArray.init(inst, def);
4742
5268
  ZodType.init(inst, def);
5269
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
4743
5270
  inst.element = def.element;
4744
5271
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
4745
5272
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -4753,6 +5280,7 @@ function array(element, params) {
4753
5280
  const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
4754
5281
  $ZodObjectJIT.init(inst, def);
4755
5282
  ZodType.init(inst, def);
5283
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
4756
5284
  defineLazy(inst, "shape", () => {
4757
5285
  return def.shape;
4758
5286
  });
@@ -4785,6 +5313,7 @@ function object(shape, params) {
4785
5313
  const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
4786
5314
  $ZodUnion.init(inst, def);
4787
5315
  ZodType.init(inst, def);
5316
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
4788
5317
  inst.options = def.options;
4789
5318
  });
4790
5319
  function union(options, params) {
@@ -4797,6 +5326,7 @@ function union(options, params) {
4797
5326
  const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
4798
5327
  $ZodIntersection.init(inst, def);
4799
5328
  ZodType.init(inst, def);
5329
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
4800
5330
  });
4801
5331
  function intersection(left, right) {
4802
5332
  return new ZodIntersection({
@@ -4808,6 +5338,7 @@ function intersection(left, right) {
4808
5338
  const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
4809
5339
  $ZodEnum.init(inst, def);
4810
5340
  ZodType.init(inst, def);
5341
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
4811
5342
  inst.enum = def.entries;
4812
5343
  inst.options = Object.values(def.entries);
4813
5344
  const keys = new Set(Object.keys(def.entries));
@@ -4855,6 +5386,7 @@ function _enum(values, params) {
4855
5386
  const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
4856
5387
  $ZodTransform.init(inst, def);
4857
5388
  ZodType.init(inst, def);
5389
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
4858
5390
  inst._zod.parse = (payload, _ctx) => {
4859
5391
  if (_ctx.direction === "backward") {
4860
5392
  throw new $ZodEncodeError(inst.constructor.name);
@@ -4895,6 +5427,7 @@ function transform(fn) {
4895
5427
  const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
4896
5428
  $ZodOptional.init(inst, def);
4897
5429
  ZodType.init(inst, def);
5430
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
4898
5431
  inst.unwrap = () => inst._zod.def.innerType;
4899
5432
  });
4900
5433
  function optional(innerType) {
@@ -4906,6 +5439,7 @@ function optional(innerType) {
4906
5439
  const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
4907
5440
  $ZodNullable.init(inst, def);
4908
5441
  ZodType.init(inst, def);
5442
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
4909
5443
  inst.unwrap = () => inst._zod.def.innerType;
4910
5444
  });
4911
5445
  function nullable(innerType) {
@@ -4917,6 +5451,7 @@ function nullable(innerType) {
4917
5451
  const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
4918
5452
  $ZodDefault.init(inst, def);
4919
5453
  ZodType.init(inst, def);
5454
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
4920
5455
  inst.unwrap = () => inst._zod.def.innerType;
4921
5456
  inst.removeDefault = inst.unwrap;
4922
5457
  });
@@ -4932,6 +5467,7 @@ function _default(innerType, defaultValue) {
4932
5467
  const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
4933
5468
  $ZodPrefault.init(inst, def);
4934
5469
  ZodType.init(inst, def);
5470
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
4935
5471
  inst.unwrap = () => inst._zod.def.innerType;
4936
5472
  });
4937
5473
  function prefault(innerType, defaultValue) {
@@ -4946,6 +5482,7 @@ function prefault(innerType, defaultValue) {
4946
5482
  const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
4947
5483
  $ZodNonOptional.init(inst, def);
4948
5484
  ZodType.init(inst, def);
5485
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
4949
5486
  inst.unwrap = () => inst._zod.def.innerType;
4950
5487
  });
4951
5488
  function nonoptional(innerType, params) {
@@ -4958,6 +5495,7 @@ function nonoptional(innerType, params) {
4958
5495
  const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
4959
5496
  $ZodCatch.init(inst, def);
4960
5497
  ZodType.init(inst, def);
5498
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
4961
5499
  inst.unwrap = () => inst._zod.def.innerType;
4962
5500
  inst.removeCatch = inst.unwrap;
4963
5501
  });
@@ -4971,6 +5509,7 @@ function _catch(innerType, catchValue) {
4971
5509
  const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
4972
5510
  $ZodPipe.init(inst, def);
4973
5511
  ZodType.init(inst, def);
5512
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
4974
5513
  inst.in = def.in;
4975
5514
  inst.out = def.out;
4976
5515
  });
@@ -4985,6 +5524,7 @@ function pipe(in_, out) {
4985
5524
  const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
4986
5525
  $ZodReadonly.init(inst, def);
4987
5526
  ZodType.init(inst, def);
5527
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
4988
5528
  inst.unwrap = () => inst._zod.def.innerType;
4989
5529
  });
4990
5530
  function readonly(innerType) {
@@ -4996,6 +5536,7 @@ function readonly(innerType) {
4996
5536
  const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
4997
5537
  $ZodCustom.init(inst, def);
4998
5538
  ZodType.init(inst, def);
5539
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
4999
5540
  });
5000
5541
  function refine(fn, _params = {}) {
5001
5542
  return _refine(ZodCustom, fn, _params);
@@ -5054,6 +5595,10 @@ const createSchema = (rule) => {
5054
5595
  }
5055
5596
  };
5056
5597
 
5598
+ function getDefaultExportFromCjs (x) {
5599
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5600
+ }
5601
+
5057
5602
  var constants;
5058
5603
  var hasRequiredConstants;
5059
5604