event_store_client 1.4.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -145
  3. data/docs/appending_events.md +155 -0
  4. data/docs/catch_up_subscriptions.md +253 -0
  5. data/docs/configuration.md +83 -0
  6. data/docs/deleting_streams.md +25 -0
  7. data/docs/encrypting_events.md +84 -0
  8. data/docs/linking_events.md +149 -0
  9. data/docs/reading_events.md +200 -0
  10. data/lib/event_store_client/adapters/grpc/client.rb +244 -105
  11. data/lib/event_store_client/adapters/grpc/cluster/gossip_discover.rb +131 -0
  12. data/lib/event_store_client/adapters/grpc/cluster/insecure_connection.rb +21 -0
  13. data/lib/event_store_client/adapters/grpc/cluster/member.rb +18 -0
  14. data/lib/event_store_client/adapters/grpc/cluster/queryless_discover.rb +25 -0
  15. data/lib/event_store_client/adapters/grpc/cluster/secure_connection.rb +71 -0
  16. data/lib/event_store_client/adapters/grpc/command_registrar.rb +7 -7
  17. data/lib/event_store_client/adapters/grpc/commands/command.rb +63 -25
  18. data/lib/event_store_client/adapters/grpc/commands/gossip/cluster_info.rb +24 -0
  19. data/lib/event_store_client/adapters/grpc/commands/streams/append.rb +43 -68
  20. data/lib/event_store_client/adapters/grpc/commands/streams/append_multiple.rb +44 -0
  21. data/lib/event_store_client/adapters/grpc/commands/streams/delete.rb +21 -17
  22. data/lib/event_store_client/adapters/grpc/commands/streams/hard_delete.rb +39 -0
  23. data/lib/event_store_client/adapters/grpc/commands/streams/link_to.rb +7 -52
  24. data/lib/event_store_client/adapters/grpc/commands/streams/link_to_multiple.rb +44 -0
  25. data/lib/event_store_client/adapters/grpc/commands/streams/read.rb +20 -85
  26. data/lib/event_store_client/adapters/grpc/commands/streams/read_paginated.rb +174 -0
  27. data/lib/event_store_client/adapters/grpc/commands/streams/subscribe.rb +31 -106
  28. data/lib/event_store_client/adapters/grpc/connection.rb +56 -36
  29. data/lib/event_store_client/adapters/grpc/discover.rb +75 -0
  30. data/lib/event_store_client/adapters/grpc/generated/cluster_pb.rb +106 -18
  31. data/lib/event_store_client/adapters/grpc/generated/cluster_services_pb.rb +12 -12
  32. data/lib/event_store_client/adapters/grpc/generated/code_pb.rb +34 -0
  33. data/lib/event_store_client/adapters/grpc/generated/gossip_pb.rb +3 -2
  34. data/lib/event_store_client/adapters/grpc/generated/gossip_services_pb.rb +3 -3
  35. data/lib/event_store_client/adapters/grpc/generated/monitoring_pb.rb +25 -0
  36. data/lib/event_store_client/adapters/grpc/generated/monitoring_services_pb.rb +26 -0
  37. data/lib/event_store_client/adapters/grpc/generated/operations_pb.rb +2 -1
  38. data/lib/event_store_client/adapters/grpc/generated/operations_services_pb.rb +8 -7
  39. data/lib/event_store_client/adapters/grpc/generated/persistent_pb.rb +199 -38
  40. data/lib/event_store_client/adapters/grpc/generated/persistent_services_pb.rb +7 -3
  41. data/lib/event_store_client/adapters/grpc/generated/projections_pb.rb +9 -26
  42. data/lib/event_store_client/adapters/grpc/generated/projections_services_pb.rb +4 -3
  43. data/lib/event_store_client/adapters/grpc/generated/serverfeatures_pb.rb +29 -0
  44. data/lib/event_store_client/adapters/grpc/generated/serverfeatures_services_pb.rb +26 -0
  45. data/lib/event_store_client/adapters/grpc/generated/shared_pb.rb +54 -12
  46. data/lib/event_store_client/adapters/grpc/generated/status_pb.rb +23 -0
  47. data/lib/event_store_client/adapters/grpc/generated/streams_pb.rb +104 -64
  48. data/lib/event_store_client/adapters/grpc/generated/streams_services_pb.rb +3 -2
  49. data/lib/event_store_client/adapters/grpc/generated/users_services_pb.rb +2 -2
  50. data/lib/event_store_client/adapters/grpc/options/streams/read_options.rb +78 -0
  51. data/lib/event_store_client/adapters/grpc/options/streams/write_options.rb +39 -0
  52. data/lib/event_store_client/adapters/grpc/shared/event_deserializer.rb +52 -0
  53. data/lib/event_store_client/adapters/grpc/shared/options/filter_options.rb +76 -0
  54. data/lib/event_store_client/adapters/grpc/shared/options/stream_options.rb +91 -0
  55. data/lib/event_store_client/adapters/grpc/shared/streams/process_response.rb +28 -0
  56. data/lib/event_store_client/adapters/grpc/shared/streams/process_responses.rb +33 -0
  57. data/lib/event_store_client/adapters/grpc.rb +28 -12
  58. data/lib/event_store_client/configuration.rb +39 -54
  59. data/lib/event_store_client/connection/url.rb +57 -0
  60. data/lib/event_store_client/connection/url_parser.rb +144 -0
  61. data/lib/event_store_client/data_decryptor.rb +2 -9
  62. data/lib/event_store_client/deserialized_event.rb +35 -10
  63. data/lib/event_store_client/encryption_metadata.rb +0 -1
  64. data/lib/event_store_client/event.rb +4 -2
  65. data/lib/event_store_client/extensions/options_extension.rb +87 -0
  66. data/lib/event_store_client/mapper/default.rb +12 -9
  67. data/lib/event_store_client/mapper/encrypted.rb +18 -17
  68. data/lib/event_store_client/types.rb +1 -1
  69. data/lib/event_store_client/utils.rb +30 -0
  70. data/lib/event_store_client/version.rb +1 -1
  71. data/lib/event_store_client.rb +8 -7
  72. metadata +74 -83
  73. data/lib/event_store_client/adapters/grpc/Protos/cluster.proto +0 -149
  74. data/lib/event_store_client/adapters/grpc/Protos/gossip.proto +0 -44
  75. data/lib/event_store_client/adapters/grpc/Protos/operations.proto +0 -45
  76. data/lib/event_store_client/adapters/grpc/Protos/persistent.proto +0 -180
  77. data/lib/event_store_client/adapters/grpc/Protos/projections.proto +0 -174
  78. data/lib/event_store_client/adapters/grpc/Protos/shared.proto +0 -22
  79. data/lib/event_store_client/adapters/grpc/Protos/streams.proto +0 -242
  80. data/lib/event_store_client/adapters/grpc/Protos/users.proto +0 -119
  81. data/lib/event_store_client/adapters/grpc/README.md +0 -16
  82. data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/create.rb +0 -46
  83. data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/delete.rb +0 -34
  84. data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/read.rb +0 -77
  85. data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/settings_schema.rb +0 -38
  86. data/lib/event_store_client/adapters/grpc/commands/persistent_subscriptions/update.rb +0 -48
  87. data/lib/event_store_client/adapters/grpc/commands/projections/create.rb +0 -48
  88. data/lib/event_store_client/adapters/grpc/commands/projections/delete.rb +0 -34
  89. data/lib/event_store_client/adapters/grpc/commands/projections/update.rb +0 -44
  90. data/lib/event_store_client/adapters/grpc/commands/streams/read_all.rb +0 -43
  91. data/lib/event_store_client/adapters/grpc/commands/streams/tombstone.rb +0 -35
  92. data/lib/event_store_client/adapters/http/README.md +0 -16
  93. data/lib/event_store_client/adapters/http/client.rb +0 -161
  94. data/lib/event_store_client/adapters/http/commands/command.rb +0 -27
  95. data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/ack.rb +0 -15
  96. data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/create.rb +0 -35
  97. data/lib/event_store_client/adapters/http/commands/persistent_subscriptions/read.rb +0 -60
  98. data/lib/event_store_client/adapters/http/commands/projections/create.rb +0 -33
  99. data/lib/event_store_client/adapters/http/commands/projections/update.rb +0 -31
  100. data/lib/event_store_client/adapters/http/commands/streams/append.rb +0 -49
  101. data/lib/event_store_client/adapters/http/commands/streams/delete.rb +0 -16
  102. data/lib/event_store_client/adapters/http/commands/streams/link_to.rb +0 -49
  103. data/lib/event_store_client/adapters/http/commands/streams/read.rb +0 -52
  104. data/lib/event_store_client/adapters/http/commands/streams/tombstone.rb +0 -17
  105. data/lib/event_store_client/adapters/http/connection.rb +0 -46
  106. data/lib/event_store_client/adapters/http/request_method.rb +0 -28
  107. data/lib/event_store_client/adapters/http.rb +0 -17
  108. data/lib/event_store_client/adapters/in_memory.rb +0 -144
  109. data/lib/event_store_client/broker.rb +0 -40
  110. data/lib/event_store_client/catch_up_subscription.rb +0 -42
  111. data/lib/event_store_client/catch_up_subscriptions.rb +0 -92
  112. data/lib/event_store_client/client.rb +0 -73
  113. data/lib/event_store_client/error_handler.rb +0 -10
  114. data/lib/event_store_client/subscription.rb +0 -23
  115. data/lib/event_store_client/subscriptions.rb +0 -38
  116. data/lib/event_store_client/value_objects/read_direction.rb +0 -43
