event_store_client 1.0.0 → 1.0.1

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: 6c10b40181ca8912df10da9e73f9bc6f1416a7f9bd495982906467562b690cb2
4
- data.tar.gz: 2e8ffe26ecb7434dd4c67636e45ece323b64dd62677931462f177cbfb319c94e
3
+ metadata.gz: 134b0426087d6b24a29e55e762f5bcbdbaafbe91b3311e95e10cbaff66d83f20
4
+ data.tar.gz: 8e08fecbacc16ef6a4983f69e867a1a6295160fa35f864e8635e365366b2ad38
5
5
  SHA512:
6
- metadata.gz: 16ad845ec3e6b0e32d039c2ac36bac1cd425b886b5867fd6c5565f540c05340354cf6352f553a968e95b4402314446e89859261a2fa0e774098c7fa5389430fe
7
- data.tar.gz: 524a554f53aee5c6eacd42cf750d5b937a56758b5b5fae60a4b92e6a50f00c0783c843ca58dbdfe5d74398f0d73ed82cb98f6d4ce112d955fca81f382acebfea
6
+ metadata.gz: 74af83ac0ba1dab7b00e660ed16320c9fe84ea87f39b28e9b876cd1689a02c4a48df70567b4d1949b5188a7dd37d3b6f46a6f897a7073adc368eac13807197cc
7
+ data.tar.gz: d69d047e3054f10bfd7928347d6b5e17c59c2a73aa0ea4f131af7d0a238188686975f5ac866b362dc9096d5d22d4ed9a5f29a9ef751f93e4c89b05d0b2d94dd7
data/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
 
4
4
  # EventStoreClient
5
5
 
6
- ### Broken version. Please use version 0.2.3 until the next release happen. Fixes will be applied in 0.3.0
7
-
8
6
  An easy-to use API client for connecting ruby applications with https://eventstore.org/
9
7
 
10
8
  ## Supported adapters
@@ -48,16 +48,15 @@ module EventStoreClient
48
48
  private
49
49
 
50
50
  def deserialize_event(entry)
51
- binding.irb if event.data.include?('00735ff8-2d12-4bc7-8db2-af432baacdf1')
52
- event = EventStoreClient::Event.new(
53
- id: entry.id.string,
54
- title: "#{entry.stream_revision}@#{entry.stream_identifier.streamName}",
55
- type: entry.metadata['type'],
56
- data: entry.data || '{}',
57
- metadata: (entry.metadata.to_h || {}).to_json
51
+ config.mapper.deserialize(
52
+ EventStoreClient::Event.new(
53
+ id: entry.id.string,
54
+ title: "#{entry.stream_revision}@#{entry.stream_identifier.streamName}",
55
+ type: entry.metadata['type'],
56
+ data: entry.data || '{}',
57
+ metadata: (entry.metadata.to_h || {}).to_json
58
+ )
58
59
  )
59
-
60
- config.mapper.deserialize(event)
61
60
  end
62
61
  end
63
62
  end
@@ -21,6 +21,15 @@ module EventStoreClient
21
21
 
22
22
  serialized_events.each do |event|
23
23
  event_metadata = JSON.parse(event.metadata)
24
+ custom_metadata = {
25
+ "type": event.type,
26
+ "created_at": Time.now,
27
+ 'content-type': event_metadata['content-type']
28
+ }
29
+ custom_metadata['encryption'] = event_metadata['encryption'] unless event_metadata['encryption'].nil?
30
+ event_metadata = event_metadata.select { |k| ['type', 'content-type', 'created_at'].include?(k) }
31
+
32
+
24
33
  payload = [
25
34
  request.new(
26
35
  options: {
@@ -36,13 +45,8 @@ module EventStoreClient
36
45
  string: SecureRandom.uuid
37
46
  },
38
47
  data: event.data,
39
- custom_metadata: JSON.generate(
40
- "type": event.type,
41
- "content-type": 'application/vnd.eventstore.events+json',
42
- "created_at": Time.now,
43
- 'encryption': event_metadata['encryption']
44
- ),
45
- metadata: event_metadata.select { |k| ['type', 'content-type', 'created_at'].include?(k) }
48
+ custom_metadata: JSON.generate(custom_metadata),
49
+ metadata: event_metadata
46
50
  }
47
51
  )
48
52
  ]
@@ -17,7 +17,19 @@ module EventStoreClient
17
17
  use_service EventStore::Client::Streams::Streams::Stub
18
18
 
19
19
  def call(stream_name, events, options: {})
20
- events.each do |event|
20
+ events.each_with_index do |event, index|
21
+ custom_metadata = JSON.generate(
22
+ "type": '$>',
23
+ "created_at": Time.now,
24
+ "encryption": event.metadata['encryption'] || ''
25
+ )
26
+
27
+ event_metadata = event.metadata.tap do |h|
28
+ h['type'] = '$>'
29
+ h['content-type'] = 'application/octet-stream'
30
+ h.delete('encryption')
31
+ end
32
+
21
33
  payload = [
22
34
  request.new(
23
35
  options: {
@@ -33,12 +45,8 @@ module EventStoreClient
33
45
  string: event.id
34
46
  },
35
47
  data: event.title,
36
- custom_metadata: JSON.generate(
37
- "type": '$>',
38
- "content-type": 'application/vnd.eventstore.events+json',
39
- "created_at": Time.now
40
- ),
41
- metadata: event.metadata.tap { |h| h['type'] = '$>' }
48
+ custom_metadata: custom_metadata,
49
+ metadata: event_metadata
42
50
  }
43
51
  )
44
52
  ]
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'dry/monads'
3
4
  module EventStoreClient
4
5
  class InMemory
5
6
  Response = Struct.new(:body, :status) do
@@ -21,6 +22,7 @@ module EventStoreClient
21
22
  'positionEventNumber' => event_store[stream_name].length
22
23
  )
23
24
  end
25
+ Dry::Monads::Success()
24
26
  end
25
27
 
26
28
  def delete_stream(stream_name, options: {}) # rubocop:disable Lint/UnusedMethodArgument
@@ -44,9 +46,10 @@ module EventStoreClient
44
46
  res = Response.new(response.to_json, 200)
45
47
 
46
48
  return [] if res.body.nil? || res.body.empty?
47
- JSON.parse(res.body)['entries'].map do |entry|
49
+ events = JSON.parse(res.body)['entries'].map do |entry|
48
50
  deserialize_event(entry)
49
51
  end.reverse
52
+ Dry::Monads::Success(events)
50
53
  end
51
54
 
52
55
  def read_all_from_stream(stream_name, options: {})
@@ -24,11 +24,17 @@ module EventStoreClient
24
24
  @data = args.fetch(:data) { {} }
25
25
  @metadata = args.fetch(:metadata) { {} }.merge(
26
26
  'type' => self.class.name,
27
- 'content-type' => 'application/vnd.eventstore.events+json'
27
+ 'content-type' => content_type
28
28
  )
29
29
  @type = args[:type] || self.class.name
30
30
  @title = args[:title]
31
31
  @id = args[:id]
32
32
  end
33
+
34
+ def content_type
35
+ return 'application/octet-stream' if EventStoreClient.config.adapter == :grpc
36
+
37
+ 'application/vnd.eventstore.events+json'
38
+ end
33
39
  end
34
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
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.0
4
+ version: 1.0.1
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-16 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable