pg_eventstore 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/pg_eventstore/commands/regular_stream_read_paginated.rb +11 -19
- data/lib/pg_eventstore/commands/system_stream_read_paginated.rb +8 -15
- data/lib/pg_eventstore/version.rb +1 -1
- data/sig/pg_eventstore/commands/regular_stream_read_paginated.rbs +1 -6
- data/sig/pg_eventstore/commands/system_stream_read_paginated.rbs +0 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66aeaf1c1365b962133efe784a507722fe0be9c80cb1911edd76512cb7a1af17
|
4
|
+
data.tar.gz: 34ebc698b212e0631f005f754bbcf808f95796c149f969a1466ede8c7842e362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad3c0661aa7c995c357588cbbaa4c9958868068ec452284250f41e0c2e3ae98eabdae837e7c00e63e59f22df7c5920aef2ad1497340d99dcc5bdc8e3e98ffb1f
|
7
|
+
data.tar.gz: 395e5697dad7945e3c5bc2b51956195097aca503e9e20445b0d3b857fcdb17e4074ec392dc8fdf8a840e132e7f353093985e715a521ef7c73db5b902e0bcbffb
|
data/CHANGELOG.md
CHANGED
@@ -6,31 +6,24 @@ module PgEventstore
|
|
6
6
|
class RegularStreamReadPaginated < AbstractCommand
|
7
7
|
# @see PgEventstore::Commands::Read for docs
|
8
8
|
def call(stream, options: {})
|
9
|
-
revision = calc_initial_revision(stream, options)
|
10
9
|
Enumerator.new do |yielder|
|
10
|
+
next_revision = nil
|
11
11
|
loop do
|
12
|
-
|
12
|
+
options = options.merge(from_revision: next_revision) if next_revision
|
13
|
+
events = read_cmd.call(stream, options: options)
|
13
14
|
yielder << events if events.any?
|
14
|
-
|
15
|
+
if end_reached?(events, options[:max_count] || QueryBuilders::EventsFiltering::DEFAULT_LIMIT)
|
16
|
+
raise StopIteration
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
raise StopIteration if
|
19
|
+
next_revision = calc_next_revision(events, options[:direction])
|
20
|
+
raise StopIteration if next_revision.negative?
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
|
-
# @param stream [PgEventstore::Stream]
|
25
|
-
# @param options [Hash]
|
26
|
-
# @return [Integer]
|
27
|
-
def calc_initial_revision(stream, options)
|
28
|
-
return options[:from_revision] if options[:from_revision]
|
29
|
-
return 0 if forwards?(options[:direction])
|
30
|
-
|
31
|
-
read_cmd.call(stream, options: options.merge(max_count: 1)).first.stream_revision
|
32
|
-
end
|
33
|
-
|
34
27
|
# @param events [Array<PgEventstore::Event>]
|
35
28
|
# @param max_count [Integer]
|
36
29
|
# @return [Boolean]
|
@@ -39,13 +32,12 @@ module PgEventstore
|
|
39
32
|
end
|
40
33
|
|
41
34
|
# @param events [Array<PgEventstore::Event>]
|
42
|
-
# @param revision [Integer]
|
43
35
|
# @param direction [String, Symbol, nil]
|
44
36
|
# @return [Integer]
|
45
|
-
def calc_next_revision(events,
|
46
|
-
return
|
37
|
+
def calc_next_revision(events, direction)
|
38
|
+
return events.last.stream_revision + 1 if forwards?(direction)
|
47
39
|
|
48
|
-
|
40
|
+
events.last.stream_revision - 1
|
49
41
|
end
|
50
42
|
|
51
43
|
# @param direction [String, Symbol, nil]
|
@@ -6,31 +6,24 @@ module PgEventstore
|
|
6
6
|
class SystemStreamReadPaginated < AbstractCommand
|
7
7
|
# @see PgEventstore::Commands::Read for docs
|
8
8
|
def call(stream, options: {})
|
9
|
-
position = calc_initial_position(stream, options)
|
10
9
|
Enumerator.new do |yielder|
|
10
|
+
next_position = nil
|
11
11
|
loop do
|
12
|
-
|
12
|
+
options = options.merge(from_position: next_position) if next_position
|
13
|
+
events = read_cmd.call(stream, options: options)
|
13
14
|
yielder << events if events.any?
|
14
|
-
|
15
|
+
if end_reached?(events, options[:max_count] || QueryBuilders::EventsFiltering::DEFAULT_LIMIT)
|
16
|
+
raise StopIteration
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
raise StopIteration if
|
19
|
+
next_position = calc_next_position(events, options[:direction])
|
20
|
+
raise StopIteration if next_position <= 0
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
|
-
# @param stream [PgEventstore::Stream]
|
25
|
-
# @param options [Hash]
|
26
|
-
# @return [Integer]
|
27
|
-
def calc_initial_position(stream, options)
|
28
|
-
return options[:from_position] if options[:from_position]
|
29
|
-
return 1 if forwards?(options[:direction])
|
30
|
-
|
31
|
-
read_cmd.call(stream, options: options.merge(max_count: 1)).first.global_position
|
32
|
-
end
|
33
|
-
|
34
27
|
# @param events [Array<PgEventstore::Event>]
|
35
28
|
# @param max_count [Integer]
|
36
29
|
# @return [Boolean]
|
@@ -6,11 +6,6 @@ module PgEventstore
|
|
6
6
|
# _@param_ `options`
|
7
7
|
%a{rbs:test:skip} def call: (PgEventstore::Stream stream, ?options: ::Hash[untyped, untyped]) -> ::Enumerator[Array[PgEventstore::Event], void]
|
8
8
|
|
9
|
-
# _@param_ `stream`
|
10
|
-
#
|
11
|
-
# _@param_ `options`
|
12
|
-
def calc_initial_revision: (PgEventstore::Stream stream, ::Hash[untyped, untyped] options) -> Integer
|
13
|
-
|
14
9
|
# _@param_ `events`
|
15
10
|
#
|
16
11
|
# _@param_ `max_count`
|
@@ -21,7 +16,7 @@ module PgEventstore
|
|
21
16
|
# _@param_ `revision`
|
22
17
|
#
|
23
18
|
# _@param_ `direction`
|
24
|
-
def calc_next_revision: (::Array[PgEventstore::Event] events,
|
19
|
+
def calc_next_revision: (::Array[PgEventstore::Event] events, (String | Symbol)? direction) -> Integer
|
25
20
|
|
26
21
|
# _@param_ `direction`
|
27
22
|
def forwards?: ((String | Symbol)? direction) -> bool
|
@@ -6,11 +6,6 @@ module PgEventstore
|
|
6
6
|
# _@param_ `options`
|
7
7
|
%a{rbs:test:skip} def call: (PgEventstore::Stream stream, ?options: ::Hash[untyped, untyped]) -> ::Enumerator[Array[PgEventstore::Event], void]
|
8
8
|
|
9
|
-
# _@param_ `stream`
|
10
|
-
#
|
11
|
-
# _@param_ `options`
|
12
|
-
def calc_initial_position: (PgEventstore::Stream stream, ::Hash[untyped, untyped] options) -> Integer
|
13
|
-
|
14
9
|
# _@param_ `events`
|
15
10
|
#
|
16
11
|
# _@param_ `max_count`
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_eventstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Dzyzenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|