Skip to content

Commit

Permalink
fix: support for Prisma 5.16.0 (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Jun 28, 2024
1 parent 303f103 commit 0a293ca
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"zod-validation-error": "^1.5.0"
},
"peerDependencies": {
"@prisma/client": "5.0.0 - 5.15.x"
"@prisma/client": "5.0.0 - 5.16.x"
},
"author": {
"name": "ZenStack Team"
Expand Down
6 changes: 3 additions & 3 deletions packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@
"zod-validation-error": "^1.5.0"
},
"peerDependencies": {
"prisma": "5.0.0 - 5.15.x"
"prisma": "5.0.0 - 5.16.x"
},
"devDependencies": {
"@prisma/client": "5.15.x",
"@prisma/client": "5.16.x",
"@types/async-exit-hook": "^2.0.0",
"@types/pluralize": "^0.0.29",
"@types/semver": "^7.3.13",
Expand All @@ -136,7 +136,7 @@
"@zenstackhq/runtime": "workspace:*",
"dotenv": "^16.0.3",
"esbuild": "^0.15.12",
"prisma": "5.15.x",
"prisma": "5.16.x",
"renamer": "^4.0.0",
"tmp": "^0.2.1",
"tsc-alias": "^1.7.0",
Expand Down
17 changes: 12 additions & 5 deletions packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ import type { Prisma, PrismaClient } from '${logicalPrismaClientDir}/index-fixed
}

private createLogicalPrismaEnhanceFunction(authTypeParam: string) {
const prismaVersion = getPrismaVersion();

// Prisma 5.16.0 introduced a new generic parameter to `DynamicClientExtensionThis`
const hasClientOptions = prismaVersion && semver.gte(prismaVersion, '5.16.0');

return `
// overload for plain PrismaClient
export function enhance<ExtArgs extends Record<string, any> & InternalArgs>(
Expand All @@ -168,11 +173,13 @@ export function enhance<ExtArgs extends Record<string, any> & InternalArgs>(
};
// overload for extended PrismaClient
export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs>(
prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs>,
context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs>${
this.generatePermissionChecker ? ' & ModelCheckers' : ''
};
export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs${
hasClientOptions ? ', ClientOptions' : ''
}>(
prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs${hasClientOptions ? ', ClientOptions' : ''}>,
context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs${
hasClientOptions ? ', ClientOptions' : ''
}>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};
export function enhance(prisma: any, context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): any {
return createEnhancement(prisma, {
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"@prisma/generator-helper": "5.15.x",
"@prisma/internals": "5.15.x",
"@prisma/generator-helper": "5.16.x",
"@prisma/internals": "5.16.x",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"langium": "1.3.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/testtools/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export type SchemaLoadOptions = {
preserveTsFiles?: boolean;
generatePermissionChecker?: boolean;
previewFeatures?: string[];
prismaClientOptions?: object;
};

const defaultOptions: SchemaLoadOptions = {
Expand Down Expand Up @@ -254,7 +255,12 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) {
});

const PrismaClient = require(path.join(projectDir, 'node_modules/.prisma/client')).PrismaClient;
let prisma = new PrismaClient({ log: ['info', 'warn', 'error'] });

let clientOptions: object = { log: ['info', 'warn', 'error'] };
if (options?.prismaClientOptions) {
clientOptions = { ...clientOptions, ...options.prismaClientOptions };
}
let prisma = new PrismaClient(clientOptions);
// https://github.com/prisma/prisma/issues/18292
prisma[Symbol.for('nodejs.util.inspect.custom')] = 'PrismaClient';

Expand Down
102 changes: 51 additions & 51 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion script/test-scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ function run(cmd: string) {
}

run('npm init -y');
run('npm i --no-audit --no-fund typescript prisma@5.15.x @prisma/client@5.15.x zod decimal.js @types/node');
run('npm i --no-audit --no-fund typescript prisma@5.16.x @prisma/client@5.16.x zod decimal.js @types/node');

console.log('Test scaffold setup complete.');
4 changes: 2 additions & 2 deletions tests/integration/test-run/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "5.15.x",
"@prisma/client": "5.16.x",
"@zenstackhq/runtime": "file:../../../packages/runtime/dist",
"prisma": "5.15.x",
"prisma": "5.16.x",
"react": "^18.2.0",
"swr": "^1.3.0",
"typescript": "^4.9.3",
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tests/cli/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('CLI Plugins Tests', () => {
'swr',
'@tanstack/react-query@^5.0.0',
'@trpc/server',
'@prisma/client@5.15.x',
'@prisma/client@5.16.x',
`${path.join(__dirname, '../../../../.build/zenstackhq-language-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../.build/zenstackhq-sdk-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../.build/zenstackhq-runtime-' + ver + '.tgz')}`,
Expand All @@ -85,7 +85,7 @@ describe('CLI Plugins Tests', () => {
const devDepPkgs = [
'typescript',
'@types/react',
'prisma@5.15.x',
'prisma@5.16.x',
`${path.join(__dirname, '../../../../.build/zenstack-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../.build/zenstackhq-tanstack-query-' + ver + '.tgz')}`,
`${path.join(__dirname, '../../../../.build/zenstackhq-swr-' + ver + '.tgz')}`,
Expand Down
Loading

0 comments on commit 0a293ca

Please sign in to comment.