foobara-typescript-remote-command-generator 0.0.16 → 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 +4 -4
- data/CHANGELOG.md +10 -1
- data/src/remote_generator/services/command_inputs_generator.rb +11 -1
- data/src/remote_generator/services/command_result_generator.rb +2 -2
- data/src/remote_generator/services/typescript_from_manifest_base_generator.rb +45 -6
- data/templates/Command/Inputs.ts.erb +3 -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 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1dd99a53687e32719ab1a6319b82b07cb180740b42083d7ae2201b9bdc900b8
|
4
|
+
data.tar.gz: b8258124ee94a323e03b278b29b3c89d137d68cc86e819c23c7f575a12442989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d492c9189a229145a184607896e6154260a0ea5a924a59f4b0ce0434d7cf21dc984580c573ab75a85c9d69f045df21c22b40890f8ba9ef91198862fe3a3554
|
7
|
+
data.tar.gz: bd54735d7293ea6a57519d22bdc44ce48f26afbac98e688124bb896864230dc5df0824b7eae11b3919741aa8ff7c3a75a31cf19728d76e3dd9aa47367dd8d96e
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
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
|
+
|
6
|
+
## [0.0.17] - 2025-04-08
|
7
|
+
|
8
|
+
- Handle undefined/empty inputs in Inputs.ts.erb
|
9
|
+
|
1
10
|
## [0.0.16] - 2025-03-31
|
2
11
|
|
3
|
-
- Add a bunch of special-case support for Foobara::Auth domain
|
12
|
+
- Add a bunch of special-case support for Foobara::Auth domain convenience
|
4
13
|
|
5
14
|
## [0.0.15] - 2025-03-30
|
6
15
|
|
@@ -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 ||=
|
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
|
-
|
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,12 +204,20 @@ 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
|
|
210
216
|
if name
|
217
|
+
# TODO: test this code path or delete it
|
218
|
+
# :nocov:
|
211
219
|
return is_empty ? "undefined" : "interface #{name} #{ts_type}"
|
220
|
+
# :nocov:
|
212
221
|
else
|
213
222
|
is_empty ? "undefined" : ts_type
|
214
223
|
end
|
@@ -218,7 +227,8 @@ module Foobara
|
|
218
227
|
type_declaration.element_type,
|
219
228
|
association_depth:,
|
220
229
|
dependency_group:,
|
221
|
-
initial: false
|
230
|
+
initial: false,
|
231
|
+
model_and_entity_free:
|
222
232
|
)
|
223
233
|
"#{ts_type}[]"
|
224
234
|
else
|
@@ -238,7 +248,25 @@ module Foobara
|
|
238
248
|
"Date"
|
239
249
|
else
|
240
250
|
if type_declaration.model?
|
241
|
-
|
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
|
242
270
|
elsif type_declaration.custom?
|
243
271
|
custom_type_to_ts_type_name(type_declaration)
|
244
272
|
end
|
@@ -262,10 +290,21 @@ module Foobara
|
|
262
290
|
end
|
263
291
|
end
|
264
292
|
|
265
|
-
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
|
+
)
|
266
299
|
guts = attributes.attribute_declarations.map do |attribute_name, attribute_declaration|
|
267
300
|
" #{attribute_name}#{"?" unless attributes.required?(attribute_name)}: #{
|
268
|
-
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
|
+
)
|
269
308
|
}"
|
270
309
|
end.join("\n")
|
271
310
|
|
@@ -2,4 +2,6 @@
|
|
2
2
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
3
3
|
<% end %>
|
4
4
|
|
5
|
-
|
5
|
+
type Inputs = <%= foobara_type_to_ts_type(inputs_type, dependency_group:, model_and_entity_free: true) %>
|
6
|
+
|
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,28 +1,14 @@
|
|
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.18
|
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
|
-
- !ruby/object:Gem::Dependency
|
13
|
-
name: foobara
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
-
requirements:
|
16
|
-
- - "~>"
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: 0.0.88
|
19
|
-
type: :runtime
|
20
|
-
prerelease: false
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
-
requirements:
|
23
|
-
- - "~>"
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: 0.0.88
|
26
12
|
- !ruby/object:Gem::Dependency
|
27
13
|
name: foobara-files-generator
|
28
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
132
|
- !ruby/object:Gem::Version
|
147
133
|
version: '0'
|
148
134
|
requirements: []
|
149
|
-
rubygems_version: 3.6.
|
135
|
+
rubygems_version: 3.6.7
|
150
136
|
specification_version: 4
|
151
137
|
summary: Generates remote commands for Typescript from a foobara manifest
|
152
138
|
test_files: []
|