diff --git a/lib/index.js b/lib/index.js index 3293af2..f326459 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,30 +23,10 @@ const makeDebug = require('debug') */ /** - * @param {{ db: PPPPPDB | null }} peer - * @returns {asserts peer is { db: PPPPPDB }} - */ -function assertDBPlugin(peer) { - if (!peer.db) throw new Error('"gc" plugin requires "db" plugin') -} - -/** - * @param {{ goals: PPPPPGoal | null }} peer - * @returns {asserts peer is { goals: PPPPPGoal }} - */ -function assertGoalsPlugin(peer) { - if (!peer.goals) throw new Error('"gc" plugin requires "goals" plugin') -} - -/** - * @param {{ db: PPPPPDB | null, goals: PPPPPGoal | null }} peer + * @param {{ db: PPPPPDB, goals: PPPPPGoal }} peer * @param {Config} config */ function initGC(peer, config) { - // Assertions - assertDBPlugin(peer) - assertGoalsPlugin(peer) - // State const debug = makeDebug('ppppp:gc') let stopMonitoringLogSize = /** @type {CallableFunction | null} */ (null) @@ -58,8 +38,6 @@ function initGC(peer, config) { * @param {CB} cb */ function cleanup(cb) { - assertDBPlugin(peer) - assertGoalsPlugin(peer) debug('Cleanup started') const startTime = Date.now() @@ -104,7 +82,6 @@ function initGC(peer, config) { * @param {CB} cb */ function compact(cb) { - assertDBPlugin(peer) debug('Compaction started') const startTime = Date.now() peer.db.log.compact((err) => { @@ -165,13 +142,10 @@ function initGC(peer, config) { * @param {number} maxLogBytes */ function monitorLogSize(maxLogBytes) { - assertDBPlugin(peer) - /** Number of records that match roughly 1% of the max log size */ const CHECKPOINT = Math.floor((maxLogBytes * 0.01) / 500) // assuming 1 record = 500 bytes function checkLogSize() { - assertDBPlugin(peer) peer.db.log.stats((err, stats) => { if (err) return const percentUsed = (stats.totalBytes / maxLogBytes) * 100 @@ -248,4 +222,5 @@ function initGC(peer, config) { } exports.name = 'gc' +exports.needs = ['db', 'goals'] exports.init = initGC diff --git a/package.json b/package.json index 1e0c290..33eb33a 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,12 @@ "ppppp-dict": "github:staltz/ppppp-dict", "ppppp-goals": "github:staltz/ppppp-goals", "ppppp-keypair": "github:staltz/ppppp-keypair", + "ppppp-set": "github:staltz/ppppp-set", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0", "secret-handshake-ext": "0.0.11", - "secret-stack": "~8.0.0", + "secret-stack": "~8.1.0", "ssb-box": "^1.0.1", "typescript": "^5.1.3" }, diff --git a/test/util.js b/test/util.js index 9c821a0..cd64f6f 100644 --- a/test/util.js +++ b/test/util.js @@ -29,6 +29,7 @@ function createPeer(config) { .use(require('secret-handshake-ext/secret-stack')) .use(require('ppppp-db')) .use(require('ppppp-dict')) + .use(require('ppppp-set')) .use(require('ppppp-goals')) .use(require('ssb-box')) .use(require('../lib')) diff --git a/tsconfig.json b/tsconfig.json index bd2acd5..cc6e7af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,6 @@ "module": "node16", "skipLibCheck": true, "strict": true, - "target": "es2021" + "target": "es2022" } } \ No newline at end of file