Skip to content

Commit 30aa27b

Browse files
committed
add zod4 as a candidate
1 parent 366ccb7 commit 30aa27b

14 files changed

+518
-13
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ At [Softnetics Team](https://www.softnetics.tech/), we specialize in building so
3939

4040
## Library Version
4141

42-
| Library | Version |
43-
| ----------------------------------------------------- | ------------- |
44-
| [Zod](https://zod.dev/) | 3.24.1 |
45-
| [typebox](https://github.com/sinclairzx81/typebox) | 0.34.14 |
46-
| [arktype](https://arktype.io/) | 2.0.3 |
47-
| [valibot](https://valibot.dev/) | 1.0.0-beta.14 |
48-
| [yup](https://github.com/jquense/yup) | 1.6.1 |
49-
| [@effect/schema](https://github.com/Effect-TS/effect) | 0.75.5 |
42+
| Library | Version |
43+
| ----------------------------------------------------- | -------------------------- |
44+
| [Zod](https://zod.dev/) | 3.24.1 |
45+
| [Zod4](https://zod.dev/) | 4.0.0-beta.20250414T061543 |
46+
| [typebox](https://github.com/sinclairzx81/typebox) | 0.34.14 |
47+
| [arktype](https://arktype.io/) | 2.0.3 |
48+
| [valibot](https://valibot.dev/) | 1.0.0-beta.14 |
49+
| [yup](https://github.com/jquense/yup) | 1.6.1 |
50+
| [@effect/schema](https://github.com/Effect-TS/effect) | 0.75.5 |
5051

5152
# Test Cases Explanation
5253

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"typescript": "^5.4.5",
2525
"valibot": "1.0.0-beta.14",
2626
"yup": "^1.6.1",
27-
"zod": "^3.24.1"
27+
"zod": "^3.24.1",
28+
"zod4": "npm:[email protected]"
2829
},
2930
"devDependencies": {
3031
"@types/node": "^20.12.12",

pnpm-lock.yaml

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reports/benchmark_plotter.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, benchmarks: pd.DataFrame, dir: str):
2020
"valibot": "#9467bd",
2121
"yup": "#8c564b",
2222
"zod": "#e377c2",
23+
"zod4": "#ffd700",
2324
}
2425
self.metrics = [
2526
{"name": "Memory used", "unit": "Megabytes"},

samples/__generated__/complex.zod4.ts

+96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/__generated__/extend.zod4.ts

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/__generated__/simple.zod4.ts

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/__generated__/union.zod4.ts

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/custom/transform-simple.valibot.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as v from 'valibot'
22

3-
type TransformSimple_ModelInput = v.InferInput<typeof TransformSimple_Model>
4-
type TransformSimple_ModelOutput = v.InferOutput<typeof TransformSimple_Model>
3+
export type TransformSimple_ModelInput = v.InferInput<typeof TransformSimple_Model>
4+
export type TransformSimple_ModelOutput = v.InferOutput<typeof TransformSimple_Model>
55
export const TransformSimple_Model = v.pipe(
66
v.object({
77
a: v.number(),

samples/custom/transform-simple.zod.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as z from 'zod'
22

3-
type TransformSimple_ModelInput = z.input<typeof TransformSimple_Model>
4-
type TransformSimple_ModelOutput = z.output<typeof TransformSimple_Model>
3+
export type TransformSimple_ModelInput = z.input<typeof TransformSimple_Model>
4+
export type TransformSimple_ModelOutput = z.output<typeof TransformSimple_Model>
55
export const TransformSimple_Model = z
66
.object({
77
a: z.number(),
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as z from 'zod4'
2+
3+
export type TransformSimple_ModelInput = z.input<typeof TransformSimple_Model>
4+
export type TransformSimple_ModelOutput = z.output<typeof TransformSimple_Model>
5+
export const TransformSimple_Model = z
6+
.object({
7+
a: z.number(),
8+
b: z.string(),
9+
c: z.boolean(),
10+
d: z.array(
11+
z.object({
12+
a: z.date(),
13+
b: z.string(),
14+
})
15+
),
16+
})
17+
.transform((input) => {
18+
return {
19+
x: `${input.a}`,
20+
y: `${input.b}`,
21+
z: `${input.c}`,
22+
l: input.d.map((item) => {
23+
return {
24+
a: item.a.toISOString(),
25+
b: item.b,
26+
}
27+
}),
28+
}
29+
})

src/cli/codegen.ts

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
TypeScriptToModel,
1919
TypeScriptToTypeBox,
2020
} from '@/tools/typebox-codegen'
21+
import { ModelToZod4 } from '@/tools/typebox-codegen/model/model-to-zod4'
2122
import { cleanDir } from '@/utils/clean-dir'
2223
import { extractFileName } from '@/utils/extract-file-name'
2324
import { writeFile } from '@/utils/write-file'
@@ -45,6 +46,10 @@ async function generateSchemaValidationLibrary(
4546
content = await ModelToZod.Generate(model)
4647
break
4748
}
49+
case SchemaValidationLibrary.ZOD4: {
50+
content = await ModelToZod4.Generate(model)
51+
break
52+
}
4853
case SchemaValidationLibrary.YUP: {
4954
content = await ModelToYup.Generate(model)
5055
break

src/constants/library.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const SchemaValidationLibrary = {
22
ZOD: 'zod',
3+
ZOD4: 'zod4',
34
YUP: 'yup',
45
VALIBOT: 'valibot',
56
EFFECT: 'effect',

0 commit comments

Comments
 (0)