diff --git a/package.json b/package.json index fa733c4..6ac941e 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,9 @@ "detect-node": "^2.0.4", "detect-webworker": "^1.0.0", "dirty-chai": "^2.0.1", - "ipfs-block-service": "~0.15.2", - "ipfs-repo": "~0.26.4", - "ipld": "~0.24.0", + "ipfs-block-service": "~0.16.0", + "ipfs-repo": "~0.27.0", + "ipld": "~0.25.0", "memdown": "^4.0.0", "temp-write": "^3.4.0" }, @@ -58,18 +58,17 @@ "debug": "^4.1.0", "err-code": "^1.1.2", "hamt-sharding": "~0.0.2", - "interface-datastore": "~0.6.0", + "interface-datastore": "~0.7.0", "ipfs-multipart": "~0.1.0", "ipfs-unixfs": "~0.1.16", "ipfs-unixfs-exporter": "~0.37.6", "ipfs-unixfs-importer": "~0.39.9", - "ipld-dag-pb": "~0.17.2", + "ipld-dag-pb": "~0.18.0", "joi-browser": "^13.4.0", "mortice": "^1.2.1", "multicodec": "~0.5.3", "multihashes": "~0.4.14", "once": "^1.4.0", - "promisify-es6": "^1.0.3", "pull-stream": "^3.6.9" }, "contributors": [ diff --git a/src/core/index.js b/src/core/index.js index 58d19e3..59068b8 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,7 +1,6 @@ 'use strict' const assert = require('assert') -const promisify = require('promisify-es6') const createLock = require('./utils/create-lock') // These operations are read-locked at the function level and will execute simultaneously @@ -48,24 +47,9 @@ module.exports = (options) => { assert(options.blocks, 'MFS requires an BlockStore instance') assert(options.datastore, 'MFS requires a DataStore instance') - // should be able to remove this when async/await PRs are in for datastore, blockstore & repo options.repo = { - blocks: { - get: promisify(options.blocks.get, { - context: options.blocks - }) - }, - datastore: { - open: promisify(options.datastore.open, { - context: options.datastore - }), - get: promisify(options.datastore.get, { - context: options.datastore - }), - put: promisify(options.datastore.put, { - context: options.datastore - }) - } + blocks: options.blocks, + datastore: options.datastore } const lock = createLock(repoOwner) diff --git a/src/core/utils/add-link.js b/src/core/utils/add-link.js index b72b0d0..4ecf4b9 100644 --- a/src/core/utils/add-link.js +++ b/src/core/utils/add-link.js @@ -87,21 +87,21 @@ const convertToShardedDirectory = async (context, options) => { } const addToDirectory = async (context, options) => { - let parent = await DAGNode.rmLink(options.parent, options.name) - parent = await DAGNode.addLink(parent, new DAGLink(options.name, options.size, options.cid)) + options.parent.rmLink(options.name) + options.parent.addLink(new DAGLink(options.name, options.size, options.cid)) const format = mc[options.format.toUpperCase().replace(/-/g, '_')] const hashAlg = mh.names[options.hashAlg] // Persist the new parent DAGNode - const cid = await context.ipld.put(parent, format, { + const cid = await context.ipld.put(options.parent, format, { cidVersion: options.cidVersion, hashAlg, hashOnly: !options.flush }) return { - node: parent, + node: options.parent, cid } } @@ -120,15 +120,13 @@ const addToShardedDirectory = async (context, options) => { const newLink = result.node.Links .find(link => link.Name.substring(0, 2) === path[0].prefix) - let parent = options.parent - if (oldLink) { - parent = await DAGNode.rmLink(options.parent, oldLink.Name) + options.parent.rmLink(oldLink.Name) } - parent = await DAGNode.addLink(parent, newLink) + options.parent.addLink(newLink) - return updateHamtDirectory(context, parent.Links, path[0].bucket, options) + return updateHamtDirectory(context, options.parent.Links, path[0].bucket, options) } const addFileToShardedDirectory = async (context, options) => { diff --git a/src/core/utils/create-node.js b/src/core/utils/create-node.js index 040cf88..f1cfb28 100644 --- a/src/core/utils/create-node.js +++ b/src/core/utils/create-node.js @@ -11,7 +11,7 @@ const createNode = async (context, type, options) => { const format = mc[options.format.toUpperCase().replace(/-/g, '_')] const hashAlg = mh.names[options.hashAlg] - const node = DAGNode.create(new UnixFS(type).marshal()) + const node = new DAGNode(new UnixFS(type).marshal()) const cid = await context.ipld.put(node, format, { cidVersion: options.cidVersion, hashAlg diff --git a/src/core/utils/hamt-utils.js b/src/core/utils/hamt-utils.js index df46e8d..94adc3f 100644 --- a/src/core/utils/hamt-utils.js +++ b/src/core/utils/hamt-utils.js @@ -21,7 +21,7 @@ const updateHamtDirectory = async (context, links, bucket, options) => { const format = mc[options.format.toUpperCase().replace(/-/g, '_')] const hashAlg = mh.names[options.hashAlg] - const parent = DAGNode.create(dir.marshal(), links) + const parent = new DAGNode(dir.marshal(), links) const cid = await context.ipld.put(parent, format, { cidVersion: options.cidVersion, hashAlg, diff --git a/src/core/utils/remove-link.js b/src/core/utils/remove-link.js index 778a36b..1ec7135 100644 --- a/src/core/utils/remove-link.js +++ b/src/core/utils/remove-link.js @@ -51,8 +51,8 @@ const removeFromDirectory = async (context, options) => { const format = mc[options.format.toUpperCase().replace(/-/g, '_')] const hashAlg = mh.names[options.hashAlg] - const newParentNode = await DAGNode.rmLink(options.parent, options.name) - const cid = await context.ipld.put(newParentNode, format, { + options.parent.rmLink(options.name) + const cid = await context.ipld.put(options.parent, format, { cidVersion: options.cidVersion, hashAlg }) @@ -60,7 +60,7 @@ const removeFromDirectory = async (context, options) => { log(`Updated regular directory ${cid}`) return { - node: newParentNode, + node: options.parent, cid } } @@ -104,11 +104,11 @@ const updateShard = async (context, positions, child, options) => { if (link.Name === `${prefix}${child.name}`) { log(`Removing existing link ${link.Name}`) - const newNode = await DAGNode.rmLink(node, link.Name) + node.rmLink(link.Name) await bucket.del(child.name) - return updateHamtDirectory(context, newNode.Links, bucket, options) + return updateHamtDirectory(context, node.Links, bucket, options) } log(`Descending into sub-shard ${link.Name} for ${prefix}${child.name}`) @@ -135,8 +135,8 @@ const updateShard = async (context, positions, child, options) => { } const updateShardParent = async (context, bucket, parent, oldName, newName, size, cid, options) => { - parent = await DAGNode.rmLink(parent, oldName) - parent = await DAGNode.addLink(parent, new DAGLink(newName, size, cid)) + parent.rmLink(oldName) + parent.addLink(new DAGLink(newName, size, cid)) return updateHamtDirectory(context, parent.Links, bucket, options) } diff --git a/src/core/utils/with-mfs-root.js b/src/core/utils/with-mfs-root.js index 992e823..38da0af 100644 --- a/src/core/utils/with-mfs-root.js +++ b/src/core/utils/with-mfs-root.js @@ -30,7 +30,7 @@ const loadMfsRoot = async (context) => { } log('Creating new MFS root') - const node = DAGNode.create(new UnixFs('directory').marshal()) + const node = new DAGNode(new UnixFs('directory').marshal()) cid = await context.ipld.put(node, mc.DAG_PB, { cidVersion: 0, hashAlg: mh.names['sha2-256'] // why can't ipld look this up? diff --git a/test/helpers/create-mfs.js b/test/helpers/create-mfs.js index cb52642..41135a5 100644 --- a/test/helpers/create-mfs.js +++ b/test/helpers/create-mfs.js @@ -2,7 +2,6 @@ const core = require('../../src/core') const isWebWorker = require('detect-webworker') -const promisify = require('promisify-es6') const { MemoryDatastore } = require('interface-datastore') @@ -21,13 +20,6 @@ const createMfs = async () => { } }) - repo.init = promisify(repo.init, { - context: repo - }) - repo.open = promisify(repo.open, { - context: repo - }) - await repo.init({}) await repo.open()