ruby_event_store 2.16.0 → 2.17.0

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_event_store/broker.rb +11 -7
  3. data/lib/ruby_event_store/client.rb +60 -20
  4. data/lib/ruby_event_store/composed_broker.rb +65 -0
  5. data/lib/ruby_event_store/errors.rb +1 -0
  6. data/lib/ruby_event_store/in_memory_repository.rb +27 -27
  7. data/lib/ruby_event_store/instrumented_broker.rb +73 -0
  8. data/lib/ruby_event_store/instrumented_subscriptions.rb +3 -11
  9. data/lib/ruby_event_store/mappers/batch_mapper.rb +19 -0
  10. data/lib/ruby_event_store/mappers/default.rb +2 -2
  11. data/lib/ruby_event_store/mappers/encryption_key.rb +8 -1
  12. data/lib/ruby_event_store/mappers/encryption_mapper.rb +2 -2
  13. data/lib/ruby_event_store/mappers/instrumented_batch_mapper.rb +28 -0
  14. data/lib/ruby_event_store/mappers/transformation/domain_event.rb +8 -10
  15. data/lib/ruby_event_store/mappers/transformation/encryption.rb +2 -3
  16. data/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb +1 -1
  17. data/lib/ruby_event_store/mappers/transformation/preserve_types.rb +11 -19
  18. data/lib/ruby_event_store/mappers/transformation/stringify_metadata_keys.rb +1 -1
  19. data/lib/ruby_event_store/mappers/transformation/symbolize_metadata_keys.rb +1 -1
  20. data/lib/ruby_event_store/record.rb +9 -10
  21. data/lib/ruby_event_store/serialized_record.rb +2 -2
  22. data/lib/ruby_event_store/spec/broker_lint.rb +27 -10
  23. data/lib/ruby_event_store/spec/dispatcher_lint.rb +1 -1
  24. data/lib/ruby_event_store/spec/event_lint.rb +3 -3
  25. data/lib/ruby_event_store/spec/event_repository_lint.rb +228 -189
  26. data/lib/ruby_event_store/spec/mapper_lint.rb +2 -2
  27. data/lib/ruby_event_store/spec/scheduler_lint.rb +1 -1
  28. data/lib/ruby_event_store/spec/subscriptions_lint.rb +21 -20
  29. data/lib/ruby_event_store/specification.rb +5 -5
  30. data/lib/ruby_event_store/specification_reader.rb +6 -2
  31. data/lib/ruby_event_store/specification_result.rb +32 -34
  32. data/lib/ruby_event_store/subscriptions.rb +20 -20
  33. data/lib/ruby_event_store/transform_keys.rb +1 -3
  34. data/lib/ruby_event_store/version.rb +1 -1
  35. data/lib/ruby_event_store.rb +5 -1
  36. metadata +7 -3
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
- ::RSpec.shared_examples :mapper do |mapper, event|
4
+ ::RSpec.shared_examples "mapper" do |mapper, event|
5
5
  specify "event_to_record returns instance of Record" do
6
6
  record = mapper.event_to_record(event)
7
7
 
8
- expect(record).to be_kind_of(Record)
8
+ expect(record).to be_a(Record)
9
9
  expect(record.event_id).to eq(event.event_id)
10
10
  expect(record.event_type).to eq(event.event_type)
11
11
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.shared_examples :scheduler do |scheduler|
3
+ RSpec.shared_examples "scheduler" do |scheduler|
4
4
  specify "#call" do
5
5
  expect(scheduler).to respond_to(:call).with(2).arguments
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.shared_examples :subscriptions do |subscriptions_class|
3
+ RSpec.shared_examples "subscriptions" do |subscriptions_class|
4
4
  Test1DomainEvent = Class.new(RubyEventStore::Event)
5
5
  Test2DomainEvent = Class.new(RubyEventStore::Event)
6
6
  Test3DomainEvent = Class.new(RubyEventStore::Event)
@@ -24,8 +24,8 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
24
24
  another_handler = TestHandler.new
25
25
  global_handler = TestHandler.new
26
26
 
