Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 1c619bb

Browse files
committed
fix: re-add configure
1 parent 6a3db3f commit 1c619bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+438
-810
lines changed

packages/ipfs-http-client/examples/files-api/files-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
'use strict'
3-
3+
const { Buffer } = require('buffer')
44
// Run `ipfs daemon` in your terminal to start the IPFS daemon
55
// Look for `API server listening on /ip4/127.0.0.1/tcp/5001`
66
const ipfs = require('../../src')('/ip4/127.0.0.1/tcp/5001')

packages/ipfs-http-client/examples/name-api/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-console */
22
'use strict'
3+
const { Buffer } = require('buffer')
34
const ipfsHttp = require('ipfs-http-client')
45
const ipfs = ipfsHttp('/ip4/127.0.0.1/tcp/5001')
56

packages/ipfs-http-client/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
"iso-url": "^0.4.6",
5555
"it-tar": "^1.2.1",
5656
"it-to-stream": "^0.1.1",
57-
"iterable-ndjson": "^1.1.0",
58-
"ky": "^0.15.0",
59-
"ky-universal": "^0.3.0",
6057
"merge-options": "^2.0.0",
6158
"multiaddr": "^7.2.1",
6259
"multiaddr-to-uri": "^5.1.0",
@@ -69,7 +66,6 @@
6966
},
7067
"devDependencies": {
7168
"aegir": "^21.3.0",
72-
"async": "^3.1.0",
7369
"browser-process-platform": "^0.1.1",
7470
"cross-env": "^7.0.0",
7571
"go-ipfs-dep": "0.4.23-3",

packages/ipfs-http-client/src/add/index.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
'use strict'
22

3-
const ndjson = require('iterable-ndjson')
43
const CID = require('cids')
5-
const toIterable = require('stream-to-it/source')
4+
const merge = require('merge-options')
65
const { toFormData } = require('./form-data')
76
const toCamel = require('../lib/object-to-camel')
8-
const merge = require('merge-options')
7+
const configure = require('../lib/configure')
98

10-
/** @typedef { import("./../lib/api") } API */
11-
12-
module.exports = (/** @type {API} */ api) => {
9+
module.exports = configure((api) => {
1310
return async function * add (input, options = {}) {
14-
// extract functions here
1511
const progressFn = options.progress
16-
// default or mutate/force options here
1712
options = merge(
1813
options,
1914
{
@@ -23,14 +18,15 @@ module.exports = (/** @type {API} */ api) => {
2318
}
2419
)
2520

26-
const res = await api.post('add', {
21+
const res = await api.ndjson('add', {
22+
method: 'POST',
2723
searchParams: options,
2824
body: await toFormData(input),
2925
timeout: options.timeout,
3026
signal: options.signal
3127
})
3228

33-
for await (let file of ndjson(toIterable(res.body))) {
29+
for await (let file of res) {
3430
file = toCamel(file)
3531

3632
if (progressFn && file.bytes) {
@@ -40,7 +36,7 @@ module.exports = (/** @type {API} */ api) => {
4036
}
4137
}
4238
}
43-
}
39+
})
4440

4541
function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) {
4642
const output = {

packages/ipfs-http-client/src/bitswap/stat.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
const { BigNumber } = require('bignumber.js')
44
const CID = require('cids')
5+
const configure = require('../lib/configure')
56

6-
module.exports = api => {
7+
module.exports = configure(api => {
78
return async (options = {}) => {
89
const res = await api.post('bitswap/stat', {
910
searchParams: options,
@@ -13,7 +14,7 @@ module.exports = api => {
1314

1415
return toCoreInterface(await res.json())
1516
}
16-
}
17+
})
1718

1819
function toCoreInterface (res) {
1920
return {

packages/ipfs-http-client/src/bitswap/unwant.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict'
22

33
const CID = require('cids')
4+
const configure = require('../lib/configure')
45

5-
module.exports = api => {
6+
module.exports = configure(api => {
67
return async (cid, options = {}) => {
78
options.arg = typeof cid === 'string' ? cid : new CID(cid).toString()
89

@@ -14,4 +15,4 @@ module.exports = api => {
1415

1516
return res.json()
1617
}
17-
}
18+
})

packages/ipfs-http-client/src/bitswap/wantlist.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict'
22

33
const CID = require('cids')
4+
const configure = require('../lib/configure')
45

5-
module.exports = api => {
6+
module.exports = configure(api => {
67
return async (peer, options = {}) => {
78
if (peer) {
89
options.peer = typeof peer === 'string' ? peer : new CID(peer).toString()
@@ -16,4 +17,4 @@ module.exports = api => {
1617

1718
return (res.Keys || []).map(k => new CID(k['/']))
1819
}
19-
}
20+
})

packages/ipfs-http-client/src/block/get.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
const Block = require('ipfs-block')
44
const CID = require('cids')
55
const { Buffer } = require('buffer')
6+
const configure = require('../lib/configure')
67

7-
/** @typedef { import("./../lib/api") } API */
8-
9-
module.exports = (/** @type {API} */ api) => {
8+
module.exports = configure(api => {
109
return async (cid, options = {}) => {
1110
cid = new CID(cid)
1211
options.arg = cid.toString()
@@ -19,4 +18,4 @@ module.exports = (/** @type {API} */ api) => {
1918

2019
return new Block(Buffer.from(await rsp.arrayBuffer()), cid)
2120
}
22-
}
21+
})

packages/ipfs-http-client/src/block/put.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const Block = require('ipfs-block')
44
const CID = require('cids')
55
const multihash = require('multihashes')
66
const toFormData = require('../lib/buffer-to-form-data')
7+
const configure = require('../lib/configure')
78

8-
/** @typedef { import("./../lib/api") } API */
9-
10-
module.exports = (/** @type {API} */ api) => {
9+
module.exports = configure(api => {
1110
async function put (data, options = {}) {
1211
if (Block.isBlock(data)) {
1312
const { name, length } = multihash.decode(data.cid.multihash)
@@ -57,4 +56,4 @@ module.exports = (/** @type {API} */ api) => {
5756
}
5857

5958
return put
60-
}
59+
})

packages/ipfs-http-client/src/block/rm.js

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

33
const CID = require('cids')
4-
const ndjson = require('iterable-ndjson')
54
const merge = require('merge-options')
6-
const toIterable = require('stream-to-it/source')
5+
const configure = require('../lib/configure')
76

8-
/** @typedef { import("./../lib/api") } API */
9-
10-
module.exports = (/** @type {API} */ api) => {
7+
module.exports = configure(api => {
118
return async function * rm (cid, options = {}) {
129
if (!Array.isArray(cid)) {
1310
cid = [cid]
@@ -26,17 +23,17 @@ module.exports = (/** @type {API} */ api) => {
2623
searchParams.append('arg', new CID(cid).toString())
2724
})
2825

29-
const res = await api.post('block/rm', {
26+
const res = await api.ndjson('block/rm', {
3027
timeout: options.timeout,
3128
signal: options.signal,
3229
searchParams: searchParams
3330
})
3431

35-
for await (const removed of ndjson(toIterable(res.body))) {
32+
for await (const removed of res) {
3633
yield toCoreInterface(removed)
3734
}
3835
}
39-
}
36+
})
4037

4138
function toCoreInterface (removed) {
4239
const out = {

packages/ipfs-http-client/src/block/stat.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const CID = require('cids')
4+
const configure = require('../lib/configure')
45

5-
/** @typedef { import("./../lib/api") } API */
6-
7-
module.exports = (/** @type {API} */ api) => {
6+
module.exports = configure(api => {
87
return async (cid, options = {}) => {
98
options.arg = (new CID(cid)).toString()
109

@@ -17,4 +16,4 @@ module.exports = (/** @type {API} */ api) => {
1716

1817
return { cid: new CID(res.Key), size: res.Size }
1918
}
20-
}
19+
})

packages/ipfs-http-client/src/bootstrap/add.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const Multiaddr = require('multiaddr')
4+
const configure = require('../lib/configure')
45

5-
/** @typedef { import("./../lib/api") } API */
6-
7-
module.exports = (/** @type {API} */ api) => {
6+
module.exports = configure(api => {
87
return async (addr, options = {}) => {
98
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
109
options = addr
@@ -21,4 +20,4 @@ module.exports = (/** @type {API} */ api) => {
2120

2221
return res.json()
2322
}
24-
}
23+
})
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
/** @typedef { import("./../lib/api") } API */
3+
const configure = require('../lib/configure')
44

5-
module.exports = (/** @type {API} */ api) => {
5+
module.exports = configure(api => {
66
return async (options = {}) => {
77
const res = await api.post('bootstrap/list', {
88
timeout: options.timeout,
@@ -12,4 +12,4 @@ module.exports = (/** @type {API} */ api) => {
1212

1313
return res.json()
1414
}
15-
}
15+
})

packages/ipfs-http-client/src/bootstrap/rm.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const Multiaddr = require('multiaddr')
4+
const configure = require('../lib/configure')
45

5-
/** @typedef { import("./../lib/api") } API */
6-
7-
module.exports = (/** @type {API} */ api) => {
6+
module.exports = configure(api => {
87
return async (addr, options = {}) => {
98
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
109
options = addr
@@ -21,4 +20,4 @@ module.exports = (/** @type {API} */ api) => {
2120

2221
return res.json()
2322
}
24-
}
23+
})

packages/ipfs-http-client/src/cat.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
const CID = require('cids')
44
const { Buffer } = require('buffer')
5-
const toIterable = require('stream-to-it/source')
65
const merge = require('merge-options')
6+
const configure = require('./lib/configure')
77

8-
/** @typedef { import("./lib/api") } API */
9-
10-
module.exports = (/** @type {API} */ api) => {
8+
module.exports = configure(api => {
119
return async function * cat (path, options = {}) {
1210
options = merge(
1311
options,
1412
{
1513
arg: typeof path === 'string' ? path : new CID(path).toString()
1614
}
1715
)
18-
const res = await api.post('cat', {
16+
const res = await api.iterator('cat', {
17+
method: 'POST',
1918
timeout: options.timeout,
2019
signal: options.signal,
2120
searchParams: options
2221
})
2322

24-
for await (const chunk of toIterable(res.body)) {
23+
for await (const chunk of res) {
2524
yield Buffer.from(chunk)
2625
}
2726
}
28-
}
27+
})
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
/** @typedef { import("./lib/api") } API */
3+
const configure = require('./lib/configure')
44

5-
module.exports = (/** @type {API} */ api) => {
5+
module.exports = configure(api => {
66
return async (options = {}) => {
77
const res = await api.post('commands', {
88
timeout: options.timeout,
@@ -12,4 +12,4 @@ module.exports = (/** @type {API} */ api) => {
1212

1313
return res.json()
1414
}
15-
}
15+
})

packages/ipfs-http-client/src/config/get.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
/** @typedef { import("./../lib/api") } API */
3+
const configure = require('../lib/configure')
44

5-
module.exports = (/** @type {API} */ api) => {
5+
module.exports = configure(api => {
66
return async (key, options = {}) => {
77
if (key && typeof key === 'object') {
88
options = key
@@ -19,4 +19,4 @@ module.exports = (/** @type {API} */ api) => {
1919

2020
return key ? data.Value : data
2121
}
22-
}
22+
})

packages/ipfs-http-client/src/config/profiles/apply.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

3-
/** @typedef { import("./../../lib/api") } API */
3+
const configure = require('../../lib/configure')
44

5-
module.exports = (/** @type {API} */ api) => {
5+
module.exports = configure(api => {
66
return async (profile, options = {}) => {
77
options.arg = profile
88
const response = await api.post('config/profile/apply', {
@@ -16,4 +16,4 @@ module.exports = (/** @type {API} */ api) => {
1616
original: res.OldCfg, updated: res.NewCfg
1717
}
1818
}
19-
}
19+
})
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const toCamel = require('../../lib/object-to-camel')
4+
const configure = require('../../lib/configure')
45

5-
/** @typedef { import("./../../lib/api") } API */
6-
7-
module.exports = (/** @type {API} */ api) => {
6+
module.exports = configure(api => {
87
return async (options = {}) => {
98
const res = await api.post('config/profile/list', {
109
timeout: options.timeout,
@@ -16,4 +15,4 @@ module.exports = (/** @type {API} */ api) => {
1615

1716
return data.map(profile => toCamel(profile))
1817
}
19-
}
18+
})

0 commit comments

Comments
 (0)