|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -const promisify = require('promisify-es6') |
| 3 | +const configure = require('../lib/configure') |
| 4 | +const toCamel = require('../lib/object-to-camel') |
| 5 | + |
| 6 | +module.exports = configure(({ ky }) => { |
| 7 | + return async (key, value, options) => { |
| 8 | + options = options || {} |
4 | 9 |
|
5 |
| -module.exports = (send) => { |
6 |
| - return promisify((key, value, opts, callback) => { |
7 |
| - if (typeof opts === 'function') { |
8 |
| - callback = opts |
9 |
| - opts = {} |
10 |
| - } |
11 | 10 | if (typeof key !== 'string') {
|
12 |
| - return callback(new Error('Invalid key type')) |
| 11 | + throw new Error('Invalid key type') |
13 | 12 | }
|
14 | 13 |
|
15 |
| - if (value === undefined || Buffer.isBuffer(value)) { |
16 |
| - return callback(new Error('Invalid value type')) |
17 |
| - } |
| 14 | + const searchParams = new URLSearchParams(options.searchParams) |
18 | 15 |
|
19 | 16 | if (typeof value === 'boolean') {
|
| 17 | + searchParams.set('bool', true) |
20 | 18 | value = value.toString()
|
21 |
| - opts = { bool: true } |
22 | 19 | } else if (typeof value !== 'string') {
|
| 20 | + searchParams.set('json', true) |
23 | 21 | value = JSON.stringify(value)
|
24 |
| - opts = { json: true } |
25 | 22 | }
|
26 | 23 |
|
27 |
| - send({ |
28 |
| - path: 'config', |
29 |
| - args: [key, value], |
30 |
| - qs: opts, |
31 |
| - files: undefined, |
32 |
| - buffer: true |
33 |
| - }, callback) |
34 |
| - }) |
35 |
| -} |
| 24 | + searchParams.set('arg', key) |
| 25 | + searchParams.append('arg', value) |
| 26 | + |
| 27 | + const res = await ky.post('config', { |
| 28 | + timeout: options.timeout, |
| 29 | + signal: options.signal, |
| 30 | + headers: options.headers, |
| 31 | + searchParams |
| 32 | + }).json() |
| 33 | + |
| 34 | + return toCamel(res) |
| 35 | + } |
| 36 | +}) |
0 commit comments