zod-compiler 1.26.3 → 1.27.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.
Files changed (38) hide show
  1. package/README.md +41 -1
  2. package/dist/core/compile.d.ts +5 -0
  3. package/dist/core/compile.d.ts.map +1 -1
  4. package/dist/core/compile.js +11 -1
  5. package/dist/core/compile.js.map +1 -1
  6. package/dist/core/extract/effects.d.ts +17 -1
  7. package/dist/core/extract/effects.d.ts.map +1 -1
  8. package/dist/core/extract/effects.js +131 -9
  9. package/dist/core/extract/effects.js.map +1 -1
  10. package/dist/core/extract/extractors/pipe.d.ts.map +1 -1
  11. package/dist/core/extract/extractors/pipe.js +18 -16
  12. package/dist/core/extract/extractors/pipe.js.map +1 -1
  13. package/dist/discovery.d.ts.map +1 -1
  14. package/dist/discovery.js +14 -18
  15. package/dist/discovery.js.map +1 -1
  16. package/dist/is-zod-schema.d.ts +23 -0
  17. package/dist/is-zod-schema.d.ts.map +1 -0
  18. package/dist/is-zod-schema.js +32 -0
  19. package/dist/is-zod-schema.js.map +1 -0
  20. package/dist/jit.d.ts +2 -0
  21. package/dist/jit.d.ts.map +1 -1
  22. package/dist/jit.js +72 -34
  23. package/dist/jit.js.map +1 -1
  24. package/dist/register/config.d.ts +20 -0
  25. package/dist/register/config.d.ts.map +1 -0
  26. package/dist/register/config.js +1 -0
  27. package/dist/register/index.d.ts +1 -0
  28. package/dist/register/index.js +68 -0
  29. package/dist/register/index.js.map +1 -0
  30. package/dist/register/transform.d.ts +16 -0
  31. package/dist/register/transform.d.ts.map +1 -0
  32. package/dist/register/transform.js +148 -0
  33. package/dist/register/transform.js.map +1 -0
  34. package/dist/unplugin/hoist-compile.d.ts.map +1 -1
  35. package/dist/unplugin/hoist-compile.js +1 -4
  36. package/dist/unplugin/hoist-compile.js.map +1 -1
  37. package/package.json +12 -1
  38. package/schema.json +80 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-compiler",
3
- "version": "1.26.3",
3
+ "version": "1.27.0",
4
4
  "description": "Compile Zod schemas into zero-overhead validation functions",
5
5
  "keywords": [
6
6
  "aot",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "schema.json",
25
26
  "LICENSE"
26
27
  ],
27
28
  "type": "module",
@@ -39,6 +40,13 @@
39
40
  "import": "./dist/jit.js",
40
41
  "default": "./dist/jit.js"
41
42
  },
43
+ "./register": {
44
+ "types": "./dist/register/index.d.ts",
45
+ "source": "./src/register/index.ts",
46
+ "import": "./dist/register/index.js",
47
+ "default": "./dist/register/index.js"
48
+ },
49
+ "./schema.json": "./schema.json",
42
50
  "./vite": {
43
51
  "types": "./dist/unplugin/vite.d.ts",
44
52
  "source": "./src/unplugin/vite.ts",
@@ -125,6 +133,7 @@
125
133
  "dependencies": {
126
134
  "@jridgewell/remapping": "^2.3.5",
127
135
  "acorn": "^8.16.0",
136
+ "es-module-lexer": "^2.3.1",
128
137
  "get-tsconfig": "^4.14.0",
129
138
  "jiti": "^2.7.0",
130
139
  "magic-string": "^0.30.21",
@@ -141,6 +150,8 @@
141
150
  "knip": "^6.29.0",
142
151
  "publint": "^0.3.22",
143
152
  "semantic-release": "^25.0.3",
153
+ "ts-json-schema-generator": "^2.9.0",
154
+ "tsx": "catalog:",
144
155
  "typescript": "catalog:",
145
156
  "vite": "catalog:",
146
157
  "vite-plus": "catalog:",
package/schema.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "include": {
6
+ "type": "array",
7
+ "items": {
8
+ "type": "string"
9
+ },
10
+ "description": "Glob patterns to include (default: [\"**\\/*.ts\", \"**\\/*.tsx\"])"
11
+ },
12
+ "exclude": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "string"
16
+ },
17
+ "description": "Glob patterns to exclude (default: [\"node_modules/**\", \"**\\/*.d.ts\"])"
18
+ },
19
+ "schemas": {
20
+ "type": "string",
21
+ "enum": [
22
+ "explicit",
23
+ "auto"
24
+ ],
25
+ "description": "How schemas are found.\n\n- `\"auto\"` (default): every exported plain Zod schema compiles — no wrappers, no zod-compiler imports in source. Detection scans files with a runtime `import ... from \"zod\"`, statically pre-filters ones whose exports provably aren't schemas, and executes the remaining candidates to check exports for `_zod.def`. Also enables build-time compilation of hoisted in-function schemas (anonymous schemas like `sql.type(z.object(...))` — there is no exported name to opt in with).\n- `\"explicit\"`: only schemas wrapped in `compile()` from zod-compiler are compiled; build-time file execution is limited to files that import it. Hoisting still applies, but hoisted schemas stay plain Zod.\n\n**Note:** in `\"auto\"` mode, candidate files are executed at build time via `loadSourceFile()`. Use `include` to limit scope if your project has schema-shaped files with side effects. A module that calls `process.exit()` during this execution (e.g. an env-validation guard in a secret-less CI build) is caught — the file falls back to runtime Zod instead of crashing the build. Guard the exit on `process.env.ZOD_COMPILER` to keep such schemas compiled.",
26
+ "default": "auto"
27
+ },
28
+ "hoist": {
29
+ "anyOf": [
30
+ {
31
+ "type": "boolean"
32
+ },
33
+ {
34
+ "type": "object",
35
+ "properties": {
36
+ "schemaNamePattern": {
37
+ "anyOf": [
38
+ {
39
+ "type": "string",
40
+ "format": "regex"
41
+ },
42
+ {
43
+ "type": "string"
44
+ },
45
+ {
46
+ "type": "null"
47
+ }
48
+ ]
49
+ }
50
+ },
51
+ "additionalProperties": false
52
+ }
53
+ ],
54
+ "description": "Hoist Zod schema construction out of function bodies to module scope (the babel-plugin-zod-hoist optimization). A schema defined inside a function — a React component, a request handler — is otherwise rebuilt on every call:\n\n```typescript function getSchema() { return z.object({ name: z.string() }); // rebuilt per call } // becomes const _zh_94b7f5c1 = z.object({ name: z.string() }); function getSchema() { return _zh_94b7f5c1; // built once } ```\n\nOnly expressions built purely from imported bindings and literals are hoisted — anything referencing local variables, module-level bindings, `this`, or globals stays put (safe globals like `Number` are allowed inside callbacks, which run per call regardless). Identical schemas dedupe to one binding.\n\nPass an object to configure `schemaNamePattern` (default `/ZodSchema$/`): imported identifiers matching it are hoistable combinator-chain roots even without an inline z.* reference (`UserZodSchema.partial()`). Set it to `null` to disable name-based matching.",
55
+ "default": true
56
+ },
57
+ "$schema": {
58
+ "type": "string",
59
+ "description": "JSON Schema used by editors.",
60
+ "default": "./node_modules/zod-compiler/schema.json"
61
+ },
62
+ "eager": {
63
+ "type": "boolean",
64
+ "description": "Compile immediately instead of when a validation method is first read.",
65
+ "default": false
66
+ },
67
+ "output": {
68
+ "type": "string",
69
+ "enum": [
70
+ "schema",
71
+ "compact"
72
+ ],
73
+ "description": "Preserve the complete compiled validator, or delegate cold error production to the retained Zod schema in compact mode.",
74
+ "default": "schema"
75
+ }
76
+ },
77
+ "additionalProperties": false,
78
+ "description": "Configuration loaded by `zod-compiler/register` from the current working directory.",
79
+ "definitions": {}
80
+ }