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
@@ -333,34 +333,22 @@ module Foobara
|
|
333
333
|
end
|
334
334
|
|
335
335
|
def foobara_manifest
|
336
|
-
to_include = TypeDeclarations.foobara_manifest_context_to_include
|
336
|
+
to_include = TypeDeclarations.foobara_manifest_context_to_include || Set.new
|
337
337
|
|
338
338
|
types = types_depended_on.select(&:registered?).map do |t|
|
339
|
-
|
340
|
-
to_include << t
|
341
|
-
end
|
339
|
+
to_include << t
|
342
340
|
t.foobara_manifest_reference
|
343
341
|
end.sort
|
344
342
|
|
345
343
|
inputs_transformers = TypeDeclarations.with_manifest_context(remove_sensitive: false) do
|
346
|
-
self.inputs_transformers
|
347
|
-
end
|
348
|
-
result_transformers = self.result_transformers.map(&:foobara_manifest)
|
349
|
-
errors_transformers = self.errors_transformers.map(&:foobara_manifest)
|
350
|
-
pre_commit_transformers = self.pre_commit_transformers.map(&:foobara_manifest)
|
351
|
-
serializers = self.serializers.map do |s|
|
352
|
-
if s.respond_to?(:foobara_manifest)
|
353
|
-
if to_include
|
354
|
-
to_include << s
|
355
|
-
end
|
356
|
-
s.foobara_manifest_reference
|
357
|
-
else
|
358
|
-
{ proc: s.to_s }
|
359
|
-
end
|
344
|
+
processors_to_manifest_symbols(self.inputs_transformers)
|
360
345
|
end
|
361
|
-
|
362
|
-
|
363
|
-
|
346
|
+
result_transformers = processors_to_manifest_symbols(self.result_transformers)
|
347
|
+
errors_transformers = processors_to_manifest_symbols(self.errors_transformers)
|
348
|
+
pre_commit_transformers = processors_to_manifest_symbols(self.pre_commit_transformers)
|
349
|
+
serializers = processors_to_manifest_symbols(self.serializers)
|
350
|
+
response_mutators = processors_to_manifest_symbols(self.response_mutators)
|
351
|
+
request_mutators = processors_to_manifest_symbols(self.request_mutators)
|
364
352
|
|
365
353
|
authenticator_details = if authenticator
|
366
354
|
{
|
@@ -404,28 +392,32 @@ module Foobara
|
|
404
392
|
)
|
405
393
|
end
|
406
394
|
|
407
|
-
def
|
408
|
-
return nil if
|
395
|
+
def processors_to_manifest_symbols(processors)
|
396
|
+
return nil if processors.nil? || processors.empty?
|
397
|
+
|
398
|
+
to_include = TypeDeclarations.foobara_manifest_context_to_include || Set.new
|
399
|
+
include_processors = TypeDeclarations.include_processors?
|
409
400
|
|
410
|
-
|
411
|
-
if
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
401
|
+
processors.map do |processor|
|
402
|
+
if processor.respond_to?(:scoped_path_set?) && processor.scoped_path_set?
|
403
|
+
if include_processors
|
404
|
+
to_include << processor
|
405
|
+
end
|
406
|
+
processor.foobara_manifest_reference
|
407
|
+
elsif processor.is_a?(Value::Processor)
|
408
|
+
klass = processor.class
|
416
409
|
|
417
410
|
if klass.scoped_path_set?
|
418
|
-
|
411
|
+
if include_processors
|
412
|
+
to_include << klass
|
413
|
+
end
|
419
414
|
klass.foobara_manifest_reference
|
420
415
|
# TODO: Delete this nocov block
|
421
416
|
# TODO: make anonymous scoped path's have better names instead of random hexadecimal
|
422
417
|
# :nocov:
|
423
|
-
elsif
|
424
|
-
|
418
|
+
elsif processor.respond_to?(:symbol) && processor.symbol
|
419
|
+
processor.symbol
|
425
420
|
else
|
426
|
-
|
427
|
-
to_include << klass if klass.scoped_path_set?
|
428
|
-
|
429
421
|
name = klass.name
|
430
422
|
|
431
423
|
while name.nil?
|
@@ -436,6 +428,12 @@ module Foobara
|
|
436
428
|
"Anonymous#{Util.non_full_name(name)}"
|
437
429
|
# :nocov:
|
438
430
|
end
|
431
|
+
elsif processor.is_a?(::Proc)
|
432
|
+
"Proc"
|
433
|
+
else
|
434
|
+
# :nocov:
|
435
|
+
"Unknown"
|
436
|
+
# :nocov:
|
439
437
|
end
|
440
438
|
end
|
441
439
|
end
|
@@ -502,7 +500,9 @@ module Foobara
|
|
502
500
|
end
|
503
501
|
|
504
502
|
def mutate_request(request)
|
505
|
-
request_mutator&.
|
503
|
+
if request_mutator&.applicable?(request)
|
504
|
+
request_mutator.process_value!(request)
|
505
|
+
end
|
506
506
|
end
|
507
507
|
|
508
508
|
def result_transformer
|
@@ -594,8 +594,10 @@ module Foobara
|
|
594
594
|
end
|
595
595
|
|
596
596
|
def transform_inputs
|
597
|
-
|
598
|
-
|
597
|
+
transformer = self.class.inputs_transformer
|
598
|
+
|
599
|
+
self.transformed_inputs = if transformer&.applicable?(untransformed_inputs)
|
600
|
+
outcome = transformer.process_value(untransformed_inputs)
|
599
601
|
|
600
602
|
if outcome.success?
|
601
603
|
outcome.result
|
@@ -625,17 +627,23 @@ module Foobara
|
|
625
627
|
end
|
626
628
|
|
627
629
|
def transform_result
|
628
|
-
|
629
|
-
|
630
|
+
transformer = self.class.result_transformer
|
631
|
+
|
632
|
+
if transformer&.applicable?(result)
|
633
|
+
self.outcome = Outcome.success(transformer.process_value!(result))
|
630
634
|
end
|
631
635
|
end
|
632
636
|
|
633
637
|
def mutate_response(response)
|
634
|
-
self.class.response_mutator
|
638
|
+
mutator = self.class.response_mutator
|
639
|
+
|
640
|
+
if mutator&.applicable?(response)
|
641
|
+
mutator.process_value!(response)
|
642
|
+
end
|
635
643
|
end
|
636
644
|
|
637
645
|
def transform_errors
|
638
|
-
if errors_transformer
|
646
|
+
if errors_transformer&.applicable?(errors)
|
639
647
|
self.outcome = Outcome.errors(errors_transformer.process_value!(errors))
|
640
648
|
end
|
641
649
|
end
|
@@ -708,7 +716,9 @@ module Foobara
|
|
708
716
|
source = if allowed_rule.block.respond_to?("source") && defined?(MethodSource)
|
709
717
|
begin
|
710
718
|
# This only works when pry is loaded
|
719
|
+
# :nocov:
|
711
720
|
allowed_rule.block.source
|
721
|
+
# :nocov:
|
712
722
|
rescue MethodSource::SourceNotFoundError
|
713
723
|
# This path is hit if the way the source code is extracted
|
714
724
|
# doesn't result in valid Ruby, for example, as part of a hash such as:
|
@@ -733,7 +743,9 @@ module Foobara
|
|
733
743
|
def apply_pre_commit_transformers
|
734
744
|
if pre_commit_transformer
|
735
745
|
command.before_commit_transaction do |**|
|
736
|
-
pre_commit_transformer.
|
746
|
+
if pre_commit_transformer.applicable?(self)
|
747
|
+
pre_commit_transformer.process_value!(self)
|
748
|
+
end
|
737
749
|
end
|
738
750
|
end
|
739
751
|
end
|
data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb
CHANGED
@@ -48,6 +48,10 @@ module Foobara
|
|
48
48
|
elsif to_type.extends?(Foobara::BuiltinTypes[:detached_entity])
|
49
49
|
declaration = to_type.target_class.primary_key_type.reference_or_declaration_data
|
50
50
|
|
51
|
+
if declaration.is_a?(::Symbol)
|
52
|
+
declaration = { type: declaration }
|
53
|
+
end
|
54
|
+
|
51
55
|
description = "#{to_type.target_class.model_name} #{to_type.target_class.primary_key_attribute}"
|
52
56
|
|
53
57
|
unless to_type.extends_directly?(Foobara::BuiltinTypes[:detached_entity]) ||
|
@@ -48,39 +48,45 @@ module Foobara
|
|
48
48
|
# TODO: technically does not belong in this project but maybe it should
|
49
49
|
def foobara_manifest
|
50
50
|
to_include = TypeDeclarations.foobara_manifest_context_to_include
|
51
|
+
include_processors = TypeDeclarations.include_processors?
|
51
52
|
|
52
53
|
if to_include
|
53
54
|
to_include << error_class
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
h = key.to_h.merge(
|
58
|
+
key: key.to_s,
|
59
|
+
error: error_class.foobara_manifest_reference,
|
60
|
+
manually_added:
|
61
|
+
)
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
if include_processors
|
64
|
+
if processor
|
65
|
+
processor_class = processor.class
|
66
|
+
if to_include
|
67
|
+
to_include << processor_class
|
68
|
+
end
|
69
|
+
|
70
|
+
if processor.scoped_path_set?
|
71
|
+
# Unclear why nothing in the test suite passes through here.
|
72
|
+
# TODO: either test this or delete it.
|
73
|
+
# :nocov:
|
74
|
+
to_include << processor
|
75
|
+
processor_reference = processor.foobara_manifest_reference
|
76
|
+
# :nocov:
|
77
|
+
end
|
69
78
|
end
|
70
|
-
end
|
71
79
|
|
72
|
-
|
80
|
+
processor_manifest_data = data unless processor_reference
|
73
81
|
|
74
|
-
|
75
|
-
key.to_h.merge(
|
76
|
-
key: key.to_s,
|
77
|
-
error: error_class.foobara_manifest_reference,
|
82
|
+
h.merge!(
|
78
83
|
processor: processor_reference,
|
79
84
|
processor_class: processor_class&.foobara_manifest_reference,
|
80
|
-
processor_manifest_data
|
81
|
-
manually_added:
|
85
|
+
processor_manifest_data:
|
82
86
|
)
|
83
|
-
|
87
|
+
end
|
88
|
+
|
89
|
+
Util.remove_blank(h)
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
@@ -20,7 +20,13 @@ module Foobara
|
|
20
20
|
def type_declaration(...)
|
21
21
|
raise "No primary key set yet" unless primary_key_attribute
|
22
22
|
|
23
|
-
|
23
|
+
declaration = super
|
24
|
+
|
25
|
+
declaration[:type] = :detached_entity
|
26
|
+
declaration[:primary_key] = primary_key_attribute
|
27
|
+
declaration.is_absolutified = true
|
28
|
+
|
29
|
+
declaration
|
24
30
|
end
|
25
31
|
|
26
32
|
def set_model_type
|
@@ -25,11 +25,21 @@ module Foobara
|
|
25
25
|
declaration_data = manifest[:declaration_data]
|
26
26
|
|
27
27
|
if self.class.type_requires_conversion?(declaration_data[:type])
|
28
|
+
# TODO: No longer is hit in this test suite but ActiveRecordType needs this class
|
29
|
+
# and potentially this snippet of code in order to do the right thing.
|
30
|
+
# TODO: test that out and delete this method if possible.
|
31
|
+
# :nocov:
|
28
32
|
declaration_data = declaration_data.merge(type: :detached_entity)
|
33
|
+
# :nocov:
|
29
34
|
end
|
30
35
|
|
31
36
|
if self.class.model_base_class_requires_conversion?(declaration_data[:model_base_class])
|
37
|
+
# TODO: No longer is hit in this test suite but ActiveRecordType needs this class
|
38
|
+
# and potentially this snippet of code in order to do the right thing.
|
39
|
+
# TODO: test that out and delete this method if possible.
|
40
|
+
# :nocov:
|
32
41
|
declaration_data = declaration_data.merge(model_base_class: "Foobara::DetachedEntity")
|
42
|
+
# :nocov:
|
33
43
|
end
|
34
44
|
|
35
45
|
# TODO: remove private attributes, add delegated attributes
|
@@ -5,7 +5,7 @@ module Foobara
|
|
5
5
|
class ModelInstanceIsValid < Model::Validators::ModelInstanceIsValid
|
6
6
|
# Why is this here in entity/ instead of in model/?
|
7
7
|
def possible_errors
|
8
|
-
return [] if parent_declaration_data ==
|
8
|
+
return [] if parent_declaration_data == expected_type_symbol
|
9
9
|
|
10
10
|
# TODO: we should also ask the class if it is mutable...
|
11
11
|
mutable = parent_declaration_data.key?(:mutable) ? parent_declaration_data[:mutable] : false
|
@@ -4,10 +4,8 @@ module Foobara
|
|
4
4
|
class ExtendDetachedEntityTypeDeclaration < ExtendModelTypeDeclaration
|
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)
|
7
|
+
return false unless sugary_type_declaration.hash?
|
8
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
11
9
|
|
12
10
|
type_symbol = sugary_type_declaration[:type] || sugary_type_declaration["type"]
|
13
11
|
return false unless type_symbol
|
@@ -16,10 +14,9 @@ module Foobara
|
|
16
14
|
|
17
15
|
return true if type_symbol == expected_type_symbol
|
18
16
|
|
19
|
-
if type_symbol.is_a?(::Symbol)
|
20
|
-
type =
|
21
|
-
|
22
|
-
)
|
17
|
+
if type_symbol.is_a?(::Symbol)
|
18
|
+
type = sugary_type_declaration.type ||
|
19
|
+
lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
|
23
20
|
|
24
21
|
type&.extends?(BuiltinTypes[expected_type_symbol])
|
25
22
|
end
|
@@ -30,7 +27,7 @@ module Foobara
|
|
30
27
|
end
|
31
28
|
|
32
29
|
def desugarize(sugary_type_declaration)
|
33
|
-
|
30
|
+
sugary_type_declaration.symbolize_keys!
|
34
31
|
end
|
35
32
|
|
36
33
|
def priority
|
@@ -10,7 +10,8 @@ module Foobara
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def desugarize(sugary_type_declaration)
|
13
|
-
sugary_type_declaration
|
13
|
+
sugary_type_declaration[:primary_key] = sugary_type_declaration[:primary_key].to_sym
|
14
|
+
sugary_type_declaration
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -316,7 +316,10 @@ module Foobara
|
|
316
316
|
# TODO: introduce a Namespace#scope method to simplify this a bit
|
317
317
|
Foobara::Namespace.use self do
|
318
318
|
if block
|
319
|
-
args = [
|
319
|
+
args = [
|
320
|
+
TypeDeclarations::Dsl::Attributes.to_declaration(&block).declaration_data,
|
321
|
+
*args
|
322
|
+
]
|
320
323
|
end
|
321
324
|
|
322
325
|
attributes_type_declaration, *args = args
|
@@ -358,7 +361,7 @@ module Foobara
|
|
358
361
|
scoped_full_name
|
359
362
|
end
|
360
363
|
|
361
|
-
|
364
|
+
declaration = TypeDeclaration.new(
|
362
365
|
Util.remove_blank(
|
363
366
|
type: :entity,
|
364
367
|
name:,
|
@@ -366,11 +369,15 @@ module Foobara
|
|
366
369
|
model_module:,
|
367
370
|
attributes_declaration: attributes_type_declaration,
|
368
371
|
primary_key:,
|
369
|
-
description
|
370
|
-
_desugarized: { type_absolutified: true }
|
372
|
+
description:
|
371
373
|
)
|
372
374
|
)
|
373
375
|
|
376
|
+
declaration.is_absolutified = true
|
377
|
+
declaration.is_duped = true
|
378
|
+
|
379
|
+
entity_type = foobara_type_builder.type_for_declaration(declaration)
|
380
|
+
|
374
381
|
entity_type.target_class
|
375
382
|
end
|
376
383
|
end
|
@@ -428,6 +435,7 @@ module Foobara
|
|
428
435
|
foobara_depends_on_namespaces << domain
|
429
436
|
foobara_type_builder.accesses << domain.foobara_type_builder
|
430
437
|
|
438
|
+
lru_cache.reset!
|
431
439
|
foobara_depends_on << domain_name
|
432
440
|
end
|
433
441
|
end
|
@@ -38,7 +38,8 @@ module Foobara
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def foobara_manifest
|
41
|
-
to_include = TypeDeclarations.foobara_manifest_context_to_include
|
41
|
+
to_include = TypeDeclarations.foobara_manifest_context_to_include || Set.new
|
42
|
+
include_processors = TypeDeclarations.include_processors?
|
42
43
|
|
43
44
|
h = {
|
44
45
|
scoped_path:,
|
@@ -53,17 +54,28 @@ module Foobara
|
|
53
54
|
organization: foobara_organization&.foobara_manifest_reference
|
54
55
|
}
|
55
56
|
|
56
|
-
|
57
|
+
candidate = scoped_namespace
|
58
|
+
parent = nil
|
57
59
|
|
58
|
-
|
59
|
-
parent_category = Namespace.global.foobara_category_symbol_for(
|
60
|
+
while candidate
|
61
|
+
parent_category = Namespace.global.foobara_category_symbol_for(candidate)
|
62
|
+
break unless parent_category
|
60
63
|
|
61
64
|
if parent_category
|
62
|
-
if
|
63
|
-
|
65
|
+
if include_processors || (parent_category != :processor && parent_category != :processor_class)
|
66
|
+
if candidate != Foobara::Value
|
67
|
+
parent = candidate
|
68
|
+
break
|
69
|
+
end
|
64
70
|
end
|
65
|
-
h[:parent] = [parent_category, parent.foobara_manifest_reference]
|
66
71
|
end
|
72
|
+
|
73
|
+
candidate = candidate.scoped_namespace
|
74
|
+
end
|
75
|
+
|
76
|
+
if parent
|
77
|
+
to_include << parent
|
78
|
+
h[:parent] = [parent_category, parent.foobara_manifest_reference]
|
67
79
|
end
|
68
80
|
|
69
81
|
h
|
@@ -34,13 +34,13 @@ module Foobara
|
|
34
34
|
"model",
|
35
35
|
"detached_entity",
|
36
36
|
"entity",
|
37
|
-
"
|
37
|
+
"persistence",
|
38
38
|
"nested_transactionable",
|
39
|
-
"
|
40
|
-
"domain_mapper",
|
41
|
-
"persistence", # Feels like this would be loaded before command?
|
39
|
+
"model_attribute_helpers",
|
42
40
|
"in_memory_crud_driver_minimal",
|
43
41
|
"in_memory_crud_driver",
|
42
|
+
"command",
|
43
|
+
"domain_mapper",
|
44
44
|
"manifest"
|
45
45
|
|
46
46
|
install!
|
@@ -70,13 +70,22 @@ module Foobara
|
|
70
70
|
scoped_full_name
|
71
71
|
end
|
72
72
|
|
73
|
+
# TODO: replace this with primitive?
|
73
74
|
def builtin?
|
74
75
|
BuiltinTypes.builtin_reference?(reference)
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
+
def primitive?
|
79
|
+
declaration_data.is_a?(::String) || declaration_data.is_a?(::Symbol)
|
80
|
+
end
|
81
|
+
|
82
|
+
# This name is confusing.
|
83
|
+
# This represents a type that is 1) registered 2) not primitive 3) does not inherit from :model
|
84
|
+
# Because this is a Manifest::Type it is registered by definition. Non-registered types are
|
85
|
+
# represented in the manifest only as type declarations scattered the other categories where
|
86
|
+
# needed.
|
78
87
|
def custom?
|
79
|
-
!
|
88
|
+
!primitive? && !extends_symbol?(:model)
|
80
89
|
end
|
81
90
|
|
82
91
|
def extends_symbol?(symbol)
|
@@ -90,6 +90,12 @@ module Foobara
|
|
90
90
|
@custom = to_type.custom?
|
91
91
|
end
|
92
92
|
|
93
|
+
def primitive?
|
94
|
+
if reference?
|
95
|
+
to_type.primitive?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
93
99
|
def to_model
|
94
100
|
raise "not an model" unless model?
|
95
101
|
|
@@ -108,7 +114,12 @@ module Foobara
|
|
108
114
|
|
109
115
|
def to_detached_entity
|
110
116
|
raise "not an detached_entity" unless detached_entity?
|
111
|
-
|
117
|
+
|
118
|
+
if to_type.primitive?
|
119
|
+
# :nocov:
|
120
|
+
raise "detached_entity extension instead of an detached_entity"
|
121
|
+
# :nocov:
|
122
|
+
end
|
112
123
|
|
113
124
|
type = to_type
|
114
125
|
|
@@ -125,7 +136,12 @@ module Foobara
|
|
125
136
|
|
126
137
|
def to_entity
|
127
138
|
raise "not an entity" unless entity?
|
128
|
-
|
139
|
+
|
140
|
+
if to_type.primitive?
|
141
|
+
# :nocov:
|
142
|
+
raise "entity extension instead of an entity"
|
143
|
+
# :nocov:
|
144
|
+
end
|
129
145
|
|
130
146
|
type = to_type
|
131
147
|
|
@@ -138,6 +154,34 @@ module Foobara
|
|
138
154
|
# awkward??
|
139
155
|
@to_type ||= find_type(self)
|
140
156
|
end
|
157
|
+
|
158
|
+
def type
|
159
|
+
if reference?
|
160
|
+
relevant_manifest
|
161
|
+
else
|
162
|
+
super
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def sensitive
|
167
|
+
if reference?
|
168
|
+
false
|
169
|
+
else
|
170
|
+
super
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def sensitive_exposed
|
175
|
+
if reference?
|
176
|
+
false
|
177
|
+
else
|
178
|
+
super
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def reference?
|
183
|
+
relevant_manifest.is_a?(::Symbol) || relevant_manifest.is_a?(::String)
|
184
|
+
end
|
141
185
|
end
|
142
186
|
end
|
143
187
|
end
|
@@ -23,8 +23,8 @@ module Foobara
|
|
23
23
|
model_name: foobara_model_name,
|
24
24
|
model_base_class: foobara_type.declaration_data[:model_base_class],
|
25
25
|
model_class: foobara_type.declaration_data[:model_class],
|
26
|
-
delegates
|
27
|
-
private:
|
26
|
+
delegates: foobara_delegates,
|
27
|
+
private: foobara_private_attribute_names
|
28
28
|
)
|
29
29
|
end
|
30
30
|
end
|