Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

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

Merged
merged 37 commits into from
Jan 21, 2021
Merged

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

merged 37 commits into from
Jan 21, 2021

Conversation

hugomrdias
Copy link
Member

@hugomrdias 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.. )
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.

Mostly good. Just minor things to be fixed

src/keytransform.js Outdated Show resolved Hide resolved
src/keytransform.js Outdated Show resolved Hide resolved
src/keytransform.js Outdated Show resolved Hide resolved
src/mount.js Outdated Show resolved Hide resolved
src/mount.js Outdated Show resolved Hide resolved
has (key, options) {
const match = this._lookup(key)
if (match == null) {
return false
return Promise.resolve(false)
Copy link
Member

Choose a reason for hiding this comment

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

Return types are inferred from the interface. However, it would probably be helpful to have them in the code, special for returning promises. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe interface should be changed to has(key:Key, options?:Options): Await<boolean> instead so wrapping in promise is unnecessary ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Gozala for that we would need to make it an async function
@vasco-santos i would like to avoid writing all the return types if they are already well inferred

Copy link
Contributor

Choose a reason for hiding this comment

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

@Gozala for that we would need to make it an async function

I don't believe that's accurate, in fact that was the whole point of Await type. Here is an example:

type Await<T> = Promise<T> | T

interface Key {
    toString():string
}

interface Has {
    has(key:Key, options?:{signal?: AbortSignal}):Await<boolean>
}

class Store implements Has {
    has(key:Key, options:{signal?: AbortSignal}):Await<boolean> {
        if (key.toString().startsWith('http://')) {
          return fetch(key.toString()).then(response => response.ok)
        } else {
            return false
        }
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

As a pattern I think Await<T> is something we should allow. The idea of the return type being variable is a bit weird, but in the past we've desired the ability to not create artificial asynchronicity for super-hot codepaths, the idea being you'd look at the return type and resolve the promise if it's a thenable.

Though it's not something we should be doing everywhere, blindly awaiting will be fine 99.9% of the time, unless some rigorous profiling has identified a bottleneck.

Copy link
Member

Choose a reason for hiding this comment

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

It does make the error handling for the caller a bit Zalgo harder to handle, mind:

async function derp (input) {
  if (input % 2 === 1) {
    throw new Error('Input was odd')
  }

  return Promise.reject(new Error('Input was even'))
}
const res1 = derp(1) // throws immediately

const res2 = derp(2)

// maybe do some other stuff

await res2 // throws here instead

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you think we should do here ?

src/mount.js Show resolved Hide resolved
src/namespace.js Outdated Show resolved Hide resolved
src/namespace.js Outdated Show resolved Hide resolved
src/shard.js Outdated Show resolved Hide resolved
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.

Looks good! Mostly provided some minor suggestions, I do however would like type-check succeed here instead of failing due to lack of generated types.

.github/workflows/main.yml Outdated Show resolved Hide resolved
src/keytransform.js Show resolved Hide resolved
src/keytransform.js Outdated Show resolved Hide resolved
src/keytransform.js Outdated Show resolved Hide resolved
src/keytransform.js Outdated Show resolved Hide resolved
src/tiered.js Outdated Show resolved Hide resolved
src/tiered.js Outdated Show resolved Hide resolved
src/tiered.js Show resolved Hide resolved
src/tiered.js Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
hugomrdias and others added 22 commits December 9, 2020 15:58
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[email protected]>
Co-authored-by: Vasco Santos <[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]>
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]>
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]>
hugomrdias and others added 5 commits December 9, 2020 16:53
Co-authored-by: Irakli Gozalishvili <[email protected]>
Co-authored-by: Irakli Gozalishvili <[email protected]>
…core into feat/ts-types

* 'feat/ts-types' of https://github.com/ipfs/js-datastore-core: (24 commits)
  Update src/tiered.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/sharding.js
  Update src/tiered.js
  Update src/tiered.js
  Update src/tiered.js
  Update src/keytransform.js
  Update src/keytransform.js
  Update src/keytransform.js
  Update src/keytransform.js
  Update .github/workflows/main.yml
  Update src/shard.js
  Update src/namespace.js
  Update src/namespace.js
  Update src/mount.js
  ...
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!

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.

Recent changes seem to have updated all the import paths from interface-datastore/src/* to interface-datastore/dist/src/*. I do not know if that is deliberate, but I do think it's great as it is going to be confusing.

@achingbrain achingbrain merged commit bee45ae into master Jan 21, 2021
@achingbrain achingbrain deleted the feat/ts-types branch January 21, 2021 18:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants