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

fix(core/components/dag): make options in put API optional #1415

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"expose-loader": "~0.7.5",
"form-data": "^2.3.2",
"hat": "0.0.3",
"interface-ipfs-core": "~0.70.2",
"interface-ipfs-core": "~0.70.3",
"ipfsd-ctl": "~0.37.3",
"mocha": "^5.1.1",
"ncp": "^2.0.0",
Expand Down
15 changes: 15 additions & 0 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ const flattenDeep = require('lodash/flattenDeep')
module.exports = function dag (self) {
return {
put: promisify((dagNode, options, callback) => {
if (typeof options === 'function') {
callback = options
} else if (options.cid && (options.format || options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide either `cid` OR `format` and `hashAlg` options.'))
} else if ((options.format && !options.hashAlg) || (!options.format && options.hashAlg)) {
return callback(new Error('Can\'t put dag node. Please provide `format` AND `hashAlg` options.'))
}

const optionDefaults = {
format: 'dag-cbor',
hashAlg: 'sha2-255'
}

options = options.cid ? options : Object.assign({}, optionDefaults, options)

self._ipld.put(dagNode, options, callback)
}),

Expand Down