event-storage 1.3.4 → 1.3.5
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.
- package/package.json +1 -1
- package/src/JoinEventStream.js +19 -1
package/package.json
CHANGED
package/src/JoinEventStream.js
CHANGED
|
@@ -5,6 +5,23 @@ import { normalizeRevision } from './utils/apiHelpers.js';
|
|
|
5
5
|
/** Reusable sentinel used for missing or empty per-stream iterators. */
|
|
6
6
|
const emptyIterator = Object.freeze({ next() { return { done: true }; } });
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* In raw mode `storage.readFrom` returns a `buffer` that is a transient view into a shared read/write
|
|
10
|
+
* buffer, only valid until the next read on that partition. The k-way merge holds the head of every
|
|
11
|
+
* per-stream iterator at once, so advancing one stream would otherwise clobber another stream's pending
|
|
12
|
+
* head when they read from the same partition. Copy each raw buffer into its own memory as it is produced
|
|
13
|
+
* so every held head stays valid across reads.
|
|
14
|
+
*
|
|
15
|
+
* @param {Iterator<{ buffer: Buffer }>} iterator
|
|
16
|
+
* @returns {Generator<{ buffer: Buffer }>}
|
|
17
|
+
*/
|
|
18
|
+
function* detachRawBuffers(iterator) {
|
|
19
|
+
for (const entry of iterator) {
|
|
20
|
+
entry.buffer = Buffer.from(entry.buffer);
|
|
21
|
+
yield entry;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
/**
|
|
9
26
|
* An event stream is a simple wrapper around an iterator over storage documents.
|
|
10
27
|
* It implements a node readable stream interface.
|
|
@@ -48,7 +65,8 @@ class JoinEventStream extends EventStream {
|
|
|
48
65
|
}
|
|
49
66
|
// Raw mode: get { buffer, time64, sequenceNumber } for binary-header ordering.
|
|
50
67
|
// Object mode: storage deserializes for us and we order by metadata.commitId.
|
|
51
|
-
|
|
68
|
+
const range = eventStore.storage.readRange(from, until, streamIndex, this.raw);
|
|
69
|
+
return this.raw ? detachRawBuffers(range) : range;
|
|
52
70
|
});
|
|
53
71
|
}
|
|
54
72
|
this._iterator = null;
|