ruby_event_store 0.32.0 → 0.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +0 -4
- data/lib/ruby_event_store/client.rb +11 -49
- data/lib/ruby_event_store/in_memory_repository.rb +5 -4
- data/lib/ruby_event_store/instrumented_repository.rb +0 -6
- data/lib/ruby_event_store/spec/event_repository_lint.rb +22 -19
- data/lib/ruby_event_store/specification.rb +40 -0
- data/lib/ruby_event_store/specification_result.rb +22 -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: 72b0e4a52d4e09c87ef8b190fd2e310c306469d053b517c3d93facf2fee6a918
|
4
|
+
data.tar.gz: ff0344153ae4e205e709da00b703b3a85605ac0c4c3aafb5b20439adce26a60e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd120b03290fa27864af3ab4aa7d07cbda4bf1786beb7523103e67d04d02ec2c3fdeb5af6fea9df304a296a658cff944aefd91790ea21839cbc213a53313b60
|
7
|
+
data.tar.gz: 710cba6e537aa3378ad677d72d6f170a91fb2c617e8bdc583aa35f03ebe78d202f0c4c40b48e6a3c88728bbcefc422a7414335d8205c6813ebd87b86b12fb892
|
data/Makefile
CHANGED
@@ -9,10 +9,6 @@ IGNORE = RubyEventStore::InMemoryRepository\#append_with_synchronize \
|
|
9
9
|
RubyEventStore::Client::Within\#add_thread_global_subscribers \
|
10
10
|
RubyEventStore::DeprecatedReadAPIRunner* \
|
11
11
|
RubyEventStore::DeprecatedReadAPIRewriter* \
|
12
|
-
RubyEventStore::Client\#publish_event \
|
13
|
-
RubyEventStore::Client\#publish_events \
|
14
|
-
RubyEventStore::Client\#link_to_stream \
|
15
|
-
RubyEventStore::Client\#append_to_stream \
|
16
12
|
RubyEventStore::AsyncDispatcher* \
|
17
13
|
RubyEventStore::AsyncProxyStrategy::Inline* \
|
18
14
|
RubyEventStore::SpecificationResult\#count \
|
@@ -37,36 +37,6 @@ module RubyEventStore
|
|
37
37
|
self
|
38
38
|
end
|
39
39
|
|
40
|
-
# @deprecated Use {#publish} instead
|
41
|
-
def publish_events(events, stream_name: GLOBAL_STREAM, expected_version: :any)
|
42
|
-
warn <<~EOW
|
43
|
-
RubyEventStore::Client#publish_events has been deprecated.
|
44
|
-
|
45
|
-
Use RubyEventStore::Client#publish instead
|
46
|
-
EOW
|
47
|
-
publish(events, stream_name: stream_name, expected_version: expected_version)
|
48
|
-
end
|
49
|
-
|
50
|
-
# @deprecated Use {#publish} instead
|
51
|
-
def publish_event(event, stream_name: GLOBAL_STREAM, expected_version: :any)
|
52
|
-
warn <<~EOW
|
53
|
-
RubyEventStore::Client#publish_event has been deprecated.
|
54
|
-
|
55
|
-
Use RubyEventStore::Client#publish instead
|
56
|
-
EOW
|
57
|
-
publish(event, stream_name: stream_name, expected_version: expected_version)
|
58
|
-
end
|
59
|
-
|
60
|
-
# @deprecated Use {#append} instead
|
61
|
-
def append_to_stream(events, stream_name: GLOBAL_STREAM, expected_version: :any)
|
62
|
-
warn <<~EOW
|
63
|
-
RubyEventStore::Client#append_to_stream has been deprecated.
|
64
|
-
|
65
|
-
Use RubyEventStore::Client#append instead
|
66
|
-
EOW
|
67
|
-
append(events, stream_name: stream_name, expected_version: expected_version)
|
68
|
-
end
|
69
|
-
|
70
40
|
# Persists new event(s) without notifying any subscribed handlers
|
71
41
|
#
|
72
42
|
# @param (see #publish)
|
@@ -89,16 +59,6 @@ module RubyEventStore
|
|
89
59
|
self
|
90
60
|
end
|
91
61
|
|
92
|
-
# @deprecated Use {#link} instead
|
93
|
-
def link_to_stream(event_ids, stream_name:, expected_version: :any)
|
94
|
-
warn <<~EOW
|
95
|
-
RubyEventStore::Client#link_to_stream has been deprecated.
|
96
|
-
|
97
|
-
Use RubyEventStore::Client#link instead
|
98
|
-
EOW
|
99
|
-
link(event_ids, stream_name: stream_name, expected_version: expected_version)
|
100
|
-
end
|
101
|
-
|
102
62
|
# Deletes a stream.
|
103
63
|
# All events from the stream remain intact but they are no
|
104
64
|
# longer linked to the stream.
|
@@ -110,12 +70,14 @@ module RubyEventStore
|
|
110
70
|
self
|
111
71
|
end
|
112
72
|
|
113
|
-
#
|
114
|
-
#
|
115
|
-
# @param event_id [String] event id
|
116
|
-
# @return [Event, Proto]
|
73
|
+
# @deprecated Use {#read.event!(event_id)} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.33.0 More info}
|
117
74
|
def read_event(event_id)
|
118
|
-
|
75
|
+
warn <<~EOW
|
76
|
+
RubyEventStore::Client#read_event(event_id) has been deprecated.
|
77
|
+
Use `client.read.event!(event_id)` instead. Also available without
|
78
|
+
bang - return nil when no event is found.
|
79
|
+
EOW
|
80
|
+
read.event!(event_id)
|
119
81
|
end
|
120
82
|
|
121
83
|
# Starts building a query specification for reading events.
|
@@ -320,6 +282,10 @@ module RubyEventStore
|
|
320
282
|
self
|
321
283
|
end
|
322
284
|
|
285
|
+
def inspect
|
286
|
+
"#<#{self.class}:0x#{__id__.to_s(16)}>"
|
287
|
+
end
|
288
|
+
|
323
289
|
EMPTY_HASH = {}.freeze
|
324
290
|
private_constant :EMPTY_HASH
|
325
291
|
|
@@ -331,10 +297,6 @@ module RubyEventStore
|
|
331
297
|
end
|
332
298
|
end
|
333
299
|
|
334
|
-
def deserialize_event(sev)
|
335
|
-
mapper.serialized_record_to_event(sev)
|
336
|
-
end
|
337
|
-
|
338
300
|
def normalize_to_array(events)
|
339
301
|
return *events
|
340
302
|
end
|
@@ -31,12 +31,9 @@ module RubyEventStore
|
|
31
31
|
stream_of(stream.name).last
|
32
32
|
end
|
33
33
|
|
34
|
-
def read_event(event_id)
|
35
|
-
global.find {|e| event_id.eql?(e.event_id)} or raise EventNotFound.new(event_id)
|
36
|
-
end
|
37
|
-
|
38
34
|
def read(spec)
|
39
35
|
events = spec.stream.global? ? global : stream_of(spec.stream.name)
|
36
|
+
events = events.select{|e| spec.with_ids.any?{|x| x.eql?(e.event_id)}} if spec.with_ids?
|
40
37
|
events = events.reverse if spec.backward?
|
41
38
|
events = events.drop(index_of(events, spec.start) + 1) unless spec.head?
|
42
39
|
events = events[0...spec.limit] if spec.limit?
|
@@ -71,6 +68,10 @@ module RubyEventStore
|
|
71
68
|
|
72
69
|
private
|
73
70
|
|
71
|
+
def read_event(event_id)
|
72
|
+
global.find {|e| event_id.eql?(e.event_id)} or raise EventNotFound.new(event_id)
|
73
|
+
end
|
74
|
+
|
74
75
|
def stream_of(name)
|
75
76
|
streams.fetch(name, Array.new)
|
76
77
|
end
|
@@ -31,12 +31,6 @@ module RubyEventStore
|
|
31
31
|
repository.last_stream_event(stream)
|
32
32
|
end
|
33
33
|
|
34
|
-
def read_event(event_id)
|
35
|
-
instrumentation.instrument("read_event.repository.rails_event_store", event_id: event_id) do
|
36
|
-
repository.read_event(event_id)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
34
|
def read(specification)
|
41
35
|
instrumentation.instrument("read.repository.rails_event_store", specification: specification) do
|
42
36
|
repository.read(specification)
|
@@ -953,25 +953,6 @@ module RubyEventStore
|
|
953
953
|
expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
|
954
954
|
end
|
955
955
|
|
956
|
-
specify 'reading particular event' do
|
957
|
-
test_event = SRecord.new(event_id: "941cd8f5-b3f9-47af-b4e4-07f8cea37467")
|
958
|
-
repository.
|
959
|
-
append_to_stream(SRecord.new, stream_test, version_none).
|
960
|
-
append_to_stream(test_event, stream_test, version_0)
|
961
|
-
|
962
|
-
expect(repository.read_event("941cd8f5-b3f9-47af-b4e4-07f8cea37467")).to eq(test_event)
|
963
|
-
end
|
964
|
-
|
965
|
-
specify 'reading non-existent event' do
|
966
|
-
expect do
|
967
|
-
repository.read_event('72922e65-1b32-4e97-8023-03ae81dd3a27')
|
968
|
-
end.to raise_error do |err|
|
969
|
-
expect(err).to be_a(EventNotFound)
|
970
|
-
expect(err.event_id).to eq('72922e65-1b32-4e97-8023-03ae81dd3a27')
|
971
|
-
expect(err.message).to eq('Event not found: 72922e65-1b32-4e97-8023-03ae81dd3a27')
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
956
|
specify 'linking non-existent event' do
|
976
957
|
skip unless test_link_events_to_stream
|
977
958
|
expect do
|
@@ -1192,5 +1173,27 @@ module RubyEventStore
|
|
1192
1173
|
expect(repository.streams_of(event_3.event_id)).to eq [stream_b]
|
1193
1174
|
expect(repository.streams_of(event_4.event_id)).to eq []
|
1194
1175
|
end
|
1176
|
+
|
1177
|
+
specify do
|
1178
|
+
e1 = SRecord.new(event_id: '8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea')
|
1179
|
+
e2 = SRecord.new(event_id: '8cee1139-4f96-483a-a175-2b947283c3c7')
|
1180
|
+
e3 = SRecord.new(event_id: 'd345f86d-b903-4d78-803f-38990c078d9e')
|
1181
|
+
stream = Stream.new('Stream A')
|
1182
|
+
repository.append_to_stream([e1, e2, e3], stream, version_any)
|
1183
|
+
|
1184
|
+
expect(repository.read(specification.with_id([
|
1185
|
+
'8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea'
|
1186
|
+
]).read_first.result)).to eq(e1)
|
1187
|
+
expect(repository.read(specification.with_id([
|
1188
|
+
'd345f86d-b903-4d78-803f-38990c078d9e'
|
1189
|
+
]).read_first.result)).to eq(e3)
|
1190
|
+
expect(repository.read(specification.with_id([
|
1191
|
+
'c31b327c-0da1-4178-a3cd-d2f6bb5d0688'
|
1192
|
+
]).read_first.result)).to eq(nil)
|
1193
|
+
expect(repository.read(specification.with_id([
|
1194
|
+
'8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea',
|
1195
|
+
'd345f86d-b903-4d78-803f-38990c078d9e'
|
1196
|
+
]).in_batches.result).to_a[0]).to eq([e1,e3])
|
1197
|
+
end
|
1195
1198
|
end
|
1196
1199
|
end
|
@@ -143,6 +143,46 @@ module RubyEventStore
|
|
143
143
|
reader.one(read_last.result)
|
144
144
|
end
|
145
145
|
|
146
|
+
# Limits the query to certain events by given even ids.
|
147
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
148
|
+
#
|
149
|
+
# @param even_ids [Array(String)] ids of event to look for.
|
150
|
+
# @return [Specification]
|
151
|
+
def with_id(event_ids)
|
152
|
+
Specification.new(reader, result.dup{ |r| r.with_ids = event_ids })
|
153
|
+
end
|
154
|
+
|
155
|
+
# Executes the query based on the specification built up to this point.
|
156
|
+
# Returns the event with specified id or nil if event is not found
|
157
|
+
# in specified collection of events.
|
158
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
159
|
+
#
|
160
|
+
# @return [Event, nil]
|
161
|
+
def event(event_id)
|
162
|
+
reader.one(read_first.with_id([event_id]).result)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Executes the query based on the specification built up to this point.
|
166
|
+
# Returns the event with specified id or raises [EventNotFound[ error if
|
167
|
+
# event is not found in specified collection of events.
|
168
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
169
|
+
#
|
170
|
+
# @return [Event]
|
171
|
+
def event!(event_id)
|
172
|
+
event(event_id) or raise EventNotFound.new(event_id)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Executes the query based on the specification built up to this point.
|
176
|
+
# Yields each event (found by id in specified collection of events)
|
177
|
+
# read from the store if block given. Otherwise, returns enumerable collection.
|
178
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
179
|
+
#
|
180
|
+
# @yield [Event, Proto] event
|
181
|
+
# @return [Enumerator, nil] Enumerator is returned when block not given
|
182
|
+
def events(event_ids)
|
183
|
+
with_id(event_ids).each
|
184
|
+
end
|
185
|
+
|
146
186
|
attr_reader :result
|
147
187
|
private
|
148
188
|
attr_reader :reader
|
@@ -5,9 +5,10 @@ module RubyEventStore
|
|
5
5
|
count: nil,
|
6
6
|
stream: Stream.new(GLOBAL_STREAM),
|
7
7
|
read_as: :all,
|
8
|
-
batch_size: Specification::DEFAULT_BATCH_SIZE
|
9
|
-
|
10
|
-
|
8
|
+
batch_size: Specification::DEFAULT_BATCH_SIZE,
|
9
|
+
with_ids: nil)
|
10
|
+
@attributes = Struct.new(:direction, :start, :count, :stream, :read_as, :batch_size, :with_ids)
|
11
|
+
.new(direction, start, count, stream, read_as, batch_size, with_ids)
|
11
12
|
freeze
|
12
13
|
end
|
13
14
|
|
@@ -75,6 +76,22 @@ module RubyEventStore
|
|
75
76
|
attributes.batch_size
|
76
77
|
end
|
77
78
|
|
79
|
+
# Ids of specified event to be read (if any given)
|
80
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
81
|
+
#
|
82
|
+
# @return [Array|nil]
|
83
|
+
def with_ids
|
84
|
+
attributes.with_ids
|
85
|
+
end
|
86
|
+
|
87
|
+
# Read by specified ids. True if event ids have been specified.
|
88
|
+
# {http://railseventstore.org/docs/read/ Find out more}.
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
def with_ids?
|
92
|
+
!(with_ids || []).empty?
|
93
|
+
end
|
94
|
+
|
78
95
|
# Read strategy. True if items will be read in batches
|
79
96
|
# {http://railseventstore.org/docs/read/ Find out more}.
|
80
97
|
#
|
@@ -145,6 +162,7 @@ module RubyEventStore
|
|
145
162
|
# * stream
|
146
163
|
# * read_as
|
147
164
|
# * batch_size
|
165
|
+
# * with_ids
|
148
166
|
#
|
149
167
|
# @return [Integer]
|
150
168
|
def hash
|
@@ -156,6 +174,7 @@ module RubyEventStore
|
|
156
174
|
stream,
|
157
175
|
attributes.read_as,
|
158
176
|
batch_size,
|
177
|
+
with_ids,
|
159
178
|
].hash ^ BIG_VALUE
|
160
179
|
end
|
161
180
|
|
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: 0.
|
4
|
+
version: 0.33.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
requirements: []
|
227
227
|
rubyforge_project:
|
228
|
-
rubygems_version:
|
228
|
+
rubygems_version: 3.0.0.beta1
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: Event Store in Ruby
|