@helia/utils 1.4.0-7d471a02 → 1.4.0-93aa4645
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/abstract-session.d.ts.map +1 -1
- package/dist/src/abstract-session.js +1 -3
- package/dist/src/abstract-session.js.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/pins.d.ts.map +1 -1
- package/dist/src/pins.js +3 -2
- package/dist/src/pins.js.map +1 -1
- package/dist/src/routing.d.ts.map +1 -1
- package/dist/src/routing.js +1 -2
- package/dist/src/routing.js.map +1 -1
- package/dist/src/storage.d.ts +6 -9
- package/dist/src/storage.d.ts.map +1 -1
- package/dist/src/storage.js +2 -2
- package/dist/src/storage.js.map +1 -1
- package/dist/src/utils/networked-storage.d.ts +6 -9
- package/dist/src/utils/networked-storage.d.ts.map +1 -1
- package/dist/src/utils/networked-storage.js +11 -10
- package/dist/src/utils/networked-storage.js.map +1 -1
- package/package.json +33 -38
- package/src/abstract-session.ts +2 -4
- package/src/index.ts +6 -2
- package/src/pins.ts +3 -2
- package/src/routing.ts +1 -2
- package/src/storage.ts +7 -7
- package/src/utils/networked-storage.ts +20 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/utils",
|
|
3
|
-
"version": "1.4.0-
|
|
3
|
+
"version": "1.4.0-93aa4645",
|
|
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",
|
|
@@ -32,13 +32,6 @@
|
|
|
32
32
|
"import": "./dist/src/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
"eslintConfig": {
|
|
36
|
-
"extends": "ipfs",
|
|
37
|
-
"parserOptions": {
|
|
38
|
-
"project": true,
|
|
39
|
-
"sourceType": "module"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
35
|
"scripts": {
|
|
43
36
|
"clean": "aegir clean",
|
|
44
37
|
"lint": "aegir lint",
|
|
@@ -54,43 +47,45 @@
|
|
|
54
47
|
"test:electron-main": "aegir test -t electron-main"
|
|
55
48
|
},
|
|
56
49
|
"dependencies": {
|
|
57
|
-
"@helia/interface": "5.4.0-
|
|
58
|
-
"@ipld/dag-cbor": "^9.2.
|
|
59
|
-
"@ipld/dag-json": "^10.2.
|
|
60
|
-
"@ipld/dag-pb": "^4.1.
|
|
61
|
-
"@libp2p/interface": "^
|
|
62
|
-
"@libp2p/keychain": "^
|
|
63
|
-
"@libp2p/logger": "^
|
|
64
|
-
"@libp2p/utils": "^
|
|
65
|
-
"@multiformats/dns": "^1.0.
|
|
66
|
-
"@multiformats/multiaddr": "^
|
|
50
|
+
"@helia/interface": "5.4.0-93aa4645",
|
|
51
|
+
"@ipld/dag-cbor": "^9.2.5",
|
|
52
|
+
"@ipld/dag-json": "^10.2.5",
|
|
53
|
+
"@ipld/dag-pb": "^4.1.5",
|
|
54
|
+
"@libp2p/interface": "^3.0.2",
|
|
55
|
+
"@libp2p/keychain": "^6.0.5",
|
|
56
|
+
"@libp2p/logger": "^6.0.5",
|
|
57
|
+
"@libp2p/utils": "^7.0.5",
|
|
58
|
+
"@multiformats/dns": "^1.0.9",
|
|
59
|
+
"@multiformats/multiaddr": "^13.0.1",
|
|
67
60
|
"any-signal": "^4.1.1",
|
|
68
|
-
"blockstore-core": "^
|
|
69
|
-
"cborg": "^4.2.
|
|
70
|
-
"interface-blockstore": "^
|
|
71
|
-
"interface-datastore": "^
|
|
72
|
-
"interface-store": "^
|
|
73
|
-
"it-drain": "^3.0.
|
|
74
|
-
"it-filter": "^3.1.
|
|
75
|
-
"it-foreach": "^2.1.
|
|
76
|
-
"it-merge": "^3.0.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
61
|
+
"blockstore-core": "^6.0.2",
|
|
62
|
+
"cborg": "^4.2.15",
|
|
63
|
+
"interface-blockstore": "^6.0.1",
|
|
64
|
+
"interface-datastore": "^9.0.2",
|
|
65
|
+
"interface-store": "^7.0.0",
|
|
66
|
+
"it-drain": "^3.0.10",
|
|
67
|
+
"it-filter": "^3.1.4",
|
|
68
|
+
"it-foreach": "^2.1.4",
|
|
69
|
+
"it-merge": "^3.0.12",
|
|
70
|
+
"it-to-buffer": "^4.0.10",
|
|
71
|
+
"libp2p": "^3.0.6",
|
|
72
|
+
"mortice": "^3.3.1",
|
|
73
|
+
"multiformats": "^13.4.1",
|
|
80
74
|
"p-defer": "^4.0.1",
|
|
81
75
|
"progress-events": "^1.0.1",
|
|
82
76
|
"uint8arrays": "^5.1.0"
|
|
83
77
|
},
|
|
84
78
|
"devDependencies": {
|
|
85
|
-
"@libp2p/crypto": "^5.
|
|
86
|
-
"@libp2p/peer-id": "^
|
|
87
|
-
"@types/sinon": "^17.0.
|
|
88
|
-
"aegir": "^47.0.
|
|
89
|
-
"datastore-core": "^
|
|
79
|
+
"@libp2p/crypto": "^5.1.12",
|
|
80
|
+
"@libp2p/peer-id": "^6.0.3",
|
|
81
|
+
"@types/sinon": "^17.0.4",
|
|
82
|
+
"aegir": "^47.0.22",
|
|
83
|
+
"datastore-core": "^11.0.2",
|
|
90
84
|
"delay": "^6.0.0",
|
|
91
|
-
"it-all": "^3.0.
|
|
92
|
-
"
|
|
93
|
-
"
|
|
85
|
+
"it-all": "^3.0.9",
|
|
86
|
+
"it-map": "^3.1.4",
|
|
87
|
+
"race-signal": "^2.0.0",
|
|
88
|
+
"sinon": "^21.0.0",
|
|
94
89
|
"sinon-ts": "^2.0.0"
|
|
95
90
|
},
|
|
96
91
|
"browser": {
|
package/src/abstract-session.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { DEFAULT_SESSION_MIN_PROVIDERS, DEFAULT_SESSION_MAX_PROVIDERS, InsufficientProvidersError } from '@helia/interface'
|
|
2
2
|
import { AbortError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
|
|
3
|
-
import { createScalableCuckooFilter } from '@libp2p/utils
|
|
4
|
-
import { Queue } from '@libp2p/utils/queue'
|
|
3
|
+
import { createScalableCuckooFilter, Queue } from '@libp2p/utils'
|
|
5
4
|
import { base64 } from 'multiformats/bases/base64'
|
|
6
5
|
import pDefer from 'p-defer'
|
|
7
6
|
import type { BlockBroker, BlockRetrievalOptions, CreateSessionOptions } from '@helia/interface'
|
|
8
7
|
import type { AbortOptions, ComponentLogger, Logger, PeerId } from '@libp2p/interface'
|
|
9
|
-
import type { Filter } from '@libp2p/utils
|
|
8
|
+
import type { Filter } from '@libp2p/utils'
|
|
10
9
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
11
10
|
import type { CID } from 'multiformats/cid'
|
|
12
11
|
import type { DeferredPromise } from 'p-defer'
|
|
@@ -88,7 +87,6 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
|
|
|
88
87
|
const queue = new Queue<Uint8Array, { provider: Provider, priority?: number } & AbortOptions>({
|
|
89
88
|
concurrency: this.maxProviders
|
|
90
89
|
})
|
|
91
|
-
queue.addEventListener('error', () => {})
|
|
92
90
|
queue.addEventListener('failure', (evt) => {
|
|
93
91
|
this.log.error('error querying provider %o, evicting from session', evt.detail.job.options.provider, evt.detail.error)
|
|
94
92
|
this.evict(evt.detail.job.options.provider)
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* modules such as `helia`, `@helia/http`, etc.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { contentRoutingSymbol, peerRoutingSymbol, start, stop } from '@libp2p/interface'
|
|
8
|
+
import { contentRoutingSymbol, peerRoutingSymbol, start, stop, TypedEventEmitter } from '@libp2p/interface'
|
|
9
9
|
import { defaultLogger } from '@libp2p/logger'
|
|
10
10
|
import { dns } from '@multiformats/dns'
|
|
11
11
|
import drain from 'it-drain'
|
|
@@ -18,7 +18,7 @@ import { getCodec } from './utils/get-codec.js'
|
|
|
18
18
|
import { getHasher } from './utils/get-hasher.js'
|
|
19
19
|
import { NetworkedStorage } from './utils/networked-storage.js'
|
|
20
20
|
import type { BlockStorageInit } from './storage.js'
|
|
21
|
-
import type { Await, CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, Routing } from '@helia/interface'
|
|
21
|
+
import type { Await, CodecLoader, GCOptions, HasherLoader, Helia as HeliaInterface, HeliaEvents, Routing } from '@helia/interface'
|
|
22
22
|
import type { BlockBroker } from '@helia/interface/blocks'
|
|
23
23
|
import type { Pins } from '@helia/interface/pins'
|
|
24
24
|
import type { ComponentLogger, Libp2p, Logger, Metrics } from '@libp2p/interface'
|
|
@@ -187,6 +187,7 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
187
187
|
public libp2p: T
|
|
188
188
|
public blockstore: BlockStorage
|
|
189
189
|
public datastore: Datastore
|
|
190
|
+
public events: TypedEventEmitter<HeliaEvents<T>>
|
|
190
191
|
public pins: Pins
|
|
191
192
|
public logger: ComponentLogger
|
|
192
193
|
public routing: Routing
|
|
@@ -204,6 +205,7 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
204
205
|
this.dns = init.dns ?? dns()
|
|
205
206
|
this.metrics = init.metrics
|
|
206
207
|
this.libp2p = init.libp2p
|
|
208
|
+
this.events = new TypedEventEmitter<HeliaEvents<T>>()
|
|
207
209
|
|
|
208
210
|
// @ts-expect-error routing is not set
|
|
209
211
|
const components: Components = {
|
|
@@ -261,6 +263,7 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
261
263
|
this.routing,
|
|
262
264
|
this.libp2p
|
|
263
265
|
)
|
|
266
|
+
this.events.dispatchEvent(new CustomEvent('start', { detail: this }))
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
async stop (): Promise<void> {
|
|
@@ -270,6 +273,7 @@ export class Helia<T extends Libp2p> implements HeliaInterface<T> {
|
|
|
270
273
|
this.routing,
|
|
271
274
|
this.libp2p
|
|
272
275
|
)
|
|
276
|
+
this.events.dispatchEvent(new CustomEvent('stop', { detail: this }))
|
|
273
277
|
}
|
|
274
278
|
|
|
275
279
|
async gc (options: GCOptions = {}): Promise<void> {
|
package/src/pins.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Queue } from '@libp2p/utils
|
|
1
|
+
import { Queue } from '@libp2p/utils'
|
|
2
2
|
import * as cborg from 'cborg'
|
|
3
3
|
import { Key } from 'interface-datastore'
|
|
4
|
+
import toBuffer from 'it-to-buffer'
|
|
4
5
|
import { base36 } from 'multiformats/bases/base36'
|
|
5
6
|
import { createUnsafe } from 'multiformats/block'
|
|
6
7
|
import { CID } from 'multiformats/cid'
|
|
@@ -124,7 +125,7 @@ export class PinsImpl implements Pins {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
const codec = await this.getCodec(cid.code)
|
|
127
|
-
const bytes = await this.blockstore.get(cid, options)
|
|
128
|
+
const bytes = await toBuffer(this.blockstore.get(cid, options))
|
|
128
129
|
const block = createUnsafe({ bytes, cid, codec })
|
|
129
130
|
|
|
130
131
|
yield cid
|
package/src/routing.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NoRoutersAvailableError } from '@helia/interface'
|
|
2
2
|
import { NotFoundError, start, stop } from '@libp2p/interface'
|
|
3
|
-
import { PeerQueue } from '@libp2p/utils
|
|
3
|
+
import { PeerQueue } from '@libp2p/utils'
|
|
4
4
|
import merge from 'it-merge'
|
|
5
5
|
import type { Routing as RoutingInterface, Provider, RoutingOptions } from '@helia/interface'
|
|
6
6
|
import type { AbortOptions, ComponentLogger, Logger, Metrics, PeerId, PeerInfo, Startable } from '@libp2p/interface'
|
|
@@ -75,7 +75,6 @@ export class Routing implements RoutingInterface, Startable {
|
|
|
75
75
|
const queue = new PeerQueue<Provider | null>({
|
|
76
76
|
concurrency: this.providerLookupConcurrency
|
|
77
77
|
})
|
|
78
|
-
queue.addEventListener('error', () => {})
|
|
79
78
|
|
|
80
79
|
for await (const peer of merge(
|
|
81
80
|
queue.toGenerator(),
|
package/src/storage.ts
CHANGED
|
@@ -3,7 +3,7 @@ import createMortice from 'mortice'
|
|
|
3
3
|
import type { Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, SessionBlockstore } from '@helia/interface/blocks'
|
|
4
4
|
import type { Pins } from '@helia/interface/pins'
|
|
5
5
|
import type { AbortOptions, Startable } from '@libp2p/interface'
|
|
6
|
-
import type { Blockstore } from 'interface-blockstore'
|
|
6
|
+
import type { Blockstore, InputPair } from 'interface-blockstore'
|
|
7
7
|
import type { AwaitIterable } from 'interface-store'
|
|
8
8
|
import type { Mortice } from 'mortice'
|
|
9
9
|
import type { CID } from 'multiformats/cid'
|
|
@@ -75,7 +75,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
75
75
|
/**
|
|
76
76
|
* Put a multiple blocks to the underlying datastore
|
|
77
77
|
*/
|
|
78
|
-
async * putMany (blocks: AwaitIterable<
|
|
78
|
+
async * putMany (blocks: AwaitIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
79
79
|
options?.signal?.throwIfAborted()
|
|
80
80
|
const releaseLock = await this.lock.readLock()
|
|
81
81
|
|
|
@@ -89,12 +89,12 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
89
89
|
/**
|
|
90
90
|
* Get a block by cid
|
|
91
91
|
*/
|
|
92
|
-
async get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}):
|
|
92
|
+
async * get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}): AsyncGenerator<Uint8Array> {
|
|
93
93
|
options?.signal?.throwIfAborted()
|
|
94
94
|
const releaseLock = await this.lock.readLock()
|
|
95
95
|
|
|
96
96
|
try {
|
|
97
|
-
|
|
97
|
+
yield * this.child.get(cid, options)
|
|
98
98
|
} finally {
|
|
99
99
|
releaseLock()
|
|
100
100
|
}
|
|
@@ -103,7 +103,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
103
103
|
/**
|
|
104
104
|
* Get multiple blocks back from an (async) iterable of cids
|
|
105
105
|
*/
|
|
106
|
-
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}):
|
|
106
|
+
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
107
107
|
options?.signal?.throwIfAborted()
|
|
108
108
|
const releaseLock = await this.lock.readLock()
|
|
109
109
|
|
|
@@ -135,7 +135,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
135
135
|
/**
|
|
136
136
|
* Delete multiple blocks from the blockstore
|
|
137
137
|
*/
|
|
138
|
-
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}):
|
|
138
|
+
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
139
139
|
options?.signal?.throwIfAborted()
|
|
140
140
|
const releaseLock = await this.lock.writeLock()
|
|
141
141
|
|
|
@@ -167,7 +167,7 @@ export class BlockStorage implements Blocks, Startable {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}):
|
|
170
|
+
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
171
171
|
options?.signal?.throwIfAborted()
|
|
172
172
|
const releaseLock = await this.lock.readLock()
|
|
173
173
|
|
|
@@ -9,7 +9,7 @@ import { isPromise } from './is-promise.js'
|
|
|
9
9
|
import type { HasherLoader } from '@helia/interface'
|
|
10
10
|
import type { BlockBroker, Blocks, Pair, DeleteManyBlocksProgressEvents, DeleteBlockProgressEvents, GetBlockProgressEvents, GetManyBlocksProgressEvents, PutManyBlocksProgressEvents, PutBlockProgressEvents, GetAllBlocksProgressEvents, GetOfflineOptions, BlockRetrievalOptions, CreateSessionOptions, SessionBlockstore } from '@helia/interface/blocks'
|
|
11
11
|
import type { AbortOptions, ComponentLogger, Logger, LoggerOptions, Startable } from '@libp2p/interface'
|
|
12
|
-
import type { Blockstore } from 'interface-blockstore'
|
|
12
|
+
import type { Blockstore, InputPair } from 'interface-blockstore'
|
|
13
13
|
import type { AwaitIterable } from 'interface-store'
|
|
14
14
|
import type { CID } from 'multiformats/cid'
|
|
15
15
|
import type { MultihashDigest, MultihashHasher } from 'multiformats/hashes/interface'
|
|
@@ -56,7 +56,7 @@ class Storage implements Blockstore {
|
|
|
56
56
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put:providers:notify', cid))
|
|
57
57
|
|
|
58
58
|
await Promise.all(
|
|
59
|
-
this.components.blockBrokers.map(async broker => broker.announce?.(cid,
|
|
59
|
+
this.components.blockBrokers.map(async broker => broker.announce?.(cid, options))
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put:blockstore:put', cid))
|
|
@@ -67,7 +67,7 @@ class Storage implements Blockstore {
|
|
|
67
67
|
/**
|
|
68
68
|
* Put a multiple blocks to the underlying datastore
|
|
69
69
|
*/
|
|
70
|
-
async * putMany (blocks: AwaitIterable<
|
|
70
|
+
async * putMany (blocks: AwaitIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
71
71
|
const missingBlocks = filter(blocks, async ({ cid }): Promise<boolean> => {
|
|
72
72
|
const has = await this.child.has(cid, options)
|
|
73
73
|
|
|
@@ -78,10 +78,10 @@ class Storage implements Blockstore {
|
|
|
78
78
|
return !has
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
const notifyEach = forEach(missingBlocks, async ({ cid
|
|
81
|
+
const notifyEach = forEach(missingBlocks, async ({ cid }): Promise<void> => {
|
|
82
82
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:put-many:providers:notify', cid))
|
|
83
83
|
await Promise.all(
|
|
84
|
-
this.components.blockBrokers.map(async broker => broker.announce?.(cid,
|
|
84
|
+
this.components.blockBrokers.map(async broker => broker.announce?.(cid, options))
|
|
85
85
|
)
|
|
86
86
|
})
|
|
87
87
|
|
|
@@ -92,7 +92,7 @@ class Storage implements Blockstore {
|
|
|
92
92
|
/**
|
|
93
93
|
* Get a block by cid
|
|
94
94
|
*/
|
|
95
|
-
async get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}):
|
|
95
|
+
async * get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}): AsyncGenerator<Uint8Array> {
|
|
96
96
|
if (options.offline !== true && !(await this.child.has(cid, options))) {
|
|
97
97
|
const hasher = await this.getHasher(cid.multihash.code)
|
|
98
98
|
|
|
@@ -108,21 +108,22 @@ class Storage implements Blockstore {
|
|
|
108
108
|
// notify other block providers of the new block
|
|
109
109
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get:providers:notify', cid))
|
|
110
110
|
await Promise.all(
|
|
111
|
-
this.components.blockBrokers.map(async broker => broker.announce?.(cid,
|
|
111
|
+
this.components.blockBrokers.map(async broker => broker.announce?.(cid, options))
|
|
112
112
|
)
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
yield block
|
|
115
|
+
return
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get:blockstore:get', cid))
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
yield * this.child.get(cid, options)
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Get multiple blocks back from an (async) iterable of cids
|
|
124
125
|
*/
|
|
125
|
-
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}):
|
|
126
|
+
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
126
127
|
options.onProgress?.(new CustomProgressEvent('blocks:get-many:blockstore:get-many'))
|
|
127
128
|
|
|
128
129
|
yield * this.child.getMany(forEach(cids, async (cid): Promise<void> => {
|
|
@@ -141,7 +142,7 @@ class Storage implements Blockstore {
|
|
|
141
142
|
// notify other block providers of the new block
|
|
142
143
|
options.onProgress?.(new CustomProgressEvent<CID>('blocks:get-many:providers:notify', cid))
|
|
143
144
|
await Promise.all(
|
|
144
|
-
this.components.blockBrokers.map(async broker => broker.announce?.(cid,
|
|
145
|
+
this.components.blockBrokers.map(async broker => broker.announce?.(cid, options))
|
|
145
146
|
)
|
|
146
147
|
}
|
|
147
148
|
}))
|
|
@@ -159,7 +160,7 @@ class Storage implements Blockstore {
|
|
|
159
160
|
/**
|
|
160
161
|
* Delete multiple blocks from the blockstore
|
|
161
162
|
*/
|
|
162
|
-
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}):
|
|
163
|
+
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
163
164
|
options.onProgress?.(new CustomProgressEvent('blocks:delete-many:blockstore:delete-many'))
|
|
164
165
|
yield * this.child.deleteMany((async function * (): AsyncGenerator<CID> {
|
|
165
166
|
for await (const cid of cids) {
|
|
@@ -172,7 +173,7 @@ class Storage implements Blockstore {
|
|
|
172
173
|
return this.child.has(cid, options)
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}):
|
|
176
|
+
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
176
177
|
options.onProgress?.(new CustomProgressEvent('blocks:get-all:blockstore:get-many'))
|
|
177
178
|
yield * this.child.getAll(options)
|
|
178
179
|
}
|
|
@@ -280,7 +281,7 @@ class SessionStorage extends Storage implements SessionBlockstore {
|
|
|
280
281
|
/**
|
|
281
282
|
* Put a multiple blocks to the underlying datastore
|
|
282
283
|
*/
|
|
283
|
-
async * putMany (blocks: AwaitIterable<
|
|
284
|
+
async * putMany (blocks: AwaitIterable<InputPair>, options: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
284
285
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
285
286
|
setMaxListeners(Infinity, signal)
|
|
286
287
|
|
|
@@ -297,12 +298,12 @@ class SessionStorage extends Storage implements SessionBlockstore {
|
|
|
297
298
|
/**
|
|
298
299
|
* Get a block by cid
|
|
299
300
|
*/
|
|
300
|
-
async get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}):
|
|
301
|
+
async * get (cid: CID, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetBlockProgressEvents> = {}): AsyncGenerator<Uint8Array> {
|
|
301
302
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
302
303
|
setMaxListeners(Infinity, signal)
|
|
303
304
|
|
|
304
305
|
try {
|
|
305
|
-
|
|
306
|
+
yield * super.get(cid, {
|
|
306
307
|
...options,
|
|
307
308
|
signal
|
|
308
309
|
})
|
|
@@ -314,7 +315,7 @@ class SessionStorage extends Storage implements SessionBlockstore {
|
|
|
314
315
|
/**
|
|
315
316
|
* Get multiple blocks back from an (async) iterable of cids
|
|
316
317
|
*/
|
|
317
|
-
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}):
|
|
318
|
+
async * getMany (cids: AwaitIterable<CID>, options: GetOfflineOptions & AbortOptions & ProgressOptions<GetManyBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
318
319
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
319
320
|
setMaxListeners(Infinity, signal)
|
|
320
321
|
|
|
@@ -348,7 +349,7 @@ class SessionStorage extends Storage implements SessionBlockstore {
|
|
|
348
349
|
/**
|
|
349
350
|
* Delete multiple blocks from the blockstore
|
|
350
351
|
*/
|
|
351
|
-
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}):
|
|
352
|
+
async * deleteMany (cids: AwaitIterable<CID>, options: AbortOptions & ProgressOptions<DeleteManyBlocksProgressEvents> = {}): AsyncGenerator<CID> {
|
|
352
353
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
353
354
|
setMaxListeners(Infinity, signal)
|
|
354
355
|
|
|
@@ -376,7 +377,7 @@ class SessionStorage extends Storage implements SessionBlockstore {
|
|
|
376
377
|
}
|
|
377
378
|
}
|
|
378
379
|
|
|
379
|
-
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}):
|
|
380
|
+
async * getAll (options: AbortOptions & ProgressOptions<GetAllBlocksProgressEvents> = {}): AsyncGenerator<Pair> {
|
|
380
381
|
const signal = anySignal([this.closeController.signal, options.signal])
|
|
381
382
|
setMaxListeners(Infinity, signal)
|
|
382
383
|
|