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