helia 1.2.0 → 1.2.2
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/dist/index.min.js +19 -19
- package/dist/src/helia.d.ts.map +1 -1
- package/dist/src/helia.js +6 -3
- package/dist/src/helia.js.map +1 -1
- package/dist/src/storage.d.ts +1 -4
- package/dist/src/storage.d.ts.map +1 -1
- package/dist/src/storage.js +2 -47
- package/dist/src/storage.js.map +1 -1
- package/dist/src/utils/networked-storage.d.ts +57 -0
- package/dist/src/utils/networked-storage.d.ts.map +1 -0
- package/dist/src/utils/networked-storage.js +108 -0
- package/dist/src/utils/networked-storage.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +2 -1
- package/src/helia.ts +7 -3
- package/src/storage.ts +3 -60
- package/src/utils/networked-storage.ts +146 -0
- package/src/version.ts +1 -1
package/dist/src/helia.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helia.d.ts","sourceRoot":"","sources":["../../src/helia.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"helia.d.ts","sourceRoot":"","sources":["../../src/helia.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAG3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,CAAA;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAMpD,UAAU,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACrE,MAAM,EAAE,CAAC,CAAA;IACT,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED,qBAAa,SAAU,YAAW,KAAK;;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,YAAY,CAAA;IACxB,SAAS,EAAE,SAAS,CAAA;IACpB,IAAI,EAAE,IAAI,CAAA;gBAIJ,IAAI,EAAE,aAAa;IAqC1B,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAOvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAKtB,EAAE,CAAE,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CA+BlD"}
|
package/dist/src/helia.js
CHANGED
|
@@ -7,6 +7,7 @@ import { CustomProgressEvent } from 'progress-events';
|
|
|
7
7
|
import { PinsImpl } from './pins.js';
|
|
8
8
|
import { BlockStorage } from './storage.js';
|
|
9
9
|
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.js';
|
|
10
|
+
import { NetworkedStorage } from './utils/networked-storage.js';
|
|
10
11
|
const log = logger('helia');
|
|
11
12
|
export class HeliaImpl {
|
|
12
13
|
libp2p;
|
|
@@ -34,10 +35,12 @@ export class HeliaImpl {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
|
-
|
|
38
|
+
const networkedStorage = new NetworkedStorage(init.blockstore, {
|
|
39
|
+
bitswap: this.#bitswap
|
|
40
|
+
});
|
|
41
|
+
this.pins = new PinsImpl(init.datastore, networkedStorage, init.dagWalkers ?? []);
|
|
38
42
|
this.libp2p = init.libp2p;
|
|
39
|
-
this.blockstore = new BlockStorage(
|
|
40
|
-
bitswap: this.#bitswap,
|
|
43
|
+
this.blockstore = new BlockStorage(networkedStorage, this.pins, {
|
|
41
44
|
holdGcLock: init.holdGcLock
|
|
42
45
|
});
|
|
43
46
|
this.datastore = init.datastore;
|
package/dist/src/helia.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helia.js","sourceRoot":"","sources":["../../src/helia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"helia.js","sourceRoot":"","sources":["../../src/helia.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAU/D,MAAM,GAAG,GAAG,MAAM,CAAC,OA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AAI,mBAAmB,CAAQ,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;qBAC5E;iBACF;YACH,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;SACP;gBAAS;YACR,WAAW,EAAE,CAAA;SACd;QAED,GAAG,CAAC,aAAa,CAAC,CAAA;IACpB,CAAC;CACF"}
|
package/dist/src/storage.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { type ProgressOptions } from 'progress-events';
|
|
2
1
|
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents } from '@helia/interface/blocks';
|
|
3
2
|
import type { Pins } from '@helia/interface/pins';
|
|
4
3
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
5
4
|
import type { Blockstore } from 'interface-blockstore';
|
|
6
5
|
import type { AwaitIterable } from 'interface-store';
|
|
7
|
-
import type { Bitswap } from 'ipfs-bitswap';
|
|
8
6
|
import type { Mortice } from 'mortice';
|
|
9
7
|
import type { CID } from 'multiformats/cid';
|
|
8
|
+
import type { ProgressOptions } from 'progress-events';
|
|
10
9
|
export interface BlockStorageInit {
|
|
11
10
|
holdGcLock?: boolean;
|
|
12
|
-
bitswap?: Bitswap;
|
|
13
11
|
}
|
|
14
12
|
export interface GetOptions extends AbortOptions {
|
|
15
13
|
progress?: (evt: Event) => void;
|
|
@@ -22,7 +20,6 @@ export interface GetOptions extends AbortOptions {
|
|
|
22
20
|
export declare class BlockStorage implements Blocks {
|
|
23
21
|
lock: Mortice;
|
|
24
22
|
private readonly child;
|
|
25
|
-
private readonly bitswap?;
|
|
26
23
|
private readonly pins;
|
|
27
24
|
/**
|
|
28
25
|
* Create a new BlockStorage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"
|
|
1
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,CAAC,GAAG,CAAC;IAU3H;;OAEG;IACK,OAAO,CAAE,MAAM,EAAE,aAAa,CAAC;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,UAAU,CAAA;KAAE,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAM,GAAG,aAAa,CAAC,GAAG,CAAC;IAUvK;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,sBAAsB,CAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAU/G;;OAEG;IACK,OAAO,CAAE,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAM,GAAG,aAAa,CAAC,IAAI,CAAC;IAU1I;;OAEG;IACG,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,yBAAyB,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc/G;;OAEG;IACK,UAAU,CAAE,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,8BAA8B,CAAM,GAAG,aAAa,CAAC,GAAG,CAAC;IAoBzI,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAU1D,MAAM,CAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,0BAA0B,CAAM,GAAG,aAAa,CAAC,IAAI,CAAC;CAS/G"}
|
package/dist/src/storage.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import filter from 'it-filter';
|
|
2
|
-
import forEach from 'it-foreach';
|
|
3
1
|
import createMortice from 'mortice';
|
|
4
|
-
import { CustomProgressEvent } from 'progress-events';
|
|
5
2
|
/**
|
|
6
3
|
* BlockStorage is a hybrid blockstore that puts/gets blocks from a configured
|
|
7
4
|
* blockstore (that may be on disk, s3, or something else). If the blocks are
|
|
@@ -10,14 +7,12 @@ import { CustomProgressEvent } from 'progress-events';
|
|
|
10
7
|
export class BlockStorage {
|
|
11
8
|
lock;
|
|
12
9
|
child;
|
|
13
|
-
bitswap;
|
|
14
10
|
pins;
|
|
15
11
|
/**
|
|
16
12
|
* Create a new BlockStorage
|
|
17
13
|
*/
|
|
18
14
|
constructor(blockstore, pins, options = {}) {
|
|
19
15
|
this.child = blockstore;
|
|
20
|
-
this.bitswap = options.bitswap;
|
|
21
16
|
this.pins = pins;
|
|
22
17
|
this.lock = createMortice({
|
|
23
18
|
singleProcess: options.holdGcLock
|
|
@@ -32,15 +27,6 @@ export class BlockStorage {
|
|
|
32
27
|
async put(cid, block, options = {}) {
|
|
33
28
|
const releaseLock = await this.lock.readLock();
|
|
34
29
|
try {
|
|
35
|
-
if (await this.child.has(cid)) {
|
|
36
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put:duplicate', cid));
|
|
37
|
-
return cid;
|
|
38
|
-
}
|
|
39
|
-
if (this.bitswap?.isStarted() === true) {
|
|
40
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put:bitswap:notify', cid));
|
|
41
|
-
this.bitswap.notify(cid, block, options);
|
|
42
|
-
}
|
|
43
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put:blockstore:put', cid));
|
|
44
30
|
return await this.child.put(cid, block, options);
|
|
45
31
|
}
|
|
46
32
|
finally {
|
|
@@ -53,19 +39,7 @@ export class BlockStorage {
|
|
|
53
39
|
async *putMany(blocks, options = {}) {
|
|
54
40
|
const releaseLock = await this.lock.readLock();
|
|
55
41
|
try {
|
|
56
|
-
|
|
57
|
-
const has = await this.child.has(cid);
|
|
58
|
-
if (has) {
|
|
59
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put-many:duplicate', cid));
|
|
60
|
-
}
|
|
61
|
-
return !has;
|
|
62
|
-
});
|
|
63
|
-
const notifyEach = forEach(missingBlocks, ({ cid, block }) => {
|
|
64
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put-many:bitswap:notify', cid));
|
|
65
|
-
this.bitswap?.notify(cid, block, options);
|
|
66
|
-
});
|
|
67
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put-many:blockstore:put-many'));
|
|
68
|
-
yield* this.child.putMany(notifyEach, options);
|
|
42
|
+
yield* this.child.putMany(blocks, options);
|
|
69
43
|
}
|
|
70
44
|
finally {
|
|
71
45
|
releaseLock();
|
|
@@ -77,14 +51,6 @@ export class BlockStorage {
|
|
|
77
51
|
async get(cid, options = {}) {
|
|
78
52
|
const releaseLock = await this.lock.readLock();
|
|
79
53
|
try {
|
|
80
|
-
if (this.bitswap?.isStarted() != null && !(await this.child.has(cid))) {
|
|
81
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get:bitswap:get', cid));
|
|
82
|
-
const block = await this.bitswap.want(cid, options);
|
|
83
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get:blockstore:put', cid));
|
|
84
|
-
await this.child.put(cid, block, options);
|
|
85
|
-
return block;
|
|
86
|
-
}
|
|
87
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get:blockstore:get', cid));
|
|
88
54
|
return await this.child.get(cid, options);
|
|
89
55
|
}
|
|
90
56
|
finally {
|
|
@@ -97,15 +63,7 @@ export class BlockStorage {
|
|
|
97
63
|
async *getMany(cids, options = {}) {
|
|
98
64
|
const releaseLock = await this.lock.readLock();
|
|
99
65
|
try {
|
|
100
|
-
|
|
101
|
-
yield* this.child.getMany(forEach(cids, async (cid) => {
|
|
102
|
-
if (this.bitswap?.isStarted() === true && !(await this.child.has(cid))) {
|
|
103
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get-many:bitswap:get', cid));
|
|
104
|
-
const block = await this.bitswap.want(cid, options);
|
|
105
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get-many:blockstore:put', cid));
|
|
106
|
-
await this.child.put(cid, block, options);
|
|
107
|
-
}
|
|
108
|
-
}));
|
|
66
|
+
yield* this.child.getMany(cids, options);
|
|
109
67
|
}
|
|
110
68
|
finally {
|
|
111
69
|
releaseLock();
|
|
@@ -120,7 +78,6 @@ export class BlockStorage {
|
|
|
120
78
|
if (await this.pins.isPinned(cid)) {
|
|
121
79
|
throw new Error('CID was pinned');
|
|
122
80
|
}
|
|
123
|
-
options.onProgress?.(new CustomProgressEvent('blocks:delete:blockstore:delete', cid));
|
|
124
81
|
await this.child.delete(cid, options);
|
|
125
82
|
}
|
|
126
83
|
finally {
|
|
@@ -134,7 +91,6 @@ export class BlockStorage {
|
|
|
134
91
|
const releaseLock = await this.lock.writeLock();
|
|
135
92
|
try {
|
|
136
93
|
const storage = this;
|
|
137
|
-
options.onProgress?.(new CustomProgressEvent('blocks:delete-many:blockstore:delete-many'));
|
|
138
94
|
yield* this.child.deleteMany((async function* () {
|
|
139
95
|
for await (const cid of cids) {
|
|
140
96
|
if (await storage.pins.isPinned(cid)) {
|
|
@@ -160,7 +116,6 @@ export class BlockStorage {
|
|
|
160
116
|
async *getAll(options = {}) {
|
|
161
117
|
const releaseLock = await this.lock.readLock();
|
|
162
118
|
try {
|
|
163
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get-all:blockstore:get-many'));
|
|
164
119
|
yield* this.child.getAll(options);
|
|
165
120
|
}
|
|
166
121
|
finally {
|
package/dist/src/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,SAAS,CAAA;AAkBnC;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAChB,IAAI,CAAS;IACH,KAAK,CAAY;IACjB,IAAI,CAAM;IAE3B;;OAEG;IACH,YAAa,UAAsB,EAAE,IAAU,EAAE,UAA4B,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SACd;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAQ,EAAE,UAAwB,EAAE;QAC7C,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAE9C,IAAI;YACF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;SAC1C;gBAAS;YACR,WAAW,EAAE,CAAA;SACd;IACH,CAAC;IAED,KAAK,CAAC,CAAE,MAAM,CAAE,UAAsE,EAAE;QACtF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAE9C,IAAI;YACF,KAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;SACnC;gBAAS;YACR,WAAW,EAAE,CAAA;SACd;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ProgressOptions } from 'progress-events';
|
|
2
|
+
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents } from '@helia/interface/blocks';
|
|
3
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
4
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
5
|
+
import type { AwaitIterable } from 'interface-store';
|
|
6
|
+
import type { Bitswap } from 'ipfs-bitswap';
|
|
7
|
+
import type { CID } from 'multiformats/cid';
|
|
8
|
+
export interface BlockStorageInit {
|
|
9
|
+
holdGcLock?: boolean;
|
|
10
|
+
bitswap?: Bitswap;
|
|
11
|
+
}
|
|
12
|
+
export interface GetOptions extends AbortOptions {
|
|
13
|
+
progress?: (evt: Event) => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Networked storage wraps a regular blockstore - when getting blocks if the
|
|
17
|
+
* blocks are not present Bitswap will be used to fetch them from network peers.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NetworkedStorage implements Blocks {
|
|
20
|
+
private readonly child;
|
|
21
|
+
private readonly bitswap?;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new BlockStorage
|
|
24
|
+
*/
|
|
25
|
+
constructor(blockstore: Blockstore, options?: BlockStorageInit);
|
|
26
|
+
unwrap(): Blockstore;
|
|
27
|
+
/**
|
|
28
|
+
* Put a block to the underlying datastore
|
|
29
|
+
*/
|
|
30
|
+
put(cid: CID, block: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>): Promise<CID>;
|
|
31
|
+
/**
|
|
32
|
+
* Put a multiple blocks to the underlying datastore
|
|
33
|
+
*/
|
|
34
|
+
putMany(blocks: AwaitIterable<{
|
|
35
|
+
cid: CID;
|
|
36
|
+
block: Uint8Array;
|
|
37
|
+
}>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): AsyncIterable<CID>;
|
|
38
|
+
/**
|
|
39
|
+
* Get a block by cid
|
|
40
|
+
*/
|
|
41
|
+
get(cid: CID, options?: AbortOptions & ProgressOptions<GetBlockProgressEvents>): Promise<Uint8Array>;
|
|
42
|
+
/**
|
|
43
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
44
|
+
*/
|
|
45
|
+
getMany(cids: AwaitIterable<CID>, options?: AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>): AsyncIterable<Pair>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a block from the blockstore
|
|
48
|
+
*/
|
|
49
|
+
delete(cid: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Delete multiple blocks from the blockstore
|
|
52
|
+
*/
|
|
53
|
+
deleteMany(cids: AwaitIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>): AsyncIterable<CID>;
|
|
54
|
+
has(cid: CID, options?: AbortOptions): Promise<boolean>;
|
|
55
|
+
getAll(options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>): AsyncIterable<Pair>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=networked-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networked-storage.d.ts","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAC5P,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;CAChC;AAED;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,MAAM;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAS;IAElC;;OAEG;gBACU,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,gBAAqB;IAKnE,MAAM,IAAK,UAAU;IAIrB;;OAEG;IACG,GAAG,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omProgressEvent } from 'progress-events';
|
|
4
|
+
/**
|
|
5
|
+
* Networked storage wraps a regular blockstore - when getting blocks if the
|
|
6
|
+
* blocks are not present Bitswap will be used to fetch them from network peers.
|
|
7
|
+
*/
|
|
8
|
+
export class NetworkedStorage {
|
|
9
|
+
child;
|
|
10
|
+
bitswap;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new BlockStorage
|
|
13
|
+
*/
|
|
14
|
+
constructor(blockstore, options = {}) {
|
|
15
|
+
this.child = blockstore;
|
|
16
|
+
this.bitswap = options.bitswap;
|
|
17
|
+
}
|
|
18
|
+
unwrap() {
|
|
19
|
+
return this.child;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Put a block to the underlying datastore
|
|
23
|
+
*/
|
|
24
|
+
async put(cid, block, options = {}) {
|
|
25
|
+
if (await this.child.has(cid)) {
|
|
26
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put:duplicate', cid));
|
|
27
|
+
return cid;
|
|
28
|
+
}
|
|
29
|
+
if (this.bitswap?.isStarted() === true) {
|
|
30
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put:bitswap:notify', cid));
|
|
31
|
+
this.bitswap.notify(cid, block, options);
|
|
32
|
+
}
|
|
33
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put:blockstore:put', cid));
|
|
34
|
+
return this.child.put(cid, block, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Put a multiple blocks to the underlying datastore
|
|
38
|
+
*/
|
|
39
|
+
async *putMany(blocks, options = {}) {
|
|
40
|
+
const missingBlocks = filter(blocks, async ({ cid }) => {
|
|
41
|
+
const has = await this.child.has(cid);
|
|
42
|
+
if (has) {
|
|
43
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put-many:duplicate', cid));
|
|
44
|
+
}
|
|
45
|
+
return !has;
|
|
46
|
+
});
|
|
47
|
+
const notifyEach = forEach(missingBlocks, ({ cid, block }) => {
|
|
48
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put-many:bitswap:notify', cid));
|
|
49
|
+
this.bitswap?.notify(cid, block, options);
|
|
50
|
+
});
|
|
51
|
+
options.onProgress?.(new CustomProgressEvent('blocks:put-many:blockstore:put-many'));
|
|
52
|
+
yield* this.child.putMany(notifyEach, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get a block by cid
|
|
56
|
+
*/
|
|
57
|
+
async get(cid, options = {}) {
|
|
58
|
+
if (this.bitswap?.isStarted() != null && !(await this.child.has(cid))) {
|
|
59
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get:bitswap:get', cid));
|
|
60
|
+
const block = await this.bitswap.want(cid, options);
|
|
61
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get:blockstore:put', cid));
|
|
62
|
+
await this.child.put(cid, block, options);
|
|
63
|
+
return block;
|
|
64
|
+
}
|
|
65
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get:blockstore:get', cid));
|
|
66
|
+
return this.child.get(cid, options);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get multiple blocks back from an (async) iterable of cids
|
|
70
|
+
*/
|
|
71
|
+
async *getMany(cids, options = {}) {
|
|
72
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get-many:blockstore:get-many'));
|
|
73
|
+
yield* this.child.getMany(forEach(cids, async (cid) => {
|
|
74
|
+
if (this.bitswap?.isStarted() === true && !(await this.child.has(cid))) {
|
|
75
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get-many:bitswap:get', cid));
|
|
76
|
+
const block = await this.bitswap.want(cid, options);
|
|
77
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get-many:blockstore:put', cid));
|
|
78
|
+
await this.child.put(cid, block, options);
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Delete a block from the blockstore
|
|
84
|
+
*/
|
|
85
|
+
async delete(cid, options = {}) {
|
|
86
|
+
options.onProgress?.(new CustomProgressEvent('blocks:delete:blockstore:delete', cid));
|
|
87
|
+
await this.child.delete(cid, options);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete multiple blocks from the blockstore
|
|
91
|
+
*/
|
|
92
|
+
async *deleteMany(cids, options = {}) {
|
|
93
|
+
options.onProgress?.(new CustomProgressEvent('blocks:delete-many:blockstore:delete-many'));
|
|
94
|
+
yield* this.child.deleteMany((async function* () {
|
|
95
|
+
for await (const cid of cids) {
|
|
96
|
+
yield cid;
|
|
97
|
+
}
|
|
98
|
+
}()), options);
|
|
99
|
+
}
|
|
100
|
+
async has(cid, options = {}) {
|
|
101
|
+
return this.child.has(cid, options);
|
|
102
|
+
}
|
|
103
|
+
async *getAll(options = {}) {
|
|
104
|
+
options.onProgress?.(new CustomProgressEvent('blocks:get-all:blockstore:get-many'));
|
|
105
|
+
yield* this.child.getAll(options);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=networked-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networked-storage.js","sourceRoot":"","sources":["../../../src/utils/networked-storage.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAwB,MAAM,iBAAiB,CAAA;AAiB3E;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACV,KAAK,CAAY;IACjB,OAAO,CAAU;IAElC;;OAEG;IACH,YAAa,UAAsB,EAAE,UAA4B,EAAE;QACjE,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IAChC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAE,GAAQ,EAAE,KAAiB,EAAE,UAAkE,EAAE;QAC1G,IA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AAC;YAC7C,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,EAAE;gBAC5B,MAAM,GAAG,CAAA;aACV;QACH,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAQ,EAAE,UAAwB,EAAE;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,CAAE,MAAM,CAAE,UAAsE,EAAE;QACtF,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAC,oCAAoC,CAAC,CAAC,CAAA;QACnF,KAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;CACF"}
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "helia",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "An implementation of IPFS in JavaScript",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/master/packages/helia#readme",
|
|
@@ -180,6 +180,7 @@
|
|
|
180
180
|
"devDependencies": {
|
|
181
181
|
"@ipld/dag-cbor": "^9.0.0",
|
|
182
182
|
"@ipld/dag-json": "^10.0.1",
|
|
183
|
+
"@multiformats/mafmt": "^12.1.5",
|
|
183
184
|
"@types/sinon": "^10.0.14",
|
|
184
185
|
"aegir": "^39.0.4",
|
|
185
186
|
"delay": "^6.0.0",
|
package/src/helia.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { CustomProgressEvent } from 'progress-events'
|
|
|
7
7
|
import { PinsImpl } from './pins.js'
|
|
8
8
|
import { BlockStorage } from './storage.js'
|
|
9
9
|
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.js'
|
|
10
|
+
import { NetworkedStorage } from './utils/networked-storage.js'
|
|
10
11
|
import type { HeliaInit } from '.'
|
|
11
12
|
import type { GCOptions, Helia } from '@helia/interface'
|
|
12
13
|
import type { Pins } from '@helia/interface/pins'
|
|
@@ -56,11 +57,14 @@ export class HeliaImpl implements Helia {
|
|
|
56
57
|
}
|
|
57
58
|
})
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
const networkedStorage = new NetworkedStorage(init.blockstore, {
|
|
61
|
+
bitswap: this.#bitswap
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
this.pins = new PinsImpl(init.datastore, networkedStorage, init.dagWalkers ?? [])
|
|
60
65
|
|
|
61
66
|
this.libp2p = init.libp2p
|
|
62
|
-
this.blockstore = new BlockStorage(
|
|
63
|
-
bitswap: this.#bitswap,
|
|
67
|
+
this.blockstore = new BlockStorage(networkedStorage, this.pins, {
|
|
64
68
|
holdGcLock: init.holdGcLock
|
|
65
69
|
})
|
|
66
70
|
this.datastore = init.datastore
|
package/src/storage.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import filter from 'it-filter'
|
|
2
|
-
import forEach from 'it-foreach'
|
|
3
1
|
import createMortice from 'mortice'
|
|
4
|
-
import { CustomProgressEvent, type ProgressOptions } from 'progress-events'
|
|
5
2
|
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents } from '@helia/interface/blocks'
|
|
6
3
|
import type { Pins } from '@helia/interface/pins'
|
|
7
4
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
5
|
import type { Blockstore } from 'interface-blockstore'
|
|
9
6
|
import type { AwaitIterable } from 'interface-store'
|
|
10
|
-
import type { Bitswap } from 'ipfs-bitswap'
|
|
11
7
|
import type { Mortice } from 'mortice'
|
|
12
8
|
import type { CID } from 'multiformats/cid'
|
|
9
|
+
import type { ProgressOptions } from 'progress-events'
|
|
13
10
|
|
|
14
11
|
export interface BlockStorageInit {
|
|
15
12
|
holdGcLock?: boolean
|
|
16
|
-
bitswap?: Bitswap
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
export interface GetOptions extends AbortOptions {
|
|
@@ -28,7 +24,6 @@ export interface GetOptions extends AbortOptions {
|
|
|
28
24
|
export class BlockStorage implements Blocks {
|
|
29
25
|
public lock: Mortice
|
|
30
26
|
private readonly child: Blockstore
|
|
31
|
-
private readonly bitswap?: Bitswap
|
|
32
27
|
private readonly pins: Pins
|
|
33
28
|
|
|
34
29
|
/**
|
|
@@ -36,7 +31,6 @@ export class BlockStorage implements Blocks {
|
|
|
36
31
|
*/
|
|
37
32
|
constructor (blockstore: Blockstore, pins: Pins, options: BlockStorageInit = {}) {
|
|
38
33
|
this.child = blockstore
|
|
39
|
-
this.bitswap = options.bitswap
|
|
40
34
|
this.pins = pins
|
|
41
35
|
this.lock = createMortice({
|
|
42
36
|
singleProcess: options.holdGcLock
|
|
@@ -54,18 +48,6 @@ export class BlockStorage implements Blocks {
|
|
|
54
48
|
const releaseLock = await this.lock.readLock()
|
|
55
49
|
|
|
56
50
|
try {
|
|
57
|
-
if (await this.child.has(cid)) {
|
|
58
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put:duplicate', cid))
|
|
59
|
-
return cid
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (this.bitswap?.isStarted() === true) {
|
|
63
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put:bitswap:notify', cid))
|
|
64
|
-
this.bitswap.notify(cid, block, options)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put:blockstore:put', cid))
|
|
68
|
-
|
|
69
51
|
return await this.child.put(cid, block, options)
|
|
70
52
|
} finally {
|
|
71
53
|
releaseLock()
|
|
@@ -79,23 +61,7 @@ export class BlockStorage implements Blocks {
|
|
|
79
61
|
const releaseLock = await this.lock.readLock()
|
|
80
62
|
|
|
81
63
|
try {
|
|
82
|
-
|
|
83
|
-
const has = await this.child.has(cid)
|
|
84
|
-
|
|
85
|
-
if (has) {
|
|
86
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put-many:duplicate', cid))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return !has
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const notifyEach = forEach(missingBlocks, ({ cid, block }): void => {
|
|
93
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put-many:bitswap:notify', cid))
|
|
94
|
-
this.bitswap?.notify(cid, block, options)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
options.onProgress?.(new CustomProgressEvent('blocks:put-many:blockstore:put-many'))
|
|
98
|
-
yield * this.child.putMany(notifyEach, options)
|
|
64
|
+
yield * this.child.putMany(blocks, options)
|
|
99
65
|
} finally {
|
|
100
66
|
releaseLock()
|
|
101
67
|
}
|
|
@@ -108,18 +74,6 @@ export class BlockStorage implements Blocks {
|
|
|
108
74
|
const releaseLock = await this.lock.readLock()
|
|
109
75
|
|
|
110
76
|
try {
|
|
111
|
-
if (this.bitswap?.isStarted() != null && !(await this.child.has(cid))) {
|
|
112
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get:bitswap:get', cid))
|
|
113
|
-
const block = await this.bitswap.want(cid, options)
|
|
114
|
-
|
|
115
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get:blockstore:put', cid))
|
|
116
|
-
await this.child.put(cid, block, options)
|
|
117
|
-
|
|
118
|
-
return block
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get:blockstore:get', cid))
|
|
122
|
-
|
|
123
77
|
return await this.child.get(cid, options)
|
|
124
78
|
} finally {
|
|
125
79
|
releaseLock()
|
|
@@ -133,15 +87,7 @@ export class BlockStorage implements Blocks {
|
|
|
133
87
|
const releaseLock = await this.lock.readLock()
|
|
134
88
|
|
|
135
89
|
try {
|
|
136
|
-
|
|
137
|
-
yield * this.child.getMany(forEach(cids, async (cid): Promise<void> => {
|
|
138
|
-
if (this.bitswap?.isStarted() === true && !(await this.child.has(cid))) {
|
|
139
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get-many:bitswap:get', cid))
|
|
140
|
-
const block = await this.bitswap.want(cid, options)
|
|
141
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get-many:blockstore:put', cid))
|
|
142
|
-
await this.child.put(cid, block, options)
|
|
143
|
-
}
|
|
144
|
-
}))
|
|
90
|
+
yield * this.child.getMany(cids, options)
|
|
145
91
|
} finally {
|
|
146
92
|
releaseLock()
|
|
147
93
|
}
|
|
@@ -158,7 +104,6 @@ export class BlockStorage implements Blocks {
|
|
|
158
104
|
throw new Error('CID was pinned')
|
|
159
105
|
}
|
|
160
106
|
|
|
161
|
-
options.onProgress?.(new CustomProgressEvent<CID>('blocks:delete:blockstore:delete', cid))
|
|
162
107
|
await this.child.delete(cid, options)
|
|
163
108
|
} finally {
|
|
164
109
|
releaseLock()
|
|
@@ -174,7 +119,6 @@ export class BlockStorage implements Blocks {
|
|
|
174
119
|
try {
|
|
175
120
|
const storage = this
|
|
176
121
|
|
|
177
|
-
options.onProgress?.(new CustomProgressEvent('blocks:delete-many:blockstore:delete-many'))
|
|
178
122
|
yield * this.child.deleteMany((async function * (): AsyncGenerator<CID> {
|
|
179
123
|
for await (const cid of cids) {
|
|
180
124
|
if (await storage.pins.isPinned(cid)) {
|
|
@@ -203,7 +147,6 @@ export class BlockStorage implements Blocks {
|
|
|
203
147
|
const releaseLock = await this.lock.readLock()
|
|
204
148
|
|
|
205
149
|
try {
|
|
206
|
-
options.onProgress?.(new CustomProgressEvent('blocks:get-all:blockstore:get-many'))
|
|
207
150
|
yield * this.child.getAll(options)
|
|
208
151
|
} finally {
|
|
209
152
|
releaseLock()
|