forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: export types and utilities statically (ipfs#951)
Allows users to access these additional types and utilities without having to create an instance of the client first. resolves ipfs#902 BREAKING CHANGE: `ipfs.util.isIPFS` has moved to a static export and should be accessed via `const { isIPFS } = require('ipfs-http-client')`. The modules available under `ipfs.types.*` have also become static exports. `ipfs.util.crypto` has been removed as it is not a dependency of `ipfs-http-client` so reduces the bundle size. If you need to use libp2p crypto primitives then please see the [js-libp2p-crypto](https://github.com/libp2p/js-libp2p-crypto) project for info on how to use it in your project. Finally `ipfs.util.getEndpointConfig` is now a direct instance method, `ipfs.getEndpointConfig` License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
- Loading branch information
Alan Shaw
authored
Mar 6, 2019
1 parent
05f2f6c
commit d1e99e7
Showing
11 changed files
with
117 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-env mocha */ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const isNode = require('detect-node') | ||
|
||
const ipfsClient = require('../src') | ||
const f = require('./utils/factory') | ||
|
||
describe('.getEndpointConfig', () => { | ||
if (!isNode) { return } | ||
|
||
let ipfsd | ||
let ipfs | ||
|
||
before(function (done) { | ||
this.timeout(20 * 1000) // slow CI | ||
|
||
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => { | ||
expect(err).to.not.exist() | ||
ipfsd = _ipfsd | ||
ipfs = ipfsClient(_ipfsd.apiAddr) | ||
done() | ||
}) | ||
}) | ||
|
||
after(function (done) { | ||
this.timeout(10 * 1000) | ||
if (!ipfsd) return done() | ||
ipfsd.stop(done) | ||
}) | ||
|
||
it('should return the endpoint configuration', function () { | ||
const endpoint = ipfs.getEndpointConfig() | ||
|
||
expect(endpoint.host).to.equal('127.0.0.1') | ||
expect(endpoint.protocol).to.equal('http') | ||
expect(endpoint['api-path']).to.equal('/api/v0/') | ||
// changes per test run so we just assert it exists. | ||
expect(endpoint).to.have.property('port') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-env mocha, browser */ | ||
'use strict' | ||
|
||
const isIPFS = require('is-ipfs') | ||
const CID = require('cids') | ||
const multiaddr = require('multiaddr') | ||
const multibase = require('multibase') | ||
const multihash = require('multihashes') | ||
const PeerId = require('peer-id') | ||
const PeerInfo = require('peer-info') | ||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
|
||
const IpfsHttpClient = require('../') | ||
|
||
describe('exports', () => { | ||
it('should export the expected types and utilities', () => { | ||
expect(IpfsHttpClient.isIPFS).to.equal(isIPFS) | ||
expect(IpfsHttpClient.Buffer).to.equal(Buffer) | ||
expect(IpfsHttpClient.CID).to.equal(CID) | ||
expect(IpfsHttpClient.multiaddr).to.equal(multiaddr) | ||
expect(IpfsHttpClient.multibase).to.equal(multibase) | ||
expect(IpfsHttpClient.multihash).to.equal(multihash) | ||
expect(IpfsHttpClient.PeerId).to.equal(PeerId) | ||
expect(IpfsHttpClient.PeerInfo).to.equal(PeerInfo) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.