suppa-mcp-2 1.1.3 → 1.2.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/LICENSE +21 -21
- package/README.md +379 -342
- package/dist/auth.js +29 -25
- package/dist/server.js +92 -51
- package/dist/tools/entity.js +343 -40
- package/dist/tools/migrate.js +459 -144
- package/package.json +50 -50
- package/skills/suppa-entity-code/SKILL.md +122 -0
- package/skills/suppa-entity-code/references/entities.md +289 -0
- package/skills/suppa-entity-code/references/registration.md +174 -0
- package/skills/suppa-entity-code/references/seeds.md +134 -0
- package/skills/suppa-entity-code/references/v1-mapping.md +78 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +692 -0
- package/skills/suppa-entity-code/templates/entity.template.ts +79 -0
- package/skills/suppa-entity-code/templates/seed.template.ts +41 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Registration — 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
|
+
## EntityModule.forFeature
|
|
6
|
+
|
|
7
|
+
Everything goes through EntityModule from @suppa/sdk. Import it with forFeature() in the module that owns the entities — usually AppModule.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Module } from '@nestjs/common';
|
|
11
|
+
import { EntityModule } from '@suppa/sdk';
|
|
12
|
+
import { Workflows, StageWorkflows } from '../common/database/entities';
|
|
13
|
+
import { workflowsSeed, stageWorkflowsSeed } from '../common/database/seeds';
|
|
14
|
+
|
|
15
|
+
@Module({
|
|
16
|
+
imports: [
|
|
17
|
+
EntityModule.forFeature([Workflows, StageWorkflows], {
|
|
18
|
+
seeds: [workflowsSeed, stageWorkflowsSeed],
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
})
|
|
22
|
+
export class AppModule {}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
EntityModule.forFeature() is what makes the platform aware of your entities and seeds. An entity class that is never passed to forFeature() is invisible — no table is created for it.
|
|
26
|
+
|
|
27
|
+
## Call Shapes
|
|
28
|
+
|
|
29
|
+
There are two supported shapes:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// 1. Explicit classes, with optional options
|
|
33
|
+
EntityModule.forFeature([Workflows, StageWorkflows], {
|
|
34
|
+
seeds: [workflowsSeed],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// 2. Options only — entities and seeds are autoloaded from paths
|
|
38
|
+
EntityModule.forFeature({
|
|
39
|
+
entitiesPath: 'dist/common/database/entities',
|
|
40
|
+
seedsPath: 'dist/common/database/seeds',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Options
|
|
45
|
+
|
|
46
|
+
| Option | Type | Description |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| seeds | EntitySeedDefinition[] | Seeds created with createSeed(). |
|
|
49
|
+
| entitiesPath | string \| string[] | Directory or file to autoload entity classes from. |
|
|
50
|
+
| seedsPath | string \| string[] | Directory or file to autoload seeds from. |
|
|
51
|
+
|
|
52
|
+
Resolution order:
|
|
53
|
+
|
|
54
|
+
1. If the entities array is passed and not empty, it is used and entitiesPath is ignored.
|
|
55
|
+
2. Otherwise entities are loaded from entitiesPath.
|
|
56
|
+
3. If seeds is passed and not empty, it is used and seedsPath is ignored.
|
|
57
|
+
4. Otherwise seeds are loaded from seedsPath.
|
|
58
|
+
|
|
59
|
+
## Recommended Project Structure
|
|
60
|
+
|
|
61
|
+
Keep entities and seeds side by side, separate from business logic:
|
|
62
|
+
|
|
63
|
+
```txt
|
|
64
|
+
src/
|
|
65
|
+
index.ts
|
|
66
|
+
app/
|
|
67
|
+
app.module.ts
|
|
68
|
+
common/
|
|
69
|
+
database/
|
|
70
|
+
index.ts
|
|
71
|
+
entities/
|
|
72
|
+
index.ts
|
|
73
|
+
workflows.entity.ts
|
|
74
|
+
stage-workflows.entity.ts
|
|
75
|
+
seeds/
|
|
76
|
+
index.ts
|
|
77
|
+
workflows.seed.ts
|
|
78
|
+
stage-workflows.seed.ts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Full Registration Example
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { Module } from '@nestjs/common';
|
|
85
|
+
import { EntityModule } from '@suppa/sdk';
|
|
86
|
+
import {
|
|
87
|
+
StageWorkflows,
|
|
88
|
+
Tasks,
|
|
89
|
+
Workflows,
|
|
90
|
+
} from '../common/database/entities';
|
|
91
|
+
import {
|
|
92
|
+
stageWorkflowsSeed,
|
|
93
|
+
workflowsSeed,
|
|
94
|
+
} from '../common/database/seeds';
|
|
95
|
+
|
|
96
|
+
@Module({
|
|
97
|
+
imports: [
|
|
98
|
+
EntityModule.forFeature([Workflows, StageWorkflows, Tasks], {
|
|
99
|
+
seeds: [workflowsSeed, stageWorkflowsSeed],
|
|
100
|
+
}),
|
|
101
|
+
],
|
|
102
|
+
})
|
|
103
|
+
export class AppModule {}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Two rules to remember:
|
|
107
|
+
|
|
108
|
+
- Every entity class must appear in the entities array.
|
|
109
|
+
- Every seed must appear in the seeds array, ordered so that dependencies come first.
|
|
110
|
+
|
|
111
|
+
## How Migrations Are Applied
|
|
112
|
+
|
|
113
|
+
You never run a migration command. The platform applies your schema as part of the application lifecycle:
|
|
114
|
+
|
|
115
|
+
1. The runner starts your application — on creation of the Applications record, on reload, or when a tenant is provisioned.
|
|
116
|
+
2. The SDK reads the decorator metadata of everything registered in EntityModule.forFeature() and generates two migration files: one for entity metadata, one for seeds.
|
|
117
|
+
3. The files are applied to the tenant's schema: tables, columns, relations, enums, indexes and checks are created or updated, then seeds are inserted or updated.
|
|
118
|
+
4. The result is recorded. If nothing in your entities or seeds changed since the last start, the step is skipped.
|
|
119
|
+
|
|
120
|
+
Two details worth knowing:
|
|
121
|
+
|
|
122
|
+
Entities and seeds behave differently on conflict. Entity metadata is overridden so the schema always converges to your class definitions. Seed rows are only inserted when missing, so data edited by users in the workspace is not overwritten on the next start.
|
|
123
|
+
|
|
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
|
+
|
|
126
|
+
## The Development Loop
|
|
127
|
+
|
|
128
|
+
```txt
|
|
129
|
+
edit entity / seed → push → reload the application → verify
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Reload with the application record id:
|
|
133
|
+
|
|
134
|
+
```http
|
|
135
|
+
POST /core/applications/:appId/reload
|
|
136
|
+
```
|
|
137
|
+
|
|
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.
|
|
139
|
+
|
|
140
|
+
See Run application for the full application lifecycle.
|
|
141
|
+
|
|
142
|
+
> **TIP**
|
|
143
|
+
> For a faster loop, suppa-dev start --watch runs your application locally through a tunnel so hooks and controllers reload on save.
|
|
144
|
+
|
|
145
|
+
## Common Mistakes
|
|
146
|
+
|
|
147
|
+
| Symptom | Cause |
|
|
148
|
+
|---|---|
|
|
149
|
+
| No table is created for an entity | The class was not passed to EntityModule.forFeature(). |
|
|
150
|
+
| Autoloading finds nothing | entitiesPath / seedsPath points at src/ instead of compiled dist/. |
|
|
151
|
+
| Duplicate seed rows after a restart | Record is missing one or more importKeyFields, so nothing matched. |
|
|
152
|
+
| Seed relation is empty or fails to resolve | Relation referenced by numeric id, or the target seed runs later. |
|
|
153
|
+
| Back reference can't insert | A reverse @OneToMany field is present in a seed record, possibly as []. |
|
|
154
|
+
| 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
|
+
| default value is rejected | A JavaScript value was passed instead of a SQL expression string. |
|
|
156
|
+
|
|
157
|
+
## Requirements
|
|
158
|
+
|
|
159
|
+
Use the latest version of @suppa/sdk:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pnpm add @suppa/sdk@latest
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Entities rely on decorator metadata, so the application tsconfig.json must enable both decorator flags:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"compilerOptions": {
|
|
170
|
+
"experimentalDecorators": true,
|
|
171
|
+
"emitDecoratorMetadata": true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Seed declaration — 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
|
+
## createSeed
|
|
6
|
+
|
|
7
|
+
A seed is created with createSeed(entityName, data, options?) and exported from a *.seed.ts file.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createSeed } from '@suppa/sdk';
|
|
11
|
+
import { EntityNamesEnum } from '../../modules';
|
|
12
|
+
|
|
13
|
+
export const workflowsSeed = createSeed(EntityNamesEnum.Workflows, [
|
|
14
|
+
{
|
|
15
|
+
name: 'Default',
|
|
16
|
+
description: 'Default set of statuses',
|
|
17
|
+
private: false,
|
|
18
|
+
externalId: null,
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The first argument is the entity name as a string — the same value as `name` in `@Entity()`. Keeping those names in a local enum (`EntityNamesEnum`) avoids typos across seeds.
|
|
24
|
+
|
|
25
|
+
## Idempotency
|
|
26
|
+
|
|
27
|
+
Seeds run on every application start, for every tenant. They must therefore be idempotent: a seed either inserts a record or updates the existing one, but never duplicates it.
|
|
28
|
+
|
|
29
|
+
Matching is done on the target entity's importKeyFields. So:
|
|
30
|
+
|
|
31
|
+
- Always provide all importKeyFields in every record.
|
|
32
|
+
- If the natural key does not fit your data, override identity per record with `$key`.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
export const localizationsSeed = createSeed('Localizations', [
|
|
36
|
+
{
|
|
37
|
+
$key: { key: 'task-manager.greeting' },
|
|
38
|
+
key: 'task-manager.greeting',
|
|
39
|
+
en: 'Hello',
|
|
40
|
+
uk: 'Привіт',
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Referencing Relations
|
|
46
|
+
|
|
47
|
+
Reference a related record through the target's importKeyFields, as an object — never by numeric id:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { createSeed } from '@suppa/sdk';
|
|
51
|
+
import { StageStatusEnum } from '../entities';
|
|
52
|
+
import { EntityNamesEnum } from '../../modules';
|
|
53
|
+
|
|
54
|
+
export const stageWorkflowsSeed = createSeed(EntityNamesEnum.StageWorkflows, [
|
|
55
|
+
{
|
|
56
|
+
name: 'To Do',
|
|
57
|
+
color: '#3069FE',
|
|
58
|
+
order: 1000,
|
|
59
|
+
default: true,
|
|
60
|
+
status: {
|
|
61
|
+
name: 'StageWorkflows.status',
|
|
62
|
+
value: StageStatusEnum.Active,
|
|
63
|
+
},
|
|
64
|
+
workflow: { name: 'Default' },
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'In Progress',
|
|
68
|
+
color: '#47D1E2',
|
|
69
|
+
order: 2000,
|
|
70
|
+
status: {
|
|
71
|
+
name: 'StageWorkflows.status',
|
|
72
|
+
value: StageStatusEnum.InProgress,
|
|
73
|
+
},
|
|
74
|
+
workflow: { name: 'Default' },
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'Done',
|
|
78
|
+
color: '#75D900',
|
|
79
|
+
order: 5000,
|
|
80
|
+
status: {
|
|
81
|
+
name: 'StageWorkflows.status',
|
|
82
|
+
value: StageStatusEnum.Completed,
|
|
83
|
+
},
|
|
84
|
+
workflow: { name: 'Default' },
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Two reference shapes appear here:
|
|
90
|
+
|
|
91
|
+
| Field type | Reference shape |
|
|
92
|
+
|---|---|
|
|
93
|
+
| @ManyToOne | { <importKeyField>: value } — e.g. { name: 'Default' } |
|
|
94
|
+
| @Enum | { name: '<global enum name>', value: '<enum value>' } |
|
|
95
|
+
| @ManyToMany | An array of reference objects. |
|
|
96
|
+
|
|
97
|
+
Because `workflow: { name: 'Default' }` resolves by name, the seed works in every tenant regardless of what id the Default workflow received there.
|
|
98
|
+
|
|
99
|
+
> **WARNING**
|
|
100
|
+
> Seed order matters for relations. Register a seed after the seed that creates the records it points at — workflowsSeed before stageWorkflowsSeed.
|
|
101
|
+
|
|
102
|
+
## What Not to Put in a Seed
|
|
103
|
+
|
|
104
|
+
| Never include | Why |
|
|
105
|
+
|---|---|
|
|
106
|
+
| id, createdAt, updatedAt, deletedAt, createdBy, removedBy | System columns. They differ per tenant and corrupt matching. |
|
|
107
|
+
| $readAccess, $updateAccess, $instanceAccess | Access metadata, not data. |
|
|
108
|
+
| Reverse @OneToMany fields — even as [] | Back references cannot be inserted; the import throws. |
|
|
109
|
+
| Numeric relation ids | They do not match across tenants. Use import-key references. |
|
|
110
|
+
|
|
111
|
+
> **TIP**
|
|
112
|
+
> 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
|
+
|
|
114
|
+
## Keeping Seed Files Thin
|
|
115
|
+
|
|
116
|
+
When a record carries a large payload, move the data to a static file and import it:
|
|
117
|
+
|
|
118
|
+
`src/common/database/static/currencies.ts`
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
export const CURRENCIES = [
|
|
122
|
+
{ code: 'USD', symbol: '$' },
|
|
123
|
+
{ code: 'EUR', symbol: '€' },
|
|
124
|
+
];
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`src/common/database/seeds/currencies.seed.ts`
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { createSeed } from '@suppa/sdk';
|
|
131
|
+
import { CURRENCIES } from '../static/currencies';
|
|
132
|
+
|
|
133
|
+
export const currenciesSeed = createSeed('Currencies', CURRENCIES);
|
|
134
|
+
```
|
|
@@ -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
|
+
```
|