@helia/http 0.9.0 → 1.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/README.md +26 -0
- package/dist/index.min.js +6 -45
- package/dist/src/index.d.ts +30 -71
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +30 -25
- package/dist/src/index.js.map +1 -1
- package/package.json +16 -12
- package/src/index.ts +34 -107
- package/dist/src/utils/libp2p-defaults.d.ts +0 -7
- package/dist/src/utils/libp2p-defaults.d.ts.map +0 -1
- package/dist/src/utils/libp2p-defaults.js +0 -13
- package/dist/src/utils/libp2p-defaults.js.map +0 -1
- package/dist/src/utils/libp2p.d.ts +0 -15
- package/dist/src/utils/libp2p.d.ts.map +0 -1
- package/dist/src/utils/libp2p.js +0 -13
- package/dist/src/utils/libp2p.js.map +0 -1
- package/src/utils/libp2p-defaults.ts +0 -19
- package/src/utils/libp2p.ts +0 -29
package/dist/src/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
|
|
5
5
|
*
|
|
6
|
+
* By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
|
|
7
|
+
*
|
|
6
8
|
* Pass it to other modules like {@link https://www.npmjs.com/package/@helia/unixfs | @helia/unixfs} to fetch files from the distributed web.
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
@@ -17,84 +19,41 @@
|
|
|
17
19
|
* const fs = unixfs(helia)
|
|
18
20
|
* fs.cat(CID.parse('bafyFoo'))
|
|
19
21
|
* ```
|
|
22
|
+
* @example with custom gateways and delegated routing endpoints
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { createHeliaHTTP } from '@helia/http'
|
|
25
|
+
* import { trustlessGateway } from '@helia/block-brokers'
|
|
26
|
+
* import { delegatedHTTPRouting } from '@helia/routers'
|
|
27
|
+
* import { unixfs } from '@helia/unixfs'
|
|
28
|
+
* import { CID } from 'multiformats/cid'
|
|
29
|
+
*
|
|
30
|
+
* const helia = await createHeliaHTTP({
|
|
31
|
+
* blockBrokers: [
|
|
32
|
+
* trustlessGateway({
|
|
33
|
+
* gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io'],
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* routers: [
|
|
37
|
+
* delegatedHTTPRouting('https://delegated-ipfs.dev')
|
|
38
|
+
* ]
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* const fs = unixfs(helia)
|
|
42
|
+
* fs.cat(CID.parse('bafyFoo'))
|
|
43
|
+
* ```
|
|
20
44
|
*/
|
|
21
|
-
import
|
|
22
|
-
import type {
|
|
23
|
-
import type { ComponentLogger, Libp2p } from '@libp2p/interface';
|
|
24
|
-
import type { Blockstore } from 'interface-blockstore';
|
|
25
|
-
import type { Datastore } from 'interface-datastore';
|
|
26
|
-
import type { Libp2pOptions } from 'libp2p';
|
|
27
|
-
import type { MultihashHasher } from 'multiformats/hashes/interface';
|
|
45
|
+
import { type HeliaInit } from '@helia/utils';
|
|
46
|
+
import type { Helia } from '@helia/interface';
|
|
28
47
|
export * from '@helia/interface';
|
|
29
|
-
export
|
|
30
|
-
export * from '@helia/interface/pins';
|
|
31
|
-
/**
|
|
32
|
-
* Options used to create a Helia node.
|
|
33
|
-
*/
|
|
34
|
-
export interface HeliaHTTPInit<T extends Libp2p = Libp2p> {
|
|
48
|
+
export interface HeliaHTTPInit extends HeliaInit {
|
|
35
49
|
/**
|
|
36
|
-
*
|
|
37
|
-
* preconfigured node or options to configure a node can be passed
|
|
38
|
-
* here.
|
|
39
|
-
*
|
|
40
|
-
* If node options are passed, they will be merged with the default
|
|
41
|
-
* config for the current platform. In this case all passed config
|
|
42
|
-
* keys will replace those from the default config.
|
|
43
|
-
*/
|
|
44
|
-
libp2p?: T | Libp2pOptions;
|
|
45
|
-
/**
|
|
46
|
-
* The blockstore is where blocks are stored
|
|
47
|
-
*/
|
|
48
|
-
blockstore?: Blockstore;
|
|
49
|
-
/**
|
|
50
|
-
* The datastore is where data is stored
|
|
51
|
-
*/
|
|
52
|
-
datastore?: Datastore;
|
|
53
|
-
/**
|
|
54
|
-
* By default sha256, sha512 and identity hashes are supported for
|
|
55
|
-
* bitswap operations. To bitswap blocks with CIDs using other hashes
|
|
56
|
-
* pass appropriate MultihashHashers here.
|
|
57
|
-
*/
|
|
58
|
-
hashers?: MultihashHasher[];
|
|
59
|
-
/**
|
|
60
|
-
* In order to pin CIDs that correspond to a DAG, it's necessary to know
|
|
61
|
-
* how to traverse that DAG. DAGWalkers take a block and yield any CIDs
|
|
62
|
-
* encoded within that block.
|
|
63
|
-
*/
|
|
64
|
-
dagWalkers?: DAGWalker[];
|
|
65
|
-
/**
|
|
66
|
-
* A list of strategies used to fetch blocks when they are not present in
|
|
67
|
-
* the local blockstore
|
|
68
|
-
*/
|
|
69
|
-
blockBrokers?: Array<(components: any) => BlockBroker>;
|
|
70
|
-
/**
|
|
71
|
-
* Pass `false` to not start the Helia node
|
|
50
|
+
* Whether to start the Helia node
|
|
72
51
|
*/
|
|
73
52
|
start?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Garbage collection requires preventing blockstore writes during searches
|
|
76
|
-
* for unpinned blocks as DAGs are typically pinned after they've been
|
|
77
|
-
* imported - without locking this could lead to the deletion of blocks while
|
|
78
|
-
* they are being added to the blockstore.
|
|
79
|
-
*
|
|
80
|
-
* By default this lock is held on the main process (e.g. node cluster's
|
|
81
|
-
* primary process, the renderer thread in browsers) and other processes will
|
|
82
|
-
* contact the main process for access (worker processes in node cluster,
|
|
83
|
-
* webworkers in the browser).
|
|
84
|
-
*
|
|
85
|
-
* If Helia is being run wholly in a non-primary process, with no other process
|
|
86
|
-
* expected to access the blockstore (e.g. being run in the background in a
|
|
87
|
-
* webworker), pass true here to hold the gc lock in this process.
|
|
88
|
-
*/
|
|
89
|
-
holdGcLock?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* An optional logging component to pass to libp2p. If not specified the
|
|
92
|
-
* default implementation from libp2p will be used.
|
|
93
|
-
*/
|
|
94
|
-
logger?: ComponentLogger;
|
|
95
53
|
}
|
|
54
|
+
/**
|
|
96
55
|
/**
|
|
97
56
|
* Create and return a Helia node
|
|
98
57
|
*/
|
|
99
|
-
export declare function createHeliaHTTP(init?: HeliaHTTPInit): Promise<Helia>;
|
|
58
|
+
export declare function createHeliaHTTP(init?: Partial<HeliaHTTPInit>): Promise<Helia>;
|
|
100
59
|
//# sourceMappingURL=index.d.ts.map
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAGlE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAI7C,cAAc,kBAAkB,CAAA;AAEhC,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAE,IAAI,GAAE,OAAO,CAAC,aAAa,CAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAqBxF"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
|
|
5
5
|
*
|
|
6
|
+
* By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
|
|
7
|
+
*
|
|
6
8
|
* Pass it to other modules like {@link https://www.npmjs.com/package/@helia/unixfs | @helia/unixfs} to fetch files from the distributed web.
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
@@ -17,41 +19,53 @@
|
|
|
17
19
|
* const fs = unixfs(helia)
|
|
18
20
|
* fs.cat(CID.parse('bafyFoo'))
|
|
19
21
|
* ```
|
|
22
|
+
* @example with custom gateways and delegated routing endpoints
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { createHeliaHTTP } from '@helia/http'
|
|
25
|
+
* import { trustlessGateway } from '@helia/block-brokers'
|
|
26
|
+
* import { delegatedHTTPRouting } from '@helia/routers'
|
|
27
|
+
* import { unixfs } from '@helia/unixfs'
|
|
28
|
+
* import { CID } from 'multiformats/cid'
|
|
29
|
+
*
|
|
30
|
+
* const helia = await createHeliaHTTP({
|
|
31
|
+
* blockBrokers: [
|
|
32
|
+
* trustlessGateway({
|
|
33
|
+
* gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io'],
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* routers: [
|
|
37
|
+
* delegatedHTTPRouting('https://delegated-ipfs.dev')
|
|
38
|
+
* ]
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* const fs = unixfs(helia)
|
|
42
|
+
* fs.cat(CID.parse('bafyFoo'))
|
|
43
|
+
* ```
|
|
20
44
|
*/
|
|
21
45
|
import { trustlessGateway } from '@helia/block-brokers';
|
|
22
|
-
import {
|
|
46
|
+
import { delegatedHTTPRouting } from '@helia/routers';
|
|
47
|
+
import { Helia as HeliaClass } from '@helia/utils';
|
|
23
48
|
import { MemoryBlockstore } from 'blockstore-core';
|
|
24
49
|
import { MemoryDatastore } from 'datastore-core';
|
|
25
|
-
import { createLibp2p } from './utils/libp2p.js';
|
|
26
50
|
// re-export interface types so people don't have to depend on @helia/interface
|
|
27
51
|
// if they don't want to
|
|
28
52
|
export * from '@helia/interface';
|
|
29
|
-
|
|
30
|
-
export * from '@helia/interface/pins';
|
|
53
|
+
/**
|
|
31
54
|
/**
|
|
32
55
|
* Create and return a Helia node
|
|
33
56
|
*/
|
|
34
57
|
export async function createHeliaHTTP(init = {}) {
|
|
35
58
|
const datastore = init.datastore ?? new MemoryDatastore();
|
|
36
59
|
const blockstore = init.blockstore ?? new MemoryBlockstore();
|
|
37
|
-
let libp2p;
|
|
38
|
-
if (isLibp2p(init.libp2p)) {
|
|
39
|
-
libp2p = init.libp2p;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
libp2p = await createLibp2p({
|
|
43
|
-
...init,
|
|
44
|
-
libp2p: init.libp2p,
|
|
45
|
-
datastore
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
60
|
const helia = new HeliaClass({
|
|
49
61
|
...init,
|
|
50
|
-
libp2p,
|
|
51
62
|
datastore,
|
|
52
63
|
blockstore,
|
|
53
64
|
blockBrokers: init.blockBrokers ?? [
|
|
54
65
|
trustlessGateway()
|
|
66
|
+
],
|
|
67
|
+
routers: init.routers ?? [
|
|
68
|
+
delegatedHTTPRouting('https://delegated-ipfs.dev')
|
|
55
69
|
]
|
|
56
70
|
});
|
|
57
71
|
if (init.start !== false) {
|
|
@@ -59,13 +73,4 @@ export async function createHeliaHTTP(init = {}) {
|
|
|
59
73
|
}
|
|
60
74
|
return helia;
|
|
61
75
|
}
|
|
62
|
-
function isLibp2p(obj) {
|
|
63
|
-
if (obj == null) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
// a non-exhaustive list of methods found on the libp2p object
|
|
67
|
-
const funcs = ['dial', 'dialProtocol', 'hangUp', 'handle', 'unhandle', 'getMultiaddrs', 'getProtocols'];
|
|
68
|
-
// if these are all functions it's probably a libp2p object
|
|
69
|
-
return funcs.every(m => typeof obj[m] === 'function');
|
|
70
|
-
}
|
|
71
76
|
//# sourceMappingURL=index.js.map
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAkB,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGhD,+EAA+E;AAC/E,wBAAwB;AACxB,cAAc,kBAAkB,CAAA;AAShC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAE,OAA+B,EAAE;IACtE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,eAAe,EAAE,CAAA;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,gBAAgB,EAAE,CAAA;IAE5D,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC;QAC3B,GAAG,IAAI;QACP,SAAS;QACT,UAAU;QACV,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI;YACjC,gBAAgB,EAAE;SACnB;QACD,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI;YACvB,oBAAoB,CAAC,4BAA4B,CAAC;SACnD;KACF,CAAC,CAAA;IAEF,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A lightweight implementation of IPFS over HTTP in JavaScript",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/http#readme",
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ipfs/helia/issues"
|
|
13
13
|
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true
|
|
17
|
+
},
|
|
14
18
|
"keywords": [
|
|
15
19
|
"IPFS"
|
|
16
20
|
],
|
|
@@ -49,19 +53,19 @@
|
|
|
49
53
|
"test:electron-main": "aegir test -t electron-main"
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
52
|
-
"@helia/block-brokers": "
|
|
53
|
-
"@helia/
|
|
54
|
-
"@helia/
|
|
55
|
-
"@helia/
|
|
56
|
-
"@libp2p/interface": "^1.1.1",
|
|
56
|
+
"@helia/block-brokers": "^2.0.0",
|
|
57
|
+
"@helia/interface": "^4.0.0",
|
|
58
|
+
"@helia/routers": "^1.0.0",
|
|
59
|
+
"@helia/utils": "^0.0.1",
|
|
57
60
|
"blockstore-core": "^4.3.8",
|
|
58
|
-
"datastore-core": "^9.2.6"
|
|
59
|
-
"interface-blockstore": "^5.2.7",
|
|
60
|
-
"interface-datastore": "^8.2.9",
|
|
61
|
-
"libp2p": "^1.1.1",
|
|
62
|
-
"multiformats": "^13.0.0"
|
|
61
|
+
"datastore-core": "^9.2.6"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"
|
|
64
|
+
"@libp2p/interface": "^1.1.1",
|
|
65
|
+
"aegir": "^42.1.0",
|
|
66
|
+
"interface-datastore": "^8.2.10",
|
|
67
|
+
"multiformats": "^13.0.1",
|
|
68
|
+
"sinon": "^17.0.1",
|
|
69
|
+
"sinon-ts": "^2.0.0"
|
|
66
70
|
}
|
|
67
71
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exports a `createHeliaHTTP` function that returns an object that implements a lightweight version of the {@link Helia} API that functions only over HTTP.
|
|
5
5
|
*
|
|
6
|
+
* By default, content and peer routing are requests are resolved using the [Delegated HTTP Routing API](https://specs.ipfs.tech/routing/http-routing-v1/) and blocks are fetched from [Trustless Gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
|
|
7
|
+
*
|
|
6
8
|
* Pass it to other modules like {@link https://www.npmjs.com/package/@helia/unixfs | @helia/unixfs} to fetch files from the distributed web.
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
@@ -17,128 +19,65 @@
|
|
|
17
19
|
* const fs = unixfs(helia)
|
|
18
20
|
* fs.cat(CID.parse('bafyFoo'))
|
|
19
21
|
* ```
|
|
22
|
+
* @example with custom gateways and delegated routing endpoints
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { createHeliaHTTP } from '@helia/http'
|
|
25
|
+
* import { trustlessGateway } from '@helia/block-brokers'
|
|
26
|
+
* import { delegatedHTTPRouting } from '@helia/routers'
|
|
27
|
+
* import { unixfs } from '@helia/unixfs'
|
|
28
|
+
* import { CID } from 'multiformats/cid'
|
|
29
|
+
*
|
|
30
|
+
* const helia = await createHeliaHTTP({
|
|
31
|
+
* blockBrokers: [
|
|
32
|
+
* trustlessGateway({
|
|
33
|
+
* gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io'],
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* routers: [
|
|
37
|
+
* delegatedHTTPRouting('https://delegated-ipfs.dev')
|
|
38
|
+
* ]
|
|
39
|
+
* })
|
|
40
|
+
*
|
|
41
|
+
* const fs = unixfs(helia)
|
|
42
|
+
* fs.cat(CID.parse('bafyFoo'))
|
|
43
|
+
* ```
|
|
20
44
|
*/
|
|
21
45
|
|
|
22
46
|
import { trustlessGateway } from '@helia/block-brokers'
|
|
23
|
-
import {
|
|
47
|
+
import { delegatedHTTPRouting } from '@helia/routers'
|
|
48
|
+
import { Helia as HeliaClass, type HeliaInit } from '@helia/utils'
|
|
24
49
|
import { MemoryBlockstore } from 'blockstore-core'
|
|
25
50
|
import { MemoryDatastore } from 'datastore-core'
|
|
26
|
-
import {
|
|
27
|
-
import type { DefaultLibp2pServices } from './utils/libp2p-defaults.js'
|
|
28
|
-
import type { DAGWalker, Helia } from '@helia/interface'
|
|
29
|
-
import type { BlockBroker } from '@helia/interface/blocks'
|
|
30
|
-
import type { ComponentLogger, Libp2p } from '@libp2p/interface'
|
|
31
|
-
import type { Blockstore } from 'interface-blockstore'
|
|
32
|
-
import type { Datastore } from 'interface-datastore'
|
|
33
|
-
import type { Libp2pOptions } from 'libp2p'
|
|
34
|
-
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
51
|
+
import type { Helia } from '@helia/interface'
|
|
35
52
|
|
|
36
53
|
// re-export interface types so people don't have to depend on @helia/interface
|
|
37
54
|
// if they don't want to
|
|
38
55
|
export * from '@helia/interface'
|
|
39
|
-
export * from '@helia/interface/blocks'
|
|
40
|
-
export * from '@helia/interface/pins'
|
|
41
56
|
|
|
42
|
-
|
|
43
|
-
* Options used to create a Helia node.
|
|
44
|
-
*/
|
|
45
|
-
export interface HeliaHTTPInit<T extends Libp2p = Libp2p> {
|
|
57
|
+
export interface HeliaHTTPInit extends HeliaInit {
|
|
46
58
|
/**
|
|
47
|
-
*
|
|
48
|
-
* preconfigured node or options to configure a node can be passed
|
|
49
|
-
* here.
|
|
50
|
-
*
|
|
51
|
-
* If node options are passed, they will be merged with the default
|
|
52
|
-
* config for the current platform. In this case all passed config
|
|
53
|
-
* keys will replace those from the default config.
|
|
54
|
-
*/
|
|
55
|
-
libp2p?: T | Libp2pOptions
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The blockstore is where blocks are stored
|
|
59
|
-
*/
|
|
60
|
-
blockstore?: Blockstore
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The datastore is where data is stored
|
|
64
|
-
*/
|
|
65
|
-
datastore?: Datastore
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* By default sha256, sha512 and identity hashes are supported for
|
|
69
|
-
* bitswap operations. To bitswap blocks with CIDs using other hashes
|
|
70
|
-
* pass appropriate MultihashHashers here.
|
|
71
|
-
*/
|
|
72
|
-
hashers?: MultihashHasher[]
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* In order to pin CIDs that correspond to a DAG, it's necessary to know
|
|
76
|
-
* how to traverse that DAG. DAGWalkers take a block and yield any CIDs
|
|
77
|
-
* encoded within that block.
|
|
78
|
-
*/
|
|
79
|
-
dagWalkers?: DAGWalker[]
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* A list of strategies used to fetch blocks when they are not present in
|
|
83
|
-
* the local blockstore
|
|
84
|
-
*/
|
|
85
|
-
blockBrokers?: Array<(components: any) => BlockBroker>
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Pass `false` to not start the Helia node
|
|
59
|
+
* Whether to start the Helia node
|
|
89
60
|
*/
|
|
90
61
|
start?: boolean
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Garbage collection requires preventing blockstore writes during searches
|
|
94
|
-
* for unpinned blocks as DAGs are typically pinned after they've been
|
|
95
|
-
* imported - without locking this could lead to the deletion of blocks while
|
|
96
|
-
* they are being added to the blockstore.
|
|
97
|
-
*
|
|
98
|
-
* By default this lock is held on the main process (e.g. node cluster's
|
|
99
|
-
* primary process, the renderer thread in browsers) and other processes will
|
|
100
|
-
* contact the main process for access (worker processes in node cluster,
|
|
101
|
-
* webworkers in the browser).
|
|
102
|
-
*
|
|
103
|
-
* If Helia is being run wholly in a non-primary process, with no other process
|
|
104
|
-
* expected to access the blockstore (e.g. being run in the background in a
|
|
105
|
-
* webworker), pass true here to hold the gc lock in this process.
|
|
106
|
-
*/
|
|
107
|
-
holdGcLock?: boolean
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* An optional logging component to pass to libp2p. If not specified the
|
|
111
|
-
* default implementation from libp2p will be used.
|
|
112
|
-
*/
|
|
113
|
-
logger?: ComponentLogger
|
|
114
62
|
}
|
|
115
63
|
|
|
64
|
+
/**
|
|
116
65
|
/**
|
|
117
66
|
* Create and return a Helia node
|
|
118
67
|
*/
|
|
119
|
-
export async function createHeliaHTTP (init: HeliaHTTPInit = {}): Promise<Helia> {
|
|
68
|
+
export async function createHeliaHTTP (init: Partial<HeliaHTTPInit> = {}): Promise<Helia> {
|
|
120
69
|
const datastore = init.datastore ?? new MemoryDatastore()
|
|
121
70
|
const blockstore = init.blockstore ?? new MemoryBlockstore()
|
|
122
71
|
|
|
123
|
-
let libp2p: Libp2p<DefaultLibp2pServices>
|
|
124
|
-
|
|
125
|
-
if (isLibp2p(init.libp2p)) {
|
|
126
|
-
libp2p = init.libp2p as any
|
|
127
|
-
} else {
|
|
128
|
-
libp2p = await createLibp2p<DefaultLibp2pServices>({
|
|
129
|
-
...init,
|
|
130
|
-
libp2p: init.libp2p,
|
|
131
|
-
datastore
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
|
|
135
72
|
const helia = new HeliaClass({
|
|
136
73
|
...init,
|
|
137
|
-
libp2p,
|
|
138
74
|
datastore,
|
|
139
75
|
blockstore,
|
|
140
76
|
blockBrokers: init.blockBrokers ?? [
|
|
141
77
|
trustlessGateway()
|
|
78
|
+
],
|
|
79
|
+
routers: init.routers ?? [
|
|
80
|
+
delegatedHTTPRouting('https://delegated-ipfs.dev')
|
|
142
81
|
]
|
|
143
82
|
})
|
|
144
83
|
|
|
@@ -148,15 +87,3 @@ export async function createHeliaHTTP (init: HeliaHTTPInit = {}): Promise<Helia>
|
|
|
148
87
|
|
|
149
88
|
return helia
|
|
150
89
|
}
|
|
151
|
-
|
|
152
|
-
function isLibp2p (obj: any): obj is Libp2p {
|
|
153
|
-
if (obj == null) {
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// a non-exhaustive list of methods found on the libp2p object
|
|
158
|
-
const funcs = ['dial', 'dialProtocol', 'hangUp', 'handle', 'unhandle', 'getMultiaddrs', 'getProtocols']
|
|
159
|
-
|
|
160
|
-
// if these are all functions it's probably a libp2p object
|
|
161
|
-
return funcs.every(m => typeof obj[m] === 'function')
|
|
162
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Libp2pDefaultsOptions } from './libp2p.js';
|
|
2
|
-
import type { Libp2pOptions } from 'libp2p';
|
|
3
|
-
export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
4
|
-
delegatedRouting: unknown;
|
|
5
|
-
}
|
|
6
|
-
export declare function libp2pDefaults(options?: Libp2pDefaultsOptions): Libp2pOptions<DefaultLibp2pServices>;
|
|
7
|
-
//# sourceMappingURL=libp2p-defaults.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,gBAAgB,EAAE,OAAO,CAAA;CAC1B;AAED,wBAAgB,cAAc,CAAE,OAAO,GAAE,qBAA0B,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAUzG"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
|
|
2
|
-
export function libp2pDefaults(options = {}) {
|
|
3
|
-
return {
|
|
4
|
-
services: {
|
|
5
|
-
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
|
|
6
|
-
},
|
|
7
|
-
connectionManager: {
|
|
8
|
-
minConnections: 0
|
|
9
|
-
},
|
|
10
|
-
...options
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=libp2p-defaults.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,6CAA6C,CAAA;AAQnG,MAAM,UAAU,cAAc,CAAE,UAAiC,EAAE;IACjE,OAAO;QACL,QAAQ,EAAE;YACR,gBAAgB,EAAE,GAAG,EAAE,CAAC,qCAAqC,CAAC,4BAA4B,CAAC;SAC5F;QACD,iBAAiB,EAAE;YACjB,cAAc,EAAE,CAAC;SAClB;QACD,GAAG,OAAO;KACX,CAAA;AACH,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { DefaultLibp2pServices } from './libp2p-defaults.js';
|
|
2
|
-
import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface';
|
|
3
|
-
import type { Datastore } from 'interface-datastore';
|
|
4
|
-
import type { Libp2pOptions } from 'libp2p';
|
|
5
|
-
export interface CreateLibp2pOptions<T extends Record<string, unknown>> {
|
|
6
|
-
datastore: Datastore;
|
|
7
|
-
libp2p?: Libp2pOptions<T>;
|
|
8
|
-
logger?: ComponentLogger;
|
|
9
|
-
start?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface Libp2pDefaultsOptions {
|
|
12
|
-
peerId?: PeerId;
|
|
13
|
-
}
|
|
14
|
-
export declare function createLibp2p<T extends Record<string, unknown> = DefaultLibp2pServices>(options: CreateLibp2pOptions<T>): Promise<Libp2p<T>>;
|
|
15
|
-
//# sourceMappingURL=libp2p.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAE3C,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAsB,YAAY,CAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,qBAAqB,EAAG,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAUnJ"}
|
package/dist/src/utils/libp2p.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createLibp2p as create } from 'libp2p';
|
|
2
|
-
import { libp2pDefaults } from './libp2p-defaults.js';
|
|
3
|
-
export async function createLibp2p(options) {
|
|
4
|
-
const defaults = libp2pDefaults();
|
|
5
|
-
options = options ?? {};
|
|
6
|
-
// @ts-expect-error derived ServiceMap is not compatible with ServiceFactoryMap
|
|
7
|
-
return create({
|
|
8
|
-
...defaults,
|
|
9
|
-
...options.libp2p,
|
|
10
|
-
start: false
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=libp2p.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../../src/utils/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAiBrD,MAAM,CAAC,KAAK,UAAU,YAAY,CAA8D,OAA+B;IAC7H,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAA;IACjC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAA;IAEvB,+EAA+E;IAC/E,OAAO,MAAM,CAAC;QACZ,GAAG,QAAQ;QACX,GAAG,OAAO,CAAC,MAAM;QACjB,KAAK,EAAE,KAAK;KACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
|
|
2
|
-
import type { Libp2pDefaultsOptions } from './libp2p.js'
|
|
3
|
-
import type { Libp2pOptions } from 'libp2p'
|
|
4
|
-
|
|
5
|
-
export interface DefaultLibp2pServices extends Record<string, unknown> {
|
|
6
|
-
delegatedRouting: unknown
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
|
|
10
|
-
return {
|
|
11
|
-
services: {
|
|
12
|
-
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
|
|
13
|
-
},
|
|
14
|
-
connectionManager: {
|
|
15
|
-
minConnections: 0
|
|
16
|
-
},
|
|
17
|
-
...options
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/utils/libp2p.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createLibp2p as create } from 'libp2p'
|
|
2
|
-
import { libp2pDefaults } from './libp2p-defaults.js'
|
|
3
|
-
import type { DefaultLibp2pServices } from './libp2p-defaults.js'
|
|
4
|
-
import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface'
|
|
5
|
-
import type { Datastore } from 'interface-datastore'
|
|
6
|
-
import type { Libp2pOptions } from 'libp2p'
|
|
7
|
-
|
|
8
|
-
export interface CreateLibp2pOptions<T extends Record<string, unknown>> {
|
|
9
|
-
datastore: Datastore
|
|
10
|
-
libp2p?: Libp2pOptions<T>
|
|
11
|
-
logger?: ComponentLogger
|
|
12
|
-
start?: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Libp2pDefaultsOptions {
|
|
16
|
-
peerId?: PeerId
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function createLibp2p <T extends Record<string, unknown> = DefaultLibp2pServices> (options: CreateLibp2pOptions<T>): Promise<Libp2p<T>> {
|
|
20
|
-
const defaults = libp2pDefaults()
|
|
21
|
-
options = options ?? {}
|
|
22
|
-
|
|
23
|
-
// @ts-expect-error derived ServiceMap is not compatible with ServiceFactoryMap
|
|
24
|
-
return create({
|
|
25
|
-
...defaults,
|
|
26
|
-
...options.libp2p,
|
|
27
|
-
start: false
|
|
28
|
-
})
|
|
29
|
-
}
|