From b4877b5b768895684be90a26f4303ae65fc209e7 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 1 Jul 2024 17:40:21 +0200 Subject: [PATCH] fix: update js-libp2p types (#570) 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. --- packages/helia/src/index.ts | 2 +- packages/helia/src/utils/libp2p-defaults.browser.ts | 2 +- packages/helia/src/utils/libp2p-defaults.ts | 2 +- packages/helia/test/libp2p.spec.ts | 2 ++ packages/interop/src/fixtures/create-helia.browser.ts | 3 +++ packages/interop/src/fixtures/create-helia.ts | 3 +++ 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/helia/src/index.ts b/packages/helia/src/index.ts index 5ec50bfc0..3fdd7732e 100644 --- a/packages/helia/src/index.ts +++ b/packages/helia/src/index.ts @@ -65,7 +65,7 @@ export interface HeliaInit extends HeliaClassInit { * The libp2p `start` option is not supported, instead please pass `start` in * the root of the HeliaInit object. */ - libp2p?: T | Omit + libp2p?: T | Omit, 'start'> /** * Pass `false` to not start the Helia node diff --git a/packages/helia/src/utils/libp2p-defaults.browser.ts b/packages/helia/src/utils/libp2p-defaults.browser.ts index 524094e93..85cd58391 100644 --- a/packages/helia/src/utils/libp2p-defaults.browser.ts +++ b/packages/helia/src/utils/libp2p-defaults.browser.ts @@ -31,7 +31,7 @@ export interface DefaultLibp2pServices extends Record { ping: PingService } -export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions { +export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions & Required, 'services'>> { const agentVersion = `${name}/${version} ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${globalThis.navigator.userAgent}` return { diff --git a/packages/helia/src/utils/libp2p-defaults.ts b/packages/helia/src/utils/libp2p-defaults.ts index 3d698facb..b7c6b8ab6 100644 --- a/packages/helia/src/utils/libp2p-defaults.ts +++ b/packages/helia/src/utils/libp2p-defaults.ts @@ -35,7 +35,7 @@ export interface DefaultLibp2pServices extends Record { upnp: unknown } -export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions { +export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions & Required, 'services'>> { const agentVersion = `${name}/${version} ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${process.version}` return { diff --git a/packages/helia/test/libp2p.spec.ts b/packages/helia/test/libp2p.spec.ts index 068c7b630..4f1f533bb 100644 --- a/packages/helia/test/libp2p.spec.ts +++ b/packages/helia/test/libp2p.spec.ts @@ -25,6 +25,8 @@ describe('libp2p', () => { it('allows overriding libp2p config', async () => { const config = { + addresses: {}, + transports: [], services: {} } diff --git a/packages/interop/src/fixtures/create-helia.browser.ts b/packages/interop/src/fixtures/create-helia.browser.ts index ccea8a44c..921e73b80 100644 --- a/packages/interop/src/fixtures/create-helia.browser.ts +++ b/packages/interop/src/fixtures/create-helia.browser.ts @@ -52,8 +52,11 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise>({ diff --git a/packages/interop/src/fixtures/create-helia.ts b/packages/interop/src/fixtures/create-helia.ts index 367af9255..42319aa31 100644 --- a/packages/interop/src/fixtures/create-helia.ts +++ b/packages/interop/src/fixtures/create-helia.ts @@ -39,8 +39,11 @@ export async function createHeliaNode (libp2pOptions?: Libp2pOptions): Promise>({