mirror of https://codeberg.org/pzp/pzp-goals.git
correct calculation of ppppp-record purpose range
This commit is contained in:
parent
4e855f4f59
commit
1b32169541
16
lib/index.js
16
lib/index.js
|
@ -3,6 +3,7 @@ const Obz = require('obz')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||||
|
* @typedef {ReturnType<import('ppppp-record').init>} PPPPPRecord
|
||||||
* @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 {ReturnType<PPPPPDB['getTangle']>} DBTangle
|
* @typedef {ReturnType<PPPPPDB['getTangle']>} DBTangle
|
||||||
|
@ -33,6 +34,14 @@ function assertDBExists(peer) {
|
||||||
if (!peer.db) throw new Error('goals plugin requires ppppp-db plugin')
|
if (!peer.db) throw new Error('goals plugin requires ppppp-db plugin')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{ record: PPPPPRecord | null }} peer
|
||||||
|
* @returns {asserts peer is { record: PPPPPRecord }}
|
||||||
|
*/
|
||||||
|
function assertRecordExists(peer) {
|
||||||
|
if (!peer.record) throw new Error('goals plugin requires ppppp-record plugin')
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @implements {Goal}
|
* @implements {Goal}
|
||||||
*/
|
*/
|
||||||
|
@ -102,7 +111,7 @@ class GoalImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ db: PPPPPDB | null }} peer
|
* @param {{ db: PPPPPDB | null, record: PPPPPRecord | null }} peer
|
||||||
* @param {unknown} config
|
* @param {unknown} config
|
||||||
*/
|
*/
|
||||||
function initGoals(peer, config) {
|
function initGoals(peer, config) {
|
||||||
|
@ -127,8 +136,11 @@ function initGoals(peer, config) {
|
||||||
return EMPTY_RANGE
|
return EMPTY_RANGE
|
||||||
case 'all':
|
case 'all':
|
||||||
case 'set':
|
case 'set':
|
||||||
case 'record':
|
|
||||||
return [0, maxDepth]
|
return [0, maxDepth]
|
||||||
|
case 'record':
|
||||||
|
assertRecordExists(peer)
|
||||||
|
const minDepth = peer.record.getMinRequiredDepth(goal.id)
|
||||||
|
return [minDepth, maxDepth]
|
||||||
case 'newest':
|
case 'newest':
|
||||||
const start = Math.max(0, maxDepth - goal.count + 1)
|
const start = Math.max(0, maxDepth - goal.count + 1)
|
||||||
return [start, maxDepth]
|
return [start, maxDepth]
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
"ppppp-db": "github:staltz/ppppp-db",
|
"ppppp-db": "github:staltz/ppppp-db",
|
||||||
"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-record": "github:staltz/ppppp-record",
|
||||||
"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",
|
||||||
|
|
Loading…
Reference in New Issue