support Sets with ghosts

This commit is contained in:
Andre Staltz 2023-10-26 17:34:22 +03:00
parent 617a41330b
commit c29447f694
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 25 additions and 4 deletions

View File

@ -4,6 +4,7 @@ const Obz = require('obz')
/** /**
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB * @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
* @typedef {ReturnType<import('ppppp-dict').init>} PPPPPDict * @typedef {ReturnType<import('ppppp-dict').init>} PPPPPDict
* @typedef {ReturnType<import('ppppp-set').init>} PPPPPSet
* @typedef {import('ppppp-db').RecPresent} RecPresent * @typedef {import('ppppp-db').RecPresent} RecPresent
* @typedef {import('ppppp-db').Tangle} Tangle * @typedef {import('ppppp-db').Tangle} Tangle
* @typedef {import('ppppp-db').Msg} Msg * @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') 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} * @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 * @param {unknown} config
*/ */
function initGoals(peer, config) { function initGoals(peer, config) {
@ -158,13 +167,17 @@ function initGoals(peer, config) {
return [start, maxDepth] return [start, maxDepth]
case 'all': case 'all':
case 'set':
return [0, maxDepth] return [0, maxDepth]
case 'set':
assertSetPlugin(peer)
const minSetDepth = peer.set.minRequiredDepth(goal.id)
return [minSetDepth, maxDepth]
case 'dict': case 'dict':
assertDictPlugin(peer) assertDictPlugin(peer)
const minDepth = peer.dict.minRequiredDepth(goal.id) const minDictDepth = peer.dict.minRequiredDepth(goal.id)
return [minDepth, maxDepth] return [minDictDepth, maxDepth]
case 'none': case 'none':
return EMPTY_RANGE return EMPTY_RANGE
@ -258,6 +271,13 @@ function initGoals(peer, config) {
return ['ghost', {tangleID: tangle.id, span }] 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'] return ['none']

View File

@ -36,6 +36,7 @@
"ppppp-dict": "github:staltz/ppppp-dict", "ppppp-dict": "github:staltz/ppppp-dict",
"ppppp-caps": "github:staltz/ppppp-caps", "ppppp-caps": "github:staltz/ppppp-caps",
"ppppp-keypair": "github:staltz/ppppp-keypair", "ppppp-keypair": "github:staltz/ppppp-keypair",
"ppppp-set": "github:staltz/ppppp-set",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^4.4.0", "rimraf": "^4.4.0",