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

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: acd95f1d6e58abba0e5c2498107a8a66d304fe3d79e96247c404c6a7fd55cb46
4
+ data.tar.gz: fdf0f9918b4c74941322ed5fdf3c750deaf47a1db6a4255475e3c980ec9f0862
5
5
  SHA512:
6
- metadata.gz: dfe94127bf3d4b42b0846282b3a036a6c7eee1769bd3c06c4b522984ac8ee4556b220471e3da023340d9b60821624f839e629d7609d37d4d51c83b0076a90d46
7
- data.tar.gz: 41e09f9b71898e73eeb2e8afc94f49aa909e37d8defc7f44454669471c9b925b130f3790e41338d1c23cfd5c2a71582a9e9a0ece77f1f0ba9250def19297950f
6
+ metadata.gz: 021b3c0a4c20daa2ba07a563b62aa2cf714e3108cab6d7441f875bbcd2cdee45e68eb5be99c17c0760993e245f065d7f40578c5997b5d0c35a251e590200f8dd
7
+ data.tar.gz: 27b3915c5fea3ef8770c26d16aff9ff4309cd3f031e4fd4a6bfd61f6fd81191defd7dad6e54e311a37825ade623ae4402b3c946ed1cbc5f99e97a0de9bd18173
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [1.2.1] - 2025-12-19
2
+
3
+ - Handle some foobara_delegate deprecation warnings
4
+
5
+ ## [1.2.0] - 2025-11-06
6
+
7
+ - If an attribute isn't required but has a default, it will have a non-required create
8
+ interface but a required read interface. This updates the types to reflect that for
9
+ convenience to avoid pointless null checks.
10
+
1
11
  ## [1.1.7] - 2025-11-02
2
12
 
3
13
  - Make CommandCastResultGenerator's interpretation of atom? match other generators
@@ -18,11 +18,13 @@ module Foobara
18
18
  @domain_generator ||= Services::DomainGenerator.new(domain)
19
19
  end
20
20
 
21
- foobara_delegate :organization_generator, :domain_name, :organization_name, to: :domain_generator
21
+ def organization_generator = domain_generator.organization_generator
22
+ def domain_name = domain_generator.domain_name
23
+ def organization_name = domain_generator.organization_name
22
24
 
23
25
  def errors_in_this_namespace
24
26
  @errors_in_this_namespace ||= possible_errors.values.map(&:error).uniq.sort_by(&:error_name).select do |error|
25
- error.parent&.path&.map(&:to_s) == path.map(&:to_s)
27
+ error.parent&.manifest_path&.map(&:to_s) == manifest_path.map(&:to_s)
26
28
  end.map do |error_manifest|
27
29
  Services::ErrorGenerator.new(error_manifest)
28
30
  end
@@ -70,7 +70,7 @@ module Foobara
70
70
  @organization_generator ||= OrganizationGenerator.new(domain_manifest.organization)
71
71
  end
72
72
 
73
- foobara_delegate :organization_name, to: :organization_generator
73
+ def organization_name = organization_generator.organization_name
74
74
  end
75
75
  end
76
76
  end
@@ -41,7 +41,9 @@ module Foobara
41
41
  end
42
42
 
43
43
  def context_type_declaration
44
- @context_type_declaration ||= Manifest::TypeDeclaration.new(root_manifest, [*path, :context_type_declaration])
44
+ @context_type_declaration ||= Manifest::TypeDeclaration.new(
45
+ root_manifest, [*manifest_path, :context_type_declaration]
46
+ )
45
47
  end
46
48
 
47
49
  def context_ts_type
@@ -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
@@ -153,9 +153,8 @@ module Foobara
153
153
  ts_instance_full_path
154
154
  end
155
155
 
156
- foobara_delegate :organization_name,
157
- :domain_name,
158
- to: :relevant_manifest
156
+ def organization_name = relevant_manifest.organization_name
157
+ def domain_name = relevant_manifest.domain_name
159
158
 
160
159
  def import_path
