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

Commit ddd3f22

Browse files
more documentation
1 parent ec58a59 commit ddd3f22

File tree

7 files changed

+110
-11
lines changed

7 files changed

+110
-11
lines changed

src/core/components/block.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ module.exports = function block (self) {
1111
* @alias block.get
1212
* @memberof IPFS#
1313
* @method
14+
* @param {CID} cid
1415
* @param {function(Error)} callback
1516
* @returns {undefined}
17+
*
18+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#get
1619
*/
1720
get: (cid, callback) => {
1821
cid = cleanCid(cid)
@@ -22,8 +25,12 @@ module.exports = function block (self) {
2225
* @alias block.put
2326
* @memberof IPFS#
2427
* @method
28+
* @param {Block} block
29+
* @param {CID} cid
2530
* @param {function(Error)} callback
2631
* @returns {undefined}
32+
*
33+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#put
2734
*/
2835
put: (block, cid, callback) => {
2936
if (typeof cid === 'function') {
@@ -67,8 +74,11 @@ module.exports = function block (self) {
6774
* @alias block.rm
6875
* @memberof IPFS#
6976
* @method
77+
* @param {CID} cid
7078
* @param {function(Error)} callback
7179
* @returns {undefined}
80+
*
81+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#rm
7282
*/
7383
rm: (cid, callback) => {
7484
cid = cleanCid(cid)
@@ -78,8 +88,11 @@ module.exports = function block (self) {
7888
* @alias block.stat
7989
* @memberof IPFS#
8090
* @method
91+
* @param {CID} cid
8192
* @param {function(Error)} callback
8293
* @returns {undefined}
94+
*
95+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#stat
8396
*/
8497
stat: (cid, callback) => {
8598
cid = cleanCid(cid)

src/core/components/go-offline.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
module.exports = function goOffline (self) {
4-
54
/**
65
* @alias goOffline
76
* @memberof IPFS#

src/core/components/id.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = function id (self) {
1111
* @param {Object} [opts={}]
1212
* @param {function(Error, IPFS#Id)} callback
1313
* @returns {Promise<IPFS#Id>|undefined}
14+
*
15+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id
1416
*/
1517
return promisify((opts, callback) => {
1618
if (typeof opts === 'function') {

src/core/components/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function load (self) {
1212
* @alias load
1313
* @memberof IPFS#
1414
* @method
15-
* @param {function(Error)} cb
15+
* @param {function(Error)} callback
1616
* @returns {undefined}
1717
*/
1818
return (callback) => {

src/core/components/object.js

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ module.exports = function object (self) {
9797
* @method
9898
* @param {function(Error)} callback
9999
* @returns {Promise<undefined>|undefined}
100+
*
101+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectnew
100102
*/
101103
new: promisify((callback) => {
102104
DAGNode.create(new Buffer(0), (err, node) => {
@@ -122,6 +124,8 @@ module.exports = function object (self) {
122124
* @method
123125
* @param {function(Error)} callback
124126
* @returns {Promise<undefined>|undefined}
127+
*
128+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectput
125129
*/
126130
put: promisify((obj, options, callback) => {
127131
if (typeof options === 'function') {
@@ -187,6 +191,8 @@ module.exports = function object (self) {
187191
* @method
188192
* @param {function(Error)} callback
189193
* @returns {Promise<undefined>|undefined}
194+
*
195+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectget
190196
*/
191197
get: promisify((multihash, options, callback) => {
192198
if (typeof options === 'function') {
@@ -211,6 +217,8 @@ module.exports = function object (self) {
211217
* @method
212218
* @param {function(Error)} callback
213219
* @returns {Promise<undefined>|undefined}
220+
*
221+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectdata
214222
*/
215223
data: promisify((multihash, options, callback) => {
216224
if (typeof options === 'function') {
@@ -232,6 +240,8 @@ module.exports = function object (self) {
232240
* @method
233241
* @param {function(Error)} callback
234242
* @returns {Promise<undefined>|undefined}
243+
*
244+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectlinks
235245
*/
236246
links: promisify((multihash, options, callback) => {
237247
if (typeof options === 'function') {
@@ -256,6 +266,8 @@ module.exports = function object (self) {
256266
* @param {Object} [options={}]
257267
* @param {function(Error)} callback
258268
* @returns {Promise<undefined>|undefined}
269+
*
270+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectstat
259271
*/
260272
stat: promisify((multihash, options, callback) => {
261273
if (typeof options === 'function') {
@@ -290,20 +302,37 @@ module.exports = function object (self) {
290302
})
291303
}),
292304

293-
/**
294-
* @alias object.patch
295-
* @memberof IPFS#
296-
* @method
297-
* @param {function(Error)} callback
298-
* @returns {Promise<undefined>|undefined}
299-
*/
300-
patch: promisify({
305+
patch: {
306+
/**
307+
* @alias object.patch.addLink
308+
* @memberof IPFS#
309+
* @method
310+
* @param {Buffer|string} multihash
311+
* @param {DAGLink} link
312+
* @param {Object} [options={}]
313+
* @param {function(Error)} callback
314+
* @returns {Promise<undefined>|undefined}
315+
*
316+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchaddlink
317+
*/
301318
addLink (multihash, link, options, callback) {
302319
editAndSave((node, cb) => {
303320
DAGNode.addLink(node, link, cb)
304321
})(multihash, options, callback)
305322
},
306323

324+
/**
325+
* @alias object.patch.rmLink
326+
* @memberof IPFS#
327+
* @method
328+
* @param {Buffer|string} multihash
329+
* @param {DAGLink} linkRef
330+
* @param {Object} [options={}]
331+
* @param {function(Error)} callback
332+
* @returns {Promise<undefined>|undefined}
333+
*
334+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchrmlink
335+
*/
307336
rmLink (multihash, linkRef, options, callback) {
308337
editAndSave((node, cb) => {
309338
if (linkRef.constructor &&
@@ -314,18 +343,42 @@ module.exports = function object (self) {
314343
})(multihash, options, callback)
315344
},
316345

346+
/**
347+
* @alias object.patch.appendData
348+
* @memberof IPFS#
349+
* @method
350+
* @param {Buffer|string} multihash
351+
* @param {Object} data
352+
* @param {Object} [options={}]
353+
* @param {function(Error)} callback
354+
* @returns {Promise<undefined>|undefined}
355+
*
356+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchappenddata
357+
*/
317358
appendData (multihash, data, options, callback) {
318359
editAndSave((node, cb) => {
319360
const newData = Buffer.concat([node.data, data])
320361
DAGNode.create(newData, node.links, cb)
321362
})(multihash, options, callback)
322363
},
323364

365+
/**
366+
* @alias object.patch.setData
367+
* @memberof IPFS#
368+
* @method
369+
* @param {Buffer|string} multihash
370+
* @param {Object} data
371+
* @param {Object} [options={}]
372+
* @param {function(Error)} callback
373+
* @returns {Promise<undefined>|undefined}
374+
*
375+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchsetdata
376+
*/
324377
setData (multihash, data, options, callback) {
325378
editAndSave((node, cb) => {
326379
DAGNode.create(data, node.links, cb)
327380
})(multihash, options, callback)
328381
}
329-
})
382+
}
330383
}
331384
}

src/core/components/version.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = function version (self) {
1010
* @method
1111
* @param {function(Error, IPFS#Version)} callback
1212
* @returns {Promise<IPFS#Version>|undefined}
13+
*
14+
* @see https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id
1315
*/
1416
return promisify((opts, callback) => {
1517
if (typeof opts === 'function') {

src/core/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ exports = module.exports = IPFS
2828

2929
/**
3030
* The core IPFS component.
31+
*
32+
* @example
33+
* const IPFS = require('ipfs')
34+
* // IPFS will need a repo, it can create one for you or you can pass
35+
* // it a repo instance of the type IPFS Repo
36+
* // https://github.com/ipfs/js-ipfs-repo
37+
* const repo = ipfsRepoOrPath
38+
*
39+
* // Create the IPFS node instance
40+
* const node = new IPFS(repo)
41+
*
42+
* // We need to init our repo, in this case the repo was empty
43+
* // We are picking 2048 bits for the RSA key that will be our PeerId
44+
* node.init({ emptyRepo: true, bits: 2048 }, (err) => {
45+
* if (err) { throw err }
46+
*
47+
* // Once the repo is initiated, we have to load it so that the IPFS
48+
* // instance has its config values. This is useful when you have
49+
* // previous created repos and you don't need to generate a new one
50+
* node.load((err) => {
51+
* if (err) { throw err }
52+
*
53+
* // Last but not the least, we want our IPFS node to use its peer
54+
* // connections to fetch and serve blocks from.
55+
* node.goOnline((err) => {
56+
* if (err) { throw err }
57+
* // Here you should be good to go and call any IPFS function
58+
* })
59+
* })
60+
*
3161
*/
3262
class IPFS {
3363
/**

0 commit comments

Comments
 (0)