mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Migrate export to TypeScript
This commit is contained in:
parent
04e39ef9e2
commit
5db9d1493a
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import {Storage} from "./Storage";
|
import {Storage} from "./Storage";
|
||||||
import { openDatabase, reqAsPromise } from "./utils";
|
import { openDatabase, reqAsPromise } from "./utils";
|
||||||
import { exportSession, importSession } from "./export.js";
|
import { exportSession, importSession } from "./export";
|
||||||
import { schema } from "./schema";
|
import { schema } from "./schema";
|
||||||
import { detectWebkitEarlyCloseTxnBug } from "./quirks";
|
import { detectWebkitEarlyCloseTxnBug } from "./quirks";
|
||||||
|
|
||||||
|
@ -14,17 +14,16 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { iterateCursor, txnAsPromise } from "./utils";
|
import { iterateCursor, NOT_DONE, txnAsPromise } from "./utils";
|
||||||
import { STORE_NAMES } from "../common";
|
import { STORE_NAMES } from "../common";
|
||||||
|
|
||||||
export async function exportSession(db) {
|
export async function exportSession(db: IDBDatabase): Promise<{ [storeName : string] : any }> {
|
||||||
const NOT_DONE = {done: false};
|
|
||||||
const txn = db.transaction(STORE_NAMES, "readonly");
|
const txn = db.transaction(STORE_NAMES, "readonly");
|
||||||
const data = {};
|
const data = {};
|
||||||
await Promise.all(STORE_NAMES.map(async name => {
|
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);
|
const store = txn.objectStore(name);
|
||||||
await iterateCursor(store.openCursor(), (value) => {
|
await iterateCursor<any>(store.openCursor(), (value) => {
|
||||||
results.push(value);
|
results.push(value);
|
||||||
return NOT_DONE;
|
return NOT_DONE;
|
||||||
});
|
});
|
||||||
@ -32,7 +31,7 @@ export async function exportSession(db) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importSession(db, data) {
|
export async function importSession(db: IDBDatabase, data: { [storeName: string]: any }): Promise<void> {
|
||||||
const txn = db.transaction(STORE_NAMES, "readwrite");
|
const txn = db.transaction(STORE_NAMES, "readwrite");
|
||||||
for (const name of STORE_NAMES) {
|
for (const name of STORE_NAMES) {
|
||||||
const store = txn.objectStore(name);
|
const store = txn.objectStore(name);
|
Loading…
Reference in New Issue
Block a user