foobara 0.0.142 → 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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +19 -0
  4. data/projects/builtin_types/lib/foobara/builtin_types.rb +1 -0
  5. 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
  6. data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/symbolize_defaults.rb +1 -1
  7. 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
  8. data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/alphabetize_required.rb +5 -5
  9. 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
  10. data/projects/builtin_types/src/builtin_types.rb +1 -1
  11. data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_desugarizer.rb +10 -2
  12. data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_type_desugarizer.rb +7 -2
  13. 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
  14. 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
  15. 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
  16. data/projects/builtin_types/src/duck/supported_validators/instance_of.rb +1 -0
  17. data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb +4 -3
  18. data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb +3 -3
  19. data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb +1 -1
  20. 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
  21. data/projects/command/src/command_pattern_implementation/concerns/inputs_type.rb +12 -12
  22. data/projects/command/src/command_pattern_implementation/concerns/reflection.rb +4 -2
  23. data/projects/command/src/command_pattern_implementation/concerns/result_type.rb +0 -4
  24. data/projects/command_connectors/src/command_connector.rb +6 -6
  25. data/projects/command_connectors/src/command_registry.rb +7 -4
  26. data/projects/command_connectors/src/transformed_command.rb +22 -8
  27. data/projects/command_connectors/src/transformers/auth_errors_transformer.rb +1 -0
  28. data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +4 -0
  29. data/projects/detached_entity/src/concerns/types.rb +7 -1
  30. data/projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/model_instance_is_valid.rb +1 -1
  31. data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/hash_desugarizer.rb +6 -9
  32. data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/primary_key_desugarizer.rb +2 -1
  33. data/projects/domain/src/domain_module_extension.rb +12 -4
  34. data/projects/entity/src/concerns/types.rb +6 -1
  35. data/projects/foobara/lib/foobara/all.rb +4 -4
  36. data/projects/manifest/src/foobara/manifest/type.rb +11 -2
  37. data/projects/manifest/src/foobara/manifest/type_declaration.rb +46 -2
  38. data/projects/model/src/concerns/aliases.rb +8 -0
  39. data/projects/model/src/concerns/reflection.rb +2 -2
  40. data/projects/model/src/concerns/types.rb +35 -20
  41. data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb +12 -8
  42. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/array_with_symbolic_elements.rb +1 -1
  43. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +15 -1
  44. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_desugarizer.rb +7 -5
  45. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +4 -7
  46. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +0 -2
  47. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/move_private_from_element_types_to_root.rb +28 -9
  48. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/symbolize_private.rb +8 -7
  49. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +4 -7
  50. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +14 -2
  51. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +8 -9
  52. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +6 -2
  53. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +5 -2
  54. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +8 -7
  55. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +4 -1
  56. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +20 -5
  57. data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -5
  58. data/projects/model/src/extensions/type_declarations/lazy_element_types/model.rb +18 -0
  59. data/projects/model_attribute_helpers/src/attribute_helpers.rb +44 -26
  60. data/projects/namespace/src/is_namespace.rb +58 -90
  61. data/projects/namespace/src/namespace/lookup_mode.rb +13 -2
  62. data/projects/namespace/src/namespace_helpers.rb +1 -0
  63. data/projects/namespace/src/prefixless_registry.rb +2 -0
  64. data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +20 -1
  65. data/projects/persistence/src/entity_base/transaction.rb +14 -11
  66. data/projects/persistence/src/entity_base/transaction_table.rb +10 -49
  67. data/projects/persistence/src/entity_base.rb +39 -0
  68. data/projects/persistence/src/persistence.rb +4 -0
  69. data/projects/type_declarations/src/attributes.rb +15 -9
  70. data/projects/type_declarations/src/attributes_transformers/from_yaml.rb +1 -1
  71. data/projects/type_declarations/src/desugarizer_pipeline.rb +9 -0
  72. data/projects/type_declarations/src/dsl/attributes.rb +14 -5
  73. data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +24 -4
  74. data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +23 -9
  75. data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +3 -7
  76. data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +15 -4
  77. data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +12 -2
  78. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/key_type_declaration_desugarizer.rb +48 -0
  79. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +3 -11
  80. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/value_type_declaration_desugarizer.rb +51 -0
  81. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +12 -2
  82. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +1 -1
  83. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +17 -7
  84. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +16 -19
  85. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +3 -6
  86. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +13 -2
  87. data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +3 -3
  88. data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +16 -4
  89. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +20 -6
  90. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +3 -9
  91. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +12 -2
  92. data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +7 -9
  93. data/projects/type_declarations/src/handlers/registered_type_declaration.rb +22 -7
  94. data/projects/type_declarations/src/lazy_element_types/array.rb +19 -0
  95. data/projects/type_declarations/src/lazy_element_types/attributes.rb +27 -0
  96. data/projects/type_declarations/src/lazy_element_types/hash.rb +38 -0
  97. data/projects/type_declarations/src/lazy_element_types/tuple.rb +23 -0
  98. data/projects/type_declarations/src/sensitive_type_remover.rb +6 -1
  99. data/projects/type_declarations/src/sensitive_type_removers/attributes.rb +2 -0
  100. data/projects/type_declarations/src/type_builder.rb +46 -21
  101. data/projects/type_declarations/src/type_declaration.rb +295 -0
  102. data/projects/type_declarations/src/type_declaration_handler.rb +10 -11
  103. data/projects/type_declarations/src/type_declarations.rb +12 -5
  104. data/projects/types/src/type.rb +26 -4
  105. data/projects/value/src/mutator.rb +1 -4
  106. data/projects/value/src/processor/casting.rb +7 -2
  107. data/projects/value/src/processor/pipeline.rb +9 -1
  108. data/projects/value/src/processor.rb +0 -2
  109. data/projects/value/src/transformer.rb +1 -3
  110. data/projects/value/src/validator.rb +0 -2
  111. data/projects/weak_object_set/src/weak_object_set.rb +2 -0
  112. metadata +10 -7
  113. data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +0 -29
  114. data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +0 -62
  115. data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +0 -32
  116. data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +0 -39
  117. data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +0 -30
  118. data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6defed2fda94d3c5f244f9f24eb9a32f4d06999bc773071dc58667565518499