@@ -0,0 +1,23 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: status.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/any_pb'
7
+ require_relative 'code_pb'
8
+
9
+ Google::Protobuf::DescriptorPool.generated_pool.build do
10
+ add_file("status.proto", :syntax => :proto3) do
11
+ add_message "google.rpc.Status" do
12
+ optional :code, :enum, 1, "google.rpc.Code"
13
+ optional :message, :string, 2
14
+ optional :details, :message, 3, "google.protobuf.Any"
15
+ end
16
+ end
17
+ end
18
+
19
+ module Google
20
+ module Rpc
21
+ Status = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.rpc.Status").msgclass
22
+ end
23
+ end
@@ -3,12 +3,14 @@
3
3
 
4
4
  require 'google/protobuf'
5
5
 
6
- require 'event_store_client/adapters/grpc/generated/shared_pb'
6
+ require_relative 'shared_pb'
7
+ require_relative 'status_pb'
8
+ require 'google/protobuf/duration_pb'
9
+ require 'google/protobuf/empty_pb'
10
+ require 'google/protobuf/timestamp_pb'
7
11
 
8
12
  Google::Protobuf::DescriptorPool.generated_pool.build do
9
13
  add_file("streams.proto", :syntax => :proto3) do
10
- ### Read Request definition
11
- #
12
14
  add_message "event_store.client.streams.ReadReq" do
