@@ -809,7 +809,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
809809 const unsafe = isUnsafeMutate ( model , args , this . modelMeta ) ;
810810
811811 // 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 ) ;
813813 if ( ( ! unsafe || context . field . isRelationOwner ) && reversedQuery [ context . field . backLink ] ) {
814814 // if mutation is safe, or current field owns the relation (so the other side has no fk),
815815 // 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
885885 if ( args . skipDuplicates ) {
886886 // get a reversed query to include fields inherited from upstream mutation,
887887 // 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 ) ;
889889 if ( await this . hasDuplicatedUniqueConstraint ( model , item , upstreamQuery , db ) ) {
890890 if ( this . shouldLogQuery ) {
891891 this . logger . info ( `[policy] \`createMany\` skipping duplicate ${ formatObject ( item ) } ` ) ;
@@ -910,7 +910,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
910910 if ( operation === 'disconnect' ) {
911911 // disconnect filter is not unique, need to build a reversed query to
912912 // 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 ) ;
914914 const found = await db [ model ] . findUnique ( {
915915 where : reversedQuery ,
916916 select : this . policyUtils . makeIdSelection ( model ) ,
@@ -936,7 +936,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
936936 const visitor = new NestedWriteVisitor ( this . modelMeta , {
937937 update : async ( model , args , context ) => {
938938 // build a unique query including upstream conditions
939- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
939+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
940940
941941 // handle not-found
942942 const existing = await this . policyUtils . checkExistence ( db , model , uniqueFilter , true ) ;
@@ -997,7 +997,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
997997 if ( preValueSelect ) {
998998 select = { ...select , ...preValueSelect } ;
999999 }
1000- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1000+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
10011001 const currentSetQuery = { select, where : reversedQuery } ;
10021002 this . policyUtils . injectAuthGuardAsWhere ( db , currentSetQuery , model , 'read' ) ;
10031003
@@ -1027,7 +1027,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
10271027 } else {
10281028 // we have to process `updateMany` separately because the guard may contain
10291029 // 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 ) ;
10311031 const updateWhere = this . policyUtils . and ( reversedQuery , updateGuard ) ;
10321032 if ( this . shouldLogQuery ) {
10331033 this . logger . info (
@@ -1066,7 +1066,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
10661066
10671067 upsert : async ( model , args , context ) => {
10681068 // build a unique query including upstream conditions
1069- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
1069+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
10701070
10711071 // branch based on if the update target exists
10721072 const existing = await this . policyUtils . checkExistence ( db , model , uniqueFilter ) ;
@@ -1090,7 +1090,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
10901090
10911091 // convert upsert to update
10921092 const convertedUpdate = {
1093- where : args . where ,
1093+ where : args . where ?? { } ,
10941094 data : this . validateUpdateInputSchema ( model , args . update ) ,
10951095 } ;
10961096 this . mergeToParent ( context . parent , 'update' , convertedUpdate ) ;
@@ -1143,7 +1143,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11431143
11441144 set : async ( model , args , context ) => {
11451145 // find the set of items to be replaced
1146- const reversedQuery = this . policyUtils . buildReversedQuery ( context ) ;
1146+ const reversedQuery = await this . policyUtils . buildReversedQuery ( db , context ) ;
11471147 const findCurrSetArgs = {
11481148 select : this . policyUtils . makeIdSelection ( model ) ,
11491149 where : reversedQuery ,
@@ -1162,7 +1162,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11621162
11631163 delete : async ( model , args , context ) => {
11641164 // build a unique query including upstream conditions
1165- const uniqueFilter = this . policyUtils . buildReversedQuery ( context ) ;
1165+ const uniqueFilter = await this . policyUtils . buildReversedQuery ( db , context ) ;
11661166
11671167 // handle not-found
11681168 await this . policyUtils . checkExistence ( db , model , uniqueFilter , true ) ;
@@ -1179,7 +1179,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
11791179 } else {
11801180 // we have to process `deleteMany` separately because the guard may contain
11811181 // 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 ) ;
11831183 const deleteWhere = this . policyUtils . and ( reversedQuery , guard ) ;
11841184 if ( this . shouldLogQuery ) {
11851185 this . logger . info ( `[policy] \`deleteMany\` ${ model } :\n${ formatObject ( { where : deleteWhere } ) } ` ) ;
@@ -1579,12 +1579,15 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
15791579 if ( this . shouldLogQuery ) {
15801580 this . logger . info (
15811581 `[policy] \`findMany\` ${ this . model } : ${ formatObject ( {
1582- where : args . where ,
1582+ where : args . where ?? { } ,
15831583 select : candidateSelect ,
15841584 } ) } `
15851585 ) ;
15861586 }
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+ } ) ;
15881591
15891592 // build a ID filter based on id values filtered by the additional checker
15901593 const { idFilter } = this . buildIdFilterWithEntityChecker ( candidates , entityChecker . func ) ;
0 commit comments