@zum/firebase-pagination
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -6,5 +6,6 @@ import { Key } from "../../types/key"; | ||
values: any[]; | ||
orderBy: string; | ||
private readonly size; | ||
private index; | ||
constructor(keys: Key[], values: any[]); | ||
constructor(keys: Key[], values: any[], orderBy: string); | ||
isEmpty(): boolean; | ||
@@ -11,0 +12,0 @@ getSize(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var item_1 = require("../../types/item"); | ||
var get_1 = require("../../utils/get"); | ||
var common_1 = require("../../utils/common"); | ||
var Buffer = /** @class */ (function () { | ||
function Buffer(keys, values) { | ||
function Buffer(keys, values, orderBy) { | ||
this.keys = keys; | ||
this.values = values; | ||
this.orderBy = orderBy; | ||
this.index = 0; | ||
common_1.checkNotNull(orderBy); | ||
if (keys.length !== values.length) { | ||
@@ -33,3 +37,4 @@ throw new Error('Keys and values should be equal lengths'); | ||
// TODO: cache the value to avoid too many "new"-s | ||
return new item_1.Item(this.keys[this.index], this.values[this.index]); | ||
var value = this.values[this.index]; | ||
return new item_1.Item(this.keys[this.index], value, get_1.get(value, this.orderBy)); | ||
}; | ||
@@ -36,0 +41,0 @@ return Buffer; |
@@ -12,3 +12,2 @@ import { Item } from "../../types/item"; | ||
private isAscending; | ||
static readonly ORDER_BY_KEY = "$ORDER_BY_KEY"; | ||
private hasNextValue; | ||
@@ -15,0 +14,0 @@ private hasNextPage; |
@@ -41,2 +41,4 @@ "use strict"; | ||
var buffer_1 = require("./buffer"); | ||
var get_1 = require("../../utils/get"); | ||
var orderByKey_1 = require("../../types/orderByKey"); | ||
var Cursor = /** @class */ (function () { | ||
@@ -55,3 +57,3 @@ function Cursor(database, path, orderBy, startAt, endAt, maxBatchSize, isAscending) { | ||
this.hasNextPage = true; | ||
this.buffer = new buffer_1.Buffer([], []); | ||
this.buffer = new buffer_1.Buffer([], [], this.orderBy); | ||
this.batchNumber = 0; | ||
@@ -99,3 +101,3 @@ common_1.checkNotNull(database); | ||
Cursor.prototype.isOrderByKey = function () { | ||
return this.orderBy === Cursor.ORDER_BY_KEY; | ||
return this.orderBy === orderByKey_1.ORDER_BY_KEY; | ||
}; | ||
@@ -119,3 +121,3 @@ Cursor.prototype.nextBatch = function () { | ||
if (keys.length === 0) { | ||
return [2 /*return*/, new buffer_1.Buffer([], [])]; | ||
return [2 /*return*/, new buffer_1.Buffer([], [], this.orderBy)]; | ||
} | ||
@@ -152,7 +154,7 @@ this.hasNextPage = keys.length === this.maxBatchSize; | ||
else { | ||
this.startAt = new pointer_1.Pointer(values[values.length - 1][this.orderBy], keys[keys.length - 1]); | ||
this.startAt = new pointer_1.Pointer(get_1.get(values[values.length - 1], this.orderBy), keys[keys.length - 1]); | ||
} | ||
} | ||
this.batchNumber++; | ||
return [2 /*return*/, new buffer_1.Buffer(keys, values)]; | ||
return [2 /*return*/, new buffer_1.Buffer(keys, values, this.orderBy)]; | ||
} | ||
@@ -209,3 +211,2 @@ }); | ||
}; | ||
Cursor.ORDER_BY_KEY = '$ORDER_BY_KEY'; | ||
return Cursor; | ||
@@ -212,0 +213,0 @@ }()); |
@@ -5,3 +5,2 @@ import { Pointer } from "../../types/pointer"; | ||
private maxBatchSize; | ||
static readonly ORDER_BY_KEY = "$ORDER_BY_KEY"; | ||
private readonly cursors; | ||
@@ -8,0 +7,0 @@ private readonly cursorComparator; |
@@ -44,5 +44,6 @@ "use strict"; | ||
var cursor_1 = require("./cursor"); | ||
var orderByKey_1 = require("../../types/orderByKey"); | ||
var MultiCursor = /** @class */ (function () { | ||
function MultiCursor(database, paths, orderBy, startAt, endAt, maxBatchSize, isAscending) { | ||
if (orderBy === void 0) { orderBy = MultiCursor.ORDER_BY_KEY; } | ||
if (orderBy === void 0) { orderBy = orderByKey_1.ORDER_BY_KEY; } | ||
if (startAt === void 0) { startAt = null; } | ||
@@ -69,6 +70,6 @@ if (endAt === void 0) { endAt = null; } | ||
var rightItem = right.peek(); | ||
if (leftItem.value[orderBy] < rightItem.value[orderBy]) { | ||
if (leftItem.orderByValue < rightItem.orderByValue) { | ||
return isAscending; | ||
} | ||
if (leftItem.value[orderBy] > rightItem.value[orderBy]) { | ||
if (leftItem.orderByValue > rightItem.orderByValue) { | ||
return !isAscending; | ||
@@ -163,3 +164,2 @@ } | ||
}; | ||
MultiCursor.ORDER_BY_KEY = cursor_1.Cursor.ORDER_BY_KEY; | ||
return MultiCursor; | ||
@@ -166,0 +166,0 @@ }()); |
@@ -9,2 +9,3 @@ import { Item } from "../../types/item"; | ||
private isOverlapping; | ||
private orderBy; | ||
index: number; | ||
@@ -15,3 +16,3 @@ keyMap: { | ||
private readonly overlappingKey; | ||
constructor(items: Item[], comparator: Comparator<Item>, isOverlapping: boolean); | ||
constructor(items: Item[], comparator: Comparator<Item>, isOverlapping: boolean, orderBy: string); | ||
private indexOfKey; | ||
@@ -38,4 +39,5 @@ move(key: Key, newValue: any): MulticursorCollectionChange; | ||
hasNext(): boolean; | ||
isOverlappingItem(index: number, key: Key): boolean; | ||
next(): Item; | ||
peek(): Item; | ||
} |
@@ -6,7 +6,9 @@ "use strict"; | ||
var multicursor_collection_change_1 = require("../../types/multicursor-collection-change"); | ||
var get_1 = require("../../utils/get"); | ||
var Buffer = /** @class */ (function () { | ||
function Buffer(items, comparator, isOverlapping) { | ||
function Buffer(items, comparator, isOverlapping, orderBy) { | ||
this.items = items; | ||
this.comparator = comparator; | ||
this.isOverlapping = isOverlapping; | ||
this.orderBy = orderBy; | ||
this.index = 0; | ||
@@ -45,3 +47,3 @@ // Keys are unique within a single cursor and, therefore, are unique within a single buffer | ||
var isDeletedFromAbove = this.deleteAtIndex(currentIndex); | ||
var newIndex = bsearch_1.binarySearch(this.items, { key: key, value: newValue }, this.comparator); | ||
var newIndex = bsearch_1.binarySearch(this.items, new item_1.Item(key, newValue, get_1.get(newValue, this.orderBy)), this.comparator); | ||
if (newIndex >= 0) { | ||
@@ -55,3 +57,3 @@ // item with the same value is found - will insert right before it | ||
var isInsertedAbove = this.insertAtIndex(newIndex, key, newValue); | ||
if (this.isOverlapping && this.overlappingKey === key && (currentIndex === 0 || newIndex === 0)) { | ||
if (this.isOverlappingItem(currentIndex, key) || this.isOverlappingItem(newIndex, key)) { | ||
if (currentIndex === 0) { | ||
@@ -102,3 +104,3 @@ if (isDeletedFromAbove && isInsertedAbove) { | ||
var isAbove = this.deleteAtIndex(currentIndex); | ||
if (!isAbove || (this.isOverlapping && currentIndex === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || this.isOverlappingItem(currentIndex, key)) { | ||
return multicursor_collection_change_1.MulticursorCollectionChange.NO_OP; | ||
@@ -111,3 +113,3 @@ } | ||
Buffer.prototype.insert = function (key, newValue) { | ||
var index = bsearch_1.binarySearch(this.items, { key: key, value: newValue }, this.comparator); | ||
var index = bsearch_1.binarySearch(this.items, new item_1.Item(key, newValue, get_1.get(newValue, this.orderBy)), this.comparator); | ||
if (index >= 0) { | ||
@@ -121,3 +123,3 @@ // item with the same value is found - will insert right next to it | ||
var isAbove = this.insertAtIndex(index, key, newValue); | ||
if (!isAbove || (this.isOverlapping && index === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || (this.isOverlappingItem(index, key))) { | ||
return multicursor_collection_change_1.MulticursorCollectionChange.NO_OP; | ||
@@ -136,3 +138,3 @@ } | ||
var isAbove = this.updateAtIndex(currentIndex, key, newValue); | ||
if (!isAbove || (this.isOverlapping && currentIndex === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || this.isOverlappingItem(currentIndex, key)) { | ||
return multicursor_collection_change_1.MulticursorCollectionChange.NO_OP; | ||
@@ -167,3 +169,3 @@ } | ||
var isChangeAbove = (index < this.index); // || (this.index === this.items.length); | ||
this.items.splice(index, 0, new item_1.Item(key, value)); | ||
this.items.splice(index, 0, new item_1.Item(key, value, get_1.get(value, this.orderBy))); | ||
this.keyMap[key] = true; | ||
@@ -183,3 +185,3 @@ if (isChangeAbove) { | ||
Buffer.prototype.updateAtIndex = function (index, key, value) { | ||
this.items[index] = new item_1.Item(key, value); | ||
this.items[index] = new item_1.Item(key, value, get_1.get(value, this.orderBy)); | ||
this.keyMap[key] = true; | ||
@@ -191,2 +193,5 @@ return index < this.index; | ||
}; | ||
Buffer.prototype.isOverlappingItem = function (index, key) { | ||
return this.isOverlapping && index === 0 && this.overlappingKey === key; | ||
}; | ||
Buffer.prototype.next = function () { | ||
@@ -193,0 +198,0 @@ var value = this.peek(); |
@@ -44,2 +44,2 @@ import { Item } from "../../types/item"; | ||
} | ||
export declare const createCursorComparator: (orderByChild: string, isAscending?: boolean) => Comparator<Cursor>; | ||
export declare const createCursorComparator: (isAscending?: boolean) => Comparator<Cursor>; |
@@ -44,2 +44,3 @@ "use strict"; | ||
var firebase_change_1 = require("../../types/firebase-change"); | ||
var get_1 = require("../../utils/get"); | ||
var Cursor = /** @class */ (function () { | ||
@@ -71,3 +72,3 @@ function Cursor(id, database, path, orderBy, comparator, startAtPointer, endAtPointer, maxBatchSize, isAscending, insert, remove, move, update) { | ||
common_1.checkNotNull(isAscending); | ||
this.buffer = new connected_buffer_1.Buffer([], this.comparator, false); | ||
this.buffer = new connected_buffer_1.Buffer([], this.comparator, false, orderBy); | ||
if (!isAscending) { | ||
@@ -117,2 +118,3 @@ var tmp = this.endAtPointer; | ||
var ref, items, snapshot, lastItem; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -127,3 +129,4 @@ switch (_a.label) { | ||
snapshot.forEach(function (child) { | ||
items.push(new item_1.Item(child.key, child.val())); | ||
var value = child.val(); | ||
items.push(new item_1.Item(child.key, value, get_1.get(value, _this.orderBy))); | ||
}); | ||
@@ -144,8 +147,6 @@ // It's easier to have offset from 0 to 1 | ||
} | ||
if (!this.isAtTheEnd) { | ||
lastItem = items[items.length - 1]; | ||
this.fetchedUntilPointer = new pointer_1.Pointer(lastItem.value[this.orderBy], lastItem.key); | ||
this.buffer = new connected_buffer_1.Buffer(items, this.comparator, this.batchNumber >= 0); | ||
this.buffers.push(this.buffer); | ||
} | ||
lastItem = items[items.length - 1]; | ||
this.fetchedUntilPointer = new pointer_1.Pointer(get_1.get(lastItem.value, this.orderBy), lastItem.key); | ||
this.buffer = new connected_buffer_1.Buffer(items, this.comparator, this.batchNumber >= 0, this.orderBy); | ||
this.buffers.push(this.buffer); | ||
if (this.batchNumber === -1) { | ||
@@ -172,2 +173,6 @@ // for all subsequent batches - fetch +1 item more, since | ||
var refLimit; | ||
// It is possible a range is not be limited on either end, so data may | ||
// continue coming indefinitely. To prevent this, limit it to 100 | ||
// TODO: parametrize | ||
var maxUnlimitedRangeItems = 100; | ||
if (this.isAscending) { | ||
@@ -194,2 +199,3 @@ refStartAt = 'startAt'; | ||
// console.log(this.id, this.batchNumber, 'start at inf'); | ||
ref = ref[refLimit](maxUnlimitedRangeItems); | ||
} | ||
@@ -207,2 +213,3 @@ if (this.isAtTheEnd) { | ||
// console.log(this.id, this.batchNumber, 'end at inf'); | ||
ref = ref[refLimit](maxUnlimitedRangeItems); | ||
} | ||
@@ -217,7 +224,5 @@ } | ||
} | ||
// It is possible a range is not be limited on either end, so data may | ||
// continue coming indefinitely. To prevent this, limit it to 100 | ||
// TODO: parametrize | ||
ref = ref[refLimit](100); | ||
this.startAtPointer = this.fetchedUntilPointer; | ||
// console.log('--------Connected buffer set listeners context: '); | ||
// console.log(refState); | ||
ref.on(firebase_change_1.FirebaseChange.CHILD_ADDED, this.on.bind(this, firebase_change_1.FirebaseChange.CHILD_ADDED, this.batchNumber, this.buffer)); | ||
@@ -245,3 +250,3 @@ ref.on(firebase_change_1.FirebaseChange.CHILD_REMOVED, this.on.bind(this, firebase_change_1.FirebaseChange.CHILD_REMOVED, this.batchNumber, this.buffer)); | ||
value = snapshot.val(); | ||
var orderByValue = value[this.orderBy]; | ||
var orderByValue = get_1.get(value, this.orderBy); | ||
// orderByValue is never null because FB does not include null values | ||
@@ -280,3 +285,3 @@ // in the snapshot (the field with null value gets deleted from the object) | ||
value = snapshot.val(); | ||
var orderByValue = value[this.orderBy]; | ||
var orderByValue = get_1.get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -291,3 +296,3 @@ // Happens if the orderBy value was removed from the object | ||
value = snapshot.val(); | ||
var orderByValue = value[this.orderBy]; | ||
var orderByValue = get_1.get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -302,3 +307,3 @@ // TODO: | ||
value = snapshot.val(); | ||
var orderByValue = value[this.orderBy]; | ||
var orderByValue = get_1.get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -351,3 +356,3 @@ // TODO: this happens if value was edited manually from Firebase Web UI | ||
case multicursor_collection_change_1.MulticursorCollectionChange.MOVED: | ||
shouldNext = this.move(this.id, batchNumber, new item_1.Item(snapshot.key, value)); | ||
shouldNext = this.move(this.id, batchNumber, new item_1.Item(snapshot.key, value, get_1.get(value, this.orderBy))); | ||
if (mayBeNext && shouldNext) { | ||
@@ -361,3 +366,3 @@ buffer.next(); | ||
case multicursor_collection_change_1.MulticursorCollectionChange.ADDED: | ||
shouldNext = this.insert(this.id, batchNumber, new item_1.Item(snapshot.key, value)); | ||
shouldNext = this.insert(this.id, batchNumber, new item_1.Item(snapshot.key, value, get_1.get(value, this.orderBy))); | ||
if (mayBeNext && shouldNext) { | ||
@@ -374,3 +379,3 @@ buffer.next(); | ||
case multicursor_collection_change_1.MulticursorCollectionChange.NO_OP: | ||
if (!buffer.hasNext()) { | ||
if (!buffer.hasNext() && !buffer.isOverlappingItem(buffer.index, snapshot.key)) { | ||
// TODO | ||
@@ -430,5 +435,5 @@ throw new Error('No-op only possible for a non-depleted buffer'); | ||
exports.Cursor = Cursor; | ||
exports.createCursorComparator = function (orderByChild, isAscending) { | ||
exports.createCursorComparator = function (isAscending) { | ||
if (isAscending === void 0) { isAscending = true; } | ||
var itemComparator = item_1.createItemComparator(orderByChild, isAscending); | ||
var itemComparator = item_1.createItemComparator(isAscending); | ||
return function (left, right) { | ||
@@ -435,0 +440,0 @@ var leftHasNext = left.hasNextNow(); |
@@ -73,5 +73,5 @@ "use strict"; | ||
common_1.checkNotNull(isAscending); | ||
this.itemComparator = item_1.createItemComparator(orderBy, isAscending); | ||
this.itemContainerComparator = item_container_1.createItemContainerComparator(orderBy, isAscending); | ||
this.cursorComparator = connected_cursor_1.createCursorComparator(orderBy, isAscending); | ||
this.itemComparator = item_1.createItemComparator(isAscending); | ||
this.itemContainerComparator = item_container_1.createItemContainerComparator(isAscending); | ||
this.cursorComparator = connected_cursor_1.createCursorComparator(isAscending); | ||
for (var i = 0; i < paths.length; i++) { | ||
@@ -78,0 +78,0 @@ var cursor = new connected_cursor_1.Cursor(i, database, paths[i], orderBy, this.itemComparator, startAt, endAt, maxBatchSize, isAscending, this.insert.bind(this), this.remove.bind(this), this.move.bind(this), this.update.bind(this)); |
@@ -11,2 +11,2 @@ import { Item } from "./item"; | ||
} | ||
export declare const createItemContainerComparator: (orderByChild: string, isAscending?: boolean) => Comparator<ItemContainer>; | ||
export declare const createItemContainerComparator: (isAscending?: boolean) => Comparator<ItemContainer>; |
@@ -17,6 +17,6 @@ "use strict"; | ||
exports.ItemContainer = ItemContainer; | ||
exports.createItemContainerComparator = function (orderByChild, isAscending) { | ||
exports.createItemContainerComparator = function (isAscending) { | ||
if (isAscending === void 0) { isAscending = true; } | ||
return function (left, right) { | ||
var result = compare_1.compare(left.item.value[orderByChild], right.item.value[orderByChild]); | ||
var result = compare_1.compare(left.item.orderByValue, right.item.orderByValue); | ||
if (!isAscending) { | ||
@@ -23,0 +23,0 @@ result = -result; |
@@ -6,4 +6,5 @@ import { Key } from "./key"; | ||
value: any; | ||
constructor(key: Key, value: any); | ||
orderByValue: any; | ||
constructor(key: Key, value: any, orderByValue: any); | ||
} | ||
export declare const createItemComparator: (orderByChild: string, isAscending?: boolean) => Comparator<Item>; | ||
export declare const createItemComparator: (isAscending?: boolean) => Comparator<Item>; |
@@ -6,7 +6,9 @@ "use strict"; | ||
var Item = /** @class */ (function () { | ||
function Item(key, value) { | ||
function Item(key, value, orderByValue) { | ||
this.key = key; | ||
this.value = value; | ||
this.orderByValue = orderByValue; | ||
common_1.checkNotNull(key); | ||
common_1.checkNotNull(value); | ||
common_1.checkNotNull(orderByValue); | ||
} | ||
@@ -16,6 +18,6 @@ return Item; | ||
exports.Item = Item; | ||
exports.createItemComparator = function (orderByChild, isAscending) { | ||
exports.createItemComparator = function (isAscending) { | ||
if (isAscending === void 0) { isAscending = true; } | ||
return function (left, right) { | ||
var result = compare_1.compare(left.value[orderByChild], right.value[orderByChild]); | ||
var result = compare_1.compare(left.orderByValue, right.orderByValue); | ||
if (result === 0) { | ||
@@ -22,0 +24,0 @@ result = compare_1.compare(left.key, right.key); |
import {Key} from "../../types/key"; | ||
import {Item} from "../../types/item"; | ||
import {get} from "../../utils/get"; | ||
import {checkNotNull} from "../../utils/common"; | ||
@@ -9,3 +11,4 @@ export class Buffer { | ||
constructor(public keys: Key[], public values: any[]) { | ||
constructor(public keys: Key[], public values: any[], public orderBy: string) { | ||
checkNotNull(orderBy); | ||
if (keys.length !== values.length) { | ||
@@ -40,4 +43,5 @@ throw new Error('Keys and values should be equal lengths'); | ||
// TODO: cache the value to avoid too many "new"-s | ||
return new Item(this.keys[this.index], this.values[this.index]); | ||
const value = this.values[this.index]; | ||
return new Item(this.keys[this.index], value, get(value, this.orderBy)); | ||
} | ||
} |
@@ -7,10 +7,10 @@ import {checkNotNull} from "../../utils/common"; | ||
import {Buffer} from "./buffer"; | ||
import {get} from "../../utils/get"; | ||
import {ORDER_BY_KEY} from "../../types/orderByKey"; | ||
export class Cursor { | ||
public static readonly ORDER_BY_KEY = '$ORDER_BY_KEY'; | ||
private hasNextValue: boolean = true; | ||
private hasNextPage: boolean = true; | ||
public buffer: Buffer = new Buffer([], []); | ||
public buffer: Buffer = new Buffer([], [], this.orderBy); | ||
public batchNumber: number = 0; | ||
@@ -60,3 +60,3 @@ | ||
private isOrderByKey() { | ||
return this.orderBy === Cursor.ORDER_BY_KEY; | ||
return this.orderBy === ORDER_BY_KEY; | ||
} | ||
@@ -74,3 +74,3 @@ | ||
if (keys.length === 0) { | ||
return new Buffer([], []); | ||
return new Buffer([], [], this.orderBy); | ||
} | ||
@@ -108,3 +108,3 @@ | ||
} else { | ||
this.startAt = new Pointer(values[values.length - 1][this.orderBy], keys[keys.length - 1]); | ||
this.startAt = new Pointer(get(values[values.length - 1], this.orderBy), keys[keys.length - 1]); | ||
} | ||
@@ -114,3 +114,3 @@ } | ||
this.batchNumber++; | ||
return new Buffer(keys, values); | ||
return new Buffer(keys, values, this.orderBy); | ||
} | ||
@@ -117,0 +117,0 @@ |
@@ -6,7 +6,6 @@ import FastPriorityQueue from 'fastpriorityqueue'; | ||
import {Cursor} from "./cursor"; | ||
import {ORDER_BY_KEY} from "../../types/orderByKey"; | ||
export class MultiCursor { | ||
public static readonly ORDER_BY_KEY = Cursor.ORDER_BY_KEY; | ||
private readonly cursors: Cursor[] = []; | ||
@@ -18,3 +17,3 @@ private readonly cursorComparator: (left: Cursor, right: Cursor) => boolean; | ||
paths: string | string[], | ||
orderBy: string = MultiCursor.ORDER_BY_KEY, | ||
orderBy: string = ORDER_BY_KEY, | ||
startAt: Pointer | null = null, | ||
@@ -38,6 +37,6 @@ endAt: Pointer | null = null, | ||
const rightItem = right.peek(); | ||
if (leftItem.value[orderBy] < rightItem.value[orderBy]) { | ||
if (leftItem.orderByValue < rightItem.orderByValue) { | ||
return isAscending; | ||
} | ||
if (leftItem.value[orderBy] > rightItem.value[orderBy]) { | ||
if (leftItem.orderByValue > rightItem.orderByValue) { | ||
return !isAscending; | ||
@@ -44,0 +43,0 @@ } |
@@ -6,2 +6,3 @@ import {binarySearch} from "../../utils/bsearch"; | ||
import {MulticursorCollectionChange} from "../../types/multicursor-collection-change"; | ||
import {get} from "../../utils/get"; | ||
@@ -20,3 +21,4 @@ export class Buffer { | ||
private comparator: Comparator<Item>, | ||
private isOverlapping: boolean | ||
private isOverlapping: boolean, | ||
private orderBy: string | ||
) { | ||
@@ -54,3 +56,3 @@ for (let i = 0; i < items.length; i++) { | ||
const isDeletedFromAbove = this.deleteAtIndex(currentIndex); | ||
let newIndex = binarySearch(this.items, {key: key, value: newValue}, this.comparator); | ||
let newIndex = binarySearch(this.items, new Item(key, newValue, get(newValue, this.orderBy)), this.comparator); | ||
if (newIndex >= 0) { | ||
@@ -65,3 +67,3 @@ // item with the same value is found - will insert right before it | ||
if (this.isOverlapping && this.overlappingKey === key && (currentIndex === 0 || newIndex === 0)) { | ||
if (this.isOverlappingItem(currentIndex, key) || this.isOverlappingItem(newIndex, key)) { | ||
if (currentIndex === 0) { | ||
@@ -104,3 +106,3 @@ if (isDeletedFromAbove && isInsertedAbove) { | ||
const isAbove = this.deleteAtIndex(currentIndex); | ||
if (!isAbove || (this.isOverlapping && currentIndex === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || this.isOverlappingItem(currentIndex, key)) { | ||
return MulticursorCollectionChange.NO_OP; | ||
@@ -113,3 +115,3 @@ } else { | ||
public insert(key: Key, newValue: any): MulticursorCollectionChange.ADDED | MulticursorCollectionChange.NO_OP { | ||
let index = binarySearch(this.items, {key: key, value: newValue}, this.comparator); | ||
let index = binarySearch(this.items, new Item(key, newValue, get(newValue, this.orderBy)), this.comparator); | ||
if (index >= 0) { | ||
@@ -122,3 +124,3 @@ // item with the same value is found - will insert right next to it | ||
const isAbove = this.insertAtIndex(index, key, newValue); | ||
if (!isAbove || (this.isOverlapping && index === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || (this.isOverlappingItem(index, key))) { | ||
return MulticursorCollectionChange.NO_OP; | ||
@@ -137,3 +139,3 @@ } else { | ||
const isAbove = this.updateAtIndex(currentIndex, key, newValue); | ||
if (!isAbove || (this.isOverlapping && currentIndex === 0 && this.overlappingKey === key)) { | ||
if (!isAbove || this.isOverlappingItem(currentIndex, key)) { | ||
return MulticursorCollectionChange.NO_OP; | ||
@@ -168,3 +170,3 @@ } else { | ||
let isChangeAbove = (index < this.index);// || (this.index === this.items.length); | ||
this.items.splice(index, 0, new Item(key, value)); | ||
this.items.splice(index, 0, new Item(key, value, get(value, this.orderBy))); | ||
this.keyMap[key] = true; | ||
@@ -184,3 +186,3 @@ if (isChangeAbove) { | ||
private updateAtIndex(index: number, key: Key, value: any) { | ||
this.items[index] = new Item(key, value); | ||
this.items[index] = new Item(key, value, get(value, this.orderBy)); | ||
this.keyMap[key] = true; | ||
@@ -194,2 +196,6 @@ return index < this.index; | ||
public isOverlappingItem(index: number, key: Key) { | ||
return this.isOverlapping && index === 0 && this.overlappingKey === key; | ||
} | ||
public next(): Item { | ||
@@ -196,0 +202,0 @@ const value = this.peek(); |
@@ -9,2 +9,3 @@ import {checkNotNull} from "../../utils/common"; | ||
import {FirebaseChange} from "../../types/firebase-change"; | ||
import {get} from "../../utils/get"; | ||
@@ -39,3 +40,3 @@ export class Cursor { | ||
checkNotNull(isAscending); | ||
this.buffer = new Buffer([], this.comparator, false); | ||
this.buffer = new Buffer([], this.comparator, false, orderBy); | ||
@@ -86,3 +87,4 @@ if (!isAscending) { | ||
snapshot.forEach((child: firebase.database.DataSnapshot) => { | ||
items.push(new Item(child.key as string, child.val())); | ||
const value = child.val(); | ||
items.push(new Item(child.key as string, value, get(value, this.orderBy))); | ||
}); | ||
@@ -105,8 +107,10 @@ | ||
if (!this.isAtTheEnd) { | ||
const lastItem = items[items.length - 1]; | ||
this.fetchedUntilPointer = new Pointer(lastItem.value[this.orderBy], lastItem.key); | ||
this.buffer = new Buffer(items, this.comparator, this.batchNumber >= 0); | ||
this.buffers.push(this.buffer); | ||
} | ||
/** | ||
* We should create a new Buffer anyway even if isAtTheEnd === true | ||
* to avoid setting listeners twice on the same buffer. | ||
*/ | ||
const lastItem = items[items.length - 1]; | ||
this.fetchedUntilPointer = new Pointer(get(lastItem.value, this.orderBy), lastItem.key); | ||
this.buffer = new Buffer(items, this.comparator, this.batchNumber >= 0, this.orderBy); | ||
this.buffers.push(this.buffer); | ||
@@ -120,3 +124,6 @@ if (this.batchNumber === -1) { | ||
this.batchNumber++; | ||
this.connect(); | ||
} | ||
@@ -132,2 +139,9 @@ | ||
let refLimit; | ||
// It is possible a range is not be limited on either end, so data may | ||
// continue coming indefinitely. To prevent this, limit it to 100 | ||
// TODO: parametrize | ||
const maxUnlimitedRangeItems = 100; | ||
if (this.isAscending) { | ||
@@ -152,2 +166,3 @@ refStartAt = 'startAt'; | ||
// console.log(this.id, this.batchNumber, 'start at inf'); | ||
ref = ref[refLimit](maxUnlimitedRangeItems); | ||
} | ||
@@ -163,2 +178,3 @@ if (this.isAtTheEnd) { | ||
// console.log(this.id, this.batchNumber, 'end at inf'); | ||
ref = ref[refLimit](maxUnlimitedRangeItems); | ||
} | ||
@@ -173,8 +189,6 @@ } else { | ||
// It is possible a range is not be limited on either end, so data may | ||
// continue coming indefinitely. To prevent this, limit it to 100 | ||
// TODO: parametrize | ||
ref = ref[refLimit](100); | ||
this.startAtPointer = this.fetchedUntilPointer; | ||
// console.log('--------Connected buffer set listeners context: '); | ||
// console.log(refState); | ||
this.startAtPointer = this.fetchedUntilPointer; | ||
ref.on(FirebaseChange.CHILD_ADDED, this.on.bind(this, FirebaseChange.CHILD_ADDED, this.batchNumber, this.buffer)); | ||
@@ -204,3 +218,3 @@ ref.on(FirebaseChange.CHILD_REMOVED, this.on.bind(this, FirebaseChange.CHILD_REMOVED, this.batchNumber, this.buffer)); | ||
value = snapshot.val(); | ||
let orderByValue = value[this.orderBy]; | ||
let orderByValue = get(value, this.orderBy); | ||
// orderByValue is never null because FB does not include null values | ||
@@ -238,3 +252,3 @@ // in the snapshot (the field with null value gets deleted from the object) | ||
value = snapshot.val(); | ||
let orderByValue = value[this.orderBy]; | ||
let orderByValue = get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -247,5 +261,5 @@ // Happens if the orderBy value was removed from the object | ||
} | ||
case FirebaseChange.CHILD_REMOVED: { | ||
case FirebaseChange.CHILD_REMOVED: { | ||
value = snapshot.val(); | ||
let orderByValue = value[this.orderBy]; | ||
let orderByValue = get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -260,3 +274,3 @@ // TODO: | ||
value = snapshot.val(); | ||
let orderByValue = value[this.orderBy]; | ||
let orderByValue = get(value, this.orderBy); | ||
if (orderByValue === undefined) { | ||
@@ -309,3 +323,3 @@ // TODO: this happens if value was edited manually from Firebase Web UI | ||
case MulticursorCollectionChange.MOVED: | ||
shouldNext = this.move(this.id, batchNumber, new Item(snapshot.key, value)); | ||
shouldNext = this.move(this.id, batchNumber, new Item(snapshot.key, value, get(value, this.orderBy))); | ||
if (mayBeNext && shouldNext) { | ||
@@ -319,3 +333,3 @@ buffer.next(); | ||
case MulticursorCollectionChange.ADDED: | ||
shouldNext = this.insert(this.id, batchNumber, new Item(snapshot.key, value)); | ||
shouldNext = this.insert(this.id, batchNumber, new Item(snapshot.key, value, get(value, this.orderBy))); | ||
if (mayBeNext && shouldNext) { | ||
@@ -332,3 +346,4 @@ buffer.next(); | ||
case MulticursorCollectionChange.NO_OP: | ||
if (!buffer.hasNext()) { | ||
if (!buffer.hasNext() && !buffer.isOverlappingItem(buffer.index, snapshot.key)) { | ||
// TODO | ||
@@ -390,4 +405,4 @@ throw new Error('No-op only possible for a non-depleted buffer'); | ||
export const createCursorComparator = (orderByChild: string, isAscending: boolean = true): Comparator<Cursor> => { | ||
const itemComparator = createItemComparator(orderByChild, isAscending); | ||
export const createCursorComparator = (isAscending: boolean = true): Comparator<Cursor> => { | ||
const itemComparator = createItemComparator(isAscending); | ||
return (left: Cursor, right: Cursor): number => { | ||
@@ -394,0 +409,0 @@ const leftHasNext = left.hasNextNow(); |
@@ -51,5 +51,5 @@ import {checkNotNull} from "../../utils/common"; | ||
checkNotNull(isAscending); | ||
this.itemComparator = createItemComparator(orderBy, isAscending); | ||
this.itemContainerComparator = createItemContainerComparator(orderBy, isAscending); | ||
this.cursorComparator = createCursorComparator(orderBy, isAscending); | ||
this.itemComparator = createItemComparator(isAscending); | ||
this.itemContainerComparator = createItemContainerComparator(isAscending); | ||
this.cursorComparator = createCursorComparator(isAscending); | ||
for (let i = 0; i < paths.length; i++) { | ||
@@ -56,0 +56,0 @@ const cursor = new Cursor( |
@@ -18,5 +18,5 @@ import {Item} from "./item"; | ||
export const createItemContainerComparator = (orderByChild: string, isAscending: boolean = true): Comparator<ItemContainer> => { | ||
export const createItemContainerComparator = (isAscending: boolean = true): Comparator<ItemContainer> => { | ||
return (left: ItemContainer, right: ItemContainer): number => { | ||
let result = compare(left.item.value[orderByChild], right.item.value[orderByChild]); | ||
let result = compare(left.item.orderByValue, right.item.orderByValue); | ||
if (!isAscending) { | ||
@@ -23,0 +23,0 @@ result = -result; |
@@ -7,11 +7,13 @@ import {checkNotNull} from "../utils/common"; | ||
export class Item { | ||
constructor(public key: Key, public value: any) { | ||
constructor(public key: Key, public value: any, public orderByValue: any) { | ||
checkNotNull(key); | ||
checkNotNull(value); | ||
checkNotNull(orderByValue); | ||
} | ||
} | ||
export const createItemComparator = (orderByChild: string, isAscending: boolean = true): Comparator<Item> => { | ||
export const createItemComparator = (isAscending: boolean = true): Comparator<Item> => { | ||
return (left: Item, right: Item): number => { | ||
let result = compare(left.value[orderByChild], right.value[orderByChild]); | ||
let result = compare(left.orderByValue, right.orderByValue); | ||
if (result === 0) { | ||
@@ -18,0 +20,0 @@ result = compare(left.key, right.key); |
{ | ||
"name": "@zum/firebase-pagination", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Extended functionality of Firebase pagination", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,2 +8,4 @@ const chai = require('chai'); | ||
const orderBy = 'id'; | ||
describe('tests for buffer.ts and cursor.ts', async () => { | ||
@@ -14,3 +16,3 @@ | ||
it('should iterate Buffer with 0 items w/o hasNext', () => { | ||
const buffer = new Buffer([], []); | ||
const buffer = new Buffer([], [], orderBy); | ||
expect(buffer.next.bind(buffer)).to.throw(); | ||
@@ -20,3 +22,3 @@ }); | ||
it('should iterate Buffer with 0 items', () => { | ||
const buffer = new Buffer([], []); | ||
const buffer = new Buffer([], [], orderBy); | ||
expect(buffer.hasNext()).to.equal(false); | ||
@@ -27,5 +29,6 @@ expect(buffer.next.bind(buffer)).to.throw(); | ||
it('should iterate Buffer with 1 item', () => { | ||
const buffer = new Buffer(['k1'], ['v1']); | ||
const value = {[orderBy]: 'v1'}; | ||
const buffer = new Buffer(['k1'], [value], orderBy); | ||
expect(buffer.hasNext()).to.equal(true); | ||
expect(buffer.next()).to.deep.equal(new Item('k1', 'v1')); | ||
expect(buffer.next()).to.deep.equal(new Item('k1', value, 'v1')); | ||
expect(buffer.hasNext()).to.equal(false); | ||
@@ -36,7 +39,9 @@ expect(buffer.next.bind(buffer)).to.throw(); | ||
it('should iterate Buffer with 2 items', () => { | ||
const buffer = new Buffer(['k1', 'k2'], ['v1', 'v2']); | ||
const v1 = {[orderBy]: 'v1'}; | ||
const v2 = {[orderBy]: 'v2'}; | ||
const buffer = new Buffer(['k1', 'k2'], [v1, v2], orderBy); | ||
expect(buffer.hasNext()).to.equal(true); | ||
expect(buffer.next()).to.deep.equal(new Item('k1', 'v1')); | ||
expect(buffer.next()).to.deep.equal(new Item('k1', v1, 'v1')); | ||
expect(buffer.hasNext()).to.equal(true); | ||
expect(buffer.next()).to.deep.equal(new Item('k2', 'v2')); | ||
expect(buffer.next()).to.deep.equal(new Item('k2', v2, 'v2')); | ||
expect(buffer.hasNext()).to.equal(false); | ||
@@ -78,3 +83,3 @@ expect(buffer.next.bind(buffer)).to.throw(); | ||
expect(await cursor.hasNext()).to.equal(true); | ||
expect(cursor.next()).to.deep.equal(new Item('k1', 'v1')); | ||
expect(cursor.next()).to.deep.equal(new Item('k1', 'v1', 'v1')); | ||
expect(await cursor.hasNext()).to.equal(false); | ||
@@ -127,9 +132,9 @@ expect(cursor.next.bind(cursor)).to.throw(); | ||
expect(await cursor.hasNext()).to.equal(true); | ||
expect(cursor.next()).to.deep.equal(new Item('k1', {timestamp: 'd1'})); | ||
expect(cursor.next()).to.deep.equal(new Item('k1', {timestamp: 'd1'}, 'd1')); | ||
expect(await cursor.hasNext()).to.equal(true); | ||
expect(cursor.next()).to.deep.equal(new Item('k2', {timestamp: 'd2'})); | ||
expect(cursor.next()).to.deep.equal(new Item('k2', {timestamp: 'd2'}, 'd2')); | ||
expect(await cursor.hasNext()).to.equal(true); | ||
expect(cursor.next()).to.deep.equal(new Item('k3', {timestamp: 'd3'})); | ||
expect(cursor.next()).to.deep.equal(new Item('k3', {timestamp: 'd3'}, 'd3')); | ||
@@ -147,3 +152,3 @@ cursor.getRef = () => { | ||
expect(await cursor.hasNext()).to.equal(true); | ||
expect(cursor.next()).to.deep.equal(new Item('k4', {timestamp: 'd4'})); | ||
expect(cursor.next()).to.deep.equal(new Item('k4', {timestamp: 'd4'}, 'd4')); | ||
expect(await cursor.hasNext()).to.equal(false); | ||
@@ -150,0 +155,0 @@ }); |
@@ -101,2 +101,5 @@ const chai = require('chai'); | ||
"key": "r01", | ||
"orderByValue": { | ||
"id": 0 | ||
}, | ||
"value": { | ||
@@ -108,2 +111,5 @@ "id": 0 | ||
"key": "r101", | ||
"orderByValue": { | ||
"id": 100 | ||
}, | ||
"value": { | ||
@@ -115,2 +121,5 @@ "id": 100 | ||
"key": "r11", | ||
"orderByValue": { | ||
"id": 10 | ||
}, | ||
"value": { | ||
@@ -122,2 +131,5 @@ "id": 10 | ||
"key": "r131", | ||
"orderByValue": { | ||
"id": 130 | ||
}, | ||
"value": { | ||
@@ -129,2 +141,5 @@ "id": 130 | ||
"key": "r21", | ||
"orderByValue": { | ||
"id": 20 | ||
}, | ||
"value": { | ||
@@ -136,2 +151,5 @@ "id": 20 | ||
"key": "r61", | ||
"orderByValue": { | ||
"id": 60 | ||
}, | ||
"value": { | ||
@@ -143,2 +161,5 @@ "id": 60 | ||
"key": "r71", | ||
"orderByValue": { | ||
"id": 70 | ||
}, | ||
"value": { | ||
@@ -150,2 +171,5 @@ "id": 70 | ||
"key": "r91", | ||
"orderByValue": { | ||
"id": 90 | ||
}, | ||
"value": { | ||
@@ -160,2 +184,3 @@ "id": 90 | ||
"key": "r01", | ||
"orderByValue": 0, | ||
"value": { | ||
@@ -167,2 +192,3 @@ "id": 0 | ||
"key": "r11", | ||
"orderByValue": 10, | ||
"value": { | ||
@@ -174,2 +200,3 @@ "id": 10 | ||
"key": "r21", | ||
"orderByValue": 20, | ||
"value": { | ||
@@ -181,2 +208,3 @@ "id": 20 | ||
"key": "r61", | ||
"orderByValue": 60, | ||
"value": { | ||
@@ -188,2 +216,3 @@ "id": 60 | ||
"key": "r71", | ||
"orderByValue": 70, | ||
"value": { | ||
@@ -195,2 +224,3 @@ "id": 70 | ||
"key": "r91", | ||
"orderByValue": 90, | ||
"value": { | ||
@@ -202,2 +232,3 @@ "id": 90 | ||
"key": "r101", | ||
"orderByValue": 100, | ||
"value": { | ||
@@ -209,2 +240,3 @@ "id": 100 | ||
"key": "r131", | ||
"orderByValue": 130, | ||
"value": { | ||
@@ -211,0 +243,0 @@ "id": 130 |
@@ -7,6 +7,8 @@ const chai = require('chai'); | ||
const orderBy = 'id'; | ||
describe.skip('tests for connected-buffer.ts', async () => { | ||
it('should insert', () => { | ||
const buffer = new Buffer(['a', 'b', 'c'], [{id: 1}, {id: 2}, {id: 3}], 'id', false); | ||
const buffer = new Buffer(['a', 'b', 'c'], [{id: 1}, {id: 2}, {id: 3}], false, orderBy); | ||
expect(buffer.insert('a', {type: 'new'})).eq('no_action'); | ||
@@ -17,3 +19,3 @@ expect(buffer.values[0]).null; | ||
it('should iterate Buffer with 0 items w/o hasNext', () => { | ||
const buffer = new Buffer([], []); | ||
const buffer = new Buffer([], [], orderBy); | ||
expect(buffer.next()).null; | ||
@@ -23,3 +25,3 @@ }); | ||
it('should iterate Buffer with 0 items', () => { | ||
const buffer = new Buffer([], []); | ||
const buffer = new Buffer([], [], orderBy); | ||
expect(buffer.hasNext()).to.equal(false); | ||
@@ -30,3 +32,3 @@ expect(buffer.next()).null; | ||
it('should iterate Buffer with 1 item', () => { | ||
const buffer = new Buffer(['k1'], ['v1']); | ||
const buffer = new Buffer(['k1'], ['v1'], orderBy); | ||
expect(buffer.hasNext()).to.equal(true); | ||
@@ -39,3 +41,3 @@ expect(buffer.next()).to.deep.equal(new Item('k1', 'v1')); | ||
it('should iterate Buffer with 2 items', () => { | ||
const buffer = new Buffer(['k1', 'k2'], ['v1', 'v2']); | ||
const buffer = new Buffer(['k1', 'k2'], ['v1', 'v2'], orderBy); | ||
expect(buffer.hasNext()).to.equal(true); | ||
@@ -42,0 +44,0 @@ expect(buffer.next()).to.deep.equal(new Item('k1', 'v1')); |
@@ -28,3 +28,3 @@ const chai = require('chai'); | ||
project.id, cert, project.databaseAuthVariableOverrideUid, | ||
'connected-multicursor.spec.js').database(); | ||
'connected-multicursor.integration.spec.js').database(); | ||
}); | ||
@@ -114,5 +114,5 @@ | ||
await cursor.nextPage(3); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r00", "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r01", "value": {"id": 0}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r00", "orderByValue": 0, "orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r01", "orderByValue": 0, "orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r10", "orderByValue": 10, "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items.length).equal(3); | ||
@@ -122,10 +122,10 @@ expect(cursor.withMoreDataCursors.length).equal(3); | ||
await cursor.nextPage(8); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r11", "value": {"id": 10}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r12", "value": {"id": 10}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r21", "value": {"id": 20}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r22", "value": {"id": 20}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r32", "value": {"id": 30}}}); | ||
expect(cursor.items[8]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "value": {"id": 50}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r11", "orderByValue": 10, "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r12", "orderByValue": 10, "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 0, "cursorId": c1Index, "item": {"key": "r21", "orderByValue": 20, "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r22", "orderByValue": 20, "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 0, "cursorId": c2Index, "item": {"key": "r32", "orderByValue": 30, "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[8]).to.deep.equal({"batchNumber": 0, "cursorId": c0Index, "item": {"key": "r40", "orderByValue": 40, "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(11); | ||
@@ -136,5 +136,5 @@ expect(cursor.withMoreDataCursors.length).equal(2); | ||
await cursor.nextPage(3); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "value": {"id": 60}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "value": {"id": 70}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "value": {"id": 80}}}); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "orderByValue": 70, "value": {"id": 70}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "orderByValue": 80, "value": {"id": 80}}}); | ||
expect(cursor.items.length).equal(14); | ||
@@ -146,8 +146,8 @@ expect(cursor.withMoreDataCursors.length).equal(2); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "value": {"id": 50}}}); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_1", "value": {"id": 51}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "value": {"id": 60}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "value": {"id": 70}}}); | ||
expect(cursor.items[14]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "value": {"id": 80}}}); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_1", "orderByValue": 51, "value": {"id": 51}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "orderByValue": 70, "value": {"id": 70}}}); | ||
expect(cursor.items[14]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "orderByValue": 80, "value": {"id": 80}}}); | ||
expect(cursor.items.length).equal(15); | ||
@@ -159,9 +159,9 @@ expect(cursor.withMoreDataCursors.length).equal(2); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "value": {"id": 50}}}); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_1", "value": {"id": 51}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_2", "value": {"id": 52}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "value": {"id": 60}}}); | ||
expect(cursor.items[14]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "value": {"id": 70}}}); | ||
expect(cursor.items[15]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "value": {"id": 80}}}); | ||
expect(cursor.items[9]).to.deep.equal({"batchNumber": 1, "cursorId": c0Index, "item": {"key": "r50", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r52", "orderByValue": 50, "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[11]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_1", "orderByValue": 51, "value": {"id": 51}}}); | ||
expect(cursor.items[12]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_2", "orderByValue": 52, "value": {"id": 52}}}); | ||
expect(cursor.items[13]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r61", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items[14]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r71", "orderByValue": 70, "value": {"id": 70}}}); | ||
expect(cursor.items[15]).to.deep.equal({"batchNumber": 1, "cursorId": c2Index, "item": {"key": "r82", "orderByValue": 80, "value": {"id": 80}}}); | ||
expect(cursor.items.length).equal(16); | ||
@@ -179,5 +179,5 @@ expect(cursor.withMoreDataCursors.length).equal(2); | ||
await cursor.nextPage(3); | ||
expect(cursor.items[15]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_2", "value": {"id": 90}}}); | ||
expect(cursor.items[16]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r91", "value": {"id": 90}}}); | ||
expect(cursor.items[17]).to.deep.equal({"batchNumber": 2, "cursorId": c1Index, "item": {"key": "r101", "value": {"id": 100}}}); | ||
expect(cursor.items[15]).to.deep.equal({"batchNumber": 2, "cursorId": c0Index, "item": {"key": "r50_2", "orderByValue": 90, "value": {"id": 90}}}); | ||
expect(cursor.items[16]).to.deep.equal({"batchNumber": 1, "cursorId": c1Index, "item": {"key": "r91", "orderByValue": 90, "value": {"id": 90}}}); | ||
expect(cursor.items[17]).to.deep.equal({"batchNumber": 2, "cursorId": c1Index, "item": {"key": "r101", "orderByValue": 100, "value": {"id":100}}}); | ||
expect(cursor.items.length).equal(18); | ||
@@ -499,6 +499,6 @@ expect(cursor.withMoreDataCursors.length).equal(2); | ||
await cursor.nextPage(10); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items.length).equal(4); | ||
@@ -515,11 +515,23 @@ | ||
await cursor.nextPage(6); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r00", "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r00", "orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(6); | ||
}); | ||
it('should remove last item after the listeners were set', async () => { | ||
cursor = new MultiCursor(database, paths, orderByChild, new Pointer(10), new Pointer(50), 3, isAscending); | ||
await cursor.nextPage(6); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(5); | ||
database.ref(PATH_PAGINATION_SINGLE).child('r50').remove(); | ||
}); | ||
it('should insert items before and after current buffer index', async () => { | ||
@@ -532,6 +544,6 @@ cursor = new MultiCursor(database, paths, orderByChild, null, null, 3, isAscending); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(4); | ||
@@ -542,28 +554,28 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(4); | ||
await cursor.nextPage(3); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r21","value": {"id": 21}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r30","value": {"id": 30}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r40","value": {"id": 40}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r21","orderByValue": 21, "value": {"id": 21}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r30","orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r40","orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items.length).equal(7); | ||
await cursor.nextPage(3); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r21","value": {"id": 21}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r30","value": {"id": 30}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r40","value": {"id": 40}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r50","value": {"id": 50}}}); | ||
expect(cursor.items[8]).to.deep.equal({"batchNumber": 2,"cursorId": 0,"item": {"key": "r60","value": {"id": 60}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 0, "value": {"id": 0}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r11","orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r21","orderByValue": 21, "value": {"id": 21}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r30","orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r40","orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 1,"cursorId": 0,"item": {"key": "r50","orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items[8]).to.deep.equal({"batchNumber": 2,"cursorId": 0,"item": {"key": "r60","orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items.length).equal(9); | ||
@@ -592,5 +604,5 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 11}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(3); | ||
@@ -602,4 +614,4 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(2); | ||
@@ -611,4 +623,4 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r20","orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(2); | ||
@@ -620,3 +632,3 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items.length).equal(1); | ||
@@ -628,4 +640,4 @@ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","value": {"id": 1}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","value": {"id": 10}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r00","orderByValue": 1, "value": {"id": 1}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0,"cursorId": 0,"item": {"key": "r10","orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items.length).equal(2); | ||
@@ -663,8 +675,8 @@ }); | ||
*/ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r00", "value": {"id": 11}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r00", "orderByValue": 11, "value": {"id": 11}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(6); | ||
@@ -686,8 +698,8 @@ | ||
*/ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r00", "value": {"id": 21}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r00", "orderByValue": 21, "value": {"id": 21}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(6); | ||
@@ -710,8 +722,8 @@ | ||
*/ | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r00", "value": {"id": 21}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r20", "value": {"id": 22}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r00", "orderByValue": 21, "value": {"id": 21}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r20", "orderByValue": 22, "value": {"id": 22}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(6); | ||
@@ -726,3 +738,3 @@ }); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r60", "value": {"id": 60}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r60", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items.length).eq(7); | ||
@@ -733,7 +745,7 @@ | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 3, "cursorId": 0, "item": {"key": "r70", "value": {"id": 70}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 3, "cursorId": 0, "item": {"key": "r70", "orderByValue": 70, "value": {"id": 70}}}); | ||
expect(cursor.items.length).eq(8); | ||
await cursor.nextPage(6); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 3, "cursorId": 0, "item": {"key": "r70", "value": {"id": 70}}}); | ||
expect(cursor.items[7]).to.deep.equal({"batchNumber": 3, "cursorId": 0, "item": {"key": "r70", "orderByValue": 70, "value": {"id": 70}}}); | ||
expect(cursor.items.length).eq(8); | ||
@@ -748,3 +760,3 @@ }); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r60", "value": {"id": 60}}}); | ||
expect(cursor.items[6]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r60", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items.length).eq(7); | ||
@@ -759,3 +771,3 @@ | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r100", "value": {"id": 100}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r100", "orderByValue": 100, "value": {"id":100}}}); | ||
expect(cursor.items.length).eq(11); | ||
@@ -765,3 +777,3 @@ | ||
await sleep(); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r80", "value": {"id": 800}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r80", "orderByValue": 800, "value": {"id": 800}}}); | ||
expect(cursor.items.length).eq(11); | ||
@@ -771,3 +783,3 @@ | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r80", "value": {"id": 800}}}); | ||
expect(cursor.items[10]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r80", "orderByValue": 800, "value": {"id": 800}}}); | ||
expect(cursor.items.length).eq(11); | ||
@@ -780,5 +792,5 @@ }); | ||
await cursor.nextPage(6); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items.length).equal(3); | ||
@@ -795,14 +807,14 @@ }); | ||
// console.log(cursor.items); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r60", "value": {"id": 60}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r50", "value": {"id": 50}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r60", "orderByValue": 60, "value": {"id": 60}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r50", "orderByValue": 50, "value": {"id": 50}}}); | ||
expect(cursor.items.length).equal(2); | ||
await cursor.nextPage(2); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items[3]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items.length).equal(4); | ||
await cursor.nextPage(2); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r10", "value": {"id": 10}}}); | ||
expect(cursor.items[4]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[5]).to.deep.equal({"batchNumber": 2, "cursorId": 0, "item": {"key": "r10", "orderByValue": 10, "value": {"id":10}}}); | ||
expect(cursor.items.length).equal(6); | ||
@@ -816,5 +828,5 @@ | ||
await cursor.nextPage(6); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "value": {"id": 20}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "value": {"id": 30}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "value": {"id": 40}}}); | ||
expect(cursor.items[0]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r20", "orderByValue": 20, "value": {"id":20}}}); | ||
expect(cursor.items[1]).to.deep.equal({"batchNumber": 0, "cursorId": 0, "item": {"key": "r30", "orderByValue": 30, "value": {"id": 30}}}); | ||
expect(cursor.items[2]).to.deep.equal({"batchNumber": 1, "cursorId": 0, "item": {"key": "r40", "orderByValue": 40, "value": {"id": 40}}}); | ||
expect(cursor.items.length).equal(3); | ||
@@ -821,0 +833,0 @@ }); |
@@ -38,2 +38,4 @@ const chai = require('chai'); | ||
pageCount++; | ||
} else { | ||
cb({key: 'k03', val: () => {return {"name": "clair"}}}); | ||
} | ||
@@ -62,3 +64,3 @@ } | ||
"isDuplicate": false, | ||
"item": {"key": "k00", value: { name: "andrew"}} | ||
"item": {"key": "k00", "orderByValue": "andrew", value: { name: "andrew"}} | ||
}); | ||
@@ -70,3 +72,3 @@ expect(cursor.items[1]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k01", value: { name: "bob"}} | ||
"item": {"key": "k01", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -78,3 +80,3 @@ expect(cursor.items[2]).to.deep.equal({ | ||
"isDuplicate": true, | ||
"item": {"key": "k02", value: { name: "bob"}} | ||
"item": {"key": "k02", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -86,3 +88,3 @@ expect(cursor.items[3]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k03", value: { name: "clair"}} | ||
"item": {"key": "k03", "orderByValue": "clair", value: { name: "clair"}} | ||
}); | ||
@@ -98,3 +100,3 @@ | ||
"isDuplicate": false, | ||
"item": {"key": "k04", value: { name: "andrew"}} | ||
"item": {"key": "k04", "orderByValue": "andrew", value: { name: "andrew"}} | ||
}); | ||
@@ -106,3 +108,3 @@ expect(cursor.items[1]).to.deep.equal({ | ||
"isDuplicate": true, | ||
"item": {"key": "k00", value: { name: "andrew"}} | ||
"item": {"key": "k00", "orderByValue": "andrew", value: { name: "andrew"}} | ||
}); | ||
@@ -114,3 +116,3 @@ expect(cursor.items[2]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k01", value: { name: "bob"}} | ||
"item": {"key": "k01", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -122,3 +124,3 @@ expect(cursor.items[3]).to.deep.equal({ | ||
"isDuplicate": true, | ||
"item": {"key": "k02", value: { name: "bob"}} | ||
"item": {"key": "k02", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -130,3 +132,3 @@ expect(cursor.items[4]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k03", value: { name: "clair"}} | ||
"item": {"key": "k03", "orderByValue": "clair", value: { name: "clair"}} | ||
}); | ||
@@ -142,3 +144,3 @@ | ||
"isDuplicate": false, | ||
"item": {"key": "k00", value: { name: "andrew"}} | ||
"item": {"key": "k00", "orderByValue": "andrew", value: { name: "andrew"}} | ||
}); | ||
@@ -150,3 +152,3 @@ expect(cursor.items[1]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k01", value: { name: "bob"}} | ||
"item": {"key": "k01", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -158,3 +160,3 @@ expect(cursor.items[2]).to.deep.equal({ | ||
"isDuplicate": true, | ||
"item": {"key": "k02", value: { name: "bob"}} | ||
"item": {"key": "k02", "orderByValue": "bob", value: { name: "bob"}} | ||
}); | ||
@@ -166,3 +168,3 @@ expect(cursor.items[3]).to.deep.equal({ | ||
"isDuplicate": false, | ||
"item": {"key": "k03", value: { name: "clair"}} | ||
"item": {"key": "k03", "orderByValue": "clair", value: { name: "clair"}} | ||
}); | ||
@@ -184,3 +186,3 @@ }); | ||
for (let i = 0; i < N; i++) { | ||
cb({key: 'k' + i, val: () => 'v' + i}); | ||
cb({key: 'k' + i, val: () => { return {id: 'v' + i}}}); | ||
} | ||
@@ -217,3 +219,3 @@ } | ||
"cursorId": 0, | ||
"item": {"key": "k0", "value": "v0"} | ||
"item": {"key": "k0", "orderByValue": "v0", "value": { "id": "v0" }} | ||
}); | ||
@@ -223,3 +225,3 @@ expect(cursor.items[N - 1]).to.deep.equal({ | ||
"cursorId": 0, | ||
"item": {"key": "k" + (N - 1), "value": "v" + (N - 1)} | ||
"item": {"key": "k" + (N - 1), "orderByValue": "v" + (N - 1), "value": { id: "v" + (N - 1)}} | ||
}); | ||
@@ -226,0 +228,0 @@ expect(cursor.items.length).equal(N); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
258918
92
4918