4
- data.tar.gz: 98a0f663a38ce6b105f78fbbefdc1e34328654ec54755daa379df824753f3214
3
+ metadata.gz: cdaf6b7b731daba3eefc95587311b462b0dcd05372e879410396ce7c3de1624f
4
+ data.tar.gz: a60835ec80262ed79f24d3dad4189d3f3eacd5516e1e0d137ba1e7dd30d6422e
5
5
  SHA512:
6
- metadata.gz: 9c42abcbd62eba3583acfd4345df530ec04efdc18d19773ce1ed5dafa9e0d43d09364b2b45355a22874b2aeaf030d476726cbd214ec1a3626812b2a20c35133f
7
- data.tar.gz: 7cc3b4e13250e4cc2b3af8468b2f5774861161fcc13972ecc87f17c1682bd8a69170a080b6f9cc72249ff5756d2a7f1ca509dfaeba2ac52bbf9896c8b9a4f3e6
6
+ metadata.gz: e12bd29804a5ca80e08796d719e023d6aa5daeeae9e5f14296ff61cc3c1833d5ed660da186e8816e3f0c2fa929af5c9b0ff1ddcb4d4f093df8b7fa9ecbd8961e
7
+ data.tar.gz: 568db83480a82cb3420f9a4286be408a020a02308947759cd6b1115a4e98f2d7af21a9cc2bef41414c1327b15e0de6e4ac836ce879ca2150fa6da054e68f1120
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.3
1
+ 3.4.5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # [0.1.1] - 2025-08-22
2
+
3
+ - Change type declarations for references to registered types to have a structure of `:some_type`
4
+ instead of a `{ type: :some_type }` structure. This makes things faster and also make things less ambiguous.
5
+ - Order entity bases and transaction tables by dependencies to simplify making sure associations
6
+ already have their primary keys set
7
+ - Add Manifest::Type#primitive? and Manifest::TypeDeclaration#primitive?/#reference?
8
+ - Add Type#primitive? and Type#derived? concepts
9
+ - Add ABSOLUTE_SINGLE_NAMESPACE and refactor #foobara_lookup to be much faster
10
+ - Checking #applicable? is now the caller's responsibility when running value processors
11
+ - Run RSpec and Rubocop in separate jobs in CI
12
+ - Don't load pry by default
13
+ - Introduce TypeDeclaration and use it to eliminate some desugarizers and speed things up significantly
14
+ while also improving code readability
15
+ - Eliminate `_desugarized` metadata entry from declaration data now that TypeDeclaration can encapsulate
16
+ such state
17
+ - Lazy load Type#element_type(s) and strictify them
18
+ - Fix bug where .add_inputs is called when .inputs was never called
19
+
1
20
  # [0.0.142] - 2025-08-10
