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

Commit

Permalink
feat: Provide access to bundled libraries when in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and daviddias committed Apr 5, 2018
1 parent 0e1ad8d commit db83b50
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions SPEC/TYPES.md
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions SPEC/UTIL.md
Original file line number Diff line number Diff line change
@@ -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)
53 changes: 53 additions & 0 deletions js/src/types.js
Original file line number Diff line number Diff line change
@@ -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
})
})
})
40 changes: 40 additions & 0 deletions js/src/util.js
Original file line number Diff line number Diff line change
@@ -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
})
})
})
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down

0 comments on commit db83b50

Please sign in to comment.