13
15
  optional :options, :message, 1, "event_store.client.streams.ReadReq.Options"
14
16
  end
@@ -16,6 +18,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
16
18
  optional :read_direction, :enum, 3, "event_store.client.streams.ReadReq.Options.ReadDirection"
17
19
  optional :resolve_links, :bool, 4
18
20
  optional :uuid_option, :message, 9, "event_store.client.streams.ReadReq.Options.UUIDOption"
21
+ optional :control_option, :message, 10, "event_store.client.streams.ReadReq.Options.ControlOption"
19
22
  oneof :stream_option do
20
23
  optional :stream, :message, 1, "event_store.client.streams.ReadReq.Options.StreamOptions"
21
24
  optional :all, :message, 2, "event_store.client.streams.ReadReq.Options.AllOptions"
@@ -26,22 +29,22 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
26
29
  end
27
30
  oneof :filter_option do
28
31
  optional :filter, :message, 7, "event_store.client.streams.ReadReq.Options.FilterOptions"
29
- optional :no_filter, :message, 8, "event_store.client.shared.Empty"
32
+ optional :no_filter, :message, 8, "event_store.client.Empty"
30
33
  end
31
34
  end
32
35
  add_message "event_store.client.streams.ReadReq.Options.StreamOptions" do
33
- optional :stream_identifier, :message, 1, "event_store.client.shared.StreamIdentifier"
36
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
34
37
  oneof :revision_option do
35
38
  optional :revision, :uint64, 2
36
- optional :start, :message, 3, "event_store.client.shared.Empty"
37
- optional :end, :message, 4, "event_store.client.shared.Empty"
39
+ optional :start, :message, 3, "event_store.client.Empty"
40
+ optional :end, :message, 4, "event_store.client.Empty"
38
41
  end
39
42
  end
40
43
  add_message "event_store.client.streams.ReadReq.Options.AllOptions" do
41
44
  oneof :all_option do
42
45
  optional :position, :message, 1, "event_store.client.streams.ReadReq.Options.Position"
43
- optional :start, :message, 2, "event_store.client.shared.Empty"
44
- optional :end, :message, 3, "event_store.client.shared.Empty"
46
+ optional :start, :message, 2, "event_store.client.Empty"
47
+ optional :end, :message, 3, "event_store.client.Empty"
45
48
  end
46
49
  end
47
50
  add_message "event_store.client.streams.ReadReq.Options.SubscriptionOptions" do
@@ -58,7 +61,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
58
61
  end
59
62
  oneof :window do
60
63
  optional :max, :uint32, 3
61
- optional :count, :message, 4, "event_store.client.shared.Empty"
64
+ optional :count, :message, 4, "event_store.client.Empty"
62
65
  end
63
66
  end
64
67
  add_message "event_store.client.streams.ReadReq.Options.FilterOptions.Expression" do
@@ -67,23 +70,26 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
67
70
  end
68
71
  add_message "event_store.client.streams.ReadReq.Options.UUIDOption" do
69
72
  oneof :content do
70
- optional :structured, :message, 1, "event_store.client.shared.Empty"
71
- optional :string, :message, 2, "event_store.client.shared.Empty"
73
+ optional :structured, :message, 1, "event_store.client.Empty"
74
+ optional :string, :message, 2, "event_store.client.Empty"
72
75
  end
73
76
  end
77
+ add_message "event_store.client.streams.ReadReq.Options.ControlOption" do
78
+ optional :compatibility, :uint32, 1
79
+ end
74
80
  add_enum "event_store.client.streams.ReadReq.Options.ReadDirection" do
75
81
  value :Forwards, 0
76
82
  value :Backwards, 1
77
83
  end
78
-
79
- # Read Response definition
80
- #
81
84
  add_message "event_store.client.streams.ReadResp" do
82
85
  oneof :content do
83
86
  optional :event, :message, 1, "event_store.client.streams.ReadResp.ReadEvent"
84
87
  optional :confirmation, :message, 2, "event_store.client.streams.ReadResp.SubscriptionConfirmation"
85
88
  optional :checkpoint, :message, 3, "event_store.client.streams.ReadResp.Checkpoint"
86
89
  optional :stream_not_found, :message, 4, "event_store.client.streams.ReadResp.StreamNotFound"
90
+ optional :first_stream_position, :uint64, 5
91
+ optional :last_stream_position, :uint64, 6
92
+ optional :last_all_stream_position, :message, 7, "event_store.client.AllStreamPosition"
87
93
  end
88
94
  end
89
95
  add_message "event_store.client.streams.ReadResp.ReadEvent" do
@@ -91,12 +97,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
91
97
  optional :link, :message, 2, "event_store.client.streams.ReadResp.ReadEvent.RecordedEvent"
92
98
  oneof :position do
93
99
  optional :commit_position, :uint64, 3
94
- optional :no_position, :message, 4, "event_store.client.shared.Empty"
100
+ optional :no_position, :message, 4, "event_store.client.Empty"
95
101
  end
96
102
  end
97
103
  add_message "event_store.client.streams.ReadResp.ReadEvent.RecordedEvent" do
98
- optional :id, :message, 1, "event_store.client.shared.UUID"
99
- optional :stream_identifier, :message, 2, "event_store.client.shared.StreamIdentifier"
104
+ optional :id, :message, 1, "event_store.client.UUID"
105
+ optional :stream_identifier, :message, 2, "event_store.client.StreamIdentifier"
100
106
  optional :stream_revision, :uint64, 3
101
107
  optional :prepare_position, :uint64, 4
102
108
  optional :commit_position, :uint64, 5
@@ -112,38 +118,29 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
112
118
  optional :prepare_position, :uint64, 2
113
119
  end
114
120
  add_message "event_store.client.streams.ReadResp.StreamNotFound" do
115
- optional :stream_identifier, :message, 1, "event_store.client.shared.StreamIdentifier"
121
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
116
122
  end
117
-
118
- # Append to stream request
119
- #
120
123
  add_message "event_store.client.streams.AppendReq" do
121
124
  oneof :content do
122
125
  optional :options, :message, 1, "event_store.client.streams.AppendReq.Options"
123
126
  optional :proposed_message, :message, 2, "event_store.client.streams.AppendReq.ProposedMessage"
124
127
  end
125
128
  end
126
- # first send options message with info to which stream to append
127
- # then send the proposed message to the last options request.
128
- #
129
129
  add_message "event_store.client.streams.AppendReq.Options" do
130
- optional :stream_identifier, :message, 1, "event_store.client.shared.StreamIdentifier"
130
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
131
131
  oneof :expected_stream_revision do
132
132
  optional :revision, :uint64, 2
133
- optional :no_stream, :message, 3, "event_store.client.shared.Empty"
134
- optional :any, :message, 4, "event_store.client.shared.Empty"
135
- optional :stream_exists, :message, 5, "event_store.client.shared.Empty"
133
+ optional :no_stream, :message, 3, "event_store.client.Empty"
134
+ optional :any, :message, 4, "event_store.client.Empty"
135
+ optional :stream_exists, :message, 5, "event_store.client.Empty"
136
136
  end
137
137
  end
138
138
  add_message "event_store.client.streams.AppendReq.ProposedMessage" do
139
- optional :id, :message, 1, "event_store.client.shared.UUID"
139
+ optional :id, :message, 1, "event_store.client.UUID"
140
140
  map :metadata, :string, :string, 2
141
141
  optional :custom_metadata, :bytes, 3
142
142
  optional :data, :bytes, 4
143
143
  end
144
-
145
- # Append to stream response
146
- #
147
144
  add_message "event_store.client.streams.AppendResp" do
148
145
  oneof :result do
149
146
  optional :success, :message, 1, "event_store.client.streams.AppendResp.Success"
@@ -157,84 +154,121 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
157
154
  add_message "event_store.client.streams.AppendResp.Success" do
158
155
  oneof :current_revision_option do
159
156
  optional :current_revision, :uint64, 1
160
- optional :no_stream, :message, 2, "event_store.client.shared.Empty"
157
+ optional :no_stream, :message, 2, "event_store.client.Empty"
161
158
  end
162
159
  oneof :position_option do
163
160
  optional :position, :message, 3, "event_store.client.streams.AppendResp.Position"
164
- optional :no_position, :message, 4, "event_store.client.shared.Empty"
161
+ optional :no_position, :message, 4, "event_store.client.Empty"
165
162
  end
166
163
  end
167
164
  add_message "event_store.client.streams.AppendResp.WrongExpectedVersion" do
168
165
  oneof :current_revision_option_20_6_0 do
169
166
  optional :current_revision_20_6_0, :uint64, 1
170
- optional :no_stream_20_6_0, :message, 2, "event_store.client.shared.Empty"
167
+ optional :no_stream_20_6_0, :message, 2, "event_store.client.Empty"
171
168
  end
172
169
  oneof :expected_revision_option_20_6_0 do
173
170
  optional :expected_revision_20_6_0, :uint64, 3
174
- optional :any_20_6_0, :message, 4, "event_store.client.shared.Empty"
175
- optional :stream_exists_20_6_0, :message, 5, "event_store.client.shared.Empty"
171
+ optional :any_20_6_0, :message, 4, "event_store.client.Empty"
172
+ optional :stream_exists_20_6_0, :message, 5, "event_store.client.Empty"
176
173
  end
177
174
  oneof :current_revision_option do
178
175
  optional :current_revision, :uint64, 6
179
- optional :current_no_stream, :message, 7, "event_store.client.shared.Empty"
176
+ optional :current_no_stream, :message, 7, "event_store.client.Empty"
180
177
  end
181
178
  oneof :expected_revision_option do
182
179
  optional :expected_revision, :uint64, 8
183
- optional :expected_any, :message, 9, "event_store.client.shared.Empty"
184
- optional :expected_stream_exists, :message, 10, "event_store.client.shared.Empty"
185
- optional :expected_no_stream, :message, 11, "event_store.client.shared.Empty"
180
+ optional :expected_any, :message, 9, "event_store.client.Empty"
181
+ optional :expected_stream_exists, :message, 10, "event_store.client.Empty"
182
+ optional :expected_no_stream, :message, 11, "event_store.client.Empty"
183
+ end
184
+ end
185
+ add_message "event_store.client.streams.BatchAppendReq" do
186
+ optional :correlation_id, :message, 1, "event_store.client.UUID"
187
+ optional :options, :message, 2, "event_store.client.streams.BatchAppendReq.Options"
188
+ repeated :proposed_messages, :message, 3, "event_store.client.streams.BatchAppendReq.ProposedMessage"
189
+ optional :is_final, :bool, 4
190
+ end
191
+ add_message "event_store.client.streams.BatchAppendReq.Options" do
192
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
193
+ oneof :expected_stream_position do
194
+ optional :stream_position, :uint64, 2
195
+ optional :no_stream, :message, 3, "google.protobuf.Empty"
196
+ optional :any, :message, 4, "google.protobuf.Empty"
197
+ optional :stream_exists, :message, 5, "google.protobuf.Empty"
198
+ end
199
+ oneof :deadline_option do
200
+ optional :deadline_21_10_0, :message, 6, "google.protobuf.Timestamp"
201
+ optional :deadline, :message, 7, "google.protobuf.Duration"
202
+ end
203
+ end
204
+ add_message "event_store.client.streams.BatchAppendReq.ProposedMessage" do
205
+ optional :id, :message, 1, "event_store.client.UUID"
206
+ map :metadata, :string, :string, 2
207
+ optional :custom_metadata, :bytes, 3
208
+ optional :data, :bytes, 4
209
+ end
210
+ add_message "event_store.client.streams.BatchAppendResp" do
211
+ optional :correlation_id, :message, 1, "event_store.client.UUID"
212
+ optional :stream_identifier, :message, 4, "event_store.client.StreamIdentifier"
213
+ oneof :result do
214
+ optional :error, :message, 2, "google.rpc.Status"
215
+ optional :success, :message, 3, "event_store.client.streams.BatchAppendResp.Success"
216
+ end
217
+ oneof :expected_stream_position do
218
+ optional :stream_position, :uint64, 5
219
+ optional :no_stream, :message, 6, "google.protobuf.Empty"
220
+ optional :any, :message, 7, "google.protobuf.Empty"
221
+ optional :stream_exists, :message, 8, "google.protobuf.Empty"
222
+ end
223
+ end
224
+ add_message "event_store.client.streams.BatchAppendResp.Success" do
225
+ oneof :current_revision_option do
226
+ optional :current_revision, :uint64, 1
227
+ optional :no_stream, :message, 2, "google.protobuf.Empty"
228
+ end
229
+ oneof :position_option do
230
+ optional :position, :message, 3, "event_store.client.AllStreamPosition"
231
+ optional :no_position, :message, 4, "google.protobuf.Empty"
186
232
  end
187
233
  end
188
-
189
- # Delete stream request
190
- #
191
234
  add_message "event_store.client.streams.DeleteReq" do
192
235
  optional :options, :message, 1, "event_store.client.streams.DeleteReq.Options"
193
236
  end
194
237
  add_message "event_store.client.streams.DeleteReq.Options" do
195
- optional :stream_identifier, :message, 1, "event_store.client.shared.StreamIdentifier"
238
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
196
239
  oneof :expected_stream_revision do
197
240
  optional :revision, :uint64, 2
198
- optional :no_stream, :message, 3, "event_store.client.shared.Empty"
199
- optional :any, :message, 4, "event_store.client.shared.Empty"
200
- optional :stream_exists, :message, 5, "event_store.client.shared.Empty"
241
+ optional :no_stream, :message, 3, "event_store.client.Empty"
242
+ optional :any, :message, 4, "event_store.client.Empty"
243
+ optional :stream_exists, :message, 5, "event_store.client.Empty"
201
244
  end
202
245
  end
203
-
204
- # Delete stream response
205
- #
206
246
  add_message "event_store.client.streams.DeleteResp" do
207
247
  oneof :position_option do
208
248
  optional :position, :message, 1, "event_store.client.streams.DeleteResp.Position"