27
- subscriptions.add_subscription(handler, ['Test1DomainEvent', 'Test3DomainEvent'])
28
- subscriptions.add_subscription(another_handler, ['Test2DomainEvent'])
27
+ subscriptions.add_subscription(handler, %w[Test1DomainEvent Test3DomainEvent])
28
+ subscriptions.add_subscription(another_handler, ["Test2DomainEvent"])
29
29
  subscriptions.add_global_subscription(global_handler)
30
30
 
31
31
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, global_handler])
@@ -38,14 +38,15 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
38
38
  another_handler = TestHandler.new
39
39
  global_handler = TestHandler.new
40
40
 
41
- subscriptions.add_thread_subscription(handler, ['Test1DomainEvent', 'Test3DomainEvent'])
42
- subscriptions.add_thread_subscription(another_handler, ['Test2DomainEvent'])
41
+ subscriptions.add_thread_subscription(handler, %w[Test1DomainEvent Test3DomainEvent])
42
+ subscriptions.add_thread_subscription(another_handler, ["Test2DomainEvent"])
43
43
  subscriptions.add_thread_global_subscription(global_handler)
44
- t = Thread.new do
45
- subscriptions.add_thread_subscription(handler, ['Test2DomainEvent'])
46
- subscriptions.add_thread_global_subscription(another_handler)
47
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([another_handler, handler])
48
- end
44
+ t =
45
+ Thread.new do
46
+ subscriptions.add_thread_subscription(handler, ["Test2DomainEvent"])
47
+ subscriptions.add_thread_global_subscription(another_handler)
48
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([another_handler, handler])
49
+ end
49
50
 
50
51
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([global_handler, handler])
51
52
  expect(subscriptions.all_for("Test2DomainEvent")).to eq([global_handler, another_handler])
@@ -61,7 +62,7 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
61
62
 
62
63
  it "returns lambda as an output of subscribe methods" do
63
64
  handler = TestHandler.new
64
- result = subscriptions.add_subscription(handler, [Test1DomainEvent, Test2DomainEvent])
65
+ result = subscriptions.add_subscription(handler, %w[Test1DomainEvent Test2DomainEvent])
65
66
  expect(result).to respond_to(:call)
66
67
  end
67
68
 
@@ -79,9 +80,9 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
79
80
  it "revokes subscription" do
80
81
  handler = TestHandler.new
81
82
 
82
- revoke = subscriptions.add_subscription(handler, ['Test1DomainEvent', 'Test2DomainEvent'])
83
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
84
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
83
+ revoke = subscriptions.add_subscription(handler, %w[Test1DomainEvent Test2DomainEvent])
84
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
85
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
85
86
  revoke.()
86
87
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
87
88
  expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
@@ -101,9 +102,9 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
101
102
  it "revokes thread subscription" do
102
103
  handler = TestHandler.new
103
104
 
104
- revoke = subscriptions.add_thread_subscription(handler, ['Test1DomainEvent', 'Test2DomainEvent'])
105
- expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler])
106
- expect(subscriptions.all_for('Test2DomainEvent')).to eq([handler])
105
+ revoke = subscriptions.add_thread_subscription(handler, %w[Test1DomainEvent Test2DomainEvent])
106
+ expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler])
107
+ expect(subscriptions.all_for("Test2DomainEvent")).to eq([handler])
107
108
  revoke.()
108
109
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([])
109
110
  expect(subscriptions.all_for("Test2DomainEvent")).to eq([])
@@ -117,10 +118,10 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
117
118
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, handler])
118
119
  end
119
120
 
120
- it 'subscribes by type of event which is a class' do
121
+ it "subscribes by type of event which is a class" do
121
122
  handler = TestHandler.new
122
- subscriptions.add_subscription(handler, ['Test1DomainEvent'])
123
- subscriptions.add_thread_subscription(handler, ['Test1DomainEvent'])
123
+ subscriptions.add_subscription(handler, ["Test1DomainEvent"])
124
+ subscriptions.add_thread_subscription(handler, ["Test1DomainEvent"])
124
125
 
125
126
  expect(subscriptions.all_for("Test1DomainEvent")).to eq([handler, handler])
126
127
  end
@@ -53,7 +53,7 @@ module RubyEventStore
53
53
  result.dup do |r|
54
54
  r.older_than = time
55
55
  r.older_than_or_equal = nil
56
- end
56
+ end,
57
57
  )
58
58
  end
