Repository: colinhacks/zod
Pull request #4556 (2025-05-28 23:36:30)

Improve discriminated union implementation
Remove the `disc` field from internals and replace with a simple `propValues` map. This makes introspection into discriminator values far easier, simplifies the parsing logic, and results in a 2x performance improvement:

```sh
$ cd packages/bench
$ pnpm bench discriminated-union
cpu: Apple M1 Max
runtime: node v22.13.0 (arm64-darwin)

benchmark           time (avg)             (min … max)       p75       p99      p999
------------------------------------------------------ -----------------------------
• z.disriminatedUnion().parse
------------------------------------------------------ -----------------------------
zod 3           33'996 ns/iter    (31'625 ns … 321 µs) 32'416 ns    129 µs    189 µs
zod 4 (after)    9'528 ns/iter     (9'000 ns … 223 µs)  9'209 ns 10'083 ns    117 µs
zod 4 (before)  19'161 ns/iter    (18'291 ns … 207 µs) 18'584 ns 32'542 ns    128 µs

summary for z.disriminatedUnion().parse
  zod 4 (after)
   2.01x faster than zod 4 (before)
   3.57x faster than zod 3
```


Patch:
diff --git a/packages/bench/discriminated-union.ts b/packages/bench/discriminated-union.ts
index c88411e6..fb983e40 100644
--- a/packages/bench/discriminated-union.ts
+++ b/packages/bench/discriminated-union.ts
@@ -1,4 +1,4 @@
-import { makeData, makeSchema, randomPick, randomString } from "./benchUtil.js";
+import { makeData, randomPick, randomString } from "./benchUtil.js";
 import { metabench } from "./metabench.js";
 
 
@@ -54,55 +54,54 @@ const z3DiscUnion = z3.discriminatedUnion("type", z3Union._def.options);
 
 function makeSchema(z: typeof z4){
    const z4fields = {
-  data1: z4.string(),
-  data2: z4.string(),
-  data3: z4.string(),
-  // data4: z4.string(),
-  // data5: z4.string(),
-  // data6: z4.string(),
-  // data7: z4.string(),
-  // data8: z4.string(),
-  // data9: z4.string(),
-  // data10: z4.string(),
-}
-const z4Union = z4.union([
-  z4.object({
-    type: z4.literal("a"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("b"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("c"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("d"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("e"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("f"),
-    ...z4fields
-  }),
-  z4.object({
-    type: z4.literal("g"),
-    ...z4fields
-  }),
-]);
-return z4Union;
+    data1: z.string(),
+    data2: z.string(),
+    data3: z.string(),
+    // data4: z.string(),
+    // data5: z.string(),
+    // data6: z.string(),
+    // data7: z.string(),
+    // data8: z.string(),
+    // data9: z.string(),
+    // data10: z.string(),
+  }
+  const z4Union = z.union([
+    z.object({
+      type: z.literal("a"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("b"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("c"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("d"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("e"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("f"),
+      ...z4fields
+    }),
+    z.object({
+      type: z.literal("g"),
+      ...z4fields
+    }),
+  ]);
+  return z4Union;
 
 }
 
 const z4Union = makeSchema(z4);
 const z4LibUnion  = makeSchema(z4lib as any);
-const z4LibDiscUnion  = z4lib.discriminatedUnion( z4LibUnion._def.options);
-
+const z4LibDiscUnion  = z4lib.discriminatedUnion("type", z4LibUnion._def.options as any);
 const z4DiscUnion = z4.discriminatedUnion("type", z4Union.def.options);
 
 const DATA = makeData(100, () => ({ 
@@ -137,7 +136,7 @@ console.dir(z4LibDiscUnion.parse(DATA[0]), {depth: null});
 
 
 const args=  {jitless: true}
-const bench = metabench("z.disriminatedUnion().parse", {
+const bench = metabench("z.discriminatedUnion().parse", {
   // z3() {
   //   for (const item of DATA) {
   //     z3Union.parse(item);
diff --git a/packages/bench/index.ts b/packages/bench/index.ts
index c7dbfabc..6cc9b088 100644
--- a/packages/bench/index.ts
+++ b/packages/bench/index.ts
@@ -6,7 +6,7 @@ async function run() {
   const files = process.argv[2].split(",").map((file) => import.meta.resolve(`./${file}`).replace("file://", ""));
 
   for (const file of files) {
-    await $`pnpm tsx --conditions @zod/source ${file}`;
+    await $`pnpm tsx ${file}`;
   }
 }
 
diff --git a/packages/bench/jit-union.ts b/packages/bench/jit-union.ts
index 92f3c857..910c2e6e 100644
--- a/packages/bench/jit-union.ts
+++ b/packages/bench/jit-union.ts
@@ -74,7 +74,7 @@ const DATA = makeData(100, () => ({
 const args=  {jitless: true}
 console.dir(z4Union.parse(DATA[0]), {depth: null});
 console.dir(z4Union.parse(DATA[0], args), {depth: null});
-const bench = metabench("z.disriminatedUnion().parse", {
+const bench = metabench("z.discriminatedUnion().parse", {
 
   v4_jit() {
     for (const item of DATA) {
diff --git a/packages/bench/package.json b/packages/bench/package.json
index 466baa9e..7ab71989 100644
--- a/packages/bench/package.json
+++ b/packages/bench/package.json
@@ -6,7 +6,7 @@
     "arktype": "^2.1.19",
     "valibot": "^1.0.0",
     "zod": "workspace:*",
-    "zodnext": "npm:zod@next",
+    "zodnext": "npm:zod@^3.25.0",
     "zod3": "npm:zod@^3.23.7"
   },
   "scripts": {
diff --git a/packages/docs/content/v4/index.mdx b/packages/docs/content/v4/index.mdx
index e5491bfb..686841cb 100644
--- a/packages/docs/content/v4/index.mdx
+++ b/packages/docs/content/v4/index.mdx
@@ -827,7 +827,7 @@ Replace `errorMap` with `error` (function syntax):
 
 ## Upgraded `z.discriminatedUnion()`
 
-Discriminated unions now support a number of schema types not previously supported, including unions, pipes, and nested objects:
+Discriminated unions now support a number of schema types not previously supported, including unions and pipes:
 
 ```ts
 const MyResult = z.discriminatedUnion("status", [
@@ -836,7 +836,7 @@ const MyResult = z.discriminatedUnion("status", [
   // union discriminator
   z.object({ status: z.union([z.literal("bbb"), z.literal("ccc")]) }),
   // pipe discriminator
-  z.object({ status: z.object({ value: z.literal("fail") }) }),
+  z.object({ status: z.literal("fail").transform(val => val.toUpperCase()) }),
 ]);
 ```
 
@@ -844,15 +844,14 @@ Perhaps most importantly, discriminated unions now *compose*—you can use one d
 
 ```ts
 const BaseError = z.object({ status: z.literal("failed"), message: z.string() });
-const MyErrors = z.discriminatedUnion("code", [
-  BaseError.extend({ code: z.literal(400) }),
-  BaseError.extend({ code: z.literal(401) }),
-  BaseError.extend({ code: z.literal(500) })
-]);
 
 const MyResult = z.discriminatedUnion("status", [
   z.object({ status: z.literal("success"), data: z.string() }),
-  MyErrors
+  z.discriminatedUnion("code", [
+    BaseError.extend({ code: z.literal(400) }),
+    BaseError.extend({ code: z.literal(401) }),
+    BaseError.extend({ code: z.literal(500) })
+  ])
 ]);
 ```
 
diff --git a/packages/treeshake/out.js b/packages/treeshake/out.js
index 007077c9..ecec4acb 100644
--- a/packages/treeshake/out.js
+++ b/packages/treeshake/out.js
@@ -1,40 +1,43 @@
 function $constructor(name, initializer, params) {
-    const Parent = params?.Parent ?? Object;
-    class _ extends Parent {
-        constructor(def) {
-            var _a;
-            super();
-            const th = this;
-            _.init(th, def);
-            (_a = th._zod).deferred ?? (_a.deferred = []);
-            for (const fn of th._zod.deferred) {
-                fn();
-            }
+    function init(inst, def) {
+        var _a;
+        Object.defineProperty(inst, "_zod", {
+            value: inst._zod ?? {},
+            enumerable: false,
+        });
+        (_a = inst._zod).traits ?? (_a.traits = new Set());
+        inst._zod.traits.add(name);
+        initializer(inst, def);
+        // support prototype modifications
+        for (const k in _.prototype) {
+            Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
         }
-        static init(inst, def) {
-            var _a;
-            Object.defineProperty(inst, "_zod", {
-                value: inst._zod ?? {},
-                enumerable: false,
-            });
-            // inst._zod ??= {} as any;
-            (_a = inst._zod).traits ?? (_a.traits = new Set());
-            // const seen = inst._zod.traits.has(name);
-            inst._zod.traits.add(name);
-            initializer(inst, def);
-            // support prototype modifications
-            for (const k in _.prototype) {
-                Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
-            }
-            inst._zod.constr = _;
-            inst._zod.def = def;
+        inst._zod.constr = _;
+        inst._zod.def = def;
+    }
+    // doesn't work if Parent has a constructor with arguments
+    const Parent = params?.Parent ?? Object;
+    class Definition extends Parent {
+    }
+    Object.defineProperty(Definition, "name", { value: name });
+    function _(def) {
+        var _a;
+        const inst = params?.Parent ? new Definition() : this;
+        init(inst, def);
+        (_a = inst._zod).deferred ?? (_a.deferred = []);
+        for (const fn of inst._zod.deferred) {
+            fn();
         }
-        static [Symbol.hasInstance](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 _;
 }
@@ -48,91 +51,22 @@ function config(newConfig) {
     return globalConfig;
 }
 
-const initializer$1 = (inst, def) => {
-    Object.defineProperty(inst, "_zod", {
-        value: inst._zod,
-        enumerable: false,
-    });
-    Object.defineProperty(inst, "issues", {
-        value: def,
-        enumerable: true,
-    });
-    // inst.message = `Invalid input`;
-    // Object.defineProperty(inst, "message", {
-    //   get() {
-    //     return (
-    //       "\n" +
-    //       inst.issues
-    //         .map((iss) => {
-    //           return `✖ ${iss.message}${iss.path.length ? ` [${iss.path.join(".")}]` : ""}`;
-    //         })
-    //         .join("\n")
-    //     );
-    //   },
-    //   enumerable: false,
-    // });
-};
-const $ZodError = $constructor("$ZodError", initializer$1);
-function flattenError(error, mapper = (issue) => issue.message) {
-    const fieldErrors = {};
-    const formErrors = [];
-    for (const sub of error.issues) {
-        if (sub.path.length > 0) {
-            fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
-            fieldErrors[sub.path[0]].push(mapper(sub));
-        }
-        else {
-            formErrors.push(mapper(sub));
-        }
-    }
-    return { formErrors, fieldErrors };
-}
-function formatError(error, _mapper) {
-    const mapper = _mapper ||
-        function (issue) {
-            return issue.message;
-        };
-    const fieldErrors = { _errors: [] };
-    const processError = (error) => {
-        for (const issue of error.issues) {
-            if (issue.code === "invalid_union") {
-                issue.errors.map((issues) => processError({ issues }));
-            }
-            else if (issue.code === "invalid_key") {
-                processError({ issues: issue.issues });
-            }
-            else if (issue.code === "invalid_element") {
-                processError({ issues: issue.issues });
-            }
-            else if (issue.path.length === 0) {
-                fieldErrors._errors.push(mapper(issue));
-            }
-            else {
-                let curr = fieldErrors;
-                let i = 0;
-                while (i < issue.path.length) {
-                    const el = issue.path[i];
-                    const terminal = i === issue.path.length - 1;
-                    if (!terminal) {
-                        curr[el] = curr[el] || { _errors: [] };
-                    }
-                    else {
-                        curr[el] = curr[el] || { _errors: [] };
-                        curr[el]._errors.push(mapper(issue));
-                    }
-                    curr = curr[el];
-                    i++;
-                }
+// functions
+function jsonStringifyReplacer(_, value) {
+    if (typeof value === "bigint")
+        return value.toString();
+    return value;
+}
+function cached(getter) {
+    return {
+        get value() {
+            {
+                const value = getter();
+                Object.defineProperty(this, "value", { value });
+                return value;
             }
-        }
+        },
     };
-    processError(error);
-    return fieldErrors;
-}
-
-// functions
-function nullish(input) {
-    return input === null || input === undefined;
 }
 function cleanRegex(source) {
     const start = source.startsWith("^") ? 1 : 0;
@@ -158,6 +92,14 @@ function defineLazy(object, key, getter) {
         configurable: true,
     });
 }
+function assignProp(target, prop, value) {
+    Object.defineProperty(target, prop, {
+        value,
+        writable: true,
+        enumerable: true,
+        configurable: true,
+    });
+}
 function randomString(length = 10) {
     const chars = "abcdefghijklmnopqrstuvwxyz";
     let str = "";
@@ -166,9 +108,22 @@ function randomString(length = 10) {
     }
     return str;
 }
-function isPlainObject(data) {
-    return typeof data === "object" && data !== null && Object.getPrototypeOf(data) === Object.prototype;
+function esc(str) {
+    return JSON.stringify(str);
 }
+function isObject(data) {
+    return typeof data === "object" && data !== null && !Array.isArray(data);
+}
+const allowsEval = cached(() => {
+    try {
+        const F = Function;
+        new F("");
+        return true;
+    }
+    catch (_) {
+        return false;
+    }
+});
 function escapeRegex(str) {
     return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
 }
@@ -180,20 +135,12 @@ function clone(inst, def, params) {
     return cl;
 }
 function normalizeParams(_params) {
-    const params = _params;
-    if (!params)
-        return {};
-    if (typeof params === "string")
-        return { error: () => params };
-    if (params?.message !== undefined) {
-        if (params?.error !== undefined)
-            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;
+    return {};
+}
+function optionalKeys(shape) {
+    return Object.keys(shape).filter((k) => {
+        return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
+    });
 }
 function aborted(x, startIndex = 0) {
     for (let i = startIndex; i < x.issues.length; i++) {
@@ -232,25 +179,27 @@ function finalizeIssue(iss, ctx, config) {
     }
     return full;
 }
-function getLengthableOrigin(input) {
-    if (Array.isArray(input))
-        return "array";
-    if (typeof input === "string")
-        return "string";
-    return "unknown";
-}
-function issue(...args) {
-    const [iss, input, inst] = args;
-    if (typeof iss === "string") {
-        return {
-            message: iss,
-            code: "custom",
-            input,
-            inst,
-        };
-    }
-    return { ...iss };
-}
+
+const initializer = (inst, def) => {
+    inst.name = "$ZodError";
+    Object.defineProperty(inst, "_zod", {
+        value: inst._zod,
+        enumerable: false,
+    });
+    Object.defineProperty(inst, "issues", {
+        value: def,
+        enumerable: false,
+    });
+    Object.defineProperty(inst, "message", {
+        get() {
+            return JSON.stringify(def, jsonStringifyReplacer, 2);
+        },
+        enumerable: true,
+        // configurable: false,
+    });
+};
+const $ZodError = $constructor("$ZodError", initializer);
+const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
 
 const _parse = (_Err) => (schema, value, _ctx, _params) => {
     const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
@@ -265,6 +214,7 @@ const _parse = (_Err) => (schema, value, _ctx, _params) => {
     }
     return result.value;
 };
+const parse = /* @__PURE__*/ _parse($ZodRealError);
 const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
     const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
     let result = schema._zod.run({ value, issues: [] }, ctx);
@@ -277,6 +227,7 @@ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
     }
     return result.value;
 };
+const parseAsync = /* @__PURE__*/ _parseAsync($ZodRealError);
 const _safeParse = (_Err) => (schema, value, _ctx) => {
     const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
     const result = schema._zod.run({ value, issues: [] }, ctx);
@@ -290,7 +241,7 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
         }
         : { success: true, data: result.value };
 };
-const safeParse$1 = /* @__PURE__*/ _safeParse($ZodError);
+const safeParse = /* @__PURE__*/ _safeParse($ZodRealError);
 const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
     const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
     let result = schema._zod.run({ value, issues: [] }, ctx);
@@ -303,289 +254,49 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
         }
         : { success: true, data: result.value };
 };
-const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodError);
+const safeParseAsync = /* @__PURE__*/ _safeParseAsync($ZodRealError);
 
-const cuid = /^[cC][^\s-]{8,}$/;
-const cuid2 = /^[0-9a-z]+$/;
-const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
-const xid = /^[0-9a-vA-V]{20}$/;
-const ksuid = /^[A-Za-z0-9]{27}$/;
-const nanoid = /^[a-zA-Z0-9_-]{21}$/;
-/** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
-const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
-/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
-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})$/;
-/** Returns a regex for validating an RFC 4122 UUID.
- *
- * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
-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)$/;
-    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})$`);
-};
-/** Practical email validation */
-const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
-// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
-const _emoji$1 = `^(\\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})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
-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})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
-// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
-const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
-const base64url = /^[A-Za-z0-9_-]*$/;
-// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
-// export const hostname: RegExp =
-//   /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
-const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
-// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
-const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
-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])))`;
-const date$1 = new RegExp(`^${dateSource}$`);
-function timeSource(args) {
-    // let regex = `\\d{2}:\\d{2}:\\d{2}`;
-    let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
-    if (args.precision) {
-        regex = `${regex}\\.\\d{${args.precision}}`;
-    }
-    else if (args.precision == null) {
-        regex = `${regex}(\\.\\d+)?`;
-    }
-    return regex;
-}
-function time$1(args) {
-    return new RegExp(`^${timeSource(args)}$`);
-}
-// Adapted from https://stackoverflow.com/a/3143231
-function datetime$1(args) {
-    let regex = `${dateSource}T${timeSource(args)}`;
-    const opts = [];
-    opts.push(args.local ? `Z?` : `Z`);
-    if (args.offset)
-        opts.push(`([+-]\\d{2}:?\\d{2})`);
-    regex = `${regex}(${opts.join("|")})`;
-    return new RegExp(`^${regex}$`);
-}
 const string$1 = (params) => {
     const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
     return new RegExp(`^${regex}$`);
 };
-// regex for string with no uppercase letters
-const lowercase = /^[^A-Z]*$/;
-// regex for string with no lowercase letters
-const uppercase = /^[^a-z]*$/;
 
-// import { $ZodType } from "./schemas.js";
-const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
-    var _a;
-    inst._zod ?? (inst._zod = {});
-    inst._zod.def = def;
-    (_a = inst._zod).onattach ?? (_a.onattach = []);
-});
-const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    inst._zod.when = (payload) => {
-        const val = payload.value;
-        return !nullish(val) && val.length !== undefined;
-    };
-    inst._zod.onattach.push((inst) => {
-        const curr = (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY);
-        if (def.maximum < curr)
-            inst._zod.bag.maximum = def.maximum;
-    });
-    inst._zod.check = (payload) => {
-        const input = payload.value;
-        const length = input.length;
-        if (length <= def.maximum)
-            return;
-        const origin = getLengthableOrigin(input);
-        payload.issues.push({
-            origin,
-            code: "too_big",
-            maximum: def.maximum,
-            input,
-            inst,
-            continue: !def.abort,
-        });
-    };
-});
-const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    inst._zod.when = (payload) => {
-        const val = payload.value;
-        return !nullish(val) && val.length !== undefined;
-    };
-    inst._zod.onattach.push((inst) => {
-        const curr = (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY);
-        if (def.minimum > curr)
-            inst._zod.bag.minimum = def.minimum;
-    });
-    inst._zod.check = (payload) => {
-        const input = payload.value;
-        const length = input.length;
-        if (length >= def.minimum)
-            return;
-        const origin = getLengthableOrigin(input);
-        payload.issues.push({
-            origin,
-            code: "too_small",
-            minimum: def.minimum,
-            input,
-            inst,
-            continue: !def.abort,
-        });
-    };
-});
-const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    inst._zod.when = (payload) => {
-        const val = payload.value;
-        return !nullish(val) && val.length !== undefined;
-    };
-    inst._zod.onattach.push((inst) => {
-        const bag = inst._zod.bag;
-        bag.minimum = def.length;
-        bag.maximum = def.length;
-        bag.length = def.length;
-    });
-    inst._zod.check = (payload) => {
-        const input = payload.value;
-        const length = input.length;
-        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 }),
-            input: payload.value,
-            inst,
-            continue: !def.abort,
-        });
-    };
-});
-const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
-    var _a;
-    $ZodCheck.init(inst, def);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.format = def.format;
-        if (def.pattern)
-            inst._zod.bag.pattern = def.pattern;
-    });
-    (_a = inst._zod).check ?? (_a.check = (payload) => {
-        if (!def.pattern)
-            throw new Error("Not implemented.");
-        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,
-        });
-    });
-});
-const $ZodCheckRegex = /*@__PURE__*/ $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 = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
-    def.pattern ?? (def.pattern = lowercase);
-    $ZodCheckStringFormat.init(inst, def);
-});
-const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
-    def.pattern ?? (def.pattern = uppercase);
-    $ZodCheckStringFormat.init(inst, def);
-});
-const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    const pattern = new RegExp(escapeRegex(def.includes));
-    def.pattern = pattern;
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.pattern = pattern;
-    });
-    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 = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
-    def.pattern ?? (def.pattern = pattern);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.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 = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
-    def.pattern ?? (def.pattern = pattern);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
-    });
-    inst._zod.check = (payload) => {
-        if (payload.value.endsWith(def.suffix))
+class Doc {
+    constructor(args = []) {
+        this.content = [];
+        this.indent = 0;
+        if (this)
+            this.args = args;
+    }
+    indented(fn) {
+        this.indent += 1;
+        fn(this);
+        this.indent -= 1;
+    }
+    write(arg) {
+        if (typeof arg === "function") {
+            arg(this, { execution: "sync" });
+            arg(this, { execution: "async" });
             return;
-        payload.issues.push({
-            origin: "string",
-            code: "invalid_format",
-            format: "ends_with",
-            suffix: def.suffix,
-            input: payload.value,
-            inst,
-            continue: !def.abort,
-        });
-    };
-});
-const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    inst._zod.check = (payload) => {
-        payload.value = def.tx(payload.value);
-    };
-});
+        }
+        const content = arg;
+        const lines = content.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 args = this?.args;
+        const content = this?.content ?? [``];
+        const lines = [...content.map((x) => `  ${x}`)];
+        // console.log(lines.join("\n"));
+        // console.dir("COMPILE", {depth: null});
+        return new F(...args, lines.join("\n"));
+    }
+}
 
 const version = {
     major: 4,
@@ -677,11 +388,11 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
     inst["~standard"] = {
         validate: (value) => {
             try {
-                const r = safeParse$1(inst, value);
+                const r = safeParse(inst, value);
                 return r.success ? { value: r.data } : { issues: r.error?.issues };
             }
             catch (_) {
-                return safeParseAsync$1(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
+                return safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
             }
         },
         vendor: "zod",
@@ -690,7 +401,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
 });
 const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
     $ZodType.init(inst, def);
-    inst._zod.pattern = inst?._zod.bag?.pattern ?? string$1(inst._zod.bag);
+    inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
     inst._zod.parse = (payload, _) => {
         if (def.coerce)
             try {
@@ -708,342 +419,222 @@ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
         return payload;
     };
 });
