Skip to content

Commit 8e353c6

Browse files
committed
More fix and more test
1 parent e8c8985 commit 8e353c6

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

packages/firestore/src/core/target.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import {
3131
isReferenceValue,
3232
MAX_VALUE,
3333
MIN_VALUE,
34-
singleValueBoundCompare,
34+
lowerBoundCompare,
3535
typeOrder,
36+
upperBoundCompare,
3637
valueCompare,
3738
valueEquals,
3839
valuesGetLowerBound,
@@ -384,7 +385,7 @@ function targetGetAscendingBound(
384385
}
385386

386387
if (
387-
singleValueBoundCompare(
388+
lowerBoundCompare(
388389
{ value, inclusive },
389390
{ value: filterValue, inclusive: filterInclusive }
390391
) < 0
@@ -402,7 +403,7 @@ function targetGetAscendingBound(
402403
if (orderBy.field.isEqual(fieldPath)) {
403404
const cursorValue = bound.position[i];
404405
if (
405-
singleValueBoundCompare(
406+
lowerBoundCompare(
406407
{ value, inclusive },
407408
{ value: cursorValue, inclusive: bound.inclusive }
408409
) < 0
@@ -459,7 +460,7 @@ function targetGetDescendingBound(
459460
}
460461

461462
if (
462-
singleValueBoundCompare(
463+
upperBoundCompare(
463464
{ value, inclusive },
464465
{ value: filterValue, inclusive: filterInclusive }
465466
) > 0
@@ -477,7 +478,7 @@ function targetGetDescendingBound(
477478
if (orderBy.field.isEqual(fieldPath)) {
478479
const cursorValue = bound.position[i];
479480
if (
480-
singleValueBoundCompare(
481+
upperBoundCompare(
481482
{ value, inclusive },
482483
{ value: cursorValue, inclusive: bound.inclusive }
483484
) > 0

packages/firestore/src/model/values.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function typeOrder(value: Value): TypeOrder {
7878
if (isServerTimestamp(value)) {
7979
return TypeOrder.ServerTimestampValue;
8080
} else if (isMaxValue(value)) {
81-
return TypeOrder.ObjectValue;
81+
return TypeOrder.MaxValue;
8282
}
8383
return TypeOrder.ObjectValue;
8484
} else {
@@ -678,7 +678,7 @@ export function valuesGetUpperBound(value: Value): Value {
678678
}
679679
}
680680

681-
export function singleValueBoundCompare(
681+
export function lowerBoundCompare(
682682
left: { value: Value; inclusive: boolean },
683683
right: { value: Value; inclusive: boolean }
684684
): number {
@@ -695,3 +695,21 @@ export function singleValueBoundCompare(
695695

696696
return 0;
697697
}
698+
699+
export function upperBoundCompare(
700+
left: { value: Value; inclusive: boolean },
701+
right: { value: Value; inclusive: boolean }
702+
): number {
703+
const cmp = valueCompare(left.value, right.value);
704+
if (cmp !== 0) {
705+
return cmp;
706+
}
707+
708+
if (left.inclusive && !right.inclusive) {
709+
return 1;
710+
} else if (!left.inclusive && right.inclusive) {
711+
return -1;
712+
}
713+
714+
return 0;
715+
}

packages/firestore/test/unit/local/index_manager.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,17 +890,29 @@ describe('IndexedDbIndexManager', async () => {
890890
await indexManager.addFieldIndex(
891891
fieldIndex('coll', { fields: [['c', IndexKind.ASCENDING]] })
892892
);
893+
await indexManager.addFieldIndex(
894+
fieldIndex('coll', { fields: [['c', IndexKind.DESCENDING]] })
895+
);
893896
await addDoc('coll/val1', { 'a': 1, 'b': 1, 'c': 3 });
894897
await addDoc('coll/val2', { 'a': 2, 'b': 2, 'c': 2 });
895898

896-
const testingQuery = queryWithStartAt(
899+
let testingQuery = queryWithStartAt(
897900
queryWithAddedOrderBy(
898901
queryWithAddedFilter(query('coll'), filter('c', '>', 2)),
899902
orderBy('c', 'asc')
900903
),
901904
bound([2], /* inclusive= */ true)
902905
);
903906
await verifyResults(testingQuery, 'coll/val1');
907+
908+
testingQuery = queryWithStartAt(
909+
queryWithAddedOrderBy(
910+
queryWithAddedFilter(query('coll'), filter('c', '<', 3)),
911+
orderBy('c', 'desc')
912+
),
913+
bound([3], /* inclusive= */ true)
914+
);
915+
await verifyResults(testingQuery, 'coll/val2');
904916
});
905917

906918
it('support advances queries', async () => {

0 commit comments

Comments
 (0)