mirror of https://codeberg.org/pzp/pzp-db.git
rename feed.getID() to feed.findMoot()
This commit is contained in:
parent
5b81c6ea82
commit
f9a3875ffd
|
@ -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,
|
||||
|
|
|
@ -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)()
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue