Skip to content

fix: ignore libp2p start param in helia factory #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/helia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export interface HeliaInit<T extends Libp2p = Libp2p> {
* If node options are passed, they will be merged with the default
* config for the current platform. In this case all passed config
* keys will replace those from the default config.
*
* The libp2p `start` option is not supported, instead please pass `start` in
* the root of the HeliaInit object.
*/
libp2p?: T | Libp2pOptions
libp2p?: T | Omit<Libp2pOptions, 'start'>

/**
* The blockstore is where blocks are stored
Expand Down Expand Up @@ -152,7 +155,13 @@ export async function createHelia (init: HeliaInit = {}): Promise<HeliaLibp2p> {
} else {
libp2p = await createLibp2p<DefaultLibp2pServices>({
...init,
libp2p: init.libp2p,
libp2p: {
...init.libp2p,

// ignore the libp2p start parameter as it should be on the main init
// object instead
start: undefined
},
datastore
})
}
Expand Down
24 changes: 24 additions & 0 deletions packages/helia/test/libp2p.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,28 @@ describe('libp2p', () => {

expect(helia.libp2p).to.equal(libp2p)
})

it('ignores libp2p start param when it is false', async () => {
helia = await createHelia({
libp2p: {
// @ts-expect-error start is omitted from libp2p init type
start: false
},
start: true
})

expect(helia.libp2p.status).to.equal('started')
})

it('ignores libp2p start param when it is true', async () => {
helia = await createHelia({
libp2p: {
// @ts-expect-error start is omitted from libp2p init type
start: true
},
start: false
})

expect(helia.libp2p.status).to.equal('stopped')
})
})