From f6bb6fdaf4a94eb250711656345b770d0308bb8a Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 7 Sep 2025 12:31:20 -0700 Subject: [PATCH 1/3] chore: run tests with zod4 --- LICENSE | 2 +- packages/LICENSE | 2 +- script/test-scaffold.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 91d4584d3..46a34ef46 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 ZenStack +Copyright (c) 2025 ZenStack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/packages/LICENSE b/packages/LICENSE index 91d4584d3..46a34ef46 100644 --- a/packages/LICENSE +++ b/packages/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 ZenStack +Copyright (c) 2025 ZenStack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/script/test-scaffold.ts b/script/test-scaffold.ts index b9c4aae4d..71f80bd25 100644 --- a/script/test-scaffold.ts +++ b/script/test-scaffold.ts @@ -20,7 +20,7 @@ function run(cmd: string) { run('npm init -y'); run( - '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' + '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' ); console.log('Test scaffold setup complete.'); From 8e5ab96ca9b04c3d9d1dc1f0c0390ab13f33b0a6 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:49:13 -0700 Subject: [PATCH 2/3] additional fixes --- packages/runtime/package.json | 23 ++++++++++--------- .../src/enhancements/node/policy/handler.ts | 2 +- pnpm-lock.yaml | 17 ++++++++++---- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 696553a1d..d5caf079e 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -112,15 +112,6 @@ "uuid": "^9.0.0", "zod-validation-error": "catalog:" }, - "peerDependencies": { - "@prisma/client": "5.0.0 - 6.15.x", - "zod": "catalog:" - }, - "author": { - "name": "ZenStack Team" - }, - "homepage": "https://zenstack.dev", - "license": "MIT", "devDependencies": { "@types/bcryptjs": "^2.4.2", "@types/pluralize": "^0.0.29", @@ -129,6 +120,16 @@ "@types/uuid": "^8.3.4", "decimal.js-light": "^2.5.1", "superjson": "^1.13.0", - "uuid": "^9.0.0" - } + "uuid": "^9.0.0", + "zod": "^4.0.0" + }, + "peerDependencies": { + "@prisma/client": "5.0.0 - 6.15.x", + "zod": "catalog:" + }, + "author": { + "name": "ZenStack Team" + }, + "homepage": "https://zenstack.dev", + "license": "MIT" } diff --git a/packages/runtime/src/enhancements/node/policy/handler.ts b/packages/runtime/src/enhancements/node/policy/handler.ts index a220fedd1..765d162b4 100644 --- a/packages/runtime/src/enhancements/node/policy/handler.ts +++ b/packages/runtime/src/enhancements/node/policy/handler.ts @@ -1262,7 +1262,7 @@ export class PolicyProxyHandler implements Pr {} ); - const validatedData = this.policyUtils.validateZodSchema(model, 'update', literalData, false, (err) => { + const validatedData: any = this.policyUtils.validateZodSchema(model, 'update', literalData, false, (err) => { throw this.policyUtils.deniedByPolicy( model, 'update', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffb106501..ed48115d5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -421,12 +421,9 @@ importers: uuid: specifier: ^9.0.0 version: 9.0.1 - zod: - specifier: 'catalog:' - version: 3.25.76 zod-validation-error: specifier: 'catalog:' - version: 4.0.1(zod@3.25.76) + version: 4.0.1(zod@4.1.5) devDependencies: '@types/bcryptjs': specifier: ^2.4.2 @@ -443,6 +440,9 @@ importers: '@types/uuid': specifier: ^8.3.4 version: 8.3.4 + zod: + specifier: ^4.0.0 + version: 4.1.5 publishDirectory: dist packages/schema: @@ -8796,6 +8796,9 @@ packages: zod@3.25.76: resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==} + zod@4.1.5: + resolution: {integrity: sha512-rcUUZqlLJgBC33IT3PNMgsCq6TzLQEG/Ei/KTCU0PedSWRMAXoOUN+4t/0H+Q8bdnLPdqUYnvboJT0bn/229qg==} + zone.js@0.15.1: resolution: {integrity: sha512-XE96n56IQpJM7NAoXswY3XRLcWFW83xe0BiAOeMD7K5k5xecOeul3Qcpx6GqEeeHNkW5DWL5zOyTbEfB4eti8w==} @@ -17946,6 +17949,12 @@ snapshots: dependencies: zod: 3.25.76 + zod-validation-error@4.0.1(zod@4.1.5): + dependencies: + zod: 4.1.5 + zod@3.25.76: {} + zod@4.1.5: {} + zone.js@0.15.1: {} From 1a256c64c7c4b2d004c65a916d9044a6f59f3e46 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 7 Sep 2025 23:55:55 -0700 Subject: [PATCH 3/3] fix lazy schema unwrapping --- packages/runtime/src/zod-utils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/runtime/src/zod-utils.ts b/packages/runtime/src/zod-utils.ts index 1ebaf9cdc..beb19409c 100644 --- a/packages/runtime/src/zod-utils.ts +++ b/packages/runtime/src/zod-utils.ts @@ -121,5 +121,14 @@ function countUnrecognizedKeys(issues: Z.ZodIssue[]) { } function unwrapLazy(z: typeof Z, schema: T | Z.ZodLazy): T { - return schema instanceof z.ZodLazy ? schema.schema : schema; + if (!(schema instanceof z.ZodLazy)) { + return schema; + } + if ('unwrap' in schema && typeof schema.unwrap === 'function') { + return schema.unwrap(); + } else if ('schema' in schema) { + return schema.schema as T; + } else { + throw new Error('Unable to determine how to unwrap a lazy schema with this zod version.'); + } }