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)