diff --git a/package.json b/package.json index f1350e5..a225330 100644 --- a/package.json +++ b/package.json @@ -32,25 +32,26 @@ "homepage": "https://github.com/ipfs/js-ipfs-ipld#readme", "license": "MIT", "devDependencies": { - "aegir": "^2.1.1", - "async": "^2.0.0-rc.3", + "aegir": "^3.0.4", + "async": "^2.0.0-rc.5", "buffer-loader": "0.0.1", "chai": "^3.5.0", "fs-blob-store": "^5.2.1", - "idb-plus-blob-store": "^1.0.0", - "ipfs-repo": "^0.6.1", - "lodash": "^4.8.2", + "idb-plus-blob-store": "^1.1.2", + "ipfs-block-service": "^0.4.0", + "ipfs-repo": "^0.8.0", + "lodash": "^4.12.0", "ncp": "^2.0.0", - "pre-commit": "^1.1.2", + "pre-commit": "^1.1.3", "rimraf": "^2.5.2" }, "dependencies": { - "babel-runtime": "^6.6.1", + "babel-runtime": "^6.9.0", "bs58": "^3.0.0", - "ipfs-blocks": "^0.1.2", - "ipld": "^0.5.2", + "ipfs-block": "^0.3.0", + "ipld": "^0.6.0", "is-ipfs": "^0.2.0", - "lodash.flatten": "^4.1.1", - "lodash.includes": "^4.1.2" + "lodash.flatten": "^4.2.0", + "lodash.includes": "^4.1.3" } } diff --git a/src/ipld-service.js b/src/ipld-service.js index e636c83..e8eef7a 100644 --- a/src/ipld-service.js +++ b/src/ipld-service.js @@ -1,7 +1,7 @@ 'use strict' const isIPFS = require('is-ipfs') -const Block = require('ipfs-blocks').Block +const Block = require('ipfs-block') const ipld = require('ipld') const base58 = require('bs58') diff --git a/src/resolve.js b/src/resolve.js index 591d745..dbecb96 100644 --- a/src/resolve.js +++ b/src/resolve.js @@ -2,9 +2,12 @@ const isIPFS = require('is-ipfs') const includes = require('lodash.includes') +const ipld = require('ipld') const IPLDService = require('./ipld-service') +const LINK_SYMBOL = ipld.LINK_SYMBOL + module.exports = function resolve (is, path, cb) { if (!(is instanceof IPLDService)) { return cb(new Error('Missing IPLDService')) @@ -13,14 +16,14 @@ module.exports = function resolve (is, path, cb) { function access (parts, obj, cb) { const isRoot = obj === null && (isIPFS.multihash(parts[0]) || isIPFS.ipfsPath('/' + parts.join('/'))) const next = parts.shift() - const isLink = obj && obj['@link'] + const isLink = obj && Object.keys(obj).length === 1 && obj[LINK_SYMBOL] const fetchLink = obj && (next ? !includes(Object.keys(obj), next) : true) if (!obj && !isRoot) { cb(new Error('No root object provided')) } else if (isLink && fetchLink) { - // resolve links in objects with an @link property - const link = obj['@link'] + // resolve links in objects with an / property + const link = obj[LINK_SYMBOL] const linkParts = splitLink(link) let blockLink = '' diff --git a/src/utils.js b/src/utils.js index 3f66283..dfdeb03 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,13 +1,16 @@ 'use strict' const flatten = require('lodash.flatten') +const ipld = require('ipld') + +const LINK_SYMBOL = ipld.LINK_SYMBOL exports = module.exports // Recursively find all '@link' values in a given node exports.getKeys = (node) => { return flatten(Object.keys(node).map((key) => { - if (key === '@link') { + if (key === LINK_SYMBOL) { return node[key] } diff --git a/test/ipld-tests.js b/test/ipld-tests.js index 577a0c6..c5df36d 100644 --- a/test/ipld-tests.js +++ b/test/ipld-tests.js @@ -2,7 +2,7 @@ 'use strict' const expect = require('chai').expect -const BlockService = require('ipfs-blocks').BlockService +const BlockService = require('ipfs-block-service') const ipld = require('ipld') const multihash = require('multihashing') const async = require('async') @@ -57,11 +57,11 @@ module.exports = (repo) => { const node3 = {data: '3'} node2.ref = { - '@link': ipld.multihash(ipld.marshal(node3)) + '/': ipld.multihash(ipld.marshal(node3)) } node1.ref = { - '@link': ipld.multihash(ipld.marshal(node2)) + '/': ipld.multihash(ipld.marshal(node2)) } async.series([ @@ -190,10 +190,10 @@ module.exports = (repo) => { const alice = { name: 'Alice', about: { - '@link': ipld.multihash(ipld.marshal(aliceAbout)) + '/': ipld.multihash(ipld.marshal(aliceAbout)) }, friends: [{ - '@link': ipld.multihash(ipld.marshal(bob)) + '/': ipld.multihash(ipld.marshal(bob)) }] } const mh = ipld.multihash(ipld.marshal(alice)) @@ -250,16 +250,16 @@ module.exports = (repo) => { const author = { name: { - '@link': `/${ipld.multihash(ipld.marshal(alice))}/name` + '/': `/${ipld.multihash(ipld.marshal(alice))}/name` } } const blogpost = { title: { - '@link': `/${ipld.multihash(ipld.marshal(draft))}/title` + '/': `/${ipld.multihash(ipld.marshal(draft))}/title` }, author: { - '@link': `/ipfs/${ipld.multihash(ipld.marshal(author))}` + '/': `/ipfs/${ipld.multihash(ipld.marshal(author))}` } } diff --git a/test/utils.spec.js b/test/utils.spec.js index 90ca8e8..8886332 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -11,12 +11,12 @@ describe('utils', () => { expect( utils.getKeys({ hello: 'world', - '@link': 'link-1', + l1: {'/': 'link-1'}, nested: { - '@link': 'link-2', + l2: {'/': 'link-2'}, even: { deeper: true, - '@link': 'link-3' + l3: {'/': 'link-3'} } } })