event_store_client 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82b73db66b7feef1d17e010f9e410476ab900bd6b137af03ee57106f2aefea6b
4
- data.tar.gz: 926d40bfa51a581de7f9e7942d7092e4e0f0d7c23d1c932cb689946ef3a690f5
3
+ metadata.gz: 3d4a4dc809c49fb6d9ab52ea68c6bfcb58217cb463d64e7591d5de7e0e5c80af
4
+ data.tar.gz: 29c38f7e04dd6b4b73a61966353ec51246037dfb6ffd25d38a8ebfc06c9faa8a
5
5
  SHA512:
6
- metadata.gz: 59dc478314bb1a15895dfe851248d6c1b62a381c26d03c8f7d1d18465a1407a28f007a959f2c655222b54dd310929df5430528125c3c97221393e3ce3b937256
7
- data.tar.gz: bb92b9f60639f5d0552c69b493e0e6dbb8e6985e89d7f4f78de6df45c12e6098554e7de13f8880e45fd84a8ddc8528eec778a78715ebd591fcc5c331709bea4a
6
+ metadata.gz: 4c15bb242df2456c57fbddd4dbe553113e803d26062081e1261ba134b64db2e445ae0f6a56a218555f3007e858c030212285749765aa941152fc6e395325acf6
7
+ data.tar.gz: 04654757ca1d4ed722255ac16d53cfa6415a7dc098ded62fbc91479fef681ed66f80ecd61e408f7a2f8bdafbf724cc4e1b9766c39f015cd79a799b327f15a3b3
@@ -2,16 +2,17 @@
2
2
 
3
3
  Configuration options:
4
4
 
