update to msg-v4

This commit is contained in:
Andre Staltz 2023-12-25 12:28:22 +02:00
parent e069033f9a
commit 0695ccc36a
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
const MsgV3 = require('ppppp-db/msg-v3')
const MsgV4 = require('ppppp-db/msg-v4')
const PREFIX = 'dict_v1__'
@ -32,7 +32,7 @@ const PREFIX = 'dict_v1__'
/**
* @template [T = any]
* @typedef {import('ppppp-db/msg-v3').Msg<T>} Msg<T>
* @typedef {import('ppppp-db/msg-v4').Msg<T>} Msg<T>
*/
/**
@ -84,7 +84,7 @@ function initDict(peer, config) {
let accountID = /** @type {string | null} */ (null)
let loadPromise = /** @type {Promise<void> | null} */ (null)
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
const tangles = /** @type {Map<Subdomain, MsgV3.Tangle>} */ (new Map())
const tangles = /** @type {Map<Subdomain, MsgV4.Tangle>} */ (new Map())
const fieldRoots = {
_map: /** @type {Map<SubdomainField, Set<MsgID>>} */ (new Map()),
@ -167,7 +167,7 @@ function initDict(peer, config) {
if (msg.metadata.account !== accountID) return false
const domain = msg.metadata.domain
if (!domain.startsWith(PREFIX)) return false
return MsgV3.isMoot(msg, accountID, domain)
return MsgV4.isMoot(msg, accountID, domain)
}
/**
@ -194,7 +194,7 @@ function initDict(peer, config) {
*/
function learnDictMoot(mootID, moot) {
const subdomain = toSubdomain(moot.metadata.domain)
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
const tangle = tangles.get(subdomain) ?? new MsgV4.Tangle(mootID)
tangle.add(mootID, moot)
tangles.set(subdomain, tangle)
}
@ -206,9 +206,9 @@ function initDict(peer, config) {
*/
function learnDictUpdate(msgID, msg) {
const { account, domain } = msg.metadata
const mootID = MsgV3.getMootID(account, domain)
const mootID = MsgV4.getMootID(account, domain)
const subdomain = toSubdomain(domain)
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
const tangle = tangles.get(subdomain) ?? new MsgV4.Tangle(mootID)
tangle.add(msgID, msg)
tangles.set(subdomain, tangle)
@ -265,7 +265,7 @@ function initDict(peer, config) {
if (!accountID) throw new Error('Cannot squeeze potential before loading')
// TODO: improve this so that the squeezePotential is the size of the
// tangle suffix built as a slice from the fieldRoots
const mootID = MsgV3.getMootID(accountID, fromSubdomain(subdomain))
const mootID = MsgV4.getMootID(accountID, fromSubdomain(subdomain))
const tangle = peer.db.getTangle(mootID)
const maxDepth = tangle.maxDepth
const fieldRoots = _getFieldRoots(subdomain)
@ -355,7 +355,7 @@ function initDict(peer, config) {
// prettier-ignore
if (!tangle || tangle.size === 0) throw new Error(`Tangle "${tangleID}" is locally unknown`)
// prettier-ignore
if (!MsgV3.isMoot(tangle.root)) throw new Error(`Tangle "${tangleID}" is not a moot`)
if (!MsgV4.isMoot(tangle.root)) throw new Error(`Tangle "${tangleID}" is not a moot`)
const domain = tangle.root.metadata.domain
// prettier-ignore
if (!domain.startsWith(PREFIX)) throw new Error(`Tangle "${tangleID}" is not a Dict moot`)
@ -400,7 +400,7 @@ function initDict(peer, config) {
function read(id, subdomain) {
assertDBPlugin(peer)
const domain = fromSubdomain(subdomain)
const mootID = MsgV3.getMootID(id, domain)
const mootID = MsgV4.getMootID(id, domain)
const tangle = peer.db.getTangle(mootID)
if (!tangle || tangle.size === 0) {
if (id === accountID) return {}
@ -427,7 +427,7 @@ function initDict(peer, config) {
if (!accountID) throw new Error('Cannot getFeedID() before loading')
assertDBPlugin(peer)
const domain = fromSubdomain(subdomain)
return MsgV3.getMootID(accountID, domain)
return MsgV4.getMootID(accountID, domain)
}
/**

View File

@ -3,7 +3,7 @@ const assert = require('node:assert')
const path = require('path')
const os = require('os')
const rimraf = require('rimraf')
const MsgV3 = require('ppppp-db/msg-v3')
const MsgV4 = require('ppppp-db/msg-v4')
const Keypair = require('ppppp-keypair')
const p = require('util').promisify
const { createPeer } = require('./util')
@ -156,8 +156,8 @@ test('Dict squeeze', async (t) => {
})
test('Dict isGhostable', (t) => {
const moot = MsgV3.createMoot(aliceID, 'dict_v1__profile', aliceKeypair)
const mootID = MsgV3.getMsgID(moot)
const moot = MsgV4.createMoot(aliceID, 'dict_v1__profile', aliceKeypair)
const mootID = MsgV4.getMsgID(moot)
assert.equal(mootID, peer.dict.getFeedID('profile'), 'getFeedID')
@ -182,16 +182,16 @@ test('Dict isGhostable', (t) => {
test('Dict receives old branched update', async (t) => {
const UPDATE6_ID = getMsgID(peer, 6, 'dict_v1__profile')
const moot = MsgV3.createMoot(aliceID, 'dict_v1__profile', aliceKeypair)
const mootID = MsgV3.getMsgID(moot)
const moot = MsgV4.createMoot(aliceID, 'dict_v1__profile', aliceKeypair)
const mootID = MsgV4.getMsgID(moot)
assert.equal(peer.dict.minRequiredDepth(mootID), 7, 'minRequiredDepth')
const tangle = new MsgV3.Tangle(mootID)
const tangle = new MsgV4.Tangle(mootID)
tangle.add(mootID, moot)
await p(peer.db.add)(moot, mootID)
const msg = MsgV3.create({
const msg = MsgV4.create({
keypair: aliceKeypair,
domain: 'dict_v1__profile',
account: aliceID,