diff --git a/src/database.ts b/src/database.ts index 6181812f..88871628 100644 --- a/src/database.ts +++ b/src/database.ts @@ -64,7 +64,7 @@ export class Database
> implements Con name, meta: opts?.meta, factoryUnreg: () => { - databases.unreg(key); + // databases.unreg(key); }, keyBag: defaultKeyBagOpts(sthis, opts?.keyBag), storeUrls: toStoreURIRuntime(sthis, name, opts?.storeUrls), diff --git a/tests/fireproof/crdt.test.ts b/tests/fireproof/crdt.test.ts index 2400ae57..73d9a46c 100644 --- a/tests/fireproof/crdt.test.ts +++ b/tests/fireproof/crdt.test.ts @@ -16,10 +16,13 @@ describe("Fresh crdt", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); }); it("should have an empty head", async function () { @@ -59,10 +62,13 @@ describe("CRDT with one record", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, `test@${sthis.nextId()}`), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); firstPut = await crdt.bulk([{ id: "hello", value: { hello: "world" } }]); }); @@ -115,10 +121,13 @@ describe("CRDT with a multi-write", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); firstPut = await crdt.bulk([ { id: "ace", value: { points: 11 } }, @@ -186,10 +195,13 @@ describe("CRDT with two multi-writes", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, `test-multiple-writes@${sthis.nextId()}`), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); firstPut = await crdt.bulk([ { id: "ace", value: { points: 11 } }, @@ -240,10 +252,13 @@ describe("Compact a named CRDT with writes", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, `named-crdt-compaction`), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); for (let i = 0; i < 10; i++) { const bulk = [ @@ -301,11 +316,14 @@ describe("CRDT with an index", function () { beforeEach(async function () { await sthis.start(); const dbOpts: DatabaseOpts = { - // meta: opts?.meta, + // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), - storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"), + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); await crdt.bulk([ { id: "ace", value: { points: 11 } }, @@ -355,9 +373,12 @@ describe("Loader with a committed transaction", function () { const dbOpts: DatabaseOpts = { keyBag: defaultKeyBagOpts(sthis), // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, storeUrls: toStoreURIRuntime(sthis, dbname), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); blockstore = crdt.blockstore as bs.EncryptedBlockstore; expect(blockstore.loader).toBeTruthy(); @@ -408,10 +429,13 @@ describe("Loader with two committed transactions", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, "test-loader"), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); blockstore = crdt.blockstore as bs.EncryptedBlockstore; expect(blockstore.loader).toBeTruthy(); @@ -464,10 +488,13 @@ describe("Loader with many committed transactions", function () { await sthis.start(); const dbOpts: DatabaseOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, "test-loader-many"), - storeEnDe: bs.ensureStoreEnDeFile({}) - } + storeEnDe: bs.ensureStoreEnDeFile({}), + }; crdt = new CRDT(sthis, dbOpts); blockstore = crdt.blockstore as bs.EncryptedBlockstore; expect(blockstore.loader).toBeTruthy(); diff --git a/tests/fireproof/database.test.ts b/tests/fireproof/database.test.ts index 2fa261b0..98d8635d 100644 --- a/tests/fireproof/database.test.ts +++ b/tests/fireproof/database.test.ts @@ -51,7 +51,7 @@ describe("basic Database with record", function () { }); beforeEach(async function () { await sthis.start(); - db = Database.factory(); + db = Database.factory("factory-name"); const ok = await db.put({ _id: "hello", value: "world" }); expect(ok.id).toBe("hello"); }); @@ -83,7 +83,7 @@ describe("basic Database with record", function () { expect(rows[0].value._id).toBe("hello"); }); it("is not persisted", async function () { - const db2 = Database.factory(); + const db2 = Database.factory("factory-name"); const { rows } = await db2.changes([]); expect(rows.length).toBe(0); const doc = await db2.get("hello").catch((e) => e); @@ -312,7 +312,7 @@ describe("basic Database with subscription", function () { }); beforeEach(async function () { await sthis.start(); - db = Database.factory(); + db = Database.factory("factory-name"); didRun = 0; waitForSub = new Promise((resolve) => { unsubscribe = db.subscribe((docs) => { @@ -356,7 +356,7 @@ describe("basic Database with no update subscription", function () { }); beforeEach(async function () { await sthis.start(); - db = Database.factory(); + db = Database.factory("factory-name"); didRun = 0; unsubscribe = db.subscribe(() => { diff --git a/tests/fireproof/indexer.test.ts b/tests/fireproof/indexer.test.ts index b2ff310e..db126016 100644 --- a/tests/fireproof/indexer.test.ts +++ b/tests/fireproof/indexer.test.ts @@ -277,6 +277,9 @@ describe("basic Index upon cold start", function () { await sthis.start(); dbOpts = { // meta: opts?.meta, + factoryUnreg() { + return Promise.resolve(); + }, keyBag: rt.kb.defaultKeyBagOpts(sthis), storeUrls: toStoreURIRuntime(sthis, "test-indexer-cold"), storeEnDe: bs.ensureStoreEnDeFile({})