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

Commit 2fe568f

Browse files
author
Alan Shaw
committed
refactor: async iterables
1 parent 0565f47 commit 2fe568f

File tree

143 files changed

+3085
-3747
lines changed

Some content is hidden

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

143 files changed

+3085
-3747
lines changed

package.json

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
],
1616
"main": "src/core/index.js",
1717
"browser": {
18-
"./src/core/components/init-assets.js": false,
19-
"./src/core/runtime/add-from-fs-nodejs.js": "./src/core/runtime/add-from-fs-browser.js",
18+
"./src/core/runtime/init-assets-nodejs.js": "./src/core/runtime/init-assets-browser.js",
2019
"./src/core/runtime/config-nodejs.js": "./src/core/runtime/config-browser.js",
2120
"./src/core/runtime/dns-nodejs.js": "./src/core/runtime/dns-browser.js",
2221
"./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js",
@@ -25,7 +24,8 @@
2524
"./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js",
2625
"./src/core/runtime/ipld-nodejs.js": "./src/core/runtime/ipld-browser.js",
2726
"./test/utils/create-repo-nodejs.js": "./test/utils/create-repo-browser.js",
28-
"stream": "readable-stream"
27+
"stream": "readable-stream",
28+
"ipfs-utils/src/files/glob-source": false
2929
},
3030
"browser-all-ipld-formats": {
3131
"./src/core/runtime/ipld-browser.js": "./src/core/runtime/ipld-browser-all.js"
@@ -93,20 +93,19 @@
9393
"glob": "^7.1.3",
9494
"hapi-pino": "^6.1.0",
9595
"hashlru": "^2.3.0",
96-
"human-to-milliseconds": "^2.0.0",
9796
"interface-datastore": "~0.8.0",
9897
"ipfs-bitswap": "^0.26.0",
9998
"ipfs-block": "~0.8.1",
10099
"ipfs-block-service": "~0.16.0",
101-
"ipfs-http-client": "^40.1.0",
100+
"ipfs-http-client": "github:ipfs/js-ipfs-http-client#refactor/async-iterables2",
102101
"ipfs-http-response": "~0.4.0",
103-
"ipfs-mfs": "^0.13.2",
102+
"ipfs-mfs": "github:ipfs/js-ipfs-mfs#refactor/remove-streams",
104103
"ipfs-multipart": "^0.2.0",
105104
"ipfs-repo": "^0.30.0",
106105
"ipfs-unixfs": "~0.1.16",
107106
"ipfs-unixfs-exporter": "^0.38.0",
108-
"ipfs-unixfs-importer": "^0.42.0",
109-
"ipfs-utils": "~0.4.0",
107+
"ipfs-unixfs-importer": "^0.40.0",
108+
"ipfs-utils": "^0.5.0",
110109
"ipld": "~0.25.0",
111110
"ipld-bitcoin": "~0.3.0",
112111
"ipld-dag-cbor": "~0.15.0",
@@ -124,34 +123,35 @@
124123
"it-all": "^1.0.1",
125124
"it-pipe": "^1.0.1",
126125
"it-to-stream": "^0.1.1",
126+
"iterable-ndjson": "^1.1.0",
127127
"jsondiffpatch": "~0.3.11",
128128
"just-safe-set": "^2.1.0",
129129
"kind-of": "^6.0.2",
130130
"ky": "^0.15.0",
131131
"ky-universal": "~0.3.0",
132-
"libp2p": "^0.26.2",
133-
"libp2p-bootstrap": "~0.9.3",
134-
"libp2p-crypto": "^0.16.2",
132+
"libp2p": "^0.27.0-pre.1",
133+
"libp2p-bootstrap": "^0.10.2",
134+
"libp2p-crypto": "^0.17.1",
135135
"libp2p-delegated-content-routing": "^0.4.1",
136-
"libp2p-delegated-peer-routing": "^0.3.1",
137-
"libp2p-floodsub": "^0.18.0",
138-
"libp2p-gossipsub": "~0.0.5",
139-
"libp2p-kad-dht": "~0.16.0",
136+
"libp2p-delegated-peer-routing": "^0.4.0",
137+
"libp2p-floodsub": "^0.20.0",
138+
"libp2p-gossipsub": "^0.2.0",
139+
"libp2p-kad-dht": "^0.18.3",
140140
"libp2p-keychain": "^0.5.2",
141-
"libp2p-mdns": "~0.12.0",
141+
"libp2p-mdns": "^0.13.0",
142142
"libp2p-record": "~0.7.0",
143-
"libp2p-secio": "~0.11.0",
144-
"libp2p-tcp": "^0.13.0",
145-
"libp2p-webrtc-star": "~0.16.0",
143+
"libp2p-secio": "^0.12.1",
144+
"libp2p-tcp": "^0.14.2",
145+
"libp2p-webrtc-star": "^0.17.0",
146146
"libp2p-websocket-star-multi": "~0.4.3",
147-
"libp2p-websockets": "~0.12.3",
147+
"libp2p-websockets": "^0.13.0",
148148
"lodash.flatten": "^4.4.0",
149149
"mafmt": "^6.0.10",
150150
"merge-options": "^2.0.0",
151151
"mime-types": "^2.1.21",
152152
"mkdirp": "~0.5.1",
153153
"mortice": "^2.0.0",
154-
"multiaddr": "^6.1.1",
154+
"multiaddr": "^7.2.1",
155155
"multiaddr-to-uri": "^5.0.0",
156156
"multibase": "~0.6.0",
157157
"multicodec": "~0.5.5",
@@ -160,9 +160,9 @@
160160
"node-fetch": "^2.3.0",
161161
"p-iteration": "^1.1.8",
162162
"p-queue": "^6.1.0",
163-
"peer-book": "^0.9.1",
164-
"peer-id": "~0.12.2",
165-
"peer-info": "~0.15.1",
163+
"parse-duration": "^0.1.2",
164+
"peer-id": "^0.13.5",
165+
"peer-info": "^0.17.0",
166166
"pretty-bytes": "^5.3.0",
167167
"progress": "^2.0.1",
168168
"promise-nodeify": "^3.0.1",
@@ -204,9 +204,10 @@
204204
"execa": "^3.0.0",
205205
"form-data": "^3.0.0",
206206
"hat": "0.0.3",
207-
"interface-ipfs-core": "^0.125.0",
207+
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#refactor/async-iterables",
208208
"ipfs-interop": "^0.1.1",
209209
"ipfsd-ctl": "^1.0.2",
210+
"it-all": "^1.0.1",
210211
"libp2p-websocket-star": "~0.10.2",
211212
"lodash": "^4.17.15",
212213
"ncp": "^2.0.0",

src/cli/commands/add.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,20 @@ module.exports = {
175175
? globSource(argv.file, { recursive: argv.recursive, hidden: argv.hidden })
176176
: process.stdin // Pipe directly to ipfs.add
177177

178-
let finalHash
178+
let finalCid
179179

180180
try {
181-
for await (const file of ipfs._addAsyncIterator(source, options)) {
181+
for await (const file of ipfs.add(source, options)) {
182182
if (argv.silent) {
183183
continue
184184
}
185185

186186
if (argv.quieter) {
187-
finalHash = file.hash
187+
finalCid = file.cid
188188
continue
189189
}
190190

191-
const cid = cidToString(file.hash, { base: argv.cidBase })
191+
const cid = cidToString(file.cid, { base: argv.cidBase })
192192
let message = cid
193193

194194
if (!argv.quiet) {
@@ -203,7 +203,7 @@ module.exports = {
203203
bar.terminate()
204204
}
205205

206-
// Tweak the error message and add more relevant infor for the CLI
206+
// Tweak the error message and add more relevant info for the CLI
207207
if (err.code === 'ERR_DIR_NON_RECURSIVE') {
208208
err.message = `'${err.path}' is a directory, use the '-r' flag to specify directories`
209209
}
@@ -216,7 +216,7 @@ module.exports = {
216216
}
217217

218218
if (argv.quieter) {
219-
log(cidToString(finalHash, { base: argv.cidBase }))
219+
log(cidToString(finalCid, { base: argv.cidBase }))
220220
}
221221
})())
222222
}

src/cli/commands/bitswap/stat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
stats.dupDataReceived = prettyBytes(stats.dupDataReceived.toNumber()).toUpperCase()
3636
stats.wantlist = `[${stats.wantlist.length} keys]`
3737
} else {
38-
const wantlist = stats.wantlist.map((elem) => cidToString(elem['/'], { base: cidBase, upgrade: false }))
38+
const wantlist = stats.wantlist.map(cid => cidToString(cid, { base: cidBase, upgrade: false }))
3939
stats.wantlist = `[${wantlist.length} keys]
4040
${wantlist.join('\n ')}`
4141
}

src/cli/commands/bitswap/wantlist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
resolve((async () => {
2626
const ipfs = await getIpfs()
2727
const list = await ipfs.bitswap.wantlist(peer)
28-
list.Keys.forEach(k => print(cidToString(k['/'], { base: cidBase, upgrade: false })))
28+
list.forEach(cid => print(cidToString(cid, { base: cidBase, upgrade: false })))
2929
})())
3030
}
3131
}