-const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
-    // check initialization must come first
-    $ZodCheckStringFormat.init(inst, def);
-    $ZodString.init(inst, def);
-});
-const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
-    def.pattern ?? (def.pattern = guid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
-    if (def.version) {
-        const versionMap = {
-            v1: 1,
-            v2: 2,
-            v3: 3,
-            v4: 4,
-            v5: 5,
-            v6: 6,
-            v7: 7,
-            v8: 8,
-        };
-        const v = versionMap[def.version];
-        if (v === undefined)
-            throw new Error(`Invalid UUID version: "${def.version}"`);
-        def.pattern ?? (def.pattern = uuid(v));
+function handleObjectResult(result, final, key) {
+    // if(isOptional)
+    if (result.issues.length) {
+        final.issues.push(...prefixIssues(key, result.issues));
     }
-    else
-        def.pattern ?? (def.pattern = uuid());
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
-    def.pattern ?? (def.pattern = email);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
-    $ZodStringFormat.init(inst, def);
-    inst._zod.check = (payload) => {
-        try {
-            const url = new URL(payload.value);
-            hostname.lastIndex = 0;
-            if (!hostname.test(url.hostname)) {
-                payload.issues.push({
-                    code: "invalid_format",
-                    format: "url",
-                    note: "Invalid hostname",
-                    pattern: hostname.source,
-                    input: payload.value,
-                    inst,
-                });
-            }
-            if (def.hostname) {
-                def.hostname.lastIndex = 0;
-                if (!def.hostname.test(url.hostname)) {
-                    payload.issues.push({
-                        code: "invalid_format",
-                        format: "url",
-                        note: "Invalid hostname",
-                        pattern: def.hostname.source,
-                        input: payload.value,
-                        inst,
-                    });
-                }
+    final.value[key] = result.value;
+}
+function handleOptionalObjectResult(result, final, key, input) {
+    if (result.issues.length) {
+        // validation failed against value schema
+        if (input[key] === undefined) {
+            // if input was undefined, ignore the error
+            if (key in input) {
+                final.value[key] = undefined;
             }
-            if (def.protocol) {
-                def.protocol.lastIndex = 0;
-                if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
-                    payload.issues.push({
-                        code: "invalid_format",
-                        format: "url",
-                        note: "Invalid protocol",
-                        pattern: def.protocol.source,
-                        input: payload.value,
-                        inst,
-                    });
-                }
+            else {
+                final.value[key] = result.value;
             }
-            return;
         }
-        catch (_) {
-            payload.issues.push({
-                code: "invalid_format",
-                format: "url",
-                input: payload.value,
-                inst,
-            });
+        else {
+            final.issues.push(...prefixIssues(key, result.issues));
         }
-    };
-});
-const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
-    def.pattern ?? (def.pattern = emoji());
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
-    def.pattern ?? (def.pattern = nanoid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
-    def.pattern ?? (def.pattern = cuid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
-    def.pattern ?? (def.pattern = cuid2);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
-    def.pattern ?? (def.pattern = ulid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
-    def.pattern ?? (def.pattern = xid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
-    def.pattern ?? (def.pattern = ksuid);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
-    def.pattern ?? (def.pattern = datetime$1(def));
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
-    def.pattern ?? (def.pattern = date$1);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
-    def.pattern ?? (def.pattern = time$1(def));
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
-    def.pattern ?? (def.pattern = duration$1);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
-    def.pattern ?? (def.pattern = ipv4);
-    $ZodStringFormat.init(inst, def);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.format = `ipv4`;
+    }
+    else if (result.value === undefined) {
+        // validation returned `undefined`
+        if (key in input)
+            final.value[key] = undefined;
+    }
+    else {
+        // non-undefined value
+        final.value[key] = result.value;
+    }
+}
+const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
+    $ZodType.init(inst, def);
+    const _normalized = cached(() => {
+        const keys = Object.keys(def.shape);
+        for (const k of keys) {
+            if (!(def.shape[k] instanceof $ZodType)) {
+                throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
+            }
+        }
+        const okeys = optionalKeys(def.shape);
+        return {
+            shape: def.shape,
+            keys,
+            keySet: new Set(keys),
+            numKeys: keys.length,
+            optionalKeys: new Set(okeys),
+        };
     });
-});
-const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
-    def.pattern ?? (def.pattern = ipv6);
-    $ZodStringFormat.init(inst, def);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.format = `ipv6`;
+    defineLazy(inst._zod, "propValues", () => {
+        const shape = def.shape;
+        const propValues = {};
+        for (const key in shape) {
+            const field = shape[key]._zod;
+            if (field.values) {
+                propValues[key] ?? (propValues[key] = new Set());
+                for (const v of field.values)
+                    propValues[key].add(v);
+            }
+        }
+        return propValues;
     });
-    inst._zod.check = (payload) => {
-        try {
-            new URL(`http://[${payload.value}]`);
-            // return;
+    const generateFastpass = (shape) => {
+        const doc = new Doc(["shape", "payload", "ctx"]);
+        const { keys, optionalKeys } = _normalized.value;
+        const parseStr = (key) => {
+            const k = esc(key);
+            return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
+        };
+        doc.write(`const input = payload.value;`);
+        const ids = Object.create(null);
+        for (const key of keys) {
+            ids[key] = randomString(15);
+        }
+        // A: preserve key order {
+        doc.write(`const newResult = {}`);
+        for (const key of keys) {
+            if (optionalKeys.has(key)) {
+                const id = ids[key];
+                doc.write(`const ${id} = ${parseStr(key)};`);
+                const k = esc(key);
+                doc.write(`
+        if (${id}.issues.length) {
+          if (input[${k}] === undefined) {
+            if (${k} in input) {
+              newResult[${k}] = undefined;
+            }
+          } else {
+            payload.issues = payload.issues.concat(
+              ${id}.issues.map((iss) => ({
+                ...iss,
+                path: iss.path ? [${k}, ...iss.path] : [${k}],
+              }))
+            );
+          }
+        } else if (${id}.value === undefined) {
+          if (${k} in input) newResult[${k}] = undefined;
+        } else {
+          newResult[${k}] = ${id}.value;
+        }
+        `);
+            }
+            else {
+                const id = ids[key];
+                //  const id = ids[key];
+                doc.write(`const ${id} = ${parseStr(key)};`);
+                doc.write(`
+          if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
+            ...iss,
+            path: iss.path ? [${esc(key)}, ...iss.path] : [${esc(key)}]
+          })));`);
+                doc.write(`newResult[${esc(key)}] = ${id}.value`);
+            }
         }
-        catch {
+        doc.write(`payload.value = newResult;`);
+        doc.write(`return payload;`);
+        const fn = doc.compile();
+        return (payload, ctx) => fn(shape, payload, ctx);
+    };
+    let fastpass;
+    const isObject$1 = isObject;
+    const jit = !globalConfig.jitless;
+    const allowsEval$1 = allowsEval;
+    const fastEnabled = jit && allowsEval$1.value; // && !def.catchall;
+    const { catchall } = def;
+    let value;
+    inst._zod.parse = (payload, ctx) => {
+        value ?? (value = _normalized.value);
+        const input = payload.value;
+        if (!isObject$1(input)) {
             payload.issues.push({
-                code: "invalid_format",
-                format: "ipv6",
-                input: payload.value,
+                expected: "object",
+                code: "invalid_type",
+                input,
                 inst,
             });
+            return payload;
         }
-    };
-});
-const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
-    def.pattern ?? (def.pattern = cidrv4);
-    $ZodStringFormat.init(inst, def);
-});
-const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
-    def.pattern ?? (def.pattern = cidrv6); // not used for validation
-    $ZodStringFormat.init(inst, def);
-    inst._zod.check = (payload) => {
-        const [address, prefix] = payload.value.split("/");
-        try {
-            if (!prefix)
-                throw new Error();
-            const prefixNum = Number(prefix);
-            if (`${prefixNum}` !== prefix)
-                throw new Error();
-            if (prefixNum < 0 || prefixNum > 128)
-                throw new Error();
-            new URL(`http://[${address}]`);
+        const proms = [];
+        if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
+            // always synchronous
+            if (!fastpass)
+                fastpass = generateFastpass(def.shape);
+            payload = fastpass(payload, ctx);
+        }
+        else {
+            payload.value = {};
+            const shape = value.shape;
+            for (const key of value.keys) {
+                const el = shape[key];
+                // do not add omitted optional keys
+                // if (!(key in input)) {
+                //   if (optionalKeys.has(key)) continue;
+                //   payload.issues.push({
+                //     code: "invalid_type",
+                //     path: [key],
+                //     expected: "nonoptional",
+                //     note: `Missing required key: "${key}"`,
+                //     input,
+                //     inst,
+                //   });
+                // }
+                const r = el._zod.run({ value: input[key], issues: [] }, ctx);
+                const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
+                if (r instanceof Promise) {
+                    proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
+                }
+                else {
+                    if (isOptional) {
+                        handleOptionalObjectResult(r, payload, key, input);
+                    }
+                    else {
+                        handleObjectResult(r, payload, key);
+                    }
+                }
+            }
+        }
+        if (!catchall) {
+            // return payload;
+            return proms.length ? Promise.all(proms).then(() => payload) : payload;
+        }
+        const unrecognized = [];
+        // iterate over input keys
+        const keySet = value.keySet;
+        const _catchall = catchall._zod;
+        const t = _catchall.def.type;
+        for (const key of Object.keys(input)) {
+            if (keySet.has(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) => handleObjectResult(r, payload, key)));
+            }
+            else {
+                handleObjectResult(r, payload, key);
+            }
         }
-        catch {
+        if (unrecognized.length) {
             payload.issues.push({
-                code: "invalid_format",
-                format: "cidrv6",
-                input: payload.value,
+                code: "unrecognized_keys",
+                keys: unrecognized,
+                input,
                 inst,
             });
         }
-    };
-});
-//////////////////////////////   ZodIP   //////////////////////////////
-// export interface $ZodIPDef extends $ZodStringFormatDef<"ip"> {
-//   version?: "v4" | "v6";
-// }
-// export interface $ZodIPInternals extends $ZodStringFormatInternals<"ip"> {
-//   def: $ZodIPDef;
-// }
-// export interface $ZodIP extends $ZodType {
-//   _zod: $ZodIPInternals;
-// }
-
-//   if (def.version === "v4") def.pattern ??= regexes.ipv4;
-//   else if (def.version === "v6") def.pattern ??= regexes.ipv6;
-//   else def.pattern ??= regexes.ip;
-//   $ZodStringFormat.init(inst, def);
-// });
-//////////////////////////////   ZodBase64   //////////////////////////////
-function isValidBase64(data) {
-    if (data === "")
-        return true;
-    if (data.length % 4 !== 0)
-        return false;
-    try {
-        atob(data);
-        return true;
-    }
-    catch {
-        return false;
-    }
-}
-const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
-    def.pattern ?? (def.pattern = base64);
-    $ZodStringFormat.init(inst, def);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.contentEncoding = "base64";
-    });
-    inst._zod.check = (payload) => {
-        if (isValidBase64(payload.value))
-            return;
-        payload.issues.push({
-            code: "invalid_format",
-            format: "base64",
-            input: payload.value,
-            inst,
-        });
-    };
-});
-//////////////////////////////   ZodBase64   //////////////////////////////
-function isValidBase64URL(data) {
-    if (!base64url.test(data))
-        return false;
-    const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
-    const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
-    return isValidBase64(padded);
-}
-const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
-    def.pattern ?? (def.pattern = base64url);
-    $ZodStringFormat.init(inst, def);
-    inst._zod.onattach.push((inst) => {
-        inst._zod.bag.contentEncoding = "base64url";
-    });
-    inst._zod.check = (payload) => {
-        if (isValidBase64URL(payload.value))
-            return;
-        payload.issues.push({
-            code: "invalid_format",
-            format: "base64url",
-            input: payload.value,
-            inst,
-        });
-    };
-});
-const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
-    def.pattern ?? (def.pattern = e164);
-    $ZodStringFormat.init(inst, def);
-});
-//////////////////////////////   ZodJWT   //////////////////////////////
-function isValidJWT(token, algorithm = null) {
-    try {
-        const tokensParts = token.split(".");
-        if (tokensParts.length !== 3)
-            return false;
-        const [header] = tokensParts;
-        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 = /*@__PURE__*/ $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,
-        });
-    };
-});
-function handleArrayResult(result, final, index) {
-    if (result.issues.length) {
-        final.issues.push(...prefixIssues(index, result.issues));
-    }
-    final.value[index] = result.value;
-}
-const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
-    $ZodType.init(inst, def);
-    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 = Array(input.length);
-        const proms = [];
-        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 (proms.length) {
-            return Promise.all(proms).then(() => payload);
-        }
-        return payload; //handleArrayResultsAsync(parseResults, final);
+        if (!proms.length)
+            return payload;
+        return Promise.all(proms).then(() => {
+            return payload;
+        });
     };
 });
 function handleUnionResults(results, final, inst, ctx) {
@@ -1101,775 +692,108 @@ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
         });
     };
 });
-const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
-    $ZodType.init(inst, def);
-    inst._zod.parse = (payload, ctx) => {
-        const { value: input } = payload;
-        const left = def.left._zod.run({ value: input, issues: [] }, ctx);
-        const right = def.right._zod.run({ value: input, issues: [] }, ctx);
-        const async = left instanceof Promise || right instanceof Promise;
-        if (async) {
-            return Promise.all([left, right]).then(([left, right]) => {
-                return handleIntersectionResults(payload, left, right);
-            });
-        }
-        return handleIntersectionResults(payload, left, right);
-    };
-});
-function mergeValues(a, b) {
-    // const aType = parse.t(a);
-    // const bType = parse.t(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 };
-        for (const key of sharedKeys) {
-            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],
-                };
+const $ZodDiscriminatedUnion = 
+/*@__PURE__*/
+$constructor("$ZodDiscriminatedUnion", (inst, def) => {
+    $ZodUnion.init(inst, def);
+    const _super = inst._zod.parse;
+    defineLazy(inst._zod, "propValues", () => {
+        const propValues = {};
+        for (const option of def.options) {
+            const pv = option._zod.propValues;
+            if (!pv || Object.keys(pv).length === 0)
+                throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
+            for (const [k, v] of Object.entries(pv)) {
+                if (!propValues[k])
+                    propValues[k] = new Set();
+                for (const val of v) {
+                    propValues[k].add(val);
+                }
             }
-            newArray.push(sharedValue.data);
         }
-        return { valid: true, data: newArray };
-    }
-    return { valid: false, mergeErrorPath: [] };
-}
-function handleIntersectionResults(result, left, right) {
-    if (left.issues.length) {
-        result.issues.push(...left.issues);
-    }
-    if (right.issues.length) {
-        result.issues.push(...right.issues);
-    }
-    if (aborted(result))
-        return result;
-    const merged = mergeValues(left.value, right.value);
-    if (!merged.valid) {
-        throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
-    }
-    result.value = merged.data;
-    return result;
-}
-const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
-    $ZodType.init(inst, def);
-    inst._zod.parse = (payload, _ctx) => {
-        const _out = def.transform(payload.value, payload);
-        if (_ctx.async) {
-            const output = _out instanceof Promise ? _out : Promise.resolve(_out);
-            return output.then((output) => {
-                payload.value = output;
-                return payload;
-            });
-        }
-        if (_out instanceof Promise) {
-            throw new $ZodAsyncError();
-        }
-        payload.value = _out;
-        return payload;
-    };
-});
-const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
-    $ZodType.init(inst, def);
-    inst._zod.optin = "optional";
-    inst._zod.optout = "optional";
-    defineLazy(inst._zod, "values", () => {
-        return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
-    });
-    defineLazy(inst._zod, "pattern", () => {
-        const pattern = def.innerType._zod.pattern;
-        return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : undefined;
+        return propValues;
     });
-    inst._zod.parse = (payload, ctx) => {
-        if (payload.value === undefined) {
-            return payload;
+    const disc = cached(() => {
+        const opts = def.options;
+        const map = new Map();
+        for (const o of opts) {
+            const values = o._zod.propValues[def.discriminator];
+            for (const v of values) {
+                if (map.has(v)) {
+                    throw new Error(`Duplicate discriminator value "${String(v)}"`);
+                }
+                map.set(v, o);
+            }
         }
-        return def.innerType._zod.run(payload, ctx);
-    };
-});
-const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
-    $ZodType.init(inst, def);
-    defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
-    defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
-    defineLazy(inst._zod, "pattern", () => {
-        const pattern = def.innerType._zod.pattern;
-        return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : undefined;
-    });
-    defineLazy(inst._zod, "values", () => {
-        return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
+        return map;
     });
     inst._zod.parse = (payload, ctx) => {
-        if (payload.value === null)
-            return payload;
-        return def.innerType._zod.run(payload, ctx);
-    };
-});
-const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
-    $ZodType.init(inst, def);
-    // inst._zod.qin = "true";
-    inst._zod.optin = "optional";
-    defineLazy(inst._zod, "values", () => def.innerType._zod.values);
-    inst._zod.parse = (payload, ctx) => {
-        if (payload.value === undefined) {
-            payload.value = def.defaultValue;
-            /**
-             * $ZodDefault always returns the default value immediately.
-             * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe.   */
+        const input = payload.value;
+        if (!isObject(input)) {
+            payload.issues.push({
+                code: "invalid_type",
+                expected: "object",
+                input,
+                inst,
+            });
             return payload;
         }
-        const result = def.innerType._zod.run(payload, ctx);
-        if (result instanceof Promise) {
-            return result.then((result) => handleDefaultResult(result, def));
+        const opt = disc.value.get(input?.[def.discriminator]);
+        if (opt) {
+            return opt._zod.run(payload, ctx);
         }
-        return handleDefaultResult(result, def);
-    };
-});
-function handleDefaultResult(payload, def) {
-    if (payload.value === undefined) {
-        payload.value = def.defaultValue;
-    }
-    return payload;
-}
-const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
-    $ZodType.init(inst, def);
-    inst._zod.optin = "optional";
-    defineLazy(inst._zod, "values", () => def.innerType._zod.values);
-    inst._zod.parse = (payload, ctx) => {
-        if (payload.value === undefined) {
-            payload.value = def.defaultValue;
+        if (def.unionFallback) {
+            return _super(payload, ctx);
         }
-        return def.innerType._zod.run(payload, ctx);
-    };
-});
-const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
-    $ZodType.init(inst, def);
-    defineLazy(inst._zod, "values", () => {
-        const v = def.innerType._zod.values;
-        return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
-    });
-    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 === undefined) {
+        // no matching discriminator
         payload.issues.push({
-            code: "invalid_type",
-            expected: "nonoptional",
-            input: payload.value,
+            code: "invalid_union",
+            errors: [],
+            note: "No matching discriminator",
+            input,
+            path: [def.discriminator],
             inst,
         });
-    }
-    return payload;
-}
-const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
-    $ZodType.init(inst, def);
-    defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
-    defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
-    defineLazy(inst._zod, "values", () => def.innerType._zod.values);
-    inst._zod.parse = (payload, ctx) => {
-        const result = def.innerType._zod.run(payload, ctx);
-        if (result instanceof Promise) {
-            return result.then((result) => {
-                payload.value = result.value;
-                if (result.issues.length) {
-                    payload.value = def.catchValue({
-                        ...payload,
-                        error: {
-                            issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
-                        },
-                        input: payload.value,
-                    });
-                    payload.issues = [];
-                }
-                return payload;
-            });
-        }
-        payload.value = result.value;
-        if (result.issues.length) {
-            payload.value = def.catchValue({
-                ...payload,
-                error: {
-                    issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())),
-                },
-                input: payload.value,
-            });
-            payload.issues = [];
-        }
         return payload;
     };
 });
-const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
-    $ZodType.init(inst, def);
-    defineLazy(inst._zod, "values", () => def.in._zod.values);
-    defineLazy(inst._zod, "optin", () => def.in._zod.optin);
-    defineLazy(inst._zod, "optout", () => def.out._zod.optout);
-    inst._zod.parse = (payload, ctx) => {
-        const left = def.in._zod.run(payload, ctx);
-        if (left instanceof Promise) {
-            return left.then((left) => handlePipeResult(left, def, ctx));
-        }
-        return handlePipeResult(left, def, ctx);
-    };
-});
-function handlePipeResult(left, def, ctx) {
-    if (aborted(left)) {
-        return left;
-    }
-    return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
-}
-const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
+const $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
     $ZodType.init(inst, def);
