From 0cf94b852ecf22e897ee39f2a9c5250825384950 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 | 2 ++ SPEC/TYPES.md | 14 +++++++++++++ SPEC/UTIL.md | 7 +++++++ js/src/types.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ js/src/util.js | 40 +++++++++++++++++++++++++++++++++++++ package.json | 4 ++++ 6 files changed, 120 insertions(+) create mode 100644 SPEC/TYPES.md create mode 100644 SPEC/UTIL.md create mode 100644 js/src/types.js create mode 100644 js/src/util.js diff --git a/README.md b/README.md index 3ad84c99..6b636075 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ 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) +- [**Util**](/SPEC/UTIL.md) ## Contribute diff --git a/SPEC/TYPES.md b/SPEC/TYPES.md new file mode 100644 index 00000000..379b3718 --- /dev/null +++ b/SPEC/TYPES.md @@ -0,0 +1,14 @@ +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.dagPB`](https://github.com/ipld/js-ipld-dag-pb) +- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor) diff --git a/SPEC/UTIL.md b/SPEC/UTIL.md new file mode 100644 index 00000000..f8a513de --- /dev/null +++ b/SPEC/UTIL.md @@ -0,0 +1,7 @@ +UTIL API +======= + +A set of utils are exposed directly from the IPFS instance under `ipfs.util`. That way you're not required to import/require the following: + +- [`ipfs.util.crypto`](https://github.com/libp2p/js-libp2p-crypto) +- [`ipfs.util.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..fbba03e8 --- /dev/null +++ b/js/src/types.js @@ -0,0 +1,53 @@ +/* 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 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, + dagPB: dagPB, + dagCBOR: dagCBOR + }) + }) +}) diff --git a/js/src/util.js b/js/src/util.js new file mode 100644 index 00000000..e0c53a04 --- /dev/null +++ b/js/src/util.js @@ -0,0 +1,40 @@ +/* eslint-env mocha */ +'use strict' + +const crypto = require('libp2p-crypto') +const isIPFS = require('is-ipfs') + +const chai = require('chai') +const dirtyChai = require('dirty-chai') +const expect = chai.expect +chai.use(dirtyChai) +util +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('util object', () => { + expect(ipfs.util).to.be.deep.equal({ + crypto: crypto, + 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": {},