Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 1c3d92a

Browse files
committed
feat: add methods for listing config profiles
New method: ```javascript Promise<Array<{ name, description }>> 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 ipfs/js-ipfs#2506 for discussion.
1 parent 55e64d4 commit 1c3d92a

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"bl": "^3.0.0",
4949
"bs58": "^4.0.1",
5050
"buffer": "^5.4.2",
51+
"callbackify": "^1.1.0",
5152
"cids": "~0.7.1",
5253
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
5354
"debug": "^4.1.0",
@@ -109,7 +110,7 @@
109110
"cross-env": "^6.0.0",
110111
"dirty-chai": "^2.0.1",
111112
"go-ipfs-dep": "^0.4.22",
112-
"interface-ipfs-core": "^0.115.0",
113+
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#add-listing-config-profiles",
113114
"ipfsd-ctl": "^0.47.1",
114115
"nock": "^11.3.2",
115116
"stream-equal": "^1.1.1"

src/config/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

3-
const moduleConfig = require('../utils/module-config')
4-
5-
module.exports = (arg) => {
6-
const send = moduleConfig(arg)
7-
3+
module.exports = (send, config) => {
84
return {
95
get: require('./get')(send),
106
set: require('./set')(send),
117
replace: require('./replace')(send),
12-
profile: require('./profile')(send)
8+
profiles: {
9+
apply: require('./profiles/apply')(send),
10+
list: require('./profiles/list')(config)
11+
}
1312
}
1413
}

src/config/profile.js src/config/profiles/apply.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = (send) => {
2727
if (err) {
2828
return callback(err)
2929
}
30-
callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg })
30+
callback(null, { old: response.OldCfg, new: response.NewCfg })
3131
})
3232
})
3333
}

src/config/profiles/list.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const configure = require('../../lib/configure')
4+
const callbackify = require('callbackify')
5+
const toCamel = require('../../lib/object-to-camel')
6+
7+
module.exports = configure(({ ky }) => {
8+
return callbackify.variadic(async (options) => {
9+
options = options || {}
10+
11+
const searchParams = new URLSearchParams(options.searchParams)
12+
searchParams.set('stream-channels', true)
13+
14+
const res = await ky.get('config/profile/list', {
15+
timeout: options.timeout,
16+
signal: options.signal,
17+
headers: options.headers,
18+
searchParams
19+
})
20+
21+
const parsed = await res.json()
22+
23+
return parsed
24+
.map(profile => toCamel(profile))
25+
})
26+
})

test/interface.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ describe('interface-ipfs-core tests', () => {
4848
{
4949
name: 'replace',
5050
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'
51+
},
52+
{
53+
name: 'should list config profiles',
54+
reason: 'TODO: Not implemented in go-ipfs'
5155
}
5256
]
5357
})

0 commit comments

Comments
 (0)