Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 5573131

Browse files
committed
fix: updates ipld-dag-pb dep to version without .cid properties
Follows on from ipld/js-ipld-dag-pb#99 and updates this module to not rely on DAGNodes having knowledge of their CIDs.
1 parent 323b0dc commit 5573131

File tree

22 files changed

+674
-367
lines changed

22 files changed

+674
-367
lines changed

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
"execa": "^1.0.0",
6969
"form-data": "^2.3.3",
7070
"hat": "0.0.3",
71-
"interface-ipfs-core": "~0.84.2",
72-
"ipfsd-ctl": "~0.39.5",
71+
"interface-ipfs-core": "ipfs/interface-ipfs-core#update-dag-pb-to-not-have-cid-property",
72+
"ipfsd-ctl": "ipfs/js-ipfsd-ctl#update-dag-pb-to-not-have-cid-property",
7373
"ncp": "^2.0.0",
7474
"qs": "^6.5.2",
7575
"rimraf": "^2.6.2",
@@ -98,19 +98,20 @@
9898
"hoek": "^5.0.4",
9999
"human-to-milliseconds": "^1.0.0",
100100
"interface-datastore": "~0.6.0",
101-
"ipfs-api": "^26.1.0",
101+
"ipfs-api": "ipfs/js-ipfs-api#update-dag-pb-to-not-have-cid-property",
102102
"ipfs-bitswap": "~0.21.0",
103103
"ipfs-block": "~0.8.0",
104104
"ipfs-block-service": "~0.15.1",
105-
"ipfs-http-response": "~0.2.0",
105+
"ipfs-http-response": "achingbrain/js-ipfs-http-response#use-cid-property-before-falling-back-to-multihash",
106106
"ipfs-mfs": "~0.4.2",
107107
"ipfs-multipart": "~0.1.0",
108108
"ipfs-repo": "~0.25.0",
109109
"ipfs-unixfs": "~0.1.16",
110110
"ipfs-unixfs-engine": "~0.33.0",
111-
"ipld": "~0.19.1",
111+
"ipld": "ipld/js-ipld#depend-on-dag-pb-without-cid",
112+
"ipld-bitcoin": "~0.1.8",
113+
"ipld-dag-pb": "ipld/js-ipld-dag-pb#remove-cid-property-from-dagnodes",
112114
"ipld-bitcoin": "~0.1.8",
113-
"ipld-dag-pb": "~0.14.11",
114115
"ipld-ethereum": "^2.0.1",
115116
"ipld-git": "~0.2.2",
116117
"ipld-raw": "^2.0.1",

src/cli/commands/object/get.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict'
22

33
const print = require('../../utils').print
4+
const {
5+
util: {
6+
cid
7+
}
8+
} = require('ipld-dag-pb')
49

510
module.exports = {
611
command: 'get <key>',
@@ -11,6 +16,10 @@ module.exports = {
1116
'data-encoding': {
1217
type: 'string',
1318
default: 'base64'
19+
},
20+
'cid-base': {
21+
default: 'base58btc',
22+
describe: 'CID base to use.'
1423
}
1524
},
1625

@@ -19,26 +28,33 @@ module.exports = {
1928
if (err) {
2029
throw err
2130
}
22-
const nodeJSON = node.toJSON()
23-
24-
if (Buffer.isBuffer(node.data)) {
25-
nodeJSON.data = node.data.toString(argv['data-encoding'] || undefined)
26-
}
27-
28-
const answer = {
29-
Data: nodeJSON.data,
30-
Hash: nodeJSON.multihash,
31-
Size: nodeJSON.size,
32-
Links: nodeJSON.links.map((l) => {
33-
return {
34-
Name: l.name,
35-
Size: l.size,
36-
Hash: l.multihash
37-
}
38-
})
39-
}
4031

41-
print(JSON.stringify(answer))
32+
cid(node, (err, result) => {
33+
if (err) {
34+
throw err
35+
}
36+
37+
let data = node.data
38+
39+
if (Buffer.isBuffer(data)) {
40+
data = node.data.toString(argv.dataEncoding || undefined)
41+
}
42+
43+
const answer = {
44+
Data: data,
45+
Hash: result.toBaseEncodedString(argv.cidBase),
46+
Size: node.size,
47+
Links: node.links.map((l) => {
48+
return {
49+
Name: l.name,
50+
Size: l.size,
51+
Hash: l.cid.toBaseEncodedString(argv.cidBase)
52+
}
53+
})
54+
}
55+
56+
print(JSON.stringify(answer))
57+
})
4258
})
4359
}
4460
}

