@helia/interface 0.0.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/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ This project is dual licensed under MIT and Apache-2.0.
2
+
3
+ MIT: https://www.opensource.org/licenses/mit
4
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @helia/interface <!-- omit in toc -->
2
+
3
+ [![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
4
+ [![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
5
+ [![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)
7
+
8
+ > The Helia API
9
+
10
+ ## Table of contents <!-- omit in toc -->
11
+
12
+ - [Install](#install)
13
+ - [API Docs](#api-docs)
14
+ - [License](#license)
15
+ - [Contribute](#contribute)
16
+
17
+ ## Install
18
+
19
+ ```console
20
+ $ npm i @helia/interface
21
+ ```
22
+
23
+ ## API Docs
24
+
25
+ - <https://ipfs.github.io/helia/modules/_helia_interface.html>
26
+
27
+ ## License
28
+
29
+ Licensed under either of
30
+
31
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
32
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
33
+
34
+ ## Contribute
35
+
36
+ Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia/issues).
37
+
38
+ 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.
39
+
40
+ 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).
41
+
42
+ 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.
43
+
44
+ [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](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,18 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,28 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,68 @@
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 { Multiaddr } from '@multiformats/multiaddr';
21
+ import type { Datastore } from 'interface-datastore';
22
+ /**
23
+ * The API presented by a Helia node.
24
+ */
25
+ export interface Helia {
26
+ /**
27
+ * The underlying libp2p node
28
+ */
29
+ libp2p: Libp2p;
30
+ /**
31
+ * Where the blocks are stored
32
+ */
33
+ blockstore: Blockstore;
34
+ /**
35
+ * A key/value store
36
+ */
37
+ datastore: Datastore;
38
+ /**
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
+ * ```
51
+ */
52
+ info: (options?: InfoOptions) => Promise<InfoResponse>;
53
+ /**
54
+ * Stops the Helia node
55
+ */
56
+ stop: () => Promise<void>;
57
+ }
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[];
67
+ }
68
+ //# 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,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,CAAA;IAEtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;;;;;;;;;;;;OAaG;IACH,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;IAEtD;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAED,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB"}
@@ -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"}
package/package.json ADDED
@@ -0,0 +1,167 @@
1
+ {
2
+ "name": "@helia/interface",
3
+ "version": "0.0.0",
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
+ "./errors": {
51
+ "types": "./dist/src/errors.d.ts",
52
+ "import": "./dist/src/errors.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
+ },
161
+ "devDependencies": {
162
+ "aegir": "^38.1.0"
163
+ },
164
+ "typedoc": {
165
+ "entryPoint": "./src/index.ts"
166
+ }
167
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,35 @@
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
+ }
package/src/index.ts ADDED
@@ -0,0 +1,98 @@
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 { Multiaddr } from '@multiformats/multiaddr'
22
+ import type { Datastore } from 'interface-datastore'
23
+
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
+ /**
34
+ * Where the blocks are stored
35
+ */
36
+ blockstore: Blockstore
37
+
38
+ /**
39
+ * A key/value store
40
+ */
41
+ datastore: Datastore
42
+
43
+ /**
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
+ * ```
56
+ */
57
+ info: (options?: InfoOptions) => Promise<InfoResponse>
58
+
59
+ /**
60
+ * Stops the Helia node
61
+ */
62
+ stop: () => Promise<void>
63
+ }
64
+
65
+ export interface InfoOptions extends AbortOptions {
66
+ /**
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
76
+ */
77
+ peerId: PeerId
78
+
79
+ /**
80
+ * The multiaddrs the peer is listening on
81
+ */
82
+ multiaddrs: Multiaddr[]
83
+
84
+ /**
85
+ * The peer's reported agent version
86
+ */
87
+ agentVersion: string
88
+
89
+ /**
90
+ * The peer's reported protocol version
91
+ */
92
+ protocolVersion: string
93
+
94
+ /**
95
+ * The protocols the peer supports
96
+ */
97
+ protocols: string[]
98
+ }