209
- optional :no_position, :message, 2, "event_store.client.shared.Empty"
249
+ optional :no_position, :message, 2, "event_store.client.Empty"
210
250
  end
211
251
  end
212
252
  add_message "event_store.client.streams.DeleteResp.Position" do
213
253
  optional :commit_position, :uint64, 1
214
254
  optional :prepare_position, :uint64, 2
215
255
  end
216
-
217
- # Tombstone stream request
218
- #
219
256
  add_message "event_store.client.streams.TombstoneReq" do
220
257
  optional :options, :message, 1, "event_store.client.streams.TombstoneReq.Options"
221
258
  end
222
259
  add_message "event_store.client.streams.TombstoneReq.Options" do
223
- optional :stream_identifier, :message, 1, "event_store.client.shared.StreamIdentifier"
260
+ optional :stream_identifier, :message, 1, "event_store.client.StreamIdentifier"
224
261
  oneof :expected_stream_revision do
225
262
  optional :revision, :uint64, 2
226
- optional :no_stream, :message, 3, "event_store.client.shared.Empty"
227
- optional :any, :message, 4, "event_store.client.shared.Empty"
228
- optional :stream_exists, :message, 5, "event_store.client.shared.Empty"
263
+ optional :no_stream, :message, 3, "event_store.client.Empty"
264
+ optional :any, :message, 4, "event_store.client.Empty"
265
+ optional :stream_exists, :message, 5, "event_store.client.Empty"
229
266
  end
230
267
  end
231
-
232
- # Tombstone stream response
233
- #
234
268
  add_message "event_store.client.streams.TombstoneResp" do
235
269
  oneof :position_option do
236
270
  optional :position, :message, 1, "event_store.client.streams.TombstoneResp.Position"
237
- optional :no_position, :message, 2, "event_store.client.shared.Empty"
271
+ optional :no_position, :message, 2, "event_store.client.Empty"
238
272
  end
239
273
  end
240
274
  add_message "event_store.client.streams.TombstoneResp.Position" do
@@ -256,6 +290,7 @@ module EventStore
256
290
  ReadReq::Options::FilterOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadReq.Options.FilterOptions").msgclass
257
291
  ReadReq::Options::FilterOptions::Expression = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadReq.Options.FilterOptions.Expression").msgclass
258
292
  ReadReq::Options::UUIDOption = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadReq.Options.UUIDOption").msgclass
293
+ ReadReq::Options::ControlOption = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadReq.Options.ControlOption").msgclass
259
294
  ReadReq::Options::ReadDirection = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadReq.Options.ReadDirection").enummodule
260
295
  ReadResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadResp").msgclass
261
296
  ReadResp::ReadEvent = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.ReadResp.ReadEvent").msgclass
@@ -270,6 +305,11 @@ module EventStore
270
305
  AppendResp::Position = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.AppendResp.Position").msgclass
271
306
  AppendResp::Success = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.AppendResp.Success").msgclass
272
307
  AppendResp::WrongExpectedVersion = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.AppendResp.WrongExpectedVersion").msgclass
308
+ BatchAppendReq = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.BatchAppendReq").msgclass
309
+ BatchAppendReq::Options = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.BatchAppendReq.Options").msgclass
310
+ BatchAppendReq::ProposedMessage = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.BatchAppendReq.ProposedMessage").msgclass
311
+ BatchAppendResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.BatchAppendResp").msgclass
312
+ BatchAppendResp::Success = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.BatchAppendResp.Success").msgclass
273
313
  DeleteReq = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.DeleteReq").msgclass
274
314
  DeleteReq::Options = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.DeleteReq.Options").msgclass
275
315
  DeleteResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("event_store.client.streams.DeleteResp").msgclass
@@ -2,7 +2,7 @@
2
2
  # Source: streams.proto for package 'event_store.client.streams'
3
3
 
4
4
  require 'grpc'
5
- require 'event_store_client/adapters/grpc/generated/streams_pb'
5
+ require_relative 'streams_pb'
6
6
 
7
7
  module EventStore
8
8
  module Client
@@ -10,7 +10,7 @@ module EventStore
10
10
  module Streams
11
11
  class Service
12
12
 
13
- include GRPC::GenericService
13
+ include ::GRPC::GenericService
14
14
 
15
15
  self.marshal_class_method = :encode
16
16
  self.unmarshal_class_method = :decode
@@ -20,6 +20,7 @@ module EventStore
20
20
  rpc :Append, stream(::EventStore::Client::Streams::AppendReq), ::EventStore::Client::Streams::AppendResp
21
21
  rpc :Delete, ::EventStore::Client::Streams::DeleteReq, ::EventStore::Client::Streams::DeleteResp
22
22
  rpc :Tombstone, ::EventStore::Client::Streams::TombstoneReq, ::EventStore::Client::Streams::TombstoneResp
23
+ rpc :BatchAppend, stream(::EventStore::Client::Streams::BatchAppendReq), stream(::EventStore::Client::Streams::BatchAppendResp)
23
24
  end
24
25
 
25
26
  Stub = Service.rpc_stub_class
