From e40779eb4a7a734e9bb6d17314f0376158ee6c19 Mon Sep 17 00:00:00 2001 From: Yiming Date: Fri, 12 Jul 2024 10:05:46 -0700 Subject: [PATCH 1/2] merge dev to main (v2.3.0) (#1582) Co-authored-by: Jason MacDonald <5718527+jasonmacdonald@users.noreply.github.com> 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 5034fdc50387a0490693285cada09a18155564ee Mon Sep 17 00:00:00 2001 From: Yiming Date: Sun, 14 Jul 2024 19:42:55 -0700 Subject: [PATCH 2/2] merge dev to main (v2.3.1) (#1593) Co-authored-by: Jason MacDonald <5718527+jasonmacdonald@users.noreply.github.com> Co-authored-by: Jason MacDonald --- package.json | 2 +- packages/ide/jetbrains/.idea/gradle.xml | 1 + packages/ide/jetbrains/CHANGELOG.md | 7 ++ packages/ide/jetbrains/build.gradle.kts | 2 +- packages/ide/jetbrains/package.json | 2 +- packages/language/package.json | 2 +- packages/misc/redwood/package.json | 2 +- packages/plugins/openapi/package.json | 2 +- packages/plugins/swr/package.json | 2 +- packages/plugins/tanstack-query/package.json | 2 +- packages/plugins/trpc/package.json | 2 +- packages/runtime/package.json | 2 +- packages/runtime/src/enhancements/delegate.ts | 105 ++++++++--------- .../src/enhancements/policy/handler.ts | 2 +- .../src/enhancements/policy/policy-utils.ts | 8 +- packages/runtime/src/enhancements/proxy.ts | 4 +- packages/schema/package.json | 2 +- .../enhancer/enhance/auth-type-generator.ts | 61 +++------- packages/sdk/package.json | 2 +- packages/server/package.json | 2 +- packages/testtools/package.json | 2 +- .../with-delegate/enhanced-client.test.ts | 108 +++++++++++++++++- .../enhancements/with-policy/auth.test.ts | 26 +++++ tests/regression/tests/issue-1574.test.ts | 108 ++++++++++++++++++ tests/regression/tests/issue-1576.test.ts | 63 ++++++++++ tests/regression/tests/issue-1585.test.ts | 30 +++++ 26 files changed, 439 insertions(+), 112 deletions(-) create mode 100644 tests/regression/tests/issue-1574.test.ts create mode 100644 tests/regression/tests/issue-1576.test.ts create mode 100644 tests/regression/tests/issue-1585.test.ts diff --git a/package.json b/package.json index 0bb385fba..427a3c8e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenstack-monorepo", - "version": "2.3.0", + "version": "2.3.1", "description": "", "scripts": { "build": "pnpm -r build", 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 @@