@libp2p/fetch 1.0.10-bedfd0aa2 → 1.0.10-f0d2b52d0

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 CHANGED
@@ -1,3 +1,5 @@
1
+ # @libp2p/fetch
2
+
1
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
5
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
@@ -7,6 +9,21 @@
7
9
 
8
10
  # About
9
11
 
12
+ <!--
13
+
14
+ !IMPORTANT!
15
+
16
+ Everything in this README between "# About" and "# Install" is automatically
17
+ generated and will be overwritten the next time the doc generator is run.
18
+
19
+ To make changes to this section, please update the @packageDocumentation section
20
+ of src/index.js or src/index.ts
21
+
22
+ To experiment with formatting, please run "npm run docs" from the root of this
23
+ repo and examine the changes made.
24
+
25
+ -->
26
+
10
27
  An implementation of the Fetch protocol as described here: <https://github.com/libp2p/specs/tree/master/fetch>
11
28
 
12
29
  The fetch protocol is a simple protocol for requesting a value corresponding to a key from a peer.
@@ -16,6 +33,7 @@ The fetch protocol is a simple protocol for requesting a value corresponding to
16
33
  ```typescript
17
34
  import { createLibp2p } from 'libp2p'
18
35
  import { fetch } from '@libp2p/fetch'
36
+ import { peerIdFromString } from '@libp2p/peer-id'
19
37
 
20
38
  const libp2p = await createLibp2p({
21
39
  services: {
@@ -23,19 +41,26 @@ const libp2p = await createLibp2p({
23
41
  }
24
42
  })
25
43
 
26
- // Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found.
27
- // All keys must be prefixed my the same prefix, which will be used to find the appropriate key
28
- // lookup function.
29
- async function my_subsystem_key_lookup(key) {
44
+ // Given a key (as a string) returns a value (as a Uint8Array), or undefined
45
+ // if the key isn't found.
46
+ // All keys must be prefixed my the same prefix, which will be used to find
47
+ // the appropriate key lookup function.
48
+ async function my_subsystem_key_lookup (key: string): Promise<Uint8Array | undefined> {
30
49
  // app specific callback to lookup key-value pairs.
50
+ return Uint8Array.from([0, 1, 2, 3, 4])
31
51
  }
32
52
 
33
- // Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/'
34
- libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
53
+ // Enable this peer to respond to fetch requests for keys that begin with
54
+ // '/my_subsystem_key_prefix/'
55
+ libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
35
56
 
36
57
  const key = '/my_subsystem_key_prefix/{...}'
37
- const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance
38
- const value = await libp2p.fetch(peerDst, key)
58
+ const peerDst = peerIdFromString('Qmfoo...')
59
+
60
+ // Load the value from the remote peer, timing out after 10s
61
+ const value = await libp2p.services.fetch.fetch(peerDst, key, {
62
+ signal: AbortSignal.timeout(10_000)
63
+ })
39
64
  ```
40
65
 
41
66
  # Install
