mongodb-chatbot-ui
Version:
UI React components for the MongoDB Chatbot Framework
1,623 lines (1,622 loc) • 77.9 kB
JavaScript
import { j as we } from "./jsx-runtime.js";
import { createContext as Ce } from "react";
import { $ as Te } from "./index16.js";
import { b as Oe, g as Re } from "./utils.js";
const Se = Ce(void 0);
function ot({ children: r, user: e }) {
return /* @__PURE__ */ we.jsx(Se.Provider, { value: e, children: r });
}
var y;
(function(r) {
r.assertEqual = (n) => {
};
function e(n) {
}
r.assertIs = e;
function t(n) {
throw new Error();
}
r.assertNever = t, r.arrayToEnum = (n) => {
const a = {};
for (const i of n)
a[i] = i;
return a;
}, r.getValidEnumValues = (n) => {
const a = r.objectKeys(n).filter((d) => typeof n[n[d]] != "number"), i = {};
for (const d of a)
i[d] = n[d];
return r.objectValues(i);
}, r.objectValues = (n) => r.objectKeys(n).map(function(a) {
return n[a];
}), r.objectKeys = typeof Object.keys == "function" ? (n) => Object.keys(n) : (n) => {
const a = [];
for (const i in n)
Object.prototype.hasOwnProperty.call(n, i) && a.push(i);
return a;
}, r.find = (n, a) => {
for (const i of n)
if (a(i))
return i;
}, r.isInteger = typeof Number.isInteger == "function" ? (n) => Number.isInteger(n) : (n) => typeof n == "number" && Number.isFinite(n) && Math.floor(n) === n;
function s(n, a = " | ") {
return n.map((i) => typeof i == "string" ? `'${i}'` : i).join(a);
}
r.joinValues = s, r.jsonStringifyReplacer = (n, a) => typeof a == "bigint" ? a.toString() : a;
})(y || (y = {}));
var te;
(function(r) {
r.mergeShapes = (e, t) => ({
...e,
...t
// second overwrites first
});
})(te || (te = {}));
const u = y.arrayToEnum([
"string",
"nan",
"number",
"integer",
"float",
"boolean",
"date",
"bigint",
"symbol",
"function",
"undefined",
"null",
"array",
"object",
"unknown",
"promise",
"void",
"never",
"map",
"set"
]), T = (r) => {
switch (typeof r) {
case "undefined":
return u.undefined;
case "string":
return u.string;
case "number":
return Number.isNaN(r) ? u.nan : u.number;
case "boolean":
return u.boolean;
case "function":
return u.function;
case "bigint":
return u.bigint;
case "symbol":
return u.symbol;
case "object":
return Array.isArray(r) ? u.array : r === null ? u.null : r.then && typeof r.then == "function" && r.catch && typeof r.catch == "function" ? u.promise : typeof Map < "u" && r instanceof Map ? u.map : typeof Set < "u" && r instanceof Set ? u.set : typeof Date < "u" && r instanceof Date ? u.date : u.object;
default:
return u.unknown;
}
}, o = y.arrayToEnum([
"invalid_type",
"invalid_literal",
"custom",
"invalid_union",
"invalid_union_discriminator",
"invalid_enum_value",
"unrecognized_keys",
"invalid_arguments",
"invalid_return_type",
"invalid_date",
"invalid_string",
"too_small",
"too_big",
"invalid_intersection_types",
"not_multiple_of",
"not_finite"
]);
class C extends Error {
get errors() {
return this.issues;
}
constructor(e) {
super(), this.issues = [], this.addIssue = (s) => {
this.issues = [...this.issues, s];
}, this.addIssues = (s = []) => {
this.issues = [...this.issues, ...s];
};
const t = new.target.prototype;
Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e;
}
format(e) {
const t = e || function(a) {
return a.message;
}, s = { _errors: [] }, n = (a) => {
for (const i of a.issues)
if (i.code === "invalid_union")
i.unionErrors.map(n);
else if (i.code === "invalid_return_type")
n(i.returnTypeError);
else if (i.code === "invalid_arguments")
n(i.argumentsError);
else if (i.path.length === 0)
s._errors.push(t(i));
else {
let d = s, h = 0;
for (; h < i.path.length; ) {
const f = i.path[h];
h === i.path.length - 1 ? (d[f] = d[f] || { _errors: [] }, d[f]._errors.push(t(i))) : d[f] = d[f] || { _errors: [] }, d = d[f], h++;
}
}
};
return n(this), s;
}
static assert(e) {
if (!(e instanceof C))
throw new Error(`Not a ZodError: ${e}`);
}
toString() {
return this.message;
}
get message() {
return JSON.stringify(this.issues, y.jsonStringifyReplacer, 2);
}
get isEmpty() {
return this.issues.length === 0;
}
flatten(e = (t) => t.message) {
const t = {}, s = [];
for (const n of this.issues)
n.path.length > 0 ? (t[n.path[0]] = t[n.path[0]] || [], t[n.path[0]].push(e(n))) : s.push(e(n));
return { formErrors: s, fieldErrors: t };
}
get formErrors() {
return this.flatten();
}
}
C.create = (r) => new C(r);
const Y = (r, e) => {
let t;
switch (r.code) {
case o.invalid_type:
r.received === u.undefined ? t = "Required" : t = `Expected ${r.expected}, received ${r.received}`;
break;
case o.invalid_literal:
t = `Invalid literal value, expected ${JSON.stringify(r.expected, y.jsonStringifyReplacer)}`;
break;
case o.unrecognized_keys:
t = `Unrecognized key(s) in object: ${y.joinValues(r.keys, ", ")}`;
break;
case o.invalid_union:
t = "Invalid input";
break;
case o.invalid_union_discriminator:
t = `Invalid discriminator value. Expected ${y.joinValues(r.options)}`;
break;
case o.invalid_enum_value:
t = `Invalid enum value. Expected ${y.joinValues(r.options)}, received '${r.received}'`;
break;
case o.invalid_arguments:
t = "Invalid function arguments";
break;
case o.invalid_return_type:
t = "Invalid function return type";
break;
case o.invalid_date:
t = "Invalid date";
break;
case o.invalid_string:
typeof r.validation == "object" ? "includes" in r.validation ? (t = `Invalid input: must include "${r.validation.includes}"`, typeof r.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${r.validation.position}`)) : "startsWith" in r.validation ? t = `Invalid input: must start with "${r.validation.startsWith}"` : "endsWith" in r.validation ? t = `Invalid input: must end with "${r.validation.endsWith}"` : y.assertNever(r.validation) : r.validation !== "regex" ? t = `Invalid ${r.validation}` : t = "Invalid";
break;
case o.too_small:
r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "more than"} ${r.minimum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "over"} ${r.minimum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(r.minimum))}` : t = "Invalid input";
break;
case o.too_big:
r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "less than"} ${r.maximum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "under"} ${r.maximum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "bigint" ? t = `BigInt must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly" : r.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(r.maximum))}` : t = "Invalid input";
break;
case o.custom:
t = "Invalid input";
break;
case o.invalid_intersection_types:
t = "Intersection results could not be merged";
break;
case o.not_multiple_of:
t = `Number must be a multiple of ${r.multipleOf}`;
break;
case o.not_finite:
t = "Number must be finite";
break;
default:
t = e.defaultError, y.assertNever(r);
}
return { message: t };
};
let Ae = Y;
function Ne() {
return Ae;
}
const Ze = (r) => {
const { data: e, path: t, errorMaps: s, issueData: n } = r, a = [...t, ...n.path || []], i = {
...n,
path: a
};
if (n.message !== void 0)
return {
...n,
path: a,
message: n.message
};
let d = "";
const h = s.filter((f) => !!f).slice().reverse();
for (const f of h)
d = f(i, { data: e, defaultError: d }).message;
return {
...n,
path: a,
message: d
};
};
function c(r, e) {
const t = Ne(), s = Ze({
issueData: e,
data: r.data,
path: r.path,
errorMaps: [
r.common.contextualErrorMap,
// contextual error map is first priority
r.schemaErrorMap,
// then schema-bound map if available
t,
// then global override map
t === Y ? void 0 : Y
// then global default map
].filter((n) => !!n)
});
r.common.issues.push(s);
}
class k {
constructor() {
this.value = "valid";
}
dirty() {
this.value === "valid" && (this.value = "dirty");
}
abort() {
this.value !== "aborted" && (this.value = "aborted");
}
static mergeArray(e, t) {
const s = [];
for (const n of t) {
if (n.status === "aborted")
return m;
n.status === "dirty" && e.dirty(), s.push(n.value);
}
return { status: e.value, value: s };
}
static async mergeObjectAsync(e, t) {
const s = [];
for (const n of t) {
const a = await n.key, i = await n.value;
s.push({
key: a,
value: i
});
}
return k.mergeObjectSync(e, s);
}
static mergeObjectSync(e, t) {
const s = {};
for (const n of t) {
const { key: a, value: i } = n;
if (a.status === "aborted" || i.status === "aborted")
return m;
a.status === "dirty" && e.dirty(), i.status === "dirty" && e.dirty(), a.value !== "__proto__" && (typeof i.value < "u" || n.alwaysSet) && (s[a.value] = i.value);
}
return { status: e.value, value: s };
}
}
const m = Object.freeze({
status: "aborted"
}), P = (r) => ({ status: "dirty", value: r }), b = (r) => ({ status: "valid", value: r }), re = (r) => r.status === "aborted", se = (r) => r.status === "dirty", j = (r) => r.status === "valid", U = (r) => typeof Promise < "u" && r instanceof Promise;
var l;
(function(r) {
r.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, r.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
})(l || (l = {}));
class S {
constructor(e, t, s, n) {
this._cachedPath = [], this.parent = e, this.data = t, this._path = s, this._key = n;
}
get path() {
return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
}
}
const ne = (r, e) => {
if (j(e))
return { success: !0, data: e.value };
if (!r.common.issues.length)
throw new Error("Validation failed but no issues detected.");
return {
success: !1,
get error() {
if (this._error)
return this._error;
const t = new C(r.common.issues);
return this._error = t, this._error;
}
};
};
function _(r) {
if (!r)
return {};
const { errorMap: e, invalid_type_error: t, required_error: s, description: n } = r;
if (e && (t || s))
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
return e ? { errorMap: e, description: n } : { errorMap: (i, d) => {
const { message: h } = r;
return i.code === "invalid_enum_value" ? { message: h ?? d.defaultError } : typeof d.data > "u" ? { message: h ?? s ?? d.defaultError } : i.code !== "invalid_type" ? { message: d.defaultError } : { message: h ?? t ?? d.defaultError };
}, description: n };
}
class g {
get description() {
return this._def.description;
}
_getType(e) {
return T(e.data);
}
_getOrReturnCtx(e, t) {
return t || {
common: e.parent.common,
data: e.data,
parsedType: T(e.data),
schemaErrorMap: this._def.errorMap,
path: e.path,
parent: e.parent
};
}
_processInputParams(e) {
return {
status: new k(),
ctx: {
common: e.parent.common,
data: e.data,
parsedType: T(e.data),
schemaErrorMap: this._def.errorMap,
path: e.path,
parent: e.parent
}
};
}
_parseSync(e) {
const t = this._parse(e);
if (U(t))
throw new Error("Synchronous parse encountered promise.");
return t;
}
_parseAsync(e) {
const t = this._parse(e);
return Promise.resolve(t);
}
parse(e, t) {
const s = this.safeParse(e, t);
if (s.success)
return s.data;
throw s.error;
}
safeParse(e, t) {
const s = {
common: {
issues: [],
async: (t == null ? void 0 : t.async) ?? !1,
contextualErrorMap: t == null ? void 0 : t.errorMap
},
path: (t == null ? void 0 : t.path) || [],
schemaErrorMap: this._def.errorMap,
parent: null,
data: e,
parsedType: T(e)
}, n = this._parseSync({ data: e, path: s.path, parent: s });
return ne(s, n);
}
"~validate"(e) {
var s, n;
const t = {
common: {
issues: [],
async: !!this["~standard"].async
},
path: [],
schemaErrorMap: this._def.errorMap,
parent: null,
data: e,
parsedType: T(e)
};
if (!this["~standard"].async)
try {
const a = this._parseSync({ data: e, path: [], parent: t });
return j(a) ? {
value: a.value
} : {
issues: t.common.issues
};
} catch (a) {
(n = (s = a == null ? void 0 : a.message) == null ? void 0 : s.toLowerCase()) != null && n.includes("encountered") && (this["~standard"].async = !0), t.common = {
issues: [],
async: !0
};
}
return this._parseAsync({ data: e, path: [], parent: t }).then((a) => j(a) ? {
value: a.value
} : {
issues: t.common.issues
});
}
async parseAsync(e, t) {
const s = await this.safeParseAsync(e, t);
if (s.success)
return s.data;
throw s.error;
}
async safeParseAsync(e, t) {
const s = {
common: {
issues: [],
contextualErrorMap: t == null ? void 0 : t.errorMap,
async: !0
},
path: (t == null ? void 0 : t.path) || [],
schemaErrorMap: this._def.errorMap,
parent: null,
data: e,
parsedType: T(e)
}, n = this._parse({ data: e, path: s.path, parent: s }), a = await (U(n) ? n : Promise.resolve(n));
return ne(s, a);
}
refine(e, t) {
const s = (n) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(n) : t;
return this._refinement((n, a) => {
const i = e(n), d = () => a.addIssue({
code: o.custom,
...s(n)
});
return typeof Promise < "u" && i instanceof Promise ? i.then((h) => h ? !0 : (d(), !1)) : i ? !0 : (d(), !1);
});
}
refinement(e, t) {
return this._refinement((s, n) => e(s) ? !0 : (n.addIssue(typeof t == "function" ? t(s, n) : t), !1));
}
_refinement(e) {
return new E({
schema: this,
typeName: p.ZodEffects,
effect: { type: "refinement", refinement: e }
});
}
superRefine(e) {
return this._refinement(e);
}
constructor(e) {
this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
version: 1,
vendor: "zod",
validate: (t) => this["~validate"](t)
};
}
optional() {
return R.create(this, this._def);
}
nullable() {
return $.create(this, this._def);
}
nullish() {
return this.nullable().optional();
}
array() {
return w.create(this);
}
promise() {
return q.create(this, this._def);
}
or(e) {
return F.create([this, e], this._def);
}
and(e) {
return W.create(this, e, this._def);
}
transform(e) {
return new E({
..._(this._def),
schema: this,
typeName: p.ZodEffects,
effect: { type: "transform", transform: e }
});
}
default(e) {
const t = typeof e == "function" ? e : () => e;
return new G({
..._(this._def),
innerType: this,
defaultValue: t,
typeName: p.ZodDefault
});
}
brand() {
return new et({
typeName: p.ZodBranded,
type: this,
..._(this._def)
});
}
catch(e) {
const t = typeof e == "function" ? e : () => e;
return new Q({
..._(this._def),
innerType: this,
catchValue: t,
typeName: p.ZodCatch
});
}
describe(e) {
const t = this.constructor;
return new t({
...this._def,
description: e
});
}
pipe(e) {
return ee.create(this, e);
}
readonly() {
return X.create(this);
}
isOptional() {
return this.safeParse(void 0).success;
}
isNullable() {
return this.safeParse(null).success;
}
}
const je = /^c[^\s-]{8,}$/i, Ie = /^[0-9a-z]+$/, Ee = /^[0-9A-HJKMNP-TV-Z]{26}$/i, $e = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, Le = /^[a-z0-9_-]{21}$/i, Ve = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, Pe = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, ze = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, Me = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
let J;
const De = /^(?:(?: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])$/, Ue = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/, Be = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, Fe = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, We = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, qe = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, ye = "((\\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])))", Je = new RegExp(`^${ye}$`);
function ve(r) {
let e = "[0-5]\\d";
r.precision ? e = `${e}\\.\\d{${r.precision}}` : r.precision == null && (e = `${e}(\\.\\d+)?`);
const t = r.precision ? "+" : "?";
return `([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`;
}
function Ye(r) {
return new RegExp(`^${ve(r)}$`);
}
function He(r) {
let e = `${ye}T${ve(r)}`;
const t = [];
return t.push(r.local ? "Z?" : "Z"), r.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`);
}
function Ge(r, e) {
return !!((e === "v4" || !e) && De.test(r) || (e === "v6" || !e) && Be.test(r));
}
function Qe(r, e) {
if (!Ve.test(r))
return !1;
try {
const [t] = r.split("."), s = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(t.length + (4 - t.length % 4) % 4, "="), n = JSON.parse(atob(s));
return !(typeof n != "object" || n === null || "typ" in n && (n == null ? void 0 : n.typ) !== "JWT" || !n.alg || e && n.alg !== e);
} catch {
return !1;
}
}
function Xe(r, e) {
return !!((e === "v4" || !e) && Ue.test(r) || (e === "v6" || !e) && Fe.test(r));
}
class O extends g {
_parse(e) {
if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== u.string) {
const a = this._getOrReturnCtx(e);
return c(a, {
code: o.invalid_type,
expected: u.string,
received: a.parsedType
}), m;
}
const s = new k();
let n;
for (const a of this._def.checks)
if (a.kind === "min")
e.data.length < a.value && (n = this._getOrReturnCtx(e, n), c(n, {
code: o.too_small,
minimum: a.value,
type: "string",
inclusive: !0,
exact: !1,
message: a.message
}), s.dirty());
else if (a.kind === "max")
e.data.length > a.value && (n = this._getOrReturnCtx(e, n), c(n, {
code: o.too_big,
maximum: a.value,
type: "string",
inclusive: !0,
exact: !1,
message: a.message
}), s.dirty());
else if (a.kind === "length") {
const i = e.data.length > a.value, d = e.data.length < a.value;
(i || d) && (n = this._getOrReturnCtx(e, n), i ? c(n, {
code: o.too_big,
maximum: a.value,
type: "string",
inclusive: !0,
exact: !0,
message: a.message
}) : d && c(n, {
code: o.too_small,
minimum: a.value,
type: "string",
inclusive: !0,
exact: !0,
message: a.message
}), s.dirty());
} else if (a.kind === "email")
ze.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "email",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "emoji")
J || (J = new RegExp(Me, "u")), J.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "emoji",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "uuid")
$e.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "uuid",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "nanoid")
Le.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "nanoid",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "cuid")
je.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "cuid",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "cuid2")
Ie.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "cuid2",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "ulid")
Ee.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "ulid",
code: o.invalid_string,
message: a.message
}), s.dirty());
else if (a.kind === "url")
try {
new URL(e.data);
} catch {
n = this._getOrReturnCtx(e, n), c(n, {
validation: "url",
code: o.invalid_string,
message: a.message
}), s.dirty();
}
else
a.kind === "regex" ? (a.regex.lastIndex = 0, a.regex.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "regex",
code: o.invalid_string,
message: a.message
}), s.dirty())) : a.kind === "trim" ? e.data = e.data.trim() : a.kind === "includes" ? e.data.includes(a.value, a.position) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: { includes: a.value, position: a.position },
message: a.message
}), s.dirty()) : a.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : a.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : a.kind === "startsWith" ? e.data.startsWith(a.value) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: { startsWith: a.value },
message: a.message
}), s.dirty()) : a.kind === "endsWith" ? e.data.endsWith(a.value) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: { endsWith: a.value },
message: a.message
}), s.dirty()) : a.kind === "datetime" ? He(a).test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: "datetime",
message: a.message
}), s.dirty()) : a.kind === "date" ? Je.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: "date",
message: a.message
}), s.dirty()) : a.kind === "time" ? Ye(a).test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
code: o.invalid_string,
validation: "time",
message: a.message
}), s.dirty()) : a.kind === "duration" ? Pe.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "duration",
code: o.invalid_string,
message: a.message
}), s.dirty()) : a.kind === "ip" ? Ge(e.data, a.version) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "ip",
code: o.invalid_string,
message: a.message
}), s.dirty()) : a.kind === "jwt" ? Qe(e.data, a.alg) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "jwt",
code: o.invalid_string,
message: a.message
}), s.dirty()) : a.kind === "cidr" ? Xe(e.data, a.version) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "cidr",
code: o.invalid_string,
message: a.message
}), s.dirty()) : a.kind === "base64" ? We.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "base64",
code: o.invalid_string,
message: a.message
}), s.dirty()) : a.kind === "base64url" ? qe.test(e.data) || (n = this._getOrReturnCtx(e, n), c(n, {
validation: "base64url",
code: o.invalid_string,
message: a.message
}), s.dirty()) : y.assertNever(a);
return { status: s.value, value: e.data };
}
_regex(e, t, s) {
return this.refinement((n) => e.test(n), {
validation: t,
code: o.invalid_string,
...l.errToObj(s)
});
}
_addCheck(e) {
return new O({
...this._def,
checks: [...this._def.checks, e]
});
}
email(e) {
return this._addCheck({ kind: "email", ...l.errToObj(e) });
}
url(e) {
return this._addCheck({ kind: "url", ...l.errToObj(e) });
}
emoji(e) {
return this._addCheck({ kind: "emoji", ...l.errToObj(e) });
}
uuid(e) {
return this._addCheck({ kind: "uuid", ...l.errToObj(e) });
}
nanoid(e) {
return this._addCheck({ kind: "nanoid", ...l.errToObj(e) });
}
cuid(e) {
return this._addCheck({ kind: "cuid", ...l.errToObj(e) });
}
cuid2(e) {
return this._addCheck({ kind: "cuid2", ...l.errToObj(e) });
}
ulid(e) {
return this._addCheck({ kind: "ulid", ...l.errToObj(e) });
}
base64(e) {
return this._addCheck({ kind: "base64", ...l.errToObj(e) });
}
base64url(e) {
return this._addCheck({
kind: "base64url",
...l.errToObj(e)
});
}
jwt(e) {
return this._addCheck({ kind: "jwt", ...l.errToObj(e) });
}
ip(e) {
return this._addCheck({ kind: "ip", ...l.errToObj(e) });
}
cidr(e) {
return this._addCheck({ kind: "cidr", ...l.errToObj(e) });
}
datetime(e) {
return typeof e == "string" ? this._addCheck({
kind: "datetime",
precision: null,
offset: !1,
local: !1,
message: e
}) : this._addCheck({
kind: "datetime",
precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
offset: (e == null ? void 0 : e.offset) ?? !1,
local: (e == null ? void 0 : e.local) ?? !1,
...l.errToObj(e == null ? void 0 : e.message)
});
}
date(e) {
return this._addCheck({ kind: "date", message: e });
}
time(e) {
return typeof e == "string" ? this._addCheck({
kind: "time",
precision: null,
message: e
}) : this._addCheck({
kind: "time",
precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
...l.errToObj(e == null ? void 0 : e.message)
});
}
duration(e) {
return this._addCheck({ kind: "duration", ...l.errToObj(e) });
}
regex(e, t) {
return this._addCheck({
kind: "regex",
regex: e,
...l.errToObj(t)
});
}
includes(e, t) {
return this._addCheck({
kind: "includes",
value: e,
position: t == null ? void 0 : t.position,
...l.errToObj(t == null ? void 0 : t.message)
});
}
startsWith(e, t) {
return this._addCheck({
kind: "startsWith",
value: e,
...l.errToObj(t)
});
}
endsWith(e, t) {
return this._addCheck({
kind: "endsWith",
value: e,
...l.errToObj(t)
});
}
min(e, t) {
return this._addCheck({
kind: "min",
value: e,
...l.errToObj(t)
});
}
max(e, t) {
return this._addCheck({
kind: "max",
value: e,
...l.errToObj(t)
});
}
length(e, t) {
return this._addCheck({
kind: "length",
value: e,
...l.errToObj(t)
});
}
/**
* Equivalent to `.min(1)`
*/
nonempty(e) {
return this.min(1, l.errToObj(e));
}
trim() {
return new O({
...this._def,
checks: [...this._def.checks, { kind: "trim" }]
});
}
toLowerCase() {
return new O({
...this._def,
checks: [...this._def.checks, { kind: "toLowerCase" }]
});
}
toUpperCase() {
return new O({
...this._def,
checks: [...this._def.checks, { kind: "toUpperCase" }]
});
}
get isDatetime() {
return !!this._def.checks.find((e) => e.kind === "datetime");
}
get isDate() {
return !!this._def.checks.find((e) => e.kind === "date");
}
get isTime() {
return !!this._def.checks.find((e) => e.kind === "time");
}
get isDuration() {
return !!this._def.checks.find((e) => e.kind === "duration");
}
get isEmail() {
return !!this._def.checks.find((e) => e.kind === "email");
}
get isURL() {
return !!this._def.checks.find((e) => e.kind === "url");
}
get isEmoji() {
return !!this._def.checks.find((e) => e.kind === "emoji");
}
get isUUID() {
return !!this._def.checks.find((e) => e.kind === "uuid");
}
get isNANOID() {
return !!this._def.checks.find((e) => e.kind === "nanoid");
}
get isCUID() {
return !!this._def.checks.find((e) => e.kind === "cuid");
}
get isCUID2() {
return !!this._def.checks.find((e) => e.kind === "cuid2");
}
get isULID() {
return !!this._def.checks.find((e) => e.kind === "ulid");
}
get isIP() {
return !!this._def.checks.find((e) => e.kind === "ip");
}
get isCIDR() {
return !!this._def.checks.find((e) => e.kind === "cidr");
}
get isBase64() {
return !!this._def.checks.find((e) => e.kind === "base64");
}
get isBase64url() {
return !!this._def.checks.find((e) => e.kind === "base64url");
}
get minLength() {
let e = null;
for (const t of this._def.checks)
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
return e;
}
get maxLength() {
let e = null;
for (const t of this._def.checks)
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
return e;
}
}
O.create = (r) => new O({
checks: [],
typeName: p.ZodString,
coerce: (r == null ? void 0 : r.coerce) ?? !1,
..._(r)
});
function Ke(r, e) {
const t = (r.toString().split(".")[1] || "").length, s = (e.toString().split(".")[1] || "").length, n = t > s ? t : s, a = Number.parseInt(r.toFixed(n).replace(".", "")), i = Number.parseInt(e.toFixed(n).replace(".", ""));
return a % i / 10 ** n;
}
class z extends g {
constructor() {
super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
}
_parse(e) {
if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== u.number) {
const a = this._getOrReturnCtx(e);
return c(a, {
code: o.invalid_type,
expected: u.number,
received: a.parsedType
}), m;
}
let s;
const n = new k();
for (const a of this._def.checks)
a.kind === "int" ? y.isInteger(e.data) || (s = this._getOrReturnCtx(e, s), c(s, {
code: o.invalid_type,
expected: "integer",
received: "float",
message: a.message
}), n.dirty()) : a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.too_small,
minimum: a.value,
type: "number",
inclusive: a.inclusive,
exact: !1,
message: a.message
}), n.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.too_big,
maximum: a.value,
type: "number",
inclusive: a.inclusive,
exact: !1,
message: a.message
}), n.dirty()) : a.kind === "multipleOf" ? Ke(e.data, a.value) !== 0 && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.not_multiple_of,
multipleOf: a.value,
message: a.message
}), n.dirty()) : a.kind === "finite" ? Number.isFinite(e.data) || (s = this._getOrReturnCtx(e, s), c(s, {
code: o.not_finite,
message: a.message
}), n.dirty()) : y.assertNever(a);
return { status: n.value, value: e.data };
}
gte(e, t) {
return this.setLimit("min", e, !0, l.toString(t));
}
gt(e, t) {
return this.setLimit("min", e, !1, l.toString(t));
}
lte(e, t) {
return this.setLimit("max", e, !0, l.toString(t));
}
lt(e, t) {
return this.setLimit("max", e, !1, l.toString(t));
}
setLimit(e, t, s, n) {
return new z({
...this._def,
checks: [
...this._def.checks,
{
kind: e,
value: t,
inclusive: s,
message: l.toString(n)
}
]
});
}
_addCheck(e) {
return new z({
...this._def,
checks: [...this._def.checks, e]
});
}
int(e) {
return this._addCheck({
kind: "int",
message: l.toString(e)
});
}
positive(e) {
return this._addCheck({
kind: "min",
value: 0,
inclusive: !1,
message: l.toString(e)
});
}
negative(e) {
return this._addCheck({
kind: "max",
value: 0,
inclusive: !1,
message: l.toString(e)
});
}
nonpositive(e) {
return this._addCheck({
kind: "max",
value: 0,
inclusive: !0,
message: l.toString(e)
});
}
nonnegative(e) {
return this._addCheck({
kind: "min",
value: 0,
inclusive: !0,
message: l.toString(e)
});
}
multipleOf(e, t) {
return this._addCheck({
kind: "multipleOf",
value: e,
message: l.toString(t)
});
}
finite(e) {
return this._addCheck({
kind: "finite",
message: l.toString(e)
});
}
safe(e) {
return this._addCheck({
kind: "min",
inclusive: !0,
value: Number.MIN_SAFE_INTEGER,
message: l.toString(e)
})._addCheck({
kind: "max",
inclusive: !0,
value: Number.MAX_SAFE_INTEGER,
message: l.toString(e)
});
}
get minValue() {
let e = null;
for (const t of this._def.checks)
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
return e;
}
get maxValue() {
let e = null;
for (const t of this._def.checks)
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
return e;
}
get isInt() {
return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && y.isInteger(e.value));
}
get isFinite() {
let e = null, t = null;
for (const s of this._def.checks) {
if (s.kind === "finite" || s.kind === "int" || s.kind === "multipleOf")
return !0;
s.kind === "min" ? (t === null || s.value > t) && (t = s.value) : s.kind === "max" && (e === null || s.value < e) && (e = s.value);
}
return Number.isFinite(t) && Number.isFinite(e);
}
}
z.create = (r) => new z({
checks: [],
typeName: p.ZodNumber,
coerce: (r == null ? void 0 : r.coerce) || !1,
..._(r)
});
class M extends g {
constructor() {
super(...arguments), this.min = this.gte, this.max = this.lte;
}
_parse(e) {
if (this._def.coerce)
try {
e.data = BigInt(e.data);
} catch {
return this._getInvalidInput(e);
}
if (this._getType(e) !== u.bigint)
return this._getInvalidInput(e);
let s;
const n = new k();
for (const a of this._def.checks)
a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.too_small,
type: "bigint",
minimum: a.value,
inclusive: a.inclusive,
message: a.message
}), n.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.too_big,
type: "bigint",
maximum: a.value,
inclusive: a.inclusive,
message: a.message
}), n.dirty()) : a.kind === "multipleOf" ? e.data % a.value !== BigInt(0) && (s = this._getOrReturnCtx(e, s), c(s, {
code: o.not_multiple_of,
multipleOf: a.value,
message: a.message
}), n.dirty()) : y.assertNever(a);
return { status: n.value, value: e.data };
}
_getInvalidInput(e) {
const t = this._getOrReturnCtx(e);
return c(t, {
code: o.invalid_type,
expected: u.bigint,
received: t.parsedType
}), m;
}
gte(e, t) {
return this.setLimit("min", e, !0, l.toString(t));
}
gt(e, t) {
return this.setLimit("min", e, !1, l.toString(t));
}
lte(e, t) {
return this.setLimit("max", e, !0, l.toString(t));
}
lt(e, t) {
return this.setLimit("max", e, !1, l.toString(t));
}
setLimit(e, t, s, n) {
return new M({
...this._def,
checks: [
...this._def.checks,
{
kind: e,
value: t,
inclusive: s,
message: l.toString(n)
}
]
});
}
_addCheck(e) {
return new M({
...this._def,
checks: [...this._def.checks, e]
});
}
positive(e) {
return this._addCheck({
kind: "min",
value: BigInt(0),
inclusive: !1,
message: l.toString(e)
});
}
negative(e) {
return this._addCheck({
kind: "max",
value: BigInt(0),
inclusive: !1,
message: l.toString(e)
});
}
nonpositive(e) {
return this._addCheck({
kind: "max",
value: BigInt(0),
inclusive: !0,
message: l.toString(e)
});
}
nonnegative(e) {
return this._addCheck({
kind: "min",
value: BigInt(0),
inclusive: !0,
message: l.toString(e)
});
}
multipleOf(e, t) {
return this._addCheck({
kind: "multipleOf",
value: e,
message: l.toString(t)
});
}
get minValue() {
let e = null;
for (const t of this._def.checks)
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
return e;
}
get maxValue() {
let e = null;
for (const t of this._def.checks)
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
return e;
}
}
M.create = (r) => new M({
checks: [],
typeName: p.ZodBigInt,
coerce: (r == null ? void 0 : r.coerce) ?? !1,
..._(r)
});
class ae extends g {
_parse(e) {
if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== u.boolean) {
const s = this._getOrReturnCtx(e);
return c(s, {
code: o.invalid_type,
expected: u.boolean,
received: s.parsedType
}), m;
}
return b(e.data);
}
}
ae.create = (r) => new ae({
typeName: p.ZodBoolean,
coerce: (r == null ? void 0 : r.coerce) || !1,
..._(r)
});
class B extends g {
_parse(e) {
if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== u.date) {
const a = this._getOrReturnCtx(e);
return c(a, {
code: o.invalid_type,
expected: u.date,
received: a.parsedType
}), m;
}
if (Number.isNaN(e.data.getTime())) {
const a = this._getOrReturnCtx(e);
return c(a, {
code: o.invalid_date
}), m;
}
const s = new k();
let n;
for (const a of this._def.checks)
a.kind === "min" ? e.data.getTime() < a.value && (n = this._getOrReturnCtx(e, n), c(n, {
code: o.too_small,
message: a.message,
inclusive: !0,
exact: !1,
minimum: a.value,
type: "date"
}), s.dirty()) : a.kind === "max" ? e.data.getTime() > a.value && (n = this._getOrReturnCtx(e, n), c(n, {
code: o.too_big,
message: a.message,
inclusive: !0,
exact: !1,
maximum: a.value,
type: "date"
}), s.dirty()) : y.assertNever(a);
return {
status: s.value,
value: new Date(e.data.getTime())
};
}
_addCheck(e) {
return new B({
...this._def,
checks: [...this._def.checks, e]
});
}
min(e, t) {
return this._addCheck({
kind: "min",
value: e.getTime(),
message: l.toString(t)
});
}
max(e, t) {
return this._addCheck({
kind: "max",
value: e.getTime(),
message: l.toString(t)
});
}
get minDate() {
let e = null;
for (const t of this._def.checks)
t.kind === "min" && (e === null || t.value > e) && (e = t.value);
return e != null ? new Date(e) : null;
}
get maxDate() {
let e = null;
for (const t of this._def.checks)
t.kind === "max" && (e === null || t.value < e) && (e = t.value);
return e != null ? new Date(e) : null;
}
}
B.create = (r) => new B({
checks: [],
coerce: (r == null ? void 0 : r.coerce) || !1,
typeName: p.ZodDate,
..._(r)
});
class ie extends g {
_parse(e) {
if (this._getType(e) !== u.symbol) {
const s = this._getOrReturnCtx(e);
return c(s, {
code: o.invalid_type,
expected: u.symbol,
received: s.parsedType
}), m;
}
return b(e.data);
}
}
ie.create = (r) => new ie({
typeName: p.ZodSymbol,
..._(r)
});
class de extends g {
_parse(e) {
if (this._getType(e) !== u.undefined) {
const s = this._getOrReturnCtx(e);
return c(s, {
code: o.invalid_type,
expected: u.undefined,
received: s.parsedType
}), m;
}
return b(e.data);
}
}
de.create = (r) => new de({
typeName: p.ZodUndefined,
..._(r)
});
class oe extends g {
_parse(e) {
if (this._getType(e) !== u.null) {
const s = this._getOrReturnCtx(e);
return c(s, {
code: o.invalid_type,
expected: u.null,
received: s.parsedType
}), m;
}
return b(e.data);
}
}
oe.create = (r) => new oe({
typeName: p.ZodNull,
..._(r)
});
class ce extends g {
constructor() {
super(...arguments), this._any = !0;
}
_parse(e) {
return b(e.data);
}
}
ce.create = (r) => new ce({
typeName: p.ZodAny,
..._(r)
});
class ue extends g {
constructor() {
super(...arguments), this._unknown = !0;
}
_parse(e) {
return b(e.data);
}
}
ue.create = (r) => new ue({
typeName: p.ZodUnknown,
..._(r)
});
class A extends g {
_parse(e) {
const t = this._getOrReturnCtx(e);
return c(t, {
code: o.invalid_type,
expected: u.never,
received: t.parsedType
}), m;
}
}
A.create = (r) => new A({
typeName: p.ZodNever,
..._(r)
});
class le extends g {
_parse(e) {
if (this._getType(e) !== u.undefined) {
const s = this._getOrReturnCtx(e);
return c(s, {
code: o.invalid_type,
expected: u.void,
received: s.parsedType
}), m;
}
return b(e.data);
}
}
le.create = (r) => new le({
typeName: p.ZodVoid,
..._(r)
});
class w extends g {
_parse(e) {
const { ctx: t, status: s } = this._processInputParams(e), n = this._def;
if (t.parsedType !== u.array)
return c(t, {
code: o.invalid_type,
expected: u.array,
received: t.parsedType
}), m;
if (n.exactLength !== null) {
const i = t.data.length > n.exactLength.value, d = t.data.length < n.exactLength.value;
(i || d) && (c(t, {
code: i ? o.too_big : o.too_small,
minimum: d ? n.exactLength.value : void 0,
maximum: i ? n.exactLength.value : void 0,
type: "array",
inclusive: !0,
exact: !0,
message: n.exactLength.message
}), s.dirty());
}
if (n.minLength !== null && t.data.length < n.minLength.value && (c(t, {
code: o.too_small,
minimum: n.minLength.value,
type: "array",
inclusive: !0,
exact: !1,
message: n.minLength.message
}), s.dirty()), n.maxLength !== null && t.data.length > n.maxLength.value && (c(t, {
code: o.too_big,
maximum: n.maxLength.value,
type: "array",
inclusive: !0,
exact: !1,
message: n.maxLength.message
}), s.dirty()), t.common.async)
return Promise.all([...t.data].map((i, d) => n.type._parseAsync(new S(t, i, t.path, d)))).then((i) => k.mergeArray(s, i));
const a = [...t.data].map((i, d) => n.type._parseSync(new S(t, i, t.path, d)));
return k.mergeArray(s, a);
}
get element() {
return this._def.type;
}
min(e, t) {
return new w({
...this._def,
minLength: { value: e, message: l.toString(t) }
});
}
max(e, t) {
return new w({
...this._def,
maxLength: { value: e, message: l.toString(t) }
});
}
length(e, t) {
return new w({
...this._def,
exactLength: { value: e, message: l.toString(t) }
});
}
nonempty(e) {
return this.min(1, e);
}
}
w.create = (r, e) => new w({
type: r,
minLength: null,
maxLength: null,
exactLength: null,
typeName: p.ZodArray,
..._(e)
});
function Z(r) {
if (r instanceof x) {
const e = {};
for (const t in r.shape) {
const s = r.shape[t];
e[t] = R.create(Z(s));
}
return new x({
...r._def,
shape: () => e
});
} else
return r instanceof w ? new w({
...r._def,
type: Z(r.element)
}) : r instanceof R ? R.create(Z(r.unwrap())) : r instanceof $ ? $.create(Z(r.unwrap())) : r instanceof N ? N.create(r.items.map((e) => Z(e))) : r;
}
class x extends g {
constructor() {
super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
}
_getCached() {
if (this._cached !== null)
return this._cached;
const e = this._def.shape(), t = y.objectKeys(e);
return this._cached = { shape: e, keys: t }, this._cached;
}
_parse(e) {
if (this._getType(e) !== u.object) {
const f = this._getOrReturnCtx(e);
return c(f, {
code: o.invalid_type,
expected: u.object,
received: f.parsedType
}), m;
}
const { status: s, ctx: n } = this._processInputParams(e), { shape: a, keys: i } = this._getCached(), d = [];
if (!(this._def.catchall instanceof A && this._def.unknownKeys === "strip"))
for (const f in n.data)
i.includes(f) || d.push(f);
const h = [];
for (const f of i) {
const v = a[f], L = n.data[f];
h.push({
key: { status: "valid", value: f },
value: v._parse(new S(n, L, n.path, f)),
alwaysSet: f in n.data
});