suppa-mcp-2 1.13.1 → 1.15.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/README.md CHANGED
@@ -378,9 +378,14 @@ shipped with restated defaults and four bare relation stand-ins. Install the
378
378
  guards into an application repo:
379
379
 
380
380
  ```bash
381
+ npx suppa-entity-guards .
382
+ # or, without npx:
381
383
  node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/install-entity-code-guards.mjs .
382
384
  ```
383
385
 
386
+ It is idempotent, and it refuses to write a hook whose path does not resolve —
387
+ hooks pointing at nothing behave exactly like no hooks at all.
388
+
384
389
  Five layers, each covering a way the previous one is missed: Claude Code hooks
385
390
  put the rules in an agent's context **before** it writes `*.entity.ts` and the
386
391
  gate's findings in front of it **after**, a `Stop` hook refuses to end a turn
package/dist/server.js CHANGED
@@ -2187,9 +2187,10 @@ export function buildServer() {
2187
2187
  " columns, in <owner>.extension.entity.ts. Extension mode ignores entity options\n" +
2188
2188
  " (W618), refuses @OneToMany/@ManyToManyBackRef (E118) and primary: true (E119),\n" +
2189
2189
  " requires a default with nullable: false (E120), and allows @Index/@Check over your\n" +
2190
- " own columns only, listed literally (E121/E122). A relation there names its\n" +
2191
- " target by string and is typed\n" +
2192
- " by shape — that form is W620 anywhere else;\n" +
2190
+ " own columns only, listed literally (E121/E122). Write every options object\n" +
2191
+ " out literally: one passed by reference or spread hides all of that (E123). A\n" +
2192
+ " relation there names its target by string and is typed by shape — that form\n" +
2193
+ " is W620 anywhere else;\n" +
2193
2194
  " * 'owner' comes first in a tabular part's importKeyFields, and no 'inverse' is passed\n" +
2194
2195
  " to @ManyToOne/@ManyToMany.\n" +
2195
2196
  ' Pass the app ROOT, not one file: several rules read the whole repo ("nothing references\n' +
package/package.json CHANGED
@@ -1,61 +1,62 @@
1
- {
2
- "name": "suppa-mcp-2",
3
- "version": "1.13.1",
4
- "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
- "type": "module",
6
- "bin": {
7
- "suppa-mcp": "dist/bin.js"
8
- },
9
- "main": "dist/bin.js",
10
- "files": [
11
- "dist",
12
- "skills",
13
- "README.md",
14
- "LICENSE"
15
- ],
16
- "engines": {
17
- "node": ">=18"
18
- },
19
- "scripts": {
20
- "build": "tsc",
21
- "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
22
- "rebuild": "npm run clean && npm run build",
23
- "start": "node dist/bin.js",
24
- "dev": "tsc --watch",
25
- "test": "node scripts/check-version-literals.mjs && vitest run",
26
- "test:watch": "vitest",
27
- "prepublishOnly": "npm run build && npm test",
28
- "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
29
- "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
30
- "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
31
- },
32
- "keywords": [
33
- "mcp",
34
- "model-context-protocol",
35
- "suppa",
36
- "modern-expo",
37
- "ai",
38
- "llm",
39
- "tools",
40
- "claude",
41
- "copilot",
42
- "cursor"
43
- ],
44
- "license": "MIT",
45
- "repository": {
46
- "type": "git",
47
- "url": "https://git.modern-expo.com/asu/me-development/skills.git",
48
- "directory": "suppa-mcp-node"
49
- },
50
- "homepage": "https://modern.suppa.me",
51
- "dependencies": {
52
- "@modelcontextprotocol/sdk": "^1.18.0",
53
- "@napi-rs/keyring": "^1.1.0",
54
- "zod": "^3.23.8"
55
- },
56
- "devDependencies": {
57
- "@types/node": "^20.0.0",
58
- "typescript": "^5.6.0",
59
- "vitest": "^2.1.0"
60
- }
61
- }
1
+ {
2
+ "name": "suppa-mcp-2",
3
+ "version": "1.15.0",
4
+ "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
+ "type": "module",
6
+ "bin": {
7
+ "suppa-mcp": "dist/bin.js",
8
+ "suppa-entity-guards": "skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
9
+ },
10
+ "main": "dist/bin.js",
11
+ "files": [
12
+ "dist",
13
+ "skills",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
23
+ "rebuild": "npm run clean && npm run build",
24
+ "start": "node dist/bin.js",
25
+ "dev": "tsc --watch",
26
+ "test": "node scripts/check-version-literals.mjs && vitest run",
27
+ "test:watch": "vitest",
28
+ "prepublishOnly": "npm run build && npm test",
29
+ "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js",
30
+ "schema:gate": "node skills/suppa-entity-code/scripts/entity-code-guard.mjs --ci .",
31
+ "guards:install": "node skills/suppa-entity-code/scripts/install-entity-code-guards.mjs"
32
+ },
33
+ "keywords": [
34
+ "mcp",
35
+ "model-context-protocol",
36
+ "suppa",
37
+ "modern-expo",
38
+ "ai",
39
+ "llm",
40
+ "tools",
41
+ "claude",
42
+ "copilot",
43
+ "cursor"
44
+ ],
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://git.modern-expo.com/asu/me-development/skills.git",
49
+ "directory": "suppa-mcp-node"
50
+ },
51
+ "homepage": "https://modern.suppa.me",
52
+ "dependencies": {
53
+ "@modelcontextprotocol/sdk": "^1.18.0",
54
+ "@napi-rs/keyring": "^1.1.0",
55
+ "zod": "^3.23.8"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "^20.0.0",
59
+ "typescript": "^5.6.0",
60
+ "vitest": "^2.1.0"
61
+ }
62
+ }
@@ -88,6 +88,7 @@ Confirm all 5 before writing anything:
88
88
  | No `primary: true` | "the owner's primary key is not yours to redefine" | **E119** |
89
89
  | No `nullable: false` without a `default` | the table already has rows, and each needs a value | **E120** |
90
90
  | `@Index` / `@Check` only over columns YOU declare, and spelled out as a literal array | anything else reaches into another owner's schema — and a column list passed by reference cannot be checked at all | **E121** / **E122** |
91
+ | Every options object written out literally, on `@Entity()` and on each field | the restrictions above are all read out of those objects; one passed by reference or carrying a spread hides `primary`, `nullable` — and which entity this even extends | **E123** |
91
92
 
92
93
  Allowed, and unchanged from your own entities: `@Column()` of any type, `@ManyToOne`, `@ManyToMany`, `@Enum`, `@MultiEnum`, `@File`, `@MultiFile`. Your columns are real columns on the owner's table — selectable, filterable, in metadata, in history — and they follow the same remove/restore semantics as your own. You cannot remove a field you do not own; it is not in your declaration to begin with.
93
94
  **A name collision fails the build and applies nothing** — `cannot declare field "Tasks.plan": it already exists and is owned by application "Planner"` — by NAME, not by key, and a soft-deleted field keeps its name reserved. A field a user added through the UI is *not* an owner: your declaration takes it over, data and all.
@@ -312,6 +313,8 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
312
313
  | `nullable: false` on an extension column | The table already has rows; each needs a value, so a `default` is mandatory (and on a big table, ship it nullable and backfill separately) | E120 |
313
314
  | An extension's `@Index`/`@Check` names a column it does not declare | An extension may only index or constrain its OWN columns | E121 |
314
315
  | An extension's `@Index`/`@Check` gets its columns from a const, a spread or an options object | The documented shape is `@Index('<name>', ['<column>'])`. A list the checker cannot read leaves E121 unchecked — and it compiles, so it ships | E122 |
316
+ | An extension passes options by reference (`@Entity(OPTS)`, `@Column(OPTS)`) or spreads them | Extension mode's whole restriction set is read out of those objects — including which entity is being extended. Inline them | E123 |
317
+ | Two entity classes share a name across files | The checker keys entities by class name, so only the first is analyzed and the other is schema code nothing checked. Rename one class — the table's name is the `@Entity({ name })` option and does not change | W619 (blocks the gate) |
315
318
  | The build stops with `cannot declare field "X.y": it already exists and is owned by application "Z"` | Field names have exactly one owner, matched by NAME (not key) — and a soft-deleted field keeps its name reserved. Nothing is applied. Rename yours, or agree with that team | not statically checkable |
316
319
  | The build stops with `refusing to build system metadata: this is an application build but applicationId is missing` | The platform is older than extension mode, or the runner does not pass the application id. Update the platform — there is nothing to change in the code | not statically checkable |
317
320
  | A relation names its target with a string (`@ManyToOne('Invoices', …)`) in an ordinary entity | That form is for extensions, where the target belongs to another application and there is no class to import | W620 (blocks the gate) |