2
21
 
3
22
  - Add LruCache to IsNamespace to speed up lookups
@@ -3,6 +3,7 @@ require "time"
3
3
  require "bigdecimal"
4
4
 
5
5
  module Foobara
6
+ # TODO: rename this to PrimitiveTypes and deprecate the name BuiltinTypes
6
7
  module BuiltinTypes
7
8
  class << self
8
9
  def builtin_types
@@ -8,12 +8,19 @@ module Foobara
8
8
  module Desugarizers
9
9
  class MoveDefaultsFromElementTypesToRoot < TypeDeclarations::Desugarizer
10
10
  def applicable?(value)
11
- value.is_a?(::Hash) && value[:type] == :attributes && value.key?(:element_type_declarations)
11
+ value.hash? && value[:type] == :attributes && value.key?(:element_type_declarations)
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
15
15
  defaults = rawish_type_declaration[:defaults]
16
- defaults = defaults ? defaults.dup : {}
16
+
17
+ if defaults
18
+ unless rawish_type_declaration.deep_duped?
19
+ defaults = defaults.dup
20
+ end
21
+ else
22
+ defaults = {}
23
+ end
17
24
 
18
25
  element_type_declarations = rawish_type_declaration[:element_type_declarations]
19
26
 
@@ -8,7 +8,7 @@ module Foobara
8
8
  module Desugarizers
9
9
  class SymbolizeDefaults < TypeDeclarations::Desugarizer
10
10
  def applicable?(value)
11
- value.is_a?(::Hash) && value[:type] == :attributes && value[:defaults]
11
+ value.hash? && value[:type] == :attributes && value[:defaults]
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
@@ -16,7 +16,7 @@ module Foobara
16
16
  end
17
17
 
18
18
  def applicable?(strict_type_declaration)
19
- strict_type_declaration.is_a?(Hash) && strict_type_declaration.key?(:defaults)
19
+ strict_type_declaration.hash? && strict_type_declaration.key?(:defaults)
20
20
  end
21
21
 
22
22
  def validation_errors(strict_type_declaration)
@@ -8,7 +8,7 @@ module Foobara
8
8
  module Desugarizers
9
9
  class AlphabetizeRequired < TypeDeclarations::Desugarizer
10
10
  def applicable?(value)
11
- value.is_a?(::Hash) && value[:type] == :attributes &&
11
+ value.hash? && value[:type] == :attributes &&
12
12
  value.key?(:required) && value[:required].size > 1
13
13
  end
14
14
 
@@ -17,11 +17,11 @@ module Foobara
17
17
 
18
18
  sorted_required = required.sort
19
19
 
20
- if sorted_required == required
21
- rawish_type_declaration
22
- else
23
- rawish_type_declaration.merge(required: sorted_required)
20
+ if sorted_required != required
21
+ rawish_type_declaration[:required] = sorted_required
24
22
  end
23
+
24
+ rawish_type_declaration
25
25
  end
26
26
 
27
27
  def priority
@@ -8,7 +8,9 @@ module Foobara
8
8
  module Desugarizers
9
9
  class MoveRequiredFromElementTypesToRoot < TypeDeclarations::Desugarizer
10
10
  def applicable?(value)
11
- value.is_a?(::Hash) && value[:type] == :attributes && value.key?(:element_type_declarations)
11
+ return false if value.strict?
12
+
13
+ value.hash? && value[:type] == :attributes && value.key?(:element_type_declarations)
12
14
  end
13
15
 
14
16
  def desugarize(rawish_type_declaration)
@@ -24,13 +26,17 @@ module Foobara
24
26
 
25
27
  element_type_declarations = rawish_type_declaration[:element_type_declarations]
26
28
 
29
+ changed = false
30
+
27
31
  element_type_declarations.each_pair do |attribute_name, attribute_type_declaration|