-    defineLazy(inst._zod, "disc", () => def.innerType._zod.disc);
-    defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
-    defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
-    inst._zod.parse = (payload, ctx) => {
-        const result = def.innerType._zod.run(payload, ctx);
-        if (result instanceof Promise) {
-            return result.then(handleReadonlyResult);
-        }
-        return handleReadonlyResult(result);
-    };
-});
-function handleReadonlyResult(payload) {
-    payload.value = Object.freeze(payload.value);
-    return payload;
-}
-const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
-    $ZodCheck.init(inst, def);
-    $ZodType.init(inst, def);
-    inst._zod.parse = (payload, _) => {
-        return payload;
-    };
-    inst._zod.check = (payload) => {
+    inst._zod.values = new Set(def.values);
+    inst._zod.pattern = new RegExp(`^(${def.values
+        .map((o) => (typeof o === "string" ? escapeRegex(o) : o ? o.toString() : String(o)))
+        .join("|")})$`);
+    inst._zod.parse = (payload, _ctx) => {
         const input = payload.value;
-        const r = def.fn(input);
-        if (r instanceof Promise) {
-            return r.then((r) => handleRefineResult(r, payload, input, inst));
+        if (inst._zod.values.has(input)) {
+            return payload;
         }
-        handleRefineResult(r, payload, input, inst);
-        return;
+        payload.issues.push({
+            code: "invalid_value",
+            values: def.values,
+            input,
+            inst,
+        });
+        return payload;
     };
 });
-function handleRefineResult(result, payload, input, inst) {
-    if (!result) {
-        const _iss = {
-            code: "custom",
-            input,
-            inst, // incorporates params.error into issue reporting
-            path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
-            continue: !inst._zod.def.abort,
-            // params: inst._zod.def.params,
-        };
-        if (inst._zod.def.params)
-            _iss.params = inst._zod.def.params;
-        payload.issues.push(issue(_iss));
-    }
-}
-
-class $ZodRegistry {
-    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) {
-            if (this._idmap.has(meta.id)) {
-                throw new Error(`ID ${meta.id} already exists in the registry`);
-            }
-            this._idmap.set(meta.id, schema);
-        }
-        return this;
-    }
-    remove(schema) {
-        this._map.delete(schema);
-        return this;
-    }
-    get(schema) {
-        // return this._map.get(schema) as any;
-        // inherit metadata
-        const p = schema._zod.parent;
-        if (p) {
-            const pm = { ...(this.get(p) ?? {}) };
-            delete pm.id; // do not inherit id
-            return { ...pm, ...this._map.get(schema) };
-        }
-        return this._map.get(schema);
-    }
-    has(schema) {
-        return this._map.has(schema);
-    }
-}
-// registries
-function registry() {
-    return new $ZodRegistry();
-}
-const globalRegistry = /*@__PURE__*/ registry();
 
 function _string(Class, params) {
     return new Class({
         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 _maxLength(maximum, params) {
-    const ch = new $ZodCheckMaxLength({
-        check: "max_length",
-        ...normalizeParams(params),
-        maximum,
-    });
-    return ch;
-}
-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,
+        ...normalizeParams(),
     });
 }
-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,
-    });
-}
-// normalize
-function _normalize(form) {
-    return _overwrite((input) => input.normalize(form));
-}
-// trim
-function _trim() {
-    return _overwrite((input) => input.trim());
-}
-// toLowerCase
-function _toLowerCase() {
-    return _overwrite((input) => input.toLowerCase());
-}
-// toUpperCase
-function _toUpperCase() {
-    return _overwrite((input) => input.toUpperCase());
-}
-function _array(Class, element, params) {
-    return new Class({
-        type: "array",
-        element,
-        // get element() {
-        //   return element;
-        // },
-        ...normalizeParams(params),
-    });
-}
-function _custom(Class, fn, _params) {
-    const schema = new Class({
-        type: "custom",
-        check: "custom",
-        fn: fn,
-        ...normalizeParams(_params),
-    });
-    return schema;
-}
-
-const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
-    $ZodISODateTime.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-function datetime(params) {
-    return _isoDateTime(ZodISODateTime, params);
-}
-const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
-    $ZodISODate.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-function date(params) {
-    return _isoDate(ZodISODate, params);
-}
-const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
-    $ZodISOTime.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-function time(params) {
-    return _isoTime(ZodISOTime, params);
-}
-const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
-    $ZodISODuration.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-function duration(params) {
-    return _isoDuration(ZodISODuration, params);
-}
 
-const initializer = (inst, issues) => {
-    $ZodError.init(inst, issues);
-    Object.defineProperties(inst, {
-        format: {
-            value: (mapper) => formatError(inst, mapper),
-            // enumerable: false,
-        },
-        flatten: {
-            value: (mapper) => flattenError(inst, mapper),
-            // enumerable: false,
-        },
-        addIssue: {
-            value: (issue) => inst.issues.push(issue),
-            // enumerable: false,
-        },
-        addIssues: {
-            value: (issues) => inst.issues.push(...issues),
-            // enumerable: false,
-        },
-        isEmpty: {
-            get() {
-                return inst.issues.length === 0;
-            },
-            // enumerable: false,
-        },
-    });
-    // Object.defineProperty(inst, "isEmpty", {
-    //   get() {
-    //     return inst.issues.length === 0;
-    //   },
-    // });
-};
-const ZodError = $constructor("ZodError", initializer);
-const ZodRealError = $constructor("ZodError", initializer, {
-    Parent: Error,
-});
-// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
-// export type ErrorMapCtx = core.$ZodErrorMapCtx;
-
-const parse = /* @__PURE__ */ _parse(ZodRealError);
-const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
-const safeParse = /* @__PURE__ */ _safeParse(ZodError);
-const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodError);
-
-const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
+const ZodMiniType = /*@__PURE__*/ $constructor("ZodMiniType", (inst, def) => {
+    if (!inst._zod)
+        throw new Error("Uninitialized schema in mixin ZodMiniType.");
     $ZodType.init(inst, def);
     inst.def = def;
-    inst._def = def;
-    // base methods
+    inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
+    inst.safeParse = (data, params) => safeParse(inst, data, params);
+    inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
+    inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
     inst.check = (...checks) => {
         return inst.clone({
             ...def,
@@ -1881,455 +805,63 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
         // { parent: true }
         );
     };
-    inst.clone = (def, params) => clone(inst, def, params);
+    inst.clone = (_def, params) => clone(inst, _def, params);
     inst.brand = () => inst;
     inst.register = ((reg, meta) => {
         reg.add(inst, meta);
         return inst;
     });
-    //  const parse: <T extends core.$ZodType>(
-    //   schema: T,
-    //   value: unknown,
-    //   _ctx?: core.ParseContext<core.$ZodIssue>
-    
-    //  const safeParse: <T extends core.$ZodType>(
-    //   schema: T,
-    //   value: unknown,
-    //   _ctx?: core.ParseContext<core.$ZodIssue>
-    
-    //  const parseAsync: <T extends core.$ZodType>(
-    //   schema: T,
-    //   value: unknown,
-    //   _ctx?: core.ParseContext<core.$ZodIssue>
-    
-    //  const safeParseAsync: <T extends core.$ZodType>(
-    //   schema: T,
-    //   value: unknown,
-    //   _ctx?: core.ParseContext<core.$ZodIssue>
-    
-    // parsing
-    inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
-    inst.safeParse = (data, params) => safeParse(inst, data, params);
-    inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
-    inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
-    inst.spa = inst.safeParseAsync;
-    // refinements
-    inst.refine = (check, params) => inst.check(refine(check, params));
-    inst.superRefine = (refinement) => inst.check(superRefine(refinement));
-    inst.overwrite = (fn) => inst.check(_overwrite(fn));
-    // wrappers
-    inst.optional = () => optional(inst);
-    inst.nullable = () => nullable(inst);
-    inst.nullish = () => optional(nullable(inst));
-    inst.nonoptional = (params) => nonoptional(inst, params);
-    inst.array = () => array(inst);
-    inst.or = (arg) => union([inst, arg]);
-    inst.and = (arg) => intersection(inst, arg);
-    inst.transform = (tx) => pipe(inst, transform(tx));
-    inst.default = (def) => _default(inst, def);
-    inst.prefault = (def) => prefault(inst, def);
-    // inst.coalesce = (def, params) => coalesce(inst, def, params);
-    inst.catch = (params) => _catch(inst, params);
-    inst.pipe = (target) => pipe(inst, target);
-    inst.readonly = () => readonly(inst);
-    // meta
-    inst.describe = (description) => {
-        const cl = inst.clone();
-        globalRegistry.add(cl, { description });
-        return cl;
-    };
-    Object.defineProperty(inst, "description", {
-        get() {
-            return globalRegistry.get(inst)?.description;
-        },
-        configurable: true,
-    });
-    inst.meta = (...args) => {
-        if (args.length === 0) {
-            return globalRegistry.get(inst);
-        }
-        const cl = inst.clone();
-        globalRegistry.add(cl, args[0]);
-        return cl;
-    };
-    // helpers
-    inst.isOptional = () => inst.safeParse(undefined).success;
-    inst.isNullable = () => inst.safeParse(null).success;
-    return inst;
 });
-/** @internal */
-const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
+const ZodMiniString = /*@__PURE__*/ $constructor("ZodMiniString", (inst, def) => {
     $ZodString.init(inst, def);
-    ZodType.init(inst, def);
-    const bag = inst._zod.bag;
-    inst.format = bag.format ?? null;
-    inst.minLength = bag.minimum ?? null;
-    inst.maxLength = bag.maximum ?? null;
-    // validations
-    inst.regex = (...args) => inst.check(_regex(...args));
-    inst.includes = (...args) => inst.check(_includes(...args));
-    inst.startsWith = (params) => inst.check(_startsWith(params));
-    inst.endsWith = (params) => inst.check(_endsWith(params));
-    inst.min = (...args) => inst.check(_minLength(...args));
-    inst.max = (...args) => inst.check(_maxLength(...args));
-    inst.length = (...args) => inst.check(_length(...args));
-    inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
-    inst.lowercase = (params) => inst.check(_lowercase(params));
-    inst.uppercase = (params) => inst.check(_uppercase(params));
-    // transforms
-    inst.trim = () => inst.check(_trim());
-    inst.normalize = (...args) => inst.check(_normalize(...args));
-    inst.toLowerCase = () => inst.check(_toLowerCase());
-    inst.toUpperCase = () => inst.check(_toUpperCase());
-});
-const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
-    $ZodString.init(inst, def);
-    _ZodString.init(inst, def);
-    inst.email = (params) => inst.check(_email(ZodEmail, params));
-    inst.url = (params) => inst.check(_url(ZodURL, params));
-    inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
-    inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
-    inst.guid = (params) => inst.check(_guid(ZodGUID, params));
-    inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
-    inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
-    inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
-    inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
-    inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
-    inst.guid = (params) => inst.check(_guid(ZodGUID, params));
-    inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
-    inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
-    inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
-    inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
-    inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
-    inst.xid = (params) => inst.check(_xid(ZodXID, params));
-    inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
-    inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
-    inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
-    inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
-    inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
-    inst.e164 = (params) => inst.check(_e164(ZodE164, params));
-    // iso
-    inst.datetime = (params) => inst.check(datetime(params));
-    inst.date = (params) => inst.check(date(params));
-    inst.time = (params) => inst.check(time(params));
-    inst.duration = (params) => inst.check(duration(params));
+    ZodMiniType.init(inst, def);
 });
 function string(params) {
-    return _string(ZodString, params);
-}
-const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
-    $ZodStringFormat.init(inst, def);
-    _ZodString.init(inst, def);
-});
-const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodEmail.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodGUID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodUUID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodURL.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodEmoji.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodNanoID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodCUID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodCUID2.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodULID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodXID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodKSUID.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodIPv4.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodIPv6.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
-    $ZodCIDRv4.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
-    $ZodCIDRv6.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodBase64.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodBase64URL.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodE164.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
-    // ZodStringFormat.init(inst, def);
-    $ZodJWT.init(inst, def);
-    ZodStringFormat.init(inst, def);
-});
-const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
-    $ZodArray.init(inst, def);
-    ZodType.init(inst, def);
-    inst.element = def.element;
-    inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
-    inst.nonempty = (params) => inst.check(_minLength(1, params));
-    inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
-    inst.length = (len, params) => inst.check(_length(len, params));
-});
-function array(element, params) {
-    return _array(ZodArray, element, params);
+    return _string(ZodMiniString);
+}
+const ZodMiniObject = /*@__PURE__*/ $constructor("ZodMiniObject", (inst, def) => {
+    $ZodObject.init(inst, def);
+    ZodMiniType.init(inst, def);
+});
+function object(shape, params) {
+    const def = {
+        type: "object",
+        get shape() {
+            assignProp(this, "shape", { ...shape });
+            return this.shape;
+        },
+        ...normalizeParams(),
+    };
+    return new ZodMiniObject(def);
 }
