pg_eventstore 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cac54fc5042fe312145da5a4e73cb211f375544fe9e19e7923408848efd0ecb
4
- data.tar.gz: 4427be145c2b9bbee701e6c1dc12ac6fcb0ee7db2dfabbb0002524fe7f16a8f9
3
+ metadata.gz: 66aeaf1c1365b962133efe784a507722fe0be9c80cb1911edd76512cb7a1af17
4
+ data.tar.gz: 34ebc698b212e0631f005f754bbcf808f95796c149f969a1466ede8c7842e362
5
5
  SHA512:
6
- metadata.gz: 2bf613831f93b498971b24a7192c10c9c22042bc6ca6f00f2c8ca8369f681d8f23e9069eff8b410c25062ff45447e32e18e4f83a8f100db7df314bbad2b707c4
7
- data.tar.gz: f6d3296d2f2ea746d6bb204041aebe1bb7cc0b1b06b5ff865d27fad6610ae2694d4f438960042408ac8f49efbc42c6e158640d513fb8e3a3f95ba397d2bf2772
6
+ metadata.gz: ad3c0661aa7c995c357588cbbaa4c9958868068ec452284250f41e0c2e3ae98eabdae837e7c00e63e59f22df7c5920aef2ad1497340d99dcc5bdc8e3e98ffb1f
7
+ data.tar.gz: 395e5697dad7945e3c5bc2b51956195097aca503e9e20445b0d3b857fcdb17e4074ec392dc8fdf8a840e132e7f353093985e715a521ef7c73db5b902e0bcbffb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.3.4]
4
+ - Fix `NoMethodError` error in `Client#read_paginated` when stream does not exist or when there are no events matching the given filter
5
+
3
6
  ## [1.3.3]
4
7
  - Adjust default value of `subscription_max_retries` setting
5
8
 
@@ -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
- events = read_cmd.call(stream, options: options.merge(from_revision: revision))
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
- raise StopIteration if end_reached?(events, options[:max_count])
15
+ if end_reached?(events, options[:max_count] || QueryBuilders::EventsFiltering::DEFAULT_LIMIT)
16
+ raise StopIteration
17
+ end
15
18
 
16
- revision = calc_next_revision(events, revision, options[:direction])
17
- raise StopIteration if revision.negative?
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, revision, direction)
46
- return revision + events.size if forwards?(direction)
37
+ def calc_next_revision(events, direction)
38
+ return events.last.stream_revision + 1 if forwards?(direction)
47
39
 
48
- revision - events.size
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
- events = read_cmd.call(stream, options: options.merge(from_position: position))
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
- raise StopIteration if end_reached?(events, options[:max_count])
15
+ if end_reached?(events, options[:max_count] || QueryBuilders::EventsFiltering::DEFAULT_LIMIT)
16
+ raise StopIteration
17
+ end
15
18
 
16
- position = calc_next_position(events, options[:direction])
17
- raise StopIteration if position <= 0
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]
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PgEventstore
4
4
  # @return [String]
5
- VERSION = "1.3.3"
5
+ VERSION = "1.3.4"
6
6
  end
@@ -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, Integer revision, (String | Symbol)? direction) -> Integer
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.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-24 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg