forked from mystiq/hydrogen-web
Make export types more precise
This commit is contained in:
parent
2262e6be30
commit
78fb8fdadf
2 changed files with 9 additions and 7 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import {Storage} from "./Storage";
|
||||
import { openDatabase, reqAsPromise } from "./utils";
|
||||
import { exportSession, importSession } from "./export";
|
||||
import { exportSession, importSession, Export } from "./export";
|
||||
import { schema } from "./schema";
|
||||
import { detectWebkitEarlyCloseTxnBug } from "./quirks";
|
||||
|
||||
|
@ -80,12 +80,12 @@ export class StorageFactory {
|
|||
return reqAsPromise(req);
|
||||
}
|
||||
|
||||
async export(sessionId: string): Promise<{ [storeName: string]: any }> {
|
||||
async export(sessionId: string): Promise<Export> {
|
||||
const db = await openDatabaseWithSessionId(sessionId, this._idbFactory);
|
||||
return await exportSession(db);
|
||||
}
|
||||
|
||||
async import(sessionId: string, data: { [storeName: string]: any }): Promise<void> {
|
||||
async import(sessionId: string, data: Export): Promise<void> {
|
||||
const db = await openDatabaseWithSessionId(sessionId, this._idbFactory);
|
||||
return await importSession(db, data);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { iterateCursor, NOT_DONE, txnAsPromise } from "./utils";
|
||||
import { STORE_NAMES } from "../common";
|
||||
import { STORE_NAMES, StoreNames } from "../common";
|
||||
|
||||
export async function exportSession(db: IDBDatabase): Promise<{ [storeName : string] : any }> {
|
||||
export type Export = { [storeName in StoreNames] : any[] }
|
||||
|
||||
export async function exportSession(db: IDBDatabase): Promise<Export> {
|
||||
const txn = db.transaction(STORE_NAMES, "readonly");
|
||||
const data = {};
|
||||
await Promise.all(STORE_NAMES.map(async name => {
|
||||
|
@ -28,10 +30,10 @@ export async function exportSession(db: IDBDatabase): Promise<{ [storeName : str
|
|||
return NOT_DONE;
|
||||
});
|
||||
}));
|
||||
return data;
|
||||
return data as Export;
|
||||
}
|
||||
|
||||
export async function importSession(db: IDBDatabase, data: { [storeName: string]: any }): Promise<void> {
|
||||
export async function importSession(db: IDBDatabase, data: Export): Promise<void> {
|
||||
const txn = db.transaction(STORE_NAMES, "readwrite");
|
||||
for (const name of STORE_NAMES) {
|
||||
const store = txn.objectStore(name);
|
||||
|
|
Loading…
Reference in a new issue