@libp2p/utils 6.6.3 → 6.6.4-776cb432d
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/src/abstract-stream.d.ts +1 -1
- package/dist/src/abstract-stream.d.ts.map +1 -1
- package/dist/src/abstract-stream.js +6 -7
- package/dist/src/abstract-stream.js.map +1 -1
- package/dist/src/adaptive-timeout.d.ts +1 -1
- package/dist/src/adaptive-timeout.d.ts.map +1 -1
- package/dist/src/adaptive-timeout.js.map +1 -1
- package/dist/src/debounce.js.map +1 -1
- package/dist/src/filters/cuckoo-filter.d.ts +1 -1
- package/dist/src/filters/cuckoo-filter.d.ts.map +1 -1
- package/dist/src/filters/cuckoo-filter.js.map +1 -1
- package/dist/src/filters/fingerprint.d.ts +1 -1
- package/dist/src/filters/fingerprint.d.ts.map +1 -1
- package/dist/src/filters/scalable-cuckoo-filter.d.ts +1 -1
- package/dist/src/filters/scalable-cuckoo-filter.d.ts.map +1 -1
- package/dist/src/filters/scalable-cuckoo-filter.js.map +1 -1
- package/dist/src/ip-port-to-multiaddr.d.ts +1 -1
- package/dist/src/ip-port-to-multiaddr.d.ts.map +1 -1
- package/dist/src/ip-port-to-multiaddr.js +1 -1
- package/dist/src/ip-port-to-multiaddr.js.map +1 -1
- package/dist/src/merge-options.d.ts +7 -0
- package/dist/src/merge-options.d.ts.map +1 -0
- package/dist/src/merge-options.js +128 -0
- package/dist/src/merge-options.js.map +1 -0
- package/dist/src/private-ip.d.ts.map +1 -1
- package/dist/src/private-ip.js +12 -6
- package/dist/src/private-ip.js.map +1 -1
- package/dist/src/queue/index.d.ts +9 -9
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/repeating-task.d.ts +1 -1
- package/dist/src/repeating-task.d.ts.map +1 -1
- package/dist/src/repeating-task.js +1 -3
- package/dist/src/repeating-task.js.map +1 -1
- package/dist/src/stream-to-ma-conn.js.map +1 -1
- package/package.json +20 -22
- package/src/abstract-stream.ts +11 -10
- package/src/adaptive-timeout.ts +2 -1
- package/src/debounce.ts +2 -2
- package/src/filters/cuckoo-filter.ts +2 -1
- package/src/filters/fingerprint.ts +1 -1
- package/src/filters/scalable-cuckoo-filter.ts +4 -2
- package/src/ip-port-to-multiaddr.ts +3 -2
- package/src/merge-options.ts +161 -0
- package/src/private-ip.ts +2 -6
- package/src/queue/index.ts +9 -9
- package/src/repeating-task.ts +6 -9
- package/src/stream-to-ma-conn.ts +4 -4
- package/dist/typedoc-urls.json +0 -141
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAsB9B;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,KAAK,CAAA;IACrE,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAE1D,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,WAAW,GAAG,KAAK,CAAA;IAEvB,wEAAwE;IACxE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,GAAG,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAsB9B;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM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-776cb432d",
|
|
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",
|
|
@@ -105,6 +105,10 @@
|
|
|
105
105
|
"types": "./dist/src/link-local-ip.d.ts",
|
|
106
106
|
"import": "./dist/src/link-local-ip.js"
|
|
107
107
|
},
|
|
108
|
+
"./merge-options": {
|
|
109
|
+
"types": "./dist/src/merge-options.d.ts",
|
|
110
|
+
"import": "./dist/src/merge-options.js"
|
|
111
|
+
},
|
|
108
112
|
"./moving-average": {
|
|
109
113
|
"types": "./dist/src/moving-average.d.ts",
|
|
110
114
|
"import": "./dist/src/moving-average.js"
|
|
@@ -170,13 +174,6 @@
|
|
|
170
174
|
"import": "./dist/src/tracked-map.js"
|
|
171
175
|
}
|
|
172
176
|
},
|
|
173
|
-
"eslintConfig": {
|
|
174
|
-
"extends": "ipfs",
|
|
175
|
-
"parserOptions": {
|
|
176
|
-
"project": true,
|
|
177
|
-
"sourceType": "module"
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
177
|
"scripts": {
|
|
181
178
|
"clean": "aegir clean",
|
|
182
179
|
"lint": "aegir lint",
|
|
@@ -192,46 +189,47 @@
|
|
|
192
189
|
"test:electron-main": "aegir test -t electron-main"
|
|
193
190
|
},
|
|
194
191
|
"dependencies": {
|
|
195
|
-
"@chainsafe/is-ip": "^2.0
|
|
192
|
+
"@chainsafe/is-ip": "^2.1.0",
|
|
196
193
|
"@chainsafe/netmask": "^2.0.0",
|
|
197
|
-
"@libp2p/crypto": "
|
|
198
|
-
"@libp2p/interface": "
|
|
199
|
-
"@libp2p/logger": "
|
|
200
|
-
"@multiformats/multiaddr": "^12.
|
|
194
|
+
"@libp2p/crypto": "5.1.3-776cb432d",
|
|
195
|
+
"@libp2p/interface": "2.10.1-776cb432d",
|
|
196
|
+
"@libp2p/logger": "5.1.17-776cb432d",
|
|
197
|
+
"@multiformats/multiaddr": "^12.4.0",
|
|
201
198
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
202
199
|
"any-signal": "^4.1.1",
|
|
203
200
|
"delay": "^6.0.0",
|
|
204
201
|
"get-iterator": "^2.0.1",
|
|
205
202
|
"is-loopback-addr": "^2.0.2",
|
|
206
|
-
"
|
|
203
|
+
"is-plain-obj": "^4.1.0",
|
|
204
|
+
"it-foreach": "^2.1.3",
|
|
207
205
|
"it-pipe": "^3.0.1",
|
|
208
206
|
"it-pushable": "^3.2.3",
|
|
209
207
|
"it-stream-types": "^2.0.2",
|
|
210
208
|
"netmask": "^2.0.2",
|
|
211
209
|
"p-defer": "^4.0.1",
|
|
212
210
|
"race-event": "^1.3.0",
|
|
213
|
-
"race-signal": "^1.1.
|
|
211
|
+
"race-signal": "^1.1.3",
|
|
214
212
|
"uint8arraylist": "^2.4.8",
|
|
215
213
|
"uint8arrays": "^5.1.0"
|
|
216
214
|
},
|
|
217
215
|
"devDependencies": {
|
|
218
|
-
"@libp2p/peer-id": "
|
|
216
|
+
"@libp2p/peer-id": "5.1.4-776cb432d",
|
|
219
217
|
"@types/netmask": "^2.0.5",
|
|
220
|
-
"aegir": "^
|
|
218
|
+
"aegir": "^47.0.6",
|
|
221
219
|
"benchmark": "^2.1.4",
|
|
222
220
|
"delay": "^6.0.0",
|
|
223
|
-
"it-all": "^3.0.
|
|
224
|
-
"it-drain": "^3.0.
|
|
221
|
+
"it-all": "^3.0.8",
|
|
222
|
+
"it-drain": "^3.0.9",
|
|
225
223
|
"it-pair": "^2.0.6",
|
|
226
|
-
"sinon": "^
|
|
224
|
+
"sinon": "^20.0.0",
|
|
227
225
|
"sinon-ts": "^2.0.0",
|
|
228
226
|
"wherearewe": "^2.0.1"
|
|
229
227
|
},
|
|
230
|
-
"sideEffects": false,
|
|
231
228
|
"browser": {
|
|
232
229
|
"./dist/src/get-thin-waist-addresses.js": "./dist/src/get-thin-waist-addresses.browser.js"
|
|
233
230
|
},
|
|
234
231
|
"react-native": {
|
|
235
232
|
"./dist/src/get-thin-waist-addresses.js": "./dist/src/get-thin-waist-addresses.js"
|
|
236
|
-
}
|
|
233
|
+
},
|
|
234
|
+
"sideEffects": false
|
|
237
235
|
}
|
package/src/abstract-stream.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { StreamResetError, StreamStateError } from '@libp2p/interface'
|
|
2
|
-
import {
|
|
3
|
-
import defer
|
|
4
|
-
import pDefer from 'p-defer'
|
|
2
|
+
import { pushable } from 'it-pushable'
|
|
3
|
+
import defer from 'p-defer'
|
|
5
4
|
import { raceSignal } from 'race-signal'
|
|
6
5
|
import { Uint8ArrayList } from 'uint8arraylist'
|
|
7
6
|
import { closeSource } from './close-source.js'
|
|
8
7
|
import type { AbortOptions, Direction, ReadStatus, Stream, StreamStatus, StreamTimeline, WriteStatus } from '@libp2p/interface'
|
|
9
8
|
import type { Logger } from '@libp2p/logger'
|
|
9
|
+
import type { Pushable } from 'it-pushable'
|
|
10
10
|
import type { Source } from 'it-stream-types'
|
|
11
|
+
import type { DeferredPromise } from 'p-defer'
|
|
11
12
|
|
|
12
13
|
const DEFAULT_SEND_CLOSE_WRITE_TIMEOUT = 5000
|
|
13
14
|
|
|
@@ -35,7 +36,7 @@ export interface AbstractStreamInit {
|
|
|
35
36
|
/**
|
|
36
37
|
* Invoked when the stream ends
|
|
37
38
|
*/
|
|
38
|
-
onEnd?(err?: Error
|
|
39
|
+
onEnd?(err?: Error): void
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Invoked when the readable end of the stream is closed
|
|
@@ -99,7 +100,7 @@ export abstract class AbstractStream implements Stream {
|
|
|
99
100
|
private readonly closed: DeferredPromise<void>
|
|
100
101
|
private endErr: Error | undefined
|
|
101
102
|
private readonly streamSource: Pushable<Uint8ArrayList>
|
|
102
|
-
private readonly onEnd?: (err?: Error
|
|
103
|
+
private readonly onEnd?: (err?: Error) => void
|
|
103
104
|
private readonly onCloseRead?: () => void
|
|
104
105
|
private readonly onCloseWrite?: () => void
|
|
105
106
|
private readonly onReset?: () => void
|
|
@@ -127,10 +128,10 @@ export abstract class AbstractStream implements Stream {
|
|
|
127
128
|
this.sendCloseWriteTimeout = init.sendCloseWriteTimeout ?? DEFAULT_SEND_CLOSE_WRITE_TIMEOUT
|
|
128
129
|
|
|
129
130
|
this.onEnd = init.onEnd
|
|
130
|
-
this.onCloseRead = init
|
|
131
|
-
this.onCloseWrite = init
|
|
132
|
-
this.onReset = init
|
|
133
|
-
this.onAbort = init
|
|
131
|
+
this.onCloseRead = init.onCloseRead
|
|
132
|
+
this.onCloseWrite = init.onCloseWrite
|
|
133
|
+
this.onReset = init.onReset
|
|
134
|
+
this.onAbort = init.onAbort
|
|
134
135
|
|
|
135
136
|
this.source = this.streamSource = pushable<Uint8ArrayList>({
|
|
136
137
|
onEnd: (err) => {
|
|
@@ -183,7 +184,7 @@ export abstract class AbstractStream implements Stream {
|
|
|
183
184
|
const res = this.sendData(data, options)
|
|
184
185
|
|
|
185
186
|
if (isPromise(res)) {
|
|
186
|
-
this.sendingData =
|
|
187
|
+
this.sendingData = defer()
|
|
187
188
|
await res
|
|
188
189
|
this.sendingData.resolve()
|
|
189
190
|
this.sendingData = undefined
|
package/src/adaptive-timeout.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { setMaxListeners } from '@libp2p/interface'
|
|
2
|
-
import { anySignal
|
|
2
|
+
import { anySignal } from 'any-signal'
|
|
3
3
|
import { MovingAverage } from './moving-average.js'
|
|
4
4
|
import type { MetricGroup, Metrics } from '@libp2p/interface'
|
|
5
|
+
import type { ClearableSignal } from 'any-signal'
|
|
5
6
|
|
|
6
7
|
export const DEFAULT_TIMEOUT_MULTIPLIER = 1.2
|
|
7
8
|
export const DEFAULT_FAILURE_MULTIPLIER = 2
|
package/src/debounce.ts
CHANGED
|
@@ -21,8 +21,8 @@ export function debounce (func: () => void | Promise<void>, wait: number): Debou
|
|
|
21
21
|
clearTimeout(timeout)
|
|
22
22
|
timeout = setTimeout(later, wait)
|
|
23
23
|
}
|
|
24
|
-
output.start = () => {}
|
|
25
|
-
output.stop = () => {
|
|
24
|
+
output.start = (): void => {}
|
|
25
|
+
output.stop = (): void => {
|
|
26
26
|
clearTimeout(timeout)
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
2
|
import { Bucket } from './bucket.js'
|
|
3
3
|
import { Fingerprint, MAX_FINGERPRINT_SIZE } from './fingerprint.js'
|
|
4
|
-
import { fnv1a
|
|
4
|
+
import { fnv1a } from './hashes.js'
|
|
5
5
|
import { getRandomInt } from './utils.js'
|
|
6
|
+
import type { Hash } from './hashes.js'
|
|
6
7
|
import type { Filter } from './index.js'
|
|
7
8
|
|
|
8
9
|
const maxCuckooCount = 500
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
|
-
import { CuckooFilter, optimize
|
|
3
|
-
import { fnv1a
|
|
2
|
+
import { CuckooFilter, optimize } from './cuckoo-filter.js'
|
|
3
|
+
import { fnv1a } from './hashes.js'
|
|
4
4
|
import { getRandomInt } from './utils.js'
|
|
5
|
+
import type { CuckooFilterInit } from './cuckoo-filter.js'
|
|
6
|
+
import type { Hash } from './hashes.js'
|
|
5
7
|
import type { Filter } from './index.js'
|
|
6
8
|
|
|
7
9
|
export interface ScalableCuckooFilterInit extends CuckooFilterInit {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
|
|
2
2
|
import { InvalidParametersError } from '@libp2p/interface'
|
|
3
|
-
import {
|
|
3
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
4
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Transform an IP, Port pair into a multiaddr
|
|
7
8
|
*/
|
|
8
9
|
export function ipPortToMultiaddr (ip: string, port: number | string): Multiaddr {
|
|
9
10
|
if (typeof ip !== 'string') {
|
|
10
|
-
throw new InvalidParametersError(`invalid ip provided: ${ip}`)
|
|
11
|
+
throw new InvalidParametersError(`invalid ip provided: ${ip}`)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
if (typeof port === 'string') {
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import isOptionObject from 'is-plain-obj'
|
|
2
|
+
|
|
3
|
+
const { hasOwnProperty } = Object.prototype
|
|
4
|
+
const { propertyIsEnumerable } = Object
|
|
5
|
+
const defineProperty = (object: any, name: any, value: any): void => {
|
|
6
|
+
Object.defineProperty(object, name, {
|
|
7
|
+
value,
|
|
8
|
+
writable: true,
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const globalThis = this
|
|
15
|
+
const defaultMergeOptions = {
|
|
16
|
+
concatArrays: false,
|
|
17
|
+
ignoreUndefined: false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getEnumerableOwnPropertyKeys = (value: any): any[] => {
|
|
21
|
+
const keys = []
|
|
22
|
+
|
|
23
|
+
for (const key in value) {
|
|
24
|
+
if (hasOwnProperty.call(value, key)) {
|
|
25
|
+
keys.push(key)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* istanbul ignore else */
|
|
30
|
+
if (Object.getOwnPropertySymbols) {
|
|
31
|
+
const symbols = Object.getOwnPropertySymbols(value)
|
|
32
|
+
|
|
33
|
+
for (const symbol of symbols) {
|
|
34
|
+
if (propertyIsEnumerable.call(value, symbol)) {
|
|
35
|
+
keys.push(symbol)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return keys
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function clone <T> (value: T): T
|
|
44
|
+
function clone <T> (value: T[]): T[]
|
|
45
|
+
function clone (value: any): any {
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return cloneArray(value)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (isOptionObject(value)) {
|
|
51
|
+
return cloneOptionObject(value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return value
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function cloneArray <T> (array: T[]): T[] {
|
|
58
|
+
const result = array.slice(0, 0)
|
|
59
|
+
|
|
60
|
+
getEnumerableOwnPropertyKeys(array).forEach(key => {
|
|
61
|
+
defineProperty(result, key, clone(array[key]))
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return result
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function cloneOptionObject (object: any): any {
|
|
68
|
+
const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {}
|
|
69
|
+
|
|
70
|
+
getEnumerableOwnPropertyKeys(object).forEach(key => {
|
|
71
|
+
defineProperty(result, key, clone(object[key]))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return result
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const mergeKeys = (merged: any, source: any, keys: any[], config: any): any => {
|
|
78
|
+
keys.forEach(key => {
|
|
79
|
+
if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Do not recurse into prototype chain of merged
|
|
84
|
+
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
|
|
85
|
+
defineProperty(merged, key, merge(merged[key], source[key], config))
|
|
86
|
+
} else {
|
|
87
|
+
defineProperty(merged, key, clone(source[key]))
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return merged
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
|
|
96
|
+
*/
|
|
97
|
+
const concatArrays = (merged: any, source: any, config: any): any => {
|
|
98
|
+
let result = merged.slice(0, 0)
|
|
99
|
+
let resultIndex = 0;
|
|
100
|
+
|
|
101
|
+
[merged, source].forEach(array => {
|
|
102
|
+
const indices: any[] = []
|
|
103
|
+
|
|
104
|
+
// `result.concat(array)` with cloning
|
|
105
|
+
for (let k = 0; k < array.length; k++) {
|
|
106
|
+
if (!hasOwnProperty.call(array, k)) {
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
indices.push(String(k))
|
|
111
|
+
|
|
112
|
+
if (array === merged) {
|
|
113
|
+
// Already cloned
|
|
114
|
+
defineProperty(result, resultIndex++, array[k])
|
|
115
|
+
} else {
|
|
116
|
+
defineProperty(result, resultIndex++, clone(array[k]))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Merge non-index keys
|
|
121
|
+
result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
return result
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function merge (merged: any, source: any, config: any): any {
|
|
128
|
+
if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
|
|
129
|
+
return concatArrays(merged, source, config)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!isOptionObject(source) || !isOptionObject(merged)) {
|
|
133
|
+
return clone(source)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Port of `merge-options` to typescript
|
|
141
|
+
*
|
|
142
|
+
* @see https://github.com/schnittstabil/merge-options/pull/28
|
|
143
|
+
*/
|
|
144
|
+
export function mergeOptions (this: any, ...options: any[]): any {
|
|
145
|
+
const config = merge(clone(defaultMergeOptions), (this !== globalThis && this) || {}, defaultMergeOptions)
|
|
146
|
+
let merged = { _: {} }
|
|
147
|
+
|
|
148
|
+
for (const option of options) {
|
|
149
|
+
if (option === undefined) {
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!isOptionObject(option)) {
|
|
154
|
+
throw new TypeError('`' + option + '` is not an Option Object')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
merged = merge(merged, { _: option }, config)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return merged._
|
|
161
|
+
}
|
package/src/private-ip.ts
CHANGED
|
@@ -32,7 +32,7 @@ const NETMASK_RANGES = PRIVATE_IP_RANGES.map(ipRange => new Netmask(ipRange))
|
|
|
32
32
|
|
|
33
33
|
function ipv4Check (ipAddr: string): boolean {
|
|
34
34
|
for (const r of NETMASK_RANGES) {
|
|
35
|
-
if (r.contains(ipAddr)) return true
|
|
35
|
+
if (r.contains(ipAddr)) { return true }
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return false
|
|
@@ -89,9 +89,5 @@ function ipv6Check (ipAddr: string): boolean {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export function isPrivateIp (ip: string): boolean | undefined {
|
|
92
|
-
if (isIPv4(ip)) return ipv4Check(ip)
|
|
93
|
-
else if (isIpv4MappedIpv6(ip)) return ipv4MappedIpv6Check(ip)
|
|
94
|
-
else if (isIpv4EmbeddedIpv6(ip)) return ipv4EmbeddedIpv6Check(ip)
|
|
95
|
-
else if (isIPv6(ip)) return ipv6Check(ip)
|
|
96
|
-
else return undefined
|
|
92
|
+
if (isIPv4(ip)) { return ipv4Check(ip) } else if (isIpv4MappedIpv6(ip)) { return ipv4MappedIpv6Check(ip) } else if (isIpv4EmbeddedIpv6(ip)) { return ipv4EmbeddedIpv6Check(ip) } else if (isIPv6(ip)) { return ipv6Check(ip) } else { return undefined }
|
|
97
93
|
}
|
package/src/queue/index.ts
CHANGED
|
@@ -71,49 +71,49 @@ export interface QueueEvents<JobReturnType, JobOptions extends AbortOptions = Ab
|
|
|
71
71
|
/**
|
|
72
72
|
* A job is about to start running
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
active: CustomEvent
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* All jobs have finished and the queue is empty
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
idle: CustomEvent
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* The queue is empty, jobs may be running
|
|
83
83
|
*/
|
|
84
|
-
|
|
84
|
+
empty: CustomEvent
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* A job was added to the queue
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
add: CustomEvent
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* A job has finished or failed
|
|
93
93
|
*/
|
|
94
|
-
|
|
94
|
+
next: CustomEvent
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* A job has finished successfully
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
completed: CustomEvent<JobReturnType>
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* A job has failed
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
error: CustomEvent<Error>
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* Emitted just after `"completed", a job has finished successfully - this
|
|
108
108
|
* event gives access to the job and it's result
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
success: CustomEvent<QueueJobSuccess<JobReturnType, JobOptions>>
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Emitted just after `"error", a job has failed - this event gives access to
|
|
114
114
|
* the job and the thrown error
|
|
115
115
|
*/
|
|
116
|
-
|
|
116
|
+
failure: CustomEvent<QueueJobFailure<JobReturnType, JobOptions>>
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
package/src/repeating-task.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface RepeatingTask {
|
|
|
18
18
|
* Update the amount of time a task will run before the passed abort signal
|
|
19
19
|
* will fire.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* This only affects the next iteration of the task, if it is currently
|
|
22
22
|
* running, that run will not be interrupted.
|
|
23
23
|
*/
|
|
24
24
|
setTimeout(ms: number): void
|
|
@@ -83,7 +83,7 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
|
|
|
83
83
|
let started = false
|
|
84
84
|
|
|
85
85
|
return {
|
|
86
|
-
setInterval: (ms) => {
|
|
86
|
+
setInterval: (ms): void => {
|
|
87
87
|
interval = ms
|
|
88
88
|
|
|
89
89
|
// maybe reschedule
|
|
@@ -92,14 +92,11 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
|
|
|
92
92
|
timeout = setTimeout(runTask, interval)
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
|
-
setTimeout: (ms) => {
|
|
96
|
-
|
|
97
|
-
options = {}
|
|
98
|
-
}
|
|
99
|
-
|
|
95
|
+
setTimeout: (ms): void => {
|
|
96
|
+
options ??= {}
|
|
100
97
|
options.timeout = ms
|
|
101
98
|
},
|
|
102
|
-
start: () => {
|
|
99
|
+
start: (): void => {
|
|
103
100
|
if (started) {
|
|
104
101
|
return
|
|
105
102
|
}
|
|
@@ -118,7 +115,7 @@ export function repeatingTask (fn: (options?: AbortOptions) => void | Promise<vo
|
|
|
118
115
|
timeout = setTimeout(runTask, interval)
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
|
-
stop: () => {
|
|
118
|
+
stop: (): void => {
|
|
122
119
|
clearTimeout(timeout)
|
|
123
120
|
shutdownController?.abort()
|
|
124
121
|
started = false
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -34,21 +34,21 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
|
|
|
34
34
|
|
|
35
35
|
// piggyback on `stream.close` invocations to close multiaddr connection
|
|
36
36
|
const streamClose = stream.close.bind(stream)
|
|
37
|
-
stream.close = async (options) => {
|
|
37
|
+
stream.close = async (options): Promise<void> => {
|
|
38
38
|
await streamClose(options)
|
|
39
39
|
close(true)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// piggyback on `stream.abort` invocations to close multiaddr connection
|
|
43
43
|
const streamAbort = stream.abort.bind(stream)
|
|
44
|
-
stream.abort = (err) => {
|
|
44
|
+
stream.abort = (err): void => {
|
|
45
45
|
streamAbort(err)
|
|
46
46
|
close(true)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// piggyback on `stream.sink` invocations to close multiaddr connection
|
|
50
50
|
const streamSink = stream.sink.bind(stream)
|
|
51
|
-
stream.sink = async (source) => {
|
|
51
|
+
stream.sink = async (source): Promise<void> => {
|
|
52
52
|
try {
|
|
53
53
|
await streamSink(
|
|
54
54
|
pipe(
|
|
@@ -73,7 +73,7 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
|
|
|
73
73
|
const maConn: MultiaddrConnection = {
|
|
74
74
|
log,
|
|
75
75
|
sink: stream.sink,
|
|
76
|
-
source: (async function * () {
|
|
76
|
+
source: (async function * (): AsyncGenerator<Uint8ArrayList> {
|
|
77
77
|
try {
|
|
78
78
|
for await (const buf of stream.source) {
|
|
79
79
|
onDataRead?.(buf)
|