diff --git a/lib/index.js b/lib/index.js index d7be9fd..7248b45 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,14 +3,14 @@ const Obz = require('obz') /** * @typedef {ReturnType} PPPPPDB - * @typedef {ReturnType} PPPPPRecord + * @typedef {ReturnType} PPPPPDict * @typedef {import('ppppp-db').RecPresent} RecPresent * @typedef {import('ppppp-db').Tangle} Tangle * @typedef {import('ppppp-db').Msg} Msg * @typedef {ReturnType} DBTangle * @typedef {string} MsgID - * @typedef {'none'|'all'|`newest-${number}`|'record'|'set'} GoalDSL - * @typedef {'none'|'all'|'newest'|'record'|'set'} GoalType + * @typedef {'none'|'all'|`newest-${number}`|'dict'|'set'} GoalDSL + * @typedef {'none'|'all'|'newest'|'dict'|'set'} GoalType * @typedef {[number, number]} Range * @typedef {{ id: string, type: GoalType, count: number }} Goal * @typedef {{ tangleID: MsgID, span: number }} GhostDetails @@ -56,11 +56,11 @@ function assertDBPlugin(peer) { } /** - * @param {{ record: PPPPPRecord | null }} peer - * @returns {asserts peer is { record: PPPPPRecord }} + * @param {{ dict: PPPPPDict | null }} peer + * @returns {asserts peer is { dict: PPPPPDict }} */ -function assertRecordPlugin(peer) { - if (!peer.record) throw new Error('goals plugin requires ppppp-record plugin') +function assertDictPlugin(peer) { + if (!peer.dict) throw new Error('goals plugin requires ppppp-dict plugin') } /** @@ -102,8 +102,8 @@ class GoalImpl { return } - if (goalDSL === 'record') { - this.#type = 'record' + if (goalDSL === 'dict') { + this.#type = 'dict' this.#count = Infinity return } @@ -132,7 +132,7 @@ class GoalImpl { } /** - * @param {{ db: PPPPPDB | null, record: PPPPPRecord | null }} peer + * @param {{ db: PPPPPDB | null, dict: PPPPPDict | null }} peer * @param {unknown} config */ function initGoals(peer, config) { @@ -161,9 +161,9 @@ function initGoals(peer, config) { case 'set': return [0, maxDepth] - case 'record': - assertRecordPlugin(peer) - const minDepth = peer.record.minRequiredDepth(goal.id) + case 'dict': + assertDictPlugin(peer) + const minDepth = peer.dict.minRequiredDepth(goal.id) return [minDepth, maxDepth] case 'none': @@ -205,7 +205,7 @@ function initGoals(peer, config) { assertDBPlugin(peer) let servesAsTrail = false - // Check whether this record is a goalful root of some tangle: + // Check whether this msg is a goalful root of some tangle: asRoot: if (goals.has(msgID)) { const goal = /** @type {GoalImpl} */ (goals.get(msgID)) if (goal.type === 'none') break asRoot @@ -217,7 +217,7 @@ function initGoals(peer, config) { if (min > 0) servesAsTrail = true } - // Check whether this record is a goalful affix of some tangle: + // Check whether this msg is a goalful affix of some tangle: const validTangles = /** @type {Array<[DBTangle, number, number, number, GoalType]>} */ ([]) asAffix: for (const tangleID in msg.metadata.tangles) { @@ -236,10 +236,10 @@ function initGoals(peer, config) { for (const [, min, max, recDepth] of validTangles) { if (min <= recDepth && recDepth <= max) return ['goal'] } - // At this point we know that the record *cannot* serve as 'goal', + // At this point we know that the msg *cannot* serve as 'goal', // so if it serves as trail, that'll do: if (servesAsTrail) return ['trail'] - // Check whether this record is a trail affix of some tangle: + // Check whether this msg is a trail affix of some tangle: // (Loop again with heavy computations now that it's inevitable:) for (const [tangle, min] of validTangles) { const minMsgIDs = tangle @@ -249,12 +249,12 @@ function initGoals(peer, config) { if (erasables.has(msgID)) return ['trail'] } - // Check whether this record is a ghost affix of some tangle: + // Check whether this msg is a ghost affix of some tangle: for (const [tangle, , , , goalType] of validTangles) { - if (goalType === 'record') { - assertRecordPlugin(peer) - const span = peer.record.getGhostSpan() - if (peer.record.isGhostable(msgID, tangle.id)) { + if (goalType === 'dict') { + assertDictPlugin(peer) + const span = peer.dict.getGhostSpan() + if (peer.dict.isGhostable(msgID, tangle.id)) { return ['ghost', {tangleID: tangle.id, span }] } } diff --git a/package.json b/package.json index f7d8542..e50dbea 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,9 @@ "bs58": "^5.0.0", "c8": "7", "ppppp-db": "github:staltz/ppppp-db", + "ppppp-dict": "github:staltz/ppppp-dict", "ppppp-caps": "github:staltz/ppppp-caps", "ppppp-keypair": "github:staltz/ppppp-keypair", - "ppppp-record": "github:staltz/ppppp-record", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0", diff --git a/test/goals.test.js b/test/goals.test.js index 2a6bb59..8ba73d7 100644 --- a/test/goals.test.js +++ b/test/goals.test.js @@ -106,7 +106,7 @@ test('getMsgPurpose', async (t) => { }) test('getMsgPurpose ghost', async (t) => { - const alice = createPeer({ name: 'alice', record: { ghostSpan: 3 } }) + const alice = createPeer({ name: 'alice', dict: { ghostSpan: 3 } }) await alice.db.loaded() const aliceID = await p(alice.db.account.create)({ @@ -114,21 +114,21 @@ test('getMsgPurpose ghost', async (t) => { _nonce: 'alice', }) - await p(alice.record.load)(aliceID) - await p(alice.record.update)('profile', { name: 'alice' }) - await p(alice.record.update)('profile', { name: 'Alice' }) - await p(alice.record.update)('profile', { name: 'Alicia' }) - await p(alice.record.update)('profile', { name: 'ALICIA' }) - await p(alice.record.update)('profile', { name: 'ALICIAA' }) + await p(alice.dict.load)(aliceID) + await p(alice.dict.update)('profile', { name: 'alice' }) + await p(alice.dict.update)('profile', { name: 'Alice' }) + await p(alice.dict.update)('profile', { name: 'Alicia' }) + await p(alice.dict.update)('profile', { name: 'ALICIA' }) + await p(alice.dict.update)('profile', { name: 'ALICIAA' }) - const feedID = alice.record.getFeedID('profile') + const feedID = alice.dict.getFeedID('profile') const tangle = alice.db.getTangle(feedID) const msgIDs = tangle.topoSort() assert.equal(msgIDs.length, 6, 'tangle has root+5 messages') const recs = msgIDs.map((id) => alice.db.getRecord(id)) - alice.goals.set(feedID, 'record') + alice.goals.set(feedID, 'dict') assert.equal(alice.goals.getMsgPurpose(recs[1].id, recs[1].msg)[0], 'none') assert.equal(alice.goals.getMsgPurpose(recs[2].id, recs[2].msg)[0], 'ghost') assert.equal(alice.goals.getMsgPurpose(recs[3].id, recs[3].msg)[0], 'trail') diff --git a/test/util.js b/test/util.js index 3f9ba8d..fed4e5f 100644 --- a/test/util.js +++ b/test/util.js @@ -18,7 +18,7 @@ function createPeer(opts) { .use(require('secret-stack/plugins/net')) .use(require('secret-handshake-ext/secret-stack')) .use(require('ppppp-db')) - .use(require('ppppp-record')) + .use(require('ppppp-dict')) .use(require('ssb-box')) .use(require('../lib')) .call(null, {