diff --git a/lib/index.js b/lib/index.js index 0722d27..79da91e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -63,17 +63,6 @@ function fromSubdomain(subdomain) { return PREFIX + subdomain } -/** - * @param {{ - * db: PPPPPDB | null, - * close: ClosableHook, - * }} peer - * @returns {asserts peer is { db: PPPPPDB, close: ClosableHook }} - */ -function assertDBPlugin(peer) { - if (!peer.db) throw new Error('"set" plugin requires "db" plugin') -} - /** * @param {unknown} check * @param {string} message @@ -84,12 +73,10 @@ function assert(check, message) { } /** - * @param {{ db: PPPPPDB | null, close: ClosableHook }} peer + * @param {{ db: PPPPPDB, close: ClosableHook }} peer * @param {Config} config */ function initSet(peer, config) { - assertDBPlugin(peer) - let ghostSpan = config.set?.ghostSpan ?? 32 if (ghostSpan < 1) throw new Error('config.set.ghostSpan must be >= 0') @@ -205,7 +192,6 @@ function initSet(peer, config) { * @param {string} subdomain */ function readSet(id, subdomain) { - assertDBPlugin(peer) const domain = fromSubdomain(subdomain) const mootID = MsgV4.getMootID(id, domain) const tangle = peer.db.getTangle(mootID) @@ -293,7 +279,6 @@ function initSet(peer, config) { * @param {string} subdomain */ function _squeezePotential(subdomain) { - assertDBPlugin(peer) // prettier-ignore if (!loadedAccountID) throw new Error('Cannot squeeze potential before loading') // TODO: improve this so that the squeezePotential is the size of the @@ -319,7 +304,6 @@ function initSet(peer, config) { * @param {CB} cb */ function load(accountID, cb) { - assertDBPlugin(peer) if (accountID === loadedAccountID) { loaded(cb) return @@ -360,7 +344,6 @@ function initSet(peer, config) { * @param {CB} cb */ function add(subdomain, value, cb) { - assertDBPlugin(peer) // TODO this error needs to be put into the `cb`, not thrown assert(!!loadedAccountID, 'Cannot add to Set before loading') // prettier-ignore @@ -411,7 +394,6 @@ function initSet(peer, config) { * @param {CB} cb */ function del(subdomain, value, cb) { - assertDBPlugin(peer) // TODO this error needs to be put into the `cb`, not thrown assert(!!loadedAccountID, 'Cannot add to Set before loading') // prettier-ignore @@ -483,7 +465,6 @@ function initSet(peer, config) { * @returns {number} */ function minRequiredDepth(tangleID) { - assertDBPlugin(peer) const tangle = peer.db.getTangle(tangleID) // prettier-ignore @@ -523,7 +504,6 @@ function initSet(peer, config) { */ function getFeedID(subdomain) { assert(!!loadedAccountID, 'Cannot getFeedID() before loading') - assertDBPlugin(peer) const domain = fromSubdomain(subdomain) return MsgV4.getMootID(loadedAccountID, domain) } @@ -536,7 +516,6 @@ function initSet(peer, config) { function isGhostable(ghostableMsgID, tangleID) { if (ghostableMsgID === tangleID) return false - assertDBPlugin(peer) const msg = peer.db.get(ghostableMsgID) // prettier-ignore @@ -578,7 +557,6 @@ function initSet(peer, config) { * @param {CB} cb */ function squeeze(subdomain, cb) { - assertDBPlugin(peer) // TODO this error needs to be put into the `cb`, not thrown assert(!!loadedAccountID, 'Cannot squeeze Set before loading') @@ -633,4 +611,5 @@ function initSet(peer, config) { } exports.name = 'set' +exports.needs = ['db'] exports.init = initSet diff --git a/package.json b/package.json index e8a6c0c..05c2f77 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "ppppp-caps": "github:staltz/ppppp-caps", "ppppp-keypair": "github:staltz/ppppp-keypair", "rimraf": "^4.4.0", - "secret-stack": "~8.0.0", + "secret-stack": "~8.1.0", "secret-handshake-ext": "0.0.10", "ssb-box": "^1.0.1", "typescript": "^5.1.3" diff --git a/tsconfig.json b/tsconfig.json index bd2acd5..cc6e7af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,6 @@ "module": "node16", "skipLibCheck": true, "strict": true, - "target": "es2021" + "target": "es2022" } } \ No newline at end of file