src/cli/commands/object/links.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ module.exports = {
77

88
describe: 'Outputs the links pointed to by the specified object',
99

10-
builder: {},
10+
builder: {
11+
'cid-base': {
12+
default: 'base58btc',
13+
describe: 'CID base to use.'
14+
}
15+
},
1116

1217
handler (argv) {
1318
argv.ipfs.object.links(argv.key, {
@@ -18,9 +23,7 @@ module.exports = {
1823
}
1924

2025
links.forEach((link) => {
21-
link = link.toJSON()
22-
23-
print(`${link.multihash} ${link.size} ${link.name}`)
26+
print(`${link.cid.toBaseEncodedString(argv.cidBase)} ${link.size} ${link.name}`)
2427
})
2528
})
2629
}

src/cli/commands/object/new.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,37 @@ const debug = require('debug')
44
const log = debug('cli:object')
55
log.error = debug('cli:object:error')
66
const print = require('../../utils').print
7+
const {
8+
util: {
9+
cid
10+
}
11+
} = require('ipld-dag-pb')
712

813
module.exports = {
914
command: 'new [<template>]',
1015

1116
describe: 'Create new ipfs objects',
1217

13-
builder: {},
18+
builder: {
19+
'cid-base': {
20+
default: 'base58btc',
21+
describe: 'CID base to use.'
22+
}
23+
},
1424

1525
handler (argv) {
1626
argv.ipfs.object.new(argv.template, (err, node) => {
1727
if (err) {
1828
throw err
1929
}
2030

21-
const nodeJSON = node.toJSON()
31+
cid(node, (err, cid) => {
32+
if (err) {
33+
throw err
34+
}
2235

23-
print(nodeJSON.multihash)
36+
print(cid.toBaseEncodedString(argv.cidBase))
37+
})
2438
})
2539
}
2640
}

src/cli/commands/object/patch/add-link.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
const dagPB = require('ipld-dag-pb')
44
const DAGLink = dagPB.DAGLink
55
const print = require('../../../utils').print
6+
const {
7+
util: {
8+
cid
9+
}
10+
} = require('ipld-dag-pb')
611

712
module.exports = {
813
command: 'add-link <root> <name> <ref>',
914

1015
describe: 'Add a link to a given object',
1116

12-
builder: {},
17+
builder: {
18+
'cid-base': {
19+
default: 'base58btc',
20+
describe: 'CID base to use.'
21+
}
22+
},
1323

1424
handler (argv) {
1525
const ipfs = argv.ipfs
@@ -20,16 +30,28 @@ module.exports = {
2030
throw err
2131
}
2232

23-
const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)
24-
25-
ipfs.object.patch.addLink(argv.root, link, {
26-
enc: 'base58'
27-
}, (err, nodeB) => {
33+
cid(nodeA, (err, result) => {
2834
if (err) {
2935
throw err
3036
}
3137

32-
print(nodeB.toJSON().multihash)
38+
const link = new DAGLink(argv.name, nodeA.size, result)
39+
40+
ipfs.object.patch.addLink(argv.root, link, {
41+
enc: 'base58'
42+
}, (err, nodeB) => {
43+
if (err) {
44+
throw err
45+
}
46+
47+
cid(nodeB, (err, result) => {
48+
if (err) {
49+
throw err
50+
}
51+
52+
print(result.toBaseEncodedString(argv.cidBase))
53+
})
54+
})
3355
})
3456
})
3557
}

src/cli/commands/object/patch/append-data.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const debug = require('debug')
66
const log = debug('cli:object')
77
log.error = debug('cli:object:error')
88
const print = require('../../../utils').print
9+
const {
10+
util: {
11+
cid
12+
}
13+
} = require('ipld-dag-pb')
914

1015
function appendData (key, data, ipfs) {
1116
ipfs.object.patch.appendData(key, data, {
@@ -14,9 +19,14 @@ function appendData (key, data, ipfs) {
1419
if (err) {
1520
throw err
1621
}
17-
const nodeJSON = node.toJSON()
1822

19-
print(nodeJSON.multihash)
23+
cid(node, (err, cid) => {
24+
if (err) {
25+
throw err
26+
}
27+
28+
print(cid.toBaseEncodedString())
29+
})
2030
})
2131
}
2232

src/cli/commands/object/patch/rm-link.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ const debug = require('debug')
44
const log = debug('cli:object')
55
log.error = debug('cli:object:error')
66
const print = require('../../../utils').print
7+
const {
8+
util: {
9+
cid
10+
}
11+
} = require('ipld-dag-pb')
712

813
module.exports = {
914
command: 'rm-link <root> <link>',
1015

1116
describe: 'Remove a link from an object',
1217

13-
builder: {},
18+
builder: {
19+
'cid-base': {
20+
default: 'base58btc',
21+
describe: 'CID base to use.'
22+
}
23+
},
1424

1525
handler (argv) {
1626
argv.ipfs.object.patch.rmLink(argv.root, { name: argv.link }, {
@@ -20,9 +30,13 @@ module.exports = {
2030
throw err
2131
}
2232

23-
const nodeJSON = node.toJSON()
33+
cid(node, (err, cid) => {
34+
if (err) {
35+
throw err
36+
}
2437

25-
print(nodeJSON.multihash)
38+
print(cid.toBaseEncodedString(argv.cidBase))
39+
})
2640
})
2741
}
2842
}

src/cli/commands/object/patch/set-data.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const debug = require('debug')
66
const log = debug('cli:object')
77
log.error = debug('cli:object:error')
88
const print = require('../../../utils').print
9+
const {
10+
util: {
11+
cid
12+
}
13+
} = require('ipld-dag-pb')
914

1015
function parseAndAddNode (key, data, ipfs) {
1116
ipfs.object.patch.setData(key, data, {
@@ -14,9 +19,14 @@ function parseAndAddNode (key, data, ipfs) {
1419
if (err) {
1520
throw err
1621
}
17-
const nodeJSON = node.toJSON()
1822

19-
print(nodeJSON.multihash)
23+
cid(node, (err, cid) => {
24+
if (err) {
25+
throw err
26+
}
27+
28+
print(cid.toBaseEncodedString())
29+
})
2030
})
2131
}
2232

src/cli/commands/object/put.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
const bl = require('bl')
44
const fs = require('fs')
55
const print = require('../../utils').print
6+
const {
7+
util: {
8+
cid
9+
}
10+
} = require('ipld-dag-pb')
611

7-
function putNode (buf, enc, ipfs) {
12+
function putNode (buf, enc, ipfs, cidEnc) {
813
ipfs.object.put(buf, { enc: enc }, (err, node) => {
914
if (err) {
1015
throw err
1116
}
1217

13-
const nodeJSON = node.toJSON()
18+
cid(node, (err, cid) => {
19+
if (err) {
20+
throw err
21+
}
1422

15-
print(`added ${nodeJSON.multihash}`)
23+
print(`added ${cid.toBaseEncodedString(cidEnc)}`)
24+
})
1625
})
1726
}
1827

@@ -25,6 +34,10 @@ module.exports = {
2534
'input-enc': {
2635
type: 'string',
2736
default: 'json'
37+
},
38+
'cid-base': {
39+
default: 'base58btc',
40+
describe: 'CID base to use.'
2841
}
2942
},
3043

@@ -40,7 +53,7 @@ module.exports = {
4053
throw err
4154
}
4255

43-
putNode(input, argv.inputEnc, ipfs)
56+
putNode(input, argv.inputEnc, ipfs, argv.cidBase)
4457
}))
4558
}
4659
}

src/core/components/dag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ module.exports = function dag (self) {
163163
if (err) { return callback(err) }
164164

165165
mapAsync(res.value.links, (link, cb) => {
166-
self.dag._getRecursive(link.multihash, options, cb)
166+
self.dag._getRecursive(link.cid, options, cb)
167167
}, (err, nodes) => {
168168
// console.log('nodes:', nodes)
169169
if (err) return callback(err)

0 commit comments

Comments
 (0)