Skip to content

Commit

Permalink
fix: update js-libp2p types (#570)
Browse files Browse the repository at this point in the history
After the last js-libp2p release, tsc now decides that the service factory map has a type and libp2p itself is better at detecting invalid configurations so we need to be stricter about how we create libp2p options.
  • Loading branch information
achingbrain authored Jul 1, 2024
1 parent 74ccc92 commit b4877b5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/helia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface HeliaInit<T extends Libp2p = Libp2p> extends HeliaClassInit {
* The libp2p `start` option is not supported, instead please pass `start` in
* the root of the HeliaInit object.
*/
libp2p?: T | Omit<Libp2pOptions, 'start'>
libp2p?: T | Omit<Libp2pOptions<any>, 'start'>

/**
* Pass `false` to not start the Helia node
Expand Down
2 changes: 1 addition & 1 deletion packages/helia/src/utils/libp2p-defaults.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
ping: PingService
}

export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> & Required<Pick<Libp2pOptions<DefaultLibp2pServices>, 'services'>> {
const agentVersion = `${name}/${version} ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${globalThis.navigator.userAgent}`

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/helia/src/utils/libp2p-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
upnp: unknown
}

export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> & Required<Pick<Libp2pOptions<DefaultLibp2pServices>, 'services'>> {
const agentVersion = `${name}/${version} ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${process.version}`

return {
Expand Down
2 changes: 2 additions & 0 deletions packages/helia/test/libp2p.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('libp2p', () => {

it('allows overriding libp2p config', async () => {
const config = {
addresses: {},
transports: [],
services: {}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/interop/src/fixtures/create-helia.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
defaults.peerDiscovery = []

// remove services that are not used in tests
// @ts-expect-error services.autoNAT is not optional
delete defaults.services.autoNAT
// @ts-expect-error services.dcutr is not optional
delete defaults.services.dcutr
// @ts-expect-error services.delegatedRouting is not optional
delete defaults.services.delegatedRouting

return createHelia<Libp2p<DefaultLibp2pServices>>({
Expand Down
3 changes: 3 additions & 0 deletions packages/interop/src/fixtures/create-helia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise<H
defaults.peerDiscovery = []

// remove services that are not used in tests
// @ts-expect-error services.autoNAT is not optional
delete defaults.services.autoNAT
// @ts-expect-error services.dcutr is not optional
delete defaults.services.dcutr
// @ts-expect-error services.delegatedRouting is not optional
delete defaults.services.delegatedRouting

return createHelia<Libp2p<DefaultLibp2pServices>>({
Expand Down

0 comments on commit b4877b5

Please sign in to comment.