evt-message_store-event_store 0.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 882072263a75671f82af6078e13729ae4587381e
4
+ data.tar.gz: fd21073a88d9c7982ffeb37c49e74aaf26329600
5
+ SHA512:
6
+ metadata.gz: b95e84d8e8f32fa0ddb3fb4f59c4e814f6eeeb6787b7a4322d5eee8fdae3dbec4739440cbe56d643f6f20796800059f560f456afcdcf48992f0870ed868968ce
7
+ data.tar.gz: 55dad20256f20529cddb4c44bc6417d3a8f64b2a9d8115f9a4b8e45a1db89be4759c0055796cc403a8b175ac48f8076996a4df9d2611f8152d527b26deaa12ff
@@ -0,0 +1,21 @@
1
+ require 'event_store/http'
2
+ require 'message_store'
3
+
4
+ require 'message_store/event_store/log'
5
+ require 'message_store/event_store/session'
6
+ require 'message_store/event_store/settings'
7
+
8
+ require 'message_store/event_store/stream_name'
9
+ require 'message_store/event_store/stream_name/pattern'
10
+
11
+ require 'message_store/event_store/get'
12
+ require 'message_store/event_store/get/assertions'
13
+ require 'message_store/event_store/get/last'
14
+ require 'message_store/event_store/get/result'
15
+
16
+ require 'message_store/event_store/put'
17
+
18
+ require 'message_store/event_store/write'
19
+
20
+ require 'message_store/event_store/read'
21
+ require 'message_store/event_store/read/iterator'
@@ -0,0 +1,13 @@
1
+ require 'identifier/uuid/controls'
2
+ require 'message_store/controls'
3
+ require 'event_store/http/controls'
4
+
5
+ require 'message_store/event_store/controls/write'
6
+
7
+ require 'message_store/event_store/controls/category'
8
+ require 'message_store/event_store/controls/stream_name'
9
+ require 'message_store/event_store/controls/uuid'
10
+
11
+ require 'message_store/event_store/controls/message_data'
12
+ require 'message_store/event_store/controls/message_data/event_id'
13
+ require 'message_store/event_store/controls/message_data/write'
@@ -0,0 +1,7 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ Category = MessageStore::Controls::Category
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ MessageData = MessageStore::Controls::MessageData
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ module MessageData
5
+ module EventID
6
+ def self.example
7
+ UUID.example
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ module MessageData
5
+ module Write
6
+ module Text
7
+ def self.example(event_id=nil, type: nil, data: nil, metadata: nil)
8
+ event_id ||= EventID.example
9
+
10
+ message_data = Write.example(type: type, data: data, metadata: metadata)
11
+
12
+ event_type = message_data.type
13
+ data = message_data.data
14
+ metadata = message_data.metadata
15
+
16
+ raw_data = {
17
+ 'eventId' => event_id,
18
+ 'eventType' => event_type,
19
+ 'data' => data
20
+ }
21
+
22
+ raw_data['metadata'] = metadata if metadata
23
+
24
+ JSON.pretty_generate [raw_data]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,7 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ Port = ::EventStore::HTTP::Connect::Controls::Port
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ Settings = ::EventStore::HTTP::Connect::Controls::Settings
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ module StreamName
5
+ def self.example(*arguments)
6
+ MessageStore::Controls::StreamName.example(*arguments)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ UUID = Identifier::UUID::Controls::Incrementing
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module Controls
4
+ module Write
5
+ def self.call(messages=nil, instances: nil, stream_name: nil)
6
+ stream_name ||= StreamName.example
7
+
8
+ if messages.nil?
9
+ instances ||= 1
10
+
11
+ messages = instances.times.map do |position|
12
+ MessageData::Write.example
13
+ end
14
+ else
15
+ messages = Array(messages)
16
+ end
17
+
18
+ ::EventStore::HTTP::Write.(messages, stream_name)
19
+
20
+ stream_name
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,68 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Get
4
+ include Log::Dependency
5
+
6
+ configure :get
7
+
8
+ initializer :batch_size, a(:long_poll_duration)
9
+
10
+ def batch_size
11
+ @batch_size ||= Defaults.batch_size
12
+ end
13
+
14
+ dependency :read_stream, ::EventStore::HTTP::ReadStream
15
+ dependency :session, Session
16
+
17
+ def self.build(batch_size: nil, long_poll_duration: nil, session: nil)
18
+ instance = new(batch_size, long_poll_duration)
19
+
20
+ Session.configure(instance, session: session)
21
+
22
+ session ||= instance.session
23
+ ::EventStore::HTTP::ReadStream.configure(instance, session: session)
24
+
25
+ instance.configure
26
+ instance
27
+ end
28
+
29
+ def self.call(stream_name, position: nil, **build_arguments)
30
+ instance = build(**build_arguments)
31
+ instance.(stream_name, position: position)
32
+ end
33
+
34
+ def configure
35
+ read_stream.embed_body
36
+ read_stream.output_schema = Result
37
+
38
+ unless long_poll_duration.nil?
39
+ read_stream.enable_long_poll(long_poll_duration)
40
+ end
41
+ end
42
+
43
+ def call(stream_name, position: nil)
44
+ logger.trace { "Reading stream (Stream Name: #{stream_name}, Position: #{position || '(start)'}, Batch Size: #{batch_size})" }
45
+
46
+ begin
47
+ messages = read_stream.(
48
+ stream_name,
49
+ position: position,
50
+ batch_size: batch_size
51
+ )
52
+ rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError
53
+ messages = []
54
+ end
55
+
56
+ logger.debug { "Done reading stream (Stream Name: #{stream_name}, Position: #{position || '(start)'}, Batch Size: #{batch_size}, Messages: #{messages.count})" }
57
+
58
+ messages
59
+ end
60
+
61
+ module Defaults
62
+ def self.batch_size
63
+ 20
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,27 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Get
4
+ module Assertions
5
+ def self.extended(get)
6
+ get.read_stream.extend(::EventStore::HTTP::Request::Assertions)
7
+ end
8
+
9
+ def long_poll_enabled?(value=nil)
10
+ duration = read_stream.long_poll_duration
11
+
12
+ if duration.nil?
13
+ false
14
+ elsif value.nil?
15
+ true
16
+ else
17
+ duration == value
18
+ end
19
+ end
20
+
21
+ def session?(session, strict: nil)
22
+ read_stream.session?(session, strict: strict)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Get
4
+ class Last
5
+ include Log::Dependency
6
+
7
+ configure :get_last
8
+
9
+ dependency :read_stream, ::EventStore::HTTP::ReadStream
10
+ dependency :session, Session
11
+
12
+ def self.build(session: nil)
13
+ instance = new
14
+ instance.configure(session: session)
15
+ instance
16
+ end
17
+
18
+ def self.call(stream_name, **build_arguments)
19
+ instance = build(**build_arguments)
20
+ instance.(stream_name)
21
+ end
22
+
23
+ def configure(session: nil)
24
+ session = Session.configure(self, session: session)
25
+
26
+ read_stream = ::EventStore::HTTP::ReadStream.configure(
27
+ self,
28
+ session: session
29
+ )
30
+
31
+ read_stream.embed_body
32
+ read_stream.output_schema = Result
33
+ end
34
+
35
+ def call(stream_name)
36
+ logger.trace { "Getting last message of stream (Stream Name: #{stream_name})" }
37
+
38
+ begin
39
+ message_data, * = read_stream.(
40
+ stream_name,
41
+ position: :head,
42
+ direction: :backward,
43
+ batch_size: 1
44
+ )
45
+ rescue ::EventStore::HTTP::ReadStream::StreamNotFoundError
46
+ end
47
+
48
+ logger.debug { "Got last message of stream (Stream Name: #{stream_name}, Message Type: #{message_data&.type.inspect}, Position: #{message_data&.position.inspect}, Global Position: #{message_data&.global_position.inspect})" }
49
+
50
+ message_data
51
+ end
52
+
53
+ Assertions = Get::Assertions
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Get
4
+ module Result
5
+ module Transformer
6
+ def self.json
7
+ JSON
8
+ end
9
+
10
+ def self.instance(raw_data)
11
+ entries = raw_data.fetch :entries
12
+
13
+ messages = []
14
+
15
+ entries.reverse_each do |atom_event|
16
+ message = MessageData::Read.new
17
+ message.id = atom_event.fetch(:event_id)
18
+ message.type = atom_event.fetch(:event_type)
19
+
20
+ data_text = atom_event.fetch(:data)
21
+ message.data = ::EventStore::HTTP::JSON::Deserialize.(data_text)
22
+
23
+ if atom_event.key?(:meta_data)
24
+ metadata_text = atom_event.fetch(:meta_data)
25
+ message.metadata = ::EventStore::HTTP::JSON::Deserialize.(metadata_text)
26
+ end
27
+
28
+ message.stream_name = atom_event.fetch(:stream_id)
29
+
30
+ message.position = atom_event.fetch(:event_number)
31
+ message.global_position = atom_event.fetch(:position_event_number)
32
+ message.time = Clock.parse atom_event.fetch(:updated)
33
+
34
+ messages << message
35
+ end
36
+
37
+ messages
38
+ end
39
+
40
+ module JSON
41
+ def self.read(text)
42
+ ::EventStore::HTTP::JSON::Deserialize.(text)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Log < ::Log
4
+ def tag!(tags)
5
+ tags << :message_store_event_store
6
+ tags << :message_store
7
+ tags << :library
8
+ tags << :verbose
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Put
4
+ include Log::Dependency
5
+
6
+ configure :put
7
+
8
+ dependency :write, ::EventStore::HTTP::Write
9
+
10
+ def self.build(session: nil)
11
+ session ||= Session.build
12
+
13
+ instance = new
14
+ ::EventStore::HTTP::Write.configure(instance, session: session)
15
+ instance
16
+ end
17
+
18
+ def self.call(message_data, stream_name, expected_version: nil, session: nil)
19
+ instance = build(session: session)
20
+ instance.(message_data, stream_name, expected_version: expected_version)
21
+ end
22
+
23
+ def call(messages, stream_name, expected_version: nil)
24
+ messages = Array(messages)
25
+
26
+ expected_version = ExpectedVersion.canonize(expected_version)
27
+
28
+ logger.trace { "Putting message data (Stream Name: #{stream_name}, Batch Size: #{messages.count}, Types: #{messages.map(&:type).inspect}, Expected Version: #{expected_version.inspect})" }
29
+
30
+ messages.each do |message_data|
31
+ message_data.metadata = nil if message_data.metadata&.empty?
32
+ end
33
+
34
+ begin
35
+ location = write.(
36
+ messages,
37
+ stream_name,
38
+ expected_version: expected_version
39
+ )
40
+ rescue ::EventStore::HTTP::Write::ExpectedVersionError => error
41
+ raise ExpectedVersion::Error, error.message
42
+ end
43
+
44
+ *, position = location.path.split '/'
45
+
46
+ logger.debug { "Put message data done (Stream Name: #{stream_name}, Batch Size: #{messages.count}, Types: #{messages.map(&:type).inspect}, Position: #{position}, Expected Version: #{expected_version.inspect})" }
47
+
48
+ position.to_i
49
+ end
50
+
51
+ module Assertions
52
+ def self.extended(put)
53
+ put.write.extend(::EventStore::HTTP::Request::Assertions)
54
+ end
55
+
56
+ def session?(session, strict: nil)
57
+ write.session?(session, strict: strict)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Read
4
+ include MessageStore::Read
5
+
6
+ def configure(session: nil)
7
+ Iterator.configure(self, stream_name, position: position)
8
+ Get.configure(self.iterator, batch_size: batch_size, session: session)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Read
4
+ class Iterator
5
+ include MessageStore::Read::Iterator
6
+
7
+ def last_position
8
+ batch.last.global_position
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module MessageStore
2
+ module EventStore
3
+ Session = ::EventStore::HTTP::Session
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MessageStore
2
+ module EventStore
3
+ Settings = ::EventStore::HTTP::Settings
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module StreamName
4
+ def self.stream_name(category_name, id=nil, type: nil, types: nil)
5
+ MessageStore::StreamName.stream_name(
6
+ category_name,
7
+ id,
8
+ type: type,
9
+ types: types
10
+ )
11
+ end
12
+
13
+ def self.get_id(stream_name)
14
+ match_data = parse(stream_name)
15
+ match_data[:stream_id]
16
+ end
17
+
18
+ def self.get_category(stream_name)
19
+ match_data = parse(stream_name)
20
+ match_data[:category]
21
+ end
22
+
23
+ def self.category?(stream_name)
24
+ match_data = parse(stream_name)
25
+ match_data[:stream_id].nil?
26
+ end
27
+
28
+ def self.get_type_list(stream_name)
29
+ match_data = parse(stream_name)
30
+ match_data[:type_list]
31
+ end
32
+
33
+ def self.get_types(stream_name)
34
+ type_list = get_type_list(stream_name)
35
+
36
+ return [] if type_list.nil?
37
+
38
+ type_list.split('+')
39
+ end
40
+
41
+ def self.get_entity_name(stream_name)
42
+ match_data = parse(stream_name)
43
+ match_data[:entity]
44
+ end
45
+
46
+ def self.parse(stream_name)
47
+ pattern = Pattern.get
48
+
49
+ pattern.match(stream_name)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,51 @@
1
+ module MessageStore
2
+ module EventStore
3
+ module StreamName
4
+ module Pattern
5
+ def self.get
6
+ @pattern ||= %r{
7
+ \A
8
+
9
+ #{optional(projection_prefix)}
10
+
11
+ #{category}
12
+
13
+ #{optional('-', stream_id)}
14
+
15
+ \z
16
+ }x
17
+ end
18
+
19
+ def self.optional(*parts)
20
+ inner_pattern = parts.join
21
+
22
+ /(?:#{inner_pattern})?/
23
+ end
24
+
25
+ def self.projection_prefix
26
+ /\$[[:alnum:]]+-/
27
+ end
28
+
29
+ def self.category
30
+ /(?<category>#{entity_and_type_list})/
31
+ end
32
+
33
+ def self.entity_and_type_list
34
+ /#{entity}#{optional(':', type_list)}/
35
+ end
36
+
37
+ def self.entity
38
+ /(?<entity>[^-:]+)/
39
+ end
40
+
41
+ def self.type_list
42
+ /(?<type_list>[[:alnum:]+]+)/
43
+ end
44
+
45
+ def self.stream_id
46
+ /(?<stream_id>[[:graph:]]+)/
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ module MessageStore
2
+ module EventStore
3
+ class Write
4
+ include MessageStore::Write
5
+
6
+ dependency :put, Put
7
+
8
+ def configure(session: nil)
9
+ Put.configure(self, session: session)
10
+ end
11
+
12
+ def write(batch, stream_name, expected_version: nil)
13
+ logger.trace { "Writing batch (Stream Name: #{stream_name}, Number of Messages: #{batch.count}, Expected Version: #{expected_version.inspect})" }
14
+
15
+ position = put.(batch, stream_name, expected_version: expected_version)
16
+
17
+ last_position = position + (batch.count - 1)
18
+
19
+ logger.debug { "Wrote batch (Stream Name: #{stream_name}, Number of Messages: #{batch.count}, Expected Version: #{expected_version.inspect}, Last Position: #{last_position})" }
20
+
21
+ last_position
22
+ end
23
+
24
+ module Assertions
25
+ def self.extended(write)
26
+ write.put.extend Put::Assertions
27
+ end
28
+
29
+ def session?(session, strict: nil)
30
+ put.session?(session, strict: strict)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-message_store-event_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evt-event_store-http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: evt-message_store
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test_bench
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: " "
56
+ email: opensource@eventide-project.org
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/message_store/event_store.rb
62
+ - lib/message_store/event_store/controls.rb
63
+ - lib/message_store/event_store/controls/category.rb
64
+ - lib/message_store/event_store/controls/message_data.rb
65
+ - lib/message_store/event_store/controls/message_data/event_id.rb
66
+ - lib/message_store/event_store/controls/message_data/write.rb
67
+ - lib/message_store/event_store/controls/port.rb
68
+ - lib/message_store/event_store/controls/settings.rb
69
+ - lib/message_store/event_store/controls/stream_name.rb
70
+ - lib/message_store/event_store/controls/uuid.rb
71
+ - lib/message_store/event_store/controls/write.rb
72
+ - lib/message_store/event_store/get.rb
73
+ - lib/message_store/event_store/get/assertions.rb
74
+ - lib/message_store/event_store/get/last.rb
75
+ - lib/message_store/event_store/get/result.rb
76
+ - lib/message_store/event_store/log.rb
77
+ - lib/message_store/event_store/put.rb
78
+ - lib/message_store/event_store/read.rb
79
+ - lib/message_store/event_store/read/iterator.rb
80
+ - lib/message_store/event_store/session.rb
81
+ - lib/message_store/event_store/settings.rb
82
+ - lib/message_store/event_store/stream_name.rb
83
+ - lib/message_store/event_store/stream_name/pattern.rb
84
+ - lib/message_store/event_store/write.rb
85
+ homepage: https://github.com/eventide-project/message-store-event-store
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 2.4.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Message store client for EventStore
109
+ test_files: []