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/package.json CHANGED
@@ -1,50 +1,50 @@
1
- {
2
- "name": "suppa-mcp-2",
3
- "version": "1.1.3",
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
- "type": "module",
6
- "bin": { "suppa-mcp": "dist/bin.js" },
7
- "main": "dist/bin.js",
8
- "files": ["dist", "README.md", "LICENSE"],
9
- "engines": { "node": ">=18" },
10
- "scripts": {
11
- "build": "tsc",
12
- "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
13
- "rebuild": "npm run clean && npm run build",
14
- "start": "node dist/bin.js",
15
- "dev": "tsc --watch",
16
- "test": "vitest run",
17
- "test:watch": "vitest",
18
- "prepublishOnly": "npm run build && npm test",
19
- "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js"
20
- },
21
- "keywords": [
22
- "mcp",
23
- "model-context-protocol",
24
- "suppa",
25
- "modern-expo",
26
- "ai",
27
- "llm",
28
- "tools",
29
- "claude",
30
- "copilot",
31
- "cursor"
32
- ],
33
- "license": "MIT",
34
- "repository": {
35
- "type": "git",
36
- "url": "https://git.modern-expo.com/asu/me-development/skills.git",
37
- "directory": "suppa-mcp-node"
38
- },
39
- "homepage": "https://modern.suppa.me",
40
- "dependencies": {
41
- "@modelcontextprotocol/sdk": "^1.18.0",
42
- "@napi-rs/keyring": "^1.1.0",
43
- "zod": "^3.23.8"
44
- },
45
- "devDependencies": {
46
- "@types/node": "^20.0.0",
47
- "typescript": "^5.6.0",
48
- "vitest": "^2.1.0"
49
- }
50
- }
1
+ {
2
+ "name": "suppa-mcp-2",
3
+ "version": "1.2.0",
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
+ "type": "module",
6
+ "bin": { "suppa-mcp": "dist/bin.js" },
7
+ "main": "dist/bin.js",
8
+ "files": ["dist", "skills", "README.md", "LICENSE"],
9
+ "engines": { "node": ">=18" },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
13
+ "rebuild": "npm run clean && npm run build",
14
+ "start": "node dist/bin.js",
15
+ "dev": "tsc --watch",
16
+ "test": "vitest run",
17
+ "test:watch": "vitest",
18
+ "prepublishOnly": "npm run build && npm test",
19
+ "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js"
20
+ },
21
+ "keywords": [
22
+ "mcp",
23
+ "model-context-protocol",
24
+ "suppa",
25
+ "modern-expo",
26
+ "ai",
27
+ "llm",
28
+ "tools",
29
+ "claude",
30
+ "copilot",
31
+ "cursor"
32
+ ],
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://git.modern-expo.com/asu/me-development/skills.git",
37
+ "directory": "suppa-mcp-node"
38
+ },
39
+ "homepage": "https://modern.suppa.me",
40
+ "dependencies": {
41
+ "@modelcontextprotocol/sdk": "^1.18.0",
42
+ "@napi-rs/keyring": "^1.1.0",
43
+ "zod": "^3.23.8"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.0.0",
47
+ "typescript": "^5.6.0",
48
+ "vitest": "^2.1.0"
49
+ }
50
+ }
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: suppa-entity-code
3
+ description: Write Suppa 2.0 application schema CODE — entity classes, seeds, and EntityModule registration — for a versioned application package, following the platform's declarative migration rules (the entity class IS the migration). Use whenever the user wants to create entities/tables/seeds as TypeScript code in an app repo instead of via API tools, port a Suppa 1.0 entity to v2 code, or asks about @Entity/@Column/@Enum/@ManyToOne decorators, createSeed, importKeyFields, or EntityModule.forFeature. Trigger phrases (English) — "write entity code", "entity class", "declarative migration", "create seed", "seed file", "register entity module", "port v1 entity to code"; (Ukrainian / Українська) — "написати код сутності", "клас сутності", "міграція", "сід", "seeds", "зареєструвати сутність", "перенести сутність у код".
4
+ ---
5
+
6
+ # Suppa v2 Entity Code (declarative migrations)
7
+
8
+ The entity class **is** the migration — there is no separate migration file to write.
9
+ The platform converges every tenant's schema to your class definitions on every application start.
10
+ This skill writes `*.entity.ts` files, `*.seed.ts` files, and the `EntityModule.forFeature()` registration that wires them in.
11
+
12
+ ## Which path — API tools or code?
13
+
14
+ | Situation | Use |
15
+ |---|---|
16
+ | Live tenant, no app repo — one-off schema change | `suppa_create_entity` / `suppa_add_field` (API tools) |
17
+ | Versioned application package — schema ships as code | **this skill** |
18
+
19
+ Code is authoritative: on every start, entity metadata is **overridden** to match the classes. Seed rows are **insert-only** — rows a user already edited in a tenant survive.
20
+
21
+ ## Pre-flight (hard gate)
22
+
23
+ Confirm all 5 before writing anything:
24
+
25
+ 1. Target app repo exists, with `src/index.ts` exporting `AppModule`.
26
+ 2. `@suppa/sdk@latest` is installed (`pnpm add @suppa/sdk@latest`).
27
+ 3. `tsconfig.json` has both `experimentalDecorators: true` and `emitDecoratorMetadata: true`.
28
+ 4. Recommended layout is in place (or will be created): `src/common/database/{entities,seeds}`, each with an `index.ts` barrel.
29
+ 5. A local module — conventionally `src/common/modules.ts` (imported as `'../../modules'` from `src/common/database/seeds/`) — exports `EntityNamesEnum` (one member per entity `name`).
30
+
31
+ ## Blocking questions — ask BEFORE writing any file
32
+
33
+ | Ask | Get it wrong and… |
34
+ |---|---|
35
+ | `importKeyFields` — the business key | Seeds have nothing to match on -> duplicate rows every restart |
36
+ | `representativeFieldName` | Records display incorrectly wherever the entity is referenced |
37
+ | Per-field `nullable` | The wrong constraint ships to every tenant |
38
+ | Flow B only — `inverse` selector for `@OneToMany` / `@ManyToManyBackRef` | v1 never reports it — it cannot be inferred, must ask |
39
+
40
+ ## Hard rules
41
+
42
+ 1. Every entity extends `SystemBaseEntity`; never declare `id`, `createdAt`, `updatedAt`, `deletedAt`, `createdBy`, `removedBy` yourself — it already provides them.
43
+ 2. `default` is a SQL expression string — `'false'`, `"'draft'"` — never a JS value; a JS value is rejected at migration time.
44
+ 3. Scalars only via `@Column({ type: FieldTypeEnum.X })`; relations/enums/files are NEVER declared via `@Column` — use the `@ManyToOne`/`@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef`/`@Enum`/`@MultiEnum`/`@File`/`@MultiFile` families.
45
+ 4. Relation targets are thunks — `() => Target`, never the class itself — or circular imports break.
46
+ 5. If an option isn't in the reference tables (`references/entities.md`, `references/seeds.md`, `references/registration.md`), it doesn't exist — stop and ask, don't guess.
47
+ 6. Every entity class must appear in some `forFeature()`'s `entities` array; every seed in its `seeds` array, dependencies first — `workflowsSeed` before `stageWorkflowsSeed`.
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
+ 8. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
50
+ 9. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
51
+
52
+ ## Decorator decision table
53
+
54
+ | You need | Decorator |
55
+ |---|---|
56
+ | Scalar column (text/numeric/integer/boolean/timestamp/json/uuid/multi-language/bytea/tsvector/multi-type/icon) | `@Column({ type: FieldTypeEnum.<Member> })` |
57
+ | Fixed single-select value set | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
58
+ | Fixed multi-select value set | `@MultiEnum(...)` — same signature as `@Enum` |
59
+ | Foreign key on this entity | `@ManyToOne(target, options?)` or `@ManyToOne(target, inverse, options?)` |
60
+ | Pivot table between two entities | `@ManyToMany(target, options?)` or `@ManyToMany(target, inverse, options?)` |
61
+ | Reverse side of a `@ManyToMany` | `@ManyToManyBackRef(target, inverse, options?)` |
62
+ | Reverse side of a `@ManyToOne` | `@OneToMany(target, inverse, options?)` |
63
+ | Single attachment | `@File({ title })` |
64
+ | Multiple attachments | `@MultiFile({ title })` |
65
+
66
+ `target` is always a thunk, `() => Target`. `inverse` is a property selector on the target entity, e.g. `(task) => task.project`.
67
+
68
+ ## Naming conventions
69
+
70
+ | Thing | Convention | Example |
71
+ |---|---|---|
72
+ | Entity/seed file | kebab-case, plural | `stage-workflows.entity.ts` / `stage-workflows.seed.ts` |
73
+ | Entity class | PascalCase, plural = `@Entity()`'s `name` | `StageWorkflows` |
74
+ | Seed export | camelCase plural + `Seed` | `stageWorkflowsSeed` |
75
+ | Enum | PascalCase + `Enum` | `StageStatusEnum` |
76
+ | Titles map | PascalCase + `Titles` suffix — this doc's own worked examples drop the suffix (`StageStatus`); either is acceptable if used consistently within a repo | `StageStatusTitles` (or `StageStatus`) |
77
+ | Enum global name | `'<EntityName>.<field>'` | `'StageWorkflows.status'` |
78
+ | Index name | `idx_<table>_<cols>` | `idx_tasks_project` |
79
+ | Check name | `chk_<table>_<rule>` | `chk_tasks_positive_duration` |
80
+
81
+ ## Flow A — new entity in an app repo
82
+
83
+ 1. Pre-flight (above) — confirm repo, SDK version, tsconfig, layout.
84
+ 2. Blocking questions (above) — get answers before writing any file.
85
+ 3. Write the entity from `templates/entity.template.ts`, following `references/entities.md`.
86
+ 4. Need default rows? Write the seed from `templates/seed.template.ts`, following `references/seeds.md`.
87
+ 5. Update the `entities`/`seeds` barrels and the `EntityModule.forFeature()` call — `references/registration.md`.
88
+ 6. Run the close-out gate (below) — do not report "done" before all 4 steps pass.
89
+
90
+ ## Flow B — port a Suppa 1.0 entity to v2 code
91
+
92
+ 1. `suppa_read_v1_entities` -> find the v1 entity.
93
+ 2. `suppa_read_v1_entity_props` (+ `suppa_read_v1_enum` for enum fields) -> read its fields.
94
+ 3. Map every field per `references/v1-mapping.md` — the same authority (`classifyV1Field`) as the API migration path.
95
+ 4. Never silently drop a field: anything unmapped or unsupported gets `// SKIPPED: <field> — <reason>` inside the class body.
96
+ 5. Continue with Flow A from the blocking questions onward (steps 2-6 above).
97
+ 6. Record data migrates separately, via `suppa_migrate_entities_from_v1` — this skill only produces schema code.
98
+
99
+ ## Close-out gate (all steps, in order — no "done" before all pass)
100
+
101
+ ```
102
+ 1. node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root> # 0 errors
103
+ (installed via npm: node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs)
104
+ 2. npx tsc --noEmit # in the app repo
105
+ 3. push, then reload: POST /core/applications/:appId/reload
106
+ 4. verify the tenant converged: suppa_describe_entity('<EntityName>')
107
+ ```
108
+
109
+ `validate-suppa-schema.mjs` exits `0` on a clean run, `1` when errors are found, `2` on a usage error or a missing path. The gate requires exit `0` — warnings alone do not block.
110
+
111
+ ## Troubleshooting
112
+
113
+ | Symptom | Cause | Validator code |
114
+ |---|---|---|
115
+ | No table is created for an entity | The class was not passed to `EntityModule.forFeature()` | E301 |
116
+ | Autoloading finds nothing | `entitiesPath` / `seedsPath` points at `src/` instead of compiled `dist/` | E303 |
117
+ | Duplicate seed rows after a restart | Record is missing one or more `importKeyFields` | E205 |
118
+ | Seed relation is empty or fails to resolve | Relation referenced by numeric id, or the target seed runs later | E203 + E304 |
119
+ | Back reference can't insert | A reverse `@OneToMany` field is present in a seed record, possibly as `[]` | E204 |
120
+ | A renamed entity or field appears as a new one | No `key` option was set | W602 |
121
+ | `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 |
@@ -0,0 +1,289 @@
1
+ # Entity 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
+ ## A Minimal Entity
6
+
7
+ ```ts
8
+ import { Column, Entity, FieldTypeEnum, SystemBaseEntity } from '@suppa/sdk';
9
+
10
+ @Entity({
11
+ name: 'Workflows',
12
+ title: { en: 'Workflows', uk: 'Робочі процеси' },
13
+ importKeyFields: ['name'],
14
+ representativeFieldName: 'name',
15
+ })
16
+ export class Workflows extends SystemBaseEntity {
17
+ @Column({ name: 'name', type: FieldTypeEnum.Text, nullable: false })
18
+ name: string;
19
+
20
+ @Column({ name: 'description', type: FieldTypeEnum.Text })
21
+ description: string;
22
+
23
+ @Column({
24
+ name: 'private',
25
+ type: FieldTypeEnum.Boolean,
26
+ default: 'false',
27
+ })
28
+ private: boolean;
29
+
30
+ @Column({ name: 'externalId', type: FieldTypeEnum.UUID })
31
+ externalId: string;
32
+ }
33
+ ```
34
+
35
+ ## SystemBaseEntity
36
+
37
+ Every entity must extend SystemBaseEntity. It contributes the standard columns, so you never declare them yourself:
38
+
39
+ | Field | Type | Description |
40
+ |---|---|---|
41
+ | id | serial | Auto-increment primary key |
42
+ | createdAt | timestamp | Creation timestamp |
43
+ | updatedAt | timestamp | Last update timestamp |
44
+ | deletedAt | timestamp | Soft-delete timestamp |
45
+ | createdBy | ManyToOne(Users) | Who created the record |
46
+ | removedBy | ManyToOne(Users) | Who soft-deleted it |
47
+
48
+ ## @Entity() Options
49
+
50
+ | Option | Type | Description |
51
+ |---|---|---|
52
+ | name | string | Entity and table name. Defaults to the class name. |
53
+ | title | Record<string, string> | Localized display name. |
54
+ | comment | string | Description shown in metadata. |
55
+ | representativeFieldName | string | Field used to display a record. Defaults to id. |
56
+ | importKeyFields | string[] | Business key used by seeds, import and relation references. |
57
+ | key | string | Stable identifier that survives renaming the entity. |
58
+ | icon | Record<string, any> | Icon configuration. |
59
+ | type | string | Entity type. |
60
+ | options | Record<string, any> | Platform features to enable or disable for the entity (see below). |
61
+
62
+ options toggles the built-in per-entity features. Disable what the entity does not need — each enabled feature adds side tables and processing:
63
+
64
+ ```ts
65
+ @Entity({
66
+ name: 'Workflows',
67
+ importKeyFields: ['name'],
68
+ options: {
69
+ comments: false,
70
+ favorites: false,
71
+ approvals: false,
72
+ timeTracking: false,
73
+ browsingHistory: false,
74
+ trackChangeHistory: false,
75
+ globalSearch: false,
76
+ notificationMutes: false,
77
+ reminders: false,
78
+ },
79
+ })
80
+ export class Workflows extends SystemBaseEntity {}
81
+ ```
82
+
83
+ ## @Column()
84
+
85
+ ```ts
86
+ import { Column, FieldTypeEnum } from '@suppa/sdk';
87
+
88
+ @Column({
89
+ name: 'title',
90
+ type: FieldTypeEnum.Text,
91
+ nullable: false,
92
+ length: 255,
93
+ })
94
+ title: string;
95
+
96
+ @Column({
97
+ name: 'estimatedDuration',
98
+ type: FieldTypeEnum.Numeric,
99
+ decimalPlaces: 2,
100
+ })
101
+ estimatedDuration: number;
102
+
103
+ @Column({ name: 'isActive', type: FieldTypeEnum.Boolean, default: 'false' })
104
+ isActive: boolean;
105
+
106
+ @Column({ name: 'deadline', type: FieldTypeEnum.Timestamp })
107
+ deadline: string;
108
+ ```
109
+
110
+ | Option | Type | Description |
111
+ |---|---|---|
112
+ | type | FieldTypeEnum | Column type. Take the value from FieldTypeEnum (see below). |
113
+ | name | string | Column name. Defaults to the property name. |
114
+ | nullable | boolean | Allow NULL. |
115
+ | primary | boolean | Mark as primary key. |
116
+ | unique | boolean | Unique constraint. |
117
+ | default | string | Default value as a SQL expression string. |
118
+ | length | number | Maximum length. |
119
+ | title | Record<string, string> | Localized field name. |
120
+ | comment | string | Description. |
121
+ | key | string | Stable identifier that survives renaming. |
122
+ | minLength | number | Validation: minimum length. |
123
+ | minValue | number | Validation: minimum value. |
124
+ | maxValue | number | Validation: maximum value. |
125
+ | decimalPlaces | number | Decimal precision. |
126
+ | isOnlyPositive | boolean | Positive numbers only. |
127
+ | mask | string | Input mask. |
128
+
129
+ > **WARNING**
130
+ > `default` is a string containing a SQL expression, not a JavaScript value. Write `default: 'false'`, not `default: false`, and `default: "'draft'"` for a string literal.
131
+
132
+ ## FieldTypeEnum — Column Types
133
+
134
+ Column types come from the FieldTypeEnum enum exported by @suppa/sdk:
135
+
136
+ ```ts
137
+ import { FieldTypeEnum } from '@suppa/sdk';
138
+ ```
139
+
140
+ `type` is declared as string, so a raw literal such as `type: 'text'` still compiles — but a misspelled one (`'txet'`) compiles too and only fails when the migration runs. Referencing the enum turns that into an editor error, and gives you the full list of valid types on autocomplete.
141
+
142
+ | Member | Value | Use for |
143
+ |---|---|---|
144
+ | Text | text | Strings of any length. Add length to cap it. |
145
+ | Numeric | numeric | Decimal numbers. Pair with decimalPlaces. |
146
+ | Integer | integer | Whole numbers. |
147
+ | Serial | serial | Auto-increment integer. Already provided by SystemBaseEntity.id. |
148
+ | Boolean | boolean | true / false. |
149
+ | Timestamp | timestamp | Dates and date-times. |
150
+ | JSON | json | Arbitrary structured payloads. |
151
+ | UUID | uuid | External identifiers. |
152
+ | MultiLang | multi-language | Per-language string values stored on the record. |
153
+ | Bytea | bytea | Raw binary. Prefer @File for attachments. |
154
+ | TsVector | tsvector | Full-text search vectors. |
155
+ | MultiType | multi-type | Composite field built from sub-fields. |
156
+ | Icon | icon | Icon reference. |
157
+
158
+ > **TIP**
159
+ > FieldTypeEnum covers scalar columns only. Relations, enums and files are declared with their own decorators — @ManyToOne, @ManyToMany, @OneToMany, @Enum, @MultiEnum, @File, @MultiFile — and never with @Column({ type: ... }). The SDK also exports RelationTypeEnum with those relation kinds, but you do not pass it manually; each decorator sets it for you.
160
+
161
+ ## Relations
162
+
163
+ Relation decorators take a thunk returning the target class — `() => Workflows` — which keeps circular imports working:
164
+
165
+ ```ts
166
+ import {
167
+ Entity,
168
+ ManyToOne,
169
+ ManyToMany,
170
+ OneToMany,
171
+ SystemBaseEntity,
172
+ IconsEntity,
173
+ } from '@suppa/sdk';
174
+ import { Workflows } from './workflows.entity';
175
+
176
+ @Entity({ name: 'StageWorkflows', importKeyFields: ['name'] })
177
+ export class StageWorkflows extends SystemBaseEntity {
178
+ @ManyToOne(() => Workflows, { nullable: false })
179
+ workflow: Workflows;
180
+
181
+ @ManyToOne(() => IconsEntity)
182
+ icon: any;
183
+ }
184
+ ```
185
+
186
+ | Decorator | Signature | Use |
187
+ |---|---|---|
188
+ | @ManyToOne | (target, options?) or (target, inverse, options?) | Foreign key on this entity. |
189
+ | @ManyToMany | (target, options?) or (target, inverse, options?) | Pivot table between both entities. |
190
+ | @ManyToManyBackRef | (target, inverse, options?) | Reverse side of a ManyToMany. |
191
+ | @OneToMany | (target, inverse, options?) | Reverse side of a ManyToOne. |
192
+
193
+ `inverse` is a property selector on the target entity, for example `(task) => task.project`.
194
+
195
+ Platform entities are importable from the SDK when you need to point at them — for example `IconsEntity`.
196
+
197
+ ## Enums
198
+
199
+ @Enum and @MultiEnum accept a TypeScript enum with string values. Give the enum a global name (first argument) so it can be referenced from seeds and shared across entities:
200
+
201
+ ```ts
202
+ export enum StageStatusEnum {
203
+ Active = 'active',
204
+ InProgress = 'inprogress',
205
+ Deferred = 'deferred',
206
+ Completed = 'completed',
207
+ Canceled = 'cancelled',
208
+ }
209
+
210
+ export const StageStatus = {
211
+ [StageStatusEnum.Active]: { title: { en: 'Active', uk: 'Активний' } },
212
+ [StageStatusEnum.InProgress]: {
213
+ title: { en: 'In Progress', uk: 'В процесі' },
214
+ },
215
+ [StageStatusEnum.Deferred]: { title: { en: 'Deferred', uk: 'Відкладений' } },
216
+ [StageStatusEnum.Completed]: {
217
+ title: { en: 'Completed', uk: 'Виконаний' },
218
+ },
219
+ [StageStatusEnum.Canceled]: { title: { en: 'Canceled', uk: 'Скасований' } },
220
+ };
221
+
222
+ @Enum('StageWorkflows.status', StageStatusEnum, StageStatus, {
223
+ nullable: false,
224
+ })
225
+ status: StageStatusEnum;
226
+ ```
227
+
228
+ The second map is optional and adds a localized title, icon and order per value.
229
+
230
+ Use @MultiEnum with the same signatures for multi-select.
231
+
232
+ ## Files
233
+
234
+ ```ts
235
+ @File({ title: { en: 'Cover', uk: 'Обкладинка' } })
236
+ cover: any;
237
+
238
+ @MultiFile({ title: { en: 'Attachments', uk: 'Вкладення' } })
239
+ attachments: any[];
240
+ ```
241
+
242
+ ## Indexes and Checks
243
+
244
+ @Index() and @Check() are class decorators:
245
+
246
+ ```ts
247
+ @Entity({ name: 'Tasks', importKeyFields: ['externalId'] })
248
+ @Index('idx_tasks_project', ['project'])
249
+ @Index('idx_tasks_alive', ['deadline'], { where: '"deletedAt" IS NULL' })
250
+ @Check(
251
+ 'chk_tasks_positive_duration',
252
+ ['estimatedDuration'],
253
+ '"estimatedDuration" > 0',
254
+ )
255
+ export class Tasks extends SystemBaseEntity {}
256
+ ```
257
+
258
+ | @Index() option | Type | Description |
259
+ |---|---|---|
260
+ | unique | boolean | Unique index. |
261
+ | method | string | Index method, e.g. btree, gin. |
262
+ | where | string | Partial index predicate. |
263
+ | expression | string | Expression index. |
264
+ | comment | string | Description. |
265
+
266
+ ## importKeyFields — the Business Key
267
+
268
+ importKeyFields names the fields that identify a record independently of its numeric id. It is the backbone of seeds, export/import and cross-schema references, because id values differ between tenants.
269
+
270
+ ```ts
271
+ @Entity({ name: 'Workflows', importKeyFields: ['name'] })
272
+ ```
273
+
274
+ Pick fields that are stable and unique in practice. Without importKeyFields, seeds have nothing to match on and cannot stay idempotent.
275
+
276
+ > **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.
278
+
279
+ ## About title
280
+
281
+ title is not stored as a column. During migration the platform creates a Localizations record holding the per-language strings and links the entity or field metadata to it. You write the object inline and the platform handles the rest:
282
+
283
+ ```ts
284
+ @Column({
285
+ type: FieldTypeEnum.Text,
286
+ title: { en: 'Email', uk: 'Електронна пошта' },
287
+ })
288
+ email: string;
289
+ ```