@helia/utils 1.3.2-7a52e951 → 1.3.2-a0266903
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 +1 -15
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +33 -19
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -17
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -2
- package/src/index.ts +41 -21
package/dist/src/index.d.ts
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* In general you should use the `helia` or `@helia/http` modules instead which
|
|
7
|
-
* pre-configure Helia for certain use-cases (p2p or pure-HTTP).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { Helia } from '@helia/utils'
|
|
13
|
-
* import type { HeliaInit } from '@helia/utils'
|
|
14
|
-
*
|
|
15
|
-
* const node = new Helia({
|
|
16
|
-
* // ...options
|
|
17
|
-
* } as HeliaInit)
|
|
18
|
-
* ```
|
|
4
|
+
* This module contains utility code that is shared between various Helia
|
|
5
|
+
* modules such as `helia`, `@helia/http`, etc.
|
|
19
6
|
*/
|
|
20
7
|
import { BlockStorage } from './storage.js';
|
|
21
8
|
import type { BlockStorageInit } from './storage.js';
|
|
22
9
|
import type { Await, CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, Routing } from '@helia/interface';
|
|
23
10
|
import type { BlockBroker } from '@helia/interface/blocks';
|
|
24
11
|
import type { Pins } from '@helia/interface/pins';
|
|
25
|
-
import type { ComponentLogger, Metrics } from '@libp2p/interface';
|
|
12
|
+
import type { ComponentLogger, Libp2p, Metrics } from '@libp2p/interface';
|
|
13
|
+
import type { KeychainInit } from '@libp2p/keychain';
|
|
26
14
|
import type { DNS } from '@multiformats/dns';
|
|
27
15
|
import type { Blockstore } from 'interface-blockstore';
|
|
28
16
|
import type { Datastore } from 'interface-datastore';
|
|
17
|
+
import type { Libp2pOptions } from 'libp2p';
|
|
29
18
|
import type { BlockCodec } from 'multiformats';
|
|
30
19
|
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
31
20
|
export { AbstractSession } from './abstract-session.js';
|
|
@@ -34,7 +23,29 @@ export type { BlockStorage, BlockStorageInit };
|
|
|
34
23
|
/**
|
|
35
24
|
* Options used to create a Helia node.
|
|
36
25
|
*/
|
|
37
|
-
export interface HeliaInit {
|
|
26
|
+
export interface HeliaInit<T extends Libp2p = Libp2p> {
|
|
27
|
+
/**
|
|
28
|
+
* A libp2p node is required to perform network operations. Either a
|
|
29
|
+
* pre-configured node or options to configure a node can be passed
|
|
30
|
+
* here.
|
|
31
|
+
*
|
|
32
|
+
* If node options are passed, they will be merged with the default
|
|
33
|
+
* config for the current platform. In this case all passed config
|
|
34
|
+
* keys will replace those from the default config.
|
|
35
|
+
*
|
|
36
|
+
* The libp2p `start` option is not supported, instead please pass `start` in
|
|
37
|
+
* the root of the HeliaInit object.
|
|
38
|
+
*/
|
|
39
|
+
libp2p: T | Omit<Libp2pOptions<any>, 'start'>;
|
|
40
|
+
/**
|
|
41
|
+
* Pass `false` to not start the Helia node
|
|
42
|
+
*/
|
|
43
|
+
start?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* By default Helia stores the node's PeerId in an encrypted form in a
|
|
46
|
+
* libp2p keystore. These options control how that keystore is configured.
|
|
47
|
+
*/
|
|
48
|
+
keychain?: KeychainInit;
|
|
38
49
|
/**
|
|
39
50
|
* The blockstore is where blocks are stored
|
|
40
51
|
*/
|
|
@@ -126,7 +137,8 @@ export interface HeliaInit {
|
|
|
126
137
|
*/
|
|
127
138
|
metrics?: Metrics;
|
|
128
139
|
}
|
|
129
|
-
export declare class Helia implements HeliaInterface {
|
|
140
|
+
export declare class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
141
|
+
libp2p: T;
|
|
130
142
|
blockstore: BlockStorage;
|
|
131
143
|
datastore: Datastore;
|
|
132
144
|
pins: Pins;
|
|
@@ -137,7 +149,9 @@ export declare class Helia implements HeliaInterface {
|
|
|
137
149
|
dns: DNS;
|
|
138
150
|
metrics?: Metrics;
|
|
139
151
|
private readonly log;
|
|
140
|
-
constructor(init: HeliaInit
|
|
152
|
+
constructor(init: Omit<HeliaInit, 'start' | 'libp2p'> & {
|
|
153
|
+
libp2p: T;
|
|
154
|
+
});
|
|
141
155
|
start(): Promise<void>;
|
|
142
156
|
stop(): Promise<void>;
|
|
143
157
|
gc(options?: GCOptions): Promise<void>;
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,IAAI,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAU,OAAO,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,C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
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* In general you should use the `helia` or `@helia/http` modules instead which
|
|
7
|
-
* pre-configure Helia for certain use-cases (p2p or pure-HTTP).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { Helia } from '@helia/utils'
|
|
13
|
-
* import type { HeliaInit } from '@helia/utils'
|
|
14
|
-
*
|
|
15
|
-
* const node = new Helia({
|
|
16
|
-
* // ...options
|
|
17
|
-
* } as HeliaInit)
|
|
18
|
-
* ```
|
|
4
|
+
* This module contains utility code that is shared between various Helia
|
|
5
|
+
* modules such as `helia`, `@helia/http`, etc.
|
|
19
6
|
*/
|
|
20
7
|
import { contentRoutingSymbol, peerRoutingSymbol, start, stop } from '@libp2p/interface';
|
|
21
8
|
import { defaultLogger } from '@libp2p/logger';
|
|
@@ -31,6 +18,7 @@ import { getHasher } from './utils/get-hasher.js';
|
|
|
31
18
|
import { NetworkedStorage } from './utils/networked-storage.js';
|
|
32
19
|
export { AbstractSession } from './abstract-session.js';
|
|
33
20
|
export class Helia {
|
|
21
|
+
libp2p;
|
|
34
22
|
blockstore;
|
|
35
23
|
datastore;
|
|
36
24
|
pins;
|
|
@@ -48,11 +36,13 @@ export class Helia {
|
|
|
48
36
|
this.getCodec = getCodec(init.codecs, init.loadCodec);
|
|
49
37
|
this.dns = init.dns ?? dns();
|
|
50
38
|
this.metrics = init.metrics;
|
|
39
|
+
this.libp2p = init.libp2p;
|
|
51
40
|
// @ts-expect-error routing is not set
|
|
52
41
|
const components = {
|
|
53
42
|
blockstore: init.blockstore,
|
|
54
43
|
datastore: init.datastore,
|
|
55
44
|
logger: this.logger,
|
|
45
|
+
libp2p: this.libp2p,
|
|
56
46
|
blockBrokers: [],
|
|
57
47
|
getHasher: this.getHasher,
|
|
58
48
|
getCodec: this.getCodec,
|
|
@@ -90,10 +80,10 @@ export class Helia {
|
|
|
90
80
|
}
|
|
91
81
|
async start() {
|
|
92
82
|
await assertDatastoreVersionIsCurrent(this.datastore);
|
|
93
|
-
await start(this.blockstore, this.datastore, this.routing);
|
|
83
|
+
await start(this.blockstore, this.datastore, this.routing, this.libp2p);
|
|
94
84
|
}
|
|
95
85
|
async stop() {
|
|
96
|
-
await stop(this.blockstore, this.datastore, this.routing);
|
|
86
|
+
await stop(this.blockstore, this.datastore, this.routing, this.libp2p);
|
|
97
87
|
}
|
|
98
88
|
async gc(options = {}) {
|
|
99
89
|
const releaseLock = await this.blockstore.lock.writeLock();
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AA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A;wBACvC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;gBACH,CAAC;YACH,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACR,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAA;QACf,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "1.3.2-
|
|
3
|
+
"version": "1.3.2-a0266903",
|
|
4
4
|
"description": "Shared code that implements the Helia API",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/utils#readme",
|
|
@@ -54,11 +54,12 @@
|
|
|
54
54
|
"test:electron-main": "aegir test -t electron-main"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@helia/interface": "5.3.2-
|
|
57
|
+
"@helia/interface": "5.3.2-a0266903",
|
|
58
58
|
"@ipld/dag-cbor": "^9.2.2",
|
|
59
59
|
"@ipld/dag-json": "^10.2.3",
|
|
60
60
|
"@ipld/dag-pb": "^4.1.3",
|
|
61
61
|
"@libp2p/interface": "^2.5.0",
|
|
62
|
+
"@libp2p/keychain": "^5.2.8",
|
|
62
63
|
"@libp2p/logger": "^5.1.8",
|
|
63
64
|
"@libp2p/utils": "^6.5.1",
|
|
64
65
|
"@multiformats/dns": "^1.0.6",
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
"it-filter": "^3.1.1",
|
|
74
75
|
"it-foreach": "^2.1.1",
|
|
75
76
|
"it-merge": "^3.0.5",
|
|
77
|
+
"libp2p": "^2.9.0",
|
|
76
78
|
"mortice": "^3.0.6",
|
|
77
79
|
"multiformats": "^13.3.1",
|
|
78
80
|
"p-defer": "^4.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* In general you should use the `helia` or `@helia/http` modules instead which
|
|
7
|
-
* pre-configure Helia for certain use-cases (p2p or pure-HTTP).
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
*
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { Helia } from '@helia/utils'
|
|
13
|
-
* import type { HeliaInit } from '@helia/utils'
|
|
14
|
-
*
|
|
15
|
-
* const node = new Helia({
|
|
16
|
-
* // ...options
|
|
17
|
-
* } as HeliaInit)
|
|
18
|
-
* ```
|
|
4
|
+
* This module contains utility code that is shared between various Helia
|
|
5
|
+
* modules such as `helia`, `@helia/http`, etc.
|
|
19
6
|
*/
|
|
20
7
|
|
|
21
8
|
import { contentRoutingSymbol, peerRoutingSymbol, start, stop } from '@libp2p/interface'
|
|
@@ -34,10 +21,12 @@ import type { BlockStorageInit } from './storage.js'
|
|
|
34
21
|
import type { Await, CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, Routing } from '@helia/interface'
|
|
35
22
|
import type { BlockBroker } from '@helia/interface/blocks'
|
|
36
23
|
import type { Pins } from '@helia/interface/pins'
|
|
37
|
-
import type { ComponentLogger, Logger, Metrics } from '@libp2p/interface'
|
|
24
|
+
import type { ComponentLogger, Libp2p, Logger, Metrics } from '@libp2p/interface'
|
|
25
|
+
import type { KeychainInit } from '@libp2p/keychain'
|
|
38
26
|
import type { DNS } from '@multiformats/dns'
|
|
39
27
|
import type { Blockstore } from 'interface-blockstore'
|
|
40
28
|
import type { Datastore } from 'interface-datastore'
|
|
29
|
+
import type { Libp2pOptions } from 'libp2p'
|
|
41
30
|
import type { BlockCodec } from 'multiformats'
|
|
42
31
|
import type { CID } from 'multiformats/cid'
|
|
43
32
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
@@ -50,7 +39,32 @@ export type { BlockStorage, BlockStorageInit }
|
|
|
50
39
|
/**
|
|
51
40
|
* Options used to create a Helia node.
|
|
52
41
|
*/
|
|
53
|
-
export interface HeliaInit {
|
|
42
|
+
export interface HeliaInit<T extends Libp2p = Libp2p> {
|
|
43
|
+
/**
|
|
44
|
+
* A libp2p node is required to perform network operations. Either a
|
|
45
|
+
* pre-configured node or options to configure a node can be passed
|
|
46
|
+
* here.
|
|
47
|
+
*
|
|
48
|
+
* If node options are passed, they will be merged with the default
|
|
49
|
+
* config for the current platform. In this case all passed config
|
|
50
|
+
* keys will replace those from the default config.
|
|
51
|
+
*
|
|
52
|
+
* The libp2p `start` option is not supported, instead please pass `start` in
|
|
53
|
+
* the root of the HeliaInit object.
|
|
54
|
+
*/
|
|
55
|
+
libp2p: T | Omit<Libp2pOptions<any>, 'start'>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Pass `false` to not start the Helia node
|
|
59
|
+
*/
|
|
60
|
+
start?: boolean
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* By default Helia stores the node's PeerId in an encrypted form in a
|
|
64
|
+
* libp2p keystore. These options control how that keystore is configured.
|
|
65
|
+
*/
|
|
66
|
+
keychain?: KeychainInit
|
|
67
|
+
|
|
54
68
|
/**
|
|
55
69
|
* The blockstore is where blocks are stored
|
|
56
70
|
*/
|
|
@@ -157,6 +171,7 @@ export interface HeliaInit {
|
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
interface Components {
|
|
174
|
+
libp2p: Libp2p
|
|
160
175
|
blockstore: Blockstore
|
|
161
176
|
datastore: Datastore
|
|
162
177
|
logger: ComponentLogger
|
|
@@ -168,7 +183,8 @@ interface Components {
|
|
|
168
183
|
getHasher: HasherLoader
|
|
169
184
|
}
|
|
170
185
|
|
|
171
|
-
export class Helia implements HeliaInterface {
|
|
186
|
+
export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
187
|
+
public libp2p: T
|
|
172
188
|
public blockstore: BlockStorage
|
|
173
189
|
public datastore: Datastore
|
|
174
190
|
public pins: Pins
|
|
@@ -180,19 +196,21 @@ export class Helia implements HeliaInterface {
|
|
|
180
196
|
public metrics?: Metrics
|
|
181
197
|
private readonly log: Logger
|
|
182
198
|
|
|
183
|
-
constructor (init: HeliaInit) {
|
|
199
|
+
constructor (init: Omit<HeliaInit, 'start' | 'libp2p'> & { libp2p: T }) {
|
|
184
200
|
this.logger = init.logger ?? defaultLogger()
|
|
185
201
|
this.log = this.logger.forComponent('helia')
|
|
186
202
|
this.getHasher = getHasher(init.hashers, init.loadHasher)
|
|
187
203
|
this.getCodec = getCodec(init.codecs, init.loadCodec)
|
|
188
204
|
this.dns = init.dns ?? dns()
|
|
189
205
|
this.metrics = init.metrics
|
|
206
|
+
this.libp2p = init.libp2p
|
|
190
207
|
|
|
191
208
|
// @ts-expect-error routing is not set
|
|
192
209
|
const components: Components = {
|
|
193
210
|
blockstore: init.blockstore,
|
|
194
211
|
datastore: init.datastore,
|
|
195
212
|
logger: this.logger,
|
|
213
|
+
libp2p: this.libp2p,
|
|
196
214
|
blockBrokers: [],
|
|
197
215
|
getHasher: this.getHasher,
|
|
198
216
|
getCodec: this.getCodec,
|
|
@@ -240,7 +258,8 @@ export class Helia implements HeliaInterface {
|
|
|
240
258
|
await start(
|
|
241
259
|
this.blockstore,
|
|
242
260
|
this.datastore,
|
|
243
|
-
this.routing
|
|
261
|
+
this.routing,
|
|
262
|
+
this.libp2p
|
|
244
263
|
)
|
|
245
264
|
}
|
|
246
265
|
|
|
@@ -248,7 +267,8 @@ export class Helia implements HeliaInterface {
|
|
|
248
267
|
await stop(
|
|
249
268
|
this.blockstore,
|
|
250
269
|
this.datastore,
|
|
251
|
-
this.routing
|
|
270
|
+
this.routing,
|
|
271
|
+
this.libp2p
|
|
252
272
|
)
|
|
253
273
|
}
|
|
254
274
|
|