foobara 0.0.142 → 0.1.2
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 +25 -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 +41 -16
- data/projects/command_connectors/src/command_registry.rb +7 -4
- data/projects/command_connectors/src/transformed_command.rb +55 -43
- 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/common/src/possible_error.rb +27 -21
- data/projects/detached_entity/src/concerns/types.rb +7 -1
- data/projects/detached_entity/src/detached_entity_type.rb +10 -0
- 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/domain/src/is_manifestable.rb +19 -7
- 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 +18 -88
- data/projects/types/src/type.rb +34 -9
- 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 -8
- 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 +11 -8
- 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
@@ -63,9 +63,12 @@ module Foobara
|
|
63
63
|
declaration = type_declaration(attributes_type.declaration_data)
|
64
64
|
|
65
65
|
if model_type
|
66
|
-
unless Foobara::TypeDeclarations.declarations_equal?(declaration
|
66
|
+
unless Foobara::TypeDeclarations.declarations_equal?(declaration.declaration_data,
|
67
|
+
model_type.declaration_data)
|
68
|
+
|
67
69
|
type_domain = domain
|
68
70
|
self.model_type = nil
|
71
|
+
|
69
72
|
type_domain.foobara_type_from_declaration(declaration)
|
70
73
|
end
|
71
74
|
else
|
@@ -97,19 +100,25 @@ module Foobara
|
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
103
|
+
type_declaration = TypeDeclaration.new(
|
104
|
+
Util.remove_blank(
|
105
|
+
type: :model,
|
106
|
+
name: model_name,
|
107
|
+
model_module: model_module_name,
|
108
|
+
model_class:,
|
109
|
+
model_base_class:,
|
110
|
+
attributes_declaration:,
|
111
|
+
description:,
|
112
|
+
mutable:,
|
113
|
+
delegates:,
|
114
|
+
private: private_attribute_names
|
115
|
+
)
|
112
116
|
)
|
117
|
+
|
118
|
+
type_declaration.is_absolutified = true
|
119
|
+
type_declaration.is_duped = true
|
120
|
+
|
121
|
+
type_declaration
|
113
122
|
end
|
114
123
|
|
115
124
|
def foobara_attributes_type
|
@@ -152,16 +161,16 @@ module Foobara
|
|
152
161
|
end
|
153
162
|
end
|
154
163
|
|
155
|
-
def
|
156
|
-
@
|
164
|
+
def foobara_delegates
|
165
|
+
@foobara_delegates ||= {}
|
157
166
|
end
|
158
167
|
|
159
168
|
def has_delegated_attributes?
|
160
169
|
!delegates.empty?
|
161
170
|
end
|
162
171
|
|
163
|
-
def
|
164
|
-
@
|
172
|
+
def foobara_private_attribute_names
|
173
|
+
@foobara_private_attribute_names ||= []
|
165
174
|
end
|
166
175
|
|
167
176
|
def private_attributes(attribute_names)
|
@@ -171,7 +180,7 @@ module Foobara
|
|
171
180
|
end
|
172
181
|
|
173
182
|
def private_attribute(attribute_name)
|
174
|
-
@
|
183
|
+
@foobara_private_attribute_names = private_attribute_names | [attribute_name]
|
175
184
|
|
176
185
|
set_model_type
|
177
186
|
end
|
@@ -229,20 +238,26 @@ module Foobara
|
|
229
238
|
private = []
|
230
239
|
attributes_type_declaration = TypeDeclarations.args_to_type_declaration(...)
|
231
240
|
|
232
|
-
if attributes_type_declaration.
|
241
|
+
if attributes_type_declaration.hash? || attributes_type_declaration.proc?
|
233
242
|
handler = domain.foobara_type_builder.handler_for_class(
|
234
243
|
TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
235
244
|
)
|
236
245
|
attributes_type_declaration = Namespace.use domain do
|
237
|
-
handler.desugarize(attributes_type_declaration)
|
246
|
+
handler.desugarize(attributes_type_declaration.clone)
|
238
247
|
end
|
239
248
|
|
240
249
|
element_type_declarations = attributes_type_declaration[:element_type_declarations]
|
241
250
|
|
242
251
|
element_type_declarations.each_pair do |attribute_name, attribute_type_declaration|
|
252
|
+
next if attribute_type_declaration.is_a?(::Symbol)
|
253
|
+
|
243
254
|
is_private = attribute_type_declaration.delete(:private)
|
244
255
|
|
245
256
|
if is_private
|
257
|
+
if attribute_type_declaration.keys.size == 1
|
258
|
+
element_type_declarations[attribute_name] = attribute_type_declaration[:type]
|
259
|
+
end
|
260
|
+
|
246
261
|
private |= [attribute_name]
|
247
262
|
end
|
248
263
|
end
|
data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb
CHANGED
@@ -22,16 +22,20 @@ module Foobara
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def possible_errors
|
25
|
-
|
25
|
+
if parent_declaration_data.is_a?(::Hash)
|
26
|
+
model_class_name = parent_declaration_data[:model_class]
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
if model_class_name
|
29
|
+
model_class = if Object.const_defined?(model_class_name)
|
30
|
+
Object.const_get(model_class_name)
|
31
|
+
else
|
32
|
+
Namespace.current.foobara_lookup_type!(model_class_name).target_class
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
+
model_class.possible_errors
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
35
39
|
else
|
36
40
|
super
|
37
41
|
end
|
@@ -12,7 +12,7 @@ module Foobara
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def applicable?(strict_type_declaration)
|
15
|
-
strict_type_declaration.
|
15
|
+
strict_type_declaration.hash? && strict_type_declaration.key?(:private)
|
16
16
|
end
|
17
17
|
|
18
18
|
def validation_errors(strict_type_declaration)
|
@@ -15,7 +15,21 @@ module Foobara
|
|
15
15
|
handler = handler_for_class(ExtendAttributesTypeDeclaration)
|
16
16
|
attributes_type_declaration = sugary_type_declaration[:attributes_declaration]
|
17
17
|
|
18
|
-
sugary_type_declaration.
|
18
|
+
declaration = sugary_type_declaration.clone_from_part(attributes_type_declaration)
|
19
|
+
|
20
|
+
if sugary_type_declaration.deep_duped?
|
21
|
+
# TODO: probably not worth directly testing this path
|
22
|
+
# :nocov:
|
23
|
+
declaration.is_duped = true
|
24
|
+
declaration.is_deep_duped = true
|
25
|
+
# :nocov:
|
26
|
+
end
|
27
|
+
|
28
|
+
declaration = handler.desugarize(declaration)
|
29
|
+
|
30
|
+
sugary_type_declaration[:attributes_declaration] = declaration.declaration_data
|
31
|
+
|
32
|
+
sugary_type_declaration
|
19
33
|
end
|
20
34
|
end
|
21
35
|
end
|
@@ -8,13 +8,13 @@ module Foobara
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def desugarize(sugary_type_declaration)
|
11
|
-
|
12
|
-
delegates = Util.deep_symbolize_keys(desugarized[:delegates])
|
11
|
+
delegates = sugary_type_declaration[:delegates]
|
13
12
|
|
14
13
|
if delegates.empty?
|
15
|
-
|
16
|
-
desugarized
|
14
|
+
sugary_type_declaration.delete(:delegates)
|
17
15
|
else
|
16
|
+
delegates = Util.deep_symbolize_keys(sugary_type_declaration[:delegates])
|
17
|
+
|
18
18
|
delegates.each_pair do |attribute_name, delegate_info|
|
19
19
|
h = delegate_info.merge(data_path: DataPath.new(delegate_info[:data_path]).to_s)
|
20
20
|
|
@@ -29,8 +29,10 @@ module Foobara
|
|
29
29
|
delegates[attribute_name] = h
|
30
30
|
end
|
31
31
|
|
32
|
-
sugary_type_declaration
|
32
|
+
sugary_type_declaration[:delegates] = delegates
|
33
33
|
end
|
34
|
+
|
35
|
+
sugary_type_declaration
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -4,12 +4,8 @@ module Foobara
|
|
4
4
|
class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
class HashDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
return false unless sugary_type_declaration.
|
8
|
-
return false unless
|
9
|
-
|
10
|
-
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
11
|
-
|
12
|
-
return true unless sugary_type_declaration.key?(:type)
|
7
|
+
return false unless sugary_type_declaration.hash?
|
8
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
13
9
|
|
14
10
|
sugary_type_declaration[:type] == expected_type_symbol
|
15
11
|
end
|
@@ -19,7 +15,8 @@ module Foobara
|
|
19
15
|
end
|
20
16
|
|
21
17
|
def desugarize(sugary_type_declaration)
|
22
|
-
|
18
|
+
sugary_type_declaration.symbolize_keys!
|
19
|
+
sugary_type_declaration
|
23
20
|
end
|
24
21
|
|
25
22
|
def priority
|
@@ -17,8 +17,6 @@ module Foobara
|
|
17
17
|
|
18
18
|
# TODO: consider splitting this up into multiple desugarizers
|
19
19
|
def desugarize(strictish_type_declaration)
|
20
|
-
strictish_type_declaration = strictish_type_declaration.dup
|
21
|
-
|
22
20
|
if strictish_type_declaration.key?(:model_module)
|
23
21
|
model_module = strictish_type_declaration[:model_module]
|
24
22
|
|
@@ -4,19 +4,28 @@ module Foobara
|
|
4
4
|
class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
class MovePrivateFromElementTypesToRoot < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(value)
|
7
|
-
if value.
|
8
|
-
|
7
|
+
if value.hash? && value.key?(:type) && value.key?(:attributes_declaration)
|
8
|
+
type = value.type || lookup_type(value[:type])
|
9
9
|
|
10
|
-
if
|
11
|
-
type
|
12
|
-
|
10
|
+
if type
|
11
|
+
if type.extends?(BuiltinTypes[:model])
|
12
|
+
value.base_type = type
|
13
|
+
true
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def desugarize(rawish_type_declaration)
|
18
20
|
private = rawish_type_declaration[:private]
|
19
|
-
|
21
|
+
|
22
|
+
if private.nil?
|
23
|
+
private = []
|
24
|
+
else
|
25
|
+
unless rawish_type_declaration.deep_duped?
|
26
|
+
private = private.dup
|
27
|
+
end
|
28
|
+
end
|
20
29
|
|
21
30
|
attributes_declaration = rawish_type_declaration[:attributes_declaration]
|
22
31
|
element_type_declarations = attributes_declaration[:element_type_declarations]
|
@@ -24,7 +33,15 @@ module Foobara
|
|
24
33
|
element_type_declarations.each_pair do |attribute_name, attribute_type_declaration|
|
25
34
|
if attribute_type_declaration.is_a?(Hash) && attribute_type_declaration.key?(:private)
|
26
35
|
is_private = attribute_type_declaration[:private]
|
27
|
-
|
36
|
+
|
37
|
+
declaration = attribute_type_declaration.except(:private)
|
38
|
+
|
39
|
+
if declaration.keys == [:type]
|
40
|
+
declaration = TypeDeclaration.new(declaration).declaration_data
|
41
|
+
end
|
42
|
+
|
43
|
+
element_type_declarations[attribute_name] = declaration
|
44
|
+
|
28
45
|
if is_private
|
29
46
|
private |= [attribute_name]
|
30
47
|
end
|
@@ -32,10 +49,12 @@ module Foobara
|
|
32
49
|
end
|
33
50
|
|
34
51
|
if private.empty?
|
35
|
-
rawish_type_declaration.
|
52
|
+
rawish_type_declaration.delete(:private)
|
36
53
|
else
|
37
|
-
rawish_type_declaration
|
54
|
+
rawish_type_declaration[:private] = private
|
38
55
|
end
|
56
|
+
|
57
|
+
rawish_type_declaration
|
39
58
|
end
|
40
59
|
|
41
60
|
def priority
|
@@ -4,11 +4,12 @@ module Foobara
|
|
4
4
|
class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
class SymbolizePrivate < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(value)
|
7
|
-
if value.
|
8
|
-
type_symbol = value[:type]
|
7
|
+
if value.hash? && value.key?(:type) && value.key?(:attributes_declaration) && value.key?(:private)
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
type = value.type || lookup_type(value[:type])
|
10
|
+
|
11
|
+
if type
|
12
|
+
value.type = type
|
12
13
|
type.extends?(BuiltinTypes[:model])
|
13
14
|
end
|
14
15
|
end
|
@@ -18,10 +19,10 @@ module Foobara
|
|
18
19
|
private = rawish_type_declaration[:private]
|
19
20
|
|
20
21
|
if private.any? { |key| key.is_a?(::String) }
|
21
|
-
rawish_type_declaration
|
22
|
-
else
|
23
|
-
rawish_type_declaration
|
22
|
+
rawish_type_declaration[:private] = private.map(&:to_sym)
|
24
23
|
end
|
24
|
+
|
25
|
+
rawish_type_declaration
|
25
26
|
end
|
26
27
|
|
27
28
|
def priority
|
@@ -25,7 +25,7 @@ module Foobara
|
|
25
25
|
else
|
26
26
|
existing_type = Domain.current.foobara_lookup_type(
|
27
27
|
model_class_name,
|
28
|
-
mode: Namespace::LookupMode::
|
28
|
+
mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
|
29
29
|
)
|
30
30
|
|
31
31
|
existing_type&.target_class
|
@@ -77,10 +77,7 @@ module Foobara
|
|
77
77
|
if outcome.success?
|
78
78
|
type = outcome.result
|
79
79
|
|
80
|
-
|
81
|
-
attributes_type_declaration = type.declaration_data[:attributes_declaration]
|
82
|
-
|
83
|
-
type.element_types = handler.process_value!(attributes_type_declaration)
|
80
|
+
type.element_types = :Model
|
84
81
|
|
85
82
|
model_class = type.target_class
|
86
83
|
existing_model_type = model_class.model_type
|
@@ -105,8 +102,8 @@ module Foobara
|
|
105
102
|
|
106
103
|
model_class.description type.declaration_data[:description]
|
107
104
|
|
108
|
-
if domain.foobara_type_registered?(type_symbol, mode: Namespace::LookupMode::
|
109
|
-
existing_type = domain.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::
|
105
|
+
if domain.foobara_type_registered?(type_symbol, mode: Namespace::LookupMode::DIRECT)
|
106
|
+
existing_type = domain.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::DIRECT)
|
110
107
|
domain.foobara_unregister(existing_type)
|
111
108
|
end
|
112
109
|
|
data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb
CHANGED
@@ -3,8 +3,20 @@ module Foobara
|
|
3
3
|
module Handlers
|
4
4
|
class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
def applicable?(sugary_type_declaration)
|
6
|
-
if sugary_type_declaration.
|
7
|
-
|
6
|
+
if sugary_type_declaration.hash?
|
7
|
+
strict_type_declaration = if sugary_type_declaration.strict?
|
8
|
+
sugary_type_declaration
|
9
|
+
else
|
10
|
+
desugarize(sugary_type_declaration.clone)
|
11
|
+
end
|
12
|
+
|
13
|
+
if strict_type_declaration[:type] == expected_type_symbol
|
14
|
+
unless sugary_type_declaration.equal?(strict_type_declaration)
|
15
|
+
sugary_type_declaration.assign(strict_type_declaration)
|
16
|
+
end
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
10
22
|
|
@@ -1,21 +1,20 @@
|
|
1
1
|
module Foobara
|
2
2
|
module TypeDeclarations
|
3
3
|
module Handlers
|
4
|
+
# TODO: Can't we just delete this type entirely?
|
4
5
|
class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
6
|
class HashDesugarizer < TypeDeclarations::Desugarizer
|
6
7
|
def applicable?(sugary_type_declaration)
|
7
|
-
return false unless sugary_type_declaration.
|
8
|
+
return false unless sugary_type_declaration.hash?
|
8
9
|
|
9
10
|
type_symbol = sugary_type_declaration[:type]
|
10
11
|
|
11
|
-
if type_symbol
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
)
|
12
|
+
if type_symbol.is_a?(::Symbol)
|
13
|
+
# TODO: cache this on a #base_type= helper
|
14
|
+
type = sugary_type_declaration.type ||
|
15
|
+
lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
16
16
|
|
17
|
-
|
18
|
-
end
|
17
|
+
type&.extends?(BuiltinTypes[expected_type_symbol])
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -24,7 +23,7 @@ module Foobara
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def desugarize(sugary_type_declaration)
|
27
|
-
|
26
|
+
sugary_type_declaration.symbolize_keys!
|
28
27
|
end
|
29
28
|
|
30
29
|
def priority
|
@@ -4,7 +4,7 @@ module Foobara
|
|
4
4
|
class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
class ModelClassTypeDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
if sugary_type_declaration.
|
7
|
+
if sugary_type_declaration.hash? && sugary_type_declaration.key?(:type)
|
8
8
|
type = sugary_type_declaration[:type]
|
9
9
|
type.is_a?(::Class) && type < Model
|
10
10
|
end
|
@@ -12,7 +12,11 @@ module Foobara
|
|
12
12
|
|
13
13
|
def desugarize(hash)
|
14
14
|
model_class = hash[:type]
|
15
|
-
hash
|
15
|
+
hash[:type] = model_class.model_type.foobara_manifest_reference.to_sym
|
16
|
+
|
17
|
+
hash.handle_symbolic_declaration
|
18
|
+
|
19
|
+
hash
|
16
20
|
end
|
17
21
|
|
18
22
|
def priority
|
@@ -21,9 +21,12 @@ module Foobara
|
|
21
21
|
|
22
22
|
def validation_errors(strict_type_declaration)
|
23
23
|
mutable = strict_type_declaration[:mutable]
|
24
|
-
return if
|
24
|
+
return if mutable == true || mutable == false
|
25
|
+
|
26
|
+
model_type = strict_type_declaration.type
|
27
|
+
|
28
|
+
model_type ||= type_for_declaration(strict_type_declaration[:type])
|
25
29
|
|
26
|
-
model_type = type_for_declaration(strict_type_declaration[:type])
|
27
30
|
valid_attribute_names = model_type.element_types.element_types.keys
|
28
31
|
|
29
32
|
mutable.map do |key|
|
@@ -4,22 +4,23 @@ module Foobara
|
|
4
4
|
class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
5
|
class NormalizeMutableAttributesDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(value)
|
7
|
-
if value.
|
7
|
+
if value.hash? && value.key?(:mutable) && value.key?(:type)
|
8
8
|
mutable = value[:mutable]
|
9
9
|
|
10
|
-
return false if
|
10
|
+
return false if mutable == true || mutable == false
|
11
11
|
|
12
12
|
if !mutable.is_a?(::Array) || (mutable.is_a?(::Array) && mutable.any? { |k| !k.is_a?(::Symbol) })
|
13
|
-
type =
|
14
|
-
|
13
|
+
type = value.type ||
|
14
|
+
lookup_type(value[:type], mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
|
15
|
+
|
16
|
+
type&.extends?(BuiltinTypes[:model])
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
def desugarize(rawish_type_declaration)
|
20
|
-
rawish_type_declaration.
|
21
|
-
|
22
|
-
)
|
22
|
+
rawish_type_declaration[:mutable] = Util.array(rawish_type_declaration[:mutable]).map!(&:to_sym)
|
23
|
+
rawish_type_declaration
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
@@ -2,6 +2,7 @@ module Foobara
|
|
2
2
|
module TypeDeclarations
|
3
3
|
module Handlers
|
4
4
|
class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
|
+
# TODO: seems like we can delete this handler entirely?
|
5
6
|
class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
|
6
7
|
# TODO: make declaration validator for model_class and model_base_class
|
7
8
|
def target_classes(strict_type_declaration)
|
@@ -14,7 +15,9 @@ module Foobara
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def declaration_to_type(strict_type_declaration)
|
17
|
-
|
18
|
+
# TODO: cache this on a #base_type= helper
|
19
|
+
strict_type_declaration.type ||
|
20
|
+
lookup_type(strict_type_declaration[:type], mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -4,17 +4,32 @@ module Foobara
|
|
4
4
|
# Why doesn't this inherit from ExtendModelTypeDeclaration
|
5
5
|
class ExtendRegisteredModelTypeDeclaration < ExtendRegisteredTypeDeclaration
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
strict_type_declaration =
|
7
|
+
strict_type_declaration = if sugary_type_declaration.strict?
|
8
|
+
# :nocov:
|
9
|
+
sugary_type_declaration
|
10
|
+
# :nocov:
|
11
|
+
else
|
12
|
+
desugarize(sugary_type_declaration.clone)
|
13
|
+
end
|
8
14
|
|
9
|
-
if strict_type_declaration.
|
15
|
+
if strict_type_declaration.hash? && strict_type_declaration.key?(:type)
|
10
16
|
type_symbol = strict_type_declaration[:type]
|
11
17
|
|
12
18
|
return false if type_symbol == expected_type_symbol
|
13
19
|
return false unless type_symbol.is_a?(::Symbol) || type_symbol.is_a?(::String)
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
# TODO: cache this on a #base_type= helper
|
22
|
+
type = strict_type_declaration.type ||
|
23
|
+
lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
24
|
+
|
25
|
+
if type
|
26
|
+
if type.extends?(BuiltinTypes[expected_type_symbol])
|
27
|
+
unless sugary_type_declaration.equal?(strict_type_declaration)
|
28
|
+
sugary_type_declaration.assign(strict_type_declaration)
|
29
|
+
end
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
@@ -4,13 +4,31 @@ module Foobara
|
|
4
4
|
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
5
5
|
class ModelClassDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
sugary_type_declaration.
|
7
|
+
sugary_type_declaration.class? && sugary_type_declaration.declaration_data < Model
|
8
8
|
end
|
9
9
|
|
10
|
-
def desugarize(
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def desugarize(declaration)
|
11
|
+
model_class = declaration.declaration_data
|
12
|
+
|
13
|
+
declaration.declaration_data = model_class.model_type.foobara_manifest_reference.to_sym
|
14
|
+
|
15
|
+
type = model_class.model_type
|
16
|
+
|
17
|
+
if type
|
18
|
+
declaration.type = type
|
19
|
+
declaration.reference_checked = true
|
20
|
+
else
|
21
|
+
# :nocov:
|
22
|
+
declaration.reference_checked = false
|
23
|
+
# :nocov:
|
24
|
+
end
|
25
|
+
|
26
|
+
declaration.is_absolutified = true
|
27
|
+
declaration.is_strict = true
|
28
|
+
declaration.is_duped = true
|
29
|
+
declaration.is_deep_duped = true
|
30
|
+
|
31
|
+
declaration
|
14
32
|
end
|
15
33
|
|
16
34
|
def priority
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module LazyElementTypes
|
4
|
+
module Model
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def resolve(type)
|
8
|
+
attributes_type_declaration = type.declaration_data[:attributes_declaration]
|
9
|
+
|
10
|
+
type.element_types = TypeDeclarations.strict do
|
11
|
+
handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
|
12
|
+
handler.process_value!(TypeDeclaration.new(attributes_type_declaration))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|