161
160
  if import_path_array.size == 1
@@ -194,14 +193,19 @@ module Foobara
194
193
  end
195
194
  end
196
195
 
197
- # TODO: relocate this to a more reusable place
196
+ # is_output means the value came from elsewhere and is fully formed.
197
+ # This is helpful for specifying what is expected to be present. If this is provided,
198
+ # then things like attribute properties that have defaults will be considered
199
+ # required and present.
198
200
  def foobara_type_to_ts_type(
199
201
  type_declaration,
200
202
  dependency_group: self.dependency_group,
201
203
  name: nil,
202
204
  association_depth: AssociationDepth::AMBIGUOUS,
203
205
  initial: true,
204
- model_and_entity_free: false
206
+ model_and_entity_free: false,
207
+ is_output: false,
208
+ parent: nil
205
209
  )
206
210
  if type_declaration.is_a?(Manifest::Error)
207
211
  error_generator = generator_for(type_declaration)
@@ -213,7 +217,9 @@ module Foobara
213
217
  type_declaration,
214
218
  association_depth:,
215
219
  dependency_group:,
216
- model_and_entity_free:
220
+ model_and_entity_free:,
221
+ is_output:,
222
+ parent:
217
223
  )
218
224
 
219
225
  if type_declaration.has_attribute_declarations?
@@ -241,7 +247,8 @@ module Foobara
241
247
  association_depth:,
242
248
  dependency_group:,
243
249
  initial: false,
244
- model_and_entity_free:
250
+ model_and_entity_free:,
251
+ is_output:
245
252
  )
246
253
  "#{ts_type}[]"
247
254
  else
@@ -275,7 +282,9 @@ module Foobara
275
282
  association_depth:,
276
283
  dependency_group:,
277
284
  initial:,
278
- model_and_entity_free:
285
+ model_and_entity_free:,
286
+ is_output:,
287
+ parent: model_type
279
288
  )
280
289
  else
281
290
  model_to_ts_model_name(type_declaration, association_depth:, initial:)
@@ -310,20 +319,34 @@ module Foobara
310
319
  attributes,
311
320
  dependency_group:,
312
321
  association_depth: AssociationDepth::AMBIGUOUS,
313
- model_and_entity_free: false
322
+ model_and_entity_free: false,
323
+ is_output: false,
324
+ parent: nil
314
325
  )
315
326
  # TODO: if we don't actually have attribute_declarations because we
316
327
  # are trying to express attributes of any type, then we want Record<string, any>
317
328
  # or something.
318
329
  if attributes.has_attribute_declarations?
319
330
  guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
320
- " #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
331
+ is_required = attributes.required?(attribute_name)
332
+
333
+ if !is_required && is_output
334
+ default = attributes.default_for(attribute_name)
335
+
336
+ if default || default == false ||
337
+ (parent&.detached_entity? && attribute_name == parent.primary_key_name.to_sym)
338
+ is_required = true
339
+ end
340
+ end
341
+
342
+ " #{attribute_name}#{"?" unless is_required}: #{
321
343
  foobara_type_to_ts_type(
322
344
  attribute_declaration,
323
345
  dependency_group:,
324
346
  association_depth:,
325
347
  initial: false,
326
- model_and_entity_free:
348
+ model_and_entity_free:,
349
+ is_output:
327
350
  )
328
351
  }"
329
352
  end.join("\n")
@@ -370,12 +393,15 @@ module Foobara
370
393
  dependency_group.non_colliding_type(generator)
371
394
  end
372
395
 
396
+ # Files generator checks that the relevant_manifest is the same but this is faster
373
397
  def ==(other)
374
- self.class == other.class && path == other.path && root_manifest == other.root_manifest
398
+ self.class == other.class &&
399
+ manifest_path == other.manifest_path &&
400
+ root_manifest == other.root_manifest
375
401
  end
376
402
 
377
403
  def hash
378
- path.hash
404
+ manifest_path.hash
379
405
  end
380
406
 
381
407
  def path_to_root
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi