Skip to content

Commit 7e871fd

Browse files
committed
fix: zod4 compatibility with server package
1 parent 1a256c6 commit 7e871fd

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

packages/server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"superjson": "^1.13.0",
3232
"ts-japi": "^1.10.1",
3333
"url-pattern": "^1.0.3",
34-
"zod-validation-error": "catalog:",
3534
"decimal.js": "^10.4.2"
3635
},
3736
"peerDependencies": {
@@ -57,7 +56,8 @@
5756
"next": "14.2.4",
5857
"nuxt": "^3.7.4",
5958
"reflect-metadata": "^0.2.2",
60-
"supertest": "^6.3.3"
59+
"supertest": "^6.3.3",
60+
"zod": "^4.0.0"
6161
},
6262
"exports": {
6363
"./package.json": "./package.json",

packages/server/src/api/rest/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class RequestHandler extends APIHandlerBase {
201201
attributes: z.object({}).passthrough().optional(),
202202
relationships: z
203203
.record(
204+
z.string(),
204205
z.object({
205206
data: z.union([
206207
z.object({ type: z.string(), id: z.union([z.string(), z.number()]) }),
@@ -1973,7 +1974,7 @@ class RequestHandler extends APIHandlerBase {
19731974
detail?: string,
19741975
status?: number,
19751976
reason?: string,
1976-
zodErrors?: ZodError
1977+
zodErrors?: ZodError<any>
19771978
) {
19781979
const error: any = {
19791980
status: status ?? this.errors[code].status,

packages/server/src/api/rpc/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {
77
isPrismaClientUnknownRequestError,
88
isPrismaClientValidationError,
99
} from '@zenstackhq/runtime';
10-
import { upperCaseFirst } from '@zenstackhq/runtime/local-helpers';
10+
import { upperCaseFirst, getZodErrorMessage } from '@zenstackhq/runtime/local-helpers';
1111
import SuperJSON from 'superjson';
1212
import { ZodError } from 'zod';
13-
import { fromZodError } from 'zod-validation-error/v3';
1413
import { Response } from '../../types';
1514
import { APIHandlerBase, RequestContext } from '../base';
1615
import { logError, registerCustomSerializers } from '../utils';
@@ -202,7 +201,8 @@ class RequestHandler extends APIHandlerBase {
202201
}
203202
}
204203

205-
private makeError(message: string, reason?: string, zodErrors?: ZodError) {
204+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
205+
private makeError(message: string, reason?: string, zodErrors?: ZodError<any>) {
206206
// eslint-disable-next-line @typescript-eslint/no-explicit-any
207207
const error: any = { message, reason };
208208
if (reason === CrudFailureReason.ACCESS_POLICY_VIOLATION || reason === CrudFailureReason.RESULT_NOT_READABLE) {
@@ -251,7 +251,7 @@ class RequestHandler extends APIHandlerBase {
251251
} else {
252252
return {
253253
data: undefined,
254-
error: fromZodError(parseResult.error).message,
254+
error: getZodErrorMessage(parseResult.error),
255255
zodErrors: parseResult.error,
256256
};
257257
}

pnpm-lock.yaml

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

script/test-scaffold.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function run(cmd: string) {
2020

2121
run('npm init -y');
2222
run(
23-
'npm i --no-audit --no-fund typescript@~5.8.0 prisma@6.11.x @prisma/client@6.11.x zod@^4.0.0 decimal.js @types/node'
23+
'npm i --no-audit --no-fund typescript@~5.8.0 prisma@6.11.x @prisma/client@6.11.x zod@^3.25.0 decimal.js @types/node'
2424
);
2525

2626
console.log('Test scaffold setup complete.');

0 commit comments

Comments
 (0)