@@ -44,11 +44,6 @@ export type AggregateWhereInput = {
4444 edge : WhereFilter ;
4545} & WhereFilter ;
4646
47- type AggregateWhereReturn = {
48- returnProjections : ( "*" | Cypher . ProjectionColumn ) [ ] ;
49- predicates : Cypher . Predicate [ ] ;
50- } ;
51-
5247export function aggregatePreComputedWhereFields ( {
5348 value,
5449 relationField,
@@ -77,20 +72,22 @@ export function aggregatePreComputedWhereFields({
7772 . to ( aggregationTarget ) ;
7873
7974 const matchQuery = new Cypher . Match ( matchPattern ) ;
80- const { returnProjections , predicates } = aggregateWhere (
75+ const innerPredicates = aggregateWhere (
8176 value as AggregateWhereInput ,
8277 refNode ,
8378 relationship ,
8479 aggregationTarget ,
8580 cypherRelation ,
8681 context
8782 ) ;
88- matchQuery . return ( ...returnProjections ) ;
83+
84+ const predicateVariable = new Cypher . Variable ( ) ;
85+ matchQuery . return ( [ Cypher . and ( ...innerPredicates ) , predicateVariable ] ) ;
8986
9087 const subquery = new Cypher . Call ( matchQuery ) . innerWith ( matchNode ) ;
9188
9289 return {
93- predicate : Cypher . and ( ... predicates ) ,
90+ predicate : Cypher . eq ( predicateVariable , new Cypher . Literal ( true ) ) ,
9491 // Cypher.concat is used because this is passed to createWherePredicate which expects a Cypher.CompositeClause
9592 preComputedSubqueries : Cypher . concat ( subquery ) ,
9693 } ;
@@ -103,63 +100,48 @@ function aggregateWhere(
103100 aggregationTarget : Cypher . Node ,
104101 cypherRelation : Cypher . Relationship ,
105102 context : Context
106- ) : AggregateWhereReturn {
107- const returnProjections : ( "*" | Cypher . ProjectionColumn ) [ ] = [ ] ;
108- const returnPredicates : Cypher . Predicate [ ] = [ ] ;
103+ ) : Cypher . Predicate [ ] {
104+ const innerPredicatesRes : Cypher . Predicate [ ] = [ ] ;
109105 Object . entries ( aggregateWhereInput ) . forEach ( ( [ key , value ] ) => {
110106 if ( AGGREGATION_AGGREGATE_COUNT_OPERATORS . includes ( key ) ) {
111- const { returnProjection, predicate } = createCountPredicateAndProjection ( aggregationTarget , key , value ) ;
112- returnProjections . push ( returnProjection ) ;
113- if ( predicate ) returnPredicates . push ( predicate ) ;
107+ const innerPredicates = createCountPredicateAndProjection ( aggregationTarget , key , value ) ;
108+ innerPredicatesRes . push ( ...innerPredicates ) ;
114109 } else if ( NODE_OR_EDGE_KEYS . includes ( key ) ) {
115110 const target = key === "edge" ? cypherRelation : aggregationTarget ;
116111 const refNodeOrRelation = key === "edge" ? relationship : refNode ;
117112 if ( ! refNodeOrRelation ) throw new Error ( `Edge filter ${ key } on undefined relationship` ) ;
118113
119- const { returnProjections : innerReturnProjections , predicates } = aggregateEntityWhere (
120- value ,
121- refNodeOrRelation ,
122- target ,
123- context
124- ) ;
125- returnProjections . push ( ...innerReturnProjections ) ;
126- returnPredicates . push ( ...predicates ) ;
114+ const innerPredicates = aggregateEntityWhere ( value , refNodeOrRelation , target , context ) ;
115+
116+ innerPredicatesRes . push ( ...innerPredicates ) ;
127117 } else if ( isLogicalOperator ( key ) ) {
128118 const logicalPredicates : Cypher . Predicate [ ] = [ ] ;
129119 asArray ( value ) . forEach ( ( whereInput ) => {
130- const { returnProjections : innerReturnProjections , predicates } = aggregateWhere (
120+ const innerPredicates = aggregateWhere (
131121 whereInput ,
132122 refNode ,
133123 relationship ,
134124 aggregationTarget ,
135125 cypherRelation ,
136126 context
137127 ) ;
138- returnProjections . push ( ...innerReturnProjections ) ;
139- logicalPredicates . push ( ...predicates ) ;
128+ logicalPredicates . push ( ...innerPredicates ) ;
140129 } ) ;
141-
142130 const logicalPredicate = getLogicalPredicate ( key , logicalPredicates ) ;
143-
144131 if ( logicalPredicate ) {
145- returnPredicates . push ( logicalPredicate ) ;
132+ innerPredicatesRes . push ( logicalPredicate ) ;
146133 }
147134 }
148135 } ) ;
149- return {
150- returnProjections,
151- predicates : returnPredicates ,
152- } ;
136+
137+ return innerPredicatesRes ;
153138}
154139
155140function createCountPredicateAndProjection (
156141 aggregationTarget : Cypher . Node ,
157142 filterKey : string ,
158143 filterValue : number
159- ) : {
160- returnProjection : "*" | Cypher . ProjectionColumn ;
161- predicate : Cypher . Predicate | undefined ;
162- } {
144+ ) : Cypher . Predicate [ ] {
163145 const paramName = new Cypher . Param ( filterValue ) ;
164146 const count = Cypher . count ( aggregationTarget ) ;
165147 const operator = whereRegEx . exec ( filterKey ) ?. groups ?. operator || "EQ" ;
@@ -168,52 +150,34 @@ function createCountPredicateAndProjection(
168150 target : count ,
169151 value : paramName ,
170152 } ) ;
171- const operationVar = new Cypher . Variable ( ) ;
172153
173- return {
174- returnProjection : [ operation , operationVar ] ,
175- predicate : Cypher . eq ( operationVar , new Cypher . Literal ( true ) ) ,
176- } ;
154+ return [ operation ] ;
177155}
178156
179157function aggregateEntityWhere (
180158 aggregateEntityWhereInput : WhereFilter ,
181159 refNodeOrRelation : Node | Relationship ,
182160 target : Cypher . Node | Cypher . Relationship ,
183161 context : Context
184- ) : AggregateWhereReturn {
185- const returnProjections : ( "*" | Cypher . ProjectionColumn ) [ ] = [ ] ;
186- const predicates : Cypher . Predicate [ ] = [ ] ;
162+ ) : Cypher . Predicate [ ] {
163+ const innerPredicatesRes : Cypher . Predicate [ ] = [ ] ;
187164 Object . entries ( aggregateEntityWhereInput ) . forEach ( ( [ key , value ] ) => {
188165 if ( isLogicalOperator ( key ) ) {
189166 const logicalPredicates : Cypher . Predicate [ ] = [ ] ;
190167 asArray ( value ) . forEach ( ( whereInput ) => {
191- const { returnProjections : innerReturnProjections , predicates : innerPredicates } = aggregateEntityWhere (
192- whereInput ,
193- refNodeOrRelation ,
194- target ,
195- context
196- ) ;
197- returnProjections . push ( ...innerReturnProjections ) ;
168+ const innerPredicates = aggregateEntityWhere ( whereInput , refNodeOrRelation , target , context ) ;
198169 logicalPredicates . push ( ...innerPredicates ) ;
199170 } ) ;
200-
201171 const logicalPredicate = getLogicalPredicate ( key , logicalPredicates ) ;
202-
203172 if ( logicalPredicate ) {
204- predicates . push ( logicalPredicate ) ;
173+ innerPredicatesRes . push ( logicalPredicate ) ;
205174 }
206175 } else {
207176 const operation = createEntityOperation ( refNodeOrRelation , target , key , value ) ;
208- const operationVar = new Cypher . Variable ( ) ;
209- returnProjections . push ( [ operation , operationVar ] ) ;
210- predicates . push ( Cypher . eq ( operationVar , new Cypher . Literal ( true ) ) ) ;
177+ innerPredicatesRes . push ( operation ) ;
211178 }
212179 } ) ;
213- return {
214- returnProjections,
215- predicates,
216- } ;
180+ return innerPredicatesRes ;
217181}
218182
219183function createEntityOperation (
0 commit comments