@@ -133,6 +133,6 @@ export class TasksBillingExtension extends SystemBaseEntity {
133
133
  After both applications start, the `Tasks` table has `name`, `plan` and `invoiceId`. Planner's declaration is unchanged and unaware of the two extra columns; Billing owns them and can alter, remove or restore them. Neither application can modify the other's fields, and `Tasks` itself — its title, its representative field — still belongs to Planner.
134
134
 
135
135
  > **HOUSE RULE — the filename declares the intent (SKILL.md rule 20).**
136
- > Nothing in the code above says which mode it will get: the platform decides by ownership at start. Name the file `<owner-entity>.extension.entity.ts` and the class `<EntityName>Extension`, as the doc's own examples do. That is what lets the validator apply the restrictions in this section BEFORE the build refuses them — W618, E118, E119, E120, E121 — instead of after. Write an index's column list as a literal array while you are here: `@Index('idx', COLUMNS)` compiles and therefore ships, and nothing can then tell whether it reaches into the owner's schema (E122).
136
+ > Nothing in the code above says which mode it will get: the platform decides by ownership at start. Name the file `<owner-entity>.extension.entity.ts` and the class `<EntityName>Extension`, as the doc's own examples do. That is what lets the validator apply the restrictions in this section BEFORE the build refuses them — W618, E118, E119, E120, E121 — instead of after. Write an index's column list as a literal array while you are here: `@Index('idx', COLUMNS)` compiles and therefore ships, and nothing can then tell whether it reaches into the owner's schema (E122). The same holds for the options objects themselves: `@Entity(OPTS)` or `@Column(OPTS)` hides `primary`, `nullable` and even which entity is being extended, so an extension writes them out literally (E123).
137
137
  >
138
138
  > Note the relation form: `@ManyToOne('Invoices', …)` names the target by STRING, because there is no class to import for an entity another application owns, and the property is typed by shape — `invoice?: { id: number }`. That is right here and only here; in your own entities a relation target is a thunk (rule 5), and the string form is W620.
@@ -20,7 +20,7 @@ These six rules are house rules of this platform. They OVERRIDE the platform's o
20
20
  3. NEVER WRITE A FIELD OPTION AT ITS DEFAULT. canGroup, canSort, showInTable, editFromTable and canFilter are already true; readOnly and searchable are already false. Write one ONLY where the field departs from that (usually just \`searchable: true\`). A field with all seven spelled out is wrong even though it works.
21
21
  4. @Enum/@MultiEnum TAKE THE GLOBAL NAME ONLY WHEN THE ENUM IS GLOBAL — shared by another entity, or referenced from a seed record. Otherwise omit the first argument entirely: \`@Enum(StatusEnum, StatusTitles, { … })\`, and the decorator derives <ClassName>.<propertyName>. A field's own \`key: 'Entity.field'\` is the rename key, NOT a reference, and does not make the enum global.
22
22
  5. A RELATION TARGET THAT ALREADY EXISTS on the tenant (created earlier, or owned by another application) gets a STUB, and a stub is three things at once: \`@Entity({ name: 'Accounts', key: 'Accounts' }) export class Accounts extends SystemBaseEntity {}\` with an EMPTY body, ALONE in a file named \`accounts.stub.entity.ts\`, and REGISTERED in forFeature() with the entities you create. Never a bare \`export class Accounts {}\` — it satisfies the thunk but registers nothing, so the platform cannot resolve the relation (E116). Never fields on a stub — a stub only stands in so a relation can point at the table (E117); to ADD columns there, see rule 6. Platform system entities need no stub — import UsersEntity/FilesEntity/IconsEntity from @suppa/sdk.
23
- 6. TO ADD COLUMNS TO AN ENTITY YOU DO NOT OWN, DECLARE AN EXTENSION — not a stub, and there is no separate API. Declare the entity by its EXISTING name with only your own columns, in a file named \`<owner-entity>.extension.entity.ts\` (class \`<OwnerEntity>Extension\`), and register it like any other entity: \`@Entity({ name: 'Users' }) export class UsersExtension extends SystemBaseEntity { @Column({ type: FieldTypeEnum.Numeric, nullable: true }) accountId?: number; }\`. The platform picks the mode by OWNERSHIP at start. In extension mode: entity options are IGNORED (title/icon/type/options/representativeFieldName/importKeyFields — W618), no @OneToMany or @ManyToManyBackRef (E118), no \`primary: true\` (E119), no \`nullable: false\` without a default (E120), and @Index/@Check only over your own columns, listed as a literal array (E121/E122). A relation to an entity you do not own is named by STRING and typed by shape — \`@ManyToOne('Invoices', { … }) invoice?: { id: number };\` — which is right there and nowhere else (W620).
23
+ 6. TO ADD COLUMNS TO AN ENTITY YOU DO NOT OWN, DECLARE AN EXTENSION — not a stub, and there is no separate API. Declare the entity by its EXISTING name with only your own columns, in a file named \`<owner-entity>.extension.entity.ts\` (class \`<OwnerEntity>Extension\`), and register it like any other entity: \`@Entity({ name: 'Users' }) export class UsersExtension extends SystemBaseEntity { @Column({ type: FieldTypeEnum.Numeric, nullable: true }) accountId?: number; }\`. The platform picks the mode by OWNERSHIP at start. In extension mode: entity options are IGNORED (title/icon/type/options/representativeFieldName/importKeyFields — W618), no @OneToMany or @ManyToManyBackRef (E118), no \`primary: true\` (E119), no \`nullable: false\` without a default (E120), and @Index/@Check only over your own columns, listed as a literal array (E121/E122). Write the options out as literal objects: an @Entity() or @Column() options object delivered by reference or through a spread cannot be read, so none of those restrictions can be checked on it (E123). A relation to an entity you do not own is named by STRING and typed by shape — \`@ManyToOne('Invoices', { … }) invoice?: { id: number };\` — which is right there and nowhere else (W620).
24
24
  Before reporting the file done, run the gate: call suppa_validate_entity_code(path=<app-root>). It fails on every one of the six and names file:line. passed=false means fix and re-run, not "note and move on". (Same checker on the command line: node node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs <app-root>.)`;
25
25
 
26
26
  /** What the gate blocks on, for a message that must not understate it. */
@@ -28,6 +28,7 @@ export const BLOCKING_SUMMARY =
28
28
  "relation typing (E114/E115/W610/W615), PascalCase enum keys (W611), no option written at its " +
29
29
  "default (W612), no global enum name on a local enum (W613), existing-entity stubs " +
30
30
  "(E116/E117/W616/W617), extension mode — ignored entity options, no reverse relations, no primary, " +
31
- "no NOT NULL without a default, indexes over your own columns only (W618/E118/E119/E120/E121/E122/W620), " +
32
- "`owner` first in a tabular part's importKeyFields (W607), and no " +
31
+ "no NOT NULL without a default, indexes over your own columns only (W618/E118/E119/E120/E121/E122/E123/W620), " +
32
+ "`owner` first in a tabular part's importKeyFields (W607), no second entity class of the same name — " +
33
+ "the other one is then analyzed by nothing (W619) — and no " +
33
34
  "`inverse` on @ManyToOne/@ManyToMany (W609)";
@@ -26,7 +26,7 @@
26
26
 
27
27
  import { execFileSync } from "node:child_process";
28
28
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
29
- import { dirname, join, relative, resolve } from "node:path";
29
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
30
30
  import { fileURLToPath } from "node:url";
31
31
 
32
32
  const HERE = dirname(fileURLToPath(import.meta.url));
@@ -61,16 +61,36 @@ function readIfExists(path) {
61
61
  }
62
62
  }
63
63
 
64
+ /**
65
+ * The guard's path RELATIVE to the repo, or null when it lives outside it.
66
+ *
67
+ * `relative()` returns an ABSOLUTE path when the two sides sit on different
68
+ * Windows drives — a global install, or the repo on another drive. That path
69
+ * does not start with "..", so the old test read it as "inside the repo" and
70
+ * wrote `${CLAUDE_PROJECT_DIR}/D:/…`: a path that can never resolve, on hooks
71
+ * that then do nothing and say nothing. Guards installed and silently dead is
72
+ * the exact failure this installer exists to prevent.
73
+ */
74
+ function guardRelativeToRoot() {
75
+ const rel = relative(root, GUARD);
76
+ return rel && !rel.startsWith("..") && !isAbsolute(rel) ? rel.replace(/\\/g, "/") : null;
77
+ }
78
+
64
79
  /**
65
80
  * How the hook command should name the guard. Inside the repo (the normal
66
81
  * `pnpm add -D suppa-mcp-2` case) it is written relative to the project so the
67
82
  * settings file stays portable across machines; outside it, absolutely.
68
83
  */
69
84
  function guardPath() {
70
- const rel = relative(root, GUARD);
71
- return !rel.startsWith("..")
72
- ? `\${CLAUDE_PROJECT_DIR}/${rel.replace(/\\/g, "/")}`
73
- : GUARD.replace(/\\/g, "/");
85
+ const rel = guardRelativeToRoot();
86
+ return rel ? `\${CLAUDE_PROJECT_DIR}/${rel}` : GUARD.replace(/\\/g, "/");
87
+ }
88
+
89
+ /** Does the path just written actually land on the guard? */
90
+ function guardPathResolves(written) {
91
+ const prefix = "${CLAUDE_PROJECT_DIR}/";
92
+ const resolved = written.startsWith(prefix) ? join(root, written.slice(prefix.length)) : written;
93
+ return existsSync(resolved);
74
94
  }
75
95
 
76
96
  // ── 1. Claude Code hooks ──
@@ -87,6 +107,16 @@ function installHooks() {
87
107
  }
88
108
  }
89
109
  const guard = guardPath();
110
+ if (!guardPathResolves(guard)) {
111
+ // Never write a hook that points at nothing: it behaves exactly like no
112
+ // hook at all — no rules before the write, no gate after, and no message
113
+ // either way.
114
+ skipped.push(
115
+ `.claude/settings.json NOT written — the guard would be '${guard}', which does not exist. ` +
116
+ `Install suppa-mcp-2 in this repo (npm i -D suppa-mcp-2) and re-run.`,
117
+ );
118
+ return;
119
+ }
90
120
  const entry = (mode, statusMessage) => ({
91
121
  type: "command",
92
122
  command: "node",
@@ -149,9 +179,9 @@ function installGitHook() {
149
179
  skipped.push("git hook skipped (--no-git)");
150
180
  return;
151
181
  }
152
- const guard = relative(root, GUARD).startsWith("..")
153
- ? GUARD.replace(/\\/g, "/")
154
- : relative(root, GUARD).replace(/\\/g, "/");
182
+ // Same rule as the hooks: inside the repo it stays relative (git runs its
183
+ // hooks from the repo root), outside it is absolute.
184
+ const guard = guardRelativeToRoot() ?? GUARD.replace(/\\/g, "/");
155
185
  const hook = `#!/bin/sh
156
186
  # Managed by suppa-mcp-2 (skills/suppa-entity-code). Refuses a commit whose
157
187
  # staged *.entity.ts / *.seed.ts files fail the schema gate.
@@ -53,6 +53,7 @@ export const DEFAULT_FIELD_OPTIONS = {
53
53
  * could not see; they do not name a line that is wrong.
54
54
  */
55
55
  export const RULE_WARNINGS = [
56
+ "W619", // a second entity class of the same name: the other one is analyzed by nothing
56
57
  "W607", // tabular part: `owner` present in importKeyFields but not first
57
58
  "W609", // inverse selector passed where it is optional (@ManyToOne/@ManyToMany)
58
59
  "W610", // relation typed optional/non-optional against its own `nullable`
@@ -418,6 +419,28 @@ function spreadElements(ts, node) {
418
419
  if (!node || !ts.isObjectLiteralExpression(node)) return [];
419
420
  return node.properties.filter((p) => ts.isSpreadAssignment(p));
420
421
  }
422
+ /**
423
+ * The node that HOLDS a field's options — the object extension mode must read
424
+ * to see `primary` and `nullable`.
425
+ *
426
+ * Every decorator keeps it somewhere else, and two of them keep only readable
427
+ * object literals in `optionsNode`, which is exactly how an options object the
428
+ * checker could not read became indistinguishable from no options at all.
429
+ */
430
+ function extensionOptionsSlot(ts, prop) {
431
+ if (prop.kind === "column" || prop.kind === "file" || prop.kind === "multi-file") {
432
+ return prop.decorator?.args?.[0] ?? null;
433
+ }
434
+ if (prop.kind === "enum" || prop.kind === "multi-enum") {
435
+ // (globalName?, Enum, titles?, options?) — only from four arguments on is
436
+ // the last one unambiguously the options object. At three,
437
+ // `@Enum('Global', E, TITLES)` and `@Enum(E, TITLES, OPTS)` are the same
438
+ // shape to an AST, and a rule that blocks may not guess between them.
439
+ const args = prop.decorator?.args ?? [];
440
+ return args.length >= 4 ? args[args.length - 1] : null;
441
+ }
442
+ return prop.rawOptionsNode ?? null; // relations keep the slot of their own
443
+ }
421
444
  function arraySpreadElements(ts, node) {
422
445
  if (!node || !ts.isArrayLiteralExpression(node)) return [];
423
446
  return node.elements.filter((e) => ts.isSpreadElement(e));
@@ -549,6 +572,20 @@ function analyzeEntities(ts, sf, model, opts = {}) {
549
572
  className,
550
573
  entityName: stringValue(ts, options.get("name")) ?? className,
551
574
  sf, node, options, optionsNode: entityDec.args[0],
575
+ // `@Entity(OPTS)` — the options handed over by reference. objectMap
576
+ // returns an EMPTY map for that, which reads exactly like
577
+ // `@Entity({})`: every entity-level rule finds nothing to object to
578
+ // and stays quiet. In extension mode the same silence also hides
579
+ // WHICH entity is being extended.
580
+ optionsUnreadable:
581
+ !!entityDec.args[0] &&
582
+ !ts.isObjectLiteralExpression(unwrapExpr(ts, entityDec.args[0])),
583
+ // A `name` that is present but not a readable string literal. Absent
584
+ // is not the same thing: without a name the platform derives one, and
585
+ // entityName's fallback to the class name is then correct.
586
+ entityNameUnreadable:
587
+ !!options.get("name") &&
588
+ stringValue(ts, unwrapExpr(ts, options.get("name"))) === null,
552
589
  importKeyFields: stringArray(ts, keysNode),
553
590
  // present but not a readable array of string literals: the key checks
554
591
  // cannot run, but claiming it is missing would be a lie (CB-8)
@@ -817,7 +854,19 @@ function checkEntity(ts, info, sdk, model, findings) {
817
854
  }
818
855
  }
819
856
 
857
+ // Options delivered by reference are read as no options at all, so E501, W602
858
+ // and E106 all stop applying at once — this file's convention is that content
859
+ // it cannot read is W606, not silence. An extension gets the blocking E123
860
+ // instead: there, the same object also decides which entity is being touched.
861
+ if (info.optionsUnreadable && !info.isExtension) {
862
+ findings.push(finding(ts, sf, info.optionsNode, "W606",
863
+ `@Entity() options for '${info.className}' are delivered by reference, so none of them can be read ` +
864
+ `here — the unknown-option check (E501), the rename-key check (W602) and the importKeyFields check ` +
865
+ `(E106) are all skipped for this entity. Inline the options object to restore them`));
866
+ }
867
+
820
868
  for (const spread of spreadElements(ts, info.optionsNode)) {
869
+ if (info.isExtension) continue; // E123 covers it, and says what it costs here
821
870
  findings.push(finding(ts, sf, spread, "W606",
822
871
  `@Entity() options include a spread — options delivered via spread cannot be statically validated: the doc-rule checks (unknown options, default-as-SQL-string, type checks) are skipped for spread content; inline the options to restore checking`));
823
872
  }
@@ -1579,6 +1628,43 @@ function checkExtension(ts, info, findings) {
1579
1628
  const sf = info.sf;
1580
1629
  const anchor = info.node.name ?? info.node;
1581
1630
 
1631
+ // Every message here points at the entity being extended. When its name
1632
+ // cannot be read, entityName falls back to the CLASS name — and printing that
1633
+ // turns each message into a statement about a table that does not exist
1634
+ // ("'UsersExtension' already has rows").
1635
+ const named = !info.entityNameUnreadable && !info.optionsUnreadable;
1636
+ const target = named ? `'${info.entityName}'` : "the entity this file extends";
1637
+
1638
+ // Extension mode's restrictions are all read out of the options objects in
1639
+ // this file. One the checker cannot read does not merely skip a rule: at the
1640
+ // entity level it hides which entity is being touched and which owner-only
1641
+ // options travel with it. It compiles, so it ships — the way a by-reference
1642
+ // index walked past E121 (E122).
1643
+ const OPTION_COST =
1644
+ "primary (E119) and nullable without a default (E120) go unchecked on a table this application " +
1645
+ "does not own";
1646
+ const unreadableOptions = (node, what, consequence) =>
1647
+ findings.push(finding(ts, sf, node ?? anchor, "E123",
1648
+ `extension '${info.className}' delivers ${what}, and this checker cannot read it — so ${consequence}. ` +
1649
+ `It compiles, so it ships: write the options out here as a literal object`));
1650
+
1651
+ if (info.optionsUnreadable) {
1652
+ unreadableOptions(info.optionsNode, "its @Entity() options by reference",
1653
+ "nothing here can tell which entity is being extended, or whether owner-only options ride along (W618)");
1654
+ } else if (info.entityNameUnreadable) {
1655
+ unreadableOptions(info.options.get("name"), "the entity name as an expression",
1656
+ "nothing here can tell which entity is being extended, and every restriction extension mode adds is " +
1657
+ "about the owner's table");
1658
+ }
1659
+ for (const spread of spreadElements(ts, info.optionsNode)) {
1660
+ unreadableOptions(spread, "part of its @Entity() options through a spread",
1661
+ "the owner-only entity options in it go unchecked (W618)");
1662
+ }
1663
+ for (const keyNode of unreadableComputedKeys(ts, info.optionsNode)) {
1664
+ unreadableOptions(keyNode, "an @Entity() option under a computed key",
1665
+ "the owner-only entity options go unchecked (W618)");
1666
+ }
1667
+
1582
1668
  // "In extension mode the entity-level options of your declaration are
1583
1669
  // ignored, silently and by design — they belong to the owner."
1584
1670
  for (const opt of OWNER_ONLY_ENTITY_OPTIONS) {
@@ -1587,15 +1673,15 @@ function checkExtension(ts, info, findings) {
1587
1673
  findings.push(finding(ts, sf, node, "W618",
1588
1674
  `extension '${info.className}' sets the entity option '${opt}', which extension mode IGNORES — ` +
1589
1675
  `title, icon, type, options, representativeFieldName, importKeyFields and the entity's localization ` +
1590
- `belong to whoever owns '${info.entityName}'. Delete it: code the platform discards reads as a promise ` +
1591
- `it does not keep. Only @Entity({ name: '${info.entityName}' }) and your own columns belong here`));
1676
+ `belong to whoever owns ${target}. Delete it: code the platform discards reads as a promise ` +
1677
+ `it does not keep. Only @Entity({ name: ${named ? `'${info.entityName}'` : "…"} }) and your own columns belong here`));
1592
1678
  }
1593
1679
 
1594
1680
  if (info.properties.size === 0) {
1595
1681
  findings.push(finding(ts, sf, anchor, "W617",
1596
- `extension '${info.className}' declares no columns, so it adds nothing to '${info.entityName}' — ` +
1682
+ `extension '${info.className}' declares no columns, so it adds nothing to ${target} — ` +
1597
1683
  `an extension exists to contribute fields. If you only need the entity as a RELATION TARGET, that is a ` +
1598
- `stub: rename the file to ${kebabOf(info.entityName)}.stub.entity.ts`));
1684
+ `stub: rename the file to ${named ? kebabOf(info.entityName) : "<owner-entity>"}.stub.entity.ts`));
1599
1685
  }
1600
1686
 
1601
1687
  for (const [propName, prop] of info.properties) {
@@ -1608,12 +1694,29 @@ function checkExtension(ts, info, findings) {
1608
1694
  `(@ManyToOne / @ManyToMany) on this class instead`));
1609
1695
  }
1610
1696
 
1697
+ // `primary: true` and `nullable: false` — the two things extension mode
1698
+ // refuses — live inside this object. Read it, or say that it was not read.
1699
+ // Enum decorators are covered only from four arguments on: at three,
1700
+ // `@Enum('Global', E, TITLES)` and `@Enum(E, TITLES, OPTS)` are the same
1701
+ // shape, and a blocking rule may not guess between them.
1702
+ const slot = extensionOptionsSlot(ts, prop);
1703
+ if (slot && !ts.isObjectLiteralExpression(unwrapExpr(ts, slot))) {
1704
+ unreadableOptions(slot, `the options of '${propName}' by reference`, OPTION_COST);
1705
+ } else {
1706
+ for (const spread of spreadElements(ts, slot)) {
1707
+ unreadableOptions(spread, `part of the options of '${propName}' through a spread`, OPTION_COST);
1708
+ }
1709
+ for (const keyNode of unreadableComputedKeys(ts, slot)) {
1710
+ unreadableOptions(keyNode, `an option of '${propName}' under a computed key`, OPTION_COST);
1711
+ }
1712
+ }
1713
+
1611
1714
  const opts = prop.columnOptions ?? prop.relOptions ?? prop.enumOptions ?? new Map();
