foobara-typescript-remote-command-generator 1.1.7 → 1.2.0

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: 7f320bbabd5ddca46562061c2824136049cdb2527db04dcc12a158faacf976ee
4
- data.tar.gz: 0dd1e7ede3eb687061654c2a69be0e666558aaac109ad6965cb1d48b23f6e996
3
+ metadata.gz: 9f783af32070cfcdc33c70d34c1b755a66a0a6bb3df7b7e8697345bdc1d148f7
4
+ data.tar.gz: fdcfa71700d34b3c42163b586fc2f8cb1c90f420bef3fb76f7a8a5a8d29e6423
5
5
  SHA512:
6
- metadata.gz: dfe94127bf3d4b42b0846282b3a036a6c7eee1769bd3c06c4b522984ac8ee4556b220471e3da023340d9b60821624f839e629d7609d37d4d51c83b0076a90d46
7
- data.tar.gz: 41e09f9b71898e73eeb2e8afc94f49aa909e37d8defc7f44454669471c9b925b130f3790e41338d1c23cfd5c2a71582a9e9a0ece77f1f0ba9250def19297950f
6
+ metadata.gz: b5b5d35cc80f88622f2a4ea321574a7af55e9c61ec7bde32d42761a9d9511af07ced97894f4905962bb1803c1871d9a8ab4c9c83722df5caefffe7342b90e474
7
+ data.tar.gz: 6d0a1fcb787dc719a330bd58953d42e387f931b35a2eb3d6168ab0d0dfbdec166a1f2215339ea7046b3edfc00473365cdca75e6846408014ed96a3f04d6ef3d8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [1.2.0] - 2025-11-06
2
+
3
+ - If an attribute isn't required but has a default, it will have a non-required create
4
+ interface but a required read interface. This updates the types to reflect that for
5
+ convenience to avoid pointless null checks.
6
+
1
7
  ## [1.1.7] - 2025-11-02
2
8
 
3
9
  - Make CommandCastResultGenerator's interpretation of atom? match other generators
@@ -120,17 +120,29 @@ module Foobara
120
120
 
121
121
  def attributes_type_ts_type
122
122
  association_depth = AssociationDepth::AMBIGUOUS
123
- foobara_type_to_ts_type(attributes_type, association_depth:, dependency_group:)
123
+ foobara_type_to_ts_type(attributes_type,
124
+ association_depth:,
125
+ dependency_group:,
126
+ is_output: true,
127
+ parent: relevant_manifest)
124
128
  end
125
129
 
126
130
  def atom_attributes_ts_type
127
131
  association_depth = AssociationDepth::ATOM
128
- foobara_type_to_ts_type(attributes_type, association_depth:, dependency_group:)
132
+ foobara_type_to_ts_type(attributes_type,
133
+ association_depth:,
134
+ dependency_group:,
135
+ is_output: true,
136
+ parent: relevant_manifest)
129
137
  end
130
138
 
131
139
  def aggregate_attributes_ts_type
132
140
  association_depth = AssociationDepth::AGGREGATE
133
- foobara_type_to_ts_type(attributes_type, association_depth:, dependency_group:)
141
+ foobara_type_to_ts_type(attributes_type,
142
+ association_depth:,
143
+ dependency_group:,
144
+ is_output: true,
145
+ parent: relevant_manifest)
134
146
  end
135
147
 
136
148
  def attribute_names
@@ -194,14 +194,19 @@ module Foobara
194
194
  end
195
195
  end
196
196
 
197
- # TODO: relocate this to a more reusable place
197
+ # is_output means the value came from elsewhere and is fully formed.
198
+ # This is helpful for specifying what is expected to be present. If this is provided,
199
+ # then things like attribute properties that have defaults will be considered
200
+ # required and present.
198
201
  def foobara_type_to_ts_type(
199
202
  type_declaration,
200
203
  dependency_group: self.dependency_group,
201
204
  name: nil,
202
205
  association_depth: AssociationDepth::AMBIGUOUS,
203
206
  initial: true,
204
- model_and_entity_free: false
207
+ model_and_entity_free: false,
208
+ is_output: false,
209
+ parent: nil
205
210
  )
206
211
  if type_declaration.is_a?(Manifest::Error)
207
212
  error_generator = generator_for(type_declaration)
@@ -213,7 +218,9 @@ module Foobara
213
218
  type_declaration,
214
219
  association_depth:,
215
220
  dependency_group:,
216
- model_and_entity_free:
221
+ model_and_entity_free:,
222
+ is_output:,
223
+ parent:
217
224
  )
218
225
 
219
226
  if type_declaration.has_attribute_declarations?
@@ -241,7 +248,8 @@ module Foobara
241
248
  association_depth:,
242
249
  dependency_group:,
243
250
  initial: false,
244
- model_and_entity_free:
251
+ model_and_entity_free:,
252
+ is_output:
245
253
  )
246
254
  "#{ts_type}[]"
247
255
  else
@@ -275,7 +283,9 @@ module Foobara
275
283
  association_depth:,
276
284
  dependency_group:,
277
285
  initial:,
278
- model_and_entity_free:
286
+ model_and_entity_free:,
287
+ is_output:,
288
+ parent: model_type
279
289
  )
280
290
  else
281
291
  model_to_ts_model_name(type_declaration, association_depth:, initial:)
@@ -310,20 +320,34 @@ module Foobara
310
320
  attributes,
311
321
  dependency_group:,
312
322
  association_depth: AssociationDepth::AMBIGUOUS,
313
- model_and_entity_free: false
323
+ model_and_entity_free: false,
324
+ is_output: false,
325
+ parent: nil
314
326
  )
315
327
  # TODO: if we don't actually have attribute_declarations because we
316
328
  # are trying to express attributes of any type, then we want Record<string, any>
317
329
  # or something.
318
330
  if attributes.has_attribute_declarations?
319
331
  guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
320
- " #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
332
+ is_required = attributes.required?(attribute_name)
333
+
334
+ if !is_required && is_output
335
+ default = attributes.default_for(attribute_name)
336
+
337
+ if default || default == false ||
338
+ (parent&.detached_entity? && attribute_name == parent.primary_key_name.to_sym)
339
+ is_required = true
340
+ end
341
+ end
342
+
343
+ " #{attribute_name}#{"?" unless is_required}: #{
321
344
  foobara_type_to_ts_type(
322
345
  attribute_declaration,
323
346
  dependency_group:,
324
347
  association_depth:,
325
348
  initial: false,
326
- model_and_entity_free:
349
+ model_and_entity_free:,
350
+ is_output:
327
351
  )
328
352
  }"
329
353
  end.join("\n")
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.1.7
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi