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