From 46728754d9da71c71f7eb9fc53ecbaf559bf7438 Mon Sep 17 00:00:00 2001 From: Jason MacDonald <5718527+jasonmacdonald@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:42:13 -0400 Subject: [PATCH 1/8] feat(nestjs): Add prop as optional parameter of getEnhancedPrisma #1537 (#1538) Co-authored-by: Jason MacDonald --- packages/server/src/nestjs/zenstack.module.ts | 4 +- packages/server/tests/adapter/nestjs.test.ts | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/server/src/nestjs/zenstack.module.ts b/packages/server/src/nestjs/zenstack.module.ts index f2ae601c6..a113fb84d 100644 --- a/packages/server/src/nestjs/zenstack.module.ts +++ b/packages/server/src/nestjs/zenstack.module.ts @@ -12,7 +12,7 @@ export interface ZenStackModuleOptions { /** * A callback for getting an enhanced `PrismaClient`. */ - getEnhancedPrisma: () => unknown; + getEnhancedPrisma: (model?: string | symbol ) => unknown; } /** @@ -79,7 +79,7 @@ export class ZenStackModule { { get(_target, prop) { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const enhancedPrisma: any = getEnhancedPrisma(); + const enhancedPrisma: any = getEnhancedPrisma(prop); if (!enhancedPrisma) { throw new Error('`getEnhancedPrisma` must return a valid Prisma client'); } diff --git a/packages/server/tests/adapter/nestjs.test.ts b/packages/server/tests/adapter/nestjs.test.ts index 6cfa48617..d28a3ecc8 100644 --- a/packages/server/tests/adapter/nestjs.test.ts +++ b/packages/server/tests/adapter/nestjs.test.ts @@ -160,4 +160,53 @@ describe('NestJS adapter tests', () => { const postSvc = app.get('PostService'); await expect(postSvc.findAll()).resolves.toHaveLength(1); }); + + it('pass property', async () => { + const { prisma, enhanceRaw } = await loadSchema(schema); + + await prisma.user.create({ + data: { + posts: { + create: [ + { title: 'post1', published: true }, + { title: 'post2', published: false }, + ], + }, + }, + }); + + const moduleRef = await Test.createTestingModule({ + imports: [ + ZenStackModule.registerAsync({ + useFactory: (prismaService) => ({ + getEnhancedPrisma: (prop) => { + return prop === 'post' ? prismaService : enhanceRaw(prismaService, { user: { id: 2 } }); + }, + }), + inject: ['PrismaService'], + extraProviders: [ + { + provide: 'PrismaService', + useValue: prisma, + }, + ], + }), + ], + providers: [ + { + provide: 'PostService', + useFactory: (enhancedPrismaService) => ({ + findAll: () => enhancedPrismaService.post.findMany(), + }), + inject: [ENHANCED_PRISMA], + }, + ], + }).compile(); + + const app = moduleRef.createNestApplication(); + await app.init(); + + const postSvc = app.get('PostService'); + await expect(postSvc.findAll()).resolves.toHaveLength(2); + }); }); From a11ab8c59d67bffac5f33aa3964722e2fd5a97ae Mon Sep 17 00:00:00 2001 From: Yiming Date: Sat, 13 Jul 2024 21:27:38 -0700 Subject: [PATCH 2/8] chore: update Jetbrains changelog (#1584) --- packages/ide/jetbrains/.idea/gradle.xml | 1 + packages/ide/jetbrains/CHANGELOG.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/packages/ide/jetbrains/.idea/gradle.xml b/packages/ide/jetbrains/.idea/gradle.xml index ce1c62c7c..2e2f480f5 100644 --- a/packages/ide/jetbrains/.idea/gradle.xml +++ b/packages/ide/jetbrains/.idea/gradle.xml @@ -5,6 +5,7 @@