diff --git a/src/core/components/dag.js b/src/core/components/dag.js index 6e3b969516..4e35972dae 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -1,11 +1,13 @@ 'use strict' const promisify = require('promisify-es6') -const dagPB = require('ipld-dag-pb') -const CID = require('cids') +// const dagPB = require('ipld-dag-pb') +// const dagCBOR = require('ipld-dag-cbor') + +// const CID = require('cids') // const mh = require('multihashes') -module.exports = function object (self) { +module.exports = function dag (self) { return { put: promisify((dagNode, multicodec, hashAlg, callback) => { // TODO @@ -15,17 +17,28 @@ module.exports = function object (self) { // put in IPLD Resolver /* - self._ipldResolver.put({ - node: node, - cid: new CID(node.multihash) - } + self._ipldResolver.put({ + node: node, + cid: new CID(node.multihash) + } */ + switch (multicodec) { + case 'dag-pb': {} break + case 'dag-cbor': {} break + default: + callback(new Error('IPLD Format not supported')) + } }), get: promisify((cid, callback) => { self.ipldResolver.get(cid, callback) }), + rm: promisify((cid, callback) => { + // TODO once pinning is complete, this remove operation has to first + // verify that some pinning chain is not broken with the operation + self.ipldResolver.remove(cid, callback) + }), resolve: promisify((cid, path, callback) => { - // TODO + self.ipldResolver.resolve(cid, path, callback) }) } } diff --git a/test/core/both/test-dag.js b/test/core/both/test-dag.js new file mode 100644 index 0000000000..1a617691c6 --- /dev/null +++ b/test/core/both/test-dag.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const IPFSFactory = require('../../utils/factory-core') + +let factory + +const common = { + setup: function (cb) { + factory = new IPFSFactory() + cb(null, factory) + }, + teardown: function (cb) { + factory.dismantle(cb) + } +} + +test.dag(common)