@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
@@ -1,43 +0,0 @@
1
- import stream from 'node:stream';
2
- import { Uint8ArrayList } from 'uint8arraylist';
3
- /**
4
- * @deprecated delete if unused
5
- */
6
- export function socketWriter(socket) {
7
- const queue = new Uint8ArrayList();
8
- return {
9
- pull() {
10
- if (socket.writableNeedDrain) {
11
- return false;
12
- }
13
- for (const buf of queue) {
14
- queue.consume(buf.byteLength);
15
- if (!socket.write(buf)) {
16
- // continue writing after drain event. this is a synchronous operation
17
- // so it will not interleave with the `this.writeToSocket()`
18
- // invocation in this.sendData so all data will be sent in-order
19
- if (queue.byteLength > 0) {
20
- socket.once('drain', () => {
21
- this.pull();
22
- });
23
- }
24
- return false;
25
- }
26
- }
27
- return true;
28
- },
29
- write(data) {
30
- if (Array.isArray(data)) {
31
- queue.appendAll(data);
32
- }
33
- else {
34
- queue.append(data);
35
- }
36
- if (socket.writableNeedDrain) {
37
- return false;
38
- }
39
- return this.pull();
40
- }
41
- };
42
- }
43
- //# sourceMappingURL=socket-writer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"socket-writer.js","sourceRoot":"","sources":["../../src/socket-writer.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAgB/C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAE,MAAqB;IACjD,MAAM,KAAK,GAAG,IAAI,cAAc,EAAE,CAAA;IAElC,OAAO;QACL,IAAI;YACF,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,OAAO,KAAK,CAAA;YACd,CAAC;YAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;gBAE7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;oBACvB,sEAAsE;oBACtE,4DAA4D;oBAC5D,gEAAgE;oBAChE,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;wBACzB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;4BACxB,IAAI,CAAC,IAAI,EAAE,CAAA;wBACb,CAAC,CAAC,CAAA;oBACJ,CAAC;oBAED,OAAO,KAAK,CAAA;gBACd,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAA;QACb,CAAC;QAED,KAAK,CAAE,IAAgD;YACrD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;YACvB,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACpB,CAAC;YAED,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,OAAO,KAAK,CAAA;YACd,CAAC;YAED,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;QACpB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,161 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
1
- import { CODE_IP4, CODE_IP6, CODE_IP6ZONE } from '@multiformats/multiaddr'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
-
4
- /**
5
- * Check if a given multiaddr is IP-based
6
- */
7
- export function isIpBased (ma: Multiaddr): boolean {
8
- try {
9
- for (const { code } of ma.getComponents()) {
10
- if (code === CODE_IP6ZONE) {
11
- continue
12
- }
13
-
14
- return code === CODE_IP4 || code === CODE_IP6
15
- }
16
- } catch {
17
-
18
- }
19
-
20
- return false
21
- }
@@ -1,3 +0,0 @@
1
- export function socketWriter (): void {
2
- throw new Error('Unsupported in browsers')
3
- }
@@ -1,64 +0,0 @@
1
- import stream from 'node:stream'
2
- import { Uint8ArrayList } from 'uint8arraylist'
3
-
4
- export interface SocketWriter {
5
- /**
6
- * Write any available data into the socket, if the socket's internal write
7
- * buffer has available capacity
8
- */
9
- pull (): boolean
10
-
11
- /**
12
- * Write data into the socket, returns false if the socket's internal write
13
- * buffer is at capacity
14
- */
15
- write (data: Uint8Array | Uint8Array[] | Uint8ArrayList): boolean
16
- }
17
-
18
- /**
19
- * @deprecated delete if unused
20
- */
21
- export function socketWriter (socket: stream.Duplex): SocketWriter {
22
- const queue = new Uint8ArrayList()
23
-
24
- return {
25
- pull (): boolean {
26
- if (socket.writableNeedDrain) {
27
- return false
28
- }
29
-
30
- for (const buf of queue) {
31
- queue.consume(buf.byteLength)
32
-
33
- if (!socket.write(buf)) {
34
- // continue writing after drain event. this is a synchronous operation
35
- // so it will not interleave with the `this.writeToSocket()`
36
- // invocation in this.sendData so all data will be sent in-order
37
- if (queue.byteLength > 0) {
38
- socket.once('drain', () => {
39
- this.pull()
40
- })
41
- }
42
-
43
- return false
44
- }
45
- }
46
-
47
- return true
48
- },
49
-
50
- write (data: Uint8Array | Uint8Array[] | Uint8ArrayList): boolean {
51
- if (Array.isArray(data)) {
52
- queue.appendAll(data)
53
- } else {
54
- queue.append(data)
55
- }
56
-
57
- if (socket.writableNeedDrain) {
58
- return false
59
- }
60
-
61
- return this.pull()
62
- }
63
- }
64
- }