suppa-mcp-2 1.3.2 → 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.
@@ -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
- @Enum('__EntityName__.__field__', __Field__Enum, __Field__Titles, { nullable: false })
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
- @ManyToOne(() => __ParentEntity__, {
49
- name: 'owner',
50
- title: { en: '__Parent title__', uk: '__Батьківська назва__' },
51
- })
52
- owner?: __ParentEntity__;
53
-
54
- @Column({
55
- name: '__businessKeyField__',
56
- title: { en: '__Field__', uk: '__Назва поля__' },
57
- type: FieldTypeEnum.Text,
58
- nullable: false,
59
- })
60
- __businessKeyField__: string;
61
-
62
- @Column({
63
- name: 'order',
64
- title: { en: 'Order', uk: 'Порядок' },
65
- type: FieldTypeEnum.Integer,
66
- })
67
- order: number;
68
- }
69
-
70
- /* Declare the back reference on the PARENT entity (__parent-entity__.entity.ts) so the
71
- * rows read as a nested array and the tab gets a localized name. A back reference is
72
- * readable, not writable — NEVER include it in a seed, not even as []:
73
- *
74
- * @OneToMany(() => __EntityName__, (item) => item.owner, {
75
- * title: { en: '__Tab title__', uk: '__Назва вкладки__' },
76
- * })
77
- * __childrenField__: __EntityName__[];
78
- *
79
- * Seed the tabular part with its own seed, referencing the parent through owner —
80
- * exactly like any other @ManyToOne (via the PARENT's importKeyFields):
81
- *
82
- * import { createSeed } from '@suppa/sdk';
83
- *
84
- * export const __camelCasePlural__Seed = createSeed('__EntityName__', [
85
- * { owner: { __parentBusinessKeyField__: '__parent-key-value__' }, __businessKeyField__: 'First', order: 1000 },
86
- * ]);
87
- *
88
- * Register both classes in forFeature() — the parent does not need to come first —
89
- * but the PARENT's seed must run before this one, or owner resolves to nothing:
90
- *
91
- * EntityModule.forFeature([__ParentEntity__, __EntityName__], {
92
- * seeds: [__parentEntity__Seed, __camelCasePlural__Seed],
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
+ */