@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,172 +1,6 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * This module contains utility code that is shared between various Helia
5
- * modules such as `helia`, `@helia/http`, etc.
6
- */
7
- import { TypedEventEmitter } from '@libp2p/interface';
8
- import { Routing as RoutingClass } from './routing.ts';
9
- import { BlockStorage } from './storage.ts';
10
- import type { BlockStorageInit } from './storage.ts';
11
- import type { CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, HeliaEvents, CryptoLoader, Crypto, NodeInfo, Router, HeliaMixin } from '@helia/interface';
12
- import type { BlockBroker } from '@helia/interface';
13
- import type { Pins } from '@helia/interface';
14
- import type { Keychain, KeychainInit } from '@ipshipyard/keychain';
15
- import type { ComponentLogger, Metrics } from '@libp2p/interface';
16
- import type { DNS } from '@multiformats/dns';
17
- import type { Blockstore } from 'interface-blockstore';
18
- import type { Datastore } from 'interface-datastore';
19
- import type { BlockCodec } from 'multiformats';
20
- import type { MultihashHasher } from 'multiformats/hashes/interface';
21
- export { AbstractSession } from './abstract-session.ts';
22
- export type { AbstractCreateSessionOptions, BlockstoreSessionEvents, AbstractSessionComponents } from './abstract-session.ts';
23
- export { isCID } from './utils/is-cid.ts';
24
- export type { BlockStorage, BlockStorageInit };
25
- export { breadthFirstWalker, depthFirstWalker, naturalOrderWalker } from './graph-walker.ts';
26
- export type { GraphWalkerComponents, GraphWalkerInit, GraphNode, GraphWalker } from './graph-walker.ts';
27
- /**
28
- * Options used to create a Helia node.
29
- */
30
- export interface HeliaInit {
31
- /**
32
- * By default Helia stores the node's PeerId in an encrypted form in a
33
- * libp2p keystore. These options control how that keystore is configured.
34
- */
35
- keychain?: KeychainInit;
36
- /**
37
- * The blockstore is where blocks are stored
38
- */
39
- blockstore?: Blockstore;
40
- /**
41
- * The datastore is where data is stored
42
- */
43
- datastore?: Datastore;
44
- /**
45
- * By default sha256, sha512 and identity hashes are supported for
46
- * bitswap operations. To bitswap blocks with CIDs using other hashes
47
- * pass appropriate MultihashHashers here.
48
- */
49
- hashers?: MultihashHasher[];
50
- /**
51
- * An optional function that can load a MultihashHasher on demand. May return
52
- * a promise.
53
- */
54
- loadHasher?(code: number): MultihashHasher | Promise<MultihashHasher>;
55
- /**
56
- * In order to pin CIDs that correspond to a DAG, it's necessary to know
57
- * how to traverse that DAG. DAGWalkers take a block and yield any CIDs
58
- * encoded within that block.
59
- */
60
- codecs?: Array<BlockCodec<any, any>>;
61
- /**
62
- * An optional function that can load a BlockCodec on demand. May return a
63
- * promise.
64
- */
65
- loadCodec?(code: number): BlockCodec<any, any> | Promise<BlockCodec<any, any>>;
66
- /**
67
- * A list of pre-supported public/private key implementations
68
- */
69
- cryptos?: Array<Crypto>;
70
- /**
71
- * Dynamically load a cryptography implementation
72
- */
73
- loadCrypto?: CryptoLoader;
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 current process and other processes
81
- * will contact this process for access.
82
- *
83
- * If Helia is being run in multiple processes, one process must hold the GC
84
- * lock so use this option to control which process that is.
85
- *
86
- * @default true
87
- */
88
- holdGcLock?: boolean;
89
- /**
90
- * An optional logging component to pass to libp2p. If not specified the
91
- * default implementation from libp2p will be used.
92
- */
93
- logger?: ComponentLogger;
94
- /**
95
- * A list of strategies used to fetch blocks when they are not present in
96
- * the local blockstore
97
- */
98
- blockBrokers?: Array<BlockBroker | ((components: any) => BlockBroker)>;
99
- /**
100
- * Routers perform operations such as looking up content providers,
101
- * information about network peers or getting/putting records.
102
- */
103
- routers?: Array<Router | ((components: any) => Router)>;
104
- /**
105
- * During provider lookups, peers can be returned from routing implementations
106
- * with no multiaddrs.
107
- *
108
- * This can happen when they've been retrieved from network peers that only
109
- * store multiaddrs for a limited amount of time.
110
- *
111
- * When this happens the peer's info has to be looked up with a further query.
112
- *
113
- * To not have this query block the yielding of other providers returned with
114
- * multiaddrs, a separate queue is used to perform this lookup.
115
- *
116
- * This config value controls the concurrency of that queue.
117
- *
118
- * @default 5
119
- */
120
- providerLookupConcurrency?: number;
121
- /**
122
- * Components used by subclasses
123
- */
124
- components?: Record<string, any>;
125
- /**
126
- * An optional DNS implementation used to perform queries for DNS records.
127
- */
128
- dns?: DNS;
129
- /**
130
- * A metrics object that can be used to collected arbitrary stats about node
131
- * usage.
132
- */
133
- metrics?: Metrics;
134
- /**
135
- * Limit the maximum supported size of identity hash digests to this value
136
- *
137
- * @default 128
138
- */
139
- maxIdentityHashDigestLength?: number;
140
- }
141
- export declare class Helia implements HeliaInterface {
142
- info: NodeInfo;
143
- blockstore: BlockStorage;
144
- datastore: Datastore;
145
- events: TypedEventEmitter<HeliaEvents<this>>;
146
- pins: Pins;
147
- logger: ComponentLogger;
148
- routing: RoutingClass;
149
- getCodec: CodecLoader;
150
- getHasher: HasherLoader;
151
- getCrypto: CryptoLoader;
152
- dns: DNS;
153
- keychain: Keychain;
154
- metrics?: Metrics;
155
- status: 'stopped' | 'stopping' | 'starting' | 'started';
156
- private readonly log;
157
- private readonly blockBrokers;
158
- private readonly mixins;
159
- constructor(init: HeliaInit & {
160
- name: string;
161
- version: string;
162
- });
163
- hasRouter(name: string): boolean;
164
- addRouter(router: Router): void;
165
- hasBlockBroker(name: string): boolean;
166
- addBlockBroker(blockBroker: BlockBroker): void;
167
- addMixin(mixin: HeliaMixin): void;
168
- start(): Promise<this>;
169
- stop(): Promise<this>;
170
- gc(options?: GCOptions): Promise<void>;
171
- }
1
+ export * from './abstract-session.ts';
2
+ export * from './errors.ts';
3
+ export * from './graph-walker.ts';
4
+ export * from './is-cid.ts';
5
+ export * from './is-promise.ts';
172
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAe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,CAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IAI5B,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAqBvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAoBtB,EAAE,CAAE,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CA+BlD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA"}
package/dist/src/index.js CHANGED
@@ -1,163 +1,6 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * This module contains utility code that is shared between various Helia
5
- * modules such as `helia`, `@helia/http`, etc.
6
- */
7
- import { keychain } from '@ipshipyard/keychain';
8
- import { start, stop, TypedEventEmitter } from '@libp2p/interface';
9
- import { dns } from '@multiformats/dns';
10
- import { defaultLogger } from 'birnam';
11
- import { MemoryBlockstore } from 'blockstore-core';
12
- import { MemoryDatastore } from 'datastore-core';
13
- import drain from 'it-drain';
14
- import { CustomProgressEvent } from 'progress-events';
15
- import { PinsImpl } from "./pins.js";
16
- import { Routing as RoutingClass } from "./routing.js";
17
- import { BlockStorage } from "./storage.js";
18
- import { assertDatastoreVersionIsCurrent } from "./utils/datastore-version.js";
19
- import { getCodec } from "./utils/get-codec.js";
20
- import { getCrypto } from "./utils/get-crypto.js";
21
- import { getHasher } from "./utils/get-hasher.js";
22
- import { NetworkedStorage } from "./utils/networked-storage.js";
23
- export { AbstractSession } from "./abstract-session.js";
24
- export { isCID } from "./utils/is-cid.js";
25
- export { breadthFirstWalker, depthFirstWalker, naturalOrderWalker } from "./graph-walker.js";
26
- export class Helia {
27
- info;
28
- blockstore;
29
- datastore;
30
- events;
31
- pins;
32
- logger;
33
- routing;
34
- getCodec;
35
- getHasher;
36
- getCrypto;
37
- dns;
38
- keychain;
39
- metrics;
40
- status;
41
- log;
42
- blockBrokers;
43
- mixins;
44
- constructor(init) {
45
- this.info = {
46
- name: init.name,
47
- version: init.version
48
- };
49
- this.logger = init.logger ?? defaultLogger();
50
- this.log = this.logger.forComponent('helia');
51
- this.getHasher = getHasher(init.hashers, init.loadHasher);
52
- this.getCodec = getCodec(init.codecs, init.loadCodec);
53
- this.getCrypto = getCrypto(init.cryptos, init.loadCrypto);
54
- this.dns = init.dns ?? dns();
55
- this.metrics = init.metrics;
56
- this.events = new TypedEventEmitter();
57
- this.status = 'stopped';
58
- this.mixins = [];
59
- // @ts-expect-error routing and keychain are not set
60
- const components = {
61
- blockstore: init.blockstore ?? new MemoryBlockstore(),
62
- datastore: init.datastore ?? new MemoryDatastore(),
63
- logger: this.logger,
64
- blockBrokers: [],
65
- getHasher: this.getHasher,
66
- getCodec: this.getCodec,
67
- getCrypto: this.getCrypto,
68
- dns: this.dns,
69
- metrics: this.metrics,
70
- ...(init.components ?? {})
71
- };
72
- this.keychain = components.keychain = keychain()(components);
73
- this.routing = components.routing = new RoutingClass(components, {
74
- routers: (init.routers ?? []).flatMap((router) => {
75
- if (typeof router === 'function') {
76
- router = router(components);
77
- }
78
- // if the router itself is a router
79
- const routers = [
80
- router
81
- ];
82
- return routers;
83
- }),
84
- providerLookupConcurrency: init.providerLookupConcurrency
85
- });
86
- this.blockBrokers = components.blockBrokers = (init.blockBrokers ?? []).map((broker) => {
87
- if (typeof broker === 'function') {
88
- broker = broker(components);
89
- }
90
- return broker;
91
- });
92
- const networkedStorage = new NetworkedStorage(components, init);
93
- this.pins = new PinsImpl(components.datastore, networkedStorage, this.getCodec);
94
- this.blockstore = new BlockStorage(networkedStorage, this.pins, this.routing, {
95
- holdGcLock: init.holdGcLock ?? true
96
- });
97
- this.datastore = components.datastore;
98
- }
99
- hasRouter(name) {
100
- return this.routing.hasRouter(name);
101
- }
102
- addRouter(router) {
103
- this.routing.addRouter(router);
104
- }
105
- hasBlockBroker(name) {
106
- return this.blockBrokers.findIndex(b => b.name === name) !== -1;
107
- }
108
- addBlockBroker(blockBroker) {
109
- this.blockBrokers.push(blockBroker);
110
- }
111
- addMixin(mixin) {
112
- this.mixins.push(mixin);
113
- }
114
- async start() {
115
- this.status = 'starting';
116
- await assertDatastoreVersionIsCurrent(this.datastore);
117
- await start(this.blockstore, this.datastore, this.routing, ...this.blockBrokers);
118
- for (const mixin of this.mixins) {
119
- await mixin.start?.(this);
120
- }
121
- this.status = 'started';
122
- this.events.dispatchEvent(new CustomEvent('start', { detail: this }));
123
- return this;
124
- }
125
- async stop() {
126
- this.status = 'stopping';
127
- for (const mixin of this.mixins) {
128
- await mixin.stop?.(this);
129
- }
130
- await stop(this.blockstore, this.datastore, this.routing, ...this.blockBrokers);
131
- this.status = 'stopped';
132
- this.events.dispatchEvent(new CustomEvent('stop', { detail: this }));
133
- return this;
134
- }
135
- async gc(options = {}) {
136
- const releaseLock = await this.blockstore.lock.writeLock();
137
- try {
138
- const helia = this;
139
- const blockstore = this.blockstore.unwrap();
140
- this.log('gc start');
141
- await drain(blockstore.deleteMany((async function* () {
142
- for await (const { cid } of blockstore.getAll()) {
143
- try {
144
- if (await helia.pins.isPinned(cid, options)) {
145
- continue;
146
- }
147
- yield cid;
148
- options.onProgress?.(new CustomProgressEvent('helia:gc:deleted', cid));
149
- }
150
- catch (err) {
151
- helia.log.error('error during gc - %e', err);
152
- options.onProgress?.(new CustomProgressEvent('helia:gc:error', err));
153
- }
154
- }
155
- }())));
156
- }
157
- finally {
158
- releaseLock();
159
- }
160
- this.log('gc finished');
161
- }
162
- }
1
+ export * from "./abstract-session.js";
2
+ export * from "./errors.js";
3
+ export * from "./graph-walker.js";
4
+ export * from "./is-cid.js";
5
+ export * from "./is-promise.js";
163
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ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AC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;4BAC5C,SAAQ;wBACV,CAAC;wBAED,MAAM,GAAG,CAAA;wBAET,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAM,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;oBAAC,OAAO,GAAQ,EAAE,CAAC;wBAClB,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;wBAC5C,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAQ,gBAAgB,EAAE,GAAG,CAAC,CAAC,CAAA;oBAC7E,CAAC;gBACH,CAAC;YACH,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACR,CAAC;gBAAS,CAAC;YACT,WAAW,EAAE,CAAA;QACf,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACzB,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-cid.d.ts","sourceRoot":"","sources":["../../src/is-cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,wBAAgB,KAAK,CAAE,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,GAAG,CAM5C"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-cid.js","sourceRoot":"","sources":["../../src/is-cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,MAAM,UAAU,KAAK,CAAE,GAAS;IAC9B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAA;AAC/B,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-promise.d.ts","sourceRoot":"","sources":["../../src/is-promise.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAE,CAAC,EAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAEvD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-promise.js","sourceRoot":"","sources":["../../src/is-promise.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAM,CAAO;IACpC,OAAO,CAAC,EAAE,IAAI,IAAI,IAAI,CAAA;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/utils",
3
- "version": "2.5.2-1361bfa5",
3
+ "version": "2.5.2-16d805e1",
4
4
  "description": "Shared code that implements the Helia API",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/utils#readme",
@@ -48,47 +48,30 @@
48
48
  "test:electron-main": "aegir test -t electron-main"
49
49
  },
50
50
  "dependencies": {
51
- "@helia/interface": "6.2.1-1361bfa5",
52
- "@ipld/dag-cbor": "^10.0.1",
53
- "@ipld/dag-json": "^11.0.0",
54
- "@ipld/dag-pb": "^4.1.7",
55
- "@ipshipyard/crypto": "^1.1.0",
56
- "@ipshipyard/keychain": "^1.0.2",
51
+ "@helia/interface": "6.2.1-16d805e1",
57
52
  "@libp2p/interface": "^3.2.3",
58
53
  "@libp2p/utils": "^7.2.2",
59
- "@multiformats/dns": "^1.0.13",
60
54
  "@multiformats/multiaddr": "^13.0.3",
61
- "abort-error": "^1.0.2",
62
- "any-signal": "^4.2.0",
63
- "birnam": "^1.0.0",
64
- "blockstore-core": "^7.0.1",
65
- "cborg": "^5.1.1",
66
- "datastore-core": "^12.0.1",
67
- "interface-blockstore": "^7.0.1",
68
- "interface-datastore": "^10.0.1",
69
- "it-drain": "^3.0.12",
70
55
  "it-filter": "^3.1.6",
71
- "it-foreach": "^2.1.7",
72
- "it-merge": "^3.0.14",
73
56
  "it-to-buffer": "^5.0.0",
74
- "mortice": "^3.3.1",
75
57
  "multiformats": "^14.0.0",
76
58
  "p-defer": "^4.0.1",
77
59
  "progress-events": "^1.1.0",
78
- "race-signal": "^2.0.0",
79
- "uint8arrays": "^6.1.1"
60
+ "race-signal": "^2.0.0"
80
61
  },
81
62
  "devDependencies": {
63
+ "@ipld/dag-cbor": "^10.0.1",
82
64
  "@libp2p/crypto": "^5.1.19",
83
65
  "@libp2p/logger": "^6.2.8",
84
66
  "@libp2p/peer-id": "^6.0.10",
85
67
  "@types/sinon": "^21.0.1",
86
68
  "aegir": "^48.0.11",
69
+ "blockstore-core": "^7.0.1",
87
70
  "delay": "^7.0.0",
71
+ "interface-blockstore": "^7.0.1",
88
72
  "it-all": "^3.0.11",
89
73
  "it-map": "^3.1.6",
90
- "sinon": "^22.0.0",
91
- "sinon-ts": "^2.0.0"
74
+ "sinon": "^22.0.0"
92
75
  },
93
76
  "sideEffects": false
94
77
  }