diff --git a/lib/index.js b/lib/index.js index 6a06bae..cb256dc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,30 +48,6 @@ const Obz = require('obz') * } PurposeWithDetails */ -/** - * @param {{ db: PPPPPDB | null }} peer - * @returns {asserts peer is { db: PPPPPDB }} - */ -function assertDBPlugin(peer) { - if (!peer.db) throw new Error('"goals" plugin requires "db" plugin') -} - -/** - * @param {{ dict: PPPPPDict | null }} peer - * @returns {asserts peer is { dict: PPPPPDict }} - */ -function assertDictPlugin(peer) { - if (!peer.dict) throw new Error('"goals" plugin requires "dict" plugin') -} - -/** - * @param {{ set: PPPPPSet | null }} peer - * @returns {asserts peer is { set: PPPPPSet }} - */ -function assertSetPlugin(peer) { - if (!peer.set) throw new Error('"goals" plugin requires "set" plugin') -} - /** * @implements {Goal} */ @@ -141,11 +117,10 @@ class GoalImpl { } /** - * @param {{ db: PPPPPDB | null, dict: PPPPPDict | null, set: PPPPPSet | null }} peer + * @param {{ db: PPPPPDB, dict: PPPPPDict, set: PPPPPSet }} peer * @param {unknown} config */ function initGoals(peer, config) { - assertDBPlugin(peer) // Constants: const EMPTY_RANGE = /** @type {Range} */ ([1, 0]) @@ -170,12 +145,10 @@ function initGoals(peer, config) { return [0, maxDepth] case 'set': - assertSetPlugin(peer) const minSetDepth = peer.set.minRequiredDepth(goal.id) return [minSetDepth, maxDepth] case 'dict': - assertDictPlugin(peer) const minDictDepth = peer.dict.minRequiredDepth(goal.id) return [minDictDepth, maxDepth] @@ -245,7 +218,6 @@ function initGoals(peer, config) { * @returns {PurposeWithDetails} */ function getMsgPurpose(msgID, msg) { - assertDBPlugin(peer) let servesAsTrail = false // Check whether this msg is a goalful root of some tangle: @@ -295,14 +267,12 @@ function initGoals(peer, config) { // Check whether this msg is a ghost affix of some tangle: for (const [tangle, , , , goalType] of validTangles) { if (goalType === 'dict') { - assertDictPlugin(peer) const span = peer.dict.getGhostSpan() if (peer.dict.isGhostable(msgID, tangle.id)) { return ['ghost', { tangleID: tangle.id, span }] } } if (goalType === 'set') { - assertSetPlugin(peer) const span = peer.set.getGhostSpan() if (peer.set.isGhostable(msgID, tangle.id)) { return ['ghost', { tangleID: tangle.id, span }] @@ -333,4 +303,5 @@ function initGoals(peer, config) { } exports.name = 'goals' +exports.needs = ['db', 'dict', 'set'] exports.init = initGoals diff --git a/package.json b/package.json index 31987b9..a658556 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "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/test/util.js b/test/util.js index c3cfac6..a6ca52a 100644 --- a/test/util.js +++ b/test/util.js @@ -29,6 +29,7 @@ function createPeer(config) { .use(require('secret-handshake-ext/secret-stack')) .use(require('ppppp-db')) .use(require('ppppp-dict')) + .use(require('ppppp-set')) .use(require('ssb-box')) .use(require('../lib')) .call(null, {