@@ -4,6 +4,7 @@ import { lowerCaseFirst } from 'lower-case-first';
44import invariant from 'tiny-invariant' ;
55import { upperCaseFirst } from 'upper-case-first' ;
66import { fromZodError } from 'zod-validation-error' ;
7+ import type { WithPolicyOptions } from '.' ;
78import { CrudFailureReason } from '../../constants' ;
89import {
910 ModelDataVisitor ,
@@ -23,7 +24,6 @@ import { formatObject, prismaClientValidationError } from '../utils';
2324import { Logger } from './logger' ;
2425import { PolicyUtil } from './policy-utils' ;
2526import { createDeferredPromise } from './promise' ;
26- import { WithPolicyOptions } from '.' ;
2727
2828// a record for post-write policy check
2929type PostWriteCheckRecord = {
@@ -58,6 +58,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
5858 this . logger = new Logger ( prisma ) ;
5959 this . utils = new PolicyUtil (
6060 this . prisma ,
61+ this . options ,
6162 this . modelMeta ,
6263 this . policy ,
6364 this . zodSchemas ,
@@ -77,20 +78,20 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
7778
7879 findUnique ( args : any ) {
7980 if ( ! args ) {
80- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
81+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
8182 }
8283 if ( ! args . where ) {
83- throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
84+ throw prismaClientValidationError ( this . prisma , this . options , 'where field is required in query argument' ) ;
8485 }
8586 return this . findWithFluentCallStubs ( args , 'findUnique' , false , ( ) => null ) ;
8687 }
8788
8889 findUniqueOrThrow ( args : any ) {
8990 if ( ! args ) {
90- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
91+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
9192 }
9293 if ( ! args . where ) {
93- throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
94+ throw prismaClientValidationError ( this . prisma , this . options , 'where field is required in query argument' ) ;
9495 }
9596 return this . findWithFluentCallStubs ( args , 'findUniqueOrThrow' , true , ( ) => {
9697 throw this . utils . notFound ( this . model ) ;
@@ -220,10 +221,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
220221
221222 async create ( args : any ) {
222223 if ( ! args ) {
223- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
224+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
224225 }
225226 if ( ! args . data ) {
226- throw prismaClientValidationError ( this . prisma , 'data field is required in query argument' ) ;
227+ throw prismaClientValidationError ( this . prisma , this . options , 'data field is required in query argument' ) ;
227228 }
228229
229230 this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -476,10 +477,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
476477
477478 async createMany ( args : { data : any ; skipDuplicates ?: boolean } ) {
478479 if ( ! args ) {
479- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
480+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
480481 }
481482 if ( ! args . data ) {
482- throw prismaClientValidationError ( this . prisma , 'data field is required in query argument' ) ;
483+ throw prismaClientValidationError ( this . prisma , this . options , 'data field is required in query argument' ) ;
483484 }
484485
485486 this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -596,13 +597,13 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
596597
597598 async update ( args : any ) {
598599 if ( ! args ) {
599- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
600+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
600601 }
601602 if ( ! args . where ) {
602- throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
603+ throw prismaClientValidationError ( this . prisma , this . options , 'where field is required in query argument' ) ;
603604 }
604605 if ( ! args . data ) {
605- throw prismaClientValidationError ( this . prisma , 'data field is required in query argument' ) ;
606+ throw prismaClientValidationError ( this . prisma , this . options , 'data field is required in query argument' ) ;
606607 }
607608
608609 args = this . utils . clone ( args ) ;
@@ -1071,10 +1072,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
10711072
10721073 async updateMany ( args : any ) {
10731074 if ( ! args ) {
1074- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1075+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
10751076 }
10761077 if ( ! args . data ) {
1077- throw prismaClientValidationError ( this . prisma , 'data field is required in query argument' ) ;
1078+ throw prismaClientValidationError ( this . prisma , this . options , 'data field is required in query argument' ) ;
10781079 }
10791080
10801081 this . utils . tryReject ( this . prisma , this . model , 'update' ) ;
@@ -1130,16 +1131,16 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11301131
11311132 async upsert ( args : any ) {
11321133 if ( ! args ) {
1133- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1134+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
11341135 }
11351136 if ( ! args . where ) {
1136- throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
1137+ throw prismaClientValidationError ( this . prisma , this . options , 'where field is required in query argument' ) ;
11371138 }
11381139 if ( ! args . create ) {
1139- throw prismaClientValidationError ( this . prisma , 'create field is required in query argument' ) ;
1140+ throw prismaClientValidationError ( this . prisma , this . options , 'create field is required in query argument' ) ;
11401141 }
11411142 if ( ! args . update ) {
1142- throw prismaClientValidationError ( this . prisma , 'update field is required in query argument' ) ;
1143+ throw prismaClientValidationError ( this . prisma , this . options , 'update field is required in query argument' ) ;
11431144 }
11441145
11451146 this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -1183,10 +1184,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11831184
11841185 async delete ( args : any ) {
11851186 if ( ! args ) {
1186- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1187+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
11871188 }
11881189 if ( ! args . where ) {
1189- throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
1190+ throw prismaClientValidationError ( this . prisma , this . options , 'where field is required in query argument' ) ;
11901191 }
11911192
11921193 this . utils . tryReject ( this . prisma , this . model , 'delete' ) ;
@@ -1239,7 +1240,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
12391240
12401241 async aggregate ( args : any ) {
12411242 if ( ! args ) {
1242- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1243+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
12431244 }
12441245
12451246 args = this . utils . clone ( args ) ;
@@ -1255,7 +1256,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
12551256
12561257 async groupBy ( args : any ) {
12571258 if ( ! args ) {
1258- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1259+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
12591260 }
12601261
12611262 args = this . utils . clone ( args ) ;
@@ -1299,7 +1300,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
12991300 args = { create : { } , update : { } , delete : { } } ;
13001301 } else {
13011302 if ( typeof args !== 'object' ) {
1302- throw prismaClientValidationError ( this . prisma , 'argument must be an object' ) ;
1303+ throw prismaClientValidationError ( this . prisma , this . options , 'argument must be an object' ) ;
13031304 }
13041305 if ( Object . keys ( args ) . length === 0 ) {
13051306 // include all
0 commit comments