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