do not ignore database version

This commit is contained in:
Florian Dold 2019-08-16 23:06:51 +02:00
parent 8f180594fe
commit 6a57ad5fe2
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 11 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{
"name": "idb-bridge",
"version": "0.0.4",
"version": "0.0.5",
"description": "IndexedDB implementation that uses SQLite3 as storage",
"main": "./build/index.js",
"types": "./build/index.d.ts",

View File

@ -312,7 +312,7 @@ test("export", async t => {
const backend = new MemoryBackend();
const idb = new BridgeIDBFactory(backend);
const request = idb.open("library");
const request = idb.open("library", 42);
request.onupgradeneeded = () => {
const db = request.result;
const store = db.createObjectStore("books", { keyPath: "isbn" });
@ -344,5 +344,6 @@ test("export", async t => {
t.assert(exportedData.databases["library"].objectStores["books"].records.length === 3);
t.deepEqual(exportedData, exportedData2);
t.is(exportedData.databases["library"].schema.databaseVersion, 42);
t.pass();
});

View File

@ -107,7 +107,7 @@ interface MemoryBackendDump {
interface Connection {
dbName: string;
modifiedSchema: Schema | undefined;
modifiedSchema: Schema;
/**
* Has the underlying database been deleted?
@ -491,6 +491,8 @@ export class MemoryBackend implements Backend {
this.connectionsByTransaction[transactionCookie] = myConn;
myConn.modifiedSchema.databaseVersion = newVersion;
return { transactionCookie };
}
@ -525,10 +527,7 @@ export class MemoryBackend implements Backend {
if (!db) {
throw Error("db not found");
}
if (myConn.modifiedSchema) {
return myConn.modifiedSchema;
}
return db.committedSchema;
return myConn.modifiedSchema;
}
renameIndex(
@ -827,9 +826,7 @@ export class MemoryBackend implements Backend {
);
}
const schema = myConn.modifiedSchema
? myConn.modifiedSchema
: db.committedSchema;
const schema = myConn.modifiedSchema;
const objectStore = myConn.objectStoreMap[objectStoreName];
if (!objectStore.modifiedData) {
@ -1264,9 +1261,7 @@ export class MemoryBackend implements Backend {
if (db.txLevel < TransactionLevel.Write) {
throw Error("only allowed while running a transaction");
}
const schema = myConn.modifiedSchema
? myConn.modifiedSchema
: db.committedSchema;
const schema = myConn.modifiedSchema;
const objectStore = myConn.objectStoreMap[storeReq.objectStoreName];
if (!objectStore.modifiedData) {
@ -1421,7 +1416,7 @@ export class MemoryBackend implements Backend {
throw Error("only allowed while running a transaction");
}
db.committedSchema = myConn.modifiedSchema || db.committedSchema;
db.committedSchema = structuredClone(myConn.modifiedSchema);
db.txLevel = TransactionLevel.Connected;
db.committedIndexes = {};

View File

@ -10,6 +10,7 @@
"strict": true,
"incremental": true,
"sourceMap": true,
"typeRoots": ["./node_modules"],
"types": []
},
"include": ["src/**/*"]