active_event_store 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/lib/active_event_store/domain_event.rb +44 -0
- data/lib/active_event_store/mapper.rb +6 -48
- data/lib/active_event_store/test_helper/event_published_matcher.rb +1 -1
- data/lib/active_event_store/version.rb +1 -1
- data/lib/active_event_store.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8710d5820746603d15b1d77b3bc01bbf70eb1943339041cf5c90fb80b15fd9b3
|
4
|
+
data.tar.gz: 8b7c765faf7eb4b781e64068b30a361e36110a775c81aea466fdc0a01a843624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f00bc57582a15aa87279ca77fe58fcce032a1e1fab32c2567faefddbfc11a6697944c438e7794f91d030494441ce9662c62911ea0bd26cd2ec69e2f81fcf6bd
|
7
|
+
data.tar.gz: d793f2718e1e706ceea6d386e63527d55ade4a09c77a3ce9c2d6c25a1a6d2d32d162570dd239f58df3e1883106112f5ca152bd37845f9f3056eb7f42e9570370
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.2.0 (2024-01-25)
|
6
|
+
|
7
|
+
- Use custom pipeline mapper and domain event transformer. ([@Samsinite][])
|
8
|
+
|
5
9
|
## 1.1.0 (2023-08-24)
|
6
10
|
|
7
11
|
- Require Ruby 2.7+. ([@palkan][])
|
@@ -37,3 +41,4 @@ Now `ActiveSupport.on_load(:active_event_store) { ... }` works.
|
|
37
41
|
[@palkan]: https://github.com/palkan
|
38
42
|
[@chriscz]: https://github.com/chriscz
|
39
43
|
[@caws]: https://github.com/caws
|
44
|
+
[@Samsinite]: https://github.com/Samsinite
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -87,10 +87,10 @@ You can also register events manually:
|
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
# by passing an event class
|
90
|
-
ActiveEventStore.
|
90
|
+
ActiveEventStore.mapping.register_event MyEventClass
|
91
91
|
|
92
92
|
# or more precisely (in that case `event.type` must be equal to "my_event")
|
93
|
-
ActiveEventStore.
|
93
|
+
ActiveEventStore.mapping.register "my_event", MyEventClass
|
94
94
|
```
|
95
95
|
|
96
96
|
### Publish events
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveEventStore
|
4
|
+
class DomainEvent < RubyEventStore::Mappers::Transformation::DomainEvent
|
5
|
+
attr_reader :mapping
|
6
|
+
def initialize(mapping:)
|
7
|
+
@mapping = mapping
|
8
|
+
end
|
9
|
+
|
10
|
+
def dump(event)
|
11
|
+
# lazily add type to mapping
|
12
|
+
# NOTE: use class name instead of a class to handle code reload
|
13
|
+
# in development (to avoid accessing orphaned classes)
|
14
|
+
mapping.register(event.event_type, event.class.name) unless mapping.exist?(event.event_type)
|
15
|
+
|
16
|
+
metadata = event.metadata.dup.to_h
|
17
|
+
timestamp = metadata[:timestamp]
|
18
|
+
valid_at = metadata[:valid_at]
|
19
|
+
RubyEventStore::Record.new(
|
20
|
+
event_id: event.event_id,
|
21
|
+
metadata: metadata,
|
22
|
+
data: event.data,
|
23
|
+
event_type: event.event_type,
|
24
|
+
timestamp: timestamp,
|
25
|
+
valid_at: valid_at
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def load(record)
|
30
|
+
event_class = mapping.fetch(record.event_type) {
|
31
|
+
raise "Don't know how to deserialize event: \"#{record.event_type}\". " \
|
32
|
+
"Add explicit mapping: ActiveEventStore.mapping.register \"#{record.event_type}\", \"<Class Name>\""
|
33
|
+
}
|
34
|
+
|
35
|
+
Object
|
36
|
+
.const_get(event_class)
|
37
|
+
.new(
|
38
|
+
**record.data.symbolize_keys,
|
39
|
+
event_id: record.event_id,
|
40
|
+
metadata: record.metadata.merge(timestamp: record.timestamp, valid_at: record.valid_at)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,54 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveEventStore
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
RubyEventStore::
|
8
|
-
|
4
|
+
class Mapper < RubyEventStore::Mappers::PipelineMapper
|
5
|
+
def initialize(mapping:)
|
6
|
+
super(RubyEventStore::Mappers::Pipeline.new(
|
7
|
+
RubyEventStore::Mappers::Transformation::SymbolizeMetadataKeys.new,
|
8
|
+
to_domain_event: ActiveEventStore::DomainEvent.new(mapping: mapping)
|
9
|
+
))
|
9
10
|
end
|
10
|
-
})
|
11
|
-
|
12
|
-
# Custom mapper for RES events.
|
13
|
-
#
|
14
|
-
# See https://github.com/RailsEventStore/rails_event_store/blob/v0.35.0/ruby_event_store/lib/ruby_event_store/mappers/default.rb
|
15
|
-
class Mapper
|
16
|
-
def initialize(mapping:, serializer: ActiveEventStore.config.serializer)
|
17
|
-
@serializer = serializer
|
18
|
-
@mapping = mapping
|
19
|
-
end
|
20
|
-
|
21
|
-
def event_to_record(domain_event)
|
22
|
-
# lazily add type to mapping
|
23
|
-
# NOTE: use class name instead of a class to handle code reload
|
24
|
-
# in development (to avoid accessing orphaned classes)
|
25
|
-
mapping.register(domain_event.event_type, domain_event.class.name) unless mapping.exist?(domain_event.event_type)
|
26
|
-
|
27
|
-
RubyEventStore::Record.new(
|
28
|
-
event_id: domain_event.event_id,
|
29
|
-
metadata: serializer.dump(domain_event.metadata.to_h),
|
30
|
-
data: serializer.dump(domain_event.data),
|
31
|
-
event_type: domain_event.event_type,
|
32
|
-
timestamp: domain_event.timestamp,
|
33
|
-
valid_at: domain_event.valid_at
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
def record_to_event(record)
|
38
|
-
event_class = mapping.fetch(record.event_type) {
|
39
|
-
raise "Don't know how to deserialize event: \"#{record.event_type}\". " \
|
40
|
-
"Add explicit mapping: ActiveEventStore.mapping.register \"#{record.event_type}\", \"<Class Name>\""
|
41
|
-
}
|
42
|
-
|
43
|
-
Object.const_get(event_class).new(
|
44
|
-
**serializer.load(record.data).symbolize_keys,
|
45
|
-
metadata: serializer.load(record.metadata).symbolize_keys,
|
46
|
-
event_id: record.event_id
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
attr_reader :serializer, :mapping
|
53
11
|
end
|
54
12
|
end
|
@@ -142,7 +142,7 @@ module ActiveEventStore
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def event_data_matches?(attributes, event)
|
145
|
-
|
145
|
+
attributes.nil? || attributes.all? { |k, v| v == event.public_send(k) }
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
data/lib/active_event_store.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails_event_store
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- README.md
|
108
108
|
- lib/active_event_store.rb
|
109
109
|
- lib/active_event_store/config.rb
|
110
|
+
- lib/active_event_store/domain_event.rb
|
110
111
|
- lib/active_event_store/engine.rb
|
111
112
|
- lib/active_event_store/event.rb
|
112
113
|
- lib/active_event_store/mapper.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
|
-
rubygems_version: 3.4.
|
146
|
+
rubygems_version: 3.4.20
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Rails Event Store in a more Rails way
|