src/cli/commands/block/rm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
const ipfs = await getIpfs()
2626
let errored = false
2727

28-
for await (const result of ipfs.block._rmAsyncIterator(hash, {
28+
for await (const result of ipfs.block.rm(hash, {
2929
force,
3030
quiet
3131
})) {

src/cli/commands/block/stat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
resolve((async () => {
2121
const ipfs = await getIpfs()
2222
const stats = await ipfs.block.stat(key)
23-
print('Key: ' + cidToString(stats.key, { base: cidBase }))
23+
print('Key: ' + cidToString(stats.cid, { base: cidBase }))
2424
print('Size: ' + stats.size)
2525
})())
2626
}

src/cli/commands/dag/resolve.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ module.exports = {
1919
const options = {}
2020

2121
try {
22-
const result = await ipfs.dag.resolve(ref, options)
2322
let lastCid
2423

25-
for (const res of result) {
24+
for await (const res of ipfs.dag.resolve(ref, options)) {
2625
if (CID.isCID(res.value)) {
2726
lastCid = res.value
2827
}

src/cli/commands/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = {
6565
const IPFS = require('../../core')
6666
const Repo = require('ipfs-repo')
6767

68-
const node = new IPFS({
68+
const node = await IPFS.create({
6969
repo: new Repo(path),
7070
init: false,
7171
start: false,

src/cli/commands/pin/add.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
const ipfs = await getIpfs()
2929
const results = await ipfs.pin.add(ipfsPath, { recursive })
3030
results.forEach((res) => {
31-
print(`pinned ${cidToString(res.hash, { base: cidBase })} ${type}ly`)
31+
print(`pinned ${cidToString(res.cid, { base: cidBase })} ${type}ly`)
3232
})
3333
})())
3434
}

src/cli/commands/pin/ls.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ module.exports = {
3434
resolve((async () => {
3535
const paths = ipfsPath
3636
const ipfs = await getIpfs()
37-
const results = await ipfs.pin.ls(paths, { type })
38-
results.forEach((res) => {
39-
let line = cidToString(res.hash, { base: cidBase })
37+
for await (const res of ipfs.pin.ls(paths, { type })) {
38+
let line = cidToString(res.cid, { base: cidBase })
4039
if (!quiet) {
4140
line += ` ${res.type}`
4241
}
4342
print(line)
44-
})
43+
}
4544
})())
4645
}
4746
}

src/cli/commands/pin/rm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
const ipfs = await getIpfs()
2828
const results = await ipfs.pin.rm(ipfsPath, { recursive })
2929
results.forEach((res) => {
30-
print(`unpinned ${cidToString(res.hash, { base: cidBase })}`)
30+
print(`unpinned ${cidToString(res.cid, { base: cidBase })}`)
3131
})
3232
})())
3333
}

src/cli/daemon.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ class Daemon {
5555

5656
// start the daemon
5757
const ipfsOpts = Object.assign({}, { init: true, start: true, libp2p }, this._options)
58-
const ipfs = await IPFS.create(ipfsOpts)
59-
60-
this._ipfs = ipfs
58+
const ipfs = this._ipfs = await IPFS.create(ipfsOpts)
6159

6260
// start HTTP servers (if API or Gateway is enabled in options)
6361
const httpApi = new HttpApi(ipfs, ipfsOpts)

src/core/api-manager.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = class ApiManager {
2+
constructor () {
3+
this._api = {}
4+
this._onUndef = () => undefined
5+
this.api = new Proxy({}, {
6+
get: (_, prop) => {
7+
if (prop === 'then') return undefined // Not a promise!
8+
return this._api[prop] === undefined ? this._onUndef(prop) : this._api[prop]
9+
},
10+
has: (_, prop) => prop in this._api
11+
})
12+
}
13+
14+
update (nextApi, onUndef) {
15+
const prevApi = this._api
16+
const prevUndef = this._onUndef
17+
this._api = nextApi
18+
if (onUndef) this._onUndef = onUndef
19+
return { cancel: () => this.update(prevApi, prevUndef), api: this.api }
20+
}
21+
}

src/core/boot.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)