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

Commit 03fa0dc

Browse files
author
Alan Shaw
committed
chore: update CIDs and IPLD formats
BREAKING CHANGE: v1 CIDs are now eencoded in base32 when stringified. Additionally IPLD formats have been updated to the latest versions. See CHANGELOGs for ipld-dag-pb and ipld-dag-cbor for more details: * https://github.com/ipld/js-ipld-dag-pb/blob/master/CHANGELOG.md#0160-2019-05-08 * https://github.com/ipld/js-ipld-dag-cbor/blob/master/CHANGELOG.md#0140-2019-05-08 License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 775ce80 commit 03fa0dc

File tree

10 files changed

+107
-80
lines changed

10 files changed

+107
-80
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
"bl": "^3.0.0",
3232
"bs58": "^4.0.1",
3333
"buffer": "^5.2.1",
34-
"cids": "~0.5.8",
34+
"cids": "~0.7.0",
3535
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
3636
"debug": "^4.1.0",
3737
"detect-node": "^2.0.4",
3838
"end-of-stream": "^1.4.1",
3939
"err-code": "^1.1.2",
4040
"flatmap": "0.0.3",
4141
"glob": "^7.1.3",
42-
"ipfs-block": "~0.8.0",
43-
"ipld-dag-cbor": "~0.13.1",
44-
"ipld-dag-pb": "~0.15.3",
45-
"is-ipfs": "~0.6.0",
42+
"ipfs-block": "~0.8.1",
43+
"ipld-dag-cbor": "~0.15.0",
44+
"ipld-dag-pb": "~0.17.0",
45+
"is-ipfs": "~0.6.1",
4646
"is-pull-stream": "0.0.0",
4747
"is-stream": "^2.0.0",
4848
"iso-stream-http": "~0.1.2",
@@ -85,7 +85,7 @@
8585
"dirty-chai": "^2.0.1",
8686
"eslint-plugin-react": "^7.11.1",
8787
"go-ipfs-dep": "0.4.19",
88-
"interface-ipfs-core": "~0.99.0",
88+
"interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#chore/update-cids-and-ipld",
8989
"ipfsd-ctl": "~0.42.0",
9090
"nock": "^10.0.2",
9191
"stream-equal": "^1.1.1"

src/dag/get.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ module.exports = (send) => {
4646
},
4747
(ipfsBlock, path, cb) => {
4848
const dagResolver = resolvers[ipfsBlock.cid.codec]
49+
4950
if (!dagResolver) {
5051
const error = new Error('ipfs-http-client is missing DAG resolver for "' + ipfsBlock.cid.codec + '" multicodec')
5152
error.missingMulticodec = ipfsBlock.cid.codec
52-
cb(error)
53-
return
53+
return cb(error)
54+
}
55+
56+
let res
57+
try {
58+
res = dagResolver.resolve(ipfsBlock.data, path)
59+
} catch (err) {
60+
return cb(err)
5461
}
55-
dagResolver.resolve(ipfsBlock.data, path, cb)
62+
cb(null, res)
5663
}
5764
], callback)
5865
})

