@libp2p/utils 6.7.2-a02cb0461 → 6.7.2-e8398d97e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/index.min.js +2 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/abstract-message-stream.d.ts.map +1 -1
  4. package/dist/src/abstract-message-stream.js +8 -4
  5. package/dist/src/abstract-message-stream.js.map +1 -1
  6. package/dist/src/abstract-multiaddr-connection.d.ts +2 -2
  7. package/dist/src/abstract-multiaddr-connection.d.ts.map +1 -1
  8. package/dist/src/get-thin-waist-addresses.browser.d.ts +1 -1
  9. package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
  10. package/dist/src/get-thin-waist-addresses.browser.js +4 -3
  11. package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
  12. package/dist/src/get-thin-waist-addresses.d.ts +1 -1
  13. package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
  14. package/dist/src/get-thin-waist-addresses.js +7 -9
  15. package/dist/src/get-thin-waist-addresses.js.map +1 -1
  16. package/dist/src/index.d.ts +0 -2
  17. package/dist/src/index.d.ts.map +1 -1
  18. package/dist/src/index.js +0 -2
  19. package/dist/src/index.js.map +1 -1
  20. package/dist/src/mock-muxer.js +1 -1
  21. package/dist/src/mock-muxer.js.map +1 -1
  22. package/dist/src/multiaddr/get-net-config.d.ts +55 -0
  23. package/dist/src/multiaddr/get-net-config.d.ts.map +1 -0
  24. package/dist/src/multiaddr/get-net-config.js +54 -0
  25. package/dist/src/multiaddr/get-net-config.js.map +1 -0
  26. package/dist/src/multiaddr/index.d.ts +1 -1
  27. package/dist/src/multiaddr/index.d.ts.map +1 -1
  28. package/dist/src/multiaddr/index.js +1 -1
  29. package/dist/src/multiaddr/index.js.map +1 -1
  30. package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -1
  31. package/dist/src/multiaddr/is-global-unicast.js +8 -9
  32. package/dist/src/multiaddr/is-global-unicast.js.map +1 -1
  33. package/dist/src/multiaddr/is-link-local.d.ts.map +1 -1
  34. package/dist/src/multiaddr/is-link-local.js +11 -16
  35. package/dist/src/multiaddr/is-link-local.js.map +1 -1
  36. package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
  37. package/dist/src/multiaddr/is-loopback.js +12 -5
  38. package/dist/src/multiaddr/is-loopback.js.map +1 -1
  39. package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
  40. package/dist/src/multiaddr/is-network-address.js +4 -16
  41. package/dist/src/multiaddr/is-network-address.js.map +1 -1
  42. package/dist/src/multiaddr/is-private.d.ts.map +1 -1
  43. package/dist/src/multiaddr/is-private.js +9 -10
  44. package/dist/src/multiaddr/is-private.js.map +1 -1
  45. package/dist/src/multiaddr/utils.d.ts +5 -0
  46. package/dist/src/multiaddr/utils.d.ts.map +1 -0
  47. package/dist/src/multiaddr/utils.js +32 -0
  48. package/dist/src/multiaddr/utils.js.map +1 -0
  49. package/dist/src/queue/index.d.ts +0 -6
  50. package/dist/src/queue/index.d.ts.map +1 -1
  51. package/dist/src/queue/index.js.map +1 -1
  52. package/dist/src/stream-utils.d.ts +1 -9
  53. package/dist/src/stream-utils.d.ts.map +1 -1
  54. package/dist/src/stream-utils.js +4 -3
  55. package/dist/src/stream-utils.js.map +1 -1
  56. package/package.json +9 -12
  57. package/src/abstract-message-stream.ts +8 -4
  58. package/src/abstract-multiaddr-connection.ts +2 -2
  59. package/src/get-thin-waist-addresses.browser.ts +5 -4
  60. package/src/get-thin-waist-addresses.ts +8 -12
  61. package/src/index.ts +0 -2
  62. package/src/mock-muxer.ts +1 -1
  63. package/src/multiaddr/get-net-config.ts +112 -0
  64. package/src/multiaddr/index.ts +1 -1
  65. package/src/multiaddr/is-global-unicast.ts +8 -11
  66. package/src/multiaddr/is-link-local.ts +11 -20
  67. package/src/multiaddr/is-loopback.ts +12 -7
  68. package/src/multiaddr/is-network-address.ts +4 -19
  69. package/src/multiaddr/is-private.ts +9 -14
  70. package/src/multiaddr/utils.ts +46 -0
  71. package/src/queue/index.ts +0 -7
  72. package/src/stream-utils.ts +5 -14
  73. package/dist/src/merge-options.d.ts +0 -7
  74. package/dist/src/merge-options.d.ts.map +0 -1
  75. package/dist/src/merge-options.js +0 -128
  76. package/dist/src/merge-options.js.map +0 -1
  77. package/dist/src/multiaddr/is-ip-based.d.ts +0 -6
  78. package/dist/src/multiaddr/is-ip-based.d.ts.map +0 -1
  79. package/dist/src/multiaddr/is-ip-based.js +0 -18
  80. package/dist/src/multiaddr/is-ip-based.js.map +0 -1
  81. package/dist/src/socket-writer.browser.d.ts +0 -2
  82. package/dist/src/socket-writer.browser.d.ts.map +0 -1
  83. package/dist/src/socket-writer.browser.js +0 -4
  84. package/dist/src/socket-writer.browser.js.map +0 -1
  85. package/dist/src/socket-writer.d.ts +0 -19
  86. package/dist/src/socket-writer.d.ts.map +0 -1
  87. package/dist/src/socket-writer.js +0 -43
  88. package/dist/src/socket-writer.js.map +0 -1
  89. package/src/merge-options.ts +0 -161
  90. package/src/multiaddr/is-ip-based.ts +0 -21
  91. package/src/socket-writer.browser.ts +0 -3
  92. package/src/socket-writer.ts +0 -64
