zod-compiler 1.28.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +176 -148
  2. package/dist/core/codegen/build-path.d.ts +12 -1
  3. package/dist/core/codegen/build-path.d.ts.map +1 -1
  4. package/dist/core/codegen/build-path.js +102 -21
  5. package/dist/core/codegen/build-path.js.map +1 -1
  6. package/dist/core/codegen/context.d.ts +31 -16
  7. package/dist/core/codegen/context.d.ts.map +1 -1
  8. package/dist/core/codegen/context.js +43 -18
  9. package/dist/core/codegen/context.js.map +1 -1
  10. package/dist/core/codegen/emit-issue.d.ts +17 -20
  11. package/dist/core/codegen/emit-issue.d.ts.map +1 -1
  12. package/dist/core/codegen/emit-issue.js +13 -13
  13. package/dist/core/codegen/emit-issue.js.map +1 -1
  14. package/dist/core/codegen/index.d.ts.map +1 -1
  15. package/dist/core/codegen/index.js +9 -7
  16. package/dist/core/codegen/index.js.map +1 -1
  17. package/dist/core/codegen/issue-decls.d.ts +83 -7
  18. package/dist/core/codegen/issue-decls.d.ts.map +1 -1
  19. package/dist/core/codegen/issue-decls.js +93 -10
  20. package/dist/core/codegen/issue-decls.js.map +1 -1
  21. package/dist/core/codegen/schemas/array.js +1 -1
  22. package/dist/core/codegen/schemas/array.js.map +1 -1
  23. package/dist/core/codegen/schemas/bigint.d.ts.map +1 -1
  24. package/dist/core/codegen/schemas/bigint.js +15 -4
  25. package/dist/core/codegen/schemas/bigint.js.map +1 -1
  26. package/dist/core/codegen/schemas/catch.d.ts.map +1 -1
  27. package/dist/core/codegen/schemas/catch.js +3 -2
  28. package/dist/core/codegen/schemas/catch.js.map +1 -1
  29. package/dist/core/codegen/schemas/discriminated-union.d.ts +6 -2
  30. package/dist/core/codegen/schemas/discriminated-union.d.ts.map +1 -1
  31. package/dist/core/codegen/schemas/discriminated-union.js +16 -56
  32. package/dist/core/codegen/schemas/discriminated-union.js.map +1 -1
  33. package/dist/core/codegen/schemas/effect.d.ts.map +1 -1
  34. package/dist/core/codegen/schemas/effect.js +4 -2
  35. package/dist/core/codegen/schemas/effect.js.map +1 -1
  36. package/dist/core/codegen/schemas/file.js +2 -8
  37. package/dist/core/codegen/schemas/file.js.map +1 -1
  38. package/dist/core/codegen/schemas/number.js +4 -3
  39. package/dist/core/codegen/schemas/number.js.map +1 -1
  40. package/dist/core/codegen/schemas/object.d.ts +11 -1
  41. package/dist/core/codegen/schemas/object.d.ts.map +1 -1
  42. package/dist/core/codegen/schemas/object.js +58 -14
  43. package/dist/core/codegen/schemas/object.js.map +1 -1
  44. package/dist/core/codegen/schemas/readonly.d.ts.map +1 -1
  45. package/dist/core/codegen/schemas/readonly.js.map +1 -1
  46. package/dist/core/codegen/schemas/record.d.ts.map +1 -1
  47. package/dist/core/codegen/schemas/record.js +8 -3
  48. package/dist/core/codegen/schemas/record.js.map +1 -1
  49. package/dist/core/codegen/schemas/sizeable.d.ts +49 -3
  50. package/dist/core/codegen/schemas/sizeable.d.ts.map +1 -1
  51. package/dist/core/codegen/schemas/sizeable.js +101 -8
  52. package/dist/core/codegen/schemas/sizeable.js.map +1 -1
  53. package/dist/core/codegen/schemas/string-bool.d.ts +12 -1
  54. package/dist/core/codegen/schemas/string-bool.d.ts.map +1 -1
  55. package/dist/core/codegen/schemas/string-bool.js +19 -4
  56. package/dist/core/codegen/schemas/string-bool.js.map +1 -1
  57. package/dist/core/codegen/schemas/string.d.ts.map +1 -1
  58. package/dist/core/codegen/schemas/string.js +60 -26
  59. package/dist/core/codegen/schemas/string.js.map +1 -1
  60. package/dist/core/codegen/schemas/tuple.d.ts +14 -11
  61. package/dist/core/codegen/schemas/tuple.d.ts.map +1 -1
  62. package/dist/core/codegen/schemas/tuple.js +99 -49
  63. package/dist/core/codegen/schemas/tuple.js.map +1 -1
  64. package/dist/core/codegen/well-known-regex.d.ts +26 -1
  65. package/dist/core/codegen/well-known-regex.d.ts.map +1 -1
  66. package/dist/core/codegen/well-known-regex.js +31 -4
  67. package/dist/core/codegen/well-known-regex.js.map +1 -1
  68. package/dist/core/extract/checks.d.ts.map +1 -1
  69. package/dist/core/extract/checks.js +1 -0
  70. package/dist/core/extract/checks.js.map +1 -1
  71. package/dist/core/extract/extractors/intersection.js +21 -6
  72. package/dist/core/extract/extractors/intersection.js.map +1 -1
  73. package/dist/core/extract/extractors/object.d.ts.map +1 -1
  74. package/dist/core/extract/extractors/object.js +25 -9
  75. package/dist/core/extract/extractors/object.js.map +1 -1
  76. package/dist/core/extract/extractors/optional.d.ts.map +1 -1
  77. package/dist/core/extract/extractors/optional.js +1 -28
  78. package/dist/core/extract/extractors/optional.js.map +1 -1
  79. package/dist/core/extract/extractors/record.js +9 -3
  80. package/dist/core/extract/extractors/record.js.map +1 -1
  81. package/dist/core/extract/extractors/tuple.d.ts.map +1 -1
  82. package/dist/core/extract/extractors/tuple.js +16 -20
  83. package/dist/core/extract/extractors/tuple.js.map +1 -1
  84. package/dist/core/extract/types.d.ts +16 -8
  85. package/dist/core/extract/types.d.ts.map +1 -1
  86. package/dist/core/iife.d.ts +2 -1
  87. package/dist/core/iife.d.ts.map +1 -1
  88. package/dist/core/iife.js +2 -1
  89. package/dist/core/iife.js.map +1 -1
  90. package/dist/core/types.d.ts +70 -21
  91. package/dist/core/types.d.ts.map +1 -1
  92. package/dist/jit.d.ts.map +1 -1
  93. package/dist/jit.js +47 -12
  94. package/dist/jit.js.map +1 -1
  95. package/dist/runtime.d.ts +4 -1
  96. package/dist/runtime.js +14 -11
  97. package/package.json +2 -2
@@ -1,36 +1,9 @@
1
- import { hasMutation } from "../../codegen/context.js";
2
1
  import { innerAppliesDefaultOnUndefined } from "../../codegen/schemas/optional.js";
3
2
  //#region src/core/extract/extractors/optional.ts