src/dag/put.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,38 @@ module.exports = (send) => {
5050

5151
options = Object.assign(optionDefaults, options)
5252

53-
if (options.format === 'dag-cbor') {
54-
dagCBOR.util.serialize(dagNode, finalize)
55-
} else if (options.format === 'dag-pb') {
56-
dagPB.util.serialize(dagNode, finalize)
57-
} else {
58-
// FIXME Hopefully already serialized...can we use IPLD to serialise instead?
59-
finalize(null, dagNode)
53+
let serialized
54+
55+
try {
56+
if (options.format === 'dag-cbor') {
57+
serialized = dagCBOR.util.serialize(dagNode)
58+
} else if (options.format === 'dag-pb') {
59+
serialized = dagPB.util.serialize(dagNode)
60+
} else {
61+
// FIXME Hopefully already serialized...can we use IPLD to serialise instead?
62+
serialized = dagNode
63+
}
64+
} catch (err) {
65+
return callback(err)
6066
}
6167

62-
function finalize (err, serialized) {
63-
if (err) { return callback(err) }
64-
const sendOptions = {
65-
qs: {
66-
hash: options.hashAlg,
67-
format: options.format,
68-
'input-enc': options.inputEnc
69-
}
68+
const sendOptions = {
69+
qs: {
70+
hash: options.hashAlg,
71+
format: options.format,
72+
'input-enc': options.inputEnc
7073
}
71-
sendOneFile(serialized, sendOptions, (err, result) => {
72-
if (err) {
73-
return callback(err)
74-
}
75-
if (result['Cid']) {
76-
return callback(null, new CID(result['Cid']['/']))
77-
} else {
78-
return callback(result)
79-
}
80-
})
8174
}
75+
76+
sendOneFile(serialized, sendOptions, (err, result) => {
77+
if (err) {
78+
return callback(err)
79+
}
80+
if (result['Cid']) {
81+
return callback(null, new CID(result['Cid']['/']))
82+
} else {
83+
return callback(result)
84+
}
85+
})
8286
})
8387
}

src/object/addLink.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ module.exports = (send) => {
1919
return callback(err)
2020
}
2121

22-
send({
23-
path: 'object/patch/add-link',
24-
args: [
25-
cid.toString(),
26-
dLink.name,
27-
dLink.cid.toString()
28-
]
29-
}, (err, result) => {
22+
const args = [
23+
cid.toString(),
24+
dLink.name || dLink.Name || null,
25+
(dLink.cid || dLink.Hash || '').toString() || null
26+
]
27+
28+
send({ path: 'object/patch/add-link', args }, (err, result) => {
3029
if (err) {
3130
return callback(err)
3231
}

src/object/get.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const dagPB = require('ipld-dag-pb')
5-
const DAGNode = dagPB.DAGNode
6-
const DAGLink = dagPB.DAGLink
4+
const { DAGNode, DAGLink } = require('ipld-dag-pb')
75
const CID = require('cids')
86
const LRU = require('lru-cache')
97
const lruOptions = {
@@ -49,19 +47,11 @@ module.exports = (send) => {
4947
return callback(err)
5048
}
5149

52-
result.Data = Buffer.from(result.Data, 'base64')
50+
const links = result.Links.map(l => new DAGLink(l.Name, l.Size, l.Hash))
51+
const node = DAGNode.create(Buffer.from(result.Data, 'base64'), links)
5352

54-
const links = result.Links.map((l) => {
55-
return new DAGLink(l.Name, l.Size, l.Hash)
56-
})
57-
58-
DAGNode.create(result.Data, links, (err, node) => {
59-
if (err) {
60-
return callback(err)
61-
}
62-
cache.set(cidB58Str, node)
63-
callback(null, node)
64-
})
53+
cache.set(cidB58Str, node)
54+
callback(null, node)
6555
})
6656
})
6757
}

src/object/links.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const dagPB = require('ipld-dag-pb')
5-
const DAGLink = dagPB.DAGLink
4+
const { DAGLink } = require('ipld-dag-pb')
65
const CID = require('cids')
76
const LRU = require('lru-cache')
87
const lruOptions = {

src/object/put.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ module.exports = (send) => {
3636
}
3737
} else if (DAGNode.isDAGNode(obj)) {
3838
tmpObj = {
39-
Data: obj.data.toString(),
40-
Links: obj.links.map((l) => {
41-
const link = l.toJSON()
42-
link.hash = link.cid
43-
return link
44-
})
39+
Data: obj.Data.toString(),
40+
Links: obj.Links.map(l => ({
41+
Name: l.Name,
42+
Hash: l.Hash.toString(),
43+
Size: l.Tsize
44+
}))
4545
}
4646
} else if (typeof obj === 'object') {
4747
tmpObj.Data = obj.Data.toString()

src/object/rmLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = (send) => {
2323
path: 'object/patch/rm-link',
2424
args: [
2525
cid.toString(),
26-
dLink.name
26+
dLink.name || dLink.Name || null
2727
]
2828
}, (err, result) => {
2929
if (err) {

test/dag.spec.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
1010
const series = require('async/series')
11-
const dagPB = require('ipld-dag-pb')
12-
const DAGNode = dagPB.DAGNode
11+
const { DAGNode } = require('ipld-dag-pb')
1312
const CID = require('cids')
1413
const ipfsClient = require('../src')
1514
const f = require('./utils/factory')
@@ -37,20 +36,19 @@ describe('.dag', function () {
3736

3837
it('should be able to put and get a DAG node with format dag-pb', (done) => {
3938
const data = Buffer.from('some data')
40-
DAGNode.create(data, (err, node) => {
39+
const node = DAGNode.create(data)
40+
41+
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
4142
expect(err).to.not.exist()
42-
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
43+
cid = cid.toV0()
44+
expect(cid.codec).to.equal('dag-pb')
45+
cid = cid.toBaseEncodedString('base58btc')
46+
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
47+
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
48+
ipfs.dag.get(cid, (err, result) => {
4349
expect(err).to.not.exist()
44-
cid = cid.toV0()
45-
expect(cid.codec).to.equal('dag-pb')
46-
cid = cid.toBaseEncodedString('base58btc')
47-
// expect(cid).to.equal('bafybeig3t3eugdchignsgkou3ly2mmy4ic4gtfor7inftnqn3yq4ws3a5u')
48-
expect(cid).to.equal('Qmd7xRhW5f29QuBFtqu3oSD27iVy35NRB91XFjmKFhtgMr')
49-
ipfs.dag.get(cid, (err, result) => {
50-
expect(err).to.not.exist()
51-
expect(result.value.data).to.deep.equal(data)
52-
done()
53-
})
50+
expect(result.value.Data).to.deep.equal(data)
51+
done()
5452
})
5553
})
5654
})

test/interface.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,36 @@ describe('interface-ipfs-core tests', () => {
173173
isNode ? null : {
174174
name: 'should readable stream ls with a base58 encoded CID',
175175
reason: 'FIXME https://github.com/ipfs/js-ipfs-http-client/issues/339'
176+
},
177+
// .refs
178+
{
179+
name: 'refs',
180+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
181+
},
182+
// .refsReadableStream
183+
{
184+
name: 'refsReadableStream',
185+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
186+
},
187+
// .refsPullStream
188+
{
189+
name: 'refsPullStream',
190+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
191+
},
192+
// .refs.local
193+
{
194+
name: 'refsLocal',
195+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
196+
},
197+
// .refs.localReadableStream
198+
{
199+
name: 'refsLocalReadableStream',
200+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
201+
},
202+
// .refs.localPullStream
203+
{
204+
name: 'refsLocalPullStream',
205+
reason: 'FIXME unskip when https://github.com/ipfs/js-ipfs-http-client/pull/978 is merged'
176206
}
177207
]
178208
})

0 commit comments

Comments
 (0)