@exodus/zod 3.24.1-rc.5 → 3.24.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/lib/index.mjs +27 -251
- package/lib/standard-schema.d.ts +0 -69
- package/lib/types.d.ts +1 -47
- package/package.json +10 -4
package/lib/index.mjs
CHANGED
|
@@ -51,7 +51,7 @@ var objectUtil;
|
|
|
51
51
|
return {
|
|
52
52
|
__proto__: null,
|
|
53
53
|
...first,
|
|
54
|
-
...second,
|
|
54
|
+
...second,
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
})(objectUtil || (objectUtil = {}));
|
|
@@ -153,7 +153,6 @@ class ZodError extends Error {
|
|
|
153
153
|
super();
|
|
154
154
|
const actualProto = new.target.prototype;
|
|
155
155
|
if (Object.setPrototypeOf) {
|
|
156
|
-
// eslint-disable-next-line ban/ban
|
|
157
156
|
Object.setPrototypeOf(this, actualProto);
|
|
158
157
|
}
|
|
159
158
|
else {
|
|
@@ -190,13 +189,6 @@ class ZodError extends Error {
|
|
|
190
189
|
const terminal = i === issue.path.length - 1;
|
|
191
190
|
if (!terminal) {
|
|
192
191
|
curr[el] = curr[el] || { _errors: [] };
|
|
193
|
-
// if (typeof el === "string") {
|
|
194
|
-
// curr[el] = curr[el] || { _errors: [] };
|
|
195
|
-
// } else if (typeof el === "number") {
|
|
196
|
-
// const errorArray: any = [];
|
|
197
|
-
// errorArray._errors = [];
|
|
198
|
-
// curr[el] = curr[el] || errorArray;
|
|
199
|
-
// }
|
|
200
192
|
}
|
|
201
193
|
else {
|
|
202
194
|
curr[el] = curr[el] || { _errors: [] };
|
|
@@ -423,10 +415,10 @@ function addIssueToContext(ctx, issueData) {
|
|
|
423
415
|
data: ctx.data,
|
|
424
416
|
path: ctx.path,
|
|
425
417
|
errorMaps: [
|
|
426
|
-
ctx.common.contextualErrorMap,
|
|
427
|
-
ctx.schemaErrorMap,
|
|
428
|
-
overrideMap,
|
|
429
|
-
overrideMap === errorMap ? undefined : errorMap,
|
|
418
|
+
ctx.common.contextualErrorMap,
|
|
419
|
+
ctx.schemaErrorMap,
|
|
420
|
+
overrideMap,
|
|
421
|
+
overrideMap === errorMap ? undefined : errorMap,
|
|
430
422
|
].filter((x) => !!x),
|
|
431
423
|
});
|
|
432
424
|
ctx.common.issues.push(issue);
|
|
@@ -544,6 +536,7 @@ const handleResult = (ctx, result) => {
|
|
|
544
536
|
};
|
|
545
537
|
}
|
|
546
538
|
};
|
|
539
|
+
const allowedChecks = new Set(["min", "max", "length", "email", "url", "uuid", "includes", "startsWith", "endsWith", "regex", "trim", "toLowerCase", "toUpperCase", "datetime", "date", "time", "ip", "base64"]);
|
|
547
540
|
function processCreateParams(params) {
|
|
548
541
|
if (!params)
|
|
549
542
|
return Object.create(null);
|
|
@@ -701,7 +694,6 @@ class ZodType {
|
|
|
701
694
|
: Promise.resolve(maybeAsyncResult));
|
|
702
695
|
return handleResult(ctx, result);
|
|
703
696
|
}
|
|
704
|
-
/** Alias of safeParseAsync */
|
|
705
697
|
spa = this.safeParseAsync;
|
|
706
698
|
refine(check, message) {
|
|
707
699
|
const getIssueProperties = (val) => {
|
|
@@ -873,52 +865,25 @@ class ZodType {
|
|
|
873
865
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
874
866
|
const cuid2Regex = /^[0-9a-z]+$/;
|
|
875
867
|
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
876
|
-
// const uuidRegex =
|
|
877
|
-
// /^([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;
|
|
878
868
|
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;
|
|
869
|
+
const urlRegex = /^(?:[a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,}(?:\:\d{1,5})?$/;
|
|
879
870
|
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
880
871
|
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
881
872
|
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)?)??$/;
|
|
882
|
-
// from https://stackoverflow.com/a/46181/1550155
|
|
883
|
-
// old version: too slow, didn't support unicode
|
|
884
|
-
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
885
|
-
//old email regex
|
|
886
|
-
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
|
887
|
-
// eslint-disable-next-line
|
|
888
|
-
// const emailRegex =
|
|
889
|
-
// /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((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}))\])|(\[IPv6:(([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})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
|
|
890
|
-
// const emailRegex =
|
|
891
|
-
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
892
|
-
// const emailRegex =
|
|
893
|
-
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
|
894
873
|
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
895
|
-
// const emailRegex =
|
|
896
|
-
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
897
|
-
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
898
874
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
899
875
|
let emojiRegex;
|
|
900
|
-
// faster, simpler, safer
|
|
901
876
|
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])$/;
|
|
902
877
|
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])$/;
|
|
903
|
-
// const ipv6Regex =
|
|
904
|
-
// /^(([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})))$/;
|
|
905
878
|
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]))$/;
|
|
906
879
|
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])$/;
|
|
907
|
-
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
908
880
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
909
|
-
// https://base64.guru/standards/base64url
|
|
910
881
|
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
911
|
-
// simple
|
|
912
|
-
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
913
|
-
// no leap year validation
|
|
914
|
-
// const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
|
|
915
|
-
// with leap year validation
|
|
916
882
|
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
917
883
|
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
918
884
|
function timeRegexSource(args) {
|
|
919
|
-
// let regex = `\\d{2}:\\d{2}:\\d{2}`;
|
|
920
885
|
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
921
|
-
if (args.precision) {
|
|
886
|
+
if (args.precision && typeof args.precision === "number") {
|
|
922
887
|
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
923
888
|
}
|
|
924
889
|
else if (args.precision == null) {
|
|
@@ -929,7 +894,6 @@ function timeRegexSource(args) {
|
|
|
929
894
|
function timeRegex(args) {
|
|
930
895
|
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
931
896
|
}
|
|
932
|
-
// Adapted from https://stackoverflow.com/a/3143231
|
|
933
897
|
function datetimeRegex(args) {
|
|
934
898
|
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
935
899
|
const opts = [];
|
|
@@ -953,7 +917,6 @@ function isValidJWT(jwt, alg) {
|
|
|
953
917
|
return false;
|
|
954
918
|
try {
|
|
955
919
|
const [header] = jwt.split(".");
|
|
956
|
-
// Convert base64url to base64
|
|
957
920
|
const base64 = header
|
|
958
921
|
.replace(/-/g, "+")
|
|
959
922
|
.replace(/_/g, "/")
|
|
@@ -1136,7 +1099,10 @@ class ZodString extends ZodType {
|
|
|
1136
1099
|
}
|
|
1137
1100
|
else if (check.kind === "url") {
|
|
1138
1101
|
try {
|
|
1139
|
-
new URL(input.data);
|
|
1102
|
+
const parsed = new URL(input.data);
|
|
1103
|
+
if (!urlRegex.test(parsed.host)) {
|
|
1104
|
+
throw new Error();
|
|
1105
|
+
}
|
|
1140
1106
|
}
|
|
1141
1107
|
catch {
|
|
1142
1108
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1150,8 +1116,7 @@ class ZodString extends ZodType {
|
|
|
1150
1116
|
}
|
|
1151
1117
|
else if (check.kind === "regex") {
|
|
1152
1118
|
check.regex.lastIndex = 0;
|
|
1153
|
-
|
|
1154
|
-
if (!testResult) {
|
|
1119
|
+
if (!(check.regex instanceof RegExp) || !check.regex.test(input.data)) {
|
|
1155
1120
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1156
1121
|
addIssueToContext(ctx, {
|
|
1157
1122
|
validation: "regex",
|
|
@@ -1205,7 +1170,9 @@ class ZodString extends ZodType {
|
|
|
1205
1170
|
}
|
|
1206
1171
|
else if (check.kind === "datetime") {
|
|
1207
1172
|
const regex = datetimeRegex(check);
|
|
1208
|
-
|
|
1173
|
+
const isoDatetime = new Date(input.data);
|
|
1174
|
+
const valid = isoDatetime.toISOString() === input.data;
|
|
1175
|
+
if (!valid || !regex.test(input.data)) {
|
|
1209
1176
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1210
1177
|
addIssueToContext(ctx, {
|
|
1211
1178
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1217,7 +1184,10 @@ class ZodString extends ZodType {
|
|
|
1217
1184
|
}
|
|
1218
1185
|
else if (check.kind === "date") {
|
|
1219
1186
|
const regex = dateRegex;
|
|
1220
|
-
|
|
1187
|
+
const date = new Date(input.data);
|
|
1188
|
+
const isoDateOnly = date.toISOString().split('T')[0];
|
|
1189
|
+
const valid = isoDateOnly === input.data;
|
|
1190
|
+
if (!valid || !regex.test(input.data)) {
|
|
1221
1191
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1222
1192
|
addIssueToContext(ctx, {
|
|
1223
1193
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1319,6 +1289,9 @@ class ZodString extends ZodType {
|
|
|
1319
1289
|
});
|
|
1320
1290
|
}
|
|
1321
1291
|
_addCheck(check) {
|
|
1292
|
+
if (!allowedChecks.has(check.kind)) {
|
|
1293
|
+
throw new Error(`Check type "${check.kind}" is disabled. Reach out to AppSec if you need it.`);
|
|
1294
|
+
}
|
|
1322
1295
|
return new ZodString({
|
|
1323
1296
|
...this._def,
|
|
1324
1297
|
checks: [...this._def.checks, check],
|
|
@@ -1352,7 +1325,6 @@ class ZodString extends ZodType {
|
|
|
1352
1325
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1353
1326
|
}
|
|
1354
1327
|
base64url(message) {
|
|
1355
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1356
1328
|
return this._addCheck({
|
|
1357
1329
|
kind: "base64url",
|
|
1358
1330
|
...errorUtil.errToObj(message),
|
|
@@ -1455,9 +1427,6 @@ class ZodString extends ZodType {
|
|
|
1455
1427
|
...errorUtil.errToObj(message),
|
|
1456
1428
|
});
|
|
1457
1429
|
}
|
|
1458
|
-
/**
|
|
1459
|
-
* Equivalent to `.min(1)`
|
|
1460
|
-
*/
|
|
1461
1430
|
nonempty(message) {
|
|
1462
1431
|
return this.min(1, errorUtil.errToObj(message));
|
|
1463
1432
|
}
|
|
@@ -1488,46 +1457,21 @@ class ZodString extends ZodType {
|
|
|
1488
1457
|
get isTime() {
|
|
1489
1458
|
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1490
1459
|
}
|
|
1491
|
-
get isDuration() {
|
|
1492
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1493
|
-
}
|
|
1494
1460
|
get isEmail() {
|
|
1495
1461
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1496
1462
|
}
|
|
1497
1463
|
get isURL() {
|
|
1498
1464
|
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1499
1465
|
}
|
|
1500
|
-
get isEmoji() {
|
|
1501
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1502
|
-
}
|
|
1503
1466
|
get isUUID() {
|
|
1504
1467
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1505
1468
|
}
|
|
1506
|
-
get isNANOID() {
|
|
1507
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1508
|
-
}
|
|
1509
|
-
get isCUID() {
|
|
1510
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1511
|
-
}
|
|
1512
|
-
get isCUID2() {
|
|
1513
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1514
|
-
}
|
|
1515
|
-
get isULID() {
|
|
1516
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1517
|
-
}
|
|
1518
1469
|
get isIP() {
|
|
1519
1470
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1520
1471
|
}
|
|
1521
|
-
get isCIDR() {
|
|
1522
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1523
|
-
}
|
|
1524
1472
|
get isBase64() {
|
|
1525
1473
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1526
1474
|
}
|
|
1527
|
-
get isBase64url() {
|
|
1528
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1529
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1530
|
-
}
|
|
1531
1475
|
get minLength() {
|
|
1532
1476
|
let min = null;
|
|
1533
1477
|
for (const ch of this._def.checks) {
|
|
@@ -1557,7 +1501,6 @@ class ZodString extends ZodType {
|
|
|
1557
1501
|
});
|
|
1558
1502
|
};
|
|
1559
1503
|
}
|
|
1560
|
-
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
|
1561
1504
|
function floatSafeRemainder(val, step) {
|
|
1562
1505
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1563
1506
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
@@ -2186,7 +2129,6 @@ class ZodNull extends ZodType {
|
|
|
2186
2129
|
};
|
|
2187
2130
|
}
|
|
2188
2131
|
class ZodAny extends ZodType {
|
|
2189
|
-
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
2190
2132
|
_any = true;
|
|
2191
2133
|
_parse(input) {
|
|
2192
2134
|
return OK(input.data);
|
|
@@ -2199,7 +2141,6 @@ class ZodAny extends ZodType {
|
|
|
2199
2141
|
};
|
|
2200
2142
|
}
|
|
2201
2143
|
class ZodUnknown extends ZodType {
|
|
2202
|
-
// required
|
|
2203
2144
|
_unknown = true;
|
|
2204
2145
|
_parse(input) {
|
|
2205
2146
|
return OK(input.data);
|
|
@@ -2447,14 +2388,12 @@ class ZodObject extends ZodType {
|
|
|
2447
2388
|
}
|
|
2448
2389
|
}
|
|
2449
2390
|
else {
|
|
2450
|
-
// run catchall validation
|
|
2451
2391
|
const catchall = this._def.catchall;
|
|
2452
2392
|
for (const key of extraKeys) {
|
|
2453
2393
|
const value = ctx.data[key];
|
|
2454
2394
|
pairs.push({
|
|
2455
2395
|
key: { status: "valid", value: key },
|
|
2456
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2457
|
-
),
|
|
2396
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2458
2397
|
alwaysSet: key in ctx.data,
|
|
2459
2398
|
});
|
|
2460
2399
|
}
|
|
@@ -2518,28 +2457,7 @@ class ZodObject extends ZodType {
|
|
|
2518
2457
|
unknownKeys: "passthrough",
|
|
2519
2458
|
});
|
|
2520
2459
|
}
|
|
2521
|
-
/**
|
|
2522
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
2523
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
2524
|
-
*/
|
|
2525
2460
|
nonstrict = this.passthrough;
|
|
2526
|
-
// const AugmentFactory =
|
|
2527
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2528
|
-
// <Augmentation extends ZodRawShape>(
|
|
2529
|
-
// augmentation: Augmentation
|
|
2530
|
-
// ): ZodObject<
|
|
2531
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2532
|
-
// Def["unknownKeys"],
|
|
2533
|
-
// Def["catchall"]
|
|
2534
|
-
// > => {
|
|
2535
|
-
// return new ZodObject({
|
|
2536
|
-
// ...def,
|
|
2537
|
-
// shape: () => ({
|
|
2538
|
-
// ...def.shape(),
|
|
2539
|
-
// ...augmentation,
|
|
2540
|
-
// }),
|
|
2541
|
-
// }) as any;
|
|
2542
|
-
// };
|
|
2543
2461
|
extend(augmentation) {
|
|
2544
2462
|
return new ZodObject({
|
|
2545
2463
|
...this._def,
|
|
@@ -2549,48 +2467,7 @@ class ZodObject extends ZodType {
|
|
|
2549
2467
|
}),
|
|
2550
2468
|
});
|
|
2551
2469
|
}
|
|
2552
|
-
// extend<
|
|
2553
|
-
// Augmentation extends ZodRawShape,
|
|
2554
|
-
// NewOutput extends util.flatten<{
|
|
2555
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2556
|
-
// ? Augmentation[k]["_output"]
|
|
2557
|
-
// : k extends keyof Output
|
|
2558
|
-
// ? Output[k]
|
|
2559
|
-
// : never;
|
|
2560
|
-
// }>,
|
|
2561
|
-
// NewInput extends util.flatten<{
|
|
2562
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2563
|
-
// ? Augmentation[k]["_input"]
|
|
2564
|
-
// : k extends keyof Input
|
|
2565
|
-
// ? Input[k]
|
|
2566
|
-
// : never;
|
|
2567
|
-
// }>
|
|
2568
|
-
// >(
|
|
2569
|
-
// augmentation: Augmentation
|
|
2570
|
-
// ): ZodObject<
|
|
2571
|
-
// extendShape<T, Augmentation>,
|
|
2572
|
-
// UnknownKeys,
|
|
2573
|
-
// Catchall,
|
|
2574
|
-
// NewOutput,
|
|
2575
|
-
// NewInput
|
|
2576
|
-
// > {
|
|
2577
|
-
// return new ZodObject({
|
|
2578
|
-
// ...this._def,
|
|
2579
|
-
// shape: () => ({
|
|
2580
|
-
// ...this._def.shape(),
|
|
2581
|
-
// ...augmentation,
|
|
2582
|
-
// }),
|
|
2583
|
-
// }) as any;
|
|
2584
|
-
// }
|
|
2585
|
-
/**
|
|
2586
|
-
* @deprecated Use `.extend` instead
|
|
2587
|
-
* */
|
|
2588
2470
|
augment = this.extend;
|
|
2589
|
-
/**
|
|
2590
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2591
|
-
* inferred type of merged objects. Please
|
|
2592
|
-
* upgrade if you are experiencing issues.
|
|
2593
|
-
*/
|
|
2594
2471
|
merge(merging) {
|
|
2595
2472
|
const merged = new ZodObject({
|
|
2596
2473
|
unknownKeys: merging._def.unknownKeys,
|
|
@@ -2603,65 +2480,9 @@ class ZodObject extends ZodType {
|
|
|
2603
2480
|
});
|
|
2604
2481
|
return merged;
|
|
2605
2482
|
}
|
|
2606
|
-
// merge<
|
|
2607
|
-
// Incoming extends AnyZodObject,
|
|
2608
|
-
// Augmentation extends Incoming["shape"],
|
|
2609
|
-
// NewOutput extends {
|
|
2610
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2611
|
-
// ? Augmentation[k]["_output"]
|
|
2612
|
-
// : k extends keyof Output
|
|
2613
|
-
// ? Output[k]
|
|
2614
|
-
// : never;
|
|
2615
|
-
// },
|
|
2616
|
-
// NewInput extends {
|
|
2617
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2618
|
-
// ? Augmentation[k]["_input"]
|
|
2619
|
-
// : k extends keyof Input
|
|
2620
|
-
// ? Input[k]
|
|
2621
|
-
// : never;
|
|
2622
|
-
// }
|
|
2623
|
-
// >(
|
|
2624
|
-
// merging: Incoming
|
|
2625
|
-
// ): ZodObject<
|
|
2626
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2627
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2628
|
-
// Incoming["_def"]["catchall"],
|
|
2629
|
-
// NewOutput,
|
|
2630
|
-
// NewInput
|
|
2631
|
-
// > {
|
|
2632
|
-
// const merged: any = new ZodObject({
|
|
2633
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2634
|
-
// catchall: merging._def.catchall,
|
|
2635
|
-
// shape: () =>
|
|
2636
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2637
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2638
|
-
// }) as any;
|
|
2639
|
-
// return merged;
|
|
2640
|
-
// }
|
|
2641
2483
|
setKey(key, schema) {
|
|
2642
2484
|
return this.augment(Object.assign(Object.create(null), { [key]: schema }));
|
|
2643
2485
|
}
|
|
2644
|
-
// merge<Incoming extends AnyZodObject>(
|
|
2645
|
-
// merging: Incoming
|
|
2646
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2647
|
-
// ZodObject<
|
|
2648
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2649
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2650
|
-
// Incoming["_def"]["catchall"]
|
|
2651
|
-
// > {
|
|
2652
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
2653
|
-
// // this._def.shape(),
|
|
2654
|
-
// // merging._def.shape()
|
|
2655
|
-
// // );
|
|
2656
|
-
// const merged: any = new ZodObject({
|
|
2657
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2658
|
-
// catchall: merging._def.catchall,
|
|
2659
|
-
// shape: () =>
|
|
2660
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2661
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2662
|
-
// }) as any;
|
|
2663
|
-
// return merged;
|
|
2664
|
-
// }
|
|
2665
2486
|
catchall(index) {
|
|
2666
2487
|
return new ZodObject({
|
|
2667
2488
|
...this._def,
|
|
@@ -2692,9 +2513,6 @@ class ZodObject extends ZodType {
|
|
|
2692
2513
|
shape: () => shape,
|
|
2693
2514
|
});
|
|
2694
2515
|
}
|
|
2695
|
-
/**
|
|
2696
|
-
* @deprecated
|
|
2697
|
-
*/
|
|
2698
2516
|
deepPartial() {
|
|
2699
2517
|
return deepPartialify(this);
|
|
2700
2518
|
}
|
|
@@ -2770,7 +2588,6 @@ class ZodUnion extends ZodType {
|
|
|
2770
2588
|
const { ctx } = this._processInputParams(input);
|
|
2771
2589
|
const options = this._def.options;
|
|
2772
2590
|
function handleResults(results) {
|
|
2773
|
-
// return first issue-free validation if it exists
|
|
2774
2591
|
for (const result of results) {
|
|
2775
2592
|
if (result.result.status === "valid") {
|
|
2776
2593
|
return result.result;
|
|
@@ -2778,12 +2595,10 @@ class ZodUnion extends ZodType {
|
|
|
2778
2595
|
}
|
|
2779
2596
|
for (const result of results) {
|
|
2780
2597
|
if (result.result.status === "dirty") {
|
|
2781
|
-
// add issues from dirty option
|
|
2782
2598
|
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2783
2599
|
return result.result;
|
|
2784
2600
|
}
|
|
2785
2601
|
}
|
|
2786
|
-
// return invalid
|
|
2787
2602
|
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2788
2603
|
addIssueToContext(ctx, {
|
|
2789
2604
|
code: ZodIssueCode.invalid_union,
|
|
@@ -2861,13 +2676,6 @@ class ZodUnion extends ZodType {
|
|
|
2861
2676
|
});
|
|
2862
2677
|
};
|
|
2863
2678
|
}
|
|
2864
|
-
/////////////////////////////////////////////////////
|
|
2865
|
-
/////////////////////////////////////////////////////
|
|
2866
|
-
////////// //////////
|
|
2867
|
-
////////// ZodDiscriminatedUnion //////////
|
|
2868
|
-
////////// //////////
|
|
2869
|
-
/////////////////////////////////////////////////////
|
|
2870
|
-
/////////////////////////////////////////////////////
|
|
2871
2679
|
const getDiscriminator = (type) => {
|
|
2872
2680
|
if (type instanceof ZodLazy) {
|
|
2873
2681
|
return getDiscriminator(type.schema);
|
|
@@ -2882,7 +2690,6 @@ const getDiscriminator = (type) => {
|
|
|
2882
2690
|
return type.options;
|
|
2883
2691
|
}
|
|
2884
2692
|
else if (type instanceof ZodNativeEnum) {
|
|
2885
|
-
// eslint-disable-next-line ban/ban
|
|
2886
2693
|
return util.objectValues(type.enum);
|
|
2887
2694
|
}
|
|
2888
2695
|
else if (type instanceof ZodDefault) {
|
|
@@ -2959,18 +2766,8 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
2959
2766
|
get optionsMap() {
|
|
2960
2767
|
return this._def.optionsMap;
|
|
2961
2768
|
}
|
|
2962
|
-
/**
|
|
2963
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2964
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2965
|
-
* have a different value for each object in the union.
|
|
2966
|
-
* @param discriminator the name of the discriminator property
|
|
2967
|
-
* @param types an array of object schemas
|
|
2968
|
-
* @param params
|
|
2969
|
-
*/
|
|
2970
2769
|
static create(discriminator, options, params) {
|
|
2971
|
-
// Get all the valid discriminator values
|
|
2972
2770
|
const optionsMap = new Map();
|
|
2973
|
-
// try {
|
|
2974
2771
|
for (const type of options) {
|
|
2975
2772
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2976
2773
|
if (!discriminatorValues.length) {
|
|
@@ -3131,7 +2928,7 @@ class ZodTuple extends ZodType {
|
|
|
3131
2928
|
return null;
|
|
3132
2929
|
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3133
2930
|
})
|
|
3134
|
-
.filter((x) => !!x);
|
|
2931
|
+
.filter((x) => !!x);
|
|
3135
2932
|
if (ctx.common.async) {
|
|
3136
2933
|
return Promise.all(items).then((results) => {
|
|
3137
2934
|
return ParseStatus.mergeArray(status, results);
|
|
@@ -3415,9 +3212,6 @@ class ZodFunction extends ZodType {
|
|
|
3415
3212
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3416
3213
|
const fn = ctx.data;
|
|
3417
3214
|
if (this._def.returns instanceof ZodPromise) {
|
|
3418
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3419
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3420
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3421
3215
|
const me = this;
|
|
3422
3216
|
return OK(async function (...args) {
|
|
3423
3217
|
const error = new ZodError([]);
|
|
@@ -3438,9 +3232,6 @@ class ZodFunction extends ZodType {
|
|
|
3438
3232
|
});
|
|
3439
3233
|
}
|
|
3440
3234
|
else {
|
|
3441
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3442
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3443
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3444
3235
|
const me = this;
|
|
3445
3236
|
return OK(function (...args) {
|
|
3446
3237
|
const parsedArgs = me._def.args.safeParse(args, params);
|
|
@@ -3766,7 +3557,6 @@ class ZodEffects extends ZodType {
|
|
|
3766
3557
|
return INVALID;
|
|
3767
3558
|
if (inner.status === "dirty")
|
|
3768
3559
|
status.dirty();
|
|
3769
|
-
// return value is ignored
|
|
3770
3560
|
executeRefinement(inner.value);
|
|
3771
3561
|
return { status: status.value, value: inner.value };
|
|
3772
3562
|
}
|
|
@@ -3896,7 +3686,6 @@ class ZodDefault extends ZodType {
|
|
|
3896
3686
|
class ZodCatch extends ZodType {
|
|
3897
3687
|
_parse(input) {
|
|
3898
3688
|
const { ctx } = this._processInputParams(input);
|
|
3899
|
-
// newCtx is used to not collect issues from inner types in ctx
|
|
3900
3689
|
const newCtx = {
|
|
3901
3690
|
...ctx,
|
|
3902
3691
|
common: {
|
|
@@ -4070,18 +3859,7 @@ class ZodReadonly extends ZodType {
|
|
|
4070
3859
|
return this._def.innerType;
|
|
4071
3860
|
}
|
|
4072
3861
|
}
|
|
4073
|
-
function custom(check, params = Object.create(null),
|
|
4074
|
-
/**
|
|
4075
|
-
* @deprecated
|
|
4076
|
-
*
|
|
4077
|
-
* Pass `fatal` into the params object instead:
|
|
4078
|
-
*
|
|
4079
|
-
* ```ts
|
|
4080
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
|
4081
|
-
* ```
|
|
4082
|
-
*
|
|
4083
|
-
*/
|
|
4084
|
-
fatal) {
|
|
3862
|
+
function custom(check, params = Object.create(null), fatal) {
|
|
4085
3863
|
if (check)
|
|
4086
3864
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4087
3865
|
if (!check(data)) {
|
|
@@ -4139,9 +3917,7 @@ var ZodFirstPartyTypeKind;
|
|
|
4139
3917
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
4140
3918
|
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
4141
3919
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4142
|
-
const instanceOfType = (
|
|
4143
|
-
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
|
4144
|
-
cls, params = {
|
|
3920
|
+
const instanceOfType = (cls, params = {
|
|
4145
3921
|
message: `Input not instance of ${cls.name}`,
|
|
4146
3922
|
}) => custom((data) => data instanceof cls, params);
|
|
4147
3923
|
const stringType = ZodString.create;
|
package/lib/standard-schema.d.ts
CHANGED
|
@@ -1,102 +1,33 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Standard Schema interface.
|
|
3
|
-
*/
|
|
4
1
|
export type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
5
|
-
/**
|
|
6
|
-
* The Standard Schema properties.
|
|
7
|
-
*/
|
|
8
2
|
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
9
3
|
};
|
|
10
4
|
export declare namespace StandardSchemaV1 {
|
|
11
|
-
/**
|
|
12
|
-
* The Standard Schema properties interface.
|
|
13
|
-
*/
|
|
14
5
|
export interface Props<Input = unknown, Output = Input> {
|
|
15
|
-
/**
|
|
16
|
-
* The version number of the standard.
|
|
17
|
-
*/
|
|
18
6
|
readonly version: 1;
|
|
19
|
-
/**
|
|
20
|
-
* The vendor name of the schema library.
|
|
21
|
-
*/
|
|
22
7
|
readonly vendor: string;
|
|
23
|
-
/**
|
|
24
|
-
* Validates unknown input values.
|
|
25
|
-
*/
|
|
26
8
|
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
27
|
-
/**
|
|
28
|
-
* Inferred types associated with the schema.
|
|
29
|
-
*/
|
|
30
9
|
readonly types?: Types<Input, Output> | undefined;
|
|
31
10
|
}
|
|
32
|
-
/**
|
|
33
|
-
* The result interface of the validate function.
|
|
34
|
-
*/
|
|
35
11
|
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
36
|
-
/**
|
|
37
|
-
* The result interface if validation succeeds.
|
|
38
|
-
*/
|
|
39
12
|
export interface SuccessResult<Output> {
|
|
40
|
-
/**
|
|
41
|
-
* The typed output value.
|
|
42
|
-
*/
|
|
43
13
|
readonly value: Output;
|
|
44
|
-
/**
|
|
45
|
-
* The non-existent issues.
|
|
46
|
-
*/
|
|
47
14
|
readonly issues?: undefined;
|
|
48
15
|
}
|
|
49
|
-
/**
|
|
50
|
-
* The result interface if validation fails.
|
|
51
|
-
*/
|
|
52
16
|
export interface FailureResult {
|
|
53
|
-
/**
|
|
54
|
-
* The issues of failed validation.
|
|
55
|
-
*/
|
|
56
17
|
readonly issues: ReadonlyArray<Issue>;
|
|
57
18
|
}
|
|
58
|
-
/**
|
|
59
|
-
* The issue interface of the failure output.
|
|
60
|
-
*/
|
|
61
19
|
export interface Issue {
|
|
62
|
-
/**
|
|
63
|
-
* The error message of the issue.
|
|
64
|
-
*/
|
|
65
20
|
readonly message: string;
|
|
66
|
-
/**
|
|
67
|
-
* The path of the issue, if any.
|
|
68
|
-
*/
|
|
69
21
|
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
70
22
|
}
|
|
71
|
-
/**
|
|
72
|
-
* The path segment interface of the issue.
|
|
73
|
-
*/
|
|
74
23
|
export interface PathSegment {
|
|
75
|
-
/**
|
|
76
|
-
* The key representing a path segment.
|
|
77
|
-
*/
|
|
78
24
|
readonly key: PropertyKey;
|
|
79
25
|
}
|
|
80
|
-
/**
|
|
81
|
-
* The Standard Schema types interface.
|
|
82
|
-
*/
|
|
83
26
|
export interface Types<Input = unknown, Output = Input> {
|
|
84
|
-
/**
|
|
85
|
-
* The input type of the schema.
|
|
86
|
-
*/
|
|
87
27
|
readonly input: Input;
|
|
88
|
-
/**
|
|
89
|
-
* The output type of the schema.
|
|
90
|
-
*/
|
|
91
28
|
readonly output: Output;
|
|
92
29
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Infers the input type of a Standard Schema.
|
|
95
|
-
*/
|
|
96
30
|
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
97
|
-
/**
|
|
98
|
-
* Infers the output type of a Standard Schema.
|
|
99
|
-
*/
|
|
100
31
|
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
101
32
|
export {};
|
|
102
33
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
|
|
|
66
66
|
"~validate"(data: unknown): StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>>;
|
|
67
67
|
parseAsync(data: unknown, params?: Partial<ParseParams>): Promise<Output>;
|
|
68
68
|
safeParseAsync(data: unknown, params?: Partial<ParseParams>): Promise<SafeParseReturnType<Input, Output>>;
|
|
69
|
-
/** Alias of safeParseAsync */
|
|
70
69
|
spa: (data: unknown, params?: Partial<ParseParams>) => Promise<SafeParseReturnType<Input, Output>>;
|
|
71
70
|
refine<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, RefinedOutput, Input>;
|
|
72
71
|
refine(check: (arg: Output) => unknown | Promise<unknown>, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, Output, Input>;
|
|
@@ -255,9 +254,6 @@ export declare class ZodString extends ZodType<string, ZodStringDef, string> {
|
|
|
255
254
|
min(minLength: number, message?: errorUtil.ErrMessage): ZodString;
|
|
256
255
|
max(maxLength: number, message?: errorUtil.ErrMessage): ZodString;
|
|
257
256
|
length(len: number, message?: errorUtil.ErrMessage): ZodString;
|
|
258
|
-
/**
|
|
259
|
-
* Equivalent to `.min(1)`
|
|
260
|
-
*/
|
|
261
257
|
nonempty(message?: errorUtil.ErrMessage): ZodString;
|
|
262
258
|
trim(): ZodString;
|
|
263
259
|
toLowerCase(): ZodString;
|
|
@@ -265,19 +261,11 @@ export declare class ZodString extends ZodType<string, ZodStringDef, string> {
|
|
|
265
261
|
get isDatetime(): boolean;
|
|
266
262
|
get isDate(): boolean;
|
|
267
263
|
get isTime(): boolean;
|
|
268
|
-
get isDuration(): boolean;
|
|
269
264
|
get isEmail(): boolean;
|
|
270
265
|
get isURL(): boolean;
|
|
271
|
-
get isEmoji(): boolean;
|
|
272
266
|
get isUUID(): boolean;
|
|
273
|
-
get isNANOID(): boolean;
|
|
274
|
-
get isCUID(): boolean;
|
|
275
|
-
get isCUID2(): boolean;
|
|
276
|
-
get isULID(): boolean;
|
|
277
267
|
get isIP(): boolean;
|
|
278
|
-
get isCIDR(): boolean;
|
|
279
268
|
get isBase64(): boolean;
|
|
280
|
-
get isBase64url(): boolean;
|
|
281
269
|
get minLength(): number | null;
|
|
282
270
|
get maxLength(): number | null;
|
|
283
271
|
static create: (params?: RawCreateParams & {
|
|
@@ -537,21 +525,9 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
|
|
|
537
525
|
strict(message?: errorUtil.ErrMessage): ZodObject<T, "strict", Catchall>;
|
|
538
526
|
strip(): ZodObject<T, "strip", Catchall>;
|
|
539
527
|
passthrough(): ZodObject<T, "passthrough", Catchall>;
|
|
540
|
-
/**
|
|
541
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
542
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
543
|
-
*/
|
|
544
528
|
nonstrict: () => ZodObject<T, "passthrough", Catchall>;
|
|
545
529
|
extend<Augmentation extends ZodRawShape>(augmentation: Augmentation): ZodObject<objectUtil.extendShape<T, Augmentation>, UnknownKeys, Catchall>;
|
|
546
|
-
/**
|
|
547
|
-
* @deprecated Use `.extend` instead
|
|
548
|
-
* */
|
|
549
530
|
augment: <Augmentation extends ZodRawShape>(augmentation: Augmentation) => ZodObject<objectUtil.extendShape<T, Augmentation>, UnknownKeys, Catchall>;
|
|
550
|
-
/**
|
|
551
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
552
|
-
* inferred type of merged objects. Please
|
|
553
|
-
* upgrade if you are experiencing issues.
|
|
554
|
-
*/
|
|
555
531
|
merge<Incoming extends AnyZodObject, Augmentation extends Incoming["shape"]>(merging: Incoming): ZodObject<objectUtil.extendShape<T, Augmentation>, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"]>;
|
|
556
532
|
setKey<Key extends string, Schema extends ZodTypeAny>(key: Key, schema: Schema): ZodObject<T & {
|
|
557
533
|
[k in Key]: Schema;
|
|
@@ -563,9 +539,6 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
|
|
|
563
539
|
omit<Mask extends util.Exactly<{
|
|
564
540
|
[k in keyof T]?: true;
|
|
565
541
|
}, Mask>>(mask: Mask): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>;
|
|
566
|
-
/**
|
|
567
|
-
* @deprecated
|
|
568
|
-
*/
|
|
569
542
|
deepPartial(): partialUtil.DeepPartial<this>;
|
|
570
543
|
partial(): ZodObject<{
|
|
571
544
|
[k in keyof T]: ZodOptional<T[k]>;
|
|
@@ -617,14 +590,6 @@ export declare class ZodDiscriminatedUnion<Discriminator extends string, Options
|
|
|
617
590
|
get discriminator(): Discriminator;
|
|
618
591
|
get options(): Options;
|
|
619
592
|
get optionsMap(): Map<Primitive, ZodDiscriminatedUnionOption<any>>;
|
|
620
|
-
/**
|
|
621
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
622
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
623
|
-
* have a different value for each object in the union.
|
|
624
|
-
* @param discriminator the name of the discriminator property
|
|
625
|
-
* @param types an array of object schemas
|
|
626
|
-
* @param params
|
|
627
|
-
*/
|
|
628
593
|
static create<Discriminator extends string, Types extends readonly [
|
|
629
594
|
ZodDiscriminatedUnionOption<Discriminator>,
|
|
630
595
|
...ZodDiscriminatedUnionOption<Discriminator>[]
|
|
@@ -935,18 +900,7 @@ export declare class ZodReadonly<T extends ZodTypeAny> extends ZodType<MakeReado
|
|
|
935
900
|
type CustomParams = CustomErrorParams & {
|
|
936
901
|
fatal?: boolean;
|
|
937
902
|
};
|
|
938
|
-
export declare function custom<T>(check?: (data: any) => any, params?: string | CustomParams | ((input: any) => CustomParams),
|
|
939
|
-
/**
|
|
940
|
-
* @deprecated
|
|
941
|
-
*
|
|
942
|
-
* Pass `fatal` into the params object instead:
|
|
943
|
-
*
|
|
944
|
-
* ```ts
|
|
945
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
|
946
|
-
* ```
|
|
947
|
-
*
|
|
948
|
-
*/
|
|
949
|
-
fatal?: boolean): ZodType<T, ZodTypeDef, T>;
|
|
903
|
+
export declare function custom<T>(check?: (data: any) => any, params?: string | CustomParams | ((input: any) => CustomParams), fatal?: boolean): ZodType<T, ZodTypeDef, T>;
|
|
950
904
|
export { ZodType as Schema, ZodType as ZodSchema };
|
|
951
905
|
export declare const late: {
|
|
952
906
|
object: <T extends ZodRawShape>(shape: () => T, params?: RawCreateParams) => ZodObject<T, "strip">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/zod",
|
|
3
|
-
"version": "3.24.1
|
|
3
|
+
"version": "3.24.1",
|
|
4
4
|
"author": "Exodus Movement, Inc.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,7 +43,11 @@
|
|
|
43
43
|
"tslib": "^2.3.1",
|
|
44
44
|
"tsx": "^3.8.0",
|
|
45
45
|
"typescript": "^5.0.0",
|
|
46
|
-
"vitest": "^0.32.2"
|
|
46
|
+
"vitest": "^0.32.2",
|
|
47
|
+
"semantic-release": "^21.1.1",
|
|
48
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
49
|
+
"@semantic-release/github": "^9.2.3",
|
|
50
|
+
"conventional-changelog-conventionalcommits": "^6.0.0"
|
|
47
51
|
},
|
|
48
52
|
"exports": {
|
|
49
53
|
".": {
|
|
@@ -97,7 +101,8 @@
|
|
|
97
101
|
"test:vitest": "npx vitest --config ./configs/vitest.config.ts",
|
|
98
102
|
"test:ts-jest": "npx jest --config ./configs/ts-jest.config.json",
|
|
99
103
|
"test:swc": "npx jest --config ./configs/swc-jest.config.json",
|
|
100
|
-
"prepublishOnly": "npm run test && npm run build"
|
|
104
|
+
"prepublishOnly": "npm run test && npm run build",
|
|
105
|
+
"release": "semantic-release"
|
|
101
106
|
},
|
|
102
107
|
"sideEffects": false,
|
|
103
108
|
"support": {
|
|
@@ -105,5 +110,6 @@
|
|
|
105
110
|
"npm-funding": true
|
|
106
111
|
}
|
|
107
112
|
},
|
|
108
|
-
"types": "./index.d.ts"
|
|
113
|
+
"types": "./index.d.ts",
|
|
114
|
+
"packageManager": "yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71"
|
|
109
115
|
}
|