4
- /**
5
- * Running `ir` on `undefined` provably leaves the value `undefined` — whether it
6
- * accepts (yielding undefined) or rejects (leaving the payload untouched).
7
- *
8
- * This is the condition under which the compiled optional's `if (input !==
9
- * undefined)` short-circuit is EQUIVALENT to zod's optin branch, which runs the
10
- * inner and then nullifies a failure whose value is still undefined
11
- * (`handleOptionalResult`). Both end at "success, undefined".
12
- *
13
- * `!hasMutation` is exactly the property needed at the bottom of the chain: a
14
- * node that cannot rewrite values cannot turn `undefined` into one. The three
15
- * named wrappers recurse because they pass `undefined` straight through
16
- * (`$ZodNullable` only intercepts `null`, `$ZodReadonly` freezes the result, and
17
- * a nested `$ZodOptional` short-circuits or forwards). Everything else —
18
- * `default`, `catch`, an effect, and above all a `fallback` leaf standing in for
19
- * `z.prefault()` / a pipe / a union — reports mutating and is handled by the
20
- * caller instead.
21
- */
22
- function passesUndefinedThrough(ir) {
23
- switch (ir.type) {
24
- case "optional":
25
- case "nullable":
26
- case "readonly": return passesUndefinedThrough(ir.inner);
27
- default: return !hasMutation(ir);
28
- }
29
- }
30
3
  const extractOptional = (def, ctx) => {
31
4
  if ((ctx.schema?._zod?.traits)?.has("$ZodExactOptional")) return ctx.fallback("unsupported");
32
5
  const inner = ctx.visit(def.innerType, "._zod.def.innerType");
33
- if (def.innerType?._zod?.optin === "optional" && !innerAppliesDefaultOnUndefined(inner) && !passesUndefinedThrough(inner)) return ctx.fallback("unsupported");
6
+ if (def.innerType?._zod?.optin === "defaulted" && !innerAppliesDefaultOnUndefined(inner)) return ctx.fallback("unsupported");
34
7
  return {
35
8
  type: "optional",
36
9
  inner
@@ -1 +1 @@
1
- {"version":3,"file":"optional.js","names":[],"sources":["../../../../src/core/extract/extractors/optional.ts"],"sourcesContent":["import { hasMutation } from \"../../codegen/context.js\";\nimport { innerAppliesDefaultOnUndefined } from \"../../codegen/schemas/optional.js\";\nimport type { SchemaIR } from \"../../types.js\";\nimport type { Extractor, ZodSchema } from \"../types.js\";\n\n/**\n * Running `ir` on `undefined` provably leaves the value `undefined` — whether it\n * accepts (yielding undefined) or rejects (leaving the payload untouched).\n *\n * This is the condition under which the compiled optional's `if (input !==\n * undefined)` short-circuit is EQUIVALENT to zod's optin branch, which runs the\n * inner and then nullifies a failure whose value is still undefined\n * (`handleOptionalResult`). Both end at \"success, undefined\".\n *\n * `!hasMutation` is exactly the property needed at the bottom of the chain: a\n * node that cannot rewrite values cannot turn `undefined` into one. The three\n * named wrappers recurse because they pass `undefined` straight through\n * (`$ZodNullable` only intercepts `null`, `$ZodReadonly` freezes the result, and\n * a nested `$ZodOptional` short-circuits or forwards). Everything else —\n * `default`, `catch`, an effect, and above all a `fallback` leaf standing in for\n * `z.prefault()` / a pipe / a union — reports mutating and is handled by the\n * caller instead.\n */\nfunction passesUndefinedThrough(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"optional\":\n case \"nullable\":\n case \"readonly\":\n return passesUndefinedThrough(ir.inner);\n default:\n return !hasMutation(ir);\n }\n}\n\nexport const extractOptional: Extractor = (def, ctx) => {\n // z.exactOptional() shares def.type \"optional\" but rejects explicit\n // `undefined` (only a missing key is allowed) — compiled optionals accept\n // undefined, so delegate to Zod. Detectable only via constructor traits.\n const traits = (ctx.schema as ZodSchema | undefined)?._zod?.traits;\n if (traits?.has(\"$ZodExactOptional\")) {\n return ctx.fallback(\"unsupported\");\n }\n const inner = ctx.visit(def.innerType, \"._zod.def.innerType\");\n\n // `$ZodOptional.parse` has TWO branches, chosen by the inner schema's `optin`:\n //\n // if (innerType._zod.optin === \"optional\") // inner consumes `undefined` itself\n // return handleOptionalResult(innerType._zod.run(payload, ctx), payload.value);\n // if (payload.value === undefined) return payload; // short-circuit\n // return innerType._zod.run(payload, ctx);\n //\n // Compiled output models the short-circuit, plus the one first-branch case\n // that matters in practice: a `.default()` beneath, which must SEE the\n // undefined so the default fires (`z.string().default(\"d\").optional()` is\n // \"d\", not undefined).\n //\n // Every other optional-in inner — `z.prefault()`, `z.exactOptional()`,\n // `.nonoptional()`, a pipe, a union with an optional-in option, all of which\n // extract to an opaque `fallback` — can substitute a value for `undefined`\n // where the short-circuit would answer `undefined`, and the compiler cannot\n // see through the delegate to tell which. Worse, zod reads `payload.value`\n // AFTER the inner has run, so a prefault that fails its own checks keeps the\n // failure (the value is no longer undefined) — behaviour with no counterpart\n // here. Delegate the whole optional to zod rather than guess.\n const innerOptin = (def.innerType as ZodSchema | undefined)?._zod?.optin === \"optional\";\n if (innerOptin && !innerAppliesDefaultOnUndefined(inner) && !passesUndefinedThrough(inner)) {\n return ctx.fallback(\"unsupported\");\n }\n\n return { type: \"optional\", inner };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,SAAS,uBAAuB,IAAuB;CACrD,QAAQ,GAAG,MAAX;EACE,KAAK;EACL,KAAK;EACL,KAAK,YACH,OAAO,uBAAuB,GAAG,KAAK;EACxC,SACE,OAAO,CAAC,YAAY,EAAE;CAC1B;AACF;AAEA,MAAa,mBAA8B,KAAK,QAAQ;CAKtD,KADgB,IAAI,QAAkC,MAAM,OAAA,EAChD,IAAI,mBAAmB,GACjC,OAAO,IAAI,SAAS,aAAa;CAEnC,MAAM,QAAQ,IAAI,MAAM,IAAI,WAAW,qBAAqB;CAuB5D,IADoB,IAAI,WAAqC,MAAM,UAAU,cAC3D,CAAC,+BAA+B,KAAK,KAAK,CAAC,uBAAuB,KAAK,GACvF,OAAO,IAAI,SAAS,aAAa;CAGnC,OAAO;EAAE,MAAM;EAAY;CAAM;AACnC"}
1
+ {"version":3,"file":"optional.js","names":[],"sources":["../../../../src/core/extract/extractors/optional.ts"],"sourcesContent":["import { innerAppliesDefaultOnUndefined } from \"../../codegen/schemas/optional.js\";\nimport type { Extractor, ZodSchema } from \"../types.js\";\n\nexport const extractOptional: Extractor = (def, ctx) => {\n // z.exactOptional() shares def.type \"optional\" but rejects explicit\n // `undefined` (only a missing key is allowed) — compiled optionals accept\n // undefined, so delegate to Zod. Detectable only via constructor traits.\n const traits = (ctx.schema as ZodSchema | undefined)?._zod?.traits;\n if (traits?.has(\"$ZodExactOptional\")) {\n return ctx.fallback(\"unsupported\");\n }\n const inner = ctx.visit(def.innerType, \"._zod.def.innerType\");\n\n // `$ZodOptional.parse` short-circuits `undefined` unless the inner schema is\n // on the \"defaulted\" rung of `optin`:\n //\n // if (payload.value === undefined) {\n // if (def.innerType._zod.optin !== \"defaulted\") return payload; // short-circuit\n // return handleOptionalResult(payload, innerType._zod.run({ value: undefined, issues: [] }, ctx));\n // }\n // return innerType._zod.run(payload, ctx);\n //\n // Compiled output models the short-circuit, plus the one defaulted case that\n // matters in practice: a `.default()` beneath, which must SEE the undefined so\n // the default fires (`z.string().default(\"d\").optional()` is \"d\", not\n // undefined) and which can never fail on it.\n //\n // Every other defaulted inner — `z.prefault()`, `.catch()` over a default, a\n // union with a defaulted option — runs on a payload of its own, and\n // `handleOptionalResult` then yields `undefined` WITHOUT issues when that run\n // failed (`z.string().min(5).prefault(\"ab\").optional()` parses `undefined` to\n // `undefined`). Those shapes extract to an opaque `fallback` or a union\n // anyway, and the swallow has no counterpart in the compiled optional, so\n // delegate the whole optional to zod rather than emit the inner twice.\n const innerDefaulted = (def.innerType as ZodSchema | undefined)?._zod?.optin === \"defaulted\";\n if (innerDefaulted && !innerAppliesDefaultOnUndefined(inner)) {\n return ctx.fallback(\"unsupported\");\n }\n\n return { type: \"optional\", inner };\n};\n"],"mappings":";;AAGA,MAAa,mBAA8B,KAAK,QAAQ;CAKtD,KADgB,IAAI,QAAkC,MAAM,OAAA,EAChD,IAAI,mBAAmB,GACjC,OAAO,IAAI,SAAS,aAAa;CAEnC,MAAM,QAAQ,IAAI,MAAM,IAAI,WAAW,qBAAqB;CAwB5D,IADwB,IAAI,WAAqC,MAAM,UAAU,eAC3D,CAAC,+BAA+B,KAAK,GACzD,OAAO,IAAI,SAAS,aAAa;CAGnC,OAAO;EAAE,MAAM;EAAY;CAAM;AACnC"}
@@ -2,13 +2,19 @@ import { hasMutation } from "../../codegen/context.js";
2
2
  //#region src/core/extract/extractors/record.ts
3
3
  function extractRecord(def, ctx) {
4
4
  if (!def.valueType) return ctx.fallback("unsupported");
5
- const keyValues = def.keyType?._zod?.values;
6
- if (keyValues !== void 0 && keyValues.size > 0) return ctx.fallback("unsupported");
5
+ const enumerableKeys = def.keyType?._zod?.values !== void 0;
6
+ if (enumerableKeys && !def.partial) return ctx.fallback("unsupported");
7
+ if (def.mode === "loose") return ctx.fallback("unsupported");
7
8
  const keyType = ctx.visit(def.keyType, "._zod.def.keyType");
8
9
  const valueType = ctx.visit(def.valueType, "._zod.def.valueType");
9
10
  if (!isStringShapedKey(keyType)) return ctx.fallback("unsupported");
10
11
  if (hasMutation(keyType)) return ctx.fallback("unsupported");
11
- return {
12
+ return enumerableKeys ? {
13
+ type: "record",
14
+ keyType,
15
+ valueType,
16
+ enumerableKeys: true
17
+ } : {
12
18
  type: "record",
13
19
  keyType,
14
20
  valueType
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","names":[],"sources":["../../../../src/core/extract/extractors/record.ts"],"sourcesContent":["import { hasMutation } from \"../../codegen/context.js\";\nimport type { SchemaIR } from \"../../types.js\";\nimport type { ExtractorContext, ZodDef } from \"../types.js\";\n\nexport function extractRecord(def: ZodDef, ctx: ExtractorContext): SchemaIR {\n if (!def.valueType) {\n return ctx.fallback(\"unsupported\");\n }\n // Exhaustive-key records: when the key schema exposes a finite value set\n // (z.record(z.enum(...))), Zod requires EVERY key to be present and rejects\n // unrecognized keys. Compiled records only iterate input keys — delegate to\n // Zod. z.partialRecord() clears `_zod.values`, so it still compiles.\n const keyValues = def.keyType?._zod?.values;\n if (keyValues !== undefined && keyValues.size > 0) {\n return ctx.fallback(\"unsupported\");\n }\n const keyType = ctx.visit(def.keyType, \"._zod.def.keyType\");\n const valueType = ctx.visit(def.valueType, \"._zod.def.valueType\");\n // Object keys are strings at runtime. Zod coerces/validates numeric-string\n // keys for z.record(z.number(), ...) — the compiled key check would run\n // typeof on the string key and reject everything. Only string-shaped key\n // schemas compile; everything else delegates to Zod.\n if (!isStringShapedKey(keyType)) {\n return ctx.fallback(\"unsupported\");\n }\n // Rewriting key schemas (z.string().trim()/.toUpperCase(), z.url() — whose\n // check writes back the normalized href) RE-HOME the entry in zod: the output\n // carries the parsed key, so `z.record(z.string().toUpperCase(), z.number())`\n // turns `{ a: 1 }` into `{ A: 1 }`. The compiled record cannot follow, on two\n // independent counts.\n //\n // First, the key is validated with `{ input: keyVar, output: keyVar }`, so an\n // overwrite effect reassigns the loop variable in place; the value is then\n // read as `input[keyVar]` — i.e. at the REWRITTEN key, which is absent from\n // the input object — so the value check sees `undefined` and the record is\n // wrongly rejected with `invalid_type` at the rewritten path.\n //\n // Second, even with the lookup pinned to the original key, the walk iterates\n // the input with for-in and returns it BY REFERENCE, so it has nowhere to put\n // the moved entry: producing zod's output would mean building a fresh object\n // under the parsed keys, which also has to resolve collisions (two keys\n // normalizing to one). Neither half is expressible here, so delegate.\n if (hasMutation(keyType)) {\n return ctx.fallback(\"unsupported\");\n }\n return { type: \"record\", keyType, valueType };\n}\n\nfunction isStringShapedKey(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"string\":\n case \"templateLiteral\":\n return true;\n case \"enum\":\n return ir.values.every((v) => typeof v === \"string\");\n case \"literal\":\n // `typeof v === \"string\"` (not merely \"has a source form\") is what keeps a\n // SYMBOL key out, and it has to: the compiled record walks its input with\n // `for-in`, which yields string keys only, so a symbol-keyed entry would\n // be invisible to it — while zod's record enumerates the symbol keys too.\n // Only zod can decide such a record, so delegate.\n return ir.values.every((v) => typeof v === \"string\");\n case \"union\":\n return ir.options.every(isStringShapedKey);\n default:\n return false;\n }\n}\n"],"mappings":";;AAIA,SAAgB,cAAc,KAAa,KAAiC;CAC1E,IAAI,CAAC,IAAI,WACP,OAAO,IAAI,SAAS,aAAa;CAMnC,MAAM,YAAY,IAAI,SAAS,MAAM;CACrC,IAAI,cAAc,KAAA,KAAa,UAAU,OAAO,GAC9C,OAAO,IAAI,SAAS,aAAa;CAEnC,MAAM,UAAU,IAAI,MAAM,IAAI,SAAS,mBAAmB;CAC1D,MAAM,YAAY,IAAI,MAAM,IAAI,WAAW,qBAAqB;CAKhE,IAAI,CAAC,kBAAkB,OAAO,GAC5B,OAAO,IAAI,SAAS,aAAa;CAmBnC,IAAI,YAAY,OAAO,GACrB,OAAO,IAAI,SAAS,aAAa;CAEnC,OAAO;EAAE,MAAM;EAAU;EAAS;CAAU;AAC9C;AAEA,SAAS,kBAAkB,IAAuB;CAChD,QAAQ,GAAG,MAAX;EACE,KAAK;EACL,KAAK,mBACH,OAAO;EACT,KAAK,QACH,OAAO,GAAG,OAAO,OAAO,MAAM,OAAO,MAAM,QAAQ;EACrD,KAAK,WAMH,OAAO,GAAG,OAAO,OAAO,MAAM,OAAO,MAAM,QAAQ;EACrD,KAAK,SACH,OAAO,GAAG,QAAQ,MAAM,iBAAiB;EAC3C,SACE,OAAO;CACX;AACF"}
1
+ {"version":3,"file":"record.js","names":[],"sources":["../../../../src/core/extract/extractors/record.ts"],"sourcesContent":["import { hasMutation } from \"../../codegen/context.js\";\nimport type { SchemaIR } from \"../../types.js\";\nimport type { ExtractorContext, ZodDef } from \"../types.js\";\n\nexport function extractRecord(def: ZodDef, ctx: ExtractorContext): SchemaIR {\n if (!def.valueType) {\n return ctx.fallback(\"unsupported\");\n }\n // Exhaustive-key records: when the key schema exposes a finite value set\n // (z.record(z.enum(...))), Zod requires EVERY key to be present and rejects\n // unrecognized keys. Compiled records only iterate input keys — delegate to\n // Zod. z.partialRecord() keeps the key schema (and its values) but sets\n // `def.partial`, which is what zod itself reads to skip the exhaustive walk;\n // the values then only decide the ISSUE a stray key raises (see RecordIR).\n const keyValues = def.keyType?._zod?.values;\n const enumerableKeys = keyValues !== undefined;\n if (enumerableKeys && !def.partial) {\n return ctx.fallback(\"unsupported\");\n }\n // `z.looseRecord()` sets `def.mode = \"loose\"`, which zod checks BEFORE it ever\n // asks whether a key is recognized: an unrecognized key is copied to the\n // output verbatim rather than raising anything. The compiled walk runs the key\n // schema over every key and reports `invalid_key`, so it rejects input zod\n // passes straight through — `z.looseRecord(z.string().regex(/^a/), z.number())`\n // accepts `{b: 1}`. Nothing in RecordIR expresses \"validate these keys, copy\n // the rest\", so delegate.\n if (def.mode === \"loose\") {\n return ctx.fallback(\"unsupported\");\n }\n const keyType = ctx.visit(def.keyType, \"._zod.def.keyType\");\n const valueType = ctx.visit(def.valueType, \"._zod.def.valueType\");\n // Object keys are strings at runtime. Zod coerces/validates numeric-string\n // keys for z.record(z.number(), ...) — the compiled key check would run\n // typeof on the string key and reject everything. Only string-shaped key\n // schemas compile; everything else delegates to Zod.\n if (!isStringShapedKey(keyType)) {\n return ctx.fallback(\"unsupported\");\n }\n // Rewriting key schemas (z.string().trim()/.toUpperCase(), z.url() — whose\n // check writes back the normalized href) RE-HOME the entry in zod: the output\n // carries the parsed key, so `z.record(z.string().toUpperCase(), z.number())`\n // turns `{ a: 1 }` into `{ A: 1 }`. The compiled record cannot follow, on two\n // independent counts.\n //\n // First, the key is validated with `{ input: keyVar, output: keyVar }`, so an\n // overwrite effect reassigns the loop variable in place; the value is then\n // read as `input[keyVar]` — i.e. at the REWRITTEN key, which is absent from\n // the input object — so the value check sees `undefined` and the record is\n // wrongly rejected with `invalid_type` at the rewritten path.\n //\n // Second, even with the lookup pinned to the original key, the walk iterates\n // the input with for-in and returns it BY REFERENCE, so it has nowhere to put\n // the moved entry: producing zod's output would mean building a fresh object\n // under the parsed keys, which also has to resolve collisions (two keys\n // normalizing to one). Neither half is expressible here, so delegate.\n if (hasMutation(keyType)) {\n return ctx.fallback(\"unsupported\");\n }\n return enumerableKeys\n ? { type: \"record\", keyType, valueType, enumerableKeys: true }\n : { type: \"record\", keyType, valueType };\n}\n\nfunction isStringShapedKey(ir: SchemaIR): boolean {\n switch (ir.type) {\n case \"string\":\n case \"templateLiteral\":\n return true;\n case \"enum\":\n return ir.values.every((v) => typeof v === \"string\");\n case \"literal\":\n // `typeof v === \"string\"` (not merely \"has a source form\") is what keeps a\n // SYMBOL key out, and it has to: the compiled record walks its input with\n // `for-in`, which yields string keys only, so a symbol-keyed entry would\n // be invisible to it — while zod's record enumerates the symbol keys too.\n // Only zod can decide such a record, so delegate.\n return ir.values.every((v) => typeof v === \"string\");\n case \"union\":\n return ir.options.every(isStringShapedKey);\n default:\n return false;\n }\n}\n"],"mappings":";;AAIA,SAAgB,cAAc,KAAa,KAAiC;CAC1E,IAAI,CAAC,IAAI,WACP,OAAO,IAAI,SAAS,aAAa;CASnC,MAAM,iBADY,IAAI,SAAS,MAAM,WACA,KAAA;CACrC,IAAI,kBAAkB,CAAC,IAAI,SACzB,OAAO,IAAI,SAAS,aAAa;CASnC,IAAI,IAAI,SAAS,SACf,OAAO,IAAI,SAAS,aAAa;CAEnC,MAAM,UAAU,IAAI,MAAM,IAAI,SAAS,mBAAmB;CAC1D,MAAM,YAAY,IAAI,MAAM,IAAI,WAAW,qBAAqB;CAKhE,IAAI,CAAC,kBAAkB,OAAO,GAC5B,OAAO,IAAI,SAAS,aAAa;CAmBnC,IAAI,YAAY,OAAO,GACrB,OAAO,IAAI,SAAS,aAAa;CAEnC,OAAO,iBACH;EAAE,MAAM;EAAU;EAAS;EAAW,gBAAgB;CAAK,IAC3D;EAAE,MAAM;EAAU;EAAS;CAAU;AAC3C;AAEA,SAAS,kBAAkB,IAAuB;CAChD,QAAQ,GAAG,MAAX;EACE,KAAK;EACL,KAAK,mBACH,OAAO;EACT,KAAK,QACH,OAAO,GAAG,OAAO,OAAO,MAAM,OAAO,MAAM,QAAQ;EACrD,KAAK,WAMH,OAAO,GAAG,OAAO,OAAO,MAAM,OAAO,MAAM,QAAQ;EACrD,KAAK,SACH,OAAO,GAAG,QAAQ,MAAM,iBAAiB;EAC3C,SACE,OAAO;CACX;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"tuple.d.ts","names":[],"sources":["../../../../src/core/extract/extractors/tuple.ts"],"mappings":";;;iBAyBgB,aAAa,KAAK,QAAQ,KAAK,mBAAmB"}
1
+ {"version":3,"file":"tuple.d.ts","names":[],"sources":["../../../../src/core/extract/extractors/tuple.ts"],"mappings":";;;iBAgBgB,aAAa,KAAK,QAAQ,KAAK,mBAAmB"}
@@ -1,31 +1,27 @@
1
1
  //#region src/core/extract/extractors/tuple.ts
2
2
  /**
3
- * Port of `$ZodTuple`'s own `optStart` computation, run against the LIVE item
4
- * schemas:
5
- *
6
- * ```js
7
- * const reversedIndex = [...items].reverse().findIndex((i) => i._zod.optin !== "optional");
8
- * const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
9
- * ```
10
- *
11
- * i.e. the start of the trailing run of optional-in items (0 when every item is
12
- * optional-in). See {@link TupleIR.optStart} for why this is read from the zod
3
+ * Port of `$ZodTuple`'s `getTupleOptStart`, run against the LIVE item schemas:
4
+ * the index after the last item that fails `omittable`, or 0 when every item
5
+ * passes it. See {@link TupleIR.optStart} for why this is read from the zod
13
6
  * schema rather than inferred from the extracted IR.
14
7
  */
15
- function computeOptStart(items) {
16
- let start = items.length;
17
- for (let i = items.length - 1; i >= 0; i--) {
18
- if (items[i]?._zod?.optin !== "optional") break;
19
- start--;
20
- }
21
- return start;
8
+ function optStart(items, omittable) {
9
+ for (let i = items.length - 1; i >= 0; i--) if (!omittable(items[i]._zod)) return i + 1;
10
+ return 0;
22
11
  }
23
12
  function extractTuple(def, ctx) {
13
+ const items = def.items.map((item, i) => ctx.visit(item, `._zod.def.items[${i}]`));
14
+ const rest = def.rest ? ctx.visit(def.rest, "._zod.def.rest") : null;
15
+ const optinStart = optStart(def.items, (z) => z.optin !== void 0);
16
+ const optoutStart = optStart(def.items, (z) => z.optout === "optional");
17
+ const optionalIn = def.items.flatMap((item, i) => item._zod.optin === "optional" ? [i] : []);
24
18
  return {
25
19
  type: "tuple",
26
- items: def.items.map((item, i) => ctx.visit(item, `._zod.def.items[${i}]`)),
27
- rest: def.rest ? ctx.visit(def.rest, "._zod.def.rest") : null,
28
- optStart: computeOptStart(def.items)
20
+ items,
21
+ rest,
22
+ optStart: optinStart,
23
+ ...optoutStart < def.items.length ? { optoutStart } : {},
24
+ ...optionalIn.length > 0 ? { optionalIn } : {}
29
25
  };
30
26
  }
31
27
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tuple.js","names":[],"sources":["../../../../src/core/extract/extractors/tuple.ts"],"sourcesContent":["import type { SchemaIR } from \"../../types.js\";\nimport type { ExtractorContext, ZodDef, ZodSchema } from \"../types.js\";\n\n/**\n * Port of `$ZodTuple`'s own `optStart` computation, run against the LIVE item\n * schemas:\n *\n * ```js\n * const reversedIndex = [...items].reverse().findIndex((i) => i._zod.optin !== \"optional\");\n * const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;\n * ```\n *\n * i.e. the start of the trailing run of optional-in items (0 when every item is\n * optional-in). See {@link TupleIR.optStart} for why this is read from the zod\n * schema rather than inferred from the extracted IR.\n */\nfunction computeOptStart(items: unknown[]): number {\n let start = items.length;\n for (let i = items.length - 1; i >= 0; i--) {\n if ((items[i] as ZodSchema | undefined)?._zod?.optin !== \"optional\") break;\n start--;\n }\n return start;\n}\n\nexport function extractTuple(def: ZodDef, ctx: ExtractorContext): SchemaIR {\n const items = def.items.map((item, i) => ctx.visit(item, `._zod.def.items[${i}]`));\n const rest = def.rest ? ctx.visit(def.rest, \"._zod.def.rest\") : null;\n return { type: \"tuple\", items, rest, optStart: computeOptStart(def.items) };\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,OAA0B;CACjD,IAAI,QAAQ,MAAM;CAClB,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;EAC1C,IAAK,MAAM,EAAE,EAA4B,MAAM,UAAU,YAAY;EACrE;CACF;CACA,OAAO;AACT;AAEA,SAAgB,aAAa,KAAa,KAAiC;CAGzE,OAAO;EAAE,MAAM;EAAS,OAFV,IAAI,MAAM,KAAK,MAAM,MAAM,IAAI,MAAM,MAAM,mBAAmB,EAAE,EAAE,CAEpD;EAAG,MADlB,IAAI,OAAO,IAAI,MAAM,IAAI,MAAM,gBAAgB,IAAI;EAC3B,UAAU,gBAAgB,IAAI,KAAK;CAAE;AAC5E"}
1
+ {"version":3,"file":"tuple.js","names":[],"sources":["../../../../src/core/extract/extractors/tuple.ts"],"sourcesContent":["import type { SchemaIR } from \"../../types.js\";\nimport type { ExtractorContext, ZodDef, ZodSchema } from \"../types.js\";\n\n/**\n * Port of `$ZodTuple`'s `getTupleOptStart`, run against the LIVE item schemas:\n * the index after the last item that fails `omittable`, or 0 when every item\n * passes it. See {@link TupleIR.optStart} for why this is read from the zod\n * schema rather than inferred from the extracted IR.\n */\nfunction optStart(items: unknown[], omittable: (item: ZodSchema[\"_zod\"]) => boolean): number {\n for (let i = items.length - 1; i >= 0; i--) {\n if (!omittable((items[i] as ZodSchema)._zod)) return i + 1;\n }\n return 0;\n}\n\nexport function extractTuple(def: ZodDef, ctx: ExtractorContext): SchemaIR {\n const items = def.items.map((item, i) => ctx.visit(item, `._zod.def.items[${i}]`));\n const rest = def.rest ? ctx.visit(def.rest, \"._zod.def.rest\") : null;\n // optin is a three-rung ladder, so any rung above `undefined` permits an\n // absent slot; optout stays two-valued.\n const optinStart = optStart(def.items, (z) => z.optin !== undefined);\n const optoutStart = optStart(def.items, (z) => z.optout === \"optional\");\n const optionalIn = def.items.flatMap((item, i) =>\n (item as ZodSchema)._zod.optin === \"optional\" ? [i] : [],\n );\n return {\n type: \"tuple\",\n items,\n rest,\n optStart: optinStart,\n ...(optoutStart < def.items.length ? { optoutStart } : {}),\n ...(optionalIn.length > 0 ? { optionalIn } : {}),\n };\n}\n"],"mappings":";;;;;;;AASA,SAAS,SAAS,OAAkB,WAAyD;CAC3F,KAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KACrC,IAAI,CAAC,UAAW,MAAM,EAAE,CAAe,IAAI,GAAG,OAAO,IAAI;CAE3D,OAAO;AACT;AAEA,SAAgB,aAAa,KAAa,KAAiC;CACzE,MAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,MAAM,IAAI,MAAM,MAAM,mBAAmB,EAAE,EAAE,CAAC;CACjF,MAAM,OAAO,IAAI,OAAO,IAAI,MAAM,IAAI,MAAM,gBAAgB,IAAI;CAGhE,MAAM,aAAa,SAAS,IAAI,QAAQ,MAAM,EAAE,UAAU,KAAA,CAAS;CACnE,MAAM,cAAc,SAAS,IAAI,QAAQ,MAAM,EAAE,WAAW,UAAU;CACtE,MAAM,aAAa,IAAI,MAAM,SAAS,MAAM,MACzC,KAAmB,KAAK,UAAU,aAAa,CAAC,CAAC,IAAI,CAAC,CACzD;CACA,OAAO;EACL,MAAM;EACN;EACA;EACA,UAAU;EACV,GAAI,cAAc,IAAI,MAAM,SAAS,EAAE,YAAY,IAAI,CAAC;EACxD,GAAI,WAAW,SAAS,IAAI,EAAE,WAAW,IAAI,CAAC;CAChD;AACF"}
@@ -77,6 +77,10 @@ interface ZodDef {
77
77
  rest: ZodSchema | null;
78
78
  keyType: ZodSchema;
79
79
  valueType: ZodSchema;
80
+ /** `z.partialRecord()`: the key schema's values are not required to be present. */
81
+ partial?: boolean;
82
+ /** `z.looseRecord()`: an unrecognized key is copied through, not reported. */
83
+ mode?: "loose" | undefined;
80
84
  left: ZodSchema;
81
85
  right: ZodSchema;
82
86
  discriminator: string;
@@ -109,16 +113,20 @@ interface ZodSchema {
109
113
  /** Class trait names from zod's $constructor (e.g. "$ZodExactOptional"). */
110
114
  traits?: Set<string>;
111
115
  /** "optional" when the key may be absent in object output (zod optout). */
112
- optout?: string;
116
+ optout?: "optional" | undefined;
113
117
  /**
114
- * "optional" when the schema ACCEPTS an absent/undefined input — zod's
115
- * `optin`. Set outright by `z.optional()`, `z.exactOptional()`,
116
- * `z.undefined()`, `.default()` and `.prefault()`, and propagated by
117
- * `.nullable()`, `.readonly()`, `.nonoptional()`, `z.lazy()`, a pipe (from
118
- * its `in`) and a union (when ANY option has it). Drives which tuple items
119
- * may be omitted and which branch `$ZodOptional` takes.
118
+ * zod's `optin`, a three-rung ladder: `undefined` (the slot must be
119
+ * present), `"optional"` (absence permitted, nothing supplied in its place
120
+ * — `z.optional()`, `z.exactOptional()`, `.catch()` over a plain schema)
121
+ * and `"defaulted"` (absence permitted, a value substituted — `.default()`,
122
+ * `.prefault()`, and `.optional()`/`.catch()` over one of those).
123
+ * Propagated by `.nullable()`, `.readonly()`, `z.lazy()`, a pipe (from its
124
+ * `in`) and a union (the highest rung any option reaches). `z.undefined()`,
125
+ * `z.any()` and `.nonoptional()` sit on the bottom rung. Drives which tuple
126
+ * items may be omitted, how an absent object key is treated and whether
127
+ * `$ZodOptional` short-circuits `undefined`.
120
128
  */
121
- optin?: string;
129
+ optin?: "optional" | "defaulted" | undefined;
122
130
  /** Discriminator dispatch values per property key (discriminated unions). */
123
131
  propValues?: Record<string, Set<unknown> | undefined>;
124
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/core/extract/types.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA,WAAW;EACX,WAAW;EACX;EACA;;UAGe;EACf;IACE,KAAK;;;;;;IAML;;;UAIa;EACf;;EAEA;;EAEA;;EAEA;EACA,QAAQ;EACR;EACA;EACA,SAAS;;EAET;;EAEA,WAAW;EACX,OAAO,eAAe;EACtB,SAAS;EACT,SAAS;EACT,WAAW;;;;;;EAMX,QAAQ;EACR,SAAS;EACT,IAAI;EACJ,KAAK;EACL,OAAO;EACP,MAAM;EACN,SAAS;EACT,WAAW;EACX,MAAM;EACN,OAAO;EACP;;;;;;EAMA;;EAEA;EACA;EACA;EACA,cAAc;;EAEd;;EAEA;;UAGe;EACf;IACE,KAAK;IACL,MAAM;;IAEN,YAAY;;IAEZ,UAAU;;IAEV,SAAS;;IAET,SAAS;;IAET;;;;;;;;;IASA;;IAEA,aAAa,eAAe;;;;UAKf;;EAEf;;EAEA;;;KAMU;;;;;;;;;;UA8CK;;WAEN;;WAEA,SAAS;;EAElB;;;UAMe;;WAEN;;WAEA;;WAEA,MAAM;;WAEN,UAAU;;WAEV,WAAW;;EAGpB,MAAM,sBAAsB,sBAHR;;EAMpB,SAAS,QAH+D,uBAGjC;;;KAI7B,aAAa,KAAK,QAAQ,KAAK,qBAAA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/core/extract/types.ts"],"mappings":";;UAEiB;EACf;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA,WAAW;EACX,WAAW;EACX;EACA;;UAGe;EACf;IACE,KAAK;;;;;;IAML;;;UAIa;EACf;;EAEA;;EAEA;;EAEA;EACA,QAAQ;EACR;EACA;EACA,SAAS;;EAET;;EAEA,WAAW;EACX,OAAO,eAAe;EACtB,SAAS;EACT,SAAS;EACT,WAAW;;;;;;EAMX,QAAQ;EACR,SAAS;EACT,IAAI;EACJ,KAAK;EACL,OAAO;EACP,MAAM;EACN,SAAS;EACT,WAAW;;EAEX;;EAEA;EACA,MAAM;EACN,OAAO;EACP;;;;;;EAMA;;EAEA;EACA;EACA;EACA,cAAc;;EAEd;;EAEA;;UAGe;EACf;IACE,KAAK;IACL,MAAM;;IAEN,YAAY;;IAEZ,UAAU;;IAEV,SAAS;;IAET,SAAS;;IAET;;;;;;;;;;;;;IAaA;;IAEA,aAAa,eAAe;;;;UAKf;;EAEf;;EAEA;;;KAMU;;;;;;;;;;UA8CK;;WAEN;;WAEA,SAAS;;EAElB;;;UAMe;;WAEN;;WAEA;;WAEA,MAAM;;WAEN,UAAU;;WAEV,WAAW;;EAGpB,MAAM,sBAAsB,sBAHR;;EAMpB,SAAS,QAH+D,uBAGjC;;;KAI7B,aAAa,KAAK,QAAQ,KAAK,qBAAA"}
@@ -222,7 +222,8 @@ declare const MK_VALIDATOR_DECL: string;
222
222
  * descriptor, so ONE `.shape` read fires ALL of an object's recursion getters).
223
223
  * Binding `__zs` itself does not: constructing the schema leaves deferred
224
224
  * callbacks unforced, and `usesRetainedSchema`'s only read is `__zs.safeParse`,
225
- * an own property zod assigns during `ZodType.init`.
225
+ * a prototype getter that binds the method and installs the bound copy on the
226
+ * instance without touching the schema's structure.
226
227
  *
227
228
  * The distinction decides whether the IIFE may be evaluated inside the
228
229
  * INITIALIZER of the binding the schema's own deferred callbacks close over —
@@ -1 +1 @@
1
- {"version":3,"file":"iife.d.ts","names":[],"sources":["../../src/core/iife.ts"],"mappings":";;;;;;;;cAca;;;;;;;;;;;;;;;;;;;;cAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CA;;;cAUA;;;;;;;;;;;;;;;;;;;;;;;cAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BA;;cAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6FA;;;;;;;;;;;;;;;;iBA4BG,iBAAiB,QAAQ;;;;;;;;;;;;;iBAgBzB,aACd,oBACA,QAAQ,oBACR;EAAY;EAAiC"}
1
+ {"version":3,"file":"iife.d.ts","names":[],"sources":["../../src/core/iife.ts"],"mappings":";;;;;;;;cAca;;;;;;;;;;;;;;;;;;;;cAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8CA;;;cAUA;;;;;;;;;;;;;;;;;;;;;;;cAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;cA2BA;;cAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6FA;;;;;;;;;;;;;;;;;iBA6BG,iBAAiB,QAAQ;;;;;;;;;;;;;iBAgBzB,aACd,oBACA,QAAQ,oBACR;EAAY;EAAiC"}
package/dist/core/iife.js CHANGED
@@ -231,7 +231,8 @@ function extractFunctionName(functionDef) {
231
231
  * descriptor, so ONE `.shape` read fires ALL of an object's recursion getters).
232
232
  * Binding `__zs` itself does not: constructing the schema leaves deferred
233
233
  * callbacks unforced, and `usesRetainedSchema`'s only read is `__zs.safeParse`,
234
- * an own property zod assigns during `ZodType.init`.
234
+ * a prototype getter that binds the method and installs the bound copy on the
235
+ * instance without touching the schema's structure.
235
236
  *
236
237
  * The distinction decides whether the IIFE may be evaluated inside the
237
238
  * INITIALIZER of the binding the schema's own deferred callbacks close over —
@@ -1 +1 @@
1
- {"version":3,"file":"iife.js","names":[],"sources":["../../src/core/iife.ts"],"sourcesContent":["/**\n * Shared CompiledSchema<T> IIFE generation.\n * Used by both CLI emitter and unplugin transform.\n */\n\nimport { RETAINED_SCHEMA_VAR } from \"./codegen/context.js\";\nimport type { CompiledSchemaInfo } from \"./pipeline.js\";\n\n/**\n * Import statement required by generateIIFE output (references\n * __zodCompilerConfig). `core` is bound for $ZodAsyncError: superRefine and\n * custom callbacks may only reveal that they are async through the promise\n * they return, at which point zod's own synchronous parse raises.\n */\nexport const ZOD_CONFIG_IMPORT =\n 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";';\n\n/**\n * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):\n * the message an issue gets when nothing was baked into it at build time.\n *\n * Resolves zod's tail of `finalizeIssue` — `config.customError` then\n * `config.localeError` then \"Invalid input\" — and does it PER CALL, because the\n * config is mutable: `z.config({ localeError })` in an entry point runs after\n * the schema modules it imports, so a value snapshotted at module init misses\n * it. Reading a captured `localeError` alone also dropped `customError`\n * outright, silently ignoring the global map most i18n setups install.\n *\n * The head of zod's chain — the schema's own `error` option — is baked into the\n * issue at build time and short-circuits this. The one link that cannot be\n * reproduced is a per-CALL `ctx.error`, which would have to travel through\n * `safeParse`; that entry point sits at V8's inlining budget, where even an\n * unused extra parameter measured ~12% on every parse.\n *\n * Only ever called while building an error, never on a successful parse.\n */\nexport const ZOD_MSG_DECLARATION =\n 'function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}' +\n \"var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;\" +\n \"if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}\" +\n \"if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}\" +\n 'return \"Invalid input\";};';\n\n/**\n * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)\n * declares it once per compiled file; lean mode (all unplugin bundlers) declares\n * it once per bundle in the plugin-materialized runtime module (module-local —\n * generated code only ever references __zcFin/__zcFinD, never __ZcFail).\n *\n * Why a prototype getter and not `{success:false, get error(){...}}`: an object\n * literal with an inline accessor forces V8 down its slow accessor-defining\n * allocation path — ~110ns per failure, measured — which dominates the entire\n * invalid-input cost whenever callers never read `.error`. Hosting `error` on\n * the prototype turns each failure into a plain field-only instantiation (~2ns,\n * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a\n * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread\n * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,\n * destructuring, and `in` are unaffected.)\n *\n * One class serves both finalizers, so the instances share one hidden class:\n * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD\n * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter\n * runs the walk on first `.error` read. The whole finalization — locale fill\n * (__zcMsg applied ONLY when an issue carries no message, never overwriting a\n * baked-in custom/fallback message), input strip, and ZodError construction\n * (zod v4 JSON.stringifies every issue into `message` and captures a stack\n * trace) — stays deferred inside the cached accessor exactly as before, since\n * the issues array is observable solely through `.error`.\n *\n * `input` is `delete`d, not assigned `undefined`. Key PRESENCE is observable —\n * `\"input\" in issue`, `Object.keys(issue)`, object spread, `toStrictEqual`\n * against a zod issue — and zod's `util.finalizeIssue` does `delete full.input`\n * whenever `reportInput` is off, so assignment left every compiled issue one\n * enumerable key wider than zod's. The delete's dictionary-mode transition is\n * affordable precisely BECAUSE of the deferral above: it runs only after a\n * caller asks for `.error` on a failed parse, and is memoised in `_c`. Neither\n * a successful parse nor a `.success`/`.is()` check on a rejected one reaches\n * it — measured, the two are unchanged, while the `.error` read itself goes\n * ~3.95us -> ~4.19us per failure, i.e. ~6% of a path whose cost is already\n * dominated by the ZodError construction on the next line (stack capture plus a\n * JSON.stringify of every issue).\n */\nexport const FAIL_CLASS_DECL =\n \"function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){' +\n \"if(this._c)return this._c;\" +\n \"var e=this._f!==null?this._f(this._i):this._e;\" +\n 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);delete e[i].input;delete e[i].continue;}' +\n \"return this._c=new __zcZodError(e);}});\";\n\n/** Eager finalizer (mutation / partial-fast-path schemas): issues already\n * collected in `e`; success short-circuits to a plain result literal. */\nexport const FIN_DECL =\n \"function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}\";\n\n/**\n * Deferred-collection finalizer for Fast-Path-eligible schemas. When the\n * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is\n * pushed into the cached `.error` accessor instead of running eagerly:\n * fast-eligible schemas never mutate, so the walk's only output is the\n * issues array, which is observable solely through `.error` — one step\n * further along the same lazy boundary `__zcFin` already established (locale\n * fill, input strip, ZodError construction). A failed safeParse whose\n * `.error` is never read costs the fast check alone.\n *\n * Takes the schema's HOSTED slow-walk function plus the input — NOT a\n * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result\n * object, where `__zcFinD(function(){...})` paid a closure environment and\n * function object per failure. Hosting the walk also shrinks safeParse to\n * two statements, within V8's inlining budget (the success-path result\n * literal becomes escape-analyzable at monomorphic call sites).\n *\n * The walk re-reads `input` at `.error`-read time; a caller that mutates\n * the input between safeParse and reading `.error` sees issues for the\n * mutated value (zod materializes at parse time). Same caveat class as the\n * documented __zcFin deferral.\n */\nexport const FIN_DEFERRED_DECL = \"function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}\";\n\n/**\n * Compact-mode failure class — a lazy failure that delegates error reporting to\n * the ORIGINAL Zod schema's `safeParse`. Used by `output: \"compact\"`, where the\n * compiled slow walk is dropped entirely: a mutation-free schema's fast check\n * is the only generated validation, and on a fast-check failure the cold error\n * path is produced by the retained Zod schema itself (`zod` is the source of\n * truth, so the issues are byte-identical — no second validation engine).\n *\n * `_z` is the schema's PRISTINE safeParse method, captured by\n * emitRetainedMethod (see context.ts), and `_r` is its receiver — the `__zs`\n * binding generateIIFE places above that capture. Both are read before the\n * trailing `__zcMkv` call installs anything, so the method is zod's own\n * implementation, never the compiled delegate, avoiding infinite recursion\n * without allocating a bound function. The zod parse is deferred until `.error`\n * is read and cached, so\n * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only\n * the fast check (zod never runs) — the same deferral boundary `__zcFinD`\n * establishes for the compiled slow walk. Sound because compact mode is gated\n * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`\n * holds without consulting zod.\n *\n * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /\n * re-wrap — zod already finalized it), so a delegated failure is exactly what\n * the unaltered schema would have produced.\n */\nexport const FAILZ_CLASS_DECL =\n \"function __ZcFailZ(z,r,i){this.success=false;this._z=z;this._r=r;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){' +\n \"return this._c||(this._c=this._z.call(this._r,this._i).error);}});\";\n\n/** Compact-mode finalizer: retain a pristine safeParse, its receiver, and input lazily. */\nexport const FINZ_DECL = \"function __zcFinZ(z,r,i){return new __ZcFailZ(z,r,i);}\";\n\n/**\n * Validator factory. Inline mode (CLI emitter) declares it once per compiled\n * file; lean mode (all unplugin bundlers) exports it once per bundle from the\n * plugin-materialized runtime module — generated code never imports it from\n * the zod-compiler package itself, so zod-compiler stays a devDependency and\n * the helper set is always version-locked to the codegen that calls it.\n * Wraps a safeParse function into the CompiledSchema interface.\n *\n * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled\n * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties\n * on the original schema object, which is returned as-is. zod v4 keys\n * several APIs on object identity — toJSONSchema's ctx.seen registers the\n * object it is handed while each processor closure captures the original\n * inst (a wrapper crashes `optionalProcessor` with \"Cannot set properties\n * of undefined (setting 'ref')\" the moment a compiled schema is composed\n * into another schema), and globalRegistry/.meta() is a WeakMap keyed by\n * the schema instance (a wrapper silently loses OpenAPI titles/ids). An\n * Object.create wrapper breaks both; mutating the original breaks neither\n * (zod's internal parsing flows through _zod.run, never the public\n * methods, and derived schemas — .optional(), .extend() — are fresh\n * instances that fall back to plain zod). schema=null (zodCompat: false)\n * still produces a plain method-bag object.\n *\n * fc is the schema's hosted fast-check boolean function (null when no Fast\n * Path exists). parse()/parseAsync() try it first and return the input\n * directly on success: fc is small enough for V8 to inline, so the hot parse\n * path runs with zero allocations — calling fn would allocate an intermediate\n * SafeParseResult that escape analysis cannot remove (fn never inlines).\n * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.\n *\n * is is the TOTAL fast-check predicate (fc when the fast path is total, else\n * null). Installed as `.is()` — a zero-allocation boolean type guard. When\n * null (partial fast path or none) `.is()` derives from fn(input).success: a\n * partial fc can pass-through valid input but its `false` does not imply\n * rejection (a default/catch may still succeed), so it would be unsound as a\n * standalone guard.\n *\n * parseAsync/safeParseAsync wrap the SYNC validator, which is right for every\n * schema the compiler can reproduce — none of them are async. It is wrong for\n * the ones it cannot: an `async` refinement or a `z.promise()` extracts to a\n * Zod delegate, and delegating means calling Zod's SYNCHRONOUS safeParse, which\n * raises `$ZodAsyncError` by design. Wrapping that gave the compiled schema an\n * async pair that rejected with `$ZodAsyncError` for EVERY input — including\n * valid ones — where Zod resolves normally, so `await UserSchema.parseAsync(x)`\n * stopped working the moment any part of the schema went async.\n *\n * So both are guarded: a synchronous throw hands off to the schema's ORIGINAL\n * async method, captured before these are installed — the same escape hatch\n * `~standard` already uses for its throw path, and for the same reason (the\n * compiled validator has no async mode to offer, and Zod's is exact). It also\n * fixes the smaller wart that a throwing `fn` made `parseAsync` throw\n * SYNCHRONOUSLY rather than return a rejected promise. With `zodCompat: false`\n * there is no schema to delegate to and the throw propagates as before.\n *\n * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as\n * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight\n * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so\n * installing the compiled one leaves this route entirely uncompiled: measured\n * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema\n * consumers (tRPC, Hono, TanStack) were getting plain Zod.\n *\n * Zod's own `~standard` is never READ, only overwritten. Zod installs the slot\n * with `util.defineLazy` — commented there as \"avoid creating objects for every\n * schema\" — so it is an accessor that builds `{version, vendor, validate}` plus\n * its closure on first touch. Reading it to capture a fallback fired that getter\n * for every compiled schema while the module was still initializing.\n *\n * How much that costs depends on the entry point, and only one of them is free:\n * classic `zod` forces the slot itself during `ZodType.init` (it does\n * `Object.assign(inst[\"~standard\"], { jsonSchema })`), so there the read hit an\n * already-built object and cost only an accessor call. `zod/mini` and raw\n * `zod/v4/core` never touch it, so for those the read built — and retained — an\n * object and a closure per schema, purely to capture a fallback the schema will\n * most likely never expose to a Standard Schema consumer.\n *\n * The throw path is rebuilt instead of captured. Zod's validate catches a\n * synchronous throw and retries through `safeParseAsync` — that is how an async\n * refinement resolves and how a throwing check surfaces as a rejected promise\n * rather than a synchronous throw — so calling the already-captured `zspa` and\n * mapping its result is the same route to the same result. `vendor` is likewise\n * a constant: schema discovery only ever admits zod schemas, and classic, mini\n * and core all hardcode `vendor: \"zod\"` themselves.\n *\n * Not carried over (unchanged by this, and pre-dating it): classic's\n * `~standard.jsonSchema` extension, which the replacement object has never\n * reproduced.\n *\n * Installed with defineProperty rather than assignment: Zod's lazy setter\n * redefines the slot as non-writable, so a second `__zcMkv` on the same schema\n * object — two exports aliasing one schema — would throw under ESM strict mode.\n */\nexport const MK_VALIDATOR_DECL =\n \"function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};\" +\n 'Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zspa)return zspa(input).then(function(q){return q.success?{value:q.data}:{issues:q.error.issues};});throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +\n \"return w;}\";\n\nfunction extractFunctionName(functionDef: string): string {\n const match = /^function\\s+(\\w+)\\s*\\(/.exec(functionDef);\n if (!match?.[1]) {\n throw new Error(\"Cannot extract function name from generated code\");\n }\n return match[1];\n}\n\n/**\n * Does the IIFE's preamble DEREFERENCE the retained schema at evaluation time?\n *\n * Only `__rf` does: every entry is `__zs<accessPath>`, and an access path walks\n * the schema's structure — `._zod.innerType` fires a `z.lazy()` getter,\n * `.shape` materializes a `z.object()` shape (zod v4 reads every property\n * descriptor, so ONE `.shape` read fires ALL of an object's recursion getters).\n * Binding `__zs` itself does not: constructing the schema leaves deferred\n * callbacks unforced, and `usesRetainedSchema`'s only read is `__zs.safeParse`,\n * an own property zod assigns during `ZodType.init`.\n *\n * The distinction decides whether the IIFE may be evaluated inside the\n * INITIALIZER of the binding the schema's own deferred callbacks close over —\n * see the self-referential path in the unplugin's autoDiscover rewrite.\n */\nexport function iifeDerefsSchema(schema: CompiledSchemaInfo): boolean {\n return schema.refEntries.length > 0;\n}\n\n/**\n * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.\n *\n * @param schemaExpr - Expression resolving to the original Zod schema\n * (e.g. `\"UserSchema\"` in unplugin, `\"(__src_X as any).schema\"` in CLI)\n * @param schema\n * @param options - `pure: false` drops the `/* @__PURE__ * /` annotation, for\n * the one caller that emits the IIFE as a STATEMENT following the\n * declaration rather than as its initializer: there the call's whole point is\n * its side effect (`__zcMkv` installing the compiled methods on the schema),\n * and a bundler that believed it pure would drop the compilation outright.\n */\nexport function generateIIFE(\n schemaExpr: string,\n schema: CompiledSchemaInfo,\n options?: { zodCompat?: boolean | undefined; pure?: boolean | undefined },\n): string {\n const { codegenResult, refEntries } = schema;\n const fnName = extractFunctionName(codegenResult.functionDef);\n const zodCompat = options?.zodCompat !== false;\n // Every fallback access starts from the same source schema, and compact\n // delegation names it outright. Capture it once whenever either needs it, so\n // an inline initializer is not reconstructed for each path and again for the\n // identity-preserving __zcMkv target.\n const bindsSchema = refEntries.length > 0 || codegenResult.usesRetainedSchema === true;\n const retainedSchema = bindsSchema ? RETAINED_SCHEMA_VAR : schemaExpr;\n const schemaArg = zodCompat ? retainedSchema : \"null\";\n const fcArg = codegenResult.fastFnName ?? \"null\";\n // `.is()` gets the fast-check directly only when it is a total predicate;\n // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding\n // schema has no by-reference `fc` but still names its predicate separately.\n const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : \"null\");\n\n return [\n options?.pure === false ? \"(() => {\" : \"/* @__PURE__ */ (() => {\",\n ...(bindsSchema ? [`var ${RETAINED_SCHEMA_VAR}=${schemaExpr};`] : []),\n // Only fallback refs need the array; a compact validator with none of its\n // own reads `__zs` directly rather than allocating `[__zs]` to index into.\n ...(refEntries.length > 0\n ? [`var __rf=[${refEntries.map((fb) => `${retainedSchema}${fb.accessPath}`).join(\",\")}];`]\n : []),\n ...codegenResult.code\n .split(\"\\n\")\n .filter((l) => l.trim() !== \"\" && l.trim() !== \"/* zod-compiler */\"),\n codegenResult.functionDef,\n `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,\n \"})()\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,oBACX;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,sBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CF,MAAa,kBACX;;;AASF,MAAa,WACX;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BjC,MAAa,mBACX;;AAKF,MAAa,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FzB,MAAa,oBACX;AAIF,SAAS,oBAAoB,aAA6B;CACxD,MAAM,QAAQ,yBAAyB,KAAK,WAAW;CACvD,IAAI,CAAC,QAAQ,IACX,MAAM,IAAI,MAAM,kDAAkD;CAEpE,OAAO,MAAM;AACf;;;;;;;;;;;;;;;;AAiBA,SAAgB,iBAAiB,QAAqC;CACpE,OAAO,OAAO,WAAW,SAAS;AACpC;;;;;;;;;;;;;AAcA,SAAgB,aACd,YACA,QACA,SACQ;CACR,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,SAAS,oBAAoB,cAAc,WAAW;CAC5D,MAAM,YAAY,SAAS,cAAc;CAKzC,MAAM,cAAc,WAAW,SAAS,KAAK,cAAc,uBAAuB;CAClF,MAAM,iBAAiB,cAAc,sBAAsB;CAC3D,MAAM,YAAY,YAAY,iBAAiB;CAC/C,MAAM,QAAQ,cAAc,cAAc;CAI1C,MAAM,QAAQ,cAAc,aAAa,cAAc,YAAY,QAAQ;CAE3E,OAAO;EACL,SAAS,SAAS,QAAQ,aAAa;EACvC,GAAI,cAAc,CAAC,OAAO,oBAAoB,GAAG,WAAW,EAAE,IAAI,CAAC;EAGnE,GAAI,WAAW,SAAS,IACpB,CAAC,aAAa,WAAW,KAAK,OAAO,GAAG,iBAAiB,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,IACvF,CAAC;EACL,GAAG,cAAc,KACd,MAAM,IAAI,CAAC,CACX,QAAQ,MAAM,EAAE,KAAK,MAAM,MAAM,EAAE,KAAK,MAAM,oBAAoB;EACrE,cAAc;EACd,kBAAkB,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM;EACxD;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
1
+ {"version":3,"file":"iife.js","names":[],"sources":["../../src/core/iife.ts"],"sourcesContent":["/**\n * Shared CompiledSchema<T> IIFE generation.\n * Used by both CLI emitter and unplugin transform.\n */\n\nimport { RETAINED_SCHEMA_VAR } from \"./codegen/context.js\";\nimport type { CompiledSchemaInfo } from \"./pipeline.js\";\n\n/**\n * Import statement required by generateIIFE output (references\n * __zodCompilerConfig). `core` is bound for $ZodAsyncError: superRefine and\n * custom callbacks may only reveal that they are async through the promise\n * they return, at which point zod's own synchronous parse raises.\n */\nexport const ZOD_CONFIG_IMPORT =\n 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";';\n\n/**\n * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):\n * the message an issue gets when nothing was baked into it at build time.\n *\n * Resolves zod's tail of `finalizeIssue` — `config.customError` then\n * `config.localeError` then \"Invalid input\" — and does it PER CALL, because the\n * config is mutable: `z.config({ localeError })` in an entry point runs after\n * the schema modules it imports, so a value snapshotted at module init misses\n * it. Reading a captured `localeError` alone also dropped `customError`\n * outright, silently ignoring the global map most i18n setups install.\n *\n * The head of zod's chain — the schema's own `error` option — is baked into the\n * issue at build time and short-circuits this. The one link that cannot be\n * reproduced is a per-CALL `ctx.error`, which would have to travel through\n * `safeParse`; that entry point sits at V8's inlining budget, where even an\n * unused extra parameter measured ~12% on every parse.\n *\n * Only ever called while building an error, never on a successful parse.\n */\nexport const ZOD_MSG_DECLARATION =\n 'function __zcUw(m){return typeof m===\"string\"?m:(m===undefined||m===null?undefined:m.message);}' +\n \"var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;\" +\n \"if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}\" +\n \"if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}\" +\n 'return \"Invalid input\";};';\n\n/**\n * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)\n * declares it once per compiled file; lean mode (all unplugin bundlers) declares\n * it once per bundle in the plugin-materialized runtime module (module-local —\n * generated code only ever references __zcFin/__zcFinD, never __ZcFail).\n *\n * Why a prototype getter and not `{success:false, get error(){...}}`: an object\n * literal with an inline accessor forces V8 down its slow accessor-defining\n * allocation path — ~110ns per failure, measured — which dominates the entire\n * invalid-input cost whenever callers never read `.error`. Hosting `error` on\n * the prototype turns each failure into a plain field-only instantiation (~2ns,\n * ~13x), with the lazy-cache semantics intact. (Trade-off: `error` is a\n * prototype accessor, so it no longer shows up in `Object.keys(result)` / spread\n * / JSON.stringify of the result wrapper — `.success`/`.error`/`.data` access,\n * destructuring, and `in` are unaffected.)\n *\n * One class serves both finalizers, so the instances share one hidden class:\n * __zcFin passes pre-collected issues in `_e` (with `_f===null`); __zcFinD\n * passes the hosted slow-walk in `_f` plus the input in `_i`, and the getter\n * runs the walk on first `.error` read. The whole finalization — locale fill\n * (__zcMsg applied ONLY when an issue carries no message, never overwriting a\n * baked-in custom/fallback message), input strip, and ZodError construction\n * (zod v4 JSON.stringifies every issue into `message` and captures a stack\n * trace) — stays deferred inside the cached accessor exactly as before, since\n * the issues array is observable solely through `.error`.\n *\n * `input` is `delete`d, not assigned `undefined`. Key PRESENCE is observable —\n * `\"input\" in issue`, `Object.keys(issue)`, object spread, `toStrictEqual`\n * against a zod issue — and zod's `util.finalizeIssue` does `delete full.input`\n * whenever `reportInput` is off, so assignment left every compiled issue one\n * enumerable key wider than zod's. The delete's dictionary-mode transition is\n * affordable precisely BECAUSE of the deferral above: it runs only after a\n * caller asks for `.error` on a failed parse, and is memoised in `_c`. Neither\n * a successful parse nor a `.success`/`.is()` check on a rejected one reaches\n * it — measured, the two are unchanged, while the `.error` read itself goes\n * ~3.95us -> ~4.19us per failure, i.e. ~6% of a path whose cost is already\n * dominated by the ZodError construction on the next line (stack capture plus a\n * JSON.stringify of every issue).\n */\nexport const FAIL_CLASS_DECL =\n \"function __ZcFail(e,f,i){this.success=false;this._e=e;this._f=f;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFail.prototype,\"error\",{configurable:true,get:function(){' +\n \"if(this._c)return this._c;\" +\n \"var e=this._f!==null?this._f(this._i):this._e;\" +\n 'for(var i=0;i<e.length;i++){if(e[i].message===undefined&&typeof __zcMsg===\"function\")e[i].message=__zcMsg(e[i]);delete e[i].input;delete e[i].continue;}' +\n \"return this._c=new __zcZodError(e);}});\";\n\n/** Eager finalizer (mutation / partial-fast-path schemas): issues already\n * collected in `e`; success short-circuits to a plain result literal. */\nexport const FIN_DECL =\n \"function __zcFin(e,d){if(!e.length)return{success:true,data:d};return new __ZcFail(e,null,null);}\";\n\n/**\n * Deferred-collection finalizer for Fast-Path-eligible schemas. When the\n * fast check fails, the ENTIRE slow path (the issue-collecting re-walk) is\n * pushed into the cached `.error` accessor instead of running eagerly:\n * fast-eligible schemas never mutate, so the walk's only output is the\n * issues array, which is observable solely through `.error` — one step\n * further along the same lazy boundary `__zcFin` already established (locale\n * fill, input strip, ZodError construction). A failed safeParse whose\n * `.error` is never read costs the fast check alone.\n *\n * Takes the schema's HOSTED slow-walk function plus the input — NOT a\n * per-call closure: `__zcFinD(__sw_N, input)` allocates only the result\n * object, where `__zcFinD(function(){...})` paid a closure environment and\n * function object per failure. Hosting the walk also shrinks safeParse to\n * two statements, within V8's inlining budget (the success-path result\n * literal becomes escape-analyzable at monomorphic call sites).\n *\n * The walk re-reads `input` at `.error`-read time; a caller that mutates\n * the input between safeParse and reading `.error` sees issues for the\n * mutated value (zod materializes at parse time). Same caveat class as the\n * documented __zcFin deferral.\n */\nexport const FIN_DEFERRED_DECL = \"function __zcFinD(f,inp){return new __ZcFail(null,f,inp);}\";\n\n/**\n * Compact-mode failure class — a lazy failure that delegates error reporting to\n * the ORIGINAL Zod schema's `safeParse`. Used by `output: \"compact\"`, where the\n * compiled slow walk is dropped entirely: a mutation-free schema's fast check\n * is the only generated validation, and on a fast-check failure the cold error\n * path is produced by the retained Zod schema itself (`zod` is the source of\n * truth, so the issues are byte-identical — no second validation engine).\n *\n * `_z` is the schema's PRISTINE safeParse method, captured by\n * emitRetainedMethod (see context.ts), and `_r` is its receiver — the `__zs`\n * binding generateIIFE places above that capture. Both are read before the\n * trailing `__zcMkv` call installs anything, so the method is zod's own\n * implementation, never the compiled delegate, avoiding infinite recursion\n * without allocating a bound function. The zod parse is deferred until `.error`\n * is read and cached, so\n * the common `safeParse(x).success`/`.is(x)` checks on invalid input cost only\n * the fast check (zod never runs) — the same deferral boundary `__zcFinD`\n * establishes for the compiled slow walk. Sound because compact mode is gated\n * on a TOTAL fast path: `fc(input) === false` ⟹ zod rejects, so `success:false`\n * holds without consulting zod.\n *\n * The getter returns zod's OWN ZodError verbatim (no locale fill / input strip /\n * re-wrap — zod already finalized it), so a delegated failure is exactly what\n * the unaltered schema would have produced.\n */\nexport const FAILZ_CLASS_DECL =\n \"function __ZcFailZ(z,r,i){this.success=false;this._z=z;this._r=r;this._i=i;this._c=undefined;}\" +\n 'Object.defineProperty(__ZcFailZ.prototype,\"error\",{configurable:true,get:function(){' +\n \"return this._c||(this._c=this._z.call(this._r,this._i).error);}});\";\n\n/** Compact-mode finalizer: retain a pristine safeParse, its receiver, and input lazily. */\nexport const FINZ_DECL = \"function __zcFinZ(z,r,i){return new __ZcFailZ(z,r,i);}\";\n\n/**\n * Validator factory. Inline mode (CLI emitter) declares it once per compiled\n * file; lean mode (all unplugin bundlers) exports it once per bundle from the\n * plugin-materialized runtime module — generated code never imports it from\n * the zod-compiler package itself, so zod-compiler stays a devDependency and\n * the helper set is always version-locked to the codegen that calls it.\n * Wraps a safeParse function into the CompiledSchema interface.\n *\n * IDENTITY-PRESERVING: with zodCompat (schema != null) the compiled\n * parse/safeParse/parseAsync/safeParseAsync are installed as OWN properties\n * on the original schema object, which is returned as-is. zod v4 keys\n * several APIs on object identity — toJSONSchema's ctx.seen registers the\n * object it is handed while each processor closure captures the original\n * inst (a wrapper crashes `optionalProcessor` with \"Cannot set properties\n * of undefined (setting 'ref')\" the moment a compiled schema is composed\n * into another schema), and globalRegistry/.meta() is a WeakMap keyed by\n * the schema instance (a wrapper silently loses OpenAPI titles/ids). An\n * Object.create wrapper breaks both; mutating the original breaks neither\n * (zod's internal parsing flows through _zod.run, never the public\n * methods, and derived schemas — .optional(), .extend() — are fresh\n * instances that fall back to plain zod). schema=null (zodCompat: false)\n * still produces a plain method-bag object.\n *\n * fc is the schema's hosted fast-check boolean function (null when no Fast\n * Path exists). parse()/parseAsync() try it first and return the input\n * directly on success: fc is small enough for V8 to inline, so the hot parse\n * path runs with zero allocations — calling fn would allocate an intermediate\n * SafeParseResult that escape analysis cannot remove (fn never inlines).\n * Fast-path-eligible schemas never mutate, so fc(input) ⟹ data === input.\n *\n * is is the TOTAL fast-check predicate (fc when the fast path is total, else\n * null). Installed as `.is()` — a zero-allocation boolean type guard. When\n * null (partial fast path or none) `.is()` derives from fn(input).success: a\n * partial fc can pass-through valid input but its `false` does not imply\n * rejection (a default/catch may still succeed), so it would be unsound as a\n * standalone guard.\n *\n * parseAsync/safeParseAsync wrap the SYNC validator, which is right for every\n * schema the compiler can reproduce — none of them are async. It is wrong for\n * the ones it cannot: an `async` refinement or a `z.promise()` extracts to a\n * Zod delegate, and delegating means calling Zod's SYNCHRONOUS safeParse, which\n * raises `$ZodAsyncError` by design. Wrapping that gave the compiled schema an\n * async pair that rejected with `$ZodAsyncError` for EVERY input — including\n * valid ones — where Zod resolves normally, so `await UserSchema.parseAsync(x)`\n * stopped working the moment any part of the schema went async.\n *\n * So both are guarded: a synchronous throw hands off to the schema's ORIGINAL\n * async method, captured before these are installed — the same escape hatch\n * `~standard` already uses for its throw path, and for the same reason (the\n * compiled validator has no async mode to offer, and Zod's is exact). It also\n * fixes the smaller wart that a throwing `fn` made `parseAsync` throw\n * SYNCHRONOUSLY rather than return a rejected promise. With `zodCompat: false`\n * there is no schema to delegate to and the throw propagates as before.\n *\n * `~standard` is REPLACED, not merely preserved. Zod builds it lazily as\n * `validate: (v) => safeParse(inst, v)` — the core FUNCTION, which goes straight\n * to `inst._zod.run`. It never reads the schema's own `safeParse` property, so\n * installing the compiled one leaves this route entirely uncompiled: measured\n * 271.7 ns against the compiled 26.6 ns on the same schema, i.e. Standard Schema\n * consumers (tRPC, Hono, TanStack) were getting plain Zod.\n *\n * Zod's own `~standard` is never READ, only overwritten. Zod installs the slot\n * with `util.defineLazy` — commented there as \"avoid creating objects for every\n * schema\" — so it is an accessor that builds `{version, vendor, validate}` plus\n * its closure on first touch. Reading it to capture a fallback fired that getter\n * for every compiled schema while the module was still initializing.\n *\n * How much that costs depends on the entry point, and only one of them is free:\n * classic `zod` forces the slot itself during `ZodType.init` (it does\n * `Object.assign(inst[\"~standard\"], { jsonSchema })`), so there the read hit an\n * already-built object and cost only an accessor call. `zod/mini` and raw\n * `zod/v4/core` never touch it, so for those the read built — and retained — an\n * object and a closure per schema, purely to capture a fallback the schema will\n * most likely never expose to a Standard Schema consumer.\n *\n * The throw path is rebuilt instead of captured. Zod's validate catches a\n * synchronous throw and retries through `safeParseAsync` — that is how an async\n * refinement resolves and how a throwing check surfaces as a rejected promise\n * rather than a synchronous throw — so calling the already-captured `zspa` and\n * mapping its result is the same route to the same result. `vendor` is likewise\n * a constant: schema discovery only ever admits zod schemas, and classic, mini\n * and core all hardcode `vendor: \"zod\"` themselves.\n *\n * Not carried over (unchanged by this, and pre-dating it): classic's\n * `~standard.jsonSchema` extension, which the replacement object has never\n * reproduced.\n *\n * Installed with defineProperty rather than assignment: Zod's lazy setter\n * redefines the slot as non-writable, so a second `__zcMkv` on the same schema\n * object — two exports aliasing one schema — would throw under ESM strict mode.\n */\nexport const MK_VALIDATOR_DECL =\n \"function __zcMkv(fn,schema,fc,is){var w=schema||{};var zpa=w.parseAsync,zspa=w.safeParseAsync;w.parse=fc?function(input){if(fc(input))return input;var r=fn(input);if(r.success)return r.data;throw r.error;}:function(input){var r=fn(input);if(r.success)return r.data;throw r.error;};w.safeParse=fn;w.safeParseAsync=function(input){try{return Promise.resolve(fn(input));}catch(e){if(zspa)return zspa(input);throw e;}};w.parseAsync=fc?function(input){try{if(fc(input))return Promise.resolve(input);var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}}:function(input){try{var r=fn(input);if(r.success)return Promise.resolve(r.data);return Promise.reject(r.error);}catch(e){if(zpa)return zpa(input);throw e;}};w.is=is||function(input){return fn(input).success;};\" +\n 'Object.defineProperty(w,\"~standard\",{configurable:true,value:{version:1,vendor:\"zod\",validate:function(input){var r;try{if(fc&&fc(input))return{value:input};r=fn(input);}catch(e){if(zspa)return zspa(input).then(function(q){return q.success?{value:q.data}:{issues:q.error.issues};});throw e;}return r.success?{value:r.data}:{issues:r.error.issues};}}});' +\n \"return w;}\";\n\nfunction extractFunctionName(functionDef: string): string {\n const match = /^function\\s+(\\w+)\\s*\\(/.exec(functionDef);\n if (!match?.[1]) {\n throw new Error(\"Cannot extract function name from generated code\");\n }\n return match[1];\n}\n\n/**\n * Does the IIFE's preamble DEREFERENCE the retained schema at evaluation time?\n *\n * Only `__rf` does: every entry is `__zs<accessPath>`, and an access path walks\n * the schema's structure — `._zod.innerType` fires a `z.lazy()` getter,\n * `.shape` materializes a `z.object()` shape (zod v4 reads every property\n * descriptor, so ONE `.shape` read fires ALL of an object's recursion getters).\n * Binding `__zs` itself does not: constructing the schema leaves deferred\n * callbacks unforced, and `usesRetainedSchema`'s only read is `__zs.safeParse`,\n * a prototype getter that binds the method and installs the bound copy on the\n * instance without touching the schema's structure.\n *\n * The distinction decides whether the IIFE may be evaluated inside the\n * INITIALIZER of the binding the schema's own deferred callbacks close over —\n * see the self-referential path in the unplugin's autoDiscover rewrite.\n */\nexport function iifeDerefsSchema(schema: CompiledSchemaInfo): boolean {\n return schema.refEntries.length > 0;\n}\n\n/**\n * Generate a `/* @__PURE__ * /` IIFE wrapping a compiled validator.\n *\n * @param schemaExpr - Expression resolving to the original Zod schema\n * (e.g. `\"UserSchema\"` in unplugin, `\"(__src_X as any).schema\"` in CLI)\n * @param schema\n * @param options - `pure: false` drops the `/* @__PURE__ * /` annotation, for\n * the one caller that emits the IIFE as a STATEMENT following the\n * declaration rather than as its initializer: there the call's whole point is\n * its side effect (`__zcMkv` installing the compiled methods on the schema),\n * and a bundler that believed it pure would drop the compilation outright.\n */\nexport function generateIIFE(\n schemaExpr: string,\n schema: CompiledSchemaInfo,\n options?: { zodCompat?: boolean | undefined; pure?: boolean | undefined },\n): string {\n const { codegenResult, refEntries } = schema;\n const fnName = extractFunctionName(codegenResult.functionDef);\n const zodCompat = options?.zodCompat !== false;\n // Every fallback access starts from the same source schema, and compact\n // delegation names it outright. Capture it once whenever either needs it, so\n // an inline initializer is not reconstructed for each path and again for the\n // identity-preserving __zcMkv target.\n const bindsSchema = refEntries.length > 0 || codegenResult.usesRetainedSchema === true;\n const retainedSchema = bindsSchema ? RETAINED_SCHEMA_VAR : schemaExpr;\n const schemaArg = zodCompat ? retainedSchema : \"null\";\n const fcArg = codegenResult.fastFnName ?? \"null\";\n // `.is()` gets the fast-check directly only when it is a total predicate;\n // partial/none falls back to safeParse().success inside __zcMkv. A rebuilding\n // schema has no by-reference `fc` but still names its predicate separately.\n const isArg = codegenResult.isFnName ?? (codegenResult.fastTotal ? fcArg : \"null\");\n\n return [\n options?.pure === false ? \"(() => {\" : \"/* @__PURE__ */ (() => {\",\n ...(bindsSchema ? [`var ${RETAINED_SCHEMA_VAR}=${schemaExpr};`] : []),\n // Only fallback refs need the array; a compact validator with none of its\n // own reads `__zs` directly rather than allocating `[__zs]` to index into.\n ...(refEntries.length > 0\n ? [`var __rf=[${refEntries.map((fb) => `${retainedSchema}${fb.accessPath}`).join(\",\")}];`]\n : []),\n ...codegenResult.code\n .split(\"\\n\")\n .filter((l) => l.trim() !== \"\" && l.trim() !== \"/* zod-compiler */\"),\n codegenResult.functionDef,\n `return __zcMkv(${fnName},${schemaArg},${fcArg},${isArg});`,\n \"})()\",\n ].join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,oBACX;;;;;;;;;;;;;;;;;;;;AAqBF,MAAa,sBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CF,MAAa,kBACX;;;AASF,MAAa,WACX;;;;;;;;;;;;;;;;;;;;;;;AAwBF,MAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BjC,MAAa,mBACX;;AAKF,MAAa,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FzB,MAAa,oBACX;AAIF,SAAS,oBAAoB,aAA6B;CACxD,MAAM,QAAQ,yBAAyB,KAAK,WAAW;CACvD,IAAI,CAAC,QAAQ,IACX,MAAM,IAAI,MAAM,kDAAkD;CAEpE,OAAO,MAAM;AACf;;;;;;;;;;;;;;;;;AAkBA,SAAgB,iBAAiB,QAAqC;CACpE,OAAO,OAAO,WAAW,SAAS;AACpC;;;;;;;;;;;;;AAcA,SAAgB,aACd,YACA,QACA,SACQ;CACR,MAAM,EAAE,eAAe,eAAe;CACtC,MAAM,SAAS,oBAAoB,cAAc,WAAW;CAC5D,MAAM,YAAY,SAAS,cAAc;CAKzC,MAAM,cAAc,WAAW,SAAS,KAAK,cAAc,uBAAuB;CAClF,MAAM,iBAAiB,cAAc,sBAAsB;CAC3D,MAAM,YAAY,YAAY,iBAAiB;CAC/C,MAAM,QAAQ,cAAc,cAAc;CAI1C,MAAM,QAAQ,cAAc,aAAa,cAAc,YAAY,QAAQ;CAE3E,OAAO;EACL,SAAS,SAAS,QAAQ,aAAa;EACvC,GAAI,cAAc,CAAC,OAAO,oBAAoB,GAAG,WAAW,EAAE,IAAI,CAAC;EAGnE,GAAI,WAAW,SAAS,IACpB,CAAC,aAAa,WAAW,KAAK,OAAO,GAAG,iBAAiB,GAAG,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,IACvF,CAAC;EACL,GAAG,cAAc,KACd,MAAM,IAAI,CAAC,CACX,QAAQ,MAAM,EAAE,KAAK,MAAM,MAAM,EAAE,KAAK,MAAM,oBAAoB;EACrE,cAAc;EACd,kBAAkB,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM;EACxD;CACF,CAAC,CAAC,KAAK,IAAI;AACb"}
@@ -309,12 +309,35 @@ interface ObjectIR {
309
309
  */
310
310
  catchall?: SchemaIR;
311
311
  /**
312
- * Fallback-typed property keys whose zod schema is optional-out: when the
313
- * key is ABSENT from the input, their issues are suppressed (mirrors zod's
314
- * handlePropertyResult). Lets z.exactOptional() and friends fall back at
315
- * the property level without rejecting missing keys.
312
+ * Keys whose zod schema sits on the middle rung of `optin` ("optional") and is
313
+ * optional-out, and whose compiled property could still raise an issue or
314
+ * produce a value when handed `undefined` (a fallback, a union, a pipe). When
315
+ * the key is ABSENT the property is not run at all — zod's
316
+ * handlePropertyResult returns before looking at the result, so nothing it
317
+ * made of `undefined` is reported or kept. The plain `.optional()` property
318
+ * needs no entry: its compiled form already short-circuits `undefined`.
319
+ */
320
+ skipAbsentKeys?: string[];
321
+ /**
322
+ * Keys whose zod schema is "defaulted" (`.default()`, `.prefault()`, a union
323
+ * containing one) AND optional-out, and whose compiled property could raise
324
+ * an issue for `undefined`: when the key is ABSENT the property runs — the
325
+ * substitute must fire — but a failure is swallowed, issues and value alike
326
+ * (mirrors zod's handlePropertyResult). Lets `z.prefault().optional()` and
327
+ * friends fall back at the property level without rejecting missing keys.
316
328
  */
317
329
  suppressAbsentKeys?: string[];
330
+ /**
331
+ * Keys whose zod schema is NOT optional-in (`_zod.optin === undefined`) but
332
+ * whose compiled property might accept `undefined` — `z.any()`, `z.unknown()`,
333
+ * `z.undefined()`, a union with such an option. zod runs the property on the
334
+ * absent key's `undefined` and, when that raised nothing, reports
335
+ * `invalid_type` with `expected: "nonoptional"` at the key: a required key
336
+ * has to be PRESENT, whatever its schema thinks of `undefined`. Keys whose
337
+ * property rejects `undefined` outright are omitted — their own issue
338
+ * already stands in for the absence.
339
+ */
340
+ nonoptionalKeys?: string[];
318
341
  }
319
342
  interface ArrayIR {
320
343
  type: "array";
@@ -326,37 +349,63 @@ interface TupleIR {
326
349
  items: SchemaIR[];
327
350
  rest: SchemaIR | null;
328
351
  /**
329
- * Index where the omittable tail begins — zod's `optStart`, captured from the
330
- * live schemas at extraction time:
352
+ * zod's `optinStart`, captured from the live schemas at extraction time: the
353
+ * index after the last item whose `_zod.optin` is `undefined`.
331
354
  *
332
355
  * ```js
333
- * const reversedIndex = [...items].reverse().findIndex((i) => i._zod.optin !== "optional");
334
- * const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
356
+ * for (let i = items.length - 1; i >= 0; i--) if (items[i]._zod.optin === undefined) return i + 1;
357
+ * return 0;
335
358
  * ```
336
359
  *
337
- * An item at or past this index is SKIPPED ENTIRELY when the input is shorter
338
- * than the tuple — zod never runs its schema, so no default/prefault fires for
339
- * it — and it also moves the under-length `too_small` threshold
340
- * (`input.length < optStart - 1`).
360
+ * Without a rest element an input shorter than this is rejected outright with
361
+ * a single `too_small` (`minimum: optStart`, `inclusive: true`) before any
362
+ * item runs. `optin` is a three-rung ladder — `undefined` (required),
363
+ * `"optional"` (absence permitted, nothing supplied) and `"defaulted"`
364
+ * (absence permitted, a value substituted) — and any rung above `undefined`
365
+ * lets the slot be absent.
341
366
  *
342
367
  * Read from `_zod.optin` rather than inferred from the item's IR type because
343
368
  * "optional-in" is a property of the ZOD schema, not of the shape the compiler
344
- * managed to compile: `z.exactOptional()`, `z.prefault()`, `.nonoptional()`
345
- * and pipes all extract to an opaque `fallback` leaf, `z.undefined()` and
346
- * `z.nullable(z.string().optional())` extract to nodes named nothing like
347
- * "optional", and a union is optional-in when ANY option is. The IR-type
348
- * inference this replaced recognised only `optional` and `default`, so every
349
- * other shape lost its omittable tail — `z.tuple([z.exactOptional(z.string())])`
350
- * rejected `[]` that zod accepts, `z.tuple([z.string().prefault("d")])` turned
351
- * `[]` into `["d"]`, and `z.tuple([z.string(), z.undefined()])` answered a
352
- * one-element input with a `too_small` where zod reports nothing.
369
+ * managed to compile: `z.exactOptional()`, `z.prefault()` and pipes extract to
370
+ * an opaque `fallback` leaf, `z.nullable(z.string().optional())` extracts to a
371
+ * node named nothing like "optional", and a union is optional-in when ANY
372
+ * option is.
353
373
  */
354
374
  optStart: number;
375
+ /**
376
+ * zod's `optoutStart`: the index after the last item whose `_zod.optout` is
377
+ * not `"optional"` — computed like {@link optStart} but over `optout`. Absent
378
+ * only when it equals `items.length` (every slot is required-out).
379
+ *
380
+ * From this index on, an absent slot can END the output: zod's
381
+ * `handleTupleResults` truncates the tail there when the item is on the
382
+ * "optional" rung (see {@link optionalIn}) or when running it on `undefined`
383
+ * failed, and afterwards drops trailing `undefined`s that absent slots
384
+ * produced. Below it an absent slot is materialized as `undefined` (or as
385
+ * whatever the item substituted), because a later required-out slot has to
386
+ * keep its index.
387
+ */
388
+ optoutStart?: number;
389
+ /**
390
+ * Indices whose item sits on the middle rung, `_zod.optin === "optional"`.
391
+ * Absent only when empty. At or past {@link optoutStart} such a slot, when
392
+ * absent, ends the output without running its schema; a "defaulted" slot
393
+ * there runs and keeps what it produced. Below `optoutStart` both run and
394
+ * write their result back.
395
+ */
396
+ optionalIn?: number[];
355
397
  }
356
398
  interface RecordIR {
357
399
  type: "record";
358
400
  keyType: SchemaIR;
359
401
  valueType: SchemaIR;
402
+ /**
403
+ * The key schema declares a finite key set (`_zod.values`), so a key outside
404
+ * it is reported as `unrecognized_keys` — one issue after the walk — rather
405
+ * than `invalid_key`. Only a partial record compiles with one; an exhaustive
406
+ * one, where every declared key must be present, delegates to zod.
407
+ */
408
+ enumerableKeys?: true;
360
409
  }
361
410
  interface SetIR {
362
411
  type: "set";
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/core/types.ts"],"mappings":"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"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/core/types.ts"],"mappings":"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"}
package/dist/jit.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jit.d.ts","names":[],"sources":["../src/jit.ts"],"mappings":";;;UA6EiB;;;;;;;EAOf;;EAEA;;;;;;;;;;;;;;;;;;;;;;;iBAwBc,IAAI,UAAU,SAC5B,QAAQ,GACR,UAAU,aACT,IAAI,eAAe,OAAO;;;;;;;;;;;;;;iBA8Kb,OAAO,iBAAiB,UAAU"}
1
+ {"version":3,"file":"jit.d.ts","names":[],"sources":["../src/jit.ts"],"mappings":";;;UAoFiB;;;;;;;EAOf;;EAEA;;;;;;;;;;;;;;;;;;;;;;;iBAwBc,IAAI,UAAU,SAC5B,QAAQ,GACR,UAAU,aACT,IAAI,eAAe,OAAO;;;;;;;;;;;;;;iBAoNb,OAAO,iBAAiB,UAAU"}