@@ -25,7 +25,7 @@ import { createDeferredPromise, createFluentPromise } from '../promise';
2525import { PrismaProxyHandler } from '../proxy' ;
2626import { QueryUtils } from '../query-utils' ;
2727import type { EntityCheckerFunc , PermissionCheckerConstraint } from '../types' ;
28- import { clone , formatObject , isUnsafeMutate , prismaClientValidationError } from '../utils' ;
28+ import { formatObject , isUnsafeMutate , prismaClientValidationError } from '../utils' ;
2929import { ConstraintSolver } from './constraint-solver' ;
3030import { PolicyUtil } from './policy-utils' ;
3131
@@ -127,7 +127,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
127127
128128 // make a find query promise with fluent API call stubs installed
129129 private findWithFluent ( method : FindOperations , args : any , handleRejection : ( ) => any ) {
130- args = clone ( args ) ;
130+ args = this . policyUtils . safeClone ( args ) ;
131131 return createFluentPromise (
132132 ( ) => this . doFind ( args , method , handleRejection ) ,
133133 args ,
@@ -138,7 +138,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
138138
139139 private async doFind ( args : any , actionName : FindOperations , handleRejection : ( ) => any ) {
140140 const origArgs = args ;
141- const _args = clone ( args ) ;
141+ const _args = this . policyUtils . safeClone ( args ) ;
142142 if ( ! this . policyUtils . injectForRead ( this . prisma , this . model , _args ) ) {
143143 if ( this . shouldLogQuery ) {
144144 this . logger . info ( `[policy] \`${ actionName } \` ${ this . model } : unconditionally denied` ) ;
@@ -176,7 +176,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
176176 this . policyUtils . tryReject ( this . prisma , this . model , 'create' ) ;
177177
178178 const origArgs = args ;
179- args = clone ( args ) ;
179+ args = this . policyUtils . safeClone ( args ) ;
180180
181181 // static input policy check for top-level create data
182182 const inputCheck = this . policyUtils . checkInputGuard ( this . model , args . data , 'create' ) ;
@@ -443,7 +443,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
443443 return createDeferredPromise ( async ( ) => {
444444 this . policyUtils . tryReject ( this . prisma , this . model , 'create' ) ;
445445
446- args = clone ( args ) ;
446+ args = this . policyUtils . safeClone ( args ) ;
447447
448448 // go through create items, statically check input to determine if post-create
449449 // check is needed, and also validate zod schema
@@ -480,7 +480,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
480480 this . policyUtils . tryReject ( this . prisma , this . model , 'create' ) ;
481481
482482 const origArgs = args ;
483- args = clone ( args ) ;
483+ args = this . policyUtils . safeClone ( args ) ;
484484
485485 // go through create items, statically check input to determine if post-create
486486 // check is needed, and also validate zod schema
@@ -686,7 +686,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
686686 }
687687
688688 return createDeferredPromise ( async ( ) => {
689- args = clone ( args ) ;
689+ args = this . policyUtils . safeClone ( args ) ;
690690
691691 const { result, error } = await this . queryUtils . transaction ( this . prisma , async ( tx ) => {
692692 // proceed with nested writes and collect post-write checks
@@ -1149,7 +1149,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11491149
11501150 // calculate id fields used for post-update check given an update payload
11511151 private calculatePostUpdateIds ( _model : string , currentIds : any , updatePayload : any ) {
1152- const result = clone ( currentIds ) ;
1152+ const result = this . policyUtils . safeClone ( currentIds ) ;
11531153 for ( const key of Object . keys ( currentIds ) ) {
11541154 const updateValue = updatePayload [ key ] ;
11551155 if ( typeof updateValue === 'string' || typeof updateValue === 'number' || typeof updateValue === 'bigint' ) {
@@ -1239,7 +1239,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
12391239 return createDeferredPromise ( ( ) => {
12401240 this . policyUtils . tryReject ( this . prisma , this . model , 'update' ) ;
12411241
1242- args = clone ( args ) ;
1242+ args = this . policyUtils . safeClone ( args ) ;
12431243 this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'update' ) ;
12441244
12451245 args . data = this . validateUpdateInputSchema ( this . model , args . data ) ;
@@ -1349,7 +1349,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
13491349 this . policyUtils . tryReject ( this . prisma , this . model , 'create' ) ;
13501350 this . policyUtils . tryReject ( this . prisma , this . model , 'update' ) ;
13511351
1352- args = clone ( args ) ;
1352+ args = this . policyUtils . safeClone ( args ) ;
13531353
13541354 // We can call the native "upsert" because we can't tell if an entity was created or updated
13551355 // for doing post-write check accordingly. Instead, decompose it into create or update.
@@ -1442,7 +1442,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
14421442 this . policyUtils . tryReject ( this . prisma , this . model , 'delete' ) ;
14431443
14441444 // inject policy conditions
1445- args = clone ( args ) ;
1445+ args = this . policyUtils . safeClone ( args ) ;
14461446 this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'delete' ) ;
14471447
14481448 const entityChecker = this . policyUtils . getEntityChecker ( this . model , 'delete' ) ;
@@ -1498,7 +1498,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
14981498 }
14991499
15001500 return createDeferredPromise ( ( ) => {
1501- args = clone ( args ) ;
1501+ args = this . policyUtils . safeClone ( args ) ;
15021502
15031503 // inject policy conditions
15041504 this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'read' ) ;
@@ -1516,7 +1516,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
15161516 }
15171517
15181518 return createDeferredPromise ( ( ) => {
1519- args = clone ( args ) ;
1519+ args = this . policyUtils . safeClone ( args ) ;
15201520
15211521 // inject policy conditions
15221522 this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'read' ) ;
@@ -1531,7 +1531,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
15311531 count ( args : any ) {
15321532 return createDeferredPromise ( ( ) => {
15331533 // inject policy conditions
1534- args = args ? clone ( args ) : { } ;
1534+ args = args ? this . policyUtils . safeClone ( args ) : { } ;
15351535 this . policyUtils . injectAuthGuardAsWhere ( this . prisma , args , this . model , 'read' ) ;
15361536
15371537 if ( this . shouldLogQuery ) {
@@ -1567,7 +1567,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
15671567 // include all
15681568 args = { create : { } , update : { } , delete : { } } ;
15691569 } else {
1570- args = clone ( args ) ;
1570+ args = this . policyUtils . safeClone ( args ) ;
15711571 }
15721572 }
15731573
0 commit comments