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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e9da9e5402f377488227d8a3d9911e0b5aaecb17c377e7209668993fcac7580
4
- data.tar.gz: 7910689c819504d3d902ee61b433f1b10765c67b75f24cfad052f55141a89c8f
3
+ metadata.gz: 4b6ba29a2e9cc4baa0b854c2af01f8f9765d784d731f71a27d664c09280050c2
4
+ data.tar.gz: 13e3647fdf41efa57db365b7b2ecb652691491cc720dc605548820e0883f0c60
5
5
  SHA512:
6
- metadata.gz: fd073a89e550986306bcf2ba57d2cb5c7bf7b13e0d3c244517e09223b9106000c429cec615e4f985359f6548c7aca8b3533e7bf0f4e53dd777228a4bb999367b
7
- data.tar.gz: 36dd52e22fbaf4c2cc193fa67ac7a7de8126e75b950a4850e9c1d896bf7e814ba4eb8b4b4936879d8cf8d508e5584153ccedad726834e13a76c6a9a6d55f1e44
6
+ metadata.gz: c6abab21d2187b784d2cf1887c9b5e7d48b11d440819e4215215f37f5ef9c4ea3df0dd6daa79be1a07733440915b26c62bf340ad16c78b4d93617557d834193b
7
+ data.tar.gz: 47ce45d8450081c5fc6029f7dc9df67c968103a7e40edda520d2a263452e014cfa54d3123f35ab346002d1bdf490c792ef8419b5cf917f09d47898254c9090f1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.2.7] - 2026-02-16
2
+
3
+ - Make generated castJsonResult.ts files undefined-safe
4
+
1
5
  ## [1.2.6] - 2026-02-16
2
6
 
3
7
  - Make use of guaranteed_to_exist to avoid marking present delegates as optional
@@ -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 codepath or delete it
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}.#{path_part}")
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}.#{path_part}")
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}.#{path_part}")
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}.#{$1}"
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
- if type_symbol == :date || type_symbol == :datetime
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
- "#{lvalue} = new #{ts_model_name}(#{value})"
196
- else
197
- # :nocov:
198
- raise "Not sure how to cast type #{type} to a Typescript expression"
199
- # :nocov:
200
- end
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi