@helia/utils 2.5.2-070b7528 → 2.5.2-73a28eda
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 +2 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/errors.d.ts +4 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +14 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/storage.d.ts +3 -4
- package/dist/src/storage.d.ts.map +1 -1
- package/dist/src/storage.js.map +1 -1
- package/dist/src/utils/constants.d.ts +4 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +4 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/get-codec.d.ts +2 -2
- package/dist/src/utils/get-codec.d.ts.map +1 -1
- package/dist/src/utils/get-codec.js +0 -1
- package/dist/src/utils/get-codec.js.map +1 -1
- package/dist/src/utils/get-crypto.d.ts +4 -0
- package/dist/src/utils/get-crypto.d.ts.map +1 -0
- package/dist/src/utils/get-crypto.js +35 -0
- package/dist/src/utils/get-crypto.js.map +1 -0
- package/dist/src/utils/get-hasher.d.ts +2 -2
- package/dist/src/utils/get-hasher.d.ts.map +1 -1
- package/dist/src/utils/get-hasher.js.map +1 -1
- package/dist/src/utils/session-storage.d.ts +3 -4
- package/dist/src/utils/session-storage.d.ts.map +1 -1
- package/dist/src/utils/session-storage.js.map +1 -1
- package/dist/src/utils/storage.d.ts +3 -4
- package/dist/src/utils/storage.d.ts.map +1 -1
- package/dist/src/utils/storage.js.map +1 -1
- package/package.json +14 -16
- package/src/errors.ts +5 -0
- package/src/index.ts +25 -5
- package/src/storage.ts +3 -4
- package/src/utils/constants.ts +3 -0
- package/src/utils/get-codec.ts +2 -4
- package/src/utils/get-crypto.ts +44 -0
- package/src/utils/get-hasher.ts +2 -2
- package/src/utils/session-storage.ts +3 -4
- package/src/utils/storage.ts +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "2.5.2-
|
|
3
|
+
"version": "2.5.2-73a28eda",
|
|
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,49 +48,47 @@
|
|
|
48
48
|
"test:electron-main": "aegir test -t electron-main"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@helia/interface": "6.2.1-
|
|
52
|
-
"@ipld/dag-cbor": "^
|
|
53
|
-
"@ipld/dag-json": "^
|
|
51
|
+
"@helia/interface": "6.2.1-73a28eda",
|
|
52
|
+
"@ipld/dag-cbor": "^10.0.0",
|
|
53
|
+
"@ipld/dag-json": "^11.0.0",
|
|
54
54
|
"@ipld/dag-pb": "^4.1.5",
|
|
55
|
+
"@ipshipyard/crypto": "^1.1.0",
|
|
56
|
+
"@ipshipyard/keychain": "^1.0.2",
|
|
55
57
|
"@libp2p/interface": "^3.2.0",
|
|
56
|
-
"@libp2p/keychain": "^6.0.12",
|
|
57
58
|
"@libp2p/utils": "^7.0.15",
|
|
58
59
|
"@multiformats/dns": "^1.0.13",
|
|
59
60
|
"@multiformats/multiaddr": "^13.0.1",
|
|
60
61
|
"any-signal": "^4.2.0",
|
|
61
|
-
"blockstore-core": "^
|
|
62
|
+
"blockstore-core": "^7.0.1",
|
|
62
63
|
"cborg": "^5.1.0",
|
|
63
|
-
"interface-blockstore": "^
|
|
64
|
-
"interface-datastore": "^
|
|
65
|
-
"interface-store": "^7.0.2",
|
|
64
|
+
"interface-blockstore": "^7.0.1",
|
|
65
|
+
"interface-datastore": "^10.0.1",
|
|
66
66
|
"it-drain": "^3.0.12",
|
|
67
67
|
"it-filter": "^3.1.5",
|
|
68
68
|
"it-foreach": "^2.1.6",
|
|
69
69
|
"it-merge": "^3.0.13",
|
|
70
|
-
"it-to-buffer": "^
|
|
70
|
+
"it-to-buffer": "^5.0.0",
|
|
71
71
|
"libp2p": "^3.2.0",
|
|
72
72
|
"mortice": "^3.3.1",
|
|
73
|
-
"multiformats": "^
|
|
73
|
+
"multiformats": "^14.0.0",
|
|
74
74
|
"p-defer": "^4.0.1",
|
|
75
75
|
"progress-events": "^1.1.0",
|
|
76
76
|
"race-signal": "^2.0.0",
|
|
77
|
-
"uint8arrays": "^
|
|
77
|
+
"uint8arrays": "^6.1.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@libp2p/crypto": "^5.1.15",
|
|
81
81
|
"@libp2p/logger": "^6.2.4",
|
|
82
82
|
"@libp2p/peer-id": "^6.0.6",
|
|
83
83
|
"@types/sinon": "^21.0.1",
|
|
84
|
+
"abort-error": "^1.0.2",
|
|
84
85
|
"aegir": "^48.0.4",
|
|
85
|
-
"datastore-core": "^
|
|
86
|
+
"datastore-core": "^12.0.1",
|
|
86
87
|
"delay": "^7.0.0",
|
|
87
88
|
"it-all": "^3.0.11",
|
|
88
89
|
"it-map": "^3.1.5",
|
|
89
90
|
"sinon": "^22.0.0",
|
|
90
91
|
"sinon-ts": "^2.0.0"
|
|
91
92
|
},
|
|
92
|
-
"browser": {
|
|
93
|
-
"./dist/src/utils/libp2p-defaults.js": "./dist/src/utils/libp2p-defaults.browser.js"
|
|
94
|
-
},
|
|
95
93
|
"sideEffects": false
|
|
96
94
|
}
|
package/src/errors.ts
CHANGED
|
@@ -32,3 +32,8 @@ export class BlockNotFoundWhileOfflineError extends Error {
|
|
|
32
32
|
static name = 'BlockNotFoundWhileOfflineError'
|
|
33
33
|
name = 'BlockNotFoundWhileOfflineError'
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
export class DecryptionFailedError extends Error {
|
|
37
|
+
static name = 'DecryptionFailedError'
|
|
38
|
+
name = 'DecryptionFailedError'
|
|
39
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* modules such as `helia`, `@helia/http`, etc.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { keychain } from '@ipshipyard/keychain'
|
|
8
9
|
import { contentRoutingSymbol, peerRoutingSymbol, start, stop, TypedEventEmitter } from '@libp2p/interface'
|
|
9
10
|
import { dns } from '@multiformats/dns'
|
|
10
11
|
import drain from 'it-drain'
|
|
@@ -14,14 +15,15 @@ import { Routing as RoutingClass } from './routing.ts'
|
|
|
14
15
|
import { BlockStorage } from './storage.ts'
|
|
15
16
|
import { assertDatastoreVersionIsCurrent } from './utils/datastore-version.ts'
|
|
16
17
|
import { getCodec } from './utils/get-codec.ts'
|
|
18
|
+
import { getCrypto } from './utils/get-crypto.ts'
|
|
17
19
|
import { getHasher } from './utils/get-hasher.ts'
|
|
18
20
|
import { NetworkedStorage } from './utils/networked-storage.ts'
|
|
19
21
|
import type { BlockStorageInit } from './storage.ts'
|
|
20
|
-
import type {
|
|
22
|
+
import type { CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, HeliaEvents, Routing, CryptoLoader, Crypto } from '@helia/interface'
|
|
21
23
|
import type { BlockBroker } from '@helia/interface/blocks'
|
|
22
24
|
import type { Pins } from '@helia/interface/pins'
|
|
25
|
+
import type { Keychain, KeychainInit } from '@ipshipyard/keychain'
|
|
23
26
|
import type { ComponentLogger, ContentRouting, Libp2p, Logger, Metrics, PeerRouting } from '@libp2p/interface'
|
|
24
|
-
import type { KeychainInit } from '@libp2p/keychain'
|
|
25
27
|
import type { DNS } from '@multiformats/dns'
|
|
26
28
|
import type { Blockstore } from 'interface-blockstore'
|
|
27
29
|
import type { Datastore } from 'interface-datastore'
|
|
@@ -88,7 +90,7 @@ export interface HeliaInit<T extends Libp2p = Libp2p> {
|
|
|
88
90
|
* An optional function that can load a MultihashHasher on demand. May return
|
|
89
91
|
* a promise.
|
|
90
92
|
*/
|
|
91
|
-
loadHasher?(code: number):
|
|
93
|
+
loadHasher?(code: number): MultihashHasher | Promise<MultihashHasher>
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* In order to pin CIDs that correspond to a DAG, it's necessary to know
|
|
@@ -101,7 +103,7 @@ export interface HeliaInit<T extends Libp2p = Libp2p> {
|
|
|
101
103
|
* An optional function that can load a BlockCodec on demand. May return a
|
|
102
104
|
* promise.
|
|
103
105
|
*/
|
|
104
|
-
loadCodec?(code: number):
|
|
106
|
+
loadCodec?(code: number): BlockCodec<any, any> | Promise<BlockCodec<any, any>>
|
|
105
107
|
|
|
106
108
|
/**
|
|
107
109
|
* A list of strategies used to fetch blocks when they are not present in
|
|
@@ -109,6 +111,16 @@ export interface HeliaInit<T extends Libp2p = Libp2p> {
|
|
|
109
111
|
*/
|
|
110
112
|
blockBrokers: Array<(components: any) => BlockBroker>
|
|
111
113
|
|
|
114
|
+
/**
|
|
115
|
+
* A list of pre-supported public/private key implementations
|
|
116
|
+
*/
|
|
117
|
+
cryptos?: Array<Crypto>
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Dynamically load a cryptography implementation
|
|
121
|
+
*/
|
|
122
|
+
loadCrypto?: CryptoLoader
|
|
123
|
+
|
|
112
124
|
/**
|
|
113
125
|
* Garbage collection requires preventing blockstore writes during searches
|
|
114
126
|
* for unpinned blocks as DAGs are typically pinned after they've been
|
|
@@ -187,9 +199,11 @@ interface Components {
|
|
|
187
199
|
blockBrokers: BlockBroker[]
|
|
188
200
|
routing: Routing
|
|
189
201
|
dns: DNS
|
|
202
|
+
keychain: Keychain
|
|
190
203
|
metrics?: Metrics
|
|
191
204
|
getCodec: CodecLoader
|
|
192
205
|
getHasher: HasherLoader
|
|
206
|
+
getCrypto: CryptoLoader
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
@@ -202,7 +216,9 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
202
216
|
public routing: Routing
|
|
203
217
|
public getCodec: CodecLoader
|
|
204
218
|
public getHasher: HasherLoader
|
|
219
|
+
public getCrypto: CryptoLoader
|
|
205
220
|
public dns: DNS
|
|
221
|
+
public keychain: Keychain
|
|
206
222
|
public metrics?: Metrics
|
|
207
223
|
private readonly log: Logger
|
|
208
224
|
|
|
@@ -211,12 +227,13 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
211
227
|
this.log = this.logger.forComponent('helia')
|
|
212
228
|
this.getHasher = getHasher(init.hashers, init.loadHasher)
|
|
213
229
|
this.getCodec = getCodec(init.codecs, init.loadCodec)
|
|
230
|
+
this.getCrypto = getCrypto(init.cryptos, init.loadCrypto)
|
|
214
231
|
this.dns = init.dns ?? dns()
|
|
215
232
|
this.metrics = init.metrics
|
|
216
233
|
this.libp2p = init.libp2p
|
|
217
234
|
this.events = new TypedEventEmitter<HeliaEvents<T>>()
|
|
218
235
|
|
|
219
|
-
// @ts-expect-error routing
|
|
236
|
+
// @ts-expect-error routing and keychain are not set
|
|
220
237
|
const components: Components = {
|
|
221
238
|
blockstore: init.blockstore,
|
|
222
239
|
datastore: init.datastore,
|
|
@@ -225,11 +242,14 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
225
242
|
blockBrokers: [],
|
|
226
243
|
getHasher: this.getHasher,
|
|
227
244
|
getCodec: this.getCodec,
|
|
245
|
+
getCrypto: this.getCrypto,
|
|
228
246
|
dns: this.dns,
|
|
229
247
|
metrics: this.metrics,
|
|
230
248
|
...(init.components ?? {})
|
|
231
249
|
}
|
|
232
250
|
|
|
251
|
+
this.keychain = components.keychain = keychain()(components)
|
|
252
|
+
|
|
233
253
|
this.routing = components.routing = new RoutingClass(components, {
|
|
234
254
|
routers: (init.routers ?? []).flatMap((router: Partial<Routing> | ((components: any) => Partial<Routing>)) => {
|
|
235
255
|
if (typeof router === 'function') {
|
package/src/storage.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressE
|
|
|
6
6
|
import type { Pins } from '@helia/interface/pins'
|
|
7
7
|
import type { AbortOptions, Startable } from '@libp2p/interface'
|
|
8
8
|
import type { Blockstore, InputPair } from 'interface-blockstore'
|
|
9
|
-
import type { AwaitIterable } from 'interface-store'
|
|
10
9
|
import type { Mortice } from 'mortice'
|
|
11
10
|
import type { CID } from 'multiformats/cid'
|
|
12
11
|
import type { ProgressOptions } from 'progress-events'
|
|
@@ -79,7 +78,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
79
78
|
/**
|
|
80
79
|
* Put a multiple blocks to the underlying datastore
|
|
81
80
|
*/
|
|
82
|
-
async * putMany (blocks:
|
|
81
|
+
async * putMany (blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
83
82
|
options?.signal?.throwIfAborted()
|
|
84
83
|
const releaseLock = await this.lock.readLock()
|
|
85
84
|
|
|
@@ -107,7 +106,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
107
106
|
/**
|
|
108
107
|
* Get multiple blocks back from an (async) iterable of cids
|
|
109
108
|
*/
|
|
110
|
-
async * getMany (cids:
|
|
109
|
+
async * getMany (cids: Iterable<CID> | AsyncIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
111
110
|
options?.signal?.throwIfAborted()
|
|
112
111
|
const releaseLock = await this.lock.readLock()
|
|
113
112
|
|
|
@@ -142,7 +141,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
142
141
|
/**
|
|
143
142
|
* Delete multiple blocks from the blockstore
|
|
144
143
|
*/
|
|
145
|
-
async * deleteMany (cids:
|
|
144
|
+
async * deleteMany (cids: Iterable<CID> | AsyncIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
146
145
|
options?.signal?.throwIfAborted()
|
|
147
146
|
const releaseLock = await this.lock.writeLock()
|
|
148
147
|
|
package/src/utils/get-codec.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint max-depth: ["error", 7] */
|
|
2
|
-
|
|
3
1
|
import { UnknownCodecError } from '@helia/interface'
|
|
4
2
|
import * as dagCbor from '@ipld/dag-cbor'
|
|
5
3
|
import * as dagJson from '@ipld/dag-json'
|
|
@@ -7,10 +5,10 @@ import * as dagPb from '@ipld/dag-pb'
|
|
|
7
5
|
import * as json from 'multiformats/codecs/json'
|
|
8
6
|
import * as raw from 'multiformats/codecs/raw'
|
|
9
7
|
import { isPromise } from './is-promise.ts'
|
|
10
|
-
import type {
|
|
8
|
+
import type { CodecLoader } from '@helia/interface'
|
|
11
9
|
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
12
10
|
|
|
13
|
-
export function getCodec
|
|
11
|
+
export function getCodec (initialCodecs: Array<BlockCodec<any, any>> = [], loadCodec?: CodecLoader): CodecLoader {
|
|
14
12
|
const codecs: Record<number, BlockCodec<any, any>> = {
|
|
15
13
|
[dagPb.code]: dagPb,
|
|
16
14
|
[raw.code]: raw,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { UnknownCryptoError } from '@helia/interface'
|
|
2
|
+
import { ecdsaCrypto, ed25519Crypto, rsaCrypto } from '@ipshipyard/crypto'
|
|
3
|
+
import { isPromise } from './is-promise.ts'
|
|
4
|
+
import type { CryptoLoader } from '@helia/interface'
|
|
5
|
+
import type { Crypto } from '@ipshipyard/crypto'
|
|
6
|
+
|
|
7
|
+
export function getCrypto (initialCryptos: Array<Crypto> = [], loadCrypto?: CryptoLoader): CryptoLoader {
|
|
8
|
+
const cryptos: Record<string | number, Crypto> = {}
|
|
9
|
+
|
|
10
|
+
initialCryptos = [
|
|
11
|
+
ecdsaCrypto(),
|
|
12
|
+
ed25519Crypto(),
|
|
13
|
+
rsaCrypto(),
|
|
14
|
+
...initialCryptos
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
initialCryptos.forEach(crypto => {
|
|
18
|
+
cryptos[crypto.type] = crypto
|
|
19
|
+
cryptos[crypto.code] = crypto
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return async (nameOrCode) => {
|
|
23
|
+
let crypto = cryptos[nameOrCode]
|
|
24
|
+
|
|
25
|
+
if (crypto == null && loadCrypto != null) {
|
|
26
|
+
const res = loadCrypto(nameOrCode)
|
|
27
|
+
|
|
28
|
+
if (isPromise(res)) {
|
|
29
|
+
crypto = await res
|
|
30
|
+
} else {
|
|
31
|
+
crypto = res
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
cryptos[crypto.type] = crypto
|
|
35
|
+
cryptos[crypto.code] = crypto
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (crypto != null) {
|
|
39
|
+
return crypto
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new UnknownCryptoError(`Could not load crypto for ${crypto}`)
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/utils/get-hasher.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { UnknownHashAlgorithmError } from '@helia/interface'
|
|
|
2
2
|
import { identity } from 'multiformats/hashes/identity'
|
|
3
3
|
import { sha256, sha512 } from 'multiformats/hashes/sha2'
|
|
4
4
|
import { isPromise } from './is-promise.ts'
|
|
5
|
-
import type {
|
|
5
|
+
import type { HasherLoader } from '@helia/interface'
|
|
6
6
|
import type { MultihashHasher } from 'multiformats/hashes/interface'
|
|
7
7
|
|
|
8
|
-
export function getHasher (initialHashers: MultihashHasher[] = [], loadHasher?:
|
|
8
|
+
export function getHasher (initialHashers: MultihashHasher[] = [], loadHasher?: HasherLoader): HasherLoader {
|
|
9
9
|
const hashers: Record<number, MultihashHasher> = {
|
|
10
10
|
[sha256.code]: sha256,
|
|
11
11
|
[sha512.code]: sha512,
|
|
@@ -6,7 +6,6 @@ import type { Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, G
|
|
|
6
6
|
import type { AbortOptions, PeerId } from '@libp2p/interface'
|
|
7
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
8
8
|
import type { InputPair } from 'interface-blockstore'
|
|
9
|
-
import type { AwaitIterable } from 'interface-store'
|
|
10
9
|
import type { CID } from 'multiformats/cid'
|
|
11
10
|
import type { ProgressOptions } from 'progress-events'
|
|
12
11
|
|
|
@@ -63,7 +62,7 @@ export class SessionStorage extends Storage<SessionBlockBroker> implements Sessi
|
|
|
63
62
|
/**
|
|
64
63
|
* Put a multiple blocks to the underlying datastore
|
|
65
64
|
*/
|
|
66
|
-
async * putMany (blocks:
|
|
65
|
+
async * putMany (blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
67
66
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
68
67
|
setMaxListeners(Infinity, signal)
|
|
69
68
|
|
|
@@ -97,7 +96,7 @@ export class SessionStorage extends Storage<SessionBlockBroker> implements Sessi
|
|
|
97
96
|
/**
|
|
98
97
|
* Get multiple blocks back from an (async) iterable of cids
|
|
99
98
|
*/
|
|
100
|
-
async * getMany (cids:
|
|
99
|
+
async * getMany (cids: Iterable<CID> | AsyncIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
101
100
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
102
101
|
setMaxListeners(Infinity, signal)
|
|
103
102
|
|
|
@@ -131,7 +130,7 @@ export class SessionStorage extends Storage<SessionBlockBroker> implements Sessi
|
|
|
131
130
|
/**
|
|
132
131
|
* Delete multiple blocks from the blockstore
|
|
133
132
|
*/
|
|
134
|
-
async * deleteMany (cids:
|
|
133
|
+
async * deleteMany (cids: Iterable<CID> | AsyncIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
135
134
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
136
135
|
setMaxListeners(Infinity, signal)
|
|
137
136
|
|
package/src/utils/storage.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { HasherLoader } from '@helia/interface'
|
|
|
11
11
|
import type { BlockBroker, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, BlockRetrievalOptions } from '@helia/interface/blocks'
|
|
12
12
|
import type { AbortOptions, ComponentLogger, Logger, LoggerOptions } from '@libp2p/interface'
|
|
13
13
|
import type { Blockstore, InputPair } from 'interface-blockstore'
|
|
14
|
-
import type { AwaitIterable } from 'interface-store'
|
|
15
14
|
import type { CID } from 'multiformats/cid'
|
|
16
15
|
import type { MultihashDigest, MultihashHasher } from 'multiformats/hashes/interface'
|
|
17
16
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
@@ -72,7 +71,7 @@ export class Storage <Broker extends BlockBroker<ProgressEvent<any, any>, Progre
|
|
|
72
71
|
/**
|
|
73
72
|
* Put a multiple blocks to the underlying datastore
|
|
74
73
|
*/
|
|
75
|
-
async * putMany (blocks:
|
|
74
|
+
async * putMany (blocks: Iterable<InputPair> | AsyncIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
76
75
|
const missingBlocks = filter(blocks, async ({ cid }): Promise<boolean> => {
|
|
77
76
|
const has = await this.child.has(cid, options)
|
|
78
77
|
|
|
@@ -137,7 +136,7 @@ export class Storage <Broker extends BlockBroker<ProgressEvent<any, any>, Progre
|
|
|
137
136
|
/**
|
|
138
137
|
* Get multiple blocks back from an (async) iterable of cids
|
|
139
138
|
*/
|
|
140
|
-
async * getMany (cids:
|
|
139
|
+
async * getMany (cids: Iterable<CID> | AsyncIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
141
140
|
options.onProgress?.(new CustomProgressEvent('blocks:get-many:blockstore:get-many'))
|
|
142
141
|
|
|
143
142
|
yield * this.child.getMany(forEach(cids, async (cid): Promise<void> => {
|
|
@@ -182,7 +181,7 @@ export class Storage <Broker extends BlockBroker<ProgressEvent<any, any>, Progre
|
|
|
182
181
|
/**
|
|
183
182
|
* Delete multiple blocks from the blockstore
|
|
184
183
|
*/
|
|
185
|
-
async * deleteMany (cids:
|
|
184
|
+
async * deleteMany (cids: Iterable<CID> | AsyncIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
186
185
|
options.onProgress?.(new CustomProgressEvent('blocks:delete-many:blockstore:delete-many'))
|
|
187
186
|
yield * this.child.deleteMany((async function * (): AsyncGenerator<CID> {
|
|
188
187
|
for await (const cid of cids) {
|