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

Commit e84955b

Browse files
committed
Revert "refactor: make code promisify free"
Just reverting on order to make a proper breaking change commit message with that commit. This reverts commit 1a98e16.
1 parent 1a98e16 commit e84955b

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

package.json

Lines changed: 4 additions & 3 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.16.0",
44-
"ipfs-repo": "^0.27.0",
43+
"ipfs-block-service": "~0.15.2",
44+
"ipfs-repo": "~0.26.5",
4545
"ipld-bitcoin": "~0.3.0",
4646
"ipld-ethereum": "^4.0.0",
4747
"ipld-git": "~0.5.0",
48-
"ipld-in-memory": "^3.0.0",
48+
"ipld-in-memory": "^2.0.0",
4949
"ipld-zcash": "~0.3.0",
5050
"merkle-patricia-tree": "^3.0.0",
5151
"multihashes": "~0.4.14",
@@ -60,6 +60,7 @@
6060
"ipld-raw": "^4.0.0",
6161
"merge-options": "^1.0.1",
6262
"multicodec": "~0.5.1",
63+
"promisify-es6": "^1.0.3",
6364
"typical": "^5.0.0"
6465
},
6566
"contributors": [

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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')
1011
const typical = require('typical')
1112
const { extendIterator } = require('./util')
1213

@@ -94,7 +95,7 @@ class IPLDResolver {
9495
// get block
9596
// use local resolver
9697
// update path value
97-
const block = await this.bs.get(cid)
98+
const block = await promisify(this.bs.get.bind(this.bs))(cid)
9899
const result = format.resolver.resolve(block.data, path)
99100

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

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

194195
if (!options.onlyHash) {
195196
const block = new Block(serialized, cid)
196-
await this.bs.put(block)
197+
await promisify(this.bs.put.bind(this.bs))(block)
197198
}
198199

199200
return cid
@@ -254,7 +255,7 @@ class IPLDResolver {
254255
* @return {Promise.<CID>} The CID of the removed IPLD Node.
255256
*/
256257
async remove (cid) { // eslint-disable-line require-await
257-
return this.bs.delete(cid)
258+
return promisify(this.bs.delete.bind(this.bs))(cid)
258259
}
259260

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

340341
const paths = format.resolver.tree(block.data)
341342
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', async () => {
27-
await inMemory(IPLDResolver, (err, r) => {
26+
it('creates an in memory repo if no blockService is passed', () => {
27+
inMemory(IPLDResolver, (err, r) => {
2828
expect(err).to.not.exist()
2929
expect(r.bs).to.exist()
3030
})

test/browser.js

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

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

89
const basePath = 'ipfs' + Math.random()
910

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

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+
2126
before(async () => {
22-
await repo.init({})
23-
await repo.open()
27+
await repoInit({})
28+
await repoOpen()
2429
})
2530

2631
after(async () => {
27-
await repo.close()
32+
await repoClose()
2833
idb.deleteDatabase(basePath)
2934
idb.deleteDatabase(basePath + '/blocks')
3035
})

test/ipld-all.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ 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')
2021

2122
const IPLDResolver = require('../src')
2223

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

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

3440
nodePb = dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'))
3541
cidPb = await resolver.put(nodePb, multicodec.DAG_PB, { cidVersion: 0 })
@@ -59,7 +65,7 @@ describe('IPLD Resolver for dag-cbor + dag-pb', () => {
5965
cidVersion: 1,
6066
hashAlg: multicodec.SHA2_256
6167
})
62-
const result = await resolver.bs._repo.blocks.has(cid)
68+
const result = await promisify(resolver.bs._repo.blocks.has)(cid)
6369
expect(result).to.be.false()
6470
})
6571

test/node.js

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

44
const fs = require('fs-extra')
55
const IPFSRepo = require('ipfs-repo')
6+
const promisify = require('promisify-es6')
67
const os = require('os')
78

89
describe('Node.js', () => {
910
const repoExample = process.cwd() + '/test/example-repo'
1011
const repoTests = os.tmpdir() + '/t-r-' + Date.now()
1112
const repo = new IPFSRepo(repoTests)
1213

14+
const repoOpen = promisify(repo.open.bind(repo))
15+
const repoClose = promisify(repo.close.bind(repo))
16+
1317
before(async () => {
1418
await fs.copy(repoExample, repoTests)
15-
await repo.open()
19+
await repoOpen()
1620
})
1721

1822
after(async () => {
19-
await repo.close()
23+
await repoClose()
2024
await fs.remove(repoTests)
2125
})
2226

0 commit comments

Comments
 (0)