suppa-mcp-2 1.30.1 → 1.31.1
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/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +4 -2
- package/skills/suppa-entity-code/references/extensions.md +7 -3
- package/skills/suppa-entity-code/scripts/house-rules.mjs +1 -1
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +31 -13
- package/skills/suppa-entity-code/templates/entity-extension.template.ts +9 -4
- package/skills/suppa-entity-code/templates/relation-target-stub.template.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
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": {
|
|
@@ -78,6 +78,8 @@ Confirm all 5 before writing anything:
|
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
`.stub.entity.ts` still ends in `.entity.ts`, so discovery and `entitiesPath` autoload are unchanged. **Registration is not what protects the real table — the empty body is.** Leaving a stub out of `forFeature()` to "keep the migration away from it" only makes the relation unresolvable (E301); a *fielded* stub that is registered is the actual disaster, and E117 is the rule that stops it. Platform system entities (`Users`, `Files`, `Icons`, …) need no stub at all — import `UsersEntity`/`FilesEntity`/`IconsEntity` from `@suppa/sdk`. Template: `templates/relation-target-stub.template.ts`.
|
|
81
|
+
|
|
82
|
+
**"ALREADY EXISTS" is a precondition, not a description — check it.** A stub is still a declaration, so if the entity is NOT on the tenant the platform creates it: an empty table, owned by YOU. The platform stamps `application` on an entity created by your migrations, which is exactly what a stub for a missing entity is. Confirm each target first — `suppa_describe_entity("Accounts")` answers in one call and reports the owning `application` (absent = nobody owns it). An entity that is not there is not a stub case: either it belongs in this package as a real entity, or the relation is pointing at the wrong name.
|
|
81
83
|
20. **To ADD columns to an entity you do not own, declare an EXTENSION — a stub cannot do it.** A stub stands in for a table so a relation can point at it, and its body stays empty (rule 19). An extension is the opposite: it exists to contribute columns to an entity the platform or another application owns — `accountId` on `Users`, `plan` on another application's `Tasks` — "without touching that entity or the fields someone else declared on it". There is no separate API: declare `@Entity({ name: 'Users' })` by the entity's existing name, list ONLY the columns you are adding, and register it in `forFeature()` like any other class. The platform decides the mode by ownership at start — yours or nobody's → own mode (create/update in full); someone else's → extension mode (only your fields are applied).
|
|
82
84
|
Because nothing in the code says which mode you will get, **the filename does**: `<entity-name>.extension.entity.ts`, class `<EntityName>Extension`. That is what makes the mode's restrictions checkable before the build:
|
|
83
85
|
|
|
@@ -92,7 +94,7 @@ Confirm all 5 before writing anything:
|
|
|
92
94
|
|
|
93
95
|
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.
|
|
94
96
|
**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.
|
|
95
|
-
**Point a relation at an entity you do not own
|
|
97
|
+
**Point a relation at an entity you do not own**: the SDK takes NO string target — `@ManyToOne` is typed `() => Target` and *calls* it at registration, so `@ManyToOne('Invoices')` fails tsc and would throw. Name the entity on a raw column: `@Column({ type: RelationTypeEnum.ManyToOne, relationEntityName: 'Invoices', relationFieldName: 'id', nullable: true }) invoice?: { id: number }` — registration reads `relationEntityName` instead of calling a thunk. A string target is W620 everywhere. Template: `templates/entity-extension.template.ts`; the doc's own section is transcribed in `references/extensions.md`.
|
|
96
98
|
**Prefer an entity-scoped enum in an extension.** A global enum name has no owning entity, so two applications using the same name write to the same rows — which is rule 18's default anyway: pass no name.
|
|
97
99
|
21. **`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.
|
|
98
100
|
|
|
@@ -347,7 +349,7 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
347
349
|
| 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) |
|
|
348
350
|
| 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 |
|
|
349
351
|
| 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 |
|
|
350
|
-
| A relation names its target with a string (`@ManyToOne('Invoices', …)`)
|
|
352
|
+
| A relation names its target with a string (`@ManyToOne('Invoices', …)`), anywhere | The SDK types the target `() => Target` and calls it at registration — a string fails tsc and would throw. Use a thunk, or `@Column({ relationEntityName: 'Invoices', … })` for an entity you cannot import | W620 (blocks the gate) |
|
|
351
353
|
| A stub kept its fields, and the migration altered a table another application owns | The empty body is the whole point of a stub — a fielded one converges columns onto the real table | E117 |
|
|
352
354
|
| A field-less entity that is really a stub, in an ordinary `*.entity.ts` | Nothing marks it as a stub, so E117 cannot apply — rename to `<name>.stub.entity.ts` | W617 (blocks the gate) |
|
|
353
355
|
| Several stubs piled into one `relation-targets.ts` | Each existing-entity stub lives in its OWN file | W616 (blocks the gate) |
|
|
@@ -109,7 +109,7 @@ import {
|
|
|
109
109
|
Entity,
|
|
110
110
|
FieldTypeEnum,
|
|
111
111
|
Index,
|
|
112
|
-
|
|
112
|
+
RelationTypeEnum,
|
|
113
113
|
SystemBaseEntity,
|
|
114
114
|
} from '@suppa/sdk';
|
|
115
115
|
|
|
@@ -123,7 +123,11 @@ export class TasksBillingExtension extends SystemBaseEntity {
|
|
|
123
123
|
})
|
|
124
124
|
plan?: string;
|
|
125
125
|
|
|
126
|
-
@
|
|
126
|
+
@Column({
|
|
127
|
+
type: RelationTypeEnum.ManyToOne,
|
|
128
|
+
relationEntityName: 'Invoices',
|
|
129
|
+
relationFieldName: 'id',
|
|
130
|
+
nullable: true,
|
|
127
131
|
title: { en: 'Invoice', uk: 'Рахунок' },
|
|
128
132
|
})
|
|
129
133
|
invoice?: { id: number };
|
|
@@ -135,4 +139,4 @@ After both applications start, the `Tasks` table has `name`, `plan` and `invoice
|
|
|
135
139
|
> **HOUSE RULE — the filename declares the intent (SKILL.md rule 20).**
|
|
136
140
|
> 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
141
|
>
|
|
138
|
-
> Note the relation form
|
|
142
|
+
> Note the relation form. There is no class to import for an entity another application owns — and the SDK takes **no string target**: `@ManyToOne` is typed `() => Target` and *calls* it at registration (`const entityClass = lazyTarget()`), so `@ManyToOne('Invoices')` fails to compile and would throw if it did. Name the entity on a raw column instead: registration reads `relationEntityName` and never calls a thunk. The property is still typed by shape — `invoice?: { id: number }`. A string target is W620 everywhere, this section included.
|
|
@@ -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\`); 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: \`@Enum(StatusEnum, StatusTitles, { … })\` 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 — 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 — it only lets a relation 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; there is no separate API. Declare the entity by its EXISTING name with only your own columns, in \`<owner-entity>.extension.entity.ts\` (class \`<OwnerEntity>Extension\`), registered 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); @Index/@Check only over your own columns, listed as a literal array (E121/E122). Write @Entity()/@Column() options as literal objects — one passed by reference or through a spread cannot be read, so none of this can be checked on it (E123). A relation to an entity you do not own
|
|
23
|
+
6. TO ADD COLUMNS TO AN ENTITY YOU DO NOT OWN, DECLARE AN EXTENSION — not a stub; there is no separate API. Declare the entity by its EXISTING name with only your own columns, in \`<owner-entity>.extension.entity.ts\` (class \`<OwnerEntity>Extension\`), registered 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); @Index/@Check only over your own columns, listed as a literal array (E121/E122). Write @Entity()/@Column() options as literal objects — one passed by reference or through a spread cannot be read, so none of this can be checked on it (E123). A relation to an entity you do not own takes NO string target - name it on a raw column (W620): \`@Column({ type: RelationTypeEnum.ManyToOne, relationEntityName: 'Invoices', relationFieldName: 'id' }) invoice?: { id: number };\`.
|
|
24
24
|
Before reporting the file done, run the gate: 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". (CLI: 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. */
|
|
@@ -79,6 +79,13 @@ export const RULE_WARNINGS = [
|
|
|
79
79
|
*/
|
|
80
80
|
export const RULE_WARNINGS_NEEDING_WHOLE_REPO = ["W613"];
|
|
81
81
|
export const DOC_COLUMN_OPTIONS = ["type", "subType", "name", "nullable", "primary", "unique", "default", "length", "title", "comment", "key", "minLength", "minValue", "maxValue", "decimalPlaces", "isOnlyPositive", "mask",
|
|
82
|
+
// The only supported way to point at an entity you cannot import. The
|
|
83
|
+
// relation decorators deliberately Omit both from their options type
|
|
84
|
+
// (RelationDecoratorOptions), so the raw column is where they belong —
|
|
85
|
+
// and registration reads relationEntityName INSTEAD of calling a thunk
|
|
86
|
+
// (system-entity-decorator-registry.util.ts). Verified against the SDK
|
|
87
|
+
// source at 1.37.1, not inferred.
|
|
88
|
+
"relationEntityName", "relationFieldName",
|
|
82
89
|
// Field options. The decorator tables do not list them, but migrations.txt:245
|
|
83
90
|
// names four of them as options a column carries — encryption makes "the
|
|
84
91
|
// searchable, canFilter, canSort and canGroup options become false" — and the
|
|
@@ -708,8 +715,8 @@ function analyzeEntities(ts, sf, model, opts = {}) {
|
|
|
708
715
|
kind: RELATION_KIND_BY_DECORATOR[d.name],
|
|
709
716
|
node: member, decorator: d,
|
|
710
717
|
targetClass: thunkTarget(ts, sf, d.args[0]),
|
|
711
|
-
//
|
|
712
|
-
//
|
|
718
|
+
// Captured only so W620 can report it: a string target is
|
|
719
|
+
// not a form the SDK accepts, here or anywhere.
|
|
713
720
|
targetName: stringValue(ts, unwrapExpr(ts, d.args[0])),
|
|
714
721
|
targetLocalText: thunkLocalText(ts, d.args[0]),
|
|
715
722
|
nameNode: relOptions.get("name") ?? null,
|
|
@@ -925,17 +932,28 @@ function checkEntity(ts, info, sdk, model, findings) {
|
|
|
925
932
|
if (RELATION_KINDS.has(prop.kind)) {
|
|
926
933
|
checkRelationTyping(ts, sf, propName, prop, findings);
|
|
927
934
|
if (prop.targetClass === null && prop.targetName !== null) {
|
|
928
|
-
// @ManyToOne('Invoices', { ... })
|
|
929
|
-
//
|
|
930
|
-
//
|
|
931
|
-
//
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
935
|
+
// @ManyToOne('Invoices', { ... }) does not work ANYWHERE, and this
|
|
936
|
+
// checker used to bless it inside extensions. Read against the SDK
|
|
937
|
+
// source (git.modern-expo.com/suppa/sdk, 1.37.1): the decorator is
|
|
938
|
+
// typed `target: () => { new (...args): T }`, so a string fails tsc;
|
|
939
|
+
// and registration does `const entityClass = lazyTarget()`, so a
|
|
940
|
+
// string that got past tsc throws "lazyTarget is not a function".
|
|
941
|
+
// There is no string branch in the SDK at all.
|
|
942
|
+
//
|
|
943
|
+
// The supported way to name a target with no class to import is the
|
|
944
|
+
// raw column: registration only calls the thunk when
|
|
945
|
+
// relationEntityName is absent.
|
|
946
|
+
findings.push(finding(ts, sf, prop.node, "W620",
|
|
947
|
+
info.isExtension
|
|
948
|
+
? `relation '${propName}' names its target by string ('${prop.targetName}'). The SDK accepts no ` +
|
|
949
|
+
`string target: @${prop.decorator.name} is typed () => Target, and registration CALLS it, so a ` +
|
|
950
|
+
`string throws "lazyTarget is not a function". For a target you cannot import, write the raw ` +
|
|
951
|
+
`column instead: @Column({ type: RelationTypeEnum.${prop.decorator.name}, relationEntityName: ` +
|
|
952
|
+
`'${prop.targetName}', relationFieldName: 'id', nullable: true }) ${propName}?: { id: number };`
|
|
953
|
+
: `relation '${propName}' names its target by string ('${prop.targetName}') instead of a thunk — ` +
|
|
954
|
+
`the SDK is typed () => Target and calls it at registration, so a string fails to compile and ` +
|
|
955
|
+
`would throw if it did. Write @${prop.decorator.name}(() => ${prop.targetName}) so the target is ` +
|
|
956
|
+
`resolved and checked`));
|
|
939
957
|
} else if (prop.targetClass === null) {
|
|
940
958
|
findings.push(finding(ts, sf, prop.node, "E105",
|
|
941
959
|
`relation '${propName}' must receive a thunk returning the target class — write @${prop.decorator.name}(() => Target); a direct class reference breaks circular imports`));
|
|
@@ -54,10 +54,15 @@ export class __OwnerEntity__Extension extends SystemBaseEntity {
|
|
|
54
54
|
// @Column({ type: FieldTypeEnum.Boolean, nullable: false, default: 'false' })
|
|
55
55
|
// __flag__: boolean;
|
|
56
56
|
|
|
57
|
-
// A relation to an entity you do not own has no class to import
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
57
|
+
// A relation to an entity you do not own has no class to import. The SDK
|
|
58
|
+
// accepts NO string target — @ManyToOne is typed () => Target and calls it
|
|
59
|
+
// at registration — so name the entity on a raw column instead. The thunk
|
|
60
|
+
// is only consulted when relationEntityName is absent (W620).
|
|
61
|
+
@Column({
|
|
62
|
+
type: RelationTypeEnum.ManyToOne,
|
|
63
|
+
relationEntityName: '__TargetEntityName__',
|
|
64
|
+
relationFieldName: 'id',
|
|
65
|
+
nullable: true,
|
|
61
66
|
title: { en: '__Target title__', uk: '__Назва звʼязку__' },
|
|
62
67
|
})
|
|
63
68
|
__target__?: { id: number };
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
* invisible to the platform (E301), and the empty body, not the missing
|
|
21
21
|
* registration, is what keeps the migration off the real table.
|
|
22
22
|
*
|
|
23
|
+
* BEFORE YOU WRITE ONE: confirm the entity is actually on the tenant.
|
|
24
|
+
* A stub is a declaration like any other, so for an entity that is NOT
|
|
25
|
+
* there the platform CREATES it — an empty table, stamped with YOUR
|
|
26
|
+
* application as its owner, because it came from your migrations.
|
|
27
|
+
* suppa_describe_entity("<Name>") answers in one call and reports the
|
|
28
|
+
* owning application (absent means nobody owns it).
|
|
29
|
+
*
|
|
23
30
|
* One stub per file (W616). Platform system entities need no stub at all —
|
|
24
31
|
* import UsersEntity/FilesEntity/IconsEntity from '@suppa/sdk' instead.
|
|
25
32
|
*/
|