From b481fa06551f033dcbc3e3ff48abcc04fd485016 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Mon, 25 Dec 2023 12:29:28 +0200 Subject: [PATCH] update to msg-v4 --- lib/index.js | 22 +++++++++++----------- test/index.test.js | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index 6dde0b1..d29c287 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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} Msg + * @typedef {import('ppppp-db/msg-v4').Msg} Msg */ /** @@ -98,7 +98,7 @@ function initSet(peer, config) { let loadPromise = /** @type {Promise | null} */ (null) let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null) const watch = /**@type {ObzType}*/ (Obz()) - const tangles = /** @type {Map} */ (new Map()) + const tangles = /** @type {Map} */ (new Map()) const itemRoots = { _map: /** @type {Map>} */ (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) } /** diff --git a/test/index.test.js b/test/index.test.js index 78de184..6eca6d1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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')