ruby_event_store 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_event_store.rb +43 -43
- data/lib/ruby_event_store/client.rb +6 -2
- data/lib/ruby_event_store/mappers/transformation/domain_event.rb +2 -2
- data/lib/ruby_event_store/spec/event_repository_lint.rb +21 -0
- data/lib/ruby_event_store/spec/subscriptions_lint.rb +0 -11
- data/lib/ruby_event_store/subscriptions.rb +4 -3
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28fef13a18c820b5e2e67ffef0aa6ee04b171a427fe9f7a9a4323dbab9db61bb
|
4
|
+
data.tar.gz: 8aa4bcf65629ae5e1912651d08be52de870f0dc0c274bd046796400d6a50bf34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2717723ff31551edb75469a884d88a5e64f97432f218a54c71fe84245bdd91ff770215bd54b90a2ee5dd56054a6bba29ed4ed766c551bb7d7c6f66806f23e207
|
7
|
+
data.tar.gz: 4f509c7e557271f414aad29db6dd04063aa9d29a45a49985fb12e89192e88d5bee5c8ad73a561faad3d196e04c4ff3ad2f1471ea3f67f0bd63f54060518cac27
|
data/lib/ruby_event_store.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
3
|
+
require_relative 'ruby_event_store/dispatcher'
|
4
|
+
require_relative 'ruby_event_store/subscriptions'
|
5
|
+
require_relative 'ruby_event_store/broker'
|
6
|
+
require_relative 'ruby_event_store/in_memory_repository'
|
7
|
+
require_relative 'ruby_event_store/projection'
|
8
|
+
require_relative 'ruby_event_store/errors'
|
9
|
+
require_relative 'ruby_event_store/constants'
|
10
|
+
require_relative 'ruby_event_store/client'
|
11
|
+
require_relative 'ruby_event_store/metadata'
|
12
|
+
require_relative 'ruby_event_store/specification'
|
13
|
+
require_relative 'ruby_event_store/specification_result'
|
14
|
+
require_relative 'ruby_event_store/specification_reader'
|
15
|
+
require_relative 'ruby_event_store/event'
|
16
|
+
require_relative 'ruby_event_store/stream'
|
17
|
+
require_relative 'ruby_event_store/expected_version'
|
18
|
+
require_relative 'ruby_event_store/record'
|
19
|
+
require_relative 'ruby_event_store/serialized_record'
|
20
|
+
require_relative 'ruby_event_store/null'
|
21
|
+
require_relative 'ruby_event_store/transform_keys'
|
22
|
+
require_relative 'ruby_event_store/mappers/encryption_key'
|
23
|
+
require_relative 'ruby_event_store/mappers/in_memory_encryption_key_repository'
|
24
|
+
require_relative 'ruby_event_store/mappers/transformation/domain_event'
|
25
|
+
require_relative 'ruby_event_store/mappers/transformation/encryption'
|
26
|
+
require_relative 'ruby_event_store/mappers/transformation/event_class_remapper'
|
27
|
+
require_relative 'ruby_event_store/mappers/transformation/upcast'
|
28
|
+
require_relative 'ruby_event_store/mappers/transformation/stringify_metadata_keys'
|
29
|
+
require_relative 'ruby_event_store/mappers/transformation/symbolize_metadata_keys'
|
30
|
+
require_relative 'ruby_event_store/mappers/pipeline'
|
31
|
+
require_relative 'ruby_event_store/mappers/pipeline_mapper'
|
32
|
+
require_relative 'ruby_event_store/mappers/default'
|
33
|
+
require_relative 'ruby_event_store/mappers/forgotten_data'
|
34
|
+
require_relative 'ruby_event_store/mappers/encryption_mapper'
|
35
|
+
require_relative 'ruby_event_store/mappers/instrumented_mapper'
|
36
|
+
require_relative 'ruby_event_store/mappers/json_mapper'
|
37
|
+
require_relative 'ruby_event_store/mappers/null_mapper'
|
38
|
+
require_relative 'ruby_event_store/batch_enumerator'
|
39
|
+
require_relative 'ruby_event_store/correlated_commands'
|
40
|
+
require_relative 'ruby_event_store/link_by_metadata'
|
41
|
+
require_relative 'ruby_event_store/immediate_async_dispatcher'
|
42
|
+
require_relative 'ruby_event_store/composed_dispatcher'
|
43
|
+
require_relative 'ruby_event_store/version'
|
44
|
+
require_relative 'ruby_event_store/instrumented_repository'
|
45
|
+
require_relative 'ruby_event_store/instrumented_dispatcher'
|
@@ -131,8 +131,8 @@ module RubyEventStore
|
|
131
131
|
#
|
132
132
|
# @param to [Class, String] type of events to get list of sybscribed handlers
|
133
133
|
# @return [Array<Object, Class>]
|
134
|
-
def subscribers_for(
|
135
|
-
subscriptions.all_for(
|
134
|
+
def subscribers_for(event_class)
|
135
|
+
subscriptions.all_for(event_type_resolver.call(event_class))
|
136
136
|
end
|
137
137
|
|
138
138
|
# Builder object for collecting temporary handlers (subscribers)
|
@@ -328,6 +328,10 @@ module RubyEventStore
|
|
328
328
|
|
329
329
|
protected
|
330
330
|
|
331
|
+
def event_type_resolver
|
332
|
+
subscriptions.event_type_resolver
|
333
|
+
end
|
334
|
+
|
331
335
|
def metadata=(value)
|
332
336
|
@metadata.value = value
|
333
337
|
end
|
@@ -5,9 +5,9 @@ module RubyEventStore
|
|
5
5
|
module Transformation
|
6
6
|
class DomainEvent
|
7
7
|
def dump(domain_event)
|
8
|
-
metadata
|
8
|
+
metadata = domain_event.metadata.dup.to_h
|
9
9
|
timestamp = metadata.delete(:timestamp)
|
10
|
-
valid_at
|
10
|
+
valid_at = metadata.delete(:valid_at)
|
11
11
|
Record.new(
|
12
12
|
event_id: domain_event.event_id,
|
13
13
|
metadata: metadata,
|
@@ -972,6 +972,8 @@ module RubyEventStore
|
|
972
972
|
|
973
973
|
specify do
|
974
974
|
expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
|
975
|
+
expect(repository.read(specification.in_batches.as_at.result)).to be_kind_of(Enumerator)
|
976
|
+
expect(repository.read(specification.in_batches.as_of.result)).to be_kind_of(Enumerator)
|
975
977
|
events = Array.new(10) { SRecord.new }
|
976
978
|
repository.append_to_stream(
|
977
979
|
events,
|
@@ -979,6 +981,9 @@ module RubyEventStore
|
|
979
981
|
ExpectedVersion.none
|
980
982
|
)
|
981
983
|
expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
|
984
|
+
expect(repository.read(specification.in_batches.as_at.result)).to be_kind_of(Enumerator)
|
985
|
+
expect(repository.read(specification.in_batches.as_of.result)).to be_kind_of(Enumerator)
|
986
|
+
|
982
987
|
end
|
983
988
|
|
984
989
|
specify do
|
@@ -1390,5 +1395,21 @@ module RubyEventStore
|
|
1390
1395
|
expect(repository.read(specification.as_of.result).map(&:event_id)).to eq [e3, e2, e1]
|
1391
1396
|
expect(repository.read(specification.as_of.backward.result).map(&:event_id)).to eq [e1, e2, e3]
|
1392
1397
|
end
|
1398
|
+
|
1399
|
+
specify "time order is respected with batches" do
|
1400
|
+
repository.append_to_stream([
|
1401
|
+
SRecord.new(event_id: e1 = SecureRandom.uuid, timestamp: Time.new(2020,1,1), valid_at: Time.new(2020,1,9)),
|
1402
|
+
SRecord.new(event_id: e2 = SecureRandom.uuid, timestamp: Time.new(2020,1,3), valid_at: Time.new(2020,1,6)),
|
1403
|
+
SRecord.new(event_id: e3 = SecureRandom.uuid, timestamp: Time.new(2020,1,2), valid_at: Time.new(2020,1,3)),
|
1404
|
+
],
|
1405
|
+
Stream.new("Dummy"),
|
1406
|
+
ExpectedVersion.any
|
1407
|
+
)
|
1408
|
+
expect(repository.read(specification.in_batches.result).to_a.flatten.map(&:event_id)).to eq [e1, e2, e3]
|
1409
|
+
expect(repository.read(specification.in_batches.as_at.result).to_a.flatten.map(&:event_id)).to eq [e1, e3, e2]
|
1410
|
+
expect(repository.read(specification.in_batches.as_at.backward.result).to_a.flatten.map(&:event_id)).to eq [e2, e3, e1]
|
1411
|
+
expect(repository.read(specification.in_batches.as_of.result).to_a.flatten.map(&:event_id)).to eq [e3, e2, e1]
|
1412
|
+
expect(repository.read(specification.in_batches.as_of.backward.result).to_a.flatten.map(&:event_id)).to eq [e1, e2, e3]
|
1413
|
+
end
|
1393
1414
|
end
|
1394
1415
|
end
|
@@ -121,16 +121,5 @@ RSpec.shared_examples :subscriptions do |subscriptions_class|
|
|
121
121
|
subscriptions.add_thread_subscription(handler, [Test1DomainEvent])
|
122
122
|
|
123
123
|
expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler, handler])
|
124
|
-
expect(subscriptions.all_for(Test1DomainEvent)).to eq([handler, handler])
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'subscribes by type of event which is a class or string with custom type resolver' do
|
128
|
-
subscriptions = subscriptions_class.new(event_type_resolver: ->(type) { type.to_s.reverse })
|
129
|
-
handler = TestHandler.new
|
130
|
-
subscriptions.add_subscription(handler, [Test1DomainEvent])
|
131
|
-
subscriptions.add_thread_subscription(handler, ['Test1DomainEvent'])
|
132
|
-
|
133
|
-
expect(subscriptions.all_for('Test1DomainEvent')).to eq([handler, handler])
|
134
|
-
expect(subscriptions.all_for(Test1DomainEvent)).to eq([handler, handler])
|
135
124
|
end
|
136
125
|
end
|
@@ -28,10 +28,11 @@ module RubyEventStore
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def all_for(event_type)
|
31
|
-
|
32
|
-
[local, global, thread].map{|r| r.all_for(resolved_event_type)}.reduce(&:+)
|
31
|
+
[local, global, thread].map{|r| r.all_for(event_type)}.reduce(&:+)
|
33
32
|
end
|
34
33
|
|
34
|
+
attr_reader :event_type_resolver
|
35
|
+
|
35
36
|
private
|
36
37
|
attr_reader :local, :global, :thread
|
37
38
|
|
@@ -44,7 +45,7 @@ module RubyEventStore
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def resolve_event_type(type)
|
47
|
-
|
48
|
+
event_type_resolver.call(type)
|
48
49
|
end
|
49
50
|
|
50
51
|
class ThreadSubscriptions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.6'
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - ">="
|