Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
@@ -9,3 +9,9 @@ import * as z from './index'; | ||
k2: z.ZodNumber; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
k1: string; | ||
k2: number; | ||
}, { | ||
k1: string; | ||
k2: number; | ||
}>; | ||
union: import("./types/array").ZodNonEmptyArray<z.ZodUnion<[z.ZodLiteral<"asdf">, z.ZodLiteral<12>]>>; | ||
@@ -17,12 +23,66 @@ array: z.ZodArray<z.ZodNumber>; | ||
p1: z.ZodOptional<z.ZodString>; | ||
}, "passthrough", z.ZodTypeAny>, z.ZodObject<{ | ||
}, "passthrough", z.ZodTypeAny, { | ||
p1?: string | undefined; | ||
}, { | ||
p1?: string | undefined; | ||
}>, z.ZodObject<{ | ||
p1: z.ZodOptional<z.ZodNumber>; | ||
}, "passthrough", z.ZodTypeAny>>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
p1?: number | undefined; | ||
}, { | ||
p1?: number | undefined; | ||
}>>; | ||
enum: z.ZodIntersection<z.ZodEnum<["zero", "one"]>, z.ZodEnum<["one", "two"]>>; | ||
nonstrict: z.ZodObject<{ | ||
points: z.ZodNumber; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
points: number; | ||
}, { | ||
points: number; | ||
}>; | ||
numProm: z.ZodPromise<z.ZodNumber>; | ||
lenfun: z.ZodFunction<z.ZodTuple<[z.ZodString]>, z.ZodBoolean>; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
array: number[]; | ||
nonstrict: { | ||
points: number; | ||
}; | ||
tuple: [string | null | undefined, number | null | undefined, boolean | null | undefined, null | undefined, null | undefined, "1234" | null | undefined]; | ||
merged: { | ||
k1: string; | ||
k2: number; | ||
}; | ||
union: ["asdf" | 12, ...("asdf" | 12)[]]; | ||
sumTransformer: number; | ||
sumMinLength: number[]; | ||
intersection: { | ||
p1?: string | undefined; | ||
} & { | ||
p1?: number | undefined; | ||
}; | ||
enum: "one"; | ||
numProm: Promise<number>; | ||
lenfun: (args_0: string) => boolean; | ||
}, { | ||
array: number[]; | ||
nonstrict: { | ||
points: number; | ||
}; | ||
tuple: [string | null | undefined, number | null | undefined, boolean | null | undefined, null | undefined, null | undefined, "1234" | null | undefined]; | ||
merged: { | ||
k1: string; | ||
k2: number; | ||
}; | ||
union: ["asdf" | 12, ...("asdf" | 12)[]]; | ||
sumTransformer: number[]; | ||
sumMinLength: number[]; | ||
intersection: { | ||
p1?: string | undefined; | ||
} & { | ||
p1?: number | undefined; | ||
}; | ||
enum: "one"; | ||
numProm: Promise<number>; | ||
lenfun: (args_0: string) => boolean; | ||
}>; | ||
export declare const asyncCrazySchema: z.ZodObject<{ | ||
@@ -32,3 +92,7 @@ array: z.ZodArray<z.ZodNumber>; | ||
points: z.ZodNumber; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
points: number; | ||
}, { | ||
points: number; | ||
}>; | ||
tuple: z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodOptional<z.ZodNullable<z.ZodNull>>, z.ZodOptional<z.ZodNullable<z.ZodUndefined>>, z.ZodOptional<z.ZodNullable<z.ZodLiteral<"1234">>>]>; | ||
@@ -40,3 +104,9 @@ merged: z.ZodObject<{ | ||
k2: z.ZodNumber; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
k1: string; | ||
k2: number; | ||
}, { | ||
k1: string; | ||
k2: number; | ||
}>; | ||
union: import("./types/array").ZodNonEmptyArray<z.ZodUnion<[z.ZodLiteral<"asdf">, z.ZodLiteral<12>]>>; | ||
@@ -47,5 +117,13 @@ sumTransformer: z.ZodTransformer<z.ZodArray<z.ZodNumber>, z.ZodNumber>; | ||
p1: z.ZodOptional<z.ZodString>; | ||
}, "passthrough", z.ZodTypeAny>, z.ZodObject<{ | ||
}, "passthrough", z.ZodTypeAny, { | ||
p1?: string | undefined; | ||
}, { | ||
p1?: string | undefined; | ||
}>, z.ZodObject<{ | ||
p1: z.ZodOptional<z.ZodNumber>; | ||
}, "passthrough", z.ZodTypeAny>>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
p1?: number | undefined; | ||
}, { | ||
p1?: number | undefined; | ||
}>>; | ||
enum: z.ZodIntersection<z.ZodEnum<["zero", "one"]>, z.ZodEnum<["one", "two"]>>; | ||
@@ -57,2 +135,48 @@ numProm: z.ZodPromise<z.ZodNumber>; | ||
async_refine: z.ZodArray<z.ZodNumber>; | ||
}, "passthrough", z.ZodTypeAny>; | ||
}, "passthrough", z.ZodTypeAny, { | ||
array: number[]; | ||
nonstrict: { | ||
points: number; | ||
}; | ||
tuple: [string | null | undefined, number | null | undefined, boolean | null | undefined, null | undefined, null | undefined, "1234" | null | undefined]; | ||
merged: { | ||
k1: string; | ||
k2: number; | ||
}; | ||
union: ["asdf" | 12, ...("asdf" | 12)[]]; | ||
sumTransformer: number; | ||
sumMinLength: number[]; | ||
intersection: { | ||
p1?: string | undefined; | ||
} & { | ||
p1?: number | undefined; | ||
}; | ||
enum: "one"; | ||
numProm: Promise<number>; | ||
lenfun: (args_0: string) => boolean; | ||
async_transform: number; | ||
async_refine: number[]; | ||
}, { | ||
array: number[]; | ||
nonstrict: { | ||
points: number; | ||
}; | ||
tuple: [string | null | undefined, number | null | undefined, boolean | null | undefined, null | undefined, null | undefined, "1234" | null | undefined]; | ||
merged: { | ||
k1: string; | ||
k2: number; | ||
}; | ||
union: ["asdf" | 12, ...("asdf" | 12)[]]; | ||
sumTransformer: number[]; | ||
sumMinLength: number[]; | ||
intersection: { | ||
p1?: string | undefined; | ||
} & { | ||
p1?: number | undefined; | ||
}; | ||
enum: "one"; | ||
numProm: Promise<number>; | ||
lenfun: (args_0: string) => boolean; | ||
async_transform: number[]; | ||
async_refine: number[]; | ||
}>; |
@@ -1,2 +0,2 @@ | ||
import { ZodSuberrorOptionalMessage } from './ZodError'; | ||
import { ZodIssueOptionalMessage } from './ZodError'; | ||
declare type ErrorMapCtx = { | ||
@@ -7,5 +7,5 @@ defaultError: string; | ||
export declare type ZodErrorMap = typeof defaultErrorMap; | ||
export declare const defaultErrorMap: (error: ZodSuberrorOptionalMessage, _ctx: ErrorMapCtx) => { | ||
export declare const defaultErrorMap: (error: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => { | ||
message: string; | ||
}; | ||
export {}; |
@@ -8,3 +8,3 @@ "use strict"; | ||
switch (error.code) { | ||
case ZodError_1.ZodErrorCode.invalid_type: | ||
case ZodError_1.ZodIssueCode.invalid_type: | ||
if (error.received === 'undefined') { | ||
@@ -17,38 +17,40 @@ message = 'Required'; | ||
break; | ||
case ZodError_1.ZodErrorCode.nonempty_array_is_empty: | ||
case ZodError_1.ZodIssueCode.nonempty_array_is_empty: | ||
message = "List must contain at least one item"; | ||
break; | ||
case ZodError_1.ZodErrorCode.unrecognized_keys: | ||
message = "Unrecognized key(s) in object: " + error.keys.map(function (k) { return "'" + k + "'"; }).join(', '); | ||
case ZodError_1.ZodIssueCode.unrecognized_keys: | ||
message = "Unrecognized key(s) in object: " + error.keys | ||
.map(function (k) { return "'" + k + "'"; }) | ||
.join(', '); | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_union: | ||
case ZodError_1.ZodIssueCode.invalid_union: | ||
message = "Invalid input"; | ||
break; | ||
// case ZodErrorCode.invalid_tuple_length: | ||
// case ZodIssueCode.invalid_tuple_length: | ||
// message = `Expected list of ${error.expected} items, received ${error.received} items`; | ||
// break; | ||
case ZodError_1.ZodErrorCode.invalid_literal_value: | ||
case ZodError_1.ZodIssueCode.invalid_literal_value: | ||
message = "Input must be \"" + error.expected + "\""; | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_enum_value: | ||
case ZodError_1.ZodIssueCode.invalid_enum_value: | ||
message = "Input must be one of these values: " + error.options.join(', '); | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_arguments: | ||
case ZodError_1.ZodIssueCode.invalid_arguments: | ||
message = "Invalid function arguments"; | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_return_type: | ||
case ZodError_1.ZodIssueCode.invalid_return_type: | ||
message = "Invalid function return type"; | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_date: | ||
case ZodError_1.ZodIssueCode.invalid_date: | ||
message = "Invalid date"; | ||
break; | ||
// case ZodErrorCode.too_small: | ||
// case ZodIssueCode.too_small: | ||
// const tooShortNoun = _ctx.data === 'string' ? 'characters' : 'items'; | ||
// message = `Too short, should be at least ${error.minimum} ${tooShortNoun}`; | ||
// break; | ||
// case ZodErrorCode.too_big: | ||
// case ZodIssueCode.too_big: | ||
// const tooLongNoun = _ctx.data === 'string' ? 'characters' : 'items'; | ||
// message = `Too short, should be at most ${error.maximum} ${tooLongNoun}`; | ||
// break; | ||
case ZodError_1.ZodErrorCode.invalid_string: | ||
case ZodError_1.ZodIssueCode.invalid_string: | ||
if (error.validation !== 'regex') | ||
@@ -59,9 +61,9 @@ message = "Invalid " + error.validation; | ||
break; | ||
// case ZodErrorCode.invalid_url: | ||
// case ZodIssueCode.invalid_url: | ||
// message = 'Invalid URL.'; | ||
// break; | ||
// case ZodErrorCode.invalid_uuid: | ||
// case ZodIssueCode.invalid_uuid: | ||
// message = 'Invalid UUID.'; | ||
// break; | ||
case ZodError_1.ZodErrorCode.too_small: | ||
case ZodError_1.ZodIssueCode.too_small: | ||
if (error.type === 'array') | ||
@@ -76,3 +78,3 @@ message = "Should have " + (error.inclusive ? "at least" : "more than") + " " + error.minimum + " items"; | ||
break; | ||
case ZodError_1.ZodErrorCode.too_big: | ||
case ZodError_1.ZodIssueCode.too_big: | ||
if (error.type === 'array') | ||
@@ -87,6 +89,6 @@ message = "Should have " + (error.inclusive ? "at most" : "less than") + " " + error.maximum + " items"; | ||
break; | ||
case ZodError_1.ZodErrorCode.custom_error: | ||
case ZodError_1.ZodIssueCode.custom: | ||
message = "Invalid input."; | ||
break; | ||
case ZodError_1.ZodErrorCode.invalid_intersection_types: | ||
case ZodError_1.ZodIssueCode.invalid_intersection_types: | ||
message = "Intersections only support objects"; | ||
@@ -93,0 +95,0 @@ break; |
@@ -27,4 +27,4 @@ import { ZodRawShape } from '../types/base'; | ||
export const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U; | ||
export const mergeObjects: <First extends AnyZodObject>(first: First) => <Second extends AnyZodObject>(second: Second) => ZodObject<First["_shape"] & Second["_shape"], First["_unknownKeys"], First["_catchall"]>; | ||
export const mergeObjects: <First extends AnyZodObject>(first: First) => <Second extends AnyZodObject>(second: Second) => ZodObject<First["_shape"] & Second["_shape"], First["_unknownKeys"], First["_catchall"], import("../types/object").objectOutputType<First["_shape"] & Second["_shape"], First["_catchall"]>, import("../types/object").objectInputType<First["_shape"] & Second["_shape"], First["_catchall"]>>; | ||
export {}; | ||
} |
export declare type Primitive = string | number | bigint | boolean | null | undefined; | ||
export declare type Scalars = Primitive | Primitive[]; |
@@ -45,3 +45,3 @@ import { ZodString, ZodStringDef } from './types/string'; | ||
declare const arrayType: <T extends ZodTypeAny>(schema: T) => ZodArray<T>; | ||
declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<T, "passthrough", ZodTypeAny>; | ||
declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<T, "passthrough", ZodTypeAny, { [k_1 in keyof import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k in keyof T]: T[k]["_output"]; }>]: import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k in keyof T]: T[k]["_output"]; }>[k_1]; }, { [k_3 in keyof import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k_2 in keyof T]: T[k_2]["_input"]; }>]: import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k_2 in keyof T]: T[k_2]["_input"]; }>[k_3]; }>; | ||
declare const unionType: <T extends [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(types: T) => ZodUnion<T>; | ||
@@ -67,7 +67,7 @@ declare const intersectionType: <T extends ZodTypeAny, U extends ZodTypeAny>(left: T, right: U) => ZodIntersection<T, U>; | ||
declare const codegen: () => ZodCodeGenerator; | ||
export declare const custom: <T>(check: (data: unknown) => any, params?: string | Partial<Pick<import("./ZodError").ZodCustomError, "path" | "message" | "params">> | ((arg: any) => Partial<Pick<import("./ZodError").ZodCustomError, "path" | "message" | "params">>) | undefined) => ZodType<T, ZodTypeDef, T>; | ||
declare const instanceOfType: <T extends new (...args: any[]) => any>(cls: T, params?: string | Partial<Pick<import("./ZodError").ZodCustomError, "path" | "message" | "params">> | ((arg: any) => Partial<Pick<import("./ZodError").ZodCustomError, "path" | "message" | "params">>) | undefined) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>; | ||
export declare const custom: <T>(check: (data: unknown) => any, params?: string | Partial<Pick<import("./ZodError").ZodCustomIssue, "path" | "message" | "params">> | ((arg: any) => Partial<Pick<import("./ZodError").ZodCustomIssue, "path" | "message" | "params">>) | undefined) => ZodType<T, ZodTypeDef, T>; | ||
declare const instanceOfType: <T extends new (...args: any[]) => any>(cls: T, params?: string | Partial<Pick<import("./ZodError").ZodCustomIssue, "path" | "message" | "params">> | ((arg: any) => Partial<Pick<import("./ZodError").ZodCustomIssue, "path" | "message" | "params">>) | undefined) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>; | ||
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, neverType as never, voidType as void, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, nativeEnumType as nativeEnum, promiseType as promise, instanceOfType as instanceof, transformerType as transformer, optionalType as optional, nullableType as nullable, ostring, onumber, oboolean, codegen, }; | ||
export declare const late: { | ||
object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, "passthrough", ZodTypeAny>; | ||
object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, "passthrough", ZodTypeAny, { [k_1 in keyof import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k in keyof T]: T[k]["_output"]; }>]: import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k in keyof T]: T[k]["_output"]; }>[k_1]; }, { [k_3 in keyof import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k_2 in keyof T]: T[k_2]["_input"]; }>]: import("./helpers/objectUtil").objectUtil.addQuestionMarks<{ [k_2 in keyof T]: T[k_2]["_input"]; }>[k_3]; }>; | ||
}; | ||
@@ -74,0 +74,0 @@ export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodNativeEnum, ZodPromise, ZodTransformer, ZodOptional, ZodNullable, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodErrorMap, ZodParsedType, ZodCodeGenerator, }; |
@@ -64,3 +64,3 @@ "use strict"; | ||
exports.ZodTypes = base_1.ZodTypes; | ||
// import { ZodError, ZodErrorCode } from './ZodError'; | ||
// import { ZodError, ZodIssueCode } from './ZodError'; | ||
var parser_1 = require("./parser"); | ||
@@ -67,0 +67,0 @@ exports.ZodParsedType = parser_1.ZodParsedType; |
@@ -62,3 +62,3 @@ "use strict"; | ||
case z.ZodTypes.tuple: | ||
returnValue = false; | ||
returnValue = def.items.every(function (x) { return exports.isScalar(x, { root: false }); }); | ||
break; | ||
@@ -65,0 +65,0 @@ case z.ZodTypes.lazy: |
import * as z from './types/base'; | ||
import { ZodError, ZodSuberrorOptionalMessage } from './ZodError'; | ||
import { ZodError, ZodIssueOptionalMessage } from './ZodError'; | ||
import { util } from './helpers/util'; | ||
@@ -27,3 +27,3 @@ import { ZodErrorMap } from './defaultErrorMap'; | ||
declare type stripPath<T extends object> = T extends any ? util.OmitKeys<T, 'path'> : never; | ||
export declare type MakeErrorData = stripPath<ZodSuberrorOptionalMessage> & { | ||
export declare type MakeErrorData = stripPath<ZodIssueOptionalMessage> & { | ||
path?: (string | number)[]; | ||
@@ -30,0 +30,0 @@ }; |
@@ -185,4 +185,4 @@ "use strict"; | ||
if (parsedType !== exports.ZodParsedType.string) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.string, | ||
@@ -198,4 +198,4 @@ received: parsedType, | ||
if (parsedType !== exports.ZodParsedType.number) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.number, | ||
@@ -208,4 +208,4 @@ received: parsedType, | ||
if (Number.isNaN(data)) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.number, | ||
@@ -221,4 +221,4 @@ received: exports.ZodParsedType.nan, | ||
if (parsedType !== exports.ZodParsedType.bigint) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.number, | ||
@@ -234,4 +234,4 @@ received: parsedType, | ||
if (parsedType !== exports.ZodParsedType.boolean) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.boolean, | ||
@@ -247,4 +247,4 @@ received: parsedType, | ||
if (parsedType !== exports.ZodParsedType.undefined) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.undefined, | ||
@@ -260,4 +260,4 @@ received: parsedType, | ||
if (parsedType !== exports.ZodParsedType.null) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.null, | ||
@@ -278,4 +278,4 @@ received: parsedType, | ||
case z.ZodTypes.never: | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.never, | ||
@@ -289,4 +289,4 @@ received: parsedType, | ||
parsedType !== exports.ZodParsedType.null) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.void, | ||
@@ -303,4 +303,4 @@ received: parsedType, | ||
if (parsedType !== exports.ZodParsedType.array) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.array, | ||
@@ -314,3 +314,3 @@ received: parsedType, | ||
if (def.nonempty === true && data.length === 0) { | ||
ERROR.addError(makeError({ code: ZodError_1.ZodErrorCode.nonempty_array_is_empty })); | ||
ERROR.addIssue(makeError({ code: ZodError_1.ZodIssueCode.nonempty_array_is_empty })); | ||
THROW(); | ||
@@ -323,3 +323,3 @@ } | ||
// const zerr: ZodError = err; | ||
// ERROR.addErrors(zerr.errors); | ||
// ERROR.addIssues(zerr.issues); | ||
// } | ||
@@ -334,3 +334,3 @@ // }); | ||
var zerr = err; | ||
ERROR.addErrors(zerr.errors); | ||
ERROR.addIssues(zerr.issues); | ||
return PseudoPromise_1.PseudoPromise.resolve(INVALID); | ||
@@ -348,4 +348,4 @@ } | ||
if (parsedType !== exports.ZodParsedType.object) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.object, | ||
@@ -376,3 +376,3 @@ received: parsedType, | ||
var zerr = err; | ||
ERROR.addErrors(zerr.errors); | ||
ERROR.addIssues(zerr.issues); | ||
return INVALID; | ||
@@ -399,4 +399,4 @@ } | ||
if (extraKeys.length > 0) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.unrecognized_keys, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.unrecognized_keys, | ||
keys: extraKeys, | ||
@@ -446,10 +446,10 @@ })); | ||
var filteredErrors = unionErrors_1.filter(function (err) { | ||
return err.errors[0].code !== 'invalid_type'; | ||
return err.issues[0].code !== 'invalid_type'; | ||
}); | ||
if (filteredErrors.length === 1) { | ||
ERROR.addErrors(filteredErrors[0].errors); | ||
ERROR.addIssues(filteredErrors[0].issues); | ||
} | ||
else { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_union, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_union, | ||
unionErrors: unionErrors_1, | ||
@@ -474,10 +474,10 @@ })); | ||
// const filteredErrors = unionErrors.filter(err => { | ||
// return err.errors[0].code !== 'invalid_type'; | ||
// return err.issues[0].code !== 'invalid_type'; | ||
// }); | ||
// if (filteredErrors.length === 1) { | ||
// ERROR.addErrors(filteredErrors[0].errors); | ||
// ERROR.addIssues(filteredErrors[0].issues); | ||
// } else { | ||
// ERROR.addError( | ||
// ERROR.addIssue( | ||
// makeError({ | ||
// code: ZodErrorCode.invalid_union, | ||
// code: ZodIssueCode.invalid_union, | ||
// unionErrors: unionErrors, | ||
@@ -502,3 +502,3 @@ // }), | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -515,3 +515,3 @@ } | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -536,4 +536,4 @@ } | ||
else { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_intersection_types, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_intersection_types, | ||
})); | ||
@@ -554,3 +554,3 @@ } | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -573,3 +573,3 @@ } | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -583,4 +583,4 @@ } | ||
if (parsedType !== exports.ZodParsedType.array) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.array, | ||
@@ -593,4 +593,4 @@ received: parsedType, | ||
if (data.length > def.items.length) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.too_big, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.too_big, | ||
maximum: def.items.length, | ||
@@ -602,4 +602,4 @@ inclusive: true, | ||
else if (data.length < def.items.length) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.too_small, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.too_small, | ||
minimum: def.items.length, | ||
@@ -622,3 +622,3 @@ inclusive: true, | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -638,3 +638,3 @@ } | ||
// } catch (err) { | ||
// ERROR.addErrors(err.errors); | ||
// ERROR.addIssues(err.issues); | ||
// } | ||
@@ -653,4 +653,4 @@ // }), | ||
if (data !== def.value) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_literal_value, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_literal_value, | ||
expected: def.value, | ||
@@ -663,4 +663,4 @@ })); | ||
if (def.values.indexOf(data) === -1) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_enum_value, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_enum_value, | ||
options: def.values, | ||
@@ -673,4 +673,4 @@ })); | ||
if (util_1.util.getValidEnumValues(def.values).indexOf(data) === -1) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_enum_value, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_enum_value, | ||
options: util_1.util.objectValues(def.values), | ||
@@ -683,4 +683,4 @@ })); | ||
if (parsedType !== exports.ZodParsedType.function) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.function, | ||
@@ -703,4 +703,4 @@ received: parsedType, | ||
var argsError = new ZodError_1.ZodError([]); | ||
argsError.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_arguments, | ||
argsError.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_arguments, | ||
argumentsError: err, | ||
@@ -719,4 +719,4 @@ })); | ||
var returnsError = new ZodError_1.ZodError([]); | ||
returnsError.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_return_type, | ||
returnsError.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_return_type, | ||
returnTypeError: err, | ||
@@ -734,4 +734,4 @@ })); | ||
if (parsedType !== exports.ZodParsedType.object) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.object, | ||
@@ -751,3 +751,3 @@ received: parsedType, | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -767,4 +767,4 @@ } | ||
if (!(data instanceof Date)) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.date, | ||
@@ -777,4 +777,4 @@ received: parsedType, | ||
if (isNaN(data.getTime())) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_date, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_date, | ||
})); | ||
@@ -788,4 +788,4 @@ // setError(error); | ||
if (parsedType !== exports.ZodParsedType.promise && params.async !== true) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.invalid_type, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.invalid_type, | ||
expected: exports.ZodParsedType.promise, | ||
@@ -805,3 +805,3 @@ received: parsedType, | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
} | ||
@@ -830,3 +830,3 @@ throw err; | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
} | ||
@@ -848,3 +848,3 @@ throw err; | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -861,3 +861,3 @@ } | ||
if (err instanceof ZodError_1.ZodError) { | ||
ERROR.addErrors(err.errors); | ||
ERROR.addIssues(err.issues); | ||
return INVALID; | ||
@@ -881,4 +881,4 @@ } | ||
var checkCtx = { | ||
addError: function (arg) { | ||
ERROR.addError(makeError(arg)); | ||
addIssue: function (arg) { | ||
ERROR.addIssue(makeError(arg)); | ||
}, | ||
@@ -902,3 +902,3 @@ }; | ||
// const { check: checkMethod, ...noMethodCheck } = check; | ||
// ERROR.addError(makeError(noMethodCheck)); | ||
// ERROR.addIssue(makeError(noMethodCheck)); | ||
// } | ||
@@ -910,5 +910,5 @@ } | ||
// if (resolvedValue === INVALID) { | ||
// throw new ZodError([]).addError( | ||
// throw new ZodError([]).addIssue( | ||
// makeError({ | ||
// code: ZodErrorCode.custom_error, | ||
// code: ZodIssueCode.custom, | ||
// message: 'Invalid', | ||
@@ -942,4 +942,4 @@ // }), | ||
if (resolvedValue === INVALID && ERROR.isEmpty) { | ||
ERROR.addError(makeError({ | ||
code: ZodError_1.ZodErrorCode.custom_error, | ||
ERROR.addIssue(makeError({ | ||
code: ZodError_1.ZodIssueCode.custom, | ||
message: 'Invalid', | ||
@@ -946,0 +946,0 @@ })); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -47,22 +11,13 @@ if (mod && mod.__esModule) return mod; | ||
var z = __importStar(require(".")); | ||
var run = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var apiString; | ||
return __generator(this, function (_a) { | ||
apiString = z.string(); | ||
z.object({ | ||
columns: z.record(z.string()), | ||
primaryKey: z.array(apiString.nonempty()).nonempty(), | ||
})._refinement(function (data, ctx) { | ||
var invalidPks = data.primaryKey.filter(function (pk) { return !Object.keys(data.columns).includes(pk); }); | ||
if (invalidPks.length) { | ||
ctx.addError({ | ||
code: z.ZodErrorCode.custom_error, | ||
message: "Invalid PKs: " + invalidPks.join(', '), | ||
}); | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); }; | ||
run(); | ||
// import { Scalars } from './helpers/primitive'; | ||
var obj = z.object({ | ||
primitiveTuple: z.tuple([z.string(), z.number()]), | ||
nonprimitiveTuple: z.tuple([z.string(), z.number().array()]), | ||
}); | ||
var prim = obj.primitives(); | ||
console.log(prim.shape); | ||
var nonprim = obj.nonprimitives(); | ||
console.log(nonprim.shape); | ||
// .primitives(); | ||
// type t1 = [[string, number]] extends [Scalars] ? true : false; | ||
//# sourceMappingURL=playground.js.map |
@@ -53,3 +53,3 @@ "use strict"; | ||
_this.min = function (minLength, message) { | ||
return _this.refinement(function (data) { return data.length >= minLength; }, __assign({ code: ZodError_1.ZodErrorCode.too_small, type: 'array', inclusive: true, minimum: minLength }, (typeof message === 'string' ? { message: message } : message))); | ||
return _this.refinement(function (data) { return data.length >= minLength; }, __assign({ code: ZodError_1.ZodIssueCode.too_small, type: 'array', inclusive: true, minimum: minLength }, (typeof message === 'string' ? { message: message } : message))); | ||
}; | ||
@@ -59,3 +59,3 @@ _this.max = function (maxLength, message) { | ||
// check: data => data.length <= maxLength, | ||
code: ZodError_1.ZodErrorCode.too_big, type: 'array', inclusive: true, maximum: maxLength }, (typeof message === 'string' ? { message: message } : message))); | ||
code: ZodError_1.ZodIssueCode.too_big, type: 'array', inclusive: true, maximum: maxLength }, (typeof message === 'string' ? { message: message } : message))); | ||
}; | ||
@@ -102,3 +102,3 @@ _this.length = function (len, message) { | ||
// check: data => data.length >= minLength, | ||
code: ZodError_1.ZodErrorCode.too_small, minimum: minLength, type: 'array', inclusive: true }, (typeof message === 'string' ? { message: message } : message))); | ||
code: ZodError_1.ZodIssueCode.too_small, minimum: minLength, type: 'array', inclusive: true }, (typeof message === 'string' ? { message: message } : message))); | ||
}; | ||
@@ -108,3 +108,3 @@ _this.max = function (maxLength, message) { | ||
// check: | ||
code: ZodError_1.ZodErrorCode.too_big, maximum: maxLength, type: 'array', inclusive: true }, (typeof message === 'string' ? { message: message } : message))); | ||
code: ZodError_1.ZodIssueCode.too_big, maximum: maxLength, type: 'array', inclusive: true }, (typeof message === 'string' ? { message: message } : message))); | ||
}; | ||
@@ -111,0 +111,0 @@ _this.length = function (len, message) { |
@@ -5,3 +5,3 @@ import { ParseParams, MakeErrorData } from '../parser'; | ||
import { ZodNullableType } from './nullable'; | ||
import { ZodCustomError } from '../ZodError'; | ||
import { ZodCustomIssue } from '../ZodError'; | ||
export declare enum ZodTypes { | ||
@@ -43,3 +43,3 @@ string = "string", | ||
check: (arg: T, ctx: { | ||
addError: (arg: MakeErrorData) => void; | ||
addIssue: (arg: MakeErrorData) => void; | ||
}) => any; | ||
@@ -86,30 +86,30 @@ }; | ||
check(u: unknown): u is Input; | ||
refine: <Func extends (arg: Output) => any>(check: Func, message?: string | Partial<Pick<ZodCustomError, "path" | "message" | "params">> | ((arg: Output) => Partial<Pick<ZodCustomError, "path" | "message" | "params">>)) => this; | ||
refinement: (check: (arg: Output) => any, refinementData: (Pick<import("..").ZodInvalidTypeError, "code" | "expected" | "received" | "message"> & { | ||
refine: <Func extends (arg: Output) => any>(check: Func, message?: string | Partial<Pick<ZodCustomIssue, "path" | "message" | "params">> | ((arg: Output) => Partial<Pick<ZodCustomIssue, "path" | "message" | "params">>)) => this; | ||
refinement: (check: (arg: Output) => any, refinementData: (Pick<import("..").ZodInvalidTypeIssue, "code" | "expected" | "received" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodNonEmptyArrayIsEmptyError, "code" | "message"> & { | ||
}) | (Pick<import("..").ZodNonEmptyArrayIsEmptyIssue, "code" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodUnrecognizedKeysError, "keys" | "code" | "message"> & { | ||
}) | (Pick<import("..").ZodUnrecognizedKeysIssue, "keys" | "code" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidUnionError, "code" | "message" | "unionErrors"> & { | ||
}) | (Pick<import("..").ZodInvalidUnionIssue, "code" | "message" | "unionErrors"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidLiteralValueError, "code" | "expected" | "message"> & { | ||
}) | (Pick<import("..").ZodInvalidLiteralValueIssue, "code" | "expected" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidEnumValueError, "code" | "message" | "options"> & { | ||
}) | (Pick<import("..").ZodInvalidEnumValueIssue, "code" | "message" | "options"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidArgumentsError, "code" | "message" | "argumentsError"> & { | ||
}) | (Pick<import("..").ZodInvalidArgumentsIssue, "code" | "message" | "argumentsError"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidReturnTypeError, "code" | "message" | "returnTypeError"> & { | ||
}) | (Pick<import("..").ZodInvalidReturnTypeIssue, "code" | "message" | "returnTypeError"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidDateError, "code" | "message"> & { | ||
}) | (Pick<import("..").ZodInvalidDateIssue, "code" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidStringError, "code" | "message" | "validation"> & { | ||
}) | (Pick<import("..").ZodInvalidStringIssue, "code" | "message" | "validation"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodTooSmallError, "code" | "message" | "minimum" | "inclusive" | "type"> & { | ||
}) | (Pick<import("..").ZodTooSmallIssue, "code" | "message" | "minimum" | "inclusive" | "type"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodTooBigError, "code" | "message" | "inclusive" | "type" | "maximum"> & { | ||
}) | (Pick<import("..").ZodTooBigIssue, "code" | "message" | "inclusive" | "type" | "maximum"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<import("..").ZodInvalidIntersectionTypesError, "code" | "message"> & { | ||
}) | (Pick<import("..").ZodInvalidIntersectionTypesIssue, "code" | "message"> & { | ||
path?: (string | number)[] | undefined; | ||
}) | (Pick<ZodCustomError, "code" | "message" | "params"> & { | ||
}) | (Pick<ZodCustomIssue, "code" | "message" | "params"> & { | ||
path?: (string | number)[] | undefined; | ||
@@ -116,0 +116,0 @@ }) | ((arg: Output) => MakeErrorData)) => this; |
@@ -154,4 +154,4 @@ "use strict"; | ||
var setError = function () { | ||
return ctx.addError({ | ||
code: index_1.ZodErrorCode.custom_error, | ||
return ctx.addIssue({ | ||
code: index_1.ZodIssueCode.custom, | ||
message: message, | ||
@@ -176,3 +176,3 @@ }); | ||
var setError = function () { | ||
return ctx.addError(__assign({ code: index_1.ZodErrorCode.custom_error }, message(val))); | ||
return ctx.addIssue(__assign({ code: index_1.ZodIssueCode.custom }, message(val))); | ||
}; | ||
@@ -194,3 +194,3 @@ if (result instanceof Promise) { | ||
var setError = function () { | ||
return ctx.addError(__assign({ code: index_1.ZodErrorCode.custom_error }, message)); | ||
return ctx.addIssue(__assign({ code: index_1.ZodIssueCode.custom }, message)); | ||
}; | ||
@@ -212,3 +212,3 @@ if (result instanceof Promise) { | ||
if (!check(val)) { | ||
ctx.addError(typeof refinementData === 'function' | ||
ctx.addIssue(typeof refinementData === 'function' | ||
? refinementData(val) | ||
@@ -215,0 +215,0 @@ : refinementData); |
@@ -48,21 +48,21 @@ "use strict"; | ||
_this.min = function (minimum, message) { | ||
return _this.refinement(function (data) { return data >= minimum; }, __assign({ code: ZodError_1.ZodErrorCode.too_small, minimum: minimum, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data >= minimum; }, __assign({ code: ZodError_1.ZodIssueCode.too_small, minimum: minimum, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.max = function (maximum, message) { | ||
return _this.refinement(function (data) { return data <= maximum; }, __assign({ code: ZodError_1.ZodErrorCode.too_big, maximum: maximum, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data <= maximum; }, __assign({ code: ZodError_1.ZodIssueCode.too_big, maximum: maximum, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.int = function (message) { | ||
return _this.refinement(function (data) { return Number.isInteger(data); }, __assign({ code: ZodError_1.ZodErrorCode.invalid_type, expected: 'integer', received: 'number' }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return Number.isInteger(data); }, __assign({ code: ZodError_1.ZodIssueCode.invalid_type, expected: 'integer', received: 'number' }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.positive = function (message) { | ||
return _this.refinement(function (data) { return data > 0; }, __assign({ code: ZodError_1.ZodErrorCode.too_small, minimum: 0, type: 'number', inclusive: false }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data > 0; }, __assign({ code: ZodError_1.ZodIssueCode.too_small, minimum: 0, type: 'number', inclusive: false }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.negative = function (message) { | ||
return _this.refinement(function (data) { return data < 0; }, __assign({ code: ZodError_1.ZodErrorCode.too_big, maximum: 0, type: 'number', inclusive: false }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data < 0; }, __assign({ code: ZodError_1.ZodIssueCode.too_big, maximum: 0, type: 'number', inclusive: false }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.nonpositive = function (message) { | ||
return _this.refinement(function (data) { return data <= 0; }, __assign({ code: ZodError_1.ZodErrorCode.too_big, maximum: 0, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data <= 0; }, __assign({ code: ZodError_1.ZodIssueCode.too_big, maximum: 0, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.nonnegative = function (message) { | ||
return _this.refinement(function (data) { return data >= 0; }, __assign({ code: ZodError_1.ZodErrorCode.too_small, minimum: 0, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data >= 0; }, __assign({ code: ZodError_1.ZodIssueCode.too_small, minimum: 0, type: 'number', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
@@ -69,0 +69,0 @@ return _this; |
import * as z from './base'; | ||
import { objectUtil } from '../helpers/objectUtil'; | ||
import { partialUtil } from '../helpers/partialUtil'; | ||
import { Scalars } from '../helpers/primitive'; | ||
declare type UnknownKeysParam = 'passthrough' | 'strict' | 'strip'; | ||
@@ -23,5 +24,4 @@ export interface ZodObjectDef<T extends z.ZodRawShape = z.ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef { | ||
}>; | ||
export declare type Scalars = string | string[] | number | number[] | boolean | boolean[] | bigint | bigint[] | undefined | null; | ||
export declare type AnyZodObject = ZodObject<any, any, any>; | ||
export declare class ZodObject<T extends z.ZodRawShape, UnknownKeys extends UnknownKeysParam = 'passthrough', Catchall extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodType<objectOutputType<T, Catchall>, ZodObjectDef<T, UnknownKeys, Catchall>, objectInputType<T, Catchall>> { | ||
export declare class ZodObject<T extends z.ZodRawShape, UnknownKeys extends UnknownKeysParam = 'passthrough', Catchall extends z.ZodTypeAny = z.ZodTypeAny, Output extends objectOutputType<T, Catchall> = objectOutputType<T, Catchall>, Input extends objectInputType<T, Catchall> = objectInputType<T, Catchall>> extends z.ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> { | ||
readonly _shape: T; | ||
@@ -37,8 +37,8 @@ readonly _unknownKeys: UnknownKeys; | ||
}; | ||
strict: () => ZodObject<T, "strict", Catchall>; | ||
strip: () => ZodObject<T, "strip", Catchall>; | ||
passthrough: () => ZodObject<T, "passthrough", Catchall>; | ||
nonstrict: () => ZodObject<T, "passthrough", Catchall>; | ||
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, UnknownKeys, Catchall>; | ||
extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, UnknownKeys, Catchall>; | ||
strict: () => ZodObject<T, "strict", Catchall, objectOutputType<T, Catchall>, objectInputType<T, Catchall>>; | ||
strip: () => ZodObject<T, "strip", Catchall, objectOutputType<T, Catchall>, objectInputType<T, Catchall>>; | ||
passthrough: () => ZodObject<T, "passthrough", Catchall, objectOutputType<T, Catchall>, objectInputType<T, Catchall>>; | ||
nonstrict: () => ZodObject<T, "passthrough", Catchall, objectOutputType<T, Catchall>, objectInputType<T, Catchall>>; | ||
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, UnknownKeys, Catchall, objectOutputType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Catchall>, objectInputType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Catchall>>; | ||
extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, UnknownKeys, Catchall, objectOutputType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Catchall>, objectInputType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k_1 in keyof Augmentation]: Augmentation[k_1]; }, Catchall>>; | ||
/** | ||
@@ -50,12 +50,12 @@ * Prior to zod@1.0.12 there was a bug in the | ||
merge: <Incoming extends AnyZodObject>(other: Incoming) => ZodObject<T & Incoming['_shape'], UnknownKeys, Catchall>; | ||
catchall: <Index extends z.ZodTypeAny>(index: Index) => ZodObject<T, UnknownKeys, Index>; | ||
pick: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_3 in { [k_2 in keyof { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }]: [{ [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_2]] extends [never] ? never : k_2; }[keyof Mask]]: k_3 extends keyof Mask ? { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_3] : never; }, UnknownKeys, Catchall>; | ||
omit: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_3 in { [k_2 in keyof { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }]: [{ [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_2]] extends [never] ? never : k_2; }[keyof T]]: k_3 extends keyof T ? { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_3] : never; }, UnknownKeys, Catchall>; | ||
partial: () => ZodObject<{ [k in keyof T]: ReturnType<T[k]["optional"]>; }, UnknownKeys, Catchall>; | ||
primitives: () => ZodObject<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_2] : never; }, UnknownKeys, Catchall>; | ||
nonprimitives: () => ZodObject<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_2] : never; }, UnknownKeys, Catchall>; | ||
catchall: <Index extends z.ZodTypeAny>(index: Index) => ZodObject<T, UnknownKeys, Index, objectOutputType<T, Index>, objectInputType<T, Index>>; | ||
pick: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_3 in { [k_2 in keyof { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }]: [{ [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_2]] extends [never] ? never : k_2; }[keyof Mask]]: k_3 extends keyof Mask ? { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_3] : never; }, UnknownKeys, Catchall, objectOutputType<{ [k_3 in { [k_2 in keyof { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }]: [{ [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_2]] extends [never] ? never : k_2; }[keyof Mask]]: k_3 extends keyof Mask ? { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_3] : never; }, Catchall>, objectInputType<{ [k_3 in { [k_2 in keyof { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }]: [{ [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_2]] extends [never] ? never : k_2; }[keyof Mask]]: k_3 extends keyof Mask ? { [k_1 in keyof Mask]: k_1 extends keyof T ? T[k_1] : never; }[k_3] : never; }, Catchall>>; | ||
omit: <Mask extends { [k in keyof T]?: true | undefined; }>(mask: Mask) => ZodObject<{ [k_3 in { [k_2 in keyof { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }]: [{ [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_2]] extends [never] ? never : k_2; }[keyof T]]: k_3 extends keyof T ? { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_3] : never; }, UnknownKeys, Catchall, objectOutputType<{ [k_3 in { [k_2 in keyof { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }]: [{ [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_2]] extends [never] ? never : k_2; }[keyof T]]: k_3 extends keyof T ? { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_3] : never; }, Catchall>, objectInputType<{ [k_3 in { [k_2 in keyof { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }]: [{ [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_2]] extends [never] ? never : k_2; }[keyof T]]: k_3 extends keyof T ? { [k_1 in keyof T]: k_1 extends keyof Mask ? never : T[k_1]; }[k_3] : never; }, Catchall>>; | ||
partial: () => ZodObject<{ [k in keyof T]: ReturnType<T[k]["optional"]>; }, UnknownKeys, Catchall, objectOutputType<{ [k in keyof T]: ReturnType<T[k]["optional"]>; }, Catchall>, objectInputType<{ [k in keyof T]: ReturnType<T[k]["optional"]>; }, Catchall>>; | ||
primitives: () => ZodObject<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_2] : never; }, UnknownKeys, Catchall, objectOutputType<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_2] : never; }, Catchall>, objectInputType<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? T[k] : never; }[k_2] : never; }, Catchall>>; | ||
nonprimitives: () => ZodObject<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_2] : never; }, UnknownKeys, Catchall, objectOutputType<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_2] : never; }, Catchall>, objectInputType<{ [k_2 in { [k_1 in keyof { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }]: [{ [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_1]] extends [never] ? never : k_1; }[keyof T]]: k_2 extends keyof T ? { [k in keyof T]: [T[k]["_output"]] extends [Scalars] ? never : T[k]; }[k_2] : never; }, Catchall>>; | ||
deepPartial: () => partialUtil.RootDeepPartial<this>; | ||
static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, "passthrough", z.ZodTypeAny>; | ||
static lazycreate: <T_1 extends z.ZodRawShape>(shape: () => T_1) => ZodObject<T_1, "passthrough", z.ZodTypeAny>; | ||
static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, "passthrough", z.ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<{ [k in keyof T_1]: T_1[k]["_output"]; }>]: objectUtil.addQuestionMarks<{ [k in keyof T_1]: T_1[k]["_output"]; }>[k_1]; }, { [k_3 in keyof objectUtil.addQuestionMarks<{ [k_2 in keyof T_1]: T_1[k_2]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_2 in keyof T_1]: T_1[k_2]["_input"]; }>[k_3]; }>; | ||
static lazycreate: <T_1 extends z.ZodRawShape>(shape: () => T_1) => ZodObject<T_1, "passthrough", z.ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<{ [k in keyof T_1]: T_1[k]["_output"]; }>]: objectUtil.addQuestionMarks<{ [k in keyof T_1]: T_1[k]["_output"]; }>[k_1]; }, { [k_3 in keyof objectUtil.addQuestionMarks<{ [k_2 in keyof T_1]: T_1[k_2]["_input"]; }>]: objectUtil.addQuestionMarks<{ [k_2 in keyof T_1]: T_1[k_2]["_input"]; }>[k_3]; }>; | ||
} | ||
export {}; |
@@ -50,9 +50,9 @@ "use strict"; | ||
_this.min = function (minLength, message) { | ||
return _this.refinement(function (data) { return data.length >= minLength; }, __assign({ code: ZodError_1.ZodErrorCode.too_small, minimum: minLength, type: 'string', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data.length >= minLength; }, __assign({ code: ZodError_1.ZodIssueCode.too_small, minimum: minLength, type: 'string', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this.max = function (maxLength, message) { | ||
return _this.refinement(function (data) { return data.length <= maxLength; }, __assign({ code: ZodError_1.ZodErrorCode.too_big, maximum: maxLength, type: 'string', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return data.length <= maxLength; }, __assign({ code: ZodError_1.ZodIssueCode.too_big, maximum: maxLength, type: 'string', inclusive: true }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
_this._regex = function (regex, validation, message) { | ||
return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodError_1.ZodErrorCode.invalid_string }, errorUtil_1.errorUtil.errToObj(message))); | ||
return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodError_1.ZodIssueCode.invalid_string }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
@@ -71,3 +71,3 @@ _this.email = function (message) { | ||
} | ||
}, __assign({ code: ZodError_1.ZodErrorCode.invalid_string, validation: 'url' }, errorUtil_1.errorUtil.errToObj(message))); | ||
}, __assign({ code: ZodError_1.ZodIssueCode.invalid_string, validation: 'url' }, errorUtil_1.errorUtil.errToObj(message))); | ||
}; | ||
@@ -74,0 +74,0 @@ // url = (message?: errorUtil.ErrMessage) => this._regex(urlRegex, 'url', message); |
import { ZodParsedType } from './parser'; | ||
export declare const ZodErrorCode: { | ||
export declare const ZodIssueCode: { | ||
invalid_type: "invalid_type"; | ||
nonempty_array_is_empty: "nonempty_array_is_empty"; | ||
custom_error: "custom_error"; | ||
custom: "custom"; | ||
invalid_union: "invalid_union"; | ||
@@ -18,49 +18,49 @@ invalid_literal_value: "invalid_literal_value"; | ||
}; | ||
export declare type ZodErrorCode = keyof typeof ZodErrorCode; | ||
export declare type ZodSuberrorBase = { | ||
export declare type ZodIssueCode = keyof typeof ZodIssueCode; | ||
export declare type ZodIssueBase = { | ||
path: (string | number)[]; | ||
message?: string; | ||
}; | ||
export interface ZodInvalidTypeError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_type; | ||
export interface ZodInvalidTypeIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_type; | ||
expected: ZodParsedType; | ||
received: ZodParsedType; | ||
} | ||
export interface ZodNonEmptyArrayIsEmptyError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.nonempty_array_is_empty; | ||
export interface ZodNonEmptyArrayIsEmptyIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.nonempty_array_is_empty; | ||
} | ||
export interface ZodUnrecognizedKeysError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.unrecognized_keys; | ||
export interface ZodUnrecognizedKeysIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.unrecognized_keys; | ||
keys: string[]; | ||
} | ||
export interface ZodInvalidUnionError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_union; | ||
export interface ZodInvalidUnionIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_union; | ||
unionErrors: ZodError[]; | ||
} | ||
export interface ZodInvalidLiteralValueError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_literal_value; | ||
export interface ZodInvalidLiteralValueIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_literal_value; | ||
expected: string | number | boolean; | ||
} | ||
export interface ZodInvalidEnumValueError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_enum_value; | ||
export interface ZodInvalidEnumValueIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_enum_value; | ||
options: (string | number)[]; | ||
} | ||
export interface ZodInvalidArgumentsError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_arguments; | ||
export interface ZodInvalidArgumentsIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_arguments; | ||
argumentsError: ZodError; | ||
} | ||
export interface ZodInvalidReturnTypeError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_return_type; | ||
export interface ZodInvalidReturnTypeIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_return_type; | ||
returnTypeError: ZodError; | ||
} | ||
export interface ZodInvalidDateError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_date; | ||
export interface ZodInvalidDateIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_date; | ||
} | ||
export declare type StringValidation = 'email' | 'url' | 'uuid' | 'regex'; | ||
export interface ZodInvalidStringError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_string; | ||
export interface ZodInvalidStringIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_string; | ||
validation: StringValidation; | ||
} | ||
export interface ZodTooSmallError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.too_small; | ||
export interface ZodTooSmallIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.too_small; | ||
minimum: number; | ||
@@ -70,4 +70,4 @@ inclusive: boolean; | ||
} | ||
export interface ZodTooBigError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.too_big; | ||
export interface ZodTooBigIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.too_big; | ||
maximum: number; | ||
@@ -77,7 +77,7 @@ inclusive: boolean; | ||
} | ||
export interface ZodInvalidIntersectionTypesError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.invalid_intersection_types; | ||
export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.invalid_intersection_types; | ||
} | ||
export interface ZodCustomError extends ZodSuberrorBase { | ||
code: typeof ZodErrorCode.custom_error; | ||
export interface ZodCustomIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.custom; | ||
params?: { | ||
@@ -87,4 +87,4 @@ [k: string]: any; | ||
} | ||
export declare type ZodSuberrorOptionalMessage = ZodInvalidTypeError | ZodNonEmptyArrayIsEmptyError | ZodUnrecognizedKeysError | ZodInvalidUnionError | ZodInvalidLiteralValueError | ZodInvalidEnumValueError | ZodInvalidArgumentsError | ZodInvalidReturnTypeError | ZodInvalidDateError | ZodInvalidStringError | ZodTooSmallError | ZodTooBigError | ZodInvalidIntersectionTypesError | ZodCustomError; | ||
export declare type ZodSuberror = ZodSuberrorOptionalMessage & { | ||
export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodNonEmptyArrayIsEmptyIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidLiteralValueIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodCustomIssue; | ||
export declare type ZodIssue = ZodIssueOptionalMessage & { | ||
message: string; | ||
@@ -94,9 +94,10 @@ }; | ||
export declare class ZodError extends Error { | ||
errors: ZodSuberror[]; | ||
constructor(errors: ZodSuberror[]); | ||
static create: (errors: ZodSuberror[]) => ZodError; | ||
issues: ZodIssue[]; | ||
get errors(): ZodIssue[]; | ||
constructor(issues: ZodIssue[]); | ||
static create: (issues: ZodIssue[]) => ZodError; | ||
get message(): string; | ||
get isEmpty(): boolean; | ||
addError: (sub: ZodSuberror) => void; | ||
addErrors: (subs?: ZodSuberror[]) => void; | ||
addIssue: (sub: ZodIssue) => void; | ||
addIssues: (subs?: ZodIssue[]) => void; | ||
flatten: () => { | ||
@@ -103,0 +104,0 @@ formErrors: string[]; |
@@ -24,6 +24,6 @@ "use strict"; | ||
var util_1 = require("./helpers/util"); | ||
exports.ZodErrorCode = util_1.util.arrayToEnum([ | ||
exports.ZodIssueCode = util_1.util.arrayToEnum([ | ||
'invalid_type', | ||
'nonempty_array_is_empty', | ||
'custom_error', | ||
'custom', | ||
'invalid_union', | ||
@@ -47,12 +47,12 @@ 'invalid_literal_value', | ||
__extends(ZodError, _super); | ||
function ZodError(errors) { | ||
function ZodError(issues) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this) || this; | ||
_this.errors = []; | ||
_this.addError = function (sub) { | ||
_this.errors = __spreadArrays(_this.errors, [sub]); | ||
_this.issues = []; | ||
_this.addIssue = function (sub) { | ||
_this.issues = __spreadArrays(_this.issues, [sub]); | ||
}; | ||
_this.addErrors = function (subs) { | ||
_this.addIssues = function (subs) { | ||
if (subs === void 0) { subs = []; } | ||
_this.errors = __spreadArrays(_this.errors, subs); | ||
_this.issues = __spreadArrays(_this.issues, subs); | ||
}; | ||
@@ -62,3 +62,3 @@ _this.flatten = function () { | ||
var formErrors = []; | ||
for (var _i = 0, _a = _this.errors; _i < _a.length; _i++) { | ||
for (var _i = 0, _a = _this.issues; _i < _a.length; _i++) { | ||
var sub = _a[_i]; | ||
@@ -78,15 +78,22 @@ if (sub.path.length > 0) { | ||
Object.setPrototypeOf(_this, actualProto); | ||
_this.errors = errors; | ||
_this.issues = issues; | ||
return _this; | ||
} | ||
Object.defineProperty(ZodError.prototype, "errors", { | ||
get: function () { | ||
return this.issues; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ZodError.prototype, "message", { | ||
get: function () { | ||
return JSON.stringify(this.errors, null, 2); | ||
return JSON.stringify(this.issues, null, 2); | ||
// const errorMessage: string[] = [ | ||
// `${this.errors.length} validation issue(s)`, | ||
// `${this.issues.length} validation issue(s)`, | ||
// '', | ||
// ]; | ||
// for (const err of this.errors) { | ||
// for (const err of this.issues) { | ||
// errorMessage.push( | ||
// ` Issue #${this.errors.indexOf(err)}: ${err.code} at ${err.path.join( | ||
// ` Issue #${this.issues.indexOf(err)}: ${err.code} at ${err.path.join( | ||
// './index', | ||
@@ -110,3 +117,3 @@ // )}`, | ||
get: function () { | ||
return this.errors.length === 0; | ||
return this.issues.length === 0; | ||
}, | ||
@@ -123,4 +130,4 @@ enumerable: true, | ||
}); | ||
ZodError.create = function (errors) { | ||
var error = new ZodError(errors); | ||
ZodError.create = function (issues) { | ||
var error = new ZodError(issues); | ||
return error; | ||
@@ -127,0 +134,0 @@ }; |
{ | ||
"name": "zod", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
@@ -5,0 +5,0 @@ "main": "./lib/src/index.js", |
@@ -32,5 +32,6 @@ <p align="center"> | ||
- Transformers! These let you provide default values, do casting/coersion, and a lot more. Read more here: [Transformers](#transformers) | ||
- Transformers! These let you provide default values, do casting/coercion, and a lot more. Read more here: [Transformers](#transformers) | ||
- Asynchronous refinements and new `.parseAsync` and `.safeParseAsync` methods. Read more here: [Refinements](#refinements) | ||
- New object methods: `.passthrough()`, `.strict()`, and `.catchall()`. Read more here: [Objects](#objects) | ||
- Schema parsing now returns a deep clone of the data you pass in (instead of the _exact_ value you pass in) | ||
- Object schemas now strip unknown keys by default. There are also new object methods: `.passthrough()`, `.strict()`, and `.catchall()`. Read more here: [Objects](#objects) | ||
@@ -72,3 +73,3 @@ In almost all cases, you'll be able to upgrade to Zod 2 without changing any code. Here are some of the (very minor) breaking changes: | ||
I work on Zod in my free time, so if you're making money from a product that is built with Zod, I'd massively appreciate sponsorship at any level. For solo devs, I recommend the [Chipotle Bowl tier](https://github.com/sponsors/vriad) or the [Cup of Coffee tier](https://github.com/sponsors/vriad). | ||
I work on Zod in my free time, so if you're making money from a product that is built with Zod, I'd massively appreciate sponsorship at any level. For solo devs, I recommend the [Chipotle Bowl tier](https://github.com/sponsors/vriad) or the [Cup of Coffee tier](https://github.com/sponsors/vriad). If you're making money from a product you built using Zod, consider the [Startup tier]([Cup of Coffee tier](https://github.com/sponsors/vriad)). You can learn more about the tiers at [github.com/sponsors/vriad](github.com/sponsors/vriad). | ||
@@ -260,6 +261,6 @@ ### Sponsors | ||
stringSchema.safeParse(12); | ||
// => { successs: false; error: ZodError } | ||
// => { success: false; error: ZodError } | ||
stringSchema.safeParse('billie'); | ||
// => { successs: true; data: 'billie' } | ||
// => { success: true; data: 'billie' } | ||
``` | ||
@@ -386,4 +387,4 @@ | ||
ZodError { | ||
errors: [{ | ||
"code": "custom_error", | ||
issues: [{ | ||
"code": "custom", | ||
"path": [ "confirm" ], | ||
@@ -412,4 +413,4 @@ "message": "Passwords don't match" | ||
ZodError { | ||
errors: [{ | ||
"code": "custom_error", | ||
issues: [{ | ||
"code": "custom", | ||
"path": [ "passwordForm", "confirm" ], | ||
@@ -416,0 +417,0 @@ "message": "Passwords don't match" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375208
5186
1787