import type { $ZodCheck, $ZodStringFormats } from "./checks.js";
import { $constructor } from "./core.js";
import type { $ZodType } from "./schemas.js";
import type { StandardSchemaV1 } from "./standard-schema.js";
import * as util from "./util.js";
///////////////////////////
//// base type ////
///////////////////////////
export interface $ZodIssueBase {
readonly code?: string;
readonly input?: unknown;
readonly path: PropertyKey[];
readonly message: string;
}
////////////////////////////////
//// issue subtypes ////
////////////////////////////////
export type $ZodInvalidTypeExpected =
| "string"
| "number"
| "int"
| "boolean"
| "bigint"
| "symbol"
| "undefined"
| "null"
| "never"
| "void"
| "date"
| "array"
| "object"
| "tuple"
| "record"
| "map"
| "set"
| "file"
| "nonoptional"
| "nan"
| "function"
| (string & {}); // class names for instanceof
export interface $ZodIssueInvalidType extends $ZodIssueBase {
readonly code: "invalid_type";
readonly expected: $ZodInvalidTypeExpected;
readonly input?: Input;
}
export interface $ZodIssueTooBig extends $ZodIssueBase {
readonly code: "too_big";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
readonly maximum: number | bigint;
readonly inclusive?: boolean;
readonly exact?: boolean;
readonly input?: Input;
}
export interface $ZodIssueTooSmall extends $ZodIssueBase {
readonly code: "too_small";
readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {});
readonly minimum: number | bigint;
/** True if the allowable range includes the minimum */
readonly inclusive?: boolean;
/** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */
readonly exact?: boolean;
readonly input?: Input;
}
export interface $ZodIssueInvalidStringFormat extends $ZodIssueBase {
readonly code: "invalid_format";
readonly format: $ZodStringFormats | (string & {});
readonly pattern?: string;
readonly input?: string;
}
export interface $ZodIssueNotMultipleOf extends $ZodIssueBase {
readonly code: "not_multiple_of";
readonly divisor: number;
readonly input?: Input;
}
export interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase {
readonly code: "unrecognized_keys";
readonly keys: string[];
readonly input?: Record;
}
interface $ZodIssueInvalidUnionNoMatch extends $ZodIssueBase {
readonly code: "invalid_union";
readonly errors: $ZodIssue[][];
readonly input?: unknown;
readonly discriminator?: string | undefined;
readonly options?: util.Primitive[];
readonly inclusive?: true;
}
interface $ZodIssueInvalidUnionMultipleMatch extends $ZodIssueBase {
readonly code: "invalid_union";
readonly errors: [];
readonly input?: unknown;
readonly discriminator?: string | undefined;
readonly inclusive: false;
/** Indices of the options that matched */
readonly matches: number[];
}
export type $ZodIssueInvalidUnion = $ZodIssueInvalidUnionNoMatch | $ZodIssueInvalidUnionMultipleMatch;
export interface $ZodIssueInvalidKey extends $ZodIssueBase {
readonly code: "invalid_key";
readonly origin: "map" | "record";
readonly issues: $ZodIssue[];
readonly input?: Input;
}
export interface $ZodIssueInvalidElement extends $ZodIssueBase {
readonly code: "invalid_element";
readonly origin: "map" | "set";
readonly key: unknown;
readonly issues: $ZodIssue[];
readonly input?: Input;
}
export interface $ZodIssueInvalidValue extends $ZodIssueBase {
readonly code: "invalid_value";
readonly values: util.Primitive[];
readonly input?: Input;
}
export interface $ZodIssueCustom extends $ZodIssueBase {
readonly code: "custom";
readonly params?: Record | undefined;
readonly input?: unknown;
}
////////////////////////////////////////////
//// first-party string formats ////
////////////////////////////////////////////
export interface $ZodIssueStringCommonFormats extends $ZodIssueInvalidStringFormat {
format: Exclude<$ZodStringFormats, "regex" | "jwt" | "starts_with" | "ends_with" | "includes">;
}
export interface $ZodIssueStringInvalidRegex extends $ZodIssueInvalidStringFormat {
format: "regex";
pattern: string;
}
export interface $ZodIssueStringInvalidJWT extends $ZodIssueInvalidStringFormat {
format: "jwt";
algorithm?: string;
}
export interface $ZodIssueStringStartsWith extends $ZodIssueInvalidStringFormat {
format: "starts_with";
prefix: string;
}
export interface $ZodIssueStringEndsWith extends $ZodIssueInvalidStringFormat {
format: "ends_with";
suffix: string;
}
export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
format: "includes";
includes: string;
}
export type $ZodStringFormatIssues =
| $ZodIssueStringCommonFormats
| $ZodIssueStringInvalidRegex
| $ZodIssueStringInvalidJWT
| $ZodIssueStringStartsWith
| $ZodIssueStringEndsWith
| $ZodIssueStringIncludes;
////////////////////////
//// utils /////
////////////////////////
export type $ZodIssue =
| $ZodIssueInvalidType
| $ZodIssueTooBig
| $ZodIssueTooSmall
| $ZodIssueInvalidStringFormat
| $ZodIssueNotMultipleOf
| $ZodIssueUnrecognizedKeys
| $ZodIssueInvalidUnion
| $ZodIssueInvalidKey
| $ZodIssueInvalidElement
| $ZodIssueInvalidValue
| $ZodIssueCustom;
export type $ZodIssueCode = $ZodIssue["code"];
export type $ZodInternalIssue = T extends any ? RawIssue : never;
type RawIssue = T extends any
? util.Flatten<
util.MakePartial & {
/** The input data */
readonly input: unknown;
/** The schema or check that originated this issue. */
readonly inst?: $ZodType | $ZodCheck;
/** The schema that owns the issue. Equal to `inst` when a schema originated the issue, and the schema the check was attached to when a check did. */
readonly schema?: $ZodType | undefined;
/** If `true`, Zod will continue executing checks/refinements after this issue. */
readonly continue?: boolean | undefined;
} & Record
>
: never;
export type $ZodRawIssue = $ZodInternalIssue;
export interface $ZodErrorMap {
// biome-ignore lint/style/useShorthandFunctionType: interface form is public API
(issue: $ZodRawIssue): { message: string } | string | undefined | null;
}
//////////////////////// ERROR CLASS ////////////////////////
// const ZOD_ERROR: symbol = Symbol.for("{{zod.error}}");
export interface $ZodError extends Error {
type: T;
issues: $ZodIssue[];
_zod: {
output: T;
def: $ZodIssue[];
};
stack?: string;
name: string;
}
/* Computing the message eagerly is expensive (pretty-printed JSON of all
* issues), so defer it until first read. The accessor functions and
* descriptors are shared across instances to keep error construction
* cheap; the computed message is cached on the internals object. The
* setter preserves plain assignment semantics for consumers that
* overwrite `message`. */
function _getMessage(this: $ZodError): string {
const internals = this._zod as { def: $ZodIssue[]; message?: string };
internals.message ??= JSON.stringify(internals.def, util.jsonStringifyReplacer, 2);
return internals.message;
}
function _setMessage(this: $ZodError, value: string): void {
(this._zod as { message?: string }).message = value;
}
const _messageDesc: PropertyDescriptor = {
get: _getMessage,
set: _setMessage,
enumerable: true,
configurable: true,
};
const _issuesDesc: PropertyDescriptor = { value: undefined, enumerable: false };
/* Prototypes that already carry the lazy `toString`. Seeded with the
* intrinsics so that `init` on a foreign object — it accepts any object —
* can never install an accessor onto a prototype we do not own. */
const _installedToString = /* @__PURE__ */ new WeakSet