suppa-mcp-2 1.3.1 → 1.4.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/dist/server.js +13 -6
- package/dist/tools/entity.js +47 -11
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +48 -7
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +1527 -1284
- package/skills/suppa-entity-code/templates/entity.template.ts +29 -1
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +99 -94
|
@@ -70,13 +70,41 @@ export class __EntityName__ extends SystemBaseEntity {
|
|
|
70
70
|
|
|
71
71
|
// Relation — ALWAYS a thunk (() => Target), never the class itself.
|
|
72
72
|
// No inverse passed — it's optional on @ManyToOne and omitted by default.
|
|
73
|
+
// TYPE THE PROPERTY: @ManyToOne holds ONE row, so the type is the target
|
|
74
|
+
// class itself. Drop the '?' only because of nullable: false; a nullable
|
|
75
|
+
// relation is written `__target__?: __TargetEntity__`.
|
|
73
76
|
@ManyToOne(() => __TargetEntity__, { nullable: false })
|
|
74
77
|
__target__: __TargetEntity__;
|
|
75
78
|
|
|
79
|
+
// The to-many decorators hold an ARRAY of the target. @ManyToMany takes no
|
|
80
|
+
// inverse; @OneToMany / @ManyToManyBackRef REQUIRE one, and it must select
|
|
81
|
+
// the property on the target that holds the other side.
|
|
82
|
+
// @ManyToMany(() => __TargetEntity__, { title: { en: 'Peers' } })
|
|
83
|
+
// __peers__: __TargetEntity__[];
|
|
84
|
+
//
|
|
85
|
+
// @OneToMany(() => __TargetEntity__, (entity) => entity.owner, { title: { en: 'Children' } })
|
|
86
|
+
// __children__: __TargetEntity__[];
|
|
87
|
+
//
|
|
88
|
+
// @ManyToManyBackRef(() => __TargetEntity__, (entity) => entity.__peers__, { title: { en: 'Back refs' } })
|
|
89
|
+
// __backRefs__: __TargetEntity__[];
|
|
90
|
+
|
|
76
91
|
// Fixed choices — @Enum/@MultiEnum, NEVER @Column({ type: 'enum' }).
|
|
77
|
-
|
|
92
|
+
// LOCAL enum (the default): no first argument — the decorator derives the
|
|
93
|
+
// name <ClassName>.<propertyName>.
|
|
94
|
+
@Enum(__Field__Enum, __Field__Titles, { nullable: false })
|
|
78
95
|
__field__: __Field__Enum;
|
|
79
96
|
|
|
97
|
+
// GLOBAL enum — pass the name FIRST, and only when the value set is shared
|
|
98
|
+
// across entities or referenced from a seed ({ name: '…', value: '…' }).
|
|
99
|
+
// @Enum('__EntityName__.__field__', __Field__Enum, __Field__Titles, { nullable: false })
|
|
100
|
+
// __field__: __Field__Enum;
|
|
101
|
+
|
|
102
|
+
// Field options: canGroup/canSort/showInTable/editFromTable/canFilter are
|
|
103
|
+
// already true and readOnly/searchable already false. Write one ONLY to
|
|
104
|
+
// depart from that — never restate a default on every field.
|
|
105
|
+
// @Column({ name: 'notes', type: FieldTypeEnum.Text, searchable: true })
|
|
106
|
+
// notes: string;
|
|
107
|
+
|
|
80
108
|
// Attachments — @File/@MultiFile, NEVER @Column({ type: 'file' }) or Bytea.
|
|
81
109
|
@File({ title: { en: 'Cover', uk: 'Обкладинка' } })
|
|
82
110
|
cover: any;
|
|
@@ -1,94 +1,99 @@
|
|
|
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
|
-
// No inverse passed — it's optional on @ManyToOne and omitted by default.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
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
|
+
// No inverse passed — it's optional on @ManyToOne and omitted by default.
|
|
48
|
+
// nullable: false, because a tabular-part row always belongs to a parent —
|
|
49
|
+
// and `owner` is the first importKeyField, which a null would break. The
|
|
50
|
+
// property is typed as the parent class, with no '?' to match that.
|
|
51
|
+
@ManyToOne(() => __ParentEntity__, {
|
|
52
|
+
name: 'owner',
|
|
53
|
+
key: '__EntityName__.owner',
|
|
54
|
+
nullable: false,
|
|
55
|
+
title: { en: '__Parent title__', uk: '__Батьківська назва__' },
|
|
56
|
+
})
|
|
57
|
+
owner: __ParentEntity__;
|
|
58
|
+
|
|
59
|
+
@Column({
|
|
60
|
+
name: '__businessKeyField__',
|
|
61
|
+
title: { en: '__Field__', uk: '__Назва поля__' },
|
|
62
|
+
type: FieldTypeEnum.Text,
|
|
63
|
+
nullable: false,
|
|
64
|
+
})
|
|
65
|
+
__businessKeyField__: string;
|
|
66
|
+
|
|
67
|
+
@Column({
|
|
68
|
+
name: 'order',
|
|
69
|
+
title: { en: 'Order', uk: 'Порядок' },
|
|
70
|
+
type: FieldTypeEnum.Integer,
|
|
71
|
+
})
|
|
72
|
+
order: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Declare the back reference on the PARENT entity (__parent-entity__.entity.ts) so the
|
|
76
|
+
* rows read as a nested array and the tab gets a localized name. A back reference is
|
|
77
|
+
* readable, not writable — NEVER include it in a seed, not even as []:
|
|
78
|
+
*
|
|
79
|
+
* @OneToMany(() => __EntityName__, (item) => item.owner, {
|
|
80
|
+
* title: { en: '__Tab title__', uk: '__Назва вкладки__' },
|
|
81
|
+
* })
|
|
82
|
+
* __childrenField__: __EntityName__[];
|
|
83
|
+
*
|
|
84
|
+
* Seed the tabular part with its own seed, referencing the parent through owner —
|
|
85
|
+
* exactly like any other @ManyToOne (via the PARENT's importKeyFields):
|
|
86
|
+
*
|
|
87
|
+
* import { createSeed } from '@suppa/sdk';
|
|
88
|
+
*
|
|
89
|
+
* export const __camelCasePlural__Seed = createSeed('__EntityName__', [
|
|
90
|
+
* { owner: { __parentBusinessKeyField__: '__parent-key-value__' }, __businessKeyField__: 'First', order: 1000 },
|
|
91
|
+
* ]);
|
|
92
|
+
*
|
|
93
|
+
* Register both classes in forFeature() — the parent does not need to come first —
|
|
94
|
+
* but the PARENT's seed must run before this one, or owner resolves to nothing:
|
|
95
|
+
*
|
|
96
|
+
* EntityModule.forFeature([__ParentEntity__, __EntityName__], {
|
|
97
|
+
* seeds: [__parentEntity__Seed, __camelCasePlural__Seed],
|
|
98
|
+
* });
|
|
99
|
+
*/
|