@currentjs/gen 0.2.2 → 0.3.1
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.
- package/CHANGELOG.md +240 -0
- package/README.md +256 -0
- package/dist/cli.js +26 -0
- package/dist/commands/createApp.js +2 -0
- package/dist/commands/generateAll.js +153 -29
- package/dist/commands/migrateCommit.d.ts +1 -0
- package/dist/commands/migrateCommit.js +201 -0
- package/dist/generators/controllerGenerator.d.ts +7 -0
- package/dist/generators/controllerGenerator.js +60 -29
- package/dist/generators/domainModelGenerator.d.ts +7 -0
- package/dist/generators/domainModelGenerator.js +57 -3
- package/dist/generators/serviceGenerator.d.ts +16 -1
- package/dist/generators/serviceGenerator.js +125 -12
- package/dist/generators/storeGenerator.d.ts +8 -0
- package/dist/generators/storeGenerator.js +133 -7
- package/dist/generators/templateGenerator.d.ts +19 -0
- package/dist/generators/templateGenerator.js +216 -11
- package/dist/generators/templates/appTemplates.d.ts +8 -7
- package/dist/generators/templates/appTemplates.js +11 -1572
- package/dist/generators/templates/data/appTsTemplate +39 -0
- package/dist/generators/templates/data/appYamlTemplate +4 -0
- package/dist/generators/templates/data/cursorRulesTemplate +671 -0
- package/dist/generators/templates/data/errorTemplate +28 -0
- package/dist/generators/templates/data/frontendScriptTemplate +739 -0
- package/dist/generators/templates/data/mainViewTemplate +16 -0
- package/dist/generators/templates/data/translationsTemplate +68 -0
- package/dist/generators/templates/data/tsConfigTemplate +19 -0
- package/dist/generators/templates/viewTemplates.d.ts +10 -1
- package/dist/generators/templates/viewTemplates.js +138 -6
- package/dist/generators/validationGenerator.d.ts +5 -0
- package/dist/generators/validationGenerator.js +51 -0
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/constants.js +5 -2
- package/dist/utils/generationRegistry.js +1 -1
- package/dist/utils/migrationUtils.d.ts +49 -0
- package/dist/utils/migrationUtils.js +291 -0
- package/howto.md +157 -65
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,38 +5,158 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [0.3.1] - 2025-10-03
|
|
11
|
+
|
|
12
|
+
bug fixed with overwriting committed changes
|
|
13
|
+
|
|
14
|
+
## [0.3.0] - 2025-10-03
|
|
15
|
+
|
|
16
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [0.3.1] - 2025-10-03
|
|
20
|
+
|
|
21
|
+
bug fixed with overwriting committed changes
|
|
22
|
+
|
|
8
23
|
## [0.2.2] - 2025-10-02
|
|
9
24
|
|
|
10
25
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
11
26
|
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## [0.3.1] - 2025-10-03
|
|
30
|
+
|
|
31
|
+
bug fixed with overwriting committed changes
|
|
32
|
+
|
|
33
|
+
## [0.3.0] - 2025-10-03
|
|
34
|
+
|
|
35
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## [0.3.1] - 2025-10-03
|
|
39
|
+
|
|
40
|
+
bug fixed with overwriting committed changes
|
|
41
|
+
|
|
12
42
|
## [0.2.1] - 2025-09-18
|
|
13
43
|
|
|
14
44
|
Improve generated package.json
|
|
15
45
|
|
|
16
46
|
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## [0.3.1] - 2025-10-03
|
|
50
|
+
|
|
51
|
+
bug fixed with overwriting committed changes
|
|
52
|
+
|
|
53
|
+
## [0.3.0] - 2025-10-03
|
|
54
|
+
|
|
55
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## [0.3.1] - 2025-10-03
|
|
59
|
+
|
|
60
|
+
bug fixed with overwriting committed changes
|
|
61
|
+
|
|
17
62
|
## [0.2.2] - 2025-10-02
|
|
18
63
|
|
|
19
64
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
20
65
|
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## [0.3.1] - 2025-10-03
|
|
69
|
+
|
|
70
|
+
bug fixed with overwriting committed changes
|
|
71
|
+
|
|
72
|
+
## [0.3.0] - 2025-10-03
|
|
73
|
+
|
|
74
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## [0.3.1] - 2025-10-03
|
|
78
|
+
|
|
79
|
+
bug fixed with overwriting committed changes
|
|
80
|
+
|
|
21
81
|
## [0.2.0] - 2025-09-18
|
|
22
82
|
|
|
23
83
|
implement multi-model generation (controllers, services); fix service-controller interaction; update documentation: more clear & reflect important things
|
|
24
84
|
|
|
25
85
|
|
|
26
86
|
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## [0.3.1] - 2025-10-03
|
|
90
|
+
|
|
91
|
+
bug fixed with overwriting committed changes
|
|
92
|
+
|
|
93
|
+
## [0.3.0] - 2025-10-03
|
|
94
|
+
|
|
95
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## [0.3.1] - 2025-10-03
|
|
99
|
+
|
|
100
|
+
bug fixed with overwriting committed changes
|
|
101
|
+
|
|
27
102
|
## [0.2.2] - 2025-10-02
|
|
28
103
|
|
|
29
104
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
30
105
|
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## [0.3.1] - 2025-10-03
|
|
109
|
+
|
|
110
|
+
bug fixed with overwriting committed changes
|
|
111
|
+
|
|
112
|
+
## [0.3.0] - 2025-10-03
|
|
113
|
+
|
|
114
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## [0.3.1] - 2025-10-03
|
|
118
|
+
|
|
119
|
+
bug fixed with overwriting committed changes
|
|
120
|
+
|
|
31
121
|
## [0.2.1] - 2025-09-18
|
|
32
122
|
|
|
33
123
|
Improve generated package.json
|
|
34
124
|
|
|
35
125
|
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
## [0.3.1] - 2025-10-03
|
|
129
|
+
|
|
130
|
+
bug fixed with overwriting committed changes
|
|
131
|
+
|
|
132
|
+
## [0.3.0] - 2025-10-03
|
|
133
|
+
|
|
134
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## [0.3.1] - 2025-10-03
|
|
138
|
+
|
|
139
|
+
bug fixed with overwriting committed changes
|
|
140
|
+
|
|
36
141
|
## [0.2.2] - 2025-10-02
|
|
37
142
|
|
|
38
143
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
39
144
|
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## [0.3.1] - 2025-10-03
|
|
148
|
+
|
|
149
|
+
bug fixed with overwriting committed changes
|
|
150
|
+
|
|
151
|
+
## [0.3.0] - 2025-10-03
|
|
152
|
+
|
|
153
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## [0.3.1] - 2025-10-03
|
|
157
|
+
|
|
158
|
+
bug fixed with overwriting committed changes
|
|
159
|
+
|
|
40
160
|
## [0.1.2] - 2025-09-18
|
|
41
161
|
|
|
42
162
|
fix: failed to generate with empty permissions actions
|
|
@@ -44,38 +164,158 @@ fix: failed to generate with empty permissions actions
|
|
|
44
164
|
|
|
45
165
|
|
|
46
166
|
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## [0.3.1] - 2025-10-03
|
|
170
|
+
|
|
171
|
+
bug fixed with overwriting committed changes
|
|
172
|
+
|
|
173
|
+
## [0.3.0] - 2025-10-03
|
|
174
|
+
|
|
175
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
## [0.3.1] - 2025-10-03
|
|
179
|
+
|
|
180
|
+
bug fixed with overwriting committed changes
|
|
181
|
+
|
|
47
182
|
## [0.2.2] - 2025-10-02
|
|
48
183
|
|
|
49
184
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
50
185
|
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## [0.3.1] - 2025-10-03
|
|
189
|
+
|
|
190
|
+
bug fixed with overwriting committed changes
|
|
191
|
+
|
|
192
|
+
## [0.3.0] - 2025-10-03
|
|
193
|
+
|
|
194
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
## [0.3.1] - 2025-10-03
|
|
198
|
+
|
|
199
|
+
bug fixed with overwriting committed changes
|
|
200
|
+
|
|
51
201
|
## [0.2.1] - 2025-09-18
|
|
52
202
|
|
|
53
203
|
Improve generated package.json
|
|
54
204
|
|
|
55
205
|
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
## [0.3.1] - 2025-10-03
|
|
209
|
+
|
|
210
|
+
bug fixed with overwriting committed changes
|
|
211
|
+
|
|
212
|
+
## [0.3.0] - 2025-10-03
|
|
213
|
+
|
|
214
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
## [0.3.1] - 2025-10-03
|
|
218
|
+
|
|
219
|
+
bug fixed with overwriting committed changes
|
|
220
|
+
|
|
56
221
|
## [0.2.2] - 2025-10-02
|
|
57
222
|
|
|
58
223
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
59
224
|
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
## [0.3.1] - 2025-10-03
|
|
228
|
+
|
|
229
|
+
bug fixed with overwriting committed changes
|
|
230
|
+
|
|
231
|
+
## [0.3.0] - 2025-10-03
|
|
232
|
+
|
|
233
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
## [0.3.1] - 2025-10-03
|
|
237
|
+
|
|
238
|
+
bug fixed with overwriting committed changes
|
|
239
|
+
|
|
60
240
|
## [0.2.0] - 2025-09-18
|
|
61
241
|
|
|
62
242
|
implement multi-model generation (controllers, services); fix service-controller interaction; update documentation: more clear & reflect important things
|
|
63
243
|
|
|
64
244
|
|
|
65
245
|
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## [0.3.1] - 2025-10-03
|
|
249
|
+
|
|
250
|
+
bug fixed with overwriting committed changes
|
|
251
|
+
|
|
252
|
+
## [0.3.0] - 2025-10-03
|
|
253
|
+
|
|
254
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
## [0.3.1] - 2025-10-03
|
|
258
|
+
|
|
259
|
+
bug fixed with overwriting committed changes
|
|
260
|
+
|
|
66
261
|
## [0.2.2] - 2025-10-02
|
|
67
262
|
|
|
68
263
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
69
264
|
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## [0.3.1] - 2025-10-03
|
|
268
|
+
|
|
269
|
+
bug fixed with overwriting committed changes
|
|
270
|
+
|
|
271
|
+
## [0.3.0] - 2025-10-03
|
|
272
|
+
|
|
273
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
## [0.3.1] - 2025-10-03
|
|
277
|
+
|
|
278
|
+
bug fixed with overwriting committed changes
|
|
279
|
+
|
|
70
280
|
## [0.2.1] - 2025-09-18
|
|
71
281
|
|
|
72
282
|
Improve generated package.json
|
|
73
283
|
|
|
74
284
|
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
## [0.3.1] - 2025-10-03
|
|
288
|
+
|
|
289
|
+
bug fixed with overwriting committed changes
|
|
290
|
+
|
|
291
|
+
## [0.3.0] - 2025-10-03
|
|
292
|
+
|
|
293
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
## [0.3.1] - 2025-10-03
|
|
297
|
+
|
|
298
|
+
bug fixed with overwriting committed changes
|
|
299
|
+
|
|
75
300
|
## [0.2.2] - 2025-10-02
|
|
76
301
|
|
|
77
302
|
fix bug: required params after optional in the generated models; fix: views(templates) are not stored in the registry and being regenerated (overwritten); small readme fix; running 'npm i' on 'create app' and 'npm run build' on 'generate'
|
|
78
303
|
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
## [0.3.1] - 2025-10-03
|
|
307
|
+
|
|
308
|
+
bug fixed with overwriting committed changes
|
|
309
|
+
|
|
310
|
+
## [0.3.0] - 2025-10-03
|
|
311
|
+
|
|
312
|
+
- model relationship (between each other); - frontend script cleanup; - new command: migrate commit; - small refactoring.
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
## [0.3.1] - 2025-10-03
|
|
316
|
+
|
|
317
|
+
bug fixed with overwriting committed changes
|
|
318
|
+
|
|
79
319
|
## [0.1.1] - 2025-09-17
|
|
80
320
|
|
|
81
321
|
Initial release
|
package/README.md
CHANGED
|
@@ -257,6 +257,94 @@ dist/
|
|
|
257
257
|
|
|
258
258
|
With this setup, your repository stays focused on what matters: your specifications and customizations, not generated boilerplate!
|
|
259
259
|
|
|
260
|
+
## Multi-Model Endpoint Support 🔀
|
|
261
|
+
|
|
262
|
+
Working with multiple related models in a single module? CurrentJS now supports flexible endpoint configurations for multi-model scenarios.
|
|
263
|
+
|
|
264
|
+
### Per-Endpoint Model Override
|
|
265
|
+
|
|
266
|
+
Override the model for specific endpoints when you need to mix models within the same API or routes section:
|
|
267
|
+
|
|
268
|
+
```yaml
|
|
269
|
+
models:
|
|
270
|
+
- name: Cat
|
|
271
|
+
fields:
|
|
272
|
+
- name: name
|
|
273
|
+
type: string
|
|
274
|
+
- name: Person
|
|
275
|
+
fields:
|
|
276
|
+
- name: name
|
|
277
|
+
type: string
|
|
278
|
+
- name: email
|
|
279
|
+
type: string
|
|
280
|
+
|
|
281
|
+
routes:
|
|
282
|
+
prefix: /cat
|
|
283
|
+
model: Cat # Default model for this section
|
|
284
|
+
endpoints:
|
|
285
|
+
- path: /create
|
|
286
|
+
action: empty
|
|
287
|
+
view: catCreate
|
|
288
|
+
# Uses Cat model (from default)
|
|
289
|
+
|
|
290
|
+
- path: /createOwner
|
|
291
|
+
action: empty
|
|
292
|
+
view: ownerCreate
|
|
293
|
+
model: Person # Override to use Person model for this endpoint
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Result**: The `/cat/createOwner` page will generate a form with Person fields (name, email), not Cat fields.
|
|
297
|
+
|
|
298
|
+
### Multiple API/Routes Sections
|
|
299
|
+
|
|
300
|
+
Organize endpoints by model or functionality using arrays:
|
|
301
|
+
|
|
302
|
+
```yaml
|
|
303
|
+
# Multiple routes sections for different models
|
|
304
|
+
routes:
|
|
305
|
+
- prefix: /cat
|
|
306
|
+
model: Cat
|
|
307
|
+
endpoints:
|
|
308
|
+
- path: /
|
|
309
|
+
action: list
|
|
310
|
+
view: catList
|
|
311
|
+
- path: /create
|
|
312
|
+
action: empty
|
|
313
|
+
view: catCreate
|
|
314
|
+
|
|
315
|
+
- prefix: /person
|
|
316
|
+
model: Person
|
|
317
|
+
endpoints:
|
|
318
|
+
- path: /
|
|
319
|
+
action: list
|
|
320
|
+
view: personList
|
|
321
|
+
- path: /create
|
|
322
|
+
action: empty
|
|
323
|
+
view: personCreate
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Result**: Generates separate controllers with their own base paths and endpoints.
|
|
327
|
+
|
|
328
|
+
### Automatic Model Inference
|
|
329
|
+
|
|
330
|
+
If you don't specify a `model`, the system will infer it from the action handler:
|
|
331
|
+
|
|
332
|
+
```yaml
|
|
333
|
+
routes:
|
|
334
|
+
prefix: /cat
|
|
335
|
+
endpoints:
|
|
336
|
+
- path: /createOwner
|
|
337
|
+
action: createOwner
|
|
338
|
+
view: ownerCreate
|
|
339
|
+
# No model specified - inferred from action below
|
|
340
|
+
|
|
341
|
+
actions:
|
|
342
|
+
createOwner:
|
|
343
|
+
handlers: [Person:default:create] # Infers Person model
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**Priority**: `endpoint.model` → inferred from handler → section `model` → first model in array
|
|
347
|
+
|
|
260
348
|
## Example: Building a Blog System 📝
|
|
261
349
|
|
|
262
350
|
Here's how you'd create a complete very simple blog system:
|
|
@@ -536,6 +624,174 @@ models:
|
|
|
536
624
|
required: false
|
|
537
625
|
```
|
|
538
626
|
|
|
627
|
+
### 🔗 Model Relationships
|
|
628
|
+
|
|
629
|
+
You can define relationships between models by specifying another model name as the field type. The generator will automatically handle foreign keys, type checking, and UI components.
|
|
630
|
+
|
|
631
|
+
**Basic Relationship Example:**
|
|
632
|
+
```yaml
|
|
633
|
+
models:
|
|
634
|
+
- name: Owner
|
|
635
|
+
fields:
|
|
636
|
+
- name: name
|
|
637
|
+
type: string
|
|
638
|
+
required: true
|
|
639
|
+
- name: email
|
|
640
|
+
type: string
|
|
641
|
+
required: true
|
|
642
|
+
|
|
643
|
+
- name: Cat
|
|
644
|
+
fields:
|
|
645
|
+
- name: name
|
|
646
|
+
type: string
|
|
647
|
+
required: true
|
|
648
|
+
- name: breed
|
|
649
|
+
type: string
|
|
650
|
+
required: false
|
|
651
|
+
- name: owner
|
|
652
|
+
type: Owner # Relationship to Owner model
|
|
653
|
+
required: true
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
**Architecture: Rich Domain Models**
|
|
657
|
+
|
|
658
|
+
The generator uses **Infrastructure-Level Relationship Assembly**:
|
|
659
|
+
|
|
660
|
+
- **Domain Layer**: Works with full objects (no FKs)
|
|
661
|
+
- **Infrastructure (Store)**: Handles FK ↔ Object conversion
|
|
662
|
+
- **DTOs**: Use FKs for API transmission
|
|
663
|
+
|
|
664
|
+
**What Gets Generated:**
|
|
665
|
+
|
|
666
|
+
1. **Domain Model**: Pure business objects
|
|
667
|
+
```typescript
|
|
668
|
+
import { Owner } from './Owner';
|
|
669
|
+
|
|
670
|
+
export class Cat {
|
|
671
|
+
constructor(
|
|
672
|
+
public id: number,
|
|
673
|
+
public name: string,
|
|
674
|
+
public breed?: string,
|
|
675
|
+
public owner: Owner // ✨ Full object, no FK!
|
|
676
|
+
) {}
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
2. **DTOs**: Use foreign keys for API
|
|
681
|
+
```typescript
|
|
682
|
+
export interface CatDTO {
|
|
683
|
+
name: string;
|
|
684
|
+
breed?: string;
|
|
685
|
+
ownerId: number; // ✨ FK for over-the-wire
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
3. **Store**: Converts FK ↔ Object
|
|
690
|
+
```typescript
|
|
691
|
+
export class CatStore {
|
|
692
|
+
constructor(
|
|
693
|
+
private db: ISqlProvider,
|
|
694
|
+
private ownerStore: OwnerStore // ✨ Foreign store dependency
|
|
695
|
+
) {}
|
|
696
|
+
|
|
697
|
+
async loadRelationships(entity: Cat, row: CatRow): Promise<Cat> {
|
|
698
|
+
const owner = await this.ownerStore.getById(row.ownerId);
|
|
699
|
+
if (owner) entity.setOwner(owner);
|
|
700
|
+
return entity;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
async insert(cat: Cat): Promise<Cat> {
|
|
704
|
+
const row = {
|
|
705
|
+
name: cat.name,
|
|
706
|
+
ownerId: cat.owner?.id // ✨ Extract FK to save
|
|
707
|
+
};
|
|
708
|
+
// ...
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
4. **Service**: Loads objects from FKs
|
|
714
|
+
```typescript
|
|
715
|
+
export class CatService {
|
|
716
|
+
constructor(
|
|
717
|
+
private catStore: CatStore,
|
|
718
|
+
private ownerStore: OwnerStore // ✨ To load relationships
|
|
719
|
+
) {}
|
|
720
|
+
|
|
721
|
+
async create(catData: CatDTO): Promise<Cat> {
|
|
722
|
+
// ✨ Load full owner object from FK
|
|
723
|
+
const owner = await this.ownerStore.getById(catData.ownerId);
|
|
724
|
+
const cat = new Cat(0, catData.name, catData.breed, owner);
|
|
725
|
+
return await this.catStore.insert(cat);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
5. **HTML Forms**: Select dropdown with "Create New" button
|
|
731
|
+
```html
|
|
732
|
+
<select id="ownerId" name="ownerId" required>
|
|
733
|
+
<option value="">-- Select Owner --</option>
|
|
734
|
+
<!-- Options loaded from /api/owner -->
|
|
735
|
+
</select>
|
|
736
|
+
<button onclick="window.open('/owner/create')">+ New</button>
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
**Relationship Naming Convention:**
|
|
740
|
+
|
|
741
|
+
The generator automatically creates foreign key fields following this convention:
|
|
742
|
+
- **Field name**: `owner` → **Foreign key**: `ownerId`
|
|
743
|
+
- **Field name**: `author` → **Foreign key**: `authorId`
|
|
744
|
+
- **Field name**: `parentComment` → **Foreign key**: `parentCommentId`
|
|
745
|
+
|
|
746
|
+
The foreign key always references the `id` field of the related model.
|
|
747
|
+
|
|
748
|
+
**Optional Configuration:**
|
|
749
|
+
|
|
750
|
+
```yaml
|
|
751
|
+
models:
|
|
752
|
+
- name: Post
|
|
753
|
+
fields:
|
|
754
|
+
- name: title
|
|
755
|
+
type: string
|
|
756
|
+
required: true
|
|
757
|
+
- name: author
|
|
758
|
+
type: User
|
|
759
|
+
required: true
|
|
760
|
+
displayFields: [name, email] # Fields to show in dropdowns (optional)
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
**Configuration Options:**
|
|
764
|
+
- `displayFields`: Array of fields from the related model to display in UI dropdowns (optional, defaults to showing the ID)
|
|
765
|
+
|
|
766
|
+
**Multiple Relationships:**
|
|
767
|
+
```yaml
|
|
768
|
+
models:
|
|
769
|
+
- name: Comment
|
|
770
|
+
fields:
|
|
771
|
+
- name: content
|
|
772
|
+
type: string
|
|
773
|
+
required: true
|
|
774
|
+
- name: post
|
|
775
|
+
type: Post # Creates foreign key: postId
|
|
776
|
+
required: true
|
|
777
|
+
- name: author
|
|
778
|
+
type: User # Creates foreign key: authorId
|
|
779
|
+
required: true
|
|
780
|
+
displayFields: [username, email]
|
|
781
|
+
- name: parentComment
|
|
782
|
+
type: Comment # Self-referential relationship
|
|
783
|
+
required: false # Creates foreign key: parentCommentId
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
**Relationship Best Practices:**
|
|
787
|
+
- ✅ Always define the foreign model first in the same module
|
|
788
|
+
- ✅ Use descriptive field names for relationships (e.g., `author` instead of `user`)
|
|
789
|
+
- ✅ Set appropriate `displayFields` to show meaningful data in dropdowns
|
|
790
|
+
- ✅ Use `required: false` for optional relationships
|
|
791
|
+
- ✅ Foreign keys are auto-generated following the pattern `fieldName + 'Id'`
|
|
792
|
+
- ❌ Don't manually add foreign key fields (they're auto-generated)
|
|
793
|
+
- ❌ Don't create circular dependencies between modules
|
|
794
|
+
|
|
539
795
|
### Action Handlers Explained
|
|
540
796
|
|
|
541
797
|
**🔄 Handler vs Action Distinction:**
|
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,9 @@ const commit_1 = require("./commands/commit");
|
|
|
8
8
|
const diff_1 = require("./commands/diff");
|
|
9
9
|
const colors_1 = require("./utils/colors");
|
|
10
10
|
const infer_1 = require("./commands/infer");
|
|
11
|
+
const migrateCommit_1 = require("./commands/migrateCommit");
|
|
12
|
+
// import { handleMigratePush } from './commands/migratePush';
|
|
13
|
+
// import { handleMigrateUpdate } from './commands/migrateUpdate';
|
|
11
14
|
function printHelp() {
|
|
12
15
|
const title = colors_1.colors.bold(colors_1.colors.brightCyan('currentjs - Clean architecture CLI'));
|
|
13
16
|
const usage = colors_1.colors.bold('Usage:');
|
|
@@ -24,6 +27,7 @@ ${usage}
|
|
|
24
27
|
${cmd('currentjs commit')} ${colors_1.colors.gray('[<file> ...]')} ${flag('--yaml')} ${colors_1.colors.gray('app.yaml')}
|
|
25
28
|
${cmd('currentjs diff')} ${colors_1.colors.gray('<module|*>')} ${flag('--yaml')} ${colors_1.colors.gray('app.yaml')}
|
|
26
29
|
${cmd('currentjs infer')} ${flag('--file')} ${colors_1.colors.gray('src/modules/<Module>/domain/entities/<Entity>.ts')} ${colors_1.colors.gray('[')}${flag('--write')}${colors_1.colors.gray(']')}
|
|
30
|
+
${cmd('currentjs migrate commit')} ${flag('--yaml')} ${colors_1.colors.gray('app.yaml')}
|
|
27
31
|
|
|
28
32
|
${options}
|
|
29
33
|
${flag('--yaml')} <path> ${colors_1.colors.gray('Path to app.yaml (default: ./app.yaml)')}
|
|
@@ -65,6 +69,9 @@ function parseArgs(argv) {
|
|
|
65
69
|
else if (result.command === 'infer') {
|
|
66
70
|
// no subcommands
|
|
67
71
|
}
|
|
72
|
+
else if (result.command === 'migrate') {
|
|
73
|
+
result.sub = rest.shift();
|
|
74
|
+
}
|
|
68
75
|
for (let i = 0; i < rest.length; i += 1) {
|
|
69
76
|
const token = rest[i];
|
|
70
77
|
if (token === '--yaml') {
|
|
@@ -127,6 +134,25 @@ async function run() {
|
|
|
127
134
|
(0, infer_1.handleInfer)(fileArg, write);
|
|
128
135
|
return;
|
|
129
136
|
}
|
|
137
|
+
case 'migrate': {
|
|
138
|
+
if (args.sub === 'commit') {
|
|
139
|
+
(0, migrateCommit_1.handleMigrateCommit)(args.yaml);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (args.sub === 'push') {
|
|
143
|
+
console.log(colors_1.colors.yellow('⚠️ Not implemented yet'));
|
|
144
|
+
// await handleMigratePush(args.yaml);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (args.sub === 'update') {
|
|
148
|
+
console.log(colors_1.colors.yellow('⚠️ Not implemented yet'));
|
|
149
|
+
// await handleMigrateUpdate(args.yaml);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
printHelp();
|
|
153
|
+
process.exitCode = 1;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
130
156
|
default: {
|
|
131
157
|
printHelp();
|
|
132
158
|
process.exitCode = 1;
|
|
@@ -46,11 +46,13 @@ function handleCreateApp(rawName) {
|
|
|
46
46
|
const webDir = path.join(targetRoot, appTemplates_1.DEFAULT_DIRECTORIES.WEB);
|
|
47
47
|
const templatesDir = path.join(targetRoot, appTemplates_1.DEFAULT_DIRECTORIES.TEMPLATES);
|
|
48
48
|
const servicesDir = path.join(targetRoot, appTemplates_1.DEFAULT_DIRECTORIES.SERVICES);
|
|
49
|
+
const migrationsDir = path.join(targetRoot, appTemplates_1.DEFAULT_DIRECTORIES.MIGRATIONS);
|
|
49
50
|
(0, cliUtils_1.ensureDir)(srcDir);
|
|
50
51
|
(0, cliUtils_1.ensureDir)(distDir);
|
|
51
52
|
(0, cliUtils_1.ensureDir)(webDir);
|
|
52
53
|
(0, cliUtils_1.ensureDir)(templatesDir);
|
|
53
54
|
(0, cliUtils_1.ensureDir)(servicesDir);
|
|
55
|
+
(0, cliUtils_1.ensureDir)(migrationsDir);
|
|
54
56
|
// Files using imported templates
|
|
55
57
|
(0, cliUtils_1.writeFileIfMissing)(path.join(targetRoot, appTemplates_1.DEFAULT_FILES.PACKAGE_JSON), (0, appTemplates_1.packageJsonTemplate)(path.basename(targetRoot)));
|
|
56
58
|
(0, cliUtils_1.writeFileIfMissing)(path.join(targetRoot, appTemplates_1.DEFAULT_FILES.TSCONFIG), appTemplates_1.tsconfigTemplate);
|