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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +23 -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/common/src/error_collection.rb +1 -1
  30. data/projects/detached_entity/src/concerns/types.rb +7 -1
  31. data/projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/model_instance_is_valid.rb +1 -1
  32. data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/hash_desugarizer.rb +6 -9
  33. data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/primary_key_desugarizer.rb +2 -1
  34. data/projects/domain/src/domain_module_extension.rb +12 -4
  35. data/projects/entity/src/concerns/types.rb +6 -1
  36. data/projects/foobara/lib/foobara/all.rb +4 -4
  37. data/projects/manifest/src/foobara/manifest/type.rb +11 -2
  38. data/projects/manifest/src/foobara/manifest/type_declaration.rb +46 -2
  39. data/projects/model/src/concerns/aliases.rb +8 -0
  40. data/projects/model/src/concerns/reflection.rb +2 -2
  41. data/projects/model/src/concerns/types.rb +35 -20
  42. data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb +12 -8
  43. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/array_with_symbolic_elements.rb +1 -1
  44. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +15 -1
  45. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_desugarizer.rb +7 -5
  46. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +4 -7
  47. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +0 -2
  48. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/move_private_from_element_types_to_root.rb +28 -9
  49. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/symbolize_private.rb +8 -7
  50. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +4 -7
  51. data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +14 -2
  52. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +8 -9
  53. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +6 -2
  54. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +5 -2
  55. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +8 -7
  56. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +4 -1
  57. data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +20 -5
  58. data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -5
  59. data/projects/model/src/extensions/type_declarations/lazy_element_types/model.rb +18 -0
  60. data/projects/model_attribute_helpers/src/attribute_helpers.rb +44 -26
  61. data/projects/namespace/src/is_namespace.rb +93 -49
  62. data/projects/namespace/src/namespace/lookup_mode.rb +13 -2
  63. data/projects/namespace/src/namespace_helpers.rb +1 -0
  64. data/projects/namespace/src/prefixless_registry.rb +2 -0
  65. data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +20 -1
  66. data/projects/persistence/src/entity_base/transaction.rb +14 -11
  67. data/projects/persistence/src/entity_base/transaction_table.rb +10 -49
  68. data/projects/persistence/src/entity_base.rb +39 -0
  69. data/projects/persistence/src/persistence.rb +4 -0
  70. data/projects/type_declarations/src/attributes.rb +15 -9
  71. data/projects/type_declarations/src/attributes_transformers/from_yaml.rb +1 -1
  72. data/projects/type_declarations/src/desugarizer_pipeline.rb +9 -0
  73. data/projects/type_declarations/src/dsl/attributes.rb +14 -5
  74. data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +24 -4
  75. data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +23 -9
  76. data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +3 -7
  77. data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +15 -4
  78. data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +12 -2
  79. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/key_type_declaration_desugarizer.rb +48 -0
  80. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +3 -11
  81. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/value_type_declaration_desugarizer.rb +51 -0
  82. data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +12 -2
  83. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +1 -1
  84. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +17 -7
  85. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +16 -19
  86. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +3 -6
  87. data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +13 -2
  88. data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +3 -3
  89. data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +16 -4
  90. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +20 -6
  91. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +3 -9
  92. data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +12 -2
  93. data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +7 -9
  94. data/projects/type_declarations/src/handlers/registered_type_declaration.rb +22 -7
  95. data/projects/type_declarations/src/lazy_element_types/array.rb +19 -0
  96. data/projects/type_declarations/src/lazy_element_types/attributes.rb +27 -0
  97. data/projects/type_declarations/src/lazy_element_types/hash.rb +38 -0
  98. data/projects/type_declarations/src/lazy_element_types/tuple.rb +23 -0
  99. data/projects/type_declarations/src/sensitive_type_remover.rb +6 -1
  100. data/projects/type_declarations/src/sensitive_type_removers/attributes.rb +2 -0
  101. data/projects/type_declarations/src/type_builder.rb +46 -21
  102. data/projects/type_declarations/src/type_declaration.rb +295 -0
  103. data/projects/type_declarations/src/type_declaration_handler.rb +10 -11
  104. data/projects/type_declarations/src/type_declarations.rb +12 -5
  105. data/projects/types/src/type.rb +26 -4
  106. data/projects/value/src/mutator.rb +1 -4
  107. data/projects/value/src/processor/casting.rb +7 -2
  108. data/projects/value/src/processor/pipeline.rb +9 -1
  109. data/projects/value/src/processor.rb +0 -2
  110. data/projects/value/src/transformer.rb +1 -3
  111. data/projects/value/src/validator.rb +0 -2
  112. data/projects/weak_object_set/src/weak_object_set.rb +2 -0
  113. metadata +24 -21
  114. data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +0 -29
  115. data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +0 -63
  116. data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +0 -32
  117. data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +0 -39
  118. data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +0 -30
  119. data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +0 -24
@@ -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.is_a?(::Hash)
8
- return false unless Util.all_symbolizable_keys?(sugary_type_declaration)
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) && type_registered?(type_symbol)
20
- type = Foobara.foobara_root_namespace.foobara_lookup_type(
21
- type_symbol, mode: Namespace::LookupMode::ABSOLUTE
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
- Util.symbolize_keys(sugary_type_declaration)
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.merge(primary_key: sugary_type_declaration[:primary_key].to_sym)
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 = [TypeDeclarations::Dsl::Attributes.to_declaration(&block), *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
- entity_type = foobara_type_builder.type_for_declaration(
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
@@ -6,7 +6,12 @@ module Foobara
6
6
 
7
7
  module ClassMethods
8
8
  def type_declaration(...)
9
- super.merge(type: :entity)
9
+ declaration = super
10
+
11
+ declaration[:type] = :entity
12
+ declaration.is_absolutified = true
13
+
14
+ declaration
10
15
  end
11
16
  end
12
17
  end
@@ -34,13 +34,13 @@ module Foobara
34
34
  "model",
35
35
  "detached_entity",
36
36
  "entity",
37
- "model_attribute_helpers",
37
+ "persistence",
38
38
  "nested_transactionable",
39
- "command",
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
- # Not sure the best way to define this...
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
- !builtin? && !model?
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
- raise "detached_entity extension instead of an detached_entity" unless relevant_manifest.size == 1
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
- raise "entity extension instead of an entity" unless relevant_manifest.size == 1
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
@@ -8,6 +8,14 @@ module Foobara
8
8
  def model_name(...)
9
9
  foobara_model_name(...)
10
10
  end
11
+
12
+ def delegates(...)
13
+ foobara_delegates(...)
14
+ end
15
+
16
+ def private_attribute_names
17
+ foobara_private_attribute_names
18
+ end
11
19
  end
12
20
  end
13
21
  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: private_attribute_names
26
+ delegates: foobara_delegates,
27
+ private: foobara_private_attribute_names
28
28
  )
29
29
  end
30
30
  end
@@ -63,9 +63,12 @@ module Foobara
63
63
  declaration = type_declaration(attributes_type.declaration_data)
64
64
 
65
65
  if model_type
66
- unless Foobara::TypeDeclarations.declarations_equal?(declaration, model_type.declaration_data)
66
+ unless Foobara::TypeDeclarations.declarations_equal?(declaration.declaration_data,
67
+ model_type.declaration_data)
68
+
67
69
  type_domain = domain
68
70
  self.model_type = nil
71
+
69
72
  type_domain.foobara_type_from_declaration(declaration)
70
73
  end
71
74
  else
@@ -97,19 +100,25 @@ module Foobara
97
100
  end
98
101
  end
99
102
 
100
- Util.remove_blank(
101
- type: :model,
102
- name: model_name,
103
- model_module: model_module_name,
104
- model_class:,
105
- model_base_class:,
106
- attributes_declaration:,
107
- description:,
108
- _desugarized: { type_absolutified: true },
109
- mutable:,
110
- delegates:,
111
- private: private_attribute_names
103
+ type_declaration = TypeDeclaration.new(
104
+ Util.remove_blank(
105
+ type: :model,
106
+ name: model_name,
107
+ model_module: model_module_name,
108
+ model_class:,
109
+ model_base_class:,
110
+ attributes_declaration:,
111
+ description:,
112
+ mutable:,
113
+ delegates:,
114
+ private: private_attribute_names
115
+ )
112
116
  )
117
+
118
+ type_declaration.is_absolutified = true
119
+ type_declaration.is_duped = true
120
+
121
+ type_declaration
113
122
  end
114
123
 
115
124
  def foobara_attributes_type
@@ -152,16 +161,16 @@ module Foobara
152
161
  end
153
162
  end
154
163
 
155
- def delegates
156
- @delegates ||= {}
164
+ def foobara_delegates
165
+ @foobara_delegates ||= {}
157
166
  end
158
167
 
159
168
  def has_delegated_attributes?
160
169
  !delegates.empty?
161
170
  end
162
171
 
163
- def private_attribute_names
164
- @private_attribute_names ||= []
172
+ def foobara_private_attribute_names
173
+ @foobara_private_attribute_names ||= []
165
174
  end
166
175
 
167
176
  def private_attributes(attribute_names)
@@ -171,7 +180,7 @@ module Foobara
171
180
  end
172
181
 
173
182
  def private_attribute(attribute_name)
174
- @private_attribute_names = private_attribute_names | [attribute_name]
183
+ @foobara_private_attribute_names = private_attribute_names | [attribute_name]
175
184
 
176
185
  set_model_type
177
186
  end
@@ -229,20 +238,26 @@ module Foobara
229
238
  private = []
230
239
  attributes_type_declaration = TypeDeclarations.args_to_type_declaration(...)
231
240
 
232
- if attributes_type_declaration.is_a?(::Hash) || attributes_type_declaration.is_a?(Proc)
241
+ if attributes_type_declaration.hash? || attributes_type_declaration.proc?
233
242
  handler = domain.foobara_type_builder.handler_for_class(
234
243
  TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
235
244
  )
236
245
  attributes_type_declaration = Namespace.use domain do
237
- handler.desugarize(attributes_type_declaration)
246
+ handler.desugarize(attributes_type_declaration.clone)
238
247
  end
239
248
 
240
249
  element_type_declarations = attributes_type_declaration[:element_type_declarations]
241
250
 
242
251
  element_type_declarations.each_pair do |attribute_name, attribute_type_declaration|
252
+ next if attribute_type_declaration.is_a?(::Symbol)
253
+
243
254
  is_private = attribute_type_declaration.delete(:private)
244
255
 
245
256
  if is_private
257
+ if attribute_type_declaration.keys.size == 1
258
+ element_type_declarations[attribute_name] = attribute_type_declaration[:type]
259
+ end
260
+
246
261
  private |= [attribute_name]
247
262
  end
248
263
  end
@@ -22,16 +22,20 @@ module Foobara
22
22
  end
23
23
 
24
24
  def possible_errors
25
- model_class_name = parent_declaration_data[:model_class]
25
+ if parent_declaration_data.is_a?(::Hash)
26
+ model_class_name = parent_declaration_data[:model_class]
26
27
 
27
- if model_class_name
28
- model_class = if Object.const_defined?(model_class_name)
29
- Object.const_get(model_class_name)
30
- else
31
- Namespace.current.foobara_lookup_type!(model_class_name).target_class
32
- end
28
+ if model_class_name
29
+ model_class = if Object.const_defined?(model_class_name)
30
+ Object.const_get(model_class_name)
31
+ else
32
+ Namespace.current.foobara_lookup_type!(model_class_name).target_class
33
+ end
33
34
 
34
- model_class.possible_errors
35
+ model_class.possible_errors
36
+ else
37
+ super
38
+ end
35
39
  else
36
40
  super
37
41
  end
@@ -12,7 +12,7 @@ module Foobara
12
12
  end
13
13
 
14
14
  def applicable?(strict_type_declaration)
15
- strict_type_declaration.is_a?(Hash) && strict_type_declaration.key?(:private)
15
+ strict_type_declaration.hash? && strict_type_declaration.key?(:private)
16
16
  end
17
17
 
18
18
  def validation_errors(strict_type_declaration)
@@ -15,7 +15,21 @@ module Foobara
15
15
  handler = handler_for_class(ExtendAttributesTypeDeclaration)
16
16
  attributes_type_declaration = sugary_type_declaration[:attributes_declaration]
17
17
 
18
- sugary_type_declaration.merge(attributes_declaration: handler.desugarize(attributes_type_declaration))
18
+ declaration = sugary_type_declaration.clone_from_part(attributes_type_declaration)
19
+
20
+ if sugary_type_declaration.deep_duped?
21
+ # TODO: probably not worth directly testing this path
22
+ # :nocov:
23
+ declaration.is_duped = true
24
+ declaration.is_deep_duped = true
25
+ # :nocov:
26
+ end
27
+
28
+ declaration = handler.desugarize(declaration)
29
+
30
+ sugary_type_declaration[:attributes_declaration] = declaration.declaration_data
31
+
32
+ sugary_type_declaration
19
33
  end
20
34
  end
21
35
  end
@@ -8,13 +8,13 @@ module Foobara
8
8
  end
9
9
 
10
10
  def desugarize(sugary_type_declaration)
11
- desugarized = sugary_type_declaration.dup
12
- delegates = Util.deep_symbolize_keys(desugarized[:delegates])
11
+ delegates = sugary_type_declaration[:delegates]
13
12
 
14
13
  if delegates.empty?
15
- desugarized.delete(:delegates)
16
- desugarized
14
+ sugary_type_declaration.delete(:delegates)
17
15
  else
16
+ delegates = Util.deep_symbolize_keys(sugary_type_declaration[:delegates])
17
+
18
18
  delegates.each_pair do |attribute_name, delegate_info|
19
19
  h = delegate_info.merge(data_path: DataPath.new(delegate_info[:data_path]).to_s)
20
20
 
@@ -29,8 +29,10 @@ module Foobara
29
29
  delegates[attribute_name] = h
30
30
  end
31
31
 
32
- sugary_type_declaration.merge(delegates:)
32
+ sugary_type_declaration[:delegates] = delegates
33
33
  end
34
+
35
+ sugary_type_declaration
34
36
  end
35
37
  end
36
38
  end
@@ -4,12 +4,8 @@ module Foobara
4
4
  class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
5
5
  class HashDesugarizer < TypeDeclarations::Desugarizer
6
6
  def applicable?(sugary_type_declaration)
7
- return false unless sugary_type_declaration.is_a?(::Hash)
8
- return false unless Util.all_symbolizable_keys?(sugary_type_declaration)
9
-
10
- sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
11
-
12
- return true unless sugary_type_declaration.key?(:type)
7
+ return false unless sugary_type_declaration.hash?
8
+ return false unless sugary_type_declaration.all_symbolizable_keys?
13
9
 
14
10
  sugary_type_declaration[:type] == expected_type_symbol
15
11
  end
@@ -19,7 +15,8 @@ module Foobara
19
15
  end
20
16
 
21
17
  def desugarize(sugary_type_declaration)
22
- Util.symbolize_keys(sugary_type_declaration)
18
+ sugary_type_declaration.symbolize_keys!
19
+ sugary_type_declaration
23
20
  end
24
21
 
25
22
  def priority
@@ -17,8 +17,6 @@ module Foobara
17
17
 
18
18
  # TODO: consider splitting this up into multiple desugarizers
19
19
  def desugarize(strictish_type_declaration)
20
- strictish_type_declaration = strictish_type_declaration.dup
21
-
22
20
  if strictish_type_declaration.key?(:model_module)
23
21
  model_module = strictish_type_declaration[:model_module]
24
22
 
@@ -4,19 +4,28 @@ module Foobara
4
4
  class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
5
5
  class MovePrivateFromElementTypesToRoot < TypeDeclarations::Desugarizer
6
6
  def applicable?(value)
7
- if value.is_a?(::Hash) && value.key?(:type) && value.key?(:attributes_declaration)
8
- type_symbol = value[:type]
7
+ if value.hash? && value.key?(:type) && value.key?(:attributes_declaration)
8
+ type = value.type || lookup_type(value[:type])
9
9
 
10
- if type_registered?(type_symbol)
11
- type = lookup_type!(type_symbol)
12
- type.extends?(BuiltinTypes[:model])
10
+ if type
11
+ if type.extends?(BuiltinTypes[:model])
12
+ value.base_type = type
13
+ true
14
+ end
13
15
  end
14
16
  end
15
17
  end
16
18
 
17
19
  def desugarize(rawish_type_declaration)
18
20
  private = rawish_type_declaration[:private]
19
- private = private ? private.dup : []
21
+
22
+ if private.nil?
23
+ private = []
24
+ else
25
+ unless rawish_type_declaration.deep_duped?
26
+ private = private.dup
27
+ end
28
+ end
20
29
 
21
30
  attributes_declaration = rawish_type_declaration[:attributes_declaration]
22
31
  element_type_declarations = attributes_declaration[:element_type_declarations]
@@ -24,7 +33,15 @@ module Foobara
24
33
  element_type_declarations.each_pair do |attribute_name, attribute_type_declaration|
25
34
  if attribute_type_declaration.is_a?(Hash) && attribute_type_declaration.key?(:private)
26
35
  is_private = attribute_type_declaration[:private]
27
- element_type_declarations[attribute_name] = attribute_type_declaration.except(:private)
36
+
37
+ declaration = attribute_type_declaration.except(:private)
38
+
39
+ if declaration.keys == [:type]
40
+ declaration = TypeDeclaration.new(declaration).declaration_data
41
+ end
42
+
43
+ element_type_declarations[attribute_name] = declaration
44
+
28
45
  if is_private
29
46
  private |= [attribute_name]
30
47
  end
@@ -32,10 +49,12 @@ module Foobara
32
49
  end
33
50
 
34
51
  if private.empty?
35
- rawish_type_declaration.except(:private)
52
+ rawish_type_declaration.delete(:private)
36
53
  else
37
- rawish_type_declaration.merge(private:)
54
+ rawish_type_declaration[:private] = private
38
55
  end
56
+
57
+ rawish_type_declaration
39
58
  end
40
59
 
41
60
  def priority
@@ -4,11 +4,12 @@ module Foobara
4
4
  class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
5
5
  class SymbolizePrivate < TypeDeclarations::Desugarizer
6
6
  def applicable?(value)
7
- if value.is_a?(::Hash) && value.key?(:type) && value.key?(:attributes_declaration) && value.key?(:private)
8
- type_symbol = value[:type]
7
+ if value.hash? && value.key?(:type) && value.key?(:attributes_declaration) && value.key?(:private)
9
8
 
10
- if type_registered?(type_symbol)
11
- type = lookup_type!(type_symbol)
9
+ type = value.type || lookup_type(value[:type])
10
+
11
+ if type
12
+ value.type = type
12
13
  type.extends?(BuiltinTypes[:model])
13
14
  end
14
15
  end
@@ -18,10 +19,10 @@ module Foobara
18
19
  private = rawish_type_declaration[:private]
19
20
 
20
21
  if private.any? { |key| key.is_a?(::String) }
21
- rawish_type_declaration.merge(private: private.map(&:to_sym))
22
- else
23
- rawish_type_declaration
22
+ rawish_type_declaration[:private] = private.map(&:to_sym)
24
23
  end
24
+
25
+ rawish_type_declaration
25
26
  end
26
27
 
27
28
  def priority
@@ -25,7 +25,7 @@ module Foobara
25
25
  else
26
26
  existing_type = Domain.current.foobara_lookup_type(
27
27
  model_class_name,
28
- mode: Namespace::LookupMode::ABSOLUTE
28
+ mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
29
29
  )
30
30
 
31
31
  existing_type&.target_class
@@ -77,10 +77,7 @@ module Foobara
77
77
  if outcome.success?
78
78
  type = outcome.result
79
79
 
80
- handler = handler_for_class(ExtendAttributesTypeDeclaration)
81
- attributes_type_declaration = type.declaration_data[:attributes_declaration]
82
-
83
- type.element_types = handler.process_value!(attributes_type_declaration)
80
+ type.element_types = :Model
84
81
 
85
82
  model_class = type.target_class
86
83
  existing_model_type = model_class.model_type
@@ -105,8 +102,8 @@ module Foobara
105
102
 
106
103
  model_class.description type.declaration_data[:description]
107
104
 
108
- if domain.foobara_type_registered?(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
109
- existing_type = domain.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::ABSOLUTE)
105
+ if domain.foobara_type_registered?(type_symbol, mode: Namespace::LookupMode::DIRECT)
106
+ existing_type = domain.foobara_lookup_type(type_symbol, mode: Namespace::LookupMode::DIRECT)
110
107
  domain.foobara_unregister(existing_type)
111
108
  end
112
109
 
@@ -3,8 +3,20 @@ module Foobara
3
3
  module Handlers
4
4
  class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
5
5
  def applicable?(sugary_type_declaration)
6
- if sugary_type_declaration.is_a?(::Hash)
7
- desugarize(sugary_type_declaration)[:type] == expected_type_symbol
6
+ if sugary_type_declaration.hash?
7
+ strict_type_declaration = if sugary_type_declaration.strict?
8
+ sugary_type_declaration
9
+ else
10
+ desugarize(sugary_type_declaration.clone)
11
+ end
12
+
13
+ if strict_type_declaration[:type] == expected_type_symbol
14
+ unless sugary_type_declaration.equal?(strict_type_declaration)
15
+ sugary_type_declaration.assign(strict_type_declaration)
16
+ end
17
+
18
+ true
19
+ end
8
20
  end
9
21
  end
10
22