-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
put
API optional (#1415)
* 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: ipfs-inactive/interface-js-ipfs-core#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 <[email protected]> * chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
0x-r4bbit
Author
Contributor
|
||
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) | ||
}), | ||
|
||
|
Cannot read property 'cid' of undefined