diff --git a/src/matrix/storage/idb/QueryTarget.ts b/src/matrix/storage/idb/QueryTarget.ts index c8fc8df1..8ed702da 100644 --- a/src/matrix/storage/idb/QueryTarget.ts +++ b/src/matrix/storage/idb/QueryTarget.ts @@ -32,10 +32,12 @@ interface QueryTargetInterface { export class QueryTarget { protected _target: QueryTargetInterface; protected _idbFactory: IDBFactory + protected _IDBKeyRange: typeof IDBKeyRange - constructor(target: QueryTargetInterface, idbFactory: IDBFactory) { + constructor(target: QueryTargetInterface, idbFactory: IDBFactory, _IDBKeyRange: typeof IDBKeyRange) { this._target = target; this._idbFactory = idbFactory; + this._IDBKeyRange = _IDBKeyRange; } _openCursor(range?: IDBQuery, direction?: IDBCursorDirection): IDBRequest { @@ -161,7 +163,7 @@ export class QueryTarget { const sortedKeys = keys.slice().sort(compareKeys); const firstKey = backwards ? sortedKeys[sortedKeys.length - 1] : sortedKeys[0]; const lastKey = backwards ? sortedKeys[0] : sortedKeys[sortedKeys.length - 1]; - const cursor = this._target.openKeyCursor(IDBKeyRange.bound(firstKey, lastKey), direction); + const cursor = this._target.openKeyCursor(this._IDBKeyRange.bound(firstKey, lastKey), direction); let i = 0; let consumerDone = false; await iterateCursor(cursor, (value, key) => { diff --git a/src/matrix/storage/idb/Store.ts b/src/matrix/storage/idb/Store.ts index 6dafd90e..1093e73d 100644 --- a/src/matrix/storage/idb/Store.ts +++ b/src/matrix/storage/idb/Store.ts @@ -130,8 +130,8 @@ class QueryTargetWrapper { export class Store extends QueryTarget { private _transaction: Transaction; - constructor(idbStore: IDBObjectStore, transaction: Transaction, idbFactory: IDBFactory) { - super(new QueryTargetWrapper(idbStore), idbFactory); + constructor(idbStore: IDBObjectStore, transaction: Transaction) { + super(new QueryTargetWrapper(idbStore), transaction.idbFactory, transaction.IDBKeyRange); this._transaction = transaction; } @@ -145,7 +145,7 @@ export class Store extends QueryTarget { } index(indexName: string): QueryTarget { - return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName)), this._idbFactory); + return new QueryTarget(new QueryTargetWrapper(this._idbStore.index(indexName)), this._idbFactory, this._IDBKeyRange); } put(value: T): void { diff --git a/src/matrix/storage/idb/Transaction.ts b/src/matrix/storage/idb/Transaction.ts index 1eaf0caf..d0a8748f 100644 --- a/src/matrix/storage/idb/Transaction.ts +++ b/src/matrix/storage/idb/Transaction.ts @@ -56,7 +56,7 @@ export class Transaction { // more specific error? this is a bug, so maybe not ... throw new StorageError(`Invalid store for transaction: ${name}, only ${this._allowedStoreNames.join(", ")} are allowed.`); } - return new Store(this._txn.objectStore(name), this, this.idbFactory); + return new Store(this._txn.objectStore(name), this); } _store(name: StoreNames, mapStore: (idbStore: Store) => T): T {