@@ -23,6 +23,7 @@ import { formatObject, prismaClientValidationError } from '../utils';
23
23
import { Logger } from './logger' ;
24
24
import { PolicyUtil } from './policy-utils' ;
25
25
import { createDeferredPromise } from './promise' ;
26
+ import { WithPolicyOptions } from '.' ;
26
27
27
28
// a record for post-write policy check
28
29
type PostWriteCheckRecord = {
@@ -42,14 +43,17 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
42
43
private readonly utils : PolicyUtil ;
43
44
private readonly model : string ;
44
45
46
+ private readonly DEFAULT_TX_MAXWAIT = 100000 ;
47
+ private readonly DEFAULT_TX_TIMEOUT = 100000 ;
48
+
45
49
constructor (
46
50
private readonly prisma : DbClient ,
47
51
private readonly policy : PolicyDef ,
48
52
private readonly modelMeta : ModelMeta ,
49
53
private readonly zodSchemas : ZodSchemas | undefined ,
50
54
model : string ,
51
- private readonly user ? : AuthUser ,
52
- private readonly logPrismaQuery ?: boolean
55
+ private readonly user : AuthUser | undefined ,
56
+ private readonly options : WithPolicyOptions | undefined
53
57
) {
54
58
this . logger = new Logger ( prisma ) ;
55
59
this . utils = new PolicyUtil (
@@ -1276,12 +1280,22 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1276
1280
//#region Utils
1277
1281
1278
1282
private get shouldLogQuery ( ) {
1279
- return ! ! this . logPrismaQuery && this . logger . enabled ( 'info' ) ;
1283
+ return ! ! this . options ?. logPrismaQuery && this . logger . enabled ( 'info' ) ;
1280
1284
}
1281
1285
1282
1286
private transaction ( action : ( tx : Record < string , DbOperations > ) => Promise < any > ) {
1283
1287
if ( this . prisma [ '$transaction' ] ) {
1284
- return this . prisma . $transaction ( ( tx ) => action ( tx ) , { maxWait : 100000 , timeout : 100000 } ) ;
1288
+ const txOptions : any = { maxWait : this . DEFAULT_TX_MAXWAIT , timeout : this . DEFAULT_TX_TIMEOUT } ;
1289
+ if ( this . options ?. transactionMaxWait !== undefined ) {
1290
+ txOptions . maxWait = this . options . transactionMaxWait ;
1291
+ }
1292
+ if ( this . options ?. transactionTimeout !== undefined ) {
1293
+ txOptions . timeout = this . options . transactionTimeout ;
1294
+ }
1295
+ if ( this . options ?. transactionIsolationLevel !== undefined ) {
1296
+ txOptions . isolationLevel = this . options . transactionIsolationLevel ;
1297
+ }
1298
+ return this . prisma . $transaction ( ( tx ) => action ( tx ) , txOptions ) ;
1285
1299
} else {
1286
1300
// already in transaction, don't nest
1287
1301
return action ( this . prisma ) ;
@@ -1304,7 +1318,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1304
1318
this . zodSchemas ,
1305
1319
model ,
1306
1320
this . user ,
1307
- this . logPrismaQuery
1321
+ this . options
1308
1322
) ;
1309
1323
}
1310
1324
0 commit comments