@@ -2,7 +2,7 @@
2
2
  # Source: users.proto for package 'event_store.client.users'
3
3
 
4
4
  require 'grpc'
5
- require 'users_pb'
5
+ require_relative 'users_pb'
6
6
 
7
7
  module EventStore
8
8
  module Client
@@ -10,7 +10,7 @@ module EventStore
10
10
  module Users
11
11
  class Service
12
12
 
13
- include GRPC::GenericService
13
+ include ::GRPC::GenericService
14
14
 
15
15
  self.marshal_class_method = :encode
16
16
  self.unmarshal_class_method = :decode
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/AbcSize
4
+
5
+ require 'event_store_client/adapters/grpc/generated/shared_pb'
6
+
7
+ module EventStoreClient
8
+ module GRPC
9
+ module Options
10
+ module Streams
11
+ class ReadOptions
12
+ include Configuration
13
+
14
+ attr_reader :options, :stream_name
15
+ private :options, :stream_name
16
+
17
+ # @param stream_name [String]
18
+ # @param options [Hash]
19
+ # @option [String] :direction 'Forwards' or 'Backwards'
20
+ # @option [Integer] :max_count
21
+ # @option [Boolean] :resolve_link_tos
22
+ # @option [Symbol] :from_revision :start or :end. Works only for regular streams.
23
+ # @option [Integer] :from_revision revision number to start from. Remember, that all reads
24
+ # are inclusive and all subscribes are exclusive. This means if you provide revision
25
+ # number when reading from stream - the first event will be an event of revision number
26
+ # you provided. And, when subscribing on stream - the first event will be an event next
27
+ # to the event of revision number you provided. Works only for regular streams.
28
+ # @option [Symbol] :from_position :start or :end. Works only for $all streams.
29
+ # @option [Hash] :from_position provided a hash with either both :commit_position and
30
+ # :prepare_position keys or with one of them to define the starting position. Remember,
31
+ # that all reads are inclusive and all subscribes are exclusive. This means if you
32
+ # provide position number when reading from stream - the first event will be an event of
33
+ # position number you provided. And, when subscribing on stream - the first event will
34
+ # be an event next to the event of position number you provided. Works only for $all
35
+ # streams. Unlike :from_revision - :commit_position and :prepare_position should contain
36
+ # values of existing event.
37
+ # Example:
38
+ # ```ruby
39
+ # new('some-stream', from_position: { commit_position: 1024, prepare_position: 1024 })
40
+ # ```
41
+ # @option [Hash] :filter see
42
+ # {EventStoreClient::GRPC::Shared::Options::FilterOptions#initialize} for available
43
+ # values
44
+ def initialize(stream_name, options)
45
+ @stream_name = stream_name
46
+ @options = options
47
+ end
48
+
49
+ # @return [Hash] see event_store.client.streams.ReadReq.Options for available options
50
+ def request_options
51
+ request_options = {}
52
+ request_options.merge!(
53
+ Shared::Options::StreamOptions.new(stream_name, options).request_options
54
+ )
55
+ request_options[:read_direction] = options[:direction]
56
+ request_options[:count] = options[:max_count] || config.per_page
57
+ request_options[:resolve_links] = options[:resolve_link_tos]
58
+ request_options.merge!(
59
+ Shared::Options::FilterOptions.new(options[:filter]).request_options
60
+ )
61
+ # This option means how event#id would look like in the response. If you provided
62
+ # :string key, then #id will be a normal UUID string. If you provided :structured
63
+ # key, then #id will be an instance of EventStore::Client::UUID::Structured class.
64
+ # Note: for some reason if you don't provide this option - the request hangs forever
65
+ # Examples:
66
+ # <EventStore::Client::UUID::Structured:
67
+ # most_significant_bits: 1266766466329758182,
68
+ # least_significant_bits: -8366670759139390653>
69
+ # <EventStore::Client::UUID: string: "f0e1771c-334b-4b8d-ad88-c2024ccbe141">
70
+ request_options[:uuid_option] = { string: EventStore::Client::Empty.new }
71
+ request_options
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ # rubocop:enable Metrics/AbcSize
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'event_store_client/adapters/grpc/generated/shared_pb'
4
+
5
+ module EventStoreClient
6
+ module GRPC
7
+ module Options
8
+ module Streams
9
+ class WriteOptions
10
+ attr_reader :stream_name, :options
11
+ private :stream_name, :options
12
+
13
+ # @param stream_name [String]
14
+ # @param options [Hash]
15
+ # @option [Integer] :expected_revision
16
+ # @option [Symbol] :expected_revision either :any, :no_stream or :stream_exists
17
+ def initialize(stream_name, options)
18
+ @stream_name = stream_name
19
+ @options = options
20
+ end
21
+
22
+ # @return [Hash] see event_store.client.streams.AppendReq.Options for available options
23
+ def request_options
24
+ revision_opt =
25
+ case options[:expected_revision]
26
+ when :any, :no_stream, :stream_exists
27
+ { options[:expected_revision] => EventStore::Client::Empty.new }
28
+ when Integer
29
+ { revision: options[:expected_revision] }
30
+ else
31
+ { any: EventStore::Client::Empty.new }
32
+ end
33
+ revision_opt.merge(stream_identifier: { stream_name: stream_name })
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/AbcSize
4
+
5
+ module EventStoreClient
6
+ module GRPC
7
+ module Shared
8
+ class EventDeserializer
9
+ include Configuration
10
+
11
+ # @param raw_event [
12
+ # Array<EventStore::Client::Streams::ReadResp::ReadEvent::RecordedEvent>,
13
+ # Array<EventStore::Client::PersistentSubscriptions::ReadResp::ReadEvent::RecordedEvent>
14
+ # ]
15
+ # @param skip_decryption [Boolean]
16
+ # @return [EventStoreClient::DeserializedEvent]
17
+ def call(raw_event, skip_decryption: false)
18
+ data = normalize_serialized(raw_event.data)
19
+ custom_metadata = normalize_serialized(raw_event.custom_metadata)
20
+
21
+ metadata =
22
+ JSON.parse(custom_metadata).merge(raw_event.metadata.to_h).to_json
23
+
24
+ event = EventStoreClient::Event.new(
25
+ id: raw_event.id.string,
26
+ title: "#{raw_event.stream_revision}@#{raw_event.stream_identifier.stream_name}",
27
+ type: raw_event.metadata['type'],
28
+ data: data,
29
+ metadata: metadata,
30
+ stream_revision: raw_event.stream_revision,
31
+ commit_position: raw_event.commit_position,
32
+ prepare_position: raw_event.prepare_position,
33
+ stream_name: raw_event.stream_identifier.stream_name
34
+ )
35
+
36
+ config.mapper.deserialize(event, skip_decryption: skip_decryption)
37
+ end
38
+
39
+ private
40
+
41
+ # @param raw_data [String, nil]
42
+ # @return [String]
43
+ def normalize_serialized(raw_data)
44
+ return {}.to_json if raw_data.nil? || raw_data.empty?
45
+
46
+ raw_data
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ # rubocop:enable Metrics/AbcSize
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'event_store_client/adapters/grpc/generated/shared_pb'
4
+
5
+ module EventStoreClient
6
+ module GRPC
7
+ module Shared
8
+ module Options
9
+ class FilterOptions
10
+ attr_reader :options
11
+ private :options
12
+
13
+ # See event_store.client.streams.ReadReq.Options.FilterOptions in streams_pb.rb generated
14
+ # file for more info(for persisted subscription the structure is the same)
15
+ # @param filter_options [Hash, nil]
16
+ # @option [Integer] :checkpointIntervalMultiplier
17
+ # @option [Integer] :max
18
+ # @option [Boolean] :count
19
+ # @option [Hash] :stream_identifier filter events by stream name using Regexp or String.
20
+ # Examples:
21
+ # ```ruby
22
+ # # Return events streams names of which end with number
23
+ # new(stream_identifier: { regex: /.*\d$/.to_s })
24
+ # # Return events streams names of which start from 'some-stream-1' or 'some-stream-2'
25
+ # # strings
26
+ # new(stream_identifier: { prefix: ['some-stream-1', 'some-stream-2'] })
27
+ # ```
28
+ # @option [Hash] :event_type filter events by event name using Regexp or String.
29
+ # Examples:
30
+ # ```ruby
31
+ # # Return events names of which end with number
32
+ # new(event_type: { regex: /.*\d$/.to_s })
33
+ # # Return events names of which start from 'some-event-1' or 'some-event-2'
34
+ # # strings
35
+ # new(event_type: { prefix: ['some-event-1', 'some-event-2'] })
36
+ # ```
37
+ def initialize(filter_options)
38
+ @options = filter_options
39
+ end
40
+
41
+ # See :filter_option in persistent_pb.rb or in streams_pb.rb generated files
42
+ # @return [Hash]
43
+ def request_options
44
+ request_options = {}
45
+ case options
46
+ in { stream_identifier: { regex: String } } | { stream_identifier: { prefix: Array } } |
47
+ { event_type: { regex: String } } | { event_type: { prefix: Array } }
48
+ request_options[:filter] = options
49
+ add_window_options(request_options)
50
+ else
51
+ request_options[:no_filter] = EventStore::Client::Empty.new
52
+ end
53
+ request_options
54
+ end
55
+
56
+ private
57
+
58
+ # Define how frequently "checkpoint" event should be produced. Its value is calculated
59
+ # by multiplying max by checkpointIntervalMultiplier.
60
+ # Example:
61
+ # Given max 32 and multiplier 2 - "checkpoint" event will be produced on each
62
+ # 64' event
63
+ # These options are only useful when subscribing to the stream
64
+ # @return [void]
65
+ def add_window_options(request_options)
66
+ request_options[:filter][:max] ||= 100
67
+ if request_options[:filter][:count]
68
+ request_options[:filter][:count] = EventStore::Client::Empty.new
69
+ end
70
+ request_options[:filter][:checkpointIntervalMultiplier] ||= 1
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end