@helia/interface 0.0.0-270bb98 → 0.0.0-42308c0

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.
@@ -0,0 +1,118 @@
1
+ import type { AbortOptions } from '@libp2p/interfaces';
2
+ import type { ProgressEvent, ProgressOptions } from 'progress-events';
3
+ import type { CID } from 'multiformats/cid';
4
+ import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap';
5
+ import type { AwaitIterable, Await } from './index.js';
6
+ import type { Blockstore } from 'interface-blockstore';
7
+ export interface Pair {
8
+ cid: CID;
9
+ block: Uint8Array;
10
+ }
11
+ export type PutBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:bitswap:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID> | BitswapNotifyProgressEvents;
12
+ export type PutManyBlocksProgressEvents = ProgressEvent<'blocks:put-many:duplicate', CID> | ProgressEvent<'blocks:put-many:bitswap:notify', CID> | ProgressEvent<'blocks:put-many:blockstore:put-many'> | BitswapNotifyProgressEvents;
13
+ export type GetBlockProgressEvents = ProgressEvent<'blocks:get:bitswap:want', CID> | ProgressEvent<'blocks:get:blockstore:get', CID> | ProgressEvent<'blocks:get:blockstore:put', CID> | BitswapWantProgressEvents;
14
+ export type GetManyBlocksProgressEvents = ProgressEvent<'blocks:get-many:blockstore:get-many'> | ProgressEvent<'blocks:get-many:bitswap:want', CID> | ProgressEvent<'blocks:get-many:blockstore:put', CID> | BitswapWantProgressEvents;
15
+ export type GetAllBlocksProgressEvents = ProgressEvent<'blocks:get-all:blockstore:get-many'>;
16
+ export type DeleteBlockProgressEvents = ProgressEvent<'blocks:delete:blockstore:delete', CID>;
17
+ export type DeleteManyBlocksProgressEvents = ProgressEvent<'blocks:delete-many:blockstore:delete-many'>;
18
+ export interface Blocks extends Blockstore {
19
+ /**
20
+ * Check for the existence of a value for the passed key
21
+ *
22
+ * @example
23
+ * ```js
24
+ * const exists = await store.has(CID('bafyfoo'))
25
+ *
26
+ * if (exists) {
27
+ * console.log('it is there')
28
+ * } else {
29
+ * console.log('it is not there')
30
+ * }
31
+ *```
32
+ */
33
+ has: (key: CID, options?: AbortOptions) => Await<boolean>;
34
+ /**
35
+ * Store the passed block under the passed CID
36
+ *
37
+ * @example
38
+ *
39
+ * ```js
40
+ * await store.put(CID('bafyfoo'), new Uint8Array([0, 1, 2, 3]))
41
+ * ```
42
+ */
43
+ put: (key: CID, val: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>) => Await<void>;
44
+ /**
45
+ * Store the given key/value pairs
46
+ *
47
+ * @example
48
+ * ```js
49
+ * const source = [{ cid: CID('bafyfoo'), block: new Uint8Array([0, 1, 2, 3]) }]
50
+ *
51
+ * for await (const { key, value } of store.putMany(source)) {
52
+ * console.info(`put content for key ${key}`)
53
+ * }
54
+ * ```
55
+ */
56
+ putMany: (source: AwaitIterable<Pair>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>) => AwaitIterable<Pair>;
57
+ /**
58
+ * Retrieve the value stored under the given key
59
+ *
60
+ * @example
61
+ * ```js
62
+ * const value = await store.get(CID('bafyfoo'))
63
+ * console.log('got content: %s', value.toString('utf8'))
64
+ * // => got content: datastore
65
+ * ```
66
+ */
67
+ get: (key: CID, options?: AbortOptions & ProgressOptions<GetBlockProgressEvents>) => Await<Uint8Array>;
68
+ /**
69
+ * Retrieve values for the passed keys
70
+ *
71
+ * @example
72
+ * ```js
73
+ * for await (const value of store.getMany([CID('bafyfoo')])) {
74
+ * console.log('got content:', new TextDecoder('utf8').decode(value))
75
+ * // => got content: datastore
76
+ * }
77
+ * ```
78
+ */
79
+ getMany: (source: AwaitIterable<CID>, options?: AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>) => AwaitIterable<Uint8Array>;
80
+ /**
81
+ * Retrieve all blocks in the blockstore
82
+ *
83
+ * @example
84
+ * ```js
85
+ * for await (const value of store.getAll()) {
86
+ * console.log('got content:', new TextDecoder('utf8').decode(value))
87
+ * // => got content: datastore
88
+ * }
89
+ * ```
90
+ */
91
+ getAll: (options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>) => AwaitIterable<Pair>;
92
+ /**
93
+ * Remove the record for the passed key
94
+ *
95
+ * @example
96
+ *
97
+ * ```js
98
+ * await store.delete(CID('bafyfoo'))
99
+ * console.log('deleted awesome content :(')
100
+ * ```
101
+ */
102
+ delete: (key: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>) => Await<void>;
103
+ /**
104
+ * Remove values for the passed keys
105
+ *
106
+ * @example
107
+ *
108
+ * ```js
109
+ * const source = [CID('bafyfoo')]
110
+ *
111
+ * for await (const key of store.deleteMany(source)) {
112
+ * console.log(`deleted content with key ${key}`)
113
+ * }
114
+ * ```
115
+ */
116
+ deleteMany: (source: AwaitIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>) => AwaitIterable<CID>;
117
+ }
118
+ //# sourceMappingURL=blocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,MAAM,sBAAsB,GACh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I,CAAC,CAAA;IAEjH;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,CACP,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,EAC3B,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAC,KAClE,aAAa,CAAC,IAAI,CAAC,CAAA;IAExB;;;;;;;;;OASG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,sBAAsB,CAAC,KAAK,KAAK,CAAC,UAAU,CAAC,CAAA;IAEtG;;;;;;;;;;OAUG;IACH,OAAO,EAAE,CACP,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAC,KAClE,aAAa,CAAC,UAAU,CAAC,CAAA;IAE9B;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CACN,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,0BAA0B,CAAC,KACjE,aAAa,CAAC,IAAI,CAAC,CAAA;IAExB;;;;;;;;;OASG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,yBAAyB,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAA;IAEtG;;;;;;;;;;;;OAYG;IACH,UAAU,EAAE,CACV,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,8BAA8B,CAAC,KACrE,aAAa,CAAC,GAAG,CAAC,CAAA;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":""}
@@ -14,14 +14,14 @@
14
14
  * ```
15
15
  */
16
16
  import type { Libp2p } from '@libp2p/interface-libp2p';
17
- import type { Blockstore } from 'interface-blockstore';
18
17
  import type { AbortOptions } from '@libp2p/interfaces';
19
18
  import type { PeerId } from '@libp2p/interface-peer-id';
20
- import type { Multiaddr } from '@multiformats/multiaddr';
21
19
  import type { Datastore } from 'interface-datastore';
22
20
  import type { Pins } from './pins.js';
23
21
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
24
22
  import type { CID } from 'multiformats/cid';
23
+ import type { Blocks } from './blocks.js';
24
+ export type { Await, AwaitIterable } from 'interface-store';
25
25
  /**
26
26
  * The API presented by a Helia node.
27
27
  */
@@ -33,7 +33,7 @@ export interface Helia {
33
33
  /**
34
34
  * Where the blocks are stored
35
35
  */
36
- blockstore: Blockstore;
36
+ blockstore: Blocks;
37
37
  /**
38
38
  * A key/value store
39
39
  */
@@ -42,21 +42,6 @@ export interface Helia {
42
42
  * Pinning operations for blocks in the blockstore
43
43
  */
44
44
  pins: Pins;
45
- /**
46
- * Returns information about this node
47
- *
48
- * @example
49
- *
50
- * ```typescript
51
- * import { createHelia } from 'helia'
52
- *
53
- * const node = await createHelia()
54
- * const id = await node.info()
55
- * console.info(id)
56
- * // { peerId: PeerId(12D3Foo), ... }
57
- * ```
58
- */
59
- info: (options?: InfoOptions) => Promise<InfoResponse>;
60
45
  /**
61
46
  * Starts the Helia node
62
47
  */
@@ -70,7 +55,7 @@ export interface Helia {
70
55
  */
71
56
  gc: (options?: GCOptions) => Promise<void>;
72
57
  }
73
- export type GcEvents = ProgressEvent<'helia:gc:deleted', CID>;
58
+ export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
74
59
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
75
60
  }
76
61
  export interface InfoOptions extends AbortOptions {
@@ -80,30 +65,4 @@ export interface InfoOptions extends AbortOptions {
80
65
  */
81
66
  peerId?: PeerId;
82
67
  }
83
- export interface InfoResponse {
84
- /**
85
- * The ID of the peer this info is about
86
- */
87
- peerId: PeerId;
88
- /**
89
- * The multiaddrs the peer is listening on
90
- */
91
- multiaddrs: Multiaddr[];
92
- /**
93
- * The peer's reported agent version
94
- */
95
- agentVersion: string;
96
- /**
97
- * The peer's reported protocol version
98
- */
99
- protocolVersion: string;
100
- /**
101
- * The protocols the peer supports
102
- */
103
- protocols: string[];
104
- /**
105
- * The status of the node
106
- */
107
- status: 'running' | 'stopped';
108
- }
109
68
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,EAAE,UAAU,CAAA;IAEtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IAEV;;;;;;;;;;;;;OAaG;IACH,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;I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,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IAEV;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE1B;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzB;;OAEG;IACH,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3C;AAED,MAAM,MAAM,QAAQ,GAClB,aAAa,CAAC,kBAAkB,EAAE,GAAG,CAAC,GACtC,aAAa,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;AAExC,MAAM,WAAW,SAAU,SAAQ,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC;CAEzE;AAED,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "0.0.0-270bb98",
3
+ "version": "0.0.0-42308c0",
4
4
  "description": "The Helia API",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/master/packages/interface#readme",
@@ -47,6 +47,10 @@
47
47
  "types": "./dist/src/index.d.ts",
48
48
  "import": "./dist/src/index.js"
49
49
  },
50
+ "./blocks": {
51
+ "types": "./dist/src/blocks.d.ts",
52
+ "import": "./dist/src/blocks.js"
53
+ },
50
54
  "./pins": {
51
55
  "types": "./dist/src/pins.d.ts",
52
56
  "import": "./dist/src/pins.js"
@@ -154,9 +158,10 @@
154
158
  "@libp2p/interface-libp2p": "^1.1.0",
155
159
  "@libp2p/interface-peer-id": "^2.0.1",
156
160
  "@libp2p/interfaces": "^3.3.1",
157
- "@multiformats/multiaddr": "^11.1.5",
158
- "interface-blockstore": "^4.0.1",
159
- "interface-datastore": "^7.0.3",
161
+ "interface-blockstore": "^5.0.0",
162
+ "interface-datastore": "^8.0.0",
163
+ "interface-store": "^4.0.0",
164
+ "ipfs-bitswap": "^17.0.0",
160
165
  "multiformats": "^11.0.1",
161
166
  "progress-events": "^1.0.0"
162
167
  },
package/src/blocks.ts ADDED
@@ -0,0 +1,163 @@
1
+ import type { AbortOptions } from '@libp2p/interfaces'
2
+ import type { ProgressEvent, ProgressOptions } from 'progress-events'
3
+ import type { CID } from 'multiformats/cid'
4
+ import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap'
5
+ import type { AwaitIterable, Await } from './index.js'
6
+ import type { Blockstore } from 'interface-blockstore'
7
+
8
+ export interface Pair {
9
+ cid: CID
10
+ block: Uint8Array
11
+ }
12
+
13
+ export type PutBlockProgressEvents =
14
+ ProgressEvent<'blocks:put:duplicate', CID> |
15
+ ProgressEvent<'blocks:put:bitswap:notify', CID> |
16
+ ProgressEvent<'blocks:put:blockstore:put', CID> |
17
+ BitswapNotifyProgressEvents
18
+
19
+ export type PutManyBlocksProgressEvents =
20
+ ProgressEvent<'blocks:put-many:duplicate', CID> |
21
+ ProgressEvent<'blocks:put-many:bitswap:notify', CID> |
22
+ ProgressEvent<'blocks:put-many:blockstore:put-many'> |
23
+ BitswapNotifyProgressEvents
24
+
25
+ export type GetBlockProgressEvents =
26
+ ProgressEvent<'blocks:get:bitswap:want', CID> |
27
+ ProgressEvent<'blocks:get:blockstore:get', CID> |
28
+ ProgressEvent<'blocks:get:blockstore:put', CID> |
29
+ BitswapWantProgressEvents
30
+
31
+ export type GetManyBlocksProgressEvents =
32
+ ProgressEvent<'blocks:get-many:blockstore:get-many'> |
33
+ ProgressEvent<'blocks:get-many:bitswap:want', CID> |
34
+ ProgressEvent<'blocks:get-many:blockstore:put', CID> |
35
+ BitswapWantProgressEvents
36
+
37
+ export type GetAllBlocksProgressEvents =
38
+ ProgressEvent<'blocks:get-all:blockstore:get-many'>
39
+
40
+ export type DeleteBlockProgressEvents =
41
+ ProgressEvent<'blocks:delete:blockstore:delete', CID>
42
+
43
+ export type DeleteManyBlocksProgressEvents =
44
+ ProgressEvent<'blocks:delete-many:blockstore:delete-many'>
45
+
46
+ export interface Blocks extends Blockstore {
47
+ /**
48
+ * Check for the existence of a value for the passed key
49
+ *
50
+ * @example
51
+ * ```js
52
+ * const exists = await store.has(CID('bafyfoo'))
53
+ *
54
+ * if (exists) {
55
+ * console.log('it is there')
56
+ * } else {
57
+ * console.log('it is not there')
58
+ * }
59
+ *```
60
+ */
61
+ has: (key: CID, options?: AbortOptions) => Await<boolean>
62
+
63
+ /**
64
+ * Store the passed block under the passed CID
65
+ *
66
+ * @example
67
+ *
68
+ * ```js
69
+ * await store.put(CID('bafyfoo'), new Uint8Array([0, 1, 2, 3]))
70
+ * ```
71
+ */
72
+ put: (key: CID, val: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>) => Await<void>
73
+
74
+ /**
75
+ * Store the given key/value pairs
76
+ *
77
+ * @example
78
+ * ```js
79
+ * const source = [{ cid: CID('bafyfoo'), block: new Uint8Array([0, 1, 2, 3]) }]
80
+ *
81
+ * for await (const { key, value } of store.putMany(source)) {
82
+ * console.info(`put content for key ${key}`)
83
+ * }
84
+ * ```
85
+ */
86
+ putMany: (
87
+ source: AwaitIterable<Pair>,
88
+ options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>
89
+ ) => AwaitIterable<Pair>
90
+
91
+ /**
92
+ * Retrieve the value stored under the given key
93
+ *
94
+ * @example
95
+ * ```js
96
+ * const value = await store.get(CID('bafyfoo'))
97
+ * console.log('got content: %s', value.toString('utf8'))
98
+ * // => got content: datastore
99
+ * ```
100
+ */
101
+ get: (key: CID, options?: AbortOptions & ProgressOptions<GetBlockProgressEvents>) => Await<Uint8Array>
102
+
103
+ /**
104
+ * Retrieve values for the passed keys
105
+ *
106
+ * @example
107
+ * ```js
108
+ * for await (const value of store.getMany([CID('bafyfoo')])) {
109
+ * console.log('got content:', new TextDecoder('utf8').decode(value))
110
+ * // => got content: datastore
111
+ * }
112
+ * ```
113
+ */
114
+ getMany: (
115
+ source: AwaitIterable<CID>,
116
+ options?: AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>
117
+ ) => AwaitIterable<Uint8Array>
118
+
119
+ /**
120
+ * Retrieve all blocks in the blockstore
121
+ *
122
+ * @example
123
+ * ```js
124
+ * for await (const value of store.getAll()) {
125
+ * console.log('got content:', new TextDecoder('utf8').decode(value))
126
+ * // => got content: datastore
127
+ * }
128
+ * ```
129
+ */
130
+ getAll: (
131
+ options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>
132
+ ) => AwaitIterable<Pair>
133
+
134
+ /**
135
+ * Remove the record for the passed key
136
+ *
137
+ * @example
138
+ *
139
+ * ```js
140
+ * await store.delete(CID('bafyfoo'))
141
+ * console.log('deleted awesome content :(')
142
+ * ```
143
+ */
144
+ delete: (key: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>) => Await<void>
145
+
146
+ /**
147
+ * Remove values for the passed keys
148
+ *
149
+ * @example
150
+ *
151
+ * ```js
152
+ * const source = [CID('bafyfoo')]
153
+ *
154
+ * for await (const key of store.deleteMany(source)) {
155
+ * console.log(`deleted content with key ${key}`)
156
+ * }
157
+ * ```
158
+ */
159
+ deleteMany: (
160
+ source: AwaitIterable<CID>,
161
+ options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>
162
+ ) => AwaitIterable<CID>
163
+ }
package/src/index.ts CHANGED
@@ -15,14 +15,15 @@
15
15
  */
16
16
 
17
17
  import type { Libp2p } from '@libp2p/interface-libp2p'
18
- import type { Blockstore } from 'interface-blockstore'
19
18
  import type { AbortOptions } from '@libp2p/interfaces'
20
19
  import type { PeerId } from '@libp2p/interface-peer-id'
21
- import type { Multiaddr } from '@multiformats/multiaddr'
22
20
  import type { Datastore } from 'interface-datastore'
23
21
  import type { Pins } from './pins.js'
24
22
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
25
23
  import type { CID } from 'multiformats/cid'
24
+ import type { Blocks } from './blocks.js'
25
+
26
+ export type { Await, AwaitIterable } from 'interface-store'
26
27
 
27
28
  /**
28
29
  * The API presented by a Helia node.
@@ -36,7 +37,7 @@ export interface Helia {
36
37
  /**
37
38
  * Where the blocks are stored
38
39
  */
39
- blockstore: Blockstore
40
+ blockstore: Blocks
40
41
 
41
42
  /**
42
43
  * A key/value store
@@ -48,22 +49,6 @@ export interface Helia {
48
49
  */
49
50
  pins: Pins
50
51
 
51
- /**
52
- * Returns information about this node
53
- *
54
- * @example
55
- *
56
- * ```typescript
57
- * import { createHelia } from 'helia'
58
- *
59
- * const node = await createHelia()
60
- * const id = await node.info()
61
- * console.info(id)
62
- * // { peerId: PeerId(12D3Foo), ... }
63
- * ```
64
- */
65
- info: (options?: InfoOptions) => Promise<InfoResponse>
66
-
67
52
  /**
68
53
  * Starts the Helia node
69
54
  */
@@ -81,7 +66,8 @@ export interface Helia {
81
66
  }
82
67
 
83
68
  export type GcEvents =
84
- ProgressEvent<'helia:gc:deleted', CID>
69
+ ProgressEvent<'helia:gc:deleted', CID> |
70
+ ProgressEvent<'helia:gc:error', Error>
85
71
 
86
72
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
87
73
 
@@ -94,35 +80,3 @@ export interface InfoOptions extends AbortOptions {
94
80
  */
95
81
  peerId?: PeerId
96
82
  }
97
-
98
- export interface InfoResponse {
99
- /**
100
- * The ID of the peer this info is about
101
- */
102
- peerId: PeerId
103
-
104
- /**
105
- * The multiaddrs the peer is listening on
106
- */
107
- multiaddrs: Multiaddr[]
108
-
109
- /**
110
- * The peer's reported agent version
111
- */
112
- agentVersion: string
113
-
114
- /**
115
- * The peer's reported protocol version
116
- */
117
- protocolVersion: string
118
-
119
- /**
120
- * The protocols the peer supports
121
- */
122
- protocols: string[]
123
-
124
- /**
125
- * The status of the node
126
- */
127
- status: 'running' | 'stopped'
128
- }