@exodus/zod 3.24.1-rc.4 → 3.24.1-rc.6
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/LICENSE +1 -1
- package/lib/index.mjs +34 -257
- package/lib/standard-schema.d.ts +0 -69
- package/lib/types.d.ts +1 -47
- package/package.json +5 -14
package/LICENSE
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -49,8 +49,9 @@ var objectUtil;
|
|
|
49
49
|
(function (objectUtil) {
|
|
50
50
|
objectUtil.mergeShapes = (first, second) => {
|
|
51
51
|
return {
|
|
52
|
+
__proto__: null,
|
|
52
53
|
...first,
|
|
53
|
-
...second,
|
|
54
|
+
...second,
|
|
54
55
|
};
|
|
55
56
|
};
|
|
56
57
|
})(objectUtil || (objectUtil = {}));
|
|
@@ -152,7 +153,6 @@ class ZodError extends Error {
|
|
|
152
153
|
super();
|
|
153
154
|
const actualProto = new.target.prototype;
|
|
154
155
|
if (Object.setPrototypeOf) {
|
|
155
|
-
// eslint-disable-next-line ban/ban
|
|
156
156
|
Object.setPrototypeOf(this, actualProto);
|
|
157
157
|
}
|
|
158
158
|
else {
|
|
@@ -189,13 +189,6 @@ class ZodError extends Error {
|
|
|
189
189
|
const terminal = i === issue.path.length - 1;
|
|
190
190
|
if (!terminal) {
|
|
191
191
|
curr[el] = curr[el] || { _errors: [] };
|
|
192
|
-
// if (typeof el === "string") {
|
|
193
|
-
// curr[el] = curr[el] || { _errors: [] };
|
|
194
|
-
// } else if (typeof el === "number") {
|
|
195
|
-
// const errorArray: any = [];
|
|
196
|
-
// errorArray._errors = [];
|
|
197
|
-
// curr[el] = curr[el] || errorArray;
|
|
198
|
-
// }
|
|
199
192
|
}
|
|
200
193
|
else {
|
|
201
194
|
curr[el] = curr[el] || { _errors: [] };
|
|
@@ -422,10 +415,10 @@ function addIssueToContext(ctx, issueData) {
|
|
|
422
415
|
data: ctx.data,
|
|
423
416
|
path: ctx.path,
|
|
424
417
|
errorMaps: [
|
|
425
|
-
ctx.common.contextualErrorMap,
|
|
426
|
-
ctx.schemaErrorMap,
|
|
427
|
-
overrideMap,
|
|
428
|
-
overrideMap === errorMap ? undefined : errorMap,
|
|
418
|
+
ctx.common.contextualErrorMap,
|
|
419
|
+
ctx.schemaErrorMap,
|
|
420
|
+
overrideMap,
|
|
421
|
+
overrideMap === errorMap ? undefined : errorMap,
|
|
429
422
|
].filter((x) => !!x),
|
|
430
423
|
});
|
|
431
424
|
ctx.common.issues.push(issue);
|
|
@@ -475,7 +468,7 @@ class ParseStatus {
|
|
|
475
468
|
status.dirty();
|
|
476
469
|
if (value.status === "dirty")
|
|
477
470
|
status.dirty();
|
|
478
|
-
if (key.value
|
|
471
|
+
if (!(key.value in Object.prototype) &&
|
|
479
472
|
(typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
480
473
|
finalObject[key.value] = value.value;
|
|
481
474
|
}
|
|
@@ -543,9 +536,10 @@ const handleResult = (ctx, result) => {
|
|
|
543
536
|
};
|
|
544
537
|
}
|
|
545
538
|
};
|
|
539
|
+
const allowedChecks = new Set(["min", "max", "length", "email", "url", "uuid", "includes", "startsWith", "endsWith", "regex", "trim", "toLowerCase", "toUpperCase", "datetime", "date", "time", "ip", "base64"]);
|
|
546
540
|
function processCreateParams(params) {
|
|
547
541
|
if (!params)
|
|
548
|
-
return
|
|
542
|
+
return Object.create(null);
|
|
549
543
|
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
550
544
|
if (errorMap && (invalid_type_error || required_error)) {
|
|
551
545
|
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
@@ -700,7 +694,6 @@ class ZodType {
|
|
|
700
694
|
: Promise.resolve(maybeAsyncResult));
|
|
701
695
|
return handleResult(ctx, result);
|
|
702
696
|
}
|
|
703
|
-
/** Alias of safeParseAsync */
|
|
704
697
|
spa = this.safeParseAsync;
|
|
705
698
|
refine(check, message) {
|
|
706
699
|
const getIssueProperties = (val) => {
|
|
@@ -872,52 +865,25 @@ class ZodType {
|
|
|
872
865
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
873
866
|
const cuid2Regex = /^[0-9a-z]+$/;
|
|
874
867
|
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
875
|
-
// const uuidRegex =
|
|
876
|
-
// /^([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;
|
|
877
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})?$/;
|
|
878
870
|
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
879
871
|
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
880
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)?)??$/;
|
|
881
|
-
// from https://stackoverflow.com/a/46181/1550155
|
|
882
|
-
// old version: too slow, didn't support unicode
|
|
883
|
-
// 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;
|
|
884
|
-
//old email regex
|
|
885
|
-
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
|
886
|
-
// eslint-disable-next-line
|
|
887
|
-
// const emailRegex =
|
|
888
|
-
// /^(([^<>()[\]\\.,;:\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,})+))$/;
|
|
889
|
-
// const emailRegex =
|
|
890
|
-
// /^[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])?)*$/;
|
|
891
|
-
// const emailRegex =
|
|
892
|
-
// /^(?:[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;
|
|
893
873
|
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
894
|
-
// const emailRegex =
|
|
895
|
-
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
896
|
-
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
897
874
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
898
875
|
let emojiRegex;
|
|
899
|
-
// faster, simpler, safer
|
|
900
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])$/;
|
|
901
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])$/;
|
|
902
|
-
// const ipv6Regex =
|
|
903
|
-
// /^(([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})))$/;
|
|
904
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]))$/;
|
|
905
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])$/;
|
|
906
|
-
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
907
880
|
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
908
|
-
// https://base64.guru/standards/base64url
|
|
909
881
|
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
910
|
-
// simple
|
|
911
|
-
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
|
912
|
-
// no leap year validation
|
|
913
|
-
// 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))`;
|
|
914
|
-
// with leap year validation
|
|
915
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])))`;
|
|
916
883
|
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
917
884
|
function timeRegexSource(args) {
|
|
918
|
-
// let regex = `\\d{2}:\\d{2}:\\d{2}`;
|
|
919
885
|
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
920
|
-
if (args.precision) {
|
|
886
|
+
if (args.precision && typeof args.precision === "number") {
|
|
921
887
|
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
922
888
|
}
|
|
923
889
|
else if (args.precision == null) {
|
|
@@ -928,7 +894,6 @@ function timeRegexSource(args) {
|
|
|
928
894
|
function timeRegex(args) {
|
|
929
895
|
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
930
896
|
}
|
|
931
|
-
// Adapted from https://stackoverflow.com/a/3143231
|
|
932
897
|
function datetimeRegex(args) {
|
|
933
898
|
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
934
899
|
const opts = [];
|
|
@@ -952,7 +917,6 @@ function isValidJWT(jwt, alg) {
|
|
|
952
917
|
return false;
|
|
953
918
|
try {
|
|
954
919
|
const [header] = jwt.split(".");
|
|
955
|
-
// Convert base64url to base64
|
|
956
920
|
const base64 = header
|
|
957
921
|
.replace(/-/g, "+")
|
|
958
922
|
.replace(/_/g, "/")
|
|
@@ -1135,7 +1099,10 @@ class ZodString extends ZodType {
|
|
|
1135
1099
|
}
|
|
1136
1100
|
else if (check.kind === "url") {
|
|
1137
1101
|
try {
|
|
1138
|
-
new URL(input.data);
|
|
1102
|
+
const parsed = new URL(input.data);
|
|
1103
|
+
if (!urlRegex.test(parsed.host)) {
|
|
1104
|
+
throw new Error();
|
|
1105
|
+
}
|
|
1139
1106
|
}
|
|
1140
1107
|
catch {
|
|
1141
1108
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1149,8 +1116,7 @@ class ZodString extends ZodType {
|
|
|
1149
1116
|
}
|
|
1150
1117
|
else if (check.kind === "regex") {
|
|
1151
1118
|
check.regex.lastIndex = 0;
|
|
1152
|
-
|
|
1153
|
-
if (!testResult) {
|
|
1119
|
+
if (!(check.regex instanceof RegExp) || !check.regex.test(input.data)) {
|
|
1154
1120
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1155
1121
|
addIssueToContext(ctx, {
|
|
1156
1122
|
validation: "regex",
|
|
@@ -1204,7 +1170,9 @@ class ZodString extends ZodType {
|
|
|
1204
1170
|
}
|
|
1205
1171
|
else if (check.kind === "datetime") {
|
|
1206
1172
|
const regex = datetimeRegex(check);
|
|
1207
|
-
|
|
1173
|
+
const isoDatetime = new Date(input.data);
|
|
1174
|
+
const valid = isoDatetime.toISOString() === input.data;
|
|
1175
|
+
if (!valid || !regex.test(input.data)) {
|
|
1208
1176
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1209
1177
|
addIssueToContext(ctx, {
|
|
1210
1178
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1216,7 +1184,10 @@ class ZodString extends ZodType {
|
|
|
1216
1184
|
}
|
|
1217
1185
|
else if (check.kind === "date") {
|
|
1218
1186
|
const regex = dateRegex;
|
|
1219
|
-
|
|
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)) {
|
|
1220
1191
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1221
1192
|
addIssueToContext(ctx, {
|
|
1222
1193
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1318,6 +1289,9 @@ class ZodString extends ZodType {
|
|
|
1318
1289
|
});
|
|
1319
1290
|
}
|
|
1320
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
|
+
}
|
|
1321
1295
|
return new ZodString({
|
|
1322
1296
|
...this._def,
|
|
1323
1297
|
checks: [...this._def.checks, check],
|
|
@@ -1351,7 +1325,6 @@ class ZodString extends ZodType {
|
|
|
1351
1325
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1352
1326
|
}
|
|
1353
1327
|
base64url(message) {
|
|
1354
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1355
1328
|
return this._addCheck({
|
|
1356
1329
|
kind: "base64url",
|
|
1357
1330
|
...errorUtil.errToObj(message),
|
|
@@ -1454,9 +1427,6 @@ class ZodString extends ZodType {
|
|
|
1454
1427
|
...errorUtil.errToObj(message),
|
|
1455
1428
|
});
|
|
1456
1429
|
}
|
|
1457
|
-
/**
|
|
1458
|
-
* Equivalent to `.min(1)`
|
|
1459
|
-
*/
|
|
1460
1430
|
nonempty(message) {
|
|
1461
1431
|
return this.min(1, errorUtil.errToObj(message));
|
|
1462
1432
|
}
|
|
@@ -1487,46 +1457,21 @@ class ZodString extends ZodType {
|
|
|
1487
1457
|
get isTime() {
|
|
1488
1458
|
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1489
1459
|
}
|
|
1490
|
-
get isDuration() {
|
|
1491
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1492
|
-
}
|
|
1493
1460
|
get isEmail() {
|
|
1494
1461
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1495
1462
|
}
|
|
1496
1463
|
get isURL() {
|
|
1497
1464
|
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1498
1465
|
}
|
|
1499
|
-
get isEmoji() {
|
|
1500
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1501
|
-
}
|
|
1502
1466
|
get isUUID() {
|
|
1503
1467
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1504
1468
|
}
|
|
1505
|
-
get isNANOID() {
|
|
1506
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1507
|
-
}
|
|
1508
|
-
get isCUID() {
|
|
1509
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1510
|
-
}
|
|
1511
|
-
get isCUID2() {
|
|
1512
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1513
|
-
}
|
|
1514
|
-
get isULID() {
|
|
1515
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1516
|
-
}
|
|
1517
1469
|
get isIP() {
|
|
1518
1470
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1519
1471
|
}
|
|
1520
|
-
get isCIDR() {
|
|
1521
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1522
|
-
}
|
|
1523
1472
|
get isBase64() {
|
|
1524
1473
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1525
1474
|
}
|
|
1526
|
-
get isBase64url() {
|
|
1527
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
1528
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1529
|
-
}
|
|
1530
1475
|
get minLength() {
|
|
1531
1476
|
let min = null;
|
|
1532
1477
|
for (const ch of this._def.checks) {
|
|
@@ -1556,7 +1501,6 @@ class ZodString extends ZodType {
|
|
|
1556
1501
|
});
|
|
1557
1502
|
};
|
|
1558
1503
|
}
|
|
1559
|
-
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
|
1560
1504
|
function floatSafeRemainder(val, step) {
|
|
1561
1505
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1562
1506
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
@@ -2185,7 +2129,6 @@ class ZodNull extends ZodType {
|
|
|
2185
2129
|
};
|
|
2186
2130
|
}
|
|
2187
2131
|
class ZodAny extends ZodType {
|
|
2188
|
-
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
2189
2132
|
_any = true;
|
|
2190
2133
|
_parse(input) {
|
|
2191
2134
|
return OK(input.data);
|
|
@@ -2198,7 +2141,6 @@ class ZodAny extends ZodType {
|
|
|
2198
2141
|
};
|
|
2199
2142
|
}
|
|
2200
2143
|
class ZodUnknown extends ZodType {
|
|
2201
|
-
// required
|
|
2202
2144
|
_unknown = true;
|
|
2203
2145
|
_parse(input) {
|
|
2204
2146
|
return OK(input.data);
|
|
@@ -2446,14 +2388,12 @@ class ZodObject extends ZodType {
|
|
|
2446
2388
|
}
|
|
2447
2389
|
}
|
|
2448
2390
|
else {
|
|
2449
|
-
// run catchall validation
|
|
2450
2391
|
const catchall = this._def.catchall;
|
|
2451
2392
|
for (const key of extraKeys) {
|
|
2452
2393
|
const value = ctx.data[key];
|
|
2453
2394
|
pairs.push({
|
|
2454
2395
|
key: { status: "valid", value: key },
|
|
2455
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2456
|
-
),
|
|
2396
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2457
2397
|
alwaysSet: key in ctx.data,
|
|
2458
2398
|
});
|
|
2459
2399
|
}
|
|
@@ -2502,7 +2442,7 @@ class ZodObject extends ZodType {
|
|
|
2502
2442
|
};
|
|
2503
2443
|
},
|
|
2504
2444
|
}
|
|
2505
|
-
:
|
|
2445
|
+
: Object.create(null)),
|
|
2506
2446
|
});
|
|
2507
2447
|
}
|
|
2508
2448
|
strip() {
|
|
@@ -2517,28 +2457,7 @@ class ZodObject extends ZodType {
|
|
|
2517
2457
|
unknownKeys: "passthrough",
|
|
2518
2458
|
});
|
|
2519
2459
|
}
|
|
2520
|
-
/**
|
|
2521
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
2522
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
2523
|
-
*/
|
|
2524
2460
|
nonstrict = this.passthrough;
|
|
2525
|
-
// const AugmentFactory =
|
|
2526
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2527
|
-
// <Augmentation extends ZodRawShape>(
|
|
2528
|
-
// augmentation: Augmentation
|
|
2529
|
-
// ): ZodObject<
|
|
2530
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2531
|
-
// Def["unknownKeys"],
|
|
2532
|
-
// Def["catchall"]
|
|
2533
|
-
// > => {
|
|
2534
|
-
// return new ZodObject({
|
|
2535
|
-
// ...def,
|
|
2536
|
-
// shape: () => ({
|
|
2537
|
-
// ...def.shape(),
|
|
2538
|
-
// ...augmentation,
|
|
2539
|
-
// }),
|
|
2540
|
-
// }) as any;
|
|
2541
|
-
// };
|
|
2542
2461
|
extend(augmentation) {
|
|
2543
2462
|
return new ZodObject({
|
|
2544
2463
|
...this._def,
|
|
@@ -2548,48 +2467,7 @@ class ZodObject extends ZodType {
|
|
|
2548
2467
|
}),
|
|
2549
2468
|
});
|
|
2550
2469
|
}
|
|
2551
|
-
// extend<
|
|
2552
|
-
// Augmentation extends ZodRawShape,
|
|
2553
|
-
// NewOutput extends util.flatten<{
|
|
2554
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2555
|
-
// ? Augmentation[k]["_output"]
|
|
2556
|
-
// : k extends keyof Output
|
|
2557
|
-
// ? Output[k]
|
|
2558
|
-
// : never;
|
|
2559
|
-
// }>,
|
|
2560
|
-
// NewInput extends util.flatten<{
|
|
2561
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2562
|
-
// ? Augmentation[k]["_input"]
|
|
2563
|
-
// : k extends keyof Input
|
|
2564
|
-
// ? Input[k]
|
|
2565
|
-
// : never;
|
|
2566
|
-
// }>
|
|
2567
|
-
// >(
|
|
2568
|
-
// augmentation: Augmentation
|
|
2569
|
-
// ): ZodObject<
|
|
2570
|
-
// extendShape<T, Augmentation>,
|
|
2571
|
-
// UnknownKeys,
|
|
2572
|
-
// Catchall,
|
|
2573
|
-
// NewOutput,
|
|
2574
|
-
// NewInput
|
|
2575
|
-
// > {
|
|
2576
|
-
// return new ZodObject({
|
|
2577
|
-
// ...this._def,
|
|
2578
|
-
// shape: () => ({
|
|
2579
|
-
// ...this._def.shape(),
|
|
2580
|
-
// ...augmentation,
|
|
2581
|
-
// }),
|
|
2582
|
-
// }) as any;
|
|
2583
|
-
// }
|
|
2584
|
-
/**
|
|
2585
|
-
* @deprecated Use `.extend` instead
|
|
2586
|
-
* */
|
|
2587
2470
|
augment = this.extend;
|
|
2588
|
-
/**
|
|
2589
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2590
|
-
* inferred type of merged objects. Please
|
|
2591
|
-
* upgrade if you are experiencing issues.
|
|
2592
|
-
*/
|
|
2593
2471
|
merge(merging) {
|
|
2594
2472
|
const merged = new ZodObject({
|
|
2595
2473
|
unknownKeys: merging._def.unknownKeys,
|
|
@@ -2602,65 +2480,9 @@ class ZodObject extends ZodType {
|
|
|
2602
2480
|
});
|
|
2603
2481
|
return merged;
|
|
2604
2482
|
}
|
|
2605
|
-
// merge<
|
|
2606
|
-
// Incoming extends AnyZodObject,
|
|
2607
|
-
// Augmentation extends Incoming["shape"],
|
|
2608
|
-
// NewOutput extends {
|
|
2609
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2610
|
-
// ? Augmentation[k]["_output"]
|
|
2611
|
-
// : k extends keyof Output
|
|
2612
|
-
// ? Output[k]
|
|
2613
|
-
// : never;
|
|
2614
|
-
// },
|
|
2615
|
-
// NewInput extends {
|
|
2616
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2617
|
-
// ? Augmentation[k]["_input"]
|
|
2618
|
-
// : k extends keyof Input
|
|
2619
|
-
// ? Input[k]
|
|
2620
|
-
// : never;
|
|
2621
|
-
// }
|
|
2622
|
-
// >(
|
|
2623
|
-
// merging: Incoming
|
|
2624
|
-
// ): ZodObject<
|
|
2625
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2626
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2627
|
-
// Incoming["_def"]["catchall"],
|
|
2628
|
-
// NewOutput,
|
|
2629
|
-
// NewInput
|
|
2630
|
-
// > {
|
|
2631
|
-
// const merged: any = new ZodObject({
|
|
2632
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2633
|
-
// catchall: merging._def.catchall,
|
|
2634
|
-
// shape: () =>
|
|
2635
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2636
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2637
|
-
// }) as any;
|
|
2638
|
-
// return merged;
|
|
2639
|
-
// }
|
|
2640
2483
|
setKey(key, schema) {
|
|
2641
|
-
return this.augment({ [key]: schema });
|
|
2642
|
-
}
|
|
2643
|
-
// merge<Incoming extends AnyZodObject>(
|
|
2644
|
-
// merging: Incoming
|
|
2645
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2646
|
-
// ZodObject<
|
|
2647
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2648
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2649
|
-
// Incoming["_def"]["catchall"]
|
|
2650
|
-
// > {
|
|
2651
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
2652
|
-
// // this._def.shape(),
|
|
2653
|
-
// // merging._def.shape()
|
|
2654
|
-
// // );
|
|
2655
|
-
// const merged: any = new ZodObject({
|
|
2656
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2657
|
-
// catchall: merging._def.catchall,
|
|
2658
|
-
// shape: () =>
|
|
2659
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2660
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2661
|
-
// }) as any;
|
|
2662
|
-
// return merged;
|
|
2663
|
-
// }
|
|
2484
|
+
return this.augment(Object.assign(Object.create(null), { [key]: schema }));
|
|
2485
|
+
}
|
|
2664
2486
|
catchall(index) {
|
|
2665
2487
|
return new ZodObject({
|
|
2666
2488
|
...this._def,
|
|
@@ -2691,9 +2513,6 @@ class ZodObject extends ZodType {
|
|
|
2691
2513
|
shape: () => shape,
|
|
2692
2514
|
});
|
|
2693
2515
|
}
|
|
2694
|
-
/**
|
|
2695
|
-
* @deprecated
|
|
2696
|
-
*/
|
|
2697
2516
|
deepPartial() {
|
|
2698
2517
|
return deepPartialify(this);
|
|
2699
2518
|
}
|
|
@@ -2769,7 +2588,6 @@ class ZodUnion extends ZodType {
|
|
|
2769
2588
|
const { ctx } = this._processInputParams(input);
|
|
2770
2589
|
const options = this._def.options;
|
|
2771
2590
|
function handleResults(results) {
|
|
2772
|
-
// return first issue-free validation if it exists
|
|
2773
2591
|
for (const result of results) {
|
|
2774
2592
|
if (result.result.status === "valid") {
|
|
2775
2593
|
return result.result;
|
|
@@ -2777,12 +2595,10 @@ class ZodUnion extends ZodType {
|
|
|
2777
2595
|
}
|
|
2778
2596
|
for (const result of results) {
|
|
2779
2597
|
if (result.result.status === "dirty") {
|
|
2780
|
-
// add issues from dirty option
|
|
2781
2598
|
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2782
2599
|
return result.result;
|
|
2783
2600
|
}
|
|
2784
2601
|
}
|
|
2785
|
-
// return invalid
|
|
2786
2602
|
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2787
2603
|
addIssueToContext(ctx, {
|
|
2788
2604
|
code: ZodIssueCode.invalid_union,
|
|
@@ -2860,13 +2676,6 @@ class ZodUnion extends ZodType {
|
|
|
2860
2676
|
});
|
|
2861
2677
|
};
|
|
2862
2678
|
}
|
|
2863
|
-
/////////////////////////////////////////////////////
|
|
2864
|
-
/////////////////////////////////////////////////////
|
|
2865
|
-
////////// //////////
|
|
2866
|
-
////////// ZodDiscriminatedUnion //////////
|
|
2867
|
-
////////// //////////
|
|
2868
|
-
/////////////////////////////////////////////////////
|
|
2869
|
-
/////////////////////////////////////////////////////
|
|
2870
2679
|
const getDiscriminator = (type) => {
|
|
2871
2680
|
if (type instanceof ZodLazy) {
|
|
2872
2681
|
return getDiscriminator(type.schema);
|
|
@@ -2881,7 +2690,6 @@ const getDiscriminator = (type) => {
|
|
|
2881
2690
|
return type.options;
|
|
2882
2691
|
}
|
|
2883
2692
|
else if (type instanceof ZodNativeEnum) {
|
|
2884
|
-
// eslint-disable-next-line ban/ban
|
|
2885
2693
|
return util.objectValues(type.enum);
|
|
2886
2694
|
}
|
|
2887
2695
|
else if (type instanceof ZodDefault) {
|
|
@@ -2958,18 +2766,8 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
2958
2766
|
get optionsMap() {
|
|
2959
2767
|
return this._def.optionsMap;
|
|
2960
2768
|
}
|
|
2961
|
-
/**
|
|
2962
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2963
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2964
|
-
* have a different value for each object in the union.
|
|
2965
|
-
* @param discriminator the name of the discriminator property
|
|
2966
|
-
* @param types an array of object schemas
|
|
2967
|
-
* @param params
|
|
2968
|
-
*/
|
|
2969
2769
|
static create(discriminator, options, params) {
|
|
2970
|
-
// Get all the valid discriminator values
|
|
2971
2770
|
const optionsMap = new Map();
|
|
2972
|
-
// try {
|
|
2973
2771
|
for (const type of options) {
|
|
2974
2772
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2975
2773
|
if (!discriminatorValues.length) {
|
|
@@ -3002,7 +2800,7 @@ function mergeValues(a, b) {
|
|
|
3002
2800
|
const sharedKeys = util
|
|
3003
2801
|
.objectKeys(a)
|
|
3004
2802
|
.filter((key) => bKeys.indexOf(key) !== -1);
|
|
3005
|
-
const newObj = { ...a, ...b };
|
|
2803
|
+
const newObj = { __proto__: null, ...a, ...b };
|
|
3006
2804
|
for (const key of sharedKeys) {
|
|
3007
2805
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
3008
2806
|
if (!sharedValue.valid) {
|
|
@@ -3130,7 +2928,7 @@ class ZodTuple extends ZodType {
|
|
|
3130
2928
|
return null;
|
|
3131
2929
|
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3132
2930
|
})
|
|
3133
|
-
.filter((x) => !!x);
|
|
2931
|
+
.filter((x) => !!x);
|
|
3134
2932
|
if (ctx.common.async) {
|
|
3135
2933
|
return Promise.all(items).then((results) => {
|
|
3136
2934
|
return ParseStatus.mergeArray(status, results);
|
|
@@ -3414,9 +3212,6 @@ class ZodFunction extends ZodType {
|
|
|
3414
3212
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3415
3213
|
const fn = ctx.data;
|
|
3416
3214
|
if (this._def.returns instanceof ZodPromise) {
|
|
3417
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3418
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3419
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3420
3215
|
const me = this;
|
|
3421
3216
|
return OK(async function (...args) {
|
|
3422
3217
|
const error = new ZodError([]);
|
|
@@ -3437,9 +3232,6 @@ class ZodFunction extends ZodType {
|
|
|
3437
3232
|
});
|
|
3438
3233
|
}
|
|
3439
3234
|
else {
|
|
3440
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3441
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3442
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3443
3235
|
const me = this;
|
|
3444
3236
|
return OK(function (...args) {
|
|
3445
3237
|
const parsedArgs = me._def.args.safeParse(args, params);
|
|
@@ -3765,7 +3557,6 @@ class ZodEffects extends ZodType {
|
|
|
3765
3557
|
return INVALID;
|
|
3766
3558
|
if (inner.status === "dirty")
|
|
3767
3559
|
status.dirty();
|
|
3768
|
-
// return value is ignored
|
|
3769
3560
|
executeRefinement(inner.value);
|
|
3770
3561
|
return { status: status.value, value: inner.value };
|
|
3771
3562
|
}
|
|
@@ -3895,7 +3686,6 @@ class ZodDefault extends ZodType {
|
|
|
3895
3686
|
class ZodCatch extends ZodType {
|
|
3896
3687
|
_parse(input) {
|
|
3897
3688
|
const { ctx } = this._processInputParams(input);
|
|
3898
|
-
// newCtx is used to not collect issues from inner types in ctx
|
|
3899
3689
|
const newCtx = {
|
|
3900
3690
|
...ctx,
|
|
3901
3691
|
common: {
|
|
@@ -4069,18 +3859,7 @@ class ZodReadonly extends ZodType {
|
|
|
4069
3859
|
return this._def.innerType;
|
|
4070
3860
|
}
|
|
4071
3861
|
}
|
|
4072
|
-
function custom(check, params = Object.create(null),
|
|
4073
|
-
/**
|
|
4074
|
-
* @deprecated
|
|
4075
|
-
*
|
|
4076
|
-
* Pass `fatal` into the params object instead:
|
|
4077
|
-
*
|
|
4078
|
-
* ```ts
|
|
4079
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
|
4080
|
-
* ```
|
|
4081
|
-
*
|
|
4082
|
-
*/
|
|
4083
|
-
fatal) {
|
|
3862
|
+
function custom(check, params = Object.create(null), fatal) {
|
|
4084
3863
|
if (check)
|
|
4085
3864
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
4086
3865
|
if (!check(data)) {
|
|
@@ -4138,9 +3917,7 @@ var ZodFirstPartyTypeKind;
|
|
|
4138
3917
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
4139
3918
|
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
4140
3919
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4141
|
-
const instanceOfType = (
|
|
4142
|
-
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
|
4143
|
-
cls, params = {
|
|
3920
|
+
const instanceOfType = (cls, params = {
|
|
4144
3921
|
message: `Input not instance of ${cls.name}`,
|
|
4145
3922
|
}) => custom((data) => data instanceof cls, params);
|
|
4146
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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/zod",
|
|
3
|
-
"version": "3.24.1-rc.
|
|
4
|
-
"author": "
|
|
3
|
+
"version": "3.24.1-rc.6",
|
|
4
|
+
"author": "Exodus Movement, Inc.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/ExodusMovement/zod.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"module": "./lib/index.mjs",
|
|
@@ -23,8 +23,6 @@
|
|
|
23
23
|
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
24
24
|
"@typescript-eslint/parser": "^5.15.0",
|
|
25
25
|
"babel-jest": "^29.5.0",
|
|
26
|
-
"benchmark": "^2.1.4",
|
|
27
|
-
"dependency-cruiser": "^9.19.0",
|
|
28
26
|
"eslint": "^8.11.0",
|
|
29
27
|
"eslint-config-prettier": "^8.5.0",
|
|
30
28
|
"eslint-plugin-ban": "^1.6.0",
|
|
@@ -55,7 +53,7 @@
|
|
|
55
53
|
"./package.json": "./package.json"
|
|
56
54
|
},
|
|
57
55
|
"bugs": {
|
|
58
|
-
"url": "https://github.com/
|
|
56
|
+
"url": "https://github.com/ExodusMovement/zod/issues"
|
|
59
57
|
},
|
|
60
58
|
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
|
61
59
|
"files": [
|
|
@@ -63,8 +61,6 @@
|
|
|
63
61
|
"/index.d.ts",
|
|
64
62
|
"!/lib/benchmarks"
|
|
65
63
|
],
|
|
66
|
-
"funding": "https://github.com/sponsors/colinhacks",
|
|
67
|
-
"homepage": "https://zod.dev",
|
|
68
64
|
"keywords": [
|
|
69
65
|
"typescript",
|
|
70
66
|
"schema",
|
|
@@ -101,12 +97,7 @@
|
|
|
101
97
|
"test:vitest": "npx vitest --config ./configs/vitest.config.ts",
|
|
102
98
|
"test:ts-jest": "npx jest --config ./configs/ts-jest.config.json",
|
|
103
99
|
"test:swc": "npx jest --config ./configs/swc-jest.config.json",
|
|
104
|
-
"prepublishOnly": "npm run test && npm run build"
|
|
105
|
-
"play": "nodemon -e ts -w . -x tsx playground.ts",
|
|
106
|
-
"depcruise": "depcruise -c .dependency-cruiser.js src",
|
|
107
|
-
"benchmark": "tsx src/benchmarks/index.ts",
|
|
108
|
-
"prepare": "husky install",
|
|
109
|
-
"docs": "netlify dev"
|
|
100
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
110
101
|
},
|
|
111
102
|
"sideEffects": false,
|
|
112
103
|
"support": {
|