59
59
 
@@ -69,7 +69,7 @@ module RubyEventStore
69
69
  result.dup do |r|
70
70
  r.older_than = nil
71
71
  r.older_than_or_equal = time
72
- end
72
+ end,
73
73
  )
74
74
  end
75
75
 
@@ -85,7 +85,7 @@ module RubyEventStore
85
85
  result.dup do |r|
86
86
  r.newer_than_or_equal = nil
87
87
  r.newer_than = time
88
- end
88
+ end,
89
89
  )
90
90
  end
91
91
 
@@ -101,7 +101,7 @@ module RubyEventStore
101
101
  result.dup do |r|
102
102
  r.newer_than_or_equal = time
103
103
  r.newer_than = nil
104
- end
104
+ end,
105
105
  )
106
106
  end
107
107
 
@@ -241,7 +241,7 @@ module RubyEventStore
241
241
  result.dup do |r|
242
242
  r.read_as = :batch
243
243
  r.batch_size = batch_size
244
- end
244
+ end,
245
245
  )
246
246
  end
247
247
  alias in_batches_of in_batches
@@ -14,13 +14,13 @@ module RubyEventStore
14
14
  # @private
15
15
  def one(specification_result)
16
16
  record = repository.read(specification_result)
17
- mapper.record_to_event(record) if record
17
+ map([record]).first if record
18
18
  end
19
19
 
20
20
  # @api private
21
21
  # @private
22
22
  def each(specification_result)
23
- repository.read(specification_result).each { |batch| yield batch.map { |record| mapper.record_to_event(record) } }
23
+ repository.read(specification_result).each { |batch| yield map(batch) }
24
24
  end
25
25
 
26
26
  # @api private
@@ -31,6 +31,10 @@ module RubyEventStore
31
31
 
32
32
  private
33
33
 
34
+ def map(records)
35
+ mapper.records_to_events(records)
36
+ end
37
+
34
38
  attr_reader :repository, :mapper
35
39
  end
36
40
  end
@@ -19,39 +19,37 @@ module RubyEventStore
19
19
  with_types: nil
20
20
  )
21
21
  @attributes =
22
- Struct
23
- .new(
24
- :direction,
25
- :start,
26
- :stop,
27
- :older_than,
28
- :older_than_or_equal,
29
- :newer_than,
30
- :newer_than_or_equal,
31
- :time_sort_by,
32
- :count,
33
- :stream,
34
- :read_as,
35
- :batch_size,
36
- :with_ids,
37
- :with_types
38
- )
39
- .new(
40
- direction,
41
- start,
42
- stop,
43
- older_than,
44
- older_than_or_equal,
45
- newer_than,
46
- newer_than_or_equal,
47
- time_sort_by,
48
- count,
49
- stream,
50
- read_as,
51
- batch_size,
52
- with_ids,
53
- with_types
54
- )
22
+ Struct.new(
23
+ :direction,
24
+ :start,
25
+ :stop,
26
+ :older_than,
27
+ :older_than_or_equal,
28
+ :newer_than,
29
+ :newer_than_or_equal,
30
+ :time_sort_by,
31
+ :count,
32
+ :stream,
33
+ :read_as,
34
+ :batch_size,
35
+ :with_ids,
36
+ :with_types,
37
+ ).new(
38
+ direction,
39
+ start,
40
+ stop,
41
+ older_than,
42
+ older_than_or_equal,
43
+ newer_than,
44
+ newer_than_or_equal,
45
+ time_sort_by,
46
+ count,
47
+ stream,
48
+ read_as,
49
+ batch_size,
50
+ with_ids,
51
+ with_types,
52
+ )
55
53
  freeze
56
54
  end
57
55
 
@@ -299,7 +297,7 @@ module RubyEventStore
299
297
  attributes.read_as,
300
298
  batch_size,
301
299
  with_ids,
302
- with_types
300
+ with_types,
303
301
  ].hash ^ self.class.hash
304
302
  end
305
303
 
@@ -10,24 +10,24 @@ module RubyEventStore
10
10
  @thread = ThreadSubscriptions.new
11
11
  end
12
12
 
13
- def add_subscription(subscriber, event_types)
14
- local.add(subscriber, event_types)
13
+ def add_subscription(subscriber, topics)
14
+ local.add(subscriber, topics)
15
15
  end
