event-storage 1.3.3 → 1.3.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "event-storage",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "type": "module",
5
5
  "description": "An optimized embedded event store for node.js",
6
6
  "keywords": [
@@ -193,15 +193,15 @@ class EventStream extends stream.Readable {
193
193
  * @returns {Array<object>}
194
194
  */
195
195
  get events() {
196
- if (this._events instanceof Array) {
197
- return this._events;
196
+ if (this.cachedEvents instanceof Array) {
197
+ return this.cachedEvents;
198
198
  }
199
- this._events = [];
199
+ this.cachedEvents = [];
200
200
  let next;
201
201
  while ((next = this.next()) !== false) {
202
- this._events.push(next.payload);
202
+ this.cachedEvents.push(next.payload);
203
203
  }
204
- return this._events;
204
+ return this.cachedEvents;
205
205
  }
206
206
 
207
207
  /**
@@ -242,7 +242,7 @@ class EventStream extends stream.Readable {
242
242
  */
243
243
  reset() {
244
244
  this._iterator = null;
245
- this._events = null;
245
+ this.cachedEvents = null;
246
246
  return this;
247
247
  }
248
248
 
@@ -259,7 +259,7 @@ class EventStream extends stream.Readable {
259
259
  this.predicate = predicate || null;
260
260
  this.rawMatcher = null;
261
261
  this._iterator = null;
262
- this._events = null;
262
+ this.cachedEvents = null;
263
263
  return this;
264
264
  }
265
265
 
@@ -34,9 +34,14 @@ class JoinEventStream extends EventStream {
34
34
  if (!streamIndex || streamIndex.length === 0) {
35
35
  return emptyIterator;
36
36
  }
37
- const from = streamIndex.find(this.minRevision, this.minRevision <= this.maxRevision);
38
- const until = streamIndex.find(this.maxRevision, this.minRevision > this.maxRevision);
39
- if (from === 0 || until === 0) {
37
+ const ascending = this.minRevision <= this.maxRevision;
38
+ const from = streamIndex.find(this.minRevision, ascending);
39
+ const until = streamIndex.find(this.maxRevision, !ascending);
40
+ if (
41
+ from === 0 ||
42
+ until === 0 ||
43
+ (ascending ? from > until : from < until)
44
+ ) {
40
45
  // find() returns 0 when the requested revision is outside the stream's range
41
46
  // (e.g. minRevision > all entries, or maxRevision < all entries).
42
47
  return emptyIterator;