@@ -0,0 +1,112 @@
1
+ import { InvalidParametersError } from '@libp2p/interface'
2
+ import type { Multiaddr } from '@multiformats/multiaddr'
3
+
4
+ export interface IP4NetConfig {
5
+ type: 'ip4'
6
+ host: string
7
+ protocol?: 'tcp' | 'udp'
8
+ port?: number
9
+ cidr?: number
10
+ sni?: string
11
+ }
12
+
13
+ export interface IP6NetConfig {
14
+ type: 'ip6'
15
+ host: string
16
+ protocol?: 'tcp' | 'udp'
17
+ port?: number
18
+ zone?: string
19
+ cidr?: string
20
+ sni?: string
21
+ }
22
+
23
+ export interface DNSNetConfig {
24
+ type: 'dns'
25
+ host: string
26
+ protocol?: 'tcp' | 'udp'
27
+ port: number
28
+ cidr?: number
29
+ }
30
+
31
+ export interface DNS4NetConfig {
32
+ type: 'dns4'
33
+ host: string
34
+ protocol?: 'tcp' | 'udp'
35
+ port: number
36
+ cidr?: number
37
+ }
38
+
39
+ export interface DNS6NetConfig {
40
+ type: 'dns6'
41
+ host: string
42
+ protocol?: 'tcp' | 'udp'
43
+ port: number
44
+ cidr?: number
45
+ }
46
+
47
+ export interface DNSAddrNetConfig {
48
+ type: 'dnsaddr'
49
+ host: string
50
+ protocol?: 'tcp' | 'udp'
51
+ port: number
52
+ cidr?: number
53
+ }
54
+
55
+ export type NetConfig = IP4NetConfig | IP6NetConfig | DNSNetConfig | DNS4NetConfig | DNS6NetConfig | DNSAddrNetConfig
56
+
57
+ /**
58
+ * Returns host/port/etc information for multiaddrs, if it is available.
59
+ *
60
+ * It will throw if the passed multiaddr does not start with a network address,
61
+ * e.g. a IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address
62
+ */
63
+ export function getNetConfig (ma: Multiaddr): NetConfig {
64
+ const components = ma.getComponents()
65
+ const config: any = {}
66
+ let index = 0
67
+
68
+ if (components[index]?.name === 'ip6zone') {
69
+ config.zone = `${components[index].value}`
70
+ index++
71
+ }
72
+
73
+ if (components[index].name === 'ip4' || components[index].name === 'ip6') {
74
+ config.type = components[index].name
75
+ config.host = components[index].value
76
+ index++
77
+ } else if (components[index].name === 'dns' || components[index].name === 'dns4' || components[index].name === 'dns6') {
78
+ config.type = components[index].name
79
+ config.host = components[index].value
80
+ index++
81
+ } else if (components[index].name === 'dnsaddr') {
82
+ config.type = components[index].name
83
+ config.host = `_dnsaddr.${components[index].value}`
84
+ index++
85
+ }
86
+
87
+ if (components[index]?.name === 'tcp' || components[index]?.name === 'udp') {
88
+ config.protocol = components[index].name === 'tcp' ? 'tcp' : 'udp'
89
+ config.port = parseInt(`${components[index].value}`)
90
+ index++
91
+ }
92
+
93
+ if (components[index]?.name === 'ipcidr') {
94
+ if (config.type === 'ip4') {
95
+ config.cidr = parseInt(`${components[index].value}`)
96
+ } else if (config.type === 'ip6') {
97
+ config.cidr = `${components[index].value}`
98
+ }
99
+ index++
100
+ }
101
+
102
+ if (config.type == null || config.host == null) {
103
+ throw new InvalidParametersError(`Multiaddr ${ma} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`)
104
+ }
105
+
106
+ if (components[index]?.name === 'tls' && components[index + 1]?.name === 'sni') {
107
+ config.sni = components[index + 1].value
108
+ index += 2
109
+ }
110
+
111
+ return config
112
+ }
@@ -1,5 +1,5 @@
1
+ export * from './get-net-config.ts'
1
2
  export * from './is-global-unicast.js'
