From e6d41a0e9e0bb4bc6fd1ac709c00a0478b7d41b5 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 2 Feb 2024 19:06:09 +0100 Subject: [PATCH] fix: @helia/verified-fetch init args are optional (#412) 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...') // ... ``` --- src/index.ts | 6 +++--- test/index.spec.ts | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9aa4e17e..c23a77df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -278,15 +278,15 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions { +export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchWithOptions): Promise { 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)) }) } diff --git a/test/index.spec.ts b/test/index.spec.ts index 1e0f47ef..9fcfc897 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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() + }) })