foobara 0.2.6 → 0.3.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +20 -7
  4. data/projects/builtin_types/lib/foobara/builtin_types.rb +1 -0
  5. data/projects/builtin_types/src/attributes/supported_processors/element_type_declarations.rb +1 -3
  6. data/projects/builtin_types/src/builtin_types.rb +6 -4
  7. data/projects/builtin_types/src/email/transformers/downcase.rb +0 -2
  8. data/projects/callback/src/block/concerns/keyword_argumentable_block.rb +2 -0
  9. data/projects/command/src/command_pattern_implementation/concerns/namespace.rb +0 -2
  10. data/projects/command/src/command_pattern_implementation/concerns/reflection.rb +0 -2
  11. data/projects/command_connectors/src/command_connector/concerns/reflection.rb +187 -0
  12. data/projects/command_connectors/src/command_connector.rb +89 -255
  13. data/projects/command_connectors/src/command_registry/exposed_command.rb +6 -4
  14. data/projects/command_connectors/src/command_registry.rb +50 -48
  15. data/projects/command_connectors/src/serializers/atomic_serializer.rb +4 -1
  16. data/projects/command_connectors/src/transformed_command.rb +104 -100
  17. data/projects/command_connectors/src/transformers/load_atoms_transformer.rb +2 -0
  18. data/projects/command_connectors/src/transformers/load_delegated_attributes_entities_pre_commit_transformer.rb +2 -0
  19. data/projects/detached_entity/lib/foobara/detached_entity.rb +2 -0
  20. data/projects/detached_entity/src/remove_sensitive_values_transformer_extensions.rb +64 -0
  21. data/projects/domain/src/domain_module_extension.rb +0 -21
  22. data/projects/model/src/concerns/types.rb +1 -0
  23. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +1 -1
  24. data/projects/model_attribute_helpers/src/attribute_helpers.rb +4 -4
  25. data/projects/namespace/src/is_namespace.rb +1 -1
  26. data/projects/namespace/src/namespace/lookup_mode.rb +6 -0
  27. data/projects/nested_transactionable/lib/foobara/nested_transactionable.rb +0 -2
  28. data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +0 -2
  29. data/projects/persistence/src/entity_base.rb +1 -0
  30. data/projects/type_declarations/lib/foobara/type_declarations.rb +3 -1
  31. data/projects/type_declarations/src/remove_sensitive_values_transformer.rb +0 -59
  32. data/version.rb +1 -1
  33. metadata +3 -1
@@ -425,52 +425,6 @@ module Foobara
425
425
  manifest
426
426
  end
427
427
 
428
- def processors_to_manifest_symbols(processors)
429
- return nil if processors.nil? || processors.empty?
430
-
431
- to_include = TypeDeclarations.foobara_manifest_context_to_include || Set.new
432
- include_processors = TypeDeclarations.include_processors?
433
-
434
- processors.map do |processor|
435
- if processor.respond_to?(:scoped_path_set?) && processor.scoped_path_set?
436
- if include_processors
437
- to_include << processor
438
- end
439
- processor.foobara_manifest_reference
440
- elsif processor.is_a?(Value::Processor)
441
- klass = processor.class
442
-
443
- if klass.scoped_path_set?
444
- if include_processors
445
- to_include << klass
446
- end
447
- klass.foobara_manifest_reference
448
- # TODO: Delete this nocov block
449
- # TODO: make anonymous scoped path's have better names instead of random hexadecimal
450
- # :nocov:
451
- elsif processor.respond_to?(:symbol) && processor.symbol
452
- processor.symbol
453
- else
454
- name = klass.name
455
-
456
- while name.nil?
457
- klass = klass.superclass
458
- name = klass.name
459
- end
460
-
461
- "Anonymous#{Util.non_full_name(name)}"
462
- # :nocov:
463
- end
464
- elsif processor.is_a?(::Proc)
465
- "Proc"
466
- else
467
- # :nocov:
468
- "Unknown"
469
- # :nocov:
470
- end
471
- end
472
- end
473
-
474
428
  def inputs_transformer
475
429
  return @inputs_transformer if defined?(@inputs_transformer)
476
430
 
@@ -581,6 +535,54 @@ module Foobara
581
535
  end
582
536
  end
583
537
  end
538
+
539
+ private
540
+
541
+ def processors_to_manifest_symbols(processors)
542
+ return nil if processors.nil? || processors.empty?
543
+
544
+ to_include = TypeDeclarations.foobara_manifest_context_to_include || Set.new
545
+ include_processors = TypeDeclarations.include_processors?
546
+
547
+ processors.map do |processor|
548
+ if processor.respond_to?(:scoped_path_set?) && processor.scoped_path_set?
549
+ if include_processors
550
+ to_include << processor
551
+ end
552
+ processor.foobara_manifest_reference
553
+ elsif processor.is_a?(Value::Processor)
554
+ klass = processor.class
555
+
556
+ if klass.scoped_path_set?
557
+ if include_processors
558
+ to_include << klass
559
+ end
560
+ klass.foobara_manifest_reference
561
+ # TODO: Delete this nocov block
562
+ # TODO: make anonymous scoped path's have better names instead of random hexadecimal
563
+ # :nocov:
564
+ elsif processor.respond_to?(:symbol) && processor.symbol
565
+ processor.symbol
566
+ else
567
+ name = klass.name
568
+
569
+ while name.nil?
570
+ klass = klass.superclass
571
+ name = klass.name
572
+ end
573
+
574
+ "Anonymous#{Util.non_full_name(name)}"
575
+ # :nocov:
576
+ end
577
+ elsif processor.is_a?(::Proc)
578
+ "Proc"
579
+ else
580
+ # :nocov:
581
+ "Unknown"
582
+ # :nocov:
583
+ end
584
+ end
585
+ end
584
586
  end
585
587
 
586
588
  attr_accessor :command, :untransformed_inputs, :transformed_inputs, :outcome, :request
@@ -626,23 +628,6 @@ module Foobara
626
628
  request.authenticated_credential
627
629
  end
628
630
 
629
- def transform_inputs
630
- transformer = self.class.inputs_transformer
631
-
632
- self.transformed_inputs = if transformer&.applicable?(untransformed_inputs)
633
- outcome = transformer.process_value(untransformed_inputs)
634
-
635
- if outcome.success?
636
- outcome.result
637
- else
638
- self.outcome = outcome
639
- untransformed_inputs
640
- end
641
- else
642
- untransformed_inputs
643
- end
644
- end
645
-
646
631
  def inputs
647
632
  return @inputs if defined?(@inputs)
648
633
 
@@ -727,6 +712,60 @@ module Foobara
727
712
  end
728
713
  end
729
714
 
715
+ def result
716
+ outcome.result
717
+ end
718
+
719
+ def errors
720
+ outcome.errors
721
+ end
722
+
723
+ # TODO: kill this
724
+ def serialize_result(body)
725
+ if serializer
726
+ serializer.process_value!(body)
727
+ else
728
+ body
729
+ end
730
+ end
731
+
732
+ def raw_inputs
733
+ untransformed_inputs
734
+ end
735
+
736
+ def method_missing(method_name, ...)
737
+ if command.respond_to?(method_name)
738
+ command.send(method_name, ...)
739
+ else
740
+ # :nocov:
741
+ super
742
+ # :nocov:
743
+ end
744
+ end
745
+
746
+ def respond_to_missing?(method_name, private = false)
747
+ command.respond_to?(method_name, private) || super
748
+ end
749
+
750
+ private
751
+
752
+ def transform_inputs
753
+ transformer = self.class.inputs_transformer
754
+
755
+ self.transformed_inputs = if transformer&.applicable?(untransformed_inputs)
756
+ outcome = transformer.process_value(untransformed_inputs)
757
+
758
+ if outcome.success?
759
+ outcome.result
760
+ else
761
+ self.outcome = outcome
762
+ untransformed_inputs
763
+ end
764
+ else
765
+ untransformed_inputs
766
+ end
767
+ end
768
+
730
769
  def construct_command
731
770
  self.command = command_class.new(transformed_inputs)
732
771
  end
@@ -804,18 +843,6 @@ module Foobara
804
843
  end
805
844
  end
806
845
 
807
- def result
808
- outcome.result
809
- end
810
-
811
- def errors
812
- outcome.errors
813
- end
814
-
815
- def flush_transactions
816
- request.opened_transactions&.reverse&.each(&:flush!)
817
- end
818
-
819
846
  def transform_outcome
820
847
  if outcome.success?
821
848
  # can we do this while still in the transaction of the command???
