foobara-typescript-remote-command-generator 1.1.6 → 1.1.7
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 +4 -0
- data/src/remote_generator/services/command_cast_result_generator.rb +53 -56
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f320bbabd5ddca46562061c2824136049cdb2527db04dcc12a158faacf976ee
|
|
4
|
+
data.tar.gz: 0dd1e7ede3eb687061654c2a69be0e666558aaac109ad6965cb1d48b23f6e996
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfe94127bf3d4b42b0846282b3a036a6c7eee1769bd3c06c4b522984ac8ee4556b220471e3da023340d9b60821624f839e629d7609d37d4d51c83b0076a90d46
|
|
7
|
+
data.tar.gz: 41e09f9b71898e73eeb2e8afc94f49aa909e37d8defc7f44454669471c9b925b130f3790e41338d1c23cfd5c2a71582a9e9a0ece77f1f0ba9250def19297950f
|
data/CHANGELOG.md
CHANGED
|
@@ -5,12 +5,12 @@ module Foobara
|
|
|
5
5
|
class Services
|
|
6
6
|
class CommandCastResultGenerator < CommandResultGenerator
|
|
7
7
|
class CastTree
|
|
8
|
-
attr_accessor :children, :declaration_to_cast, :
|
|
8
|
+
attr_accessor :children, :declaration_to_cast, :initial
|
|
9
9
|
|
|
10
|
-
def initialize(children: nil, declaration_to_cast: nil,
|
|
10
|
+
def initialize(children: nil, declaration_to_cast: nil, initial: false)
|
|
11
11
|
self.children = children
|
|
12
12
|
self.declaration_to_cast = declaration_to_cast
|
|
13
|
-
self.
|
|
13
|
+
self.initial = initial
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def empty?
|
|
@@ -41,31 +41,30 @@ module Foobara
|
|
|
41
41
|
|
|
42
42
|
nested_model_generators = []
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else
|
|
54
|
-
Services::AtomModelGenerator
|
|
55
|
-
end
|
|
56
|
-
elsif aggregate?
|
|
57
|
-
Services::AggregateModelGenerator
|
|
44
|
+
if result_type.detached_entity? && atom?
|
|
45
|
+
declaration = result_type.is_a?(Manifest::TypeDeclaration) ? result_type.to_type : result_type
|
|
46
|
+
return @nested_model_generators = Set[Services::AtomEntityGenerator.new(declaration)]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
_models_reachable_from_declaration(result_type, initial: true)&.each do |model|
|
|
50
|
+
generator_class = if atom?
|
|
51
|
+
if model.detached_entity?
|
|
52
|
+
Services::UnloadedEntityGenerator
|
|
58
53
|
else
|
|
59
|
-
Services::
|
|
54
|
+
Services::AtomModelGenerator
|
|
60
55
|
end
|
|
56
|
+
elsif aggregate?
|
|
57
|
+
Services::AggregateModelGenerator
|
|
58
|
+
else
|
|
59
|
+
Services::ModelGenerator
|
|
60
|
+
end
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
new_generator = generator_class.new(model)
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
end
|
|
64
|
+
unless nested_model_generators.any? do |g|
|
|
65
|
+
g.relevant_manifest == model && g.class == new_generator.class
|
|
66
|
+
end
|
|
67
|
+
nested_model_generators << new_generator
|
|
69
68
|
end
|
|
70
69
|
end
|
|
71
70
|
|
|
@@ -81,7 +80,7 @@ module Foobara
|
|
|
81
80
|
end
|
|
82
81
|
|
|
83
82
|
def dependencies
|
|
84
|
-
|
|
83
|
+
nested_model_generators
|
|
85
84
|
end
|
|
86
85
|
|
|
87
86
|
def cast_json_result_function
|
|
@@ -92,7 +91,7 @@ module Foobara
|
|
|
92
91
|
|
|
93
92
|
# TODO: need to make use of initial?
|
|
94
93
|
def cast_json_result_function_body(
|
|
95
|
-
cast_tree = _construct_cast_tree(result_type),
|
|
94
|
+
cast_tree = _construct_cast_tree(result_type, initial: true),
|
|
96
95
|
parent: "json",
|
|
97
96
|
property: nil,
|
|
98
97
|
value: parent
|
|
@@ -189,8 +188,9 @@ module Foobara
|
|
|
189
188
|
if type_symbol == :date || type_symbol == :datetime
|
|
190
189
|
"#{lvalue} = new Date(#{value})"
|
|
191
190
|
elsif type.model?
|
|
192
|
-
ts_model_name = model_to_ts_model_name(type,
|
|
193
|
-
|
|
191
|
+
ts_model_name = model_to_ts_model_name(type,
|
|
192
|
+
association_depth:,
|
|
193
|
+
initial: cast_tree.initial)
|
|
194
194
|
|
|
195
195
|
"#{lvalue} = new #{ts_model_name}(#{value})"
|
|
196
196
|
else
|
|
@@ -200,7 +200,7 @@ module Foobara
|
|
|
200
200
|
end
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
-
def _construct_cast_tree(type_declaration,
|
|
203
|
+
def _construct_cast_tree(type_declaration, initial: false)
|
|
204
204
|
if type_declaration.is_a?(Manifest::Attributes)
|
|
205
205
|
return unless type_declaration.has_attribute_declarations?
|
|
206
206
|
return if type_declaration.attribute_declarations.empty?
|
|
@@ -209,39 +209,39 @@ module Foobara
|
|
|
209
209
|
|
|
210
210
|
type_declaration.attribute_declarations.each_pair do |attribute_name, attribute_declaration|
|
|
211
211
|
if type_requires_cast?(attribute_declaration)
|
|
212
|
-
path_tree[attribute_name] = _construct_cast_tree(attribute_declaration
|
|
212
|
+
path_tree[attribute_name] = _construct_cast_tree(attribute_declaration)
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
215
|
|
|
216
216
|
unless path_tree.empty?
|
|
217
|
-
CastTree.new(children: path_tree,
|
|
217
|
+
CastTree.new(children: path_tree, initial:)
|
|
218
218
|
end
|
|
219
219
|
elsif type_declaration.is_a?(Manifest::Array)
|
|
220
220
|
element_type = type_declaration.element_type
|
|
221
221
|
|
|
222
222
|
if element_type && type_requires_cast?(element_type)
|
|
223
|
-
CastTree.new(children: { "#": _construct_cast_tree(element_type
|
|
223
|
+
CastTree.new(initial:, children: { "#": _construct_cast_tree(element_type) })
|
|
224
224
|
end
|
|
225
225
|
elsif type_declaration.type.to_sym == :date || type_declaration.type.to_sym == :datetime
|
|
226
|
-
CastTree.new(declaration_to_cast: type_declaration,
|
|
226
|
+
CastTree.new(declaration_to_cast: type_declaration, initial:)
|
|
227
227
|
elsif type_declaration.model?
|
|
228
228
|
type_declaration = type_declaration.to_type
|
|
229
229
|
|
|
230
230
|
children = if type_declaration.detached_entity? && atom?
|
|
231
231
|
nil
|
|
232
232
|
else
|
|
233
|
-
_construct_cast_tree(type_declaration.attributes_type
|
|
233
|
+
_construct_cast_tree(type_declaration.attributes_type)
|
|
234
234
|
end
|
|
235
235
|
|
|
236
|
-
CastTree.new(children:, declaration_to_cast: type_declaration,
|
|
236
|
+
CastTree.new(children:, declaration_to_cast: type_declaration, initial:)
|
|
237
237
|
# TODO: either test this code path or raise or delete it
|
|
238
238
|
# :nocov:
|
|
239
239
|
elsif type_declaration.custom?
|
|
240
240
|
if type_requires_cast?(type_declaration.base_type.to_type_declaration)
|
|
241
|
-
tree = _construct_cast_tree(type_declaration.base_type.to_type_declaration
|
|
241
|
+
tree = _construct_cast_tree(type_declaration.base_type.to_type_declaration)
|
|
242
242
|
|
|
243
243
|
if tree && !tree.empty?
|
|
244
|
-
CastTree.new(children: tree,
|
|
244
|
+
CastTree.new(children: tree, initial:)
|
|
245
245
|
end
|
|
246
246
|
end
|
|
247
247
|
end
|
|
@@ -249,7 +249,7 @@ module Foobara
|
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
# TODO: Feels like similar complicated logic is popping up in many places? How to find/converge such logic
|
|
252
|
-
def _models_reachable_from_declaration(type_declaration,
|
|
252
|
+
def _models_reachable_from_declaration(type_declaration, initial: false)
|
|
253
253
|
if type_declaration.is_a?(Manifest::Attributes)
|
|
254
254
|
return unless type_declaration.has_attribute_declarations?
|
|
255
255
|
return if type_declaration.attribute_declarations.empty?
|
|
@@ -258,13 +258,14 @@ module Foobara
|
|
|
258
258
|
|
|
259
259
|
type_declaration.attribute_declarations.each_value do |attribute_declaration|
|
|
260
260
|
if type_requires_cast?(attribute_declaration)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
261
|
+
additional = _models_reachable_from_declaration(attribute_declaration)
|
|
262
|
+
|
|
263
|
+
if additional
|
|
264
|
+
if models
|
|
265
|
+
models |= additional
|
|
266
|
+
else
|
|
267
|
+
models = additional
|
|
268
|
+
end
|
|
268
269
|
end
|
|
269
270
|
end
|
|
270
271
|
end
|
|
@@ -274,24 +275,23 @@ module Foobara
|
|
|
274
275
|
element_type = type_declaration.element_type
|
|
275
276
|
|
|
276
277
|
if element_type && type_requires_cast?(element_type)
|
|
277
|
-
_models_reachable_from_declaration(element_type
|
|
278
|
+
_models_reachable_from_declaration(element_type)
|
|
278
279
|
end
|
|
279
280
|
elsif type_declaration.model?
|
|
280
281
|
if type_declaration.is_a?(Manifest::TypeDeclaration)
|
|
281
282
|
type_declaration = type_declaration.to_type
|
|
282
283
|
end
|
|
283
284
|
|
|
284
|
-
models = Set[
|
|
285
|
+
models = Set[type_declaration]
|
|
285
286
|
|
|
286
287
|
if atom? && type_declaration.detached_entity?
|
|
287
288
|
return models
|
|
288
289
|
end
|
|
289
290
|
|
|
290
|
-
_models_reachable_from_declaration(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
models << pair
|
|
291
|
+
additional = _models_reachable_from_declaration(type_declaration.attributes_type)
|
|
292
|
+
|
|
293
|
+
if additional
|
|
294
|
+
models |= additional
|
|
295
295
|
end
|
|
296
296
|
|
|
297
297
|
models
|
|
@@ -299,10 +299,7 @@ module Foobara
|
|
|
299
299
|
# TODO: either test this code path or raise or delete it
|
|
300
300
|
# :nocov:
|
|
301
301
|
if type_requires_cast?(type_declaration.base_type.to_type_declaration)
|
|
302
|
-
_models_reachable_from_declaration(
|
|
303
|
-
type_declaration.base_type.to_type_declaration,
|
|
304
|
-
past_first_model:
|
|
305
|
-
)
|
|
302
|
+
_models_reachable_from_declaration(type_declaration.base_type.to_type_declaration)
|
|
306
303
|
end
|
|
307
304
|
# :nocov:
|
|
308
305
|
end
|