mirror of https://codeberg.org/pzp/pzp-goals.git
add Set and Record as goal types
This commit is contained in:
parent
bd575b5f40
commit
a8728506d6
28
lib/index.js
28
lib/index.js
|
@ -2,15 +2,9 @@
|
|||
const Obz = require('obz')
|
||||
|
||||
/**
|
||||
* @typedef {import('ppppp-db/msg-v3').RecPresent} RecPresent
|
||||
* @typedef {import('ppppp-db').RecPresent} RecPresent
|
||||
* @typedef {import('ppppp-db').Tangle} Tangle
|
||||
*
|
||||
* @typedef {'none'} GoalNone
|
||||
* @typedef {'all'} GoalAll
|
||||
* @typedef {`newest-${number}`} GoalNewest
|
||||
* @typedef {`oldest-${number}`} GoalOldest
|
||||
* @typedef {GoalNone|GoalAll|GoalNewest|GoalOldest} GoalDSL
|
||||
*
|
||||
* @typedef {'none'|'all'|`newest-${number}`|`oldest-${number}`|'record'|'set'} GoalDSL
|
||||
* @typedef {[number, number]} Range
|
||||
*/
|
||||
|
||||
|
@ -18,7 +12,7 @@ class Goal {
|
|||
/** @type {string} */
|
||||
#id
|
||||
|
||||
/** @type {'none' | 'all' | 'newest' | 'oldest'} */
|
||||
/** @type {'none' | 'all' | 'set' | 'record' | 'newest' | 'oldest'} */
|
||||
#type
|
||||
|
||||
/** @type {number} */
|
||||
|
@ -33,7 +27,7 @@ class Goal {
|
|||
this.#id = tangleID
|
||||
|
||||
if (goalDSL === 'none') {
|
||||
this.#type = 'all'
|
||||
this.#type = 'none'
|
||||
this.#count = 0
|
||||
return
|
||||
}
|
||||
|
@ -44,6 +38,18 @@ class Goal {
|
|||
return
|
||||
}
|
||||
|
||||
if (goalDSL === 'set') {
|
||||
this.#type = 'set'
|
||||
this.#count = Infinity
|
||||
return
|
||||
}
|
||||
|
||||
if (goalDSL === 'record') {
|
||||
this.#type = 'record'
|
||||
this.#count = Infinity
|
||||
return
|
||||
}
|
||||
|
||||
const matchN = goalDSL.match(/^newest-(\d+)$/)
|
||||
if (matchN) {
|
||||
this.#type = 'newest'
|
||||
|
@ -105,6 +111,8 @@ module.exports = {
|
|||
case 'none':
|
||||
return EMPTY_RANGE
|
||||
case 'all':
|
||||
case 'set':
|
||||
case 'record':
|
||||
return [0, maxDepth]
|
||||
case 'newest':
|
||||
const start = Math.max(0, maxDepth - goal.count + 1)
|
||||
|
|
Loading…
Reference in New Issue