Skip to content

Commit e33bc24

Browse files
committed
fix: incorrect typing when Prisma client extension is used with logical client
1 parent be82307 commit e33bc24

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ export function enhance<ExtArgs extends Record<string, any> & InternalArgs>(
173173
};
174174
175175
// overload for extended PrismaClient
176-
export function enhance<TypeMap extends TypeMapDef, TypeMapCb extends TypeMapCbDef, ExtArgs extends Record<string, any> & InternalArgs${
177-
hasClientOptions ? ', ClientOptions' : ''
178-
}>(
179-
prisma: DynamicClientExtensionThis<TypeMap, TypeMapCb, ExtArgs${hasClientOptions ? ', ClientOptions' : ''}>,
180-
context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap, Prisma.TypeMapCb, ExtArgs${
176+
export function enhance<ExtArgs extends Record<string, any> & InternalArgs${hasClientOptions ? ', ClientOptions' : ''}>(
177+
prisma: DynamicClientExtensionThis<Prisma.TypeMap<ExtArgs>, Prisma.TypeMapCb, ExtArgs${
178+
hasClientOptions ? ', ClientOptions' : ''
179+
}>,
180+
context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis<Prisma.TypeMap<ExtArgs>, Prisma.TypeMapCb, ExtArgs${
181181
hasClientOptions ? ', ClientOptions' : ''
182182
}>${this.generatePermissionChecker ? ' & ModelCheckers' : ''};
183183
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
describe('issue 1493', () => {
3+
it('regression', async () => {
4+
await loadSchema(
5+
`
6+
datasource db {
7+
provider = 'sqlite'
8+
url = 'file:./dev.db'
9+
}
10+
11+
generator js {
12+
provider = 'prisma-client-js'
13+
}
14+
15+
plugin enhancer {
16+
provider = '@core/enhancer'
17+
output = './zenstack'
18+
}
19+
20+
model User {
21+
id Int @id
22+
email String
23+
posts Post[]
24+
}
25+
26+
model Post {
27+
id Int @id
28+
title String
29+
content String
30+
author User @relation(fields: [authorId], references: [id])
31+
authorId Int @default(auth().id)
32+
}
33+
`,
34+
{
35+
addPrelude: false,
36+
compile: true,
37+
getPrismaOnly: true,
38+
extraSourceFiles: [
39+
{
40+
name: 'main.ts',
41+
content: `
42+
import { PrismaClient } from '@prisma/client';
43+
import { enhance } from './zenstack/enhance';
44+
const prisma = new PrismaClient().$extends({
45+
result: {
46+
user: {
47+
gravatarUrl: {
48+
needs: { email: true },
49+
compute(user) {
50+
return user.email + 'hash';
51+
},
52+
},
53+
},
54+
},
55+
});
56+
57+
prisma.user.findFirst().then((user) => user?.gravatarUrl);
58+
const db = enhance(prisma, undefined, { kinds: [] });
59+
db.user.findFirst().then((user) => user?.gravatarUrl);
60+
`,
61+
},
62+
],
63+
}
64+
);
65+
});
66+
});

0 commit comments

Comments
 (0)