@helia/utils 2.5.2-1361bfa5 → 2.5.2-16d805e1

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.
Files changed (77) hide show
  1. package/dist/index.min.js +1 -22
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/index.d.ts +5 -171
  4. package/dist/src/index.d.ts.map +1 -1
  5. package/dist/src/index.js +5 -162
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/is-cid.d.ts.map +1 -0
  8. package/dist/src/is-cid.js.map +1 -0
  9. package/dist/src/is-promise.d.ts.map +1 -0
  10. package/dist/src/is-promise.js.map +1 -0
  11. package/package.json +7 -24
  12. package/src/index.ts +5 -368
  13. package/dist/src/pins.d.ts +0 -21
  14. package/dist/src/pins.d.ts.map +0 -1
  15. package/dist/src/pins.js +0 -141
  16. package/dist/src/pins.js.map +0 -1
  17. package/dist/src/routing.d.ts +0 -51
  18. package/dist/src/routing.d.ts.map +0 -1
  19. package/dist/src/routing.js +0 -311
  20. package/dist/src/routing.js.map +0 -1
  21. package/dist/src/storage.d.ts +0 -62
  22. package/dist/src/storage.d.ts.map +0 -1
  23. package/dist/src/storage.js +0 -159
  24. package/dist/src/storage.js.map +0 -1
  25. package/dist/src/utils/constants.d.ts +0 -4
  26. package/dist/src/utils/constants.d.ts.map +0 -1
  27. package/dist/src/utils/constants.js +0 -4
  28. package/dist/src/utils/constants.js.map +0 -1
  29. package/dist/src/utils/datastore-version.d.ts +0 -3
  30. package/dist/src/utils/datastore-version.d.ts.map +0 -1
  31. package/dist/src/utils/datastore-version.js +0 -20
  32. package/dist/src/utils/datastore-version.js.map +0 -1
  33. package/dist/src/utils/get-codec.d.ts +0 -4
  34. package/dist/src/utils/get-codec.d.ts.map +0 -1
  35. package/dist/src/utils/get-codec.js +0 -37
  36. package/dist/src/utils/get-codec.js.map +0 -1
  37. package/dist/src/utils/get-crypto.d.ts +0 -4
  38. package/dist/src/utils/get-crypto.d.ts.map +0 -1
  39. package/dist/src/utils/get-crypto.js +0 -35
  40. package/dist/src/utils/get-crypto.js.map +0 -1
  41. package/dist/src/utils/get-hasher.d.ts +0 -4
  42. package/dist/src/utils/get-hasher.d.ts.map +0 -1
  43. package/dist/src/utils/get-hasher.js +0 -32
  44. package/dist/src/utils/get-hasher.js.map +0 -1
  45. package/dist/src/utils/is-cid.d.ts.map +0 -1
  46. package/dist/src/utils/is-cid.js.map +0 -1
  47. package/dist/src/utils/is-promise.d.ts.map +0 -1
  48. package/dist/src/utils/is-promise.js.map +0 -1
  49. package/dist/src/utils/networked-storage.d.ts +0 -28
  50. package/dist/src/utils/networked-storage.d.ts.map +0 -1
  51. package/dist/src/utils/networked-storage.js +0 -52
  52. package/dist/src/utils/networked-storage.js.map +0 -1
  53. package/dist/src/utils/session-storage.d.ts +0 -47
  54. package/dist/src/utils/session-storage.d.ts.map +0 -1
  55. package/dist/src/utils/session-storage.js +0 -148
  56. package/dist/src/utils/session-storage.js.map +0 -1
  57. package/dist/src/utils/storage.d.ts +0 -55
  58. package/dist/src/utils/storage.d.ts.map +0 -1
  59. package/dist/src/utils/storage.js +0 -225
  60. package/dist/src/utils/storage.js.map +0 -1
  61. package/src/pins.ts +0 -209
  62. package/src/routing.ts +0 -389
  63. package/src/storage.ts +0 -194
  64. package/src/utils/constants.ts +0 -3
  65. package/src/utils/datastore-version.ts +0 -25
  66. package/src/utils/get-codec.ts +0 -45
  67. package/src/utils/get-crypto.ts +0 -44
  68. package/src/utils/get-hasher.ts +0 -40
  69. package/src/utils/networked-storage.ts +0 -74
  70. package/src/utils/session-storage.ts +0 -174
  71. package/src/utils/storage.ts +0 -294
  72. /package/dist/src/{utils/is-cid.d.ts → is-cid.d.ts} +0 -0
  73. /package/dist/src/{utils/is-cid.js → is-cid.js} +0 -0
  74. /package/dist/src/{utils/is-promise.d.ts → is-promise.d.ts} +0 -0
  75. /package/dist/src/{utils/is-promise.js → is-promise.js} +0 -0
  76. /package/src/{utils/is-cid.ts → is-cid.ts} +0 -0
  77. /package/src/{utils/is-promise.ts → is-promise.ts} +0 -0
