@@ -21,8 +21,7 @@ import {
21
21
FieldIndex ,
22
22
fieldIndexGetArraySegment ,
23
23
fieldIndexGetDirectionalSegments ,
24
- IndexKind ,
25
- IndexSegment
24
+ IndexKind
26
25
} from '../model/field_index' ;
27
26
import { FieldPath , ResourcePath } from '../model/path' ;
28
27
import {
@@ -308,8 +307,12 @@ export function targetGetLowerBound(
308
307
for ( const segment of fieldIndexGetDirectionalSegments ( fieldIndex ) ) {
309
308
const segmentBound =
310
309
segment . kind === IndexKind . ASCENDING
311
- ? targetGetAscendingBound ( target , segment , target . startAt )
312
- : targetGetDescendingBound ( target , segment , target . startAt ) ;
310
+ ? targetGetLowerBoundForField ( target , segment . fieldPath , target . startAt )
311
+ : targetGetUpperBoundForField (
312
+ target ,
313
+ segment . fieldPath ,
314
+ target . startAt
315
+ ) ;
313
316
314
317
if ( ! segmentBound . value ) {
315
318
// No lower bound exists
@@ -338,8 +341,8 @@ export function targetGetUpperBound(
338
341
for ( const segment of fieldIndexGetDirectionalSegments ( fieldIndex ) ) {
339
342
const segmentBound =
340
343
segment . kind === IndexKind . ASCENDING
341
- ? targetGetDescendingBound ( target , segment , target . endAt )
342
- : targetGetAscendingBound ( target , segment , target . endAt ) ;
344
+ ? targetGetUpperBoundForField ( target , segment . fieldPath , target . endAt )
345
+ : targetGetLowerBoundForField ( target , segment . fieldPath , target . endAt ) ;
343
346
344
347
if ( ! segmentBound . value ) {
345
348
// No upper bound exists
@@ -352,19 +355,20 @@ export function targetGetUpperBound(
352
355
return new Bound ( values , inclusive ) ;
353
356
}
354
357
355
- function targetGetAscendingBound (
358
+ /**
359
+ * Returns the value to use as the lower bound for ascending index segment at
360
+ * the provided `fieldPath` (or the upper bound for an descending segment).
361
+ */
362
+ function targetGetLowerBoundForField (
356
363
target : Target ,
357
- segment : IndexSegment ,
364
+ fieldPath : FieldPath ,
358
365
bound : Bound | null
359
366
) : { value : ProtoValue | undefined ; inclusive : boolean } {
360
367
let value : ProtoValue | undefined = undefined ;
361
368
let inclusive = true ;
362
369
363
370
// Process all filters to find a value for the current field segment
364
- for ( const fieldFilter of targetGetFieldFiltersForPath (
365
- target ,
366
- segment . fieldPath
367
- ) ) {
371
+ for ( const fieldFilter of targetGetFieldFiltersForPath ( target , fieldPath ) ) {
368
372
let filterValue : ProtoValue | undefined = undefined ;
369
373
let filterInclusive = true ;
370
374
@@ -401,7 +405,7 @@ function targetGetAscendingBound(
401
405
if ( bound !== null ) {
402
406
for ( let i = 0 ; i < target . orderBy . length ; ++ i ) {
403
407
const orderBy = target . orderBy [ i ] ;
404
- if ( orderBy . field . isEqual ( segment . fieldPath ) ) {
408
+ if ( orderBy . field . isEqual ( fieldPath ) ) {
405
409
const cursorValue = bound . position [ i ] ;
406
410
if ( valuesMax ( value , cursorValue ) === cursorValue ) {
407
411
value = cursorValue ;
@@ -415,19 +419,20 @@ function targetGetAscendingBound(
415
419
return { value, inclusive } ;
416
420
}
417
421
418
- function targetGetDescendingBound (
422
+ /**
423
+ * Returns the value to use as the upper bound for ascending index segment at
424
+ * the provided `fieldPath` (or the lower bound for an descending segment).
425
+ */
426
+ function targetGetUpperBoundForField (
419
427
target : Target ,
420
- segment : IndexSegment ,
428
+ fieldPath : FieldPath ,
421
429
bound : Bound | null
422
430
) : { value : ProtoValue | undefined ; inclusive : boolean } {
423
431
let value : ProtoValue | undefined = undefined ;
424
432
let inclusive = true ;
425
433
426
434
// Process all filters to find a value for the current field segment
427
- for ( const fieldFilter of targetGetFieldFiltersForPath (
428
- target ,
429
- segment . fieldPath
430
- ) ) {
435
+ for ( const fieldFilter of targetGetFieldFiltersForPath ( target , fieldPath ) ) {
431
436
let filterValue : ProtoValue | undefined = undefined ;
432
437
let filterInclusive = true ;
433
438
@@ -465,7 +470,7 @@ function targetGetDescendingBound(
465
470
if ( bound !== null ) {
466
471
for ( let i = 0 ; i < target . orderBy . length ; ++ i ) {
467
472
const orderBy = target . orderBy [ i ] ;
468
- if ( orderBy . field . isEqual ( segment . fieldPath ) ) {
473
+ if ( orderBy . field . isEqual ( fieldPath ) ) {
469
474
const cursorValue = bound . position [ i ] ;
470
475
if ( valuesMin ( value , cursorValue ) === cursorValue ) {
471
476
value = cursorValue ;
0 commit comments