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

Commit

Permalink
fix: updates ipld-dag-pb dep to version without .cid properties
Browse files Browse the repository at this point in the history
Follows on from ipld/js-ipld-dag-pb#99 and
updates this module to not rely on DAGNodes having knowledge of
their CIDs.
  • Loading branch information
achingbrain committed Nov 13, 2018
1 parent aefb261 commit b0eab93
Show file tree
Hide file tree
Showing 22 changed files with 675 additions and 369 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.84.2",
"ipfsd-ctl": "~0.39.5",
"interface-ipfs-core": "~0.86.0",
"ipfsd-ctl": "ipfs/js-ipfsd-ctl#update-dag-pb-to-not-have-cid-property",
"ncp": "^2.0.0",
"qs": "^6.5.2",
"rimraf": "^2.6.2",
Expand Down Expand Up @@ -98,19 +98,19 @@
"hoek": "^5.0.4",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
"ipfs-api": "^26.1.0",
"ipfs-api": "ipfs/js-ipfs-api",
"ipfs-bitswap": "~0.21.0",
"ipfs-block": "~0.8.0",
"ipfs-block-service": "~0.15.1",
"ipfs-http-response": "~0.2.0",
"ipfs-mfs": "~0.4.2",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.5.0",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.25.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.33.0",
"ipld": "~0.19.3",
"ipfs-unixfs-engine": "~0.34.0",
"ipld": "~0.20.0",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-pb": "~0.14.11",
"ipld-dag-pb": "~0.15.0",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-zcash": "~0.1.6",
Expand Down
54 changes: 35 additions & 19 deletions src/cli/commands/object/get.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict'

const print = require('../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

module.exports = {
command: 'get <key>',
Expand All @@ -11,6 +16,10 @@ module.exports = {
'data-encoding': {
type: 'string',
default: 'base64'
},
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

Expand All @@ -19,26 +28,33 @@ module.exports = {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

if (Buffer.isBuffer(node.data)) {
nodeJSON.data = node.data.toString(argv['data-encoding'] || undefined)
}

const answer = {
Data: nodeJSON.data,
Hash: nodeJSON.multihash,
Size: nodeJSON.size,
Links: nodeJSON.links.map((l) => {
return {
Name: l.name,
Size: l.size,
Hash: l.multihash
}
})
}

print(JSON.stringify(answer))
cid(node, (err, result) => {
if (err) {
throw err
}

let data = node.data

if (Buffer.isBuffer(data)) {
data = node.data.toString(argv.dataEncoding || undefined)
}

const answer = {
Data: data,
Hash: result.toBaseEncodedString(argv.cidBase),
Size: node.size,
Links: node.links.map((l) => {
return {
Name: l.name,
Size: l.size,
Hash: l.cid.toBaseEncodedString(argv.cidBase)
}
})
}

print(JSON.stringify(answer))
})
})
}
}
11 changes: 7 additions & 4 deletions src/cli/commands/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ module.exports = {

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

builder: {},
builder: {
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

handler (argv) {
argv.ipfs.object.links(argv.key, {
Expand All @@ -18,9 +23,7 @@ module.exports = {
}

links.forEach((link) => {
link = link.toJSON()

print(`${link.multihash} ${link.size} ${link.name}`)
print(`${link.cid.toBaseEncodedString(argv.cidBase)} ${link.size} ${link.name}`)
})
})
}
Expand Down
20 changes: 17 additions & 3 deletions src/cli/commands/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

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

describe: 'Create new ipfs objects',

builder: {},
builder: {
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

handler (argv) {
argv.ipfs.object.new(argv.template, (err, node) => {
if (err) {
throw err
}

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(nodeJSON.multihash)
print(cid.toBaseEncodedString(argv.cidBase))
})
})
}
}
36 changes: 29 additions & 7 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

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

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

builder: {},
builder: {
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

handler (argv) {
const ipfs = argv.ipfs
Expand All @@ -20,16 +30,28 @@ module.exports = {
throw err
}

const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)

ipfs.object.patch.addLink(argv.root, link, {
enc: 'base58'
}, (err, nodeB) => {
cid(nodeA, (err, result) => {
if (err) {
throw err
}

print(nodeB.toJSON().multihash)
const link = new DAGLink(argv.name, nodeA.size, result)

ipfs.object.patch.addLink(argv.root, link, {
enc: 'base58'
}, (err, nodeB) => {
if (err) {
throw err
}

cid(nodeB, (err, result) => {
if (err) {
throw err
}

print(result.toBaseEncodedString(argv.cidBase))
})
})
})
})
}
Expand Down
14 changes: 12 additions & 2 deletions src/cli/commands/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function appendData (key, data, ipfs) {
ipfs.object.patch.appendData(key, data, {
Expand All @@ -14,9 +19,14 @@ function appendData (key, data, ipfs) {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

print(nodeJSON.multihash)
cid(node, (err, cid) => {
if (err) {
throw err
}

print(cid.toBaseEncodedString())
})
})
}

Expand Down
20 changes: 17 additions & 3 deletions src/cli/commands/object/patch/rm-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

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

describe: 'Remove a link from an object',

builder: {},
builder: {
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

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

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(nodeJSON.multihash)
print(cid.toBaseEncodedString(argv.cidBase))
})
})
}
}
14 changes: 12 additions & 2 deletions src/cli/commands/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function parseAndAddNode (key, data, ipfs) {
ipfs.object.patch.setData(key, data, {
Expand All @@ -14,9 +19,14 @@ function parseAndAddNode (key, data, ipfs) {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

print(nodeJSON.multihash)
cid(node, (err, cid) => {
if (err) {
throw err
}

print(cid.toBaseEncodedString())
})
})
}

Expand Down
21 changes: 17 additions & 4 deletions src/cli/commands/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
const bl = require('bl')
const fs = require('fs')
const print = require('../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function putNode (buf, enc, ipfs) {
function putNode (buf, enc, ipfs, cidEnc) {
ipfs.object.put(buf, { enc: enc }, (err, node) => {
if (err) {
throw err
}

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(`added ${nodeJSON.multihash}`)
print(`added ${cid.toBaseEncodedString(cidEnc)}`)
})
})
}

Expand All @@ -25,6 +34,10 @@ module.exports = {
'input-enc': {
type: 'string',
default: 'json'
},
'cid-base': {
default: 'base58btc',
describe: 'CID base to use.'
}
},

Expand All @@ -40,7 +53,7 @@ module.exports = {
throw err
}

putNode(input, argv.inputEnc, ipfs)
putNode(input, argv.inputEnc, ipfs, argv.cidBase)
}))
}
}
2 changes: 1 addition & 1 deletion src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = function dag (self) {
if (err) { return callback(err) }

mapAsync(res.value.links, (link, cb) => {
self.dag._getRecursive(link.multihash, options, cb)
self.dag._getRecursive(link.cid, options, cb)
}, (err, nodes) => {
// console.log('nodes:', nodes)
if (err) return callback(err)
Expand Down
Loading

0 comments on commit b0eab93

Please sign in to comment.