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