diff --git a/src/matrix/storage/idb/QueryTarget.ts b/src/matrix/storage/idb/QueryTarget.ts index 88304db2..ed05198e 100644 --- a/src/matrix/storage/idb/QueryTarget.ts +++ b/src/matrix/storage/idb/QueryTarget.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {iterateCursor, reqAsPromise} from "./utils"; +import {iterateCursor, DONE, NOT_DONE, reqAsPromise} from "./utils"; type Reducer = (acc: B, val: A) => B @@ -101,7 +101,7 @@ export class QueryTarget { const results: T[] = []; await iterateCursor(cursor, (value) => { results.push(value); - return {done: false}; + return NOT_DONE; }); return results; } @@ -127,7 +127,7 @@ export class QueryTarget { let maxKey: IDBValidKey | undefined; await iterateCursor(cursor, (_, key) => { maxKey = key; - return {done: true}; + return DONE; }); return maxKey; } @@ -191,7 +191,7 @@ export class QueryTarget { const cursor = this._openCursor(range, direction); return iterateCursor(cursor, (value) => { reducedValue = reducer(reducedValue, value); - return {done: false}; + return NOT_DONE; }); } diff --git a/src/matrix/storage/idb/export.ts b/src/matrix/storage/idb/export.ts index 28267ad4..c2880f3d 100644 --- a/src/matrix/storage/idb/export.ts +++ b/src/matrix/storage/idb/export.ts @@ -14,11 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { iterateCursor, txnAsPromise } from "./utils"; +import { iterateCursor, NOT_DONE, txnAsPromise } from "./utils"; import { STORE_NAMES } from "../common"; export async function exportSession(db: IDBDatabase): Promise<{ [storeName : string] : any }> { - const NOT_DONE = {done: false}; const txn = db.transaction(STORE_NAMES, "readonly"); const data = {}; await Promise.all(STORE_NAMES.map(async name => { diff --git a/src/matrix/storage/idb/schema.ts b/src/matrix/storage/idb/schema.ts index e94b0a76..2ff85747 100644 --- a/src/matrix/storage/idb/schema.ts +++ b/src/matrix/storage/idb/schema.ts @@ -1,4 +1,4 @@ -import {iterateCursor, reqAsPromise} from "./utils"; +import {iterateCursor, NOT_DONE, reqAsPromise} from "./utils"; import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../room/members/RoomMember.js"; import {RoomMemberStore} from "./stores/RoomMemberStore"; import {RoomStateEntry} from "./stores/RoomStateStore"; @@ -21,8 +21,6 @@ export const schema = [ ]; // TODO: how to deal with git merge conflicts of this array? -const NOT_DONE = {done:false}; - // TypeScript note: for now, do not bother introducing interfaces / alias // for old schemas. Just take them as `any`. diff --git a/src/matrix/storage/idb/utils.ts b/src/matrix/storage/idb/utils.ts index 6c43f94e..d96f7386 100644 --- a/src/matrix/storage/idb/utils.ts +++ b/src/matrix/storage/idb/utils.ts @@ -18,6 +18,9 @@ limitations under the License. import { IDBRequestError } from "./error"; import { StorageError } from "../common"; +export const NOT_DONE = { done: false }; +export const DONE = { done: true }; + let needsSyncPromise = false; /* should be called on legacy platforms to see