foobara-typescript-remote-command-generator 0.0.17 → 0.0.19
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 +4 -4
- data/CHANGELOG.md +10 -1
- data/src/remote_generator/services/command_inputs_generator.rb +27 -1
- data/src/remote_generator/services/command_result_generator.rb +2 -2
- data/src/remote_generator/services/typescript_from_manifest_base_generator.rb +42 -6
- data/templates/Command/Inputs.ts.erb +1 -1
- data/templates/Entity/Ambiguous.ts.erb +0 -1
- data/templates/base/Entity.ts +4 -0
- data/templates/base/Model.ts +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc51a16bfdbedc2c4d5a9f37d387c88a40bffe9b6c53354eb92a0c72d08b8a6
|
4
|
+
data.tar.gz: 51ad94eefd521eae56c332c6893c15dc5773e6536d0f009561f1f8670ac35d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f932745cf47d642490dc4ec1d45c76e89a80d0600e72dd5b3e45a87d58f8b242c0d7683679982588f8d6685f6c28486a8786722217e1f6c664debba9fd4fc0f7
|
7
|
+
data.tar.gz: 563901c212a0c14ff26b7b24b5aa50b2a518b4c63358bf50927b8806c7197503deda60e391d14c20255b3402da26955e4a7e5292c03db211d59152e187310baf
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
## [0.0.19] - 2025-04-25
|
2
|
+
|
3
|
+
- Fix bugs causing issues with generating command inputs for entities or custom types
|
4
|
+
|
5
|
+
## [0.0.18] - 2025-04-15
|
6
|
+
|
7
|
+
- Don't make use of Model/Entity in input types
|
8
|
+
- Add toJSON methods to Model and Entity for proper serialization when building inputs
|
9
|
+
|
1
10
|
## [0.0.17] - 2025-04-08
|
2
11
|
|
3
|
-
-
|
12
|
+
- Handle undefined/empty inputs in Inputs.ts.erb
|
4
13
|
|
5
14
|
## [0.0.16] - 2025-03-31
|
6
15
|
|
@@ -14,8 +14,34 @@ 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(types_to_consider = inputs_types_depended_on)
|
24
|
+
types = []
|
25
|
+
|
26
|
+
types_to_consider.each do |type|
|
27
|
+
if type.is_a?(Manifest::TypeDeclaration)
|
28
|
+
type = type.to_type
|
29
|
+
end
|
30
|
+
|
31
|
+
if type.detached_entity?
|
32
|
+
types += model_and_entity_free_types_depended_on([type.primary_key_type])
|
33
|
+
elsif type.model?
|
34
|
+
types += model_and_entity_free_types_depended_on(type.types_depended_on)
|
35
|
+
elsif !type.builtin?
|
36
|
+
types << type
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
types
|
41
|
+
end
|
42
|
+
|
17
43
|
def type_generators
|
18
|
-
@type_generators ||=
|
44
|
+
@type_generators ||= model_and_entity_free_types_depended_on.uniq.map do |type|
|
19
45
|
TypeGenerator.new(type)
|
20
46
|
end
|
21
47
|
end
|
@@ -29,7 +29,7 @@ module Foobara
|
|
29
29
|
elsif aggregate?
|
30
30
|
AggregateEntityGenerator
|
31
31
|
else
|
32
|
-
|
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
|
-
|
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(
|
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
|
-
|
251
|
+
if model_and_entity_free
|
252
|
+
model_type = type_declaration.to_type
|
253
|
+
|
254
|
+
translated_type = if type_declaration.detached_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(
|
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(
|
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
|
data/templates/base/Entity.ts
CHANGED
data/templates/base/Model.ts
CHANGED
@@ -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.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
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.
|
135
|
+
rubygems_version: 3.6.8
|
136
136
|
specification_version: 4
|
137
137
|
summary: Generates remote commands for Typescript from a foobara manifest
|
138
138
|
test_files: []
|