@helia/interface 6.2.1-6f8165b5 → 6.2.1-9114743f
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/blocks.d.ts +8 -8
- package/dist/src/blocks.d.ts.map +1 -1
- package/dist/src/errors.d.ts +4 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/graph-walker.d.ts +28 -0
- package/dist/src/graph-walker.d.ts.map +1 -0
- package/dist/src/graph-walker.js +2 -0
- package/dist/src/graph-walker.js.map +1 -0
- package/dist/src/index.d.ts +62 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/pins.d.ts +10 -1
- package/dist/src/pins.d.ts.map +1 -1
- package/dist/src/routing.d.ts +66 -25
- package/dist/src/routing.d.ts.map +1 -1
- package/package.json +9 -4
- package/src/blocks.ts +8 -8
- package/src/errors.ts +5 -0
- package/src/graph-walker.ts +38 -0
- package/src/index.ts +73 -14
- package/src/pins.ts +11 -2
- package/src/routing.ts +72 -25
package/dist/src/routing.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import type { AbortOptions } from 'abort-error';
|
|
2
3
|
import type { CID } from 'multiformats/cid';
|
|
3
4
|
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
4
5
|
/**
|
|
@@ -7,7 +8,7 @@ import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
|
7
8
|
* local cache that may be used in preference over network calls, for example
|
|
8
9
|
* when a record has a TTL.
|
|
9
10
|
*/
|
|
10
|
-
export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event
|
|
11
|
+
export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event> {
|
|
11
12
|
/**
|
|
12
13
|
* Pass `false` to not use the network
|
|
13
14
|
*
|
|
@@ -26,11 +27,36 @@ export interface RoutingOptions<Event extends ProgressEvent = any> extends Abort
|
|
|
26
27
|
* @default true
|
|
27
28
|
*/
|
|
28
29
|
validate?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Where tracing is used, this value carries tracing context
|
|
32
|
+
*/
|
|
33
|
+
trace?: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A Peer is another node on the network
|
|
37
|
+
*/
|
|
38
|
+
export interface Peer {
|
|
39
|
+
/**
|
|
40
|
+
* The identifier of the remote peer
|
|
41
|
+
*/
|
|
42
|
+
id: CID;
|
|
43
|
+
/**
|
|
44
|
+
* The multiaddrs a peer is listening on
|
|
45
|
+
*/
|
|
46
|
+
multiaddrs: Multiaddr[];
|
|
29
47
|
}
|
|
30
48
|
/**
|
|
31
49
|
* A provider can supply the content for a CID
|
|
32
50
|
*/
|
|
33
|
-
export interface Provider
|
|
51
|
+
export interface Provider {
|
|
52
|
+
/**
|
|
53
|
+
* The identifier of the remote peer, a CID
|
|
54
|
+
*/
|
|
55
|
+
id: CID;
|
|
56
|
+
/**
|
|
57
|
+
* The multiaddrs a peer is listening on
|
|
58
|
+
*/
|
|
59
|
+
multiaddrs: Multiaddr[];
|
|
34
60
|
/**
|
|
35
61
|
* If present these are the methods that the peer can supply the content via.
|
|
36
62
|
*
|
|
@@ -61,14 +87,14 @@ export interface RoutingFindProvidersEndEvent {
|
|
|
61
87
|
export interface RoutingFindProvidersHttpGatewayProvider {
|
|
62
88
|
routing: 'http-gateway-router';
|
|
63
89
|
cid: CID;
|
|
64
|
-
provider:
|
|
90
|
+
provider: Peer & {
|
|
65
91
|
protocols: ['transport-ipfs-gateway-http'];
|
|
66
92
|
};
|
|
67
93
|
}
|
|
68
94
|
export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
|
|
69
95
|
routing: 'delegated-http-router';
|
|
70
96
|
cid: CID;
|
|
71
|
-
provider:
|
|
97
|
+
provider: Peer & {
|
|
72
98
|
routing: 'delegated-http-routing';
|
|
73
99
|
protocols: string[];
|
|
74
100
|
};
|
|
@@ -76,7 +102,7 @@ export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
|
|
|
76
102
|
export interface RoutingFindProvidersLibp2pProvider {
|
|
77
103
|
routing: 'libp2p-router';
|
|
78
104
|
cid: CID;
|
|
79
|
-
provider:
|
|
105
|
+
provider: Peer;
|
|
80
106
|
}
|
|
81
107
|
export type RoutingFindProvidersProviderEvent = RoutingFindProvidersHttpGatewayProvider | RoutingFindProvidersDelegatedHttpRoutingProvider | RoutingFindProvidersLibp2pProvider;
|
|
82
108
|
export type RoutingFindProvidersProgressEvents = ProgressEvent<'helia:routing:find-providers:start', RoutingFindProvidersStartEvent> | ProgressEvent<'helia:routing:find-providers:provider', RoutingFindProvidersProviderEvent> | ProgressEvent<'helia:routing:find-providers:end', RoutingFindProvidersEndEvent> | RoutingFindPeerProgressEvents;
|
|
@@ -120,11 +146,11 @@ export interface RoutingGetEndEvent {
|
|
|
120
146
|
export type RoutingGetProgressEvents = ProgressEvent<'helia:routing:get:start', RoutingGetStartEvent> | ProgressEvent<'helia:routing:get:end', RoutingGetEndEvent>;
|
|
121
147
|
export interface RoutingFindPeerStartEvent {
|
|
122
148
|
routing: string;
|
|
123
|
-
peerId:
|
|
149
|
+
peerId: CID;
|
|
124
150
|
}
|
|
125
151
|
export interface RoutingFindPeerEndEvent {
|
|
126
152
|
routing: string;
|
|
127
|
-
peerId:
|
|
153
|
+
peerId: CID;
|
|
128
154
|
}
|
|
129
155
|
export type RoutingFindPeerProgressEvents = ProgressEvent<'helia:routing:find-peer:start', RoutingFindPeerStartEvent> | ProgressEvent<'helia:routing:find-peer:end', RoutingFindPeerEndEvent>;
|
|
130
156
|
export interface RoutingGetClosestPeersStartEvent {
|
|
@@ -136,7 +162,7 @@ export interface RoutingGetClosestPeersEndEvent {
|
|
|
136
162
|
key: Uint8Array;
|
|
137
163
|
}
|
|
138
164
|
export type RoutingGetClosestPeersProgressEvents = ProgressEvent<'helia:routing:get-closest-peers:start', RoutingGetClosestPeersStartEvent> | ProgressEvent<'helia:routing:get-closest-peers:end', RoutingGetClosestPeersEndEvent>;
|
|
139
|
-
export interface
|
|
165
|
+
export interface Router {
|
|
140
166
|
/**
|
|
141
167
|
* The name of this routing implementation
|
|
142
168
|
*/
|
|
@@ -149,10 +175,12 @@ export interface Routing {
|
|
|
149
175
|
*
|
|
150
176
|
* ```js
|
|
151
177
|
* // ...
|
|
152
|
-
* await contentRouting.provide(cid
|
|
178
|
+
* await contentRouting.provide(cid, {
|
|
179
|
+
* signal: AbortSignal.timeout(5_000)
|
|
180
|
+
* })
|
|
153
181
|
* ```
|
|
154
182
|
*/
|
|
155
|
-
provide(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
|
|
183
|
+
provide?(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
|
|
156
184
|
/**
|
|
157
185
|
* Helia will periodically re-provide every previously provided CID. Use this
|
|
158
186
|
* method to no longer re-provide the passed CID.
|
|
@@ -161,10 +189,12 @@ export interface Routing {
|
|
|
161
189
|
*
|
|
162
190
|
* ```js
|
|
163
191
|
* // ...
|
|
164
|
-
* await contentRouting.cancelReprovide(cid
|
|
192
|
+
* await contentRouting.cancelReprovide(cid, {
|
|
193
|
+
* signal: AbortSignal.timeout(5_000)
|
|
194
|
+
* })
|
|
165
195
|
* ```
|
|
166
196
|
*/
|
|
167
|
-
cancelReprovide(key: CID, options?: AbortOptions): Promise<void>;
|
|
197
|
+
cancelReprovide?(key: CID, options?: AbortOptions): Promise<void>;
|
|
168
198
|
/**
|
|
169
199
|
* Find the providers of the passed CID.
|
|
170
200
|
*
|
|
@@ -172,12 +202,14 @@ export interface Routing {
|
|
|
172
202
|
*
|
|
173
203
|
* ```js
|
|
174
204
|
* // Iterate over the providers found for the given cid
|
|
175
|
-
* for await (const provider of contentRouting.findProviders(cid
|
|
205
|
+
* for await (const provider of contentRouting.findProviders(cid, {
|
|
206
|
+
* signal: AbortSignal.timeout(5_000)
|
|
207
|
+
* })) {
|
|
176
208
|
* console.log(provider.id, provider.multiaddrs)
|
|
177
209
|
* }
|
|
178
210
|
* ```
|
|
179
211
|
*/
|
|
180
|
-
findProviders(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
|
|
212
|
+
findProviders?(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
|
|
181
213
|
/**
|
|
182
214
|
* Puts a value corresponding to the passed key in a way that can later be
|
|
183
215
|
* retrieved by another network peer using the get method.
|
|
@@ -186,13 +218,15 @@ export interface Routing {
|
|
|
186
218
|
*
|
|
187
219
|
* ```js
|
|
188
220
|
* // ...
|
|
189
|
-
* const key = '/key'
|
|
221
|
+
* const key = uint8ArrayFromString('/key')
|
|
190
222
|
* const value = uint8ArrayFromString('oh hello there')
|
|
191
223
|
*
|
|
192
|
-
* await contentRouting.put(key, value
|
|
224
|
+
* await contentRouting.put(key, value, {
|
|
225
|
+
* signal: AbortSignal.timeout(5_000)
|
|
226
|
+
* })
|
|
193
227
|
* ```
|
|
194
228
|
*/
|
|
195
|
-
put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
|
|
229
|
+
put?(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
|
|
196
230
|
/**
|
|
197
231
|
* Retrieves a value from the network corresponding to the passed key.
|
|
198
232
|
*
|
|
@@ -201,11 +235,13 @@ export interface Routing {
|
|
|
201
235
|
* ```js
|
|
202
236
|
* // ...
|
|
203
237
|
*
|
|
204
|
-
* const key = '/key'
|
|
205
|
-
* const value = await contentRouting.get(key
|
|
238
|
+
* const key = uint8ArrayFromString('/key')
|
|
239
|
+
* const value = await contentRouting.get(key, {
|
|
240
|
+
* signal: AbortSignal.timeout(5_000)
|
|
241
|
+
* })
|
|
206
242
|
* ```
|
|
207
243
|
*/
|
|
208
|
-
get(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
|
|
244
|
+
get?(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
|
|
209
245
|
/**
|
|
210
246
|
* Searches the network for peer info corresponding to the passed peer id.
|
|
211
247
|
*
|
|
@@ -213,10 +249,12 @@ export interface Routing {
|
|
|
213
249
|
*
|
|
214
250
|
* ```js
|
|
215
251
|
* // ...
|
|
216
|
-
* const peer = await peerRouting.findPeer(peerId,
|
|
252
|
+
* const peer = await peerRouting.findPeer(peerId, {
|
|
253
|
+
* signal: AbortSignal.timeout(5_000)
|
|
254
|
+
* })
|
|
217
255
|
* ```
|
|
218
256
|
*/
|
|
219
|
-
findPeer(
|
|
257
|
+
findPeer?(peer: CID, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<Peer>;
|
|
220
258
|
/**
|
|
221
259
|
* Search the network for peers that are closer to the passed key. Peer
|
|
222
260
|
* info should be yielded in ever-increasing closeness to the key.
|
|
@@ -225,11 +263,14 @@ export interface Routing {
|
|
|
225
263
|
*
|
|
226
264
|
* ```js
|
|
227
265
|
* // Iterate over the closest peers found for the given key
|
|
228
|
-
* for await (const peer of peerRouting.getClosestPeers(key
|
|
266
|
+
* for await (const peer of peerRouting.getClosestPeers(key, {
|
|
267
|
+
* signal: AbortSignal.timeout(5_000)
|
|
268
|
+
* })) {
|
|
229
269
|
* console.log(peer.id, peer.multiaddrs)
|
|
230
270
|
* }
|
|
231
271
|
* ```
|
|
232
272
|
*/
|
|
233
|
-
getClosestPeers(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<
|
|
273
|
+
getClosestPeers?(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<Peer>;
|
|
234
274
|
}
|
|
275
|
+
export type Routing = Required<Omit<Router, 'name'>>;
|
|
235
276
|
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,aAAa,GAAG,GAAG,CAAE,SAAQ,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC;IAC7G;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,EAAE,EAAE,GAAG,CAAA;IAEP;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,EAAE,EAAE,GAAG,CAAA;IAEP;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAA;IAEvB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IAEpB;;OAEG;IACH,OAAO,EAAE,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c,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE9F;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE5F;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,oCAAoC,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;CACvH;AAED,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/interface",
|
|
3
|
-
"version": "6.2.1-
|
|
3
|
+
"version": "6.2.1-9114743f",
|
|
4
4
|
"description": "The Helia API",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/interface#readme",
|
|
@@ -72,16 +72,21 @@
|
|
|
72
72
|
"build": "aegir build"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@
|
|
75
|
+
"@ipshipyard/crypto": "^1.1.0",
|
|
76
|
+
"@ipshipyard/keychain": "^1.0.2",
|
|
77
|
+
"@libp2p/interface": "^3.2.3",
|
|
76
78
|
"@multiformats/dns": "^1.0.13",
|
|
77
|
-
"@multiformats/multiaddr": "^13.0.
|
|
79
|
+
"@multiformats/multiaddr": "^13.0.3",
|
|
80
|
+
"abort-error": "^1.0.2",
|
|
81
|
+
"birnam": "^1.0.0",
|
|
78
82
|
"interface-blockstore": "^7.0.1",
|
|
79
83
|
"interface-datastore": "^10.0.1",
|
|
84
|
+
"main-event": "^1.0.4",
|
|
80
85
|
"multiformats": "^14.0.0",
|
|
81
86
|
"progress-events": "^1.1.0"
|
|
82
87
|
},
|
|
83
88
|
"devDependencies": {
|
|
84
|
-
"aegir": "^48.0.
|
|
89
|
+
"aegir": "^48.0.11"
|
|
85
90
|
},
|
|
86
91
|
"sideEffects": false
|
|
87
92
|
}
|
package/src/blocks.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RoutingFindProvidersProgressEvents } from './routing.ts'
|
|
2
|
-
import type { PeerId, AbortOptions } from '@libp2p/interface'
|
|
3
2
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
import type { AbortOptions } from 'abort-error'
|
|
4
4
|
import type { Blockstore } from 'interface-blockstore'
|
|
5
5
|
import type { CID } from 'multiformats/cid'
|
|
6
6
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
@@ -16,7 +16,7 @@ export interface ProviderOptions {
|
|
|
16
16
|
* child blocks, a `findProviders` routing query will be run to find peers
|
|
17
17
|
* that can supply the blocks.
|
|
18
18
|
*/
|
|
19
|
-
providers?: Array<
|
|
19
|
+
providers?: Array<CID | Multiaddr | Multiaddr[]>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -25,7 +25,7 @@ export interface ProviderOptions {
|
|
|
25
25
|
export interface BlockBrokerConnectProgressEvent {
|
|
26
26
|
broker: string
|
|
27
27
|
type: 'connect'
|
|
28
|
-
provider:
|
|
28
|
+
provider: CID
|
|
29
29
|
cid: CID
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -35,7 +35,7 @@ export interface BlockBrokerConnectProgressEvent {
|
|
|
35
35
|
export interface BlockBrokerConnectedProgressEvent {
|
|
36
36
|
broker: string
|
|
37
37
|
type: 'connected'
|
|
38
|
-
provider:
|
|
38
|
+
provider: CID
|
|
39
39
|
address: Multiaddr
|
|
40
40
|
cid: CID
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ export interface BlockBrokerConnectedProgressEvent {
|
|
|
46
46
|
export interface BlockBrokerRequestBlockProgressEvent {
|
|
47
47
|
broker: string
|
|
48
48
|
type: 'request-block'
|
|
49
|
-
provider:
|
|
49
|
+
provider: CID
|
|
50
50
|
cid: CID
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -56,7 +56,7 @@ export interface BlockBrokerRequestBlockProgressEvent {
|
|
|
56
56
|
export interface BlockBrokerReceiveBlockProgressEvent {
|
|
57
57
|
broker: string
|
|
58
58
|
type: 'receive-block'
|
|
59
|
-
provider:
|
|
59
|
+
provider: CID
|
|
60
60
|
cid: CID
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -150,7 +150,7 @@ ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProg
|
|
|
150
150
|
* Adds a new peer to the session if they are supported and are either
|
|
151
151
|
* not already in the session and have not been evicted previously.
|
|
152
152
|
*/
|
|
153
|
-
addPeer (peer:
|
|
153
|
+
addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
export interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {
|
|
@@ -232,7 +232,7 @@ export interface SessionBlockBroker<RetrieveProgressEvents extends ProgressEvent
|
|
|
232
232
|
* Adds a new peer to the session if they are supported and are either
|
|
233
233
|
* not already in the session and have not been evicted previously.
|
|
234
234
|
*/
|
|
235
|
-
addPeer (peer:
|
|
235
|
+
addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export const DEFAULT_SESSION_MIN_PROVIDERS = 1
|
package/src/errors.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CodecLoader } from './index.js'
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
3
|
+
import type { Blockstore } from 'interface-blockstore'
|
|
4
|
+
import type { BlockView, CID, Version } from 'multiformats'
|
|
5
|
+
|
|
6
|
+
export interface GraphWalkerComponents {
|
|
7
|
+
blockstore: Blockstore
|
|
8
|
+
getCodec: CodecLoader
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface GraphWalkerInit {}
|
|
12
|
+
|
|
13
|
+
export interface GraphNode<
|
|
14
|
+
T = unknown,
|
|
15
|
+
C extends number = number,
|
|
16
|
+
A extends number = number,
|
|
17
|
+
V extends Version = 0 | 1
|
|
18
|
+
> {
|
|
19
|
+
block: BlockView<T, C, A, V>
|
|
20
|
+
depth: number
|
|
21
|
+
path: CID[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface WalkOptions<T> extends AbortOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Stop traversal once `node.depth` reaches this value. The root is
|
|
27
|
+
* depth 0. Default: Infinity (walk the entire DAG).
|
|
28
|
+
*/
|
|
29
|
+
depth?: number
|
|
30
|
+
|
|
31
|
+
includeChild?(child: CID, parent: BlockView<T, number, number, 0 | 1>): boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface GraphWalker {
|
|
35
|
+
walk<T = any>(cid: CID, options?: WalkOptions<T>): AsyncGenerator<GraphNode<T>>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GraphWalkerFactory = (components: GraphWalkerComponents) => GraphWalker
|
package/src/index.ts
CHANGED
|
@@ -14,32 +14,50 @@
|
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import type { Blocks } from './blocks.ts'
|
|
17
|
+
import type { BlockBroker, Blocks } from './blocks.ts'
|
|
18
18
|
import type { Pins } from './pins.ts'
|
|
19
|
-
import type { Routing } from './routing.ts'
|
|
20
|
-
import type {
|
|
19
|
+
import type { Router, Routing } from './routing.ts'
|
|
20
|
+
import type { CryptoLoader, Keychain } from '@ipshipyard/keychain'
|
|
21
|
+
import type { Metrics } from '@libp2p/interface'
|
|
21
22
|
import type { DNS } from '@multiformats/dns'
|
|
23
|
+
import type { AbortOptions } from 'abort-error'
|
|
24
|
+
import type { ComponentLogger } from 'birnam'
|
|
22
25
|
import type { Datastore } from 'interface-datastore'
|
|
26
|
+
import type { TypedEventEmitter } from 'main-event'
|
|
23
27
|
import type { BlockCodec, MultihashHasher } from 'multiformats'
|
|
24
28
|
import type { CID } from 'multiformats/cid'
|
|
25
29
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
26
30
|
|
|
27
31
|
export interface CodecLoader {
|
|
28
|
-
<T = any, Code extends number = any>(code: Code): BlockCodec<Code, T> | Promise<BlockCodec<Code, T>>
|
|
32
|
+
<T = any, Code extends number = any>(code: Code, options?: AbortOptions): BlockCodec<Code, T> | Promise<BlockCodec<Code, T>>
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export interface HasherLoader {
|
|
32
|
-
(code: number): MultihashHasher | Promise<MultihashHasher>
|
|
36
|
+
(code: number, options?: AbortOptions): MultihashHasher | Promise<MultihashHasher>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type { CryptoLoader, Keychain } from '@ipshipyard/keychain'
|
|
40
|
+
export type { Crypto, PrivateKey, PublicKey } from '@ipshipyard/crypto'
|
|
41
|
+
export { isPrivateKey, isPublicKey } from '@ipshipyard/crypto'
|
|
42
|
+
|
|
43
|
+
export interface NodeInfo {
|
|
44
|
+
name: string
|
|
45
|
+
version: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface HeliaMixin<Start extends Helia = Helia, Stop = Start> {
|
|
49
|
+
start?(helia: Start): Promise<void> | void
|
|
50
|
+
stop?(helia: Stop): Promise<void> | void
|
|
33
51
|
}
|
|
34
52
|
|
|
35
53
|
/**
|
|
36
54
|
* The API presented by a Helia node
|
|
37
55
|
*/
|
|
38
|
-
export interface Helia
|
|
56
|
+
export interface Helia {
|
|
39
57
|
/**
|
|
40
|
-
*
|
|
58
|
+
* Runtime information about the node
|
|
41
59
|
*/
|
|
42
|
-
|
|
60
|
+
info: NodeInfo
|
|
43
61
|
|
|
44
62
|
/**
|
|
45
63
|
* Where the blocks are stored
|
|
@@ -54,7 +72,12 @@ export interface Helia<T extends Libp2p = Libp2p> {
|
|
|
54
72
|
/**
|
|
55
73
|
* Event emitter for Helia start and stop events
|
|
56
74
|
*/
|
|
57
|
-
events: TypedEventEmitter<HeliaEvents<
|
|
75
|
+
events: TypedEventEmitter<HeliaEvents<this>>
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Secure storage for private keys
|
|
79
|
+
*/
|
|
80
|
+
keychain: Keychain
|
|
58
81
|
|
|
59
82
|
/**
|
|
60
83
|
* Pinning operations for blocks in the blockstore
|
|
@@ -84,15 +107,20 @@ export interface Helia<T extends Libp2p = Libp2p> {
|
|
|
84
107
|
*/
|
|
85
108
|
metrics?: Metrics
|
|
86
109
|
|
|
110
|
+
/**
|
|
111
|
+
* The current status of the Helia node
|
|
112
|
+
*/
|
|
113
|
+
status: 'starting' | 'started' | 'stopping' | 'stopped'
|
|
114
|
+
|
|
87
115
|
/**
|
|
88
116
|
* Starts the Helia node
|
|
89
117
|
*/
|
|
90
|
-
start(): Promise<
|
|
118
|
+
start(options?: AbortOptions): Promise<this>
|
|
91
119
|
|
|
92
120
|
/**
|
|
93
121
|
* Stops the Helia node
|
|
94
122
|
*/
|
|
95
|
-
stop(): Promise<
|
|
123
|
+
stop(options?: AbortOptions): Promise<this>
|
|
96
124
|
|
|
97
125
|
/**
|
|
98
126
|
* Remove any unpinned blocks from the blockstore
|
|
@@ -111,6 +139,36 @@ export interface Helia<T extends Libp2p = Libp2p> {
|
|
|
111
139
|
* the hasher is being fetched from the network.
|
|
112
140
|
*/
|
|
113
141
|
getHasher: HasherLoader
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Cryptography implementations securely sign and verify data
|
|
145
|
+
*/
|
|
146
|
+
getCrypto: CryptoLoader
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns `true` if a router with the passed name has been configured
|
|
150
|
+
*/
|
|
151
|
+
hasRouter (name: string): boolean
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Add a router
|
|
155
|
+
*/
|
|
156
|
+
addRouter(router: Router): void
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns `true` if a block broker with the passed name has been configured
|
|
160
|
+
*/
|
|
161
|
+
hasBlockBroker (name: string): boolean
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Add a block broker
|
|
165
|
+
*/
|
|
166
|
+
addBlockBroker(blockBroker: BlockBroker): void
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Add a mixin to extend runtime functionality
|
|
170
|
+
*/
|
|
171
|
+
addMixin<T extends Helia = Helia & Record<string, any>>(mixin: HeliaMixin<T>): void
|
|
114
172
|
}
|
|
115
173
|
|
|
116
174
|
export type GcEvents =
|
|
@@ -121,7 +179,7 @@ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
|
|
|
121
179
|
|
|
122
180
|
}
|
|
123
181
|
|
|
124
|
-
export interface HeliaEvents<
|
|
182
|
+
export interface HeliaEvents<H extends Helia = Helia> {
|
|
125
183
|
/**
|
|
126
184
|
* This event notifies listeners that the node has started
|
|
127
185
|
*
|
|
@@ -131,7 +189,7 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
|
|
|
131
189
|
* })
|
|
132
190
|
* ```
|
|
133
191
|
*/
|
|
134
|
-
start: CustomEvent<
|
|
192
|
+
start: CustomEvent<H>
|
|
135
193
|
|
|
136
194
|
/**
|
|
137
195
|
* This event notifies listeners that the node has stopped
|
|
@@ -142,10 +200,11 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
|
|
|
142
200
|
* })
|
|
143
201
|
* ```
|
|
144
202
|
*/
|
|
145
|
-
stop: CustomEvent<
|
|
203
|
+
stop: CustomEvent<H>
|
|
146
204
|
}
|
|
147
205
|
|
|
148
206
|
export * from './blocks.ts'
|
|
149
207
|
export * from './errors.ts'
|
|
208
|
+
export * from './graph-walker.ts'
|
|
150
209
|
export * from './pins.ts'
|
|
151
210
|
export * from './routing.ts'
|
package/src/pins.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GetBlockProgressEvents } from './blocks.ts'
|
|
2
|
-
import type {
|
|
2
|
+
import type { GraphWalkerFactory } from './graph-walker.ts'
|
|
3
|
+
import type { AbortOptions } from 'abort-error'
|
|
3
4
|
import type { CID } from 'multiformats/cid'
|
|
4
5
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
5
6
|
|
|
@@ -20,6 +21,11 @@ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents |
|
|
|
20
21
|
*/
|
|
21
22
|
depth?: number
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
|
|
26
|
+
*/
|
|
27
|
+
walker?: GraphWalkerFactory
|
|
28
|
+
|
|
23
29
|
/**
|
|
24
30
|
* Optional user-defined metadata to store with the pin
|
|
25
31
|
*/
|
|
@@ -27,7 +33,10 @@ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents |
|
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export interface RmOptions extends AbortOptions {
|
|
30
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
|
|
38
|
+
*/
|
|
39
|
+
walker?: GraphWalkerFactory
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
export interface LsOptions extends AbortOptions {
|