Skip to content

Commit 11b83fa

Browse files
authored
Merge pull request #19 from Melvynx/zod-v4-upgrade
feat: upgrade to Zod v4.0.17 with 3x performance improvement
2 parents f402b15 + 7534cfb commit 11b83fa

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
]
5555
},
5656
"dependencies": {
57-
"zod": "^3.23.8"
57+
"zod": "^4.0.17"
5858
},
5959
"devDependencies": {
6060
"@swc/core": "^1.5.29",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routeHandlerBuilder.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createZodRoute } from './createZodRoute';
55
import { MiddlewareFunction } from './types';
66

77
const paramsSchema = z.object({
8-
id: z.string().uuid(),
8+
id: z.uuid(),
99
});
1010

1111
const querySchema = z.object({
@@ -60,6 +60,7 @@ describe('query validation', () => {
6060
it('should validate and handle valid query', async () => {
6161
const GET = createZodRoute()
6262
.params(paramsSchema)
63+
.query(querySchema)
6364
.handler((request, context) => {
6465
expectTypeOf(context.query).toMatchTypeOf<z.infer<typeof querySchema>>();
6566
const search = context.query.search;
@@ -93,6 +94,7 @@ describe('query validation', () => {
9394
it('should validate and handle valid query when query is array', async () => {
9495
const GET = createZodRoute()
9596
.params(paramsSchema)
97+
.query(querySchema)
9698
.handler((request, context) => {
9799
expectTypeOf(context.query).toMatchTypeOf<z.infer<typeof querySchema>>();
98100
const status = context.query.status;

src/routeHandlerBuilder.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line import/no-named-as-default
2-
import z from 'zod';
2+
import z from 'zod/v4';
33

44
import {
55
HandlerFunction,
@@ -40,7 +40,7 @@ export class RouteHandlerBuilder<
4040
};
4141
readonly middlewares: Array<MiddlewareFunction<TContext, Record<string, unknown>, z.infer<TMetadata>>>;
4242
readonly handleServerError?: HandlerServerErrorFn;
43-
readonly metadataValue: z.infer<TMetadata>;
43+
readonly metadataValue?: z.infer<TMetadata>;
4444
readonly contextType!: TContext;
4545

4646
constructor({
@@ -116,8 +116,11 @@ export class RouteHandlerBuilder<
116116
*/
117117
defineMetadata<T extends z.Schema>(schema: T) {
118118
return new RouteHandlerBuilder<TParams, TQuery, TBody, TContext, T>({
119-
...this,
120119
config: { ...this.config, metadataSchema: schema },
120+
middlewares: [],
121+
handleServerError: this.handleServerError,
122+
contextType: this.contextType,
123+
metadataValue: undefined,
121124
});
122125
}
123126

@@ -199,7 +202,7 @@ export class RouteHandlerBuilder<
199202
JSON.stringify({ message: 'Invalid params', errors: paramsResult.error.issues }),
200203
);
201204
}
202-
params = paramsResult.data;
205+
params = paramsResult.data as Record<string, unknown>;
203206
}
204207

205208
// Validate the query against the provided schema

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/ban-types */
22

33
/* eslint-disable @typescript-eslint/no-explicit-any */
4-
import { Schema } from 'zod';
4+
import { Schema } from 'zod/v4';
55

66
/**
77
* Function that is called when the route handler is executed and all the middleware has been executed

0 commit comments

Comments
 (0)