-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
Codecov Report
@@ Coverage Diff @@
## master #48 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 3 3
Lines 84 65 -19
=====================================
- Hits 84 65 -19
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ok, aside from some suggestions, insofar as my expertise on this goes
src/resolver.js
Outdated
remainderPath: '' | ||
}) | ||
} | ||
exports = module.exports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be necessary, exports
is a legacy of original commonjs and should always be defined and be the same object as module.exports
src/resolver.js
Outdated
exports.resolve = async (binaryBlob, path) => { | ||
let node = await util.deserialize(binaryBlob) | ||
|
||
const parts = path.split('/').filter((x) => x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter(Boolean)
is a simpler way of doing this
src/resolver.js
Outdated
const traverse = function * (node, path) { | ||
// Traverse only objects and arrays | ||
if (Buffer.isBuffer(node) || CID.isCID(node) || typeof node === 'string' || | ||
node === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this should be node == null
to account for null
values too which will cause problems with Object.keys()
below
src/resolver.js
Outdated
const value = resolveField(dagNode, pathArray[0]) | ||
if (value === null) { | ||
return callback(new Error('No such path'), null) | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we ditching jsdocs in this? If so, maybe we could make some more moves away from aegir and it's massive dependency tree.
src/util.js
Outdated
}) | ||
}) | ||
|
||
visibility.removeEnumerableProperties(deserialized, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be the only use of visibility
and it's fairly trivial, maybe it should be collapsed?
[ 'bits', 'merkleRoot', 'prevHash', 'transactions', 'witnessCommit' ].forEach((p) => {
if (p in object) {
Object.defineProperty(object, p, { enumerable: false })
}
})
then visibility.js can be removed, there's a lot of noise in there that's not relevant
src/util.js
Outdated
], callback) | ||
const cid = async (binaryBlob, userOptions) => { | ||
const defaultOptions = { cidVersion: 1, hashAlg: DEFAULT_HASH_ALG } | ||
const options = mergeOptions(defaultOptions, userOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the use of options here is so simple (no nested objects), Object.assign()
will do this same work and you can remove the 'merge-options'
dependency: const options = Object.assign({ cidVersion: 1, hashAlg: DEFAULT_HASH_ALG }, userOptions)
.
test/resolver.spec.js
Outdated
it('should return the timestamp', (done) => { | ||
verifyPath(fixtureBlockHeader, 'timestamp', 1386981279, done) | ||
it('should return the version', async () => { | ||
await verifyPath(fixtureBlockHeader, 'version', 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think return
might be better than await
in all of these, let it be resolved by mocha
test/resolver.spec.js
Outdated
done() | ||
}) | ||
const verifyError = async (block, path, error) => { | ||
await expect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above comment, this should probably just be return
271f917
to
f0952ed
Compare
BREAKING CHANGE: The API is now async/await based There are numerous changes, the most significant one is that the API is no longer callback based, but it using async/await. For the full new API please see the [IPLD Formats spec]. [IPLD Formats spec]: https://github.com/ipld/interface-ipld-format
BREAKING CHANGE: The API is now async/await based
There are numerous changes, the most significant one is that the API
is no longer callback based, but it using async/await.
For the full new API please see the IPLD Formats spec.