@@ -825,31 +852,8 @@ module Foobara
825
852
  end
826
853
  end
827
854
 
828
- # TODO: kill this
829
- def serialize_result(body)
830
- if serializer
831
- serializer.process_value!(body)
832
- else
833
- body
834
- end
835
- end
836
-
837
- def raw_inputs
838
- untransformed_inputs
839
- end
840
-
841
- def method_missing(method_name, ...)
842
- if command.respond_to?(method_name)
843
- command.send(method_name, ...)
844
- else
845
- # :nocov:
846
- super
847
- # :nocov:
848
- end
849
- end
850
-
851
- def respond_to_missing?(method_name, private = false)
852
- command.respond_to?(method_name, private) || super
855
+ def flush_transactions
856
+ request.opened_transactions&.reverse&.each(&:flush!)
853
857
  end
854
858
  end
855
859
  end
@@ -6,6 +6,8 @@ module Foobara
6
6
  load_atoms(object)
7
7
  end
8
8
 
9
+ private
10
+
9
11
  def load_atoms(object)
10
12
  case object
11
13
  when Entity
@@ -14,6 +14,8 @@ module Foobara
14
14
  request
15
15
  end
16
16
 
17
+ private
18
+
17
19
  def load_delegated_attribute_entities(object)
18
20
  case object
19
21
  when Entity
@@ -13,6 +13,8 @@ module Foobara
13
13
 
14
14
  model = Namespace.global.foobara_lookup_type!(:model)
15
15
  BuiltinTypes.build_and_register!(:detached_entity, model, nil)
16
+
17
+ TypeDeclarations::RemoveSensitiveValuesTransformer.include(RemoveSensitiveValuesTransformerExtensions)
16
18
  end
17
19
 
18
20
  def reset_all
@@ -0,0 +1,64 @@
1
+ module Foobara
2
+ class DetachedEntity < Model
3
+ module RemoveSensitiveValuesTransformerExtensions
4
+ def from(...)
5
+ super.tap do
6
+ create_all_association_types_in_current_namespace(from_type)
7
+ end
8
+ end
9
+
10
+ def to(...)
11
+ super.tap do
12
+ create_all_association_types_in_current_namespace(to_type)
13
+ end
14
+ end
15
+
16
+ def create_all_association_types_in_current_namespace(type)
17
+ already_sanitized = Set.new
18
+
19
+ associations = Foobara::DetachedEntity.construct_deep_associations(type)
20
+
21
+ associations&.values&.reverse&.each do |entity_type|
22
+ next if already_sanitized.include?(entity_type)
23
+
24
+ next if entity_type.sensitive?
25
+
26
+ unless entity_type.has_sensitive_types?
27
+ already_sanitized << entity_type
28
+ next
29
+ end
30
+
31
+ ns = Namespace.current
32
+
33
+ declaration = entity_type.declaration_data
34
+ sanitized_type_declaration = TypeDeclarations.remove_sensitive_types(declaration)
35
+
36
+ existing_type = ns.foobara_lookup(
37
+ entity_type.full_type_symbol,
38
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
39
+ )
40
+
41
+ if existing_type
42
+ if existing_type.declaration_data == sanitized_type_declaration
43
+ already_sanitized << entity_type
44
+ already_sanitized << existing_type
45
+ next
46
+ else
47
+ # :nocov:
48
+ raise "Did not expect to be re-sanitizing #{entity_type.full_type_symbol}"
49
+ # :nocov:
50
+ end
51
+
52
+ end
53
+
54
+ # We want to make sure that any types that change due to having sensitive types
55
+ # has a corresponding registered type in the command registry domain if needed
56
+ # TODO: this all feels so messy and brittle.
57
+ Domain.current.foobara_type_from_declaration(sanitized_type_declaration)
58
+
59
+ already_sanitized << entity_type
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -310,27 +310,6 @@ module Foobara
310
310
  type
311
311
  end
312
312
 
313
- def foobara_register_model(model_class)
314
- type = model_class.model_type
315
-
316
- full_name = type.scoped_full_name
317
-
318
- if model_class.full_model_name.size > full_name.size
319
- # TODO: why does this happen exactly??
320
- full_name = model_class.full_model_name
321
- end
322
-
323
- if type.scoped_path_set? && foobara_registered?(full_name, mode: Namespace::LookupMode::DIRECT)
324
- # :nocov:
325
- raise AlreadyRegisteredError, "Already registered: #{type.inspect}"
326
- # :nocov:
327
- end
328
-
329
- foobara_register(type)
330
-
331
- type.target_class
332
- end
333
-
334
313
  def foobara_register_and_deanonymize_entity(name, *, &)
