mirror of https://codeberg.org/pzp/pzp-goals.git
support Sets with ghosts
This commit is contained in:
parent
617a41330b
commit
c29447f694
28
lib/index.js
28
lib/index.js
|
@ -4,6 +4,7 @@ const Obz = require('obz')
|
|||
/**
|
||||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||
* @typedef {ReturnType<import('ppppp-dict').init>} PPPPPDict
|
||||
* @typedef {ReturnType<import('ppppp-set').init>} 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']
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue