Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 164a133

Browse files
committed
feat: Provide access to bundled libraries when in browser
1 parent 0e1ad8d commit 164a133

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ In order to be considered "valid", an IPFS core implementation must expose the
103103
- [config](/SPEC/CONFIG.md)
104104
- [stats](/SPEC/STATS.md)
105105
- [repo](/SPEC/REPO.md)
106+
- [**Types**](/SPEC/TYPES.md)
106107

107108
## Contribute
108109

SPEC/TYPES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
TYPES API
2+
=======
3+
4+
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.
5+
6+
- [`ipfs.types.Buffer`](https://www.npmjs.com/package/buffer)
7+
- [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id)
8+
- [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info)
9+
- [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr)
10+
- [`ipfs.types.multibase`](https://github.com/multiformats/multibase)
11+
- [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash)
12+
- [`ipfs.types.CID`](https://github.com/ipld/js-cid)
13+
- [`ipfs.types.crypto`](https://github.com/libp2p/js-libp2p-crypto)
14+
- [`ipfs.types.dagPB`](https://github.com/ipld/js-ipld-dag-pb)
15+
- [`ipfs.types.dagCBOR`](https://github.com/ipld/js-ipld-dag-cbor)
16+
- [`ipfs.types.isIPFS`](https://github.com/ipfs-shipyard/is-ipfs)

js/src/types.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const PeerId = require('peer-id')
5+
const PeerInfo = require('peer-info')
6+
const dagCBOR = require('ipld-dag-cbor')
7+
const dagPB = require('ipld-dag-pb')
8+
const crypto = require('libp2p-crypto')
9+
const isIPFS = require('is-ipfs')
10+
const multiaddr = require('multiaddr')
11+
const multibase = require('multibase')
12+
const multihash = require('multihashes')
13+
const CID = require('cids')
14+
15+
const chai = require('chai')
16+
const dirtyChai = require('dirty-chai')
17+
const expect = chai.expect
18+
chai.use(dirtyChai)
19+
20+
describe('.types', function () {
21+
let ipfs
22+
23+
before(function (done) {
24+
// CI takes longer to instantiate the daemon, so we need to increase the
25+
// timeout for the before step
26+
this.timeout(60 * 1000)
27+
28+
common.setup((err, factory) => {
29+
expect(err).to.not.exist()
30+
factory.spawnNode((err, node) => {
31+
expect(err).to.not.exist()
32+
ipfs = node
33+
done()
34+
})
35+
})
36+
})
37+
38+
after((done) => {
39+
common.teardown(done)
40+
})
41+
42+
it('types object', () => {
43+
expect(ipfs.types).to.be.deep.equal({
44+
Buffer: Buffer,
45+
PeerId: PeerId,
46+
PeerInfo: PeerInfo,
47+
multiaddr: multiaddr,
48+
multibase: multibase,
49+
multihash: multihash,
50+
CID: CID,
51+
crypto: crypto,
52+
dagPB: dagPB,
53+
dagCBOR: dagCBOR,
54+
isIPFS: isIPFS
55+
})
56+
})
57+
})

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@
4444
"ipfs-block": "~0.6.1",
4545
"ipld-dag-cbor": "~0.12.0",
4646
"ipld-dag-pb": "~0.13.1",
47+
"is-ipfs": "^0.3.2",
48+
"libp2p-crypto": "^0.12.1",
4749
"multiaddr": "^3.1.0",
50+
"multibase": "^0.4.0",
4851
"multihashes": "~0.4.13",
4952
"multihashing-async": "~0.4.8",
5053
"peer-id": "~0.10.6",
54+
"peer-info": "^0.11.6",
5155
"pull-stream": "^3.6.7"
5256
},
5357
"devDependencies": {},

0 commit comments

Comments
 (0)