diff --git a/lib/index.js b/lib/index.js index 24c488b..6dde0b1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -90,7 +90,7 @@ function assert(check, message) { function initSet(peer, config) { assertDBPlugin(peer) - const ghostSpan = config.set?.ghostSpan ?? 32 + let ghostSpan = config.set?.ghostSpan ?? 32 if (ghostSpan < 1) throw new Error('config.set.ghostSpan must be >= 0') //#region state @@ -531,6 +531,15 @@ function initSet(peer, config) { return ghostSpan } + /** + * @param {number} span + * @returns {void} + */ + function setGhostSpan(span) { + if (span < 1) throw new Error('ghostSpan must be >= 0') + ghostSpan = span + } + /** * @param {any} subdomain */ @@ -583,6 +592,7 @@ function initSet(peer, config) { getFeedID, isGhostable, getGhostSpan, + setGhostSpan, minGhostDepth, minRequiredDepth, squeeze, diff --git a/test/index.test.js b/test/index.test.js index 806ddd7..78de184 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -19,7 +19,7 @@ test('setup', async (t) => { peer = createPeer({ keypair: aliceKeypair, db: { path: DIR }, - set: { ghostSpan: 4 }, + set: { ghostSpan: 40 }, }) await peer.db.loaded() @@ -30,6 +30,7 @@ test('setup', async (t) => { }) await p(peer.set.load)(aliceID) + peer.set.setGhostSpan(4) assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan') })