Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 23de2e4

Browse files
committed
refactor: make code promisify free
There's no need for the promisify-es6 module anymore as all the code is using async/await based libraries now. This is the same commit as 1a98e16, the only difference is a commit message that contains the information about the breaking change. This reverts commit e84955b. BREAKING CHANGE: Everyone upgrading to this release also needs to upgrade ipfs-block-service, ipfs-repo and ipld-in-memory. This commit uses the new async API of: - ipfs-block-service >= 0.16.0 - ipfs-repo >=0.27.0 - ipld-in-memory >= 3.0.0 If your library has a dependency on any of those, you likely also need to upgrade to at least those versions.
1 parent 8f20e0f commit 23de2e4

File tree

6 files changed

+17
-34
lines changed

6 files changed

+17
-34
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
"dirty-chai": "^2.0.1",
4141
"ethereumjs-block": "^2.2.0",
4242
"fs-extra": "^8.0.1",
43-
"ipfs-block-service": "~0.15.2",
44-
"ipfs-repo": "~0.26.5",
43+
"ipfs-block-service": "^0.16.0",
44+
"ipfs-repo": "^0.27.0",
4545
"ipld-bitcoin": "~0.3.0",
4646
"ipld-ethereum": "^4.0.0",
4747
"ipld-git": "~0.5.0",
48-
"ipld-in-memory": "^2.0.0",
48+
"ipld-in-memory": "^3.0.0",
4949
"ipld-zcash": "~0.3.0",
5050
"merkle-patricia-tree": "^3.0.0",
5151
"multihashes": "~0.4.14",
@@ -60,7 +60,6 @@
6060
"ipld-raw": "^4.0.0",
6161
"merge-options": "^1.0.1",
6262
"multicodec": "~0.5.1",
63-
"promisify-es6": "^1.0.3",
6463
"typical": "^5.0.0"
6564
},
6665
"contributors": [

src/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const ipldDagCbor = require('ipld-dag-cbor')
77
const ipldDagPb = require('ipld-dag-pb')
88
const ipldRaw = require('ipld-raw')
99
const multicodec = require('multicodec')
10-
const promisify = require('promisify-es6')
1110
const typical = require('typical')
1211
const { extendIterator } = require('./util')
1312

@@ -95,7 +94,7 @@ class IPLDResolver {
9594
// get block
9695
// use local resolver
9796
// update path value
98-
const block = await promisify(this.bs.get.bind(this.bs))(cid)
97+
const block = await this.bs.get(cid)
9998
const result = format.resolver.resolve(block.data, path)
10099

101100
// Prepare for the next iteration if there is a `remainderPath`
@@ -129,7 +128,7 @@ class IPLDResolver {
129128
* @returns {Promise.<Object>} - Returns a Promise with the IPLD Node that correspond to the given `cid`.
130129
*/
131130
async get (cid) {
132-
const block = await promisify(this.bs.get.bind(this.bs))(cid)
131+
const block = await this.bs.get(cid)
133132
const format = await this._getFormat(block.cid.codec)
134133
const node = format.util.deserialize(block.data)
135134

@@ -194,7 +193,7 @@ class IPLDResolver {
194193

195194
if (!options.onlyHash) {
196195
const block = new Block(serialized, cid)
197-
await promisify(this.bs.put.bind(this.bs))(block)
196+
await this.bs.put(block)
198197
}
199198

200199
return cid
@@ -255,7 +254,7 @@ class IPLDResolver {
255254
* @return {Promise.<CID>} The CID of the removed IPLD Node.
256255
*/
257256
async remove (cid) { // eslint-disable-line require-await
258-
return promisify(this.bs.delete.bind(this.bs))(cid)
257+
return this.bs.delete(cid)
259258
}
260259

261260
/**
@@ -336,7 +335,7 @@ class IPLDResolver {
336335
if (treePaths.length === 0 && queue.length > 0) {
337336
({ cid, basePath } = queue.shift())
338337
const format = await this._getFormat(cid.codec)
339-
block = await promisify(this.bs.get.bind(this.bs))(cid)
338+
block = await this.bs.get(cid)
340339

341340
const paths = format.resolver.tree(block.data)
342341
treePaths.push(...paths)

test/basics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = (repo) => {
2323
expect(r.bs).to.exist()
2424
})
2525

26-
it('creates an in memory repo if no blockService is passed', () => {
27-
inMemory(IPLDResolver, (err, r) => {
26+
it('creates an in memory repo if no blockService is passed', async () => {
27+
await inMemory(IPLDResolver, (err, r) => {
2828
expect(err).to.not.exist()
2929
expect(r.bs).to.exist()
3030
})

test/browser.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'use strict'
55

66
const IPFSRepo = require('ipfs-repo')
7-
const promisify = require('promisify-es6')
87

98
const basePath = 'ipfs' + Math.random()
109

@@ -19,17 +18,13 @@ idb.deleteDatabase(basePath + '/blocks')
1918
describe('Browser', () => {
2019
const repo = new IPFSRepo(basePath)
2120

22-
const repoInit = promisify(repo.init.bind(repo))
23-
const repoOpen = promisify(repo.open.bind(repo))
24-
const repoClose = promisify(repo.close.bind(repo))
25-
2621
before(async () => {
27-
await repoInit({})
28-
await repoOpen()
22+
await repo.init({})
23+
await repo.open()
2924
})
3025

3126
after(async () => {
32-
await repoClose()
27+
await repo.close()
3328
idb.deleteDatabase(basePath)
3429
idb.deleteDatabase(basePath + '/blocks')
3530
})

test/ipld-all.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const dagPB = require('ipld-dag-pb')
1717
const CID = require('cids')
1818
const inMemory = require('ipld-in-memory')
1919
const multicodec = require('multicodec')
20-
const promisify = require('promisify-es6')
2120

2221
const IPLDResolver = require('../src')
2322

@@ -30,12 +29,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
3029
let cidPb
3130

3231
before(async () => {
33-
resolver = await new Promise((resolve, reject) => {
34-
inMemory(IPLDResolver, (error, res) => {
35-
if (error) reject(error)
36-
else resolve(res)
37-
})
38-
})
32+
resolver = await inMemory(IPLDResolver)
3933

4034
nodePb = dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'))
4135
cidPb = await resolver.put(nodePb, multicodec.DAG_PB, { cidVersion: 0 })
@@ -65,7 +59,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
6559
cidVersion: 1,
6660
hashAlg: multicodec.SHA2_256
6761
})
68-
const result = await promisify(resolver.bs._repo.blocks.has)(cid)
62+
const result = await resolver.bs._repo.blocks.has(cid)
6963
expect(result).to.be.false()
7064
})
7165

test/node.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33

44
const fs = require('fs-extra')
55
const IPFSRepo = require('ipfs-repo')
6-
const promisify = require('promisify-es6')
76
const os = require('os')
87

98
describe('Node.js', () => {
109
const repoExample = process.cwd() + '/test/example-repo'
1110
const repoTests = os.tmpdir() + '/t-r-' + Date.now()
1211
const repo = new IPFSRepo(repoTests)
1312

14-
const repoOpen = promisify(repo.open.bind(repo))
15-
const repoClose = promisify(repo.close.bind(repo))
16-
1713
before(async () => {
1814
await fs.copy(repoExample, repoTests)
19-
await repoOpen()
15+
await repo.open()
2016
})
2117

2218
after(async () => {
23-
await repoClose()
19+
await repo.close()
2420
await fs.remove(repoTests)
2521
})
2622

0 commit comments

Comments
 (0)