|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 |
|
3 | 3 | import deepmerge from 'deepmerge'; |
4 | | -import { z, type ZodError, type ZodObject, type ZodSchema } from 'zod'; |
| 4 | +import type { z, ZodError, ZodObject, ZodSchema } from 'zod'; |
| 5 | +import { z as zod3 } from 'zod/v3'; |
| 6 | +import { z as zod4 } from 'zod/v4'; |
5 | 7 | import { CrudFailureReason, PrismaErrorCode } from '../../../constants'; |
6 | 8 | import { |
7 | 9 | clone, |
@@ -1376,17 +1378,19 @@ export class PolicyUtil extends QueryUtils { |
1376 | 1378 | let schema: ZodObject<any> | undefined; |
1377 | 1379 |
|
1378 | 1380 | const overridePasswordFields = (schema: z.ZodObject<any>) => { |
| 1381 | + const useZod: any = schema._def ? zod3 : zod4; |
| 1382 | + |
1379 | 1383 | let result = schema; |
1380 | 1384 | const modelFields = this.modelMeta.models[lowerCaseFirst(model)]?.fields; |
1381 | 1385 | if (modelFields) { |
1382 | 1386 | for (const [key, field] of Object.entries(modelFields)) { |
1383 | 1387 | if (field.attributes?.some((attr) => attr.name === '@password')) { |
1384 | 1388 | // override `@password` field schema with a string schema |
1385 | | - let pwFieldSchema: ZodSchema = z.string(); |
| 1389 | + let pwFieldSchema: ZodSchema = useZod.string(); |
1386 | 1390 | if (field.isOptional) { |
1387 | 1391 | pwFieldSchema = pwFieldSchema.nullish(); |
1388 | 1392 | } |
1389 | | - result = result.merge(z.object({ [key]: pwFieldSchema })); |
| 1393 | + result = result.merge(useZod.object({ [key]: pwFieldSchema })); |
1390 | 1394 | } |
1391 | 1395 | } |
1392 | 1396 | } |
@@ -1540,7 +1544,12 @@ export class PolicyUtil extends QueryUtils { |
1540 | 1544 | continue; |
1541 | 1545 | } |
1542 | 1546 |
|
1543 | | - if (fieldInfo.isDataModel && queryArgs?.include && typeof queryArgs.include === 'object' && !queryArgs.include[field]) { |
| 1547 | + if ( |
| 1548 | + fieldInfo.isDataModel && |
| 1549 | + queryArgs?.include && |
| 1550 | + typeof queryArgs.include === 'object' && |
| 1551 | + !queryArgs.include[field] |
| 1552 | + ) { |
1544 | 1553 | // respect include |
1545 | 1554 | delete entityData[field]; |
1546 | 1555 | continue; |
|
0 commit comments