export type Goal

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

View File

@ -6,9 +6,10 @@ const Obz = require('obz')
* @typedef {import('ppppp-db').Tangle} Tangle
* @typedef {'none'|'all'|`newest-${number}`|`oldest-${number}`|'record'|'set'} GoalDSL
* @typedef {[number, number]} Range
* @typedef {Goal_} Goal
*/
class Goal {
class Goal_ {
/** @type {string} */
#id
@ -96,12 +97,12 @@ module.exports = {
const EMPTY_RANGE = /** @type {Range} */ ([1, 0])
// State:
const goals = /** @type {Map<string, Goal>} */ (new Map())
const goals = /** @type {Map<string, Goal_>} */ (new Map())
const listen = Obz()
/**
* @private
* @param {Goal} goal
* @param {Goal_} goal
* @param {Tangle} tangle
* @returns {Range}
*/
@ -130,7 +131,7 @@ module.exports = {
* @returns {void}
*/
function set(tangleID, goalDSL) {
const goal = new Goal(tangleID, goalDSL)
const goal = new Goal_(tangleID, goalDSL)
goals.set(tangleID, goal)
listen.set(goal)
}
@ -138,7 +139,7 @@ module.exports = {
/**
* @public
* @param {string} msgID
* @returns {Goal | null}
* @returns {Goal_ | null}
*/
function getByID(msgID) {
return goals.get(msgID) ?? null
@ -147,18 +148,18 @@ module.exports = {
/**
* @public
* @param {RecPresent} rec
* @returns {Array<Goal>}
* @returns {Array<Goal_>}
*/
function getByRec(rec) {
const arr = []
if (goals.has(rec.id)) {
const goal = /** @type {Goal} */ (goals.get(rec.id))
const goal = /** @type {Goal_} */ (goals.get(rec.id))
arr.push(goal)
}
if (rec.msg) {
for (const tangleID in rec.msg.metadata.tangles) {
if (goals.has(tangleID)) {
const goal = /** @type {Goal} */ (goals.get(tangleID))
const goal = /** @type {Goal_} */ (goals.get(tangleID))
const tangle = peer.db.getTangle(tangleID)
if (tangle) {
const [min, max] = crossGoalWithTangle(goal, tangle)
@ -173,7 +174,7 @@ module.exports = {
/**
* @public
* @returns {IterableIterator<Goal>}
* @returns {IterableIterator<Goal_>}
*/
function list() {
return goals.values()