suppa-mcp-2 1.2.0 → 1.2.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/README.md CHANGED
@@ -296,13 +296,21 @@ node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root>
296
296
  Checks: SQL-string defaults, decorator misuse, thunk-less relations, seed
297
297
  idempotency (importKeyFields / `$key`), forbidden seed keys, numeric relation
298
298
  ids, reverse `@OneToMany` references, `forFeature` membership, seed dependency
299
- order, `dist/` autoload paths, tsconfig decorator flags, and unknown
300
- `@Entity()`/`@Column()` options or field types — validated against the
301
- installed `@suppa/sdk` typings when resolvable, falling back to the doc
302
- tables otherwise (E101/E102/E107/E501/E502). Options/records/registration
303
- arrays delivered via spread or by reference can't be statically checked and
304
- fire a W606 warning instead. Exit code 1 on any error. Use the
305
- `write_entity_code` MCP prompt to drive it from any client.
299
+ order, `dist/` autoload paths, tsconfig decorator flags, unknown
300
+ `@Entity()`/`@Column()` options or field types, and tabular-part rules —
301
+ the `type: 'tabular-part'` + `relationEntityName` + `owner` triad, `owner`
302
+ resolving to the right parent, and `owner` first in `importKeyFields`
303
+ (E108/E109/E110/W607) — validated against the installed `@suppa/sdk` typings
304
+ when resolvable, falling back to the doc tables otherwise
305
+ (E101/E102/E107/E501/E502). Options/records/registration arrays delivered via
306
+ spread or by reference can't be statically checked and fire a W606 warning
307
+ instead. Exit code 1 on any error. Use the `write_entity_code` MCP prompt to
308
+ drive it from any client.
309
+
310
+ Tabular parts (owned child sub-tables like checklist items or order lines)
311
+ and the remove-and-re-add-a-field semantics — a re-added field restores its
312
+ old data because the key defaults to `<EntityName>.<fieldName>` — are both
313
+ covered; see `references/tabular-parts.md` and `references/registration.md`.
306
314
 
307
315
  ---
308
316
 
