feat: Passwordless cross-device authentication

- Arkitektur: docs/auth/passwordless-architecture.md
- Backend: iom/quixzoom-auth-service/ (FastAPI + Redis)
- Webb: quixzoom-market-pages/se/login/ (QR-kod + polling)
- App: iom/quixzoom-app/src/features/auth/ (push + deep links)

Flöde: QR-kod → app-godkännande → webb-inloggad
This commit is contained in:
Bernt
2026-07-07 07:11:50 +00:00
parent 4aa984ad74
commit 6989a98d75
61843 changed files with 5491611 additions and 872231 deletions
+32
View File
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
var index_js_1 = require("../core/index.cjs");
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return index_js_1._lt; } });
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return index_js_1._lte; } });
Object.defineProperty(exports, "gt", { enumerable: true, get: function () { return index_js_1._gt; } });
Object.defineProperty(exports, "gte", { enumerable: true, get: function () { return index_js_1._gte; } });
Object.defineProperty(exports, "positive", { enumerable: true, get: function () { return index_js_1._positive; } });
Object.defineProperty(exports, "negative", { enumerable: true, get: function () { return index_js_1._negative; } });
Object.defineProperty(exports, "nonpositive", { enumerable: true, get: function () { return index_js_1._nonpositive; } });
Object.defineProperty(exports, "nonnegative", { enumerable: true, get: function () { return index_js_1._nonnegative; } });
Object.defineProperty(exports, "multipleOf", { enumerable: true, get: function () { return index_js_1._multipleOf; } });
Object.defineProperty(exports, "maxSize", { enumerable: true, get: function () { return index_js_1._maxSize; } });
Object.defineProperty(exports, "minSize", { enumerable: true, get: function () { return index_js_1._minSize; } });
Object.defineProperty(exports, "size", { enumerable: true, get: function () { return index_js_1._size; } });
Object.defineProperty(exports, "maxLength", { enumerable: true, get: function () { return index_js_1._maxLength; } });
Object.defineProperty(exports, "minLength", { enumerable: true, get: function () { return index_js_1._minLength; } });
Object.defineProperty(exports, "length", { enumerable: true, get: function () { return index_js_1._length; } });
Object.defineProperty(exports, "regex", { enumerable: true, get: function () { return index_js_1._regex; } });
Object.defineProperty(exports, "lowercase", { enumerable: true, get: function () { return index_js_1._lowercase; } });
Object.defineProperty(exports, "uppercase", { enumerable: true, get: function () { return index_js_1._uppercase; } });
Object.defineProperty(exports, "includes", { enumerable: true, get: function () { return index_js_1._includes; } });
Object.defineProperty(exports, "startsWith", { enumerable: true, get: function () { return index_js_1._startsWith; } });
Object.defineProperty(exports, "endsWith", { enumerable: true, get: function () { return index_js_1._endsWith; } });
Object.defineProperty(exports, "property", { enumerable: true, get: function () { return index_js_1._property; } });
Object.defineProperty(exports, "mime", { enumerable: true, get: function () { return index_js_1._mime; } });
Object.defineProperty(exports, "overwrite", { enumerable: true, get: function () { return index_js_1._overwrite; } });
Object.defineProperty(exports, "normalize", { enumerable: true, get: function () { return index_js_1._normalize; } });
Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return index_js_1._trim; } });
Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function () { return index_js_1._toLowerCase; } });
Object.defineProperty(exports, "toUpperCase", { enumerable: true, get: function () { return index_js_1._toUpperCase; } });
+1
View File
@@ -0,0 +1 @@
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.cjs";
+1
View File
@@ -0,0 +1 @@
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
+1
View File
@@ -0,0 +1 @@
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
+47
View File
@@ -0,0 +1,47 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.string = string;
exports.number = number;
exports.boolean = boolean;
exports.bigint = bigint;
exports.date = date;
const core = __importStar(require("../core/index.cjs"));
const schemas = __importStar(require("./schemas.cjs"));
function string(params) {
return core._coercedString(schemas.ZodString, params);
}
function number(params) {
return core._coercedNumber(schemas.ZodNumber, params);
}
function boolean(params) {
return core._coercedBoolean(schemas.ZodBoolean, params);
}
function bigint(params) {
return core._coercedBigint(schemas.ZodBigInt, params);
}
function date(params) {
return core._coercedDate(schemas.ZodDate, params);
}
+17
View File
@@ -0,0 +1,17 @@
import * as core from "../core/index.cjs";
import * as schemas from "./schemas.cjs";
export interface ZodCoercedString<T = unknown> extends schemas._ZodString<core.$ZodStringInternals<T>> {
}
export declare function string<T = unknown>(params?: string | core.$ZodStringParams): ZodCoercedString<T>;
export interface ZodCoercedNumber<T = unknown> extends schemas._ZodNumber<core.$ZodNumberInternals<T>> {
}
export declare function number<T = unknown>(params?: string | core.$ZodNumberParams): ZodCoercedNumber<T>;
export interface ZodCoercedBoolean<T = unknown> extends schemas._ZodBoolean<core.$ZodBooleanInternals<T>> {
}
export declare function boolean<T = unknown>(params?: string | core.$ZodBooleanParams): ZodCoercedBoolean<T>;
export interface ZodCoercedBigInt<T = unknown> extends schemas._ZodBigInt<core.$ZodBigIntInternals<T>> {
}
export declare function bigint<T = unknown>(params?: string | core.$ZodBigIntParams): ZodCoercedBigInt<T>;
export interface ZodCoercedDate<T = unknown> extends schemas._ZodDate<core.$ZodDateInternals<T>> {
}
export declare function date<T = unknown>(params?: string | core.$ZodDateParams): ZodCoercedDate<T>;
+17
View File
@@ -0,0 +1,17 @@
import * as core from "../core/index.js";
import * as schemas from "./schemas.js";
export interface ZodCoercedString<T = unknown> extends schemas._ZodString<core.$ZodStringInternals<T>> {
}
export declare function string<T = unknown>(params?: string | core.$ZodStringParams): ZodCoercedString<T>;
export interface ZodCoercedNumber<T = unknown> extends schemas._ZodNumber<core.$ZodNumberInternals<T>> {
}
export declare function number<T = unknown>(params?: string | core.$ZodNumberParams): ZodCoercedNumber<T>;
export interface ZodCoercedBoolean<T = unknown> extends schemas._ZodBoolean<core.$ZodBooleanInternals<T>> {
}
export declare function boolean<T = unknown>(params?: string | core.$ZodBooleanParams): ZodCoercedBoolean<T>;
export interface ZodCoercedBigInt<T = unknown> extends schemas._ZodBigInt<core.$ZodBigIntInternals<T>> {
}
export declare function bigint<T = unknown>(params?: string | core.$ZodBigIntParams): ZodCoercedBigInt<T>;
export interface ZodCoercedDate<T = unknown> extends schemas._ZodDate<core.$ZodDateInternals<T>> {
}
export declare function date<T = unknown>(params?: string | core.$ZodDateParams): ZodCoercedDate<T>;
+17
View File
@@ -0,0 +1,17 @@
import * as core from "../core/index.js";
import * as schemas from "./schemas.js";
export function string(params) {
return core._coercedString(schemas.ZodString, params);
}
export function number(params) {
return core._coercedNumber(schemas.ZodNumber, params);
}
export function boolean(params) {
return core._coercedBoolean(schemas.ZodBoolean, params);
}
export function bigint(params) {
return core._coercedBigint(schemas.ZodBigInt, params);
}
export function date(params) {
return core._coercedDate(schemas.ZodDate, params);
}
+57
View File
@@ -0,0 +1,57 @@
"use strict";
// Zod 3 compat layer
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.config = exports.$brand = exports.ZodIssueCode = void 0;
exports.setErrorMap = setErrorMap;
exports.getErrorMap = getErrorMap;
const core = __importStar(require("../core/index.cjs"));
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
exports.ZodIssueCode = {
invalid_type: "invalid_type",
too_big: "too_big",
too_small: "too_small",
invalid_format: "invalid_format",
not_multiple_of: "not_multiple_of",
unrecognized_keys: "unrecognized_keys",
invalid_union: "invalid_union",
invalid_key: "invalid_key",
invalid_element: "invalid_element",
invalid_value: "invalid_value",
custom: "custom",
};
var index_js_1 = require("../core/index.cjs");
Object.defineProperty(exports, "$brand", { enumerable: true, get: function () { return index_js_1.$brand; } });
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return index_js_1.config; } });
/** @deprecated Use `z.config(params)` instead. */
function setErrorMap(map) {
core.config({
customError: map,
});
}
/** @deprecated Use `z.config()` instead. */
function getErrorMap() {
return core.config().customError;
}
+46
View File
@@ -0,0 +1,46 @@
import * as core from "../core/index.cjs";
import type { ZodType } from "./schemas.cjs";
export type {
/** @deprecated Use `z.output<T>` instead. */
output as TypeOf,
/** @deprecated Use `z.output<T>` instead. */
output as Infer,
/** @deprecated Use `z.core.$$ZodFirstPartyTypes` instead */
$ZodTypes as ZodFirstPartySchemaTypes, } from "../core/index.cjs";
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
export declare const ZodIssueCode: {
readonly invalid_type: "invalid_type";
readonly too_big: "too_big";
readonly too_small: "too_small";
readonly invalid_format: "invalid_format";
readonly not_multiple_of: "not_multiple_of";
readonly unrecognized_keys: "unrecognized_keys";
readonly invalid_union: "invalid_union";
readonly invalid_key: "invalid_key";
readonly invalid_element: "invalid_element";
readonly invalid_value: "invalid_value";
readonly custom: "custom";
};
/** @deprecated Use `z.$ZodFlattenedError` */
export type inferFlattenedErrors<T extends core.$ZodType, U = string> = core.$ZodFlattenedError<core.output<T>, U>;
/** @deprecated Use `z.$ZodFormattedError` */
export type inferFormattedError<T extends core.$ZodType<any, any>, U = string> = core.$ZodFormattedError<core.output<T>, U>;
/** Use `z.$brand` instead */
export type BRAND<T extends string | number | symbol = string | number | symbol> = {
[core.$brand]: {
[k in T]: true;
};
};
export { $brand, config } from "../core/index.cjs";
/** @deprecated Use `z.config(params)` instead. */
export declare function setErrorMap(map: core.$ZodErrorMap): void;
/** @deprecated Use `z.config()` instead. */
export declare function getErrorMap(): core.$ZodErrorMap<core.$ZodIssue> | undefined;
export type {
/** @deprecated Use z.ZodType (without generics) instead. */
ZodType as ZodTypeAny,
/** @deprecated Use `z.ZodType` */
ZodType as ZodSchema,
/** @deprecated Use `z.ZodType` */
ZodType as Schema, };
export type ZodRawShape = core.$ZodShape;
+46
View File
@@ -0,0 +1,46 @@
import * as core from "../core/index.js";
import type { ZodType } from "./schemas.js";
export type {
/** @deprecated Use `z.output<T>` instead. */
output as TypeOf,
/** @deprecated Use `z.output<T>` instead. */
output as Infer,
/** @deprecated Use `z.core.$$ZodFirstPartyTypes` instead */
$ZodTypes as ZodFirstPartySchemaTypes, } from "../core/index.js";
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
export declare const ZodIssueCode: {
readonly invalid_type: "invalid_type";
readonly too_big: "too_big";
readonly too_small: "too_small";
readonly invalid_format: "invalid_format";
readonly not_multiple_of: "not_multiple_of";
readonly unrecognized_keys: "unrecognized_keys";
readonly invalid_union: "invalid_union";
readonly invalid_key: "invalid_key";
readonly invalid_element: "invalid_element";
readonly invalid_value: "invalid_value";
readonly custom: "custom";
};
/** @deprecated Use `z.$ZodFlattenedError` */
export type inferFlattenedErrors<T extends core.$ZodType, U = string> = core.$ZodFlattenedError<core.output<T>, U>;
/** @deprecated Use `z.$ZodFormattedError` */
export type inferFormattedError<T extends core.$ZodType<any, any>, U = string> = core.$ZodFormattedError<core.output<T>, U>;
/** Use `z.$brand` instead */
export type BRAND<T extends string | number | symbol = string | number | symbol> = {
[core.$brand]: {
[k in T]: true;
};
};
export { $brand, config } from "../core/index.js";
/** @deprecated Use `z.config(params)` instead. */
export declare function setErrorMap(map: core.$ZodErrorMap): void;
/** @deprecated Use `z.config()` instead. */
export declare function getErrorMap(): core.$ZodErrorMap<core.$ZodIssue> | undefined;
export type {
/** @deprecated Use z.ZodType (without generics) instead. */
ZodType as ZodTypeAny,
/** @deprecated Use `z.ZodType` */
ZodType as ZodSchema,
/** @deprecated Use `z.ZodType` */
ZodType as Schema, };
export type ZodRawShape = core.$ZodShape;
+27
View File
@@ -0,0 +1,27 @@
// Zod 3 compat layer
import * as core from "../core/index.js";
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
export const ZodIssueCode = {
invalid_type: "invalid_type",
too_big: "too_big",
too_small: "too_small",
invalid_format: "invalid_format",
not_multiple_of: "not_multiple_of",
unrecognized_keys: "unrecognized_keys",
invalid_union: "invalid_union",
invalid_key: "invalid_key",
invalid_element: "invalid_element",
invalid_value: "invalid_value",
custom: "custom",
};
export { $brand, config } from "../core/index.js";
/** @deprecated Use `z.config(params)` instead. */
export function setErrorMap(map) {
core.config({
customError: map,
});
}
/** @deprecated Use `z.config()` instead. */
export function getErrorMap() {
return core.config().customError;
}
+67
View File
@@ -0,0 +1,67 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodRealError = exports.ZodError = void 0;
const core = __importStar(require("../core/index.cjs"));
const index_js_1 = require("../core/index.cjs");
const initializer = (inst, issues) => {
index_js_1.$ZodError.init(inst, issues);
inst.name = "ZodError";
Object.defineProperties(inst, {
format: {
value: (mapper) => core.formatError(inst, mapper),
// enumerable: false,
},
flatten: {
value: (mapper) => core.flattenError(inst, mapper),
// enumerable: false,
},
addIssue: {
value: (issue) => inst.issues.push(issue),
// enumerable: false,
},
addIssues: {
value: (issues) => inst.issues.push(...issues),
// enumerable: false,
},
isEmpty: {
get() {
return inst.issues.length === 0;
},
// enumerable: false,
},
});
// Object.defineProperty(inst, "isEmpty", {
// get() {
// return inst.issues.length === 0;
// },
// });
};
exports.ZodError = core.$constructor("ZodError", initializer);
exports.ZodRealError = core.$constructor("ZodError", initializer, {
Parent: Error,
});
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
+30
View File
@@ -0,0 +1,30 @@
import * as core from "../core/index.cjs";
import { $ZodError } from "../core/index.cjs";
/** @deprecated Use `z.core.$ZodIssue` from `@zod/core` instead, especially if you are building a library on top of Zod. */
export type ZodIssue = core.$ZodIssue;
/** An Error-like class used to store Zod validation issues. */
export interface ZodError<T = unknown> extends $ZodError<T> {
/** @deprecated Use the `z.treeifyError(err)` function instead. */
format(): core.$ZodFormattedError<T>;
format<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFormattedError<T, U>;
/** @deprecated Use the `z.treeifyError(err)` function instead. */
flatten(): core.$ZodFlattenedError<T>;
flatten<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFlattenedError<T, U>;
/** @deprecated Push directly to `.issues` instead. */
addIssue(issue: core.$ZodIssue): void;
/** @deprecated Push directly to `.issues` instead. */
addIssues(issues: core.$ZodIssue[]): void;
/** @deprecated Check `err.issues.length === 0` instead. */
isEmpty: boolean;
}
export declare const ZodError: core.$constructor<ZodError>;
export declare const ZodRealError: core.$constructor<ZodError>;
export type {
/** @deprecated Use `z.core.$ZodFlattenedError` instead. */
$ZodFlattenedError as ZodFlattenedError,
/** @deprecated Use `z.core.$ZodFormattedError` instead. */
$ZodFormattedError as ZodFormattedError,
/** @deprecated Use `z.core.$ZodErrorMap` instead. */
$ZodErrorMap as ZodErrorMap, } from "../core/index.cjs";
/** @deprecated Use `z.core.$ZodRawIssue` instead. */
export type IssueData = core.$ZodRawIssue;
+30
View File
@@ -0,0 +1,30 @@
import * as core from "../core/index.js";
import { $ZodError } from "../core/index.js";
/** @deprecated Use `z.core.$ZodIssue` from `@zod/core` instead, especially if you are building a library on top of Zod. */
export type ZodIssue = core.$ZodIssue;
/** An Error-like class used to store Zod validation issues. */
export interface ZodError<T = unknown> extends $ZodError<T> {
/** @deprecated Use the `z.treeifyError(err)` function instead. */
format(): core.$ZodFormattedError<T>;
format<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFormattedError<T, U>;
/** @deprecated Use the `z.treeifyError(err)` function instead. */
flatten(): core.$ZodFlattenedError<T>;
flatten<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFlattenedError<T, U>;
/** @deprecated Push directly to `.issues` instead. */
addIssue(issue: core.$ZodIssue): void;
/** @deprecated Push directly to `.issues` instead. */
addIssues(issues: core.$ZodIssue[]): void;
/** @deprecated Check `err.issues.length === 0` instead. */
isEmpty: boolean;
}
export declare const ZodError: core.$constructor<ZodError>;
export declare const ZodRealError: core.$constructor<ZodError>;
export type {
/** @deprecated Use `z.core.$ZodFlattenedError` instead. */
$ZodFlattenedError as ZodFlattenedError,
/** @deprecated Use `z.core.$ZodFormattedError` instead. */
$ZodFormattedError as ZodFormattedError,
/** @deprecated Use `z.core.$ZodErrorMap` instead. */
$ZodErrorMap as ZodErrorMap, } from "../core/index.js";
/** @deprecated Use `z.core.$ZodRawIssue` instead. */
export type IssueData = core.$ZodRawIssue;
+41
View File
@@ -0,0 +1,41 @@
import * as core from "../core/index.js";
import { $ZodError } from "../core/index.js";
const initializer = (inst, issues) => {
$ZodError.init(inst, issues);
inst.name = "ZodError";
Object.defineProperties(inst, {
format: {
value: (mapper) => core.formatError(inst, mapper),
// enumerable: false,
},
flatten: {
value: (mapper) => core.flattenError(inst, mapper),
// enumerable: false,
},
addIssue: {
value: (issue) => inst.issues.push(issue),
// enumerable: false,
},
addIssues: {
value: (issues) => inst.issues.push(...issues),
// enumerable: false,
},
isEmpty: {
get() {
return inst.issues.length === 0;
},
// enumerable: false,
},
});
// Object.defineProperty(inst, "isEmpty", {
// get() {
// return inst.issues.length === 0;
// },
// });
};
export const ZodError = core.$constructor("ZodError", initializer);
export const ZodRealError = core.$constructor("ZodError", initializer, {
Parent: Error,
});
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
+70
View File
@@ -0,0 +1,70 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.coerce = exports.iso = exports.ZodISODuration = exports.ZodISOTime = exports.ZodISODate = exports.ZodISODateTime = exports.locales = exports.NEVER = exports.TimePrecision = exports.toJSONSchema = exports.flattenError = exports.formatError = exports.prettifyError = exports.treeifyError = exports.regexes = exports.clone = exports.$brand = exports.$input = exports.$output = exports.function = exports.config = exports.registry = exports.globalRegistry = exports.core = void 0;
exports.core = __importStar(require("../core/index.cjs"));
__exportStar(require("./schemas.cjs"), exports);
__exportStar(require("./checks.cjs"), exports);
__exportStar(require("./errors.cjs"), exports);
__exportStar(require("./parse.cjs"), exports);
__exportStar(require("./compat.cjs"), exports);
// zod-specified
const index_js_1 = require("../core/index.cjs");
const en_js_1 = __importDefault(require("../locales/en.cjs"));
(0, index_js_1.config)((0, en_js_1.default)());
var index_js_2 = require("../core/index.cjs");
Object.defineProperty(exports, "globalRegistry", { enumerable: true, get: function () { return index_js_2.globalRegistry; } });
Object.defineProperty(exports, "registry", { enumerable: true, get: function () { return index_js_2.registry; } });
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return index_js_2.config; } });
Object.defineProperty(exports, "function", { enumerable: true, get: function () { return index_js_2.function; } });
Object.defineProperty(exports, "$output", { enumerable: true, get: function () { return index_js_2.$output; } });
Object.defineProperty(exports, "$input", { enumerable: true, get: function () { return index_js_2.$input; } });
Object.defineProperty(exports, "$brand", { enumerable: true, get: function () { return index_js_2.$brand; } });
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return index_js_2.clone; } });
Object.defineProperty(exports, "regexes", { enumerable: true, get: function () { return index_js_2.regexes; } });
Object.defineProperty(exports, "treeifyError", { enumerable: true, get: function () { return index_js_2.treeifyError; } });
Object.defineProperty(exports, "prettifyError", { enumerable: true, get: function () { return index_js_2.prettifyError; } });
Object.defineProperty(exports, "formatError", { enumerable: true, get: function () { return index_js_2.formatError; } });
Object.defineProperty(exports, "flattenError", { enumerable: true, get: function () { return index_js_2.flattenError; } });
Object.defineProperty(exports, "toJSONSchema", { enumerable: true, get: function () { return index_js_2.toJSONSchema; } });
Object.defineProperty(exports, "TimePrecision", { enumerable: true, get: function () { return index_js_2.TimePrecision; } });
Object.defineProperty(exports, "NEVER", { enumerable: true, get: function () { return index_js_2.NEVER; } });
exports.locales = __importStar(require("../locales/index.cjs"));
// iso
// must be exported from top-level
// https://github.com/colinhacks/zod/issues/4491
var iso_js_1 = require("./iso.cjs");
Object.defineProperty(exports, "ZodISODateTime", { enumerable: true, get: function () { return iso_js_1.ZodISODateTime; } });
Object.defineProperty(exports, "ZodISODate", { enumerable: true, get: function () { return iso_js_1.ZodISODate; } });
Object.defineProperty(exports, "ZodISOTime", { enumerable: true, get: function () { return iso_js_1.ZodISOTime; } });
Object.defineProperty(exports, "ZodISODuration", { enumerable: true, get: function () { return iso_js_1.ZodISODuration; } });
exports.iso = __importStar(require("./iso.cjs"));
exports.coerce = __importStar(require("./coerce.cjs"));
+13
View File
@@ -0,0 +1,13 @@
export * as core from "../core/index.cjs";
export * from "./schemas.cjs";
export * from "./checks.cjs";
export * from "./errors.cjs";
export * from "./parse.cjs";
export * from "./compat.cjs";
export type { infer, output, input } from "../core/index.cjs";
export { globalRegistry, type GlobalMeta, registry, config, function, $output, $input, $brand, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.cjs";
export * as locales from "../locales/index.cjs";
export { ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration } from "./iso.cjs";
export * as iso from "./iso.cjs";
export type { ZodCoercedString, ZodCoercedNumber, ZodCoercedBigInt, ZodCoercedBoolean, ZodCoercedDate, } from "./coerce.cjs";
export * as coerce from "./coerce.cjs";
+13
View File
@@ -0,0 +1,13 @@
export * as core from "../core/index.js";
export * from "./schemas.js";
export * from "./checks.js";
export * from "./errors.js";
export * from "./parse.js";
export * from "./compat.js";
export type { infer, output, input } from "../core/index.js";
export { globalRegistry, type GlobalMeta, registry, config, function, $output, $input, $brand, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.js";
export * as locales from "../locales/index.js";
export { ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration } from "./iso.js";
export * as iso from "./iso.js";
export type { ZodCoercedString, ZodCoercedNumber, ZodCoercedBigInt, ZodCoercedBoolean, ZodCoercedDate, } from "./coerce.js";
export * as coerce from "./coerce.js";
+18
View File
@@ -0,0 +1,18 @@
export * as core from "../core/index.js";
export * from "./schemas.js";
export * from "./checks.js";
export * from "./errors.js";
export * from "./parse.js";
export * from "./compat.js";
// zod-specified
import { config } from "../core/index.js";
import en from "../locales/en.js";
config(en());
export { globalRegistry, registry, config, function, $output, $input, $brand, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.js";
export * as locales from "../locales/index.js";
// iso
// must be exported from top-level
// https://github.com/colinhacks/zod/issues/4491
export { ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration } from "./iso.js";
export * as iso from "./iso.js";
export * as coerce from "./coerce.js";
+33
View File
@@ -0,0 +1,33 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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.cjs"));
exports.z = z;
__exportStar(require("./external.cjs"), exports);
exports.default = z;
+4
View File
@@ -0,0 +1,4 @@
import * as z from "./external.cjs";
export { z };
export * from "./external.cjs";
export default z;
+4
View File
@@ -0,0 +1,4 @@
import * as z from "./external.js";
export { z };
export * from "./external.js";
export default z;
+4
View File
@@ -0,0 +1,4 @@
import * as z from "./external.js";
export { z };
export * from "./external.js";
export default z;
+60
View File
@@ -0,0 +1,60 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodISODuration = exports.ZodISOTime = exports.ZodISODate = exports.ZodISODateTime = void 0;
exports.datetime = datetime;
exports.date = date;
exports.time = time;
exports.duration = duration;
const core = __importStar(require("../core/index.cjs"));
const schemas = __importStar(require("./schemas.cjs"));
exports.ZodISODateTime = core.$constructor("ZodISODateTime", (inst, def) => {
core.$ZodISODateTime.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
function datetime(params) {
return core._isoDateTime(exports.ZodISODateTime, params);
}
exports.ZodISODate = core.$constructor("ZodISODate", (inst, def) => {
core.$ZodISODate.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
function date(params) {
return core._isoDate(exports.ZodISODate, params);
}
exports.ZodISOTime = core.$constructor("ZodISOTime", (inst, def) => {
core.$ZodISOTime.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
function time(params) {
return core._isoTime(exports.ZodISOTime, params);
}
exports.ZodISODuration = core.$constructor("ZodISODuration", (inst, def) => {
core.$ZodISODuration.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
function duration(params) {
return core._isoDuration(exports.ZodISODuration, params);
}
+22
View File
@@ -0,0 +1,22 @@
import * as core from "../core/index.cjs";
import * as schemas from "./schemas.cjs";
export interface ZodISODateTime extends schemas.ZodStringFormat {
_zod: core.$ZodISODateTimeInternals;
}
export declare const ZodISODateTime: core.$constructor<ZodISODateTime>;
export declare function datetime(params?: string | core.$ZodISODateTimeParams): ZodISODateTime;
export interface ZodISODate extends schemas.ZodStringFormat {
_zod: core.$ZodISODateInternals;
}
export declare const ZodISODate: core.$constructor<ZodISODate>;
export declare function date(params?: string | core.$ZodISODateParams): ZodISODate;
export interface ZodISOTime extends schemas.ZodStringFormat {
_zod: core.$ZodISOTimeInternals;
}
export declare const ZodISOTime: core.$constructor<ZodISOTime>;
export declare function time(params?: string | core.$ZodISOTimeParams): ZodISOTime;
export interface ZodISODuration extends schemas.ZodStringFormat {
_zod: core.$ZodISODurationInternals;
}
export declare const ZodISODuration: core.$constructor<ZodISODuration>;
export declare function duration(params?: string | core.$ZodISODurationParams): ZodISODuration;
+22
View File
@@ -0,0 +1,22 @@
import * as core from "../core/index.js";
import * as schemas from "./schemas.js";
export interface ZodISODateTime extends schemas.ZodStringFormat {
_zod: core.$ZodISODateTimeInternals;
}
export declare const ZodISODateTime: core.$constructor<ZodISODateTime>;
export declare function datetime(params?: string | core.$ZodISODateTimeParams): ZodISODateTime;
export interface ZodISODate extends schemas.ZodStringFormat {
_zod: core.$ZodISODateInternals;
}
export declare const ZodISODate: core.$constructor<ZodISODate>;
export declare function date(params?: string | core.$ZodISODateParams): ZodISODate;
export interface ZodISOTime extends schemas.ZodStringFormat {
_zod: core.$ZodISOTimeInternals;
}
export declare const ZodISOTime: core.$constructor<ZodISOTime>;
export declare function time(params?: string | core.$ZodISOTimeParams): ZodISOTime;
export interface ZodISODuration extends schemas.ZodStringFormat {
_zod: core.$ZodISODurationInternals;
}
export declare const ZodISODuration: core.$constructor<ZodISODuration>;
export declare function duration(params?: string | core.$ZodISODurationParams): ZodISODuration;
+30
View File
@@ -0,0 +1,30 @@
import * as core from "../core/index.js";
import * as schemas from "./schemas.js";
export const ZodISODateTime = /*@__PURE__*/ core.$constructor("ZodISODateTime", (inst, def) => {
core.$ZodISODateTime.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
export function datetime(params) {
return core._isoDateTime(ZodISODateTime, params);
}
export const ZodISODate = /*@__PURE__*/ core.$constructor("ZodISODate", (inst, def) => {
core.$ZodISODate.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
export function date(params) {
return core._isoDate(ZodISODate, params);
}
export const ZodISOTime = /*@__PURE__*/ core.$constructor("ZodISOTime", (inst, def) => {
core.$ZodISOTime.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
export function time(params) {
return core._isoTime(ZodISOTime, params);
}
export const ZodISODuration = /*@__PURE__*/ core.$constructor("ZodISODuration", (inst, def) => {
core.$ZodISODuration.init(inst, def);
schemas.ZodStringFormat.init(inst, def);
});
export function duration(params) {
return core._isoDuration(ZodISODuration, params);
}
+32
View File
@@ -0,0 +1,32 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeParseAsync = exports.safeParse = exports.parseAsync = exports.parse = void 0;
const core = __importStar(require("../core/index.cjs"));
const errors_js_1 = require("./errors.cjs");
exports.parse = core._parse(errors_js_1.ZodRealError);
exports.parseAsync = core._parseAsync(errors_js_1.ZodRealError);
exports.safeParse = core._safeParse(errors_js_1.ZodRealError);
exports.safeParseAsync = core._safeParseAsync(errors_js_1.ZodRealError);
+23
View File
@@ -0,0 +1,23 @@
import * as core from "../core/index.cjs";
import { type ZodError } from "./errors.cjs";
export type ZodSafeParseResult<T> = ZodSafeParseSuccess<T> | ZodSafeParseError<T>;
export type ZodSafeParseSuccess<T> = {
success: true;
data: T;
error?: never;
};
export type ZodSafeParseError<T> = {
success: false;
data?: never;
error: ZodError<T>;
};
export declare const parse: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>, _params?: {
callee?: core.util.AnyFunc;
Err?: core.$ZodErrorClass;
}) => core.output<T>;
export declare const parseAsync: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>, _params?: {
callee?: core.util.AnyFunc;
Err?: core.$ZodErrorClass;
}) => Promise<core.output<T>>;
export declare const safeParse: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>) => ZodSafeParseResult<core.output<T>>;
export declare const safeParseAsync: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>) => Promise<ZodSafeParseResult<core.output<T>>>;
+23
View File
@@ -0,0 +1,23 @@
import * as core from "../core/index.js";
import { type ZodError } from "./errors.js";
export type ZodSafeParseResult<T> = ZodSafeParseSuccess<T> | ZodSafeParseError<T>;
export type ZodSafeParseSuccess<T> = {
success: true;
data: T;
error?: never;
};
export type ZodSafeParseError<T> = {
success: false;
data?: never;
error: ZodError<T>;
};
export declare const parse: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>, _params?: {
callee?: core.util.AnyFunc;
Err?: core.$ZodErrorClass;
}) => core.output<T>;
export declare const parseAsync: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>, _params?: {
callee?: core.util.AnyFunc;
Err?: core.$ZodErrorClass;
}) => Promise<core.output<T>>;
export declare const safeParse: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>) => ZodSafeParseResult<core.output<T>>;
export declare const safeParseAsync: <T extends core.$ZodType>(schema: T, value: unknown, _ctx?: core.ParseContext<core.$ZodIssue>) => Promise<ZodSafeParseResult<core.output<T>>>;
+6
View File
@@ -0,0 +1,6 @@
import * as core from "../core/index.js";
import { ZodRealError } from "./errors.js";
export const parse = /* @__PURE__ */ core._parse(ZodRealError);
export const parseAsync = /* @__PURE__ */ core._parseAsync(ZodRealError);
export const safeParse = /* @__PURE__ */ core._safeParse(ZodRealError);
export const safeParseAsync = /* @__PURE__ */ core._safeParseAsync(ZodRealError);
+1109
View File
@@ -0,0 +1,1109 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZodTransform = exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodCustomStringFormat = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
exports.stringbool = exports.ZodCustom = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = void 0;
exports.string = string;
exports.email = email;
exports.guid = guid;
exports.uuid = uuid;
exports.uuidv4 = uuidv4;
exports.uuidv6 = uuidv6;
exports.uuidv7 = uuidv7;
exports.url = url;
exports.emoji = emoji;
exports.nanoid = nanoid;
exports.cuid = cuid;
exports.cuid2 = cuid2;
exports.ulid = ulid;
exports.xid = xid;
exports.ksuid = ksuid;
exports.ipv4 = ipv4;
exports.ipv6 = ipv6;
exports.cidrv4 = cidrv4;
exports.cidrv6 = cidrv6;
exports.base64 = base64;
exports.base64url = base64url;
exports.e164 = e164;
exports.jwt = jwt;
exports.stringFormat = stringFormat;
exports.number = number;
exports.int = int;
exports.float32 = float32;
exports.float64 = float64;
exports.int32 = int32;
exports.uint32 = uint32;
exports.boolean = boolean;
exports.bigint = bigint;
exports.int64 = int64;
exports.uint64 = uint64;
exports.symbol = symbol;
exports.undefined = _undefined;
exports.null = _null;
exports.any = any;
exports.unknown = unknown;
exports.never = never;
exports.void = _void;
exports.date = date;
exports.array = array;
exports.keyof = keyof;
exports.object = object;
exports.strictObject = strictObject;
exports.looseObject = looseObject;
exports.union = union;
exports.discriminatedUnion = discriminatedUnion;
exports.intersection = intersection;
exports.tuple = tuple;
exports.record = record;
exports.partialRecord = partialRecord;
exports.map = map;
exports.set = set;
exports.enum = _enum;
exports.nativeEnum = nativeEnum;
exports.literal = literal;
exports.file = file;
exports.transform = transform;
exports.optional = optional;
exports.nullable = nullable;
exports.nullish = nullish;
exports._default = _default;
exports.prefault = prefault;
exports.nonoptional = nonoptional;
exports.success = success;
exports.catch = _catch;
exports.nan = nan;
exports.pipe = pipe;
exports.readonly = readonly;
exports.templateLiteral = templateLiteral;
exports.lazy = lazy;
exports.promise = promise;
exports.check = check;
exports.custom = custom;
exports.refine = refine;
exports.superRefine = superRefine;
exports.instanceof = _instanceof;
exports.json = json;
exports.preprocess = preprocess;
const core = __importStar(require("../core/index.cjs"));
const index_js_1 = require("../core/index.cjs");
const checks = __importStar(require("./checks.cjs"));
const iso = __importStar(require("./iso.cjs"));
const parse = __importStar(require("./parse.cjs"));
exports.ZodType = core.$constructor("ZodType", (inst, def) => {
core.$ZodType.init(inst, def);
inst.def = def;
Object.defineProperty(inst, "_def", { value: def });
// base methods
inst.check = (...checks) => {
return inst.clone({
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
],
}
// { parent: true }
);
};
inst.clone = (def, params) => core.clone(inst, def, params);
inst.brand = () => inst;
inst.register = ((reg, meta) => {
reg.add(inst, meta);
return inst;
});
// parsing
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
inst.spa = inst.safeParseAsync;
// refinements
inst.refine = (check, params) => inst.check(refine(check, params));
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
// wrappers
inst.optional = () => optional(inst);
inst.nullable = () => nullable(inst);
inst.nullish = () => optional(nullable(inst));
inst.nonoptional = (params) => nonoptional(inst, params);
inst.array = () => array(inst);
inst.or = (arg) => union([inst, arg]);
inst.and = (arg) => intersection(inst, arg);
inst.transform = (tx) => pipe(inst, transform(tx));
inst.default = (def) => _default(inst, def);
inst.prefault = (def) => prefault(inst, def);
// inst.coalesce = (def, params) => coalesce(inst, def, params);
inst.catch = (params) => _catch(inst, params);
inst.pipe = (target) => pipe(inst, target);
inst.readonly = () => readonly(inst);
// meta
inst.describe = (description) => {
const cl = inst.clone();
core.globalRegistry.add(cl, { description });
return cl;
};
Object.defineProperty(inst, "description", {
get() {
return core.globalRegistry.get(inst)?.description;
},
configurable: true,
});
inst.meta = (...args) => {
if (args.length === 0) {
return core.globalRegistry.get(inst);
}
const cl = inst.clone();
core.globalRegistry.add(cl, args[0]);
return cl;
};
// helpers
inst.isOptional = () => inst.safeParse(undefined).success;
inst.isNullable = () => inst.safeParse(null).success;
return inst;
});
/** @internal */
exports._ZodString = core.$constructor("_ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
exports.ZodType.init(inst, def);
const bag = inst._zod.bag;
inst.format = bag.format ?? null;
inst.minLength = bag.minimum ?? null;
inst.maxLength = bag.maximum ?? null;
// validations
inst.regex = (...args) => inst.check(checks.regex(...args));
inst.includes = (...args) => inst.check(checks.includes(...args));
inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
inst.endsWith = (...args) => inst.check(checks.endsWith(...args));
inst.min = (...args) => inst.check(checks.minLength(...args));
inst.max = (...args) => inst.check(checks.maxLength(...args));
inst.length = (...args) => inst.check(checks.length(...args));
inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args));
inst.lowercase = (params) => inst.check(checks.lowercase(params));
inst.uppercase = (params) => inst.check(checks.uppercase(params));
// transforms
inst.trim = () => inst.check(checks.trim());
inst.normalize = (...args) => inst.check(checks.normalize(...args));
inst.toLowerCase = () => inst.check(checks.toLowerCase());
inst.toUpperCase = () => inst.check(checks.toUpperCase());
});
exports.ZodString = core.$constructor("ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
exports._ZodString.init(inst, def);
inst.email = (params) => inst.check(core._email(exports.ZodEmail, params));
inst.url = (params) => inst.check(core._url(exports.ZodURL, params));
inst.jwt = (params) => inst.check(core._jwt(exports.ZodJWT, params));
inst.emoji = (params) => inst.check(core._emoji(exports.ZodEmoji, params));
inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params));
inst.uuid = (params) => inst.check(core._uuid(exports.ZodUUID, params));
inst.uuidv4 = (params) => inst.check(core._uuidv4(exports.ZodUUID, params));
inst.uuidv6 = (params) => inst.check(core._uuidv6(exports.ZodUUID, params));
inst.uuidv7 = (params) => inst.check(core._uuidv7(exports.ZodUUID, params));
inst.nanoid = (params) => inst.check(core._nanoid(exports.ZodNanoID, params));
inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params));
inst.cuid = (params) => inst.check(core._cuid(exports.ZodCUID, params));
inst.cuid2 = (params) => inst.check(core._cuid2(exports.ZodCUID2, params));
inst.ulid = (params) => inst.check(core._ulid(exports.ZodULID, params));
inst.base64 = (params) => inst.check(core._base64(exports.ZodBase64, params));
inst.base64url = (params) => inst.check(core._base64url(exports.ZodBase64URL, params));
inst.xid = (params) => inst.check(core._xid(exports.ZodXID, params));
inst.ksuid = (params) => inst.check(core._ksuid(exports.ZodKSUID, params));
inst.ipv4 = (params) => inst.check(core._ipv4(exports.ZodIPv4, params));
inst.ipv6 = (params) => inst.check(core._ipv6(exports.ZodIPv6, params));
inst.cidrv4 = (params) => inst.check(core._cidrv4(exports.ZodCIDRv4, params));
inst.cidrv6 = (params) => inst.check(core._cidrv6(exports.ZodCIDRv6, params));
inst.e164 = (params) => inst.check(core._e164(exports.ZodE164, params));
// iso
inst.datetime = (params) => inst.check(iso.datetime(params));
inst.date = (params) => inst.check(iso.date(params));
inst.time = (params) => inst.check(iso.time(params));
inst.duration = (params) => inst.check(iso.duration(params));
});
function string(params) {
return core._string(exports.ZodString, params);
}
exports.ZodStringFormat = core.$constructor("ZodStringFormat", (inst, def) => {
core.$ZodStringFormat.init(inst, def);
exports._ZodString.init(inst, def);
});
exports.ZodEmail = core.$constructor("ZodEmail", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmail.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function email(params) {
return core._email(exports.ZodEmail, params);
}
exports.ZodGUID = core.$constructor("ZodGUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodGUID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function guid(params) {
return core._guid(exports.ZodGUID, params);
}
exports.ZodUUID = core.$constructor("ZodUUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodUUID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function uuid(params) {
return core._uuid(exports.ZodUUID, params);
}
function uuidv4(params) {
return core._uuidv4(exports.ZodUUID, params);
}
// ZodUUIDv6
function uuidv6(params) {
return core._uuidv6(exports.ZodUUID, params);
}
// ZodUUIDv7
function uuidv7(params) {
return core._uuidv7(exports.ZodUUID, params);
}
exports.ZodURL = core.$constructor("ZodURL", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodURL.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function url(params) {
return core._url(exports.ZodURL, params);
}
exports.ZodEmoji = core.$constructor("ZodEmoji", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmoji.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function emoji(params) {
return core._emoji(exports.ZodEmoji, params);
}
exports.ZodNanoID = core.$constructor("ZodNanoID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodNanoID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function nanoid(params) {
return core._nanoid(exports.ZodNanoID, params);
}
exports.ZodCUID = core.$constructor("ZodCUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function cuid(params) {
return core._cuid(exports.ZodCUID, params);
}
exports.ZodCUID2 = core.$constructor("ZodCUID2", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID2.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function cuid2(params) {
return core._cuid2(exports.ZodCUID2, params);
}
exports.ZodULID = core.$constructor("ZodULID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodULID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function ulid(params) {
return core._ulid(exports.ZodULID, params);
}
exports.ZodXID = core.$constructor("ZodXID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodXID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function xid(params) {
return core._xid(exports.ZodXID, params);
}
exports.ZodKSUID = core.$constructor("ZodKSUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodKSUID.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function ksuid(params) {
return core._ksuid(exports.ZodKSUID, params);
}
exports.ZodIPv4 = core.$constructor("ZodIPv4", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv4.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function ipv4(params) {
return core._ipv4(exports.ZodIPv4, params);
}
exports.ZodIPv6 = core.$constructor("ZodIPv6", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv6.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function ipv6(params) {
return core._ipv6(exports.ZodIPv6, params);
}
exports.ZodCIDRv4 = core.$constructor("ZodCIDRv4", (inst, def) => {
core.$ZodCIDRv4.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function cidrv4(params) {
return core._cidrv4(exports.ZodCIDRv4, params);
}
exports.ZodCIDRv6 = core.$constructor("ZodCIDRv6", (inst, def) => {
core.$ZodCIDRv6.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function cidrv6(params) {
return core._cidrv6(exports.ZodCIDRv6, params);
}
exports.ZodBase64 = core.$constructor("ZodBase64", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function base64(params) {
return core._base64(exports.ZodBase64, params);
}
exports.ZodBase64URL = core.$constructor("ZodBase64URL", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64URL.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function base64url(params) {
return core._base64url(exports.ZodBase64URL, params);
}
exports.ZodE164 = core.$constructor("ZodE164", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodE164.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function e164(params) {
return core._e164(exports.ZodE164, params);
}
exports.ZodJWT = core.$constructor("ZodJWT", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodJWT.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function jwt(params) {
return core._jwt(exports.ZodJWT, params);
}
exports.ZodCustomStringFormat = core.$constructor("ZodCustomStringFormat", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCustomStringFormat.init(inst, def);
exports.ZodStringFormat.init(inst, def);
});
function stringFormat(format, fnOrRegex, _params = {}) {
return core._stringFormat(exports.ZodCustomStringFormat, format, fnOrRegex, _params);
}
exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => {
core.$ZodNumber.init(inst, def);
exports.ZodType.init(inst, def);
inst.gt = (value, params) => inst.check(checks.gt(value, params));
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.lt = (value, params) => inst.check(checks.lt(value, params));
inst.lte = (value, params) => inst.check(checks.lte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
inst.int = (params) => inst.check(int(params));
inst.safe = (params) => inst.check(int(params));
inst.positive = (params) => inst.check(checks.gt(0, params));
inst.nonnegative = (params) => inst.check(checks.gte(0, params));
inst.negative = (params) => inst.check(checks.lt(0, params));
inst.nonpositive = (params) => inst.check(checks.lte(0, params));
inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
inst.step = (value, params) => inst.check(checks.multipleOf(value, params));
// inst.finite = (params) => inst.check(core.finite(params));
inst.finite = () => inst;
const bag = inst._zod.bag;
inst.minValue =
Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
inst.maxValue =
Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
inst.isFinite = true;
inst.format = bag.format ?? null;
});
function number(params) {
return core._number(exports.ZodNumber, params);
}
exports.ZodNumberFormat = core.$constructor("ZodNumberFormat", (inst, def) => {
core.$ZodNumberFormat.init(inst, def);
exports.ZodNumber.init(inst, def);
});
function int(params) {
return core._int(exports.ZodNumberFormat, params);
}
function float32(params) {
return core._float32(exports.ZodNumberFormat, params);
}
function float64(params) {
return core._float64(exports.ZodNumberFormat, params);
}
function int32(params) {
return core._int32(exports.ZodNumberFormat, params);
}
function uint32(params) {
return core._uint32(exports.ZodNumberFormat, params);
}
exports.ZodBoolean = core.$constructor("ZodBoolean", (inst, def) => {
core.$ZodBoolean.init(inst, def);
exports.ZodType.init(inst, def);
});
function boolean(params) {
return core._boolean(exports.ZodBoolean, params);
}
exports.ZodBigInt = core.$constructor("ZodBigInt", (inst, def) => {
core.$ZodBigInt.init(inst, def);
exports.ZodType.init(inst, def);
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.gt = (value, params) => inst.check(checks.gt(value, params));
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.lt = (value, params) => inst.check(checks.lt(value, params));
inst.lte = (value, params) => inst.check(checks.lte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
inst.positive = (params) => inst.check(checks.gt(BigInt(0), params));
inst.negative = (params) => inst.check(checks.lt(BigInt(0), params));
inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params));
inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params));
inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
const bag = inst._zod.bag;
inst.minValue = bag.minimum ?? null;
inst.maxValue = bag.maximum ?? null;
inst.format = bag.format ?? null;
});
function bigint(params) {
return core._bigint(exports.ZodBigInt, params);
}
exports.ZodBigIntFormat = core.$constructor("ZodBigIntFormat", (inst, def) => {
core.$ZodBigIntFormat.init(inst, def);
exports.ZodBigInt.init(inst, def);
});
// int64
function int64(params) {
return core._int64(exports.ZodBigIntFormat, params);
}
// uint64
function uint64(params) {
return core._uint64(exports.ZodBigIntFormat, params);
}
exports.ZodSymbol = core.$constructor("ZodSymbol", (inst, def) => {
core.$ZodSymbol.init(inst, def);
exports.ZodType.init(inst, def);
});
function symbol(params) {
return core._symbol(exports.ZodSymbol, params);
}
exports.ZodUndefined = core.$constructor("ZodUndefined", (inst, def) => {
core.$ZodUndefined.init(inst, def);
exports.ZodType.init(inst, def);
});
function _undefined(params) {
return core._undefined(exports.ZodUndefined, params);
}
exports.ZodNull = core.$constructor("ZodNull", (inst, def) => {
core.$ZodNull.init(inst, def);
exports.ZodType.init(inst, def);
});
function _null(params) {
return core._null(exports.ZodNull, params);
}
exports.ZodAny = core.$constructor("ZodAny", (inst, def) => {
core.$ZodAny.init(inst, def);
exports.ZodType.init(inst, def);
});
function any() {
return core._any(exports.ZodAny);
}
exports.ZodUnknown = core.$constructor("ZodUnknown", (inst, def) => {
core.$ZodUnknown.init(inst, def);
exports.ZodType.init(inst, def);
});
function unknown() {
return core._unknown(exports.ZodUnknown);
}
exports.ZodNever = core.$constructor("ZodNever", (inst, def) => {
core.$ZodNever.init(inst, def);
exports.ZodType.init(inst, def);
});
function never(params) {
return core._never(exports.ZodNever, params);
}
exports.ZodVoid = core.$constructor("ZodVoid", (inst, def) => {
core.$ZodVoid.init(inst, def);
exports.ZodType.init(inst, def);
});
function _void(params) {
return core._void(exports.ZodVoid, params);
}
exports.ZodDate = core.$constructor("ZodDate", (inst, def) => {
core.$ZodDate.init(inst, def);
exports.ZodType.init(inst, def);
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
const c = inst._zod.bag;
inst.minDate = c.minimum ? new Date(c.minimum) : null;
inst.maxDate = c.maximum ? new Date(c.maximum) : null;
});
function date(params) {
return core._date(exports.ZodDate, params);
}
exports.ZodArray = core.$constructor("ZodArray", (inst, def) => {
core.$ZodArray.init(inst, def);
exports.ZodType.init(inst, def);
inst.element = def.element;
inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
inst.nonempty = (params) => inst.check(checks.minLength(1, params));
inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
inst.length = (len, params) => inst.check(checks.length(len, params));
inst.unwrap = () => inst.element;
});
function array(element, params) {
return core._array(exports.ZodArray, element, params);
}
// .keyof
function keyof(schema) {
const shape = schema._zod.def.shape;
return literal(Object.keys(shape));
}
exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
core.$ZodObject.init(inst, def);
exports.ZodType.init(inst, def);
index_js_1.util.defineLazy(inst, "shape", () => def.shape);
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
// inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
inst.extend = (incoming) => {
return index_js_1.util.extend(inst, incoming);
};
inst.merge = (other) => index_js_1.util.merge(inst, other);
inst.pick = (mask) => index_js_1.util.pick(inst, mask);
inst.omit = (mask) => index_js_1.util.omit(inst, mask);
inst.partial = (...args) => index_js_1.util.partial(exports.ZodOptional, inst, args[0]);
inst.required = (...args) => index_js_1.util.required(exports.ZodNonOptional, inst, args[0]);
});
function object(shape, params) {
const def = {
type: "object",
get shape() {
index_js_1.util.assignProp(this, "shape", { ...shape });
return this.shape;
},
...index_js_1.util.normalizeParams(params),
};
return new exports.ZodObject(def);
}
// strictObject
function strictObject(shape, params) {
return new exports.ZodObject({
type: "object",
get shape() {
index_js_1.util.assignProp(this, "shape", { ...shape });
return this.shape;
},
catchall: never(),
...index_js_1.util.normalizeParams(params),
});
}
// looseObject
function looseObject(shape, params) {
return new exports.ZodObject({
type: "object",
get shape() {
index_js_1.util.assignProp(this, "shape", { ...shape });
return this.shape;
},
catchall: unknown(),
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodUnion = core.$constructor("ZodUnion", (inst, def) => {
core.$ZodUnion.init(inst, def);
exports.ZodType.init(inst, def);
inst.options = def.options;
});
function union(options, params) {
return new exports.ZodUnion({
type: "union",
options: options,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodDiscriminatedUnion = core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
exports.ZodUnion.init(inst, def);
core.$ZodDiscriminatedUnion.init(inst, def);
});
function discriminatedUnion(discriminator, options, params) {
// const [options, params] = args;
return new exports.ZodDiscriminatedUnion({
type: "union",
options,
discriminator,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodIntersection = core.$constructor("ZodIntersection", (inst, def) => {
core.$ZodIntersection.init(inst, def);
exports.ZodType.init(inst, def);
});
function intersection(left, right) {
return new exports.ZodIntersection({
type: "intersection",
left: left,
right: right,
});
}
exports.ZodTuple = core.$constructor("ZodTuple", (inst, def) => {
core.$ZodTuple.init(inst, def);
exports.ZodType.init(inst, def);
inst.rest = (rest) => inst.clone({
...inst._zod.def,
rest: rest,
});
});
function tuple(items, _paramsOrRest, _params) {
const hasRest = _paramsOrRest instanceof core.$ZodType;
const params = hasRest ? _params : _paramsOrRest;
const rest = hasRest ? _paramsOrRest : null;
return new exports.ZodTuple({
type: "tuple",
items: items,
rest,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodRecord = core.$constructor("ZodRecord", (inst, def) => {
core.$ZodRecord.init(inst, def);
exports.ZodType.init(inst, def);
inst.keyType = def.keyType;
inst.valueType = def.valueType;
});
function record(keyType, valueType, params) {
return new exports.ZodRecord({
type: "record",
keyType,
valueType: valueType,
...index_js_1.util.normalizeParams(params),
});
}
// type alksjf = core.output<core.$ZodRecordKey>;
function partialRecord(keyType, valueType, params) {
return new exports.ZodRecord({
type: "record",
keyType: union([keyType, never()]),
valueType: valueType,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodMap = core.$constructor("ZodMap", (inst, def) => {
core.$ZodMap.init(inst, def);
exports.ZodType.init(inst, def);
inst.keyType = def.keyType;
inst.valueType = def.valueType;
});
function map(keyType, valueType, params) {
return new exports.ZodMap({
type: "map",
keyType: keyType,
valueType: valueType,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodSet = core.$constructor("ZodSet", (inst, def) => {
core.$ZodSet.init(inst, def);
exports.ZodType.init(inst, def);
inst.min = (...args) => inst.check(core._minSize(...args));
inst.nonempty = (params) => inst.check(core._minSize(1, params));
inst.max = (...args) => inst.check(core._maxSize(...args));
inst.size = (...args) => inst.check(core._size(...args));
});
function set(valueType, params) {
return new exports.ZodSet({
type: "set",
valueType: valueType,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodEnum = core.$constructor("ZodEnum", (inst, def) => {
core.$ZodEnum.init(inst, def);
exports.ZodType.init(inst, def);
inst.enum = def.entries;
inst.options = Object.values(def.entries);
const keys = new Set(Object.keys(def.entries));
inst.extract = (values, params) => {
const newEntries = {};
for (const value of values) {
if (keys.has(value)) {
newEntries[value] = def.entries[value];
}
else
throw new Error(`Key ${value} not found in enum`);
}
return new exports.ZodEnum({
...def,
checks: [],
...index_js_1.util.normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (values, params) => {
const newEntries = { ...def.entries };
for (const value of values) {
if (keys.has(value)) {
delete newEntries[value];
}
else
throw new Error(`Key ${value} not found in enum`);
}
return new exports.ZodEnum({
...def,
checks: [],
...index_js_1.util.normalizeParams(params),
entries: newEntries,
});
};
});
function _enum(values, params) {
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
return new exports.ZodEnum({
type: "enum",
entries,
...index_js_1.util.normalizeParams(params),
});
}
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
*
* ```ts
* enum Colors { red, green, blue }
* z.enum(Colors);
* ```
*/
function nativeEnum(entries, params) {
return new exports.ZodEnum({
type: "enum",
entries,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodLiteral = core.$constructor("ZodLiteral", (inst, def) => {
core.$ZodLiteral.init(inst, def);
exports.ZodType.init(inst, def);
inst.values = new Set(def.values);
Object.defineProperty(inst, "value", {
get() {
if (def.values.length > 1) {
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
}
return def.values[0];
},
});
});
function literal(value, params) {
return new exports.ZodLiteral({
type: "literal",
values: Array.isArray(value) ? value : [value],
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodFile = core.$constructor("ZodFile", (inst, def) => {
core.$ZodFile.init(inst, def);
exports.ZodType.init(inst, def);
inst.min = (size, params) => inst.check(core._minSize(size, params));
inst.max = (size, params) => inst.check(core._maxSize(size, params));
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
});
function file(params) {
return core._file(exports.ZodFile, params);
}
exports.ZodTransform = core.$constructor("ZodTransform", (inst, def) => {
core.$ZodTransform.init(inst, def);
exports.ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
payload.addIssue = (issue) => {
if (typeof issue === "string") {
payload.issues.push(index_js_1.util.issue(issue, payload.value, def));
}
else {
// for Zod 3 backwards compatibility
const _issue = issue;
if (_issue.fatal)
_issue.continue = false;
_issue.code ?? (_issue.code = "custom");
_issue.input ?? (_issue.input = payload.value);
_issue.inst ?? (_issue.inst = inst);
_issue.continue ?? (_issue.continue = true);
payload.issues.push(index_js_1.util.issue(_issue));
}
};
const output = def.transform(payload.value, payload);
if (output instanceof Promise) {
return output.then((output) => {
payload.value = output;
return payload;
});
}
payload.value = output;
return payload;
};
});
function transform(fn) {
return new exports.ZodTransform({
type: "transform",
transform: fn,
});
}
exports.ZodOptional = core.$constructor("ZodOptional", (inst, def) => {
core.$ZodOptional.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function optional(innerType) {
return new exports.ZodOptional({
type: "optional",
innerType: innerType,
});
}
exports.ZodNullable = core.$constructor("ZodNullable", (inst, def) => {
core.$ZodNullable.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function nullable(innerType) {
return new exports.ZodNullable({
type: "nullable",
innerType: innerType,
});
}
// nullish
function nullish(innerType) {
return optional(nullable(innerType));
}
exports.ZodDefault = core.$constructor("ZodDefault", (inst, def) => {
core.$ZodDefault.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
});
function _default(innerType, defaultValue) {
return new exports.ZodDefault({
type: "default",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
},
});
}
exports.ZodPrefault = core.$constructor("ZodPrefault", (inst, def) => {
core.$ZodPrefault.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function prefault(innerType, defaultValue) {
return new exports.ZodPrefault({
type: "prefault",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
},
});
}
exports.ZodNonOptional = core.$constructor("ZodNonOptional", (inst, def) => {
core.$ZodNonOptional.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function nonoptional(innerType, params) {
return new exports.ZodNonOptional({
type: "nonoptional",
innerType: innerType,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodSuccess = core.$constructor("ZodSuccess", (inst, def) => {
core.$ZodSuccess.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function success(innerType) {
return new exports.ZodSuccess({
type: "success",
innerType: innerType,
});
}
exports.ZodCatch = core.$constructor("ZodCatch", (inst, def) => {
core.$ZodCatch.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
});
function _catch(innerType, catchValue) {
return new exports.ZodCatch({
type: "catch",
innerType: innerType,
catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
});
}
exports.ZodNaN = core.$constructor("ZodNaN", (inst, def) => {
core.$ZodNaN.init(inst, def);
exports.ZodType.init(inst, def);
});
function nan(params) {
return core._nan(exports.ZodNaN, params);
}
exports.ZodPipe = core.$constructor("ZodPipe", (inst, def) => {
core.$ZodPipe.init(inst, def);
exports.ZodType.init(inst, def);
inst.in = def.in;
inst.out = def.out;
});
function pipe(in_, out) {
return new exports.ZodPipe({
type: "pipe",
in: in_,
out: out,
// ...util.normalizeParams(params),
});
}
exports.ZodReadonly = core.$constructor("ZodReadonly", (inst, def) => {
core.$ZodReadonly.init(inst, def);
exports.ZodType.init(inst, def);
});
function readonly(innerType) {
return new exports.ZodReadonly({
type: "readonly",
innerType: innerType,
});
}
exports.ZodTemplateLiteral = core.$constructor("ZodTemplateLiteral", (inst, def) => {
core.$ZodTemplateLiteral.init(inst, def);
exports.ZodType.init(inst, def);
});
function templateLiteral(parts, params) {
return new exports.ZodTemplateLiteral({
type: "template_literal",
parts,
...index_js_1.util.normalizeParams(params),
});
}
exports.ZodLazy = core.$constructor("ZodLazy", (inst, def) => {
core.$ZodLazy.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.getter();
});
function lazy(getter) {
return new exports.ZodLazy({
type: "lazy",
getter: getter,
});
}
exports.ZodPromise = core.$constructor("ZodPromise", (inst, def) => {
core.$ZodPromise.init(inst, def);
exports.ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
function promise(innerType) {
return new exports.ZodPromise({
type: "promise",
innerType: innerType,
});
}
exports.ZodCustom = core.$constructor("ZodCustom", (inst, def) => {
core.$ZodCustom.init(inst, def);
exports.ZodType.init(inst, def);
});
// custom checks
function check(fn) {
const ch = new core.$ZodCheck({
check: "custom",
// ...util.normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
function custom(fn, _params) {
return core._custom(exports.ZodCustom, fn ?? (() => true), _params);
}
function refine(fn, _params = {}) {
return core._refine(exports.ZodCustom, fn, _params);
}
// superRefine
function superRefine(fn) {
const ch = check((payload) => {
payload.addIssue = (issue) => {
if (typeof issue === "string") {
payload.issues.push(index_js_1.util.issue(issue, payload.value, ch._zod.def));
}
else {
// for Zod 3 backwards compatibility
const _issue = issue;
if (_issue.fatal)
_issue.continue = false;
_issue.code ?? (_issue.code = "custom");
_issue.input ?? (_issue.input = payload.value);
_issue.inst ?? (_issue.inst = ch);
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
payload.issues.push(index_js_1.util.issue(_issue));
}
};
return fn(payload.value, payload);
});
return ch;
}
function _instanceof(cls, params = {
error: `Input not instance of ${cls.name}`,
}) {
const inst = new exports.ZodCustom({
type: "custom",
check: "custom",
fn: (data) => data instanceof cls,
abort: true,
...index_js_1.util.normalizeParams(params),
});
inst._zod.bag.Class = cls;
return inst;
}
// stringbool
const stringbool = (...args) => core._stringbool({
Pipe: exports.ZodPipe,
Boolean: exports.ZodBoolean,
String: exports.ZodString,
Transform: exports.ZodTransform,
}, ...args);
exports.stringbool = stringbool;
function json(params) {
const jsonSchema = lazy(() => {
return union([string(params), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
});
return jsonSchema;
}
// preprocess
// /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
function preprocess(fn, schema) {
return pipe(transform(fn), schema);
}
+630
View File
@@ -0,0 +1,630 @@
import * as core from "../core/index.cjs";
import { util } from "../core/index.cjs";
import * as parse from "./parse.cjs";
export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
}
export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
def: Internals["def"];
type: Internals["def"]["type"];
/** @deprecated Use `.def` instead. */
_def: Internals["def"];
/** @deprecated Use `z.output<typeof schema>` instead. */
_output: Internals["output"];
/** @deprecated Use `z.input<typeof schema>` instead. */
_input: Internals["input"];
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
clone(def?: Internals["def"], params?: {
parent: boolean;
}): this;
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T>;
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
/** @deprecated Use `.check()` instead. */
superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
optional(): ZodOptional<this>;
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
nullable(): ZodNullable<this>;
nullish(): ZodOptional<ZodNullable<this>>;
default(def: core.output<this>): ZodDefault<this>;
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
prefault(def: () => core.input<this>): ZodPrefault<this>;
prefault(def: core.input<this>): ZodPrefault<this>;
array(): ZodArray<this>;
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
catch(def: core.output<this>): ZodCatch<this>;
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
readonly(): ZodReadonly<this>;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
describe(description: string): this;
description?: string;
/** Returns the metadata associated with this instance in `z.globalRegistry` */
meta(): core.$replace<core.GlobalMeta, this> | undefined;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
meta(data: core.$replace<core.GlobalMeta, this>): this;
/** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
*
* ```ts
* const schema = z.string().optional();
* const isOptional = schema.safeParse(undefined).success; // true
* ```
*/
isOptional(): boolean;
/**
* @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
*
* ```ts
* const schema = z.string().nullable();
* const isNullable = schema.safeParse(null).success; // true
* ```
*/
isNullable(): boolean;
}
export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$ZodTypeInternals> extends ZodType<any, any, Internals> {
}
export declare const ZodType: core.$constructor<ZodType>;
export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$ZodStringInternals<unknown>> extends _ZodType<T> {
format: string | null;
minLength: number | null;
maxLength: number | null;
regex(regex: RegExp, params?: string | core.$ZodCheckRegexParams): this;
includes(value: string, params?: core.$ZodCheckIncludesParams): this;
startsWith(value: string, params?: string | core.$ZodCheckStartsWithParams): this;
endsWith(value: string, params?: string | core.$ZodCheckEndsWithParams): this;
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
lowercase(params?: string | core.$ZodCheckLowerCaseParams): this;
uppercase(params?: string | core.$ZodCheckUpperCaseParams): this;
trim(): this;
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
toLowerCase(): this;
toUpperCase(): this;
}
/** @internal */
export declare const _ZodString: core.$constructor<_ZodString>;
export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
/** @deprecated Use `z.email()` instead. */
email(params?: string | core.$ZodCheckEmailParams): this;
/** @deprecated Use `z.url()` instead. */
url(params?: string | core.$ZodCheckURLParams): this;
/** @deprecated Use `z.jwt()` instead. */
jwt(params?: string | core.$ZodCheckJWTParams): this;
/** @deprecated Use `z.emoji()` instead. */
emoji(params?: string | core.$ZodCheckEmojiParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuid(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv4(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv6(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv7(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.nanoid()` instead. */
nanoid(params?: string | core.$ZodCheckNanoIDParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/** @deprecated Use `z.cuid()` instead. */
cuid(params?: string | core.$ZodCheckCUIDParams): this;
/** @deprecated Use `z.cuid2()` instead. */
cuid2(params?: string | core.$ZodCheckCUID2Params): this;
/** @deprecated Use `z.ulid()` instead. */
ulid(params?: string | core.$ZodCheckULIDParams): this;
/** @deprecated Use `z.base64()` instead. */
base64(params?: string | core.$ZodCheckBase64Params): this;
/** @deprecated Use `z.base64url()` instead. */
base64url(params?: string | core.$ZodCheckBase64URLParams): this;
/** @deprecated Use `z.xid()` instead. */
xid(params?: string | core.$ZodCheckXIDParams): this;
/** @deprecated Use `z.ksuid()` instead. */
ksuid(params?: string | core.$ZodCheckKSUIDParams): this;
/** @deprecated Use `z.ipv4()` instead. */
ipv4(params?: string | core.$ZodCheckIPv4Params): this;
/** @deprecated Use `z.ipv6()` instead. */
ipv6(params?: string | core.$ZodCheckIPv6Params): this;
/** @deprecated Use `z.cidrv4()` instead. */
cidrv4(params?: string | core.$ZodCheckCIDRv4Params): this;
/** @deprecated Use `z.cidrv6()` instead. */
cidrv6(params?: string | core.$ZodCheckCIDRv6Params): this;
/** @deprecated Use `z.e164()` instead. */
e164(params?: string | core.$ZodCheckE164Params): this;
/** @deprecated Use `z.iso.datetime()` instead. */
datetime(params?: string | core.$ZodCheckISODateTimeParams): this;
/** @deprecated Use `z.iso.date()` instead. */
date(params?: string | core.$ZodCheckISODateParams): this;
/** @deprecated Use `z.iso.time()` instead. */
time(params?: string | core.$ZodCheckISOTimeParams): this;
/** @deprecated Use `z.iso.duration()` instead. */
duration(params?: string | core.$ZodCheckISODurationParams): this;
}
export declare const ZodString: core.$constructor<ZodString>;
export declare function string(params?: string | core.$ZodStringParams): ZodString;
export declare function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
export interface ZodStringFormat<Format extends string = string> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
}
export declare const ZodStringFormat: core.$constructor<ZodStringFormat>;
export interface ZodEmail extends ZodStringFormat<"email"> {
_zod: core.$ZodEmailInternals;
}
export declare const ZodEmail: core.$constructor<ZodEmail>;
export declare function email(params?: string | core.$ZodEmailParams): ZodEmail;
export interface ZodGUID extends ZodStringFormat<"guid"> {
_zod: core.$ZodGUIDInternals;
}
export declare const ZodGUID: core.$constructor<ZodGUID>;
export declare function guid(params?: string | core.$ZodGUIDParams): ZodGUID;
export interface ZodUUID extends ZodStringFormat<"uuid"> {
_zod: core.$ZodUUIDInternals;
}
export declare const ZodUUID: core.$constructor<ZodUUID>;
export declare function uuid(params?: string | core.$ZodUUIDParams): ZodUUID;
export declare function uuidv4(params?: string | core.$ZodUUIDv4Params): ZodUUID;
export declare function uuidv6(params?: string | core.$ZodUUIDv6Params): ZodUUID;
export declare function uuidv7(params?: string | core.$ZodUUIDv7Params): ZodUUID;
export interface ZodURL extends ZodStringFormat<"url"> {
_zod: core.$ZodURLInternals;
}
export declare const ZodURL: core.$constructor<ZodURL>;
export declare function url(params?: string | core.$ZodURLParams): ZodURL;
export interface ZodEmoji extends ZodStringFormat<"emoji"> {
_zod: core.$ZodEmojiInternals;
}
export declare const ZodEmoji: core.$constructor<ZodEmoji>;
export declare function emoji(params?: string | core.$ZodEmojiParams): ZodEmoji;
export interface ZodNanoID extends ZodStringFormat<"nanoid"> {
_zod: core.$ZodNanoIDInternals;
}
export declare const ZodNanoID: core.$constructor<ZodNanoID>;
export declare function nanoid(params?: string | core.$ZodNanoIDParams): ZodNanoID;
export interface ZodCUID extends ZodStringFormat<"cuid"> {
_zod: core.$ZodCUIDInternals;
}
export declare const ZodCUID: core.$constructor<ZodCUID>;
export declare function cuid(params?: string | core.$ZodCUIDParams): ZodCUID;
export interface ZodCUID2 extends ZodStringFormat<"cuid2"> {
_zod: core.$ZodCUID2Internals;
}
export declare const ZodCUID2: core.$constructor<ZodCUID2>;
export declare function cuid2(params?: string | core.$ZodCUID2Params): ZodCUID2;
export interface ZodULID extends ZodStringFormat<"ulid"> {
_zod: core.$ZodULIDInternals;
}
export declare const ZodULID: core.$constructor<ZodULID>;
export declare function ulid(params?: string | core.$ZodULIDParams): ZodULID;
export interface ZodXID extends ZodStringFormat<"xid"> {
_zod: core.$ZodXIDInternals;
}
export declare const ZodXID: core.$constructor<ZodXID>;
export declare function xid(params?: string | core.$ZodXIDParams): ZodXID;
export interface ZodKSUID extends ZodStringFormat<"ksuid"> {
_zod: core.$ZodKSUIDInternals;
}
export declare const ZodKSUID: core.$constructor<ZodKSUID>;
export declare function ksuid(params?: string | core.$ZodKSUIDParams): ZodKSUID;
export interface ZodIPv4 extends ZodStringFormat<"ipv4"> {
_zod: core.$ZodIPv4Internals;
}
export declare const ZodIPv4: core.$constructor<ZodIPv4>;
export declare function ipv4(params?: string | core.$ZodIPv4Params): ZodIPv4;
export interface ZodIPv6 extends ZodStringFormat<"ipv6"> {
_zod: core.$ZodIPv6Internals;
}
export declare const ZodIPv6: core.$constructor<ZodIPv6>;
export declare function ipv6(params?: string | core.$ZodIPv6Params): ZodIPv6;
export interface ZodCIDRv4 extends ZodStringFormat<"cidrv4"> {
_zod: core.$ZodCIDRv4Internals;
}
export declare const ZodCIDRv4: core.$constructor<ZodCIDRv4>;
export declare function cidrv4(params?: string | core.$ZodCIDRv4Params): ZodCIDRv4;
export interface ZodCIDRv6 extends ZodStringFormat<"cidrv6"> {
_zod: core.$ZodCIDRv6Internals;
}
export declare const ZodCIDRv6: core.$constructor<ZodCIDRv6>;
export declare function cidrv6(params?: string | core.$ZodCIDRv6Params): ZodCIDRv6;
export interface ZodBase64 extends ZodStringFormat<"base64"> {
_zod: core.$ZodBase64Internals;
}
export declare const ZodBase64: core.$constructor<ZodBase64>;
export declare function base64(params?: string | core.$ZodBase64Params): ZodBase64;
export interface ZodBase64URL extends ZodStringFormat<"base64url"> {
_zod: core.$ZodBase64URLInternals;
}
export declare const ZodBase64URL: core.$constructor<ZodBase64URL>;
export declare function base64url(params?: string | core.$ZodBase64URLParams): ZodBase64URL;
export interface ZodE164 extends ZodStringFormat<"e164"> {
_zod: core.$ZodE164Internals;
}
export declare const ZodE164: core.$constructor<ZodE164>;
export declare function e164(params?: string | core.$ZodE164Params): ZodE164;
export interface ZodJWT extends ZodStringFormat<"jwt"> {
_zod: core.$ZodJWTInternals;
}
export declare const ZodJWT: core.$constructor<ZodJWT>;
export declare function jwt(params?: string | core.$ZodJWTParams): ZodJWT;
export interface ZodCustomStringFormat<Format extends string = string> extends ZodStringFormat<Format>, core.$ZodCustomStringFormat<Format> {
_zod: core.$ZodCustomStringFormatInternals<Format>;
}
export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Identical to .min() */
gte(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
min(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
lt(value: number, params?: string | core.$ZodCheckLessThanParams): this;
/** Identical to .max() */
lte(value: number, params?: string | core.$ZodCheckLessThanParams): this;
max(value: number, params?: string | core.$ZodCheckLessThanParams): this;
/** Consider `z.int()` instead. This API is considered *legacy*; it will never be removed but a better alternative exists. */
int(params?: string | core.$ZodCheckNumberFormatParams): this;
/** @deprecated This is now identical to `.int()`. Only numbers in the safe integer range are accepted. */
safe(params?: string | core.$ZodCheckNumberFormatParams): this;
positive(params?: string | core.$ZodCheckGreaterThanParams): this;
nonnegative(params?: string | core.$ZodCheckGreaterThanParams): this;
negative(params?: string | core.$ZodCheckLessThanParams): this;
nonpositive(params?: string | core.$ZodCheckLessThanParams): this;
multipleOf(value: number, params?: string | core.$ZodCheckMultipleOfParams): this;
/** @deprecated Use `.multipleOf()` instead. */
step(value: number, params?: string | core.$ZodCheckMultipleOfParams): this;
/** @deprecated In v4 and later, z.number() does not allow infinite values by default. This is a no-op. */
finite(params?: unknown): this;
minValue: number | null;
maxValue: number | null;
/** @deprecated Check the `format` property instead. */
isInt: boolean;
/** @deprecated Number schemas no longer accept infinite values, so this always returns `true`. */
isFinite: boolean;
format: string | null;
}
export interface ZodNumber extends _ZodNumber<core.$ZodNumberInternals<number>> {
}
export declare const ZodNumber: core.$constructor<ZodNumber>;
export declare function number(params?: string | core.$ZodNumberParams): ZodNumber;
export interface ZodNumberFormat extends ZodNumber {
_zod: core.$ZodNumberFormatInternals;
}
export declare const ZodNumberFormat: core.$constructor<ZodNumberFormat>;
export interface ZodInt extends ZodNumberFormat {
}
export declare function int(params?: string | core.$ZodCheckNumberFormatParams): ZodInt;
export interface ZodFloat32 extends ZodNumberFormat {
}
export declare function float32(params?: string | core.$ZodCheckNumberFormatParams): ZodFloat32;
export interface ZodFloat64 extends ZodNumberFormat {
}
export declare function float64(params?: string | core.$ZodCheckNumberFormatParams): ZodFloat64;
export interface ZodInt32 extends ZodNumberFormat {
}
export declare function int32(params?: string | core.$ZodCheckNumberFormatParams): ZodInt32;
export interface ZodUInt32 extends ZodNumberFormat {
}
export declare function uint32(params?: string | core.$ZodCheckNumberFormatParams): ZodUInt32;
export interface _ZodBoolean<T extends core.$ZodBooleanInternals = core.$ZodBooleanInternals> extends _ZodType<T> {
}
export interface ZodBoolean extends _ZodBoolean<core.$ZodBooleanInternals<boolean>> {
}
export declare const ZodBoolean: core.$constructor<ZodBoolean>;
export declare function boolean(params?: string | core.$ZodBooleanParams): ZodBoolean;
export interface _ZodBigInt<T extends core.$ZodBigIntInternals = core.$ZodBigIntInternals> extends _ZodType<T> {
gte(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Alias of `.gte()` */
min(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
gt(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Alias of `.lte()` */
lte(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
max(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
lt(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
positive(params?: string | core.$ZodCheckGreaterThanParams): this;
negative(params?: string | core.$ZodCheckLessThanParams): this;
nonpositive(params?: string | core.$ZodCheckLessThanParams): this;
nonnegative(params?: string | core.$ZodCheckGreaterThanParams): this;
multipleOf(value: bigint, params?: string | core.$ZodCheckMultipleOfParams): this;
minValue: bigint | null;
maxValue: bigint | null;
format: string | null;
}
export interface ZodBigInt extends _ZodBigInt<core.$ZodBigIntInternals<bigint>> {
}
export declare const ZodBigInt: core.$constructor<ZodBigInt>;
export declare function bigint(params?: string | core.$ZodBigIntParams): ZodBigInt;
export interface ZodBigIntFormat extends ZodBigInt {
_zod: core.$ZodBigIntFormatInternals;
}
export declare const ZodBigIntFormat: core.$constructor<ZodBigIntFormat>;
export declare function int64(params?: string | core.$ZodBigIntFormatParams): ZodBigIntFormat;
export declare function uint64(params?: string | core.$ZodBigIntFormatParams): ZodBigIntFormat;
export interface ZodSymbol extends _ZodType<core.$ZodSymbolInternals> {
}
export declare const ZodSymbol: core.$constructor<ZodSymbol>;
export declare function symbol(params?: string | core.$ZodSymbolParams): ZodSymbol;
export interface ZodUndefined extends _ZodType<core.$ZodUndefinedInternals> {
}
export declare const ZodUndefined: core.$constructor<ZodUndefined>;
declare function _undefined(params?: string | core.$ZodUndefinedParams): ZodUndefined;
export { _undefined as undefined };
export interface ZodNull extends _ZodType<core.$ZodNullInternals> {
}
export declare const ZodNull: core.$constructor<ZodNull>;
declare function _null(params?: string | core.$ZodNullParams): ZodNull;
export { _null as null };
export interface ZodAny extends _ZodType<core.$ZodAnyInternals> {
}
export declare const ZodAny: core.$constructor<ZodAny>;
export declare function any(): ZodAny;
export interface ZodUnknown extends _ZodType<core.$ZodUnknownInternals> {
}
export declare const ZodUnknown: core.$constructor<ZodUnknown>;
export declare function unknown(): ZodUnknown;
export interface ZodNever extends _ZodType<core.$ZodNeverInternals> {
}
export declare const ZodNever: core.$constructor<ZodNever>;
export declare function never(params?: string | core.$ZodNeverParams): ZodNever;
export interface ZodVoid extends _ZodType<core.$ZodVoidInternals> {
}
export declare const ZodVoid: core.$constructor<ZodVoid>;
declare function _void(params?: string | core.$ZodVoidParams): ZodVoid;
export { _void as void };
export interface _ZodDate<T extends core.$ZodDateInternals = core.$ZodDateInternals> extends _ZodType<T> {
min(value: number | Date, params?: string | core.$ZodCheckGreaterThanParams): this;
max(value: number | Date, params?: string | core.$ZodCheckLessThanParams): this;
/** @deprecated Not recommended. */
minDate: Date | null;
/** @deprecated Not recommended. */
maxDate: Date | null;
}
export interface ZodDate extends _ZodDate<core.$ZodDateInternals<Date>> {
}
export declare const ZodDate: core.$constructor<ZodDate>;
export declare function date(params?: string | core.$ZodDateParams): ZodDate;
export interface ZodArray<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodArrayInternals<T>>, core.$ZodArray<T> {
element: T;
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
unwrap(): T;
}
export declare const ZodArray: core.$constructor<ZodArray>;
export declare function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T>;
export declare function keyof<T extends ZodObject>(schema: T): ZodLiteral<Exclude<keyof T["_zod"]["output"], symbol>>;
export interface ZodObject<
/** @ts-ignore Cast variance */
out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
shape: Shape;
keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
/** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
catchall<T extends core.SomeType>(schema: T): ZodObject<Shape, core.$catchall<T>>;
/** @deprecated Use `z.looseObject()` or `.loose()` instead. */
passthrough(): ZodObject<Shape, core.$loose>;
/** Consider `z.looseObject(A.shape)` instead */
loose(): ZodObject<Shape, core.$loose>;
/** Consider `z.strictObject(A.shape)` instead */
strict(): ZodObject<Shape, core.$strict>;
/** This is the default behavior. This method call is likely unnecessary. */
strip(): ZodObject<Shape, core.$strip>;
extend<U extends core.$ZodLooseShape & Partial<Record<keyof Shape, core.SomeType>>>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
/**
* @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
*
* ```ts
* const A = z.object({ a: z.string() });
* const B = z.object({ b: z.number() });
*
* const C = z.object({
* ...A.shape,
* ...B.shape
* });
* ```
*/
merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
pick<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
omit<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
partial(): ZodObject<{
[k in keyof Shape]: ZodOptional<Shape[k]>;
}, Config>;
partial<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<{
[k in keyof Shape]: k extends keyof M ? ZodOptional<Shape[k]> : Shape[k];
}, Config>;
required(): ZodObject<{
[k in keyof Shape]: ZodNonOptional<Shape[k]>;
}, Config>;
required<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<{
[k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
}, Config>;
}
export declare const ZodObject: core.$constructor<ZodObject>;
export declare function object<T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>>(shape?: T, params?: string | core.$ZodObjectParams): ZodObject<util.Writeable<T>, core.$strip>;
export declare function strictObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, core.$strict>;
export declare function looseObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, core.$loose>;
export interface ZodUnion<T extends readonly core.SomeType[] = readonly core.$ZodType[]> extends _ZodType<core.$ZodUnionInternals<T>>, core.$ZodUnion<T> {
options: T;
}
export declare const ZodUnion: core.$constructor<ZodUnion>;
export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[] = readonly core.$ZodType[]> extends ZodUnion<Options>, core.$ZodDiscriminatedUnion<Options> {
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
}
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]]>(discriminator: string, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types>;
export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodIntersectionInternals<A, B>>, core.$ZodIntersection<A, B> {
}
export declare const ZodIntersection: core.$constructor<ZodIntersection>;
export declare function intersection<T extends core.SomeType, U extends core.SomeType>(left: T, right: U): ZodIntersection<T, U>;
export interface ZodTuple<T extends util.TupleItems = readonly core.$ZodType[], Rest extends core.SomeType | null = core.$ZodType | null> extends _ZodType<core.$ZodTupleInternals<T, Rest>>, core.$ZodTuple<T, Rest> {
rest<Rest extends core.SomeType = core.$ZodType>(rest: Rest): ZodTuple<T, Rest>;
}
export declare const ZodTuple: core.$constructor<ZodTuple>;
export declare function tuple<T extends readonly [core.SomeType, ...core.SomeType[]]>(items: T, params?: string | core.$ZodTupleParams): ZodTuple<T, null>;
export declare function tuple<T extends readonly [core.SomeType, ...core.SomeType[]], Rest extends core.SomeType>(items: T, rest: Rest, params?: string | core.$ZodTupleParams): ZodTuple<T, Rest>;
export declare function tuple(items: [], params?: string | core.$ZodTupleParams): ZodTuple<[], null>;
export interface ZodRecord<Key extends core.$ZodRecordKey = core.$ZodRecordKey, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodRecordInternals<Key, Value>>, core.$ZodRecord<Key, Value> {
keyType: Key;
valueType: Value;
}
export declare const ZodRecord: core.$constructor<ZodRecord>;
export declare function record<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key, Value>;
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key & core.$partial, Value>;
export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodMapInternals<Key, Value>>, core.$ZodMap<Key, Value> {
keyType: Key;
valueType: Value;
}
export declare const ZodMap: core.$constructor<ZodMap>;
export declare function map<Key extends core.SomeType, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodMapParams): ZodMap<Key, Value>;
export interface ZodSet<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodSetInternals<T>>, core.$ZodSet<T> {
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
/** */
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
size(size: number, params?: string | core.$ZodCheckSizeEqualsParams): this;
}
export declare const ZodSet: core.$constructor<ZodSet>;
export declare function set<Value extends core.SomeType>(valueType: Value, params?: string | core.$ZodSetParams): ZodSet<Value>;
export interface ZodEnum<
/** @ts-ignore Cast variance */
out T extends util.EnumLike = util.EnumLike> extends _ZodType<core.$ZodEnumInternals<T>>, core.$ZodEnum<T> {
enum: T;
options: Array<T[keyof T]>;
extract<const U extends readonly (keyof T)[]>(values: U, params?: string | core.$ZodEnumParams): ZodEnum<util.Flatten<Pick<T, U[number]>>>;
exclude<const U extends readonly (keyof T)[]>(values: U, params?: string | core.$ZodEnumParams): ZodEnum<util.Flatten<Omit<T, U[number]>>>;
}
export declare const ZodEnum: core.$constructor<ZodEnum>;
declare function _enum<const T extends readonly string[]>(values: T, params?: string | core.$ZodEnumParams): ZodEnum<util.ToEnum<T[number]>>;
declare function _enum<const T extends util.EnumLike>(entries: T, params?: string | core.$ZodEnumParams): ZodEnum<T>;
export { _enum as enum };
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
*
* ```ts
* enum Colors { red, green, blue }
* z.enum(Colors);
* ```
*/
export declare function nativeEnum<T extends util.EnumLike>(entries: T, params?: string | core.$ZodEnumParams): ZodEnum<T>;
export interface ZodLiteral<T extends util.Literal = util.Literal> extends _ZodType<core.$ZodLiteralInternals<T>>, core.$ZodLiteral<T> {
values: Set<T>;
/** @legacy Use `.values` instead. Accessing this property will throw an error if the literal accepts multiple values. */
value: T;
}
export declare const ZodLiteral: core.$constructor<ZodLiteral>;
export declare function literal<const T extends ReadonlyArray<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T[number]>;
export declare function literal<const T extends util.Literal>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T>;
export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile {
min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
max(size: number, params?: string | core.$ZodCheckMaxSizeParams): this;
mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
}
export declare const ZodFile: core.$constructor<ZodFile>;
export declare function file(params?: string | core.$ZodFileParams): ZodFile;
export interface ZodTransform<O = unknown, I = unknown> extends _ZodType<core.$ZodTransformInternals<O, I>>, core.$ZodTransform<O, I> {
}
export declare const ZodTransform: core.$constructor<ZodTransform>;
export declare function transform<I = unknown, O = I>(fn: (input: I, ctx: core.ParsePayload) => O): ZodTransform<Awaited<O>, I>;
export interface ZodOptional<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodOptionalInternals<T>>, core.$ZodOptional<T> {
unwrap(): T;
}
export declare const ZodOptional: core.$constructor<ZodOptional>;
export declare function optional<T extends core.SomeType>(innerType: T): ZodOptional<T>;
export interface ZodNullable<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodNullableInternals<T>>, core.$ZodNullable<T> {
unwrap(): T;
}
export declare const ZodNullable: core.$constructor<ZodNullable>;
export declare function nullable<T extends core.SomeType>(innerType: T): ZodNullable<T>;
export declare function nullish<T extends core.SomeType>(innerType: T): ZodOptional<ZodNullable<T>>;
export interface ZodDefault<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodDefaultInternals<T>>, core.$ZodDefault<T> {
unwrap(): T;
/** @deprecated Use `.unwrap()` instead. */
removeDefault(): T;
}
export declare const ZodDefault: core.$constructor<ZodDefault>;
export declare function _default<T extends core.SomeType>(innerType: T, defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)): ZodDefault<T>;
export interface ZodPrefault<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPrefaultInternals<T>>, core.$ZodPrefault<T> {
unwrap(): T;
}
export declare const ZodPrefault: core.$constructor<ZodPrefault>;
export declare function prefault<T extends core.SomeType>(innerType: T, defaultValue: core.input<T> | (() => core.input<T>)): ZodPrefault<T>;
export interface ZodNonOptional<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodNonOptionalInternals<T>>, core.$ZodNonOptional<T> {
unwrap(): T;
}
export declare const ZodNonOptional: core.$constructor<ZodNonOptional>;
export declare function nonoptional<T extends core.SomeType>(innerType: T, params?: string | core.$ZodNonOptionalParams): ZodNonOptional<T>;
export interface ZodSuccess<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodSuccessInternals<T>>, core.$ZodSuccess<T> {
unwrap(): T;
}
export declare const ZodSuccess: core.$constructor<ZodSuccess>;
export declare function success<T extends core.SomeType>(innerType: T): ZodSuccess<T>;
export interface ZodCatch<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodCatchInternals<T>>, core.$ZodCatch<T> {
unwrap(): T;
/** @deprecated Use `.unwrap()` instead. */
removeCatch(): T;
}
export declare const ZodCatch: core.$constructor<ZodCatch>;
declare function _catch<T extends core.SomeType>(innerType: T, catchValue: core.output<T> | ((ctx: core.$ZodCatchCtx) => core.output<T>)): ZodCatch<T>;
export { _catch as catch };
export interface ZodNaN extends _ZodType<core.$ZodNaNInternals>, core.$ZodNaN {
}
export declare const ZodNaN: core.$constructor<ZodNaN>;
export declare function nan(params?: string | core.$ZodNaNParams): ZodNaN;
export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPipeInternals<A, B>>, core.$ZodPipe<A, B> {
in: A;
out: B;
}
export declare const ZodPipe: core.$constructor<ZodPipe>;
export declare function pipe<const A extends core.SomeType, B extends core.$ZodType<unknown, core.output<A>> = core.$ZodType<unknown, core.output<A>>>(in_: A, out: B | core.$ZodType<unknown, core.output<A>>): ZodPipe<A, B>;
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
}
export declare const ZodReadonly: core.$constructor<ZodReadonly>;
export declare function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T>;
export interface ZodTemplateLiteral<Template extends string = string> extends _ZodType<core.$ZodTemplateLiteralInternals<Template>>, core.$ZodTemplateLiteral<Template> {
}
export declare const ZodTemplateLiteral: core.$constructor<ZodTemplateLiteral>;
export declare function templateLiteral<const Parts extends core.$ZodTemplateLiteralPart[]>(parts: Parts, params?: string | core.$ZodTemplateLiteralParams): ZodTemplateLiteral<core.$PartsToTemplateLiteral<Parts>>;
export interface ZodLazy<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodLazyInternals<T>>, core.$ZodLazy<T> {
unwrap(): T;
}
export declare const ZodLazy: core.$constructor<ZodLazy>;
export declare function lazy<T extends core.SomeType>(getter: () => T): ZodLazy<T>;
export interface ZodPromise<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPromiseInternals<T>>, core.$ZodPromise<T> {
unwrap(): T;
}
export declare const ZodPromise: core.$constructor<ZodPromise>;
export declare function promise<T extends core.SomeType>(innerType: T): ZodPromise<T>;
export interface ZodCustom<O = unknown, I = unknown> extends _ZodType<core.$ZodCustomInternals<O, I>>, core.$ZodCustom<O, I> {
}
export declare const ZodCustom: core.$constructor<ZodCustom>;
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
export { _instanceof as instanceof };
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodPipe<ZodPipe<ZodString, ZodTransform<boolean, string>>, ZodBoolean>;
type _ZodJSONSchema = ZodUnion<[
ZodString,
ZodNumber,
ZodBoolean,
ZodNull,
ZodArray<ZodJSONSchema>,
ZodRecord<ZodString, ZodJSONSchema>
]>;
type _ZodJSONSchemaInternals = _ZodJSONSchema["_zod"];
export interface ZodJSONSchemaInternals extends _ZodJSONSchemaInternals {
output: util.JSONType;
input: util.JSONType;
}
export interface ZodJSONSchema extends _ZodJSONSchema {
_zod: ZodJSONSchemaInternals;
}
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
+630
View File
@@ -0,0 +1,630 @@
import * as core from "../core/index.js";
import { util } from "../core/index.js";
import * as parse from "./parse.js";
export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
}
export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
def: Internals["def"];
type: Internals["def"]["type"];
/** @deprecated Use `.def` instead. */
_def: Internals["def"];
/** @deprecated Use `z.output<typeof schema>` instead. */
_output: Internals["output"];
/** @deprecated Use `z.input<typeof schema>` instead. */
_input: Internals["input"];
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
clone(def?: Internals["def"], params?: {
parent: boolean;
}): this;
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T>;
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
/** @deprecated Use `.check()` instead. */
superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
optional(): ZodOptional<this>;
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
nullable(): ZodNullable<this>;
nullish(): ZodOptional<ZodNullable<this>>;
default(def: core.output<this>): ZodDefault<this>;
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
prefault(def: () => core.input<this>): ZodPrefault<this>;
prefault(def: core.input<this>): ZodPrefault<this>;
array(): ZodArray<this>;
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
catch(def: core.output<this>): ZodCatch<this>;
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
readonly(): ZodReadonly<this>;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
describe(description: string): this;
description?: string;
/** Returns the metadata associated with this instance in `z.globalRegistry` */
meta(): core.$replace<core.GlobalMeta, this> | undefined;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
meta(data: core.$replace<core.GlobalMeta, this>): this;
/** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
*
* ```ts
* const schema = z.string().optional();
* const isOptional = schema.safeParse(undefined).success; // true
* ```
*/
isOptional(): boolean;
/**
* @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
*
* ```ts
* const schema = z.string().nullable();
* const isNullable = schema.safeParse(null).success; // true
* ```
*/
isNullable(): boolean;
}
export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$ZodTypeInternals> extends ZodType<any, any, Internals> {
}
export declare const ZodType: core.$constructor<ZodType>;
export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$ZodStringInternals<unknown>> extends _ZodType<T> {
format: string | null;
minLength: number | null;
maxLength: number | null;
regex(regex: RegExp, params?: string | core.$ZodCheckRegexParams): this;
includes(value: string, params?: core.$ZodCheckIncludesParams): this;
startsWith(value: string, params?: string | core.$ZodCheckStartsWithParams): this;
endsWith(value: string, params?: string | core.$ZodCheckEndsWithParams): this;
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
lowercase(params?: string | core.$ZodCheckLowerCaseParams): this;
uppercase(params?: string | core.$ZodCheckUpperCaseParams): this;
trim(): this;
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
toLowerCase(): this;
toUpperCase(): this;
}
/** @internal */
export declare const _ZodString: core.$constructor<_ZodString>;
export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
/** @deprecated Use `z.email()` instead. */
email(params?: string | core.$ZodCheckEmailParams): this;
/** @deprecated Use `z.url()` instead. */
url(params?: string | core.$ZodCheckURLParams): this;
/** @deprecated Use `z.jwt()` instead. */
jwt(params?: string | core.$ZodCheckJWTParams): this;
/** @deprecated Use `z.emoji()` instead. */
emoji(params?: string | core.$ZodCheckEmojiParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuid(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv4(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv6(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv7(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.nanoid()` instead. */
nanoid(params?: string | core.$ZodCheckNanoIDParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/** @deprecated Use `z.cuid()` instead. */
cuid(params?: string | core.$ZodCheckCUIDParams): this;
/** @deprecated Use `z.cuid2()` instead. */
cuid2(params?: string | core.$ZodCheckCUID2Params): this;
/** @deprecated Use `z.ulid()` instead. */
ulid(params?: string | core.$ZodCheckULIDParams): this;
/** @deprecated Use `z.base64()` instead. */
base64(params?: string | core.$ZodCheckBase64Params): this;
/** @deprecated Use `z.base64url()` instead. */
base64url(params?: string | core.$ZodCheckBase64URLParams): this;
/** @deprecated Use `z.xid()` instead. */
xid(params?: string | core.$ZodCheckXIDParams): this;
/** @deprecated Use `z.ksuid()` instead. */
ksuid(params?: string | core.$ZodCheckKSUIDParams): this;
/** @deprecated Use `z.ipv4()` instead. */
ipv4(params?: string | core.$ZodCheckIPv4Params): this;
/** @deprecated Use `z.ipv6()` instead. */
ipv6(params?: string | core.$ZodCheckIPv6Params): this;
/** @deprecated Use `z.cidrv4()` instead. */
cidrv4(params?: string | core.$ZodCheckCIDRv4Params): this;
/** @deprecated Use `z.cidrv6()` instead. */
cidrv6(params?: string | core.$ZodCheckCIDRv6Params): this;
/** @deprecated Use `z.e164()` instead. */
e164(params?: string | core.$ZodCheckE164Params): this;
/** @deprecated Use `z.iso.datetime()` instead. */
datetime(params?: string | core.$ZodCheckISODateTimeParams): this;
/** @deprecated Use `z.iso.date()` instead. */
date(params?: string | core.$ZodCheckISODateParams): this;
/** @deprecated Use `z.iso.time()` instead. */
time(params?: string | core.$ZodCheckISOTimeParams): this;
/** @deprecated Use `z.iso.duration()` instead. */
duration(params?: string | core.$ZodCheckISODurationParams): this;
}
export declare const ZodString: core.$constructor<ZodString>;
export declare function string(params?: string | core.$ZodStringParams): ZodString;
export declare function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
export interface ZodStringFormat<Format extends string = string> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
}
export declare const ZodStringFormat: core.$constructor<ZodStringFormat>;
export interface ZodEmail extends ZodStringFormat<"email"> {
_zod: core.$ZodEmailInternals;
}
export declare const ZodEmail: core.$constructor<ZodEmail>;
export declare function email(params?: string | core.$ZodEmailParams): ZodEmail;
export interface ZodGUID extends ZodStringFormat<"guid"> {
_zod: core.$ZodGUIDInternals;
}
export declare const ZodGUID: core.$constructor<ZodGUID>;
export declare function guid(params?: string | core.$ZodGUIDParams): ZodGUID;
export interface ZodUUID extends ZodStringFormat<"uuid"> {
_zod: core.$ZodUUIDInternals;
}
export declare const ZodUUID: core.$constructor<ZodUUID>;
export declare function uuid(params?: string | core.$ZodUUIDParams): ZodUUID;
export declare function uuidv4(params?: string | core.$ZodUUIDv4Params): ZodUUID;
export declare function uuidv6(params?: string | core.$ZodUUIDv6Params): ZodUUID;
export declare function uuidv7(params?: string | core.$ZodUUIDv7Params): ZodUUID;
export interface ZodURL extends ZodStringFormat<"url"> {
_zod: core.$ZodURLInternals;
}
export declare const ZodURL: core.$constructor<ZodURL>;
export declare function url(params?: string | core.$ZodURLParams): ZodURL;
export interface ZodEmoji extends ZodStringFormat<"emoji"> {
_zod: core.$ZodEmojiInternals;
}
export declare const ZodEmoji: core.$constructor<ZodEmoji>;
export declare function emoji(params?: string | core.$ZodEmojiParams): ZodEmoji;
export interface ZodNanoID extends ZodStringFormat<"nanoid"> {
_zod: core.$ZodNanoIDInternals;
}
export declare const ZodNanoID: core.$constructor<ZodNanoID>;
export declare function nanoid(params?: string | core.$ZodNanoIDParams): ZodNanoID;
export interface ZodCUID extends ZodStringFormat<"cuid"> {
_zod: core.$ZodCUIDInternals;
}
export declare const ZodCUID: core.$constructor<ZodCUID>;
export declare function cuid(params?: string | core.$ZodCUIDParams): ZodCUID;
export interface ZodCUID2 extends ZodStringFormat<"cuid2"> {
_zod: core.$ZodCUID2Internals;
}
export declare const ZodCUID2: core.$constructor<ZodCUID2>;
export declare function cuid2(params?: string | core.$ZodCUID2Params): ZodCUID2;
export interface ZodULID extends ZodStringFormat<"ulid"> {
_zod: core.$ZodULIDInternals;
}
export declare const ZodULID: core.$constructor<ZodULID>;
export declare function ulid(params?: string | core.$ZodULIDParams): ZodULID;
export interface ZodXID extends ZodStringFormat<"xid"> {
_zod: core.$ZodXIDInternals;
}
export declare const ZodXID: core.$constructor<ZodXID>;
export declare function xid(params?: string | core.$ZodXIDParams): ZodXID;
export interface ZodKSUID extends ZodStringFormat<"ksuid"> {
_zod: core.$ZodKSUIDInternals;
}
export declare const ZodKSUID: core.$constructor<ZodKSUID>;
export declare function ksuid(params?: string | core.$ZodKSUIDParams): ZodKSUID;
export interface ZodIPv4 extends ZodStringFormat<"ipv4"> {
_zod: core.$ZodIPv4Internals;
}
export declare const ZodIPv4: core.$constructor<ZodIPv4>;
export declare function ipv4(params?: string | core.$ZodIPv4Params): ZodIPv4;
export interface ZodIPv6 extends ZodStringFormat<"ipv6"> {
_zod: core.$ZodIPv6Internals;
}
export declare const ZodIPv6: core.$constructor<ZodIPv6>;
export declare function ipv6(params?: string | core.$ZodIPv6Params): ZodIPv6;
export interface ZodCIDRv4 extends ZodStringFormat<"cidrv4"> {
_zod: core.$ZodCIDRv4Internals;
}
export declare const ZodCIDRv4: core.$constructor<ZodCIDRv4>;
export declare function cidrv4(params?: string | core.$ZodCIDRv4Params): ZodCIDRv4;
export interface ZodCIDRv6 extends ZodStringFormat<"cidrv6"> {
_zod: core.$ZodCIDRv6Internals;
}
export declare const ZodCIDRv6: core.$constructor<ZodCIDRv6>;
export declare function cidrv6(params?: string | core.$ZodCIDRv6Params): ZodCIDRv6;
export interface ZodBase64 extends ZodStringFormat<"base64"> {
_zod: core.$ZodBase64Internals;
}
export declare const ZodBase64: core.$constructor<ZodBase64>;
export declare function base64(params?: string | core.$ZodBase64Params): ZodBase64;
export interface ZodBase64URL extends ZodStringFormat<"base64url"> {
_zod: core.$ZodBase64URLInternals;
}
export declare const ZodBase64URL: core.$constructor<ZodBase64URL>;
export declare function base64url(params?: string | core.$ZodBase64URLParams): ZodBase64URL;
export interface ZodE164 extends ZodStringFormat<"e164"> {
_zod: core.$ZodE164Internals;
}
export declare const ZodE164: core.$constructor<ZodE164>;
export declare function e164(params?: string | core.$ZodE164Params): ZodE164;
export interface ZodJWT extends ZodStringFormat<"jwt"> {
_zod: core.$ZodJWTInternals;
}
export declare const ZodJWT: core.$constructor<ZodJWT>;
export declare function jwt(params?: string | core.$ZodJWTParams): ZodJWT;
export interface ZodCustomStringFormat<Format extends string = string> extends ZodStringFormat<Format>, core.$ZodCustomStringFormat<Format> {
_zod: core.$ZodCustomStringFormatInternals<Format>;
}
export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Identical to .min() */
gte(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
min(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
lt(value: number, params?: string | core.$ZodCheckLessThanParams): this;
/** Identical to .max() */
lte(value: number, params?: string | core.$ZodCheckLessThanParams): this;
max(value: number, params?: string | core.$ZodCheckLessThanParams): this;
/** Consider `z.int()` instead. This API is considered *legacy*; it will never be removed but a better alternative exists. */
int(params?: string | core.$ZodCheckNumberFormatParams): this;
/** @deprecated This is now identical to `.int()`. Only numbers in the safe integer range are accepted. */
safe(params?: string | core.$ZodCheckNumberFormatParams): this;
positive(params?: string | core.$ZodCheckGreaterThanParams): this;
nonnegative(params?: string | core.$ZodCheckGreaterThanParams): this;
negative(params?: string | core.$ZodCheckLessThanParams): this;
nonpositive(params?: string | core.$ZodCheckLessThanParams): this;
multipleOf(value: number, params?: string | core.$ZodCheckMultipleOfParams): this;
/** @deprecated Use `.multipleOf()` instead. */
step(value: number, params?: string | core.$ZodCheckMultipleOfParams): this;
/** @deprecated In v4 and later, z.number() does not allow infinite values by default. This is a no-op. */
finite(params?: unknown): this;
minValue: number | null;
maxValue: number | null;
/** @deprecated Check the `format` property instead. */
isInt: boolean;
/** @deprecated Number schemas no longer accept infinite values, so this always returns `true`. */
isFinite: boolean;
format: string | null;
}
export interface ZodNumber extends _ZodNumber<core.$ZodNumberInternals<number>> {
}
export declare const ZodNumber: core.$constructor<ZodNumber>;
export declare function number(params?: string | core.$ZodNumberParams): ZodNumber;
export interface ZodNumberFormat extends ZodNumber {
_zod: core.$ZodNumberFormatInternals;
}
export declare const ZodNumberFormat: core.$constructor<ZodNumberFormat>;
export interface ZodInt extends ZodNumberFormat {
}
export declare function int(params?: string | core.$ZodCheckNumberFormatParams): ZodInt;
export interface ZodFloat32 extends ZodNumberFormat {
}
export declare function float32(params?: string | core.$ZodCheckNumberFormatParams): ZodFloat32;
export interface ZodFloat64 extends ZodNumberFormat {
}
export declare function float64(params?: string | core.$ZodCheckNumberFormatParams): ZodFloat64;
export interface ZodInt32 extends ZodNumberFormat {
}
export declare function int32(params?: string | core.$ZodCheckNumberFormatParams): ZodInt32;
export interface ZodUInt32 extends ZodNumberFormat {
}
export declare function uint32(params?: string | core.$ZodCheckNumberFormatParams): ZodUInt32;
export interface _ZodBoolean<T extends core.$ZodBooleanInternals = core.$ZodBooleanInternals> extends _ZodType<T> {
}
export interface ZodBoolean extends _ZodBoolean<core.$ZodBooleanInternals<boolean>> {
}
export declare const ZodBoolean: core.$constructor<ZodBoolean>;
export declare function boolean(params?: string | core.$ZodBooleanParams): ZodBoolean;
export interface _ZodBigInt<T extends core.$ZodBigIntInternals = core.$ZodBigIntInternals> extends _ZodType<T> {
gte(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Alias of `.gte()` */
min(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
gt(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
/** Alias of `.lte()` */
lte(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
max(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
lt(value: bigint, params?: string | core.$ZodCheckLessThanParams): this;
positive(params?: string | core.$ZodCheckGreaterThanParams): this;
negative(params?: string | core.$ZodCheckLessThanParams): this;
nonpositive(params?: string | core.$ZodCheckLessThanParams): this;
nonnegative(params?: string | core.$ZodCheckGreaterThanParams): this;
multipleOf(value: bigint, params?: string | core.$ZodCheckMultipleOfParams): this;
minValue: bigint | null;
maxValue: bigint | null;
format: string | null;
}
export interface ZodBigInt extends _ZodBigInt<core.$ZodBigIntInternals<bigint>> {
}
export declare const ZodBigInt: core.$constructor<ZodBigInt>;
export declare function bigint(params?: string | core.$ZodBigIntParams): ZodBigInt;
export interface ZodBigIntFormat extends ZodBigInt {
_zod: core.$ZodBigIntFormatInternals;
}
export declare const ZodBigIntFormat: core.$constructor<ZodBigIntFormat>;
export declare function int64(params?: string | core.$ZodBigIntFormatParams): ZodBigIntFormat;
export declare function uint64(params?: string | core.$ZodBigIntFormatParams): ZodBigIntFormat;
export interface ZodSymbol extends _ZodType<core.$ZodSymbolInternals> {
}
export declare const ZodSymbol: core.$constructor<ZodSymbol>;
export declare function symbol(params?: string | core.$ZodSymbolParams): ZodSymbol;
export interface ZodUndefined extends _ZodType<core.$ZodUndefinedInternals> {
}
export declare const ZodUndefined: core.$constructor<ZodUndefined>;
declare function _undefined(params?: string | core.$ZodUndefinedParams): ZodUndefined;
export { _undefined as undefined };
export interface ZodNull extends _ZodType<core.$ZodNullInternals> {
}
export declare const ZodNull: core.$constructor<ZodNull>;
declare function _null(params?: string | core.$ZodNullParams): ZodNull;
export { _null as null };
export interface ZodAny extends _ZodType<core.$ZodAnyInternals> {
}
export declare const ZodAny: core.$constructor<ZodAny>;
export declare function any(): ZodAny;
export interface ZodUnknown extends _ZodType<core.$ZodUnknownInternals> {
}
export declare const ZodUnknown: core.$constructor<ZodUnknown>;
export declare function unknown(): ZodUnknown;
export interface ZodNever extends _ZodType<core.$ZodNeverInternals> {
}
export declare const ZodNever: core.$constructor<ZodNever>;
export declare function never(params?: string | core.$ZodNeverParams): ZodNever;
export interface ZodVoid extends _ZodType<core.$ZodVoidInternals> {
}
export declare const ZodVoid: core.$constructor<ZodVoid>;
declare function _void(params?: string | core.$ZodVoidParams): ZodVoid;
export { _void as void };
export interface _ZodDate<T extends core.$ZodDateInternals = core.$ZodDateInternals> extends _ZodType<T> {
min(value: number | Date, params?: string | core.$ZodCheckGreaterThanParams): this;
max(value: number | Date, params?: string | core.$ZodCheckLessThanParams): this;
/** @deprecated Not recommended. */
minDate: Date | null;
/** @deprecated Not recommended. */
maxDate: Date | null;
}
export interface ZodDate extends _ZodDate<core.$ZodDateInternals<Date>> {
}
export declare const ZodDate: core.$constructor<ZodDate>;
export declare function date(params?: string | core.$ZodDateParams): ZodDate;
export interface ZodArray<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodArrayInternals<T>>, core.$ZodArray<T> {
element: T;
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
unwrap(): T;
}
export declare const ZodArray: core.$constructor<ZodArray>;
export declare function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T>;
export declare function keyof<T extends ZodObject>(schema: T): ZodLiteral<Exclude<keyof T["_zod"]["output"], symbol>>;
export interface ZodObject<
/** @ts-ignore Cast variance */
out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
shape: Shape;
keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
/** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
catchall<T extends core.SomeType>(schema: T): ZodObject<Shape, core.$catchall<T>>;
/** @deprecated Use `z.looseObject()` or `.loose()` instead. */
passthrough(): ZodObject<Shape, core.$loose>;
/** Consider `z.looseObject(A.shape)` instead */
loose(): ZodObject<Shape, core.$loose>;
/** Consider `z.strictObject(A.shape)` instead */
strict(): ZodObject<Shape, core.$strict>;
/** This is the default behavior. This method call is likely unnecessary. */
strip(): ZodObject<Shape, core.$strip>;
extend<U extends core.$ZodLooseShape & Partial<Record<keyof Shape, core.SomeType>>>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
/**
* @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
*
* ```ts
* const A = z.object({ a: z.string() });
* const B = z.object({ b: z.number() });
*
* const C = z.object({
* ...A.shape,
* ...B.shape
* });
* ```
*/
merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
pick<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
omit<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
partial(): ZodObject<{
[k in keyof Shape]: ZodOptional<Shape[k]>;
}, Config>;
partial<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<{
[k in keyof Shape]: k extends keyof M ? ZodOptional<Shape[k]> : Shape[k];
}, Config>;
required(): ZodObject<{
[k in keyof Shape]: ZodNonOptional<Shape[k]>;
}, Config>;
required<M extends util.Mask<keyof Shape>>(mask: M): ZodObject<{
[k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
}, Config>;
}
export declare const ZodObject: core.$constructor<ZodObject>;
export declare function object<T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>>(shape?: T, params?: string | core.$ZodObjectParams): ZodObject<util.Writeable<T>, core.$strip>;
export declare function strictObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, core.$strict>;
export declare function looseObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, core.$loose>;
export interface ZodUnion<T extends readonly core.SomeType[] = readonly core.$ZodType[]> extends _ZodType<core.$ZodUnionInternals<T>>, core.$ZodUnion<T> {
options: T;
}
export declare const ZodUnion: core.$constructor<ZodUnion>;
export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[] = readonly core.$ZodType[]> extends ZodUnion<Options>, core.$ZodDiscriminatedUnion<Options> {
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
}
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]]>(discriminator: string, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types>;
export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodIntersectionInternals<A, B>>, core.$ZodIntersection<A, B> {
}
export declare const ZodIntersection: core.$constructor<ZodIntersection>;
export declare function intersection<T extends core.SomeType, U extends core.SomeType>(left: T, right: U): ZodIntersection<T, U>;
export interface ZodTuple<T extends util.TupleItems = readonly core.$ZodType[], Rest extends core.SomeType | null = core.$ZodType | null> extends _ZodType<core.$ZodTupleInternals<T, Rest>>, core.$ZodTuple<T, Rest> {
rest<Rest extends core.SomeType = core.$ZodType>(rest: Rest): ZodTuple<T, Rest>;
}
export declare const ZodTuple: core.$constructor<ZodTuple>;
export declare function tuple<T extends readonly [core.SomeType, ...core.SomeType[]]>(items: T, params?: string | core.$ZodTupleParams): ZodTuple<T, null>;
export declare function tuple<T extends readonly [core.SomeType, ...core.SomeType[]], Rest extends core.SomeType>(items: T, rest: Rest, params?: string | core.$ZodTupleParams): ZodTuple<T, Rest>;
export declare function tuple(items: [], params?: string | core.$ZodTupleParams): ZodTuple<[], null>;
export interface ZodRecord<Key extends core.$ZodRecordKey = core.$ZodRecordKey, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodRecordInternals<Key, Value>>, core.$ZodRecord<Key, Value> {
keyType: Key;
valueType: Value;
}
export declare const ZodRecord: core.$constructor<ZodRecord>;
export declare function record<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key, Value>;
export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodRecord<Key & core.$partial, Value>;
export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodMapInternals<Key, Value>>, core.$ZodMap<Key, Value> {
keyType: Key;
valueType: Value;
}
export declare const ZodMap: core.$constructor<ZodMap>;
export declare function map<Key extends core.SomeType, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodMapParams): ZodMap<Key, Value>;
export interface ZodSet<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodSetInternals<T>>, core.$ZodSet<T> {
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
/** */
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
size(size: number, params?: string | core.$ZodCheckSizeEqualsParams): this;
}
export declare const ZodSet: core.$constructor<ZodSet>;
export declare function set<Value extends core.SomeType>(valueType: Value, params?: string | core.$ZodSetParams): ZodSet<Value>;
export interface ZodEnum<
/** @ts-ignore Cast variance */
out T extends util.EnumLike = util.EnumLike> extends _ZodType<core.$ZodEnumInternals<T>>, core.$ZodEnum<T> {
enum: T;
options: Array<T[keyof T]>;
extract<const U extends readonly (keyof T)[]>(values: U, params?: string | core.$ZodEnumParams): ZodEnum<util.Flatten<Pick<T, U[number]>>>;
exclude<const U extends readonly (keyof T)[]>(values: U, params?: string | core.$ZodEnumParams): ZodEnum<util.Flatten<Omit<T, U[number]>>>;
}
export declare const ZodEnum: core.$constructor<ZodEnum>;
declare function _enum<const T extends readonly string[]>(values: T, params?: string | core.$ZodEnumParams): ZodEnum<util.ToEnum<T[number]>>;
declare function _enum<const T extends util.EnumLike>(entries: T, params?: string | core.$ZodEnumParams): ZodEnum<T>;
export { _enum as enum };
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
*
* ```ts
* enum Colors { red, green, blue }
* z.enum(Colors);
* ```
*/
export declare function nativeEnum<T extends util.EnumLike>(entries: T, params?: string | core.$ZodEnumParams): ZodEnum<T>;
export interface ZodLiteral<T extends util.Literal = util.Literal> extends _ZodType<core.$ZodLiteralInternals<T>>, core.$ZodLiteral<T> {
values: Set<T>;
/** @legacy Use `.values` instead. Accessing this property will throw an error if the literal accepts multiple values. */
value: T;
}
export declare const ZodLiteral: core.$constructor<ZodLiteral>;
export declare function literal<const T extends ReadonlyArray<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T[number]>;
export declare function literal<const T extends util.Literal>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T>;
export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile {
min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
max(size: number, params?: string | core.$ZodCheckMaxSizeParams): this;
mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
}
export declare const ZodFile: core.$constructor<ZodFile>;
export declare function file(params?: string | core.$ZodFileParams): ZodFile;
export interface ZodTransform<O = unknown, I = unknown> extends _ZodType<core.$ZodTransformInternals<O, I>>, core.$ZodTransform<O, I> {
}
export declare const ZodTransform: core.$constructor<ZodTransform>;
export declare function transform<I = unknown, O = I>(fn: (input: I, ctx: core.ParsePayload) => O): ZodTransform<Awaited<O>, I>;
export interface ZodOptional<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodOptionalInternals<T>>, core.$ZodOptional<T> {
unwrap(): T;
}
export declare const ZodOptional: core.$constructor<ZodOptional>;
export declare function optional<T extends core.SomeType>(innerType: T): ZodOptional<T>;
export interface ZodNullable<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodNullableInternals<T>>, core.$ZodNullable<T> {
unwrap(): T;
}
export declare const ZodNullable: core.$constructor<ZodNullable>;
export declare function nullable<T extends core.SomeType>(innerType: T): ZodNullable<T>;
export declare function nullish<T extends core.SomeType>(innerType: T): ZodOptional<ZodNullable<T>>;
export interface ZodDefault<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodDefaultInternals<T>>, core.$ZodDefault<T> {
unwrap(): T;
/** @deprecated Use `.unwrap()` instead. */
removeDefault(): T;
}
export declare const ZodDefault: core.$constructor<ZodDefault>;
export declare function _default<T extends core.SomeType>(innerType: T, defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)): ZodDefault<T>;
export interface ZodPrefault<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPrefaultInternals<T>>, core.$ZodPrefault<T> {
unwrap(): T;
}
export declare const ZodPrefault: core.$constructor<ZodPrefault>;
export declare function prefault<T extends core.SomeType>(innerType: T, defaultValue: core.input<T> | (() => core.input<T>)): ZodPrefault<T>;
export interface ZodNonOptional<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodNonOptionalInternals<T>>, core.$ZodNonOptional<T> {
unwrap(): T;
}
export declare const ZodNonOptional: core.$constructor<ZodNonOptional>;
export declare function nonoptional<T extends core.SomeType>(innerType: T, params?: string | core.$ZodNonOptionalParams): ZodNonOptional<T>;
export interface ZodSuccess<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodSuccessInternals<T>>, core.$ZodSuccess<T> {
unwrap(): T;
}
export declare const ZodSuccess: core.$constructor<ZodSuccess>;
export declare function success<T extends core.SomeType>(innerType: T): ZodSuccess<T>;
export interface ZodCatch<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodCatchInternals<T>>, core.$ZodCatch<T> {
unwrap(): T;
/** @deprecated Use `.unwrap()` instead. */
removeCatch(): T;
}
export declare const ZodCatch: core.$constructor<ZodCatch>;
declare function _catch<T extends core.SomeType>(innerType: T, catchValue: core.output<T> | ((ctx: core.$ZodCatchCtx) => core.output<T>)): ZodCatch<T>;
export { _catch as catch };
export interface ZodNaN extends _ZodType<core.$ZodNaNInternals>, core.$ZodNaN {
}
export declare const ZodNaN: core.$constructor<ZodNaN>;
export declare function nan(params?: string | core.$ZodNaNParams): ZodNaN;
export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPipeInternals<A, B>>, core.$ZodPipe<A, B> {
in: A;
out: B;
}
export declare const ZodPipe: core.$constructor<ZodPipe>;
export declare function pipe<const A extends core.SomeType, B extends core.$ZodType<unknown, core.output<A>> = core.$ZodType<unknown, core.output<A>>>(in_: A, out: B | core.$ZodType<unknown, core.output<A>>): ZodPipe<A, B>;
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
}
export declare const ZodReadonly: core.$constructor<ZodReadonly>;
export declare function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T>;
export interface ZodTemplateLiteral<Template extends string = string> extends _ZodType<core.$ZodTemplateLiteralInternals<Template>>, core.$ZodTemplateLiteral<Template> {
}
export declare const ZodTemplateLiteral: core.$constructor<ZodTemplateLiteral>;
export declare function templateLiteral<const Parts extends core.$ZodTemplateLiteralPart[]>(parts: Parts, params?: string | core.$ZodTemplateLiteralParams): ZodTemplateLiteral<core.$PartsToTemplateLiteral<Parts>>;
export interface ZodLazy<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodLazyInternals<T>>, core.$ZodLazy<T> {
unwrap(): T;
}
export declare const ZodLazy: core.$constructor<ZodLazy>;
export declare function lazy<T extends core.SomeType>(getter: () => T): ZodLazy<T>;
export interface ZodPromise<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodPromiseInternals<T>>, core.$ZodPromise<T> {
unwrap(): T;
}
export declare const ZodPromise: core.$constructor<ZodPromise>;
export declare function promise<T extends core.SomeType>(innerType: T): ZodPromise<T>;
export interface ZodCustom<O = unknown, I = unknown> extends _ZodType<core.$ZodCustomInternals<O, I>>, core.$ZodCustom<O, I> {
}
export declare const ZodCustom: core.$constructor<ZodCustom>;
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
export { _instanceof as instanceof };
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodPipe<ZodPipe<ZodString, ZodTransform<boolean, string>>, ZodBoolean>;
type _ZodJSONSchema = ZodUnion<[
ZodString,
ZodNumber,
ZodBoolean,
ZodNull,
ZodArray<ZodJSONSchema>,
ZodRecord<ZodString, ZodJSONSchema>
]>;
type _ZodJSONSchemaInternals = _ZodJSONSchema["_zod"];
export interface ZodJSONSchemaInternals extends _ZodJSONSchemaInternals {
output: util.JSONType;
input: util.JSONType;
}
export interface ZodJSONSchema extends _ZodJSONSchema {
_zod: ZodJSONSchemaInternals;
}
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
+1006
View File
@@ -0,0 +1,1006 @@
import * as core from "../core/index.js";
import { util } from "../core/index.js";
import * as checks from "./checks.js";
import * as iso from "./iso.js";
import * as parse from "./parse.js";
export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
core.$ZodType.init(inst, def);
inst.def = def;
Object.defineProperty(inst, "_def", { value: def });
// base methods
inst.check = (...checks) => {
return inst.clone({
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
],
}
// { parent: true }
);
};
inst.clone = (def, params) => core.clone(inst, def, params);
inst.brand = () => inst;
inst.register = ((reg, meta) => {
reg.add(inst, meta);
return inst;
});
// parsing
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
inst.spa = inst.safeParseAsync;
// refinements
inst.refine = (check, params) => inst.check(refine(check, params));
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
// wrappers
inst.optional = () => optional(inst);
inst.nullable = () => nullable(inst);
inst.nullish = () => optional(nullable(inst));
inst.nonoptional = (params) => nonoptional(inst, params);
inst.array = () => array(inst);
inst.or = (arg) => union([inst, arg]);
inst.and = (arg) => intersection(inst, arg);
inst.transform = (tx) => pipe(inst, transform(tx));
inst.default = (def) => _default(inst, def);
inst.prefault = (def) => prefault(inst, def);
// inst.coalesce = (def, params) => coalesce(inst, def, params);
inst.catch = (params) => _catch(inst, params);
inst.pipe = (target) => pipe(inst, target);
inst.readonly = () => readonly(inst);
// meta
inst.describe = (description) => {
const cl = inst.clone();
core.globalRegistry.add(cl, { description });
return cl;
};
Object.defineProperty(inst, "description", {
get() {
return core.globalRegistry.get(inst)?.description;
},
configurable: true,
});
inst.meta = (...args) => {
if (args.length === 0) {
return core.globalRegistry.get(inst);
}
const cl = inst.clone();
core.globalRegistry.add(cl, args[0]);
return cl;
};
// helpers
inst.isOptional = () => inst.safeParse(undefined).success;
inst.isNullable = () => inst.safeParse(null).success;
return inst;
});
/** @internal */
export const _ZodString = /*@__PURE__*/ core.$constructor("_ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
ZodType.init(inst, def);
const bag = inst._zod.bag;
inst.format = bag.format ?? null;
inst.minLength = bag.minimum ?? null;
inst.maxLength = bag.maximum ?? null;
// validations
inst.regex = (...args) => inst.check(checks.regex(...args));
inst.includes = (...args) => inst.check(checks.includes(...args));
inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
inst.endsWith = (...args) => inst.check(checks.endsWith(...args));
inst.min = (...args) => inst.check(checks.minLength(...args));
inst.max = (...args) => inst.check(checks.maxLength(...args));
inst.length = (...args) => inst.check(checks.length(...args));
inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args));
inst.lowercase = (params) => inst.check(checks.lowercase(params));
inst.uppercase = (params) => inst.check(checks.uppercase(params));
// transforms
inst.trim = () => inst.check(checks.trim());
inst.normalize = (...args) => inst.check(checks.normalize(...args));
inst.toLowerCase = () => inst.check(checks.toLowerCase());
inst.toUpperCase = () => inst.check(checks.toUpperCase());
});
export const ZodString = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
_ZodString.init(inst, def);
inst.email = (params) => inst.check(core._email(ZodEmail, params));
inst.url = (params) => inst.check(core._url(ZodURL, params));
inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params));
inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params));
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params));
inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params));
inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params));
inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params));
inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params));
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params));
inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params));
inst.ulid = (params) => inst.check(core._ulid(ZodULID, params));
inst.base64 = (params) => inst.check(core._base64(ZodBase64, params));
inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params));
inst.xid = (params) => inst.check(core._xid(ZodXID, params));
inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params));
inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params));
inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params));
inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params));
inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params));
inst.e164 = (params) => inst.check(core._e164(ZodE164, params));
// iso
inst.datetime = (params) => inst.check(iso.datetime(params));
inst.date = (params) => inst.check(iso.date(params));
inst.time = (params) => inst.check(iso.time(params));
inst.duration = (params) => inst.check(iso.duration(params));
});
export function string(params) {
return core._string(ZodString, params);
}
export const ZodStringFormat = /*@__PURE__*/ core.$constructor("ZodStringFormat", (inst, def) => {
core.$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
});
export const ZodEmail = /*@__PURE__*/ core.$constructor("ZodEmail", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function email(params) {
return core._email(ZodEmail, params);
}
export const ZodGUID = /*@__PURE__*/ core.$constructor("ZodGUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function guid(params) {
return core._guid(ZodGUID, params);
}
export const ZodUUID = /*@__PURE__*/ core.$constructor("ZodUUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function uuid(params) {
return core._uuid(ZodUUID, params);
}
export function uuidv4(params) {
return core._uuidv4(ZodUUID, params);
}
// ZodUUIDv6
export function uuidv6(params) {
return core._uuidv6(ZodUUID, params);
}
// ZodUUIDv7
export function uuidv7(params) {
return core._uuidv7(ZodUUID, params);
}
export const ZodURL = /*@__PURE__*/ core.$constructor("ZodURL", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function url(params) {
return core._url(ZodURL, params);
}
export const ZodEmoji = /*@__PURE__*/ core.$constructor("ZodEmoji", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function emoji(params) {
return core._emoji(ZodEmoji, params);
}
export const ZodNanoID = /*@__PURE__*/ core.$constructor("ZodNanoID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function nanoid(params) {
return core._nanoid(ZodNanoID, params);
}
export const ZodCUID = /*@__PURE__*/ core.$constructor("ZodCUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cuid(params) {
return core._cuid(ZodCUID, params);
}
export const ZodCUID2 = /*@__PURE__*/ core.$constructor("ZodCUID2", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cuid2(params) {
return core._cuid2(ZodCUID2, params);
}
export const ZodULID = /*@__PURE__*/ core.$constructor("ZodULID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ulid(params) {
return core._ulid(ZodULID, params);
}
export const ZodXID = /*@__PURE__*/ core.$constructor("ZodXID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function xid(params) {
return core._xid(ZodXID, params);
}
export const ZodKSUID = /*@__PURE__*/ core.$constructor("ZodKSUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ksuid(params) {
return core._ksuid(ZodKSUID, params);
}
export const ZodIPv4 = /*@__PURE__*/ core.$constructor("ZodIPv4", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ipv4(params) {
return core._ipv4(ZodIPv4, params);
}
export const ZodIPv6 = /*@__PURE__*/ core.$constructor("ZodIPv6", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ipv6(params) {
return core._ipv6(ZodIPv6, params);
}
export const ZodCIDRv4 = /*@__PURE__*/ core.$constructor("ZodCIDRv4", (inst, def) => {
core.$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cidrv4(params) {
return core._cidrv4(ZodCIDRv4, params);
}
export const ZodCIDRv6 = /*@__PURE__*/ core.$constructor("ZodCIDRv6", (inst, def) => {
core.$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cidrv6(params) {
return core._cidrv6(ZodCIDRv6, params);
}
export const ZodBase64 = /*@__PURE__*/ core.$constructor("ZodBase64", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function base64(params) {
return core._base64(ZodBase64, params);
}
export const ZodBase64URL = /*@__PURE__*/ core.$constructor("ZodBase64URL", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function base64url(params) {
return core._base64url(ZodBase64URL, params);
}
export const ZodE164 = /*@__PURE__*/ core.$constructor("ZodE164", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function e164(params) {
return core._e164(ZodE164, params);
}
export const ZodJWT = /*@__PURE__*/ core.$constructor("ZodJWT", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function jwt(params) {
return core._jwt(ZodJWT, params);
}
export const ZodCustomStringFormat = /*@__PURE__*/ core.$constructor("ZodCustomStringFormat", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCustomStringFormat.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function stringFormat(format, fnOrRegex, _params = {}) {
return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
}
export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
core.$ZodNumber.init(inst, def);
ZodType.init(inst, def);
inst.gt = (value, params) => inst.check(checks.gt(value, params));
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.lt = (value, params) => inst.check(checks.lt(value, params));
inst.lte = (value, params) => inst.check(checks.lte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
inst.int = (params) => inst.check(int(params));
inst.safe = (params) => inst.check(int(params));
inst.positive = (params) => inst.check(checks.gt(0, params));
inst.nonnegative = (params) => inst.check(checks.gte(0, params));
inst.negative = (params) => inst.check(checks.lt(0, params));
inst.nonpositive = (params) => inst.check(checks.lte(0, params));
inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
inst.step = (value, params) => inst.check(checks.multipleOf(value, params));
// inst.finite = (params) => inst.check(core.finite(params));
inst.finite = () => inst;
const bag = inst._zod.bag;
inst.minValue =
Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
inst.maxValue =
Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
inst.isFinite = true;
inst.format = bag.format ?? null;
});
export function number(params) {
return core._number(ZodNumber, params);
}
export const ZodNumberFormat = /*@__PURE__*/ core.$constructor("ZodNumberFormat", (inst, def) => {
core.$ZodNumberFormat.init(inst, def);
ZodNumber.init(inst, def);
});
export function int(params) {
return core._int(ZodNumberFormat, params);
}
export function float32(params) {
return core._float32(ZodNumberFormat, params);
}
export function float64(params) {
return core._float64(ZodNumberFormat, params);
}
export function int32(params) {
return core._int32(ZodNumberFormat, params);
}
export function uint32(params) {
return core._uint32(ZodNumberFormat, params);
}
export const ZodBoolean = /*@__PURE__*/ core.$constructor("ZodBoolean", (inst, def) => {
core.$ZodBoolean.init(inst, def);
ZodType.init(inst, def);
});
export function boolean(params) {
return core._boolean(ZodBoolean, params);
}
export const ZodBigInt = /*@__PURE__*/ core.$constructor("ZodBigInt", (inst, def) => {
core.$ZodBigInt.init(inst, def);
ZodType.init(inst, def);
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.gt = (value, params) => inst.check(checks.gt(value, params));
inst.gte = (value, params) => inst.check(checks.gte(value, params));
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.lt = (value, params) => inst.check(checks.lt(value, params));
inst.lte = (value, params) => inst.check(checks.lte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
inst.positive = (params) => inst.check(checks.gt(BigInt(0), params));
inst.negative = (params) => inst.check(checks.lt(BigInt(0), params));
inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params));
inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params));
inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
const bag = inst._zod.bag;
inst.minValue = bag.minimum ?? null;
inst.maxValue = bag.maximum ?? null;
inst.format = bag.format ?? null;
});
export function bigint(params) {
return core._bigint(ZodBigInt, params);
}
export const ZodBigIntFormat = /*@__PURE__*/ core.$constructor("ZodBigIntFormat", (inst, def) => {
core.$ZodBigIntFormat.init(inst, def);
ZodBigInt.init(inst, def);
});
// int64
export function int64(params) {
return core._int64(ZodBigIntFormat, params);
}
// uint64
export function uint64(params) {
return core._uint64(ZodBigIntFormat, params);
}
export const ZodSymbol = /*@__PURE__*/ core.$constructor("ZodSymbol", (inst, def) => {
core.$ZodSymbol.init(inst, def);
ZodType.init(inst, def);
});
export function symbol(params) {
return core._symbol(ZodSymbol, params);
}
export const ZodUndefined = /*@__PURE__*/ core.$constructor("ZodUndefined", (inst, def) => {
core.$ZodUndefined.init(inst, def);
ZodType.init(inst, def);
});
function _undefined(params) {
return core._undefined(ZodUndefined, params);
}
export { _undefined as undefined };
export const ZodNull = /*@__PURE__*/ core.$constructor("ZodNull", (inst, def) => {
core.$ZodNull.init(inst, def);
ZodType.init(inst, def);
});
function _null(params) {
return core._null(ZodNull, params);
}
export { _null as null };
export const ZodAny = /*@__PURE__*/ core.$constructor("ZodAny", (inst, def) => {
core.$ZodAny.init(inst, def);
ZodType.init(inst, def);
});
export function any() {
return core._any(ZodAny);
}
export const ZodUnknown = /*@__PURE__*/ core.$constructor("ZodUnknown", (inst, def) => {
core.$ZodUnknown.init(inst, def);
ZodType.init(inst, def);
});
export function unknown() {
return core._unknown(ZodUnknown);
}
export const ZodNever = /*@__PURE__*/ core.$constructor("ZodNever", (inst, def) => {
core.$ZodNever.init(inst, def);
ZodType.init(inst, def);
});
export function never(params) {
return core._never(ZodNever, params);
}
export const ZodVoid = /*@__PURE__*/ core.$constructor("ZodVoid", (inst, def) => {
core.$ZodVoid.init(inst, def);
ZodType.init(inst, def);
});
function _void(params) {
return core._void(ZodVoid, params);
}
export { _void as void };
export const ZodDate = /*@__PURE__*/ core.$constructor("ZodDate", (inst, def) => {
core.$ZodDate.init(inst, def);
ZodType.init(inst, def);
inst.min = (value, params) => inst.check(checks.gte(value, params));
inst.max = (value, params) => inst.check(checks.lte(value, params));
const c = inst._zod.bag;
inst.minDate = c.minimum ? new Date(c.minimum) : null;
inst.maxDate = c.maximum ? new Date(c.maximum) : null;
});
export function date(params) {
return core._date(ZodDate, params);
}
export const ZodArray = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) => {
core.$ZodArray.init(inst, def);
ZodType.init(inst, def);
inst.element = def.element;
inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
inst.nonempty = (params) => inst.check(checks.minLength(1, params));
inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
inst.length = (len, params) => inst.check(checks.length(len, params));
inst.unwrap = () => inst.element;
});
export function array(element, params) {
return core._array(ZodArray, element, params);
}
// .keyof
export function keyof(schema) {
const shape = schema._zod.def.shape;
return literal(Object.keys(shape));
}
export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
core.$ZodObject.init(inst, def);
ZodType.init(inst, def);
util.defineLazy(inst, "shape", () => def.shape);
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
// inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
inst.extend = (incoming) => {
return util.extend(inst, incoming);
};
inst.merge = (other) => util.merge(inst, other);
inst.pick = (mask) => util.pick(inst, mask);
inst.omit = (mask) => util.omit(inst, mask);
inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]);
inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]);
});
export function object(shape, params) {
const def = {
type: "object",
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
...util.normalizeParams(params),
};
return new ZodObject(def);
}
// strictObject
export function strictObject(shape, params) {
return new ZodObject({
type: "object",
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
catchall: never(),
...util.normalizeParams(params),
});
}
// looseObject
export function looseObject(shape, params) {
return new ZodObject({
type: "object",
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
catchall: unknown(),
...util.normalizeParams(params),
});
}
export const ZodUnion = /*@__PURE__*/ core.$constructor("ZodUnion", (inst, def) => {
core.$ZodUnion.init(inst, def);
ZodType.init(inst, def);
inst.options = def.options;
});
export function union(options, params) {
return new ZodUnion({
type: "union",
options: options,
...util.normalizeParams(params),
});
}
export const ZodDiscriminatedUnion = /*@__PURE__*/ core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
ZodUnion.init(inst, def);
core.$ZodDiscriminatedUnion.init(inst, def);
});
export function discriminatedUnion(discriminator, options, params) {
// const [options, params] = args;
return new ZodDiscriminatedUnion({
type: "union",
options,
discriminator,
...util.normalizeParams(params),
});
}
export const ZodIntersection = /*@__PURE__*/ core.$constructor("ZodIntersection", (inst, def) => {
core.$ZodIntersection.init(inst, def);
ZodType.init(inst, def);
});
export function intersection(left, right) {
return new ZodIntersection({
type: "intersection",
left: left,
right: right,
});
}
export const ZodTuple = /*@__PURE__*/ core.$constructor("ZodTuple", (inst, def) => {
core.$ZodTuple.init(inst, def);
ZodType.init(inst, def);
inst.rest = (rest) => inst.clone({
...inst._zod.def,
rest: rest,
});
});
export function tuple(items, _paramsOrRest, _params) {
const hasRest = _paramsOrRest instanceof core.$ZodType;
const params = hasRest ? _params : _paramsOrRest;
const rest = hasRest ? _paramsOrRest : null;
return new ZodTuple({
type: "tuple",
items: items,
rest,
...util.normalizeParams(params),
});
}
export const ZodRecord = /*@__PURE__*/ core.$constructor("ZodRecord", (inst, def) => {
core.$ZodRecord.init(inst, def);
ZodType.init(inst, def);
inst.keyType = def.keyType;
inst.valueType = def.valueType;
});
export function record(keyType, valueType, params) {
return new ZodRecord({
type: "record",
keyType,
valueType: valueType,
...util.normalizeParams(params),
});
}
// type alksjf = core.output<core.$ZodRecordKey>;
export function partialRecord(keyType, valueType, params) {
return new ZodRecord({
type: "record",
keyType: union([keyType, never()]),
valueType: valueType,
...util.normalizeParams(params),
});
}
export const ZodMap = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => {
core.$ZodMap.init(inst, def);
ZodType.init(inst, def);
inst.keyType = def.keyType;
inst.valueType = def.valueType;
});
export function map(keyType, valueType, params) {
return new ZodMap({
type: "map",
keyType: keyType,
valueType: valueType,
...util.normalizeParams(params),
});
}
export const ZodSet = /*@__PURE__*/ core.$constructor("ZodSet", (inst, def) => {
core.$ZodSet.init(inst, def);
ZodType.init(inst, def);
inst.min = (...args) => inst.check(core._minSize(...args));
inst.nonempty = (params) => inst.check(core._minSize(1, params));
inst.max = (...args) => inst.check(core._maxSize(...args));
inst.size = (...args) => inst.check(core._size(...args));
});
export function set(valueType, params) {
return new ZodSet({
type: "set",
valueType: valueType,
...util.normalizeParams(params),
});
}
export const ZodEnum = /*@__PURE__*/ core.$constructor("ZodEnum", (inst, def) => {
core.$ZodEnum.init(inst, def);
ZodType.init(inst, def);
inst.enum = def.entries;
inst.options = Object.values(def.entries);
const keys = new Set(Object.keys(def.entries));
inst.extract = (values, params) => {
const newEntries = {};
for (const value of values) {
if (keys.has(value)) {
newEntries[value] = def.entries[value];
}
else
throw new Error(`Key ${value} not found in enum`);
}
return new ZodEnum({
...def,
checks: [],
...util.normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (values, params) => {
const newEntries = { ...def.entries };
for (const value of values) {
if (keys.has(value)) {
delete newEntries[value];
}
else
throw new Error(`Key ${value} not found in enum`);
}
return new ZodEnum({
...def,
checks: [],
...util.normalizeParams(params),
entries: newEntries,
});
};
});
function _enum(values, params) {
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
return new ZodEnum({
type: "enum",
entries,
...util.normalizeParams(params),
});
}
export { _enum as enum };
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
*
* ```ts
* enum Colors { red, green, blue }
* z.enum(Colors);
* ```
*/
export function nativeEnum(entries, params) {
return new ZodEnum({
type: "enum",
entries,
...util.normalizeParams(params),
});
}
export const ZodLiteral = /*@__PURE__*/ core.$constructor("ZodLiteral", (inst, def) => {
core.$ZodLiteral.init(inst, def);
ZodType.init(inst, def);
inst.values = new Set(def.values);
Object.defineProperty(inst, "value", {
get() {
if (def.values.length > 1) {
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
}
return def.values[0];
},
});
});
export function literal(value, params) {
return new ZodLiteral({
type: "literal",
values: Array.isArray(value) ? value : [value],
...util.normalizeParams(params),
});
}
export const ZodFile = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) => {
core.$ZodFile.init(inst, def);
ZodType.init(inst, def);
inst.min = (size, params) => inst.check(core._minSize(size, params));
inst.max = (size, params) => inst.check(core._maxSize(size, params));
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
});
export function file(params) {
return core._file(ZodFile, params);
}
export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (inst, def) => {
core.$ZodTransform.init(inst, def);
ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
payload.addIssue = (issue) => {
if (typeof issue === "string") {
payload.issues.push(util.issue(issue, payload.value, def));
}
else {
// for Zod 3 backwards compatibility
const _issue = issue;
if (_issue.fatal)
_issue.continue = false;
_issue.code ?? (_issue.code = "custom");
_issue.input ?? (_issue.input = payload.value);
_issue.inst ?? (_issue.inst = inst);
_issue.continue ?? (_issue.continue = true);
payload.issues.push(util.issue(_issue));
}
};
const output = def.transform(payload.value, payload);
if (output instanceof Promise) {
return output.then((output) => {
payload.value = output;
return payload;
});
}
payload.value = output;
return payload;
};
});
export function transform(fn) {
return new ZodTransform({
type: "transform",
transform: fn,
});
}
export const ZodOptional = /*@__PURE__*/ core.$constructor("ZodOptional", (inst, def) => {
core.$ZodOptional.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function optional(innerType) {
return new ZodOptional({
type: "optional",
innerType: innerType,
});
}
export const ZodNullable = /*@__PURE__*/ core.$constructor("ZodNullable", (inst, def) => {
core.$ZodNullable.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function nullable(innerType) {
return new ZodNullable({
type: "nullable",
innerType: innerType,
});
}
// nullish
export function nullish(innerType) {
return optional(nullable(innerType));
}
export const ZodDefault = /*@__PURE__*/ core.$constructor("ZodDefault", (inst, def) => {
core.$ZodDefault.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
});
export function _default(innerType, defaultValue) {
return new ZodDefault({
type: "default",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
},
});
}
export const ZodPrefault = /*@__PURE__*/ core.$constructor("ZodPrefault", (inst, def) => {
core.$ZodPrefault.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function prefault(innerType, defaultValue) {
return new ZodPrefault({
type: "prefault",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
},
});
}
export const ZodNonOptional = /*@__PURE__*/ core.$constructor("ZodNonOptional", (inst, def) => {
core.$ZodNonOptional.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function nonoptional(innerType, params) {
return new ZodNonOptional({
type: "nonoptional",
innerType: innerType,
...util.normalizeParams(params),
});
}
export const ZodSuccess = /*@__PURE__*/ core.$constructor("ZodSuccess", (inst, def) => {
core.$ZodSuccess.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function success(innerType) {
return new ZodSuccess({
type: "success",
innerType: innerType,
});
}
export const ZodCatch = /*@__PURE__*/ core.$constructor("ZodCatch", (inst, def) => {
core.$ZodCatch.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
});
function _catch(innerType, catchValue) {
return new ZodCatch({
type: "catch",
innerType: innerType,
catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
});
}
export { _catch as catch };
export const ZodNaN = /*@__PURE__*/ core.$constructor("ZodNaN", (inst, def) => {
core.$ZodNaN.init(inst, def);
ZodType.init(inst, def);
});
export function nan(params) {
return core._nan(ZodNaN, params);
}
export const ZodPipe = /*@__PURE__*/ core.$constructor("ZodPipe", (inst, def) => {
core.$ZodPipe.init(inst, def);
ZodType.init(inst, def);
inst.in = def.in;
inst.out = def.out;
});
export function pipe(in_, out) {
return new ZodPipe({
type: "pipe",
in: in_,
out: out,
// ...util.normalizeParams(params),
});
}
export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
core.$ZodReadonly.init(inst, def);
ZodType.init(inst, def);
});
export function readonly(innerType) {
return new ZodReadonly({
type: "readonly",
innerType: innerType,
});
}
export const ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("ZodTemplateLiteral", (inst, def) => {
core.$ZodTemplateLiteral.init(inst, def);
ZodType.init(inst, def);
});
export function templateLiteral(parts, params) {
return new ZodTemplateLiteral({
type: "template_literal",
parts,
...util.normalizeParams(params),
});
}
export const ZodLazy = /*@__PURE__*/ core.$constructor("ZodLazy", (inst, def) => {
core.$ZodLazy.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.getter();
});
export function lazy(getter) {
return new ZodLazy({
type: "lazy",
getter: getter,
});
}
export const ZodPromise = /*@__PURE__*/ core.$constructor("ZodPromise", (inst, def) => {
core.$ZodPromise.init(inst, def);
ZodType.init(inst, def);
inst.unwrap = () => inst._zod.def.innerType;
});
export function promise(innerType) {
return new ZodPromise({
type: "promise",
innerType: innerType,
});
}
export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
core.$ZodCustom.init(inst, def);
ZodType.init(inst, def);
});
// custom checks
export function check(fn) {
const ch = new core.$ZodCheck({
check: "custom",
// ...util.normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
export function custom(fn, _params) {
return core._custom(ZodCustom, fn ?? (() => true), _params);
}
export function refine(fn, _params = {}) {
return core._refine(ZodCustom, fn, _params);
}
// superRefine
export function superRefine(fn) {
const ch = check((payload) => {
payload.addIssue = (issue) => {
if (typeof issue === "string") {
payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
}
else {
// for Zod 3 backwards compatibility
const _issue = issue;
if (_issue.fatal)
_issue.continue = false;
_issue.code ?? (_issue.code = "custom");
_issue.input ?? (_issue.input = payload.value);
_issue.inst ?? (_issue.inst = ch);
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
payload.issues.push(util.issue(_issue));
}
};
return fn(payload.value, payload);
});
return ch;
}
function _instanceof(cls, params = {
error: `Input not instance of ${cls.name}`,
}) {
const inst = new ZodCustom({
type: "custom",
check: "custom",
fn: (data) => data instanceof cls,
abort: true,
...util.normalizeParams(params),
});
inst._zod.bag.Class = cls;
return inst;
}
export { _instanceof as instanceof };
// stringbool
export const stringbool = (...args) => core._stringbool({
Pipe: ZodPipe,
Boolean: ZodBoolean,
String: ZodString,
Transform: ZodTransform,
}, ...args);
export function json(params) {
const jsonSchema = lazy(() => {
return union([string(params), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
});
return jsonSchema;
}
// preprocess
// /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
export function preprocess(fn, schema) {
return pipe(transform(fn), schema);
}