foobara-typescript-remote-command-generator 0.0.17 → 0.0.18

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: 0edeec83ef5a6e8fdd8f4b0bf8352c0791a593386aec53f70724d3437b7b3b13
4
- data.tar.gz: c80f2d935699af9c03f0af3e0db70e9f411299d8017790cd78ae865fe21573eb
3
+ metadata.gz: e1dd99a53687e32719ab1a6319b82b07cb180740b42083d7ae2201b9bdc900b8
4
+ data.tar.gz: b8258124ee94a323e03b278b29b3c89d137d68cc86e819c23c7f575a12442989
5
5
  SHA512:
6
- metadata.gz: acb79c060d229a21d77a0962f72e6ce30adadd7a513ab061725d3fde6a60a414bf0fd5b917d48df58ecaf0012290d6021886ddcf3a11913f9ed798bff2018d63
7
- data.tar.gz: caea17f1356db403b37e29bc6edeefea58107e94b57f3d4bc19987ae9c1b112e506f3248c1468cbb07746947604f0a95a68368380d2633e9e835b00d2dba3d96
6
+ metadata.gz: 34d492c9189a229145a184607896e6154260a0ea5a924a59f4b0ce0434d7cf21dc984580c573ab75a85c9d69f045df21c22b40890f8ba9ef91198862fe3a3554
7
+ data.tar.gz: bd54735d7293ea6a57519d22bdc44ce48f26afbac98e688124bb896864230dc5df0824b7eae11b3919741aa8ff7c3a75a31cf19728d76e3dd9aa47367dd8d96e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ ## [0.0.18] - 2025-04-15
2
+
3
+ - Don't make use of Model/Entity in input types
4
+ - Add toJSON methods to Model and Entity for proper serialization when building inputs
5
+
1
6
  ## [0.0.17] - 2025-04-08
2
7
 
3
- -
8
+ - Handle undefined/empty inputs in Inputs.ts.erb
4
9
 
5
10
  ## [0.0.16] - 2025-03-31
6
11
 
@@ -14,8 +14,18 @@ module Foobara
14
14
  "Command/Inputs.ts.erb"
15
15
  end
16
16
 
17
+ # TODO: we should break the various TypeScript WhateverAttributesType and
18
+ # WhateverPrimaryKeyType into separate generators with separate templates so
19
+ # we can use those types instead of constructing new types from the attributes/primary keys
20
+ # of models/entities.
21
+ # Instead, for now, we will just translate input types to not have entities/models
22
+ # by converting models to their attributes and entities to their primary keys.
23
+ def model_and_entity_free_types_depended_on
24
+ inputs_types_depended_on.reject { |type| type.model? || type.entity? }.reject(&:builtin?).uniq
25
+ end
26
+
17
27
  def type_generators
18
- @type_generators ||= inputs_types_depended_on.reject(&:builtin?).uniq.map do |type|
28
+ @type_generators ||= model_and_entity_free_types_depended_on.uniq.map do |type|
19
29
  TypeGenerator.new(type)
20
30
  end
21
31
  end
@@ -29,7 +29,7 @@ module Foobara
29
29
  elsif aggregate?
30
30
  AggregateEntityGenerator
31
31
  else
32
- EntityGenerator
32
+ TypeGenerator
33
33
  end
34
34
 
35
35
  entity = if type.entity?
@@ -45,7 +45,7 @@ module Foobara
45
45
  elsif aggregate?
46
46
  AggregateModelGenerator
47
47
  else
48
- ModelGenerator
48
+ TypeGenerator
49
49
  end
50
50
 
51
51
  [generator_class.new(type.to_model)]
@@ -195,7 +195,8 @@ module Foobara
195
195
  dependency_group: self.dependency_group,
196
196
  name: nil,
197
197
  association_depth: AssociationDepth::AMBIGUOUS,
198
- initial: true
198
+ initial: true,
199
+ model_and_entity_free: false
199
200
  )
200
201
  if type_declaration.is_a?(Manifest::Error)
201
202
  error_generator = generator_for(type_declaration)
@@ -203,7 +204,12 @@ module Foobara
203
204
  end
204
205
 
205
206
  type_string = if type_declaration.is_a?(Manifest::Attributes)
206
- ts_type = attributes_to_ts_type(type_declaration, association_depth:, dependency_group:)
207
+ ts_type = attributes_to_ts_type(
208
+ type_declaration,
209
+ association_depth:,
210
+ dependency_group:,
211
+ model_and_entity_free:
212
+ )
207
213
 
208
214
  is_empty = type_declaration.attribute_declarations.empty?
209
215
 
@@ -221,7 +227,8 @@ module Foobara
221
227
  type_declaration.element_type,
222
228
  association_depth:,
223
229
  dependency_group:,
224
- initial: false
230
+ initial: false,
231
+ model_and_entity_free:
225
232
  )
226
233
  "#{ts_type}[]"
227
234
  else
@@ -241,7 +248,25 @@ module Foobara
241
248
  "Date"
242
249
  else
243
250
  if type_declaration.model?
244
- model_to_ts_model_name(type_declaration, association_depth:, initial:)
251
+ if model_and_entity_free
252
+ model_type = type_declaration.to_type
253
+
254
+ translated_type = if type_declaration.entity?
255
+ model_type.primary_key_type
256
+ else
257
+ model_type.attributes_type
258
+ end
259
+
260
+ foobara_type_to_ts_type(
261
+ translated_type,
262
+ association_depth:,
263
+ dependency_group:,
264
+ initial:,
265
+ model_and_entity_free:
266
+ )
267
+ else
268
+ model_to_ts_model_name(type_declaration, association_depth:, initial:)
269
+ end
245
270
  elsif type_declaration.custom?
246
271
  custom_type_to_ts_type_name(type_declaration)
247
272
  end
@@ -265,10 +290,21 @@ module Foobara
265
290
  end
266
291
  end
267
292
 
268
- def attributes_to_ts_type(attributes, dependency_group:, association_depth: AssociationDepth::AMBIGUOUS)
293
+ def attributes_to_ts_type(
294
+ attributes,
295
+ dependency_group:,
296
+ association_depth: AssociationDepth::AMBIGUOUS,
297
+ model_and_entity_free: false
298
+ )
269
299
  guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
270
300
  " #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
271
- foobara_type_to_ts_type(attribute_declaration, dependency_group:, association_depth:, initial: false)
301
+ foobara_type_to_ts_type(
302
+ attribute_declaration,
303
+ dependency_group:,
304
+ association_depth:,
305
+ initial: false,
306
+ model_and_entity_free:
307
+ )
272
308
  }"
273
309
  end.join("\n")
274
310
 
@@ -2,6 +2,6 @@
2
2
  import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
3
3
  <% end %>
4
4
 
5
- type Inputs = <%= foobara_type_to_ts_type(inputs_type, dependency_group:) %>
5
+ type Inputs = <%= foobara_type_to_ts_type(inputs_type, dependency_group:, model_and_entity_free: true) %>
6
6
 
7
7
  export default Inputs
@@ -26,5 +26,4 @@ export class <%= entity_short_name %><
26
26
  return this.readAttribute("<%= attribute_name %>")
27
27
  }
28
28
  <% end %>
29
-
30
29
  }
@@ -84,4 +84,8 @@ export abstract class Entity<PrimaryKeyType extends EntityPrimaryKeyType, Attrib
84
84
 
85
85
  return this._attributes
86
86
  }
87
+
88
+ override toJSON (): unknown {
89
+ return this.primaryKey
90
+ }
87
91
  }
@@ -21,4 +21,8 @@ export abstract class Model<AttributesType> {
21
21
  readAttribute<T extends keyof this["_attributes"]>(attributeName: T): this["_attributes"][T] {
22
22
  return (this.attributes as unknown as this["_attributes"])[attributeName]
23
23
  }
24
+
25
+ toJSON (): unknown {
26
+ return this._attributes
27
+ }
24
28
  }
metadata CHANGED
@@ -1,13 +1,13 @@
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.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara-files-generator
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.6.2
135
+ rubygems_version: 3.6.7
136
136
  specification_version: 4
137
137
  summary: Generates remote commands for Typescript from a foobara manifest
138
138
  test_files: []