From ae3d1d83d81158669b99f1889b429808c7e4c1f2 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Mon, 8 Jan 2024 11:33:45 +0200 Subject: [PATCH] update secret-stack to 8.1 --- lib/algorithm.js | 26 ++------------------------ lib/index.js | 41 ++++++----------------------------------- package.json | 2 +- tsconfig.json | 2 +- 4 files changed, 10 insertions(+), 61 deletions(-) diff --git a/lib/algorithm.js b/lib/algorithm.js index c6e3765..f64758b 100644 --- a/lib/algorithm.js +++ b/lib/algorithm.js @@ -24,31 +24,11 @@ function countIter(iter) { return count } -/** - * @param {{ dict: PPPPPDict | null }} peer - * @returns {asserts peer is { dict: PPPPPDict }} - */ -function assertDictPlugin(peer) { - if (!peer.dict) { - throw new Error('sync plugin requires ppppp-dict plugin') - } -} - -/** - * @param {{ set: PPPPPSet | null }} peer - * @returns {asserts peer is { set: PPPPPSet }} - */ -function assertSetPlugin(peer) { - if (!peer.set) { - throw new Error('sync plugin requires ppppp-set plugin') - } -} - class Algorithm { - /** @type {{ db: PPPPPDB, dict: PPPPPDict | null, set: PPPPPSet | null }} */ + /** @type {ConstructorParameters[0]} */ #peer - /** @param {{ db: PPPPPDB, dict: PPPPPDict | null, set: PPPPPSet | null }} peer */ + /** @param {{ db: PPPPPDB, dict: PPPPPDict, set: PPPPPSet }} peer */ constructor(peer) { this.#peer = peer } @@ -149,12 +129,10 @@ class Algorithm { return this.#wantAllRange(localHave, remoteHave) case 'dict': - assertDictPlugin(this.#peer) const minDictGhostDepth = this.#peer.dict.minGhostDepth(goal.id) return this.#wantDictOrSetRange(minDictGhostDepth, remoteHave) case 'set': - assertSetPlugin(this.#peer) const minSetGhostDepth = this.#peer.set.minGhostDepth(goal.id) return this.#wantDictOrSetRange(minSetGhostDepth, remoteHave) diff --git a/lib/index.js b/lib/index.js index 773c646..2806ad2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,44 +27,17 @@ function isMuxrpcMissingError(err, namespace, methodName) { return err.message === jsErrorMessage || err.message === goErrorMessage } -/** - * @param {{ db: PPPPPDB | null }} peer - * @returns {asserts peer is { db: PPPPPDB }} - */ -function assertDBExists(peer) { - if (!peer.db) throw new Error('"sync" plugin requires "db" plugin') -} - -/** - * @param {{ goals: PPPPPGoals | null }} peer - * @returns {asserts peer is { goals: PPPPPGoals }} - */ -function assertGoalsExists(peer) { - if (!peer.goals) throw new Error('"sync" plugin requires "goals" plugin') -} - -/** - * @param {{ shse: SHSE | null }} peer - * @returns {asserts peer is { shse: SHSE }} - */ -function assertSHSEExists(peer) { - if (!peer.shse) throw new Error('"sync" plugin requires "shse" plugin') -} - /** * @param {Emitter & { - * db: PPPPPDB | null, - * dict: PPPPPDict | null, - * set: PPPPPSet | null, - * goals: PPPPPGoals | null, - * shse: SHSE | null + * db: PPPPPDB, + * dict: PPPPPDict, + * set: PPPPPSet, + * goals: PPPPPGoals, + * shse: SHSE * }} peer * @param {unknown} config */ function initSync(peer, config) { - assertDBExists(peer) - assertGoalsExists(peer) - assertSHSEExists(peer) const debug = makeDebug(`ppppp:sync`) const algo = new Algorithm(peer) let started = false @@ -76,8 +49,6 @@ function initSync(peer, config) { * @param {boolean} iamClient */ function createStream(remoteId, iamClient) { - assertSHSEExists(peer) - assertGoalsExists(peer) // prettier-ignore debug('Opening a stream with remote %s %s', iamClient ? 'server' : 'client', remoteId) const stream = new SyncStream(peer.shse.pubkey, debug, peer.goals, algo) @@ -90,7 +61,6 @@ function initSync(peer, config) { * @param {boolean} iamClient */ function onSyncRPCConnect(rpc, iamClient) { - assertSHSEExists(peer) if (rpc.shse.pubkey === peer.shse.pubkey) return // connecting to myself if (!iamClient) return const stream = createStream(rpc.shse.pubkey, true) @@ -136,6 +106,7 @@ function initSync(peer, config) { } exports.name = 'sync' +exports.needs = ['db', 'dict', 'set', 'goals', 'shse'] exports.manifest = { connect: 'duplex', initiate: 'sync', diff --git a/package.json b/package.json index 8b874bb..f9900ac 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0", - "secret-stack": "~8.0.0", + "secret-stack": "~8.1.0", "secret-handshake-ext": "0.0.11", "ssb-box": "^1.0.1", "typescript": "^5.1.3" 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