ruby_event_store 0.41.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/ruby_event_store.rb +1 -0
- data/lib/ruby_event_store/broker.rb +1 -1
- data/lib/ruby_event_store/event.rb +2 -16
- data/lib/ruby_event_store/link_by_metadata.rb +4 -4
- data/lib/ruby_event_store/mappers/json_mapper.rb +16 -0
- data/lib/ruby_event_store/mappers/protobuf.rb +1 -7
- data/lib/ruby_event_store/mappers/transformation/domain_event.rb +1 -1
- data/lib/ruby_event_store/mappers/transformation/encryption.rb +2 -2
- data/lib/ruby_event_store/mappers/transformation/protobuf_nested_struct_metadata.rb +1 -2
- data/lib/ruby_event_store/projection.rb +6 -4
- data/lib/ruby_event_store/spec/broker_lint.rb +1 -1
- data/lib/ruby_event_store/spec/event_lint.rb +6 -8
- data/lib/ruby_event_store/spec/mapper_lint.rb +1 -1
- data/lib/ruby_event_store/specification_result.rb +1 -1
- data/lib/ruby_event_store/version.rb +1 -1
- data/ruby_event_store.gemspec +1 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e7110d2b9570a081d8c27c092fb49f745e2fc52df0f5ac8a1fef43e9c947b5
|
4
|
+
data.tar.gz: eca5201fd1e093a988d0dbd405a46fbd78c1da27e2733fc263e6fcd4b474eed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa50fda1e6bf1deb3d8ea4b22b39d4e039a18b3ad6fd325c1b6295195f435214f4210a14fb4f164ad5113db0a8f0bd8d27ff083bd2cccdb6a6714c01cda3239f
|
7
|
+
data.tar.gz: d7bf94647c93fa324249b63495a792bd56678037db5bc0a03fb654679e7298d8d15fbd4846e174a98335986c6eeccd9d326c4c8b67435b0e03edb84a94a2249d
|
data/Gemfile
CHANGED
data/lib/ruby_event_store.rb
CHANGED
@@ -36,6 +36,7 @@ require 'ruby_event_store/mappers/default'
|
|
36
36
|
require 'ruby_event_store/mappers/forgotten_data'
|
37
37
|
require 'ruby_event_store/mappers/encryption_mapper'
|
38
38
|
require 'ruby_event_store/mappers/instrumented_mapper'
|
39
|
+
require 'ruby_event_store/mappers/json_mapper'
|
39
40
|
require 'ruby_event_store/mappers/null_mapper'
|
40
41
|
require 'ruby_event_store/mappers/protobuf'
|
41
42
|
require 'ruby_event_store/batch_enumerator'
|
@@ -8,7 +8,7 @@ module RubyEventStore
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(event, serialized_event)
|
11
|
-
subscribers = subscriptions.all_for(event.
|
11
|
+
subscribers = subscriptions.all_for(event.event_type)
|
12
12
|
subscribers.each do |subscriber|
|
13
13
|
dispatcher.call(subscriber, event, serialized_event)
|
14
14
|
end
|
@@ -30,24 +30,10 @@ module RubyEventStore
|
|
30
30
|
|
31
31
|
# Type of event. Used when matching with subscribed handlers.
|
32
32
|
# @return [String]
|
33
|
-
def
|
33
|
+
def event_type
|
34
34
|
self.class.name
|
35
35
|
end
|
36
36
|
|
37
|
-
# Returns a hash representation of the event.
|
38
|
-
#
|
39
|
-
# Metadata is converted to hash as well
|
40
|
-
#
|
41
|
-
# @return [Hash] with :event_id, :metadata, :data, :type keys
|
42
|
-
def to_h
|
43
|
-
{
|
44
|
-
event_id: event_id,
|
45
|
-
metadata: metadata.to_h,
|
46
|
-
data: data,
|
47
|
-
type: type,
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
37
|
# Timestamp from metadata
|
52
38
|
#
|
53
39
|
# @return [Time, nil]
|
@@ -140,4 +126,4 @@ module RubyEventStore
|
|
140
126
|
|
141
127
|
alias_method :eql?, :==
|
142
128
|
end
|
143
|
-
end
|
129
|
+
end
|
@@ -13,7 +13,7 @@ module RubyEventStore
|
|
13
13
|
return unless event.metadata.has_key?(@key)
|
14
14
|
|
15
15
|
@event_store.link(
|
16
|
-
[event.
|
16
|
+
[event.event_id],
|
17
17
|
stream_name: "#{@prefix}#{event.metadata.fetch(@key)}"
|
18
18
|
)
|
19
19
|
end
|
@@ -48,10 +48,10 @@ module RubyEventStore
|
|
48
48
|
|
49
49
|
def call(event)
|
50
50
|
@event_store.link(
|
51
|
-
[event.
|
52
|
-
stream_name: "#{@prefix}#{event.
|
51
|
+
[event.event_id],
|
52
|
+
stream_name: "#{@prefix}#{event.event_type}"
|
53
53
|
)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
end
|
57
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Mappers
|
5
|
+
class JSONMapper < PipelineMapper
|
6
|
+
def initialize(events_class_remapping: {})
|
7
|
+
super(Pipeline.new(
|
8
|
+
transformations: [
|
9
|
+
Transformation::EventClassRemapper.new(events_class_remapping),
|
10
|
+
Transformation::SymbolizeMetadataKeys.new,
|
11
|
+
],
|
12
|
+
))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,15 +2,9 @@
|
|
2
2
|
|
3
3
|
module RubyEventStore
|
4
4
|
class Proto < RubyEventStore::Event
|
5
|
-
def
|
5
|
+
def event_type
|
6
6
|
data.class.descriptor.name
|
7
7
|
end
|
8
|
-
|
9
|
-
def ==(other_event)
|
10
|
-
other_event.instance_of?(self.class) &&
|
11
|
-
other_event.event_id.eql?(event_id) &&
|
12
|
-
other_event.data == data # https://github.com/google/protobuf/issues/4455
|
13
|
-
end
|
14
8
|
end
|
15
9
|
|
16
10
|
module Mappers
|
@@ -82,14 +82,14 @@ module RubyEventStore
|
|
82
82
|
|
83
83
|
def encrypt_data(data, meta)
|
84
84
|
meta.reduce(data) do |acc, (key, value)|
|
85
|
-
acc[key] = encrypt_attribute(acc, key, value)
|
85
|
+
acc[key] = encrypt_attribute(acc, key, value) if data.has_key?(key)
|
86
86
|
acc
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
def decrypt_data(data, meta)
|
91
91
|
meta.reduce(data) do |acc, (key, value)|
|
92
|
-
acc[key] = decrypt_attribute(data, key, value)
|
92
|
+
acc[key] = decrypt_attribute(data, key, value) if data.has_key?(key)
|
93
93
|
acc
|
94
94
|
end
|
95
95
|
end
|
@@ -9,8 +9,7 @@ module RubyEventStore
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def dump(item)
|
12
|
-
|
13
|
-
metadata = ProtobufNestedStruct::HashMapStringValue.dump(stringify.dump(item).metadata)
|
12
|
+
metadata = ProtobufNestedStruct::HashMapStringValue.dump(item.metadata)
|
14
13
|
item.merge(metadata: metadata)
|
15
14
|
end
|
16
15
|
|
@@ -15,8 +15,8 @@ module RubyEventStore
|
|
15
15
|
|
16
16
|
def initialize(streams: [])
|
17
17
|
@streams = streams
|
18
|
-
@handlers =
|
19
|
-
@init = -> {
|
18
|
+
@handlers = {}
|
19
|
+
@init = -> { {} }
|
20
20
|
end
|
21
21
|
|
22
22
|
attr_reader :streams, :handlers
|
@@ -43,7 +43,7 @@ module RubyEventStore
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def call(event)
|
46
|
-
handlers.fetch(event.
|
46
|
+
handlers.fetch(event.event_type).(current_state, event)
|
47
47
|
end
|
48
48
|
|
49
49
|
def handled_events
|
@@ -51,6 +51,7 @@ module RubyEventStore
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def run(event_store, start: nil, count: PAGE_SIZE)
|
54
|
+
return initial_state if handled_events.empty?
|
54
55
|
if streams.any?
|
55
56
|
reduce_from_streams(event_store, start, count)
|
56
57
|
else
|
@@ -83,6 +84,7 @@ module RubyEventStore
|
|
83
84
|
|
84
85
|
def read_scope(event_store, stream, count, start)
|
85
86
|
scope = event_store.read.in_batches(count)
|
87
|
+
scope = scope.of_type(handled_events)
|
86
88
|
scope = scope.stream(stream) if stream
|
87
89
|
scope = scope.from(start) if start
|
88
90
|
scope
|
@@ -93,7 +95,7 @@ module RubyEventStore
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def transition(state, event)
|
96
|
-
handlers
|
98
|
+
handlers.fetch(event.event_type).call(state, event)
|
97
99
|
state
|
98
100
|
end
|
99
101
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
RSpec.shared_examples :broker do |broker_klass|
|
2
|
-
let(:event) { instance_double(::RubyEventStore::Event,
|
2
|
+
let(:event) { instance_double(::RubyEventStore::Event, event_type: 'EventType') }
|
3
3
|
let(:serialized_event) { instance_double(::RubyEventStore::SerializedRecord) }
|
4
4
|
let(:handler) { HandlerClass.new }
|
5
5
|
let(:subscriptions) { ::RubyEventStore::Subscriptions.new }
|
@@ -1,9 +1,7 @@
|
|
1
|
-
RSpec.shared_examples :event do |event_class|
|
1
|
+
RSpec.shared_examples :event do |event_class, data, metadata|
|
2
2
|
it 'allows initialization' do
|
3
3
|
expect {
|
4
|
-
|
5
|
-
allow(metadata).to receive(:to_h).and_return({})
|
6
|
-
event_class.new(event_id: Object.new, data: Object.new, metadata: metadata)
|
4
|
+
event_class.new(event_id: Object.new, data: data || Object.new, metadata: metadata || {})
|
7
5
|
}.not_to raise_error
|
8
6
|
end
|
9
7
|
|
@@ -29,11 +27,11 @@ RSpec.shared_examples :event do |event_class|
|
|
29
27
|
expect(event.event_id).to eq '1234567890'
|
30
28
|
end
|
31
29
|
|
32
|
-
it 'provides type as string' do
|
30
|
+
it 'provides event type as string' do
|
33
31
|
event = event_class.new
|
34
|
-
expect(event.
|
35
|
-
expect(event.
|
36
|
-
expect(event.
|
32
|
+
expect(event.event_type).to be_an_instance_of(String)
|
33
|
+
expect(event.event_type).not_to eq ''
|
34
|
+
expect(event.event_type).not_to eq nil
|
37
35
|
end
|
38
36
|
|
39
37
|
it "provides data" do
|
@@ -5,7 +5,7 @@ module RubyEventStore
|
|
5
5
|
|
6
6
|
expect(record).to be_kind_of(SerializedRecord)
|
7
7
|
expect(record.event_id).to eq(domain_event.event_id)
|
8
|
-
expect(record.event_type).to eq(domain_event.
|
8
|
+
expect(record.event_type).to eq(domain_event.event_type)
|
9
9
|
end
|
10
10
|
|
11
11
|
specify "serialize and deserialize gives equal event" do
|
@@ -151,7 +151,7 @@ module RubyEventStore
|
|
151
151
|
def dup
|
152
152
|
new_attributes = attributes.dup
|
153
153
|
yield new_attributes if block_given?
|
154
|
-
SpecificationResult.new(new_attributes.to_h)
|
154
|
+
SpecificationResult.new(**new_attributes.to_h)
|
155
155
|
end
|
156
156
|
|
157
157
|
# Two specification attributess are equal if:
|
data/ruby_event_store.gemspec
CHANGED
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.6
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.6
|
27
33
|
description: Implementation of Event Store in Ruby
|
28
34
|
email:
|
29
35
|
- dev@arkency.com
|
@@ -57,6 +63,7 @@ files:
|
|
57
63
|
- lib/ruby_event_store/mappers/forgotten_data.rb
|
58
64
|
- lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb
|
59
65
|
- lib/ruby_event_store/mappers/instrumented_mapper.rb
|
66
|
+
- lib/ruby_event_store/mappers/json_mapper.rb
|
60
67
|
- lib/ruby_event_store/mappers/null_mapper.rb
|
61
68
|
- lib/ruby_event_store/mappers/pipeline.rb
|
62
69
|
- lib/ruby_event_store/mappers/pipeline_mapper.rb
|
@@ -113,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
120
|
- !ruby/object:Gem::Version
|
114
121
|
version: '0'
|
115
122
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.7.6.2
|
123
|
+
rubygems_version: 3.0.3
|
118
124
|
signing_key:
|
119
125
|
specification_version: 4
|
120
126
|
summary: Event Store in Ruby
|