foobara 0.0.142 → 0.1.1
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/.ruby-version +1 -1
- data/CHANGELOG.md +19 -0
- data/projects/builtin_types/lib/foobara/builtin_types.rb +1 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_defaults_from_element_types_to_root.rb +9 -2
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/symbolize_defaults.rb +1 -1
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/hash_with_symbolic_keys.rb +1 -1
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/alphabetize_required.rb +5 -5
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_required_from_element_types_to_root.rb +12 -2
- data/projects/builtin_types/src/builtin_types.rb +1 -1
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_desugarizer.rb +10 -2
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_type_desugarizer.rb +7 -2
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_class_desugarizer.rb +3 -4
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_symbol_desugarizer.rb +3 -4
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb +1 -1
- data/projects/builtin_types/src/duck/supported_validators/instance_of.rb +1 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb +4 -3
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb +3 -3
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb +1 -1
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb +2 -4
- data/projects/command/src/command_pattern_implementation/concerns/inputs_type.rb +12 -12
- data/projects/command/src/command_pattern_implementation/concerns/reflection.rb +4 -2
- data/projects/command/src/command_pattern_implementation/concerns/result_type.rb +0 -4
- data/projects/command_connectors/src/command_connector.rb +6 -6
- data/projects/command_connectors/src/command_registry.rb +7 -4
- data/projects/command_connectors/src/transformed_command.rb +22 -8
- data/projects/command_connectors/src/transformers/auth_errors_transformer.rb +1 -0
- data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +4 -0
- data/projects/detached_entity/src/concerns/types.rb +7 -1
- data/projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/model_instance_is_valid.rb +1 -1
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/hash_desugarizer.rb +6 -9
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/primary_key_desugarizer.rb +2 -1
- data/projects/domain/src/domain_module_extension.rb +12 -4
- data/projects/entity/src/concerns/types.rb +6 -1
- data/projects/foobara/lib/foobara/all.rb +4 -4
- data/projects/manifest/src/foobara/manifest/type.rb +11 -2
- data/projects/manifest/src/foobara/manifest/type_declaration.rb +46 -2
- data/projects/model/src/concerns/aliases.rb +8 -0
- data/projects/model/src/concerns/reflection.rb +2 -2
- data/projects/model/src/concerns/types.rb +35 -20
- data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb +12 -8
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/array_with_symbolic_elements.rb +1 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +15 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_desugarizer.rb +7 -5
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +4 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +0 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/move_private_from_element_types_to_root.rb +28 -9
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/symbolize_private.rb +8 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +4 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +14 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +8 -9
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +6 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +5 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +8 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +4 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +20 -5
- data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -5
- data/projects/model/src/extensions/type_declarations/lazy_element_types/model.rb +18 -0
- data/projects/model_attribute_helpers/src/attribute_helpers.rb +44 -26
- data/projects/namespace/src/is_namespace.rb +58 -90
- data/projects/namespace/src/namespace/lookup_mode.rb +13 -2
- data/projects/namespace/src/namespace_helpers.rb +1 -0
- data/projects/namespace/src/prefixless_registry.rb +2 -0
- data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +20 -1
- data/projects/persistence/src/entity_base/transaction.rb +14 -11
- data/projects/persistence/src/entity_base/transaction_table.rb +10 -49
- data/projects/persistence/src/entity_base.rb +39 -0
- data/projects/persistence/src/persistence.rb +4 -0
- data/projects/type_declarations/src/attributes.rb +15 -9
- data/projects/type_declarations/src/attributes_transformers/from_yaml.rb +1 -1
- data/projects/type_declarations/src/desugarizer_pipeline.rb +9 -0
- data/projects/type_declarations/src/dsl/attributes.rb +14 -5
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +24 -4
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +23 -9
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +3 -7
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +15 -4
- data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/key_type_declaration_desugarizer.rb +48 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +3 -11
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/value_type_declaration_desugarizer.rb +51 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +1 -1
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +17 -7
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +16 -19
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +3 -6
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +13 -2
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +3 -3
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +16 -4
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +20 -6
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +3 -9
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +7 -9
- data/projects/type_declarations/src/handlers/registered_type_declaration.rb +22 -7
- data/projects/type_declarations/src/lazy_element_types/array.rb +19 -0
- data/projects/type_declarations/src/lazy_element_types/attributes.rb +27 -0
- data/projects/type_declarations/src/lazy_element_types/hash.rb +38 -0
- data/projects/type_declarations/src/lazy_element_types/tuple.rb +23 -0
- data/projects/type_declarations/src/sensitive_type_remover.rb +6 -1
- data/projects/type_declarations/src/sensitive_type_removers/attributes.rb +2 -0
- data/projects/type_declarations/src/type_builder.rb +46 -21
- data/projects/type_declarations/src/type_declaration.rb +295 -0
- data/projects/type_declarations/src/type_declaration_handler.rb +10 -11
- data/projects/type_declarations/src/type_declarations.rb +12 -5
- data/projects/types/src/type.rb +26 -4
- data/projects/value/src/mutator.rb +1 -4
- data/projects/value/src/processor/casting.rb +7 -2
- data/projects/value/src/processor/pipeline.rb +9 -1
- data/projects/value/src/processor.rb +0 -2
- data/projects/value/src/transformer.rb +1 -3
- data/projects/value/src/validator.rb +0 -2
- data/projects/weak_object_set/src/weak_object_set.rb +2 -0
- metadata +10 -7
- data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +0 -29
- data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +0 -62
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +0 -32
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +0 -39
- data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +0 -30
- data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +0 -24
@@ -0,0 +1,295 @@
|
|
1
|
+
module Foobara
|
2
|
+
# Inheriting from ::Hash for now but we should remove this once all of the handlers are updated
|
3
|
+
class TypeDeclaration
|
4
|
+
attr_reader :is_strict
|
5
|
+
|
6
|
+
attr_accessor :is_duped,
|
7
|
+
:declaration_data,
|
8
|
+
:is_deep_duped,
|
9
|
+
:is_absolutified,
|
10
|
+
:reference_checked,
|
11
|
+
:type,
|
12
|
+
:base_type
|
13
|
+
|
14
|
+
# TODO: we should be able to delete absolutified opt once strict declarations
|
15
|
+
# use `:ref` instead of `{type: :ref}` format.
|
16
|
+
def initialize(declaration_data, absolutified = false, skip_reference_check = false)
|
17
|
+
if TypeDeclarations.strict?
|
18
|
+
self.is_strict = true
|
19
|
+
elsif absolutified || TypeDeclarations.strict_stringified?
|
20
|
+
self.is_absolutified = true
|
21
|
+
end
|
22
|
+
|
23
|
+
self.declaration_data = declaration_data
|
24
|
+
|
25
|
+
unless strict? || skip_reference_check
|
26
|
+
handle_symbolic_declaration
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_strict=(value)
|
31
|
+
if value
|
32
|
+
self.is_absolutified = true
|
33
|
+
end
|
34
|
+
|
35
|
+
@is_strict = value
|
36
|
+
end
|
37
|
+
|
38
|
+
def handle_symbolic_declaration
|
39
|
+
self.reference_checked = true
|
40
|
+
|
41
|
+
if declaration_data.is_a?(::Symbol)
|
42
|
+
symbol = declaration_data
|
43
|
+
elsif declaration_data.is_a?(::String) && TypeDeclarations.stringified?
|
44
|
+
symbol = declaration_data.to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
if symbol
|
48
|
+
type = if absolutified?
|
49
|
+
Domain.current.foobara_lookup_type(symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
50
|
+
else
|
51
|
+
Domain.current.foobara_lookup_type(symbol)
|
52
|
+
end
|
53
|
+
|
54
|
+
if type
|
55
|
+
unless strict?
|
56
|
+
self.declaration_data = type.full_type_symbol
|
57
|
+
end
|
58
|
+
|
59
|
+
self.type = type
|
60
|
+
|
61
|
+
self.is_strict = true
|
62
|
+
self.is_deep_duped = true
|
63
|
+
self.is_duped = true
|
64
|
+
|
65
|
+
else
|
66
|
+
if declaration_data.is_a?(::Symbol)
|
67
|
+
self.is_duped = true
|
68
|
+
self.is_deep_duped = true
|
69
|
+
end
|
70
|
+
|
71
|
+
self.declaration_data = declaration_data
|
72
|
+
end
|
73
|
+
elsif TypeDeclarations.strict_stringified?
|
74
|
+
symbolize_keys!
|
75
|
+
type_symbol = self[:type].to_sym
|
76
|
+
self[:type] = type_symbol
|
77
|
+
|
78
|
+
type = Domain.current.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
79
|
+
|
80
|
+
if type
|
81
|
+
if declaration_data.keys.size == 1
|
82
|
+
self.type = type
|
83
|
+
self.is_strict = true
|
84
|
+
self.is_deep_duped = true
|
85
|
+
self.is_duped = true
|
86
|
+
self.declaration_data = type.full_type_symbol
|
87
|
+
else
|
88
|
+
self.base_type = type
|
89
|
+
end
|
90
|
+
end
|
91
|
+
elsif declaration_data.is_a?(::Hash)
|
92
|
+
type_symbol = self[:type] || self["type"]
|
93
|
+
|
94
|
+
if type_symbol
|
95
|
+
if type_symbol.is_a?(::Symbol) || type_symbol.is_a?(::String)
|
96
|
+
type = if absolutified?
|
97
|
+
Domain.current.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
98
|
+
else
|
99
|
+
Domain.current.foobara_lookup_type(type_symbol)
|
100
|
+
end
|
101
|
+
|
102
|
+
if type
|
103
|
+
symbolize_keys!
|
104
|
+
self[:type] = type.full_type_symbol
|
105
|
+
self.is_absolutified = true
|
106
|
+
|
107
|
+
if declaration_data.keys.size == 1
|
108
|
+
self.declaration_data = type.full_type_symbol
|
109
|
+
|
110
|
+
self.type = type
|
111
|
+
self.is_strict = true
|
112
|
+
self.is_deep_duped = true
|
113
|
+
else
|
114
|
+
self.base_type = type
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def hash?
|
123
|
+
declaration_data.is_a?(::Hash)
|
124
|
+
end
|
125
|
+
|
126
|
+
def key?(key)
|
127
|
+
declaration_data.key?(key)
|
128
|
+
end
|
129
|
+
|
130
|
+
def [](key)
|
131
|
+
declaration_data[key]
|
132
|
+
end
|
133
|
+
|
134
|
+
def array?
|
135
|
+
declaration_data.is_a?(::Array)
|
136
|
+
end
|
137
|
+
|
138
|
+
def proc?
|
139
|
+
declaration_data.is_a?(::Proc)
|
140
|
+
end
|
141
|
+
|
142
|
+
def to_proc
|
143
|
+
declaration_data
|
144
|
+
end
|
145
|
+
|
146
|
+
def size
|
147
|
+
declaration_data.size
|
148
|
+
end
|
149
|
+
|
150
|
+
def delete(key)
|
151
|
+
return unless declaration_data.key?(key)
|
152
|
+
|
153
|
+
if duped?
|
154
|
+
declaration_data.delete(key)
|
155
|
+
else
|
156
|
+
self.declaration_data = declaration_data.except(key)
|
157
|
+
self.is_duped = true
|
158
|
+
end
|
159
|
+
|
160
|
+
if strict?
|
161
|
+
self.is_strict = false
|
162
|
+
end
|
163
|
+
|
164
|
+
if absolutified? && key == :type
|
165
|
+
self.is_absolutified = false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def class?
|
170
|
+
declaration_data.is_a?(::Class)
|
171
|
+
end
|
172
|
+
|
173
|
+
def []=(key, value)
|
174
|
+
if strict?
|
175
|
+
self.is_strict = false
|
176
|
+
end
|
177
|
+
|
178
|
+
unless duped?
|
179
|
+
self.declaration_data = declaration_data.dup
|
180
|
+
self.is_duped = true
|
181
|
+
end
|
182
|
+
|
183
|
+
declaration_data[key] = value
|
184
|
+
end
|
185
|
+
|
186
|
+
def all_symbolizable_keys?
|
187
|
+
Util.all_symbolizable_keys?(declaration_data)
|
188
|
+
end
|
189
|
+
|
190
|
+
def symbolize_keys!
|
191
|
+
if duped?
|
192
|
+
declaration_data.transform_keys!(&:to_sym)
|
193
|
+
else
|
194
|
+
self.declaration_data = declaration_data.transform_keys(&:to_sym)
|
195
|
+
self.is_duped = true
|
196
|
+
end
|
197
|
+
|
198
|
+
self
|
199
|
+
end
|
200
|
+
|
201
|
+
def except(...)
|
202
|
+
parts = declaration_data.except(...)
|
203
|
+
|
204
|
+
declaration = clone_from_part(parts)
|
205
|
+
declaration.is_duped = true
|
206
|
+
|
207
|
+
if declaration.strict?
|
208
|
+
declaration.is_strict = false
|
209
|
+
end
|
210
|
+
|
211
|
+
declaration
|
212
|
+
end
|
213
|
+
|
214
|
+
def slice(...)
|
215
|
+
parts = declaration_data.slice(...)
|
216
|
+
|
217
|
+
declaration = clone_from_part(parts)
|
218
|
+
declaration.is_duped = true
|
219
|
+
|
220
|
+
if declaration.strict?
|
221
|
+
declaration.is_strict = false
|
222
|
+
end
|
223
|
+
|
224
|
+
declaration
|
225
|
+
end
|
226
|
+
|
227
|
+
def assign(other)
|
228
|
+
self.declaration_data = other.declaration_data
|
229
|
+
|
230
|
+
if absolutified? != other.absolutified?
|
231
|
+
self.is_absolutified = other.absolutified?
|
232
|
+
end
|
233
|
+
|
234
|
+
if strict? != other.strict?
|
235
|
+
self.is_strict = other.strict?
|
236
|
+
end
|
237
|
+
|
238
|
+
if duped? != other.duped?
|
239
|
+
self.is_duped = other.duped?
|
240
|
+
end
|
241
|
+
|
242
|
+
if deep_duped? != other.deep_duped?
|
243
|
+
self.is_deep_duped = other.deep_duped?
|
244
|
+
end
|
245
|
+
|
246
|
+
if other.type
|
247
|
+
self.type = other.type
|
248
|
+
end
|
249
|
+
|
250
|
+
if other.base_type
|
251
|
+
self.base_type = other.base_type
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def clone
|
256
|
+
declaration = TypeDeclaration.new(declaration_data, false, true)
|
257
|
+
|
258
|
+
if strict?
|
259
|
+
declaration.is_strict = true
|
260
|
+
end
|
261
|
+
|
262
|
+
if absolutified?
|
263
|
+
declaration.is_absolutified = true
|
264
|
+
end
|
265
|
+
|
266
|
+
if type
|
267
|
+
declaration.type = type
|
268
|
+
end
|
269
|
+
|
270
|
+
if base_type
|
271
|
+
declaration.base_type = base_type
|
272
|
+
end
|
273
|
+
|
274
|
+
if reference_checked?
|
275
|
+
declaration.reference_checked = true
|
276
|
+
end
|
277
|
+
|
278
|
+
declaration
|
279
|
+
end
|
280
|
+
|
281
|
+
def clone_from_part(part)
|
282
|
+
TypeDeclaration.new(part)
|
283
|
+
end
|
284
|
+
|
285
|
+
def reference?
|
286
|
+
strict? && declaration_data.is_a?(::Symbol)
|
287
|
+
end
|
288
|
+
|
289
|
+
alias absolutified? is_absolutified
|
290
|
+
alias duped? is_duped
|
291
|
+
alias deep_duped? is_deep_duped
|
292
|
+
alias strict? is_strict
|
293
|
+
alias reference_checked? reference_checked
|
294
|
+
end
|
295
|
+
end
|
@@ -92,25 +92,24 @@ module Foobara
|
|
92
92
|
[desugarizer, type_declaration_validator, to_type_transformer]
|
93
93
|
end
|
94
94
|
|
95
|
-
def process_value(raw_type_declaration)
|
96
|
-
# TODO: deep_dup this again??
|
97
|
-
super.tap do |type_outcome|
|
98
|
-
if type_outcome.success?
|
99
|
-
type_outcome.result.raw_declaration_data = raw_type_declaration
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
95
|
def desugarizer
|
105
96
|
# TODO: memoize this?
|
106
|
-
|
97
|
+
DesugarizerPipeline.new(processors: desugarizers)
|
107
98
|
end
|
108
99
|
|
109
100
|
def desugarize(value)
|
110
|
-
|
101
|
+
unless value.strict?
|
102
|
+
if desugarizer.applicable?(value)
|
103
|
+
value = desugarizer.process_value!(value)
|
104
|
+
value.is_strict = true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
value
|
111
109
|
end
|
112
110
|
|
113
111
|
def type_declaration_validator
|
112
|
+
# TODO: memoize this
|
114
113
|
Value::Processor::Pipeline.new(processors: type_declaration_validators)
|
115
114
|
end
|
116
115
|
|
@@ -30,11 +30,14 @@ module Foobara
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def remove_sensitive_types(strict_type_declaration)
|
33
|
-
|
33
|
+
declaration = TypeDeclaration.new(strict_type_declaration)
|
34
|
+
declaration.is_strict = true
|
35
|
+
|
36
|
+
handler = GlobalDomain.foobara_type_builder.type_declaration_handler_for(declaration)
|
34
37
|
|
35
38
|
sensitive_type_remover = sensitive_type_removers[handler.class.name]
|
36
39
|
|
37
|
-
if sensitive_type_remover
|
40
|
+
if sensitive_type_remover&.applicable?(strict_type_declaration)
|
38
41
|
sensitive_type_remover.process_value!(strict_type_declaration)
|
39
42
|
else
|
40
43
|
strict_type_declaration
|
@@ -51,12 +54,16 @@ module Foobara
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def sensitive_value_remover_class_for_type(type)
|
54
|
-
|
57
|
+
declaration_data = type.declaration_data
|
58
|
+
declaration = TypeDeclaration.new(declaration_data)
|
59
|
+
declaration.is_strict = true
|
60
|
+
|
61
|
+
handler = GlobalDomain.foobara_type_builder.type_declaration_handler_for(declaration)
|
55
62
|
remover_class = sensitive_value_removers[handler.class.name]
|
56
63
|
|
57
64
|
unless remover_class
|
58
65
|
# :nocov:
|
59
|
-
raise "No sensitive value remover found for #{
|
66
|
+
raise "No sensitive value remover found for #{declaration_data}"
|
60
67
|
# :nocov:
|
61
68
|
end
|
62
69
|
|
@@ -89,7 +96,7 @@ module Foobara
|
|
89
96
|
end
|
90
97
|
|
91
98
|
def stringified?
|
92
|
-
foobara_manifest_context_mode == Mode::STRINGIFIED
|
99
|
+
foobara_manifest_context_mode == Mode::STRINGIFIED || strict_stringified?
|
93
100
|
end
|
94
101
|
|
95
102
|
# TODO: we should desugarize these but can't because of a bug where desugarizing entities results in creating the
|
data/projects/types/src/type.rb
CHANGED
@@ -21,7 +21,6 @@ module Foobara
|
|
21
21
|
:element_processors,
|
22
22
|
:structure_count,
|
23
23
|
:is_builtin,
|
24
|
-
:raw_declaration_data,
|
25
24
|
:name,
|
26
25
|
:target_classes,
|
27
26
|
:description,
|
@@ -77,6 +76,15 @@ module Foobara
|
|
77
76
|
validate_processors!
|
78
77
|
end
|
79
78
|
|
79
|
+
# TODO: replace the concept of builtin? with primitive?
|
80
|
+
def primitive?
|
81
|
+
declaration_data.is_a?(::Symbol)
|
82
|
+
end
|
83
|
+
|
84
|
+
def derived?
|
85
|
+
declaration_data.is_a?(::Hash)
|
86
|
+
end
|
87
|
+
|
80
88
|
def sensitive?
|
81
89
|
sensitive
|
82
90
|
end
|
@@ -86,11 +94,23 @@ module Foobara
|
|
86
94
|
end
|
87
95
|
|
88
96
|
def element_type
|
89
|
-
@element_type || base_type&.element_type
|
97
|
+
type = @element_type || base_type&.element_type
|
98
|
+
|
99
|
+
if type.is_a?(::Symbol)
|
100
|
+
type = @element_type = TypeDeclarations::LazyElementTypes.const_get(type).resolve(self)
|
101
|
+
end
|
102
|
+
|
103
|
+
type
|
90
104
|
end
|
91
105
|
|
92
106
|
def element_types
|
93
|
-
@element_types || base_type&.element_types
|
107
|
+
types = @element_types || base_type&.element_types
|
108
|
+
|
109
|
+
if types.is_a?(::Symbol)
|
110
|
+
types = @element_types = TypeDeclarations::LazyElementTypes.const_get(types).resolve(self)
|
111
|
+
end
|
112
|
+
|
113
|
+
types
|
94
114
|
end
|
95
115
|
|
96
116
|
def has_sensitive_types?
|
@@ -380,7 +400,7 @@ module Foobara
|
|
380
400
|
|
381
401
|
if registered?
|
382
402
|
# TODO: we should just use the symbol and nothing else in this context instead of a hash with 1 element.
|
383
|
-
|
403
|
+
foobara_manifest_reference.to_sym
|
384
404
|
elsif remove_sensitive
|
385
405
|
TypeDeclarations.remove_sensitive_types(declaration_data)
|
386
406
|
else
|
@@ -450,6 +470,8 @@ module Foobara
|
|
450
470
|
super.merge(h)
|
451
471
|
end
|
452
472
|
|
473
|
+
# TODO: replace the concept of builtin? with primitive? and delete this method since
|
474
|
+
# primitive? already exists.
|
453
475
|
def builtin?
|
454
476
|
is_builtin
|
455
477
|
end
|
@@ -89,8 +89,13 @@ module Foobara
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def error_message(value)
|
92
|
-
type = declaration_data[:cast_to]
|
93
|
-
|
92
|
+
type = declaration_data[:cast_to]
|
93
|
+
|
94
|
+
if type.is_a?(::Hash)
|
95
|
+
type = type[:type]
|
96
|
+
end
|
97
|
+
|
98
|
+
article = type.to_s =~ /^[aeiouy]/i ? "an" : "a"
|
94
99
|
|
95
100
|
"Cannot cast #{value.inspect} to #{article} #{type}. Expected it to #{applies_message}"
|
96
101
|
end
|
@@ -14,7 +14,15 @@ module Foobara
|
|
14
14
|
|
15
15
|
def process_outcome(old_outcome)
|
16
16
|
processors.inject(old_outcome) do |outcome, processor|
|
17
|
-
|
17
|
+
return outcome if outcome.fatal?
|
18
|
+
|
19
|
+
value = outcome.result
|
20
|
+
|
21
|
+
if processor.applicable?(value)
|
22
|
+
processor.process_outcome(outcome)
|
23
|
+
else
|
24
|
+
outcome
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -95,6 +95,7 @@ module Foobara
|
|
95
95
|
monitor.synchronize do
|
96
96
|
ref = ref_for(object_or_object_id)
|
97
97
|
|
98
|
+
# TODO: is this necessary? Why not check weakref_alive? now that we're in a mutex?
|
98
99
|
object = begin
|
99
100
|
ref&.__getobj__
|
100
101
|
rescue WeakRef::RefError
|
@@ -122,6 +123,7 @@ module Foobara
|
|
122
123
|
def each
|
123
124
|
monitor.synchronize do
|
124
125
|
objects.each_value do |ref|
|
126
|
+
# Is this still necessary now that we're in a mutex?
|
125
127
|
object = begin
|
126
128
|
ref.__getobj__
|
127
129
|
rescue WeakRef::RefError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
@@ -373,6 +373,7 @@ files:
|
|
373
373
|
- projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb
|
374
374
|
- projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb
|
375
375
|
- projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb
|
376
|
+
- projects/model/src/extensions/type_declarations/lazy_element_types/model.rb
|
376
377
|
- projects/model/src/model.rb
|
377
378
|
- projects/model/src/sensitive_type_removers/extended_model.rb
|
378
379
|
- projects/model/src/sensitive_type_removers/model.rb
|
@@ -421,6 +422,7 @@ files:
|
|
421
422
|
- projects/type_declarations/src/attributes_transformers/reject.rb
|
422
423
|
- projects/type_declarations/src/caster.rb
|
423
424
|
- projects/type_declarations/src/desugarizer.rb
|
425
|
+
- projects/type_declarations/src/desugarizer_pipeline.rb
|
424
426
|
- projects/type_declarations/src/dsl/attributes.rb
|
425
427
|
- projects/type_declarations/src/element_processor.rb
|
426
428
|
- projects/type_declarations/src/error_extension.rb
|
@@ -430,7 +432,9 @@ files:
|
|
430
432
|
- projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb
|
431
433
|
- projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb
|
432
434
|
- projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb
|
435
|
+
- projects/type_declarations/src/handlers/extend_associative_array_type_declaration/key_type_declaration_desugarizer.rb
|
433
436
|
- projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb
|
437
|
+
- projects/type_declarations/src/handlers/extend_associative_array_type_declaration/value_type_declaration_desugarizer.rb
|
434
438
|
- projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb
|
435
439
|
- projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb
|
436
440
|
- projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb
|
@@ -442,13 +446,11 @@ files:
|
|
442
446
|
- projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb
|
443
447
|
- projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb
|
444
448
|
- projects/type_declarations/src/handlers/registered_type_declaration.rb
|
445
|
-
- projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb
|
446
|
-
- projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb
|
447
|
-
- projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb
|
448
|
-
- projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb
|
449
|
-
- projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb
|
450
449
|
- projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb
|
451
|
-
- projects/type_declarations/src/
|
450
|
+
- projects/type_declarations/src/lazy_element_types/array.rb
|
451
|
+
- projects/type_declarations/src/lazy_element_types/attributes.rb
|
452
|
+
- projects/type_declarations/src/lazy_element_types/hash.rb
|
453
|
+
- projects/type_declarations/src/lazy_element_types/tuple.rb
|
452
454
|
- projects/type_declarations/src/processor.rb
|
453
455
|
- projects/type_declarations/src/remove_sensitive_values_transformer.rb
|
454
456
|
- projects/type_declarations/src/sensitive_type_remover.rb
|
@@ -459,6 +461,7 @@ files:
|
|
459
461
|
- projects/type_declarations/src/to_type_transformer.rb
|
460
462
|
- projects/type_declarations/src/transformer.rb
|
461
463
|
- projects/type_declarations/src/type_builder.rb
|
464
|
+
- projects/type_declarations/src/type_declaration.rb
|
462
465
|
- projects/type_declarations/src/type_declaration_error.rb
|
463
466
|
- projects/type_declarations/src/type_declaration_handler.rb
|
464
467
|
- projects/type_declarations/src/type_declaration_handler_registry.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
Foobara.require_project_file("type_declarations", "desugarizer")
|
2
|
-
|
3
|
-
module Foobara
|
4
|
-
module TypeDeclarations
|
5
|
-
module Handlers
|
6
|
-
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
7
|
-
# type_symbol is basically just a flag that lets us know that type is fully qualified.
|
8
|
-
# rather hacky but other potential workarounds seemed gnarlier
|
9
|
-
class DesugarizerMetadataCleanupDesugarizer < TypeDeclarations::Desugarizer
|
10
|
-
def applicable?(strict_type_declaration)
|
11
|
-
strict_type_declaration.is_a?(::Hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
def desugarize(strict_type_declaration)
|
15
|
-
strict_type_declaration = strict_type_declaration.dup
|
16
|
-
|
17
|
-
strict_type_declaration.delete(:_desugarized)
|
18
|
-
|
19
|
-
strict_type_declaration
|
20
|
-
end
|
21
|
-
|
22
|
-
def priority
|
23
|
-
Priority::LOWEST + 100
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
Foobara.require_project_file("type_declarations", "desugarizer")
|
2
|
-
|
3
|
-
module Foobara
|
4
|
-
module TypeDeclarations
|
5
|
-
module Handlers
|
6
|
-
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
7
|
-
class ShortTypeNameDesugarizer < TypeDeclarations::Desugarizer
|
8
|
-
def applicable?(sugary_type_declaration)
|
9
|
-
return false if TypeDeclarations.strict_stringified? || TypeDeclarations.strict?
|
10
|
-
return false unless sugary_type_declaration.is_a?(::Hash)
|
11
|
-
|
12
|
-
sugary_type_declaration = sugary_type_declaration.dup
|
13
|
-
|
14
|
-
sugary_type_declaration = normalize_type(sugary_type_declaration)
|
15
|
-
|
16
|
-
if sugary_type_declaration.key?(:type) &&
|
17
|
-
!sugary_type_declaration.dig(:_desugarized, :type_absolutified)
|
18
|
-
type_symbol = sugary_type_declaration[:type]
|
19
|
-
|
20
|
-
(type_symbol.is_a?(::Symbol) || type_symbol.is_a?(::String)) && type_registered?(type_symbol)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def desugarize(sugary_type_declaration)
|
25
|
-
sugary_type_declaration = normalize_type(sugary_type_declaration)
|
26
|
-
|
27
|
-
type_symbol = sugary_type_declaration[:type]
|
28
|
-
type = lookup_type!(type_symbol)
|
29
|
-
|
30
|
-
desugarized = sugary_type_declaration[:_desugarized] || {}
|
31
|
-
desugarized[:type_absolutified] = true
|
32
|
-
# TODO: just use the symbol and nothing else??
|
33
|
-
# maybe confusing in languages with no distinction between symbol and string?
|
34
|
-
sugary_type_declaration.merge(type: type.full_type_symbol, _desugarized: desugarized)
|
35
|
-
end
|
36
|
-
|
37
|
-
# TODO: clean this up in a different desugarizer so we don't have to think about it here
|
38
|
-
def normalize_type(sugary_type_declaration)
|
39
|
-
if sugary_type_declaration.key?("type") && !sugary_type_declaration.key?(:type)
|
40
|
-
if Util.all_symbolizable_keys?(sugary_type_declaration)
|
41
|
-
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
42
|
-
type_symbol = sugary_type_declaration[:type]
|
43
|
-
|
44
|
-
if type_symbol.is_a?(::String)
|
45
|
-
sugary_type_declaration[:type] = type_symbol.to_sym
|
46
|
-
end
|
47
|
-
end
|
48
|
-
else
|
49
|
-
sugary_type_declaration = sugary_type_declaration.dup
|
50
|
-
end
|
51
|
-
|
52
|
-
sugary_type_declaration
|
53
|
-
end
|
54
|
-
|
55
|
-
def priority
|
56
|
-
Priority::FIRST + 2
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|