suppa-mcp-2 1.2.0 → 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.
@@ -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
+ */