From 164a1331cf202b5681b85b7738a1e11c5ac9a568 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 4 Apr 2018 11:22:22 +0100 Subject: [PATCH] feat: Provide access to bundled libraries when in browser --- README.md | 1 + SPEC/TYPES.md | 16 ++++++++++++++ js/src/types.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++++ 4 files changed, 78 insertions(+) create mode 100644 SPEC/TYPES.md create mode 100644 js/src/types.js diff --git a/README.md b/README.md index 3ad84c99..9ba4be1e 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ In order to be considered "valid", an IPFS core implementation must expose the - [config](/SPEC/CONFIG.md) - [stats](/SPEC/STATS.md) - [repo](/SPEC/REPO.md) +- [**Types**](/SPEC/TYPES.md) ## Contribute diff --git a/SPEC/TYPES.md b/SPEC/TYPES.md new file mode 100644 index 00000000..9ba226e7 --- /dev/null +++ b/SPEC/TYPES.md @@ -0,0 +1,16 @@ +TYPES API +======= + +A set of data types are exposed directly from the IPFS instance under `ipfs.types`. That way you're not required to import/require the following. + +- [`ipfs.types.Buffer`](https://www.npmjs.com/package/buffer) +- [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id) +- [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info) +- [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr) +- [`ipfs.types.multibase`](https://github.com/multiformats/multibase) +- [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash) +- [`ipfs.types.CID`](https://github.com/ipld/js-cid) +- [`ipfs.types.crypto`](https://github.com/libp2p/js-libp2p-crypto) +- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb) +- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor) +- [`ipfs.types.isIPFS`](https://github.com/ipfs-shipyard/is-ipfs) diff --git a/js/src/types.js b/js/src/types.js new file mode 100644 index 00000000..971ba8ae --- /dev/null +++ b/js/src/types.js @@ -0,0 +1,57 @@ +/* eslint-env mocha */ +'use strict' + +const PeerId = require('peer-id') +const PeerInfo = require('peer-info') +const dagCBOR = require('ipld-dag-cbor') +const dagPB = require('ipld-dag-pb') +const crypto = require('libp2p-crypto') +const isIPFS = require('is-ipfs') +const multiaddr = require('multiaddr') +const multibase = require('multibase') +const multihash = require('multihashes') +const CID = require('cids') + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) + +describe('.types', function () { + let ipfs + + before(function (done) { + // CI takes longer to instantiate the daemon, so we need to increase the + // timeout for the before step + this.timeout(60 * 1000) + + common.setup((err, factory) => { + expect(err).to.not.exist() + factory.spawnNode((err, node) => { + expect(err).to.not.exist() + ipfs = node + done() + }) + }) + }) + + after((done) => { + common.teardown(done) + }) + + it('types object', () => { + expect(ipfs.types).to.be.deep.equal({ + Buffer: Buffer, + PeerId: PeerId, + PeerInfo: PeerInfo, + multiaddr: multiaddr, + multibase: multibase, + multihash: multihash, + CID: CID, + crypto: crypto, + dagPB: dagPB, + dagCBOR: dagCBOR, + isIPFS: isIPFS + }) + }) +}) diff --git a/package.json b/package.json index d7124f8e..828fb143 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,14 @@ "ipfs-block": "~0.6.1", "ipld-dag-cbor": "~0.12.0", "ipld-dag-pb": "~0.13.1", + "is-ipfs": "^0.3.2", + "libp2p-crypto": "^0.12.1", "multiaddr": "^3.1.0", + "multibase": "^0.4.0", "multihashes": "~0.4.13", "multihashing-async": "~0.4.8", "peer-id": "~0.10.6", + "peer-info": "^0.11.6", "pull-stream": "^3.6.7" }, "devDependencies": {},