16
16
 
17
17
  def add_global_subscription(subscriber)
18
18
  global.add(subscriber)
19
19
  end
20
20
 
21
- def add_thread_subscription(subscriber, event_types)
22
- thread.local.add(subscriber, event_types)
21
+ def add_thread_subscription(subscriber, topics)
22
+ thread.local.add(subscriber, topics)
23
23
  end
24
24
 
25
25
  def add_thread_global_subscription(subscriber)
26
26
  thread.global.add(subscriber)
27
27
  end
28
28
 
29
- def all_for(event_type)
30
- [local, global, thread].map { |r| r.all_for(event_type) }.reduce(&:+)
29
+ def all_for(topic)
30
+ [local, global, thread].map { |r| r.all_for(topic) }.reduce(&:+)
31
31
  end
32
32
 
33
33
  private
@@ -41,8 +41,8 @@ module RubyEventStore
41
41
  end
42
42
  attr_reader :local, :global
43
43
 
44
- def all_for(event_type)
45
- [global, local].map { |r| r.all_for(event_type) }.reduce(&:+)
44
+ def all_for(topic)
45
+ [global, local].map { |r| r.all_for(topic) }.reduce(&:+)
46
46
  end
47
47
  end
48
48
 
@@ -51,13 +51,13 @@ module RubyEventStore
51
51
  @subscriptions = Hash.new { |hsh, key| hsh[key] = [] }
52
52
  end
53
53
 
54
- def add(subscription, event_types)
55
- event_types.each { |type| @subscriptions[type] << subscription }
56
- -> { event_types.each { |type| @subscriptions.fetch(type).delete(subscription) } }
54
+ def add(subscription, topics)
55
+ topics.each { |topic| @subscriptions[topic] << subscription }
56
+ -> { topics.each { |topic| @subscriptions.fetch(topic).delete(subscription) } }
57
57
  end
58
58
 
59
- def all_for(event_type)
60
- @subscriptions[event_type]
59
+ def all_for(topic)
60
+ @subscriptions[topic]
61
61
  end
62
62
  end
63
63
 
@@ -71,7 +71,7 @@ module RubyEventStore
71
71
  -> { @subscriptions.delete(subscription) }
72
72
  end
73
73
 
74
- def all_for(_event_type)
74
+ def all_for(_topic)
75
75
  @subscriptions
76
76
  end
77
77
  end
@@ -81,13 +81,13 @@ module RubyEventStore
81
81
  @subscriptions = Concurrent::ThreadLocalVar.new { Hash.new { |hsh, key| hsh[key] = [] } }
82
82
  end
83
83
 
84
- def add(subscription, event_types)
85
- event_types.each { |type| @subscriptions.value[type] << subscription }
86
- -> { event_types.each { |type| @subscriptions.value.fetch(type).delete(subscription) } }
84
+ def add(subscription, topics)
85
+ topics.each { |topic| @subscriptions.value[topic] << subscription }
86
+ -> { topics.each { |topic| @subscriptions.value.fetch(topic).delete(subscription) } }
87
87
  end
88
88
 
89
- def all_for(event_type)
90
- @subscriptions.value[event_type]
89
+ def all_for(topic)
90
+ @subscriptions.value[topic]
91
91
  end
92
92
  end
93
93
 
@@ -101,7 +101,7 @@ module RubyEventStore
101
101
  -> { @subscriptions.value -= [subscription] }
102
102
  end
103
103
 
104
- def all_for(_event_type)
104
+ def all_for(_topic)
105
105
  @subscriptions.value
106
106
  end
107
107
  end
@@ -16,9 +16,7 @@ module RubyEventStore
16
16
  def deep_transform(data, &block)
17
17
  case data
18
18
  when Hash
19
- data.each_with_object({}) do |(key, value), hash|
20
- hash[yield(key)] = deep_transform(value, &block)
21
- end
19
+ data.each_with_object({}) { |(key, value), hash| hash[yield(key)] = deep_transform(value, &block) }
22
20
  when Array
23
21
  data.map { |i| deep_transform(i, &block) }
24
22
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
- VERSION = "2.16.0"
4
+ VERSION = "2.17.0"
5
5
  end
