From ef49e95746af28405b5c4d882dae1c838eb7cb99 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 24 Oct 2018 13:20:24 +0100 Subject: [PATCH 1/6] feat: ipns over pubsub (#846) --- README.md | 3 +++ package.json | 2 +- src/name/index.js | 3 ++- src/name/pubsub/cancel.js | 24 ++++++++++++++++++++++++ src/name/pubsub/index.js | 7 +++++++ src/name/pubsub/state.js | 23 +++++++++++++++++++++++ src/name/pubsub/subs.js | 21 +++++++++++++++++++++ test/interface.spec.js | 21 +++++++++++++++++++++ 8 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/name/pubsub/cancel.js create mode 100644 src/name/pubsub/index.js create mode 100644 src/name/pubsub/state.js create mode 100644 src/name/pubsub/subs.js diff --git a/README.md b/README.md index 914f9aac6..b50218380 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,9 @@ const ipfs = IpfsApi({ - [name](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md) - [`ipfs.name.publish(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepublish) + - [`ipfs.name.pubsub.cancel(arg, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubcancel) + - [`ipfs.name.pubsub.state([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubstate) + - [`ipfs.name.pubsub.subs([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#namepubsubsubs) - [`ipfs.name.resolve(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/NAME.md#nameresolve) #### Node Management diff --git a/package.json b/package.json index 77ec25ef2..0f3637d56 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "eslint-plugin-react": "^7.10.0", "go-ipfs-dep": "~0.4.17", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.78.0", + "interface-ipfs-core": "~0.80.0", "ipfsd-ctl": "~0.39.0", "pull-stream": "^3.6.8", "socket.io": "^2.1.1", diff --git a/src/name/index.js b/src/name/index.js index 811357b7c..8f823311a 100644 --- a/src/name/index.js +++ b/src/name/index.js @@ -7,6 +7,7 @@ module.exports = (arg) => { return { publish: require('./publish')(send), - resolve: require('./resolve')(send) + resolve: require('./resolve')(send), + pubsub: require('./pubsub')(send) } } diff --git a/src/name/pubsub/cancel.js b/src/name/pubsub/cancel.js new file mode 100644 index 000000000..32dbbb3af --- /dev/null +++ b/src/name/pubsub/cancel.js @@ -0,0 +1,24 @@ +'use strict' + +const promisify = require('promisify-es6') + +const transform = function (res, callback) { + callback(null, { + canceled: res.Canceled === undefined || res.Canceled === true + }) +} + +module.exports = (send) => { + return promisify((args, opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + + send.andTransform({ + path: 'name/pubsub/cancel', + args: args, + qs: opts + }, transform, callback) + }) +} diff --git a/src/name/pubsub/index.js b/src/name/pubsub/index.js new file mode 100644 index 000000000..aefc0f880 --- /dev/null +++ b/src/name/pubsub/index.js @@ -0,0 +1,7 @@ +'use strict' + +module.exports = (send) => ({ + cancel: require('./cancel')(send), + state: require('./state')(send), + subs: require('./subs')(send) +}) diff --git a/src/name/pubsub/state.js b/src/name/pubsub/state.js new file mode 100644 index 000000000..cc9b0b369 --- /dev/null +++ b/src/name/pubsub/state.js @@ -0,0 +1,23 @@ +'use strict' + +const promisify = require('promisify-es6') + +const transform = function (res, callback) { + callback(null, { + enabled: res.Enabled + }) +} + +module.exports = (send) => { + return promisify((opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + + send.andTransform({ + path: 'name/pubsub/state', + qs: opts + }, transform, callback) + }) +} diff --git a/src/name/pubsub/subs.js b/src/name/pubsub/subs.js new file mode 100644 index 000000000..3a3a54c2a --- /dev/null +++ b/src/name/pubsub/subs.js @@ -0,0 +1,21 @@ +'use strict' + +const promisify = require('promisify-es6') + +const transform = function (res, callback) { + callback(null, res.Strings || []) +} + +module.exports = (send) => { + return promisify((opts, callback) => { + if (typeof (opts) === 'function') { + callback = opts + opts = {} + } + + send.andTransform({ + path: 'name/pubsub/subs', + qs: opts + }, transform, callback) + }) +} diff --git a/test/interface.spec.js b/test/interface.spec.js index 30fe04a92..04e1dd303 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -183,6 +183,27 @@ describe('interface-ipfs-core tests', () => { ] }) + // TODO: uncomment after https://github.com/ipfs/interface-ipfs-core/pull/361 being merged and a new release + tests.namePubsub(CommonFactory.create({ + spawnOptions: { + args: ['--enable-namesys-pubsub'], + initOptions: { bits: 1024 } + } + }), { + skip: [ + // name.pubsub.cancel + { + name: 'should cancel a subscription correctly returning true', + reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' + }, + // name.pubsub.subs + { + name: 'should get the list of subscriptions updated after a resolve', + reason: 'go-ipfs is really slow for publishing and resolving ipns records, unless in offline mode' + } + ] + }) + tests.object(defaultCommonFactory) tests.pin(defaultCommonFactory) From c53437572da0e1fd3f24c463347504ac2b8c49eb Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Mon, 29 Oct 2018 17:38:30 +0100 Subject: [PATCH 2/6] chore: remove ipld formats re-export (#872) Prior to this change the `ipld-dag-cbor` and `ipld-dag-pb` modules are re-exported so that can be accessed within the Browser bundle. Those modules normally don't need to be used directly, they are kind of implementation details of IPLD. Hence remove them. BREAKING CHANGE: remove `types.dagCBOR` and `types.dagPB` from public API If you need the `ipld-dag-cbor` or `ipld-dag-pb` module in the Browser, you need to bundle them yourself. --- src/types.js | 4 ---- test/types.spec.js | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/types.js b/src/types.js index a6ae650c4..39c80c50b 100644 --- a/src/types.js +++ b/src/types.js @@ -1,8 +1,6 @@ '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') @@ -12,8 +10,6 @@ const PeerInfo = require('peer-info') module.exports = () => ({ Buffer: Buffer, CID: CID, - dagPB: dagPB, - dagCBOR: dagCBOR, multiaddr: multiaddr, multibase: multibase, multihash: multihash, diff --git a/test/types.spec.js b/test/types.spec.js index 49b68a5ef..b27adf6da 100644 --- a/test/types.spec.js +++ b/test/types.spec.js @@ -3,8 +3,6 @@ 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') @@ -47,9 +45,7 @@ describe('.types', function () { multiaddr: multiaddr, multibase: multibase, multihash: multihash, - CID: CID, - dagPB: dagPB, - dagCBOR: dagCBOR + CID: CID }) }) }) From 0652ac0e21f2ab80bd9e9f7333730e413b35cbeb Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 25 Oct 2018 16:25:06 +0200 Subject: [PATCH 3/6] chore: update to ipld-dag-cbor 0.13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No further changes are needed as js-ipfs-api is getting the raw blocks from IPFS and does the whole parsing client-sided in JavaScript. BREAKING CHANGE: dag-cbor nodes now represent links as CID objects The API for [dag-cbor](https://github.com/ipld/js-ipld-dag-cbor) changed. Links are no longer represented as JSON objects (`{"/": "base-encoded-cid"}`, but as [CID objects](https://github.com/ipld/js-cid). `ipfs.dag.get()` and now always return links as CID objects. `ipfs.dag.put()` also expects links to be represented as CID objects. The old-style JSON objects representation is still supported, but deprecated. Prior to this change: ```js const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') // Link as JSON object representation const putCid = await ipfs.dag.put({link: {'/': cid.toBaseEncodedString()}}) const result = await ipfs.dag.get(putCid) console.log(result.value) ``` Output: ```js { link: { '/': } } ``` Now: ```js const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') // Link as CID object const putCid = await ipfs.dag.put({link: cid}) const result = await ipfs.dag.get(putCid) console.log(result.value) ``` Output: ```js { link: CID { codec: 'dag-pb', version: 0, multihash: } } ``` See https://github.com/ipld/ipld/issues/44 for more information on why this change was made. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f3637d56..6a214ca42 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "glob": "^7.1.2", "ipfs-block": "~0.7.1", "ipfs-unixfs": "~0.1.15", - "ipld-dag-cbor": "~0.12.1", + "ipld-dag-cbor": "~0.13.0", "ipld-dag-pb": "~0.14.6", "is-ipfs": "~0.4.2", "is-pull-stream": "0.0.0", @@ -82,7 +82,7 @@ "eslint-plugin-react": "^7.10.0", "go-ipfs-dep": "~0.4.17", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.80.0", + "interface-ipfs-core": "~0.81.0", "ipfsd-ctl": "~0.39.0", "pull-stream": "^3.6.8", "socket.io": "^2.1.1", From 979d8b518951697cdcf3acc18d22dbcedc9cdf8a Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Tue, 30 Oct 2018 14:47:14 +0000 Subject: [PATCH 4/6] fix: add missing and remove unused dependencies (#879) --- package.json | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 6a214ca42..db0ac5cb6 100644 --- a/package.json +++ b/package.json @@ -23,47 +23,50 @@ "release-minor": "aegir release --type minor ", "release-major": "aegir release --type major ", "coverage": "aegir coverage --timeout 100000", - "coverage-publish": "aegir coverage --provider coveralls --timeout 100000" + "coverage-publish": "aegir coverage --provider coveralls --timeout 100000", + "dep-check": "npx dependency-check package.json './test/**/*.js' './src/**/*.js'" }, "dependencies": { "async": "^2.6.1", - "big.js": "^5.1.2", - "bl": "^2.0.1", + "big.js": "^5.2.2", + "bl": "^2.1.2", "bs58": "^4.0.1", - "cids": "~0.5.3", + "cids": "~0.5.5", "concat-stream": "^1.6.2", - "debug": "^3.1.0", - "detect-node": "^2.0.3", + "debug": "^4.1.0", + "detect-node": "^2.0.4", + "end-of-stream": "^1.4.1", "flatmap": "0.0.3", - "glob": "^7.1.2", - "ipfs-block": "~0.7.1", - "ipfs-unixfs": "~0.1.15", + "glob": "^7.1.3", + "ipfs-block": "~0.8.0", + "ipfs-unixfs": "~0.1.16", "ipld-dag-cbor": "~0.13.0", - "ipld-dag-pb": "~0.14.6", - "is-ipfs": "~0.4.2", + "ipld-dag-pb": "~0.14.11", + "is-ipfs": "~0.4.7", "is-pull-stream": "0.0.0", "is-stream": "^1.1.0", - "libp2p-crypto": "~0.13.0", + "libp2p-crypto": "~0.14.0", "lodash": "^4.17.11", "lru-cache": "^4.1.3", "multiaddr": "^5.0.0", - "multibase": "~0.4.0", - "multihashes": "~0.4.13", + "multibase": "~0.5.0", + "multihashes": "~0.4.14", "ndjson": "^1.5.0", "once": "^1.4.0", - "peer-id": "~0.11.0", + "peer-id": "~0.12.0", "peer-info": "~0.14.1", "promisify-es6": "^1.0.3", - "pull-defer": "~0.2.2", + "pull-defer": "~0.2.3", "pull-pushable": "^2.2.0", "pull-stream-to-stream": "^1.3.4", "pump": "^3.0.0", "qs": "^6.5.2", - "readable-stream": "^2.3.6", + "readable-stream": "^3.0.6", "stream-http": "^3.0.0", "stream-to-pull-stream": "^1.7.2", "streamifier": "~0.1.1", - "tar-stream": "^1.6.1" + "tar-stream": "^1.6.2", + "through2": "^2.0.3" }, "engines": { "node": ">=8.0.0", @@ -74,19 +77,17 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^15.1.0", + "aegir": "^17.0.1", "browser-process-platform": "~0.1.1", - "chai": "^4.1.2", + "chai": "^4.2.0", "cross-env": "^5.2.0", "dirty-chai": "^2.0.1", - "eslint-plugin-react": "^7.10.0", + "eslint-plugin-react": "^7.11.1", "go-ipfs-dep": "~0.4.17", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.81.0", - "ipfsd-ctl": "~0.39.0", - "pull-stream": "^3.6.8", - "socket.io": "^2.1.1", - "socket.io-client": "^2.1.1", + "interface-ipfs-core": "~0.83.0", + "ipfsd-ctl": "~0.39.5", + "pull-stream": "^3.6.9", "stream-equal": "^1.1.1" }, "keywords": [ From 3f927a99cb6837c374e0e336e6762e6e322f163c Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 30 Oct 2018 16:53:48 +0000 Subject: [PATCH 5/6] chore: update contributors --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index db0ac5cb6..4a6e79c40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-api", - "version": "25.0.0", + "version": "26.0.0", "description": "A client library for the IPFS HTTP API", "leadMaintainer": "Alan Shaw ", "main": "src/index.js", @@ -120,6 +120,7 @@ "Harlan T Wood ", "Henrique Dias ", "Holodisc ", + "Hugo Dias ", "JGAntunes ", "Jacob Heun ", "James Halliday ", @@ -155,8 +156,8 @@ "Tara Vancil ", "Travis Person ", "Travis Person ", - "Vasco Santos ", "Vasco Santos ", + "Vasco Santos ", "Victor Bjelkholm ", "Volker Mische ", "dmitriy ryajov ", From 9eaaea32620af9d68d72db99a2e3e70630659eb6 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 30 Oct 2018 16:53:48 +0000 Subject: [PATCH 6/6] chore: release version v26.0.0 --- CHANGELOG.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 159d27d01..87ac8177a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,83 @@ + +# [26.0.0](https://github.com/ipfs/js-ipfs-api/compare/v25.0.0...v26.0.0) (2018-10-30) + + +### Bug Fixes + +* add missing and remove unused dependencies ([#879](https://github.com/ipfs/js-ipfs-api/issues/879)) ([979d8b5](https://github.com/ipfs/js-ipfs-api/commit/979d8b5)) + + +### Chores + +* remove ipld formats re-export ([#872](https://github.com/ipfs/js-ipfs-api/issues/872)) ([c534375](https://github.com/ipfs/js-ipfs-api/commit/c534375)) +* update to ipld-dag-cbor 0.13 ([0652ac0](https://github.com/ipfs/js-ipfs-api/commit/0652ac0)) + + +### Features + +* ipns over pubsub ([#846](https://github.com/ipfs/js-ipfs-api/issues/846)) ([ef49e95](https://github.com/ipfs/js-ipfs-api/commit/ef49e95)) + + +### BREAKING CHANGES + +* dag-cbor nodes now represent links as CID objects + +The API for [dag-cbor](https://github.com/ipld/js-ipld-dag-cbor) changed. +Links are no longer represented as JSON objects (`{"/": "base-encoded-cid"}`, +but as [CID objects](https://github.com/ipld/js-cid). `ipfs.dag.get()` and +now always return links as CID objects. `ipfs.dag.put()` also expects links +to be represented as CID objects. The old-style JSON objects representation +is still supported, but deprecated. + +Prior to this change: + +```js +const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') +// Link as JSON object representation +const putCid = await ipfs.dag.put({link: {'/': cid.toBaseEncodedString()}}) +const result = await ipfs.dag.get(putCid) +console.log(result.value) + +``` + +Output: + +```js +{ link: + { '/': + } } +``` + +Now: + +```js +const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5') +// Link as CID object +const putCid = await ipfs.dag.put({link: cid}) +const result = await ipfs.dag.get(putCid) +console.log(result.value) +``` + +Output: + +```js +{ link: + CID { + codec: 'dag-pb', + version: 0, + multihash: + } } +``` + +See https://github.com/ipld/ipld/issues/44 for more information on why this +change was made. +* remove `types.dagCBOR` and `types.dagPB` from public API + +If you need the `ipld-dag-cbor` or `ipld-dag-pb` module in the Browser, +you need to bundle them yourself. + + + # [25.0.0](https://github.com/ipfs/js-ipfs-api/compare/v24.0.2...v25.0.0) (2018-10-15)