@@ -39,7 +39,7 @@ export declare class Fetch implements Startable, FetchInterface {
39
39
  *
40
40
  * @example
41
41
  *
42
- * ```js
42
+ * ```TypeScript
43
43
  * // ...
44
44
  * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
45
45
  * ```
@@ -51,7 +51,7 @@ export declare class Fetch implements Startable, FetchInterface {
51
51
  *
52
52
  * @example
53
53
  *
54
- * ```js
54
+ * ```TypeScript
55
55
  * // ...
56
56
  * libp2p.fetchService.unregisterLookupFunction('/prefix')
57
57
  * ```
package/dist/src/fetch.js CHANGED
@@ -173,7 +173,7 @@ export class Fetch {
173
173
  *
174
174
  * @example
175
175
  *
176
- * ```js
176
+ * ```TypeScript
177
177
  * // ...
178
178
  * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
179
179
  * ```
@@ -190,7 +190,7 @@ export class Fetch {
190
190
  *
191
191
  * @example
192
192
  *
193
- * ```js
193
+ * ```TypeScript
194
194
  * // ...
195
195
  * libp2p.fetchService.unregisterLookupFunction('/prefix')
196
196
  * ```
@@ -10,6 +10,7 @@
10
10
  * ```typescript
11
11
  * import { createLibp2p } from 'libp2p'
12
12
  * import { fetch } from '@libp2p/fetch'
13
+ * import { peerIdFromString } from '@libp2p/peer-id'
13
14
  *
14
15
  * const libp2p = await createLibp2p({
15
16
  * services: {
@@ -17,19 +18,26 @@
17
18
  * }
18
19
  * })
19
20
  *
20
- * // Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found.
21
- * // All keys must be prefixed my the same prefix, which will be used to find the appropriate key
22
- * // lookup function.
23
- * async function my_subsystem_key_lookup(key) {
21
+ * // Given a key (as a string) returns a value (as a Uint8Array), or undefined
22
+ * // if the key isn't found.
23
+ * // All keys must be prefixed my the same prefix, which will be used to find
24
+ * // the appropriate key lookup function.
25
+ * async function my_subsystem_key_lookup (key: string): Promise<Uint8Array | undefined> {
24
26
  * // app specific callback to lookup key-value pairs.
27
+ * return Uint8Array.from([0, 1, 2, 3, 4])
25
28
  * }
26
29
  *
27
- * // Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/'
28
- * libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
30
+ * // Enable this peer to respond to fetch requests for keys that begin with
31
+ * // '/my_subsystem_key_prefix/'
32
+ * libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
29
33
  *
30
34
  * const key = '/my_subsystem_key_prefix/{...}'
31
- * const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance
32
- * const value = await libp2p.fetch(peerDst, key)
35
+ * const peerDst = peerIdFromString('Qmfoo...')
36
+ *
37
+ * // Load the value from the remote peer, timing out after 10s
38
+ * const value = await libp2p.services.fetch.fetch(peerDst, key, {
39
+ * signal: AbortSignal.timeout(10_000)
40
+ * })
33
41
  * ```
34
42
  */
35
43
  import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface';
@@ -62,9 +70,9 @@ export interface Fetch {
62
70
  *
63
71
  * @example
64
72
  *
65
- * ```js
73
+ * ```TypeScript
66
74
  * // ...
67
- * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
75
+ * libp2p.services.fetch.registerLookupFunction('/prefix', (key) => { ... })
68
76
  * ```
69
77
  */
70
78
  registerLookupFunction(prefix: string, lookup: LookupFunction): void;
@@ -74,9 +82,9 @@ export interface Fetch {
74
82
  *
75
83
  * @example
76
84
  *
77
- * ```js
85
+ * ```TypeScript
78
86
  * // ...
79
- * libp2p.fetchService.unregisterLookupFunction('/prefix')
87
+ * libp2p.services.fetch.unregisterLookupFunction('/prefix')
80
88
  * ```
81
89
  */
82
90
  unregisterLookupFunction(prefix: string, lookup?: LookupFunction): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAE9E,MAAM,WAAW,SAAS;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;CAC/C;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACp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ED,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;IAEzF;;;;;;;;;;OAUG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAAA;IAEpE;;;;;;;;;;OAUG;IACH,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;CACxE;AAED,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,KAAK,CAEnF"}
package/dist/src/index.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * ```typescript
11
11
  * import { createLibp2p } from 'libp2p'
12
12
  * import { fetch } from '@libp2p/fetch'
13
+ * import { peerIdFromString } from '@libp2p/peer-id'
13
14
  *
14
15
  * const libp2p = await createLibp2p({
15
16
  * services: {
@@ -17,19 +18,26 @@
17
18
  * }
18
19
  * })
19
20
  *
20
- * // Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found.
21
- * // All keys must be prefixed my the same prefix, which will be used to find the appropriate key
22
- * // lookup function.
23
- * async function my_subsystem_key_lookup(key) {
21
+ * // Given a key (as a string) returns a value (as a Uint8Array), or undefined
22
+ * // if the key isn't found.
23
+ * // All keys must be prefixed my the same prefix, which will be used to find
24
+ * // the appropriate key lookup function.
25
+ * async function my_subsystem_key_lookup (key: string): Promise<Uint8Array | undefined> {
24
26
  * // app specific callback to lookup key-value pairs.
27
+ * return Uint8Array.from([0, 1, 2, 3, 4])
25
28
  * }
26
29
  *
27
- * // Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/'
28
- * libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
30
+ * // Enable this peer to respond to fetch requests for keys that begin with
31
+ * // '/my_subsystem_key_prefix/'
32
+ * libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
29
33
  *
30
34
  * const key = '/my_subsystem_key_prefix/{...}'
31
- * const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance
32
- * const value = await libp2p.fetch(peerDst, key)
35
+ * const peerDst = peerIdFromString('Qmfoo...')
36
+ *
37
+ * // Load the value from the remote peer, timing out after 10s
38
+ * const value = await libp2p.services.fetch.fetch(peerDst, key, {
39
+ * signal: AbortSignal.timeout(10_000)
40
+ * })
33
41
  * ```
34
42
  */
35
43
  import { Fetch as FetchClass } from './fetch.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AA0DhD,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AA0DhD,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/fetch",
3
- "version": "1.0.10-bedfd0aa2",
3
+ "version": "1.0.10-f0d2b52d0",
4
4
  "description": "Implementation of the Fetch Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-fetch#readme",
@@ -48,20 +48,21 @@
48
48
  "test:firefox": "aegir test -t browser -- --browser firefox",
49
49
  "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
50
50
  "test:node": "aegir test -t node --cov",
51
- "dep-check": "aegir dep-check"
51
+ "dep-check": "aegir dep-check",
52
+ "doc-check": "aegir doc-check"
52
53
  },
53
54
  "dependencies": {
54
- "@libp2p/interface": "1.1.3-bedfd0aa2",
55
- "@libp2p/interface-internal": "1.0.8-bedfd0aa2",
55
+ "@libp2p/interface": "1.1.3-f0d2b52d0",
56
+ "@libp2p/interface-internal": "1.0.8-f0d2b52d0",
56
57
  "it-protobuf-stream": "^1.1.2",
57
58
  "protons-runtime": "^5.4.0",
58
59
  "uint8arraylist": "^2.4.8",
59
- "uint8arrays": "^5.0.1"
60
+ "uint8arrays": "^5.0.2"
60
61
  },
61
62
  "devDependencies": {
62
- "@libp2p/logger": "4.0.6-bedfd0aa2",
63
- "@libp2p/peer-id-factory": "4.0.6-bedfd0aa2",
64
- "aegir": "^42.2.3",
63
+ "@libp2p/logger": "4.0.6-f0d2b52d0",
64
+ "@libp2p/peer-id-factory": "4.0.6-f0d2b52d0",
65
+ "aegir": "^42.2.4",
65
66
  "it-pair": "^2.0.6",
66
67
  "protons": "^7.5.0",
67
68
  "sinon": "^17.0.1",
package/src/fetch.ts CHANGED
@@ -195,7 +195,7 @@ export class Fetch implements Startable, FetchInterface {
195
195
  *
196
196
  * @example
197
197
  *
198
- * ```js
198
+ * ```TypeScript
199
199
  * // ...
200
200
  * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
201
201
  * ```
@@ -214,7 +214,7 @@ export class Fetch implements Startable, FetchInterface {
214
214
  *
215
215
  * @example
216
216
  *
217
- * ```js
217
+ * ```TypeScript
218
218
  * // ...
219
219
  * libp2p.fetchService.unregisterLookupFunction('/prefix')
220
220
  * ```
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  * ```typescript
11
11
  * import { createLibp2p } from 'libp2p'
12
12
  * import { fetch } from '@libp2p/fetch'
13
+ * import { peerIdFromString } from '@libp2p/peer-id'
13
14
  *
14
15
  * const libp2p = await createLibp2p({
15
16
  * services: {
@@ -17,19 +18,26 @@
17
18
  * }
18
19
  * })
19
20
  *
20
- * // Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found.
21
- * // All keys must be prefixed my the same prefix, which will be used to find the appropriate key
22
- * // lookup function.
23
- * async function my_subsystem_key_lookup(key) {
21
+ * // Given a key (as a string) returns a value (as a Uint8Array), or undefined
22
+ * // if the key isn't found.
23
+ * // All keys must be prefixed my the same prefix, which will be used to find
24
+ * // the appropriate key lookup function.
25
+ * async function my_subsystem_key_lookup (key: string): Promise<Uint8Array | undefined> {
24
26
  * // app specific callback to lookup key-value pairs.
27
+ * return Uint8Array.from([0, 1, 2, 3, 4])
25
28
  * }
26
29
  *
27
- * // Enable this peer to respond to fetch requests for keys that begin with '/my_subsystem_key_prefix/'
28
- * libp2p.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
30
+ * // Enable this peer to respond to fetch requests for keys that begin with
31
+ * // '/my_subsystem_key_prefix/'
32
+ * libp2p.services.fetch.registerLookupFunction('/my_subsystem_key_prefix/', my_subsystem_key_lookup)
29
33
  *
30
34
  * const key = '/my_subsystem_key_prefix/{...}'
31
- * const peerDst = PeerId.parse('Qmfoo...') // or Multiaddr instance
32
- * const value = await libp2p.fetch(peerDst, key)
35
+ * const peerDst = peerIdFromString('Qmfoo...')
36
+ *
37
+ * // Load the value from the remote peer, timing out after 10s
38
+ * const value = await libp2p.services.fetch.fetch(peerDst, key, {
39
+ * signal: AbortSignal.timeout(10_000)
40
+ * })
33
41
  * ```
34
42
  */
35
43
 
@@ -70,9 +78,9 @@ export interface Fetch {
70
78
  *
71
79
  * @example
72
80
  *
73
- * ```js
81
+ * ```TypeScript
74
82
  * // ...
75
- * libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
83
+ * libp2p.services.fetch.registerLookupFunction('/prefix', (key) => { ... })
76
84
  * ```
77
85
  */
78
86
  registerLookupFunction(prefix: string, lookup: LookupFunction): void
@@ -83,9 +91,9 @@ export interface Fetch {
83
91
  *
84
92
  * @example
85
93
  *
86
- * ```js
94
+ * ```TypeScript
87
95
  * // ...
88
- * libp2p.fetchService.unregisterLookupFunction('/prefix')
96
+ * libp2p.services.fetch.unregisterLookupFunction('/prefix')
89
97
  * ```
90
98
  */
91
99
  unregisterLookupFunction(prefix: string, lookup?: LookupFunction): void