zod-compiler 1.22.5 → 1.23.0

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.
package/README.md CHANGED
@@ -13,11 +13,11 @@ Keep your existing Zod schemas. Get **2-43x faster** validation. No code changes
13
13
 
14
14
  ## Usage
15
15
 
16
- There are three ways to use zod-compiler. Choose the one that fits your project.
16
+ Four ways to use zod-compiler pick one:
17
17
 
18
18
  ### 1. Automatic Mode (Default)
19
19
 
20
- The plugin automatically detects and compiles all exported Zod schemas at build time. No wrappers, no imports from `zod-compiler` in your source code.
20
+ The plugin detects and compiles every exported Zod schema at build time. No wrappers, no imports from `zod-compiler` in your source.
21
21
 
22
22
  **vite.config.ts:**
23
23
 
@@ -42,11 +42,11 @@ export const CreateUserSchema = z.object({
42
42
  });
43
43
  ```
44
44
 
45
- Use them as usual. Compiled methods are installed on the original schema object, so `.shape`, `._zod`,
46
- Standard Schema, `instanceof` and `z.toJSONSchema()` keep working and consumers need no changes.
45
+ Use them as usual. Methods are installed on the original schema object, so `.shape`, `._zod`, Standard
46
+ Schema, `instanceof` and `z.toJSONSchema()` keep working.
47
47
 
48
- Compiled schemas also expose **`.is(input): input is T`** — the compiled check itself, allocating
49
- nothing. A drop-in replacement for `safeParse(x).success`.
48
+ Compiled schemas also expose **`.is(input): input is T`** — a zero-allocation drop-in for
49
+ `safeParse(x).success`.
50
50
 
51
51
  ### 2. compile() (Explicit)
52
52
 
@@ -69,7 +69,7 @@ validateUser.parse(data);
69
69
  validateUser.safeParse(data);
70
70
  ```
71
71
 
72
- `compile()` and auto mode coexist `compile()` schemas are detected first, then every remaining plain Zod export is picked up. To make `compile()` the _only_ path (no automatic detection, no build-time execution of plain schema files), pair it with `schemas: "explicit"` in the plugin options.
72
+ `compile()` and auto mode coexist. Pair with `schemas: "explicit"` to make `compile()` the _only_ path no automatic detection, no build-time execution of plain schema files.
73
73
 
74
74
  ### 3. CLI (No Bundler)
75
75
 
@@ -92,6 +92,27 @@ npx zod-compiler generate src/ --schemas explicit --emit bag
92
92
  npx zod-compiler generate src/ --emit compact
93
93
  ```
94
94
 
95
+ ### 4. Runtime Compilation (No Build Step)
96
+
97
+ `jit()` runs the same pipeline in-process, for `tsx`, `ts-node`, Jest — anywhere no plugin fires:
98
+
99
+ ```typescript
100
+ import { jit } from "zod-compiler/jit";
101
+
102
+ export const UserSchema = jit(z.object({ name: z.string().min(1), email: z.email() }));
103
+ ```
104
+
105
+ Same validators a build emits, installed on the schema object, so Zod interop is unchanged.
106
+ Compilation is lazy — 0.1-0.3 ms on a schema's first parse; `{ eager: true }` compiles up front,
107
+ `jitAll(namespace)` takes a whole module.
108
+
109
+ The cost is the import: ~570 KB of codegen and `acorn`, **~10 ms of module load**. That suits a
110
+ long-lived process, not a CLI, a cold serverless handler or a browser — use the build plugin there.
111
+ Libraries should ship plain Zod and let the app decide.
112
+
113
+ Needs `new Function`, as Zod's own object fast-path does. `z.config({ jitless: true })` and a CSP
114
+ that blocks eval both leave a working plain-Zod schema.
115
+
95
116
  ## Build Plugin
96
117
 
97
118
  ### Supported Build Tools
@@ -148,8 +169,7 @@ export default defineConfig({
148
169
 
149
170
  ### Bun
150
171
 
151
- zod-compiler is a build-time tool, so on Bun it applies wherever your code passes through a build step.
152
- Requires **Bun ≥ 1.2.22**.
172
+ Applies wherever your code passes through a build step. Requires **Bun ≥ 1.2.22**.
153
173
 
154
174
  ```typescript
155
175
  import zodCompiler from "zod-compiler/bun";
@@ -157,7 +177,8 @@ import zodCompiler from "zod-compiler/bun";
157
177
  await Bun.build({ entrypoints: ["./src/index.tsx"], outdir: "./dist", plugins: [zodCompiler()] });
