schemas/libraries/zod-compiler/download_compiled/bag/unminified.js
schemas/libraries/zod-compiler/download_compiled/bag/unminified.js
schemas/libraries/zod-compiler/download_compiled/bag/unminified.js
schemas/libraries/zod-compiler/download_compiled/bag/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 joinValues(
array,
separator = "|",
) {
return array
.map((val) =>
stringifyPrimitive(val),
)
.join(separator);
}
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 floatSafeRemainder(val, step) {
const ratio = val / step;
const roundedRatio =
Math.round(ratio);
const tolerance =
4 *
Number.EPSILON *
Math.max(Math.abs(ratio), 1);
if (
Math.abs(ratio - roundedRatio) <
tolerance
)
return 0;
return ratio - roundedRatio;
}
function assignProp(
target,
prop,
value,
) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
function rawShape(def) {
const desc =
Object.getOwnPropertyDescriptor(
def,
"shape",
);
return desc?.get
? desc.get.raw
: desc?.value;
}
function sourceShape(schema) {
return (
rawShape(schema._zod.def) ??
schema._zod.def.shape
);
}
function deferProp(
target,
key,
getter,
) {
Object.defineProperty(target, key, {
get() {
const value = getter();
assignProp(this, key, value);
return value;
},
enumerable: true,
configurable: true,
});
}
function putProp(target, key, value) {
if (key in target)
assignProp(target, key, value);
else target[key] = value;
}
function mirrorShape(
target,
source,
keys,
wrap,
) {
const raw = sourceShape(source);
for (const key of keys) {
const desc =
Object.getOwnPropertyDescriptor(
raw,
key,
);
if (!desc.enumerable) continue;
if (desc.get)
deferProp(target, key, () => {
const value =
source._zod.def.shape[key];
return wrap
? wrap(value, key)
: value;
});
else
putProp(
target,
key,
wrap
? wrap(desc.value, key)
: desc.value,
);
}
}
function mirrorProps(target, source) {
for (const key of Reflect.ownKeys(
source,
)) {
const desc =
Object.getOwnPropertyDescriptor(
source,
key,
);
if (!desc.enumerable) continue;
if (desc.get)
deferProp(
target,
key,
() => source[key],
);
else
putProp(target, key, desc.value);
}
}
function mergeDefs(...defs) {
const mergedDescriptors = {};
for (const def of defs) {
const descriptors =
Object.getOwnPropertyDescriptors(
def,
);
Object.assign(
mergedDescriptors,
descriptors,
);
}
return Object.defineProperties(
{},
mergedDescriptors,
);
}
function esc(str) {
return JSON.stringify(str);
}
function slugify(input) {
return input
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, "")
.replace(/[\s_-]+/g, "-")
.replace(/^-+|-+$/g, "");
}
const captureStackTrace =
"captureStackTrace" in Error
? Error.captureStackTrace
: (..._args) => {};
function isObject(data) {
return (
typeof data === "object" &&
data !== null &&
!Array.isArray(data)
);
}
const allowsEval =
cached(() => {
if (globalConfig.jitless)
return false;
if (
typeof navigator !==
"undefined" &&
navigator?.userAgent?.includes(
"Cloudflare",
)
)
return false;
try {
new Function("");
return true;
} catch (_) {
return false;
}
});
function isPlainObject(o) {
if (isObject(o) === false)
return false;
const ctor = o.constructor;
if (ctor === void 0) return true;
if (typeof ctor !== "function")
return true;
const prot = ctor.prototype;
if (isObject(prot) === false)
return false;
if (
Object.prototype.hasOwnProperty.call(
prot,
"isPrototypeOf",
) === false
)
return false;
return true;
}
function shallowClone(o) {
if (isPlainObject(o)) return { ...o };
if (Array.isArray(o)) return [...o];
if (o instanceof Map)
return new Map(o);
if (o instanceof Set)
return new Set(o);
return o;
}
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 stringifyPrimitive(value) {
if (typeof value === "bigint")
return value.toString() + "n";
if (typeof value === "string")
return `"${value}"`;
return `${value}`;
}
function optionalKeys(shape) {
return Object.keys(shape).filter(
(k) => {
return (
shape[k]._zod.optin !==
void 0 &&
shape[k]._zod.optout ===
"optional"
);
},
);
}
const NUMBER_FORMAT_RANGES =
(() => ({
safeint: [
Number.MIN_SAFE_INTEGER,
Number.MAX_SAFE_INTEGER,
],
int32: [-2147483648, 2147483647],
uint32: [0, 4294967295],
float32: [
-34028234663852886e22,
34028234663852886e22,
],
float64: [
-Number.MAX_VALUE,
Number.MAX_VALUE,
],
}))();
const BIGINT_FORMAT_RANGES = {
int64: [
BigInt(
"-9223372036854775808",
),
BigInt(
"9223372036854775807",
),
],
uint64: [
BigInt(0),
BigInt(
"18446744073709551615",
),
],
};
function pick(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".pick() cannot be used on object schemas containing refinements",
);
const newShape = {};
mirrorShape(
newShape,
schema,
maskedKeys(schema, mask),
);
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function maskedKeys(schema, mask) {
const raw = sourceShape(schema);
const keys = [];
for (const key of Reflect.ownKeys(
mask,
)) {
if (
!Object.getOwnPropertyDescriptor(
raw,
key,
)?.enumerable
)
throw new Error(
`Unrecognized key: "${String(key)}"`,
);
if (mask[key]) keys.push(key);
}
return keys;
}
function omit(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".omit() cannot be used on object schemas containing refinements",
);
const omitted = new Set(
maskedKeys(schema, mask),
);
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(
sourceShape(schema),
).filter(
(key) => !omitted.has(key),
),
);
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function extend(schema, shape) {
if (!isPlainObject(shape))
throw new Error(
"Invalid input to extend: expected a plain object",
);
const checks = schema._zod.def.checks;
if (checks && checks.length > 0) {
const existingShape =
sourceShape(schema);
for (const key of Reflect.ownKeys(
shape,
))
if (
Object.getOwnPropertyDescriptor(
existingShape,
key,
) !== void 0
)
throw new Error(
"Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.",
);
}
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: extended(schema, shape),
}),
);
}
function extended(schema, shape) {
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(
sourceShape(schema),
),
);
mirrorProps(newShape, shape);
return newShape;
}
function safeExtend(schema, shape) {
if (!isPlainObject(shape))
throw new Error(
"Invalid input to safeExtend: expected a plain object",
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: extended(schema, shape),
}),
);
}
function merge(a, b) {
if (!b?._zod?.def)
throw new Error(
"Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.",
);
if (a._zod.def.checks?.length)
throw new Error(
".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.",
);
const newShape = {};
mirrorShape(
newShape,
a,
Reflect.ownKeys(sourceShape(a)),
);
mirrorShape(
newShape,
b,
Reflect.ownKeys(sourceShape(b)),
);
return clone(
a,
mergeDefs(a._zod.def, {
shape: newShape,
get catchall() {
return b._zod.def.catchall;
},
checks: b._zod.def.checks ?? [],
}),
);
}
function partial(
Class,
schema,
mask,
name = "partial",
) {
const checks = schema._zod.def.checks;
if (checks && checks.length > 0)
throw new Error(
`.${name}() cannot be used on object schemas containing refinements`,
);
const selected = mask
? new Set(maskedKeys(schema, mask))
: void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(
sourceShape(schema),
),
Class &&
((value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "optional",
innerType: value,
})),
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: newShape,
checks: [],
}),
);
}
function required(Class, schema, mask) {
const selected = mask
? new Set(maskedKeys(schema, mask))
: void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(
sourceShape(schema),
),
(value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "nonoptional",
innerType: value,
}),
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: newShape,
}),
);
}
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 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 parsedType(data) {
const t = typeof data;
switch (t) {
case "number":
return Number.isNaN(data)
? "nan"
: "number";
case "object": {
if (data === null) return "null";
if (Array.isArray(data))
return "array";
const obj = data;
if (
obj &&
Object.getPrototypeOf(obj) !==
Object.prototype &&
"constructor" in obj &&
obj.constructor
)
return obj.constructor.name;
}
}
return t;
}
function issue(...args) {
const [iss, input, inst] = args;
if (typeof iss === "string")
return {
message: iss,
code: "custom",
input,
inst,
};
return { ...iss };
}
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 derived(computes, table) {
for (const key in computes) {
const compute = computes[key];
Object.defineProperty(table, key, {
configurable: true,
enumerable: true,
get() {
return own(
this,
key,
compute(this),
);
},
set(value) {
own(this, key, value);
},
});
}
return table;
}
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,
});
},
});
}
const CONSTANT_CATCH = "~constantCatch";
function constantCatch(value) {
const fn = () => value;
fn[CONSTANT_CATCH] = true;
return fn;
}
var _a$1;
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.`,
);
}
};
var $ZodEncodeError = class extends Error {
constructor(name) {
super(
`Encountered unidirectional transform during encode: ${name}`,
);
this.name = "ZodEncodeError";
}
};
(_a$1 = globalThis)
.__zod_globalConfig ??
(_a$1.__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$1 = (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 $ZodError = $constructor(
"$ZodError",
initializer$1,
);
$constructor(
"$ZodError",
initializer$1,
void 0,
{ Parent: Error },
);
function node(obj, key, make) {
if (
!Object.prototype.hasOwnProperty.call(
obj,
key,
)
) {
if (key === "__proto__")
Object.defineProperty(obj, key, {
value: make(),
writable: true,
enumerable: true,
configurable: true,
});
else obj[key] = make();
}
return obj[key];
}
function flattenError(
error,
mapper = (issue) => issue.message,
) {
const fieldErrors = {};
const formErrors = [];
for (const sub of error.issues)
if (sub.path.length > 0)
node(
fieldErrors,
sub.path[0],
() => [],
).push(mapper(sub));
else formErrors.push(mapper(sub));
return {
formErrors,
fieldErrors,
};
}
function formatError(
error,
mapper = (issue) => issue.message,
) {
const fieldErrors = { _errors: [] };
const processError = (
error,
path = [],
) => {
for (const issue of error.issues)
if (
issue.code ===
"invalid_union" &&
issue.errors.length
)
issue.errors.map((issues) =>
processError({ issues }, [
...path,
...issue.path,
]),
);
else if (
issue.code === "invalid_key"
)
processError(
{ issues: issue.issues },
[...path, ...issue.path],
);
else if (
issue.code === "invalid_element"
)
processError(
{ issues: issue.issues },
[...path, ...issue.path],
);
else {
const fullpath = [
...path,
...issue.path,
];
if (fullpath.length === 0)
fieldErrors._errors.push(
mapper(issue),
);
else {
let curr = fieldErrors;
let i = 0;
while (i < fullpath.length) {
const el = fullpath[i];
const terminal =
i === fullpath.length - 1;
if (el === "_errors") {
if (terminal)
curr._errors.push(
mapper(issue),
);
i++;
continue;
}
if (
!Object.prototype.hasOwnProperty.call(
curr,
el,
)
)
Object.defineProperty(
curr,
el,
{
value: {
_errors: [],
},
enumerable: true,
writable: true,
configurable: true,
},
);
const node = curr[el];
if (terminal)
node._errors.push(
mapper(issue),
);
curr = node;
i++;
}
}
}
};
processError(error);
return fieldErrors;
}
function finalizeParams(
callee,
params,
) {
return {
callee: params?.callee ?? callee,
Err: params?.Err,
};
}
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 _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 _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,
};
};
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 COMPILE_INVALID =
Symbol.for(
"zod.compile.invalid",
);
const COMPILE_FALLBACK =
Symbol.for(
"zod.compile.fallback",
);
const validate = (
schema,
value,
_ctx,
) => {
const validator =
schema._zod.bag.validator;
if (validator !== void 0) {
if (
validator(value) !==
COMPILE_INVALID
)
return true;
if (
validator.definite === true &&
_ctx === void 0
)
return false;
}
return validateFallback(
schema,
value,
_ctx,
);
};
function validateFallback(
schema,
value,
_ctx,
) {
const ctx = _ctx
? {
..._ctx,
async: false,
abortEarly: true,
}
: {
async: false,
abortEarly: true,
};
const fallbackRun =
schema._zod.bag.fallbackRun;
let result;
if (fallbackRun) {
ctx[COMPILE_FALLBACK] = true;
result = fallbackRun(
{
value,
issues: [],
},
ctx,
);
} else
result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
throw new $ZodAsyncError();
return result.issues.length === 0;
}
const validateAsync$1 = async (
schema,
value,
_ctx,
) => {
const ctx = _ctx
? {
..._ctx,
async: true,
abortEarly: true,
}
: {
async: true,
abortEarly: true,
};
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
result = await result;
return result.issues.length === 0;
};
const _encode = (_Err) => {
const parse = _parse(_Err);
const fn = (
schema,
value,
_ctx,
_params,
) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return parse(
schema,
value,
ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _decode = (_Err) => {
const parse = _parse(_Err);
const fn = (
schema,
value,
_ctx,
_params,
) => {
return parse(
schema,
value,
_ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _encodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (
schema,
value,
_ctx,
_params,
) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return await parseAsync(
schema,
value,
ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _decodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (
schema,
value,
_ctx,
_params,
) => {
return await parseAsync(
schema,
value,
_ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _safeEncode =
(_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParse(_Err)(
schema,
value,
ctx,
);
};
const _safeDecode =
(_Err) => (schema, value, _ctx) => {
return _safeParse(_Err)(
schema,
value,
_ctx,
);
};
const _safeEncodeAsync =
(_Err) =>
async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParseAsync(_Err)(
schema,
value,
ctx,
);
};
const _safeDecodeAsync =
(_Err) =>
async (schema, value, _ctx) => {
return _safeParseAsync(_Err)(
schema,
value,
_ctx,
);
};
const cuid = /^[cC][0-9a-z]{6,}$/;
const cuid2 = /^[0-9a-z]+$/;
const ulid =
/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
const xid = /^[0-9a-vA-V]{20}$/;
const ksuid = /^[A-Za-z0-9]{27}$/;
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
function nanoidOfLength(length) {
return new RegExp(
`^[a-zA-Z0-9_-]{${length}}$`,
);
}
const duration =
/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
const guid =
/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
const uuid = (version) => {
if (!version)
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
return new RegExp(
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`,
);
};
const email =
/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
function emoji() {
return new RegExp(_emoji$1, "u");
}
const ipv4 =
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
const ipv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
const cidrv4 =
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
const cidrv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
const base64 =
/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
const base64url =
/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
const httpProtocol = /^https?$/;
const e164 = /^\+[1-9]\d{6,14}$/;
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
function anchor(source) {
return new RegExp(`^${source}$`);
}
const date$1 =
anchor(dateSource);
function timeSource(args) {
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
return typeof args.precision ===
"number"
? args.precision === -1
? `${hhmm}`
: args.precision === 0
? `${hhmm}:[0-5]\\d`
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
: args.seconds
? `${hhmm}:[0-5]\\d(?:\\.\\d+)?`
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
}
function time(args) {
return new RegExp(
`^${timeSource(args)}$`,
);
}
function datetime(args) {
const opts = ["Z"];
if (args.offset)
opts.push(
`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`,
);
const qualified = `${timeSource({
precision: args.precision,
seconds: true,
})}(?:${opts.join("|")})`;
const timeRegex = args.local
? `${qualified}|${timeSource({ precision: args.precision })}`
: qualified;
return new RegExp(
`^${dateSource}T(?:${timeRegex})$`,
);
}
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const lowercase = /^[^A-Z]*$/;
const uppercase = /^[^a-z]*$/;
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 $ZodCheckMultipleOf =
$constructor(
"$ZodCheckMultipleOf",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
if (
typeof payload.value !==
typeof def.value
)
throw new Error(
"Cannot mix number and bigint in multiple_of check.",
);
if (
typeof payload.value ===
"bigint"
? def.value !== BigInt(0) &&
payload.value %
def.value ===
BigInt(0)
: floatSafeRemainder(
payload.value,
def.value,
) === 0
)
return;
payload.issues.push({
origin: typeof payload.value,
code: "not_multiple_of",
divisor: def.value,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckNumberFormat =
$constructor(
"$ZodCheckNumberFormat",
(inst, def) => {
$ZodCheck.init(inst, def);
def.format =
def.format || "float64";
const isInt =
def.format?.includes("int");
const origin = isInt
? "int"
: "number";
const [minimum, maximum] =
NUMBER_FORMAT_RANGES[
def.format
];
inst._zod.check = (payload) => {
const input = payload.value;
if (isInt) {
if (
!Number.isInteger(input)
) {
payload.issues.push({
expected: origin,
format: def.format,
code: "invalid_type",
continue: false,
input,
inst,
});
return;
}
if (
!Number.isSafeInteger(input)
) {
if (input > 0)
payload.issues.push({
input,
code: "too_big",
maximum:
Number.MAX_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
else
payload.issues.push({
input,
code: "too_small",
minimum:
Number.MIN_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
return;
}
}
if (input < minimum)
payload.issues.push({
origin: "number",
input,
code: "too_small",
minimum,
inclusive: true,
inst,
continue: !def.abort,
});
if (input > maximum)
payload.issues.push({
origin: "number",
input,
code: "too_big",
maximum,
inclusive: true,
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 $ZodCheckLengthEquals =
$constructor(
"$ZodCheckLengthEquals",
(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;
const length =
typeof input === "string" &&
units >= def.length &&
units <= def.length * 2
? codePointLength(input)
: units;
if (length === def.length)
return;
const origin =
getLengthableOrigin(input);
const tooBig =
length > def.length;
payload.issues.push({
origin,
...(tooBig
? {
code: "too_big",
maximum: def.length,
}
: {
code: "too_small",
minimum: def.length,
}),
inclusive: true,
exact: true,
input: payload.value,
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 $ZodCheckRegex =
$constructor(
"$ZodCheckRegex",
(inst, def) => {
$ZodCheckStringFormat.init(
inst,
def,
);
inst._zod.check = (payload) => {
def.pattern.lastIndex = 0;
if (
def.pattern.test(
payload.value,
)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "regex",
input: payload.value,
pattern:
def.pattern.toString(),
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckLowerCase =
$constructor(
"$ZodCheckLowerCase",
(inst, def) => {
def.pattern ??
(def.pattern = lowercase);
$ZodCheckStringFormat.init(
inst,
def,
);
},
);
const $ZodCheckUpperCase =
$constructor(
"$ZodCheckUpperCase",
(inst, def) => {
def.pattern ??
(def.pattern = uppercase);
$ZodCheckStringFormat.init(
inst,
def,
);
},
);
const $ZodCheckIncludes =
$constructor(
"$ZodCheckIncludes",
(inst, def) => {
$ZodCheck.init(inst, def);
const escapedRegex = escapeRegex(
def.includes,
);
def.pattern = new RegExp(
typeof def.position === "number"
? `^.{${def.position},}${escapedRegex}`
: escapedRegex,
);
inst._zod.check = (payload) => {
if (
payload.value.includes(
def.includes,
def.position,
)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "includes",
includes: def.includes,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStartsWith =
$constructor(
"$ZodCheckStartsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(
`^${escapeRegex(def.prefix)}.*`,
);
def.pattern ??
(def.pattern = pattern);
inst._zod.check = (payload) => {
if (
payload.value.startsWith(
def.prefix,
)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "starts_with",
prefix: def.prefix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckEndsWith =
$constructor(
"$ZodCheckEndsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(
`.*${escapeRegex(def.suffix)}$`,
);
def.pattern ??
(def.pattern = pattern);
inst._zod.check = (payload) => {
if (
payload.value.endsWith(
def.suffix,
)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "ends_with",
suffix: def.suffix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckOverwrite =
$constructor(
"$ZodCheckOverwrite",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
payload.value = def.tx(
payload.value,
);
};
},
);
var Doc = class {
constructor(args = [], closed = {}) {
this.content = [];
this.indent = 0;
this.args = args;
this.closed = closed;
}
indented(fn) {
this.indent += 1;
try {
fn(this);
} finally {
this.indent -= 1;
}
}
write(arg) {
if (typeof arg === "function") {
arg(this, { execution: "sync" });
arg(this, { execution: "async" });
return;
}
const lines = arg
.split("\n")
.filter((x) => x);
const minIndent = Math.min(
...lines.map(
(x) =>
x.length -
x.trimStart().length,
),
);
const dedented = lines
.map((x) => x.slice(minIndent))
.map(
(x) =>
" ".repeat(this.indent * 2) +
x,
);
for (const line of dedented)
this.content.push(line);
}
compile() {
const F = Function;
const content = this?.content ?? [
``,
];
return new F(
...Object.keys(this.closed),
`return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`,
)(...Object.values(this.closed));
}
};
const version = {
major: 4,
minor: 6,
patch: 5,
};
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);
},
);
const $ZodGUID =
$constructor(
"$ZodGUID",
(inst, def) => {
def.pattern ??
(def.pattern = guid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodUUID =
$constructor(
"$ZodUUID",
(inst, def) => {
if (def.version) {
const v = {
v1: 1,
v2: 2,
v3: 3,
v4: 4,
v5: 5,
v6: 6,
v7: 7,
v8: 8,
}[def.version];
if (v === void 0)
throw new Error(
`Invalid UUID version: "${def.version}"`,
);
def.pattern ??
(def.pattern = uuid(v));
} else
def.pattern ??
(def.pattern = uuid());
$ZodStringFormat.init(inst, def);
},
);
const $ZodEmail =
$constructor(
"$ZodEmail",
(inst, def) => {
def.pattern ??
(def.pattern = email);
$ZodStringFormat.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 $ZodEmoji =
$constructor(
"$ZodEmoji",
(inst, def) => {
def.pattern ??
(def.pattern = emoji());
$ZodStringFormat.init(inst, def);
},
);
const $ZodNanoID =
$constructor(
"$ZodNanoID",
(inst, def) => {
if (
def.length !== void 0 &&
(!Number.isInteger(
def.length,
) ||
def.length < 1)
)
throw new Error(
`Invalid nanoid length: ${def.length}`,
);
def.pattern ??
(def.pattern =
def.length === void 0
? nanoid
: nanoidOfLength(
def.length,
));
$ZodStringFormat.init(inst, def);
},
);
const $ZodCUID =
$constructor(
"$ZodCUID",
(inst, def) => {
def.pattern ??
(def.pattern = cuid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodCUID2 =
$constructor(
"$ZodCUID2",
(inst, def) => {
def.pattern ??
(def.pattern = cuid2);
$ZodStringFormat.init(inst, def);
},
);
const $ZodULID =
$constructor(
"$ZodULID",
(inst, def) => {
def.pattern ??
(def.pattern = ulid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodXID =
$constructor(
"$ZodXID",
(inst, def) => {
def.pattern ??
(def.pattern = xid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodKSUID =
$constructor(
"$ZodKSUID",
(inst, def) => {
def.pattern ??
(def.pattern = ksuid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODateTime =
$constructor(
"$ZodISODateTime",
(inst, def) => {
def.pattern ??
(def.pattern = datetime(def));
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODate =
$constructor(
"$ZodISODate",
(inst, def) => {
def.pattern ??
(def.pattern = date$1);
$ZodStringFormat.init(inst, def);
},
);
const $ZodISOTime =
$constructor(
"$ZodISOTime",
(inst, def) => {
def.pattern ??
(def.pattern = time(def));
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODuration =
$constructor(
"$ZodISODuration",
(inst, def) => {
def.pattern ??
(def.pattern = duration);
$ZodStringFormat.init(inst, def);
},
);
const $ZodIPv4 =
$constructor(
"$ZodIPv4",
(inst, def) => {
def.pattern ??
(def.pattern = ipv4);
$ZodStringFormat.init(inst, def);
},
);
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
function isValidIPv6(value) {
if (!ipv6Alphabet.test(value))
return false;
return canParseURL(
`http://[${value}]`,
);
}
const $ZodIPv6 =
$constructor(
"$ZodIPv6",
(inst, def) => {
def.pattern ??
(def.pattern = ipv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidIPv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "ipv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCIDRv4 =
$constructor(
"$ZodCIDRv4",
(inst, def) => {
def.pattern ??
(def.pattern = cidrv4);
$ZodStringFormat.init(inst, def);
},
);
function isValidCIDRv6(value) {
const parts = value.split("/");
if (parts.length !== 2) return false;
const [address, prefix] = parts;
if (!prefix) return false;
const prefixNum = Number(prefix);
if (`${prefixNum}` !== prefix)
return false;
if (prefixNum < 0 || prefixNum > 128)
return false;
return isValidIPv6(address);
}
const $ZodCIDRv6 =
$constructor(
"$ZodCIDRv6",
(inst, def) => {
def.pattern ??
(def.pattern = cidrv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (
!isValidCIDRv6(payload.value)
)
payload.issues.push({
code: "invalid_format",
format: "cidrv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
function isValidBase64(data) {
if (data === "") return true;
if (/\s/.test(data)) return false;
if (data.length % 4 !== 0)
return false;
try {
atob(data);
return true;
} catch {
return false;
}
}
const base64Charset =
/^[0-9a-zA-Z+/]*={0,2}$/;
const $ZodBase64 =
$constructor(
"$ZodBase64",
(inst, def) => {
def.pattern ??
(def.pattern = base64Charset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (
isValidBase64(payload.value)
)
return;
payload.issues.push({
code: "invalid_format",
format: "base64",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const base64urlCharset =
/^[A-Za-z0-9_-]*$/;
function isValidBase64URL(data) {
if (!base64urlCharset.test(data))
return false;
const base64 = data.replace(
/[-_]/g,
(c) => (c === "-" ? "+" : "/"),
);
return isValidBase64(
base64.padEnd(
Math.ceil(base64.length / 4) * 4,
"=",
),
);
}
const $ZodBase64URL =
$constructor(
"$ZodBase64URL",
(inst, def) => {
def.pattern ??
(def.pattern =
base64urlCharset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (
isValidBase64URL(
payload.value,
)
)
return;
payload.issues.push({
code: "invalid_format",
format: "base64url",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodE164 =
$constructor(
"$ZodE164",
(inst, def) => {
def.pattern ??
(def.pattern = e164);
$ZodStringFormat.init(inst, def);
},
);
function isValidJWT(
token,
algorithm = null,
) {
try {
const tokensParts =
token.split(".");
if (tokensParts.length !== 3)
return false;
const [header] = tokensParts;
if (!header) return false;
const parsedHeader = JSON.parse(
atob(header),
);
if (
"typ" in parsedHeader &&
parsedHeader?.typ !== "JWT"
)
return false;
if (!parsedHeader.alg) return false;
if (
algorithm &&
(!("alg" in parsedHeader) ||
parsedHeader.alg !== algorithm)
)
return false;
return true;
} catch {
return false;
}
}
const $ZodJWT =
$constructor(
"$ZodJWT",
(inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (
isValidJWT(
payload.value,
def.alg,
)
)
return;
payload.issues.push({
code: "invalid_format",
format: "jwt",
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 $ZodNumberFormat =
$constructor(
"$ZodNumberFormat",
(inst, def) => {
$ZodCheckNumberFormat.init(
inst,
def,
);
$ZodNumber.init(inst, def);
},
);
const $ZodUnknown =
$constructor(
"$ZodUnknown",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload) =>
payload;
},
);
const $ZodNever =
$constructor(
"$ZodNever",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (
payload,
_ctx,
) => {
payload.issues.push({
expected: "never",
code: "invalid_type",
input: payload.value,
inst,
});
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 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;
};
},
);
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$2 = 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$2(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 $ZodObjectJIT =
$constructor(
"$ZodObjectJIT",
(inst, def) => {
$ZodObject.init(inst, def);
const superParse =
inst._zod.parse;
const _normalized = cached(() =>
normalizeDef(def),
);
const memo =
globalConfig.memoizer;
const generateFastpass = (
shape,
) => {
const normalized =
_normalized.value;
const syms =
normalized.symbolKeys;
const doc = new Doc(
["payload", "ctx"],
{
shape,
inst,
memo,
syms,
},
);
const parseStr = (k) =>
`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
const prefixStr = (id, k) => `
let ${id}_ab = false;
for (let i = 0; i < ${id}.issues.length; i++) {
const iss = ${id}.issues[i];
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
payload.issues.push(iss);
if (iss.continue !== true) ${id}_ab = true;
}
if (${id}_ab && ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}`;
doc.write(
`const input = payload.value;`,
);
const ids = Object.create(null);
let counter = 0;
for (const key of normalized.allKeys)
ids[key] = `key_${counter++}`;
doc.write(
memo
? `const newResult = memo.alloc(inst, payload, {}, ctx);`
: `const newResult = {};`,
);
for (const key of normalized.allKeys) {
if (key === "__proto__")
continue;
const id = ids[key];
const k =
typeof key === "symbol"
? `syms[${syms.indexOf(key)}]`
: esc(key);
const isPresent = `${k} in input`;
const schema = shape[key];
const optin =
schema?._zod?.optin;
const isOptionalIn =
optin !== void 0;
const isOptionalOut =
schema?._zod?.optout ===
"optional";
doc.write(
`const ${id} = ${parseStr(k)};`,
);
if (
isOptionalIn &&
isOptionalOut
) {
const assign =
optin === "optional"
? `${id}_present`
: `${id}.value !== undefined || ${id}_present`;
doc.write(`
const ${id}_present = ${isPresent};
if (!${id}.issues.length || ${id}_present) {
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (${assign}) {
newResult[${k}] = ${id}.value;
}
}
`);
} else if (!isOptionalIn)
doc.write(`
const ${id}_present = ${isPresent};
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (!${id}_present && !${id}.issues.length) {
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [${k}]
});
if (ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}
}
if (${id}_present) {
newResult[${k}] = ${id}.value;
}
`);
else {
doc.write(`
if (${id}.issues.length) {${prefixStr(id, k)}
}
`);
if (optin === "defaulted")
doc.write(
`newResult[${k}] = ${id}.value;`,
);
else
doc.write(`
if (${id}.value !== undefined || ${isPresent}) {
newResult[${k}] = ${id}.value;
}
`);
}
}
doc.write(
`payload.value = newResult;`,
);
doc.write(`return payload;`);
return doc.compile();
};
let fastpass;
const isObject$1 = isObject;
const jit = !globalConfig.jitless;
const fastEnabled =
jit && allowsEval.value;
const catchall = def.catchall;
let value;
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;
}
if (
jit &&
fastEnabled &&
ctx?.async === false &&
ctx.jitless !== true
) {
if (!fastpass)
fastpass = generateFastpass(
def.shape,
);
payload = fastpass(
payload,
ctx,
);
if (!catchall) return payload;
return handleCatchall(
[],
input,
payload,
ctx,
value,
inst,
ctx?.abortEarly === true,
);
}
return superParse(payload, ctx);
};
},
);
function handleUnionResults(
results,
final,
inst,
ctx,
) {
for (const result of results)
if (result.issues.length === 0) {
final.value = result.value;
return final;
}
const nonaborted = results.filter(
(r) => !aborted(r),
);
if (nonaborted.length === 1) {
final.value = nonaborted[0].value;
return nonaborted[0];
}
final.issues.push({
code: "invalid_union",
input: final.value,
inst,
errors: results.map((result) =>
result.issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
),
});
return final;
}
const $ZodUnion =
$constructor(
"$ZodUnion",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"optin",
(zod) =>
zod.def.options.some(
(o) =>
o._zod.optin ===
"defaulted",
)
? "defaulted"
: zod.def.options.some(
(o) =>
o._zod.optin !==
void 0,
)
? "optional"
: void 0,
);
defineLazyInternal(
inst,
"optout",
(zod) =>
zod.def.options.some(
(o) =>
o._zod.optout ===
"optional",
)
? "optional"
: void 0,
);
defineLazyInternal(
inst,
"values",
(zod) => {
if (
zod.def.options.every(
(o) => o._zod.values,
)
)
return new Set(
zod.def.options.flatMap(
(option) =>
Array.from(
option._zod.values,
),
),
);
},
);
defineLazyInternal(
inst,
"pattern",
(zod) => {
if (
zod.def.options.every(
(o) => o._zod.pattern,
)
) {
const patterns =
zod.def.options.map(
(o) => o._zod.pattern,
);
return new RegExp(
`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`,
);
}
},
);
const first =
def.options.length === 1
? def.options[0]._zod.run
: null;
inst._zod.parse = (
payload,
ctx,
) => {
if (first)
return first(payload, ctx);
let async = false;
const results = [];
for (const option of def.options) {
const result =
option._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (
result instanceof Promise
) {
results.push(result);
async = true;
} else {
if (
result.issues.length === 0
)
return result;
results.push(result);
}
}
if (!async)
return handleUnionResults(
results,
payload,
inst,
ctx,
);
return Promise.all(
results,
).then((results) => {
return handleUnionResults(
results,
payload,
inst,
ctx,
);
});
};
},
);
const $ZodIntersection =
$constructor(
"$ZodIntersection",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (
payload,
ctx,
) => {
const input = payload.value;
const left = def.left._zod.run(
{
value: input,
issues: [],
},
ctx,
);
const right =
def.right._zod.run(
{
value: input,
issues: [],
},
ctx,
);
if (
left instanceof Promise ||
right instanceof Promise
)
return Promise.all([
left,
right,
]).then(([left, right]) => {
return handleIntersectionResults(
payload,
left,
right,
);
});
return handleIntersectionResults(
payload,
left,
right,
);
};
},
);
function mergeValues(a, b) {
if (a === b)
return {
valid: true,
data: a,
};
if (
a instanceof Date &&
b instanceof Date &&
+a === +b
)
return {
valid: true,
data: a,
};
if (
isPlainObject(a) &&
isPlainObject(b)
) {
const bKeys = Object.keys(b);
const sharedKeys = Object.keys(
a,
).filter(
(key) =>
bKeys.indexOf(key) !== -1,
);
const newObj = {
...a,
...b,
};
if (
Object.prototype.hasOwnProperty.call(
newObj,
"__proto__",
)
)
delete newObj.__proto__;
for (const key of sharedKeys) {
if (key === "__proto__") continue;
const sharedValue = mergeValues(
a[key],
b[key],
);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [
key,
...sharedValue.mergeErrorPath,
],
};
newObj[key] = sharedValue.data;
}
return {
valid: true,
data: newObj,
};
}
if (
Array.isArray(a) &&
Array.isArray(b)
) {
if (a.length !== b.length)
return {
valid: false,
mergeErrorPath: [],
};
const newArray = [];
for (
let index = 0;
index < a.length;
index++
) {
const itemA = a[index];
const itemB = b[index];
const sharedValue = mergeValues(
itemA,
itemB,
);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [
index,
...sharedValue.mergeErrorPath,
],
};
newArray.push(sharedValue.data);
}
return {
valid: true,
data: newArray,
};
}
return {
valid: false,
mergeErrorPath: [],
};
}
function handleIntersectionResults(
result,
left,
right,
) {
const unrecKeys =
new Map();
let unrecIssue;
const keyIssues =
new Map();
const collect = (iss, side) => {
let keys;
if (
iss.code ===
"unrecognized_keys" &&
!iss.path?.length
) {
unrecIssue ?? (unrecIssue = iss);
keys = iss.keys;
} else if (
iss.code === "invalid_key" &&
iss.origin === "record" &&
iss.path?.length === 1
) {
const k = String(iss.path[0]);
if (!keyIssues.has(k))
keyIssues.set(k, iss);
keys = [k];
} else return false;
for (const k of keys) {
if (!unrecKeys.has(k))
unrecKeys.set(k, {});
unrecKeys.get(k)[side] = true;
}
return true;
};
for (const iss of left.issues)
if (!collect(iss, "l"))
result.issues.push(iss);
for (const iss of right.issues)
if (!collect(iss, "r"))
result.issues.push(iss);
const bothKeys = [...unrecKeys]
.filter(([, f]) => f.l && f.r)
.map(([k]) => k);
if (bothKeys.length) {
const aggregated = unrecIssue
? bothKeys.filter((k) =>
unrecIssue.keys.includes(k),
)
: [];
if (aggregated.length)
result.issues.push({
...unrecIssue,
keys: aggregated,
});
for (const k of bothKeys)
if (
!aggregated.includes(k) &&
keyIssues.has(k)
)
result.issues.push(
keyIssues.get(k),
);
}
const merged = mergeValues(
left.value,
right.value,
);
if (!merged.valid) {
if (aborted(result)) return result;
throw new Error(
`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`,
);
}
result.value = merged.data;
return result;
}
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 $ZodTransform =
$constructor(
"$ZodTransform",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "optional";
globalConfig.memoizer?.guard(
inst,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
)
throw new $ZodEncodeError(
inst.constructor.name,
);
const _out = def.transform(
payload.value,
payload,
);
if (ctx.async)
return (
_out instanceof Promise
? _out
: Promise.resolve(_out)
).then((output) => {
payload.value = output;
return payload;
});
if (_out instanceof Promise)
throw new $ZodAsyncError();
payload.value = _out;
return payload;
};
},
);
function handleOptionalResult(
payload,
result,
) {
payload.value = result.issues.length
? void 0
: result.value;
return payload;
}
const $ZodOptional =
$constructor(
"$ZodOptional",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"optin",
(zod) =>
zod.def.innerType._zod
.optin === "defaulted"
? "defaulted"
: "optional",
);
inst._zod.optout = "optional";
defineLazyInternal(
inst,
"values",
(zod) => {
const values =
zod.def.innerType._zod
.values;
return values
? new Set([
...values,
void 0,
])
: void 0;
},
);
defineLazyInternal(
inst,
"pattern",
(zod) => {
const pattern =
zod.def.innerType._zod
.pattern;
return pattern
? new RegExp(
`^(${cleanRegex(pattern.source)})?$`,
)
: void 0;
},
);
inst._zod.parse = (
payload,
ctx,
) => {
if (payload.value === void 0) {
if (
def.innerType._zod.optin !==
"defaulted"
)
return payload;
const result =
def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then(
(result) =>
handleOptionalResult(
payload,
result,
),
);
return handleOptionalResult(
payload,
result,
);
}
return def.innerType._zod.run(
payload,
ctx,
);
};
},
);
const $ZodExactOptional =
$constructor(
"$ZodExactOptional",
(inst, def) => {
$ZodOptional.init(inst, def);
defineLazyInternal(
inst,
"values",
(zod) =>
zod.def.innerType._zod.values,
);
defineLazyInternal(
inst,
"pattern",
(zod) =>
zod.def.innerType._zod
.pattern,
);
inst._zod.parse = (
payload,
ctx,
) => {
return def.innerType._zod.run(
payload,
ctx,
);
};
},
);
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,
);
};
},
);
const $ZodDefault =
$constructor(
"$ZodDefault",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(
inst,
"values",
(zod) =>
zod.def.innerType._zod.values,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
)
return def.innerType._zod.run(
payload,
ctx,
);
if (payload.value === void 0) {
payload.value =
def.defaultValue;
return payload;
}
const result =
def.innerType._zod.run(
payload,
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleDefaultResult(
result,
def,
),
);
return handleDefaultResult(
result,
def,
);
};
},
);
function handleDefaultResult(
payload,
def,
) {
if (payload.value === void 0)
payload.value = def.defaultValue;
return payload;
}
const $ZodPrefault =
$constructor(
"$ZodPrefault",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(
inst,
"values",
(zod) =>
zod.def.innerType._zod.values,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
)
return def.innerType._zod.run(
payload,
ctx,
);
if (payload.value === void 0)
payload.value =
def.defaultValue;
return def.innerType._zod.run(
payload,
ctx,
);
};
},
);
const $ZodNonOptional =
$constructor(
"$ZodNonOptional",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"values",
(zod) => {
const v =
zod.def.innerType._zod
.values;
return v
? new Set(
[...v].filter(
(x) => x !== void 0,
),
)
: void 0;
},
);
inst._zod.parse = (
payload,
ctx,
) => {
const result =
def.innerType._zod.run(
payload,
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleNonOptionalResult(
result,
inst,
),
);
return handleNonOptionalResult(
result,
inst,
);
};
},
);
function handleNonOptionalResult(
payload,
inst,
) {
if (
!payload.issues.length &&
payload.value === void 0
)
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: payload.value,
inst,
});
return payload;
}
function handleCatchResult(
payload,
result,
def,
ctx,
) {
if (!result.issues.length) {
payload.value = result.value;
if (result.memo)
payload.memo = true;
return payload;
}
payload.value = def.catchValue({
...result,
value: payload.value,
error: {
issues: result.issues.map((iss) =>
finalizeIssue(
iss,
ctx,
config(),
),
),
},
input: payload.value,
});
return payload;
}
const $ZodCatch =
$constructor(
"$ZodCatch",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"optin",
(zod) =>
zod.def.innerType._zod
.optin === "defaulted"
? "defaulted"
: "optional",
);
defineLazyInternal(
inst,
"optout",
(zod) =>
zod.def.innerType._zod.optout,
);
defineLazyInternal(
inst,
"values",
(zod) =>
zod.def.innerType._zod.values,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
)
return def.innerType._zod.run(
payload,
ctx,
);
const result =
def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleCatchResult(
payload,
result,
def,
ctx,
),
);
return handleCatchResult(
payload,
result,
def,
ctx,
);
};
},
);
const $ZodPipe =
$constructor(
"$ZodPipe",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"values",
(zod) => zod.def.in._zod.values,
);
defineLazyInternal(
inst,
"optin",
(zod) => zod.def.in._zod.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) =>
zod.def.out._zod.optout,
);
defineLazyInternal(
inst,
"propValues",
(zod) =>
zod.def.in._zod.propValues,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
) {
const right =
def.out._zod.run(
payload,
ctx,
);
if (right instanceof Promise)
return right.then((right) =>
handlePipeResult(
right,
def.in,
ctx,
),
);
return handlePipeResult(
right,
def.in,
ctx,
);
}
const left = def.in._zod.run(
payload,
ctx,
);
if (left instanceof Promise)
return left.then((left) =>
handlePipeResult(
left,
def.out,
ctx,
),
);
return handlePipeResult(
left,
def.out,
ctx,
);
};
},
);
function handlePipeResult(
left,
next,
ctx,
) {
if (
left.issues.some(
(iss) =>
iss.code !==
"unrecognized_keys",
)
) {
left.aborted = true;
return left;
}
return next._zod.run(
{
value: left.value,
issues: left.issues,
},
ctx,
);
}
const $ZodReadonly =
$constructor(
"$ZodReadonly",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"propValues",
(zod) =>
zod.def.innerType._zod
.propValues,
);
defineLazyInternal(
inst,
"values",
(zod) =>
zod.def.innerType._zod.values,
);
defineLazyInternal(
inst,
"optin",
(zod) =>
zod.def.innerType?._zod
?.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) =>
zod.def.innerType?._zod
?.optout,
);
inst._zod.parse = (
payload,
ctx,
) => {
if (
ctx.direction === "backward"
)
return def.innerType._zod.run(
payload,
ctx,
);
const result =
def.innerType._zod.run(
payload,
ctx,
);
if (result instanceof Promise)
return result.then(
handleReadonlyResult,
);
return handleReadonlyResult(
result,
);
};
},
);
function handleReadonlyResult(payload) {
if (!payload.memo)
payload.value = Object.freeze(
payload.value,
);
return payload;
}
const $ZodCustom =
$constructor(
"$ZodCustom",
(inst, def) => {
$ZodCheck.init(inst, def);
$ZodType.init(inst, def);
inst._zod.parse = (
payload,
_,
) => {
return payload;
};
inst._zod.check = (payload) => {
const input = payload.value;
const r = def.fn(input);
if (r instanceof Promise)
return r.then((r) =>
handleRefineResult(
r,
payload,
input,
inst,
),
);
handleRefineResult(
r,
payload,
input,
inst,
);
};
},
);
function handleRefineResult(
result,
payload,
input,
inst,
) {
if (!result) {
const _iss = {
code: "custom",
input,
inst,
path: [
...(inst._zod.def.path ?? []),
],
continue: !inst._zod.def.abort,
};
if (inst._zod.def.params)
_iss.params =
inst._zod.def.params;
payload.issues.push(issue(_iss));
}
}
var $ZodCyclicError = class extends Error {
constructor() {
super(
`Cannot parse a reference cycle that closes through a transform`,
);
this.name = "ZodCyclicError";
}
};
const STATE = "~memo";
const NO_ISSUES = [];
function isRef(value) {
return (
value !== null &&
typeof value === "object"
);
}
function cloneIssues(issues) {
return issues.map((iss) =>
iss.path
? {
...iss,
path: iss.path.slice(),
}
: { ...iss },
);
}
const recursive =
new WeakMap();
const NONE = 0;
const ASSUMED = 1;
const PROVEN = 2;
function isRecursive(
inst,
stack,
resolve,
) {
const cached = recursive.get(inst);
if (cached !== void 0)
return cached ? PROVEN : NONE;
if (stack.has(inst)) return PROVEN;
stack.add(inst);
let result = NONE;
const check = (child) => {
if (
result !== PROVEN &&
child?._zod
) {
const answer = isRecursive(
child,
stack,
resolve,
);
if (answer > result)
result = answer;
}
};
const shape = (sh, spread) => {
let answer = NONE;
for (const key of Reflect.ownKeys(
sh,
)) {
const desc =
Object.getOwnPropertyDescriptor(
sh,
key,
);
if (spread && !desc.enumerable)
continue;
const child = desc.get
? ASSUMED
: desc.value?._zod
? isRecursive(
desc.value,
stack,
resolve,
)
: NONE;
if (child > answer)
answer = child;
}
return answer;
};
const merge = (answer) => {
if (answer > result)
result = answer;
};
const def = inst._zod.def;
switch (def.type) {
case "object": {
const raw = rawShape(def);
merge(
raw
? shape(raw, true)
: ASSUMED,
);
check(def.catchall);
break;
}
case "array":
check(def.element);
break;
case "tuple":
for (const el of def.items)
check(el);
check(def.rest);
break;
case "record":
case "map":
check(def.keyType);
check(def.valueType);
break;
case "set":
check(def.valueType);
break;
case "union":
for (const el of def.options)
check(el);
break;
case "intersection":
check(def.left);
check(def.right);
break;
case "optional":
case "nullable":
case "default":
case "prefault":
case "catch":
case "readonly":
case "nonoptional":
case "promise":
case "success":
check(def.innerType);
break;
case "pipe":
check(def.in);
check(def.out);
break;
case "function":
check(def.input);
check(def.output);
break;
case "lazy": {
const inner =
def._cachedInner ??
(resolve
? inst._zod.innerType
: void 0);
merge(
inner
? isRecursive(
inner,
stack,
false,
)
: ASSUMED,
);
break;
}
case "template_literal":
case "string":
case "number":
case "int":
case "boolean":
case "bigint":
case "symbol":
case "undefined":
case "null":
case "void":
case "never":
case "any":
case "unknown":
case "date":
case "nan":
case "enum":
case "literal":
case "file":
case "transform":
case "custom":
break;
default:
for (const key in def) {
const desc =
Object.getOwnPropertyDescriptor(
def,
key,
);
if (!desc || desc.get) continue;
const value = desc.value;
if (
!value ||
typeof value !== "object"
)
continue;
if (value._zod) check(value);
else if (Array.isArray(value))
for (const el of value)
check(el);
}
}
stack.delete(inst);
return settle(inst, result);
}
function settle(inst, answer) {
if (answer !== ASSUMED)
recursive.set(
inst,
answer === PROVEN,
);
return answer;
}
function bucketFor(state, inst) {
let bucket = state.buckets.get(inst);
if (!bucket) {
bucket =
new WeakMap();
state.buckets.set(inst, bucket);
}
return bucket;
}
let handoff;
const open = [];
const memo = {
alloc(_inst, payload, empty) {
const bucket = handoff;
if (!bucket) return empty;
handoff = void 0;
const entry = {
value: empty,
issues: null,
};
bucket.set(payload.value, entry);
open.push(entry);
return empty;
},
guard(inst) {
var _a;
(_a = inst._zod).deferred ??
(_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (
payload,
ctx,
) => {
if (
ctx.direction !==
"backward" &&
isBackEdge(ctx, payload.value)
)
throw new $ZodCyclicError();
return base(payload, ctx);
};
inst._zod.parse = wrapped;
if (inst._zod.run === base)
inst._zod.run = wrapped;
});
},
attach(inst) {
var _a;
let isRecursiveInst;
let rechecked = false;
let lastCtx;
let lastBucket;
(_a = inst._zod).deferred ??
(_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (
payload,
ctx,
) => {
if (
isRecursiveInst === void 0
) {
const walked = isRecursive(
inst,
new Set(),
false,
);
if (walked === NONE) {
inst._zod.parse = base;
if (
inst._zod.run === wrapped
)
inst._zod.run = base;
return base(payload, ctx);
}
if (
walked === PROVEN ||
rechecked
)
isRecursiveInst = true;
else rechecked = true;
}
const input = payload.value;
if (!isRef(input))
return base(payload, ctx);
let state = ctx[STATE];
if (!state) {
state = {
buckets:
new WeakMap(),
backEdges: void 0,
};
ctx[STATE] = state;
}
let bucket;
if (lastCtx === ctx)
bucket = lastBucket;
else {
bucket = bucketFor(
state,
inst,
);
lastCtx = ctx;
lastBucket = bucket;
}
const hit = bucket.get(input);
if (hit) {
payload.value = hit.value;
if (hit.issues) {
if (hit.issues.length)
payload.issues.push(
...cloneIssues(
hit.issues,
),
);
} else {
payload.memo = true;
state.backEdges ??
(state.backEdges =
new WeakSet());
state.backEdges.add(
hit.value,
);
}
return payload;
}
handoff = bucket;
const depth = open.length;
const result = base(
payload,
ctx,
);
handoff = void 0;
const entry =
open.length > depth
? open.pop()
: void 0;
if (result instanceof Promise)
return result.then((r) => {
if (entry)
entry.issues = r.issues
.length
? cloneIssues(r.issues)
: NO_ISSUES;
return r;
});
if (entry)
entry.issues = result.issues
.length
? cloneIssues(result.issues)
: NO_ISSUES;
return result;
};
inst._zod.parse = wrapped;
if (inst._zod.run === base)
inst._zod.run = wrapped;
});
},
};
function memoizer() {
return memo;
}
function isBackEdge(ctx, value) {
const backEdges =
ctx[STATE]?.backEdges;
return (
backEdges !== void 0 &&
isRef(value) &&
backEdges.has(value)
);
}
const error = () => {
const Sizable = {
string: {
unit: "characters",
verb: "to have",
},
file: {
unit: "bytes",
verb: "to have",
},
array: {
unit: "items",
verb: "to have",
},
set: {
unit: "items",
verb: "to have",
},
map: {
unit: "entries",
verb: "to have",
},
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const FormatDictionary = {
regex: "input",
email: "email address",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO datetime",
date: "ISO date",
time: "ISO time",
duration: "ISO duration",
ipv4: "IPv4 address",
ipv6: "IPv6 address",
mac: "MAC address",
cidrv4: "IPv4 range",
cidrv6: "IPv6 range",
base64: "base64-encoded string",
base64url:
"base64url-encoded string",
json_string: "JSON string",
e164: "E.164 number",
currency_code: "currency code",
credit_card: "credit card number",
iban: "IBAN",
jwt: "JWT",
template_literal: "input",
};
const TypeDictionary = { nan: "NaN" };
function getTypeName(type, input) {
if (
type === "number" &&
typeof input === "number" &&
!Number.isFinite(input)
)
return String(input);
return TypeDictionary[type] ?? type;
}
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `Invalid input: expected ${getTypeName(issue.expected)}, received ${getTypeName(parsedType(issue.input), issue.input)}`;
case "invalid_value":
if (issue.values.length === 1)
return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.exact
? "exactly "
: issue.inclusive
? "<="
: "<";
const sizing = getSizing(
issue.origin,
);
if (sizing)
return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.exact
? "exactly "
: issue.inclusive
? ">="
: ">";
const sizing = getSizing(
issue.origin,
);
if (sizing)
return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
if (
_issue.format ===
"starts_with"
)
return `Invalid string: must start with "${_issue.prefix}"`;
if (
_issue.format === "ends_with"
)
return `Invalid string: must end with "${_issue.suffix}"`;
if (
_issue.format === "includes"
)
return `Invalid string: must include "${_issue.includes}"`;
if (_issue.format === "regex")
return `Invalid string: must match pattern ${_issue.pattern}`;
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `Invalid number: must be a multiple of ${issue.divisor}`;
case "unrecognized_keys":
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Invalid key in ${issue.origin}`;
case "invalid_union":
if (
issue.options &&
Array.isArray(
issue.options,
) &&
issue.options.length > 0
)
return `Invalid discriminator value. Expected ${issue.options.map((o) => `'${o}'`).join(" | ")}`;
if (issue.inclusive === false)
return "Invalid input: more than one option matched";
return "Invalid input";
case "invalid_element":
return `Invalid value in ${issue.origin}`;
default:
return `Invalid input`;
}
};
};
function en_default() {
return { localeError: error() };
}
var _a;
var $ZodRegistry = class {
constructor() {
this._map =
new WeakMap();
this._idmap =
new Map();
}
add(schema, ..._meta) {
const meta = _meta[0];
this._map.set(schema, meta);
if (
meta &&
typeof meta === "object" &&
"id" in meta
)
this._idmap.set(meta.id, schema);
return this;
}
clear() {
this._map =
new WeakMap();
this._idmap =
new Map();
return this;
}
remove(schema) {
const meta = this._map.get(schema);
if (
meta &&
typeof meta === "object" &&
"id" in meta
)
this._idmap.delete(meta.id);
this._map.delete(schema);
return this;
}
get(schema) {
const p = schema._zod.parent;
if (p) {
const pm = {
...(this.get(p) ?? {}),
};
delete pm.id;
const f = {
...pm,
...this._map.get(schema),
};
return Object.keys(f).length
? f
: void 0;
}
return this._map.get(schema);
}
has(schema) {
return this._map.has(schema);
}
};
function registry() {
return new $ZodRegistry();
}
(_a = globalThis)
.__zod_globalRegistry ??
(_a.__zod_globalRegistry =
registry());
const globalRegistry =
globalThis.__zod_globalRegistry;
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 _email(Class, params) {
return new Class({
type: "string",
format: "email",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _guid(Class, params) {
return new Class({
type: "string",
format: "guid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuid(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuidv4(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v4",
...normalizeParams(params),
});
}
function _uuidv6(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v6",
...normalizeParams(params),
});
}
function _uuidv7(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v7",
...normalizeParams(params),
});
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _emoji(Class, params) {
return new Class({
type: "string",
format: "emoji",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _nanoid(Class, params) {
return new Class({
type: "string",
format: "nanoid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid(Class, params) {
return new Class({
type: "string",
format: "cuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid2(Class, params) {
return new Class({
type: "string",
format: "cuid2",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ulid(Class, params) {
return new Class({
type: "string",
format: "ulid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _xid(Class, params) {
return new Class({
type: "string",
format: "xid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ksuid(Class, params) {
return new Class({
type: "string",
format: "ksuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv4(Class, params) {
return new Class({
type: "string",
format: "ipv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv6(Class, params) {
return new Class({
type: "string",
format: "ipv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv4(Class, params) {
return new Class({
type: "string",
format: "cidrv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv6(Class, params) {
return new Class({
type: "string",
format: "cidrv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64(Class, params) {
return new Class({
type: "string",
format: "base64",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64url(Class, params) {
return new Class({
type: "string",
format: "base64url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _e164(Class, params) {
return new Class({
type: "string",
format: "e164",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _jwt(Class, params) {
return new Class({
type: "string",
format: "jwt",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _isoDateTime(Class, params) {
return new Class({
type: "string",
format: "datetime",
check: "string_format",
offset: false,
local: false,
precision: null,
...normalizeParams(params),
});
}
function _isoDate(Class, params) {
return new Class({
type: "string",
format: "date",
check: "string_format",
...normalizeParams(params),
});
}
function _isoTime(Class, params) {
return new Class({
type: "string",
format: "time",
check: "string_format",
precision: null,
...normalizeParams(params),
});
}
function _isoDuration(Class, params) {
return new Class({
type: "string",
format: "duration",
check: "string_format",
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _int(Class, params) {
return new Class({
type: "number",
check: "number_format",
abort: false,
format: "safeint",
...normalizeParams(params),
});
}
function _unknown(Class) {
return new Class({ type: "unknown" });
}
function _never(Class, params) {
return new Class({
type: "never",
...normalizeParams(params),
});
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lt(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gt(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _multipleOf(value, params) {
return new $ZodCheckMultipleOf({
check: "multiple_of",
...normalizeParams(params),
value,
});
}
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,
});
}
function _length(length, params) {
return new $ZodCheckLengthEquals({
check: "length_equals",
...normalizeParams(params),
length,
});
}
function _regex(pattern, params) {
return new $ZodCheckRegex({
check: "string_format",
format: "regex",
...normalizeParams(params),
pattern,
});
}
function _lowercase(params) {
return new $ZodCheckLowerCase({
check: "string_format",
format: "lowercase",
...normalizeParams(params),
});
}
function _uppercase(params) {
return new $ZodCheckUpperCase({
check: "string_format",
format: "uppercase",
...normalizeParams(params),
});
}
function _includes(includes, params) {
return new $ZodCheckIncludes({
check: "string_format",
format: "includes",
...normalizeParams(params),
includes,
});
}
function _startsWith(prefix, params) {
return new $ZodCheckStartsWith({
check: "string_format",
format: "starts_with",
...normalizeParams(params),
prefix,
});
}
function _endsWith(suffix, params) {
return new $ZodCheckEndsWith({
check: "string_format",
format: "ends_with",
...normalizeParams(params),
suffix,
});
}
function _overwrite(tx) {
return new $ZodCheckOverwrite({
check: "overwrite",
tx,
});
}
function _normalize(form) {
return _overwrite(
(input) => input.normalize(form),
);
}
function _trim() {
return _overwrite(
(input) => input.trim(),
);
}
function _toLowerCase() {
return _overwrite(
(input) => input.toLowerCase(),
);
}
function _toUpperCase() {
return _overwrite(
(input) => input.toUpperCase(),
);
}
function _slugify() {
return _overwrite(
(input) => slugify(input),
);
}
function _array(
Class,
element,
params,
) {
return new Class({
type: "array",
element,
...normalizeParams(params),
});
}
function _refine(Class, fn, _params) {
return new Class({
type: "custom",
check: "custom",
fn,
...normalizeParams(_params),
});
}
function _superRefine(fn, params) {
const ch = _check(
(payload) => {
payload.addIssue = (issue$2) => {
if (typeof issue$2 === "string")
payload.issues.push(
issue(
issue$2,
payload.value,
ch._zod.def,
),
);
else {
const _issue = issue$2;
if (_issue.fatal)
_issue.continue = false;
_issue.code ??
(_issue.code = "custom");
if (!("input" in _issue))
_issue.input =
payload.value;
_issue.inst ??
(_issue.inst = ch);
_issue.continue ??
(_issue.continue =
!ch._zod.def.abort);
payload.issues.push(
issue(_issue),
);
}
};
return fn(payload.value, payload);
},
params,
);
return ch;
}
function _check(fn, params) {
const ch = new $ZodCheck({
check: "custom",
...normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
function assignProps(
target,
...sources
) {
for (const source of sources)
for (const key of Reflect.ownKeys(
source,
))
if (
Object.prototype.propertyIsEnumerable.call(
source,
key,
)
)
assignProp(
target,
key,
source[key],
);
return target;
}
function initializeContext(params) {
let target =
params?.target ?? "draft-2020-12";
if (target === "draft-4")
target = "draft-04";
if (target === "draft-7")
target = "draft-07";
return {
processors: params.processors ?? {},
metadataRegistry:
params?.metadata ??
globalRegistry,
target,
unrepresentable:
params?.unrepresentable ??
"throw",
override:
params?.override ?? (() => {}),
io: params?.io ?? "output",
counter: 0,
seen: new Map(),
sharedDefsExtractedFor: void 0,
sharedEmitDoneFor: void 0,
cycles: params?.cycles ?? "ref",
reused: params?.reused ?? "inline",
intersections: [],
deferred: [],
external:
params?.external ?? void 0,
};
}
function handleUnrepresentable(
schema,
ctx,
json,
params,
message,
) {
const result =
typeof ctx.unrepresentable ===
"function"
? ctx.unrepresentable({
zodSchema: schema,
path: params.path,
message,
})
: ctx.unrepresentable;
if (result === "any") return false;
if (
result === void 0 ||
result === "throw"
)
throw new Error(message);
Object.assign(json, result);
return true;
}
function processSchema(
schema,
ctx,
_params = {
path: [],
schemaPath: [],
},
) {
var _a;
const def = schema._zod.def;
const seen = ctx.seen.get(schema);
if (seen) {
seen.count++;
if (
_params.schemaPath.includes(
schema,
)
)
seen.cycle = _params.path;
return seen.schema;
}
const result = {
schema: {},
count: 1,
cycle: void 0,
path: _params.path,
};
ctx.seen.set(schema, result);
ctx.sharedDefsExtractedFor = void 0;
ctx.sharedEmitDoneFor = void 0;
const overrideSchema =
schema._zod.toJSONSchema?.();
if (overrideSchema)
result.schema = overrideSchema;
else {
const params = {
..._params,
schemaPath: [
..._params.schemaPath,
schema,
],
path: _params.path,
};
if (schema._zod.processJSONSchema)
schema._zod.processJSONSchema(
ctx,
result.schema,
params,
);
else {
const _json = result.schema;
const processor =
ctx.processors[def.type];
if (!processor)
throw new Error(
`[toJSONSchema]: Non-representable type encountered: ${def.type}`,
);
processor(
schema,
ctx,
_json,
params,
);
}
const parent = schema._zod.parent;
if (parent) {
if (!result.ref)
result.ref = parent;
processSchema(
parent,
ctx,
params,
);
ctx.seen.get(parent).isParent =
true;
}
}
const meta =
ctx.metadataRegistry.get(schema);
if (meta)
assignProps(result.schema, meta);
if (
ctx.io === "input" &&
isTransforming(schema)
) {
delete result.schema.examples;
delete result.schema.default;
}
if (
ctx.io === "input" &&
"_prefault" in result.schema
)
(_a = result.schema).default ??
(_a.default =
result.schema._prefault);
delete result.schema._prefault;
return ctx.seen.get(schema).schema;
}
function encodeJSONPointerSegment(
segment,
) {
return segment
.replace(/~/g, "~0")
.replace(/\//g, "~1");
}
function extractDefs(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root)
throw new Error(
"Unprocessed schema. This is a bug in Zod.",
);
if (
ctx.external &&
ctx.sharedDefsExtractedFor ===
ctx.external
)
return;
const idToSchema =
new Map();
for (const entry of ctx.seen.entries()) {
const id = ctx.metadataRegistry.get(
entry[0],
)?.id;
if (id) {
const existing =
idToSchema.get(id);
if (
existing &&
existing !== entry[0]
)
throw new Error(
`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`,
);
idToSchema.set(id, entry[0]);
}
}
const makeURI = (entry) => {
const defsSegment =
ctx.target === "draft-2020-12"
? "$defs"
: "definitions";
if (ctx.external) {
const externalId =
ctx.external.registry.get(
entry[0],
)?.id;
const uriGenerator =
ctx.external.uri ??
((id) => id);
if (externalId)
return {
ref: uriGenerator(externalId),
};
const id =
entry[1].defId ??
entry[1].schema.id ??
`schema${ctx.counter++}`;
entry[1].defId = id;
return {
defId: id,
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`,
};
}
const uriPrefix = `#`;
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
if (
entry[1] === root &&
!entry[1].schema.id
)
return { ref: uriPrefix };
const defId =
entry[1].schema.id ??
`__schema${ctx.counter++}`;
return {
defId,
ref:
defUriPrefix +
encodeJSONPointerSegment(defId),
};
};
const extractToDef = (entry) => {
if (entry[1].schema.$ref) return;
const seen = entry[1];
const { ref, defId } =
makeURI(entry);
seen.def = { ...seen.schema };
if (defId) seen.defId = defId;
const schema = seen.schema;
for (const key in schema)
delete schema[key];
schema.$ref = ref;
};
if (ctx.cycles === "throw")
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.cycle)
throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
}
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (schema === entry[0]) {
extractToDef(entry);
continue;
}
if (ctx.external) {
const ext =
ctx.external.registry.get(
entry[0],
)?.id;
if (schema !== entry[0] && ext) {
extractToDef(entry);
continue;
}
}
if (
ctx.metadataRegistry.get(entry[0])
?.id
) {
extractToDef(entry);
continue;
}
if (seen.cycle) {
extractToDef(entry);
continue;
}
if (seen.count > 1) {
if (ctx.reused === "ref")
extractToDef(entry);
}
}
if (ctx.external)
ctx.sharedDefsExtractedFor =
ctx.external;
}
function compactTypeUnion(schema) {
const options = schema.anyOf;
if (
!Array.isArray(options) ||
options.length === 0 ||
schema.type !== void 0
)
return;
const types = [];
for (const option of options) {
if (
!option ||
typeof option !== "object"
)
return;
compactTypeUnion(option);
const keys = Object.keys(option);
if (
keys.length !== 1 ||
keys[0] !== "type"
)
return;
const type = option.type;
for (const member of Array.isArray(
type,
)
? type
: [type]) {
if (typeof member !== "string")
return;
if (!types.includes(member))
types.push(member);
}
}
delete schema.anyOf;
schema.type =
types.length === 1
? types[0]
: types;
}
const FOLDABLE_KEYS =
new Set([
"type",
"properties",
"required",
"additionalProperties",
]);
const UNION_KEYS = ["oneOf", "anyOf"];
function undeclaredConstraint(member) {
const extra =
member.additionalProperties;
if (
extra === void 0 ||
extra === false ||
typeof extra !== "object" ||
extra === null
)
return null;
return Object.keys(extra).length
? extra
: null;
}
function foldObjects(members) {
const objects = [];
for (const member of members) {
if (
typeof member !== "object" ||
member.type !== "object"
)
return null;
for (const key in member)
if (!FOLDABLE_KEYS.has(key))
return null;
objects.push(member);
}
const properties = {};
const required =
new Set();
for (const object of objects) {
for (const key in object.properties) {
if (
Object.prototype.hasOwnProperty.call(
properties,
key,
)
)
continue;
const parts = [];
for (const other of objects) {
const part =
other.properties?.[key] ??
undeclaredConstraint(other);
if (
part === null ||
part === void 0
)
continue;
if (
!parts.some(
(seen) =>
JSON.stringify(seen) ===
JSON.stringify(part),
)
)
parts.push(part);
}
assignProp(
properties,
key,
parts.length === 1
? parts[0]
: (foldObjects(parts) ?? {
allOf: parts,
}),
);
}
for (const key of object.required ??
[])
required.add(key);
}
const folded = {
type: "object",
properties,
};
if (required.size)
folded.required = [...required];
if (
objects.every(
(object) =>
object.additionalProperties ===
false,
)
)
folded.additionalProperties = false;
else {
const constraints = [];
for (const object of objects) {
const constraint =
undeclaredConstraint(object);
if (
constraint &&
!constraints.some(
(seen) =>
JSON.stringify(seen) ===
JSON.stringify(constraint),
)
)
constraints.push(constraint);
}
if (constraints.length === 1)
folded.additionalProperties =
constraints[0];
else if (constraints.length > 1)
folded.additionalProperties = {
allOf: constraints,
};
}
return folded;
}
function foldIntersection(json) {
const allOf = json.allOf;
if (
!Array.isArray(allOf) ||
allOf.length < 2
)
return;
for (const key of FOLDABLE_KEYS)
if (key in json) return;
const unions = allOf.filter((m) =>
UNION_KEYS.some((k) =>
Array.isArray(m[k]),
),
);
let folded = null;
if (!unions.length)
folded = foldObjects(allOf);
else {
const union = unions[0];
const keyword = UNION_KEYS.find(
(k) => Array.isArray(union[k]),
);
if (Object.keys(union).length !== 1)
return;
const rest = allOf.filter(
(m) => m !== union,
);
const branches = union[keyword].map(
(branch) =>
foldObjects([...rest, branch]),
);
if (branches.some((b) => !b))
return;
folded = { [keyword]: branches };
}
if (!folded) return;
delete json.allOf;
assignProps(json, folded);
}
function finalize(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root)
throw new Error(
"Unprocessed schema. This is a bug in Zod.",
);
const flattenRef = (zodSchema) => {
const seen =
ctx.seen.get(zodSchema);
if (seen.ref === null) return;
const schema =
seen.def ?? seen.schema;
const _cached = { ...schema };
const ref = seen.ref;
seen.ref = null;
if (ref) {
flattenRef(ref);
const refSeen = ctx.seen.get(ref);
const refSchema = refSeen.schema;
if (
refSchema.$ref &&
(ctx.target === "draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0")
) {
schema.allOf =
schema.allOf ?? [];
schema.allOf.push(refSchema);
} else
assignProps(schema, refSchema);
assignProps(schema, _cached);
if (zodSchema._zod.parent === ref)
for (const key in schema) {
if (
key === "$ref" ||
key === "allOf"
)
continue;
if (!(key in _cached))
delete schema[key];
}
if (refSchema.$ref && refSeen.def)
for (const key in schema) {
if (
key === "$ref" ||
key === "allOf"
)
continue;
if (
key in refSeen.def &&
JSON.stringify(
schema[key],
) ===
JSON.stringify(
refSeen.def[key],
)
)
delete schema[key];
}
}
const parent =
zodSchema._zod.parent;
if (parent && parent !== ref) {
flattenRef(parent);
const parentSeen =
ctx.seen.get(parent);
if (parentSeen?.schema.$ref) {
schema.$ref =
parentSeen.schema.$ref;
if (parentSeen.def)
for (const key in schema) {
if (
key === "$ref" ||
key === "allOf"
)
continue;
if (
key in parentSeen.def &&
JSON.stringify(
schema[key],
) ===
JSON.stringify(
parentSeen.def[key],
)
)
delete schema[key];
}
}
}
ctx.override({
zodSchema,
jsonSchema: schema,
path: seen.path ?? [],
});
};
if (
!ctx.external ||
ctx.sharedEmitDoneFor !==
ctx.external
) {
for (const entry of [
...ctx.seen.entries(),
].reverse())
flattenRef(entry[0]);
if (ctx.target !== "openapi-3.0")
for (const entry of ctx.seen.entries())
compactTypeUnion(
entry[1].def ??
entry[1].schema,
);
for (const rewrite of ctx.deferred)
rewrite();
if (ctx.intersections.length) {
const carriers =
new Map();
for (const seen of ctx.seen.values())
for (const json of [
seen.schema,
seen.def,
]) {
const allOf = json?.allOf;
if (!Array.isArray(allOf))
continue;
const existing =
carriers.get(allOf);
if (existing)
existing.push(json);
else
carriers.set(allOf, [json]);
}
for (const allOf of ctx.intersections)
for (const json of carriers.get(
allOf,
) ?? [])
foldIntersection(json);
}
}
const result = {};
if (ctx.target === "draft-2020-12")
result.$schema =
"https://json-schema.org/draft/2020-12/schema";
else if (ctx.target === "draft-07")
result.$schema =
"http://json-schema.org/draft-07/schema#";
else if (ctx.target === "draft-04")
result.$schema =
"http://json-schema.org/draft-04/schema#";
else if (
ctx.target === "openapi-3.0"
) {
}
if (ctx.external?.uri) {
const id =
ctx.external.registry.get(
schema,
)?.id;
if (!id)
throw new Error(
"Schema is missing an `id` property",
);
result.$id = ctx.external.uri(id);
}
assignProps(
result,
root.defId
? root.schema
: (root.def ?? root.schema),
);
const rootMetaId =
ctx.metadataRegistry.get(
schema,
)?.id;
if (
rootMetaId !== void 0 &&
result.id === rootMetaId
)
delete result.id;
const defs = ctx.external?.defs ?? {};
if (
!ctx.external ||
ctx.sharedEmitDoneFor !==
ctx.external
)
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.def && seen.defId) {
if (seen.def.id === seen.defId)
delete seen.def.id;
assignProp(
defs,
seen.defId,
seen.def,
);
}
}
if (ctx.external)
ctx.sharedEmitDoneFor =
ctx.external;
if (ctx.external) {
} else if (
Object.keys(defs).length > 0
) {
if (ctx.target === "draft-2020-12")
result.$defs = defs;
else result.definitions = defs;
}
try {
const finalized = JSON.parse(
JSON.stringify(result),
);
Object.defineProperty(
finalized,
"~standard",
{
value: {
...schema["~standard"],
jsonSchema: {
input:
createStandardJSONSchemaMethod(
schema,
"input",
ctx.processors,
),
output:
createStandardJSONSchemaMethod(
schema,
"output",
ctx.processors,
),
},
},
enumerable: false,
writable: false,
},
);
return finalized;
} catch (_err) {
throw new Error(
"Error converting schema to JSON.",
);
}
}
function isTransforming(_schema, _ctx) {
const ctx = _ctx ?? {
seen: new Set(),
};
if (ctx.seen.has(_schema))
return false;
ctx.seen.add(_schema);
const def = _schema._zod.def;
if (def.type === "transform")
return true;
if (def.type === "array")
return isTransforming(
def.element,
ctx,
);
if (def.type === "set")
return isTransforming(
def.valueType,
ctx,
);
if (def.type === "lazy")
return isTransforming(
def.getter(),
ctx,
);
if (
def.type === "promise" ||
def.type === "optional" ||
def.type === "nonoptional" ||
def.type === "nullable" ||
def.type === "readonly" ||
def.type === "default" ||
def.type === "prefault" ||
def.type === "catch"
)
return isTransforming(
def.innerType,
ctx,
);
if (def.type === "intersection")
return (
isTransforming(def.left, ctx) ||
isTransforming(def.right, ctx)
);
if (
def.type === "record" ||
def.type === "map"
)
return (
isTransforming(
def.keyType,
ctx,
) ||
isTransforming(def.valueType, ctx)
);
if (def.type === "pipe") {
if (
_schema._zod.traits.has(
"$ZodCodec",
)
)
return true;
return (
isTransforming(def.in, ctx) ||
isTransforming(def.out, ctx)
);
}
if (def.type === "object") {
for (const key in def.shape)
if (
isTransforming(
def.shape[key],
ctx,
)
)
return true;
return false;
}
if (def.type === "union") {
for (const option of def.options)
if (isTransforming(option, ctx))
return true;
return false;
}
if (def.type === "tuple") {
for (const item of def.items)
if (isTransforming(item, ctx))
return true;
if (
def.rest &&
isTransforming(def.rest, ctx)
)
return true;
return false;
}
return false;
}
const createToJSONSchemaMethod =
(schema, processors = {}) =>
(params) => {
const ctx = initializeContext({
...params,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const createStandardJSONSchemaMethod =
(schema, io, processors = {}) =>
(params) => {
const { libraryOptions, target } =
params ?? {};
const ctx = initializeContext({
...(libraryOptions ?? {}),
target,
io,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const narrowMin = (agg, key, value) => {
if (
agg[key] === void 0 ||
value > agg[key]
)
agg[key] = value;
};
const narrowMax = (agg, key, value) => {
if (
agg[key] === void 0 ||
value < agg[key]
)
agg[key] = value;
};
const narrowBoth = (agg, value) => {
narrowMin(agg, "minimum", value);
narrowMax(agg, "maximum", value);
};
const addDivisor = (agg, value) => {
agg.multipleOf ??
(agg.multipleOf = []);
if (!agg.multipleOf.includes(value))
agg.multipleOf.push(value);
};
const addPattern = (agg, pattern) => {
agg.patterns ??
(agg.patterns =
new Set());
agg.patterns.add(pattern);
};
const intersectMime = (agg, mime) => {
agg.mime = agg.mime
? agg.mime.filter((m) =>
mime.includes(m),
)
: [...mime];
};
const setFormat = (agg, format) => {
agg.format = format;
if (format.includes("int"))
agg.isInt = true;
};
const minContributor = (agg, def) =>
narrowMin(
agg,
"minimum",
def.minimum,
);
const maxContributor = (agg, def) =>
narrowMax(
agg,
"maximum",
def.maximum,
);
const formatContributor =
(ranges) => (agg, def) => {
setFormat(agg, def.format);
const [minimum, maximum] =
ranges[def.format];
narrowMin(agg, "minimum", minimum);
narrowMax(agg, "maximum", maximum);
};
const contributors = {
greater_than: (agg, def) =>
narrowMin(
agg,
def.inclusive
? "minimum"
: "exclusiveMinimum",
def.value,
),
less_than: (agg, def) =>
narrowMax(
agg,
def.inclusive
? "maximum"
: "exclusiveMaximum",
def.value,
),
multiple_of: (agg, def) =>
addDivisor(agg, def.value),
number_format: formatContributor(
NUMBER_FORMAT_RANGES,
),
bigint_format: formatContributor(
BIGINT_FORMAT_RANGES,
),
min_length: minContributor,
max_length: maxContributor,
length_equals: (agg, def) =>
narrowBoth(agg, def.length),
min_size: minContributor,
max_size: maxContributor,
size_equals: (agg, def) =>
narrowBoth(agg, def.size),
string_format: (agg, def) => {
setFormat(agg, def.format);
if (def.pattern)
addPattern(agg, def.pattern);
if (
def.format === "base64" ||
def.format === "base64url"
)
agg.contentEncoding = def.format;
if (
def.local ||
def.precision === -1
)
agg.laxFormat = true;
},
mime_type: (agg, def) =>
intersectMime(agg, def.mime),
};
function aggregateChecks(schema) {
const agg = {};
const def = schema._zod.def;
const list = schema._zod.traits.has(
"$ZodCheck",
)
? [schema, ...(def.checks ?? [])]
: (def.checks ?? []);
for (const ch of list)
contributors[ch._zod.def.check]?.(
agg,
ch._zod.def,
);
const bag = schema._zod.bag;
if (bag.minimum !== void 0)
narrowMin(
agg,
"minimum",
bag.minimum,
);
if (bag.exclusiveMinimum !== void 0)
narrowMin(
agg,
"exclusiveMinimum",
bag.exclusiveMinimum,
);
if (bag.maximum !== void 0)
narrowMax(
agg,
"maximum",
bag.maximum,
);
if (bag.exclusiveMaximum !== void 0)
narrowMax(
agg,
"exclusiveMaximum",
bag.exclusiveMaximum,
);
if (bag.multipleOf !== void 0)
addDivisor(agg, bag.multipleOf);
if (bag.format !== void 0) {
agg.format ??
(agg.format = bag.format);
if (bag.format.includes("int"))
agg.isInt = true;
}
if (bag.mime)
intersectMime(agg, bag.mime);
for (const pattern of bag.patterns ??
[])
addPattern(agg, pattern);
return agg;
}
const formatMap = {
guid: "uuid",
url: "uri",
datetime: "date-time",
json_string: "json-string",
regex: "",
};
const exactPatterns =
new Map([
[base64Charset, base64],
[base64urlCharset, base64url],
]);
const exactPattern = (p) =>
exactPatterns.get(p) ?? p;
const stringProcessor = (
schema,
ctx,
_json,
_params,
) => {
const json = _json;
json.type = "string";
const {
minimum,
maximum,
format,
patterns,
contentEncoding,
laxFormat,
} = aggregateChecks(schema);
if (typeof minimum === "number")
json.minLength = minimum;
if (typeof maximum === "number")
json.maxLength = maximum;
if (format) {
json.format =
formatMap[format] ?? format;
if (json.format === "")
delete json.format;
if (format === "time" || laxFormat)
delete json.format;
}
if (contentEncoding)
json.contentEncoding =
contentEncoding;
if (patterns && patterns.size > 0) {
const patternList = [
...patterns,
].map(exactPattern);
if (patternList.length === 1)
json.pattern =
patternList[0].source;
else if (patternList.length > 1)
json.allOf = [
...patternList.map((regex) => ({
...(ctx.target ===
"draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0"
? { type: "string" }
: {}),
pattern: regex.source,
})),
];
}
};
const numberProcessor = (
schema,
ctx,
_json,
params,
) => {
const json = _json;
const {
minimum,
maximum,
multipleOf,
exclusiveMaximum,
exclusiveMinimum,
isInt,
} = aggregateChecks(schema);
json.type = isInt
? "integer"
: "number";
const exMin =
typeof exclusiveMinimum ===
"number" &&
exclusiveMinimum >=
(minimum ??
Number.NEGATIVE_INFINITY);
const exMax =
typeof exclusiveMaximum ===
"number" &&
exclusiveMaximum <=
(maximum ??
Number.POSITIVE_INFINITY);
const legacy =
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0";
if (exMin) {
if (legacy) {
json.minimum = exclusiveMinimum;
json.exclusiveMinimum = true;
} else
json.exclusiveMinimum =
exclusiveMinimum;
} else if (
typeof minimum === "number"
)
json.minimum = minimum;
if (exMax) {
if (legacy) {
json.maximum = exclusiveMaximum;
json.exclusiveMaximum = true;
} else
json.exclusiveMaximum =
exclusiveMaximum;
} else if (
typeof maximum === "number"
)
json.maximum = maximum;
if (multipleOf) {
const divisors =
new Set();
for (const divisor of multipleOf)
if (
Number.isFinite(divisor) &&
divisor !== 0
)
divisors.add(Math.abs(divisor));
else
handleUnrepresentable(
schema,
ctx,
json,
params,
`A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`,
);
const [first, ...rest] = divisors;
if (first !== void 0)
json.multipleOf = first;
if (rest.length)
json.allOf = [
...(json.allOf ?? []),
...rest.map((m) => ({
multipleOf: m,
})),
];
}
};
const neverProcessor = (
_schema,
_ctx,
json,
_params,
) => {
json.not = {};
};
const dateProcessor = (
schema,
ctx,
json,
params,
) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Date cannot be represented in JSON Schema",
);
};
const enumProcessor = (
schema,
_ctx,
json,
_params,
) => {
const def = schema._zod.def;
const values = getEnumValues(
def.entries,
);
if (values.length === 0) {
json.not = {};
return;
}
if (
values.every(
(v) => typeof v === "number",
)
)
json.type = "number";
if (
values.every(
(v) => typeof v === "string",
)
)
json.type = "string";
json.enum = values;
};
const customProcessor = (
schema,
ctx,
json,
params,
) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Custom types cannot be represented in JSON Schema",
);
};
const transformProcessor = (
schema,
ctx,
json,
params,
) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Transforms cannot be represented in JSON Schema",
);
};
const arrayProcessor = (
schema,
ctx,
_json,
params,
) => {
const json = _json;
const def = schema._zod.def;
const { minimum, maximum } =
aggregateChecks(schema);
if (typeof minimum === "number")
json.minItems = minimum;
if (typeof maximum === "number")
json.maxItems = maximum;
json.type = "array";
json.items = processSchema(
def.element,
ctx,
{
...params,
path: [...params.path, "items"],
},
);
};
function inputOptin(schema) {
const def = schema._zod.def;
if (
def.type === "pipe" &&
def.in._zod.traits.has(
"$ZodTransform",
)
)
return inputOptin(def.out);
if (def.type === "catch")
return inputOptin(def.innerType);
return schema._zod.optin;
}
const objectProcessor = (
schema,
ctx,
_json,
params,
) => {
const json = _json;
const def = schema._zod.def;
const shape = def.shape;
if (
Object.getOwnPropertySymbols(shape)
.length &&
handleUnrepresentable(
schema,
ctx,
json,
params,
"Symbol keys cannot be represented in JSON Schema",
)
)
return;
json.type = "object";
json.properties = {};
for (const key in shape)
assignProp(
json.properties,
key,
processSchema(shape[key], ctx, {
...params,
path: [
...params.path,
"properties",
key,
],
}),
);
const requiredKeys = [];
for (const key of Object.keys(
shape,
)) {
const field = def.shape[key];
if (
ctx.io === "input"
? inputOptin(field) === void 0
: field._zod.optout === void 0
)
requiredKeys.push(key);
}
if (requiredKeys.length > 0)
json.required = requiredKeys;
if (
def.catchall?._zod.def.type ===
"never"
)
json.additionalProperties = false;
else if (!def.catchall) {
if (ctx.io === "output")
json.additionalProperties = false;
} else if (def.catchall)
json.additionalProperties =
processSchema(def.catchall, ctx, {
...params,
path: [
...params.path,
"additionalProperties",
],
});
};
const unionProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
const isExclusive =
def.inclusive === false;
const options = def.options.map(
(x, i) =>
processSchema(x, ctx, {
...params,
path: [
...params.path,
isExclusive
? "oneOf"
: "anyOf",
i,
],
}),
);
if (isExclusive) json.oneOf = options;
else json.anyOf = options;
};
const intersectionProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
const a = processSchema(
def.left,
ctx,
{
...params,
path: [
...params.path,
"allOf",
0,
],
},
);
const b = processSchema(
def.right,
ctx,
{
...params,
path: [
...params.path,
"allOf",
1,
],
},
);
const isSimpleIntersection = (val) =>
"allOf" in val &&
Object.keys(val).length === 1;
const allOf = [
...(isSimpleIntersection(a)
? a.allOf
: [a]),
...(isSimpleIntersection(b)
? b.allOf
: [b]),
];
json.allOf = allOf;
ctx.intersections.push(allOf);
};
const nullableProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
const inner = processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
if (ctx.target === "openapi-3.0") {
seen.ref = def.innerType;
json.nullable = true;
} else
json.anyOf = [
inner,
{ type: "null" },
];
};
const nonoptionalProcessor = (
schema,
ctx,
_json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const UNREPRESENTABLE_DEFAULT =
Symbol();
function serializeDefaultValue(
value,
schema,
ctx,
json,
params,
) {
let unrepresentable = false;
const serialized = JSON.stringify(
value,
(_, val) => {
if (typeof val !== "bigint")
return val;
unrepresentable = true;
return null;
},
);
if (!unrepresentable)
return JSON.parse(serialized);
handleUnrepresentable(
schema,
ctx,
json,
params,
"BigInt defaults cannot be represented in JSON Schema",
);
return UNREPRESENTABLE_DEFAULT;
}
const defaultProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT)
json.default = value;
};
const prefaultProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
if (ctx.io !== "input") return;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT)
json._prefault = value;
};
const catchProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
let catchValue;
try {
catchValue = def.catchValue(void 0);
} catch {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Dynamic catch values are not supported in JSON Schema",
);
return;
}
json.default = catchValue;
};
const pipeProcessor = (
schema,
ctx,
_json,
params,
) => {
const def = schema._zod.def;
const inIsTransform =
def.in._zod.traits.has(
"$ZodTransform",
);
const innerType =
ctx.io === "input"
? inIsTransform
? def.out
: def.in
: def.out;
processSchema(innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = innerType;
};
const readonlyProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
json.readOnly = true;
};
const optionalProcessor = (
schema,
ctx,
_json,
params,
) => {
const def = schema._zod.def;
processSchema(
def.innerType,
ctx,
params,
);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const _installedErrorProtos =
new WeakSet([
Object.prototype,
Error.prototype,
]);
function _lazyMethod(proto, key, make) {
Object.defineProperty(proto, key, {
configurable: true,
enumerable: false,
get() {
const value = make(this);
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
},
});
}
const initializer = (inst, issues) => {
$ZodError.init(inst, issues);
inst.name = "ZodError";
const proto =
Object.getPrototypeOf(inst);
if (_installedErrorProtos.has(proto))
return;
_installedErrorProtos.add(proto);
_lazyMethod(
proto,
"format",
(self) => (mapper) =>
formatError(self, mapper),
);
_lazyMethod(
proto,
"flatten",
(self) => (mapper) =>
flattenError(self, mapper),
);
_lazyMethod(
proto,
"addIssue",
(self) => (issue) => {
self.issues.push(issue);
self.message = JSON.stringify(
self.issues,
jsonStringifyReplacer,
2,
);
},
);
_lazyMethod(
proto,
"addIssues",
(self) => (issues) => {
self.issues.push(...issues);
self.message = JSON.stringify(
self.issues,
jsonStringifyReplacer,
2,
);
},
);
Object.defineProperty(
proto,
"isEmpty",
{
configurable: true,
enumerable: false,
get() {
return this.issues.length === 0;
},
},
);
};
const ZodRealError =
$constructor(
"ZodError",
initializer,
void 0,
{ Parent: Error },
);
const parse = _parse(
ZodRealError,
);
const parseAsync =
_parseAsync(
ZodRealError,
);
const safeParse =
_safeParse(
ZodRealError,
);
const safeParseAsync =
_safeParseAsync(
ZodRealError,
);
const encode = _encode(
ZodRealError,
);
const decode = _decode(
ZodRealError,
);
const encodeAsync =
_encodeAsync(
ZodRealError,
);
const decodeAsync =
_decodeAsync(
ZodRealError,
);
const safeEncode =
_safeEncode(
ZodRealError,
);
const safeDecode =
_safeDecode(
ZodRealError,
);
const safeEncodeAsync =
_safeEncodeAsync(
ZodRealError,
);
const safeDecodeAsync =
_safeDecodeAsync(
ZodRealError,
);
function _ensureDefaultLocale() {
if (!globalConfig.localeError)
config(en_default());
}
function _ensureDefaultMemoizer() {
if (!globalConfig.memoizer)
config({ memoizer: memoizer() });
}
const ZodType =
$constructor(
"ZodType",
(inst, def) => {
_ensureDefaultLocale();
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
return inst;
},
{
check(...chks) {
const def = this.def;
return this.clone(
mergeDefs(def, {
checks: [
...(def.checks ?? []),
...chks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: {
check:
"custom",
},
onattach: [],
},
}
: ch,
),
],
}),
{ parent: true },
);
},
with(...chks) {
return this.check(...chks);
},
clone(def, params) {
return clone(this, def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
refine(check, params) {
return this.check(
refine(check, params),
);
},
superRefine(refinement, params) {
return this.check(
superRefine(
refinement,
params,
),
);
},
overwrite(fn) {
return this.check(
_overwrite(
fn,
),
);
},
optional() {
return optional(this);
},
exactOptional() {
return exactOptional(this);
},
nullable() {
return nullable(this);
},
nullish() {
return optional(nullable(this));
},
nonoptional(params) {
return nonoptional(
this,
params,
);
},
array() {
return array(this);
},
or(arg) {
return union([this, arg]);
},
and(arg) {
return intersection(this, arg);
},
transform(tx) {
return pipe(
this,
transform(tx),
);
},
default(d) {
return _default(this, d);
},
prefault(d) {
return prefault(this, d);
},
catch(params) {
return _catch(this, params);
},
pipe(target) {
return pipe(this, target);
},
readonly() {
return readonly(this);
},
describe(description) {
const cl = this.clone();
globalRegistry.add(cl, {
description,
});
return cl;
},
meta(...args) {
if (args.length === 0)
return globalRegistry.get(
this,
);
const cl = this.clone();
globalRegistry.add(cl, args[0]);
return cl;
},
isOptional() {
return this.safeParse(void 0)
.success;
},
isNullable() {
return this.safeParse(null)
.success;
},
apply(fn, ...args) {
return args.length === 0
? fn(this)
: fn(this, ...args);
},
get "~standard"() {
return hide(this, "~standard", {
...standardProps(this),
jsonSchema: {
input:
createStandardJSONSchemaMethod(
this,
"input",
),
output:
createStandardJSONSchemaMethod(
this,
"output",
),
},
});
},
set "~standard"(value) {
own(this, "~standard", value);
},
parse: function _parse(
data,
params,
) {
return parse(
this,
data,
params,
{ callee: _parse },
);
},
parseAsync:
async function _parseAsync(
data,
params,
) {
return await parseAsync(
this,
data,
params,
{ callee: _parseAsync },
);
},
safeParse(data, params) {
return safeParse(
this,
data,
params,
);
},
async safeParseAsync(
data,
params,
) {
return safeParseAsync(
this,
data,
params,
);
},
get spa() {
return this?.safeParseAsync;
},
set spa(value) {
own(this, "spa", value);
},
validate(data, params) {
return validate(
this,
data,
params,
);
},
validateAsync(data, params) {
return validateAsync$1(
this,
data,
params,
);
},
encode: function _encode(
data,
params,
) {
return encode(
this,
data,
params,
{ callee: _encode },
);
},
decode: function _decode(
data,
params,
) {
return decode(
this,
data,
params,
{ callee: _decode },
);
},
encodeAsync:
async function _encodeAsync(
data,
params,
) {
return await encodeAsync(
this,
data,
params,
{ callee: _encodeAsync },
);
},
decodeAsync:
async function _decodeAsync(
data,
params,
) {
return await decodeAsync(
this,
data,
params,
{ callee: _decodeAsync },
);
},
safeEncode(data, params) {
return safeEncode(
this,
data,
params,
);
},
safeDecode(data, params) {
return safeDecode(
this,
data,
params,
);
},
async safeEncodeAsync(
data,
params,
) {
return safeEncodeAsync(
this,
data,
params,
);
},
async safeDecodeAsync(
data,
params,
) {
return safeDecodeAsync(
this,
data,
params,
);
},
toJSONSchema(params) {
return createToJSONSchemaMethod(
this,
{},
)(params);
},
get description() {
return globalRegistry.get(this)
?.description;
},
get _def() {
return this._zod.def;
},
},
);
const _ZodString =
$constructor(
"_ZodString",
(inst, def) => {
$ZodString.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
stringProcessor(
inst,
ctx,
json,
params,
);
},
derived(
{
format: (inst) =>
aggregateChecks(inst)
.format ?? null,
minLength: (inst) =>
aggregateChecks(inst)
.minimum ?? null,
maxLength: (inst) =>
aggregateChecks(inst)
.maximum ?? null,
},
{
regex(...args) {
return this.check(
_regex(
...args,
),
);
},
includes(...args) {
return this.check(
_includes(
...args,
),
);
},
startsWith(...args) {
return this.check(
_startsWith(
...args,
),
);
},
endsWith(...args) {
return this.check(
_endsWith(
...args,
),
);
},
min(...args) {
return this.check(
_minLength(
...args,
),
);
},
max(...args) {
return this.check(
_maxLength(
...args,
),
);
},
length(...args) {
return this.check(
_length(
...args,
),
);
},
nonempty(...args) {
return this.check(
_minLength(
1,
...args,
),
);
},
lowercase(params) {
return this.check(
_lowercase(
params,
),
);
},
uppercase(params) {
return this.check(
_uppercase(
params,
),
);
},
trim() {
return this.check(
_trim(),
);
},
normalize(...args) {
return this.check(
_normalize(
...args,
),
);
},
toLowerCase() {
return this.check(
_toLowerCase(),
);
},
toUpperCase() {
return this.check(
_toUpperCase(),
);
},
slugify() {
return this.check(
_slugify(),
);
},
},
),
);
const ZodString =
$constructor(
"ZodString",
(inst, def) => {
$ZodString.init(inst, def);
_ZodString.init(inst, def);
},
{
email(params) {
return this.check(
_email(
ZodEmail,
params,
),
);
},
url(params) {
return this.check(
_url(
ZodURL,
params,
),
);
},
jwt(params) {
return this.check(
_jwt(
ZodJWT,
params,
),
);
},
emoji(params) {
return this.check(
_emoji(
ZodEmoji,
params,
),
);
},
guid(params) {
return this.check(
_guid(
ZodGUID,
params,
),
);
},
uuid(params) {
return this.check(
_uuid(
ZodUUID,
params,
),
);
},
uuidv4(params) {
return this.check(
_uuidv4(
ZodUUID,
params,
),
);
},
uuidv6(params) {
return this.check(
_uuidv6(
ZodUUID,
params,
),
);
},
uuidv7(params) {
return this.check(
_uuidv7(
ZodUUID,
params,
),
);
},
nanoid(params) {
return this.check(
_nanoid(
ZodNanoID,
params,
),
);
},
cuid(params) {
return this.check(
_cuid(
ZodCUID,
params,
),
);
},
cuid2(params) {
return this.check(
_cuid2(
ZodCUID2,
params,
),
);
},
ulid(params) {
return this.check(
_ulid(
ZodULID,
params,
),
);
},
base64(params) {
return this.check(
_base64(
ZodBase64,
params,
),
);
},
base64url(params) {
return this.check(
_base64url(
ZodBase64URL,
params,
),
);
},
xid(params) {
return this.check(
_xid(
ZodXID,
params,
),
);
},
ksuid(params) {
return this.check(
_ksuid(
ZodKSUID,
params,
),
);
},
ipv4(params) {
return this.check(
_ipv4(
ZodIPv4,
params,
),
);
},
ipv6(params) {
return this.check(
_ipv6(
ZodIPv6,
params,
),
);
},
cidrv4(params) {
return this.check(
_cidrv4(
ZodCIDRv4,
params,
),
);
},
cidrv6(params) {
return this.check(
_cidrv6(
ZodCIDRv6,
params,
),
);
},
e164(params) {
return this.check(
_e164(
ZodE164,
params,
),
);
},
datetime(params) {
return this.check(
_isoDateTime(
ZodISODateTime,
params,
),
);
},
date(params) {
return this.check(
_isoDate(
ZodISODate,
params,
),
);
},
time(params) {
return this.check(
_isoTime(
ZodISOTime,
params,
),
);
},
duration(params) {
return this.check(
_isoDuration(
ZodISODuration,
params,
),
);
},
},
);
function string(params) {
return _string(
ZodString,
params,
);
}
const ZodStringFormat =
$constructor(
"ZodStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
},
);
const ZodISODateTime =
$constructor(
"ZodISODateTime",
(inst, def) => {
$ZodISODateTime.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISODate =
$constructor(
"ZodISODate",
(inst, def) => {
$ZodISODate.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISOTime =
$constructor(
"ZodISOTime",
(inst, def) => {
$ZodISOTime.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISODuration =
$constructor(
"ZodISODuration",
(inst, def) => {
$ZodISODuration.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodEmail =
$constructor(
"ZodEmail",
(inst, def) => {
$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodGUID =
$constructor(
"ZodGUID",
(inst, def) => {
$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodUUID =
$constructor(
"ZodUUID",
(inst, def) => {
$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodURL =
$constructor(
"ZodURL",
(inst, def) => {
$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
function url(params) {
return _url(
ZodURL,
params,
);
}
const ZodEmoji =
$constructor(
"ZodEmoji",
(inst, def) => {
$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodNanoID =
$constructor(
"ZodNanoID",
(inst, def) => {
$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCUID =
$constructor(
"ZodCUID",
(inst, def) => {
$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCUID2 =
$constructor(
"ZodCUID2",
(inst, def) => {
$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodULID =
$constructor(
"ZodULID",
(inst, def) => {
$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodXID =
$constructor(
"ZodXID",
(inst, def) => {
$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodKSUID =
$constructor(
"ZodKSUID",
(inst, def) => {
$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodIPv4 =
$constructor(
"ZodIPv4",
(inst, def) => {
$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodIPv6 =
$constructor(
"ZodIPv6",
(inst, def) => {
$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCIDRv4 =
$constructor(
"ZodCIDRv4",
(inst, def) => {
$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCIDRv6 =
$constructor(
"ZodCIDRv6",
(inst, def) => {
$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodBase64 =
$constructor(
"ZodBase64",
(inst, def) => {
$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodBase64URL =
$constructor(
"ZodBase64URL",
(inst, def) => {
$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodE164 =
$constructor(
"ZodE164",
(inst, def) => {
$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodJWT =
$constructor(
"ZodJWT",
(inst, def) => {
$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodNumber =
$constructor(
"ZodNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
numberProcessor(
inst,
ctx,
json,
params,
);
inst.isFinite = true;
},
derived(
{
minValue: (inst) => {
const {
minimum,
exclusiveMinimum,
} = aggregateChecks(inst);
return Math.max(
minimum ??
Number.NEGATIVE_INFINITY,
exclusiveMinimum ??
Number.NEGATIVE_INFINITY,
);
},
maxValue: (inst) => {
const {
maximum,
exclusiveMaximum,
} = aggregateChecks(inst);
return Math.min(
maximum ??
Number.POSITIVE_INFINITY,
exclusiveMaximum ??
Number.POSITIVE_INFINITY,
);
},
isInt: (inst) => {
const { isInt, multipleOf } =
aggregateChecks(inst);
return (
!!isInt ||
!!multipleOf?.some(
Number.isSafeInteger,
)
);
},
format: (inst) =>
aggregateChecks(inst)
.format ?? null,
},
{
gt(value, params) {
return this.check(
_gt(
value,
params,
),
);
},
gte(value, params) {
return this.check(
_gte(
value,
params,
),
);
},
min(value, params) {
return this.check(
_gte(
value,
params,
),
);
},
lt(value, params) {
return this.check(
_lt(
value,
params,
),
);
},
lte(value, params) {
return this.check(
_lte(
value,
params,
),
);
},
max(value, params) {
return this.check(
_lte(
value,
params,
),
);
},
int(params) {
return this.check(
int(params),
);
},
safe(params) {
return this.check(
int(params),
);
},
positive(params) {
return this.check(
_gt(
0,
params,
),
);
},
nonnegative(params) {
return this.check(
_gte(
0,
params,
),
);
},
negative(params) {
return this.check(
_lt(
0,
params,
),
);
},
nonpositive(params) {
return this.check(
_lte(
0,
params,
),
);
},
multipleOf(value, params) {
return this.check(
_multipleOf(
value,
params,
),
);
},
step(value, params) {
return this.check(
_multipleOf(
value,
params,
),
);
},
finite() {
return this;
},
},
),
);
function number(params) {
return _number(
ZodNumber,
params,
);
}
const ZodNumberFormat =
$constructor(
"ZodNumberFormat",
(inst, def) => {
$ZodNumberFormat.init(inst, def);
ZodNumber.init(inst, def);
},
);
function int(params) {
return _int(
ZodNumberFormat,
params,
);
}
const ZodUnknown =
$constructor(
"ZodUnknown",
(inst, def) => {
$ZodUnknown.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) => void 0;
},
);
function unknown() {
return _unknown(
ZodUnknown,
);
}
const ZodNever =
$constructor(
"ZodNever",
(inst, def) => {
$ZodNever.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
neverProcessor(
inst,
ctx,
json,
params,
);
},
);
function never(params) {
return _never(
ZodNever,
params,
);
}
const ZodDate =
$constructor(
"ZodDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
dateProcessor(
inst,
ctx,
json,
params,
);
inst.min = (value, params) =>
inst.check(
_gte(
value,
params,
),
);
inst.max = (value, params) =>
inst.check(
_lte(
value,
params,
),
);
},
derived(
{
minDate: (inst) => {
const { minimum } =
aggregateChecks(inst);
return minimum
? new Date(minimum)
: null;
},
maxDate: (inst) => {
const { maximum } =
aggregateChecks(inst);
return maximum
? new Date(maximum)
: null;
},
},
{},
),
);
function date(params) {
return _date(
ZodDate,
params,
);
}
const ZodArray =
$constructor(
"ZodArray",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodArray.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
arrayProcessor(
inst,
ctx,
json,
params,
);
inst.element = def.element;
},
{
min(n, params) {
return this.check(
_minLength(
n,
params,
),
);
},
nonempty(params) {
return this.check(
_minLength(
1,
params,
),
);
},
max(n, params) {
return this.check(
_maxLength(
n,
params,
),
);
},
length(n, params) {
return this.check(
_length(
n,
params,
),
);
},
unwrap() {
return this.element;
},
},
);
function array(element, params) {
return _array(
ZodArray,
element,
params,
);
}
const ZodObject =
$constructor(
"ZodObject",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodObjectJIT.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
objectProcessor(
inst,
ctx,
json,
params,
);
installLazyProp(
inst,
"shape",
(self) => self._zod.def.shape,
false,
);
},
{
keyof() {
return _enum(
Object.keys(
this._zod.def.shape,
),
);
},
catchall(catchall) {
return this.clone(
mergeDefs(this._zod.def, {
catchall,
}),
);
},
passthrough() {
return this.clone(
mergeDefs(this._zod.def, {
catchall: unknown(),
}),
);
},
loose() {
return this.clone(
mergeDefs(this._zod.def, {
catchall: unknown(),
}),
);
},
strict() {
return this.clone(
mergeDefs(this._zod.def, {
catchall: never(),
}),
);
},
strip() {
return this.clone(
mergeDefs(this._zod.def, {
catchall: void 0,
}),
);
},
extend(incoming) {
return extend(this, incoming);
},
safeExtend(incoming) {
return safeExtend(
this,
incoming,
);
},
merge(other) {
return merge(this, other);
},
pick(mask) {
return pick(this, mask);
},
omit(mask) {
return omit(this, mask);
},
partial(...args) {
return partial(
ZodOptional,
this,
args[0],
);
},
exactPartial(...args) {
return partial(
ZodExactOptional,
this,
args[0],
"exactPartial",
);
},
required(...args) {
return required(
ZodNonOptional,
this,
args[0],
);
},
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodObject(def);
}
const ZodUnion =
$constructor(
"ZodUnion",
(inst, def) => {
$ZodUnion.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
unionProcessor(
inst,
ctx,
json,
params,
);
inst.options = def.options;
},
);
function union(options, params) {
return new ZodUnion({
type: "union",
options,
...normalizeParams(params),
});
}
const ZodIntersection =
$constructor(
"ZodIntersection",
(inst, def) => {
$ZodIntersection.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
intersectionProcessor(
inst,
ctx,
json,
params,
);
},
);
function intersection(left, right) {
return new ZodIntersection({
type: "intersection",
left,
right,
});
}
const ZodEnum =
$constructor(
"ZodEnum",
(inst, def) => {
$ZodEnum.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
enumProcessor(
inst,
ctx,
json,
params,
);
inst.enum = def.entries;
inst.options = [
...inst._zod.values,
];
const keys = new Set(
Object.keys(def.entries),
);
inst.extract = (
values,
params,
) => {
const newEntries = {};
for (const value of values)
if (keys.has(value))
newEntries[value] =
def.entries[value];
else
throw new Error(
`Key ${value} not found in enum`,
);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (
values,
params,
) => {
const newEntries = {
...def.entries,
};
for (const value of values)
if (keys.has(value))
delete newEntries[value];
else
throw new Error(
`Key ${value} not found in enum`,
);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
},
);
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(
values.map((v) => [v, v]),
)
: values;
return new ZodEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodTransform =
$constructor(
"ZodTransform",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodTransform.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
transformProcessor(
inst,
ctx,
json,
params,
);
inst._zod.parse = (
payload,
_ctx,
) => {
if (
_ctx.direction === "backward"
)
throw new $ZodEncodeError(
inst.constructor.name,
);
payload.addIssue = (
issue$1,
) => {
if (
typeof issue$1 === "string"
)
payload.issues.push(
issue(
issue$1,
payload.value,
def,
),
);
else {
const _issue = issue$1;
if (_issue.fatal)
_issue.continue = false;
_issue.code ??
(_issue.code = "custom");
if (!("input" in _issue))
_issue.input =
payload.value;
_issue.inst ??
(_issue.inst = inst);
payload.issues.push(
issue(_issue),
);
}
};
const output = def.transform(
payload.value,
payload,
);
if (output instanceof Promise)
return output.then(
(output) => {
payload.value = output;
return payload;
},
);
payload.value = output;
return payload;
};
},
);
function transform(fn) {
return new ZodTransform({
type: "transform",
transform: fn,
});
}
const ZodOptional =
$constructor(
"ZodOptional",
(inst, def) => {
$ZodOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
optionalProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function optional(innerType) {
return new ZodOptional({
type: "optional",
innerType,
});
}
const ZodExactOptional =
$constructor(
"ZodExactOptional",
(inst, def) => {
$ZodExactOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
optionalProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function exactOptional(innerType) {
return new ZodExactOptional({
type: "optional",
innerType,
});
}
const ZodNullable =
$constructor(
"ZodNullable",
(inst, def) => {
$ZodNullable.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
nullableProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function nullable(innerType) {
return new ZodNullable({
type: "nullable",
innerType,
});
}
const ZodDefault =
$constructor(
"ZodDefault",
(inst, def) => {
$ZodDefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
defaultProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
},
);
function _default(
innerType,
defaultValue,
) {
return new ZodDefault({
type: "default",
innerType,
get defaultValue() {
return typeof defaultValue ===
"function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodPrefault =
$constructor(
"ZodPrefault",
(inst, def) => {
$ZodPrefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
prefaultProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function prefault(
innerType,
defaultValue,
) {
return new ZodPrefault({
type: "prefault",
innerType,
get defaultValue() {
return typeof defaultValue ===
"function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodNonOptional =
$constructor(
"ZodNonOptional",
(inst, def) => {
$ZodNonOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
nonoptionalProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function nonoptional(
innerType,
params,
) {
return new ZodNonOptional({
type: "nonoptional",
innerType,
...normalizeParams(params),
});
}
const ZodCatch =
$constructor(
"ZodCatch",
(inst, def) => {
$ZodCatch.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
catchProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
},
);
function _catch(innerType, catchValue) {
return new ZodCatch({
type: "catch",
innerType,
catchValue:
typeof catchValue === "function"
? catchValue
: constantCatch(catchValue),
});
}
const ZodPipe =
$constructor(
"ZodPipe",
(inst, def) => {
$ZodPipe.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
pipeProcessor(
inst,
ctx,
json,
params,
);
inst.in = def.in;
inst.out = def.out;
},
);
function pipe(in_, out) {
return new ZodPipe({
type: "pipe",
in: in_,
out,
});
}
const ZodReadonly =
$constructor(
"ZodReadonly",
(inst, def) => {
$ZodReadonly.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
readonlyProcessor(
inst,
ctx,
json,
params,
);
inst.unwrap = () =>
inst._zod.def.innerType;
},
);
function readonly(innerType) {
return new ZodReadonly({
type: "readonly",
innerType,
});
}
const ZodCustom =
$constructor(
"ZodCustom",
(inst, def) => {
$ZodCustom.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (
ctx,
json,
params,
) =>
customProcessor(
inst,
ctx,
json,
params,
);
},
);
function refine(fn, _params = {}) {
return _refine(
ZodCustom,
fn,
_params,
);
}
function superRefine(fn, params) {
return _superRefine(
fn,
params,
);
}
function __zcUw(m) {
return typeof m === "string"
? m
: m === void 0 || m === null
? void 0
: m.message;
}
var __zcMsg = function (iss) {
var c = config(),
m;
if (c.customError) {
m = __zcUw(c.customError(iss));
if (m !== void 0 && m !== null)
return m;
}
if (c.localeError) {
m = __zcUw(c.localeError(iss));
if (m !== void 0 && m !== null)
return m;
}
return "Invalid input";
};
function __ZcFail(e, f, i) {
this.success = false;
this._e = e;
this._f = f;
this._i = i;
this._c = void 0;
}
Object.defineProperty(
__ZcFail.prototype,
"error",
{
configurable: true,
get: function () {
if (this._c) return this._c;
var e =
this._f !== null
? this._f(this._i)
: this._e;
for (
var i = 0;
i < e.length;
i++
) {
if (
e[i].message === void 0 &&
typeof __zcMsg === "function"
)
e[i].message = __zcMsg(e[i]);
delete e[i].input;
delete e[i].continue;
}
return (this._c =
new ZodRealError(e));
},
},
);
function __ZcFailZ(z, r, i) {
this.success = false;
this._z = z;
this._r = r;
this._i = i;
this._c = void 0;
}
Object.defineProperty(
__ZcFailZ.prototype,
"error",
{
configurable: true,
get: function () {
return (
this._c ||
(this._c = this._z.call(
this._r,
this._i,
).error)
);
},
},
);
function __zcMkv(fn, schema, fc, is) {
var w = schema || {};
var zpa = w.parseAsync,
zspa = w.safeParseAsync;
w.parse = fc
? function (input) {
if (fc(input)) return input;
var r = fn(input);
if (r.success) return r.data;
throw r.error;
}
: function (input) {
var r = fn(input);
if (r.success) return r.data;
throw r.error;
};
w.safeParse = fn;
w.safeParseAsync = function (input) {
try {
return Promise.resolve(fn(input));
} catch (e) {
if (zspa) return zspa(input);
throw e;
}
};
w.parseAsync = fc
? function (input) {
try {
if (fc(input))
return Promise.resolve(
input,
);
var r = fn(input);
if (r.success)
return Promise.resolve(
r.data,
);
return Promise.reject(
r.error,
);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
}
: function (input) {
try {
var r = fn(input);
if (r.success)
return Promise.resolve(
r.data,
);
return Promise.reject(
r.error,
);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
};
w.is =
is ||
function (input) {
return fn(input).success;
};
Object.defineProperty(
w,
"~standard",
{
configurable: true,
value: {
version: 1,
vendor: "zod",
validate: function (input) {
var r;
try {
if (fc && fc(input))
return { value: input };
r = fn(input);
} catch (e) {
if (zspa)
return zspa(input).then(
function (q) {
return q.success
? { value: q.data }
: {
issues:
q.error
.issues,
};
},
);
throw e;
}
return r.success
? { value: r.data }
: {
issues: r.error.issues,
};
},
},
},
);
return w;
}
function __zcFin(e, d) {
if (!e.length)
return {
success: true,
data: d,
};
return new __ZcFail(e, null, null);
}
function __zcTS(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_small",
minimum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcTB(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_big",
maximum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIT(e, inp, p, msg) {
var r = {
expected: e,
code: "invalid_type",
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIF(
o,
f,
inp,
p,
extra,
msg,
) {
var r =
o === void 0
? {
code: "invalid_format",
format: f,
}
: {
origin: o,
code: "invalid_format",
format: f,
};
if (extra) Object.assign(r, extra);
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIV(
values,
inp,
p,
extra,
msg,
) {
var r = { code: "invalid_value" };
if (extra) Object.assign(r, extra);
r.values = values;
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcLo(v) {
return Array.isArray(v)
? "array"
: typeof v === "string"
? "string"
: "unknown";
}
function __zcCpl(s) {
var n = s.length;
if (!/[\uD800-\uDBFF]/.test(s))
return n;
var c = n;
for (var i = 0; i < n - 1; i++)
if (
(s.charCodeAt(i) & 64512) ===
55296 &&
(s.charCodeAt(i + 1) & 64512) ===
56320
) {
c--;
i++;
}
return c;
}
var __re_tnl_11 =
new RegExp(
"[\\t\\n\\r]",
"g",
);
function __zcSw_0(input, path, _e) {
if (!Array.isArray(input))
_e.push(
__zcIT("array", input, path),
);
else {
var __ar_0 = input;
__ar_0 = __ar_0.slice();
for (
var __i_1 = 0;
__i_1 < __ar_0.length;
__i_1++
)
__ar_0[__i_1] = __zcSw_1(
__ar_0[__i_1],
path.concat(__i_1),
_e,
);
input = __ar_0;
}
return input;
}
function __zcSw_1(input, path, _e) {
if (
typeof input !== "object" ||
input === null ||
Array.isArray(input)
)
_e.push(
__zcIT("object", input, path),
);
else {
var __sv_3 = input["id"];
if (typeof __sv_3 !== "number")
_e.push(
__zcIT(
"number",
__sv_3,
path.concat("id"),
),
);
else if (Number.isNaN(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_3,
path: path.concat("id"),
});
else if (!Number.isFinite(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_3),
input: __sv_3,
path: path.concat("id"),
});
var __sv_4 = input["created"];
if (!(__sv_4 instanceof Date))
_e.push(
__zcIT(
"date",
__sv_4,
path.concat("created"),
),
);
else if (isNaN(__sv_4.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_4,
path: path.concat("created"),
});
var __sv_5 = input["title"];
if (typeof __sv_5 !== "string") {
_e.push(
__zcIT(
"string",
__sv_5,
path.concat("title"),
),
);
if (
__sv_5 !== void 0 &&
__sv_5 !== null &&
__sv_5.length !== void 0
) {
if (__sv_5.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_5),
true,
__sv_5,
path.concat("title"),
),
);
if (__sv_5.length > 100)
_e.push(
__zcTB(
100,
__zcLo(__sv_5),
true,
__sv_5,
path.concat("title"),
),
);
}
} else {
if (__sv_5.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_5,
path.concat("title"),
),
);
if (
__sv_5.length > 100 &&
(__sv_5.length > 200 ||
__zcCpl(__sv_5) > 100)
)
_e.push(
__zcTB(
100,
"string",
true,
__sv_5,
path.concat("title"),
),
);
}
var __sv_6 = input["type"];
if (
__sv_6 !== "jpg" &&
__sv_6 !== "png"
)
_e.push(
__zcIV(
["jpg", "png"],
__sv_6,
path.concat("type"),
),
);
var __sv_7 = input["size"];
if (typeof __sv_7 !== "number")
_e.push(
__zcIT(
"number",
__sv_7,
path.concat("size"),
),
);
else if (Number.isNaN(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_7,
path: path.concat("size"),
});
else if (!Number.isFinite(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_7),
input: __sv_7,
path: path.concat("size"),
});
var __sv_8 = input["url"];
if (typeof __sv_8 !== "string")
_e.push(
__zcIT(
"string",
__sv_8,
path.concat("url"),
),
);
else {
var __ut_9 = __sv_8.trim();
var __u_10 = null;
try {
__u_10 = new URL(__ut_9);
} catch (_) {}
if (__u_10 === null)
_e.push(
__zcIF(
void 0,
"url",
__sv_8,
path.concat("url"),
),
);
else
__sv_8 = __ut_9.replace(
__re_tnl_11,
"",
);
}
input = {
id: __sv_3,
created: __sv_4,
title: __sv_5,
type: __sv_6,
size: __sv_7,
url: __sv_8,
};
}
return input;
}
const imageSchema = object({
id: number(),
created: date(),
title: string().min(1).max(100),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().min(1).max(5),
title: string().min(1).max(100),
text: string().min(1).max(1e3),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().min(1).max(100),
brand: string().min(1).max(30),
description: string()
.min(1)
.max(500),
price: number().min(1).max(1e4),
discount: number()
.min(1)
.max(100)
.nullable(),
quantity: number().min(0).max(10),
tags: array(
string().min(1).max(30),
),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
);
(() => {
function safeParse_compiledProductSchema(
input,
) {
var _e = [];
var _d = input;
if (
typeof _d !== "object" ||
_d === null ||
Array.isArray(_d)
)
_e.push(__zcIT("object", _d, []));
else {
var __sv_5 = _d["id"];
if (typeof __sv_5 !== "number")
_e.push(
__zcIT("number", __sv_5, [
"id",
]),
);
else if (Number.isNaN(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_5,
path: ["id"],
});
else if (!Number.isFinite(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_5),
input: __sv_5,
path: ["id"],
});
var __sv_6 = _d["created"];
if (!(__sv_6 instanceof Date))
_e.push(
__zcIT("date", __sv_6, [
"created",
]),
);
else if (isNaN(__sv_6.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_6,
path: ["created"],
});
var __sv_7 = _d["title"];
if (typeof __sv_7 !== "string") {
_e.push(
__zcIT("string", __sv_7, [
"title",
]),
);
if (
__sv_7 !== void 0 &&
__sv_7 !== null &&
__sv_7.length !== void 0
) {
if (__sv_7.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_7),
true,
__sv_7,
["title"],
),
);
if (__sv_7.length > 100)
_e.push(
__zcTB(
100,
__zcLo(__sv_7),
true,
__sv_7,
["title"],
),
);
}
} else {
if (__sv_7.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_7,
["title"],
),
);
if (
__sv_7.length > 100 &&
(__sv_7.length > 200 ||
__zcCpl(__sv_7) > 100)
)
_e.push(
__zcTB(
100,
"string",
true,
__sv_7,
["title"],
),
);
}
var __sv_8 = _d["brand"];
if (typeof __sv_8 !== "string") {
_e.push(
__zcIT("string", __sv_8, [
"brand",
]),
);
if (
__sv_8 !== void 0 &&
__sv_8 !== null &&
__sv_8.length !== void 0
) {
if (__sv_8.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_8),
true,
__sv_8,
["brand"],
),
);
if (__sv_8.length > 30)
_e.push(
__zcTB(
30,
__zcLo(__sv_8),
true,
__sv_8,
["brand"],
),
);
}
} else {
if (__sv_8.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_8,
["brand"],
),
);
if (
__sv_8.length > 30 &&
(__sv_8.length > 60 ||
__zcCpl(__sv_8) > 30)
)
_e.push(
__zcTB(
30,
"string",
true,
__sv_8,
["brand"],
),
);
}
var __sv_9 = _d["description"];
if (typeof __sv_9 !== "string") {
_e.push(
__zcIT("string", __sv_9, [
"description",
]),
);
if (
__sv_9 !== void 0 &&
__sv_9 !== null &&
__sv_9.length !== void 0
) {
if (__sv_9.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_9),
true,
__sv_9,
["description"],
),
);
if (__sv_9.length > 500)
_e.push(
__zcTB(
500,
__zcLo(__sv_9),
true,
__sv_9,
["description"],
),
);
}
} else {
if (__sv_9.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_9,
["description"],
),
);
if (
__sv_9.length > 500 &&
(__sv_9.length > 1e3 ||
__zcCpl(__sv_9) > 500)
)
_e.push(
__zcTB(
500,
"string",
true,
__sv_9,
["description"],
),
);
}
var __sv_10 = _d["price"];
if (typeof __sv_10 !== "number")
_e.push(
__zcIT("number", __sv_10, [
"price",
]),
);
else if (Number.isNaN(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_10,
path: ["price"],
});
else if (
!Number.isFinite(__sv_10)
)
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_10),
input: __sv_10,
path: ["price"],
});
else {
if (__sv_10 < 1)
_e.push(
__zcTS(
1,
"number",
true,
__sv_10,
["price"],
),
);
if (__sv_10 > 1e4)
_e.push(
__zcTB(
1e4,
"number",
true,
__sv_10,
["price"],
),
);
}
var __sv_11 = _d["discount"];
if (__sv_11 !== null) {
if (typeof __sv_11 !== "number")
_e.push(
__zcIT("number", __sv_11, [
"discount",
]),
);
else if (Number.isNaN(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_11,
path: ["discount"],
});
else if (
!Number.isFinite(__sv_11)
)
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_11),
input: __sv_11,
path: ["discount"],
});
else {
if (__sv_11 < 1)
_e.push(
__zcTS(
1,
"number",
true,
__sv_11,
["discount"],
),
);
if (__sv_11 > 100)
_e.push(
__zcTB(
100,
"number",
true,
__sv_11,
["discount"],
),
);
}
}
var __sv_12 = _d["quantity"];
if (typeof __sv_12 !== "number")
_e.push(
__zcIT("number", __sv_12, [
"quantity",
]),
);
else if (Number.isNaN(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_12,
path: ["quantity"],
});
else if (
!Number.isFinite(__sv_12)
)
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_12),
input: __sv_12,
path: ["quantity"],
});
else {
if (__sv_12 < 0)
_e.push(
__zcTS(
0,
"number",
true,
__sv_12,
["quantity"],
),
);
if (__sv_12 > 10)
_e.push(
__zcTB(
10,
"number",
true,
__sv_12,
["quantity"],
),
);
}
var __sv_13 = _d["tags"];
if (!Array.isArray(__sv_13))
_e.push(
__zcIT("array", __sv_13, [
"tags",
]),
);
else {
var __ar_14 = __sv_13;
for (
var __i_15 = 0;
__i_15 < __ar_14.length;
__i_15++
) {
var __mv_16 = __ar_14[__i_15];
if (
typeof __mv_16 !== "string"
) {
_e.push(
__zcIT(
"string",
__mv_16,
["tags", __i_15],
),
);
if (
__mv_16 !== void 0 &&
__mv_16 !== null &&
__mv_16.length !== void 0
) {
if (__mv_16.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__mv_16),
true,
__mv_16,
["tags", __i_15],
),
);
if (__mv_16.length > 30)
_e.push(
__zcTB(
30,
__zcLo(__mv_16),
true,
__mv_16,
["tags", __i_15],
),
);
}
} else {
if (__mv_16.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__mv_16,
["tags", __i_15],
),
);
if (
__mv_16.length > 30 &&
(__mv_16.length > 60 ||
__zcCpl(__mv_16) > 30)
)
_e.push(
__zcTB(
30,
"string",
true,
__mv_16,
["tags", __i_15],
),
);
}
}
__sv_13 = __ar_14;
}
var __sv_18 = _d["images"];
__sv_18 = __zcSw_0(
__sv_18,
["images"],
_e,
);
var __sv_19 = _d["ratings"];
if (!Array.isArray(__sv_19))
_e.push(
__zcIT("array", __sv_19, [
"ratings",
]),
);
else {
var __ar_20 = __sv_19;
__ar_20 = __ar_20.slice();
for (
var __i_21 = 0;
__i_21 < __ar_20.length;
__i_21++
)
if (
typeof __ar_20[__i_21] !==
"object" ||
__ar_20[__i_21] === null ||
Array.isArray(
__ar_20[__i_21],
)
)
_e.push(
__zcIT(
"object",
__ar_20[__i_21],
["ratings", __i_21],
),
);
else {
var __sv_23 =
__ar_20[__i_21]["id"];
if (
typeof __sv_23 !==
"number"
)
_e.push(
__zcIT(
"number",
__sv_23,
[
"ratings",
__i_21,
"id",
],
),
);
else if (
Number.isNaN(__sv_23)
)
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_23,
path: [
"ratings",
__i_21,
"id",
],
});
else if (
!Number.isFinite(__sv_23)
)
_e.push({
expected: "number",
code: "invalid_type",
received:
String(__sv_23),
input: __sv_23,
path: [
"ratings",
__i_21,
"id",
],
});
var __sv_24 =
__ar_20[__i_21]["stars"];
if (
typeof __sv_24 !==
"number"
)
_e.push(
__zcIT(
"number",
__sv_24,
[
"ratings",
__i_21,
"stars",
],
),
);
else if (
Number.isNaN(__sv_24)
)
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_24,
path: [
"ratings",
__i_21,
"stars",
],
});
else if (
!Number.isFinite(__sv_24)
)
_e.push({
expected: "number",
code: "invalid_type",
received:
String(__sv_24),
input: __sv_24,
path: [
"ratings",
__i_21,
"stars",
],
});
else {
if (__sv_24 < 1)
_e.push(
__zcTS(
1,
"number",
true,
__sv_24,
[
"ratings",
__i_21,
"stars",
],
),
);
if (__sv_24 > 5)
_e.push(
__zcTB(
5,
"number",
true,
__sv_24,
[
"ratings",
__i_21,
"stars",
],
),
);
}
var __sv_25 =
__ar_20[__i_21]["title"];
if (
typeof __sv_25 !==
"string"
) {
_e.push(
__zcIT(
"string",
__sv_25,
[
"ratings",
__i_21,
"title",
],
),
);
if (
__sv_25 !== void 0 &&
__sv_25 !== null &&
__sv_25.length !==
void 0
) {
if (__sv_25.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_25),
true,
__sv_25,
[
"ratings",
__i_21,
"title",
],
),
);
if (
__sv_25.length > 100
)
_e.push(
__zcTB(
100,
__zcLo(__sv_25),
true,
__sv_25,
[
"ratings",
__i_21,
"title",
],
),
);
}
} else {
if (__sv_25.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_25,
[
"ratings",
__i_21,
"title",
],
),
);
if (
__sv_25.length > 100 &&
(__sv_25.length > 200 ||
__zcCpl(__sv_25) >
100)
)
_e.push(
__zcTB(
100,
"string",
true,
__sv_25,
[
"ratings",
__i_21,
"title",
],
),
);
}
var __sv_26 =
__ar_20[__i_21]["text"];
if (
typeof __sv_26 !==
"string"
) {
_e.push(
__zcIT(
"string",
__sv_26,
[
"ratings",
__i_21,
"text",
],
),
);
if (
__sv_26 !== void 0 &&
__sv_26 !== null &&
__sv_26.length !==
void 0
) {
if (__sv_26.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_26),
true,
__sv_26,
[
"ratings",
__i_21,
"text",
],
),
);
if (
__sv_26.length > 1e3
)
_e.push(
__zcTB(
1e3,
__zcLo(__sv_26),
true,
__sv_26,
[
"ratings",
__i_21,
"text",
],
),
);
}
} else {
if (__sv_26.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_26,
[
"ratings",
__i_21,
"text",
],
),
);
if (
__sv_26.length > 1e3 &&
(__sv_26.length > 2e3 ||
__zcCpl(__sv_26) >
1e3)
)
_e.push(
__zcTB(
1e3,
"string",
true,
__sv_26,
[
"ratings",
__i_21,
"text",
],
),
);
}
var __sv_27 =
__ar_20[__i_21]["images"];
__sv_27 = __zcSw_0(
__sv_27,
[
"ratings",
__i_21,
"images",
],
_e,
);
__ar_20[__i_21] = {
id: __sv_23,
stars: __sv_24,
title: __sv_25,
text: __sv_26,
images: __sv_27,
};
}
__sv_19 = __ar_20;
}
_d = {
id: __sv_5,
created: __sv_6,
title: __sv_7,
brand: __sv_8,
description: __sv_9,
price: __sv_10,
discount: __sv_11,
quantity: __sv_12,
tags: __sv_13,
images: __sv_18,
ratings: __sv_19,
};
}
if (_e.length === 0)
return {
success: true,
data: _d,
};
return __zcFin(_e, _d);
}
return __zcMkv(
safeParse_compiledProductSchema,
null,
null,
null,
);
})().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 joinValues(array, separator = "|") {
return array
.map((val) => stringifyPrimitive(val))
.join(separator);
}
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 floatSafeRemainder(val, step) {
const ratio = val / step;
const roundedRatio = Math.round(ratio);
const tolerance =
4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
return ratio - roundedRatio;
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
function rawShape(def) {
const desc = Object.getOwnPropertyDescriptor(
def,
"shape",
);
return desc?.get ? desc.get.raw : desc?.value;
}
function sourceShape(schema) {
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
}
function deferProp(target, key, getter) {
Object.defineProperty(target, key, {
get() {
const value = getter();
assignProp(this, key, value);
return value;
},
enumerable: true,
configurable: true,
});
}
function putProp(target, key, value) {
if (key in target) assignProp(target, key, value);
else target[key] = value;
}
function mirrorShape(target, source, keys, wrap) {
const raw = sourceShape(source);
for (const key of keys) {
const desc = Object.getOwnPropertyDescriptor(raw, key);
if (!desc.enumerable) continue;
if (desc.get)
deferProp(target, key, () => {
const value = source._zod.def.shape[key];
return wrap ? wrap(value, key) : value;
});
else
putProp(
target,
key,
wrap ? wrap(desc.value, key) : desc.value,
);
}
}
function mirrorProps(target, source) {
for (const key of Reflect.ownKeys(source)) {
const desc = Object.getOwnPropertyDescriptor(
source,
key,
);
if (!desc.enumerable) continue;
if (desc.get) deferProp(target, key, () => source[key]);
else putProp(target, key, desc.value);
}
}
function mergeDefs(...defs) {
const mergedDescriptors = {};
for (const def of defs) {
const descriptors =
Object.getOwnPropertyDescriptors(def);
Object.assign(mergedDescriptors, descriptors);
}
return Object.defineProperties({}, mergedDescriptors);
}
function esc(str) {
return JSON.stringify(str);
}
function slugify(input) {
return input
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, "")
.replace(/[\s_-]+/g, "-")
.replace(/^-+|-+$/g, "");
}
const captureStackTrace =
"captureStackTrace" in Error
? Error.captureStackTrace
: (..._args) => {};
function isObject(data) {
return (
typeof data === "object" &&
data !== null &&
!Array.isArray(data)
);
}
const allowsEval = cached(() => {
if (globalConfig.jitless) return false;
if (
typeof navigator !== "undefined" &&
navigator?.userAgent?.includes("Cloudflare")
)
return false;
try {
new Function("");
return true;
} catch (_) {
return false;
}
});
function isPlainObject(o) {
if (isObject(o) === false) return false;
const ctor = o.constructor;
if (ctor === void 0) return true;
if (typeof ctor !== "function") return true;
const prot = ctor.prototype;
if (isObject(prot) === false) return false;
if (
Object.prototype.hasOwnProperty.call(
prot,
"isPrototypeOf",
) === false
)
return false;
return true;
}
function shallowClone(o) {
if (isPlainObject(o)) return { ...o };
if (Array.isArray(o)) return [...o];
if (o instanceof Map) return new Map(o);
if (o instanceof Set) return new Set(o);
return o;
}
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 stringifyPrimitive(value) {
if (typeof value === "bigint")
return value.toString() + "n";
if (typeof value === "string") return `"${value}"`;
return `${value}`;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return (
shape[k]._zod.optin !== void 0 &&
shape[k]._zod.optout === "optional"
);
});
}
const NUMBER_FORMAT_RANGES = (() => ({
safeint: [
Number.MIN_SAFE_INTEGER,
Number.MAX_SAFE_INTEGER,
],
int32: [-2147483648, 2147483647],
uint32: [0, 4294967295],
float32: [-34028234663852886e22, 34028234663852886e22],
float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
}))();
const BIGINT_FORMAT_RANGES = {
int64: [
BigInt("-9223372036854775808"),
BigInt("9223372036854775807"),
],
uint64: [
BigInt(0),
BigInt("18446744073709551615"),
],
};
function pick(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".pick() cannot be used on object schemas containing refinements",
);
const newShape = {};
mirrorShape(newShape, schema, maskedKeys(schema, mask));
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function maskedKeys(schema, mask) {
const raw = sourceShape(schema);
const keys = [];
for (const key of Reflect.ownKeys(mask)) {
if (
!Object.getOwnPropertyDescriptor(raw, key)?.enumerable
)
throw new Error(`Unrecognized key: "${String(key)}"`);
if (mask[key]) keys.push(key);
}
return keys;
}
function omit(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".omit() cannot be used on object schemas containing refinements",
);
const omitted = new Set(maskedKeys(schema, mask));
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)).filter(
(key) => !omitted.has(key),
),
);
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function extend(schema, shape) {
if (!isPlainObject(shape))
throw new Error(
"Invalid input to extend: expected a plain object",
);
const checks = schema._zod.def.checks;
if (checks && checks.length > 0) {
const existingShape = sourceShape(schema);
for (const key of Reflect.ownKeys(shape))
if (
Object.getOwnPropertyDescriptor(
existingShape,
key,
) !== void 0
)
throw new Error(
"Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.",
);
}
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: extended(schema, shape),
}),
);
}
function extended(schema, shape) {
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
);
mirrorProps(newShape, shape);
return newShape;
}
function safeExtend(schema, shape) {
if (!isPlainObject(shape))
throw new Error(
"Invalid input to safeExtend: expected a plain object",
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: extended(schema, shape),
}),
);
}
function merge(a, b) {
if (!b?._zod?.def)
throw new Error(
"Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.",
);
if (a._zod.def.checks?.length)
throw new Error(
".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.",
);
const newShape = {};
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
return clone(
a,
mergeDefs(a._zod.def, {
shape: newShape,
get catchall() {
return b._zod.def.catchall;
},
checks: b._zod.def.checks ?? [],
}),
);
}
function partial(Class, schema, mask, name = "partial") {
const checks = schema._zod.def.checks;
if (checks && checks.length > 0)
throw new Error(
`.${name}() cannot be used on object schemas containing refinements`,
);
const selected = mask
? new Set(maskedKeys(schema, mask))
: void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
Class &&
((value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "optional",
innerType: value,
})),
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: newShape,
checks: [],
}),
);
}
function required(Class, schema, mask) {
const selected = mask
? new Set(maskedKeys(schema, mask))
: void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
(value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "nonoptional",
innerType: value,
}),
);
return clone(
schema,
mergeDefs(schema._zod.def, { shape: newShape }),
);
}
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 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 parsedType(data) {
const t = typeof data;
switch (t) {
case "number":
return Number.isNaN(data) ? "nan" : "number";
case "object": {
if (data === null) return "null";
if (Array.isArray(data)) return "array";
const obj = data;
if (
obj &&
Object.getPrototypeOf(obj) !== Object.prototype &&
"constructor" in obj &&
obj.constructor
)
return obj.constructor.name;
}
}
return t;
}
function issue(...args) {
const [iss, input, inst] = args;
if (typeof iss === "string")
return {
message: iss,
code: "custom",
input,
inst,
};
return { ...iss };
}
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 derived(computes, table) {
for (const key in computes) {
const compute = computes[key];
Object.defineProperty(table, key, {
configurable: true,
enumerable: true,
get() {
return own(this, key, compute(this));
},
set(value) {
own(this, key, value);
},
});
}
return table;
}
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,
});
},
});
}
const CONSTANT_CATCH = "~constantCatch";
function constantCatch(value) {
const fn = () => value;
fn[CONSTANT_CATCH] = true;
return fn;
}
var _a$1;
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.`,
);
}
};
var $ZodEncodeError = class extends Error {
constructor(name) {
super(
`Encountered unidirectional transform during encode: ${name}`,
);
this.name = "ZodEncodeError";
}
};
(_a$1 = globalThis).__zod_globalConfig ??
(_a$1.__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$1 = (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 $ZodError = $constructor("$ZodError", initializer$1);
$constructor("$ZodError", initializer$1, void 0, {
Parent: Error,
});
function node(obj, key, make) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
if (key === "__proto__")
Object.defineProperty(obj, key, {
value: make(),
writable: true,
enumerable: true,
configurable: true,
});
else obj[key] = make();
}
return obj[key];
}
function flattenError(
error,
mapper = (issue) => issue.message,
) {
const fieldErrors = {};
const formErrors = [];
for (const sub of error.issues)
if (sub.path.length > 0)
node(fieldErrors, sub.path[0], () => []).push(
mapper(sub),
);
else formErrors.push(mapper(sub));
return {
formErrors,
fieldErrors,
};
}
function formatError(
error,
mapper = (issue) => issue.message,
) {
const fieldErrors = { _errors: [] };
const processError = (error, path = []) => {
for (const issue of error.issues)
if (
issue.code === "invalid_union" &&
issue.errors.length
)
issue.errors.map((issues) =>
processError({ issues }, [
...path,
...issue.path,
]),
);
else if (issue.code === "invalid_key")
processError({ issues: issue.issues }, [
...path,
...issue.path,
]);
else if (issue.code === "invalid_element")
processError({ issues: issue.issues }, [
...path,
...issue.path,
]);
else {
const fullpath = [...path, ...issue.path];
if (fullpath.length === 0)
fieldErrors._errors.push(mapper(issue));
else {
let curr = fieldErrors;
let i = 0;
while (i < fullpath.length) {
const el = fullpath[i];
const terminal = i === fullpath.length - 1;
if (el === "_errors") {
if (terminal)
curr._errors.push(mapper(issue));
i++;
continue;
}
if (
!Object.prototype.hasOwnProperty.call(
curr,
el,
)
)
Object.defineProperty(curr, el, {
value: { _errors: [] },
enumerable: true,
writable: true,
configurable: true,
});
const node = curr[el];
if (terminal) node._errors.push(mapper(issue));
curr = node;
i++;
}
}
}
};
processError(error);
return fieldErrors;
}
function finalizeParams(callee, params) {
return {
callee: params?.callee ?? callee,
Err: params?.Err,
};
}
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 _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 _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,
};
};
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 COMPILE_INVALID = Symbol.for(
"zod.compile.invalid",
);
const COMPILE_FALLBACK = Symbol.for(
"zod.compile.fallback",
);
const validate = (schema, value, _ctx) => {
const validator = schema._zod.bag.validator;
if (validator !== void 0) {
if (validator(value) !== COMPILE_INVALID) return true;
if (validator.definite === true && _ctx === void 0)
return false;
}
return validateFallback(schema, value, _ctx);
};
function validateFallback(schema, value, _ctx) {
const ctx = _ctx
? {
..._ctx,
async: false,
abortEarly: true,
}
: {
async: false,
abortEarly: true,
};
const fallbackRun = schema._zod.bag.fallbackRun;
let result;
if (fallbackRun) {
ctx[COMPILE_FALLBACK] = true;
result = fallbackRun(
{
value,
issues: [],
},
ctx,
);
} else
result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length === 0;
}
const validateAsync$1 = async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
abortEarly: true,
}
: {
async: true,
abortEarly: true,
};
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length === 0;
};
const _encode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return parse(
schema,
value,
ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _decode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
return parse(
schema,
value,
_ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _encodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return await parseAsync(
schema,
value,
ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _decodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
return await parseAsync(
schema,
value,
_ctx,
finalizeParams(fn, _params),
);
};
return fn;
};
const _safeEncode = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParse(_Err)(schema, value, ctx);
};
const _safeDecode = (_Err) => (schema, value, _ctx) => {
return _safeParse(_Err)(schema, value, _ctx);
};
const _safeEncodeAsync =
(_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParseAsync(_Err)(schema, value, ctx);
};
const _safeDecodeAsync =
(_Err) => async (schema, value, _ctx) => {
return _safeParseAsync(_Err)(schema, value, _ctx);
};
const cuid = /^[cC][0-9a-z]{6,}$/;
const cuid2 = /^[0-9a-z]+$/;
const ulid = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
const xid = /^[0-9a-vA-V]{20}$/;
const ksuid = /^[A-Za-z0-9]{27}$/;
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
function nanoidOfLength(length) {
return new RegExp(`^[a-zA-Z0-9_-]{${length}}$`);
}
const duration =
/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
const guid =
/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
const uuid = (version) => {
if (!version)
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
return new RegExp(
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`,
);
};
const email =
/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
function emoji() {
return new RegExp(_emoji$1, "u");
}
const ipv4 =
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
const ipv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
const cidrv4 =
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
const cidrv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
const base64 =
/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
const base64url =
/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
const httpProtocol = /^https?$/;
const e164 = /^\+[1-9]\d{6,14}$/;
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
function anchor(source) {
return new RegExp(`^${source}$`);
}
const date$1 = anchor(dateSource);
function timeSource(args) {
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
return typeof args.precision === "number"
? args.precision === -1
? `${hhmm}`
: args.precision === 0
? `${hhmm}:[0-5]\\d`
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
: args.seconds
? `${hhmm}:[0-5]\\d(?:\\.\\d+)?`
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
}
function time(args) {
return new RegExp(`^${timeSource(args)}$`);
}
function datetime(args) {
const opts = ["Z"];
if (args.offset)
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
const qualified = `${timeSource({
precision: args.precision,
seconds: true,
})}(?:${opts.join("|")})`;
const timeRegex = args.local
? `${qualified}|${timeSource({ precision: args.precision })}`
: qualified;
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
}
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const lowercase = /^[^A-Z]*$/;
const uppercase = /^[^a-z]*$/;
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 $ZodCheckMultipleOf = $constructor(
"$ZodCheckMultipleOf",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
if (typeof payload.value !== typeof def.value)
throw new Error(
"Cannot mix number and bigint in multiple_of check.",
);
if (
typeof payload.value === "bigint"
? def.value !== BigInt(0) &&
payload.value % def.value === BigInt(0)
: floatSafeRemainder(payload.value, def.value) ===
0
)
return;
payload.issues.push({
origin: typeof payload.value,
code: "not_multiple_of",
divisor: def.value,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckNumberFormat = $constructor(
"$ZodCheckNumberFormat",
(inst, def) => {
$ZodCheck.init(inst, def);
def.format = def.format || "float64";
const isInt = def.format?.includes("int");
const origin = isInt ? "int" : "number";
const [minimum, maximum] =
NUMBER_FORMAT_RANGES[def.format];
inst._zod.check = (payload) => {
const input = payload.value;
if (isInt) {
if (!Number.isInteger(input)) {
payload.issues.push({
expected: origin,
format: def.format,
code: "invalid_type",
continue: false,
input,
inst,
});
return;
}
if (!Number.isSafeInteger(input)) {
if (input > 0)
payload.issues.push({
input,
code: "too_big",
maximum: Number.MAX_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
else
payload.issues.push({
input,
code: "too_small",
minimum: Number.MIN_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
return;
}
}
if (input < minimum)
payload.issues.push({
origin: "number",
input,
code: "too_small",
minimum,
inclusive: true,
inst,
continue: !def.abort,
});
if (input > maximum)
payload.issues.push({
origin: "number",
input,
code: "too_big",
maximum,
inclusive: true,
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 $ZodCheckLengthEquals = $constructor(
"$ZodCheckLengthEquals",
(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;
const length =
typeof input === "string" &&
units >= def.length &&
units <= def.length * 2
? codePointLength(input)
: units;
if (length === def.length) return;
const origin = getLengthableOrigin(input);
const tooBig = length > def.length;
payload.issues.push({
origin,
...(tooBig
? {
code: "too_big",
maximum: def.length,
}
: {
code: "too_small",
minimum: def.length,
}),
inclusive: true,
exact: true,
input: payload.value,
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 $ZodCheckRegex = $constructor(
"$ZodCheckRegex",
(inst, def) => {
$ZodCheckStringFormat.init(inst, def);
inst._zod.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "regex",
input: payload.value,
pattern: def.pattern.toString(),
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckLowerCase = $constructor(
"$ZodCheckLowerCase",
(inst, def) => {
def.pattern ?? (def.pattern = lowercase);
$ZodCheckStringFormat.init(inst, def);
},
);
const $ZodCheckUpperCase = $constructor(
"$ZodCheckUpperCase",
(inst, def) => {
def.pattern ?? (def.pattern = uppercase);
$ZodCheckStringFormat.init(inst, def);
},
);
const $ZodCheckIncludes = $constructor(
"$ZodCheckIncludes",
(inst, def) => {
$ZodCheck.init(inst, def);
const escapedRegex = escapeRegex(def.includes);
def.pattern = new RegExp(
typeof def.position === "number"
? `^.{${def.position},}${escapedRegex}`
: escapedRegex,
);
inst._zod.check = (payload) => {
if (
payload.value.includes(def.includes, def.position)
)
return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "includes",
includes: def.includes,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStartsWith = $constructor(
"$ZodCheckStartsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(
`^${escapeRegex(def.prefix)}.*`,
);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.startsWith(def.prefix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "starts_with",
prefix: def.prefix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckEndsWith = $constructor(
"$ZodCheckEndsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(
`.*${escapeRegex(def.suffix)}$`,
);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.endsWith(def.suffix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "ends_with",
suffix: def.suffix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckOverwrite = $constructor(
"$ZodCheckOverwrite",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
payload.value = def.tx(payload.value);
};
},
);
var Doc = class {
constructor(args = [], closed = {}) {
this.content = [];
this.indent = 0;
this.args = args;
this.closed = closed;
}
indented(fn) {
this.indent += 1;
try {
fn(this);
} finally {
this.indent -= 1;
}
}
write(arg) {
if (typeof arg === "function") {
arg(this, { execution: "sync" });
arg(this, { execution: "async" });
return;
}
const lines = arg.split("\n").filter((x) => x);
const minIndent = Math.min(
...lines.map((x) => x.length - x.trimStart().length),
);
const dedented = lines
.map((x) => x.slice(minIndent))
.map((x) => " ".repeat(this.indent * 2) + x);
for (const line of dedented) this.content.push(line);
}
compile() {
const F = Function;
const content = this?.content ?? [``];
return new F(
...Object.keys(this.closed),
`return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`,
)(...Object.values(this.closed));
}
};
const version = {
major: 4,
minor: 6,
patch: 5,
};
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);
},
);
const $ZodGUID = $constructor(
"$ZodGUID",
(inst, def) => {
def.pattern ?? (def.pattern = guid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodUUID = $constructor(
"$ZodUUID",
(inst, def) => {
if (def.version) {
const v = {
v1: 1,
v2: 2,
v3: 3,
v4: 4,
v5: 5,
v6: 6,
v7: 7,
v8: 8,
}[def.version];
if (v === void 0)
throw new Error(
`Invalid UUID version: "${def.version}"`,
);
def.pattern ?? (def.pattern = uuid(v));
} else def.pattern ?? (def.pattern = uuid());
$ZodStringFormat.init(inst, def);
},
);
const $ZodEmail = $constructor(
"$ZodEmail",
(inst, def) => {
def.pattern ?? (def.pattern = email);
$ZodStringFormat.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 $ZodEmoji = $constructor(
"$ZodEmoji",
(inst, def) => {
def.pattern ?? (def.pattern = emoji());
$ZodStringFormat.init(inst, def);
},
);
const $ZodNanoID = $constructor(
"$ZodNanoID",
(inst, def) => {
if (
def.length !== void 0 &&
(!Number.isInteger(def.length) || def.length < 1)
)
throw new Error(
`Invalid nanoid length: ${def.length}`,
);
def.pattern ??
(def.pattern =
def.length === void 0
? nanoid
: nanoidOfLength(def.length));
$ZodStringFormat.init(inst, def);
},
);
const $ZodCUID = $constructor(
"$ZodCUID",
(inst, def) => {
def.pattern ?? (def.pattern = cuid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodCUID2 = $constructor(
"$ZodCUID2",
(inst, def) => {
def.pattern ?? (def.pattern = cuid2);
$ZodStringFormat.init(inst, def);
},
);
const $ZodULID = $constructor(
"$ZodULID",
(inst, def) => {
def.pattern ?? (def.pattern = ulid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodXID = $constructor(
"$ZodXID",
(inst, def) => {
def.pattern ?? (def.pattern = xid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodKSUID = $constructor(
"$ZodKSUID",
(inst, def) => {
def.pattern ?? (def.pattern = ksuid);
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODateTime = $constructor(
"$ZodISODateTime",
(inst, def) => {
def.pattern ?? (def.pattern = datetime(def));
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODate = $constructor(
"$ZodISODate",
(inst, def) => {
def.pattern ?? (def.pattern = date$1);
$ZodStringFormat.init(inst, def);
},
);
const $ZodISOTime = $constructor(
"$ZodISOTime",
(inst, def) => {
def.pattern ?? (def.pattern = time(def));
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODuration = $constructor(
"$ZodISODuration",
(inst, def) => {
def.pattern ?? (def.pattern = duration);
$ZodStringFormat.init(inst, def);
},
);
const $ZodIPv4 = $constructor(
"$ZodIPv4",
(inst, def) => {
def.pattern ?? (def.pattern = ipv4);
$ZodStringFormat.init(inst, def);
},
);
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
function isValidIPv6(value) {
if (!ipv6Alphabet.test(value)) return false;
return canParseURL(`http://[${value}]`);
}
const $ZodIPv6 = $constructor(
"$ZodIPv6",
(inst, def) => {
def.pattern ?? (def.pattern = ipv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidIPv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "ipv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCIDRv4 = $constructor(
"$ZodCIDRv4",
(inst, def) => {
def.pattern ?? (def.pattern = cidrv4);
$ZodStringFormat.init(inst, def);
},
);
function isValidCIDRv6(value) {
const parts = value.split("/");
if (parts.length !== 2) return false;
const [address, prefix] = parts;
if (!prefix) return false;
const prefixNum = Number(prefix);
if (`${prefixNum}` !== prefix) return false;
if (prefixNum < 0 || prefixNum > 128) return false;
return isValidIPv6(address);
}
const $ZodCIDRv6 = $constructor(
"$ZodCIDRv6",
(inst, def) => {
def.pattern ?? (def.pattern = cidrv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidCIDRv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "cidrv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
function isValidBase64(data) {
if (data === "") return true;
if (/\s/.test(data)) return false;
if (data.length % 4 !== 0) return false;
try {
atob(data);
return true;
} catch {
return false;
}
}
const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
const $ZodBase64 = $constructor(
"$ZodBase64",
(inst, def) => {
def.pattern ?? (def.pattern = base64Charset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const base64urlCharset = /^[A-Za-z0-9_-]*$/;
function isValidBase64URL(data) {
if (!base64urlCharset.test(data)) return false;
const base64 = data.replace(/[-_]/g, (c) =>
c === "-" ? "+" : "/",
);
return isValidBase64(
base64.padEnd(Math.ceil(base64.length / 4) * 4, "="),
);
}
const $ZodBase64URL = $constructor(
"$ZodBase64URL",
(inst, def) => {
def.pattern ?? (def.pattern = base64urlCharset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64URL(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64url",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodE164 = $constructor(
"$ZodE164",
(inst, def) => {
def.pattern ?? (def.pattern = e164);
$ZodStringFormat.init(inst, def);
},
);
function isValidJWT(token, algorithm = null) {
try {
const tokensParts = token.split(".");
if (tokensParts.length !== 3) return false;
const [header] = tokensParts;
if (!header) return false;
const parsedHeader = JSON.parse(atob(header));
if (
"typ" in parsedHeader &&
parsedHeader?.typ !== "JWT"
)
return false;
if (!parsedHeader.alg) return false;
if (
algorithm &&
(!("alg" in parsedHeader) ||
parsedHeader.alg !== algorithm)
)
return false;
return true;
} catch {
return false;
}
}
const $ZodJWT = $constructor(
"$ZodJWT",
(inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidJWT(payload.value, def.alg)) return;
payload.issues.push({
code: "invalid_format",
format: "jwt",
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 $ZodNumberFormat = $constructor(
"$ZodNumberFormat",
(inst, def) => {
$ZodCheckNumberFormat.init(inst, def);
$ZodNumber.init(inst, def);
},
);
const $ZodUnknown = $constructor(
"$ZodUnknown",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload) => payload;
},
);
const $ZodNever = $constructor(
"$ZodNever",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
payload.issues.push({
expected: "never",
code: "invalid_type",
input: payload.value,
inst,
});
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 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;
};
},
);
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$2 = 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$2(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 $ZodObjectJIT = $constructor(
"$ZodObjectJIT",
(inst, def) => {
$ZodObject.init(inst, def);
const superParse = inst._zod.parse;
const _normalized = cached(() => normalizeDef(def));
const memo = globalConfig.memoizer;
const generateFastpass = (shape) => {
const normalized = _normalized.value;
const syms = normalized.symbolKeys;
const doc = new Doc(["payload", "ctx"], {
shape,
inst,
memo,
syms,
});
const parseStr = (k) =>
`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
const prefixStr = (id, k) => `
let ${id}_ab = false;
for (let i = 0; i < ${id}.issues.length; i++) {
const iss = ${id}.issues[i];
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
payload.issues.push(iss);
if (iss.continue !== true) ${id}_ab = true;
}
if (${id}_ab && ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}`;
doc.write(`const input = payload.value;`);
const ids = Object.create(null);
let counter = 0;
for (const key of normalized.allKeys)
ids[key] = `key_${counter++}`;
doc.write(
memo
? `const newResult = memo.alloc(inst, payload, {}, ctx);`
: `const newResult = {};`,
);
for (const key of normalized.allKeys) {
if (key === "__proto__") continue;
const id = ids[key];
const k =
typeof key === "symbol"
? `syms[${syms.indexOf(key)}]`
: esc(key);
const isPresent = `${k} in input`;
const schema = shape[key];
const optin = schema?._zod?.optin;
const isOptionalIn = optin !== void 0;
const isOptionalOut =
schema?._zod?.optout === "optional";
doc.write(`const ${id} = ${parseStr(k)};`);
if (isOptionalIn && isOptionalOut) {
const assign =
optin === "optional"
? `${id}_present`
: `${id}.value !== undefined || ${id}_present`;
doc.write(`
const ${id}_present = ${isPresent};
if (!${id}.issues.length || ${id}_present) {
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (${assign}) {
newResult[${k}] = ${id}.value;
}
}
`);
} else if (!isOptionalIn)
doc.write(`
const ${id}_present = ${isPresent};
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (!${id}_present && !${id}.issues.length) {
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [${k}]
});
if (ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}
}
if (${id}_present) {
newResult[${k}] = ${id}.value;
}
`);
else {
doc.write(`
if (${id}.issues.length) {${prefixStr(id, k)}
}
`);
if (optin === "defaulted")
doc.write(`newResult[${k}] = ${id}.value;`);
else
doc.write(`
if (${id}.value !== undefined || ${isPresent}) {
newResult[${k}] = ${id}.value;
}
`);
}
}
doc.write(`payload.value = newResult;`);
doc.write(`return payload;`);
return doc.compile();
};
let fastpass;
const isObject$1 = isObject;
const jit = !globalConfig.jitless;
const fastEnabled = jit && allowsEval.value;
const catchall = def.catchall;
let value;
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;
}
if (
jit &&
fastEnabled &&
ctx?.async === false &&
ctx.jitless !== true
) {
if (!fastpass)
fastpass = generateFastpass(def.shape);
payload = fastpass(payload, ctx);
if (!catchall) return payload;
return handleCatchall(
[],
input,
payload,
ctx,
value,
inst,
ctx?.abortEarly === true,
);
}
return superParse(payload, ctx);
};
},
);
function handleUnionResults(results, final, inst, ctx) {
for (const result of results)
if (result.issues.length === 0) {
final.value = result.value;
return final;
}
const nonaborted = results.filter((r) => !aborted(r));
if (nonaborted.length === 1) {
final.value = nonaborted[0].value;
return nonaborted[0];
}
final.issues.push({
code: "invalid_union",
input: final.value,
inst,
errors: results.map((result) =>
result.issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
),
});
return final;
}
const $ZodUnion = $constructor(
"$ZodUnion",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.options.some(
(o) => o._zod.optin === "defaulted",
)
? "defaulted"
: zod.def.options.some(
(o) => o._zod.optin !== void 0,
)
? "optional"
: void 0,
);
defineLazyInternal(inst, "optout", (zod) =>
zod.def.options.some(
(o) => o._zod.optout === "optional",
)
? "optional"
: void 0,
);
defineLazyInternal(inst, "values", (zod) => {
if (zod.def.options.every((o) => o._zod.values))
return new Set(
zod.def.options.flatMap((option) =>
Array.from(option._zod.values),
),
);
});
defineLazyInternal(inst, "pattern", (zod) => {
if (zod.def.options.every((o) => o._zod.pattern)) {
const patterns = zod.def.options.map(
(o) => o._zod.pattern,
);
return new RegExp(
`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`,
);
}
});
const first =
def.options.length === 1
? def.options[0]._zod.run
: null;
inst._zod.parse = (payload, ctx) => {
if (first) return first(payload, ctx);
let async = false;
const results = [];
for (const option of def.options) {
const result = option._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise) {
results.push(result);
async = true;
} else {
if (result.issues.length === 0) return result;
results.push(result);
}
}
if (!async)
return handleUnionResults(
results,
payload,
inst,
ctx,
);
return Promise.all(results).then((results) => {
return handleUnionResults(
results,
payload,
inst,
ctx,
);
});
};
},
);
const $ZodIntersection = $constructor(
"$ZodIntersection",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
const left = def.left._zod.run(
{
value: input,
issues: [],
},
ctx,
);
const right = def.right._zod.run(
{
value: input,
issues: [],
},
ctx,
);
if (
left instanceof Promise ||
right instanceof Promise
)
return Promise.all([left, right]).then(
([left, right]) => {
return handleIntersectionResults(
payload,
left,
right,
);
},
);
return handleIntersectionResults(
payload,
left,
right,
);
};
},
);
function mergeValues(a, b) {
if (a === b)
return {
valid: true,
data: a,
};
if (a instanceof Date && b instanceof Date && +a === +b)
return {
valid: true,
data: a,
};
if (isPlainObject(a) && isPlainObject(b)) {
const bKeys = Object.keys(b);
const sharedKeys = Object.keys(a).filter(
(key) => bKeys.indexOf(key) !== -1,
);
const newObj = {
...a,
...b,
};
if (
Object.prototype.hasOwnProperty.call(
newObj,
"__proto__",
)
)
delete newObj.__proto__;
for (const key of sharedKeys) {
if (key === "__proto__") continue;
const sharedValue = mergeValues(a[key], b[key]);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [
key,
...sharedValue.mergeErrorPath,
],
};
newObj[key] = sharedValue.data;
}
return {
valid: true,
data: newObj,
};
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length)
return {
valid: false,
mergeErrorPath: [],
};
const newArray = [];
for (let index = 0; index < a.length; index++) {
const itemA = a[index];
const itemB = b[index];
const sharedValue = mergeValues(itemA, itemB);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [
index,
...sharedValue.mergeErrorPath,
],
};
newArray.push(sharedValue.data);
}
return {
valid: true,
data: newArray,
};
}
return {
valid: false,
mergeErrorPath: [],
};
}
function handleIntersectionResults(result, left, right) {
const unrecKeys = new Map();
let unrecIssue;
const keyIssues = new Map();
const collect = (iss, side) => {
let keys;
if (
iss.code === "unrecognized_keys" &&
!iss.path?.length
) {
unrecIssue ?? (unrecIssue = iss);
keys = iss.keys;
} else if (
iss.code === "invalid_key" &&
iss.origin === "record" &&
iss.path?.length === 1
) {
const k = String(iss.path[0]);
if (!keyIssues.has(k)) keyIssues.set(k, iss);
keys = [k];
} else return false;
for (const k of keys) {
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
unrecKeys.get(k)[side] = true;
}
return true;
};
for (const iss of left.issues)
if (!collect(iss, "l")) result.issues.push(iss);
for (const iss of right.issues)
if (!collect(iss, "r")) result.issues.push(iss);
const bothKeys = [...unrecKeys]
.filter(([, f]) => f.l && f.r)
.map(([k]) => k);
if (bothKeys.length) {
const aggregated = unrecIssue
? bothKeys.filter((k) => unrecIssue.keys.includes(k))
: [];
if (aggregated.length)
result.issues.push({
...unrecIssue,
keys: aggregated,
});
for (const k of bothKeys)
if (!aggregated.includes(k) && keyIssues.has(k))
result.issues.push(keyIssues.get(k));
}
const merged = mergeValues(left.value, right.value);
if (!merged.valid) {
if (aborted(result)) return result;
throw new Error(
`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`,
);
}
result.value = merged.data;
return result;
}
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 $ZodTransform = $constructor(
"$ZodTransform",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "optional";
globalConfig.memoizer?.guard(inst);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
throw new $ZodEncodeError(inst.constructor.name);
const _out = def.transform(payload.value, payload);
if (ctx.async)
return (
_out instanceof Promise
? _out
: Promise.resolve(_out)
).then((output) => {
payload.value = output;
return payload;
});
if (_out instanceof Promise)
throw new $ZodAsyncError();
payload.value = _out;
return payload;
};
},
);
function handleOptionalResult(payload, result) {
payload.value = result.issues.length
? void 0
: result.value;
return payload;
}
const $ZodOptional = $constructor(
"$ZodOptional",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted"
? "defaulted"
: "optional",
);
inst._zod.optout = "optional";
defineLazyInternal(inst, "values", (zod) => {
const values = zod.def.innerType._zod.values;
return values
? new Set([...values, void 0])
: void 0;
});
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern
? new RegExp(`^(${cleanRegex(pattern.source)})?$`)
: void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === void 0) {
if (def.innerType._zod.optin !== "defaulted")
return payload;
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleOptionalResult(payload, result),
);
return handleOptionalResult(payload, result);
}
return def.innerType._zod.run(payload, ctx);
};
},
);
const $ZodExactOptional = $constructor(
"$ZodExactOptional",
(inst, def) => {
$ZodOptional.init(inst, def);
defineLazyInternal(
inst,
"values",
(zod) => zod.def.innerType._zod.values,
);
defineLazyInternal(
inst,
"pattern",
(zod) => zod.def.innerType._zod.pattern,
);
inst._zod.parse = (payload, ctx) => {
return def.innerType._zod.run(payload, ctx);
};
},
);
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);
};
},
);
const $ZodDefault = $constructor(
"$ZodDefault",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(
inst,
"values",
(zod) => zod.def.innerType._zod.values,
);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0) {
payload.value = def.defaultValue;
return payload;
}
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((result) =>
handleDefaultResult(result, def),
);
return handleDefaultResult(result, def);
};
},
);
function handleDefaultResult(payload, def) {
if (payload.value === void 0)
payload.value = def.defaultValue;
return payload;
}
const $ZodPrefault = $constructor(
"$ZodPrefault",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(
inst,
"values",
(zod) => zod.def.innerType._zod.values,
);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0)
payload.value = def.defaultValue;
return def.innerType._zod.run(payload, ctx);
};
},
);
const $ZodNonOptional = $constructor(
"$ZodNonOptional",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "values", (zod) => {
const v = zod.def.innerType._zod.values;
return v
? new Set([...v].filter((x) => x !== void 0))
: void 0;
});
inst._zod.parse = (payload, ctx) => {
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((result) =>
handleNonOptionalResult(result, inst),
);
return handleNonOptionalResult(result, inst);
};
},
);
function handleNonOptionalResult(payload, inst) {
if (!payload.issues.length && payload.value === void 0)
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: payload.value,
inst,
});
return payload;
}
function handleCatchResult(payload, result, def, ctx) {
if (!result.issues.length) {
payload.value = result.value;
if (result.memo) payload.memo = true;
return payload;
}
payload.value = def.catchValue({
...result,
value: payload.value,
error: {
issues: result.issues.map((iss) =>
finalizeIssue(iss, ctx, config()),
),
},
input: payload.value,
});
return payload;
}
const $ZodCatch = $constructor(
"$ZodCatch",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted"
? "defaulted"
: "optional",
);
defineLazyInternal(
inst,
"optout",
(zod) => zod.def.innerType._zod.optout,
);
defineLazyInternal(
inst,
"values",
(zod) => zod.def.innerType._zod.values,
);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleCatchResult(payload, result, def, ctx),
);
return handleCatchResult(payload, result, def, ctx);
};
},
);
const $ZodPipe = $constructor(
"$ZodPipe",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"values",
(zod) => zod.def.in._zod.values,
);
defineLazyInternal(
inst,
"optin",
(zod) => zod.def.in._zod.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) => zod.def.out._zod.optout,
);
defineLazyInternal(
inst,
"propValues",
(zod) => zod.def.in._zod.propValues,
);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
const right = def.out._zod.run(payload, ctx);
if (right instanceof Promise)
return right.then((right) =>
handlePipeResult(right, def.in, ctx),
);
return handlePipeResult(right, def.in, ctx);
}
const left = def.in._zod.run(payload, ctx);
if (left instanceof Promise)
return left.then((left) =>
handlePipeResult(left, def.out, ctx),
);
return handlePipeResult(left, def.out, ctx);
};
},
);
function handlePipeResult(left, next, ctx) {
if (
left.issues.some(
(iss) => iss.code !== "unrecognized_keys",
)
) {
left.aborted = true;
return left;
}
return next._zod.run(
{
value: left.value,
issues: left.issues,
},
ctx,
);
}
const $ZodReadonly = $constructor(
"$ZodReadonly",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"propValues",
(zod) => zod.def.innerType._zod.propValues,
);
defineLazyInternal(
inst,
"values",
(zod) => zod.def.innerType._zod.values,
);
defineLazyInternal(
inst,
"optin",
(zod) => zod.def.innerType?._zod?.optin,
);
defineLazyInternal(
inst,
"optout",
(zod) => zod.def.innerType?._zod?.optout,
);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then(handleReadonlyResult);
return handleReadonlyResult(result);
};
},
);
function handleReadonlyResult(payload) {
if (!payload.memo)
payload.value = Object.freeze(payload.value);
return payload;
}
const $ZodCustom = $constructor(
"$ZodCustom",
(inst, def) => {
$ZodCheck.init(inst, def);
$ZodType.init(inst, def);
inst._zod.parse = (payload, _) => {
return payload;
};
inst._zod.check = (payload) => {
const input = payload.value;
const r = def.fn(input);
if (r instanceof Promise)
return r.then((r) =>
handleRefineResult(r, payload, input, inst),
);
handleRefineResult(r, payload, input, inst);
};
},
);
function handleRefineResult(result, payload, input, inst) {
if (!result) {
const _iss = {
code: "custom",
input,
inst,
path: [...(inst._zod.def.path ?? [])],
continue: !inst._zod.def.abort,
};
if (inst._zod.def.params)
_iss.params = inst._zod.def.params;
payload.issues.push(issue(_iss));
}
}
var $ZodCyclicError = class extends Error {
constructor() {
super(
`Cannot parse a reference cycle that closes through a transform`,
);
this.name = "ZodCyclicError";
}
};
const STATE = "~memo";
const NO_ISSUES = [];
function isRef(value) {
return value !== null && typeof value === "object";
}
function cloneIssues(issues) {
return issues.map((iss) =>
iss.path
? {
...iss,
path: iss.path.slice(),
}
: { ...iss },
);
}
const recursive = new WeakMap();
const NONE = 0;
const ASSUMED = 1;
const PROVEN = 2;
function isRecursive(inst, stack, resolve) {
const cached = recursive.get(inst);
if (cached !== void 0) return cached ? PROVEN : NONE;
if (stack.has(inst)) return PROVEN;
stack.add(inst);
let result = NONE;
const check = (child) => {
if (result !== PROVEN && child?._zod) {
const answer = isRecursive(child, stack, resolve);
if (answer > result) result = answer;
}
};
const shape = (sh, spread) => {
let answer = NONE;
for (const key of Reflect.ownKeys(sh)) {
const desc = Object.getOwnPropertyDescriptor(sh, key);
if (spread && !desc.enumerable) continue;
const child = desc.get
? ASSUMED
: desc.value?._zod
? isRecursive(desc.value, stack, resolve)
: NONE;
if (child > answer) answer = child;
}
return answer;
};
const merge = (answer) => {
if (answer > result) result = answer;
};
const def = inst._zod.def;
switch (def.type) {
case "object": {
const raw = rawShape(def);
merge(raw ? shape(raw, true) : ASSUMED);
check(def.catchall);
break;
}
case "array":
check(def.element);
break;
case "tuple":
for (const el of def.items) check(el);
check(def.rest);
break;
case "record":
case "map":
check(def.keyType);
check(def.valueType);
break;
case "set":
check(def.valueType);
break;
case "union":
for (const el of def.options) check(el);
break;
case "intersection":
check(def.left);
check(def.right);
break;
case "optional":
case "nullable":
case "default":
case "prefault":
case "catch":
case "readonly":
case "nonoptional":
case "promise":
case "success":
check(def.innerType);
break;
case "pipe":
check(def.in);
check(def.out);
break;
case "function":
check(def.input);
check(def.output);
break;
case "lazy": {
const inner =
def._cachedInner ??
(resolve ? inst._zod.innerType : void 0);
merge(
inner ? isRecursive(inner, stack, false) : ASSUMED,
);
break;
}
case "template_literal":
case "string":
case "number":
case "int":
case "boolean":
case "bigint":
case "symbol":
case "undefined":
case "null":
case "void":
case "never":
case "any":
case "unknown":
case "date":
case "nan":
case "enum":
case "literal":
case "file":
case "transform":
case "custom":
break;
default:
for (const key in def) {
const desc = Object.getOwnPropertyDescriptor(
def,
key,
);
if (!desc || desc.get) continue;
const value = desc.value;
if (!value || typeof value !== "object") continue;
if (value._zod) check(value);
else if (Array.isArray(value))
for (const el of value) check(el);
}
}
stack.delete(inst);
return settle(inst, result);
}
function settle(inst, answer) {
if (answer !== ASSUMED)
recursive.set(inst, answer === PROVEN);
return answer;
}
function bucketFor(state, inst) {
let bucket = state.buckets.get(inst);
if (!bucket) {
bucket = new WeakMap();
state.buckets.set(inst, bucket);
}
return bucket;
}
let handoff;
const open = [];
const memo = {
alloc(_inst, payload, empty) {
const bucket = handoff;
if (!bucket) return empty;
handoff = void 0;
const entry = {
value: empty,
issues: null,
};
bucket.set(payload.value, entry);
open.push(entry);
return empty;
},
guard(inst) {
var _a;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (
ctx.direction !== "backward" &&
isBackEdge(ctx, payload.value)
)
throw new $ZodCyclicError();
return base(payload, ctx);
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
attach(inst) {
var _a;
let isRecursiveInst;
let rechecked = false;
let lastCtx;
let lastBucket;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (isRecursiveInst === void 0) {
const walked = isRecursive(
inst,
new Set(),
false,
);
if (walked === NONE) {
inst._zod.parse = base;
if (inst._zod.run === wrapped)
inst._zod.run = base;
return base(payload, ctx);
}
if (walked === PROVEN || rechecked)
isRecursiveInst = true;
else rechecked = true;
}
const input = payload.value;
if (!isRef(input)) return base(payload, ctx);
let state = ctx[STATE];
if (!state) {
state = {
buckets: new WeakMap(),
backEdges: void 0,
};
ctx[STATE] = state;
}
let bucket;
if (lastCtx === ctx) bucket = lastBucket;
else {
bucket = bucketFor(state, inst);
lastCtx = ctx;
lastBucket = bucket;
}
const hit = bucket.get(input);
if (hit) {
payload.value = hit.value;
if (hit.issues) {
if (hit.issues.length)
payload.issues.push(
...cloneIssues(hit.issues),
);
} else {
payload.memo = true;
state.backEdges ??
(state.backEdges =
new WeakSet());
state.backEdges.add(hit.value);
}
return payload;
}
handoff = bucket;
const depth = open.length;
const result = base(payload, ctx);
handoff = void 0;
const entry =
open.length > depth ? open.pop() : void 0;
if (result instanceof Promise)
return result.then((r) => {
if (entry)
entry.issues = r.issues.length
? cloneIssues(r.issues)
: NO_ISSUES;
return r;
});
if (entry)
entry.issues = result.issues.length
? cloneIssues(result.issues)
: NO_ISSUES;
return result;
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
};
function memoizer() {
return memo;
}
function isBackEdge(ctx, value) {
const backEdges = ctx[STATE]?.backEdges;
return (
backEdges !== void 0 &&
isRef(value) &&
backEdges.has(value)
);
}
const error = () => {
const Sizable = {
string: {
unit: "characters",
verb: "to have",
},
file: {
unit: "bytes",
verb: "to have",
},
array: {
unit: "items",
verb: "to have",
},
set: {
unit: "items",
verb: "to have",
},
map: {
unit: "entries",
verb: "to have",
},
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const FormatDictionary = {
regex: "input",
email: "email address",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO datetime",
date: "ISO date",
time: "ISO time",
duration: "ISO duration",
ipv4: "IPv4 address",
ipv6: "IPv6 address",
mac: "MAC address",
cidrv4: "IPv4 range",
cidrv6: "IPv6 range",
base64: "base64-encoded string",
base64url: "base64url-encoded string",
json_string: "JSON string",
e164: "E.164 number",
currency_code: "currency code",
credit_card: "credit card number",
iban: "IBAN",
jwt: "JWT",
template_literal: "input",
};
const TypeDictionary = { nan: "NaN" };
function getTypeName(type, input) {
if (
type === "number" &&
typeof input === "number" &&
!Number.isFinite(input)
)
return String(input);
return TypeDictionary[type] ?? type;
}
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `Invalid input: expected ${getTypeName(issue.expected)}, received ${getTypeName(parsedType(issue.input), issue.input)}`;
case "invalid_value":
if (issue.values.length === 1)
return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.exact
? "exactly "
: issue.inclusive
? "<="
: "<";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.exact
? "exactly "
: issue.inclusive
? ">="
: ">";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
if (_issue.format === "starts_with")
return `Invalid string: must start with "${_issue.prefix}"`;
if (_issue.format === "ends_with")
return `Invalid string: must end with "${_issue.suffix}"`;
if (_issue.format === "includes")
return `Invalid string: must include "${_issue.includes}"`;
if (_issue.format === "regex")
return `Invalid string: must match pattern ${_issue.pattern}`;
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `Invalid number: must be a multiple of ${issue.divisor}`;
case "unrecognized_keys":
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Invalid key in ${issue.origin}`;
case "invalid_union":
if (
issue.options &&
Array.isArray(issue.options) &&
issue.options.length > 0
)
return `Invalid discriminator value. Expected ${issue.options.map((o) => `'${o}'`).join(" | ")}`;
if (issue.inclusive === false)
return "Invalid input: more than one option matched";
return "Invalid input";
case "invalid_element":
return `Invalid value in ${issue.origin}`;
default:
return `Invalid input`;
}
};
};
function en_default() {
return { localeError: error() };
}
var _a;
var $ZodRegistry = class {
constructor() {
this._map = new WeakMap();
this._idmap = new Map();
}
add(schema, ..._meta) {
const meta = _meta[0];
this._map.set(schema, meta);
if (meta && typeof meta === "object" && "id" in meta)
this._idmap.set(meta.id, schema);
return this;
}
clear() {
this._map = new WeakMap();
this._idmap = new Map();
return this;
}
remove(schema) {
const meta = this._map.get(schema);
if (meta && typeof meta === "object" && "id" in meta)
this._idmap.delete(meta.id);
this._map.delete(schema);
return this;
}
get(schema) {
const p = schema._zod.parent;
if (p) {
const pm = { ...(this.get(p) ?? {}) };
delete pm.id;
const f = {
...pm,
...this._map.get(schema),
};
return Object.keys(f).length ? f : void 0;
}
return this._map.get(schema);
}
has(schema) {
return this._map.has(schema);
}
};
function registry() {
return new $ZodRegistry();
}
(_a = globalThis).__zod_globalRegistry ??
(_a.__zod_globalRegistry = registry());
const globalRegistry = globalThis.__zod_globalRegistry;
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 _email(Class, params) {
return new Class({
type: "string",
format: "email",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _guid(Class, params) {
return new Class({
type: "string",
format: "guid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuid(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuidv4(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v4",
...normalizeParams(params),
});
}
function _uuidv6(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v6",
...normalizeParams(params),
});
}
function _uuidv7(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v7",
...normalizeParams(params),
});
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _emoji(Class, params) {
return new Class({
type: "string",
format: "emoji",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _nanoid(Class, params) {
return new Class({
type: "string",
format: "nanoid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid(Class, params) {
return new Class({
type: "string",
format: "cuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid2(Class, params) {
return new Class({
type: "string",
format: "cuid2",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ulid(Class, params) {
return new Class({
type: "string",
format: "ulid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _xid(Class, params) {
return new Class({
type: "string",
format: "xid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ksuid(Class, params) {
return new Class({
type: "string",
format: "ksuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv4(Class, params) {
return new Class({
type: "string",
format: "ipv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv6(Class, params) {
return new Class({
type: "string",
format: "ipv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv4(Class, params) {
return new Class({
type: "string",
format: "cidrv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv6(Class, params) {
return new Class({
type: "string",
format: "cidrv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64(Class, params) {
return new Class({
type: "string",
format: "base64",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64url(Class, params) {
return new Class({
type: "string",
format: "base64url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _e164(Class, params) {
return new Class({
type: "string",
format: "e164",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _jwt(Class, params) {
return new Class({
type: "string",
format: "jwt",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _isoDateTime(Class, params) {
return new Class({
type: "string",
format: "datetime",
check: "string_format",
offset: false,
local: false,
precision: null,
...normalizeParams(params),
});
}
function _isoDate(Class, params) {
return new Class({
type: "string",
format: "date",
check: "string_format",
...normalizeParams(params),
});
}
function _isoTime(Class, params) {
return new Class({
type: "string",
format: "time",
check: "string_format",
precision: null,
...normalizeParams(params),
});
}
function _isoDuration(Class, params) {
return new Class({
type: "string",
format: "duration",
check: "string_format",
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _int(Class, params) {
return new Class({
type: "number",
check: "number_format",
abort: false,
format: "safeint",
...normalizeParams(params),
});
}
function _unknown(Class) {
return new Class({ type: "unknown" });
}
function _never(Class, params) {
return new Class({
type: "never",
...normalizeParams(params),
});
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lt(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gt(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _multipleOf(value, params) {
return new $ZodCheckMultipleOf({
check: "multiple_of",
...normalizeParams(params),
value,
});
}
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,
});
}
function _length(length, params) {
return new $ZodCheckLengthEquals({
check: "length_equals",
...normalizeParams(params),
length,
});
}
function _regex(pattern, params) {
return new $ZodCheckRegex({
check: "string_format",
format: "regex",
...normalizeParams(params),
pattern,
});
}
function _lowercase(params) {
return new $ZodCheckLowerCase({
check: "string_format",
format: "lowercase",
...normalizeParams(params),
});
}
function _uppercase(params) {
return new $ZodCheckUpperCase({
check: "string_format",
format: "uppercase",
...normalizeParams(params),
});
}
function _includes(includes, params) {
return new $ZodCheckIncludes({
check: "string_format",
format: "includes",
...normalizeParams(params),
includes,
});
}
function _startsWith(prefix, params) {
return new $ZodCheckStartsWith({
check: "string_format",
format: "starts_with",
...normalizeParams(params),
prefix,
});
}
function _endsWith(suffix, params) {
return new $ZodCheckEndsWith({
check: "string_format",
format: "ends_with",
...normalizeParams(params),
suffix,
});
}
function _overwrite(tx) {
return new $ZodCheckOverwrite({
check: "overwrite",
tx,
});
}
function _normalize(form) {
return _overwrite((input) =>
input.normalize(form),
);
}
function _trim() {
return _overwrite((input) =>
input.trim(),
);
}
function _toLowerCase() {
return _overwrite((input) =>
input.toLowerCase(),
);
}
function _toUpperCase() {
return _overwrite((input) =>
input.toUpperCase(),
);
}
function _slugify() {
return _overwrite((input) =>
slugify(input),
);
}
function _array(Class, element, params) {
return new Class({
type: "array",
element,
...normalizeParams(params),
});
}
function _refine(Class, fn, _params) {
return new Class({
type: "custom",
check: "custom",
fn,
...normalizeParams(_params),
});
}
function _superRefine(fn, params) {
const ch = _check((payload) => {
payload.addIssue = (issue$2) => {
if (typeof issue$2 === "string")
payload.issues.push(
issue(issue$2, payload.value, ch._zod.def),
);
else {
const _issue = issue$2;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue))
_issue.input = payload.value;
_issue.inst ?? (_issue.inst = ch);
_issue.continue ??
(_issue.continue = !ch._zod.def.abort);
payload.issues.push(issue(_issue));
}
};
return fn(payload.value, payload);
}, params);
return ch;
}
function _check(fn, params) {
const ch = new $ZodCheck({
check: "custom",
...normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
function assignProps(target, ...sources) {
for (const source of sources)
for (const key of Reflect.ownKeys(source))
if (
Object.prototype.propertyIsEnumerable.call(
source,
key,
)
)
assignProp(target, key, source[key]);
return target;
}
function initializeContext(params) {
let target = params?.target ?? "draft-2020-12";
if (target === "draft-4") target = "draft-04";
if (target === "draft-7") target = "draft-07";
return {
processors: params.processors ?? {},
metadataRegistry: params?.metadata ?? globalRegistry,
target,
unrepresentable: params?.unrepresentable ?? "throw",
override: params?.override ?? (() => {}),
io: params?.io ?? "output",
counter: 0,
seen: new Map(),
sharedDefsExtractedFor: void 0,
sharedEmitDoneFor: void 0,
cycles: params?.cycles ?? "ref",
reused: params?.reused ?? "inline",
intersections: [],
deferred: [],
external: params?.external ?? void 0,
};
}
function handleUnrepresentable(
schema,
ctx,
json,
params,
message,
) {
const result =
typeof ctx.unrepresentable === "function"
? ctx.unrepresentable({
zodSchema: schema,
path: params.path,
message,
})
: ctx.unrepresentable;
if (result === "any") return false;
if (result === void 0 || result === "throw")
throw new Error(message);
Object.assign(json, result);
return true;
}
function processSchema(
schema,
ctx,
_params = {
path: [],
schemaPath: [],
},
) {
var _a;
const def = schema._zod.def;
const seen = ctx.seen.get(schema);
if (seen) {
seen.count++;
if (_params.schemaPath.includes(schema))
seen.cycle = _params.path;
return seen.schema;
}
const result = {
schema: {},
count: 1,
cycle: void 0,
path: _params.path,
};
ctx.seen.set(schema, result);
ctx.sharedDefsExtractedFor = void 0;
ctx.sharedEmitDoneFor = void 0;
const overrideSchema = schema._zod.toJSONSchema?.();
if (overrideSchema) result.schema = overrideSchema;
else {
const params = {
..._params,
schemaPath: [..._params.schemaPath, schema],
path: _params.path,
};
if (schema._zod.processJSONSchema)
schema._zod.processJSONSchema(
ctx,
result.schema,
params,
);
else {
const _json = result.schema;
const processor = ctx.processors[def.type];
if (!processor)
throw new Error(
`[toJSONSchema]: Non-representable type encountered: ${def.type}`,
);
processor(schema, ctx, _json, params);
}
const parent = schema._zod.parent;
if (parent) {
if (!result.ref) result.ref = parent;
processSchema(parent, ctx, params);
ctx.seen.get(parent).isParent = true;
}
}
const meta = ctx.metadataRegistry.get(schema);
if (meta) assignProps(result.schema, meta);
if (ctx.io === "input" && isTransforming(schema)) {
delete result.schema.examples;
delete result.schema.default;
}
if (ctx.io === "input" && "_prefault" in result.schema)
(_a = result.schema).default ??
(_a.default = result.schema._prefault);
delete result.schema._prefault;
return ctx.seen.get(schema).schema;
}
function encodeJSONPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function extractDefs(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root)
throw new Error(
"Unprocessed schema. This is a bug in Zod.",
);
if (
ctx.external &&
ctx.sharedDefsExtractedFor === ctx.external
)
return;
const idToSchema = new Map();
for (const entry of ctx.seen.entries()) {
const id = ctx.metadataRegistry.get(entry[0])?.id;
if (id) {
const existing = idToSchema.get(id);
if (existing && existing !== entry[0])
throw new Error(
`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`,
);
idToSchema.set(id, entry[0]);
}
}
const makeURI = (entry) => {
const defsSegment =
ctx.target === "draft-2020-12"
? "$defs"
: "definitions";
if (ctx.external) {
const externalId = ctx.external.registry.get(
entry[0],
)?.id;
const uriGenerator = ctx.external.uri ?? ((id) => id);
if (externalId)
return { ref: uriGenerator(externalId) };
const id =
entry[1].defId ??
entry[1].schema.id ??
`schema${ctx.counter++}`;
entry[1].defId = id;
return {
defId: id,
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`,
};
}
const uriPrefix = `#`;
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
if (entry[1] === root && !entry[1].schema.id)
return { ref: uriPrefix };
const defId =
entry[1].schema.id ?? `__schema${ctx.counter++}`;
return {
defId,
ref: defUriPrefix + encodeJSONPointerSegment(defId),
};
};
const extractToDef = (entry) => {
if (entry[1].schema.$ref) return;
const seen = entry[1];
const { ref, defId } = makeURI(entry);
seen.def = { ...seen.schema };
if (defId) seen.defId = defId;
const schema = seen.schema;
for (const key in schema) delete schema[key];
schema.$ref = ref;
};
if (ctx.cycles === "throw")
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.cycle)
throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
}
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (schema === entry[0]) {
extractToDef(entry);
continue;
}
if (ctx.external) {
const ext = ctx.external.registry.get(entry[0])?.id;
if (schema !== entry[0] && ext) {
extractToDef(entry);
continue;
}
}
if (ctx.metadataRegistry.get(entry[0])?.id) {
extractToDef(entry);
continue;
}
if (seen.cycle) {
extractToDef(entry);
continue;
}
if (seen.count > 1) {
if (ctx.reused === "ref") extractToDef(entry);
}
}
if (ctx.external)
ctx.sharedDefsExtractedFor = ctx.external;
}
function compactTypeUnion(schema) {
const options = schema.anyOf;
if (
!Array.isArray(options) ||
options.length === 0 ||
schema.type !== void 0
)
return;
const types = [];
for (const option of options) {
if (!option || typeof option !== "object") return;
compactTypeUnion(option);
const keys = Object.keys(option);
if (keys.length !== 1 || keys[0] !== "type") return;
const type = option.type;
for (const member of Array.isArray(type)
? type
: [type]) {
if (typeof member !== "string") return;
if (!types.includes(member)) types.push(member);
}
}
delete schema.anyOf;
schema.type = types.length === 1 ? types[0] : types;
}
const FOLDABLE_KEYS = new Set([
"type",
"properties",
"required",
"additionalProperties",
]);
const UNION_KEYS = ["oneOf", "anyOf"];
function undeclaredConstraint(member) {
const extra = member.additionalProperties;
if (
extra === void 0 ||
extra === false ||
typeof extra !== "object" ||
extra === null
)
return null;
return Object.keys(extra).length ? extra : null;
}
function foldObjects(members) {
const objects = [];
for (const member of members) {
if (
typeof member !== "object" ||
member.type !== "object"
)
return null;
for (const key in member)
if (!FOLDABLE_KEYS.has(key)) return null;
objects.push(member);
}
const properties = {};
const required = new Set();
for (const object of objects) {
for (const key in object.properties) {
if (
Object.prototype.hasOwnProperty.call(
properties,
key,
)
)
continue;
const parts = [];
for (const other of objects) {
const part =
other.properties?.[key] ??
undeclaredConstraint(other);
if (part === null || part === void 0) continue;
if (
!parts.some(
(seen) =>
JSON.stringify(seen) === JSON.stringify(part),
)
)
parts.push(part);
}
assignProp(
properties,
key,
parts.length === 1
? parts[0]
: (foldObjects(parts) ?? { allOf: parts }),
);
}
for (const key of object.required ?? [])
required.add(key);
}
const folded = {
type: "object",
properties,
};
if (required.size) folded.required = [...required];
if (
objects.every(
(object) => object.additionalProperties === false,
)
)
folded.additionalProperties = false;
else {
const constraints = [];
for (const object of objects) {
const constraint = undeclaredConstraint(object);
if (
constraint &&
!constraints.some(
(seen) =>
JSON.stringify(seen) ===
JSON.stringify(constraint),
)
)
constraints.push(constraint);
}
if (constraints.length === 1)
folded.additionalProperties = constraints[0];
else if (constraints.length > 1)
folded.additionalProperties = { allOf: constraints };
}
return folded;
}
function foldIntersection(json) {
const allOf = json.allOf;
if (!Array.isArray(allOf) || allOf.length < 2) return;
for (const key of FOLDABLE_KEYS) if (key in json) return;
const unions = allOf.filter((m) =>
UNION_KEYS.some((k) => Array.isArray(m[k])),
);
let folded = null;
if (!unions.length) folded = foldObjects(allOf);
else {
const union = unions[0];
const keyword = UNION_KEYS.find((k) =>
Array.isArray(union[k]),
);
if (Object.keys(union).length !== 1) return;
const rest = allOf.filter((m) => m !== union);
const branches = union[keyword].map((branch) =>
foldObjects([...rest, branch]),
);
if (branches.some((b) => !b)) return;
folded = { [keyword]: branches };
}
if (!folded) return;
delete json.allOf;
assignProps(json, folded);
}
function finalize(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root)
throw new Error(
"Unprocessed schema. This is a bug in Zod.",
);
const flattenRef = (zodSchema) => {
const seen = ctx.seen.get(zodSchema);
if (seen.ref === null) return;
const schema = seen.def ?? seen.schema;
const _cached = { ...schema };
const ref = seen.ref;
seen.ref = null;
if (ref) {
flattenRef(ref);
const refSeen = ctx.seen.get(ref);
const refSchema = refSeen.schema;
if (
refSchema.$ref &&
(ctx.target === "draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0")
) {
schema.allOf = schema.allOf ?? [];
schema.allOf.push(refSchema);
} else assignProps(schema, refSchema);
assignProps(schema, _cached);
if (zodSchema._zod.parent === ref)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (!(key in _cached)) delete schema[key];
}
if (refSchema.$ref && refSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in refSeen.def &&
JSON.stringify(schema[key]) ===
JSON.stringify(refSeen.def[key])
)
delete schema[key];
}
}
const parent = zodSchema._zod.parent;
if (parent && parent !== ref) {
flattenRef(parent);
const parentSeen = ctx.seen.get(parent);
if (parentSeen?.schema.$ref) {
schema.$ref = parentSeen.schema.$ref;
if (parentSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in parentSeen.def &&
JSON.stringify(schema[key]) ===
JSON.stringify(parentSeen.def[key])
)
delete schema[key];
}
}
}
ctx.override({
zodSchema,
jsonSchema: schema,
path: seen.path ?? [],
});
};
if (
!ctx.external ||
ctx.sharedEmitDoneFor !== ctx.external
) {
for (const entry of [...ctx.seen.entries()].reverse())
flattenRef(entry[0]);
if (ctx.target !== "openapi-3.0")
for (const entry of ctx.seen.entries())
compactTypeUnion(entry[1].def ?? entry[1].schema);
for (const rewrite of ctx.deferred) rewrite();
if (ctx.intersections.length) {
const carriers = new Map();
for (const seen of ctx.seen.values())
for (const json of [seen.schema, seen.def]) {
const allOf = json?.allOf;
if (!Array.isArray(allOf)) continue;
const existing = carriers.get(allOf);
if (existing) existing.push(json);
else carriers.set(allOf, [json]);
}
for (const allOf of ctx.intersections)
for (const json of carriers.get(allOf) ?? [])
foldIntersection(json);
}
}
const result = {};
if (ctx.target === "draft-2020-12")
result.$schema =
"https://json-schema.org/draft/2020-12/schema";
else if (ctx.target === "draft-07")
result.$schema =
"http://json-schema.org/draft-07/schema#";
else if (ctx.target === "draft-04")
result.$schema =
"http://json-schema.org/draft-04/schema#";
else if (ctx.target === "openapi-3.0") {
}
if (ctx.external?.uri) {
const id = ctx.external.registry.get(schema)?.id;
if (!id)
throw new Error("Schema is missing an `id` property");
result.$id = ctx.external.uri(id);
}
assignProps(
result,
root.defId ? root.schema : (root.def ?? root.schema),
);
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
if (rootMetaId !== void 0 && result.id === rootMetaId)
delete result.id;
const defs = ctx.external?.defs ?? {};
if (
!ctx.external ||
ctx.sharedEmitDoneFor !== ctx.external
)
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.def && seen.defId) {
if (seen.def.id === seen.defId) delete seen.def.id;
assignProp(defs, seen.defId, seen.def);
}
}
if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
if (ctx.external) {
} else if (Object.keys(defs).length > 0) {
if (ctx.target === "draft-2020-12") result.$defs = defs;
else result.definitions = defs;
}
try {
const finalized = JSON.parse(JSON.stringify(result));
Object.defineProperty(finalized, "~standard", {
value: {
...schema["~standard"],
jsonSchema: {
input: createStandardJSONSchemaMethod(
schema,
"input",
ctx.processors,
),
output: createStandardJSONSchemaMethod(
schema,
"output",
ctx.processors,
),
},
},
enumerable: false,
writable: false,
});
return finalized;
} catch (_err) {
throw new Error("Error converting schema to JSON.");
}
}
function isTransforming(_schema, _ctx) {
const ctx = _ctx ?? { seen: new Set() };
if (ctx.seen.has(_schema)) return false;
ctx.seen.add(_schema);
const def = _schema._zod.def;
if (def.type === "transform") return true;
if (def.type === "array")
return isTransforming(def.element, ctx);
if (def.type === "set")
return isTransforming(def.valueType, ctx);
if (def.type === "lazy")
return isTransforming(def.getter(), ctx);
if (
def.type === "promise" ||
def.type === "optional" ||
def.type === "nonoptional" ||
def.type === "nullable" ||
def.type === "readonly" ||
def.type === "default" ||
def.type === "prefault" ||
def.type === "catch"
)
return isTransforming(def.innerType, ctx);
if (def.type === "intersection")
return (
isTransforming(def.left, ctx) ||
isTransforming(def.right, ctx)
);
if (def.type === "record" || def.type === "map")
return (
isTransforming(def.keyType, ctx) ||
isTransforming(def.valueType, ctx)
);
if (def.type === "pipe") {
if (_schema._zod.traits.has("$ZodCodec")) return true;
return (
isTransforming(def.in, ctx) ||
isTransforming(def.out, ctx)
);
}
if (def.type === "object") {
for (const key in def.shape)
if (isTransforming(def.shape[key], ctx)) return true;
return false;
}
if (def.type === "union") {
for (const option of def.options)
if (isTransforming(option, ctx)) return true;
return false;
}
if (def.type === "tuple") {
for (const item of def.items)
if (isTransforming(item, ctx)) return true;
if (def.rest && isTransforming(def.rest, ctx))
return true;
return false;
}
return false;
}
const createToJSONSchemaMethod =
(schema, processors = {}) =>
(params) => {
const ctx = initializeContext({
...params,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const createStandardJSONSchemaMethod =
(schema, io, processors = {}) =>
(params) => {
const { libraryOptions, target } = params ?? {};
const ctx = initializeContext({
...(libraryOptions ?? {}),
target,
io,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const narrowMin = (agg, key, value) => {
if (agg[key] === void 0 || value > agg[key])
agg[key] = value;
};
const narrowMax = (agg, key, value) => {
if (agg[key] === void 0 || value < agg[key])
agg[key] = value;
};
const narrowBoth = (agg, value) => {
narrowMin(agg, "minimum", value);
narrowMax(agg, "maximum", value);
};
const addDivisor = (agg, value) => {
agg.multipleOf ?? (agg.multipleOf = []);
if (!agg.multipleOf.includes(value))
agg.multipleOf.push(value);
};
const addPattern = (agg, pattern) => {
agg.patterns ??
(agg.patterns = new Set());
agg.patterns.add(pattern);
};
const intersectMime = (agg, mime) => {
agg.mime = agg.mime
? agg.mime.filter((m) => mime.includes(m))
: [...mime];
};
const setFormat = (agg, format) => {
agg.format = format;
if (format.includes("int")) agg.isInt = true;
};
const minContributor = (agg, def) =>
narrowMin(agg, "minimum", def.minimum);
const maxContributor = (agg, def) =>
narrowMax(agg, "maximum", def.maximum);
const formatContributor = (ranges) => (agg, def) => {
setFormat(agg, def.format);
const [minimum, maximum] = ranges[def.format];
narrowMin(agg, "minimum", minimum);
narrowMax(agg, "maximum", maximum);
};
const contributors = {
greater_than: (agg, def) =>
narrowMin(
agg,
def.inclusive ? "minimum" : "exclusiveMinimum",
def.value,
),
less_than: (agg, def) =>
narrowMax(
agg,
def.inclusive ? "maximum" : "exclusiveMaximum",
def.value,
),
multiple_of: (agg, def) => addDivisor(agg, def.value),
number_format: formatContributor(NUMBER_FORMAT_RANGES),
bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
min_length: minContributor,
max_length: maxContributor,
length_equals: (agg, def) => narrowBoth(agg, def.length),
min_size: minContributor,
max_size: maxContributor,
size_equals: (agg, def) => narrowBoth(agg, def.size),
string_format: (agg, def) => {
setFormat(agg, def.format);
if (def.pattern) addPattern(agg, def.pattern);
if (
def.format === "base64" ||
def.format === "base64url"
)
agg.contentEncoding = def.format;
if (def.local || def.precision === -1)
agg.laxFormat = true;
},
mime_type: (agg, def) => intersectMime(agg, def.mime),
};
function aggregateChecks(schema) {
const agg = {};
const def = schema._zod.def;
const list = schema._zod.traits.has("$ZodCheck")
? [schema, ...(def.checks ?? [])]
: (def.checks ?? []);
for (const ch of list)
contributors[ch._zod.def.check]?.(agg, ch._zod.def);
const bag = schema._zod.bag;
if (bag.minimum !== void 0)
narrowMin(agg, "minimum", bag.minimum);
if (bag.exclusiveMinimum !== void 0)
narrowMin(
agg,
"exclusiveMinimum",
bag.exclusiveMinimum,
);
if (bag.maximum !== void 0)
narrowMax(agg, "maximum", bag.maximum);
if (bag.exclusiveMaximum !== void 0)
narrowMax(
agg,
"exclusiveMaximum",
bag.exclusiveMaximum,
);
if (bag.multipleOf !== void 0)
addDivisor(agg, bag.multipleOf);
if (bag.format !== void 0) {
agg.format ?? (agg.format = bag.format);
if (bag.format.includes("int")) agg.isInt = true;
}
if (bag.mime) intersectMime(agg, bag.mime);
for (const pattern of bag.patterns ?? [])
addPattern(agg, pattern);
return agg;
}
const formatMap = {
guid: "uuid",
url: "uri",
datetime: "date-time",
json_string: "json-string",
regex: "",
};
const exactPatterns = new Map([
[base64Charset, base64],
[base64urlCharset, base64url],
]);
const exactPattern = (p) => exactPatterns.get(p) ?? p;
const stringProcessor = (schema, ctx, _json, _params) => {
const json = _json;
json.type = "string";
const {
minimum,
maximum,
format,
patterns,
contentEncoding,
laxFormat,
} = aggregateChecks(schema);
if (typeof minimum === "number") json.minLength = minimum;
if (typeof maximum === "number") json.maxLength = maximum;
if (format) {
json.format = formatMap[format] ?? format;
if (json.format === "") delete json.format;
if (format === "time" || laxFormat) delete json.format;
}
if (contentEncoding)
json.contentEncoding = contentEncoding;
if (patterns && patterns.size > 0) {
const patternList = [...patterns].map(exactPattern);
if (patternList.length === 1)
json.pattern = patternList[0].source;
else if (patternList.length > 1)
json.allOf = [
...patternList.map((regex) => ({
...(ctx.target === "draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0"
? { type: "string" }
: {}),
pattern: regex.source,
})),
];
}
};
const numberProcessor = (schema, ctx, _json, params) => {
const json = _json;
const {
minimum,
maximum,
multipleOf,
exclusiveMaximum,
exclusiveMinimum,
isInt,
} = aggregateChecks(schema);
json.type = isInt ? "integer" : "number";
const exMin =
typeof exclusiveMinimum === "number" &&
exclusiveMinimum >=
(minimum ?? Number.NEGATIVE_INFINITY);
const exMax =
typeof exclusiveMaximum === "number" &&
exclusiveMaximum <=
(maximum ?? Number.POSITIVE_INFINITY);
const legacy =
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0";
if (exMin) {
if (legacy) {
json.minimum = exclusiveMinimum;
json.exclusiveMinimum = true;
} else json.exclusiveMinimum = exclusiveMinimum;
} else if (typeof minimum === "number")
json.minimum = minimum;
if (exMax) {
if (legacy) {
json.maximum = exclusiveMaximum;
json.exclusiveMaximum = true;
} else json.exclusiveMaximum = exclusiveMaximum;
} else if (typeof maximum === "number")
json.maximum = maximum;
if (multipleOf) {
const divisors = new Set();
for (const divisor of multipleOf)
if (Number.isFinite(divisor) && divisor !== 0)
divisors.add(Math.abs(divisor));
else
handleUnrepresentable(
schema,
ctx,
json,
params,
`A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`,
);
const [first, ...rest] = divisors;
if (first !== void 0) json.multipleOf = first;
if (rest.length)
json.allOf = [
...(json.allOf ?? []),
...rest.map((m) => ({ multipleOf: m })),
];
}
};
const neverProcessor = (_schema, _ctx, json, _params) => {
json.not = {};
};
const dateProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Date cannot be represented in JSON Schema",
);
};
const enumProcessor = (schema, _ctx, json, _params) => {
const def = schema._zod.def;
const values = getEnumValues(def.entries);
if (values.length === 0) {
json.not = {};
return;
}
if (values.every((v) => typeof v === "number"))
json.type = "number";
if (values.every((v) => typeof v === "string"))
json.type = "string";
json.enum = values;
};
const customProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Custom types cannot be represented in JSON Schema",
);
};
const transformProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Transforms cannot be represented in JSON Schema",
);
};
const arrayProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const { minimum, maximum } = aggregateChecks(schema);
if (typeof minimum === "number") json.minItems = minimum;
if (typeof maximum === "number") json.maxItems = maximum;
json.type = "array";
json.items = processSchema(def.element, ctx, {
...params,
path: [...params.path, "items"],
});
};
function inputOptin(schema) {
const def = schema._zod.def;
if (
def.type === "pipe" &&
def.in._zod.traits.has("$ZodTransform")
)
return inputOptin(def.out);
if (def.type === "catch")
return inputOptin(def.innerType);
return schema._zod.optin;
}
const objectProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const shape = def.shape;
if (
Object.getOwnPropertySymbols(shape).length &&
handleUnrepresentable(
schema,
ctx,
json,
params,
"Symbol keys cannot be represented in JSON Schema",
)
)
return;
json.type = "object";
json.properties = {};
for (const key in shape)
assignProp(
json.properties,
key,
processSchema(shape[key], ctx, {
...params,
path: [...params.path, "properties", key],
}),
);
const requiredKeys = [];
for (const key of Object.keys(shape)) {
const field = def.shape[key];
if (
ctx.io === "input"
? inputOptin(field) === void 0
: field._zod.optout === void 0
)
requiredKeys.push(key);
}
if (requiredKeys.length > 0) json.required = requiredKeys;
if (def.catchall?._zod.def.type === "never")
json.additionalProperties = false;
else if (!def.catchall) {
if (ctx.io === "output")
json.additionalProperties = false;
} else if (def.catchall)
json.additionalProperties = processSchema(
def.catchall,
ctx,
{
...params,
path: [...params.path, "additionalProperties"],
},
);
};
const unionProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const isExclusive = def.inclusive === false;
const options = def.options.map((x, i) =>
processSchema(x, ctx, {
...params,
path: [
...params.path,
isExclusive ? "oneOf" : "anyOf",
i,
],
}),
);
if (isExclusive) json.oneOf = options;
else json.anyOf = options;
};
const intersectionProcessor = (
schema,
ctx,
json,
params,
) => {
const def = schema._zod.def;
const a = processSchema(def.left, ctx, {
...params,
path: [...params.path, "allOf", 0],
});
const b = processSchema(def.right, ctx, {
...params,
path: [...params.path, "allOf", 1],
});
const isSimpleIntersection = (val) =>
"allOf" in val && Object.keys(val).length === 1;
const allOf = [
...(isSimpleIntersection(a) ? a.allOf : [a]),
...(isSimpleIntersection(b) ? b.allOf : [b]),
];
json.allOf = allOf;
ctx.intersections.push(allOf);
};
const nullableProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const inner = processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
if (ctx.target === "openapi-3.0") {
seen.ref = def.innerType;
json.nullable = true;
} else json.anyOf = [inner, { type: "null" }];
};
const nonoptionalProcessor = (
schema,
ctx,
_json,
params,
) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const UNREPRESENTABLE_DEFAULT = Symbol();
function serializeDefaultValue(
value,
schema,
ctx,
json,
params,
) {
let unrepresentable = false;
const serialized = JSON.stringify(value, (_, val) => {
if (typeof val !== "bigint") return val;
unrepresentable = true;
return null;
});
if (!unrepresentable) return JSON.parse(serialized);
handleUnrepresentable(
schema,
ctx,
json,
params,
"BigInt defaults cannot be represented in JSON Schema",
);
return UNREPRESENTABLE_DEFAULT;
}
const defaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT)
json.default = value;
};
const prefaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
if (ctx.io !== "input") return;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT)
json._prefault = value;
};
const catchProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
let catchValue;
try {
catchValue = def.catchValue(void 0);
} catch {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Dynamic catch values are not supported in JSON Schema",
);
return;
}
json.default = catchValue;
};
const pipeProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
const inIsTransform =
def.in._zod.traits.has("$ZodTransform");
const innerType =
ctx.io === "input"
? inIsTransform
? def.out
: def.in
: def.out;
processSchema(innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = innerType;
};
const readonlyProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
json.readOnly = true;
};
const optionalProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const _installedErrorProtos = new WeakSet([
Object.prototype,
Error.prototype,
]);
function _lazyMethod(proto, key, make) {
Object.defineProperty(proto, key, {
configurable: true,
enumerable: false,
get() {
const value = make(this);
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
},
});
}
const initializer = (inst, issues) => {
$ZodError.init(inst, issues);
inst.name = "ZodError";
const proto = Object.getPrototypeOf(inst);
if (_installedErrorProtos.has(proto)) return;
_installedErrorProtos.add(proto);
_lazyMethod(
proto,
"format",
(self) => (mapper) => formatError(self, mapper),
);
_lazyMethod(
proto,
"flatten",
(self) => (mapper) => flattenError(self, mapper),
);
_lazyMethod(proto, "addIssue", (self) => (issue) => {
self.issues.push(issue);
self.message = JSON.stringify(
self.issues,
jsonStringifyReplacer,
2,
);
});
_lazyMethod(proto, "addIssues", (self) => (issues) => {
self.issues.push(...issues);
self.message = JSON.stringify(
self.issues,
jsonStringifyReplacer,
2,
);
});
Object.defineProperty(proto, "isEmpty", {
configurable: true,
enumerable: false,
get() {
return this.issues.length === 0;
},
});
};
const ZodRealError = $constructor(
"ZodError",
initializer,
void 0,
{ Parent: Error },
);
const parse = _parse(ZodRealError);
const parseAsync =
_parseAsync(ZodRealError);
const safeParse = _safeParse(ZodRealError);
const safeParseAsync =
_safeParseAsync(ZodRealError);
const encode = _encode(ZodRealError);
const decode = _decode(ZodRealError);
const encodeAsync =
_encodeAsync(ZodRealError);
const decodeAsync =
_decodeAsync(ZodRealError);
const safeEncode =
_safeEncode(ZodRealError);
const safeDecode =
_safeDecode(ZodRealError);
const safeEncodeAsync =
_safeEncodeAsync(ZodRealError);
const safeDecodeAsync =
_safeDecodeAsync(ZodRealError);
function _ensureDefaultLocale() {
if (!globalConfig.localeError) config(en_default());
}
function _ensureDefaultMemoizer() {
if (!globalConfig.memoizer)
config({ memoizer: memoizer() });
}
const ZodType = $constructor(
"ZodType",
(inst, def) => {
_ensureDefaultLocale();
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
return inst;
},
{
check(...chks) {
const def = this.def;
return this.clone(
mergeDefs(def, {
checks: [
...(def.checks ?? []),
...chks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
}),
{ parent: true },
);
},
with(...chks) {
return this.check(...chks);
},
clone(def, params) {
return clone(this, def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
refine(check, params) {
return this.check(refine(check, params));
},
superRefine(refinement, params) {
return this.check(superRefine(refinement, params));
},
overwrite(fn) {
return this.check( _overwrite(fn));
},
optional() {
return optional(this);
},
exactOptional() {
return exactOptional(this);
},
nullable() {
return nullable(this);
},
nullish() {
return optional(nullable(this));
},
nonoptional(params) {
return nonoptional(this, params);
},
array() {
return array(this);
},
or(arg) {
return union([this, arg]);
},
and(arg) {
return intersection(this, arg);
},
transform(tx) {
return pipe(this, transform(tx));
},
default(d) {
return _default(this, d);
},
prefault(d) {
return prefault(this, d);
},
catch(params) {
return _catch(this, params);
},
pipe(target) {
return pipe(this, target);
},
readonly() {
return readonly(this);
},
describe(description) {
const cl = this.clone();
globalRegistry.add(cl, { description });
return cl;
},
meta(...args) {
if (args.length === 0)
return globalRegistry.get(this);
const cl = this.clone();
globalRegistry.add(cl, args[0]);
return cl;
},
isOptional() {
return this.safeParse(void 0).success;
},
isNullable() {
return this.safeParse(null).success;
},
apply(fn, ...args) {
return args.length === 0
? fn(this)
: fn(this, ...args);
},
get "~standard"() {
return hide(this, "~standard", {
...standardProps(this),
jsonSchema: {
input: createStandardJSONSchemaMethod(
this,
"input",
),
output: createStandardJSONSchemaMethod(
this,
"output",
),
},
});
},
set "~standard"(value) {
own(this, "~standard", value);
},
parse: function _parse(data, params) {
return parse(this, data, params, { callee: _parse });
},
parseAsync: async function _parseAsync(data, params) {
return await parseAsync(this, data, params, {
callee: _parseAsync,
});
},
safeParse(data, params) {
return safeParse(this, data, params);
},
async safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
get spa() {
return this?.safeParseAsync;
},
set spa(value) {
own(this, "spa", value);
},
validate(data, params) {
return validate(this, data, params);
},
validateAsync(data, params) {
return validateAsync$1(this, data, params);
},
encode: function _encode(data, params) {
return encode(this, data, params, {
callee: _encode,
});
},
decode: function _decode(data, params) {
return decode(this, data, params, {
callee: _decode,
});
},
encodeAsync: async function _encodeAsync(data, params) {
return await encodeAsync(this, data, params, {
callee: _encodeAsync,
});
},
decodeAsync: async function _decodeAsync(data, params) {
return await decodeAsync(this, data, params, {
callee: _decodeAsync,
});
},
safeEncode(data, params) {
return safeEncode(this, data, params);
},
safeDecode(data, params) {
return safeDecode(this, data, params);
},
async safeEncodeAsync(data, params) {
return safeEncodeAsync(this, data, params);
},
async safeDecodeAsync(data, params) {
return safeDecodeAsync(this, data, params);
},
toJSONSchema(params) {
return createToJSONSchemaMethod(this, {})(params);
},
get description() {
return globalRegistry.get(this)?.description;
},
get _def() {
return this._zod.def;
},
},
);
const _ZodString = $constructor(
"_ZodString",
(inst, def) => {
$ZodString.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
stringProcessor(inst, ctx, json, params);
},
derived(
{
format: (inst) =>
aggregateChecks(inst).format ?? null,
minLength: (inst) =>
aggregateChecks(inst).minimum ?? null,
maxLength: (inst) =>
aggregateChecks(inst).maximum ?? null,
},
{
regex(...args) {
return this.check( _regex(...args));
},
includes(...args) {
return this.check(
_includes(...args),
);
},
startsWith(...args) {
return this.check(
_startsWith(...args),
);
},
endsWith(...args) {
return this.check(
_endsWith(...args),
);
},
min(...args) {
return this.check(
_minLength(...args),
);
},
max(...args) {
return this.check(
_maxLength(...args),
);
},
length(...args) {
return this.check( _length(...args));
},
nonempty(...args) {
return this.check(
_minLength(1, ...args),
);
},
lowercase(params) {
return this.check(
_lowercase(params),
);
},
uppercase(params) {
return this.check(
_uppercase(params),
);
},
trim() {
return this.check( _trim());
},
normalize(...args) {
return this.check(
_normalize(...args),
);
},
toLowerCase() {
return this.check( _toLowerCase());
},
toUpperCase() {
return this.check( _toUpperCase());
},
slugify() {
return this.check( _slugify());
},
},
),
);
const ZodString = $constructor(
"ZodString",
(inst, def) => {
$ZodString.init(inst, def);
_ZodString.init(inst, def);
},
{
email(params) {
return this.check(
_email(ZodEmail, params),
);
},
url(params) {
return this.check(
_url(ZodURL, params),
);
},
jwt(params) {
return this.check(
_jwt(ZodJWT, params),
);
},
emoji(params) {
return this.check(
_emoji(ZodEmoji, params),
);
},
guid(params) {
return this.check(
_guid(ZodGUID, params),
);
},
uuid(params) {
return this.check(
_uuid(ZodUUID, params),
);
},
uuidv4(params) {
return this.check(
_uuidv4(ZodUUID, params),
);
},
uuidv6(params) {
return this.check(
_uuidv6(ZodUUID, params),
);
},
uuidv7(params) {
return this.check(
_uuidv7(ZodUUID, params),
);
},
nanoid(params) {
return this.check(
_nanoid(ZodNanoID, params),
);
},
cuid(params) {
return this.check(
_cuid(ZodCUID, params),
);
},
cuid2(params) {
return this.check(
_cuid2(ZodCUID2, params),
);
},
ulid(params) {
return this.check(
_ulid(ZodULID, params),
);
},
base64(params) {
return this.check(
_base64(ZodBase64, params),
);
},
base64url(params) {
return this.check(
_base64url(ZodBase64URL, params),
);
},
xid(params) {
return this.check(
_xid(ZodXID, params),
);
},
ksuid(params) {
return this.check(
_ksuid(ZodKSUID, params),
);
},
ipv4(params) {
return this.check(
_ipv4(ZodIPv4, params),
);
},
ipv6(params) {
return this.check(
_ipv6(ZodIPv6, params),
);
},
cidrv4(params) {
return this.check(
_cidrv4(ZodCIDRv4, params),
);
},
cidrv6(params) {
return this.check(
_cidrv6(ZodCIDRv6, params),
);
},
e164(params) {
return this.check(
_e164(ZodE164, params),
);
},
datetime(params) {
return this.check(
_isoDateTime(
ZodISODateTime,
params,
),
);
},
date(params) {
return this.check(
_isoDate(ZodISODate, params),
);
},
time(params) {
return this.check(
_isoTime(ZodISOTime, params),
);
},
duration(params) {
return this.check(
_isoDuration(
ZodISODuration,
params,
),
);
},
},
);
function string(params) {
return _string(ZodString, params);
}
const ZodStringFormat = $constructor(
"ZodStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
},
);
const ZodISODateTime = $constructor(
"ZodISODateTime",
(inst, def) => {
$ZodISODateTime.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISODate = $constructor(
"ZodISODate",
(inst, def) => {
$ZodISODate.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISOTime = $constructor(
"ZodISOTime",
(inst, def) => {
$ZodISOTime.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISODuration = $constructor(
"ZodISODuration",
(inst, def) => {
$ZodISODuration.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodEmail = $constructor(
"ZodEmail",
(inst, def) => {
$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodGUID = $constructor(
"ZodGUID",
(inst, def) => {
$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodUUID = $constructor(
"ZodUUID",
(inst, def) => {
$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodURL = $constructor(
"ZodURL",
(inst, def) => {
$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
function url(params) {
return _url(ZodURL, params);
}
const ZodEmoji = $constructor(
"ZodEmoji",
(inst, def) => {
$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodNanoID = $constructor(
"ZodNanoID",
(inst, def) => {
$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCUID = $constructor(
"ZodCUID",
(inst, def) => {
$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCUID2 = $constructor(
"ZodCUID2",
(inst, def) => {
$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodULID = $constructor(
"ZodULID",
(inst, def) => {
$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodXID = $constructor(
"ZodXID",
(inst, def) => {
$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodKSUID = $constructor(
"ZodKSUID",
(inst, def) => {
$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodIPv4 = $constructor(
"ZodIPv4",
(inst, def) => {
$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodIPv6 = $constructor(
"ZodIPv6",
(inst, def) => {
$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCIDRv4 = $constructor(
"ZodCIDRv4",
(inst, def) => {
$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodCIDRv6 = $constructor(
"ZodCIDRv6",
(inst, def) => {
$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodBase64 = $constructor(
"ZodBase64",
(inst, def) => {
$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodBase64URL = $constructor(
"ZodBase64URL",
(inst, def) => {
$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodE164 = $constructor(
"ZodE164",
(inst, def) => {
$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodJWT = $constructor(
"ZodJWT",
(inst, def) => {
$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodNumber = $constructor(
"ZodNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
numberProcessor(inst, ctx, json, params);
inst.isFinite = true;
},
derived(
{
minValue: (inst) => {
const { minimum, exclusiveMinimum } =
aggregateChecks(inst);
return Math.max(
minimum ?? Number.NEGATIVE_INFINITY,
exclusiveMinimum ?? Number.NEGATIVE_INFINITY,
);
},
maxValue: (inst) => {
const { maximum, exclusiveMaximum } =
aggregateChecks(inst);
return Math.min(
maximum ?? Number.POSITIVE_INFINITY,
exclusiveMaximum ?? Number.POSITIVE_INFINITY,
);
},
isInt: (inst) => {
const { isInt, multipleOf } = aggregateChecks(inst);
return (
!!isInt ||
!!multipleOf?.some(Number.isSafeInteger)
);
},
format: (inst) =>
aggregateChecks(inst).format ?? null,
},
{
gt(value, params) {
return this.check(
_gt(value, params),
);
},
gte(value, params) {
return this.check(
_gte(value, params),
);
},
min(value, params) {
return this.check(
_gte(value, params),
);
},
lt(value, params) {
return this.check(
_lt(value, params),
);
},
lte(value, params) {
return this.check(
_lte(value, params),
);
},
max(value, params) {
return this.check(
_lte(value, params),
);
},
int(params) {
return this.check(int(params));
},
safe(params) {
return this.check(int(params));
},
positive(params) {
return this.check( _gt(0, params));
},
nonnegative(params) {
return this.check( _gte(0, params));
},
negative(params) {
return this.check( _lt(0, params));
},
nonpositive(params) {
return this.check( _lte(0, params));
},
multipleOf(value, params) {
return this.check(
_multipleOf(value, params),
);
},
step(value, params) {
return this.check(
_multipleOf(value, params),
);
},
finite() {
return this;
},
},
),
);
function number(params) {
return _number(ZodNumber, params);
}
const ZodNumberFormat = $constructor(
"ZodNumberFormat",
(inst, def) => {
$ZodNumberFormat.init(inst, def);
ZodNumber.init(inst, def);
},
);
function int(params) {
return _int(ZodNumberFormat, params);
}
const ZodUnknown = $constructor(
"ZodUnknown",
(inst, def) => {
$ZodUnknown.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
void 0;
},
);
function unknown() {
return _unknown(ZodUnknown);
}
const ZodNever = $constructor(
"ZodNever",
(inst, def) => {
$ZodNever.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
neverProcessor(inst, ctx, json, params);
},
);
function never(params) {
return _never(ZodNever, params);
}
const ZodDate = $constructor(
"ZodDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
dateProcessor(inst, ctx, json, params);
inst.min = (value, params) =>
inst.check( _gte(value, params));
inst.max = (value, params) =>
inst.check( _lte(value, params));
},
derived(
{
minDate: (inst) => {
const { minimum } = aggregateChecks(inst);
return minimum ? new Date(minimum) : null;
},
maxDate: (inst) => {
const { maximum } = aggregateChecks(inst);
return maximum ? new Date(maximum) : null;
},
},
{},
),
);
function date(params) {
return _date(ZodDate, params);
}
const ZodArray = $constructor(
"ZodArray",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodArray.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
arrayProcessor(inst, ctx, json, params);
inst.element = def.element;
},
{
min(n, params) {
return this.check(
_minLength(n, params),
);
},
nonempty(params) {
return this.check(
_minLength(1, params),
);
},
max(n, params) {
return this.check(
_maxLength(n, params),
);
},
length(n, params) {
return this.check( _length(n, params));
},
unwrap() {
return this.element;
},
},
);
function array(element, params) {
return _array(ZodArray, element, params);
}
const ZodObject = $constructor(
"ZodObject",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodObjectJIT.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
objectProcessor(inst, ctx, json, params);
installLazyProp(
inst,
"shape",
(self) => self._zod.def.shape,
false,
);
},
{
keyof() {
return _enum(Object.keys(this._zod.def.shape));
},
catchall(catchall) {
return this.clone(
mergeDefs(this._zod.def, { catchall }),
);
},
passthrough() {
return this.clone(
mergeDefs(this._zod.def, { catchall: unknown() }),
);
},
loose() {
return this.clone(
mergeDefs(this._zod.def, { catchall: unknown() }),
);
},
strict() {
return this.clone(
mergeDefs(this._zod.def, { catchall: never() }),
);
},
strip() {
return this.clone(
mergeDefs(this._zod.def, { catchall: void 0 }),
);
},
extend(incoming) {
return extend(this, incoming);
},
safeExtend(incoming) {
return safeExtend(this, incoming);
},
merge(other) {
return merge(this, other);
},
pick(mask) {
return pick(this, mask);
},
omit(mask) {
return omit(this, mask);
},
partial(...args) {
return partial(ZodOptional, this, args[0]);
},
exactPartial(...args) {
return partial(
ZodExactOptional,
this,
args[0],
"exactPartial",
);
},
required(...args) {
return required(ZodNonOptional, this, args[0]);
},
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodObject(def);
}
const ZodUnion = $constructor(
"ZodUnion",
(inst, def) => {
$ZodUnion.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
unionProcessor(inst, ctx, json, params);
inst.options = def.options;
},
);
function union(options, params) {
return new ZodUnion({
type: "union",
options,
...normalizeParams(params),
});
}
const ZodIntersection = $constructor(
"ZodIntersection",
(inst, def) => {
$ZodIntersection.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
intersectionProcessor(inst, ctx, json, params);
},
);
function intersection(left, right) {
return new ZodIntersection({
type: "intersection",
left,
right,
});
}
const ZodEnum = $constructor(
"ZodEnum",
(inst, def) => {
$ZodEnum.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
enumProcessor(inst, ctx, json, params);
inst.enum = def.entries;
inst.options = [...inst._zod.values];
const keys = new Set(Object.keys(def.entries));
inst.extract = (values, params) => {
const newEntries = {};
for (const value of values)
if (keys.has(value))
newEntries[value] = def.entries[value];
else
throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (values, params) => {
const newEntries = { ...def.entries };
for (const value of values)
if (keys.has(value)) delete newEntries[value];
else
throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
},
);
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(values.map((v) => [v, v]))
: values;
return new ZodEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodTransform = $constructor(
"ZodTransform",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodTransform.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
transformProcessor(inst, ctx, json, params);
inst._zod.parse = (payload, _ctx) => {
if (_ctx.direction === "backward")
throw new $ZodEncodeError(inst.constructor.name);
payload.addIssue = (issue$1) => {
if (typeof issue$1 === "string")
payload.issues.push(
issue(issue$1, payload.value, def),
);
else {
const _issue = issue$1;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue))
_issue.input = payload.value;
_issue.inst ?? (_issue.inst = inst);
payload.issues.push(issue(_issue));
}
};
const output = def.transform(payload.value, payload);
if (output instanceof Promise)
return output.then((output) => {
payload.value = output;
return payload;
});
payload.value = output;
return payload;
};
},
);
function transform(fn) {
return new ZodTransform({
type: "transform",
transform: fn,
});
}
const ZodOptional = $constructor(
"ZodOptional",
(inst, def) => {
$ZodOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function optional(innerType) {
return new ZodOptional({
type: "optional",
innerType,
});
}
const ZodExactOptional = $constructor(
"ZodExactOptional",
(inst, def) => {
$ZodExactOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function exactOptional(innerType) {
return new ZodExactOptional({
type: "optional",
innerType,
});
}
const ZodNullable = $constructor(
"ZodNullable",
(inst, def) => {
$ZodNullable.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
nullableProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function nullable(innerType) {
return new ZodNullable({
type: "nullable",
innerType,
});
}
const ZodDefault = $constructor(
"ZodDefault",
(inst, def) => {
$ZodDefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
defaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
},
);
function _default(innerType, defaultValue) {
return new ZodDefault({
type: "default",
innerType,
get defaultValue() {
return typeof defaultValue === "function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodPrefault = $constructor(
"ZodPrefault",
(inst, def) => {
$ZodPrefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
prefaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function prefault(innerType, defaultValue) {
return new ZodPrefault({
type: "prefault",
innerType,
get defaultValue() {
return typeof defaultValue === "function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodNonOptional = $constructor(
"ZodNonOptional",
(inst, def) => {
$ZodNonOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
nonoptionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function nonoptional(innerType, params) {
return new ZodNonOptional({
type: "nonoptional",
innerType,
...normalizeParams(params),
});
}
const ZodCatch = $constructor(
"ZodCatch",
(inst, def) => {
$ZodCatch.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
catchProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
},
);
function _catch(innerType, catchValue) {
return new ZodCatch({
type: "catch",
innerType,
catchValue:
typeof catchValue === "function"
? catchValue
: constantCatch(catchValue),
});
}
const ZodPipe = $constructor(
"ZodPipe",
(inst, def) => {
$ZodPipe.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
pipeProcessor(inst, ctx, json, params);
inst.in = def.in;
inst.out = def.out;
},
);
function pipe(in_, out) {
return new ZodPipe({
type: "pipe",
in: in_,
out,
});
}
const ZodReadonly = $constructor(
"ZodReadonly",
(inst, def) => {
$ZodReadonly.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
readonlyProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function readonly(innerType) {
return new ZodReadonly({
type: "readonly",
innerType,
});
}
const ZodCustom = $constructor(
"ZodCustom",
(inst, def) => {
$ZodCustom.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
customProcessor(inst, ctx, json, params);
},
);
function refine(fn, _params = {}) {
return _refine(ZodCustom, fn, _params);
}
function superRefine(fn, params) {
return _superRefine(fn, params);
}
function __zcUw(m) {
return typeof m === "string"
? m
: m === void 0 || m === null
? void 0
: m.message;
}
var __zcMsg = function (iss) {
var c = config(),
m;
if (c.customError) {
m = __zcUw(c.customError(iss));
if (m !== void 0 && m !== null) return m;
}
if (c.localeError) {
m = __zcUw(c.localeError(iss));
if (m !== void 0 && m !== null) return m;
}
return "Invalid input";
};
function __ZcFail(e, f, i) {
this.success = false;
this._e = e;
this._f = f;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFail.prototype, "error", {
configurable: true,
get: function () {
if (this._c) return this._c;
var e = this._f !== null ? this._f(this._i) : this._e;
for (var i = 0; i < e.length; i++) {
if (
e[i].message === void 0 &&
typeof __zcMsg === "function"
)
e[i].message = __zcMsg(e[i]);
delete e[i].input;
delete e[i].continue;
}
return (this._c = new ZodRealError(e));
},
});
function __ZcFailZ(z, r, i) {
this.success = false;
this._z = z;
this._r = r;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFailZ.prototype, "error", {
configurable: true,
get: function () {
return (
this._c ||
(this._c = this._z.call(this._r, this._i).error)
);
},
});
function __zcMkv(fn, schema, fc, is) {
var w = schema || {};
var zpa = w.parseAsync,
zspa = w.safeParseAsync;
w.parse = fc
? function (input) {
if (fc(input)) return input;
var r = fn(input);
if (r.success) return r.data;
throw r.error;
}
: function (input) {
var r = fn(input);
if (r.success) return r.data;
throw r.error;
};
w.safeParse = fn;
w.safeParseAsync = function (input) {
try {
return Promise.resolve(fn(input));
} catch (e) {
if (zspa) return zspa(input);
throw e;
}
};
w.parseAsync = fc
? function (input) {
try {
if (fc(input)) return Promise.resolve(input);
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
}
: function (input) {
try {
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
};
w.is =
is ||
function (input) {
return fn(input).success;
};
Object.defineProperty(w, "~standard", {
configurable: true,
value: {
version: 1,
vendor: "zod",
validate: function (input) {
var r;
try {
if (fc && fc(input)) return { value: input };
r = fn(input);
} catch (e) {
if (zspa)
return zspa(input).then(function (q) {
return q.success
? { value: q.data }
: { issues: q.error.issues };
});
throw e;
}
return r.success
? { value: r.data }
: { issues: r.error.issues };
},
},
});
return w;
}
function __zcFin(e, d) {
if (!e.length)
return {
success: true,
data: d,
};
return new __ZcFail(e, null, null);
}
function __zcTS(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_small",
minimum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcTB(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_big",
maximum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIT(e, inp, p, msg) {
var r = {
expected: e,
code: "invalid_type",
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIF(o, f, inp, p, extra, msg) {
var r =
o === void 0
? {
code: "invalid_format",
format: f,
}
: {
origin: o,
code: "invalid_format",
format: f,
};
if (extra) Object.assign(r, extra);
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIV(values, inp, p, extra, msg) {
var r = { code: "invalid_value" };
if (extra) Object.assign(r, extra);
r.values = values;
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcLo(v) {
return Array.isArray(v)
? "array"
: typeof v === "string"
? "string"
: "unknown";
}
function __zcCpl(s) {
var n = s.length;
if (!/[\uD800-\uDBFF]/.test(s)) return n;
var c = n;
for (var i = 0; i < n - 1; i++)
if (
(s.charCodeAt(i) & 64512) === 55296 &&
(s.charCodeAt(i + 1) & 64512) === 56320
) {
c--;
i++;
}
return c;
}
var __re_tnl_11 = new RegExp(
"[\\t\\n\\r]",
"g",
);
function __zcSw_0(input, path, _e) {
if (!Array.isArray(input))
_e.push(__zcIT("array", input, path));
else {
var __ar_0 = input;
__ar_0 = __ar_0.slice();
for (var __i_1 = 0; __i_1 < __ar_0.length; __i_1++)
__ar_0[__i_1] = __zcSw_1(
__ar_0[__i_1],
path.concat(__i_1),
_e,
);
input = __ar_0;
}
return input;
}
function __zcSw_1(input, path, _e) {
if (
typeof input !== "object" ||
input === null ||
Array.isArray(input)
)
_e.push(__zcIT("object", input, path));
else {
var __sv_3 = input["id"];
if (typeof __sv_3 !== "number")
_e.push(__zcIT("number", __sv_3, path.concat("id")));
else if (Number.isNaN(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_3,
path: path.concat("id"),
});
else if (!Number.isFinite(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_3),
input: __sv_3,
path: path.concat("id"),
});
var __sv_4 = input["created"];
if (!(__sv_4 instanceof Date))
_e.push(
__zcIT("date", __sv_4, path.concat("created")),
);
else if (isNaN(__sv_4.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_4,
path: path.concat("created"),
});
var __sv_5 = input["title"];
if (typeof __sv_5 !== "string") {
_e.push(
__zcIT("string", __sv_5, path.concat("title")),
);
if (
__sv_5 !== void 0 &&
__sv_5 !== null &&
__sv_5.length !== void 0
) {
if (__sv_5.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_5),
true,
__sv_5,
path.concat("title"),
),
);
if (__sv_5.length > 100)
_e.push(
__zcTB(
100,
__zcLo(__sv_5),
true,
__sv_5,
path.concat("title"),
),
);
}
} else {
if (__sv_5.length < 1)
_e.push(
__zcTS(
1,
"string",
true,
__sv_5,
path.concat("title"),
),
);
if (
__sv_5.length > 100 &&
(__sv_5.length > 200 || __zcCpl(__sv_5) > 100)
)
_e.push(
__zcTB(
100,
"string",
true,
__sv_5,
path.concat("title"),
),
);
}
var __sv_6 = input["type"];
if (__sv_6 !== "jpg" && __sv_6 !== "png")
_e.push(
__zcIV(["jpg", "png"], __sv_6, path.concat("type")),
);
var __sv_7 = input["size"];
if (typeof __sv_7 !== "number")
_e.push(
__zcIT("number", __sv_7, path.concat("size")),
);
else if (Number.isNaN(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_7,
path: path.concat("size"),
});
else if (!Number.isFinite(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_7),
input: __sv_7,
path: path.concat("size"),
});
var __sv_8 = input["url"];
if (typeof __sv_8 !== "string")
_e.push(__zcIT("string", __sv_8, path.concat("url")));
else {
var __ut_9 = __sv_8.trim();
var __u_10 = null;
try {
__u_10 = new URL(__ut_9);
} catch (_) {}
if (__u_10 === null)
_e.push(
__zcIF(void 0, "url", __sv_8, path.concat("url")),
);
else __sv_8 = __ut_9.replace(__re_tnl_11, "");
}
input = {
id: __sv_3,
created: __sv_4,
title: __sv_5,
type: __sv_6,
size: __sv_7,
url: __sv_8,
};
}
return input;
}
const imageSchema = object({
id: number(),
created: date(),
title: string().min(1).max(100),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().min(1).max(5),
title: string().min(1).max(100),
text: string().min(1).max(1e3),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().min(1).max(100),
brand: string().min(1).max(30),
description: string().min(1).max(500),
price: number().min(1).max(1e4),
discount: number().min(1).max(100).nullable(),
quantity: number().min(0).max(10),
tags: array(string().min(1).max(30)),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
);
(() => {
function safeParse_compiledProductSchema(input) {
var _e = [];
var _d = input;
if (
typeof _d !== "object" ||
_d === null ||
Array.isArray(_d)
)
_e.push(__zcIT("object", _d, []));
else {
var __sv_5 = _d["id"];
if (typeof __sv_5 !== "number")
_e.push(__zcIT("number", __sv_5, ["id"]));
else if (Number.isNaN(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_5,
path: ["id"],
});
else if (!Number.isFinite(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_5),
input: __sv_5,
path: ["id"],
});
var __sv_6 = _d["created"];
if (!(__sv_6 instanceof Date))
_e.push(__zcIT("date", __sv_6, ["created"]));
else if (isNaN(__sv_6.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_6,
path: ["created"],
});
var __sv_7 = _d["title"];
if (typeof __sv_7 !== "string") {
_e.push(__zcIT("string", __sv_7, ["title"]));
if (
__sv_7 !== void 0 &&
__sv_7 !== null &&
__sv_7.length !== void 0
) {
if (__sv_7.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_7), true, __sv_7, [
"title",
]),
);
if (__sv_7.length > 100)
_e.push(
__zcTB(100, __zcLo(__sv_7), true, __sv_7, [
"title",
]),
);
}
} else {
if (__sv_7.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_7, ["title"]),
);
if (
__sv_7.length > 100 &&
(__sv_7.length > 200 || __zcCpl(__sv_7) > 100)
)
_e.push(
__zcTB(100, "string", true, __sv_7, ["title"]),
);
}
var __sv_8 = _d["brand"];
if (typeof __sv_8 !== "string") {
_e.push(__zcIT("string", __sv_8, ["brand"]));
if (
__sv_8 !== void 0 &&
__sv_8 !== null &&
__sv_8.length !== void 0
) {
if (__sv_8.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_8), true, __sv_8, [
"brand",
]),
);
if (__sv_8.length > 30)
_e.push(
__zcTB(30, __zcLo(__sv_8), true, __sv_8, [
"brand",
]),
);
}
} else {
if (__sv_8.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_8, ["brand"]),
);
if (
__sv_8.length > 30 &&
(__sv_8.length > 60 || __zcCpl(__sv_8) > 30)
)
_e.push(
__zcTB(30, "string", true, __sv_8, ["brand"]),
);
}
var __sv_9 = _d["description"];
if (typeof __sv_9 !== "string") {
_e.push(__zcIT("string", __sv_9, ["description"]));
if (
__sv_9 !== void 0 &&
__sv_9 !== null &&
__sv_9.length !== void 0
) {
if (__sv_9.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_9), true, __sv_9, [
"description",
]),
);
if (__sv_9.length > 500)
_e.push(
__zcTB(500, __zcLo(__sv_9), true, __sv_9, [
"description",
]),
);
}
} else {
if (__sv_9.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_9, [
"description",
]),
);
if (
__sv_9.length > 500 &&
(__sv_9.length > 1e3 || __zcCpl(__sv_9) > 500)
)
_e.push(
__zcTB(500, "string", true, __sv_9, [
"description",
]),
);
}
var __sv_10 = _d["price"];
if (typeof __sv_10 !== "number")
_e.push(__zcIT("number", __sv_10, ["price"]));
else if (Number.isNaN(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_10,
path: ["price"],
});
else if (!Number.isFinite(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_10),
input: __sv_10,
path: ["price"],
});
else {
if (__sv_10 < 1)
_e.push(
__zcTS(1, "number", true, __sv_10, ["price"]),
);
if (__sv_10 > 1e4)
_e.push(
__zcTB(1e4, "number", true, __sv_10, ["price"]),
);
}
var __sv_11 = _d["discount"];
if (__sv_11 !== null) {
if (typeof __sv_11 !== "number")
_e.push(__zcIT("number", __sv_11, ["discount"]));
else if (Number.isNaN(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_11,
path: ["discount"],
});
else if (!Number.isFinite(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_11),
input: __sv_11,
path: ["discount"],
});
else {
if (__sv_11 < 1)
_e.push(
__zcTS(1, "number", true, __sv_11, [
"discount",
]),
);
if (__sv_11 > 100)
_e.push(
__zcTB(100, "number", true, __sv_11, [
"discount",
]),
);
}
}
var __sv_12 = _d["quantity"];
if (typeof __sv_12 !== "number")
_e.push(__zcIT("number", __sv_12, ["quantity"]));
else if (Number.isNaN(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_12,
path: ["quantity"],
});
else if (!Number.isFinite(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_12),
input: __sv_12,
path: ["quantity"],
});
else {
if (__sv_12 < 0)
_e.push(
__zcTS(0, "number", true, __sv_12, [
"quantity",
]),
);
if (__sv_12 > 10)
_e.push(
__zcTB(10, "number", true, __sv_12, [
"quantity",
]),
);
}
var __sv_13 = _d["tags"];
if (!Array.isArray(__sv_13))
_e.push(__zcIT("array", __sv_13, ["tags"]));
else {
var __ar_14 = __sv_13;
for (
var __i_15 = 0;
__i_15 < __ar_14.length;
__i_15++
) {
var __mv_16 = __ar_14[__i_15];
if (typeof __mv_16 !== "string") {
_e.push(
__zcIT("string", __mv_16, ["tags", __i_15]),
);
if (
__mv_16 !== void 0 &&
__mv_16 !== null &&
__mv_16.length !== void 0
) {
if (__mv_16.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__mv_16),
true,
__mv_16,
["tags", __i_15],
),
);
if (__mv_16.length > 30)
_e.push(
__zcTB(
30,
__zcLo(__mv_16),
true,
__mv_16,
["tags", __i_15],
),
);
}
} else {
if (__mv_16.length < 1)
_e.push(
__zcTS(1, "string", true, __mv_16, [
"tags",
__i_15,
]),
);
if (
__mv_16.length > 30 &&
(__mv_16.length > 60 || __zcCpl(__mv_16) > 30)
)
_e.push(
__zcTB(30, "string", true, __mv_16, [
"tags",
__i_15,
]),
);
}
}
__sv_13 = __ar_14;
}
var __sv_18 = _d["images"];
__sv_18 = __zcSw_0(__sv_18, ["images"], _e);
var __sv_19 = _d["ratings"];
if (!Array.isArray(__sv_19))
_e.push(__zcIT("array", __sv_19, ["ratings"]));
else {
var __ar_20 = __sv_19;
__ar_20 = __ar_20.slice();
for (
var __i_21 = 0;
__i_21 < __ar_20.length;
__i_21++
)
if (
typeof __ar_20[__i_21] !== "object" ||
__ar_20[__i_21] === null ||
Array.isArray(__ar_20[__i_21])
)
_e.push(
__zcIT("object", __ar_20[__i_21], [
"ratings",
__i_21,
]),
);
else {
var __sv_23 = __ar_20[__i_21]["id"];
if (typeof __sv_23 !== "number")
_e.push(
__zcIT("number", __sv_23, [
"ratings",
__i_21,
"id",
]),
);
else if (Number.isNaN(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
else if (!Number.isFinite(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_23),
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
var __sv_24 = __ar_20[__i_21]["stars"];
if (typeof __sv_24 !== "number")
_e.push(
__zcIT("number", __sv_24, [
"ratings",
__i_21,
"stars",
]),
);
else if (Number.isNaN(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else if (!Number.isFinite(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_24),
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else {
if (__sv_24 < 1)
_e.push(
__zcTS(1, "number", true, __sv_24, [
"ratings",
__i_21,
"stars",
]),
);
if (__sv_24 > 5)
_e.push(
__zcTB(5, "number", true, __sv_24, [
"ratings",
__i_21,
"stars",
]),
);
}
var __sv_25 = __ar_20[__i_21]["title"];
if (typeof __sv_25 !== "string") {
_e.push(
__zcIT("string", __sv_25, [
"ratings",
__i_21,
"title",
]),
);
if (
__sv_25 !== void 0 &&
__sv_25 !== null &&
__sv_25.length !== void 0
) {
if (__sv_25.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_25),
true,
__sv_25,
["ratings", __i_21, "title"],
),
);
if (__sv_25.length > 100)
_e.push(
__zcTB(
100,
__zcLo(__sv_25),
true,
__sv_25,
["ratings", __i_21, "title"],
),
);
}
} else {
if (__sv_25.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
if (
__sv_25.length > 100 &&
(__sv_25.length > 200 ||
__zcCpl(__sv_25) > 100)
)
_e.push(
__zcTB(100, "string", true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
}
var __sv_26 = __ar_20[__i_21]["text"];
if (typeof __sv_26 !== "string") {
_e.push(
__zcIT("string", __sv_26, [
"ratings",
__i_21,
"text",
]),
);
if (
__sv_26 !== void 0 &&
__sv_26 !== null &&
__sv_26.length !== void 0
) {
if (__sv_26.length < 1)
_e.push(
__zcTS(
1,
__zcLo(__sv_26),
true,
__sv_26,
["ratings", __i_21, "text"],
),
);
if (__sv_26.length > 1e3)
_e.push(
__zcTB(
1e3,
__zcLo(__sv_26),
true,
__sv_26,
["ratings", __i_21, "text"],
),
);
}
} else {
if (__sv_26.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
if (
__sv_26.length > 1e3 &&
(__sv_26.length > 2e3 ||
__zcCpl(__sv_26) > 1e3)
)
_e.push(
__zcTB(1e3, "string", true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
}
var __sv_27 = __ar_20[__i_21]["images"];
__sv_27 = __zcSw_0(
__sv_27,
["ratings", __i_21, "images"],
_e,
);
__ar_20[__i_21] = {
id: __sv_23,
stars: __sv_24,
title: __sv_25,
text: __sv_26,
images: __sv_27,
};
}
__sv_19 = __ar_20;
}
_d = {
id: __sv_5,
created: __sv_6,
title: __sv_7,
brand: __sv_8,
description: __sv_9,
price: __sv_10,
discount: __sv_11,
quantity: __sv_12,
tags: __sv_13,
images: __sv_18,
ratings: __sv_19,
};
}
if (_e.length === 0)
return {
success: true,
data: _d,
};
return __zcFin(_e, _d);
}
return __zcMkv(
safeParse_compiledProductSchema,
null,
null,
null,
);
})().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 joinValues(array, separator = "|") {
return array.map((val) => stringifyPrimitive(val)).join(separator);
}
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 floatSafeRemainder(val, step) {
const ratio = val / step;
const roundedRatio = Math.round(ratio);
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
return ratio - roundedRatio;
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
function rawShape(def) {
const desc = Object.getOwnPropertyDescriptor(def, "shape");
return desc?.get ? desc.get.raw : desc?.value;
}
function sourceShape(schema) {
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
}
function deferProp(target, key, getter) {
Object.defineProperty(target, key, {
get() {
const value = getter();
assignProp(this, key, value);
return value;
},
enumerable: true,
configurable: true,
});
}
function putProp(target, key, value) {
if (key in target) assignProp(target, key, value);
else target[key] = value;
}
function mirrorShape(target, source, keys, wrap) {
const raw = sourceShape(source);
for (const key of keys) {
const desc = Object.getOwnPropertyDescriptor(raw, key);
if (!desc.enumerable) continue;
if (desc.get)
deferProp(target, key, () => {
const value = source._zod.def.shape[key];
return wrap ? wrap(value, key) : value;
});
else putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
}
}
function mirrorProps(target, source) {
for (const key of Reflect.ownKeys(source)) {
const desc = Object.getOwnPropertyDescriptor(source, key);
if (!desc.enumerable) continue;
if (desc.get) deferProp(target, key, () => source[key]);
else putProp(target, key, desc.value);
}
}
function mergeDefs(...defs) {
const mergedDescriptors = {};
for (const def of defs) {
const descriptors = Object.getOwnPropertyDescriptors(def);
Object.assign(mergedDescriptors, descriptors);
}
return Object.defineProperties({}, mergedDescriptors);
}
function esc(str) {
return JSON.stringify(str);
}
function slugify(input) {
return input
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, "")
.replace(/[\s_-]+/g, "-")
.replace(/^-+|-+$/g, "");
}
const captureStackTrace =
"captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
const allowsEval = cached(() => {
if (globalConfig.jitless) return false;
if (
typeof navigator !== "undefined" &&
navigator?.userAgent?.includes("Cloudflare")
)
return false;
try {
new Function("");
return true;
} catch (_) {
return false;
}
});
function isPlainObject(o) {
if (isObject(o) === false) return false;
const ctor = o.constructor;
if (ctor === void 0) return true;
if (typeof ctor !== "function") return true;
const prot = ctor.prototype;
if (isObject(prot) === false) return false;
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false)
return false;
return true;
}
function shallowClone(o) {
if (isPlainObject(o)) return { ...o };
if (Array.isArray(o)) return [...o];
if (o instanceof Map) return new Map(o);
if (o instanceof Set) return new Set(o);
return o;
}
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 stringifyPrimitive(value) {
if (typeof value === "bigint") return value.toString() + "n";
if (typeof value === "string") return `"${value}"`;
return `${value}`;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return (
shape[k]._zod.optin !== void 0 && shape[k]._zod.optout === "optional"
);
});
}
const NUMBER_FORMAT_RANGES = (() => ({
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
int32: [-2147483648, 2147483647],
uint32: [0, 4294967295],
float32: [-34028234663852886e22, 34028234663852886e22],
float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
}))();
const BIGINT_FORMAT_RANGES = {
int64: [
BigInt("-9223372036854775808"),
BigInt("9223372036854775807"),
],
uint64: [
BigInt(0),
BigInt("18446744073709551615"),
],
};
function pick(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".pick() cannot be used on object schemas containing refinements",
);
const newShape = {};
mirrorShape(newShape, schema, maskedKeys(schema, mask));
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function maskedKeys(schema, mask) {
const raw = sourceShape(schema);
const keys = [];
for (const key of Reflect.ownKeys(mask)) {
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable)
throw new Error(`Unrecognized key: "${String(key)}"`);
if (mask[key]) keys.push(key);
}
return keys;
}
function omit(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(
".omit() cannot be used on object schemas containing refinements",
);
const omitted = new Set(maskedKeys(schema, mask));
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)).filter((key) => !omitted.has(key)),
);
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function extend(schema, shape) {
if (!isPlainObject(shape))
throw new Error("Invalid input to extend: expected a plain object");
const checks = schema._zod.def.checks;
if (checks && checks.length > 0) {
const existingShape = sourceShape(schema);
for (const key of Reflect.ownKeys(shape))
if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0)
throw new Error(
"Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.",
);
}
return clone(
schema,
mergeDefs(schema._zod.def, { shape: extended(schema, shape) }),
);
}
function extended(schema, shape) {
const newShape = {};
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
mirrorProps(newShape, shape);
return newShape;
}
function safeExtend(schema, shape) {
if (!isPlainObject(shape))
throw new Error("Invalid input to safeExtend: expected a plain object");
return clone(
schema,
mergeDefs(schema._zod.def, { shape: extended(schema, shape) }),
);
}
function merge(a, b) {
if (!b?._zod?.def)
throw new Error(
"Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.",
);
if (a._zod.def.checks?.length)
throw new Error(
".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.",
);
const newShape = {};
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
return clone(
a,
mergeDefs(a._zod.def, {
shape: newShape,
get catchall() {
return b._zod.def.catchall;
},
checks: b._zod.def.checks ?? [],
}),
);
}
function partial(Class, schema, mask, name = "partial") {
const checks = schema._zod.def.checks;
if (checks && checks.length > 0)
throw new Error(
`.${name}() cannot be used on object schemas containing refinements`,
);
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
Class &&
((value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "optional",
innerType: value,
})),
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: newShape,
checks: [],
}),
);
}
function required(Class, schema, mask) {
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
(value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "nonoptional",
innerType: value,
}),
);
return clone(schema, mergeDefs(schema._zod.def, { shape: newShape }));
}
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 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 parsedType(data) {
const t = typeof data;
switch (t) {
case "number":
return Number.isNaN(data) ? "nan" : "number";
case "object": {
if (data === null) return "null";
if (Array.isArray(data)) return "array";
const obj = data;
if (
obj &&
Object.getPrototypeOf(obj) !== Object.prototype &&
"constructor" in obj &&
obj.constructor
)
return obj.constructor.name;
}
}
return t;
}
function issue(...args) {
const [iss, input, inst] = args;
if (typeof iss === "string")
return {
message: iss,
code: "custom",
input,
inst,
};
return { ...iss };
}
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 derived(computes, table) {
for (const key in computes) {
const compute = computes[key];
Object.defineProperty(table, key, {
configurable: true,
enumerable: true,
get() {
return own(this, key, compute(this));
},
set(value) {
own(this, key, value);
},
});
}
return table;
}
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,
});
},
});
}
const CONSTANT_CATCH = "~constantCatch";
function constantCatch(value) {
const fn = () => value;
fn[CONSTANT_CATCH] = true;
return fn;
}
var _a$1;
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.`,
);
}
};
var $ZodEncodeError = class extends Error {
constructor(name) {
super(`Encountered unidirectional transform during encode: ${name}`);
this.name = "ZodEncodeError";
}
};
(_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__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$1 = (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 $ZodError = $constructor("$ZodError", initializer$1);
$constructor("$ZodError", initializer$1, void 0, { Parent: Error });
function node(obj, key, make) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
if (key === "__proto__")
Object.defineProperty(obj, key, {
value: make(),
writable: true,
enumerable: true,
configurable: true,
});
else obj[key] = make();
}
return obj[key];
}
function flattenError(error, mapper = (issue) => issue.message) {
const fieldErrors = {};
const formErrors = [];
for (const sub of error.issues)
if (sub.path.length > 0)
node(fieldErrors, sub.path[0], () => []).push(mapper(sub));
else formErrors.push(mapper(sub));
return {
formErrors,
fieldErrors,
};
}
function formatError(error, mapper = (issue) => issue.message) {
const fieldErrors = { _errors: [] };
const processError = (error, path = []) => {
for (const issue of error.issues)
if (issue.code === "invalid_union" && issue.errors.length)
issue.errors.map((issues) =>
processError({ issues }, [...path, ...issue.path]),
);
else if (issue.code === "invalid_key")
processError({ issues: issue.issues }, [...path, ...issue.path]);
else if (issue.code === "invalid_element")
processError({ issues: issue.issues }, [...path, ...issue.path]);
else {
const fullpath = [...path, ...issue.path];
if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
else {
let curr = fieldErrors;
let i = 0;
while (i < fullpath.length) {
const el = fullpath[i];
const terminal = i === fullpath.length - 1;
if (el === "_errors") {
if (terminal) curr._errors.push(mapper(issue));
i++;
continue;
}
if (!Object.prototype.hasOwnProperty.call(curr, el))
Object.defineProperty(curr, el, {
value: { _errors: [] },
enumerable: true,
writable: true,
configurable: true,
});
const node = curr[el];
if (terminal) node._errors.push(mapper(issue));
curr = node;
i++;
}
}
}
};
processError(error);
return fieldErrors;
}
function finalizeParams(callee, params) {
return {
callee: params?.callee ?? callee,
Err: params?.Err,
};
}
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 _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 _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,
};
};
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 COMPILE_INVALID = Symbol.for("zod.compile.invalid");
const COMPILE_FALLBACK = Symbol.for("zod.compile.fallback");
const validate = (schema, value, _ctx) => {
const validator = schema._zod.bag.validator;
if (validator !== void 0) {
if (validator(value) !== COMPILE_INVALID) return true;
if (validator.definite === true && _ctx === void 0) return false;
}
return validateFallback(schema, value, _ctx);
};
function validateFallback(schema, value, _ctx) {
const ctx = _ctx
? {
..._ctx,
async: false,
abortEarly: true,
}
: {
async: false,
abortEarly: true,
};
const fallbackRun = schema._zod.bag.fallbackRun;
let result;
if (fallbackRun) {
ctx[COMPILE_FALLBACK] = true;
result = fallbackRun(
{
value,
issues: [],
},
ctx,
);
} else
result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length === 0;
}
const validateAsync$1 = async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
abortEarly: true,
}
: {
async: true,
abortEarly: true,
};
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length === 0;
};
const _encode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return parse(schema, value, ctx, finalizeParams(fn, _params));
};
return fn;
};
const _decode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
return parse(schema, value, _ctx, finalizeParams(fn, _params));
};
return fn;
};
const _encodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return await parseAsync(schema, value, ctx, finalizeParams(fn, _params));
};
return fn;
};
const _decodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
return await parseAsync(schema, value, _ctx, finalizeParams(fn, _params));
};
return fn;
};
const _safeEncode = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParse(_Err)(schema, value, ctx);
};
const _safeDecode = (_Err) => (schema, value, _ctx) => {
return _safeParse(_Err)(schema, value, _ctx);
};
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParseAsync(_Err)(schema, value, ctx);
};
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
return _safeParseAsync(_Err)(schema, value, _ctx);
};
const cuid = /^[cC][0-9a-z]{6,}$/;
const cuid2 = /^[0-9a-z]+$/;
const ulid = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
const xid = /^[0-9a-vA-V]{20}$/;
const ksuid = /^[A-Za-z0-9]{27}$/;
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
function nanoidOfLength(length) {
return new RegExp(`^[a-zA-Z0-9_-]{${length}}$`);
}
const duration =
/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
const guid =
/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
const uuid = (version) => {
if (!version)
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
return new RegExp(
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`,
);
};
const email =
/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
function emoji() {
return new RegExp(_emoji$1, "u");
}
const ipv4 =
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
const ipv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
const cidrv4 =
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
const cidrv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
const base64 =
/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
const httpProtocol = /^https?$/;
const e164 = /^\+[1-9]\d{6,14}$/;
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
function anchor(source) {
return new RegExp(`^${source}$`);
}
const date$1 = anchor(dateSource);
function timeSource(args) {
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
return typeof args.precision === "number"
? args.precision === -1
? `${hhmm}`
: args.precision === 0
? `${hhmm}:[0-5]\\d`
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
: args.seconds
? `${hhmm}:[0-5]\\d(?:\\.\\d+)?`
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
}
function time(args) {
return new RegExp(`^${timeSource(args)}$`);
}
function datetime(args) {
const opts = ["Z"];
if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
const qualified = `${timeSource({
precision: args.precision,
seconds: true,
})}(?:${opts.join("|")})`;
const timeRegex = args.local
? `${qualified}|${timeSource({ precision: args.precision })}`
: qualified;
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
}
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const lowercase = /^[^A-Z]*$/;
const uppercase = /^[^a-z]*$/;
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 $ZodCheckMultipleOf = $constructor(
"$ZodCheckMultipleOf",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
if (typeof payload.value !== typeof def.value)
throw new Error("Cannot mix number and bigint in multiple_of check.");
if (
typeof payload.value === "bigint"
? def.value !== BigInt(0) && payload.value % def.value === BigInt(0)
: floatSafeRemainder(payload.value, def.value) === 0
)
return;
payload.issues.push({
origin: typeof payload.value,
code: "not_multiple_of",
divisor: def.value,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckNumberFormat = $constructor(
"$ZodCheckNumberFormat",
(inst, def) => {
$ZodCheck.init(inst, def);
def.format = def.format || "float64";
const isInt = def.format?.includes("int");
const origin = isInt ? "int" : "number";
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
inst._zod.check = (payload) => {
const input = payload.value;
if (isInt) {
if (!Number.isInteger(input)) {
payload.issues.push({
expected: origin,
format: def.format,
code: "invalid_type",
continue: false,
input,
inst,
});
return;
}
if (!Number.isSafeInteger(input)) {
if (input > 0)
payload.issues.push({
input,
code: "too_big",
maximum: Number.MAX_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
else
payload.issues.push({
input,
code: "too_small",
minimum: Number.MIN_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
return;
}
}
if (input < minimum)
payload.issues.push({
origin: "number",
input,
code: "too_small",
minimum,
inclusive: true,
inst,
continue: !def.abort,
});
if (input > maximum)
payload.issues.push({
origin: "number",
input,
code: "too_big",
maximum,
inclusive: true,
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 $ZodCheckLengthEquals = $constructor(
"$ZodCheckLengthEquals",
(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;
const length =
typeof input === "string" &&
units >= def.length &&
units <= def.length * 2
? codePointLength(input)
: units;
if (length === def.length) return;
const origin = getLengthableOrigin(input);
const tooBig = length > def.length;
payload.issues.push({
origin,
...(tooBig
? {
code: "too_big",
maximum: def.length,
}
: {
code: "too_small",
minimum: def.length,
}),
inclusive: true,
exact: true,
input: payload.value,
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 $ZodCheckRegex = $constructor(
"$ZodCheckRegex",
(inst, def) => {
$ZodCheckStringFormat.init(inst, def);
inst._zod.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "regex",
input: payload.value,
pattern: def.pattern.toString(),
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckLowerCase = $constructor(
"$ZodCheckLowerCase",
(inst, def) => {
def.pattern ?? (def.pattern = lowercase);
$ZodCheckStringFormat.init(inst, def);
},
);
const $ZodCheckUpperCase = $constructor(
"$ZodCheckUpperCase",
(inst, def) => {
def.pattern ?? (def.pattern = uppercase);
$ZodCheckStringFormat.init(inst, def);
},
);
const $ZodCheckIncludes = $constructor(
"$ZodCheckIncludes",
(inst, def) => {
$ZodCheck.init(inst, def);
const escapedRegex = escapeRegex(def.includes);
def.pattern = new RegExp(
typeof def.position === "number"
? `^.{${def.position},}${escapedRegex}`
: escapedRegex,
);
inst._zod.check = (payload) => {
if (payload.value.includes(def.includes, def.position)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "includes",
includes: def.includes,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckStartsWith = $constructor(
"$ZodCheckStartsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.startsWith(def.prefix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "starts_with",
prefix: def.prefix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckEndsWith = $constructor(
"$ZodCheckEndsWith",
(inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.endsWith(def.suffix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "ends_with",
suffix: def.suffix,
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodCheckOverwrite = $constructor(
"$ZodCheckOverwrite",
(inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
payload.value = def.tx(payload.value);
};
},
);
var Doc = class {
constructor(args = [], closed = {}) {
this.content = [];
this.indent = 0;
this.args = args;
this.closed = closed;
}
indented(fn) {
this.indent += 1;
try {
fn(this);
} finally {
this.indent -= 1;
}
}
write(arg) {
if (typeof arg === "function") {
arg(this, { execution: "sync" });
arg(this, { execution: "async" });
return;
}
const lines = arg.split("\n").filter((x) => x);
const minIndent = Math.min(
...lines.map((x) => x.length - x.trimStart().length),
);
const dedented = lines
.map((x) => x.slice(minIndent))
.map((x) => " ".repeat(this.indent * 2) + x);
for (const line of dedented) this.content.push(line);
}
compile() {
const F = Function;
const content = this?.content ?? [``];
return new F(
...Object.keys(this.closed),
`return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`,
)(...Object.values(this.closed));
}
};
const version = {
major: 4,
minor: 6,
patch: 5,
};
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);
},
);
const $ZodGUID = $constructor("$ZodGUID", (inst, def) => {
def.pattern ?? (def.pattern = guid);
$ZodStringFormat.init(inst, def);
});
const $ZodUUID = $constructor("$ZodUUID", (inst, def) => {
if (def.version) {
const v = {
v1: 1,
v2: 2,
v3: 3,
v4: 4,
v5: 5,
v6: 6,
v7: 7,
v8: 8,
}[def.version];
if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
def.pattern ?? (def.pattern = uuid(v));
} else def.pattern ?? (def.pattern = uuid());
$ZodStringFormat.init(inst, def);
});
const $ZodEmail = $constructor("$ZodEmail", (inst, def) => {
def.pattern ?? (def.pattern = email);
$ZodStringFormat.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 $ZodEmoji = $constructor("$ZodEmoji", (inst, def) => {
def.pattern ?? (def.pattern = emoji());
$ZodStringFormat.init(inst, def);
});
const $ZodNanoID = $constructor("$ZodNanoID", (inst, def) => {
if (
def.length !== void 0 &&
(!Number.isInteger(def.length) || def.length < 1)
)
throw new Error(`Invalid nanoid length: ${def.length}`);
def.pattern ??
(def.pattern = def.length === void 0 ? nanoid : nanoidOfLength(def.length));
$ZodStringFormat.init(inst, def);
});
const $ZodCUID = $constructor("$ZodCUID", (inst, def) => {
def.pattern ?? (def.pattern = cuid);
$ZodStringFormat.init(inst, def);
});
const $ZodCUID2 = $constructor("$ZodCUID2", (inst, def) => {
def.pattern ?? (def.pattern = cuid2);
$ZodStringFormat.init(inst, def);
});
const $ZodULID = $constructor("$ZodULID", (inst, def) => {
def.pattern ?? (def.pattern = ulid);
$ZodStringFormat.init(inst, def);
});
const $ZodXID = $constructor("$ZodXID", (inst, def) => {
def.pattern ?? (def.pattern = xid);
$ZodStringFormat.init(inst, def);
});
const $ZodKSUID = $constructor("$ZodKSUID", (inst, def) => {
def.pattern ?? (def.pattern = ksuid);
$ZodStringFormat.init(inst, def);
});
const $ZodISODateTime = $constructor(
"$ZodISODateTime",
(inst, def) => {
def.pattern ?? (def.pattern = datetime(def));
$ZodStringFormat.init(inst, def);
},
);
const $ZodISODate = $constructor("$ZodISODate", (inst, def) => {
def.pattern ?? (def.pattern = date$1);
$ZodStringFormat.init(inst, def);
});
const $ZodISOTime = $constructor("$ZodISOTime", (inst, def) => {
def.pattern ?? (def.pattern = time(def));
$ZodStringFormat.init(inst, def);
});
const $ZodISODuration = $constructor(
"$ZodISODuration",
(inst, def) => {
def.pattern ?? (def.pattern = duration);
$ZodStringFormat.init(inst, def);
},
);
const $ZodIPv4 = $constructor("$ZodIPv4", (inst, def) => {
def.pattern ?? (def.pattern = ipv4);
$ZodStringFormat.init(inst, def);
});
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
function isValidIPv6(value) {
if (!ipv6Alphabet.test(value)) return false;
return canParseURL(`http://[${value}]`);
}
const $ZodIPv6 = $constructor("$ZodIPv6", (inst, def) => {
def.pattern ?? (def.pattern = ipv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidIPv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "ipv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCIDRv4 = $constructor("$ZodCIDRv4", (inst, def) => {
def.pattern ?? (def.pattern = cidrv4);
$ZodStringFormat.init(inst, def);
});
function isValidCIDRv6(value) {
const parts = value.split("/");
if (parts.length !== 2) return false;
const [address, prefix] = parts;
if (!prefix) return false;
const prefixNum = Number(prefix);
if (`${prefixNum}` !== prefix) return false;
if (prefixNum < 0 || prefixNum > 128) return false;
return isValidIPv6(address);
}
const $ZodCIDRv6 = $constructor("$ZodCIDRv6", (inst, def) => {
def.pattern ?? (def.pattern = cidrv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidCIDRv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "cidrv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
function isValidBase64(data) {
if (data === "") return true;
if (/\s/.test(data)) return false;
if (data.length % 4 !== 0) return false;
try {
atob(data);
return true;
} catch {
return false;
}
}
const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
const $ZodBase64 = $constructor("$ZodBase64", (inst, def) => {
def.pattern ?? (def.pattern = base64Charset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const base64urlCharset = /^[A-Za-z0-9_-]*$/;
function isValidBase64URL(data) {
if (!base64urlCharset.test(data)) return false;
const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
}
const $ZodBase64URL = $constructor(
"$ZodBase64URL",
(inst, def) => {
def.pattern ?? (def.pattern = base64urlCharset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64URL(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64url",
input: payload.value,
inst,
continue: !def.abort,
});
};
},
);
const $ZodE164 = $constructor("$ZodE164", (inst, def) => {
def.pattern ?? (def.pattern = e164);
$ZodStringFormat.init(inst, def);
});
function isValidJWT(token, algorithm = null) {
try {
const tokensParts = token.split(".");
if (tokensParts.length !== 3) return false;
const [header] = tokensParts;
if (!header) return false;
const parsedHeader = JSON.parse(atob(header));
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
if (!parsedHeader.alg) return false;
if (
algorithm &&
(!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)
)
return false;
return true;
} catch {
return false;
}
}
const $ZodJWT = $constructor("$ZodJWT", (inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidJWT(payload.value, def.alg)) return;
payload.issues.push({
code: "invalid_format",
format: "jwt",
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 $ZodNumberFormat = $constructor(
"$ZodNumberFormat",
(inst, def) => {
$ZodCheckNumberFormat.init(inst, def);
$ZodNumber.init(inst, def);
},
);
const $ZodUnknown = $constructor("$ZodUnknown", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload) => payload;
});
const $ZodNever = $constructor("$ZodNever", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
payload.issues.push({
expected: "never",
code: "invalid_type",
input: payload.value,
inst,
});
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 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;
};
});
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$2 = 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$2(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 $ZodObjectJIT = $constructor(
"$ZodObjectJIT",
(inst, def) => {
$ZodObject.init(inst, def);
const superParse = inst._zod.parse;
const _normalized = cached(() => normalizeDef(def));
const memo = globalConfig.memoizer;
const generateFastpass = (shape) => {
const normalized = _normalized.value;
const syms = normalized.symbolKeys;
const doc = new Doc(["payload", "ctx"], {
shape,
inst,
memo,
syms,
});
const parseStr = (k) =>
`shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
const prefixStr = (id, k) => `
let ${id}_ab = false;
for (let i = 0; i < ${id}.issues.length; i++) {
const iss = ${id}.issues[i];
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
payload.issues.push(iss);
if (iss.continue !== true) ${id}_ab = true;
}
if (${id}_ab && ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}`;
doc.write(`const input = payload.value;`);
const ids = Object.create(null);
let counter = 0;
for (const key of normalized.allKeys) ids[key] = `key_${counter++}`;
doc.write(
memo
? `const newResult = memo.alloc(inst, payload, {}, ctx);`
: `const newResult = {};`,
);
for (const key of normalized.allKeys) {
if (key === "__proto__") continue;
const id = ids[key];
const k =
typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc(key);
const isPresent = `${k} in input`;
const schema = shape[key];
const optin = schema?._zod?.optin;
const isOptionalIn = optin !== void 0;
const isOptionalOut = schema?._zod?.optout === "optional";
doc.write(`const ${id} = ${parseStr(k)};`);
if (isOptionalIn && isOptionalOut) {
const assign =
optin === "optional"
? `${id}_present`
: `${id}.value !== undefined || ${id}_present`;
doc.write(`
const ${id}_present = ${isPresent};
if (!${id}.issues.length || ${id}_present) {
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (${assign}) {
newResult[${k}] = ${id}.value;
}
}
`);
} else if (!isOptionalIn)
doc.write(`
const ${id}_present = ${isPresent};
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (!${id}_present && !${id}.issues.length) {
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [${k}]
});
if (ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}
}
if (${id}_present) {
newResult[${k}] = ${id}.value;
}
`);
else {
doc.write(`
if (${id}.issues.length) {${prefixStr(id, k)}
}
`);
if (optin === "defaulted")
doc.write(`newResult[${k}] = ${id}.value;`);
else
doc.write(`
if (${id}.value !== undefined || ${isPresent}) {
newResult[${k}] = ${id}.value;
}
`);
}
}
doc.write(`payload.value = newResult;`);
doc.write(`return payload;`);
return doc.compile();
};
let fastpass;
const isObject$1 = isObject;
const jit = !globalConfig.jitless;
const fastEnabled = jit && allowsEval.value;
const catchall = def.catchall;
let value;
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;
}
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
if (!fastpass) fastpass = generateFastpass(def.shape);
payload = fastpass(payload, ctx);
if (!catchall) return payload;
return handleCatchall(
[],
input,
payload,
ctx,
value,
inst,
ctx?.abortEarly === true,
);
}
return superParse(payload, ctx);
};
},
);
function handleUnionResults(results, final, inst, ctx) {
for (const result of results)
if (result.issues.length === 0) {
final.value = result.value;
return final;
}
const nonaborted = results.filter((r) => !aborted(r));
if (nonaborted.length === 1) {
final.value = nonaborted[0].value;
return nonaborted[0];
}
final.issues.push({
code: "invalid_union",
input: final.value,
inst,
errors: results.map((result) =>
result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
),
});
return final;
}
const $ZodUnion = $constructor("$ZodUnion", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.options.some((o) => o._zod.optin === "defaulted")
? "defaulted"
: zod.def.options.some((o) => o._zod.optin !== void 0)
? "optional"
: void 0,
);
defineLazyInternal(inst, "optout", (zod) =>
zod.def.options.some((o) => o._zod.optout === "optional")
? "optional"
: void 0,
);
defineLazyInternal(inst, "values", (zod) => {
if (zod.def.options.every((o) => o._zod.values))
return new Set(
zod.def.options.flatMap((option) => Array.from(option._zod.values)),
);
});
defineLazyInternal(inst, "pattern", (zod) => {
if (zod.def.options.every((o) => o._zod.pattern)) {
const patterns = zod.def.options.map((o) => o._zod.pattern);
return new RegExp(
`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`,
);
}
});
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
inst._zod.parse = (payload, ctx) => {
if (first) return first(payload, ctx);
let async = false;
const results = [];
for (const option of def.options) {
const result = option._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise) {
results.push(result);
async = true;
} else {
if (result.issues.length === 0) return result;
results.push(result);
}
}
if (!async) return handleUnionResults(results, payload, inst, ctx);
return Promise.all(results).then((results) => {
return handleUnionResults(results, payload, inst, ctx);
});
};
});
const $ZodIntersection = $constructor(
"$ZodIntersection",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
const left = def.left._zod.run(
{
value: input,
issues: [],
},
ctx,
);
const right = def.right._zod.run(
{
value: input,
issues: [],
},
ctx,
);
if (left instanceof Promise || right instanceof Promise)
return Promise.all([left, right]).then(([left, right]) => {
return handleIntersectionResults(payload, left, right);
});
return handleIntersectionResults(payload, left, right);
};
},
);
function mergeValues(a, b) {
if (a === b)
return {
valid: true,
data: a,
};
if (a instanceof Date && b instanceof Date && +a === +b)
return {
valid: true,
data: a,
};
if (isPlainObject(a) && isPlainObject(b)) {
const bKeys = Object.keys(b);
const sharedKeys = Object.keys(a).filter(
(key) => bKeys.indexOf(key) !== -1,
);
const newObj = {
...a,
...b,
};
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__"))
delete newObj.__proto__;
for (const key of sharedKeys) {
if (key === "__proto__") continue;
const sharedValue = mergeValues(a[key], b[key]);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
};
newObj[key] = sharedValue.data;
}
return {
valid: true,
data: newObj,
};
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length)
return {
valid: false,
mergeErrorPath: [],
};
const newArray = [];
for (let index = 0; index < a.length; index++) {
const itemA = a[index];
const itemB = b[index];
const sharedValue = mergeValues(itemA, itemB);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
};
newArray.push(sharedValue.data);
}
return {
valid: true,
data: newArray,
};
}
return {
valid: false,
mergeErrorPath: [],
};
}
function handleIntersectionResults(result, left, right) {
const unrecKeys = new Map();
let unrecIssue;
const keyIssues = new Map();
const collect = (iss, side) => {
let keys;
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
unrecIssue ?? (unrecIssue = iss);
keys = iss.keys;
} else if (
iss.code === "invalid_key" &&
iss.origin === "record" &&
iss.path?.length === 1
) {
const k = String(iss.path[0]);
if (!keyIssues.has(k)) keyIssues.set(k, iss);
keys = [k];
} else return false;
for (const k of keys) {
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
unrecKeys.get(k)[side] = true;
}
return true;
};
for (const iss of left.issues)
if (!collect(iss, "l")) result.issues.push(iss);
for (const iss of right.issues)
if (!collect(iss, "r")) result.issues.push(iss);
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
if (bothKeys.length) {
const aggregated = unrecIssue
? bothKeys.filter((k) => unrecIssue.keys.includes(k))
: [];
if (aggregated.length)
result.issues.push({
...unrecIssue,
keys: aggregated,
});
for (const k of bothKeys)
if (!aggregated.includes(k) && keyIssues.has(k))
result.issues.push(keyIssues.get(k));
}
const merged = mergeValues(left.value, right.value);
if (!merged.valid) {
if (aborted(result)) return result;
throw new Error(
`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`,
);
}
result.value = merged.data;
return result;
}
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 $ZodTransform = $constructor(
"$ZodTransform",
(inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "optional";
globalConfig.memoizer?.guard(inst);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
throw new $ZodEncodeError(inst.constructor.name);
const _out = def.transform(payload.value, payload);
if (ctx.async)
return (_out instanceof Promise ? _out : Promise.resolve(_out)).then(
(output) => {
payload.value = output;
return payload;
},
);
if (_out instanceof Promise) throw new $ZodAsyncError();
payload.value = _out;
return payload;
};
},
);
function handleOptionalResult(payload, result) {
payload.value = result.issues.length ? void 0 : result.value;
return payload;
}
const $ZodOptional = $constructor("$ZodOptional", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional",
);
inst._zod.optout = "optional";
defineLazyInternal(inst, "values", (zod) => {
const values = zod.def.innerType._zod.values;
return values ? new Set([...values, void 0]) : void 0;
});
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === void 0) {
if (def.innerType._zod.optin !== "defaulted") return payload;
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) => handleOptionalResult(payload, result));
return handleOptionalResult(payload, result);
}
return def.innerType._zod.run(payload, ctx);
};
});
const $ZodExactOptional = $constructor(
"$ZodExactOptional",
(inst, def) => {
$ZodOptional.init(inst, def);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
defineLazyInternal(
inst,
"pattern",
(zod) => zod.def.innerType._zod.pattern,
);
inst._zod.parse = (payload, ctx) => {
return def.innerType._zod.run(payload, ctx);
};
},
);
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);
};
});
const $ZodDefault = $constructor("$ZodDefault", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0) {
payload.value = def.defaultValue;
return payload;
}
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((result) => handleDefaultResult(result, def));
return handleDefaultResult(result, def);
};
});
function handleDefaultResult(payload, def) {
if (payload.value === void 0) payload.value = def.defaultValue;
return payload;
}
const $ZodPrefault = $constructor("$ZodPrefault", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0) payload.value = def.defaultValue;
return def.innerType._zod.run(payload, ctx);
};
});
const $ZodNonOptional = $constructor(
"$ZodNonOptional",
(inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "values", (zod) => {
const v = zod.def.innerType._zod.values;
return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
});
inst._zod.parse = (payload, ctx) => {
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((result) => handleNonOptionalResult(result, inst));
return handleNonOptionalResult(result, inst);
};
},
);
function handleNonOptionalResult(payload, inst) {
if (!payload.issues.length && payload.value === void 0)
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: payload.value,
inst,
});
return payload;
}
function handleCatchResult(payload, result, def, ctx) {
if (!result.issues.length) {
payload.value = result.value;
if (result.memo) payload.memo = true;
return payload;
}
payload.value = def.catchValue({
...result,
value: payload.value,
error: {
issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
},
input: payload.value,
});
return payload;
}
const $ZodCatch = $constructor("$ZodCatch", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional",
);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) =>
handleCatchResult(payload, result, def, ctx),
);
return handleCatchResult(payload, result, def, ctx);
};
});
const $ZodPipe = $constructor("$ZodPipe", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
const right = def.out._zod.run(payload, ctx);
if (right instanceof Promise)
return right.then((right) => handlePipeResult(right, def.in, ctx));
return handlePipeResult(right, def.in, ctx);
}
const left = def.in._zod.run(payload, ctx);
if (left instanceof Promise)
return left.then((left) => handlePipeResult(left, def.out, ctx));
return handlePipeResult(left, def.out, ctx);
};
});
function handlePipeResult(left, next, ctx) {
if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
left.aborted = true;
return left;
}
return next._zod.run(
{
value: left.value,
issues: left.issues,
},
ctx,
);
}
const $ZodReadonly = $constructor("$ZodReadonly", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(
inst,
"propValues",
(zod) => zod.def.innerType._zod.propValues,
);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward")
return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) return result.then(handleReadonlyResult);
return handleReadonlyResult(result);
};
});
function handleReadonlyResult(payload) {
if (!payload.memo) payload.value = Object.freeze(payload.value);
return payload;
}
const $ZodCustom = $constructor("$ZodCustom", (inst, def) => {
$ZodCheck.init(inst, def);
$ZodType.init(inst, def);
inst._zod.parse = (payload, _) => {
return payload;
};
inst._zod.check = (payload) => {
const input = payload.value;
const r = def.fn(input);
if (r instanceof Promise)
return r.then((r) => handleRefineResult(r, payload, input, inst));
handleRefineResult(r, payload, input, inst);
};
});
function handleRefineResult(result, payload, input, inst) {
if (!result) {
const _iss = {
code: "custom",
input,
inst,
path: [...(inst._zod.def.path ?? [])],
continue: !inst._zod.def.abort,
};
if (inst._zod.def.params) _iss.params = inst._zod.def.params;
payload.issues.push(issue(_iss));
}
}
var $ZodCyclicError = class extends Error {
constructor() {
super(`Cannot parse a reference cycle that closes through a transform`);
this.name = "ZodCyclicError";
}
};
const STATE = "~memo";
const NO_ISSUES = [];
function isRef(value) {
return value !== null && typeof value === "object";
}
function cloneIssues(issues) {
return issues.map((iss) =>
iss.path
? {
...iss,
path: iss.path.slice(),
}
: { ...iss },
);
}
const recursive = new WeakMap();
const NONE = 0;
const ASSUMED = 1;
const PROVEN = 2;
function isRecursive(inst, stack, resolve) {
const cached = recursive.get(inst);
if (cached !== void 0) return cached ? PROVEN : NONE;
if (stack.has(inst)) return PROVEN;
stack.add(inst);
let result = NONE;
const check = (child) => {
if (result !== PROVEN && child?._zod) {
const answer = isRecursive(child, stack, resolve);
if (answer > result) result = answer;
}
};
const shape = (sh, spread) => {
let answer = NONE;
for (const key of Reflect.ownKeys(sh)) {
const desc = Object.getOwnPropertyDescriptor(sh, key);
if (spread && !desc.enumerable) continue;
const child = desc.get
? ASSUMED
: desc.value?._zod
? isRecursive(desc.value, stack, resolve)
: NONE;
if (child > answer) answer = child;
}
return answer;
};
const merge = (answer) => {
if (answer > result) result = answer;
};
const def = inst._zod.def;
switch (def.type) {
case "object": {
const raw = rawShape(def);
merge(raw ? shape(raw, true) : ASSUMED);
check(def.catchall);
break;
}
case "array":
check(def.element);
break;
case "tuple":
for (const el of def.items) check(el);
check(def.rest);
break;
case "record":
case "map":
check(def.keyType);
check(def.valueType);
break;
case "set":
check(def.valueType);
break;
case "union":
for (const el of def.options) check(el);
break;
case "intersection":
check(def.left);
check(def.right);
break;
case "optional":
case "nullable":
case "default":
case "prefault":
case "catch":
case "readonly":
case "nonoptional":
case "promise":
case "success":
check(def.innerType);
break;
case "pipe":
check(def.in);
check(def.out);
break;
case "function":
check(def.input);
check(def.output);
break;
case "lazy": {
const inner =
def._cachedInner ?? (resolve ? inst._zod.innerType : void 0);
merge(inner ? isRecursive(inner, stack, false) : ASSUMED);
break;
}
case "template_literal":
case "string":
case "number":
case "int":
case "boolean":
case "bigint":
case "symbol":
case "undefined":
case "null":
case "void":
case "never":
case "any":
case "unknown":
case "date":
case "nan":
case "enum":
case "literal":
case "file":
case "transform":
case "custom":
break;
default:
for (const key in def) {
const desc = Object.getOwnPropertyDescriptor(def, key);
if (!desc || desc.get) continue;
const value = desc.value;
if (!value || typeof value !== "object") continue;
if (value._zod) check(value);
else if (Array.isArray(value)) for (const el of value) check(el);
}
}
stack.delete(inst);
return settle(inst, result);
}
function settle(inst, answer) {
if (answer !== ASSUMED) recursive.set(inst, answer === PROVEN);
return answer;
}
function bucketFor(state, inst) {
let bucket = state.buckets.get(inst);
if (!bucket) {
bucket = new WeakMap();
state.buckets.set(inst, bucket);
}
return bucket;
}
let handoff;
const open = [];
const memo = {
alloc(_inst, payload, empty) {
const bucket = handoff;
if (!bucket) return empty;
handoff = void 0;
const entry = {
value: empty,
issues: null,
};
bucket.set(payload.value, entry);
open.push(entry);
return empty;
},
guard(inst) {
var _a;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (ctx.direction !== "backward" && isBackEdge(ctx, payload.value))
throw new $ZodCyclicError();
return base(payload, ctx);
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
attach(inst) {
var _a;
let isRecursiveInst;
let rechecked = false;
let lastCtx;
let lastBucket;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (isRecursiveInst === void 0) {
const walked = isRecursive(inst, new Set(), false);
if (walked === NONE) {
inst._zod.parse = base;
if (inst._zod.run === wrapped) inst._zod.run = base;
return base(payload, ctx);
}
if (walked === PROVEN || rechecked) isRecursiveInst = true;
else rechecked = true;
}
const input = payload.value;
if (!isRef(input)) return base(payload, ctx);
let state = ctx[STATE];
if (!state) {
state = {
buckets: new WeakMap(),
backEdges: void 0,
};
ctx[STATE] = state;
}
let bucket;
if (lastCtx === ctx) bucket = lastBucket;
else {
bucket = bucketFor(state, inst);
lastCtx = ctx;
lastBucket = bucket;
}
const hit = bucket.get(input);
if (hit) {
payload.value = hit.value;
if (hit.issues) {
if (hit.issues.length)
payload.issues.push(...cloneIssues(hit.issues));
} else {
payload.memo = true;
state.backEdges ??
(state.backEdges = new WeakSet());
state.backEdges.add(hit.value);
}
return payload;
}
handoff = bucket;
const depth = open.length;
const result = base(payload, ctx);
handoff = void 0;
const entry = open.length > depth ? open.pop() : void 0;
if (result instanceof Promise)
return result.then((r) => {
if (entry)
entry.issues = r.issues.length
? cloneIssues(r.issues)
: NO_ISSUES;
return r;
});
if (entry)
entry.issues = result.issues.length
? cloneIssues(result.issues)
: NO_ISSUES;
return result;
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
};
function memoizer() {
return memo;
}
function isBackEdge(ctx, value) {
const backEdges = ctx[STATE]?.backEdges;
return backEdges !== void 0 && isRef(value) && backEdges.has(value);
}
const error = () => {
const Sizable = {
string: {
unit: "characters",
verb: "to have",
},
file: {
unit: "bytes",
verb: "to have",
},
array: {
unit: "items",
verb: "to have",
},
set: {
unit: "items",
verb: "to have",
},
map: {
unit: "entries",
verb: "to have",
},
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const FormatDictionary = {
regex: "input",
email: "email address",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO datetime",
date: "ISO date",
time: "ISO time",
duration: "ISO duration",
ipv4: "IPv4 address",
ipv6: "IPv6 address",
mac: "MAC address",
cidrv4: "IPv4 range",
cidrv6: "IPv6 range",
base64: "base64-encoded string",
base64url: "base64url-encoded string",
json_string: "JSON string",
e164: "E.164 number",
currency_code: "currency code",
credit_card: "credit card number",
iban: "IBAN",
jwt: "JWT",
template_literal: "input",
};
const TypeDictionary = { nan: "NaN" };
function getTypeName(type, input) {
if (
type === "number" &&
typeof input === "number" &&
!Number.isFinite(input)
)
return String(input);
return TypeDictionary[type] ?? type;
}
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `Invalid input: expected ${getTypeName(issue.expected)}, received ${getTypeName(parsedType(issue.input), issue.input)}`;
case "invalid_value":
if (issue.values.length === 1)
return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.exact ? "exactly " : issue.inclusive ? "<=" : "<";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.exact ? "exactly " : issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
if (_issue.format === "starts_with")
return `Invalid string: must start with "${_issue.prefix}"`;
if (_issue.format === "ends_with")
return `Invalid string: must end with "${_issue.suffix}"`;
if (_issue.format === "includes")
return `Invalid string: must include "${_issue.includes}"`;
if (_issue.format === "regex")
return `Invalid string: must match pattern ${_issue.pattern}`;
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `Invalid number: must be a multiple of ${issue.divisor}`;
case "unrecognized_keys":
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Invalid key in ${issue.origin}`;
case "invalid_union":
if (
issue.options &&
Array.isArray(issue.options) &&
issue.options.length > 0
)
return `Invalid discriminator value. Expected ${issue.options.map((o) => `'${o}'`).join(" | ")}`;
if (issue.inclusive === false)
return "Invalid input: more than one option matched";
return "Invalid input";
case "invalid_element":
return `Invalid value in ${issue.origin}`;
default:
return `Invalid input`;
}
};
};
function en_default() {
return { localeError: error() };
}
var _a;
var $ZodRegistry = class {
constructor() {
this._map = new WeakMap();
this._idmap = new Map();
}
add(schema, ..._meta) {
const meta = _meta[0];
this._map.set(schema, meta);
if (meta && typeof meta === "object" && "id" in meta)
this._idmap.set(meta.id, schema);
return this;
}
clear() {
this._map = new WeakMap();
this._idmap = new Map();
return this;
}
remove(schema) {
const meta = this._map.get(schema);
if (meta && typeof meta === "object" && "id" in meta)
this._idmap.delete(meta.id);
this._map.delete(schema);
return this;
}
get(schema) {
const p = schema._zod.parent;
if (p) {
const pm = { ...(this.get(p) ?? {}) };
delete pm.id;
const f = {
...pm,
...this._map.get(schema),
};
return Object.keys(f).length ? f : void 0;
}
return this._map.get(schema);
}
has(schema) {
return this._map.has(schema);
}
};
function registry() {
return new $ZodRegistry();
}
(_a = globalThis).__zod_globalRegistry ??
(_a.__zod_globalRegistry = registry());
const globalRegistry = globalThis.__zod_globalRegistry;
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 _email(Class, params) {
return new Class({
type: "string",
format: "email",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _guid(Class, params) {
return new Class({
type: "string",
format: "guid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuid(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuidv4(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v4",
...normalizeParams(params),
});
}
function _uuidv6(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v6",
...normalizeParams(params),
});
}
function _uuidv7(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v7",
...normalizeParams(params),
});
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _emoji(Class, params) {
return new Class({
type: "string",
format: "emoji",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _nanoid(Class, params) {
return new Class({
type: "string",
format: "nanoid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid(Class, params) {
return new Class({
type: "string",
format: "cuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid2(Class, params) {
return new Class({
type: "string",
format: "cuid2",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ulid(Class, params) {
return new Class({
type: "string",
format: "ulid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _xid(Class, params) {
return new Class({
type: "string",
format: "xid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ksuid(Class, params) {
return new Class({
type: "string",
format: "ksuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv4(Class, params) {
return new Class({
type: "string",
format: "ipv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv6(Class, params) {
return new Class({
type: "string",
format: "ipv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv4(Class, params) {
return new Class({
type: "string",
format: "cidrv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv6(Class, params) {
return new Class({
type: "string",
format: "cidrv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64(Class, params) {
return new Class({
type: "string",
format: "base64",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64url(Class, params) {
return new Class({
type: "string",
format: "base64url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _e164(Class, params) {
return new Class({
type: "string",
format: "e164",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _jwt(Class, params) {
return new Class({
type: "string",
format: "jwt",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _isoDateTime(Class, params) {
return new Class({
type: "string",
format: "datetime",
check: "string_format",
offset: false,
local: false,
precision: null,
...normalizeParams(params),
});
}
function _isoDate(Class, params) {
return new Class({
type: "string",
format: "date",
check: "string_format",
...normalizeParams(params),
});
}
function _isoTime(Class, params) {
return new Class({
type: "string",
format: "time",
check: "string_format",
precision: null,
...normalizeParams(params),
});
}
function _isoDuration(Class, params) {
return new Class({
type: "string",
format: "duration",
check: "string_format",
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _int(Class, params) {
return new Class({
type: "number",
check: "number_format",
abort: false,
format: "safeint",
...normalizeParams(params),
});
}
function _unknown(Class) {
return new Class({ type: "unknown" });
}
function _never(Class, params) {
return new Class({
type: "never",
...normalizeParams(params),
});
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lt(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gt(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _multipleOf(value, params) {
return new $ZodCheckMultipleOf({
check: "multiple_of",
...normalizeParams(params),
value,
});
}
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,
});
}
function _length(length, params) {
return new $ZodCheckLengthEquals({
check: "length_equals",
...normalizeParams(params),
length,
});
}
function _regex(pattern, params) {
return new $ZodCheckRegex({
check: "string_format",
format: "regex",
...normalizeParams(params),
pattern,
});
}
function _lowercase(params) {
return new $ZodCheckLowerCase({
check: "string_format",
format: "lowercase",
...normalizeParams(params),
});
}
function _uppercase(params) {
return new $ZodCheckUpperCase({
check: "string_format",
format: "uppercase",
...normalizeParams(params),
});
}
function _includes(includes, params) {
return new $ZodCheckIncludes({
check: "string_format",
format: "includes",
...normalizeParams(params),
includes,
});
}
function _startsWith(prefix, params) {
return new $ZodCheckStartsWith({
check: "string_format",
format: "starts_with",
...normalizeParams(params),
prefix,
});
}
function _endsWith(suffix, params) {
return new $ZodCheckEndsWith({
check: "string_format",
format: "ends_with",
...normalizeParams(params),
suffix,
});
}
function _overwrite(tx) {
return new $ZodCheckOverwrite({
check: "overwrite",
tx,
});
}
function _normalize(form) {
return _overwrite((input) => input.normalize(form));
}
function _trim() {
return _overwrite((input) => input.trim());
}
function _toLowerCase() {
return _overwrite((input) => input.toLowerCase());
}
function _toUpperCase() {
return _overwrite((input) => input.toUpperCase());
}
function _slugify() {
return _overwrite((input) => slugify(input));
}
function _array(Class, element, params) {
return new Class({
type: "array",
element,
...normalizeParams(params),
});
}
function _refine(Class, fn, _params) {
return new Class({
type: "custom",
check: "custom",
fn,
...normalizeParams(_params),
});
}
function _superRefine(fn, params) {
const ch = _check((payload) => {
payload.addIssue = (issue$2) => {
if (typeof issue$2 === "string")
payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
else {
const _issue = issue$2;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue)) _issue.input = payload.value;
_issue.inst ?? (_issue.inst = ch);
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
payload.issues.push(issue(_issue));
}
};
return fn(payload.value, payload);
}, params);
return ch;
}
function _check(fn, params) {
const ch = new $ZodCheck({
check: "custom",
...normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
function assignProps(target, ...sources) {
for (const source of sources)
for (const key of Reflect.ownKeys(source))
if (Object.prototype.propertyIsEnumerable.call(source, key))
assignProp(target, key, source[key]);
return target;
}
function initializeContext(params) {
let target = params?.target ?? "draft-2020-12";
if (target === "draft-4") target = "draft-04";
if (target === "draft-7") target = "draft-07";
return {
processors: params.processors ?? {},
metadataRegistry: params?.metadata ?? globalRegistry,
target,
unrepresentable: params?.unrepresentable ?? "throw",
override: params?.override ?? (() => {}),
io: params?.io ?? "output",
counter: 0,
seen: new Map(),
sharedDefsExtractedFor: void 0,
sharedEmitDoneFor: void 0,
cycles: params?.cycles ?? "ref",
reused: params?.reused ?? "inline",
intersections: [],
deferred: [],
external: params?.external ?? void 0,
};
}
function handleUnrepresentable(schema, ctx, json, params, message) {
const result =
typeof ctx.unrepresentable === "function"
? ctx.unrepresentable({
zodSchema: schema,
path: params.path,
message,
})
: ctx.unrepresentable;
if (result === "any") return false;
if (result === void 0 || result === "throw") throw new Error(message);
Object.assign(json, result);
return true;
}
function processSchema(
schema,
ctx,
_params = {
path: [],
schemaPath: [],
},
) {
var _a;
const def = schema._zod.def;
const seen = ctx.seen.get(schema);
if (seen) {
seen.count++;
if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
return seen.schema;
}
const result = {
schema: {},
count: 1,
cycle: void 0,
path: _params.path,
};
ctx.seen.set(schema, result);
ctx.sharedDefsExtractedFor = void 0;
ctx.sharedEmitDoneFor = void 0;
const overrideSchema = schema._zod.toJSONSchema?.();
if (overrideSchema) result.schema = overrideSchema;
else {
const params = {
..._params,
schemaPath: [..._params.schemaPath, schema],
path: _params.path,
};
if (schema._zod.processJSONSchema)
schema._zod.processJSONSchema(ctx, result.schema, params);
else {
const _json = result.schema;
const processor = ctx.processors[def.type];
if (!processor)
throw new Error(
`[toJSONSchema]: Non-representable type encountered: ${def.type}`,
);
processor(schema, ctx, _json, params);
}
const parent = schema._zod.parent;
if (parent) {
if (!result.ref) result.ref = parent;
processSchema(parent, ctx, params);
ctx.seen.get(parent).isParent = true;
}
}
const meta = ctx.metadataRegistry.get(schema);
if (meta) assignProps(result.schema, meta);
if (ctx.io === "input" && isTransforming(schema)) {
delete result.schema.examples;
delete result.schema.default;
}
if (ctx.io === "input" && "_prefault" in result.schema)
(_a = result.schema).default ?? (_a.default = result.schema._prefault);
delete result.schema._prefault;
return ctx.seen.get(schema).schema;
}
function encodeJSONPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function extractDefs(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
if (ctx.external && ctx.sharedDefsExtractedFor === ctx.external) return;
const idToSchema = new Map();
for (const entry of ctx.seen.entries()) {
const id = ctx.metadataRegistry.get(entry[0])?.id;
if (id) {
const existing = idToSchema.get(id);
if (existing && existing !== entry[0])
throw new Error(
`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`,
);
idToSchema.set(id, entry[0]);
}
}
const makeURI = (entry) => {
const defsSegment =
ctx.target === "draft-2020-12" ? "$defs" : "definitions";
if (ctx.external) {
const externalId = ctx.external.registry.get(entry[0])?.id;
const uriGenerator = ctx.external.uri ?? ((id) => id);
if (externalId) return { ref: uriGenerator(externalId) };
const id =
entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
entry[1].defId = id;
return {
defId: id,
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`,
};
}
const uriPrefix = `#`;
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
if (entry[1] === root && !entry[1].schema.id) return { ref: uriPrefix };
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
return {
defId,
ref: defUriPrefix + encodeJSONPointerSegment(defId),
};
};
const extractToDef = (entry) => {
if (entry[1].schema.$ref) return;
const seen = entry[1];
const { ref, defId } = makeURI(entry);
seen.def = { ...seen.schema };
if (defId) seen.defId = defId;
const schema = seen.schema;
for (const key in schema) delete schema[key];
schema.$ref = ref;
};
if (ctx.cycles === "throw")
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.cycle)
throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
}
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (schema === entry[0]) {
extractToDef(entry);
continue;
}
if (ctx.external) {
const ext = ctx.external.registry.get(entry[0])?.id;
if (schema !== entry[0] && ext) {
extractToDef(entry);
continue;
}
}
if (ctx.metadataRegistry.get(entry[0])?.id) {
extractToDef(entry);
continue;
}
if (seen.cycle) {
extractToDef(entry);
continue;
}
if (seen.count > 1) {
if (ctx.reused === "ref") extractToDef(entry);
}
}
if (ctx.external) ctx.sharedDefsExtractedFor = ctx.external;
}
function compactTypeUnion(schema) {
const options = schema.anyOf;
if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0)
return;
const types = [];
for (const option of options) {
if (!option || typeof option !== "object") return;
compactTypeUnion(option);
const keys = Object.keys(option);
if (keys.length !== 1 || keys[0] !== "type") return;
const type = option.type;
for (const member of Array.isArray(type) ? type : [type]) {
if (typeof member !== "string") return;
if (!types.includes(member)) types.push(member);
}
}
delete schema.anyOf;
schema.type = types.length === 1 ? types[0] : types;
}
const FOLDABLE_KEYS = new Set([
"type",
"properties",
"required",
"additionalProperties",
]);
const UNION_KEYS = ["oneOf", "anyOf"];
function undeclaredConstraint(member) {
const extra = member.additionalProperties;
if (
extra === void 0 ||
extra === false ||
typeof extra !== "object" ||
extra === null
)
return null;
return Object.keys(extra).length ? extra : null;
}
function foldObjects(members) {
const objects = [];
for (const member of members) {
if (typeof member !== "object" || member.type !== "object") return null;
for (const key in member) if (!FOLDABLE_KEYS.has(key)) return null;
objects.push(member);
}
const properties = {};
const required = new Set();
for (const object of objects) {
for (const key in object.properties) {
if (Object.prototype.hasOwnProperty.call(properties, key)) continue;
const parts = [];
for (const other of objects) {
const part = other.properties?.[key] ?? undeclaredConstraint(other);
if (part === null || part === void 0) continue;
if (
!parts.some((seen) => JSON.stringify(seen) === JSON.stringify(part))
)
parts.push(part);
}
assignProp(
properties,
key,
parts.length === 1
? parts[0]
: (foldObjects(parts) ?? { allOf: parts }),
);
}
for (const key of object.required ?? []) required.add(key);
}
const folded = {
type: "object",
properties,
};
if (required.size) folded.required = [...required];
if (objects.every((object) => object.additionalProperties === false))
folded.additionalProperties = false;
else {
const constraints = [];
for (const object of objects) {
const constraint = undeclaredConstraint(object);
if (
constraint &&
!constraints.some(
(seen) => JSON.stringify(seen) === JSON.stringify(constraint),
)
)
constraints.push(constraint);
}
if (constraints.length === 1) folded.additionalProperties = constraints[0];
else if (constraints.length > 1)
folded.additionalProperties = { allOf: constraints };
}
return folded;
}
function foldIntersection(json) {
const allOf = json.allOf;
if (!Array.isArray(allOf) || allOf.length < 2) return;
for (const key of FOLDABLE_KEYS) if (key in json) return;
const unions = allOf.filter((m) =>
UNION_KEYS.some((k) => Array.isArray(m[k])),
);
let folded = null;
if (!unions.length) folded = foldObjects(allOf);
else {
const union = unions[0];
const keyword = UNION_KEYS.find((k) => Array.isArray(union[k]));
if (Object.keys(union).length !== 1) return;
const rest = allOf.filter((m) => m !== union);
const branches = union[keyword].map((branch) =>
foldObjects([...rest, branch]),
);
if (branches.some((b) => !b)) return;
folded = { [keyword]: branches };
}
if (!folded) return;
delete json.allOf;
assignProps(json, folded);
}
function finalize(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
const flattenRef = (zodSchema) => {
const seen = ctx.seen.get(zodSchema);
if (seen.ref === null) return;
const schema = seen.def ?? seen.schema;
const _cached = { ...schema };
const ref = seen.ref;
seen.ref = null;
if (ref) {
flattenRef(ref);
const refSeen = ctx.seen.get(ref);
const refSchema = refSeen.schema;
if (
refSchema.$ref &&
(ctx.target === "draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0")
) {
schema.allOf = schema.allOf ?? [];
schema.allOf.push(refSchema);
} else assignProps(schema, refSchema);
assignProps(schema, _cached);
if (zodSchema._zod.parent === ref)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (!(key in _cached)) delete schema[key];
}
if (refSchema.$ref && refSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in refSeen.def &&
JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])
)
delete schema[key];
}
}
const parent = zodSchema._zod.parent;
if (parent && parent !== ref) {
flattenRef(parent);
const parentSeen = ctx.seen.get(parent);
if (parentSeen?.schema.$ref) {
schema.$ref = parentSeen.schema.$ref;
if (parentSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in parentSeen.def &&
JSON.stringify(schema[key]) ===
JSON.stringify(parentSeen.def[key])
)
delete schema[key];
}
}
}
ctx.override({
zodSchema,
jsonSchema: schema,
path: seen.path ?? [],
});
};
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) {
for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
if (ctx.target !== "openapi-3.0")
for (const entry of ctx.seen.entries())
compactTypeUnion(entry[1].def ?? entry[1].schema);
for (const rewrite of ctx.deferred) rewrite();
if (ctx.intersections.length) {
const carriers = new Map();
for (const seen of ctx.seen.values())
for (const json of [seen.schema, seen.def]) {
const allOf = json?.allOf;
if (!Array.isArray(allOf)) continue;
const existing = carriers.get(allOf);
if (existing) existing.push(json);
else carriers.set(allOf, [json]);
}
for (const allOf of ctx.intersections)
for (const json of carriers.get(allOf) ?? []) foldIntersection(json);
}
}
const result = {};
if (ctx.target === "draft-2020-12")
result.$schema = "https://json-schema.org/draft/2020-12/schema";
else if (ctx.target === "draft-07")
result.$schema = "http://json-schema.org/draft-07/schema#";
else if (ctx.target === "draft-04")
result.$schema = "http://json-schema.org/draft-04/schema#";
else if (ctx.target === "openapi-3.0") {
}
if (ctx.external?.uri) {
const id = ctx.external.registry.get(schema)?.id;
if (!id) throw new Error("Schema is missing an `id` property");
result.$id = ctx.external.uri(id);
}
assignProps(result, root.defId ? root.schema : (root.def ?? root.schema));
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
const defs = ctx.external?.defs ?? {};
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external)
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.def && seen.defId) {
if (seen.def.id === seen.defId) delete seen.def.id;
assignProp(defs, seen.defId, seen.def);
}
}
if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
if (ctx.external) {
} else if (Object.keys(defs).length > 0) {
if (ctx.target === "draft-2020-12") result.$defs = defs;
else result.definitions = defs;
}
try {
const finalized = JSON.parse(JSON.stringify(result));
Object.defineProperty(finalized, "~standard", {
value: {
...schema["~standard"],
jsonSchema: {
input: createStandardJSONSchemaMethod(
schema,
"input",
ctx.processors,
),
output: createStandardJSONSchemaMethod(
schema,
"output",
ctx.processors,
),
},
},
enumerable: false,
writable: false,
});
return finalized;
} catch (_err) {
throw new Error("Error converting schema to JSON.");
}
}
function isTransforming(_schema, _ctx) {
const ctx = _ctx ?? { seen: new Set() };
if (ctx.seen.has(_schema)) return false;
ctx.seen.add(_schema);
const def = _schema._zod.def;
if (def.type === "transform") return true;
if (def.type === "array") return isTransforming(def.element, ctx);
if (def.type === "set") return isTransforming(def.valueType, ctx);
if (def.type === "lazy") return isTransforming(def.getter(), ctx);
if (
def.type === "promise" ||
def.type === "optional" ||
def.type === "nonoptional" ||
def.type === "nullable" ||
def.type === "readonly" ||
def.type === "default" ||
def.type === "prefault" ||
def.type === "catch"
)
return isTransforming(def.innerType, ctx);
if (def.type === "intersection")
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
if (def.type === "record" || def.type === "map")
return (
isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx)
);
if (def.type === "pipe") {
if (_schema._zod.traits.has("$ZodCodec")) return true;
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
}
if (def.type === "object") {
for (const key in def.shape)
if (isTransforming(def.shape[key], ctx)) return true;
return false;
}
if (def.type === "union") {
for (const option of def.options)
if (isTransforming(option, ctx)) return true;
return false;
}
if (def.type === "tuple") {
for (const item of def.items) if (isTransforming(item, ctx)) return true;
if (def.rest && isTransforming(def.rest, ctx)) return true;
return false;
}
return false;
}
const createToJSONSchemaMethod =
(schema, processors = {}) =>
(params) => {
const ctx = initializeContext({
...params,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const createStandardJSONSchemaMethod =
(schema, io, processors = {}) =>
(params) => {
const { libraryOptions, target } = params ?? {};
const ctx = initializeContext({
...(libraryOptions ?? {}),
target,
io,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const narrowMin = (agg, key, value) => {
if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
};
const narrowMax = (agg, key, value) => {
if (agg[key] === void 0 || value < agg[key]) agg[key] = value;
};
const narrowBoth = (agg, value) => {
narrowMin(agg, "minimum", value);
narrowMax(agg, "maximum", value);
};
const addDivisor = (agg, value) => {
agg.multipleOf ?? (agg.multipleOf = []);
if (!agg.multipleOf.includes(value)) agg.multipleOf.push(value);
};
const addPattern = (agg, pattern) => {
agg.patterns ?? (agg.patterns = new Set());
agg.patterns.add(pattern);
};
const intersectMime = (agg, mime) => {
agg.mime = agg.mime ? agg.mime.filter((m) => mime.includes(m)) : [...mime];
};
const setFormat = (agg, format) => {
agg.format = format;
if (format.includes("int")) agg.isInt = true;
};
const minContributor = (agg, def) => narrowMin(agg, "minimum", def.minimum);
const maxContributor = (agg, def) => narrowMax(agg, "maximum", def.maximum);
const formatContributor = (ranges) => (agg, def) => {
setFormat(agg, def.format);
const [minimum, maximum] = ranges[def.format];
narrowMin(agg, "minimum", minimum);
narrowMax(agg, "maximum", maximum);
};
const contributors = {
greater_than: (agg, def) =>
narrowMin(agg, def.inclusive ? "minimum" : "exclusiveMinimum", def.value),
less_than: (agg, def) =>
narrowMax(agg, def.inclusive ? "maximum" : "exclusiveMaximum", def.value),
multiple_of: (agg, def) => addDivisor(agg, def.value),
number_format: formatContributor(NUMBER_FORMAT_RANGES),
bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
min_length: minContributor,
max_length: maxContributor,
length_equals: (agg, def) => narrowBoth(agg, def.length),
min_size: minContributor,
max_size: maxContributor,
size_equals: (agg, def) => narrowBoth(agg, def.size),
string_format: (agg, def) => {
setFormat(agg, def.format);
if (def.pattern) addPattern(agg, def.pattern);
if (def.format === "base64" || def.format === "base64url")
agg.contentEncoding = def.format;
if (def.local || def.precision === -1) agg.laxFormat = true;
},
mime_type: (agg, def) => intersectMime(agg, def.mime),
};
function aggregateChecks(schema) {
const agg = {};
const def = schema._zod.def;
const list = schema._zod.traits.has("$ZodCheck")
? [schema, ...(def.checks ?? [])]
: (def.checks ?? []);
for (const ch of list) contributors[ch._zod.def.check]?.(agg, ch._zod.def);
const bag = schema._zod.bag;
if (bag.minimum !== void 0) narrowMin(agg, "minimum", bag.minimum);
if (bag.exclusiveMinimum !== void 0)
narrowMin(agg, "exclusiveMinimum", bag.exclusiveMinimum);
if (bag.maximum !== void 0) narrowMax(agg, "maximum", bag.maximum);
if (bag.exclusiveMaximum !== void 0)
narrowMax(agg, "exclusiveMaximum", bag.exclusiveMaximum);
if (bag.multipleOf !== void 0) addDivisor(agg, bag.multipleOf);
if (bag.format !== void 0) {
agg.format ?? (agg.format = bag.format);
if (bag.format.includes("int")) agg.isInt = true;
}
if (bag.mime) intersectMime(agg, bag.mime);
for (const pattern of bag.patterns ?? []) addPattern(agg, pattern);
return agg;
}
const formatMap = {
guid: "uuid",
url: "uri",
datetime: "date-time",
json_string: "json-string",
regex: "",
};
const exactPatterns = new Map([
[base64Charset, base64],
[base64urlCharset, base64url],
]);
const exactPattern = (p) => exactPatterns.get(p) ?? p;
const stringProcessor = (schema, ctx, _json, _params) => {
const json = _json;
json.type = "string";
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } =
aggregateChecks(schema);
if (typeof minimum === "number") json.minLength = minimum;
if (typeof maximum === "number") json.maxLength = maximum;
if (format) {
json.format = formatMap[format] ?? format;
if (json.format === "") delete json.format;
if (format === "time" || laxFormat) delete json.format;
}
if (contentEncoding) json.contentEncoding = contentEncoding;
if (patterns && patterns.size > 0) {
const patternList = [...patterns].map(exactPattern);
if (patternList.length === 1) json.pattern = patternList[0].source;
else if (patternList.length > 1)
json.allOf = [
...patternList.map((regex) => ({
...(ctx.target === "draft-07" ||
ctx.target === "draft-04" ||
ctx.target === "openapi-3.0"
? { type: "string" }
: {}),
pattern: regex.source,
})),
];
}
};
const numberProcessor = (schema, ctx, _json, params) => {
const json = _json;
const {
minimum,
maximum,
multipleOf,
exclusiveMaximum,
exclusiveMinimum,
isInt,
} = aggregateChecks(schema);
json.type = isInt ? "integer" : "number";
const exMin =
typeof exclusiveMinimum === "number" &&
exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
const exMax =
typeof exclusiveMaximum === "number" &&
exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
if (exMin) {
if (legacy) {
json.minimum = exclusiveMinimum;
json.exclusiveMinimum = true;
} else json.exclusiveMinimum = exclusiveMinimum;
} else if (typeof minimum === "number") json.minimum = minimum;
if (exMax) {
if (legacy) {
json.maximum = exclusiveMaximum;
json.exclusiveMaximum = true;
} else json.exclusiveMaximum = exclusiveMaximum;
} else if (typeof maximum === "number") json.maximum = maximum;
if (multipleOf) {
const divisors = new Set();
for (const divisor of multipleOf)
if (Number.isFinite(divisor) && divisor !== 0)
divisors.add(Math.abs(divisor));
else
handleUnrepresentable(
schema,
ctx,
json,
params,
`A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`,
);
const [first, ...rest] = divisors;
if (first !== void 0) json.multipleOf = first;
if (rest.length)
json.allOf = [
...(json.allOf ?? []),
...rest.map((m) => ({ multipleOf: m })),
];
}
};
const neverProcessor = (_schema, _ctx, json, _params) => {
json.not = {};
};
const dateProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Date cannot be represented in JSON Schema",
);
};
const enumProcessor = (schema, _ctx, json, _params) => {
const def = schema._zod.def;
const values = getEnumValues(def.entries);
if (values.length === 0) {
json.not = {};
return;
}
if (values.every((v) => typeof v === "number")) json.type = "number";
if (values.every((v) => typeof v === "string")) json.type = "string";
json.enum = values;
};
const customProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Custom types cannot be represented in JSON Schema",
);
};
const transformProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Transforms cannot be represented in JSON Schema",
);
};
const arrayProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const { minimum, maximum } = aggregateChecks(schema);
if (typeof minimum === "number") json.minItems = minimum;
if (typeof maximum === "number") json.maxItems = maximum;
json.type = "array";
json.items = processSchema(def.element, ctx, {
...params,
path: [...params.path, "items"],
});
};
function inputOptin(schema) {
const def = schema._zod.def;
if (def.type === "pipe" && def.in._zod.traits.has("$ZodTransform"))
return inputOptin(def.out);
if (def.type === "catch") return inputOptin(def.innerType);
return schema._zod.optin;
}
const objectProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const shape = def.shape;
if (
Object.getOwnPropertySymbols(shape).length &&
handleUnrepresentable(
schema,
ctx,
json,
params,
"Symbol keys cannot be represented in JSON Schema",
)
)
return;
json.type = "object";
json.properties = {};
for (const key in shape)
assignProp(
json.properties,
key,
processSchema(shape[key], ctx, {
...params,
path: [...params.path, "properties", key],
}),
);
const requiredKeys = [];
for (const key of Object.keys(shape)) {
const field = def.shape[key];
if (
ctx.io === "input"
? inputOptin(field) === void 0
: field._zod.optout === void 0
)
requiredKeys.push(key);
}
if (requiredKeys.length > 0) json.required = requiredKeys;
if (def.catchall?._zod.def.type === "never")
json.additionalProperties = false;
else if (!def.catchall) {
if (ctx.io === "output") json.additionalProperties = false;
} else if (def.catchall)
json.additionalProperties = processSchema(def.catchall, ctx, {
...params,
path: [...params.path, "additionalProperties"],
});
};
const unionProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const isExclusive = def.inclusive === false;
const options = def.options.map((x, i) =>
processSchema(x, ctx, {
...params,
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
}),
);
if (isExclusive) json.oneOf = options;
else json.anyOf = options;
};
const intersectionProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const a = processSchema(def.left, ctx, {
...params,
path: [...params.path, "allOf", 0],
});
const b = processSchema(def.right, ctx, {
...params,
path: [...params.path, "allOf", 1],
});
const isSimpleIntersection = (val) =>
"allOf" in val && Object.keys(val).length === 1;
const allOf = [
...(isSimpleIntersection(a) ? a.allOf : [a]),
...(isSimpleIntersection(b) ? b.allOf : [b]),
];
json.allOf = allOf;
ctx.intersections.push(allOf);
};
const nullableProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const inner = processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
if (ctx.target === "openapi-3.0") {
seen.ref = def.innerType;
json.nullable = true;
} else json.anyOf = [inner, { type: "null" }];
};
const nonoptionalProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const UNREPRESENTABLE_DEFAULT = Symbol();
function serializeDefaultValue(value, schema, ctx, json, params) {
let unrepresentable = false;
const serialized = JSON.stringify(value, (_, val) => {
if (typeof val !== "bigint") return val;
unrepresentable = true;
return null;
});
if (!unrepresentable) return JSON.parse(serialized);
handleUnrepresentable(
schema,
ctx,
json,
params,
"BigInt defaults cannot be represented in JSON Schema",
);
return UNREPRESENTABLE_DEFAULT;
}
const defaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT) json.default = value;
};
const prefaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
if (ctx.io !== "input") return;
const value = serializeDefaultValue(
def.defaultValue,
schema,
ctx,
json,
params,
);
if (value !== UNREPRESENTABLE_DEFAULT) json._prefault = value;
};
const catchProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
let catchValue;
try {
catchValue = def.catchValue(void 0);
} catch {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Dynamic catch values are not supported in JSON Schema",
);
return;
}
json.default = catchValue;
};
const pipeProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
const innerType =
ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
processSchema(innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = innerType;
};
const readonlyProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
json.readOnly = true;
};
const optionalProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const _installedErrorProtos = new WeakSet([
Object.prototype,
Error.prototype,
]);
function _lazyMethod(proto, key, make) {
Object.defineProperty(proto, key, {
configurable: true,
enumerable: false,
get() {
const value = make(this);
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
},
});
}
const initializer = (inst, issues) => {
$ZodError.init(inst, issues);
inst.name = "ZodError";
const proto = Object.getPrototypeOf(inst);
if (_installedErrorProtos.has(proto)) return;
_installedErrorProtos.add(proto);
_lazyMethod(proto, "format", (self) => (mapper) => formatError(self, mapper));
_lazyMethod(
proto,
"flatten",
(self) => (mapper) => flattenError(self, mapper),
);
_lazyMethod(proto, "addIssue", (self) => (issue) => {
self.issues.push(issue);
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
});
_lazyMethod(proto, "addIssues", (self) => (issues) => {
self.issues.push(...issues);
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
});
Object.defineProperty(proto, "isEmpty", {
configurable: true,
enumerable: false,
get() {
return this.issues.length === 0;
},
});
};
const ZodRealError = $constructor(
"ZodError",
initializer,
void 0,
{ Parent: Error },
);
const parse = _parse(ZodRealError);
const parseAsync = _parseAsync(ZodRealError);
const safeParse = _safeParse(ZodRealError);
const safeParseAsync = _safeParseAsync(ZodRealError);
const encode = _encode(ZodRealError);
const decode = _decode(ZodRealError);
const encodeAsync = _encodeAsync(ZodRealError);
const decodeAsync = _decodeAsync(ZodRealError);
const safeEncode = _safeEncode(ZodRealError);
const safeDecode = _safeDecode(ZodRealError);
const safeEncodeAsync = _safeEncodeAsync(ZodRealError);
const safeDecodeAsync = _safeDecodeAsync(ZodRealError);
function _ensureDefaultLocale() {
if (!globalConfig.localeError) config(en_default());
}
function _ensureDefaultMemoizer() {
if (!globalConfig.memoizer) config({ memoizer: memoizer() });
}
const ZodType = $constructor(
"ZodType",
(inst, def) => {
_ensureDefaultLocale();
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
return inst;
},
{
check(...chks) {
const def = this.def;
return this.clone(
mergeDefs(def, {
checks: [
...(def.checks ?? []),
...chks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
}),
{ parent: true },
);
},
with(...chks) {
return this.check(...chks);
},
clone(def, params) {
return clone(this, def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
refine(check, params) {
return this.check(refine(check, params));
},
superRefine(refinement, params) {
return this.check(superRefine(refinement, params));
},
overwrite(fn) {
return this.check( _overwrite(fn));
},
optional() {
return optional(this);
},
exactOptional() {
return exactOptional(this);
},
nullable() {
return nullable(this);
},
nullish() {
return optional(nullable(this));
},
nonoptional(params) {
return nonoptional(this, params);
},
array() {
return array(this);
},
or(arg) {
return union([this, arg]);
},
and(arg) {
return intersection(this, arg);
},
transform(tx) {
return pipe(this, transform(tx));
},
default(d) {
return _default(this, d);
},
prefault(d) {
return prefault(this, d);
},
catch(params) {
return _catch(this, params);
},
pipe(target) {
return pipe(this, target);
},
readonly() {
return readonly(this);
},
describe(description) {
const cl = this.clone();
globalRegistry.add(cl, { description });
return cl;
},
meta(...args) {
if (args.length === 0) return globalRegistry.get(this);
const cl = this.clone();
globalRegistry.add(cl, args[0]);
return cl;
},
isOptional() {
return this.safeParse(void 0).success;
},
isNullable() {
return this.safeParse(null).success;
},
apply(fn, ...args) {
return args.length === 0 ? fn(this) : fn(this, ...args);
},
get "~standard"() {
return hide(this, "~standard", {
...standardProps(this),
jsonSchema: {
input: createStandardJSONSchemaMethod(this, "input"),
output: createStandardJSONSchemaMethod(this, "output"),
},
});
},
set "~standard"(value) {
own(this, "~standard", value);
},
parse: function _parse(data, params) {
return parse(this, data, params, { callee: _parse });
},
parseAsync: async function _parseAsync(data, params) {
return await parseAsync(this, data, params, { callee: _parseAsync });
},
safeParse(data, params) {
return safeParse(this, data, params);
},
async safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
get spa() {
return this?.safeParseAsync;
},
set spa(value) {
own(this, "spa", value);
},
validate(data, params) {
return validate(this, data, params);
},
validateAsync(data, params) {
return validateAsync$1(this, data, params);
},
encode: function _encode(data, params) {
return encode(this, data, params, { callee: _encode });
},
decode: function _decode(data, params) {
return decode(this, data, params, { callee: _decode });
},
encodeAsync: async function _encodeAsync(data, params) {
return await encodeAsync(this, data, params, { callee: _encodeAsync });
},
decodeAsync: async function _decodeAsync(data, params) {
return await decodeAsync(this, data, params, { callee: _decodeAsync });
},
safeEncode(data, params) {
return safeEncode(this, data, params);
},
safeDecode(data, params) {
return safeDecode(this, data, params);
},
async safeEncodeAsync(data, params) {
return safeEncodeAsync(this, data, params);
},
async safeDecodeAsync(data, params) {
return safeDecodeAsync(this, data, params);
},
toJSONSchema(params) {
return createToJSONSchemaMethod(this, {})(params);
},
get description() {
return globalRegistry.get(this)?.description;
},
get _def() {
return this._zod.def;
},
},
);
const _ZodString = $constructor(
"_ZodString",
(inst, def) => {
$ZodString.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
stringProcessor(inst, ctx, json, params);
},
derived(
{
format: (inst) => aggregateChecks(inst).format ?? null,
minLength: (inst) => aggregateChecks(inst).minimum ?? null,
maxLength: (inst) => aggregateChecks(inst).maximum ?? null,
},
{
regex(...args) {
return this.check( _regex(...args));
},
includes(...args) {
return this.check( _includes(...args));
},
startsWith(...args) {
return this.check( _startsWith(...args));
},
endsWith(...args) {
return this.check( _endsWith(...args));
},
min(...args) {
return this.check( _minLength(...args));
},
max(...args) {
return this.check( _maxLength(...args));
},
length(...args) {
return this.check( _length(...args));
},
nonempty(...args) {
return this.check( _minLength(1, ...args));
},
lowercase(params) {
return this.check( _lowercase(params));
},
uppercase(params) {
return this.check( _uppercase(params));
},
trim() {
return this.check( _trim());
},
normalize(...args) {
return this.check( _normalize(...args));
},
toLowerCase() {
return this.check( _toLowerCase());
},
toUpperCase() {
return this.check( _toUpperCase());
},
slugify() {
return this.check( _slugify());
},
},
),
);
const ZodString = $constructor(
"ZodString",
(inst, def) => {
$ZodString.init(inst, def);
_ZodString.init(inst, def);
},
{
email(params) {
return this.check( _email(ZodEmail, params));
},
url(params) {
return this.check( _url(ZodURL, params));
},
jwt(params) {
return this.check( _jwt(ZodJWT, params));
},
emoji(params) {
return this.check( _emoji(ZodEmoji, params));
},
guid(params) {
return this.check( _guid(ZodGUID, params));
},
uuid(params) {
return this.check( _uuid(ZodUUID, params));
},
uuidv4(params) {
return this.check( _uuidv4(ZodUUID, params));
},
uuidv6(params) {
return this.check( _uuidv6(ZodUUID, params));
},
uuidv7(params) {
return this.check( _uuidv7(ZodUUID, params));
},
nanoid(params) {
return this.check( _nanoid(ZodNanoID, params));
},
cuid(params) {
return this.check( _cuid(ZodCUID, params));
},
cuid2(params) {
return this.check( _cuid2(ZodCUID2, params));
},
ulid(params) {
return this.check( _ulid(ZodULID, params));
},
base64(params) {
return this.check( _base64(ZodBase64, params));
},
base64url(params) {
return this.check( _base64url(ZodBase64URL, params));
},
xid(params) {
return this.check( _xid(ZodXID, params));
},
ksuid(params) {
return this.check( _ksuid(ZodKSUID, params));
},
ipv4(params) {
return this.check( _ipv4(ZodIPv4, params));
},
ipv6(params) {
return this.check( _ipv6(ZodIPv6, params));
},
cidrv4(params) {
return this.check( _cidrv4(ZodCIDRv4, params));
},
cidrv6(params) {
return this.check( _cidrv6(ZodCIDRv6, params));
},
e164(params) {
return this.check( _e164(ZodE164, params));
},
datetime(params) {
return this.check( _isoDateTime(ZodISODateTime, params));
},
date(params) {
return this.check( _isoDate(ZodISODate, params));
},
time(params) {
return this.check( _isoTime(ZodISOTime, params));
},
duration(params) {
return this.check( _isoDuration(ZodISODuration, params));
},
},
);
function string(params) {
return _string(ZodString, params);
}
const ZodStringFormat = $constructor(
"ZodStringFormat",
(inst, def) => {
$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
},
);
const ZodISODateTime = $constructor(
"ZodISODateTime",
(inst, def) => {
$ZodISODateTime.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodISODate = $constructor("ZodISODate", (inst, def) => {
$ZodISODate.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodISOTime = $constructor("ZodISOTime", (inst, def) => {
$ZodISOTime.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodISODuration = $constructor(
"ZodISODuration",
(inst, def) => {
$ZodISODuration.init(inst, def);
ZodStringFormat.init(inst, def);
},
);
const ZodEmail = $constructor("ZodEmail", (inst, def) => {
$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodGUID = $constructor("ZodGUID", (inst, def) => {
$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodUUID = $constructor("ZodUUID", (inst, def) => {
$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodURL = $constructor("ZodURL", (inst, def) => {
$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
});
function url(params) {
return _url(ZodURL, params);
}
const ZodEmoji = $constructor("ZodEmoji", (inst, def) => {
$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodNanoID = $constructor("ZodNanoID", (inst, def) => {
$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCUID = $constructor("ZodCUID", (inst, def) => {
$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCUID2 = $constructor("ZodCUID2", (inst, def) => {
$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodULID = $constructor("ZodULID", (inst, def) => {
$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodXID = $constructor("ZodXID", (inst, def) => {
$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodKSUID = $constructor("ZodKSUID", (inst, def) => {
$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodIPv4 = $constructor("ZodIPv4", (inst, def) => {
$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodIPv6 = $constructor("ZodIPv6", (inst, def) => {
$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCIDRv4 = $constructor("ZodCIDRv4", (inst, def) => {
$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCIDRv6 = $constructor("ZodCIDRv6", (inst, def) => {
$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodBase64 = $constructor("ZodBase64", (inst, def) => {
$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodBase64URL = $constructor("ZodBase64URL", (inst, def) => {
$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodE164 = $constructor("ZodE164", (inst, def) => {
$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodJWT = $constructor("ZodJWT", (inst, def) => {
$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodNumber = $constructor(
"ZodNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
numberProcessor(inst, ctx, json, params);
inst.isFinite = true;
},
derived(
{
minValue: (inst) => {
const { minimum, exclusiveMinimum } = aggregateChecks(inst);
return Math.max(
minimum ?? Number.NEGATIVE_INFINITY,
exclusiveMinimum ?? Number.NEGATIVE_INFINITY,
);
},
maxValue: (inst) => {
const { maximum, exclusiveMaximum } = aggregateChecks(inst);
return Math.min(
maximum ?? Number.POSITIVE_INFINITY,
exclusiveMaximum ?? Number.POSITIVE_INFINITY,
);
},
isInt: (inst) => {
const { isInt, multipleOf } = aggregateChecks(inst);
return !!isInt || !!multipleOf?.some(Number.isSafeInteger);
},
format: (inst) => aggregateChecks(inst).format ?? null,
},
{
gt(value, params) {
return this.check( _gt(value, params));
},
gte(value, params) {
return this.check( _gte(value, params));
},
min(value, params) {
return this.check( _gte(value, params));
},
lt(value, params) {
return this.check( _lt(value, params));
},
lte(value, params) {
return this.check( _lte(value, params));
},
max(value, params) {
return this.check( _lte(value, params));
},
int(params) {
return this.check(int(params));
},
safe(params) {
return this.check(int(params));
},
positive(params) {
return this.check( _gt(0, params));
},
nonnegative(params) {
return this.check( _gte(0, params));
},
negative(params) {
return this.check( _lt(0, params));
},
nonpositive(params) {
return this.check( _lte(0, params));
},
multipleOf(value, params) {
return this.check( _multipleOf(value, params));
},
step(value, params) {
return this.check( _multipleOf(value, params));
},
finite() {
return this;
},
},
),
);
function number(params) {
return _number(ZodNumber, params);
}
const ZodNumberFormat = $constructor(
"ZodNumberFormat",
(inst, def) => {
$ZodNumberFormat.init(inst, def);
ZodNumber.init(inst, def);
},
);
function int(params) {
return _int(ZodNumberFormat, params);
}
const ZodUnknown = $constructor("ZodUnknown", (inst, def) => {
$ZodUnknown.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => void 0;
});
function unknown() {
return _unknown(ZodUnknown);
}
const ZodNever = $constructor("ZodNever", (inst, def) => {
$ZodNever.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
neverProcessor(inst, ctx, json, params);
});
function never(params) {
return _never(ZodNever, params);
}
const ZodDate = $constructor(
"ZodDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
dateProcessor(inst, ctx, json, params);
inst.min = (value, params) =>
inst.check( _gte(value, params));
inst.max = (value, params) =>
inst.check( _lte(value, params));
},
derived(
{
minDate: (inst) => {
const { minimum } = aggregateChecks(inst);
return minimum ? new Date(minimum) : null;
},
maxDate: (inst) => {
const { maximum } = aggregateChecks(inst);
return maximum ? new Date(maximum) : null;
},
},
{},
),
);
function date(params) {
return _date(ZodDate, params);
}
const ZodArray = $constructor(
"ZodArray",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodArray.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
arrayProcessor(inst, ctx, json, params);
inst.element = def.element;
},
{
min(n, params) {
return this.check( _minLength(n, params));
},
nonempty(params) {
return this.check( _minLength(1, params));
},
max(n, params) {
return this.check( _maxLength(n, params));
},
length(n, params) {
return this.check( _length(n, params));
},
unwrap() {
return this.element;
},
},
);
function array(element, params) {
return _array(ZodArray, element, params);
}
const ZodObject = $constructor(
"ZodObject",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodObjectJIT.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
objectProcessor(inst, ctx, json, params);
installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
},
{
keyof() {
return _enum(Object.keys(this._zod.def.shape));
},
catchall(catchall) {
return this.clone(mergeDefs(this._zod.def, { catchall }));
},
passthrough() {
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
},
loose() {
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
},
strict() {
return this.clone(mergeDefs(this._zod.def, { catchall: never() }));
},
strip() {
return this.clone(mergeDefs(this._zod.def, { catchall: void 0 }));
},
extend(incoming) {
return extend(this, incoming);
},
safeExtend(incoming) {
return safeExtend(this, incoming);
},
merge(other) {
return merge(this, other);
},
pick(mask) {
return pick(this, mask);
},
omit(mask) {
return omit(this, mask);
},
partial(...args) {
return partial(ZodOptional, this, args[0]);
},
exactPartial(...args) {
return partial(ZodExactOptional, this, args[0], "exactPartial");
},
required(...args) {
return required(ZodNonOptional, this, args[0]);
},
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodObject(def);
}
const ZodUnion = $constructor("ZodUnion", (inst, def) => {
$ZodUnion.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
unionProcessor(inst, ctx, json, params);
inst.options = def.options;
});
function union(options, params) {
return new ZodUnion({
type: "union",
options,
...normalizeParams(params),
});
}
const ZodIntersection = $constructor(
"ZodIntersection",
(inst, def) => {
$ZodIntersection.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
intersectionProcessor(inst, ctx, json, params);
},
);
function intersection(left, right) {
return new ZodIntersection({
type: "intersection",
left,
right,
});
}
const ZodEnum = $constructor("ZodEnum", (inst, def) => {
$ZodEnum.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
enumProcessor(inst, ctx, json, params);
inst.enum = def.entries;
inst.options = [...inst._zod.values];
const keys = new Set(Object.keys(def.entries));
inst.extract = (values, params) => {
const newEntries = {};
for (const value of values)
if (keys.has(value)) newEntries[value] = def.entries[value];
else throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (values, params) => {
const newEntries = { ...def.entries };
for (const value of values)
if (keys.has(value)) delete newEntries[value];
else throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
});
function _enum(values, params) {
const entries = Array.isArray(values)
? Object.fromEntries(values.map((v) => [v, v]))
: values;
return new ZodEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodTransform = $constructor("ZodTransform", (inst, def) => {
_ensureDefaultMemoizer();
$ZodTransform.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
transformProcessor(inst, ctx, json, params);
inst._zod.parse = (payload, _ctx) => {
if (_ctx.direction === "backward")
throw new $ZodEncodeError(inst.constructor.name);
payload.addIssue = (issue$1) => {
if (typeof issue$1 === "string")
payload.issues.push(issue(issue$1, payload.value, def));
else {
const _issue = issue$1;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue)) _issue.input = payload.value;
_issue.inst ?? (_issue.inst = inst);
payload.issues.push(issue(_issue));
}
};
const output = def.transform(payload.value, payload);
if (output instanceof Promise)
return output.then((output) => {
payload.value = output;
return payload;
});
payload.value = output;
return payload;
};
});
function transform(fn) {
return new ZodTransform({
type: "transform",
transform: fn,
});
}
const ZodOptional = $constructor("ZodOptional", (inst, def) => {
$ZodOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function optional(innerType) {
return new ZodOptional({
type: "optional",
innerType,
});
}
const ZodExactOptional = $constructor(
"ZodExactOptional",
(inst, def) => {
$ZodExactOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function exactOptional(innerType) {
return new ZodExactOptional({
type: "optional",
innerType,
});
}
const ZodNullable = $constructor("ZodNullable", (inst, def) => {
$ZodNullable.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
nullableProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function nullable(innerType) {
return new ZodNullable({
type: "nullable",
innerType,
});
}
const ZodDefault = $constructor("ZodDefault", (inst, def) => {
$ZodDefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
defaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
});
function _default(innerType, defaultValue) {
return new ZodDefault({
type: "default",
innerType,
get defaultValue() {
return typeof defaultValue === "function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodPrefault = $constructor("ZodPrefault", (inst, def) => {
$ZodPrefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
prefaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function prefault(innerType, defaultValue) {
return new ZodPrefault({
type: "prefault",
innerType,
get defaultValue() {
return typeof defaultValue === "function"
? defaultValue()
: shallowClone(defaultValue);
},
});
}
const ZodNonOptional = $constructor(
"ZodNonOptional",
(inst, def) => {
$ZodNonOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
nonoptionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
},
);
function nonoptional(innerType, params) {
return new ZodNonOptional({
type: "nonoptional",
innerType,
...normalizeParams(params),
});
}
const ZodCatch = $constructor("ZodCatch", (inst, def) => {
$ZodCatch.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
catchProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
});
function _catch(innerType, catchValue) {
return new ZodCatch({
type: "catch",
innerType,
catchValue:
typeof catchValue === "function" ? catchValue : constantCatch(catchValue),
});
}
const ZodPipe = $constructor("ZodPipe", (inst, def) => {
$ZodPipe.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
pipeProcessor(inst, ctx, json, params);
inst.in = def.in;
inst.out = def.out;
});
function pipe(in_, out) {
return new ZodPipe({
type: "pipe",
in: in_,
out,
});
}
const ZodReadonly = $constructor("ZodReadonly", (inst, def) => {
$ZodReadonly.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
readonlyProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function readonly(innerType) {
return new ZodReadonly({
type: "readonly",
innerType,
});
}
const ZodCustom = $constructor("ZodCustom", (inst, def) => {
$ZodCustom.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
customProcessor(inst, ctx, json, params);
});
function refine(fn, _params = {}) {
return _refine(ZodCustom, fn, _params);
}
function superRefine(fn, params) {
return _superRefine(fn, params);
}
function __zcUw(m) {
return typeof m === "string"
? m
: m === void 0 || m === null
? void 0
: m.message;
}
var __zcMsg = function (iss) {
var c = config(),
m;
if (c.customError) {
m = __zcUw(c.customError(iss));
if (m !== void 0 && m !== null) return m;
}
if (c.localeError) {
m = __zcUw(c.localeError(iss));
if (m !== void 0 && m !== null) return m;
}
return "Invalid input";
};
function __ZcFail(e, f, i) {
this.success = false;
this._e = e;
this._f = f;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFail.prototype, "error", {
configurable: true,
get: function () {
if (this._c) return this._c;
var e = this._f !== null ? this._f(this._i) : this._e;
for (var i = 0; i < e.length; i++) {
if (e[i].message === void 0 && typeof __zcMsg === "function")
e[i].message = __zcMsg(e[i]);
delete e[i].input;
delete e[i].continue;
}
return (this._c = new ZodRealError(e));
},
});
function __ZcFailZ(z, r, i) {
this.success = false;
this._z = z;
this._r = r;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFailZ.prototype, "error", {
configurable: true,
get: function () {
return this._c || (this._c = this._z.call(this._r, this._i).error);
},
});
function __zcMkv(fn, schema, fc, is) {
var w = schema || {};
var zpa = w.parseAsync,
zspa = w.safeParseAsync;
w.parse = fc
? function (input) {
if (fc(input)) return input;
var r = fn(input);
if (r.success) return r.data;
throw r.error;
}
: function (input) {
var r = fn(input);
if (r.success) return r.data;
throw r.error;
};
w.safeParse = fn;
w.safeParseAsync = function (input) {
try {
return Promise.resolve(fn(input));
} catch (e) {
if (zspa) return zspa(input);
throw e;
}
};
w.parseAsync = fc
? function (input) {
try {
if (fc(input)) return Promise.resolve(input);
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
}
: function (input) {
try {
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
};
w.is =
is ||
function (input) {
return fn(input).success;
};
Object.defineProperty(w, "~standard", {
configurable: true,
value: {
version: 1,
vendor: "zod",
validate: function (input) {
var r;
try {
if (fc && fc(input)) return { value: input };
r = fn(input);
} catch (e) {
if (zspa)
return zspa(input).then(function (q) {
return q.success ? { value: q.data } : { issues: q.error.issues };
});
throw e;
}
return r.success ? { value: r.data } : { issues: r.error.issues };
},
},
});
return w;
}
function __zcFin(e, d) {
if (!e.length)
return {
success: true,
data: d,
};
return new __ZcFail(e, null, null);
}
function __zcTS(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_small",
minimum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcTB(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_big",
maximum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIT(e, inp, p, msg) {
var r = {
expected: e,
code: "invalid_type",
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIF(o, f, inp, p, extra, msg) {
var r =
o === void 0
? {
code: "invalid_format",
format: f,
}
: {
origin: o,
code: "invalid_format",
format: f,
};
if (extra) Object.assign(r, extra);
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIV(values, inp, p, extra, msg) {
var r = { code: "invalid_value" };
if (extra) Object.assign(r, extra);
r.values = values;
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcLo(v) {
return Array.isArray(v)
? "array"
: typeof v === "string"
? "string"
: "unknown";
}
function __zcCpl(s) {
var n = s.length;
if (!/[\uD800-\uDBFF]/.test(s)) return n;
var c = n;
for (var i = 0; i < n - 1; i++)
if (
(s.charCodeAt(i) & 64512) === 55296 &&
(s.charCodeAt(i + 1) & 64512) === 56320
) {
c--;
i++;
}
return c;
}
var __re_tnl_11 = new RegExp("[\\t\\n\\r]", "g");
function __zcSw_0(input, path, _e) {
if (!Array.isArray(input)) _e.push(__zcIT("array", input, path));
else {
var __ar_0 = input;
__ar_0 = __ar_0.slice();
for (var __i_1 = 0; __i_1 < __ar_0.length; __i_1++)
__ar_0[__i_1] = __zcSw_1(__ar_0[__i_1], path.concat(__i_1), _e);
input = __ar_0;
}
return input;
}
function __zcSw_1(input, path, _e) {
if (typeof input !== "object" || input === null || Array.isArray(input))
_e.push(__zcIT("object", input, path));
else {
var __sv_3 = input["id"];
if (typeof __sv_3 !== "number")
_e.push(__zcIT("number", __sv_3, path.concat("id")));
else if (Number.isNaN(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_3,
path: path.concat("id"),
});
else if (!Number.isFinite(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_3),
input: __sv_3,
path: path.concat("id"),
});
var __sv_4 = input["created"];
if (!(__sv_4 instanceof Date))
_e.push(__zcIT("date", __sv_4, path.concat("created")));
else if (isNaN(__sv_4.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_4,
path: path.concat("created"),
});
var __sv_5 = input["title"];
if (typeof __sv_5 !== "string") {
_e.push(__zcIT("string", __sv_5, path.concat("title")));
if (__sv_5 !== void 0 && __sv_5 !== null && __sv_5.length !== void 0) {
if (__sv_5.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_5), true, __sv_5, path.concat("title")),
);
if (__sv_5.length > 100)
_e.push(
__zcTB(100, __zcLo(__sv_5), true, __sv_5, path.concat("title")),
);
}
} else {
if (__sv_5.length < 1)
_e.push(__zcTS(1, "string", true, __sv_5, path.concat("title")));
if (__sv_5.length > 100 && (__sv_5.length > 200 || __zcCpl(__sv_5) > 100))
_e.push(__zcTB(100, "string", true, __sv_5, path.concat("title")));
}
var __sv_6 = input["type"];
if (__sv_6 !== "jpg" && __sv_6 !== "png")
_e.push(__zcIV(["jpg", "png"], __sv_6, path.concat("type")));
var __sv_7 = input["size"];
if (typeof __sv_7 !== "number")
_e.push(__zcIT("number", __sv_7, path.concat("size")));
else if (Number.isNaN(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_7,
path: path.concat("size"),
});
else if (!Number.isFinite(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_7),
input: __sv_7,
path: path.concat("size"),
});
var __sv_8 = input["url"];
if (typeof __sv_8 !== "string")
_e.push(__zcIT("string", __sv_8, path.concat("url")));
else {
var __ut_9 = __sv_8.trim();
var __u_10 = null;
try {
__u_10 = new URL(__ut_9);
} catch (_) {}
if (__u_10 === null)
_e.push(__zcIF(void 0, "url", __sv_8, path.concat("url")));
else __sv_8 = __ut_9.replace(__re_tnl_11, "");
}
input = {
id: __sv_3,
created: __sv_4,
title: __sv_5,
type: __sv_6,
size: __sv_7,
url: __sv_8,
};
}
return input;
}
const imageSchema = object({
id: number(),
created: date(),
title: string().min(1).max(100),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().min(1).max(5),
title: string().min(1).max(100),
text: string().min(1).max(1e3),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().min(1).max(100),
brand: string().min(1).max(30),
description: string().min(1).max(500),
price: number().min(1).max(1e4),
discount: number().min(1).max(100).nullable(),
quantity: number().min(0).max(10),
tags: array(string().min(1).max(30)),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
);
(() => {
function safeParse_compiledProductSchema(input) {
var _e = [];
var _d = input;
if (typeof _d !== "object" || _d === null || Array.isArray(_d))
_e.push(__zcIT("object", _d, []));
else {
var __sv_5 = _d["id"];
if (typeof __sv_5 !== "number") _e.push(__zcIT("number", __sv_5, ["id"]));
else if (Number.isNaN(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_5,
path: ["id"],
});
else if (!Number.isFinite(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_5),
input: __sv_5,
path: ["id"],
});
var __sv_6 = _d["created"];
if (!(__sv_6 instanceof Date))
_e.push(__zcIT("date", __sv_6, ["created"]));
else if (isNaN(__sv_6.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_6,
path: ["created"],
});
var __sv_7 = _d["title"];
if (typeof __sv_7 !== "string") {
_e.push(__zcIT("string", __sv_7, ["title"]));
if (__sv_7 !== void 0 && __sv_7 !== null && __sv_7.length !== void 0) {
if (__sv_7.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_7), true, __sv_7, ["title"]));
if (__sv_7.length > 100)
_e.push(__zcTB(100, __zcLo(__sv_7), true, __sv_7, ["title"]));
}
} else {
if (__sv_7.length < 1)
_e.push(__zcTS(1, "string", true, __sv_7, ["title"]));
if (
__sv_7.length > 100 &&
(__sv_7.length > 200 || __zcCpl(__sv_7) > 100)
)
_e.push(__zcTB(100, "string", true, __sv_7, ["title"]));
}
var __sv_8 = _d["brand"];
if (typeof __sv_8 !== "string") {
_e.push(__zcIT("string", __sv_8, ["brand"]));
if (__sv_8 !== void 0 && __sv_8 !== null && __sv_8.length !== void 0) {
if (__sv_8.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_8), true, __sv_8, ["brand"]));
if (__sv_8.length > 30)
_e.push(__zcTB(30, __zcLo(__sv_8), true, __sv_8, ["brand"]));
}
} else {
if (__sv_8.length < 1)
_e.push(__zcTS(1, "string", true, __sv_8, ["brand"]));
if (__sv_8.length > 30 && (__sv_8.length > 60 || __zcCpl(__sv_8) > 30))
_e.push(__zcTB(30, "string", true, __sv_8, ["brand"]));
}
var __sv_9 = _d["description"];
if (typeof __sv_9 !== "string") {
_e.push(__zcIT("string", __sv_9, ["description"]));
if (__sv_9 !== void 0 && __sv_9 !== null && __sv_9.length !== void 0) {
if (__sv_9.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_9), true, __sv_9, ["description"]));
if (__sv_9.length > 500)
_e.push(__zcTB(500, __zcLo(__sv_9), true, __sv_9, ["description"]));
}
} else {
if (__sv_9.length < 1)
_e.push(__zcTS(1, "string", true, __sv_9, ["description"]));
if (
__sv_9.length > 500 &&
(__sv_9.length > 1e3 || __zcCpl(__sv_9) > 500)
)
_e.push(__zcTB(500, "string", true, __sv_9, ["description"]));
}
var __sv_10 = _d["price"];
if (typeof __sv_10 !== "number")
_e.push(__zcIT("number", __sv_10, ["price"]));
else if (Number.isNaN(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_10,
path: ["price"],
});
else if (!Number.isFinite(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_10),
input: __sv_10,
path: ["price"],
});
else {
if (__sv_10 < 1) _e.push(__zcTS(1, "number", true, __sv_10, ["price"]));
if (__sv_10 > 1e4)
_e.push(__zcTB(1e4, "number", true, __sv_10, ["price"]));
}
var __sv_11 = _d["discount"];
if (__sv_11 !== null) {
if (typeof __sv_11 !== "number")
_e.push(__zcIT("number", __sv_11, ["discount"]));
else if (Number.isNaN(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_11,
path: ["discount"],
});
else if (!Number.isFinite(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_11),
input: __sv_11,
path: ["discount"],
});
else {
if (__sv_11 < 1)
_e.push(__zcTS(1, "number", true, __sv_11, ["discount"]));
if (__sv_11 > 100)
_e.push(__zcTB(100, "number", true, __sv_11, ["discount"]));
}
}
var __sv_12 = _d["quantity"];
if (typeof __sv_12 !== "number")
_e.push(__zcIT("number", __sv_12, ["quantity"]));
else if (Number.isNaN(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_12,
path: ["quantity"],
});
else if (!Number.isFinite(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_12),
input: __sv_12,
path: ["quantity"],
});
else {
if (__sv_12 < 0)
_e.push(__zcTS(0, "number", true, __sv_12, ["quantity"]));
if (__sv_12 > 10)
_e.push(__zcTB(10, "number", true, __sv_12, ["quantity"]));
}
var __sv_13 = _d["tags"];
if (!Array.isArray(__sv_13)) _e.push(__zcIT("array", __sv_13, ["tags"]));
else {
var __ar_14 = __sv_13;
for (var __i_15 = 0; __i_15 < __ar_14.length; __i_15++) {
var __mv_16 = __ar_14[__i_15];
if (typeof __mv_16 !== "string") {
_e.push(__zcIT("string", __mv_16, ["tags", __i_15]));
if (
__mv_16 !== void 0 &&
__mv_16 !== null &&
__mv_16.length !== void 0
) {
if (__mv_16.length < 1)
_e.push(
__zcTS(1, __zcLo(__mv_16), true, __mv_16, ["tags", __i_15]),
);
if (__mv_16.length > 30)
_e.push(
__zcTB(30, __zcLo(__mv_16), true, __mv_16, ["tags", __i_15]),
);
}
} else {
if (__mv_16.length < 1)
_e.push(__zcTS(1, "string", true, __mv_16, ["tags", __i_15]));
if (
__mv_16.length > 30 &&
(__mv_16.length > 60 || __zcCpl(__mv_16) > 30)
)
_e.push(__zcTB(30, "string", true, __mv_16, ["tags", __i_15]));
}
}
__sv_13 = __ar_14;
}
var __sv_18 = _d["images"];
__sv_18 = __zcSw_0(__sv_18, ["images"], _e);
var __sv_19 = _d["ratings"];
if (!Array.isArray(__sv_19))
_e.push(__zcIT("array", __sv_19, ["ratings"]));
else {
var __ar_20 = __sv_19;
__ar_20 = __ar_20.slice();
for (var __i_21 = 0; __i_21 < __ar_20.length; __i_21++)
if (
typeof __ar_20[__i_21] !== "object" ||
__ar_20[__i_21] === null ||
Array.isArray(__ar_20[__i_21])
)
_e.push(__zcIT("object", __ar_20[__i_21], ["ratings", __i_21]));
else {
var __sv_23 = __ar_20[__i_21]["id"];
if (typeof __sv_23 !== "number")
_e.push(__zcIT("number", __sv_23, ["ratings", __i_21, "id"]));
else if (Number.isNaN(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
else if (!Number.isFinite(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_23),
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
var __sv_24 = __ar_20[__i_21]["stars"];
if (typeof __sv_24 !== "number")
_e.push(__zcIT("number", __sv_24, ["ratings", __i_21, "stars"]));
else if (Number.isNaN(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else if (!Number.isFinite(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_24),
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else {
if (__sv_24 < 1)
_e.push(
__zcTS(1, "number", true, __sv_24, [
"ratings",
__i_21,
"stars",
]),
);
if (__sv_24 > 5)
_e.push(
__zcTB(5, "number", true, __sv_24, [
"ratings",
__i_21,
"stars",
]),
);
}
var __sv_25 = __ar_20[__i_21]["title"];
if (typeof __sv_25 !== "string") {
_e.push(__zcIT("string", __sv_25, ["ratings", __i_21, "title"]));
if (
__sv_25 !== void 0 &&
__sv_25 !== null &&
__sv_25.length !== void 0
) {
if (__sv_25.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_25), true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
if (__sv_25.length > 100)
_e.push(
__zcTB(100, __zcLo(__sv_25), true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
}
} else {
if (__sv_25.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
if (
__sv_25.length > 100 &&
(__sv_25.length > 200 || __zcCpl(__sv_25) > 100)
)
_e.push(
__zcTB(100, "string", true, __sv_25, [
"ratings",
__i_21,
"title",
]),
);
}
var __sv_26 = __ar_20[__i_21]["text"];
if (typeof __sv_26 !== "string") {
_e.push(__zcIT("string", __sv_26, ["ratings", __i_21, "text"]));
if (
__sv_26 !== void 0 &&
__sv_26 !== null &&
__sv_26.length !== void 0
) {
if (__sv_26.length < 1)
_e.push(
__zcTS(1, __zcLo(__sv_26), true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
if (__sv_26.length > 1e3)
_e.push(
__zcTB(1e3, __zcLo(__sv_26), true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
}
} else {
if (__sv_26.length < 1)
_e.push(
__zcTS(1, "string", true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
if (
__sv_26.length > 1e3 &&
(__sv_26.length > 2e3 || __zcCpl(__sv_26) > 1e3)
)
_e.push(
__zcTB(1e3, "string", true, __sv_26, [
"ratings",
__i_21,
"text",
]),
);
}
var __sv_27 = __ar_20[__i_21]["images"];
__sv_27 = __zcSw_0(__sv_27, ["ratings", __i_21, "images"], _e);
__ar_20[__i_21] = {
id: __sv_23,
stars: __sv_24,
title: __sv_25,
text: __sv_26,
images: __sv_27,
};
}
__sv_19 = __ar_20;
}
_d = {
id: __sv_5,
created: __sv_6,
title: __sv_7,
brand: __sv_8,
description: __sv_9,
price: __sv_10,
discount: __sv_11,
quantity: __sv_12,
tags: __sv_13,
images: __sv_18,
ratings: __sv_19,
};
}
if (_e.length === 0)
return {
success: true,
data: _d,
};
return __zcFin(_e, _d);
}
return __zcMkv(safeParse_compiledProductSchema, null, null, null);
})().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 joinValues(array, separator = "|") {
return array.map((val) => stringifyPrimitive(val)).join(separator);
}
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 floatSafeRemainder(val, step) {
const ratio = val / step;
const roundedRatio = Math.round(ratio);
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
return ratio - roundedRatio;
}
function assignProp(target, prop, value) {
Object.defineProperty(target, prop, {
value,
writable: true,
enumerable: true,
configurable: true,
});
}
function rawShape(def) {
const desc = Object.getOwnPropertyDescriptor(def, "shape");
return desc?.get ? desc.get.raw : desc?.value;
}
function sourceShape(schema) {
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
}
function deferProp(target, key, getter) {
Object.defineProperty(target, key, {
get() {
const value = getter();
assignProp(this, key, value);
return value;
},
enumerable: true,
configurable: true,
});
}
function putProp(target, key, value) {
if (key in target) assignProp(target, key, value);
else target[key] = value;
}
function mirrorShape(target, source, keys, wrap) {
const raw = sourceShape(source);
for (const key of keys) {
const desc = Object.getOwnPropertyDescriptor(raw, key);
if (!desc.enumerable) continue;
if (desc.get)
deferProp(target, key, () => {
const value = source._zod.def.shape[key];
return wrap ? wrap(value, key) : value;
});
else putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
}
}
function mirrorProps(target, source) {
for (const key of Reflect.ownKeys(source)) {
const desc = Object.getOwnPropertyDescriptor(source, key);
if (!desc.enumerable) continue;
if (desc.get) deferProp(target, key, () => source[key]);
else putProp(target, key, desc.value);
}
}
function mergeDefs(...defs) {
const mergedDescriptors = {};
for (const def of defs) {
const descriptors = Object.getOwnPropertyDescriptors(def);
Object.assign(mergedDescriptors, descriptors);
}
return Object.defineProperties({}, mergedDescriptors);
}
function esc(str) {
return JSON.stringify(str);
}
function slugify(input) {
return input
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, "")
.replace(/[\s_-]+/g, "-")
.replace(/^-+|-+$/g, "");
}
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
const allowsEval = cached(() => {
if (globalConfig.jitless) return false;
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare"))
return false;
try {
new Function("");
return true;
} catch (_) {
return false;
}
});
function isPlainObject(o) {
if (isObject(o) === false) return false;
const ctor = o.constructor;
if (ctor === void 0) return true;
if (typeof ctor !== "function") return true;
const prot = ctor.prototype;
if (isObject(prot) === false) return false;
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
return true;
}
function shallowClone(o) {
if (isPlainObject(o)) return { ...o };
if (Array.isArray(o)) return [...o];
if (o instanceof Map) return new Map(o);
if (o instanceof Set) return new Set(o);
return o;
}
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 stringifyPrimitive(value) {
if (typeof value === "bigint") return value.toString() + "n";
if (typeof value === "string") return `"${value}"`;
return `${value}`;
}
function optionalKeys(shape) {
return Object.keys(shape).filter((k) => {
return shape[k]._zod.optin !== void 0 && shape[k]._zod.optout === "optional";
});
}
const NUMBER_FORMAT_RANGES = (() => ({
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
int32: [-2147483648, 2147483647],
uint32: [0, 4294967295],
float32: [-34028234663852886e22, 34028234663852886e22],
float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
}))();
const BIGINT_FORMAT_RANGES = {
int64: [
BigInt("-9223372036854775808"),
BigInt("9223372036854775807"),
],
uint64: [ BigInt(0), BigInt("18446744073709551615")],
};
function pick(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(".pick() cannot be used on object schemas containing refinements");
const newShape = {};
mirrorShape(newShape, schema, maskedKeys(schema, mask));
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function maskedKeys(schema, mask) {
const raw = sourceShape(schema);
const keys = [];
for (const key of Reflect.ownKeys(mask)) {
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable)
throw new Error(`Unrecognized key: "${String(key)}"`);
if (mask[key]) keys.push(key);
}
return keys;
}
function omit(schema, mask) {
const currDef = schema._zod.def;
const checks = currDef.checks;
if (checks && checks.length > 0)
throw new Error(".omit() cannot be used on object schemas containing refinements");
const omitted = new Set(maskedKeys(schema, mask));
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)).filter((key) => !omitted.has(key)),
);
return clone(
schema,
mergeDefs(currDef, {
shape: newShape,
checks: [],
}),
);
}
function extend(schema, shape) {
if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
const checks = schema._zod.def.checks;
if (checks && checks.length > 0) {
const existingShape = sourceShape(schema);
for (const key of Reflect.ownKeys(shape))
if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0)
throw new Error(
"Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.",
);
}
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
}
function extended(schema, shape) {
const newShape = {};
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
mirrorProps(newShape, shape);
return newShape;
}
function safeExtend(schema, shape) {
if (!isPlainObject(shape))
throw new Error("Invalid input to safeExtend: expected a plain object");
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
}
function merge(a, b) {
if (!b?._zod?.def)
throw new Error(
"Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.",
);
if (a._zod.def.checks?.length)
throw new Error(
".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.",
);
const newShape = {};
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
return clone(
a,
mergeDefs(a._zod.def, {
shape: newShape,
get catchall() {
return b._zod.def.catchall;
},
checks: b._zod.def.checks ?? [],
}),
);
}
function partial(Class, schema, mask, name = "partial") {
const checks = schema._zod.def.checks;
if (checks && checks.length > 0)
throw new Error(`.${name}() cannot be used on object schemas containing refinements`);
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
const newShape = {};
mirrorShape(
newShape,
schema,
Reflect.ownKeys(sourceShape(schema)),
Class &&
((value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "optional",
innerType: value,
})),
);
return clone(
schema,
mergeDefs(schema._zod.def, {
shape: newShape,
checks: [],
}),
);
}
function required(Class, schema, mask) {
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
const newShape = {};
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), (value, key) =>
selected && !selected.has(key)
? value
: new Class({
type: "nonoptional",
innerType: value,
}),
);
return clone(schema, mergeDefs(schema._zod.def, { shape: newShape }));
}
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 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 parsedType(data) {
const t = typeof data;
switch (t) {
case "number":
return Number.isNaN(data) ? "nan" : "number";
case "object": {
if (data === null) return "null";
if (Array.isArray(data)) return "array";
const obj = data;
if (
obj &&
Object.getPrototypeOf(obj) !== Object.prototype &&
"constructor" in obj &&
obj.constructor
)
return obj.constructor.name;
}
}
return t;
}
function issue(...args) {
const [iss, input, inst] = args;
if (typeof iss === "string")
return {
message: iss,
code: "custom",
input,
inst,
};
return { ...iss };
}
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 derived(computes, table) {
for (const key in computes) {
const compute = computes[key];
Object.defineProperty(table, key, {
configurable: true,
enumerable: true,
get() {
return own(this, key, compute(this));
},
set(value) {
own(this, key, value);
},
});
}
return table;
}
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,
});
},
});
}
const CONSTANT_CATCH = "~constantCatch";
function constantCatch(value) {
const fn = () => value;
fn[CONSTANT_CATCH] = true;
return fn;
}
var _a$1;
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.`);
}
};
var $ZodEncodeError = class extends Error {
constructor(name) {
super(`Encountered unidirectional transform during encode: ${name}`);
this.name = "ZodEncodeError";
}
};
(_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__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$1 = (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 $ZodError = $constructor("$ZodError", initializer$1);
$constructor("$ZodError", initializer$1, void 0, { Parent: Error });
function node(obj, key, make) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
if (key === "__proto__")
Object.defineProperty(obj, key, {
value: make(),
writable: true,
enumerable: true,
configurable: true,
});
else obj[key] = make();
}
return obj[key];
}
function flattenError(error, mapper = (issue) => issue.message) {
const fieldErrors = {};
const formErrors = [];
for (const sub of error.issues)
if (sub.path.length > 0) node(fieldErrors, sub.path[0], () => []).push(mapper(sub));
else formErrors.push(mapper(sub));
return {
formErrors,
fieldErrors,
};
}
function formatError(error, mapper = (issue) => issue.message) {
const fieldErrors = { _errors: [] };
const processError = (error, path = []) => {
for (const issue of error.issues)
if (issue.code === "invalid_union" && issue.errors.length)
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
else if (issue.code === "invalid_key")
processError({ issues: issue.issues }, [...path, ...issue.path]);
else if (issue.code === "invalid_element")
processError({ issues: issue.issues }, [...path, ...issue.path]);
else {
const fullpath = [...path, ...issue.path];
if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
else {
let curr = fieldErrors;
let i = 0;
while (i < fullpath.length) {
const el = fullpath[i];
const terminal = i === fullpath.length - 1;
if (el === "_errors") {
if (terminal) curr._errors.push(mapper(issue));
i++;
continue;
}
if (!Object.prototype.hasOwnProperty.call(curr, el))
Object.defineProperty(curr, el, {
value: { _errors: [] },
enumerable: true,
writable: true,
configurable: true,
});
const node = curr[el];
if (terminal) node._errors.push(mapper(issue));
curr = node;
i++;
}
}
}
};
processError(error);
return fieldErrors;
}
function finalizeParams(callee, params) {
return {
callee: params?.callee ?? callee,
Err: params?.Err,
};
}
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 _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 _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,
};
};
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 COMPILE_INVALID = Symbol.for("zod.compile.invalid");
const COMPILE_FALLBACK = Symbol.for("zod.compile.fallback");
const validate = (schema, value, _ctx) => {
const validator = schema._zod.bag.validator;
if (validator !== void 0) {
if (validator(value) !== COMPILE_INVALID) return true;
if (validator.definite === true && _ctx === void 0) return false;
}
return validateFallback(schema, value, _ctx);
};
function validateFallback(schema, value, _ctx) {
const ctx = _ctx
? {
..._ctx,
async: false,
abortEarly: true,
}
: {
async: false,
abortEarly: true,
};
const fallbackRun = schema._zod.bag.fallbackRun;
let result;
if (fallbackRun) {
ctx[COMPILE_FALLBACK] = true;
result = fallbackRun(
{
value,
issues: [],
},
ctx,
);
} else
result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) throw new $ZodAsyncError();
return result.issues.length === 0;
}
const validateAsync$1 = async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
async: true,
abortEarly: true,
}
: {
async: true,
abortEarly: true,
};
let result = schema._zod.run(
{
value,
issues: [],
},
ctx,
);
if (result instanceof Promise) result = await result;
return result.issues.length === 0;
};
const _encode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return parse(schema, value, ctx, finalizeParams(fn, _params));
};
return fn;
};
const _decode = (_Err) => {
const parse = _parse(_Err);
const fn = (schema, value, _ctx, _params) => {
return parse(schema, value, _ctx, finalizeParams(fn, _params));
};
return fn;
};
const _encodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return await parseAsync(schema, value, ctx, finalizeParams(fn, _params));
};
return fn;
};
const _decodeAsync = (_Err) => {
const parseAsync = _parseAsync(_Err);
const fn = async (schema, value, _ctx, _params) => {
return await parseAsync(schema, value, _ctx, finalizeParams(fn, _params));
};
return fn;
};
const _safeEncode = (_Err) => (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParse(_Err)(schema, value, ctx);
};
const _safeDecode = (_Err) => (schema, value, _ctx) => {
return _safeParse(_Err)(schema, value, _ctx);
};
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
const ctx = _ctx
? {
..._ctx,
direction: "backward",
}
: { direction: "backward" };
return _safeParseAsync(_Err)(schema, value, ctx);
};
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
return _safeParseAsync(_Err)(schema, value, _ctx);
};
const cuid = /^[cC][0-9a-z]{6,}$/;
const cuid2 = /^[0-9a-z]+$/;
const ulid = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
const xid = /^[0-9a-vA-V]{20}$/;
const ksuid = /^[A-Za-z0-9]{27}$/;
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
function nanoidOfLength(length) {
return new RegExp(`^[a-zA-Z0-9_-]{${length}}$`);
}
const duration =
/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
const uuid = (version) => {
if (!version)
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
return new RegExp(
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`,
);
};
const email =
/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
function emoji() {
return new RegExp(_emoji$1, "u");
}
const ipv4 =
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
const ipv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
const cidrv4 =
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
const cidrv6 =
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
const httpProtocol = /^https?$/;
const e164 = /^\+[1-9]\d{6,14}$/;
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
function anchor(source) {
return new RegExp(`^${source}$`);
}
const date$1 = anchor(dateSource);
function timeSource(args) {
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
return typeof args.precision === "number"
? args.precision === -1
? `${hhmm}`
: args.precision === 0
? `${hhmm}:[0-5]\\d`
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
: args.seconds
? `${hhmm}:[0-5]\\d(?:\\.\\d+)?`
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
}
function time(args) {
return new RegExp(`^${timeSource(args)}$`);
}
function datetime(args) {
const opts = ["Z"];
if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
const qualified = `${timeSource({
precision: args.precision,
seconds: true,
})}(?:${opts.join("|")})`;
const timeRegex = args.local
? `${qualified}|${timeSource({ precision: args.precision })}`
: qualified;
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
}
const anyString = /^[\s\S]{0,}$/;
const number$1 = /^-?\d+(?:\.\d+)?$/;
const lowercase = /^[^A-Z]*$/;
const uppercase = /^[^a-z]*$/;
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 $ZodCheckMultipleOf = $constructor("$ZodCheckMultipleOf", (inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
if (typeof payload.value !== typeof def.value)
throw new Error("Cannot mix number and bigint in multiple_of check.");
if (
typeof payload.value === "bigint"
? def.value !== BigInt(0) && payload.value % def.value === BigInt(0)
: floatSafeRemainder(payload.value, def.value) === 0
)
return;
payload.issues.push({
origin: typeof payload.value,
code: "not_multiple_of",
divisor: def.value,
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckNumberFormat = $constructor("$ZodCheckNumberFormat", (inst, def) => {
$ZodCheck.init(inst, def);
def.format = def.format || "float64";
const isInt = def.format?.includes("int");
const origin = isInt ? "int" : "number";
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
inst._zod.check = (payload) => {
const input = payload.value;
if (isInt) {
if (!Number.isInteger(input)) {
payload.issues.push({
expected: origin,
format: def.format,
code: "invalid_type",
continue: false,
input,
inst,
});
return;
}
if (!Number.isSafeInteger(input)) {
if (input > 0)
payload.issues.push({
input,
code: "too_big",
maximum: Number.MAX_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
else
payload.issues.push({
input,
code: "too_small",
minimum: Number.MIN_SAFE_INTEGER,
note: "Integers must be within the safe integer range.",
inst,
origin,
inclusive: true,
continue: !def.abort,
});
return;
}
}
if (input < minimum)
payload.issues.push({
origin: "number",
input,
code: "too_small",
minimum,
inclusive: true,
inst,
continue: !def.abort,
});
if (input > maximum)
payload.issues.push({
origin: "number",
input,
code: "too_big",
maximum,
inclusive: true,
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 $ZodCheckLengthEquals = $constructor("$ZodCheckLengthEquals", (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;
const length =
typeof input === "string" && units >= def.length && units <= def.length * 2
? codePointLength(input)
: units;
if (length === def.length) return;
const origin = getLengthableOrigin(input);
const tooBig = length > def.length;
payload.issues.push({
origin,
...(tooBig
? {
code: "too_big",
maximum: def.length,
}
: {
code: "too_small",
minimum: def.length,
}),
inclusive: true,
exact: true,
input: payload.value,
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 $ZodCheckRegex = $constructor("$ZodCheckRegex", (inst, def) => {
$ZodCheckStringFormat.init(inst, def);
inst._zod.check = (payload) => {
def.pattern.lastIndex = 0;
if (def.pattern.test(payload.value)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "regex",
input: payload.value,
pattern: def.pattern.toString(),
inst,
continue: !def.abort,
});
};
});
const $ZodCheckLowerCase = $constructor("$ZodCheckLowerCase", (inst, def) => {
def.pattern ?? (def.pattern = lowercase);
$ZodCheckStringFormat.init(inst, def);
});
const $ZodCheckUpperCase = $constructor("$ZodCheckUpperCase", (inst, def) => {
def.pattern ?? (def.pattern = uppercase);
$ZodCheckStringFormat.init(inst, def);
});
const $ZodCheckIncludes = $constructor("$ZodCheckIncludes", (inst, def) => {
$ZodCheck.init(inst, def);
const escapedRegex = escapeRegex(def.includes);
def.pattern = new RegExp(
typeof def.position === "number" ? `^.{${def.position},}${escapedRegex}` : escapedRegex,
);
inst._zod.check = (payload) => {
if (payload.value.includes(def.includes, def.position)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "includes",
includes: def.includes,
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckStartsWith = $constructor("$ZodCheckStartsWith", (inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.startsWith(def.prefix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "starts_with",
prefix: def.prefix,
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckEndsWith = $constructor("$ZodCheckEndsWith", (inst, def) => {
$ZodCheck.init(inst, def);
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
def.pattern ?? (def.pattern = pattern);
inst._zod.check = (payload) => {
if (payload.value.endsWith(def.suffix)) return;
payload.issues.push({
origin: "string",
code: "invalid_format",
format: "ends_with",
suffix: def.suffix,
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCheckOverwrite = $constructor("$ZodCheckOverwrite", (inst, def) => {
$ZodCheck.init(inst, def);
inst._zod.check = (payload) => {
payload.value = def.tx(payload.value);
};
});
var Doc = class {
constructor(args = [], closed = {}) {
this.content = [];
this.indent = 0;
this.args = args;
this.closed = closed;
}
indented(fn) {
this.indent += 1;
try {
fn(this);
} finally {
this.indent -= 1;
}
}
write(arg) {
if (typeof arg === "function") {
arg(this, { execution: "sync" });
arg(this, { execution: "async" });
return;
}
const lines = arg.split("\n").filter((x) => x);
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
const dedented = lines
.map((x) => x.slice(minIndent))
.map((x) => " ".repeat(this.indent * 2) + x);
for (const line of dedented) this.content.push(line);
}
compile() {
const F = Function;
const content = this?.content ?? [``];
return new F(
...Object.keys(this.closed),
`return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`,
)(...Object.values(this.closed));
}
};
const version = {
major: 4,
minor: 6,
patch: 5,
};
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);
});
const $ZodGUID = $constructor("$ZodGUID", (inst, def) => {
def.pattern ?? (def.pattern = guid);
$ZodStringFormat.init(inst, def);
});
const $ZodUUID = $constructor("$ZodUUID", (inst, def) => {
if (def.version) {
const v = {
v1: 1,
v2: 2,
v3: 3,
v4: 4,
v5: 5,
v6: 6,
v7: 7,
v8: 8,
}[def.version];
if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
def.pattern ?? (def.pattern = uuid(v));
} else def.pattern ?? (def.pattern = uuid());
$ZodStringFormat.init(inst, def);
});
const $ZodEmail = $constructor("$ZodEmail", (inst, def) => {
def.pattern ?? (def.pattern = email);
$ZodStringFormat.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 $ZodEmoji = $constructor("$ZodEmoji", (inst, def) => {
def.pattern ?? (def.pattern = emoji());
$ZodStringFormat.init(inst, def);
});
const $ZodNanoID = $constructor("$ZodNanoID", (inst, def) => {
if (def.length !== void 0 && (!Number.isInteger(def.length) || def.length < 1))
throw new Error(`Invalid nanoid length: ${def.length}`);
def.pattern ?? (def.pattern = def.length === void 0 ? nanoid : nanoidOfLength(def.length));
$ZodStringFormat.init(inst, def);
});
const $ZodCUID = $constructor("$ZodCUID", (inst, def) => {
def.pattern ?? (def.pattern = cuid);
$ZodStringFormat.init(inst, def);
});
const $ZodCUID2 = $constructor("$ZodCUID2", (inst, def) => {
def.pattern ?? (def.pattern = cuid2);
$ZodStringFormat.init(inst, def);
});
const $ZodULID = $constructor("$ZodULID", (inst, def) => {
def.pattern ?? (def.pattern = ulid);
$ZodStringFormat.init(inst, def);
});
const $ZodXID = $constructor("$ZodXID", (inst, def) => {
def.pattern ?? (def.pattern = xid);
$ZodStringFormat.init(inst, def);
});
const $ZodKSUID = $constructor("$ZodKSUID", (inst, def) => {
def.pattern ?? (def.pattern = ksuid);
$ZodStringFormat.init(inst, def);
});
const $ZodISODateTime = $constructor("$ZodISODateTime", (inst, def) => {
def.pattern ?? (def.pattern = datetime(def));
$ZodStringFormat.init(inst, def);
});
const $ZodISODate = $constructor("$ZodISODate", (inst, def) => {
def.pattern ?? (def.pattern = date$1);
$ZodStringFormat.init(inst, def);
});
const $ZodISOTime = $constructor("$ZodISOTime", (inst, def) => {
def.pattern ?? (def.pattern = time(def));
$ZodStringFormat.init(inst, def);
});
const $ZodISODuration = $constructor("$ZodISODuration", (inst, def) => {
def.pattern ?? (def.pattern = duration);
$ZodStringFormat.init(inst, def);
});
const $ZodIPv4 = $constructor("$ZodIPv4", (inst, def) => {
def.pattern ?? (def.pattern = ipv4);
$ZodStringFormat.init(inst, def);
});
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
function isValidIPv6(value) {
if (!ipv6Alphabet.test(value)) return false;
return canParseURL(`http://[${value}]`);
}
const $ZodIPv6 = $constructor("$ZodIPv6", (inst, def) => {
def.pattern ?? (def.pattern = ipv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidIPv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "ipv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodCIDRv4 = $constructor("$ZodCIDRv4", (inst, def) => {
def.pattern ?? (def.pattern = cidrv4);
$ZodStringFormat.init(inst, def);
});
function isValidCIDRv6(value) {
const parts = value.split("/");
if (parts.length !== 2) return false;
const [address, prefix] = parts;
if (!prefix) return false;
const prefixNum = Number(prefix);
if (`${prefixNum}` !== prefix) return false;
if (prefixNum < 0 || prefixNum > 128) return false;
return isValidIPv6(address);
}
const $ZodCIDRv6 = $constructor("$ZodCIDRv6", (inst, def) => {
def.pattern ?? (def.pattern = cidrv6);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (!isValidCIDRv6(payload.value))
payload.issues.push({
code: "invalid_format",
format: "cidrv6",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
function isValidBase64(data) {
if (data === "") return true;
if (/\s/.test(data)) return false;
if (data.length % 4 !== 0) return false;
try {
atob(data);
return true;
} catch {
return false;
}
}
const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
const $ZodBase64 = $constructor("$ZodBase64", (inst, def) => {
def.pattern ?? (def.pattern = base64Charset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const base64urlCharset = /^[A-Za-z0-9_-]*$/;
function isValidBase64URL(data) {
if (!base64urlCharset.test(data)) return false;
const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
}
const $ZodBase64URL = $constructor("$ZodBase64URL", (inst, def) => {
def.pattern ?? (def.pattern = base64urlCharset);
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidBase64URL(payload.value)) return;
payload.issues.push({
code: "invalid_format",
format: "base64url",
input: payload.value,
inst,
continue: !def.abort,
});
};
});
const $ZodE164 = $constructor("$ZodE164", (inst, def) => {
def.pattern ?? (def.pattern = e164);
$ZodStringFormat.init(inst, def);
});
function isValidJWT(token, algorithm = null) {
try {
const tokensParts = token.split(".");
if (tokensParts.length !== 3) return false;
const [header] = tokensParts;
if (!header) return false;
const parsedHeader = JSON.parse(atob(header));
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
if (!parsedHeader.alg) return false;
if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
return true;
} catch {
return false;
}
}
const $ZodJWT = $constructor("$ZodJWT", (inst, def) => {
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
if (isValidJWT(payload.value, def.alg)) return;
payload.issues.push({
code: "invalid_format",
format: "jwt",
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 $ZodNumberFormat = $constructor("$ZodNumberFormat", (inst, def) => {
$ZodCheckNumberFormat.init(inst, def);
$ZodNumber.init(inst, def);
});
const $ZodUnknown = $constructor("$ZodUnknown", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload) => payload;
});
const $ZodNever = $constructor("$ZodNever", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
payload.issues.push({
expected: "never",
code: "invalid_type",
input: payload.value,
inst,
});
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 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;
};
});
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$2 = 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$2(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 $ZodObjectJIT = $constructor("$ZodObjectJIT", (inst, def) => {
$ZodObject.init(inst, def);
const superParse = inst._zod.parse;
const _normalized = cached(() => normalizeDef(def));
const memo = globalConfig.memoizer;
const generateFastpass = (shape) => {
const normalized = _normalized.value;
const syms = normalized.symbolKeys;
const doc = new Doc(["payload", "ctx"], {
shape,
inst,
memo,
syms,
});
const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
const prefixStr = (id, k) => `
let ${id}_ab = false;
for (let i = 0; i < ${id}.issues.length; i++) {
const iss = ${id}.issues[i];
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
payload.issues.push(iss);
if (iss.continue !== true) ${id}_ab = true;
}
if (${id}_ab && ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}`;
doc.write(`const input = payload.value;`);
const ids = Object.create(null);
let counter = 0;
for (const key of normalized.allKeys) ids[key] = `key_${counter++}`;
doc.write(
memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`,
);
for (const key of normalized.allKeys) {
if (key === "__proto__") continue;
const id = ids[key];
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc(key);
const isPresent = `${k} in input`;
const schema = shape[key];
const optin = schema?._zod?.optin;
const isOptionalIn = optin !== void 0;
const isOptionalOut = schema?._zod?.optout === "optional";
doc.write(`const ${id} = ${parseStr(k)};`);
if (isOptionalIn && isOptionalOut) {
const assign =
optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
doc.write(`
const ${id}_present = ${isPresent};
if (!${id}.issues.length || ${id}_present) {
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (${assign}) {
newResult[${k}] = ${id}.value;
}
}
`);
} else if (!isOptionalIn)
doc.write(`
const ${id}_present = ${isPresent};
if (${id}.issues.length) {${prefixStr(id, k)}
}
if (!${id}_present && !${id}.issues.length) {
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [${k}]
});
if (ctx && ctx.abortEarly) {
payload.value = newResult;
return payload;
}
}
if (${id}_present) {
newResult[${k}] = ${id}.value;
}
`);
else {
doc.write(`
if (${id}.issues.length) {${prefixStr(id, k)}
}
`);
if (optin === "defaulted") doc.write(`newResult[${k}] = ${id}.value;`);
else
doc.write(`
if (${id}.value !== undefined || ${isPresent}) {
newResult[${k}] = ${id}.value;
}
`);
}
}
doc.write(`payload.value = newResult;`);
doc.write(`return payload;`);
return doc.compile();
};
let fastpass;
const isObject$1 = isObject;
const jit = !globalConfig.jitless;
const fastEnabled = jit && allowsEval.value;
const catchall = def.catchall;
let value;
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;
}
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
if (!fastpass) fastpass = generateFastpass(def.shape);
payload = fastpass(payload, ctx);
if (!catchall) return payload;
return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
}
return superParse(payload, ctx);
};
});
function handleUnionResults(results, final, inst, ctx) {
for (const result of results)
if (result.issues.length === 0) {
final.value = result.value;
return final;
}
const nonaborted = results.filter((r) => !aborted(r));
if (nonaborted.length === 1) {
final.value = nonaborted[0].value;
return nonaborted[0];
}
final.issues.push({
code: "invalid_union",
input: final.value,
inst,
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config()))),
});
return final;
}
const $ZodUnion = $constructor("$ZodUnion", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.options.some((o) => o._zod.optin === "defaulted")
? "defaulted"
: zod.def.options.some((o) => o._zod.optin !== void 0)
? "optional"
: void 0,
);
defineLazyInternal(inst, "optout", (zod) =>
zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0,
);
defineLazyInternal(inst, "values", (zod) => {
if (zod.def.options.every((o) => o._zod.values))
return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
});
defineLazyInternal(inst, "pattern", (zod) => {
if (zod.def.options.every((o) => o._zod.pattern)) {
const patterns = zod.def.options.map((o) => o._zod.pattern);
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
}
});
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
inst._zod.parse = (payload, ctx) => {
if (first) return first(payload, ctx);
let async = false;
const results = [];
for (const option of def.options) {
const result = option._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise) {
results.push(result);
async = true;
} else {
if (result.issues.length === 0) return result;
results.push(result);
}
}
if (!async) return handleUnionResults(results, payload, inst, ctx);
return Promise.all(results).then((results) => {
return handleUnionResults(results, payload, inst, ctx);
});
};
});
const $ZodIntersection = $constructor("$ZodIntersection", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
const left = def.left._zod.run(
{
value: input,
issues: [],
},
ctx,
);
const right = def.right._zod.run(
{
value: input,
issues: [],
},
ctx,
);
if (left instanceof Promise || right instanceof Promise)
return Promise.all([left, right]).then(([left, right]) => {
return handleIntersectionResults(payload, left, right);
});
return handleIntersectionResults(payload, left, right);
};
});
function mergeValues(a, b) {
if (a === b)
return {
valid: true,
data: a,
};
if (a instanceof Date && b instanceof Date && +a === +b)
return {
valid: true,
data: a,
};
if (isPlainObject(a) && isPlainObject(b)) {
const bKeys = Object.keys(b);
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
const newObj = {
...a,
...b,
};
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
for (const key of sharedKeys) {
if (key === "__proto__") continue;
const sharedValue = mergeValues(a[key], b[key]);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
};
newObj[key] = sharedValue.data;
}
return {
valid: true,
data: newObj,
};
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length)
return {
valid: false,
mergeErrorPath: [],
};
const newArray = [];
for (let index = 0; index < a.length; index++) {
const itemA = a[index];
const itemB = b[index];
const sharedValue = mergeValues(itemA, itemB);
if (!sharedValue.valid)
return {
valid: false,
mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
};
newArray.push(sharedValue.data);
}
return {
valid: true,
data: newArray,
};
}
return {
valid: false,
mergeErrorPath: [],
};
}
function handleIntersectionResults(result, left, right) {
const unrecKeys = new Map();
let unrecIssue;
const keyIssues = new Map();
const collect = (iss, side) => {
let keys;
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
unrecIssue ?? (unrecIssue = iss);
keys = iss.keys;
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
const k = String(iss.path[0]);
if (!keyIssues.has(k)) keyIssues.set(k, iss);
keys = [k];
} else return false;
for (const k of keys) {
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
unrecKeys.get(k)[side] = true;
}
return true;
};
for (const iss of left.issues) if (!collect(iss, "l")) result.issues.push(iss);
for (const iss of right.issues) if (!collect(iss, "r")) result.issues.push(iss);
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
if (bothKeys.length) {
const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
if (aggregated.length)
result.issues.push({
...unrecIssue,
keys: aggregated,
});
for (const k of bothKeys)
if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k));
}
const merged = mergeValues(left.value, right.value);
if (!merged.valid) {
if (aborted(result)) return result;
throw new Error(
`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`,
);
}
result.value = merged.data;
return result;
}
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 $ZodTransform = $constructor("$ZodTransform", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "optional";
globalConfig.memoizer?.guard(inst);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
const _out = def.transform(payload.value, payload);
if (ctx.async)
return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
payload.value = output;
return payload;
});
if (_out instanceof Promise) throw new $ZodAsyncError();
payload.value = _out;
return payload;
};
});
function handleOptionalResult(payload, result) {
payload.value = result.issues.length ? void 0 : result.value;
return payload;
}
const $ZodOptional = $constructor("$ZodOptional", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional",
);
inst._zod.optout = "optional";
defineLazyInternal(inst, "values", (zod) => {
const values = zod.def.innerType._zod.values;
return values ? new Set([...values, void 0]) : void 0;
});
defineLazyInternal(inst, "pattern", (zod) => {
const pattern = zod.def.innerType._zod.pattern;
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
});
inst._zod.parse = (payload, ctx) => {
if (payload.value === void 0) {
if (def.innerType._zod.optin !== "defaulted") return payload;
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) => handleOptionalResult(payload, result));
return handleOptionalResult(payload, result);
}
return def.innerType._zod.run(payload, ctx);
};
});
const $ZodExactOptional = $constructor("$ZodExactOptional", (inst, def) => {
$ZodOptional.init(inst, def);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
inst._zod.parse = (payload, ctx) => {
return def.innerType._zod.run(payload, ctx);
};
});
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);
};
});
const $ZodDefault = $constructor("$ZodDefault", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0) {
payload.value = def.defaultValue;
return payload;
}
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
return handleDefaultResult(result, def);
};
});
function handleDefaultResult(payload, def) {
if (payload.value === void 0) payload.value = def.defaultValue;
return payload;
}
const $ZodPrefault = $constructor("$ZodPrefault", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "defaulted";
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
if (payload.value === void 0) payload.value = def.defaultValue;
return def.innerType._zod.run(payload, ctx);
};
});
const $ZodNonOptional = $constructor("$ZodNonOptional", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "values", (zod) => {
const v = zod.def.innerType._zod.values;
return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
});
inst._zod.parse = (payload, ctx) => {
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((result) => handleNonOptionalResult(result, inst));
return handleNonOptionalResult(result, inst);
};
});
function handleNonOptionalResult(payload, inst) {
if (!payload.issues.length && payload.value === void 0)
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: payload.value,
inst,
});
return payload;
}
function handleCatchResult(payload, result, def, ctx) {
if (!result.issues.length) {
payload.value = result.value;
if (result.memo) payload.memo = true;
return payload;
}
payload.value = def.catchValue({
...result,
value: payload.value,
error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
input: payload.value,
});
return payload;
}
const $ZodCatch = $constructor("$ZodCatch", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "optin", (zod) =>
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional",
);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(
{
value: payload.value,
issues: [],
},
ctx,
);
if (result instanceof Promise)
return result.then((result) => handleCatchResult(payload, result, def, ctx));
return handleCatchResult(payload, result, def, ctx);
};
});
const $ZodPipe = $constructor("$ZodPipe", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
const right = def.out._zod.run(payload, ctx);
if (right instanceof Promise)
return right.then((right) => handlePipeResult(right, def.in, ctx));
return handlePipeResult(right, def.in, ctx);
}
const left = def.in._zod.run(payload, ctx);
if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
return handlePipeResult(left, def.out, ctx);
};
});
function handlePipeResult(left, next, ctx) {
if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
left.aborted = true;
return left;
}
return next._zod.run(
{
value: left.value,
issues: left.issues,
},
ctx,
);
}
const $ZodReadonly = $constructor("$ZodReadonly", (inst, def) => {
$ZodType.init(inst, def);
defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) return result.then(handleReadonlyResult);
return handleReadonlyResult(result);
};
});
function handleReadonlyResult(payload) {
if (!payload.memo) payload.value = Object.freeze(payload.value);
return payload;
}
const $ZodCustom = $constructor("$ZodCustom", (inst, def) => {
$ZodCheck.init(inst, def);
$ZodType.init(inst, def);
inst._zod.parse = (payload, _) => {
return payload;
};
inst._zod.check = (payload) => {
const input = payload.value;
const r = def.fn(input);
if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
handleRefineResult(r, payload, input, inst);
};
});
function handleRefineResult(result, payload, input, inst) {
if (!result) {
const _iss = {
code: "custom",
input,
inst,
path: [...(inst._zod.def.path ?? [])],
continue: !inst._zod.def.abort,
};
if (inst._zod.def.params) _iss.params = inst._zod.def.params;
payload.issues.push(issue(_iss));
}
}
var $ZodCyclicError = class extends Error {
constructor() {
super(`Cannot parse a reference cycle that closes through a transform`);
this.name = "ZodCyclicError";
}
};
const STATE = "~memo";
const NO_ISSUES = [];
function isRef(value) {
return value !== null && typeof value === "object";
}
function cloneIssues(issues) {
return issues.map((iss) =>
iss.path
? {
...iss,
path: iss.path.slice(),
}
: { ...iss },
);
}
const recursive = new WeakMap();
const NONE = 0;
const ASSUMED = 1;
const PROVEN = 2;
function isRecursive(inst, stack, resolve) {
const cached = recursive.get(inst);
if (cached !== void 0) return cached ? PROVEN : NONE;
if (stack.has(inst)) return PROVEN;
stack.add(inst);
let result = NONE;
const check = (child) => {
if (result !== PROVEN && child?._zod) {
const answer = isRecursive(child, stack, resolve);
if (answer > result) result = answer;
}
};
const shape = (sh, spread) => {
let answer = NONE;
for (const key of Reflect.ownKeys(sh)) {
const desc = Object.getOwnPropertyDescriptor(sh, key);
if (spread && !desc.enumerable) continue;
const child = desc.get
? ASSUMED
: desc.value?._zod
? isRecursive(desc.value, stack, resolve)
: NONE;
if (child > answer) answer = child;
}
return answer;
};
const merge = (answer) => {
if (answer > result) result = answer;
};
const def = inst._zod.def;
switch (def.type) {
case "object": {
const raw = rawShape(def);
merge(raw ? shape(raw, true) : ASSUMED);
check(def.catchall);
break;
}
case "array":
check(def.element);
break;
case "tuple":
for (const el of def.items) check(el);
check(def.rest);
break;
case "record":
case "map":
check(def.keyType);
check(def.valueType);
break;
case "set":
check(def.valueType);
break;
case "union":
for (const el of def.options) check(el);
break;
case "intersection":
check(def.left);
check(def.right);
break;
case "optional":
case "nullable":
case "default":
case "prefault":
case "catch":
case "readonly":
case "nonoptional":
case "promise":
case "success":
check(def.innerType);
break;
case "pipe":
check(def.in);
check(def.out);
break;
case "function":
check(def.input);
check(def.output);
break;
case "lazy": {
const inner = def._cachedInner ?? (resolve ? inst._zod.innerType : void 0);
merge(inner ? isRecursive(inner, stack, false) : ASSUMED);
break;
}
case "template_literal":
case "string":
case "number":
case "int":
case "boolean":
case "bigint":
case "symbol":
case "undefined":
case "null":
case "void":
case "never":
case "any":
case "unknown":
case "date":
case "nan":
case "enum":
case "literal":
case "file":
case "transform":
case "custom":
break;
default:
for (const key in def) {
const desc = Object.getOwnPropertyDescriptor(def, key);
if (!desc || desc.get) continue;
const value = desc.value;
if (!value || typeof value !== "object") continue;
if (value._zod) check(value);
else if (Array.isArray(value)) for (const el of value) check(el);
}
}
stack.delete(inst);
return settle(inst, result);
}
function settle(inst, answer) {
if (answer !== ASSUMED) recursive.set(inst, answer === PROVEN);
return answer;
}
function bucketFor(state, inst) {
let bucket = state.buckets.get(inst);
if (!bucket) {
bucket = new WeakMap();
state.buckets.set(inst, bucket);
}
return bucket;
}
let handoff;
const open = [];
const memo = {
alloc(_inst, payload, empty) {
const bucket = handoff;
if (!bucket) return empty;
handoff = void 0;
const entry = {
value: empty,
issues: null,
};
bucket.set(payload.value, entry);
open.push(entry);
return empty;
},
guard(inst) {
var _a;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (ctx.direction !== "backward" && isBackEdge(ctx, payload.value))
throw new $ZodCyclicError();
return base(payload, ctx);
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
attach(inst) {
var _a;
let isRecursiveInst;
let rechecked = false;
let lastCtx;
let lastBucket;
(_a = inst._zod).deferred ?? (_a.deferred = []);
inst._zod.deferred.push(() => {
const base = inst._zod.parse;
const wrapped = (payload, ctx) => {
if (isRecursiveInst === void 0) {
const walked = isRecursive(inst, new Set(), false);
if (walked === NONE) {
inst._zod.parse = base;
if (inst._zod.run === wrapped) inst._zod.run = base;
return base(payload, ctx);
}
if (walked === PROVEN || rechecked) isRecursiveInst = true;
else rechecked = true;
}
const input = payload.value;
if (!isRef(input)) return base(payload, ctx);
let state = ctx[STATE];
if (!state) {
state = {
buckets: new WeakMap(),
backEdges: void 0,
};
ctx[STATE] = state;
}
let bucket;
if (lastCtx === ctx) bucket = lastBucket;
else {
bucket = bucketFor(state, inst);
lastCtx = ctx;
lastBucket = bucket;
}
const hit = bucket.get(input);
if (hit) {
payload.value = hit.value;
if (hit.issues) {
if (hit.issues.length) payload.issues.push(...cloneIssues(hit.issues));
} else {
payload.memo = true;
state.backEdges ?? (state.backEdges = new WeakSet());
state.backEdges.add(hit.value);
}
return payload;
}
handoff = bucket;
const depth = open.length;
const result = base(payload, ctx);
handoff = void 0;
const entry = open.length > depth ? open.pop() : void 0;
if (result instanceof Promise)
return result.then((r) => {
if (entry) entry.issues = r.issues.length ? cloneIssues(r.issues) : NO_ISSUES;
return r;
});
if (entry) entry.issues = result.issues.length ? cloneIssues(result.issues) : NO_ISSUES;
return result;
};
inst._zod.parse = wrapped;
if (inst._zod.run === base) inst._zod.run = wrapped;
});
},
};
function memoizer() {
return memo;
}
function isBackEdge(ctx, value) {
const backEdges = ctx[STATE]?.backEdges;
return backEdges !== void 0 && isRef(value) && backEdges.has(value);
}
const error = () => {
const Sizable = {
string: {
unit: "characters",
verb: "to have",
},
file: {
unit: "bytes",
verb: "to have",
},
array: {
unit: "items",
verb: "to have",
},
set: {
unit: "items",
verb: "to have",
},
map: {
unit: "entries",
verb: "to have",
},
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const FormatDictionary = {
regex: "input",
email: "email address",
url: "URL",
emoji: "emoji",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO datetime",
date: "ISO date",
time: "ISO time",
duration: "ISO duration",
ipv4: "IPv4 address",
ipv6: "IPv6 address",
mac: "MAC address",
cidrv4: "IPv4 range",
cidrv6: "IPv6 range",
base64: "base64-encoded string",
base64url: "base64url-encoded string",
json_string: "JSON string",
e164: "E.164 number",
currency_code: "currency code",
credit_card: "credit card number",
iban: "IBAN",
jwt: "JWT",
template_literal: "input",
};
const TypeDictionary = { nan: "NaN" };
function getTypeName(type, input) {
if (type === "number" && typeof input === "number" && !Number.isFinite(input))
return String(input);
return TypeDictionary[type] ?? type;
}
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `Invalid input: expected ${getTypeName(issue.expected)}, received ${getTypeName(parsedType(issue.input), issue.input)}`;
case "invalid_value":
if (issue.values.length === 1)
return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.exact ? "exactly " : issue.inclusive ? "<=" : "<";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.exact ? "exactly " : issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
if (sizing)
return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
if (_issue.format === "starts_with")
return `Invalid string: must start with "${_issue.prefix}"`;
if (_issue.format === "ends_with")
return `Invalid string: must end with "${_issue.suffix}"`;
if (_issue.format === "includes")
return `Invalid string: must include "${_issue.includes}"`;
if (_issue.format === "regex")
return `Invalid string: must match pattern ${_issue.pattern}`;
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `Invalid number: must be a multiple of ${issue.divisor}`;
case "unrecognized_keys":
return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `Invalid key in ${issue.origin}`;
case "invalid_union":
if (issue.options && Array.isArray(issue.options) && issue.options.length > 0)
return `Invalid discriminator value. Expected ${issue.options.map((o) => `'${o}'`).join(" | ")}`;
if (issue.inclusive === false) return "Invalid input: more than one option matched";
return "Invalid input";
case "invalid_element":
return `Invalid value in ${issue.origin}`;
default:
return `Invalid input`;
}
};
};
function en_default() {
return { localeError: error() };
}
var _a;
var $ZodRegistry = class {
constructor() {
this._map = new WeakMap();
this._idmap = new Map();
}
add(schema, ..._meta) {
const meta = _meta[0];
this._map.set(schema, meta);
if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
return this;
}
clear() {
this._map = new WeakMap();
this._idmap = new Map();
return this;
}
remove(schema) {
const meta = this._map.get(schema);
if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
this._map.delete(schema);
return this;
}
get(schema) {
const p = schema._zod.parent;
if (p) {
const pm = { ...(this.get(p) ?? {}) };
delete pm.id;
const f = {
...pm,
...this._map.get(schema),
};
return Object.keys(f).length ? f : void 0;
}
return this._map.get(schema);
}
has(schema) {
return this._map.has(schema);
}
};
function registry() {
return new $ZodRegistry();
}
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
const globalRegistry = globalThis.__zod_globalRegistry;
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 _email(Class, params) {
return new Class({
type: "string",
format: "email",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _guid(Class, params) {
return new Class({
type: "string",
format: "guid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuid(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _uuidv4(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v4",
...normalizeParams(params),
});
}
function _uuidv6(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v6",
...normalizeParams(params),
});
}
function _uuidv7(Class, params) {
return new Class({
type: "string",
format: "uuid",
check: "string_format",
abort: false,
version: "v7",
...normalizeParams(params),
});
}
function _url(Class, params) {
return new Class({
type: "string",
format: "url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _emoji(Class, params) {
return new Class({
type: "string",
format: "emoji",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _nanoid(Class, params) {
return new Class({
type: "string",
format: "nanoid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid(Class, params) {
return new Class({
type: "string",
format: "cuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cuid2(Class, params) {
return new Class({
type: "string",
format: "cuid2",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ulid(Class, params) {
return new Class({
type: "string",
format: "ulid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _xid(Class, params) {
return new Class({
type: "string",
format: "xid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ksuid(Class, params) {
return new Class({
type: "string",
format: "ksuid",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv4(Class, params) {
return new Class({
type: "string",
format: "ipv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _ipv6(Class, params) {
return new Class({
type: "string",
format: "ipv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv4(Class, params) {
return new Class({
type: "string",
format: "cidrv4",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _cidrv6(Class, params) {
return new Class({
type: "string",
format: "cidrv6",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64(Class, params) {
return new Class({
type: "string",
format: "base64",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _base64url(Class, params) {
return new Class({
type: "string",
format: "base64url",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _e164(Class, params) {
return new Class({
type: "string",
format: "e164",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _jwt(Class, params) {
return new Class({
type: "string",
format: "jwt",
check: "string_format",
abort: false,
...normalizeParams(params),
});
}
function _isoDateTime(Class, params) {
return new Class({
type: "string",
format: "datetime",
check: "string_format",
offset: false,
local: false,
precision: null,
...normalizeParams(params),
});
}
function _isoDate(Class, params) {
return new Class({
type: "string",
format: "date",
check: "string_format",
...normalizeParams(params),
});
}
function _isoTime(Class, params) {
return new Class({
type: "string",
format: "time",
check: "string_format",
precision: null,
...normalizeParams(params),
});
}
function _isoDuration(Class, params) {
return new Class({
type: "string",
format: "duration",
check: "string_format",
...normalizeParams(params),
});
}
function _number(Class, params) {
return new Class(
snapshotChecks({
type: "number",
checks: [],
...normalizeParams(params),
}),
);
}
function _int(Class, params) {
return new Class({
type: "number",
check: "number_format",
abort: false,
format: "safeint",
...normalizeParams(params),
});
}
function _unknown(Class) {
return new Class({ type: "unknown" });
}
function _never(Class, params) {
return new Class({
type: "never",
...normalizeParams(params),
});
}
function _date(Class, params) {
return new Class({
type: "date",
...normalizeParams(params),
});
}
function _lt(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _lte(value, params) {
return new $ZodCheckLessThan({
check: "less_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _gt(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: false,
});
}
function _gte(value, params) {
return new $ZodCheckGreaterThan({
check: "greater_than",
...normalizeParams(params),
value,
inclusive: true,
});
}
function _multipleOf(value, params) {
return new $ZodCheckMultipleOf({
check: "multiple_of",
...normalizeParams(params),
value,
});
}
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,
});
}
function _length(length, params) {
return new $ZodCheckLengthEquals({
check: "length_equals",
...normalizeParams(params),
length,
});
}
function _regex(pattern, params) {
return new $ZodCheckRegex({
check: "string_format",
format: "regex",
...normalizeParams(params),
pattern,
});
}
function _lowercase(params) {
return new $ZodCheckLowerCase({
check: "string_format",
format: "lowercase",
...normalizeParams(params),
});
}
function _uppercase(params) {
return new $ZodCheckUpperCase({
check: "string_format",
format: "uppercase",
...normalizeParams(params),
});
}
function _includes(includes, params) {
return new $ZodCheckIncludes({
check: "string_format",
format: "includes",
...normalizeParams(params),
includes,
});
}
function _startsWith(prefix, params) {
return new $ZodCheckStartsWith({
check: "string_format",
format: "starts_with",
...normalizeParams(params),
prefix,
});
}
function _endsWith(suffix, params) {
return new $ZodCheckEndsWith({
check: "string_format",
format: "ends_with",
...normalizeParams(params),
suffix,
});
}
function _overwrite(tx) {
return new $ZodCheckOverwrite({
check: "overwrite",
tx,
});
}
function _normalize(form) {
return _overwrite((input) => input.normalize(form));
}
function _trim() {
return _overwrite((input) => input.trim());
}
function _toLowerCase() {
return _overwrite((input) => input.toLowerCase());
}
function _toUpperCase() {
return _overwrite((input) => input.toUpperCase());
}
function _slugify() {
return _overwrite((input) => slugify(input));
}
function _array(Class, element, params) {
return new Class({
type: "array",
element,
...normalizeParams(params),
});
}
function _refine(Class, fn, _params) {
return new Class({
type: "custom",
check: "custom",
fn,
...normalizeParams(_params),
});
}
function _superRefine(fn, params) {
const ch = _check((payload) => {
payload.addIssue = (issue$2) => {
if (typeof issue$2 === "string")
payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
else {
const _issue = issue$2;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue)) _issue.input = payload.value;
_issue.inst ?? (_issue.inst = ch);
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
payload.issues.push(issue(_issue));
}
};
return fn(payload.value, payload);
}, params);
return ch;
}
function _check(fn, params) {
const ch = new $ZodCheck({
check: "custom",
...normalizeParams(params),
});
ch._zod.check = fn;
return ch;
}
function assignProps(target, ...sources) {
for (const source of sources)
for (const key of Reflect.ownKeys(source))
if (Object.prototype.propertyIsEnumerable.call(source, key))
assignProp(target, key, source[key]);
return target;
}
function initializeContext(params) {
let target = params?.target ?? "draft-2020-12";
if (target === "draft-4") target = "draft-04";
if (target === "draft-7") target = "draft-07";
return {
processors: params.processors ?? {},
metadataRegistry: params?.metadata ?? globalRegistry,
target,
unrepresentable: params?.unrepresentable ?? "throw",
override: params?.override ?? (() => {}),
io: params?.io ?? "output",
counter: 0,
seen: new Map(),
sharedDefsExtractedFor: void 0,
sharedEmitDoneFor: void 0,
cycles: params?.cycles ?? "ref",
reused: params?.reused ?? "inline",
intersections: [],
deferred: [],
external: params?.external ?? void 0,
};
}
function handleUnrepresentable(schema, ctx, json, params, message) {
const result =
typeof ctx.unrepresentable === "function"
? ctx.unrepresentable({
zodSchema: schema,
path: params.path,
message,
})
: ctx.unrepresentable;
if (result === "any") return false;
if (result === void 0 || result === "throw") throw new Error(message);
Object.assign(json, result);
return true;
}
function processSchema(
schema,
ctx,
_params = {
path: [],
schemaPath: [],
},
) {
var _a;
const def = schema._zod.def;
const seen = ctx.seen.get(schema);
if (seen) {
seen.count++;
if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
return seen.schema;
}
const result = {
schema: {},
count: 1,
cycle: void 0,
path: _params.path,
};
ctx.seen.set(schema, result);
ctx.sharedDefsExtractedFor = void 0;
ctx.sharedEmitDoneFor = void 0;
const overrideSchema = schema._zod.toJSONSchema?.();
if (overrideSchema) result.schema = overrideSchema;
else {
const params = {
..._params,
schemaPath: [..._params.schemaPath, schema],
path: _params.path,
};
if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
else {
const _json = result.schema;
const processor = ctx.processors[def.type];
if (!processor)
throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
processor(schema, ctx, _json, params);
}
const parent = schema._zod.parent;
if (parent) {
if (!result.ref) result.ref = parent;
processSchema(parent, ctx, params);
ctx.seen.get(parent).isParent = true;
}
}
const meta = ctx.metadataRegistry.get(schema);
if (meta) assignProps(result.schema, meta);
if (ctx.io === "input" && isTransforming(schema)) {
delete result.schema.examples;
delete result.schema.default;
}
if (ctx.io === "input" && "_prefault" in result.schema)
(_a = result.schema).default ?? (_a.default = result.schema._prefault);
delete result.schema._prefault;
return ctx.seen.get(schema).schema;
}
function encodeJSONPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function extractDefs(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
if (ctx.external && ctx.sharedDefsExtractedFor === ctx.external) return;
const idToSchema = new Map();
for (const entry of ctx.seen.entries()) {
const id = ctx.metadataRegistry.get(entry[0])?.id;
if (id) {
const existing = idToSchema.get(id);
if (existing && existing !== entry[0])
throw new Error(
`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`,
);
idToSchema.set(id, entry[0]);
}
}
const makeURI = (entry) => {
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
if (ctx.external) {
const externalId = ctx.external.registry.get(entry[0])?.id;
const uriGenerator = ctx.external.uri ?? ((id) => id);
if (externalId) return { ref: uriGenerator(externalId) };
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
entry[1].defId = id;
return {
defId: id,
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`,
};
}
const uriPrefix = `#`;
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
if (entry[1] === root && !entry[1].schema.id) return { ref: uriPrefix };
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
return {
defId,
ref: defUriPrefix + encodeJSONPointerSegment(defId),
};
};
const extractToDef = (entry) => {
if (entry[1].schema.$ref) return;
const seen = entry[1];
const { ref, defId } = makeURI(entry);
seen.def = { ...seen.schema };
if (defId) seen.defId = defId;
const schema = seen.schema;
for (const key in schema) delete schema[key];
schema.$ref = ref;
};
if (ctx.cycles === "throw")
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.cycle)
throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
}
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (schema === entry[0]) {
extractToDef(entry);
continue;
}
if (ctx.external) {
const ext = ctx.external.registry.get(entry[0])?.id;
if (schema !== entry[0] && ext) {
extractToDef(entry);
continue;
}
}
if (ctx.metadataRegistry.get(entry[0])?.id) {
extractToDef(entry);
continue;
}
if (seen.cycle) {
extractToDef(entry);
continue;
}
if (seen.count > 1) {
if (ctx.reused === "ref") extractToDef(entry);
}
}
if (ctx.external) ctx.sharedDefsExtractedFor = ctx.external;
}
function compactTypeUnion(schema) {
const options = schema.anyOf;
if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0) return;
const types = [];
for (const option of options) {
if (!option || typeof option !== "object") return;
compactTypeUnion(option);
const keys = Object.keys(option);
if (keys.length !== 1 || keys[0] !== "type") return;
const type = option.type;
for (const member of Array.isArray(type) ? type : [type]) {
if (typeof member !== "string") return;
if (!types.includes(member)) types.push(member);
}
}
delete schema.anyOf;
schema.type = types.length === 1 ? types[0] : types;
}
const FOLDABLE_KEYS = new Set([
"type",
"properties",
"required",
"additionalProperties",
]);
const UNION_KEYS = ["oneOf", "anyOf"];
function undeclaredConstraint(member) {
const extra = member.additionalProperties;
if (extra === void 0 || extra === false || typeof extra !== "object" || extra === null)
return null;
return Object.keys(extra).length ? extra : null;
}
function foldObjects(members) {
const objects = [];
for (const member of members) {
if (typeof member !== "object" || member.type !== "object") return null;
for (const key in member) if (!FOLDABLE_KEYS.has(key)) return null;
objects.push(member);
}
const properties = {};
const required = new Set();
for (const object of objects) {
for (const key in object.properties) {
if (Object.prototype.hasOwnProperty.call(properties, key)) continue;
const parts = [];
for (const other of objects) {
const part = other.properties?.[key] ?? undeclaredConstraint(other);
if (part === null || part === void 0) continue;
if (!parts.some((seen) => JSON.stringify(seen) === JSON.stringify(part))) parts.push(part);
}
assignProp(
properties,
key,
parts.length === 1 ? parts[0] : (foldObjects(parts) ?? { allOf: parts }),
);
}
for (const key of object.required ?? []) required.add(key);
}
const folded = {
type: "object",
properties,
};
if (required.size) folded.required = [...required];
if (objects.every((object) => object.additionalProperties === false))
folded.additionalProperties = false;
else {
const constraints = [];
for (const object of objects) {
const constraint = undeclaredConstraint(object);
if (
constraint &&
!constraints.some((seen) => JSON.stringify(seen) === JSON.stringify(constraint))
)
constraints.push(constraint);
}
if (constraints.length === 1) folded.additionalProperties = constraints[0];
else if (constraints.length > 1) folded.additionalProperties = { allOf: constraints };
}
return folded;
}
function foldIntersection(json) {
const allOf = json.allOf;
if (!Array.isArray(allOf) || allOf.length < 2) return;
for (const key of FOLDABLE_KEYS) if (key in json) return;
const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
let folded = null;
if (!unions.length) folded = foldObjects(allOf);
else {
const union = unions[0];
const keyword = UNION_KEYS.find((k) => Array.isArray(union[k]));
if (Object.keys(union).length !== 1) return;
const rest = allOf.filter((m) => m !== union);
const branches = union[keyword].map((branch) => foldObjects([...rest, branch]));
if (branches.some((b) => !b)) return;
folded = { [keyword]: branches };
}
if (!folded) return;
delete json.allOf;
assignProps(json, folded);
}
function finalize(ctx, schema) {
const root = ctx.seen.get(schema);
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
const flattenRef = (zodSchema) => {
const seen = ctx.seen.get(zodSchema);
if (seen.ref === null) return;
const schema = seen.def ?? seen.schema;
const _cached = { ...schema };
const ref = seen.ref;
seen.ref = null;
if (ref) {
flattenRef(ref);
const refSeen = ctx.seen.get(ref);
const refSchema = refSeen.schema;
if (
refSchema.$ref &&
(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")
) {
schema.allOf = schema.allOf ?? [];
schema.allOf.push(refSchema);
} else assignProps(schema, refSchema);
assignProps(schema, _cached);
if (zodSchema._zod.parent === ref)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (!(key in _cached)) delete schema[key];
}
if (refSchema.$ref && refSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in refSeen.def &&
JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])
)
delete schema[key];
}
}
const parent = zodSchema._zod.parent;
if (parent && parent !== ref) {
flattenRef(parent);
const parentSeen = ctx.seen.get(parent);
if (parentSeen?.schema.$ref) {
schema.$ref = parentSeen.schema.$ref;
if (parentSeen.def)
for (const key in schema) {
if (key === "$ref" || key === "allOf") continue;
if (
key in parentSeen.def &&
JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])
)
delete schema[key];
}
}
}
ctx.override({
zodSchema,
jsonSchema: schema,
path: seen.path ?? [],
});
};
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) {
for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
if (ctx.target !== "openapi-3.0")
for (const entry of ctx.seen.entries()) compactTypeUnion(entry[1].def ?? entry[1].schema);
for (const rewrite of ctx.deferred) rewrite();
if (ctx.intersections.length) {
const carriers = new Map();
for (const seen of ctx.seen.values())
for (const json of [seen.schema, seen.def]) {
const allOf = json?.allOf;
if (!Array.isArray(allOf)) continue;
const existing = carriers.get(allOf);
if (existing) existing.push(json);
else carriers.set(allOf, [json]);
}
for (const allOf of ctx.intersections)
for (const json of carriers.get(allOf) ?? []) foldIntersection(json);
}
}
const result = {};
if (ctx.target === "draft-2020-12")
result.$schema = "https://json-schema.org/draft/2020-12/schema";
else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
else if (ctx.target === "openapi-3.0") {
}
if (ctx.external?.uri) {
const id = ctx.external.registry.get(schema)?.id;
if (!id) throw new Error("Schema is missing an `id` property");
result.$id = ctx.external.uri(id);
}
assignProps(result, root.defId ? root.schema : (root.def ?? root.schema));
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
const defs = ctx.external?.defs ?? {};
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external)
for (const entry of ctx.seen.entries()) {
const seen = entry[1];
if (seen.def && seen.defId) {
if (seen.def.id === seen.defId) delete seen.def.id;
assignProp(defs, seen.defId, seen.def);
}
}
if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
if (ctx.external) {
} else if (Object.keys(defs).length > 0) {
if (ctx.target === "draft-2020-12") result.$defs = defs;
else result.definitions = defs;
}
try {
const finalized = JSON.parse(JSON.stringify(result));
Object.defineProperty(finalized, "~standard", {
value: {
...schema["~standard"],
jsonSchema: {
input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
output: createStandardJSONSchemaMethod(schema, "output", ctx.processors),
},
},
enumerable: false,
writable: false,
});
return finalized;
} catch (_err) {
throw new Error("Error converting schema to JSON.");
}
}
function isTransforming(_schema, _ctx) {
const ctx = _ctx ?? { seen: new Set() };
if (ctx.seen.has(_schema)) return false;
ctx.seen.add(_schema);
const def = _schema._zod.def;
if (def.type === "transform") return true;
if (def.type === "array") return isTransforming(def.element, ctx);
if (def.type === "set") return isTransforming(def.valueType, ctx);
if (def.type === "lazy") return isTransforming(def.getter(), ctx);
if (
def.type === "promise" ||
def.type === "optional" ||
def.type === "nonoptional" ||
def.type === "nullable" ||
def.type === "readonly" ||
def.type === "default" ||
def.type === "prefault" ||
def.type === "catch"
)
return isTransforming(def.innerType, ctx);
if (def.type === "intersection")
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
if (def.type === "record" || def.type === "map")
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
if (def.type === "pipe") {
if (_schema._zod.traits.has("$ZodCodec")) return true;
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
}
if (def.type === "object") {
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
return false;
}
if (def.type === "union") {
for (const option of def.options) if (isTransforming(option, ctx)) return true;
return false;
}
if (def.type === "tuple") {
for (const item of def.items) if (isTransforming(item, ctx)) return true;
if (def.rest && isTransforming(def.rest, ctx)) return true;
return false;
}
return false;
}
const createToJSONSchemaMethod =
(schema, processors = {}) =>
(params) => {
const ctx = initializeContext({
...params,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const createStandardJSONSchemaMethod =
(schema, io, processors = {}) =>
(params) => {
const { libraryOptions, target } = params ?? {};
const ctx = initializeContext({
...(libraryOptions ?? {}),
target,
io,
processors,
});
processSchema(schema, ctx);
extractDefs(ctx, schema);
return finalize(ctx, schema);
};
const narrowMin = (agg, key, value) => {
if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
};
const narrowMax = (agg, key, value) => {
if (agg[key] === void 0 || value < agg[key]) agg[key] = value;
};
const narrowBoth = (agg, value) => {
narrowMin(agg, "minimum", value);
narrowMax(agg, "maximum", value);
};
const addDivisor = (agg, value) => {
agg.multipleOf ?? (agg.multipleOf = []);
if (!agg.multipleOf.includes(value)) agg.multipleOf.push(value);
};
const addPattern = (agg, pattern) => {
agg.patterns ?? (agg.patterns = new Set());
agg.patterns.add(pattern);
};
const intersectMime = (agg, mime) => {
agg.mime = agg.mime ? agg.mime.filter((m) => mime.includes(m)) : [...mime];
};
const setFormat = (agg, format) => {
agg.format = format;
if (format.includes("int")) agg.isInt = true;
};
const minContributor = (agg, def) => narrowMin(agg, "minimum", def.minimum);
const maxContributor = (agg, def) => narrowMax(agg, "maximum", def.maximum);
const formatContributor = (ranges) => (agg, def) => {
setFormat(agg, def.format);
const [minimum, maximum] = ranges[def.format];
narrowMin(agg, "minimum", minimum);
narrowMax(agg, "maximum", maximum);
};
const contributors = {
greater_than: (agg, def) =>
narrowMin(agg, def.inclusive ? "minimum" : "exclusiveMinimum", def.value),
less_than: (agg, def) =>
narrowMax(agg, def.inclusive ? "maximum" : "exclusiveMaximum", def.value),
multiple_of: (agg, def) => addDivisor(agg, def.value),
number_format: formatContributor(NUMBER_FORMAT_RANGES),
bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
min_length: minContributor,
max_length: maxContributor,
length_equals: (agg, def) => narrowBoth(agg, def.length),
min_size: minContributor,
max_size: maxContributor,
size_equals: (agg, def) => narrowBoth(agg, def.size),
string_format: (agg, def) => {
setFormat(agg, def.format);
if (def.pattern) addPattern(agg, def.pattern);
if (def.format === "base64" || def.format === "base64url") agg.contentEncoding = def.format;
if (def.local || def.precision === -1) agg.laxFormat = true;
},
mime_type: (agg, def) => intersectMime(agg, def.mime),
};
function aggregateChecks(schema) {
const agg = {};
const def = schema._zod.def;
const list = schema._zod.traits.has("$ZodCheck")
? [schema, ...(def.checks ?? [])]
: (def.checks ?? []);
for (const ch of list) contributors[ch._zod.def.check]?.(agg, ch._zod.def);
const bag = schema._zod.bag;
if (bag.minimum !== void 0) narrowMin(agg, "minimum", bag.minimum);
if (bag.exclusiveMinimum !== void 0) narrowMin(agg, "exclusiveMinimum", bag.exclusiveMinimum);
if (bag.maximum !== void 0) narrowMax(agg, "maximum", bag.maximum);
if (bag.exclusiveMaximum !== void 0) narrowMax(agg, "exclusiveMaximum", bag.exclusiveMaximum);
if (bag.multipleOf !== void 0) addDivisor(agg, bag.multipleOf);
if (bag.format !== void 0) {
agg.format ?? (agg.format = bag.format);
if (bag.format.includes("int")) agg.isInt = true;
}
if (bag.mime) intersectMime(agg, bag.mime);
for (const pattern of bag.patterns ?? []) addPattern(agg, pattern);
return agg;
}
const formatMap = {
guid: "uuid",
url: "uri",
datetime: "date-time",
json_string: "json-string",
regex: "",
};
const exactPatterns = new Map([
[base64Charset, base64],
[base64urlCharset, base64url],
]);
const exactPattern = (p) => exactPatterns.get(p) ?? p;
const stringProcessor = (schema, ctx, _json, _params) => {
const json = _json;
json.type = "string";
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } =
aggregateChecks(schema);
if (typeof minimum === "number") json.minLength = minimum;
if (typeof maximum === "number") json.maxLength = maximum;
if (format) {
json.format = formatMap[format] ?? format;
if (json.format === "") delete json.format;
if (format === "time" || laxFormat) delete json.format;
}
if (contentEncoding) json.contentEncoding = contentEncoding;
if (patterns && patterns.size > 0) {
const patternList = [...patterns].map(exactPattern);
if (patternList.length === 1) json.pattern = patternList[0].source;
else if (patternList.length > 1)
json.allOf = [
...patternList.map((regex) => ({
...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
? { type: "string" }
: {}),
pattern: regex.source,
})),
];
}
};
const numberProcessor = (schema, ctx, _json, params) => {
const json = _json;
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } =
aggregateChecks(schema);
json.type = isInt ? "integer" : "number";
const exMin =
typeof exclusiveMinimum === "number" &&
exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
const exMax =
typeof exclusiveMaximum === "number" &&
exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
if (exMin) {
if (legacy) {
json.minimum = exclusiveMinimum;
json.exclusiveMinimum = true;
} else json.exclusiveMinimum = exclusiveMinimum;
} else if (typeof minimum === "number") json.minimum = minimum;
if (exMax) {
if (legacy) {
json.maximum = exclusiveMaximum;
json.exclusiveMaximum = true;
} else json.exclusiveMaximum = exclusiveMaximum;
} else if (typeof maximum === "number") json.maximum = maximum;
if (multipleOf) {
const divisors = new Set();
for (const divisor of multipleOf)
if (Number.isFinite(divisor) && divisor !== 0) divisors.add(Math.abs(divisor));
else
handleUnrepresentable(
schema,
ctx,
json,
params,
`A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`,
);
const [first, ...rest] = divisors;
if (first !== void 0) json.multipleOf = first;
if (rest.length) json.allOf = [...(json.allOf ?? []), ...rest.map((m) => ({ multipleOf: m }))];
}
};
const neverProcessor = (_schema, _ctx, json, _params) => {
json.not = {};
};
const dateProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(schema, ctx, json, params, "Date cannot be represented in JSON Schema");
};
const enumProcessor = (schema, _ctx, json, _params) => {
const def = schema._zod.def;
const values = getEnumValues(def.entries);
if (values.length === 0) {
json.not = {};
return;
}
if (values.every((v) => typeof v === "number")) json.type = "number";
if (values.every((v) => typeof v === "string")) json.type = "string";
json.enum = values;
};
const customProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Custom types cannot be represented in JSON Schema",
);
};
const transformProcessor = (schema, ctx, json, params) => {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Transforms cannot be represented in JSON Schema",
);
};
const arrayProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const { minimum, maximum } = aggregateChecks(schema);
if (typeof minimum === "number") json.minItems = minimum;
if (typeof maximum === "number") json.maxItems = maximum;
json.type = "array";
json.items = processSchema(def.element, ctx, {
...params,
path: [...params.path, "items"],
});
};
function inputOptin(schema) {
const def = schema._zod.def;
if (def.type === "pipe" && def.in._zod.traits.has("$ZodTransform")) return inputOptin(def.out);
if (def.type === "catch") return inputOptin(def.innerType);
return schema._zod.optin;
}
const objectProcessor = (schema, ctx, _json, params) => {
const json = _json;
const def = schema._zod.def;
const shape = def.shape;
if (
Object.getOwnPropertySymbols(shape).length &&
handleUnrepresentable(
schema,
ctx,
json,
params,
"Symbol keys cannot be represented in JSON Schema",
)
)
return;
json.type = "object";
json.properties = {};
for (const key in shape)
assignProp(
json.properties,
key,
processSchema(shape[key], ctx, {
...params,
path: [...params.path, "properties", key],
}),
);
const requiredKeys = [];
for (const key of Object.keys(shape)) {
const field = def.shape[key];
if (ctx.io === "input" ? inputOptin(field) === void 0 : field._zod.optout === void 0)
requiredKeys.push(key);
}
if (requiredKeys.length > 0) json.required = requiredKeys;
if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
else if (!def.catchall) {
if (ctx.io === "output") json.additionalProperties = false;
} else if (def.catchall)
json.additionalProperties = processSchema(def.catchall, ctx, {
...params,
path: [...params.path, "additionalProperties"],
});
};
const unionProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const isExclusive = def.inclusive === false;
const options = def.options.map((x, i) =>
processSchema(x, ctx, {
...params,
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
}),
);
if (isExclusive) json.oneOf = options;
else json.anyOf = options;
};
const intersectionProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const a = processSchema(def.left, ctx, {
...params,
path: [...params.path, "allOf", 0],
});
const b = processSchema(def.right, ctx, {
...params,
path: [...params.path, "allOf", 1],
});
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
const allOf = [
...(isSimpleIntersection(a) ? a.allOf : [a]),
...(isSimpleIntersection(b) ? b.allOf : [b]),
];
json.allOf = allOf;
ctx.intersections.push(allOf);
};
const nullableProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
const inner = processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
if (ctx.target === "openapi-3.0") {
seen.ref = def.innerType;
json.nullable = true;
} else json.anyOf = [inner, { type: "null" }];
};
const nonoptionalProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const UNREPRESENTABLE_DEFAULT = Symbol();
function serializeDefaultValue(value, schema, ctx, json, params) {
let unrepresentable = false;
const serialized = JSON.stringify(value, (_, val) => {
if (typeof val !== "bigint") return val;
unrepresentable = true;
return null;
});
if (!unrepresentable) return JSON.parse(serialized);
handleUnrepresentable(
schema,
ctx,
json,
params,
"BigInt defaults cannot be represented in JSON Schema",
);
return UNREPRESENTABLE_DEFAULT;
}
const defaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
if (value !== UNREPRESENTABLE_DEFAULT) json.default = value;
};
const prefaultProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
if (ctx.io !== "input") return;
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
if (value !== UNREPRESENTABLE_DEFAULT) json._prefault = value;
};
const catchProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
let catchValue;
try {
catchValue = def.catchValue(void 0);
} catch {
handleUnrepresentable(
schema,
ctx,
json,
params,
"Dynamic catch values are not supported in JSON Schema",
);
return;
}
json.default = catchValue;
};
const pipeProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
const innerType = ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
processSchema(innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = innerType;
};
const readonlyProcessor = (schema, ctx, json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
json.readOnly = true;
};
const optionalProcessor = (schema, ctx, _json, params) => {
const def = schema._zod.def;
processSchema(def.innerType, ctx, params);
const seen = ctx.seen.get(schema);
seen.ref = def.innerType;
};
const _installedErrorProtos = new WeakSet([Object.prototype, Error.prototype]);
function _lazyMethod(proto, key, make) {
Object.defineProperty(proto, key, {
configurable: true,
enumerable: false,
get() {
const value = make(this);
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
return value;
},
set(value) {
Object.defineProperty(this, key, {
value,
configurable: true,
writable: true,
});
},
});
}
const initializer = (inst, issues) => {
$ZodError.init(inst, issues);
inst.name = "ZodError";
const proto = Object.getPrototypeOf(inst);
if (_installedErrorProtos.has(proto)) return;
_installedErrorProtos.add(proto);
_lazyMethod(proto, "format", (self) => (mapper) => formatError(self, mapper));
_lazyMethod(proto, "flatten", (self) => (mapper) => flattenError(self, mapper));
_lazyMethod(proto, "addIssue", (self) => (issue) => {
self.issues.push(issue);
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
});
_lazyMethod(proto, "addIssues", (self) => (issues) => {
self.issues.push(...issues);
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
});
Object.defineProperty(proto, "isEmpty", {
configurable: true,
enumerable: false,
get() {
return this.issues.length === 0;
},
});
};
const ZodRealError = $constructor("ZodError", initializer, void 0, { Parent: Error });
const parse = _parse(ZodRealError);
const parseAsync = _parseAsync(ZodRealError);
const safeParse = _safeParse(ZodRealError);
const safeParseAsync = _safeParseAsync(ZodRealError);
const encode = _encode(ZodRealError);
const decode = _decode(ZodRealError);
const encodeAsync = _encodeAsync(ZodRealError);
const decodeAsync = _decodeAsync(ZodRealError);
const safeEncode = _safeEncode(ZodRealError);
const safeDecode = _safeDecode(ZodRealError);
const safeEncodeAsync = _safeEncodeAsync(ZodRealError);
const safeDecodeAsync = _safeDecodeAsync(ZodRealError);
function _ensureDefaultLocale() {
if (!globalConfig.localeError) config(en_default());
}
function _ensureDefaultMemoizer() {
if (!globalConfig.memoizer) config({ memoizer: memoizer() });
}
const ZodType = $constructor(
"ZodType",
(inst, def) => {
_ensureDefaultLocale();
$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
return inst;
},
{
check(...chks) {
const def = this.def;
return this.clone(
mergeDefs(def, {
checks: [
...(def.checks ?? []),
...chks.map((ch) =>
typeof ch === "function"
? {
_zod: {
check: ch,
def: { check: "custom" },
onattach: [],
},
}
: ch,
),
],
}),
{ parent: true },
);
},
with(...chks) {
return this.check(...chks);
},
clone(def, params) {
return clone(this, def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
refine(check, params) {
return this.check(refine(check, params));
},
superRefine(refinement, params) {
return this.check(superRefine(refinement, params));
},
overwrite(fn) {
return this.check( _overwrite(fn));
},
optional() {
return optional(this);
},
exactOptional() {
return exactOptional(this);
},
nullable() {
return nullable(this);
},
nullish() {
return optional(nullable(this));
},
nonoptional(params) {
return nonoptional(this, params);
},
array() {
return array(this);
},
or(arg) {
return union([this, arg]);
},
and(arg) {
return intersection(this, arg);
},
transform(tx) {
return pipe(this, transform(tx));
},
default(d) {
return _default(this, d);
},
prefault(d) {
return prefault(this, d);
},
catch(params) {
return _catch(this, params);
},
pipe(target) {
return pipe(this, target);
},
readonly() {
return readonly(this);
},
describe(description) {
const cl = this.clone();
globalRegistry.add(cl, { description });
return cl;
},
meta(...args) {
if (args.length === 0) return globalRegistry.get(this);
const cl = this.clone();
globalRegistry.add(cl, args[0]);
return cl;
},
isOptional() {
return this.safeParse(void 0).success;
},
isNullable() {
return this.safeParse(null).success;
},
apply(fn, ...args) {
return args.length === 0 ? fn(this) : fn(this, ...args);
},
get "~standard"() {
return hide(this, "~standard", {
...standardProps(this),
jsonSchema: {
input: createStandardJSONSchemaMethod(this, "input"),
output: createStandardJSONSchemaMethod(this, "output"),
},
});
},
set "~standard"(value) {
own(this, "~standard", value);
},
parse: function _parse(data, params) {
return parse(this, data, params, { callee: _parse });
},
parseAsync: async function _parseAsync(data, params) {
return await parseAsync(this, data, params, { callee: _parseAsync });
},
safeParse(data, params) {
return safeParse(this, data, params);
},
async safeParseAsync(data, params) {
return safeParseAsync(this, data, params);
},
get spa() {
return this?.safeParseAsync;
},
set spa(value) {
own(this, "spa", value);
},
validate(data, params) {
return validate(this, data, params);
},
validateAsync(data, params) {
return validateAsync$1(this, data, params);
},
encode: function _encode(data, params) {
return encode(this, data, params, { callee: _encode });
},
decode: function _decode(data, params) {
return decode(this, data, params, { callee: _decode });
},
encodeAsync: async function _encodeAsync(data, params) {
return await encodeAsync(this, data, params, { callee: _encodeAsync });
},
decodeAsync: async function _decodeAsync(data, params) {
return await decodeAsync(this, data, params, { callee: _decodeAsync });
},
safeEncode(data, params) {
return safeEncode(this, data, params);
},
safeDecode(data, params) {
return safeDecode(this, data, params);
},
async safeEncodeAsync(data, params) {
return safeEncodeAsync(this, data, params);
},
async safeDecodeAsync(data, params) {
return safeDecodeAsync(this, data, params);
},
toJSONSchema(params) {
return createToJSONSchemaMethod(this, {})(params);
},
get description() {
return globalRegistry.get(this)?.description;
},
get _def() {
return this._zod.def;
},
},
);
const _ZodString = $constructor(
"_ZodString",
(inst, def) => {
$ZodString.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
},
derived(
{
format: (inst) => aggregateChecks(inst).format ?? null,
minLength: (inst) => aggregateChecks(inst).minimum ?? null,
maxLength: (inst) => aggregateChecks(inst).maximum ?? null,
},
{
regex(...args) {
return this.check( _regex(...args));
},
includes(...args) {
return this.check( _includes(...args));
},
startsWith(...args) {
return this.check( _startsWith(...args));
},
endsWith(...args) {
return this.check( _endsWith(...args));
},
min(...args) {
return this.check( _minLength(...args));
},
max(...args) {
return this.check( _maxLength(...args));
},
length(...args) {
return this.check( _length(...args));
},
nonempty(...args) {
return this.check( _minLength(1, ...args));
},
lowercase(params) {
return this.check( _lowercase(params));
},
uppercase(params) {
return this.check( _uppercase(params));
},
trim() {
return this.check( _trim());
},
normalize(...args) {
return this.check( _normalize(...args));
},
toLowerCase() {
return this.check( _toLowerCase());
},
toUpperCase() {
return this.check( _toUpperCase());
},
slugify() {
return this.check( _slugify());
},
},
),
);
const ZodString = $constructor(
"ZodString",
(inst, def) => {
$ZodString.init(inst, def);
_ZodString.init(inst, def);
},
{
email(params) {
return this.check( _email(ZodEmail, params));
},
url(params) {
return this.check( _url(ZodURL, params));
},
jwt(params) {
return this.check( _jwt(ZodJWT, params));
},
emoji(params) {
return this.check( _emoji(ZodEmoji, params));
},
guid(params) {
return this.check( _guid(ZodGUID, params));
},
uuid(params) {
return this.check( _uuid(ZodUUID, params));
},
uuidv4(params) {
return this.check( _uuidv4(ZodUUID, params));
},
uuidv6(params) {
return this.check( _uuidv6(ZodUUID, params));
},
uuidv7(params) {
return this.check( _uuidv7(ZodUUID, params));
},
nanoid(params) {
return this.check( _nanoid(ZodNanoID, params));
},
cuid(params) {
return this.check( _cuid(ZodCUID, params));
},
cuid2(params) {
return this.check( _cuid2(ZodCUID2, params));
},
ulid(params) {
return this.check( _ulid(ZodULID, params));
},
base64(params) {
return this.check( _base64(ZodBase64, params));
},
base64url(params) {
return this.check( _base64url(ZodBase64URL, params));
},
xid(params) {
return this.check( _xid(ZodXID, params));
},
ksuid(params) {
return this.check( _ksuid(ZodKSUID, params));
},
ipv4(params) {
return this.check( _ipv4(ZodIPv4, params));
},
ipv6(params) {
return this.check( _ipv6(ZodIPv6, params));
},
cidrv4(params) {
return this.check( _cidrv4(ZodCIDRv4, params));
},
cidrv6(params) {
return this.check( _cidrv6(ZodCIDRv6, params));
},
e164(params) {
return this.check( _e164(ZodE164, params));
},
datetime(params) {
return this.check( _isoDateTime(ZodISODateTime, params));
},
date(params) {
return this.check( _isoDate(ZodISODate, params));
},
time(params) {
return this.check( _isoTime(ZodISOTime, params));
},
duration(params) {
return this.check( _isoDuration(ZodISODuration, params));
},
},
);
function string(params) {
return _string(ZodString, params);
}
const ZodStringFormat = $constructor("ZodStringFormat", (inst, def) => {
$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
});
const ZodISODateTime = $constructor("ZodISODateTime", (inst, def) => {
$ZodISODateTime.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodISODate = $constructor("ZodISODate", (inst, def) => {
$ZodISODate.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodISOTime = $constructor("ZodISOTime", (inst, def) => {
$ZodISOTime.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodISODuration = $constructor("ZodISODuration", (inst, def) => {
$ZodISODuration.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodEmail = $constructor("ZodEmail", (inst, def) => {
$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodGUID = $constructor("ZodGUID", (inst, def) => {
$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodUUID = $constructor("ZodUUID", (inst, def) => {
$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodURL = $constructor("ZodURL", (inst, def) => {
$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
});
function url(params) {
return _url(ZodURL, params);
}
const ZodEmoji = $constructor("ZodEmoji", (inst, def) => {
$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodNanoID = $constructor("ZodNanoID", (inst, def) => {
$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCUID = $constructor("ZodCUID", (inst, def) => {
$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCUID2 = $constructor("ZodCUID2", (inst, def) => {
$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodULID = $constructor("ZodULID", (inst, def) => {
$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodXID = $constructor("ZodXID", (inst, def) => {
$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodKSUID = $constructor("ZodKSUID", (inst, def) => {
$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodIPv4 = $constructor("ZodIPv4", (inst, def) => {
$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodIPv6 = $constructor("ZodIPv6", (inst, def) => {
$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCIDRv4 = $constructor("ZodCIDRv4", (inst, def) => {
$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodCIDRv6 = $constructor("ZodCIDRv6", (inst, def) => {
$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodBase64 = $constructor("ZodBase64", (inst, def) => {
$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodBase64URL = $constructor("ZodBase64URL", (inst, def) => {
$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodE164 = $constructor("ZodE164", (inst, def) => {
$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodJWT = $constructor("ZodJWT", (inst, def) => {
$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
});
const ZodNumber = $constructor(
"ZodNumber",
(inst, def) => {
$ZodNumber.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json, params);
inst.isFinite = true;
},
derived(
{
minValue: (inst) => {
const { minimum, exclusiveMinimum } = aggregateChecks(inst);
return Math.max(
minimum ?? Number.NEGATIVE_INFINITY,
exclusiveMinimum ?? Number.NEGATIVE_INFINITY,
);
},
maxValue: (inst) => {
const { maximum, exclusiveMaximum } = aggregateChecks(inst);
return Math.min(
maximum ?? Number.POSITIVE_INFINITY,
exclusiveMaximum ?? Number.POSITIVE_INFINITY,
);
},
isInt: (inst) => {
const { isInt, multipleOf } = aggregateChecks(inst);
return !!isInt || !!multipleOf?.some(Number.isSafeInteger);
},
format: (inst) => aggregateChecks(inst).format ?? null,
},
{
gt(value, params) {
return this.check( _gt(value, params));
},
gte(value, params) {
return this.check( _gte(value, params));
},
min(value, params) {
return this.check( _gte(value, params));
},
lt(value, params) {
return this.check( _lt(value, params));
},
lte(value, params) {
return this.check( _lte(value, params));
},
max(value, params) {
return this.check( _lte(value, params));
},
int(params) {
return this.check(int(params));
},
safe(params) {
return this.check(int(params));
},
positive(params) {
return this.check( _gt(0, params));
},
nonnegative(params) {
return this.check( _gte(0, params));
},
negative(params) {
return this.check( _lt(0, params));
},
nonpositive(params) {
return this.check( _lte(0, params));
},
multipleOf(value, params) {
return this.check( _multipleOf(value, params));
},
step(value, params) {
return this.check( _multipleOf(value, params));
},
finite() {
return this;
},
},
),
);
function number(params) {
return _number(ZodNumber, params);
}
const ZodNumberFormat = $constructor("ZodNumberFormat", (inst, def) => {
$ZodNumberFormat.init(inst, def);
ZodNumber.init(inst, def);
});
function int(params) {
return _int(ZodNumberFormat, params);
}
const ZodUnknown = $constructor("ZodUnknown", (inst, def) => {
$ZodUnknown.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => void 0;
});
function unknown() {
return _unknown(ZodUnknown);
}
const ZodNever = $constructor("ZodNever", (inst, def) => {
$ZodNever.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
});
function never(params) {
return _never(ZodNever, params);
}
const ZodDate = $constructor(
"ZodDate",
(inst, def) => {
$ZodDate.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => dateProcessor(inst, ctx, json, params);
inst.min = (value, params) => inst.check( _gte(value, params));
inst.max = (value, params) => inst.check( _lte(value, params));
},
derived(
{
minDate: (inst) => {
const { minimum } = aggregateChecks(inst);
return minimum ? new Date(minimum) : null;
},
maxDate: (inst) => {
const { maximum } = aggregateChecks(inst);
return maximum ? new Date(maximum) : null;
},
},
{},
),
);
function date(params) {
return _date(ZodDate, params);
}
const ZodArray = $constructor(
"ZodArray",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodArray.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
inst.element = def.element;
},
{
min(n, params) {
return this.check( _minLength(n, params));
},
nonempty(params) {
return this.check( _minLength(1, params));
},
max(n, params) {
return this.check( _maxLength(n, params));
},
length(n, params) {
return this.check( _length(n, params));
},
unwrap() {
return this.element;
},
},
);
function array(element, params) {
return _array(ZodArray, element, params);
}
const ZodObject = $constructor(
"ZodObject",
(inst, def) => {
_ensureDefaultMemoizer();
$ZodObjectJIT.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
},
{
keyof() {
return _enum(Object.keys(this._zod.def.shape));
},
catchall(catchall) {
return this.clone(mergeDefs(this._zod.def, { catchall }));
},
passthrough() {
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
},
loose() {
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
},
strict() {
return this.clone(mergeDefs(this._zod.def, { catchall: never() }));
},
strip() {
return this.clone(mergeDefs(this._zod.def, { catchall: void 0 }));
},
extend(incoming) {
return extend(this, incoming);
},
safeExtend(incoming) {
return safeExtend(this, incoming);
},
merge(other) {
return merge(this, other);
},
pick(mask) {
return pick(this, mask);
},
omit(mask) {
return omit(this, mask);
},
partial(...args) {
return partial(ZodOptional, this, args[0]);
},
exactPartial(...args) {
return partial(ZodExactOptional, this, args[0], "exactPartial");
},
required(...args) {
return required(ZodNonOptional, this, args[0]);
},
},
);
function object(shape, params) {
const def = {
type: "object",
shape: shape ?? {},
...normalizeParams(params),
};
return new ZodObject(def);
}
const ZodUnion = $constructor("ZodUnion", (inst, def) => {
$ZodUnion.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
inst.options = def.options;
});
function union(options, params) {
return new ZodUnion({
type: "union",
options,
...normalizeParams(params),
});
}
const ZodIntersection = $constructor("ZodIntersection", (inst, def) => {
$ZodIntersection.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
intersectionProcessor(inst, ctx, json, params);
});
function intersection(left, right) {
return new ZodIntersection({
type: "intersection",
left,
right,
});
}
const ZodEnum = $constructor("ZodEnum", (inst, def) => {
$ZodEnum.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
inst.enum = def.entries;
inst.options = [...inst._zod.values];
const keys = new Set(Object.keys(def.entries));
inst.extract = (values, params) => {
const newEntries = {};
for (const value of values)
if (keys.has(value)) newEntries[value] = def.entries[value];
else throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
inst.exclude = (values, params) => {
const newEntries = { ...def.entries };
for (const value of values)
if (keys.has(value)) delete newEntries[value];
else throw new Error(`Key ${value} not found in enum`);
return new ZodEnum({
...def,
checks: [],
...normalizeParams(params),
entries: newEntries,
});
};
});
function _enum(values, params) {
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
return new ZodEnum({
type: "enum",
entries,
...normalizeParams(params),
});
}
const ZodTransform = $constructor("ZodTransform", (inst, def) => {
_ensureDefaultMemoizer();
$ZodTransform.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
inst._zod.parse = (payload, _ctx) => {
if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
payload.addIssue = (issue$1) => {
if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
else {
const _issue = issue$1;
if (_issue.fatal) _issue.continue = false;
_issue.code ?? (_issue.code = "custom");
if (!("input" in _issue)) _issue.input = payload.value;
_issue.inst ?? (_issue.inst = inst);
payload.issues.push(issue(_issue));
}
};
const output = def.transform(payload.value, payload);
if (output instanceof Promise)
return output.then((output) => {
payload.value = output;
return payload;
});
payload.value = output;
return payload;
};
});
function transform(fn) {
return new ZodTransform({
type: "transform",
transform: fn,
});
}
const ZodOptional = $constructor("ZodOptional", (inst, def) => {
$ZodOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function optional(innerType) {
return new ZodOptional({
type: "optional",
innerType,
});
}
const ZodExactOptional = $constructor("ZodExactOptional", (inst, def) => {
$ZodExactOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function exactOptional(innerType) {
return new ZodExactOptional({
type: "optional",
innerType,
});
}
const ZodNullable = $constructor("ZodNullable", (inst, def) => {
$ZodNullable.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function nullable(innerType) {
return new ZodNullable({
type: "nullable",
innerType,
});
}
const ZodDefault = $constructor("ZodDefault", (inst, def) => {
$ZodDefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeDefault = inst.unwrap;
});
function _default(innerType, defaultValue) {
return new ZodDefault({
type: "default",
innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
},
});
}
const ZodPrefault = $constructor("ZodPrefault", (inst, def) => {
$ZodPrefault.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function prefault(innerType, defaultValue) {
return new ZodPrefault({
type: "prefault",
innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
},
});
}
const ZodNonOptional = $constructor("ZodNonOptional", (inst, def) => {
$ZodNonOptional.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) =>
nonoptionalProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function nonoptional(innerType, params) {
return new ZodNonOptional({
type: "nonoptional",
innerType,
...normalizeParams(params),
});
}
const ZodCatch = $constructor("ZodCatch", (inst, def) => {
$ZodCatch.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
inst.removeCatch = inst.unwrap;
});
function _catch(innerType, catchValue) {
return new ZodCatch({
type: "catch",
innerType,
catchValue: typeof catchValue === "function" ? catchValue : constantCatch(catchValue),
});
}
const ZodPipe = $constructor("ZodPipe", (inst, def) => {
$ZodPipe.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
inst.in = def.in;
inst.out = def.out;
});
function pipe(in_, out) {
return new ZodPipe({
type: "pipe",
in: in_,
out,
});
}
const ZodReadonly = $constructor("ZodReadonly", (inst, def) => {
$ZodReadonly.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
inst.unwrap = () => inst._zod.def.innerType;
});
function readonly(innerType) {
return new ZodReadonly({
type: "readonly",
innerType,
});
}
const ZodCustom = $constructor("ZodCustom", (inst, def) => {
$ZodCustom.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
});
function refine(fn, _params = {}) {
return _refine(ZodCustom, fn, _params);
}
function superRefine(fn, params) {
return _superRefine(fn, params);
}
function __zcUw(m) {
return typeof m === "string" ? m : m === void 0 || m === null ? void 0 : m.message;
}
var __zcMsg = function (iss) {
var c = config(),
m;
if (c.customError) {
m = __zcUw(c.customError(iss));
if (m !== void 0 && m !== null) return m;
}
if (c.localeError) {
m = __zcUw(c.localeError(iss));
if (m !== void 0 && m !== null) return m;
}
return "Invalid input";
};
function __ZcFail(e, f, i) {
this.success = false;
this._e = e;
this._f = f;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFail.prototype, "error", {
configurable: true,
get: function () {
if (this._c) return this._c;
var e = this._f !== null ? this._f(this._i) : this._e;
for (var i = 0; i < e.length; i++) {
if (e[i].message === void 0 && typeof __zcMsg === "function") e[i].message = __zcMsg(e[i]);
delete e[i].input;
delete e[i].continue;
}
return (this._c = new ZodRealError(e));
},
});
function __ZcFailZ(z, r, i) {
this.success = false;
this._z = z;
this._r = r;
this._i = i;
this._c = void 0;
}
Object.defineProperty(__ZcFailZ.prototype, "error", {
configurable: true,
get: function () {
return this._c || (this._c = this._z.call(this._r, this._i).error);
},
});
function __zcMkv(fn, schema, fc, is) {
var w = schema || {};
var zpa = w.parseAsync,
zspa = w.safeParseAsync;
w.parse = fc
? function (input) {
if (fc(input)) return input;
var r = fn(input);
if (r.success) return r.data;
throw r.error;
}
: function (input) {
var r = fn(input);
if (r.success) return r.data;
throw r.error;
};
w.safeParse = fn;
w.safeParseAsync = function (input) {
try {
return Promise.resolve(fn(input));
} catch (e) {
if (zspa) return zspa(input);
throw e;
}
};
w.parseAsync = fc
? function (input) {
try {
if (fc(input)) return Promise.resolve(input);
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
}
: function (input) {
try {
var r = fn(input);
if (r.success) return Promise.resolve(r.data);
return Promise.reject(r.error);
} catch (e) {
if (zpa) return zpa(input);
throw e;
}
};
w.is =
is ||
function (input) {
return fn(input).success;
};
Object.defineProperty(w, "~standard", {
configurable: true,
value: {
version: 1,
vendor: "zod",
validate: function (input) {
var r;
try {
if (fc && fc(input)) return { value: input };
r = fn(input);
} catch (e) {
if (zspa)
return zspa(input).then(function (q) {
return q.success ? { value: q.data } : { issues: q.error.issues };
});
throw e;
}
return r.success ? { value: r.data } : { issues: r.error.issues };
},
},
});
return w;
}
function __zcFin(e, d) {
if (!e.length)
return {
success: true,
data: d,
};
return new __ZcFail(e, null, null);
}
function __zcTS(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_small",
minimum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcTB(m, o, i, inp, p, msg) {
var r = {
origin: o,
code: "too_big",
maximum: m,
inclusive: i,
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIT(e, inp, p, msg) {
var r = {
expected: e,
code: "invalid_type",
input: inp,
path: p,
};
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIF(o, f, inp, p, extra, msg) {
var r =
o === void 0
? {
code: "invalid_format",
format: f,
}
: {
origin: o,
code: "invalid_format",
format: f,
};
if (extra) Object.assign(r, extra);
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcIV(values, inp, p, extra, msg) {
var r = { code: "invalid_value" };
if (extra) Object.assign(r, extra);
r.values = values;
r.input = inp;
r.path = p;
if (msg !== void 0) r.message = msg;
return r;
}
function __zcLo(v) {
return Array.isArray(v) ? "array" : typeof v === "string" ? "string" : "unknown";
}
function __zcCpl(s) {
var n = s.length;
if (!/[\uD800-\uDBFF]/.test(s)) return n;
var c = n;
for (var i = 0; i < n - 1; i++)
if ((s.charCodeAt(i) & 64512) === 55296 && (s.charCodeAt(i + 1) & 64512) === 56320) {
c--;
i++;
}
return c;
}
var __re_tnl_11 = new RegExp("[\\t\\n\\r]", "g");
function __zcSw_0(input, path, _e) {
if (!Array.isArray(input)) _e.push(__zcIT("array", input, path));
else {
var __ar_0 = input;
__ar_0 = __ar_0.slice();
for (var __i_1 = 0; __i_1 < __ar_0.length; __i_1++)
__ar_0[__i_1] = __zcSw_1(__ar_0[__i_1], path.concat(__i_1), _e);
input = __ar_0;
}
return input;
}
function __zcSw_1(input, path, _e) {
if (typeof input !== "object" || input === null || Array.isArray(input))
_e.push(__zcIT("object", input, path));
else {
var __sv_3 = input["id"];
if (typeof __sv_3 !== "number") _e.push(__zcIT("number", __sv_3, path.concat("id")));
else if (Number.isNaN(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_3,
path: path.concat("id"),
});
else if (!Number.isFinite(__sv_3))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_3),
input: __sv_3,
path: path.concat("id"),
});
var __sv_4 = input["created"];
if (!(__sv_4 instanceof Date)) _e.push(__zcIT("date", __sv_4, path.concat("created")));
else if (isNaN(__sv_4.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_4,
path: path.concat("created"),
});
var __sv_5 = input["title"];
if (typeof __sv_5 !== "string") {
_e.push(__zcIT("string", __sv_5, path.concat("title")));
if (__sv_5 !== void 0 && __sv_5 !== null && __sv_5.length !== void 0) {
if (__sv_5.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_5), true, __sv_5, path.concat("title")));
if (__sv_5.length > 100)
_e.push(__zcTB(100, __zcLo(__sv_5), true, __sv_5, path.concat("title")));
}
} else {
if (__sv_5.length < 1) _e.push(__zcTS(1, "string", true, __sv_5, path.concat("title")));
if (__sv_5.length > 100 && (__sv_5.length > 200 || __zcCpl(__sv_5) > 100))
_e.push(__zcTB(100, "string", true, __sv_5, path.concat("title")));
}
var __sv_6 = input["type"];
if (__sv_6 !== "jpg" && __sv_6 !== "png")
_e.push(__zcIV(["jpg", "png"], __sv_6, path.concat("type")));
var __sv_7 = input["size"];
if (typeof __sv_7 !== "number") _e.push(__zcIT("number", __sv_7, path.concat("size")));
else if (Number.isNaN(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_7,
path: path.concat("size"),
});
else if (!Number.isFinite(__sv_7))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_7),
input: __sv_7,
path: path.concat("size"),
});
var __sv_8 = input["url"];
if (typeof __sv_8 !== "string") _e.push(__zcIT("string", __sv_8, path.concat("url")));
else {
var __ut_9 = __sv_8.trim();
var __u_10 = null;
try {
__u_10 = new URL(__ut_9);
} catch (_) {}
if (__u_10 === null) _e.push(__zcIF(void 0, "url", __sv_8, path.concat("url")));
else __sv_8 = __ut_9.replace(__re_tnl_11, "");
}
input = {
id: __sv_3,
created: __sv_4,
title: __sv_5,
type: __sv_6,
size: __sv_7,
url: __sv_8,
};
}
return input;
}
const imageSchema = object({
id: number(),
created: date(),
title: string().min(1).max(100),
type: _enum(["jpg", "png"]),
size: number(),
url: url(),
});
const ratingSchema = object({
id: number(),
stars: number().min(1).max(5),
title: string().min(1).max(100),
text: string().min(1).max(1e3),
images: array(imageSchema),
});
toZod()(
object({
id: number(),
created: date(),
title: string().min(1).max(100),
brand: string().min(1).max(30),
description: string().min(1).max(500),
price: number().min(1).max(1e4),
discount: number().min(1).max(100).nullable(),
quantity: number().min(0).max(10),
tags: array(string().min(1).max(30)),
images: array(imageSchema),
ratings: array(ratingSchema),
}),
);
(() => {
function safeParse_compiledProductSchema(input) {
var _e = [];
var _d = input;
if (typeof _d !== "object" || _d === null || Array.isArray(_d))
_e.push(__zcIT("object", _d, []));
else {
var __sv_5 = _d["id"];
if (typeof __sv_5 !== "number") _e.push(__zcIT("number", __sv_5, ["id"]));
else if (Number.isNaN(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_5,
path: ["id"],
});
else if (!Number.isFinite(__sv_5))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_5),
input: __sv_5,
path: ["id"],
});
var __sv_6 = _d["created"];
if (!(__sv_6 instanceof Date)) _e.push(__zcIT("date", __sv_6, ["created"]));
else if (isNaN(__sv_6.getTime()))
_e.push({
expected: "date",
code: "invalid_type",
received: "Invalid Date",
input: __sv_6,
path: ["created"],
});
var __sv_7 = _d["title"];
if (typeof __sv_7 !== "string") {
_e.push(__zcIT("string", __sv_7, ["title"]));
if (__sv_7 !== void 0 && __sv_7 !== null && __sv_7.length !== void 0) {
if (__sv_7.length < 1) _e.push(__zcTS(1, __zcLo(__sv_7), true, __sv_7, ["title"]));
if (__sv_7.length > 100) _e.push(__zcTB(100, __zcLo(__sv_7), true, __sv_7, ["title"]));
}
} else {
if (__sv_7.length < 1) _e.push(__zcTS(1, "string", true, __sv_7, ["title"]));
if (__sv_7.length > 100 && (__sv_7.length > 200 || __zcCpl(__sv_7) > 100))
_e.push(__zcTB(100, "string", true, __sv_7, ["title"]));
}
var __sv_8 = _d["brand"];
if (typeof __sv_8 !== "string") {
_e.push(__zcIT("string", __sv_8, ["brand"]));
if (__sv_8 !== void 0 && __sv_8 !== null && __sv_8.length !== void 0) {
if (__sv_8.length < 1) _e.push(__zcTS(1, __zcLo(__sv_8), true, __sv_8, ["brand"]));
if (__sv_8.length > 30) _e.push(__zcTB(30, __zcLo(__sv_8), true, __sv_8, ["brand"]));
}
} else {
if (__sv_8.length < 1) _e.push(__zcTS(1, "string", true, __sv_8, ["brand"]));
if (__sv_8.length > 30 && (__sv_8.length > 60 || __zcCpl(__sv_8) > 30))
_e.push(__zcTB(30, "string", true, __sv_8, ["brand"]));
}
var __sv_9 = _d["description"];
if (typeof __sv_9 !== "string") {
_e.push(__zcIT("string", __sv_9, ["description"]));
if (__sv_9 !== void 0 && __sv_9 !== null && __sv_9.length !== void 0) {
if (__sv_9.length < 1) _e.push(__zcTS(1, __zcLo(__sv_9), true, __sv_9, ["description"]));
if (__sv_9.length > 500)
_e.push(__zcTB(500, __zcLo(__sv_9), true, __sv_9, ["description"]));
}
} else {
if (__sv_9.length < 1) _e.push(__zcTS(1, "string", true, __sv_9, ["description"]));
if (__sv_9.length > 500 && (__sv_9.length > 1e3 || __zcCpl(__sv_9) > 500))
_e.push(__zcTB(500, "string", true, __sv_9, ["description"]));
}
var __sv_10 = _d["price"];
if (typeof __sv_10 !== "number") _e.push(__zcIT("number", __sv_10, ["price"]));
else if (Number.isNaN(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_10,
path: ["price"],
});
else if (!Number.isFinite(__sv_10))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_10),
input: __sv_10,
path: ["price"],
});
else {
if (__sv_10 < 1) _e.push(__zcTS(1, "number", true, __sv_10, ["price"]));
if (__sv_10 > 1e4) _e.push(__zcTB(1e4, "number", true, __sv_10, ["price"]));
}
var __sv_11 = _d["discount"];
if (__sv_11 !== null) {
if (typeof __sv_11 !== "number") _e.push(__zcIT("number", __sv_11, ["discount"]));
else if (Number.isNaN(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_11,
path: ["discount"],
});
else if (!Number.isFinite(__sv_11))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_11),
input: __sv_11,
path: ["discount"],
});
else {
if (__sv_11 < 1) _e.push(__zcTS(1, "number", true, __sv_11, ["discount"]));
if (__sv_11 > 100) _e.push(__zcTB(100, "number", true, __sv_11, ["discount"]));
}
}
var __sv_12 = _d["quantity"];
if (typeof __sv_12 !== "number") _e.push(__zcIT("number", __sv_12, ["quantity"]));
else if (Number.isNaN(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_12,
path: ["quantity"],
});
else if (!Number.isFinite(__sv_12))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_12),
input: __sv_12,
path: ["quantity"],
});
else {
if (__sv_12 < 0) _e.push(__zcTS(0, "number", true, __sv_12, ["quantity"]));
if (__sv_12 > 10) _e.push(__zcTB(10, "number", true, __sv_12, ["quantity"]));
}
var __sv_13 = _d["tags"];
if (!Array.isArray(__sv_13)) _e.push(__zcIT("array", __sv_13, ["tags"]));
else {
var __ar_14 = __sv_13;
for (var __i_15 = 0; __i_15 < __ar_14.length; __i_15++) {
var __mv_16 = __ar_14[__i_15];
if (typeof __mv_16 !== "string") {
_e.push(__zcIT("string", __mv_16, ["tags", __i_15]));
if (__mv_16 !== void 0 && __mv_16 !== null && __mv_16.length !== void 0) {
if (__mv_16.length < 1)
_e.push(__zcTS(1, __zcLo(__mv_16), true, __mv_16, ["tags", __i_15]));
if (__mv_16.length > 30)
_e.push(__zcTB(30, __zcLo(__mv_16), true, __mv_16, ["tags", __i_15]));
}
} else {
if (__mv_16.length < 1) _e.push(__zcTS(1, "string", true, __mv_16, ["tags", __i_15]));
if (__mv_16.length > 30 && (__mv_16.length > 60 || __zcCpl(__mv_16) > 30))
_e.push(__zcTB(30, "string", true, __mv_16, ["tags", __i_15]));
}
}
__sv_13 = __ar_14;
}
var __sv_18 = _d["images"];
__sv_18 = __zcSw_0(__sv_18, ["images"], _e);
var __sv_19 = _d["ratings"];
if (!Array.isArray(__sv_19)) _e.push(__zcIT("array", __sv_19, ["ratings"]));
else {
var __ar_20 = __sv_19;
__ar_20 = __ar_20.slice();
for (var __i_21 = 0; __i_21 < __ar_20.length; __i_21++)
if (
typeof __ar_20[__i_21] !== "object" ||
__ar_20[__i_21] === null ||
Array.isArray(__ar_20[__i_21])
)
_e.push(__zcIT("object", __ar_20[__i_21], ["ratings", __i_21]));
else {
var __sv_23 = __ar_20[__i_21]["id"];
if (typeof __sv_23 !== "number")
_e.push(__zcIT("number", __sv_23, ["ratings", __i_21, "id"]));
else if (Number.isNaN(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
else if (!Number.isFinite(__sv_23))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_23),
input: __sv_23,
path: ["ratings", __i_21, "id"],
});
var __sv_24 = __ar_20[__i_21]["stars"];
if (typeof __sv_24 !== "number")
_e.push(__zcIT("number", __sv_24, ["ratings", __i_21, "stars"]));
else if (Number.isNaN(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: "NaN",
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else if (!Number.isFinite(__sv_24))
_e.push({
expected: "number",
code: "invalid_type",
received: String(__sv_24),
input: __sv_24,
path: ["ratings", __i_21, "stars"],
});
else {
if (__sv_24 < 1)
_e.push(__zcTS(1, "number", true, __sv_24, ["ratings", __i_21, "stars"]));
if (__sv_24 > 5)
_e.push(__zcTB(5, "number", true, __sv_24, ["ratings", __i_21, "stars"]));
}
var __sv_25 = __ar_20[__i_21]["title"];
if (typeof __sv_25 !== "string") {
_e.push(__zcIT("string", __sv_25, ["ratings", __i_21, "title"]));
if (__sv_25 !== void 0 && __sv_25 !== null && __sv_25.length !== void 0) {
if (__sv_25.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_25), true, __sv_25, ["ratings", __i_21, "title"]));
if (__sv_25.length > 100)
_e.push(
__zcTB(100, __zcLo(__sv_25), true, __sv_25, ["ratings", __i_21, "title"]),
);
}
} else {
if (__sv_25.length < 1)
_e.push(__zcTS(1, "string", true, __sv_25, ["ratings", __i_21, "title"]));
if (__sv_25.length > 100 && (__sv_25.length > 200 || __zcCpl(__sv_25) > 100))
_e.push(__zcTB(100, "string", true, __sv_25, ["ratings", __i_21, "title"]));
}
var __sv_26 = __ar_20[__i_21]["text"];
if (typeof __sv_26 !== "string") {
_e.push(__zcIT("string", __sv_26, ["ratings", __i_21, "text"]));
if (__sv_26 !== void 0 && __sv_26 !== null && __sv_26.length !== void 0) {
if (__sv_26.length < 1)
_e.push(__zcTS(1, __zcLo(__sv_26), true, __sv_26, ["ratings", __i_21, "text"]));
if (__sv_26.length > 1e3)
_e.push(__zcTB(1e3, __zcLo(__sv_26), true, __sv_26, ["ratings", __i_21, "text"]));
}
} else {
if (__sv_26.length < 1)
_e.push(__zcTS(1, "string", true, __sv_26, ["ratings", __i_21, "text"]));
if (__sv_26.length > 1e3 && (__sv_26.length > 2e3 || __zcCpl(__sv_26) > 1e3))
_e.push(__zcTB(1e3, "string", true, __sv_26, ["ratings", __i_21, "text"]));
}
var __sv_27 = __ar_20[__i_21]["images"];
__sv_27 = __zcSw_0(__sv_27, ["ratings", __i_21, "images"], _e);
__ar_20[__i_21] = {
id: __sv_23,
stars: __sv_24,
title: __sv_25,
text: __sv_26,
images: __sv_27,
};
}
__sv_19 = __ar_20;
}
_d = {
id: __sv_5,
created: __sv_6,
title: __sv_7,
brand: __sv_8,
description: __sv_9,
price: __sv_10,
discount: __sv_11,
quantity: __sv_12,
tags: __sv_13,
images: __sv_18,
ratings: __sv_19,
};
}
if (_e.length === 0)
return {
success: true,
data: _d,
};
return __zcFin(_e, _d);
}
return __zcMkv(safeParse_compiledProductSchema, null, null, null);
})().parse({});