solid-result 2.0.0
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 +7 -0
- data/.rubocop.yml +98 -0
- data/.rubocop_todo.yml +12 -0
- data/CHANGELOG.md +600 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +2691 -0
- data/Rakefile +28 -0
- data/Steepfile +31 -0
- data/examples/multiple_listeners/Rakefile +55 -0
- data/examples/multiple_listeners/app/models/account/member.rb +10 -0
- data/examples/multiple_listeners/app/models/account/owner_creation.rb +62 -0
- data/examples/multiple_listeners/app/models/account.rb +11 -0
- data/examples/multiple_listeners/app/models/user/creation.rb +67 -0
- data/examples/multiple_listeners/app/models/user/token/creation.rb +51 -0
- data/examples/multiple_listeners/app/models/user/token.rb +7 -0
- data/examples/multiple_listeners/app/models/user.rb +15 -0
- data/examples/multiple_listeners/config/boot.rb +16 -0
- data/examples/multiple_listeners/config/initializers/solid_result.rb +9 -0
- data/examples/multiple_listeners/config.rb +27 -0
- data/examples/multiple_listeners/db/setup.rb +60 -0
- data/examples/multiple_listeners/lib/event_logs_listener/stdout.rb +60 -0
- data/examples/multiple_listeners/lib/runtime_breaker.rb +11 -0
- data/examples/multiple_listeners/lib/solid/result/event_logs_record.rb +27 -0
- data/examples/multiple_listeners/lib/solid/result/rollback_on_failure.rb +15 -0
- data/examples/service_objects/Rakefile +36 -0
- data/examples/service_objects/app/models/account/member.rb +10 -0
- data/examples/service_objects/app/models/account.rb +11 -0
- data/examples/service_objects/app/models/user/token.rb +7 -0
- data/examples/service_objects/app/models/user.rb +15 -0
- data/examples/service_objects/app/services/account/owner_creation.rb +47 -0
- data/examples/service_objects/app/services/application_service.rb +79 -0
- data/examples/service_objects/app/services/user/creation.rb +56 -0
- data/examples/service_objects/app/services/user/token/creation.rb +37 -0
- data/examples/service_objects/config/boot.rb +17 -0
- data/examples/service_objects/config/initializers/solid_result.rb +9 -0
- data/examples/service_objects/config.rb +20 -0
- data/examples/service_objects/db/setup.rb +49 -0
- data/examples/single_listener/Rakefile +92 -0
- data/examples/single_listener/app/models/account/member.rb +10 -0
- data/examples/single_listener/app/models/account/owner_creation.rb +62 -0
- data/examples/single_listener/app/models/account.rb +11 -0
- data/examples/single_listener/app/models/user/creation.rb +67 -0
- data/examples/single_listener/app/models/user/token/creation.rb +51 -0
- data/examples/single_listener/app/models/user/token.rb +7 -0
- data/examples/single_listener/app/models/user.rb +15 -0
- data/examples/single_listener/config/boot.rb +16 -0
- data/examples/single_listener/config/initializers/solid_result.rb +9 -0
- data/examples/single_listener/config.rb +23 -0
- data/examples/single_listener/db/setup.rb +49 -0
- data/examples/single_listener/lib/runtime_breaker.rb +11 -0
- data/examples/single_listener/lib/single_event_logs_listener.rb +117 -0
- data/examples/single_listener/lib/solid/result/rollback_on_failure.rb +15 -0
- data/lib/solid/failure.rb +23 -0
- data/lib/solid/output/callable_and_then.rb +40 -0
- data/lib/solid/output/expectations/mixin.rb +31 -0
- data/lib/solid/output/expectations.rb +25 -0
- data/lib/solid/output/failure.rb +9 -0
- data/lib/solid/output/mixin.rb +57 -0
- data/lib/solid/output/success.rb +37 -0
- data/lib/solid/output.rb +115 -0
- data/lib/solid/result/_self.rb +198 -0
- data/lib/solid/result/callable_and_then/caller.rb +49 -0
- data/lib/solid/result/callable_and_then/config.rb +15 -0
- data/lib/solid/result/callable_and_then/error.rb +11 -0
- data/lib/solid/result/callable_and_then.rb +9 -0
- data/lib/solid/result/config/options.rb +27 -0
- data/lib/solid/result/config/switcher.rb +82 -0
- data/lib/solid/result/config/switchers/addons.rb +25 -0
- data/lib/solid/result/config/switchers/constant_aliases.rb +33 -0
- data/lib/solid/result/config/switchers/features.rb +32 -0
- data/lib/solid/result/config/switchers/pattern_matching.rb +20 -0
- data/lib/solid/result/config.rb +64 -0
- data/lib/solid/result/contract/disabled.rb +25 -0
- data/lib/solid/result/contract/error.rb +17 -0
- data/lib/solid/result/contract/evaluator.rb +45 -0
- data/lib/solid/result/contract/for_types.rb +29 -0
- data/lib/solid/result/contract/for_types_and_values.rb +46 -0
- data/lib/solid/result/contract/interface.rb +21 -0
- data/lib/solid/result/contract/type_checker.rb +37 -0
- data/lib/solid/result/contract.rb +33 -0
- data/lib/solid/result/data.rb +33 -0
- data/lib/solid/result/error.rb +59 -0
- data/lib/solid/result/event_logs/config.rb +28 -0
- data/lib/solid/result/event_logs/listener.rb +51 -0
- data/lib/solid/result/event_logs/listeners.rb +87 -0
- data/lib/solid/result/event_logs/tracking/disabled.rb +15 -0
- data/lib/solid/result/event_logs/tracking/enabled.rb +161 -0
- data/lib/solid/result/event_logs/tracking.rb +26 -0
- data/lib/solid/result/event_logs/tree.rb +141 -0
- data/lib/solid/result/event_logs.rb +27 -0
- data/lib/solid/result/expectations/mixin.rb +58 -0
- data/lib/solid/result/expectations.rb +75 -0
- data/lib/solid/result/failure.rb +11 -0
- data/lib/solid/result/handler/allowed_types.rb +45 -0
- data/lib/solid/result/handler.rb +57 -0
- data/lib/solid/result/ignored_types.rb +14 -0
- data/lib/solid/result/mixin.rb +72 -0
- data/lib/solid/result/success.rb +11 -0
- data/lib/solid/result/version.rb +7 -0
- data/lib/solid/result.rb +27 -0
- data/lib/solid/success.rb +23 -0
- data/lib/solid-result.rb +3 -0
- data/sig/solid/failure.rbs +13 -0
- data/sig/solid/output.rbs +175 -0
- data/sig/solid/result/callable_and_then.rbs +60 -0
- data/sig/solid/result/config.rbs +102 -0
- data/sig/solid/result/contract.rbs +120 -0
- data/sig/solid/result/data.rbs +16 -0
- data/sig/solid/result/error.rbs +34 -0
- data/sig/solid/result/event_logs.rbs +189 -0
- data/sig/solid/result/expectations.rbs +71 -0
- data/sig/solid/result/handler.rbs +47 -0
- data/sig/solid/result/ignored_types.rbs +9 -0
- data/sig/solid/result/mixin.rbs +45 -0
- data/sig/solid/result/version.rbs +5 -0
- data/sig/solid/result.rbs +85 -0
- data/sig/solid/success.rbs +13 -0
- metadata +167 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
class Solid::Output < Solid::Result
|
|
2
|
+
EXPECTED_OUTCOME: String
|
|
3
|
+
|
|
4
|
+
SourceMethodArity: ^(Method) -> Integer
|
|
5
|
+
|
|
6
|
+
attr_reader memo: Hash[Symbol, untyped]
|
|
7
|
+
|
|
8
|
+
def initialize: (
|
|
9
|
+
type: Symbol,
|
|
10
|
+
value: untyped,
|
|
11
|
+
?source: untyped,
|
|
12
|
+
?expectations: Solid::Result::Contract::Evaluator,
|
|
13
|
+
?terminal: bool
|
|
14
|
+
) -> void
|
|
15
|
+
|
|
16
|
+
def and_then: (?Symbol, **untyped) ?{ (Hash[Symbol, untyped]) -> untyped } -> untyped
|
|
17
|
+
|
|
18
|
+
def and_then!: (untyped, **untyped) -> untyped
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def call_and_then_source_method: (Symbol, Hash[Symbol, untyped]) -> Solid::Output
|
|
23
|
+
|
|
24
|
+
def call_and_then_callable!: (untyped, value: untyped, injected_value: untyped, method_name: (Symbol | nil)) -> Solid::Output
|
|
25
|
+
|
|
26
|
+
def ensure_result_object: (untyped, origin: Symbol) -> Solid::Output
|
|
27
|
+
|
|
28
|
+
def raise_unexpected_outcome_error: (Solid::Output | untyped, Symbol) -> void
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Solid::Output
|
|
32
|
+
class Error < Solid::Result::Error
|
|
33
|
+
class InvalidExposure < Solid::Output::Error
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class Solid::Output
|
|
39
|
+
class Success < Solid::Output
|
|
40
|
+
include Solid::Success
|
|
41
|
+
|
|
42
|
+
FetchValues: Proc
|
|
43
|
+
|
|
44
|
+
def and_expose: (Symbol, Array[Symbol], terminal: bool) -> Solid::Output::Success
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.Success: (Symbol, **untyped) -> Solid::Output::Success
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
module Solid::Output::CallableAndThen
|
|
51
|
+
class Caller < Solid::Result::CallableAndThen::Caller
|
|
52
|
+
module KeyArgs
|
|
53
|
+
def self.parameters?: (untyped) -> bool
|
|
54
|
+
|
|
55
|
+
def self.invalid_arity: (untyped, Symbol) -> Solid::Result::CallableAndThen::Error::InvalidArity
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.call: (
|
|
59
|
+
untyped source,
|
|
60
|
+
value: untyped,
|
|
61
|
+
injected_value: untyped,
|
|
62
|
+
method_name: (Symbol | nil),
|
|
63
|
+
) -> Solid::Output
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def self.call_proc!: (
|
|
68
|
+
untyped source,
|
|
69
|
+
Hash[Symbol, untyped] value,
|
|
70
|
+
nil injected_value
|
|
71
|
+
) -> Solid::Output
|
|
72
|
+
|
|
73
|
+
def self.call_method!: (
|
|
74
|
+
untyped source,
|
|
75
|
+
Method method,
|
|
76
|
+
Hash[Symbol, untyped] value,
|
|
77
|
+
nil injected_value
|
|
78
|
+
) -> Solid::Output
|
|
79
|
+
|
|
80
|
+
def self.callable_method: (
|
|
81
|
+
untyped source,
|
|
82
|
+
(Symbol | nil) method_name
|
|
83
|
+
) -> ::Method
|
|
84
|
+
|
|
85
|
+
def self.ensure_result_object: (
|
|
86
|
+
untyped source,
|
|
87
|
+
untyped value,
|
|
88
|
+
Solid::Output result
|
|
89
|
+
) -> Solid::Output
|
|
90
|
+
|
|
91
|
+
def self.expected_result_object: () -> singleton(Solid::Output)
|
|
92
|
+
|
|
93
|
+
def self.expected_outcome: () -> String
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class Solid::Output
|
|
98
|
+
class Failure < Solid::Output
|
|
99
|
+
include Solid::Failure
|
|
100
|
+
|
|
101
|
+
def and_expose: (Symbol, Array[Symbol], **untyped) -> Solid::Output::Failure
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.Failure: (Symbol, **untyped) -> Solid::Output::Failure
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class Solid::Output
|
|
108
|
+
module Mixin
|
|
109
|
+
Factory: singleton(Solid::Result::Mixin::Factory)
|
|
110
|
+
|
|
111
|
+
module Methods
|
|
112
|
+
def Success: (Symbol, **untyped) -> Solid::Output::Success
|
|
113
|
+
|
|
114
|
+
def Failure: (Symbol, **untyped) -> Solid::Output::Failure
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def _ResultAs: (singleton(Solid::Output), Symbol, untyped, ?terminal: bool) -> untyped
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
module Addons
|
|
122
|
+
module Continue
|
|
123
|
+
include Solid::Output::Mixin::Methods
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def Continue: (**untyped) -> Solid::Output::Success
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
module Given
|
|
131
|
+
include Solid::Output::Mixin::Methods
|
|
132
|
+
|
|
133
|
+
private
|
|
134
|
+
|
|
135
|
+
def Given: (*untyped) -> Solid::Output::Success
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
OPTIONS: Hash[Symbol, Module]
|
|
139
|
+
|
|
140
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Hash[Symbol, Module]
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def self.mixin_module: -> singleton(Solid::Output::Mixin)
|
|
145
|
+
|
|
146
|
+
def self.result_factory: -> singleton(Solid::Output)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class Solid::Output::Expectations < Solid::Result::Expectations
|
|
150
|
+
def self.mixin_module: -> singleton(Solid::Output::Expectations::Mixin)
|
|
151
|
+
|
|
152
|
+
def self.result_factory_without_expectations: -> singleton(Solid::Result)
|
|
153
|
+
|
|
154
|
+
def Success: (Symbol, **untyped) -> Solid::Output::Success
|
|
155
|
+
def Failure: (Symbol, **untyped) -> Solid::Output::Failure
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
module Solid::Output::Expectations::Mixin
|
|
159
|
+
Methods: singleton(Solid::Result::Expectations::Mixin::Methods)
|
|
160
|
+
Factory: singleton(Solid::Result::Expectations::Mixin::Factory)
|
|
161
|
+
|
|
162
|
+
module Addons
|
|
163
|
+
module Continue
|
|
164
|
+
private def Continue: (**untyped) -> Solid::Output::Success
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
module Given
|
|
168
|
+
private def Given: (*untyped) -> Solid::Output::Success
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
OPTIONS: Hash[Symbol, Module]
|
|
172
|
+
|
|
173
|
+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Hash[Symbol, Module]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Solid::Result::CallableAndThen
|
|
2
|
+
class Config
|
|
3
|
+
attr_accessor default_method_name_to_call: Symbol
|
|
4
|
+
|
|
5
|
+
def initialize: -> void
|
|
6
|
+
|
|
7
|
+
def options: () -> Hash[Symbol, untyped]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class Error < Solid::Result::Error
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Error::InvalidArity < Error
|
|
14
|
+
def self.build: (
|
|
15
|
+
source: untyped,
|
|
16
|
+
method: Symbol,
|
|
17
|
+
arity: String
|
|
18
|
+
) -> Error::InvalidArity
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Caller
|
|
22
|
+
def self.call: (
|
|
23
|
+
untyped source,
|
|
24
|
+
value: untyped,
|
|
25
|
+
injected_value: untyped,
|
|
26
|
+
method_name: (Symbol | nil)
|
|
27
|
+
) -> Solid::Result
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def self.call_proc!: (
|
|
32
|
+
untyped source,
|
|
33
|
+
untyped value,
|
|
34
|
+
untyped injected_value
|
|
35
|
+
) -> Solid::Result
|
|
36
|
+
|
|
37
|
+
def self.call_method!: (
|
|
38
|
+
untyped source,
|
|
39
|
+
Method method,
|
|
40
|
+
untyped value,
|
|
41
|
+
untyped injected_value
|
|
42
|
+
) -> Solid::Result
|
|
43
|
+
|
|
44
|
+
def self.callable_method: (
|
|
45
|
+
untyped source,
|
|
46
|
+
(Symbol | nil) method_name
|
|
47
|
+
) -> ::Method
|
|
48
|
+
|
|
49
|
+
def self.ensure_result_object: (
|
|
50
|
+
untyped source,
|
|
51
|
+
untyped value,
|
|
52
|
+
Solid::Result result
|
|
53
|
+
) -> Solid::Result
|
|
54
|
+
|
|
55
|
+
def self.expected_result_object: () -> singleton(Solid::Result)
|
|
56
|
+
|
|
57
|
+
def self.expected_outcome: () -> String
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
class Solid::Result::Config
|
|
2
|
+
ADDON: Hash[Symbol, Hash[Symbol, untyped]]
|
|
3
|
+
FEATURE: Hash[Symbol, Hash[Symbol, untyped]]
|
|
4
|
+
PATTERN_MATCHING: Hash[Symbol, Hash[Symbol, untyped]]
|
|
5
|
+
|
|
6
|
+
attr_reader addon: Solid::Result::Config::Switcher
|
|
7
|
+
attr_reader feature: Solid::Result::Config::Switcher
|
|
8
|
+
attr_reader constant_alias: Solid::Result::Config::Switcher
|
|
9
|
+
attr_reader pattern_matching: Solid::Result::Config::Switcher
|
|
10
|
+
|
|
11
|
+
def self.instance: -> Solid::Result::Config
|
|
12
|
+
|
|
13
|
+
def initialize: -> void
|
|
14
|
+
|
|
15
|
+
def and_then!: () -> Solid::Result::CallableAndThen::Config
|
|
16
|
+
def event_logs: () -> Solid::Result::EventLogs::Config
|
|
17
|
+
|
|
18
|
+
def freeze: -> Solid::Result::Config
|
|
19
|
+
def options: -> Hash[Symbol, Solid::Result::Config::Switcher]
|
|
20
|
+
def to_h: -> Hash[Symbol, Hash[Symbol | String, bool]]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Solid::Result::Config::Options
|
|
24
|
+
def self.with_defaults: (
|
|
25
|
+
Hash[Symbol, Hash[Symbol, bool]],
|
|
26
|
+
Symbol
|
|
27
|
+
) -> Hash[Symbol, bool]
|
|
28
|
+
|
|
29
|
+
def self.select: (
|
|
30
|
+
Hash[Symbol, Hash[Symbol, bool]],
|
|
31
|
+
config: Symbol,
|
|
32
|
+
from: Hash[Symbol, untyped]
|
|
33
|
+
) -> Hash[Symbol, untyped]
|
|
34
|
+
|
|
35
|
+
def self.addon: (
|
|
36
|
+
map: Hash[Symbol, Hash[Symbol, bool]],
|
|
37
|
+
from: Hash[Symbol, Module]
|
|
38
|
+
) -> Hash[Symbol, Module]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Solid::Result::Config::Switcher
|
|
42
|
+
private attr_reader _affects: Hash[Symbol | String, Array[String]]
|
|
43
|
+
private attr_reader _options: Hash[Symbol | String, bool]
|
|
44
|
+
private attr_reader listener: Proc
|
|
45
|
+
|
|
46
|
+
def initialize: (
|
|
47
|
+
options: Hash[Symbol | String, Hash[Symbol, untyped]],
|
|
48
|
+
?listener: Proc
|
|
49
|
+
) -> void
|
|
50
|
+
|
|
51
|
+
def freeze: -> Solid::Result::Config::Switcher
|
|
52
|
+
|
|
53
|
+
def to_h: -> Hash[Symbol | String, bool]
|
|
54
|
+
|
|
55
|
+
def options: -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
|
56
|
+
|
|
57
|
+
def enabled?: (Symbol | String) -> bool
|
|
58
|
+
|
|
59
|
+
def enable!: (*(Symbol | String)) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
|
60
|
+
|
|
61
|
+
def disable!: (*(Symbol | String)) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def set_many: (Array[Symbol | String], to: bool) -> Hash[Symbol | String, Hash[Symbol, untyped]]
|
|
66
|
+
|
|
67
|
+
def set_one: (Symbol | String, bool) -> void
|
|
68
|
+
|
|
69
|
+
def require_option!: (Array[Symbol | String]) -> void
|
|
70
|
+
|
|
71
|
+
def validate_option!: (Symbol | String) -> void
|
|
72
|
+
|
|
73
|
+
def available_options_message: -> String
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
module Solid::Result::Config::Addons
|
|
77
|
+
AFFECTS: Array[String]
|
|
78
|
+
OPTIONS: Hash[String, Hash[Symbol, untyped]]
|
|
79
|
+
|
|
80
|
+
def self.switcher: -> Solid::Result::Config::Switcher
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
module Solid::Result::Config::ConstantAliases
|
|
84
|
+
MAPPING: Hash[String, Hash[Symbol, untyped]]
|
|
85
|
+
OPTIONS: Hash[String, Hash[Symbol, untyped]]
|
|
86
|
+
Listener: Proc
|
|
87
|
+
|
|
88
|
+
def self.switcher: -> Solid::Result::Config::Switcher
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
module Solid::Result::Config::Features
|
|
92
|
+
OPTIONS: Hash[String, Hash[Symbol, untyped]]
|
|
93
|
+
Listener: Proc
|
|
94
|
+
|
|
95
|
+
def self.switcher: -> Solid::Result::Config::Switcher
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
module Solid::Result::Config::PatternMatching
|
|
99
|
+
OPTIONS: Hash[String, Hash[Symbol, untyped]]
|
|
100
|
+
|
|
101
|
+
def self.switcher: -> Solid::Result::Config::Switcher
|
|
102
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
module Solid::Result::Contract
|
|
2
|
+
NONE: Solid::Result::Contract::Evaluator
|
|
3
|
+
|
|
4
|
+
def self.evaluate: (
|
|
5
|
+
Solid::Result::Data,
|
|
6
|
+
Solid::Result::Contract::Evaluator
|
|
7
|
+
) -> Solid::Result::Contract::TypeChecker
|
|
8
|
+
|
|
9
|
+
ToEnsure: ^(Hash[Symbol, untyped] | Array[Symbol], Hash[Symbol, Hash[Symbol, bool]])
|
|
10
|
+
-> Solid::Result::Contract::Interface
|
|
11
|
+
|
|
12
|
+
def self.new: (
|
|
13
|
+
success: Hash[Symbol, untyped] | Array[Symbol],
|
|
14
|
+
failure: Hash[Symbol, untyped] | Array[Symbol],
|
|
15
|
+
config: Hash[Symbol, Hash[Symbol, bool]]
|
|
16
|
+
) -> Solid::Result::Contract::Evaluator
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Solid::Result::Contract
|
|
20
|
+
class TypeChecker
|
|
21
|
+
attr_reader result_type: Symbol
|
|
22
|
+
attr_reader expectations: Solid::Result::Contract::Evaluator
|
|
23
|
+
|
|
24
|
+
def initialize: (
|
|
25
|
+
Symbol,
|
|
26
|
+
expectations: Solid::Result::Contract::Evaluator
|
|
27
|
+
) -> void
|
|
28
|
+
|
|
29
|
+
def allow!: (Symbol) -> Symbol
|
|
30
|
+
def allow?: (Array[Symbol]) -> bool
|
|
31
|
+
def allow_success?: (Array[Symbol]) -> bool
|
|
32
|
+
def allow_failure?: (Array[Symbol]) -> bool
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def validate: (
|
|
37
|
+
Array[Symbol],
|
|
38
|
+
expected: Solid::Result::Contract::Interface,
|
|
39
|
+
allow_empty: bool
|
|
40
|
+
) -> bool
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Solid::Result::Contract::Error < Solid::Result::Error
|
|
45
|
+
class UnexpectedType < Solid::Result::Contract::Error
|
|
46
|
+
def self.build: (type: Symbol, allowed_types: Set[Symbol])
|
|
47
|
+
-> Solid::Result::Contract::Error::UnexpectedType
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class UnexpectedValue < Solid::Result::Contract::Error
|
|
51
|
+
def self.build: (type: Symbol, value: untyped, ?cause: Exception)
|
|
52
|
+
-> Solid::Result::Contract::Error::UnexpectedValue
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
module Solid::Result::Contract
|
|
57
|
+
module Interface
|
|
58
|
+
def ==: (Solid::Result::Contract::Interface) -> bool
|
|
59
|
+
|
|
60
|
+
def allowed_types: -> Set[Symbol]
|
|
61
|
+
|
|
62
|
+
def type?: (Symbol) -> bool
|
|
63
|
+
|
|
64
|
+
def type!: (Symbol) -> Symbol
|
|
65
|
+
|
|
66
|
+
def type_and_value!: (Solid::Result::Data) -> void
|
|
67
|
+
|
|
68
|
+
def !=: (untyped) -> bool
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
module Solid::Result::Contract
|
|
73
|
+
module Disabled
|
|
74
|
+
extend Interface
|
|
75
|
+
|
|
76
|
+
EMPTY_SET: Set[Symbol]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
module Solid::Result::Contract
|
|
81
|
+
class ForTypes
|
|
82
|
+
include Interface
|
|
83
|
+
|
|
84
|
+
def initialize: (Array[Symbol]) -> void
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
module Solid::Result::Contract
|
|
89
|
+
class ForTypesAndValues
|
|
90
|
+
include Interface
|
|
91
|
+
|
|
92
|
+
def initialize: (
|
|
93
|
+
Hash[Symbol, untyped],
|
|
94
|
+
Hash[Symbol, Hash[Symbol, bool]]
|
|
95
|
+
) -> void
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def nil_as_valid_value_checking?: -> bool
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
module Solid::Result::Contract
|
|
104
|
+
class Evaluator
|
|
105
|
+
include Interface
|
|
106
|
+
|
|
107
|
+
attr_reader allowed_types: Set[Symbol]
|
|
108
|
+
attr_reader success: Solid::Result::Contract::Interface
|
|
109
|
+
attr_reader failure: Solid::Result::Contract::Interface
|
|
110
|
+
|
|
111
|
+
def initialize: (
|
|
112
|
+
Solid::Result::Contract::Interface,
|
|
113
|
+
Solid::Result::Contract::Interface
|
|
114
|
+
) -> void
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def for: (Solid::Result::Data) -> Solid::Result::Contract::Interface
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Solid::Result
|
|
2
|
+
class Data
|
|
3
|
+
attr_reader kind: Symbol
|
|
4
|
+
attr_reader type: Symbol
|
|
5
|
+
attr_reader value: untyped
|
|
6
|
+
attr_reader to_h: Hash[Symbol, untyped]
|
|
7
|
+
attr_reader to_a: [Symbol, Symbol, untyped]
|
|
8
|
+
|
|
9
|
+
def initialize: (Symbol, Symbol, untyped) -> void
|
|
10
|
+
|
|
11
|
+
def inspect: -> String
|
|
12
|
+
|
|
13
|
+
alias to_ary to_a
|
|
14
|
+
alias to_hash to_h
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Solid::Result
|
|
2
|
+
class Error < StandardError
|
|
3
|
+
def self.build: (**untyped) -> Solid::Result::Error
|
|
4
|
+
|
|
5
|
+
class NotImplemented < Solid::Result::Error
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class MissingTypeArgument < Solid::Result::Error
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class UnexpectedOutcome < Solid::Result::Error
|
|
12
|
+
def self.build: (outcome: untyped, origin: Symbol, ?expected: String)
|
|
13
|
+
-> Solid::Result::Error::UnexpectedOutcome
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class InvalidResultSource < Solid::Result::Error
|
|
17
|
+
def self.build: (given_result: Solid::Result, expected_source: untyped)
|
|
18
|
+
-> Solid::Result::Error::InvalidResultSource
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class InvalidSourceMethodArity < Solid::Result::Error
|
|
22
|
+
def self.build: (source: untyped, method: Method, max_arity: Integer)
|
|
23
|
+
-> Solid::Result::Error::InvalidSourceMethodArity
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class UnhandledTypes < Solid::Result::Error
|
|
27
|
+
def self.build: (types: Set[Symbol])
|
|
28
|
+
-> Solid::Result::Error::UnhandledTypes
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class CallableAndThenDisabled < Solid::Result::Error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
class Solid::Result
|
|
2
|
+
module EventLogs
|
|
3
|
+
module Listener
|
|
4
|
+
module ClassMethods
|
|
5
|
+
def around_and_then?: () -> bool
|
|
6
|
+
def around_event_logs?: () -> bool
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
extend ClassMethods
|
|
10
|
+
|
|
11
|
+
def around_event_logs: (scope: Hash[Symbol, untyped]) { () -> untyped } -> untyped
|
|
12
|
+
|
|
13
|
+
def on_start: (scope: Hash[Symbol, untyped]) -> untyped
|
|
14
|
+
|
|
15
|
+
def around_and_then: (scope: Hash[Symbol, untyped], and_then: Hash[Symbol, untyped]) { () -> untyped } -> untyped
|
|
16
|
+
|
|
17
|
+
def on_record: (record: Hash[Symbol, untyped] ) -> untyped
|
|
18
|
+
|
|
19
|
+
def on_finish: (event_logs: Hash[Symbol, untyped] ) -> untyped
|
|
20
|
+
|
|
21
|
+
def before_interruption: (exception: ::Exception, event_logs: Hash[Symbol, untyped]) -> untyped
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Listeners
|
|
25
|
+
class Chain
|
|
26
|
+
include Listener
|
|
27
|
+
|
|
28
|
+
attr_reader listeners: Hash[Symbol, untyped]
|
|
29
|
+
|
|
30
|
+
def initialize: (Array[untyped]) -> void
|
|
31
|
+
|
|
32
|
+
def new: () -> Listeners
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def listener?: (untyped, untyped) -> bool
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.[]: (*untyped) -> Chain
|
|
40
|
+
|
|
41
|
+
private attr_reader listeners: Array[Listener]
|
|
42
|
+
private attr_reader around_and_then_listener: untyped
|
|
43
|
+
private attr_reader around_event_logs_listener: untyped
|
|
44
|
+
|
|
45
|
+
def initialize: (Array[Listener], untyped, untyped) -> void
|
|
46
|
+
|
|
47
|
+
def around_event_logs: (scope: Hash[Symbol, untyped]) { () -> untyped } -> untyped
|
|
48
|
+
|
|
49
|
+
def on_start: (scope: Hash[Symbol, untyped]) -> untyped
|
|
50
|
+
|
|
51
|
+
def around_and_then: (scope: Hash[Symbol, untyped], and_then: Hash[Symbol, untyped]) { () -> untyped } -> untyped
|
|
52
|
+
|
|
53
|
+
def on_record: (record: Hash[Symbol, untyped] ) -> untyped
|
|
54
|
+
|
|
55
|
+
def on_finish: (event_logs: Hash[Symbol, untyped] ) -> untyped
|
|
56
|
+
|
|
57
|
+
def before_interruption: (exception: ::Exception, event_logs: Hash[Symbol, untyped]) -> untyped
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
module Listener::Null
|
|
61
|
+
extend Listener
|
|
62
|
+
|
|
63
|
+
def self.new: () -> untyped
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class Config
|
|
67
|
+
attr_reader listener: untyped
|
|
68
|
+
attr_reader trace_id: ::Proc
|
|
69
|
+
|
|
70
|
+
def self.instance: -> Config
|
|
71
|
+
|
|
72
|
+
def initialize: -> void
|
|
73
|
+
|
|
74
|
+
def listener=: (Listener) -> void
|
|
75
|
+
def trace_id=: (::Proc) -> void
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class Tree
|
|
79
|
+
class Node
|
|
80
|
+
attr_reader id: Integer
|
|
81
|
+
attr_reader value: untyped
|
|
82
|
+
attr_reader parent: (Node | nil)
|
|
83
|
+
attr_reader normalizer: ^(Integer, Array[untyped]) -> untyped
|
|
84
|
+
attr_reader children: Array[Node]
|
|
85
|
+
|
|
86
|
+
def initialize: (
|
|
87
|
+
untyped value,
|
|
88
|
+
parent: (Node | nil),
|
|
89
|
+
id: Integer,
|
|
90
|
+
normalizer: ^(Integer, Array[untyped]) -> untyped
|
|
91
|
+
) -> void
|
|
92
|
+
|
|
93
|
+
def insert: (untyped, id: Integer) -> Node
|
|
94
|
+
|
|
95
|
+
def root?: () -> bool
|
|
96
|
+
def leaf?: () -> bool
|
|
97
|
+
def node?: () -> bool
|
|
98
|
+
def inspect: () -> String
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
attr_reader size: Integer
|
|
102
|
+
attr_reader root: Node
|
|
103
|
+
attr_reader current: Node
|
|
104
|
+
|
|
105
|
+
def initialize: (untyped, ?normalizer: ^(Integer, Array[untyped]) -> untyped) -> void
|
|
106
|
+
def root_value: () -> untyped
|
|
107
|
+
def parent_value: () -> untyped
|
|
108
|
+
def current_value: () -> untyped
|
|
109
|
+
def insert: (untyped) -> Node
|
|
110
|
+
def insert!: (untyped) -> Tree
|
|
111
|
+
def move_to!: (Node) -> Tree
|
|
112
|
+
def move_up!: (?Integer level) -> Tree
|
|
113
|
+
def move_down!: (?Integer level) -> Tree
|
|
114
|
+
def move_to_root!: () -> Tree
|
|
115
|
+
|
|
116
|
+
Ids: ^(Node) -> Array[untyped]
|
|
117
|
+
IdsMatrix: ::Proc
|
|
118
|
+
IdsLevelParent: ::Proc
|
|
119
|
+
|
|
120
|
+
def ids: () -> Array[untyped]
|
|
121
|
+
def ids_list: () -> Array[Integer]
|
|
122
|
+
def ids_matrix: () -> untyped
|
|
123
|
+
def ids_level_parent: () -> untyped
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
module Tracking
|
|
127
|
+
EMPTY_ARRAY: Array[untyped]
|
|
128
|
+
EMPTY_HASH: Hash[untyped, untyped]
|
|
129
|
+
EMPTY_TREE: EventLogs::Tree
|
|
130
|
+
EMPTY_IDS: Hash[untyped, untyped]
|
|
131
|
+
VERSION: Integer
|
|
132
|
+
EMPTY: Hash[Symbol, untyped]
|
|
133
|
+
|
|
134
|
+
class Enabled
|
|
135
|
+
private attr_accessor tree: EventLogs::Tree
|
|
136
|
+
private attr_accessor records: Array[Hash[Symbol, untyped]]
|
|
137
|
+
private attr_accessor listener: untyped
|
|
138
|
+
private attr_accessor root_started_at: Integer
|
|
139
|
+
|
|
140
|
+
def exec: (untyped, untyped) { () -> untyped } -> untyped
|
|
141
|
+
def err!: (::Exception, untyped) -> void
|
|
142
|
+
def reset!: () -> void
|
|
143
|
+
def record: (Solid::Result) -> void
|
|
144
|
+
def record_and_then: ((untyped), untyped) { () -> untyped } -> untyped
|
|
145
|
+
def reset_and_then!: () -> void
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def start: (String, String) -> [EventLogs::Tree::Node, Hash[Symbol, untyped]]
|
|
150
|
+
def finish: (untyped) -> untyped
|
|
151
|
+
|
|
152
|
+
TreeNodeValueNormalizer: ^(Integer, Array[untyped]) -> untyped
|
|
153
|
+
|
|
154
|
+
def root_start: (Array[untyped]) -> void
|
|
155
|
+
|
|
156
|
+
def track: (Solid::Result, time: Time) -> void
|
|
157
|
+
def track_record: (Solid::Result, Time) -> Hash[Symbol, untyped]
|
|
158
|
+
|
|
159
|
+
def now_in_milliseconds: () -> Integer
|
|
160
|
+
|
|
161
|
+
def map_event_logs: () -> Hash[Symbol, untyped]
|
|
162
|
+
|
|
163
|
+
def build_listener: () -> Listener
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
module Disabled
|
|
167
|
+
def self.exec: (untyped, untyped) { () -> untyped } -> untyped
|
|
168
|
+
def self.err!: (::Exception) -> void
|
|
169
|
+
def self.reset!: () -> void
|
|
170
|
+
def self.record: (Solid::Result) -> void
|
|
171
|
+
def self.record_and_then: ((untyped), untyped) { () -> Solid::Result } -> Solid::Result
|
|
172
|
+
def self.reset_and_then!: () -> void
|
|
173
|
+
|
|
174
|
+
private
|
|
175
|
+
|
|
176
|
+
def self.start: (String, String) -> void
|
|
177
|
+
def self.finish: (untyped) -> untyped
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def self.instance: () -> (Enabled | singleton(Disabled))
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
THREAD_VAR_NAME: Symbol
|
|
184
|
+
|
|
185
|
+
EnsureResult: ^(untyped) -> Solid::Result
|
|
186
|
+
|
|
187
|
+
def self.tracking: () -> (Tracking::Enabled | singleton(Tracking::Disabled))
|
|
188
|
+
end
|
|
189
|
+
end
|