foobara-typescript-remote-command-generator 0.0.24 → 1.0.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: 46c714c0eb18fde6fcf73ce38aaa8b3f561bf5801f63eb080ac134cb92a46cb4
4
- data.tar.gz: 249bf1a42385f4eee8c35400c92681c558dcb4ff088c7c8a1619809d2477e9b2
3
+ metadata.gz: 2b714e6eec1090af9247514d151a2e72e4a9577d17c3adbde2e15964ae1bd18c
4
+ data.tar.gz: a200de6d84262582fe8a2e79df98c04142e6a01fe1932e11341082d6d49d3c06
5
5
  SHA512:
6
- metadata.gz: 9784818a6ac63aab255b0e186fe0ff826cf355e5ebb753255abf2e2b6ea13c64b1836aa6e9e4f510f7948ed4eb2eccf2f6bac766e575c6c2ea2249785ac82778
7
- data.tar.gz: 271b4bbf8db8affb1c1e782428d3ae0282d526598027995593c12b0c141300a4d4e9097e9d7b19cf5adeece2fef31447ad62336ac641c15be935c25a98c6dbb1
6
+ metadata.gz: 9c2eb881fe792592c5ed08cff88cf9b20d797fdb4ca08fbae5e416a9243a7d4d3d5505d1b744148d48d3fd64a629d3d7922c07262b393d14e2bfa8e6d74ac787
7
+ data.tar.gz: edc6d812189f61711f968f8d317dd79ef44e1ad51db573e059f0cdc5777c1da35b2693fc19b586c2b8bfe5309ab3fb030847a3ad130d3abeff8f814c9cbbbf60
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [1.0.0] - 2025-07-31
2
+
3
+ - Create never types for Error/PossibleErrors when command cannot error
4
+ - Support built-in non-extended attributes type
5
+
1
6
  ## [0.0.24] - 2025-05-14
2
7
 
3
8
  - Fix bugs with setup.ts
@@ -15,6 +15,10 @@ module Foobara
15
15
  "Command/Errors.ts.erb"
16
16
  end
17
17
 
18
+ def has_possible_errors?
19
+ error_generators.any?
20
+ end
21
+
18
22
  def error_generators
19
23
  @error_generators ||= possible_errors.values.map(&:error).sort_by(&:error_name).uniq.map do |error|
20
24
  Services::ErrorGenerator.new(error)
@@ -22,6 +26,8 @@ module Foobara
22
26
  end
23
27
 
24
28
  def error_type_union
29
+ return "never" unless has_possible_errors?
30
+
25
31
  error_generators.map do |error_generator|
26
32
  dependency_group.non_colliding_type(error_generator)
27
33
  end.join(" |\n ")
@@ -216,15 +216,23 @@ module Foobara
216
216
  model_and_entity_free:
217
217
  )
218
218
 
219
- is_empty = type_declaration.attribute_declarations.empty?
219
+ if type_declaration.has_attribute_declarations?
220
+ is_empty = type_declaration.attribute_declarations.empty?
220
221
 
221
- if name
222
- # TODO: test this code path or delete it
222
+ if name
223
+ # TODO: test this code path or delete it
224
+ # :nocov:
225
+ return is_empty ? "undefined" : "interface #{name} #{ts_type}"
226
+ # :nocov:
227
+ else
228
+ is_empty ? "undefined" : ts_type
229
+ end
230
+ else
231
+ # TODO: test this path with an :attributes type (not extended from :attributes but
232
+ # the built-in type itself directly)
223
233
  # :nocov:
224
- return is_empty ? "undefined" : "interface #{name} #{ts_type}"
234
+ ts_type
225
235
  # :nocov:
226
- else
227
- is_empty ? "undefined" : ts_type
228
236
  end
229
237
  elsif type_declaration.is_a?(Manifest::Array)
230
238
  # TODO: which association_depth do we pass here?
@@ -287,7 +295,8 @@ module Foobara
287
295
  type_string = "#{type_string} | null"
288
296
  end
289
297
 
290
- name ? "#{name} = #{type_string}" : type_string
298
+ # TODO: Add description as a comment?
299
+ name ? "type #{name} = #{type_string}" : type_string
291
300
  else
292
301
  # :nocov:
293
302
  raise "Not sure how to convert #{type_declaration} to a TS type"
@@ -301,8 +310,12 @@ module Foobara
301
310
  association_depth: AssociationDepth::AMBIGUOUS,
302
311
  model_and_entity_free: false
303
312
  )
304
- guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
305
- " #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
313
+ # TODO: if we don't actually have attribute_declarations because we
314
+ # are trying to express attributes of any type, then we want Record<string, any>
315
+ # or something.
316
+ if attributes.has_attribute_declarations?
317
+ guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
318
+ " #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
306
319
  foobara_type_to_ts_type(
307
320
  attribute_declaration,
308
321
  dependency_group:,
@@ -311,9 +324,16 @@ module Foobara
311
324
  model_and_entity_free:
312
325
  )
313
326
  }"
314
- end.join("\n")
327
+ end.join("\n")
315
328
 
316
- "{\n#{guts}\n}"
329
+ "{\n#{guts}\n}"
330
+ else
331
+ # TODO: test this path with an :attributes type (not extended from :attributes but
332
+ # the built-in type itself directly)
333
+ # :nocov:
334
+ "Record<string, any>"
335
+ # :nocov:
336
+ end
317
337
  end
318
338
 
319
339
  def model_to_ts_model_name(model, association_depth: AssociationDepth::AMBIGUOUS, initial: true)
@@ -2,10 +2,14 @@
2
2
  import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
3
3
  <% end %>
4
4
 
5
+ <% if has_possible_errors? %>
5
6
  export interface PossibleErrors {
6
7
  <% possible_errors.keys.sort.each do |key| %>
7
8
  "<%= key %>": <%= foobara_type_to_ts_type(possible_errors[key].error, dependency_group:) %>,
8
9
  <% end %>
9
10
  }
11
+ <% else %>
12
+ export type PossibleErrors = Record<never, never>
13
+ <% end %>
10
14
 
11
15
  export type Error = <%= error_type_union %>
metadata CHANGED
@@ -1,28 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2025-08-01 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara-files-generator
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - "<"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.1
18
+ version: 2.0.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - "<"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.1
25
+ version: 2.0.0
26
26
  email:
27
27
  - azimux@gmail.com
28
28
  executables: []
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.6.7
141
+ rubygems_version: 3.6.2
142
142
  specification_version: 4
143
143
  summary: Generates remote commands for Typescript from a foobara manifest
144
144
  test_files: []