mirror of https://codeberg.org/pzp/pzp-goals.git
export type Goal
This commit is contained in:
parent
a8728506d6
commit
41fd9749a6
19
lib/index.js
19
lib/index.js
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue