@kevisual/router 0.0.6 → 0.0.7
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 +18 -0
- package/dist/router-browser.js +279 -90
- package/dist/router-sign.js +7 -7
- package/dist/router-simple.d.ts +1 -1
- package/dist/router.d.ts +18 -0
- package/dist/router.js +278 -90
- package/package.json +1 -1
package/dist/router.js
CHANGED
|
@@ -261,6 +261,9 @@ const quotelessJson = (obj) => {
|
|
|
261
261
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
262
262
|
};
|
|
263
263
|
class ZodError extends Error {
|
|
264
|
+
get errors() {
|
|
265
|
+
return this.issues;
|
|
266
|
+
}
|
|
264
267
|
constructor(issues) {
|
|
265
268
|
super();
|
|
266
269
|
this.issues = [];
|
|
@@ -281,9 +284,6 @@ class ZodError extends Error {
|
|
|
281
284
|
this.name = "ZodError";
|
|
282
285
|
this.issues = issues;
|
|
283
286
|
}
|
|
284
|
-
get errors() {
|
|
285
|
-
return this.issues;
|
|
286
|
-
}
|
|
287
287
|
format(_mapper) {
|
|
288
288
|
const mapper = _mapper ||
|
|
289
289
|
function (issue) {
|
|
@@ -539,9 +539,9 @@ function addIssueToContext(ctx, issueData) {
|
|
|
539
539
|
data: ctx.data,
|
|
540
540
|
path: ctx.path,
|
|
541
541
|
errorMaps: [
|
|
542
|
-
ctx.common.contextualErrorMap,
|
|
543
|
-
ctx.schemaErrorMap,
|
|
544
|
-
overrideMap,
|
|
542
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
543
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
544
|
+
overrideMap, // then global override map
|
|
545
545
|
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
546
546
|
].filter((x) => !!x),
|
|
547
547
|
});
|
|
@@ -628,12 +628,12 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
628
628
|
***************************************************************************** */
|
|
629
629
|
|
|
630
630
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
631
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
631
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
632
632
|
return state.get(receiver);
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
636
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
636
|
+
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
637
637
|
return (state.set(receiver, value)), value;
|
|
638
638
|
}
|
|
639
639
|
|
|
@@ -714,35 +714,6 @@ function processCreateParams(params) {
|
|
|
714
714
|
return { errorMap: customMap, description };
|
|
715
715
|
}
|
|
716
716
|
class ZodType {
|
|
717
|
-
constructor(def) {
|
|
718
|
-
/** Alias of safeParseAsync */
|
|
719
|
-
this.spa = this.safeParseAsync;
|
|
720
|
-
this._def = def;
|
|
721
|
-
this.parse = this.parse.bind(this);
|
|
722
|
-
this.safeParse = this.safeParse.bind(this);
|
|
723
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
724
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
725
|
-
this.spa = this.spa.bind(this);
|
|
726
|
-
this.refine = this.refine.bind(this);
|
|
727
|
-
this.refinement = this.refinement.bind(this);
|
|
728
|
-
this.superRefine = this.superRefine.bind(this);
|
|
729
|
-
this.optional = this.optional.bind(this);
|
|
730
|
-
this.nullable = this.nullable.bind(this);
|
|
731
|
-
this.nullish = this.nullish.bind(this);
|
|
732
|
-
this.array = this.array.bind(this);
|
|
733
|
-
this.promise = this.promise.bind(this);
|
|
734
|
-
this.or = this.or.bind(this);
|
|
735
|
-
this.and = this.and.bind(this);
|
|
736
|
-
this.transform = this.transform.bind(this);
|
|
737
|
-
this.brand = this.brand.bind(this);
|
|
738
|
-
this.default = this.default.bind(this);
|
|
739
|
-
this.catch = this.catch.bind(this);
|
|
740
|
-
this.describe = this.describe.bind(this);
|
|
741
|
-
this.pipe = this.pipe.bind(this);
|
|
742
|
-
this.readonly = this.readonly.bind(this);
|
|
743
|
-
this.isNullable = this.isNullable.bind(this);
|
|
744
|
-
this.isOptional = this.isOptional.bind(this);
|
|
745
|
-
}
|
|
746
717
|
get description() {
|
|
747
718
|
return this._def.description;
|
|
748
719
|
}
|
|
@@ -806,6 +777,48 @@ class ZodType {
|
|
|
806
777
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
807
778
|
return handleResult(ctx, result);
|
|
808
779
|
}
|
|
780
|
+
"~validate"(data) {
|
|
781
|
+
var _a, _b;
|
|
782
|
+
const ctx = {
|
|
783
|
+
common: {
|
|
784
|
+
issues: [],
|
|
785
|
+
async: !!this["~standard"].async,
|
|
786
|
+
},
|
|
787
|
+
path: [],
|
|
788
|
+
schemaErrorMap: this._def.errorMap,
|
|
789
|
+
parent: null,
|
|
790
|
+
data,
|
|
791
|
+
parsedType: getParsedType(data),
|
|
792
|
+
};
|
|
793
|
+
if (!this["~standard"].async) {
|
|
794
|
+
try {
|
|
795
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
796
|
+
return isValid(result)
|
|
797
|
+
? {
|
|
798
|
+
value: result.value,
|
|
799
|
+
}
|
|
800
|
+
: {
|
|
801
|
+
issues: ctx.common.issues,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
catch (err) {
|
|
805
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
806
|
+
this["~standard"].async = true;
|
|
807
|
+
}
|
|
808
|
+
ctx.common = {
|
|
809
|
+
issues: [],
|
|
810
|
+
async: true,
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result)
|
|
815
|
+
? {
|
|
816
|
+
value: result.value,
|
|
817
|
+
}
|
|
818
|
+
: {
|
|
819
|
+
issues: ctx.common.issues,
|
|
820
|
+
});
|
|
821
|
+
}
|
|
809
822
|
async parseAsync(data, params) {
|
|
810
823
|
const result = await this.safeParseAsync(data, params);
|
|
811
824
|
if (result.success)
|
|
@@ -892,6 +905,40 @@ class ZodType {
|
|
|
892
905
|
superRefine(refinement) {
|
|
893
906
|
return this._refinement(refinement);
|
|
894
907
|
}
|
|
908
|
+
constructor(def) {
|
|
909
|
+
/** Alias of safeParseAsync */
|
|
910
|
+
this.spa = this.safeParseAsync;
|
|
911
|
+
this._def = def;
|
|
912
|
+
this.parse = this.parse.bind(this);
|
|
913
|
+
this.safeParse = this.safeParse.bind(this);
|
|
914
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
915
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
916
|
+
this.spa = this.spa.bind(this);
|
|
917
|
+
this.refine = this.refine.bind(this);
|
|
918
|
+
this.refinement = this.refinement.bind(this);
|
|
919
|
+
this.superRefine = this.superRefine.bind(this);
|
|
920
|
+
this.optional = this.optional.bind(this);
|
|
921
|
+
this.nullable = this.nullable.bind(this);
|
|
922
|
+
this.nullish = this.nullish.bind(this);
|
|
923
|
+
this.array = this.array.bind(this);
|
|
924
|
+
this.promise = this.promise.bind(this);
|
|
925
|
+
this.or = this.or.bind(this);
|
|
926
|
+
this.and = this.and.bind(this);
|
|
927
|
+
this.transform = this.transform.bind(this);
|
|
928
|
+
this.brand = this.brand.bind(this);
|
|
929
|
+
this.default = this.default.bind(this);
|
|
930
|
+
this.catch = this.catch.bind(this);
|
|
931
|
+
this.describe = this.describe.bind(this);
|
|
932
|
+
this.pipe = this.pipe.bind(this);
|
|
933
|
+
this.readonly = this.readonly.bind(this);
|
|
934
|
+
this.isNullable = this.isNullable.bind(this);
|
|
935
|
+
this.isOptional = this.isOptional.bind(this);
|
|
936
|
+
this["~standard"] = {
|
|
937
|
+
version: 1,
|
|
938
|
+
vendor: "zod",
|
|
939
|
+
validate: (data) => this["~validate"](data),
|
|
940
|
+
};
|
|
941
|
+
}
|
|
895
942
|
optional() {
|
|
896
943
|
return ZodOptional.create(this, this._def);
|
|
897
944
|
}
|
|
@@ -902,7 +949,7 @@ class ZodType {
|
|
|
902
949
|
return this.nullable().optional();
|
|
903
950
|
}
|
|
904
951
|
array() {
|
|
905
|
-
return ZodArray.create(this
|
|
952
|
+
return ZodArray.create(this);
|
|
906
953
|
}
|
|
907
954
|
promise() {
|
|
908
955
|
return ZodPromise.create(this, this._def);
|
|
@@ -968,11 +1015,12 @@ class ZodType {
|
|
|
968
1015
|
}
|
|
969
1016
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
970
1017
|
const cuid2Regex = /^[0-9a-z]+$/;
|
|
971
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
1018
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
972
1019
|
// const uuidRegex =
|
|
973
1020
|
// /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
974
1021
|
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
975
1022
|
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1023
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
976
1024
|
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
977
1025
|
// from https://stackoverflow.com/a/46181/1550155
|
|
978
1026
|
// old version: too slow, didn't support unicode
|
|
@@ -994,9 +1042,15 @@ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
|
994
1042
|
let emojiRegex;
|
|
995
1043
|
// faster, simpler, safer
|
|
996
1044
|
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
997
|
-
const
|
|
1045
|
+
const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
1046
|
+
// const ipv6Regex =
|
|
1047
|
+
// /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
|
1048
|
+
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1049
|
+
const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
998
1050
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
999
1051
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1052
|
+
// https://base64.guru/standards/base64url
|
|
1053
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1000
1054
|
// simple
|
|
1001
1055
|
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
1002
1056
|
// no leap year validation
|
|
@@ -1037,6 +1091,38 @@ function isValidIP(ip, version) {
|
|
|
1037
1091
|
}
|
|
1038
1092
|
return false;
|
|
1039
1093
|
}
|
|
1094
|
+
function isValidJWT(jwt, alg) {
|
|
1095
|
+
if (!jwtRegex.test(jwt))
|
|
1096
|
+
return false;
|
|
1097
|
+
try {
|
|
1098
|
+
const [header] = jwt.split(".");
|
|
1099
|
+
// Convert base64url to base64
|
|
1100
|
+
const base64 = header
|
|
1101
|
+
.replace(/-/g, "+")
|
|
1102
|
+
.replace(/_/g, "/")
|
|
1103
|
+
.padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
|
|
1104
|
+
const decoded = JSON.parse(atob(base64));
|
|
1105
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1106
|
+
return false;
|
|
1107
|
+
if (!decoded.typ || !decoded.alg)
|
|
1108
|
+
return false;
|
|
1109
|
+
if (alg && decoded.alg !== alg)
|
|
1110
|
+
return false;
|
|
1111
|
+
return true;
|
|
1112
|
+
}
|
|
1113
|
+
catch (_a) {
|
|
1114
|
+
return false;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
function isValidCidr(ip, version) {
|
|
1118
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1119
|
+
return true;
|
|
1120
|
+
}
|
|
1121
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1122
|
+
return true;
|
|
1123
|
+
}
|
|
1124
|
+
return false;
|
|
1125
|
+
}
|
|
1040
1126
|
class ZodString extends ZodType {
|
|
1041
1127
|
_parse(input) {
|
|
1042
1128
|
if (this._def.coerce) {
|
|
@@ -1318,6 +1404,28 @@ class ZodString extends ZodType {
|
|
|
1318
1404
|
status.dirty();
|
|
1319
1405
|
}
|
|
1320
1406
|
}
|
|
1407
|
+
else if (check.kind === "jwt") {
|
|
1408
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1409
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1410
|
+
addIssueToContext(ctx, {
|
|
1411
|
+
validation: "jwt",
|
|
1412
|
+
code: ZodIssueCode.invalid_string,
|
|
1413
|
+
message: check.message,
|
|
1414
|
+
});
|
|
1415
|
+
status.dirty();
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
else if (check.kind === "cidr") {
|
|
1419
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1420
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1421
|
+
addIssueToContext(ctx, {
|
|
1422
|
+
validation: "cidr",
|
|
1423
|
+
code: ZodIssueCode.invalid_string,
|
|
1424
|
+
message: check.message,
|
|
1425
|
+
});
|
|
1426
|
+
status.dirty();
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1321
1429
|
else if (check.kind === "base64") {
|
|
1322
1430
|
if (!base64Regex.test(input.data)) {
|
|
1323
1431
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1329,6 +1437,17 @@ class ZodString extends ZodType {
|
|
|
1329
1437
|
status.dirty();
|
|
1330
1438
|
}
|
|
1331
1439
|
}
|
|
1440
|
+
else if (check.kind === "base64url") {
|
|
1441
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1442
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1443
|
+
addIssueToContext(ctx, {
|
|
1444
|
+
validation: "base64url",
|
|
1445
|
+
code: ZodIssueCode.invalid_string,
|
|
1446
|
+
message: check.message,
|
|
1447
|
+
});
|
|
1448
|
+
status.dirty();
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1332
1451
|
else {
|
|
1333
1452
|
util.assertNever(check);
|
|
1334
1453
|
}
|
|
@@ -1375,9 +1494,22 @@ class ZodString extends ZodType {
|
|
|
1375
1494
|
base64(message) {
|
|
1376
1495
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1377
1496
|
}
|
|
1497
|
+
base64url(message) {
|
|
1498
|
+
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1499
|
+
return this._addCheck({
|
|
1500
|
+
kind: "base64url",
|
|
1501
|
+
...errorUtil.errToObj(message),
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
jwt(options) {
|
|
1505
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1506
|
+
}
|
|
1378
1507
|
ip(options) {
|
|
1379
1508
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1380
1509
|
}
|
|
1510
|
+
cidr(options) {
|
|
1511
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1512
|
+
}
|
|
1381
1513
|
datetime(options) {
|
|
1382
1514
|
var _a, _b;
|
|
1383
1515
|
if (typeof options === "string") {
|
|
@@ -1468,8 +1600,7 @@ class ZodString extends ZodType {
|
|
|
1468
1600
|
});
|
|
1469
1601
|
}
|
|
1470
1602
|
/**
|
|
1471
|
-
*
|
|
1472
|
-
* @see {@link ZodString.min}
|
|
1603
|
+
* Equivalent to `.min(1)`
|
|
1473
1604
|
*/
|
|
1474
1605
|
nonempty(message) {
|
|
1475
1606
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1531,9 +1662,16 @@ class ZodString extends ZodType {
|
|
|
1531
1662
|
get isIP() {
|
|
1532
1663
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1533
1664
|
}
|
|
1665
|
+
get isCIDR() {
|
|
1666
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1667
|
+
}
|
|
1534
1668
|
get isBase64() {
|
|
1535
1669
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1536
1670
|
}
|
|
1671
|
+
get isBase64url() {
|
|
1672
|
+
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1673
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1674
|
+
}
|
|
1537
1675
|
get minLength() {
|
|
1538
1676
|
let min = null;
|
|
1539
1677
|
for (const ch of this._def.checks) {
|
|
@@ -1826,17 +1964,16 @@ class ZodBigInt extends ZodType {
|
|
|
1826
1964
|
}
|
|
1827
1965
|
_parse(input) {
|
|
1828
1966
|
if (this._def.coerce) {
|
|
1829
|
-
|
|
1967
|
+
try {
|
|
1968
|
+
input.data = BigInt(input.data);
|
|
1969
|
+
}
|
|
1970
|
+
catch (_a) {
|
|
1971
|
+
return this._getInvalidInput(input);
|
|
1972
|
+
}
|
|
1830
1973
|
}
|
|
1831
1974
|
const parsedType = this._getType(input);
|
|
1832
1975
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1833
|
-
|
|
1834
|
-
addIssueToContext(ctx, {
|
|
1835
|
-
code: ZodIssueCode.invalid_type,
|
|
1836
|
-
expected: ZodParsedType.bigint,
|
|
1837
|
-
received: ctx.parsedType,
|
|
1838
|
-
});
|
|
1839
|
-
return INVALID;
|
|
1976
|
+
return this._getInvalidInput(input);
|
|
1840
1977
|
}
|
|
1841
1978
|
let ctx = undefined;
|
|
1842
1979
|
const status = new ParseStatus();
|
|
@@ -1890,6 +2027,15 @@ class ZodBigInt extends ZodType {
|
|
|
1890
2027
|
}
|
|
1891
2028
|
return { status: status.value, value: input.data };
|
|
1892
2029
|
}
|
|
2030
|
+
_getInvalidInput(input) {
|
|
2031
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2032
|
+
addIssueToContext(ctx, {
|
|
2033
|
+
code: ZodIssueCode.invalid_type,
|
|
2034
|
+
expected: ZodParsedType.bigint,
|
|
2035
|
+
received: ctx.parsedType,
|
|
2036
|
+
});
|
|
2037
|
+
return INVALID;
|
|
2038
|
+
}
|
|
1893
2039
|
gte(value, message) {
|
|
1894
2040
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1895
2041
|
}
|
|
@@ -4096,7 +4242,23 @@ ZodReadonly.create = (type, params) => {
|
|
|
4096
4242
|
...processCreateParams(params),
|
|
4097
4243
|
});
|
|
4098
4244
|
};
|
|
4099
|
-
|
|
4245
|
+
////////////////////////////////////////
|
|
4246
|
+
////////////////////////////////////////
|
|
4247
|
+
////////// //////////
|
|
4248
|
+
////////// z.custom //////////
|
|
4249
|
+
////////// //////////
|
|
4250
|
+
////////////////////////////////////////
|
|
4251
|
+
////////////////////////////////////////
|
|
4252
|
+
function cleanParams(params, data) {
|
|
4253
|
+
const p = typeof params === "function"
|
|
4254
|
+
? params(data)
|
|
4255
|
+
: typeof params === "string"
|
|
4256
|
+
? { message: params }
|
|
4257
|
+
: params;
|
|
4258
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4259
|
+
return p2;
|
|
4260
|
+
}
|
|
4261
|
+
function custom(check, _params = {},
|
|
4100
4262
|
/**
|
|
4101
4263
|
* @deprecated
|
|
4102
4264
|
*
|
|
@@ -4111,16 +4273,23 @@ fatal) {
|
|
|
4111
4273
|
if (check)
|
|
4112
4274
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4113
4275
|
var _a, _b;
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4276
|
+
const r = check(data);
|
|
4277
|
+
if (r instanceof Promise) {
|
|
4278
|
+
return r.then((r) => {
|
|
4279
|
+
var _a, _b;
|
|
4280
|
+
if (!r) {
|
|
4281
|
+
const params = cleanParams(_params, data);
|
|
4282
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4283
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4284
|
+
}
|
|
4285
|
+
});
|
|
4286
|
+
}
|
|
4287
|
+
if (!r) {
|
|
4288
|
+
const params = cleanParams(_params, data);
|
|
4289
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4290
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4123
4291
|
}
|
|
4292
|
+
return;
|
|
4124
4293
|
});
|
|
4125
4294
|
return ZodAny.create();
|
|
4126
4295
|
}
|
|
@@ -4584,9 +4753,6 @@ function arrayMap(array, iteratee) {
|
|
|
4584
4753
|
*/
|
|
4585
4754
|
var isArray = Array.isArray;
|
|
4586
4755
|
|
|
4587
|
-
/** Used as references for various `Number` constants. */
|
|
4588
|
-
var INFINITY$1 = 1 / 0;
|
|
4589
|
-
|
|
4590
4756
|
/** Used to convert symbols to primitives and strings. */
|
|
4591
4757
|
var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
|
|
4592
4758
|
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
|
@@ -4612,7 +4778,7 @@ function baseToString(value) {
|
|
|
4612
4778
|
return symbolToString ? symbolToString.call(value) : '';
|
|
4613
4779
|
}
|
|
4614
4780
|
var result = (value + '');
|
|
4615
|
-
return (result == '0' && (1 / value) == -
|
|
4781
|
+
return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
|
|
4616
4782
|
}
|
|
4617
4783
|
|
|
4618
4784
|
/**
|
|
@@ -5402,9 +5568,6 @@ function castPath(value, object) {
|
|
|
5402
5568
|
return isKey(value, object) ? [value] : stringToPath(toString(value));
|
|
5403
5569
|
}
|
|
5404
5570
|
|
|
5405
|
-
/** Used as references for various `Number` constants. */
|
|
5406
|
-
var INFINITY = 1 / 0;
|
|
5407
|
-
|
|
5408
5571
|
/**
|
|
5409
5572
|
* Converts `value` to a string key if it's not a string or symbol.
|
|
5410
5573
|
*
|
|
@@ -5417,7 +5580,7 @@ function toKey(value) {
|
|
|
5417
5580
|
return value;
|
|
5418
5581
|
}
|
|
5419
5582
|
var result = (value + '');
|
|
5420
|
-
return (result == '0' && (1 / value) == -
|
|
5583
|
+
return (result == '0' && (1 / value) == -Infinity) ? '-0' : result;
|
|
5421
5584
|
}
|
|
5422
5585
|
|
|
5423
5586
|
/**
|
|
@@ -5472,19 +5635,32 @@ function get(object, path, defaultValue) {
|
|
|
5472
5635
|
|
|
5473
5636
|
const pickValue = ['path', 'key', 'id', 'description', 'type', 'validator', 'middleware'];
|
|
5474
5637
|
class Route {
|
|
5638
|
+
/**
|
|
5639
|
+
* 一级路径
|
|
5640
|
+
*/
|
|
5475
5641
|
path;
|
|
5642
|
+
/**
|
|
5643
|
+
* 二级路径
|
|
5644
|
+
*/
|
|
5476
5645
|
key;
|
|
5477
5646
|
id;
|
|
5478
5647
|
share = false;
|
|
5479
5648
|
run;
|
|
5480
5649
|
nextRoute; // route to run after this route
|
|
5481
5650
|
description;
|
|
5651
|
+
metadata;
|
|
5482
5652
|
middleware; // middleware
|
|
5483
5653
|
type = 'route';
|
|
5484
5654
|
_validator;
|
|
5485
5655
|
schema;
|
|
5486
5656
|
data;
|
|
5657
|
+
/**
|
|
5658
|
+
* 是否需要验证
|
|
5659
|
+
*/
|
|
5487
5660
|
isVerify;
|
|
5661
|
+
/**
|
|
5662
|
+
* 是否开启debug,开启后会打印错误信息
|
|
5663
|
+
*/
|
|
5488
5664
|
isDebug;
|
|
5489
5665
|
constructor(path, key = '', opts) {
|
|
5490
5666
|
path = path.trim();
|
|
@@ -5499,6 +5675,7 @@ class Route {
|
|
|
5499
5675
|
this.run = opts.run;
|
|
5500
5676
|
this.nextRoute = opts.nextRoute;
|
|
5501
5677
|
this.description = opts.description;
|
|
5678
|
+
this.metadata = opts.metadata;
|
|
5502
5679
|
this.type = opts.type || 'route';
|
|
5503
5680
|
this.validator = opts.validator;
|
|
5504
5681
|
this.middleware = opts.middleware || [];
|
|
@@ -5613,7 +5790,7 @@ class Route {
|
|
|
5613
5790
|
// 全覆盖,所以opts需要准确,不能由idUsePath 需要check的变量
|
|
5614
5791
|
const setOpts = (opts) => {
|
|
5615
5792
|
const keys = Object.keys(opts);
|
|
5616
|
-
const checkList = ['path', 'key', 'run', 'nextRoute', 'description', 'middleware', 'type', 'validator', 'isVerify', 'isDebug'];
|
|
5793
|
+
const checkList = ['path', 'key', 'run', 'nextRoute', 'description', 'metadata', 'middleware', 'type', 'validator', 'isVerify', 'isDebug'];
|
|
5617
5794
|
for (let item of keys) {
|
|
5618
5795
|
if (!checkList.includes(item)) {
|
|
5619
5796
|
continue;
|
|
@@ -5711,30 +5888,41 @@ class QueryRouter {
|
|
|
5711
5888
|
// run middleware
|
|
5712
5889
|
if (route && route.middleware && route.middleware.length > 0) {
|
|
5713
5890
|
const errorMiddleware = [];
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
const
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
route = this.routes.find((r) => r.path === m.path && r.key === m.key);
|
|
5723
|
-
}
|
|
5724
|
-
if (!route) {
|
|
5891
|
+
const getMiddleware = (m) => {
|
|
5892
|
+
if (!m.middleware || m.middleware.length === 0)
|
|
5893
|
+
return [];
|
|
5894
|
+
const routeMiddleware = [];
|
|
5895
|
+
for (let i = 0; i < m.middleware.length; i++) {
|
|
5896
|
+
const item = m.middleware[i];
|
|
5897
|
+
let route;
|
|
5898
|
+
const isString = typeof item === 'string';
|
|
5725
5899
|
if (isString) {
|
|
5726
|
-
|
|
5727
|
-
id: m,
|
|
5728
|
-
});
|
|
5900
|
+
route = this.routes.find((r) => r.id === item);
|
|
5729
5901
|
}
|
|
5730
|
-
else
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5902
|
+
else {
|
|
5903
|
+
route = this.routes.find((r) => r.path === item.path && r.key === item.key);
|
|
5904
|
+
}
|
|
5905
|
+
if (!route) {
|
|
5906
|
+
if (isString) {
|
|
5907
|
+
errorMiddleware.push({
|
|
5908
|
+
id: item,
|
|
5909
|
+
});
|
|
5910
|
+
}
|
|
5911
|
+
else
|
|
5912
|
+
errorMiddleware.push({
|
|
5913
|
+
path: m?.path,
|
|
5914
|
+
key: m?.key,
|
|
5915
|
+
});
|
|
5916
|
+
}
|
|
5917
|
+
const routeMiddlewarePrevious = getMiddleware(route);
|
|
5918
|
+
if (routeMiddlewarePrevious.length > 0) {
|
|
5919
|
+
routeMiddleware.push(...routeMiddlewarePrevious);
|
|
5920
|
+
}
|
|
5921
|
+
routeMiddleware.push(route);
|
|
5735
5922
|
}
|
|
5736
|
-
return
|
|
5737
|
-
}
|
|
5923
|
+
return routeMiddleware;
|
|
5924
|
+
};
|
|
5925
|
+
const routeMiddleware = getMiddleware(route);
|
|
5738
5926
|
if (errorMiddleware.length > 0) {
|
|
5739
5927
|
console.error('middleware not found');
|
|
5740
5928
|
ctx.body = errorMiddleware;
|