@currentjs/gen 0.1.1 → 0.2.0
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 +15 -0
- package/README.md +327 -251
- package/dist/commands/createModule.js +7 -5
- package/dist/generators/controllerGenerator.d.ts +3 -0
- package/dist/generators/controllerGenerator.js +143 -29
- package/dist/generators/serviceGenerator.d.ts +3 -1
- package/dist/generators/serviceGenerator.js +225 -52
- package/dist/generators/templates/appTemplates.d.ts +1 -1
- package/dist/generators/templates/appTemplates.js +64 -34
- package/dist/generators/templates/serviceTemplates.d.ts +1 -0
- package/dist/generators/templates/serviceTemplates.js +5 -0
- package/howto.md +48 -29
- package/package.json +1 -1
|
@@ -1119,6 +1119,7 @@ models:
|
|
|
1119
1119
|
|
|
1120
1120
|
api: # REST API configuration
|
|
1121
1121
|
prefix: /api/posts # Base URL for API endpoints
|
|
1122
|
+
model: Post # Optional: which model this API serves (defaults to first model)
|
|
1122
1123
|
endpoints:
|
|
1123
1124
|
- method: GET # HTTP method
|
|
1124
1125
|
path: / # Relative path (becomes /api/posts/)
|
|
@@ -1138,9 +1139,11 @@ api: # REST API configuration
|
|
|
1138
1139
|
- method: POST # Custom endpoint
|
|
1139
1140
|
path: /:id/publish
|
|
1140
1141
|
action: publish
|
|
1142
|
+
model: Post # Optional: override model for specific endpoint
|
|
1141
1143
|
|
|
1142
1144
|
routes: # Web interface configuration
|
|
1143
1145
|
prefix: /posts # Base URL for web pages
|
|
1146
|
+
model: Post # Optional: which model this route serves (defaults to first model)
|
|
1144
1147
|
strategy: [toast, back] # Default success strategies for forms
|
|
1145
1148
|
endpoints:
|
|
1146
1149
|
- path: / # List page
|
|
@@ -1155,41 +1158,40 @@ routes: # Web interface configuration
|
|
|
1155
1158
|
- path: /:id/edit # Edit form page
|
|
1156
1159
|
action: get # Load existing data
|
|
1157
1160
|
view: postUpdate
|
|
1161
|
+
model: Post # Optional: override model for specific endpoint
|
|
1158
1162
|
|
|
1159
1163
|
actions: # Business logic mapping
|
|
1160
1164
|
list:
|
|
1161
|
-
handlers: [default:list]
|
|
1165
|
+
handlers: [Post:default:list] # Use built-in list handler
|
|
1162
1166
|
get:
|
|
1163
|
-
handlers: [default:
|
|
1167
|
+
handlers: [Post:default:get] # Use built-in get handler
|
|
1164
1168
|
create:
|
|
1165
|
-
handlers: [default:create]
|
|
1169
|
+
handlers: [Post:default:create] # Built-in create
|
|
1166
1170
|
update:
|
|
1167
|
-
handlers: [default:update]
|
|
1171
|
+
handlers: [Post:default:update]
|
|
1168
1172
|
delete:
|
|
1169
1173
|
handlers: [ # Chain multiple handlers
|
|
1170
|
-
|
|
1171
|
-
default:delete
|
|
1174
|
+
Post:checkCanDelete, # Custom business logic
|
|
1175
|
+
Post:default:delete
|
|
1172
1176
|
]
|
|
1173
1177
|
publish: # Custom action
|
|
1174
1178
|
handlers: [
|
|
1175
|
-
default:
|
|
1176
|
-
|
|
1177
|
-
|
|
1179
|
+
Post:default:get, # Fetch entity
|
|
1180
|
+
Post:validateForPublish, # Custom validation
|
|
1181
|
+
Post:updatePublishStatus # Custom update logic
|
|
1178
1182
|
]
|
|
1179
1183
|
|
|
1180
1184
|
permissions: # Role-based access control
|
|
1181
|
-
-
|
|
1182
|
-
|
|
1183
|
-
-
|
|
1184
|
-
|
|
1185
|
-
-
|
|
1186
|
-
|
|
1187
|
-
-
|
|
1188
|
-
|
|
1189
|
-
-
|
|
1190
|
-
|
|
1191
|
-
- action: publish
|
|
1192
|
-
roles: [owner, editor, admin] # Multiple roles allowed
|
|
1185
|
+
- role: all
|
|
1186
|
+
actions: [list, get] # Anyone (including anonymous)
|
|
1187
|
+
- role: authenticated
|
|
1188
|
+
actions: [create] # Must be logged in
|
|
1189
|
+
- role: owner
|
|
1190
|
+
actions: [update, publish] # Entity owner permissions
|
|
1191
|
+
- role: admin
|
|
1192
|
+
actions: [update, delete, publish] # Admin role permissions
|
|
1193
|
+
- role: editor
|
|
1194
|
+
actions: [publish] # Editor role permissions
|
|
1193
1195
|
\`\`\`
|
|
1194
1196
|
|
|
1195
1197
|
**Make sure no \`ID\`/\`owner id\`/\`is deleted\` fields are present in the model definition, since it's added automatically**
|
|
@@ -1200,17 +1202,38 @@ permissions: # Role-based access control
|
|
|
1200
1202
|
- \`boolean\` - True/false values
|
|
1201
1203
|
- \`datetime\` - Date and time values
|
|
1202
1204
|
|
|
1205
|
+
**🔄 Handler vs Action Architecture:**
|
|
1206
|
+
- **Handler**: Creates a separate service method (one handler = one service method)
|
|
1207
|
+
- **Action**: Virtual controller concept that calls handler methods step-by-step
|
|
1208
|
+
|
|
1203
1209
|
**Built-in Action Handlers:**
|
|
1204
|
-
- \`default:list\` -
|
|
1205
|
-
- \`default:
|
|
1206
|
-
- \`default:create\` - Creates
|
|
1207
|
-
- \`default:update\` -
|
|
1208
|
-
- \`default:delete\` -
|
|
1210
|
+
- \`ModelName:default:list\` - Creates service method with pagination parameters
|
|
1211
|
+
- \`ModelName:default:get\` - Creates service method named \`get\` with ID parameter
|
|
1212
|
+
- \`ModelName:default:create\` - Creates service method with DTO parameter
|
|
1213
|
+
- \`ModelName:default:update\` - Creates service method with ID and DTO parameters
|
|
1214
|
+
- \`ModelName:default:delete\` - Creates service method with ID parameter
|
|
1209
1215
|
|
|
1210
1216
|
**Custom Action Handlers:**
|
|
1211
|
-
- \`
|
|
1212
|
-
-
|
|
1213
|
-
-
|
|
1217
|
+
- \`ModelName:customMethodName\` - Creates service method that accepts \`result, context\` parameters
|
|
1218
|
+
- \`result\`: Result from previous handler (or \`null\` if it's the first handler)
|
|
1219
|
+
- \`context\`: The request context object
|
|
1220
|
+
- Each handler generates a separate method in the service
|
|
1221
|
+
- User can customize the implementation after generation
|
|
1222
|
+
|
|
1223
|
+
**🔗 Multiple Handlers per Action:**
|
|
1224
|
+
When an action has multiple handlers, each handler generates a separate service method, and the controller action calls them sequentially. The action returns the result from the last handler.
|
|
1225
|
+
|
|
1226
|
+
**Parameter Passing Rules:**
|
|
1227
|
+
- **Default handlers** (\`:default:\`): Receive standard parameters (id, pagination, DTO, etc.)
|
|
1228
|
+
- **Custom handlers**: Receive \`(result, context)\` where:
|
|
1229
|
+
- \`result\`: Result from previous handler, or \`null\` if it's the first handler
|
|
1230
|
+
- \`context\`: Request context object
|
|
1231
|
+
|
|
1232
|
+
**Handler Format Examples:**
|
|
1233
|
+
- \`Post:default:list\` - Creates Post service method \`list(page, limit)\`
|
|
1234
|
+
- \`Post:default:get\` - Creates Post service method \`get(id)\`
|
|
1235
|
+
- \`Post:validateContent\` - Creates Post service method \`validateContent(result, context)\`
|
|
1236
|
+
- \`Comment:notifySubscribers\` - Creates Comment service method \`notifySubscribers(result, context)\`
|
|
1214
1237
|
|
|
1215
1238
|
**Strategy Options (for forms):**
|
|
1216
1239
|
- \`toast\` - Success toast notification
|
|
@@ -1228,14 +1251,21 @@ permissions: # Role-based access control
|
|
|
1228
1251
|
- Multiple roles can be specified for each action
|
|
1229
1252
|
|
|
1230
1253
|
**Generated Files from Configuration:**
|
|
1231
|
-
- Domain entity class
|
|
1232
|
-
- Service class
|
|
1233
|
-
- API controller with REST endpoints
|
|
1234
|
-
- Web controller with page rendering
|
|
1235
|
-
- Store class with database operations
|
|
1254
|
+
- Domain entity class (one per model)
|
|
1255
|
+
- Service class (one per model)
|
|
1256
|
+
- API controller with REST endpoints (one per model)
|
|
1257
|
+
- Web controller with page rendering (one per model)
|
|
1258
|
+
- Store class with database operations (one per model)
|
|
1236
1259
|
- HTML templates for all views
|
|
1237
1260
|
- TypeScript interfaces and DTOs
|
|
1238
1261
|
|
|
1262
|
+
**Multi-Model Support:**
|
|
1263
|
+
- Each model gets its own service, controller, and store
|
|
1264
|
+
- Use \`model\` parameter in \`api\` and \`routes\` to specify which model to use (defaults to first model)
|
|
1265
|
+
- Use \`model\` parameter on individual endpoints to override model for specific endpoints
|
|
1266
|
+
- Action handlers use \`modelname:action\` format to specify which model's service method to call
|
|
1267
|
+
- Controllers and services are generated per model, not per module
|
|
1268
|
+
|
|
1239
1269
|
## Module Structure
|
|
1240
1270
|
\`\`\`
|
|
1241
1271
|
src/modules/ModuleName/
|
|
@@ -22,6 +22,11 @@ exports.serviceTemplates = {
|
|
|
22
22
|
defaultImplementations: {
|
|
23
23
|
list: `const {{ENTITY_LOWER}}s = await this.{{ENTITY_LOWER}}Store.getAll(page, limit);
|
|
24
24
|
return {{ENTITY_LOWER}}s;`,
|
|
25
|
+
get: `const {{ENTITY_LOWER}} = await this.{{ENTITY_LOWER}}Store.getById(id);
|
|
26
|
+
if (!{{ENTITY_LOWER}}) {
|
|
27
|
+
throw new Error('{{ENTITY_NAME}} not found');
|
|
28
|
+
}
|
|
29
|
+
return {{ENTITY_LOWER}};`,
|
|
25
30
|
getById: `const {{ENTITY_LOWER}} = await this.{{ENTITY_LOWER}}Store.getById(id);
|
|
26
31
|
if (!{{ENTITY_LOWER}}) {
|
|
27
32
|
throw new Error('{{ENTITY_NAME}} not found');
|
package/howto.md
CHANGED
|
@@ -114,38 +114,36 @@ routes: # Web interface configuration
|
|
|
114
114
|
|
|
115
115
|
actions: # Business logic mapping
|
|
116
116
|
list:
|
|
117
|
-
handlers: [default:list]
|
|
117
|
+
handlers: [Post:default:list] # Use built-in list handler
|
|
118
118
|
get:
|
|
119
|
-
handlers: [default:
|
|
119
|
+
handlers: [Post:default:get] # Use built-in get handler
|
|
120
120
|
create:
|
|
121
|
-
handlers: [default:create]
|
|
121
|
+
handlers: [Post:default:create] # Built-in create
|
|
122
122
|
update:
|
|
123
|
-
handlers: [default:update]
|
|
123
|
+
handlers: [Post:default:update]
|
|
124
124
|
delete:
|
|
125
125
|
handlers: [ # Chain multiple handlers
|
|
126
|
-
|
|
127
|
-
default:delete
|
|
126
|
+
Post:checkCanDelete, # Custom business logic
|
|
127
|
+
Post:default:delete
|
|
128
128
|
]
|
|
129
129
|
publish: # Custom action
|
|
130
130
|
handlers: [
|
|
131
|
-
default:
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
Post:default:get, # Fetch entity
|
|
132
|
+
Post:validateForPublish, # Custom validation
|
|
133
|
+
Post:updatePublishStatus # Custom update logic
|
|
134
134
|
]
|
|
135
135
|
|
|
136
136
|
permissions: # Role-based access control
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
-
|
|
140
|
-
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
- action: publish
|
|
148
|
-
roles: [owner, editor, admin] # Multiple roles allowed
|
|
137
|
+
- role: all
|
|
138
|
+
actions: [list, get] # Anyone (including anonymous)
|
|
139
|
+
- role: authenticated
|
|
140
|
+
actions: [create] # Must be logged in
|
|
141
|
+
- role: owner
|
|
142
|
+
actions: [update, publish] # Entity owner permissions
|
|
143
|
+
- role: admin
|
|
144
|
+
actions: [update, delete, publish] # Admin role permissions
|
|
145
|
+
- role: editor
|
|
146
|
+
actions: [publish] # Editor role permissions
|
|
149
147
|
```
|
|
150
148
|
|
|
151
149
|
**Make sure no `ID`/`owner id`/`is deleted` fields are present in the model definition, since it's added automatically**
|
|
@@ -156,17 +154,38 @@ permissions: # Role-based access control
|
|
|
156
154
|
- `boolean` - True/false values
|
|
157
155
|
- `datetime` - Date and time values
|
|
158
156
|
|
|
157
|
+
**🔄 Handler vs Action Architecture:**
|
|
158
|
+
- **Handler**: Creates a separate service method (one handler = one service method)
|
|
159
|
+
- **Action**: Virtual controller concept that calls handler methods step-by-step
|
|
160
|
+
|
|
159
161
|
**Built-in Action Handlers:**
|
|
160
|
-
- `default:list` -
|
|
161
|
-
- `default:
|
|
162
|
-
- `default:create` - Creates
|
|
163
|
-
- `default:update` -
|
|
164
|
-
- `default:delete` -
|
|
162
|
+
- `ModelName:default:list` - Creates service method with pagination parameters
|
|
163
|
+
- `ModelName:default:get` - Creates service method named `get` with ID parameter
|
|
164
|
+
- `ModelName:default:create` - Creates service method with DTO parameter
|
|
165
|
+
- `ModelName:default:update` - Creates service method with ID and DTO parameters
|
|
166
|
+
- `ModelName:default:delete` - Creates service method with ID parameter
|
|
165
167
|
|
|
166
168
|
**Custom Action Handlers:**
|
|
167
|
-
- `
|
|
168
|
-
-
|
|
169
|
-
-
|
|
169
|
+
- `ModelName:customMethodName` - Creates service method that accepts `result, context` parameters
|
|
170
|
+
- `result`: Result from previous handler (or `null` if it's the first handler)
|
|
171
|
+
- `context`: The request context object
|
|
172
|
+
- Each handler generates a separate method in the service
|
|
173
|
+
- User can customize the implementation after generation
|
|
174
|
+
|
|
175
|
+
**🔗 Multiple Handlers per Action:**
|
|
176
|
+
When an action has multiple handlers, each handler generates a separate service method, and the controller action calls them sequentially. The action returns the result from the last handler.
|
|
177
|
+
|
|
178
|
+
**Parameter Passing Rules:**
|
|
179
|
+
- **Default handlers** (`:default:`): Receive standard parameters (id, pagination, DTO, etc.)
|
|
180
|
+
- **Custom handlers**: Receive `(result, context)` where:
|
|
181
|
+
- `result`: Result from previous handler, or `null` if it's the first handler
|
|
182
|
+
- `context`: Request context object
|
|
183
|
+
|
|
184
|
+
**Handler Format Examples:**
|
|
185
|
+
- `Post:default:list` - Creates Post service method `list(page, limit)`
|
|
186
|
+
- `Post:default:get` - Creates Post service method `get(id)`
|
|
187
|
+
- `Post:validateContent` - Creates Post service method `validateContent(result, context)`
|
|
188
|
+
- `Comment:notifySubscribers` - Creates Comment service method `notifySubscribers(result, context)`
|
|
170
189
|
|
|
171
190
|
**Strategy Options (for forms):**
|
|
172
191
|
- `toast` - Success toast notification
|