2
- export * from './is-ip-based.js'
3
3
  export * from './is-link-local.js'
4
4
  export * from './is-loopback.js'
5
5
  export * from './is-network-address.js'
@@ -1,5 +1,5 @@
1
1
  import { cidrContains } from '@chainsafe/netmask'
2
- import { CODE_IP6 } from '@multiformats/multiaddr'
2
+ import { getNetConfig } from './get-net-config.ts'
3
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
4
 
5
5
  /**
@@ -7,18 +7,15 @@ import type { Multiaddr } from '@multiformats/multiaddr'
7
7
  */
8
8
  export function isGlobalUnicast (ma: Multiaddr): boolean {
9
9
  try {
10
- for (const { code, value } of ma.getComponents()) {
11
- if (value == null) {
12
- continue
13
- }
10
+ const config = getNetConfig(ma)
14
11
 
15
- if (code === CODE_IP6) {
16
- return cidrContains('2000::/3', value)
17
- }
12
+ switch (config.type) {
13
+ case 'ip6':
14
+ return cidrContains('2000::/3', config.host)
15
+ default:
16
+ return false
18
17
  }
19
18
  } catch {
20
-
19
+ return false
21
20
  }
22
-
23
- return false
24
21
  }
@@ -1,4 +1,4 @@
1
- import { CODE_IP4, CODE_IP6, CODE_IP6ZONE } from '@multiformats/multiaddr'
1
+ import { getNetConfig } from './get-net-config.ts'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
4
  /**
@@ -6,26 +6,17 @@ import type { Multiaddr } from '@multiformats/multiaddr'
6
6
  */
7
7
  export function isLinkLocal (ma: Multiaddr): boolean {
8
8
  try {
9
- for (const { code, value } of ma.getComponents()) {
10
- if (code === CODE_IP6ZONE) {
11
- continue
12
- }
9
+ const config = getNetConfig(ma)
13
10
 
14
- if (value == null) {
15
- continue
16
- }
17
-
18
- if (code === CODE_IP4) {
19
- return value.startsWith('169.254.')
20
- }
21
-
22
- if (code === CODE_IP6) {
23
- return value.toLowerCase().startsWith('fe80')
24
- }
11
+ switch (config.type) {
12
+ case 'ip4':
13
+ return config.host.startsWith('169.254.')
14
+ case 'ip6':
15
+ return config.host.toLowerCase().startsWith('fe80')
16
+ default:
17
+ return false
25
18
  }
26
- } catch {
27
-
19
+ } catch (err) {
20
+ return false
28
21
  }
29
-
30
- return false
31
22
  }
@@ -1,17 +1,22 @@
1
1
  import { isLoopbackAddr } from 'is-loopback-addr'
2
- import { isIpBased } from './is-ip-based.js'
2
+ import { getNetConfig } from './get-net-config.ts'
3
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
4
 
5
5
  /**
6
6
  * Check if a given multiaddr is a loopback address.
7
7
  */
8
8
  export function isLoopback (ma: Multiaddr): boolean {
9
- if (!isIpBased(ma)) {
10
- // not an IP based multiaddr, cannot be private
9
+ try {
10
+ const config = getNetConfig(ma)
11
+
12
+ switch (config.type) {
13
+ case 'ip4':
14
+ case 'ip6':
15
+ return isLoopbackAddr(config.host)
16
+ default:
17
+ return false
18
+ }
19
+ } catch {
11
20
  return false
12
21
  }
13
-
14
- const { address } = ma.nodeAddress()
15
-
16
- return isLoopbackAddr(address)
17
22
  }
@@ -1,30 +1,15 @@
1
- import { CODE_IP4, CODE_IP6, CODE_IP6ZONE, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR } from '@multiformats/multiaddr'
1
+ import { getNetConfig } from './get-net-config.ts'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
- const NETWORK_CODECS = [
5
- CODE_IP4,
6
- CODE_IP6,
7
- CODE_DNS,
8
- CODE_DNS4,
9
- CODE_DNS6,
10
- CODE_DNSADDR
11
- ]
12
-
13
4
  /**
14
5
  * Check if a given multiaddr is a network address
15
6
  */
16
7
  export function isNetworkAddress (ma: Multiaddr): boolean {
17
8
  try {
18
- for (const { code } of ma.getComponents()) {
19
- if (code === CODE_IP6ZONE) {
20
- continue
21
- }
9
+ getNetConfig(ma)
22
10
 
23
- return NETWORK_CODECS.includes(code)
24
- }
11
+ return true
25
12
  } catch {
26
-
13
+ return false
27
14
  }
28
-
29
- return false
30
15
  }
@@ -1,5 +1,5 @@
1
1
  import { isPrivateIp } from '../private-ip.js'
2
- import { isIpBased } from './is-ip-based.js'
2
+ import { getNetConfig } from './get-net-config.ts'
3
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
4
 
5
5
  /**
@@ -7,21 +7,16 @@ import type { Multiaddr } from '@multiformats/multiaddr'
7
7
  */
8
8
  export function isPrivate (ma: Multiaddr): boolean {
9
9
  try {
10
- if (!isIpBased(ma)) {
11
- // not an IP based multiaddr, cannot be private
12
- return false
13
- }
14
-
15
- const [[, value]] = ma.stringTuples()
10
+ const config = getNetConfig(ma)
16
11
 
17
- if (value == null) {
18
- return false
12
+ switch (config.type) {
13
+ case 'ip4':
14
+ case 'ip6':
15
+ return isPrivateIp(config.host) ?? false
16
+ default:
17
+ return config.host === 'localhost'
19
18
  }
20
-
21
- return isPrivateIp(value) ?? false
22
19
  } catch {
23
-
20
+ return false
24
21
  }
25
-
26
- return true
27
22
  }
@@ -0,0 +1,46 @@
1
+ import { CODE_IP4, CODE_IP6, CODE_IP6ZONE, multiaddr } from '@multiformats/multiaddr'
2
+ import type { NetConfig } from './get-net-config.ts'
3
+ import type { Multiaddr } from '@multiformats/multiaddr'
4
+
5
+ export function getIpFromMultiaddr (ma: Multiaddr): string | undefined {
6
+ const components = ma.getComponents()
7
+ let index = 0
8
+
9
+ if (components[0]?.code === CODE_IP6ZONE) {
10
+ index++
11
+ }
12
+
13
+ if (components[index]?.code !== CODE_IP4 && components[index]?.code !== CODE_IP6) {
14
+ return
15
+ }
16
+
17
+ return components[index]?.value
18
+ }
19
+
20
+ export function netConfigToMultiaddr (config: NetConfig, port?: number | string, host?: string): Multiaddr {
21
+ const parts: Array<string | number> = [
22
+ config.type,
23
+ host ?? config.host
24
+ ]
25
+
26
+ if (config.protocol != null) {
27
+ const p = port ?? config.port
28
+
29
+ if (p != null) {
30
+ parts.push(
31
+ config.protocol,
32
+ p
33
+ )
34
+ }
35
+ }
36
+
37
+ if (config.type === 'ip6' && config.zone != null) {
38
+ parts.unshift('ip6zone', config.zone)
39
+ }
40
+
41
+ if (config.cidr != null) {
42
+ parts.push('ipcidr', config.cidr)
43
+ }
44
+
45
+ return multiaddr(`/${parts.join('/')}`)
46
+ }
@@ -99,13 +99,6 @@ export interface QueueEvents<JobReturnType, JobOptions extends AbortOptions = Ab
99
99
  */
100
100
  completed: CustomEvent<JobReturnType>
101
101
 
102
- /**
103
- * A job has failed
104
- *
105
- * @deprecated Listen for the 'failure' event instead - it gives more context and is generally more useful, this event will be removed in a future release
106
- */
107
- error: CustomEvent<Error>
108
-
109
102
  /**
110
103
  * Emitted just after `"completed", a job has finished successfully - this
111
104
  * event gives access to the job and it's result
@@ -6,8 +6,7 @@ import { raceSignal } from 'race-signal'
6
6
  import * as varint from 'uint8-varint'
7
7
  import { Uint8ArrayList } from 'uint8arraylist'
8
8
  import { UnexpectedEOFError } from './errors.js'
9
- import type { MessageStream, MultiaddrConnection, Stream } from '@libp2p/interface'
10
- import type { AbortOptions } from '@multiformats/multiaddr'
9
+ import type { MessageStream, MultiaddrConnection, Stream, AbortOptions } from '@libp2p/interface'
11
10
  import type { Duplex, Source, Transform, Sink } from 'it-stream-types'
12
11
 
13
12
  const DEFAULT_MAX_BUFFER_SIZE = 4_194_304
@@ -51,14 +50,6 @@ export interface ByteStreamOpts {
51
50
  * @default 4_194_304
52
51
  */
53
52
  maxBufferSize?: number
54
-
55
- /**
56
- * If true, prevent message events propagating after they have been received,
57
- *
58
- * This is useful for when there are be other observers of messages and the
59
- * caller does not wish to them to receive anything
60
- */
61
- stopPropagation?: boolean
62
53
  }
63
54
 
64
55
  export interface ReadBytesOptions extends AbortOptions {
@@ -133,10 +124,6 @@ export function byteStream <T extends MessageStream> (stream: T, opts?: ByteStre
133
124
  }
134
125
 
135
126
  const byteStreamOnMessageListener = (evt: StreamMessageEvent): void => {
136
- if (opts?.stopPropagation === true) {
137
- // evt.stopImmediatePropagation()
138
- }
139
-
140
127
  readBuffer.append(evt.data)
141
128
 
142
129
  if (readBuffer.byteLength > maxBufferSize) {
@@ -178,6 +165,7 @@ export function byteStream <T extends MessageStream> (stream: T, opts?: ByteStre
178
165
  }
179
166
 
180
167
  if (readBuffer.byteLength < options.bytes) {
168
+ stream.log.error('closed after reading %d/%d bytes', readBuffer.byteLength, options.bytes)
181
169
  throw new UnexpectedEOFError(`Unexpected EOF - stream closed after reading ${readBuffer.byteLength}/${options.bytes} bytes`)
182
170
  }
183
171
  }
@@ -211,6 +199,7 @@ export function byteStream <T extends MessageStream> (stream: T, opts?: ByteStre
211
199
 
212
200
  if (readBuffer.byteLength < toRead) {
213
201
  if (isEOF(stream)) {
202
+ stream.log.error('closed while reading %d/%d bytes', readBuffer.byteLength, toRead)
214
203
  throw new UnexpectedEOFError(`Unexpected EOF - stream closed while reading ${readBuffer.byteLength}/${toRead} bytes`)
215
204
  }
216
205
 
@@ -353,10 +342,12 @@ export function lpStream <T extends MessageStream> (stream: T, opts: Partial<Len
353
342
  })
354
343
 
355
344
  if (buf == null) {
345
+ stream.log.error('tried to read %d bytes but the stream closed', dataLength)
356
346
  throw new UnexpectedEOFError(`Unexpected EOF - tried to read ${dataLength} bytes but the stream closed`)
357
347
  }
358
348
 
359
349
  if (buf.byteLength !== dataLength) {
350
+ stream.log.error('read %d/%d bytes before the stream closed', buf.byteLength, dataLength)
360
351
  throw new UnexpectedEOFError(`Unexpected EOF - read ${buf.byteLength}/${dataLength} bytes before the stream closed`)
361
352
  }
362
353
 
@@ -1,7 +0,0 @@
1
- /**
2
- * Port of `merge-options` to typescript
3
- *
4
- * @see https://github.com/schnittstabil/merge-options/pull/28
5
- */
6
- export declare function mergeOptions(this: any, ...options: any[]): any;
7
- //# sourceMappingURL=merge-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-options.d.ts","sourceRoot":"","sources":["../../src/merge-options.ts"],"names":[],"mappings":"AA0IA;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAiB/D"}
@@ -1,128 +0,0 @@
1
- import isOptionObject from 'is-plain-obj';
2
- const { hasOwnProperty } = Object.prototype;
3
- const { propertyIsEnumerable } = Object;
4
- const defineProperty = (object, name, value) => {
5
- Object.defineProperty(object, name, {
6
- value,
7
- writable: true,
8
- enumerable: true,
9
- configurable: true
10
- });
11
- };
12
- const globalThis = this;
13
- const defaultMergeOptions = {
14
- concatArrays: false,
15
- ignoreUndefined: false
16
- };
17
- const getEnumerableOwnPropertyKeys = (value) => {
18
- const keys = [];
19
- for (const key in value) {
20
- if (hasOwnProperty.call(value, key)) {
21
- keys.push(key);
22
- }
23
- }
24
- /* istanbul ignore else */
25
- if (Object.getOwnPropertySymbols) {
26
- const symbols = Object.getOwnPropertySymbols(value);
27
- for (const symbol of symbols) {
28
- if (propertyIsEnumerable.call(value, symbol)) {
29
- keys.push(symbol);
30
- }
31
- }
32
- }
33
- return keys;
34
- };
35
- function clone(value) {
36
- if (Array.isArray(value)) {
37
- return cloneArray(value);
38
- }
39
- if (isOptionObject(value)) {
40
- return cloneOptionObject(value);
41
- }
42
- return value;
43
- }
44
- function cloneArray(array) {
45
- const result = array.slice(0, 0);
46
- getEnumerableOwnPropertyKeys(array).forEach(key => {
47
- defineProperty(result, key, clone(array[key]));
48
- });
49
- return result;
50
- }
51
- function cloneOptionObject(object) {
52
- const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {};
53
- getEnumerableOwnPropertyKeys(object).forEach(key => {
54
- defineProperty(result, key, clone(object[key]));
55
- });
56
- return result;
57
- }
58
- const mergeKeys = (merged, source, keys, config) => {
59
- keys.forEach(key => {
60
- if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
61
- return;
62
- }
63
- // Do not recurse into prototype chain of merged
64
- if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
65
- defineProperty(merged, key, merge(merged[key], source[key], config));
66
- }
67
- else {
68
- defineProperty(merged, key, clone(source[key]));
69
- }
70
- });
71
- return merged;
72
- };
73
- /**
74
- * see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
75
- */
76
- const concatArrays = (merged, source, config) => {
77
- let result = merged.slice(0, 0);
78
- let resultIndex = 0;
79
- [merged, source].forEach(array => {
80
- const indices = [];
81
- // `result.concat(array)` with cloning
82
- for (let k = 0; k < array.length; k++) {
83
- if (!hasOwnProperty.call(array, k)) {
84
- continue;
85
- }
86
- indices.push(String(k));
87
- if (array === merged) {
88
- // Already cloned
89
- defineProperty(result, resultIndex++, array[k]);
90
- }
91
- else {
92
- defineProperty(result, resultIndex++, clone(array[k]));
93
- }
94
- }
95
- // Merge non-index keys
96
- result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config);
97
- });
98
- return result;
99
- };
100
- function merge(merged, source, config) {
101
- if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
102
- return concatArrays(merged, source, config);
103
- }
104
- if (!isOptionObject(source) || !isOptionObject(merged)) {
105
- return clone(source);
106
- }
107
- return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config);
108
- }
109
- /**
110
- * Port of `merge-options` to typescript
111
- *
112
- * @see https://github.com/schnittstabil/merge-options/pull/28
113
- */
114
- export function mergeOptions(...options) {
115
- const config = merge(clone(defaultMergeOptions), (this !== globalThis && this) || {}, defaultMergeOptions);
116
- let merged = { _: {} };
117
- for (const option of options) {
118
- if (option === undefined) {
119
- continue;
120
- }
121
- if (!isOptionObject(option)) {
122
- throw new TypeError('`' + option + '` is not an Option Object');
123
- }
124
- merged = merge(merged, { _: option }, config);
125
- }
126
- return merged._;
127
- }
128
- //# sourceMappingURL=merge-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-options.js","sourceRoot":"","sources":["../../src/merge-options.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,cAAc,CAAA;AAEzC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;AAC3C,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;AACvC,MAAM,cAAc,GAAG,CAAC,MAAW,EAAE,IAAS,EAAE,KAAU,EAAQ,EAAE;IAClE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;QAClC,KAAK;QACL,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,mBAAmB,GAAG;IAC1B,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;CACvB,CAAA;AAED,MAAM,4BAA4B,GAAG,CAAC,KAAU,EAAS,EAAE;IACzD,MAAM,IAAI,GAAG,EAAE,CAAA;IAEf,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;QAEnD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;gBAC7C,IA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EAAE,EAAE,mBAAmB,CAAC,CAAA;IAC1G,IAAI,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAA;IAEtB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,SAAQ;QACV,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,SAAS,CAAC,GAAG,GAAG,MAAM,GAAG,2BAA2B,CAAC,CAAA;QACjE,CAAC;QAED,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC,CAAC,CAAA;AACjB,CAAC"}
@@ -1,6 +0,0 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr';
2
- /**
3
- * Check if a given multiaddr is IP-based
4
- */
5
- export declare function isIpBased(ma: Multiaddr): boolean;
6
- //# sourceMappingURL=is-ip-based.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-ip-based.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-ip-based.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,SAAS,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAcjD"}
@@ -1,18 +0,0 @@
1
- import { CODE_IP4, CODE_IP6, CODE_IP6ZONE } from '@multiformats/multiaddr';
2
- /**
3
- * Check if a given multiaddr is IP-based
4
- */
5
- export function isIpBased(ma) {
6
- try {
7
- for (const { code } of ma.getComponents()) {
8
- if (code === CODE_IP6ZONE) {
9
- continue;
10
- }
11
- return code === CODE_IP4 || code === CODE_IP6;
12
- }
13
- }
14
- catch {
15
- }
16
- return false;
17
- }
18
- //# sourceMappingURL=is-ip-based.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-ip-based.js","sourceRoot":"","sources":["../../../src/multiaddr/is-ip-based.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAG1E;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,IAAI,CAAC;QACH,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC;YAC1C,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,SAAQ;YACV,CAAC;YAED,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAAA;QAC/C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function socketWriter(): void;
2
- //# sourceMappingURL=socket-writer.browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"socket-writer.browser.d.ts","sourceRoot":"","sources":["../../src/socket-writer.browser.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAK,IAAI,CAEpC"}
@@ -1,4 +0,0 @@
1
- export function socketWriter() {
2
- throw new Error('Unsupported in browsers');
3
- }
4
- //# sourceMappingURL=socket-writer.browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"socket-writer.browser.js","sourceRoot":"","sources":["../../src/socket-writer.browser.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY;IAC1B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;AAC5C,CAAC"}
@@ -1,19 +0,0 @@
1
- import stream from 'node:stream';
2
- import { Uint8ArrayList } from 'uint8arraylist';
3
- export interface SocketWriter {
4
- /**
5
- * Write any available data into the socket, if the socket's internal write
6
- * buffer has available capacity
7
- */
8
- pull(): boolean;
9
- /**
10
- * Write data into the socket, returns false if the socket's internal write
11
- * buffer is at capacity
12
- */
13
- write(data: Uint8Array | Uint8Array[] | Uint8ArrayList): boolean;
14
- }
15
- /**
16
- * @deprecated delete if unused
17
- */
18
- export declare function socketWriter(socket: stream.Duplex): SocketWriter;
19
- //# sourceMappingURL=socket-writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"socket-writer.d.ts","sourceRoot":"","sources":["../../src/socket-writer.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,IAAK,OAAO,CAAA;IAEhB;;;OAGG;IACH,KAAK,CAAE,IAAI,EAAE,UAAU,GAAG,UAAU,EAAE,GAAG,cAAc,GAAG,OAAO,CAAA;CAClE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,YAAY,CA2CjE"}