@@ -28,12 +28,14 @@ require_relative "ruby_event_store/mappers/transformation/upcast"
28
28
  require_relative "ruby_event_store/mappers/transformation/stringify_metadata_keys"
29
29
  require_relative "ruby_event_store/mappers/transformation/symbolize_metadata_keys"
30
30
  require_relative "ruby_event_store/mappers/transformation/preserve_types"
31
+ require_relative "ruby_event_store/mappers/batch_mapper"
31
32
  require_relative "ruby_event_store/mappers/pipeline"
32
33
  require_relative "ruby_event_store/mappers/pipeline_mapper"
33
34
  require_relative "ruby_event_store/mappers/default"
34
35
  require_relative "ruby_event_store/mappers/forgotten_data"
35
36
  require_relative "ruby_event_store/mappers/encryption_mapper"
36
37
  require_relative "ruby_event_store/mappers/instrumented_mapper"
38
+ require_relative "ruby_event_store/mappers/instrumented_batch_mapper"
37
39
  require_relative "ruby_event_store/mappers/json_mapper"
38
40
  require_relative "ruby_event_store/mappers/null_mapper"
39
41
  require_relative "ruby_event_store/serializers/yaml"
@@ -42,8 +44,10 @@ require_relative "ruby_event_store/correlated_commands"
42
44
  require_relative "ruby_event_store/link_by_metadata"
43
45
  require_relative "ruby_event_store/immediate_async_dispatcher"
44
46
  require_relative "ruby_event_store/composed_dispatcher"
47
+ require_relative "ruby_event_store/composed_broker"
45
48
  require_relative "ruby_event_store/version"
46
49
  require_relative "ruby_event_store/instrumented_repository"
47
50
  require_relative "ruby_event_store/instrumented_dispatcher"
48
51
  require_relative "ruby_event_store/instrumented_subscriptions"
49
- require_relative "ruby_event_store/event_type_resolver"
52
+ require_relative "ruby_event_store/instrumented_broker"
53
+ require_relative "ruby_event_store/event_type_resolver"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.0
4
+ version: 2.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: concurrent-ruby
@@ -43,6 +43,7 @@ files:
43
43
  - lib/ruby_event_store/batch_enumerator.rb
44
44
  - lib/ruby_event_store/broker.rb
45
45
  - lib/ruby_event_store/client.rb
46
+ - lib/ruby_event_store/composed_broker.rb
46
47
  - lib/ruby_event_store/composed_dispatcher.rb
47
48
  - lib/ruby_event_store/constants.rb
48
49
  - lib/ruby_event_store/correlated_commands.rb
@@ -53,15 +54,18 @@ files:
53
54
  - lib/ruby_event_store/expected_version.rb
54
55
  - lib/ruby_event_store/immediate_async_dispatcher.rb
55
56
  - lib/ruby_event_store/in_memory_repository.rb
57
+ - lib/ruby_event_store/instrumented_broker.rb
56
58
  - lib/ruby_event_store/instrumented_dispatcher.rb
57
59
  - lib/ruby_event_store/instrumented_repository.rb
58
60
  - lib/ruby_event_store/instrumented_subscriptions.rb
59
61
  - lib/ruby_event_store/link_by_metadata.rb
62
+ - lib/ruby_event_store/mappers/batch_mapper.rb
60
63
  - lib/ruby_event_store/mappers/default.rb
61
64
  - lib/ruby_event_store/mappers/encryption_key.rb
62
65
  - lib/ruby_event_store/mappers/encryption_mapper.rb
63
66
  - lib/ruby_event_store/mappers/forgotten_data.rb
64
67
  - lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb
68
+ - lib/ruby_event_store/mappers/instrumented_batch_mapper.rb
65
69
  - lib/ruby_event_store/mappers/instrumented_mapper.rb
66
70
  - lib/ruby_event_store/mappers/json_mapper.rb
67
71
  - lib/ruby_event_store/mappers/null_mapper.rb
@@ -117,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  - !ruby/object:Gem::Version
118
122
  version: '0'
119
123
  requirements: []
120
- rubygems_version: 3.6.2
124
+ rubygems_version: 3.6.9
121
125
  specification_version: 4
122
126
  summary: Implementation of an event store in Ruby
123
127
  test_files: []