5
- | name | value | default value | description |
6
- |----------------------|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7
- | eventstore_url | String | `'esdb://localhost:2113'` | Connection string. See description of possible values below. |
8
- | per_page | Integer | `20` | Number of events to return in one response. |
9
- | mapper | `EventStoreClient::Mapper::Default.new` or `EventStoreClient::Mapper::Encrypted.new` | `EventStoreClient::Mapper::Default.new` | An object that is responsible for serialization / deserialization and encryption / decryption of events. |
10
- | default_event_class | `DeserializedEvent` or any class, inherited from it | `DeserializedEvent` | This class will be used during the deserialization process when deserializer fails to resolve an event's class from response. |
11
- | logger | `Logger` | `nil` | A logger that would log messages from `event_store_client` and `grpc` gems. |
12
- | skip_deserialization | Boolean | `false` | Whether to skip event deserialization using the given `mapper` setting. If you set it to `true` decryption will be skipped as well. It is useful when you want to defer deserialization and handle it later by yourself. |
13
- | skip_decryption | Boolean | `false` | Whether to skip decrypting encrypted event payloads. |
14
- | channel_args | Hash | `{ 'grpc.min_reconnect_backoff_ms' => 100, 'grpc.max_reconnect_backoff_ms' => 100, 'grpc.initial_reconnect_backoff_ms' => 100 }` | GRPC-specific connection options. This hash will be passed into the `:channel_args` argument of a Stub class of your request. More GRPC options can be found [here](https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h). |
5
+ | name | value | default value | description |
6
+ |----------------------|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7
+ | eventstore_url | String | `'esdb://localhost:2113'` | Connection string. See description of possible values below. |
8
+ | per_page | Integer | `20` | Number of events to return in one response. |
9
+ | mapper | `EventStoreClient::Mapper::Default.new` or `EventStoreClient::Mapper::Encrypted.new` | `EventStoreClient::Mapper::Default.new` | An object that is responsible for serialization / deserialization and encryption / decryption of events. |
10
+ | default_event_class | `DeserializedEvent` or any class, inherited from it | `EventStoreClient::DeserializedEvent` | This class will be used during the deserialization process when deserializer fails to resolve an event's class from response. |
11
+ | event_class_resolver | `Proc` | `nil` | A Proc that accepts a string and returns event class. |
12
+ | logger | `Logger` | `nil` | A logger that would log messages from `event_store_client` and `grpc` gems. |
13
+ | skip_deserialization | Boolean | `false` | Whether to skip event deserialization using the given `mapper` setting. If you set it to `true` decryption will be skipped as well. It is useful when you want to defer deserialization and handle it later by yourself. |
14
+ | skip_decryption | Boolean | `false` | Whether to skip decrypting encrypted event payloads. |
15
+ | channel_args | Hash | `{ 'grpc.min_reconnect_backoff_ms' => 100, 'grpc.max_reconnect_backoff_ms' => 100, 'grpc.initial_reconnect_backoff_ms' => 100 }` | GRPC-specific connection options. This hash will be passed into the `:channel_args` argument of a Stub class of your request. More GRPC options can be found [here](https://github.com/grpc/grpc/blob/v1.55.1/include/grpc/impl/grpc_types.h#L141). |
15
16
 
16
17
  ## A note about channel_args option
17
18
 
@@ -23,6 +23,7 @@ module EventStoreClient
23
23
  # https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h
24
24
  option(:channel_args) # Hash
25
25
  option(:name) { :default }
26
+ option(:event_class_resolver) # Proc that excepts a string and returns a class
26
27
 
27
28
  def eventstore_url=(value)
28
29
  @eventstore_url =
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EventStoreClient
4
+ class EventClassResolver
5
+ attr_reader :config
6
+ private :config
7
+
8
+ # @param config [EventStoreClient::Config]
9
+ def initialize(config)
10
+ @config = config
11
+ end
12
+
13
+ # @param event_type [String, nil]
14
+ # @return [Class<EventStoreClient::DeserializedEvent>]
15
+ def resolve(event_type)
16
+ return config.event_class_resolver.(event_type) || config.default_event_class if config.event_class_resolver
17
+
18
+ Object.const_get(event_type)
19
+ rescue NameError, TypeError
20
+ config.logger&.debug(<<~TEXT.strip)
21
+ Unable to resolve class by `#{event_type}' event type. \
22
+ Picking default `#{config.default_event_class}' event class to instantiate the event.
23
+ TEXT
24
+ config.default_event_class
25
+ end
26
+ end
27
+ end
@@ -32,7 +32,8 @@ module EventStoreClient
32
32
  custom_metadata = serializer.deserialize(normalize_serialized(raw_event.custom_metadata))
33
33
  metadata = raw_event.metadata.to_h
34
34
 
35
- event_class(metadata['type']).new(
35
+ event_class = EventStoreClient::EventClassResolver.new(config).resolve(metadata['type'])
36
+ event_class.new(
36
37
  skip_validation: true,
37
38
  id: raw_event.id.string,
38
39
  title: "#{raw_event.stream_revision}@#{raw_event.stream_identifier.stream_name}",
@@ -49,18 +50,6 @@ module EventStoreClient
49
50
 
50
51
  private
51
52
 
52
- # @param event_type [String]
53
- # @return [Class<EventStoreClient::DeserializedEvent>]
54
- def event_class(event_type)
55
- Object.const_get(event_type)
56
- rescue NameError, TypeError
57
- config.logger&.debug(<<~TEXT.strip)
58
- Unable to resolve class by `#{event_type}' event type. \
59
- Picking default `#{config.default_event_class}' event class to instantiate the event.
60
- TEXT
61
- config.default_event_class
62
- end
63
-
64
53
  # @param raw_data [String]
65
54
  # @return [String]
66
55
  def normalize_serialized(raw_data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
@@ -17,6 +17,7 @@ require 'event_store_client/connection/url'
17
17
  require 'event_store_client/connection/url_parser'
18
18
  require 'event_store_client/deserialized_event'
19
19
  require 'event_store_client/serialized_event'
20
+ require 'event_store_client/event_class_resolver'
20
21
  require 'event_store_client/config'
21
22
 
22
23
  require 'event_store_client/mapper'
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: 3.1.0
4
+ version: 3.2.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: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2023-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -222,6 +222,7 @@ files:
222
222
  - lib/event_store_client/deserialized_event.rb
223
223
  - lib/event_store_client/encryption_metadata.rb
224
224
  - lib/event_store_client/errors.rb
225
+ - lib/event_store_client/event_class_resolver.rb
225
226
  - lib/event_store_client/extensions/options_extension.rb
226
227
  - lib/event_store_client/mapper.rb
227
228
  - lib/event_store_client/mapper/default.rb