foobara 0.0.141 → 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 +23 -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/common/src/error_collection.rb +1 -1
- 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 +93 -49
- 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 +24 -21
- 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 -63
- 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
@@ -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
|
data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb
CHANGED
@@ -8,20 +8,34 @@ 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
|
12
12
|
end
|
13
13
|
|
14
14
|
def desugarize(sugary_type_declaration)
|
15
|
-
element_type_declarations = sugary_type_declaration.map do |element_type_declaration|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
element_type_declarations = sugary_type_declaration.declaration_data.map do |element_type_declaration|
|
16
|
+
if element_type_declaration.is_a?(Types::Type)
|
17
|
+
element_type_declaration.reference_or_declaration_data
|
18
|
+
else
|
19
|
+
declaration = TypeDeclaration.new(element_type_declaration)
|
20
|
+
if sugary_type_declaration.deep_duped?
|
21
|
+
# TODO: probably not worth directly testing this path
|
22
|
+
# :nocov:
|
23
|
+
declaration.is_deep_duped = true
|
24
|
+
declaration.is_duped = true
|
25
|
+
# :nocov:
|
26
|
+
end
|
27
|
+
handler = type_declaration_handler_for(declaration)
|
28
|
+
handler.desugarize(declaration).declaration_data
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
|
-
{
|
32
|
+
sugary_type_declaration.declaration_data = {
|
22
33
|
type: :tuple,
|
23
34
|
element_type_declarations:
|
24
35
|
}
|
36
|
+
sugary_type_declaration.is_strict = true
|
37
|
+
|
38
|
+
sugary_type_declaration
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb
CHANGED
@@ -7,15 +7,9 @@ module Foobara
|
|
7
7
|
class ExtendTupleTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
8
|
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
9
9
|
def transform(strict_type_declaration)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if element_type_declarations && !element_type_declarations.empty?
|
14
|
-
type.element_types = element_type_declarations.map do |element_type_declaration|
|
15
|
-
type_for_declaration(element_type_declaration)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
10
|
+
type = super
|
11
|
+
type.element_types = :Tuple
|
12
|
+
type
|
19
13
|
end
|
20
14
|
end
|
21
15
|
end
|
@@ -3,9 +3,19 @@ module Foobara
|
|
3
3
|
module Handlers
|
4
4
|
class ExtendTupleTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
5
5
|
def applicable?(sugary_type_declaration)
|
6
|
-
strictish_type_declaration =
|
6
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
7
|
+
sugary_type_declaration
|
8
|
+
else
|
9
|
+
desugarize(sugary_type_declaration.clone)
|
10
|
+
end
|
7
11
|
|
8
|
-
strictish_type_declaration.
|
12
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :tuple
|
13
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
14
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
15
|
+
end
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb
CHANGED
@@ -10,16 +10,14 @@ module Foobara
|
|
10
10
|
registered_type(strict_type_declaration)
|
11
11
|
end
|
12
12
|
|
13
|
-
def type_symbol(strict_type_declaration)
|
14
|
-
strict_type_declaration[:type]
|
15
|
-
end
|
16
|
-
|
17
13
|
def registered_type(strict_type_declaration)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
lookup_type!(
|
14
|
+
type = strict_type_declaration.type || strict_type_declaration.base_type
|
15
|
+
|
16
|
+
return type if type
|
17
|
+
|
18
|
+
type = lookup_type!(strict_type_declaration[:type], mode: Namespace::LookupMode::ABSOLUTE)
|
19
|
+
|
20
|
+
strict_type_declaration.base_type = type
|
23
21
|
end
|
24
22
|
|
25
23
|
def target_classes(strict_type_declaration)
|
@@ -6,16 +6,31 @@ module Foobara
|
|
6
6
|
# TODO: we should just use the symbol instead of {type: symbol} to save space and simplify some stuff...
|
7
7
|
class RegisteredTypeDeclaration < TypeDeclarationHandler
|
8
8
|
def applicable?(sugary_type_declaration)
|
9
|
-
|
9
|
+
return true if sugary_type_declaration.type
|
10
10
|
|
11
|
-
|
11
|
+
unless sugary_type_declaration.reference_checked?
|
12
|
+
sugary_type_declaration.handle_symbolic_declaration
|
13
|
+
return true if sugary_type_declaration.type
|
14
|
+
end
|
15
|
+
|
16
|
+
strict_type_declaration = if sugary_type_declaration.strict?
|
17
|
+
sugary_type_declaration
|
18
|
+
else
|
19
|
+
desugarize(sugary_type_declaration.clone)
|
20
|
+
end
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
22
|
+
if strict_type_declaration.reference?
|
23
|
+
unless strict_type_declaration.type
|
24
|
+
# :nocov:
|
25
|
+
strict_type_declaration.handle_symbolic_declaration
|
26
|
+
# :nocov:
|
18
27
|
end
|
28
|
+
|
29
|
+
unless sugary_type_declaration.equal?(strict_type_declaration)
|
30
|
+
sugary_type_declaration.assign(strict_type_declaration)
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
19
34
|
end
|
20
35
|
end
|
21
36
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module LazyElementTypes
|
4
|
+
module Array
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def resolve(type)
|
8
|
+
element_type_declaration = type.declaration_data[:element_type_declaration]
|
9
|
+
|
10
|
+
type.element_type = if element_type_declaration
|
11
|
+
TypeDeclarations.strict do
|
12
|
+
Domain.current.foobara_type_from_declaration(element_type_declaration)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module LazyElementTypes
|
4
|
+
module Attributes
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def resolve(type)
|
8
|
+
type_declarations = type.declaration_data[:element_type_declarations]
|
9
|
+
|
10
|
+
type.element_types = if type_declarations
|
11
|
+
if type_declarations.empty?
|
12
|
+
{}
|
13
|
+
else
|
14
|
+
TypeDeclarations.strict do
|
15
|
+
domain = Domain.current
|
16
|
+
|
17
|
+
type_declarations.transform_values do |attribute_declaration|
|
18
|
+
domain.foobara_type_from_declaration(attribute_declaration)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module LazyElementTypes
|
4
|
+
# Using Hash instead of AssociativeArray to avoid making a symbol for it
|
5
|
+
# (probably doesn't really matter)
|
6
|
+
module Hash
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def resolve(type)
|
10
|
+
declaration_data = type.declaration_data
|
11
|
+
|
12
|
+
key_type_declaration = declaration_data[:key_type_declaration]
|
13
|
+
value_type_declaration = declaration_data[:value_type_declaration]
|
14
|
+
|
15
|
+
type.element_types = if key_type_declaration || value_type_declaration
|
16
|
+
TypeDeclarations.strict do
|
17
|
+
domain = Domain.current
|
18
|
+
|
19
|
+
key_declaration = if key_type_declaration
|
20
|
+
domain.foobara_type_from_declaration(key_type_declaration)
|
21
|
+
else
|
22
|
+
BuiltinTypes[:duck]
|
23
|
+
end
|
24
|
+
|
25
|
+
value_declaration = if value_type_declaration
|
26
|
+
domain.foobara_type_from_declaration(value_type_declaration)
|
27
|
+
else
|
28
|
+
BuiltinTypes[:duck]
|
29
|
+
end
|
30
|
+
|
31
|
+
[key_declaration, value_declaration]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module LazyElementTypes
|
4
|
+
module Tuple
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def resolve(type)
|
8
|
+
element_type_declarations = type.declaration_data[:element_type_declarations]
|
9
|
+
|
10
|
+
type.element_types = if element_type_declarations
|
11
|
+
TypeDeclarations.strict do
|
12
|
+
domain = Domain.current
|
13
|
+
|
14
|
+
element_type_declarations.map do |element_type_declaration|
|
15
|
+
domain.foobara_type_from_declaration(element_type_declaration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,7 +2,12 @@ module Foobara
|
|
2
2
|
module TypeDeclarations
|
3
3
|
class SensitiveTypeRemover < Value::Transformer
|
4
4
|
def applicable?(strict_type_declaration)
|
5
|
-
|
5
|
+
declaration = TypeDeclaration.new(strict_type_declaration)
|
6
|
+
|
7
|
+
declaration.is_strict = true
|
8
|
+
declaration.is_absolutified = true
|
9
|
+
|
10
|
+
handler.applicable?(declaration)
|
6
11
|
end
|
7
12
|
|
8
13
|
def handler
|
@@ -16,6 +16,8 @@ module Foobara
|
|
16
16
|
to_remove = []
|
17
17
|
|
18
18
|
strict_type_declaration[:element_type_declarations].each_pair do |attribute_name, attribute_declaration|
|
19
|
+
next if attribute_declaration.is_a?(::Symbol)
|
20
|
+
|
19
21
|
if attribute_declaration[:sensitive]
|
20
22
|
to_remove << attribute_name
|
21
23
|
else
|
@@ -7,9 +7,13 @@ module Foobara
|
|
7
7
|
def args_to_type_declaration(*args, &block)
|
8
8
|
if block
|
9
9
|
if args.empty? || args == [:attributes]
|
10
|
-
block
|
10
|
+
TypeDeclaration.new(block)
|
11
11
|
elsif args == [:array]
|
12
|
-
|
12
|
+
type_declaration = TypeDeclaration.new(type: :array, element_type_declaration: block)
|
13
|
+
type_declaration.is_absolutified = true
|
14
|
+
type_declaration.is_duped = true
|
15
|
+
type_declaration.is_deep_duped = true
|
16
|
+
type_declaration
|
13
17
|
else
|
14
18
|
# :nocov:
|
15
19
|
raise ArgumentError, "Cannot provide both block and declaration of #{args}"
|
@@ -22,23 +26,39 @@ module Foobara
|
|
22
26
|
raise ArgumentError, "expected 1 argument or a block but got 0 arguments and no block"
|
23
27
|
# :nocov:
|
24
28
|
when 1
|
25
|
-
args.first
|
29
|
+
arg = args.first
|
30
|
+
|
31
|
+
if arg.is_a?(TypeDeclaration)
|
32
|
+
arg
|
33
|
+
else
|
34
|
+
TypeDeclaration.new(arg)
|
35
|
+
end
|
26
36
|
else
|
27
37
|
type, *symbolic_processors, processor_data = args
|
28
38
|
|
29
|
-
if !symbolic_processors.empty?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
type_declaration = if !symbolic_processors.empty?
|
40
|
+
symbolic_processors = symbolic_processors.to_h { |symbol| [symbol, true] }
|
41
|
+
|
42
|
+
if processor_data.is_a?(::Hash) && !processor_data.empty?
|
43
|
+
h = processor_data.merge(symbolic_processors)
|
44
|
+
h[:type] = type
|
45
|
+
TypeDeclaration.new(h)
|
46
|
+
else
|
47
|
+
type_declaration = TypeDeclaration.new(symbolic_processors.merge(type:))
|
48
|
+
type_declaration.is_deep_duped = true
|
49
|
+
type_declaration
|
50
|
+
end
|
51
|
+
elsif processor_data.is_a?(::Hash)
|
52
|
+
TypeDeclaration.new(processor_data.merge(type:))
|
53
|
+
else
|
54
|
+
h = { type:, processor_data.to_sym => true }
|
55
|
+
type_declaration = TypeDeclaration.new(h)
|
56
|
+
type_declaration.is_deep_duped = true
|
57
|
+
type_declaration
|
58
|
+
end
|
59
|
+
|
60
|
+
type_declaration.is_duped = true
|
61
|
+
type_declaration
|
42
62
|
end
|
43
63
|
end
|
44
64
|
end
|
@@ -81,7 +101,7 @@ module Foobara
|
|
81
101
|
end
|
82
102
|
|
83
103
|
raise NoTypeDeclarationHandlerFoundError,
|
84
|
-
"No type declaration handler found for #{type_declaration}"
|
104
|
+
"No type declaration handler found for #{type_declaration.declaration_data}"
|
85
105
|
end
|
86
106
|
|
87
107
|
def handlers
|
@@ -94,15 +114,17 @@ module Foobara
|
|
94
114
|
|
95
115
|
def type_for_strict_stringified_declaration(type_declaration)
|
96
116
|
TypeDeclarations.strict_stringified do
|
97
|
-
|
98
|
-
handler
|
117
|
+
declaration = TypeDeclaration.new(type_declaration)
|
118
|
+
handler = type_declaration_handler_for(declaration)
|
119
|
+
handler.process_value!(declaration)
|
99
120
|
end
|
100
121
|
end
|
101
122
|
|
102
123
|
def type_for_strict_declaration(type_declaration)
|
103
124
|
TypeDeclarations.strict do
|
104
|
-
|
105
|
-
handler
|
125
|
+
declaration = TypeDeclaration.new(type_declaration)
|
126
|
+
handler = type_declaration_handler_for(declaration)
|
127
|
+
handler.process_value!(declaration)
|
106
128
|
end
|
107
129
|
end
|
108
130
|
|
@@ -123,6 +145,9 @@ module Foobara
|
|
123
145
|
def type_for_declaration_without_cache(*type_declaration_bits, &)
|
124
146
|
type_declaration = TypeDeclarations.args_to_type_declaration(*type_declaration_bits, &)
|
125
147
|
|
148
|
+
type = type_declaration.type
|
149
|
+
return type if type
|
150
|
+
|
126
151
|
handler = type_declaration_handler_for(type_declaration)
|
127
152
|
handler.process_value!(type_declaration)
|
128
153
|
end
|