diff --git a/src/matrix/storage/idb/Storage.js b/src/matrix/storage/idb/Storage.ts similarity index 83% rename from src/matrix/storage/idb/Storage.js rename to src/matrix/storage/idb/Storage.ts index d04183b6..747a9e16 100644 --- a/src/matrix/storage/idb/Storage.js +++ b/src/matrix/storage/idb/Storage.ts @@ -21,21 +21,26 @@ import { reqAsPromise } from "./utils"; const WEBKITEARLYCLOSETXNBUG_BOGUS_KEY = "782rh281re38-boguskey"; export class Storage { - constructor(idbDatabase, IDBKeyRange, hasWebkitEarlyCloseTxnBug) { + private _db: IDBDatabase; + private _hasWebkitEarlyCloseTxnBug: boolean; + storeNames: typeof StoreNames; + + constructor(idbDatabase: IDBDatabase, IDBKeyRange, hasWebkitEarlyCloseTxnBug: boolean) { this._db = idbDatabase; + // @ts-ignore this._IDBKeyRange = IDBKeyRange; this._hasWebkitEarlyCloseTxnBug = hasWebkitEarlyCloseTxnBug; this.storeNames = StoreNames; } - _validateStoreNames(storeNames) { + _validateStoreNames(storeNames: StoreNames[]): void { 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: StoreNames[]): Promise { this._validateStoreNames(storeNames); try { const txn = this._db.transaction(storeNames, "readonly"); @@ -44,13 +49,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: StoreNames[]): Promise { this._validateStoreNames(storeNames); try { const txn = this._db.transaction(storeNames, "readwrite"); @@ -59,13 +65,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("readWriteTxn failed", err); } } - close() { + close(): void { this._db.close(); } } diff --git a/src/matrix/storage/idb/StorageFactory.js b/src/matrix/storage/idb/StorageFactory.js index a9dc8eed..84b699eb 100644 --- a/src/matrix/storage/idb/StorageFactory.js +++ b/src/matrix/storage/idb/StorageFactory.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {Storage} from "./Storage.js"; +import {Storage} from "./Storage"; import { openDatabase, reqAsPromise } from "./utils"; import { exportSession, importSession } from "./export.js"; import { schema } from "./schema.js";