Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit f501a9d

Browse files
docs(api): first pass
1 parent 1af30c1 commit f501a9d

22 files changed

+438
-48
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ build
3131
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3232
node_modules
3333

34-
lib
3534
dist
35+
docs

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ build
3232
node_modules
3333

3434
test
35+
docs

documentation.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
toc:
2+
- name: Intro
3+
file: intro.md

intro.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Install
2+
3+
### npm
4+
5+
This project is available through [npm](https://www.npmjs.com/). To install:
6+
7+
```bash
8+
$ npm install ipfs --save
9+
```
10+
11+
Requires npm@3 and node >= 4, tested on OSX & Linux, expected to work on Windows.
12+
13+
### Use in Node.js
14+
15+
To include this project programmatically:
16+
17+
```js
18+
var IPFS = require('ipfs')
19+
20+
var node = new IPFS()
21+
```
22+
23+
### Through command line tool
24+
25+
In order to use js-ipfs as a CLI, you must install it with the `global` flag. Run the following (even if you have ipfs installed locally):
26+
27+
```bash
28+
$ npm install ipfs --global
29+
```
30+
31+
The CLI is available by using the command `jsipfs` in your terminal. This is aliased, instead of using `ipfs`, to make sure it does not conflict with the Go implementation.
32+
33+
### Use in the browser with browserify, webpack or any bundler
34+
35+
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust the asset management process.
36+
37+
```js
38+
var ipfs = require('ipfs');
39+
```
40+
41+
### Use in a browser using a script tag
42+
43+
Loading this module in a browser (using a `<script>` tag) makes the `Ipfs` object available in the global namespace.
44+
45+
The last published version of the package become [available for download](https://unpkg.com/ipfs/dist/) from [unpkg](https://unpkg.com/) and thus you may use it as the source:
46+
47+
48+
```html
49+
<!-- loading the minified version -->
50+
<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>
51+
52+
<!-- loading the human-readable (not minified) version -->
53+
<script src="https://unpkg.com/ipfs/dist/index.js"></script>
54+
```

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020
"scripts": {
2121
"lint": "aegir-lint",
2222
"coverage": "gulp coverage",
23+
"docs": "aegir-docs",
2324
"test": "gulp test",
2425
"test:node": "gulp test:node",
2526
"test:node:core": "TEST=core npm run test:node",
2627
"test:node:http": "TEST=http npm run test:node",
2728
"test:node:cli": "TEST=cli npm run test:node",
2829
"test:browser": "gulp test:browser",
2930
"build": "gulp build",
30-
"release": "gulp release",
31-
"release-minor": "gulp release --type minor",
32-
"release-major": "gulp release --type major",
31+
"release": "gulp release --docs",
32+
"release-minor": "gulp release --type minor --docs",
33+
"release-major": "gulp release --type major --docs",
3334
"coverage-publish": "aegir-coverage publish"
3435
},
3536
"pre-commit": [
@@ -150,4 +151,4 @@
150151
"nginnever <[email protected]>",
151152
"npmcdn-to-unpkg-bot <[email protected]>"
152153
]
153-
}
154+
}

