ruby_event_store-protobuf 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +21 -0
- data/lib/ruby_event_store/protobuf.rb +30 -0
- data/lib/ruby_event_store/protobuf/mappers/protobuf.rb +24 -0
- data/lib/ruby_event_store/protobuf/mappers/transformation/proto_event.rb +22 -0
- data/lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb +46 -0
- data/lib/ruby_event_store/protobuf/mappers/transformation/protobuf_nested_struct_metadata.rb +45 -0
- data/lib/ruby_event_store/protobuf/version.rb +7 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 121764a1339325e2fcb9c412c2b6dc59fa0f622d13a146c47888c7e9867e3934
|
4
|
+
data.tar.gz: 4086449bb203b83c116dea628688b40e70a00e7f9679b71c98f2c0bff77ee7b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27db1e88a5ea0062eab49fe219d89c335ffbaf51511ccd3689e9b11e28c73e6d4dd02ce13c89a693f64b55042a35708b0d0ec1f538943640a996113418c4e721
|
7
|
+
data.tar.gz: 489b8652495a33ae80b7a397b419fe0b705d56402f830af2d099fb51c6975edbeefc06bffb7a872d7355cf1e98f21a6df480d92c992705777300134f94515e09
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Ruby Event Store Protobuf
|
2
|
+
|
3
|
+
Moved from RubyEventStore (based on version 1.3.0).
|
4
|
+
|
5
|
+
![Ruby Event Store Protobuf](https://github.com/RailsEventStore/rails_event_store/workflows/ruby_event_store-protobuf/badge.svg)
|
6
|
+
|
7
|
+
|
8
|
+
## How to use this gem
|
9
|
+
|
10
|
+
Add to your gemfile in application:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "ruby_event_store-protobuf"
|
14
|
+
```
|
15
|
+
|
16
|
+
Read more about [using Rails Event Store with Protobuf](https://railseventstore.org/docs/v2/protobuf/#configure-protobuf-mapper)
|
17
|
+
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RailsEventStore/rails_event_store.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby_event_store'
|
4
|
+
|
5
|
+
module RubyEventStore
|
6
|
+
ProtobufEncodingFailed = Class.new(Error)
|
7
|
+
|
8
|
+
module Protobuf
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require_relative 'protobuf/mappers/transformation/proto_event'
|
13
|
+
require_relative 'protobuf/mappers/transformation/protobuf_encoder'
|
14
|
+
require_relative 'protobuf/mappers/transformation/protobuf_nested_struct_metadata'
|
15
|
+
require_relative 'protobuf/mappers/protobuf'
|
16
|
+
require_relative 'protobuf/version'
|
17
|
+
|
18
|
+
module RubyEventStore
|
19
|
+
Proto = Protobuf::Proto
|
20
|
+
|
21
|
+
module Mappers
|
22
|
+
Protobuf = RubyEventStore::Protobuf::Mappers::Protobuf
|
23
|
+
|
24
|
+
module Transformation
|
25
|
+
ProtoEvent = RubyEventStore::Protobuf::Mappers::Transformation::ProtoEvent
|
26
|
+
ProtobufEncoder = RubyEventStore::Protobuf::Mappers::Transformation::ProtobufEncoder
|
27
|
+
ProtobufNestedStructMetadata = RubyEventStore::Protobuf::Mappers::Transformation::ProtobufNestedStructMetadata
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Protobuf
|
5
|
+
class Proto < RubyEventStore::Event
|
6
|
+
def event_type
|
7
|
+
data.class.descriptor.name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Mappers
|
12
|
+
class Protobuf < RubyEventStore::Mappers::PipelineMapper
|
13
|
+
def initialize(events_class_remapping: {})
|
14
|
+
super(RubyEventStore::Mappers::Pipeline.new(
|
15
|
+
Transformation::ProtobufEncoder.new,
|
16
|
+
RubyEventStore::Mappers::Transformation::EventClassRemapper.new(events_class_remapping),
|
17
|
+
Transformation::ProtobufNestedStructMetadata.new,
|
18
|
+
to_domain_event: Transformation::ProtoEvent.new,
|
19
|
+
))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Protobuf
|
5
|
+
module Mappers
|
6
|
+
module Transformation
|
7
|
+
class ProtoEvent < RubyEventStore::Mappers::Transformation::DomainEvent
|
8
|
+
def load(record)
|
9
|
+
Proto.new(
|
10
|
+
event_id: record.event_id,
|
11
|
+
data: record.data,
|
12
|
+
metadata: record.metadata.merge(
|
13
|
+
timestamp: record.timestamp,
|
14
|
+
valid_at: record.valid_at,
|
15
|
+
),
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Protobuf
|
5
|
+
module Mappers
|
6
|
+
module Transformation
|
7
|
+
class ProtobufEncoder
|
8
|
+
def dump(record)
|
9
|
+
Record.new(
|
10
|
+
event_id: record.event_id,
|
11
|
+
event_type: record.event_type,
|
12
|
+
data: encode_data(record.data),
|
13
|
+
metadata: record.metadata,
|
14
|
+
timestamp: record.timestamp,
|
15
|
+
valid_at: record.valid_at,
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def load(record)
|
20
|
+
Record.new(
|
21
|
+
event_id: record.event_id,
|
22
|
+
event_type: record.event_type,
|
23
|
+
data: load_data(record.event_type, record.data),
|
24
|
+
metadata: record.metadata,
|
25
|
+
timestamp: record.timestamp,
|
26
|
+
valid_at: record.valid_at,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def encode_data(data)
|
32
|
+
begin
|
33
|
+
data.class.encode(data)
|
34
|
+
rescue NoMethodError
|
35
|
+
raise ProtobufEncodingFailed
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_data(event_type, protobuf_data)
|
40
|
+
Google::Protobuf::DescriptorPool.generated_pool.lookup(event_type).msgclass.decode(protobuf_data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyEventStore
|
4
|
+
module Protobuf
|
5
|
+
module Mappers
|
6
|
+
module Transformation
|
7
|
+
class ProtobufNestedStructMetadata
|
8
|
+
def initialize
|
9
|
+
require_optional_dependency
|
10
|
+
end
|
11
|
+
|
12
|
+
def dump(record)
|
13
|
+
Record.new(
|
14
|
+
event_id: record.event_id,
|
15
|
+
event_type: record.event_type,
|
16
|
+
data: record.data,
|
17
|
+
metadata: ProtobufNestedStruct::HashMapStringValue.dump(record.metadata),
|
18
|
+
timestamp: record.timestamp,
|
19
|
+
valid_at: record.valid_at,
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def load(record)
|
24
|
+
RubyEventStore::Mappers::Transformation::SymbolizeMetadataKeys.new.load(
|
25
|
+
Record.new(
|
26
|
+
event_id: record.event_id,
|
27
|
+
event_type: record.event_type,
|
28
|
+
data: record.data,
|
29
|
+
metadata: ProtobufNestedStruct::HashMapStringValue.load(record.metadata),
|
30
|
+
timestamp: record.timestamp,
|
31
|
+
valid_at: record.valid_at,
|
32
|
+
)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def require_optional_dependency
|
37
|
+
require 'protobuf_nested_struct'
|
38
|
+
rescue LoadError
|
39
|
+
raise LoadError, "cannot load such file -- protobuf_nested_struct. Add protobuf_nested_struct gem to Gemfile"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_event_store-protobuf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arkency
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby_event_store
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
description:
|
34
|
+
email: dev@arkency.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files:
|
38
|
+
- README.md
|
39
|
+
files:
|
40
|
+
- README.md
|
41
|
+
- lib/ruby_event_store/protobuf.rb
|
42
|
+
- lib/ruby_event_store/protobuf/mappers/protobuf.rb
|
43
|
+
- lib/ruby_event_store/protobuf/mappers/transformation/proto_event.rb
|
44
|
+
- lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb
|
45
|
+
- lib/ruby_event_store/protobuf/mappers/transformation/protobuf_nested_struct_metadata.rb
|
46
|
+
- lib/ruby_event_store/protobuf/version.rb
|
47
|
+
homepage: https://railseventstore.org
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
homepage_uri: https://railseventstore.org
|
52
|
+
source_code_uri: https://github.com/RailsEventStore/rails_event_store
|
53
|
+
bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.5'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.1.4
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Protobuf support for Ruby Event Store
|
73
|
+
test_files: []
|