@@ -809,7 +809,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
809
809
const unsafe = isUnsafeMutate ( model , args , this . modelMeta ) ;
810
810
811
811
// handles the connection to upstream entity
812
- const reversedQuery = this . policyUtils . buildReversedQuery ( context , true , unsafe ) ;
812
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context , true , unsafe ) ;
813
813
if ( ( ! unsafe || context . field . isRelationOwner ) && reversedQuery [ context . field . backLink ] ) {
814
814
// if mutation is safe, or current field owns the relation (so the other side has no fk),
815
815
// and the reverse query contains the back link, then we can build a "connect" with it
@@ -885,7 +885,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
885
885
if ( args . skipDuplicates ) {
886
886
// get a reversed query to include fields inherited from upstream mutation,
887
887
// it'll be merged with the create payload for unique constraint checking
888
- const upstreamQuery = this . policyUtils . buildReversedQuery ( context ) ;
888
+ const upstreamQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
889
889
if ( await this . hasDuplicatedUniqueConstraint ( model , item , upstreamQuery , db ) ) {
890
890
if ( this . shouldLogQuery ) {
891
891
this . logger . info ( `[policy] \`createMany\` skipping duplicate ${ formatObject ( item ) } ` ) ;
@@ -910,7 +910,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
910
910
if ( operation === 'disconnect' ) {
911
911
// disconnect filter is not unique, need to build a reversed query to
912
912
// locate the entity and use its id fields as unique filter
913
- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
913
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
914
914
const found = await db [ model ] . findUnique ( {
915
915
where : reversedQuery ,
916
916
select : this . policyUtils . makeIdSelection ( model ) ,
@@ -936,7 +936,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
936
936
const visitor = new NestedWriteVisitor ( this . modelMeta , {
937
937
update : async ( model , args , context ) => {
938
938
// build a unique query including upstream conditions
939
- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
939
+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
940
940
941
941
// handle not-found
942
942
const existing = await this . policyUtils . checkExistence ( db , model , uniqueFilter , true ) ;
@@ -997,7 +997,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
997
997
if ( preValueSelect ) {
998
998
select = { ...select , ...preValueSelect } ;
999
999
}
1000
- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1000
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
1001
1001
const currentSetQuery = { select, where : reversedQuery } ;
1002
1002
this . policyUtils . injectAuthGuardAsWhere ( db , currentSetQuery , model , 'read' ) ;
1003
1003
@@ -1027,7 +1027,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1027
1027
} else {
1028
1028
// we have to process `updateMany` separately because the guard may contain
1029
1029
// filters using relation fields which are not allowed in nested `updateMany`
1030
- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1030
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
1031
1031
const updateWhere = this . policyUtils . and ( reversedQuery , updateGuard ) ;
1032
1032
if ( this . shouldLogQuery ) {
1033
1033
this . logger . info (
@@ -1066,7 +1066,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1066
1066
1067
1067
upsert : async ( model , args , context ) => {
1068
1068
// build a unique query including upstream conditions
1069
- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
1069
+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
1070
1070
1071
1071
// branch based on if the update target exists
1072
1072
const existing = await this . policyUtils . checkExistence ( db , model , uniqueFilter ) ;
@@ -1090,7 +1090,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1090
1090
1091
1091
// convert upsert to update
1092
1092
const convertedUpdate = {
1093
- where : args . where ,
1093
+ where : args . where ?? { } ,
1094
1094
data : this . validateUpdateInputSchema ( model , args . update ) ,
1095
1095
} ;
1096
1096
this . mergeToParent ( context . parent , 'update' , convertedUpdate ) ;
@@ -1143,7 +1143,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1143
1143
1144
1144
set : async ( model , args , context ) => {
1145
1145
// find the set of items to be replaced
1146
- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1146
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
1147
1147
const findCurrSetArgs = {
1148
1148
select : this . policyUtils . makeIdSelection ( model ) ,
1149
1149
where : reversedQuery ,
@@ -1162,7 +1162,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1162
1162
1163
1163
delete : async ( model , args , context ) => {
1164
1164
// build a unique query including upstream conditions
1165
- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
1165
+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
1166
1166
1167
1167
// handle not-found
1168
1168
await this . policyUtils . checkExistence ( db , model , uniqueFilter , true ) ;
@@ -1179,7 +1179,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1179
1179
} else {
1180
1180
// we have to process `deleteMany` separately because the guard may contain
1181
1181
// filters using relation fields which are not allowed in nested `deleteMany`
1182
- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1182
+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
1183
1183
const deleteWhere = this . policyUtils . and ( reversedQuery , guard ) ;
1184
1184
if ( this . shouldLogQuery ) {
1185
1185
this . logger . info ( `[policy] \`deleteMany\` ${ model } :\n${ formatObject ( { where : deleteWhere } ) } ` ) ;
@@ -1579,12 +1579,15 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
1579
1579
if ( this . shouldLogQuery ) {
1580
1580
this . logger . info (
1581
1581
`[policy] \`findMany\` ${ this . model } : ${ formatObject ( {
1582
- where : args . where ,
1582
+ where : args . where ?? { } ,
1583
1583
select : candidateSelect ,
1584
1584
} ) } `
1585
1585
) ;
1586
1586
}
1587
- const candidates = await tx [ this . model ] . findMany ( { where : args . where , select : candidateSelect } ) ;
1587
+ const candidates = await tx [ this . model ] . findMany ( {
1588
+ where : args . where ?? { } ,
1589
+ select : candidateSelect ,
1590
+ } ) ;
1588
1591
1589
1592
// build a ID filter based on id values filtered by the additional checker
1590
1593
const { idFilter } = this . buildIdFilterWithEntityChecker ( candidates , entityChecker . func ) ;
0 commit comments