@helia/interface 0.0.0-031ca73
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/LICENSE +4 -0
- package/README.md +50 -0
- package/dist/index.min.js +3 -0
- package/dist/src/index.d.ts +67 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pins.d.ts +48 -0
- package/dist/src/pins.d.ts.map +1 -0
- package/dist/src/pins.js +2 -0
- package/dist/src/pins.js.map +1 -0
- package/package.json +169 -0
- package/src/index.ts +79 -0
- package/src/pins.ts +62 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
|
|
7
|
+
# @helia/interface <!-- omit in toc -->
|
|
8
|
+
|
|
9
|
+
[](https://ipfs.tech)
|
|
10
|
+
[](https://discuss.ipfs.tech)
|
|
11
|
+
[](https://codecov.io/gh/ipfs/helia)
|
|
12
|
+
[](https://github.com/ipfs/helia/actions/workflows/main.yml?query=branch%3Amain)
|
|
13
|
+
|
|
14
|
+
> The Helia API
|
|
15
|
+
|
|
16
|
+
## Table of contents <!-- omit in toc -->
|
|
17
|
+
|
|
18
|
+
- [Install](#install)
|
|
19
|
+
- [API Docs](#api-docs)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
- [Contribute](#contribute)
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```console
|
|
26
|
+
$ npm i @helia/interface
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Docs
|
|
30
|
+
|
|
31
|
+
- <https://ipfs.github.io/helia/modules/_helia_interface.html>
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
Licensed under either of
|
|
36
|
+
|
|
37
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
38
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
39
|
+
|
|
40
|
+
## Contribute
|
|
41
|
+
|
|
42
|
+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia/issues).
|
|
43
|
+
|
|
44
|
+
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
|
|
45
|
+
|
|
46
|
+
Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
47
|
+
|
|
48
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
49
|
+
|
|
50
|
+
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaInterface = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
"use strict";var HeliaInterface=(()=>{var t=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(o,e,x,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of b(e))!c.call(o,p)&&p!==x&&t(o,p,{get:()=>e[p],enumerable:!(r=a(e,p))||r.enumerable});return o};var f=o=>d(t({},"__esModule",{value:!0}),o);var g={};return f(g);})();
|
|
3
|
+
return HeliaInterface}));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The API defined by a Helia node
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { Helia } from '@helia/interface'
|
|
10
|
+
*
|
|
11
|
+
* export function doSomething(helia: Helia) {
|
|
12
|
+
* // use helia node functions here
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { Libp2p } from '@libp2p/interface-libp2p';
|
|
17
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
18
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
19
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
20
|
+
import type { Datastore } from 'interface-datastore';
|
|
21
|
+
import type { Pins } from './pins.js';
|
|
22
|
+
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
23
|
+
import type { CID } from 'multiformats/cid';
|
|
24
|
+
/**
|
|
25
|
+
* The API presented by a Helia node.
|
|
26
|
+
*/
|
|
27
|
+
export interface Helia {
|
|
28
|
+
/**
|
|
29
|
+
* The underlying libp2p node
|
|
30
|
+
*/
|
|
31
|
+
libp2p: Libp2p;
|
|
32
|
+
/**
|
|
33
|
+
* Where the blocks are stored
|
|
34
|
+
*/
|
|
35
|
+
blockstore: Blockstore;
|
|
36
|
+
/**
|
|
37
|
+
* A key/value store
|
|
38
|
+
*/
|
|
39
|
+
datastore: Datastore;
|
|
40
|
+
/**
|
|
41
|
+
* Pinning operations for blocks in the blockstore
|
|
42
|
+
*/
|
|
43
|
+
pins: Pins;
|
|
44
|
+
/**
|
|
45
|
+
* Starts the Helia node
|
|
46
|
+
*/
|
|
47
|
+
start: () => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Stops the Helia node
|
|
50
|
+
*/
|
|
51
|
+
stop: () => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Remove any unpinned blocks from the blockstore
|
|
54
|
+
*/
|
|
55
|
+
gc: (options?: GCOptions) => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
export type GcEvents = ProgressEvent<'helia:gc:deleted', CID>;
|
|
58
|
+
export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
|
|
59
|
+
}
|
|
60
|
+
export interface InfoOptions extends AbortOptions {
|
|
61
|
+
/**
|
|
62
|
+
* If passed, return information about this PeerId, defaults
|
|
63
|
+
* to the ID of the current node.
|
|
64
|
+
*/
|
|
65
|
+
peerId?: PeerId;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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;;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,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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The API defined by a Helia node
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { Helia } from '@helia/interface'
|
|
10
|
+
*
|
|
11
|
+
* export function doSomething(helia: Helia) {
|
|
12
|
+
* // use helia node functions here
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -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"}
|
package/dist/src/pins.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pins.js","sourceRoot":"","sources":["../../src/pins.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@helia/interface",
|
|
3
|
+
"version": "0.0.0-031ca73",
|
|
4
|
+
"description": "The Helia API",
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/ipfs/helia/tree/master/packages/interface#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ipfs/helia.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ipfs/helia/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"IPFS"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16.0.0",
|
|
19
|
+
"npm": ">=7.0.0"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/src/index.d.ts",
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"*": [
|
|
26
|
+
"*",
|
|
27
|
+
"dist/*",
|
|
28
|
+
"dist/src/*",
|
|
29
|
+
"dist/src/*/index"
|
|
30
|
+
],
|
|
31
|
+
"src/*": [
|
|
32
|
+
"*",
|
|
33
|
+
"dist/*",
|
|
34
|
+
"dist/src/*",
|
|
35
|
+
"dist/src/*/index"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"src",
|
|
41
|
+
"dist",
|
|
42
|
+
"!dist/test",
|
|
43
|
+
"!**/*.tsbuildinfo"
|
|
44
|
+
],
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./dist/src/index.d.ts",
|
|
48
|
+
"import": "./dist/src/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./pins": {
|
|
51
|
+
"types": "./dist/src/pins.d.ts",
|
|
52
|
+
"import": "./dist/src/pins.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"eslintConfig": {
|
|
56
|
+
"extends": "ipfs",
|
|
57
|
+
"parserOptions": {
|
|
58
|
+
"sourceType": "module"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"release": {
|
|
62
|
+
"branches": [
|
|
63
|
+
"main"
|
|
64
|
+
],
|
|
65
|
+
"plugins": [
|
|
66
|
+
[
|
|
67
|
+
"@semantic-release/commit-analyzer",
|
|
68
|
+
{
|
|
69
|
+
"preset": "conventionalcommits",
|
|
70
|
+
"releaseRules": [
|
|
71
|
+
{
|
|
72
|
+
"breaking": true,
|
|
73
|
+
"release": "major"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"revert": true,
|
|
77
|
+
"release": "patch"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "feat",
|
|
81
|
+
"release": "minor"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "fix",
|
|
85
|
+
"release": "patch"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"type": "docs",
|
|
89
|
+
"release": "patch"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"type": "test",
|
|
93
|
+
"release": "patch"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "deps",
|
|
97
|
+
"release": "patch"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"scope": "no-release",
|
|
101
|
+
"release": false
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"@semantic-release/release-notes-generator",
|
|
108
|
+
{
|
|
109
|
+
"preset": "conventionalcommits",
|
|
110
|
+
"presetConfig": {
|
|
111
|
+
"types": [
|
|
112
|
+
{
|
|
113
|
+
"type": "feat",
|
|
114
|
+
"section": "Features"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"type": "fix",
|
|
118
|
+
"section": "Bug Fixes"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "chore",
|
|
122
|
+
"section": "Trivial Changes"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"type": "docs",
|
|
126
|
+
"section": "Documentation"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"type": "deps",
|
|
130
|
+
"section": "Dependencies"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"type": "test",
|
|
134
|
+
"section": "Tests"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"@semantic-release/changelog",
|
|
141
|
+
"@semantic-release/npm",
|
|
142
|
+
"@semantic-release/github",
|
|
143
|
+
"@semantic-release/git"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
"scripts": {
|
|
147
|
+
"clean": "aegir clean",
|
|
148
|
+
"lint": "aegir lint",
|
|
149
|
+
"dep-check": "aegir dep-check",
|
|
150
|
+
"build": "aegir build",
|
|
151
|
+
"release": "aegir release"
|
|
152
|
+
},
|
|
153
|
+
"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",
|
|
160
|
+
"multiformats": "^11.0.1",
|
|
161
|
+
"progress-events": "^1.0.0"
|
|
162
|
+
},
|
|
163
|
+
"devDependencies": {
|
|
164
|
+
"aegir": "^38.1.0"
|
|
165
|
+
},
|
|
166
|
+
"typedoc": {
|
|
167
|
+
"entryPoint": "./src/index.ts"
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The API defined by a Helia node
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import type { Helia } from '@helia/interface'
|
|
10
|
+
*
|
|
11
|
+
* export function doSomething(helia: Helia) {
|
|
12
|
+
* // use helia node functions here
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { Libp2p } from '@libp2p/interface-libp2p'
|
|
18
|
+
import type { Blockstore } from 'interface-blockstore'
|
|
19
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
20
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
21
|
+
import type { Datastore } from 'interface-datastore'
|
|
22
|
+
import type { Pins } from './pins.js'
|
|
23
|
+
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
24
|
+
import type { CID } from 'multiformats/cid'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The API presented by a Helia node.
|
|
28
|
+
*/
|
|
29
|
+
export interface Helia {
|
|
30
|
+
/**
|
|
31
|
+
* The underlying libp2p node
|
|
32
|
+
*/
|
|
33
|
+
libp2p: Libp2p
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Where the blocks are stored
|
|
37
|
+
*/
|
|
38
|
+
blockstore: Blockstore
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A key/value store
|
|
42
|
+
*/
|
|
43
|
+
datastore: Datastore
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Pinning operations for blocks in the blockstore
|
|
47
|
+
*/
|
|
48
|
+
pins: Pins
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Starts the Helia node
|
|
52
|
+
*/
|
|
53
|
+
start: () => Promise<void>
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Stops the Helia node
|
|
57
|
+
*/
|
|
58
|
+
stop: () => Promise<void>
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Remove any unpinned blocks from the blockstore
|
|
62
|
+
*/
|
|
63
|
+
gc: (options?: GCOptions) => Promise<void>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type GcEvents =
|
|
67
|
+
ProgressEvent<'helia:gc:deleted', CID>
|
|
68
|
+
|
|
69
|
+
export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface InfoOptions extends AbortOptions {
|
|
74
|
+
/**
|
|
75
|
+
* If passed, return information about this PeerId, defaults
|
|
76
|
+
* to the ID of the current node.
|
|
77
|
+
*/
|
|
78
|
+
peerId?: PeerId
|
|
79
|
+
}
|
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
|
+
}
|