@@ -64,16 +64,19 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
64
64
throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
65
65
}
66
66
67
+ const origArgs = args ;
67
68
args = this . utils . clone ( args ) ;
68
69
if ( ! ( await this . utils . injectForRead ( this . prisma , this . model , args ) ) ) {
69
70
return null ;
70
71
}
71
72
73
+ this . utils . injectReadCheckSelect ( this . model , args ) ;
74
+
72
75
if ( this . shouldLogQuery ) {
73
76
this . logger . info ( `[policy] \`findUnique\` ${ this . model } :\n${ formatObject ( args ) } ` ) ;
74
77
}
75
78
const result = await this . modelClient . findUnique ( args ) ;
76
- this . utils . postProcessForRead ( result ) ;
79
+ this . utils . postProcessForRead ( result , this . model , origArgs ) ;
77
80
return result ;
78
81
}
79
82
@@ -85,58 +88,70 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
85
88
throw prismaClientValidationError ( this . prisma , 'where field is required in query argument' ) ;
86
89
}
87
90
91
+ const origArgs = args ;
88
92
args = this . utils . clone ( args ) ;
89
93
if ( ! ( await this . utils . injectForRead ( this . prisma , this . model , args ) ) ) {
90
94
throw this . utils . notFound ( this . model ) ;
91
95
}
92
96
97
+ this . utils . injectReadCheckSelect ( this . model , args ) ;
98
+
93
99
if ( this . shouldLogQuery ) {
94
100
this . logger . info ( `[policy] \`findUniqueOrThrow\` ${ this . model } :\n${ formatObject ( args ) } ` ) ;
95
101
}
96
102
const result = await this . modelClient . findUniqueOrThrow ( args ) ;
97
- this . utils . postProcessForRead ( result ) ;
103
+ this . utils . postProcessForRead ( result , this . model , origArgs ) ;
98
104
return result ;
99
105
}
100
106
101
107
async findFirst ( args : any ) {
108
+ const origArgs = args ;
102
109
args = args ? this . utils . clone ( args ) : { } ;
103
110
if ( ! ( await this . utils . injectForRead ( this . prisma , this . model , args ) ) ) {
104
111
return null ;
105
112
}
106
113
114
+ this . utils . injectReadCheckSelect ( this . model , args ) ;
115
+
107
116
if ( this . shouldLogQuery ) {
108
117
this . logger . info ( `[policy] \`findFirst\` ${ this . model } :\n${ formatObject ( args ) } ` ) ;
109
118
}
110
119
const result = await this . modelClient . findFirst ( args ) ;
111
- this . utils . postProcessForRead ( result ) ;
120
+ this . utils . postProcessForRead ( result , this . model , origArgs ) ;
112
121
return result ;
113
122
}
114
123
115
124
async findFirstOrThrow ( args : any ) {
125
+ const origArgs = args ;
116
126
args = args ? this . utils . clone ( args ) : { } ;
117
127
if ( ! ( await this . utils . injectForRead ( this . prisma , this . model , args ) ) ) {
118
128
throw this . utils . notFound ( this . model ) ;
119
129
}
120
130
131
+ this . utils . injectReadCheckSelect ( this . model , args ) ;
132
+
121
133
if ( this . shouldLogQuery ) {
122
134
this . logger . info ( `[policy] \`findFirstOrThrow\` ${ this . model } :\n${ formatObject ( args ) } ` ) ;
123
135
}
124
136
const result = await this . modelClient . findFirstOrThrow ( args ) ;
125
- this . utils . postProcessForRead ( result ) ;
137
+ this . utils . postProcessForRead ( result , this . model , origArgs ) ;
126
138
return result ;
127
139
}
128
140
129
141
async findMany ( args : any ) {
142
+ const origArgs = args ;
130
143
args = args ? this . utils . clone ( args ) : { } ;
131
144
if ( ! ( await this . utils . injectForRead ( this . prisma , this . model , args ) ) ) {
132
145
return [ ] ;
133
146
}
134
147
148
+ this . utils . injectReadCheckSelect ( this . model , args ) ;
149
+
135
150
if ( this . shouldLogQuery ) {
136
151
this . logger . info ( `[policy] \`findMany\` ${ this . model } :\n${ formatObject ( args ) } ` ) ;
137
152
}
138
153
const result = await this . modelClient . findMany ( args ) ;
139
- this . utils . postProcessForRead ( result ) ;
154
+ this . utils . postProcessForRead ( result , this . model , origArgs ) ;
140
155
return result ;
141
156
}
142
157
@@ -255,7 +270,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
255
270
if ( backLinkField ?. isRelationOwner ) {
256
271
// the target side of relation owns the relation,
257
272
// check if it's updatable
258
- await this . utils . checkPolicyForUnique ( model , args . where , 'update' , db ) ;
273
+ await this . utils . checkPolicyForUnique ( model , args . where , 'update' , db , args ) ;
259
274
}
260
275
}
261
276
@@ -300,7 +315,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
300
315
301
316
// the target side of relation owns the relation,
302
317
// check if it's updatable
303
- await this . utils . checkPolicyForUnique ( model , args , 'update' , db ) ;
318
+ await this . utils . checkPolicyForUnique ( model , args , 'update' , db , args ) ;
304
319
}
305
320
}
306
321
} ,
@@ -597,7 +612,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
597
612
const backLinkField = this . utils . getModelField ( model , context . field . backLink ) ;
598
613
if ( backLinkField . isRelationOwner ) {
599
614
// update happens on the related model, require updatable
600
- await this . utils . checkPolicyForUnique ( model , args , 'update' , db ) ;
615
+ await this . utils . checkPolicyForUnique ( model , args , 'update' , db , args ) ;
601
616
602
617
// register post-update check
603
618
await _registerPostUpdateCheck ( model , args ) ;
@@ -638,7 +653,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
638
653
this . utils . tryReject ( db , this . model , 'update' ) ;
639
654
640
655
// check pre-update guard
641
- await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'update' , db ) ;
656
+ await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'update' , db , args ) ;
642
657
643
658
// handles the case where id fields are updated
644
659
const ids = this . utils . clone ( existing ) ;
@@ -721,7 +736,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
721
736
// update case
722
737
723
738
// check pre-update guard
724
- await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'update' , db ) ;
739
+ await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'update' , db , args ) ;
725
740
726
741
// register post-update check
727
742
await _registerPostUpdateCheck ( model , uniqueFilter ) ;
@@ -789,7 +804,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
789
804
await this . utils . checkExistence ( db , model , uniqueFilter , true ) ;
790
805
791
806
// check delete guard
792
- await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'delete' , db ) ;
807
+ await this . utils . checkPolicyForUnique ( model , uniqueFilter , 'delete' , db , args ) ;
793
808
} ,
794
809
795
810
deleteMany : async ( model , args , context ) => {
@@ -942,7 +957,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
942
957
await this . utils . checkExistence ( tx , this . model , args . where , true ) ;
943
958
944
959
// inject delete guard
945
- await this . utils . checkPolicyForUnique ( this . model , args . where , 'delete' , tx ) ;
960
+ await this . utils . checkPolicyForUnique ( this . model , args . where , 'delete' , tx , args ) ;
946
961
947
962
// proceed with the deletion
948
963
if ( this . shouldLogQuery ) {
@@ -1037,7 +1052,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1037
1052
private async runPostWriteChecks ( postWriteChecks : PostWriteCheckRecord [ ] , db : Record < string , DbOperations > ) {
1038
1053
await Promise . all (
1039
1054
postWriteChecks . map ( async ( { model, operation, uniqueFilter, preValue } ) =>
1040
- this . utils . checkPolicyForUnique ( model , uniqueFilter , operation , db , preValue )
1055
+ this . utils . checkPolicyForUnique ( model , uniqueFilter , operation , db , undefined , preValue )
1041
1056
)
1042
1057
) ;
1043
1058
}
0 commit comments