From bcf7f4822dd03ab251f418d3556ab6ae61f64244 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Tue, 17 Dec 2024 16:38:52 -0800 Subject: [PATCH 1/2] Expose `dbPromise` in `StateStore` --- src/state-store.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/state-store.js b/src/state-store.js index 1b3482aedc..c443e3fbf3 100644 --- a/src/state-store.js +++ b/src/state-store.js @@ -44,6 +44,11 @@ module.exports = class StateStore { return this._getCorrectImplementation().then(i => i.count()); } + get dbPromise() { + // Exposed due to usage in [`project-plus`](https://web.pulsar-edit.dev/packages/project-plus) + return this._getCorrectImplementation().then(i => i.dbPromise()); + } + _getCorrectImplementation() { return awaitForAtomGlobal().then(() => { if(atom.config.get('core.useLegacySessionStore')) { From 4788055cc0b8e2408c0b2a8c6a362fd829d31d15 Mon Sep 17 00:00:00 2001 From: confused-Techie Date: Thu, 19 Dec 2024 20:20:35 -0800 Subject: [PATCH 2/2] Add specs --- spec/state-store-spec.js | 13 +++++++++++++ src/state-store.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/state-store-spec.js b/spec/state-store-spec.js index 89679a7b8d..7342bb7ea8 100644 --- a/spec/state-store-spec.js +++ b/spec/state-store-spec.js @@ -50,6 +50,12 @@ describe('StateStore', () => { }); }); + it('returns a database instance via dbPromise', async () => { + const store = new StateStore(databaseName, version); + const instance = await store.dbPromise; + expect(instance instanceof IDBDatabase).toBe(true); + }); + describe('when there is an error reading from the database', () => { it('rejects the promise returned by load', () => { const store = new StateStore(databaseName, version); @@ -119,5 +125,12 @@ describe('StateStore', () => { expect(count).toBe(0); }); }); + + it('returns a database instance via dbPromise', async () => { + const store = new StateStore(databaseName, version); + const instance = await store.dbPromise; + const Database = require("better-sqlite3"); + expect(instance instanceof Database).toBe(true); + }); }); }); diff --git a/src/state-store.js b/src/state-store.js index c443e3fbf3..adc4189021 100644 --- a/src/state-store.js +++ b/src/state-store.js @@ -46,7 +46,7 @@ module.exports = class StateStore { get dbPromise() { // Exposed due to usage in [`project-plus`](https://web.pulsar-edit.dev/packages/project-plus) - return this._getCorrectImplementation().then(i => i.dbPromise()); + return this._getCorrectImplementation().then(i => i.dbPromise); } _getCorrectImplementation() {