add Set and Record as goal types

This commit is contained in:
Andre Staltz 2023-09-14 14:14:28 +03:00
parent bd575b5f40
commit a8728506d6
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 18 additions and 10 deletions

View File

@ -2,15 +2,9 @@
const Obz = require('obz') 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 {import('ppppp-db').Tangle} Tangle
* * @typedef {'none'|'all'|`newest-${number}`|`oldest-${number}`|'record'|'set'} GoalDSL
* @typedef {'none'} GoalNone
* @typedef {'all'} GoalAll
* @typedef {`newest-${number}`} GoalNewest
* @typedef {`oldest-${number}`} GoalOldest
* @typedef {GoalNone|GoalAll|GoalNewest|GoalOldest} GoalDSL
*
* @typedef {[number, number]} Range * @typedef {[number, number]} Range
*/ */
@ -18,7 +12,7 @@ class Goal {
/** @type {string} */ /** @type {string} */
#id #id
/** @type {'none' | 'all' | 'newest' | 'oldest'} */ /** @type {'none' | 'all' | 'set' | 'record' | 'newest' | 'oldest'} */
#type #type
/** @type {number} */ /** @type {number} */
@ -33,7 +27,7 @@ class Goal {
this.#id = tangleID this.#id = tangleID
if (goalDSL === 'none') { if (goalDSL === 'none') {
this.#type = 'all' this.#type = 'none'
this.#count = 0 this.#count = 0
return return
} }
@ -44,6 +38,18 @@ class Goal {
return 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+)$/) const matchN = goalDSL.match(/^newest-(\d+)$/)
if (matchN) { if (matchN) {
this.#type = 'newest' this.#type = 'newest'
@ -105,6 +111,8 @@ module.exports = {
case 'none': case 'none':
return EMPTY_RANGE return EMPTY_RANGE
case 'all': case 'all':
case 'set':
case 'record':
return [0, maxDepth] return [0, maxDepth]
case 'newest': case 'newest':
const start = Math.max(0, maxDepth - goal.count + 1) const start = Math.max(0, maxDepth - goal.count + 1)