ruby_event_store 0.38.1 → 0.39.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: ae2342adc48ba108f06f9232aa334244c40a5c9ed5ffcf3064ca2eb921e53085
4
- data.tar.gz: 1d31c578fe5c5be2fb6b23379d8f12262374baa06bfc256cedeec073bd319d8d
3
+ metadata.gz: 93c4fb13b69f6c54171be328e0bb2f10ad9172afbad3b367762a831754523700
4
+ data.tar.gz: e3ee2f58ed04b5df00c2e44685b9f6d1172fce73f8df639d35bae021930af3ae
5
5
  SHA512:
6
- metadata.gz: ba69556b416acc5ea6d559fd0e607fe57f25cea8ca97bab2796d1b86a353799ac0984635dc9102fbd2b7dd3630b1724d6b6630e2af511c7354027719887ada3c
7
- data.tar.gz: 71db45ebec0b62858655d20e71ed91fb30732ff4c714592b1d334c7f2fafba2bc1191431eecd726566378159f394076e978af22379a3efb1e5a6732895650480
6
+ metadata.gz: 3fd6b0a07e06ec3faf668a57e7564c8d151b567d0b24e07097042a29032ec9e598d430a9107c64d581dcb83f89a4ea52420798ee6039e7b08da5d417db337ef7
7
+ data.tar.gz: e7426bddb8d654198b340c7aba9d882cb2296bf379dab83dd6182cb824ff3fd3f2839cdc17f2ddd8d3bd4a5f0846cf38c82fa29d9925bc7cc0dac4852fcf9677
data/Gemfile CHANGED
@@ -1,8 +1,10 @@
1
1
  source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
2
4
  gemspec
3
5
 
4
- eval_gemfile File.expand_path('../lib/Gemfile.shared', __dir__)
6
+ eval_gemfile File.expand_path('../support/bundler/Gemfile.shared', __dir__)
5
7
 
6
8
  gem 'protobuf_nested_struct'
7
- gem 'google-protobuf', '= 3.6.1', source: 'https://gem.fury.io/pawelpacana/'
9
+ gem 'google-protobuf', '~> 3.7.0'
8
10
  gem 'activesupport', '~> 5.0'
data/Makefile CHANGED
@@ -7,12 +7,15 @@ IGNORE = RubyEventStore::InMemoryRepository\#append_with_synchronize \
7
7
  RubyEventStore::Client::Within\#call \
8
8
  RubyEventStore::Mappers::InMemoryEncryptionKeyRepository\#prepare_encrypt \
9
9
  RubyEventStore::Mappers::EncryptionKey\#prepare_encrypt \
10
- RubyEventStore::Mappers::EncryptionKey\#prepare_decrypt
10
+ RubyEventStore::Mappers::EncryptionKey\#prepare_decrypt \
11
+ RubyEventStore::Mappers::EncryptionKey\#prepare_auth_data \
12
+ RubyEventStore::Mappers::EncryptionKey\#encrypt_authenticated \
13
+ RubyEventStore::Mappers::EncryptionKey\#ciphertext_from_authenticated
11
14
 
12
15
  SUBJECT ?= RubyEventStore*
13
16
 
14
- include ../lib/install.mk
15
- include ../lib/test.mk
16
- include ../lib/mutant.mk
17
- include ../lib/gem.mk
18
- include ../lib/help.mk
17
+ include ../support/make/install.mk
18
+ include ../support/make/test.mk
19
+ include ../support/make/mutant.mk
20
+ include ../support/make/gem.mk
21
+ include ../support/make/help.mk
@@ -72,7 +72,7 @@ module RubyEventStore
72
72
  events = events.select{|e| spec.with_ids.any?{|x| x.eql?(e.event_id)}} if spec.with_ids?
73
73
  events = events.select{|e| spec.with_types.any?{|x| x.eql?(e.event_type)}} if spec.with_types?
74
74
  events = events.reverse if spec.backward?
75
- events = events.drop(index_of(events, spec.start) + 1) unless spec.head?
75
+ events = events.drop(index_of(events, spec.start) + 1) if spec.start
76
76
  events = events.take(index_of(events, spec.stop)) if spec.stop
77
77
  events = events[0...spec.limit] if spec.limit?
78
78
  events
@@ -25,7 +25,7 @@ module RubyEventStore
25
25
  end
26
26
 
27
27
  class InMemoryEncryptionKeyRepository
28
- DEFAULT_CIPHER = 'aes-256-cbc'.freeze
28
+ DEFAULT_CIPHER = 'aes-256-gcm'.freeze
29
29
 
30
30
  def initialize
31
31
  @keys = {}
@@ -63,14 +63,25 @@ module RubyEventStore
63
63
  crypto = prepare_encrypt(cipher)
64
64
  crypto.iv = iv
65
65
  crypto.key = key
