From 2b44878332c231648b27b8555f27e70475abe512 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 10 Aug 2021 14:11:26 -0700 Subject: [PATCH] Restrict type for iterateCursor --- src/matrix/storage/idb/QueryTarget.ts | 20 ++++++++++---------- src/matrix/storage/idb/utils.ts | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/matrix/storage/idb/QueryTarget.ts b/src/matrix/storage/idb/QueryTarget.ts index 27baf233..e02e28fc 100644 --- a/src/matrix/storage/idb/QueryTarget.ts +++ b/src/matrix/storage/idb/QueryTarget.ts @@ -18,19 +18,19 @@ import {iterateCursor, reqAsPromise} from "./utils"; type Reducer = (acc: B, val: A) => B -interface QueryTargetWrapper { - openCursor: (range?: IDBKeyRange | null , direction?: IDBCursorDirection) => IDBRequest - openKeyCursor: (range: IDBKeyRange, direction: IDBCursorDirection) => IDBRequest +interface QueryTargetInterface { + openCursor: (range?: IDBKeyRange | null , direction?: IDBCursorDirection) => IDBRequest + openKeyCursor: (range: IDBKeyRange, direction: IDBCursorDirection) => IDBRequest supports: (method: string) => boolean keyPath: string - get: (key: IDBValidKey) => IDBRequest - getKey: (key: IDBValidKey) => IDBRequest + get: (key: IDBValidKey) => IDBRequest + getKey: (key: IDBValidKey) => IDBRequest } export class QueryTarget { - private _target: QueryTargetWrapper + private _target: QueryTargetInterface - constructor(target: QueryTargetWrapper) { + constructor(target: QueryTargetInterface) { this._target = target; } @@ -50,7 +50,7 @@ export class QueryTarget { return this._target.supports(methodName); } - get(key: IDBValidKey): Promise { + get(key: IDBValidKey): Promise { return reqAsPromise(this._target.get(key)); } @@ -58,7 +58,7 @@ export class QueryTarget { if (this._target.supports("getKey")) { return reqAsPromise(this._target.getKey(key)); } else { - return reqAsPromise(this._target.get(key)).then(value => { + return reqAsPromise(this._target.get(key)).then(value => { if (value) { return value[this._target.keyPath]; } @@ -119,7 +119,7 @@ export class QueryTarget { async findMaxKey(range: IDBKeyRange): Promise { const cursor = this._target.openKeyCursor(range, "prev"); let maxKey; - await iterateCursor(cursor, (value, key) => { + await iterateCursor(cursor, (_, key) => { maxKey = key; return {done: true}; }); diff --git a/src/matrix/storage/idb/utils.ts b/src/matrix/storage/idb/utils.ts index 53f391e8..6c43f94e 100644 --- a/src/matrix/storage/idb/utils.ts +++ b/src/matrix/storage/idb/utils.ts @@ -128,7 +128,7 @@ type CursorIterator = I extends IDBCursorWithValue ? (value: T, key: IDBValidKey, cursor: IDBCursorWithValue) => { done: boolean, jumpTo?: IDBValidKey } : (value: undefined, key: IDBValidKey, cursor: IDBCursor) => { done: boolean, jumpTo?: IDBValidKey } -export function iterateCursor(cursorRequest: IDBRequest, processValue: CursorIterator): Promise { +export function iterateCursor(cursorRequest: IDBRequest, processValue: CursorIterator): Promise { // TODO: does cursor already have a value here?? return new Promise((resolve, reject) => { cursorRequest.onerror = () => {