158
178
  ```
159
179
 
160
- For code run straight from source (`bun run src/server.ts`) no build plugin fires — use the
180
+ For code run straight from source (`bun run src/server.ts`) no build plugin fires — use
181
+ [`jit()`](#4-runtime-compilation-no-build-step) to compile in-process, or the
161
182
  [CLI](#3-cli-no-bundler) to compile ahead of time.
162
183
 
163
184
  ### Schema Hoisting
@@ -179,16 +200,14 @@ Only expressions built from imported bindings and literals move; anything touchi
179
200
  `new Date()` stays put. Combinator chains on imported schemas qualify via `schemaNamePattern`
180
201
  (default `/ZodSchema$/`).
181
202
 
182
- In auto mode hoisted schemas also **compile** which rescues the schema that never leaves a function
183
- (a slonik query, a tRPC input), invisible to export scanning. Measured on that pattern: ~16,700 ns →
184
- ~14 ns per call.
203
+ In auto mode hoisted schemas also **compile**, rescuing the schema that never leaves a function (a
204
+ slonik query, a tRPC input) and so is invisible to export scanning: ~16,700 ns → ~14 ns per call.
185
205
 
186
206
  ### Bundle Size & Cross-File Dedup
187
207
 
188
208
  Validators share a runtime helper layer imported from one module, so each helper appears once per
189
- bundle. Schemas in a file sharing a structurally identical sub-shape emit its error walk once, which
190
- scales with how much a file repeats: **19% raw / 10% gzipped** for two exports reusing one nested
191
- shape, **28% / 18%** for four exports reusing two.
209
+ bundle. Schemas in a file sharing a structurally identical sub-shape emit its error walk once
210
+ **19-28% raw / 10-18% gzipped**, scaling with how much the file repeats.
192
211
 
193
212
  **Transpile-only esbuild builds** (no `--bundle`) never fire the bundler's resolve hooks, so the
194
213
  `virtual:` specifier would survive into `dist/` and fail at runtime. Set `codegenMode: "inline"` to emit
@@ -202,8 +221,8 @@ Set `output: "bag"` to also drop the retained Zod schema when you don't need `.s
202
221
 
203
222
  ### SWC
204
223
 
205
- `zod-compiler/swc` is a programmatic `@swc/core` bridge, not a `.swcrc` WASM plugin — discovery needs
206
- Node.js, so it wraps `transform()`. Install `@swc/core`, then:
224
+ A programmatic `@swc/core` bridge wrapping `transform()`, not a `.swcrc` plugin. Install
225
+ `@swc/core`, then:
207
226
 
208
227
  ```typescript
209
228
  import { transform } from "zod-compiler/swc";
@@ -220,13 +239,9 @@ Defaults `codegenMode` to `"inline"` (SWC has no virtual-module hook); pass
220
239
 
221
240
  ### Compact Output (`output: "compact"`)
222
241
 
223
- The error-collecting walk is 64–77% of the generated bytes, and it only reproduces Zod's issues on
224
- failure which the retained Zod schema already does. `output: "compact"` (CLI: `--emit compact`)
225
- compiles the fast path and delegates the cold error path to it.
226
-
227
- On 50 distinct schemas, output drops **~73% raw / ~71% gzipped**. The hot path is unchanged, errors are
228
- Zod's own, and `safeParse(x).success` / `.is(x)` never invoke Zod — only reading `.error` does. Mutation
229
- schemas keep the compiled path. Mutually exclusive with `output: "bag"`.
242
+ Compiles the fast path and delegates the cold error path to the retained Zod schema, dropping
243
+ **~73% raw / ~71% gzipped** on 50 distinct schemas. The hot path is unchanged and errors are Zod's own;
244
+ only reading `.error` invokes Zod. Mutually exclusive with `output: "bag"`.
230
245
 
231
246
  ### Auto Mode: Side Effects Warning
232
247
 
@@ -245,15 +260,8 @@ if (!process.env.ZOD_COMPILER) {
245
260
 
246
261
  With `@t3-oss/env-*`, pass `skipValidation: !!process.env.ZOD_COMPILER`.
247
262
 
248
- ### schemas: "auto" vs "explicit"
249
-
250
- | | `"auto"` (default) | `"explicit"` + compile() |
251
- | ---------------------------- | ---------------------------------------------------------- | ------------------------------------------- |
252
- | Source code changes | None | Wrap each schema |
253
- | `zod-compiler` import needed | No | Yes |
254
- | What gets compiled | All exported Zod schemas | Only wrapped schemas |
255
- | Build-time file execution | Zod-importing files that may export schemas (pre-filtered) | Files with `import ... from "zod-compiler"` |
256
- | Best for | New projects, framework integration | Gradual adoption, selective optimization |
263
+ A schema whose SHAPE branches on an env var is baked at build time, and the cache key does not include
264
+ the environment — give each environment its own `cache` directory if you share one across them.
257
265
 
258
266
  ### Large projects and CI
259
267
 
@@ -267,14 +275,13 @@ expensive one — later runs hit the persistent cache.
267
275
  key: zod-compiler-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
268
276
  ```
