@helia/block-brokers 4.2.4 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/bitswap.js +4 -4
- package/dist/src/bitswap.js.map +1 -1
- package/dist/src/index.d.ts +48 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +48 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/trustless-gateway/broker.d.ts +4 -1
- package/dist/src/trustless-gateway/broker.d.ts.map +1 -1
- package/dist/src/trustless-gateway/broker.js.map +1 -1
- package/dist/src/trustless-gateway/utils.d.ts +2 -2
- package/dist/src/trustless-gateway/utils.d.ts.map +1 -1
- package/dist/src/trustless-gateway/utils.js +3 -3
- package/dist/src/trustless-gateway/utils.js.map +1 -1
- package/package.json +20 -26
- package/src/bitswap.ts +4 -4
- package/src/index.ts +49 -0
- package/src/trustless-gateway/broker.ts +5 -1
- package/src/trustless-gateway/utils.ts +6 -5
package/README.md
CHANGED
|
@@ -13,6 +13,68 @@
|
|
|
13
13
|
|
|
14
14
|
> Block brokers for Helia
|
|
15
15
|
|
|
16
|
+
# About
|
|
17
|
+
|
|
18
|
+
<!--
|
|
19
|
+
|
|
20
|
+
!IMPORTANT!
|
|
21
|
+
|
|
22
|
+
Everything in this README between "# About" and "# Install" is automatically
|
|
23
|
+
generated and will be overwritten the next time the doc generator is run.
|
|
24
|
+
|
|
25
|
+
To make changes to this section, please update the @packageDocumentation section
|
|
26
|
+
of src/index.js or src/index.ts
|
|
27
|
+
|
|
28
|
+
To experiment with formatting, please run "npm run docs" from the root of this
|
|
29
|
+
repo and examine the changes made.
|
|
30
|
+
|
|
31
|
+
-->
|
|
32
|
+
|
|
33
|
+
This module contains Helia block brokers, currently for [bitswap](https://docs.ipfs.tech/concepts/bitswap/)
|
|
34
|
+
and [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
|
|
35
|
+
|
|
36
|
+
## Trustless Gateway Block Broker
|
|
37
|
+
|
|
38
|
+
The TrustlessGatewayBlockBroker fetches blocks from HTTP gateways.
|
|
39
|
+
|
|
40
|
+
## Example - Customizing fetch requests with custom headers
|
|
41
|
+
|
|
42
|
+
It is possible to modify outgoing requests to (for example) include
|
|
43
|
+
authentication information (such as a JWT token in a header).
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { createHelia } from 'helia'
|
|
47
|
+
import { trustlessGateway } from '@helia/block-brokers'
|
|
48
|
+
import { unixfs } from '@helia/unixfs'
|
|
49
|
+
import { CID } from 'multiformats/cid'
|
|
50
|
+
import { concat } from 'uint8arrays/concat'
|
|
51
|
+
import all from 'it-all'
|
|
52
|
+
|
|
53
|
+
const helia = await createHelia({
|
|
54
|
+
blockBrokers: [
|
|
55
|
+
trustlessGateway({
|
|
56
|
+
transformRequestInit: (requestInit) => {
|
|
57
|
+
// modify the request init object as required
|
|
58
|
+
requestInit.headers = {
|
|
59
|
+
...requestInit.headers,
|
|
60
|
+
'User-Agent': 'Helia Example Script'
|
|
61
|
+
}
|
|
62
|
+
return requestInit
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const cid = CID.parse('bafkreife2klsil6kaxqhvmhgldpsvk5yutzm4i5bgjoq6fydefwtihnesa')
|
|
69
|
+
const fs = unixfs(helia)
|
|
70
|
+
|
|
71
|
+
for await (const chunk of fs.cat(cid, {
|
|
72
|
+
signal: AbortSignal.timeout(10_000)
|
|
73
|
+
})) {
|
|
74
|
+
console.info(chunk)
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
16
78
|
# Install
|
|
17
79
|
|
|
18
80
|
```console
|