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)
|
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
|
* @public
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
|
@ -416,6 +437,7 @@ function initRecord(peer, config) {
|
||||||
update,
|
update,
|
||||||
read,
|
read,
|
||||||
getFieldRoots,
|
getFieldRoots,
|
||||||
|
getFieldRootsOfTangle,
|
||||||
squeeze,
|
squeeze,
|
||||||
|
|
||||||
_squeezePotential,
|
_squeezePotential,
|
||||||
|
|
|
@ -79,6 +79,8 @@ test('Record update() and get()', async (t) => {
|
||||||
{ age: ['9iTTqNabtnXmw4AiZxNMRq'], name: ['M2JhM7TE2KX5T5rfnxBh6M'] },
|
{ age: ['9iTTqNabtnXmw4AiZxNMRq'], name: ['M2JhM7TE2KX5T5rfnxBh6M'] },
|
||||||
'fieldRoots'
|
'fieldRoots'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Record squeeze', async (t) => {
|
test('Record squeeze', async (t) => {
|
||||||
|
@ -141,6 +143,9 @@ test('Record receives old branched update', async (t) => {
|
||||||
'fieldRoots'
|
'fieldRoots'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const altFieldRoots7 = peer.record.getFieldRootsOfTangle(mootID)
|
||||||
|
assert.deepEqual(altFieldRoots7, fieldRoots7, 'getFieldRootsOfTangle')
|
||||||
|
|
||||||
assert.equal(peer.record._squeezePotential('profile'), 6, 'squeezePotential=6')
|
assert.equal(peer.record._squeezePotential('profile'), 6, 'squeezePotential=6')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue