From 0695ccc36a7810a11ec7237c928b0cb14a9d5087 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Mon, 25 Dec 2023 12:28:22 +0200 Subject: [PATCH] update to msg-v4 --- lib/index.js | 22 +++++++++++----------- test/index.test.js | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/index.js b/lib/index.js index ad5cdce..a320662 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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} Msg + * @typedef {import('ppppp-db/msg-v4').Msg} Msg */ /** @@ -84,7 +84,7 @@ function initDict(peer, config) { let accountID = /** @type {string | null} */ (null) let loadPromise = /** @type {Promise | null} */ (null) let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null) - const tangles = /** @type {Map} */ (new Map()) + const tangles = /** @type {Map} */ (new Map()) const fieldRoots = { _map: /** @type {Map>} */ (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) } /** diff --git a/test/index.test.js b/test/index.test.js index d401626..6549483 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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,