update to msg-v4

This commit is contained in:
Andre Staltz 2023-12-25 12:29:28 +02:00
parent 39b3364137
commit b481fa0655
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 14 additions and 14 deletions

View File

@ -1,6 +1,6 @@
// @ts-ignore
const Obz = require('obz')
const MsgV3 = require('ppppp-db/msg-v3')
const MsgV4 = require('ppppp-db/msg-v4')
const PREFIX = 'set_v1__'
@ -36,7 +36,7 @@ const PREFIX = 'set_v1__'
/**
* @template [T = any]
* @typedef {import('ppppp-db/msg-v3').Msg<T>} Msg<T>
* @typedef {import('ppppp-db/msg-v4').Msg<T>} Msg<T>
*/
/**
@ -98,7 +98,7 @@ function initSet(peer, config) {
let loadPromise = /** @type {Promise<void> | null} */ (null)
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
const watch = /**@type {ObzType}*/ (Obz())
const tangles = /** @type {Map<Subdomain, MsgV3.Tangle>} */ (new Map())
const tangles = /** @type {Map<Subdomain, MsgV4.Tangle>} */ (new Map())
const itemRoots = {
_map: /** @type {Map<SubdomainItem, Set<MsgID>>} */ (new Map()),
@ -181,7 +181,7 @@ function initSet(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)
}
/**
@ -207,7 +207,7 @@ function initSet(peer, config) {
function readSet(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) return new Set()
const msgIDs = tangle.topoSort()
@ -230,7 +230,7 @@ function initSet(peer, config) {
function learnSetMoot(mootID, moot) {
const { domain } = moot.metadata
const subdomain = toSubdomain(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)
}
@ -241,9 +241,9 @@ function initSet(peer, config) {
*/
function learnSetUpdate(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)
const addOrDel = msg.data.add.concat(msg.data.del)
@ -297,7 +297,7 @@ function initSet(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 currentItemRoots = itemRoots.getAll(subdomain)
@ -464,7 +464,7 @@ function initSet(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 Set moot`)
@ -500,7 +500,7 @@ function initSet(peer, config) {
assert(!!accountID, '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('node:path')
const os = require('node:os')
const rimraf = require('rimraf')
const MsgV3 = require('ppppp-db/msg-v3')
const MsgV4 = require('ppppp-db/msg-v4')
const p = require('node:util').promisify
const { createPeer } = require('./util')
const Keypair = require('ppppp-keypair')
@ -170,8 +170,8 @@ test('predsl Set squeeze', async (t) => {
})
test('Set isGhostable', (t) => {
const moot = MsgV3.createMoot(aliceID, 'set_v1__follows', aliceKeypair)
const mootID = MsgV3.getMsgID(moot)
const moot = MsgV4.createMoot(aliceID, 'set_v1__follows', aliceKeypair)
const mootID = MsgV4.getMsgID(moot)
assert.equal(mootID, peer.set.getFeedID('follows'), 'getFeedID')