From a8728506d626ea0fcc1e9fab2a46a3bb7a121dcb Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 14 Sep 2023 14:14:28 +0300 Subject: [PATCH] add Set and Record as goal types --- lib/index.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4652fc2..b2235f4 100644 --- a/lib/index.js +++ b/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)