Skip to content
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

docs: generate readme #70

Merged
merged 17 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 9 additions & 4 deletions packages/verified-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ A `verifiedFetch` function is exported to get up and running quickly, and a `cre

Browser-cache-friendly [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects are returned which should be instantly familiar to web developers.

Learn more in the [announcement blog post](https://blog.ipfs.tech/verified-fetch/) and check out the [ready-to-run example](https://github.com/ipfs-examples/helia-examples/tree/main/examples/helia-browser-verified-fetch).

You may use any supported resource argument to fetch content:

- [CID](https://multiformats.github.io/js-multiformats/classes/cid.CID.html) instance
Expand Down Expand Up @@ -122,17 +124,20 @@ You can see variations of Helia and js-libp2p configuration options at <https://
```typescript
import { trustlessGateway } from '@helia/block-brokers'
import { createHeliaHTTP } from '@helia/http'
import { delegatedHTTPRouting } from '@helia/routers'
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
import { createVerifiedFetch } from '@helia/verified-fetch'

const fetch = await createVerifiedFetch(
await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
trustlessGateway()
],
routers: [
...['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl)),
httpGatewayRouting({
gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
})
],
routers: ['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl))
]
})
)

Expand Down
24 changes: 15 additions & 9 deletions packages/verified-fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,25 @@
*
* The [helia](https://www.npmjs.com/package/helia) module is configured with a libp2p node that is suited for decentralized applications, alternatively [@helia/http](https://www.npmjs.com/package/@helia/http) is available which uses HTTP gateways for all network operations.
*
* See variations of [Helia and js-libp2p configuration options](https://helia.io/interfaces/helia.HeliaInit.html)
* You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
*
* ```typescript
* import { trustlessGateway } from '@helia/block-brokers'
* import { createHeliaHTTP } from '@helia/http'
* import { delegatedHTTPRouting } from '@helia/routers'
* import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
* import { createVerifiedFetch } from '@helia/verified-fetch'
*
* const fetch = await createVerifiedFetch(
* await createHeliaHTTP({
* blockBrokers: [
* trustlessGateway({
* trustlessGateway()
* ],
* routers: [
* ...['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl)),
* httpGatewayRouting({
* gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
* })
* ],
* routers: ['http://delegated-ipfs.dev'].map((routerUrl) => delegatedHTTPRouting(routerUrl))
* ]
* })
* )
*
Expand Down Expand Up @@ -588,12 +591,12 @@
* 1. `TypeError` - If the resource argument is not a string, CID, or CID string.
* 2. `TypeError` - If the options argument is passed and not an object.
* 3. `TypeError` - If the options argument is passed and is malformed.
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal.
* 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
*/

import { trustlessGateway } from '@helia/block-brokers'
import { createHeliaHTTP } from '@helia/http'
import { delegatedHTTPRouting } from '@helia/routers'
import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
import { dns } from '@multiformats/dns'
import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js'
import type { GetBlockProgressEvents, Helia } from '@helia/interface'
Expand Down Expand Up @@ -707,11 +710,14 @@ export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchIni
if (!isHelia(init)) {
init = await createHeliaHTTP({
blockBrokers: [
trustlessGateway({
trustlessGateway()
],
routers: [
...(init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
httpGatewayRouting({
gateways: init?.gateways
})
],
routers: (init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
dns: createDns(init?.dnsResolvers)
})
}
Expand Down
Loading