Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 605a14dcda |
+226
-85
@@ -41154,7 +41154,7 @@ const isDirty = (x) => x.status === "dirty";
|
||||
exports.isDirty = isDirty;
|
||||
const isValid = (x) => x.status === "valid";
|
||||
exports.isValid = isValid;
|
||||
const isAsync = (x) => typeof Promise !== undefined && x instanceof Promise;
|
||||
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
||||
exports.isAsync = isAsync;
|
||||
|
||||
|
||||
@@ -41707,28 +41707,29 @@ class ZodType {
|
||||
return this._refinement(refinement);
|
||||
}
|
||||
optional() {
|
||||
return ZodOptional.create(this);
|
||||
return ZodOptional.create(this, this._def);
|
||||
}
|
||||
nullable() {
|
||||
return ZodNullable.create(this);
|
||||
return ZodNullable.create(this, this._def);
|
||||
}
|
||||
nullish() {
|
||||
return this.optional().nullable();
|
||||
return this.nullable().optional();
|
||||
}
|
||||
array() {
|
||||
return ZodArray.create(this);
|
||||
return ZodArray.create(this, this._def);
|
||||
}
|
||||
promise() {
|
||||
return ZodPromise.create(this);
|
||||
return ZodPromise.create(this, this._def);
|
||||
}
|
||||
or(option) {
|
||||
return ZodUnion.create([this, option]);
|
||||
return ZodUnion.create([this, option], this._def);
|
||||
}
|
||||
and(incoming) {
|
||||
return ZodIntersection.create(this, incoming);
|
||||
return ZodIntersection.create(this, incoming, this._def);
|
||||
}
|
||||
transform(transform) {
|
||||
return new ZodEffects({
|
||||
...processCreateParams(this._def),
|
||||
schema: this,
|
||||
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
||||
effect: { type: "transform", transform },
|
||||
@@ -41737,6 +41738,7 @@ class ZodType {
|
||||
default(def) {
|
||||
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
||||
return new ZodDefault({
|
||||
...processCreateParams(this._def),
|
||||
innerType: this,
|
||||
defaultValue: defaultValueFunc,
|
||||
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
||||
@@ -41746,14 +41748,15 @@ class ZodType {
|
||||
return new ZodBranded({
|
||||
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
||||
type: this,
|
||||
...processCreateParams(undefined),
|
||||
...processCreateParams(this._def),
|
||||
});
|
||||
}
|
||||
catch(def) {
|
||||
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
||||
const catchValueFunc = typeof def === "function" ? def : () => def;
|
||||
return new ZodCatch({
|
||||
...processCreateParams(this._def),
|
||||
innerType: this,
|
||||
defaultValue: defaultValueFunc,
|
||||
catchValue: catchValueFunc,
|
||||
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
||||
});
|
||||
}
|
||||
@@ -41778,12 +41781,15 @@ exports.ZodType = ZodType;
|
||||
exports.Schema = ZodType;
|
||||
exports.ZodSchema = ZodType;
|
||||
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;
|
||||
// from https://stackoverflow.com/a/46181/1550155
|
||||
// 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@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\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 {
|
||||
/**
|
||||
* Match any configuration
|
||||
@@ -41794,7 +41800,7 @@ const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\")
|
||||
const datetimeRegex = (args) => {
|
||||
if (args.precision) {
|
||||
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 {
|
||||
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) {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
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") {
|
||||
try {
|
||||
new URL(input.data);
|
||||
@@ -42031,6 +42048,9 @@ class ZodString extends ZodType {
|
||||
cuid(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) {
|
||||
var _a;
|
||||
if (typeof options === "string") {
|
||||
@@ -42105,6 +42125,9 @@ class ZodString extends ZodType {
|
||||
get isCUID() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
||||
}
|
||||
get isCUID2() {
|
||||
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
||||
}
|
||||
get minLength() {
|
||||
let min = null;
|
||||
for (const ch of this._def.checks) {
|
||||
@@ -42346,7 +42369,27 @@ class ZodNumber extends ZodType {
|
||||
return max;
|
||||
}
|
||||
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;
|
||||
@@ -42718,13 +42761,13 @@ class ZodArray extends ZodType {
|
||||
}
|
||||
}
|
||||
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));
|
||||
})).then((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 parseUtil_1.ParseStatus.mergeArray(status, result);
|
||||
@@ -42781,15 +42824,6 @@ var objectUtil;
|
||||
};
|
||||
};
|
||||
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
||||
const AugmentFactory = (def) => (augmentation) => {
|
||||
return new ZodObject({
|
||||
...def,
|
||||
shape: () => ({
|
||||
...def.shape(),
|
||||
...augmentation,
|
||||
}),
|
||||
});
|
||||
};
|
||||
function deepPartialify(schema) {
|
||||
if (schema instanceof ZodObject) {
|
||||
const newShape = {};
|
||||
@@ -42827,8 +42861,43 @@ class ZodObject extends ZodType {
|
||||
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
||||
*/
|
||||
this.nonstrict = this.passthrough;
|
||||
this.augment = AugmentFactory(this._def);
|
||||
this.extend = AugmentFactory(this._def);
|
||||
// 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;
|
||||
}
|
||||
_getCached() {
|
||||
if (this._cached !== null)
|
||||
@@ -42966,8 +43035,31 @@ class ZodObject extends ZodType {
|
||||
unknownKeys: "passthrough",
|
||||
});
|
||||
}
|
||||
setKey(key, schema) {
|
||||
return this.augment({ [key]: schema });
|
||||
// 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) {
|
||||
return new ZodObject({
|
||||
...this._def,
|
||||
shape: () => ({
|
||||
...this._def.shape(),
|
||||
...augmentation,
|
||||
}),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
merge(merging) {
|
||||
// const mergedShape = objectUtil.mergeShapes(
|
||||
// this._def.shape(),
|
||||
// merging._def.shape()
|
||||
// );
|
||||
const merged = new ZodObject({
|
||||
unknownKeys: merging._def.unknownKeys,
|
||||
catchall: merging._def.catchall,
|
||||
@@ -42987,6 +43075,65 @@ class ZodObject extends ZodType {
|
||||
});
|
||||
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) {
|
||||
return new ZodObject({
|
||||
...this._def,
|
||||
@@ -42995,10 +43142,10 @@ class ZodObject extends ZodType {
|
||||
}
|
||||
pick(mask) {
|
||||
const shape = {};
|
||||
util_1.util.objectKeys(mask).map((key) => {
|
||||
// only add to shape if key corresponds to an element of the current shape
|
||||
if (this.shape[key])
|
||||
util_1.util.objectKeys(mask).forEach((key) => {
|
||||
if (mask[key] && this.shape[key]) {
|
||||
shape[key] = this.shape[key];
|
||||
}
|
||||
});
|
||||
return new ZodObject({
|
||||
...this._def,
|
||||
@@ -43007,8 +43154,8 @@ class ZodObject extends ZodType {
|
||||
}
|
||||
omit(mask) {
|
||||
const shape = {};
|
||||
util_1.util.objectKeys(this.shape).map((key) => {
|
||||
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
||||
util_1.util.objectKeys(this.shape).forEach((key) => {
|
||||
if (!mask[key]) {
|
||||
shape[key] = this.shape[key];
|
||||
}
|
||||
});
|
||||
@@ -43022,26 +43169,15 @@ class ZodObject extends ZodType {
|
||||
}
|
||||
partial(mask) {
|
||||
const newShape = {};
|
||||
if (mask) {
|
||||
util_1.util.objectKeys(this.shape).map((key) => {
|
||||
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
||||
newShape[key] = this.shape[key];
|
||||
}
|
||||
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];
|
||||
util_1.util.objectKeys(this.shape).forEach((key) => {
|
||||
const fieldSchema = this.shape[key];
|
||||
if (mask && !mask[key]) {
|
||||
newShape[key] = fieldSchema;
|
||||
}
|
||||
else {
|
||||
newShape[key] = fieldSchema.optional();
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ZodObject({
|
||||
...this._def,
|
||||
shape: () => newShape,
|
||||
@@ -43049,23 +43185,11 @@ class ZodObject extends ZodType {
|
||||
}
|
||||
required(mask) {
|
||||
const newShape = {};
|
||||
if (mask) {
|
||||
util_1.util.objectKeys(this.shape).map((key) => {
|
||||
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
||||
newShape[key] = this.shape[key];
|
||||
}
|
||||
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) {
|
||||
util_1.util.objectKeys(this.shape).forEach((key) => {
|
||||
if (mask && !mask[key]) {
|
||||
newShape[key] = this.shape[key];
|
||||
}
|
||||
else {
|
||||
const fieldSchema = this.shape[key];
|
||||
let newField = fieldSchema;
|
||||
while (newField instanceof ZodOptional) {
|
||||
@@ -43073,7 +43197,7 @@ class ZodObject extends ZodType {
|
||||
}
|
||||
newShape[key] = newField;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new ZodObject({
|
||||
...this._def,
|
||||
shape: () => newShape,
|
||||
@@ -43458,7 +43582,7 @@ class ZodTuple extends ZodType {
|
||||
});
|
||||
status.dirty();
|
||||
}
|
||||
const items = ctx.data
|
||||
const items = [...ctx.data]
|
||||
.map((item, itemIndex) => {
|
||||
const schema = this._def.items[itemIndex] || this._def.rest;
|
||||
if (!schema)
|
||||
@@ -43844,6 +43968,7 @@ class ZodLiteral extends ZodType {
|
||||
if (input.data !== this._def.value) {
|
||||
const ctx = this._getOrReturnCtx(input);
|
||||
(0, parseUtil_1.addIssueToContext)(ctx, {
|
||||
received: ctx.data,
|
||||
code: ZodError_1.ZodIssueCode.invalid_literal,
|
||||
expected: this._def.value,
|
||||
});
|
||||
@@ -43918,6 +44043,12 @@ class ZodEnum extends ZodType {
|
||||
}
|
||||
return enumValues;
|
||||
}
|
||||
extract(values) {
|
||||
return ZodEnum.create(values);
|
||||
}
|
||||
exclude(values) {
|
||||
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
|
||||
}
|
||||
}
|
||||
exports.ZodEnum = ZodEnum;
|
||||
ZodEnum.create = createZodEnum;
|
||||
@@ -43959,6 +44090,9 @@ ZodNativeEnum.create = (values, params) => {
|
||||
});
|
||||
};
|
||||
class ZodPromise extends ZodType {
|
||||
unwrap() {
|
||||
return this._def.type;
|
||||
}
|
||||
_parse(input) {
|
||||
const { ctx } = this._processInputParams(input);
|
||||
if (ctx.parsedType !== util_1.ZodParsedType.promise &&
|
||||
@@ -44204,24 +44338,30 @@ class ZodCatch extends ZodType {
|
||||
const result = this._def.innerType._parse({
|
||||
data: ctx.data,
|
||||
path: ctx.path,
|
||||
parent: ctx,
|
||||
parent: {
|
||||
...ctx,
|
||||
common: {
|
||||
...ctx.common,
|
||||
issues: [], // don't collect issues from inner type
|
||||
},
|
||||
},
|
||||
});
|
||||
if ((0, parseUtil_1.isAsync)(result)) {
|
||||
return result.then((result) => {
|
||||
return {
|
||||
status: "valid",
|
||||
value: result.status === "valid" ? result.value : this._def.defaultValue(),
|
||||
value: result.status === "valid" ? result.value : this._def.catchValue(),
|
||||
};
|
||||
});
|
||||
}
|
||||
else {
|
||||
return {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -44230,9 +44370,7 @@ ZodCatch.create = (type, params) => {
|
||||
return new ZodCatch({
|
||||
innerType: type,
|
||||
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
||||
defaultValue: typeof params.default === "function"
|
||||
? params.default
|
||||
: () => params.default,
|
||||
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
||||
...processCreateParams(params),
|
||||
});
|
||||
};
|
||||
@@ -44475,7 +44613,10 @@ exports.oboolean = oboolean;
|
||||
exports.coerce = {
|
||||
string: ((arg) => ZodString.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 })),
|
||||
date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
|
||||
};
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user