@libp2p/utils 7.0.15 → 7.0.17-500287203
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 +4 -9
- package/dist/index.min.js.map +4 -4
- package/dist/src/abstract-stream.d.ts +2 -2
- package/dist/src/abstract-stream.js +1 -1
- package/dist/src/adaptive-timeout.js +1 -1
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/filters/bloom-filter.d.ts +1 -1
- package/dist/src/filters/bloom-filter.js +1 -1
- package/dist/src/filters/bucket.d.ts +1 -1
- package/dist/src/filters/bucket.js +2 -2
- package/dist/src/filters/cuckoo-filter.d.ts +2 -2
- package/dist/src/filters/cuckoo-filter.js +4 -4
- package/dist/src/filters/fingerprint.d.ts +1 -1
- package/dist/src/filters/index.d.ts +6 -6
- package/dist/src/filters/index.js +3 -3
- package/dist/src/filters/scalable-cuckoo-filter.d.ts +2 -2
- package/dist/src/filters/scalable-cuckoo-filter.js +3 -3
- package/dist/src/get-thin-waist-addresses.js +1 -1
- package/dist/src/index.d.ts +31 -31
- package/dist/src/index.js +31 -31
- package/dist/src/message-queue.js +1 -1
- package/dist/src/mock-muxer.js +1 -1
- package/dist/src/multiaddr/index.d.ts +5 -5
- package/dist/src/multiaddr/index.js +5 -5
- package/dist/src/peer-queue.d.ts +2 -2
- package/dist/src/peer-queue.js +1 -1
- package/dist/src/priority-queue.d.ts +2 -2
- package/dist/src/priority-queue.js +1 -1
- package/dist/src/queue/index.d.ts +5 -4
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/queue/index.js +4 -3
- package/dist/src/queue/index.js.map +1 -1
- package/dist/src/queue/job.d.ts +5 -4
- package/dist/src/queue/job.d.ts.map +1 -1
- package/dist/src/queue/job.js +10 -5
- package/dist/src/queue/job.js.map +1 -1
- package/dist/src/queue/recipient.d.ts +5 -2
- package/dist/src/queue/recipient.d.ts.map +1 -1
- package/dist/src/queue/recipient.js +4 -2
- package/dist/src/queue/recipient.js.map +1 -1
- package/dist/src/rate-limiter.js +1 -1
- package/dist/src/stream-utils.js +1 -1
- package/package.json +9 -7
- package/src/abstract-stream.ts +2 -2
- package/src/adaptive-timeout.ts +1 -1
- package/src/errors.ts +1 -1
- package/src/filters/bloom-filter.ts +2 -2
- package/src/filters/bucket.ts +2 -2
- package/src/filters/cuckoo-filter.ts +6 -6
- package/src/filters/fingerprint.ts +1 -1
- package/src/filters/index.ts +6 -6
- package/src/filters/scalable-cuckoo-filter.ts +6 -6
- package/src/get-thin-waist-addresses.ts +1 -1
- package/src/index.ts +31 -31
- package/src/message-queue.ts +1 -1
- package/src/mock-muxer.ts +1 -1
- package/src/multiaddr/index.ts +5 -5
- package/src/peer-queue.ts +2 -2
- package/src/priority-queue.ts +2 -2
- package/src/queue/index.ts +10 -6
- package/src/queue/job.ts +13 -7
- package/src/queue/recipient.ts +7 -3
- package/src/rate-limiter.ts +1 -1
- package/src/stream-utils.ts +1 -1
- package/dist/typedoc-urls.json +0 -124
package/dist/src/rate-limiter.js
CHANGED
package/dist/src/stream-utils.js
CHANGED
|
@@ -5,7 +5,7 @@ import { pEvent } from 'p-event';
|
|
|
5
5
|
import { raceSignal } from 'race-signal';
|
|
6
6
|
import * as varint from 'uint8-varint';
|
|
7
7
|
import { Uint8ArrayList } from 'uint8arraylist';
|
|
8
|
-
import { UnexpectedEOFError } from
|
|
8
|
+
import { UnexpectedEOFError } from "./errors.js";
|
|
9
9
|
const DEFAULT_MAX_BUFFER_SIZE = 4_194_304;
|
|
10
10
|
export class UnwrappedError extends Error {
|
|
11
11
|
static name = 'UnwrappedError';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.17-500287203",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/src/index.d.ts",
|
|
29
|
-
"import": "./dist/src/index.js"
|
|
29
|
+
"import": "./dist/src/index.js",
|
|
30
|
+
"module-sync": "./dist/src/index.js"
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
@@ -46,13 +47,13 @@
|
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@chainsafe/is-ip": "^2.1.0",
|
|
48
49
|
"@chainsafe/netmask": "^2.0.0",
|
|
49
|
-
"@libp2p/crypto": "
|
|
50
|
-
"@libp2p/interface": "
|
|
51
|
-
"@libp2p/logger": "
|
|
50
|
+
"@libp2p/crypto": "5.1.17-500287203",
|
|
51
|
+
"@libp2p/interface": "3.2.2-500287203",
|
|
52
|
+
"@libp2p/logger": "6.2.6-500287203",
|
|
52
53
|
"@multiformats/multiaddr": "^13.0.1",
|
|
53
54
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
54
55
|
"any-signal": "^4.1.1",
|
|
55
|
-
"cborg": "^
|
|
56
|
+
"cborg": "^5.1.0",
|
|
56
57
|
"delay": "^7.0.0",
|
|
57
58
|
"is-loopback-addr": "^2.0.2",
|
|
58
59
|
"it-length-prefixed": "^10.0.1",
|
|
@@ -63,13 +64,14 @@
|
|
|
63
64
|
"netmask": "^2.0.2",
|
|
64
65
|
"p-defer": "^4.0.1",
|
|
65
66
|
"p-event": "^7.0.0",
|
|
67
|
+
"progress-events": "^1.1.0",
|
|
66
68
|
"race-signal": "^2.0.0",
|
|
67
69
|
"uint8-varint": "^2.0.4",
|
|
68
70
|
"uint8arraylist": "^2.4.8",
|
|
69
71
|
"uint8arrays": "^5.1.0"
|
|
70
72
|
},
|
|
71
73
|
"devDependencies": {
|
|
72
|
-
"@libp2p/peer-id": "
|
|
74
|
+
"@libp2p/peer-id": "6.0.8-500287203",
|
|
73
75
|
"@types/netmask": "^2.0.5",
|
|
74
76
|
"aegir": "^47.0.22",
|
|
75
77
|
"benchmark": "^2.1.4",
|
package/src/abstract-stream.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pEvent } from 'p-event'
|
|
2
|
-
import { AbstractMessageStream } from './abstract-message-stream.
|
|
3
|
-
import type { MessageStreamInit } from './abstract-message-stream.
|
|
2
|
+
import { AbstractMessageStream } from './abstract-message-stream.ts'
|
|
3
|
+
import type { MessageStreamInit } from './abstract-message-stream.ts'
|
|
4
4
|
import type { AbortOptions, Stream } from '@libp2p/interface'
|
|
5
5
|
|
|
6
6
|
export interface AbstractStreamInit extends MessageStreamInit {
|
package/src/adaptive-timeout.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { anySignal } from 'any-signal'
|
|
2
2
|
import { setMaxListeners } from 'main-event'
|
|
3
|
-
import { MovingAverage } from './moving-average.
|
|
3
|
+
import { MovingAverage } from './moving-average.ts'
|
|
4
4
|
import type { MetricGroup, Metrics } from '@libp2p/interface'
|
|
5
5
|
import type { ClearableSignal } from 'any-signal'
|
|
6
6
|
|
package/src/errors.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { randomBytes } from '@libp2p/crypto'
|
|
|
3
3
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
4
4
|
import { alloc } from 'uint8arrays/alloc'
|
|
5
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
-
import { fnv1a } from './hashes.
|
|
7
|
-
import type { Filter } from './index.
|
|
6
|
+
import { fnv1a } from './hashes.ts'
|
|
7
|
+
import type { Filter } from './index.ts'
|
|
8
8
|
|
|
9
9
|
const LN2_SQUARED = Math.LN2 * Math.LN2
|
|
10
10
|
|
package/src/filters/bucket.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
|
-
import { Bucket } from './bucket.
|
|
3
|
-
import { Fingerprint, MAX_FINGERPRINT_SIZE } from './fingerprint.
|
|
4
|
-
import { fnv1a } from './hashes.
|
|
5
|
-
import { getRandomInt } from './utils.
|
|
6
|
-
import type { Hash } from './hashes.
|
|
7
|
-
import type { Filter } from './index.
|
|
2
|
+
import { Bucket } from './bucket.ts'
|
|
3
|
+
import { Fingerprint, MAX_FINGERPRINT_SIZE } from './fingerprint.ts'
|
|
4
|
+
import { fnv1a } from './hashes.ts'
|
|
5
|
+
import { getRandomInt } from './utils.ts'
|
|
6
|
+
import type { Hash } from './hashes.ts'
|
|
7
|
+
import type { Filter } from './index.ts'
|
|
8
8
|
|
|
9
9
|
const maxCuckooCount = 500
|
|
10
10
|
|
package/src/filters/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { BloomFilter, createBloomFilter, type BloomFilterOptions } from './bloom-filter.
|
|
2
|
-
export { CuckooFilter, createCuckooFilter, type CuckooFilterInit } from './cuckoo-filter.
|
|
3
|
-
export { ScalableCuckooFilter, createScalableCuckooFilter, type ScalableCuckooFilterInit } from './scalable-cuckoo-filter.
|
|
4
|
-
export type { Bucket } from './bucket.
|
|
5
|
-
export type { Fingerprint } from './fingerprint.
|
|
6
|
-
export type { Hash } from './hashes.
|
|
1
|
+
export { BloomFilter, createBloomFilter, type BloomFilterOptions } from './bloom-filter.ts'
|
|
2
|
+
export { CuckooFilter, createCuckooFilter, type CuckooFilterInit } from './cuckoo-filter.ts'
|
|
3
|
+
export { ScalableCuckooFilter, createScalableCuckooFilter, type ScalableCuckooFilterInit } from './scalable-cuckoo-filter.ts'
|
|
4
|
+
export type { Bucket } from './bucket.ts'
|
|
5
|
+
export type { Fingerprint } from './fingerprint.ts'
|
|
6
|
+
export type { Hash } from './hashes.ts'
|
|
7
7
|
|
|
8
8
|
export interface Filter {
|
|
9
9
|
add(item: Uint8Array | string): void
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
|
-
import { CuckooFilter, optimize } from './cuckoo-filter.
|
|
3
|
-
import { fnv1a } from './hashes.
|
|
4
|
-
import { getRandomInt } from './utils.
|
|
5
|
-
import type { CuckooFilterInit } from './cuckoo-filter.
|
|
6
|
-
import type { Hash } from './hashes.
|
|
7
|
-
import type { Filter } from './index.
|
|
2
|
+
import { CuckooFilter, optimize } from './cuckoo-filter.ts'
|
|
3
|
+
import { fnv1a } from './hashes.ts'
|
|
4
|
+
import { getRandomInt } from './utils.ts'
|
|
5
|
+
import type { CuckooFilterInit } from './cuckoo-filter.ts'
|
|
6
|
+
import type { Hash } from './hashes.ts'
|
|
7
|
+
import type { Filter } from './index.ts'
|
|
8
8
|
|
|
9
9
|
export interface ScalableCuckooFilterInit extends CuckooFilterInit {
|
|
10
10
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os from 'node:os'
|
|
2
|
-
import { isLinkLocalIp } from './link-local-ip.
|
|
2
|
+
import { isLinkLocalIp } from './link-local-ip.ts'
|
|
3
3
|
import { getNetConfig } from './multiaddr/get-net-config.ts'
|
|
4
4
|
import { netConfigToMultiaddr } from './multiaddr/utils.ts'
|
|
5
5
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
package/src/index.ts
CHANGED
|
@@ -4,34 +4,34 @@
|
|
|
4
4
|
* This module contains utility functions used by libp2p modules.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export * from './filters/index.
|
|
8
|
-
export * from './multiaddr/index.
|
|
9
|
-
export * from './queue/index.
|
|
10
|
-
export * from './abstract-message-stream.
|
|
11
|
-
export * from './abstract-multiaddr-connection.
|
|
12
|
-
export * from './abstract-stream-muxer.
|
|
13
|
-
export * from './abstract-stream.
|
|
14
|
-
export * from './adaptive-timeout.
|
|
15
|
-
export * from './debounce.
|
|
16
|
-
export * from './errors.
|
|
17
|
-
export * from './get-thin-waist-addresses.
|
|
18
|
-
export * from './global-unicast-ip.
|
|
19
|
-
export * from './ip-port-to-multiaddr.
|
|
20
|
-
export * from './is-async-generator.
|
|
21
|
-
export * from './is-generator.
|
|
22
|
-
export * from './is-promise.
|
|
23
|
-
export * from './length-prefixed-decoder.
|
|
24
|
-
export * from './link-local-ip.
|
|
25
|
-
export * from './mock-muxer.
|
|
26
|
-
export * from './mock-stream.
|
|
27
|
-
export * from './moving-average.
|
|
28
|
-
export * from './multiaddr-connection-pair.
|
|
29
|
-
export * from './peer-queue.
|
|
30
|
-
export * from './priority-queue.
|
|
31
|
-
export * from './private-ip.
|
|
32
|
-
export * from './rate-limiter.
|
|
33
|
-
export * from './repeating-task.
|
|
34
|
-
export * from './stream-pair.
|
|
35
|
-
export * from './stream-utils.
|
|
36
|
-
export * from './tracked-list.
|
|
37
|
-
export * from './tracked-map.
|
|
7
|
+
export * from './filters/index.ts'
|
|
8
|
+
export * from './multiaddr/index.ts'
|
|
9
|
+
export * from './queue/index.ts'
|
|
10
|
+
export * from './abstract-message-stream.ts'
|
|
11
|
+
export * from './abstract-multiaddr-connection.ts'
|
|
12
|
+
export * from './abstract-stream-muxer.ts'
|
|
13
|
+
export * from './abstract-stream.ts'
|
|
14
|
+
export * from './adaptive-timeout.ts'
|
|
15
|
+
export * from './debounce.ts'
|
|
16
|
+
export * from './errors.ts'
|
|
17
|
+
export * from './get-thin-waist-addresses.ts'
|
|
18
|
+
export * from './global-unicast-ip.ts'
|
|
19
|
+
export * from './ip-port-to-multiaddr.ts'
|
|
20
|
+
export * from './is-async-generator.ts'
|
|
21
|
+
export * from './is-generator.ts'
|
|
22
|
+
export * from './is-promise.ts'
|
|
23
|
+
export * from './length-prefixed-decoder.ts'
|
|
24
|
+
export * from './link-local-ip.ts'
|
|
25
|
+
export * from './mock-muxer.ts'
|
|
26
|
+
export * from './mock-stream.ts'
|
|
27
|
+
export * from './moving-average.ts'
|
|
28
|
+
export * from './multiaddr-connection-pair.ts'
|
|
29
|
+
export * from './peer-queue.ts'
|
|
30
|
+
export * from './priority-queue.ts'
|
|
31
|
+
export * from './private-ip.ts'
|
|
32
|
+
export * from './rate-limiter.ts'
|
|
33
|
+
export * from './repeating-task.ts'
|
|
34
|
+
export * from './stream-pair.ts'
|
|
35
|
+
export * from './stream-utils.ts'
|
|
36
|
+
export * from './tracked-list.ts'
|
|
37
|
+
export * from './tracked-map.ts'
|
package/src/message-queue.ts
CHANGED
|
@@ -3,7 +3,7 @@ import delay from 'delay'
|
|
|
3
3
|
import { TypedEventEmitter } from 'main-event'
|
|
4
4
|
import { raceSignal } from 'race-signal'
|
|
5
5
|
import { isUint8ArrayList, Uint8ArrayList } from 'uint8arraylist'
|
|
6
|
-
import { Queue } from './queue/index.
|
|
6
|
+
import { Queue } from './queue/index.ts'
|
|
7
7
|
import type { AbortOptions, Logger } from '@libp2p/interface'
|
|
8
8
|
|
|
9
9
|
const DEFAULT_CHUNK_SIZE = 1024 * 64
|
package/src/mock-muxer.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { pushable } from 'it-pushable'
|
|
|
4
4
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
5
5
|
import { AbstractStreamMuxer } from './abstract-stream-muxer.ts'
|
|
6
6
|
import { AbstractStream } from './abstract-stream.ts'
|
|
7
|
-
import { Queue } from './queue/index.
|
|
7
|
+
import { Queue } from './queue/index.ts'
|
|
8
8
|
import type { SendResult } from './abstract-message-stream.ts'
|
|
9
9
|
import type { AbstractStreamInit } from './abstract-stream.ts'
|
|
10
10
|
import type { AbortOptions, MessageStreamDirection, CreateStreamOptions, StreamMuxerFactory, StreamMuxer, MultiaddrConnection, StreamMuxerOptions } from '@libp2p/interface'
|
package/src/multiaddr/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './get-net-config.ts'
|
|
2
|
-
export * from './is-global-unicast.
|
|
3
|
-
export * from './is-link-local.
|
|
4
|
-
export * from './is-loopback.
|
|
5
|
-
export * from './is-network-address.
|
|
6
|
-
export * from './is-private.
|
|
2
|
+
export * from './is-global-unicast.ts'
|
|
3
|
+
export * from './is-link-local.ts'
|
|
4
|
+
export * from './is-loopback.ts'
|
|
5
|
+
export * from './is-network-address.ts'
|
|
6
|
+
export * from './is-private.ts'
|
package/src/peer-queue.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Queue } from './queue/index.
|
|
2
|
-
import type { Job } from './queue/job.
|
|
1
|
+
import { Queue } from './queue/index.ts'
|
|
2
|
+
import type { Job } from './queue/job.ts'
|
|
3
3
|
import type { AbortOptions, PeerId } from '@libp2p/interface'
|
|
4
4
|
|
|
5
5
|
export interface PeerQueueJobOptions extends AbortOptions {
|
package/src/priority-queue.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Queue } from './queue/index.
|
|
2
|
-
import type { QueueInit } from './queue/index.
|
|
1
|
+
import { Queue } from './queue/index.ts'
|
|
2
|
+
import type { QueueInit } from './queue/index.ts'
|
|
3
3
|
import type { AbortOptions } from '@libp2p/interface'
|
|
4
4
|
|
|
5
5
|
export interface PriorityQueueJobOptions extends AbortOptions {
|
package/src/queue/index.ts
CHANGED
|
@@ -4,11 +4,12 @@ import { TypedEventEmitter } from 'main-event'
|
|
|
4
4
|
import { pEvent } from 'p-event'
|
|
5
5
|
import { debounce } from '../debounce.js'
|
|
6
6
|
import { QueueFullError } from '../errors.js'
|
|
7
|
-
import { Job } from './job.
|
|
7
|
+
import { Job } from './job.ts'
|
|
8
8
|
import type { AbortOptions, Metrics } from '@libp2p/interface'
|
|
9
|
+
import type { ProgressOptions } from 'progress-events'
|
|
9
10
|
|
|
10
|
-
export type { Job, JobTimeline } from './job.
|
|
11
|
-
export type { JobRecipient } from './recipient.
|
|
11
|
+
export type { Job, JobTimeline } from './job.ts'
|
|
12
|
+
export type { JobRecipient } from './recipient.ts'
|
|
12
13
|
|
|
13
14
|
export interface Comparator<T> {
|
|
14
15
|
(a: T, b: T): -1 | 0 | 1
|
|
@@ -118,7 +119,7 @@ export interface QueueEvents<JobReturnType, JobOptions extends AbortOptions = Ab
|
|
|
118
119
|
* 1. Items remain at the head of the queue while they are running so `queue.size` includes `queue.pending` items - this is so interested parties can join the results of a queue item while it is running
|
|
119
120
|
* 2. The options for a job are stored separately to the job in order for them to be modified while they are still in the queue
|
|
120
121
|
*/
|
|
121
|
-
export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = AbortOptions> extends TypedEventEmitter<QueueEvents<JobReturnType, JobOptions>> {
|
|
122
|
+
export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions & ProgressOptions = AbortOptions> extends TypedEventEmitter<QueueEvents<JobReturnType, JobOptions>> {
|
|
122
123
|
public concurrency: number
|
|
123
124
|
public maxSize: number
|
|
124
125
|
public queue: Array<Job<JobOptions, JobReturnType>>
|
|
@@ -257,9 +258,8 @@ export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = Ab
|
|
|
257
258
|
const job = new Job<JobOptions, JobReturnType>(fn, options)
|
|
258
259
|
this.enqueue(job)
|
|
259
260
|
this.safeDispatchEvent('add')
|
|
260
|
-
this.tryToStartAnother()
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
const result = job.join(options)
|
|
263
263
|
.then(result => {
|
|
264
264
|
this.safeDispatchEvent('completed', { detail: result })
|
|
265
265
|
this.safeDispatchEvent('success', { detail: { job, result } })
|
|
@@ -281,6 +281,10 @@ export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = Ab
|
|
|
281
281
|
|
|
282
282
|
throw err
|
|
283
283
|
})
|
|
284
|
+
|
|
285
|
+
this.tryToStartAnother()
|
|
286
|
+
|
|
287
|
+
return result
|
|
284
288
|
}
|
|
285
289
|
|
|
286
290
|
/**
|
package/src/queue/job.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbortError } from '@libp2p/interface'
|
|
2
2
|
import { setMaxListeners } from 'main-event'
|
|
3
3
|
import { raceSignal } from 'race-signal'
|
|
4
|
-
import { JobRecipient } from './recipient.
|
|
5
|
-
import type { JobStatus } from './index.
|
|
4
|
+
import { JobRecipient } from './recipient.ts'
|
|
5
|
+
import type { JobStatus } from './index.ts'
|
|
6
6
|
import type { AbortOptions } from '@libp2p/interface'
|
|
7
|
+
import type { ProgressOptions } from 'progress-events'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Returns a random string
|
|
@@ -18,7 +19,7 @@ export interface JobTimeline {
|
|
|
18
19
|
finished?: number
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export class Job <JobOptions extends AbortOptions = AbortOptions, JobReturnType = unknown> {
|
|
22
|
+
export class Job <JobOptions extends AbortOptions & ProgressOptions = AbortOptions, JobReturnType = unknown> {
|
|
22
23
|
public id: string
|
|
23
24
|
public fn: (options: JobOptions) => Promise<JobReturnType>
|
|
24
25
|
public options: JobOptions
|
|
@@ -59,11 +60,11 @@ export class Job <JobOptions extends AbortOptions = AbortOptions, JobReturnType
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
async join (options
|
|
63
|
-
const recipient = new JobRecipient<JobReturnType>(options
|
|
63
|
+
async join (options?: Partial<Pick<JobOptions, 'signal' | 'onProgress'>>): Promise<JobReturnType> {
|
|
64
|
+
const recipient = new JobRecipient<JobReturnType>(options)
|
|
64
65
|
this.recipients.push(recipient)
|
|
65
66
|
|
|
66
|
-
options
|
|
67
|
+
options?.signal?.addEventListener('abort', this.onAbort)
|
|
67
68
|
|
|
68
69
|
return recipient.deferred.promise
|
|
69
70
|
}
|
|
@@ -77,7 +78,12 @@ export class Job <JobOptions extends AbortOptions = AbortOptions, JobReturnType
|
|
|
77
78
|
|
|
78
79
|
const result = await raceSignal(this.fn({
|
|
79
80
|
...(this.options ?? {}),
|
|
80
|
-
signal: this.controller.signal
|
|
81
|
+
signal: this.controller.signal,
|
|
82
|
+
onProgress: (evt: any): void => {
|
|
83
|
+
this.recipients.forEach(recipient => {
|
|
84
|
+
recipient.onProgress?.(evt)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
81
87
|
}), this.controller.signal)
|
|
82
88
|
|
|
83
89
|
this.recipients.forEach(recipient => {
|
package/src/queue/recipient.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { AbortError } from '@libp2p/interface'
|
|
2
2
|
import pDefer from 'p-defer'
|
|
3
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
3
4
|
import type { DeferredPromise } from 'p-defer'
|
|
5
|
+
import type { ProgressOptions, ProgressEventListener } from 'progress-events'
|
|
4
6
|
|
|
5
|
-
export class JobRecipient<JobReturnType> {
|
|
7
|
+
export class JobRecipient<JobReturnType, JobOptions extends AbortOptions & ProgressOptions = any> {
|
|
6
8
|
public deferred: DeferredPromise<JobReturnType>
|
|
7
9
|
public signal?: AbortSignal
|
|
10
|
+
public onProgress?: ProgressEventListener
|
|
8
11
|
|
|
9
|
-
constructor (
|
|
10
|
-
this.signal = signal
|
|
12
|
+
constructor (options?: Partial<Pick<JobOptions, 'signal' | 'onProgress'>>) {
|
|
13
|
+
this.signal = options?.signal
|
|
14
|
+
this.onProgress = options?.onProgress
|
|
11
15
|
this.deferred = pDefer()
|
|
12
16
|
|
|
13
17
|
this.onAbort = this.onAbort.bind(this)
|
package/src/rate-limiter.ts
CHANGED
package/src/stream-utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { pEvent } from 'p-event'
|
|
|
5
5
|
import { raceSignal } from 'race-signal'
|
|
6
6
|
import * as varint from 'uint8-varint'
|
|
7
7
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
8
|
-
import { UnexpectedEOFError } from './errors.
|
|
8
|
+
import { UnexpectedEOFError } from './errors.ts'
|
|
9
9
|
import type { MessageStream, MultiaddrConnection, Stream, AbortOptions } from '@libp2p/interface'
|
|
10
10
|
import type { Duplex, Source, Transform, Sink } from 'it-stream-types'
|
|
11
11
|
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AbstractMessageStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractMessageStream.html",
|
|
3
|
-
"AbstractMultiaddrConnection": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractMultiaddrConnection.html",
|
|
4
|
-
"AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractStream.html",
|
|
5
|
-
"AbstractStreamMuxer": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AbstractStreamMuxer.html",
|
|
6
|
-
"AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.AdaptiveTimeout.html",
|
|
7
|
-
"BloomFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.BloomFilter.html",
|
|
8
|
-
"CuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.CuckooFilter.html",
|
|
9
|
-
"InvalidDataLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidDataLengthError.html",
|
|
10
|
-
"InvalidDataLengthLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidDataLengthLengthError.html",
|
|
11
|
-
"InvalidMessageLengthError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.InvalidMessageLengthError.html",
|
|
12
|
-
"LengthPrefixedDecoder": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.LengthPrefixedDecoder.html",
|
|
13
|
-
"MaxEarlyStreamsError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MaxEarlyStreamsError.html",
|
|
14
|
-
"MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MemoryStorage.html",
|
|
15
|
-
"MockStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MockStream.html",
|
|
16
|
-
"MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.MovingAverage.html",
|
|
17
|
-
"PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.PeerQueue.html",
|
|
18
|
-
"PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.PriorityQueue.html",
|
|
19
|
-
"Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.Queue.html",
|
|
20
|
-
"QueueFullError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.QueueFullError.html",
|
|
21
|
-
"RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.RateLimiter.html",
|
|
22
|
-
"RateLimitError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.RateLimitError.html",
|
|
23
|
-
"ScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.ScalableCuckooFilter.html",
|
|
24
|
-
"StreamClosedError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.StreamClosedError.html",
|
|
25
|
-
"UnexpectedEOFError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.UnexpectedEOFError.html",
|
|
26
|
-
"UnwrappedError": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.UnwrappedError.html",
|
|
27
|
-
"AbstractMultiaddrConnectionInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractMultiaddrConnectionInit.html",
|
|
28
|
-
"AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractStreamInit.html",
|
|
29
|
-
"AbstractStreamMuxerInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AbstractStreamMuxerInit.html",
|
|
30
|
-
"AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AdaptiveTimeoutInit.html",
|
|
31
|
-
"AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.AdaptiveTimeoutSignal.html",
|
|
32
|
-
"BloomFilterOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.BloomFilterOptions.html",
|
|
33
|
-
"Bucket": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Bucket.html",
|
|
34
|
-
"ByteStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ByteStream.html",
|
|
35
|
-
"ByteStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ByteStreamOpts.html",
|
|
36
|
-
"Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Comparator.html",
|
|
37
|
-
"CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CreateTrackedListInit.html",
|
|
38
|
-
"CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CreateTrackedMapInit.html",
|
|
39
|
-
"CuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.CuckooFilterInit.html",
|
|
40
|
-
"DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DebouncedFunction.html",
|
|
41
|
-
"DNS4NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNS4NetConfig.html",
|
|
42
|
-
"DNS6NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNS6NetConfig.html",
|
|
43
|
-
"DNSAddrNetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNSAddrNetConfig.html",
|
|
44
|
-
"DNSNetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.DNSNetConfig.html",
|
|
45
|
-
"Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Filter.html",
|
|
46
|
-
"Fingerprint": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Fingerprint.html",
|
|
47
|
-
"GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.GetKeySecDurationOptions.html",
|
|
48
|
-
"GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.GetTimeoutSignalOptions.html",
|
|
49
|
-
"Hash": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Hash.html",
|
|
50
|
-
"IP4NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.IP4NetConfig.html",
|
|
51
|
-
"IP6NetConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.IP6NetConfig.html",
|
|
52
|
-
"Job": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.Job.html",
|
|
53
|
-
"JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobMatcher.html",
|
|
54
|
-
"JobRecipient": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobRecipient.html",
|
|
55
|
-
"JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.JobTimeline.html",
|
|
56
|
-
"LengthPrefixedDecoderInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedDecoderInit.html",
|
|
57
|
-
"LengthPrefixedStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedStream.html",
|
|
58
|
-
"LengthPrefixedStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.LengthPrefixedStreamOpts.html",
|
|
59
|
-
"MessageStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MessageStreamInit.html",
|
|
60
|
-
"MockMultiaddrConnectionInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MockMultiaddrConnectionInit.html",
|
|
61
|
-
"MockMuxedStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MockMuxedStreamInit.html",
|
|
62
|
-
"MultiaddrConnectionPairOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.MultiaddrConnectionPairOptions.html",
|
|
63
|
-
"PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.PeerQueueJobOptions.html",
|
|
64
|
-
"PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.PriorityQueueJobOptions.html",
|
|
65
|
-
"ProtobufDecoder": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufDecoder.html",
|
|
66
|
-
"ProtobufEncoder": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufEncoder.html",
|
|
67
|
-
"ProtobufMessageStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufMessageStream.html",
|
|
68
|
-
"ProtobufStream": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufStream.html",
|
|
69
|
-
"ProtobufStreamOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ProtobufStreamOpts.html",
|
|
70
|
-
"QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueEvents.html",
|
|
71
|
-
"QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueInit.html",
|
|
72
|
-
"QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueJobFailure.html",
|
|
73
|
-
"QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.QueueJobSuccess.html",
|
|
74
|
-
"RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateLimiterInit.html",
|
|
75
|
-
"RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateLimiterResult.html",
|
|
76
|
-
"RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RateRecord.html",
|
|
77
|
-
"ReadBytesOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ReadBytesOptions.html",
|
|
78
|
-
"RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RepeatingTask.html",
|
|
79
|
-
"RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RepeatingTaskOptions.html",
|
|
80
|
-
"RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.RunFunction.html",
|
|
81
|
-
"ScalableCuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.ScalableCuckooFilterInit.html",
|
|
82
|
-
"SendResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.SendResult.html",
|
|
83
|
-
"StreamPairOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.StreamPairOptions.html",
|
|
84
|
-
"TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.TrackedMapInit.html",
|
|
85
|
-
"JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.JobStatus.html",
|
|
86
|
-
"NetConfig": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.NetConfig.html",
|
|
87
|
-
"PipeInput": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.PipeInput.html",
|
|
88
|
-
"DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_FAILURE_MULTIPLIER.html",
|
|
89
|
-
"DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_INTERVAL.html",
|
|
90
|
-
"DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_MAX_TIMEOUT.html",
|
|
91
|
-
"DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_MIN_TIMEOUT.html",
|
|
92
|
-
"DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.DEFAULT_TIMEOUT_MULTIPLIER.html",
|
|
93
|
-
"byteStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.byteStream.html",
|
|
94
|
-
"createBloomFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createBloomFilter.html",
|
|
95
|
-
"createCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createCuckooFilter.html",
|
|
96
|
-
"createScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.createScalableCuckooFilter.html",
|
|
97
|
-
"debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.html",
|
|
98
|
-
"echo": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.echo.html",
|
|
99
|
-
"echoStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.echoStream.html",
|
|
100
|
-
"getNetConfig": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.getNetConfig.html",
|
|
101
|
-
"getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.getThinWaistAddresses.html",
|
|
102
|
-
"ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ipPortToMultiaddr.html",
|
|
103
|
-
"isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isAsyncGenerator.html",
|
|
104
|
-
"isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGenerator.html",
|
|
105
|
-
"isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGlobalUnicast.html",
|
|
106
|
-
"isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isGlobalUnicastIp.html",
|
|
107
|
-
"isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLinkLocal.html",
|
|
108
|
-
"isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLinkLocalIp.html",
|
|
109
|
-
"isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isLoopback.html",
|
|
110
|
-
"isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isNetworkAddress.html",
|
|
111
|
-
"isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPrivate.html",
|
|
112
|
-
"isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPrivateIp.html",
|
|
113
|
-
"isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.isPromise.html",
|
|
114
|
-
"lpStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.lpStream.html",
|
|
115
|
-
"messageStreamToDuplex": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.messageStreamToDuplex.html",
|
|
116
|
-
"mockMuxer": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.mockMuxer.html",
|
|
117
|
-
"multiaddrConnectionPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddrConnectionPair.html",
|
|
118
|
-
"pbStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.pbStream.html",
|
|
119
|
-
"pipe": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.pipe.html",
|
|
120
|
-
"repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeatingTask.html",
|
|
121
|
-
"streamPair": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.streamPair.html",
|
|
122
|
-
"trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.trackedList.html",
|
|
123
|
-
"trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.trackedMap.html"
|
|
124
|
-
}
|