From 0b7f49846e3feb43bb4700699b9aa29af7d44cd4 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Mon, 28 Aug 2023 15:47:24 +0300 Subject: [PATCH] rename some Tangle getters --- lib/index.js | 2 +- lib/msg-v3/index.js | 5 ++--- lib/msg-v3/tangle.js | 8 ++++---- lib/msg-v3/validation.js | 8 +++----- test/getTangle.test.js | 8 ++++---- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8b59156..76f5a54 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/lib/msg-v3/index.js b/lib/msg-v3/index.js index 55fc982..379276b 100644 --- a/lib/msg-v3/index.js +++ b/lib/msg-v3/index.js @@ -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 { diff --git a/lib/msg-v3/tangle.js b/lib/msg-v3/tangle.js index 405e15a..c8fb5d4 100644 --- a/lib/msg-v3/tangle.js +++ b/lib/msg-v3/tangle.js @@ -151,7 +151,7 @@ class Tangle { /** * @returns {Set} */ - getTips() { + get tips() { if (!this.#rootMsg) { console.trace('Tangle is missing root message') return new Set() @@ -196,14 +196,14 @@ class Tangle { return isMoot(this.#rootMsg) } - getMoot() { + get mootDetails() { if (!this.isFeed()) return null if (!this.#rootMsg) { console.trace('Tangle is missing root message') return null } const { account, domain } = this.#rootMsg.metadata - return { account, domain, id: this.#rootID } + return { account, domain, id: this.#rootID } } /** @@ -261,7 +261,7 @@ class Tangle { return this.#depth.size } - getMaxDepth() { + get maxDepth() { return this.#maxDepth } diff --git a/lib/msg-v3/validation.js b/lib/msg-v3/validation.js index c84777c..ec74917 100644 --- a/lib/msg-v3/validation.js +++ b/lib/msg-v3/validation.js @@ -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>} FeedDetails + * @typedef {NonNullable} 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) diff --git a/test/getTangle.test.js b/test/getTangle.test.js index 66030c6..6580c6f 100644 --- a/test/getTangle.test.js +++ b/test/getTangle.test.js @@ -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')