foobara-typescript-remote-command-generator 1.2.6 → 1.2.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 +27 -19
- 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: 4b6ba29a2e9cc4baa0b854c2af01f8f9765d784d731f71a27d664c09280050c2
|
|
4
|
+
data.tar.gz: 13e3647fdf41efa57db365b7b2ecb652691491cc720dc605548820e0883f0c60
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6abab21d2187b784d2cf1887c9b5e7d48b11d440819e4215215f37f5ef9c4ea3df0dd6daa79be1a07733440915b26c62bf340ad16c78b4d93617557d834193b
|
|
7
|
+
data.tar.gz: 47ce45d8450081c5fc6029f7dc9df67c968103a7e40edda520d2a263452e014cfa54d3123f35ab346002d1bdf490c792ef8419b5cf917f09d47898254c9090f1
|
data/CHANGELOG.md
CHANGED
|
@@ -116,24 +116,24 @@ module Foobara
|
|
|
116
116
|
value: "element")
|
|
117
117
|
result << "})"
|
|
118
118
|
elsif child_cast_tree.is_a?(::Hash)
|
|
119
|
-
# TODO: either test this
|
|
119
|
+
# TODO: either test this code path or delete it
|
|
120
120
|
# :nocov:
|
|
121
121
|
property = path_part =~ /\A\d+\z/ ? path_part.to_i : "\"#{path_part}\""
|
|
122
122
|
|
|
123
123
|
result << cast_json_result_function_body(child_cast_tree,
|
|
124
124
|
parent:,
|
|
125
125
|
property:,
|
|
126
|
-
value: "#{parent}
|
|
126
|
+
value: "#{parent}?.#{path_part}")
|
|
127
127
|
# :nocov:
|
|
128
128
|
elsif child_cast_tree.is_a?(CastTree)
|
|
129
129
|
result << cast_json_result_function_body(child_cast_tree.children,
|
|
130
|
-
parent: "#{parent}
|
|
130
|
+
parent: "#{parent}?.#{path_part}")
|
|
131
131
|
|
|
132
132
|
property = path_part =~ /\A\d+\z/ ? path_part.to_i : "\"#{path_part}\""
|
|
133
133
|
result << _ts_cast_expression(child_cast_tree,
|
|
134
134
|
parent:,
|
|
135
135
|
property:,
|
|
136
|
-
value: "#{parent}
|
|
136
|
+
value: "#{parent}?.#{path_part}")
|
|
137
137
|
else
|
|
138
138
|
# :nocov:
|
|
139
139
|
raise "Not sure how to handle a #{cast_tree.class}: #{cast_tree}"
|
|
@@ -164,9 +164,9 @@ module Foobara
|
|
|
164
164
|
if property.nil?
|
|
165
165
|
parent
|
|
166
166
|
elsif property =~ /\A"(.*)"\z/
|
|
167
|
-
"#{parent}
|
|
167
|
+
"#{parent}?.#{$1}"
|
|
168
168
|
else
|
|
169
|
-
"#{parent}[#{property}]"
|
|
169
|
+
"#{parent}?.[#{property}]"
|
|
170
170
|
end
|
|
171
171
|
else
|
|
172
172
|
# TODO: either test this path or raise
|
|
@@ -183,21 +183,29 @@ module Foobara
|
|
|
183
183
|
|
|
184
184
|
type_symbol = type.type_symbol
|
|
185
185
|
|
|
186
|
-
value ||= lvalue
|
|
186
|
+
value ||= lvalue.dup
|
|
187
|
+
lvalue = lvalue.gsub("?.[", "[").gsub("?.", ".")
|
|
188
|
+
present_value = value.gsub("?.[", "[").gsub("?.", ".")
|
|
187
189
|
|
|
188
|
-
|
|
189
|
-
"#{lvalue} = new Date(#{value})"
|
|
190
|
-
elsif type.model?
|
|
191
|
-
ts_model_name = model_to_ts_model_name(type,
|
|
192
|
-
association_depth:,
|
|
193
|
-
initial: cast_tree.initial)
|
|
190
|
+
expression = "if (#{value} !== undefined) {\n"
|
|
194
191
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
192
|
+
expression += if type_symbol == :date || type_symbol == :datetime
|
|
193
|
+
"#{lvalue} = new Date(#{present_value})"
|
|
194
|
+
elsif type.model?
|
|
195
|
+
ts_model_name = model_to_ts_model_name(type,
|
|
196
|
+
association_depth:,
|
|
197
|
+
initial: cast_tree.initial)
|
|
198
|
+
|
|
199
|
+
"#{lvalue} = new #{ts_model_name}(#{present_value})"
|
|
200
|
+
else
|
|
201
|
+
# :nocov:
|
|
202
|
+
raise "Not sure how to cast type #{type} to a Typescript expression"
|
|
203
|
+
# :nocov:
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
expression += "\n}"
|
|
207
|
+
|
|
208
|
+
expression
|
|
201
209
|
end
|
|
202
210
|
|
|
203
211
|
def _construct_cast_tree(type_declaration, initial: false)
|