-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
hugomrdias
commented
Nov 30, 2020
- add ts types with jsdocs and aegir
- remove travis and add github action
- update deps and repo clean up (readme, package.json, etc.. )
- add ts types with jsdocs and aegir - remove travis and add github action - update deps and repo clean up (readme, package.json, etc.. )
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.
LGTM!
Co-authored-by: Vasco Santos <[email protected]>
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.
@hugomrdias thanks for driving this (it has been on my TODO list for quite some time). I think I'm almost happy with it, but I did offered:
- Few suggestions
- Type renaming
What I would however really like if we could converge onto a more granular interface(s), in fact I was adding those here https://github.com/ipfs/js-ipfs/pull/3365/files#diff-14db44021fcaf5fb4d2e74233129f8048ca4c35d372d2d470a33898944ffe449 reasoning here is that most all of the stores in ipfs-repo than can be expressed through them. If you do disagree it would be good to discuss so we can come to mutual agreement.
src/utils.js
Outdated
const TextEncoder = require('ipfs-utils/src/text-encoder') | ||
const TextDecoder = require('ipfs-utils/src/text-decoder') | ||
const _TextEncoder = require('ipfs-utils/src/text-encoder') | ||
const _TextDecoder = require('ipfs-utils/src/text-decoder') |
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.
Why _
prefix here ? If there is a reason it would be a good to have a comment explaining it.
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.
because those aren't typed, and the name get duplicated
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
…nto feat/ts-types * 'feat/ts-types' of github.com:ipfs/interface-datastore: Update src/key.js Update src/key.js Update src/key.js Update src/adapter.js Update src/adapter.js Update src/key.js
Me and @hugomrdias had a conversation about this and I have failed to make my arguments on why interface granularity were better way to go convincing. I do not want to press this further and I’m ok with going proposed approach in this pull. That said I would like to document my arguments in favor of more granular interfaces that were my preference:
I do hope in some future we might find enough merit in the arguments above to justify decomposing datastore interface. |
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.
LGTM, some minor nits
src/adapter.js
Outdated
/** | ||
* @implements {Datastore} | ||
*/ | ||
class DatastoreBase { |
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 would either rename the file this is in, or don't rename the class. The inconsistency of having one thing called an adapter
and another called a base
is confusing.
* @param {any} value - Value to check | ||
* @returns {boolean} | ||
*/ | ||
static isKey (value) { |
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 we shouldn't do this sort of thing any more and just use instanceof
. Boolean(value && value[symbol])
doesn't make any guarantees that what's being tested is compatible with the caller's expectation of the API.
It will break when two copies of this module are in the dep tree, but I think that's better than the returned type being incompatible.
async delete (key) { // eslint-disable-line require-await | ||
delete this.data[key.toString()] | ||
} | ||
|
||
* _all () { | ||
async * _all () { |
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.
There's no await
here?
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.
_all kinda needs to have the same return type as query
src/types.ts
Outdated
* @param q | ||
* @param options | ||
*/ | ||
_all(q: Query, options?: Options): AsyncIterable<Pair>; |
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 function isn't really part of the datastore API, it's part of the adapter implementation - we're not expecting users to call this.
src/key.js
Outdated
* Check if value is a Key instance | ||
* | ||
* @param {any} value - Value to check | ||
* @returns {boolean} |
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.
* @returns {boolean} | |
* @returns {value is Key} |
This would enable following to type check:
if (Key.isKey(x)) {
x.child(y)
}
Without this change it would not be able to refine x
type to Key
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.
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.
LGTM
module.exports.dbOpenFailedError = (err) => { | ||
/** | ||
* | ||
* @param {Error} [err] |
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.
Why aren't we documenting return types?
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.
no specific reason, in these situations i just let TS infer from the calls. When the code is more complex and i want to make sure the return type is what i want i explicitly write the return type.