cdc-core 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +12 -4
- data/lib/cdc/core/change_event.rb +10 -5
- data/lib/cdc/core/column_change.rb +4 -4
- data/lib/cdc/core/composite_processor.rb +3 -3
- data/lib/cdc/core/event_metadata.rb +14 -9
- data/lib/cdc/core/event_position.rb +1 -1
- data/lib/cdc/core/filter.rb +8 -8
- data/lib/cdc/core/observer.rb +24 -19
- data/lib/cdc/core/ordering_key.rb +8 -3
- data/lib/cdc/core/ordering_policy.rb +12 -9
- data/lib/cdc/core/pipeline.rb +5 -5
- data/lib/cdc/core/processor.rb +7 -7
- data/lib/cdc/core/processor_chain.rb +1 -1
- data/lib/cdc/core/processor_result.rb +18 -14
- data/lib/cdc/core/router.rb +6 -6
- data/lib/cdc/core/source_adapter.rb +2 -2
- data/lib/cdc/core/transaction_envelope.rb +9 -4
- data/lib/cdc/core/version.rb +1 -1
- data/sig/cdc/core/change_event.rbs +34 -216
- data/sig/cdc/core/column_change.rbs +4 -43
- data/sig/cdc/core/composite_processor.rbs +11 -54
- data/sig/cdc/core/errors.rbs +1 -7
- data/sig/cdc/core/event_metadata.rbs +7 -39
- data/sig/cdc/core/event_position.rbs +12 -12
- data/sig/cdc/core/filter.rbs +11 -62
- data/sig/cdc/core/null_observer.rbs +1 -2
- data/sig/cdc/core/observer.rbs +11 -13
- data/sig/cdc/core/operation.rbs +7 -29
- data/sig/cdc/core/ordering_key.rbs +5 -7
- data/sig/cdc/core/ordering_policy.rbs +10 -15
- data/sig/cdc/core/ordering_scope.rbs +7 -5
- data/sig/cdc/core/pipeline.rbs +9 -54
- data/sig/cdc/core/processor.rbs +5 -56
- data/sig/cdc/core/processor_chain.rbs +8 -35
- data/sig/cdc/core/processor_result.rbs +32 -125
- data/sig/cdc/core/router.rbs +12 -13
- data/sig/cdc/core/source_adapter.rbs +2 -4
- data/sig/cdc/core/transaction_envelope.rbs +17 -71
- data/sig/cdc/core/version.rbs +1 -2
- data/sig/cdc/core.rbs +28 -7
- data/sig/cdc_core.rbs +4 -0
- metadata +2 -2
|
@@ -1,137 +1,44 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Result returned by processors and pipelines.
|
|
4
|
-
#
|
|
5
|
-
# ProcessorResult standardizes processor outcomes so callers can distinguish
|
|
6
|
-
# successful processing, skipped events, and failures without relying on
|
|
7
|
-
# processor-specific return values.
|
|
8
3
|
class ProcessorResult
|
|
9
|
-
VALID_STATUSES:
|
|
10
|
-
|
|
4
|
+
VALID_STATUSES: ::Array[Symbol]
|
|
5
|
+
EMPTY_METADATA: metadata_hash
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@value: untyped
|
|
15
|
-
|
|
16
|
-
@error: untyped
|
|
17
|
-
|
|
18
|
-
@metadata: untyped
|
|
19
|
-
|
|
20
|
-
# @return [Symbol] result status
|
|
21
|
-
# @return [ChangeEvent, nil] event associated with the result
|
|
22
|
-
# @return [Exception, nil] failure error, when status is :failure
|
|
23
|
-
# @return [EventMetadata] result metadata
|
|
24
|
-
attr_reader status: untyped
|
|
25
|
-
|
|
26
|
-
# @return [Symbol] result status
|
|
27
|
-
# @return [ChangeEvent, nil] event associated with the result
|
|
28
|
-
# @return [Exception, nil] failure error, when status is :failure
|
|
29
|
-
# @return [EventMetadata] result metadata
|
|
7
|
+
attr_reader status: Symbol
|
|
30
8
|
attr_reader event: untyped
|
|
31
|
-
|
|
32
|
-
# @return [Object, nil] value produced by the processor
|
|
33
9
|
attr_reader value: untyped
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
# Build a failure result.
|
|
55
|
-
#
|
|
56
|
-
# @param error [Exception] processor error
|
|
57
|
-
# @param event [ChangeEvent, nil] event being processed
|
|
58
|
-
# @param reason [String, nil] human-readable failure reason
|
|
59
|
-
# @param retryable [Boolean, nil] whether the failure can be retried
|
|
60
|
-
# @param processor [String, nil] processor name associated with the failure
|
|
61
|
-
# @param failed_at [String, nil] timestamp for when the failure occurred
|
|
62
|
-
# @param metadata [Hash, EventMetadata] result metadata
|
|
63
|
-
# @return [ProcessorResult]
|
|
64
|
-
def self.failure: (untyped error, ?event: untyped?, ?reason: untyped?, ?retryable: untyped?, ?processor: untyped?, ?failed_at: untyped?, ?metadata: untyped) -> untyped
|
|
65
|
-
|
|
66
|
-
# Build a skipped result.
|
|
67
|
-
#
|
|
68
|
-
# @param event [ChangeEvent, nil] skipped event
|
|
69
|
-
# @param metadata [Hash, EventMetadata] result metadata
|
|
70
|
-
# @return [ProcessorResult]
|
|
71
|
-
def self.skipped: (?untyped? event, ?metadata: ::Hash[untyped, untyped]) -> untyped
|
|
72
|
-
|
|
73
|
-
# Build a processor result with an explicit status.
|
|
74
|
-
#
|
|
75
|
-
# @param status [#to_sym] result status
|
|
76
|
-
# @param event [ChangeEvent, nil] associated event
|
|
77
|
-
# @param error [Exception, nil] associated failure
|
|
78
|
-
# @param metadata [Hash, EventMetadata] result metadata
|
|
79
|
-
def initialize: (untyped status, ?event: untyped?, ?error: untyped?, ?metadata: ::Hash[untyped, untyped], ?value: untyped?) -> void
|
|
80
|
-
|
|
81
|
-
# @return [Boolean] true when status is :success
|
|
82
|
-
def success?: () -> untyped
|
|
83
|
-
|
|
84
|
-
# @return [Boolean] true when status is :failure
|
|
85
|
-
def failure?: () -> untyped
|
|
86
|
-
|
|
87
|
-
# @return [Boolean] true when status is :skipped
|
|
88
|
-
def skipped?: () -> untyped
|
|
89
|
-
|
|
90
|
-
# Human-readable failure reason, when present.
|
|
91
|
-
#
|
|
92
|
-
# @return [String, nil]
|
|
93
|
-
def failure_reason: () -> untyped
|
|
94
|
-
|
|
95
|
-
# Whether the failure is retryable.
|
|
96
|
-
#
|
|
97
|
-
# @return [Boolean]
|
|
10
|
+
attr_reader error: ::Exception?
|
|
11
|
+
attr_reader metadata: EventMetadata
|
|
12
|
+
|
|
13
|
+
def self.success: (?untyped event, ?metadata: EventMetadata | metadata_hash, ?value: untyped) -> ProcessorResult
|
|
14
|
+
def self.failure: (
|
|
15
|
+
::Exception error,
|
|
16
|
+
?event: untyped,
|
|
17
|
+
?reason: String?,
|
|
18
|
+
?retryable: bool?,
|
|
19
|
+
?processor: String?,
|
|
20
|
+
?failed_at: String?,
|
|
21
|
+
?metadata: EventMetadata | metadata_hash?
|
|
22
|
+
) -> ProcessorResult
|
|
23
|
+
def self.skipped: (?untyped event, ?metadata: EventMetadata | metadata_hash) -> ProcessorResult
|
|
24
|
+
|
|
25
|
+
def initialize: (Symbol | String status, ?event: untyped, ?error: ::Exception?, ?metadata: EventMetadata | metadata_hash, ?value: untyped) -> void
|
|
26
|
+
def success?: () -> bool
|
|
27
|
+
def failure?: () -> bool
|
|
28
|
+
def skipped?: () -> bool
|
|
29
|
+
def failure_reason: () -> String?
|
|
98
30
|
def retryable?: () -> bool
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def
|
|
104
|
-
|
|
105
|
-
# Timestamp for when the failure occurred, when present.
|
|
106
|
-
#
|
|
107
|
-
# @return [String, nil]
|
|
108
|
-
def failed_at: () -> untyped
|
|
109
|
-
|
|
110
|
-
# Error class name, when present.
|
|
111
|
-
#
|
|
112
|
-
# @return [String, nil]
|
|
113
|
-
def error_class: () -> untyped
|
|
114
|
-
|
|
115
|
-
# Error message, when present.
|
|
116
|
-
#
|
|
117
|
-
# @return [String, nil]
|
|
118
|
-
def error_message: () -> untyped
|
|
119
|
-
|
|
120
|
-
# Error backtrace, when present.
|
|
121
|
-
#
|
|
122
|
-
# @return [Array<String>]
|
|
123
|
-
def error_backtrace: () -> untyped
|
|
124
|
-
|
|
125
|
-
# Convert the result into a shareable hash.
|
|
126
|
-
#
|
|
127
|
-
# @return [Hash{String=>Object,nil}]
|
|
128
|
-
def to_h: () -> untyped
|
|
31
|
+
def processor_name: () -> String?
|
|
32
|
+
def failed_at: () -> String?
|
|
33
|
+
def error_class: () -> String?
|
|
34
|
+
def error_message: () -> String?
|
|
35
|
+
def error_backtrace: () -> ::Array[String]
|
|
36
|
+
def to_h: () -> shareable_hash
|
|
129
37
|
|
|
130
38
|
private
|
|
131
|
-
|
|
132
|
-
def make_shareable_when_possible: () ->
|
|
133
|
-
|
|
134
|
-
def normalize_status: (untyped status) -> untyped
|
|
39
|
+
|
|
40
|
+
def make_shareable_when_possible: () -> self?
|
|
41
|
+
def normalize_status: (Symbol | String status) -> Symbol
|
|
135
42
|
end
|
|
136
43
|
end
|
|
137
44
|
end
|
data/sig/cdc/core/router.rbs
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Routes CDC work items to the appropriate handler.
|
|
4
3
|
class Router
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
attr_reader processor: _RoutableProcessor
|
|
5
|
+
attr_reader transaction_processor: _ProcessorLike?
|
|
6
|
+
attr_reader observer: Observer
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
def initialize: (
|
|
9
|
+
processor: _RoutableProcessor,
|
|
10
|
+
?transaction_processor: _ProcessorLike?,
|
|
11
|
+
?observer: Observer?
|
|
12
|
+
) -> void
|
|
13
|
+
|
|
14
|
+
def process: (work_item item) -> untyped
|
|
15
15
|
|
|
16
16
|
private
|
|
17
17
|
|
|
18
|
-
def route_transaction: (
|
|
19
|
-
def route_many: (untyped items) -> untyped
|
|
18
|
+
def route_transaction: (TransactionEnvelope transaction) -> untyped
|
|
19
|
+
def route_many: (::Array[untyped] items) -> untyped
|
|
20
20
|
def observe_result: (untyped result) -> untyped
|
|
21
|
-
def observe_results: (untyped results) -> untyped
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
end
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
# Base class for source adapters that normalize upstream payloads into CDC
|
|
2
|
-
# core domain objects.
|
|
3
1
|
module CDC
|
|
4
2
|
module Core
|
|
5
3
|
class SourceAdapter
|
|
6
|
-
def normalize: (untyped input) ->
|
|
7
|
-
def normalize_many: (untyped inputs) -> ::Array[
|
|
4
|
+
def normalize: (untyped input) -> normalized_object
|
|
5
|
+
def normalize_many: (::Enumerable[untyped] inputs) -> ::Array[ChangeEvent | TransactionEnvelope]
|
|
8
6
|
end
|
|
9
7
|
end
|
|
10
8
|
end
|
|
@@ -1,79 +1,25 @@
|
|
|
1
1
|
module CDC
|
|
2
2
|
module Core
|
|
3
|
-
# Immutable group of change events committed in one transaction.
|
|
4
|
-
#
|
|
5
|
-
# TransactionEnvelope is useful when a downstream processor needs transaction
|
|
6
|
-
# boundaries instead of isolated row-level events. The contained events and
|
|
7
|
-
# metadata are Ractor-shareable when construction succeeds.
|
|
8
3
|
class TransactionEnvelope
|
|
9
|
-
|
|
4
|
+
EMPTY_METADATA: metadata_hash
|
|
10
5
|
|
|
11
|
-
@events: untyped
|
|
12
|
-
|
|
13
|
-
@commit_lsn: untyped
|
|
14
|
-
|
|
15
|
-
@committed_at: untyped
|
|
16
|
-
|
|
17
|
-
@metadata: untyped
|
|
18
|
-
|
|
19
|
-
# @return [Object] transaction identifier
|
|
20
|
-
# @return [Array<ChangeEvent>] events committed by the transaction
|
|
21
|
-
# @return [String, nil] commit log sequence number
|
|
22
|
-
# @return [Time, nil] commit timestamp
|
|
23
|
-
# @return [EventMetadata] transaction metadata
|
|
24
6
|
attr_reader transaction_id: untyped
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# @return [Array<ChangeEvent>] events committed by the transaction
|
|
42
|
-
# @return [String, nil] commit log sequence number
|
|
43
|
-
# @return [Time, nil] commit timestamp
|
|
44
|
-
# @return [EventMetadata] transaction metadata
|
|
45
|
-
attr_reader committed_at: untyped
|
|
46
|
-
|
|
47
|
-
# @return [Object] transaction identifier
|
|
48
|
-
# @return [Array<ChangeEvent>] events committed by the transaction
|
|
49
|
-
# @return [String, nil] commit log sequence number
|
|
50
|
-
# @return [Time, nil] commit timestamp
|
|
51
|
-
# @return [EventMetadata] transaction metadata
|
|
52
|
-
attr_reader metadata: untyped
|
|
53
|
-
|
|
54
|
-
# Build a transaction envelope.
|
|
55
|
-
#
|
|
56
|
-
# @param transaction_id [Object] upstream transaction identifier
|
|
57
|
-
# @param events [Array<ChangeEvent>] committed events
|
|
58
|
-
# @param commit_lsn [#to_s, nil] commit log sequence number
|
|
59
|
-
# @param committed_at [Time, nil] commit timestamp
|
|
60
|
-
# @param metadata [Hash, EventMetadata] transaction metadata
|
|
61
|
-
def initialize: (transaction_id: untyped, events: untyped, ?commit_lsn: untyped?, ?committed_at: untyped?, ?metadata: ::Hash[untyped, untyped]) -> void
|
|
62
|
-
|
|
63
|
-
# Whether the envelope has no events.
|
|
64
|
-
#
|
|
65
|
-
# @return [Boolean]
|
|
66
|
-
def empty?: () -> untyped
|
|
67
|
-
|
|
68
|
-
# Number of events in the envelope.
|
|
69
|
-
#
|
|
70
|
-
# @return [Integer]
|
|
71
|
-
def size: () -> untyped
|
|
72
|
-
|
|
73
|
-
# Convert the transaction envelope into a Ractor-shareable hash.
|
|
74
|
-
#
|
|
75
|
-
# @return [Hash{String=>Object,nil}]
|
|
76
|
-
def to_h: () -> untyped
|
|
7
|
+
attr_reader events: ::Array[ChangeEvent]
|
|
8
|
+
attr_reader commit_lsn: String?
|
|
9
|
+
attr_reader committed_at: ::Time?
|
|
10
|
+
attr_reader metadata: EventMetadata
|
|
11
|
+
|
|
12
|
+
def initialize: (
|
|
13
|
+
transaction_id: untyped,
|
|
14
|
+
events: ::Array[ChangeEvent],
|
|
15
|
+
?commit_lsn: String?,
|
|
16
|
+
?committed_at: ::Time?,
|
|
17
|
+
?metadata: EventMetadata | metadata_hash
|
|
18
|
+
) -> void
|
|
19
|
+
|
|
20
|
+
def empty?: () -> bool
|
|
21
|
+
def size: () -> Integer
|
|
22
|
+
def to_h: () -> shareable_hash
|
|
77
23
|
end
|
|
78
24
|
end
|
|
79
25
|
end
|
data/sig/cdc/core/version.rbs
CHANGED
data/sig/cdc/core.rbs
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
|
-
# Top-level namespace for Change Data Capture libraries.
|
|
2
1
|
module CDC
|
|
3
|
-
# Database-agnostic Change Data Capture domain primitives.
|
|
4
|
-
#
|
|
5
|
-
# CDC::Core intentionally contains only lightweight runtime abstractions:
|
|
6
|
-
# events, metadata, processors, filters, pipelines, and processor results.
|
|
7
|
-
# Transport, PostgreSQL protocol parsing, and value decoding live in sibling
|
|
8
|
-
# gems so this layer can remain independently useful.
|
|
9
2
|
module Core
|
|
3
|
+
type metadata_hash = ::Hash[untyped, untyped]
|
|
4
|
+
type metric_tags = ::Hash[String, untyped]
|
|
5
|
+
type shareable_hash = ::Hash[untyped, untyped]
|
|
6
|
+
type event_values = ::Hash[String, untyped]
|
|
7
|
+
type core_object = ChangeEvent | TransactionEnvelope
|
|
8
|
+
type normalized_object = ChangeEvent | TransactionEnvelope | ::Array[ChangeEvent] | ::Array[TransactionEnvelope]
|
|
9
|
+
type work_item = ChangeEvent | TransactionEnvelope | ::Array[ChangeEvent]
|
|
10
|
+
|
|
11
|
+
interface _ProcessorLike
|
|
12
|
+
def class: () -> singleton(::Object)
|
|
13
|
+
def respond_to?: (Symbol | String method_name, ?bool include_private) -> bool
|
|
14
|
+
def ractor_safe?: () -> bool
|
|
15
|
+
def process: (untyped input) -> untyped
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
interface _RoutableProcessor
|
|
19
|
+
def class: () -> singleton(::Object)
|
|
20
|
+
def respond_to?: (Symbol | String method_name, ?bool include_private) -> bool
|
|
21
|
+
def process: (untyped input) -> untyped
|
|
22
|
+
def process_many: (::Array[untyped] inputs) -> untyped
|
|
23
|
+
end
|
|
24
|
+
interface _BatchProcessorLike
|
|
25
|
+
def process_many: (::Enumerable[untyped] inputs) -> untyped
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
interface _FilterLike
|
|
29
|
+
def match?: (ChangeEvent event) -> bool
|
|
30
|
+
end
|
|
10
31
|
end
|
|
11
32
|
end
|
data/sig/cdc_core.rbs
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cdc-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ken C. Demanawa
|
|
@@ -92,5 +92,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
92
|
requirements: []
|
|
93
93
|
rubygems_version: 3.6.9
|
|
94
94
|
specification_version: 4
|
|
95
|
-
summary: Source-agnostic Change Data Capture contracts and domain primitives for Ruby
|
|
95
|
+
summary: Source-agnostic Change Data Capture contracts and domain primitives for Ruby.
|
|
96
96
|
test_files: []
|