@lodestar/reqresp 1.41.0-dev.a35cbde8b3 → 1.41.0-dev.aeab9f930d

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 (151) hide show
  1. package/README.md +1 -1
  2. package/lib/ReqResp.d.ts +3 -3
  3. package/lib/ReqResp.d.ts.map +1 -1
  4. package/lib/ReqResp.js +4 -4
  5. package/lib/ReqResp.js.map +1 -1
  6. package/lib/encoders/requestDecode.d.ts +2 -3
  7. package/lib/encoders/requestDecode.d.ts.map +1 -1
  8. package/lib/encoders/requestDecode.js +28 -11
  9. package/lib/encoders/requestDecode.js.map +1 -1
  10. package/lib/encoders/requestEncode.d.ts +1 -1
  11. package/lib/encoders/requestEncode.d.ts.map +1 -1
  12. package/lib/encoders/requestEncode.js +1 -1
  13. package/lib/encoders/requestEncode.js.map +1 -1
  14. package/lib/encoders/responseDecode.d.ts +10 -10
  15. package/lib/encoders/responseDecode.d.ts.map +1 -1
  16. package/lib/encoders/responseDecode.js +63 -60
  17. package/lib/encoders/responseDecode.js.map +1 -1
  18. package/lib/encoders/responseEncode.d.ts +2 -4
  19. package/lib/encoders/responseEncode.d.ts.map +1 -1
  20. package/lib/encoders/responseEncode.js +13 -22
  21. package/lib/encoders/responseEncode.js.map +1 -1
  22. package/lib/encodingStrategies/index.d.ts +4 -3
  23. package/lib/encodingStrategies/index.d.ts.map +1 -1
  24. package/lib/encodingStrategies/index.js +4 -4
  25. package/lib/encodingStrategies/index.js.map +1 -1
  26. package/lib/encodingStrategies/sszSnappy/decode.d.ts +5 -4
  27. package/lib/encodingStrategies/sszSnappy/decode.d.ts.map +1 -1
  28. package/lib/encodingStrategies/sszSnappy/decode.js +83 -52
  29. package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
  30. package/lib/encodingStrategies/sszSnappy/encode.d.ts +2 -2
  31. package/lib/encodingStrategies/sszSnappy/encode.d.ts.map +1 -1
  32. package/lib/encodingStrategies/sszSnappy/encode.js +1 -1
  33. package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
  34. package/lib/encodingStrategies/sszSnappy/errors.d.ts +0 -8
  35. package/lib/encodingStrategies/sszSnappy/errors.d.ts.map +1 -1
  36. package/lib/encodingStrategies/sszSnappy/errors.js +2 -3
  37. package/lib/encodingStrategies/sszSnappy/errors.js.map +1 -1
  38. package/lib/encodingStrategies/sszSnappy/index.d.ts +0 -1
  39. package/lib/encodingStrategies/sszSnappy/index.d.ts.map +1 -1
  40. package/lib/encodingStrategies/sszSnappy/index.js +0 -1
  41. package/lib/encodingStrategies/sszSnappy/index.js.map +1 -1
  42. package/lib/encodingStrategies/sszSnappy/utils.js.map +1 -1
  43. package/lib/interface.js +2 -1
  44. package/lib/interface.js.map +1 -1
  45. package/lib/metrics.d.ts +1 -7
  46. package/lib/metrics.d.ts.map +1 -1
  47. package/lib/metrics.js +1 -17
  48. package/lib/metrics.js.map +1 -1
  49. package/lib/rate_limiter/ReqRespRateLimiter.d.ts.map +1 -1
  50. package/lib/rate_limiter/ReqRespRateLimiter.js.map +1 -1
  51. package/lib/rate_limiter/rateLimiterGRCA.d.ts.map +1 -1
  52. package/lib/rate_limiter/rateLimiterGRCA.js.map +1 -1
  53. package/lib/rate_limiter/selfRateLimiter.d.ts.map +1 -1
  54. package/lib/rate_limiter/selfRateLimiter.js.map +1 -1
  55. package/lib/request/errors.d.ts +1 -7
  56. package/lib/request/errors.d.ts.map +1 -1
  57. package/lib/request/errors.js +3 -6
  58. package/lib/request/errors.js.map +1 -1
  59. package/lib/request/index.d.ts +0 -3
  60. package/lib/request/index.d.ts.map +1 -1
  61. package/lib/request/index.js +85 -70
  62. package/lib/request/index.js.map +1 -1
  63. package/lib/response/errors.d.ts.map +1 -1
  64. package/lib/response/errors.js +2 -1
  65. package/lib/response/errors.js.map +1 -1
  66. package/lib/response/index.d.ts +2 -2
  67. package/lib/response/index.d.ts.map +1 -1
  68. package/lib/response/index.js +46 -50
  69. package/lib/response/index.js.map +1 -1
  70. package/lib/types.d.ts +1 -2
  71. package/lib/types.d.ts.map +1 -1
  72. package/lib/types.js +7 -5
  73. package/lib/types.js.map +1 -1
  74. package/lib/utils/collectExactOne.js.map +1 -1
  75. package/lib/utils/collectMaxResponse.d.ts.map +1 -1
  76. package/lib/utils/collectMaxResponse.js +1 -2
  77. package/lib/utils/collectMaxResponse.js.map +1 -1
  78. package/lib/utils/errorMessage.d.ts +3 -3
  79. package/lib/utils/errorMessage.d.ts.map +1 -1
  80. package/lib/utils/errorMessage.js +14 -13
  81. package/lib/utils/errorMessage.js.map +1 -1
  82. package/lib/utils/index.d.ts +1 -3
  83. package/lib/utils/index.d.ts.map +1 -1
  84. package/lib/utils/index.js +1 -3
  85. package/lib/utils/index.js.map +1 -1
  86. package/lib/utils/peerId.js.map +1 -1
  87. package/lib/utils/protocolId.d.ts +2 -2
  88. package/lib/utils/protocolId.js +2 -2
  89. package/lib/utils/protocolId.js.map +1 -1
  90. package/lib/utils/snappyCommon.js +2 -1
  91. package/lib/utils/snappyCommon.js.map +1 -1
  92. package/lib/utils/snappyCompress.d.ts +1 -1
  93. package/lib/utils/snappyCompress.d.ts.map +1 -1
  94. package/lib/utils/snappyCompress.js +1 -1
  95. package/lib/utils/snappyCompress.js.map +1 -1
  96. package/lib/utils/snappyIndex.d.ts +1 -1
  97. package/lib/utils/snappyIndex.d.ts.map +1 -1
  98. package/lib/utils/snappyIndex.js +1 -1
  99. package/lib/utils/snappyIndex.js.map +1 -1
  100. package/lib/utils/snappyUncompress.d.ts +7 -11
  101. package/lib/utils/snappyUncompress.d.ts.map +1 -1
  102. package/lib/utils/snappyUncompress.js +68 -68
  103. package/lib/utils/snappyUncompress.js.map +1 -1
  104. package/lib/utils/stream.d.ts +6 -0
  105. package/lib/utils/stream.d.ts.map +1 -0
  106. package/lib/utils/stream.js +21 -0
  107. package/lib/utils/stream.js.map +1 -0
  108. package/package.json +16 -18
  109. package/src/ReqResp.ts +4 -4
  110. package/src/encoders/requestDecode.ts +32 -16
  111. package/src/encoders/requestEncode.ts +1 -1
  112. package/src/encoders/responseDecode.ts +68 -72
  113. package/src/encoders/responseEncode.ts +17 -29
  114. package/src/encodingStrategies/index.ts +8 -6
  115. package/src/encodingStrategies/sszSnappy/decode.ts +111 -53
  116. package/src/encodingStrategies/sszSnappy/encode.ts +2 -2
  117. package/src/encodingStrategies/sszSnappy/errors.ts +0 -4
  118. package/src/encodingStrategies/sszSnappy/index.ts +0 -1
  119. package/src/metrics.ts +1 -17
  120. package/src/request/errors.ts +1 -6
  121. package/src/request/index.ts +109 -86
  122. package/src/response/index.ts +55 -61
  123. package/src/types.ts +1 -3
  124. package/src/utils/collectMaxResponse.ts +1 -2
  125. package/src/utils/errorMessage.ts +14 -13
  126. package/src/utils/index.ts +1 -3
  127. package/src/utils/protocolId.ts +2 -2
  128. package/src/utils/snappyCompress.ts +1 -1
  129. package/src/utils/snappyIndex.ts +1 -1
  130. package/src/utils/snappyUncompress.ts +73 -75
  131. package/src/utils/stream.ts +34 -0
  132. package/lib/utils/abortableSource.d.ts +0 -12
  133. package/lib/utils/abortableSource.d.ts.map +0 -1
  134. package/lib/utils/abortableSource.js +0 -69
  135. package/lib/utils/abortableSource.js.map +0 -1
  136. package/lib/utils/bufferedSource.d.ts +0 -16
  137. package/lib/utils/bufferedSource.d.ts.map +0 -1
  138. package/lib/utils/bufferedSource.js +0 -40
  139. package/lib/utils/bufferedSource.js.map +0 -1
  140. package/lib/utils/onChunk.d.ts +0 -6
  141. package/lib/utils/onChunk.d.ts.map +0 -1
  142. package/lib/utils/onChunk.js +0 -13
  143. package/lib/utils/onChunk.js.map +0 -1
  144. package/lib/utils/snappy.d.ts +0 -3
  145. package/lib/utils/snappy.d.ts.map +0 -1
  146. package/lib/utils/snappy.js +0 -3
  147. package/lib/utils/snappy.js.map +0 -1
  148. package/src/utils/abortableSource.ts +0 -80
  149. package/src/utils/bufferedSource.ts +0 -46
  150. package/src/utils/onChunk.ts +0 -12
  151. package/src/utils/snappy.ts +0 -2
@@ -1,40 +0,0 @@
1
- import { Uint8ArrayList } from "uint8arraylist";
2
- /**
3
- * Wraps a buffer chunk stream source with another async iterable
4
- * so it can be reused in multiple for..of statements.
5
- *
6
- * Uses a BufferList internally to make sure all chunks are consumed
7
- * when switching consumers
8
- */
9
- export class BufferedSource {
10
- isDone = false;
11
- buffer;
12
- source;
13
- constructor(source) {
14
- this.buffer = new Uint8ArrayList();
15
- this.source = source;
16
- }
17
- [Symbol.asyncIterator]() {
18
- const that = this;
19
- let firstNext = true;
20
- return {
21
- async next() {
22
- // Prevent fetching a new chunk if there are pending bytes
23
- // not processed by a previous consumer of this BufferedSource
24
- if (firstNext && that.buffer.length > 0) {
25
- firstNext = false;
26
- return { done: false, value: that.buffer };
27
- }
28
- const { done, value: chunk } = await that.source.next();
29
- if (done === true) {
30
- that.isDone = true;
31
- return { done: true, value: undefined };
32
- }
33
- // Concat new chunk and return a reference to its BufferList instance
34
- that.buffer.append(chunk);
35
- return { done: false, value: that.buffer };
36
- },
37
- };
38
- }
39
- }
40
- //# sourceMappingURL=bufferedSource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bufferedSource.js","sourceRoot":"","sources":["../../src/utils/bufferedSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IACzB,MAAM,GAAG,KAAK,CAAC;IACP,MAAM,CAAiB;IACvB,MAAM,CAA8C;IAE5D,YAAY,MAAmD;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,OAAO;YACL,KAAK,CAAC,IAAI;gBACR,0DAA0D;gBAC1D,8DAA8D;gBAC9D,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACxC,SAAS,GAAG,KAAK,CAAC;oBAClB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC;gBAC3C,CAAC;gBAED,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACtD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;oBAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;oBACnB,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAC,CAAC;gBACxC,CAAC;gBAED,qEAAqE;gBACrE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC1B,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC;YAC3C,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Calls `callback` with each `chunk` received from the `source` AsyncIterable
3
- * Useful for logging, or cancelling timeouts
4
- */
5
- export declare function onChunk<T>(callback: (chunk: T) => void): (source: AsyncIterable<T>) => AsyncIterable<T>;
6
- //# sourceMappingURL=onChunk.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onChunk.d.ts","sourceRoot":"","sources":["../../src/utils/onChunk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAOvG"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Calls `callback` with each `chunk` received from the `source` AsyncIterable
3
- * Useful for logging, or cancelling timeouts
4
- */
5
- export function onChunk(callback) {
6
- return async function* onChunkTransform(source) {
7
- for await (const chunk of source) {
8
- callback(chunk);
9
- yield chunk;
10
- }
11
- };
12
- }
13
- //# sourceMappingURL=onChunk.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onChunk.js","sourceRoot":"","sources":["../../src/utils/onChunk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAI,QAA4B;IACrD,OAAO,KAAK,SAAS,CAAC,CAAC,gBAAgB,CAAC,MAAM;QAC5C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACjC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1,3 +0,0 @@
1
- export { compressSync as compress } from "snappy";
2
- export { uncompress } from "snappyjs";
3
- //# sourceMappingURL=snappy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snappy.d.ts","sourceRoot":"","sources":["../../src/utils/snappy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,IAAI,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC"}
@@ -1,3 +0,0 @@
1
- export { compressSync as compress } from "snappy";
2
- export { uncompress } from "snappyjs";
3
- //# sourceMappingURL=snappy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snappy.js","sourceRoot":"","sources":["../../src/utils/snappy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,IAAI,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC"}
@@ -1,80 +0,0 @@
1
- /**
2
- * Wraps an AsyncIterable and rejects early if any signal aborts.
3
- * Throws the error returned by `getError()` of each signal options.
4
- *
5
- * Simplified fork of `"abortable-iterator"`.
6
- * Read function's source for reasoning of the fork.
7
- */
8
- export function abortableSource<T>(
9
- sourceArg: AsyncIterable<T>,
10
- signals: {
11
- signal: AbortSignal;
12
- getError: () => Error;
13
- }[]
14
- ): AsyncIterable<T> {
15
- const source = sourceArg as AsyncGenerator<T>;
16
-
17
- async function* abortable(): AsyncIterable<T> {
18
- // Handler that will hold a reference to the `abort()` promise,
19
- // necessary for the signal abort listeners to reject the iterable promise
20
- let nextAbortHandler: ((error: Error) => void) | null = null;
21
-
22
- // For each signal register an abortHandler(), and prepare clean-up with `onDoneCbs`
23
- const onDoneCbs: (() => void)[] = [];
24
- for (const {signal, getError} of signals) {
25
- const abortHandler = (): void => {
26
- if (nextAbortHandler) nextAbortHandler(getError());
27
- };
28
- signal.addEventListener("abort", abortHandler);
29
- onDoneCbs.push(() => {
30
- signal.removeEventListener("abort", abortHandler);
31
- });
32
- }
33
-
34
- try {
35
- while (true) {
36
- // Abort early if any signal is aborted
37
- for (const {signal, getError} of signals) {
38
- if (signal.aborted) {
39
- throw getError();
40
- }
41
- }
42
-
43
- // Race the iterator and the abort signals
44
- const result = await Promise.race([
45
- new Promise<never>((_, reject) => {
46
- nextAbortHandler = (error) => reject(error);
47
- }),
48
- source.next(),
49
- ]);
50
-
51
- // source.next() resolved first
52
- nextAbortHandler = null;
53
-
54
- if (result.done) {
55
- return;
56
- }
57
-
58
- yield result.value;
59
- }
60
- } catch (err) {
61
- // End the iterator if it is a generator
62
- if (typeof source.return === "function") {
63
- // This source.return() function may never resolve depending on the source AsyncGenerator implementation.
64
- // This is the main reason to fork "abortable-iterator", which caused our node to get stuck during Sync.
65
- // We choose to call .return() but not await it. In general, source.return should never throw. If it does,
66
- // it a problem of the source implementor, and thus logged as an unhandled rejection. If that happens,
67
- // the source implementor should fix the upstream code.
68
- void source.return(null);
69
- }
70
-
71
- throw err;
72
- } finally {
73
- for (const cb of onDoneCbs) {
74
- cb();
75
- }
76
- }
77
- }
78
-
79
- return abortable();
80
- }
@@ -1,46 +0,0 @@
1
- import {Uint8ArrayList} from "uint8arraylist";
2
-
3
- /**
4
- * Wraps a buffer chunk stream source with another async iterable
5
- * so it can be reused in multiple for..of statements.
6
- *
7
- * Uses a BufferList internally to make sure all chunks are consumed
8
- * when switching consumers
9
- */
10
- export class BufferedSource {
11
- isDone = false;
12
- private buffer: Uint8ArrayList;
13
- private source: AsyncGenerator<Uint8ArrayList | Uint8Array>;
14
-
15
- constructor(source: AsyncGenerator<Uint8ArrayList | Uint8Array>) {
16
- this.buffer = new Uint8ArrayList();
17
- this.source = source;
18
- }
19
-
20
- [Symbol.asyncIterator](): AsyncIterator<Uint8ArrayList> {
21
- const that = this;
22
-
23
- let firstNext = true;
24
-
25
- return {
26
- async next() {
27
- // Prevent fetching a new chunk if there are pending bytes
28
- // not processed by a previous consumer of this BufferedSource
29
- if (firstNext && that.buffer.length > 0) {
30
- firstNext = false;
31
- return {done: false, value: that.buffer};
32
- }
33
-
34
- const {done, value: chunk} = await that.source.next();
35
- if (done === true) {
36
- that.isDone = true;
37
- return {done: true, value: undefined};
38
- }
39
-
40
- // Concat new chunk and return a reference to its BufferList instance
41
- that.buffer.append(chunk);
42
- return {done: false, value: that.buffer};
43
- },
44
- };
45
- }
46
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Calls `callback` with each `chunk` received from the `source` AsyncIterable
3
- * Useful for logging, or cancelling timeouts
4
- */
5
- export function onChunk<T>(callback: (chunk: T) => void): (source: AsyncIterable<T>) => AsyncIterable<T> {
6
- return async function* onChunkTransform(source) {
7
- for await (const chunk of source) {
8
- callback(chunk);
9
- yield chunk;
10
- }
11
- };
12
- }
@@ -1,2 +0,0 @@
1
- export {compressSync as compress} from "snappy";
2
- export {uncompress} from "snappyjs";