mirror of https://codeberg.org/pzp/pzp-db.git
rename some Tangle getters
This commit is contained in:
parent
c76584953b
commit
0b7f49846e
|
@ -702,7 +702,7 @@ function initDB(peer, config) {
|
|||
tangleTemplates.push(mootID)
|
||||
const tangles = populateTangles(tangleTemplates)
|
||||
const accountTangle = new DBTangle(opts.account, records())
|
||||
const accountTips = [...accountTangle.getTips()]
|
||||
const accountTips = [...accountTangle.tips]
|
||||
const fullOpts = { ...opts, tangles, accountTips, keypair }
|
||||
|
||||
// If opts ask for encryption, encrypt and put ciphertext in opts.data
|
||||
|
|
|
@ -147,10 +147,9 @@ function create(opts) {
|
|||
for (const rootID in opts.tangles) {
|
||||
if ((err = validateMsgID(rootID))) throw err
|
||||
const tangle = opts.tangles[rootID]
|
||||
const depth = tangle.getMaxDepth() + 1
|
||||
const tips = tangle.getTips()
|
||||
const depth = tangle.maxDepth + 1
|
||||
const lipmaaSet = tangle.getLipmaaSet(depth)
|
||||
const prev = [...union(lipmaaSet, tips)].sort()
|
||||
const prev = [...union(lipmaaSet, tangle.tips)].sort()
|
||||
tangles[rootID] = { depth, prev }
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -151,7 +151,7 @@ class Tangle {
|
|||
/**
|
||||
* @returns {Set<string>}
|
||||
*/
|
||||
getTips() {
|
||||
get tips() {
|
||||
if (!this.#rootMsg) {
|
||||
console.trace('Tangle is missing root message')
|
||||
return new Set()
|
||||
|
@ -196,7 +196,7 @@ class Tangle {
|
|||
return isMoot(this.#rootMsg)
|
||||
}
|
||||
|
||||
getMoot() {
|
||||
get mootDetails() {
|
||||
if (!this.isFeed()) return null
|
||||
if (!this.#rootMsg) {
|
||||
console.trace('Tangle is missing root message')
|
||||
|
@ -261,7 +261,7 @@ class Tangle {
|
|||
return this.#depth.size
|
||||
}
|
||||
|
||||
getMaxDepth() {
|
||||
get maxDepth() {
|
||||
return this.#maxDepth
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,7 @@ function validateShape(msg) {
|
|||
return 'invalid message: must have metadata.dataSize\n' + JSON.stringify(msg)
|
||||
}
|
||||
if (!('account' in msg.metadata)) {
|
||||
return (
|
||||
'invalid message: must have metadata.account\n' + JSON.stringify(msg)
|
||||
)
|
||||
return 'invalid message: must have metadata.account\n' + JSON.stringify(msg)
|
||||
}
|
||||
if (!('accountTips' in msg.metadata)) {
|
||||
// prettier-ignore
|
||||
|
@ -163,7 +161,7 @@ function validateSignature(msg) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @typedef {NonNullable<ReturnType<Tangle['getMoot']>>} FeedDetails
|
||||
* @typedef {NonNullable<Tangle['mootDetails']>} MootDetails
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -187,7 +185,7 @@ function validateTangle(msg, tangle, tangleID) {
|
|||
return `invalid message: depth "${depth}" should have been a positive integer\n` + JSON.stringify(msg)
|
||||
}
|
||||
if (tangle.isFeed()) {
|
||||
const { account, domain } = /** @type {FeedDetails} */ (tangle.getMoot())
|
||||
const { account, domain } = /** @type {MootDetails} */ (tangle.mootDetails)
|
||||
if (domain !== msg.metadata.domain) {
|
||||
// prettier-ignore
|
||||
return `invalid message: domain "${msg.metadata.domain}" should have been feed domain "${domain}"\n` + JSON.stringify(msg)
|
||||
|
|
|
@ -113,8 +113,8 @@ test('Tangle.getDepth', (t) => {
|
|||
assert.equal(tangle.getDepth(reply3Hi), 3, 'depth of reply3Hi is 3')
|
||||
})
|
||||
|
||||
test('Tangle.getMaxDepth', (t) => {
|
||||
assert.equal(tangle.getMaxDepth(), 3, 'max depth is 3')
|
||||
test('Tangle.maxDepth', (t) => {
|
||||
assert.equal(tangle.maxDepth, 3, 'max depth is 3')
|
||||
})
|
||||
|
||||
test('Tangle.topoSort', (t) => {
|
||||
|
@ -173,8 +173,8 @@ test('Tangle.precedes', (t) => {
|
|||
)
|
||||
})
|
||||
|
||||
test('Tangle.getTips', (t) => {
|
||||
const tips = tangle.getTips()
|
||||
test('Tangle.tips', (t) => {
|
||||
const tips = tangle.tips
|
||||
|
||||
assert.equal(tips.size, 2, 'there are 2 tips')
|
||||
assert.equal(tips.has(reply3Lo), true, 'tips contains reply3Lo')
|
||||
|
|
Loading…
Reference in New Issue