@@ -4,6 +4,7 @@ import { lowerCaseFirst } from 'lower-case-first';
4
4
import invariant from 'tiny-invariant' ;
5
5
import { upperCaseFirst } from 'upper-case-first' ;
6
6
import { fromZodError } from 'zod-validation-error' ;
7
+ import type { WithPolicyOptions } from '.' ;
7
8
import { CrudFailureReason } from '../../constants' ;
8
9
import {
9
10
ModelDataVisitor ,
@@ -23,7 +24,6 @@ import { formatObject, prismaClientValidationError } from '../utils';
23
24
import { Logger } from './logger' ;
24
25
import { PolicyUtil } from './policy-utils' ;
25
26
import { createDeferredPromise } from './promise' ;
26
- import { WithPolicyOptions } from '.' ;
27
27
28
28
// a record for post-write policy check
29
29
type PostWriteCheckRecord = {
@@ -58,6 +58,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
58
58
this . logger = new Logger ( prisma ) ;
59
59
this . utils = new PolicyUtil (
60
60
this . prisma ,
61
+ this . options ,
61
62
this . modelMeta ,
62
63
this . policy ,
63
64
this . zodSchemas ,
@@ -77,20 +78,20 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
77
78
78
79
findUnique ( args : any ) {
79
80
if ( ! args ) {
80
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
81
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
81
82
}
82
83
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' ) ;
84
85
}
85
86
return this . findWithFluentCallStubs ( args , 'findUnique' , false , ( ) => null ) ;
86
87
}
87
88
88
89
findUniqueOrThrow ( args : any ) {
89
90
if ( ! args ) {
90
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
91
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
91
92
}
92
93
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' ) ;
94
95
}
95
96
return this . findWithFluentCallStubs ( args , 'findUniqueOrThrow' , true , ( ) => {
96
97
throw this . utils . notFound ( this . model ) ;
@@ -220,10 +221,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
220
221
221
222
async create ( args : any ) {
222
223
if ( ! args ) {
223
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
224
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
224
225
}
225
226
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' ) ;
227
228
}
228
229
229
230
this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -476,10 +477,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
476
477
477
478
async createMany ( args : { data : any ; skipDuplicates ?: boolean } ) {
478
479
if ( ! args ) {
479
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
480
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
480
481
}
481
482
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' ) ;
483
484
}
484
485
485
486
this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -596,13 +597,13 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
596
597
597
598
async update ( args : any ) {
598
599
if ( ! args ) {
599
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
600
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
600
601
}
601
602
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' ) ;
603
604
}
604
605
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' ) ;
606
607
}
607
608
608
609
args = this . utils . clone ( args ) ;
@@ -1071,10 +1072,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1071
1072
1072
1073
async updateMany ( args : any ) {
1073
1074
if ( ! args ) {
1074
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1075
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
1075
1076
}
1076
1077
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' ) ;
1078
1079
}
1079
1080
1080
1081
this . utils . tryReject ( this . prisma , this . model , 'update' ) ;
@@ -1130,16 +1131,16 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1130
1131
1131
1132
async upsert ( args : any ) {
1132
1133
if ( ! args ) {
1133
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1134
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
1134
1135
}
1135
1136
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' ) ;
1137
1138
}
1138
1139
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' ) ;
1140
1141
}
1141
1142
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' ) ;
1143
1144
}
1144
1145
1145
1146
this . utils . tryReject ( this . prisma , this . model , 'create' ) ;
@@ -1183,10 +1184,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1183
1184
1184
1185
async delete ( args : any ) {
1185
1186
if ( ! args ) {
1186
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1187
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
1187
1188
}
1188
1189
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' ) ;
1190
1191
}
1191
1192
1192
1193
this . utils . tryReject ( this . prisma , this . model , 'delete' ) ;
@@ -1239,7 +1240,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1239
1240
1240
1241
async aggregate ( args : any ) {
1241
1242
if ( ! args ) {
1242
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1243
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
1243
1244
}
1244
1245
1245
1246
args = this . utils . clone ( args ) ;
@@ -1255,7 +1256,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1255
1256
1256
1257
async groupBy ( args : any ) {
1257
1258
if ( ! args ) {
1258
- throw prismaClientValidationError ( this . prisma , 'query argument is required' ) ;
1259
+ throw prismaClientValidationError ( this . prisma , this . options , 'query argument is required' ) ;
1259
1260
}
1260
1261
1261
1262
args = this . utils . clone ( args ) ;
@@ -1299,7 +1300,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1299
1300
args = { create : { } , update : { } , delete : { } } ;
1300
1301
} else {
1301
1302
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' ) ;
1303
1304
}
1304
1305
if ( Object . keys ( args ) . length === 0 ) {
1305
1306
// include all
0 commit comments