66
- crypto.update(message) + crypto.final
66
+
67
+ if crypto.authenticated?
68
+ encrypt_authenticated(crypto, message)
69
+ else
70
+ crypto.update(message) + crypto.final
71
+ end
67
72
  end
68
73
 
69
74
  def decrypt(message, iv)
70
75
  crypto = prepare_decrypt(cipher)
71
76
  crypto.iv = iv
72
77
  crypto.key = key
73
- (crypto.update(message) + crypto.final).force_encoding("UTF-8")
78
+ ciphertext =
79
+ if crypto.authenticated?
80
+ ciphertext_from_authenticated(crypto, message)
81
+ else
82
+ message
83
+ end
84
+ (crypto.update(ciphertext) + crypto.final).force_encoding("UTF-8")
74
85
  end
75
86
 
76
87
  def random_iv
@@ -82,6 +93,22 @@ module RubyEventStore
82
93
 
83
94
  private
84
95
 
96
+ def ciphertext_from_authenticated(crypto, message)
97
+ prepare_auth_data(crypto)
98
+ crypto.auth_tag = message[-16...message.length]
99
+ message[0...-16]
100
+ end
101
+
102
+ def encrypt_authenticated(crypto, message)
103
+ prepare_auth_data(crypto)
104
+ crypto.update(message) + crypto.final + crypto.auth_tag
105
+ end
106
+
107
+ def prepare_auth_data(crypto)
108
+ crypto.auth_data = ""
109
+ crypto
110
+ end
111
+
85
112
  def prepare_encrypt(cipher)
86
113
  crypto = OpenSSL::Cipher.new(cipher)
87
114
  crypto.encrypt
@@ -1,13 +1,26 @@
1
+ require 'forwardable'
2
+
1
3
  module RubyEventStore
2
4
  module Mappers
3
5
  class NullMapper
4
- def event_to_serialized_record(domain_event)
5
- domain_event
6
+ extend Forwardable
7
+ class NULL
8
+ def self.dump(event)
9
+ event
10
+ end
11
+
12
+ def self.load(record)
13
+ record
14
+ end
6
15
  end
16
+ private_constant :NULL
7
17
 
8
- def serialized_record_to_event(record)
9
- record
18
+
19
+ def initialize
20
+ @mapper = Default.new(serializer: NULL)
10
21
  end
22
+
23
+ def_delegators :@mapper, :event_to_serialized_record, :serialized_record_to_event
11
24
  end
12
25
  end
13
26
  end
@@ -49,7 +49,7 @@ module RubyEventStore
49
49
  handlers.keys
50
50
  end
51
51
 
52
- def run(event_store, start: :head, count: PAGE_SIZE)
52
+ def run(event_store, start: nil, count: PAGE_SIZE)
53
53
  if streams.any?
54
54
  reduce_from_streams(event_store, start, count)
55
55
  else
@@ -60,7 +60,7 @@ module RubyEventStore
60
60
  private
61
61
 
62
62
  def valid_starting_point?(start)
63
- return true if start === :head
63
+ return true unless start
64
64
  if streams.any?
65
65
  (start.instance_of?(Array) && start.size === streams.size)
66
66
  else
@@ -69,19 +69,26 @@ module RubyEventStore
69
69
  end
70
70
 
71
71
  def reduce_from_streams(event_store, start, count)
72
- raise ArgumentError.new('Start must be an array with event ids or :head') unless valid_starting_point?(start)
72
+ raise ArgumentError.new('Start must be an array with event ids') unless valid_starting_point?(start)
73
73
  streams.zip(start_events(start)).reduce(initial_state) do |state, (stream_name, start_event_id)|
74
- event_store.read.in_batches(count).stream(stream_name).from(start_event_id).reduce(state, &method(:transition))
74
+ read_scope(event_store, stream_name, count, start_event_id).reduce(state, &method(:transition))
75
75
  end
76
76
  end
77
77
 
78
78
  def reduce_from_all_streams(event_store, start, count)
79
- raise ArgumentError.new('Start must be valid event id or :head') unless valid_starting_point?(start)
80
- event_store.read.in_batches(count).from(start).reduce(initial_state, &method(:transition))
79
+ raise ArgumentError.new('Start must be valid event id') unless valid_starting_point?(start)
80
+ read_scope(event_store, nil, count, start).reduce(initial_state, &method(:transition))
81
+ end
82
+
83
+ def read_scope(event_store, stream, count, start)
84
+ scope = event_store.read.in_batches(count)
85
+ scope = scope.stream(stream) if stream
86
+ scope = scope.from(start) if start
87
+ scope
81
88
  end
82
89
 
83
90
  def start_events(start)
84
- start === :head ? Array.new(streams.size) { :head } : start
91
+ start ? start : Array.new
85
92
  end
86
93
 
87
94
  def transition(state, event)
@@ -2,7 +2,7 @@ module RubyEventStore
2
2
  class SerializedRecord
3
3
  StringsRequired = Class.new(StandardError)
4
4
  def initialize(event_id:, data:, metadata:, event_type:)
