Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

feat: ts types, github ci and clean up #56

Merged
merged 22 commits into from
Jan 15, 2021
Merged

feat: ts types, github ci and clean up #56

merged 22 commits into from
Jan 15, 2021

Conversation

hugomrdias
Copy link
Member

  • 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.. )
@hugomrdias hugomrdias requested review from achingbrain, Gozala and vasco-santos and removed request for achingbrain and Gozala November 30, 2020 14:50
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

src/key.js Outdated Show resolved Hide resolved
Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
Copy link
Contributor

@Gozala Gozala left a 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/adapter.js Outdated Show resolved Hide resolved
src/adapter.js Outdated Show resolved Hide resolved
src/key.js Show resolved Hide resolved
src/key.js Outdated Show resolved Hide resolved
src/key.js Show resolved Hide resolved
src/key.js Outdated Show resolved Hide resolved
src/key.js Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
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')
Copy link
Contributor

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.

Copy link
Member Author

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

hugomrdias and others added 7 commits December 2, 2020 14:26
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
…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
@Gozala
Copy link
Contributor

Gozala commented Dec 3, 2020

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.

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:

  1. Datastore is just a more concrete key value store & it makes sense to express it the same way.
  2. Proposed interfaces decomposed it into multiple interfaces based on their capabilities
    • store lookups
    • store writes
    • store reads
    • store imports (batch write)
    • store export (batch read)
  3. That separation of concerns enables:
    • Writing functions that require subset of capabilities
    • Which makes it clear to the reader what function can do (read stuff ? write stuff ? etc...)
    • Type checker to ensure that no capabilities are violated
    • Setup where reader and writer are different

    General effect of this is e.g. I can expose / implement just read part of the datastore (e.g. over the wire one) and it will claim to implement only read & lookup interfaces. And will be compatible with all the functions that require read capabilities. Now contrast that with one interface to rule them all. It no longer possible to have over the wire store reader that works with any of the functions as they all assume read+write capabilities (even if in practice they don’t need them). In other words:

    • My implementation can’t claim to satisfy existing interface
    • All existing functions are incompatible because they assume read+write (at least for type checker perspective)
    • And even function that don’t need write are hard to identify because types mislead.
    • Instead of encouraging code that follows sepration of concerns it does the opposite.
  4. ipfs-repo is just a just a cluster of key-value stores with diff keys and values that could be expressed by composing those smaller generic interfaces. Which in turn would enable some of the functionality be generic over key value stores regardless of keys and values. Furthermore it would encourage simple consistent API across bunch of components (that right now are slightly inconsistent).
  5. It helpers that e.g that take simpler key value store that just implement read + write interface and return enhanced store that adds imports+exports+query regardless of the keys and values at play.

I do hope in some future we might find enough merit in the arguments above to justify decomposing datastore interface.

@achingbrain achingbrain linked an issue Dec 15, 2020 that may be closed by this pull request
Copy link
Member

@achingbrain achingbrain left a 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 {
Copy link
Member

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) {
Copy link
Member

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 () {
Copy link
Member

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?

Copy link
Member Author

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>;
Copy link
Member

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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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

Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

package.json Outdated Show resolved Hide resolved
src/adapter.js Show resolved Hide resolved
module.exports.dbOpenFailedError = (err) => {
/**
*
* @param {Error} [err]
Copy link
Member

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?

Copy link
Member Author

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.

@achingbrain achingbrain merged commit 8ea7888 into master Jan 15, 2021
@achingbrain achingbrain deleted the feat/ts-types branch January 15, 2021 16:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Additional types maintainer(s)?
4 participants