summaryrefslogtreecommitdiff
path: root/node_modules/zod/lib
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/zod/lib
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
Diffstat (limited to 'node_modules/zod/lib')
-rw-r--r--node_modules/zod/lib/ZodError.d.ts163
-rw-r--r--node_modules/zod/lib/ZodError.js124
-rw-r--r--node_modules/zod/lib/__tests__/Mocker.d.ts17
-rw-r--r--node_modules/zod/lib/__tests__/Mocker.js57
-rw-r--r--node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/discriminatedUnion.js79
-rw-r--r--node_modules/zod/lib/benchmarks/index.d.ts1
-rw-r--r--node_modules/zod/lib/benchmarks/index.js46
-rw-r--r--node_modules/zod/lib/benchmarks/object.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/object.js70
-rw-r--r--node_modules/zod/lib/benchmarks/primitives.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/primitives.js136
-rw-r--r--node_modules/zod/lib/benchmarks/realworld.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/realworld.js56
-rw-r--r--node_modules/zod/lib/benchmarks/string.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/string.js55
-rw-r--r--node_modules/zod/lib/benchmarks/union.d.ts5
-rw-r--r--node_modules/zod/lib/benchmarks/union.js79
-rw-r--r--node_modules/zod/lib/errors.d.ts5
-rw-r--r--node_modules/zod/lib/errors.js17
-rw-r--r--node_modules/zod/lib/external.d.ts6
-rw-r--r--node_modules/zod/lib/external.js18
-rw-r--r--node_modules/zod/lib/helpers/enumUtil.d.ts8
-rw-r--r--node_modules/zod/lib/helpers/enumUtil.js2
-rw-r--r--node_modules/zod/lib/helpers/errorUtil.d.ts9
-rw-r--r--node_modules/zod/lib/helpers/errorUtil.js8
-rw-r--r--node_modules/zod/lib/helpers/parseUtil.d.ts78
-rw-r--r--node_modules/zod/lib/helpers/parseUtil.js115
-rw-r--r--node_modules/zod/lib/helpers/partialUtil.d.ts8
-rw-r--r--node_modules/zod/lib/helpers/partialUtil.js2
-rw-r--r--node_modules/zod/lib/helpers/typeAliases.d.ts2
-rw-r--r--node_modules/zod/lib/helpers/typeAliases.js2
-rw-r--r--node_modules/zod/lib/helpers/util.d.ts68
-rw-r--r--node_modules/zod/lib/helpers/util.js142
-rw-r--r--node_modules/zod/lib/index.d.ts4
-rw-r--r--node_modules/zod/lib/index.js29
-rw-r--r--node_modules/zod/lib/index.mjs4006
-rw-r--r--node_modules/zod/lib/index.umd.js4120
-rw-r--r--node_modules/zod/lib/locales/en.d.ts3
-rw-r--r--node_modules/zod/lib/locales/en.js129
-rw-r--r--node_modules/zod/lib/types.d.ts1029
-rw-r--r--node_modules/zod/lib/types.js3288
42 files changed, 14011 insertions, 0 deletions
diff --git a/node_modules/zod/lib/ZodError.d.ts b/node_modules/zod/lib/ZodError.d.ts
new file mode 100644
index 0000000..90f54af
--- /dev/null
+++ b/node_modules/zod/lib/ZodError.d.ts
@@ -0,0 +1,163 @@
+import type { TypeOf, ZodType } from ".";
+import { Primitive } from "./helpers/typeAliases";
+import { util, ZodParsedType } from "./helpers/util";
+declare type allKeys<T> = T extends any ? keyof T : never;
+export declare type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
+export declare type typeToFlattenedError<T, U = string> = {
+ formErrors: U[];
+ fieldErrors: {
+ [P in allKeys<T>]?: U[];
+ };
+};
+export declare const ZodIssueCode: {
+ invalid_type: "invalid_type";
+ invalid_literal: "invalid_literal";
+ custom: "custom";
+ invalid_union: "invalid_union";
+ invalid_union_discriminator: "invalid_union_discriminator";
+ invalid_enum_value: "invalid_enum_value";
+ unrecognized_keys: "unrecognized_keys";
+ invalid_arguments: "invalid_arguments";
+ invalid_return_type: "invalid_return_type";
+ invalid_date: "invalid_date";
+ invalid_string: "invalid_string";
+ too_small: "too_small";
+ too_big: "too_big";
+ invalid_intersection_types: "invalid_intersection_types";
+ not_multiple_of: "not_multiple_of";
+ not_finite: "not_finite";
+};
+export declare type ZodIssueCode = keyof typeof ZodIssueCode;
+export declare type ZodIssueBase = {
+ path: (string | number)[];
+ message?: string;
+};
+export interface ZodInvalidTypeIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_type;
+ expected: ZodParsedType;
+ received: ZodParsedType;
+}
+export interface ZodInvalidLiteralIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_literal;
+ expected: unknown;
+ received: unknown;
+}
+export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.unrecognized_keys;
+ keys: string[];
+}
+export interface ZodInvalidUnionIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_union;
+ unionErrors: ZodError[];
+}
+export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_union_discriminator;
+ options: Primitive[];
+}
+export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
+ received: string | number;
+ code: typeof ZodIssueCode.invalid_enum_value;
+ options: (string | number)[];
+}
+export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_arguments;
+ argumentsError: ZodError;
+}
+export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_return_type;
+ returnTypeError: ZodError;
+}
+export interface ZodInvalidDateIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_date;
+}
+export declare type StringValidation = "email" | "url" | "emoji" | "uuid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "ip" | {
+ includes: string;
+ position?: number;
+} | {
+ startsWith: string;
+} | {
+ endsWith: string;
+};
+export interface ZodInvalidStringIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_string;
+ validation: StringValidation;
+}
+export interface ZodTooSmallIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.too_small;
+ minimum: number | bigint;
+ inclusive: boolean;
+ exact?: boolean;
+ type: "array" | "string" | "number" | "set" | "date" | "bigint";
+}
+export interface ZodTooBigIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.too_big;
+ maximum: number | bigint;
+ inclusive: boolean;
+ exact?: boolean;
+ type: "array" | "string" | "number" | "set" | "date" | "bigint";
+}
+export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.invalid_intersection_types;
+}
+export interface ZodNotMultipleOfIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.not_multiple_of;
+ multipleOf: number | bigint;
+}
+export interface ZodNotFiniteIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.not_finite;
+}
+export interface ZodCustomIssue extends ZodIssueBase {
+ code: typeof ZodIssueCode.custom;
+ params?: {
+ [k: string]: any;
+ };
+}
+export declare type DenormalizedError = {
+ [k: string]: DenormalizedError | string[];
+};
+export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
+export declare type ZodIssue = ZodIssueOptionalMessage & {
+ fatal?: boolean;
+ message: string;
+};
+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[];
+} & recursiveZodFormattedError<NonNullable<T>>;
+export declare type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
+export declare class ZodError<T = any> extends Error {
+ issues: ZodIssue[];
+ get errors(): ZodIssue[];
+ constructor(issues: ZodIssue[]);
+ format(): ZodFormattedError<T>;
+ format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
+ static create: (issues: ZodIssue[]) => ZodError<any>;
+ toString(): string;
+ get message(): string;
+ get isEmpty(): boolean;
+ addIssue: (sub: ZodIssue) => void;
+ addIssues: (subs?: ZodIssue[]) => void;
+ flatten(): typeToFlattenedError<T>;
+ flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
+ get formErrors(): typeToFlattenedError<T, string>;
+}
+declare type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
+export declare type IssueData = stripPath<ZodIssueOptionalMessage> & {
+ path?: (string | number)[];
+ fatal?: boolean;
+};
+export declare type ErrorMapCtx = {
+ defaultError: string;
+ data: any;
+};
+export declare type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
+ message: string;
+};
+export {};
diff --git a/node_modules/zod/lib/ZodError.js b/node_modules/zod/lib/ZodError.js
new file mode 100644
index 0000000..5901765
--- /dev/null
+++ b/node_modules/zod/lib/ZodError.js
@@ -0,0 +1,124 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
+const util_1 = require("./helpers/util");
+exports.ZodIssueCode = util_1.util.arrayToEnum([
+ "invalid_type",
+ "invalid_literal",
+ "custom",
+ "invalid_union",
+ "invalid_union_discriminator",
+ "invalid_enum_value",
+ "unrecognized_keys",
+ "invalid_arguments",
+ "invalid_return_type",
+ "invalid_date",
+ "invalid_string",
+ "too_small",
+ "too_big",
+ "invalid_intersection_types",
+ "not_multiple_of",
+ "not_finite",
+]);
+const quotelessJson = (obj) => {
+ const json = JSON.stringify(obj, null, 2);
+ return json.replace(/"([^"]+)":/g, "$1:");
+};
+exports.quotelessJson = quotelessJson;
+class ZodError extends Error {
+ constructor(issues) {
+ super();
+ this.issues = [];
+ this.addIssue = (sub) => {
+ this.issues = [...this.issues, sub];
+ };
+ this.addIssues = (subs = []) => {
+ this.issues = [...this.issues, ...subs];
+ };
+ const actualProto = new.target.prototype;
+ if (Object.setPrototypeOf) {
+ Object.setPrototypeOf(this, actualProto);
+ }
+ else {
+ this.__proto__ = actualProto;
+ }
+ this.name = "ZodError";
+ this.issues = issues;
+ }
+ get errors() {
+ return this.issues;
+ }
+ format(_mapper) {
+ const mapper = _mapper ||
+ function (issue) {
+ return issue.message;
+ };
+ const fieldErrors = { _errors: [] };
+ const processError = (error) => {
+ for (const issue of error.issues) {
+ if (issue.code === "invalid_union") {
+ issue.unionErrors.map(processError);
+ }
+ else if (issue.code === "invalid_return_type") {
+ processError(issue.returnTypeError);
+ }
+ else if (issue.code === "invalid_arguments") {
+ processError(issue.argumentsError);
+ }
+ else if (issue.path.length === 0) {
+ fieldErrors._errors.push(mapper(issue));
+ }
+ else {
+ let curr = fieldErrors;
+ let i = 0;
+ while (i < issue.path.length) {
+ const el = issue.path[i];
+ const terminal = i === issue.path.length - 1;
+ if (!terminal) {
+ curr[el] = curr[el] || { _errors: [] };
+ }
+ else {
+ curr[el] = curr[el] || { _errors: [] };
+ curr[el]._errors.push(mapper(issue));
+ }
+ curr = curr[el];
+ i++;
+ }
+ }
+ }
+ };
+ processError(this);
+ return fieldErrors;
+ }
+ toString() {
+ return this.message;
+ }
+ get message() {
+ return JSON.stringify(this.issues, util_1.util.jsonStringifyReplacer, 2);
+ }
+ get isEmpty() {
+ return this.issues.length === 0;
+ }
+ flatten(mapper = (issue) => issue.message) {
+ const fieldErrors = {};
+ const formErrors = [];
+ for (const sub of this.issues) {
+ if (sub.path.length > 0) {
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
+ fieldErrors[sub.path[0]].push(mapper(sub));
+ }
+ else {
+ formErrors.push(mapper(sub));
+ }
+ }
+ return { formErrors, fieldErrors };
+ }
+ get formErrors() {
+ return this.flatten();
+ }
+}
+exports.ZodError = ZodError;
+ZodError.create = (issues) => {
+ const error = new ZodError(issues);
+ return error;
+};
diff --git a/node_modules/zod/lib/__tests__/Mocker.d.ts b/node_modules/zod/lib/__tests__/Mocker.d.ts
new file mode 100644
index 0000000..2f605b6
--- /dev/null
+++ b/node_modules/zod/lib/__tests__/Mocker.d.ts
@@ -0,0 +1,17 @@
+export declare class Mocker {
+ pick: (...args: any[]) => any;
+ get string(): string;
+ get number(): number;
+ get bigint(): bigint;
+ get boolean(): boolean;
+ get date(): Date;
+ get symbol(): symbol;
+ get null(): null;
+ get undefined(): undefined;
+ get stringOptional(): any;
+ get stringNullable(): any;
+ get numberOptional(): any;
+ get numberNullable(): any;
+ get booleanOptional(): any;
+ get booleanNullable(): any;
+}
diff --git a/node_modules/zod/lib/__tests__/Mocker.js b/node_modules/zod/lib/__tests__/Mocker.js
new file mode 100644
index 0000000..6a56647
--- /dev/null
+++ b/node_modules/zod/lib/__tests__/Mocker.js
@@ -0,0 +1,57 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Mocker = void 0;
+function getRandomInt(max) {
+ return Math.floor(Math.random() * Math.floor(max));
+}
+const testSymbol = Symbol("test");
+class Mocker {
+ constructor() {
+ this.pick = (...args) => {
+ return args[getRandomInt(args.length)];
+ };
+ }
+ get string() {
+ return Math.random().toString(36).substring(7);
+ }
+ get number() {
+ return Math.random() * 100;
+ }
+ get bigint() {
+ return BigInt(Math.floor(Math.random() * 10000));
+ }
+ get boolean() {
+ return Math.random() < 0.5;
+ }
+ get date() {
+ return new Date(Math.floor(Date.now() * Math.random()));
+ }
+ get symbol() {
+ return testSymbol;
+ }
+ get null() {
+ return null;
+ }
+ get undefined() {
+ return undefined;
+ }
+ get stringOptional() {
+ return this.pick(this.string, this.undefined);
+ }
+ get stringNullable() {
+ return this.pick(this.string, this.null);
+ }
+ get numberOptional() {
+ return this.pick(this.number, this.undefined);
+ }
+ get numberNullable() {
+ return this.pick(this.number, this.null);
+ }
+ get booleanOptional() {
+ return this.pick(this.boolean, this.undefined);
+ }
+ get booleanNullable() {
+ return this.pick(this.boolean, this.null);
+ }
+}
+exports.Mocker = Mocker;
diff --git a/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts b/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/discriminatedUnion.js b/node_modules/zod/lib/benchmarks/discriminatedUnion.js
new file mode 100644
index 0000000..ea148f6
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/discriminatedUnion.js
@@ -0,0 +1,79 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double");
+const manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many");
+const aSchema = index_1.z.object({
+ type: index_1.z.literal("a"),
+});
+const objA = {
+ type: "a",
+};
+const bSchema = index_1.z.object({
+ type: index_1.z.literal("b"),
+});
+const objB = {
+ type: "b",
+};
+const cSchema = index_1.z.object({
+ type: index_1.z.literal("c"),
+});
+const objC = {
+ type: "c",
+};
+const dSchema = index_1.z.object({
+ type: index_1.z.literal("d"),
+});
+const double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]);
+const many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]);
+doubleSuite
+ .add("valid: a", () => {
+ double.parse(objA);
+})
+ .add("valid: b", () => {
+ double.parse(objB);
+})
+ .add("invalid: null", () => {
+ try {
+ double.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ double.parse(objC);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${doubleSuite.name}: ${e.target}`);
+});
+manySuite
+ .add("valid: a", () => {
+ many.parse(objA);
+})
+ .add("valid: c", () => {
+ many.parse(objC);
+})
+ .add("invalid: null", () => {
+ try {
+ many.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ many.parse({ type: "unknown" });
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${manySuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [doubleSuite, manySuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/index.d.ts b/node_modules/zod/lib/benchmarks/index.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/index.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/node_modules/zod/lib/benchmarks/index.js b/node_modules/zod/lib/benchmarks/index.js
new file mode 100644
index 0000000..71930b4
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/index.js
@@ -0,0 +1,46 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const discriminatedUnion_1 = __importDefault(require("./discriminatedUnion"));
+const object_1 = __importDefault(require("./object"));
+const primitives_1 = __importDefault(require("./primitives"));
+const realworld_1 = __importDefault(require("./realworld"));
+const string_1 = __importDefault(require("./string"));
+const union_1 = __importDefault(require("./union"));
+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();
+}
diff --git a/node_modules/zod/lib/benchmarks/object.d.ts b/node_modules/zod/lib/benchmarks/object.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/object.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/object.js b/node_modules/zod/lib/benchmarks/object.js
new file mode 100644
index 0000000..02f26c5
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/object.js
@@ -0,0 +1,70 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const emptySuite = new benchmark_1.default.Suite("z.object: empty");
+const shortSuite = new benchmark_1.default.Suite("z.object: short");
+const longSuite = new benchmark_1.default.Suite("z.object: long");
+const empty = index_1.z.object({});
+const short = index_1.z.object({
+ string: index_1.z.string(),
+});
+const long = index_1.z.object({
+ string: index_1.z.string(),
+ number: index_1.z.number(),
+ boolean: index_1.z.boolean(),
+});
+emptySuite
+ .add("valid", () => {
+ empty.parse({});
+})
+ .add("valid: extra keys", () => {
+ empty.parse({ string: "string" });
+})
+ .add("invalid: null", () => {
+ try {
+ empty.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${emptySuite.name}: ${e.target}`);
+});
+shortSuite
+ .add("valid", () => {
+ short.parse({ string: "string" });
+})
+ .add("valid: extra keys", () => {
+ short.parse({ string: "string", number: 42 });
+})
+ .add("invalid: null", () => {
+ try {
+ short.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${shortSuite.name}: ${e.target}`);
+});
+longSuite
+ .add("valid", () => {
+ long.parse({ string: "string", number: 42, boolean: true });
+})
+ .add("valid: extra keys", () => {
+ long.parse({ string: "string", number: 42, boolean: true, list: [] });
+})
+ .add("invalid: null", () => {
+ try {
+ long.parse(null);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${longSuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [emptySuite, shortSuite, longSuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/primitives.d.ts b/node_modules/zod/lib/benchmarks/primitives.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/primitives.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/primitives.js b/node_modules/zod/lib/benchmarks/primitives.js
new file mode 100644
index 0000000..9ea5862
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/primitives.js
@@ -0,0 +1,136 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const Mocker_1 = require("../__tests__/Mocker");
+const index_1 = require("../index");
+const val = new Mocker_1.Mocker();
+const enumSuite = new benchmark_1.default.Suite("z.enum");
+const enumSchema = index_1.z.enum(["a", "b", "c"]);
+enumSuite
+ .add("valid", () => {
+ enumSchema.parse("a");
+})
+ .add("invalid", () => {
+ try {
+ enumSchema.parse("x");
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.enum: ${e.target}`);
+});
+const undefinedSuite = new benchmark_1.default.Suite("z.undefined");
+const undefinedSchema = index_1.z.undefined();
+undefinedSuite
+ .add("valid", () => {
+ undefinedSchema.parse(undefined);
+})
+ .add("invalid", () => {
+ try {
+ undefinedSchema.parse(1);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.undefined: ${e.target}`);
+});
+const literalSuite = new benchmark_1.default.Suite("z.literal");
+const short = "short";
+const bad = "bad";
+const literalSchema = index_1.z.literal("short");
+literalSuite
+ .add("valid", () => {
+ literalSchema.parse(short);
+})
+ .add("invalid", () => {
+ try {
+ literalSchema.parse(bad);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.literal: ${e.target}`);
+});
+const numberSuite = new benchmark_1.default.Suite("z.number");
+const numberSchema = index_1.z.number().int();
+numberSuite
+ .add("valid", () => {
+ numberSchema.parse(1);
+})
+ .add("invalid type", () => {
+ try {
+ numberSchema.parse("bad");
+ }
+ catch (e) { }
+})
+ .add("invalid number", () => {
+ try {
+ numberSchema.parse(0.5);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.number: ${e.target}`);
+});
+const dateSuite = new benchmark_1.default.Suite("z.date");
+const plainDate = index_1.z.date();
+const minMaxDate = index_1.z
+ .date()
+ .min(new Date("2021-01-01"))
+ .max(new Date("2030-01-01"));
+dateSuite
+ .add("valid", () => {
+ plainDate.parse(new Date());
+})
+ .add("invalid", () => {
+ try {
+ plainDate.parse(1);
+ }
+ catch (e) { }
+})
+ .add("valid min and max", () => {
+ minMaxDate.parse(new Date("2023-01-01"));
+})
+ .add("invalid min", () => {
+ try {
+ minMaxDate.parse(new Date("2019-01-01"));
+ }
+ catch (e) { }
+})
+ .add("invalid max", () => {
+ try {
+ minMaxDate.parse(new Date("2031-01-01"));
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.date: ${e.target}`);
+});
+const symbolSuite = new benchmark_1.default.Suite("z.symbol");
+const symbolSchema = index_1.z.symbol();
+symbolSuite
+ .add("valid", () => {
+ symbolSchema.parse(val.symbol);
+})
+ .add("invalid", () => {
+ try {
+ symbolSchema.parse(1);
+ }
+ catch (e) { }
+})
+ .on("cycle", (e) => {
+ console.log(`z.symbol: ${e.target}`);
+});
+exports.default = {
+ suites: [
+ enumSuite,
+ undefinedSuite,
+ literalSuite,
+ numberSuite,
+ dateSuite,
+ symbolSuite,
+ ],
+};
diff --git a/node_modules/zod/lib/benchmarks/realworld.d.ts b/node_modules/zod/lib/benchmarks/realworld.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/realworld.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/realworld.js b/node_modules/zod/lib/benchmarks/realworld.js
new file mode 100644
index 0000000..06f67ab
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/realworld.js
@@ -0,0 +1,56 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const shortSuite = new benchmark_1.default.Suite("realworld");
+const People = index_1.z.array(index_1.z.object({
+ type: index_1.z.literal("person"),
+ hair: index_1.z.enum(["blue", "brown"]),
+ active: index_1.z.boolean(),
+ name: index_1.z.string(),
+ age: index_1.z.number().int(),
+ hobbies: index_1.z.array(index_1.z.string()),
+ address: index_1.z.object({
+ street: index_1.z.string(),
+ zip: index_1.z.string(),
+ country: index_1.z.string(),
+ }),
+}));
+let i = 0;
+function num() {
+ return ++i;
+}
+function str() {
+ return (++i % 100).toString(16);
+}
+function array(fn) {
+ return Array.from({ length: ++i % 10 }, () => fn());
+}
+const people = Array.from({ length: 100 }, () => {
+ return {
+ type: "person",
+ hair: i % 2 ? "blue" : "brown",
+ active: !!(i % 2),
+ name: str(),
+ age: num(),
+ hobbies: array(str),
+ address: {
+ street: str(),
+ zip: str(),
+ country: str(),
+ },
+ };
+});
+shortSuite
+ .add("valid", () => {
+ People.parse(people);
+})
+ .on("cycle", (e) => {
+ console.log(`${shortSuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [shortSuite],
+};
diff --git a/node_modules/zod/lib/benchmarks/string.d.ts b/node_modules/zod/lib/benchmarks/string.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/string.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/string.js b/node_modules/zod/lib/benchmarks/string.js
new file mode 100644
index 0000000..14248d5
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/string.js
@@ -0,0 +1,55 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const SUITE_NAME = "z.string";
+const suite = new benchmark_1.default.Suite(SUITE_NAME);
+const empty = "";
+const short = "short";
+const long = "long".repeat(256);
+const manual = (str) => {
+ if (typeof str !== "string") {
+ throw new Error("Not a string");
+ }
+ return str;
+};
+const stringSchema = index_1.z.string();
+const optionalStringSchema = index_1.z.string().optional();
+const optionalNullableStringSchema = index_1.z.string().optional().nullable();
+suite
+ .add("empty string", () => {
+ stringSchema.parse(empty);
+})
+ .add("short string", () => {
+ stringSchema.parse(short);
+})
+ .add("long string", () => {
+ stringSchema.parse(long);
+})
+ .add("optional string", () => {
+ optionalStringSchema.parse(long);
+})
+ .add("nullable string", () => {
+ optionalNullableStringSchema.parse(long);
+})
+ .add("nullable (null) string", () => {
+ optionalNullableStringSchema.parse(null);
+})
+ .add("invalid: null", () => {
+ try {
+ stringSchema.parse(null);
+ }
+ catch (err) { }
+})
+ .add("manual parser: long", () => {
+ manual(long);
+})
+ .on("cycle", (e) => {
+ console.log(`${SUITE_NAME}: ${e.target}`);
+});
+exports.default = {
+ suites: [suite],
+};
diff --git a/node_modules/zod/lib/benchmarks/union.d.ts b/node_modules/zod/lib/benchmarks/union.d.ts
new file mode 100644
index 0000000..9d2c302
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/union.d.ts
@@ -0,0 +1,5 @@
+import Benchmark from "benchmark";
+declare const _default: {
+ suites: Benchmark.Suite[];
+};
+export default _default;
diff --git a/node_modules/zod/lib/benchmarks/union.js b/node_modules/zod/lib/benchmarks/union.js
new file mode 100644
index 0000000..0639e21
--- /dev/null
+++ b/node_modules/zod/lib/benchmarks/union.js
@@ -0,0 +1,79 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const benchmark_1 = __importDefault(require("benchmark"));
+const index_1 = require("../index");
+const doubleSuite = new benchmark_1.default.Suite("z.union: double");
+const manySuite = new benchmark_1.default.Suite("z.union: many");
+const aSchema = index_1.z.object({
+ type: index_1.z.literal("a"),
+});
+const objA = {
+ type: "a",
+};
+const bSchema = index_1.z.object({
+ type: index_1.z.literal("b"),
+});
+const objB = {
+ type: "b",
+};
+const cSchema = index_1.z.object({
+ type: index_1.z.literal("c"),
+});
+const objC = {
+ type: "c",
+};
+const dSchema = index_1.z.object({
+ type: index_1.z.literal("d"),
+});
+const double = index_1.z.union([aSchema, bSchema]);
+const many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]);
+doubleSuite
+ .add("valid: a", () => {
+ double.parse(objA);
+})
+ .add("valid: b", () => {
+ double.parse(objB);
+})
+ .add("invalid: null", () => {
+ try {
+ double.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ double.parse(objC);
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${doubleSuite.name}: ${e.target}`);
+});
+manySuite
+ .add("valid: a", () => {
+ many.parse(objA);
+})
+ .add("valid: c", () => {
+ many.parse(objC);
+})
+ .add("invalid: null", () => {
+ try {
+ many.parse(null);
+ }
+ catch (err) { }
+})
+ .add("invalid: wrong shape", () => {
+ try {
+ many.parse({ type: "unknown" });
+ }
+ catch (err) { }
+})
+ .on("cycle", (e) => {
+ console.log(`${manySuite.name}: ${e.target}`);
+});
+exports.default = {
+ suites: [doubleSuite, manySuite],
+};
diff --git a/node_modules/zod/lib/errors.d.ts b/node_modules/zod/lib/errors.d.ts
new file mode 100644
index 0000000..ebf6b0f
--- /dev/null
+++ b/node_modules/zod/lib/errors.d.ts
@@ -0,0 +1,5 @@
+import defaultErrorMap from "./locales/en";
+import type { ZodErrorMap } from "./ZodError";
+export { defaultErrorMap };
+export declare function setErrorMap(map: ZodErrorMap): void;
+export declare function getErrorMap(): ZodErrorMap;
diff --git a/node_modules/zod/lib/errors.js b/node_modules/zod/lib/errors.js
new file mode 100644
index 0000000..93c6bc1
--- /dev/null
+++ b/node_modules/zod/lib/errors.js
@@ -0,0 +1,17 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0;
+const en_1 = __importDefault(require("./locales/en"));
+exports.defaultErrorMap = en_1.default;
+let overrideErrorMap = en_1.default;
+function setErrorMap(map) {
+ overrideErrorMap = map;
+}
+exports.setErrorMap = setErrorMap;
+function getErrorMap() {
+ return overrideErrorMap;
+}
+exports.getErrorMap = getErrorMap;
diff --git a/node_modules/zod/lib/external.d.ts b/node_modules/zod/lib/external.d.ts
new file mode 100644
index 0000000..002e17d
--- /dev/null
+++ b/node_modules/zod/lib/external.d.ts
@@ -0,0 +1,6 @@
+export * from "./errors";
+export * from "./helpers/parseUtil";
+export * from "./helpers/typeAliases";
+export * from "./helpers/util";
+export * from "./types";
+export * from "./ZodError";
diff --git a/node_modules/zod/lib/external.js b/node_modules/zod/lib/external.js
new file mode 100644
index 0000000..48e6db2
--- /dev/null
+++ b/node_modules/zod/lib/external.js
@@ -0,0 +1,18 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./errors"), exports);
+__exportStar(require("./helpers/parseUtil"), exports);
+__exportStar(require("./helpers/typeAliases"), exports);
+__exportStar(require("./helpers/util"), exports);
+__exportStar(require("./types"), exports);
+__exportStar(require("./ZodError"), exports);
diff --git a/node_modules/zod/lib/helpers/enumUtil.d.ts b/node_modules/zod/lib/helpers/enumUtil.d.ts
new file mode 100644
index 0000000..fad28a7
--- /dev/null
+++ b/node_modules/zod/lib/helpers/enumUtil.d.ts
@@ -0,0 +1,8 @@
+export declare namespace enumUtil {
+ type UnionToIntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
+ type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last ? Last : never;
+ type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] ? Tuple : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>;
+ type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never;
+ export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>;
+ export {};
+}
diff --git a/node_modules/zod/lib/helpers/enumUtil.js b/node_modules/zod/lib/helpers/enumUtil.js
new file mode 100644
index 0000000..c8ad2e5
--- /dev/null
+++ b/node_modules/zod/lib/helpers/enumUtil.js
@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
diff --git a/node_modules/zod/lib/helpers/errorUtil.d.ts b/node_modules/zod/lib/helpers/errorUtil.d.ts
new file mode 100644
index 0000000..5346d72
--- /dev/null
+++ b/node_modules/zod/lib/helpers/errorUtil.d.ts
@@ -0,0 +1,9 @@
+export declare namespace errorUtil {
+ type ErrMessage = string | {
+ message?: string;
+ };
+ const errToObj: (message?: ErrMessage | undefined) => {
+ message?: string | undefined;
+ };
+ const toString: (message?: ErrMessage | undefined) => string | undefined;
+}
diff --git a/node_modules/zod/lib/helpers/errorUtil.js b/node_modules/zod/lib/helpers/errorUtil.js
new file mode 100644
index 0000000..7fa2797
--- /dev/null
+++ b/node_modules/zod/lib/helpers/errorUtil.js
@@ -0,0 +1,8 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.errorUtil = void 0;
+var errorUtil;
+(function (errorUtil) {
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
+})(errorUtil = exports.errorUtil || (exports.errorUtil = {}));
diff --git a/node_modules/zod/lib/helpers/parseUtil.d.ts b/node_modules/zod/lib/helpers/parseUtil.d.ts
new file mode 100644
index 0000000..f3f2bba
--- /dev/null
+++ b/node_modules/zod/lib/helpers/parseUtil.d.ts
@@ -0,0 +1,78 @@
+import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
+import type { ZodParsedType } from "./util";
+export declare const makeIssue: (params: {
+ data: any;
+ path: (string | number)[];
+ errorMaps: ZodErrorMap[];
+ issueData: IssueData;
+}) => ZodIssue;
+export declare type ParseParams = {
+ path: (string | number)[];
+ errorMap: ZodErrorMap;
+ async: boolean;
+};
+export declare type ParsePathComponent = string | number;
+export declare type ParsePath = ParsePathComponent[];
+export declare const EMPTY_PATH: ParsePath;
+export interface ParseContext {
+ readonly common: {
+ readonly issues: ZodIssue[];
+ readonly contextualErrorMap?: ZodErrorMap;
+ readonly async: boolean;
+ };
+ readonly path: ParsePath;
+ readonly schemaErrorMap?: ZodErrorMap;
+ readonly parent: ParseContext | null;
+ readonly data: any;
+ readonly parsedType: ZodParsedType;
+}
+export declare type ParseInput = {
+ data: any;
+ path: (string | number)[];
+ parent: ParseContext;
+};
+export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
+export declare type ObjectPair = {
+ key: SyncParseReturnType<any>;
+ value: SyncParseReturnType<any>;
+};
+export declare class ParseStatus {
+ value: "aborted" | "dirty" | "valid";
+ dirty(): void;
+ abort(): void;
+ static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType;
+ static mergeObjectAsync(status: ParseStatus, pairs: {
+ key: ParseReturnType<any>;
+ value: ParseReturnType<any>;
+ }[]): Promise<SyncParseReturnType<any>>;
+ static mergeObjectSync(status: ParseStatus, pairs: {
+ key: SyncParseReturnType<any>;
+ value: SyncParseReturnType<any>;
+ alwaysSet?: boolean;
+ }[]): SyncParseReturnType;
+}
+export interface ParseResult {
+ status: "aborted" | "dirty" | "valid";
+ data: any;
+}
+export declare type INVALID = {
+ status: "aborted";
+};
+export declare const INVALID: INVALID;
+export declare type DIRTY<T> = {
+ status: "dirty";
+ value: T;
+};
+export declare const DIRTY: <T>(value: T) => DIRTY<T>;
+export declare type OK<T> = {
+ status: "valid";
+ value: T;
+};
+export declare const OK: <T>(value: T) => OK<T>;
+export declare type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
+export declare type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
+export declare type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
+export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
+export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
+export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
+export declare const isAsync: <T>(x: ParseReturnType<T>) => x is AsyncParseReturnType<T>;
diff --git a/node_modules/zod/lib/helpers/parseUtil.js b/node_modules/zod/lib/helpers/parseUtil.js
new file mode 100644
index 0000000..5510257
--- /dev/null
+++ b/node_modules/zod/lib/helpers/parseUtil.js
@@ -0,0 +1,115 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
+const errors_1 = require("../errors");
+const en_1 = __importDefault(require("../locales/en"));
+const makeIssue = (params) => {
+ const { data, path, errorMaps, issueData } = params;
+ const fullPath = [...path, ...(issueData.path || [])];
+ const fullIssue = {
+ ...issueData,
+ path: fullPath,
+ };
+ let errorMessage = "";
+ const maps = errorMaps
+ .filter((m) => !!m)
+ .slice()
+ .reverse();
+ for (const map of maps) {
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
+ }
+ return {
+ ...issueData,
+ path: fullPath,
+ message: issueData.message || errorMessage,
+ };
+};
+exports.makeIssue = makeIssue;
+exports.EMPTY_PATH = [];
+function addIssueToContext(ctx, issueData) {
+ const issue = (0, exports.makeIssue)({
+ issueData: issueData,
+ data: ctx.data,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ (0, errors_1.getErrorMap)(),
+ en_1.default,
+ ].filter((x) => !!x),
+ });
+ ctx.common.issues.push(issue);
+}
+exports.addIssueToContext = addIssueToContext;
+class ParseStatus {
+ constructor() {
+ this.value = "valid";
+ }
+ dirty() {
+ if (this.value === "valid")
+ this.value = "dirty";
+ }
+ abort() {
+ if (this.value !== "aborted")
+ this.value = "aborted";
+ }
+ static mergeArray(status, results) {
+ const arrayValue = [];
+ for (const s of results) {
+ if (s.status === "aborted")
+ return exports.INVALID;
+ if (s.status === "dirty")
+ status.dirty();
+ arrayValue.push(s.value);
+ }
+ return { status: status.value, value: arrayValue };
+ }
+ static async mergeObjectAsync(status, pairs) {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ syncPairs.push({
+ key: await pair.key,
+ value: await pair.value,
+ });
+ }
+ return ParseStatus.mergeObjectSync(status, syncPairs);
+ }
+ static mergeObjectSync(status, pairs) {
+ const finalObject = {};
+ for (const pair of pairs) {
+ const { key, value } = pair;
+ if (key.status === "aborted")
+ return exports.INVALID;
+ if (value.status === "aborted")
+ return exports.INVALID;
+ if (key.status === "dirty")
+ status.dirty();
+ if (value.status === "dirty")
+ status.dirty();
+ if (key.value !== "__proto__" &&
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
+ finalObject[key.value] = value.value;
+ }
+ }
+ return { status: status.value, value: finalObject };
+ }
+}
+exports.ParseStatus = ParseStatus;
+exports.INVALID = Object.freeze({
+ status: "aborted",
+});
+const DIRTY = (value) => ({ status: "dirty", value });
+exports.DIRTY = DIRTY;
+const OK = (value) => ({ status: "valid", value });
+exports.OK = OK;
+const isAborted = (x) => x.status === "aborted";
+exports.isAborted = isAborted;
+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;
+exports.isAsync = isAsync;
diff --git a/node_modules/zod/lib/helpers/partialUtil.d.ts b/node_modules/zod/lib/helpers/partialUtil.d.ts
new file mode 100644
index 0000000..dd56a9d
--- /dev/null
+++ b/node_modules/zod/lib/helpers/partialUtil.d.ts
@@ -0,0 +1,8 @@
+import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index";
+export declare namespace partialUtil {
+ type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
+ [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
+ }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray<infer Type, infer Card> ? ZodArray<DeepPartial<Type>, Card> : T extends ZodOptional<infer Type> ? ZodOptional<DeepPartial<Type>> : T extends ZodNullable<infer Type> ? ZodNullable<DeepPartial<Type>> : T extends ZodTuple<infer Items> ? {
+ [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial<Items[k]> : never;
+ } extends infer PI ? PI extends ZodTupleItems ? ZodTuple<PI> : never : never : T;
+}
diff --git a/node_modules/zod/lib/helpers/partialUtil.js b/node_modules/zod/lib/helpers/partialUtil.js
new file mode 100644
index 0000000..c8ad2e5
--- /dev/null
+++ b/node_modules/zod/lib/helpers/partialUtil.js
@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
diff --git a/node_modules/zod/lib/helpers/typeAliases.d.ts b/node_modules/zod/lib/helpers/typeAliases.d.ts
new file mode 100644
index 0000000..aba4b3a
--- /dev/null
+++ b/node_modules/zod/lib/helpers/typeAliases.d.ts
@@ -0,0 +1,2 @@
+export declare type Primitive = string | number | symbol | bigint | boolean | null | undefined;
+export declare type Scalars = Primitive | Primitive[];
diff --git a/node_modules/zod/lib/helpers/typeAliases.js b/node_modules/zod/lib/helpers/typeAliases.js
new file mode 100644
index 0000000..c8ad2e5
--- /dev/null
+++ b/node_modules/zod/lib/helpers/typeAliases.js
@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
diff --git a/node_modules/zod/lib/helpers/util.d.ts b/node_modules/zod/lib/helpers/util.d.ts
new file mode 100644
index 0000000..d400ef6
--- /dev/null
+++ b/node_modules/zod/lib/helpers/util.d.ts
@@ -0,0 +1,68 @@
+export declare namespace util {
+ type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : false;
+ export type isAny<T> = 0 extends 1 & T ? true : false;
+ export const assertEqual: <A, B>(val: AssertEqual<A, B>) => AssertEqual<A, B>;
+ export function assertIs<T>(_arg: T): void;
+ export function assertNever(_x: never): never;
+ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
+ export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
+ export type MakePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
+ export const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
+ export const getValidEnumValues: (obj: any) => any[];
+ export const objectValues: (obj: any) => any[];
+ export const objectKeys: ObjectConstructor["keys"];
+ export const find: <T>(arr: T[], checker: (arg: T) => any) => T | undefined;
+ export type identity<T> = objectUtil.identity<T>;
+ export type flatten<T> = objectUtil.flatten<T>;
+ export type noUndefined<T> = T extends undefined ? never : T;
+ export const isInteger: NumberConstructor["isInteger"];
+ export function joinValues<T extends any[]>(array: T, separator?: string): string;
+ export const jsonStringifyReplacer: (_: string, value: any) => any;
+ export {};
+}
+export declare namespace objectUtil {
+ export type MergeShapes<U, V> = {
+ [k in Exclude<keyof U, keyof V>]: U[k];
+ } & V;
+ type requiredKeys<T extends object> = {
+ [k in keyof T]: undefined extends T[k] ? never : k;
+ }[keyof T];
+ export type addQuestionMarks<T extends object, R extends keyof T = requiredKeys<T>> = Pick<Required<T>, R> & Partial<T>;
+ export type identity<T> = T;
+ export type flatten<T> = identity<{
+ [k in keyof T]: T[k];
+ }>;
+ export type noNeverKeys<T> = {
+ [k in keyof T]: [T[k]] extends [never] ? never : k;
+ }[keyof T];
+ export type noNever<T> = identity<{
+ [k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
+ }>;
+ export const mergeShapes: <U, T>(first: U, second: T) => T & U;
+ export type extendShape<A, B> = flatten<Omit<A, keyof B> & B>;
+ export {};
+}
+export declare const ZodParsedType: {
+ function: "function";
+ number: "number";
+ string: "string";
+ nan: "nan";
+ integer: "integer";
+ float: "float";
+ boolean: "boolean";
+ date: "date";
+ bigint: "bigint";
+ symbol: "symbol";
+ undefined: "undefined";
+ null: "null";
+ array: "array";
+ object: "object";
+ unknown: "unknown";
+ promise: "promise";
+ void: "void";
+ never: "never";
+ map: "map";
+ set: "set";
+};
+export declare type ZodParsedType = keyof typeof ZodParsedType;
+export declare const getParsedType: (data: any) => ZodParsedType;
diff --git a/node_modules/zod/lib/helpers/util.js b/node_modules/zod/lib/helpers/util.js
new file mode 100644
index 0000000..d35a6eb
--- /dev/null
+++ b/node_modules/zod/lib/helpers/util.js
@@ -0,0 +1,142 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
+var util;
+(function (util) {
+ util.assertEqual = (val) => val;
+ function assertIs(_arg) { }
+ util.assertIs = assertIs;
+ function assertNever(_x) {
+ throw new Error();
+ }
+ util.assertNever = assertNever;
+ util.arrayToEnum = (items) => {
+ const obj = {};
+ for (const item of items) {
+ obj[item] = item;
+ }
+ return obj;
+ };
+ util.getValidEnumValues = (obj) => {
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
+ const filtered = {};
+ for (const k of validKeys) {
+ filtered[k] = obj[k];
+ }
+ return util.objectValues(filtered);
+ };
+ util.objectValues = (obj) => {
+ return util.objectKeys(obj).map(function (e) {
+ return obj[e];
+ });
+ };
+ util.objectKeys = typeof Object.keys === "function"
+ ? (obj) => Object.keys(obj)
+ : (object) => {
+ const keys = [];
+ for (const key in object) {
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
+ keys.push(key);
+ }
+ }
+ return keys;
+ };
+ util.find = (arr, checker) => {
+ for (const item of arr) {
+ if (checker(item))
+ return item;
+ }
+ return undefined;
+ };
+ util.isInteger = typeof Number.isInteger === "function"
+ ? (val) => Number.isInteger(val)
+ : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
+ function joinValues(array, separator = " | ") {
+ return array
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
+ .join(separator);
+ }
+ util.joinValues = joinValues;
+ util.jsonStringifyReplacer = (_, value) => {
+ if (typeof value === "bigint") {
+ return value.toString();
+ }
+ return value;
+ };
+})(util = exports.util || (exports.util = {}));
+var objectUtil;
+(function (objectUtil) {
+ objectUtil.mergeShapes = (first, second) => {
+ return {
+ ...first,
+ ...second,
+ };
+ };
+})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
+exports.ZodParsedType = util.arrayToEnum([
+ "string",
+ "nan",
+ "number",
+ "integer",
+ "float",
+ "boolean",
+ "date",
+ "bigint",
+ "symbol",
+ "function",
+ "undefined",
+ "null",
+ "array",
+ "object",
+ "unknown",
+ "promise",
+ "void",
+ "never",
+ "map",
+ "set",
+]);
+const getParsedType = (data) => {
+ const t = typeof data;
+ switch (t) {
+ case "undefined":
+ return exports.ZodParsedType.undefined;
+ case "string":
+ return exports.ZodParsedType.string;
+ case "number":
+ return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
+ case "boolean":
+ return exports.ZodParsedType.boolean;
+ case "function":
+ return exports.ZodParsedType.function;
+ case "bigint":
+ return exports.ZodParsedType.bigint;
+ case "symbol":
+ return exports.ZodParsedType.symbol;
+ case "object":
+ if (Array.isArray(data)) {
+ return exports.ZodParsedType.array;
+ }
+ if (data === null) {
+ return exports.ZodParsedType.null;
+ }
+ if (data.then &&
+ typeof data.then === "function" &&
+ data.catch &&
+ typeof data.catch === "function") {
+ return exports.ZodParsedType.promise;
+ }
+ if (typeof Map !== "undefined" && data instanceof Map) {
+ return exports.ZodParsedType.map;
+ }
+ if (typeof Set !== "undefined" && data instanceof Set) {
+ return exports.ZodParsedType.set;
+ }
+ if (typeof Date !== "undefined" && data instanceof Date) {
+ return exports.ZodParsedType.date;
+ }
+ return exports.ZodParsedType.object;
+ default:
+ return exports.ZodParsedType.unknown;
+ }
+};
+exports.getParsedType = getParsedType;
diff --git a/node_modules/zod/lib/index.d.ts b/node_modules/zod/lib/index.d.ts
new file mode 100644
index 0000000..e6a2db6
--- /dev/null
+++ b/node_modules/zod/lib/index.d.ts
@@ -0,0 +1,4 @@
+import * as z from "./external";
+export * from "./external";
+export { z };
+export default z;
diff --git a/node_modules/zod/lib/index.js b/node_modules/zod/lib/index.js
new file mode 100644
index 0000000..1875b39
--- /dev/null
+++ b/node_modules/zod/lib/index.js
@@ -0,0 +1,29 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.z = void 0;
+const z = __importStar(require("./external"));
+exports.z = z;
+__exportStar(require("./external"), exports);
+exports.default = z;
diff --git a/node_modules/zod/lib/index.mjs b/node_modules/zod/lib/index.mjs
new file mode 100644
index 0000000..a6b6c35
--- /dev/null
+++ b/node_modules/zod/lib/index.mjs
@@ -0,0 +1,4006 @@
+var util;
+(function (util) {
+ util.assertEqual = (val) => val;
+ function assertIs(_arg) { }
+ util.assertIs = assertIs;
+ function assertNever(_x) {
+ throw new Error();
+ }
+ util.assertNever = assertNever;
+ util.arrayToEnum = (items) => {
+ const obj = {};
+ for (const item of items) {
+ obj[item] = item;
+ }
+ return obj;
+ };
+ util.getValidEnumValues = (obj) => {
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
+ const filtered = {};
+ for (const k of validKeys) {
+ filtered[k] = obj[k];
+ }
+ return util.objectValues(filtered);
+ };
+ util.objectValues = (obj) => {
+ return util.objectKeys(obj).map(function (e) {
+ return obj[e];
+ });
+ };
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
+ : (object) => {
+ const keys = [];
+ for (const key in object) {
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
+ keys.push(key);
+ }
+ }
+ return keys;
+ };
+ util.find = (arr, checker) => {
+ for (const item of arr) {
+ if (checker(item))
+ return item;
+ }
+ return undefined;
+ };
+ util.isInteger = typeof Number.isInteger === "function"
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
+ : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
+ function joinValues(array, separator = " | ") {
+ return array
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
+ .join(separator);
+ }
+ util.joinValues = joinValues;
+ util.jsonStringifyReplacer = (_, value) => {
+ if (typeof value === "bigint") {
+ return value.toString();
+ }
+ return value;
+ };
+})(util || (util = {}));
+var objectUtil;
+(function (objectUtil) {
+ objectUtil.mergeShapes = (first, second) => {
+ return {
+ ...first,
+ ...second, // second overwrites first
+ };
+ };
+})(objectUtil || (objectUtil = {}));
+const ZodParsedType = util.arrayToEnum([
+ "string",
+ "nan",
+ "number",
+ "integer",
+ "float",
+ "boolean",
+ "date",
+ "bigint",
+ "symbol",
+ "function",
+ "undefined",
+ "null",
+ "array",
+ "object",
+ "unknown",
+ "promise",
+ "void",
+ "never",
+ "map",
+ "set",
+]);
+const getParsedType = (data) => {
+ const t = typeof data;
+ switch (t) {
+ case "undefined":
+ return ZodParsedType.undefined;
+ case "string":
+ return ZodParsedType.string;
+ case "number":
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
+ case "boolean":
+ return ZodParsedType.boolean;
+ case "function":
+ return ZodParsedType.function;
+ case "bigint":
+ return ZodParsedType.bigint;
+ case "symbol":
+ return ZodParsedType.symbol;
+ case "object":
+ if (Array.isArray(data)) {
+ return ZodParsedType.array;
+ }
+ if (data === null) {
+ return ZodParsedType.null;
+ }
+ if (data.then &&
+ typeof data.then === "function" &&
+ data.catch &&
+ typeof data.catch === "function") {
+ return ZodParsedType.promise;
+ }
+ if (typeof Map !== "undefined" && data instanceof Map) {
+ return ZodParsedType.map;
+ }
+ if (typeof Set !== "undefined" && data instanceof Set) {
+ return ZodParsedType.set;
+ }
+ if (typeof Date !== "undefined" && data instanceof Date) {
+ return ZodParsedType.date;
+ }
+ return ZodParsedType.object;
+ default:
+ return ZodParsedType.unknown;
+ }
+};
+
+const ZodIssueCode = util.arrayToEnum([
+ "invalid_type",
+ "invalid_literal",
+ "custom",
+ "invalid_union",
+ "invalid_union_discriminator",
+ "invalid_enum_value",
+ "unrecognized_keys",
+ "invalid_arguments",
+ "invalid_return_type",
+ "invalid_date",
+ "invalid_string",
+ "too_small",
+ "too_big",
+ "invalid_intersection_types",
+ "not_multiple_of",
+ "not_finite",
+]);
+const quotelessJson = (obj) => {
+ const json = JSON.stringify(obj, null, 2);
+ return json.replace(/"([^"]+)":/g, "$1:");
+};
+class ZodError extends Error {
+ constructor(issues) {
+ super();
+ this.issues = [];
+ this.addIssue = (sub) => {
+ this.issues = [...this.issues, sub];
+ };
+ this.addIssues = (subs = []) => {
+ this.issues = [...this.issues, ...subs];
+ };
+ const actualProto = new.target.prototype;
+ if (Object.setPrototypeOf) {
+ // eslint-disable-next-line ban/ban
+ Object.setPrototypeOf(this, actualProto);
+ }
+ else {
+ this.__proto__ = actualProto;
+ }
+ this.name = "ZodError";
+ this.issues = issues;
+ }
+ get errors() {
+ return this.issues;
+ }
+ format(_mapper) {
+ const mapper = _mapper ||
+ function (issue) {
+ return issue.message;
+ };
+ const fieldErrors = { _errors: [] };
+ const processError = (error) => {
+ for (const issue of error.issues) {
+ if (issue.code === "invalid_union") {
+ issue.unionErrors.map(processError);
+ }
+ else if (issue.code === "invalid_return_type") {
+ processError(issue.returnTypeError);
+ }
+ else if (issue.code === "invalid_arguments") {
+ processError(issue.argumentsError);
+ }
+ else if (issue.path.length === 0) {
+ fieldErrors._errors.push(mapper(issue));
+ }
+ else {
+ let curr = fieldErrors;
+ let i = 0;
+ while (i < issue.path.length) {
+ const el = issue.path[i];
+ const terminal = i === issue.path.length - 1;
+ if (!terminal) {
+ curr[el] = curr[el] || { _errors: [] };
+ // if (typeof el === "string") {
+ // curr[el] = curr[el] || { _errors: [] };
+ // } else if (typeof el === "number") {
+ // const errorArray: any = [];
+ // errorArray._errors = [];
+ // curr[el] = curr[el] || errorArray;
+ // }
+ }
+ else {
+ curr[el] = curr[el] || { _errors: [] };
+ curr[el]._errors.push(mapper(issue));
+ }
+ curr = curr[el];
+ i++;
+ }
+ }
+ }
+ };
+ processError(this);
+ return fieldErrors;
+ }
+ toString() {
+ return this.message;
+ }
+ get message() {
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
+ }
+ get isEmpty() {
+ return this.issues.length === 0;
+ }
+ flatten(mapper = (issue) => issue.message) {
+ const fieldErrors = {};
+ const formErrors = [];
+ for (const sub of this.issues) {
+ if (sub.path.length > 0) {
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
+ fieldErrors[sub.path[0]].push(mapper(sub));
+ }
+ else {
+ formErrors.push(mapper(sub));
+ }
+ }
+ return { formErrors, fieldErrors };
+ }
+ get formErrors() {
+ return this.flatten();
+ }
+}
+ZodError.create = (issues) => {
+ const error = new ZodError(issues);
+ return error;
+};
+
+const errorMap = (issue, _ctx) => {
+ let message;
+ switch (issue.code) {
+ case ZodIssueCode.invalid_type:
+ if (issue.received === ZodParsedType.undefined) {
+ message = "Required";
+ }
+ else {
+ message = `Expected ${issue.expected}, received ${issue.received}`;
+ }
+ break;
+ case ZodIssueCode.invalid_literal:
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
+ break;
+ case ZodIssueCode.unrecognized_keys:
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
+ break;
+ case ZodIssueCode.invalid_union:
+ message = `Invalid input`;
+ break;
+ case ZodIssueCode.invalid_union_discriminator:
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
+ break;
+ case ZodIssueCode.invalid_enum_value:
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
+ break;
+ case ZodIssueCode.invalid_arguments:
+ message = `Invalid function arguments`;
+ break;
+ case ZodIssueCode.invalid_return_type:
+ message = `Invalid function return type`;
+ break;
+ case ZodIssueCode.invalid_date:
+ message = `Invalid date`;
+ break;
+ case ZodIssueCode.invalid_string:
+ if (typeof issue.validation === "object") {
+ if ("includes" in issue.validation) {
+ message = `Invalid input: must include "${issue.validation.includes}"`;
+ if (typeof issue.validation.position === "number") {
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
+ }
+ }
+ else if ("startsWith" in issue.validation) {
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
+ }
+ else if ("endsWith" in issue.validation) {
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
+ }
+ else {
+ util.assertNever(issue.validation);
+ }
+ }
+ else if (issue.validation !== "regex") {
+ message = `Invalid ${issue.validation}`;
+ }
+ else {
+ message = "Invalid";
+ }
+ break;
+ case ZodIssueCode.too_small:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${issue.minimum}`;
+ else if (issue.type === "date")
+ message = `Date must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${new Date(Number(issue.minimum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodIssueCode.too_big:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `less than or equal to`
+ : `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")
+ message = `Date must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `smaller than or equal to`
+ : `smaller than`} ${new Date(Number(issue.maximum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodIssueCode.custom:
+ message = `Invalid input`;
+ break;
+ case ZodIssueCode.invalid_intersection_types:
+ message = `Intersection results could not be merged`;
+ break;
+ case ZodIssueCode.not_multiple_of:
+ message = `Number must be a multiple of ${issue.multipleOf}`;
+ break;
+ case ZodIssueCode.not_finite:
+ message = "Number must be finite";
+ break;
+ default:
+ message = _ctx.defaultError;
+ util.assertNever(issue);
+ }
+ return { message };
+};
+
+let overrideErrorMap = errorMap;
+function setErrorMap(map) {
+ overrideErrorMap = map;
+}
+function getErrorMap() {
+ return overrideErrorMap;
+}
+
+const makeIssue = (params) => {
+ const { data, path, errorMaps, issueData } = params;
+ const fullPath = [...path, ...(issueData.path || [])];
+ const fullIssue = {
+ ...issueData,
+ path: fullPath,
+ };
+ let errorMessage = "";
+ const maps = errorMaps
+ .filter((m) => !!m)
+ .slice()
+ .reverse();
+ for (const map of maps) {
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
+ }
+ return {
+ ...issueData,
+ path: fullPath,
+ message: issueData.message || errorMessage,
+ };
+};
+const EMPTY_PATH = [];
+function addIssueToContext(ctx, issueData) {
+ const issue = makeIssue({
+ issueData: issueData,
+ data: ctx.data,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap, // then global default map
+ ].filter((x) => !!x),
+ });
+ ctx.common.issues.push(issue);
+}
+class ParseStatus {
+ constructor() {
+ this.value = "valid";
+ }
+ dirty() {
+ if (this.value === "valid")
+ this.value = "dirty";
+ }
+ abort() {
+ if (this.value !== "aborted")
+ this.value = "aborted";
+ }
+ static mergeArray(status, results) {
+ const arrayValue = [];
+ for (const s of results) {
+ if (s.status === "aborted")
+ return INVALID;
+ if (s.status === "dirty")
+ status.dirty();
+ arrayValue.push(s.value);
+ }
+ return { status: status.value, value: arrayValue };
+ }
+ static async mergeObjectAsync(status, pairs) {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ syncPairs.push({
+ key: await pair.key,
+ value: await pair.value,
+ });
+ }
+ return ParseStatus.mergeObjectSync(status, syncPairs);
+ }
+ static mergeObjectSync(status, pairs) {
+ const finalObject = {};
+ for (const pair of pairs) {
+ const { key, value } = pair;
+ if (key.status === "aborted")
+ return INVALID;
+ if (value.status === "aborted")
+ return INVALID;
+ if (key.status === "dirty")
+ status.dirty();
+ if (value.status === "dirty")
+ status.dirty();
+ if (key.value !== "__proto__" &&
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
+ finalObject[key.value] = value.value;
+ }
+ }
+ return { status: status.value, value: finalObject };
+ }
+}
+const INVALID = Object.freeze({
+ status: "aborted",
+});
+const DIRTY = (value) => ({ status: "dirty", value });
+const OK = (value) => ({ status: "valid", value });
+const isAborted = (x) => x.status === "aborted";
+const isDirty = (x) => x.status === "dirty";
+const isValid = (x) => x.status === "valid";
+const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
+
+var errorUtil;
+(function (errorUtil) {
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
+})(errorUtil || (errorUtil = {}));
+
+class ParseInputLazyPath {
+ constructor(parent, value, path, key) {
+ this._cachedPath = [];
+ this.parent = parent;
+ this.data = value;
+ this._path = path;
+ this._key = key;
+ }
+ get path() {
+ if (!this._cachedPath.length) {
+ if (this._key instanceof Array) {
+ this._cachedPath.push(...this._path, ...this._key);
+ }
+ else {
+ this._cachedPath.push(...this._path, this._key);
+ }
+ }
+ return this._cachedPath;
+ }
+}
+const handleResult = (ctx, result) => {
+ if (isValid(result)) {
+ return { success: true, data: result.value };
+ }
+ else {
+ if (!ctx.common.issues.length) {
+ throw new Error("Validation failed but no issues detected.");
+ }
+ return {
+ success: false,
+ get error() {
+ if (this._error)
+ return this._error;
+ const error = new ZodError(ctx.common.issues);
+ this._error = error;
+ return this._error;
+ },
+ };
+ }
+};
+function processCreateParams(params) {
+ if (!params)
+ return {};
+ const { errorMap, invalid_type_error, required_error, description } = params;
+ if (errorMap && (invalid_type_error || required_error)) {
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
+ }
+ if (errorMap)
+ return { errorMap: errorMap, description };
+ const customMap = (iss, ctx) => {
+ if (iss.code !== "invalid_type")
+ return { message: ctx.defaultError };
+ if (typeof ctx.data === "undefined") {
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
+ }
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
+ };
+ return { errorMap: customMap, description };
+}
+class ZodType {
+ constructor(def) {
+ /** Alias of safeParseAsync */
+ this.spa = this.safeParseAsync;
+ this._def = def;
+ this.parse = this.parse.bind(this);
+ this.safeParse = this.safeParse.bind(this);
+ this.parseAsync = this.parseAsync.bind(this);
+ this.safeParseAsync = this.safeParseAsync.bind(this);
+ this.spa = this.spa.bind(this);
+ this.refine = this.refine.bind(this);
+ this.refinement = this.refinement.bind(this);
+ this.superRefine = this.superRefine.bind(this);
+ this.optional = this.optional.bind(this);
+ this.nullable = this.nullable.bind(this);
+ this.nullish = this.nullish.bind(this);
+ this.array = this.array.bind(this);
+ this.promise = this.promise.bind(this);
+ this.or = this.or.bind(this);
+ this.and = this.and.bind(this);
+ this.transform = this.transform.bind(this);
+ this.brand = this.brand.bind(this);
+ this.default = this.default.bind(this);
+ this.catch = this.catch.bind(this);
+ this.describe = this.describe.bind(this);
+ this.pipe = this.pipe.bind(this);
+ this.readonly = this.readonly.bind(this);
+ this.isNullable = this.isNullable.bind(this);
+ this.isOptional = this.isOptional.bind(this);
+ }
+ get description() {
+ return this._def.description;
+ }
+ _getType(input) {
+ return getParsedType(input.data);
+ }
+ _getOrReturnCtx(input, ctx) {
+ return (ctx || {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: getParsedType(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ });
+ }
+ _processInputParams(input) {
+ return {
+ status: new ParseStatus(),
+ ctx: {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: getParsedType(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ },
+ };
+ }
+ _parseSync(input) {
+ const result = this._parse(input);
+ if (isAsync(result)) {
+ throw new Error("Synchronous parse encountered promise.");
+ }
+ return result;
+ }
+ _parseAsync(input) {
+ const result = this._parse(input);
+ return Promise.resolve(result);
+ }
+ parse(data, params) {
+ const result = this.safeParse(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ safeParse(data, params) {
+ var _a;
+ const ctx = {
+ common: {
+ issues: [],
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: getParsedType(data),
+ };
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
+ return handleResult(ctx, result);
+ }
+ async parseAsync(data, params) {
+ const result = await this.safeParseAsync(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ async safeParseAsync(data, params) {
+ const ctx = {
+ common: {
+ issues: [],
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ async: true,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: getParsedType(data),
+ };
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
+ const result = await (isAsync(maybeAsyncResult)
+ ? maybeAsyncResult
+ : Promise.resolve(maybeAsyncResult));
+ return handleResult(ctx, result);
+ }
+ refine(check, message) {
+ const getIssueProperties = (val) => {
+ if (typeof message === "string" || typeof message === "undefined") {
+ return { message };
+ }
+ else if (typeof message === "function") {
+ return message(val);
+ }
+ else {
+ return message;
+ }
+ };
+ return this._refinement((val, ctx) => {
+ const result = check(val);
+ const setError = () => ctx.addIssue({
+ code: ZodIssueCode.custom,
+ ...getIssueProperties(val),
+ });
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
+ return result.then((data) => {
+ if (!data) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ if (!result) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ refinement(check, refinementData) {
+ return this._refinement((val, ctx) => {
+ if (!check(val)) {
+ ctx.addIssue(typeof refinementData === "function"
+ ? refinementData(val, ctx)
+ : refinementData);
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ _refinement(refinement) {
+ return new ZodEffects({
+ schema: this,
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ effect: { type: "refinement", refinement },
+ });
+ }
+ superRefine(refinement) {
+ return this._refinement(refinement);
+ }
+ optional() {
+ return ZodOptional.create(this, this._def);
+ }
+ nullable() {
+ return ZodNullable.create(this, this._def);
+ }
+ nullish() {
+ return this.nullable().optional();
+ }
+ array() {
+ return ZodArray.create(this, this._def);
+ }
+ promise() {
+ return ZodPromise.create(this, this._def);
+ }
+ or(option) {
+ return ZodUnion.create([this, option], this._def);
+ }
+ and(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 },
+ });
+ }
+ default(def) {
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodDefault({
+ ...processCreateParams(this._def),
+ innerType: this,
+ defaultValue: defaultValueFunc,
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
+ });
+ }
+ brand() {
+ return new ZodBranded({
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
+ type: this,
+ ...processCreateParams(this._def),
+ });
+ }
+ catch(def) {
+ const catchValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodCatch({
+ ...processCreateParams(this._def),
+ innerType: this,
+ catchValue: catchValueFunc,
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
+ });
+ }
+ describe(description) {
+ const This = this.constructor;
+ return new This({
+ ...this._def,
+ description,
+ });
+ }
+ pipe(target) {
+ return ZodPipeline.create(this, target);
+ }
+ readonly() {
+ return ZodReadonly.create(this);
+ }
+ isOptional() {
+ return this.safeParse(undefined).success;
+ }
+ isNullable() {
+ return this.safeParse(null).success;
+ }
+}
+const cuidRegex = /^c[^\s-]{8,}$/i;
+const cuid2Regex = /^[a-z][a-z0-9]*$/;
+const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
+// const uuidRegex =
+// /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
+const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
+// 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@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
+// const emailRegex =
+// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
+// const emailRegex =
+// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
+const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
+// const emailRegex =
+// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
+// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
+const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
+const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
+const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
+// Adapted from https://stackoverflow.com/a/3143231
+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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
+ }
+ }
+};
+function isValidIP(ip, version) {
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
+ return true;
+ }
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
+ return true;
+ }
+ return false;
+}
+class ZodString extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
+ validation,
+ code: ZodIssueCode.invalid_string,
+ ...errorUtil.errToObj(message),
+ });
+ /**
+ * @deprecated Use z.string().min(1) instead.
+ * @see {@link ZodString.min}
+ */
+ this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
+ this.trim = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "trim" }],
+ });
+ this.toLowerCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
+ });
+ this.toUpperCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
+ });
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = String(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.string) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.string,
+ received: ctx.parsedType,
+ }
+ //
+ );
+ return INVALID;
+ }
+ const status = new ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.length < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.length > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "length") {
+ const tooBig = input.data.length > check.value;
+ const tooSmall = input.data.length < check.value;
+ if (tooBig || tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ if (tooBig) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ else if (tooSmall) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ status.dirty();
+ }
+ }
+ else if (check.kind === "email") {
+ if (!emailRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "email",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "emoji") {
+ if (!emojiRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "emoji",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "uuid") {
+ if (!uuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "uuid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "cuid") {
+ if (!cuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "cuid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "cuid2") {
+ if (!cuid2Regex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "cuid2",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "ulid") {
+ if (!ulidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "ulid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "url") {
+ try {
+ new URL(input.data);
+ }
+ catch (_a) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "url",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "regex") {
+ check.regex.lastIndex = 0;
+ const testResult = check.regex.test(input.data);
+ if (!testResult) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "regex",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "trim") {
+ input.data = input.data.trim();
+ }
+ else if (check.kind === "includes") {
+ if (!input.data.includes(check.value, check.position)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { includes: check.value, position: check.position },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "toLowerCase") {
+ input.data = input.data.toLowerCase();
+ }
+ else if (check.kind === "toUpperCase") {
+ input.data = input.data.toUpperCase();
+ }
+ else if (check.kind === "startsWith") {
+ if (!input.data.startsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { startsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "endsWith") {
+ if (!input.data.endsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { endsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "datetime") {
+ const regex = datetimeRegex(check);
+ if (!regex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: "datetime",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "ip") {
+ if (!isValidIP(input.data, check.version)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "ip",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ _addCheck(check) {
+ return new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ email(message) {
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
+ }
+ url(message) {
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
+ }
+ emoji(message) {
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
+ }
+ uuid(message) {
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
+ }
+ cuid(message) {
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
+ }
+ cuid2(message) {
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
+ }
+ ulid(message) {
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
+ }
+ ip(options) {
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
+ }
+ datetime(options) {
+ var _a;
+ if (typeof options === "string") {
+ return this._addCheck({
+ kind: "datetime",
+ precision: null,
+ offset: false,
+ message: options,
+ });
+ }
+ return this._addCheck({
+ kind: "datetime",
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ regex(regex, message) {
+ return this._addCheck({
+ kind: "regex",
+ regex: regex,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ includes(value, options) {
+ return this._addCheck({
+ kind: "includes",
+ value: value,
+ position: options === null || options === void 0 ? void 0 : options.position,
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ startsWith(value, message) {
+ return this._addCheck({
+ kind: "startsWith",
+ value: value,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ endsWith(value, message) {
+ return this._addCheck({
+ kind: "endsWith",
+ value: value,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ min(minLength, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minLength,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ max(maxLength, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxLength,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ length(len, message) {
+ return this._addCheck({
+ kind: "length",
+ value: len,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ get isDatetime() {
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
+ }
+ get isEmail() {
+ return !!this._def.checks.find((ch) => ch.kind === "email");
+ }
+ get isURL() {
+ return !!this._def.checks.find((ch) => ch.kind === "url");
+ }
+ get isEmoji() {
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
+ }
+ get isUUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
+ }
+ get isCUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
+ }
+ get isCUID2() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
+ }
+ get isULID() {
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
+ }
+ get isIP() {
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
+ }
+ get minLength() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxLength() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+}
+ZodString.create = (params) => {
+ var _a;
+ return new ZodString({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodString,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+};
+// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
+function floatSafeRemainder(val, step) {
+ const valDecCount = (val.toString().split(".")[1] || "").length;
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
+ return (valInt % stepInt) / Math.pow(10, decCount);
+}
+class ZodNumber extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ this.step = this.multipleOf;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Number(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.number) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.number,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ let ctx = undefined;
+ const status = new ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "int") {
+ if (!util.isInteger(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: "integer",
+ received: "float",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "finite") {
+ if (!Number.isFinite(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_finite,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ int(message) {
+ return this._addCheck({
+ kind: "int",
+ message: errorUtil.toString(message),
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value: value,
+ message: errorUtil.toString(message),
+ });
+ }
+ finite(message) {
+ return this._addCheck({
+ kind: "finite",
+ message: errorUtil.toString(message),
+ });
+ }
+ safe(message) {
+ return this._addCheck({
+ kind: "min",
+ inclusive: true,
+ value: Number.MIN_SAFE_INTEGER,
+ message: errorUtil.toString(message),
+ })._addCheck({
+ kind: "max",
+ inclusive: true,
+ value: Number.MAX_SAFE_INTEGER,
+ message: errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+ get isInt() {
+ return !!this._def.checks.find((ch) => ch.kind === "int" ||
+ (ch.kind === "multipleOf" && 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);
+ }
+}
+ZodNumber.create = (params) => {
+ return new ZodNumber({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+};
+class ZodBigInt extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = BigInt(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.bigint) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.bigint,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ let ctx = undefined;
+ const status = new ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ type: "bigint",
+ minimum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ type: "bigint",
+ maximum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (input.data % check.value !== BigInt(0)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value,
+ message: errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+}
+ZodBigInt.create = (params) => {
+ var _a;
+ return new ZodBigInt({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+};
+class ZodBoolean extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Boolean(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.boolean) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.boolean,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+}
+ZodBoolean.create = (params) => {
+ return new ZodBoolean({
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+};
+class ZodDate extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = new Date(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.date) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.date,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (isNaN(input.data.getTime())) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_date,
+ });
+ return INVALID;
+ }
+ const status = new ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.getTime() < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ minimum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.getTime() > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ maximum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util.assertNever(check);
+ }
+ }
+ return {
+ status: status.value,
+ value: new Date(input.data.getTime()),
+ };
+ }
+ _addCheck(check) {
+ return new ZodDate({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ min(minDate, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minDate.getTime(),
+ message: errorUtil.toString(message),
+ });
+ }
+ max(maxDate, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxDate.getTime(),
+ message: errorUtil.toString(message),
+ });
+ }
+ get minDate() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min != null ? new Date(min) : null;
+ }
+ get maxDate() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max != null ? new Date(max) : null;
+ }
+}
+ZodDate.create = (params) => {
+ return new ZodDate({
+ checks: [],
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ typeName: ZodFirstPartyTypeKind.ZodDate,
+ ...processCreateParams(params),
+ });
+};
+class ZodSymbol extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.symbol) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.symbol,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+}
+ZodSymbol.create = (params) => {
+ return new ZodSymbol({
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
+ ...processCreateParams(params),
+ });
+};
+class ZodUndefined extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.undefined,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+}
+ZodUndefined.create = (params) => {
+ return new ZodUndefined({
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
+ ...processCreateParams(params),
+ });
+};
+class ZodNull extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.null) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.null,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+}
+ZodNull.create = (params) => {
+ return new ZodNull({
+ typeName: ZodFirstPartyTypeKind.ZodNull,
+ ...processCreateParams(params),
+ });
+};
+class ZodAny extends ZodType {
+ constructor() {
+ super(...arguments);
+ // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
+ this._any = true;
+ }
+ _parse(input) {
+ return OK(input.data);
+ }
+}
+ZodAny.create = (params) => {
+ return new ZodAny({
+ typeName: ZodFirstPartyTypeKind.ZodAny,
+ ...processCreateParams(params),
+ });
+};
+class ZodUnknown extends ZodType {
+ constructor() {
+ super(...arguments);
+ // required
+ this._unknown = true;
+ }
+ _parse(input) {
+ return OK(input.data);
+ }
+}
+ZodUnknown.create = (params) => {
+ return new ZodUnknown({
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
+ ...processCreateParams(params),
+ });
+};
+class ZodNever extends ZodType {
+ _parse(input) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.never,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+}
+ZodNever.create = (params) => {
+ return new ZodNever({
+ typeName: ZodFirstPartyTypeKind.ZodNever,
+ ...processCreateParams(params),
+ });
+};
+class ZodVoid extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.void,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+}
+ZodVoid.create = (params) => {
+ return new ZodVoid({
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
+ ...processCreateParams(params),
+ });
+};
+class ZodArray extends ZodType {
+ _parse(input) {
+ const { ctx, status } = this._processInputParams(input);
+ const def = this._def;
+ if (ctx.parsedType !== ZodParsedType.array) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (def.exactLength !== null) {
+ const tooBig = ctx.data.length > def.exactLength.value;
+ const tooSmall = ctx.data.length < def.exactLength.value;
+ if (tooBig || tooSmall) {
+ addIssueToContext(ctx, {
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
+ minimum: (tooSmall ? def.exactLength.value : undefined),
+ maximum: (tooBig ? def.exactLength.value : undefined),
+ type: "array",
+ inclusive: true,
+ exact: true,
+ message: def.exactLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.minLength !== null) {
+ if (ctx.data.length < def.minLength.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: def.minLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.minLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxLength !== null) {
+ if (ctx.data.length > def.maxLength.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: def.maxLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.maxLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (ctx.common.async) {
+ return Promise.all([...ctx.data].map((item, i) => {
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
+ })).then((result) => {
+ return ParseStatus.mergeArray(status, result);
+ });
+ }
+ const result = [...ctx.data].map((item, i) => {
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
+ });
+ return ParseStatus.mergeArray(status, result);
+ }
+ get element() {
+ return this._def.type;
+ }
+ min(minLength, message) {
+ return new ZodArray({
+ ...this._def,
+ minLength: { value: minLength, message: errorUtil.toString(message) },
+ });
+ }
+ max(maxLength, message) {
+ return new ZodArray({
+ ...this._def,
+ maxLength: { value: maxLength, message: errorUtil.toString(message) },
+ });
+ }
+ length(len, message) {
+ return new ZodArray({
+ ...this._def,
+ exactLength: { value: len, message: errorUtil.toString(message) },
+ });
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+}
+ZodArray.create = (schema, params) => {
+ return new ZodArray({
+ type: schema,
+ minLength: null,
+ maxLength: null,
+ exactLength: null,
+ typeName: ZodFirstPartyTypeKind.ZodArray,
+ ...processCreateParams(params),
+ });
+};
+function deepPartialify(schema) {
+ if (schema instanceof ZodObject) {
+ const newShape = {};
+ for (const key in schema.shape) {
+ const fieldSchema = schema.shape[key];
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
+ }
+ return new ZodObject({
+ ...schema._def,
+ shape: () => newShape,
+ });
+ }
+ else if (schema instanceof ZodArray) {
+ return new ZodArray({
+ ...schema._def,
+ type: deepPartialify(schema.element),
+ });
+ }
+ else if (schema instanceof ZodOptional) {
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodNullable) {
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodTuple) {
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
+ }
+ else {
+ return schema;
+ }
+}
+class ZodObject extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._cached = null;
+ /**
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
+ */
+ this.nonstrict = this.passthrough;
+ // 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)
+ return this._cached;
+ const shape = this._def.shape();
+ const keys = util.objectKeys(shape);
+ return (this._cached = { shape, keys });
+ }
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.object) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const { status, ctx } = this._processInputParams(input);
+ const { shape, keys: shapeKeys } = this._getCached();
+ const extraKeys = [];
+ if (!(this._def.catchall instanceof ZodNever &&
+ this._def.unknownKeys === "strip")) {
+ for (const key in ctx.data) {
+ if (!shapeKeys.includes(key)) {
+ extraKeys.push(key);
+ }
+ }
+ }
+ const pairs = [];
+ for (const key of shapeKeys) {
+ const keyValidator = shape[key];
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ if (this._def.catchall instanceof ZodNever) {
+ const unknownKeys = this._def.unknownKeys;
+ if (unknownKeys === "passthrough") {
+ for (const key of extraKeys) {
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: { status: "valid", value: ctx.data[key] },
+ });
+ }
+ }
+ else if (unknownKeys === "strict") {
+ if (extraKeys.length > 0) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.unrecognized_keys,
+ keys: extraKeys,
+ });
+ status.dirty();
+ }
+ }
+ else if (unknownKeys === "strip") ;
+ else {
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
+ }
+ }
+ else {
+ // run catchall validation
+ const catchall = this._def.catchall;
+ for (const key of extraKeys) {
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
+ ),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ }
+ if (ctx.common.async) {
+ return Promise.resolve()
+ .then(async () => {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ const key = await pair.key;
+ syncPairs.push({
+ key,
+ value: await pair.value,
+ alwaysSet: pair.alwaysSet,
+ });
+ }
+ return syncPairs;
+ })
+ .then((syncPairs) => {
+ return ParseStatus.mergeObjectSync(status, syncPairs);
+ });
+ }
+ else {
+ return ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get shape() {
+ return this._def.shape();
+ }
+ strict(message) {
+ errorUtil.errToObj;
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strict",
+ ...(message !== undefined
+ ? {
+ errorMap: (issue, ctx) => {
+ var _a, _b, _c, _d;
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
+ if (issue.code === "unrecognized_keys")
+ return {
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
+ };
+ return {
+ message: defaultError,
+ };
+ },
+ }
+ : {}),
+ });
+ }
+ strip() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strip",
+ });
+ }
+ passthrough() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "passthrough",
+ });
+ }
+ // const AugmentFactory =
+ // <Def extends ZodObjectDef>(def: Def) =>
+ // <Augmentation extends ZodRawShape>(
+ // augmentation: Augmentation
+ // ): ZodObject<
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
+ // Def["unknownKeys"],
+ // Def["catchall"]
+ // > => {
+ // return new ZodObject({
+ // ...def,
+ // shape: () => ({
+ // ...def.shape(),
+ // ...augmentation,
+ // }),
+ // }) as any;
+ // };
+ extend(augmentation) {
+ return new ZodObject({
+ ...this._def,
+ shape: () => ({
+ ...this._def.shape(),
+ ...augmentation,
+ }),
+ });
+ }
+ /**
+ * Prior to zod@1.0.12 there was a bug in the
+ * inferred type of merged objects. Please
+ * upgrade if you are experiencing issues.
+ */
+ merge(merging) {
+ const merged = new ZodObject({
+ unknownKeys: merging._def.unknownKeys,
+ catchall: merging._def.catchall,
+ shape: () => ({
+ ...this._def.shape(),
+ ...merging._def.shape(),
+ }),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ });
+ 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,
+ catchall: index,
+ });
+ }
+ pick(mask) {
+ const shape = {};
+ util.objectKeys(mask).forEach((key) => {
+ if (mask[key] && this.shape[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ omit(mask) {
+ const shape = {};
+ util.objectKeys(this.shape).forEach((key) => {
+ if (!mask[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ /**
+ * @deprecated
+ */
+ deepPartial() {
+ return deepPartialify(this);
+ }
+ partial(mask) {
+ const newShape = {};
+ 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,
+ });
+ }
+ required(mask) {
+ const newShape = {};
+ 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) {
+ newField = newField._def.innerType;
+ }
+ newShape[key] = newField;
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => newShape,
+ });
+ }
+ keyof() {
+ return createZodEnum(util.objectKeys(this.shape));
+ }
+}
+ZodObject.create = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+ZodObject.strictCreate = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strict",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+ZodObject.lazycreate = (shape, params) => {
+ return new ZodObject({
+ shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+class ZodUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const options = this._def.options;
+ function handleResults(results) {
+ // return first issue-free validation if it exists
+ for (const result of results) {
+ if (result.result.status === "valid") {
+ return result.result;
+ }
+ }
+ for (const result of results) {
+ if (result.result.status === "dirty") {
+ // add issues from dirty option
+ ctx.common.issues.push(...result.ctx.common.issues);
+ return result.result;
+ }
+ }
+ // return invalid
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return INVALID;
+ }
+ if (ctx.common.async) {
+ return Promise.all(options.map(async (option) => {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ return {
+ result: await option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ }),
+ ctx: childCtx,
+ };
+ })).then(handleResults);
+ }
+ else {
+ let dirty = undefined;
+ const issues = [];
+ for (const option of options) {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ const result = option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ });
+ if (result.status === "valid") {
+ return result;
+ }
+ else if (result.status === "dirty" && !dirty) {
+ dirty = { result, ctx: childCtx };
+ }
+ if (childCtx.common.issues.length) {
+ issues.push(childCtx.common.issues);
+ }
+ }
+ if (dirty) {
+ ctx.common.issues.push(...dirty.ctx.common.issues);
+ return dirty.result;
+ }
+ const unionErrors = issues.map((issues) => new ZodError(issues));
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return INVALID;
+ }
+ }
+ get options() {
+ return this._def.options;
+ }
+}
+ZodUnion.create = (types, params) => {
+ return new ZodUnion({
+ options: types,
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
+ ...processCreateParams(params),
+ });
+};
+/////////////////////////////////////////////////////
+/////////////////////////////////////////////////////
+////////// //////////
+////////// ZodDiscriminatedUnion //////////
+////////// //////////
+/////////////////////////////////////////////////////
+/////////////////////////////////////////////////////
+const getDiscriminator = (type) => {
+ if (type instanceof ZodLazy) {
+ return getDiscriminator(type.schema);
+ }
+ else if (type instanceof ZodEffects) {
+ return getDiscriminator(type.innerType());
+ }
+ else if (type instanceof ZodLiteral) {
+ return [type.value];
+ }
+ else if (type instanceof ZodEnum) {
+ return type.options;
+ }
+ else if (type instanceof ZodNativeEnum) {
+ // eslint-disable-next-line ban/ban
+ return Object.keys(type.enum);
+ }
+ else if (type instanceof ZodDefault) {
+ return getDiscriminator(type._def.innerType);
+ }
+ else if (type instanceof ZodUndefined) {
+ return [undefined];
+ }
+ else if (type instanceof ZodNull) {
+ return [null];
+ }
+ else {
+ return null;
+ }
+};
+class ZodDiscriminatedUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.object) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const discriminator = this.discriminator;
+ const discriminatorValue = ctx.data[discriminator];
+ const option = this.optionsMap.get(discriminatorValue);
+ if (!option) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union_discriminator,
+ options: Array.from(this.optionsMap.keys()),
+ path: [discriminator],
+ });
+ return INVALID;
+ }
+ if (ctx.common.async) {
+ return option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ else {
+ return option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ get discriminator() {
+ return this._def.discriminator;
+ }
+ get options() {
+ return this._def.options;
+ }
+ get optionsMap() {
+ return this._def.optionsMap;
+ }
+ /**
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
+ * have a different value for each object in the union.
+ * @param discriminator the name of the discriminator property
+ * @param types an array of object schemas
+ * @param params
+ */
+ static create(discriminator, options, params) {
+ // Get all the valid discriminator values
+ const optionsMap = new Map();
+ // try {
+ for (const type of options) {
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
+ if (!discriminatorValues) {
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
+ }
+ for (const value of discriminatorValues) {
+ if (optionsMap.has(value)) {
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
+ }
+ optionsMap.set(value, type);
+ }
+ }
+ return new ZodDiscriminatedUnion({
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
+ discriminator,
+ options,
+ optionsMap,
+ ...processCreateParams(params),
+ });
+ }
+}
+function mergeValues(a, b) {
+ const aType = getParsedType(a);
+ const bType = getParsedType(b);
+ if (a === b) {
+ return { valid: true, data: a };
+ }
+ else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
+ const bKeys = util.objectKeys(b);
+ const sharedKeys = util
+ .objectKeys(a)
+ .filter((key) => bKeys.indexOf(key) !== -1);
+ const newObj = { ...a, ...b };
+ for (const key of sharedKeys) {
+ const sharedValue = mergeValues(a[key], b[key]);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newObj[key] = sharedValue.data;
+ }
+ return { valid: true, data: newObj };
+ }
+ else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
+ if (a.length !== b.length) {
+ return { valid: false };
+ }
+ const newArray = [];
+ for (let index = 0; index < a.length; index++) {
+ const itemA = a[index];
+ const itemB = b[index];
+ const sharedValue = mergeValues(itemA, itemB);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newArray.push(sharedValue.data);
+ }
+ return { valid: true, data: newArray };
+ }
+ else if (aType === ZodParsedType.date &&
+ bType === ZodParsedType.date &&
+ +a === +b) {
+ return { valid: true, data: a };
+ }
+ else {
+ return { valid: false };
+ }
+}
+class ZodIntersection extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const handleParsed = (parsedLeft, parsedRight) => {
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
+ return INVALID;
+ }
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
+ if (!merged.valid) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_intersection_types,
+ });
+ return INVALID;
+ }
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
+ status.dirty();
+ }
+ return { status: status.value, value: merged.data };
+ };
+ if (ctx.common.async) {
+ return Promise.all([
+ this._def.left._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ this._def.right._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ ]).then(([left, right]) => handleParsed(left, right));
+ }
+ else {
+ return handleParsed(this._def.left._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }), this._def.right._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }));
+ }
+ }
+}
+ZodIntersection.create = (left, right, params) => {
+ return new ZodIntersection({
+ left: left,
+ right: right,
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
+ ...processCreateParams(params),
+ });
+};
+class ZodTuple extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.array) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (ctx.data.length < this._def.items.length) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ return INVALID;
+ }
+ const rest = this._def.rest;
+ if (!rest && ctx.data.length > this._def.items.length) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ status.dirty();
+ }
+ const items = [...ctx.data]
+ .map((item, itemIndex) => {
+ const schema = this._def.items[itemIndex] || this._def.rest;
+ if (!schema)
+ return null;
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
+ })
+ .filter((x) => !!x); // filter nulls
+ if (ctx.common.async) {
+ return Promise.all(items).then((results) => {
+ return ParseStatus.mergeArray(status, results);
+ });
+ }
+ else {
+ return ParseStatus.mergeArray(status, items);
+ }
+ }
+ get items() {
+ return this._def.items;
+ }
+ rest(rest) {
+ return new ZodTuple({
+ ...this._def,
+ rest,
+ });
+ }
+}
+ZodTuple.create = (schemas, params) => {
+ if (!Array.isArray(schemas)) {
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
+ }
+ return new ZodTuple({
+ items: schemas,
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
+ rest: null,
+ ...processCreateParams(params),
+ });
+};
+class ZodRecord extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.object) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const pairs = [];
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ for (const key in ctx.data) {
+ pairs.push({
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
+ });
+ }
+ if (ctx.common.async) {
+ return ParseStatus.mergeObjectAsync(status, pairs);
+ }
+ else {
+ return ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get element() {
+ return this._def.valueType;
+ }
+ static create(first, second, third) {
+ if (second instanceof ZodType) {
+ return new ZodRecord({
+ keyType: first,
+ valueType: second,
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(third),
+ });
+ }
+ return new ZodRecord({
+ keyType: ZodString.create(),
+ valueType: first,
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(second),
+ });
+ }
+}
+class ZodMap extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.map) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.map,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
+ return {
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
+ };
+ });
+ if (ctx.common.async) {
+ const finalMap = new Map();
+ return Promise.resolve().then(async () => {
+ for (const pair of pairs) {
+ const key = await pair.key;
+ const value = await pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ });
+ }
+ else {
+ const finalMap = new Map();
+ for (const pair of pairs) {
+ const key = pair.key;
+ const value = pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ }
+ }
+}
+ZodMap.create = (keyType, valueType, params) => {
+ return new ZodMap({
+ valueType,
+ keyType,
+ typeName: ZodFirstPartyTypeKind.ZodMap,
+ ...processCreateParams(params),
+ });
+};
+class ZodSet extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.set) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.set,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const def = this._def;
+ if (def.minSize !== null) {
+ if (ctx.data.size < def.minSize.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: def.minSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.minSize.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxSize !== null) {
+ if (ctx.data.size > def.maxSize.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: def.maxSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.maxSize.message,
+ });
+ status.dirty();
+ }
+ }
+ const valueType = this._def.valueType;
+ function finalizeSet(elements) {
+ const parsedSet = new Set();
+ for (const element of elements) {
+ if (element.status === "aborted")
+ return INVALID;
+ if (element.status === "dirty")
+ status.dirty();
+ parsedSet.add(element.value);
+ }
+ return { status: status.value, value: parsedSet };
+ }
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
+ if (ctx.common.async) {
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
+ }
+ else {
+ return finalizeSet(elements);
+ }
+ }
+ min(minSize, message) {
+ return new ZodSet({
+ ...this._def,
+ minSize: { value: minSize, message: errorUtil.toString(message) },
+ });
+ }
+ max(maxSize, message) {
+ return new ZodSet({
+ ...this._def,
+ maxSize: { value: maxSize, message: errorUtil.toString(message) },
+ });
+ }
+ size(size, message) {
+ return this.min(size, message).max(size, message);
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+}
+ZodSet.create = (valueType, params) => {
+ return new ZodSet({
+ valueType,
+ minSize: null,
+ maxSize: null,
+ typeName: ZodFirstPartyTypeKind.ZodSet,
+ ...processCreateParams(params),
+ });
+};
+class ZodFunction extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.validate = this.implement;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.function) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.function,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ function makeArgsIssue(args, error) {
+ return makeIssue({
+ data: args,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodIssueCode.invalid_arguments,
+ argumentsError: error,
+ },
+ });
+ }
+ function makeReturnsIssue(returns, error) {
+ return makeIssue({
+ data: returns,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodIssueCode.invalid_return_type,
+ returnTypeError: error,
+ },
+ });
+ }
+ const params = { errorMap: ctx.common.contextualErrorMap };
+ const fn = ctx.data;
+ if (this._def.returns instanceof ZodPromise) {
+ // Would love a way to avoid disabling this rule, but we need
+ // an alias (using an arrow function was what caused 2651).
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
+ const me = this;
+ return OK(async function (...args) {
+ const error = new ZodError([]);
+ const parsedArgs = await me._def.args
+ .parseAsync(args, params)
+ .catch((e) => {
+ error.addIssue(makeArgsIssue(args, e));
+ throw error;
+ });
+ const result = await Reflect.apply(fn, this, parsedArgs);
+ const parsedReturns = await me._def.returns._def.type
+ .parseAsync(result, params)
+ .catch((e) => {
+ error.addIssue(makeReturnsIssue(result, e));
+ throw error;
+ });
+ return parsedReturns;
+ });
+ }
+ else {
+ // Would love a way to avoid disabling this rule, but we need
+ // an alias (using an arrow function was what caused 2651).
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
+ const me = this;
+ return OK(function (...args) {
+ const parsedArgs = me._def.args.safeParse(args, params);
+ if (!parsedArgs.success) {
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
+ }
+ const result = Reflect.apply(fn, this, parsedArgs.data);
+ const parsedReturns = me._def.returns.safeParse(result, params);
+ if (!parsedReturns.success) {
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
+ }
+ return parsedReturns.data;
+ });
+ }
+ }
+ parameters() {
+ return this._def.args;
+ }
+ returnType() {
+ return this._def.returns;
+ }
+ args(...items) {
+ return new ZodFunction({
+ ...this._def,
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
+ });
+ }
+ returns(returnType) {
+ return new ZodFunction({
+ ...this._def,
+ returns: returnType,
+ });
+ }
+ implement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ strictImplement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ static create(args, returns, params) {
+ return new ZodFunction({
+ args: (args
+ ? args
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
+ returns: returns || ZodUnknown.create(),
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
+ ...processCreateParams(params),
+ });
+ }
+}
+class ZodLazy extends ZodType {
+ get schema() {
+ return this._def.getter();
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const lazySchema = this._def.getter();
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
+ }
+}
+ZodLazy.create = (getter, params) => {
+ return new ZodLazy({
+ getter: getter,
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
+ ...processCreateParams(params),
+ });
+};
+class ZodLiteral extends ZodType {
+ _parse(input) {
+ if (input.data !== this._def.value) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_literal,
+ expected: this._def.value,
+ });
+ return INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+ get value() {
+ return this._def.value;
+ }
+}
+ZodLiteral.create = (value, params) => {
+ return new ZodLiteral({
+ value: value,
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
+ ...processCreateParams(params),
+ });
+};
+function createZodEnum(values, params) {
+ return new ZodEnum({
+ values,
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
+ ...processCreateParams(params),
+ });
+}
+class ZodEnum extends ZodType {
+ _parse(input) {
+ if (typeof input.data !== "string") {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ addIssueToContext(ctx, {
+ expected: util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodIssueCode.invalid_type,
+ });
+ return INVALID;
+ }
+ if (this._def.values.indexOf(input.data) === -1) {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ get options() {
+ return this._def.values;
+ }
+ get enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Values() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ extract(values) {
+ return ZodEnum.create(values);
+ }
+ exclude(values) {
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
+ }
+}
+ZodEnum.create = createZodEnum;
+class ZodNativeEnum extends ZodType {
+ _parse(input) {
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
+ const ctx = this._getOrReturnCtx(input);
+ if (ctx.parsedType !== ZodParsedType.string &&
+ ctx.parsedType !== ZodParsedType.number) {
+ const expectedValues = util.objectValues(nativeEnumValues);
+ addIssueToContext(ctx, {
+ expected: util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodIssueCode.invalid_type,
+ });
+ return INVALID;
+ }
+ if (nativeEnumValues.indexOf(input.data) === -1) {
+ const expectedValues = util.objectValues(nativeEnumValues);
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ get enum() {
+ return this._def.values;
+ }
+}
+ZodNativeEnum.create = (values, params) => {
+ return new ZodNativeEnum({
+ values: values,
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
+ ...processCreateParams(params),
+ });
+};
+class ZodPromise extends ZodType {
+ unwrap() {
+ return this._def.type;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.promise &&
+ ctx.common.async === false) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.promise,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const promisified = ctx.parsedType === ZodParsedType.promise
+ ? ctx.data
+ : Promise.resolve(ctx.data);
+ return OK(promisified.then((data) => {
+ return this._def.type.parseAsync(data, {
+ path: ctx.path,
+ errorMap: ctx.common.contextualErrorMap,
+ });
+ }));
+ }
+}
+ZodPromise.create = (schema, params) => {
+ return new ZodPromise({
+ type: schema,
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
+ ...processCreateParams(params),
+ });
+};
+class ZodEffects extends ZodType {
+ innerType() {
+ return this._def.schema;
+ }
+ sourceType() {
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
+ ? this._def.schema.sourceType()
+ : this._def.schema;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const effect = this._def.effect || null;
+ const checkCtx = {
+ addIssue: (arg) => {
+ addIssueToContext(ctx, arg);
+ if (arg.fatal) {
+ status.abort();
+ }
+ else {
+ status.dirty();
+ }
+ },
+ get path() {
+ return ctx.path;
+ },
+ };
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
+ if (effect.type === "preprocess") {
+ const processed = effect.transform(ctx.data, checkCtx);
+ if (ctx.common.issues.length) {
+ return {
+ status: "dirty",
+ value: ctx.data,
+ };
+ }
+ if (ctx.common.async) {
+ return Promise.resolve(processed).then((processed) => {
+ return this._def.schema._parseAsync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ });
+ }
+ else {
+ return this._def.schema._parseSync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ if (effect.type === "refinement") {
+ const executeRefinement = (acc
+ // effect: RefinementEffect<any>
+ ) => {
+ const result = effect.refinement(acc, checkCtx);
+ if (ctx.common.async) {
+ return Promise.resolve(result);
+ }
+ if (result instanceof Promise) {
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
+ }
+ return acc;
+ };
+ if (ctx.common.async === false) {
+ const inner = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inner.status === "aborted")
+ return INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ // return value is ignored
+ executeRefinement(inner.value);
+ return { status: status.value, value: inner.value };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((inner) => {
+ if (inner.status === "aborted")
+ return INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ return executeRefinement(inner.value).then(() => {
+ return { status: status.value, value: inner.value };
+ });
+ });
+ }
+ }
+ if (effect.type === "transform") {
+ if (ctx.common.async === false) {
+ const base = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (!isValid(base))
+ return base;
+ const result = effect.transform(base.value, checkCtx);
+ if (result instanceof Promise) {
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
+ }
+ return { status: status.value, value: result };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((base) => {
+ if (!isValid(base))
+ return base;
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
+ });
+ }
+ }
+ util.assertNever(effect);
+ }
+}
+ZodEffects.create = (schema, effect, params) => {
+ return new ZodEffects({
+ schema,
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ effect,
+ ...processCreateParams(params),
+ });
+};
+ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
+ return new ZodEffects({
+ schema,
+ effect: { type: "preprocess", transform: preprocess },
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ ...processCreateParams(params),
+ });
+};
+class ZodOptional extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === ZodParsedType.undefined) {
+ return OK(undefined);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+}
+ZodOptional.create = (type, params) => {
+ return new ZodOptional({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
+ ...processCreateParams(params),
+ });
+};
+class ZodNullable extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === ZodParsedType.null) {
+ return OK(null);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+}
+ZodNullable.create = (type, params) => {
+ return new ZodNullable({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
+ ...processCreateParams(params),
+ });
+};
+class ZodDefault extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ let data = ctx.data;
+ if (ctx.parsedType === ZodParsedType.undefined) {
+ data = this._def.defaultValue();
+ }
+ return this._def.innerType._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ removeDefault() {
+ return this._def.innerType;
+ }
+}
+ZodDefault.create = (type, params) => {
+ return new ZodDefault({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
+ defaultValue: typeof params.default === "function"
+ ? params.default
+ : () => params.default,
+ ...processCreateParams(params),
+ });
+};
+class ZodCatch extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ // newCtx is used to not collect issues from inner types in ctx
+ const newCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ };
+ const result = this._def.innerType._parse({
+ data: newCtx.data,
+ path: newCtx.path,
+ parent: {
+ ...newCtx,
+ },
+ });
+ if (isAsync(result)) {
+ return result.then((result) => {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ });
+ }
+ else {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ }
+ }
+ removeCatch() {
+ return this._def.innerType;
+ }
+}
+ZodCatch.create = (type, params) => {
+ return new ZodCatch({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
+ ...processCreateParams(params),
+ });
+};
+class ZodNaN extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.nan) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.nan,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+}
+ZodNaN.create = (params) => {
+ return new ZodNaN({
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
+ ...processCreateParams(params),
+ });
+};
+const BRAND = Symbol("zod_brand");
+class ZodBranded extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const data = ctx.data;
+ return this._def.type._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ unwrap() {
+ return this._def.type;
+ }
+}
+class ZodPipeline extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.common.async) {
+ const handleAsync = async () => {
+ const inResult = await this._def.in._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return DIRTY(inResult.value);
+ }
+ else {
+ return this._def.out._parseAsync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ };
+ return handleAsync();
+ }
+ else {
+ const inResult = this._def.in._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return {
+ status: "dirty",
+ value: inResult.value,
+ };
+ }
+ else {
+ return this._def.out._parseSync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ }
+ static create(a, b) {
+ return new ZodPipeline({
+ in: a,
+ out: b,
+ typeName: ZodFirstPartyTypeKind.ZodPipeline,
+ });
+ }
+}
+class ZodReadonly extends ZodType {
+ _parse(input) {
+ const result = this._def.innerType._parse(input);
+ if (isValid(result)) {
+ result.value = Object.freeze(result.value);
+ }
+ return result;
+ }
+}
+ZodReadonly.create = (type, params) => {
+ return new ZodReadonly({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
+ ...processCreateParams(params),
+ });
+};
+const custom = (check, params = {},
+/*
+ * @deprecated
+ *
+ * Pass `fatal` into the params object instead:
+ *
+ * ```ts
+ * z.string().custom((val) => val.length > 5, { fatal: false })
+ * ```
+ *
+ */
+fatal) => {
+ if (check)
+ return ZodAny.create().superRefine((data, ctx) => {
+ var _a, _b;
+ if (!check(data)) {
+ const p = typeof params === "function"
+ ? params(data)
+ : typeof params === "string"
+ ? { message: params }
+ : params;
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
+ const p2 = typeof p === "string" ? { message: p } : p;
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
+ }
+ });
+ return ZodAny.create();
+};
+const late = {
+ object: ZodObject.lazycreate,
+};
+var ZodFirstPartyTypeKind;
+(function (ZodFirstPartyTypeKind) {
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
+})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
+const instanceOfType = (
+// const instanceOfType = <T extends new (...args: any[]) => any>(
+cls, params = {
+ message: `Input not instance of ${cls.name}`,
+}) => custom((data) => data instanceof cls, params);
+const stringType = ZodString.create;
+const numberType = ZodNumber.create;
+const nanType = ZodNaN.create;
+const bigIntType = ZodBigInt.create;
+const booleanType = ZodBoolean.create;
+const dateType = ZodDate.create;
+const symbolType = ZodSymbol.create;
+const undefinedType = ZodUndefined.create;
+const nullType = ZodNull.create;
+const anyType = ZodAny.create;
+const unknownType = ZodUnknown.create;
+const neverType = ZodNever.create;
+const voidType = ZodVoid.create;
+const arrayType = ZodArray.create;
+const objectType = ZodObject.create;
+const strictObjectType = ZodObject.strictCreate;
+const unionType = ZodUnion.create;
+const discriminatedUnionType = ZodDiscriminatedUnion.create;
+const intersectionType = ZodIntersection.create;
+const tupleType = ZodTuple.create;
+const recordType = ZodRecord.create;
+const mapType = ZodMap.create;
+const setType = ZodSet.create;
+const functionType = ZodFunction.create;
+const lazyType = ZodLazy.create;
+const literalType = ZodLiteral.create;
+const enumType = ZodEnum.create;
+const nativeEnumType = ZodNativeEnum.create;
+const promiseType = ZodPromise.create;
+const effectsType = ZodEffects.create;
+const optionalType = ZodOptional.create;
+const nullableType = ZodNullable.create;
+const preprocessType = ZodEffects.createWithPreprocess;
+const pipelineType = ZodPipeline.create;
+const ostring = () => stringType().optional();
+const onumber = () => numberType().optional();
+const oboolean = () => booleanType().optional();
+const coerce = {
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
+ number: ((arg) => ZodNumber.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 })),
+};
+const NEVER = INVALID;
+
+var z = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ defaultErrorMap: errorMap,
+ setErrorMap: setErrorMap,
+ getErrorMap: getErrorMap,
+ makeIssue: makeIssue,
+ EMPTY_PATH: EMPTY_PATH,
+ addIssueToContext: addIssueToContext,
+ ParseStatus: ParseStatus,
+ INVALID: INVALID,
+ DIRTY: DIRTY,
+ OK: OK,
+ isAborted: isAborted,
+ isDirty: isDirty,
+ isValid: isValid,
+ isAsync: isAsync,
+ get util () { return util; },
+ get objectUtil () { return objectUtil; },
+ ZodParsedType: ZodParsedType,
+ getParsedType: getParsedType,
+ ZodType: ZodType,
+ ZodString: ZodString,
+ ZodNumber: ZodNumber,
+ ZodBigInt: ZodBigInt,
+ ZodBoolean: ZodBoolean,
+ ZodDate: ZodDate,
+ ZodSymbol: ZodSymbol,
+ ZodUndefined: ZodUndefined,
+ ZodNull: ZodNull,
+ ZodAny: ZodAny,
+ ZodUnknown: ZodUnknown,
+ ZodNever: ZodNever,
+ ZodVoid: ZodVoid,
+ ZodArray: ZodArray,
+ ZodObject: ZodObject,
+ ZodUnion: ZodUnion,
+ ZodDiscriminatedUnion: ZodDiscriminatedUnion,
+ ZodIntersection: ZodIntersection,
+ ZodTuple: ZodTuple,
+ ZodRecord: ZodRecord,
+ ZodMap: ZodMap,
+ ZodSet: ZodSet,
+ ZodFunction: ZodFunction,
+ ZodLazy: ZodLazy,
+ ZodLiteral: ZodLiteral,
+ ZodEnum: ZodEnum,
+ ZodNativeEnum: ZodNativeEnum,
+ ZodPromise: ZodPromise,
+ ZodEffects: ZodEffects,
+ ZodTransformer: ZodEffects,
+ ZodOptional: ZodOptional,
+ ZodNullable: ZodNullable,
+ ZodDefault: ZodDefault,
+ ZodCatch: ZodCatch,
+ ZodNaN: ZodNaN,
+ BRAND: BRAND,
+ ZodBranded: ZodBranded,
+ ZodPipeline: ZodPipeline,
+ ZodReadonly: ZodReadonly,
+ custom: custom,
+ Schema: ZodType,
+ ZodSchema: ZodType,
+ late: late,
+ get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
+ coerce: coerce,
+ any: anyType,
+ array: arrayType,
+ bigint: bigIntType,
+ boolean: booleanType,
+ date: dateType,
+ discriminatedUnion: discriminatedUnionType,
+ effect: effectsType,
+ 'enum': enumType,
+ 'function': functionType,
+ 'instanceof': instanceOfType,
+ intersection: intersectionType,
+ lazy: lazyType,
+ literal: literalType,
+ map: mapType,
+ nan: nanType,
+ nativeEnum: nativeEnumType,
+ never: neverType,
+ 'null': nullType,
+ nullable: nullableType,
+ number: numberType,
+ object: objectType,
+ oboolean: oboolean,
+ onumber: onumber,
+ optional: optionalType,
+ ostring: ostring,
+ pipeline: pipelineType,
+ preprocess: preprocessType,
+ promise: promiseType,
+ record: recordType,
+ set: setType,
+ strictObject: strictObjectType,
+ string: stringType,
+ symbol: symbolType,
+ transformer: effectsType,
+ tuple: tupleType,
+ 'undefined': undefinedType,
+ union: unionType,
+ unknown: unknownType,
+ 'void': voidType,
+ NEVER: NEVER,
+ ZodIssueCode: ZodIssueCode,
+ quotelessJson: quotelessJson,
+ ZodError: ZodError
+});
+
+export { BRAND, DIRTY, EMPTY_PATH, INVALID, NEVER, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodBranded, ZodCatch, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPipeline, ZodPromise, ZodReadonly, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodSymbol, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, coerce, custom, dateType as date, z as default, errorMap as defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getErrorMap, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, pipelineType as pipeline, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, symbolType as symbol, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, util, voidType as void, z };
diff --git a/node_modules/zod/lib/index.umd.js b/node_modules/zod/lib/index.umd.js
new file mode 100644
index 0000000..e08b14b
--- /dev/null
+++ b/node_modules/zod/lib/index.umd.js
@@ -0,0 +1,4120 @@
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Zod = {}));
+})(this, (function (exports) { 'use strict';
+
+ exports.util = void 0;
+ (function (util) {
+ util.assertEqual = (val) => val;
+ function assertIs(_arg) { }
+ util.assertIs = assertIs;
+ function assertNever(_x) {
+ throw new Error();
+ }
+ util.assertNever = assertNever;
+ util.arrayToEnum = (items) => {
+ const obj = {};
+ for (const item of items) {
+ obj[item] = item;
+ }
+ return obj;
+ };
+ util.getValidEnumValues = (obj) => {
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
+ const filtered = {};
+ for (const k of validKeys) {
+ filtered[k] = obj[k];
+ }
+ return util.objectValues(filtered);
+ };
+ util.objectValues = (obj) => {
+ return util.objectKeys(obj).map(function (e) {
+ return obj[e];
+ });
+ };
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
+ : (object) => {
+ const keys = [];
+ for (const key in object) {
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
+ keys.push(key);
+ }
+ }
+ return keys;
+ };
+ util.find = (arr, checker) => {
+ for (const item of arr) {
+ if (checker(item))
+ return item;
+ }
+ return undefined;
+ };
+ util.isInteger = typeof Number.isInteger === "function"
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
+ : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
+ function joinValues(array, separator = " | ") {
+ return array
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
+ .join(separator);
+ }
+ util.joinValues = joinValues;
+ util.jsonStringifyReplacer = (_, value) => {
+ if (typeof value === "bigint") {
+ return value.toString();
+ }
+ return value;
+ };
+ })(exports.util || (exports.util = {}));
+ exports.objectUtil = void 0;
+ (function (objectUtil) {
+ objectUtil.mergeShapes = (first, second) => {
+ return {
+ ...first,
+ ...second, // second overwrites first
+ };
+ };
+ })(exports.objectUtil || (exports.objectUtil = {}));
+ const ZodParsedType = exports.util.arrayToEnum([
+ "string",
+ "nan",
+ "number",
+ "integer",
+ "float",
+ "boolean",
+ "date",
+ "bigint",
+ "symbol",
+ "function",
+ "undefined",
+ "null",
+ "array",
+ "object",
+ "unknown",
+ "promise",
+ "void",
+ "never",
+ "map",
+ "set",
+ ]);
+ const getParsedType = (data) => {
+ const t = typeof data;
+ switch (t) {
+ case "undefined":
+ return ZodParsedType.undefined;
+ case "string":
+ return ZodParsedType.string;
+ case "number":
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
+ case "boolean":
+ return ZodParsedType.boolean;
+ case "function":
+ return ZodParsedType.function;
+ case "bigint":
+ return ZodParsedType.bigint;
+ case "symbol":
+ return ZodParsedType.symbol;
+ case "object":
+ if (Array.isArray(data)) {
+ return ZodParsedType.array;
+ }
+ if (data === null) {
+ return ZodParsedType.null;
+ }
+ if (data.then &&
+ typeof data.then === "function" &&
+ data.catch &&
+ typeof data.catch === "function") {
+ return ZodParsedType.promise;
+ }
+ if (typeof Map !== "undefined" && data instanceof Map) {
+ return ZodParsedType.map;
+ }
+ if (typeof Set !== "undefined" && data instanceof Set) {
+ return ZodParsedType.set;
+ }
+ if (typeof Date !== "undefined" && data instanceof Date) {
+ return ZodParsedType.date;
+ }
+ return ZodParsedType.object;
+ default:
+ return ZodParsedType.unknown;
+ }
+ };
+
+ const ZodIssueCode = exports.util.arrayToEnum([
+ "invalid_type",
+ "invalid_literal",
+ "custom",
+ "invalid_union",
+ "invalid_union_discriminator",
+ "invalid_enum_value",
+ "unrecognized_keys",
+ "invalid_arguments",
+ "invalid_return_type",
+ "invalid_date",
+ "invalid_string",
+ "too_small",
+ "too_big",
+ "invalid_intersection_types",
+ "not_multiple_of",
+ "not_finite",
+ ]);
+ const quotelessJson = (obj) => {
+ const json = JSON.stringify(obj, null, 2);
+ return json.replace(/"([^"]+)":/g, "$1:");
+ };
+ class ZodError extends Error {
+ constructor(issues) {
+ super();
+ this.issues = [];
+ this.addIssue = (sub) => {
+ this.issues = [...this.issues, sub];
+ };
+ this.addIssues = (subs = []) => {
+ this.issues = [...this.issues, ...subs];
+ };
+ const actualProto = new.target.prototype;
+ if (Object.setPrototypeOf) {
+ // eslint-disable-next-line ban/ban
+ Object.setPrototypeOf(this, actualProto);
+ }
+ else {
+ this.__proto__ = actualProto;
+ }
+ this.name = "ZodError";
+ this.issues = issues;
+ }
+ get errors() {
+ return this.issues;
+ }
+ format(_mapper) {
+ const mapper = _mapper ||
+ function (issue) {
+ return issue.message;
+ };
+ const fieldErrors = { _errors: [] };
+ const processError = (error) => {
+ for (const issue of error.issues) {
+ if (issue.code === "invalid_union") {
+ issue.unionErrors.map(processError);
+ }
+ else if (issue.code === "invalid_return_type") {
+ processError(issue.returnTypeError);
+ }
+ else if (issue.code === "invalid_arguments") {
+ processError(issue.argumentsError);
+ }
+ else if (issue.path.length === 0) {
+ fieldErrors._errors.push(mapper(issue));
+ }
+ else {
+ let curr = fieldErrors;
+ let i = 0;
+ while (i < issue.path.length) {
+ const el = issue.path[i];
+ const terminal = i === issue.path.length - 1;
+ if (!terminal) {
+ curr[el] = curr[el] || { _errors: [] };
+ // if (typeof el === "string") {
+ // curr[el] = curr[el] || { _errors: [] };
+ // } else if (typeof el === "number") {
+ // const errorArray: any = [];
+ // errorArray._errors = [];
+ // curr[el] = curr[el] || errorArray;
+ // }
+ }
+ else {
+ curr[el] = curr[el] || { _errors: [] };
+ curr[el]._errors.push(mapper(issue));
+ }
+ curr = curr[el];
+ i++;
+ }
+ }
+ }
+ };
+ processError(this);
+ return fieldErrors;
+ }
+ toString() {
+ return this.message;
+ }
+ get message() {
+ return JSON.stringify(this.issues, exports.util.jsonStringifyReplacer, 2);
+ }
+ get isEmpty() {
+ return this.issues.length === 0;
+ }
+ flatten(mapper = (issue) => issue.message) {
+ const fieldErrors = {};
+ const formErrors = [];
+ for (const sub of this.issues) {
+ if (sub.path.length > 0) {
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
+ fieldErrors[sub.path[0]].push(mapper(sub));
+ }
+ else {
+ formErrors.push(mapper(sub));
+ }
+ }
+ return { formErrors, fieldErrors };
+ }
+ get formErrors() {
+ return this.flatten();
+ }
+ }
+ ZodError.create = (issues) => {
+ const error = new ZodError(issues);
+ return error;
+ };
+
+ const errorMap = (issue, _ctx) => {
+ let message;
+ switch (issue.code) {
+ case ZodIssueCode.invalid_type:
+ if (issue.received === ZodParsedType.undefined) {
+ message = "Required";
+ }
+ else {
+ message = `Expected ${issue.expected}, received ${issue.received}`;
+ }
+ break;
+ case ZodIssueCode.invalid_literal:
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, exports.util.jsonStringifyReplacer)}`;
+ break;
+ case ZodIssueCode.unrecognized_keys:
+ message = `Unrecognized key(s) in object: ${exports.util.joinValues(issue.keys, ", ")}`;
+ break;
+ case ZodIssueCode.invalid_union:
+ message = `Invalid input`;
+ break;
+ case ZodIssueCode.invalid_union_discriminator:
+ message = `Invalid discriminator value. Expected ${exports.util.joinValues(issue.options)}`;
+ break;
+ case ZodIssueCode.invalid_enum_value:
+ message = `Invalid enum value. Expected ${exports.util.joinValues(issue.options)}, received '${issue.received}'`;
+ break;
+ case ZodIssueCode.invalid_arguments:
+ message = `Invalid function arguments`;
+ break;
+ case ZodIssueCode.invalid_return_type:
+ message = `Invalid function return type`;
+ break;
+ case ZodIssueCode.invalid_date:
+ message = `Invalid date`;
+ break;
+ case ZodIssueCode.invalid_string:
+ if (typeof issue.validation === "object") {
+ if ("includes" in issue.validation) {
+ message = `Invalid input: must include "${issue.validation.includes}"`;
+ if (typeof issue.validation.position === "number") {
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
+ }
+ }
+ else if ("startsWith" in issue.validation) {
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
+ }
+ else if ("endsWith" in issue.validation) {
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
+ }
+ else {
+ exports.util.assertNever(issue.validation);
+ }
+ }
+ else if (issue.validation !== "regex") {
+ message = `Invalid ${issue.validation}`;
+ }
+ else {
+ message = "Invalid";
+ }
+ break;
+ case ZodIssueCode.too_small:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${issue.minimum}`;
+ else if (issue.type === "date")
+ message = `Date must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${new Date(Number(issue.minimum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodIssueCode.too_big:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `less than or equal to`
+ : `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")
+ message = `Date must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `smaller than or equal to`
+ : `smaller than`} ${new Date(Number(issue.maximum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodIssueCode.custom:
+ message = `Invalid input`;
+ break;
+ case ZodIssueCode.invalid_intersection_types:
+ message = `Intersection results could not be merged`;
+ break;
+ case ZodIssueCode.not_multiple_of:
+ message = `Number must be a multiple of ${issue.multipleOf}`;
+ break;
+ case ZodIssueCode.not_finite:
+ message = "Number must be finite";
+ break;
+ default:
+ message = _ctx.defaultError;
+ exports.util.assertNever(issue);
+ }
+ return { message };
+ };
+
+ let overrideErrorMap = errorMap;
+ function setErrorMap(map) {
+ overrideErrorMap = map;
+ }
+ function getErrorMap() {
+ return overrideErrorMap;
+ }
+
+ const makeIssue = (params) => {
+ const { data, path, errorMaps, issueData } = params;
+ const fullPath = [...path, ...(issueData.path || [])];
+ const fullIssue = {
+ ...issueData,
+ path: fullPath,
+ };
+ let errorMessage = "";
+ const maps = errorMaps
+ .filter((m) => !!m)
+ .slice()
+ .reverse();
+ for (const map of maps) {
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
+ }
+ return {
+ ...issueData,
+ path: fullPath,
+ message: issueData.message || errorMessage,
+ };
+ };
+ const EMPTY_PATH = [];
+ function addIssueToContext(ctx, issueData) {
+ const issue = makeIssue({
+ issueData: issueData,
+ data: ctx.data,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap, // then global default map
+ ].filter((x) => !!x),
+ });
+ ctx.common.issues.push(issue);
+ }
+ class ParseStatus {
+ constructor() {
+ this.value = "valid";
+ }
+ dirty() {
+ if (this.value === "valid")
+ this.value = "dirty";
+ }
+ abort() {
+ if (this.value !== "aborted")
+ this.value = "aborted";
+ }
+ static mergeArray(status, results) {
+ const arrayValue = [];
+ for (const s of results) {
+ if (s.status === "aborted")
+ return INVALID;
+ if (s.status === "dirty")
+ status.dirty();
+ arrayValue.push(s.value);
+ }
+ return { status: status.value, value: arrayValue };
+ }
+ static async mergeObjectAsync(status, pairs) {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ syncPairs.push({
+ key: await pair.key,
+ value: await pair.value,
+ });
+ }
+ return ParseStatus.mergeObjectSync(status, syncPairs);
+ }
+ static mergeObjectSync(status, pairs) {
+ const finalObject = {};
+ for (const pair of pairs) {
+ const { key, value } = pair;
+ if (key.status === "aborted")
+ return INVALID;
+ if (value.status === "aborted")
+ return INVALID;
+ if (key.status === "dirty")
+ status.dirty();
+ if (value.status === "dirty")
+ status.dirty();
+ if (key.value !== "__proto__" &&
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
+ finalObject[key.value] = value.value;
+ }
+ }
+ return { status: status.value, value: finalObject };
+ }
+ }
+ const INVALID = Object.freeze({
+ status: "aborted",
+ });
+ const DIRTY = (value) => ({ status: "dirty", value });
+ const OK = (value) => ({ status: "valid", value });
+ const isAborted = (x) => x.status === "aborted";
+ const isDirty = (x) => x.status === "dirty";
+ const isValid = (x) => x.status === "valid";
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
+
+ var errorUtil;
+ (function (errorUtil) {
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
+ })(errorUtil || (errorUtil = {}));
+
+ class ParseInputLazyPath {
+ constructor(parent, value, path, key) {
+ this._cachedPath = [];
+ this.parent = parent;
+ this.data = value;
+ this._path = path;
+ this._key = key;
+ }
+ get path() {
+ if (!this._cachedPath.length) {
+ if (this._key instanceof Array) {
+ this._cachedPath.push(...this._path, ...this._key);
+ }
+ else {
+ this._cachedPath.push(...this._path, this._key);
+ }
+ }
+ return this._cachedPath;
+ }
+ }
+ const handleResult = (ctx, result) => {
+ if (isValid(result)) {
+ return { success: true, data: result.value };
+ }
+ else {
+ if (!ctx.common.issues.length) {
+ throw new Error("Validation failed but no issues detected.");
+ }
+ return {
+ success: false,
+ get error() {
+ if (this._error)
+ return this._error;
+ const error = new ZodError(ctx.common.issues);
+ this._error = error;
+ return this._error;
+ },
+ };
+ }
+ };
+ function processCreateParams(params) {
+ if (!params)
+ return {};
+ const { errorMap, invalid_type_error, required_error, description } = params;
+ if (errorMap && (invalid_type_error || required_error)) {
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
+ }
+ if (errorMap)
+ return { errorMap: errorMap, description };
+ const customMap = (iss, ctx) => {
+ if (iss.code !== "invalid_type")
+ return { message: ctx.defaultError };
+ if (typeof ctx.data === "undefined") {
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
+ }
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
+ };
+ return { errorMap: customMap, description };
+ }
+ class ZodType {
+ constructor(def) {
+ /** Alias of safeParseAsync */
+ this.spa = this.safeParseAsync;
+ this._def = def;
+ this.parse = this.parse.bind(this);
+ this.safeParse = this.safeParse.bind(this);
+ this.parseAsync = this.parseAsync.bind(this);
+ this.safeParseAsync = this.safeParseAsync.bind(this);
+ this.spa = this.spa.bind(this);
+ this.refine = this.refine.bind(this);
+ this.refinement = this.refinement.bind(this);
+ this.superRefine = this.superRefine.bind(this);
+ this.optional = this.optional.bind(this);
+ this.nullable = this.nullable.bind(this);
+ this.nullish = this.nullish.bind(this);
+ this.array = this.array.bind(this);
+ this.promise = this.promise.bind(this);
+ this.or = this.or.bind(this);
+ this.and = this.and.bind(this);
+ this.transform = this.transform.bind(this);
+ this.brand = this.brand.bind(this);
+ this.default = this.default.bind(this);
+ this.catch = this.catch.bind(this);
+ this.describe = this.describe.bind(this);
+ this.pipe = this.pipe.bind(this);
+ this.readonly = this.readonly.bind(this);
+ this.isNullable = this.isNullable.bind(this);
+ this.isOptional = this.isOptional.bind(this);
+ }
+ get description() {
+ return this._def.description;
+ }
+ _getType(input) {
+ return getParsedType(input.data);
+ }
+ _getOrReturnCtx(input, ctx) {
+ return (ctx || {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: getParsedType(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ });
+ }
+ _processInputParams(input) {
+ return {
+ status: new ParseStatus(),
+ ctx: {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: getParsedType(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ },
+ };
+ }
+ _parseSync(input) {
+ const result = this._parse(input);
+ if (isAsync(result)) {
+ throw new Error("Synchronous parse encountered promise.");
+ }
+ return result;
+ }
+ _parseAsync(input) {
+ const result = this._parse(input);
+ return Promise.resolve(result);
+ }
+ parse(data, params) {
+ const result = this.safeParse(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ safeParse(data, params) {
+ var _a;
+ const ctx = {
+ common: {
+ issues: [],
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: getParsedType(data),
+ };
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
+ return handleResult(ctx, result);
+ }
+ async parseAsync(data, params) {
+ const result = await this.safeParseAsync(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ async safeParseAsync(data, params) {
+ const ctx = {
+ common: {
+ issues: [],
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ async: true,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: getParsedType(data),
+ };
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
+ const result = await (isAsync(maybeAsyncResult)
+ ? maybeAsyncResult
+ : Promise.resolve(maybeAsyncResult));
+ return handleResult(ctx, result);
+ }
+ refine(check, message) {
+ const getIssueProperties = (val) => {
+ if (typeof message === "string" || typeof message === "undefined") {
+ return { message };
+ }
+ else if (typeof message === "function") {
+ return message(val);
+ }
+ else {
+ return message;
+ }
+ };
+ return this._refinement((val, ctx) => {
+ const result = check(val);
+ const setError = () => ctx.addIssue({
+ code: ZodIssueCode.custom,
+ ...getIssueProperties(val),
+ });
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
+ return result.then((data) => {
+ if (!data) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ if (!result) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ refinement(check, refinementData) {
+ return this._refinement((val, ctx) => {
+ if (!check(val)) {
+ ctx.addIssue(typeof refinementData === "function"
+ ? refinementData(val, ctx)
+ : refinementData);
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ _refinement(refinement) {
+ return new ZodEffects({
+ schema: this,
+ typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
+ effect: { type: "refinement", refinement },
+ });
+ }
+ superRefine(refinement) {
+ return this._refinement(refinement);
+ }
+ optional() {
+ return ZodOptional.create(this, this._def);
+ }
+ nullable() {
+ return ZodNullable.create(this, this._def);
+ }
+ nullish() {
+ return this.nullable().optional();
+ }
+ array() {
+ return ZodArray.create(this, this._def);
+ }
+ promise() {
+ return ZodPromise.create(this, this._def);
+ }
+ or(option) {
+ return ZodUnion.create([this, option], this._def);
+ }
+ and(incoming) {
+ return ZodIntersection.create(this, incoming, this._def);
+ }
+ transform(transform) {
+ return new ZodEffects({
+ ...processCreateParams(this._def),
+ schema: this,
+ typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
+ effect: { type: "transform", transform },
+ });
+ }
+ default(def) {
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodDefault({
+ ...processCreateParams(this._def),
+ innerType: this,
+ defaultValue: defaultValueFunc,
+ typeName: exports.ZodFirstPartyTypeKind.ZodDefault,
+ });
+ }
+ brand() {
+ return new ZodBranded({
+ typeName: exports.ZodFirstPartyTypeKind.ZodBranded,
+ type: this,
+ ...processCreateParams(this._def),
+ });
+ }
+ catch(def) {
+ const catchValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodCatch({
+ ...processCreateParams(this._def),
+ innerType: this,
+ catchValue: catchValueFunc,
+ typeName: exports.ZodFirstPartyTypeKind.ZodCatch,
+ });
+ }
+ describe(description) {
+ const This = this.constructor;
+ return new This({
+ ...this._def,
+ description,
+ });
+ }
+ pipe(target) {
+ return ZodPipeline.create(this, target);
+ }
+ readonly() {
+ return ZodReadonly.create(this);
+ }
+ isOptional() {
+ return this.safeParse(undefined).success;
+ }
+ isNullable() {
+ return this.safeParse(null).success;
+ }
+ }
+ const cuidRegex = /^c[^\s-]{8,}$/i;
+ const cuid2Regex = /^[a-z][a-z0-9]*$/;
+ const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
+ // const uuidRegex =
+ // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
+ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
+ // 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@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
+ // const emailRegex =
+ // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
+ // const emailRegex =
+ // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
+ const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
+ // const emailRegex =
+ // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
+ const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
+ const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
+ const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
+ // Adapted from https://stackoverflow.com/a/3143231
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
+ }
+ }
+ };
+ function isValidIP(ip, version) {
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
+ return true;
+ }
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
+ return true;
+ }
+ return false;
+ }
+ class ZodString extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
+ validation,
+ code: ZodIssueCode.invalid_string,
+ ...errorUtil.errToObj(message),
+ });
+ /**
+ * @deprecated Use z.string().min(1) instead.
+ * @see {@link ZodString.min}
+ */
+ this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
+ this.trim = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "trim" }],
+ });
+ this.toLowerCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
+ });
+ this.toUpperCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
+ });
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = String(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.string) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.string,
+ received: ctx.parsedType,
+ }
+ //
+ );
+ return INVALID;
+ }
+ const status = new ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.length < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.length > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "length") {
+ const tooBig = input.data.length > check.value;
+ const tooSmall = input.data.length < check.value;
+ if (tooBig || tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ if (tooBig) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ else if (tooSmall) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ status.dirty();
+ }
+ }
+ else if (check.kind === "email") {
+ if (!emailRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "email",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "emoji") {
+ if (!emojiRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "emoji",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "uuid") {
+ if (!uuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "uuid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "cuid") {
+ if (!cuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "cuid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "cuid2") {
+ if (!cuid2Regex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "cuid2",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "ulid") {
+ if (!ulidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "ulid",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "url") {
+ try {
+ new URL(input.data);
+ }
+ catch (_a) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "url",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "regex") {
+ check.regex.lastIndex = 0;
+ const testResult = check.regex.test(input.data);
+ if (!testResult) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "regex",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "trim") {
+ input.data = input.data.trim();
+ }
+ else if (check.kind === "includes") {
+ if (!input.data.includes(check.value, check.position)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { includes: check.value, position: check.position },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "toLowerCase") {
+ input.data = input.data.toLowerCase();
+ }
+ else if (check.kind === "toUpperCase") {
+ input.data = input.data.toUpperCase();
+ }
+ else if (check.kind === "startsWith") {
+ if (!input.data.startsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { startsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "endsWith") {
+ if (!input.data.endsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: { endsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "datetime") {
+ const regex = datetimeRegex(check);
+ if (!regex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_string,
+ validation: "datetime",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "ip") {
+ if (!isValidIP(input.data, check.version)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ validation: "ip",
+ code: ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ exports.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ _addCheck(check) {
+ return new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ email(message) {
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
+ }
+ url(message) {
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
+ }
+ emoji(message) {
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
+ }
+ uuid(message) {
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
+ }
+ cuid(message) {
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
+ }
+ cuid2(message) {
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
+ }
+ ulid(message) {
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
+ }
+ ip(options) {
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
+ }
+ datetime(options) {
+ var _a;
+ if (typeof options === "string") {
+ return this._addCheck({
+ kind: "datetime",
+ precision: null,
+ offset: false,
+ message: options,
+ });
+ }
+ return this._addCheck({
+ kind: "datetime",
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ regex(regex, message) {
+ return this._addCheck({
+ kind: "regex",
+ regex: regex,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ includes(value, options) {
+ return this._addCheck({
+ kind: "includes",
+ value: value,
+ position: options === null || options === void 0 ? void 0 : options.position,
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ startsWith(value, message) {
+ return this._addCheck({
+ kind: "startsWith",
+ value: value,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ endsWith(value, message) {
+ return this._addCheck({
+ kind: "endsWith",
+ value: value,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ min(minLength, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minLength,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ max(maxLength, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxLength,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ length(len, message) {
+ return this._addCheck({
+ kind: "length",
+ value: len,
+ ...errorUtil.errToObj(message),
+ });
+ }
+ get isDatetime() {
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
+ }
+ get isEmail() {
+ return !!this._def.checks.find((ch) => ch.kind === "email");
+ }
+ get isURL() {
+ return !!this._def.checks.find((ch) => ch.kind === "url");
+ }
+ get isEmoji() {
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
+ }
+ get isUUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
+ }
+ get isCUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
+ }
+ get isCUID2() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
+ }
+ get isULID() {
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
+ }
+ get isIP() {
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
+ }
+ get minLength() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxLength() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+ }
+ ZodString.create = (params) => {
+ var _a;
+ return new ZodString({
+ checks: [],
+ typeName: exports.ZodFirstPartyTypeKind.ZodString,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+ };
+ // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
+ function floatSafeRemainder(val, step) {
+ const valDecCount = (val.toString().split(".")[1] || "").length;
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
+ return (valInt % stepInt) / Math.pow(10, decCount);
+ }
+ class ZodNumber extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ this.step = this.multipleOf;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Number(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.number) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.number,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ let ctx = undefined;
+ const status = new ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "int") {
+ if (!exports.util.isInteger(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: "integer",
+ received: "float",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "finite") {
+ if (!Number.isFinite(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_finite,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ exports.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ int(message) {
+ return this._addCheck({
+ kind: "int",
+ message: errorUtil.toString(message),
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value: value,
+ message: errorUtil.toString(message),
+ });
+ }
+ finite(message) {
+ return this._addCheck({
+ kind: "finite",
+ message: errorUtil.toString(message),
+ });
+ }
+ safe(message) {
+ return this._addCheck({
+ kind: "min",
+ inclusive: true,
+ value: Number.MIN_SAFE_INTEGER,
+ message: errorUtil.toString(message),
+ })._addCheck({
+ kind: "max",
+ inclusive: true,
+ value: Number.MAX_SAFE_INTEGER,
+ message: errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+ get isInt() {
+ return !!this._def.checks.find((ch) => ch.kind === "int" ||
+ (ch.kind === "multipleOf" && exports.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);
+ }
+ }
+ ZodNumber.create = (params) => {
+ return new ZodNumber({
+ checks: [],
+ typeName: exports.ZodFirstPartyTypeKind.ZodNumber,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodBigInt extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = BigInt(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.bigint) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.bigint,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ let ctx = undefined;
+ const status = new ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ type: "bigint",
+ minimum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ type: "bigint",
+ maximum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (input.data % check.value !== BigInt(0)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ exports.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value,
+ message: errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+ }
+ ZodBigInt.create = (params) => {
+ var _a;
+ return new ZodBigInt({
+ checks: [],
+ typeName: exports.ZodFirstPartyTypeKind.ZodBigInt,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodBoolean extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Boolean(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.boolean) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.boolean,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ }
+ ZodBoolean.create = (params) => {
+ return new ZodBoolean({
+ typeName: exports.ZodFirstPartyTypeKind.ZodBoolean,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodDate extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = new Date(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.date) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.date,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (isNaN(input.data.getTime())) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_date,
+ });
+ return INVALID;
+ }
+ const status = new ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.getTime() < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ minimum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.getTime() > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ maximum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else {
+ exports.util.assertNever(check);
+ }
+ }
+ return {
+ status: status.value,
+ value: new Date(input.data.getTime()),
+ };
+ }
+ _addCheck(check) {
+ return new ZodDate({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ min(minDate, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minDate.getTime(),
+ message: errorUtil.toString(message),
+ });
+ }
+ max(maxDate, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxDate.getTime(),
+ message: errorUtil.toString(message),
+ });
+ }
+ get minDate() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min != null ? new Date(min) : null;
+ }
+ get maxDate() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max != null ? new Date(max) : null;
+ }
+ }
+ ZodDate.create = (params) => {
+ return new ZodDate({
+ checks: [],
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ typeName: exports.ZodFirstPartyTypeKind.ZodDate,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodSymbol extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.symbol) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.symbol,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ }
+ ZodSymbol.create = (params) => {
+ return new ZodSymbol({
+ typeName: exports.ZodFirstPartyTypeKind.ZodSymbol,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodUndefined extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.undefined,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ }
+ ZodUndefined.create = (params) => {
+ return new ZodUndefined({
+ typeName: exports.ZodFirstPartyTypeKind.ZodUndefined,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodNull extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.null) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.null,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ }
+ ZodNull.create = (params) => {
+ return new ZodNull({
+ typeName: exports.ZodFirstPartyTypeKind.ZodNull,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodAny extends ZodType {
+ constructor() {
+ super(...arguments);
+ // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
+ this._any = true;
+ }
+ _parse(input) {
+ return OK(input.data);
+ }
+ }
+ ZodAny.create = (params) => {
+ return new ZodAny({
+ typeName: exports.ZodFirstPartyTypeKind.ZodAny,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodUnknown extends ZodType {
+ constructor() {
+ super(...arguments);
+ // required
+ this._unknown = true;
+ }
+ _parse(input) {
+ return OK(input.data);
+ }
+ }
+ ZodUnknown.create = (params) => {
+ return new ZodUnknown({
+ typeName: exports.ZodFirstPartyTypeKind.ZodUnknown,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodNever extends ZodType {
+ _parse(input) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.never,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ }
+ ZodNever.create = (params) => {
+ return new ZodNever({
+ typeName: exports.ZodFirstPartyTypeKind.ZodNever,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodVoid extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.void,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ }
+ ZodVoid.create = (params) => {
+ return new ZodVoid({
+ typeName: exports.ZodFirstPartyTypeKind.ZodVoid,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodArray extends ZodType {
+ _parse(input) {
+ const { ctx, status } = this._processInputParams(input);
+ const def = this._def;
+ if (ctx.parsedType !== ZodParsedType.array) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (def.exactLength !== null) {
+ const tooBig = ctx.data.length > def.exactLength.value;
+ const tooSmall = ctx.data.length < def.exactLength.value;
+ if (tooBig || tooSmall) {
+ addIssueToContext(ctx, {
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
+ minimum: (tooSmall ? def.exactLength.value : undefined),
+ maximum: (tooBig ? def.exactLength.value : undefined),
+ type: "array",
+ inclusive: true,
+ exact: true,
+ message: def.exactLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.minLength !== null) {
+ if (ctx.data.length < def.minLength.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: def.minLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.minLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxLength !== null) {
+ if (ctx.data.length > def.maxLength.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: def.maxLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.maxLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (ctx.common.async) {
+ return Promise.all([...ctx.data].map((item, i) => {
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
+ })).then((result) => {
+ return ParseStatus.mergeArray(status, result);
+ });
+ }
+ const result = [...ctx.data].map((item, i) => {
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
+ });
+ return ParseStatus.mergeArray(status, result);
+ }
+ get element() {
+ return this._def.type;
+ }
+ min(minLength, message) {
+ return new ZodArray({
+ ...this._def,
+ minLength: { value: minLength, message: errorUtil.toString(message) },
+ });
+ }
+ max(maxLength, message) {
+ return new ZodArray({
+ ...this._def,
+ maxLength: { value: maxLength, message: errorUtil.toString(message) },
+ });
+ }
+ length(len, message) {
+ return new ZodArray({
+ ...this._def,
+ exactLength: { value: len, message: errorUtil.toString(message) },
+ });
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+ }
+ ZodArray.create = (schema, params) => {
+ return new ZodArray({
+ type: schema,
+ minLength: null,
+ maxLength: null,
+ exactLength: null,
+ typeName: exports.ZodFirstPartyTypeKind.ZodArray,
+ ...processCreateParams(params),
+ });
+ };
+ function deepPartialify(schema) {
+ if (schema instanceof ZodObject) {
+ const newShape = {};
+ for (const key in schema.shape) {
+ const fieldSchema = schema.shape[key];
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
+ }
+ return new ZodObject({
+ ...schema._def,
+ shape: () => newShape,
+ });
+ }
+ else if (schema instanceof ZodArray) {
+ return new ZodArray({
+ ...schema._def,
+ type: deepPartialify(schema.element),
+ });
+ }
+ else if (schema instanceof ZodOptional) {
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodNullable) {
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodTuple) {
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
+ }
+ else {
+ return schema;
+ }
+ }
+ class ZodObject extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._cached = null;
+ /**
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
+ */
+ this.nonstrict = this.passthrough;
+ // 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)
+ return this._cached;
+ const shape = this._def.shape();
+ const keys = exports.util.objectKeys(shape);
+ return (this._cached = { shape, keys });
+ }
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.object) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const { status, ctx } = this._processInputParams(input);
+ const { shape, keys: shapeKeys } = this._getCached();
+ const extraKeys = [];
+ if (!(this._def.catchall instanceof ZodNever &&
+ this._def.unknownKeys === "strip")) {
+ for (const key in ctx.data) {
+ if (!shapeKeys.includes(key)) {
+ extraKeys.push(key);
+ }
+ }
+ }
+ const pairs = [];
+ for (const key of shapeKeys) {
+ const keyValidator = shape[key];
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ if (this._def.catchall instanceof ZodNever) {
+ const unknownKeys = this._def.unknownKeys;
+ if (unknownKeys === "passthrough") {
+ for (const key of extraKeys) {
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: { status: "valid", value: ctx.data[key] },
+ });
+ }
+ }
+ else if (unknownKeys === "strict") {
+ if (extraKeys.length > 0) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.unrecognized_keys,
+ keys: extraKeys,
+ });
+ status.dirty();
+ }
+ }
+ else if (unknownKeys === "strip") ;
+ else {
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
+ }
+ }
+ else {
+ // run catchall validation
+ const catchall = this._def.catchall;
+ for (const key of extraKeys) {
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
+ ),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ }
+ if (ctx.common.async) {
+ return Promise.resolve()
+ .then(async () => {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ const key = await pair.key;
+ syncPairs.push({
+ key,
+ value: await pair.value,
+ alwaysSet: pair.alwaysSet,
+ });
+ }
+ return syncPairs;
+ })
+ .then((syncPairs) => {
+ return ParseStatus.mergeObjectSync(status, syncPairs);
+ });
+ }
+ else {
+ return ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get shape() {
+ return this._def.shape();
+ }
+ strict(message) {
+ errorUtil.errToObj;
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strict",
+ ...(message !== undefined
+ ? {
+ errorMap: (issue, ctx) => {
+ var _a, _b, _c, _d;
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
+ if (issue.code === "unrecognized_keys")
+ return {
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
+ };
+ return {
+ message: defaultError,
+ };
+ },
+ }
+ : {}),
+ });
+ }
+ strip() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strip",
+ });
+ }
+ passthrough() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "passthrough",
+ });
+ }
+ // const AugmentFactory =
+ // <Def extends ZodObjectDef>(def: Def) =>
+ // <Augmentation extends ZodRawShape>(
+ // augmentation: Augmentation
+ // ): ZodObject<
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
+ // Def["unknownKeys"],
+ // Def["catchall"]
+ // > => {
+ // return new ZodObject({
+ // ...def,
+ // shape: () => ({
+ // ...def.shape(),
+ // ...augmentation,
+ // }),
+ // }) as any;
+ // };
+ extend(augmentation) {
+ return new ZodObject({
+ ...this._def,
+ shape: () => ({
+ ...this._def.shape(),
+ ...augmentation,
+ }),
+ });
+ }
+ /**
+ * Prior to zod@1.0.12 there was a bug in the
+ * inferred type of merged objects. Please
+ * upgrade if you are experiencing issues.
+ */
+ merge(merging) {
+ const merged = new ZodObject({
+ unknownKeys: merging._def.unknownKeys,
+ catchall: merging._def.catchall,
+ shape: () => ({
+ ...this._def.shape(),
+ ...merging._def.shape(),
+ }),
+ typeName: exports.ZodFirstPartyTypeKind.ZodObject,
+ });
+ 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,
+ catchall: index,
+ });
+ }
+ pick(mask) {
+ const shape = {};
+ exports.util.objectKeys(mask).forEach((key) => {
+ if (mask[key] && this.shape[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ omit(mask) {
+ const shape = {};
+ exports.util.objectKeys(this.shape).forEach((key) => {
+ if (!mask[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ /**
+ * @deprecated
+ */
+ deepPartial() {
+ return deepPartialify(this);
+ }
+ partial(mask) {
+ const newShape = {};
+ exports.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,
+ });
+ }
+ required(mask) {
+ const newShape = {};
+ exports.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) {
+ newField = newField._def.innerType;
+ }
+ newShape[key] = newField;
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => newShape,
+ });
+ }
+ keyof() {
+ return createZodEnum(exports.util.objectKeys(this.shape));
+ }
+ }
+ ZodObject.create = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: exports.ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+ };
+ ZodObject.strictCreate = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strict",
+ catchall: ZodNever.create(),
+ typeName: exports.ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+ };
+ ZodObject.lazycreate = (shape, params) => {
+ return new ZodObject({
+ shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: exports.ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const options = this._def.options;
+ function handleResults(results) {
+ // return first issue-free validation if it exists
+ for (const result of results) {
+ if (result.result.status === "valid") {
+ return result.result;
+ }
+ }
+ for (const result of results) {
+ if (result.result.status === "dirty") {
+ // add issues from dirty option
+ ctx.common.issues.push(...result.ctx.common.issues);
+ return result.result;
+ }
+ }
+ // return invalid
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return INVALID;
+ }
+ if (ctx.common.async) {
+ return Promise.all(options.map(async (option) => {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ return {
+ result: await option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ }),
+ ctx: childCtx,
+ };
+ })).then(handleResults);
+ }
+ else {
+ let dirty = undefined;
+ const issues = [];
+ for (const option of options) {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ const result = option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ });
+ if (result.status === "valid") {
+ return result;
+ }
+ else if (result.status === "dirty" && !dirty) {
+ dirty = { result, ctx: childCtx };
+ }
+ if (childCtx.common.issues.length) {
+ issues.push(childCtx.common.issues);
+ }
+ }
+ if (dirty) {
+ ctx.common.issues.push(...dirty.ctx.common.issues);
+ return dirty.result;
+ }
+ const unionErrors = issues.map((issues) => new ZodError(issues));
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return INVALID;
+ }
+ }
+ get options() {
+ return this._def.options;
+ }
+ }
+ ZodUnion.create = (types, params) => {
+ return new ZodUnion({
+ options: types,
+ typeName: exports.ZodFirstPartyTypeKind.ZodUnion,
+ ...processCreateParams(params),
+ });
+ };
+ /////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////
+ ////////// //////////
+ ////////// ZodDiscriminatedUnion //////////
+ ////////// //////////
+ /////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////
+ const getDiscriminator = (type) => {
+ if (type instanceof ZodLazy) {
+ return getDiscriminator(type.schema);
+ }
+ else if (type instanceof ZodEffects) {
+ return getDiscriminator(type.innerType());
+ }
+ else if (type instanceof ZodLiteral) {
+ return [type.value];
+ }
+ else if (type instanceof ZodEnum) {
+ return type.options;
+ }
+ else if (type instanceof ZodNativeEnum) {
+ // eslint-disable-next-line ban/ban
+ return Object.keys(type.enum);
+ }
+ else if (type instanceof ZodDefault) {
+ return getDiscriminator(type._def.innerType);
+ }
+ else if (type instanceof ZodUndefined) {
+ return [undefined];
+ }
+ else if (type instanceof ZodNull) {
+ return [null];
+ }
+ else {
+ return null;
+ }
+ };
+ class ZodDiscriminatedUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.object) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const discriminator = this.discriminator;
+ const discriminatorValue = ctx.data[discriminator];
+ const option = this.optionsMap.get(discriminatorValue);
+ if (!option) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_union_discriminator,
+ options: Array.from(this.optionsMap.keys()),
+ path: [discriminator],
+ });
+ return INVALID;
+ }
+ if (ctx.common.async) {
+ return option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ else {
+ return option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ get discriminator() {
+ return this._def.discriminator;
+ }
+ get options() {
+ return this._def.options;
+ }
+ get optionsMap() {
+ return this._def.optionsMap;
+ }
+ /**
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
+ * have a different value for each object in the union.
+ * @param discriminator the name of the discriminator property
+ * @param types an array of object schemas
+ * @param params
+ */
+ static create(discriminator, options, params) {
+ // Get all the valid discriminator values
+ const optionsMap = new Map();
+ // try {
+ for (const type of options) {
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
+ if (!discriminatorValues) {
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
+ }
+ for (const value of discriminatorValues) {
+ if (optionsMap.has(value)) {
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
+ }
+ optionsMap.set(value, type);
+ }
+ }
+ return new ZodDiscriminatedUnion({
+ typeName: exports.ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
+ discriminator,
+ options,
+ optionsMap,
+ ...processCreateParams(params),
+ });
+ }
+ }
+ function mergeValues(a, b) {
+ const aType = getParsedType(a);
+ const bType = getParsedType(b);
+ if (a === b) {
+ return { valid: true, data: a };
+ }
+ else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
+ const bKeys = exports.util.objectKeys(b);
+ const sharedKeys = exports.util
+ .objectKeys(a)
+ .filter((key) => bKeys.indexOf(key) !== -1);
+ const newObj = { ...a, ...b };
+ for (const key of sharedKeys) {
+ const sharedValue = mergeValues(a[key], b[key]);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newObj[key] = sharedValue.data;
+ }
+ return { valid: true, data: newObj };
+ }
+ else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
+ if (a.length !== b.length) {
+ return { valid: false };
+ }
+ const newArray = [];
+ for (let index = 0; index < a.length; index++) {
+ const itemA = a[index];
+ const itemB = b[index];
+ const sharedValue = mergeValues(itemA, itemB);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newArray.push(sharedValue.data);
+ }
+ return { valid: true, data: newArray };
+ }
+ else if (aType === ZodParsedType.date &&
+ bType === ZodParsedType.date &&
+ +a === +b) {
+ return { valid: true, data: a };
+ }
+ else {
+ return { valid: false };
+ }
+ }
+ class ZodIntersection extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const handleParsed = (parsedLeft, parsedRight) => {
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
+ return INVALID;
+ }
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
+ if (!merged.valid) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_intersection_types,
+ });
+ return INVALID;
+ }
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
+ status.dirty();
+ }
+ return { status: status.value, value: merged.data };
+ };
+ if (ctx.common.async) {
+ return Promise.all([
+ this._def.left._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ this._def.right._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ ]).then(([left, right]) => handleParsed(left, right));
+ }
+ else {
+ return handleParsed(this._def.left._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }), this._def.right._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }));
+ }
+ }
+ }
+ ZodIntersection.create = (left, right, params) => {
+ return new ZodIntersection({
+ left: left,
+ right: right,
+ typeName: exports.ZodFirstPartyTypeKind.ZodIntersection,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodTuple extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.array) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ if (ctx.data.length < this._def.items.length) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ return INVALID;
+ }
+ const rest = this._def.rest;
+ if (!rest && ctx.data.length > this._def.items.length) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ status.dirty();
+ }
+ const items = [...ctx.data]
+ .map((item, itemIndex) => {
+ const schema = this._def.items[itemIndex] || this._def.rest;
+ if (!schema)
+ return null;
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
+ })
+ .filter((x) => !!x); // filter nulls
+ if (ctx.common.async) {
+ return Promise.all(items).then((results) => {
+ return ParseStatus.mergeArray(status, results);
+ });
+ }
+ else {
+ return ParseStatus.mergeArray(status, items);
+ }
+ }
+ get items() {
+ return this._def.items;
+ }
+ rest(rest) {
+ return new ZodTuple({
+ ...this._def,
+ rest,
+ });
+ }
+ }
+ ZodTuple.create = (schemas, params) => {
+ if (!Array.isArray(schemas)) {
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
+ }
+ return new ZodTuple({
+ items: schemas,
+ typeName: exports.ZodFirstPartyTypeKind.ZodTuple,
+ rest: null,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodRecord extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.object) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const pairs = [];
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ for (const key in ctx.data) {
+ pairs.push({
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
+ });
+ }
+ if (ctx.common.async) {
+ return ParseStatus.mergeObjectAsync(status, pairs);
+ }
+ else {
+ return ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get element() {
+ return this._def.valueType;
+ }
+ static create(first, second, third) {
+ if (second instanceof ZodType) {
+ return new ZodRecord({
+ keyType: first,
+ valueType: second,
+ typeName: exports.ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(third),
+ });
+ }
+ return new ZodRecord({
+ keyType: ZodString.create(),
+ valueType: first,
+ typeName: exports.ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(second),
+ });
+ }
+ }
+ class ZodMap extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.map) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.map,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
+ return {
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
+ };
+ });
+ if (ctx.common.async) {
+ const finalMap = new Map();
+ return Promise.resolve().then(async () => {
+ for (const pair of pairs) {
+ const key = await pair.key;
+ const value = await pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ });
+ }
+ else {
+ const finalMap = new Map();
+ for (const pair of pairs) {
+ const key = pair.key;
+ const value = pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ }
+ }
+ }
+ ZodMap.create = (keyType, valueType, params) => {
+ return new ZodMap({
+ valueType,
+ keyType,
+ typeName: exports.ZodFirstPartyTypeKind.ZodMap,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodSet extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.set) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.set,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const def = this._def;
+ if (def.minSize !== null) {
+ if (ctx.data.size < def.minSize.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_small,
+ minimum: def.minSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.minSize.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxSize !== null) {
+ if (ctx.data.size > def.maxSize.value) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.too_big,
+ maximum: def.maxSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.maxSize.message,
+ });
+ status.dirty();
+ }
+ }
+ const valueType = this._def.valueType;
+ function finalizeSet(elements) {
+ const parsedSet = new Set();
+ for (const element of elements) {
+ if (element.status === "aborted")
+ return INVALID;
+ if (element.status === "dirty")
+ status.dirty();
+ parsedSet.add(element.value);
+ }
+ return { status: status.value, value: parsedSet };
+ }
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
+ if (ctx.common.async) {
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
+ }
+ else {
+ return finalizeSet(elements);
+ }
+ }
+ min(minSize, message) {
+ return new ZodSet({
+ ...this._def,
+ minSize: { value: minSize, message: errorUtil.toString(message) },
+ });
+ }
+ max(maxSize, message) {
+ return new ZodSet({
+ ...this._def,
+ maxSize: { value: maxSize, message: errorUtil.toString(message) },
+ });
+ }
+ size(size, message) {
+ return this.min(size, message).max(size, message);
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+ }
+ ZodSet.create = (valueType, params) => {
+ return new ZodSet({
+ valueType,
+ minSize: null,
+ maxSize: null,
+ typeName: exports.ZodFirstPartyTypeKind.ZodSet,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodFunction extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.validate = this.implement;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.function) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.function,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ function makeArgsIssue(args, error) {
+ return makeIssue({
+ data: args,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodIssueCode.invalid_arguments,
+ argumentsError: error,
+ },
+ });
+ }
+ function makeReturnsIssue(returns, error) {
+ return makeIssue({
+ data: returns,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ getErrorMap(),
+ errorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodIssueCode.invalid_return_type,
+ returnTypeError: error,
+ },
+ });
+ }
+ const params = { errorMap: ctx.common.contextualErrorMap };
+ const fn = ctx.data;
+ if (this._def.returns instanceof ZodPromise) {
+ // Would love a way to avoid disabling this rule, but we need
+ // an alias (using an arrow function was what caused 2651).
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
+ const me = this;
+ return OK(async function (...args) {
+ const error = new ZodError([]);
+ const parsedArgs = await me._def.args
+ .parseAsync(args, params)
+ .catch((e) => {
+ error.addIssue(makeArgsIssue(args, e));
+ throw error;
+ });
+ const result = await Reflect.apply(fn, this, parsedArgs);
+ const parsedReturns = await me._def.returns._def.type
+ .parseAsync(result, params)
+ .catch((e) => {
+ error.addIssue(makeReturnsIssue(result, e));
+ throw error;
+ });
+ return parsedReturns;
+ });
+ }
+ else {
+ // Would love a way to avoid disabling this rule, but we need
+ // an alias (using an arrow function was what caused 2651).
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
+ const me = this;
+ return OK(function (...args) {
+ const parsedArgs = me._def.args.safeParse(args, params);
+ if (!parsedArgs.success) {
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
+ }
+ const result = Reflect.apply(fn, this, parsedArgs.data);
+ const parsedReturns = me._def.returns.safeParse(result, params);
+ if (!parsedReturns.success) {
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
+ }
+ return parsedReturns.data;
+ });
+ }
+ }
+ parameters() {
+ return this._def.args;
+ }
+ returnType() {
+ return this._def.returns;
+ }
+ args(...items) {
+ return new ZodFunction({
+ ...this._def,
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
+ });
+ }
+ returns(returnType) {
+ return new ZodFunction({
+ ...this._def,
+ returns: returnType,
+ });
+ }
+ implement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ strictImplement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ static create(args, returns, params) {
+ return new ZodFunction({
+ args: (args
+ ? args
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
+ returns: returns || ZodUnknown.create(),
+ typeName: exports.ZodFirstPartyTypeKind.ZodFunction,
+ ...processCreateParams(params),
+ });
+ }
+ }
+ class ZodLazy extends ZodType {
+ get schema() {
+ return this._def.getter();
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const lazySchema = this._def.getter();
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
+ }
+ }
+ ZodLazy.create = (getter, params) => {
+ return new ZodLazy({
+ getter: getter,
+ typeName: exports.ZodFirstPartyTypeKind.ZodLazy,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodLiteral extends ZodType {
+ _parse(input) {
+ if (input.data !== this._def.value) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_literal,
+ expected: this._def.value,
+ });
+ return INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+ get value() {
+ return this._def.value;
+ }
+ }
+ ZodLiteral.create = (value, params) => {
+ return new ZodLiteral({
+ value: value,
+ typeName: exports.ZodFirstPartyTypeKind.ZodLiteral,
+ ...processCreateParams(params),
+ });
+ };
+ function createZodEnum(values, params) {
+ return new ZodEnum({
+ values,
+ typeName: exports.ZodFirstPartyTypeKind.ZodEnum,
+ ...processCreateParams(params),
+ });
+ }
+ class ZodEnum extends ZodType {
+ _parse(input) {
+ if (typeof input.data !== "string") {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ addIssueToContext(ctx, {
+ expected: exports.util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodIssueCode.invalid_type,
+ });
+ return INVALID;
+ }
+ if (this._def.values.indexOf(input.data) === -1) {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ get options() {
+ return this._def.values;
+ }
+ get enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Values() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ extract(values) {
+ return ZodEnum.create(values);
+ }
+ exclude(values) {
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
+ }
+ }
+ ZodEnum.create = createZodEnum;
+ class ZodNativeEnum extends ZodType {
+ _parse(input) {
+ const nativeEnumValues = exports.util.getValidEnumValues(this._def.values);
+ const ctx = this._getOrReturnCtx(input);
+ if (ctx.parsedType !== ZodParsedType.string &&
+ ctx.parsedType !== ZodParsedType.number) {
+ const expectedValues = exports.util.objectValues(nativeEnumValues);
+ addIssueToContext(ctx, {
+ expected: exports.util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodIssueCode.invalid_type,
+ });
+ return INVALID;
+ }
+ if (nativeEnumValues.indexOf(input.data) === -1) {
+ const expectedValues = exports.util.objectValues(nativeEnumValues);
+ addIssueToContext(ctx, {
+ received: ctx.data,
+ code: ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return INVALID;
+ }
+ return OK(input.data);
+ }
+ get enum() {
+ return this._def.values;
+ }
+ }
+ ZodNativeEnum.create = (values, params) => {
+ return new ZodNativeEnum({
+ values: values,
+ typeName: exports.ZodFirstPartyTypeKind.ZodNativeEnum,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodPromise extends ZodType {
+ unwrap() {
+ return this._def.type;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== ZodParsedType.promise &&
+ ctx.common.async === false) {
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.promise,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ const promisified = ctx.parsedType === ZodParsedType.promise
+ ? ctx.data
+ : Promise.resolve(ctx.data);
+ return OK(promisified.then((data) => {
+ return this._def.type.parseAsync(data, {
+ path: ctx.path,
+ errorMap: ctx.common.contextualErrorMap,
+ });
+ }));
+ }
+ }
+ ZodPromise.create = (schema, params) => {
+ return new ZodPromise({
+ type: schema,
+ typeName: exports.ZodFirstPartyTypeKind.ZodPromise,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodEffects extends ZodType {
+ innerType() {
+ return this._def.schema;
+ }
+ sourceType() {
+ return this._def.schema._def.typeName === exports.ZodFirstPartyTypeKind.ZodEffects
+ ? this._def.schema.sourceType()
+ : this._def.schema;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const effect = this._def.effect || null;
+ const checkCtx = {
+ addIssue: (arg) => {
+ addIssueToContext(ctx, arg);
+ if (arg.fatal) {
+ status.abort();
+ }
+ else {
+ status.dirty();
+ }
+ },
+ get path() {
+ return ctx.path;
+ },
+ };
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
+ if (effect.type === "preprocess") {
+ const processed = effect.transform(ctx.data, checkCtx);
+ if (ctx.common.issues.length) {
+ return {
+ status: "dirty",
+ value: ctx.data,
+ };
+ }
+ if (ctx.common.async) {
+ return Promise.resolve(processed).then((processed) => {
+ return this._def.schema._parseAsync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ });
+ }
+ else {
+ return this._def.schema._parseSync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ if (effect.type === "refinement") {
+ const executeRefinement = (acc
+ // effect: RefinementEffect<any>
+ ) => {
+ const result = effect.refinement(acc, checkCtx);
+ if (ctx.common.async) {
+ return Promise.resolve(result);
+ }
+ if (result instanceof Promise) {
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
+ }
+ return acc;
+ };
+ if (ctx.common.async === false) {
+ const inner = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inner.status === "aborted")
+ return INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ // return value is ignored
+ executeRefinement(inner.value);
+ return { status: status.value, value: inner.value };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((inner) => {
+ if (inner.status === "aborted")
+ return INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ return executeRefinement(inner.value).then(() => {
+ return { status: status.value, value: inner.value };
+ });
+ });
+ }
+ }
+ if (effect.type === "transform") {
+ if (ctx.common.async === false) {
+ const base = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (!isValid(base))
+ return base;
+ const result = effect.transform(base.value, checkCtx);
+ if (result instanceof Promise) {
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
+ }
+ return { status: status.value, value: result };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((base) => {
+ if (!isValid(base))
+ return base;
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
+ });
+ }
+ }
+ exports.util.assertNever(effect);
+ }
+ }
+ ZodEffects.create = (schema, effect, params) => {
+ return new ZodEffects({
+ schema,
+ typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
+ effect,
+ ...processCreateParams(params),
+ });
+ };
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
+ return new ZodEffects({
+ schema,
+ effect: { type: "preprocess", transform: preprocess },
+ typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodOptional extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === ZodParsedType.undefined) {
+ return OK(undefined);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+ }
+ ZodOptional.create = (type, params) => {
+ return new ZodOptional({
+ innerType: type,
+ typeName: exports.ZodFirstPartyTypeKind.ZodOptional,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodNullable extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === ZodParsedType.null) {
+ return OK(null);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+ }
+ ZodNullable.create = (type, params) => {
+ return new ZodNullable({
+ innerType: type,
+ typeName: exports.ZodFirstPartyTypeKind.ZodNullable,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodDefault extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ let data = ctx.data;
+ if (ctx.parsedType === ZodParsedType.undefined) {
+ data = this._def.defaultValue();
+ }
+ return this._def.innerType._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ removeDefault() {
+ return this._def.innerType;
+ }
+ }
+ ZodDefault.create = (type, params) => {
+ return new ZodDefault({
+ innerType: type,
+ typeName: exports.ZodFirstPartyTypeKind.ZodDefault,
+ defaultValue: typeof params.default === "function"
+ ? params.default
+ : () => params.default,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodCatch extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ // newCtx is used to not collect issues from inner types in ctx
+ const newCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ };
+ const result = this._def.innerType._parse({
+ data: newCtx.data,
+ path: newCtx.path,
+ parent: {
+ ...newCtx,
+ },
+ });
+ if (isAsync(result)) {
+ return result.then((result) => {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ });
+ }
+ else {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ }
+ }
+ removeCatch() {
+ return this._def.innerType;
+ }
+ }
+ ZodCatch.create = (type, params) => {
+ return new ZodCatch({
+ innerType: type,
+ typeName: exports.ZodFirstPartyTypeKind.ZodCatch,
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
+ ...processCreateParams(params),
+ });
+ };
+ class ZodNaN extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== ZodParsedType.nan) {
+ const ctx = this._getOrReturnCtx(input);
+ addIssueToContext(ctx, {
+ code: ZodIssueCode.invalid_type,
+ expected: ZodParsedType.nan,
+ received: ctx.parsedType,
+ });
+ return INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+ }
+ ZodNaN.create = (params) => {
+ return new ZodNaN({
+ typeName: exports.ZodFirstPartyTypeKind.ZodNaN,
+ ...processCreateParams(params),
+ });
+ };
+ const BRAND = Symbol("zod_brand");
+ class ZodBranded extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const data = ctx.data;
+ return this._def.type._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ unwrap() {
+ return this._def.type;
+ }
+ }
+ class ZodPipeline extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.common.async) {
+ const handleAsync = async () => {
+ const inResult = await this._def.in._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return DIRTY(inResult.value);
+ }
+ else {
+ return this._def.out._parseAsync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ };
+ return handleAsync();
+ }
+ else {
+ const inResult = this._def.in._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return {
+ status: "dirty",
+ value: inResult.value,
+ };
+ }
+ else {
+ return this._def.out._parseSync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ }
+ static create(a, b) {
+ return new ZodPipeline({
+ in: a,
+ out: b,
+ typeName: exports.ZodFirstPartyTypeKind.ZodPipeline,
+ });
+ }
+ }
+ class ZodReadonly extends ZodType {
+ _parse(input) {
+ const result = this._def.innerType._parse(input);
+ if (isValid(result)) {
+ result.value = Object.freeze(result.value);
+ }
+ return result;
+ }
+ }
+ ZodReadonly.create = (type, params) => {
+ return new ZodReadonly({
+ innerType: type,
+ typeName: exports.ZodFirstPartyTypeKind.ZodReadonly,
+ ...processCreateParams(params),
+ });
+ };
+ const custom = (check, params = {},
+ /*
+ * @deprecated
+ *
+ * Pass `fatal` into the params object instead:
+ *
+ * ```ts
+ * z.string().custom((val) => val.length > 5, { fatal: false })
+ * ```
+ *
+ */
+ fatal) => {
+ if (check)
+ return ZodAny.create().superRefine((data, ctx) => {
+ var _a, _b;
+ if (!check(data)) {
+ const p = typeof params === "function"
+ ? params(data)
+ : typeof params === "string"
+ ? { message: params }
+ : params;
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
+ const p2 = typeof p === "string" ? { message: p } : p;
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
+ }
+ });
+ return ZodAny.create();
+ };
+ const late = {
+ object: ZodObject.lazycreate,
+ };
+ exports.ZodFirstPartyTypeKind = void 0;
+ (function (ZodFirstPartyTypeKind) {
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
+ })(exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
+ const instanceOfType = (
+ // const instanceOfType = <T extends new (...args: any[]) => any>(
+ cls, params = {
+ message: `Input not instance of ${cls.name}`,
+ }) => custom((data) => data instanceof cls, params);
+ const stringType = ZodString.create;
+ const numberType = ZodNumber.create;
+ const nanType = ZodNaN.create;
+ const bigIntType = ZodBigInt.create;
+ const booleanType = ZodBoolean.create;
+ const dateType = ZodDate.create;
+ const symbolType = ZodSymbol.create;
+ const undefinedType = ZodUndefined.create;
+ const nullType = ZodNull.create;
+ const anyType = ZodAny.create;
+ const unknownType = ZodUnknown.create;
+ const neverType = ZodNever.create;
+ const voidType = ZodVoid.create;
+ const arrayType = ZodArray.create;
+ const objectType = ZodObject.create;
+ const strictObjectType = ZodObject.strictCreate;
+ const unionType = ZodUnion.create;
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
+ const intersectionType = ZodIntersection.create;
+ const tupleType = ZodTuple.create;
+ const recordType = ZodRecord.create;
+ const mapType = ZodMap.create;
+ const setType = ZodSet.create;
+ const functionType = ZodFunction.create;
+ const lazyType = ZodLazy.create;
+ const literalType = ZodLiteral.create;
+ const enumType = ZodEnum.create;
+ const nativeEnumType = ZodNativeEnum.create;
+ const promiseType = ZodPromise.create;
+ const effectsType = ZodEffects.create;
+ const optionalType = ZodOptional.create;
+ const nullableType = ZodNullable.create;
+ const preprocessType = ZodEffects.createWithPreprocess;
+ const pipelineType = ZodPipeline.create;
+ const ostring = () => stringType().optional();
+ const onumber = () => numberType().optional();
+ const oboolean = () => booleanType().optional();
+ const coerce = {
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
+ number: ((arg) => ZodNumber.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 })),
+ };
+ const NEVER = INVALID;
+
+ var z = /*#__PURE__*/Object.freeze({
+ __proto__: null,
+ defaultErrorMap: errorMap,
+ setErrorMap: setErrorMap,
+ getErrorMap: getErrorMap,
+ makeIssue: makeIssue,
+ EMPTY_PATH: EMPTY_PATH,
+ addIssueToContext: addIssueToContext,
+ ParseStatus: ParseStatus,
+ INVALID: INVALID,
+ DIRTY: DIRTY,
+ OK: OK,
+ isAborted: isAborted,
+ isDirty: isDirty,
+ isValid: isValid,
+ isAsync: isAsync,
+ get util () { return exports.util; },
+ get objectUtil () { return exports.objectUtil; },
+ ZodParsedType: ZodParsedType,
+ getParsedType: getParsedType,
+ ZodType: ZodType,
+ ZodString: ZodString,
+ ZodNumber: ZodNumber,
+ ZodBigInt: ZodBigInt,
+ ZodBoolean: ZodBoolean,
+ ZodDate: ZodDate,
+ ZodSymbol: ZodSymbol,
+ ZodUndefined: ZodUndefined,
+ ZodNull: ZodNull,
+ ZodAny: ZodAny,
+ ZodUnknown: ZodUnknown,
+ ZodNever: ZodNever,
+ ZodVoid: ZodVoid,
+ ZodArray: ZodArray,
+ ZodObject: ZodObject,
+ ZodUnion: ZodUnion,
+ ZodDiscriminatedUnion: ZodDiscriminatedUnion,
+ ZodIntersection: ZodIntersection,
+ ZodTuple: ZodTuple,
+ ZodRecord: ZodRecord,
+ ZodMap: ZodMap,
+ ZodSet: ZodSet,
+ ZodFunction: ZodFunction,
+ ZodLazy: ZodLazy,
+ ZodLiteral: ZodLiteral,
+ ZodEnum: ZodEnum,
+ ZodNativeEnum: ZodNativeEnum,
+ ZodPromise: ZodPromise,
+ ZodEffects: ZodEffects,
+ ZodTransformer: ZodEffects,
+ ZodOptional: ZodOptional,
+ ZodNullable: ZodNullable,
+ ZodDefault: ZodDefault,
+ ZodCatch: ZodCatch,
+ ZodNaN: ZodNaN,
+ BRAND: BRAND,
+ ZodBranded: ZodBranded,
+ ZodPipeline: ZodPipeline,
+ ZodReadonly: ZodReadonly,
+ custom: custom,
+ Schema: ZodType,
+ ZodSchema: ZodType,
+ late: late,
+ get ZodFirstPartyTypeKind () { return exports.ZodFirstPartyTypeKind; },
+ coerce: coerce,
+ any: anyType,
+ array: arrayType,
+ bigint: bigIntType,
+ boolean: booleanType,
+ date: dateType,
+ discriminatedUnion: discriminatedUnionType,
+ effect: effectsType,
+ 'enum': enumType,
+ 'function': functionType,
+ 'instanceof': instanceOfType,
+ intersection: intersectionType,
+ lazy: lazyType,
+ literal: literalType,
+ map: mapType,
+ nan: nanType,
+ nativeEnum: nativeEnumType,
+ never: neverType,
+ 'null': nullType,
+ nullable: nullableType,
+ number: numberType,
+ object: objectType,
+ oboolean: oboolean,
+ onumber: onumber,
+ optional: optionalType,
+ ostring: ostring,
+ pipeline: pipelineType,
+ preprocess: preprocessType,
+ promise: promiseType,
+ record: recordType,
+ set: setType,
+ strictObject: strictObjectType,
+ string: stringType,
+ symbol: symbolType,
+ transformer: effectsType,
+ tuple: tupleType,
+ 'undefined': undefinedType,
+ union: unionType,
+ unknown: unknownType,
+ 'void': voidType,
+ NEVER: NEVER,
+ ZodIssueCode: ZodIssueCode,
+ quotelessJson: quotelessJson,
+ ZodError: ZodError
+ });
+
+ exports.BRAND = BRAND;
+ exports.DIRTY = DIRTY;
+ exports.EMPTY_PATH = EMPTY_PATH;
+ exports.INVALID = INVALID;
+ exports.NEVER = NEVER;
+ exports.OK = OK;
+ exports.ParseStatus = ParseStatus;
+ exports.Schema = ZodType;
+ exports.ZodAny = ZodAny;
+ exports.ZodArray = ZodArray;
+ exports.ZodBigInt = ZodBigInt;
+ exports.ZodBoolean = ZodBoolean;
+ exports.ZodBranded = ZodBranded;
+ exports.ZodCatch = ZodCatch;
+ exports.ZodDate = ZodDate;
+ exports.ZodDefault = ZodDefault;
+ exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
+ exports.ZodEffects = ZodEffects;
+ exports.ZodEnum = ZodEnum;
+ exports.ZodError = ZodError;
+ exports.ZodFunction = ZodFunction;
+ exports.ZodIntersection = ZodIntersection;
+ exports.ZodIssueCode = ZodIssueCode;
+ exports.ZodLazy = ZodLazy;
+ exports.ZodLiteral = ZodLiteral;
+ exports.ZodMap = ZodMap;
+ exports.ZodNaN = ZodNaN;
+ exports.ZodNativeEnum = ZodNativeEnum;
+ exports.ZodNever = ZodNever;
+ exports.ZodNull = ZodNull;
+ exports.ZodNullable = ZodNullable;
+ exports.ZodNumber = ZodNumber;
+ exports.ZodObject = ZodObject;
+ exports.ZodOptional = ZodOptional;
+ exports.ZodParsedType = ZodParsedType;
+ exports.ZodPipeline = ZodPipeline;
+ exports.ZodPromise = ZodPromise;
+ exports.ZodReadonly = ZodReadonly;
+ exports.ZodRecord = ZodRecord;
+ exports.ZodSchema = ZodType;
+ exports.ZodSet = ZodSet;
+ exports.ZodString = ZodString;
+ exports.ZodSymbol = ZodSymbol;
+ exports.ZodTransformer = ZodEffects;
+ exports.ZodTuple = ZodTuple;
+ exports.ZodType = ZodType;
+ exports.ZodUndefined = ZodUndefined;
+ exports.ZodUnion = ZodUnion;
+ exports.ZodUnknown = ZodUnknown;
+ exports.ZodVoid = ZodVoid;
+ exports.addIssueToContext = addIssueToContext;
+ exports.any = anyType;
+ exports.array = arrayType;
+ exports.bigint = bigIntType;
+ exports.boolean = booleanType;
+ exports.coerce = coerce;
+ exports.custom = custom;
+ exports.date = dateType;
+ exports["default"] = z;
+ exports.defaultErrorMap = errorMap;
+ exports.discriminatedUnion = discriminatedUnionType;
+ exports.effect = effectsType;
+ exports["enum"] = enumType;
+ exports["function"] = functionType;
+ exports.getErrorMap = getErrorMap;
+ exports.getParsedType = getParsedType;
+ exports["instanceof"] = instanceOfType;
+ exports.intersection = intersectionType;
+ exports.isAborted = isAborted;
+ exports.isAsync = isAsync;
+ exports.isDirty = isDirty;
+ exports.isValid = isValid;
+ exports.late = late;
+ exports.lazy = lazyType;
+ exports.literal = literalType;
+ exports.makeIssue = makeIssue;
+ exports.map = mapType;
+ exports.nan = nanType;
+ exports.nativeEnum = nativeEnumType;
+ exports.never = neverType;
+ exports["null"] = nullType;
+ exports.nullable = nullableType;
+ exports.number = numberType;
+ exports.object = objectType;
+ exports.oboolean = oboolean;
+ exports.onumber = onumber;
+ exports.optional = optionalType;
+ exports.ostring = ostring;
+ exports.pipeline = pipelineType;
+ exports.preprocess = preprocessType;
+ exports.promise = promiseType;
+ exports.quotelessJson = quotelessJson;
+ exports.record = recordType;
+ exports.set = setType;
+ exports.setErrorMap = setErrorMap;
+ exports.strictObject = strictObjectType;
+ exports.string = stringType;
+ exports.symbol = symbolType;
+ exports.transformer = effectsType;
+ exports.tuple = tupleType;
+ exports["undefined"] = undefinedType;
+ exports.union = unionType;
+ exports.unknown = unknownType;
+ exports["void"] = voidType;
+ exports.z = z;
+
+ Object.defineProperty(exports, '__esModule', { value: true });
+
+}));
diff --git a/node_modules/zod/lib/locales/en.d.ts b/node_modules/zod/lib/locales/en.d.ts
new file mode 100644
index 0000000..e5a3871
--- /dev/null
+++ b/node_modules/zod/lib/locales/en.d.ts
@@ -0,0 +1,3 @@
+import { ZodErrorMap } from "../ZodError";
+declare const errorMap: ZodErrorMap;
+export default errorMap;
diff --git a/node_modules/zod/lib/locales/en.js b/node_modules/zod/lib/locales/en.js
new file mode 100644
index 0000000..98342a0
--- /dev/null
+++ b/node_modules/zod/lib/locales/en.js
@@ -0,0 +1,129 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const util_1 = require("../helpers/util");
+const ZodError_1 = require("../ZodError");
+const errorMap = (issue, _ctx) => {
+ let message;
+ switch (issue.code) {
+ case ZodError_1.ZodIssueCode.invalid_type:
+ if (issue.received === util_1.ZodParsedType.undefined) {
+ message = "Required";
+ }
+ else {
+ message = `Expected ${issue.expected}, received ${issue.received}`;
+ }
+ break;
+ case ZodError_1.ZodIssueCode.invalid_literal:
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_1.util.jsonStringifyReplacer)}`;
+ break;
+ case ZodError_1.ZodIssueCode.unrecognized_keys:
+ message = `Unrecognized key(s) in object: ${util_1.util.joinValues(issue.keys, ", ")}`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_union:
+ message = `Invalid input`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_union_discriminator:
+ message = `Invalid discriminator value. Expected ${util_1.util.joinValues(issue.options)}`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_enum_value:
+ message = `Invalid enum value. Expected ${util_1.util.joinValues(issue.options)}, received '${issue.received}'`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_arguments:
+ message = `Invalid function arguments`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_return_type:
+ message = `Invalid function return type`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_date:
+ message = `Invalid date`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_string:
+ if (typeof issue.validation === "object") {
+ if ("includes" in issue.validation) {
+ message = `Invalid input: must include "${issue.validation.includes}"`;
+ if (typeof issue.validation.position === "number") {
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
+ }
+ }
+ else if ("startsWith" in issue.validation) {
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
+ }
+ else if ("endsWith" in issue.validation) {
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
+ }
+ else {
+ util_1.util.assertNever(issue.validation);
+ }
+ }
+ else if (issue.validation !== "regex") {
+ message = `Invalid ${issue.validation}`;
+ }
+ else {
+ message = "Invalid";
+ }
+ break;
+ case ZodError_1.ZodIssueCode.too_small:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${issue.minimum}`;
+ else if (issue.type === "date")
+ message = `Date must be ${issue.exact
+ ? `exactly equal to `
+ : issue.inclusive
+ ? `greater than or equal to `
+ : `greater than `}${new Date(Number(issue.minimum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodError_1.ZodIssueCode.too_big:
+ if (issue.type === "array")
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
+ else if (issue.type === "string")
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
+ else if (issue.type === "number")
+ message = `Number must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `less than or equal to`
+ : `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")
+ message = `Date must be ${issue.exact
+ ? `exactly`
+ : issue.inclusive
+ ? `smaller than or equal to`
+ : `smaller than`} ${new Date(Number(issue.maximum))}`;
+ else
+ message = "Invalid input";
+ break;
+ case ZodError_1.ZodIssueCode.custom:
+ message = `Invalid input`;
+ break;
+ case ZodError_1.ZodIssueCode.invalid_intersection_types:
+ message = `Intersection results could not be merged`;
+ break;
+ case ZodError_1.ZodIssueCode.not_multiple_of:
+ message = `Number must be a multiple of ${issue.multipleOf}`;
+ break;
+ case ZodError_1.ZodIssueCode.not_finite:
+ message = "Number must be finite";
+ break;
+ default:
+ message = _ctx.defaultError;
+ util_1.util.assertNever(issue);
+ }
+ return { message };
+};
+exports.default = errorMap;
diff --git a/node_modules/zod/lib/types.d.ts b/node_modules/zod/lib/types.d.ts
new file mode 100644
index 0000000..0ece6e8
--- /dev/null
+++ b/node_modules/zod/lib/types.d.ts
@@ -0,0 +1,1029 @@
+import { enumUtil } from "./helpers/enumUtil";
+import { errorUtil } from "./helpers/errorUtil";
+import { AsyncParseReturnType, ParseContext, ParseInput, ParseParams, ParseReturnType, ParseStatus, SyncParseReturnType } from "./helpers/parseUtil";
+import { partialUtil } from "./helpers/partialUtil";
+import { Primitive } from "./helpers/typeAliases";
+import { objectUtil, util } from "./helpers/util";
+import { IssueData, StringValidation, ZodCustomIssue, ZodError, ZodErrorMap } from "./ZodError";
+export declare type RefinementCtx = {
+ addIssue: (arg: IssueData) => void;
+ path: (string | number)[];
+};
+export declare type ZodRawShape = {
+ [k: string]: ZodTypeAny;
+};
+export declare type ZodTypeAny = ZodType<any, any, any>;
+export declare type TypeOf<T extends ZodType<any, any, any>> = T["_output"];
+export declare type input<T extends ZodType<any, any, any>> = T["_input"];
+export declare type output<T extends ZodType<any, any, any>> = T["_output"];
+export type { TypeOf as infer };
+export declare type CustomErrorParams = Partial<util.Omit<ZodCustomIssue, "code">>;
+export interface ZodTypeDef {
+ errorMap?: ZodErrorMap;
+ description?: string;
+}
+export declare type RawCreateParams = {
+ errorMap?: ZodErrorMap;
+ invalid_type_error?: string;
+ required_error?: string;
+ description?: string;
+} | undefined;
+export declare type ProcessedCreateParams = {
+ errorMap?: ZodErrorMap;
+ description?: string;
+};
+export declare type SafeParseSuccess<Output> = {
+ success: true;
+ data: Output;
+};
+export declare type SafeParseError<Input> = {
+ success: false;
+ error: ZodError<Input>;
+};
+export declare type SafeParseReturnType<Input, Output> = SafeParseSuccess<Output> | SafeParseError<Input>;
+export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {
+ readonly _type: Output;
+ readonly _output: Output;
+ readonly _input: Input;
+ readonly _def: Def;
+ get description(): string | undefined;
+ abstract _parse(input: ParseInput): ParseReturnType<Output>;
+ _getType(input: ParseInput): string;
+ _getOrReturnCtx(input: ParseInput, ctx?: ParseContext | undefined): ParseContext;
+ _processInputParams(input: ParseInput): {
+ status: ParseStatus;
+ ctx: ParseContext;
+ };
+ _parseSync(input: ParseInput): SyncParseReturnType<Output>;
+ _parseAsync(input: ParseInput): AsyncParseReturnType<Output>;
+ parse(data: unknown, params?: Partial<ParseParams>): Output;
+ safeParse(data: unknown, params?: Partial<ParseParams>): SafeParseReturnType<Input, Output>;
+ parseAsync(data: unknown, params?: Partial<ParseParams>): Promise<Output>;
+ safeParseAsync(data: unknown, params?: Partial<ParseParams>): Promise<SafeParseReturnType<Input, Output>>;
+ spa: (data: unknown, params?: Partial<ParseParams> | undefined) => Promise<SafeParseReturnType<Input, Output>>;
+ refine<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, RefinedOutput, Input>;
+ refine(check: (arg: Output) => unknown | Promise<unknown>, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, Output, Input>;
+ refinement<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects<this, RefinedOutput, Input>;
+ refinement(check: (arg: Output) => boolean, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects<this, Output, Input>;
+ _refinement(refinement: RefinementEffect<Output>["refinement"]): ZodEffects<this, Output, Input>;
+ superRefine<RefinedOutput extends Output>(refinement: (arg: Output, ctx: RefinementCtx) => arg is RefinedOutput): ZodEffects<this, RefinedOutput, Input>;
+ superRefine(refinement: (arg: Output, ctx: RefinementCtx) => void): ZodEffects<this, Output, Input>;
+ superRefine(refinement: (arg: Output, ctx: RefinementCtx) => Promise<void>): ZodEffects<this, Output, Input>;
+ constructor(def: Def);
+ optional(): ZodOptional<this>;
+ nullable(): ZodNullable<this>;
+ nullish(): ZodOptional<ZodNullable<this>>;
+ array(): ZodArray<this>;
+ promise(): ZodPromise<this>;
+ or<T extends ZodTypeAny>(option: T): ZodUnion<[this, T]>;
+ and<T extends ZodTypeAny>(incoming: T): ZodIntersection<this, T>;
+ transform<NewOut>(transform: (arg: Output, ctx: RefinementCtx) => NewOut | Promise<NewOut>): ZodEffects<this, NewOut>;
+ default(def: util.noUndefined<Input>): ZodDefault<this>;
+ default(def: () => util.noUndefined<Input>): ZodDefault<this>;
+ brand<B extends string | number | symbol>(brand?: B): ZodBranded<this, B>;
+ catch(def: Output): ZodCatch<this>;
+ catch(def: (ctx: {
+ error: ZodError;
+ input: Input;
+ }) => Output): ZodCatch<this>;
+ describe(description: string): this;
+ pipe<T extends ZodTypeAny>(target: T): ZodPipeline<this, T>;
+ readonly(): ZodReadonly<this>;
+ isOptional(): boolean;
+ isNullable(): boolean;
+}
+export declare type IpVersion = "v4" | "v6";
+export declare type ZodStringCheck = {
+ kind: "min";
+ value: number;
+ message?: string;
+} | {
+ kind: "max";
+ value: number;
+ message?: string;
+} | {
+ kind: "length";
+ value: number;
+ message?: string;
+} | {
+ kind: "email";
+ message?: string;
+} | {
+ kind: "url";
+ message?: string;
+} | {
+ kind: "emoji";
+ message?: string;
+} | {
+ kind: "uuid";
+ message?: string;
+} | {
+ kind: "cuid";
+ message?: string;
+} | {
+ kind: "includes";
+ value: string;
+ position?: number;
+ message?: string;
+} | {
+ kind: "cuid2";
+ message?: string;
+} | {
+ kind: "ulid";
+ message?: string;
+} | {
+ kind: "startsWith";
+ value: string;
+ message?: string;
+} | {
+ kind: "endsWith";
+ value: string;
+ message?: string;
+} | {
+ kind: "regex";
+ regex: RegExp;
+ message?: string;
+} | {
+ kind: "trim";
+ message?: string;
+} | {
+ kind: "toLowerCase";
+ message?: string;
+} | {
+ kind: "toUpperCase";
+ message?: string;
+} | {
+ kind: "datetime";
+ offset: boolean;
+ precision: number | null;
+ message?: string;
+} | {
+ kind: "ip";
+ version?: IpVersion;
+ message?: string;
+};
+export interface ZodStringDef extends ZodTypeDef {
+ checks: ZodStringCheck[];
+ typeName: ZodFirstPartyTypeKind.ZodString;
+ coerce: boolean;
+}
+export declare class ZodString extends ZodType<string, ZodStringDef> {
+ _parse(input: ParseInput): ParseReturnType<string>;
+ protected _regex: (regex: RegExp, validation: StringValidation, message?: errorUtil.ErrMessage | undefined) => ZodEffects<this, string, string>;
+ _addCheck(check: ZodStringCheck): ZodString;
+ email(message?: errorUtil.ErrMessage): ZodString;
+ 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;
+ ulid(message?: errorUtil.ErrMessage): ZodString;
+ ip(options?: string | {
+ version?: "v4" | "v6";
+ message?: string;
+ }): ZodString;
+ datetime(options?: string | {
+ message?: string | undefined;
+ precision?: number | null;
+ offset?: boolean;
+ }): ZodString;
+ regex(regex: RegExp, message?: errorUtil.ErrMessage): ZodString;
+ includes(value: string, options?: {
+ message?: string;
+ position?: number;
+ }): ZodString;
+ startsWith(value: string, message?: errorUtil.ErrMessage): ZodString;
+ endsWith(value: string, message?: errorUtil.ErrMessage): ZodString;
+ min(minLength: number, message?: errorUtil.ErrMessage): ZodString;
+ max(maxLength: number, message?: errorUtil.ErrMessage): ZodString;
+ length(len: number, message?: errorUtil.ErrMessage): ZodString;
+ nonempty: (message?: errorUtil.ErrMessage | undefined) => ZodString;
+ 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 isULID(): boolean;
+ get isIP(): boolean;
+ get minLength(): number | null;
+ get maxLength(): number | null;
+ static create: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: true | undefined;
+ }) | undefined) => ZodString;
+}
+export declare type ZodNumberCheck = {
+ kind: "min";
+ value: number;
+ inclusive: boolean;
+ message?: string;
+} | {
+ kind: "max";
+ value: number;
+ inclusive: boolean;
+ message?: string;
+} | {
+ kind: "int";
+ message?: string;
+} | {
+ kind: "multipleOf";
+ value: number;
+ message?: string;
+} | {
+ kind: "finite";
+ message?: string;
+};
+export interface ZodNumberDef extends ZodTypeDef {
+ checks: ZodNumberCheck[];
+ typeName: ZodFirstPartyTypeKind.ZodNumber;
+ coerce: boolean;
+}
+export declare class ZodNumber extends ZodType<number, ZodNumberDef> {
+ _parse(input: ParseInput): ParseReturnType<number>;
+ static create: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodNumber;
+ gte(value: number, message?: errorUtil.ErrMessage): ZodNumber;
+ min: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber;
+ gt(value: number, message?: errorUtil.ErrMessage): ZodNumber;
+ lte(value: number, message?: errorUtil.ErrMessage): ZodNumber;
+ max: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber;
+ lt(value: number, message?: errorUtil.ErrMessage): ZodNumber;
+ protected setLimit(kind: "min" | "max", value: number, inclusive: boolean, message?: string): ZodNumber;
+ _addCheck(check: ZodNumberCheck): ZodNumber;
+ int(message?: errorUtil.ErrMessage): ZodNumber;
+ positive(message?: errorUtil.ErrMessage): ZodNumber;
+ negative(message?: errorUtil.ErrMessage): ZodNumber;
+ nonpositive(message?: errorUtil.ErrMessage): ZodNumber;
+ nonnegative(message?: errorUtil.ErrMessage): ZodNumber;
+ multipleOf(value: number, message?: errorUtil.ErrMessage): ZodNumber;
+ step: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber;
+ finite(message?: errorUtil.ErrMessage): ZodNumber;
+ safe(message?: errorUtil.ErrMessage): ZodNumber;
+ get minValue(): number | null;
+ get maxValue(): number | null;
+ get isInt(): boolean;
+ get isFinite(): boolean;
+}
+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;
+ coerce: boolean;
+}
+export declare class ZodBigInt extends ZodType<bigint, ZodBigIntDef> {
+ _parse(input: ParseInput): ParseReturnType<bigint>;
+ static create: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | 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;
+}
+export interface ZodBooleanDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodBoolean;
+ coerce: boolean;
+}
+export declare class ZodBoolean extends ZodType<boolean, ZodBooleanDef> {
+ _parse(input: ParseInput): ParseReturnType<boolean>;
+ static create: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodBoolean;
+}
+export declare type ZodDateCheck = {
+ kind: "min";
+ value: number;
+ message?: string;
+} | {
+ kind: "max";
+ value: number;
+ message?: string;
+};
+export interface ZodDateDef extends ZodTypeDef {
+ checks: ZodDateCheck[];
+ coerce: boolean;
+ typeName: ZodFirstPartyTypeKind.ZodDate;
+}
+export declare class ZodDate extends ZodType<Date, ZodDateDef> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ _addCheck(check: ZodDateCheck): ZodDate;
+ min(minDate: Date, message?: errorUtil.ErrMessage): ZodDate;
+ max(maxDate: Date, message?: errorUtil.ErrMessage): ZodDate;
+ get minDate(): Date | null;
+ get maxDate(): Date | null;
+ static create: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodDate;
+}
+export interface ZodSymbolDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodSymbol;
+}
+export declare class ZodSymbol extends ZodType<symbol, ZodSymbolDef, symbol> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodSymbol;
+}
+export interface ZodUndefinedDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodUndefined;
+}
+export declare class ZodUndefined extends ZodType<undefined, ZodUndefinedDef> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ params?: RawCreateParams;
+ static create: (params?: RawCreateParams) => ZodUndefined;
+}
+export interface ZodNullDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodNull;
+}
+export declare class ZodNull extends ZodType<null, ZodNullDef> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodNull;
+}
+export interface ZodAnyDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodAny;
+}
+export declare class ZodAny extends ZodType<any, ZodAnyDef> {
+ _any: true;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodAny;
+}
+export interface ZodUnknownDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodUnknown;
+}
+export declare class ZodUnknown extends ZodType<unknown, ZodUnknownDef> {
+ _unknown: true;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodUnknown;
+}
+export interface ZodNeverDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodNever;
+}
+export declare class ZodNever extends ZodType<never, ZodNeverDef> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodNever;
+}
+export interface ZodVoidDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodVoid;
+}
+export declare class ZodVoid extends ZodType<void, ZodVoidDef> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: (params?: RawCreateParams) => ZodVoid;
+}
+export interface ZodArrayDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ type: T;
+ typeName: ZodFirstPartyTypeKind.ZodArray;
+ exactLength: {
+ value: number;
+ message?: string;
+ } | null;
+ minLength: {
+ value: number;
+ message?: string;
+ } | null;
+ maxLength: {
+ value: number;
+ message?: string;
+ } | null;
+}
+export declare type ArrayCardinality = "many" | "atleastone";
+export declare type arrayOutputType<T extends ZodTypeAny, Cardinality extends ArrayCardinality = "many"> = Cardinality extends "atleastone" ? [T["_output"], ...T["_output"][]] : T["_output"][];
+export declare class ZodArray<T extends ZodTypeAny, Cardinality extends ArrayCardinality = "many"> extends ZodType<arrayOutputType<T, Cardinality>, ZodArrayDef<T>, Cardinality extends "atleastone" ? [T["_input"], ...T["_input"][]] : T["_input"][]> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get element(): T;
+ min(minLength: number, message?: errorUtil.ErrMessage): this;
+ max(maxLength: number, message?: errorUtil.ErrMessage): this;
+ length(len: number, message?: errorUtil.ErrMessage): this;
+ nonempty(message?: errorUtil.ErrMessage): ZodArray<T, "atleastone">;
+ static create: <T_1 extends ZodTypeAny>(schema: T_1, params?: RawCreateParams) => ZodArray<T_1, "many">;
+}
+export declare type ZodNonEmptyArray<T extends ZodTypeAny> = ZodArray<T, "atleastone">;
+export declare type UnknownKeysParam = "passthrough" | "strict" | "strip";
+export interface ZodObjectDef<T extends ZodRawShape = ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodObject;
+ shape: () => T;
+ catchall: Catchall;
+ unknownKeys: UnknownKeys;
+}
+export declare type mergeTypes<A, B> = {
+ [k in keyof A | keyof B]: k extends keyof B ? B[k] : k extends keyof A ? A[k] : never;
+};
+export declare type objectOutputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny, UnknownKeys extends UnknownKeysParam = UnknownKeysParam> = objectUtil.flatten<objectUtil.addQuestionMarks<baseObjectOutputType<Shape>>> & CatchallOutput<Catchall> & PassthroughType<UnknownKeys>;
+export declare type baseObjectOutputType<Shape extends ZodRawShape> = {
+ [k in keyof Shape]: Shape[k]["_output"];
+};
+export declare type objectInputType<Shape extends ZodRawShape, Catchall extends ZodTypeAny, UnknownKeys extends UnknownKeysParam = UnknownKeysParam> = objectUtil.flatten<baseObjectInputType<Shape>> & CatchallInput<Catchall> & PassthroughType<UnknownKeys>;
+export declare type baseObjectInputType<Shape extends ZodRawShape> = objectUtil.addQuestionMarks<{
+ [k in keyof Shape]: Shape[k]["_input"];
+}>;
+export declare type CatchallOutput<T extends ZodTypeAny> = ZodTypeAny extends T ? unknown : {
+ [k: string]: T["_output"];
+};
+export declare type CatchallInput<T extends ZodTypeAny> = ZodTypeAny extends T ? unknown : {
+ [k: string]: T["_input"];
+};
+export declare type PassthroughType<T extends UnknownKeysParam> = T extends "passthrough" ? {
+ [k: string]: unknown;
+} : unknown;
+export declare type deoptional<T extends ZodTypeAny> = T extends ZodOptional<infer U> ? deoptional<U> : T extends ZodNullable<infer U> ? ZodNullable<deoptional<U>> : T;
+export declare type SomeZodObject = ZodObject<ZodRawShape, UnknownKeysParam, ZodTypeAny>;
+export declare type noUnrecognized<Obj extends object, Shape extends object> = {
+ [k in keyof Obj]: k extends keyof Shape ? Obj[k] : never;
+};
+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;
+ _getCached(): {
+ shape: T;
+ keys: string[];
+ };
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get shape(): T;
+ strict(message?: errorUtil.ErrMessage): ZodObject<T, "strict", Catchall>;
+ strip(): ZodObject<T, "strip", Catchall>;
+ passthrough(): ZodObject<T, "passthrough", Catchall>;
+ nonstrict: () => ZodObject<T, "passthrough", Catchall>;
+ extend<Augmentation extends ZodRawShape>(augmentation: Augmentation): ZodObject<objectUtil.extendShape<T, Augmentation>, UnknownKeys, 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>>;
+ merge<Incoming extends AnyZodObject, Augmentation extends Incoming["shape"]>(merging: Incoming): ZodObject<objectUtil.extendShape<T, Augmentation>, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"]>;
+ setKey<Key extends string, Schema extends ZodTypeAny>(key: Key, schema: Schema): ZodObject<T & {
+ [k in Key]: Schema;
+ }, UnknownKeys, Catchall>;
+ catchall<Index extends ZodTypeAny>(index: Index): ZodObject<T, UnknownKeys, Index>;
+ pick<Mask extends {
+ [k in keyof T]?: true;
+ }>(mask: Mask): ZodObject<Pick<T, Extract<keyof T, keyof Mask>>, UnknownKeys, Catchall>;
+ omit<Mask extends {
+ [k in keyof T]?: true;
+ }>(mask: Mask): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>;
+ deepPartial(): partialUtil.DeepPartial<this>;
+ partial(): ZodObject<{
+ [k in keyof T]: ZodOptional<T[k]>;
+ }, UnknownKeys, Catchall>;
+ partial<Mask extends {
+ [k in keyof T]?: true;
+ }>(mask: Mask): ZodObject<objectUtil.noNever<{
+ [k in keyof T]: k extends keyof Mask ? ZodOptional<T[k]> : T[k];
+ }>, UnknownKeys, Catchall>;
+ required(): ZodObject<{
+ [k in keyof T]: deoptional<T[k]>;
+ }, UnknownKeys, Catchall>;
+ required<Mask extends {
+ [k in keyof T]?: true;
+ }>(mask: Mask): ZodObject<objectUtil.noNever<{
+ [k in keyof T]: k extends keyof Mask ? deoptional<T[k]> : T[k];
+ }>, UnknownKeys, Catchall>;
+ keyof(): ZodEnum<enumUtil.UnionToTupleString<keyof T>>;
+ static create: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T_1>]: baseObjectInputType<T_1>[k_2]; }>;
+ static strictCreate: <T_1 extends ZodRawShape>(shape: T_1, params?: RawCreateParams) => ZodObject<T_1, "strict", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T_1>]: baseObjectInputType<T_1>[k_2]; }>;
+ static lazycreate: <T_1 extends ZodRawShape>(shape: () => T_1, params?: RawCreateParams) => ZodObject<T_1, "strip", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T_1>, { [k in keyof baseObjectOutputType<T_1>]: undefined extends baseObjectOutputType<T_1>[k] ? never : k; }[keyof T_1]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T_1>]: baseObjectInputType<T_1>[k_2]; }>;
+}
+export declare type AnyZodObject = ZodObject<any, any, any>;
+export declare type ZodUnionOptions = Readonly<[ZodTypeAny, ...ZodTypeAny[]]>;
+export interface ZodUnionDef<T extends ZodUnionOptions = Readonly<[
+ ZodTypeAny,
+ ZodTypeAny,
+ ...ZodTypeAny[]
+]>> extends ZodTypeDef {
+ options: T;
+ typeName: ZodFirstPartyTypeKind.ZodUnion;
+}
+export declare class ZodUnion<T extends ZodUnionOptions> extends ZodType<T[number]["_output"], ZodUnionDef<T>, T[number]["_input"]> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get options(): T;
+ static create: <T_1 extends readonly [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(types: T_1, params?: RawCreateParams) => ZodUnion<T_1>;
+}
+export declare type ZodDiscriminatedUnionOption<Discriminator extends string> = ZodObject<{
+ [key in Discriminator]: ZodTypeAny;
+} & ZodRawShape, UnknownKeysParam, ZodTypeAny>;
+export interface ZodDiscriminatedUnionDef<Discriminator extends string, Options extends ZodDiscriminatedUnionOption<string>[] = ZodDiscriminatedUnionOption<string>[]> extends ZodTypeDef {
+ discriminator: Discriminator;
+ options: Options;
+ optionsMap: Map<Primitive, ZodDiscriminatedUnionOption<any>>;
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion;
+}
+export declare class ZodDiscriminatedUnion<Discriminator extends string, Options extends ZodDiscriminatedUnionOption<Discriminator>[]> extends ZodType<output<Options[number]>, ZodDiscriminatedUnionDef<Discriminator, Options>, input<Options[number]>> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get discriminator(): Discriminator;
+ get options(): Options;
+ get optionsMap(): Map<Primitive, ZodDiscriminatedUnionOption<any>>;
+ static create<Discriminator extends string, Types extends [
+ ZodDiscriminatedUnionOption<Discriminator>,
+ ...ZodDiscriminatedUnionOption<Discriminator>[]
+ ]>(discriminator: Discriminator, options: Types, params?: RawCreateParams): ZodDiscriminatedUnion<Discriminator, Types>;
+}
+export interface ZodIntersectionDef<T extends ZodTypeAny = ZodTypeAny, U extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ left: T;
+ right: U;
+ typeName: ZodFirstPartyTypeKind.ZodIntersection;
+}
+export declare class ZodIntersection<T extends ZodTypeAny, U extends ZodTypeAny> extends ZodType<T["_output"] & U["_output"], ZodIntersectionDef<T, U>, T["_input"] & U["_input"]> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <T_1 extends ZodTypeAny, U_1 extends ZodTypeAny>(left: T_1, right: U_1, params?: RawCreateParams) => ZodIntersection<T_1, U_1>;
+}
+export declare type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
+export declare type AssertArray<T> = T extends any[] ? T : never;
+export declare type OutputTypeOfTuple<T extends ZodTupleItems | []> = AssertArray<{
+ [k in keyof T]: T[k] extends ZodType<any, any> ? T[k]["_output"] : never;
+}>;
+export declare type OutputTypeOfTupleWithRest<T extends ZodTupleItems | [], Rest extends ZodTypeAny | null = null> = Rest extends ZodTypeAny ? [...OutputTypeOfTuple<T>, ...Rest["_output"][]] : OutputTypeOfTuple<T>;
+export declare type InputTypeOfTuple<T extends ZodTupleItems | []> = AssertArray<{
+ [k in keyof T]: T[k] extends ZodType<any, any> ? T[k]["_input"] : never;
+}>;
+export declare type InputTypeOfTupleWithRest<T extends ZodTupleItems | [], Rest extends ZodTypeAny | null = null> = Rest extends ZodTypeAny ? [...InputTypeOfTuple<T>, ...Rest["_input"][]] : InputTypeOfTuple<T>;
+export interface ZodTupleDef<T extends ZodTupleItems | [] = ZodTupleItems, Rest extends ZodTypeAny | null = null> extends ZodTypeDef {
+ items: T;
+ rest: Rest;
+ typeName: ZodFirstPartyTypeKind.ZodTuple;
+}
+export declare type AnyZodTuple = ZodTuple<[
+ ZodTypeAny,
+ ...ZodTypeAny[]
+] | [], ZodTypeAny | null>;
+export declare class ZodTuple<T extends [ZodTypeAny, ...ZodTypeAny[]] | [] = [ZodTypeAny, ...ZodTypeAny[]], Rest extends ZodTypeAny | null = null> extends ZodType<OutputTypeOfTupleWithRest<T, Rest>, ZodTupleDef<T, Rest>, InputTypeOfTupleWithRest<T, Rest>> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get items(): T;
+ rest<Rest extends ZodTypeAny>(rest: Rest): ZodTuple<T, Rest>;
+ static create: <T_1 extends [] | [ZodTypeAny, ...ZodTypeAny[]]>(schemas: T_1, params?: RawCreateParams) => ZodTuple<T_1, null>;
+}
+export interface ZodRecordDef<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ valueType: Value;
+ keyType: Key;
+ typeName: ZodFirstPartyTypeKind.ZodRecord;
+}
+export declare type KeySchema = ZodType<string | number | symbol, any, any>;
+export declare type RecordType<K extends string | number | symbol, V> = [
+ string
+] 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"]>> {
+ get keySchema(): Key;
+ get valueSchema(): Value;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get element(): Value;
+ static create<Value extends ZodTypeAny>(valueType: Value, params?: RawCreateParams): ZodRecord<ZodString, Value>;
+ static create<Keys extends KeySchema, Value extends ZodTypeAny>(keySchema: Keys, valueType: Value, params?: RawCreateParams): ZodRecord<Keys, Value>;
+}
+export interface ZodMapDef<Key extends ZodTypeAny = ZodTypeAny, Value extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ valueType: Value;
+ keyType: Key;
+ typeName: ZodFirstPartyTypeKind.ZodMap;
+}
+export declare class ZodMap<Key extends ZodTypeAny = ZodTypeAny, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<Map<Key["_output"], Value["_output"]>, ZodMapDef<Key, Value>, Map<Key["_input"], Value["_input"]>> {
+ get keySchema(): Key;
+ get valueSchema(): Value;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <Key_1 extends ZodTypeAny = ZodTypeAny, Value_1 extends ZodTypeAny = ZodTypeAny>(keyType: Key_1, valueType: Value_1, params?: RawCreateParams) => ZodMap<Key_1, Value_1>;
+}
+export interface ZodSetDef<Value extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ valueType: Value;
+ typeName: ZodFirstPartyTypeKind.ZodSet;
+ minSize: {
+ value: number;
+ message?: string;
+ } | null;
+ maxSize: {
+ value: number;
+ message?: string;
+ } | null;
+}
+export declare class ZodSet<Value extends ZodTypeAny = ZodTypeAny> extends ZodType<Set<Value["_output"]>, ZodSetDef<Value>, Set<Value["_input"]>> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ min(minSize: number, message?: errorUtil.ErrMessage): this;
+ max(maxSize: number, message?: errorUtil.ErrMessage): this;
+ size(size: number, message?: errorUtil.ErrMessage): this;
+ nonempty(message?: errorUtil.ErrMessage): ZodSet<Value>;
+ static create: <Value_1 extends ZodTypeAny = ZodTypeAny>(valueType: Value_1, params?: RawCreateParams) => ZodSet<Value_1>;
+}
+export interface ZodFunctionDef<Args extends ZodTuple<any, any> = ZodTuple<any, any>, Returns extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ args: Args;
+ returns: Returns;
+ typeName: ZodFirstPartyTypeKind.ZodFunction;
+}
+export declare type OuterTypeOfFunction<Args extends ZodTuple<any, any>, Returns extends ZodTypeAny> = Args["_input"] extends Array<any> ? (...args: Args["_input"]) => Returns["_output"] : never;
+export declare type InnerTypeOfFunction<Args extends ZodTuple<any, any>, Returns extends ZodTypeAny> = Args["_output"] extends Array<any> ? (...args: Args["_output"]) => Returns["_input"] : never;
+export declare class ZodFunction<Args extends ZodTuple<any, any>, Returns extends ZodTypeAny> extends ZodType<OuterTypeOfFunction<Args, Returns>, ZodFunctionDef<Args, Returns>, InnerTypeOfFunction<Args, Returns>> {
+ _parse(input: ParseInput): ParseReturnType<any>;
+ parameters(): Args;
+ returnType(): 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>;
+ implement<F extends InnerTypeOfFunction<Args, Returns>>(func: F): ReturnType<F> extends Returns["_output"] ? (...args: Args["_input"]) => ReturnType<F> : OuterTypeOfFunction<Args, Returns>;
+ strictImplement(func: InnerTypeOfFunction<Args, Returns>): InnerTypeOfFunction<Args, Returns>;
+ validate: <F extends InnerTypeOfFunction<Args, Returns>>(func: F) => ReturnType<F> extends Returns["_output"] ? (...args: Args["_input"]) => ReturnType<F> : OuterTypeOfFunction<Args, Returns>;
+ static create(): ZodFunction<ZodTuple<[], ZodUnknown>, ZodUnknown>;
+ static create<T extends AnyZodTuple = ZodTuple<[], ZodUnknown>>(args: T): ZodFunction<T, ZodUnknown>;
+ static create<T extends AnyZodTuple, U extends ZodTypeAny>(args: T, returns: U): ZodFunction<T, U>;
+ static create<T extends AnyZodTuple = ZodTuple<[], ZodUnknown>, U extends ZodTypeAny = ZodUnknown>(args: T, returns: U, params?: RawCreateParams): ZodFunction<T, U>;
+}
+export interface ZodLazyDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ getter: () => T;
+ typeName: ZodFirstPartyTypeKind.ZodLazy;
+}
+export declare class ZodLazy<T extends ZodTypeAny> extends ZodType<output<T>, ZodLazyDef<T>, input<T>> {
+ get schema(): T;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <T_1 extends ZodTypeAny>(getter: () => T_1, params?: RawCreateParams) => ZodLazy<T_1>;
+}
+export interface ZodLiteralDef<T = any> extends ZodTypeDef {
+ value: T;
+ typeName: ZodFirstPartyTypeKind.ZodLiteral;
+}
+export declare class ZodLiteral<T> extends ZodType<T, ZodLiteralDef<T>> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get value(): T;
+ static create: <T_1 extends Primitive>(value: T_1, params?: RawCreateParams) => ZodLiteral<T_1>;
+}
+export declare type ArrayKeys = keyof any[];
+export declare type Indices<T> = Exclude<keyof T, ArrayKeys>;
+export declare type EnumValues = [string, ...string[]];
+export declare type Values<T extends EnumValues> = {
+ [k in T[number]]: k;
+};
+export interface ZodEnumDef<T extends EnumValues = EnumValues> extends ZodTypeDef {
+ values: T;
+ typeName: ZodFirstPartyTypeKind.ZodEnum;
+}
+export declare type Writeable<T> = {
+ -readonly [P in keyof T]: T[P];
+};
+export declare type FilterEnum<Values, ToExclude> = Values extends [] ? [] : Values extends [infer Head, ...infer Rest] ? Head extends ToExclude ? FilterEnum<Rest, ToExclude> : [Head, ...FilterEnum<Rest, ToExclude>] : never;
+export declare type typecast<A, T> = A extends T ? A : never;
+declare function createZodEnum<U extends string, T extends Readonly<[U, ...U[]]>>(values: T, params?: RawCreateParams): ZodEnum<Writeable<T>>;
+declare function createZodEnum<U extends string, T extends [U, ...U[]]>(values: T, params?: RawCreateParams): ZodEnum<T>;
+export declare class ZodEnum<T extends [string, ...string[]]> extends ZodType<T[number], ZodEnumDef<T>> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ get options(): T;
+ get enum(): Values<T>;
+ get Values(): Values<T>;
+ get Enum(): Values<T>;
+ extract<ToExtract extends readonly [T[number], ...T[number][]]>(values: ToExtract): ZodEnum<Writeable<ToExtract>>;
+ exclude<ToExclude extends readonly [T[number], ...T[number][]]>(values: ToExclude): ZodEnum<typecast<Writeable<FilterEnum<T, ToExclude[number]>>, [string, ...string[]]>>;
+ static create: typeof createZodEnum;
+}
+export interface ZodNativeEnumDef<T extends EnumLike = EnumLike> extends ZodTypeDef {
+ values: T;
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum;
+}
+export declare type EnumLike = {
+ [k: string]: string | number;
+ [nu: number]: string;
+};
+export declare class ZodNativeEnum<T extends EnumLike> extends ZodType<T[keyof T], ZodNativeEnumDef<T>> {
+ _parse(input: ParseInput): ParseReturnType<T[keyof T]>;
+ get enum(): T;
+ static create: <T_1 extends EnumLike>(values: T_1, params?: RawCreateParams) => ZodNativeEnum<T_1>;
+}
+export interface ZodPromiseDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ type: T;
+ typeName: ZodFirstPartyTypeKind.ZodPromise;
+}
+export declare class ZodPromise<T extends ZodTypeAny> extends ZodType<Promise<T["_output"]>, ZodPromiseDef<T>, Promise<T["_input"]>> {
+ unwrap(): T;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <T_1 extends ZodTypeAny>(schema: T_1, params?: RawCreateParams) => ZodPromise<T_1>;
+}
+export declare type Refinement<T> = (arg: T, ctx: RefinementCtx) => any;
+export declare type SuperRefinement<T> = (arg: T, ctx: RefinementCtx) => void | Promise<void>;
+export declare type RefinementEffect<T> = {
+ type: "refinement";
+ refinement: (arg: T, ctx: RefinementCtx) => any;
+};
+export declare type TransformEffect<T> = {
+ type: "transform";
+ transform: (arg: T, ctx: RefinementCtx) => any;
+};
+export declare type PreprocessEffect<T> = {
+ type: "preprocess";
+ transform: (arg: T, ctx: RefinementCtx) => any;
+};
+export declare type Effect<T> = RefinementEffect<T> | TransformEffect<T> | PreprocessEffect<T>;
+export interface ZodEffectsDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ schema: T;
+ typeName: ZodFirstPartyTypeKind.ZodEffects;
+ effect: Effect<any>;
+}
+export declare class ZodEffects<T extends ZodTypeAny, Output = output<T>, Input = input<T>> extends ZodType<Output, ZodEffectsDef<T>, Input> {
+ innerType(): T;
+ sourceType(): T;
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <I extends ZodTypeAny>(schema: I, effect: Effect<I["_output"]>, params?: RawCreateParams) => ZodEffects<I, I["_output"], input<I>>;
+ static createWithPreprocess: <I extends ZodTypeAny>(preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
+}
+export { ZodEffects as ZodTransformer };
+export interface ZodOptionalDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ innerType: T;
+ typeName: ZodFirstPartyTypeKind.ZodOptional;
+}
+export declare type ZodOptionalType<T extends ZodTypeAny> = ZodOptional<T>;
+export declare class ZodOptional<T extends ZodTypeAny> extends ZodType<T["_output"] | undefined, ZodOptionalDef<T>, T["_input"] | undefined> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ unwrap(): T;
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodOptional<T_1>;
+}
+export interface ZodNullableDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ innerType: T;
+ typeName: ZodFirstPartyTypeKind.ZodNullable;
+}
+export declare type ZodNullableType<T extends ZodTypeAny> = ZodNullable<T>;
+export declare class ZodNullable<T extends ZodTypeAny> extends ZodType<T["_output"] | null, ZodNullableDef<T>, T["_input"] | null> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ unwrap(): T;
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodNullable<T_1>;
+}
+export interface ZodDefaultDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ innerType: T;
+ defaultValue: () => util.noUndefined<T["_input"]>;
+ typeName: ZodFirstPartyTypeKind.ZodDefault;
+}
+export declare class ZodDefault<T extends ZodTypeAny> extends ZodType<util.noUndefined<T["_output"]>, ZodDefaultDef<T>, T["_input"] | undefined> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ removeDefault(): T;
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params: {
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ default: T_1["_input"] | (() => util.noUndefined<T_1["_input"]>);
+ }) => ZodDefault<T_1>;
+}
+export interface ZodCatchDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ innerType: T;
+ catchValue: (ctx: {
+ error: ZodError;
+ input: unknown;
+ }) => T["_input"];
+ typeName: ZodFirstPartyTypeKind.ZodCatch;
+}
+export declare class ZodCatch<T extends ZodTypeAny> extends ZodType<T["_output"], ZodCatchDef<T>, unknown> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ removeCatch(): T;
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params: {
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ catch: T_1["_output"] | (() => T_1["_output"]);
+ }) => ZodCatch<T_1>;
+}
+export interface ZodNaNDef extends ZodTypeDef {
+ typeName: ZodFirstPartyTypeKind.ZodNaN;
+}
+export declare class ZodNaN extends ZodType<number, ZodNaNDef> {
+ _parse(input: ParseInput): ParseReturnType<any>;
+ static create: (params?: RawCreateParams) => ZodNaN;
+}
+export interface ZodBrandedDef<T extends ZodTypeAny> extends ZodTypeDef {
+ type: T;
+ typeName: ZodFirstPartyTypeKind.ZodBranded;
+}
+export declare const BRAND: unique symbol;
+export declare type BRAND<T extends string | number | symbol> = {
+ [BRAND]: {
+ [k in T]: true;
+ };
+};
+export declare class ZodBranded<T extends ZodTypeAny, B extends string | number | symbol> extends ZodType<T["_output"] & BRAND<B>, ZodBrandedDef<T>, T["_input"]> {
+ _parse(input: ParseInput): ParseReturnType<any>;
+ unwrap(): T;
+}
+export interface ZodPipelineDef<A extends ZodTypeAny, B extends ZodTypeAny> extends ZodTypeDef {
+ in: A;
+ out: B;
+ typeName: ZodFirstPartyTypeKind.ZodPipeline;
+}
+export declare class ZodPipeline<A extends ZodTypeAny, B extends ZodTypeAny> extends ZodType<B["_output"], ZodPipelineDef<A, B>, A["_input"]> {
+ _parse(input: ParseInput): ParseReturnType<any>;
+ static create<A extends ZodTypeAny, B extends ZodTypeAny>(a: A, b: B): ZodPipeline<A, B>;
+}
+declare type BuiltIn = (((...args: any[]) => any) | (new (...args: any[]) => any)) | {
+ readonly [Symbol.toStringTag]: string;
+} | Date | Error | Generator | Promise<unknown> | RegExp;
+declare type MakeReadonly<T> = T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : T extends Set<infer V> ? ReadonlySet<V> : T extends [infer Head, ...infer Tail] ? readonly [Head, ...Tail] : T extends Array<infer V> ? ReadonlyArray<V> : T extends BuiltIn ? T : Readonly<T>;
+export interface ZodReadonlyDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
+ innerType: T;
+ typeName: ZodFirstPartyTypeKind.ZodReadonly;
+}
+export declare class ZodReadonly<T extends ZodTypeAny> extends ZodType<MakeReadonly<T["_output"]>, ZodReadonlyDef<T>, T["_input"]> {
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodReadonly<T_1>;
+}
+declare type CustomParams = CustomErrorParams & {
+ fatal?: boolean;
+};
+export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: string | CustomParams | ((input: any) => CustomParams), fatal?: boolean | undefined) => ZodType<T, ZodTypeDef, T>;
+export { ZodType as Schema, ZodType as ZodSchema };
+export declare const late: {
+ object: <T extends ZodRawShape>(shape: () => T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T>]: baseObjectInputType<T>[k_2]; }>;
+};
+export declare enum ZodFirstPartyTypeKind {
+ ZodString = "ZodString",
+ ZodNumber = "ZodNumber",
+ ZodNaN = "ZodNaN",
+ ZodBigInt = "ZodBigInt",
+ ZodBoolean = "ZodBoolean",
+ ZodDate = "ZodDate",
+ ZodSymbol = "ZodSymbol",
+ ZodUndefined = "ZodUndefined",
+ ZodNull = "ZodNull",
+ ZodAny = "ZodAny",
+ ZodUnknown = "ZodUnknown",
+ ZodNever = "ZodNever",
+ ZodVoid = "ZodVoid",
+ ZodArray = "ZodArray",
+ ZodObject = "ZodObject",
+ ZodUnion = "ZodUnion",
+ ZodDiscriminatedUnion = "ZodDiscriminatedUnion",
+ ZodIntersection = "ZodIntersection",
+ ZodTuple = "ZodTuple",
+ ZodRecord = "ZodRecord",
+ ZodMap = "ZodMap",
+ ZodSet = "ZodSet",
+ ZodFunction = "ZodFunction",
+ ZodLazy = "ZodLazy",
+ ZodLiteral = "ZodLiteral",
+ ZodEnum = "ZodEnum",
+ ZodEffects = "ZodEffects",
+ ZodNativeEnum = "ZodNativeEnum",
+ ZodOptional = "ZodOptional",
+ ZodNullable = "ZodNullable",
+ ZodDefault = "ZodDefault",
+ ZodCatch = "ZodCatch",
+ ZodPromise = "ZodPromise",
+ ZodBranded = "ZodBranded",
+ ZodPipeline = "ZodPipeline",
+ ZodReadonly = "ZodReadonly"
+}
+export declare type ZodFirstPartySchemaTypes = ZodString | ZodNumber | ZodNaN | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid | ZodArray<any, any> | ZodObject<any, any, any> | ZodUnion<any> | ZodDiscriminatedUnion<any, any> | ZodIntersection<any, any> | ZodTuple<any, any> | ZodRecord<any, any> | ZodMap<any> | ZodSet<any> | ZodFunction<any, any> | ZodLazy<any> | ZodLiteral<any> | ZodEnum<any> | ZodEffects<any, any, any> | ZodNativeEnum<any> | ZodOptional<any> | ZodNullable<any> | ZodDefault<any> | ZodCatch<any> | ZodPromise<any> | ZodBranded<any, any> | ZodPipeline<any, any>;
+declare abstract class Class {
+ constructor(..._: any[]);
+}
+declare const instanceOfType: <T extends typeof Class>(cls: T, params?: CustomParams) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
+declare const stringType: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+} & {
+ coerce?: true | undefined;
+}) | undefined) => ZodString;
+declare const numberType: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+} & {
+ coerce?: boolean | undefined;
+}) | undefined) => ZodNumber;
+declare const nanType: (params?: RawCreateParams) => ZodNaN;
+declare const bigIntType: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+} & {
+ coerce?: boolean | undefined;
+}) | undefined) => ZodBigInt;
+declare const booleanType: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+} & {
+ coerce?: boolean | undefined;
+}) | undefined) => ZodBoolean;
+declare const dateType: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+} & {
+ coerce?: boolean | undefined;
+}) | undefined) => ZodDate;
+declare const symbolType: (params?: RawCreateParams) => ZodSymbol;
+declare const undefinedType: (params?: RawCreateParams) => ZodUndefined;
+declare const nullType: (params?: RawCreateParams) => ZodNull;
+declare const anyType: (params?: RawCreateParams) => ZodAny;
+declare const unknownType: (params?: RawCreateParams) => ZodUnknown;
+declare const neverType: (params?: RawCreateParams) => ZodNever;
+declare const voidType: (params?: RawCreateParams) => ZodVoid;
+declare const arrayType: <T extends ZodTypeAny>(schema: T, params?: RawCreateParams) => ZodArray<T, "many">;
+declare const objectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strip", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T>]: baseObjectInputType<T>[k_2]; }>;
+declare const strictObjectType: <T extends ZodRawShape>(shape: T, params?: RawCreateParams) => ZodObject<T, "strict", ZodTypeAny, { [k_1 in keyof objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>]: objectUtil.addQuestionMarks<baseObjectOutputType<T>, { [k in keyof baseObjectOutputType<T>]: undefined extends baseObjectOutputType<T>[k] ? never : k; }[keyof T]>[k_1]; }, { [k_2 in keyof baseObjectInputType<T>]: baseObjectInputType<T>[k_2]; }>;
+declare const unionType: <T extends readonly [ZodTypeAny, ZodTypeAny, ...ZodTypeAny[]]>(types: T, params?: RawCreateParams) => ZodUnion<T>;
+declare const discriminatedUnionType: typeof ZodDiscriminatedUnion.create;
+declare const intersectionType: <T extends ZodTypeAny, U extends ZodTypeAny>(left: T, right: U, params?: RawCreateParams) => ZodIntersection<T, U>;
+declare const tupleType: <T extends [] | [ZodTypeAny, ...ZodTypeAny[]]>(schemas: T, params?: RawCreateParams) => ZodTuple<T, null>;
+declare const recordType: typeof ZodRecord.create;
+declare const mapType: <Key extends ZodTypeAny = ZodTypeAny, Value extends ZodTypeAny = ZodTypeAny>(keyType: Key, valueType: Value, params?: RawCreateParams) => ZodMap<Key, Value>;
+declare const setType: <Value extends ZodTypeAny = ZodTypeAny>(valueType: Value, params?: RawCreateParams) => ZodSet<Value>;
+declare const functionType: typeof ZodFunction.create;
+declare const lazyType: <T extends ZodTypeAny>(getter: () => T, params?: RawCreateParams) => ZodLazy<T>;
+declare const literalType: <T extends Primitive>(value: T, params?: RawCreateParams) => ZodLiteral<T>;
+declare const enumType: typeof createZodEnum;
+declare const nativeEnumType: <T extends EnumLike>(values: T, params?: RawCreateParams) => ZodNativeEnum<T>;
+declare const promiseType: <T extends ZodTypeAny>(schema: T, params?: RawCreateParams) => ZodPromise<T>;
+declare const effectsType: <I extends ZodTypeAny>(schema: I, effect: Effect<I["_output"]>, params?: RawCreateParams) => ZodEffects<I, I["_output"], input<I>>;
+declare const optionalType: <T extends ZodTypeAny>(type: T, params?: RawCreateParams) => ZodOptional<T>;
+declare const nullableType: <T extends ZodTypeAny>(type: T, params?: RawCreateParams) => ZodNullable<T>;
+declare const preprocessType: <I extends ZodTypeAny>(preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
+declare const pipelineType: typeof ZodPipeline.create;
+declare const ostring: () => ZodOptional<ZodString>;
+declare const onumber: () => ZodOptional<ZodNumber>;
+declare const oboolean: () => ZodOptional<ZodBoolean>;
+export declare const coerce: {
+ string: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: true | undefined;
+ }) | undefined) => ZodString;
+ number: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodNumber;
+ boolean: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodBoolean;
+ bigint: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodBigInt;
+ date: (params?: ({
+ errorMap?: ZodErrorMap | undefined;
+ invalid_type_error?: string | undefined;
+ required_error?: string | undefined;
+ description?: string | undefined;
+ } & {
+ coerce?: boolean | undefined;
+ }) | undefined) => ZodDate;
+};
+export { anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, dateType as date, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, instanceOfType as instanceof, intersectionType as intersection, lazyType as lazy, literalType as literal, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, oboolean, onumber, optionalType as optional, ostring, pipelineType as pipeline, preprocessType as preprocess, promiseType as promise, recordType as record, setType as set, strictObjectType as strictObject, stringType as string, symbolType as symbol, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, };
+export declare const NEVER: never;
diff --git a/node_modules/zod/lib/types.js b/node_modules/zod/lib/types.js
new file mode 100644
index 0000000..cf197b3
--- /dev/null
+++ b/node_modules/zod/lib/types.js
@@ -0,0 +1,3288 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
+exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = void 0;
+const errors_1 = require("./errors");
+const errorUtil_1 = require("./helpers/errorUtil");
+const parseUtil_1 = require("./helpers/parseUtil");
+const util_1 = require("./helpers/util");
+const ZodError_1 = require("./ZodError");
+class ParseInputLazyPath {
+ constructor(parent, value, path, key) {
+ this._cachedPath = [];
+ this.parent = parent;
+ this.data = value;
+ this._path = path;
+ this._key = key;
+ }
+ get path() {
+ if (!this._cachedPath.length) {
+ if (this._key instanceof Array) {
+ this._cachedPath.push(...this._path, ...this._key);
+ }
+ else {
+ this._cachedPath.push(...this._path, this._key);
+ }
+ }
+ return this._cachedPath;
+ }
+}
+const handleResult = (ctx, result) => {
+ if ((0, parseUtil_1.isValid)(result)) {
+ return { success: true, data: result.value };
+ }
+ else {
+ if (!ctx.common.issues.length) {
+ throw new Error("Validation failed but no issues detected.");
+ }
+ return {
+ success: false,
+ get error() {
+ if (this._error)
+ return this._error;
+ const error = new ZodError_1.ZodError(ctx.common.issues);
+ this._error = error;
+ return this._error;
+ },
+ };
+ }
+};
+function processCreateParams(params) {
+ if (!params)
+ return {};
+ const { errorMap, invalid_type_error, required_error, description } = params;
+ if (errorMap && (invalid_type_error || required_error)) {
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
+ }
+ if (errorMap)
+ return { errorMap: errorMap, description };
+ const customMap = (iss, ctx) => {
+ if (iss.code !== "invalid_type")
+ return { message: ctx.defaultError };
+ if (typeof ctx.data === "undefined") {
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
+ }
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
+ };
+ return { errorMap: customMap, description };
+}
+class ZodType {
+ constructor(def) {
+ this.spa = this.safeParseAsync;
+ this._def = def;
+ this.parse = this.parse.bind(this);
+ this.safeParse = this.safeParse.bind(this);
+ this.parseAsync = this.parseAsync.bind(this);
+ this.safeParseAsync = this.safeParseAsync.bind(this);
+ this.spa = this.spa.bind(this);
+ this.refine = this.refine.bind(this);
+ this.refinement = this.refinement.bind(this);
+ this.superRefine = this.superRefine.bind(this);
+ this.optional = this.optional.bind(this);
+ this.nullable = this.nullable.bind(this);
+ this.nullish = this.nullish.bind(this);
+ this.array = this.array.bind(this);
+ this.promise = this.promise.bind(this);
+ this.or = this.or.bind(this);
+ this.and = this.and.bind(this);
+ this.transform = this.transform.bind(this);
+ this.brand = this.brand.bind(this);
+ this.default = this.default.bind(this);
+ this.catch = this.catch.bind(this);
+ this.describe = this.describe.bind(this);
+ this.pipe = this.pipe.bind(this);
+ this.readonly = this.readonly.bind(this);
+ this.isNullable = this.isNullable.bind(this);
+ this.isOptional = this.isOptional.bind(this);
+ }
+ get description() {
+ return this._def.description;
+ }
+ _getType(input) {
+ return (0, util_1.getParsedType)(input.data);
+ }
+ _getOrReturnCtx(input, ctx) {
+ return (ctx || {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: (0, util_1.getParsedType)(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ });
+ }
+ _processInputParams(input) {
+ return {
+ status: new parseUtil_1.ParseStatus(),
+ ctx: {
+ common: input.parent.common,
+ data: input.data,
+ parsedType: (0, util_1.getParsedType)(input.data),
+ schemaErrorMap: this._def.errorMap,
+ path: input.path,
+ parent: input.parent,
+ },
+ };
+ }
+ _parseSync(input) {
+ const result = this._parse(input);
+ if ((0, parseUtil_1.isAsync)(result)) {
+ throw new Error("Synchronous parse encountered promise.");
+ }
+ return result;
+ }
+ _parseAsync(input) {
+ const result = this._parse(input);
+ return Promise.resolve(result);
+ }
+ parse(data, params) {
+ const result = this.safeParse(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ safeParse(data, params) {
+ var _a;
+ const ctx = {
+ common: {
+ issues: [],
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: (0, util_1.getParsedType)(data),
+ };
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
+ return handleResult(ctx, result);
+ }
+ async parseAsync(data, params) {
+ const result = await this.safeParseAsync(data, params);
+ if (result.success)
+ return result.data;
+ throw result.error;
+ }
+ async safeParseAsync(data, params) {
+ const ctx = {
+ common: {
+ issues: [],
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
+ async: true,
+ },
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
+ schemaErrorMap: this._def.errorMap,
+ parent: null,
+ data,
+ parsedType: (0, util_1.getParsedType)(data),
+ };
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
+ const result = await ((0, parseUtil_1.isAsync)(maybeAsyncResult)
+ ? maybeAsyncResult
+ : Promise.resolve(maybeAsyncResult));
+ return handleResult(ctx, result);
+ }
+ refine(check, message) {
+ const getIssueProperties = (val) => {
+ if (typeof message === "string" || typeof message === "undefined") {
+ return { message };
+ }
+ else if (typeof message === "function") {
+ return message(val);
+ }
+ else {
+ return message;
+ }
+ };
+ return this._refinement((val, ctx) => {
+ const result = check(val);
+ const setError = () => ctx.addIssue({
+ code: ZodError_1.ZodIssueCode.custom,
+ ...getIssueProperties(val),
+ });
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
+ return result.then((data) => {
+ if (!data) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ if (!result) {
+ setError();
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ refinement(check, refinementData) {
+ return this._refinement((val, ctx) => {
+ if (!check(val)) {
+ ctx.addIssue(typeof refinementData === "function"
+ ? refinementData(val, ctx)
+ : refinementData);
+ return false;
+ }
+ else {
+ return true;
+ }
+ });
+ }
+ _refinement(refinement) {
+ return new ZodEffects({
+ schema: this,
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ effect: { type: "refinement", refinement },
+ });
+ }
+ superRefine(refinement) {
+ return this._refinement(refinement);
+ }
+ optional() {
+ return ZodOptional.create(this, this._def);
+ }
+ nullable() {
+ return ZodNullable.create(this, this._def);
+ }
+ nullish() {
+ return this.nullable().optional();
+ }
+ array() {
+ return ZodArray.create(this, this._def);
+ }
+ promise() {
+ return ZodPromise.create(this, this._def);
+ }
+ or(option) {
+ return ZodUnion.create([this, option], this._def);
+ }
+ and(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 },
+ });
+ }
+ default(def) {
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodDefault({
+ ...processCreateParams(this._def),
+ innerType: this,
+ defaultValue: defaultValueFunc,
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
+ });
+ }
+ brand() {
+ return new ZodBranded({
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
+ type: this,
+ ...processCreateParams(this._def),
+ });
+ }
+ catch(def) {
+ const catchValueFunc = typeof def === "function" ? def : () => def;
+ return new ZodCatch({
+ ...processCreateParams(this._def),
+ innerType: this,
+ catchValue: catchValueFunc,
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
+ });
+ }
+ describe(description) {
+ const This = this.constructor;
+ return new This({
+ ...this._def,
+ description,
+ });
+ }
+ pipe(target) {
+ return ZodPipeline.create(this, target);
+ }
+ readonly() {
+ return ZodReadonly.create(this);
+ }
+ isOptional() {
+ return this.safeParse(undefined).success;
+ }
+ isNullable() {
+ return this.safeParse(null).success;
+ }
+}
+exports.ZodType = ZodType;
+exports.Schema = ZodType;
+exports.ZodSchema = ZodType;
+const cuidRegex = /^c[^\s-]{8,}$/i;
+const cuid2Regex = /^[a-z][a-z0-9]*$/;
+const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
+const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
+const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
+const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
+const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
+const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
+const 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
+ }
+ }
+ 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)$`);
+ }
+ else {
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
+ }
+ }
+};
+function isValidIP(ip, version) {
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
+ return true;
+ }
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
+ return true;
+ }
+ return false;
+}
+class ZodString extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
+ validation,
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ this.nonempty = (message) => this.min(1, errorUtil_1.errorUtil.errToObj(message));
+ this.trim = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "trim" }],
+ });
+ this.toLowerCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
+ });
+ this.toUpperCase = () => new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
+ });
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = String(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.string) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.string,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const status = new parseUtil_1.ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.length < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.length > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "length") {
+ const tooBig = input.data.length > check.value;
+ const tooSmall = input.data.length < check.value;
+ if (tooBig || tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ if (tooBig) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ else if (tooSmall) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "string",
+ inclusive: true,
+ exact: true,
+ message: check.message,
+ });
+ }
+ status.dirty();
+ }
+ }
+ else if (check.kind === "email") {
+ if (!emailRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "email",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "emoji") {
+ if (!emojiRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "emoji",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "uuid") {
+ if (!uuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "uuid",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "cuid") {
+ if (!cuidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "cuid",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ 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 === "ulid") {
+ if (!ulidRegex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "ulid",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "url") {
+ try {
+ new URL(input.data);
+ }
+ catch (_a) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "url",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "regex") {
+ check.regex.lastIndex = 0;
+ const testResult = check.regex.test(input.data);
+ if (!testResult) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "regex",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "trim") {
+ input.data = input.data.trim();
+ }
+ else if (check.kind === "includes") {
+ if (!input.data.includes(check.value, check.position)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ validation: { includes: check.value, position: check.position },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "toLowerCase") {
+ input.data = input.data.toLowerCase();
+ }
+ else if (check.kind === "toUpperCase") {
+ input.data = input.data.toUpperCase();
+ }
+ else if (check.kind === "startsWith") {
+ if (!input.data.startsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ validation: { startsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "endsWith") {
+ if (!input.data.endsWith(check.value)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ validation: { endsWith: check.value },
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "datetime") {
+ const regex = datetimeRegex(check);
+ if (!regex.test(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ validation: "datetime",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "ip") {
+ if (!isValidIP(input.data, check.version)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ validation: "ip",
+ code: ZodError_1.ZodIssueCode.invalid_string,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util_1.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ _addCheck(check) {
+ return new ZodString({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ email(message) {
+ return this._addCheck({ kind: "email", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ url(message) {
+ return this._addCheck({ kind: "url", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ emoji(message) {
+ return this._addCheck({ kind: "emoji", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ uuid(message) {
+ return this._addCheck({ kind: "uuid", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ cuid(message) {
+ return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ cuid2(message) {
+ return this._addCheck({ kind: "cuid2", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ ulid(message) {
+ return this._addCheck({ kind: "ulid", ...errorUtil_1.errorUtil.errToObj(message) });
+ }
+ ip(options) {
+ return this._addCheck({ kind: "ip", ...errorUtil_1.errorUtil.errToObj(options) });
+ }
+ datetime(options) {
+ var _a;
+ if (typeof options === "string") {
+ return this._addCheck({
+ kind: "datetime",
+ precision: null,
+ offset: false,
+ message: options,
+ });
+ }
+ return this._addCheck({
+ kind: "datetime",
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
+ ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ regex(regex, message) {
+ return this._addCheck({
+ kind: "regex",
+ regex: regex,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ includes(value, options) {
+ return this._addCheck({
+ kind: "includes",
+ value: value,
+ position: options === null || options === void 0 ? void 0 : options.position,
+ ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
+ });
+ }
+ startsWith(value, message) {
+ return this._addCheck({
+ kind: "startsWith",
+ value: value,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ endsWith(value, message) {
+ return this._addCheck({
+ kind: "endsWith",
+ value: value,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ min(minLength, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minLength,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ max(maxLength, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxLength,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ length(len, message) {
+ return this._addCheck({
+ kind: "length",
+ value: len,
+ ...errorUtil_1.errorUtil.errToObj(message),
+ });
+ }
+ get isDatetime() {
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
+ }
+ get isEmail() {
+ return !!this._def.checks.find((ch) => ch.kind === "email");
+ }
+ get isURL() {
+ return !!this._def.checks.find((ch) => ch.kind === "url");
+ }
+ get isEmoji() {
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
+ }
+ get isUUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
+ }
+ get isCUID() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
+ }
+ get isCUID2() {
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
+ }
+ get isULID() {
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
+ }
+ get isIP() {
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
+ }
+ get minLength() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxLength() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+}
+exports.ZodString = ZodString;
+ZodString.create = (params) => {
+ var _a;
+ return new ZodString({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodString,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+};
+function floatSafeRemainder(val, step) {
+ const valDecCount = (val.toString().split(".")[1] || "").length;
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
+ return (valInt % stepInt) / Math.pow(10, decCount);
+}
+class ZodNumber extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ this.step = this.multipleOf;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Number(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.number) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.number,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ let ctx = undefined;
+ const status = new parseUtil_1.ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "int") {
+ if (!util_1.util.isInteger(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: "integer",
+ received: "float",
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: check.value,
+ type: "number",
+ inclusive: check.inclusive,
+ exact: false,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "finite") {
+ if (!Number.isFinite(input.data)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.not_finite,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util_1.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil_1.errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodNumber({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ int(message) {
+ return this._addCheck({
+ kind: "int",
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: false,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: false,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: 0,
+ inclusive: true,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: 0,
+ inclusive: true,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value: value,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ finite(message) {
+ return this._addCheck({
+ kind: "finite",
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ safe(message) {
+ return this._addCheck({
+ kind: "min",
+ inclusive: true,
+ value: Number.MIN_SAFE_INTEGER,
+ message: errorUtil_1.errorUtil.toString(message),
+ })._addCheck({
+ kind: "max",
+ inclusive: true,
+ value: Number.MAX_SAFE_INTEGER,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+ get isInt() {
+ 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;
+ZodNumber.create = (params) => {
+ return new ZodNumber({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+};
+class ZodBigInt extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.min = this.gte;
+ this.max = this.lte;
+ }
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = BigInt(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.bigint) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.bigint,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ let ctx = undefined;
+ const status = new parseUtil_1.ParseStatus();
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ const tooSmall = check.inclusive
+ ? input.data < check.value
+ : input.data <= check.value;
+ if (tooSmall) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ type: "bigint",
+ minimum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ const tooBig = check.inclusive
+ ? input.data > check.value
+ : input.data >= check.value;
+ if (tooBig) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ type: "bigint",
+ maximum: check.value,
+ inclusive: check.inclusive,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "multipleOf") {
+ if (input.data % check.value !== BigInt(0)) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.not_multiple_of,
+ multipleOf: check.value,
+ message: check.message,
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util_1.util.assertNever(check);
+ }
+ }
+ return { status: status.value, value: input.data };
+ }
+ gte(value, message) {
+ return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
+ }
+ gt(value, message) {
+ return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
+ }
+ lte(value, message) {
+ return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
+ }
+ lt(value, message) {
+ return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
+ }
+ setLimit(kind, value, inclusive, message) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [
+ ...this._def.checks,
+ {
+ kind,
+ value,
+ inclusive,
+ message: errorUtil_1.errorUtil.toString(message),
+ },
+ ],
+ });
+ }
+ _addCheck(check) {
+ return new ZodBigInt({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ positive(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ negative(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: false,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ nonpositive(message) {
+ return this._addCheck({
+ kind: "max",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ nonnegative(message) {
+ return this._addCheck({
+ kind: "min",
+ value: BigInt(0),
+ inclusive: true,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ multipleOf(value, message) {
+ return this._addCheck({
+ kind: "multipleOf",
+ value,
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ get minValue() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min;
+ }
+ get maxValue() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max;
+ }
+}
+exports.ZodBigInt = ZodBigInt;
+ZodBigInt.create = (params) => {
+ var _a;
+ return new ZodBigInt({
+ checks: [],
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
+ ...processCreateParams(params),
+ });
+};
+class ZodBoolean extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = Boolean(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.boolean) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.boolean,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodBoolean = ZodBoolean;
+ZodBoolean.create = (params) => {
+ return new ZodBoolean({
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ ...processCreateParams(params),
+ });
+};
+class ZodDate extends ZodType {
+ _parse(input) {
+ if (this._def.coerce) {
+ input.data = new Date(input.data);
+ }
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.date) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.date,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (isNaN(input.data.getTime())) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_date,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const status = new parseUtil_1.ParseStatus();
+ let ctx = undefined;
+ for (const check of this._def.checks) {
+ if (check.kind === "min") {
+ if (input.data.getTime() < check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ minimum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else if (check.kind === "max") {
+ if (input.data.getTime() > check.value) {
+ ctx = this._getOrReturnCtx(input, ctx);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ message: check.message,
+ inclusive: true,
+ exact: false,
+ maximum: check.value,
+ type: "date",
+ });
+ status.dirty();
+ }
+ }
+ else {
+ util_1.util.assertNever(check);
+ }
+ }
+ return {
+ status: status.value,
+ value: new Date(input.data.getTime()),
+ };
+ }
+ _addCheck(check) {
+ return new ZodDate({
+ ...this._def,
+ checks: [...this._def.checks, check],
+ });
+ }
+ min(minDate, message) {
+ return this._addCheck({
+ kind: "min",
+ value: minDate.getTime(),
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ max(maxDate, message) {
+ return this._addCheck({
+ kind: "max",
+ value: maxDate.getTime(),
+ message: errorUtil_1.errorUtil.toString(message),
+ });
+ }
+ get minDate() {
+ let min = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "min") {
+ if (min === null || ch.value > min)
+ min = ch.value;
+ }
+ }
+ return min != null ? new Date(min) : null;
+ }
+ get maxDate() {
+ let max = null;
+ for (const ch of this._def.checks) {
+ if (ch.kind === "max") {
+ if (max === null || ch.value < max)
+ max = ch.value;
+ }
+ }
+ return max != null ? new Date(max) : null;
+ }
+}
+exports.ZodDate = ZodDate;
+ZodDate.create = (params) => {
+ return new ZodDate({
+ checks: [],
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
+ typeName: ZodFirstPartyTypeKind.ZodDate,
+ ...processCreateParams(params),
+ });
+};
+class ZodSymbol extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.symbol) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.symbol,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodSymbol = ZodSymbol;
+ZodSymbol.create = (params) => {
+ return new ZodSymbol({
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
+ ...processCreateParams(params),
+ });
+};
+class ZodUndefined extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.undefined,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodUndefined = ZodUndefined;
+ZodUndefined.create = (params) => {
+ return new ZodUndefined({
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
+ ...processCreateParams(params),
+ });
+};
+class ZodNull extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.null) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.null,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodNull = ZodNull;
+ZodNull.create = (params) => {
+ return new ZodNull({
+ typeName: ZodFirstPartyTypeKind.ZodNull,
+ ...processCreateParams(params),
+ });
+};
+class ZodAny extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._any = true;
+ }
+ _parse(input) {
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodAny = ZodAny;
+ZodAny.create = (params) => {
+ return new ZodAny({
+ typeName: ZodFirstPartyTypeKind.ZodAny,
+ ...processCreateParams(params),
+ });
+};
+class ZodUnknown extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._unknown = true;
+ }
+ _parse(input) {
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodUnknown = ZodUnknown;
+ZodUnknown.create = (params) => {
+ return new ZodUnknown({
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
+ ...processCreateParams(params),
+ });
+};
+class ZodNever extends ZodType {
+ _parse(input) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.never,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+}
+exports.ZodNever = ZodNever;
+ZodNever.create = (params) => {
+ return new ZodNever({
+ typeName: ZodFirstPartyTypeKind.ZodNever,
+ ...processCreateParams(params),
+ });
+};
+class ZodVoid extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.undefined) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.void,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+}
+exports.ZodVoid = ZodVoid;
+ZodVoid.create = (params) => {
+ return new ZodVoid({
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
+ ...processCreateParams(params),
+ });
+};
+class ZodArray extends ZodType {
+ _parse(input) {
+ const { ctx, status } = this._processInputParams(input);
+ const def = this._def;
+ if (ctx.parsedType !== util_1.ZodParsedType.array) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (def.exactLength !== null) {
+ const tooBig = ctx.data.length > def.exactLength.value;
+ const tooSmall = ctx.data.length < def.exactLength.value;
+ if (tooBig || tooSmall) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: tooBig ? ZodError_1.ZodIssueCode.too_big : ZodError_1.ZodIssueCode.too_small,
+ minimum: (tooSmall ? def.exactLength.value : undefined),
+ maximum: (tooBig ? def.exactLength.value : undefined),
+ type: "array",
+ inclusive: true,
+ exact: true,
+ message: def.exactLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.minLength !== null) {
+ if (ctx.data.length < def.minLength.value) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: def.minLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.minLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxLength !== null) {
+ if (ctx.data.length > def.maxLength.value) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: def.maxLength.value,
+ type: "array",
+ inclusive: true,
+ exact: false,
+ message: def.maxLength.message,
+ });
+ status.dirty();
+ }
+ }
+ if (ctx.common.async) {
+ 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) => {
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
+ });
+ return parseUtil_1.ParseStatus.mergeArray(status, result);
+ }
+ get element() {
+ return this._def.type;
+ }
+ min(minLength, message) {
+ return new ZodArray({
+ ...this._def,
+ minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) },
+ });
+ }
+ max(maxLength, message) {
+ return new ZodArray({
+ ...this._def,
+ maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) },
+ });
+ }
+ length(len, message) {
+ return new ZodArray({
+ ...this._def,
+ exactLength: { value: len, message: errorUtil_1.errorUtil.toString(message) },
+ });
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+}
+exports.ZodArray = ZodArray;
+ZodArray.create = (schema, params) => {
+ return new ZodArray({
+ type: schema,
+ minLength: null,
+ maxLength: null,
+ exactLength: null,
+ typeName: ZodFirstPartyTypeKind.ZodArray,
+ ...processCreateParams(params),
+ });
+};
+function deepPartialify(schema) {
+ if (schema instanceof ZodObject) {
+ const newShape = {};
+ for (const key in schema.shape) {
+ const fieldSchema = schema.shape[key];
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
+ }
+ return new ZodObject({
+ ...schema._def,
+ shape: () => newShape,
+ });
+ }
+ else if (schema instanceof ZodArray) {
+ return new ZodArray({
+ ...schema._def,
+ type: deepPartialify(schema.element),
+ });
+ }
+ else if (schema instanceof ZodOptional) {
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodNullable) {
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
+ }
+ else if (schema instanceof ZodTuple) {
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
+ }
+ else {
+ return schema;
+ }
+}
+class ZodObject extends ZodType {
+ constructor() {
+ super(...arguments);
+ this._cached = null;
+ this.nonstrict = this.passthrough;
+ this.augment = this.extend;
+ }
+ _getCached() {
+ if (this._cached !== null)
+ return this._cached;
+ const shape = this._def.shape();
+ const keys = util_1.util.objectKeys(shape);
+ return (this._cached = { shape, keys });
+ }
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.object) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const { status, ctx } = this._processInputParams(input);
+ const { shape, keys: shapeKeys } = this._getCached();
+ const extraKeys = [];
+ if (!(this._def.catchall instanceof ZodNever &&
+ this._def.unknownKeys === "strip")) {
+ for (const key in ctx.data) {
+ if (!shapeKeys.includes(key)) {
+ extraKeys.push(key);
+ }
+ }
+ }
+ const pairs = [];
+ for (const key of shapeKeys) {
+ const keyValidator = shape[key];
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ if (this._def.catchall instanceof ZodNever) {
+ const unknownKeys = this._def.unknownKeys;
+ if (unknownKeys === "passthrough") {
+ for (const key of extraKeys) {
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: { status: "valid", value: ctx.data[key] },
+ });
+ }
+ }
+ else if (unknownKeys === "strict") {
+ if (extraKeys.length > 0) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.unrecognized_keys,
+ keys: extraKeys,
+ });
+ status.dirty();
+ }
+ }
+ else if (unknownKeys === "strip") {
+ }
+ else {
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
+ }
+ }
+ else {
+ const catchall = this._def.catchall;
+ for (const key of extraKeys) {
+ const value = ctx.data[key];
+ pairs.push({
+ key: { status: "valid", value: key },
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
+ alwaysSet: key in ctx.data,
+ });
+ }
+ }
+ if (ctx.common.async) {
+ return Promise.resolve()
+ .then(async () => {
+ const syncPairs = [];
+ for (const pair of pairs) {
+ const key = await pair.key;
+ syncPairs.push({
+ key,
+ value: await pair.value,
+ alwaysSet: pair.alwaysSet,
+ });
+ }
+ return syncPairs;
+ })
+ .then((syncPairs) => {
+ return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
+ });
+ }
+ else {
+ return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get shape() {
+ return this._def.shape();
+ }
+ strict(message) {
+ errorUtil_1.errorUtil.errToObj;
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strict",
+ ...(message !== undefined
+ ? {
+ errorMap: (issue, ctx) => {
+ var _a, _b, _c, _d;
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
+ if (issue.code === "unrecognized_keys")
+ return {
+ message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
+ };
+ return {
+ message: defaultError,
+ };
+ },
+ }
+ : {}),
+ });
+ }
+ strip() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "strip",
+ });
+ }
+ passthrough() {
+ return new ZodObject({
+ ...this._def,
+ unknownKeys: "passthrough",
+ });
+ }
+ extend(augmentation) {
+ return new ZodObject({
+ ...this._def,
+ shape: () => ({
+ ...this._def.shape(),
+ ...augmentation,
+ }),
+ });
+ }
+ merge(merging) {
+ const merged = new ZodObject({
+ unknownKeys: merging._def.unknownKeys,
+ catchall: merging._def.catchall,
+ shape: () => ({
+ ...this._def.shape(),
+ ...merging._def.shape(),
+ }),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ });
+ return merged;
+ }
+ setKey(key, schema) {
+ return this.augment({ [key]: schema });
+ }
+ catchall(index) {
+ return new ZodObject({
+ ...this._def,
+ catchall: index,
+ });
+ }
+ pick(mask) {
+ const shape = {};
+ util_1.util.objectKeys(mask).forEach((key) => {
+ if (mask[key] && this.shape[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ omit(mask) {
+ const shape = {};
+ util_1.util.objectKeys(this.shape).forEach((key) => {
+ if (!mask[key]) {
+ shape[key] = this.shape[key];
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => shape,
+ });
+ }
+ deepPartial() {
+ return deepPartialify(this);
+ }
+ partial(mask) {
+ const newShape = {};
+ 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,
+ });
+ }
+ required(mask) {
+ const newShape = {};
+ 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) {
+ newField = newField._def.innerType;
+ }
+ newShape[key] = newField;
+ }
+ });
+ return new ZodObject({
+ ...this._def,
+ shape: () => newShape,
+ });
+ }
+ keyof() {
+ return createZodEnum(util_1.util.objectKeys(this.shape));
+ }
+}
+exports.ZodObject = ZodObject;
+ZodObject.create = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+ZodObject.strictCreate = (shape, params) => {
+ return new ZodObject({
+ shape: () => shape,
+ unknownKeys: "strict",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+ZodObject.lazycreate = (shape, params) => {
+ return new ZodObject({
+ shape,
+ unknownKeys: "strip",
+ catchall: ZodNever.create(),
+ typeName: ZodFirstPartyTypeKind.ZodObject,
+ ...processCreateParams(params),
+ });
+};
+class ZodUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const options = this._def.options;
+ function handleResults(results) {
+ for (const result of results) {
+ if (result.result.status === "valid") {
+ return result.result;
+ }
+ }
+ for (const result of results) {
+ if (result.result.status === "dirty") {
+ ctx.common.issues.push(...result.ctx.common.issues);
+ return result.result;
+ }
+ }
+ const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (ctx.common.async) {
+ return Promise.all(options.map(async (option) => {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ return {
+ result: await option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ }),
+ ctx: childCtx,
+ };
+ })).then(handleResults);
+ }
+ else {
+ let dirty = undefined;
+ const issues = [];
+ for (const option of options) {
+ const childCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ parent: null,
+ };
+ const result = option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: childCtx,
+ });
+ if (result.status === "valid") {
+ return result;
+ }
+ else if (result.status === "dirty" && !dirty) {
+ dirty = { result, ctx: childCtx };
+ }
+ if (childCtx.common.issues.length) {
+ issues.push(childCtx.common.issues);
+ }
+ }
+ if (dirty) {
+ ctx.common.issues.push(...dirty.ctx.common.issues);
+ return dirty.result;
+ }
+ const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_union,
+ unionErrors,
+ });
+ return parseUtil_1.INVALID;
+ }
+ }
+ get options() {
+ return this._def.options;
+ }
+}
+exports.ZodUnion = ZodUnion;
+ZodUnion.create = (types, params) => {
+ return new ZodUnion({
+ options: types,
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
+ ...processCreateParams(params),
+ });
+};
+const getDiscriminator = (type) => {
+ if (type instanceof ZodLazy) {
+ return getDiscriminator(type.schema);
+ }
+ else if (type instanceof ZodEffects) {
+ return getDiscriminator(type.innerType());
+ }
+ else if (type instanceof ZodLiteral) {
+ return [type.value];
+ }
+ else if (type instanceof ZodEnum) {
+ return type.options;
+ }
+ else if (type instanceof ZodNativeEnum) {
+ return Object.keys(type.enum);
+ }
+ else if (type instanceof ZodDefault) {
+ return getDiscriminator(type._def.innerType);
+ }
+ else if (type instanceof ZodUndefined) {
+ return [undefined];
+ }
+ else if (type instanceof ZodNull) {
+ return [null];
+ }
+ else {
+ return null;
+ }
+};
+class ZodDiscriminatedUnion extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.object) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const discriminator = this.discriminator;
+ const discriminatorValue = ctx.data[discriminator];
+ const option = this.optionsMap.get(discriminatorValue);
+ if (!option) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
+ options: Array.from(this.optionsMap.keys()),
+ path: [discriminator],
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (ctx.common.async) {
+ return option._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ else {
+ return option._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ get discriminator() {
+ return this._def.discriminator;
+ }
+ get options() {
+ return this._def.options;
+ }
+ get optionsMap() {
+ return this._def.optionsMap;
+ }
+ static create(discriminator, options, params) {
+ const optionsMap = new Map();
+ for (const type of options) {
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
+ if (!discriminatorValues) {
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
+ }
+ for (const value of discriminatorValues) {
+ if (optionsMap.has(value)) {
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
+ }
+ optionsMap.set(value, type);
+ }
+ }
+ return new ZodDiscriminatedUnion({
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
+ discriminator,
+ options,
+ optionsMap,
+ ...processCreateParams(params),
+ });
+ }
+}
+exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
+function mergeValues(a, b) {
+ const aType = (0, util_1.getParsedType)(a);
+ const bType = (0, util_1.getParsedType)(b);
+ if (a === b) {
+ return { valid: true, data: a };
+ }
+ else if (aType === util_1.ZodParsedType.object && bType === util_1.ZodParsedType.object) {
+ const bKeys = util_1.util.objectKeys(b);
+ const sharedKeys = util_1.util
+ .objectKeys(a)
+ .filter((key) => bKeys.indexOf(key) !== -1);
+ const newObj = { ...a, ...b };
+ for (const key of sharedKeys) {
+ const sharedValue = mergeValues(a[key], b[key]);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newObj[key] = sharedValue.data;
+ }
+ return { valid: true, data: newObj };
+ }
+ else if (aType === util_1.ZodParsedType.array && bType === util_1.ZodParsedType.array) {
+ if (a.length !== b.length) {
+ return { valid: false };
+ }
+ const newArray = [];
+ for (let index = 0; index < a.length; index++) {
+ const itemA = a[index];
+ const itemB = b[index];
+ const sharedValue = mergeValues(itemA, itemB);
+ if (!sharedValue.valid) {
+ return { valid: false };
+ }
+ newArray.push(sharedValue.data);
+ }
+ return { valid: true, data: newArray };
+ }
+ else if (aType === util_1.ZodParsedType.date &&
+ bType === util_1.ZodParsedType.date &&
+ +a === +b) {
+ return { valid: true, data: a };
+ }
+ else {
+ return { valid: false };
+ }
+}
+class ZodIntersection extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const handleParsed = (parsedLeft, parsedRight) => {
+ if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
+ return parseUtil_1.INVALID;
+ }
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
+ if (!merged.valid) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_intersection_types,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if ((0, parseUtil_1.isDirty)(parsedLeft) || (0, parseUtil_1.isDirty)(parsedRight)) {
+ status.dirty();
+ }
+ return { status: status.value, value: merged.data };
+ };
+ if (ctx.common.async) {
+ return Promise.all([
+ this._def.left._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ this._def.right._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }),
+ ]).then(([left, right]) => handleParsed(left, right));
+ }
+ else {
+ return handleParsed(this._def.left._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }), this._def.right._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ }));
+ }
+ }
+}
+exports.ZodIntersection = ZodIntersection;
+ZodIntersection.create = (left, right, params) => {
+ return new ZodIntersection({
+ left: left,
+ right: right,
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
+ ...processCreateParams(params),
+ });
+};
+class ZodTuple extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.array) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.array,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (ctx.data.length < this._def.items.length) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ return parseUtil_1.INVALID;
+ }
+ const rest = this._def.rest;
+ if (!rest && ctx.data.length > this._def.items.length) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: this._def.items.length,
+ inclusive: true,
+ exact: false,
+ type: "array",
+ });
+ status.dirty();
+ }
+ const items = [...ctx.data]
+ .map((item, itemIndex) => {
+ const schema = this._def.items[itemIndex] || this._def.rest;
+ if (!schema)
+ return null;
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
+ })
+ .filter((x) => !!x);
+ if (ctx.common.async) {
+ return Promise.all(items).then((results) => {
+ return parseUtil_1.ParseStatus.mergeArray(status, results);
+ });
+ }
+ else {
+ return parseUtil_1.ParseStatus.mergeArray(status, items);
+ }
+ }
+ get items() {
+ return this._def.items;
+ }
+ rest(rest) {
+ return new ZodTuple({
+ ...this._def,
+ rest,
+ });
+ }
+}
+exports.ZodTuple = ZodTuple;
+ZodTuple.create = (schemas, params) => {
+ if (!Array.isArray(schemas)) {
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
+ }
+ return new ZodTuple({
+ items: schemas,
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
+ rest: null,
+ ...processCreateParams(params),
+ });
+};
+class ZodRecord extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.object) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.object,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const pairs = [];
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ for (const key in ctx.data) {
+ pairs.push({
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
+ });
+ }
+ if (ctx.common.async) {
+ return parseUtil_1.ParseStatus.mergeObjectAsync(status, pairs);
+ }
+ else {
+ return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
+ }
+ }
+ get element() {
+ return this._def.valueType;
+ }
+ static create(first, second, third) {
+ if (second instanceof ZodType) {
+ return new ZodRecord({
+ keyType: first,
+ valueType: second,
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(third),
+ });
+ }
+ return new ZodRecord({
+ keyType: ZodString.create(),
+ valueType: first,
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
+ ...processCreateParams(second),
+ });
+ }
+}
+exports.ZodRecord = ZodRecord;
+class ZodMap extends ZodType {
+ get keySchema() {
+ return this._def.keyType;
+ }
+ get valueSchema() {
+ return this._def.valueType;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.map) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.map,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const keyType = this._def.keyType;
+ const valueType = this._def.valueType;
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
+ return {
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
+ };
+ });
+ if (ctx.common.async) {
+ const finalMap = new Map();
+ return Promise.resolve().then(async () => {
+ for (const pair of pairs) {
+ const key = await pair.key;
+ const value = await pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return parseUtil_1.INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ });
+ }
+ else {
+ const finalMap = new Map();
+ for (const pair of pairs) {
+ const key = pair.key;
+ const value = pair.value;
+ if (key.status === "aborted" || value.status === "aborted") {
+ return parseUtil_1.INVALID;
+ }
+ if (key.status === "dirty" || value.status === "dirty") {
+ status.dirty();
+ }
+ finalMap.set(key.value, value.value);
+ }
+ return { status: status.value, value: finalMap };
+ }
+ }
+}
+exports.ZodMap = ZodMap;
+ZodMap.create = (keyType, valueType, params) => {
+ return new ZodMap({
+ valueType,
+ keyType,
+ typeName: ZodFirstPartyTypeKind.ZodMap,
+ ...processCreateParams(params),
+ });
+};
+class ZodSet extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.set) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.set,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const def = this._def;
+ if (def.minSize !== null) {
+ if (ctx.data.size < def.minSize.value) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_small,
+ minimum: def.minSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.minSize.message,
+ });
+ status.dirty();
+ }
+ }
+ if (def.maxSize !== null) {
+ if (ctx.data.size > def.maxSize.value) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.too_big,
+ maximum: def.maxSize.value,
+ type: "set",
+ inclusive: true,
+ exact: false,
+ message: def.maxSize.message,
+ });
+ status.dirty();
+ }
+ }
+ const valueType = this._def.valueType;
+ function finalizeSet(elements) {
+ const parsedSet = new Set();
+ for (const element of elements) {
+ if (element.status === "aborted")
+ return parseUtil_1.INVALID;
+ if (element.status === "dirty")
+ status.dirty();
+ parsedSet.add(element.value);
+ }
+ return { status: status.value, value: parsedSet };
+ }
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
+ if (ctx.common.async) {
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
+ }
+ else {
+ return finalizeSet(elements);
+ }
+ }
+ min(minSize, message) {
+ return new ZodSet({
+ ...this._def,
+ minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) },
+ });
+ }
+ max(maxSize, message) {
+ return new ZodSet({
+ ...this._def,
+ maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) },
+ });
+ }
+ size(size, message) {
+ return this.min(size, message).max(size, message);
+ }
+ nonempty(message) {
+ return this.min(1, message);
+ }
+}
+exports.ZodSet = ZodSet;
+ZodSet.create = (valueType, params) => {
+ return new ZodSet({
+ valueType,
+ minSize: null,
+ maxSize: null,
+ typeName: ZodFirstPartyTypeKind.ZodSet,
+ ...processCreateParams(params),
+ });
+};
+class ZodFunction extends ZodType {
+ constructor() {
+ super(...arguments);
+ this.validate = this.implement;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.function) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.function,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ function makeArgsIssue(args, error) {
+ return (0, parseUtil_1.makeIssue)({
+ data: args,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ (0, errors_1.getErrorMap)(),
+ errors_1.defaultErrorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodError_1.ZodIssueCode.invalid_arguments,
+ argumentsError: error,
+ },
+ });
+ }
+ function makeReturnsIssue(returns, error) {
+ return (0, parseUtil_1.makeIssue)({
+ data: returns,
+ path: ctx.path,
+ errorMaps: [
+ ctx.common.contextualErrorMap,
+ ctx.schemaErrorMap,
+ (0, errors_1.getErrorMap)(),
+ errors_1.defaultErrorMap,
+ ].filter((x) => !!x),
+ issueData: {
+ code: ZodError_1.ZodIssueCode.invalid_return_type,
+ returnTypeError: error,
+ },
+ });
+ }
+ const params = { errorMap: ctx.common.contextualErrorMap };
+ const fn = ctx.data;
+ if (this._def.returns instanceof ZodPromise) {
+ const me = this;
+ return (0, parseUtil_1.OK)(async function (...args) {
+ const error = new ZodError_1.ZodError([]);
+ const parsedArgs = await me._def.args
+ .parseAsync(args, params)
+ .catch((e) => {
+ error.addIssue(makeArgsIssue(args, e));
+ throw error;
+ });
+ const result = await Reflect.apply(fn, this, parsedArgs);
+ const parsedReturns = await me._def.returns._def.type
+ .parseAsync(result, params)
+ .catch((e) => {
+ error.addIssue(makeReturnsIssue(result, e));
+ throw error;
+ });
+ return parsedReturns;
+ });
+ }
+ else {
+ const me = this;
+ return (0, parseUtil_1.OK)(function (...args) {
+ const parsedArgs = me._def.args.safeParse(args, params);
+ if (!parsedArgs.success) {
+ throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
+ }
+ const result = Reflect.apply(fn, this, parsedArgs.data);
+ const parsedReturns = me._def.returns.safeParse(result, params);
+ if (!parsedReturns.success) {
+ throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
+ }
+ return parsedReturns.data;
+ });
+ }
+ }
+ parameters() {
+ return this._def.args;
+ }
+ returnType() {
+ return this._def.returns;
+ }
+ args(...items) {
+ return new ZodFunction({
+ ...this._def,
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
+ });
+ }
+ returns(returnType) {
+ return new ZodFunction({
+ ...this._def,
+ returns: returnType,
+ });
+ }
+ implement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ strictImplement(func) {
+ const validatedFunc = this.parse(func);
+ return validatedFunc;
+ }
+ static create(args, returns, params) {
+ return new ZodFunction({
+ args: (args
+ ? args
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
+ returns: returns || ZodUnknown.create(),
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
+ ...processCreateParams(params),
+ });
+ }
+}
+exports.ZodFunction = ZodFunction;
+class ZodLazy extends ZodType {
+ get schema() {
+ return this._def.getter();
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const lazySchema = this._def.getter();
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
+ }
+}
+exports.ZodLazy = ZodLazy;
+ZodLazy.create = (getter, params) => {
+ return new ZodLazy({
+ getter: getter,
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
+ ...processCreateParams(params),
+ });
+};
+class ZodLiteral extends ZodType {
+ _parse(input) {
+ 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,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+ get value() {
+ return this._def.value;
+ }
+}
+exports.ZodLiteral = ZodLiteral;
+ZodLiteral.create = (value, params) => {
+ return new ZodLiteral({
+ value: value,
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
+ ...processCreateParams(params),
+ });
+};
+function createZodEnum(values, params) {
+ return new ZodEnum({
+ values,
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
+ ...processCreateParams(params),
+ });
+}
+class ZodEnum extends ZodType {
+ _parse(input) {
+ if (typeof input.data !== "string") {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ expected: util_1.util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (this._def.values.indexOf(input.data) === -1) {
+ const ctx = this._getOrReturnCtx(input);
+ const expectedValues = this._def.values;
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ received: ctx.data,
+ code: ZodError_1.ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+ get options() {
+ return this._def.values;
+ }
+ get enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Values() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ return enumValues;
+ }
+ get Enum() {
+ const enumValues = {};
+ for (const val of this._def.values) {
+ enumValues[val] = val;
+ }
+ 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;
+class ZodNativeEnum extends ZodType {
+ _parse(input) {
+ const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
+ const ctx = this._getOrReturnCtx(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.string &&
+ ctx.parsedType !== util_1.ZodParsedType.number) {
+ const expectedValues = util_1.util.objectValues(nativeEnumValues);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ expected: util_1.util.joinValues(expectedValues),
+ received: ctx.parsedType,
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ });
+ return parseUtil_1.INVALID;
+ }
+ if (nativeEnumValues.indexOf(input.data) === -1) {
+ const expectedValues = util_1.util.objectValues(nativeEnumValues);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ received: ctx.data,
+ code: ZodError_1.ZodIssueCode.invalid_enum_value,
+ options: expectedValues,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return (0, parseUtil_1.OK)(input.data);
+ }
+ get enum() {
+ return this._def.values;
+ }
+}
+exports.ZodNativeEnum = ZodNativeEnum;
+ZodNativeEnum.create = (values, params) => {
+ return new ZodNativeEnum({
+ values: values,
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
+ ...processCreateParams(params),
+ });
+};
+class ZodPromise extends ZodType {
+ unwrap() {
+ return this._def.type;
+ }
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ if (ctx.parsedType !== util_1.ZodParsedType.promise &&
+ ctx.common.async === false) {
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.promise,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ const promisified = ctx.parsedType === util_1.ZodParsedType.promise
+ ? ctx.data
+ : Promise.resolve(ctx.data);
+ return (0, parseUtil_1.OK)(promisified.then((data) => {
+ return this._def.type.parseAsync(data, {
+ path: ctx.path,
+ errorMap: ctx.common.contextualErrorMap,
+ });
+ }));
+ }
+}
+exports.ZodPromise = ZodPromise;
+ZodPromise.create = (schema, params) => {
+ return new ZodPromise({
+ type: schema,
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
+ ...processCreateParams(params),
+ });
+};
+class ZodEffects extends ZodType {
+ innerType() {
+ return this._def.schema;
+ }
+ sourceType() {
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
+ ? this._def.schema.sourceType()
+ : this._def.schema;
+ }
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ const effect = this._def.effect || null;
+ const checkCtx = {
+ addIssue: (arg) => {
+ (0, parseUtil_1.addIssueToContext)(ctx, arg);
+ if (arg.fatal) {
+ status.abort();
+ }
+ else {
+ status.dirty();
+ }
+ },
+ get path() {
+ return ctx.path;
+ },
+ };
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
+ if (effect.type === "preprocess") {
+ const processed = effect.transform(ctx.data, checkCtx);
+ if (ctx.common.issues.length) {
+ return {
+ status: "dirty",
+ value: ctx.data,
+ };
+ }
+ if (ctx.common.async) {
+ return Promise.resolve(processed).then((processed) => {
+ return this._def.schema._parseAsync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ });
+ }
+ else {
+ return this._def.schema._parseSync({
+ data: processed,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ if (effect.type === "refinement") {
+ const executeRefinement = (acc) => {
+ const result = effect.refinement(acc, checkCtx);
+ if (ctx.common.async) {
+ return Promise.resolve(result);
+ }
+ if (result instanceof Promise) {
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
+ }
+ return acc;
+ };
+ if (ctx.common.async === false) {
+ const inner = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inner.status === "aborted")
+ return parseUtil_1.INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ executeRefinement(inner.value);
+ return { status: status.value, value: inner.value };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((inner) => {
+ if (inner.status === "aborted")
+ return parseUtil_1.INVALID;
+ if (inner.status === "dirty")
+ status.dirty();
+ return executeRefinement(inner.value).then(() => {
+ return { status: status.value, value: inner.value };
+ });
+ });
+ }
+ }
+ if (effect.type === "transform") {
+ if (ctx.common.async === false) {
+ const base = this._def.schema._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (!(0, parseUtil_1.isValid)(base))
+ return base;
+ const result = effect.transform(base.value, checkCtx);
+ if (result instanceof Promise) {
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
+ }
+ return { status: status.value, value: result };
+ }
+ else {
+ return this._def.schema
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
+ .then((base) => {
+ if (!(0, parseUtil_1.isValid)(base))
+ return base;
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
+ });
+ }
+ }
+ util_1.util.assertNever(effect);
+ }
+}
+exports.ZodEffects = ZodEffects;
+exports.ZodTransformer = ZodEffects;
+ZodEffects.create = (schema, effect, params) => {
+ return new ZodEffects({
+ schema,
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ effect,
+ ...processCreateParams(params),
+ });
+};
+ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
+ return new ZodEffects({
+ schema,
+ effect: { type: "preprocess", transform: preprocess },
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
+ ...processCreateParams(params),
+ });
+};
+class ZodOptional extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === util_1.ZodParsedType.undefined) {
+ return (0, parseUtil_1.OK)(undefined);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+}
+exports.ZodOptional = ZodOptional;
+ZodOptional.create = (type, params) => {
+ return new ZodOptional({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
+ ...processCreateParams(params),
+ });
+};
+class ZodNullable extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType === util_1.ZodParsedType.null) {
+ return (0, parseUtil_1.OK)(null);
+ }
+ return this._def.innerType._parse(input);
+ }
+ unwrap() {
+ return this._def.innerType;
+ }
+}
+exports.ZodNullable = ZodNullable;
+ZodNullable.create = (type, params) => {
+ return new ZodNullable({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
+ ...processCreateParams(params),
+ });
+};
+class ZodDefault extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ let data = ctx.data;
+ if (ctx.parsedType === util_1.ZodParsedType.undefined) {
+ data = this._def.defaultValue();
+ }
+ return this._def.innerType._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ removeDefault() {
+ return this._def.innerType;
+ }
+}
+exports.ZodDefault = ZodDefault;
+ZodDefault.create = (type, params) => {
+ return new ZodDefault({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
+ defaultValue: typeof params.default === "function"
+ ? params.default
+ : () => params.default,
+ ...processCreateParams(params),
+ });
+};
+class ZodCatch extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const newCtx = {
+ ...ctx,
+ common: {
+ ...ctx.common,
+ issues: [],
+ },
+ };
+ const result = this._def.innerType._parse({
+ data: newCtx.data,
+ path: newCtx.path,
+ parent: {
+ ...newCtx,
+ },
+ });
+ if ((0, parseUtil_1.isAsync)(result)) {
+ return result.then((result) => {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError_1.ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ });
+ }
+ else {
+ return {
+ status: "valid",
+ value: result.status === "valid"
+ ? result.value
+ : this._def.catchValue({
+ get error() {
+ return new ZodError_1.ZodError(newCtx.common.issues);
+ },
+ input: newCtx.data,
+ }),
+ };
+ }
+ }
+ removeCatch() {
+ return this._def.innerType;
+ }
+}
+exports.ZodCatch = ZodCatch;
+ZodCatch.create = (type, params) => {
+ return new ZodCatch({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
+ ...processCreateParams(params),
+ });
+};
+class ZodNaN extends ZodType {
+ _parse(input) {
+ const parsedType = this._getType(input);
+ if (parsedType !== util_1.ZodParsedType.nan) {
+ const ctx = this._getOrReturnCtx(input);
+ (0, parseUtil_1.addIssueToContext)(ctx, {
+ code: ZodError_1.ZodIssueCode.invalid_type,
+ expected: util_1.ZodParsedType.nan,
+ received: ctx.parsedType,
+ });
+ return parseUtil_1.INVALID;
+ }
+ return { status: "valid", value: input.data };
+ }
+}
+exports.ZodNaN = ZodNaN;
+ZodNaN.create = (params) => {
+ return new ZodNaN({
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
+ ...processCreateParams(params),
+ });
+};
+exports.BRAND = Symbol("zod_brand");
+class ZodBranded extends ZodType {
+ _parse(input) {
+ const { ctx } = this._processInputParams(input);
+ const data = ctx.data;
+ return this._def.type._parse({
+ data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ unwrap() {
+ return this._def.type;
+ }
+}
+exports.ZodBranded = ZodBranded;
+class ZodPipeline extends ZodType {
+ _parse(input) {
+ const { status, ctx } = this._processInputParams(input);
+ if (ctx.common.async) {
+ const handleAsync = async () => {
+ const inResult = await this._def.in._parseAsync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return parseUtil_1.INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return (0, parseUtil_1.DIRTY)(inResult.value);
+ }
+ else {
+ return this._def.out._parseAsync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ };
+ return handleAsync();
+ }
+ else {
+ const inResult = this._def.in._parseSync({
+ data: ctx.data,
+ path: ctx.path,
+ parent: ctx,
+ });
+ if (inResult.status === "aborted")
+ return parseUtil_1.INVALID;
+ if (inResult.status === "dirty") {
+ status.dirty();
+ return {
+ status: "dirty",
+ value: inResult.value,
+ };
+ }
+ else {
+ return this._def.out._parseSync({
+ data: inResult.value,
+ path: ctx.path,
+ parent: ctx,
+ });
+ }
+ }
+ }
+ static create(a, b) {
+ return new ZodPipeline({
+ in: a,
+ out: b,
+ typeName: ZodFirstPartyTypeKind.ZodPipeline,
+ });
+ }
+}
+exports.ZodPipeline = ZodPipeline;
+class ZodReadonly extends ZodType {
+ _parse(input) {
+ const result = this._def.innerType._parse(input);
+ if ((0, parseUtil_1.isValid)(result)) {
+ result.value = Object.freeze(result.value);
+ }
+ return result;
+ }
+}
+exports.ZodReadonly = ZodReadonly;
+ZodReadonly.create = (type, params) => {
+ return new ZodReadonly({
+ innerType: type,
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
+ ...processCreateParams(params),
+ });
+};
+const custom = (check, params = {}, fatal) => {
+ if (check)
+ return ZodAny.create().superRefine((data, ctx) => {
+ var _a, _b;
+ if (!check(data)) {
+ const p = typeof params === "function"
+ ? params(data)
+ : typeof params === "string"
+ ? { message: params }
+ : params;
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
+ const p2 = typeof p === "string" ? { message: p } : p;
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
+ }
+ });
+ return ZodAny.create();
+};
+exports.custom = custom;
+exports.late = {
+ object: ZodObject.lazycreate,
+};
+var ZodFirstPartyTypeKind;
+(function (ZodFirstPartyTypeKind) {
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
+})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
+class Class {
+ constructor(..._) { }
+}
+const instanceOfType = (cls, params = {
+ message: `Input not instance of ${cls.name}`,
+}) => (0, exports.custom)((data) => data instanceof cls, params);
+exports.instanceof = instanceOfType;
+const stringType = ZodString.create;
+exports.string = stringType;
+const numberType = ZodNumber.create;
+exports.number = numberType;
+const nanType = ZodNaN.create;
+exports.nan = nanType;
+const bigIntType = ZodBigInt.create;
+exports.bigint = bigIntType;
+const booleanType = ZodBoolean.create;
+exports.boolean = booleanType;
+const dateType = ZodDate.create;
+exports.date = dateType;
+const symbolType = ZodSymbol.create;
+exports.symbol = symbolType;
+const undefinedType = ZodUndefined.create;
+exports.undefined = undefinedType;
+const nullType = ZodNull.create;
+exports.null = nullType;
+const anyType = ZodAny.create;
+exports.any = anyType;
+const unknownType = ZodUnknown.create;
+exports.unknown = unknownType;
+const neverType = ZodNever.create;
+exports.never = neverType;
+const voidType = ZodVoid.create;
+exports.void = voidType;
+const arrayType = ZodArray.create;
+exports.array = arrayType;
+const objectType = ZodObject.create;
+exports.object = objectType;
+const strictObjectType = ZodObject.strictCreate;
+exports.strictObject = strictObjectType;
+const unionType = ZodUnion.create;
+exports.union = unionType;
+const discriminatedUnionType = ZodDiscriminatedUnion.create;
+exports.discriminatedUnion = discriminatedUnionType;
+const intersectionType = ZodIntersection.create;
+exports.intersection = intersectionType;
+const tupleType = ZodTuple.create;
+exports.tuple = tupleType;
+const recordType = ZodRecord.create;
+exports.record = recordType;
+const mapType = ZodMap.create;
+exports.map = mapType;
+const setType = ZodSet.create;
+exports.set = setType;
+const functionType = ZodFunction.create;
+exports.function = functionType;
+const lazyType = ZodLazy.create;
+exports.lazy = lazyType;
+const literalType = ZodLiteral.create;
+exports.literal = literalType;
+const enumType = ZodEnum.create;
+exports.enum = enumType;
+const nativeEnumType = ZodNativeEnum.create;
+exports.nativeEnum = nativeEnumType;
+const promiseType = ZodPromise.create;
+exports.promise = promiseType;
+const effectsType = ZodEffects.create;
+exports.effect = effectsType;
+exports.transformer = effectsType;
+const optionalType = ZodOptional.create;
+exports.optional = optionalType;
+const nullableType = ZodNullable.create;
+exports.nullable = nullableType;
+const preprocessType = ZodEffects.createWithPreprocess;
+exports.preprocess = preprocessType;
+const pipelineType = ZodPipeline.create;
+exports.pipeline = pipelineType;
+const ostring = () => stringType().optional();
+exports.ostring = ostring;
+const onumber = () => numberType().optional();
+exports.onumber = onumber;
+const oboolean = () => booleanType().optional();
+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,
+ })),
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
+};
+exports.NEVER = parseUtil_1.INVALID;