Skip to content

Commit

Permalink
fix: @helia/verified-fetch init args are optional (#412)
Browse files Browse the repository at this point in the history
To allow no-option, all-defaults construction of verified fetch

```TypeScript
import { createVerifiedFetch } from '@helia/verified-fetch'

const fetch = await createVerifiedFetch()

const resp = await fetch('ipfs://bafy...')
// ...
```
  • Loading branch information
achingbrain authored Feb 2, 2024
1 parent 06d36fe commit e6d41a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledP
/**
* Create and return a Helia node
*/
export async function createVerifiedFetch (init: Helia | CreateVerifiedFetchWithOptions): Promise<VerifiedFetch> {
export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchWithOptions): Promise<VerifiedFetch> {
if (!isHelia(init)) {
init = await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
gateways: init.gateways
gateways: init?.gateways
})
],
routers: init.routers?.map((routerUrl) => delegatedHTTPRouting(routerUrl))
routers: (init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl))
})
}

Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ describe('createVerifiedFetch', () => {
expect(verifiedFetch).to.be.ok()
await verifiedFetch.stop()
})

it('can be constructed with no options', async () => {
const verifiedFetch = await createVerifiedFetch()

expect(verifiedFetch).to.be.ok()
await verifiedFetch.stop()
})
})

0 comments on commit e6d41a0

Please sign in to comment.