5
- raise StringsRequired unless [event_id, data, metadata, event_type].all? { |v| v.instance_of?(String) }
5
+ raise StringsRequired unless [event_id, event_type].all? { |v| v.instance_of?(String) }
6
6
  @event_id = event_id
7
7
  @data = data
8
8
  @metadata = metadata
@@ -1212,9 +1212,7 @@ module RubyEventStore
1212
1212
  expect(repository.count(specification.stream('not-existing-stream').result)).to eq(0)
1213
1213
 
1214
1214
  repository.append_to_stream([SRecord.new(event_type: Type1.to_s)], dummy, version_any)
1215
- expect(repository.count(specification.from(:head).result)).to eq(5)
1216
1215
  expect(repository.count(specification.from(event_id).result)).to eq(1)
1217
- expect(repository.count(specification.stream("Dummy").from(:head).result)).to eq(2)
1218
1216
  expect(repository.count(specification.stream("Dummy").from(event_id).result)).to eq(1)
1219
1217
  expect(repository.count(specification.stream("Dummy").to(event_id).result)).to eq(0)
1220
1218
 
@@ -0,0 +1,17 @@
1
+ module RubyEventStore
2
+ RSpec.shared_examples :mapper do |mapper, domain_event|
3
+ specify "event_to_serialized_record returns instance of SerializedRecord" do
4
+ record = mapper.event_to_serialized_record(domain_event)
5
+
6
+ expect(record).to be_kind_of(SerializedRecord)
7
+ expect(record.event_id).to eq(domain_event.event_id)
8
+ expect(record.event_type).to eq(domain_event.type)
9
+ end
10
+
11
+ specify "serialize and deserialize gives equal event" do
12
+ record = mapper.event_to_serialized_record(domain_event)
13
+
14
+ expect(mapper.serialized_record_to_event(record)).to eq(domain_event)
15
+ end
16
+ end
17
+ end
@@ -22,23 +22,11 @@ module RubyEventStore
22
22
  # Limits the query to events before or after another event.
23
23
  # {http://railseventstore.org/docs/read/ Find out more}.
24
24
  #
25
- # @param start [:head, String] id of event to start reading from.
26
- # :head can mean the beginning or end of the stream, depending on the
27
- # #direction
25
+ # @param start [String] id of event to start reading from.
28
26
  # @return [Specification]
29
27
  def from(start)
30
- if start.equal?(:head)
31
- warn <<~EOW
32
- `:head` has been deprecated. Use event_id or skip from instead.
33
- EOW
34
- end
35
- case start
36
- when Symbol
37
- raise InvalidPageStart unless start.equal?(:head)
38
- else
39
- raise InvalidPageStart if start.nil? || start.empty?
40
- raise EventNotFound.new(start) unless reader.has_event?(start)
41
- end
28
+ raise InvalidPageStart if start.nil? || start.empty?
29
+ raise EventNotFound.new(start) unless reader.has_event?(start)
42
30
  Specification.new(reader, result.dup { |r| r.start = start })
43
31
  end
44
32
 
@@ -1,7 +1,7 @@
1
1
  module RubyEventStore
2
2
  class SpecificationResult
3
3
  def initialize(direction: :forward,
4
- start: :head,
4
+ start: nil,
5
5
  stop: nil,
6
6
  count: nil,
7
7
  stream: Stream.new(GLOBAL_STREAM),
@@ -38,18 +38,10 @@ module RubyEventStore
38
38
  attributes.stream
39
39
  end
40
40
 
41
- # Starting position. True is starting from head
41
+ # Starting position. Event id of starting event
42
42
  # {http://railseventstore.org/docs/read/ Find out more}.
43
43
  #
44
- # @return [Boolean]
45
- def head?
46
- start.equal?(:head)
47
- end
48
-
49
- # Starting position. Event id of starting event or :head
50
- # {http://railseventstore.org/docs/read/ Find out more}.
51
- #
52
- # @return [String|Symbol]
44
+ # @return [String]
53
45
  def start
54
46
  attributes.start
55
47
  end
@@ -1,3 +1,3 @@
1
1
  module RubyEventStore
2
- VERSION = "0.38.1"
2
+ VERSION = "0.39.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.1
4
+ version: 0.39.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -64,6 +64,7 @@ files:
64
64
  - lib/ruby_event_store/spec/dispatcher_lint.rb
65
65
  - lib/ruby_event_store/spec/event_lint.rb
66
66
  - lib/ruby_event_store/spec/event_repository_lint.rb
67
+ - lib/ruby_event_store/spec/mapper_lint.rb
67
68
  - lib/ruby_event_store/spec/scheduler_lint.rb
68
69
  - lib/ruby_event_store/spec/subscriptions_lint.rb
69
70
  - lib/ruby_event_store/specification.rb
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  requirements: []
99
- rubygems_version: 3.0.2
100
+ rubygems_version: 3.0.3
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: Event Store in Ruby