@@ -12,8 +12,9 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
1212 const schema = indexCache ;
1313 const primaryKeys = schema ? Array . from ( schema . compoundKeys ) : [ ] ;
1414
15- for ( const addition of queryAdditions ) {
16- let validCombos = QUERY_ADDITION_RULES [ addition . additionFunction ] ;
15+ for ( let i = 0 ; i < queryAdditions . length ; i ++ ) {
16+ const addition = queryAdditions [ i ] ;
17+ const validCombos = QUERY_ADDITION_RULES [ addition . additionFunction ] ;
1718
1819 if ( ! validCombos ) {
1920 console . error ( `Unsupported query addition: ${ addition . additionFunction } ` ) ;
@@ -26,20 +27,19 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
2627 const isIndexed = schema ?. indexes . has ( addition . property ) || primaryKeys . includes ( addition . property ) ;
2728 if ( ! isIndexed ) {
2829 debugLog ( `Query requires cursor: ORDER_BY on non-indexed property ${ addition . property } ` ) ;
29- requiresCursor = true ; // Forces cursor usage
30+ requiresCursor = true ;
3031 }
3132 }
3233
33- // **If TAKE_LAST is used after ORDER_BY, allow it (when indexed)**
3434 if ( addition . additionFunction === QUERY_ADDITIONS . TAKE_LAST ) {
35- let prevAddition = queryAdditions [ queryAdditions . indexOf ( addition ) - 1 ] ;
35+ const prevAddition = queryAdditions [ i - 1 ] ;
3636 if ( ! prevAddition || ( prevAddition . additionFunction !== QUERY_ADDITIONS . ORDER_BY && prevAddition . additionFunction !== QUERY_ADDITIONS . ORDER_BY_DESCENDING ) ) {
3737 debugLog ( `TAKE_LAST requires ORDER_BY but was not found before it.` ) ;
38- requiresCursor = true ; // Force cursor if there's no ORDER_BY before it.
38+ requiresCursor = true ;
3939 }
4040 }
4141
42- // Check if the addition conflicts with previous additions
42+ // Check for conflicts with previously seen additions
4343 for ( const seen of seenAdditions ) {
4444 if ( ! validCombos . includes ( seen ) ) {
4545 requiresCursor = true ;
@@ -54,6 +54,7 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
5454}
5555
5656export function validateQueryCombinations ( nestedOrFilter ) {
57+
5758 debugLog ( "Validating Query Combinations" , { nestedOrFilter } ) ;
5859
5960 if ( ! nestedOrFilter || ! Array . isArray ( nestedOrFilter . orGroups ) ) {
0 commit comments