From 08312b955065a5ac264e7087642534c175cdd33e Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Fri, 29 Jun 2018 16:01:22 +0100 Subject: [PATCH] fix(core/components/dag): make options in `put` API optional The [dag.put](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DAG.md#dagput) interface takes an options object which is required, but should be optional with decent defaults. See dedicated test here: https://github.com/ipfs/interface-ipfs-core/pull/316 This commit implements this behaviour. **Before**: ```js ipfs.dag.put(obj, options, (err, cid) => {...}); ``` ^ Prior to this commit, without passing `options`, this call resulted in an error. **After**: ```js ipfs.dag.put(obj, (err, cid) => {...}); ``` ^ This is now perfectly fine. Fixes #1395 License: MIT Signed-off-by: Pascal Precht --- src/core/components/dag.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/components/dag.js b/src/core/components/dag.js index e43ea241f8..6afb9df015 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -9,6 +9,17 @@ const flattenDeep = require('lodash.flattendeep') module.exports = function dag (self) { return { put: promisify((dagNode, options, callback) => { + if (typeof options === 'function') { + callback = options + } + + const optionDefaults = { + format: 'dag-cbor', + hashAlg: 'sha2-256' + } + + options = options.cid ? options : Object.assign({}, optionDefaults, options) + self._ipld.put(dagNode, options, callback) }),