suppa-mcp-2 1.4.1 → 1.6.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.
@@ -40,7 +40,7 @@ Confirm all 5 before writing anything:
40
40
  ## Hard rules
41
41
 
42
42
  1. Every entity extends `SystemBaseEntity`; never declare `id`, `createdAt`, `updatedAt`, `deletedAt`, `createdBy`, `removedBy` yourself — it already provides them.
43
- 2. An entity class that is not in `EntityModule.forFeature()` does not exist — the platform creates no table for it (doc: "An entity class that is never passed to forFeature() is invisible"). Write the entity and register it in the SAME step; never move on to the next entity, or report progress, with an unregistered class.
43
+ 2. An entity class that is not in `EntityModule.forFeature()` does not exist — the platform creates no table for it (doc: "An entity class that is never passed to forFeature() is invisible"). Write the entity and register it in the SAME step; never move on to the next entity, or report progress, with an unregistered class. Being *named* in a `forFeature()` is not enough: the call's result must be consumed by an `@Module`'s `imports` (rule 19), or nothing is registered at all.
44
44
  3. `default` is a SQL expression string — `'false'`, `"'draft'"` — never a JS value; a JS value is rejected at migration time.
45
45
  4. Scalars only via `@Column({ type: FieldTypeEnum.X })`; relations/enums/files are NEVER declared via `@Column` — use the `@ManyToOne`/`@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef`/`@Enum`/`@MultiEnum`/`@File`/`@MultiFile` families.
46
46
  5. Relation targets are thunks — `() => Target`, never the class itself — or circular imports break.
@@ -57,7 +57,7 @@ Confirm all 5 before writing anything:
57
57
  16. **Never write an option that already holds its default value.** The platform applies `canGroup: true`, `canSort: true`, `showInTable: true`, `editFromTable: true`, `canFilter: true`, `readOnly: false`, `searchable: false` on its own. Declare one of these ONLY where the field departs from it; repeating defaults on every field buries the one option that actually differs. W612.
58
58
  17. **`@Enum`/`@MultiEnum` take the global name only when the enum is global.** Default is local: `@Enum(StageStatusEnum, StageStatus, { nullable: false })` — the decorator derives `<ClassName>.<propertyName>`. Pass the name as the FIRST argument only when the value set is shared across entities or referenced from a seed: `@Enum('StageWorkflows.status', StageStatusEnum, StageStatus, { … })`. W613.
59
59
  18. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
60
- 19. **`EntityModule.forFeature()` has exactly two shapes** (`references/registration.md`): `forFeature([A, B], { seeds: [...] })` — classes FIRST, options second — or `forFeature({ entitiesPath, seedsPath })` for autoloading. The options object accepts only `seeds`, `entitiesPath` and `seedsPath`. `forFeature({ entities: [...] })` looks reasonable and registers NOTHING: the classes are dropped with the unknown option and no table is created for any of them. E306.
60
+ 19. **`EntityModule.forFeature()` must be consumed by an `@Module`, and has exactly two shapes.** It RETURNS a module: put it in `@Module({ imports: [...] })` and export that class from `src/index.ts` as `AppModule` — a bare `EntityModule.forFeature(...);` statement discards the result and registers nothing (E307). The two shapes (`references/registration.md`) are `forFeature([A, B], { seeds: [...] })` — classes FIRST, options second — and `forFeature({ entitiesPath, seedsPath })` for autoloading. The options object accepts only `seeds`, `entitiesPath` and `seedsPath`. `forFeature({ entities: [...] })` looks reasonable and registers NOTHING: the classes are dropped with the unknown option and no table is created for any of them. E306.
61
61
 
62
62
  ## Decorator decision table
63
63
 
@@ -162,17 +162,32 @@ Four edits, every time:
162
162
 
