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