-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This might make things even easier to get started? ```TypeScript import { verifiedFetch } from '@helia/verified-fetch' const response = await verifiedFetch('ipfs://Qmfoo') console.info(await response.json()) ``` It's not in this PR but maybe we'd want to allow some config: ```TypeScript import { verifiedFetch } from '@helia/verified-fetch' const response = await verifiedFetch('ipfs://Qmfoo', { gateways: ['https://...'] }) console.info(await response.json()) ``` Calling this twice with different gateways might result in an error. ```TypeScript import { verifiedFetch } from '@helia/verified-fetch' const response1 = await verifiedFetch('ipfs://Qmfoo', { gateways: ['https://foo...'] }) const response2 = await verifiedFetch('ipfs://Qmfoo', { gateways: ['https://bar...'] }) // Error: Only one set of gateways/routers may be specified, please use `createVerifiedFetch` for more flexibility ```
- Loading branch information
1 parent
8dcf18e
commit f29d6a6
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createVerifiedFetch } from './index.js' | ||
import type { Resource, VerifiedFetch, VerifiedFetchInit } from './index.js' | ||
|
||
interface VerifiedFetchSingleton extends VerifiedFetch { | ||
_impl?: VerifiedFetch | ||
} | ||
|
||
const singleton: VerifiedFetchSingleton = async function verifiedFetch (resource: Resource, options?: VerifiedFetchInit): Promise<Response> { | ||
if (singleton._impl == null) { | ||
singleton._impl = await createVerifiedFetch() | ||
} | ||
|
||
return singleton._impl(resource, options) | ||
} | ||
singleton.start = async function () { | ||
await singleton._impl?.stop() | ||
} | ||
singleton.stop = async function () { | ||
await singleton._impl?.stop() | ||
} | ||
const verifiedFetchSingleton: VerifiedFetch = singleton | ||
|
||
export { verifiedFetchSingleton as verifiedFetch } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters