From 1c3d92a17c85fa11dc6fdcb1e37c1e33b34d51d0 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 3 Oct 2019 07:56:43 +0100 Subject: [PATCH] feat: add methods for listing config profiles New method: ```javascript Promise> ipfs.config.profiles.list() ``` BREAKING CHANGE: ```javascript Promise<{oldCfg, newCfg}> ipfs.config.profile(name, opts) // is now Promise<{old, new}> ipfs.config.profiles.apply(name, opts) ``` Possibly contentious; Adds `callbackify` as a dependency, see https://github.com/ipfs/js-ipfs/issues/2506 for discussion. --- package.json | 3 ++- src/config/index.js | 11 ++++----- src/config/{profile.js => profiles/apply.js} | 2 +- src/config/profiles/list.js | 26 ++++++++++++++++++++ test/interface.spec.js | 4 +++ 5 files changed, 38 insertions(+), 8 deletions(-) rename src/config/{profile.js => profiles/apply.js} (91%) create mode 100644 src/config/profiles/list.js diff --git a/package.json b/package.json index 3ded46610..245a63fc4 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "bl": "^3.0.0", "bs58": "^4.0.1", "buffer": "^5.4.2", + "callbackify": "^1.1.0", "cids": "~0.7.1", "concat-stream": "github:hugomrdias/concat-stream#feat/smaller", "debug": "^4.1.0", @@ -109,7 +110,7 @@ "cross-env": "^6.0.0", "dirty-chai": "^2.0.1", "go-ipfs-dep": "^0.4.22", - "interface-ipfs-core": "^0.115.0", + "interface-ipfs-core": "ipfs/interface-js-ipfs-core#add-listing-config-profiles", "ipfsd-ctl": "^0.47.1", "nock": "^11.3.2", "stream-equal": "^1.1.1" diff --git a/src/config/index.js b/src/config/index.js index d690d8099..731df5bcb 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,14 +1,13 @@ 'use strict' -const moduleConfig = require('../utils/module-config') - -module.exports = (arg) => { - const send = moduleConfig(arg) - +module.exports = (send, config) => { return { get: require('./get')(send), set: require('./set')(send), replace: require('./replace')(send), - profile: require('./profile')(send) + profiles: { + apply: require('./profiles/apply')(send), + list: require('./profiles/list')(config) + } } } diff --git a/src/config/profile.js b/src/config/profiles/apply.js similarity index 91% rename from src/config/profile.js rename to src/config/profiles/apply.js index 809adb5d4..b922bbe08 100644 --- a/src/config/profile.js +++ b/src/config/profiles/apply.js @@ -27,7 +27,7 @@ module.exports = (send) => { if (err) { return callback(err) } - callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg }) + callback(null, { old: response.OldCfg, new: response.NewCfg }) }) }) } diff --git a/src/config/profiles/list.js b/src/config/profiles/list.js new file mode 100644 index 000000000..a77fc8af6 --- /dev/null +++ b/src/config/profiles/list.js @@ -0,0 +1,26 @@ +'use strict' + +const configure = require('../../lib/configure') +const callbackify = require('callbackify') +const toCamel = require('../../lib/object-to-camel') + +module.exports = configure(({ ky }) => { + return callbackify.variadic(async (options) => { + options = options || {} + + const searchParams = new URLSearchParams(options.searchParams) + searchParams.set('stream-channels', true) + + const res = await ky.get('config/profile/list', { + timeout: options.timeout, + signal: options.signal, + headers: options.headers, + searchParams + }) + + const parsed = await res.json() + + return parsed + .map(profile => toCamel(profile)) + }) +}) diff --git a/test/interface.spec.js b/test/interface.spec.js index e3c8ffb19..b6f00342e 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -48,6 +48,10 @@ describe('interface-ipfs-core tests', () => { { name: 'replace', reason: 'FIXME Waiting for fix on go-ipfs https://github.com/ipfs/js-ipfs-http-client/pull/307#discussion_r69281789 and https://github.com/ipfs/go-ipfs/issues/2927' + }, + { + name: 'should list config profiles', + reason: 'TODO: Not implemented in go-ipfs' } ] })