ruby_event_store 2.18.0 → 2.19.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.
- checksums.yaml +4 -4
- data/lib/ruby_event_store/client.rb +22 -12
- data/lib/ruby_event_store/dispatcher.rb +6 -14
- data/lib/ruby_event_store/event.rb +5 -5
- data/lib/ruby_event_store/immediate_async_dispatcher.rb +6 -10
- data/lib/ruby_event_store/immediate_dispatcher.rb +17 -0
- data/lib/ruby_event_store/in_memory_repository.rb +13 -7
- data/lib/ruby_event_store/instrumented_broker.rb +52 -20
- data/lib/ruby_event_store/instrumented_dispatcher.rb +22 -2
- data/lib/ruby_event_store/instrumented_repository.rb +47 -15
- data/lib/ruby_event_store/mappers/default.rb +14 -6
- data/lib/ruby_event_store/mappers/instrumented_batch_mapper.rb +26 -4
- data/lib/ruby_event_store/mappers/instrumented_mapper.rb +41 -4
- data/lib/ruby_event_store/mappers/null_mapper.rb +4 -0
- data/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb +4 -0
- data/lib/ruby_event_store/projection.rb +87 -55
- data/lib/ruby_event_store/specification.rb +47 -31
- data/lib/ruby_event_store/specification_result.rb +23 -23
- data/lib/ruby_event_store/sync_scheduler.rb +31 -0
- data/lib/ruby_event_store/version.rb +1 -1
- data/lib/ruby_event_store.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f21bbf176c36c5948ac817d5e6cf13972d608c25eeb11d691831ba3a51f09bd
|
|
4
|
+
data.tar.gz: f9cd6d162d9927454ccd9bba582d53644a83a635c775c515283ea32654209652
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cbe530dace472f1e46a7bfe52cdfb11adb0b4f4b38e59fb448fb68d679fdd5a8cd76be0dc6fdcc29ecb6d4e316845d6022eafd4499cc303e66601c64336556a
|
|
7
|
+
data.tar.gz: b1288e6f0a95d0eb90550f089a791b6e23583f4939426bdc655e63d94814837187b95cd81860c07de666be07063667dcf1823103bbae3cbede2d6d075077ef0a
|
|
@@ -18,7 +18,7 @@ module RubyEventStore
|
|
|
18
18
|
@mapper = batch_mapper?(mapper) ? mapper : Mappers::BatchMapper.new(mapper)
|
|
19
19
|
@broker =
|
|
20
20
|
message_broker ||
|
|
21
|
-
Broker.new(subscriptions: subscriptions || Subscriptions.new, dispatcher: dispatcher ||
|
|
21
|
+
Broker.new(subscriptions: subscriptions || Subscriptions.new, dispatcher: dispatcher || SyncScheduler.new)
|
|
22
22
|
@clock = clock
|
|
23
23
|
@metadata = Concurrent::ThreadLocalVar.new
|
|
24
24
|
@correlation_id_generator = correlation_id_generator
|
|
@@ -33,7 +33,7 @@ module RubyEventStore
|
|
|
33
33
|
event_store = RubyEventStore::Client.new(
|
|
34
34
|
message_broker: RubyEventStore::Broker.new(
|
|
35
35
|
subscriptions: RubyEventStore::Subscriptions.new,
|
|
36
|
-
dispatcher: RubyEventStore::
|
|
36
|
+
dispatcher: RubyEventStore::SyncScheduler.new
|
|
37
37
|
)
|
|
38
38
|
)
|
|
39
39
|
EOW
|
|
@@ -54,7 +54,7 @@ module RubyEventStore
|
|
|
54
54
|
#
|
|
55
55
|
# @param events [Array<Event>, Event] event(s)
|
|
56
56
|
# @param stream_name [String] name of the stream for persisting events.
|
|
57
|
-
# @param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {
|
|
57
|
+
# @param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {https://railseventstore.org/docs/core-concepts/expected-version Read more}
|
|
58
58
|
# @return [self]
|
|
59
59
|
def publish(events, topic: nil, stream_name: GLOBAL_STREAM, expected_version: :any)
|
|
60
60
|
enriched_events = enrich_events_metadata(events)
|
|
@@ -98,6 +98,11 @@ module RubyEventStore
|
|
|
98
98
|
# @param expected_version (see #publish)
|
|
99
99
|
# @return [self]
|
|
100
100
|
def link(event_ids, stream_name:, expected_version: :any)
|
|
101
|
+
if event_ids.nil? || Array(event_ids).any?(&:nil?)
|
|
102
|
+
warn <<~EOW
|
|
103
|
+
Passing `nil` to link is deprecated and will raise ArgumentError in RubyEventStore 3.0.
|
|
104
|
+
EOW
|
|
105
|
+
end
|
|
101
106
|
@repository.link_to_stream(Array(event_ids), Stream.new(stream_name), ExpectedVersion.new(expected_version))
|
|
102
107
|
self
|
|
103
108
|
end
|
|
@@ -114,7 +119,7 @@ module RubyEventStore
|
|
|
114
119
|
end
|
|
115
120
|
|
|
116
121
|
# Starts building a query specification for reading events.
|
|
117
|
-
# {
|
|
122
|
+
# {https://railseventstore.org/docs/core-concepts/read More info.}
|
|
118
123
|
#
|
|
119
124
|
# @return [Specification]
|
|
120
125
|
def read
|
|
@@ -222,7 +227,7 @@ module RubyEventStore
|
|
|
222
227
|
# will be called for all published events.
|
|
223
228
|
# The subscription is active only during the invocation
|
|
224
229
|
# of the block of code provided to {Client#within}.
|
|
225
|
-
# {
|
|
230
|
+
# {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
|
|
226
231
|
#
|
|
227
232
|
# @param handlers [Object, Class] handlers passed as objects or classes
|
|
228
233
|
# @param handler2 [Proc] handler passed as proc
|
|
@@ -237,7 +242,7 @@ module RubyEventStore
|
|
|
237
242
|
# will be called for published events of provided type.
|
|
238
243
|
# The subscription is active only during the invocation
|
|
239
244
|
# of the block of code provided to {Client#within}.
|
|
240
|
-
# {
|
|
245
|
+
# {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
|
|
241
246
|
#
|
|
242
247
|
# @overload subscribe(handler, to:)
|
|
243
248
|
# @param handler [Object, Class] handler passed as objects or classes
|
|
@@ -255,7 +260,7 @@ module RubyEventStore
|
|
|
255
260
|
|
|
256
261
|
# Invokes the block of code provided to {Client#within}
|
|
257
262
|
# and then unsubscribes temporary handlers.
|
|
258
|
-
# {
|
|
263
|
+
# {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
|
|
259
264
|
#
|
|
260
265
|
# @return [Object] value returned by the invoked block of code
|
|
261
266
|
def call
|
|
@@ -280,7 +285,7 @@ module RubyEventStore
|
|
|
280
285
|
end
|
|
281
286
|
|
|
282
287
|
# Use for starting temporary subscriptions.
|
|
283
|
-
# {
|
|
288
|
+
# {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more}
|
|
284
289
|
#
|
|
285
290
|
# @param block [Proc] block of code during which the temporary subscriptions will be active
|
|
286
291
|
# @return [Within] builder object which collects temporary subscriptions
|
|
@@ -290,7 +295,7 @@ module RubyEventStore
|
|
|
290
295
|
end
|
|
291
296
|
|
|
292
297
|
# Set additional metadata for all events published within the provided block
|
|
293
|
-
# {
|
|
298
|
+
# {https://railseventstore.org/docs/core-concepts/request-metadata#passing-your-own-metadata-using-with_metadata Read more}
|
|
294
299
|
#
|
|
295
300
|
# @param metadata [Hash] metadata to set for events
|
|
296
301
|
# @param block [Proc] block of code during which the metadata will be added
|
|
@@ -304,7 +309,7 @@ module RubyEventStore
|
|
|
304
309
|
end
|
|
305
310
|
|
|
306
311
|
# Deserialize event which was serialized for async event handlers
|
|
307
|
-
# {
|
|
312
|
+
# {https://railseventstore.org/docs/core-concepts/subscribe#async-handlers Read more}
|
|
308
313
|
#
|
|
309
314
|
# @return [Event] deserialized event
|
|
310
315
|
def deserialize(serializer:, event_type:, event_id:, data:, metadata:, timestamp: nil, valid_at: nil)
|
|
@@ -325,7 +330,7 @@ module RubyEventStore
|
|
|
325
330
|
end
|
|
326
331
|
|
|
327
332
|
# Read additional metadata which will be added for published events
|
|
328
|
-
# {
|
|
333
|
+
# {https://railseventstore.org/docs/core-concepts/request-metadata#passing-your-own-metadata-using-with_metadata Read more}
|
|
329
334
|
#
|
|
330
335
|
# @return [Hash]
|
|
331
336
|
def metadata
|
|
@@ -337,7 +342,7 @@ module RubyEventStore
|
|
|
337
342
|
# Does not notify any subscribed handlers.
|
|
338
343
|
# Does not enrich with additional current metadata.
|
|
339
344
|
# Does not allow changing which streams these events are in.
|
|
340
|
-
# {
|
|
345
|
+
# {https://railseventstore.org/docs/advanced-topics/migrating-existing-events Read more}
|
|
341
346
|
#
|
|
342
347
|
# @example Add data and metadata to existing events
|
|
343
348
|
#
|
|
@@ -380,6 +385,11 @@ module RubyEventStore
|
|
|
380
385
|
end
|
|
381
386
|
|
|
382
387
|
def enrich_events_metadata(events)
|
|
388
|
+
if events.nil? || Array(events).any?(&:nil?)
|
|
389
|
+
warn <<~EOW
|
|
390
|
+
Passing `nil` to publish/append is deprecated and will raise ArgumentError in RubyEventStore 3.0.
|
|
391
|
+
EOW
|
|
392
|
+
end
|
|
383
393
|
events = Array(events)
|
|
384
394
|
events.each { |event| enrich_event_metadata(event) }
|
|
385
395
|
end
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RubyEventStore
|
|
4
|
-
class Dispatcher
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def verify(subscriber)
|
|
11
|
-
begin
|
|
12
|
-
subscriber_instance = Class === subscriber ? subscriber.new : subscriber
|
|
13
|
-
rescue ArgumentError
|
|
14
|
-
false
|
|
15
|
-
else
|
|
16
|
-
subscriber_instance.respond_to?(:call)
|
|
17
|
-
end
|
|
4
|
+
class Dispatcher < SyncScheduler
|
|
5
|
+
def initialize
|
|
6
|
+
warn <<~EOW
|
|
7
|
+
DEPRECATION WARNING: `RubyEventStore::Dispatcher` is deprecated and will be removed in the next major release.
|
|
8
|
+
Use `RubyEventStore::SyncScheduler` instead.
|
|
9
|
+
EOW
|
|
18
10
|
end
|
|
19
11
|
end
|
|
20
12
|
end
|
|
@@ -78,7 +78,7 @@ module RubyEventStore
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# Reads correlation_id from metadata.
|
|
81
|
-
# {
|
|
81
|
+
# {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
|
|
82
82
|
#
|
|
83
83
|
# @return [String, nil]
|
|
84
84
|
def correlation_id
|
|
@@ -86,7 +86,7 @@ module RubyEventStore
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Sets correlation_id in metadata.
|
|
89
|
-
# {
|
|
89
|
+
# {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
|
|
90
90
|
#
|
|
91
91
|
# @param val [String]
|
|
92
92
|
# @return [String]
|
|
@@ -95,7 +95,7 @@ module RubyEventStore
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
# Reads causation_id from metadata.
|
|
98
|
-
# {
|
|
98
|
+
# {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
|
|
99
99
|
#
|
|
100
100
|
# @return [String, nil]
|
|
101
101
|
def causation_id
|
|
@@ -103,7 +103,7 @@ module RubyEventStore
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
# Sets causation_id= in metadata.
|
|
106
|
-
# {
|
|
106
|
+
# {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
|
|
107
107
|
#
|
|
108
108
|
# @param val [String]
|
|
109
109
|
# @return [String]
|
|
@@ -113,7 +113,7 @@ module RubyEventStore
|
|
|
113
113
|
|
|
114
114
|
# Sets correlation_id and causation_id in metadata based
|
|
115
115
|
# on correlation_id and message_id of the provided message.
|
|
116
|
-
# {
|
|
116
|
+
# {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
|
|
117
117
|
#
|
|
118
118
|
# @param other_message [Event, command] message to correlate with. Most likely an event or a command. Must respond to correlation_id and message_id.
|
|
119
119
|
# @return [String] set causation_id
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RubyEventStore
|
|
4
|
-
class ImmediateAsyncDispatcher
|
|
4
|
+
class ImmediateAsyncDispatcher < ImmediateDispatcher
|
|
5
5
|
def initialize(scheduler:)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def verify(subscriber)
|
|
14
|
-
@scheduler.verify(subscriber)
|
|
6
|
+
warn <<~EOW
|
|
7
|
+
DEPRECATION WARNING: `RubyEventStore::ImmediateAsyncDispatcher` is deprecated and will be removed in the next major release.
|
|
8
|
+
Use `RubyEventStore::ImmediateDispatcher` instead.
|
|
9
|
+
EOW
|
|
10
|
+
super
|
|
15
11
|
end
|
|
16
12
|
end
|
|
17
13
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RubyEventStore
|
|
4
|
+
class ImmediateDispatcher
|
|
5
|
+
def initialize(scheduler:)
|
|
6
|
+
@scheduler = scheduler
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call(subscriber, _, record)
|
|
10
|
+
@scheduler.call(subscriber, record)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def verify(subscriber)
|
|
14
|
+
@scheduler.verify(subscriber)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -8,7 +8,7 @@ module RubyEventStore
|
|
|
8
8
|
Mixing expected version :any and specific position (or :auto) is unsupported.
|
|
9
9
|
|
|
10
10
|
Read more about expected versions here:
|
|
11
|
-
https://railseventstore.org/docs/
|
|
11
|
+
https://railseventstore.org/docs/core-concepts/expected-version
|
|
12
12
|
EOS
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -100,7 +100,7 @@ module RubyEventStore
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
def count(spec)
|
|
103
|
-
read_scope(spec).
|
|
103
|
+
read_scope(spec).size # mutant:disable
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def update_messages(records)
|
|
@@ -234,12 +234,18 @@ module RubyEventStore
|
|
|
234
234
|
end
|
|
235
235
|
|
|
236
236
|
def ensure_supported_any_usage(resolved_version, stream)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
237
|
+
stream_positions = streams.fetch(stream.name, Array.new).map(&:position)
|
|
238
|
+
violation =
|
|
239
|
+
(resolved_version.nil? && !stream_positions.compact.empty?) ||
|
|
240
|
+
(!resolved_version.nil? && stream_positions.include?(nil))
|
|
241
|
+
|
|
242
|
+
if violation
|
|
243
|
+
if @ensure_supported_any_usage
|
|
244
|
+
raise UnsupportedVersionAnyUsage
|
|
241
245
|
else
|
|
242
|
-
|
|
246
|
+
warn <<~EOW
|
|
247
|
+
Mixing expected version :any and specific position (or :auto) is deprecated and will raise UnsupportedVersionAnyUsage in RubyEventStore 3.0.
|
|
248
|
+
EOW
|
|
243
249
|
end
|
|
244
250
|
end
|
|
245
251
|
end
|
|
@@ -2,55 +2,75 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyEventStore
|
|
4
4
|
class InstrumentedBroker
|
|
5
|
+
DEPRECATION_MESSAGE = <<~EOW
|
|
6
|
+
Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
|
|
7
|
+
Use *.ruby_event_store instead.
|
|
8
|
+
EOW
|
|
9
|
+
private_constant :DEPRECATION_MESSAGE
|
|
10
|
+
|
|
5
11
|
def initialize(broker, instrumentation)
|
|
6
12
|
@broker = broker
|
|
7
13
|
@instrumentation = instrumentation
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def call(topic, event, record)
|
|
11
|
-
instrumentation.instrument("call.broker.
|
|
12
|
-
|
|
13
|
-
broker.call
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
instrumentation.instrument("call.broker.ruby_event_store", topic: topic, event: event, record: record) do
|
|
18
|
+
deprecated_instrument("call.broker.rails_event_store", topic: topic, event: event, record: record) do
|
|
19
|
+
if broker.public_method(:call).arity == 3
|
|
20
|
+
broker.call(topic, event, record)
|
|
21
|
+
else
|
|
22
|
+
warn <<~EOW
|
|
23
|
+
Message broker shall support topics.
|
|
24
|
+
Topic WILL BE IGNORED in the current broker.
|
|
25
|
+
Modify the broker implementation to pass topic as an argument to broker.call method.
|
|
26
|
+
EOW
|
|
27
|
+
broker.call(event, record)
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
|
24
32
|
|
|
25
33
|
def add_subscription(subscriber, topics)
|
|
26
|
-
instrumentation.instrument("add_subscription.broker.
|
|
27
|
-
broker.
|
|
34
|
+
instrumentation.instrument("add_subscription.broker.ruby_event_store", subscriber: subscriber, topics: topics) do
|
|
35
|
+
deprecated_instrument("add_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
|
|
36
|
+
broker.add_subscription(subscriber, topics)
|
|
37
|
+
end
|
|
28
38
|
end
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
def add_global_subscription(subscriber)
|
|
32
|
-
instrumentation.instrument("add_global_subscription.broker.
|
|
33
|
-
broker.
|
|
42
|
+
instrumentation.instrument("add_global_subscription.broker.ruby_event_store", subscriber: subscriber) do
|
|
43
|
+
deprecated_instrument("add_global_subscription.broker.rails_event_store", subscriber: subscriber) do
|
|
44
|
+
broker.add_global_subscription(subscriber)
|
|
45
|
+
end
|
|
34
46
|
end
|
|
35
47
|
end
|
|
36
48
|
|
|
37
49
|
def add_thread_subscription(subscriber, topics)
|
|
38
50
|
instrumentation.instrument(
|
|
39
|
-
"add_thread_subscription.broker.
|
|
51
|
+
"add_thread_subscription.broker.ruby_event_store",
|
|
40
52
|
subscriber: subscriber,
|
|
41
53
|
topics: topics,
|
|
42
|
-
)
|
|
54
|
+
) do
|
|
55
|
+
deprecated_instrument("add_thread_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
|
|
56
|
+
broker.add_thread_subscription(subscriber, topics)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
43
59
|
end
|
|
44
60
|
|
|
45
61
|
def add_thread_global_subscription(subscriber)
|
|
46
|
-
instrumentation.instrument("add_thread_global_subscription.broker.
|
|
47
|
-
broker.
|
|
62
|
+
instrumentation.instrument("add_thread_global_subscription.broker.ruby_event_store", subscriber: subscriber) do
|
|
63
|
+
deprecated_instrument("add_thread_global_subscription.broker.rails_event_store", subscriber: subscriber) do
|
|
64
|
+
broker.add_thread_global_subscription(subscriber)
|
|
65
|
+
end
|
|
48
66
|
end
|
|
49
67
|
end
|
|
50
68
|
|
|
51
69
|
def all_subscriptions_for(topic)
|
|
52
|
-
instrumentation.instrument("all_subscriptions_for.broker.
|
|
53
|
-
broker.
|
|
70
|
+
instrumentation.instrument("all_subscriptions_for.broker.ruby_event_store", topic: topic) do
|
|
71
|
+
deprecated_instrument("all_subscriptions_for.broker.rails_event_store", topic: topic) do
|
|
72
|
+
broker.all_subscriptions_for(topic)
|
|
73
|
+
end
|
|
54
74
|
end
|
|
55
75
|
end
|
|
56
76
|
|
|
@@ -69,5 +89,17 @@ module RubyEventStore
|
|
|
69
89
|
private
|
|
70
90
|
|
|
71
91
|
attr_reader :instrumentation, :broker
|
|
92
|
+
|
|
93
|
+
def deprecated_instrument(name, payload, &block)
|
|
94
|
+
canonical_name = name.sub("rails_event_store", "ruby_event_store")
|
|
95
|
+
old_listeners = instrumentation.notifier.all_listeners_for(name)
|
|
96
|
+
new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
|
|
97
|
+
if (old_listeners - new_listeners).any?
|
|
98
|
+
warn DEPRECATION_MESSAGE
|
|
99
|
+
instrumentation.instrument(name, payload, &block)
|
|
100
|
+
else
|
|
101
|
+
yield
|
|
102
|
+
end
|
|
103
|
+
end
|
|
72
104
|
end
|
|
73
105
|
end
|
|
@@ -2,14 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyEventStore
|
|
4
4
|
class InstrumentedDispatcher
|
|
5
|
+
DEPRECATION_MESSAGE = <<~EOW
|
|
6
|
+
Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
|
|
7
|
+
Use *.ruby_event_store instead.
|
|
8
|
+
EOW
|
|
9
|
+
private_constant :DEPRECATION_MESSAGE
|
|
10
|
+
|
|
5
11
|
def initialize(dispatcher, instrumentation)
|
|
6
12
|
@dispatcher = dispatcher
|
|
7
13
|
@instrumentation = instrumentation
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def call(subscriber, event, record)
|
|
11
|
-
instrumentation.instrument("call.dispatcher.
|
|
12
|
-
dispatcher.
|
|
17
|
+
instrumentation.instrument("call.dispatcher.ruby_event_store", event: event, subscriber: subscriber) do
|
|
18
|
+
deprecated_instrument("call.dispatcher.rails_event_store", event: event, subscriber: subscriber) do
|
|
19
|
+
dispatcher.call(subscriber, event, record)
|
|
20
|
+
end
|
|
13
21
|
end
|
|
14
22
|
end
|
|
15
23
|
|
|
@@ -28,5 +36,17 @@ module RubyEventStore
|
|
|
28
36
|
private
|
|
29
37
|
|
|
30
38
|
attr_reader :instrumentation, :dispatcher
|
|
39
|
+
|
|
40
|
+
def deprecated_instrument(name, payload, &block)
|
|
41
|
+
canonical_name = name.sub("rails_event_store", "ruby_event_store")
|
|
42
|
+
old_listeners = instrumentation.notifier.all_listeners_for(name)
|
|
43
|
+
new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
|
|
44
|
+
if (old_listeners - new_listeners).any?
|
|
45
|
+
warn DEPRECATION_MESSAGE
|
|
46
|
+
instrumentation.instrument(name, payload, &block)
|
|
47
|
+
else
|
|
48
|
+
yield
|
|
49
|
+
end
|
|
50
|
+
end
|
|
31
51
|
end
|
|
32
52
|
end
|
|
@@ -2,50 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyEventStore
|
|
4
4
|
class InstrumentedRepository
|
|
5
|
+
DEPRECATION_MESSAGE = <<~EOW
|
|
6
|
+
Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
|
|
7
|
+
Use *.ruby_event_store instead.
|
|
8
|
+
EOW
|
|
9
|
+
private_constant :DEPRECATION_MESSAGE
|
|
10
|
+
|
|
5
11
|
def initialize(repository, instrumentation)
|
|
6
12
|
@repository = repository
|
|
7
13
|
@instrumentation = instrumentation
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
def append_to_stream(records, stream, expected_version)
|
|
11
|
-
instrumentation.instrument("append_to_stream.repository.
|
|
12
|
-
repository.
|
|
17
|
+
instrumentation.instrument("append_to_stream.repository.ruby_event_store", records: records, events: records, stream: stream) do
|
|
18
|
+
deprecated_instrument("append_to_stream.repository.rails_event_store", { records: records, events: records, stream: stream }) do
|
|
19
|
+
repository.append_to_stream(records, stream, expected_version)
|
|
20
|
+
end
|
|
13
21
|
end
|
|
14
22
|
end
|
|
15
23
|
|
|
16
24
|
def link_to_stream(event_ids, stream, expected_version)
|
|
17
|
-
instrumentation.instrument("link_to_stream.repository.
|
|
18
|
-
repository.
|
|
25
|
+
instrumentation.instrument("link_to_stream.repository.ruby_event_store", event_ids: event_ids, stream: stream) do
|
|
26
|
+
deprecated_instrument("link_to_stream.repository.rails_event_store", event_ids: event_ids, stream: stream) do
|
|
27
|
+
repository.link_to_stream(event_ids, stream, expected_version)
|
|
28
|
+
end
|
|
19
29
|
end
|
|
20
30
|
end
|
|
21
31
|
|
|
22
32
|
def delete_stream(stream)
|
|
23
|
-
instrumentation.instrument("delete_stream.repository.
|
|
24
|
-
repository.
|
|
33
|
+
instrumentation.instrument("delete_stream.repository.ruby_event_store", stream: stream) do
|
|
34
|
+
deprecated_instrument("delete_stream.repository.rails_event_store", stream: stream) do
|
|
35
|
+
repository.delete_stream(stream)
|
|
36
|
+
end
|
|
25
37
|
end
|
|
26
38
|
end
|
|
27
39
|
|
|
28
40
|
def read(specification)
|
|
29
|
-
instrumentation.instrument("read.repository.
|
|
30
|
-
repository.
|
|
41
|
+
instrumentation.instrument("read.repository.ruby_event_store", specification: specification) do
|
|
42
|
+
deprecated_instrument("read.repository.rails_event_store", specification: specification) do
|
|
43
|
+
repository.read(specification)
|
|
44
|
+
end
|
|
31
45
|
end
|
|
32
46
|
end
|
|
33
47
|
|
|
34
48
|
def count(specification)
|
|
35
|
-
instrumentation.instrument("count.repository.
|
|
36
|
-
repository.
|
|
49
|
+
instrumentation.instrument("count.repository.ruby_event_store", specification: specification) do
|
|
50
|
+
deprecated_instrument("count.repository.rails_event_store", specification: specification) do
|
|
51
|
+
repository.count(specification)
|
|
52
|
+
end
|
|
37
53
|
end
|
|
38
54
|
end
|
|
39
55
|
|
|
40
|
-
def update_messages(
|
|
41
|
-
instrumentation.instrument("update_messages.repository.
|
|
42
|
-
repository.
|
|
56
|
+
def update_messages(records)
|
|
57
|
+
instrumentation.instrument("update_messages.repository.ruby_event_store", records: records, messages: records) do
|
|
58
|
+
deprecated_instrument("update_messages.repository.rails_event_store", { records: records, messages: records }) do
|
|
59
|
+
repository.update_messages(records)
|
|
60
|
+
end
|
|
43
61
|
end
|
|
44
62
|
end
|
|
45
63
|
|
|
46
64
|
def streams_of(event_id)
|
|
47
|
-
instrumentation.instrument("streams_of.repository.
|
|
48
|
-
repository.
|
|
65
|
+
instrumentation.instrument("streams_of.repository.ruby_event_store", event_id: event_id) do
|
|
66
|
+
deprecated_instrument("streams_of.repository.rails_event_store", event_id: event_id) do
|
|
67
|
+
repository.streams_of(event_id)
|
|
68
|
+
end
|
|
49
69
|
end
|
|
50
70
|
end
|
|
51
71
|
|
|
@@ -64,5 +84,17 @@ module RubyEventStore
|
|
|
64
84
|
private
|
|
65
85
|
|
|
66
86
|
attr_reader :repository, :instrumentation
|
|
87
|
+
|
|
88
|
+
def deprecated_instrument(name, payload, &block)
|
|
89
|
+
canonical_name = name.sub("rails_event_store", "ruby_event_store")
|
|
90
|
+
old_listeners = instrumentation.notifier.all_listeners_for(name)
|
|
91
|
+
new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
|
|
92
|
+
if (old_listeners - new_listeners).any?
|
|
93
|
+
warn DEPRECATION_MESSAGE
|
|
94
|
+
instrumentation.instrument(name, payload, &block)
|
|
95
|
+
else
|
|
96
|
+
yield
|
|
97
|
+
end
|
|
98
|
+
end
|
|
67
99
|
end
|
|
68
100
|
end
|
|
@@ -4,12 +4,20 @@ module RubyEventStore
|
|
|
4
4
|
module Mappers
|
|
5
5
|
class Default < PipelineMapper
|
|
6
6
|
def initialize(events_class_remapping: {})
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Transformation::
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
if events_class_remapping.any?
|
|
8
|
+
warn <<~EOW
|
|
9
|
+
DEPRECATION WARNING: `events_class_remapping` option in `RubyEventStore::Mappers::Default` is deprecated and will be removed in the next major release.
|
|
10
|
+
Use `RubyEventStore::Mappers::Transformation::Upcast` instead.
|
|
11
|
+
EOW
|
|
12
|
+
super(
|
|
13
|
+
Pipeline.new(
|
|
14
|
+
Transformation::EventClassRemapper.new(events_class_remapping),
|
|
15
|
+
Transformation::SymbolizeMetadataKeys.new,
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
else
|
|
19
|
+
super(Pipeline.new(Transformation::SymbolizeMetadataKeys.new))
|
|
20
|
+
end
|
|
13
21
|
end
|
|
14
22
|
end
|
|
15
23
|
end
|
|
@@ -3,26 +3,48 @@
|
|
|
3
3
|
module RubyEventStore
|
|
4
4
|
module Mappers
|
|
5
5
|
class InstrumentedBatchMapper
|
|
6
|
+
DEPRECATION_MESSAGE = <<~EOW
|
|
7
|
+
Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
|
|
8
|
+
Use *.ruby_event_store instead.
|
|
9
|
+
EOW
|
|
10
|
+
private_constant :DEPRECATION_MESSAGE
|
|
11
|
+
|
|
6
12
|
def initialize(mapper, instrumentation)
|
|
7
13
|
@mapper = mapper
|
|
8
14
|
@instrumentation = instrumentation
|
|
9
15
|
end
|
|
10
16
|
|
|
11
17
|
def events_to_records(events)
|
|
12
|
-
instrumentation.instrument("events_to_records.mapper.
|
|
13
|
-
mapper.
|
|
18
|
+
instrumentation.instrument("events_to_records.mapper.ruby_event_store", domain_events: events) do
|
|
19
|
+
deprecated_instrument("events_to_records.mapper.rails_event_store", domain_events: events) do
|
|
20
|
+
mapper.events_to_records(events)
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
end
|
|
16
24
|
|
|
17
25
|
def records_to_events(records)
|
|
18
|
-
instrumentation.instrument("records_to_events.mapper.
|
|
19
|
-
mapper.
|
|
26
|
+
instrumentation.instrument("records_to_events.mapper.ruby_event_store", records: records) do
|
|
27
|
+
deprecated_instrument("records_to_events.mapper.rails_event_store", records: records) do
|
|
28
|
+
mapper.records_to_events(records)
|
|
29
|
+
end
|
|
20
30
|
end
|
|
21
31
|
end
|
|
22
32
|
|
|
23
33
|
private
|
|
24
34
|
|
|
25
35
|
attr_reader :instrumentation, :mapper
|
|
36
|
+
|
|
37
|
+
def deprecated_instrument(name, payload, &block)
|
|
38
|
+
canonical_name = name.sub("rails_event_store", "ruby_event_store")
|
|
39
|
+
old_listeners = instrumentation.notifier.all_listeners_for(name)
|
|
40
|
+
new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
|
|
41
|
+
if (old_listeners - new_listeners).any?
|
|
42
|
+
warn DEPRECATION_MESSAGE
|
|
43
|
+
instrumentation.instrument(name, payload, &block)
|
|
44
|
+
else
|
|
45
|
+
yield
|
|
46
|
+
end
|
|
47
|
+
end
|
|
26
48
|
end
|
|
27
49
|
end
|
|
28
50
|
end
|