idb-bridge: fix bug in index deletion

This commit is contained in:
Florian Dold 2019-08-17 01:50:51 +02:00
parent d947b90df3
commit 9e3a26ca70
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -244,6 +244,9 @@ export class MemoryBackend implements Backend {
* been made.
*/
importDump(data: any) {
if (this.enableTracing) {
console.log("importing dump (a)");
}
if (this.transactionIdCounter != 1 || this.connectionIdCounter != 1) {
throw Error(
"data must be imported before first transaction or connection",
@ -326,6 +329,7 @@ export class MemoryBackend implements Backend {
* Only exports data that has been committed.
*/
exportDump(): MemoryBackendDump {
this.enableTracing && console.log("exporting dump");
const dbDumps: { [name: string]: DatabaseDump } = {};
for (const dbName of Object.keys(this.databases)) {
const db = this.databases[dbName];
@ -873,12 +877,12 @@ export class MemoryBackend implements Backend {
throw Error("assertion failed");
}
for (const indexName of Object.keys(schema.objectStores[objectStoreName].indexes)) {
const index = myConn.objectStoreMap[objectStoreName].indexMap[indexName];
if (!index) {
throw Error("index referenced by object store does not exist");
}
this.enableTracing && console.log(`deleting from index ${indexName} for object store ${objectStoreName}`);
const indexProperties = schema.objectStores[objectStoreName].indexes[indexName];
this.deleteFromIndex(
index,
@ -925,7 +929,7 @@ export class MemoryBackend implements Backend {
x => compareKeys(x, primaryKey) !== 0,
);
if (newPrimaryKeys.length === 0) {
index.originalData = indexData.without(indexKey);
index.modifiedData = indexData.without(indexKey);
} else {
const newIndexRecord = {
indexKey,