@lodestar/reqresp 1.41.0-dev.ef310100c0 → 1.41.0-dev.f2caa915ab

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 (133) hide show
  1. package/README.md +1 -1
  2. package/lib/ReqResp.d.ts +3 -3
  3. package/lib/ReqResp.js +4 -4
  4. package/lib/ReqResp.js.map +1 -1
  5. package/lib/encoders/requestDecode.d.ts +2 -3
  6. package/lib/encoders/requestDecode.d.ts.map +1 -1
  7. package/lib/encoders/requestDecode.js +28 -11
  8. package/lib/encoders/requestDecode.js.map +1 -1
  9. package/lib/encoders/requestEncode.d.ts +1 -1
  10. package/lib/encoders/requestEncode.d.ts.map +1 -1
  11. package/lib/encoders/requestEncode.js +1 -1
  12. package/lib/encoders/requestEncode.js.map +1 -1
  13. package/lib/encoders/responseDecode.d.ts +10 -10
  14. package/lib/encoders/responseDecode.d.ts.map +1 -1
  15. package/lib/encoders/responseDecode.js +63 -60
  16. package/lib/encoders/responseDecode.js.map +1 -1
  17. package/lib/encoders/responseEncode.d.ts +2 -4
  18. package/lib/encoders/responseEncode.d.ts.map +1 -1
  19. package/lib/encoders/responseEncode.js +13 -22
  20. package/lib/encoders/responseEncode.js.map +1 -1
  21. package/lib/encodingStrategies/index.d.ts +4 -3
  22. package/lib/encodingStrategies/index.d.ts.map +1 -1
  23. package/lib/encodingStrategies/index.js +4 -4
  24. package/lib/encodingStrategies/index.js.map +1 -1
  25. package/lib/encodingStrategies/sszSnappy/decode.d.ts +5 -4
  26. package/lib/encodingStrategies/sszSnappy/decode.d.ts.map +1 -1
  27. package/lib/encodingStrategies/sszSnappy/decode.js +83 -52
  28. package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
  29. package/lib/encodingStrategies/sszSnappy/encode.d.ts +2 -2
  30. package/lib/encodingStrategies/sszSnappy/encode.d.ts.map +1 -1
  31. package/lib/encodingStrategies/sszSnappy/encode.js +1 -1
  32. package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
  33. package/lib/encodingStrategies/sszSnappy/errors.d.ts +0 -8
  34. package/lib/encodingStrategies/sszSnappy/errors.d.ts.map +1 -1
  35. package/lib/encodingStrategies/sszSnappy/errors.js +0 -2
  36. package/lib/encodingStrategies/sszSnappy/errors.js.map +1 -1
  37. package/lib/encodingStrategies/sszSnappy/index.d.ts +0 -1
  38. package/lib/encodingStrategies/sszSnappy/index.d.ts.map +1 -1
  39. package/lib/encodingStrategies/sszSnappy/index.js +0 -1
  40. package/lib/encodingStrategies/sszSnappy/index.js.map +1 -1
  41. package/lib/metrics.d.ts +1 -7
  42. package/lib/metrics.d.ts.map +1 -1
  43. package/lib/metrics.js +1 -17
  44. package/lib/metrics.js.map +1 -1
  45. package/lib/request/errors.d.ts +1 -7
  46. package/lib/request/errors.d.ts.map +1 -1
  47. package/lib/request/errors.js +1 -5
  48. package/lib/request/errors.js.map +1 -1
  49. package/lib/request/index.d.ts +0 -3
  50. package/lib/request/index.d.ts.map +1 -1
  51. package/lib/request/index.js +58 -70
  52. package/lib/request/index.js.map +1 -1
  53. package/lib/response/index.d.ts +1 -1
  54. package/lib/response/index.d.ts.map +1 -1
  55. package/lib/response/index.js +46 -50
  56. package/lib/response/index.js.map +1 -1
  57. package/lib/types.d.ts +1 -2
  58. package/lib/types.d.ts.map +1 -1
  59. package/lib/types.js +1 -2
  60. package/lib/types.js.map +1 -1
  61. package/lib/utils/collectMaxResponse.d.ts.map +1 -1
  62. package/lib/utils/collectMaxResponse.js +1 -2
  63. package/lib/utils/collectMaxResponse.js.map +1 -1
  64. package/lib/utils/errorMessage.d.ts +3 -3
  65. package/lib/utils/errorMessage.d.ts.map +1 -1
  66. package/lib/utils/errorMessage.js +14 -13
  67. package/lib/utils/errorMessage.js.map +1 -1
  68. package/lib/utils/index.d.ts +1 -3
  69. package/lib/utils/index.d.ts.map +1 -1
  70. package/lib/utils/index.js +1 -3
  71. package/lib/utils/index.js.map +1 -1
  72. package/lib/utils/protocolId.d.ts +2 -2
  73. package/lib/utils/protocolId.js +2 -2
  74. package/lib/utils/snappyCompress.d.ts +1 -1
  75. package/lib/utils/snappyCompress.d.ts.map +1 -1
  76. package/lib/utils/snappyCompress.js +1 -1
  77. package/lib/utils/snappyCompress.js.map +1 -1
  78. package/lib/utils/snappyIndex.d.ts +1 -1
  79. package/lib/utils/snappyIndex.d.ts.map +1 -1
  80. package/lib/utils/snappyIndex.js +1 -1
  81. package/lib/utils/snappyIndex.js.map +1 -1
  82. package/lib/utils/snappyUncompress.d.ts +7 -11
  83. package/lib/utils/snappyUncompress.d.ts.map +1 -1
  84. package/lib/utils/snappyUncompress.js +68 -68
  85. package/lib/utils/snappyUncompress.js.map +1 -1
  86. package/lib/utils/stream.d.ts +6 -0
  87. package/lib/utils/stream.d.ts.map +1 -0
  88. package/lib/utils/stream.js +21 -0
  89. package/lib/utils/stream.js.map +1 -0
  90. package/package.json +14 -16
  91. package/src/ReqResp.ts +4 -4
  92. package/src/encoders/requestDecode.ts +32 -16
  93. package/src/encoders/requestEncode.ts +1 -1
  94. package/src/encoders/responseDecode.ts +68 -72
  95. package/src/encoders/responseEncode.ts +17 -29
  96. package/src/encodingStrategies/index.ts +8 -6
  97. package/src/encodingStrategies/sszSnappy/decode.ts +111 -53
  98. package/src/encodingStrategies/sszSnappy/encode.ts +2 -2
  99. package/src/encodingStrategies/sszSnappy/errors.ts +0 -4
  100. package/src/encodingStrategies/sszSnappy/index.ts +0 -1
  101. package/src/metrics.ts +1 -17
  102. package/src/request/errors.ts +1 -6
  103. package/src/request/index.ts +74 -86
  104. package/src/response/index.ts +55 -61
  105. package/src/types.ts +1 -3
  106. package/src/utils/collectMaxResponse.ts +1 -2
  107. package/src/utils/errorMessage.ts +14 -13
  108. package/src/utils/index.ts +1 -3
  109. package/src/utils/protocolId.ts +2 -2
  110. package/src/utils/snappyCompress.ts +1 -1
  111. package/src/utils/snappyIndex.ts +1 -1
  112. package/src/utils/snappyUncompress.ts +73 -75
  113. package/src/utils/stream.ts +34 -0
  114. package/lib/utils/abortableSource.d.ts +0 -12
  115. package/lib/utils/abortableSource.d.ts.map +0 -1
  116. package/lib/utils/abortableSource.js +0 -69
  117. package/lib/utils/abortableSource.js.map +0 -1
  118. package/lib/utils/bufferedSource.d.ts +0 -16
  119. package/lib/utils/bufferedSource.d.ts.map +0 -1
  120. package/lib/utils/bufferedSource.js +0 -40
  121. package/lib/utils/bufferedSource.js.map +0 -1
  122. package/lib/utils/onChunk.d.ts +0 -6
  123. package/lib/utils/onChunk.d.ts.map +0 -1
  124. package/lib/utils/onChunk.js +0 -13
  125. package/lib/utils/onChunk.js.map +0 -1
  126. package/lib/utils/snappy.d.ts +0 -3
  127. package/lib/utils/snappy.d.ts.map +0 -1
  128. package/lib/utils/snappy.js +0 -3
  129. package/lib/utils/snappy.js.map +0 -1
  130. package/src/utils/abortableSource.ts +0 -80
  131. package/src/utils/bufferedSource.ts +0 -46
  132. package/src/utils/onChunk.ts +0 -12
  133. package/src/utils/snappy.ts +0 -2