163
163
  ```ts
164
164
  // before
165
- EntityModule.forFeature([Workflows], { seeds: [workflowsSeed] });
165
+ import { Module } from '@nestjs/common';
166
+ import { EntityModule } from '@suppa/sdk';
167
+ import { Workflows } from '../common/database/entities';
168
+ import { workflowsSeed } from '../common/database/seeds';
169
+
170
+ @Module({
171
+ imports: [EntityModule.forFeature([Workflows], { seeds: [workflowsSeed] })],
172
+ })
173
+ export class AppModule {}
166
174
 
167
175
  // after — new import, new entity, new seed
168
176
  import { MyNewEntity } from '../common/database/entities';
169
177
  import { myNewEntitySeed } from '../common/database/seeds';
170
178
 
171
- EntityModule.forFeature([Workflows, MyNewEntity], {
172
- seeds: [workflowsSeed, myNewEntitySeed],
173
- });
179
+ @Module({
180
+ imports: [
181
+ EntityModule.forFeature([Workflows, MyNewEntity], {
182
+ seeds: [workflowsSeed, myNewEntitySeed],
183
+ }),
184
+ ],
185
+ })
186
+ export class AppModule {}
174
187
  ```
175
188
 
189
+ **forFeature() RETURNS a module — something must consume it.** It goes in the `imports` of an `@Module`. Called as a bare statement the returned module is thrown away and NOTHING is registered, while the call still looks exactly like working code (E307). And `src/index.ts` must export `AppModule`: the runner imports your package from there and expects to find it.
190
+
176
191
  **The shape is not negotiable.** There are exactly two (`references/registration.md`): the classes as the FIRST argument with an options object second, or an options object alone that autoloads from `entitiesPath`/`seedsPath`. The options object accepts only `seeds`, `entitiesPath` and `seedsPath` — there is no `entities` option:
177
192
 
178
193
  ```ts
@@ -213,6 +228,7 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
213
228
  |---|---|---|
214
229
  | No table is created for an entity | The class was not passed to `EntityModule.forFeature()` | E301 |
215
230
  | No table is created for ANY entity, and the registration looks right | `forFeature({ entities: [...] })` — an invented shape; the classes go in the FIRST argument and the options object has no `entities` key | E306 |
231
+ | Every entity is missing its table, and the registration reads correctly | `forFeature()` called as a bare statement — the module it returns is discarded | E307 — put it in `@Module({ imports: [...] })` and export `AppModule` from `src/index.ts` |
216
232
  | E301 never fires even though an entity is clearly unregistered | A `forFeature()` names neither a class array nor `entitiesPath`, so membership is unknown and the check is skipped for the whole run | W614 |
217
233
  | Autoloading finds nothing | `entitiesPath` / `seedsPath` points at `src/` instead of compiled `dist/` | E303 |
218
234
  | Duplicate seed rows after a restart | Record is missing one or more `importKeyFields` | E205 |
@@ -10,7 +10,7 @@ The API migration path and this code path share one authority: `classifyV1Field(
10
10
  | `numeric` | `@Column({ type: FieldTypeEnum.Numeric })` |
11
11
  | `integer` | `@Column({ type: FieldTypeEnum.Integer })` |
12
12
  | `boolean` | `@Column({ type: FieldTypeEnum.Boolean })` |
13
- | `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` — plus `subType: 'date'` when `classifyV1Field` returns `v2SubType: 'date'` (see below) |
13
+ | `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` — plus `subType: 'date'` or `subType: 'time'` when `classifyV1Field` returns that `v2SubType` (see below) |
14
14
  | `json` | `@Column({ type: FieldTypeEnum.JSON })` |
15
15
  | `uuid` | `@Column({ type: FieldTypeEnum.UUID })` |
16
16
  | `multi-language` | `@Column({ type: FieldTypeEnum.MultiLang })` |
@@ -21,22 +21,34 @@ The API migration path and this code path share one authority: `classifyV1Field(
21
21
  | `multi-file` | `@MultiFile({ title: … })` |
22
22
  | `many-to-one` | `@ManyToOne(() => <TargetClass>)` |
23
23
  | `many-to-many` | `@ManyToMany(() => <TargetClass>)` |
24
- | `one-to-many` | `@OneToMany(() => <TargetClass>, <inverse>)` — **inverse is a blocking question** (v1 props don't name it) |
25
- | `many-to-many-backref` | `@ManyToManyBackRef(() => <TargetClass>, <inverse>)` — **inverse is a blocking question** |
26
- | `serial` | never emitted — `SystemBaseEntity.id` already provides it |
24
+ | `one-to-many` | `@OneToMany(() => <TargetClass>, <inverse>)` — **inverse is a blocking question** (v1 props don't name it). NEVER produced by `classifyV1Field` — see the warning below |
25
+ | `many-to-many-backref` | `@ManyToManyBackRef(() => <TargetClass>, <inverse>)` — **inverse is a blocking question**. NEVER produced by `classifyV1Field` |
26
+ | `serial` | never emitted — `SystemBaseEntity.id` already provides it, and `classifyV1Field` never returns it |
27
27
  | kind = `skip` | emit `// SKIPPED: <field> — <note from classifyV1Field>` inside the class body — never silently drop a field |
28
28
 
29
+ > **This table is keyed on the CLASSIFIER'S OUTPUT (`v2Type`), never on a raw v1 `sub_type`.**
30
+ > The distinction matters most for one string: v1 reports `sub_type: 'one-to-many'` on an ordinary
31
+ > foreign-key column, and `classifyV1Field` maps that to **`many-to-one`** (`v1Fields.ts` —
32
+ > `"one-to-many": ["many-to-one", false]`). Matching the raw v1 string against the left column
33
+ > instead would emit `@OneToMany`, a back reference, where `@ManyToOne` is correct — the FK would
34
+ > never be created. The `one-to-many`, `many-to-many-backref` and `serial` rows exist only to say
35
+ > what to write IF that v2 type ever reaches you: the reverse-side decorators are authored,
36
+ > parent-side additions you add deliberately, never products of the migration.
37
+
29
38
  ### Never drop a field silently
30
39
 
31
40
  If `classifyV1Field` returns `kind = 'skip'` — a system/structural field, an unsupported relation sub_type, or an unrecognized v1 type — the field must still appear in the generated class as a `// SKIPPED: <field> — <reason>` comment, using the classifier's own note as `<reason>`. Omitting it is not an option: the generated code must account for every v1 field, migrated or not.
32
41
 
33
- ## `v2SubType` — date-only v1 fields
42
+ ## `v2SubType` — date-only and time-only v1 fields
34
43
 
35
- `classifyV1Field` returns `v2SubType: 'date'` for a v1 date-only field. That maps to a documented option: `FieldTypeEnum.Timestamp` + `subType: 'date'`, which the platform turns into a real Postgres `date` column.
44
+ `classifyV1Field` returns `v2SubType: 'date'` for a v1 date-only field and `v2SubType: 'time'` for a time-only one. Both map to a documented option: `FieldTypeEnum.Timestamp` plus that `subType`, which the platform turns into a real Postgres `date` / `time` column. There is no `FieldTypeEnum.Date` and no `FieldTypeEnum.Time`.
36
45
 
37
46
  ```ts
38
47
  @Column({ name: 'birthday', type: FieldTypeEnum.Timestamp, subType: 'date' })
39
48
  birthday: string;
49
+
50
+ @Column({ name: 'opensAt', type: FieldTypeEnum.Timestamp, subType: 'time' })
51
+ opensAt: string;
40
52
  ```
41
53
 
42
54
  Get it right the first time: `subType` is immutable after creation except for the `'encrypted'` toggle, so a field created as plain `timestamp` cannot later be converted to `date` — it has to be replaced by a new field. Never emit `subType` on an `@Enum`/`@MultiEnum` field; the decorator writes it.