-const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
-    $ZodUnion.init(inst, def);
-    ZodType.init(inst, def);
-    inst.options = def.options;
+const ZodMiniDiscriminatedUnion = /*@__PURE__*/ $constructor("ZodMiniDiscriminatedUnion", (inst, def) => {
+    $ZodDiscriminatedUnion.init(inst, def);
+    ZodMiniType.init(inst, def);
 });
-function union(options, params) {
-    return new ZodUnion({
+function discriminatedUnion(discriminator, options, params) {
+    return new ZodMiniDiscriminatedUnion({
         type: "union",
         options,
-        ...normalizeParams(params),
+        discriminator,
+        ...normalizeParams(),
     });
 }
-const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
-    $ZodIntersection.init(inst, def);
-    ZodType.init(inst, def);
+const ZodMiniLiteral = /*@__PURE__*/ $constructor("ZodMiniLiteral", (inst, def) => {
+    $ZodLiteral.init(inst, def);
+    ZodMiniType.init(inst, def);
 });
-function intersection(left, right) {
-    return new ZodIntersection({
-        type: "intersection",
-        left,
-        right,
-    });
-}
-const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
-    $ZodTransform.init(inst, def);
-    ZodType.init(inst, def);
-    inst._zod.parse = (payload, _ctx) => {
-        payload.addIssue = (issue$1) => {
-            if (typeof issue$1 === "string") {
-                payload.issues.push(issue(issue$1, payload.value, def));
-            }
-            else {
-                // for Zod 3 backwards compatibility
-                const _issue = issue$1;
-                if (_issue.fatal)
-                    _issue.continue = false;
-                _issue.code ?? (_issue.code = "custom");
-                _issue.input ?? (_issue.input = payload.value);
-                _issue.inst ?? (_issue.inst = inst);
-                _issue.continue ?? (_issue.continue = true);
-                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 = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
-    $ZodOptional.init(inst, def);
-    ZodType.init(inst, def);
-    inst.unwrap = () => inst._zod.def.innerType;
-});
-function optional(innerType) {
-    return new ZodOptional({
-        type: "optional",
-        innerType,
-    });
-}
-const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
-    $ZodNullable.init(inst, def);
-    ZodType.init(inst, def);
-    inst.unwrap = () => inst._zod.def.innerType;
-});
-function nullable(innerType) {
-    return new ZodNullable({
-        type: "nullable",
-        innerType,
-    });
-}
-const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
-    $ZodDefault.init(inst, def);
-    ZodType.init(inst, def);
-    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() : defaultValue;
-        },
+function literal(value, params) {
+    return new ZodMiniLiteral({
+        type: "literal",
+        values: Array.isArray(value) ? value : [value],
+        ...normalizeParams(),
     });
 }
-const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
-    $ZodPrefault.init(inst, def);
-    ZodType.init(inst, def);
-    inst.unwrap = () => inst._zod.def.innerType;
-});
-function prefault(innerType, defaultValue) {
-    return new ZodPrefault({
-        type: "prefault",
-        innerType,
-        get defaultValue() {
-            return typeof defaultValue === "function" ? defaultValue() : defaultValue;
-        },
-    });
-}
-const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
-    $ZodNonOptional.init(inst, def);
-    ZodType.init(inst, def);
-    inst.unwrap = () => inst._zod.def.innerType;
-});
-function nonoptional(innerType, params) {
-    return new ZodNonOptional({
-        type: "nonoptional",
-        innerType,
-        ...normalizeParams(params),
-    });
-}
-const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
-    $ZodCatch.init(inst, def);
-    ZodType.init(inst, def);
-    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 : () => catchValue),
-    });
-}
-const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
-    $ZodPipe.init(inst, def);
-    ZodType.init(inst, def);
-    inst.in = def.in;
-    inst.out = def.out;
-});
-function pipe(in_, out) {
-    return new ZodPipe({
-        type: "pipe",
-        in: in_,
-        out,
-        // ...util.normalizeParams(params),
-    });
-}
-const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
-    $ZodReadonly.init(inst, def);
-    ZodType.init(inst, def);
-});
-function readonly(innerType) {
-    return new ZodReadonly({
-        type: "readonly",
-        innerType,
-    });
-}
-const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
-    $ZodCustom.init(inst, def);
-    ZodType.init(inst, def);
-});
-// custom checks
-function check(fn, params) {
-    const ch = new $ZodCheck({
-        check: "custom",
-        ...normalizeParams(params),
-    });
-    ch._zod.check = fn;
-    return ch;
-}
-function refine(fn, _params = {}) {
-    return _custom(ZodCustom, fn, _params);
-}
-// superRefine
-function superRefine(fn, params) {
-    const ch = check((payload) => {
-        payload.addIssue = (issue$1) => {
-            if (typeof issue$1 === "string") {
-                payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
-            }
-            else {
-                // for Zod 3 backwards compatibility
-                const _issue = issue$1;
-                if (_issue.fatal)
-                    _issue.continue = false;
-                _issue.code ?? (_issue.code = "custom");
-                _issue.input ?? (_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;
-}
 
-// z.string().check(
-//   z.minLength(5), 
-//   z.maxLength(10),
-//   z.refine(val => val.includes("@")),
-//   z.trim()
-// );
-string().min(5).max(10).refine(function (val) { return val.includes("@"); }).trim().parse("asd@adsf");
+var PlaySchema = discriminatedUnion("type", [
+    object({ type: literal("play"), id: string() }),
+    object({ type: literal("play2"), name: string() }),
+]);
+PlaySchema.parse({ type: "play", id: "123" }); // valid
+
+export { PlaySchema };
diff --git a/packages/treeshake/package.json b/packages/treeshake/package.json
index 8b442dc5..f6be0db0 100644
--- a/packages/treeshake/package.json
+++ b/packages/treeshake/package.json
@@ -4,7 +4,8 @@
   "type": "module",
   "license": "MIT",
   "scripts": {
-    "bundle:rollup": "rollup -c",
+    "bundle": "rollup -c rollup.config.js --input",
+    "bundle:rollup": "rollup --input",
     "bundle:esbuild": "esbuild --bundle ./in.ts --outfile=./out.js --bundle --format=esm"
   },
   "devDependencies": {
@@ -18,6 +19,7 @@
     "rollup-plugin-filesize": "^10.0.0",
     "rollup-plugin-bundle-size": "^1.0.3",
     "valibot": "^1.0.0",
-    "zod3": "npm:zod@^3.24.0"
+    "zod3": "npm:zod@^3.24.0",
+    "zod4": "npm:zod@^3.25.0"
   }
 }
diff --git a/packages/zod/src/v4/classic/schemas.ts b/packages/zod/src/v4/classic/schemas.ts
index 19a0452d..979a72b9 100644
--- a/packages/zod/src/v4/classic/schemas.ts
+++ b/packages/zod/src/v4/classic/schemas.ts
@@ -1238,15 +1238,9 @@ export const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion> = /
   }
 );
 
-export interface $ZodTypeDiscriminableInternals extends core.$ZodTypeInternals {
-  disc: util.DiscriminatorMap;
-}
-
-export interface $ZodTypeDiscriminable extends ZodType {
-  _zod: $ZodTypeDiscriminableInternals;
-}
-
-export function discriminatedUnion<Types extends readonly [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(
+export function discriminatedUnion<
+  Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]],
+>(
   discriminator: string,
   options: Types,
   params?: string | core.$ZodDiscriminatedUnionParams
diff --git a/packages/zod/src/v4/core/api.ts b/packages/zod/src/v4/core/api.ts
index f6787333..6f1da375 100644
--- a/packages/zod/src/v4/core/api.ts
+++ b/packages/zod/src/v4/core/api.ts
@@ -1071,7 +1071,7 @@ export function _union<const T extends readonly schemas.$ZodObject[]>(
 
 // ZodDiscriminatedUnion
 export interface $ZodTypeDiscriminableInternals extends schemas.$ZodTypeInternals {
-  disc: util.DiscriminatorMap;
+  propValues: util.PropValues;
 }
 
 export interface $ZodTypeDiscriminable extends schemas.$ZodType {
diff --git a/packages/zod/src/v4/core/schemas.ts b/packages/zod/src/v4/core/schemas.ts
index 0f4172d7..6f499bd0 100644
--- a/packages/zod/src/v4/core/schemas.ts
+++ b/packages/zod/src/v4/core/schemas.ts
@@ -1,3 +1,4 @@
+import type { $ZodTypeDiscriminable } from "./api.js";
 import * as checks from "./checks.js";
 import * as core from "./core.js";
 import { Doc } from "./doc.js";
@@ -116,16 +117,16 @@ export interface $ZodTypeInternals<out O = unknown, out I = unknown> {
   optin?: "optional" | undefined;
   optout?: "optional" | undefined;
 
-  /** @internal A set of literal discriminators used for the fast path in discriminated unions. */
-  disc: util.DiscriminatorMap | undefined;
-
   /** @internal The set of literal values that will pass validation. Must be an exhaustive set. Used to determine optionality in z.record().
    *
    * Defined on: enum, const, literal, null, undefined
    * Passthrough: optional, nullable, branded, default, catch, pipe
    * Todo: unions?
    */
-  values: util.PrimitiveSet | undefined;
+  values?: util.PrimitiveSet | undefined;
+
+  /** @internal A set of literal discriminators used for the fast path in discriminated unions. */
+  propValues?: util.PropValues | undefined;
 
   /** @internal This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */
   pattern: RegExp | undefined;
@@ -1528,7 +1529,7 @@ export interface $ZodObjectInternals<
   def: $ZodObjectDef<Shape>;
   config: Config;
   isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
-  disc: util.DiscriminatorMap;
+  propValues: util.PropValues;
   // special keys only used for objects
   // not defined on $ZodTypeInternals (base interface) because it breaks cyclical inference
   // the z.infer<> util checks for these first when extracting inferred type
@@ -1642,25 +1643,17 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
     };
   });
 
-  util.defineLazy(inst._zod, "disc", () => {
+  util.defineLazy(inst._zod, "propValues", () => {
     const shape = def.shape;
-    const discMap: util.DiscriminatorMap = new Map();
-    let hasDisc = false;
+    const propValues: util.PropValues = {};
     for (const key in shape) {
       const field = shape[key]._zod;
-      if (field.values || field.disc) {
-        hasDisc = true;
-        const o: util.DiscriminatorMapElement = {
-          values: new Set(field.values ?? []),
-          maps: field.disc ? [field.disc] : [],
-        };
-        discMap.set(key, o);
+      if (field.values) {
+        propValues[key] ??= new Set();
+        for (const v of field.values) propValues[key].add(v);
       }
     }
-    if (!hasDisc) {
-      return undefined as any;
-    }
-    return discMap;
+    return propValues;
   });
 
   const generateFastpass = (shape: any) => {
@@ -1940,75 +1933,46 @@ export interface $ZodDiscriminatedUnionDef<Options extends readonly $ZodType[] =
 export interface $ZodDiscriminatedUnionInternals<Options extends readonly $ZodType[] = readonly $ZodType[]>
   extends $ZodUnionInternals<Options> {
   def: $ZodDiscriminatedUnionDef<Options>;
-  disc: util.DiscriminatorMap;
+  propValues: util.PropValues;
 }
 
 export interface $ZodDiscriminatedUnion<T extends readonly $ZodType[] = readonly $ZodType[]> extends $ZodType {
   _zod: $ZodDiscriminatedUnionInternals<T>;
 }
 
-function matchDiscriminatorAtKey(input: any, key: PropertyKey, disc: util.DiscriminatorMapElement): boolean {
-  let matched = true;
-  const data = input?.[key];
-
-  if (disc.values.size && !disc.values.has(data)) {
-    matched = false;
-  }
-  if (disc.maps.length > 0) {
-    for (const m of disc.maps) {
-      if (!matchDiscriminators(data, m)) {
-        matched = false;
-      }
-    }
-  }
-
-  return matched;
-}
-
-function matchDiscriminators(input: any, discs: util.DiscriminatorMap): boolean {
-  let matched = true;
-  for (const [key, value] of discs) {
-    if (!matchDiscriminatorAtKey(input, key, value)) {
-      matched = false;
-    }
-  }
-
-  return matched;
-}
-
 export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
   /*@__PURE__*/
   core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
     $ZodUnion.init(inst, def);
 
     const _super = inst._zod.parse;
-    util.defineLazy(inst._zod, "disc", () => {
-      const _disc: util.DiscriminatorMap = new Map();
-      for (const el of def.options) {
-        const subdisc = el._zod.disc;
-        if (!subdisc) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(el)}"`);
-        for (const [key, o] of subdisc) {
-          if (!_disc.has(key))
-            _disc.set(key, {
-              values: new Set(),
-              maps: [],
-            });
-          const _o = _disc.get(key)!;
-          for (const v of o.values) {
-            _o.values.add(v);
+    util.defineLazy(inst._zod, "propValues", () => {
+      const propValues: util.PropValues = {};
+      for (const option of def.options) {
+        const pv = option._zod.propValues;
+        if (!pv || Object.keys(pv).length === 0)
+          throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
+        for (const [k, v] of Object.entries(pv!)) {
+          if (!propValues[k]) propValues[k] = new Set();
+          for (const val of v) {
+            propValues[k].add(val);
           }
-          for (const m of o.maps) _o.maps.push(m);
         }
       }
-      return _disc;
+      return propValues;
     });
 
-    const _discmap = util.cached(() => {
-      const map: Map<$ZodType, util.DiscriminatorMapElement> = new Map();
-      for (const o of def.options) {
-        const discEl = o._zod.disc?.get(def.discriminator);
-        if (!discEl) throw new Error("Invalid discriminated union option");
-        map.set(o, discEl);
+    const disc = util.cached(() => {
+      const opts = def.options as $ZodTypeDiscriminable[];
+      const map: Map<util.Primitive, $ZodType> = new Map();
+      for (const o of opts) {
+        const values = o._zod.propValues[def.discriminator];
+        for (const v of values) {
+          if (map.has(v)) {
+            throw new Error(`Duplicate discriminator value "${String(v)}"`);
+          }
+          map.set(v, o);
+        }
       }
       return map;
     });
@@ -2025,16 +1989,11 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
         return payload;
       }
 
-      const filtered: $ZodType[] = [];
-      const discmap = _discmap.value;
-      for (const option of def.options) {
-        const subdisc = discmap.get(option)!;
-        if (matchDiscriminatorAtKey(input, def.discriminator, subdisc)) {
-          filtered.push(option);
-        }
+      const opt = disc.value.get(input?.[def.discriminator] as any);
+      if (opt) {
+        return opt._zod.run(payload, ctx) as any;
       }
 
-      if (filtered.length === 1) return filtered[0]._zod.run(payload, ctx) as any;
       if (def.unionFallback) {
         return _super(payload, ctx);
       }
@@ -3407,7 +3366,7 @@ export interface $ZodReadonlyInternals<T extends $ZodType = $ZodType>
   optin: T["_zod"]["optin"];
   optout: T["_zod"]["optout"];
   isst: never;
-  disc: T["_zod"]["disc"];
+  propValues: T["_zod"]["propValues"];
 }
 
 export interface $ZodReadonly<T extends $ZodType = $ZodType> extends $ZodType {
@@ -3418,7 +3377,7 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
   "$ZodReadonly",
   (inst, def) => {
     $ZodType.init(inst, def);
-    util.defineLazy(inst._zod, "disc", () => def.innerType._zod.disc);
+    util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
     util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
     util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
 
@@ -3592,7 +3551,7 @@ export interface $ZodLazyInternals<T extends $ZodType = $ZodType>
   /** Auto-cached way to retrieve the inner schema */
   innerType: T;
   pattern: T["_zod"]["pattern"];
-  disc: T["_zod"]["disc"];
+  propValues: T["_zod"]["propValues"];
   optin: T["_zod"]["optin"];
   optout: T["_zod"]["optout"];
 }
@@ -3606,7 +3565,7 @@ export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constru
 
   util.defineLazy(inst._zod, "innerType", () => def.getter());
   util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
-  util.defineLazy(inst._zod, "disc", () => inst._zod.innerType._zod.disc);
+  util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
   util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
   util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
   inst._zod.parse = (payload, ctx) => {
diff --git a/packages/zod/src/v4/core/util.ts b/packages/zod/src/v4/core/util.ts
index 9431471e..f3c5e975 100644
--- a/packages/zod/src/v4/core/util.ts
+++ b/packages/zod/src/v4/core/util.ts
@@ -177,12 +177,13 @@ export type SafeParseError<T> = {
   error: errors.$ZodError<T>;
 };
 
-export type DiscriminatorMapElement = {
-  values: Set<Primitive>;
-  maps: DiscriminatorMap[];
-};
-export type DiscriminatorMap = Map<PropertyKey, DiscriminatorMapElement>;
+// export type DiscriminatorMapElement = {
+//   values: Set<Primitive>;
+//   maps: DiscriminatorMap[];
+// };
+export type PropValues = Record<string, Set<Primitive>>;
 export type PrimitiveSet = Set<Primitive>;
+export type DiscriminatorMap = Map<Primitive, schemas.$ZodType>;
 
 // functions
 export function assertEqual<A, B>(val: AssertEqual<A, B>): AssertEqual<A, B> {
diff --git a/packages/zod/src/v4/mini/schemas.ts b/packages/zod/src/v4/mini/schemas.ts
index 71f439f9..d48c7b35 100644
--- a/packages/zod/src/v4/mini/schemas.ts
+++ b/packages/zod/src/v4/mini/schemas.ts
@@ -878,15 +878,9 @@ export const ZodMiniDiscriminatedUnion: core.$constructor<ZodMiniDiscriminatedUn
   }
 );
 
-export interface $ZodTypeDiscriminableInternals extends core.$ZodTypeInternals {
-  disc: util.DiscriminatorMap;
-}
-
-export interface $ZodTypeDiscriminable extends ZodMiniType {
-  _zod: $ZodTypeDiscriminableInternals;
-}
-
-export function discriminatedUnion<Types extends readonly [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(
+export function discriminatedUnion<
+  Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]],
+>(
   discriminator: string,
   options: Types,
   params?: string | core.$ZodDiscriminatedUnionParams
diff --git a/play.ts b/play.ts
index 23bdd10a..5d3cc193 100644
--- a/play.ts
+++ b/play.ts
@@ -1,21 +1,3 @@
 import { z } from "zod/v3";
 
-// import * as z from "zod";
-
-const parseResult = z
-  .string()
-  .refine((x) => false) // force anything/everything to fail
-  .transform((x) => {
-    console.log("I don't get called"); // correct
-    return x.length;
-  })
-  .refine((x) => {
-    console.log("I shouldn't get called!!!!!!");
-    console.log(typeof x); // number
-    console.log(x);
-  })
-  .safeParse("123");
-
-console.log(`succeeded:  ${parseResult.success}`); // false (correct behavior)
-
-// z.string().min(1234, { abort: true });
+z;
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 50199364..93175e68 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -108,14 +108,14 @@ importers:
         specifier: npm:zod@^3.23.7
         version: zod@3.24.2
       zodnext:
-        specifier: npm:zod@next
-        version: zod@3.25.0-beta.20250518T204520
+        specifier: npm:zod@^3.25.0
+        version: zod@3.25.34
 
   packages/docs:
     dependencies:
       '@inkeep/cxkit-react':
         specifier: ^0.5.80
-        version: 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)
+        version: 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)
       '@radix-ui/react-accordion':
         specifier: ^1.2.4
         version: 1.2.4(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)
@@ -210,6 +210,9 @@ importers:
       zod3:
         specifier: npm:zod@^3.24.0
         version: zod@3.24.2
+      zod4:
+        specifier: npm:zod@^3.25.0
+        version: zod@3.25.34
 
   packages/tsc:
     devDependencies:
@@ -5751,8 +5754,8 @@ packages:
   zod@3.24.3:
     resolution: {integrity: sha512-HhY1oqzWCQWuUqvBFnsyrtZRhyPeR7SUGv+C4+MsisMuVfSPx8HpwWqH8tRahSlt6M3PiFAcoeFhZAqIXTxoSg==}
 
-  zod@3.25.0-beta.20250518T204520:
-    resolution: {integrity: sha512-R1E2HPJQ/VbG/P3Resy9+Oqgal1NNeAJMRmwqmlV/NlrpFjbk0hUKD9PAiZ9Pp5F/dQyCJmozNNSJZDDoikhxQ==}
+  zod@3.25.34:
+    resolution: {integrity: sha512-lZHvSc2PpWdcfpHlyB33HA9nqP16GpC9IpiG4lYq9jZCJVLZNnWd6Y1cj79bcLSBKTkxepfpjckPv5Y5VOPlwA==}
 
   zod@4.0.0-beta.20250420T053007:
     resolution: {integrity: sha512-5pp8Q0PNDaNcUptGiBE9akyioJh3RJpagIxrLtAVMR9IxwcSZiOsJD/1/98CyhItdTlI2H91MfhhLzRlU+fifA==}
@@ -6228,7 +6231,7 @@ snapshots:
 
   '@inkeep/cxkit-color-mode@0.5.80': {}
 
-  '@inkeep/cxkit-primitives@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)':
+  '@inkeep/cxkit-primitives@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)':
     dependencies:
       '@inkeep/cxkit-color-mode': 0.5.80
       '@inkeep/cxkit-theme': 0.5.80
@@ -6262,7 +6265,7 @@ snapshots:
       lucide-react: 0.503.0(react@19.0.0)
       marked: 15.0.12
       merge-anything: 5.1.7
-      openai: 4.78.1(encoding@0.1.13)(zod@packages+zod)
+      openai: 4.78.1(encoding@0.1.13)(zod@3.25.34)
       prism-react-renderer: 2.4.1(react@19.0.0)
       react: 19.0.0
       react-dom: 19.0.0(react@19.0.0)
@@ -6283,9 +6286,9 @@ snapshots:
       - supports-color
       - zod
 
-  '@inkeep/cxkit-react@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)':
+  '@inkeep/cxkit-react@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)':
     dependencies:
-      '@inkeep/cxkit-styled': 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)
+      '@inkeep/cxkit-styled': 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)
       '@radix-ui/react-use-controllable-state': 1.1.0(@types/react@19.0.11)(react@19.0.0)
       lucide-react: 0.503.0(react@19.0.0)
     transitivePeerDependencies:
@@ -6297,9 +6300,9 @@ snapshots:
       - supports-color
       - zod
 
-  '@inkeep/cxkit-styled@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)':
+  '@inkeep/cxkit-styled@0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)':
     dependencies:
-      '@inkeep/cxkit-primitives': 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@packages+zod)
+      '@inkeep/cxkit-primitives': 0.5.80(@types/react-dom@19.0.4(@types/react@19.0.11))(@types/react@19.0.11)(encoding@0.1.13)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(zod@3.25.34)
       class-variance-authority: 0.7.1
       clsx: 2.1.1
       merge-anything: 5.1.7
@@ -10291,7 +10294,7 @@ snapshots:
       regex: 6.0.1
       regex-recursion: 6.0.2
 
-  openai@4.78.1(encoding@0.1.13)(zod@packages+zod):
+  openai@4.78.1(encoding@0.1.13)(zod@3.25.34):
     dependencies:
       '@types/node': 18.19.103
       '@types/node-fetch': 2.6.12
@@ -10301,7 +10304,7 @@ snapshots:
       formdata-node: 4.4.1
       node-fetch: 2.7.0(encoding@0.1.13)
     optionalDependencies:
-      zod: link:packages/zod
+      zod: 3.25.34
     transitivePeerDependencies:
       - encoding
 
@@ -11623,7 +11626,7 @@ snapshots:
 
   zod@3.24.3: {}
 
-  zod@3.25.0-beta.20250518T204520: {}
+  zod@3.25.34: {}
 
   zod@4.0.0-beta.20250420T053007:
     dependencies:


Test patch:
diff --git a/packages/zod/src/v4/classic/tests/discriminated-unions.test.ts b/packages/zod/src/v4/classic/tests/discriminated-unions.test.ts
index 64c75b09..de4a2a39 100644
--- a/packages/zod/src/v4/classic/tests/discriminated-unions.test.ts
+++ b/packages/zod/src/v4/classic/tests/discriminated-unions.test.ts
@@ -260,7 +260,7 @@ test("wrong schema - missing discriminator", () => {
     z.discriminatedUnion("type", [
       z.object({ type: z.literal("a"), a: z.string() }),
       z.object({ b: z.string() }) as any,
-    ])._zod.disc;
+    ])._zod.propValues;
     throw new Error();
   } catch (e: any) {
     expect(e.message.includes("Invalid discriminated union option")).toBe(true);
@@ -532,6 +532,32 @@ test("nested discriminated unions", () => {
     MyErrors,
   ]);
 
+  expect(MyErrors._zod.propValues).toMatchInlineSnapshot(`
+    {
+      "code": Set {
+        400,
+        401,
+        500,
+      },
+      "status": Set {
+        "failed",
+      },
+    }
+  `);
+  expect(MyResult._zod.propValues).toMatchInlineSnapshot(`
+    {
+      "code": Set {
+        400,
+        401,
+        500,
+      },
+      "status": Set {
+        "success",
+        "failed",
+      },
+    }
+  `);
+
   const result = MyResult.parse({ status: "success", data: "hello" });
   expect(result).toMatchInlineSnapshot(`
     {
diff --git a/packages/zod/src/v4/classic/tests/index.test.ts b/packages/zod/src/v4/classic/tests/index.test.ts
index 5ded8c49..7094794f 100644
--- a/packages/zod/src/v4/classic/tests/index.test.ts
+++ b/packages/zod/src/v4/classic/tests/index.test.ts
@@ -228,96 +228,6 @@ test("z.union", () => {
   expect(() => z.parse(a, true)).toThrow();
 });
 
-test("z.discriminatedUnion", () => {
-  const a = z.object({
-    type: z.literal("A"),
-    name: z.string(),
-  });
-  expect(a._zod.disc!.get("type")).toEqual({
-    values: new Set(["A"]),
-    maps: [],
-  });
-
-  const b = z.object({
-    type: z.literal("B"),
-    age: z.number(),
-  });
-
-  const c = z.discriminatedUnion("type", [a, b]);
-
-  expect(c._zod.def.options.length).toEqual(2);
-  expect(c._zod.disc!.get("type")!.values.has("A")).toEqual(true);
-  expect(c._zod.disc!.get("type")!.values.has("B")).toEqual(true);
-
-  expect(z.parse(c, { type: "A", name: "john" })).toEqual({
-    type: "A",
-    name: "john",
-  });
-  expect(z.parse(c, { type: "B", age: 30 })).toEqual({ type: "B", age: 30 });
-});
-
-test("z.discriminatedUnion with nested discriminator", () => {
-  const a = z.object({
-    type: z.object({ key: z.literal("A") }),
-    name: z.string(),
-  });
-
-  const b = z.object({
-    type: z.object({ key: z.literal("B") }),
-    age: z.number(),
-  });
-
-  const c = z.discriminatedUnion("type", [a, b]);
-  expect(c._zod.disc!.get("type")!.maps[0].get("key")!.values.has("A")).toEqual(true);
-  expect(c._zod.disc!.get("type")!.maps[1].get("key")!.values.has("B")).toEqual(true);
-
-  expect(z.parse(c, { type: { key: "A" }, name: "john" })).toEqual({
-    type: { key: "A" },
-    name: "john",
-  });
-  expect(z.parse(c, { type: { key: "B" }, age: 30 })).toEqual({
-    type: { key: "B" },
-    age: 30,
-  });
-});
-
-test("z.discriminatedUnion nested", () => {
-  const schema1 = z.discriminatedUnion("type", [
-    z.object({
-      type: z.literal("A"),
-      name: z.string(),
-    }),
-    z.object({
-      num: z.literal(1),
-      type: z.literal("B"),
-      age: z.number(),
-    }),
-  ]);
-
-  const schema2 = z.discriminatedUnion("type", [
-    z.object({
-      num: z.literal(2),
-      type: z.literal("C"),
-      name: z.string(),
-    }),
-    z.object({
-      num: z.literal(2),
-      type: z.literal("D"),
-      age: z.number(),
-    }),
-  ]);
-
-  const hyper = z.discriminatedUnion("type", [schema1, schema2]);
-  expect(hyper._zod.disc!.get("num")).toEqual({
-    values: new Set([1, 2]),
-    maps: [],
-  });
-  expect(hyper._zod.disc!.get("type")).toEqual({
-    values: new Set(["A", "B", "C", "D"]),
-    maps: [],
-  });
-});
-
 test("z.intersection", () => {
   const a = z.intersection(z.object({ a: z.string() }), z.object({ b: z.number() }));
   expect(z.parse(a, { a: "hello", b: 123 })).toEqual({ a: "hello", b: 123 });
diff --git a/packages/zod/src/v4/mini/tests/index.test.ts b/packages/zod/src/v4/mini/tests/index.test.ts
index d92d9cec..d1ab967b 100644
--- a/packages/zod/src/v4/mini/tests/index.test.ts
+++ b/packages/zod/src/v4/mini/tests/index.test.ts
@@ -228,96 +228,6 @@ test("z.union", () => {
   expect(() => z.parse(a, true)).toThrow();
 });
 
-test("z.discriminatedUnion", () => {
-  const a = z.object({
-    type: z.literal("A"),
-    name: z.string(),
-  });
-  expect(a._zod.disc?.get("type")).toEqual({
-    values: new Set(["A"]),
-    maps: [],
-  });
-
-  const b = z.object({
-    type: z.literal("B"),
-    age: z.number(),
-  });
-
-  const c = z.discriminatedUnion("type", [a, b]);
-
-  expect(c._zod.def.options.length).toEqual(2);
-  expect(c._zod.disc.get("type")!.values.has("A")).toEqual(true);
-  expect(c._zod.disc.get("type")!.values.has("B")).toEqual(true);
-
-  expect(z.parse(c, { type: "A", name: "john" })).toEqual({
-    type: "A",
-    name: "john",
-  });
-  expect(z.parse(c, { type: "B", age: 30 })).toEqual({ type: "B", age: 30 });
-});
-
-test("z.discriminatedUnion with nested discriminator", () => {
-  const a = z.object({
-    type: z.object({ key: z.literal("A") }),
-    name: z.string(),
-  });
-
-  const b = z.object({
-    type: z.object({ key: z.literal("B") }),
-    age: z.number(),
-  });
-
-  const c = z.discriminatedUnion("type", [a, b]);
-  expect(c._zod.disc!.get("type")!.maps[0].get("key")!.values.has("A")).toEqual(true);
-  expect(c._zod.disc!.get("type")!.maps[1].get("key")!.values.has("B")).toEqual(true);
-
-  expect(z.parse(c, { type: { key: "A" }, name: "john" })).toEqual({
-    type: { key: "A" },
-    name: "john",
-  });
-  expect(z.parse(c, { type: { key: "B" }, age: 30 })).toEqual({
-    type: { key: "B" },
-    age: 30,
-  });
-});
-
-test("z.discriminatedUnion nested", () => {
-  const schema1 = z.discriminatedUnion("type", [
-    z.object({
-      type: z.literal("A"),
-      name: z.string(),
-    }),
-    z.object({
-      num: z.literal(1),
-      type: z.literal("B"),
-      age: z.number(),
-    }),
-  ]);
-
-  const schema2 = z.discriminatedUnion("type", [
-    z.object({
-      num: z.literal(2),
-      type: z.literal("C"),
-      name: z.string(),
-    }),
-    z.object({
-      num: z.literal(2),
-      type: z.literal("D"),
-      age: z.number(),
-    }),
-  ]);
-
-  const hyper = z.discriminatedUnion("type", [schema1, schema2]);
-  expect(hyper._zod.disc.get("num")).toEqual({
-    values: new Set([1, 2]),
-    maps: [],
-  });
-  expect(hyper._zod.disc.get("type")).toEqual({
-    values: new Set(["A", "B", "C", "D"]),
-    maps: [],
-  });
-});
-
 test("z.intersection", () => {
   const a = z.intersection(z.object({ a: z.string() }), z.object({ b: z.number() }));
   expect(z.parse(a, { a: "hello", b: 123 })).toEqual({ a: "hello", b: 123 });