diff --git a/package.json b/package.json index 1780fc2..bad3d87 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ ] }, "dependencies": { - "zod": "^3.23.8" + "zod": "^4.0.17" }, "devDependencies": { "@swc/core": "^1.5.29", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ceabca7..b37dfd4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: zod: - specifier: ^3.23.8 - version: 3.23.8 + specifier: ^4.0.17 + version: 4.0.17 devDependencies: '@swc/core': specifier: ^1.5.29 @@ -3271,8 +3271,8 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} - zod@3.23.8: - resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} + zod@4.0.17: + resolution: {integrity: sha512-1PHjlYRevNxxdy2JZ8JcNAw7rX8V9P1AKkP+x/xZfxB0K5FYfuV+Ug6P/6NVSR2jHQ+FzDDoDHS04nYUsOIyLQ==} snapshots: @@ -6788,4 +6788,4 @@ snapshots: yocto-queue@1.0.0: {} - zod@3.23.8: {} + zod@4.0.17: {} diff --git a/src/routeHandlerBuilder.test.ts b/src/routeHandlerBuilder.test.ts index ef3c460..8c4674a 100644 --- a/src/routeHandlerBuilder.test.ts +++ b/src/routeHandlerBuilder.test.ts @@ -1,11 +1,11 @@ import { describe, expect, expectTypeOf, it } from 'vitest'; -import { z } from 'zod'; +import { z } from 'zod/v4'; import { createZodRoute } from './createZodRoute'; import { MiddlewareFunction } from './types'; const paramsSchema = z.object({ - id: z.string().uuid(), + id: z.uuid(), }); const querySchema = z.object({ @@ -60,6 +60,7 @@ describe('query validation', () => { it('should validate and handle valid query', async () => { const GET = createZodRoute() .params(paramsSchema) + .query(querySchema) .handler((request, context) => { expectTypeOf(context.query).toMatchTypeOf>(); const search = context.query.search; @@ -93,6 +94,7 @@ describe('query validation', () => { it('should validate and handle valid query when query is array', async () => { const GET = createZodRoute() .params(paramsSchema) + .query(querySchema) .handler((request, context) => { expectTypeOf(context.query).toMatchTypeOf>(); const status = context.query.status; diff --git a/src/routeHandlerBuilder.ts b/src/routeHandlerBuilder.ts index 6f90383..2a6bedc 100644 --- a/src/routeHandlerBuilder.ts +++ b/src/routeHandlerBuilder.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-named-as-default -import z from 'zod'; +import z from 'zod/v4'; import { HandlerFunction, @@ -40,7 +40,7 @@ export class RouteHandlerBuilder< }; readonly middlewares: Array, z.infer>>; readonly handleServerError?: HandlerServerErrorFn; - readonly metadataValue: z.infer; + readonly metadataValue?: z.infer; readonly contextType!: TContext; constructor({ @@ -116,8 +116,11 @@ export class RouteHandlerBuilder< */ defineMetadata(schema: T) { return new RouteHandlerBuilder({ - ...this, config: { ...this.config, metadataSchema: schema }, + middlewares: [], + handleServerError: this.handleServerError, + contextType: this.contextType, + metadataValue: undefined, }); } @@ -199,7 +202,7 @@ export class RouteHandlerBuilder< JSON.stringify({ message: 'Invalid params', errors: paramsResult.error.issues }), ); } - params = paramsResult.data; + params = paramsResult.data as Record; } // Validate the query against the provided schema diff --git a/src/types.ts b/src/types.ts index 627d187..50484cd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Schema } from 'zod'; +import { Schema } from 'zod/v4'; /** * Function that is called when the route handler is executed and all the middleware has been executed