@helia/interface 0.0.0 → 1.1.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 CHANGED
@@ -1,9 +1,15 @@
1
+ <p align="center">
2
+ <a href="https://github.com/ipfs/helia" title="Helia">
3
+ <img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" />
4
+ </a>
5
+ </p>
6
+
1
7
  # @helia/interface <!-- omit in toc -->
2
8
 
3
9
  [![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
4
10
  [![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
5
11
  [![codecov](https://img.shields.io/codecov/c/github/ipfs/helia.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia)
6
- [![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
12
+ [![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia/main.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia/actions/workflows/main.yml?query=branch%3Amain)
7
13
 
8
14
  > The Helia API
9
15
 
@@ -0,0 +1,19 @@
1
+ import type { Blockstore } from 'interface-blockstore';
2
+ import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap';
3
+ import type { CID } from 'multiformats/cid';
4
+ import type { ProgressEvent, ProgressOptions } from 'progress-events';
5
+ export interface Pair {
6
+ cid: CID;
7
+ block: Uint8Array;
8
+ }
9
+ export type HasBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:bitswap:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID> | BitswapNotifyProgressEvents;
10
+ export type PutBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:bitswap:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID> | BitswapNotifyProgressEvents;
11
+ export type PutManyBlocksProgressEvents = ProgressEvent<'blocks:put-many:duplicate', CID> | ProgressEvent<'blocks:put-many:bitswap:notify', CID> | ProgressEvent<'blocks:put-many:blockstore:put-many'> | BitswapNotifyProgressEvents;
12
+ export type GetBlockProgressEvents = ProgressEvent<'blocks:get:bitswap:want', CID> | ProgressEvent<'blocks:get:blockstore:get', CID> | ProgressEvent<'blocks:get:blockstore:put', CID> | BitswapWantProgressEvents;
13
+ 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;
14
+ export type GetAllBlocksProgressEvents = ProgressEvent<'blocks:get-all:blockstore:get-many'>;
15
+ export type DeleteBlockProgressEvents = ProgressEvent<'blocks:delete:blockstore:delete', CID>;
16
+ export type DeleteManyBlocksProgressEvents = ProgressEvent<'blocks:delete-many:blockstore:delete-many'>;
17
+ export interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>, ProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>, ProgressOptions<GetBlockProgressEvents>, ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>, ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>> {
18
+ }
19
+ //# 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,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC1F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,C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C,aAAa,CAAC,2CAA2C,CAAC,CAAA;AAE5D,MAAM,WAAW,MAAO,SAAQ,UAAU,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAClF,eAAe,CAAC,sBAAsB,CAAC,EAAE,eAAe,CAAC,2BAA2B,CAAC,EACrF,eAAe,CAAC,sBAAsB,CAAC,EAAE,eAAe,CAAC,2BAA2B,CAAC,EAAE,eAAe,CAAC,0BAA0B,CAAC,EAClI,eAAe,CAAC,yBAAyB,CAAC,EAAE,eAAe,CAAC,8BAA8B,CAAC,CAC1F;CAEA"}
@@ -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":""}
@@ -13,56 +13,48 @@
13
13
  * }
14
14
  * ```
15
15
  */
16
+ import type { Blocks } from './blocks.js';
17
+ import type { Pins } from './pins.js';
16
18
  import type { Libp2p } from '@libp2p/interface-libp2p';
17
- import type { Blockstore } from 'interface-blockstore';
18
19
  import type { AbortOptions } from '@libp2p/interfaces';
19
- import type { PeerId } from '@libp2p/interface-peer-id';
20
- import type { Multiaddr } from '@multiformats/multiaddr';
21
20
  import type { Datastore } from 'interface-datastore';
21
+ import type { CID } from 'multiformats/cid';
22
+ import type { ProgressEvent, ProgressOptions } from 'progress-events';
23
+ export type { Await, AwaitIterable } from 'interface-store';
22
24
  /**
23
25
  * The API presented by a Helia node.
24
26
  */
25
- export interface Helia {
27
+ export interface Helia<T = Libp2p> {
26
28
  /**
27
29
  * The underlying libp2p node
28
30
  */
29
- libp2p: Libp2p;
31
+ libp2p: T;
30
32
  /**
31
33
  * Where the blocks are stored
32
34
  */
33
- blockstore: Blockstore;
35
+ blockstore: Blocks;
34
36
  /**
35
37
  * A key/value store
36
38
  */
37
39
  datastore: Datastore;
38
40
  /**
39
- * Returns information about this node
40
- *
41
- * @example
42
- *
43
- * ```typescript
44
- * import { createHelia } from 'helia'
45
- *
46
- * const node = await createHelia()
47
- * const id = await node.info()
48
- * console.info(id)
49
- * // { peerId: PeerId(12D3Foo), ... }
50
- * ```
41
+ * Pinning operations for blocks in the blockstore
51
42
  */
52
- info: (options?: InfoOptions) => Promise<InfoResponse>;
43
+ pins: Pins;
44
+ /**
45
+ * Starts the Helia node
46
+ */
47
+ start: () => Promise<void>;
53
48
  /**
54
49
  * Stops the Helia node
55
50
  */
56
51
  stop: () => Promise<void>;
52
+ /**
53
+ * Remove any unpinned blocks from the blockstore
54
+ */
55
+ gc: (options?: GCOptions) => Promise<void>;
57
56
  }
58
- export interface InfoOptions extends AbortOptions {
59
- peerId?: PeerId;
60
- }
61
- export interface InfoResponse {
62
- peerId: PeerId;
63
- multiaddrs: Multiaddr[];
64
- agentVersion: string;
65
- protocolVersion: string;
66
- protocols: string[];
57
+ export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
58
+ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
67
59
  }
68
60
  //# 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;AAEpD;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,EAAE,UAAU,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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"}
@@ -0,0 +1,48 @@
1
+ import type { AbortOptions } from '@libp2p/interfaces';
2
+ import type { CID } from 'multiformats/cid';
3
+ import type { ProgressEvent, ProgressOptions } from 'progress-events';
4
+ export type PinType = 'recursive' | 'direct' | 'indirect';
5
+ export interface Pin {
6
+ cid: CID;
7
+ depth: number;
8
+ metadata: Record<string, any>;
9
+ }
10
+ export type AddPinEvents = ProgressEvent<'helia:pin:add', unknown>;
11
+ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents> {
12
+ /**
13
+ * How deeply to pin the DAG, defaults to Infinity
14
+ */
15
+ depth?: number;
16
+ /**
17
+ * Optional user-defined metadata to store with the pin
18
+ */
19
+ metadata?: Record<string, string | number | boolean>;
20
+ }
21
+ export interface RmOptions extends AbortOptions {
22
+ }
23
+ export interface LsOptions extends AbortOptions {
24
+ cid?: CID;
25
+ }
26
+ export interface IsPinnedOptions extends AbortOptions {
27
+ }
28
+ export interface Pins {
29
+ /**
30
+ * Pin a block in the blockstore. It will not be deleted
31
+ * when garbage collection is run.
32
+ */
33
+ add: (cid: CID, options?: AddOptions) => Promise<Pin>;
34
+ /**
35
+ * Unpin the block that corresponds to the passed CID. The block will
36
+ * be deleted when garbage collection is run.
37
+ */
38
+ rm: (cid: CID, options?: RmOptions) => Promise<Pin>;
39
+ /**
40
+ * List all blocks that have been pinned.
41
+ */
42
+ ls: (options?: LsOptions) => AsyncGenerator<Pin, void, undefined>;
43
+ /**
44
+ * Return true if the passed CID is pinned
45
+ */
46
+ isPinned: (cid: CID, options?: IsPinnedOptions) => Promise<boolean>;
47
+ }
48
+ //# sourceMappingURL=pins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pins.d.ts","sourceRoot":"","sources":["../../src/pins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAA;AAEzD,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC9B;AAED,MAAM,MAAM,YAAY,GACtB,aAAa,CAAC,eAAe,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe,CAAC,YAAY,CAAC;IAC7E;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,SAAU,SAAQ,YAAY;CAE9C;AAED,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,MAAM,WAAW,eAAgB,SAAQ,YAAY;CAEpD;AAED,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAErD;;;OAGG;IACH,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAEnD;;OAEG;IACH,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,KAAK,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAEjE;;OAEG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACpE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pins.js","sourceRoot":"","sources":["../../src/pins.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ {
2
+ "AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.AddOptions.html",
3
+ "Blocks": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.Blocks.html",
4
+ "IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.IsPinnedOptions.html",
5
+ "LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.LsOptions.html",
6
+ "Pin": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.Pin.html",
7
+ "Pins": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.Pins.html",
8
+ "RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface._internal_.RmOptions.html",
9
+ "AddPinEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.AddPinEvents.html",
10
+ "DeleteBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.DeleteBlockProgressEvents.html",
11
+ "DeleteManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.DeleteManyBlocksProgressEvents.html",
12
+ "GetAllBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.GetAllBlocksProgressEvents.html",
13
+ "GetBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.GetBlockProgressEvents.html",
14
+ "GetManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.GetManyBlocksProgressEvents.html",
15
+ "HasBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.HasBlockProgressEvents.html",
16
+ "PutBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.PutBlockProgressEvents.html",
17
+ "PutManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface._internal_.PutManyBlocksProgressEvents.html",
18
+ "GCOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.GCOptions.html",
19
+ "Helia": "https://ipfs.github.io/helia/interfaces/_helia_interface.Helia.html",
20
+ "GcEvents": "https://ipfs.github.io/helia/types/_helia_interface.GcEvents.html"
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "0.0.0",
3
+ "version": "1.1.0",
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,9 +47,13 @@
47
47
  "types": "./dist/src/index.d.ts",
48
48
  "import": "./dist/src/index.js"
49
49
  },
50
- "./errors": {
51
- "types": "./dist/src/errors.d.ts",
52
- "import": "./dist/src/errors.js"
50
+ "./blocks": {
51
+ "types": "./dist/src/blocks.d.ts",
52
+ "import": "./dist/src/blocks.js"
53
+ },
54
+ "./pins": {
55
+ "types": "./dist/src/pins.d.ts",
56
+ "import": "./dist/src/pins.js"
53
57
  }
54
58
  },
55
59
  "eslintConfig": {
@@ -151,15 +155,17 @@
151
155
  "release": "aegir release"
152
156
  },
153
157
  "dependencies": {
154
- "@libp2p/interface-libp2p": "^1.1.0",
155
- "@libp2p/interface-peer-id": "^2.0.1",
156
- "@libp2p/interfaces": "^3.3.1",
157
- "@multiformats/multiaddr": "^11.1.5",
158
- "interface-blockstore": "^4.0.1",
159
- "interface-datastore": "^7.0.3"
158
+ "@libp2p/interface-libp2p": "^3.1.0",
159
+ "@libp2p/interfaces": "^3.3.2",
160
+ "interface-blockstore": "^5.0.0",
161
+ "interface-datastore": "^8.0.0",
162
+ "interface-store": "^5.0.1",
163
+ "ipfs-bitswap": "^18.0.0",
164
+ "multiformats": "^11.0.1",
165
+ "progress-events": "^1.0.0"
160
166
  },
161
167
  "devDependencies": {
162
- "aegir": "^38.1.0"
168
+ "aegir": "^39.0.4"
163
169
  },
164
170
  "typedoc": {
165
171
  "entryPoint": "./src/index.ts"
package/src/blocks.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { Blockstore } from 'interface-blockstore'
2
+ import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap'
3
+ import type { CID } from 'multiformats/cid'
4
+ import type { ProgressEvent, ProgressOptions } from 'progress-events'
5
+
6
+ export interface Pair {
7
+ cid: CID
8
+ block: Uint8Array
9
+ }
10
+
11
+ export type HasBlockProgressEvents =
12
+ ProgressEvent<'blocks:put:duplicate', CID> |
13
+ ProgressEvent<'blocks:put:bitswap:notify', CID> |
14
+ ProgressEvent<'blocks:put:blockstore:put', CID> |
15
+ BitswapNotifyProgressEvents
16
+
17
+ export type PutBlockProgressEvents =
18
+ ProgressEvent<'blocks:put:duplicate', CID> |
19
+ ProgressEvent<'blocks:put:bitswap:notify', CID> |
20
+ ProgressEvent<'blocks:put:blockstore:put', CID> |
21
+ BitswapNotifyProgressEvents
22
+
23
+ export type PutManyBlocksProgressEvents =
24
+ ProgressEvent<'blocks:put-many:duplicate', CID> |
25
+ ProgressEvent<'blocks:put-many:bitswap:notify', CID> |
26
+ ProgressEvent<'blocks:put-many:blockstore:put-many'> |
27
+ BitswapNotifyProgressEvents
28
+
29
+ export type GetBlockProgressEvents =
30
+ ProgressEvent<'blocks:get:bitswap:want', CID> |
31
+ ProgressEvent<'blocks:get:blockstore:get', CID> |
32
+ ProgressEvent<'blocks:get:blockstore:put', CID> |
33
+ BitswapWantProgressEvents
34
+
35
+ export type GetManyBlocksProgressEvents =
36
+ ProgressEvent<'blocks:get-many:blockstore:get-many'> |
37
+ ProgressEvent<'blocks:get-many:bitswap:want', CID> |
38
+ ProgressEvent<'blocks:get-many:blockstore:put', CID> |
39
+ BitswapWantProgressEvents
40
+
41
+ export type GetAllBlocksProgressEvents =
42
+ ProgressEvent<'blocks:get-all:blockstore:get-many'>
43
+
44
+ export type DeleteBlockProgressEvents =
45
+ ProgressEvent<'blocks:delete:blockstore:delete', CID>
46
+
47
+ export type DeleteManyBlocksProgressEvents =
48
+ ProgressEvent<'blocks:delete-many:blockstore:delete-many'>
49
+
50
+ export interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>,
51
+ ProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,
52
+ ProgressOptions<GetBlockProgressEvents>, ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>,
53
+ ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>
54
+ > {
55
+
56
+ }
package/src/index.ts CHANGED
@@ -14,26 +14,29 @@
14
14
  * ```
15
15
  */
16
16
 
17
+ import type { Blocks } from './blocks.js'
18
+ import type { Pins } from './pins.js'
17
19
  import type { Libp2p } from '@libp2p/interface-libp2p'
18
- import type { Blockstore } from 'interface-blockstore'
19
20
  import type { AbortOptions } from '@libp2p/interfaces'
20
- import type { PeerId } from '@libp2p/interface-peer-id'
21
- import type { Multiaddr } from '@multiformats/multiaddr'
22
21
  import type { Datastore } from 'interface-datastore'
22
+ import type { CID } from 'multiformats/cid'
23
+ import type { ProgressEvent, ProgressOptions } from 'progress-events'
24
+
25
+ export type { Await, AwaitIterable } from 'interface-store'
23
26
 
24
27
  /**
25
28
  * The API presented by a Helia node.
26
29
  */
27
- export interface Helia {
30
+ export interface Helia<T = Libp2p> {
28
31
  /**
29
32
  * The underlying libp2p node
30
33
  */
31
- libp2p: Libp2p
34
+ libp2p: T
32
35
 
33
36
  /**
34
37
  * Where the blocks are stored
35
38
  */
36
- blockstore: Blockstore
39
+ blockstore: Blocks
37
40
 
38
41
  /**
39
42
  * A key/value store
@@ -41,58 +44,30 @@ export interface Helia {
41
44
  datastore: Datastore
42
45
 
43
46
  /**
44
- * Returns information about this node
45
- *
46
- * @example
47
- *
48
- * ```typescript
49
- * import { createHelia } from 'helia'
50
- *
51
- * const node = await createHelia()
52
- * const id = await node.info()
53
- * console.info(id)
54
- * // { peerId: PeerId(12D3Foo), ... }
55
- * ```
47
+ * Pinning operations for blocks in the blockstore
56
48
  */
57
- info: (options?: InfoOptions) => Promise<InfoResponse>
49
+ pins: Pins
58
50
 
59
51
  /**
60
- * Stops the Helia node
52
+ * Starts the Helia node
61
53
  */
62
- stop: () => Promise<void>
63
- }
54
+ start: () => Promise<void>
64
55
 
65
- export interface InfoOptions extends AbortOptions {
66
56
  /**
67
- * If passed, return information about this PeerId, defaults
68
- * to the ID of the current node.
69
- */
70
- peerId?: PeerId
71
- }
72
-
73
- export interface InfoResponse {
74
- /**
75
- * The ID of the peer this info is about
57
+ * Stops the Helia node
76
58
  */
77
- peerId: PeerId
59
+ stop: () => Promise<void>
78
60
 
79
61
  /**
80
- * The multiaddrs the peer is listening on
62
+ * Remove any unpinned blocks from the blockstore
81
63
  */
82
- multiaddrs: Multiaddr[]
64
+ gc: (options?: GCOptions) => Promise<void>
65
+ }
83
66
 
84
- /**
85
- * The peer's reported agent version
86
- */
87
- agentVersion: string
67
+ export type GcEvents =
68
+ ProgressEvent<'helia:gc:deleted', CID> |
69
+ ProgressEvent<'helia:gc:error', Error>
88
70
 
89
- /**
90
- * The peer's reported protocol version
91
- */
92
- protocolVersion: string
71
+ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
93
72
 
94
- /**
95
- * The protocols the peer supports
96
- */
97
- protocols: string[]
98
73
  }
package/src/pins.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { AbortOptions } from '@libp2p/interfaces'
2
+ import type { CID } from 'multiformats/cid'
3
+ import type { ProgressEvent, ProgressOptions } from 'progress-events'
4
+
5
+ export type PinType = 'recursive' | 'direct' | 'indirect'
6
+
7
+ export interface Pin {
8
+ cid: CID
9
+ depth: number
10
+ metadata: Record<string, any>
11
+ }
12
+
13
+ export type AddPinEvents =
14
+ ProgressEvent<'helia:pin:add', unknown>
15
+
16
+ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents> {
17
+ /**
18
+ * How deeply to pin the DAG, defaults to Infinity
19
+ */
20
+ depth?: number
21
+
22
+ /**
23
+ * Optional user-defined metadata to store with the pin
24
+ */
25
+ metadata?: Record<string, string | number | boolean>
26
+ }
27
+
28
+ export interface RmOptions extends AbortOptions {
29
+
30
+ }
31
+
32
+ export interface LsOptions extends AbortOptions {
33
+ cid?: CID
34
+ }
35
+
36
+ export interface IsPinnedOptions extends AbortOptions {
37
+
38
+ }
39
+
40
+ export interface Pins {
41
+ /**
42
+ * Pin a block in the blockstore. It will not be deleted
43
+ * when garbage collection is run.
44
+ */
45
+ add: (cid: CID, options?: AddOptions) => Promise<Pin>
46
+
47
+ /**
48
+ * Unpin the block that corresponds to the passed CID. The block will
49
+ * be deleted when garbage collection is run.
50
+ */
51
+ rm: (cid: CID, options?: RmOptions) => Promise<Pin>
52
+
53
+ /**
54
+ * List all blocks that have been pinned.
55
+ */
56
+ ls: (options?: LsOptions) => AsyncGenerator<Pin, void, undefined>
57
+
58
+ /**
59
+ * Return true if the passed CID is pinned
60
+ */
61
+ isPinned: (cid: CID, options?: IsPinnedOptions) => Promise<boolean>
62
+ }
@@ -1,18 +0,0 @@
1
- export declare abstract class HeliaError extends Error {
2
- readonly name: string;
3
- readonly code: string;
4
- constructor(message: string, name: string, code: string);
5
- }
6
- export declare class NotAFileError extends HeliaError {
7
- constructor(message?: string);
8
- }
9
- export declare class NotADirectoryError extends HeliaError {
10
- constructor(message?: string);
11
- }
12
- export declare class NoContentError extends HeliaError {
13
- constructor(message?: string);
14
- }
15
- export declare class InvalidParametersError extends HeliaError {
16
- constructor(message?: string);
17
- }
18
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,8BAAsB,UAAW,SAAQ,KAAK;IAC5C,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAEf,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAMzD;AAED,qBAAa,aAAc,SAAQ,UAAU;gBAC9B,OAAO,SAAe;CAGpC;AAED,qBAAa,kBAAmB,SAAQ,UAAU;gBACnC,OAAO,SAAoB;CAGzC;AAED,qBAAa,cAAe,SAAQ,UAAU;gBAC/B,OAAO,SAAe;CAGpC;AAED,qBAAa,sBAAuB,SAAQ,UAAU;gBACvC,OAAO,SAAuB;CAG5C"}
@@ -1,28 +0,0 @@
1
- export class HeliaError extends Error {
2
- constructor(message, name, code) {
3
- super(message);
4
- this.name = name;
5
- this.code = code;
6
- }
7
- }
8
- export class NotAFileError extends HeliaError {
9
- constructor(message = 'not a file') {
10
- super(message, 'NotAFileError', 'ERR_NOT_FILE');
11
- }
12
- }
13
- export class NotADirectoryError extends HeliaError {
14
- constructor(message = 'not a directory') {
15
- super(message, 'NotAFileError', 'ERR_NOT_DIRECTORY');
16
- }
17
- }
18
- export class NoContentError extends HeliaError {
19
- constructor(message = 'no content') {
20
- super(message, 'NoContentError', 'ERR_NO_CONTENT');
21
- }
22
- }
23
- export class InvalidParametersError extends HeliaError {
24
- constructor(message = 'invalid parameters') {
25
- super(message, 'InvalidParametersError', 'ERR_INVALID_PARAMETERS');
26
- }
27
- }
28
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,UAAW,SAAQ,KAAK;IAI5C,YAAa,OAAe,EAAE,IAAY,EAAE,IAAY;QACtD,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YAAa,OAAO,GAAG,YAAY;QACjC,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,cAAc,CAAC,CAAA;IACjD,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAChD,YAAa,OAAO,GAAG,iBAAiB;QACtC,KAAK,CAAC,OAAO,EAAE,eAAe,EAAE,mBAAmB,CAAC,CAAA;IACtD,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,YAAa,OAAO,GAAG,YAAY;QACjC,KAAK,CAAC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAA;IACpD,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IACpD,YAAa,OAAO,GAAG,oBAAoB;QACzC,KAAK,CAAC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,CAAC,CAAA;IACpE,CAAC;CACF"}
package/src/errors.ts DELETED
@@ -1,35 +0,0 @@
1
- export abstract class HeliaError extends Error {
2
- public readonly name: string
3
- public readonly code: string
4
-
5
- constructor (message: string, name: string, code: string) {
6
- super(message)
7
-
8
- this.name = name
9
- this.code = code
10
- }
11
- }
12
-
13
- export class NotAFileError extends HeliaError {
14
- constructor (message = 'not a file') {
15
- super(message, 'NotAFileError', 'ERR_NOT_FILE')
16
- }
17
- }
18
-
19
- export class NotADirectoryError extends HeliaError {
20
- constructor (message = 'not a directory') {
21
- super(message, 'NotAFileError', 'ERR_NOT_DIRECTORY')
22
- }
23
- }
24
-
25
- export class NoContentError extends HeliaError {
26
- constructor (message = 'no content') {
27
- super(message, 'NoContentError', 'ERR_NO_CONTENT')
28
- }
29
- }
30
-
31
- export class InvalidParametersError extends HeliaError {
32
- constructor (message = 'invalid parameters') {
33
- super(message, 'InvalidParametersError', 'ERR_INVALID_PARAMETERS')
34
- }
35
- }