diff --git a/packages/schema/src/plugins/enhancer/enhance/index.ts b/packages/schema/src/plugins/enhancer/enhance/index.ts index cef6efced..0da689e49 100644 --- a/packages/schema/src/plugins/enhancer/enhance/index.ts +++ b/packages/schema/src/plugins/enhancer/enhance/index.ts @@ -147,12 +147,7 @@ export function enhance(prisma: DbClient, context?: Enh private createLogicalPrismaImports(prismaImport: string, logicalPrismaClientDir: string) { return `import { Prisma as _Prisma, PrismaClient as _PrismaClient } from '${prismaImport}'; -import type { - InternalArgs, - TypeMapDef, - TypeMapCbDef, - DynamicClientExtensionThis, -} from '${prismaImport}/runtime/library'; +import type { InternalArgs, DynamicClientExtensionThis } from '${prismaImport}/runtime/library'; import type * as _P from '${logicalPrismaClientDir}/index-fixed'; import type { Prisma, PrismaClient } from '${logicalPrismaClientDir}/index-fixed'; `; @@ -173,11 +168,11 @@ export function enhance & InternalArgs>( }; // overload for extended PrismaClient -export function enhance & InternalArgs${ - hasClientOptions ? ', ClientOptions' : '' - }>( - prisma: DynamicClientExtensionThis, - context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis & InternalArgs${hasClientOptions ? ', ClientOptions' : ''}>( + prisma: DynamicClientExtensionThis<_Prisma.TypeMap, _Prisma.TypeMapCb, ExtArgs${ + hasClientOptions ? ', ClientOptions' : '' + }>, + context?: EnhancementContext<${authTypeParam}>, options?: EnhancementOptions): DynamicClientExtensionThis, Prisma.TypeMapCb, ExtArgs${ hasClientOptions ? ', ClientOptions' : '' }>${this.generatePermissionChecker ? ' & ModelCheckers' : ''}; diff --git a/tests/regression/tests/issue-1493.test.ts b/tests/regression/tests/issue-1493.test.ts new file mode 100644 index 000000000..aa1bbb3af --- /dev/null +++ b/tests/regression/tests/issue-1493.test.ts @@ -0,0 +1,66 @@ +import { loadSchema } from '@zenstackhq/testtools'; +describe('issue 1493', () => { + it('regression', async () => { + await loadSchema( + ` + datasource db { + provider = 'sqlite' + url = 'file:./dev.db' + } + + generator js { + provider = 'prisma-client-js' + } + + plugin enhancer { + provider = '@core/enhancer' + output = './zenstack' + } + + model User { + id Int @id + email String + posts Post[] + } + + model Post { + id Int @id + title String + content String + author User @relation(fields: [authorId], references: [id]) + authorId Int @default(auth().id) + } + `, + { + addPrelude: false, + compile: true, + getPrismaOnly: true, + extraSourceFiles: [ + { + name: 'main.ts', + content: ` + import { PrismaClient } from '@prisma/client'; + import { enhance } from './zenstack/enhance'; + const prisma = new PrismaClient().$extends({ + result: { + user: { + gravatarUrl: { + needs: { email: true }, + compute(user) { + return user.email + 'hash'; + }, + }, + }, + }, + }); + + prisma.user.findFirst().then((user) => user?.gravatarUrl); + const db = enhance(prisma, undefined, { kinds: [] }); + db.user.findFirst().then((user) => user?.gravatarUrl); + `, + }, + ], + } + ); + }); +});