suppa-mcp-2 1.2.3 → 1.3.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.
@@ -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 })` |
13
+ | `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` — plus `subType: 'date'` when `classifyV1Field` returns `v2SubType: 'date'` (see below) |
14
14
  | `json` | `@Column({ type: FieldTypeEnum.JSON })` |
15
15
  | `uuid` | `@Column({ type: FieldTypeEnum.UUID })` |
16
16
  | `multi-language` | `@Column({ type: FieldTypeEnum.MultiLang })` |
@@ -30,9 +30,19 @@ The API migration path and this code path share one authority: `classifyV1Field(
30
30
 
31
31
  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
32
 
33
+ ## `v2SubType` — date-only v1 fields
34
+
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.
36
+
37
+ ```ts
38
+ @Column({ name: 'birthday', type: FieldTypeEnum.Timestamp, subType: 'date' })
39
+ birthday: string;
40
+ ```
41
+
42
+ 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.
43
+
33
44
  ## Documented open edges
34
45
 
35
- - `v2SubType: 'date'` (date-only v1 fields): `@Column()` has no documented `subType` option — emit `FieldTypeEnum.Timestamp` plus `// TODO: date-only in v1 — @Column has no documented date subtype; confirm rendering`.
36
46
  - Icon duality: default scalar `FieldTypeEnum.Icon`; relation form only if v1 reports `type: relation` targeting icons.
37
47
  - Lossy mappings carry the classifier's note as a trailing comment, e.g. `// v1 html_text → text (2.0 has no rich-text type)`.
38
48
 
@@ -19,7 +19,18 @@ import { pathToFileURL } from "node:url";
19
19
  export const SYSTEM_COLUMNS = ["id", "createdAt", "updatedAt", "deletedAt", "createdBy", "removedBy"];
20
20
  export const ACCESS_METADATA_KEYS = ["$readAccess", "$updateAccess", "$instanceAccess"];
21
21
  export const DOC_ENTITY_OPTIONS = ["name", "title", "comment", "representativeFieldName", "importKeyFields", "key", "icon", "type", "relationEntityName", "options"];
22
- export const DOC_COLUMN_OPTIONS = ["type", "name", "nullable", "primary", "unique", "default", "length", "title", "comment", "key", "minLength", "minValue", "maxValue", "decimalPlaces", "isOnlyPositive", "mask"];
22
+ export const DOC_COLUMN_OPTIONS = ["type", "subType", "name", "nullable", "primary", "unique", "default", "length", "title", "comment", "key", "minLength", "minValue", "maxValue", "decimalPlaces", "isOnlyPositive", "mask"];
23
+ /**
24
+ * The doc's subType matrix — "it means three unrelated things depending on the
25
+ * base type". Keyed by the CANONICAL FieldTypeEnum value, so E112 can be decided
26
+ * from whatever `checkColumn` resolved `type` to. The Enum/MultiEnum row of that
27
+ * matrix is deliberately absent: `subType` there is the enum's global name, set
28
+ * by @Enum()/@MultiEnum() and never written by hand — that is E113, not E112.
29
+ */
30
+ export const DOC_SUBTYPES_BY_TYPE = {
31
+ timestamp: ["date", "time", "timestamp"],
32
+ text: ["encrypted"],
33
+ };
23
34
  export const DOC_FIELD_TYPES = {
24
35
  Text: "text", Numeric: "numeric", Integer: "integer", Serial: "serial",
25
36
  Boolean: "boolean", Timestamp: "timestamp", JSON: "json", UUID: "uuid",
@@ -293,10 +304,20 @@ function analyzeEntities(ts, sf, model) {
293
304
  nameNode: columnOptions.get("name") ?? null,
294
305
  });
295
306
  } else if (ENUM_DECORATORS.has(d.name)) {
307
+ // (globalName?, Enum, titles?, options?) — the options object is
308
+ // the LAST argument when that is an object literal. An inline
309
+ // titles map occupies the same slot when options are omitted, so
310
+ // this node is only ever read for keys options own (E113's
311
+ // `subType`); a titles map never carries one.
312
+ const last = d.args[d.args.length - 1];
313
+ const enumOptionsNode =
314
+ d.args.length >= 2 && last && ts.isObjectLiteralExpression(last) ? last : null;
296
315
  info.properties.set(propName, {
297
316
  kind: d.name === "Enum" ? "enum" : "multi-enum",
298
317
  node: member, decorator: d,
299
318
  enumGlobalName: stringValue(ts, d.args[0]),
319
+ optionsNode: enumOptionsNode,
320
+ enumOptions: objectMap(ts, enumOptionsNode),
300
321
  });
301
322
  } else if (FILE_DECORATORS.has(d.name)) {
302
323
  info.properties.set(propName, {
@@ -479,7 +500,10 @@ function checkEntity(ts, info, sdk, model, findings) {
479
500
  findings.push(finding(ts, sf, prop.nameNode, "E102",
480
501
  `column name '${colName}' on property '${propName}' collides with the system column of the same name provided by SystemBaseEntity — "you never declare them yourself"`));
481
502
  }
482
- if (prop.kind === "column") checkColumn(ts, sf, prop, sdk, findings);
503
+ if (prop.kind === "column") checkColumn(ts, sf, propName, prop, sdk, findings);
504
+ if (prop.kind === "enum" || prop.kind === "multi-enum") {
505
+ checkEnumSubType(ts, sf, propName, prop, findings);
506
+ }
483
507
  if (RELATION_KINDS.has(prop.kind)) {
484
508
  if (prop.targetClass === null) {
485
509
  findings.push(finding(ts, sf, prop.node, "E105",
@@ -526,7 +550,21 @@ function checkInverseSelector(ts, sf, propName, prop, model, findings) {
526
550
  `inverse selector on '${propName}' (@${prop.decorator.name}) targets '${target.entityName}.${accessed}', but ${reason} — an inverse selector must select the RELATION property on the target that holds the OTHER SIDE of this relation, e.g. (task) => task.project`));
527
551
  }
528
552
 
529
- function checkColumn(ts, sf, prop, sdk, findings) {
553
+ /**
554
+ * E113 — "@Enum() and @MultiEnum() fill it from their first argument […] do not
555
+ * pass subType yourself on an enum field". Passing one by hand either duplicates
556
+ * what the decorator already writes or silently disagrees with it, and the value
557
+ * it disagrees with is the one that resolves { value: 'active' } to an enum
558
+ * record on insert.
559
+ */
560
+ function checkEnumSubType(ts, sf, propName, prop, findings) {
561
+ const subTypeNode = prop.enumOptions?.get("subType");
562
+ if (!subTypeNode) return;
563
+ findings.push(finding(ts, sf, subTypeNode, "E113",
564
+ `'${propName}' (@${prop.decorator.name}) passes 'subType' by hand — on an enum field subType holds the enum's global name and is "Set by the decorator — never by hand"; @Enum()/@MultiEnum() fill it from their first argument (or derive <ClassName>.<propertyName>). Remove the option.`));
565
+ }
566
+
567
+ function checkColumn(ts, sf, propName, prop, sdk, findings) {
530
568
  const opts = prop.columnOptions;
531
569
  for (const [opt, valNode] of opts) {
532
570
  if (!sdk.columnOptions.includes(opt)) {
@@ -584,6 +622,8 @@ function checkColumn(ts, sf, prop, sdk, findings) {
584
622
  `cannot statically verify that 'default' is a SQL expression string — it is delivered by reference or by an expression this checker cannot evaluate, so the check is skipped; inline a literal SQL string to restore checking`));
585
623
  }
586
624
  }
625
+ checkSubType(ts, sf, propName, prop, typeValue, findings);
626
+
587
627
  if (opts.has("length") && typeValue !== null && typeValue !== "text") {
588
628
  findings.push(finding(ts, sf, opts.get("length"), "W603",
589
629
  `'length' caps Text columns; this column is '${typeValue}'`));
@@ -594,6 +634,36 @@ function checkColumn(ts, sf, prop, sdk, findings) {
594
634
  }
595
635
  }
596
636
 
637
+ /**
638
+ * E112 — a subType string that the doc's matrix does not pair with this base
639
+ * type. Only two rows of that matrix belong to @Column(): Timestamp takes
640
+ * 'date' | 'time' | 'timestamp' ("Chooses the physical column type"), Text takes
641
+ * 'encrypted'. Anything else is rejected by the platform, not by tsc — `subType`
642
+ * is typed as a plain string, so a wrong pairing compiles.
643
+ *
644
+ * `subType: null` is the DOCUMENTED way to clear a subtype ("write subType: null
645
+ * explicitly") and is always clean. A value this AST-only checker cannot read
646
+ * takes the usual W606 unverifiable path — never E112. An unresolved `type`
647
+ * leaves nothing to judge the pairing against, so the check is skipped.
648
+ */
649
+ function checkSubType(ts, sf, propName, prop, typeValue, findings) {
650
+ const node = prop.columnOptions.get("subType");
651
+ if (!node) return;
652
+ const val = unwrapExpr(ts, node);
653
+ if (val.kind === ts.SyntaxKind.NullKeyword) return; // the documented "clear it"
654
+ const raw = stringValue(ts, val);
655
+ if (raw === null) {
656
+ findings.push(finding(ts, sf, node, "W606",
657
+ `cannot statically verify 'subType' of '${propName}' — it is delivered by reference or by an expression this checker cannot evaluate, so the base-type pairing check (E112) is skipped; inline the string literal to restore checking`));
658
+ return;
659
+ }
660
+ if (typeValue === null) return; // no readable `type` to pair it against
661
+ const allowed = DOC_SUBTYPES_BY_TYPE[typeValue];
662
+ if (allowed && allowed.includes(raw)) return;
663
+ findings.push(finding(ts, sf, node, "E112",
664
+ `subType '${raw}' is not valid on a '${typeValue}' column ('${propName}') — the doc's matrix pairs subType with exactly two @Column base types: Timestamp takes 'date', 'time' or 'timestamp', and Text takes 'encrypted'. No other (type, subType) combination exists.`));
665
+ }
666
+
597
667
  // ── extraction: string enums (createSeed(EnumName.Member) resolution) ──
598
668
  function analyzeEnums(ts, sf, model) {
599
669
  sf.forEachChild(function walk(node) {
@@ -55,6 +55,19 @@ export class __EntityName__ extends SystemBaseEntity {
55
55
  @Column({ name: 'amount', type: FieldTypeEnum.Numeric, decimalPlaces: 2 })
56
56
  amount: number;
57
57
 
58
+ // Date-only column — there is no FieldTypeEnum.Date; it is Timestamp + subType.
59
+ // CAVEAT: subType is fixed at creation — getting 'date' vs plain timestamp
60
+ // wrong later means a NEW field, not a conversion.
61
+ // @Column({ name: 'birthday', type: FieldTypeEnum.Timestamp, subType: 'date' })
62
+ // birthday: string;
63
+
64
+ // Encrypted at rest — Text only.
65
+ // CAVEAT: the platform forces unique/searchable/canFilter/canSort/canGroup to
66
+ // false and clears maxLength/minLength/mask — keep anything users must search
67
+ // in a separate plaintext column.
68
+ // @Column({ name: 'payload', type: FieldTypeEnum.Text, subType: 'encrypted' })
69
+ // payload: string;
70
+
58
71
  // Relation — ALWAYS a thunk (() => Target), never the class itself.
59
72
  // No inverse passed — it's optional on @ManyToOne and omitted by default.
60
73
  @ManyToOne(() => __TargetEntity__, { nullable: false })