335
314
  entity_class = foobara_register_entity(name, *, &)
336
315
  Foobara::Model.deanonymize_class(entity_class)
@@ -208,6 +208,7 @@ module Foobara
208
208
  delegates[attribute_name] = delegate_manifest
209
209
 
210
210
  delegated_type_declaration = model_type.type_at_path(data_path).reference_or_declaration_data
211
+ # TODO: add defaults and required for the delegated declaration!
211
212
  attributes(type: :attributes, element_type_declarations: { attribute_name => delegated_type_declaration })
212
213
 
213
214
  define_method attribute_name do
@@ -118,7 +118,7 @@ module Foobara
118
118
 
119
119
  model_class.description type.declaration_data[:description]
120
120
 
121
- domain.foobara_register_model(model_class)
121
+ domain.foobara_register(type)
122
122
 
123
123
  if type.declaration_data[:delegates]
124
124
  model_class.delegate_attributes type.declaration_data[:delegates]
@@ -18,7 +18,7 @@ module Foobara
18
18
  # foobara_primary_key_type (nil if not an entity type)
19
19
  # foobara_associations
20
20
  module AttributeHelpers
21
- include Foobara::Concern
21
+ include Concern
22
22
 
23
23
  module ClassMethods
24
24
  def foobara_has_primary_key?
@@ -46,15 +46,15 @@ module Foobara
46
46
 
47
47
  Namespace.use foobara_attributes_type.created_in_namespace do
48
48
  unless includes_primary_key
49
- declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, foobara_primary_key_attribute)
49
+ declaration = TypeDeclarations::Attributes.reject(declaration, foobara_primary_key_attribute)
50
50
  end
51
51
 
52
52
  unless include_private
53
- declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, *private_attribute_names)
53
+ declaration = TypeDeclarations::Attributes.reject(declaration, *private_attribute_names)
54
54
  end
55
55
 
56
56
  unless include_delegates
57
- declaration = Foobara::TypeDeclarations::Attributes.reject(declaration, *foobara_delegates.keys)
57
+ declaration = TypeDeclarations::Attributes.reject(declaration, *foobara_delegates.keys)
58
58
  end
59
59
 
60
60
  Domain.current.foobara_type_from_declaration(declaration)
@@ -181,7 +181,7 @@ module Foobara
181
181
 
182
182
  if candidates.size > 1
183
183
  # :nocov:
184
- raise AmbiguousNameError,
184
+ raise AmbiguousLookupError,
185
185
  "#{path} is ambiguous. Matches the following: #{candidates.map(&:scoped_full_name)}"
186
186
  # :nocov:
187
187
  end
@@ -30,6 +30,12 @@ module Foobara
30
30
  # Maybe use bitmasks for the above 3 places to look instead of a list of 7 lookup types? (There should be 8...)
31
31
  module LookupMode
32
32
  GENERAL = :general
33
+ # Relaxed will allow you to find registered entries without prefixes as long as it's not ambiguous
34
+ # So if there is a SomeOrg::SomeDomain::SomeCommand `GlobalOrganization.foobara_lookup(:SomeCommand)`
35
+ # will return nil but
36
+ # `GlobalOrganization.foobara_lookup(:SomeCommand, mode: Foobara::Namespace::LookupMode::RELAXED)`
37
+ # will return SomeOrg::SomeDomain::SomeCommand even though we didn't specify the necessary prefixes
38
+ # to navigate to it.
33
39
  RELAXED = :relaxed
34
40
  DIRECT = :direct
35
41
  STRICT = :strict
@@ -1,7 +1,5 @@
1
1
  module Foobara
2
2
  module NestedTransactionable
3
- include Concern
4
-
5
3
  class << self
6
4
  def relevant_entity_classes_for_type(type)
7
5
  entity_classes = []
@@ -7,8 +7,6 @@ module Foobara
7
7
 
8
8
  module Concerns
9
9
  module StateTransitions
10
- foobara_delegate :close, to: :state_machine
11
-
12
10
  def currently_open?
13
11
  state_machine.currently_open?
14
12
  end
@@ -188,6 +188,7 @@ module Foobara
188
188
  if tx.currently_open? && !existing_transaction
189
189
  tx.commit!
190
190
  end
191
+
191
192
  result
192
193
  rescue Foobara::Persistence::EntityBase::Transaction::RolledBack # rubocop:disable Lint/SuppressedException
193
194
  rescue => e
@@ -46,8 +46,10 @@ module Foobara
46
46
  Namespace.global.foobara_register(scoped)
47
47
  end
48
48
 
49
+ children = Namespace.global.foobara_children
50
+
49
51
  @original_children.each do |child|
50
- Namespace.global.foobara_children << child
52
+ children.foobara_children << child unless children.include?(child)
51
53
  end
52
54
 
53
55
  GlobalOrganization.foobara_register(GlobalDomain)
@@ -3,65 +3,6 @@ require_relative "typed_transformer"
3
3
  module Foobara
4
4
  module TypeDeclarations
5
5
  class RemoveSensitiveValuesTransformer < TypedTransformer
6
- def from(...)
7
- super.tap do
8
- create_all_association_types_in_current_namespace(from_type)
9
- end
10
- end
11
-
12
- def to(...)
13
- super.tap do
14
- create_all_association_types_in_current_namespace(to_type)
15
- end
16
- end
17
-
18
- def create_all_association_types_in_current_namespace(type)
19
- already_sanitized = Set.new
20
-
21
- associations = Foobara::DetachedEntity.construct_deep_associations(type)
22
-
23
- associations&.values&.reverse&.each do |entity_type|
24
- next if already_sanitized.include?(entity_type)
25
-
26
- next if entity_type.sensitive?
27
-
28
- unless entity_type.has_sensitive_types?
29
- already_sanitized << entity_type
30
- next
31
- end
32
-
33
- ns = Namespace.current
34
-
35
- declaration = entity_type.declaration_data
36
- sanitized_type_declaration = TypeDeclarations.remove_sensitive_types(declaration)
37
-
38
- existing_type = ns.foobara_lookup(
39
- entity_type.full_type_symbol,
40
- mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
41
- )
42
-
43
- if existing_type
44
- if existing_type.declaration_data == sanitized_type_declaration
45
- already_sanitized << entity_type
46
- already_sanitized << existing_type
47
- next
48
- else
49
- # :nocov:
50
- raise "Did not expect to be re-sanitizing #{entity_type.full_type_symbol}"
51
- # :nocov:
52
- end
53
-
54
- end
55
-
56
- # We want to make sure that any types that change due to having sensitive types
57
- # has a corresponding registered type in the command registry domain if needed
58
- # TODO: this all feels so messy and brittle.
59
- Domain.current.foobara_type_from_declaration(sanitized_type_declaration)
60
-
61
- already_sanitized << entity_type
62
- end
63
- end
64
-
65
6
  def to_type_declaration
66
7
  TypeDeclarations.remove_sensitive_types(from_type.declaration_data)
67
8
  end
data/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Foobara
2
2
  module Version
3
- VERSION = "0.2.6".freeze
3
+ VERSION = "0.3.0".freeze
4
4
  MINIMUM_RUBY_VERSION = ">= 3.4.0".freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -190,6 +190,7 @@ files:
190
190
  - projects/command_connectors/src/command_connector/commands/ping.rb
191
191
  - projects/command_connectors/src/command_connector/commands/query_git_commit_info.rb
192
192
  - projects/command_connectors/src/command_connector/concerns/desugarizers.rb
193
+ - projects/command_connectors/src/command_connector/concerns/reflection.rb
193
194
  - projects/command_connectors/src/command_connector/invalid_context_error.rb
194
195
  - projects/command_connectors/src/command_connector/no_command_found_error.rb
195
196
  - projects/command_connectors/src/command_connector/no_command_or_type_found_error.rb
@@ -274,6 +275,7 @@ files:
274
275
  - projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_is_symbol.rb
275
276
  - projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_present.rb
276
277
  - projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
278
+ - projects/detached_entity/src/remove_sensitive_values_transformer_extensions.rb
277
279
  - projects/detached_entity/src/sensitive_type_removers/detached_entity.rb
278
280
  - projects/detached_entity/src/sensitive_value_removers/detached_entity.rb
279
281
  - projects/domain/lib/foobara/domain.rb