From 20ea2f9ac4195b0598e0b57de37e418c11731a1d Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 19 Aug 2022 14:48:33 -0700 Subject: [PATCH] feat: add js-kubo-rpc-client see https://github.com/ipfs/kubo/issues/9125 --- .aegir.js | 4 +++- package.json | 9 +++++---- src/factory.js | 3 ++- src/ipfsd-client.js | 8 +++++++- src/ipfsd-daemon.js | 8 +++++++- src/ipfsd-in-proc.js | 9 ++++++++- src/types.ts | 4 ++++ 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.aegir.js b/.aegir.js index 8b6ca72d..6e57c500 100644 --- a/.aegir.js +++ b/.aegir.js @@ -1,6 +1,7 @@ import { createServer } from './src/index.js' import * as ipfsModule from 'ipfs' import * as ipfsHttpModule from 'ipfs-http-client' +import * as kuboRpcModule from 'js-kubo-rpc-client' import * as goIpfsModule from 'go-ipfs' /** @type {import('aegir').Options["build"]["config"]} */ @@ -22,7 +23,8 @@ export default { before: async () => { const server = createServer(undefined, { ipfsModule, - ipfsHttpModule + ipfsHttpModule: process.env.USE_KUBO_JS ? undefined : ipfsHttpModule, + kuboRpcModule: process.env.USE_KUBO_JS ? kuboRpcModule : undefined }, { go: { ipfsBin: goIpfsModule.path() diff --git a/package.json b/package.json index 1faf5f6a..b12012e0 100644 --- a/package.json +++ b/package.json @@ -140,10 +140,10 @@ "scripts": { "lint": "aegir lint", "build": "aegir build", - "test": "aegir test", - "test:node": "aegir test -t node", - "test:chrome": "aegir test -t browser", - "test:firefox": "aegir test -t browser -- --browser firefox", + "test": "aegir test && USE_KUBO_JS=1 aegir test", + "test:node": "aegir test -t node && USE_KUBO_JS=1 aegir test -t node", + "test:chrome": "aegir test -t browser && USE_KUBO_JS=1 aegir test -t browser", + "test:firefox": "aegir test -t browser -- --browser firefox && USE_KUBO_JS=1 aegir test -t browser -- --browser firefox", "release": "aegir release" }, "dependencies": { @@ -155,6 +155,7 @@ "execa": "^6.1.0", "ipfs-utils": "^9.0.1", "joi": "^17.2.1", + "js-kubo-rpc-client": "^1.0.0", "merge-options": "^3.0.1", "nanoid": "^4.0.0", "p-wait-for": "^4.1.0", diff --git a/src/factory.js b/src/factory.js index 81e13ba7..9f8f3e78 100644 --- a/src/factory.js +++ b/src/factory.js @@ -88,7 +88,8 @@ class Factory { remote: false, ipfsBin: undefined, ipfsModule: undefined, - ipfsHttpModule: undefined + ipfsHttpModule: undefined, + kuboRpcModule: undefined } } diff --git a/src/ipfsd-client.js b/src/ipfsd-client.js index 528ab016..0e06b719 100644 --- a/src/ipfsd-client.js +++ b/src/ipfsd-client.js @@ -95,7 +95,13 @@ class Client { http: this.apiAddr }) } else if (this.apiAddr) { - this.api = this.opts.ipfsHttpModule.create(this.apiAddr) + if (this.opts.kuboRpcModule != null) { + this.api = this.opts.kuboRpcModule.create(this.apiAddr) + } else if (this.opts.ipfsHttpModule != null) { + this.api = this.opts.ipfsHttpModule.create(this.apiAddr) + } else { + throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule') + } } if (this.api) { diff --git a/src/ipfsd-daemon.js b/src/ipfsd-daemon.js index 9ad655f6..f9b3e84e 100644 --- a/src/ipfsd-daemon.js +++ b/src/ipfsd-daemon.js @@ -100,7 +100,13 @@ class Daemon { http: this.apiAddr }) } else if (this.apiAddr) { - this.api = this.opts.ipfsHttpModule.create(this.apiAddr) + if (this.opts.kuboRpcModule != null) { + this.api = this.opts.kuboRpcModule.create(this.apiAddr) + } else if (this.opts.ipfsHttpModule != null) { + this.api = this.opts.ipfsHttpModule.create(this.apiAddr) + } else { + throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule') + } } if (!this.api) { diff --git a/src/ipfsd-in-proc.js b/src/ipfsd-in-proc.js index 15a6970e..8d21bf3a 100644 --- a/src/ipfsd-in-proc.js +++ b/src/ipfsd-in-proc.js @@ -67,7 +67,14 @@ class InProc { */ _setApi (addr) { this.apiAddr = new Multiaddr(addr) - this.api = this.opts.ipfsHttpModule.create(addr) + + if (this.opts.kuboRpcModule != null) { + this.api = this.opts.kuboRpcModule.create(addr) + } else if (this.opts.ipfsHttpModule != null) { + this.api = this.opts.ipfsHttpModule.create(addr) + } else { + throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule') + } this.api.apiHost = this.apiAddr.nodeAddress().address this.api.apiPort = this.apiAddr.nodeAddress().port } diff --git a/src/types.ts b/src/types.ts index fcc1d4af..bca76334 100644 --- a/src/types.ts +++ b/src/types.ts @@ -168,6 +168,10 @@ export interface ControllerOptions { * Reference to an ipfs-http-client module */ ipfsHttpModule?: any + /** + * Reference to a js-kubo-rpc-client module + */ + kuboRpcModule?: any /** * Reference to an ipfs or ipfs-core module */