adding dist
This commit is contained in:
+250
-35
@@ -44158,6 +44158,7 @@ class ZodError extends Error {
|
|||||||
};
|
};
|
||||||
const actualProto = new.target.prototype;
|
const actualProto = new.target.prototype;
|
||||||
if (Object.setPrototypeOf) {
|
if (Object.setPrototypeOf) {
|
||||||
|
// eslint-disable-next-line ban/ban
|
||||||
Object.setPrototypeOf(this, actualProto);
|
Object.setPrototypeOf(this, actualProto);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -44197,6 +44198,13 @@ class ZodError extends Error {
|
|||||||
const terminal = i === issue.path.length - 1;
|
const terminal = i === issue.path.length - 1;
|
||||||
if (!terminal) {
|
if (!terminal) {
|
||||||
curr[el] = curr[el] || { _errors: [] };
|
curr[el] = curr[el] || { _errors: [] };
|
||||||
|
// if (typeof el === "string") {
|
||||||
|
// curr[el] = curr[el] || { _errors: [] };
|
||||||
|
// } else if (typeof el === "number") {
|
||||||
|
// const errorArray: any = [];
|
||||||
|
// errorArray._errors = [];
|
||||||
|
// curr[el] = curr[el] || errorArray;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
curr[el] = curr[el] || { _errors: [] };
|
curr[el] = curr[el] || { _errors: [] };
|
||||||
@@ -44358,7 +44366,7 @@ function addIssueToContext(ctx, issueData) {
|
|||||||
ctx.common.contextualErrorMap,
|
ctx.common.contextualErrorMap,
|
||||||
ctx.schemaErrorMap,
|
ctx.schemaErrorMap,
|
||||||
(0, errors_1.getErrorMap)(),
|
(0, errors_1.getErrorMap)(),
|
||||||
en_1.default,
|
en_1.default, // then global default map
|
||||||
].filter((x) => !!x),
|
].filter((x) => !!x),
|
||||||
});
|
});
|
||||||
ctx.common.issues.push(issue);
|
ctx.common.issues.push(issue);
|
||||||
@@ -44483,8 +44491,8 @@ var util;
|
|||||||
return obj[e];
|
return obj[e];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
util.objectKeys = typeof Object.keys === "function"
|
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
||||||
? (obj) => Object.keys(obj)
|
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
||||||
: (object) => {
|
: (object) => {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
for (const key in object) {
|
for (const key in object) {
|
||||||
@@ -44502,7 +44510,7 @@ var util;
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
util.isInteger = typeof Number.isInteger === "function"
|
util.isInteger = typeof Number.isInteger === "function"
|
||||||
? (val) => Number.isInteger(val)
|
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
||||||
: (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
: (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
||||||
function joinValues(array, separator = " | ") {
|
function joinValues(array, separator = " | ") {
|
||||||
return array
|
return array
|
||||||
@@ -44522,7 +44530,7 @@ var objectUtil;
|
|||||||
objectUtil.mergeShapes = (first, second) => {
|
objectUtil.mergeShapes = (first, second) => {
|
||||||
return {
|
return {
|
||||||
...first,
|
...first,
|
||||||
...second,
|
...second, // second overwrites first
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
||||||
@@ -44845,6 +44853,7 @@ function processCreateParams(params) {
|
|||||||
}
|
}
|
||||||
class ZodType {
|
class ZodType {
|
||||||
constructor(def) {
|
constructor(def) {
|
||||||
|
/** Alias of safeParseAsync */
|
||||||
this.spa = this.safeParseAsync;
|
this.spa = this.safeParseAsync;
|
||||||
this._def = def;
|
this._def = def;
|
||||||
this.parse = this.parse.bind(this);
|
this.parse = this.parse.bind(this);
|
||||||
@@ -45100,12 +45109,31 @@ exports.Schema = ZodType;
|
|||||||
exports.ZodSchema = ZodType;
|
exports.ZodSchema = ZodType;
|
||||||
const cuidRegex = /^c[^\s-]{8,}$/i;
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
||||||
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
||||||
const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
|
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
||||||
|
// const uuidRegex =
|
||||||
|
// /^([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;
|
||||||
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;
|
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;
|
||||||
const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
// from https://stackoverflow.com/a/46181/1550155
|
||||||
const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
|
// old version: too slow, didn't support unicode
|
||||||
|
// 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;
|
||||||
|
//old email regex
|
||||||
|
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// const emailRegex =
|
||||||
|
// /^(([^<>()[\]\\.,;:\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,})+))$/;
|
||||||
|
// const emailRegex =
|
||||||
|
// /^[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])?)*$/;
|
||||||
|
// const emailRegex =
|
||||||
|
// /^(?:[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;
|
||||||
|
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
||||||
|
// const emailRegex =
|
||||||
|
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
||||||
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
||||||
|
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
||||||
|
let emojiRegex;
|
||||||
const ipv4Regex = /^(((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}))$/;
|
const ipv4Regex = /^(((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}))$/;
|
||||||
const ipv6Regex = /^(([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})))$/;
|
const ipv6Regex = /^(([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})))$/;
|
||||||
|
// Adapted from https://stackoverflow.com/a/3143231
|
||||||
const datetimeRegex = (args) => {
|
const datetimeRegex = (args) => {
|
||||||
if (args.precision) {
|
if (args.precision) {
|
||||||
if (args.offset) {
|
if (args.offset) {
|
||||||
@@ -45142,27 +45170,6 @@ function isValidIP(ip, version) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
class ZodString extends ZodType {
|
class ZodString extends ZodType {
|
||||||
constructor() {
|
|
||||||
super(...arguments);
|
|
||||||
this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
|
|
||||||
validation,
|
|
||||||
code: ZodError_1.ZodIssueCode.invalid_string,
|
|
||||||
...errorUtil_1.errorUtil.errToObj(message),
|
|
||||||
});
|
|
||||||
this.nonempty = (message) => this.min(1, errorUtil_1.errorUtil.errToObj(message));
|
|
||||||
this.trim = () => new ZodString({
|
|
||||||
...this._def,
|
|
||||||
checks: [...this._def.checks, { kind: "trim" }],
|
|
||||||
});
|
|
||||||
this.toLowerCase = () => new ZodString({
|
|
||||||
...this._def,
|
|
||||||
checks: [...this._def.checks, { kind: "toLowerCase" }],
|
|
||||||
});
|
|
||||||
this.toUpperCase = () => new ZodString({
|
|
||||||
...this._def,
|
|
||||||
checks: [...this._def.checks, { kind: "toUpperCase" }],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_parse(input) {
|
_parse(input) {
|
||||||
if (this._def.coerce) {
|
if (this._def.coerce) {
|
||||||
input.data = String(input.data);
|
input.data = String(input.data);
|
||||||
@@ -45174,7 +45181,9 @@ class ZodString extends ZodType {
|
|||||||
code: ZodError_1.ZodIssueCode.invalid_type,
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
||||||
expected: util_1.ZodParsedType.string,
|
expected: util_1.ZodParsedType.string,
|
||||||
received: ctx.parsedType,
|
received: ctx.parsedType,
|
||||||
});
|
}
|
||||||
|
//
|
||||||
|
);
|
||||||
return parseUtil_1.INVALID;
|
return parseUtil_1.INVALID;
|
||||||
}
|
}
|
||||||
const status = new parseUtil_1.ParseStatus();
|
const status = new parseUtil_1.ParseStatus();
|
||||||
@@ -45248,6 +45257,9 @@ class ZodString extends ZodType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (check.kind === "emoji") {
|
else if (check.kind === "emoji") {
|
||||||
|
if (!emojiRegex) {
|
||||||
|
emojiRegex = new RegExp(_emojiRegex, "u");
|
||||||
|
}
|
||||||
if (!emojiRegex.test(input.data)) {
|
if (!emojiRegex.test(input.data)) {
|
||||||
ctx = this._getOrReturnCtx(input, ctx);
|
ctx = this._getOrReturnCtx(input, ctx);
|
||||||
(0, parseUtil_1.addIssueToContext)(ctx, {
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
||||||
@@ -45400,6 +45412,13 @@ class ZodString extends ZodType {
|
|||||||
}
|
}
|
||||||
return { status: status.value, value: input.data };
|
return { status: status.value, value: input.data };
|
||||||
}
|
}
|
||||||
|
_regex(regex, validation, message) {
|
||||||
|
return this.refinement((data) => regex.test(data), {
|
||||||
|
validation,
|
||||||
|
code: ZodError_1.ZodIssueCode.invalid_string,
|
||||||
|
...errorUtil_1.errorUtil.errToObj(message),
|
||||||
|
});
|
||||||
|
}
|
||||||
_addCheck(check) {
|
_addCheck(check) {
|
||||||
return new ZodString({
|
return new ZodString({
|
||||||
...this._def,
|
...this._def,
|
||||||
@@ -45497,6 +45516,31 @@ class ZodString extends ZodType {
|
|||||||
...errorUtil_1.errorUtil.errToObj(message),
|
...errorUtil_1.errorUtil.errToObj(message),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @deprecated Use z.string().min(1) instead.
|
||||||
|
* @see {@link ZodString.min}
|
||||||
|
*/
|
||||||
|
nonempty(message) {
|
||||||
|
return this.min(1, errorUtil_1.errorUtil.errToObj(message));
|
||||||
|
}
|
||||||
|
trim() {
|
||||||
|
return new ZodString({
|
||||||
|
...this._def,
|
||||||
|
checks: [...this._def.checks, { kind: "trim" }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
toLowerCase() {
|
||||||
|
return new ZodString({
|
||||||
|
...this._def,
|
||||||
|
checks: [...this._def.checks, { kind: "toLowerCase" }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
toUpperCase() {
|
||||||
|
return new ZodString({
|
||||||
|
...this._def,
|
||||||
|
checks: [...this._def.checks, { kind: "toUpperCase" }],
|
||||||
|
});
|
||||||
|
}
|
||||||
get isDatetime() {
|
get isDatetime() {
|
||||||
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
||||||
}
|
}
|
||||||
@@ -45555,6 +45599,7 @@ ZodString.create = (params) => {
|
|||||||
...processCreateParams(params),
|
...processCreateParams(params),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
||||||
function floatSafeRemainder(val, step) {
|
function floatSafeRemainder(val, step) {
|
||||||
const valDecCount = (val.toString().split(".")[1] || "").length;
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
||||||
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
||||||
@@ -46190,6 +46235,7 @@ ZodNull.create = (params) => {
|
|||||||
class ZodAny extends ZodType {
|
class ZodAny extends ZodType {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
||||||
this._any = true;
|
this._any = true;
|
||||||
}
|
}
|
||||||
_parse(input) {
|
_parse(input) {
|
||||||
@@ -46206,6 +46252,7 @@ ZodAny.create = (params) => {
|
|||||||
class ZodUnknown extends ZodType {
|
class ZodUnknown extends ZodType {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
// required
|
||||||
this._unknown = true;
|
this._unknown = true;
|
||||||
}
|
}
|
||||||
_parse(input) {
|
_parse(input) {
|
||||||
@@ -46396,7 +46443,47 @@ class ZodObject extends ZodType {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this._cached = null;
|
this._cached = null;
|
||||||
|
/**
|
||||||
|
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
||||||
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
||||||
|
*/
|
||||||
this.nonstrict = this.passthrough;
|
this.nonstrict = this.passthrough;
|
||||||
|
// extend<
|
||||||
|
// Augmentation extends ZodRawShape,
|
||||||
|
// NewOutput extends util.flatten<{
|
||||||
|
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
||||||
|
// ? Augmentation[k]["_output"]
|
||||||
|
// : k extends keyof Output
|
||||||
|
// ? Output[k]
|
||||||
|
// : never;
|
||||||
|
// }>,
|
||||||
|
// NewInput extends util.flatten<{
|
||||||
|
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
||||||
|
// ? Augmentation[k]["_input"]
|
||||||
|
// : k extends keyof Input
|
||||||
|
// ? Input[k]
|
||||||
|
// : never;
|
||||||
|
// }>
|
||||||
|
// >(
|
||||||
|
// augmentation: Augmentation
|
||||||
|
// ): ZodObject<
|
||||||
|
// extendShape<T, Augmentation>,
|
||||||
|
// UnknownKeys,
|
||||||
|
// Catchall,
|
||||||
|
// NewOutput,
|
||||||
|
// NewInput
|
||||||
|
// > {
|
||||||
|
// return new ZodObject({
|
||||||
|
// ...this._def,
|
||||||
|
// shape: () => ({
|
||||||
|
// ...this._def.shape(),
|
||||||
|
// ...augmentation,
|
||||||
|
// }),
|
||||||
|
// }) as any;
|
||||||
|
// }
|
||||||
|
/**
|
||||||
|
* @deprecated Use `.extend` instead
|
||||||
|
* */
|
||||||
this.augment = this.extend;
|
this.augment = this.extend;
|
||||||
}
|
}
|
||||||
_getCached() {
|
_getCached() {
|
||||||
@@ -46464,12 +46551,14 @@ class ZodObject extends ZodType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// run catchall validation
|
||||||
const catchall = this._def.catchall;
|
const catchall = this._def.catchall;
|
||||||
for (const key of extraKeys) {
|
for (const key of extraKeys) {
|
||||||
const value = ctx.data[key];
|
const value = ctx.data[key];
|
||||||
pairs.push({
|
pairs.push({
|
||||||
key: { status: "valid", value: key },
|
key: { status: "valid", value: key },
|
||||||
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
||||||
|
),
|
||||||
alwaysSet: key in ctx.data,
|
alwaysSet: key in ctx.data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -46533,6 +46622,23 @@ class ZodObject extends ZodType {
|
|||||||
unknownKeys: "passthrough",
|
unknownKeys: "passthrough",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// const AugmentFactory =
|
||||||
|
// <Def extends ZodObjectDef>(def: Def) =>
|
||||||
|
// <Augmentation extends ZodRawShape>(
|
||||||
|
// augmentation: Augmentation
|
||||||
|
// ): ZodObject<
|
||||||
|
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
||||||
|
// Def["unknownKeys"],
|
||||||
|
// Def["catchall"]
|
||||||
|
// > => {
|
||||||
|
// return new ZodObject({
|
||||||
|
// ...def,
|
||||||
|
// shape: () => ({
|
||||||
|
// ...def.shape(),
|
||||||
|
// ...augmentation,
|
||||||
|
// }),
|
||||||
|
// }) as any;
|
||||||
|
// };
|
||||||
extend(augmentation) {
|
extend(augmentation) {
|
||||||
return new ZodObject({
|
return new ZodObject({
|
||||||
...this._def,
|
...this._def,
|
||||||
@@ -46542,6 +46648,11 @@ class ZodObject extends ZodType {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Prior to zod@1.0.12 there was a bug in the
|
||||||
|
* inferred type of merged objects. Please
|
||||||
|
* upgrade if you are experiencing issues.
|
||||||
|
*/
|
||||||
merge(merging) {
|
merge(merging) {
|
||||||
const merged = new ZodObject({
|
const merged = new ZodObject({
|
||||||
unknownKeys: merging._def.unknownKeys,
|
unknownKeys: merging._def.unknownKeys,
|
||||||
@@ -46554,9 +46665,65 @@ class ZodObject extends ZodType {
|
|||||||
});
|
});
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
// merge<
|
||||||
|
// Incoming extends AnyZodObject,
|
||||||
|
// Augmentation extends Incoming["shape"],
|
||||||
|
// NewOutput extends {
|
||||||
|
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
||||||
|
// ? Augmentation[k]["_output"]
|
||||||
|
// : k extends keyof Output
|
||||||
|
// ? Output[k]
|
||||||
|
// : never;
|
||||||
|
// },
|
||||||
|
// NewInput extends {
|
||||||
|
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
||||||
|
// ? Augmentation[k]["_input"]
|
||||||
|
// : k extends keyof Input
|
||||||
|
// ? Input[k]
|
||||||
|
// : never;
|
||||||
|
// }
|
||||||
|
// >(
|
||||||
|
// merging: Incoming
|
||||||
|
// ): ZodObject<
|
||||||
|
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
||||||
|
// Incoming["_def"]["unknownKeys"],
|
||||||
|
// Incoming["_def"]["catchall"],
|
||||||
|
// NewOutput,
|
||||||
|
// NewInput
|
||||||
|
// > {
|
||||||
|
// const merged: any = new ZodObject({
|
||||||
|
// unknownKeys: merging._def.unknownKeys,
|
||||||
|
// catchall: merging._def.catchall,
|
||||||
|
// shape: () =>
|
||||||
|
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
||||||
|
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
||||||
|
// }) as any;
|
||||||
|
// return merged;
|
||||||
|
// }
|
||||||
setKey(key, schema) {
|
setKey(key, schema) {
|
||||||
return this.augment({ [key]: schema });
|
return this.augment({ [key]: schema });
|
||||||
}
|
}
|
||||||
|
// merge<Incoming extends AnyZodObject>(
|
||||||
|
// merging: Incoming
|
||||||
|
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
||||||
|
// ZodObject<
|
||||||
|
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
||||||
|
// Incoming["_def"]["unknownKeys"],
|
||||||
|
// Incoming["_def"]["catchall"]
|
||||||
|
// > {
|
||||||
|
// // const mergedShape = objectUtil.mergeShapes(
|
||||||
|
// // this._def.shape(),
|
||||||
|
// // merging._def.shape()
|
||||||
|
// // );
|
||||||
|
// const merged: any = new ZodObject({
|
||||||
|
// unknownKeys: merging._def.unknownKeys,
|
||||||
|
// catchall: merging._def.catchall,
|
||||||
|
// shape: () =>
|
||||||
|
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
||||||
|
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
||||||
|
// }) as any;
|
||||||
|
// return merged;
|
||||||
|
// }
|
||||||
catchall(index) {
|
catchall(index) {
|
||||||
return new ZodObject({
|
return new ZodObject({
|
||||||
...this._def,
|
...this._def,
|
||||||
@@ -46587,6 +46754,9 @@ class ZodObject extends ZodType {
|
|||||||
shape: () => shape,
|
shape: () => shape,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
deepPartial() {
|
deepPartial() {
|
||||||
return deepPartialify(this);
|
return deepPartialify(this);
|
||||||
}
|
}
|
||||||
@@ -46663,6 +46833,7 @@ class ZodUnion extends ZodType {
|
|||||||
const { ctx } = this._processInputParams(input);
|
const { ctx } = this._processInputParams(input);
|
||||||
const options = this._def.options;
|
const options = this._def.options;
|
||||||
function handleResults(results) {
|
function handleResults(results) {
|
||||||
|
// return first issue-free validation if it exists
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
if (result.result.status === "valid") {
|
if (result.result.status === "valid") {
|
||||||
return result.result;
|
return result.result;
|
||||||
@@ -46670,10 +46841,12 @@ class ZodUnion extends ZodType {
|
|||||||
}
|
}
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
if (result.result.status === "dirty") {
|
if (result.result.status === "dirty") {
|
||||||
|
// add issues from dirty option
|
||||||
ctx.common.issues.push(...result.ctx.common.issues);
|
ctx.common.issues.push(...result.ctx.common.issues);
|
||||||
return result.result;
|
return result.result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// return invalid
|
||||||
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
|
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
|
||||||
(0, parseUtil_1.addIssueToContext)(ctx, {
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
||||||
code: ZodError_1.ZodIssueCode.invalid_union,
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
||||||
@@ -46752,6 +46925,13 @@ ZodUnion.create = (types, params) => {
|
|||||||
...processCreateParams(params),
|
...processCreateParams(params),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
////////// //////////
|
||||||
|
////////// ZodDiscriminatedUnion //////////
|
||||||
|
////////// //////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
const getDiscriminator = (type) => {
|
const getDiscriminator = (type) => {
|
||||||
if (type instanceof ZodLazy) {
|
if (type instanceof ZodLazy) {
|
||||||
return getDiscriminator(type.schema);
|
return getDiscriminator(type.schema);
|
||||||
@@ -46766,6 +46946,7 @@ const getDiscriminator = (type) => {
|
|||||||
return type.options;
|
return type.options;
|
||||||
}
|
}
|
||||||
else if (type instanceof ZodNativeEnum) {
|
else if (type instanceof ZodNativeEnum) {
|
||||||
|
// eslint-disable-next-line ban/ban
|
||||||
return Object.keys(type.enum);
|
return Object.keys(type.enum);
|
||||||
}
|
}
|
||||||
else if (type instanceof ZodDefault) {
|
else if (type instanceof ZodDefault) {
|
||||||
@@ -46827,8 +47008,18 @@ class ZodDiscriminatedUnion extends ZodType {
|
|||||||
get optionsMap() {
|
get optionsMap() {
|
||||||
return this._def.optionsMap;
|
return this._def.optionsMap;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
||||||
|
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
||||||
|
* have a different value for each object in the union.
|
||||||
|
* @param discriminator the name of the discriminator property
|
||||||
|
* @param types an array of object schemas
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
static create(discriminator, options, params) {
|
static create(discriminator, options, params) {
|
||||||
|
// Get all the valid discriminator values
|
||||||
const optionsMap = new Map();
|
const optionsMap = new Map();
|
||||||
|
// try {
|
||||||
for (const type of options) {
|
for (const type of options) {
|
||||||
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
||||||
if (!discriminatorValues) {
|
if (!discriminatorValues) {
|
||||||
@@ -46991,7 +47182,7 @@ class ZodTuple extends ZodType {
|
|||||||
return null;
|
return null;
|
||||||
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
||||||
})
|
})
|
||||||
.filter((x) => !!x);
|
.filter((x) => !!x); // filter nulls
|
||||||
if (ctx.common.async) {
|
if (ctx.common.async) {
|
||||||
return Promise.all(items).then((results) => {
|
return Promise.all(items).then((results) => {
|
||||||
return parseUtil_1.ParseStatus.mergeArray(status, results);
|
return parseUtil_1.ParseStatus.mergeArray(status, results);
|
||||||
@@ -47282,6 +47473,9 @@ class ZodFunction extends ZodType {
|
|||||||
const params = { errorMap: ctx.common.contextualErrorMap };
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
||||||
const fn = ctx.data;
|
const fn = ctx.data;
|
||||||
if (this._def.returns instanceof ZodPromise) {
|
if (this._def.returns instanceof ZodPromise) {
|
||||||
|
// Would love a way to avoid disabling this rule, but we need
|
||||||
|
// an alias (using an arrow function was what caused 2651).
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||||
const me = this;
|
const me = this;
|
||||||
return (0, parseUtil_1.OK)(async function (...args) {
|
return (0, parseUtil_1.OK)(async function (...args) {
|
||||||
const error = new ZodError_1.ZodError([]);
|
const error = new ZodError_1.ZodError([]);
|
||||||
@@ -47302,6 +47496,9 @@ class ZodFunction extends ZodType {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Would love a way to avoid disabling this rule, but we need
|
||||||
|
// an alias (using an arrow function was what caused 2651).
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||||
const me = this;
|
const me = this;
|
||||||
return (0, parseUtil_1.OK)(function (...args) {
|
return (0, parseUtil_1.OK)(function (...args) {
|
||||||
const parsedArgs = me._def.args.safeParse(args, params);
|
const parsedArgs = me._def.args.safeParse(args, params);
|
||||||
@@ -47586,7 +47783,9 @@ class ZodEffects extends ZodType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (effect.type === "refinement") {
|
if (effect.type === "refinement") {
|
||||||
const executeRefinement = (acc) => {
|
const executeRefinement = (acc
|
||||||
|
// effect: RefinementEffect<any>
|
||||||
|
) => {
|
||||||
const result = effect.refinement(acc, checkCtx);
|
const result = effect.refinement(acc, checkCtx);
|
||||||
if (ctx.common.async) {
|
if (ctx.common.async) {
|
||||||
return Promise.resolve(result);
|
return Promise.resolve(result);
|
||||||
@@ -47606,6 +47805,7 @@ class ZodEffects extends ZodType {
|
|||||||
return parseUtil_1.INVALID;
|
return parseUtil_1.INVALID;
|
||||||
if (inner.status === "dirty")
|
if (inner.status === "dirty")
|
||||||
status.dirty();
|
status.dirty();
|
||||||
|
// return value is ignored
|
||||||
executeRefinement(inner.value);
|
executeRefinement(inner.value);
|
||||||
return { status: status.value, value: inner.value };
|
return { status: status.value, value: inner.value };
|
||||||
}
|
}
|
||||||
@@ -47740,6 +47940,7 @@ ZodDefault.create = (type, params) => {
|
|||||||
class ZodCatch extends ZodType {
|
class ZodCatch extends ZodType {
|
||||||
_parse(input) {
|
_parse(input) {
|
||||||
const { ctx } = this._processInputParams(input);
|
const { ctx } = this._processInputParams(input);
|
||||||
|
// newCtx is used to not collect issues from inner types in ctx
|
||||||
const newCtx = {
|
const newCtx = {
|
||||||
...ctx,
|
...ctx,
|
||||||
common: {
|
common: {
|
||||||
@@ -47910,7 +48111,18 @@ ZodReadonly.create = (type, params) => {
|
|||||||
...processCreateParams(params),
|
...processCreateParams(params),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const custom = (check, params = {}, fatal) => {
|
const custom = (check, params = {},
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
|
* Pass `fatal` into the params object instead:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* z.string().custom((val) => val.length > 5, { fatal: false })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
fatal) => {
|
||||||
if (check)
|
if (check)
|
||||||
return ZodAny.create().superRefine((data, ctx) => {
|
return ZodAny.create().superRefine((data, ctx) => {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
@@ -47970,10 +48182,13 @@ var ZodFirstPartyTypeKind;
|
|||||||
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
||||||
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
||||||
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
||||||
|
// requires TS 4.4+
|
||||||
class Class {
|
class Class {
|
||||||
constructor(..._) { }
|
constructor(..._) { }
|
||||||
}
|
}
|
||||||
const instanceOfType = (cls, params = {
|
const instanceOfType = (
|
||||||
|
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
||||||
|
cls, params = {
|
||||||
message: `Input not instance of ${cls.name}`,
|
message: `Input not instance of ${cls.name}`,
|
||||||
}) => (0, exports.custom)((data) => data instanceof cls, params);
|
}) => (0, exports.custom)((data) => data instanceof cls, params);
|
||||||
exports["instanceof"] = instanceOfType;
|
exports["instanceof"] = instanceOfType;
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user