event_store_client 1.0.1 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 134b0426087d6b24a29e55e762f5bcbdbaafbe91b3311e95e10cbaff66d83f20
4
- data.tar.gz: 8e08fecbacc16ef6a4983f69e867a1a6295160fa35f864e8635e365366b2ad38
3
+ metadata.gz: 073a691ef952647fd7be92fad2526a279dccfe05867c524ccab6a86aee815dd2
4
+ data.tar.gz: 75c51d92577ceb57488e07761466dd58bf1b8cb52e23ee11a82d40bdfb387039
5
5
  SHA512:
6
- metadata.gz: 74af83ac0ba1dab7b00e660ed16320c9fe84ea87f39b28e9b876cd1689a02c4a48df70567b4d1949b5188a7dd37d3b6f46a6f897a7073adc368eac13807197cc
7
- data.tar.gz: d69d047e3054f10bfd7928347d6b5e17c59c2a73aa0ea4f131af7d0a238188686975f5ac866b362dc9096d5d22d4ed9a5f29a9ef751f93e4c89b05d0b2d94dd7
6
+ metadata.gz: c9ba15429219f65fc9a7473642ff2e7a0c048cf14a0246f00ecac62ad5daf38ab9c0a800993911d14cd142706ec1d3f5e233e092279391c7c7d9d43683468a05
7
+ data.tar.gz: 27f4088d4e92c6a0cef51a93970559a4253d44789e5d9c3a744afebc59de027f3f1853e0c527de5438ede1031bd5cf9ad36aff2e6f8f82856202c23a45b47025
@@ -48,13 +48,23 @@ module EventStoreClient
48
48
  private
49
49
 
50
50
  def deserialize_event(entry)
51
+ id = entry.id.string
52
+ id = SecureRandom.uuid if id.nil? || id.empty?
53
+
54
+ data = (entry.data.nil? || entry.data.empty?) ? '{}' : entry.data
55
+
56
+ metadata =
57
+ JSON.parse(entry.custom_metadata || '{}').merge(
58
+ entry.metadata.to_h || {}
59
+ ).to_json
60
+
51
61
  config.mapper.deserialize(
52
62
  EventStoreClient::Event.new(
53
- id: entry.id.string,
63
+ id: id,
54
64
  title: "#{entry.stream_revision}@#{entry.stream_identifier.streamName}",
55
65
  type: entry.metadata['type'],
56
- data: entry.data || '{}',
57
- metadata: (entry.metadata.to_h || {}).to_json
66
+ data: data,
67
+ metadata: metadata
58
68
  )
59
69
  )
60
70
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'securerandom'
3
4
  require 'grpc'
4
5
  require 'event_store_client/adapters/grpc/generated/streams_pb.rb'
5
6
  require 'event_store_client/adapters/grpc/generated/streams_services_pb.rb'
@@ -26,10 +27,13 @@ module EventStoreClient
26
27
 
27
28
  event_metadata = event.metadata.tap do |h|
28
29
  h['type'] = '$>'
29
- h['content-type'] = 'application/octet-stream'
30
+ h['content-type'] = 'application/json'
30
31
  h.delete('encryption')
31
32
  end
32
33
 
34
+ event_id = event.id
35
+ event_id = SecureRandom.uuid if event.id.nil? || event.id.empty?
36
+
33
37
  payload = [
34
38
  request.new(
35
39
  options: {
@@ -42,7 +46,7 @@ module EventStoreClient
42
46
  request.new(
43
47
  proposed_message: {
44
48
  id: {
45
- string: event.id
49
+ string: event_id
46
50
  },
47
51
  data: event.title,
48
52
  custom_metadata: custom_metadata,
@@ -10,9 +10,8 @@ module EventStoreClient
10
10
  WrongExpectedEventVersion = Class.new(StandardError)
11
11
 
12
12
  def publish(stream:, events:, options: {})
13
- connection.append_to_stream(stream, events, options: options)
14
- rescue HTTP::Client::WrongExpectedEventVersion => e
15
- raise WrongExpectedEventVersion.new(e.message)
13
+ res = connection.append_to_stream(stream, events, options: options)
14
+ raise WrongExpectedEventVersion.new(e.message) if res.failure?
16
15
  end
17
16
 
18
17
  def read(stream, options: {})
@@ -43,7 +42,7 @@ module EventStoreClient
43
42
  end
44
43
  # rubocop:enable Metrics/CyclomaticComplexity
45
44
 
46
- attr_accessor :connection, :service_name
45
+ attr_accessor :connection
47
46
 
48
47
  private
49
48
 
@@ -53,7 +52,6 @@ module EventStoreClient
53
52
  @threads = []
54
53
  @connection ||= EventStoreClient.adapter
55
54
  @error_handler ||= config.error_handler
56
- @service_name ||= 'default'
57
55
  @broker ||= Broker.new(connection: connection)
58
56
  @subscriptions ||= Subscriptions.new(connection: connection, service: config.service_name)
59
57
  end
@@ -32,7 +32,7 @@ module EventStoreClient
32
32
  end
33
33
 
34
34
  def content_type
35
- return 'application/octet-stream' if EventStoreClient.config.adapter == :grpc
35
+ return 'application/json' if EventStoreClient.config.adapter == :grpc
36
36
 
37
37
  'application/vnd.eventstore.events+json'
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable