-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat: allow use as a singleton #413
Conversation
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...') // ... ```
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 ```
Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com>
I think we should leave the singleton to the most basic, unconfigurable, usecase and have users use createVerifiedFetch if they want to customize gateways, so that we don't have to muck around with error and edge-cases or confusion on the second options argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love the updates to the readme.
This might make things even easier to get started? It exports a singleton version of verified fetch that creates the backing Helia node on the first fetch access, transparent to the user.
It's not in this PR but maybe we'd want to allow some config:
Calling this twice with different gateways might result in an error.