event_store_client 0.2.8 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -37
- data/lib/event_store_client.rb +0 -2
- data/lib/event_store_client/adapters/grpc.rb +21 -0
- data/lib/event_store_client/adapters/grpc/Protos/cluster.proto +149 -0
- data/lib/event_store_client/adapters/grpc/Protos/gossip.proto +44 -0
- data/lib/event_store_client/adapters/grpc/Protos/operations.proto +45 -0
- data/lib/event_store_client/adapters/grpc/Protos/persistent.proto +180 -0
- data/lib/event_store_client/adapters/grpc/Protos/projections.proto +174 -0
- data/lib/event_store_client/adapters/grpc/Protos/shared.proto +22 -0
- data/lib/event_store_client/adapters/grpc/Protos/streams.proto +242 -0
- data/lib/event_store_client/adapters/grpc/Protos/users.proto +119 -0
- data/lib/event_store_client/adapters/grpc/client.rb +119 -0
- data/lib/event_store_client/adapters/grpc/command_registrar.rb +32 -0
- data/lib/event_store_client/adapters/grpc/commands/command.rb +43 -0
- data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/create.rb +46 -0
- data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/delete.rb +34 -0
- data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/read.rb +65 -0
- data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/settings_schema.rb +38 -0
- data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/update.rb +48 -0
- data/lib/event_store_client/adapters/grpc/commands/projections/create.rb +45 -0
- data/lib/event_store_client/adapters/grpc/commands/projections/delete.rb +34 -0
- data/lib/event_store_client/adapters/grpc/commands/projections/update.rb +42 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/append.rb +61 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/delete.rb +35 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/link_to.rb +61 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/read.rb +80 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/read_all.rb +43 -0
- data/lib/event_store_client/adapters/grpc/commands/streams/tombstone.rb +35 -0
- data/lib/event_store_client/adapters/grpc/connection.rb +50 -0
- data/lib/event_store_client/adapters/grpc/generated/cluster_pb.rb +140 -0
- data/lib/event_store_client/adapters/grpc/generated/cluster_services_pb.rb +46 -0
- data/lib/event_store_client/adapters/grpc/generated/gossip_pb.rb +53 -0
- data/lib/event_store_client/adapters/grpc/generated/gossip_services_pb.rb +26 -0
- data/lib/event_store_client/adapters/grpc/generated/operations_pb.rb +49 -0
- data/lib/event_store_client/adapters/grpc/generated/operations_services_pb.rb +31 -0
- data/lib/event_store_client/adapters/grpc/generated/persistent_pb.rb +213 -0
- data/lib/event_store_client/adapters/grpc/generated/persistent_services_pb.rb +29 -0
- data/lib/event_store_client/adapters/grpc/generated/projections_pb.rb +193 -0
- data/lib/event_store_client/adapters/grpc/generated/projections_services_pb.rb +34 -0
- data/lib/event_store_client/adapters/grpc/generated/shared_pb.rb +35 -0
- data/lib/event_store_client/adapters/grpc/generated/streams_pb.rb +283 -0
- data/lib/event_store_client/adapters/grpc/generated/streams_services_pb.rb +29 -0
- data/lib/event_store_client/adapters/grpc/generated/users_pb.rb +126 -0
- data/lib/event_store_client/adapters/grpc/generated/users_services_pb.rb +33 -0
- data/lib/event_store_client/adapters/http.rb +16 -0
- data/lib/event_store_client/adapters/http/README.md +16 -0
- data/lib/event_store_client/adapters/http/client.rb +160 -0
- data/lib/event_store_client/adapters/http/commands/command.rb +27 -0
- data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/ack.rb +15 -0
- data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/create.rb +31 -0
- data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/read.rb +57 -0
- data/lib/event_store_client/adapters/http/commands/projections/create.rb +30 -0
- data/lib/event_store_client/adapters/http/commands/streams/append.rb +49 -0
- data/lib/event_store_client/adapters/http/commands/streams/delete.rb +16 -0
- data/lib/event_store_client/adapters/http/commands/streams/link_to.rb +49 -0
- data/lib/event_store_client/adapters/http/commands/streams/read.rb +53 -0
- data/lib/event_store_client/adapters/http/commands/streams/tombstone.rb +17 -0
- data/lib/event_store_client/adapters/http/connection.rb +46 -0
- data/lib/event_store_client/adapters/http/request_method.rb +28 -0
- data/lib/event_store_client/adapters/in_memory.rb +142 -0
- data/lib/event_store_client/broker.rb +16 -5
- data/lib/event_store_client/client.rb +18 -72
- data/lib/event_store_client/configuration.rb +28 -14
- data/lib/event_store_client/data_decryptor.rb +13 -8
- data/lib/event_store_client/data_encryptor.rb +7 -6
- data/lib/event_store_client/deserialized_event.rb +10 -1
- data/lib/event_store_client/event.rb +2 -2
- data/lib/event_store_client/mapper/default.rb +0 -1
- data/lib/event_store_client/serializer/json.rb +2 -0
- data/lib/event_store_client/subscriptions.rb +4 -13
- data/lib/event_store_client/types.rb +3 -1
- data/lib/event_store_client/value_objects/read_direction.rb +43 -0
- data/lib/event_store_client/version.rb +1 -1
- metadata +97 -15
- data/lib/event_store_client/store_adapter.rb +0 -10
- data/lib/event_store_client/store_adapter/api/client.rb +0 -224
- data/lib/event_store_client/store_adapter/api/connection.rb +0 -43
- data/lib/event_store_client/store_adapter/api/request_method.rb +0 -30
- data/lib/event_store_client/store_adapter/in_memory.rb +0 -160
@@ -1,160 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EventStoreClient
|
4
|
-
module StoreAdapter
|
5
|
-
class InMemory
|
6
|
-
Response = Struct.new(:body, :status) do
|
7
|
-
def success?
|
8
|
-
status == 200
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :event_store
|
13
|
-
|
14
|
-
def append_to_stream(stream_name, events, expected_version: nil) # rubocop:disable Lint/UnusedMethodArgument,Metrics/LineLength
|
15
|
-
event_store[stream_name] = [] unless event_store.key?(stream_name)
|
16
|
-
[events].flatten.each do |event|
|
17
|
-
event_store[stream_name].unshift(
|
18
|
-
'eventId' => event.id,
|
19
|
-
'data' => event.data,
|
20
|
-
'eventType' => event.type,
|
21
|
-
'metaData' => event.metadata,
|
22
|
-
'positionEventNumber' => event_store[stream_name].length
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def read(stream_name, direction: 'forward', start: 0, resolve_links: nil)
|
28
|
-
response =
|
29
|
-
if direction == 'forward'
|
30
|
-
read_stream_forward(stream_name, start: start)
|
31
|
-
else
|
32
|
-
read_stream_backward(stream_name, start: start)
|
33
|
-
end
|
34
|
-
|
35
|
-
res = Response.new(response.to_json, 200)
|
36
|
-
|
37
|
-
return [] if res.body.nil? || res.body.empty?
|
38
|
-
JSON.parse(res.body)['entries'].map do |entry|
|
39
|
-
deserialize_event(entry)
|
40
|
-
end.reverse
|
41
|
-
end
|
42
|
-
|
43
|
-
def read_all_from_stream(stream_name, direction: 'forward', start: 0, resolve_links: true)
|
44
|
-
response =
|
45
|
-
if direction == 'forward'
|
46
|
-
read_stream_forward(stream_name, start: start)
|
47
|
-
else
|
48
|
-
read_stream_backward(stream_name, start: start)
|
49
|
-
end
|
50
|
-
res = Response.new(response.to_json, 200)
|
51
|
-
|
52
|
-
return [] if res.body.nil? || res.body.empty?
|
53
|
-
JSON.parse(res.body)['entries'].map do |entry|
|
54
|
-
deserialize_event(entry)
|
55
|
-
end.reverse
|
56
|
-
end
|
57
|
-
|
58
|
-
def subscribe_to_stream(stream_name, subscription_name, **)
|
59
|
-
# TODO: implement method body
|
60
|
-
end
|
61
|
-
|
62
|
-
def consume_feed(
|
63
|
-
stream_name,
|
64
|
-
subscription_name,
|
65
|
-
**
|
66
|
-
)
|
67
|
-
# TODO: implement method body
|
68
|
-
end
|
69
|
-
|
70
|
-
def delete_stream(stream_name, hard_delete: false) # rubocop:disable Lint/UnusedMethodArgument
|
71
|
-
event_store.delete(stream_name)
|
72
|
-
end
|
73
|
-
|
74
|
-
def link_to(stream_name, events, **)
|
75
|
-
append_to_stream(stream_name, events)
|
76
|
-
events
|
77
|
-
end
|
78
|
-
|
79
|
-
def ack(url)
|
80
|
-
# TODO: implement method body
|
81
|
-
end
|
82
|
-
|
83
|
-
def join_streams(name, streams); end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
attr_reader :per_page, :mapper
|
88
|
-
|
89
|
-
def initialize(mapper:, per_page: 20)
|
90
|
-
@per_page = per_page
|
91
|
-
@mapper = mapper
|
92
|
-
@event_store = {}
|
93
|
-
end
|
94
|
-
|
95
|
-
def read_stream_backward(stream_name, start: 0)
|
96
|
-
response = {
|
97
|
-
'entries' => [],
|
98
|
-
'links' => []
|
99
|
-
}
|
100
|
-
return response unless event_store.key?(stream_name)
|
101
|
-
|
102
|
-
start = start == 'head' ? event_store[stream_name].length - 1 : start
|
103
|
-
last_index = start - per_page
|
104
|
-
response['entries'] = event_store[stream_name].select do |event|
|
105
|
-
event['positionEventNumber'] > last_index &&
|
106
|
-
event['positionEventNumber'] <= start
|
107
|
-
end
|
108
|
-
response['links'] = links(stream_name, last_index, 'next', response['entries'], per_page)
|
109
|
-
|
110
|
-
response
|
111
|
-
end
|
112
|
-
|
113
|
-
def read_stream_forward(stream_name, start: 0)
|
114
|
-
response = {
|
115
|
-
'entries' => [],
|
116
|
-
'links' => []
|
117
|
-
}
|
118
|
-
|
119
|
-
return response unless event_store.key?(stream_name)
|
120
|
-
|
121
|
-
last_index = start + per_page
|
122
|
-
response['entries'] = event_store[stream_name].select do |event|
|
123
|
-
event['positionEventNumber'] < last_index &&
|
124
|
-
event['positionEventNumber'] >= start
|
125
|
-
end
|
126
|
-
response['links'] =
|
127
|
-
links(stream_name, last_index, 'previous', response['entries'], per_page)
|
128
|
-
|
129
|
-
response
|
130
|
-
end
|
131
|
-
|
132
|
-
def links(stream_name, batch_size, direction, entries, count)
|
133
|
-
if entries.empty? || batch_size.negative?
|
134
|
-
[]
|
135
|
-
else
|
136
|
-
[{
|
137
|
-
'uri' =>
|
138
|
-
"/streams/#{stream_name}/#{batch_size}/#{direction}/#{count}",
|
139
|
-
'relation' => direction
|
140
|
-
}]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
def deserialize_event(entry)
|
147
|
-
data = (entry['data'].is_a?(Hash) ? entry['data'].to_json.presence : entry['data']) || '{}'
|
148
|
-
event = EventStoreClient::Event.new(
|
149
|
-
id: entry['eventId'],
|
150
|
-
title: entry['title'],
|
151
|
-
type: entry['eventType'],
|
152
|
-
data: data,
|
153
|
-
metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
|
154
|
-
)
|
155
|
-
|
156
|
-
mapper.deserialize(event)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|