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

Commit 140e221

Browse files
committed
chore: upgrade dag-pb to the new, new api
1 parent 1a08a28 commit 140e221

File tree

11 files changed

+46
-42
lines changed

11 files changed

+46
-42
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"async": "^2.6.2",
4040
"bl": "^3.0.0",
4141
"bs58": "^4.0.1",
42+
"callbackify": "^1.1.0",
4243
"chai": "^4.2.0",
4344
"cids": "~0.7.1",
4445
"concat-stream": "^2.0.0",
@@ -50,7 +51,7 @@
5051
"ipfs-unixfs": "~0.1.16",
5152
"ipfs-utils": "~0.1.0",
5253
"ipld-dag-cbor": "~0.15.0",
53-
"ipld-dag-pb": "~0.17.3",
54+
"ipld-dag-pb": "^0.18.1",
5455
"is-ipfs": "~0.6.1",
5556
"is-plain-object": "^3.0.0",
5657
"it-pushable": "^1.2.1",

src/dag/get.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = (createCommon, options) => {
4949
const someData = Buffer.from('some other data')
5050

5151
try {
52-
pbNode = DAGNode.create(someData)
52+
pbNode = new DAGNode(someData)
5353
} catch (err) {
5454
return cb(err)
5555
}
@@ -62,15 +62,15 @@ module.exports = (createCommon, options) => {
6262
},
6363
(cb) => {
6464
try {
65-
nodePb = DAGNode.create(Buffer.from('I am inside a Protobuf'))
65+
nodePb = new DAGNode(Buffer.from('I am inside a Protobuf'))
6666
} catch (err) {
6767
return cb(err)
6868
}
6969

7070
cb()
7171
},
7272
(cb) => {
73-
dagPB.util.cid(dagPB.util.serialize(nodePb))
73+
dagPB.util.cid(nodePb.serialize())
7474
.then(cid => {
7575
cidPb = cid
7676
cb()
@@ -139,7 +139,7 @@ module.exports = (createCommon, options) => {
139139

140140
const node = result.value
141141

142-
dagPB.util.cid(dagPB.util.serialize(node))
142+
dagPB.util.cid(node.serialize())
143143
.then(cid => {
144144
expect(cid).to.eql(cidPb)
145145
done()
@@ -232,7 +232,7 @@ module.exports = (createCommon, options) => {
232232
it('should get a node added as CIDv0 with a CIDv1', done => {
233233
const input = Buffer.from(`TEST${Date.now()}`)
234234

235-
const node = dagPB.DAGNode.create(input)
235+
const node = new DAGNode(input)
236236

237237
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
238238
expect(err).to.not.exist()

src/dag/put.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = (createCommon, options) => {
4242
const someData = Buffer.from('some data')
4343

4444
try {
45-
pbNode = DAGNode.create(someData)
45+
pbNode = new DAGNode(someData)
4646
} catch (err) {
4747
return done(err)
4848
}

src/dag/tree.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const series = require('async/series')
55
const eachSeries = require('async/eachSeries')
66
const dagPB = require('ipld-dag-pb')
7+
const DAGNode = dagPB.DAGNode
78
const dagCBOR = require('ipld-dag-cbor')
89
const { spawnNodeWithId } = require('../utils/spawn')
910
const { getDescribe, getIt, expect } = require('../utils/mocha')
@@ -43,15 +44,15 @@ module.exports = (createCommon, options) => {
4344
series([
4445
(cb) => {
4546
try {
46-
nodePb = dagPB.DAGNode.create(Buffer.from('I am inside a Protobuf'))
47+
nodePb = new DAGNode(Buffer.from('I am inside a Protobuf'))
4748
} catch (err) {
4849
return cb(err)
4950
}
5051

5152
cb()
5253
},
5354
(cb) => {
54-
dagPB.util.cid(dagPB.util.serialize(nodePb))
55+
dagPB.util.cid(nodePb.serialize())
5556
.then(cid => {
5657
cidPb = cid
5758
cb()

src/object/get.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const hat = require('hat')
88
const { getDescribe, getIt, expect } = require('../utils/mocha')
99
const UnixFs = require('ipfs-unixfs')
1010
const crypto = require('crypto')
11-
const { asDAGLink } = require('./utils')
11+
const callbackify = require('callbackify')
1212

1313
module.exports = (createCommon, options) => {
1414
const describe = getDescribe(options)
@@ -67,7 +67,7 @@ module.exports = (createCommon, options) => {
6767
// because js-ipfs-api can't infer if the
6868
// returned Data is Buffer or String
6969
if (typeof node.Data === 'string') {
70-
node = DAGNode.create(Buffer.from(node.Data), node.Links, node.size)
70+
node = new DAGNode(Buffer.from(node.Data), node.Links, node.size)
7171
}
7272

7373
node2 = node
@@ -96,7 +96,7 @@ module.exports = (createCommon, options) => {
9696
// because js-ipfs-api can't infer if the
9797
// returned Data is Buffer or String
9898
if (typeof node2.Data === 'string') {
99-
node2 = DAGNode.create(Buffer.from(node2.Data), node2.Links, node2.size)
99+
node2 = new DAGNode(Buffer.from(node2.Data), node2.Links, node2.size)
100100
}
101101

102102
expect(node1.Data).to.deep.equal(node2.Data)
@@ -133,7 +133,7 @@ module.exports = (createCommon, options) => {
133133
// because js-ipfs-api can't infer if the
134134
// returned Data is Buffer or String
135135
if (typeof node.Data === 'string') {
136-
node = DAGNode.create(Buffer.from(node.Data), node.Links, node.size)
136+
node = new DAGNode(Buffer.from(node.Data), node.Links, node.size)
137137
}
138138

139139
node2 = node
@@ -161,7 +161,7 @@ module.exports = (createCommon, options) => {
161161
// because js-ipfs-api can't infer if the
162162
// returned Data is Buffer or String
163163
if (typeof node2.Data === 'string') {
164-
node2 = DAGNode.create(Buffer.from(node2.Data), node2.Links, node2.size)
164+
node2 = new DAGNode(Buffer.from(node2.Data), node2.Links, node2.size)
165165
}
166166

167167
expect(node1.Data).to.deep.equal(node2.Data)
@@ -178,7 +178,7 @@ module.exports = (createCommon, options) => {
178178
series([
179179
(cb) => {
180180
try {
181-
node1a = DAGNode.create(Buffer.from('Some data 1'))
181+
node1a = new DAGNode(Buffer.from('Some data 1'))
182182
} catch (err) {
183183
return cb(err)
184184
}
@@ -187,22 +187,24 @@ module.exports = (createCommon, options) => {
187187
},
188188
(cb) => {
189189
try {
190-
node2 = DAGNode.create(Buffer.from('Some data 2'))
190+
node2 = new DAGNode(Buffer.from('Some data 2'))
191191
} catch (err) {
192192
return cb(err)
193193
}
194194

195195
cb()
196196
},
197197
(cb) => {
198-
asDAGLink(node2, 'some-link', (err, link) => {
199-
expect(err).to.not.exist()
198+
callbackify.variadic(node2.toDAGLink.bind(node2))({
199+
name: 'some-link'
200+
}, (err, link) => {
201+
if (err) {
202+
return cb(err)
203+
}
200204

201-
DAGNode.addLink(node1a, link)
202-
.then(node => {
203-
node1b = node
204-
cb()
205-
}, cb)
205+
node1b = new DAGNode(node1a.Data, node1a.Links.concat(link))
206+
207+
cb()
206208
})
207209
},
208210
(cb) => {
@@ -219,7 +221,7 @@ module.exports = (createCommon, options) => {
219221
// because js-ipfs-api can't infer if the
220222
// returned Data is Buffer or String
221223
if (typeof node.Data === 'string') {
222-
node = DAGNode.create(Buffer.from(node.Data), node.Links, node.size)
224+
node = new DAGNode(Buffer.from(node.Data), node.Links, node.size)
223225
}
224226

225227
node1c = node
@@ -262,7 +264,7 @@ module.exports = (createCommon, options) => {
262264
// because js-ipfs-api can't infer if the
263265
// returned Data is Buffer or String
264266
if (typeof node.Data === 'string') {
265-
node = DAGNode.create(Buffer.from(node.Data), node.Links, node.size)
267+
node = new DAGNode(Buffer.from(node.Data), node.Links, node.size)
266268
}
267269
node1b = node
268270
cb()
@@ -305,7 +307,7 @@ module.exports = (createCommon, options) => {
305307
// because js-ipfs-api can't infer if the
306308
// returned Data is Buffer or String
307309
if (typeof node.Data === 'string') {
308-
node = DAGNode.create(Buffer.from(node.Data), node.Links, node.size)
310+
node = new DAGNode(Buffer.from(node.Data), node.Links, node.size)
309311
}
310312
node1b = node
311313
cb()

src/object/links.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = (createCommon, options) => {
8080
series([
8181
(cb) => {
8282
try {
83-
node1a = DAGNode.create(Buffer.from('Some data 1'))
83+
node1a = new DAGNode(Buffer.from('Some data 1'))
8484
} catch (err) {
8585
return cb(err)
8686
}
@@ -89,7 +89,7 @@ module.exports = (createCommon, options) => {
8989
},
9090
(cb) => {
9191
try {
92-
node2 = DAGNode.create(Buffer.from('Some data 2'))
92+
node2 = new DAGNode(Buffer.from('Some data 2'))
9393
} catch (err) {
9494
return cb(err)
9595
}
@@ -104,7 +104,7 @@ module.exports = (createCommon, options) => {
104104
.then(node => {
105105
node1b = node
106106

107-
return dagPB.util.cid(dagPB.util.serialize(node1b))
107+
return dagPB.util.cid(node1b.serialize())
108108
})
109109
.then(cid => {
110110
node1bCid = cid

src/object/patch/add-link.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = (createCommon, options) => {
6161
},
6262
(cb) => {
6363
try {
64-
node1a = DAGNode.create(obj.Data, obj.Links)
64+
node1a = new DAGNode(obj.Data, obj.Links)
6565
} catch (err) {
6666
return cb(err)
6767
}
@@ -70,7 +70,7 @@ module.exports = (createCommon, options) => {
7070
},
7171
(cb) => {
7272
try {
73-
node2 = DAGNode.create(Buffer.from('some other node'))
73+
node2 = new DAGNode(Buffer.from('some other node'))
7474
} catch (err) {
7575
return cb(err)
7676
}
@@ -95,7 +95,7 @@ module.exports = (createCommon, options) => {
9595
.then(node => {
9696
node1b = node
9797

98-
return dagPB.util.cid(dagPB.util.serialize(node), {
98+
return dagPB.util.cid(node.serialize(), {
9999
cidVersion: 0
100100
})
101101
})

src/object/put.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = (createCommon, options) => {
100100
series([
101101
(cb) => {
102102
try {
103-
node = DAGNode.create(Buffer.from(hat()))
103+
node = new DAGNode(Buffer.from(hat()))
104104
} catch (err) {
105105
return cb(err)
106106
}
@@ -109,7 +109,7 @@ module.exports = (createCommon, options) => {
109109
},
110110
(cb) => {
111111
try {
112-
serialized = dagPB.util.serialize(node)
112+
serialized = node.serialize()
113113
} catch (err) {
114114
return cb(err)
115115
}
@@ -146,7 +146,7 @@ module.exports = (createCommon, options) => {
146146
})
147147

148148
it('should put a Protobuf DAGNode', (done) => {
149-
const dNode = DAGNode.create(Buffer.from(hat()))
149+
const dNode = new DAGNode(Buffer.from(hat()))
150150

151151
ipfs.object.put(dNode, (err, cid) => {
152152
expect(err).to.not.exist()
@@ -175,7 +175,7 @@ module.exports = (createCommon, options) => {
175175
series([
176176
(cb) => {
177177
try {
178-
node1a = DAGNode.create(Buffer.from(hat()))
178+
node1a = new DAGNode(Buffer.from(hat()))
179179
} catch (err) {
180180
return cb(err)
181181
}
@@ -184,7 +184,7 @@ module.exports = (createCommon, options) => {
184184
},
185185
(cb) => {
186186
try {
187-
node2 = DAGNode.create(Buffer.from(hat()))
187+
node2 = new DAGNode(Buffer.from(hat()))
188188
} catch (err) {
189189
return cb(err)
190190
}

src/object/stat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = (createCommon, options) => {
115115
series([
116116
(cb) => {
117117
try {
118-
node1a = DAGNode.create(Buffer.from('Some data 1'))
118+
node1a = new DAGNode(Buffer.from('Some data 1'))
119119
} catch (err) {
120120
return cb(err)
121121
}
@@ -124,7 +124,7 @@ module.exports = (createCommon, options) => {
124124
},
125125
(cb) => {
126126
try {
127-
node2 = DAGNode.create(Buffer.from('Some data 2'))
127+
node2 = new DAGNode(Buffer.from('Some data 2'))
128128
} catch (err) {
129129
return cb(err)
130130
}

src/object/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const dagPB = require('ipld-dag-pb')
55
const { DAGNode, DAGLink } = dagPB
66

77
const calculateCid = promisify((node, cb) => {
8-
dagPB.util.cid(dagPB.util.serialize(node), {
8+
dagPB.util.cid(node.serialize(), {
99
cidVersion: 0
1010
})
1111
.then(cid => cb(null, cid), cb)
1212
})
1313

1414
const createDAGNode = promisify((data, links, cb) => {
15-
cb(null, DAGNode.create(data, links))
15+
cb(null, new DAGNode(data, links))
1616
})
1717

1818
const addLinkToDAGNode = promisify((parent, link, cb) => {

src/repo/gc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ module.exports = (createCommon, options) => {
184184
await ipfs.pin.rm(dataHash)
185185

186186
// Create a link to the data from an object
187-
const obj = await DAGNode.create(Buffer.from('fruit'), [{
187+
const obj = await new DAGNode(Buffer.from('fruit'), [{
188188
Name: 'p',
189189
Hash: dataHash,
190190
TSize: addRes[0].size

0 commit comments

Comments
 (0)