evt-entity_snapshot-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: 42b986a9cc2c9020fd59b436f10cfc8a50a15748
4
+ data.tar.gz: 95d77e3c349097f54285300b4c79aa68e107f710
5
+ SHA512:
6
+ metadata.gz: 5b42e0d0b82b3fe44c953fa80ebafb45fc26ec1780a7b5b5084cac3b87d9c9fbb050ab2652197ad26774a6d756fbcbc78abed2d6f5484c5181d382c2b473897f
7
+ data.tar.gz: a6ccb6dfe4957c30e8ad898d7b412b81d9a264aad12c2b47f00e4d1a3e71c602dca03b04a94ef0d20dc3d9691b72ca56f6ca47c0f104ec4ac473cc26b4f5cbd6
@@ -0,0 +1,6 @@
1
+ require 'messaging/event_store'
2
+ require 'entity_store'
3
+
4
+ require 'entity_snapshot/event_store/log'
5
+ require 'entity_snapshot/event_store/recorded'
6
+ require 'entity_snapshot/event_store/event_store'
@@ -0,0 +1,12 @@
1
+ require 'entity_store/controls'
2
+
3
+ require 'entity_snapshot/event_store/controls/time'
4
+ require 'entity_snapshot/event_store/controls/id'
5
+ require 'entity_snapshot/event_store/controls/stream_name'
6
+ require 'entity_snapshot/event_store/controls/version'
7
+ require 'entity_snapshot/event_store/controls/message'
8
+ require 'entity_snapshot/event_store/controls/batch'
9
+ require 'entity_snapshot/event_store/controls/entity'
10
+ require 'entity_snapshot/event_store/controls/snapshot'
11
+ require 'entity_snapshot/event_store/controls/write'
12
+ require 'entity_snapshot/event_store/controls/entity_store'
@@ -0,0 +1,20 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module Batch
5
+ def self.example(count: nil, starting_number: nil)
6
+ count ||= 2
7
+ starting_number ||= 1
8
+
9
+ batch = []
10
+ count.times do |i|
11
+ number = ('1' * (i + starting_number)).to_i
12
+ batch << Controls::Message.example(number: number)
13
+ end
14
+
15
+ batch
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module Entity
5
+ def self.example
6
+ Example.build(Data.example)
7
+ end
8
+
9
+ class Example
10
+ include Schema::DataStructure
11
+
12
+ attribute :some_attribute
13
+
14
+ module Transformer
15
+ def self.raw_data(instance)
16
+ instance.to_h
17
+ end
18
+
19
+ def self.instance(raw_data)
20
+ Example.build(raw_data)
21
+ end
22
+ end
23
+ end
24
+
25
+ module Data
26
+ def self.example
27
+ {
28
+ some_attribute: MessageStore::Controls::RandomValue.example
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module EntityStore
5
+ def self.example(category: nil, entity_class: nil, projection_class: nil, snapshot_interval: nil)
6
+ reader_class = MessageStore::EventStore::Read
7
+ snapshot_class = EntitySnapshot::EventStore
8
+ snapshot_interval ||= 2
9
+ category ||= 'example'
10
+ ::EntityStore::Controls::EntityStore.example(category: category, entity_class: entity_class, projection_class: projection_class, reader_class: reader_class, snapshot_class: snapshot_class, snapshot_interval: snapshot_interval)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ ID = EntityStore::Controls::ID
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module Message
5
+ def self.example(number: nil)
6
+ number ||= 1
7
+ Example.build number: number
8
+ end
9
+
10
+ def self.first
11
+ Example.build :number => 1
12
+ end
13
+
14
+ def self.second
15
+ Example.build :number => 11
16
+ end
17
+
18
+ class Example
19
+ include Messaging::Message
20
+
21
+ attribute :number
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module Snapshot
5
+ def self.example
6
+ EntitySnapshot::EventStore.build(Controls::Entity::Example)
7
+ end
8
+
9
+ def self.subject
10
+ Controls::Entity::Example
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ StreamName = EntityStore::Controls::StreamName
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ Time = EntityCache::Controls::Time
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ Version = EntityStore::Controls::Version
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ module Controls
4
+ module Write
5
+ def self.batch(stream_name: nil, category: nil, count: nil, starting_number: nil)
6
+ stream_name ||= Controls::StreamName.example(category: category)
7
+
8
+ write = ::Messaging::EventStore::Write.build
9
+
10
+ batch = Batch.example(count: count, starting_number: starting_number)
11
+
12
+ write.(batch, stream_name)
13
+
14
+ stream_name
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ include Log::Dependency
4
+ include EntityCache::Storage::Persistent
5
+
6
+ dependency :write, MessageStore::EventStore::Write
7
+ dependency :read, MessageStore::EventStore::Get::Last
8
+
9
+ attr_accessor :session
10
+
11
+ alias_method :entity_class, :subject
12
+
13
+ def snapshot_stream_name(id)
14
+ entity_class_name = entity_class.name.split('::').last
15
+ entity_category = Casing::Camel.(entity_class_name)
16
+
17
+ Messaging::StreamName.stream_name(id, entity_category, type: 'snapshot')
18
+ end
19
+
20
+ def configure(session: nil)
21
+ MessageStore::EventStore::Session.configure(self, session: session)
22
+ MessageStore::EventStore::Write.configure(self, session: self.session, attr_name: :write)
23
+ MessageStore::EventStore::Get::Last.configure(self, session: self.session, attr_name: :read)
24
+ end
25
+
26
+ def put(id, entity, version, time)
27
+ unless entity.is_a? subject
28
+ raise Error, "Persistent storage for #{subject} cannot store #{entity}"
29
+ end
30
+
31
+ stream_name = snapshot_stream_name(id)
32
+
33
+ logger.trace "Writing snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time})"
34
+
35
+ entity_data = Transform::Write.raw_data(entity)
36
+
37
+ event_data = MessageStore::MessageData::Write.new
38
+
39
+ data = {
40
+ entity_data: entity_data,
41
+ entity_version: version
42
+ }
43
+
44
+ event_data.type = 'Recorded'
45
+ event_data.data = data
46
+
47
+ position = write.(event_data, stream_name)
48
+
49
+ logger.debug "Wrote snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity.class.name}, Version: #{version.inspect}, Time: #{time})"
50
+
51
+ position
52
+ end
53
+
54
+ def get(id)
55
+ stream_name = snapshot_stream_name(id)
56
+
57
+ logger.trace "Reading snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name})"
58
+
59
+ event_data = read.(stream_name)
60
+
61
+ if event_data.nil?
62
+ logger.debug "No snapshot could not be read (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name})"
63
+ return
64
+ end
65
+
66
+ entity = entity_class.build(event_data.data[:entity_data])
67
+ version = event_data.data[:entity_version]
68
+ time = event_data.time
69
+
70
+ logger.debug "Read snapshot (Stream: #{stream_name.inspect}, Entity Class: #{entity_class.name}, Version: #{version.inspect}, Time: #{time})"
71
+
72
+ return entity, version, time
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,11 @@
1
+ module EntitySnapshot
2
+ class EventStore
3
+ class Log < ::Log
4
+ def tag!(tags)
5
+ tags << :entity_snapshot_event_store
6
+ tags << :library
7
+ tags << :verbose
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module EntitySnapshot
2
+ class Recorded
3
+ include Messaging::Message
4
+
5
+ attribute :entity_data
6
+ attribute :entity_version
7
+
8
+ module Serializer
9
+ def self.raw_data(instance)
10
+ instance.to_h
11
+ end
12
+
13
+ def self.instance(raw_data)
14
+ Message.build raw_data
15
+ end
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-entity_snapshot-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-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evt-entity_store
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-messaging-event_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/entity_snapshot/event_store.rb
62
+ - lib/entity_snapshot/event_store/controls.rb
63
+ - lib/entity_snapshot/event_store/controls/batch.rb
64
+ - lib/entity_snapshot/event_store/controls/entity.rb
65
+ - lib/entity_snapshot/event_store/controls/entity_store.rb
66
+ - lib/entity_snapshot/event_store/controls/id.rb
67
+ - lib/entity_snapshot/event_store/controls/message.rb
68
+ - lib/entity_snapshot/event_store/controls/snapshot.rb
69
+ - lib/entity_snapshot/event_store/controls/stream_name.rb
70
+ - lib/entity_snapshot/event_store/controls/time.rb
71
+ - lib/entity_snapshot/event_store/controls/version.rb
72
+ - lib/entity_snapshot/event_store/controls/write.rb
73
+ - lib/entity_snapshot/event_store/event_store.rb
74
+ - lib/entity_snapshot/event_store/log.rb
75
+ - lib/entity_snapshot/event_store/recorded.rb
76
+ homepage: https://github.com/eventide-project/entity-snapshot-event-store
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.4.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Projected entity snapshotting for EventStore
100
+ test_files: []