package/dist/server.js CHANGED
@@ -1656,7 +1656,9 @@ export function buildServer() {
1656
1656
  "representativeFieldName, and per-field nullable.\n" +
1657
1657
  "3. Write src/common/database/entities/*.entity.ts — @Entity class extending SystemBaseEntity; scalars via @Column({ type: FieldTypeEnum.X }); " +
1658
1658
  "relations via thunks (@ManyToOne(() => Target)); fixed choices via @Enum('Entity.field', ...); attachments via @File/@MultiFile; " +
1659
- "'default' is a SQL expression STRING ('false', \"'draft'\") — never a JS value.\n" +
1659
+ "'default' is a SQL expression STRING ('false', \"'draft'\") — never a JS value. Repeating rows owned by one parent record " +
1660
+ "(checklist items, order lines) are a TABULAR PART, not a plain entity: type: 'tabular-part' + relationEntityName + a @ManyToOne " +
1661
+ "field named owner, with owner first in importKeyFields (see references/tabular-parts.md).\n" +
1660
1662
  "4. Write matching *.seed.ts with createSeed(): every importKeyField in every record (or $key); relations referenced by import key " +
1661
1663
  "({ name: 'Default' }) — never numeric ids; never system columns, access metadata, or reverse @OneToMany fields.\n" +
1662
1664
  "5. Register in EntityModule.forFeature([entities], { seeds }) — dependencies' seeds first.\n" +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.2.0",
3
+ "version": "1.2.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": { "suppa-mcp": "dist/bin.js" },
@@ -48,11 +48,13 @@ Confirm all 5 before writing anything:
48
48
  7. Seeds: every record carries all `importKeyFields` (or `$key`); relations are referenced by the target's import-key object, never a numeric id; no system columns; no `$readAccess`/`$updateAccess`/`$instanceAccess`; no reverse `@OneToMany` field, even as `[]`.
49
49
  8. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
50
50
  9. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
51
+ 10. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
51
52
 
52
53
  ## Decorator decision table
53
54
 
54
55
  | You need | Decorator |
55
56
  |---|---|
57
+ | Repeating rows owned by one parent record (checklist items, order lines, attendees) | **Tabular part** — `type: 'tabular-part'` + `relationEntityName` + a `@ManyToOne` field named `owner` on `@Entity()`; see `templates/tabular-part.template.ts` and `references/tabular-parts.md` |
56
58
  | Scalar column (text/numeric/integer/boolean/timestamp/json/uuid/multi-language/bytea/tsvector/multi-type/icon) | `@Column({ type: FieldTypeEnum.<Member> })` |
57
59
  | Fixed single-select value set | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
58
60
  | Fixed multi-select value set | `@MultiEnum(...)` — same signature as `@Enum` |
@@ -119,4 +121,13 @@ Confirm all 5 before writing anything:
119
121
  | Back reference can't insert | A reverse `@OneToMany` field is present in a seed record, possibly as `[]` | E204 |
120
122
  | A renamed entity or field appears as a new one | No `key` option was set | W602 |
121
123
  | `default` value is rejected | A JavaScript value was passed instead of a SQL expression string | E103 |
122
- | Validator warns W606 | Options/records/registration arrays delivered via spread or reference — inline them so the validator can check | W606 |
124
+ | A re-added field already contains old data | Same name means the same key, so the soft-deleted field was restored with its column — this is a runtime migration outcome, not statically checkable | documented-only, see references/registration.md |
125
+ | A removed field is still present after a reload | The removal pass was skipped because the system user could not be resolved | documented-only, see references/registration.md |
126
+ | The table has columns such as `title_1730457600000` | Leftovers from removed fields — renaming is how the platform removes a column; nothing cleans them up | documented-only, see references/registration.md |
127
+ | A tabular part has no `ownerId` column and its tab stays empty | `relationEntityName` was set, but the `owner` `@ManyToOne` was not declared | E108 |
128
+ | A tabular part is missing from the parent's tabs | `type: 'tabular-part'` or `relationEntityName` is missing, so it is listed under `/related` instead | E108 |
129
+ | Duplicate tabular-part rows across different parents | `owner` is missing from `importKeyFields`, so the key is matched globally instead of per-parent | E110 |
130
+ | A tabular part's rows land on/read from the wrong parent | `owner`'s `@ManyToOne` target resolves to an entity whose `@Entity()` name doesn't match `relationEntityName` | E109 |
131
+ | A tabular part's business key isn't scoped to its parent | `owner` is present in `importKeyFields` but not first | W607 |
132
+ | Validator warns W606 | Content delivered via spread or reference — options, `default`, `importKeyFields`, seed records, enum refs, `$key`, autoload paths, registration arrays, tabular-part `type`/`relationEntityName` — is not statically verifiable; the matching check is skipped. Inline it so the validator can check | W606 |
133
+ | Validator warns W608 | No `tsconfig.json` at the given root, so `experimentalDecorators`/`emitDecoratorMetadata` could not be verified — point the validator at the app root | W608 |
@@ -56,9 +56,12 @@ Every entity must extend SystemBaseEntity. It contributes the standard columns,
56
56
  | importKeyFields | string[] | Business key used by seeds, import and relation references. |
57
57
  | key | string | Stable identifier that survives renaming the entity. |
58
58
  | icon | Record<string, any> | Icon configuration. |
59
- | type | string | Entity type. |
59
+ | type | string | Entity kind. Omit for a standalone entity, or set 'tabular-part' — see Tabular Parts. |
60
+ | relationEntityName | string | Name of the entity this one belongs to. Required for a tabular part. |
60
61
  | options | Record<string, any> | Platform features to enable or disable for the entity (see below). |
61
62
 
63
+ See [references/tabular-parts.md](tabular-parts.md) for the full triad required to declare a tabular part (`type: 'tabular-part'` + `relationEntityName` + an `owner` relation).
64
+
62
65
  options toggles the built-in per-entity features. Disable what the entity does not need — each enabled feature adds side tables and processing:
63
66
 
64
67
  ```ts
@@ -274,7 +277,7 @@ importKeyFields names the fields that identify a record independently of its num
274
277
  Pick fields that are stable and unique in practice. Without importKeyFields, seeds have nothing to match on and cannot stay idempotent.
275
278
 
276
279
  > **TIP**
277
- > Use the key option on @Entity() and @Column() when you expect to rename things later. The key is the stable identity used to recognize an existing entity or field, so a rename becomes a rename instead of a drop-and-create.
280
+ > Use the key option on @Entity() and @Column() when you expect to rename things later. The key is the stable identity used to recognize an existing entity or field, so a rename becomes a rename instead of a drop-and-create. Without it the key defaults to the name — see Removing and Re-Adding a Field.
278
281
 
279
282
  ## About title
280
283
 
@@ -123,6 +123,50 @@ Entities and seeds behave differently on conflict. Entity metadata is overridden
123
123
 
124
124
  It runs per tenant. Each tenant schema is migrated separately, and a newly provisioned tenant gets your entities and seeds when the application first boots for it.
125
125
 
126
+ ## Removing and Re-Adding a Field
127
+
128
+ Deleting a property from an entity class and later adding it back with the same name is the one change whose outcome surprises people. Nothing is destroyed, and nothing starts empty: the field comes back with its old data.
129
+
130
+ The reason is that the sync matches your declarations against existing metadata by key, and the key of a field defaults to `<EntityName>.<fieldName>`. Same entity plus same field name means the same key, whether or not you ever set key yourself.
131
+
132
+ ### Removing a Field
133
+
134
+ Delete the property, push, reload — on the next start the sync sees a key that exists in metadata but is no longer declared, and tears the field down:
135
+
136
+ | Step | Result |
137
+ |---|---|
138
+ | Field metadata | Soft-deleted: deletedAt is set and removedBy points at the system user. The row itself stays. |
139
+ | Column | Renamed, not dropped: title becomes title_1730457600000, where the suffix is deletedAt in epoch milliseconds. |
140
+ | Data | Untouched. Every value is still in the renamed column. |
141
+ | Relation fields | The relation is torn down the same way, through a soft removal. |
142
+ | Indexes and checks on the field | Their metadata is removed together with the field. |
143
+ | API and UI | The field is gone from metadata, from selects, and from forms. |
144
+
145
+ ```sql
146
+ -- what the platform actually runs
147
+ ALTER TABLE "Tasks" RENAME COLUMN "title" TO "title_1730457600000";
148
+ ```
149
+
150
+ > **WARNING**
151
+ > The renamed column is never cleaned up. It stays in the table with all its rows, invisible to the platform, until someone drops it manually. Removing a field is therefore not a way to delete data, and repeated remove/re-add cycles leave one leftover column each.
152
+
153
+ ### Adding the Same Field Back
154
+
155
+ Re-declare the property with the same name on the same entity, and the sync resolves the key to the soft-deleted field instead of creating a new one:
156
+
157
+ | Step | Result |
158
+ |---|---|
159
+ | Field metadata | The same row is restored — deletedAt is cleared. No duplicate field, and the field id does not change. |
160
+ | Column | title_1730457600000 is renamed back to title. |
161
+ | Data | The old values are back, including everything written before the removal. |
162
+
163
+ ```sql
164
+ ALTER TABLE "Tasks" RENAME COLUMN "title_1730457600000" TO "title";
165
+ ```
166
+
167
+ > **WARNING**
168
+ > Re-adding a field is a restore, not a fresh start. If you removed the field in order to clear it, the data returns the moment you declare it again. There is no flag that turns this off — to get a genuinely empty field, the new field must have a different key.
169
+
126
170
  ## The Development Loop
127
171
 
128
172
  ```txt
@@ -135,7 +179,7 @@ Reload with the application record id:
135
179
  POST /core/applications/:appId/reload
136
180
  ```
137
181
 
138
- appId is the id of the record in the Applications table. The runner rebuilds the app from that record and restarts the running instance.
182
+ (From Run application:) appId is the id of the record in the Applications table. The runner rebuilds the app from that record and restarts the running instance.
139
183
 
140
184
  See Run application for the full application lifecycle.
141
185
 
@@ -153,6 +197,12 @@ See Run application for the full application lifecycle.
153
197
  | Back reference can't insert | A reverse @OneToMany field is present in a seed record, possibly as []. |
154
198
  | A renamed entity or field appears as a new one | No key option was set, so the rename was not recognized as a rename. |
155
199
  | default value is rejected | A JavaScript value was passed instead of a SQL expression string. |
200
+ | A re-added field already contains old data | Same name means the same key, so the soft-deleted field was restored with its column. |
201
+ | A removed field is still present after a reload | The removal pass was skipped because the system user could not be resolved. |
202
+ | The table has columns such as title_1730457600000 | Leftovers from removed fields. Renaming is how the platform removes a column; nothing cleans them up. |
203
+ | A tabular part has no ownerId column and its tab stays empty | relationEntityName was set, but the owner @ManyToOne was not declared. |
204
+ | A tabular part is missing from the parent's tabs | type: 'tabular-part' or relationEntityName is missing, so it is listed under /related instead. |
205
+ | Duplicate tabular-part rows across different parents | owner is missing from importKeyFields, so the key is matched globally. |
156
206
 
157
207
  ## Requirements
158
208
 
@@ -108,6 +108,8 @@ Because `workflow: { name: 'Default' }` resolves by name, the seed works in ever
108
108
  | Reverse @OneToMany fields — even as [] | Back references cannot be inserted; the import throws. |
109
109
  | Numeric relation ids | They do not match across tenants. Use import-key references. |
110
110
 
111
+ Seeding a tabular part's owner is the same @ManyToOne reference shape as any other relation — see [references/tabular-parts.md](tabular-parts.md) for the owner-referenced seed example.
112
+
111
113
  > **TIP**
112
114
  > When you build a seed from an exported record, strip those keys before committing. Seed a child entity with its own seed instead of nesting it in the parent.
113
115
 
@@ -0,0 +1,146 @@
1
+ # Tabular parts — verbatim rules
2
+
3
+ Transcribed from docs.modern-expo.com/backend/application-developing/migrations.html (captured 2026-08-03). If an option is not in these tables, it does not exist — stop and ask.
4
+
5
+ ## Tabular Parts
6
+
7
+ A tabular part is a child entity whose rows only exist inside one parent record — the table the user edits on the parent's form rather than a separate section with its own list. Checklist items of a task, lines of an order, attendees of an event.
8
+
9
+ The platform uses the same mechanism for its own entities: ApplicationJobs and ApplicationEnvs are tabular parts of Applications, CalendarEventAttendees is a tabular part of CalendarEvents.
10
+
11
+ A tabular part is still an ordinary entity — its own table, its own columns, readable through Query Manager. What `type: 'tabular-part'` changes is ownership: the platform records that these rows belong to a parent record, and the UI renders them inside it.
12
+
13
+ ## Declaring One
14
+
15
+ Three things make an entity a tabular part. All three are required, and the platform does not infer any of them:
16
+
17
+ - `type: 'tabular-part'` on `@Entity()`.
18
+ - `relationEntityName` — the name of the parent entity.
19
+ - A `@ManyToOne` field named `owner` pointing at the parent class.
20
+
21
+ ```ts
22
+ import {
23
+ Column,
24
+ Entity,
25
+ FieldTypeEnum,
26
+ Index,
27
+ ManyToOne,
28
+ SystemBaseEntity,
29
+ } from '@suppa/sdk';
30
+ import { Tasks } from './tasks.entity';
31
+
32
+ @Index('TaskChecklistItemsOwnerTitleUindex', ['owner', 'title'], {
33
+ unique: true,
34
+ where: '"deletedAt" IS NULL',
35
+ })
36
+ @Entity({
37
+ name: 'TaskChecklistItems',
38
+ title: { en: 'Checklist items', uk: 'Пункти чеклиста' },
39
+ type: 'tabular-part',
40
+ relationEntityName: 'Tasks',
41
+ importKeyFields: ['owner', 'title'],
42
+ representativeFieldName: 'title',
43
+ })
44
+ export class TaskChecklistItems extends SystemBaseEntity {
45
+ @ManyToOne(() => Tasks, {
46
+ name: 'owner',
47
+ title: { en: 'Task', uk: 'Задача' },
48
+ })
49
+ owner?: Tasks;
50
+
51
+ @Column({
52
+ name: 'title',
53
+ title: { en: 'Title', uk: 'Назва' },
54
+ type: FieldTypeEnum.Text,
55
+ nullable: false,
56
+ })
57
+ title: string;
58
+
59
+ @Column({
60
+ name: 'done',
61
+ title: { en: 'Done', uk: 'Виконано' },
62
+ type: FieldTypeEnum.Boolean,
63
+ nullable: false,
64
+ default: 'false',
65
+ })
66
+ done: boolean;
67
+
68
+ @Column({
69
+ name: 'order',
70
+ title: { en: 'Order', uk: 'Порядок' },
71
+ type: FieldTypeEnum.Integer,
72
+ })
73
+ order: number;
74
+ }
75
+ ```
76
+
77
+ ## What Gets Created
78
+
79
+ Registering the class in EntityModule.forFeature() and starting the application produces:
80
+
81
+ | Artifact | Result |
82
+ |---|---|
83
+ | Table | A normal table TaskChecklistItems in the tenant schema. Nothing about the storage differs from a standalone entity. |
84
+ | ownerId column | An integer foreign key to the parent table, materialized from the owner relation. |
85
+ | Entity metadata | An EntityMetadata row with type = 'tabular-part' and relationEntity pointing at Tasks. |
86
+ | Schema API | The entity is returned by GET /core/schema/Tasks/tabular-parts and is excluded from GET /core/schema/Tasks/related. |
87
+ | UI | The client reads that list and renders the rows as a table on the parent record instead of giving the entity its own navigation entry. |
88
+ | Index and constraints | Whatever you declared with @Index() / @Check(), unchanged. |
89
+
90
+ ## Scoping the Business Key
91
+
92
+ Put owner first in importKeyFields. A checklist item is unique inside its task, not across the workspace, and seeds, import and export all resolve the row through that pair:
93
+
94
+ ```ts
95
+ importKeyFields: ['owner', 'title'],
96
+ ```
97
+
98
+ The unique index mirrors the same pair, so the database enforces what the metadata declares:
99
+
100
+ ```ts
101
+ @Index('TaskChecklistItemsOwnerTitleUindex', ['owner', 'title'], {
102
+ unique: true,
103
+ where: '"deletedAt" IS NULL',
104
+ })
105
+ ```
106
+
107
+ `where: '"deletedAt" IS NULL'` keeps soft-deleted rows from blocking a re-created one.
108
+
109
+ ## The Back Reference on the Parent
110
+
111
+ Declare the reverse side on the parent to read the rows as a nested array and to give the tab a localized name:
112
+
113
+ ```ts
114
+ @OneToMany(() => TaskChecklistItems, (item) => item.owner, {
115
+ title: { en: 'Checklist', uk: 'Чекліст' },
116
+ })
117
+ checklist: TaskChecklistItems[];
118
+ ```
119
+
120
+ This is the same shape the platform uses — Applications.jobs is an @OneToMany to ApplicationJobs inverted on owner.
121
+
122
+ > **WARNING**
123
+ > A back reference is readable, not writable. Never include the field in a seed — not even as `[]` — the import throws `Back reference can't insert`. Seed the tabular part with its own seed and reference the parent through owner.
124
+
125
+ ```ts
126
+ import { createSeed } from '@suppa/sdk';
127
+
128
+ export const taskChecklistItemsSeed = createSeed('TaskChecklistItems', [
129
+ { owner: { externalId: 'onboarding-task' }, title: 'Sign the NDA', order: 1000 },
130
+ { owner: { externalId: 'onboarding-task' }, title: 'Set up the laptop', order: 2000 },
131
+ ]);
132
+ ```
133
+
134
+ owner is referenced through the parent's importKeyFields, exactly like any other @ManyToOne.
135
+
136
+ ## Registration
137
+
138
+ A tabular part is registered like any other entity — both classes go into forFeature(), and the parent does not need to come first:
139
+
140
+ ```ts
141
+ EntityModule.forFeature([Tasks, TaskChecklistItems], {
142
+ seeds: [tasksSeed, taskChecklistItemsSeed],
143
+ });
144
+ ```
145
+
146
+ Seed order still matters: the parent's seed must run before the tabular part's seed, or owner resolves to nothing.