From 4f0c0e5cf7944dc0195b960e4d5108034fc2f211 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 8 Nov 2018 21:45:19 +0000 Subject: [PATCH] fix: updates ipld-dag-pb dep to version without .cid properties Follows on from https://github.com/ipld/js-ipld-dag-pb/pull/99 and updates this module to not rely on DAGNodes having knowledge of their CIDs. --- package.json | 16 +- src/cli/commands/object/get.js | 54 +++--- src/cli/commands/object/links.js | 11 +- src/cli/commands/object/new.js | 20 ++- src/cli/commands/object/patch/add-link.js | 36 +++- src/cli/commands/object/patch/append-data.js | 14 +- src/cli/commands/object/patch/rm-link.js | 20 ++- src/cli/commands/object/patch/set-data.js | 14 +- src/cli/commands/object/put.js | 21 ++- src/core/components/dag.js | 2 +- src/core/components/init.js | 13 +- src/core/components/object.js | 80 ++++----- src/core/components/pin-set.js | 81 ++++++--- src/core/components/pin.js | 166 +++++++++++------- src/core/index.js | 6 +- src/core/utils.js | 12 +- src/http/api/resources/object.js | 170 +++++++++---------- test/core/object.spec.js | 93 ++++++---- test/core/pin-set.js | 55 +++--- test/core/pin.js | 2 +- test/core/preload.spec.js | 106 +++++++++--- test/http-api/object.js | 52 ++++-- 22 files changed, 675 insertions(+), 369 deletions(-) diff --git a/package.json b/package.json index 3bdaa3b57a..d6295f4aeb 100644 --- a/package.json +++ b/package.json @@ -69,8 +69,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", @@ -102,19 +102,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", diff --git a/src/cli/commands/object/get.js b/src/cli/commands/object/get.js index 80190d8d96..ccc4b466ab 100644 --- a/src/cli/commands/object/get.js +++ b/src/cli/commands/object/get.js @@ -1,6 +1,11 @@ 'use strict' const print = require('../../utils').print +const { + util: { + cid + } +} = require('ipld-dag-pb') module.exports = { command: 'get ', @@ -11,6 +16,10 @@ module.exports = { 'data-encoding': { type: 'string', default: 'base64' + }, + 'cid-base': { + default: 'base58btc', + describe: 'CID base to use.' } }, @@ -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)) + }) }) } } diff --git a/src/cli/commands/object/links.js b/src/cli/commands/object/links.js index d657820fb4..9a3a3e203e 100644 --- a/src/cli/commands/object/links.js +++ b/src/cli/commands/object/links.js @@ -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, { @@ -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}`) }) }) } diff --git a/src/cli/commands/object/new.js b/src/cli/commands/object/new.js index f96db85fb2..36ab5a3659 100644 --- a/src/cli/commands/object/new.js +++ b/src/cli/commands/object/new.js @@ -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: 'new [