diff --git a/lib/index.js b/lib/index.js index 7248b45..27b1427 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,6 +4,7 @@ const Obz = require('obz') /** * @typedef {ReturnType} PPPPPDB * @typedef {ReturnType} PPPPPDict + * @typedef {ReturnType} PPPPPSet * @typedef {import('ppppp-db').RecPresent} RecPresent * @typedef {import('ppppp-db').Tangle} Tangle * @typedef {import('ppppp-db').Msg} Msg @@ -63,6 +64,14 @@ function assertDictPlugin(peer) { if (!peer.dict) throw new Error('goals plugin requires ppppp-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 ppppp-set plugin') +} + /** * @implements {Goal} */ @@ -132,7 +141,7 @@ class GoalImpl { } /** - * @param {{ db: PPPPPDB | null, dict: PPPPPDict | null }} peer + * @param {{ db: PPPPPDB | null, dict: PPPPPDict | null, set: PPPPPSet | null }} peer * @param {unknown} config */ function initGoals(peer, config) { @@ -158,13 +167,17 @@ function initGoals(peer, config) { return [start, maxDepth] case 'all': - case 'set': return [0, maxDepth] + case 'set': + assertSetPlugin(peer) + const minSetDepth = peer.set.minRequiredDepth(goal.id) + return [minSetDepth, maxDepth] + case 'dict': assertDictPlugin(peer) - const minDepth = peer.dict.minRequiredDepth(goal.id) - return [minDepth, maxDepth] + const minDictDepth = peer.dict.minRequiredDepth(goal.id) + return [minDictDepth, maxDepth] case 'none': return EMPTY_RANGE @@ -258,6 +271,13 @@ function initGoals(peer, config) { 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 }] + } + } } return ['none'] diff --git a/package.json b/package.json index e50dbea..eb8541a 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "ppppp-dict": "github:staltz/ppppp-dict", "ppppp-caps": "github:staltz/ppppp-caps", "ppppp-keypair": "github:staltz/ppppp-keypair", + "ppppp-set": "github:staltz/ppppp-set", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0",