schemas/libraries/zod/mini/download_compiled/index/unminified.js
schemas/libraries/zod/mini/download_compiled/index/unminified.js
schemas/libraries/zod/mini/download_compiled/index/unminified.js
schemas/libraries/zod/mini/download_compiled/index/unminified.js
function toZod() {
return (schema) => schema;
}
function getEnumValues(entries) {
const numericValues = Object.values(
entries,
).filter(
(v) => typeof v === "number",
);
return Object.entries(entries)
.filter(
([k, _]) =>
numericValues.indexOf(+k) ===
-1,
)
.map(([_, v]) => v);
}
function jsonStringifyReplacer(
_,
value,
) {
if (typeof value === "bigint")
return value.toString();
return value;
}
var Cached = class {
constructor(getter) {
this._getter = getter;
this._value = void 0;
}
get value() {
const getter = this._getter;
if (getter !== void 0) {
this._value = getter();
this._getter = void 0;
}
return this._value;
}
};
function cached(getter) {
return new Cached(getter);
}
function nullish(input) {
return (
input === null || input === void 0
);
}
function cleanRegex(source) {
const start = source.startsWith("^")
? 1
: 0;
const end = source.endsWith("$")
? source.length - 1
: source.length;
return source.slice(start, end);
}
function assignProp(
target,
prop,
value,
) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
const captureStackTrace =
"captureStackTrace" in Error
? Error.captureStackTrace
: (..._args) => {};
function isObject(data) {
return (
typeof data === "object" &&
data !== null &&
!Array.isArray(data)
);
}
const propertyKeyTypes =
new Set([
"string",
"number",
"symbol",
]);
function escapeRegex(str) {
return str.replace(
/[.*+?^${}()|[\]\\]/g,
"\\$&",
);
}
function clone(inst, def, params) {
const cl = new inst._zod.constr(
def ?? inst._zod.def,
);
if (!def || params?.parent)
cl._zod.parent = inst;
return cl;
}
function normalizeParams(_params) {
const params = _params;
if (!params) return {};
if (typeof params === "string")
return { error: () => params };
if (params?.message !== void 0) {
if (params?.error !== void 0)
throw new Error(
"Cannot specify both `message` and `error` params",
);
params.error = params.message;
}
delete params.message;
if (typeof params.error === "string")
return {
...params,
error: () => params.error,
};
return params;
}
function optionalKeys(shape) {
return Object.keys(shape).filter(
(k) => {
return (
shape[k]._zod.optin !==
void 0 &&
shape[k]._zod.optout ===
"optional"
);
},
);
}
function aborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (
let i = startIndex;
i < x.issues.length;
i++
)
if (x.issues[i]?.continue !== true)
return true;
return false;
}
function explicitlyAborted(
x,
startIndex = 0,
) {
if (x.aborted === true) return true;
for (
let i = startIndex;
i < x.issues.length;
i++
)
if (x.issues[i]?.continue === false)
return true;
return false;
}
function prefixIssues(path, issues) {
return issues.map((iss) => {
var _a;
(_a = iss).path ?? (_a.path = []);
iss.path.unshift(path);
return iss;
});
}
function unwrapMessage(message) {
return typeof message === "string"
? message
: message?.message;
}
function sizeCaps(defChecks) {
const caps = [];
for (const ch of defChecks ?? []) {
const d = ch._zod.def;
if (
!/_(length|size)$|_equals$/.test(
d.check,
)
)
break;
const max =
d.maximum ?? d.length ?? d.size;
if (max >= 0) caps.push([max, ch]);
}
return caps;
}
function attachSchema(
issues,
start,
inst,
) {
var _a;
for (
let i = start;
i < issues.length;
i++
)
(_a = issues[i]).schema ??
(_a.schema = inst);
}
function finalizeIssue(
iss,
ctx,
config,
) {
var _a;
const traits = iss.inst?._zod?.traits;
if (traits?.has("$ZodType")) {
if (traits.has("$ZodCheck"))
(_a = iss).schema ??
(_a.schema = iss.inst);
else iss.schema = iss.inst;
}
const schemaError =
iss.schema !== iss.inst
? iss.schema?._zod.def?.error
: void 0;
const message = iss.message
? iss.message
: (unwrapMessage(
iss.inst?._zod.def?.error?.(
iss,
),
) ??
unwrapMessage(
schemaError?.(iss),
) ??
unwrapMessage(
ctx?.error?.(iss),
) ??
unwrapMessage(
config.customError?.(iss),
) ??
unwrapMessage(
config.localeError?.(iss),
) ??
"Invalid input");
const full = {};
for (const k of Object.keys(iss)) {
if (
k === "inst" ||
k === "schema" ||
k === "continue" ||
k === "input" ||
k === "__proto__"
)
continue;
full[k] = iss[k];
}
full.path ?? (full.path = []);
full.message = message;
if (ctx?.reportInput)
full.input = iss.input;
return full;
}
const highSurrogate = /[\uD800-\uDBFF]/;
function codePointLength(str) {
const units = str.length;
if (!highSurrogate.test(str))
return units;
let count = units;
for (let i = 0; i < units - 1; i++)
if (
(str.charCodeAt(i) & 64512) ===
55296 &&
(str.charCodeAt(i + 1) &
64512) ===
56320
) {
count--;
i++;
}
return count;
}
function getLengthableOrigin(input) {
if (Array.isArray(input))
return "array";
if (typeof input === "string")
return "string";
return "unknown";
}
function members(proto, table) {
for (const key in table) {
const desc =
Object.getOwnPropertyDescriptor(
table,
key,
);
if (desc.get)
Object.defineProperty(
proto,
key,
{
...desc,
enumerable: false,
},
);
else
defineBound(
proto,
key,
desc.value,
);
}
}
function own(
inst,
key,
value,
enumerable = true,
) {
Object.defineProperty(inst, key, {
configurable: true,
writable: true,
enumerable,
value,
});
return value;
}
function hide(inst, key, value) {
return own(inst, key, value, false);
}
function defineBound(proto, key, fn) {
Object.defineProperty(proto, key, {
configurable: true,
get() {
return this == null
? fn
: own(this, key, fn.bind(this));
},
set(value) {
own(this, key, value);
},
});
}
function claim(inst, sentinel) {
const proto =
Object.getPrototypeOf(inst);
return sentinel in proto
? void 0
: proto;
}
let installing;
let broke = false;
const breaker = {
configurable: true,
get() {
broke = true;
},
};
function defineLazyInternal(
inst,
key,
compute,
) {
const proto = Object.getPrototypeOf(
inst._zod,
);
if (
key in proto &&
installing !== inst._zod
) {
installing = void 0;
return;
}
installing = inst._zod;
Object.defineProperty(proto, key, {
configurable: true,
get() {
Object.defineProperty(
this,
key,
breaker,
);
const outer = broke;
broke = false;
try {
const value = compute(this);
if (broke) delete this[key];
else
Object.defineProperty(
this,
key,
{
configurable: true,
writable: true,
value,
},
);
broke = broke || outer;
return value;
} catch (err) {
delete this[key];
broke = broke || outer;
throw err;
}
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
},
});
}
function installLazyProp(
inst,
key,
make,
enumerable,
) {
const proto = claim(inst, key);
if (!proto) return;
Object.defineProperty(proto, key, {
configurable: true,
get() {
const desc = {
configurable: true,
writable: true,
enumerable,
value: void 0,
};
Object.defineProperty(
this,
key,
desc,
);
desc.value = make(this);
Object.defineProperty(
this,
key,
desc,
);
return desc.value;
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable,
value,
});
},
});
}
var _a;
const _zodDesc = {
value: void 0,
enumerable: false,
};
let _E =
"captureStackTrace" in Error
? Error
: null;
function newError(Definition) {
const E = _E;
if (E) {
const saved = E.stackTraceLimit;
if (typeof saved === "number") {
try {
E.stackTraceLimit = 0;
} catch {
_E = null;
return new Definition();
}
try {
return new Definition();
} finally {
E.stackTraceLimit = saved;
}
}
}
return new Definition();
}
function $constructor(
name,
initializer,
proto,
params,
) {
const zodProto = {};
function Internals(def) {
this.def = def;
this.constr = _;
this.traits =
new Set();
}
Internals.prototype = zodProto;
const protoMembers = proto;
const initialized =
protoMembers &&
new WeakSet();
function init(inst, def) {
if (!inst._zod) {
_zodDesc.value = new Internals(
def,
);
try {
Object.defineProperty(
inst,
"_zod",
_zodDesc,
);
} finally {
_zodDesc.value = void 0;
}
} else if (
inst._zod.traits.has(name)
)
return;
inst._zod.traits.add(name);
initializer(inst, def);
if (initialized) {
const own =
Object.getPrototypeOf(inst);
const ctorProto =
inst._zod.constr.prototype;
let up = own;
while (up && up !== ctorProto)
up = Object.getPrototypeOf(up);
const target = up ?? own;
if (!initialized.has(target)) {
initialized.add(target);
members(target, protoMembers);
}
}
const proto = _.prototype;
for (const k in proto) {
if (
!Object.prototype.hasOwnProperty.call(
proto,
k,
)
)
continue;
if (!(k in inst))
inst[k] = proto[k].bind(inst);
}
}
const Parent =
params?.Parent ?? Object;
class Definition extends Parent {}
Object.defineProperty(
Definition,
"name",
{ value: name },
);
function _(def) {
const inst = params?.Parent
? newError(Definition)
: this;
init(inst, def);
const deferred = inst._zod.deferred;
if (deferred) {
for (const fn of deferred) fn();
inst._zod.deferred = void 0;
}
const pp =
globalThis.__zod_globalConfig
?.postProcessor;
if (pp) pp(inst);
return inst;
}
Object.defineProperty(_, "init", {
value: init,
});
Object.defineProperty(
_,
Symbol.hasInstance,
{
value: (inst) => {
if (
params?.Parent &&
inst instanceof params.Parent
)
return true;
return inst?._zod?.traits?.has(
name,
);
},
},
);
Object.defineProperty(_, "name", {
value: name,
});
return _;
}
var $ZodAsyncError = class extends Error {
constructor() {
super(
`Encountered Promise during synchronous parse. Use .parseAsync() instead.`,
);
}
};
(_a = globalThis).__zod_globalConfig ??
(_a.__zod_globalConfig = {});
const globalConfig =
globalThis.__zod_globalConfig;
function config(newConfig) {
if (newConfig)
Object.assign(
globalConfig,
newConfig,
);
return globalConfig;
}
function _getMessage() {
const internals = this._zod;
internals.message ??
(internals.message = JSON.stringify(
internals.def,
jsonStringifyReplacer,
2,
));
return internals.message;
}
function _setMessage(value) {
this._zod.message = value;
}
const _messageDesc = {
get: _getMessage,
set: _setMessage,
enumerable: true,
configurable: true,
};
const _issuesDesc = {
value: void 0,
enumerable: false,
};
const _installedToString =
new WeakSet([
Object.prototype,
Error.prototype,
]);
const initializer = (inst, def) => {
inst.name = "$ZodError";
_issuesDesc.value = def;
Object.defineProperty(
inst,
"issues",
_issuesDesc,
);
_issuesDesc.value = void 0;
Object.defineProperty(
inst,
"message",
_messageDesc,
);
const proto =
Object.getPrototypeOf(inst);
if (!_installedToString.has(proto)) {
_installedToString.add(proto);
Object.defineProperty(
proto,
"toString",
{
configurable: true,
enumerable: false,
get() {
const value = () =>
this.message;
Object.defineProperty(
this,
"toString",
{
value,
configurable: true,
writable: true,
},
);
return value;
},
set(value) {
Object.defineProperty(
this,
"toString",
{
value,
configurable: true,
writable: true,
},
);
},
},
);
}
};
const $ZodRealError =
$constructor(
"$ZodError",
initializer,
void 0,
{ Parent: Error },
);
const _parse = (_Err) => {
const fn = (
schema,
value,
_ctx,
_params,
) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
throw new $ZodAsyncError();
if (result.issues.length) {
const e = new (
_params?.Err ?? _Err
)(
result.issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
);
captureStackTrace(
e,
_params?.callee ?? fn,
);
throw e;
}
return result.value;
};
return fn;
};
const parse = _parse(
$ZodRealError,
);
const _parseAsync = (_Err) => {
const fn = async (
schema,
value,
_ctx,
params,
) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
result = await result;
if (result.issues.length) {
const e = new (
params?.Err ?? _Err
)(
result.issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
);
captureStackTrace(
e,
params?.callee ?? fn,
);
throw e;
}
return result.value;
};
return fn;
};
const parseAsync =
_parseAsync(
$ZodRealError,
);
const _safeParse =
(_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
throw new $ZodAsyncError();
return result.issues.length
? failure(
_Err,
result.issues,
ctx,
)
: {
success: true,
data: result.value,
};
};
const safeParse =
_safeParse(
$ZodRealError,
);
function failure(Err, issues, ctx) {
let error;
return {
success: false,
get error() {
if (!error) {
error = new Err(
issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
);
issues = void 0;
ctx = void 0;
}
return error;
},
set error(e) {
error = e;
issues = void 0;
ctx = void 0;
},
};
}
const _safeParseAsync =
(_Err) =>
async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
result = await result;
return result.issues.length
? failure(
_Err,
result.issues,
ctx,
)
: {
success: true,
data: result.value,
};
};
const safeParseAsync =
_safeParseAsync(
$ZodRealError,
);
const httpProtocol = /^https?$/;
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const $ZodCheck =
$constructor(
"$ZodCheck",
(inst, def) => {
var _a;
inst._zod ?? (inst._zod = {});
inst._zod.def = def;
(_a = inst._zod).onattach ??
(_a.onattach = []);
},
);
const _whenHasLength = (payload) => {
const val = payload.value;
return (
!nullish(val) &&
val.length !== void 0
);
};
const numericOriginMap = {
number: "number",
bigint: "bigint",
object: "date",
};
const $ZodCheckLessThan =
$constructor(
"$ZodCheckLessThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin =
numericOriginMap[
typeof def.value
];
inst._zod.check = (payload) => {
if (
def.inclusive
? payload.value <= def.value
: payload.value < def.value
)
return;
payload.issues.push({
origin:
numericOriginMap[
typeof payload.value
] ?? origin,
code: "too_big",
maximum:
typeof def.value ===
"object"
? def.value.getTime()
: def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckGreaterThan =
$constructor(
"$ZodCheckGreaterThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin =
numericOriginMap[
typeof def.value
];
inst._zod.check = (payload) => {
if (
def.inclusive
? payload.value >= def.value
: payload.value > def.value
)
return;
payload.issues.push({
origin:
numericOriginMap[
typeof payload.value
] ?? origin,
code: "too_small",
minimum:
typeof def.value ===
"object"
? def.value.getTime()
: def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMaxLength =
$constructor(
"$ZodCheckMaxLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ??
(_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" &&
units > def.maximum
? codePointLength(input)
: units) <= def.maximum
)
return;
const origin =
getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_big",
maximum: def.maximum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMinLength =
$constructor(
"$ZodCheckMinLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ??
(_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" &&
units >= def.minimum &&
units < def.minimum * 2
? codePointLength(input)
: units) >= def.minimum
)
return;
const origin =
getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_small",
minimum: def.minimum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStringFormat =
$constructor(
"$ZodCheckStringFormat",
(inst, def) => {
var _a, _b;
$ZodCheck.init(inst, def);
if (def.pattern)
(_a = inst._zod).check ??
(_a.check = (payload) => {
def.pattern.lastIndex = 0;
if (
def.pattern.test(
payload.value,
)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: def.format,
input: payload.value,
...(def.pattern
? {
pattern:
def.pattern.toString(),
}
: {}),
inst,
continue: !def.abort,
});
});
else
(_b = inst._zod).check ??
(_b.check = () => {});
},
);
const version = {
major: 4,
minor: 6,
patch: 7,
};
const $ZodType =
$constructor(
"$ZodType",
(inst, def) => {
var _a;
inst ?? (inst = {});
inst._zod.def = def;
inst._zod.bag =
inst._zod.bag || {};
inst._zod.version = version;
const defChecks =
inst._zod.def.checks;
const checks =
inst._zod.traits.has(
"$ZodCheck",
)
? [inst, ...(defChecks ?? [])]
: defChecks?.length
? [...defChecks]
: [];
for (const ch of checks)
for (const fn of ch._zod
.onattach)
fn(inst);
if (checks.length === 0) {
(_a = inst._zod).deferred ??
(_a.deferred = []);
inst._zod.deferred?.push(() => {
inst._zod.run =
inst._zod.parse;
});
} else {
const runChecks = (
payload,
checks,
ctx,
) => {
if (payload.memo)
return payload;
let isAborted =
aborted(payload);
let asyncResult;
for (const ch of checks) {
if (ch._zod.def.when) {
if (
explicitlyAborted(
payload,
)
)
continue;
if (
!ch._zod.def.when(
payload,
)
)
continue;
} else if (isAborted)
continue;
const currLen =
payload.issues.length;
const _ =
ch._zod.check(payload);
if (
_ instanceof Promise &&
ctx?.async === false
)
throw new $ZodAsyncError();
if (
asyncResult ||
_ instanceof Promise
)
asyncResult = (
asyncResult ??
Promise.resolve()
).then(async () => {
await _;
if (
payload.issues
.length === currLen
)
return;
attachSchema(
payload.issues,
currLen,
inst,
);
if (!isAborted)
isAborted = aborted(
payload,
currLen,
);
});
else {
if (
payload.issues
.length === currLen
)
continue;
attachSchema(
payload.issues,
currLen,
inst,
);
if (!isAborted)
isAborted = aborted(
payload,
currLen,
);
}
}
if (asyncResult)
return asyncResult.then(
() => {
return payload;
},
);
return payload;
};
const handleCanaryResult = (
canary,
payload,
ctx,
) => {
if (aborted(canary)) {
canary.aborted = true;
return canary;
}
const checkResult = runChecks(
payload,
checks,
ctx,
);
if (
checkResult instanceof
Promise
) {
if (ctx.async === false)
throw new $ZodAsyncError();
return checkResult.then(
(checkResult) =>
inst._zod.parse(
checkResult,
ctx,
),
);
}
return inst._zod.parse(
checkResult,
ctx,
);
};
inst._zod.run = (
payload,
ctx,
) => {
if (ctx.skipChecks)
return inst._zod.parse(
payload,
ctx,
);
if (
ctx.direction === "backward"
) {
const canary =
inst._zod.parse(
{
value: payload.value,
issues: [],
},
{
...ctx,
skipChecks: true,
},
);
if (
canary instanceof Promise
)
return canary.then(
(canary) => {
return handleCanaryResult(
canary,
payload,
ctx,
);
},
);
return handleCanaryResult(
canary,
payload,
ctx,
);
}
const result =
inst._zod.parse(
payload,
ctx,
);
if (
result instanceof Promise
) {
if (ctx.async === false)
throw new $ZodAsyncError();
return result.then(
(result) =>
runChecks(
result,
checks,
ctx,
),
);
}
return runChecks(
result,
checks,
ctx,
);
};
}
},
{
get "~standard"() {
return hide(
this,
"~standard",
standardProps(this),
);
},
set "~standard"(value) {
own(this, "~standard", value);
},
},
);
const toStandardResult = (r, ctx) =>
r.issues.length
? {
issues: r.issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
}
: { value: r.value };
async function validateAsync(
inst,
value,
) {
const ctx = { async: true };
return toStandardResult(
await inst._zod.run(
{
value,
issues: [],
},
ctx,
),
ctx,
);
}
function standardProps(inst) {
return {
validate: (value) => {
const ctx = { async: false };
try {
const r = inst._zod.run(
{
value,
issues: [],
},
ctx,
);
if (!(r instanceof Promise))
return toStandardResult(
r,
ctx,
);
} catch (_) {}
return validateAsync(inst, value);
},
vendor: "zod",
version: 1,
};
}
const $ZodString =
$constructor(
"$ZodString",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern =
def.pattern ?? anyString;
inst._zod.parse = (
payload,
_,
) => {
if (def.coerce)
try {
payload.value = String(
payload.value,
);
} catch (_) {}
if (
typeof payload.value ===
"string"
)
return payload;
payload.issues.push({
expected: "string",
code: "invalid_type",
input: payload.value,
inst,
});
return payload;
};
},
);
const $ZodStringFormat =
$constructor(
"$ZodStringFormat",
(inst, def) => {
$ZodCheckStringFormat.init(
inst,
def,
);
$ZodString.init(inst, def);
},
);
function canParseURL(input) {
try {
if (
typeof URL !== "undefined" &&
typeof URL.canParse === "function"
)
return URL.canParse(input);
new URL(input);
return true;
} catch {
return false;
}
}
function validateURL(trimmed, def) {
if (
!("normalize" in def) &&
!("hostname" in def) &&
!("protocol" in def)
)
return canParseURL(trimmed) || 2;
return parseURLObject(trimmed, def);
}
function parseURLObject(trimmed, def) {
if (
!def.normalize &&
def.protocol?.source ===
httpProtocol.source &&
!/^https?:\/\//i.test(trimmed)
)
return 1;
try {
if (typeof URL !== "undefined") {
const URLStatic = URL;
if (
typeof URLStatic.parse ===
"function"
)
return (
URLStatic.parse(trimmed) ?? 2
);
}
return new URL(trimmed);
} catch {
return 2;
}
}
const asciiTabOrNewline = /[\t\n\r]/g;
function stripTabAndNewline(value) {
return value.replace(
asciiTabOrNewline,
"",
);
}
function urlHostnameOk(url, hostname) {
hostname.lastIndex = 0;
return hostname.test(url.hostname);
}
function urlProtocolOk(url, protocol) {
protocol.lastIndex = 0;
return protocol.test(
url.protocol.endsWith(":")
? url.protocol.slice(0, -1)
: url.protocol,
);
}
const $ZodURL =
$constructor(
"$ZodURL",
(inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
try {
const trimmed =
payload.value.trim();
const url = validateURL(
trimmed,
def,
);
if (url === 1) {
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid URL format",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === 2) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === true) {
payload.value =
stripTabAndNewline(
trimmed,
);
return;
}
if (
def.hostname &&
!urlHostnameOk(
url,
def.hostname,
)
)
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid hostname",
pattern:
def.hostname.source,
input: payload.value,
inst,
continue: !def.abort,
});
if (
def.protocol &&
!urlProtocolOk(
url,
def.protocol,
)
)
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid protocol",
pattern:
def.protocol.source,
input: payload.value,
inst,
continue: !def.abort,
});
payload.value = def.normalize
? url.href
: stripTabAndNewline(
trimmed,
);
return;
} catch (_) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
}
};
},
);
const $ZodNumber =
$constructor(
"$ZodNumber",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = number$1;
inst._zod.parse = (
payload,
_ctx,
) => {
if (def.coerce)
try {
payload.value = Number(
payload.value,
);
} catch (_) {}
const input = payload.value;
if (
typeof input === "number" &&
!Number.isNaN(input) &&
Number.isFinite(input)
)
return payload;
const received =
typeof input === "number"
? Number.isNaN(input)
? "NaN"
: !Number.isFinite(input)
? String(input)
: void 0
: void 0;
payload.issues.push({
expected: "number",
code: "invalid_type",
input,
inst,
...(received
? { received }
: {}),
});
return payload;
};
},
);
const $ZodDate =
$constructor(
"$ZodDate",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (
payload,
_ctx,
) => {
if (def.coerce)
try {
payload.value = new Date(
payload.value,
);
} catch (_err) {}
const input = payload.value;
const isDate =
input instanceof Date;
if (
isDate &&
!Number.isNaN(input.getTime())
)
return payload;
payload.issues.push({
expected: "date",
code: "invalid_type",
input,
...(isDate
? {
received:
"Invalid Date",
}
: {}),
inst,
});
return payload;
};
},
);
function capSize(inst, size) {
const caps = sizeCaps(
inst._zod.def.checks,
);
if (!caps.length) return;
const cap = Math.min(
...caps.map((c) => c[0]),
);
const parse = inst._zod.parse;
inst._zod.parse = (payload, ctx) => {
const n = size(payload.value);
if (
n > cap &&
!ctx?.skipChecks &&
ctx?.direction !== "backward"
) {
for (const [max, ch] of sizeCaps(
inst._zod.def.checks,
))
if (
n > max &&
ch._zod.def.when(payload)
) {
const start =
payload.issues.length;
ch._zod.check(payload);
payload.issues[
start
].continue = false;
attachSchema(
payload.issues,
start,
inst,
);
return payload;
}
}
return parse(payload, ctx);
};
}
const arraySize = (input) =>
Array.isArray(input)
? input.length
: -1;
function handleArrayResult(
result,
final,
index,
) {
if (result.issues.length)
final.issues.push(
...prefixIssues(
index,
result.issues,
),
);
final.value[index] = result.value;
}
const $ZodArray =
$constructor(
"$ZodArray",
(inst, def) => {
$ZodType.init(inst, def);
const memo =
globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (
payload,
ctx,
) => {
const input = payload.value;
if (!Array.isArray(input)) {
payload.issues.push({
expected: "array",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(
inst,
payload,
Array(input.length),
ctx,
)
: Array(input.length);
const proms = [];
const abortEarly =
ctx?.abortEarly;
for (
let i = 0;
i < input.length;
i++
) {
const item = input[i];
const result =
def.element._zod.run(
{
value: item,
issues: [],
},
ctx,
);
if (result instanceof Promise)
proms.push(
result.then((result) =>
handleArrayResult(
result,
payload,
i,
),
),
);
else {
handleArrayResult(
result,
payload,
i,
);
if (
abortEarly &&
result.issues.length !==
0 &&
aborted(result)
)
break;
}
}
if (proms.length)
return Promise.all(
proms,
).then(() => payload);
return payload;
};
capSize(inst, arraySize);
},
);
function handlePropertyResult(
result,
final,
key,
input,
optin,
optout,
) {
const isPresent = key in input;
const isOptionalOut =
optout === "optional";
if (
!isPresent &&
isOptionalOut &&
optin === "optional"
)
return;
if (result.issues.length) {
if (
optin !== void 0 &&
isOptionalOut &&
!isPresent
)
return;
final.issues.push(
...prefixIssues(
key,
result.issues,
),
);
}
if (!isPresent && optin === void 0) {
if (!result.issues.length)
final.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: void 0,
path: [key],
});
return;
}
if (result.value === void 0) {
if (
isPresent ||
(optin === "defaulted" &&
!isOptionalOut)
)
final.value[key] = void 0;
} else
final.value[key] = result.value;
}
const NO_SYMBOL_KEYS = [];
function normalizeDef(def) {
const keys = Object.keys(def.shape);
const ownSymbols =
Object.getOwnPropertySymbols(
def.shape,
);
const symbolKeys = ownSymbols.length
? ownSymbols
: NO_SYMBOL_KEYS;
const allKeys = symbolKeys.length
? [...keys, ...symbolKeys]
: keys;
for (const k of allKeys)
if (
!def.shape?.[
k
]?._zod?.traits?.has("$ZodType")
)
throw new Error(
`Invalid element at key "${String(k)}": expected a Zod schema`,
);
const okeys = optionalKeys(def.shape);
return {
...def,
allKeys,
symbolKeys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
}
function handleCatchall(
proms,
input,
payload,
ctx,
def,
inst,
abortEarly,
) {
const unrecognized = [];
const keySet = def.keySet;
const _catchall = def.catchall._zod;
const t = _catchall.def.type;
const optin = _catchall.optin;
const optout = _catchall.optout;
let seen = 0;
for (const key in input) {
if (
abortEarly &&
payload.issues.length !== seen
) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (keySet.has(key)) continue;
if (key === "__proto__") {
if (t === "never")
unrecognized.push(key);
continue;
}
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
),
),
);
else
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
);
}
if (unrecognized.length)
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
continue: true,
});
if (!proms.length) return payload;
return Promise.all(proms).then(() => {
return payload;
});
}
const $ZodObject =
$constructor(
"$ZodObject",
(inst, def) => {
$ZodType.init(inst, def);
const desc =
Object.getOwnPropertyDescriptor(
def,
"shape",
);
const sh = desc?.get
? desc.get.raw
: (def.shape ?? {});
if (sh) {
const get = () => {
const newSh = { ...sh };
Object.defineProperty(
def,
"shape",
{ value: newSh },
);
get.raw = newSh;
return newSh;
};
get.raw = sh;
Object.defineProperty(
def,
"shape",
{ get },
);
}
const _normalized = cached(() =>
normalizeDef(def),
);
defineLazyInternal(
inst,
"propValues",
(zod) => {
const shape = zod.def.shape;
const propValues = {};
for (const key in shape) {
const field =
shape[key]._zod;
if (field.values) {
if (
!Object.prototype.hasOwnProperty.call(
propValues,
key,
)
)
assignProp(
propValues,
key,
new Set(),
);
for (const v of field.values)
propValues[key].add(v);
if (
field.optin !== void 0
)
propValues[key].add(
void 0,
);
}
}
return propValues;
},
);
const isObject$1 = isObject;
const catchall = def.catchall;
let value;
const memo =
globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (
payload,
ctx,
) => {
value ??
(value = _normalized.value);
const input = payload.value;
if (!isObject$1(input)) {
payload.issues.push({
expected: "object",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(
inst,
payload,
{},
ctx,
)
: {};
const proms = [];
const shape = value.shape;
const abortEarly =
ctx?.abortEarly;
let seen =
payload.issues.length;
for (const key of value.allKeys) {
if (
abortEarly &&
payload.issues.length !==
seen
) {
if (aborted(payload, seen))
break;
seen =
payload.issues.length;
}
if (key === "__proto__")
continue;
const el = shape[key];
const optin = el._zod.optin;
const optout = el._zod.optout;
const r = el._zod.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
),
),
);
else
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
);
}
if (!catchall)
return proms.length
? Promise.all(proms).then(
() => payload,
)
: payload;
return handleCatchall(
proms,
input,
payload,
ctx,
_normalized.value,
inst,
abortEarly === true,
);
};
},
);
const $ZodEnum =
$constructor(
"$ZodEnum",
(inst, def) => {
$ZodType.init(inst, def);
const values = getEnumValues(
def.entries,
);
const valuesSet = new Set(values);
inst._zod.values = valuesSet;
defineLazyInternal(
inst,
"pattern",
(zod) => {
const patternValues =
getEnumValues(
zod.def.entries,
).filter((k) =>
propertyKeyTypes.has(
typeof k,
),
);
return new RegExp(
patternValues.length
? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$`
: "^[^\\s\\S]$",
);
},
);
inst._zod.parse = (
payload,
_ctx,
) => {
const input = payload.value;
if (valuesSet.has(input))
return payload;
payload.issues.push({
code: "invalid_value",
values,
input,
inst,
});
return payload;
};
},
);
const $ZodNullable =
$constructor(
"$ZodNullable",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"optin",
(zod) =>
zod.def.innerType._zod.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) =>
zod.def.innerType._zod.optout,
);
defineLazyInternal(
inst,
"pattern",
(zod) => {
const pattern =
zod.def.innerType._zod
.pattern;
return pattern
? new RegExp(
`^(${cleanRegex(pattern.source)}|null)$`,
)
: void 0;
},
);
defineLazyInternal(
inst,
"values",
(zod) => {
return zod.def.innerType._zod
.values
? new Set([
...zod.def.innerType
._zod.values,
null,
])
: void 0;
},
);
inst._zod.parse = (
payload,
ctx,
) => {
if (payload.value === null)
return payload;
return def.innerType._zod.run(
payload,
ctx,
);
};
},
);
function snapshotChecks(def) {
if (def.checks)
def.checks = [...def.checks];
return def;
}
function _string(Class, params) {
return new Class(
snapshotChecks({
type: "string",
...normalizeParams(params),
}),
);
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _maxLength(maximum, params) {
return new $ZodCheckMaxLength({
check: "max_length",
...normalizeParams(params),
maximum,
});
}
function _minLength(minimum, params) {
return new $ZodCheckMinLength({
check: "min_length",
...normalizeParams(params),
minimum,
});
}
const ZodMiniType =
$constructor(
"ZodMiniType",
(inst, def) => {
if (!inst._zod)
throw new Error(
"Uninitialized schema in ZodMiniType.",
);
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
},
{
get with() {
return this.check;
},
set with(value) {
own(this, "with", value);
},
parse(data, params) {
return parse(
this,
data,
params,
{ callee: this.parse },
);
},
parseAsync(data, params) {
return parseAsync(
this,
data,
params,
{ callee: this.parseAsync },
);
},
safeParse(data, params) {
return safeParse(
this,
data,
params,
);
},
safeParseAsync(data, params) {
return safeParseAsync(
this,
data,
params,
);
},
check(...checks) {
const def = this.def;
return this.clone(
{
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: {
check:
"custom",
},
onattach: [],
},
}
: ch,
),
],
},
{ parent: true },
);
},
clone(_def, params) {
return clone(
this,
_def,
params,
);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
apply(fn, ...args) {
return args.length === 0
? fn(this)
: fn(this, ...args);
},
},
);
const ZodMiniString =
$constructor(
"ZodMiniString",
(inst, def) => {
$ZodString.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function string(params) {
return _string(
ZodMiniString,
params,
);
}
const ZodMiniStringFormat =
$constructor(
"ZodMiniStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
ZodMiniString.init(inst, def);
},
);
const ZodMiniURL =
$constructor(
"ZodMiniURL",
(inst, def) => {
$ZodURL.init(inst, def);
ZodMiniStringFormat.init(
inst,
def,
);
},
);
function url(params) {
return _url(
ZodMiniURL,
params,
);
}
const ZodMiniNumber =
$constructor(
"ZodMiniNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function number(params) {
return _number(
ZodMiniNumber,
params,
);
}
const ZodMiniDate =
$constructor(
"ZodMiniDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function date(params) {
return _date(
ZodMiniDate,
params,
);
}
const ZodMiniArray =
$constructor(
"ZodMiniArray",
(inst, def) => {
$ZodArray.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function array(element, params) {
return new ZodMiniArray({
type: "array",
element,
...normalizeParams(params),
});
}
const ZodMiniObject =
$constructor(
"ZodMiniObject",
(inst, def) => {
$ZodObject.init(inst, def);
ZodMiniType.init(inst, def);
installLazyProp(
inst,
"shape",
(self) => self._zod.def.shape,
false,
);
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodMiniObject(def);
}
const ZodMiniEnum =
$constructor(
"ZodMiniEnum",
(inst, def) => {
$ZodEnum.init(inst, def);
ZodMiniType.init(inst, def);
inst.options = [
...inst._zod.values,
];
},
);
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(
values.map((v) => [v, v]),
)
: values;
return new ZodMiniEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodMiniNullable =
$constructor(
"ZodMiniNullable",
(inst, def) => {
$ZodNullable.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function nullable(innerType) {
return new ZodMiniNullable({
type: "nullable",
innerType,
});
}
const imageSchema =
object({
id: number(),
created: date(),
title:
string().check(
_minLength(1),
_maxLength(100),
),
type: _enum([
"jpg",
"png",
]),
size: number(),
url: url(),
});
const ratingSchema =
object({
id: number(),
stars:
number().check(
_gte(1),
_lte(5),
),
title:
string().check(
_minLength(1),
_maxLength(100),
),
text: string().check(
_minLength(1),
_maxLength(1e3),
),
images: array(
imageSchema,
),
});
toZod()(
object({
id: number(),
created: date(),
title:
string().check(
_minLength(1),
_maxLength(100),
),
brand:
string().check(
_minLength(1),
_maxLength(30),
),
description:
string().check(
_minLength(1),
_maxLength(500),
),
price:
number().check(
_gte(1),
_lte(1e4),
),
discount: nullable(
number().check(
_gte(1),
_lte(100),
),
),
quantity:
number().check(
_gte(0),
_lte(10),
),
tags: array(
string().check(
_minLength(1),
_maxLength(30),
),
),
images: array(
imageSchema,
),
ratings: array(
ratingSchema,
),
}),
).parse({});
function toZod() {
return (schema) => schema;
}
function getEnumValues(entries) {
const numericValues = Object.values(entries).filter(
(v) => typeof v === "number",
);
return Object.entries(entries)
.filter(([k, _]) => numericValues.indexOf(+k) === -1)
.map(([_, v]) => v);
}
function jsonStringifyReplacer(_, value) {
if (typeof value === "bigint") return value.toString();
return value;
}
var Cached = class {
constructor(getter) {
this._getter = getter;
this._value = void 0;
}
get value() {
const getter = this._getter;
if (getter !== void 0) {
this._value = getter();
this._getter = void 0;
}
return this._value;
}
};
function cached(getter) {
return new Cached(getter);
}
function nullish(input) {
return input === null || input === void 0;
}
function cleanRegex(source) {
const start = source.startsWith("^") ? 1 : 0;
const end = source.endsWith("$")
? source.length - 1
: source.length;
return source.slice(start, end);
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
const captureStackTrace =
"captureStackTrace" in Error
? Error.captureStackTrace
: (..._args) => {};
function isObject(data) {
return (
typeof data === "object" &&
data !== null &&
!Array.isArray(data)
);
}
const propertyKeyTypes = new Set([
"string",
"number",
"symbol",
]);
function escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function clone(inst, def, params) {
const cl = new inst._zod.constr(def ?? inst._zod.def);
if (!def || params?.parent) cl._zod.parent = inst;
return cl;
}
function normalizeParams(_params) {
const params = _params;
if (!params) return {};
if (typeof params === "string")
return { error: () => params };
if (params?.message !== void 0) {
if (params?.error !== void 0)
throw new Error(
"Cannot specify both `message` and `error` params",
);
params.error = params.message;
}
delete params.message;
if (typeof params.error === "string")
return {
...params,
error: () => params.error,
};
return params;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return (
shape[k]._zod.optin !== void 0 &&
shape[k]._zod.optout === "optional"
);
});
}
function aborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue !== true) return true;
return false;
}
function explicitlyAborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue === false) return true;
return false;
}
function prefixIssues(path, issues) {
return issues.map((iss) => {
var _a;
(_a = iss).path ?? (_a.path = []);
iss.path.unshift(path);
return iss;
});
}
function unwrapMessage(message) {
return typeof message === "string"
? message
: message?.message;
}
function sizeCaps(defChecks) {
const caps = [];
for (const ch of defChecks ?? []) {
const d = ch._zod.def;
if (!/_(length|size)$|_equals$/.test(d.check)) break;
const max = d.maximum ?? d.length ?? d.size;
if (max >= 0) caps.push([max, ch]);
}
return caps;
}
function attachSchema(issues, start, inst) {
var _a;
for (let i = start; i < issues.length; i++)
(_a = issues[i]).schema ?? (_a.schema = inst);
}
function finalizeIssue(iss, ctx, config) {
var _a;
const traits = iss.inst?._zod?.traits;
if (traits?.has("$ZodType")) {
if (traits.has("$ZodCheck"))
(_a = iss).schema ?? (_a.schema = iss.inst);
else iss.schema = iss.inst;
}
const schemaError =
iss.schema !== iss.inst
? iss.schema?._zod.def?.error
: void 0;
const message = iss.message
? iss.message
: (unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
unwrapMessage(schemaError?.(iss)) ??
unwrapMessage(ctx?.error?.(iss)) ??
unwrapMessage(config.customError?.(iss)) ??
unwrapMessage(config.localeError?.(iss)) ??
"Invalid input");
const full = {};
for (const k of Object.keys(iss)) {
if (
k === "inst" ||
k === "schema" ||
k === "continue" ||
k === "input" ||
k === "__proto__"
)
continue;
full[k] = iss[k];
}
full.path ?? (full.path = []);
full.message = message;
if (ctx?.reportInput) full.input = iss.input;
return full;
}
const highSurrogate = /[\uD800-\uDBFF]/;
function codePointLength(str) {
const units = str.length;
if (!highSurrogate.test(str)) return units;
let count = units;
for (let i = 0; i < units - 1; i++)
if (
(str.charCodeAt(i) & 64512) === 55296 &&
(str.charCodeAt(i + 1) & 64512) === 56320
) {
count--;
i++;
}
return count;
}
function getLengthableOrigin(input) {
if (Array.isArray(input)) return "array";
if (typeof input === "string") return "string";
return "unknown";
}
function members(proto, table) {
for (const key in table) {
const desc = Object.getOwnPropertyDescriptor(
table,
key,
);
if (desc.get)
Object.defineProperty(proto, key, {
...desc,
enumerable: false,
});
else defineBound(proto, key, desc.value);
}
}
function own(inst, key, value, enumerable = true) {
Object.defineProperty(inst, key, {
configurable: true,
writable: true,
enumerable,
value,
});
return value;
}
function hide(inst, key, value) {
return own(inst, key, value, false);
}
function defineBound(proto, key, fn) {
Object.defineProperty(proto, key, {
configurable: true,
get() {
return this == null
? fn
: own(this, key, fn.bind(this));
},
set(value) {
own(this, key, value);
},
});
}
function claim(inst, sentinel) {
const proto = Object.getPrototypeOf(inst);
return sentinel in proto ? void 0 : proto;
}
let installing;
let broke = false;
const breaker = {
configurable: true,
get() {
broke = true;
},
};
function defineLazyInternal(inst, key, compute) {
const proto = Object.getPrototypeOf(inst._zod);
if (key in proto && installing !== inst._zod) {
installing = void 0;
return;
}
installing = inst._zod;
Object.defineProperty(proto, key, {
configurable: true,
get() {
Object.defineProperty(this, key, breaker);
const outer = broke;
broke = false;
try {
const value = compute(this);
if (broke) delete this[key];
else
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
broke = broke || outer;
return value;
} catch (err) {
delete this[key];
broke = broke || outer;
throw err;
}
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
},
});
}
function installLazyProp(inst, key, make, enumerable) {
const proto = claim(inst, key);
if (!proto) return;
Object.defineProperty(proto, key, {
configurable: true,
get() {
const desc = {
configurable: true,
writable: true,
enumerable,
value: void 0,
};
Object.defineProperty(this, key, desc);
desc.value = make(this);
Object.defineProperty(this, key, desc);
return desc.value;
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable,
value,
});
},
});
}
var _a;
const _zodDesc = {
value: void 0,
enumerable: false,
};
let _E = "captureStackTrace" in Error ? Error : null;
function newError(Definition) {
const E = _E;
if (E) {
const saved = E.stackTraceLimit;
if (typeof saved === "number") {
try {
E.stackTraceLimit = 0;
} catch {
_E = null;
return new Definition();
}
try {
return new Definition();
} finally {
E.stackTraceLimit = saved;
}
}
}
return new Definition();
}
function $constructor(name, initializer, proto, params) {
const zodProto = {};
function Internals(def) {
this.def = def;
this.constr = _;
this.traits = new Set();
}
Internals.prototype = zodProto;
const protoMembers = proto;
const initialized =
protoMembers && new WeakSet();
function init(inst, def) {
if (!inst._zod) {
_zodDesc.value = new Internals(def);
try {
Object.defineProperty(inst, "_zod", _zodDesc);
} finally {
_zodDesc.value = void 0;
}
} else if (inst._zod.traits.has(name)) return;
inst._zod.traits.add(name);
initializer(inst, def);
if (initialized) {
const own = Object.getPrototypeOf(inst);
const ctorProto = inst._zod.constr.prototype;
let up = own;
while (up && up !== ctorProto)
up = Object.getPrototypeOf(up);
const target = up ?? own;
if (!initialized.has(target)) {
initialized.add(target);
members(target, protoMembers);
}
}
const proto = _.prototype;
for (const k in proto) {
if (!Object.prototype.hasOwnProperty.call(proto, k))
continue;
if (!(k in inst)) inst[k] = proto[k].bind(inst);
}
}
const Parent = params?.Parent ?? Object;
class Definition extends Parent {}
Object.defineProperty(Definition, "name", {
value: name,
});
function _(def) {
const inst = params?.Parent
? newError(Definition)
: this;
init(inst, def);
const deferred = inst._zod.deferred;
if (deferred) {
for (const fn of deferred) fn();
inst._zod.deferred = void 0;
}
const pp = globalThis.__zod_globalConfig?.postProcessor;
if (pp) pp(inst);
return inst;
}
Object.defineProperty(_, "init", { value: init });
Object.defineProperty(_, Symbol.hasInstance, {
value: (inst) => {
if (params?.Parent && inst instanceof params.Parent)
return true;
return inst?._zod?.traits?.has(name);
},
});
Object.defineProperty(_, "name", { value: name });
return _;
}
var $ZodAsyncError = class extends Error {
constructor() {
super(
`Encountered Promise during synchronous parse. Use .parseAsync() instead.`,
);
}
};
(_a = globalThis).__zod_globalConfig ??
(_a.__zod_globalConfig = {});
const globalConfig = globalThis.__zod_globalConfig;
function config(newConfig) {
if (newConfig) Object.assign(globalConfig, newConfig);
return globalConfig;
}
function _getMessage() {
const internals = this._zod;
internals.message ??
(internals.message = JSON.stringify(
internals.def,
jsonStringifyReplacer,
2,
));
return internals.message;
}
function _setMessage(value) {
this._zod.message = value;
}
const _messageDesc = {
get: _getMessage,
set: _setMessage,
enumerable: true,
configurable: true,
};
const _issuesDesc = {
value: void 0,
enumerable: false,
};
const _installedToString = new WeakSet([
Object.prototype,
Error.prototype,
]);
const initializer = (inst, def) => {
inst.name = "$ZodError";
_issuesDesc.value = def;
Object.defineProperty(inst, "issues", _issuesDesc);
_issuesDesc.value = void 0;
Object.defineProperty(inst, "message", _messageDesc);
const proto = Object.getPrototypeOf(inst);
if (!_installedToString.has(proto)) {
_installedToString.add(proto);
Object.defineProperty(proto, "toString", {
configurable: true,
enumerable: false,
get() {
const value = () => this.message;
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
},
});
}
};
const $ZodRealError = $constructor(
"$ZodError",
initializer,
void 0,
{ Parent: Error },
);
const _parse = (_Err) => {
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
throw new $ZodAsyncError();
if (result.issues.length) {
const e = new (_params?.Err ?? _Err)(
result.issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
);
captureStackTrace(e, _params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parse = _parse($ZodRealError);
const _parseAsync = (_Err) => {
const fn = async (schema, value, _ctx, params) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
if (result.issues.length) {
const e = new (params?.Err ?? _Err)(
result.issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
);
captureStackTrace(e, params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parseAsync =
_parseAsync($ZodRealError);
const _safeParse = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParse = _safeParse($ZodRealError);
function failure(Err, issues, ctx) {
let error;
return {
success: false,
get error() {
if (!error) {
error = new Err(
issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
);
issues = void 0;
ctx = void 0;
}
return error;
},
set error(e) {
error = e;
issues = void 0;
ctx = void 0;
},
};
}
const _safeParseAsync =
(_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParseAsync =
_safeParseAsync($ZodRealError);
const httpProtocol = /^https?$/;
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const $ZodCheck = $constructor(
"$ZodCheck",
(inst, def) => {
var _a;
inst._zod ?? (inst._zod = {});
inst._zod.def = def;
(_a = inst._zod).onattach ?? (_a.onattach = []);
},
);
const _whenHasLength = (payload) => {
const val = payload.value;
return !nullish(val) && val.length !== void 0;
};
const numericOriginMap = {
number: "number",
bigint: "bigint",
object: "date",
};
const $ZodCheckLessThan = $constructor(
"$ZodCheckLessThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (
def.inclusive
? payload.value <= def.value
: payload.value < def.value
)
return;
payload.issues.push({
origin:
numericOriginMap[typeof payload.value] ?? origin,
code: "too_big",
maximum:
typeof def.value === "object"
? def.value.getTime()
: def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckGreaterThan = $constructor(
"$ZodCheckGreaterThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (
def.inclusive
? payload.value >= def.value
: payload.value > def.value
)
return;
payload.issues.push({
origin:
numericOriginMap[typeof payload.value] ?? origin,
code: "too_small",
minimum:
typeof def.value === "object"
? def.value.getTime()
: def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMaxLength = $constructor(
"$ZodCheckMaxLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" && units > def.maximum
? codePointLength(input)
: units) <= def.maximum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_big",
maximum: def.maximum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMinLength = $constructor(
"$ZodCheckMinLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" &&
units >= def.minimum &&
units < def.minimum * 2
? codePointLength(input)
: units) >= def.minimum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_small",
minimum: def.minimum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStringFormat = $constructor(
"$ZodCheckStringFormat",
(inst, def) => {
var _a, _b;
$ZodCheck.init(inst, def);
if (def.pattern)
(_a = inst._zod).check ??
(_a.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: def.format,
input: payload.value,
...(def.pattern
? { pattern: def.pattern.toString() }
: {}),
inst,
continue: !def.abort,
});
});
else (_b = inst._zod).check ?? (_b.check = () => {});
},
);
const version = {
major: 4,
minor: 6,
patch: 7,
};
const $ZodType = $constructor(
"$ZodType",
(inst, def) => {
var _a;
inst ?? (inst = {});
inst._zod.def = def;
inst._zod.bag = inst._zod.bag || {};
inst._zod.version = version;
const defChecks = inst._zod.def.checks;
const checks = inst._zod.traits.has("$ZodCheck")
? [inst, ...(defChecks ?? [])]
: defChecks?.length
? [...defChecks]
: [];
for (const ch of checks)
for (const fn of ch._zod.onattach) fn(inst);
if (checks.length === 0) {
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred?.push(() => {
inst._zod.run = inst._zod.parse;
});
} else {
const runChecks = (payload, checks, ctx) => {
if (payload.memo) return payload;
let isAborted = aborted(payload);
let asyncResult;
for (const ch of checks) {
if (ch._zod.def.when) {
if (explicitlyAborted(payload)) continue;
if (!ch._zod.def.when(payload)) continue;
} else if (isAborted) continue;
const currLen = payload.issues.length;
const _ = ch._zod.check(payload);
if (_ instanceof Promise && ctx?.async === false)
throw new $ZodAsyncError();
if (asyncResult || _ instanceof Promise)
asyncResult = (
asyncResult ?? Promise.resolve()
).then(async () => {
await _;
if (payload.issues.length === currLen) return;
attachSchema(payload.issues, currLen, inst);
if (!isAborted)
isAborted = aborted(payload, currLen);
});
else {
if (payload.issues.length === currLen) continue;
attachSchema(payload.issues, currLen, inst);
if (!isAborted)
isAborted = aborted(payload, currLen);
}
}
if (asyncResult)
return asyncResult.then(() => {
return payload;
});
return payload;
};
const handleCanaryResult = (canary, payload, ctx) => {
if (aborted(canary)) {
canary.aborted = true;
return canary;
}
const checkResult = runChecks(payload, checks, ctx);
if (checkResult instanceof Promise) {
if (ctx.async === false)
throw new $ZodAsyncError();
return checkResult.then((checkResult) =>
inst._zod.parse(checkResult, ctx),
);
}
return inst._zod.parse(checkResult, ctx);
};
inst._zod.run = (payload, ctx) => {
if (ctx.skipChecks)
return inst._zod.parse(payload, ctx);
if (ctx.direction === "backward") {
const canary = inst._zod.parse(
{
value: payload.value,
issues: [],
},
{
...ctx,
skipChecks: true,
},
);
if (canary instanceof Promise)
return canary.then((canary) => {
return handleCanaryResult(
canary,
payload,
ctx,
);
});
return handleCanaryResult(canary, payload, ctx);
}
const result = inst._zod.parse(payload, ctx);
if (result instanceof Promise) {
if (ctx.async === false)
throw new $ZodAsyncError();
return result.then((result) =>
runChecks(result, checks, ctx),
);
}
return runChecks(result, checks, ctx);
};
}
},
{
get "~standard"() {
return hide(this, "~standard", standardProps(this));
},
set "~standard"(value) {
own(this, "~standard", value);
},
},
);
const toStandardResult = (r, ctx) =>
r.issues.length
? {
issues: r.issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
}
: { value: r.value };
async function validateAsync(inst, value) {
const ctx = { async: true };
return toStandardResult(
await inst._zod.run(
{
value,
issues: [],
},
ctx,
),
ctx,
);
}
function standardProps(inst) {
return {
validate: (value) => {
const ctx = { async: false };
try {
const r = inst._zod.run(
{
value,
issues: [],
},
ctx,
);
if (!(r instanceof Promise))
return toStandardResult(r, ctx);
} catch (_) {}
return validateAsync(inst, value);
},
vendor: "zod",
version: 1,
};
}
const $ZodString = $constructor(
"$ZodString",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = def.pattern ?? anyString;
inst._zod.parse = (payload, _) => {
if (def.coerce)
try {
payload.value = String(payload.value);
} catch (_) {}
if (typeof payload.value === "string") return payload;
payload.issues.push({
expected: "string",
code: "invalid_type",
input: payload.value,
inst,
});
return payload;
};
},
);
const $ZodStringFormat = $constructor(
"$ZodStringFormat",
(inst, def) => {
$ZodCheckStringFormat.init(inst, def);
$ZodString.init(inst, def);
},
);
function canParseURL(input) {
try {
if (
typeof URL !== "undefined" &&
typeof URL.canParse === "function"
)
return URL.canParse(input);
new URL(input);
return true;
} catch {
return false;
}
}
function validateURL(trimmed, def) {
if (
!("normalize" in def) &&
!("hostname" in def) &&
!("protocol" in def)
)
return canParseURL(trimmed) || 2;
return parseURLObject(trimmed, def);
}
function parseURLObject(trimmed, def) {
if (
!def.normalize &&
def.protocol?.source === httpProtocol.source &&
!/^https?:\/\//i.test(trimmed)
)
return 1;
try {
if (typeof URL !== "undefined") {
const URLStatic = URL;
if (typeof URLStatic.parse === "function")
return URLStatic.parse(trimmed) ?? 2;
}
return new URL(trimmed);
} catch {
return 2;
}
}
const asciiTabOrNewline = /[\t\n\r]/g;
function stripTabAndNewline(value) {
return value.replace(asciiTabOrNewline, "");
}
function urlHostnameOk(url, hostname) {
hostname.lastIndex = 0;
return hostname.test(url.hostname);
}
function urlProtocolOk(url, protocol) {
protocol.lastIndex = 0;
return protocol.test(
url.protocol.endsWith(":")
? url.protocol.slice(0, -1)
: url.protocol,
);
}
const $ZodURL = $constructor(
"$ZodURL",
(inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
try {
const trimmed = payload.value.trim();
const url = validateURL(trimmed, def);
if (url === 1) {
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid URL format",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === 2) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === true) {
payload.value = stripTabAndNewline(trimmed);
return;
}
if (
def.hostname &&
!urlHostnameOk(url, def.hostname)
)
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid hostname",
pattern: def.hostname.source,
input: payload.value,
inst,
continue: !def.abort,
});
if (
def.protocol &&
!urlProtocolOk(url, def.protocol)
)
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid protocol",
pattern: def.protocol.source,
input: payload.value,
inst,
continue: !def.abort,
});
payload.value = def.normalize
? url.href
: stripTabAndNewline(trimmed);
return;
} catch (_) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
}
};
},
);
const $ZodNumber = $constructor(
"$ZodNumber",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = number$1;
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = Number(payload.value);
} catch (_) {}
const input = payload.value;
if (
typeof input === "number" &&
!Number.isNaN(input) &&
Number.isFinite(input)
)
return payload;
const received =
typeof input === "number"
? Number.isNaN(input)
? "NaN"
: !Number.isFinite(input)
? String(input)
: void 0
: void 0;
payload.issues.push({
expected: "number",
code: "invalid_type",
input,
inst,
...(received ? { received } : {}),
});
return payload;
};
},
);
const $ZodDate = $constructor(
"$ZodDate",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = new Date(payload.value);
} catch (_err) {}
const input = payload.value;
const isDate = input instanceof Date;
if (isDate && !Number.isNaN(input.getTime()))
return payload;
payload.issues.push({
expected: "date",
code: "invalid_type",
input,
...(isDate ? { received: "Invalid Date" } : {}),
inst,
});
return payload;
};
},
);
function capSize(inst, size) {
const caps = sizeCaps(inst._zod.def.checks);
if (!caps.length) return;
const cap = Math.min(...caps.map((c) => c[0]));
const parse = inst._zod.parse;
inst._zod.parse = (payload, ctx) => {
const n = size(payload.value);
if (
n > cap &&
!ctx?.skipChecks &&
ctx?.direction !== "backward"
) {
for (const [max, ch] of sizeCaps(
inst._zod.def.checks,
))
if (n > max && ch._zod.def.when(payload)) {
const start = payload.issues.length;
ch._zod.check(payload);
payload.issues[start].continue = false;
attachSchema(payload.issues, start, inst);
return payload;
}
}
return parse(payload, ctx);
};
}
const arraySize = (input) =>
Array.isArray(input) ? input.length : -1;
function handleArrayResult(result, final, index) {
if (result.issues.length)
final.issues.push(
...prefixIssues(index, result.issues),
);
final.value[index] = result.value;
}
const $ZodArray = $constructor(
"$ZodArray",
(inst, def) => {
$ZodType.init(inst, def);
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
if (!Array.isArray(input)) {
payload.issues.push({
expected: "array",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(
inst,
payload,
Array(input.length),
ctx,
)
: Array(input.length);
const proms = [];
const abortEarly = ctx?.abortEarly;
for (let i = 0; i < input.length; i++) {
const item = input[i];
const result = def.element._zod.run(
{
value: item,
issues: [],
},
ctx,
);
if (result instanceof Promise)
proms.push(
result.then((result) =>
handleArrayResult(result, payload, i),
),
);
else {
handleArrayResult(result, payload, i);
if (
abortEarly &&
result.issues.length !== 0 &&
aborted(result)
)
break;
}
}
if (proms.length)
return Promise.all(proms).then(() => payload);
return payload;
};
capSize(inst, arraySize);
},
);
function handlePropertyResult(
result,
final,
key,
input,
optin,
optout,
) {
const isPresent = key in input;
const isOptionalOut = optout === "optional";
if (!isPresent && isOptionalOut && optin === "optional")
return;
if (result.issues.length) {
if (optin !== void 0 && isOptionalOut && !isPresent)
return;
final.issues.push(...prefixIssues(key, result.issues));
}
if (!isPresent && optin === void 0) {
if (!result.issues.length)
final.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: void 0,
path: [key],
});
return;
}
if (result.value === void 0) {
if (
isPresent ||
(optin === "defaulted" && !isOptionalOut)
)
final.value[key] = void 0;
} else final.value[key] = result.value;
}
const NO_SYMBOL_KEYS = [];
function normalizeDef(def) {
const keys = Object.keys(def.shape);
const ownSymbols = Object.getOwnPropertySymbols(
def.shape,
);
const symbolKeys = ownSymbols.length
? ownSymbols
: NO_SYMBOL_KEYS;
const allKeys = symbolKeys.length
? [...keys, ...symbolKeys]
: keys;
for (const k of allKeys)
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType"))
throw new Error(
`Invalid element at key "${String(k)}": expected a Zod schema`,
);
const okeys = optionalKeys(def.shape);
return {
...def,
allKeys,
symbolKeys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
}
function handleCatchall(
proms,
input,
payload,
ctx,
def,
inst,
abortEarly,
) {
const unrecognized = [];
const keySet = def.keySet;
const _catchall = def.catchall._zod;
const t = _catchall.def.type;
const optin = _catchall.optin;
const optout = _catchall.optout;
let seen = 0;
for (const key in input) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (keySet.has(key)) continue;
if (key === "__proto__") {
if (t === "never") unrecognized.push(key);
continue;
}
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
),
),
);
else
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
);
}
if (unrecognized.length)
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
continue: true,
});
if (!proms.length) return payload;
return Promise.all(proms).then(() => {
return payload;
});
}
const $ZodObject = $constructor(
"$ZodObject",
(inst, def) => {
$ZodType.init(inst, def);
const desc = Object.getOwnPropertyDescriptor(
def,
"shape",
);
const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
if (sh) {
const get = () => {
const newSh = { ...sh };
Object.defineProperty(def, "shape", {
value: newSh,
});
get.raw = newSh;
return newSh;
};
get.raw = sh;
Object.defineProperty(def, "shape", { get });
}
const _normalized = cached(() => normalizeDef(def));
defineLazyInternal(inst, "propValues", (zod) => {
const shape = zod.def.shape;
const propValues = {};
for (const key in shape) {
const field = shape[key]._zod;
if (field.values) {
if (
!Object.prototype.hasOwnProperty.call(
propValues,
key,
)
)
assignProp(
propValues,
key,
new Set(),
);
for (const v of field.values)
propValues[key].add(v);
if (field.optin !== void 0)
propValues[key].add(void 0);
}
}
return propValues;
});
const isObject$1 = isObject;
const catchall = def.catchall;
let value;
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
value ?? (value = _normalized.value);
const input = payload.value;
if (!isObject$1(input)) {
payload.issues.push({
expected: "object",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(inst, payload, {}, ctx)
: {};
const proms = [];
const shape = value.shape;
const abortEarly = ctx?.abortEarly;
let seen = payload.issues.length;
for (const key of value.allKeys) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (key === "__proto__") continue;
const el = shape[key];
const optin = el._zod.optin;
const optout = el._zod.optout;
const r = el._zod.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
),
),
);
else
handlePropertyResult(
r,
payload,
key,
input,
optin,
optout,
);
}
if (!catchall)
return proms.length
? Promise.all(proms).then(() => payload)
: payload;
return handleCatchall(
proms,
input,
payload,
ctx,
_normalized.value,
inst,
abortEarly === true,
);
};
},
);
const $ZodEnum = $constructor(
"$ZodEnum",
(inst, def) => {
$ZodType.init(inst, def);
const values = getEnumValues(def.entries);
const valuesSet = new Set(values);
inst._zod.values = valuesSet;
defineLazyInternal(inst, "pattern", (zod) => {
const patternValues = getEnumValues(
zod.def.entries,
).filter((k) => propertyKeyTypes.has(typeof k));
return new RegExp(
patternValues.length
? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$`
: "^[^\\s\\S]$",
);
});
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (valuesSet.has(input)) return payload;
payload.issues.push({
code: "invalid_value",
values,
input,
inst,
});
return payload;
};
},
);
const $ZodNullable = $constructor(
"$ZodNullable",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"optin",
(zod) => zod.def.innerType._zod.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) => zod.def.innerType._zod.optout,
);
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern
? new RegExp(
`^(${cleanRegex(pattern.source)}|null)$`,
)
: void 0;
});
defineLazyInternal(inst, "values", (zod) => {
return zod.def.innerType._zod.values
? new Set([
...zod.def.innerType._zod.values,
null,
])
: void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === null) return payload;
return def.innerType._zod.run(payload, ctx);
};
},
);
function snapshotChecks(def) {
if (def.checks) def.checks = [...def.checks];
return def;
}
function _string(Class, params) {
return new Class(
snapshotChecks({
type: "string",
...normalizeParams(params),
}),
);
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _maxLength(maximum, params) {
return new $ZodCheckMaxLength({
check: "max_length",
...normalizeParams(params),
maximum,
});
}
function _minLength(minimum, params) {
return new $ZodCheckMinLength({
check: "min_length",
...normalizeParams(params),
minimum,
});
}
const ZodMiniType = $constructor(
"ZodMiniType",
(inst, def) => {
if (!inst._zod)
throw new Error(
"Uninitialized schema in ZodMiniType.",
);
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
},
{
get with() {
return this.check;
},
set with(value) {
own(this, "with", value);
},
parse(data, params) {
return parse(this, data, params, {
callee: this.parse,
});
},
parseAsync(data, params) {
return parseAsync(this, data, params, {
callee: this.parseAsync,
});
},
safeParse(data, params) {
return safeParse(this, data, params);
},
safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
check(...checks) {
const def = this.def;
return this.clone(
{
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
},
{ parent: true },
);
},
clone(_def, params) {
return clone(this, _def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
apply(fn, ...args) {
return args.length === 0
? fn(this)
: fn(this, ...args);
},
},
);
const ZodMiniString = $constructor(
"ZodMiniString",
(inst, def) => {
$ZodString.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function string(params) {
return _string(ZodMiniString, params);
}
const ZodMiniStringFormat = $constructor(
"ZodMiniStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
ZodMiniString.init(inst, def);
},
);
const ZodMiniURL = $constructor(
"ZodMiniURL",
(inst, def) => {
$ZodURL.init(inst, def);
ZodMiniStringFormat.init(inst, def);
},
);
function url(params) {
return _url(ZodMiniURL, params);
}
const ZodMiniNumber = $constructor(
"ZodMiniNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function number(params) {
return _number(ZodMiniNumber, params);
}
const ZodMiniDate = $constructor(
"ZodMiniDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function date(params) {
return _date(ZodMiniDate, params);
}
const ZodMiniArray = $constructor(
"ZodMiniArray",
(inst, def) => {
$ZodArray.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function array(element, params) {
return new ZodMiniArray({
type: "array",
element,
...normalizeParams(params),
});
}
const ZodMiniObject = $constructor(
"ZodMiniObject",
(inst, def) => {
$ZodObject.init(inst, def);
ZodMiniType.init(inst, def);
installLazyProp(
inst,
"shape",
(self) => self._zod.def.shape,
false,
);
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodMiniObject(def);
}
const ZodMiniEnum = $constructor(
"ZodMiniEnum",
(inst, def) => {
$ZodEnum.init(inst, def);
ZodMiniType.init(inst, def);
inst.options = [...inst._zod.values];
},
);
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(values.map((v) => [v, v]))
: values;
return new ZodMiniEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodMiniNullable = $constructor(
"ZodMiniNullable",
(inst, def) => {
$ZodNullable.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function nullable(innerType) {
return new ZodMiniNullable({
type: "nullable",
innerType,
});
}
const imageSchema = object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().check(
_gte(1),
_lte(5),
),
title: string().check(
_minLength(1),
_maxLength(100),
),
text: string().check(
_minLength(1),
_maxLength(1e3),
),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
brand: string().check(
_minLength(1),
_maxLength(30),
),
description: string().check(
_minLength(1),
_maxLength(500),
),
price: number().check(
_gte(1),
_lte(1e4),
),
discount: nullable(
number().check(
_gte(1),
_lte(100),
),
),
quantity: number().check(
_gte(0),
_lte(10),
),
tags: array(
string().check(
_minLength(1),
_maxLength(30),
),
),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
).parse({});
function toZod() {
return (schema) => schema;
}
function getEnumValues(entries) {
const numericValues = Object.values(entries).filter(
(v) => typeof v === "number",
);
return Object.entries(entries)
.filter(([k, _]) => numericValues.indexOf(+k) === -1)
.map(([_, v]) => v);
}
function jsonStringifyReplacer(_, value) {
if (typeof value === "bigint") return value.toString();
return value;
}
var Cached = class {
constructor(getter) {
this._getter = getter;
this._value = void 0;
}
get value() {
const getter = this._getter;
if (getter !== void 0) {
this._value = getter();
this._getter = void 0;
}
return this._value;
}
};
function cached(getter) {
return new Cached(getter);
}
function nullish(input) {
return input === null || input === void 0;
}
function cleanRegex(source) {
const start = source.startsWith("^") ? 1 : 0;
const end = source.endsWith("$") ? source.length - 1 : source.length;
return source.slice(start, end);
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
const captureStackTrace =
"captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
const propertyKeyTypes = new Set(["string", "number", "symbol"]);
function escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function clone(inst, def, params) {
const cl = new inst._zod.constr(def ?? inst._zod.def);
if (!def || params?.parent) cl._zod.parent = inst;
return cl;
}
function normalizeParams(_params) {
const params = _params;
if (!params) return {};
if (typeof params === "string") return { error: () => params };
if (params?.message !== void 0) {
if (params?.error !== void 0)
throw new Error("Cannot specify both `message` and `error` params");
params.error = params.message;
}
delete params.message;
if (typeof params.error === "string")
return {
...params,
error: () => params.error,
};
return params;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return (
shape[k]._zod.optin !== void 0 && shape[k]._zod.optout === "optional"
);
});
}
function aborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue !== true) return true;
return false;
}
function explicitlyAborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue === false) return true;
return false;
}
function prefixIssues(path, issues) {
return issues.map((iss) => {
var _a;
(_a = iss).path ?? (_a.path = []);
iss.path.unshift(path);
return iss;
});
}
function unwrapMessage(message) {
return typeof message === "string" ? message : message?.message;
}
function sizeCaps(defChecks) {
const caps = [];
for (const ch of defChecks ?? []) {
const d = ch._zod.def;
if (!/_(length|size)$|_equals$/.test(d.check)) break;
const max = d.maximum ?? d.length ?? d.size;
if (max >= 0) caps.push([max, ch]);
}
return caps;
}
function attachSchema(issues, start, inst) {
var _a;
for (let i = start; i < issues.length; i++)
(_a = issues[i]).schema ?? (_a.schema = inst);
}
function finalizeIssue(iss, ctx, config) {
var _a;
const traits = iss.inst?._zod?.traits;
if (traits?.has("$ZodType")) {
if (traits.has("$ZodCheck")) (_a = iss).schema ?? (_a.schema = iss.inst);
else iss.schema = iss.inst;
}
const schemaError =
iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
const message = iss.message
? iss.message
: (unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
unwrapMessage(schemaError?.(iss)) ??
unwrapMessage(ctx?.error?.(iss)) ??
unwrapMessage(config.customError?.(iss)) ??
unwrapMessage(config.localeError?.(iss)) ??
"Invalid input");
const full = {};
for (const k of Object.keys(iss)) {
if (
k === "inst" ||
k === "schema" ||
k === "continue" ||
k === "input" ||
k === "__proto__"
)
continue;
full[k] = iss[k];
}
full.path ?? (full.path = []);
full.message = message;
if (ctx?.reportInput) full.input = iss.input;
return full;
}
const highSurrogate = /[\uD800-\uDBFF]/;
function codePointLength(str) {
const units = str.length;
if (!highSurrogate.test(str)) return units;
let count = units;
for (let i = 0; i < units - 1; i++)
if (
(str.charCodeAt(i) & 64512) === 55296 &&
(str.charCodeAt(i + 1) & 64512) === 56320
) {
count--;
i++;
}
return count;
}
function getLengthableOrigin(input) {
if (Array.isArray(input)) return "array";
if (typeof input === "string") return "string";
return "unknown";
}
function members(proto, table) {
for (const key in table) {
const desc = Object.getOwnPropertyDescriptor(table, key);
if (desc.get)
Object.defineProperty(proto, key, {
...desc,
enumerable: false,
});
else defineBound(proto, key, desc.value);
}
}
function own(inst, key, value, enumerable = true) {
Object.defineProperty(inst, key, {
configurable: true,
writable: true,
enumerable,
value,
});
return value;
}
function hide(inst, key, value) {
return own(inst, key, value, false);
}
function defineBound(proto, key, fn) {
Object.defineProperty(proto, key, {
configurable: true,
get() {
return this == null ? fn : own(this, key, fn.bind(this));
},
set(value) {
own(this, key, value);
},
});
}
function claim(inst, sentinel) {
const proto = Object.getPrototypeOf(inst);
return sentinel in proto ? void 0 : proto;
}
let installing;
let broke = false;
const breaker = {
configurable: true,
get() {
broke = true;
},
};
function defineLazyInternal(inst, key, compute) {
const proto = Object.getPrototypeOf(inst._zod);
if (key in proto && installing !== inst._zod) {
installing = void 0;
return;
}
installing = inst._zod;
Object.defineProperty(proto, key, {
configurable: true,
get() {
Object.defineProperty(this, key, breaker);
const outer = broke;
broke = false;
try {
const value = compute(this);
if (broke) delete this[key];
else
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
broke = broke || outer;
return value;
} catch (err) {
delete this[key];
broke = broke || outer;
throw err;
}
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
},
});
}
function installLazyProp(inst, key, make, enumerable) {
const proto = claim(inst, key);
if (!proto) return;
Object.defineProperty(proto, key, {
configurable: true,
get() {
const desc = {
configurable: true,
writable: true,
enumerable,
value: void 0,
};
Object.defineProperty(this, key, desc);
desc.value = make(this);
Object.defineProperty(this, key, desc);
return desc.value;
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable,
value,
});
},
});
}
var _a;
const _zodDesc = {
value: void 0,
enumerable: false,
};
let _E = "captureStackTrace" in Error ? Error : null;
function newError(Definition) {
const E = _E;
if (E) {
const saved = E.stackTraceLimit;
if (typeof saved === "number") {
try {
E.stackTraceLimit = 0;
} catch {
_E = null;
return new Definition();
}
try {
return new Definition();
} finally {
E.stackTraceLimit = saved;
}
}
}
return new Definition();
}
function $constructor(name, initializer, proto, params) {
const zodProto = {};
function Internals(def) {
this.def = def;
this.constr = _;
this.traits = new Set();
}
Internals.prototype = zodProto;
const protoMembers = proto;
const initialized = protoMembers && new WeakSet();
function init(inst, def) {
if (!inst._zod) {
_zodDesc.value = new Internals(def);
try {
Object.defineProperty(inst, "_zod", _zodDesc);
} finally {
_zodDesc.value = void 0;
}
} else if (inst._zod.traits.has(name)) return;
inst._zod.traits.add(name);
initializer(inst, def);
if (initialized) {
const own = Object.getPrototypeOf(inst);
const ctorProto = inst._zod.constr.prototype;
let up = own;
while (up && up !== ctorProto) up = Object.getPrototypeOf(up);
const target = up ?? own;
if (!initialized.has(target)) {
initialized.add(target);
members(target, protoMembers);
}
}
const proto = _.prototype;
for (const k in proto) {
if (!Object.prototype.hasOwnProperty.call(proto, k)) continue;
if (!(k in inst)) inst[k] = proto[k].bind(inst);
}
}
const Parent = params?.Parent ?? Object;
class Definition extends Parent {}
Object.defineProperty(Definition, "name", { value: name });
function _(def) {
const inst = params?.Parent ? newError(Definition) : this;
init(inst, def);
const deferred = inst._zod.deferred;
if (deferred) {
for (const fn of deferred) fn();
inst._zod.deferred = void 0;
}
const pp = globalThis.__zod_globalConfig?.postProcessor;
if (pp) pp(inst);
return inst;
}
Object.defineProperty(_, "init", { value: init });
Object.defineProperty(_, Symbol.hasInstance, {
value: (inst) => {
if (params?.Parent && inst instanceof params.Parent) return true;
return inst?._zod?.traits?.has(name);
},
});
Object.defineProperty(_, "name", { value: name });
return _;
}
var $ZodAsyncError = class extends Error {
constructor() {
super(
`Encountered Promise during synchronous parse. Use .parseAsync() instead.`,
);
}
};
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
const globalConfig = globalThis.__zod_globalConfig;
function config(newConfig) {
if (newConfig) Object.assign(globalConfig, newConfig);
return globalConfig;
}
function _getMessage() {
const internals = this._zod;
internals.message ??
(internals.message = JSON.stringify(
internals.def,
jsonStringifyReplacer,
2,
));
return internals.message;
}
function _setMessage(value) {
this._zod.message = value;
}
const _messageDesc = {
get: _getMessage,
set: _setMessage,
enumerable: true,
configurable: true,
};
const _issuesDesc = {
value: void 0,
enumerable: false,
};
const _installedToString = new WeakSet([
Object.prototype,
Error.prototype,
]);
const initializer = (inst, def) => {
inst.name = "$ZodError";
_issuesDesc.value = def;
Object.defineProperty(inst, "issues", _issuesDesc);
_issuesDesc.value = void 0;
Object.defineProperty(inst, "message", _messageDesc);
const proto = Object.getPrototypeOf(inst);
if (!_installedToString.has(proto)) {
_installedToString.add(proto);
Object.defineProperty(proto, "toString", {
configurable: true,
enumerable: false,
get() {
const value = () => this.message;
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
},
});
}
};
const $ZodRealError = $constructor(
"$ZodError",
initializer,
void 0,
{ Parent: Error },
);
const _parse = (_Err) => {
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
if (result.issues.length) {
const e = new (_params?.Err ?? _Err)(
result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
);
captureStackTrace(e, _params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parse = _parse($ZodRealError);
const _parseAsync = (_Err) => {
const fn = async (schema, value, _ctx, params) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
if (result.issues.length) {
const e = new (params?.Err ?? _Err)(
result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
);
captureStackTrace(e, params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parseAsync = _parseAsync($ZodRealError);
const _safeParse = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParse = _safeParse($ZodRealError);
function failure(Err, issues, ctx) {
let error;
return {
success: false,
get error() {
if (!error) {
error = new Err(issues.map((iss) => finalizeIssue(iss, ctx, config())));
issues = void 0;
ctx = void 0;
}
return error;
},
set error(e) {
error = e;
issues = void 0;
ctx = void 0;
},
};
}
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParseAsync = _safeParseAsync($ZodRealError);
const httpProtocol = /^https?$/;
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const $ZodCheck = $constructor("$ZodCheck", (inst, def) => {
var _a;
inst._zod ?? (inst._zod = {});
inst._zod.def = def;
(_a = inst._zod).onattach ?? (_a.onattach = []);
});
const _whenHasLength = (payload) => {
const val = payload.value;
return !nullish(val) && val.length !== void 0;
};
const numericOriginMap = {
number: "number",
bigint: "bigint",
object: "date",
};
const $ZodCheckLessThan = $constructor(
"$ZodCheckLessThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (
def.inclusive ? payload.value <= def.value : payload.value < def.value
)
return;
payload.issues.push({
origin: numericOriginMap[typeof payload.value] ?? origin,
code: "too_big",
maximum:
typeof def.value === "object" ? def.value.getTime() : def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckGreaterThan = $constructor(
"$ZodCheckGreaterThan",
(inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (
def.inclusive ? payload.value >= def.value : payload.value > def.value
)
return;
payload.issues.push({
origin: numericOriginMap[typeof payload.value] ?? origin,
code: "too_small",
minimum:
typeof def.value === "object" ? def.value.getTime() : def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMaxLength = $constructor(
"$ZodCheckMaxLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" && units > def.maximum
? codePointLength(input)
: units) <= def.maximum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_big",
maximum: def.maximum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckMinLength = $constructor(
"$ZodCheckMinLength",
(inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" &&
units >= def.minimum &&
units < def.minimum * 2
? codePointLength(input)
: units) >= def.minimum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_small",
minimum: def.minimum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStringFormat = $constructor(
"$ZodCheckStringFormat",
(inst, def) => {
var _a, _b;
$ZodCheck.init(inst, def);
if (def.pattern)
(_a = inst._zod).check ??
(_a.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: def.format,
input: payload.value,
...(def.pattern ? { pattern: def.pattern.toString() } : {}),
inst,
continue: !def.abort,
});
});
else (_b = inst._zod).check ?? (_b.check = () => {});
},
);
const version = {
major: 4,
minor: 6,
patch: 7,
};
const $ZodType = $constructor(
"$ZodType",
(inst, def) => {
var _a;
inst ?? (inst = {});
inst._zod.def = def;
inst._zod.bag = inst._zod.bag || {};
inst._zod.version = version;
const defChecks = inst._zod.def.checks;
const checks = inst._zod.traits.has("$ZodCheck")
? [inst, ...(defChecks ?? [])]
: defChecks?.length
? [...defChecks]
: [];
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
if (checks.length === 0) {
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred?.push(() => {
inst._zod.run = inst._zod.parse;
});
} else {
const runChecks = (payload, checks, ctx) => {
if (payload.memo) return payload;
let isAborted = aborted(payload);
let asyncResult;
for (const ch of checks) {
if (ch._zod.def.when) {
if (explicitlyAborted(payload)) continue;
if (!ch._zod.def.when(payload)) continue;
} else if (isAborted) continue;
const currLen = payload.issues.length;
const _ = ch._zod.check(payload);
if (_ instanceof Promise && ctx?.async === false)
throw new $ZodAsyncError();
if (asyncResult || _ instanceof Promise)
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
await _;
if (payload.issues.length === currLen) return;
attachSchema(payload.issues, currLen, inst);
if (!isAborted) isAborted = aborted(payload, currLen);
});
else {
if (payload.issues.length === currLen) continue;
attachSchema(payload.issues, currLen, inst);
if (!isAborted) isAborted = aborted(payload, currLen);
}
}
if (asyncResult)
return asyncResult.then(() => {
return payload;
});
return payload;
};
const handleCanaryResult = (canary, payload, ctx) => {
if (aborted(canary)) {
canary.aborted = true;
return canary;
}
const checkResult = runChecks(payload, checks, ctx);
if (checkResult instanceof Promise) {
if (ctx.async === false) throw new $ZodAsyncError();
return checkResult.then((checkResult) =>
inst._zod.parse(checkResult, ctx),
);
}
return inst._zod.parse(checkResult, ctx);
};
inst._zod.run = (payload, ctx) => {
if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
if (ctx.direction === "backward") {
const canary = inst._zod.parse(
{
value: payload.value,
issues: [],
},
{
...ctx,
skipChecks: true,
},
);
if (canary instanceof Promise)
return canary.then((canary) => {
return handleCanaryResult(canary, payload, ctx);
});
return handleCanaryResult(canary, payload, ctx);
}
const result = inst._zod.parse(payload, ctx);
if (result instanceof Promise) {
if (ctx.async === false) throw new $ZodAsyncError();
return result.then((result) => runChecks(result, checks, ctx));
}
return runChecks(result, checks, ctx);
};
}
},
{
get "~standard"() {
return hide(this, "~standard", standardProps(this));
},
set "~standard"(value) {
own(this, "~standard", value);
},
},
);
const toStandardResult = (r, ctx) =>
r.issues.length
? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) }
: { value: r.value };
async function validateAsync(inst, value) {
const ctx = { async: true };
return toStandardResult(
await inst._zod.run(
{
value,
issues: [],
},
ctx,
),
ctx,
);
}
function standardProps(inst) {
return {
validate: (value) => {
const ctx = { async: false };
try {
const r = inst._zod.run(
{
value,
issues: [],
},
ctx,
);
if (!(r instanceof Promise)) return toStandardResult(r, ctx);
} catch (_) {}
return validateAsync(inst, value);
},
vendor: "zod",
version: 1,
};
}
const $ZodString = $constructor("$ZodString", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = def.pattern ?? anyString;
inst._zod.parse = (payload, _) => {
if (def.coerce)
try {
payload.value = String(payload.value);
} catch (_) {}
if (typeof payload.value === "string") return payload;
payload.issues.push({
expected: "string",
code: "invalid_type",
input: payload.value,
inst,
});
return payload;
};
});
const $ZodStringFormat = $constructor(
"$ZodStringFormat",
(inst, def) => {
$ZodCheckStringFormat.init(inst, def);
$ZodString.init(inst, def);
},
);
function canParseURL(input) {
try {
if (typeof URL !== "undefined" && typeof URL.canParse === "function")
return URL.canParse(input);
new URL(input);
return true;
} catch {
return false;
}
}
function validateURL(trimmed, def) {
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def))
return canParseURL(trimmed) || 2;
return parseURLObject(trimmed, def);
}
function parseURLObject(trimmed, def) {
if (
!def.normalize &&
def.protocol?.source === httpProtocol.source &&
!/^https?:\/\//i.test(trimmed)
)
return 1;
try {
if (typeof URL !== "undefined") {
const URLStatic = URL;
if (typeof URLStatic.parse === "function")
return URLStatic.parse(trimmed) ?? 2;
}
return new URL(trimmed);
} catch {
return 2;
}
}
const asciiTabOrNewline = /[\t\n\r]/g;
function stripTabAndNewline(value) {
return value.replace(asciiTabOrNewline, "");
}
function urlHostnameOk(url, hostname) {
hostname.lastIndex = 0;
return hostname.test(url.hostname);
}
function urlProtocolOk(url, protocol) {
protocol.lastIndex = 0;
return protocol.test(
url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol,
);
}
const $ZodURL = $constructor("$ZodURL", (inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
try {
const trimmed = payload.value.trim();
const url = validateURL(trimmed, def);
if (url === 1) {
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid URL format",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === 2) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === true) {
payload.value = stripTabAndNewline(trimmed);
return;
}
if (def.hostname && !urlHostnameOk(url, def.hostname))
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid hostname",
pattern: def.hostname.source,
input: payload.value,
inst,
continue: !def.abort,
});
if (def.protocol && !urlProtocolOk(url, def.protocol))
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid protocol",
pattern: def.protocol.source,
input: payload.value,
inst,
continue: !def.abort,
});
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
return;
} catch (_) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
}
};
});
const $ZodNumber = $constructor("$ZodNumber", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = number$1;
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = Number(payload.value);
} catch (_) {}
const input = payload.value;
if (
typeof input === "number" &&
!Number.isNaN(input) &&
Number.isFinite(input)
)
return payload;
const received =
typeof input === "number"
? Number.isNaN(input)
? "NaN"
: !Number.isFinite(input)
? String(input)
: void 0
: void 0;
payload.issues.push({
expected: "number",
code: "invalid_type",
input,
inst,
...(received ? { received } : {}),
});
return payload;
};
});
const $ZodDate = $constructor("$ZodDate", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = new Date(payload.value);
} catch (_err) {}
const input = payload.value;
const isDate = input instanceof Date;
if (isDate && !Number.isNaN(input.getTime())) return payload;
payload.issues.push({
expected: "date",
code: "invalid_type",
input,
...(isDate ? { received: "Invalid Date" } : {}),
inst,
});
return payload;
};
});
function capSize(inst, size) {
const caps = sizeCaps(inst._zod.def.checks);
if (!caps.length) return;
const cap = Math.min(...caps.map((c) => c[0]));
const parse = inst._zod.parse;
inst._zod.parse = (payload, ctx) => {
const n = size(payload.value);
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
for (const [max, ch] of sizeCaps(inst._zod.def.checks))
if (n > max && ch._zod.def.when(payload)) {
const start = payload.issues.length;
ch._zod.check(payload);
payload.issues[start].continue = false;
attachSchema(payload.issues, start, inst);
return payload;
}
}
return parse(payload, ctx);
};
}
const arraySize = (input) => (Array.isArray(input) ? input.length : -1);
function handleArrayResult(result, final, index) {
if (result.issues.length)
final.issues.push(...prefixIssues(index, result.issues));
final.value[index] = result.value;
}
const $ZodArray = $constructor("$ZodArray", (inst, def) => {
$ZodType.init(inst, def);
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
if (!Array.isArray(input)) {
payload.issues.push({
expected: "array",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(inst, payload, Array(input.length), ctx)
: Array(input.length);
const proms = [];
const abortEarly = ctx?.abortEarly;
for (let i = 0; i < input.length; i++) {
const item = input[i];
const result = def.element._zod.run(
{
value: item,
issues: [],
},
ctx,
);
if (result instanceof Promise)
proms.push(
result.then((result) => handleArrayResult(result, payload, i)),
);
else {
handleArrayResult(result, payload, i);
if (abortEarly && result.issues.length !== 0 && aborted(result)) break;
}
}
if (proms.length) return Promise.all(proms).then(() => payload);
return payload;
};
capSize(inst, arraySize);
});
function handlePropertyResult(result, final, key, input, optin, optout) {
const isPresent = key in input;
const isOptionalOut = optout === "optional";
if (!isPresent && isOptionalOut && optin === "optional") return;
if (result.issues.length) {
if (optin !== void 0 && isOptionalOut && !isPresent) return;
final.issues.push(...prefixIssues(key, result.issues));
}
if (!isPresent && optin === void 0) {
if (!result.issues.length)
final.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: void 0,
path: [key],
});
return;
}
if (result.value === void 0) {
if (isPresent || (optin === "defaulted" && !isOptionalOut))
final.value[key] = void 0;
} else final.value[key] = result.value;
}
const NO_SYMBOL_KEYS = [];
function normalizeDef(def) {
const keys = Object.keys(def.shape);
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
for (const k of allKeys)
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType"))
throw new Error(
`Invalid element at key "${String(k)}": expected a Zod schema`,
);
const okeys = optionalKeys(def.shape);
return {
...def,
allKeys,
symbolKeys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
}
function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
const unrecognized = [];
const keySet = def.keySet;
const _catchall = def.catchall._zod;
const t = _catchall.def.type;
const optin = _catchall.optin;
const optout = _catchall.optout;
let seen = 0;
for (const key in input) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (keySet.has(key)) continue;
if (key === "__proto__") {
if (t === "never") unrecognized.push(key);
continue;
}
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(r, payload, key, input, optin, optout),
),
);
else handlePropertyResult(r, payload, key, input, optin, optout);
}
if (unrecognized.length)
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
continue: true,
});
if (!proms.length) return payload;
return Promise.all(proms).then(() => {
return payload;
});
}
const $ZodObject = $constructor("$ZodObject", (inst, def) => {
$ZodType.init(inst, def);
const desc = Object.getOwnPropertyDescriptor(def, "shape");
const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
if (sh) {
const get = () => {
const newSh = { ...sh };
Object.defineProperty(def, "shape", { value: newSh });
get.raw = newSh;
return newSh;
};
get.raw = sh;
Object.defineProperty(def, "shape", { get });
}
const _normalized = cached(() => normalizeDef(def));
defineLazyInternal(inst, "propValues", (zod) => {
const shape = zod.def.shape;
const propValues = {};
for (const key in shape) {
const field = shape[key]._zod;
if (field.values) {
if (!Object.prototype.hasOwnProperty.call(propValues, key))
assignProp(propValues, key, new Set());
for (const v of field.values) propValues[key].add(v);
if (field.optin !== void 0) propValues[key].add(void 0);
}
}
return propValues;
});
const isObject$1 = isObject;
const catchall = def.catchall;
let value;
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
value ?? (value = _normalized.value);
const input = payload.value;
if (!isObject$1(input)) {
payload.issues.push({
expected: "object",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
const proms = [];
const shape = value.shape;
const abortEarly = ctx?.abortEarly;
let seen = payload.issues.length;
for (const key of value.allKeys) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (key === "__proto__") continue;
const el = shape[key];
const optin = el._zod.optin;
const optout = el._zod.optout;
const r = el._zod.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(
r.then((r) =>
handlePropertyResult(r, payload, key, input, optin, optout),
),
);
else handlePropertyResult(r, payload, key, input, optin, optout);
}
if (!catchall)
return proms.length ? Promise.all(proms).then(() => payload) : payload;
return handleCatchall(
proms,
input,
payload,
ctx,
_normalized.value,
inst,
abortEarly === true,
);
};
});
const $ZodEnum = $constructor("$ZodEnum", (inst, def) => {
$ZodType.init(inst, def);
const values = getEnumValues(def.entries);
const valuesSet = new Set(values);
inst._zod.values = valuesSet;
defineLazyInternal(inst, "pattern", (zod) => {
const patternValues = getEnumValues(zod.def.entries).filter((k) =>
propertyKeyTypes.has(typeof k),
);
return new RegExp(
patternValues.length
? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$`
: "^[^\\s\\S]$",
);
});
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (valuesSet.has(input)) return payload;
payload.issues.push({
code: "invalid_value",
values,
input,
inst,
});
return payload;
};
});
const $ZodNullable = $constructor("$ZodNullable", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern
? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`)
: void 0;
});
defineLazyInternal(inst, "values", (zod) => {
return zod.def.innerType._zod.values
? new Set([...zod.def.innerType._zod.values, null])
: void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === null) return payload;
return def.innerType._zod.run(payload, ctx);
};
});
function snapshotChecks(def) {
if (def.checks) def.checks = [...def.checks];
return def;
}
function _string(Class, params) {
return new Class(
snapshotChecks({
type: "string",
...normalizeParams(params),
}),
);
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _maxLength(maximum, params) {
return new $ZodCheckMaxLength({
check: "max_length",
...normalizeParams(params),
maximum,
});
}
function _minLength(minimum, params) {
return new $ZodCheckMinLength({
check: "min_length",
...normalizeParams(params),
minimum,
});
}
const ZodMiniType = $constructor(
"ZodMiniType",
(inst, def) => {
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
},
{
get with() {
return this.check;
},
set with(value) {
own(this, "with", value);
},
parse(data, params) {
return parse(this, data, params, { callee: this.parse });
},
parseAsync(data, params) {
return parseAsync(this, data, params, { callee: this.parseAsync });
},
safeParse(data, params) {
return safeParse(this, data, params);
},
safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
check(...checks) {
const def = this.def;
return this.clone(
{
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
},
{ parent: true },
);
},
clone(_def, params) {
return clone(this, _def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
apply(fn, ...args) {
return args.length === 0 ? fn(this) : fn(this, ...args);
},
},
);
const ZodMiniString = $constructor(
"ZodMiniString",
(inst, def) => {
$ZodString.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function string(params) {
return _string(ZodMiniString, params);
}
const ZodMiniStringFormat = $constructor(
"ZodMiniStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
ZodMiniString.init(inst, def);
},
);
const ZodMiniURL = $constructor("ZodMiniURL", (inst, def) => {
$ZodURL.init(inst, def);
ZodMiniStringFormat.init(inst, def);
});
function url(params) {
return _url(ZodMiniURL, params);
}
const ZodMiniNumber = $constructor(
"ZodMiniNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function number(params) {
return _number(ZodMiniNumber, params);
}
const ZodMiniDate = $constructor("ZodMiniDate", (inst, def) => {
$ZodDate.init(inst, def);
ZodMiniType.init(inst, def);
});
function date(params) {
return _date(ZodMiniDate, params);
}
const ZodMiniArray = $constructor("ZodMiniArray", (inst, def) => {
$ZodArray.init(inst, def);
ZodMiniType.init(inst, def);
});
function array(element, params) {
return new ZodMiniArray({
type: "array",
element,
...normalizeParams(params),
});
}
const ZodMiniObject = $constructor(
"ZodMiniObject",
(inst, def) => {
$ZodObject.init(inst, def);
ZodMiniType.init(inst, def);
installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodMiniObject(def);
}
const ZodMiniEnum = $constructor("ZodMiniEnum", (inst, def) => {
$ZodEnum.init(inst, def);
ZodMiniType.init(inst, def);
inst.options = [...inst._zod.values];
});
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(values.map((v) => [v, v]))
: values;
return new ZodMiniEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodMiniNullable = $constructor(
"ZodMiniNullable",
(inst, def) => {
$ZodNullable.init(inst, def);
ZodMiniType.init(inst, def);
},
);
function nullable(innerType) {
return new ZodMiniNullable({
type: "nullable",
innerType,
});
}
const imageSchema = object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().check(
_gte(1),
_lte(5),
),
title: string().check(
_minLength(1),
_maxLength(100),
),
text: string().check(
_minLength(1),
_maxLength(1e3),
),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
brand: string().check(
_minLength(1),
_maxLength(30),
),
description: string().check(
_minLength(1),
_maxLength(500),
),
price: number().check(
_gte(1),
_lte(1e4),
),
discount: nullable(
number().check(
_gte(1),
_lte(100),
),
),
quantity: number().check(
_gte(0),
_lte(10),
),
tags: array(
string().check(
_minLength(1),
_maxLength(30),
),
),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
).parse({});
function toZod() {
return (schema) => schema;
}
function getEnumValues(entries) {
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
return Object.entries(entries)
.filter(([k, _]) => numericValues.indexOf(+k) === -1)
.map(([_, v]) => v);
}
function jsonStringifyReplacer(_, value) {
if (typeof value === "bigint") return value.toString();
return value;
}
var Cached = class {
constructor(getter) {
this._getter = getter;
this._value = void 0;
}
get value() {
const getter = this._getter;
if (getter !== void 0) {
this._value = getter();
this._getter = void 0;
}
return this._value;
}
};
function cached(getter) {
return new Cached(getter);
}
function nullish(input) {
return input === null || input === void 0;
}
function cleanRegex(source) {
const start = source.startsWith("^") ? 1 : 0;
const end = source.endsWith("$") ? source.length - 1 : source.length;
return source.slice(start, end);
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
const propertyKeyTypes = new Set(["string", "number", "symbol"]);
function escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function clone(inst, def, params) {
const cl = new inst._zod.constr(def ?? inst._zod.def);
if (!def || params?.parent) cl._zod.parent = inst;
return cl;
}
function normalizeParams(_params) {
const params = _params;
if (!params) return {};
if (typeof params === "string") return { error: () => params };
if (params?.message !== void 0) {
if (params?.error !== void 0)
throw new Error("Cannot specify both `message` and `error` params");
params.error = params.message;
}
delete params.message;
if (typeof params.error === "string")
return {
...params,
error: () => params.error,
};
return params;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return shape[k]._zod.optin !== void 0 && shape[k]._zod.optout === "optional";
});
}
function aborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue !== true) return true;
return false;
}
function explicitlyAborted(x, startIndex = 0) {
if (x.aborted === true) return true;
for (let i = startIndex; i < x.issues.length; i++)
if (x.issues[i]?.continue === false) return true;
return false;
}
function prefixIssues(path, issues) {
return issues.map((iss) => {
var _a;
(_a = iss).path ?? (_a.path = []);
iss.path.unshift(path);
return iss;
});
}
function unwrapMessage(message) {
return typeof message === "string" ? message : message?.message;
}
function sizeCaps(defChecks) {
const caps = [];
for (const ch of defChecks ?? []) {
const d = ch._zod.def;
if (!/_(length|size)$|_equals$/.test(d.check)) break;
const max = d.maximum ?? d.length ?? d.size;
if (max >= 0) caps.push([max, ch]);
}
return caps;
}
function attachSchema(issues, start, inst) {
var _a;
for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
}
function finalizeIssue(iss, ctx, config) {
var _a;
const traits = iss.inst?._zod?.traits;
if (traits?.has("$ZodType")) {
if (traits.has("$ZodCheck")) (_a = iss).schema ?? (_a.schema = iss.inst);
else iss.schema = iss.inst;
}
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
const message = iss.message
? iss.message
: (unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
unwrapMessage(schemaError?.(iss)) ??
unwrapMessage(ctx?.error?.(iss)) ??
unwrapMessage(config.customError?.(iss)) ??
unwrapMessage(config.localeError?.(iss)) ??
"Invalid input");
const full = {};
for (const k of Object.keys(iss)) {
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
continue;
full[k] = iss[k];
}
full.path ?? (full.path = []);
full.message = message;
if (ctx?.reportInput) full.input = iss.input;
return full;
}
const highSurrogate = /[\uD800-\uDBFF]/;
function codePointLength(str) {
const units = str.length;
if (!highSurrogate.test(str)) return units;
let count = units;
for (let i = 0; i < units - 1; i++)
if ((str.charCodeAt(i) & 64512) === 55296 && (str.charCodeAt(i + 1) & 64512) === 56320) {
count--;
i++;
}
return count;
}
function getLengthableOrigin(input) {
if (Array.isArray(input)) return "array";
if (typeof input === "string") return "string";
return "unknown";
}
function members(proto, table) {
for (const key in table) {
const desc = Object.getOwnPropertyDescriptor(table, key);
if (desc.get)
Object.defineProperty(proto, key, {
...desc,
enumerable: false,
});
else defineBound(proto, key, desc.value);
}
}
function own(inst, key, value, enumerable = true) {
Object.defineProperty(inst, key, {
configurable: true,
writable: true,
enumerable,
value,
});
return value;
}
function hide(inst, key, value) {
return own(inst, key, value, false);
}
function defineBound(proto, key, fn) {
Object.defineProperty(proto, key, {
configurable: true,
get() {
return this == null ? fn : own(this, key, fn.bind(this));
},
set(value) {
own(this, key, value);
},
});
}
function claim(inst, sentinel) {
const proto = Object.getPrototypeOf(inst);
return sentinel in proto ? void 0 : proto;
}
let installing;
let broke = false;
const breaker = {
configurable: true,
get() {
broke = true;
},
};
function defineLazyInternal(inst, key, compute) {
const proto = Object.getPrototypeOf(inst._zod);
if (key in proto && installing !== inst._zod) {
installing = void 0;
return;
}
installing = inst._zod;
Object.defineProperty(proto, key, {
configurable: true,
get() {
Object.defineProperty(this, key, breaker);
const outer = broke;
broke = false;
try {
const value = compute(this);
if (broke) delete this[key];
else
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
broke = broke || outer;
return value;
} catch (err) {
delete this[key];
broke = broke || outer;
throw err;
}
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value,
});
},
});
}
function installLazyProp(inst, key, make, enumerable) {
const proto = claim(inst, key);
if (!proto) return;
Object.defineProperty(proto, key, {
configurable: true,
get() {
const desc = {
configurable: true,
writable: true,
enumerable,
value: void 0,
};
Object.defineProperty(this, key, desc);
desc.value = make(this);
Object.defineProperty(this, key, desc);
return desc.value;
},
set(value) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable,
value,
});
},
});
}
var _a;
const _zodDesc = {
value: void 0,
enumerable: false,
};
let _E = "captureStackTrace" in Error ? Error : null;
function newError(Definition) {
const E = _E;
if (E) {
const saved = E.stackTraceLimit;
if (typeof saved === "number") {
try {
E.stackTraceLimit = 0;
} catch {
_E = null;
return new Definition();
}
try {
return new Definition();
} finally {
E.stackTraceLimit = saved;
}
}
}
return new Definition();
}
function $constructor(name, initializer, proto, params) {
const zodProto = {};
function Internals(def) {
this.def = def;
this.constr = _;
this.traits = new Set();
}
Internals.prototype = zodProto;
const protoMembers = proto;
const initialized = protoMembers && new WeakSet();
function init(inst, def) {
if (!inst._zod) {
_zodDesc.value = new Internals(def);
try {
Object.defineProperty(inst, "_zod", _zodDesc);
} finally {
_zodDesc.value = void 0;
}
} else if (inst._zod.traits.has(name)) return;
inst._zod.traits.add(name);
initializer(inst, def);
if (initialized) {
const own = Object.getPrototypeOf(inst);
const ctorProto = inst._zod.constr.prototype;
let up = own;
while (up && up !== ctorProto) up = Object.getPrototypeOf(up);
const target = up ?? own;
if (!initialized.has(target)) {
initialized.add(target);
members(target, protoMembers);
}
}
const proto = _.prototype;
for (const k in proto) {
if (!Object.prototype.hasOwnProperty.call(proto, k)) continue;
if (!(k in inst)) inst[k] = proto[k].bind(inst);
}
}
const Parent = params?.Parent ?? Object;
class Definition extends Parent {}
Object.defineProperty(Definition, "name", { value: name });
function _(def) {
const inst = params?.Parent ? newError(Definition) : this;
init(inst, def);
const deferred = inst._zod.deferred;
if (deferred) {
for (const fn of deferred) fn();
inst._zod.deferred = void 0;
}
const pp = globalThis.__zod_globalConfig?.postProcessor;
if (pp) pp(inst);
return inst;
}
Object.defineProperty(_, "init", { value: init });
Object.defineProperty(_, Symbol.hasInstance, {
value: (inst) => {
if (params?.Parent && inst instanceof params.Parent) return true;
return inst?._zod?.traits?.has(name);
},
});
Object.defineProperty(_, "name", { value: name });
return _;
}
var $ZodAsyncError = class extends Error {
constructor() {
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
}
};
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
const globalConfig = globalThis.__zod_globalConfig;
function config(newConfig) {
if (newConfig) Object.assign(globalConfig, newConfig);
return globalConfig;
}
function _getMessage() {
const internals = this._zod;
internals.message ??
(internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
return internals.message;
}
function _setMessage(value) {
this._zod.message = value;
}
const _messageDesc = {
get: _getMessage,
set: _setMessage,
enumerable: true,
configurable: true,
};
const _issuesDesc = {
value: void 0,
enumerable: false,
};
const _installedToString = new WeakSet([Object.prototype, Error.prototype]);
const initializer = (inst, def) => {
inst.name = "$ZodError";
_issuesDesc.value = def;
Object.defineProperty(inst, "issues", _issuesDesc);
_issuesDesc.value = void 0;
Object.defineProperty(inst, "message", _messageDesc);
const proto = Object.getPrototypeOf(inst);
if (!_installedToString.has(proto)) {
_installedToString.add(proto);
Object.defineProperty(proto, "toString", {
configurable: true,
enumerable: false,
get() {
const value = () => this.message;
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, "toString", {
value,
configurable: true,
writable: true,
});
},
});
}
};
const $ZodRealError = $constructor("$ZodError", initializer, void 0, {
Parent: Error,
});
const _parse = (_Err) => {
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
if (result.issues.length) {
const e = new (_params?.Err ?? _Err)(
result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
);
captureStackTrace(e, _params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parse = _parse($ZodRealError);
const _parseAsync = (_Err) => {
const fn = async (schema, value, _ctx, params) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
if (result.issues.length) {
const e = new (params?.Err ?? _Err)(
result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
);
captureStackTrace(e, params?.callee ?? fn);
throw e;
}
return result.value;
};
return fn;
};
const parseAsync = _parseAsync($ZodRealError);
const _safeParse = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: false,
}
: { async: false };
const result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParse = _safeParse($ZodRealError);
function failure(Err, issues, ctx) {
let error;
return {
success: false,
get error() {
if (!error) {
error = new Err(issues.map((iss) => finalizeIssue(iss, ctx, config())));
issues = void 0;
ctx = void 0;
}
return error;
},
set error(e) {
error = e;
issues = void 0;
ctx = void 0;
},
};
}
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
}
: { async: true };
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length
? failure(_Err, result.issues, ctx)
: {
success: true,
data: result.value,
};
};
const safeParseAsync = _safeParseAsync($ZodRealError);
const httpProtocol = /^https?$/;
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const $ZodCheck = $constructor("$ZodCheck", (inst, def) => {
var _a;
inst._zod ?? (inst._zod = {});
inst._zod.def = def;
(_a = inst._zod).onattach ?? (_a.onattach = []);
});
const _whenHasLength = (payload) => {
const val = payload.value;
return !nullish(val) && val.length !== void 0;
};
const numericOriginMap = {
number: "number",
bigint: "bigint",
object: "date",
};
const $ZodCheckLessThan = $constructor("$ZodCheckLessThan", (inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
payload.issues.push({
origin: numericOriginMap[typeof payload.value] ?? origin,
code: "too_big",
maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckGreaterThan = $constructor("$ZodCheckGreaterThan", (inst, def) => {
$ZodCheck.init(inst, def);
const origin = numericOriginMap[typeof def.value];
inst._zod.check = (payload) => {
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
payload.issues.push({
origin: numericOriginMap[typeof payload.value] ?? origin,
code: "too_small",
minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
input: payload.value,
inclusive: def.inclusive,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckMaxLength = $constructor("$ZodCheckMaxLength", (inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" && units > def.maximum ? codePointLength(input) : units) <=
def.maximum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_big",
maximum: def.maximum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckMinLength = $constructor("$ZodCheckMinLength", (inst, def) => {
var _a;
$ZodCheck.init(inst, def);
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
inst._zod.check = (payload) => {
const input = payload.value;
const units = input.length;
if (
(typeof input === "string" && units >= def.minimum && units < def.minimum * 2
? codePointLength(input)
: units) >= def.minimum
)
return;
const origin = getLengthableOrigin(input);
payload.issues.push({
origin,
code: "too_small",
minimum: def.minimum,
inclusive: true,
input,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckStringFormat = $constructor("$ZodCheckStringFormat", (inst, def) => {
var _a, _b;
$ZodCheck.init(inst, def);
if (def.pattern)
(_a = inst._zod).check ??
(_a.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: def.format,
input: payload.value,
...(def.pattern ? { pattern: def.pattern.toString() } : {}),
inst,
continue: !def.abort,
});
});
else (_b = inst._zod).check ?? (_b.check = () => {});
});
const version = {
major: 4,
minor: 6,
patch: 7,
};
const $ZodType = $constructor(
"$ZodType",
(inst, def) => {
var _a;
inst ?? (inst = {});
inst._zod.def = def;
inst._zod.bag = inst._zod.bag || {};
inst._zod.version = version;
const defChecks = inst._zod.def.checks;
const checks = inst._zod.traits.has("$ZodCheck")
? [inst, ...(defChecks ?? [])]
: defChecks?.length
? [...defChecks]
: [];
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
if (checks.length === 0) {
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred?.push(() => {
inst._zod.run = inst._zod.parse;
});
} else {
const runChecks = (payload, checks, ctx) => {
if (payload.memo) return payload;
let isAborted = aborted(payload);
let asyncResult;
for (const ch of checks) {
if (ch._zod.def.when) {
if (explicitlyAborted(payload)) continue;
if (!ch._zod.def.when(payload)) continue;
} else if (isAborted) continue;
const currLen = payload.issues.length;
const _ = ch._zod.check(payload);
if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
if (asyncResult || _ instanceof Promise)
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
await _;
if (payload.issues.length === currLen) return;
attachSchema(payload.issues, currLen, inst);
if (!isAborted) isAborted = aborted(payload, currLen);
});
else {
if (payload.issues.length === currLen) continue;
attachSchema(payload.issues, currLen, inst);
if (!isAborted) isAborted = aborted(payload, currLen);
}
}
if (asyncResult)
return asyncResult.then(() => {
return payload;
});
return payload;
};
const handleCanaryResult = (canary, payload, ctx) => {
if (aborted(canary)) {
canary.aborted = true;
return canary;
}
const checkResult = runChecks(payload, checks, ctx);
if (checkResult instanceof Promise) {
if (ctx.async === false) throw new $ZodAsyncError();
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
}
return inst._zod.parse(checkResult, ctx);
};
inst._zod.run = (payload, ctx) => {
if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
if (ctx.direction === "backward") {
const canary = inst._zod.parse(
{
value: payload.value,
issues: [],
},
{
...ctx,
skipChecks: true,
},
);
if (canary instanceof Promise)
return canary.then((canary) => {
return handleCanaryResult(canary, payload, ctx);
});
return handleCanaryResult(canary, payload, ctx);
}
const result = inst._zod.parse(payload, ctx);
if (result instanceof Promise) {
if (ctx.async === false) throw new $ZodAsyncError();
return result.then((result) => runChecks(result, checks, ctx));
}
return runChecks(result, checks, ctx);
};
}
},
{
get "~standard"() {
return hide(this, "~standard", standardProps(this));
},
set "~standard"(value) {
own(this, "~standard", value);
},
},
);
const toStandardResult = (r, ctx) =>
r.issues.length
? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) }
: { value: r.value };
async function validateAsync(inst, value) {
const ctx = { async: true };
return toStandardResult(
await inst._zod.run(
{
value,
issues: [],
},
ctx,
),
ctx,
);
}
function standardProps(inst) {
return {
validate: (value) => {
const ctx = { async: false };
try {
const r = inst._zod.run(
{
value,
issues: [],
},
ctx,
);
if (!(r instanceof Promise)) return toStandardResult(r, ctx);
} catch (_) {}
return validateAsync(inst, value);
},
vendor: "zod",
version: 1,
};
}
const $ZodString = $constructor("$ZodString", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = def.pattern ?? anyString;
inst._zod.parse = (payload, _) => {
if (def.coerce)
try {
payload.value = String(payload.value);
} catch (_) {}
if (typeof payload.value === "string") return payload;
payload.issues.push({
expected: "string",
code: "invalid_type",
input: payload.value,
inst,
});
return payload;
};
});
const $ZodStringFormat = $constructor("$ZodStringFormat", (inst, def) => {
$ZodCheckStringFormat.init(inst, def);
$ZodString.init(inst, def);
});
function canParseURL(input) {
try {
if (typeof URL !== "undefined" && typeof URL.canParse === "function")
return URL.canParse(input);
new URL(input);
return true;
} catch {
return false;
}
}
function validateURL(trimmed, def) {
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def))
return canParseURL(trimmed) || 2;
return parseURLObject(trimmed, def);
}
function parseURLObject(trimmed, def) {
if (
!def.normalize &&
def.protocol?.source === httpProtocol.source &&
!/^https?:\/\//i.test(trimmed)
)
return 1;
try {
if (typeof URL !== "undefined") {
const URLStatic = URL;
if (typeof URLStatic.parse === "function") return URLStatic.parse(trimmed) ?? 2;
}
return new URL(trimmed);
} catch {
return 2;
}
}
const asciiTabOrNewline = /[\t\n\r]/g;
function stripTabAndNewline(value) {
return value.replace(asciiTabOrNewline, "");
}
function urlHostnameOk(url, hostname) {
hostname.lastIndex = 0;
return hostname.test(url.hostname);
}
function urlProtocolOk(url, protocol) {
protocol.lastIndex = 0;
return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
}
const $ZodURL = $constructor("$ZodURL", (inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
try {
const trimmed = payload.value.trim();
const url = validateURL(trimmed, def);
if (url === 1) {
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid URL format",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === 2) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
if (url === true) {
payload.value = stripTabAndNewline(trimmed);
return;
}
if (def.hostname && !urlHostnameOk(url, def.hostname))
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid hostname",
pattern: def.hostname.source,
input: payload.value,
inst,
continue: !def.abort,
});
if (def.protocol && !urlProtocolOk(url, def.protocol))
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid protocol",
pattern: def.protocol.source,
input: payload.value,
inst,
continue: !def.abort,
});
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
return;
} catch (_) {
payload.issues.push({
code: "invalid_format",
format: "url",
input: payload.value,
inst,
continue: !def.abort,
});
}
};
});
const $ZodNumber = $constructor("$ZodNumber", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.pattern = number$1;
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = Number(payload.value);
} catch (_) {}
const input = payload.value;
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
const received =
typeof input === "number"
? Number.isNaN(input)
? "NaN"
: !Number.isFinite(input)
? String(input)
: void 0
: void 0;
payload.issues.push({
expected: "number",
code: "invalid_type",
input,
inst,
...(received ? { received } : {}),
});
return payload;
};
});
const $ZodDate = $constructor("$ZodDate", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
if (def.coerce)
try {
payload.value = new Date(payload.value);
} catch (_err) {}
const input = payload.value;
const isDate = input instanceof Date;
if (isDate && !Number.isNaN(input.getTime())) return payload;
payload.issues.push({
expected: "date",
code: "invalid_type",
input,
...(isDate ? { received: "Invalid Date" } : {}),
inst,
});
return payload;
};
});
function capSize(inst, size) {
const caps = sizeCaps(inst._zod.def.checks);
if (!caps.length) return;
const cap = Math.min(...caps.map((c) => c[0]));
const parse = inst._zod.parse;
inst._zod.parse = (payload, ctx) => {
const n = size(payload.value);
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
for (const [max, ch] of sizeCaps(inst._zod.def.checks))
if (n > max && ch._zod.def.when(payload)) {
const start = payload.issues.length;
ch._zod.check(payload);
payload.issues[start].continue = false;
attachSchema(payload.issues, start, inst);
return payload;
}
}
return parse(payload, ctx);
};
}
const arraySize = (input) => (Array.isArray(input) ? input.length : -1);
function handleArrayResult(result, final, index) {
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
final.value[index] = result.value;
}
const $ZodArray = $constructor("$ZodArray", (inst, def) => {
$ZodType.init(inst, def);
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
if (!Array.isArray(input)) {
payload.issues.push({
expected: "array",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo
? memo.alloc(inst, payload, Array(input.length), ctx)
: Array(input.length);
const proms = [];
const abortEarly = ctx?.abortEarly;
for (let i = 0; i < input.length; i++) {
const item = input[i];
const result = def.element._zod.run(
{
value: item,
issues: [],
},
ctx,
);
if (result instanceof Promise)
proms.push(result.then((result) => handleArrayResult(result, payload, i)));
else {
handleArrayResult(result, payload, i);
if (abortEarly && result.issues.length !== 0 && aborted(result)) break;
}
}
if (proms.length) return Promise.all(proms).then(() => payload);
return payload;
};
capSize(inst, arraySize);
});
function handlePropertyResult(result, final, key, input, optin, optout) {
const isPresent = key in input;
const isOptionalOut = optout === "optional";
if (!isPresent && isOptionalOut && optin === "optional") return;
if (result.issues.length) {
if (optin !== void 0 && isOptionalOut && !isPresent) return;
final.issues.push(...prefixIssues(key, result.issues));
}
if (!isPresent && optin === void 0) {
if (!result.issues.length)
final.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: void 0,
path: [key],
});
return;
}
if (result.value === void 0) {
if (isPresent || (optin === "defaulted" && !isOptionalOut)) final.value[key] = void 0;
} else final.value[key] = result.value;
}
const NO_SYMBOL_KEYS = [];
function normalizeDef(def) {
const keys = Object.keys(def.shape);
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
for (const k of allKeys)
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType"))
throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
const okeys = optionalKeys(def.shape);
return {
...def,
allKeys,
symbolKeys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
}
function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
const unrecognized = [];
const keySet = def.keySet;
const _catchall = def.catchall._zod;
const t = _catchall.def.type;
const optin = _catchall.optin;
const optout = _catchall.optout;
let seen = 0;
for (const key in input) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (keySet.has(key)) continue;
if (key === "__proto__") {
if (t === "never") unrecognized.push(key);
continue;
}
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
else handlePropertyResult(r, payload, key, input, optin, optout);
}
if (unrecognized.length)
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
continue: true,
});
if (!proms.length) return payload;
return Promise.all(proms).then(() => {
return payload;
});
}
const $ZodObject = $constructor("$ZodObject", (inst, def) => {
$ZodType.init(inst, def);
const desc = Object.getOwnPropertyDescriptor(def, "shape");
const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
if (sh) {
const get = () => {
const newSh = { ...sh };
Object.defineProperty(def, "shape", { value: newSh });
get.raw = newSh;
return newSh;
};
get.raw = sh;
Object.defineProperty(def, "shape", { get });
}
const _normalized = cached(() => normalizeDef(def));
defineLazyInternal(inst, "propValues", (zod) => {
const shape = zod.def.shape;
const propValues = {};
for (const key in shape) {
const field = shape[key]._zod;
if (field.values) {
if (!Object.prototype.hasOwnProperty.call(propValues, key))
assignProp(propValues, key, new Set());
for (const v of field.values) propValues[key].add(v);
if (field.optin !== void 0) propValues[key].add(void 0);
}
}
return propValues;
});
const isObject$1 = isObject;
const catchall = def.catchall;
let value;
const memo = globalConfig.memoizer;
memo?.attach(inst);
inst._zod.parse = (payload, ctx) => {
value ?? (value = _normalized.value);
const input = payload.value;
if (!isObject$1(input)) {
payload.issues.push({
expected: "object",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
const proms = [];
const shape = value.shape;
const abortEarly = ctx?.abortEarly;
let seen = payload.issues.length;
for (const key of value.allKeys) {
if (abortEarly && payload.issues.length !== seen) {
if (aborted(payload, seen)) break;
seen = payload.issues.length;
}
if (key === "__proto__") continue;
const el = shape[key];
const optin = el._zod.optin;
const optout = el._zod.optout;
const r = el._zod.run(
{
value: input[key],
issues: [],
},
ctx,
);
if (r instanceof Promise)
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
else handlePropertyResult(r, payload, key, input, optin, optout);
}
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
};
});
const $ZodEnum = $constructor("$ZodEnum", (inst, def) => {
$ZodType.init(inst, def);
const values = getEnumValues(def.entries);
const valuesSet = new Set(values);
inst._zod.values = valuesSet;
defineLazyInternal(inst, "pattern", (zod) => {
const patternValues = getEnumValues(zod.def.entries).filter((k) =>
propertyKeyTypes.has(typeof k),
);
return new RegExp(
patternValues.length
? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$`
: "^[^\\s\\S]$",
);
});
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (valuesSet.has(input)) return payload;
payload.issues.push({
code: "invalid_value",
values,
input,
inst,
});
return payload;
};
});
const $ZodNullable = $constructor("$ZodNullable", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
});
defineLazyInternal(inst, "values", (zod) => {
return zod.def.innerType._zod.values
? new Set([...zod.def.innerType._zod.values, null])
: void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === null) return payload;
return def.innerType._zod.run(payload, ctx);
};
});
function snapshotChecks(def) {
if (def.checks) def.checks = [...def.checks];
return def;
}
function _string(Class, params) {
return new Class(
snapshotChecks({
type: "string",
...normalizeParams(params),
}),
);
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _maxLength(maximum, params) {
return new $ZodCheckMaxLength({
check: "max_length",
...normalizeParams(params),
maximum,
});
}
function _minLength(minimum, params) {
return new $ZodCheckMinLength({
check: "min_length",
...normalizeParams(params),
minimum,
});
}
const ZodMiniType = $constructor(
"ZodMiniType",
(inst, def) => {
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
},
{
get with() {
return this.check;
},
set with(value) {
own(this, "with", value);
},
parse(data, params) {
return parse(this, data, params, { callee: this.parse });
},
parseAsync(data, params) {
return parseAsync(this, data, params, { callee: this.parseAsync });
},
safeParse(data, params) {
return safeParse(this, data, params);
},
safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
check(...checks) {
const def = this.def;
return this.clone(
{
...def,
checks: [
...(def.checks ?? []),
...checks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
},
{ parent: true },
);
},
clone(_def, params) {
return clone(this, _def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
apply(fn, ...args) {
return args.length === 0 ? fn(this) : fn(this, ...args);
},
},
);
const ZodMiniString = $constructor("ZodMiniString", (inst, def) => {
$ZodString.init(inst, def);
ZodMiniType.init(inst, def);
});
function string(params) {
return _string(ZodMiniString, params);
}
const ZodMiniStringFormat = $constructor("ZodMiniStringFormat", (inst, def) => {
$ZodStringFormat.init(inst, def);
ZodMiniString.init(inst, def);
});
const ZodMiniURL = $constructor("ZodMiniURL", (inst, def) => {
$ZodURL.init(inst, def);
ZodMiniStringFormat.init(inst, def);
});
function url(params) {
return _url(ZodMiniURL, params);
}
const ZodMiniNumber = $constructor("ZodMiniNumber", (inst, def) => {
$ZodNumber.init(inst, def);
ZodMiniType.init(inst, def);
});
function number(params) {
return _number(ZodMiniNumber, params);
}
const ZodMiniDate = $constructor("ZodMiniDate", (inst, def) => {
$ZodDate.init(inst, def);
ZodMiniType.init(inst, def);
});
function date(params) {
return _date(ZodMiniDate, params);
}
const ZodMiniArray = $constructor("ZodMiniArray", (inst, def) => {
$ZodArray.init(inst, def);
ZodMiniType.init(inst, def);
});
function array(element, params) {
return new ZodMiniArray({
type: "array",
element,
...normalizeParams(params),
});
}
const ZodMiniObject = $constructor("ZodMiniObject", (inst, def) => {
$ZodObject.init(inst, def);
ZodMiniType.init(inst, def);
installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
});
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodMiniObject(def);
}
const ZodMiniEnum = $constructor("ZodMiniEnum", (inst, def) => {
$ZodEnum.init(inst, def);
ZodMiniType.init(inst, def);
inst.options = [...inst._zod.values];
});
function _enum(values, params) {
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
return new ZodMiniEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodMiniNullable = $constructor("ZodMiniNullable", (inst, def) => {
$ZodNullable.init(inst, def);
ZodMiniType.init(inst, def);
});
function nullable(innerType) {
return new ZodMiniNullable({
type: "nullable",
innerType,
});
}
const imageSchema = object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().check( _gte(1), _lte(5)),
title: string().check(
_minLength(1),
_maxLength(100),
),
text: string().check(
_minLength(1),
_maxLength(1e3),
),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().check(
_minLength(1),
_maxLength(100),
),
brand: string().check(
_minLength(1),
_maxLength(30),
),
description: string().check(
_minLength(1),
_maxLength(500),
),
price: number().check( _gte(1), _lte(1e4)),
discount: nullable(
number().check( _gte(1), _lte(100)),
),
quantity: number().check( _gte(0), _lte(10)),
tags: array(
string().check( _minLength(1), _maxLength(30)),
),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
).parse({});