zod-aot 0.0.9 → 0.0.10
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 +29 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ Measured with `vitest bench` on Node.js (Apple M-series):
|
|
|
25
25
|
|
|
26
26
|
### safeParse
|
|
27
27
|
|
|
28
|
-
| Scenario | Zod v4 | zod-aot | Speedup
|
|
29
|
-
|
|
28
|
+
| Scenario | Zod v4 | zod-aot | Speedup |
|
|
29
|
+
|---|---|---|----------|
|
|
30
30
|
| simple string | 10.4M ops/s | 17.9M ops/s | **1.7x** |
|
|
31
31
|
| string (min/max) | 5.3M ops/s | 17.6M ops/s | **3.3x** |
|
|
32
32
|
| number (int+positive) | 5.2M ops/s | 16.4M ops/s | **3.1x** |
|
|
@@ -35,10 +35,10 @@ Measured with `vitest bench` on Node.js (Apple M-series):
|
|
|
35
35
|
| record\<string, number\> (5 keys) | 1.9M ops/s | 8.3M ops/s | **4.3x** |
|
|
36
36
|
| discriminatedUnion (3 variants) | 3.0M ops/s | 15.7M ops/s | **5.3x** |
|
|
37
37
|
| medium object (7 props, valid) | 1.7M ops/s | 6.6M ops/s | **4.0x** |
|
|
38
|
-
| medium object (7 props, invalid) | 65K ops/s | 1.5M ops/s | **23x**
|
|
39
|
-
| large object (10 nested items) | 111K ops/s | 4.8M ops/s | **43x**
|
|
40
|
-
| large object (100 nested items) | 11.9K ops/s | 713K ops/s | **
|
|
41
|
-
| event log (combined) | 431K ops/s | 5.0M ops/s | **12x**
|
|
38
|
+
| medium object (7 props, invalid) | 65K ops/s | 1.5M ops/s | **23x** |
|
|
39
|
+
| large object (10 nested items) | 111K ops/s | 4.8M ops/s | **43x** |
|
|
40
|
+
| large object (100 nested items) | 11.9K ops/s | 713K ops/s | **64x** |
|
|
41
|
+
| event log (combined) | 431K ops/s | 5.0M ops/s | **12x** |
|
|
42
42
|
| partial fallback object (transform) | 1.2M ops/s | 3.0M ops/s | **2.5x** |
|
|
43
43
|
| partial fallback array 10 (transform) | 447K ops/s | 2.1M ops/s | **4.6x** |
|
|
44
44
|
| partial fallback array 50 (transform) | 100K ops/s | 467K ops/s | **4.7x** |
|
|
@@ -233,8 +233,7 @@ z.object({
|
|
|
233
233
|
|
|
234
234
|
```javascript
|
|
235
235
|
/* zod-aot */
|
|
236
|
-
var
|
|
237
|
-
var __set_1 = new Set(["admin", "user"]);
|
|
236
|
+
var __set_0 = new Set(["admin", "user"]);
|
|
238
237
|
|
|
239
238
|
function safeParse_validate(input) {
|
|
240
239
|
var __issues = [];
|
|
@@ -252,7 +251,7 @@ function safeParse_validate(input) {
|
|
|
252
251
|
}
|
|
253
252
|
|
|
254
253
|
// role: enum(["admin", "user"])
|
|
255
|
-
if (!
|
|
254
|
+
if (!__set_0.has(input["role"])) {
|
|
256
255
|
__issues.push({ code: "invalid_enum_value", path: ["role"] });
|
|
257
256
|
}
|
|
258
257
|
}
|
|
@@ -371,45 +370,33 @@ The intermediate representation — a discriminated union of all supported schem
|
|
|
371
370
|
|
|
372
371
|
## Supported Types
|
|
373
372
|
|
|
374
|
-
### Tier 1 — Primitives & Core
|
|
375
|
-
|
|
376
373
|
| Type | Supported Checks |
|
|
377
374
|
|---|---|
|
|
378
375
|
| `string` | `min`, `max`, `length`, `email`, `url`, `uuid`, `regex` |
|
|
379
376
|
| `number` | `int`, `positive`, `negative`, `nonnegative`, `nonpositive`, `min`, `max`, `multipleOf` |
|
|
377
|
+
| `bigint` | `min`, `max`, `positive`, `negative`, `nonnegative`, `nonpositive`, `multipleOf` |
|
|
380
378
|
| `boolean` | — |
|
|
381
379
|
| `null` | — |
|
|
382
380
|
| `undefined` | — |
|
|
381
|
+
| `any` | — (always passes) |
|
|
382
|
+
| `unknown` | — (always passes) |
|
|
383
383
|
| `literal` | single value, multi-value |
|
|
384
384
|
| `enum` | string enum values |
|
|
385
|
+
| `date` | `min`, `max` (timestamp comparison) |
|
|
385
386
|
| `object` | nested objects, mixed property types |
|
|
386
387
|
| `array` | `min`, `max`, `length`, element validation |
|
|
387
|
-
| `union` | sequential trial of all options |
|
|
388
|
-
| `optional` | wraps any supported type |
|
|
389
|
-
| `nullable` | wraps any supported type |
|
|
390
|
-
|
|
391
|
-
### Tier 2 — Composites & Extended
|
|
392
|
-
|
|
393
|
-
| Type | Supported Checks |
|
|
394
|
-
|---|---|
|
|
395
|
-
| `any` | — (always passes) |
|
|
396
|
-
| `unknown` | — (always passes) |
|
|
397
|
-
| `readonly` | validates inner type (TS-only concept) |
|
|
398
|
-
| `date` | `min`, `max` (timestamp comparison) |
|
|
399
388
|
| `tuple` | per-element types, optional rest element |
|
|
400
389
|
| `record` | key and value type validation |
|
|
401
|
-
| `default` | replaces `undefined` with default value, then validates inner |
|
|
402
|
-
| `intersection` | validates both left and right schemas |
|
|
403
|
-
| `discriminatedUnion` | O(1) `switch` dispatch on discriminator field |
|
|
404
|
-
|
|
405
|
-
### Tier 3 — Collections & Pipeline
|
|
406
|
-
|
|
407
|
-
| Type | Supported Checks |
|
|
408
|
-
|---|---|
|
|
409
|
-
| `bigint` | `min`, `max`, `positive`, `negative`, `nonnegative`, `nonpositive`, `multipleOf` |
|
|
410
390
|
| `set` | `min`, `max` (size), element validation |
|
|
411
391
|
| `map` | key and value type validation |
|
|
392
|
+
| `union` | sequential trial of all options |
|
|
393
|
+
| `discriminatedUnion` | O(1) `switch` dispatch on discriminator field |
|
|
394
|
+
| `intersection` | validates both left and right schemas |
|
|
412
395
|
| `pipe` (non-transform) | sequential in→out validation |
|
|
396
|
+
| `optional` | wraps any supported type |
|
|
397
|
+
| `nullable` | wraps any supported type |
|
|
398
|
+
| `readonly` | validates inner type (TS-only concept) |
|
|
399
|
+
| `default` | replaces `undefined` with default value, then validates inner |
|
|
413
400
|
|
|
414
401
|
### Automatic Fallback to Zod
|
|
415
402
|
|
|
@@ -427,40 +414,6 @@ When a schema contains a mix of compilable and non-compilable parts (e.g., an ob
|
|
|
427
414
|
|
|
428
415
|
> **Note:** If a schema heavily relies on `transform`, `refine`, or other non-compilable features, the performance benefit from partial fallback will be minimal — most of the validation work is still delegated to Zod. Partial fallback is most effective when only a small portion of the schema uses these features.
|
|
429
416
|
|
|
430
|
-
### Planned
|
|
431
|
-
|
|
432
|
-
| Type | Status |
|
|
433
|
-
|---|---|
|
|
434
|
-
| `template_literal` | Pending Zod v4 API verification |
|
|
435
|
-
|
|
436
|
-
## Roadmap
|
|
437
|
-
|
|
438
|
-
### Phase 1: Core Compiler — Complete
|
|
439
|
-
|
|
440
|
-
- [x] SchemaIR type definitions
|
|
441
|
-
- [x] Extractor: `_zod.def` → SchemaIR (Tier 1 types)
|
|
442
|
-
- [x] CodeGen: SchemaIR → optimized JS
|
|
443
|
-
- [x] Runtime fallback (`createFallback`)
|
|
444
|
-
- [x] Benchmarks (vitest bench + standalone scripts)
|
|
445
|
-
- [x] E2E compatibility tests (Zod ↔ generated code)
|
|
446
|
-
- [x] CI/CD (GitHub Actions + npm publish)
|
|
447
|
-
|
|
448
|
-
### Phase 2: Type Expansion + CLI + Build Plugin
|
|
449
|
-
|
|
450
|
-
- [x] Tier 2 type support (9 types: any, unknown, readonly, date, tuple, record, default, intersection, discriminatedUnion)
|
|
451
|
-
- [x] `discriminatedUnion` → O(1) switch statement optimization
|
|
452
|
-
- [x] CLI (`npx zod-aot generate` / `npx zod-aot check`)
|
|
453
|
-
- [x] Partial fallback (objects with some transform properties)
|
|
454
|
-
- [x] unplugin integration (Vite / webpack / esbuild / Rollup)
|
|
455
|
-
- [x] Watch mode (`--watch` / `-w`)
|
|
456
|
-
|
|
457
|
-
### Phase 3: Ecosystem
|
|
458
|
-
|
|
459
|
-
- [x] Tier 3 type support (bigint, set, map, pipe non-transform)
|
|
460
|
-
- [x] Lazy schema fallback
|
|
461
|
-
- [ ] `template_literal` type support
|
|
462
|
-
- [ ] Documentation site
|
|
463
|
-
|
|
464
417
|
## Development
|
|
465
418
|
|
|
466
419
|
```bash
|
|
@@ -490,20 +443,18 @@ zod-aot/
|
|
|
490
443
|
├── packages/zod-aot/ # Main npm package
|
|
491
444
|
│ ├── src/
|
|
492
445
|
│ │ ├── index.ts # Public API exports
|
|
493
|
-
│ │ ├──
|
|
494
|
-
│ │ ├──
|
|
495
|
-
│ │ ├──
|
|
496
|
-
│ │
|
|
446
|
+
│ │ ├── discovery.ts # Schema discovery (shared by CLI & unplugin)
|
|
447
|
+
│ │ ├── loader.ts # Runtime-aware file loader
|
|
448
|
+
│ │ ├── core/ # Pure logic (no CLI/unplugin deps)
|
|
449
|
+
│ │ │ ├── types.ts # SchemaIR, CompiledSchema, CheckIR
|
|
450
|
+
│ │ │ ├── compile.ts # compile() marker + isCompiledSchema()
|
|
451
|
+
│ │ │ ├── runtime.ts # createFallback (dev-time)
|
|
452
|
+
│ │ │ ├── extractor.ts # _zod.def → SchemaIR
|
|
453
|
+
│ │ │ └── codegen/ # SchemaIR → optimized JS
|
|
454
|
+
│ │ ├── cli/ # CLI commands (generate, check, watch)
|
|
455
|
+
│ │ └── unplugin/ # Build plugin (Vite/webpack/esbuild/Rollup)
|
|
497
456
|
│ └── tests/
|
|
498
|
-
│ ├── integration.test.ts # E2E: Zod ↔ generated code
|
|
499
|
-
│ ├── extractor/ # Extractor unit tests
|
|
500
|
-
│ ├── codegen/ # CodeGen unit tests
|
|
501
|
-
│ └── runtime.test.ts # Fallback tests
|
|
502
457
|
├── benchmarks/ # vitest bench + standalone scripts
|
|
503
|
-
│ ├── standalone/
|
|
504
|
-
│ │ ├── zod-only.ts # Standalone Zod benchmark
|
|
505
|
-
│ │ └── zod-aot.ts # Standalone zod-aot benchmark
|
|
506
|
-
│ └── ...
|
|
507
458
|
└── .github/workflows/ # CI + release automation
|
|
508
459
|
```
|
|
509
460
|
|