mirror of https://codeberg.org/pzp/pzp-dict.git
new API getFieldRootsOfTangle
This commit is contained in:
parent
cc7cf9858d
commit
8fe7b8717d
22
lib/index.js
22
lib/index.js
|
@ -333,6 +333,27 @@ function initRecord(peer, config) {
|
|||
return fieldRoots.getAll(subdomain)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} tangleID
|
||||
*/
|
||||
function getFieldRootsOfTangle(tangleID) {
|
||||
assertDBExists(peer)
|
||||
// prettier-ignore
|
||||
if (!accountID) throw new Error('Cannot getFieldRootsByTangle() before loading')
|
||||
|
||||
const rootMsg = peer.db.get(tangleID)
|
||||
if (!rootMsg) throw new Error(`Cannot find tangle root "${tangleID}"`)
|
||||
// prettier-ignore
|
||||
if (!MsgV3.isMoot(rootMsg, accountID)) throw new Error(`"${tangleID}" is not a moot`)
|
||||
|
||||
const domain = rootMsg.metadata.domain
|
||||
// prettier-ignore
|
||||
if (!domain.startsWith(PREFIX)) throw new Error(`"${tangleID}" is not a record moot`)
|
||||
const subdomain = toSubdomain(domain)
|
||||
|
||||
return getFieldRoots(subdomain)
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @param {string} id
|
||||
|
@ -416,6 +437,7 @@ function initRecord(peer, config) {
|
|||
update,
|
||||
read,
|
||||
getFieldRoots,
|
||||
getFieldRootsOfTangle,
|
||||
squeeze,
|
||||
|
||||
_squeezePotential,
|
||||
|
|
|
@ -79,6 +79,8 @@ test('Record update() and get()', async (t) => {
|
|||
{ age: ['9iTTqNabtnXmw4AiZxNMRq'], name: ['M2JhM7TE2KX5T5rfnxBh6M'] },
|
||||
'fieldRoots'
|
||||
)
|
||||
|
||||
|
||||
})
|
||||
|
||||
test('Record squeeze', async (t) => {
|
||||
|
@ -141,6 +143,9 @@ test('Record receives old branched update', async (t) => {
|
|||
'fieldRoots'
|
||||
)
|
||||
|
||||
const altFieldRoots7 = peer.record.getFieldRootsOfTangle(mootID)
|
||||
assert.deepEqual(altFieldRoots7, fieldRoots7, 'getFieldRootsOfTangle')
|
||||
|
||||
assert.equal(peer.record._squeezePotential('profile'), 6, 'squeezePotential=6')
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue