import { $ZodCheck as Y, $ZodCheckStringFormat as ee, $ZodCheckNumberFormat as ne } from "./checks.js";
import { $constructor as a, globalConfig as te, $ZodAsyncError as T, $ZodEncodeError as re, config as P } from "./core.js";
import { Doc as oe } from "./doc.js";
import { safeParse as se, safeParseAsync as ie } from "./parse.js";
import { string as ue, base64 as ce, number as ae, boolean as le, null as pe, datetime as de, date as ve, time as he, duration as _e, email as ze, guid as fe, uuid as V, hostname as me, emoji as $e, nanoid as Ze, cuid as ge, cuid2 as we, ulid as be, xid as ke, ksuid as Te, ipv4 as Pe, ipv6 as Ie, cidrv4 as Re, cidrv6 as Ee, base64url as W, e164 as Se } from "./regexes.js";
import { allowsEval as De, cached as O, isObject as N, esc as C, defineLazy as p, cleanRegex as U, isPlainObject as E, prefixIssues as g, finalizeIssue as I, getEnumValues as Oe, propertyKeyTypes as Ne, escapeRegex as S, aborted as w, issue as Ue, optionalKeys as je } from "./util.js";
import { clone as Mn } from "./util.js";
import { version as Ve } from "./versions.js";
const v = /* @__PURE__ */ a("$ZodType", (e, n) => {
  var t;
  e ?? (e = {}), e._zod.def = n, e._zod.bag = e._zod.bag || {}, e._zod.version = Ve;
  const o = [...e._zod.def.checks ?? []];
  e._zod.traits.has("$ZodCheck") && o.unshift(e);
  for (const r of o)
    for (const i of r._zod.onattach)
      i(e);
  if (o.length === 0)
    (t = e._zod).deferred ?? (t.deferred = []), e._zod.deferred?.push(() => {
      e._zod.run = e._zod.parse;
    });
  else {
    const r = (s, u, c) => {
      let l = w(s), d;
      for (const f of u) {
        if (f._zod.def.when) {
          if (!f._zod.def.when(s))
            continue;
        } else if (l)
          continue;
        const z = s.issues.length, _ = f._zod.check(s);
        if (_ instanceof Promise && c?.async === !1)
          throw new T();
        if (d || _ instanceof Promise)
          d = (d ?? Promise.resolve()).then(async () => {
            await _, s.issues.length !== z && (l || (l = w(s, z)));
          });
        else {
          if (s.issues.length === z)
            continue;
          l || (l = w(s, z));
        }
      }
      return d ? d.then(() => s) : s;
    }, i = (s, u, c) => {
      if (w(s))
        return s.aborted = !0, s;
      const l = r(u, o, c);
      if (l instanceof Promise) {
        if (c.async === !1)
          throw new T();
        return l.then((d) => e._zod.parse(d, c));
      }
      return e._zod.parse(l, c);
    };
    e._zod.run = (s, u) => {
      if (u.skipChecks)
        return e._zod.parse(s, u);
      if (u.direction === "backward") {
        const l = e._zod.parse({ value: s.value, issues: [] }, { ...u, skipChecks: !0 });
        return l instanceof Promise ? l.then((d) => i(d, s, u)) : i(l, s, u);
      }
      const c = e._zod.parse(s, u);
      if (c instanceof Promise) {
        if (u.async === !1)
          throw new T();
        return c.then((l) => r(l, o, u));
      }
      return r(c, o, u);
    };
  }
  e["~standard"] = {
    validate: (r) => {
      try {
        const i = se(e, r);
        return i.success ? { value: i.data } : { issues: i.error?.issues };
      } catch {
        return ie(e, r).then((s) => s.success ? { value: s.data } : { issues: s.error?.issues });
      }
    },
    vendor: "zod",
    version: 1
  };
}), Ce = /* @__PURE__ */ a("$ZodString", (e, n) => {
  v.init(e, n), e._zod.pattern = [...e?._zod.bag?.patterns ?? []].pop() ?? ue(e._zod.bag), e._zod.parse = (t, o) => {
    if (n.coerce)
      try {
        t.value = String(t.value);
      } catch {
      }
    return typeof t.value == "string" || t.issues.push({
      expected: "string",
      code: "invalid_type",
      input: t.value,
      inst: e
    }), t;
  };
}), h = /* @__PURE__ */ a("$ZodStringFormat", (e, n) => {
  ee.init(e, n), Ce.init(e, n);
}), He = /* @__PURE__ */ a("$ZodGUID", (e, n) => {
  n.pattern ?? (n.pattern = fe), h.init(e, n);
}), qe = /* @__PURE__ */ a("$ZodUUID", (e, n) => {
  if (n.version) {
    const o = {
      v1: 1,
      v2: 2,
      v3: 3,
      v4: 4,
      v5: 5,
      v6: 6,
      v7: 7,
      v8: 8
    }[n.version];
    if (o === void 0)
      throw new Error(`Invalid UUID version: "${n.version}"`);
    n.pattern ?? (n.pattern = V(o));
  } else
    n.pattern ?? (n.pattern = V());
  h.init(e, n);
}), Qe = /* @__PURE__ */ a("$ZodEmail", (e, n) => {
  n.pattern ?? (n.pattern = ze), h.init(e, n);
}), Ye = /* @__PURE__ */ a("$ZodURL", (e, n) => {
  h.init(e, n), e._zod.check = (t) => {
    try {
      const o = t.value.trim(), r = new URL(o);
      n.hostname && (n.hostname.lastIndex = 0, n.hostname.test(r.hostname) || t.issues.push({
        code: "invalid_format",
        format: "url",
        note: "Invalid hostname",
        pattern: me.source,
        input: t.value,
        inst: e,
        continue: !n.abort
      })), n.protocol && (n.protocol.lastIndex = 0, n.protocol.test(r.protocol.endsWith(":") ? r.protocol.slice(0, -1) : r.protocol) || t.issues.push({
        code: "invalid_format",
        format: "url",
        note: "Invalid protocol",
        pattern: n.protocol.source,
        input: t.value,
        inst: e,
        continue: !n.abort
      })), n.normalize ? t.value = r.href : t.value = o;
      return;
    } catch {
      t.issues.push({
        code: "invalid_format",
        format: "url",
        input: t.value,
        inst: e,
        continue: !n.abort
      });
    }
  };
}), en = /* @__PURE__ */ a("$ZodEmoji", (e, n) => {
  n.pattern ?? (n.pattern = $e()), h.init(e, n);
}), nn = /* @__PURE__ */ a("$ZodNanoID", (e, n) => {
  n.pattern ?? (n.pattern = Ze), h.init(e, n);
}), tn = /* @__PURE__ */ a("$ZodCUID", (e, n) => {
  n.pattern ?? (n.pattern = ge), h.init(e, n);
}), rn = /* @__PURE__ */ a("$ZodCUID2", (e, n) => {
  n.pattern ?? (n.pattern = we), h.init(e, n);
}), on = /* @__PURE__ */ a("$ZodULID", (e, n) => {
  n.pattern ?? (n.pattern = be), h.init(e, n);
}), sn = /* @__PURE__ */ a("$ZodXID", (e, n) => {
  n.pattern ?? (n.pattern = ke), h.init(e, n);
}), un = /* @__PURE__ */ a("$ZodKSUID", (e, n) => {
  n.pattern ?? (n.pattern = Te), h.init(e, n);
}), cn = /* @__PURE__ */ a("$ZodISODateTime", (e, n) => {
  n.pattern ?? (n.pattern = de(n)), h.init(e, n);
}), an = /* @__PURE__ */ a("$ZodISODate", (e, n) => {
  n.pattern ?? (n.pattern = ve), h.init(e, n);
}), ln = /* @__PURE__ */ a("$ZodISOTime", (e, n) => {
  n.pattern ?? (n.pattern = he(n)), h.init(e, n);
}), pn = /* @__PURE__ */ a("$ZodISODuration", (e, n) => {
  n.pattern ?? (n.pattern = _e), h.init(e, n);
}), dn = /* @__PURE__ */ a("$ZodIPv4", (e, n) => {
  n.pattern ?? (n.pattern = Pe), h.init(e, n), e._zod.onattach.push((t) => {
    const o = t._zod.bag;
    o.format = "ipv4";
  });
}), vn = /* @__PURE__ */ a("$ZodIPv6", (e, n) => {
  n.pattern ?? (n.pattern = Ie), h.init(e, n), e._zod.onattach.push((t) => {
    const o = t._zod.bag;
    o.format = "ipv6";
  }), e._zod.check = (t) => {
    try {
      new URL(`http://[${t.value}]`);
    } catch {
      t.issues.push({
        code: "invalid_format",
        format: "ipv6",
        input: t.value,
        inst: e,
        continue: !n.abort
      });
    }
  };
}), hn = /* @__PURE__ */ a("$ZodCIDRv4", (e, n) => {
  n.pattern ?? (n.pattern = Re), h.init(e, n);
}), _n = /* @__PURE__ */ a("$ZodCIDRv6", (e, n) => {
  n.pattern ?? (n.pattern = Ee), h.init(e, n), e._zod.check = (t) => {
    const [o, r] = t.value.split("/");
    try {
      if (!r)
        throw new Error();
      const i = Number(r);
      if (`${i}` !== r)
        throw new Error();
      if (i < 0 || i > 128)
        throw new Error();
      new URL(`http://[${o}]`);
    } catch {
      t.issues.push({
        code: "invalid_format",
        format: "cidrv6",
        input: t.value,
        inst: e,
        continue: !n.abort
      });
    }
  };
});
function G(e) {
  if (e === "")
    return !0;
  if (e.length % 4 !== 0)
    return !1;
  try {
    return atob(e), !0;
  } catch {
    return !1;
  }
}
const zn = /* @__PURE__ */ a("$ZodBase64", (e, n) => {
  n.pattern ?? (n.pattern = ce), h.init(e, n), e._zod.onattach.push((t) => {
    t._zod.bag.contentEncoding = "base64";
  }), e._zod.check = (t) => {
    G(t.value) || t.issues.push({
      code: "invalid_format",
      format: "base64",
      input: t.value,
      inst: e,
      continue: !n.abort
    });
  };
});
function Le(e) {
  if (!W.test(e))
    return !1;
  const n = e.replace(/[-_]/g, (o) => o === "-" ? "+" : "/"), t = n.padEnd(Math.ceil(n.length / 4) * 4, "=");
  return G(t);
}
const fn = /* @__PURE__ */ a("$ZodBase64URL", (e, n) => {
  n.pattern ?? (n.pattern = W), h.init(e, n), e._zod.onattach.push((t) => {
    t._zod.bag.contentEncoding = "base64url";
  }), e._zod.check = (t) => {
    Le(t.value) || t.issues.push({
      code: "invalid_format",
      format: "base64url",
      input: t.value,
      inst: e,
      continue: !n.abort
    });
  };
}), mn = /* @__PURE__ */ a("$ZodE164", (e, n) => {
  n.pattern ?? (n.pattern = Se), h.init(e, n);
});
function Ae(e, n = null) {
  try {
    const t = e.split(".");
    if (t.length !== 3)
      return !1;
    const [o] = t;
    if (!o)
      return !1;
    const r = JSON.parse(atob(o));
    return !("typ" in r && r?.typ !== "JWT" || !r.alg || n && (!("alg" in r) || r.alg !== n));
  } catch {
    return !1;
  }
}
const $n = /* @__PURE__ */ a("$ZodJWT", (e, n) => {
  h.init(e, n), e._zod.check = (t) => {
    Ae(t.value, n.alg) || t.issues.push({
      code: "invalid_format",
      format: "jwt",
      input: t.value,
      inst: e,
      continue: !n.abort
    });
  };
}), Be = /* @__PURE__ */ a("$ZodNumber", (e, n) => {
  v.init(e, n), e._zod.pattern = e._zod.bag.pattern ?? ae, e._zod.parse = (t, o) => {
    if (n.coerce)
      try {
        t.value = Number(t.value);
      } catch {
      }
    const r = t.value;
    if (typeof r == "number" && !Number.isNaN(r) && Number.isFinite(r))
      return t;
    const i = typeof r == "number" ? Number.isNaN(r) ? "NaN" : Number.isFinite(r) ? void 0 : "Infinity" : void 0;
    return t.issues.push({
      expected: "number",
      code: "invalid_type",
      input: r,
      inst: e,
      ...i ? { received: i } : {}
    }), t;
  };
}), Zn = /* @__PURE__ */ a("$ZodNumber", (e, n) => {
  ne.init(e, n), Be.init(e, n);
}), gn = /* @__PURE__ */ a("$ZodBoolean", (e, n) => {
  v.init(e, n), e._zod.pattern = le, e._zod.parse = (t, o) => {
    if (n.coerce)
      try {
        t.value = !!t.value;
      } catch {
      }
    const r = t.value;
    return typeof r == "boolean" || t.issues.push({
      expected: "boolean",
      code: "invalid_type",
      input: r,
      inst: e
    }), t;
  };
}), wn = /* @__PURE__ */ a("$ZodNull", (e, n) => {
  v.init(e, n), e._zod.pattern = pe, e._zod.values = /* @__PURE__ */ new Set([null]), e._zod.parse = (t, o) => {
    const r = t.value;
    return r === null || t.issues.push({
      expected: "null",
      code: "invalid_type",
      input: r,
      inst: e
    }), t;
  };
}), bn = /* @__PURE__ */ a("$ZodUnknown", (e, n) => {
  v.init(e, n), e._zod.parse = (t) => t;
}), kn = /* @__PURE__ */ a("$ZodNever", (e, n) => {
  v.init(e, n), e._zod.parse = (t, o) => (t.issues.push({
    expected: "never",
    code: "invalid_type",
    input: t.value,
    inst: e
  }), t);
});
function L(e, n, t) {
  e.issues.length && n.issues.push(...g(t, e.issues)), n.value[t] = e.value;
}
const Tn = /* @__PURE__ */ a("$ZodArray", (e, n) => {
  v.init(e, n), e._zod.parse = (t, o) => {
    const r = t.value;
    if (!Array.isArray(r))
      return t.issues.push({
        expected: "array",
        code: "invalid_type",
        input: r,
        inst: e
      }), t;
    t.value = Array(r.length);
    const i = [];
    for (let s = 0; s < r.length; s++) {
      const u = r[s], c = n.element._zod.run({
        value: u,
        issues: []
      }, o);
      c instanceof Promise ? i.push(c.then((l) => L(l, t, s))) : L(c, t, s);
    }
    return i.length ? Promise.all(i).then(() => t) : t;
  };
});
function R(e, n, t, o) {
  e.issues.length && n.issues.push(...g(t, e.issues)), e.value === void 0 ? t in o && (n.value[t] = void 0) : n.value[t] = e.value;
}
function X(e) {
  const n = Object.keys(e.shape);
  for (const o of n)
    if (!e.shape[o]._zod.traits.has("$ZodType"))
      throw new Error(`Invalid element at key "${o}": expected a Zod schema`);
  const t = je(e.shape);
  return {
    ...e,
    keys: n,
    keySet: new Set(n),
    numKeys: n.length,
    optionalKeys: new Set(t)
  };
}
function x(e, n, t, o, r, i) {
  const s = [], u = r.keySet, c = r.catchall._zod, l = c.def.type;
  for (const d of Object.keys(n)) {
    if (u.has(d))
      continue;
    if (l === "never") {
      s.push(d);
      continue;
    }
    const f = c.run({ value: n[d], issues: [] }, o);
    f instanceof Promise ? e.push(f.then((z) => R(z, t, d, n))) : R(f, t, d, n);
  }
  return s.length && t.issues.push({
    code: "unrecognized_keys",
    keys: s,
    input: n,
    inst: i
  }), e.length ? Promise.all(e).then(() => t) : t;
}
const Fe = /* @__PURE__ */ a("$ZodObject", (e, n) => {
  v.init(e, n);
  const t = O(() => X(n));
  p(e._zod, "propValues", () => {
    const s = n.shape, u = {};
    for (const c in s) {
      const l = s[c]._zod;
      if (l.values) {
        u[c] ?? (u[c] = /* @__PURE__ */ new Set());
        for (const d of l.values)
          u[c].add(d);
      }
    }
    return u;
  });
  const o = N, r = n.catchall;
  let i;
  e._zod.parse = (s, u) => {
    i ?? (i = t.value);
    const c = s.value;
    if (!o(c))
      return s.issues.push({
        expected: "object",
        code: "invalid_type",
        input: c,
        inst: e
      }), s;
    s.value = {};
    const l = [], d = i.shape;
    for (const f of i.keys) {
      const _ = d[f]._zod.run({ value: c[f], issues: [] }, u);
      _ instanceof Promise ? l.push(_.then((m) => R(m, s, f, c))) : R(_, s, f, c);
    }
    return r ? x(l, c, s, u, t.value, e) : l.length ? Promise.all(l).then(() => s) : s;
  };
}), Pn = /* @__PURE__ */ a("$ZodObjectJIT", (e, n) => {
  Fe.init(e, n);
  const t = e._zod.parse, o = O(() => X(n)), r = (z) => {
    const _ = new oe(["shape", "payload", "ctx"]), m = o.value, H = (Z) => {
      const $ = C(Z);
      return `shape[${$}]._zod.run({ value: input[${$}], issues: [] }, ctx)`;
    };
    _.write("const input = payload.value;");
    const j = /* @__PURE__ */ Object.create(null);
    let q = 0;
    for (const Z of m.keys)
      j[Z] = `key_${q++}`;
    _.write("const newResult = {}");
    for (const Z of m.keys) {
      const $ = j[Z], b = C(Z);
      _.write(`const ${$} = ${H(Z)};`), _.write(`
        if (${$}.issues.length) {
          payload.issues = payload.issues.concat(${$}.issues.map(iss => ({
            ...iss,
            path: iss.path ? [${b}, ...iss.path] : [${b}]
          })));
        }
        
        if (${$}.value === undefined) {
          if (${b} in input) {
            newResult[${b}] = undefined;
          }
        } else {
          newResult[${b}] = ${$}.value;
        }
      `);
    }
    _.write("payload.value = newResult;"), _.write("return payload;");
    const Q = _.compile();
    return (Z, $) => Q(z, Z, $);
  };
  let i;
  const s = N, u = !te.jitless, l = u && De.value, d = n.catchall;
  let f;
  e._zod.parse = (z, _) => {
    f ?? (f = o.value);
    const m = z.value;
    return s(m) ? u && l && _?.async === !1 && _.jitless !== !0 ? (i || (i = r(n.shape)), z = i(z, _), d ? x([], m, z, _, f, e) : z) : t(z, _) : (z.issues.push({
      expected: "object",
      code: "invalid_type",
      input: m,
      inst: e
    }), z);
  };
});
function A(e, n, t, o) {
  for (const i of e)
    if (i.issues.length === 0)
      return n.value = i.value, n;
  const r = e.filter((i) => !w(i));
  return r.length === 1 ? (n.value = r[0].value, r[0]) : (n.issues.push({
    code: "invalid_union",
    input: n.value,
    inst: t,
    errors: e.map((i) => i.issues.map((s) => I(s, o, P())))
  }), n);
}
const Ke = /* @__PURE__ */ a("$ZodUnion", (e, n) => {
  v.init(e, n), p(e._zod, "optin", () => n.options.some((r) => r._zod.optin === "optional") ? "optional" : void 0), p(e._zod, "optout", () => n.options.some((r) => r._zod.optout === "optional") ? "optional" : void 0), p(e._zod, "values", () => {
    if (n.options.every((r) => r._zod.values))
      return new Set(n.options.flatMap((r) => Array.from(r._zod.values)));
  }), p(e._zod, "pattern", () => {
    if (n.options.every((r) => r._zod.pattern)) {
      const r = n.options.map((i) => i._zod.pattern);
      return new RegExp(`^(${r.map((i) => U(i.source)).join("|")})$`);
    }
  });
  const t = n.options.length === 1, o = n.options[0]._zod.run;
  e._zod.parse = (r, i) => {
    if (t)
      return o(r, i);
    let s = !1;
    const u = [];
    for (const c of n.options) {
      const l = c._zod.run({
        value: r.value,
        issues: []
      }, i);
      if (l instanceof Promise)
        u.push(l), s = !0;
      else {
        if (l.issues.length === 0)
          return l;
        u.push(l);
      }
    }
    return s ? Promise.all(u).then((c) => A(c, r, e, i)) : A(u, r, e, i);
  };
}), In = /* @__PURE__ */ a("$ZodDiscriminatedUnion", (e, n) => {
  Ke.init(e, n);
  const t = e._zod.parse;
  p(e._zod, "propValues", () => {
    const r = {};
    for (const i of n.options) {
      const s = i._zod.propValues;
      if (!s || Object.keys(s).length === 0)
        throw new Error(`Invalid discriminated union option at index "${n.options.indexOf(i)}"`);
      for (const [u, c] of Object.entries(s)) {
        r[u] || (r[u] = /* @__PURE__ */ new Set());
        for (const l of c)
          r[u].add(l);
      }
    }
    return r;
  });
  const o = O(() => {
    const r = n.options, i = /* @__PURE__ */ new Map();
    for (const s of r) {
      const u = s._zod.propValues?.[n.discriminator];
      if (!u || u.size === 0)
        throw new Error(`Invalid discriminated union option at index "${n.options.indexOf(s)}"`);
      for (const c of u) {
        if (i.has(c))
          throw new Error(`Duplicate discriminator value "${String(c)}"`);
        i.set(c, s);
      }
    }
    return i;
  });
  e._zod.parse = (r, i) => {
    const s = r.value;
    if (!N(s))
      return r.issues.push({
        code: "invalid_type",
        expected: "object",
        input: s,
        inst: e
      }), r;
    const u = o.value.get(s?.[n.discriminator]);
    return u ? u._zod.run(r, i) : n.unionFallback ? t(r, i) : (r.issues.push({
      code: "invalid_union",
      errors: [],
      note: "No matching discriminator",
      discriminator: n.discriminator,
      input: s,
      path: [n.discriminator],
      inst: e
    }), r);
  };
}), Rn = /* @__PURE__ */ a("$ZodIntersection", (e, n) => {
  v.init(e, n), e._zod.parse = (t, o) => {
    const r = t.value, i = n.left._zod.run({ value: r, issues: [] }, o), s = n.right._zod.run({ value: r, issues: [] }, o);
    return i instanceof Promise || s instanceof Promise ? Promise.all([i, s]).then(([c, l]) => B(t, c, l)) : B(t, i, s);
  };
});
function D(e, n) {
  if (e === n)
    return { valid: !0, data: e };
  if (e instanceof Date && n instanceof Date && +e == +n)
    return { valid: !0, data: e };
  if (E(e) && E(n)) {
    const t = Object.keys(n), o = Object.keys(e).filter((i) => t.indexOf(i) !== -1), r = { ...e, ...n };
    for (const i of o) {
      const s = D(e[i], n[i]);
      if (!s.valid)
        return {
          valid: !1,
          mergeErrorPath: [i, ...s.mergeErrorPath]
        };
      r[i] = s.data;
    }
    return { valid: !0, data: r };
  }
  if (Array.isArray(e) && Array.isArray(n)) {
    if (e.length !== n.length)
      return { valid: !1, mergeErrorPath: [] };
    const t = [];
    for (let o = 0; o < e.length; o++) {
      const r = e[o], i = n[o], s = D(r, i);
      if (!s.valid)
        return {
          valid: !1,
          mergeErrorPath: [o, ...s.mergeErrorPath]
        };
      t.push(s.data);
    }
    return { valid: !0, data: t };
  }
  return { valid: !1, mergeErrorPath: [] };
}
function B(e, n, t) {
  if (n.issues.length && e.issues.push(...n.issues), t.issues.length && e.issues.push(...t.issues), w(e))
    return e;
  const o = D(n.value, t.value);
  if (!o.valid)
    throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);
  return e.value = o.data, e;
}
const En = /* @__PURE__ */ a("$ZodRecord", (e, n) => {
  v.init(e, n), e._zod.parse = (t, o) => {
    const r = t.value;
    if (!E(r))
      return t.issues.push({
        expected: "record",
        code: "invalid_type",
        input: r,
        inst: e
      }), t;
    const i = [];
    if (n.keyType._zod.values) {
      const s = n.keyType._zod.values;
      t.value = {};
      for (const c of s)
        if (typeof c == "string" || typeof c == "number" || typeof c == "symbol") {
          const l = n.valueType._zod.run({ value: r[c], issues: [] }, o);
          l instanceof Promise ? i.push(l.then((d) => {
            d.issues.length && t.issues.push(...g(c, d.issues)), t.value[c] = d.value;
          })) : (l.issues.length && t.issues.push(...g(c, l.issues)), t.value[c] = l.value);
        }
      let u;
      for (const c in r)
        s.has(c) || (u = u ?? [], u.push(c));
      u && u.length > 0 && t.issues.push({
        code: "unrecognized_keys",
        input: r,
        inst: e,
        keys: u
      });
    } else {
      t.value = {};
      for (const s of Reflect.ownKeys(r)) {
        if (s === "__proto__")
          continue;
        const u = n.keyType._zod.run({ value: s, issues: [] }, o);
        if (u instanceof Promise)
          throw new Error("Async schemas not supported in object keys currently");
        if (u.issues.length) {
          t.issues.push({
            code: "invalid_key",
            origin: "record",
            issues: u.issues.map((l) => I(l, o, P())),
            input: s,
            path: [s],
            inst: e
          }), t.value[u.value] = u.value;
          continue;
        }
        const c = n.valueType._zod.run({ value: r[s], issues: [] }, o);
        c instanceof Promise ? i.push(c.then((l) => {
          l.issues.length && t.issues.push(...g(s, l.issues)), t.value[u.value] = l.value;
        })) : (c.issues.length && t.issues.push(...g(s, c.issues)), t.value[u.value] = c.value);
      }
    }
    return i.length ? Promise.all(i).then(() => t) : t;
  };
}), Sn = /* @__PURE__ */ a("$ZodEnum", (e, n) => {
  v.init(e, n);
  const t = Oe(n.entries), o = new Set(t);
  e._zod.values = o, e._zod.pattern = new RegExp(`^(${t.filter((r) => Ne.has(typeof r)).map((r) => typeof r == "string" ? S(r) : r.toString()).join("|")})$`), e._zod.parse = (r, i) => {
    const s = r.value;
    return o.has(s) || r.issues.push({
      code: "invalid_value",
      values: t,
      input: s,
      inst: e
    }), r;
  };
}), Dn = /* @__PURE__ */ a("$ZodLiteral", (e, n) => {
  if (v.init(e, n), n.values.length === 0)
    throw new Error("Cannot create literal schema with no valid values");
  e._zod.values = new Set(n.values), e._zod.pattern = new RegExp(`^(${n.values.map((t) => typeof t == "string" ? S(t) : t ? S(t.toString()) : String(t)).join("|")})$`), e._zod.parse = (t, o) => {
    const r = t.value;
    return e._zod.values.has(r) || t.issues.push({
      code: "invalid_value",
      values: n.values,
      input: r,
      inst: e
    }), t;
  };
}), On = /* @__PURE__ */ a("$ZodTransform", (e, n) => {
  v.init(e, n), e._zod.parse = (t, o) => {
    if (o.direction === "backward")
      throw new re(e.constructor.name);
    const r = n.transform(t.value, t);
    if (o.async)
      return (r instanceof Promise ? r : Promise.resolve(r)).then((s) => (t.value = s, t));
    if (r instanceof Promise)
      throw new T();
    return t.value = r, t;
  };
});
function F(e, n) {
  return e.issues.length && n === void 0 ? { issues: [], value: void 0 } : e;
}
const Nn = /* @__PURE__ */ a("$ZodOptional", (e, n) => {
  v.init(e, n), e._zod.optin = "optional", e._zod.optout = "optional", p(e._zod, "values", () => n.innerType._zod.values ? /* @__PURE__ */ new Set([...n.innerType._zod.values, void 0]) : void 0), p(e._zod, "pattern", () => {
    const t = n.innerType._zod.pattern;
    return t ? new RegExp(`^(${U(t.source)})?$`) : void 0;
  }), e._zod.parse = (t, o) => {
    if (n.innerType._zod.optin === "optional") {
      const r = n.innerType._zod.run(t, o);
      return r instanceof Promise ? r.then((i) => F(i, t.value)) : F(r, t.value);
    }
    return t.value === void 0 ? t : n.innerType._zod.run(t, o);
  };
}), Un = /* @__PURE__ */ a("$ZodNullable", (e, n) => {
  v.init(e, n), p(e._zod, "optin", () => n.innerType._zod.optin), p(e._zod, "optout", () => n.innerType._zod.optout), p(e._zod, "pattern", () => {
    const t = n.innerType._zod.pattern;
    return t ? new RegExp(`^(${U(t.source)}|null)$`) : void 0;
  }), p(e._zod, "values", () => n.innerType._zod.values ? /* @__PURE__ */ new Set([...n.innerType._zod.values, null]) : void 0), e._zod.parse = (t, o) => t.value === null ? t : n.innerType._zod.run(t, o);
}), jn = /* @__PURE__ */ a("$ZodDefault", (e, n) => {
  v.init(e, n), e._zod.optin = "optional", p(e._zod, "values", () => n.innerType._zod.values), e._zod.parse = (t, o) => {
    if (o.direction === "backward")
      return n.innerType._zod.run(t, o);
    if (t.value === void 0)
      return t.value = n.defaultValue, t;
    const r = n.innerType._zod.run(t, o);
    return r instanceof Promise ? r.then((i) => K(i, n)) : K(r, n);
  };
});
function K(e, n) {
  return e.value === void 0 && (e.value = n.defaultValue), e;
}
const Vn = /* @__PURE__ */ a("$ZodPrefault", (e, n) => {
  v.init(e, n), e._zod.optin = "optional", p(e._zod, "values", () => n.innerType._zod.values), e._zod.parse = (t, o) => (o.direction === "backward" || t.value === void 0 && (t.value = n.defaultValue), n.innerType._zod.run(t, o));
}), Cn = /* @__PURE__ */ a("$ZodNonOptional", (e, n) => {
  v.init(e, n), p(e._zod, "values", () => {
    const t = n.innerType._zod.values;
    return t ? new Set([...t].filter((o) => o !== void 0)) : void 0;
  }), e._zod.parse = (t, o) => {
    const r = n.innerType._zod.run(t, o);
    return r instanceof Promise ? r.then((i) => J(i, e)) : J(r, e);
  };
});
function J(e, n) {
  return !e.issues.length && e.value === void 0 && e.issues.push({
    code: "invalid_type",
    expected: "nonoptional",
    input: e.value,
    inst: n
  }), e;
}
const Ln = /* @__PURE__ */ a("$ZodCatch", (e, n) => {
  v.init(e, n), p(e._zod, "optin", () => n.innerType._zod.optin), p(e._zod, "optout", () => n.innerType._zod.optout), p(e._zod, "values", () => n.innerType._zod.values), e._zod.parse = (t, o) => {
    if (o.direction === "backward")
      return n.innerType._zod.run(t, o);
    const r = n.innerType._zod.run(t, o);
    return r instanceof Promise ? r.then((i) => (t.value = i.value, i.issues.length && (t.value = n.catchValue({
      ...t,
      error: {
        issues: i.issues.map((s) => I(s, o, P()))
      },
      input: t.value
    }), t.issues = []), t)) : (t.value = r.value, r.issues.length && (t.value = n.catchValue({
      ...t,
      error: {
        issues: r.issues.map((i) => I(i, o, P()))
      },
      input: t.value
    }), t.issues = []), t);
  };
}), An = /* @__PURE__ */ a("$ZodPipe", (e, n) => {
  v.init(e, n), p(e._zod, "values", () => n.in._zod.values), p(e._zod, "optin", () => n.in._zod.optin), p(e._zod, "optout", () => n.out._zod.optout), p(e._zod, "propValues", () => n.in._zod.propValues), e._zod.parse = (t, o) => {
    if (o.direction === "backward") {
      const i = n.out._zod.run(t, o);
      return i instanceof Promise ? i.then((s) => k(s, n.in, o)) : k(i, n.in, o);
    }
    const r = n.in._zod.run(t, o);
    return r instanceof Promise ? r.then((i) => k(i, n.out, o)) : k(r, n.out, o);
  };
});
function k(e, n, t) {
  return e.issues.length ? (e.aborted = !0, e) : n._zod.run({ value: e.value, issues: e.issues }, t);
}
const Bn = /* @__PURE__ */ a("$ZodReadonly", (e, n) => {
  v.init(e, n), p(e._zod, "propValues", () => n.innerType._zod.propValues), p(e._zod, "values", () => n.innerType._zod.values), p(e._zod, "optin", () => n.innerType._zod.optin), p(e._zod, "optout", () => n.innerType._zod.optout), e._zod.parse = (t, o) => {
    if (o.direction === "backward")
      return n.innerType._zod.run(t, o);
    const r = n.innerType._zod.run(t, o);
    return r instanceof Promise ? r.then(y) : y(r);
  };
});
function y(e) {
  return e.value = Object.freeze(e.value), e;
}
const Fn = /* @__PURE__ */ a("$ZodLazy", (e, n) => {
  v.init(e, n), p(e._zod, "innerType", () => n.getter()), p(e._zod, "pattern", () => e._zod.innerType._zod.pattern), p(e._zod, "propValues", () => e._zod.innerType._zod.propValues), p(e._zod, "optin", () => e._zod.innerType._zod.optin ?? void 0), p(e._zod, "optout", () => e._zod.innerType._zod.optout ?? void 0), e._zod.parse = (t, o) => e._zod.innerType._zod.run(t, o);
}), Kn = /* @__PURE__ */ a("$ZodCustom", (e, n) => {
  Y.init(e, n), v.init(e, n), e._zod.parse = (t, o) => t, e._zod.check = (t) => {
    const o = t.value, r = n.fn(o);
    if (r instanceof Promise)
      return r.then((i) => M(i, t, o, e));
    M(r, t, o, e);
  };
});
function M(e, n, t, o) {
  if (!e) {
    const r = {
      code: "custom",
      input: t,
      inst: o,
      // incorporates params.error into issue reporting
      path: [...o._zod.def.path ?? []],
      // incorporates params.error into issue reporting
      continue: !o._zod.def.abort
      // params: inst._zod.def.params,
    };
    o._zod.def.params && (r.params = o._zod.def.params), n.issues.push(Ue(r));
  }
}
export {
  Tn as $ZodArray,
  zn as $ZodBase64,
  fn as $ZodBase64URL,
  gn as $ZodBoolean,
  hn as $ZodCIDRv4,
  _n as $ZodCIDRv6,
  tn as $ZodCUID,
  rn as $ZodCUID2,
  Ln as $ZodCatch,
  Kn as $ZodCustom,
  jn as $ZodDefault,
  In as $ZodDiscriminatedUnion,
  mn as $ZodE164,
  Qe as $ZodEmail,
  en as $ZodEmoji,
  Sn as $ZodEnum,
  He as $ZodGUID,
  dn as $ZodIPv4,
  vn as $ZodIPv6,
  an as $ZodISODate,
  cn as $ZodISODateTime,
  pn as $ZodISODuration,
  ln as $ZodISOTime,
  Rn as $ZodIntersection,
  $n as $ZodJWT,
  un as $ZodKSUID,
  Fn as $ZodLazy,
  Dn as $ZodLiteral,
  nn as $ZodNanoID,
  kn as $ZodNever,
  Cn as $ZodNonOptional,
  wn as $ZodNull,
  Un as $ZodNullable,
  Be as $ZodNumber,
  Zn as $ZodNumberFormat,
  Fe as $ZodObject,
  Pn as $ZodObjectJIT,
  Nn as $ZodOptional,
  An as $ZodPipe,
  Vn as $ZodPrefault,
  Bn as $ZodReadonly,
  En as $ZodRecord,
  Ce as $ZodString,
  h as $ZodStringFormat,
  On as $ZodTransform,
  v as $ZodType,
  on as $ZodULID,
  Ye as $ZodURL,
  qe as $ZodUUID,
  Ke as $ZodUnion,
  bn as $ZodUnknown,
  sn as $ZodXID,
  Mn as clone,
  G as isValidBase64,
  Le as isValidBase64URL,
  Ae as isValidJWT
};
//# sourceMappingURL=schemas.js.map
