From 287242deda07e69c29f10db1da19c522e08c67e6 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 12 Aug 2021 13:10:13 -0700 Subject: [PATCH] Add type annotations to Storage --- src/matrix/storage/idb/Storage.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/matrix/storage/idb/Storage.ts b/src/matrix/storage/idb/Storage.ts index ad155a17..ceab34f9 100644 --- a/src/matrix/storage/idb/Storage.ts +++ b/src/matrix/storage/idb/Storage.ts @@ -21,8 +21,13 @@ import { reqAsPromise } from "./utils"; const WEBKITEARLYCLOSETXNBUG_BOGUS_KEY = "782rh281re38-boguskey"; export class Storage { - constructor(idbDatabase, IDBKeyRange, hasWebkitEarlyCloseTxnBug) { + private _db: IDBDatabase + private _hasWebkitEarlyCloseTxnBug: boolean + storeNames: { [ name : string] : string } + + constructor(idbDatabase: IDBDatabase, IDBKeyRange, hasWebkitEarlyCloseTxnBug: boolean) { this._db = idbDatabase; + // @ts-ignore this._IDBKeyRange = IDBKeyRange; this._hasWebkitEarlyCloseTxnBug = hasWebkitEarlyCloseTxnBug; const nameMap = STORE_NAMES.reduce((nameMap, name) => { @@ -32,14 +37,14 @@ export class Storage { this.storeNames = Object.freeze(nameMap); } - _validateStoreNames(storeNames) { + _validateStoreNames(storeNames: string[]) { const idx = storeNames.findIndex(name => !STORE_NAMES.includes(name)); if (idx !== -1) { throw new StorageError(`Tried top, a transaction unknown store ${storeNames[idx]}`); } } - async readTxn(storeNames) { + async readTxn(storeNames: string[]): Promise { this._validateStoreNames(storeNames); try { const txn = this._db.transaction(storeNames, "readonly"); @@ -48,13 +53,14 @@ export class Storage { if (this._hasWebkitEarlyCloseTxnBug) { await reqAsPromise(txn.objectStore(storeNames[0]).get(WEBKITEARLYCLOSETXNBUG_BOGUS_KEY)); } + // @ts-ignore return new Transaction(txn, storeNames, this._IDBKeyRange); } catch(err) { throw new StorageError("readTxn failed", err); } } - async readWriteTxn(storeNames) { + async readWriteTxn(storeNames: string[]): Promise { this._validateStoreNames(storeNames); try { const txn = this._db.transaction(storeNames, "readwrite"); @@ -63,6 +69,7 @@ export class Storage { if (this._hasWebkitEarlyCloseTxnBug) { await reqAsPromise(txn.objectStore(storeNames[0]).get(WEBKITEARLYCLOSETXNBUG_BOGUS_KEY)); } + // @ts-ignore return new Transaction(txn, storeNames, this._IDBKeyRange); } catch(err) { throw new StorageError("readWriteTxn failed", err);