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,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity template — Suppa v2 declarative migration.
|
|
3
|
+
* The class IS the migration: the platform converges every tenant's table
|
|
4
|
+
* to this shape on each application start. Replace __markers__; delete
|
|
5
|
+
* any decorator you don't need. Rules: references/entities.md.
|
|
6
|
+
*
|
|
7
|
+
* File name: __kebab-case-plural__.entity.ts (e.g. stage-workflows.entity.ts)
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
Column,
|
|
11
|
+
Entity,
|
|
12
|
+
Enum,
|
|
13
|
+
FieldTypeEnum,
|
|
14
|
+
File,
|
|
15
|
+
ManyToOne,
|
|
16
|
+
MultiFile,
|
|
17
|
+
SystemBaseEntity,
|
|
18
|
+
} from '@suppa/sdk';
|
|
19
|
+
import { __TargetEntity__ } from './__target-entity__.entity';
|
|
20
|
+
|
|
21
|
+
// Fixed value set? Declare a string enum + optional per-value titles map.
|
|
22
|
+
// The GLOBAL NAME '__EntityName__.__field__' is how seeds reference values.
|
|
23
|
+
export enum __Field__Enum {
|
|
24
|
+
Active = 'active',
|
|
25
|
+
Done = 'done',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const __Field__Titles = {
|
|
29
|
+
[__Field__Enum.Active]: { title: { en: 'Active', uk: 'Активний' } },
|
|
30
|
+
[__Field__Enum.Done]: { title: { en: 'Done', uk: 'Виконаний' } },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
@Entity({
|
|
34
|
+
name: '__EntityName__', // = class name; table + createSeed() key
|
|
35
|
+
title: { en: '__EntityName__', uk: '__Українська назва__' },
|
|
36
|
+
key: '__entity-stable-key__', // survives renames — rename stays a rename
|
|
37
|
+
importKeyFields: ['__businessKeyField__'], // BLOCKING QUESTION — stable+unique business key
|
|
38
|
+
representativeFieldName: '__businessKeyField__', // BLOCKING QUESTION
|
|
39
|
+
// options: { comments: false, favorites: false, approvals: false,
|
|
40
|
+
// timeTracking: false, browsingHistory: false, trackChangeHistory: false,
|
|
41
|
+
// globalSearch: false, notificationMutes: false, reminders: false },
|
|
42
|
+
})
|
|
43
|
+
export class __EntityName__ extends SystemBaseEntity {
|
|
44
|
+
// NEVER declare: id, createdAt, updatedAt, deletedAt, createdBy, removedBy
|
|
45
|
+
// (SystemBaseEntity provides them).
|
|
46
|
+
|
|
47
|
+
// Scalar column — type ALWAYS from FieldTypeEnum, never a raw string.
|
|
48
|
+
@Column({ name: '__businessKeyField__', type: FieldTypeEnum.Text, nullable: false })
|
|
49
|
+
__businessKeyField__: string;
|
|
50
|
+
|
|
51
|
+
// default is a SQL EXPRESSION STRING: 'false', '0', "'draft'" — never a JS value.
|
|
52
|
+
@Column({ name: 'isActive', type: FieldTypeEnum.Boolean, default: 'false' })
|
|
53
|
+
isActive: boolean;
|
|
54
|
+
|
|
55
|
+
@Column({ name: 'amount', type: FieldTypeEnum.Numeric, decimalPlaces: 2 })
|
|
56
|
+
amount: number;
|
|
57
|
+
|
|
58
|
+
// Relation — ALWAYS a thunk (() => Target), never the class itself.
|
|
59
|
+
@ManyToOne(() => __TargetEntity__, { nullable: false })
|
|
60
|
+
__target__: __TargetEntity__;
|
|
61
|
+
|
|
62
|
+
// Fixed choices — @Enum/@MultiEnum, NEVER @Column({ type: 'enum' }).
|
|
63
|
+
@Enum('__EntityName__.__field__', __Field__Enum, __Field__Titles, { nullable: false })
|
|
64
|
+
__field__: __Field__Enum;
|
|
65
|
+
|
|
66
|
+
// Attachments — @File/@MultiFile, NEVER @Column({ type: 'file' }) or Bytea.
|
|
67
|
+
@File({ title: { en: 'Cover', uk: 'Обкладинка' } })
|
|
68
|
+
cover: any;
|
|
69
|
+
|
|
70
|
+
@MultiFile({ title: { en: 'Attachments', uk: 'Вкладення' } })
|
|
71
|
+
attachments: any[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Class-level index/check decorators go ABOVE the class — add `Check`/`Index`
|
|
75
|
+
* to the @suppa/sdk import above when you uncomment these:
|
|
76
|
+
@Index('idx___table____col__', ['__col__'])
|
|
77
|
+
@Index('idx___table___alive', ['deadline'], { where: '"deletedAt" IS NULL' })
|
|
78
|
+
@Check('chk___table____rule__', ['amount'], '"amount" >= 0')
|
|
79
|
+
*/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed template — default rows, applied on EVERY application start for EVERY
|
|
3
|
+
* tenant. Must be idempotent: matching runs on the entity's importKeyFields.
|
|
4
|
+
* Rules: references/seeds.md.
|
|
5
|
+
*
|
|
6
|
+
* File name: __kebab-case-plural__.seed.ts. Register in forFeature({ seeds })
|
|
7
|
+
* AFTER the seeds it depends on (workflowsSeed before stageWorkflowsSeed).
|
|
8
|
+
*/
|
|
9
|
+
import { createSeed } from '@suppa/sdk';
|
|
10
|
+
import { __Field__Enum } from '../entities/__kebab-case-plural__.entity';
|
|
11
|
+
import { EntityNamesEnum } from '../../modules';
|
|
12
|
+
|
|
13
|
+
export const __camelCasePlural__Seed = createSeed(EntityNamesEnum.__EntityName__, [
|
|
14
|
+
{
|
|
15
|
+
// ALWAYS include every importKeyField — else duplicate rows on restart.
|
|
16
|
+
__businessKeyField__: 'Default',
|
|
17
|
+
|
|
18
|
+
// Relation: reference by the TARGET's importKeyFields — NEVER numeric id.
|
|
19
|
+
__target__: { name: 'Default' },
|
|
20
|
+
|
|
21
|
+
// Enum: { name: '<global enum name>', value: '<enum value>' }.
|
|
22
|
+
__field__: {
|
|
23
|
+
name: '__EntityName__.__field__',
|
|
24
|
+
value: __Field__Enum.Active,
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// NEVER include: id/createdAt/updatedAt/deletedAt/createdBy/removedBy,
|
|
28
|
+
// $readAccess/$updateAccess/$instanceAccess, reverse @OneToMany fields
|
|
29
|
+
// (even as []), numeric relation ids.
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
// Natural key doesn't fit? Override identity per record with $key:
|
|
33
|
+
$key: { __businessKeyField__: 'unique-identity' },
|
|
34
|
+
__businessKeyField__: 'unique-identity',
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
/* Large payload? Keep the seed thin — move data to a static file:
|
|
39
|
+
src/common/database/static/__name__.ts → export const ROWS = [ … ];
|
|
40
|
+
then: export const __name__Seed = createSeed('__EntityName__', ROWS);
|
|
41
|
+
*/
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabular-part template — Suppa v2 declarative migration.
|
|
3
|
+
* A tabular part is a child entity whose rows only exist inside one parent
|
|
4
|
+
* record (checklist items of a task, lines of an order, attendees of an
|
|
5
|
+
* event) — the platform renders it as a table on the parent's form instead
|
|
6
|
+
* of giving it its own navigation entry.
|
|
7
|
+
*
|
|
8
|
+
* The triad, ALL THREE required — the platform does not infer any of them:
|
|
9
|
+
* 1. type: 'tabular-part' on @Entity()
|
|
10
|
+
* 2. relationEntityName — the PARENT entity's @Entity() name
|
|
11
|
+
* 3. a @ManyToOne field named EXACTLY `owner`, pointing at the parent class
|
|
12
|
+
*
|
|
13
|
+
* Put `owner` FIRST in importKeyFields — a row is unique inside its parent,
|
|
14
|
+
* not across the workspace; owner missing/misplaced ⇒ duplicate rows across
|
|
15
|
+
* different parents (E110/W607). Replace __markers__. Rules:
|
|
16
|
+
* references/tabular-parts.md.
|
|
17
|
+
*
|
|
18
|
+
* File name: __kebab-case-plural__.entity.ts (e.g. task-checklist-items.entity.ts)
|
|
19
|
+
*/
|
|
20
|
+
import {
|
|
21
|
+
Column,
|
|
22
|
+
Entity,
|
|
23
|
+
FieldTypeEnum,
|
|
24
|
+
Index,
|
|
25
|
+
ManyToOne,
|
|
26
|
+
SystemBaseEntity,
|
|
27
|
+
} from '@suppa/sdk';
|
|
28
|
+
import { __ParentEntity__ } from './__parent-entity__.entity';
|
|
29
|
+
|
|
30
|
+
@Index('__EntityName__OwnerKeyUindex', ['owner', '__businessKeyField__'], {
|
|
31
|
+
unique: true,
|
|
32
|
+
where: '"deletedAt" IS NULL',
|
|
33
|
+
})
|
|
34
|
+
@Entity({
|
|
35
|
+
name: '__EntityName__', // = class name; table + createSeed() key
|
|
36
|
+
title: { en: '__EntityName__', uk: '__Українська назва__' },
|
|
37
|
+
type: 'tabular-part', // 1/3 — makes this a tabular part of __ParentEntity__
|
|
38
|
+
relationEntityName: '__ParentEntity__', // 2/3 — the PARENT's @Entity() name, not the class name if they differ
|
|
39
|
+
importKeyFields: ['owner', '__businessKeyField__'], // owner FIRST — see references/tabular-parts.md
|
|
40
|
+
representativeFieldName: '__businessKeyField__',
|
|
41
|
+
})
|
|
42
|
+
export class __EntityName__ extends SystemBaseEntity {
|
|
43
|
+
// NEVER declare: id, createdAt, updatedAt, deletedAt, createdBy, removedBy
|
|
44
|
+
// (SystemBaseEntity provides them).
|
|
45
|
+
|
|
46
|
+
// 3/3 — the property MUST be named `owner`, pointing at the parent via a thunk.
|
|
47
|
+
@ManyToOne(() => __ParentEntity__, {
|
|
48
|
+
name: 'owner',
|
|
49
|
+
title: { en: '__Parent title__', uk: '__Батьківська назва__' },
|
|
50
|
+
})
|
|
51
|
+
owner?: __ParentEntity__;
|
|
52
|
+
|
|
53
|
+
@Column({
|
|
54
|
+
name: '__businessKeyField__',
|
|
55
|
+
title: { en: '__Field__', uk: '__Назва поля__' },
|
|
56
|
+
type: FieldTypeEnum.Text,
|
|
57
|
+
nullable: false,
|
|
58
|
+
})
|
|
59
|
+
__businessKeyField__: string;
|
|
60
|
+
|
|
61
|
+
@Column({
|
|
62
|
+
name: 'order',
|
|
63
|
+
title: { en: 'Order', uk: 'Порядок' },
|
|
64
|
+
type: FieldTypeEnum.Integer,
|
|
65
|
+
})
|
|
66
|
+
order: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Declare the back reference on the PARENT entity (__parent-entity__.entity.ts) so the
|
|
70
|
+
* rows read as a nested array and the tab gets a localized name. A back reference is
|
|
71
|
+
* readable, not writable — NEVER include it in a seed, not even as []:
|
|
72
|
+
*
|
|
73
|
+
* @OneToMany(() => __EntityName__, (item) => item.owner, {
|
|
74
|
+
* title: { en: '__Tab title__', uk: '__Назва вкладки__' },
|
|
75
|
+
* })
|
|
76
|
+
* __childrenField__: __EntityName__[];
|
|
77
|
+
*
|
|
78
|
+
* Seed the tabular part with its own seed, referencing the parent through owner —
|
|
79
|
+
* exactly like any other @ManyToOne (via the PARENT's importKeyFields):
|
|
80
|
+
*
|
|
81
|
+
* import { createSeed } from '@suppa/sdk';
|
|
82
|
+
*
|
|
83
|
+
* export const __camelCasePlural__Seed = createSeed('__EntityName__', [
|
|
84
|
+
* { owner: { __parentBusinessKeyField__: '__parent-key-value__' }, __businessKeyField__: 'First', order: 1000 },
|
|
85
|
+
* ]);
|
|
86
|
+
*
|
|
87
|
+
* Register both classes in forFeature() — the parent does not need to come first —
|
|
88
|
+
* but the PARENT's seed must run before this one, or owner resolves to nothing:
|
|
89
|
+
*
|
|
90
|
+
* EntityModule.forFeature([__ParentEntity__, __EntityName__], {
|
|
91
|
+
* seeds: [__parentEntity__Seed, __camelCasePlural__Seed],
|
|
92
|
+
* });
|
|
93
|
+
*/
|