Comparing version 3.20.6 to 3.21.0
@@ -12,11 +12,36 @@ "use strict"; | ||
const union_1 = __importDefault(require("./union")); | ||
for (const suite of [ | ||
...realworld_1.default.suites, | ||
...primitives_1.default.suites, | ||
...string_1.default.suites, | ||
...object_1.default.suites, | ||
...union_1.default.suites, | ||
...discriminatedUnion_1.default.suites, | ||
]) { | ||
const argv = process.argv.slice(2); | ||
let suites = []; | ||
if (!argv.length) { | ||
suites = [ | ||
...realworld_1.default.suites, | ||
...primitives_1.default.suites, | ||
...string_1.default.suites, | ||
...object_1.default.suites, | ||
...union_1.default.suites, | ||
...discriminatedUnion_1.default.suites, | ||
]; | ||
} | ||
else { | ||
if (argv.includes("--realworld")) { | ||
suites.push(...realworld_1.default.suites); | ||
} | ||
if (argv.includes("--primitives")) { | ||
suites.push(...primitives_1.default.suites); | ||
} | ||
if (argv.includes("--string")) { | ||
suites.push(...string_1.default.suites); | ||
} | ||
if (argv.includes("--object")) { | ||
suites.push(...object_1.default.suites); | ||
} | ||
if (argv.includes("--union")) { | ||
suites.push(...union_1.default.suites); | ||
} | ||
if (argv.includes("--discriminatedUnion")) { | ||
suites.push(...discriminatedUnion_1.default.suites); | ||
} | ||
} | ||
for (const suite of suites) { | ||
suite.run(); | ||
} |
@@ -1,4 +0,4 @@ | ||
import * as mod from "./external"; | ||
import * as z from "./external"; | ||
export * from "./external"; | ||
export { mod as z }; | ||
export default mod; | ||
export { z }; | ||
export default z; |
@@ -26,5 +26,5 @@ "use strict"; | ||
exports.z = void 0; | ||
const mod = __importStar(require("./external")); | ||
exports.z = mod; | ||
const z = __importStar(require("./external")); | ||
exports.z = z; | ||
__exportStar(require("./external"), exports); | ||
exports.default = mod; | ||
exports.default = z; |
@@ -75,3 +75,3 @@ "use strict"; | ||
? `greater than or equal to ` | ||
: `greater than `}${new Date(issue.minimum)}`; | ||
: `greater than `}${new Date(Number(issue.minimum))}`; | ||
else | ||
@@ -91,2 +91,8 @@ message = "Invalid input"; | ||
: `less than`} ${issue.maximum}`; | ||
else if (issue.type === "bigint") | ||
message = `BigInt must be ${issue.exact | ||
? `exactly` | ||
: issue.inclusive | ||
? `less than or equal to` | ||
: `less than`} ${issue.maximum}`; | ||
else if (issue.type === "date") | ||
@@ -97,3 +103,3 @@ message = `Date must be ${issue.exact | ||
? `smaller than or equal to` | ||
: `smaller than`} ${new Date(issue.maximum)}`; | ||
: `smaller than`} ${new Date(Number(issue.maximum))}`; | ||
else | ||
@@ -100,0 +106,0 @@ message = "Invalid input"; |
@@ -85,3 +85,5 @@ import { enumUtil } from "./helpers/enumUtil"; | ||
catch(def: Output): ZodCatch<this>; | ||
catch(def: () => Output): ZodCatch<this>; | ||
catch(def: (ctx: { | ||
error: ZodError; | ||
}) => Output): ZodCatch<this>; | ||
describe(description: string): this; | ||
@@ -92,2 +94,3 @@ pipe<T extends ZodTypeAny>(target: T): ZodPipeline<this, T>; | ||
} | ||
export declare type IpVersion = "v4" | "v6"; | ||
export declare type ZodStringCheck = { | ||
@@ -112,2 +115,5 @@ kind: "min"; | ||
} | { | ||
kind: "emoji"; | ||
message?: string; | ||
} | { | ||
kind: "uuid"; | ||
@@ -137,2 +143,8 @@ message?: string; | ||
} | { | ||
kind: "toLowerCase"; | ||
message?: string; | ||
} | { | ||
kind: "toUpperCase"; | ||
message?: string; | ||
} | { | ||
kind: "datetime"; | ||
@@ -142,2 +154,6 @@ offset: boolean; | ||
message?: string; | ||
} | { | ||
kind: "ip"; | ||
version?: IpVersion; | ||
message?: string; | ||
}; | ||
@@ -155,5 +171,10 @@ export interface ZodStringDef extends ZodTypeDef { | ||
url(message?: errorUtil.ErrMessage): ZodString; | ||
emoji(message?: errorUtil.ErrMessage): ZodString; | ||
uuid(message?: errorUtil.ErrMessage): ZodString; | ||
cuid(message?: errorUtil.ErrMessage): ZodString; | ||
cuid2(message?: errorUtil.ErrMessage): ZodString; | ||
ip(options?: string | { | ||
version?: "v4" | "v6"; | ||
message?: string; | ||
}): ZodString; | ||
datetime(options?: string | { | ||
@@ -176,8 +197,12 @@ message?: string | undefined; | ||
trim: () => ZodString; | ||
toLowerCase: () => ZodString; | ||
toUpperCase: () => ZodString; | ||
get isDatetime(): boolean; | ||
get isEmail(): boolean; | ||
get isURL(): boolean; | ||
get isEmoji(): boolean; | ||
get isUUID(): boolean; | ||
get isCUID(): boolean; | ||
get isCUID2(): boolean; | ||
get isIP(): boolean; | ||
get minLength(): number | null; | ||
@@ -244,4 +269,5 @@ get maxLength(): number | null; | ||
multipleOf(value: number, message?: errorUtil.ErrMessage): ZodNumber; | ||
step: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber; | ||
finite(message?: errorUtil.ErrMessage): ZodNumber; | ||
step: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber; | ||
safe(message?: errorUtil.ErrMessage): ZodNumber; | ||
get minValue(): number | null; | ||
@@ -252,3 +278,19 @@ get maxValue(): number | null; | ||
} | ||
export declare type ZodBigIntCheck = { | ||
kind: "min"; | ||
value: bigint; | ||
inclusive: boolean; | ||
message?: string; | ||
} | { | ||
kind: "max"; | ||
value: bigint; | ||
inclusive: boolean; | ||
message?: string; | ||
} | { | ||
kind: "multipleOf"; | ||
value: bigint; | ||
message?: string; | ||
}; | ||
export interface ZodBigIntDef extends ZodTypeDef { | ||
checks: ZodBigIntCheck[]; | ||
typeName: ZodFirstPartyTypeKind.ZodBigInt; | ||
@@ -267,2 +309,17 @@ coerce: boolean; | ||
}) | undefined) => ZodBigInt; | ||
gte(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; | ||
min: (value: bigint, message?: errorUtil.ErrMessage | undefined) => ZodBigInt; | ||
gt(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; | ||
lte(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; | ||
max: (value: bigint, message?: errorUtil.ErrMessage | undefined) => ZodBigInt; | ||
lt(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; | ||
protected setLimit(kind: "min" | "max", value: bigint, inclusive: boolean, message?: string): ZodBigInt; | ||
_addCheck(check: ZodBigIntCheck): ZodBigInt; | ||
positive(message?: errorUtil.ErrMessage): ZodBigInt; | ||
negative(message?: errorUtil.ErrMessage): ZodBigInt; | ||
nonpositive(message?: errorUtil.ErrMessage): ZodBigInt; | ||
nonnegative(message?: errorUtil.ErrMessage): ZodBigInt; | ||
multipleOf(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; | ||
get minValue(): bigint | null; | ||
get maxValue(): bigint | null; | ||
} | ||
@@ -433,11 +490,14 @@ export interface ZodBooleanDef extends ZodTypeDef { | ||
}>; | ||
export declare type objectOutputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny> = ZodTypeAny extends Catchall ? objectUtil.flatten<baseObjectOutputType<Shape>> : objectUtil.flatten<baseObjectOutputType<Shape> & { | ||
export declare type objectOutputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny, UnknownKeys extends UnknownKeysParam = UnknownKeysParam> = ZodTypeAny extends Catchall ? objectUtil.flatten<baseObjectOutputType<Shape>> & Passthrough<UnknownKeys> : objectUtil.flatten<baseObjectOutputType<Shape> & { | ||
[k: string]: Catchall["_output"]; | ||
}>; | ||
} & Passthrough<UnknownKeys>>; | ||
export declare type baseObjectInputType<Shape extends ZodRawShape> = objectUtil.flatten<objectUtil.addQuestionMarks<{ | ||
[k in keyof Shape]: Shape[k]["_input"]; | ||
}>>; | ||
export declare type objectInputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny> = ZodTypeAny extends Catchall ? baseObjectInputType<Shape> : objectUtil.flatten<baseObjectInputType<Shape> & { | ||
export declare type Passthrough<UnknownKeys extends UnknownKeysParam> = UnknownKeys extends "passthrough" ? { | ||
[k: string]: unknown; | ||
} : unknown; | ||
export declare type objectInputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny, UnknownKeys extends UnknownKeysParam = UnknownKeysParam> = ZodTypeAny extends Catchall ? baseObjectInputType<Shape> & Passthrough<UnknownKeys> : objectUtil.flatten<baseObjectInputType<Shape> & { | ||
[k: string]: Catchall["_input"]; | ||
}>; | ||
} & Passthrough<UnknownKeys>>; | ||
export declare type deoptional<T extends ZodTypeAny> = T extends ZodOptional<infer U> ? deoptional<U> : T extends ZodNullable<infer U> ? ZodNullable<deoptional<U>> : T; | ||
@@ -451,3 +511,3 @@ export declare type SomeZodObject = ZodObject<ZodRawShape, UnknownKeysParam, ZodTypeAny>; | ||
}; | ||
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall>, Input = objectInputType<T, Catchall>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> { | ||
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall, UnknownKeys>, Input = objectInputType<T, Catchall, UnknownKeys>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> { | ||
private _cached; | ||
@@ -472,3 +532,3 @@ _getCached(): { | ||
* */ | ||
augment: <Augmentation extends ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, UnknownKeys, Catchall, objectOutputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall>, objectInputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall>>; | ||
augment: <Augmentation extends ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, UnknownKeys, Catchall, objectOutputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall, UnknownKeys>, objectInputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall, UnknownKeys>>; | ||
/** | ||
@@ -486,2 +546,5 @@ * Prior to zod@1.0.12 there was a bug in the | ||
omit<Mask extends objectKeyMask<T>>(mask: noUnrecognized<Mask, objectKeyMask<T>>): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>; | ||
/** | ||
* @deprecated | ||
*/ | ||
deepPartial(): partialUtil.DeepPartial<this>; | ||
@@ -589,3 +652,3 @@ partial(): ZodObject<{ | ||
string | ||
] extends [K] ? Record<K, V> : [number] extends [K] ? Record<K, V> : [symbol] extends [K] ? Record<K, V> : Partial<Record<K, V>>; | ||
] extends [K] ? Record<K, V> : [number] extends [K] ? Record<K, V> : [symbol] extends [K] ? Record<K, V> : [BRAND<string | number | symbol>] extends [K] ? Record<K, V> : Partial<Record<K, V>>; | ||
export declare class ZodRecord<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<RecordType<Key["_output"], Value["_output"]>, ZodRecordDef<Key, Value>, RecordType<Key["_input"], Value["_input"]>> { | ||
@@ -639,3 +702,3 @@ get keySchema(): Key; | ||
returnType(): Returns; | ||
args<Items extends Parameters<typeof ZodTuple["create"]>[0]>(...items: Items): ZodFunction<ZodTuple<Items, ZodUnknown>, Returns>; | ||
args<Items extends Parameters<(typeof ZodTuple)["create"]>[0]>(...items: Items): ZodFunction<ZodTuple<Items, ZodUnknown>, Returns>; | ||
returns<NewReturnType extends ZodType<any, any>>(returnType: NewReturnType): ZodFunction<Args, NewReturnType>; | ||
@@ -784,3 +847,5 @@ implement<F extends InnerTypeOfFunction<Args, Returns>>(func: F): ReturnType<F> extends Returns["_output"] ? (...args: Args["_input"]) => ReturnType<F> : OuterTypeOfFunction<Args, Returns>; | ||
innerType: T; | ||
catchValue: () => C; | ||
catchValue: (ctx: { | ||
error: ZodError; | ||
}) => C; | ||
typeName: ZodFirstPartyTypeKind.ZodCatch; | ||
@@ -830,3 +895,6 @@ } | ||
} | ||
export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: Parameters<ZodTypeAny["refine"]>[1], fatal?: boolean | undefined) => ZodType<T, ZodTypeDef, T>; | ||
declare type CustomParams = CustomErrorParams & { | ||
fatal?: boolean; | ||
}; | ||
export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: CustomParams | ((input: any) => CustomParams), fatal?: boolean | undefined) => ZodType<T, ZodTypeDef, T>; | ||
export { ZodType as Schema, ZodType as ZodSchema }; | ||
@@ -877,3 +945,3 @@ export declare const late: { | ||
} | ||
declare const instanceOfType: <T extends typeof Class>(cls: T, params?: Parameters<ZodTypeAny["refine"]>[1]) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>; | ||
declare const instanceOfType: <T extends typeof Class>(cls: T, params?: CustomParams) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>; | ||
declare const stringType: (params?: ({ | ||
@@ -880,0 +948,0 @@ errorMap?: ZodErrorMap | undefined; |
@@ -73,3 +73,3 @@ import type { TypeOf, ZodType } from "."; | ||
} | ||
export declare type StringValidation = "email" | "url" | "uuid" | "regex" | "cuid" | "cuid2" | "datetime" | { | ||
export declare type StringValidation = "email" | "url" | "emoji" | "uuid" | "regex" | "cuid" | "cuid2" | "datetime" | "ip" | { | ||
startsWith: string; | ||
@@ -85,13 +85,13 @@ } | { | ||
code: typeof ZodIssueCode.too_small; | ||
minimum: number; | ||
minimum: number | bigint; | ||
inclusive: boolean; | ||
exact?: boolean; | ||
type: "array" | "string" | "number" | "set" | "date"; | ||
type: "array" | "string" | "number" | "set" | "date" | "bigint"; | ||
} | ||
export interface ZodTooBigIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.too_big; | ||
maximum: number; | ||
maximum: number | bigint; | ||
inclusive: boolean; | ||
exact?: boolean; | ||
type: "array" | "string" | "number" | "set" | "date"; | ||
type: "array" | "string" | "number" | "set" | "date" | "bigint"; | ||
} | ||
@@ -103,3 +103,3 @@ export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase { | ||
code: typeof ZodIssueCode.not_multiple_of; | ||
multipleOf: number; | ||
multipleOf: number | bigint; | ||
} | ||
@@ -124,11 +124,12 @@ export interface ZodNotFiniteIssue extends ZodIssueBase { | ||
export declare const quotelessJson: (obj: any) => string; | ||
declare type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? { | ||
[K in keyof T]?: ZodFormattedError<T[K]>; | ||
} : T extends any[] ? { | ||
[k: number]: ZodFormattedError<T[number]>; | ||
} : T extends object ? { | ||
[K in keyof T]?: ZodFormattedError<T[K]>; | ||
} : unknown; | ||
export declare type ZodFormattedError<T, U = string> = { | ||
_errors: U[]; | ||
} & (NonNullable<T> extends [any, ...any[]] ? { | ||
[K in keyof NonNullable<T>]?: ZodFormattedError<NonNullable<T>[K], U>; | ||
} : NonNullable<T> extends any[] ? { | ||
[k: number]: ZodFormattedError<NonNullable<T>[number], U>; | ||
} : NonNullable<T> extends object ? { | ||
[K in keyof NonNullable<T>]?: ZodFormattedError<NonNullable<T>[K], U>; | ||
} : unknown); | ||
} & recursiveZodFormattedError<NonNullable<T>>; | ||
export declare type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>; | ||
@@ -135,0 +136,0 @@ export declare class ZodError<T = any> extends Error { |
{ | ||
"name": "zod", | ||
"version": "3.20.6", | ||
"version": "3.21.0", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
@@ -8,3 +8,2 @@ "main": "./lib/index.js", | ||
"module": "./lib/index.mjs", | ||
"dependencies": {}, | ||
"exports": { | ||
@@ -47,2 +46,3 @@ ".": { | ||
], | ||
"dependencies": {}, | ||
"scripts": { | ||
@@ -98,3 +98,3 @@ "prettier:check": "prettier --check src/**/*.ts deno/lib/**/*.ts --no-error-on-unmatched-pattern", | ||
"tsx": "^3.8.0", | ||
"typescript": "4.5" | ||
"typescript": "~4.5.0" | ||
}, | ||
@@ -101,0 +101,0 @@ "lint-staged": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
601270
13875
2612