diff --git a/lib/algorithm.js b/lib/algorithm.js index 93c29a5..c8c83db 100644 --- a/lib/algorithm.js +++ b/lib/algorithm.js @@ -10,6 +10,7 @@ const { EMPTY_RANGE, isEmptyRange, estimateMsgCount } = require('./range') * @typedef {ReturnType} PZPDict * @typedef {ReturnType} PZPSet * @typedef {import('pzp-db/msg-v4').Msg} Msg + * @typedef {import('pzp-db/db-tangle')} DBTangle * @typedef {import('pzp-goals').Goal} Goal * @typedef {import('./range').Range} Range * @typedef {string} MsgID @@ -314,12 +315,15 @@ class Algorithm { * @param {number} count */ async pruneNewest(rootID, count) { + /** @type {DBTangle | null} */ const tangle = await p(this.#peer.db.getTangle)(rootID) if (!tangle) return const sorted = tangle.topoSort() if (sorted.length <= count) return const msgID = sorted[sorted.length - count] // New "oldest dataful msg" - const { deletables, erasables } = tangle.getDeletablesAndErasables(msgID) + const deletablesErasables = tangle.getDeletablesAndErasables(msgID) + if (!deletablesErasables) return + const { deletables, erasables } = deletablesErasables const del = p(this.#peer.db.del) const erase = p(this.#peer.db.erase) for (const msgID of deletables) { diff --git a/package.json b/package.json index cc0238c..fd86e5e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@types/node": "16.x", "c8": "7", "pzp-caps": "^1.0.0", - "pzp-db": "^1.0.1", + "pzp-db": "^1.0.4", "pzp-dict": "^1.0.0", "pzp-goals": "^1.0.0", "pzp-keypair": "^1.0.0",