@simplix-boot/cli 2.0.4 → 2.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplix-boot/cli",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Command line tool that generates SimpliX Spring Boot code (services, controllers, DTOs, tests) from JPA entities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -137,6 +137,32 @@ export function mergeThreeWay(base, ours, theirs) {
137
137
  }
138
138
  }
139
139
 
140
+ const SINGLE_IMPORT = /^import (?:static )?[\w.]+\.(\w+);$/;
141
+
142
+ /**
143
+ * Puts back each import the edited file had and the merge dropped while the merged code still names
144
+ * the imported class or member: a template that stops importing a class cannot see that code
145
+ * written into the file by hand still uses it.
146
+ *
147
+ * @param {string} ours the edited file
148
+ * @param {string} merged the result of the three-way merge
149
+ * @returns {string} the merge with those imports after its last import line
150
+ */
151
+ export function keepUsedImports(ours, merged) {
152
+ const mergedLines = merged.split('\n');
153
+ const present = new Set(mergedLines.filter(line => SINGLE_IMPORT.test(line)));
154
+ const code = mergedLines.filter(line => !line.startsWith('import ')).join('\n');
155
+ const dropped = ours.split('\n').filter(line => {
156
+ const name = SINGLE_IMPORT.exec(line)?.[1];
157
+ return name !== undefined && !present.has(line) && new RegExp(`\\b${name}\\b`).test(code);
158
+ });
159
+ if (dropped.length === 0) return merged;
160
+ const lastImport = mergedLines.findLastIndex(line => line.startsWith('import '));
161
+ if (lastImport < 0) return merged;
162
+ mergedLines.splice(lastImport + 1, 0, ...new Set(dropped));
163
+ return mergedLines.join('\n');
164
+ }
165
+
140
166
  /**
141
167
  * What a promote of one fresh render into one file comes to, without writing anything.
142
168
  *
@@ -164,7 +190,9 @@ export function planTracked(root, filePath, stamped) {
164
190
  if (base === undefined) return { outcome: 'no-base' };
165
191
  // The stamp lines name the render a file was read against and are not content: every side takes
166
192
  // the fresh render's, so a fingerprint that moved never collides with one an edit carried.
167
- const { text, hunks } = mergeThreeWay(carryStamp(base, stamped), carryStamp(ours, stamped), stamped);
193
+ const merge = mergeThreeWay(carryStamp(base, stamped), carryStamp(ours, stamped), stamped);
194
+ const hunks = merge.hunks;
195
+ const text = filePath.endsWith('.java') ? keepUsedImports(ours, merge.text) : merge.text;
168
196
  if (hunks.length > 0) return { outcome: 'conflict', text, hunks };
169
197
  if (text === ours || text === carryStamp(ours, stamped)) return { outcome: 'current', text: ours };
170
198
  return { outcome: 'merged', text };
@@ -50,6 +50,7 @@ import dev.simplecore.searchable.core.condition.SearchCondition;
50
50
  import dev.simplecore.searchable.openapi.annotation.SearchableParams;
51
51
  import io.swagger.v3.oas.annotations.Operation;
52
52
  import io.swagger.v3.oas.annotations.tags.Tag;
53
+ import jakarta.validation.Valid;
53
54
  import org.springframework.data.domain.Page;
54
55
  <% if (exportConfig.enabled) { -%>
55
56
  import dev.simplecore.simplix.excel.export.ExportFormat;
@@ -179,13 +180,14 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
179
180
  /**
180
181
  * Updates multiple <%= entityName %> entities in a single operation.
181
182
  *
182
- * @param updateDtos set of DTOs containing update data
183
+ * @param updateDtos set of DTOs containing update data; {@code @Valid} on the element validates
184
+ * each one as a single update is, since a bare set is not validated
183
185
  * @return response containing the list of updated <%= classPrefix %>DetailDTOs
184
186
  */
185
187
  @PatchMapping
186
188
  @Operation(summary = "Update Multiple <%= entityName %>", description = "Updates multiple existing <%= entityName %>")
187
189
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
188
- public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> multiUpdate(@RequestBody Set<<%= classPrefix %>UpdateDTO> updateDtos) {
190
+ public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> multiUpdate(@RequestBody Set<@Valid <%= classPrefix %>UpdateDTO> updateDtos) {
189
191
  <% if (hasTreeEntity) { %>
190
192
  // TreeService doesn't support multiUpdate - use service instead
191
193
  List<<%= classPrefix %>DetailDTO> updatedItems = service.multiUpdate(updateDtos);
@@ -329,7 +331,7 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
329
331
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
330
332
  public SimpliXApiResponse<List<<%= classPrefix %>ListDTO>> updateTreeOrder(
331
333
  @RequestParam(required = false) <%= idType %> parentId,
332
- @RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
334
+ @RequestBody List<@Valid <%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
333
335
  try {
334
336
  List<<%= classPrefix %>ListDTO> updatedEntities = treeService.updateOrders(parentId, orderUpdateDtos);
335
337
  return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
@@ -350,7 +352,7 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
350
352
  @SimpliXStandardApi
351
353
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
352
354
  public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> updateOrder(
353
- @RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
355
+ @RequestBody List<@Valid <%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
354
356
  List<<%= classPrefix %>DetailDTO> updatedEntities = service.updateOrders(orderUpdateDtos);
355
357
  return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
356
358
  }