@thirstie/thirstievalidators 1.0.1 → 1.1.1
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/CHANGELOG.md +38 -0
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/agegate.js.html +1 -1
- package/coverage/lcov-report/emailLists.js.html +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/index.js.html +1 -1
- package/coverage/lcov-report/iso3166codes.js.html +1 -1
- package/coverage/lcov-report/passwordcheck.js.html +1 -1
- package/dist/bundle.cjs +229 -60
- package/dist/bundle.iife.js +1 -1
- package/dist/bundle.mjs +229 -60
- package/package.json +2 -2
package/dist/bundle.mjs
CHANGED
|
@@ -332,6 +332,9 @@ const quotelessJson = (obj) => {
|
|
|
332
332
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
333
333
|
};
|
|
334
334
|
class ZodError extends Error {
|
|
335
|
+
get errors() {
|
|
336
|
+
return this.issues;
|
|
337
|
+
}
|
|
335
338
|
constructor(issues) {
|
|
336
339
|
super();
|
|
337
340
|
this.issues = [];
|
|
@@ -352,9 +355,6 @@ class ZodError extends Error {
|
|
|
352
355
|
this.name = "ZodError";
|
|
353
356
|
this.issues = issues;
|
|
354
357
|
}
|
|
355
|
-
get errors() {
|
|
356
|
-
return this.issues;
|
|
357
|
-
}
|
|
358
358
|
format(_mapper) {
|
|
359
359
|
const mapper = _mapper ||
|
|
360
360
|
function (issue) {
|
|
@@ -610,9 +610,9 @@ function addIssueToContext(ctx, issueData) {
|
|
|
610
610
|
data: ctx.data,
|
|
611
611
|
path: ctx.path,
|
|
612
612
|
errorMaps: [
|
|
613
|
-
ctx.common.contextualErrorMap,
|
|
614
|
-
ctx.schemaErrorMap,
|
|
615
|
-
overrideMap,
|
|
613
|
+
ctx.common.contextualErrorMap, // contextual error map is first priority
|
|
614
|
+
ctx.schemaErrorMap, // then schema-bound map if available
|
|
615
|
+
overrideMap, // then global override map
|
|
616
616
|
overrideMap === errorMap ? undefined : errorMap, // then global default map
|
|
617
617
|
].filter((x) => !!x),
|
|
618
618
|
});
|
|
@@ -699,12 +699,12 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
699
699
|
***************************************************************************** */
|
|
700
700
|
|
|
701
701
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
702
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
702
|
+
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");
|
|
703
703
|
return state.get(receiver);
|
|
704
704
|
}
|
|
705
705
|
|
|
706
706
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
707
|
-
if (typeof state === "function" ? receiver !== state ||
|
|
707
|
+
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");
|
|
708
708
|
return (state.set(receiver, value)), value;
|
|
709
709
|
}
|
|
710
710
|
|
|
@@ -785,35 +785,6 @@ function processCreateParams(params) {
|
|
|
785
785
|
return { errorMap: customMap, description };
|
|
786
786
|
}
|
|
787
787
|
class ZodType {
|
|
788
|
-
constructor(def) {
|
|
789
|
-
/** Alias of safeParseAsync */
|
|
790
|
-
this.spa = this.safeParseAsync;
|
|
791
|
-
this._def = def;
|
|
792
|
-
this.parse = this.parse.bind(this);
|
|
793
|
-
this.safeParse = this.safeParse.bind(this);
|
|
794
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
795
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
796
|
-
this.spa = this.spa.bind(this);
|
|
797
|
-
this.refine = this.refine.bind(this);
|
|
798
|
-
this.refinement = this.refinement.bind(this);
|
|
799
|
-
this.superRefine = this.superRefine.bind(this);
|
|
800
|
-
this.optional = this.optional.bind(this);
|
|
801
|
-
this.nullable = this.nullable.bind(this);
|
|
802
|
-
this.nullish = this.nullish.bind(this);
|
|
803
|
-
this.array = this.array.bind(this);
|
|
804
|
-
this.promise = this.promise.bind(this);
|
|
805
|
-
this.or = this.or.bind(this);
|
|
806
|
-
this.and = this.and.bind(this);
|
|
807
|
-
this.transform = this.transform.bind(this);
|
|
808
|
-
this.brand = this.brand.bind(this);
|
|
809
|
-
this.default = this.default.bind(this);
|
|
810
|
-
this.catch = this.catch.bind(this);
|
|
811
|
-
this.describe = this.describe.bind(this);
|
|
812
|
-
this.pipe = this.pipe.bind(this);
|
|
813
|
-
this.readonly = this.readonly.bind(this);
|
|
814
|
-
this.isNullable = this.isNullable.bind(this);
|
|
815
|
-
this.isOptional = this.isOptional.bind(this);
|
|
816
|
-
}
|
|
817
788
|
get description() {
|
|
818
789
|
return this._def.description;
|
|
819
790
|
}
|
|
@@ -877,6 +848,48 @@ class ZodType {
|
|
|
877
848
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
878
849
|
return handleResult(ctx, result);
|
|
879
850
|
}
|
|
851
|
+
"~validate"(data) {
|
|
852
|
+
var _a, _b;
|
|
853
|
+
const ctx = {
|
|
854
|
+
common: {
|
|
855
|
+
issues: [],
|
|
856
|
+
async: !!this["~standard"].async,
|
|
857
|
+
},
|
|
858
|
+
path: [],
|
|
859
|
+
schemaErrorMap: this._def.errorMap,
|
|
860
|
+
parent: null,
|
|
861
|
+
data,
|
|
862
|
+
parsedType: getParsedType(data),
|
|
863
|
+
};
|
|
864
|
+
if (!this["~standard"].async) {
|
|
865
|
+
try {
|
|
866
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
867
|
+
return isValid(result)
|
|
868
|
+
? {
|
|
869
|
+
value: result.value,
|
|
870
|
+
}
|
|
871
|
+
: {
|
|
872
|
+
issues: ctx.common.issues,
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
catch (err) {
|
|
876
|
+
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")) {
|
|
877
|
+
this["~standard"].async = true;
|
|
878
|
+
}
|
|
879
|
+
ctx.common = {
|
|
880
|
+
issues: [],
|
|
881
|
+
async: true,
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result)
|
|
886
|
+
? {
|
|
887
|
+
value: result.value,
|
|
888
|
+
}
|
|
889
|
+
: {
|
|
890
|
+
issues: ctx.common.issues,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
880
893
|
async parseAsync(data, params) {
|
|
881
894
|
const result = await this.safeParseAsync(data, params);
|
|
882
895
|
if (result.success)
|
|
@@ -963,6 +976,40 @@ class ZodType {
|
|
|
963
976
|
superRefine(refinement) {
|
|
964
977
|
return this._refinement(refinement);
|
|
965
978
|
}
|
|
979
|
+
constructor(def) {
|
|
980
|
+
/** Alias of safeParseAsync */
|
|
981
|
+
this.spa = this.safeParseAsync;
|
|
982
|
+
this._def = def;
|
|
983
|
+
this.parse = this.parse.bind(this);
|
|
984
|
+
this.safeParse = this.safeParse.bind(this);
|
|
985
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
986
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
987
|
+
this.spa = this.spa.bind(this);
|
|
988
|
+
this.refine = this.refine.bind(this);
|
|
989
|
+
this.refinement = this.refinement.bind(this);
|
|
990
|
+
this.superRefine = this.superRefine.bind(this);
|
|
991
|
+
this.optional = this.optional.bind(this);
|
|
992
|
+
this.nullable = this.nullable.bind(this);
|
|
993
|
+
this.nullish = this.nullish.bind(this);
|
|
994
|
+
this.array = this.array.bind(this);
|
|
995
|
+
this.promise = this.promise.bind(this);
|
|
996
|
+
this.or = this.or.bind(this);
|
|
997
|
+
this.and = this.and.bind(this);
|
|
998
|
+
this.transform = this.transform.bind(this);
|
|
999
|
+
this.brand = this.brand.bind(this);
|
|
1000
|
+
this.default = this.default.bind(this);
|
|
1001
|
+
this.catch = this.catch.bind(this);
|
|
1002
|
+
this.describe = this.describe.bind(this);
|
|
1003
|
+
this.pipe = this.pipe.bind(this);
|
|
1004
|
+
this.readonly = this.readonly.bind(this);
|
|
1005
|
+
this.isNullable = this.isNullable.bind(this);
|
|
1006
|
+
this.isOptional = this.isOptional.bind(this);
|
|
1007
|
+
this["~standard"] = {
|
|
1008
|
+
version: 1,
|
|
1009
|
+
vendor: "zod",
|
|
1010
|
+
validate: (data) => this["~validate"](data),
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
966
1013
|
optional() {
|
|
967
1014
|
return ZodOptional.create(this, this._def);
|
|
968
1015
|
}
|
|
@@ -973,7 +1020,7 @@ class ZodType {
|
|
|
973
1020
|
return this.nullable().optional();
|
|
974
1021
|
}
|
|
975
1022
|
array() {
|
|
976
|
-
return ZodArray.create(this
|
|
1023
|
+
return ZodArray.create(this);
|
|
977
1024
|
}
|
|
978
1025
|
promise() {
|
|
979
1026
|
return ZodPromise.create(this, this._def);
|
|
@@ -1039,11 +1086,12 @@ class ZodType {
|
|
|
1039
1086
|
}
|
|
1040
1087
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1041
1088
|
const cuid2Regex = /^[0-9a-z]+$/;
|
|
1042
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
1089
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1043
1090
|
// const uuidRegex =
|
|
1044
1091
|
// /^([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;
|
|
1045
1092
|
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;
|
|
1046
1093
|
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1094
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1047
1095
|
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)?)??$/;
|
|
1048
1096
|
// from https://stackoverflow.com/a/46181/1550155
|
|
1049
1097
|
// old version: too slow, didn't support unicode
|
|
@@ -1065,9 +1113,15 @@ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
|
1065
1113
|
let emojiRegex;
|
|
1066
1114
|
// faster, simpler, safer
|
|
1067
1115
|
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])$/;
|
|
1068
|
-
const
|
|
1116
|
+
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])$/;
|
|
1117
|
+
// const ipv6Regex =
|
|
1118
|
+
// /^(([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})))$/;
|
|
1119
|
+
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]))$/;
|
|
1120
|
+
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])$/;
|
|
1069
1121
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
1070
1122
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1123
|
+
// https://base64.guru/standards/base64url
|
|
1124
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1071
1125
|
// simple
|
|
1072
1126
|
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
1073
1127
|
// no leap year validation
|
|
@@ -1108,6 +1162,38 @@ function isValidIP(ip, version) {
|
|
|
1108
1162
|
}
|
|
1109
1163
|
return false;
|
|
1110
1164
|
}
|
|
1165
|
+
function isValidJWT(jwt, alg) {
|
|
1166
|
+
if (!jwtRegex.test(jwt))
|
|
1167
|
+
return false;
|
|
1168
|
+
try {
|
|
1169
|
+
const [header] = jwt.split(".");
|
|
1170
|
+
// Convert base64url to base64
|
|
1171
|
+
const base64 = header
|
|
1172
|
+
.replace(/-/g, "+")
|
|
1173
|
+
.replace(/_/g, "/")
|
|
1174
|
+
.padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
|
|
1175
|
+
const decoded = JSON.parse(atob(base64));
|
|
1176
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1177
|
+
return false;
|
|
1178
|
+
if (!decoded.typ || !decoded.alg)
|
|
1179
|
+
return false;
|
|
1180
|
+
if (alg && decoded.alg !== alg)
|
|
1181
|
+
return false;
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
catch (_a) {
|
|
1185
|
+
return false;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function isValidCidr(ip, version) {
|
|
1189
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1111
1197
|
class ZodString extends ZodType {
|
|
1112
1198
|
_parse(input) {
|
|
1113
1199
|
if (this._def.coerce) {
|
|
@@ -1389,6 +1475,28 @@ class ZodString extends ZodType {
|
|
|
1389
1475
|
status.dirty();
|
|
1390
1476
|
}
|
|
1391
1477
|
}
|
|
1478
|
+
else if (check.kind === "jwt") {
|
|
1479
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1480
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1481
|
+
addIssueToContext(ctx, {
|
|
1482
|
+
validation: "jwt",
|
|
1483
|
+
code: ZodIssueCode.invalid_string,
|
|
1484
|
+
message: check.message,
|
|
1485
|
+
});
|
|
1486
|
+
status.dirty();
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
else if (check.kind === "cidr") {
|
|
1490
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1491
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1492
|
+
addIssueToContext(ctx, {
|
|
1493
|
+
validation: "cidr",
|
|
1494
|
+
code: ZodIssueCode.invalid_string,
|
|
1495
|
+
message: check.message,
|
|
1496
|
+
});
|
|
1497
|
+
status.dirty();
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1392
1500
|
else if (check.kind === "base64") {
|
|
1393
1501
|
if (!base64Regex.test(input.data)) {
|
|
1394
1502
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1400,6 +1508,17 @@ class ZodString extends ZodType {
|
|
|
1400
1508
|
status.dirty();
|
|
1401
1509
|
}
|
|
1402
1510
|
}
|
|
1511
|
+
else if (check.kind === "base64url") {
|
|
1512
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1513
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1514
|
+
addIssueToContext(ctx, {
|
|
1515
|
+
validation: "base64url",
|
|
1516
|
+
code: ZodIssueCode.invalid_string,
|
|
1517
|
+
message: check.message,
|
|
1518
|
+
});
|
|
1519
|
+
status.dirty();
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1403
1522
|
else {
|
|
1404
1523
|
util.assertNever(check);
|
|
1405
1524
|
}
|
|
@@ -1446,9 +1565,22 @@ class ZodString extends ZodType {
|
|
|
1446
1565
|
base64(message) {
|
|
1447
1566
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1448
1567
|
}
|
|
1568
|
+
base64url(message) {
|
|
1569
|
+
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1570
|
+
return this._addCheck({
|
|
1571
|
+
kind: "base64url",
|
|
1572
|
+
...errorUtil.errToObj(message),
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
jwt(options) {
|
|
1576
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1577
|
+
}
|
|
1449
1578
|
ip(options) {
|
|
1450
1579
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1451
1580
|
}
|
|
1581
|
+
cidr(options) {
|
|
1582
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1583
|
+
}
|
|
1452
1584
|
datetime(options) {
|
|
1453
1585
|
var _a, _b;
|
|
1454
1586
|
if (typeof options === "string") {
|
|
@@ -1539,8 +1671,7 @@ class ZodString extends ZodType {
|
|
|
1539
1671
|
});
|
|
1540
1672
|
}
|
|
1541
1673
|
/**
|
|
1542
|
-
*
|
|
1543
|
-
* @see {@link ZodString.min}
|
|
1674
|
+
* Equivalent to `.min(1)`
|
|
1544
1675
|
*/
|
|
1545
1676
|
nonempty(message) {
|
|
1546
1677
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1602,9 +1733,16 @@ class ZodString extends ZodType {
|
|
|
1602
1733
|
get isIP() {
|
|
1603
1734
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1604
1735
|
}
|
|
1736
|
+
get isCIDR() {
|
|
1737
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1738
|
+
}
|
|
1605
1739
|
get isBase64() {
|
|
1606
1740
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1607
1741
|
}
|
|
1742
|
+
get isBase64url() {
|
|
1743
|
+
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1744
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1745
|
+
}
|
|
1608
1746
|
get minLength() {
|
|
1609
1747
|
let min = null;
|
|
1610
1748
|
for (const ch of this._def.checks) {
|
|
@@ -1897,17 +2035,16 @@ class ZodBigInt extends ZodType {
|
|
|
1897
2035
|
}
|
|
1898
2036
|
_parse(input) {
|
|
1899
2037
|
if (this._def.coerce) {
|
|
1900
|
-
|
|
2038
|
+
try {
|
|
2039
|
+
input.data = BigInt(input.data);
|
|
2040
|
+
}
|
|
2041
|
+
catch (_a) {
|
|
2042
|
+
return this._getInvalidInput(input);
|
|
2043
|
+
}
|
|
1901
2044
|
}
|
|
1902
2045
|
const parsedType = this._getType(input);
|
|
1903
2046
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1904
|
-
|
|
1905
|
-
addIssueToContext(ctx, {
|
|
1906
|
-
code: ZodIssueCode.invalid_type,
|
|
1907
|
-
expected: ZodParsedType.bigint,
|
|
1908
|
-
received: ctx.parsedType,
|
|
1909
|
-
});
|
|
1910
|
-
return INVALID;
|
|
2047
|
+
return this._getInvalidInput(input);
|
|
1911
2048
|
}
|
|
1912
2049
|
let ctx = undefined;
|
|
1913
2050
|
const status = new ParseStatus();
|
|
@@ -1961,6 +2098,15 @@ class ZodBigInt extends ZodType {
|
|
|
1961
2098
|
}
|
|
1962
2099
|
return { status: status.value, value: input.data };
|
|
1963
2100
|
}
|
|
2101
|
+
_getInvalidInput(input) {
|
|
2102
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2103
|
+
addIssueToContext(ctx, {
|
|
2104
|
+
code: ZodIssueCode.invalid_type,
|
|
2105
|
+
expected: ZodParsedType.bigint,
|
|
2106
|
+
received: ctx.parsedType,
|
|
2107
|
+
});
|
|
2108
|
+
return INVALID;
|
|
2109
|
+
}
|
|
1964
2110
|
gte(value, message) {
|
|
1965
2111
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1966
2112
|
}
|
|
@@ -4167,7 +4313,23 @@ ZodReadonly.create = (type, params) => {
|
|
|
4167
4313
|
...processCreateParams(params),
|
|
4168
4314
|
});
|
|
4169
4315
|
};
|
|
4170
|
-
|
|
4316
|
+
////////////////////////////////////////
|
|
4317
|
+
////////////////////////////////////////
|
|
4318
|
+
////////// //////////
|
|
4319
|
+
////////// z.custom //////////
|
|
4320
|
+
////////// //////////
|
|
4321
|
+
////////////////////////////////////////
|
|
4322
|
+
////////////////////////////////////////
|
|
4323
|
+
function cleanParams(params, data) {
|
|
4324
|
+
const p = typeof params === "function"
|
|
4325
|
+
? params(data)
|
|
4326
|
+
: typeof params === "string"
|
|
4327
|
+
? { message: params }
|
|
4328
|
+
: params;
|
|
4329
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4330
|
+
return p2;
|
|
4331
|
+
}
|
|
4332
|
+
function custom(check, _params = {},
|
|
4171
4333
|
/**
|
|
4172
4334
|
* @deprecated
|
|
4173
4335
|
*
|
|
@@ -4182,16 +4344,23 @@ fatal) {
|
|
|
4182
4344
|
if (check)
|
|
4183
4345
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4184
4346
|
var _a, _b;
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4347
|
+
const r = check(data);
|
|
4348
|
+
if (r instanceof Promise) {
|
|
4349
|
+
return r.then((r) => {
|
|
4350
|
+
var _a, _b;
|
|
4351
|
+
if (!r) {
|
|
4352
|
+
const params = cleanParams(_params, data);
|
|
4353
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4354
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4355
|
+
}
|
|
4356
|
+
});
|
|
4357
|
+
}
|
|
4358
|
+
if (!r) {
|
|
4359
|
+
const params = cleanParams(_params, data);
|
|
4360
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4361
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4194
4362
|
}
|
|
4363
|
+
return;
|
|
4195
4364
|
});
|
|
4196
4365
|
return ZodAny.create();
|
|
4197
4366
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thirstie/thirstievalidators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A collection of data validators used by Thirstiejs modules",
|
|
5
5
|
"author": "Thirstie, Inc. <technology@thirstie.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"testEnvironment": "jsdom",
|
|
34
34
|
"transform": {}
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "caaf0cd837ce0029d5de4033ce3afddf9643da71"
|
|
37
37
|
}
|