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
@@ -25,12 +25,16 @@ module Foobara
|
|
25
25
|
TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
26
26
|
)
|
27
27
|
|
28
|
-
|
29
|
-
type:
|
28
|
+
declaration = TypeDeclaration.new(
|
29
|
+
type: :attributes,
|
30
30
|
element_type_declarations:,
|
31
31
|
required:,
|
32
32
|
defaults:
|
33
33
|
)
|
34
|
+
declaration.is_absolutified = true
|
35
|
+
declaration.is_duped = true
|
36
|
+
|
37
|
+
handler.desugarize(declaration).declaration_data
|
34
38
|
end
|
35
39
|
|
36
40
|
def only(declaration, *keys)
|
@@ -49,9 +53,8 @@ module Foobara
|
|
49
53
|
reject(declaration, keys_to_reject)
|
50
54
|
end
|
51
55
|
|
52
|
-
def reject(
|
53
|
-
|
54
|
-
declaration = Util.deep_dup(declaration)
|
56
|
+
def reject(declaration_data, *keys)
|
57
|
+
declaration = TypeDeclaration.new(declaration_data)
|
55
58
|
|
56
59
|
element_type_declarations = declaration[:element_type_declarations]
|
57
60
|
required = declaration[:required]
|
@@ -64,17 +67,20 @@ module Foobara
|
|
64
67
|
|
65
68
|
if element_type_declarations.key?(key)
|
66
69
|
changed = true
|
67
|
-
element_type_declarations.
|
70
|
+
declaration[:element_type_declarations] = declaration[:element_type_declarations].except(key)
|
68
71
|
end
|
69
72
|
|
70
73
|
if required&.include?(key)
|
71
74
|
changed = true
|
75
|
+
required = required.dup
|
72
76
|
required.delete(key)
|
77
|
+
declaration[:required] = required
|
73
78
|
end
|
74
79
|
|
75
80
|
if defaults&.key?(key)
|
76
81
|
changed = true
|
77
|
-
defaults.
|
82
|
+
defaults = defaults.except(key)
|
83
|
+
declaration[:defaults] = defaults
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
@@ -83,9 +89,9 @@ module Foobara
|
|
83
89
|
TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
84
90
|
)
|
85
91
|
|
86
|
-
handler.desugarize(declaration)
|
92
|
+
handler.desugarize(declaration).declaration_data
|
87
93
|
else
|
88
|
-
|
94
|
+
declaration_data
|
89
95
|
end
|
90
96
|
end
|
91
97
|
end
|
@@ -48,7 +48,7 @@ module Foobara
|
|
48
48
|
|
49
49
|
declaration[:element_type_declarations].each_pair do |attribute_name, declaration_data|
|
50
50
|
element_type_declarations[attribute_name] = if from_yaml.include?(attribute_name)
|
51
|
-
|
51
|
+
:string
|
52
52
|
else
|
53
53
|
declaration_data
|
54
54
|
end
|
@@ -117,7 +117,8 @@ module Foobara
|
|
117
117
|
_add_attribute(attribute_name, type)
|
118
118
|
else
|
119
119
|
declaration = if block
|
120
|
-
attributes_declaration =
|
120
|
+
attributes_declaration =
|
121
|
+
Attributes.to_declaration(&block).declaration_data.merge(declaration)
|
121
122
|
|
122
123
|
if type == :array
|
123
124
|
{
|
@@ -173,13 +174,21 @@ module Foobara
|
|
173
174
|
|
174
175
|
def _type_declaration
|
175
176
|
@_type_declaration ||= begin
|
176
|
-
|
177
|
-
type:
|
177
|
+
declaration = TypeDeclaration.new(
|
178
|
+
type: :attributes,
|
178
179
|
element_type_declarations: {}
|
179
|
-
|
180
|
+
)
|
181
|
+
|
182
|
+
declaration.is_absolutified = true
|
183
|
+
declaration.is_duped = true
|
180
184
|
|
181
185
|
handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
|
182
|
-
handler.desugarize(
|
186
|
+
declaration = handler.desugarize(declaration)
|
187
|
+
|
188
|
+
declaration.is_strict = false
|
189
|
+
declaration.is_absolutified = true
|
190
|
+
|
191
|
+
declaration
|
183
192
|
end
|
184
193
|
end
|
185
194
|
end
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb
CHANGED
@@ -8,18 +8,38 @@ module Foobara
|
|
8
8
|
# TODO: make a quick way to convert a couple simple procs into a transformer
|
9
9
|
class ArrayDesugarizer < TypeDeclarations::Desugarizer
|
10
10
|
def applicable?(sugary_type_declaration)
|
11
|
-
sugary_type_declaration.
|
11
|
+
sugary_type_declaration.array? && sugary_type_declaration.size <= 1 && !sugary_type_declaration.strict?
|
12
12
|
end
|
13
13
|
|
14
14
|
def desugarize(sugary_type_declaration)
|
15
|
-
strict_type_declaration =
|
15
|
+
strict_type_declaration = sugary_type_declaration
|
16
|
+
sugary_type_declaration = sugary_type_declaration.declaration_data
|
17
|
+
|
18
|
+
strict_type_declaration.declaration_data = { type: :array }
|
19
|
+
strict_type_declaration.is_duped = true
|
20
|
+
strict_type_declaration.is_absolutified = true
|
16
21
|
|
17
22
|
unless sugary_type_declaration.empty?
|
18
23
|
element_type_declaration = sugary_type_declaration.first
|
19
24
|
|
20
|
-
|
25
|
+
element_type_declaration = if element_type_declaration.is_a?(Types::Type)
|
26
|
+
element_type_declaration.reference_or_declaration_data
|
27
|
+
else
|
28
|
+
declaration = TypeDeclaration.new(element_type_declaration)
|
29
|
+
|
30
|
+
if strict_type_declaration.deep_duped?
|
31
|
+
# TODO: probably not worth directly testing this path
|
32
|
+
# :nocov:
|
33
|
+
declaration.is_deep_duped = true
|
34
|
+
declaration.is_duped = true
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
|
38
|
+
handler = type_declaration_handler_for(declaration)
|
39
|
+
handler.desugarize(declaration).declaration_data
|
40
|
+
end
|
21
41
|
|
22
|
-
strict_type_declaration[:element_type_declaration] =
|
42
|
+
strict_type_declaration[:element_type_declaration] = element_type_declaration
|
23
43
|
end
|
24
44
|
|
25
45
|
strict_type_declaration
|
@@ -4,23 +4,37 @@ module Foobara
|
|
4
4
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
5
5
|
class ElementTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
return false
|
8
|
-
return false unless
|
9
|
-
|
10
|
-
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
11
|
-
|
12
|
-
return false unless sugary_type_declaration.key?(:type)
|
7
|
+
return false if sugary_type_declaration.strict?
|
8
|
+
return false unless sugary_type_declaration.hash?
|
9
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
13
10
|
|
14
11
|
type_symbol = sugary_type_declaration[:type]
|
15
12
|
|
16
|
-
type_symbol == :array &&
|
13
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :array &&
|
14
|
+
sugary_type_declaration.key?(:element_type_declaration)
|
17
15
|
end
|
18
16
|
|
19
17
|
def desugarize(sugary_type_declaration)
|
18
|
+
sugary_type_declaration.symbolize_keys!
|
19
|
+
|
20
20
|
sugar = sugary_type_declaration[:element_type_declaration]
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
strict = if sugar.is_a?(Types::Type)
|
23
|
+
sugar.reference_or_declaration_data
|
24
|
+
else
|
25
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
# TODO: probably not worth directly testing this path
|
29
|
+
# :nocov:
|
30
|
+
declaration.is_deep_duped = true
|
31
|
+
declaration.is_duped = true
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
|
35
|
+
handler = type_declaration_handler_for(declaration)
|
36
|
+
handler.desugarize(declaration).declaration_data
|
37
|
+
end
|
24
38
|
|
25
39
|
sugary_type_declaration[:element_type_declaration] = strict
|
26
40
|
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb
CHANGED
@@ -7,13 +7,9 @@ module Foobara
|
|
7
7
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
8
|
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
9
9
|
def transform(strict_type_declaration)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if element_type_declaration
|
14
|
-
type.element_type = type_for_declaration(element_type_declaration)
|
15
|
-
end
|
16
|
-
end
|
10
|
+
type = super
|
11
|
+
type.element_type = :Array
|
12
|
+
type
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -7,21 +7,32 @@ module Foobara
|
|
7
7
|
# TODO: make a quick way to convert a couple simple procs into a transformer
|
8
8
|
class TypeSetToArrayDesugarizer < ArrayDesugarizer
|
9
9
|
def applicable?(sugary_type_declaration)
|
10
|
-
if sugary_type_declaration.
|
11
|
-
extra_keys = sugary_type_declaration.keys -
|
10
|
+
if sugary_type_declaration.hash? && sugary_type_declaration.key?(:type)
|
11
|
+
extra_keys = sugary_type_declaration.declaration_data.keys -
|
12
|
+
[:type, :description, :sensitive, :sensitive_exposed]
|
12
13
|
|
13
14
|
return false if extra_keys.any?
|
14
15
|
|
15
16
|
type = sugary_type_declaration[:type]
|
16
17
|
|
17
18
|
if type.is_a?(::Array)
|
18
|
-
super(type)
|
19
|
+
super(TypeDeclaration.new(type))
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
def desugarize(sugary_type_declaration)
|
24
|
-
strict_type_declaration =
|
25
|
+
strict_type_declaration = TypeDeclaration.new(sugary_type_declaration[:type])
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
# TODO: probably not worth testing this path
|
29
|
+
# :nocov:
|
30
|
+
strict_type_declaration.is_deep_duped = true
|
31
|
+
strict_type_declaration.is_duped = true
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
|
35
|
+
strict_type_declaration = super(strict_type_declaration)
|
25
36
|
|
26
37
|
if sugary_type_declaration.key?(:description)
|
27
38
|
strict_type_declaration[:description] = sugary_type_declaration[:description]
|
@@ -4,9 +4,19 @@ module Foobara
|
|
4
4
|
# Hmmmm... this inheritance feels backwards
|
5
5
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
strictish_type_declaration =
|
7
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
8
|
+
sugary_type_declaration
|
9
|
+
else
|
10
|
+
desugarize(sugary_type_declaration.clone)
|
11
|
+
end
|
8
12
|
|
9
|
-
strictish_type_declaration.
|
13
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :array
|
14
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
15
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
16
|
+
end
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
|
+
class KeyTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
6
|
+
def applicable?(sugary_type_declaration)
|
7
|
+
return false if sugary_type_declaration.strict?
|
8
|
+
return false unless sugary_type_declaration.hash?
|
9
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
10
|
+
|
11
|
+
type_symbol = sugary_type_declaration[:type]
|
12
|
+
|
13
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :associative_array &&
|
14
|
+
sugary_type_declaration.key?(:key_type_declaration)
|
15
|
+
end
|
16
|
+
|
17
|
+
def desugarize(sugary_type_declaration)
|
18
|
+
sugary_type_declaration.symbolize_keys!
|
19
|
+
|
20
|
+
sugar = sugary_type_declaration[:key_type_declaration]
|
21
|
+
|
22
|
+
strict = if sugar.is_a?(Types::Type)
|
23
|
+
sugar.reference_or_declaration_data
|
24
|
+
else
|
25
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
declaration.is_deep_duped = true
|
29
|
+
declaration.is_duped = true
|
30
|
+
end
|
31
|
+
|
32
|
+
handler = type_declaration_handler_for(declaration)
|
33
|
+
handler.desugarize(declaration).declaration_data
|
34
|
+
end
|
35
|
+
|
36
|
+
sugary_type_declaration[:key_type_declaration] = strict
|
37
|
+
|
38
|
+
sugary_type_declaration
|
39
|
+
end
|
40
|
+
|
41
|
+
def priority
|
42
|
+
Priority::LOW
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -9,17 +9,9 @@ module Foobara
|
|
9
9
|
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
10
10
|
class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
|
11
11
|
def transform(strict_type_declaration)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if key_type_declaration || value_type_declaration
|
17
|
-
type.element_types = [
|
18
|
-
type_for_declaration(key_type_declaration || :duck),
|
19
|
-
type_for_declaration(value_type_declaration || :duck)
|
20
|
-
]
|
21
|
-
end
|
22
|
-
end
|
12
|
+
type = super
|
13
|
+
type.element_types = :Hash
|
14
|
+
type
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative "../extend_registered_type_declaration"
|
2
|
+
require_relative "../../desugarizer"
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module TypeDeclarations
|
6
|
+
module Handlers
|
7
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
8
|
+
class ValueTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
9
|
+
def applicable?(sugary_type_declaration)
|
10
|
+
return false if sugary_type_declaration.strict?
|
11
|
+
return false unless sugary_type_declaration.hash?
|
12
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
13
|
+
|
14
|
+
type_symbol = sugary_type_declaration[:type]
|
15
|
+
|
16
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :associative_array &&
|
17
|
+
sugary_type_declaration.key?(:value_type_declaration)
|
18
|
+
end
|
19
|
+
|
20
|
+
def desugarize(sugary_type_declaration)
|
21
|
+
sugary_type_declaration.symbolize_keys!
|
22
|
+
|
23
|
+
sugar = sugary_type_declaration[:value_type_declaration]
|
24
|
+
|
25
|
+
strict = if sugar.is_a?(Types::Type)
|
26
|
+
sugar.reference_or_declaration_data
|
27
|
+
else
|
28
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
29
|
+
|
30
|
+
if sugary_type_declaration.deep_duped?
|
31
|
+
declaration.is_deep_duped = true
|
32
|
+
declaration.is_duped = true
|
33
|
+
end
|
34
|
+
|
35
|
+
handler = type_declaration_handler_for(declaration)
|
36
|
+
handler.desugarize(declaration).declaration_data
|
37
|
+
end
|
38
|
+
|
39
|
+
sugary_type_declaration[:value_type_declaration] = strict
|
40
|
+
|
41
|
+
sugary_type_declaration
|
42
|
+
end
|
43
|
+
|
44
|
+
def priority
|
45
|
+
Priority::LOW
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -5,9 +5,19 @@ module Foobara
|
|
5
5
|
module Handlers
|
6
6
|
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
7
7
|
def applicable?(sugary_type_declaration)
|
8
|
-
strictish_type_declaration =
|
8
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
9
|
+
sugary_type_declaration
|
10
|
+
else
|
11
|
+
desugarize(sugary_type_declaration.clone)
|
12
|
+
end
|
9
13
|
|
10
|
-
strictish_type_declaration.
|
14
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :associative_array
|
15
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
16
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
17
|
+
end
|
18
|
+
|
19
|
+
true
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
# TODO: do we really need this? Isn't this the default?
|
data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb
CHANGED
@@ -6,7 +6,7 @@ module Foobara
|
|
6
6
|
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
7
7
|
class DslDesugarizer < TypeDeclarations::Desugarizer
|
8
8
|
def applicable?(sugary_type_declaration)
|
9
|
-
sugary_type_declaration.
|
9
|
+
sugary_type_declaration.proc?
|
10
10
|
end
|
11
11
|
|
12
12
|
def desugarize(block)
|
@@ -9,16 +9,26 @@ module Foobara
|
|
9
9
|
# TODO: make a quick way to convert a couple simple procs into a transformer
|
10
10
|
class ElementTypeDeclarationsDesugarizer < HashDesugarizer
|
11
11
|
def desugarize(sugary_type_declaration)
|
12
|
-
sugary_type_declaration = sugary_type_declaration.dup
|
13
|
-
|
14
12
|
sugary_type_declaration[:element_type_declarations] =
|
15
13
|
sugary_type_declaration[:element_type_declarations].to_h do |attribute_name, element_type_declaration|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
element_type_declaration = if element_type_declaration.is_a?(Types::Type)
|
15
|
+
element_type_declaration.reference_or_declaration_data
|
16
|
+
else
|
17
|
+
declaration = TypeDeclaration.new(element_type_declaration)
|
18
|
+
|
19
|
+
if sugary_type_declaration.deep_duped?
|
20
|
+
# TODO: probably not worth directly testing this path
|
21
|
+
# :nocov:
|
22
|
+
declaration.is_deep_duped = true
|
23
|
+
declaration.is_duped = true
|
24
|
+
# :nocov:
|
25
|
+
end
|
26
|
+
|
27
|
+
handler = type_declaration_handler_for(declaration)
|
28
|
+
handler.desugarize(declaration).declaration_data
|
29
|
+
end
|
20
30
|
|
21
|
-
[attribute_name, element_type_declaration]
|
31
|
+
[attribute_name.to_sym, element_type_declaration]
|
22
32
|
end
|
23
33
|
|
24
34
|
sugary_type_declaration
|
data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb
CHANGED
@@ -7,40 +7,36 @@ module Foobara
|
|
7
7
|
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
8
|
class HashDesugarizer < TypeDeclarations::Desugarizer
|
9
9
|
def applicable?(sugary_type_declaration)
|
10
|
-
return false
|
11
|
-
return false unless
|
12
|
-
|
13
|
-
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
14
|
-
|
15
|
-
return true unless sugary_type_declaration.key?(:type)
|
10
|
+
return false if sugary_type_declaration.strict?
|
11
|
+
return false unless sugary_type_declaration.hash?
|
16
12
|
|
17
13
|
type_symbol = sugary_type_declaration[:type]
|
18
14
|
|
19
|
-
|
15
|
+
unless type_symbol
|
16
|
+
return sugary_type_declaration.all_symbolizable_keys?
|
17
|
+
end
|
18
|
+
|
19
|
+
if type_symbol == :attributes
|
20
20
|
sugary_type_declaration.key?(:element_type_declarations) &&
|
21
21
|
Util.all_symbolizable_keys?(sugary_type_declaration[:element_type_declarations])
|
22
22
|
elsif type_symbol.is_a?(::Symbol)
|
23
|
-
#
|
23
|
+
# if the type isn't registered we will assume it's an attribute named type
|
24
24
|
!type_registered?(type_symbol)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def desugarize(sugary_type_declaration)
|
29
|
-
sugary_type_declaration
|
30
|
-
|
31
|
-
Util.symbolize_keys!(sugary_type_declaration)
|
29
|
+
sugary_type_declaration.symbolize_keys!
|
32
30
|
|
33
31
|
unless strictish_type_declaration?(sugary_type_declaration)
|
34
|
-
sugary_type_declaration = {
|
32
|
+
sugary_type_declaration.declaration_data = {
|
35
33
|
type: :attributes,
|
36
|
-
|
37
|
-
element_type_declarations: sugary_type_declaration
|
34
|
+
element_type_declarations: sugary_type_declaration.declaration_data
|
38
35
|
}
|
39
|
-
|
36
|
+
sugary_type_declaration.is_absolutified = true
|
37
|
+
sugary_type_declaration.is_duped = true
|
40
38
|
end
|
41
39
|
|
42
|
-
Util.symbolize_keys!(sugary_type_declaration[:element_type_declarations])
|
43
|
-
|
44
40
|
sugary_type_declaration
|
45
41
|
end
|
46
42
|
|
@@ -51,8 +47,9 @@ module Foobara
|
|
51
47
|
private
|
52
48
|
|
53
49
|
def strictish_type_declaration?(hash)
|
54
|
-
|
55
|
-
|
50
|
+
if hash.key?(:type) || hash.key?("type")
|
51
|
+
hash.key?(:element_type_declarations) || hash.key?("element_type_declarations")
|
52
|
+
end
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
@@ -7,12 +7,9 @@ module Foobara
|
|
7
7
|
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
8
|
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
9
9
|
def transform(strict_type_declaration)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
type_for_declaration(attribute_declaration)
|
14
|
-
end
|
15
|
-
end
|
10
|
+
type = super
|
11
|
+
type.element_types = :Attributes
|
12
|
+
type
|
16
13
|
end
|
17
14
|
end
|
18
15
|
end
|
@@ -3,8 +3,19 @@ module Foobara
|
|
3
3
|
module Handlers
|
4
4
|
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
5
5
|
def applicable?(sugary_type_declaration)
|
6
|
-
strictish_type_declaration =
|
7
|
-
|
6
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
7
|
+
sugary_type_declaration
|
8
|
+
else
|
9
|
+
desugarize(sugary_type_declaration.clone)
|
10
|
+
end
|
11
|
+
|
12
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :attributes
|
13
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
14
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
8
19
|
end
|
9
20
|
|
10
21
|
def priority
|
@@ -16,7 +16,7 @@ module Foobara
|
|
16
16
|
validators = []
|
17
17
|
element_processors = []
|
18
18
|
|
19
|
-
additional_processors_to_apply = strict_type_declaration.except(*non_processor_keys)
|
19
|
+
additional_processors_to_apply = strict_type_declaration.declaration_data.except(*non_processor_keys)
|
20
20
|
|
21
21
|
# TODO: validate the name
|
22
22
|
additional_processors_to_apply.each_pair do |processor_symbol, declaration_data|
|
@@ -49,7 +49,7 @@ module Foobara
|
|
49
49
|
sensitive_exposed = strict_type_declaration[:sensitive_exposed]
|
50
50
|
|
51
51
|
type_class.new(
|
52
|
-
strict_type_declaration,
|
52
|
+
strict_type_declaration.declaration_data,
|
53
53
|
base_type:,
|
54
54
|
description: strict_type_declaration[:description],
|
55
55
|
casters:,
|
@@ -74,7 +74,7 @@ module Foobara
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def non_processor_keys
|
77
|
-
[:type, :
|
77
|
+
[:type, :description, :sensitive, :sensitive_exposed]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -5,13 +5,25 @@ module Foobara
|
|
5
5
|
module Handlers
|
6
6
|
class ExtendRegisteredTypeDeclaration < RegisteredTypeDeclaration
|
7
7
|
def applicable?(sugary_type_declaration)
|
8
|
-
strict_type_declaration =
|
8
|
+
strict_type_declaration = if sugary_type_declaration.strict?
|
9
|
+
# :nocov:
|
10
|
+
sugary_type_declaration
|
11
|
+
# :nocov:
|
12
|
+
else
|
13
|
+
desugarize(sugary_type_declaration.clone)
|
14
|
+
end
|
9
15
|
|
10
|
-
return false unless strict_type_declaration.
|
16
|
+
return false unless strict_type_declaration.hash?
|
11
17
|
# if there's no processors to extend the existing type with, then we don't handle that here
|
12
|
-
return false if strict_type_declaration.keys == [:type]
|
18
|
+
return false if strict_type_declaration.declaration_data.keys == [:type]
|
13
19
|
|
14
|
-
super(strict_type_declaration.slice(:type))
|
20
|
+
applicable = super(strict_type_declaration.slice(:type))
|
21
|
+
|
22
|
+
if applicable && !sugary_type_declaration.equal?(strict_type_declaration)
|
23
|
+
sugary_type_declaration.assign(strict_type_declaration)
|
24
|
+
end
|
25
|
+
|
26
|
+
applicable
|
15
27
|
end
|
16
28
|
|
17
29
|
def priority
|