Compare commits

...

1 Commits

Author SHA1 Message Date
Federico Builes 605a14dcda adding dist 2023-02-16 14:41:52 +01:00
2 changed files with 227 additions and 86 deletions
Generated Vendored
+226 -85
View File
@@ -41154,7 +41154,7 @@ const isDirty = (x) => x.status === "dirty";
exports.isDirty = isDirty; exports.isDirty = isDirty;
const isValid = (x) => x.status === "valid"; const isValid = (x) => x.status === "valid";
exports.isValid = isValid; exports.isValid = isValid;
const isAsync = (x) => typeof Promise !== undefined && x instanceof Promise; const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
exports.isAsync = isAsync; exports.isAsync = isAsync;
@@ -41707,28 +41707,29 @@ class ZodType {
return this._refinement(refinement); return this._refinement(refinement);
} }
optional() { optional() {
return ZodOptional.create(this); return ZodOptional.create(this, this._def);
} }
nullable() { nullable() {
return ZodNullable.create(this); return ZodNullable.create(this, this._def);
} }
nullish() { nullish() {
return this.optional().nullable(); return this.nullable().optional();
} }
array() { array() {
return ZodArray.create(this); return ZodArray.create(this, this._def);
} }
promise() { promise() {
return ZodPromise.create(this); return ZodPromise.create(this, this._def);
} }
or(option) { or(option) {
return ZodUnion.create([this, option]); return ZodUnion.create([this, option], this._def);
} }
and(incoming) { and(incoming) {
return ZodIntersection.create(this, incoming); return ZodIntersection.create(this, incoming, this._def);
} }
transform(transform) { transform(transform) {
return new ZodEffects({ return new ZodEffects({
...processCreateParams(this._def),
schema: this, schema: this,
typeName: ZodFirstPartyTypeKind.ZodEffects, typeName: ZodFirstPartyTypeKind.ZodEffects,
effect: { type: "transform", transform }, effect: { type: "transform", transform },
@@ -41737,6 +41738,7 @@ class ZodType {
default(def) { default(def) {
const defaultValueFunc = typeof def === "function" ? def : () => def; const defaultValueFunc = typeof def === "function" ? def : () => def;
return new ZodDefault({ return new ZodDefault({
...processCreateParams(this._def),
innerType: this, innerType: this,
defaultValue: defaultValueFunc, defaultValue: defaultValueFunc,
typeName: ZodFirstPartyTypeKind.ZodDefault, typeName: ZodFirstPartyTypeKind.ZodDefault,
@@ -41746,14 +41748,15 @@ class ZodType {
return new ZodBranded({ return new ZodBranded({
typeName: ZodFirstPartyTypeKind.ZodBranded, typeName: ZodFirstPartyTypeKind.ZodBranded,
type: this, type: this,
...processCreateParams(undefined), ...processCreateParams(this._def),
}); });
} }
catch(def) { catch(def) {
const defaultValueFunc = typeof def === "function" ? def : () => def; const catchValueFunc = typeof def === "function" ? def : () => def;
return new ZodCatch({ return new ZodCatch({
...processCreateParams(this._def),
innerType: this, innerType: this,
defaultValue: defaultValueFunc, catchValue: catchValueFunc,
typeName: ZodFirstPartyTypeKind.ZodCatch, typeName: ZodFirstPartyTypeKind.ZodCatch,
}); });
} }
@@ -41778,12 +41781,15 @@ exports.ZodType = ZodType;
exports.Schema = ZodType; 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 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 = /^([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;
// from https://stackoverflow.com/a/46181/1550155 // from https://stackoverflow.com/a/46181/1550155
// old version: too slow, didn't support unicode // 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; // 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 // eslint-disable-next-line
const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|([^-]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}))$/;
// interface IsDateStringOptions extends StringDateOptions { // interface IsDateStringOptions extends StringDateOptions {
/** /**
* Match any configuration * Match any configuration
@@ -41794,7 +41800,7 @@ const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\")
const datetimeRegex = (args) => { const datetimeRegex = (args) => {
if (args.precision) { if (args.precision) {
if (args.offset) { if (args.offset) {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}:\\d{2})|Z)$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
} }
else { else {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
@@ -41802,7 +41808,7 @@ const datetimeRegex = (args) => {
} }
else if (args.precision === 0) { else if (args.precision === 0) {
if (args.offset) { if (args.offset) {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
} }
else { else {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
@@ -41810,7 +41816,7 @@ const datetimeRegex = (args) => {
} }
else { else {
if (args.offset) { if (args.offset) {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
} }
else { else {
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`); return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
@@ -41943,6 +41949,17 @@ class ZodString extends ZodType {
status.dirty(); status.dirty();
} }
} }
else if (check.kind === "cuid2") {
if (!cuid2Regex.test(input.data)) {
ctx = this._getOrReturnCtx(input, ctx);
(0, parseUtil_1.addIssueToContext)(ctx, {
validation: "cuid2",
code: ZodError_1.ZodIssueCode.invalid_string,
message: check.message,
});
status.dirty();
}
}
else if (check.kind === "url") { else if (check.kind === "url") {
try { try {
new URL(input.data); new URL(input.data);
@@ -42031,6 +42048,9 @@ class ZodString extends ZodType {
cuid(message) { cuid(message) {
return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) }); return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
} }
cuid2(message) {
return this._addCheck({ kind: "cuid2", ...errorUtil_1.errorUtil.errToObj(message) });
}
datetime(options) { datetime(options) {
var _a; var _a;
if (typeof options === "string") { if (typeof options === "string") {
@@ -42105,6 +42125,9 @@ class ZodString extends ZodType {
get isCUID() { get isCUID() {
return !!this._def.checks.find((ch) => ch.kind === "cuid"); return !!this._def.checks.find((ch) => ch.kind === "cuid");
} }
get isCUID2() {
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
}
get minLength() { get minLength() {
let min = null; let min = null;
for (const ch of this._def.checks) { for (const ch of this._def.checks) {
@@ -42346,7 +42369,27 @@ class ZodNumber extends ZodType {
return max; return max;
} }
get isInt() { get isInt() {
return !!this._def.checks.find((ch) => ch.kind === "int"); return !!this._def.checks.find((ch) => ch.kind === "int" ||
(ch.kind === "multipleOf" && util_1.util.isInteger(ch.value)));
}
get isFinite() {
let max = null, min = null;
for (const ch of this._def.checks) {
if (ch.kind === "finite" ||
ch.kind === "int" ||
ch.kind === "multipleOf") {
return true;
}
else if (ch.kind === "min") {
if (min === null || ch.value > min)
min = ch.value;
}
else if (ch.kind === "max") {
if (max === null || ch.value < max)
max = ch.value;
}
}
return Number.isFinite(min) && Number.isFinite(max);
} }
} }
exports.ZodNumber = ZodNumber; exports.ZodNumber = ZodNumber;
@@ -42718,13 +42761,13 @@ class ZodArray extends ZodType {
} }
} }
if (ctx.common.async) { if (ctx.common.async) {
return Promise.all(ctx.data.map((item, i) => { return Promise.all([...ctx.data].map((item, i) => {
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)); return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
})).then((result) => { })).then((result) => {
return parseUtil_1.ParseStatus.mergeArray(status, result); return parseUtil_1.ParseStatus.mergeArray(status, result);
}); });
} }
const result = ctx.data.map((item, i) => { const result = [...ctx.data].map((item, i) => {
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)); return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
}); });
return parseUtil_1.ParseStatus.mergeArray(status, result); return parseUtil_1.ParseStatus.mergeArray(status, result);
@@ -42781,15 +42824,6 @@ var objectUtil;
}; };
}; };
})(objectUtil = exports.objectUtil || (exports.objectUtil = {})); })(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
const AugmentFactory = (def) => (augmentation) => {
return new ZodObject({
...def,
shape: () => ({
...def.shape(),
...augmentation,
}),
});
};
function deepPartialify(schema) { function deepPartialify(schema) {
if (schema instanceof ZodObject) { if (schema instanceof ZodObject) {
const newShape = {}; const newShape = {};
@@ -42827,8 +42861,43 @@ class ZodObject extends ZodType {
* If you want to pass through unknown properties, use `.passthrough()` instead. * If you want to pass through unknown properties, use `.passthrough()` instead.
*/ */
this.nonstrict = this.passthrough; this.nonstrict = this.passthrough;
this.augment = AugmentFactory(this._def); // extend<
this.extend = AugmentFactory(this._def); // 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;
} }
_getCached() { _getCached() {
if (this._cached !== null) if (this._cached !== null)
@@ -42966,8 +43035,31 @@ class ZodObject extends ZodType {
unknownKeys: "passthrough", unknownKeys: "passthrough",
}); });
} }
setKey(key, schema) { // const AugmentFactory =
return this.augment({ [key]: schema }); // <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) {
return new ZodObject({
...this._def,
shape: () => ({
...this._def.shape(),
...augmentation,
}),
});
} }
/** /**
* Prior to zod@1.0.12 there was a bug in the * Prior to zod@1.0.12 there was a bug in the
@@ -42975,10 +43067,6 @@ class ZodObject extends ZodType {
* upgrade if you are experiencing issues. * upgrade if you are experiencing issues.
*/ */
merge(merging) { merge(merging) {
// const mergedShape = objectUtil.mergeShapes(
// this._def.shape(),
// merging._def.shape()
// );
const merged = new ZodObject({ const merged = new ZodObject({
unknownKeys: merging._def.unknownKeys, unknownKeys: merging._def.unknownKeys,
catchall: merging._def.catchall, catchall: merging._def.catchall,
@@ -42987,6 +43075,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) {
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,
@@ -42995,10 +43142,10 @@ class ZodObject extends ZodType {
} }
pick(mask) { pick(mask) {
const shape = {}; const shape = {};
util_1.util.objectKeys(mask).map((key) => { util_1.util.objectKeys(mask).forEach((key) => {
// only add to shape if key corresponds to an element of the current shape if (mask[key] && this.shape[key]) {
if (this.shape[key])
shape[key] = this.shape[key]; shape[key] = this.shape[key];
}
}); });
return new ZodObject({ return new ZodObject({
...this._def, ...this._def,
@@ -43007,8 +43154,8 @@ class ZodObject extends ZodType {
} }
omit(mask) { omit(mask) {
const shape = {}; const shape = {};
util_1.util.objectKeys(this.shape).map((key) => { util_1.util.objectKeys(this.shape).forEach((key) => {
if (util_1.util.objectKeys(mask).indexOf(key) === -1) { if (!mask[key]) {
shape[key] = this.shape[key]; shape[key] = this.shape[key];
} }
}); });
@@ -43022,26 +43169,15 @@ class ZodObject extends ZodType {
} }
partial(mask) { partial(mask) {
const newShape = {}; const newShape = {};
if (mask) { util_1.util.objectKeys(this.shape).forEach((key) => {
util_1.util.objectKeys(this.shape).map((key) => { const fieldSchema = this.shape[key];
if (util_1.util.objectKeys(mask).indexOf(key) === -1) { if (mask && !mask[key]) {
newShape[key] = this.shape[key]; newShape[key] = fieldSchema;
} }
else { else {
newShape[key] = this.shape[key].optional();
}
});
return new ZodObject({
...this._def,
shape: () => newShape,
});
}
else {
for (const key in this.shape) {
const fieldSchema = this.shape[key];
newShape[key] = fieldSchema.optional(); newShape[key] = fieldSchema.optional();
} }
} });
return new ZodObject({ return new ZodObject({
...this._def, ...this._def,
shape: () => newShape, shape: () => newShape,
@@ -43049,23 +43185,11 @@ class ZodObject extends ZodType {
} }
required(mask) { required(mask) {
const newShape = {}; const newShape = {};
if (mask) { util_1.util.objectKeys(this.shape).forEach((key) => {
util_1.util.objectKeys(this.shape).map((key) => { if (mask && !mask[key]) {
if (util_1.util.objectKeys(mask).indexOf(key) === -1) { newShape[key] = this.shape[key];
newShape[key] = this.shape[key]; }
} else {
else {
const fieldSchema = this.shape[key];
let newField = fieldSchema;
while (newField instanceof ZodOptional) {
newField = newField._def.innerType;
}
newShape[key] = newField;
}
});
}
else {
for (const key in this.shape) {
const fieldSchema = this.shape[key]; const fieldSchema = this.shape[key];
let newField = fieldSchema; let newField = fieldSchema;
while (newField instanceof ZodOptional) { while (newField instanceof ZodOptional) {
@@ -43073,7 +43197,7 @@ class ZodObject extends ZodType {
} }
newShape[key] = newField; newShape[key] = newField;
} }
} });
return new ZodObject({ return new ZodObject({
...this._def, ...this._def,
shape: () => newShape, shape: () => newShape,
@@ -43458,7 +43582,7 @@ class ZodTuple extends ZodType {
}); });
status.dirty(); status.dirty();
} }
const items = ctx.data const items = [...ctx.data]
.map((item, itemIndex) => { .map((item, itemIndex) => {
const schema = this._def.items[itemIndex] || this._def.rest; const schema = this._def.items[itemIndex] || this._def.rest;
if (!schema) if (!schema)
@@ -43844,6 +43968,7 @@ class ZodLiteral extends ZodType {
if (input.data !== this._def.value) { if (input.data !== this._def.value) {
const ctx = this._getOrReturnCtx(input); const ctx = this._getOrReturnCtx(input);
(0, parseUtil_1.addIssueToContext)(ctx, { (0, parseUtil_1.addIssueToContext)(ctx, {
received: ctx.data,
code: ZodError_1.ZodIssueCode.invalid_literal, code: ZodError_1.ZodIssueCode.invalid_literal,
expected: this._def.value, expected: this._def.value,
}); });
@@ -43918,6 +44043,12 @@ class ZodEnum extends ZodType {
} }
return enumValues; return enumValues;
} }
extract(values) {
return ZodEnum.create(values);
}
exclude(values) {
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
}
} }
exports.ZodEnum = ZodEnum; exports.ZodEnum = ZodEnum;
ZodEnum.create = createZodEnum; ZodEnum.create = createZodEnum;
@@ -43959,6 +44090,9 @@ ZodNativeEnum.create = (values, params) => {
}); });
}; };
class ZodPromise extends ZodType { class ZodPromise extends ZodType {
unwrap() {
return this._def.type;
}
_parse(input) { _parse(input) {
const { ctx } = this._processInputParams(input); const { ctx } = this._processInputParams(input);
if (ctx.parsedType !== util_1.ZodParsedType.promise && if (ctx.parsedType !== util_1.ZodParsedType.promise &&
@@ -44204,24 +44338,30 @@ class ZodCatch extends ZodType {
const result = this._def.innerType._parse({ const result = this._def.innerType._parse({
data: ctx.data, data: ctx.data,
path: ctx.path, path: ctx.path,
parent: ctx, parent: {
...ctx,
common: {
...ctx.common,
issues: [], // don't collect issues from inner type
},
},
}); });
if ((0, parseUtil_1.isAsync)(result)) { if ((0, parseUtil_1.isAsync)(result)) {
return result.then((result) => { return result.then((result) => {
return { return {
status: "valid", status: "valid",
value: result.status === "valid" ? result.value : this._def.defaultValue(), value: result.status === "valid" ? result.value : this._def.catchValue(),
}; };
}); });
} }
else { else {
return { return {
status: "valid", status: "valid",
value: result.status === "valid" ? result.value : this._def.defaultValue(), value: result.status === "valid" ? result.value : this._def.catchValue(),
}; };
} }
} }
removeDefault() { removeCatch() {
return this._def.innerType; return this._def.innerType;
} }
} }
@@ -44230,9 +44370,7 @@ ZodCatch.create = (type, params) => {
return new ZodCatch({ return new ZodCatch({
innerType: type, innerType: type,
typeName: ZodFirstPartyTypeKind.ZodCatch, typeName: ZodFirstPartyTypeKind.ZodCatch,
defaultValue: typeof params.default === "function" catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
? params.default
: () => params.default,
...processCreateParams(params), ...processCreateParams(params),
}); });
}; };
@@ -44475,7 +44613,10 @@ exports.oboolean = oboolean;
exports.coerce = { exports.coerce = {
string: ((arg) => ZodString.create({ ...arg, coerce: true })), string: ((arg) => ZodString.create({ ...arg, coerce: true })),
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })), number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
boolean: ((arg) => ZodBoolean.create({ ...arg, coerce: true })), boolean: ((arg) => ZodBoolean.create({
...arg,
coerce: true,
})),
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })), bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
date: ((arg) => ZodDate.create({ ...arg, coerce: true })), date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
}; };
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long