@@ -1,311 +0,0 @@
1
- import { NoRoutersAvailableError } from '@helia/interface';
2
- import { NotFoundError, start, stop } from '@libp2p/interface';
3
- import { Queue } from '@libp2p/utils';
4
- import merge from 'it-merge';
5
- import { CustomProgressEvent } from 'progress-events';
6
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
7
- import { GetFailedError } from "./errors.js";
8
- const DEFAULT_PROVIDER_LOOKUP_CONCURRENCY = 5;
9
- export class Routing {
10
- name;
11
- log;
12
- routers;
13
- providerLookupConcurrency;
14
- constructor(components, init) {
15
- this.name = 'helia';
16
- this.log = components.logger.forComponent('helia:routing');
17
- this.routers = init.routers ?? [];
18
- this.providerLookupConcurrency = init.providerLookupConcurrency ?? DEFAULT_PROVIDER_LOOKUP_CONCURRENCY;
19
- this.findProviders = components.metrics?.traceFunction('helia.routing.findProviders', this.findProviders.bind(this), {
20
- optionsIndex: 1
21
- }) ?? this.findProviders;
22
- this.provide = components.metrics?.traceFunction('helia.routing.provide', this.provide.bind(this), {
23
- optionsIndex: 1
24
- }) ?? this.provide;
25
- this.cancelReprovide = components.metrics?.traceFunction('helia.routing.cancelReprovide', this.cancelReprovide.bind(this), {
26
- optionsIndex: 1
27
- }) ?? this.cancelReprovide;
28
- this.put = components.metrics?.traceFunction('helia.routing.put', this.put.bind(this), {
29
- optionsIndex: 2
30
- }) ?? this.put;
31
- this.get = components.metrics?.traceFunction('helia.routing.get', this.get.bind(this), {
32
- optionsIndex: 1
33
- }) ?? this.get;
34
- this.findPeer = components.metrics?.traceFunction('helia.routing.findPeer', this.findPeer.bind(this), {
35
- optionsIndex: 1
36
- }) ?? this.findPeer;
37
- this.getClosestPeers = components.metrics?.traceFunction('helia.routing.getClosestPeers', this.getClosestPeers.bind(this), {
38
- optionsIndex: 1
39
- }) ?? this.getClosestPeers;
40
- }
41
- async start() {
42
- await start(...this.routers);
43
- }
44
- async stop() {
45
- await stop(...this.routers);
46
- }
47
- hasRouter(name) {
48
- return this.routers.findIndex(r => r.name === name) !== -1;
49
- }
50
- addRouter(router) {
51
- this.routers.push(router);
52
- }
53
- /**
54
- * Iterates over all content routers in parallel to find providers of the
55
- * given key
56
- */
57
- async *findProviders(key, options = {}) {
58
- if (this.routers.length === 0) {
59
- throw new NoRoutersAvailableError('No content routers available');
60
- }
61
- // provider multiaddrs are only cached for a limited time, so they can come
62
- // back as an empty array - when this happens we have to do a FIND_PEER
63
- // query to get updated addresses, but we shouldn't block on this so use a
64
- // separate bounded queue to perform this lookup
65
- const queue = new Queue({
66
- concurrency: this.providerLookupConcurrency
67
- });
68
- let foundProviders = 0;
69
- const errors = [];
70
- const self = this;
71
- let routersFinished = 0;
72
- this.log('findProviders for %c start using routers %s', key, this.routers.map(r => r.toString()).join(', '));
73
- const routers = supports(this.routers, 'findProviders')
74
- .map(async function* (router) {
75
- let foundProviders = 0;
76
- options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:start', {
77
- routing: router.name,
78
- cid: key
79
- }));
80
- try {
81
- for await (const prov of router.findProviders(key, options)) {
82
- foundProviders++;
83
- // @ts-expect-error router.name is a string, needs to be specific
84
- options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:provider', {
85
- routing: router.name,
86
- cid: key,
87
- provider: prov
88
- }));
89
- yield prov;
90
- }
91
- }
92
- catch (err) {
93
- errors.push(err);
94
- }
95
- finally {
96
- self.log('router %s found %d providers for %c', router, foundProviders, key);
97
- options?.onProgress?.(new CustomProgressEvent('helia:routing:find-providers:end', {
98
- routing: router.name,
99
- cid: key,
100
- found: foundProviders
101
- }));
102
- routersFinished++;
103
- // if all routers have finished and there are no jobs to find updated
104
- // peer multiaddres running or queued, cause the generator to exit
105
- if (routersFinished === routers.length && queue.size === 0) {
106
- queue.emitIdle();
107
- }
108
- }
109
- });
110
- for await (const peer of merge(queue.toGenerator(), ...routers)) {
111
- // the peer was yielded by a content router without multiaddrs and we
112
- // failed to load them
113
- if (peer == null) {
114
- continue;
115
- }
116
- // have to refresh peer info for this peer to get updated multiaddrs
117
- if (peer.multiaddrs.length === 0) {
118
- // already looking this peer up
119
- if (queue.queue.find(job => job.options.peer.equals(peer.id)) != null) {
120
- continue;
121
- }
122
- queue.add(async () => {
123
- try {
124
- const provider = await this.findPeer(peer.id, options);
125
- if (provider.multiaddrs.length === 0) {
126
- return null;
127
- }
128
- return {
129
- ...provider,
130
- protocols: peer.protocols,
131
- routing: peer.routing
132
- };
133
- }
134
- catch (err) {
135
- this.log.error('could not load multiaddrs for peer %p - %e', peer.id, err);
136
- return null;
137
- }
138
- }, {
139
- peer: peer.id,
140
- signal: options.signal
141
- })
142
- .catch(err => {
143
- this.log.error('could not load multiaddrs for peer %p - %e', peer.id, err);
144
- });
145
- continue;
146
- }
147
- foundProviders++;
148
- yield peer;
149
- }
150
- this.log('findProviders finished, found %d providers for %c', foundProviders, key);
151
- }
152
- /**
153
- * Iterates over all content routers in parallel to notify it is
154
- * a provider of the given key
155
- */
156
- async provide(key, options = {}) {
157
- if (this.routers.length === 0) {
158
- throw new NoRoutersAvailableError('No content routers available');
159
- }
160
- await Promise.all(supports(this.routers, 'provide')
161
- .map(async (router) => {
162
- options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:start', {
163
- routing: router.name,
164
- cid: key
165
- }));
166
- await router.provide(key, options);
167
- options?.onProgress?.(new CustomProgressEvent('helia:routing:provide:end', {
168
- routing: router.name,
169
- cid: key
170
- }));
171
- }));
172
- }
173
- async cancelReprovide(key, options = {}) {
174
- await Promise.all(supports(this.routers, 'cancelReprovide')
175
- .map(async (router) => {
176
- options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:start', {
177
- routing: router.name,
178
- cid: key
179
- }));
180
- await router.cancelReprovide(key, options);
181
- options?.onProgress?.(new CustomProgressEvent('helia:routing:cancel-reprovide:end', {
182
- routing: router.name,
183
- cid: key
184
- }));
185
- }));
186
- }
187
- /**
188
- * Store the given key/value pair in the available content routings
189
- */
190
- async put(key, value, options) {
191
- await Promise.all(supports(this.routers, 'put')
192
- .map(async (router) => {
193
- options?.onProgress?.(new CustomProgressEvent('helia:routing:put:start', {
194
- routing: router.name,
195
- key,
196
- value
197
- }));
198
- await router.put(key, value, options);
199
- options?.onProgress?.(new CustomProgressEvent('helia:routing:put:end', {
200
- routing: router.name,
201
- key,
202
- value
203
- }));
204
- }));
205
- }
206
- /**
207
- * Get the value to the given key. The first value offered by any configured
208
- * router will be returned.
209
- */
210
- async get(key, options) {
211
- const errors = [];
212
- let result;
213
- try {
214
- result = await Promise.any(supports(this.routers, 'get')
215
- .map(async (router) => {
216
- options?.onProgress?.(new CustomProgressEvent('helia:routing:get:start', {
217
- routing: router.name,
218
- key
219
- }));
220
- try {
221
- return await router.get(key, options);
222
- }
223
- catch (err) {
224
- this.log('router %s failed with %e', router, err);
225
- errors.push(err);
226
- }
227
- finally {
228
- options?.onProgress?.(new CustomProgressEvent('helia:routing:get:end', {
229
- routing: router.name,
230
- key
231
- }));
232
- }
233
- }));
234
- }
235
- catch {
236
- // ignore AggregateError as we will throw a better-named one
237
- }
238
- if (result == null) {
239
- throw new GetFailedError(errors, `Failed to get value key ${uint8ArrayToString(key, 'base58btc')}`);
240
- }
241
- return result;
242
- }
243
- /**
244
- * Iterates over all peer routers in parallel to find the given peer
245
- */
246
- async findPeer(id, options) {
247
- if (this.routers.length === 0) {
248
- throw new NoRoutersAvailableError('No peer routers available');
249
- }
250
- const self = this;
251
- const source = merge(...supports(this.routers, 'findPeer')
252
- .map(router => (async function* () {
253
- options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:start', {
254
- routing: router.name,
255
- peerId: id
256
- }));
257
- try {
258
- yield await router.findPeer(id, options);
259
- }
260
- catch (err) {
261
- self.log.error(err);
262
- }
263
- finally {
264
- options?.onProgress?.(new CustomProgressEvent('helia:routing:find-peer:end', {
265
- routing: router.name,
266
- peerId: id
267
- }));
268
- }
269
- })()));
270
- for await (const peer of source) {
271
- if (peer == null) {
272
- continue;
273
- }
274
- return peer;
275
- }
276
- throw new NotFoundError('Could not find peer in routing');
277
- }
278
- /**
279
- * Attempt to find the closest peers on the network to the given key
280
- */
281
- async *getClosestPeers(key, options = {}) {
282
- if (this.routers.length === 0) {
283
- throw new NoRoutersAvailableError('No peer routers available');
284
- }
285
- for await (const peer of merge(...supports(this.routers, 'getClosestPeers')
286
- .map(async function* (router) {
287
- options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:start', {
288
- routing: router.name,
289
- key
290
- }));
291
- try {
292
- yield* router.getClosestPeers(key, options);
293
- }
294
- finally {
295
- options?.onProgress?.(new CustomProgressEvent('helia:routing:get-closest-peers:end', {
296
- routing: router.name,
297
- key
298
- }));
299
- }
300
- }))) {
301
- if (peer == null) {
302
- continue;
303
- }
304
- yield peer;
305
- }
306
- }
307
- }
308
- function supports(routers, key) {
309
- return routers.filter(router => router[key] != null);
310
- }
311
- //# sourceMappingURL=routing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAM5C,MAAM,mCAAmC,GAAG,CAAC,CAAA;AAgB7C,MAAM,OAAO,OAAO;IACX,IAAI,CAAQ;IAEF,GAAG,CAAQ;IACX,OAAO,CAAU;IACjB,yBAAyB,CAAQ;IAElD,YAAa,UAA6B,EAAE,I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,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAA;AACtD,CAAC"}
@@ -1,62 +0,0 @@
1
- import type { Routing } from '@helia/interface';
2
- import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore } from '@helia/interface';
3
- import type { Pins } from '@helia/interface';
4
- import type { AbortOptions, Startable } from '@libp2p/interface';
5
- import type { Blockstore, InputPair } from 'interface-blockstore';
6
- import type { Mortice } from 'mortice';
7
- import type { CID } from 'multiformats/cid';
8
- import type { ProgressOptions } from 'progress-events';
9
- export interface BlockStorageInit {
10
- holdGcLock?: boolean;
11
- }
12
- export interface GetOptions extends AbortOptions {
13
- progress?(evt: Event): void;
14
- }
15
- /**
16
- * BlockStorage is a hybrid blockstore that puts/gets blocks from a configured
17
- * blockstore (that may be on disk, s3, or something else). If the blocks are
18
- * not present Bitswap will be used to fetch them from network peers.
19
- */
20
- export declare class BlockStorage implements Blocks, Startable {
21
- lock: Mortice;
22
- private readonly child;
23
- private readonly pins;
24
- private readonly routing;
25
- private started;
26
- /**
27
- * Create a new BlockStorage
28
- */
29
- constructor(blockstore: Blocks, pins: Pins, routing: Routing, options?: BlockStorageInit);
30
- isStarted(): boolean;
31
- start(): Promise<void>;
32
- stop(): Promise<void>;
33
- unwrap(): Blockstore;
34
- /**
35
- * Put a block to the underlying datastore
36
- */
37
- put(cid: CID, block: Uint8Array, options?: AbortOptions & ProgressOptions<PutBlockProgressEvents>): Promise<CID>;
38
- /**
39
- * Put a multiple blocks to the underlying datastore
40
- */
41
- putMany(blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): AsyncGenerator<CID>;
42
- /**
43
- * Get a block by cid
44
- */
45
- get(cid: CID, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents>): AsyncGenerator<Uint8Array>;
46
- /**
47
- * Get multiple blocks back from an (async) iterable of cids
48
- */
49
- getMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents>): AsyncGenerator<Pair>;
50
- /**
51
- * Delete a block from the blockstore
52
- */
53
- delete(cid: CID, options?: AbortOptions & ProgressOptions<DeleteBlockProgressEvents>): Promise<void>;
54
- /**
55
- * Delete multiple blocks from the blockstore
56
- */
57
- deleteMany(cids: Iterable<CID> | AsyncIterable<CID>, options?: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents>): AsyncGenerator<CID>;
58
- has(cid: CID, options?: AbortOptions): Promise<boolean>;
59
- getAll(options?: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents>): AsyncGenerator<Pair>;
60
- createSession(root: CID, options?: AbortOptions): SessionBlockstore;
61
- }
62
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC3R,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAA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M,GAAG,cAAc,CAAC,UAAU,CAAC;IAW5I;;OAEG;IACK,OAAO,CAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,iBAAiB,GAAG,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAM,GAAG,cAAc,CAAC,IAAI,CAAC;IAW/K;;OAEG;IACG,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,yBAAyB,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB/G;;OAEG;IACK,UAAU,CAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,8BAA8B,CAAM,GAAG,cAAc,CAAC,GAAG,CAAC;IAwB1J,GAAG,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAW1D,MAAM,CAAE,OAAO,GAAE,YAAY,GAAG,eAAe,CAAC,0BAA0B,CAAM,GAAG,cAAc,CAAC,IAAI,CAAC;IAW/G,aAAa,CAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,iBAAiB;CAIrE"}
@@ -1,159 +0,0 @@
1
- import { start, stop } from '@libp2p/interface';
2
- import createMortice from 'mortice';
3
- import { BlockPinnedError } from "./errors.js";
4
- /**
5
- * BlockStorage is a hybrid blockstore that puts/gets blocks from a configured
6
- * blockstore (that may be on disk, s3, or something else). If the blocks are
7
- * not present Bitswap will be used to fetch them from network peers.
8
- */
9
- export class BlockStorage {
10
- lock;
11
- child;
12
- pins;
13
- routing;
14
- started;
15
- /**
16
- * Create a new BlockStorage
17
- */
18
- constructor(blockstore, pins, routing, options = {}) {
19
- this.child = blockstore;
20
- this.pins = pins;
21
- this.routing = routing;
22
- this.lock = createMortice({
23
- singleProcess: options.holdGcLock
24
- });
25
- this.started = false;
26
- }
27
- isStarted() {
28
- return this.started;
29
- }
30
- async start() {
31
- await start(this.child);
32
- this.started = true;
33
- }
34
- async stop() {
35
- await stop(this.child);
36
- this.started = false;
37
- }
38
- unwrap() {
39
- return this.child;
40
- }
41
- /**
42
- * Put a block to the underlying datastore
43
- */
44
- async put(cid, block, options = {}) {
45
- options?.signal?.throwIfAborted();
46
- const releaseLock = await this.lock.readLock();
47
- try {
48
- return await this.child.put(cid, block, options);
49
- }
50
- finally {
51
- releaseLock();
52
- }
53
- }
54
- /**
55
- * Put a multiple blocks to the underlying datastore
56
- */
57
- async *putMany(blocks, options = {}) {
58
- options?.signal?.throwIfAborted();
59
- const releaseLock = await this.lock.readLock();
60
- try {
61
- yield* this.child.putMany(blocks, options);
62
- }
63
- finally {
64
- releaseLock();
65
- }
66
- }
67
- /**
68
- * Get a block by cid
69
- */
70
- async *get(cid, options = {}) {
71
- options?.signal?.throwIfAborted();
72
- const releaseLock = await this.lock.readLock();
73
- try {
74
- yield* this.child.get(cid, options);
75
- }
76
- finally {
77
- releaseLock();
78
- }
79
- }
80
- /**
81
- * Get multiple blocks back from an (async) iterable of cids
82
- */
83
- async *getMany(cids, options = {}) {
84
- options?.signal?.throwIfAborted();
85
- const releaseLock = await this.lock.readLock();
86
- try {
87
- yield* this.child.getMany(cids, options);
88
- }
89
- finally {
90
- releaseLock();
91
- }
92
- }
93
- /**
94
- * Delete a block from the blockstore
95
- */
96
- async delete(cid, options = {}) {
97
- options?.signal?.throwIfAborted();
98
- const releaseLock = await this.lock.writeLock();
99
- try {
100
- if (await this.pins.isPinned(cid)) {
101
- throw new BlockPinnedError('Block was pinned - please unpin and try again');
102
- }
103
- // stop re-providing this CID if necessary
104
- await this.routing.cancelReprovide(cid, options);
105
- await this.child.delete(cid, options);
106
- }
107
- finally {
108
- releaseLock();
109
- }
110
- }
111
- /**
112
- * Delete multiple blocks from the blockstore
113
- */
114
- async *deleteMany(cids, options = {}) {
115
- options?.signal?.throwIfAborted();
116
- const releaseLock = await this.lock.writeLock();
117
- try {
118
- const storage = this;
119
- yield* this.child.deleteMany((async function* () {
120
- for await (const cid of cids) {
121
- if (await storage.pins.isPinned(cid)) {
122
- throw new BlockPinnedError('Block was pinned - please unpin and try again');
123
- }
124
- // stop re-providing this CID if necessary
125
- await storage.routing.cancelReprovide(cid, options);
126
- yield cid;
127
- }
128
- }()), options);
129
- }
130
- finally {
131
- releaseLock();
132
- }
133
- }
134
- async has(cid, options = {}) {
135
- options?.signal?.throwIfAborted();
136
- const releaseLock = await this.lock.readLock();
137
- try {
138
- return await this.child.has(cid, options);
139
- }
140
- finally {
141
- releaseLock();
142
- }
143
- }
144
- async *getAll(options = {}) {
145
- options?.signal?.throwIfAborted();
146
- const releaseLock = await this.lock.readLock();
147
- try {
148
- yield* this.child.getAll(options);
149
- }
150
- finally {
151
- releaseLock();
152
- }
153
- }
154
- createSession(root, options) {
155
- options?.signal?.throwIfAborted();
156
- return this.child.createSession(root, options);
157
- }
158
- }
159
- //# sourceMappingURL=storage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,aAAa,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAkB9C;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAChB,IAAI,CAAS;IACH,KAAK,CAAQ;IACb,IAAI,CAAM;IACV,OAAO,CAAS;IACzB,OAAO,CAAS;IAExB;;OAEG;IACH,YAAa,UAAkB,EAAE,IAAU,EAAE,OAAgB,EAAE,UAA4B,EAAE;QAC3F,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAA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AAO,CAAC,CAAA;QAC3C,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAA;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAE,MAAM,CAAE,UAAsE,EAAE;QACtF,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAE9C,IAAI,CAAC;YACH,KAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACpC,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAA;QACf,CAAC;IACH,CAAC;IAED,aAAa,CAAE,IAAS,EAAE,OAAsB;QAC9C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;CACF"}
@@ -1,4 +0,0 @@
1
- export declare const SALT_LENGTH = 16;
2
- export declare const KEY_SIZE = 32;
3
- export declare const ITERATIONS = 10000;
4
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,KAAK,CAAA;AAC7B,eAAO,MAAM,QAAQ,KAAK,CAAA;AAC1B,eAAO,MAAM,UAAU,QAAQ,CAAA"}
@@ -1,4 +0,0 @@
1
- export const SALT_LENGTH = 16;
2
- export const KEY_SIZE = 32;
3
- export const ITERATIONS = 10000;
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAA;AAC1B,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Datastore } from 'interface-datastore';
2
- export declare function assertDatastoreVersionIsCurrent(datastore: Datastore): Promise<void>;
3
- //# sourceMappingURL=datastore-version.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datastore-version.d.ts","sourceRoot":"","sources":["../../../src/utils/datastore-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAKpD,wBAAsB,+BAA+B,CAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1F"}
@@ -1,20 +0,0 @@
1
- import { Key } from 'interface-datastore';
2
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
3
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
4
- import { InvalidDatastoreVersionError } from "../errors.js";
5
- const DS_VERSION_KEY = new Key('/version');
6
- const CURRENT_VERSION = 1;
7
- export async function assertDatastoreVersionIsCurrent(datastore) {
8
- if (!(await datastore.has(DS_VERSION_KEY))) {
9
- await datastore.put(DS_VERSION_KEY, uint8ArrayFromString(`${CURRENT_VERSION}`));
10
- return;
11
- }
12
- const buf = await datastore.get(DS_VERSION_KEY);
13
- const str = uint8ArrayToString(buf);
14
- const version = parseInt(str, 10);
15
- if (version !== CURRENT_VERSION) {
16
- // TODO: write migrations when we break compatibility - for an example, see https://github.com/ipfs/js-ipfs-repo/tree/master/packages/ipfs-repo-migrations
17
- throw new InvalidDatastoreVersionError('Invalid datastore version, a datastore migration may be required');
18
- }
19
- }
20
- //# sourceMappingURL=datastore-version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datastore-version.js","sourceRoot":"","sources":["../../../src/utils/datastore-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAG3D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;AAC1C,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,MAAM,CAAC,KAAK,UAAU,+BAA+B,CAAE,SAAoB;IACzE,IAAI,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC;QAC3C,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAA;QAE/E,OAAM;IACR,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC/C,MAAM,GAAG,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IAEjC,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;QAChC,0JAA0J;QAC1J,MAAM,IAAI,4BAA4B,CAAC,kEAAkE,CAAC,CAAA;IAC5G,CAAC;AACH,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { CodecLoader } from '@helia/interface';
2
- import type { BlockCodec } from 'multiformats/codecs/interface';
3
- export declare function getCodec(initialCodecs?: Array<BlockCodec<any, any>>, loadCodec?: CodecLoader): CodecLoader;
4
- //# sourceMappingURL=get-codec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-codec.d.ts","sourceRoot":"","sources":["../../../src/utils/get-codec.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,wBAAgB,QAAQ,CAAE,aAAa,GAAE,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAM,EAAE,SAAS,CAAC,EAAE,WAAW,GAAG,WAAW,CAkC/G"}