src/core/components/bitswap.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ function formatWantlist (list) {
88

99
module.exports = function bitswap (self) {
1010
return {
11+
/**
12+
* @alias bitswap.wantlist
13+
* @memberof IPFS#
14+
* @method
15+
* @returns {Array}
16+
*/
1117
wantlist: () => {
1218
if (!self.isOnline()) {
1319
throw OFFLINE_ERROR
@@ -16,6 +22,12 @@ module.exports = function bitswap (self) {
1622
const list = self._bitswap.getWantlist()
1723
return formatWantlist(list)
1824
},
25+
/**
26+
* @alias bitswap.stat
27+
* @memberof IPFS#
28+
* @method
29+
* @returns {Object}
30+
*/
1931
stat: () => {
2032
if (!self.isOnline()) {
2133
throw OFFLINE_ERROR
@@ -27,6 +39,14 @@ module.exports = function bitswap (self) {
2739

2840
return stats
2941
},
42+
/**
43+
* NOT IMPLEMENTED
44+
* @alias bitswap.unwant
45+
* @memberof IPFS#
46+
* @method
47+
* @param {*} key
48+
* @returns {undefined}
49+
*/
3050
unwant: (key) => {
3151
if (!self.isOnline()) {
3252
throw OFFLINE_ERROR

src/core/components/block.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ const waterfall = require('async/waterfall')
77

88
module.exports = function block (self) {
99
return {
10+
/**
11+
* @alias block.get
12+
* @memberof IPFS#
13+
* @method
14+
* @param {function(Error)} callback
15+
* @returns {undefined}
16+
*/
1017
get: (cid, callback) => {
1118
cid = cleanCid(cid)
1219
self._blockService.get(cid, callback)
1320
},
21+
/**
22+
* @alias block.put
23+
* @memberof IPFS#
24+
* @method
25+
* @param {function(Error)} callback
26+
* @returns {undefined}
27+
*/
1428
put: (block, cid, callback) => {
1529
if (typeof cid === 'function') {
1630
// legacy (without CID)
@@ -49,10 +63,24 @@ module.exports = function block (self) {
4963
callback(null, block)
5064
})
5165
},
66+
/**
67+
* @alias block.rm
68+
* @memberof IPFS#
69+
* @method
70+
* @param {function(Error)} callback
71+
* @returns {undefined}
72+
*/
5273
rm: (cid, callback) => {
5374
cid = cleanCid(cid)
5475
self._blockService.delete(cid, callback)
5576
},
77+
/**
78+
* @alias block.stat
79+
* @memberof IPFS#
80+
* @method
81+
* @param {function(Error)} callback
82+
* @returns {undefined}
83+
*/
5684
stat: (cid, callback) => {
5785
cid = cleanCid(cid)
5886

src/core/components/bootstrap.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
module.exports = function bootstrap (self) {
44
return {
5+
/**
6+
* @alias bootstrap.list
7+
* @memberof IPFS#
8+
* @param {function(Error, Array<string>)} callback
9+
* @returns {Promise<Array<string>>|undefined}
10+
*/
511
list: (callback) => {
612
self._repo.config.get((err, config) => {
713
if (err) {
@@ -10,6 +16,14 @@ module.exports = function bootstrap (self) {
1016
callback(null, config.Bootstrap)
1117
})
1218
},
19+
20+
/**
21+
* @alias bootstrap.add
22+
* @memberof IPFS#
23+
* @param {string} multiaddr
24+
* @param {function(Error)} callback
25+
* @returns {Promise<undefined>|undefined}
26+
*/
1327
add: (multiaddr, callback) => {
1428
self._repo.config.get((err, config) => {
1529
if (err) {
@@ -19,6 +33,14 @@ module.exports = function bootstrap (self) {
1933
self._repo.config.set(config, callback)
2034
})
2135
},
36+
37+
/**
38+
* @alias bootstrap.rm
39+
* @memberof IPFS#
40+
* @param {string} multiaddr
41+
* @param {function(Error)} callback
42+
* @returns {Promise<undefiend>|undefined}
43+
*/
2244
rm: (multiaddr, callback) => {
2345
self._repo.config.get((err, config) => {
2446
if (err) {

src/core/components/config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const _set = require('lodash.set')
77

88
module.exports = function config (self) {
99
return {
10+
/**
11+
* @alias config.get
12+
* @memberof IPFS#
13+
* @method
14+
* @param {function(Error)} callback
15+
* @returns {Promise<undefined>|undefined}
16+
*/
1017
get: promisify((key, callback) => {
1118
if (typeof key === 'function') {
1219
callback = key
@@ -33,6 +40,13 @@ module.exports = function config (self) {
3340
}
3441
})
3542
}),
43+
/**
44+
* @alias config.set
45+
* @memberof IPFS#
46+
* @method
47+
* @param {function(Error)} callback
48+
* @returns {Promise<undefined>|undefined}
49+
*/
3650
set: promisify((key, value, callback) => {
3751
if (!key || typeof key !== 'string') {
3852
return callback(new Error('Invalid key type'))
@@ -50,6 +64,13 @@ module.exports = function config (self) {
5064
self.config.replace(config, callback)
5165
})
5266
}),
67+
/**
68+
* @alias config.replace
69+
* @memberof IPFS#
70+
* @method
71+
* @param {function(Error)} callback
72+
* @returns {Promise<undefined>|undefined}
73+
*/
5374
replace: promisify((config, callback) => {
5475
self._repo.config.set(config, callback)
5576
})

src/core/components/files.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,32 @@ module.exports = function files (self) {
2525
}
2626

2727
return {
28+
/**
29+
* @alias files.createAddStream
30+
* @memberof IPFS#
31+
* @method
32+
* @param {function(Error, DuplexStream)} callback
33+
* @returns {Promise<DuplexStream>|undefined}
34+
*/
2835
createAddStream: (callback) => {
2936
callback(null, toStream(createAddPullStream()))
3037
},
31-
38+
/**
39+
* @alias files.createAddPullStream
40+
* @memberof IPFS#
41+
* @method
42+
* @param {function(Error, Pullstream)} callback
43+
* @returns {Promise<PullStream>|undefined}
44+
*/
3245
createAddPullStream: createAddPullStream,
33-
46+
/**
47+
* @alias files.add
48+
* @memberof IPFS#
49+
* @method
50+
* @param {*} data
51+
* @param {function(Error *)} callback
52+
* @returns {Promise<*>|undefined}
53+
*/
3454
add: promisify((data, callback) => {
3555
if (!callback || typeof callback !== 'function') {
3656
callback = noop
@@ -48,7 +68,14 @@ module.exports = function files (self) {
4868
pull.collect(callback)
4969
)
5070
}),
51-
71+
/**
72+
* @alias files.cat
73+
* @memberof IPFS#
74+
* @method
75+
* @param {string} hash
76+
* @param {function(Error, ReadableStream)} callback
77+
* @returns {Promise<ReadableStream>|undefined}
78+
*/
5279
cat: promisify((hash, callback) => {
5380
if (typeof hash === 'function') {
5481
return callback(new Error('You must supply a multihash'))
@@ -77,7 +104,14 @@ module.exports = function files (self) {
77104
)
78105
})
79106
}),
80-
107+
/**
108+
* @alias files.get
109+
* @memberof IPFS#
110+
* @method
111+
* @param {string} hash
112+
* @param {function(Error, *)} callback
113+
* @returns {Promise<*>|undefined}
114+
*/
81115
get: promisify((hash, callback) => {
82116
callback(null, toStream.source(pull(
83117
exporter(hash, self._ipldResolver),
@@ -91,7 +125,14 @@ module.exports = function files (self) {
91125
})
92126
)))
93127
}),
94-
128+
/**
129+
* @alias files.getPull
130+
* @memberof IPFS#
131+
* @method
132+
* @param {string} hash
133+
* @param {function(Error, *)} callback
134+
* @returns {Promise<*>|undefined}
135+
*/
95136
getPull: promisify((hash, callback) => {
96137
callback(null, exporter(hash, self._ipldResolver))
97138
})

0 commit comments

Comments
 (0)