@@ -2,96 +2,94 @@ import {uncompress} from "snappyjs";
2
2
  import {Uint8ArrayList} from "uint8arraylist";
3
3
  import {ChunkType, IDENTIFIER, UNCOMPRESSED_CHUNK_SIZE, crc} from "./snappyCommon.js";
4
4
 
5
- export class SnappyFramesUncompress {
6
- private buffer = new Uint8ArrayList();
7
-
8
- private state: UncompressState = {
9
- foundIdentifier: false,
10
- };
11
-
12
- /**
13
- * Accepts chunk of data containing some part of snappy frames stream
14
- * @param chunk
15
- * @return Buffer if there is one or more whole frames, null if it's partial
16
- */
17
- uncompress(chunk: Uint8ArrayList): Uint8ArrayList | null {
18
- this.buffer.append(chunk);
19
- const result = new Uint8ArrayList();
20
- while (this.buffer.length > 0) {
21
- if (this.buffer.length < 4) break;
5
+ export function parseSnappyFrameHeader(header: Uint8Array): {type: ChunkType; frameSize: number} {
6
+ if (header.length !== 4) {
7
+ throw new Error("malformed input: incomplete frame header");
8
+ }
22
9
 
23
- const type = getChunkType(this.buffer.get(0));
10
+ const type = getChunkType(header[0]);
11
+ const frameSize = header[1] + (header[2] << 8) + (header[3] << 16);
12
+ return {type, frameSize};
13
+ }
24
14
 
25
- if (!this.state.foundIdentifier && type !== ChunkType.IDENTIFIER) {
26
- throw "malformed input: must begin with an identifier";
15
+ export function decodeSnappyFrameData(type: ChunkType, frame: Uint8Array): Uint8Array | null {
16
+ switch (type) {
17
+ case ChunkType.IDENTIFIER: {
18
+ if (!Buffer.prototype.equals.call(frame, IDENTIFIER)) {
19
+ throw new Error("malformed input: bad identifier");
20
+ }
21
+ return null;
22
+ }
23
+ case ChunkType.PADDING:
24
+ case ChunkType.SKIPPABLE:
25
+ return null;
26
+ case ChunkType.COMPRESSED: {
27
+ if (frame.length < 4) {
28
+ throw new Error("malformed input: too short");
27
29
  }
28
30
 
29
- const frameSize = getFrameSize(this.buffer, 1);
31
+ const checksum = frame.subarray(0, 4);
32
+ const data = frame.subarray(4);
33
+ const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
34
+ if (crc(uncompressed).compare(checksum) !== 0) {
35
+ throw new Error("malformed input: bad checksum");
36
+ }
37
+ return uncompressed;
38
+ }
39
+ case ChunkType.UNCOMPRESSED: {
40
+ if (frame.length < 4) {
41
+ throw new Error("malformed input: too short");
42
+ }
30
43
 
31
- if (this.buffer.length - 4 < frameSize) {
32
- break;
44
+ const checksum = frame.subarray(0, 4);
45
+ const uncompressed = frame.subarray(4);
46
+ if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
47
+ throw new Error("malformed input: too large");
48
+ }
49
+ if (crc(uncompressed).compare(checksum) !== 0) {
50
+ throw new Error("malformed input: bad checksum");
33
51
  }
52
+ return uncompressed;
53
+ }
54
+ }
55
+ }
34
56
 
35
- const frame = this.buffer.subarray(4, 4 + frameSize);
36
- this.buffer.consume(4 + frameSize);
57
+ export function decodeSnappyFrames(data: Uint8Array): Uint8ArrayList {
58
+ const out = new Uint8ArrayList();
59
+ let foundIdentifier = false;
60
+ let offset = 0;
37
61
 
38
- switch (type) {
39
- case ChunkType.IDENTIFIER: {
40
- if (!Buffer.prototype.equals.call(frame, IDENTIFIER)) {
41
- throw "malformed input: bad identifier";
42
- }
43
- this.state.foundIdentifier = true;
44
- continue;
45
- }
46
- case ChunkType.PADDING:
47
- case ChunkType.SKIPPABLE:
48
- continue;
49
- case ChunkType.COMPRESSED: {
50
- const checksum = frame.subarray(0, 4);
51
- const data = frame.subarray(4);
62
+ while (offset < data.length) {
63
+ const remaining = data.length - offset;
64
+ if (remaining < 4) {
65
+ throw new Error("malformed input: incomplete frame header");
66
+ }
52
67
 
53
- const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
54
- if (crc(uncompressed).compare(checksum) !== 0) {
55
- throw "malformed input: bad checksum";
56
- }
57
- result.append(uncompressed);
58
- break;
59
- }
60
- case ChunkType.UNCOMPRESSED: {
61
- const checksum = frame.subarray(0, 4);
62
- const uncompressed = frame.subarray(4);
68
+ const {type, frameSize} = parseSnappyFrameHeader(data.subarray(offset, offset + 4));
69
+ if (!foundIdentifier && type !== ChunkType.IDENTIFIER) {
70
+ throw new Error("malformed input: must begin with an identifier");
71
+ }
63
72
 
64
- if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
65
- throw "malformed input: too large";
66
- }
67
- if (crc(uncompressed).compare(checksum) !== 0) {
68
- throw "malformed input: bad checksum";
69
- }
70
- result.append(uncompressed);
71
- break;
72
- }
73
- }
73
+ offset += 4;
74
+
75
+ if (data.length - offset < frameSize) {
76
+ throw new Error("malformed input: incomplete frame");
74
77
  }
75
- if (result.length === 0) {
76
- return null;
78
+
79
+ const frame = data.subarray(offset, offset + frameSize);
80
+ offset += frameSize;
81
+
82
+ if (type === ChunkType.IDENTIFIER) {
83
+ foundIdentifier = true;
77
84
  }
78
- return result;
79
- }
80
85
 
81
- reset(): void {
82
- this.buffer = new Uint8ArrayList();
83
- this.state = {
84
- foundIdentifier: false,
85
- };
86
+ const uncompressed = decodeSnappyFrameData(type, frame);
87
+ if (uncompressed !== null) {
88
+ out.append(uncompressed);
89
+ }
86
90
  }
87
- }
88
-
89
- type UncompressState = {
90
- foundIdentifier: boolean;
91
- };
92
91
 
93
- function getFrameSize(buffer: Uint8ArrayList, offset: number): number {
94
- return buffer.get(offset) + (buffer.get(offset + 1) << 8) + (buffer.get(offset + 2) << 16);
92
+ return out;
95
93
  }
96
94
 
97
95
  function getChunkType(value: number): ChunkType {
@@ -0,0 +1,34 @@
1
+ import type {Stream} from "@libp2p/interface";
2
+ import {ByteStream} from "@libp2p/utils";
3
+ import {Uint8ArrayList} from "uint8arraylist";
4
+ import {ErrorAborted} from "@lodestar/utils";
5
+
6
+ export async function sendChunks(
7
+ stream: Stream,
8
+ source: Iterable<Uint8Array | Uint8ArrayList> | AsyncIterable<Uint8Array | Uint8ArrayList>,
9
+ signal?: AbortSignal
10
+ ): Promise<void> {
11
+ for await (const chunk of source) {
12
+ if (signal?.aborted) {
13
+ throw new ErrorAborted("sendChunks");
14
+ }
15
+
16
+ if (!stream.send(chunk)) {
17
+ await stream.onDrain({signal});
18
+ }
19
+ }
20
+ }
21
+
22
+ export function drainByteStream(bytes: ByteStream<Stream>): Uint8Array | undefined {
23
+ const readBuffer = (
24
+ bytes as unknown as {
25
+ readBuffer?: {byteLength: number; subarray: () => Uint8Array; consume: (bytes: number) => void};
26
+ }
27
+ ).readBuffer;
28
+ if (readBuffer && readBuffer.byteLength > 0) {
29
+ const drained = readBuffer.subarray();
30
+ readBuffer.consume(readBuffer.byteLength);
31
+ return drained;
32
+ }
33
+ return undefined;
34
+ }
@@ -1,12 +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 declare function abortableSource<T>(sourceArg: AsyncIterable<T>, signals: {
9
- signal: AbortSignal;
10
- getError: () => Error;
11
- }[]): AsyncIterable<T>;
12
- //# sourceMappingURL=abortableSource.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abortableSource.d.ts","sourceRoot":"","sources":["../../src/utils/abortableSource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE;IACP,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,KAAK,CAAC;CACvB,EAAE,GACF,aAAa,CAAC,CAAC,CAAC,CAkElB"}
@@ -1,69 +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(sourceArg, signals) {
9
- const source = sourceArg;
10
- async function* abortable() {
11
- // Handler that will hold a reference to the `abort()` promise,
12
- // necessary for the signal abort listeners to reject the iterable promise
13
- let nextAbortHandler = null;
14
- // For each signal register an abortHandler(), and prepare clean-up with `onDoneCbs`
15
- const onDoneCbs = [];
16
- for (const { signal, getError } of signals) {
17
- const abortHandler = () => {
18
- if (nextAbortHandler)
19
- nextAbortHandler(getError());
20
- };
21
- signal.addEventListener("abort", abortHandler);
22
- onDoneCbs.push(() => {
23
- signal.removeEventListener("abort", abortHandler);
24
- });
25
- }
26
- try {
27
- while (true) {
28
- // Abort early if any signal is aborted
29
- for (const { signal, getError } of signals) {
30
- if (signal.aborted) {
31
- throw getError();
32
- }
33
- }
34
- // Race the iterator and the abort signals
35
- const result = await Promise.race([
36
- new Promise((_, reject) => {
37
- nextAbortHandler = (error) => reject(error);
38
- }),
39
- source.next(),
40
- ]);
41
- // source.next() resolved first
42
- nextAbortHandler = null;
43
- if (result.done) {
44
- return;
45
- }
46
- yield result.value;
47
- }
48
- }
49
- catch (err) {
50
- // End the iterator if it is a generator
51
- if (typeof source.return === "function") {
52
- // This source.return() function may never resolve depending on the source AsyncGenerator implementation.
53
- // This is the main reason to fork "abortable-iterator", which caused our node to get stuck during Sync.
54
- // We choose to call .return() but not await it. In general, source.return should never throw. If it does,
55
- // it a problem of the source implementor, and thus logged as an unhandled rejection. If that happens,
56
- // the source implementor should fix the upstream code.
57
- void source.return(null);
58
- }
59
- throw err;
60
- }
61
- finally {
62
- for (const cb of onDoneCbs) {
63
- cb();
64
- }
65
- }
66
- }
67
- return abortable();
68
- }
69
- //# sourceMappingURL=abortableSource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abortableSource.js","sourceRoot":"","sources":["../../src/utils/abortableSource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA2B,EAC3B,OAGG;IAEH,MAAM,MAAM,GAAG,SAA8B,CAAC;IAE9C,KAAK,SAAS,CAAC,CAAC,SAAS;QACvB,+DAA+D;QAC/D,0EAA0E;QAC1E,IAAI,gBAAgB,GAAoC,IAAI,CAAC;QAE7D,oFAAoF;QACpF,MAAM,SAAS,GAAmB,EAAE,CAAC;QACrC,KAAK,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,IAAI,OAAO,EAAE,CAAC;YACzC,MAAM,YAAY,GAAG,GAAS,EAAE;gBAC9B,IAAI,gBAAgB;oBAAE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC;YACrD,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAC/C,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE;gBAClB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACpD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;gBACZ,uCAAuC;gBACvC,KAAK,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,IAAI,OAAO,EAAE,CAAC;oBACzC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;wBACnB,MAAM,QAAQ,EAAE,CAAC;oBACnB,CAAC;gBACH,CAAC;gBAED,0CAA0C;gBAC1C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;oBAChC,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;wBAC/B,gBAAgB,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC9C,CAAC,CAAC;oBACF,MAAM,CAAC,IAAI,EAAE;iBACd,CAAC,CAAC;gBAEH,+BAA+B;gBAC/B,gBAAgB,GAAG,IAAI,CAAC;gBAExB,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;oBAChB,OAAO;gBACT,CAAC;gBAED,MAAM,MAAM,CAAC,KAAK,CAAC;YACrB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,wCAAwC;YACxC,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBACxC,yGAAyG;gBACzG,wGAAwG;gBACxG,0GAA0G;gBAC1G,sGAAsG;gBACtG,uDAAuD;gBACvD,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;YAED,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC3B,EAAE,EAAE,CAAC;YACP,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,EAAE,CAAC;AACrB,CAAC"}
@@ -1,16 +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 declare class BufferedSource {
10
- isDone: boolean;
11
- private buffer;
12
- private source;
13
- constructor(source: AsyncGenerator<Uint8ArrayList | Uint8Array>);
14
- [Symbol.asyncIterator](): AsyncIterator<Uint8ArrayList>;
15
- }
16
- //# sourceMappingURL=bufferedSource.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bufferedSource.d.ts","sourceRoot":"","sources":["../../src/utils/bufferedSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,MAAM,UAAS;IACf,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,MAAM,CAA8C;gBAEhD,MAAM,EAAE,cAAc,CAAC,cAAc,GAAG,UAAU,CAAC;IAK/D,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,cAAc,CAAC;CA0BxD"}
@@ -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";