From 5db9d1493aea79ee230a2e0bbe2966058ecf6cbe Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 12 Aug 2021 13:20:37 -0700 Subject: [PATCH] Migrate export to TypeScript --- src/matrix/storage/idb/StorageFactory.js | 2 +- src/matrix/storage/idb/{export.js => export.ts} | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) rename src/matrix/storage/idb/{export.js => export.ts} (73%) diff --git a/src/matrix/storage/idb/StorageFactory.js b/src/matrix/storage/idb/StorageFactory.js index 259c8c0f..fa5bbabc 100644 --- a/src/matrix/storage/idb/StorageFactory.js +++ b/src/matrix/storage/idb/StorageFactory.js @@ -16,7 +16,7 @@ limitations under the License. import {Storage} from "./Storage"; import { openDatabase, reqAsPromise } from "./utils"; -import { exportSession, importSession } from "./export.js"; +import { exportSession, importSession } from "./export"; import { schema } from "./schema"; import { detectWebkitEarlyCloseTxnBug } from "./quirks"; diff --git a/src/matrix/storage/idb/export.js b/src/matrix/storage/idb/export.ts similarity index 73% rename from src/matrix/storage/idb/export.js rename to src/matrix/storage/idb/export.ts index 27979ce0..c2880f3d 100644 --- a/src/matrix/storage/idb/export.js +++ b/src/matrix/storage/idb/export.ts @@ -14,17 +14,16 @@ 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) { - const NOT_DONE = {done: false}; +export async function exportSession(db: IDBDatabase): Promise<{ [storeName : string] : any }> { const txn = db.transaction(STORE_NAMES, "readonly"); const data = {}; await Promise.all(STORE_NAMES.map(async name => { - const results = data[name] = []; // initialize in deterministic order + const results: any[] = data[name] = []; // initialize in deterministic order const store = txn.objectStore(name); - await iterateCursor(store.openCursor(), (value) => { + await iterateCursor(store.openCursor(), (value) => { results.push(value); return NOT_DONE; }); @@ -32,7 +31,7 @@ export async function exportSession(db) { return data; } -export async function importSession(db, data) { +export async function importSession(db: IDBDatabase, data: { [storeName: string]: any }): Promise { const txn = db.transaction(STORE_NAMES, "readwrite"); for (const name of STORE_NAMES) { const store = txn.objectStore(name);