From 39a2d6f2065af34bb9ef3977d55a7a9095b06bb5 Mon Sep 17 00:00:00 2001 From: PodkopovP <113348735+PodkopovP@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:36:09 +0100 Subject: [PATCH 1/2] feat(handler): add 'count' operation to FindOperations and update count method implementation --- .../src/enhancements/node/policy/handler.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/runtime/src/enhancements/node/policy/handler.ts b/packages/runtime/src/enhancements/node/policy/handler.ts index f42dad01f..828977d18 100644 --- a/packages/runtime/src/enhancements/node/policy/handler.ts +++ b/packages/runtime/src/enhancements/node/policy/handler.ts @@ -35,7 +35,7 @@ type PostWriteCheckRecord = { preValue?: any; }; -type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFirstOrThrow' | 'findMany'; +type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFirstOrThrow' | 'findMany' | 'count'; /** * Prisma proxy handler for injecting access policy check. @@ -144,6 +144,10 @@ export class PolicyProxyHandler implements Pr this.logger.info(`[policy] \`${actionName}\` ${this.model}:\n${formatObject(_args)}`); } + if (actionName === 'count') { + _args.select = true; + } + const result = await this.modelClient[actionName](_args); return this.policyUtils.postProcessForRead(result, this.model, origArgs); } @@ -1650,16 +1654,7 @@ export class PolicyProxyHandler implements Pr } count(args: any) { - return createDeferredPromise(() => { - // inject policy conditions - args = args ? this.policyUtils.safeClone(args) : {}; - this.policyUtils.injectAuthGuardAsWhere(this.prisma, args, this.model, 'read'); - - if (this.shouldLogQuery) { - this.logger.info(`[policy] \`count\` ${this.model}:\n${formatObject(args)}`); - } - return this.modelClient.count(args); - }); + return createDeferredPromise(() => this.doFind(args, 'findMany', () => [])); } //#endregion From 0de0b7d57c8722f6f9166541df28aa1644978d8f Mon Sep 17 00:00:00 2001 From: PodkopovP <113348735+PodkopovP@users.noreply.github.com> Date: Tue, 24 Jun 2025 15:41:38 +0100 Subject: [PATCH 2/2] fix(handler): update count method to use 'count' operation in doFind --- packages/runtime/src/enhancements/node/policy/handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime/src/enhancements/node/policy/handler.ts b/packages/runtime/src/enhancements/node/policy/handler.ts index 828977d18..8d3d496be 100644 --- a/packages/runtime/src/enhancements/node/policy/handler.ts +++ b/packages/runtime/src/enhancements/node/policy/handler.ts @@ -1654,7 +1654,7 @@ export class PolicyProxyHandler implements Pr } count(args: any) { - return createDeferredPromise(() => this.doFind(args, 'findMany', () => [])); + return createDeferredPromise(() => this.doFind(args, 'count', () => [])); } //#endregion