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

chore: add dht selectors and validators #94

Merged
merged 4 commits into from
Apr 22, 2021

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Apr 21, 2021

Adds dht selectors and validators here to be used across the board easily.

Also removes unecessary EventEmitter types, as this was already fixed

@vasco-santos vasco-santos force-pushed the chore/add-dht-selectors-validators branch from d0df910 to b2cdea0 Compare April 21, 2021 15:58
new(): EventEmitter;
}
export type SelectFn = function (Uint8Array, Uint8Array[]): number
export type ValidateFn = function (Uint8Array, Uint8Array): Promise<void>
Copy link
Member

Choose a reason for hiding this comment

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

If you add a typedef to /src/index.js like:

/**
 * @typedef {import('./types').SelectFn} SelectFn
 * @typedef {import('./types').ValidateFn} ValidateFn
 * @typedef {import('./types').DhtSelectors} DhtSelectors
 * @typedef {import('./types').DhtValidators} DhtValidators
 */

then you can use them from other modules like:

/**
 * @typedef {import('libp2p-interfaces').SelectFn} SelectFn
 */

otherwise you have to do:

/**
 * @typedef {import('libp2p-interfaces/src/types').SelectFn} SelectFn
 */

Which is ok, but needs the typesVersions hack and prevents you from moving that file in future.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was causing:

src/validator.js:15:19 - error TS2306: File '/Users/vsantos/work/pl/gh/libp2p/js-libp2p-record/node_modules/libp2p-interfaces/dist/src/index.d.ts' is not a module.
15  * @param {import('libp2p-interfaces').DhtValidators} validators

After generated

type SelectFn = import('./types').SelectFn;
type ValidateFn = import('./types').ValidateFn;
type DhtSelectors = import('./types').DhtSelectors;
type DhtValidators = import('./types').DhtValidators;
//# sourceMappingURL=index.d.ts.map

I could not easily work around this issue, so I reverted to the original solution for now

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.

Small suggestion inline, not a blocker

@vasco-santos vasco-santos merged commit 5bf2555 into master Apr 22, 2021
@vasco-santos vasco-santos deleted the chore/add-dht-selectors-validators branch April 22, 2021 07:36
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.

2 participants