Skip to content

Commit

Permalink
chore: use .create function for http client and ipfs client
Browse files Browse the repository at this point in the history
ipfs/js-ipfs#3550 switches away from default exports for `ipfs-http-client`
and `ipfs-client` to enable an easier transition to es6 modules.

All `ipfs` modules now export a `.create` factory function which returns
instances of the client module.

BREAKING CHANGE: expects `ipfs-http-client` and `ipfs-client` to export a `.create` function
  • Loading branch information
achingbrain committed Mar 21, 2021
1 parent 85229f5 commit 77c3f29
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/ipfsd-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class Client {
*/
_createApi () {
if (this.opts.ipfsClientModule && this.grpcAddr && this.apiAddr) {
this.api = this.opts.ipfsClientModule({
this.api = this.opts.ipfsClientModule.create({
grpc: this.grpcAddr,
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule(this.apiAddr)
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
}

if (this.api) {
Expand Down
4 changes: 2 additions & 2 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class Daemon {

_createApi () {
if (this.opts.ipfsClientModule && this.grpcAddr) {
this.api = this.opts.ipfsClientModule({
this.api = this.opts.ipfsClientModule.create({
grpc: this.grpcAddr,
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule(this.apiAddr)
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
}

if (!this.api) {
Expand Down
2 changes: 1 addition & 1 deletion src/ipfsd-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class InProc {
*/
_setApi (addr) {
this.apiAddr = multiaddr(addr)
this.api = this.opts.ipfsHttpModule(addr)
this.api = this.opts.ipfsHttpModule.create(addr)
this.api.apiHost = this.apiAddr.nodeAddress().address
this.api.apiPort = this.apiAddr.nodeAddress().port
}
Expand Down
32 changes: 20 additions & 12 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ describe('`createController` should return the correct class', () => {
type: 'js',
disposable: false,
ipfsModule: require('ipfs'),
ipfsClientModule: (opts) => {
clientCreated = true
ipfsClientModule: {
create: (opts) => {
clientCreated = true

return require('ipfs-client')(opts)
return require('ipfs-client')(opts)
}
},
ipfsHttpModule: (opts) => {
httpCreated = true
ipfsHttpModule: {
create: (opts) => {
httpCreated = true

return require('ipfs-http-client')(opts)
return require('ipfs-http-client')(opts)
}
},
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})
Expand All @@ -90,15 +94,19 @@ describe('`createController` should return the correct class', () => {
remote: true,
disposable: false,
ipfsModule: require('ipfs'),
ipfsClientModule: (opts) => {
clientCreated = true
ipfsClientModule: {
create: (opts) => {
clientCreated = true

return require('ipfs-client')(opts)
return require('ipfs-client')(opts)
}
},
ipfsHttpModule: (opts) => {
httpCreated = true
ipfsHttpModule: {
create: (opts) => {
httpCreated = true

return require('ipfs-http-client')(opts)
return require('ipfs-http-client')(opts)
}
},
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})
Expand Down

0 comments on commit 77c3f29

Please sign in to comment.