Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit c21e032

Browse files
vmxachingbrain
authored andcommitted
fix: update to newest IPLD libraries
ipld-dag-pb got a new release with breaking changes, update to that release.
1 parent c9c74de commit c21e032

File tree

8 files changed

+24
-51
lines changed

8 files changed

+24
-51
lines changed

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"detect-node": "^2.0.4",
4545
"detect-webworker": "^1.0.0",
4646
"dirty-chai": "^2.0.1",
47-
"ipfs-block-service": "~0.15.2",
48-
"ipfs-repo": "~0.26.4",
49-
"ipld": "~0.24.0",
47+
"ipfs-block-service": "~0.16.0",
48+
"ipfs-repo": "~0.27.0",
49+
"ipld": "~0.25.0",
5050
"memdown": "^4.0.0",
5151
"temp-write": "^3.4.0"
5252
},
@@ -58,18 +58,17 @@
5858
"debug": "^4.1.0",
5959
"err-code": "^1.1.2",
6060
"hamt-sharding": "~0.0.2",
61-
"interface-datastore": "~0.6.0",
61+
"interface-datastore": "~0.7.0",
6262
"ipfs-multipart": "~0.1.0",
6363
"ipfs-unixfs": "~0.1.16",
6464
"ipfs-unixfs-exporter": "~0.37.6",
6565
"ipfs-unixfs-importer": "~0.39.9",
66-
"ipld-dag-pb": "~0.17.2",
66+
"ipld-dag-pb": "~0.18.0",
6767
"joi-browser": "^13.4.0",
6868
"mortice": "^1.2.1",
6969
"multicodec": "~0.5.3",
7070
"multihashes": "~0.4.14",
7171
"once": "^1.4.0",
72-
"promisify-es6": "^1.0.3",
7372
"pull-stream": "^3.6.9"
7473
},
7574
"contributors": [

src/core/index.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const assert = require('assert')
4-
const promisify = require('promisify-es6')
54
const createLock = require('./utils/create-lock')
65

76
// These operations are read-locked at the function level and will execute simultaneously
@@ -48,24 +47,9 @@ module.exports = (options) => {
4847
assert(options.blocks, 'MFS requires an BlockStore instance')
4948
assert(options.datastore, 'MFS requires a DataStore instance')
5049

51-
// should be able to remove this when async/await PRs are in for datastore, blockstore & repo
5250
options.repo = {
53-
blocks: {
54-
get: promisify(options.blocks.get, {
55-
context: options.blocks
56-
})
57-
},
58-
datastore: {
59-
open: promisify(options.datastore.open, {
60-
context: options.datastore
61-
}),
62-
get: promisify(options.datastore.get, {
63-
context: options.datastore
64-
}),
65-
put: promisify(options.datastore.put, {
66-
context: options.datastore
67-
})
68-
}
51+
blocks: options.blocks,
52+
datastore: options.datastore
6953
}
7054

7155
const lock = createLock(repoOwner)

src/core/utils/add-link.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ const convertToShardedDirectory = async (context, options) => {
8787
}
8888

8989
const addToDirectory = async (context, options) => {
90-
let parent = await DAGNode.rmLink(options.parent, options.name)
91-
parent = await DAGNode.addLink(parent, new DAGLink(options.name, options.size, options.cid))
90+
options.parent.rmLink(options.name)
91+
options.parent.addLink(new DAGLink(options.name, options.size, options.cid))
9292

9393
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
9494
const hashAlg = mh.names[options.hashAlg]
9595

9696
// Persist the new parent DAGNode
97-
const cid = await context.ipld.put(parent, format, {
97+
const cid = await context.ipld.put(options.parent, format, {
9898
cidVersion: options.cidVersion,
9999
hashAlg,
100100
hashOnly: !options.flush
101101
})
102102

103103
return {
104-
node: parent,
104+
node: options.parent,
105105
cid
106106
}
107107
}
@@ -120,15 +120,13 @@ const addToShardedDirectory = async (context, options) => {
120120
const newLink = result.node.Links
121121
.find(link => link.Name.substring(0, 2) === path[0].prefix)
122122

123-
let parent = options.parent
124-
125123
if (oldLink) {
126-
parent = await DAGNode.rmLink(options.parent, oldLink.Name)
124+
options.parent.rmLink(oldLink.Name)
127125
}
128126

129-
parent = await DAGNode.addLink(parent, newLink)
127+
options.parent.addLink(newLink)
130128

131-
return updateHamtDirectory(context, parent.Links, path[0].bucket, options)
129+
return updateHamtDirectory(context, options.parent.Links, path[0].bucket, options)
132130
}
133131

134132
const addFileToShardedDirectory = async (context, options) => {

src/core/utils/create-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const createNode = async (context, type, options) => {
1111
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
1212
const hashAlg = mh.names[options.hashAlg]
1313

14-
const node = DAGNode.create(new UnixFS(type).marshal())
14+
const node = new DAGNode(new UnixFS(type).marshal())
1515
const cid = await context.ipld.put(node, format, {
1616
cidVersion: options.cidVersion,
1717
hashAlg

src/core/utils/hamt-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const updateHamtDirectory = async (context, links, bucket, options) => {
2121
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
2222
const hashAlg = mh.names[options.hashAlg]
2323

24-
const parent = DAGNode.create(dir.marshal(), links)
24+
const parent = new DAGNode(dir.marshal(), links)
2525
const cid = await context.ipld.put(parent, format, {
2626
cidVersion: options.cidVersion,
2727
hashAlg,

src/core/utils/remove-link.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ const removeFromDirectory = async (context, options) => {
5151
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
5252
const hashAlg = mh.names[options.hashAlg]
5353

54-
const newParentNode = await DAGNode.rmLink(options.parent, options.name)
55-
const cid = await context.ipld.put(newParentNode, format, {
54+
options.parent.rmLink(options.name)
55+
const cid = await context.ipld.put(options.parent, format, {
5656
cidVersion: options.cidVersion,
5757
hashAlg
5858
})
5959

6060
log(`Updated regular directory ${cid}`)
6161

6262
return {
63-
node: newParentNode,
63+
node: options.parent,
6464
cid
6565
}
6666
}
@@ -104,11 +104,11 @@ const updateShard = async (context, positions, child, options) => {
104104
if (link.Name === `${prefix}${child.name}`) {
105105
log(`Removing existing link ${link.Name}`)
106106

107-
const newNode = await DAGNode.rmLink(node, link.Name)
107+
node.rmLink(link.Name)
108108

109109
await bucket.del(child.name)
110110

111-
return updateHamtDirectory(context, newNode.Links, bucket, options)
111+
return updateHamtDirectory(context, node.Links, bucket, options)
112112
}
113113

114114
log(`Descending into sub-shard ${link.Name} for ${prefix}${child.name}`)
@@ -135,8 +135,8 @@ const updateShard = async (context, positions, child, options) => {
135135
}
136136

137137
const updateShardParent = async (context, bucket, parent, oldName, newName, size, cid, options) => {
138-
parent = await DAGNode.rmLink(parent, oldName)
139-
parent = await DAGNode.addLink(parent, new DAGLink(newName, size, cid))
138+
parent.rmLink(oldName)
139+
parent.addLink(new DAGLink(newName, size, cid))
140140

141141
return updateHamtDirectory(context, parent.Links, bucket, options)
142142
}

src/core/utils/with-mfs-root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const loadMfsRoot = async (context) => {
3030
}
3131

3232
log('Creating new MFS root')
33-
const node = DAGNode.create(new UnixFs('directory').marshal())
33+
const node = new DAGNode(new UnixFs('directory').marshal())
3434
cid = await context.ipld.put(node, mc.DAG_PB, {
3535
cidVersion: 0,
3636
hashAlg: mh.names['sha2-256'] // why can't ipld look this up?

test/helpers/create-mfs.js

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

33
const core = require('../../src/core')
44
const isWebWorker = require('detect-webworker')
5-
const promisify = require('promisify-es6')
65
const {
76
MemoryDatastore
87
} = require('interface-datastore')
@@ -21,13 +20,6 @@ const createMfs = async () => {
2120
}
2221
})
2322

24-
repo.init = promisify(repo.init, {
25-
context: repo
26-
})
27-
repo.open = promisify(repo.open, {
28-
context: repo
29-
})
30-
3123
await repo.init({})
3224
await repo.open()
3325

0 commit comments

Comments
 (0)