suppa-mcp-2 1.13.0 → 1.14.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/dist/server.js +4 -2
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +5 -1
- package/skills/suppa-entity-code/references/extensions.md +1 -1
- package/skills/suppa-entity-code/scripts/house-rules.mjs +4 -3
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +160 -20
- package/skills/suppa-entity-code/templates/entity-extension.template.ts +6 -1
package/dist/server.js
CHANGED
|
@@ -2187,8 +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 (E121).
|
|
2191
|
-
" by
|
|
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" +
|
|
2192
2194
|
" * 'owner' comes first in a tabular part's importKeyFields, and no 'inverse' is passed\n" +
|
|
2193
2195
|
" to @ManyToOne/@ManyToMany.\n" +
|
|
2194
2196
|
' Pass the app ROOT, not one file: several rules read the whole repo ("nothing references\n' +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
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
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -87,7 +87,8 @@ Confirm all 5 before writing anything:
|
|
|
87
87
|
| No `@OneToMany` / `@ManyToManyBackRef` | "a reverse relation creates a field on the other entity" | **E118** |
|
|
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
|
-
| `@Index` / `@Check` only over columns YOU declare | anything else reaches into another owner's schema | **E121** |
|
|
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.
|
|
@@ -311,6 +312,9 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
311
312
|
| An extension declares `primary: true` | The owner's primary key is not yours to redefine | E119 |
|
|
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 |
|
|
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) |
|
|
314
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 |
|
|
315
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 |
|
|
316
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.
|
|
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 (E121). 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/W620), " +
|
|
32
|
-
"`owner` first in a tabular part's importKeyFields (W607),
|
|
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)";
|
|
@@ -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)
|
|
@@ -566,11 +603,22 @@ function analyzeEntities(ts, sf, model, opts = {}) {
|
|
|
566
603
|
// class: in extension mode these may only cover columns you declare.
|
|
567
604
|
classIndexes: decs
|
|
568
605
|
.filter((d) => d.name === "Index" || d.name === "Check")
|
|
569
|
-
.map((d) =>
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
606
|
+
.map((d) => {
|
|
607
|
+
const list = d.args.find((a) => ts.isArrayLiteralExpression(a));
|
|
608
|
+
const columns = stringArray(ts, list);
|
|
609
|
+
return {
|
|
610
|
+
name: d.name,
|
|
611
|
+
node: d.args[0] ?? node,
|
|
612
|
+
columns: columns ?? [],
|
|
613
|
+
// "no columns" and "columns I cannot read" are not the same
|
|
614
|
+
// answer, and collapsing them into [] made E121 pass silently
|
|
615
|
+
// on `@Index('i', COLS)` — a column list delivered by
|
|
616
|
+
// reference, which tsc accepts and which therefore ships. An
|
|
617
|
+
// extension indexing a column it does not own is exactly what
|
|
618
|
+
// that rule exists to stop, so an unreadable list has to speak.
|
|
619
|
+
columnsUnreadable: d.args.length > 0 && columns === null,
|
|
620
|
+
};
|
|
621
|
+
}),
|
|
574
622
|
// Reached by following a relation target rather than by being handed
|
|
575
623
|
// to this run; `outOfScope` marks one that is not the app's own code,
|
|
576
624
|
// and every rule skips those (see chaseRelationTargets' inScope).
|
|
@@ -806,7 +854,19 @@ function checkEntity(ts, info, sdk, model, findings) {
|
|
|
806
854
|
}
|
|
807
855
|
}
|
|
808
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
|
+
|
|
809
868
|
for (const spread of spreadElements(ts, info.optionsNode)) {
|
|
869
|
+
if (info.isExtension) continue; // E123 covers it, and says what it costs here
|
|
810
870
|
findings.push(finding(ts, sf, spread, "W606",
|
|
811
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`));
|
|
812
872
|
}
|
|
@@ -1568,6 +1628,43 @@ function checkExtension(ts, info, findings) {
|
|
|
1568
1628
|
const sf = info.sf;
|
|
1569
1629
|
const anchor = info.node.name ?? info.node;
|
|
1570
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
|
+
|
|
1571
1668
|
// "In extension mode the entity-level options of your declaration are
|
|
1572
1669
|
// ignored, silently and by design — they belong to the owner."
|
|
1573
1670
|
for (const opt of OWNER_ONLY_ENTITY_OPTIONS) {
|
|
@@ -1576,15 +1673,15 @@ function checkExtension(ts, info, findings) {
|
|
|
1576
1673
|
findings.push(finding(ts, sf, node, "W618",
|
|
1577
1674
|
`extension '${info.className}' sets the entity option '${opt}', which extension mode IGNORES — ` +
|
|
1578
1675
|
`title, icon, type, options, representativeFieldName, importKeyFields and the entity's localization ` +
|
|
1579
|
-
`belong to whoever owns
|
|
1580
|
-
`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`));
|
|
1581
1678
|
}
|
|
1582
1679
|
|
|
1583
1680
|
if (info.properties.size === 0) {
|
|
1584
1681
|
findings.push(finding(ts, sf, anchor, "W617",
|
|
1585
|
-
`extension '${info.className}' declares no columns, so it adds nothing to
|
|
1682
|
+
`extension '${info.className}' declares no columns, so it adds nothing to ${target} — ` +
|
|
1586
1683
|
`an extension exists to contribute fields. If you only need the entity as a RELATION TARGET, that is a ` +
|
|
1587
|
-
`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`));
|
|
1588
1685
|
}
|
|
1589
1686
|
|
|
1590
1687
|
for (const [propName, prop] of info.properties) {
|
|
@@ -1597,12 +1694,29 @@ function checkExtension(ts, info, findings) {
|
|
|
1597
1694
|
`(@ManyToOne / @ManyToMany) on this class instead`));
|
|
1598
1695
|
}
|
|
1599
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
|
+
|
|
1600
1714
|
const opts = prop.columnOptions ?? prop.relOptions ?? prop.enumOptions ?? new Map();
|
|
1601
1715
|
|
|
1602
1716
|
// "primary: true — the owner's primary key is not yours to redefine."
|
|
1603
1717
|
if (booleanValue(ts, unwrapExpr(ts, opts.get("primary"))) === true) {
|
|
1604
1718
|
findings.push(finding(ts, sf, opts.get("primary"), "E119",
|
|
1605
|
-
`extension '${info.className}' declares '${propName}' as primary — the primary key of
|
|
1719
|
+
`extension '${info.className}' declares '${propName}' as primary — the primary key of ${target} ` +
|
|
1606
1720
|
`belongs to its owner and is not yours to redefine`));
|
|
1607
1721
|
}
|
|
1608
1722
|
|
|
@@ -1612,7 +1726,7 @@ function checkExtension(ts, info, findings) {
|
|
|
1612
1726
|
const notNull = booleanValue(ts, unwrapExpr(ts, opts.get("nullable"))) === false;
|
|
1613
1727
|
if (notNull && !opts.has("default")) {
|
|
1614
1728
|
findings.push(finding(ts, sf, prop.node, "E120",
|
|
1615
|
-
`extension '${info.className}' declares '${propName}' as nullable: false with no default —
|
|
1729
|
+
`extension '${info.className}' declares '${propName}' as nullable: false with no default — ${target} ` +
|
|
1616
1730
|
`already has rows, and a NOT NULL column needs a value for every one of them. Add a default (a SQL ` +
|
|
1617
1731
|
`expression string), or ship the column nullable. On a large table the backfill holds a lock for the ` +
|
|
1618
1732
|
`whole migration transaction (doc WARNING) — there, ship it nullable and fill it separately`));
|
|
@@ -1621,12 +1735,21 @@ function checkExtension(ts, info, findings) {
|
|
|
1621
1735
|
|
|
1622
1736
|
// "@Index() / @Check() covering a field you do not own" is not allowed.
|
|
1623
1737
|
for (const idx of info.classIndexes ?? []) {
|
|
1738
|
+
if (idx.columnsUnreadable) {
|
|
1739
|
+
findings.push(finding(ts, sf, idx.node, "E122",
|
|
1740
|
+
`@${idx.name} on extension '${info.className}' does not spell its columns out — the documented ` +
|
|
1741
|
+
`shape is @${idx.name}('<name>', ['<column>', …]), and a list delivered any other way (a const, a ` +
|
|
1742
|
+
`spread, an options object) cannot be read here. That leaves the one restriction extension mode ` +
|
|
1743
|
+
`turns on unchecked: an extension may only index or constrain the columns it declares itself. ` +
|
|
1744
|
+
`Write the array literally, in the decorator`));
|
|
1745
|
+
continue;
|
|
1746
|
+
}
|
|
1624
1747
|
for (const col of idx.columns) {
|
|
1625
1748
|
if (info.properties.has(col) || info.columnNames.has(col)) continue;
|
|
1626
1749
|
findings.push(finding(ts, sf, idx.node, "E121",
|
|
1627
1750
|
`@${idx.name} on extension '${info.className}' covers '${col}', which this class does not declare — ` +
|
|
1628
|
-
`an extension may only index or constrain the columns it owns. '${col}' belongs to ${
|
|
1629
|
-
`
|
|
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`));
|
|
1630
1753
|
}
|
|
1631
1754
|
}
|
|
1632
1755
|
}
|
|
@@ -2184,8 +2307,9 @@ function checkRegistration(ts, model, findings, rootDir) {
|
|
|
2184
2307
|
if (m.entities.mode === "autoload" && !m.entities.pathNode) {
|
|
2185
2308
|
findings.push(finding(ts, m.sf, m.entities.node, "W614",
|
|
2186
2309
|
`EntityModule.forFeature() names neither an entities array (first argument) nor entitiesPath, so this ` +
|
|
2187
|
-
`module registers no entity classes
|
|
2188
|
-
`
|
|
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`));
|
|
2189
2313
|
}
|
|
2190
2314
|
}
|
|
2191
2315
|
|
|
@@ -2218,8 +2342,18 @@ function checkRegistration(ts, model, findings, rootDir) {
|
|
|
2218
2342
|
// an autoload (or unverifiable) module anywhere may cover any entity/seed not
|
|
2219
2343
|
// named explicitly — membership becomes the platform's job, so E301/E302 would
|
|
2220
2344
|
// only false-positive.
|
|
2221
|
-
|
|
2222
|
-
|
|
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));
|
|
2223
2357
|
|
|
2224
2358
|
if (!entitiesUnknown) {
|
|
2225
2359
|
const registeredEntities = new Set(model.modules.flatMap((m) => m.entities.names));
|
|
@@ -2433,10 +2567,16 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
|
|
|
2433
2567
|
chaseRelationTargets(ts, model, findings, parsedByCanonical, rootDir);
|
|
2434
2568
|
|
|
2435
2569
|
for (const c of model.classNameClashes) {
|
|
2436
|
-
|
|
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",
|
|
2437
2576
|
`entity class '${c.className}' is also declared in ${displayPath(process.cwd(), c.firstFile)} — this ` +
|
|
2438
|
-
`checker keys entities by class name, so only the first declaration
|
|
2439
|
-
`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).`));
|
|
2440
2580
|
}
|
|
2441
2581
|
|
|
2442
2582
|
// createSeed(EnumName.Member) passes the member's VALUE; the member name is
|
|
@@ -26,9 +26,14 @@ 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
|
-
// the owner's (E121)
|
|
34
|
+
// the owner's (E121), and the column list is written out here as a literal
|
|
35
|
+
// array: one handed over as a const compiles, so it ships, and nothing can
|
|
36
|
+
// check what it covers (E122).
|
|
32
37
|
@Index('idx___owner_table_____field__', ['__field__'])
|
|
33
38
|
export class __OwnerEntity__Extension extends SystemBaseEntity {
|
|
34
39
|
// Your own columns, and only yours. The owner's fields are never part of
|