ruby_event_store 2.5.1 → 2.6.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/client.rb +3 -3
- data/lib/ruby_event_store/event.rb +1 -4
- data/lib/ruby_event_store/expected_version.rb +1 -4
- data/lib/ruby_event_store/instrumented_subscriptions.rb +61 -0
- data/lib/ruby_event_store/mappers/transformation/preserve_types.rb +123 -0
- data/lib/ruby_event_store/record.rb +1 -2
- data/lib/ruby_event_store/serialized_record.rb +1 -2
- data/lib/ruby_event_store/spec/event_repository_lint.rb +9 -0
- data/lib/ruby_event_store/specification.rb +4 -4
- data/lib/ruby_event_store/specification_result.rb +1 -5
- data/lib/ruby_event_store/stream.rb +1 -4
- data/lib/ruby_event_store/transform_keys.rb +9 -10
- data/lib/ruby_event_store/version.rb +1 -1
- data/lib/ruby_event_store.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81a9b613c69a42dd544741b6c9beda7f8bffe1e680eba7e4bd93c1fad1ef2f40
|
4
|
+
data.tar.gz: ada38679291f059d618a9232770d401f795deb3e0ce6b8c04e43604269a36353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106d20e97c28f0595d5750aa61934a905b74aa8d9ecd28ac14176225c5a257082017da184c47d7a314cda09e142b5c1e31a20a9544bee2eeaf4973f8f158a745
|
7
|
+
data.tar.gz: b78ee185caefd7070b3cb82f355f03e6efd9299c367187fbbdde5cb65e75973d796dba103c7ddc3123a6eb7919992dab1cb84cef9717409632244cdf93a6a7eb
|
@@ -254,9 +254,9 @@ module RubyEventStore
|
|
254
254
|
# @param metadata [Hash] metadata to set for events
|
255
255
|
# @param block [Proc] block of code during which the metadata will be added
|
256
256
|
# @return [Object] last value returned by the provided block
|
257
|
-
def with_metadata(
|
258
|
-
previous_metadata = metadata
|
259
|
-
self.metadata = previous_metadata.merge(
|
257
|
+
def with_metadata(metadata_for_block, &block)
|
258
|
+
previous_metadata = metadata
|
259
|
+
self.metadata = previous_metadata.merge(metadata_for_block)
|
260
260
|
block.call if block_given?
|
261
261
|
ensure
|
262
262
|
self.metadata = previous_metadata
|
@@ -62,9 +62,6 @@ module RubyEventStore
|
|
62
62
|
other_event.event_id.eql?(event_id) && other_event.data.eql?(data)
|
63
63
|
end
|
64
64
|
|
65
|
-
# @private
|
66
|
-
BIG_VALUE = 0b111111100100000010010010110011101011000101010101001100100110000
|
67
|
-
|
68
65
|
# Generates a Fixnum hash value for this object. This function
|
69
66
|
# have the property that a.eql?(b) implies a.hash == b.hash.
|
70
67
|
#
|
@@ -77,7 +74,7 @@ module RubyEventStore
|
|
77
74
|
# * data
|
78
75
|
def hash
|
79
76
|
# We don't use metadata because == does not use metadata
|
80
|
-
[
|
77
|
+
[event_type, event_id, data].hash ^ self.class.hash
|
81
78
|
end
|
82
79
|
|
83
80
|
# Reads correlation_id from metadata.
|
@@ -49,11 +49,8 @@ module RubyEventStore
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
BIG_VALUE = 0b110111100100000010010010110011101011000101010101001100100110011
|
53
|
-
private_constant :BIG_VALUE
|
54
|
-
|
55
52
|
def hash
|
56
|
-
|
53
|
+
version.hash ^ self.class.hash
|
57
54
|
end
|
58
55
|
|
59
56
|
def ==(other_expected_version)
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
class InstrumentedSubscriptions
|
5
|
+
def initialize(subscriptions, instrumentation)
|
6
|
+
@subscriptions = subscriptions
|
7
|
+
@instrumentation = instrumentation
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_subscription(subscriber, event_types)
|
11
|
+
instrument(subscriber: subscriber, event_types: event_types) do
|
12
|
+
subscriptions.add_subscription(subscriber, event_types)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_global_subscription(subscriber)
|
17
|
+
instrument(subscriber: subscriber) do
|
18
|
+
subscriptions.add_global_subscription(subscriber)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_thread_subscription(subscriber, event_types)
|
23
|
+
instrument(subscriber: subscriber, event_types: event_types) do
|
24
|
+
subscriptions.add_thread_subscription(subscriber, event_types)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_thread_global_subscription(subscriber)
|
29
|
+
instrument(subscriber: subscriber) do
|
30
|
+
subscriptions.add_thread_global_subscription(subscriber)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(method_name, *arguments, &block)
|
35
|
+
if respond_to?(method_name)
|
36
|
+
subscriptions.public_send(method_name, *arguments, &block)
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def respond_to_missing?(method_name, _include_private)
|
43
|
+
subscriptions.respond_to?(method_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def instrument(args)
|
49
|
+
instrumentation.instrument("add.subscriptions.rails_event_store", args) do
|
50
|
+
unsubscribe = yield
|
51
|
+
->() {
|
52
|
+
instrumentation.instrument("remove.subscriptions.rails_event_store", args) do
|
53
|
+
unsubscribe.call
|
54
|
+
end
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_reader :instrumentation, :subscriptions
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Mappers
|
5
|
+
module Transformation
|
6
|
+
class PreserveTypes
|
7
|
+
def initialize(type_resolver: ->(type) { type.to_s } )
|
8
|
+
@registered_type_serializers = {}
|
9
|
+
@type_resolver = type_resolver
|
10
|
+
end
|
11
|
+
|
12
|
+
def register(type, serializer:, deserializer:)
|
13
|
+
@registered_type_serializers[@type_resolver.(type)] = {
|
14
|
+
serializer: serializer,
|
15
|
+
deserializer: deserializer
|
16
|
+
}
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def dump(record)
|
21
|
+
data = transform(record.data)
|
22
|
+
metadata = transform(record.metadata)
|
23
|
+
if (metadata.respond_to?(:[]=))
|
24
|
+
metadata[:types] = {
|
25
|
+
data: store_type(record.data),
|
26
|
+
metadata: store_type(record.metadata),
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
Record.new(
|
31
|
+
event_id: record.event_id,
|
32
|
+
event_type: record.event_type,
|
33
|
+
data: data,
|
34
|
+
metadata: metadata,
|
35
|
+
timestamp: record.timestamp,
|
36
|
+
valid_at: record.valid_at,
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def load(record)
|
41
|
+
types = record.metadata.delete(:types) rescue nil
|
42
|
+
data_types = types&.fetch(:data, nil)
|
43
|
+
metadata_types = types&.fetch(:metadata, nil)
|
44
|
+
data = data_types ? restore_type(record.data, data_types) : record.data
|
45
|
+
metadata = metadata_types ? restore_type(record.metadata, metadata_types) : record.metadata
|
46
|
+
|
47
|
+
Record.new(
|
48
|
+
event_id: record.event_id,
|
49
|
+
event_type: record.event_type,
|
50
|
+
data: data,
|
51
|
+
metadata: metadata,
|
52
|
+
timestamp: record.timestamp,
|
53
|
+
valid_at: record.valid_at,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
PASS_THROUGH = ->(v) { v }
|
59
|
+
|
60
|
+
def transform_hash(argument)
|
61
|
+
argument.each_with_object({}) do |(key, value), hash|
|
62
|
+
hash[transform(key)] = transform(value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def transform(argument)
|
67
|
+
case argument
|
68
|
+
when Hash
|
69
|
+
transform_hash(argument)
|
70
|
+
when Array
|
71
|
+
argument.map{|i| transform(i)}
|
72
|
+
else
|
73
|
+
serializer_of(argument.class).call(argument)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def store_types(argument)
|
78
|
+
argument.each_with_object({}) do |(key, value), hash|
|
79
|
+
hash[transform(key)] = [store_type(key), store_type(value)]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def store_type(argument)
|
84
|
+
case argument
|
85
|
+
when Hash
|
86
|
+
store_types(argument)
|
87
|
+
when Array
|
88
|
+
argument.map{|i| store_type(i)}
|
89
|
+
else
|
90
|
+
argument.class.name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def restore_types(argument, types)
|
95
|
+
argument.each_with_object({}) do |(key, value), hash|
|
96
|
+
key_type, value_type = types.fetch(key.to_sym)
|
97
|
+
restored_key = restore_type(key, key_type)
|
98
|
+
hash[restored_key] = restore_type(value, value_type)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def restore_type(argument, type)
|
103
|
+
case argument
|
104
|
+
when Hash
|
105
|
+
restore_types(argument, type)
|
106
|
+
when Array
|
107
|
+
argument.each_with_index.map{|a,idx| restore_type(a, type.fetch(idx))}
|
108
|
+
else
|
109
|
+
deserializer_of(type).call(argument)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def serializer_of(type)
|
114
|
+
@registered_type_serializers.dig(@type_resolver.(type), :serializer) || PASS_THROUGH
|
115
|
+
end
|
116
|
+
|
117
|
+
def deserializer_of(type)
|
118
|
+
@registered_type_serializers.dig(type, :deserializer) || PASS_THROUGH
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -17,9 +17,8 @@ module RubyEventStore
|
|
17
17
|
|
18
18
|
attr_reader :event_id, :data, :metadata, :event_type, :timestamp, :valid_at
|
19
19
|
|
20
|
-
BIG_VALUE = 0b110011100100000010010010110011101011110101010101001100111110011
|
21
20
|
def hash
|
22
|
-
[
|
21
|
+
[event_id, data, metadata, event_type, timestamp, valid_at].hash ^ self.class.hash
|
23
22
|
end
|
24
23
|
|
25
24
|
def ==(other)
|
@@ -16,9 +16,8 @@ module RubyEventStore
|
|
16
16
|
|
17
17
|
attr_reader :event_id, :data, :metadata, :event_type, :timestamp, :valid_at
|
18
18
|
|
19
|
-
BIG_VALUE = 0b110011100100000010010010110011101011110101010101001100111110111
|
20
19
|
def hash
|
21
|
-
[
|
20
|
+
[event_id, data, metadata, event_type, timestamp, valid_at].hash ^ self.class.hash
|
22
21
|
end
|
23
22
|
|
24
23
|
def ==(other)
|
@@ -1407,6 +1407,15 @@ module RubyEventStore
|
|
1407
1407
|
)
|
1408
1408
|
expect(repository.read(specification.result).count).to eq(0)
|
1409
1409
|
end
|
1410
|
+
|
1411
|
+
specify "linking empty list of commits to stream should be a no-op" do
|
1412
|
+
repository.link_to_stream(
|
1413
|
+
[],
|
1414
|
+
RubyEventStore::Stream.new("whatever-non-globa"),
|
1415
|
+
RubyEventStore::ExpectedVersion.any
|
1416
|
+
)
|
1417
|
+
expect(repository.read(specification.result).count).to eq(0)
|
1418
|
+
end
|
1410
1419
|
end
|
1411
1420
|
|
1412
1421
|
::RSpec::Matchers.define :eq_ids do |expected_ids|
|
@@ -43,7 +43,7 @@ module RubyEventStore
|
|
43
43
|
Specification.new(reader, result.dup { |r| r.stop = stop })
|
44
44
|
end
|
45
45
|
|
46
|
-
# Limits the query to events that
|
46
|
+
# Limits the query to events that occurred before given time.
|
47
47
|
# {http://railseventstore.org/docs/read/ Find out more}.
|
48
48
|
#
|
49
49
|
# @param time [Time]
|
@@ -59,7 +59,7 @@ module RubyEventStore
|
|
59
59
|
)
|
60
60
|
end
|
61
61
|
|
62
|
-
# Limits the query to events that occurred on given time
|
62
|
+
# Limits the query to events that occurred on or before given time.
|
63
63
|
# {http://railseventstore.org/docs/read/ Find out more}.
|
64
64
|
#
|
65
65
|
# @param time [Time]
|
@@ -75,7 +75,7 @@ module RubyEventStore
|
|
75
75
|
)
|
76
76
|
end
|
77
77
|
|
78
|
-
# Limits the query to events that occurred
|
78
|
+
# Limits the query to events that occurred after given time.
|
79
79
|
# {http://railseventstore.org/docs/read/ Find out more}.
|
80
80
|
#
|
81
81
|
# @param time [Time]
|
@@ -91,7 +91,7 @@ module RubyEventStore
|
|
91
91
|
)
|
92
92
|
end
|
93
93
|
|
94
|
-
# Limits the query to events that occurred on given time
|
94
|
+
# Limits the query to events that occurred on or after given time.
|
95
95
|
# {http://railseventstore.org/docs/read/ Find out more}.
|
96
96
|
#
|
97
97
|
# @param time [Time]
|
@@ -244,9 +244,6 @@ module RubyEventStore
|
|
244
244
|
other_spec.hash.eql?(hash)
|
245
245
|
end
|
246
246
|
|
247
|
-
# @private
|
248
|
-
BIG_VALUE = 0b100010010100011110111101100001011111100101001010111110101000000
|
249
|
-
|
250
247
|
# Generates a Fixnum hash value for this object. This function
|
251
248
|
# have the property that a.eql?(b) implies a.hash == b.hash.
|
252
249
|
#
|
@@ -273,7 +270,6 @@ module RubyEventStore
|
|
273
270
|
# @return [Integer]
|
274
271
|
def hash
|
275
272
|
[
|
276
|
-
self.class,
|
277
273
|
get_direction,
|
278
274
|
start,
|
279
275
|
stop,
|
@@ -288,7 +284,7 @@ module RubyEventStore
|
|
288
284
|
batch_size,
|
289
285
|
with_ids,
|
290
286
|
with_types
|
291
|
-
].hash ^
|
287
|
+
].hash ^ self.class.hash
|
292
288
|
end
|
293
289
|
|
294
290
|
private
|
@@ -13,9 +13,8 @@ module RubyEventStore
|
|
13
13
|
|
14
14
|
attr_reader :name
|
15
15
|
|
16
|
-
BIG_VALUE = 0b111111100100000010010010110011101011000101010101001100100110011
|
17
16
|
def hash
|
18
|
-
|
17
|
+
name.hash ^ self.class.hash
|
19
18
|
end
|
20
19
|
|
21
20
|
def ==(other_stream)
|
@@ -23,7 +22,5 @@ module RubyEventStore
|
|
23
22
|
end
|
24
23
|
|
25
24
|
alias_method :eql?, :==
|
26
|
-
|
27
|
-
private_constant :BIG_VALUE
|
28
25
|
end
|
29
26
|
end
|
@@ -14,16 +14,15 @@ module RubyEventStore
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def deep_transform(data, &block)
|
17
|
-
data
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
17
|
+
case data
|
18
|
+
when Hash
|
19
|
+
data.each_with_object({}) do |(key, value), hash|
|
20
|
+
hash[yield(key)] = deep_transform(value, &block)
|
21
|
+
end
|
22
|
+
when Array
|
23
|
+
data.map { |i| deep_transform(i, &block) }
|
24
|
+
else
|
25
|
+
data
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
data/lib/ruby_event_store.rb
CHANGED
@@ -27,6 +27,7 @@ require_relative "ruby_event_store/mappers/transformation/event_class_remapper"
|
|
27
27
|
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
|
+
require_relative "ruby_event_store/mappers/transformation/preserve_types"
|
30
31
|
require_relative "ruby_event_store/mappers/pipeline"
|
31
32
|
require_relative "ruby_event_store/mappers/pipeline_mapper"
|
32
33
|
require_relative "ruby_event_store/mappers/default"
|
@@ -44,3 +45,4 @@ require_relative "ruby_event_store/composed_dispatcher"
|
|
44
45
|
require_relative "ruby_event_store/version"
|
45
46
|
require_relative "ruby_event_store/instrumented_repository"
|
46
47
|
require_relative "ruby_event_store/instrumented_dispatcher"
|
48
|
+
require_relative "ruby_event_store/instrumented_subscriptions"
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/ruby_event_store/in_memory_repository.rb
|
56
56
|
- lib/ruby_event_store/instrumented_dispatcher.rb
|
57
57
|
- lib/ruby_event_store/instrumented_repository.rb
|
58
|
+
- lib/ruby_event_store/instrumented_subscriptions.rb
|
58
59
|
- lib/ruby_event_store/link_by_metadata.rb
|
59
60
|
- lib/ruby_event_store/mappers/default.rb
|
60
61
|
- lib/ruby_event_store/mappers/encryption_key.rb
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/ruby_event_store/mappers/transformation/domain_event.rb
|
70
71
|
- lib/ruby_event_store/mappers/transformation/encryption.rb
|
71
72
|
- lib/ruby_event_store/mappers/transformation/event_class_remapper.rb
|
73
|
+
- lib/ruby_event_store/mappers/transformation/preserve_types.rb
|
72
74
|
- lib/ruby_event_store/mappers/transformation/stringify_metadata_keys.rb
|
73
75
|
- lib/ruby_event_store/mappers/transformation/symbolize_metadata_keys.rb
|
74
76
|
- lib/ruby_event_store/mappers/transformation/upcast.rb
|
@@ -116,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
118
|
- !ruby/object:Gem::Version
|
117
119
|
version: '0'
|
118
120
|
requirements: []
|
119
|
-
rubygems_version: 3.3.
|
121
|
+
rubygems_version: 3.3.26
|
120
122
|
signing_key:
|
121
123
|
specification_version: 4
|
122
124
|
summary: Implementation of an event store in Ruby
|