foobara-typescript-remote-command-generator 1.2.1 → 1.2.3
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 +11 -1
- data/src/remote_generator/services/aggregate_entity_generator.rb +15 -9
- data/src/remote_generator/services/aggregate_model_generator.rb +6 -3
- data/src/remote_generator/services/atom_entity_generator.rb +3 -9
- data/src/remote_generator/services/atom_model_generator.rb +6 -3
- data/src/remote_generator/services/dependency_group.rb +39 -10
- data/src/remote_generator/services/entity_generator.rb +12 -0
- data/src/remote_generator/services/error_generator.rb +0 -10
- data/src/remote_generator/services/loaded_entity_generator.rb +3 -9
- data/src/remote_generator/services/model_generator.rb +12 -0
- data/src/remote_generator/services/typescript_from_manifest_base_generator.rb +12 -6
- data/src/remote_generator/services/unloaded_entity_generator.rb +4 -5
- data/src/remote_generator/write_typescript_to_disk.rb +32 -25
- data/templates/Entity/Aggregate.ts.erb +1 -1
- data/templates/Model/Model.ts.erb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a05ca67a91d4783f58462b104e7fe231916bbb7bb6b2d54138f5ea4a924c8653
|
|
4
|
+
data.tar.gz: b889694f3237d501fd5ff8a9504dbb70be5389f7b1223a0134dc4e76eb7ea1c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 81e53ffa5b4dd3eed11873aead7ad5e7edfb76dcf8487525306a33e0e93692b8a525b46602634477e70798ea886a3990a5bd53c2d7a6013ded7c3dcff0dc1110
|
|
7
|
+
data.tar.gz: 9377c12ceea5f00184d8c0ca380b7be7a5d26c5dc79e25021a1c656f756a643542b6940edbfedcb25b7daffa202e610c6696f295d9b8500654bd41c44eee2fc6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
## [1.2.3] - 2026-01-24
|
|
2
|
+
|
|
3
|
+
- Default the project_directory to "." instead of the output_directory
|
|
4
|
+
|
|
5
|
+
## [1.2.2] - 2026-01-24
|
|
6
|
+
|
|
7
|
+
- Add support for an app model named Model, which collide's with Foobara's Model
|
|
8
|
+
- Fixes a bug when the superclass we import collides with dependencies
|
|
9
|
+
- Fixes a bug where a dependency collides with something we're generating
|
|
10
|
+
|
|
1
11
|
## [1.2.1] - 2025-12-19
|
|
2
12
|
|
|
3
|
-
- Handle some foobara_delegate deprecation warnings
|
|
13
|
+
- Handle some .foobara_delegate and #path deprecation warnings
|
|
4
14
|
|
|
5
15
|
## [1.2.0] - 2025-11-06
|
|
6
16
|
|
|
@@ -30,22 +30,28 @@ module Foobara
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def dependencies
|
|
34
|
+
[*super, superclass_generator]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def collision_winners
|
|
38
|
+
superclass_generator
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def superclass_generator
|
|
42
|
+
@superclass_generator ||= LoadedEntityGenerator.new(relevant_manifest)
|
|
43
|
+
end
|
|
44
|
+
|
|
33
45
|
def attributes_type_ts_type
|
|
34
46
|
aggregate_attributes_ts_type
|
|
35
47
|
end
|
|
36
48
|
|
|
37
49
|
def ts_instance_path
|
|
38
|
-
*
|
|
39
|
-
[*prefix, "#{name}Aggregate"]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def ts_instance_full_path
|
|
43
|
-
*prefix, name = scoped_full_path
|
|
44
|
-
[*prefix, "#{name}Aggregate"]
|
|
50
|
+
[*model_prefix, generated_type]
|
|
45
51
|
end
|
|
46
52
|
|
|
47
|
-
def
|
|
48
|
-
"
|
|
53
|
+
def generated_type
|
|
54
|
+
"#{scoped_short_name}Aggregate"
|
|
49
55
|
end
|
|
50
56
|
end
|
|
51
57
|
end
|
|
@@ -38,9 +38,12 @@ module Foobara
|
|
|
38
38
|
aggregate_attributes_ts_type
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def
|
|
42
|
-
*
|
|
43
|
-
|
|
41
|
+
def ts_instance_path
|
|
42
|
+
[*model_prefix, generated_type]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def generated_type
|
|
46
|
+
"#{scoped_short_name}Aggregate"
|
|
44
47
|
end
|
|
45
48
|
end
|
|
46
49
|
end
|
|
@@ -33,17 +33,11 @@ module Foobara
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def ts_instance_path
|
|
36
|
-
*
|
|
37
|
-
[*prefix, "#{name}Atom"]
|
|
36
|
+
[*model_prefix, generated_type]
|
|
38
37
|
end
|
|
39
38
|
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
[*prefix, "#{name}Atom"]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def import_destructure
|
|
46
|
-
"{ #{scoped_short_name}Atom }"
|
|
39
|
+
def generated_type
|
|
40
|
+
"#{scoped_short_name}Atom"
|
|
47
41
|
end
|
|
48
42
|
end
|
|
49
43
|
end
|
|
@@ -34,9 +34,12 @@ module Foobara
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def
|
|
38
|
-
*
|
|
39
|
-
|
|
37
|
+
def ts_instance_path
|
|
38
|
+
[*model_prefix, generated_type]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def generated_type
|
|
42
|
+
"#{scoped_short_name}Atom"
|
|
40
43
|
end
|
|
41
44
|
end
|
|
42
45
|
end
|
|
@@ -10,11 +10,14 @@ module Foobara
|
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
attr_accessor :dependencies, :name
|
|
13
|
+
attr_accessor :dependencies, :name, :will_define, :deps_are_for, :winners
|
|
14
14
|
|
|
15
|
-
def initialize(dependencies, name:)
|
|
15
|
+
def initialize(dependencies, name:, deps_are_for:, will_define:, winners: nil)
|
|
16
|
+
self.deps_are_for = deps_are_for
|
|
17
|
+
self.will_define = will_define
|
|
16
18
|
self.name = name
|
|
17
19
|
self.dependencies = dependencies.to_set
|
|
20
|
+
self.winners = [*winners] if winners
|
|
18
21
|
|
|
19
22
|
find_collisions
|
|
20
23
|
end
|
|
@@ -57,18 +60,17 @@ module Foobara
|
|
|
57
60
|
def non_colliding_root(dep)
|
|
58
61
|
root = dep
|
|
59
62
|
points = points_for(dep)
|
|
60
|
-
points_climbed =
|
|
63
|
+
points_climbed = dep.ts_instance_path.size
|
|
61
64
|
|
|
62
65
|
until points_climbed >= points
|
|
63
|
-
|
|
64
|
-
points_climbed += dep.scoped_path.size
|
|
66
|
+
points_climbed += dep.ts_instance_path.size
|
|
65
67
|
root = root.parent
|
|
66
68
|
end
|
|
67
69
|
|
|
68
70
|
root
|
|
69
71
|
end
|
|
70
72
|
|
|
71
|
-
def
|
|
73
|
+
def raw_points_for(dep)
|
|
72
74
|
points = collision_data_for(dep).points
|
|
73
75
|
|
|
74
76
|
unless points
|
|
@@ -80,6 +82,14 @@ module Foobara
|
|
|
80
82
|
points
|
|
81
83
|
end
|
|
82
84
|
|
|
85
|
+
def points_for(dep)
|
|
86
|
+
if winners&.include?(dep)
|
|
87
|
+
0
|
|
88
|
+
else
|
|
89
|
+
raw_points_for(dep)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
83
93
|
def non_colliding_type_name(dep, points = points_for(dep))
|
|
84
94
|
non_colliding_type_path(dep, points).join(".")
|
|
85
95
|
end
|
|
@@ -89,16 +99,31 @@ module Foobara
|
|
|
89
99
|
end
|
|
90
100
|
|
|
91
101
|
def non_colliding_type_path(dep, points = points_for(dep))
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
if points == 0
|
|
103
|
+
path = dep.ts_instance_path
|
|
104
|
+
return path.size == 1 ? path : [path.last]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
path = dep.ts_instance_path
|
|
108
|
+
paths = [path]
|
|
109
|
+
points_climbed = path.size
|
|
94
110
|
|
|
95
|
-
|
|
111
|
+
until points_climbed >= points
|
|
112
|
+
dep = dep.parent
|
|
113
|
+
break unless dep
|
|
114
|
+
|
|
115
|
+
path = dep.ts_instance_path
|
|
116
|
+
paths.unshift(path)
|
|
117
|
+
points_climbed += path.size
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
paths.flatten
|
|
96
121
|
end
|
|
97
122
|
|
|
98
123
|
private
|
|
99
124
|
|
|
100
125
|
def find_collisions
|
|
101
|
-
dependencies.each do |dep|
|
|
126
|
+
[deps_are_for, *dependencies].each do |dep|
|
|
102
127
|
collision_data = CollisionData.new
|
|
103
128
|
|
|
104
129
|
points = 0
|
|
@@ -110,6 +135,10 @@ module Foobara
|
|
|
110
135
|
dep != other_dep && name == non_colliding_type_name(other_dep, points)
|
|
111
136
|
end
|
|
112
137
|
|
|
138
|
+
if will_define&.include?(name)
|
|
139
|
+
collisions << deps_are_for
|
|
140
|
+
end
|
|
141
|
+
|
|
113
142
|
if collisions.empty?
|
|
114
143
|
collision_data.points = points
|
|
115
144
|
set_collision_data_for(dep, collision_data)
|
|
@@ -14,6 +14,10 @@ module Foobara
|
|
|
14
14
|
["Entity", "Ambiguous.ts.erb"]
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
def ts_instance_path
|
|
18
|
+
[*model_prefix, scoped_short_name]
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
def entity_name(...)
|
|
18
22
|
model_name(...)
|
|
19
23
|
end
|
|
@@ -41,6 +45,14 @@ module Foobara
|
|
|
41
45
|
def association_property_paths_ts
|
|
42
46
|
associations.keys.map { |k| DataPath.parse(k).path.map(&:to_s) }.inspect
|
|
43
47
|
end
|
|
48
|
+
|
|
49
|
+
def will_define
|
|
50
|
+
[generated_type]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def generated_type
|
|
54
|
+
entity_short_name
|
|
55
|
+
end
|
|
44
56
|
end
|
|
45
57
|
end
|
|
46
58
|
end
|
|
@@ -58,16 +58,6 @@ module Foobara
|
|
|
58
58
|
def dependencies
|
|
59
59
|
@dependencies ||= types_depended_on.select { |type| type.detached_entity? || type.custom? || type.model? }
|
|
60
60
|
end
|
|
61
|
-
|
|
62
|
-
def ts_type_full_path
|
|
63
|
-
if parent.is_a?(CommandGenerator)
|
|
64
|
-
p = super.dup
|
|
65
|
-
p[-2] += "Errors"
|
|
66
|
-
p
|
|
67
|
-
else
|
|
68
|
-
super
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
61
|
end
|
|
72
62
|
end
|
|
73
63
|
end
|
|
@@ -13,17 +13,11 @@ module Foobara
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def ts_instance_path
|
|
16
|
-
*
|
|
17
|
-
[*prefix, "Loaded#{name}"]
|
|
16
|
+
[*model_prefix, generated_type]
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
[*prefix, "Loaded#{name}"]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def import_destructure
|
|
26
|
-
"{ Loaded#{scoped_short_name} }"
|
|
19
|
+
def generated_type
|
|
20
|
+
"Loaded#{scoped_short_name}"
|
|
27
21
|
end
|
|
28
22
|
end
|
|
29
23
|
end
|
|
@@ -23,6 +23,10 @@ module Foobara
|
|
|
23
23
|
[*domain.scoped_full_path, "Types", *model_prefix, model_short_name, "#{model_short_name}.ts"]
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
def ts_instance_path
|
|
27
|
+
[*model_prefix, scoped_short_name]
|
|
28
|
+
end
|
|
29
|
+
|
|
26
30
|
def model_short_name
|
|
27
31
|
type_short_name
|
|
28
32
|
end
|
|
@@ -42,6 +46,14 @@ module Foobara
|
|
|
42
46
|
def model_name_downcase
|
|
43
47
|
type_name_downcase
|
|
44
48
|
end
|
|
49
|
+
|
|
50
|
+
def generated_type
|
|
51
|
+
model_short_name
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def import_destructure
|
|
55
|
+
"{ #{generated_type} }"
|
|
56
|
+
end
|
|
45
57
|
end
|
|
46
58
|
end
|
|
47
59
|
end
|
|
@@ -120,10 +120,18 @@ module Foobara
|
|
|
120
120
|
generator_for(dependency)
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
DependencyGroup.new(generators,
|
|
123
|
+
DependencyGroup.new(generators,
|
|
124
|
+
deps_are_for: self,
|
|
125
|
+
name: scoped_full_path.join("."),
|
|
126
|
+
will_define:,
|
|
127
|
+
winners: collision_winners)
|
|
124
128
|
end
|
|
125
129
|
end
|
|
126
130
|
|
|
131
|
+
def will_define
|
|
132
|
+
nil
|
|
133
|
+
end
|
|
134
|
+
|
|
127
135
|
def dependency_roots
|
|
128
136
|
return @dependency_roots if defined?(@dependency_roots)
|
|
129
137
|
|
|
@@ -137,6 +145,8 @@ module Foobara
|
|
|
137
145
|
@dependency_roots = dependency_group.non_colliding_dependency_roots.sort_by(&:scoped_full_name)
|
|
138
146
|
end
|
|
139
147
|
|
|
148
|
+
def collision_winners = nil
|
|
149
|
+
|
|
140
150
|
def ts_instance_path
|
|
141
151
|
scoped_path
|
|
142
152
|
end
|
|
@@ -146,11 +156,7 @@ module Foobara
|
|
|
146
156
|
end
|
|
147
157
|
|
|
148
158
|
def ts_instance_full_path
|
|
149
|
-
scoped_full_path
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def ts_type_full_path
|
|
153
|
-
ts_instance_full_path
|
|
159
|
+
[*parent&.scoped_full_path, *ts_instance_path]
|
|
154
160
|
end
|
|
155
161
|
|
|
156
162
|
def organization_name = relevant_manifest.organization_name
|
|
@@ -10,13 +10,12 @@ module Foobara
|
|
|
10
10
|
["Entity", "Unloaded.ts.erb"]
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def
|
|
14
|
-
*
|
|
15
|
-
[*prefix, "Unloaded#{name}"]
|
|
13
|
+
def ts_instance_path
|
|
14
|
+
[*model_prefix, generated_type]
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
def
|
|
19
|
-
"
|
|
17
|
+
def generated_type
|
|
18
|
+
"Unloaded#{scoped_short_name}"
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
end
|
|
@@ -3,30 +3,22 @@ require_relative "generate_typescript"
|
|
|
3
3
|
module Foobara
|
|
4
4
|
module RemoteGenerator
|
|
5
5
|
class WriteTypescriptToDisk < Generators::WriteGeneratedFilesToDisk
|
|
6
|
-
|
|
7
|
-
def generator_key
|
|
8
|
-
"typescript-remote-commands"
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# TODO: shouldn't have to qualify DataError like this
|
|
13
|
-
class MissingManifestError < Value::DataError
|
|
14
|
-
class << self
|
|
15
|
-
def context_type_declaration
|
|
16
|
-
{}
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
possible_error MissingManifestError
|
|
6
|
+
def self.generator_key = "typescript-remote-commands"
|
|
22
7
|
|
|
23
8
|
inputs do
|
|
24
9
|
raw_manifest :associative_array, :allow_nil
|
|
25
10
|
manifest_url :string, :allow_nil
|
|
26
11
|
# TODO: should be able to delete this and inherit it
|
|
12
|
+
project_directory :string,
|
|
13
|
+
default: ".",
|
|
14
|
+
description: "This lets you specify a directory to run the linter or npm run build in"
|
|
27
15
|
output_directory :string, default: "src/domains"
|
|
16
|
+
fail_if_does_not_pass_linter :boolean, default: false
|
|
28
17
|
end
|
|
29
18
|
|
|
19
|
+
possible_error :missing_manifest
|
|
20
|
+
possible_error :failed_to_lint, context: -> { stdout :string, :required; stderr :string, :required }
|
|
21
|
+
|
|
30
22
|
depends_on GenerateTypescript
|
|
31
23
|
|
|
32
24
|
def execute
|
|
@@ -40,13 +32,16 @@ module Foobara
|
|
|
40
32
|
end
|
|
41
33
|
|
|
42
34
|
def validate
|
|
35
|
+
# TODO: kind of strange that we have to use a runtime error here. Maybe if input errors
|
|
36
|
+
# supported the concept of multiple inputs this would be cleaner?
|
|
43
37
|
if raw_manifest.nil? && manifest_url.nil?
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
38
|
+
# TODO: we should support a sugar like:
|
|
39
|
+
# add_runtime_error(
|
|
40
|
+
# :missing_manifest,
|
|
41
|
+
# "Must provide either raw_manifest or manifest_url",
|
|
42
|
+
# some_context_item: "blah"
|
|
43
|
+
# )
|
|
44
|
+
add_runtime_error(symbol: :missing_manifest, message: "Must provide either raw_manifest or manifest_url")
|
|
50
45
|
end
|
|
51
46
|
end
|
|
52
47
|
|
|
@@ -58,21 +53,33 @@ module Foobara
|
|
|
58
53
|
end
|
|
59
54
|
|
|
60
55
|
def run_post_generation_tasks
|
|
61
|
-
|
|
56
|
+
Dir.chdir(project_directory || output_directory) do
|
|
57
|
+
eslint_fix
|
|
58
|
+
end
|
|
62
59
|
end
|
|
63
60
|
|
|
64
61
|
def eslint_fix
|
|
65
62
|
cmd = "npx eslint 'src/**/*.{js,jsx,ts,tsx}' --fix"
|
|
66
63
|
|
|
67
|
-
Open3.popen3(cmd) do |_stdin,
|
|
64
|
+
Open3.popen3(cmd) do |_stdin, stdout, stderr, wait_thr|
|
|
68
65
|
exit_status = wait_thr.value
|
|
66
|
+
|
|
69
67
|
unless exit_status.success?
|
|
70
68
|
# :nocov:
|
|
71
|
-
|
|
69
|
+
out = stdout.read
|
|
70
|
+
err = stderr.read
|
|
71
|
+
|
|
72
|
+
if fail_if_does_not_pass_linter?
|
|
73
|
+
add_runtime_error :failed_to_lint, stdout: out, stderr: err
|
|
74
|
+
else
|
|
75
|
+
warn "WARNING: could not #{cmd}\n#{out}\n#{err}"
|
|
76
|
+
end
|
|
72
77
|
# :nocov:
|
|
73
78
|
end
|
|
74
79
|
end
|
|
75
80
|
end
|
|
81
|
+
|
|
82
|
+
def fail_if_does_not_pass_linter? = fail_if_does_not_pass_linter
|
|
76
83
|
end
|
|
77
84
|
end
|
|
78
85
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
<%= entity_short_name %>AttributesType
|
|
3
3
|
} from "./Ambiguous"
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
<% dependency_roots.each do |dependency_root| %>
|
|
6
6
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
|
7
7
|
<% end %>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from "<%= path_to_root %>base/Model"
|
|
1
|
+
import { Model as FoobaraModel } from "<%= path_to_root %>base/Model"
|
|
2
2
|
<% dependency_roots.each do |dependency_root| %>
|
|
3
3
|
import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= dependency_root.import_path %>"
|
|
4
4
|
<% end %>
|
|
@@ -7,7 +7,7 @@ export interface <%= model_short_name %>AttributesType <%= attributes_type_ts_ty
|
|
|
7
7
|
|
|
8
8
|
export class <%= model_short_name %><
|
|
9
9
|
AttributesType extends <%= model_short_name %>AttributesType = <%= model_short_name %>AttributesType
|
|
10
|
-
> extends
|
|
10
|
+
> extends FoobaraModel<AttributesType> {
|
|
11
11
|
static readonly modelName: string = "<%= model_short_name %>"
|
|
12
12
|
|
|
13
13
|
<% attribute_names.each do |attribute_name| %>
|