foobara 0.0.131 → 0.0.132
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/CHANGELOG.md +8 -0
- data/projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb +2 -2
- data/projects/command_connectors/src/transformed_command.rb +10 -11
- data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +88 -0
- data/projects/detached_entity/src/concerns/associations.rb +20 -10
- data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb +1 -1
- data/projects/type_declarations/src/typed_transformer.rb +4 -0
- data/projects/types/src/type.rb +21 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4c8a877056c159be9d156cde81dececc246a1dda21e99c39d567603c4b99aca
|
4
|
+
data.tar.gz: 71f5c66811f399c7311b6a13fcd9562b7b11f1e6b3eb34e6cd0298cb6e2e548a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97210eac20ace35283b2fdffe8ac36d924c3ac19336a34b914357a7c0cc7ab0a3097a867d78032898cbf8dc21ef57c6c605100919f96cfbbad15a3955cde4d2f
|
7
|
+
data.tar.gz: fb717c26f27f5fb6be91d77ddce128de252198523d4cc535d315fbe1029981951242a845b37460cee4cc3b6b0862a6220463750499e400d4a8d8426c62e776d4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# [0.0.132] - 2025-06-19
|
2
|
+
|
3
|
+
- Add/improve the description for primary key types in EntityToPrimaryKeyInputsTransformer
|
4
|
+
- Support model and tuple types in .has_associations?
|
5
|
+
- Move EntityToPrimaryKeyInputsTransformer over from foobara-agent gem
|
6
|
+
- Make sure EntitiesToPrimaryKeysSerializer recurses into models/detached entities
|
7
|
+
- Fix bugs impacting use of multiple inputs transformers at a time and other issues with typed transformers
|
8
|
+
|
1
9
|
# [0.0.131] - 2025-06-16
|
2
10
|
|
3
11
|
- Extract InMemoryMinimal crud driver specs to foobara-crud-driver-spec-helpers gem
|
@@ -14,10 +14,10 @@ module Foobara
|
|
14
14
|
if detached_to_primary_key?
|
15
15
|
object.primary_key
|
16
16
|
else
|
17
|
-
object.attributes_with_delegates
|
17
|
+
serialize(object.attributes_with_delegates)
|
18
18
|
end
|
19
19
|
when Model
|
20
|
-
object.attributes_with_delegates
|
20
|
+
serialize(object.attributes_with_delegates)
|
21
21
|
when ::Array
|
22
22
|
object.map { |element| serialize(element) }
|
23
23
|
when ::Hash
|
@@ -114,7 +114,9 @@ module Foobara
|
|
114
114
|
inputs_type = command_class.inputs_type
|
115
115
|
|
116
116
|
@inputs_transformers = transformers_to_processors(@inputs_transformers, inputs_type, direction: :to)
|
117
|
+
@inputs_transformers = @inputs_transformers.reverse
|
117
118
|
|
119
|
+
# TODO: this block looks pointless...
|
118
120
|
@inputs_transformers.each do |transformer|
|
119
121
|
if transformer.is_a?(TypeDeclarations::TypedTransformer)
|
120
122
|
new_type = transformer.from_type
|
@@ -442,21 +444,18 @@ module Foobara
|
|
442
444
|
def inputs_transformer
|
443
445
|
return @inputs_transformer if defined?(@inputs_transformer)
|
444
446
|
|
445
|
-
|
447
|
+
transformers = inputs_transformers
|
448
|
+
|
449
|
+
if transformers.empty?
|
446
450
|
@inputs_transformer = nil
|
447
451
|
return
|
448
452
|
end
|
449
453
|
|
450
|
-
@inputs_transformer =
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
transformers.first
|
456
|
-
else
|
457
|
-
Value::Processor::Pipeline.new(processors: transformers)
|
458
|
-
end
|
459
|
-
end
|
454
|
+
@inputs_transformer = if transformers.size == 1
|
455
|
+
transformers.first
|
456
|
+
else
|
457
|
+
Value::Processor::Pipeline.new(processors: transformers)
|
458
|
+
end
|
460
459
|
end
|
461
460
|
|
462
461
|
def response_mutator
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Foobara
|
2
|
+
module CommandConnectors
|
3
|
+
module Transformers
|
4
|
+
class EntityToPrimaryKeyInputsTransformer < TypeDeclarations::TypedTransformer
|
5
|
+
def from_type_declaration
|
6
|
+
return nil unless to_type
|
7
|
+
|
8
|
+
if contains_associations_or_is_entity?(to_type)
|
9
|
+
if to_type.extends?(Foobara::BuiltinTypes[:attributes])
|
10
|
+
to_fix = {}
|
11
|
+
|
12
|
+
to_type.element_types.each_pair do |attribute_name, attribute_type|
|
13
|
+
if contains_associations_or_is_entity?(attribute_type)
|
14
|
+
to_fix[attribute_name] = attribute_type
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
element_type_declarations = to_type.declaration_data[:element_type_declarations].dup
|
19
|
+
|
20
|
+
to_fix.each_pair do |attribute_name, attribute_type|
|
21
|
+
transformer = EntityToPrimaryKeyInputsTransformer.new(to: attribute_type)
|
22
|
+
element_type_declarations[attribute_name] = transformer.from_type_declaration
|
23
|
+
end
|
24
|
+
|
25
|
+
to_type.declaration_data.merge(element_type_declarations:)
|
26
|
+
elsif to_type.extends?(Foobara::BuiltinTypes[:tuple])
|
27
|
+
indexes_to_fix = []
|
28
|
+
|
29
|
+
to_type.element_types.each.with_index do |element_type, index|
|
30
|
+
if contains_associations_or_is_entity?(element_type)
|
31
|
+
indexes_to_fix << index
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
element_type_declarations = to_type.declaration_data[:element_type_declarations].dup
|
36
|
+
|
37
|
+
indexes_to_fix.each do |index|
|
38
|
+
transformer = EntityToPrimaryKeyInputsTransformer.new(to: to_type.element_types[index])
|
39
|
+
element_type_declarations[index] = transformer.from_type_declaration
|
40
|
+
end
|
41
|
+
|
42
|
+
to_type.declaration_data.merge(element_type_declarations:)
|
43
|
+
elsif to_type.extends?(Foobara::BuiltinTypes[:array])
|
44
|
+
transformer = EntityToPrimaryKeyInputsTransformer.new(to: to_type.element_type)
|
45
|
+
element_type_declaration = transformer.from_type_declaration
|
46
|
+
|
47
|
+
to_type.declaration_data.merge(element_type_declaration:)
|
48
|
+
elsif to_type.extends?(Foobara::BuiltinTypes[:detached_entity])
|
49
|
+
declaration = to_type.target_class.primary_key_type.reference_or_declaration_data
|
50
|
+
|
51
|
+
description = "#{to_type.target_class.model_name} #{to_type.target_class.primary_key_attribute}"
|
52
|
+
|
53
|
+
unless to_type.extends_directly?(Foobara::BuiltinTypes[:detached_entity]) ||
|
54
|
+
to_type.extends_directly?(Foobara::BuiltinTypes[:entity])
|
55
|
+
description = [
|
56
|
+
description,
|
57
|
+
to_type.description
|
58
|
+
].join(" : ")
|
59
|
+
end
|
60
|
+
declaration[:description] = description
|
61
|
+
|
62
|
+
declaration
|
63
|
+
elsif to_type.extends?(Foobara::BuiltinTypes[:model])
|
64
|
+
attributes_type = to_type.target_class.attributes_type
|
65
|
+
EntityToPrimaryKeyInputsTransformer.new(to: attributes_type).from_type_declaration
|
66
|
+
else
|
67
|
+
# :nocov:
|
68
|
+
raise "Not sure how to handle #{to_type}"
|
69
|
+
# :nocov:
|
70
|
+
end
|
71
|
+
else
|
72
|
+
to_type
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def transform(inputs)
|
77
|
+
inputs
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def contains_associations_or_is_entity?(type)
|
83
|
+
DetachedEntity.contains_associations?(type) || type.extends?(Foobara::BuiltinTypes[:detached_entity])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -221,19 +221,29 @@ module Foobara
|
|
221
221
|
|
222
222
|
if type.extends?(BuiltinTypes[:detached_entity])
|
223
223
|
if initial
|
224
|
-
|
225
|
-
|
226
|
-
if remove_sensitive
|
227
|
-
# TODO: test this code path
|
228
|
-
# :nocov:
|
229
|
-
element_types = element_types&.reject(&:sensitive?)
|
230
|
-
# :nocov:
|
231
|
-
end
|
232
|
-
|
233
|
-
contains_associations?(element_types, false)
|
224
|
+
contains_associations?(type.element_types, false)
|
234
225
|
else
|
235
226
|
true
|
236
227
|
end
|
228
|
+
elsif type.extends?(BuiltinTypes[:model])
|
229
|
+
element_types = type.element_types
|
230
|
+
|
231
|
+
if remove_sensitive
|
232
|
+
# TODO: test this code path
|
233
|
+
# :nocov:
|
234
|
+
element_types = element_types&.reject(&:sensitive?)
|
235
|
+
# :nocov:
|
236
|
+
end
|
237
|
+
|
238
|
+
contains_associations?(element_types, false)
|
239
|
+
elsif type.extends?(BuiltinTypes[:tuple])
|
240
|
+
element_types = type.element_types
|
241
|
+
|
242
|
+
element_types&.any? do |element_type|
|
243
|
+
if !remove_sensitive || !element_type.sensitive?
|
244
|
+
contains_associations?(element_type, false)
|
245
|
+
end
|
246
|
+
end
|
237
247
|
elsif type.extends?(BuiltinTypes[:array])
|
238
248
|
# TODO: what to do about an associative array type?? Unclear how to make a key from that...
|
239
249
|
# TODO: raise if associative array contains a non-persisted record to handle this edge case for now.
|
data/projects/types/src/type.rb
CHANGED
@@ -232,6 +232,27 @@ module Foobara
|
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
+
def extends_directly?(type)
|
236
|
+
case type
|
237
|
+
when Type
|
238
|
+
base_type == type
|
239
|
+
when Symbol, String
|
240
|
+
concrete_type = created_in_namespace.foobara_lookup_type(type)
|
241
|
+
|
242
|
+
if concrete_type.nil?
|
243
|
+
# :nocov:
|
244
|
+
raise "No type found for #{type}"
|
245
|
+
# :nocov:
|
246
|
+
end
|
247
|
+
|
248
|
+
extends_directly?(concrete_type)
|
249
|
+
else
|
250
|
+
# :nocov:
|
251
|
+
raise ArgumentError, "Expected a Type or a Symbol/String, but got #{type.inspect}"
|
252
|
+
# :nocov:
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
235
256
|
def extends_type?(type)
|
236
257
|
return true if self == type
|
237
258
|
|
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.0.
|
4
|
+
version: 0.0.132
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- projects/command_connectors/src/serializers/yaml_serializer.rb
|
230
230
|
- projects/command_connectors/src/transformed_command.rb
|
231
231
|
- projects/command_connectors/src/transformers/auth_errors_transformer.rb
|
232
|
+
- projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb
|
232
233
|
- projects/command_connectors/src/transformers/load_aggregates_pre_commit_transformer.rb
|
233
234
|
- projects/command_connectors/src/transformers/load_delegated_attributes_entities_pre_commit_transformer.rb
|
234
235
|
- projects/common/lib/foobara/common.rb
|