From 4ddb2549b1c0a74b46db5c2546509aa1d9ca09ae Mon Sep 17 00:00:00 2001 From: Joris <31551856+CSDUMMI@users.noreply.github.com> Date: Fri, 30 Apr 2021 18:46:43 +0200 Subject: [PATCH 1/4] Return all entries by default for iterator --- src/EventStore.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/EventStore.js b/src/EventStore.js index 8bd003d..c988431 100644 --- a/src/EventStore.js +++ b/src/EventStore.js @@ -26,6 +26,7 @@ class EventStore extends Store { get (hash) { return this.iterator({ gte: hash, limit: 1 }).collect()[0] } + iterator (options) { const messages = this._query(options) let currentIndex = 0 @@ -50,7 +51,8 @@ class EventStore extends Store { _query (opts) { if (!opts) opts = {} - const amount = opts.limit ? (opts.limit > -1 ? opts.limit : this._index.get().length) : 1 // Return 1 if no limit is provided + let amount + const amount = !opts.limit || opts.limit == -1 ? this._index.get().length : opts.limit; // Return all by default. const events = this._index.get().slice() let result = [] From c43f56515857058cec23e60e8fc8b5ddab9359f2 Mon Sep 17 00:00:00 2001 From: Joris <31551856+CSDUMMI@users.noreply.github.com> Date: Sat, 1 May 2021 08:23:14 +0200 Subject: [PATCH 2/4] Update EventStore.js --- src/EventStore.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/EventStore.js b/src/EventStore.js index c988431..8f20e46 100644 --- a/src/EventStore.js +++ b/src/EventStore.js @@ -51,7 +51,6 @@ class EventStore extends Store { _query (opts) { if (!opts) opts = {} - let amount const amount = !opts.limit || opts.limit == -1 ? this._index.get().length : opts.limit; // Return all by default. const events = this._index.get().slice() let result = [] From b64e7fa029fc5967aac1a2202d1d5b1d97d65522 Mon Sep 17 00:00:00 2001 From: Joris <31551856+CSDUMMI@users.noreply.github.com> Date: Wed, 19 May 2021 16:12:09 +0200 Subject: [PATCH 3/4] Wrapping amount with Math.abs To handle negative limit values. --- src/EventStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventStore.js b/src/EventStore.js index 8f20e46..ca6ed9f 100644 --- a/src/EventStore.js +++ b/src/EventStore.js @@ -51,7 +51,7 @@ class EventStore extends Store { _query (opts) { if (!opts) opts = {} - const amount = !opts.limit || opts.limit == -1 ? this._index.get().length : opts.limit; // Return all by default. + const amount = !opts.limit || opts.limit == -1 ? this._index.get().length : Math.abs(opts.limit); // Return all by default. const events = this._index.get().slice() let result = [] From 552365d4306c1391b5b5a71be62f18681abe0dc4 Mon Sep 17 00:00:00 2001 From: Joris <31551856+CSDUMMI@users.noreply.github.com> Date: Wed, 19 May 2021 17:48:01 +0200 Subject: [PATCH 4/4] Allow negative values for amount By setting the default = 0 and returning all on the default. --- src/EventStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventStore.js b/src/EventStore.js index ca6ed9f..c70f872 100644 --- a/src/EventStore.js +++ b/src/EventStore.js @@ -51,7 +51,7 @@ class EventStore extends Store { _query (opts) { if (!opts) opts = {} - const amount = !opts.limit || opts.limit == -1 ? this._index.get().length : Math.abs(opts.limit); // Return all by default. + const amount = !opts.limit || opts.limit == 0 ? this._index.get().length : opts.limit; // Return all by default. const events = this._index.get().slice() let result = []