event_store_client 1.2.0 → 1.3.0

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: a4e812b6d0afb6200592432fd8561b9eb4a82eb35f3c97341996b2c57f8eb370
4
- data.tar.gz: bb704ed3eea51dd21b422e736d1aa793394d075a45ea6620b6f5b455bca712a4
3
+ metadata.gz: 700f420a0fa9e3fb0352784f3bc0431cac18216130ba397897dfb77c98a4f7c6
4
+ data.tar.gz: e408f3a666dd7f1e95634591923bf8df51ce30c6b521cd9042072f551e5ff645
5
5
  SHA512:
6
- metadata.gz: b099f9683c7e804bc89f89da3d2725abab47452a1dd52edc06b0a94a90ad3e5fc93eb19a296f2a4ea0f45cd4dc0553231a10a4679ae0ab3f8a2f3a80b34c6fb2
7
- data.tar.gz: a2986ef2a17e00a28c9745d237870071c8bad0851e931dbccafad88b9e38c5ff6958412682a90f565d275176af816d91ffa05cdaabf1459be1a803d0679cefa9
6
+ metadata.gz: 2232248c19c04924effd9bab97271f5a0bf3e7b4cf4e56e5453fc32a27c56d587777239b48d0aafc026c265b1086691aa5e8c04e7863209d9bb1e07c046946e6
7
+ data.tar.gz: 2db191ee47dae6f22b5858ab85bde4d3129af6220f534d9b11e502150058c7211285afa2562aae70ae08877e21c8d2205c8d1400ec8365e10567e7c5295b7afc
@@ -84,10 +84,12 @@ module EventStoreClient
84
84
  #
85
85
  def listen(subscription, options: {})
86
86
  consume_feed(subscription, options: options) do |event|
87
- yield event if block_given?
87
+ begin
88
+ yield event if block_given?
89
+ rescue StandardError => e
90
+ config.error_handler&.call(e)
91
+ end
88
92
  end
89
- rescue StandardError => e
90
- config.error_handler&.call(e)
91
93
  end
92
94
 
93
95
  # Subscribe to a stream
@@ -44,7 +44,12 @@ module EventStoreClient
44
44
  end
45
45
 
46
46
  skip_decryption = options[:skip_decryption] || false
47
- events = read_stream(opts, skip_decryption)
47
+ events =
48
+ if options[:skip_deserialization]
49
+ read_stream_raw(opts)
50
+ else
51
+ read_stream(opts, skip_decryption)
52
+ end
48
53
  Success(events)
49
54
  rescue StreamNotFound
50
55
  Failure(:not_found)
@@ -64,6 +69,18 @@ module EventStoreClient
64
69
  raise GRPCUnavailableRetryFailed
65
70
  end
66
71
 
72
+ def read_stream_raw(options)
73
+ retries ||= 0
74
+ service.read(request.new(options: options), metadata: metadata).map do |res|
75
+ raise StreamNotFound if res.stream_not_found
76
+ res.event.event
77
+ end
78
+ rescue ::GRPC::Unavailable
79
+ sleep config.grpc_unavailable_retry_sleep
80
+ retry if (retries += 1) <= config.grpc_unavailable_retry_count
81
+ raise GRPCUnavailableRetryFailed
82
+ end
83
+
67
84
  def deserialize_event(entry, skip_decryption: false)
68
85
  data = (entry.data.nil? || entry.data.empty?) ? '{}' : entry.data
69
86
 
@@ -5,6 +5,8 @@ module EventStoreClient
5
5
  FILTER_DEFAULT_MAX = 32
6
6
  FILTER_DEFAULT_CHECKPOINT_INTERVAL_MULTIPLIER = 10000
7
7
 
8
+ include Configuration
9
+
8
10
  def create_or_load(subscriber, filter: {})
9
11
  filter_options = prepare_filter_options(filter)
10
12
  position = subscription_store.load_all_position(CatchUpSubscription.name(subscriber))
@@ -41,10 +43,10 @@ module EventStoreClient
41
43
  logger&.info(msg)
42
44
  break
43
45
  end
44
- rescue StandardError
46
+ rescue StandardError => e
45
47
  subscription.position = old_position
46
48
  subscription_store.update_position(subscription)
47
- raise
49
+ config.error_handler&.call(e)
48
50
  end
49
51
  end
50
52
 
@@ -11,7 +11,7 @@ module EventStoreClient
11
11
 
12
12
  def publish(stream:, events:, options: {})
13
13
  res = connection.append_to_stream(stream, events, options: options)
14
- raise WrongExpectedEventVersion.new(e.message) if res.failure?
14
+ raise WrongExpectedEventVersion.new(res.failure) if res.failure?
15
15
  res
16
16
  end
17
17
 
@@ -15,14 +15,16 @@ module EventStoreClient
15
15
  end
16
16
  end
17
17
 
18
- def initialize(**args)
19
- validation = schema.call(args[:data] || {})
18
+ def initialize(args = {})
19
+ validation = schema.call(args[:data] || {}) unless args[:skip_validation]
20
20
  @data = args.fetch(:data) { {} }
21
21
  @metadata = args.fetch(:metadata) { {} }.merge(
22
22
  'type' => self.class.name,
23
23
  'content-type' => content_type
24
24
  )
25
- @metadata.merge!('validation-errors' => validation.errors.to_h) if validation.errors.any?
25
+ if !args[:skip_validation] && validation.errors.any?
26
+ @metadata.merge!('validation-errors' => validation.errors.to_h)
27
+ end
26
28
  @type = args[:type] || self.class.name
27
29
  @title = args[:title]
28
30
  @id = args[:id]
@@ -14,7 +14,7 @@ module EventStoreClient
14
14
 
15
15
  private
16
16
 
17
- def initialize(**args)
17
+ def initialize(args = {})
18
18
  args[:id] = SecureRandom.uuid if args[:id].nil?
19
19
  hash_meta = JSON.parse(args[:metadata] || '{}')
20
20
  hash_meta['created_at'] ||= Time.now
@@ -23,6 +23,7 @@ module EventStoreClient
23
23
  EventStoreClient::DeserializedEvent
24
24
  end
25
25
  event_class.new(
26
+ skip_validation: true,
26
27
  id: event.id,
27
28
  type: event.type,
28
29
  title: event.title,
@@ -51,7 +51,7 @@ module EventStoreClient
51
51
 
52
52
  def deserialize(event, skip_decryption: false)
53
53
  metadata = serializer.deserialize(event.metadata)
54
- encryption_schema = serializer.deserialize(event.metadata)['encryption']
54
+ encryption_schema = metadata['encryption']
55
55
 
56
56
  decrypted_data =
57
57
  if skip_decryption
@@ -72,6 +72,7 @@ module EventStoreClient
72
72
  end
73
73
 
74
74
  event_class.new(
75
+ skip_validation: true,
75
76
  id: event.id,
76
77
  type: event.type,
77
78
  title: event.title,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
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.2.0
4
+ version: 1.3.0
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-07-15 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
262
  - !ruby/object:Gem::Version
263
263
  version: '0'
264
264
  requirements: []
265
- rubygems_version: 3.1.4
265
+ rubygems_version: 3.1.0.pre1
266
266
  signing_key:
267
267
  specification_version: 4
268
268
  summary: Ruby integration for https://eventstore.org