diff --git a/lib/index.js b/lib/index.js index 74ed33e..86f2532 100644 --- a/lib/index.js +++ b/lib/index.js @@ -475,7 +475,7 @@ function initDB(peer, config) { const keypair = opts.keypair ?? config.keypair const { account, domain } = opts - const mootID = findMoot(account, domain) + const mootID = findMoot(account, domain)?.id if (mootID) return cb(null, mootID) const moot = MsgV3.createMoot(account, domain, keypair) @@ -915,12 +915,13 @@ function initDB(peer, config) { /** * @param {string} id * @param {string} findDomain + * @returns {RecPresent | null} */ function findMoot(id, findDomain) { const findAccount = MsgV3.stripAccount(id) for (const rec of records()) { if (rec.msg && MsgV3.isMoot(rec.msg, findAccount, findDomain)) { - return rec.id + return rec } } return null @@ -1097,7 +1098,7 @@ function initDB(peer, config) { }, feed: { publish: publishToFeed, - getID: findMoot, + findMoot, }, getRecord, get, diff --git a/test/account-add.test.js b/test/account-add.test.js index 7869e5d..7f7868c 100644 --- a/test/account-add.test.js +++ b/test/account-add.test.js @@ -181,8 +181,8 @@ test('account.add()', async (t) => { keypair: keypair2, }) assert.equal(postRec.msg.data.text, 'hello', 'post text correct') - const postsID = peer.db.feed.getID(account, 'post') - assert.ok(postsID, 'postsID exists') + const mootRec = peer.db.feed.findMoot(account, 'post') + assert.ok(mootRec, 'posts moot exists') const recs = [...peer.db.records()] assert.equal(recs.length, 4, '4 records') @@ -219,8 +219,8 @@ test('account.add()', async (t) => { await p(carol.db.add)(accountMsg0, account) await p(carol.db.add)(accountRec1.msg, account) - await p(carol.db.add)(postsRoot.msg, postsID) - await p(carol.db.add)(postRec.msg, postsID) + await p(carol.db.add)(postsRoot.msg, mootRec.id) + await p(carol.db.add)(postRec.msg, mootRec.id) // t.pass('carol added all msgs successfully') await p(carol.close)() diff --git a/test/feed-get-id.test.js b/test/feed-get-id.test.js index fc25b85..241832f 100644 --- a/test/feed-get-id.test.js +++ b/test/feed-get-id.test.js @@ -12,7 +12,7 @@ const MsgV3 = require('../lib/msg-v3') const DIR = path.join(os.tmpdir(), 'ppppp-db-feed-publish') rimraf.sync(DIR) -test('feed.getID()', async (t) => { +test('feed.findMoot()', async (t) => { const keypair = Keypair.generate('ed25519', 'alice') const peer = SecretStack({ appKey: caps.shse }) .use(require('../lib')) @@ -27,8 +27,8 @@ test('feed.getID()', async (t) => { await p(peer.db.add)(moot, mootID) - const feedID = peer.db.feed.getID(id, 'post') - assert.equal(feedID, mootID, 'feed.getID() returns moot ID') + const mootRec = peer.db.feed.findMoot(id, 'post') + assert.equal(mootRec.id, mootID, 'feed.findMoot() returns moot ID') await p(peer.close)(true) }) diff --git a/test/ghosts.tests.js b/test/ghosts.tests.js index ff1cc4c..a893c37 100644 --- a/test/ghosts.tests.js +++ b/test/ghosts.tests.js @@ -32,7 +32,7 @@ test('ghosts.add, ghosts.get, ghosts.getMinDepth', async (t) => { }) msgIDs.push(rec.id) } - const tangleID = peer.db.feed.getID(account, 'post') + const tangleID = peer.db.feed.findMoot(account, 'post')?.id const ghosts0 = peer.db.ghosts.get(tangleID) assert.deepEqual(ghosts0, [], 'no ghosts so far') @@ -78,7 +78,7 @@ test('ghosts.add queues very-concurrent calls', async (t) => { }) msgIDs.push(rec.id) } - const tangleID = peer.db.feed.getID(account, 'post') + const tangleID = peer.db.feed.findMoot(account, 'post')?.id const ghosts0 = peer.db.ghosts.get(tangleID) assert.deepEqual(ghosts0, [], 'no ghosts so far')