28
32
  if attribute_type_declaration.is_a?(::Hash) && attribute_type_declaration.key?(:required)
29
33
  is_required = attribute_type_declaration[:required]
30
34
 
31
- if [true, false].include?(is_required)
35
+ if is_required == true || is_required == false
32
36
  element_type_declarations[attribute_name] = attribute_type_declaration.except(:required)
33
37
 
38
+ changed = true
39
+
34
40
  if is_required
35
41
  required_attributes << attribute_name
36
42
  else
@@ -46,6 +52,10 @@ module Foobara
46
52
  rawish_type_declaration[:required] = required_attributes
47
53
  end
48
54
 
55
+ if changed
56
+ rawish_type_declaration[:element_type_declarations] = element_type_declarations
57
+ end
58
+
49
59
  rawish_type_declaration
50
60
  end
51
61
  end
@@ -16,7 +16,7 @@ module Foobara
16
16
  description: "Built-in #{type_symbol} type",
17
17
  type_module: nil
18
18
  )
19
- declaration_data = { type: type_symbol.to_sym }
19
+ declaration_data = type_symbol.to_sym
20
20
 
21
21
  module_symbol = Util.classify(type_symbol).to_sym
22
22
 
@@ -8,11 +8,19 @@ module Foobara
8
8
  module Desugarizers
9
9
  class ClassDesugarizer < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- rawish_type_declaration.is_a?(::Class)
11
+ rawish_type_declaration.class?
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
15
- { type: :duck, instance_of: rawish_type_declaration.name }
15
+ rawish_type_declaration.declaration_data = {
16
+ type: :duck,
17
+ instance_of: rawish_type_declaration.declaration_data.name
18
+ }
19
+ rawish_type_declaration.is_strict = true
20
+ rawish_type_declaration.is_deep_duped = true
21
+ rawish_type_declaration.is_duped = true
22
+
23
+ rawish_type_declaration
16
24
  end
17
25
 
18
26
  def priority
@@ -8,14 +8,19 @@ module Foobara
8
8
  module Desugarizers
9
9
  class ClassTypeDesugarizer < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- return false unless rawish_type_declaration.is_a?(::Hash)
11
+ return false unless rawish_type_declaration.hash?
12
12
 
13
13
  rawish_type_declaration[:type].is_a?(::Class)
14
14
  end
15
15
 
16
16
  def desugarize(rawish_type_declaration)
17
17
  klass = rawish_type_declaration[:type]
18
- rawish_type_declaration.merge(type: :duck, instance_of: klass.name)
18
+
19
+ rawish_type_declaration[:type] = :duck
20
+ rawish_type_declaration[:instance_of] = klass.name
21
+ rawish_type_declaration.is_absolutified = true
22
+
23
+ rawish_type_declaration
19
24
  end
20
25
 
21
26
  def priority
@@ -8,13 +8,12 @@ module Foobara
8
8
  module Desugarizers
9
9
  class InstanceOfClassDesugarizer < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:instance_of].is_a?(::Class)
11
+ rawish_type_declaration.hash? && rawish_type_declaration[:instance_of].is_a?(::Class)
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
15
- instance_of = rawish_type_declaration[:instance_of]
16
- instance_of = instance_of.name
17
- rawish_type_declaration.merge(instance_of:)
15
+ rawish_type_declaration[:instance_of] = rawish_type_declaration[:instance_of].name
16
+ rawish_type_declaration
18
17
  end
19
18
 
20
19
  def priority
@@ -8,13 +8,12 @@ module Foobara
8
8
  module Desugarizers
9
9
  class InstanceOfSymbolDesugarizer < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:instance_of].is_a?(::Symbol)
11
+ rawish_type_declaration.hash? && rawish_type_declaration[:instance_of].is_a?(::Symbol)
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
15
- instance_of = rawish_type_declaration[:instance_of]
16
- instance_of = instance_of.to_s
17
- rawish_type_declaration.merge(instance_of:)
15
+ rawish_type_declaration[:instance_of] = rawish_type_declaration[:instance_of].to_s
16
+ rawish_type_declaration
18
17
  end
19
18
 
20
19
  def priority
@@ -16,7 +16,7 @@ module Foobara
16
16
  end
17
17
 
18
18
  def applicable?(strict_type_declaration)
19
- strict_type_declaration.is_a?(Hash) && strict_type_declaration.key?(:instance_of)
19
+ strict_type_declaration.hash? && strict_type_declaration.key?(:instance_of)
20
20
  end
21
21
 
22
22
  def validation_errors(strict_type_declaration)
@@ -30,6 +30,7 @@ module Foobara
30
30
 
31
31
  def validation_errors(value)
32
32
  klass = Object.const_get(expected_class_name)
33
+
33
34
  unless value.is_a?(klass)
34
35
  build_error(value)
35
36
  end
@@ -8,19 +8,20 @@ module Foobara
8
8
  module Desugarizers
9
9
  class CastOneOf < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:one_of].is_a?(::Array)
11
+ rawish_type_declaration.hash? && rawish_type_declaration[:one_of].is_a?(::Array)
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
15
15
  one_of = rawish_type_declaration[:one_of]
16
16
 
17
+ # TODO: for performance, can we just use the type identified by type: when possible?
17
18
  type = type_for_declaration(rawish_type_declaration.except(:one_of))
18
19
 
19
- one_of = one_of.map do |value|
20
+ rawish_type_declaration[:one_of] = one_of.map do |value|
20
21
  type.process_value!(value)
21
22
  end
22
23
 
23
- rawish_type_declaration.merge(one_of:)
24
+ rawish_type_declaration
24
25
  end
25
26
 
26
27
  def priority
@@ -8,7 +8,7 @@ module Foobara
8
8
  module Desugarizers
9
9
  class ModuleDesugarizer < TypeDeclarations::Desugarizer
10
10
  def applicable?(rawish_type_declaration)
11
- rawish_type_declaration.is_a?(::Hash) && rawish_type_declaration[:one_of].is_a?(::Module)
11
+ rawish_type_declaration.hash? && rawish_type_declaration[:one_of].is_a?(::Module)
12
12
  end
13
13
 
14
14
  def desugarize(rawish_type_declaration)
@@ -16,7 +16,7 @@ module Foobara
16
16
 
17
17
  one_of = Util.constant_values(mod)
18
18
 
19
- one_of = begin
19
+ rawish_type_declaration[:one_of] = begin
20
20
  one_of.sort
21
21
  rescue
22
22
  # :nocov:
@@ -24,7 +24,7 @@ module Foobara
24
24
  # :nocov:
25
25
  end
26
26
 
27
- rawish_type_declaration.merge(one_of:)
27
+ rawish_type_declaration
28
28
  end
29
29
 
30
30
  def priority
@@ -8,7 +8,7 @@ module Foobara
8
8
  module Desugarizers
9
9
  class SetSize < TypeDeclarations::Desugarizer
10
10
  def applicable?(value)
11
- if value.is_a?(::Hash)
11
+ if value.hash?
12
12
  value.key?(:element_type_declarations) && value[:type] == :tuple && !value.key?(:size)
13
13
  end
14
14
  end
@@ -12,8 +12,7 @@ module Foobara
12
12
  def context_type_declaration
13
13
  {
14
14
  expected_size: :integer,
15
- actual_size: :integer,
16
- value: :array
15
+ actual_size: :integer
17
16
  }
18
17
  end
19
18
  end
@@ -33,8 +32,7 @@ module Foobara
33
32
  message: "Expected tuple to have #{size} elements but it had #{element_type_declarations_size}",
34
33
  context: {
35
34
  expected_size: size,
36
- actual_size: element_type_declarations_size,
37
- value: strict_type_declaration
35
+ actual_size: element_type_declarations_size
38
36
  }
39
37
  )
40
38
  end
@@ -26,13 +26,17 @@ module Foobara
26
26
  end
27
27
 
28
28
  def add_inputs(...)
29
- new_type = type_for_declaration(...)
30
- new_declaration = TypeDeclarations::Attributes.merge(
31
- inputs_type.declaration_data,
32
- new_type.declaration_data
33
- )
34
-
35
- inputs new_declaration
29
+ if inputs_type
30
+ new_type = type_for_declaration(...)
31
+ new_declaration = TypeDeclarations::Attributes.merge(
32
+ inputs_type.declaration_data,
33
+ new_type.declaration_data
34
+ )
35
+
36
+ inputs new_declaration
37
+ else
38
+ inputs(...)
39
+ end
36
40
  end
37
41
 
38
42
  def inputs_type
@@ -43,10 +47,6 @@ module Foobara
43
47
  end
44
48
  end
45
49
 
46
- def raw_inputs_type_declaration
47
- inputs_type.raw_declaration_data
48
- end
49
-
50
50
  def inputs_type_declaration
51
51
  inputs_type.declaration_data
52
52
  end
@@ -61,7 +61,7 @@ module Foobara
61
61
  end
62
62
  end
63
63
 
64
- foobara_delegate :inputs_type, :raw_inputs_type_declaration, to: :class
64
+ foobara_delegate :inputs_type, to: :class
65
65
  end
66
66
  end
67
67
  end
@@ -24,8 +24,10 @@ module Foobara
24
24
  to_include = TypeDeclarations.foobara_manifest_context_to_include
25
25
 
26
26
  depends_on = self.depends_on.map do |command_name|
27
- other_command = Foobara::Namespace.global.foobara_lookup!(command_name,
28
- mode: Foobara::Namespace::LookupMode::ABSOLUTE)
27
+ other_command = Foobara::Namespace.global.foobara_lookup!(
28
+ command_name,
29
+ mode: Foobara::Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
30
+ )
29
31
  if to_include
30
32
  to_include << other_command
31
33
  end
@@ -16,10 +16,6 @@ module Foobara
16
16
  superclass.result_type
17
17
  end
18
18
  end
19
-
20
- def raw_result_type_declaration
21
- result_type.raw_declaration_data
22
- end
23
19
  end
24
20
 
25
21
  foobara_delegate :result_type, :raw_result_type_declaration, to: :class
@@ -494,8 +494,7 @@ module Foobara
494
494
  to_include << command_registry.global_organization
495
495
  to_include << command_registry.global_domain
496
496
 
497
- # ABSOLUTE lets us get all of the children but not include dependent domains (GlobalDomain)
498
- command_registry.foobara_each(mode: Namespace::LookupMode::ABSOLUTE) do |exposed_whatever|
497
+ command_registry.foobara_each(mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) do |exposed_whatever|
499
498
  to_include << exposed_whatever
500
499
  end
501
500
 
@@ -539,19 +538,20 @@ module Foobara
539
538
  else
540
539
  domain_name = o.foobara_domain.scoped_full_name
541
540
 
542
- unless command_registry.foobara_registered?(domain_name, mode: Namespace::LookupMode::ABSOLUTE)
541
+ unless command_registry.foobara_registered?(domain_name,
542
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
543
543
  command_registry.build_and_register_exposed_domain(domain_name)
544
544
 
545
545
  # Since we don't know which other domains/orgs creating this domain might have created,
546
546
  # we will just add them all to be included just in case
547
547
  command_registry.foobara_all_domain(
548
- mode: Namespace::LookupMode::ABSOLUTE
548
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
549
549
  ).each do |exposed_domain|
550
550
  additional_to_include << exposed_domain
551
551
  end
552
552
 
553
553
  command_registry.foobara_all_organization(
554
- mode: Namespace::LookupMode::ABSOLUTE
554
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
555
555
  ).each do |exposed_organization|
556
556
  additional_to_include << exposed_organization
557
557
  end
@@ -649,7 +649,7 @@ module Foobara
649
649
  def all_exposed_commands
650
650
  process_delayed_connections
651
651
 
652
- command_registry.foobara_all_command(mode: Namespace::LookupMode::ABSOLUTE)
652
+ command_registry.foobara_all_command(mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
653
653
  end
654
654
 
655
655
  def all_exposed_type_names
@@ -34,7 +34,8 @@ module Foobara
34
34
 
35
35
  def create_exposed_command(command_class, **)
36
36
  full_domain_name = command_class.domain.scoped_full_name
37
- exposed_domain = foobara_lookup_domain(full_domain_name, mode: Namespace::LookupMode::ABSOLUTE) ||
37
+ exposed_domain = foobara_lookup_domain(full_domain_name,
38
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) ||
38
39
  build_and_register_exposed_domain(full_domain_name)
39
40
 
40
41
  exposed_command = create_exposed_command_without_domain(command_class, **)
@@ -81,7 +82,7 @@ module Foobara
81
82
 
82
83
  exposed_organization = foobara_lookup_organization(
83
84
  full_organization_name,
84
- mode: Namespace::LookupMode::ABSOLUTE
85
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
85
86
  ) || build_and_register_exposed_organization(full_organization_name)
86
87
 
87
88
  exposed_domain = Module.new
@@ -108,13 +109,15 @@ module Foobara
108
109
  end
109
110
 
110
111
  def global_domain
111
- foobara_lookup_domain("") || build_and_register_exposed_domain("")
112
+ foobara_lookup_domain("", mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) ||
113
+ build_and_register_exposed_domain("")
112
114
  end
113
115
 
114
116
  def global_organization
115
117
  # TODO: test this
116
118
  # :nocov:
117
- foobara_lookup_organization("") || build_and_register_exposed_organization("")
119
+ foobara_lookup_organization("", mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) ||
120
+ build_and_register_exposed_organization("")
118
121
  # :nocov:
119
122
  end
120
123
 
@@ -502,7 +502,9 @@ module Foobara
502
502
  end
503
503
 
504
504
  def mutate_request(request)
505
- request_mutator&.process_value!(request)
505
+ if request_mutator&.applicable?(request)
506
+ request_mutator.process_value!(request)
507
+ end
506
508
  end
507
509
 
508
510
  def result_transformer
@@ -594,8 +596,10 @@ module Foobara
594
596
  end
595
597
 
596
598
  def transform_inputs
597
- self.transformed_inputs = if self.class.inputs_transformer
598
- outcome = self.class.inputs_transformer.process_value(untransformed_inputs)
599
+ transformer = self.class.inputs_transformer
600
+
601
+ self.transformed_inputs = if transformer&.applicable?(untransformed_inputs)
602
+ outcome = transformer.process_value(untransformed_inputs)
599
603
 
600
604
  if outcome.success?
601
605
  outcome.result
@@ -625,17 +629,23 @@ module Foobara
625
629
  end
626
630
 
627
631
  def transform_result
628
- if self.class.result_transformer
629
- self.outcome = Outcome.success(self.class.result_transformer.process_value!(result))
632
+ transformer = self.class.result_transformer
633
+
634
+ if transformer&.applicable?(result)
635
+ self.outcome = Outcome.success(transformer.process_value!(result))
630
636
  end
631
637
  end
632
638
 
633
639
  def mutate_response(response)
634
- self.class.response_mutator&.process_value!(response)
640
+ mutator = self.class.response_mutator
641
+
642
+ if mutator&.applicable?(response)
643
+ mutator.process_value!(response)
644
+ end
635
645
  end
636
646
 
637
647
  def transform_errors
638
- if errors_transformer
648
+ if errors_transformer&.applicable?(errors)
639
649
  self.outcome = Outcome.errors(errors_transformer.process_value!(errors))
640
650
  end
641
651
  end
@@ -708,7 +718,9 @@ module Foobara
708
718
  source = if allowed_rule.block.respond_to?("source") && defined?(MethodSource)
709
719
  begin
710
720
  # This only works when pry is loaded
721
+ # :nocov:
711
722
  allowed_rule.block.source
723
+ # :nocov:
712
724
  rescue MethodSource::SourceNotFoundError
713
725
  # This path is hit if the way the source code is extracted
714
726
  # doesn't result in valid Ruby, for example, as part of a hash such as:
@@ -733,7 +745,9 @@ module Foobara
733
745
  def apply_pre_commit_transformers
734
746
  if pre_commit_transformer
735
747
  command.before_commit_transaction do |**|
736
- pre_commit_transformer.process_value!(self)
748
+ if pre_commit_transformer.applicable?(self)
749
+ pre_commit_transformer.process_value!(self)
750
+ end
737
751
  end
738
752
  end
739
753
  end
@@ -20,6 +20,7 @@ module Foobara
20
20
  map
21
21
  end
22
22
  end
23
+
23
24
  def applicable?(_request)
24
25
  false
25
26
  end
@@ -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]) ||
@@ -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
- super.merge(type: :detached_entity, primary_key: primary_key_attribute)
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
@@ -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 == { type: expected_type_symbol }
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