mirror of https://codeberg.org/pzp/pzp-set.git
update to msg-v4
This commit is contained in:
parent
39b3364137
commit
b481fa0655
22
lib/index.js
22
lib/index.js
|
@ -1,6 +1,6 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const Obz = require('obz')
|
const Obz = require('obz')
|
||||||
const MsgV3 = require('ppppp-db/msg-v3')
|
const MsgV4 = require('ppppp-db/msg-v4')
|
||||||
|
|
||||||
const PREFIX = 'set_v1__'
|
const PREFIX = 'set_v1__'
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ const PREFIX = 'set_v1__'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template [T = any]
|
* @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 loadPromise = /** @type {Promise<void> | null} */ (null)
|
||||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
||||||
const watch = /**@type {ObzType}*/ (Obz())
|
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 = {
|
const itemRoots = {
|
||||||
_map: /** @type {Map<SubdomainItem, Set<MsgID>>} */ (new Map()),
|
_map: /** @type {Map<SubdomainItem, Set<MsgID>>} */ (new Map()),
|
||||||
|
@ -181,7 +181,7 @@ function initSet(peer, config) {
|
||||||
if (msg.metadata.account !== accountID) return false
|
if (msg.metadata.account !== accountID) return false
|
||||||
const domain = msg.metadata.domain
|
const domain = msg.metadata.domain
|
||||||
if (!domain.startsWith(PREFIX)) return false
|
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) {
|
function readSet(id, subdomain) {
|
||||||
assertDBPlugin(peer)
|
assertDBPlugin(peer)
|
||||||
const domain = fromSubdomain(subdomain)
|
const domain = fromSubdomain(subdomain)
|
||||||
const mootID = MsgV3.getMootID(id, domain)
|
const mootID = MsgV4.getMootID(id, domain)
|
||||||
const tangle = peer.db.getTangle(mootID)
|
const tangle = peer.db.getTangle(mootID)
|
||||||
if (!tangle || tangle.size === 0) return new Set()
|
if (!tangle || tangle.size === 0) return new Set()
|
||||||
const msgIDs = tangle.topoSort()
|
const msgIDs = tangle.topoSort()
|
||||||
|
@ -230,7 +230,7 @@ function initSet(peer, config) {
|
||||||
function learnSetMoot(mootID, moot) {
|
function learnSetMoot(mootID, moot) {
|
||||||
const { domain } = moot.metadata
|
const { domain } = moot.metadata
|
||||||
const subdomain = toSubdomain(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(mootID, moot)
|
tangle.add(mootID, moot)
|
||||||
tangles.set(subdomain, tangle)
|
tangles.set(subdomain, tangle)
|
||||||
}
|
}
|
||||||
|
@ -241,9 +241,9 @@ function initSet(peer, config) {
|
||||||
*/
|
*/
|
||||||
function learnSetUpdate(msgID, msg) {
|
function learnSetUpdate(msgID, msg) {
|
||||||
const { account, domain } = msg.metadata
|
const { account, domain } = msg.metadata
|
||||||
const mootID = MsgV3.getMootID(account, domain)
|
const mootID = MsgV4.getMootID(account, domain)
|
||||||
const subdomain = toSubdomain(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)
|
tangle.add(msgID, msg)
|
||||||
tangles.set(subdomain, tangle)
|
tangles.set(subdomain, tangle)
|
||||||
const addOrDel = msg.data.add.concat(msg.data.del)
|
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')
|
if (!accountID) throw new Error('Cannot squeeze potential before loading')
|
||||||
// TODO: improve this so that the squeezePotential is the size of the
|
// TODO: improve this so that the squeezePotential is the size of the
|
||||||
// tangle suffix built as a slice from the fieldRoots
|
// 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 tangle = peer.db.getTangle(mootID)
|
||||||
const maxDepth = tangle.maxDepth
|
const maxDepth = tangle.maxDepth
|
||||||
const currentItemRoots = itemRoots.getAll(subdomain)
|
const currentItemRoots = itemRoots.getAll(subdomain)
|
||||||
|
@ -464,7 +464,7 @@ function initSet(peer, config) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
if (!tangle || tangle.size === 0) throw new Error(`Tangle "${tangleID}" is locally unknown`)
|
if (!tangle || tangle.size === 0) throw new Error(`Tangle "${tangleID}" is locally unknown`)
|
||||||
// prettier-ignore
|
// 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
|
const domain = tangle.root.metadata.domain
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
if (!domain.startsWith(PREFIX)) throw new Error(`Tangle "${tangleID}" is not a Set moot`)
|
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')
|
assert(!!accountID, 'Cannot getFeedID() before loading')
|
||||||
assertDBPlugin(peer)
|
assertDBPlugin(peer)
|
||||||
const domain = fromSubdomain(subdomain)
|
const domain = fromSubdomain(subdomain)
|
||||||
return MsgV3.getMootID(accountID, domain)
|
return MsgV4.getMootID(accountID, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@ const assert = require('node:assert')
|
||||||
const path = require('node:path')
|
const path = require('node:path')
|
||||||
const os = require('node:os')
|
const os = require('node:os')
|
||||||
const rimraf = require('rimraf')
|
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 p = require('node:util').promisify
|
||||||
const { createPeer } = require('./util')
|
const { createPeer } = require('./util')
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
|
@ -170,8 +170,8 @@ test('predsl Set squeeze', async (t) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Set isGhostable', (t) => {
|
test('Set isGhostable', (t) => {
|
||||||
const moot = MsgV3.createMoot(aliceID, 'set_v1__follows', aliceKeypair)
|
const moot = MsgV4.createMoot(aliceID, 'set_v1__follows', aliceKeypair)
|
||||||
const mootID = MsgV3.getMsgID(moot)
|
const mootID = MsgV4.getMsgID(moot)
|
||||||
|
|
||||||
assert.equal(mootID, peer.set.getFeedID('follows'), 'getFeedID')
|
assert.equal(mootID, peer.set.getFeedID('follows'), 'getFeedID')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue