suppa-mcp-2 1.1.4 → 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/LICENSE +21 -21
- package/README.md +387 -342
- package/dist/auth.js +29 -25
- package/dist/server.js +93 -50
- package/dist/tools/entity.js +343 -40
- package/dist/tools/migrate.js +148 -11
- package/package.json +50 -50
- package/skills/suppa-entity-code/SKILL.md +133 -0
- package/skills/suppa-entity-code/references/entities.md +292 -0
- package/skills/suppa-entity-code/references/registration.md +224 -0
- package/skills/suppa-entity-code/references/seeds.md +136 -0
- package/skills/suppa-entity-code/references/tabular-parts.md +146 -0
- package/skills/suppa-entity-code/references/v1-mapping.md +78 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +1063 -0
- package/skills/suppa-entity-code/templates/entity.template.ts +79 -0
- package/skills/suppa-entity-code/templates/seed.template.ts +41 -0
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +93 -0
|
@@ -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.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Suppa 1.0 → v2 code mapping
|
|
2
|
+
|
|
3
|
+
The API migration path and this code path share one authority: `classifyV1Field()` in suppa-mcp-2. Read the v1 schema with `suppa_read_v1_entities` → `suppa_read_v1_entity_props` (+ `suppa_read_v1_enum` for enum fields); normalize names with the same rules as `suppa_migrate_entities_from_v1` (entities → PascalCase, fields → camelCase, semantic dictionary, Cyrillic transliteration). Then map each classified field to a decorator with the table below. Never invent a mapping not listed here.
|
|
4
|
+
|
|
5
|
+
## Builder-type → decorator table
|
|
6
|
+
|
|
7
|
+
| `classifyV1Field` v2Type | Decorator to emit |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `text` | `@Column({ type: FieldTypeEnum.Text })` |
|
|
10
|
+
| `numeric` | `@Column({ type: FieldTypeEnum.Numeric })` |
|
|
11
|
+
| `integer` | `@Column({ type: FieldTypeEnum.Integer })` |
|
|
12
|
+
| `boolean` | `@Column({ type: FieldTypeEnum.Boolean })` |
|
|
13
|
+
| `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` |
|
|
14
|
+
| `json` | `@Column({ type: FieldTypeEnum.JSON })` |
|
|
15
|
+
| `uuid` | `@Column({ type: FieldTypeEnum.UUID })` |
|
|
16
|
+
| `multi-language` | `@Column({ type: FieldTypeEnum.MultiLang })` |
|
|
17
|
+
| `icon` | `@Column({ type: FieldTypeEnum.Icon })` — scalar by default; use `@ManyToOne(() => IconsEntity)` only when v1 reports a relation |
|
|
18
|
+
| `enum` | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles, { … })` + a TypeScript string enum built from `suppa_read_v1_enum` values + a seed is NOT needed (enum values live in the decorator maps) |
|
|
19
|
+
| `multi-enum` | `@MultiEnum(…)` — same signature as `@Enum` |
|
|
20
|
+
| `file` | `@File({ title: … })` |
|
|
21
|
+
| `multi-file` | `@MultiFile({ title: … })` |
|
|
22
|
+
| `many-to-one` | `@ManyToOne(() => <TargetClass>)` |
|
|
23
|
+
| `many-to-many` | `@ManyToMany(() => <TargetClass>)` |
|
|
24
|
+
| `one-to-many` | `@OneToMany(() => <TargetClass>, <inverse>)` — **inverse is a blocking question** (v1 props don't name it) |
|
|
25
|
+
| `many-to-many-backref` | `@ManyToManyBackRef(() => <TargetClass>, <inverse>)` — **inverse is a blocking question** |
|
|
26
|
+
| `serial` | never emitted — `SystemBaseEntity.id` already provides it |
|
|
27
|
+
| kind = `skip` | emit `// SKIPPED: <field> — <note from classifyV1Field>` inside the class body — never silently drop a field |
|
|
28
|
+
|
|
29
|
+
### Never drop a field silently
|
|
30
|
+
|
|
31
|
+
If `classifyV1Field` returns `kind = 'skip'` — a system/structural field, an unsupported relation sub_type, or an unrecognized v1 type — the field must still appear in the generated class as a `// SKIPPED: <field> — <reason>` comment, using the classifier's own note as `<reason>`. Omitting it is not an option: the generated code must account for every v1 field, migrated or not.
|
|
32
|
+
|
|
33
|
+
## Documented open edges
|
|
34
|
+
|
|
35
|
+
- `v2SubType: 'date'` (date-only v1 fields): `@Column()` has no documented `subType` option — emit `FieldTypeEnum.Timestamp` plus `// TODO: date-only in v1 — @Column has no documented date subtype; confirm rendering`.
|
|
36
|
+
- Icon duality: default scalar `FieldTypeEnum.Icon`; relation form only if v1 reports `type: relation` targeting icons.
|
|
37
|
+
- Lossy mappings carry the classifier's note as a trailing comment, e.g. `// v1 html_text → text (2.0 has no rich-text type)`.
|
|
38
|
+
|
|
39
|
+
## Worked example
|
|
40
|
+
|
|
41
|
+
v1 entity `zakazy` (fields: `nazva` — string/string, `status` — custom_enum/one-to-many, `klient` — relation/one-to-many).
|
|
42
|
+
|
|
43
|
+
Name normalization (per `nameMap.ts`'s `SEMANTIC_DICT`): `zakazy` → `Orders` (entity), `nazva` → `Name` → field `name`, `klient` → `Customer` → field `customer`, targeting entity class `Customers` (the v1 `klient` relation points at the customers entity, whose own v1 name normalizes to `Customers`).
|
|
44
|
+
|
|
45
|
+
Classification (per `classifyV1Field`): `nazva` (`string`/`string`) → scalar `text`. `status` (`custom_enum`/`one-to-many`) → `kind: enum`, `v2Type: 'enum'`, not multiple (sub_type is `one-to-many`, not `many-to-many`). `klient` (`relation`/`one-to-many`) → `kind: relation`, `v2Type: 'many-to-one'`, not multiple.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { Column, Entity, Enum, FieldTypeEnum, ManyToOne, SystemBaseEntity } from '@suppa/sdk';
|
|
49
|
+
import { Customers } from './customers.entity';
|
|
50
|
+
|
|
51
|
+
export enum StatusEnum {
|
|
52
|
+
New = 'new',
|
|
53
|
+
Completed = 'completed',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const StatusTitles = {
|
|
57
|
+
// Illustrative only — read the real value set with `suppa_read_v1_enum`.
|
|
58
|
+
[StatusEnum.New]: { title: { en: 'New' } },
|
|
59
|
+
[StatusEnum.Completed]: { title: { en: 'Completed' } },
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
@Entity({
|
|
63
|
+
name: 'Orders',
|
|
64
|
+
title: { en: 'zakazy' }, // carries the original v1 entity name through
|
|
65
|
+
// BLOCKING QUESTION: v1 does not report a business key for this entity —
|
|
66
|
+
// confirm the correct importKeyFields with the user before migrating.
|
|
67
|
+
})
|
|
68
|
+
export class Orders extends SystemBaseEntity {
|
|
69
|
+
@Column({ name: 'name', type: FieldTypeEnum.Text })
|
|
70
|
+
name: string;
|
|
71
|
+
|
|
72
|
+
@Enum('Orders.status', StatusEnum, StatusTitles)
|
|
73
|
+
status: StatusEnum;
|
|
74
|
+
|
|
75
|
+
@ManyToOne(() => Customers)
|
|
76
|
+
customer: Customers;
|
|
77
|
+
}
|
|
78
|
+
```
|