Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5c718a6

Browse files
committedNov 12, 2018
fix: updates ipld-dag-pb dep to version without .cid properties
1 parent 8483084 commit 5c718a6

File tree

14 files changed

+549
-312
lines changed

14 files changed

+549
-312
lines changed
 

‎js/src/dag/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = (createCommon, options) => {
4646
(cb) => {
4747
const someData = Buffer.from('some other data')
4848

49-
pbNode = DAGNode.create(someData, (err, node) => {
49+
DAGNode.create(someData, (err, node) => {
5050
expect(err).to.not.exist()
5151
pbNode = node
5252
cb()

‎js/src/dag/put.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = (createCommon, options) => {
4141
before((done) => {
4242
const someData = Buffer.from('some data')
4343

44-
pbNode = DAGNode.create(someData, (err, node) => {
44+
DAGNode.create(someData, (err, node) => {
4545
expect(err).to.not.exist()
4646
pbNode = node
4747
done()

‎js/src/object/data.js

+51-35
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/* eslint-env mocha */
2+
/* eslint-disable max-nested-callbacks */
23
'use strict'
34

45
const bs58 = require('bs58')
56
const hat = require('hat')
67
const { getDescribe, getIt, expect } = require('../utils/mocha')
8+
const {
9+
calculateCid
10+
} = require('../utils/dag-pb')
711

812
module.exports = (createCommon, options) => {
913
const describe = getDescribe(options)
@@ -41,36 +45,40 @@ module.exports = (createCommon, options) => {
4145
ipfs.object.put(testObj, (err, node) => {
4246
expect(err).to.not.exist()
4347

44-
ipfs.object.data(node.multihash, (err, data) => {
48+
calculateCid(node, (err, nodeCid) => {
4549
expect(err).to.not.exist()
4650

47-
// because js-ipfs-api can't infer
48-
// if the returned Data is Buffer or String
49-
if (typeof data === 'string') {
50-
data = Buffer.from(data)
51-
}
52-
expect(node.data).to.eql(data)
53-
done()
51+
ipfs.object.data(nodeCid, (err, data) => {
52+
expect(err).to.not.exist()
53+
54+
// because js-ipfs-api can't infer
55+
// if the returned Data is Buffer or String
56+
if (typeof data === 'string') {
57+
data = Buffer.from(data)
58+
}
59+
expect(node.data).to.eql(data)
60+
done()
61+
})
5462
})
5563
})
5664
})
5765

58-
it('should get data by multihash (promised)', () => {
66+
it('should get data by multihash (promised)', async () => {
5967
const testObj = {
6068
Data: Buffer.from(hat()),
6169
Links: []
6270
}
6371

64-
return ipfs.object.put(testObj).then((node) => {
65-
return ipfs.object.data(node.multihash).then((data) => {
66-
// because js-ipfs-api can't infer
67-
// if the returned Data is Buffer or String
68-
if (typeof data === 'string') {
69-
data = Buffer.from(data)
70-
}
71-
expect(node.data).to.deep.equal(data)
72-
})
73-
})
72+
const node = await ipfs.object.put(testObj)
73+
const nodeCid = await calculateCid(node)
74+
let data = await ipfs.object.data(nodeCid)
75+
76+
// because js-ipfs-api can't infer
77+
// if the returned Data is Buffer or String
78+
if (typeof data === 'string') {
79+
data = Buffer.from(data)
80+
}
81+
expect(node.data).to.deep.equal(data)
7482
})
7583

7684
it('should get data by base58 encoded multihash', (done) => {
@@ -82,16 +90,20 @@ module.exports = (createCommon, options) => {
8290
ipfs.object.put(testObj, (err, node) => {
8391
expect(err).to.not.exist()
8492

85-
ipfs.object.data(bs58.encode(node.multihash), { enc: 'base58' }, (err, data) => {
93+
calculateCid(node, (err, nodeCid) => {
8694
expect(err).to.not.exist()
8795

88-
// because js-ipfs-api can't infer
89-
// if the returned Data is Buffer or String
90-
if (typeof data === 'string') {
91-
data = Buffer.from(data)
92-
}
93-
expect(node.data).to.eql(data)
94-
done()
96+
ipfs.object.data(bs58.encode(nodeCid.buffer), { enc: 'base58' }, (err, data) => {
97+
expect(err).to.not.exist()
98+
99+
// because js-ipfs-api can't infer
100+
// if the returned Data is Buffer or String
101+
if (typeof data === 'string') {
102+
data = Buffer.from(data)
103+
}
104+
expect(node.data).to.eql(data)
105+
done()
106+
})
95107
})
96108
})
97109
})
@@ -105,16 +117,20 @@ module.exports = (createCommon, options) => {
105117
ipfs.object.put(testObj, (err, node) => {
106118
expect(err).to.not.exist()
107119

108-
ipfs.object.data(bs58.encode(node.multihash).toString(), { enc: 'base58' }, (err, data) => {
120+
calculateCid(node, (err, nodeCid) => {
109121
expect(err).to.not.exist()
110122

111-
// because js-ipfs-api can't infer if the
112-
// returned Data is Buffer or String
113-
if (typeof data === 'string') {
114-
data = Buffer.from(data)
115-
}
116-
expect(node.data).to.eql(data)
117-
done()
123+
ipfs.object.data(bs58.encode(nodeCid.buffer).toString(), { enc: 'base58' }, (err, data) => {
124+
expect(err).to.not.exist()
125+
126+
// because js-ipfs-api can't infer if the
127+
// returned Data is Buffer or String
128+
if (typeof data === 'string') {
129+
data = Buffer.from(data)
130+
}
131+
expect(node.data).to.eql(data)
132+
done()
133+
})
118134
})
119135
})
120136
})

‎js/src/object/get.js

+132-52
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
const dagPB = require('ipld-dag-pb')
55
const DAGNode = dagPB.DAGNode
6-
const bs58 = require('bs58')
76
const series = require('async/series')
87
const hat = require('hat')
98
const { getDescribe, getIt, expect } = require('../utils/mocha')
109
const UnixFs = require('ipfs-unixfs')
1110
const crypto = require('crypto')
11+
const {
12+
calculateCid,
13+
asDAGLink
14+
} = require('../utils/dag-pb')
1215

1316
module.exports = (createCommon, options) => {
1417
const describe = getDescribe(options)
@@ -44,18 +47,26 @@ module.exports = (createCommon, options) => {
4447
}
4548

4649
let node1
50+
let node1Cid
4751
let node2
4852

4953
series([
5054
(cb) => {
5155
ipfs.object.put(obj, (err, node) => {
5256
expect(err).to.not.exist()
5357
node1 = node
54-
cb()
58+
59+
calculateCid(node, (err, result) => {
60+
expect(err).to.not.exist()
61+
62+
node1Cid = result
63+
64+
cb()
65+
})
5566
})
5667
},
5768
(cb) => {
58-
ipfs.object.get(node1.multihash, (err, node) => {
69+
ipfs.object.get(node1Cid, (err, node) => {
5970
expect(err).to.not.exist()
6071
node2 = node
6172

@@ -70,30 +81,29 @@ module.exports = (createCommon, options) => {
7081
(cb) => {
7182
expect(node1.data).to.eql(node2.data)
7283
expect(node1.links).to.eql(node2.links)
73-
expect(node1.multihash).to.eql(node2.multihash)
7484
cb()
7585
}
7686
], done)
7787
})
7888

79-
it('should get object by multihash (promised)', () => {
89+
it('should get object by multihash (promised)', async () => {
8090
const testObj = {
8191
Data: Buffer.from(hat()),
8292
Links: []
8393
}
8494

85-
return ipfs.object.put(testObj).then((node1) => {
86-
return ipfs.object.get(node1.multihash).then((node2) => {
87-
// because js-ipfs-api can't infer if the
88-
// returned Data is Buffer or String
89-
if (typeof node2.data === 'string') {
90-
node2.data = Buffer.from(node2.data)
91-
}
95+
const node1 = await ipfs.object.put(testObj)
96+
const node1Cid = await calculateCid(node1)
97+
const node2 = await ipfs.object.get(node1Cid)
9298

93-
expect(node1.data).to.deep.equal(node2.data)
94-
expect(node1.links).to.deep.equal(node2.links)
95-
})
96-
})
99+
// because js-ipfs-api can't infer if the
100+
// returned Data is Buffer or String
101+
if (typeof node2.data === 'string') {
102+
node2.data = Buffer.from(node2.data)
103+
}
104+
105+
expect(node1.data).to.deep.equal(node2.data)
106+
expect(node1.links).to.deep.equal(node2.links)
97107
})
98108

99109
it('should get object by multihash string', (done) => {
@@ -103,95 +113,126 @@ module.exports = (createCommon, options) => {
103113
}
104114

105115
let node1
116+
let node1Cid
106117
let node2
118+
let node2Cid
107119

108120
series([
109121
(cb) => {
110122
ipfs.object.put(obj, (err, node) => {
111123
expect(err).to.not.exist()
112124
node1 = node
113-
cb()
125+
126+
calculateCid(node, (err, result) => {
127+
expect(err).to.not.exist()
128+
129+
node1Cid = result
130+
131+
cb()
132+
})
114133
})
115134
},
116135
(cb) => {
117136
// get object from ipfs multihash string
118-
ipfs.object.get(node1.toJSON().multihash, (err, node) => {
137+
ipfs.object.get(node1Cid.toBaseEncodedString(), (err, node) => {
119138
expect(err).to.not.exist()
120139
// because js-ipfs-api can't infer if the
121140
// returned Data is Buffer or String
122141
if (typeof node.data === 'string') {
123142
node.data = Buffer.from(node.data)
124143
}
125144
node2 = node
126-
cb()
145+
146+
calculateCid(node, (err, result) => {
147+
expect(err).to.not.exist()
148+
149+
node2Cid = result
150+
151+
cb()
152+
})
127153
})
128154
},
129155
(cb) => {
130156
expect(node1.data).to.eql(node2.data)
131157
expect(node1.links).to.eql(node2.links)
132-
expect(node1.multihash).to.eql(node2.multihash)
158+
expect(node1Cid).to.deep.eql(node2Cid)
133159
cb()
134160
}
135161
], done)
136162
})
137163

138-
it('should get object by multihash string (promised)', () => {
164+
it('should get object by multihash string (promised)', async () => {
139165
const obj = {
140166
Data: Buffer.from(hat()),
141167
Links: []
142168
}
143169

144-
return ipfs.object.put(obj)
145-
.then((node1) => {
146-
return ipfs.object.get(node1.toJSON().multihash)
147-
.then((node2) => {
148-
// because js-ipfs-api can't infer if the
149-
// returned Data is Buffer or String
150-
if (typeof node2.data === 'string') {
151-
node2.data = Buffer.from(node2.data)
152-
}
153-
154-
expect(node1.data).to.deep.equal(node2.data)
155-
expect(node1.links).to.deep.equal(node2.links)
156-
})
157-
})
170+
const node1 = await ipfs.object.put(obj)
171+
const node1Cid = await calculateCid(node1)
172+
const node2 = await ipfs.object.get(node1Cid.toBaseEncodedString())
173+
const node2Cid = await calculateCid(node2)
174+
// because js-ipfs-api can't infer if the
175+
// returned Data is Buffer or String
176+
if (typeof node2.data === 'string') {
177+
node2.data = Buffer.from(node2.data)
178+
}
179+
180+
expect(node1.data).to.deep.equal(node2.data)
181+
expect(node1.links).to.deep.equal(node2.links)
182+
expect(node1Cid).to.deep.eql(node2Cid)
158183
})
159184

160185
it('should get object with links by multihash string', (done) => {
161186
let node1a
162187
let node1b
188+
let node1bCid
163189
let node1c
190+
let node1cCid
164191
let node2
165192

166193
series([
167194
(cb) => {
168195
DAGNode.create(Buffer.from('Some data 1'), (err, node) => {
169196
expect(err).to.not.exist()
170197
node1a = node
198+
171199
cb()
172200
})
173201
},
174202
(cb) => {
175203
DAGNode.create(Buffer.from('Some data 2'), (err, node) => {
176204
expect(err).to.not.exist()
177205
node2 = node
206+
178207
cb()
179208
})
180209
},
181210
(cb) => {
182-
const link = node2.toJSON()
183-
link.name = 'some-link'
184-
DAGNode.addLink(node1a, link, (err, node) => {
211+
asDAGLink(node2, 'some-link', (err, link) => {
185212
expect(err).to.not.exist()
186-
node1b = node
187-
cb()
213+
214+
DAGNode.addLink(node1a, link, (err, node) => {
215+
expect(err).to.not.exist()
216+
node1b = node
217+
cb()
218+
})
188219
})
189220
},
190221
(cb) => {
191-
ipfs.object.put(node1b, cb)
222+
ipfs.object.put(node1b, (err, node) => {
223+
expect(err).to.not.exist()
224+
225+
calculateCid(node, (err, result) => {
226+
expect(err).to.not.exist()
227+
228+
node1bCid = result
229+
230+
cb()
231+
})
232+
})
192233
},
193234
(cb) => {
194-
ipfs.object.get(node1b.multihash, (err, node) => {
235+
ipfs.object.get(node1bCid, (err, node) => {
195236
expect(err).to.not.exist()
196237

197238
// because js-ipfs-api can't infer if the
@@ -201,12 +242,19 @@ module.exports = (createCommon, options) => {
201242
}
202243

203244
node1c = node
204-
cb()
245+
246+
calculateCid(node, (err, result) => {
247+
expect(err).to.not.exist()
248+
249+
node1cCid = result
250+
251+
cb()
252+
})
205253
})
206254
},
207255
(cb) => {
208256
expect(node1a.data).to.eql(node1c.data)
209-
expect(node1b.multihash).to.eql(node1c.multihash)
257+
expect(node1bCid).to.eql(node1cCid)
210258
cb()
211259
}
212260
], done)
@@ -219,30 +267,46 @@ module.exports = (createCommon, options) => {
219267
}
220268

221269
let node1a
270+
let node1aCid
222271
let node1b
272+
let node1bCid
223273

224274
series([
225275
(cb) => {
226276
ipfs.object.put(obj, (err, node) => {
227277
expect(err).to.not.exist()
228278
node1a = node
229-
cb()
279+
280+
calculateCid(node, (err, result) => {
281+
expect(err).to.not.exist()
282+
283+
node1aCid = result
284+
285+
cb()
286+
})
230287
})
231288
},
232289
(cb) => {
233-
ipfs.object.get(node1a.multihash, { enc: 'base58' }, (err, node) => {
290+
ipfs.object.get(node1aCid, { enc: 'base58' }, (err, node) => {
234291
expect(err).to.not.exist()
235292
// because js-ipfs-api can't infer if the
236293
// returned Data is Buffer or String
237294
if (typeof node.data === 'string') {
238295
node.data = Buffer.from(node.data)
239296
}
240297
node1b = node
241-
cb()
298+
299+
calculateCid(node, (err, result) => {
300+
expect(err).to.not.exist()
301+
302+
node1bCid = result
303+
304+
cb()
305+
})
242306
})
243307
},
244308
(cb) => {
245-
expect(node1a.multihash).to.eql(node1b.multihash)
309+
expect(node1aCid).to.deep.eql(node1bCid)
246310
expect(node1a.data).to.eql(node1b.data)
247311
expect(node1a.links).to.eql(node1b.links)
248312
cb()
@@ -257,30 +321,46 @@ module.exports = (createCommon, options) => {
257321
}
258322

259323
let node1a
324+
let node1aCid
260325
let node1b
326+
let node1bCid
261327

262328
series([
263329
(cb) => {
264330
ipfs.object.put(obj, (err, node) => {
265331
expect(err).to.not.exist()
266332
node1a = node
267-
cb()
333+
334+
calculateCid(node, (err, result) => {
335+
expect(err).to.not.exist()
336+
337+
node1aCid = result
338+
339+
cb()
340+
})
268341
})
269342
},
270343
(cb) => {
271-
ipfs.object.get(bs58.encode(node1a.multihash).toString(), { enc: 'base58' }, (err, node) => {
344+
ipfs.object.get(node1aCid.toBaseEncodedString(), { enc: 'base58' }, (err, node) => {
272345
expect(err).to.not.exist()
273346
// because js-ipfs-api can't infer if the
274347
// returned Data is Buffer or String
275348
if (typeof node.data === 'string') {
276349
node.data = Buffer.from(node.data)
277350
}
278351
node1b = node
279-
cb()
352+
353+
calculateCid(node, (err, result) => {
354+
expect(err).to.not.exist()
355+
356+
node1bCid = result
357+
358+
cb()
359+
})
280360
})
281361
},
282362
(cb) => {
283-
expect(node1a.multihash).to.eql(node1b.multihash)
363+
expect(node1aCid).to.deep.eql(node1bCid)
284364
expect(node1a.data).to.eql(node1b.data)
285365
expect(node1a.links).to.eql(node1b.links)
286366
cb()

‎js/src/object/links.js

+51-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/* eslint-env mocha */
2+
/* eslint-disable max-nested-callbacks */
23
'use strict'
34

45
const dagPB = require('ipld-dag-pb')
56
const DAGNode = dagPB.DAGNode
6-
const bs58 = require('bs58')
77
const series = require('async/series')
88
const hat = require('hat')
99
const { getDescribe, getIt, expect } = require('../utils/mocha')
10+
const {
11+
calculateCid,
12+
asDAGLink
13+
} = require('../utils/dag-pb')
1014

1115
module.exports = (createCommon, options) => {
1216
const describe = getDescribe(options)
@@ -44,37 +48,43 @@ module.exports = (createCommon, options) => {
4448
ipfs.object.put(testObj, (err, node) => {
4549
expect(err).to.not.exist()
4650

47-
ipfs.object.links(node.multihash, (err, links) => {
51+
calculateCid(node, (err, cid) => {
4852
expect(err).to.not.exist()
49-
expect(node.links).to.deep.equal(links)
50-
done()
53+
54+
ipfs.object.links(cid, (err, links) => {
55+
expect(err).to.not.exist()
56+
expect(node.links).to.deep.equal(links)
57+
done()
58+
})
5159
})
5260
})
5361
})
5462

55-
it('should get empty links by multihash (promised)', () => {
63+
it('should get empty links by multihash (promised)', async () => {
5664
const testObj = {
5765
Data: Buffer.from(hat()),
5866
Links: []
5967
}
6068

61-
return ipfs.object.put(testObj).then((node) => {
62-
return ipfs.object.links(node.multihash).then((links) => {
63-
expect(node.links).to.eql(links)
64-
})
65-
})
69+
const node = await ipfs.object.put(testObj)
70+
const cid = await calculateCid(node)
71+
const links = await ipfs.object.links(cid)
72+
73+
expect(node.links).to.eql(links)
6674
})
6775

6876
it('should get links by multihash', (done) => {
6977
let node1a
7078
let node1b
79+
let node1bCid
7180
let node2
7281

7382
series([
7483
(cb) => {
7584
DAGNode.create(Buffer.from('Some data 1'), (err, node) => {
7685
expect(err).to.not.exist()
7786
node1a = node
87+
7888
cb()
7989
})
8090
},
@@ -86,20 +96,28 @@ module.exports = (createCommon, options) => {
8696
})
8797
},
8898
(cb) => {
89-
const link = node2.toJSON()
90-
link.name = 'some-link'
91-
92-
DAGNode.addLink(node1a, link, (err, node) => {
99+
asDAGLink(node2, 'some-link', (err, link) => {
93100
expect(err).to.not.exist()
94-
node1b = node
95-
cb()
101+
102+
DAGNode.addLink(node1a, link, (err, node) => {
103+
expect(err).to.not.exist()
104+
node1b = node
105+
106+
calculateCid(node, (err, cid) => {
107+
expect(err).to.not.exist()
108+
109+
node1bCid = cid
110+
111+
cb()
112+
})
113+
})
96114
})
97115
},
98116
(cb) => {
99-
ipfs.object.put(node1b, cb)
117+
ipfs.object.put(node1b, (cb))
100118
},
101119
(cb) => {
102-
ipfs.object.links(node1b.multihash, (err, links) => {
120+
ipfs.object.links(node1bCid, (err, links) => {
103121
expect(err).to.not.exist()
104122
expect(node1b.links[0].toJSON()).to.eql(links[0].toJSON())
105123
cb()
@@ -117,10 +135,14 @@ module.exports = (createCommon, options) => {
117135
ipfs.object.put(testObj, (err, node) => {
118136
expect(err).to.not.exist()
119137

120-
ipfs.object.links(bs58.encode(node.multihash), { enc: 'base58' }, (err, links) => {
138+
calculateCid(node, (err, cid) => {
121139
expect(err).to.not.exist()
122-
expect(node.links).to.deep.equal(links)
123-
done()
140+
141+
ipfs.object.links(cid.buffer, { enc: 'base58' }, (err, links) => {
142+
expect(err).to.not.exist()
143+
expect(node.links).to.deep.equal(links)
144+
done()
145+
})
124146
})
125147
})
126148
})
@@ -133,10 +155,15 @@ module.exports = (createCommon, options) => {
133155

134156
ipfs.object.put(testObj, (err, node) => {
135157
expect(err).to.not.exist()
136-
ipfs.object.links(bs58.encode(node.multihash), { enc: 'base58' }, (err, links) => {
158+
159+
calculateCid(node, (err, cid) => {
137160
expect(err).to.not.exist()
138-
expect(node.links).to.deep.equal(links)
139-
done()
161+
162+
ipfs.object.links(cid.toBaseEncodedString(), { enc: 'base58' }, (err, links) => {
163+
expect(err).to.not.exist()
164+
expect(node.links).to.deep.equal(links)
165+
done()
166+
})
140167
})
141168
})
142169
})

‎js/src/object/new.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
'use strict'
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5+
const {
6+
calculateCid
7+
} = require('../utils/dag-pb')
58

69
module.exports = (createCommon, options) => {
710
const describe = getDescribe(options)
@@ -33,27 +36,31 @@ module.exports = (createCommon, options) => {
3336
it('should create a new object with no template', (done) => {
3437
ipfs.object.new((err, node) => {
3538
expect(err).to.not.exist()
36-
const nodeJSON = node.toJSON()
37-
expect(nodeJSON.multihash).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
38-
done()
39+
40+
calculateCid(node, (err, cid) => {
41+
expect(err).to.not.exist()
42+
expect(cid.toBaseEncodedString()).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
43+
done()
44+
})
3945
})
4046
})
4147

42-
it('should create a new object with no template (promised)', () => {
43-
return ipfs.object.new()
44-
.then((node) => {
45-
const nodeJSON = node.toJSON()
46-
expect(nodeJSON.multihash).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
47-
})
48+
it('should create a new object with no template (promised)', async () => {
49+
const node = await ipfs.object.new()
50+
const cid = await calculateCid(node)
51+
52+
expect(cid.toBaseEncodedString()).to.equal('QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n')
4853
})
4954

5055
it('should create a new object with unixfs-dir template', (done) => {
5156
ipfs.object.new('unixfs-dir', (err, node) => {
5257
expect(err).to.not.exist()
53-
const nodeJSON = node.toJSON()
54-
expect(nodeJSON.multihash)
55-
.to.equal('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn')
56-
done()
58+
59+
calculateCid(node, (err, cid) => {
60+
expect(err).to.not.exist()
61+
expect(cid.toBaseEncodedString()).to.equal('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn')
62+
done()
63+
})
5764
})
5865
})
5966
})

‎js/src/object/patch/add-link.js

+50-59
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const dagPB = require('ipld-dag-pb')
55
const DAGNode = dagPB.DAGNode
66
const series = require('async/series')
77
const { getDescribe, getIt, expect } = require('../../utils/mocha')
8+
const {
9+
calculateCid,
10+
createDAGNode,
11+
addLinkToDAGNode
12+
} = require('../../utils/dag-pb')
813

914
module.exports = (createCommon, options) => {
1015
const describe = getDescribe(options)
@@ -35,6 +40,7 @@ module.exports = (createCommon, options) => {
3540

3641
it('should add a link to an existing node', (done) => {
3742
let testNodeMultihash
43+
let node1bMultihash
3844
let node1a
3945
let node1b
4046
let node2
@@ -48,8 +54,12 @@ module.exports = (createCommon, options) => {
4854
(cb) => {
4955
ipfs.object.put(obj, (err, node) => {
5056
expect(err).to.not.exist()
51-
testNodeMultihash = node.multihash
52-
cb()
57+
58+
calculateCid(node, (err, result) => {
59+
expect(err).to.not.exist()
60+
testNodeMultihash = result
61+
cb()
62+
})
5363
})
5464
},
5565
(cb) => {
@@ -72,19 +82,34 @@ module.exports = (createCommon, options) => {
7282
ipfs.object.put(node2, cb)
7383
},
7484
(cb) => {
75-
const link = node2.toJSON()
76-
link.name = 'link-to-node'
77-
DAGNode.addLink(node1a, link, (err, node) => {
85+
calculateCid(node2, (err, result) => {
7886
expect(err).to.not.exist()
79-
node1b = node
80-
cb()
87+
88+
DAGNode.addLink(node1a, {
89+
name: 'link-to-node',
90+
size: node2.toJSON().size,
91+
cid: result
92+
}, (err, node) => {
93+
expect(err).to.not.exist()
94+
node1b = node
95+
96+
calculateCid(node1b, (err, result) => {
97+
expect(err).to.not.exist()
98+
node1bMultihash = result
99+
cb()
100+
})
101+
})
81102
})
82103
},
83104
(cb) => {
84105
ipfs.object.patch.addLink(testNodeMultihash, node1b.links[0], (err, node) => {
85106
expect(err).to.not.exist()
86-
expect(node1b.multihash).to.eql(node.multihash)
87-
cb()
107+
108+
calculateCid(node, (err, result) => {
109+
expect(err).to.not.exist()
110+
expect(node1bMultihash).to.eql(result)
111+
cb()
112+
})
88113
})
89114
}
90115
/* TODO: revisit this assertions.
@@ -119,61 +144,27 @@ module.exports = (createCommon, options) => {
119144
], done)
120145
})
121146

122-
it('should add a link to an existing node (promised)', () => {
123-
let testNodeMultihash
124-
let node1a
125-
let node1b
126-
let node2
127-
147+
it('should add a link to an existing node (promised)', async () => {
128148
const obj = {
129149
Data: Buffer.from('patch test object (promised)'),
130150
Links: []
131151
}
132152

133-
return ipfs.object.put(obj)
134-
.then((node) => {
135-
testNodeMultihash = node.multihash
136-
})
137-
.then(() => new Promise((resolve, reject) => {
138-
DAGNode.create(obj.Data, obj.Links, function (err, node) {
139-
if (err) {
140-
return reject(err)
141-
}
142-
return resolve(node)
143-
})
144-
}))
145-
.then((node) => {
146-
node1a = node
147-
return new Promise((resolve, reject) => {
148-
DAGNode.create(Buffer.from('some other node'), function (err, node) {
149-
if (err) {
150-
return reject(err)
151-
}
152-
return resolve(node)
153-
})
154-
}).then((node1) => {
155-
node2 = node1
156-
return ipfs.object.put(node2)
157-
})
158-
})
159-
.then(() => {
160-
const link = node2.toJSON()
161-
link.name = 'link-to-node'
162-
return new Promise((resolve, reject) => {
163-
DAGNode.addLink(node1a, link, function (err, node) {
164-
if (err) {
165-
return reject(err)
166-
}
167-
return resolve(node)
168-
})
169-
}).then((node) => {
170-
node1b = node
171-
return ipfs.object.patch.addLink(testNodeMultihash, node1b.links[0])
172-
})
173-
})
174-
.then((node) => {
175-
expect(node1b.multihash).to.eql(node.multihash)
176-
})
153+
const parent = await ipfs.object.put(obj)
154+
const parentCid = await calculateCid(parent)
155+
const child = await ipfs.object.put(await createDAGNode(Buffer.from('some other node'), []))
156+
const childCid = await calculateCid(child)
157+
const newParent = await addLinkToDAGNode(parent, {
158+
name: 'link-to-node',
159+
size: child.size,
160+
cid: childCid
161+
})
162+
const newParentCid = await calculateCid(newParent)
163+
164+
const nodeFromObjectPatch = await ipfs.object.patch.addLink(parentCid, newParent.links[0])
165+
const nodeFromObjectPatchCid = await calculateCid(nodeFromObjectPatch)
166+
167+
expect(newParentCid).to.eql(nodeFromObjectPatchCid)
177168
})
178169
})
179170
}

‎js/src/object/patch/append-data.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* eslint-env mocha */
2+
/* eslint-disable max-nested-callbacks */
23
'use strict'
34

45
const { getDescribe, getIt, expect } = require('../../utils/mocha')
6+
const {
7+
calculateCid
8+
} = require('../../utils/dag-pb')
59

610
module.exports = (createCommon, options) => {
711
const describe = getDescribe(options)
@@ -39,28 +43,35 @@ module.exports = (createCommon, options) => {
3943
ipfs.object.put(obj, (err, node) => {
4044
expect(err).to.not.exist()
4145

42-
ipfs.object.patch.appendData(node.multihash, Buffer.from('append'), (err, patchedNode) => {
46+
calculateCid(node, (err, nodeCid) => {
4347
expect(err).to.not.exist()
44-
expect(patchedNode.multihash).to.not.deep.equal(node.multihash)
45-
done()
48+
49+
ipfs.object.patch.appendData(nodeCid, Buffer.from('append'), (err, patchedNode) => {
50+
expect(err).to.not.exist()
51+
52+
calculateCid(patchedNode, (err, patchedNodeCid) => {
53+
expect(err).to.not.exist()
54+
expect(patchedNodeCid).to.not.deep.equal(nodeCid)
55+
56+
done()
57+
})
58+
})
4659
})
4760
})
4861
})
4962

50-
it('should append data to an existing node (promised)', () => {
63+
it('should append data to an existing node (promised)', async () => {
5164
const obj = {
5265
Data: Buffer.from('patch test object (promised)'),
5366
Links: []
5467
}
5568

56-
return ipfs.object.put(obj)
57-
.then((node) => {
58-
return ipfs.object.patch.appendData(node.multihash, Buffer.from('append'))
59-
.then((patchedNode) => ({ patchedNode, node }))
60-
})
61-
.then(({ patchedNode, node }) => {
62-
expect(patchedNode.multihash).to.not.deep.equal(node.multihash)
63-
})
69+
const node = await ipfs.object.put(obj)
70+
const nodeCid = await calculateCid(node)
71+
const patchedNode = await ipfs.object.patch.appendData(nodeCid, Buffer.from('append'))
72+
const patchedNodeCid = await calculateCid(patchedNode)
73+
74+
expect(nodeCid).to.not.deep.equal(patchedNodeCid)
6475
})
6576
})
6677
}

‎js/src/object/patch/rm-link.js

+55-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const dagPB = require('ipld-dag-pb')
55
const DAGLink = dagPB.DAGLink
66
const series = require('async/series')
77
const { getDescribe, getIt, expect } = require('../../utils/mocha')
8+
const {
9+
calculateCid,
10+
asDAGLink
11+
} = require('../../utils/dag-pb')
812

913
module.exports = (createCommon, options) => {
1014
const describe = getDescribe(options)
@@ -34,9 +38,10 @@ module.exports = (createCommon, options) => {
3438
after((done) => common.teardown(done))
3539

3640
it('should remove a link from an existing node', (done) => {
37-
let node1a
38-
let node1b
41+
let node1aCid
42+
let node1bCid
3943
let node2
44+
let node2Cid
4045
let testLink
4146

4247
const obj1 = {
@@ -53,31 +58,57 @@ module.exports = (createCommon, options) => {
5358
(cb) => {
5459
ipfs.object.put(obj1, (err, node) => {
5560
expect(err).to.not.exist()
56-
node1a = node
57-
cb()
61+
62+
calculateCid(node, (err, result) => {
63+
expect(err).to.not.exist()
64+
65+
node1aCid = result
66+
67+
cb()
68+
})
5869
})
5970
},
6071
(cb) => {
6172
ipfs.object.put(obj2, (err, node) => {
6273
expect(err).to.not.exist()
6374
node2 = node
64-
cb()
75+
76+
calculateCid(node, (err, result) => {
77+
expect(err).to.not.exist()
78+
79+
node2Cid = result
80+
81+
cb()
82+
})
6583
})
6684
},
6785
(cb) => {
68-
testLink = new DAGLink('link-to-node', node2.size, node2.multihash)
86+
testLink = new DAGLink('link-to-node', node2.size, node2Cid)
6987

70-
ipfs.object.patch.addLink(node1a.multihash, testLink, (err, node) => {
88+
ipfs.object.patch.addLink(node1aCid, testLink, (err, node) => {
7189
expect(err).to.not.exist()
72-
node1b = node
73-
cb()
90+
91+
calculateCid(node, (err, result) => {
92+
expect(err).to.not.exist()
93+
94+
node1bCid = result
95+
96+
cb()
97+
})
7498
})
7599
},
76100
(cb) => {
77-
ipfs.object.patch.rmLink(node1b.multihash, testLink, (err, node) => {
101+
ipfs.object.patch.rmLink(node1bCid, testLink, (err, node) => {
78102
expect(err).to.not.exist()
79-
expect(node.multihash).to.not.deep.equal(node1b.multihash)
80-
cb()
103+
104+
calculateCid(node, (err, result) => {
105+
expect(err).to.not.exist()
106+
107+
expect(result).to.not.deep.equal(node1bCid)
108+
expect(result).to.deep.equal(node1aCid)
109+
110+
cb()
111+
})
81112
})
82113
}
83114
/* TODO: revisit this assertions.
@@ -92,12 +123,7 @@ module.exports = (createCommon, options) => {
92123
], done)
93124
})
94125

95-
it('should remove a link from an existing node (promised)', () => {
96-
let node1a
97-
let node1b
98-
let node2
99-
let testLink
100-
126+
it('should remove a link from an existing node (promised)', async () => {
101127
const obj1 = {
102128
Data: Buffer.from('patch test object 1'),
103129
Links: []
@@ -108,17 +134,17 @@ module.exports = (createCommon, options) => {
108134
Links: []
109135
}
110136

111-
return ipfs.object.put(obj1)
112-
.then((node) => { node1a = node })
113-
.then(() => ipfs.object.put(obj2))
114-
.then((node) => { node2 = node })
115-
.then(() => {
116-
testLink = new DAGLink('link-to-node', node2.size, node2.multihash)
117-
return ipfs.object.patch.addLink(node1a.multihash, testLink)
118-
})
119-
.then((node) => { node1b = node })
120-
.then(() => ipfs.object.patch.rmLink(node1b.multihash, testLink))
121-
.then((node) => expect(node.multihash).to.not.deep.equal(node1b.multihash))
137+
const node = await ipfs.object.put(obj1)
138+
const nodeCid = await calculateCid(node)
139+
const child = await ipfs.object.put(obj2)
140+
const childAsDAGLink = await asDAGLink(child, 'my-link')
141+
const parent = await ipfs.object.patch.addLink(nodeCid, childAsDAGLink)
142+
const parentCid = await calculateCid(parent)
143+
const withoutChild = await ipfs.object.patch.rmLink(parentCid, childAsDAGLink)
144+
const withoutChildCid = await calculateCid(withoutChild)
145+
146+
expect(withoutChildCid).to.not.deep.equal(parentCid)
147+
expect(withoutChildCid).to.deep.equal(nodeCid)
122148
})
123149
})
124150
}

‎js/src/object/patch/set-data.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* eslint-env mocha */
2+
/* eslint-disable max-nested-callbacks */
23
'use strict'
34

45
const { getDescribe, getIt, expect } = require('../../utils/mocha')
6+
const {
7+
calculateCid
8+
} = require('../../utils/dag-pb')
59

610
module.exports = (createCommon, options) => {
711
const describe = getDescribe(options)
@@ -39,28 +43,34 @@ module.exports = (createCommon, options) => {
3943
ipfs.object.put(obj, (err, node) => {
4044
expect(err).to.not.exist()
4145

42-
ipfs.object.patch.setData(node.multihash, Buffer.from('set'), (err, patchedNode) => {
46+
calculateCid(node, (err, nodeCid) => {
4347
expect(err).to.not.exist()
44-
expect(node.multihash).to.not.deep.equal(patchedNode.multihash)
45-
done()
48+
49+
ipfs.object.patch.setData(nodeCid, Buffer.from('set'), (err, patchedNode) => {
50+
expect(err).to.not.exist()
51+
52+
calculateCid(patchedNode, (err, patchedNodeCid) => {
53+
expect(err).to.not.exist()
54+
55+
done()
56+
})
57+
})
4658
})
4759
})
4860
})
4961

50-
it('should set data for an existing node (promised)', () => {
62+
it('should set data for an existing node (promised)', async () => {
5163
const obj = {
5264
Data: Buffer.from('patch test object (promised)'),
5365
Links: []
5466
}
5567

56-
return ipfs.object.put(obj)
57-
.then((node) => {
58-
return ipfs.object.patch.setData(node.multihash, Buffer.from('set'))
59-
.then((patchedNode) => ({ patchedNode, node }))
60-
})
61-
.then(({ patchedNode, node }) => {
62-
expect(node.multihash).to.not.deep.equal(patchedNode.multihash)
63-
})
68+
const node = await ipfs.object.put(obj)
69+
const nodeCid = await calculateCid(node)
70+
const patchedNode = await ipfs.object.patch.setData(nodeCid, Buffer.from('set'))
71+
const patchedNodeCid = await calculateCid(patchedNode)
72+
73+
expect(nodeCid).to.not.deep.equal(patchedNodeCid)
6474
})
6575
})
6676
}

‎js/src/object/put.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const DAGNode = dagPB.DAGNode
66
const series = require('async/series')
77
const hat = require('hat')
88
const { getDescribe, getIt, expect } = require('../utils/mocha')
9+
const {
10+
asDAGLink
11+
} = require('../utils/dag-pb')
912

1013
module.exports = (createCommon, options) => {
1114
const describe = getDescribe(options)
@@ -45,24 +48,21 @@ module.exports = (createCommon, options) => {
4548
const nodeJSON = node.toJSON()
4649
expect(nodeJSON.data).to.eql(obj.Data)
4750
expect(nodeJSON.links).to.eql(obj.Links)
48-
expect(nodeJSON.multihash).to.exist()
4951
done()
5052
})
5153
})
5254

53-
it('should put an object (promised)', () => {
55+
it('should put an object (promised)', async () => {
5456
const obj = {
5557
Data: Buffer.from(hat()),
5658
Links: []
5759
}
5860

59-
return ipfs.object.put(obj)
60-
.then((node) => {
61-
const nodeJSON = node.toJSON()
62-
expect(obj.Data).to.deep.equal(nodeJSON.data)
63-
expect(obj.Links).to.deep.equal(nodeJSON.links)
64-
expect(nodeJSON.multihash).to.exist()
65-
})
61+
const node = await ipfs.object.put(obj)
62+
63+
const nodeJSON = node.toJSON()
64+
expect(obj.Data).to.deep.equal(nodeJSON.data)
65+
expect(obj.Links).to.deep.equal(nodeJSON.links)
6666
})
6767

6868
it('should put a JSON encoded Buffer', (done) => {
@@ -83,7 +83,6 @@ module.exports = (createCommon, options) => {
8383
const nodeJSON = node.toJSON()
8484

8585
expect(nodeJSON.data).to.eql(node.data)
86-
expect(nodeJSON.multihash).to.exist()
8786
done()
8887
})
8988
})
@@ -112,7 +111,6 @@ module.exports = (createCommon, options) => {
112111
expect(err).to.not.exist()
113112
expect(node.data).to.deep.equal(node.data)
114113
expect(node.links).to.deep.equal(node.links)
115-
expect(node.multihash).to.eql(storedNode.multihash)
116114
cb()
117115
})
118116
}
@@ -126,7 +124,6 @@ module.exports = (createCommon, options) => {
126124
const nodeJSON = node.toJSON()
127125
expect(data).to.deep.equal(nodeJSON.data)
128126
expect([]).to.deep.equal(nodeJSON.links)
129-
expect(nodeJSON.multihash).to.exist()
130127
done()
131128
})
132129
})
@@ -171,12 +168,14 @@ module.exports = (createCommon, options) => {
171168
})
172169
},
173170
(cb) => {
174-
const link = node2.toJSON()
175-
link.name = 'some-link'
176-
DAGNode.addLink(node1a, link, (err, node) => {
171+
asDAGLink(node2, 'some-link', (err, link) => {
177172
expect(err).to.not.exist()
178-
node1b = node
179-
cb()
173+
174+
DAGNode.addLink(node1a, link, (err, node) => {
175+
expect(err).to.not.exist()
176+
node1b = node
177+
cb()
178+
})
180179
})
181180
},
182181
(cb) => {

‎js/src/object/stat.js

+83-56
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/* eslint-env mocha */
2+
/* eslint-disable max-nested-callbacks */
23
'use strict'
34

45
const dagPB = require('ipld-dag-pb')
56
const DAGNode = dagPB.DAGNode
6-
const bs58 = require('bs58')
77
const series = require('async/series')
88
const { getDescribe, getIt, expect } = require('../utils/mocha')
9+
const {
10+
calculateCid,
11+
asDAGLink
12+
} = require('../utils/dag-pb')
913

1014
module.exports = (createCommon, options) => {
1115
const describe = getDescribe(options)
@@ -43,33 +47,11 @@ module.exports = (createCommon, options) => {
4347
ipfs.object.put(testObj, (err, node) => {
4448
expect(err).to.not.exist()
4549

46-
ipfs.object.stat(node.multihash, (err, stats) => {
50+
calculateCid(node, (err, cid) => {
4751
expect(err).to.not.exist()
48-
const expected = {
49-
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
50-
NumLinks: 0,
51-
BlockSize: 17,
52-
LinksSize: 2,
53-
DataSize: 15,
54-
CumulativeSize: 17
55-
}
56-
expect(expected).to.deep.equal(stats)
57-
done()
58-
})
59-
})
60-
})
6152

62-
it('should get stats for object by multihash (promised)', () => {
63-
const testObj = {
64-
Data: Buffer.from('get test object'),
65-
Links: []
66-
}
67-
68-
return ipfs.object.put(testObj, (err, node) => {
69-
expect(err).to.not.exist()
70-
71-
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', { enc: 'base58' })
72-
.then((stats) => {
53+
ipfs.object.stat(cid, (err, stats) => {
54+
expect(err).to.not.exist()
7355
const expected = {
7456
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
7557
NumLinks: 0,
@@ -79,13 +61,37 @@ module.exports = (createCommon, options) => {
7961
CumulativeSize: 17
8062
}
8163
expect(expected).to.deep.equal(stats)
64+
done()
8265
})
66+
})
8367
})
8468
})
8569

70+
it('should get stats for object by multihash (promised)', async () => {
71+
const testObj = {
72+
Data: Buffer.from('get test object'),
73+
Links: []
74+
}
75+
76+
await ipfs.object.put(testObj)
77+
const stats = await ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', { enc: 'base58' })
78+
79+
const expected = {
80+
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
81+
NumLinks: 0,
82+
BlockSize: 17,
83+
LinksSize: 2,
84+
DataSize: 15,
85+
CumulativeSize: 17
86+
}
87+
88+
expect(expected).to.deep.equal(stats)
89+
})
90+
8691
it('should get stats for object with links by multihash', (done) => {
8792
let node1a
8893
let node1b
94+
let node1bCid
8995
let node2
9096

9197
series([
@@ -104,20 +110,33 @@ module.exports = (createCommon, options) => {
104110
})
105111
},
106112
(cb) => {
107-
const link = node2.toJSON()
108-
link.name = 'some-link'
109-
110-
DAGNode.addLink(node1a, link, (err, node) => {
113+
asDAGLink(node2, 'some-link', (err, link) => {
111114
expect(err).to.not.exist()
112-
node1b = node
113-
cb()
115+
116+
DAGNode.addLink(node1a, link, (err, node) => {
117+
expect(err).to.not.exist()
118+
119+
node1b = node
120+
121+
cb()
122+
})
114123
})
115124
},
116125
(cb) => {
117-
ipfs.object.put(node1b, cb)
126+
ipfs.object.put(node1b, (err, node) => {
127+
expect(err).to.not.exist()
128+
129+
calculateCid(node, (err, cid) => {
130+
expect(err).to.not.exist()
131+
132+
node1bCid = cid
133+
134+
cb()
135+
})
136+
})
118137
},
119138
(cb) => {
120-
ipfs.object.stat(node1b.multihash, (err, stats) => {
139+
ipfs.object.stat(node1bCid, (err, stats) => {
121140
expect(err).to.not.exist()
122141
const expected = {
123142
Hash: 'QmPR7W4kaADkAo4GKEVVPQN81EDUFCHJtqejQZ5dEG7pBC',
@@ -143,18 +162,22 @@ module.exports = (createCommon, options) => {
143162
ipfs.object.put(testObj, (err, node) => {
144163
expect(err).to.not.exist()
145164

146-
ipfs.object.stat(bs58.encode(node.multihash), { enc: 'base58' }, (err, stats) => {
165+
calculateCid(node, (err, cid) => {
147166
expect(err).to.not.exist()
148-
const expected = {
149-
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
150-
NumLinks: 0,
151-
BlockSize: 17,
152-
LinksSize: 2,
153-
DataSize: 15,
154-
CumulativeSize: 17
155-
}
156-
expect(expected).to.deep.equal(stats)
157-
done()
167+
168+
ipfs.object.stat(cid.buffer, { enc: 'base58' }, (err, stats) => {
169+
expect(err).to.not.exist()
170+
const expected = {
171+
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
172+
NumLinks: 0,
173+
BlockSize: 17,
174+
LinksSize: 2,
175+
DataSize: 15,
176+
CumulativeSize: 17
177+
}
178+
expect(expected).to.deep.equal(stats)
179+
done()
180+
})
158181
})
159182
})
160183
})
@@ -168,18 +191,22 @@ module.exports = (createCommon, options) => {
168191
ipfs.object.put(testObj, (err, node) => {
169192
expect(err).to.not.exist()
170193

171-
ipfs.object.stat(bs58.encode(node.multihash).toString(), { enc: 'base58' }, (err, stats) => {
194+
calculateCid(node, (err, cid) => {
172195
expect(err).to.not.exist()
173-
const expected = {
174-
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
175-
NumLinks: 0,
176-
BlockSize: 17,
177-
LinksSize: 2,
178-
DataSize: 15,
179-
CumulativeSize: 17
180-
}
181-
expect(expected).to.deep.equal(stats)
182-
done()
196+
197+
ipfs.object.stat(cid.toBaseEncodedString(), { enc: 'base58' }, (err, stats) => {
198+
expect(err).to.not.exist()
199+
const expected = {
200+
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
201+
NumLinks: 0,
202+
BlockSize: 17,
203+
LinksSize: 2,
204+
DataSize: 15,
205+
CumulativeSize: 17
206+
}
207+
expect(expected).to.deep.equal(stats)
208+
done()
209+
})
183210
})
184211
})
185212
})

‎js/src/utils/dag-pb.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict'
2+
3+
const {
4+
promisify
5+
} = require('es6-promisify')
6+
const {
7+
util: {
8+
cid
9+
},
10+
DAGNode,
11+
DAGLink
12+
} = require('ipld-dag-pb')
13+
14+
module.exports.calculateCid = promisify((node, cb) => {
15+
cid(node, cb)
16+
})
17+
18+
module.exports.createDAGNode = promisify((data, links, cb) => {
19+
DAGNode.create(data, links, cb)
20+
})
21+
22+
module.exports.addLinkToDAGNode = promisify((parent, link, cb) => {
23+
DAGNode.addLink(parent, link, cb)
24+
})
25+
26+
module.exports.asDAGLink = promisify((node, name, cb) => {
27+
if (typeof name === 'function') {
28+
cb = name
29+
name = ''
30+
}
31+
32+
cid(node, (err, nodeCid) => {
33+
if (err) {
34+
return cb(err)
35+
}
36+
37+
DAGLink.create(name, node.size, nodeCid, cb)
38+
})
39+
})

‎package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"main": "js/src/index.js",
77
"scripts": {
88
"test": "exit 0",
9+
"test:node": "exit 0",
10+
"test:browser": "exit 0",
11+
"test:webworker": "exit 0",
912
"lint": "aegir lint",
1013
"release": "aegir release -t node --no-docs --no-build --no-test",
1114
"release-minor": "aegir release -t node --type minor --no-docs --no-build --no-test",
@@ -40,11 +43,12 @@
4043
"concat-stream": "^1.6.2",
4144
"crypto": "^1.0.1",
4245
"dirty-chai": "^2.0.1",
46+
"es6-promisify": "^6.0.1",
4347
"hat": "0.0.3",
4448
"ipfs-block": "~0.8.0",
4549
"ipfs-unixfs": "~0.1.16",
4650
"ipld-dag-cbor": "~0.13.0",
47-
"ipld-dag-pb": "~0.14.11",
51+
"ipld-dag-pb": "~0.15.0",
4852
"is-ipfs": "~0.4.7",
4953
"libp2p-crypto": "~0.14.0",
5054
"multiaddr": "^5.0.0",

0 commit comments

Comments
 (0)
This repository has been archived.