@neohm/nh-cli 1.1.1 → 1.1.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.
package/README.md CHANGED
@@ -90,13 +90,14 @@ created spreading `baseJobConstants` / `baseEntityConstants` /
90
90
  Generated artifacts extend the `@neohm/nestend` base classes:
91
91
 
92
92
  - Entity → `CommonEntity` (with an empty `attributes` jsonb column)
93
- - DTO → `CommonPayloadDto`
93
+ - DTO → `CommonDataDto`
94
94
  - Data processor → `CommonDataProcessor` (`process()` → `validate()` → `set()`)
95
95
  - Listing processor → `CommonListProcessor` (column allowlist config, `id` default sort). It takes `CommonListFilterDto` directly — no per-list DTO is generated, since paging, sorting, filters and free-text search all live on the base DTO and the filterable columns are declared in the processor's `columns` config.
96
96
 
97
97
  When both a controller and a listing processor are generated, the controller
98
98
  ships with a `POST list` endpoint that runs the listing processor (with
99
99
  `SqlService` injected via the constructor).
100
+
100
101
  - Migration → `MigrationUtility`
101
102
  - Seed → `SeederUtility`
102
103
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neohm/nh-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "nh — Command Line Interface for neohm. NestJS projects",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -222,6 +222,28 @@ async function gen() {
222
222
  );
223
223
  }
224
224
 
225
+ // 7. Optional: migration -------------------------------------------------
226
+ const { migration } = await inquirer.prompt([
227
+ {
228
+ type: "confirm",
229
+ name: "migration",
230
+ message: `Create migration (M-${n.migrationName})?`,
231
+ default: true,
232
+ },
233
+ ]);
234
+
235
+ if (migration) {
236
+ const ts = Date.now();
237
+ // Same filename/class rule as `nh migration`.
238
+ const file = naming.migrationFileName(n.migrationName, ts);
239
+ const migrationPath = path.join(paths.migrationsDir, file);
240
+ report(
241
+ writeFile(migrationPath, tpl.genMigration(entityName, tableName, ts)),
242
+ migrationPath,
243
+ paths.root,
244
+ );
245
+ }
246
+
225
247
  // Auto-wire: rebuild this module's barrel and register it in app.module.ts.
226
248
  log.info("\nWiring imports...");
227
249
  const mod = sync.scanModule(
@@ -27,7 +27,7 @@ async function migration() {
27
27
  ]);
28
28
 
29
29
  const ts = Date.now();
30
- const file = `${ts}M-${naming.toPascalCase(migrationName)}.ts`;
30
+ const file = naming.migrationFileName(migrationName, ts);
31
31
  const p = path.join(paths.migrationsDir, file);
32
32
  report(
33
33
  writeFile(p, tpl.migration(migrationName, tableName, ts)),
package/src/lib/naming.js CHANGED
@@ -42,10 +42,25 @@ function toKebabCase(input) {
42
42
  return toWords(input).join('-');
43
43
  }
44
44
 
45
+ /**
46
+ * `<timestamp>M-<PascalName>.ts` — the single migration filename rule, shared by
47
+ * `nh migration` and the migration `nh gen` scaffolds alongside an entity.
48
+ */
49
+ function migrationFileName(migrationName, timestamp) {
50
+ return `${timestamp}M-${toPascalCase(migrationName)}.ts`;
51
+ }
52
+
53
+ /** `<PascalName><timestamp>` — the class name matching migrationFileName(). */
54
+ function migrationClassName(migrationName, timestamp) {
55
+ return `${toPascalCase(migrationName)}${timestamp}`;
56
+ }
57
+
45
58
  module.exports = {
46
59
  toWords,
47
60
  toDotCase,
48
61
  toPascalCase,
49
62
  toCamelCase,
50
63
  toKebabCase,
64
+ migrationFileName,
65
+ migrationClassName,
51
66
  };
@@ -1,11 +1,17 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- const { toDotCase, toPascalCase, toKebabCase, toCamelCase } = require('./naming');
3
+ const {
4
+ toDotCase,
5
+ toPascalCase,
6
+ toKebabCase,
7
+ toCamelCase,
8
+ migrationClassName,
9
+ } = require("./naming");
4
10
 
5
11
  /**
6
12
  * Code templates. All generated code imports shared base classes from the
7
13
  * published library `@neohm/nestend` (verified exports: CommonEntity,
8
- * CommonPayloadDto, CommonDataProcessor, MigrationUtility, SeederUtility, etc.)
14
+ * CommonDataDto, CommonDataProcessor, MigrationUtility, SeederUtility, etc.)
9
15
  * and matches the dot.separated filename / PascalCase class conventions used
10
16
  * across nestjs-boilerplate.
11
17
  */
@@ -36,6 +42,9 @@ function names(base) {
36
42
  subscriberFile: `${dot}.subscriber.ts`,
37
43
  jobClass: `${pascal}Job`,
38
44
  jobFile: `${dot}.job.ts`,
45
+ // Fed through naming.migrationFileName/migrationClassName so the migration
46
+ // `nh gen` writes is named exactly like one from `nh migration`.
47
+ migrationName: `Add${pascal}Table`,
39
48
  };
40
49
  }
41
50
 
@@ -94,9 +103,9 @@ export class ${n.controllerClass} {
94
103
 
95
104
  function dto(base) {
96
105
  const n = names(base);
97
- return `import { CommonPayloadDto } from '@neohm/nestend';
106
+ return `import { CommonDataDto } from '@neohm/nestend';
98
107
 
99
- export class ${n.dtoClass} extends CommonPayloadDto {
108
+ export class ${n.dtoClass} extends CommonDataDto {
100
109
  // TODO: declare validated payload fields for ${n.pascal}.
101
110
  }
102
111
  `;
@@ -120,7 +129,7 @@ export class ${n.processorClass} extends CommonDataProcessor {
120
129
 
121
130
  private async validate() {
122
131
  // TODO: collect validation errors via this.addErrors({ column: 'message' }).
123
- this.throwExceptionOnError();
132
+ this.raiseExceptionOnValidationFailure();
124
133
  }
125
134
 
126
135
  private async set() {
@@ -206,7 +215,7 @@ export class ${n.jobClass} extends CommonJob {
206
215
  super(JobConstants.${n.camel}Job);
207
216
  }
208
217
 
209
- async handle(event: any): Promise<void> {
218
+ async handle(event: DataBaseEventDto<${n.entityClass}>): Promise<void> {
210
219
  return;
211
220
  }
212
221
  }
@@ -220,7 +229,7 @@ export class ${n.jobClass} extends CommonJob {
220
229
  */
221
230
  function genMigration(base, tableName, timestamp) {
222
231
  const n = names(base);
223
- const className = `Add${n.pascal}Table${timestamp}`;
232
+ const className = migrationClassName(n.migrationName, timestamp);
224
233
  return `import { MigrationUtility } from '@neohm/nestend';
225
234
 
226
235
  export class ${className} extends MigrationUtility {
@@ -242,7 +251,7 @@ export class ${className} extends MigrationUtility {
242
251
 
243
252
  /** Standalone migration (`nh migration`). */
244
253
  function migration(migrationName, tableName, timestamp) {
245
- const className = `${toPascalCase(migrationName)}${timestamp}`;
254
+ const className = migrationClassName(migrationName, timestamp);
246
255
  return `import { MigrationUtility } from '@neohm/nestend';
247
256
 
248
257
  export class ${className} extends MigrationUtility {