269
277
 
270
- Cache entries self-validate against dependency hashes, so a stale cache can only cause recompiles.
271
- Scope discovery with `include`; set `ZOD_COMPILER_TIMING=1` to see per-phase wall time. Files that never
272
- mention `zod` cost nothing.
278
+ Scope discovery with `include`; set `ZOD_COMPILER_TIMING=1` for a per-phase breakdown. Files that
279
+ never mention `zod` cost nothing.
273
280
 
274
281
  ## Framework Examples
275
282
 
276
- Nothing framework-specific is needed. In auto mode your exported schemas are compiled in place, so
277
- anything that accepts a Zod schema keeps working and picks up the compiled version:
283
+ Nothing framework-specific is needed exported schemas are compiled in place, so anything accepting
284
+ a Zod schema picks up the compiled version:
278
285
 
279
286
  ```typescript
280
287
  // tRPC — no .input(compile(...)) needed
@@ -287,14 +294,15 @@ app.post("/users", zValidator("json", UserSchema), (c) => c.json(c.req.valid("js
287
294
  useForm({ resolver: zodResolver(SignupSchema) });
288
295
  ```
289
296
 
290
- The same applies to any [Standard Schema](https://standardschema.dev) consumer. `~standard.validate`
291
- is re-installed on top of the compiled path — Zod's own builds it around its internal parse, so
292
- leaving it alone would have handed these consumers plain Zod. Its `version`/`vendor` are unchanged,
293
- and an async refinement still resolves through Zod.
297
+ The same applies to any [Standard Schema](https://standardschema.dev) consumer `~standard.validate`
298
+ routes through the compiled validator.
299
+
300
+ Compiled methods live on the schema object, so Zod's functional API (`z.safeParse(Schema, x)`) and a
301
+ compiled schema composed into an uncompiled parent stay on plain Zod.
294
302
 
295
303
  ## Schema Diagnostics
296
304
 
297
- Analyze your schemas before compiling — check coverage, Fast Path eligibility, and get actionable hints:
305
+ Check coverage and Fast Path eligibility before compiling:
298
306
 
299
307
  ```bash
300
308
  npx zod-compiler check src/schemas.ts
@@ -374,16 +382,18 @@ see what compiled.
374
382
  ### Behavioral Differences from Zod
375
383
 
376
384
  Compiled validators match Zod on verdicts, output data and error messages, including issue ordering.
377
- Two things differ by design, both from the zero-allocation fast path:
385
+ Three things differ by design:
386
+
387
+ | Behavior | Zod | zod-compiler |
388
+ | ------------------------- | ----------------------------------------------- | ------------------------------------------------------- |
389
+ | Record key iteration | All own keys (`Reflect.ownKeys`) | Own enumerable **string** keys only |
390
+ | Container output identity | A fresh array / set / map / object | The input container, by reference (array holes survive) |
391
+ | Per-call parse params | `safeParse(x, { error, reportInput })` honoured | Ignored; global `z.config()` maps still apply |
378
392
 
379
- | Behavior | Zod | zod-compiler |
380
- | ------------------------- | ---------------------------------- | ------------------------------------------------------- |
381
- | Record key iteration | All own keys (`Reflect.ownKeys`) | Own enumerable **string** keys only |
382
- | Container output identity | A fresh array / set / map / object | The input container, by reference (array holes survive) |
393
+ Schema-level `error` and `z.config()` maps are unaffected; for a per-call map use
394
+ `z.safeParse(Schema, x, params)`.
383
395
 
384
- A container whose contents need no rewriting is validated in place and handed back, where Zod always
385
- rebuilds it. `z.object()` is the exception — it strips unknown keys exactly as Zod does, so its output
386
- is always a fresh object.
396
+ `z.object()` strips unknown keys exactly as Zod does, so its output is always a fresh object.
387
397
 
388
398
  ## Benchmark
389
399
 
@@ -441,9 +451,8 @@ pnpm benchmark # run locally
441
451
  An eligible schema compiles to a **fast path** — one `&&` chain validating the whole input with zero
442
452
  allocations, reused by `.is()` and `parse()` — plus a **slow path** that collects errors, run only on
443
453
  failure and deferred until `.error` is read. A `z.object()` strips, so it instead compiles to a single
444
- pass that validates and rebuilds together, bailing on the first failure. That pass also covers the
445
- idioms that reshape a value — array size checks, `.refine()`, `.default()`, `.trim()`, `.transform()`
446
- so one of them in a schema no longer costs it the whole single-pass parse.
454
+ pass that validates and rebuilds together, bailing on the first failure including the reshaping
455
+ idioms (array size checks, `.refine()`, `.default()`, `.trim()`, `.transform()`).
447
456
 
448
457
  Regexes are pre-compiled with bounded repeats unrolled, checks run cheapest-first, discriminated unions
449
458
  dispatch through a jump table (plain tagged unions are auto-discriminated into it), and oversized check
@@ -11,8 +11,26 @@ import type { CompiledSchemaInfo } from "./pipeline.js";
11
11
  * parse raises (see ZC_SR_DECL).
12
12
  */
13
13
  export declare const ZOD_CONFIG_IMPORT = "import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from \"zod\";";
14
- /** File-level __zcMsg declaration (must appear once after ZOD_CONFIG_IMPORT). */
15
- export declare const ZOD_MSG_DECLARATION = "var __zcMsg=__zodCompilerConfig().localeError;";
14
+ /**
15
+ * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):
16
+ * the message an issue gets when nothing was baked into it at build time.
17
+ *
18
+ * Resolves zod's tail of `finalizeIssue` — `config.customError` then
19
+ * `config.localeError` then "Invalid input" — and does it PER CALL, because the
20
+ * config is mutable: `z.config({ localeError })` in an entry point runs after
21
+ * the schema modules it imports, so a value snapshotted at module init misses
22
+ * it. Reading a captured `localeError` alone also dropped `customError`
23
+ * outright, silently ignoring the global map most i18n setups install.
24
+ *
25
+ * The head of zod's chain — the schema's own `error` option — is baked into the
26
+ * issue at build time and short-circuits this. The one link that cannot be
27
+ * reproduced is a per-CALL `ctx.error`, which would have to travel through
28
+ * `safeParse`; that entry point sits at V8's inlining budget, where even an
29
+ * unused extra parameter measured ~12% on every parse.
30
+ *
31
+ * Only ever called while building an error, never on a successful parse.
32
+ */
33
+ export declare const ZOD_MSG_DECLARATION: string;
16
34
  /**
17
35
  * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)
18
36
  * declares it once per compiled file; lean mode (all unplugin bundlers) declares
@@ -1 +1 @@
1
- {"version":3,"file":"iife.d.ts","sourceRoot":"","sources":["../../src/core/iife.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,2GAC0E,CAAC;AAEzG,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,mDAAmD,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,QAMe,CAAC;AAE5C;yEACyE;AACzE,eAAO,MAAM,QAAQ,sGACgF,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,iBAAiB,+DAA+D,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,QAG4B,CAAC;AAE1D,qGAAqG;AAC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CAAA;CAAE,GAC5C,MAAM,CAuBR"}
package/dist/core/iife.js CHANGED
@@ -10,8 +10,30 @@
10
10
  * parse raises (see ZC_SR_DECL).
11
11
  */
12
12
  export const ZOD_CONFIG_IMPORT = 'import { config as __zodCompilerConfig, core as __zcCore, ZodRealError as __zcZodError } from "zod";';
13
- /** File-level __zcMsg declaration (must appear once after ZOD_CONFIG_IMPORT). */
14
- export const ZOD_MSG_DECLARATION = "var __zcMsg=__zodCompilerConfig().localeError;";
13
+ /**
14
+ * File-level `__zcMsg` declaration (must appear once after ZOD_CONFIG_IMPORT):
15
+ * the message an issue gets when nothing was baked into it at build time.
16
+ *
17
+ * Resolves zod's tail of `finalizeIssue` — `config.customError` then
18
+ * `config.localeError` then "Invalid input" — and does it PER CALL, because the
19
+ * config is mutable: `z.config({ localeError })` in an entry point runs after
20
+ * the schema modules it imports, so a value snapshotted at module init misses
21
+ * it. Reading a captured `localeError` alone also dropped `customError`
22
+ * outright, silently ignoring the global map most i18n setups install.
23
+ *
24
+ * The head of zod's chain — the schema's own `error` option — is baked into the
25
+ * issue at build time and short-circuits this. The one link that cannot be
26
+ * reproduced is a per-CALL `ctx.error`, which would have to travel through
27
+ * `safeParse`; that entry point sits at V8's inlining budget, where even an
28
+ * unused extra parameter measured ~12% on every parse.
29
+ *
30
+ * Only ever called while building an error, never on a successful parse.
31
+ */
32
+ export const ZOD_MSG_DECLARATION = 'function __zcUw(m){return typeof m==="string"?m:(m===undefined||m===null?undefined:m.message);}' +
33
+ "var __zcMsg=function(iss){var c=__zodCompilerConfig(),m;" +
34
+ "if(c.customError){m=__zcUw(c.customError(iss));if(m!==undefined&&m!==null)return m;}" +
35
+ "if(c.localeError){m=__zcUw(c.localeError(iss));if(m!==undefined&&m!==null)return m;}" +
36
+ 'return "Invalid input";};';
15
37
  /**
16
38
  * Shared failure-result for __zcFin / __zcFinD. Inline mode (CLI emitter)
17
39
  * declares it once per compiled file; lean mode (all unplugin bundlers) declares
@@ -1 +1 @@
1
-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@@ -0,0 +1,78 @@
1
+ /**
2
+ * Runtime compilation — the same extract → codegen pipeline the build plugin
3
+ * runs, executed in-process and evaluated through `new Function`.
4
+ *
5
+ * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
6
+ * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
7
+ * suite, a serverless handler bundled by someone else's toolchain, a library
8
+ * that ships schemas to consumers. There `compile()` is a no-op and every parse
9
+ * runs plain Zod. `jit()` closes that gap — one call, no build integration,
10
+ * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
11
+ *
12
+ * Nothing here re-implements validation: {@link compileSchemas} and
13
+ * {@link generateIIFE} are the exact modules the plugin and CLI use, so the
14
+ * generated validator, its Zod parity and its performance are identical to what
15
+ * a build would have emitted. The only difference is *when* the code is
16
+ * produced.
17
+ *
18
+ * Compilation is LAZY by default: `jit()` installs accessors that compile on
19
+ * the first read of a parse method and replace themselves with the compiled
20
+ * ones. Importing a module of 500 schemas therefore costs nothing, and a
21
+ * serverless invocation touching three of them pays for three.
22
+ *
23
+ * Runtime code generation is not always permitted — a strict CSP without
24
+ * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
25
+ * fast-pass is itself a `new Function`) and already exposes the two switches
26
+ * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
27
+ * `jit()` honours both and degrades to plain Zod, so one setting governs both
28
+ * compilers. Those targets are where the build plugin belongs anyway — it emits
29
+ * the same validator with no runtime evaluation at all.
30
+ */
31
+ import { type output, type ZodType } from "zod";
32
+ import type { CompiledSchema } from "./core/types.js";
33
+ export interface JitOptions {
34
+ /**
35
+ * Compile immediately instead of on first use. Costs ~0.1-0.2 ms per schema
36
+ * at import time; useful for a long-lived server that would rather pay during
37
+ * startup than on the first request, or to surface a compilation failure
38
+ * eagerly. Default `false`.
39
+ */
40
+ eager?: boolean | undefined;
41
+ }
42
+ /**
43
+ * Compile `schema` in-process and install the compiled `parse` / `safeParse` /
44
+ * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.
45
+ *
46
+ * Returns the SAME object — identity-preserving exactly as the build plugin is,
47
+ * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and
48
+ * composition into a larger schema all keep working, and every existing
49
+ * reference to the schema picks the compiled methods up.
50
+ *
51
+ * ```ts
52
+ * import { z } from "zod";
53
+ * import { jit } from "zod-compiler/jit";
54
+ *
55
+ * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));
56
+ * UserSchema.safeParse(input); // compiled on this first call
57
+ * ```
58
+ *
59
+ * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the
60
+ * same way they do at build time; a schema that cannot be compiled at all is
61
+ * left as plain Zod.
62
+ */
63
+ export declare function jit<T extends ZodType>(schema: T, options?: JitOptions): T & CompiledSchema<output<T>>;
64
+ /**
65
+ * Compile every Zod schema found among an object's own values — typically a
66
+ * module namespace, so a whole schema file opts in with one call:
67
+ *
68
+ * ```ts
69
+ * import * as schemas from "./schemas.js";
70
+ * jitAll(schemas);
71
+ * ```
72
+ *
73
+ * The namespace object itself is never written to (a module namespace is
74
+ * read-only); `jit()` mutates the schema objects it holds, which is what every
75
+ * importer of that module already references.
76
+ */
77
+ export declare function jitAll(schemas: object, options?: JitOptions): void;
78
+ //# sourceMappingURL=jit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jit.d.ts","sourceRoot":"","sources":["../src/jit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAsD,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAYpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAiCtD,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,OAAO,EACnC,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,UAAU,GACnB,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAoD/B;AA0CD;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAIlE"}
package/dist/jit.js ADDED
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Runtime compilation — the same extract → codegen pipeline the build plugin
3
+ * runs, executed in-process and evaluated through `new Function`.
4
+ *
5
+ * The AOT paths (unplugin, CLI) need a build step to fire. Plenty of everyday
6
+ * code has none: `tsx server.ts`, `node --experimental-strip-types`, a Jest
7
+ * suite, a serverless handler bundled by someone else's toolchain, a library
8
+ * that ships schemas to consumers. There `compile()` is a no-op and every parse
9
+ * runs plain Zod. `jit()` closes that gap — one call, no build integration,
10
+ * measured 3-25x on everyday schemas at ~0.1-0.2 ms of one-time compilation.
11
+ *
12
+ * Nothing here re-implements validation: {@link compileSchemas} and
13
+ * {@link generateIIFE} are the exact modules the plugin and CLI use, so the
14
+ * generated validator, its Zod parity and its performance are identical to what
15
+ * a build would have emitted. The only difference is *when* the code is
16
+ * produced.
17
+ *
18
+ * Compilation is LAZY by default: `jit()` installs accessors that compile on
19
+ * the first read of a parse method and replace themselves with the compiled
20
+ * ones. Importing a module of 500 schemas therefore costs nothing, and a
21
+ * serverless invocation touching three of them pays for three.
22
+ *
23
+ * Runtime code generation is not always permitted — a strict CSP without
24
+ * `unsafe-eval`, some edge runtimes. Zod v4 has the same constraint (its object
25
+ * fast-pass is itself a `new Function`) and already exposes the two switches
26
+ * for it: the `core.util.allowsEval` probe and `z.config({ jitless: true })`.
27
+ * `jit()` honours both and degrades to plain Zod, so one setting governs both
28
+ * compilers. Those targets are where the build plugin belongs anyway — it emits
29
+ * the same validator with no runtime evaluation at all.
30
+ */
31
+ import { config as zodConfig, core as zodCore, ZodRealError } from "zod";
32
+ import { FAIL_CLASS_DECL, FAILZ_CLASS_DECL, FIN_DECL, FIN_DEFERRED_DECL, FINZ_DECL, generateIIFE, MK_VALIDATOR_DECL, ZOD_MSG_DECLARATION, } from "./core/iife.js";
33
+ import { compileSchemas } from "./core/pipeline.js";
34
+ /**
35
+ * The declarations `ZOD_CONFIG_IMPORT` supplies to an emitted module, minus the
36
+ * import itself — `zod`'s three bindings arrive as parameters instead, so the
37
+ * evaluated code has no module scope to resolve. Byte-for-byte the same helper
38
+ * source the CLI emitter writes into a `.compiled.ts`, so a JIT validator and
39
+ * an AOT one share their entire runtime layer.
40
+ */
41
+ const RUNTIME_PRELUDE = [
42
+ ZOD_MSG_DECLARATION,
43
+ FAIL_CLASS_DECL,
44
+ MK_VALIDATOR_DECL,
45
+ FIN_DECL,
46
+ FIN_DEFERRED_DECL,
47
+ FAILZ_CLASS_DECL,
48
+ FINZ_DECL,
49
+ ].join("\n");
50
+ /**
51
+ * Methods `__zcMkv` installs. Each is fronted by a compile-on-read accessor
52
+ * until the schema materializes.
53
+ *
54
+ * `~standard` earns its place: Zod builds it as a closure over `_zod.run`, not
55
+ * over the schema's `safeParse` property, so a Standard Schema consumer (tRPC,
56
+ * Hono, TanStack Form) that never touches `safeParse` would otherwise keep
57
+ * running plain Zod forever behind a "compiled" schema.
58
+ */
59
+ const SLOTS = ["parse", "safeParse", "parseAsync", "safeParseAsync", "is", "~standard"];
60
+ /** Schemas already handed to `jit()`, so a second call is a no-op rather than a recompile. */
61
+ const seen = new WeakSet();
62
+ /**
63
+ * Compile `schema` in-process and install the compiled `parse` / `safeParse` /
64
+ * `parseAsync` / `safeParseAsync` / `is` / `~standard` on it.
65
+ *
66
+ * Returns the SAME object — identity-preserving exactly as the build plugin is,
67
+ * so `.shape`, `_zod`, `instanceof`, `z.toJSONSchema()`, `.meta()` and
68
+ * composition into a larger schema all keep working, and every existing
69
+ * reference to the schema picks the compiled methods up.
70
+ *
71
+ * ```ts
72
+ * import { z } from "zod";
73
+ * import { jit } from "zod-compiler/jit";
74
+ *
75
+ * export const UserSchema = jit(z.object({ name: z.string(), email: z.email() }));
76
+ * UserSchema.safeParse(input); // compiled on this first call
77
+ * ```
78
+ *
79
+ * Schemas the compiler cannot reproduce fall back to Zod per sub-schema, the
80
+ * same way they do at build time; a schema that cannot be compiled at all is
81
+ * left as plain Zod.
82
+ */
83
+ export function jit(schema, options) {
84
+ const target = schema;
85
+ if (seen.has(target))
86
+ return schema;
87
+ seen.add(target);
88
+ if (options?.eager === true) {
89
+ materialize(schema);
90
+ return schema;
91
+ }
92
+ // Snapshot Zod's own descriptors first: materialize() restores them before
93
+ // handing the object to `__zcMkv`, so the generated code sees a pristine
94
+ // schema — it captures `~standard`'s original `validate` as its throw path,
95
+ // and capturing a stub there would loop back into itself.
96
+ const original = new Map();
97
+ for (const slot of SLOTS) {
98
+ original.set(slot, Object.getOwnPropertyDescriptor(target, slot));
99
+ }
100
+ // Installing the accessors is the one step that can throw rather than degrade:
101
+ // a slot locked non-configurable (a future Zod, another wrapper) makes
102
+ // defineProperty raise, and `jit()` is called at module scope — so an
103
+ // unhandled throw here takes down the importing app at boot. Roll back to
104
+ // whatever Zod had and leave the schema alone instead.
105
+ let pending = true;
106
+ try {
107
+ installAccessors(target, original, () => {
108
+ if (!pending)
109
+ return;
110
+ pending = false;
111
+ restore(target, original);
112
+ materialize(schema);
113
+ }, () => {
114
+ if (!pending)
115
+ return;
116
+ pending = false;
117
+ // Restore EVERY slot, not just the one being written. A left-behind
118
+ // accessor whose trigger has been cancelled would read `target[slot]`
119
+ // and re-enter itself — unbounded recursion. This is the path the build
120
+ // plugin takes when a file uses `jit()` too: `__zcMkv` assigns the parse
121
+ // methods (cancelling here) and then reads `~standard`.
122
+ restore(target, original);
123
+ });
124
+ }
125
+ catch {
126
+ pending = false;
127
+ restore(target, original);
128
+ }
129
+ return schema;
130
+ }
131
+ /**
132
+ * Front every installed method with a compile-on-read accessor. `trigger`
133
+ * materializes the schema, which replaces these accessors with the compiled
134
+ * methods (or restores Zod's own), so the read that follows never re-enters.
135
+ */
136
+ function installAccessors(target, original, trigger, cancel) {
137
+ for (const slot of SLOTS) {
138
+ Object.defineProperty(target, slot, {
139
+ configurable: true,
140
+ // Preserve Zod's own visibility: parse/safeParse/... are enumerable own
141
+ // properties, `~standard` is not. `is` does not exist on a Zod schema, so
142
+ // it follows the non-enumerable convention `compile()` already uses.
143
+ enumerable: original.get(slot)?.enumerable ?? false,
144
+ get() {
145
+ trigger();
146
+ // Whatever now occupies the slot: the compiled method, or — if
147
+ // compilation was impossible — Zod's own, put back by restore().
148
+ return target[slot];
149
+ },
150
+ set(value) {
151
+ // Someone overwrote a method before first use (a test double, another
152
+ // wrapper). Their value wins, and compilation is cancelled outright —
153
+ // materializing later would restore Zod's descriptors over it.
154
+ cancel();
155
+ Object.defineProperty(target, slot, {
156
+ configurable: true,
157
+ enumerable: original.get(slot)?.enumerable ?? false,
158
+ value,
159
+ writable: true,
160
+ });
161
+ },
162
+ });
163
+ }
164
+ }
165
+ /**
166
+ * Compile every Zod schema found among an object's own values — typically a
167
+ * module namespace, so a whole schema file opts in with one call:
168
+ *
169
+ * ```ts
170
+ * import * as schemas from "./schemas.js";
171
+ * jitAll(schemas);
172
+ * ```
173
+ *
174
+ * The namespace object itself is never written to (a module namespace is
175
+ * read-only); `jit()` mutates the schema objects it holds, which is what every
176
+ * importer of that module already references.
177
+ */
178
+ export function jitAll(schemas, options) {
179
+ for (const value of Object.values(schemas)) {
180
+ if (isZodSchema(value))
181
+ jit(value, options);
182
+ }
183
+ }
184
+ /** Zod schemas carry `_zod.def`; the same probe auto-discovery uses at build time. */
185
+ function isZodSchema(value) {
186
+ if (typeof value !== "object" || value === null || !("_zod" in value))
187
+ return false;
188
+ const internal = value["_zod"];
189
+ return typeof internal === "object" && internal !== null && "def" in internal;
190
+ }
191
+ /** Put Zod's own descriptors back, dropping the compile-on-read accessors. */
192
+ function restore(target, original) {
193
+ for (const slot of SLOTS) {
194
+ const descriptor = original.get(slot);
195
+ if (descriptor === undefined)
196
+ delete target[slot];
197
+ else
198
+ Object.defineProperty(target, slot, descriptor);
199
+ }
200
+ }
201
+ /**
202
+ * Whether runtime code generation is permitted here. Read per call, never
203
+ * snapshotted: `z.config({ jitless: true })` runs in an entry point, after the
204
+ * schema modules it imports have already been evaluated.
205
+ */
206
+ function codegenAllowed() {
207
+ return zodCore.globalConfig.jitless !== true && zodCore.util.allowsEval.value;
208
+ }
209
+ /**
210
+ * Run the pipeline and let the generated IIFE install its methods on `schema`.
211
+ * Swallows failure: a schema that cannot be compiled keeps Zod's own methods,
212
+ * which the caller already has, so there is nothing to report and nothing to
213
+ * break.
214
+ */
215
+ function materialize(schema) {
216
+ if (!codegenAllowed())
217
+ return;
218
+ try {
219
+ buildValidator(schema);
220
+ }
221
+ catch {
222
+ // Left as plain Zod. Deliberately silent: `jit()` is an optimization, and a
223
+ // schema using a construct the compiler declines is a supported outcome,
224
+ // not an error.
225
+ }
226
+ }
227
+ /**
228
+ * Generate the validator and evaluate it, reproducing the module a
229
+ * `.compiled.ts` would have been: helper preamble, the file-level shared block,
230
+ * then the `__zcMkv` IIFE whose `__rf[]` bases and install target are the live
231
+ * schema object passed in as `__schema`.
232
+ */
233
+ function buildValidator(schema) {
234
+ const { schemas, shared } = compileSchemas([{ exportName: "jit", schema }], { mode: "inline" });
235
+ const compiled = schemas[0];
236
+ if (compiled === undefined)
237
+ throw new Error("zod-compiler: schema produced no validator");
238
+ const body = [RUNTIME_PRELUDE, shared.code, `return ${generateIIFE("__schema", compiled)};`].join("\n");
239
+ // The three bindings ZOD_CONFIG_IMPORT would have imported, passed in so the
240
+ // evaluated code needs no module resolution of its own.
241
+ // oxlint-disable-next-line no-new-func -- generating the validator IS the feature
242
+ const factory = new Function("__zodCompilerConfig", "__zcCore", "__zcZodError", "__schema", body);
243
+ factory(zodConfig, zodCore, ZodRealError, schema);
244
+ }
245
+ //# sourceMappingURL=jit.js.map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,EACrB,UAAU,EACV,cAAc,EACd,UAAU,EACV,IAAI,CAMM,CAAC;IAEb,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-compiler",
3
- "version": "1.22.5",
3
+ "version": "1.23.0",
4
4
  "description": "Compile Zod schemas into zero-overhead validation functions",
5
5
  "keywords": [
6
6
  "aot",
@@ -32,6 +32,12 @@
32
32
  "import": "./dist/index.js",
33
33
  "default": "./dist/index.js"
34
34
  },
35
+ "./jit": {
36
+ "types": "./dist/jit.d.ts",
37
+ "source": "./src/jit.ts",
38
+ "import": "./dist/jit.js",
39
+ "default": "./dist/jit.js"
40
+ },
35
41
  "./vite": {
36
42
  "types": "./dist/unplugin/vite.d.ts",
37
43
  "source": "./src/unplugin/vite.ts",