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

Commit 2970c9f

Browse files
nunofmndaviddias
authored andcommitted
modularize js-ipfs-api (#561)
* refactor: modularize js-ipfs-api(#544)
1 parent 3ca9904 commit 2970c9f

File tree

156 files changed

+2452
-1422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2452
-1422
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ test/setup/tmp-disposable-nodes-addrs.json
44
dist
55
coverage
66
**/*.swp
7+
examples/sub-module/**/bundle.js
8+
examples/sub-module/**/*-minified.js
9+
examples/sub-module/*-bundle.js

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ipfs-api
2525
- [Install](#install)
2626
- [Running the daemon with the right port](#running-the-daemon-with-the-right-port)
2727
- [Importing the module and usage](#importing-the-module-and-usage)
28+
- [Importing a sub-module and usage](#importing-a-sub-module-and-usage)
2829
- [In a web browser through Browserify](#in-a-web-browser-through-browserify)
2930
- [In a web browser from CDN](#in-a-web-browser-from-cdn)
3031
- [CORS](#cors)
@@ -74,6 +75,14 @@ var ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
7475
// or using options
7576
var ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'})
7677
```
78+
### Importing a sub-module and usage
79+
```javascript
80+
const bitswap = require('ipfs-api/src/bitswap')('/ip4/127.0.0.1/tcp/5001')
81+
82+
bitswap.unwant(key, (err) => {
83+
// ...
84+
}
85+
```
7786
7887
### In a web browser through Browserify
7988
@@ -224,12 +233,15 @@ This means:
224233
- [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id)
225234
- [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#version)
226235
- [`ipfs.ping()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#ping)
227-
- [`ipfs.log()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#log)
228236
229-
#### [key](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key)
237+
- log:
238+
- [`ipfs.log.ls([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
239+
- [`ipfs.log.tail([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
240+
- [`ipfs.log.level(subsystem, level, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
230241
231-
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
232-
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
242+
- key:
243+
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
244+
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
233245
234246
##### [name](https://github.com/ipfs/interface-ipfs-core/tree/master/API/name)
235247
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name, bundled (KBs), minified (KBs)
2+
IPFS, 1685.41, 661.64
3+
add, 968.11, 344.13
4+
bitswap, 684.80, 232.13
5+
block, 724.77, 250.23
6+
bootstrap, 685.64, 232.39
7+
cat, 725.05, 250.33
8+
commands, 683.89, 231.76
9+
config, 686.87, 233.10
10+
dht, 688.51, 233.41
11+
diag, 684.97, 232.18
12+
files, 1120.38, 404.30
13+
get, 907.74, 318.35
14+
id, 684.31, 231.95
15+
key, 684.59, 232.03
16+
log, 685.40, 232.38
17+
ls, 684.00, 231.80
18+
mount, 684.18, 231.86
19+
name, 684.63, 232.06
20+
object, 923.66, 340.57
21+
pin, 685.51, 232.39
22+
ping, 684.59, 231.90
23+
pubsub, 740.40, 249.54
24+
refs, 684.39, 231.94
25+
repo, 684.56, 232.02
26+
swarm, 1324.18, 527.03
27+
update, 684.45, 231.96
28+
version, 684.21, 231.88
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../src')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/add')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/bitswap')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/block')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/bootstrap')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/cat')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/commands')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/config')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/dht')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/diag')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/files')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/get')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/modules/id/id.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/id')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/key')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/log')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/modules/ls/ls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/ls')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/mount')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/name')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/object')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/pin')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/ping')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/pubsub')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/refs')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/repo')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/swarm')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/update')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
require('../../../../src/version')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "sub-module",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"author": "Nuno Nogueira",
9+
"license": "MIT",
10+
"devDependencies": {
11+
"babel-core": "^6.25.0",
12+
"babel-loader": "^7.1.0",
13+
"babel-preset-env": "^1.5.2",
14+
"babili": "^0.1.4",
15+
"webpack": "^3.0.0"
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
set -e
3+
4+
modules=($(ls modules/))
5+
6+
echo "name, bundled (KBs), minified (KBs)"
7+
8+
# Full IPFS module
9+
webpack --display none --config webpack.confg.js complete-module.js complete-bundle.js
10+
babili complete-bundle.js -o complete-bundle-minified.js
11+
12+
ipfsBundleSize=($(wc -c < complete-bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))
13+
ipfsMinSize=($(wc -c < complete-bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))
14+
15+
echo IPFS, $ipfsBundleSize, $ipfsMinSize
16+
17+
for module in "${modules[@]}"
18+
do
19+
moduledir="modules/$module"
20+
webpack --display none --config webpack.config.js $moduledir/$module.js $moduledir/bundle.js
21+
babili $moduledir/bundle.js -o $moduledir/bundle-minified.js
22+
23+
bundlesize=($(wc -c < $moduledir/bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))
24+
minsize=($(wc -c < $moduledir/bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))
25+
echo $module, $bundlesize, $minsize
26+
done

examples/sub-module/webpack.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
module: {
5+
loaders: [{
6+
test: /\.js$/,
7+
loaders: ['babel-loader']
8+
}]
9+
},
10+
node: {
11+
fs: 'empty',
12+
net: 'empty',
13+
tls: 'empty'
14+
}
15+
}

src/add.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
const moduleConfig = require('./utils/module-config')
4+
5+
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
8+
return require('./files/add')(send)
9+
}

src/api/bitswap.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)