From b650e6c9e1bdd82130228a1e921974d725e72783 Mon Sep 17 00:00:00 2001 From: Clemo Date: Tue, 3 Apr 2018 08:20:14 +0200 Subject: [PATCH 01/14] docs: Update README.md (#728) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e9a92a14..e7b7b05f1 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P - [`ipfs.repo.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/REPO.md#version) - [key](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md) - - [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md#javascript---ipfskeygenname-options-callback) + - [`ipfs.key.gen(name, options, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md#javascript---ipfskeygenname-options-callback) - [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md#javascript---ipfskeylistcallback) - [`ipfs.key.rm(name, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md#javascript---ipfskeyrmname-callback) - [`ipfs.key.rename(oldName, newName, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/KEY.md#javascript---ipfskeyrenameoldname-newname-callback) From 41d32e302372bb5a1b2bd36a439bdada0404fa12 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 3 Apr 2018 16:12:07 +0100 Subject: [PATCH 02/14] feat: public-readonly-method-for-getting-host-and-port Closes #580 --- README.md | 6 ++++++ src/index.js | 2 +- src/util/get-endpoint-config.js | 8 ++++++++ src/utils/load-commands.js | 9 +++++---- test/util.spec.js | 9 +++++++++ 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/util/get-endpoint-config.js diff --git a/README.md b/README.md index e7b7b05f1..392423ced 100644 --- a/README.md +++ b/README.md @@ -372,6 +372,12 @@ ipfs.util.addFromStream(, (err, result) => { }) ``` +##### Get endpoint configuration (host and port) + +> `ipfs.util.getEndpointConfig()` + +This returns an object containing the `host` and the `port` + ### Callbacks and Promises If you do not pass in a callback all API functions will return a `Promise`. For example: diff --git a/src/index.js b/src/index.js index b56a521a9..70ed59097 100644 --- a/src/index.js +++ b/src/index.js @@ -36,7 +36,7 @@ function IpfsAPI (hostOrMultiaddr, port, opts) { } const requestAPI = sendRequest(config) - const cmds = loadCommands(requestAPI) + const cmds = loadCommands(requestAPI, config) cmds.send = requestAPI cmds.Buffer = Buffer diff --git a/src/util/get-endpoint-config.js b/src/util/get-endpoint-config.js new file mode 100644 index 000000000..7598239ee --- /dev/null +++ b/src/util/get-endpoint-config.js @@ -0,0 +1,8 @@ +'use strict' + +module.exports = (config) => { + return () => ({ + host: config.host, + port: config.port + }) +} diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js index e86982e18..e9494055e 100644 --- a/src/utils/load-commands.js +++ b/src/utils/load-commands.js @@ -55,11 +55,12 @@ function requireCommands () { return files } - cmds.util = function (send) { + cmds.util = function (send, config) { const util = { addFromFs: require('../util/fs-add')(send), addFromStream: require('../files/add')(send), - addFromURL: require('../util/url-add')(send) + addFromURL: require('../util/url-add')(send), + getEndpointConfig: require('../util/get-endpoint-config')(config) } return util } @@ -67,12 +68,12 @@ function requireCommands () { return cmds } -function loadCommands (send) { +function loadCommands (send, config) { const files = requireCommands() const cmds = {} Object.keys(files).forEach((file) => { - cmds[file] = files[file](send) + cmds[file] = files[file](send, config) }) return cmds diff --git a/test/util.spec.js b/test/util.spec.js index 766fd3a65..0c15f3347 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -156,4 +156,13 @@ describe('.util', () => { .then(out => expectTimeout(ipfs.object.get(out[0].hash), 4000)) }) }) + + describe('.getEndpointConfig', () => { + it('should return the endpoint configured host and port', function () { + const endpoint = ipfs.util.getEndpointConfig() + + expect(endpoint).to.have.property('host') + expect(endpoint).to.have.property('port') + }) + }) }) From 9463d3a52ce8ab13e0ae9686a3e9308d373a28fc Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 9 Mar 2017 16:06:32 +0000 Subject: [PATCH 03/14] feat: dag.put --- package.json | 1 + src/dag/dag.js | 79 ++++++++++++++++++++++++++++++++++++++ test/interface/dag.spec.js | 34 ++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/dag/dag.js create mode 100644 test/interface/dag.spec.js diff --git a/package.json b/package.json index 0fabfe21c..9e86be21d 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "glob": "^7.1.2", "ipfs-block": "~0.6.1", "ipfs-unixfs": "~0.1.14", + "ipld-dag-cbor": "^0.12.0", "ipld-dag-pb": "~0.13.1", "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", diff --git a/src/dag/dag.js b/src/dag/dag.js new file mode 100644 index 000000000..ab81f041c --- /dev/null +++ b/src/dag/dag.js @@ -0,0 +1,79 @@ +'use strict' + +const dagPB = require('ipld-dag-pb') +const dagCBOR = require('ipld-dag-cbor') +const promisify = require('promisify-es6') +const CID = require('cids') +const multihash = require('multihashes') + +function noop () {} + +module.exports = (send) => { + const api = { + put: promisify((dagNode, options, callback) => { + if (typeof options === 'function') { + return setImmediate(() => callback(new Error('no options were passed'))) + } + + callback = callback || noop + + let hashAlg = options.hashAlg || 'sha2-256' + let format + let inputEnc + + if (options.cid && CID.isCID(options.cid)) { + format = options.cid.codec + hashAlg = multihash.decode(options.cid.multihash).name + prepare() + } else if (options.format) { + format = options.format + prepare() + } else { + callback(new Error('Invalid arguments')) + } + + function prepare () { + if (format === 'dag-cbor') { + // TODO change this once + // https://github.com/ipfs/go-ipfs/issues/3771 is finished + format = 'cbor' + + inputEnc = 'cbor' + dagCBOR.util.serialize(dagNode, finalize) + } + if (format === 'dag-pb') { + // TODO change this once + // https://github.com/ipfs/go-ipfs/issues/3771 is finished + format = 'protobuf' + + inputEnc = 'protobuf' + dagPB.util.serialize(dagNode, finalize) + } + } + + function finalize (err, serialized) { + if (err) { return callback(err) } + + send({ + path: 'dag/put', + qs: { + hashAlg: hashAlg, // not implemented in go yet https://github.com/ipfs/go-ipfs/issues/3771 + format: format, + inputenc: inputEnc + }, + files: serialized + }, (err, result) => { + if (err) { + return callback(err) + } + // TODO handle the result + }) + } + }), + get: promisify((cid, path, options, callback) => { + // TODO + }) + } + + return api +} diff --git a/test/interface/dag.spec.js b/test/interface/dag.spec.js new file mode 100644 index 000000000..6c68680e7 --- /dev/null +++ b/test/interface/dag.spec.js @@ -0,0 +1,34 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + +const IPFSApi = require('../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create() + +const nodes = [] +const common = { + setup: function (callback) { + callback(null, { + spawnNode: (cb) => { + df.spawn((err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, IPFSApi(_ipfsd.apiAddr)) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) + } +} + +test.dag(common) From 93a9af913dfd9b99d3366e41c25e47deff5f03ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Tenorio-Forn=C3=A9s?= Date: Sat, 24 Jun 2017 13:19:10 +0200 Subject: [PATCH 04/14] Feat(dag): DAG api (#568) * Implement dag.get * Handle dag put response, enable CIDs for dag get and fix dag get request param --- src/dag/dag.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/dag/dag.js b/src/dag/dag.js index ab81f041c..6e86f62e8 100644 --- a/src/dag/dag.js +++ b/src/dag/dag.js @@ -66,12 +66,53 @@ module.exports = (send) => { if (err) { return callback(err) } - // TODO handle the result + if (result.Cid) { + return callback(null, new CID(result.Cid['/'])) + } else { + return callback(result) + } }) } }), get: promisify((cid, path, options, callback) => { - // TODO + if (typeof path === 'function') { + callback = path + path = undefined + } + + if (typeof options === 'function') { + callback = options + options = {} + } + + options = options || {} + + if (CID.isCID(cid)) { + cid = cid.toBaseEncodedString() + } + + if (typeof cid === 'string') { + const split = cid.split('/') + cid = split[0] + split.shift() + + if (split.length > 0) { + path = split.join('/') + } else { + path = '/' + } + } + + send({ + path: 'dag/get', + args: cid + '/' + path, + qs: options + }, (err, result) => { + if (err) { + return callback(err) + } + callback(undefined, {value: result}) + }) }) } From 9bf1c6c1921caec611faefdabee94d13cdf4d3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 11 Aug 2017 23:37:13 +0200 Subject: [PATCH 05/14] feat(dag): update option names to reflect go-ipfs API --- src/dag/dag.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/dag/dag.js b/src/dag/dag.js index 6e86f62e8..4acf0ae36 100644 --- a/src/dag/dag.js +++ b/src/dag/dag.js @@ -17,7 +17,7 @@ module.exports = (send) => { callback = callback || noop - let hashAlg = options.hashAlg || 'sha2-256' + let hashAlg = options.hash || 'sha2-256' let format let inputEnc @@ -33,20 +33,12 @@ module.exports = (send) => { } function prepare () { - if (format === 'dag-cbor') { - // TODO change this once - // https://github.com/ipfs/go-ipfs/issues/3771 is finished - format = 'cbor' + inputEnc = 'raw' - inputEnc = 'cbor' + if (format === 'dag-cbor') { dagCBOR.util.serialize(dagNode, finalize) } if (format === 'dag-pb') { - // TODO change this once - // https://github.com/ipfs/go-ipfs/issues/3771 is finished - format = 'protobuf' - - inputEnc = 'protobuf' dagPB.util.serialize(dagNode, finalize) } } @@ -57,9 +49,9 @@ module.exports = (send) => { send({ path: 'dag/put', qs: { - hashAlg: hashAlg, // not implemented in go yet https://github.com/ipfs/go-ipfs/issues/3771 + hash: hashAlg, format: format, - inputenc: inputEnc + 'input-enc': inputEnc }, files: serialized }, (err, result) => { From 7ba0343a5ccf8db41bc038f41b829ee09b2d0ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 13 Aug 2017 18:38:45 +0200 Subject: [PATCH 06/14] feat(dag): proper get implementation --- src/dag/dag.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/dag/dag.js b/src/dag/dag.js index 4acf0ae36..666437ed6 100644 --- a/src/dag/dag.js +++ b/src/dag/dag.js @@ -5,6 +5,7 @@ const dagCBOR = require('ipld-dag-cbor') const promisify = require('promisify-es6') const CID = require('cids') const multihash = require('multihashes') +const block = require('./block') function noop () {} @@ -96,14 +97,28 @@ module.exports = (send) => { } send({ - path: 'dag/get', + path: 'dag/resolve', args: cid + '/' + path, qs: options - }, (err, result) => { + }, (err, resolved) => { if (err) { return callback(err) } - callback(undefined, {value: result}) + + let resolvedCid = new CID(resolved['Cid']['/']) + + block(send).get(resolvedCid, (err, blk) => { + if (err) { + return callback(err) + } + + if (resolvedCid.codec === 'dag-cbor') { + dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback) + } + if (resolvedCid.codec === 'dag-pb') { + dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback) + } + }) }) }) } From ad9eab86676ac510cd63b4524e70d4f5a627fc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 13 Aug 2017 20:40:10 +0200 Subject: [PATCH 07/14] feat(dag): rebase, use waterfall for put --- src/dag/dag.js | 127 ------------------------------------- src/dag/get.js | 61 ++++++++++++++++++ src/dag/index.js | 12 ++++ src/dag/put.js | 68 ++++++++++++++++++++ src/utils/load-commands.js | 1 + 5 files changed, 142 insertions(+), 127 deletions(-) delete mode 100644 src/dag/dag.js create mode 100644 src/dag/get.js create mode 100644 src/dag/index.js create mode 100644 src/dag/put.js diff --git a/src/dag/dag.js b/src/dag/dag.js deleted file mode 100644 index 666437ed6..000000000 --- a/src/dag/dag.js +++ /dev/null @@ -1,127 +0,0 @@ -'use strict' - -const dagPB = require('ipld-dag-pb') -const dagCBOR = require('ipld-dag-cbor') -const promisify = require('promisify-es6') -const CID = require('cids') -const multihash = require('multihashes') -const block = require('./block') - -function noop () {} - -module.exports = (send) => { - const api = { - put: promisify((dagNode, options, callback) => { - if (typeof options === 'function') { - return setImmediate(() => callback(new Error('no options were passed'))) - } - - callback = callback || noop - - let hashAlg = options.hash || 'sha2-256' - let format - let inputEnc - - if (options.cid && CID.isCID(options.cid)) { - format = options.cid.codec - hashAlg = multihash.decode(options.cid.multihash).name - prepare() - } else if (options.format) { - format = options.format - prepare() - } else { - callback(new Error('Invalid arguments')) - } - - function prepare () { - inputEnc = 'raw' - - if (format === 'dag-cbor') { - dagCBOR.util.serialize(dagNode, finalize) - } - if (format === 'dag-pb') { - dagPB.util.serialize(dagNode, finalize) - } - } - - function finalize (err, serialized) { - if (err) { return callback(err) } - - send({ - path: 'dag/put', - qs: { - hash: hashAlg, - format: format, - 'input-enc': inputEnc - }, - files: serialized - }, (err, result) => { - if (err) { - return callback(err) - } - if (result.Cid) { - return callback(null, new CID(result.Cid['/'])) - } else { - return callback(result) - } - }) - } - }), - get: promisify((cid, path, options, callback) => { - if (typeof path === 'function') { - callback = path - path = undefined - } - - if (typeof options === 'function') { - callback = options - options = {} - } - - options = options || {} - - if (CID.isCID(cid)) { - cid = cid.toBaseEncodedString() - } - - if (typeof cid === 'string') { - const split = cid.split('/') - cid = split[0] - split.shift() - - if (split.length > 0) { - path = split.join('/') - } else { - path = '/' - } - } - - send({ - path: 'dag/resolve', - args: cid + '/' + path, - qs: options - }, (err, resolved) => { - if (err) { - return callback(err) - } - - let resolvedCid = new CID(resolved['Cid']['/']) - - block(send).get(resolvedCid, (err, blk) => { - if (err) { - return callback(err) - } - - if (resolvedCid.codec === 'dag-cbor') { - dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback) - } - if (resolvedCid.codec === 'dag-pb') { - dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback) - } - }) - }) - }) - } - - return api -} diff --git a/src/dag/get.js b/src/dag/get.js new file mode 100644 index 000000000..af3fa55e7 --- /dev/null +++ b/src/dag/get.js @@ -0,0 +1,61 @@ +'use strict' + +const dagPB = require('ipld-dag-pb') +const dagCBOR = require('ipld-dag-cbor') +const promisify = require('promisify-es6') +const CID = require('cids') +const waterfall = require('async/waterfall') +const block = require('../block') + +module.exports = (send) => { + return promisify((cid, path, options, callback) => { + if (typeof path === 'function') { + callback = path + path = undefined + } + + if (typeof options === 'function') { + callback = options + options = {} + } + + options = options || {} + + if (CID.isCID(cid)) { + cid = cid.toBaseEncodedString() + } + + if (typeof cid === 'string') { + const split = cid.split('/') + cid = split[0] + split.shift() + + if (split.length > 0) { + path = split.join('/') + } else { + path = '/' + } + } + + waterfall([ + cb => { + send({ + path: 'dag/resolve', + args: cid + '/' + path, + qs: options + }, cb) + }, + (resolved, cb) => { + block(send).get(new CID(resolved['Cid']['/']), (err, blk) => cb(err, blk, resolved['RemPath'])) + }, + (blk, path, cb) => { + if (blk.cid.codec === 'dag-cbor') { + dagCBOR.resolver.resolve(blk, path, cb) + } + if (blk.cid.codec === 'dag-pb') { + dagPB.resolver.resolve(blk, path, cb) + } + } + ], callback) + }) +} diff --git a/src/dag/index.js b/src/dag/index.js new file mode 100644 index 000000000..bb6b1333c --- /dev/null +++ b/src/dag/index.js @@ -0,0 +1,12 @@ +'use strict' + +const moduleConfig = require('../utils/module-config') + +module.exports = (arg) => { + const send = moduleConfig(arg) + + return { + get: require('./get')(send), + put: require('./put')(send) + } +} diff --git a/src/dag/put.js b/src/dag/put.js new file mode 100644 index 000000000..ee67261b6 --- /dev/null +++ b/src/dag/put.js @@ -0,0 +1,68 @@ +'use strict' + +const dagPB = require('ipld-dag-pb') +const dagCBOR = require('ipld-dag-cbor') +const promisify = require('promisify-es6') +const CID = require('cids') +const multihash = require('multihashes') + +function noop () {} + +module.exports = (send) => { + return promisify((dagNode, options, callback) => { + if (typeof options === 'function') { + return setImmediate(() => callback(new Error('no options were passed'))) + } + + callback = callback || noop + + let hashAlg = options.hash || 'sha2-256' + let format + let inputEnc + + if (options.cid && CID.isCID(options.cid)) { + format = options.cid.codec + hashAlg = multihash.decode(options.cid.multihash).name + prepare() + } else if (options.format) { + format = options.format + prepare() + } else { + callback(new Error('Invalid arguments')) + } + + function prepare () { + inputEnc = 'raw' + + if (format === 'dag-cbor') { + dagCBOR.util.serialize(dagNode, finalize) + } + if (format === 'dag-pb') { + dagPB.util.serialize(dagNode, finalize) + } + } + + function finalize (err, serialized) { + if (err) { return callback(err) } + + send({ + path: 'dag/put', + qs: { + hash: hashAlg, + format: format, + 'input-enc': inputEnc + }, + files: serialized + }, (err, result) => { + if (err) { + return callback(err) + } + if (result['Cid']) { + return callback(null, new CID(result['Cid']['/'])) + } else { + return callback(result) + } + }) + } + }) +} diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js index e9494055e..4f8bdd7db 100644 --- a/src/utils/load-commands.js +++ b/src/utils/load-commands.js @@ -21,6 +21,7 @@ function requireCommands () { bootstrap: require('../bootstrap'), commands: require('../commands'), config: require('../config'), + dag: require('../dag'), dht: require('../dht'), diag: require('../diag'), id: require('../id'), From d2b203bc71082604c20946530206b7491faa8122 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 22 Feb 2018 14:20:49 +0100 Subject: [PATCH 08/14] fix(dag): path logic for DAG get was wrong --- src/dag/get.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/dag/get.js b/src/dag/get.js index af3fa55e7..989d5373b 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -20,23 +20,12 @@ module.exports = (send) => { } options = options || {} + path = path || '' if (CID.isCID(cid)) { cid = cid.toBaseEncodedString() } - if (typeof cid === 'string') { - const split = cid.split('/') - cid = split[0] - split.shift() - - if (split.length > 0) { - path = split.join('/') - } else { - path = '/' - } - } - waterfall([ cb => { send({ From 2683c7eb33b42acea8aca6e08f02e1348b1d497f Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 22 Feb 2018 14:21:55 +0100 Subject: [PATCH 09/14] fix(dag): js-ipld format resolver take the raw block The js-ipld formats API changed, they now take a raw data block rather than an IPFS block. --- src/dag/get.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dag/get.js b/src/dag/get.js index 989d5373b..ead6a732c 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -35,14 +35,16 @@ module.exports = (send) => { }, cb) }, (resolved, cb) => { - block(send).get(new CID(resolved['Cid']['/']), (err, blk) => cb(err, blk, resolved['RemPath'])) + block(send).get(new CID(resolved['Cid']['/']), (err, ipfsBlock) => { + cb(err, ipfsBlock, resolved['RemPath']) + }) }, - (blk, path, cb) => { - if (blk.cid.codec === 'dag-cbor') { - dagCBOR.resolver.resolve(blk, path, cb) + (ipfsBlock, path, cb) => { + if (ipfsBlock.cid.codec === 'dag-cbor') { + dagCBOR.resolver.resolve(ipfsBlock.data, path, cb) } - if (blk.cid.codec === 'dag-pb') { - dagPB.resolver.resolve(blk, path, cb) + if (ipfsBlock.cid.codec === 'dag-pb') { + dagPB.resolver.resolve(ipfsBlock.data, path, cb) } } ], callback) From 9c37213123d706e1b8f12682b67a861c245f2171 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Fri, 23 Feb 2018 13:22:41 +0100 Subject: [PATCH 10/14] fix(dag): use SendOneFile for dag put There was a refactoring, now the usual way of doing a HTTP request is through SendOneFile. --- src/dag/put.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dag/put.js b/src/dag/put.js index ee67261b6..541c0d512 100644 --- a/src/dag/put.js +++ b/src/dag/put.js @@ -5,10 +5,13 @@ const dagCBOR = require('ipld-dag-cbor') const promisify = require('promisify-es6') const CID = require('cids') const multihash = require('multihashes') +const SendOneFile = require('../utils/send-one-file') function noop () {} module.exports = (send) => { + const sendOneFile = SendOneFile(send, 'dag/put') + return promisify((dagNode, options, callback) => { if (typeof options === 'function') { return setImmediate(() => callback(new Error('no options were passed'))) @@ -44,16 +47,14 @@ module.exports = (send) => { function finalize (err, serialized) { if (err) { return callback(err) } - - send({ - path: 'dag/put', + const sendOptions = { qs: { hash: hashAlg, format: format, 'input-enc': inputEnc - }, - files: serialized - }, (err, result) => { + } + } + sendOneFile(serialized, sendOptions, (err, result) => { if (err) { return callback(err) } From 994bdad73725cb85fece79739e6219ed74d32c45 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 5 Apr 2018 16:05:05 +0100 Subject: [PATCH 11/14] feat: Provide access to bundled libraries when in browser (#732) Close #406 --- README.md | 26 +++++++++++++++++++ package.json | 4 ++- src/index.js | 2 +- src/types.js | 22 ++++++++++++++++ src/utils/load-commands.js | 5 +++- test/types.spec.js | 52 ++++++++++++++++++++++++++++++++++++++ test/util.spec.js | 16 ++++++++++++ 7 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/types.js create mode 100644 test/types.spec.js diff --git a/README.md b/README.md index 392423ced..5b9446a59 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,20 @@ This means: - See https://github.com/ipfs/js-ipfs for details on pubsub in js-ipfs +#### `Domain data types` + +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) + #### `Utility functions` Adding to the methods defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), `js-ipfs-api` exposes a set of extra utility methods. These utility functions are scoped behind the `ipfs.util`. @@ -378,6 +392,18 @@ ipfs.util.addFromStream(, (err, result) => { This returns an object containing the `host` and the `port` +##### Get libp2p crypto primitives + +> `ipfs.util.crypto` + +This contains an object with the crypto primitives + +##### Get is-ipfs utilities + +> `ipfs.util.isIPFS` + +This contains an object with the is-ipfs utilities to help identifying IPFS resources + ### Callbacks and Promises If you do not pass in a callback all API functions will return a `Promise`. For example: diff --git a/package.json b/package.json index 9e86be21d..63cfe8cbb 100644 --- a/package.json +++ b/package.json @@ -36,11 +36,13 @@ "ipfs-block": "~0.6.1", "ipfs-unixfs": "~0.1.14", "ipld-dag-cbor": "^0.12.0", - "ipld-dag-pb": "~0.13.1", + "ipld-dag-pb": "^0.13.1", "is-ipfs": "^0.3.2", "is-stream": "^1.1.0", + "libp2p-crypto": "^0.12.1", "lru-cache": "^4.1.2", "multiaddr": "^3.1.0", + "multibase": "^0.4.0", "multihashes": "~0.4.13", "ndjson": "^1.5.0", "once": "^1.4.0", diff --git a/src/index.js b/src/index.js index 70ed59097..f0f73b782 100644 --- a/src/index.js +++ b/src/index.js @@ -38,7 +38,7 @@ function IpfsAPI (hostOrMultiaddr, port, opts) { const requestAPI = sendRequest(config) const cmds = loadCommands(requestAPI, config) cmds.send = requestAPI - cmds.Buffer = Buffer + cmds.Buffer = Buffer // Added buffer in types (this should be removed once a breaking change is release) return cmds } diff --git a/src/types.js b/src/types.js new file mode 100644 index 000000000..a6ae650c4 --- /dev/null +++ b/src/types.js @@ -0,0 +1,22 @@ +'use strict' + +const CID = require('cids') +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 PeerId = require('peer-id') +const PeerInfo = require('peer-info') + +module.exports = () => ({ + Buffer: Buffer, + CID: CID, + dagPB: dagPB, + dagCBOR: dagCBOR, + multiaddr: multiaddr, + multibase: multibase, + multihash: multihash, + PeerId: PeerId, + PeerInfo: PeerInfo +}) diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js index 4f8bdd7db..ec56d2a11 100644 --- a/src/utils/load-commands.js +++ b/src/utils/load-commands.js @@ -42,6 +42,7 @@ function requireCommands () { pubsub: require('../pubsub'), update: require('../update'), version: require('../version'), + types: require('../types'), dns: require('../dns') } @@ -61,7 +62,9 @@ function requireCommands () { addFromFs: require('../util/fs-add')(send), addFromStream: require('../files/add')(send), addFromURL: require('../util/url-add')(send), - getEndpointConfig: require('../util/get-endpoint-config')(config) + getEndpointConfig: require('../util/get-endpoint-config')(config), + crypto: require('libp2p-crypto'), + isIPFS: require('is-ipfs') } return util } diff --git a/test/types.spec.js b/test/types.spec.js new file mode 100644 index 000000000..5310982ae --- /dev/null +++ b/test/types.spec.js @@ -0,0 +1,52 @@ +/* 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) + +const IPFSApi = require('../src') + +const f = require('./utils/factory') + +describe('.types', function () { + this.timeout(20 * 1000) + + let ipfsd + let ipfs + + before((done) => { + f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => { + expect(err).to.not.exist() + ipfsd = _ipfsd + ipfs = IPFSApi(_ipfsd.apiAddr) + done() + }) + }) + + after((done) => ipfsd.stop(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 + }) + }) +}) diff --git a/test/util.spec.js b/test/util.spec.js index 0c15f3347..09fac4c91 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -165,4 +165,20 @@ describe('.util', () => { expect(endpoint).to.have.property('port') }) }) + + describe('.crypto', () => { + it('should contain the crypto primitives object', function () { + const cripto = ipfs.util.crypto + + expect(cripto).to.exist() + }) + }) + + describe('.isIPFS', () => { + it('should contain the isIPFS utilities object', function () { + const isIPFS = ipfs.util.isIPFS + + expect(isIPFS).to.exist() + }) + }) }) From 160860e8f064557bf33ad6d35e3cf968530365be Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 5 Apr 2018 16:31:33 +0100 Subject: [PATCH 12/14] feat: Wrap with dir (#730) * feat: add awareness of wrapWithDirectory option to utils/send-files-stream * chore: update interface-ipfs-core * chore: update deps --- package.json | 14 +++++++------- src/utils/send-files-stream.js | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 63cfe8cbb..0bbfe0148 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "is-stream": "^1.1.0", "libp2p-crypto": "^0.12.1", "lru-cache": "^4.1.2", - "multiaddr": "^3.1.0", + "multiaddr": "^4.0.0", "multibase": "^0.4.0", "multihashes": "~0.4.13", "ndjson": "^1.5.0", @@ -53,7 +53,7 @@ "pull-pushable": "^2.2.0", "pump": "^3.0.0", "qs": "^6.5.1", - "readable-stream": "^2.3.5", + "readable-stream": "^2.3.6", "stream-http": "^2.8.1", "stream-to-pull-stream": "^1.7.2", "streamifier": "^0.1.1", @@ -76,14 +76,14 @@ "eslint-plugin-react": "^7.7.0", "go-ipfs-dep": "^0.4.14", "gulp": "^3.9.1", - "hapi": "^17.2.3", - "interface-ipfs-core": "~0.58.0", + "hapi": "^17.3.1", + "interface-ipfs-core": "~0.60.1", "ipfs": "~0.28.2", "ipfsd-ctl": "~0.31.0", "pre-commit": "^1.2.2", - "pull-stream": "^3.6.2", - "socket.io": "^2.0.4", - "socket.io-client": "^2.0.4", + "pull-stream": "^3.6.7", + "socket.io": "^2.1.0", + "socket.io-client": "^2.1.0", "stream-equal": "^1.1.1" }, "pre-commit": [ diff --git a/src/utils/send-files-stream.js b/src/utils/send-files-stream.js index e6379c205..46a57e383 100644 --- a/src/utils/send-files-stream.js +++ b/src/utils/send-files-stream.js @@ -78,6 +78,7 @@ module.exports = (send, path) => { qs['cid-version'] = propOrProp(options, 'cid-version', 'cidVersion') qs['raw-leaves'] = propOrProp(options, 'raw-leaves', 'rawLeaves') qs['only-hash'] = propOrProp(options, 'only-hash', 'onlyHash') + qs['wrap-with-directory'] = propOrProp(options, 'wrap-with-directory', 'wrapWithDirectory') qs.hash = propOrProp(options, 'hash', 'hashAlg') const args = { From 21b3bdf03694f8696b359a8ffd1eef6e2a611f63 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 5 Apr 2018 16:33:56 +0100 Subject: [PATCH 13/14] chore: update contributors --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 0bbfe0148..cedcf9d14 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "Alex Mingoia ", "Antonio Tenorio-Fornés ", "Bruno Barbieri ", + "Clemo ", "Connor Keenan ", "Danny ", "David Braun ", @@ -140,6 +141,8 @@ "Stephen Whitmore ", "Tara Vancil ", "Travis Person ", + "Vasco Santos ", + "Vasco Santos ", "Victor Bjelkholm ", "Volker Mische ", "dmitriy ryajov ", @@ -152,6 +155,7 @@ "priecint ", "samuli ", "victorbjelkholm ", + "Łukasz Magiera ", "Łukasz Magiera " ], "license": "MIT", From b644c16a9144298c517b3412c94ccbe54a107f15 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 5 Apr 2018 16:33:57 +0100 Subject: [PATCH 14/14] chore: release version v20.0.0 --- CHANGELOG.md | 23 +++++++++++++++++++++++ package.json | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b93e8b8d4..4925460eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ + +# [20.0.0](https://github.com/ipfs/js-ipfs-api/compare/v19.0.0...v20.0.0) (2018-04-05) + + +### Bug Fixes + +* **dag:** js-ipld format resolver take the raw block ([2683c7e](https://github.com/ipfs/js-ipfs-api/commit/2683c7e)) +* **dag:** path logic for DAG get was wrong ([d2b203b](https://github.com/ipfs/js-ipfs-api/commit/d2b203b)) +* **dag:** use SendOneFile for dag put ([9c37213](https://github.com/ipfs/js-ipfs-api/commit/9c37213)) + + +### Features + +* dag.put ([9463d3a](https://github.com/ipfs/js-ipfs-api/commit/9463d3a)) +* **dag:** proper get implementation ([7ba0343](https://github.com/ipfs/js-ipfs-api/commit/7ba0343)) +* **dag:** rebase, use waterfall for put ([ad9eab8](https://github.com/ipfs/js-ipfs-api/commit/ad9eab8)) +* **dag:** update option names to reflect go-ipfs API ([9bf1c6c](https://github.com/ipfs/js-ipfs-api/commit/9bf1c6c)) +* Provide access to bundled libraries when in browser ([#732](https://github.com/ipfs/js-ipfs-api/issues/732)) ([994bdad](https://github.com/ipfs/js-ipfs-api/commit/994bdad)), closes [#406](https://github.com/ipfs/js-ipfs-api/issues/406) +* public-readonly-method-for-getting-host-and-port ([41d32e3](https://github.com/ipfs/js-ipfs-api/commit/41d32e3)), closes [#580](https://github.com/ipfs/js-ipfs-api/issues/580) +* Wrap with dir ([#730](https://github.com/ipfs/js-ipfs-api/issues/730)) ([160860e](https://github.com/ipfs/js-ipfs-api/commit/160860e)) + + + # [19.0.0](https://github.com/ipfs/js-ipfs-api/compare/v18.2.1...v19.0.0) (2018-03-28) diff --git a/package.json b/package.json index cedcf9d14..d9c45fc7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "19.0.0", + "version": "20.0.0", "description": "A client library for the IPFS HTTP API", "main": "src/index.js", "browser": {