update secret-stack to 8.1

This commit is contained in:
Andre Staltz 2024-01-08 11:29:02 +02:00
parent 41dcb8a374
commit aee242981f
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
3 changed files with 4 additions and 32 deletions

View File

@ -48,30 +48,6 @@ const Obz = require('obz')
* } PurposeWithDetails * } 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} * @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 * @param {unknown} config
*/ */
function initGoals(peer, config) { function initGoals(peer, config) {
assertDBPlugin(peer)
// Constants: // Constants:
const EMPTY_RANGE = /** @type {Range} */ ([1, 0]) const EMPTY_RANGE = /** @type {Range} */ ([1, 0])
@ -170,12 +145,10 @@ function initGoals(peer, config) {
return [0, maxDepth] return [0, maxDepth]
case 'set': case 'set':
assertSetPlugin(peer)
const minSetDepth = peer.set.minRequiredDepth(goal.id) const minSetDepth = peer.set.minRequiredDepth(goal.id)
return [minSetDepth, maxDepth] return [minSetDepth, maxDepth]
case 'dict': case 'dict':
assertDictPlugin(peer)
const minDictDepth = peer.dict.minRequiredDepth(goal.id) const minDictDepth = peer.dict.minRequiredDepth(goal.id)
return [minDictDepth, maxDepth] return [minDictDepth, maxDepth]
@ -245,7 +218,6 @@ function initGoals(peer, config) {
* @returns {PurposeWithDetails} * @returns {PurposeWithDetails}
*/ */
function getMsgPurpose(msgID, msg) { function getMsgPurpose(msgID, msg) {
assertDBPlugin(peer)
let servesAsTrail = false let servesAsTrail = false
// Check whether this msg is a goalful root of some tangle: // 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: // Check whether this msg is a ghost affix of some tangle:
for (const [tangle, , , , goalType] of validTangles) { for (const [tangle, , , , goalType] of validTangles) {
if (goalType === 'dict') { if (goalType === 'dict') {
assertDictPlugin(peer)
const span = peer.dict.getGhostSpan() const span = peer.dict.getGhostSpan()
if (peer.dict.isGhostable(msgID, tangle.id)) { if (peer.dict.isGhostable(msgID, tangle.id)) {
return ['ghost', { tangleID: tangle.id, span }] return ['ghost', { tangleID: tangle.id, span }]
} }
} }
if (goalType === 'set') { if (goalType === 'set') {
assertSetPlugin(peer)
const span = peer.set.getGhostSpan() const span = peer.set.getGhostSpan()
if (peer.set.isGhostable(msgID, tangle.id)) { if (peer.set.isGhostable(msgID, tangle.id)) {
return ['ghost', { tangleID: tangle.id, span }] return ['ghost', { tangleID: tangle.id, span }]
@ -333,4 +303,5 @@ function initGoals(peer, config) {
} }
exports.name = 'goals' exports.name = 'goals'
exports.needs = ['db', 'dict', 'set']
exports.init = initGoals exports.init = initGoals

View File

@ -40,7 +40,7 @@
"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",
"secret-stack": "~8.0.0", "secret-stack": "~8.1.0",
"secret-handshake-ext": "0.0.10", "secret-handshake-ext": "0.0.10",
"ssb-box": "^1.0.1", "ssb-box": "^1.0.1",
"typescript": "^5.1.3" "typescript": "^5.1.3"

View File

@ -29,6 +29,7 @@ function createPeer(config) {
.use(require('secret-handshake-ext/secret-stack')) .use(require('secret-handshake-ext/secret-stack'))
.use(require('ppppp-db')) .use(require('ppppp-db'))
.use(require('ppppp-dict')) .use(require('ppppp-dict'))
.use(require('ppppp-set'))
.use(require('ssb-box')) .use(require('ssb-box'))
.use(require('../lib')) .use(require('../lib'))
.call(null, { .call(null, {