@libp2p/utils 6.7.2-0f07e3df5 → 6.7.2-6059227cb

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 (39) 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/index.d.ts +0 -2
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +0 -2
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/mock-muxer.js +1 -1
  11. package/dist/src/mock-muxer.js.map +1 -1
  12. package/dist/src/queue/index.d.ts +0 -6
  13. package/dist/src/queue/index.d.ts.map +1 -1
  14. package/dist/src/queue/index.js.map +1 -1
  15. package/dist/src/stream-utils.d.ts +0 -7
  16. package/dist/src/stream-utils.d.ts.map +1 -1
  17. package/dist/src/stream-utils.js +4 -3
  18. package/dist/src/stream-utils.js.map +1 -1
  19. package/package.json +8 -11
  20. package/src/abstract-message-stream.ts +8 -4
  21. package/src/index.ts +0 -2
  22. package/src/mock-muxer.ts +1 -1
  23. package/src/queue/index.ts +0 -7
  24. package/src/stream-utils.ts +4 -12
  25. package/dist/src/merge-options.d.ts +0 -7
  26. package/dist/src/merge-options.d.ts.map +0 -1
  27. package/dist/src/merge-options.js +0 -128
  28. package/dist/src/merge-options.js.map +0 -1
  29. package/dist/src/socket-writer.browser.d.ts +0 -2
  30. package/dist/src/socket-writer.browser.d.ts.map +0 -1
  31. package/dist/src/socket-writer.browser.js +0 -4
  32. package/dist/src/socket-writer.browser.js.map +0 -1
  33. package/dist/src/socket-writer.d.ts +0 -19
  34. package/dist/src/socket-writer.d.ts.map +0 -1
  35. package/dist/src/socket-writer.js +0 -43
  36. package/dist/src/socket-writer.js.map +0 -1
  37. package/src/merge-options.ts +0 -161
  38. package/src/socket-writer.browser.ts +0 -3
  39. package/src/socket-writer.ts +0 -64
@@ -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,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MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,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,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"}
@@ -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,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
- }