1612
1715
 
1613
1716
  // "primary: true — the owner's primary key is not yours to redefine."
1614
1717
  if (booleanValue(ts, unwrapExpr(ts, opts.get("primary"))) === true) {
1615
1718
  findings.push(finding(ts, sf, opts.get("primary"), "E119",
1616
- `extension '${info.className}' declares '${propName}' as primary — the primary key of '${info.entityName}' ` +
1719
+ `extension '${info.className}' declares '${propName}' as primary — the primary key of ${target} ` +
1617
1720
  `belongs to its owner and is not yours to redefine`));
1618
1721
  }
1619
1722
 
@@ -1623,7 +1726,7 @@ function checkExtension(ts, info, findings) {
1623
1726
  const notNull = booleanValue(ts, unwrapExpr(ts, opts.get("nullable"))) === false;
1624
1727
  if (notNull && !opts.has("default")) {
1625
1728
  findings.push(finding(ts, sf, prop.node, "E120",
1626
- `extension '${info.className}' declares '${propName}' as nullable: false with no default — '${info.entityName}' ` +
1729
+ `extension '${info.className}' declares '${propName}' as nullable: false with no default — ${target} ` +
1627
1730
  `already has rows, and a NOT NULL column needs a value for every one of them. Add a default (a SQL ` +
1628
1731
  `expression string), or ship the column nullable. On a large table the backfill holds a lock for the ` +
1629
1732
  `whole migration transaction (doc WARNING) — there, ship it nullable and fill it separately`));
@@ -1645,8 +1748,8 @@ function checkExtension(ts, info, findings) {
1645
1748
  if (info.properties.has(col) || info.columnNames.has(col)) continue;
1646
1749
  findings.push(finding(ts, sf, idx.node, "E121",
1647
1750
  `@${idx.name} on extension '${info.className}' covers '${col}', which this class does not declare — ` +
1648
- `an extension may only index or constrain the columns it owns. '${col}' belongs to ${info.entityName}'s ` +
1649
- `owner (or to another application), and reaching into it is what extension mode refuses`));
1751
+ `an extension may only index or constrain the columns it owns. '${col}' belongs to the owner of ${target} ` +
1752
+ `(or to another application), and reaching into it is what extension mode refuses`));
1650
1753
  }
1651
1754
  }
1652
1755
  }
@@ -2204,8 +2307,9 @@ function checkRegistration(ts, model, findings, rootDir) {
2204
2307
  if (m.entities.mode === "autoload" && !m.entities.pathNode) {
2205
2308
  findings.push(finding(ts, m.sf, m.entities.node, "W614",
2206
2309
  `EntityModule.forFeature() names neither an entities array (first argument) nor entitiesPath, so this ` +
2207
- `module registers no entity classes — E301 (unregistered entity) is skipped for the whole run. Pass the ` +
2208
- `classes as the first argument, or set entitiesPath to the compiled dist/ directory`));
2310
+ `module registers no entity classes at all. Anything this application declares and does not register ` +
2311
+ `elsewhere does not exist to the platform, and no table is created for it (E301). Pass the classes as ` +
2312
+ `the first argument, or set entitiesPath to the compiled dist/ directory`));
2209
2313
  }
2210
2314
  }
2211
2315
 
@@ -2238,8 +2342,18 @@ function checkRegistration(ts, model, findings, rootDir) {
2238
2342
  // an autoload (or unverifiable) module anywhere may cover any entity/seed not
2239
2343
  // named explicitly — membership becomes the platform's job, so E301/E302 would
2240
2344
  // only false-positive.
2241
- const entitiesUnknown = model.modules.some((m) => m.entities.mode !== "explicit" || m.entities.spreads.length > 0);
2242
- const seedsUnknown = model.modules.some((m) => m.seeds.mode !== "explicit" || m.seeds.spreads.length > 0);
2345
+ // A side that autoloads from NOWHERE — an empty or absent array with no
2346
+ // entitiesPath/seedsPath beside it — cannot cover anything: the doc's
2347
+ // resolution order ends there. Counting it as "membership is the platform's
2348
+ // job" switched E301/E302 off for the WHOLE run, so an application that
2349
+ // declared entities and registered none passed the gate on an advisory
2350
+ // (W614) — the one mistake the house rules call out as costing a table.
2351
+ const coversUnknown = (side) =>
2352
+ side.mode === "unverifiable" ||
2353
+ (side.mode === "autoload" && !!side.pathNode) ||
2354
+ side.spreads.length > 0;
2355
+ const entitiesUnknown = model.modules.some((m) => coversUnknown(m.entities));
2356
+ const seedsUnknown = model.modules.some((m) => coversUnknown(m.seeds));
2243
2357
 
2244
2358
  if (!entitiesUnknown) {
2245
2359
  const registeredEntities = new Set(model.modules.flatMap((m) => m.entities.names));
@@ -2453,10 +2567,16 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
2453
2567
  chaseRelationTargets(ts, model, findings, parsedByCanonical, rootDir);
2454
2568
 
2455
2569
  for (const c of model.classNameClashes) {
2456
- findings.push(finding(ts, c.sf, c.node.name ?? c.node, "W606",
2570
+ // Every other W606 says one check could not run on one field. This one says
2571
+ // an entire entity went unexamined — no typing rule, no option rule, no
2572
+ // extension rule — which is the same as not analyzing the file at all. A
2573
+ // gate may not answer "clean" about schema code it never looked at, so this
2574
+ // blocks instead of advising.
2575
+ findings.push(finding(ts, c.sf, c.node.name ?? c.node, "W619",
2457
2576
  `entity class '${c.className}' is also declared in ${displayPath(process.cwd(), c.firstFile)} — this ` +
2458
- `checker keys entities by class name, so only the first declaration is analyzed and EVERY rule is ` +
2459
- `skipped for this one. Give the two classes distinct names.`));
2577
+ `checker keys entities by class name, so only the first declaration was analyzed and EVERY rule is ` +
2578
+ `skipped for this one: it is schema code that nothing checked. Give the two classes distinct names ` +
2579
+ `(the table's name is the @Entity({ name }) option, and is unaffected).`));
2460
2580
  }
2461
2581
 
2462
2582
  // createSeed(EnumName.Member) passes the member's VALUE; the member name is
@@ -26,6 +26,9 @@ import {
26
26
  // type, options, representativeFieldName, importKeyFields and the entity's
27
27
  // localization are ignored in extension mode — they belong to the owner, and
28
28
  // writing them here is a promise the platform does not keep (W618).
29
+ // Written out literally, here and on every field below: options handed over
30
+ // by reference or through a spread cannot be read, and extension mode's whole
31
+ // restriction set is read out of them (E123).
29
32
  @Entity({ name: '__OwnerEntityName__' })
30
33
  // Indexes and checks may cover only the columns declared BELOW — never one of
31
34
  // the owner's (E121), and the column list is written out here as a literal