zod-compiler 1.0.18 → 1.2.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 +134 -66
- package/dist/cli/commands/check.js +3 -3
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/index.js +40 -18
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/logger.js +2 -2
- package/dist/cli/logger.js.map +1 -1
- package/dist/core/codegen/context.d.ts +1 -10
- package/dist/core/codegen/context.d.ts.map +1 -1
- package/dist/core/codegen/context.js +0 -40
- package/dist/core/codegen/context.js.map +1 -1
- package/dist/core/codegen/fast-path.js +1 -1
- package/dist/core/codegen/fast-path.js.map +1 -1
- package/dist/core/codegen/issue-decls.d.ts +0 -10
- package/dist/core/codegen/issue-decls.d.ts.map +1 -1
- package/dist/core/codegen/issue-decls.js +8 -10
- package/dist/core/codegen/issue-decls.js.map +1 -1
- package/dist/core/codegen/slow-path.js +1 -1
- package/dist/core/codegen/slow-path.js.map +1 -1
- package/dist/core/extract/checks.d.ts +0 -2
- package/dist/core/extract/checks.d.ts.map +1 -1
- package/dist/core/extract/checks.js +1 -1
- package/dist/core/extract/checks.js.map +1 -1
- package/dist/unplugin/dep-graph.d.ts.map +1 -1
- package/dist/unplugin/dep-graph.js +13 -6
- package/dist/unplugin/dep-graph.js.map +1 -1
- package/dist/unplugin/hoist.d.ts.map +1 -1
- package/dist/unplugin/hoist.js.map +1 -1
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +8 -4
- package/dist/unplugin/index.js.map +1 -1
- package/dist/unplugin/transform.js +2 -2
- package/dist/unplugin/transform.js.map +1 -1
- package/dist/unplugin/types.d.ts +32 -18
- package/dist/unplugin/types.d.ts.map +1 -1
- package/package.json +17 -7
- package/dist/core/extract/extractors/index.d.ts +0 -32
- package/dist/core/extract/extractors/index.d.ts.map +0 -1
- package/dist/core/extract/extractors/index.js +0 -32
- package/dist/core/extract/extractors/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,45 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
Keep your existing Zod schemas. Get **2-74x faster** validation. No code changes required.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default defineConfig({
|
|
11
|
-
plugins: [zodCompiler({ autoDiscover: true })],
|
|
12
|
-
});
|
|
13
|
-
```
|
|
7
|
+
- [What Gets Compiled](#what-gets-compiled)
|
|
8
|
+
- [Schema Hoisting](#schema-hoisting)
|
|
9
|
+
- [Benchmark](#benchmark)
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
|
|
19
|
-
export const UserSchema = z.object({
|
|
20
|
-
name: z.string().min(3),
|
|
21
|
-
email: z.email(),
|
|
22
|
-
age: z.number().int().positive(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// Use it anywhere — tRPC, Hono, React Hook Form, etc.
|
|
26
|
-
// At build time, zod-compiler compiles it to a 2-74x faster validator.
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install zod-compiler zod@^4
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
| Runtime | Version |
|
|
36
|
-
| ------- | ------- |
|
|
37
|
-
| Node.js | 20+ |
|
|
38
|
-
| Bun | 1.3+ |
|
|
39
|
-
| Deno | 2.0+ |
|
|
11
|
+
> [!NOTE]
|
|
12
|
+
> zod-compiler has been tested to work in large projects with tens of thousands of Zod schemas.
|
|
40
13
|
|
|
41
14
|
## Usage
|
|
42
15
|
|
|
43
16
|
There are three ways to use zod-compiler. Choose the one that fits your project.
|
|
44
17
|
|
|
45
|
-
### 1.
|
|
18
|
+
### 1. Automatic Mode (Default)
|
|
46
19
|
|
|
47
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.
|
|
48
21
|
|
|
@@ -52,7 +25,7 @@ The plugin automatically detects and compiles all exported Zod schemas at build
|
|
|
52
25
|
import zodCompiler from "zod-compiler/vite";
|
|
53
26
|
|
|
54
27
|
export default defineConfig({
|
|
55
|
-
plugins: [zodCompiler(
|
|
28
|
+
plugins: [zodCompiler()],
|
|
56
29
|
});
|
|
57
30
|
```
|
|
58
31
|
|
|
@@ -118,7 +91,7 @@ validateUser.parse(data);
|
|
|
118
91
|
validateUser.safeParse(data);
|
|
119
92
|
```
|
|
120
93
|
|
|
121
|
-
`compile()` and
|
|
94
|
+
`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.
|
|
122
95
|
|
|
123
96
|
### 3. CLI (No Bundler)
|
|
124
97
|
|
|
@@ -133,6 +106,9 @@ npx zod-compiler generate src/ -o src/compiled/
|
|
|
133
106
|
|
|
134
107
|
# Watch mode
|
|
135
108
|
npx zod-compiler generate src/ --watch
|
|
109
|
+
|
|
110
|
+
# Only compile() calls (skip plain exports); minimal methods-only output
|
|
111
|
+
npx zod-compiler generate src/ --schemas explicit --emit bag
|
|
136
112
|
```
|
|
137
113
|
|
|
138
114
|
## Build Plugin
|
|
@@ -152,20 +128,19 @@ npx zod-compiler generate src/ --watch
|
|
|
152
128
|
|
|
153
129
|
### Options
|
|
154
130
|
|
|
155
|
-
| Option
|
|
156
|
-
|
|
|
157
|
-
| `
|
|
158
|
-
| `include`
|
|
159
|
-
| `exclude`
|
|
160
|
-
| `
|
|
161
|
-
| `verbose`
|
|
162
|
-
| `hoist`
|
|
163
|
-
| `apply`
|
|
164
|
-
| `cache`
|
|
131
|
+
| Option | Type | Default | Description |
|
|
132
|
+
| --------- | ----------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `schemas` | `"auto" \| "explicit"` | `"auto"` | How schemas are found. `"auto"`: every exported Zod schema compiles (also enables compiling hoisted in-function schemas). `"explicit"`: only `compile()`-wrapped schemas; only files importing zod-compiler execute at build time |
|
|
134
|
+
| `include` | `string[]` | — | Only process files matching these path globs (picomatch, matched anywhere in the path; plain substrings work too) |
|
|
135
|
+
| `exclude` | `string[]` | — | Skip files matching these path globs (same matching rules as `include`) |
|
|
136
|
+
| `output` | `"schema" \| "bag"` | `"schema"` | What a compiled export evaluates to. `"schema"`: the original Zod schema with compiled methods installed (full API preserved). `"bag"`: a minimal methods-only object — smaller bundles, breaks Zod-schema consumers |
|
|
137
|
+
| `verbose` | `boolean` | `false` | Log per-schema compilation status during build |
|
|
138
|
+
| `hoist` | `boolean` | `true` | Hoist Zod schemas defined inside function bodies to module scope so they're constructed once instead of per call (babel-plugin-zod-hoist equivalent). Only expressions built purely from imports and literals are hoisted |
|
|
139
|
+
| `apply` | `"build" \| "serve" \| "all"` | builds + Vitest | **Vite only**: when the plugin runs. By default, production builds and test runs are compiled (so tests exercise what ships); plain dev servers use the Zod fallback. `"all"` also compiles the dev server; `"build"` also skips tests |
|
|
140
|
+
| `cache` | `boolean \| string` | `true` | Persistent transform cache (`node_modules/.cache/zod-compiler`, or a custom directory). Skips discovery + codegen across processes when nothing changed; entries self-validate against dependency content hashes |
|
|
165
141
|
|
|
166
142
|
```typescript
|
|
167
143
|
zodCompiler({
|
|
168
|
-
autoDiscover: true,
|
|
169
144
|
include: ["src/schemas"],
|
|
170
145
|
verbose: true,
|
|
171
146
|
});
|
|
@@ -210,6 +185,91 @@ Combinator chains on imported schemas also qualify: bases matching
|
|
|
210
185
|
`z.*` reference (`Base.extend({ a: z.string() })`). Configure via
|
|
211
186
|
`hoist: { schemaNamePattern: /Shape$/ }` (string and `null` accepted).
|
|
212
187
|
|
|
188
|
+
#### Hoisted schemas compile too (auto mode)
|
|
189
|
+
|
|
190
|
+
The most common shape this rescues is a schema that never leaves a function —
|
|
191
|
+
a [slonik](https://github.com/gajus/slonik) query, a tRPC input, a handler-local
|
|
192
|
+
validator. It is not exported, so export scanning alone would never see it:
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { pool, sql } from "./db.js";
|
|
196
|
+
import { z } from "zod";
|
|
197
|
+
|
|
198
|
+
const getUser = (id: number) => {
|
|
199
|
+
return pool.one(
|
|
200
|
+
sql.type(
|
|
201
|
+
z.object({
|
|
202
|
+
id: z.number(),
|
|
203
|
+
name: z.string(),
|
|
204
|
+
}),
|
|
205
|
+
)`SELECT id, name FROM users WHERE id = ${id}`,
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
In auto mode (the default), the build output is (verbatim, lightly trimmed):
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { __zcFin, __zcFinD, __zcIT, __zcMkv } from "virtual:zod-compiler/runtime";
|
|
214
|
+
const _zh_6c9cb1a3 = /* @__PURE__ */ (() => {
|
|
215
|
+
function __fc_0(input) {
|
|
216
|
+
return (
|
|
217
|
+
typeof input === "object" &&
|
|
218
|
+
input !== null &&
|
|
219
|
+
!Array.isArray(input) &&
|
|
220
|
+
Number.isFinite(input["id"]) &&
|
|
221
|
+
typeof input["name"] === "string"
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
function __sw_2(input) {
|
|
225
|
+
var _e = [];
|
|
226
|
+
/* error-collecting walk — runs only when .error is read */ return _e;
|
|
227
|
+
}
|
|
228
|
+
function safeParse__zh_6c9cb1a3(input) {
|
|
229
|
+
if (__fc_0(input)) {
|
|
230
|
+
return { success: true, data: input };
|
|
231
|
+
}
|
|
232
|
+
return __zcFinD(__sw_2, input);
|
|
233
|
+
}
|
|
234
|
+
return __zcMkv(
|
|
235
|
+
safeParse__zh_6c9cb1a3,
|
|
236
|
+
z.object({
|
|
237
|
+
id: z.number(),
|
|
238
|
+
name: z.string(),
|
|
239
|
+
}),
|
|
240
|
+
__fc_0,
|
|
241
|
+
);
|
|
242
|
+
})();
|
|
243
|
+
import { pool, sql } from "./db.js";
|
|
244
|
+
import { z } from "zod";
|
|
245
|
+
|
|
246
|
+
const getUser = (id: number) => {
|
|
247
|
+
return pool.one(sql.type(_zh_6c9cb1a3)`SELECT id, name FROM users WHERE id = ${id}`);
|
|
248
|
+
};
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Reading it bottom-up:
|
|
252
|
+
|
|
253
|
+
- **The real Zod schema is still constructed** (once, at module load) and is the
|
|
254
|
+
object `_zh_6c9cb1a3` resolves to — `__zcMkv` installs the compiled
|
|
255
|
+
`parse`/`safeParse`/`parseAsync`/`safeParseAsync` as own properties on it and
|
|
256
|
+
returns it. `sql.type()` receives a genuine Zod schema (identity, `.shape`,
|
|
257
|
+
`._zod`, Standard Schema all intact) whose `safeParse` happens to be compiled.
|
|
258
|
+
- **`__fc_0` is the Fast Path**: when slonik validates each row, a valid row
|
|
259
|
+
costs one boolean chain — no per-node traversal, no allocations beyond the
|
|
260
|
+
result object.
|
|
261
|
+
- **`__sw_2` + `__zcFinD` are the failure path**: an invalid row returns
|
|
262
|
+
`{success: false}` immediately; the full error walk runs lazily only if
|
|
263
|
+
`.error` is actually read.
|
|
264
|
+
- The `sql.type(...)` call itself stays at the call site (it closes over `id`
|
|
265
|
+
via the tagged template) — only its schema argument was hoisted and compiled.
|
|
266
|
+
|
|
267
|
+
Measured on this exact pattern: schema construction + validation drops from
|
|
268
|
+
~16,700ns to ~14ns per call — construction amortizes to module load, and
|
|
269
|
+
per-row validation rides the Fast Path. With `schemas: "explicit"` the same file
|
|
270
|
+
still gets the plain hoist (construction once instead of per call); the
|
|
271
|
+
compiled IIFE requires auto mode (the default) because the schema is anonymous.
|
|
272
|
+
|
|
213
273
|
### Bundle Size & Cross-File Dedup
|
|
214
274
|
|
|
215
275
|
Generated validators share a small runtime helper layer (`__zcMkv` validator
|
|
@@ -225,25 +285,24 @@ many files reference them.
|
|
|
225
285
|
|
|
226
286
|
The result: a 5-file project with 10 schemas all using `z.email()` and
|
|
227
287
|
`z.uuid()` produces a bundle where each shared regex appears exactly **once**.
|
|
228
|
-
Set `
|
|
288
|
+
Set `output: "bag"` to additionally drop the original Zod schema reference
|
|
229
289
|
when you don't need `instanceof` / `.shape` access on the compiled output.
|
|
230
290
|
|
|
231
|
-
###
|
|
291
|
+
### Auto Mode: Side Effects Warning
|
|
232
292
|
|
|
233
|
-
|
|
293
|
+
In auto mode (the default), the plugin executes files to inspect their exports. A static pre-filter skips files whose exports provably can't be schemas without executing them — but if a file has schema-shaped exports AND side effects (starts a server, connects to a database), those side effects run at build time.
|
|
234
294
|
|
|
235
295
|
**Fix:** Use `include` to limit which files are scanned:
|
|
236
296
|
|
|
237
297
|
```typescript
|
|
238
298
|
zodCompiler({
|
|
239
|
-
autoDiscover: true,
|
|
240
299
|
include: ["src/schemas", "src/validators"],
|
|
241
300
|
});
|
|
242
301
|
```
|
|
243
302
|
|
|
244
|
-
###
|
|
303
|
+
### schemas: "auto" vs "explicit"
|
|
245
304
|
|
|
246
|
-
| |
|
|
305
|
+
| | `"auto"` (default) | `"explicit"` + compile() |
|
|
247
306
|
| ---------------------------- | ---------------------------------------------------------- | ------------------------------------------- |
|
|
248
307
|
| Source code changes | None | Wrap each schema |
|
|
249
308
|
| `zod-compiler` import needed | No | Yes |
|
|
@@ -281,10 +340,10 @@ performance, run hoist-only in Vitest and compile only real builds:
|
|
|
281
340
|
|
|
282
341
|
```typescript
|
|
283
342
|
// vitest.config.ts — hoisting still applies; validation uses plain Zod
|
|
284
|
-
zodCompiler({
|
|
343
|
+
zodCompiler({ schemas: "explicit" });
|
|
285
344
|
|
|
286
345
|
// vite.config.ts (build)
|
|
287
|
-
zodCompiler({
|
|
346
|
+
zodCompiler({ include: ["src/schemas"] });
|
|
288
347
|
```
|
|
289
348
|
|
|
290
349
|
**3. Measure before tuning.** `ZOD_COMPILER_TIMING=1` prints per-phase wall
|
|
@@ -313,7 +372,7 @@ export const appRouter = t.router({
|
|
|
313
372
|
});
|
|
314
373
|
```
|
|
315
374
|
|
|
316
|
-
|
|
375
|
+
In auto mode (the default), `CreateUserSchema` is compiled at build time. The tRPC router uses the optimized version automatically. No `.input(compile(CreateUserSchema))` needed.
|
|
317
376
|
|
|
318
377
|
### Hono
|
|
319
378
|
|
|
@@ -405,14 +464,14 @@ All standard Zod checks are supported: `min`, `max`, `length`, `email`, `url`, `
|
|
|
405
464
|
|
|
406
465
|
These contain JavaScript callbacks that cannot be reproduced in generated code:
|
|
407
466
|
|
|
408
|
-
| Type
|
|
409
|
-
|
|
|
410
|
-
| `transform` / `refine` with captures
|
|
411
|
-
| `superRefine`
|
|
412
|
-
| `custom`
|
|
413
|
-
| `preprocess`
|
|
414
|
-
| `lazy` (non-recursive)
|
|
415
|
-
| `.catchall(schema)`
|
|
467
|
+
| Type | Why | Alternative |
|
|
468
|
+
| ------------------------------------ | ------------------------------------------------------------- | --------------------------------------------- |
|
|
469
|
+
| `transform` / `refine` with captures | Callback captures outer variables (or is async / takes `ctx`) | Use zero-capture callbacks or built-in checks |
|
|
470
|
+
| `superRefine` | Callback needs `ctx` for issue collection | Use `refine` or built-in checks |
|
|
471
|
+
| `custom` | Arbitrary validation logic | — |
|
|
472
|
+
| `preprocess` | Input preprocessing function | Use `z.coerce` when possible |
|
|
473
|
+
| `lazy` (non-recursive) | Cannot resolve inner type | Use self-referencing lazy for recursion |
|
|
474
|
+
| `.catchall(schema)` | Unknown keys validated against a value schema | `strictObject` and `looseObject` both compile |
|
|
416
475
|
|
|
417
476
|
**Zero-capture effects compile:** a `transform`/`refine` callback that takes a
|
|
418
477
|
single argument and references only its own parameters, locals, and safe
|
|
@@ -425,7 +484,7 @@ compiles; `z.string().transform((s) => s + suffix)` falls back (it captures
|
|
|
425
484
|
|
|
426
485
|
**Tip:** Run `npx zod-compiler check` to see exactly which parts of your schemas are compiled and which fall back.
|
|
427
486
|
|
|
428
|
-
##
|
|
487
|
+
## Benchmark
|
|
429
488
|
|
|
430
489
|
5-way comparison: **Zod v3** vs **Zod v4** vs **zod-compiler** vs **[Typia](https://typia.io/)** vs **[AJV](https://ajv.js.org/)**
|
|
431
490
|
|
|
@@ -464,7 +523,7 @@ Performance scales with schema complexity. Nested objects and arrays see the big
|
|
|
464
523
|
`parse()` (throwing API) rides a zero-allocation fast path: medium object 2.2M → 9.1M ops/s (4.2x), large object (100 items) 18K → 1.4M ops/s (76x).
|
|
465
524
|
|
|
466
525
|
```bash
|
|
467
|
-
pnpm
|
|
526
|
+
pnpm benchmark # run locally
|
|
468
527
|
```
|
|
469
528
|
|
|
470
529
|
### Performance Architecture
|
|
@@ -478,6 +537,15 @@ Additional optimizations: check ordering (cheap checks first), pre-compiled rege
|
|
|
478
537
|
|
|
479
538
|
Run `npx zod-compiler check --json` to see which schemas qualify for Fast Path.
|
|
480
539
|
|
|
540
|
+
## Development
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
pnpm install
|
|
544
|
+
pnpm test
|
|
545
|
+
pnpm benchmark
|
|
546
|
+
pnpm lint
|
|
547
|
+
```
|
|
548
|
+
|
|
481
549
|
## Acknowledgements
|
|
482
550
|
|
|
483
|
-
zod-compiler started as a fork of [zod-aot](https://github.com/wakita181009/zod-aot) by [@wakita181009](https://github.com/wakita181009).
|
|
551
|
+
zod-compiler started as a fork of [zod-aot](https://github.com/wakita181009/zod-aot) by [@wakita181009](https://github.com/wakita181009).
|
|
@@ -48,9 +48,9 @@ function buildJsonReport(filePath, results) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
export async function runCheck(options) {
|
|
51
|
-
//
|
|
51
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
52
52
|
const out = console.log;
|
|
53
|
-
//
|
|
53
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
54
54
|
const err = console.error;
|
|
55
55
|
const colorEnabled = !options.noColor && process.stdout.isTTY === true;
|
|
56
56
|
const c = createColors(colorEnabled);
|
|
@@ -84,7 +84,7 @@ export async function runCheck(options) {
|
|
|
84
84
|
if (schemas.length === 0) {
|
|
85
85
|
const hint = options.autoDiscover
|
|
86
86
|
? "no Zod schemas exported"
|
|
87
|
-
: "no compile() calls found (use --auto
|
|
87
|
+
: "no compile() calls found (use --schemas auto to scan plain Zod exports)";
|
|
88
88
|
logger.warn(`${relPath}: ${hint}`);
|
|
89
89
|
continue;
|
|
90
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/cli/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEpD,+EAA+E;AAE/E,SAAS,UAAU,CAAC,IAAoB,EAAE,CAAS,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,IAAI;IAC7E,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,SAAS,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAE3E,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CA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;IACH,CAAC;SAAM,IAAI,gBAAgB,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -6,23 +6,25 @@ import { logger } from "./logger.js";
|
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
7
7
|
const VERSION = require("../../package.json").version;
|
|
8
8
|
function printUsage() {
|
|
9
|
-
//
|
|
9
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
10
10
|
console.log(`
|
|
11
11
|
zod-compiler v${VERSION} — Compile Zod schemas into zero-overhead validation functions
|
|
12
12
|
|
|
13
13
|
Usage:
|
|
14
|
-
zod-compiler generate <files...> [-o <output>] [-w] [--
|
|
15
|
-
zod-compiler check <files...> [--json] [--fail-under <pct>] [--no-color] [--
|
|
14
|
+
zod-compiler generate <files...> [-o <output>] [-w] [--schemas <mode>]
|
|
15
|
+
zod-compiler check <files...> [--json] [--fail-under <pct>] [--no-color] [--schemas <mode>]
|
|
16
16
|
|
|
17
17
|
Commands:
|
|
18
|
-
generate Generate optimized validation code from
|
|
18
|
+
generate Generate optimized validation code from discovered schemas
|
|
19
19
|
check Check schemas with tree view, coverage, Fast Path status, and hints
|
|
20
20
|
|
|
21
21
|
Options:
|
|
22
22
|
-o, --output <path> Output file or directory
|
|
23
23
|
-w, --watch Watch for changes and regenerate
|
|
24
|
-
--
|
|
25
|
-
|
|
24
|
+
--schemas <explicit|auto> How schemas are found: "auto" (default) compiles every
|
|
25
|
+
exported Zod schema; "explicit" only compile()-wrapped ones
|
|
26
|
+
--emit <schema|bag> Compiled export shape: "schema" (default, full Zod API) or
|
|
27
|
+
"bag" (minimal methods-only object, smaller output)
|
|
26
28
|
--json Output diagnosis as JSON (check only)
|
|
27
29
|
--fail-under <pct> Exit with code 1 if any schema's coverage < pct (check only)
|
|
28
30
|
--no-color Disable colored output (check only)
|
|
@@ -33,12 +35,27 @@ Examples:
|
|
|
33
35
|
zod-compiler generate src/schemas.ts
|
|
34
36
|
zod-compiler generate src/schemas.ts -o src/schemas.compiled.ts
|
|
35
37
|
zod-compiler generate src/ --watch
|
|
36
|
-
zod-compiler generate src/
|
|
38
|
+
zod-compiler generate src/schemas.ts --schemas explicit
|
|
37
39
|
zod-compiler check src/schemas.ts
|
|
38
|
-
zod-compiler check src/env.ts --auto-discover
|
|
39
40
|
zod-compiler check src/schemas.ts --json --fail-under 80
|
|
40
41
|
`.trim());
|
|
41
42
|
}
|
|
43
|
+
/** Parse a `--schemas <explicit|auto>` value; exits on invalid input. */
|
|
44
|
+
function parseSchemasValue(val) {
|
|
45
|
+
if (val !== "explicit" && val !== "auto") {
|
|
46
|
+
logger.error('--schemas must be "explicit" or "auto"');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
return val === "auto";
|
|
50
|
+
}
|
|
51
|
+
/** Parse an `--emit <schema|bag>` value; exits on invalid input. */
|
|
52
|
+
function parseEmitValue(val) {
|
|
53
|
+
if (val !== "schema" && val !== "bag") {
|
|
54
|
+
logger.error('--emit must be "schema" or "bag"');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
return val === "schema";
|
|
58
|
+
}
|
|
42
59
|
function parseArgs(argv) {
|
|
43
60
|
const args = argv.slice(2);
|
|
44
61
|
if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
|
|
@@ -54,7 +71,8 @@ function parseArgs(argv) {
|
|
|
54
71
|
let output;
|
|
55
72
|
let watch = false;
|
|
56
73
|
let zodCompat;
|
|
57
|
-
|
|
74
|
+
// Default "auto": every exported Zod schema compiles, matching the plugin.
|
|
75
|
+
let autoDiscover = true;
|
|
58
76
|
for (let i = 0; i < rest.length; i++) {
|
|
59
77
|
const arg = rest[i];
|
|
60
78
|
if (arg === "-o" || arg === "--output") {
|
|
@@ -69,11 +87,13 @@ function parseArgs(argv) {
|
|
|
69
87
|
else if (arg === "-w" || arg === "--watch") {
|
|
70
88
|
watch = true;
|
|
71
89
|
}
|
|
72
|
-
else if (arg === "--
|
|
73
|
-
|
|
90
|
+
else if (arg === "--schemas") {
|
|
91
|
+
i++;
|
|
92
|
+
autoDiscover = parseSchemasValue(rest[i]);
|
|
74
93
|
}
|
|
75
|
-
else if (arg === "--
|
|
76
|
-
|
|
94
|
+
else if (arg === "--emit") {
|
|
95
|
+
i++;
|
|
96
|
+
zodCompat = parseEmitValue(rest[i]);
|
|
77
97
|
}
|
|
78
98
|
else if (arg.startsWith("-")) {
|
|
79
99
|
logger.error(`Unknown option: ${arg}`);
|
|
@@ -103,12 +123,17 @@ function parseArgs(argv) {
|
|
|
103
123
|
let json = false;
|
|
104
124
|
let failUnder;
|
|
105
125
|
let noColor = false;
|
|
106
|
-
|
|
126
|
+
// Default "auto", matching generate and the plugin.
|
|
127
|
+
let autoDiscover = true;
|
|
107
128
|
for (let i = 0; i < rest.length; i++) {
|
|
108
129
|
const arg = rest[i];
|
|
109
130
|
if (arg === "--json") {
|
|
110
131
|
json = true;
|
|
111
132
|
}
|
|
133
|
+
else if (arg === "--schemas") {
|
|
134
|
+
i++;
|
|
135
|
+
autoDiscover = parseSchemasValue(rest[i]);
|
|
136
|
+
}
|
|
112
137
|
else if (arg === "--fail-under") {
|
|
113
138
|
i++;
|
|
114
139
|
const val = rest[i];
|
|
@@ -126,9 +151,6 @@ function parseArgs(argv) {
|
|
|
126
151
|
else if (arg === "--no-color") {
|
|
127
152
|
noColor = true;
|
|
128
153
|
}
|
|
129
|
-
else if (arg === "--auto-discover") {
|
|
130
|
-
autoDiscover = true;
|
|
131
|
-
}
|
|
132
154
|
else if (arg.startsWith("-")) {
|
|
133
155
|
logger.error(`Unknown option: ${arg}`);
|
|
134
156
|
process.exit(1);
|
|
@@ -153,7 +175,7 @@ async function main() {
|
|
|
153
175
|
printUsage();
|
|
154
176
|
break;
|
|
155
177
|
case "version":
|
|
156
|
-
//
|
|
178
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
157
179
|
console.log(VERSION);
|
|
158
180
|
break;
|
|
159
181
|
case "generate": {
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAY,OAAO,CAAC,oBAAoB,CAAyB,CAAC,OAAO,CAAC;AAUvF,SAAS,UAAU;IACjB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAY,OAAO,CAAC,oBAAoB,CAAyB,CAAC,OAAO,CAAC;AAUvF,SAAS,UAAU;IACjB,oDAAoD;IACpD,OAAO,CAAC,GAAG,CACT;gBACY,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BtB,CAAC,IAAI,EAAE,CACL,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,SAAS,iBAAiB,CAAC,GAAuB;IAChD,IAAI,GAAG,KAAK,UAAU,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACzC,MAAM,CAAC,KAA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ACpD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,MAAM;QACR,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC1B,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;gBACzD,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;gBAC/D,MAAM,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YACD,MAAM;QACR,CAAC;QACD,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;YACzD,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAChC,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC;AAED,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IACjC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/cli/logger.js
CHANGED
|
@@ -22,9 +22,9 @@ export function createColors(enabled) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
const colors = createColors(process.stdout.isTTY === true);
|
|
25
|
-
//
|
|
25
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
26
26
|
const log = console.log;
|
|
27
|
-
//
|
|
27
|
+
// oxlint-disable-next-line no-console -- CLI output
|
|
28
28
|
const logError = console.error;
|
|
29
29
|
export const logger = {
|
|
30
30
|
info(msg) {
|
package/dist/cli/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/cli/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAYnC,MAAM,SAAS,GAAW;IACxB,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;AAE3D,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/cli/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAYnC,MAAM,SAAS,GAAW;IACxB,KAAK,EAAE,EAAE;IACT,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO;QACL,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;AAE3D,oDAAoD;AACpD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;AACxB,oDAAoD;AACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;AAE/B,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,CAAC,GAAW;QACd,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,CAAC,GAAW;QACjB,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,OAAO,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,CAAC,GAAW;QACd,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,CAAC,GAAW;QACf,QAAQ,CAAC,GAAG,MAAM,CAAC,GAAG,QAAQ,MAAM,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IACvD,CAAC;IACD,GAAG,CAAC,GAAW;QACb,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BigIntCheckIR, CheckIR,
|
|
1
|
+
import type { BigIntCheckIR, CheckIR, DateCheckIR, SchemaIR, SetCheckIR } from "../types.js";
|
|
2
2
|
/** Codegen output mode. "inline" emits self-contained code (CLI .compiled.ts). "lean" emits references to imports from "virtual:zod-compiler/runtime" (unplugin). */
|
|
3
3
|
export type CodegenMode = "inline" | "lean";
|
|
4
4
|
export interface CodeGenResult {
|
|
@@ -193,13 +193,4 @@ export declare function hasMutation(ir: SchemaIR): boolean;
|
|
|
193
193
|
* Used by fast-path generators after filtering out refine_effect entries.
|
|
194
194
|
*/
|
|
195
195
|
export declare function checkPriority(a: CheckIR | BigIntCheckIR | DateCheckIR | SetCheckIR, b: CheckIR | BigIntCheckIR | DateCheckIR | SetCheckIR): number;
|
|
196
|
-
/**
|
|
197
|
-
* Sort compilable checks by cost (cheapest first) while preserving
|
|
198
|
-
* the original position of refine_effect entries.
|
|
199
|
-
*
|
|
200
|
-
* Zod preserves insertion order for checks. Compilable checks (typeof, length,
|
|
201
|
-
* regex) are reordered for performance, but refine_effect entries stay at their
|
|
202
|
-
* original index to maintain semantic parity with Zod.
|
|
203
|
-
*/
|
|
204
|
-
export declare function sortChecksPreservingEffects<T extends CheckIR | CheckOrEffectIR | BigIntCheckIR | DateCheckIR>(checks: T[]): T[];
|
|
205
196
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/core/codegen/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/core/codegen/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAO7F,qKAAqK;AACrK,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;I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AAG,OAAO,CAmDjD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,OAAO,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,EACrD,CAAC,EAAE,OAAO,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,GACpD,MAAM,CAER"}
|
|
@@ -260,44 +260,4 @@ export function hasMutation(ir) {
|
|
|
260
260
|
export function checkPriority(a, b) {
|
|
261
261
|
return (CHECK_PRIORITY[a.kind] ?? 99) - (CHECK_PRIORITY[b.kind] ?? 99);
|
|
262
262
|
}
|
|
263
|
-
/**
|
|
264
|
-
* Sort compilable checks by cost (cheapest first) while preserving
|
|
265
|
-
* the original position of refine_effect entries.
|
|
266
|
-
*
|
|
267
|
-
* Zod preserves insertion order for checks. Compilable checks (typeof, length,
|
|
268
|
-
* regex) are reordered for performance, but refine_effect entries stay at their
|
|
269
|
-
* original index to maintain semantic parity with Zod.
|
|
270
|
-
*/
|
|
271
|
-
export function sortChecksPreservingEffects(checks) {
|
|
272
|
-
// Value-mutating checks (overwrite effects, trimming url checks) make order
|
|
273
|
-
// semantically load-bearing: a length check before vs after .trim() measures
|
|
274
|
-
// different strings. Keep Zod's exact order when any mutator is present.
|
|
275
|
-
const isMutator = (c) => c.kind === "overwrite_effect" || (c.kind === "string_format" && c.format === "url");
|
|
276
|
-
if (checks.some(isMutator)) {
|
|
277
|
-
return [...checks];
|
|
278
|
-
}
|
|
279
|
-
const result = new Array(checks.length);
|
|
280
|
-
const compilable = [];
|
|
281
|
-
// First pass: place refine_effects at their original positions
|
|
282
|
-
for (let i = 0; i < checks.length; i++) {
|
|
283
|
-
const check = checks[i];
|
|
284
|
-
if (check.kind === "refine_effect") {
|
|
285
|
-
result[i] = check;
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
compilable.push({ check, originalIndex: i });
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
// Sort compilable checks by priority (cheapest first)
|
|
292
|
-
compilable.sort((a, b) => (CHECK_PRIORITY[a.check.kind] ?? 99) - (CHECK_PRIORITY[b.check.kind] ?? 99));
|
|
293
|
-
// Fill remaining slots with sorted compilable checks
|
|
294
|
-
let ci = 0;
|
|
295
|
-
for (let i = 0; i < result.length; i++) {
|
|
296
|
-
if (result[i] === undefined) {
|
|
297
|
-
const entry = compilable[ci++];
|
|
298
|
-
result[i] = entry.check;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
263
|
//# sourceMappingURL=context.js.map
|