suppa-mcp-2 1.2.2 → 1.2.4
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/README.md +7 -5
- package/dist/httpClient.js +32 -1
- package/dist/server.js +117 -10
- package/dist/tools/docs.js +12 -3
- package/dist/tools/entity.js +298 -49
- package/dist/tools/migrate.js +71 -6
- package/dist/tools/tasks.js +12 -2
- package/dist/utils.js +89 -1
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +30 -12
- package/skills/suppa-entity-code/references/entities.md +87 -1
- package/skills/suppa-entity-code/references/v1-mapping.md +12 -2
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +176 -12
- package/skills/suppa-entity-code/templates/entity.template.ts +14 -0
- package/skills/suppa-entity-code/templates/tabular-part.template.ts +1 -0
package/dist/tools/migrate.js
CHANGED
|
@@ -604,6 +604,10 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
604
604
|
title: ftitle,
|
|
605
605
|
type: cls.v2Type,
|
|
606
606
|
required,
|
|
607
|
+
// The v1 default must travel with the planned field: _requiredOpts reads
|
|
608
|
+
// `default_value` off the PLAN, so a plan that omits it downgrades every
|
|
609
|
+
// required field to nullable and the notNull path is never taken.
|
|
610
|
+
default_value: p.default_value ?? null,
|
|
607
611
|
relation_entity: v2Target ?? (target ? normalizeEntityName(target) : null),
|
|
608
612
|
target_in_set: inSet,
|
|
609
613
|
};
|
|
@@ -630,6 +634,7 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
630
634
|
title: ftitle,
|
|
631
635
|
type: cls.v2Type,
|
|
632
636
|
required,
|
|
637
|
+
default_value: p.default_value ?? null,
|
|
633
638
|
enum_name: _enumNameFor(v2EntName, v2Fname),
|
|
634
639
|
values,
|
|
635
640
|
});
|
|
@@ -642,6 +647,7 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
642
647
|
title: ftitle,
|
|
643
648
|
type: cls.v2Type,
|
|
644
649
|
required,
|
|
650
|
+
default_value: p.default_value ?? null,
|
|
645
651
|
sub_type: cls.v2SubType,
|
|
646
652
|
max_length: cls.v2Type === "text" ? maxLength : null,
|
|
647
653
|
decimal_places: cls.v2Type === "numeric" ? decimalPlaces : null,
|
|
@@ -988,6 +994,62 @@ async function _runWrite(action, fn) {
|
|
|
988
994
|
}
|
|
989
995
|
return { action, status: "created", result: parsed };
|
|
990
996
|
}
|
|
997
|
+
// Types the 2.0 builder marks notNull WITHOUT a defaultValue: the doc's
|
|
998
|
+
// "Relation types" group, whose values live in a join/side table
|
|
999
|
+
// (docs/superpowers/specs/captures/api-entity-builder-builder.txt:43 —
|
|
1000
|
+
// "defaultValue ... Not applicable to relations, enums, or unique fields";
|
|
1001
|
+
// :63 lists the group). Mirrors NO_DEFAULT_VALUE_FIELD_TYPES in tools/entity.ts,
|
|
1002
|
+
// kept local so the migrator decides before the write instead of learning from a
|
|
1003
|
+
// failed one — entity.js is module-mocked in the migrator's tests.
|
|
1004
|
+
const _NO_DEFAULT_VALUE_TYPES = new Set([
|
|
1005
|
+
"many-to-one",
|
|
1006
|
+
"one-to-many",
|
|
1007
|
+
"many-to-many",
|
|
1008
|
+
"many-to-many-backref",
|
|
1009
|
+
"enum",
|
|
1010
|
+
"multi-enum",
|
|
1011
|
+
"file",
|
|
1012
|
+
"multi-file",
|
|
1013
|
+
]);
|
|
1014
|
+
const _DOWNGRADE_NOTE = "Some fields that are required in Suppa 1.0 were created NULLABLE here: the 2.0 " +
|
|
1015
|
+
"builder refuses NOT NULL without a defaultValue, and this migrator will not " +
|
|
1016
|
+
"invent one — the value empty rows should carry is a data decision, not a " +
|
|
1017
|
+
"migration detail. See required_downgrades. To restore the constraint: add " +
|
|
1018
|
+
'"default_value" to those fields in the plan (a SQL expression or literal, e.g. ' +
|
|
1019
|
+
"\"0\", \"'draft'\", \"now()\") and re-run in gap-fill mode after dropping the " +
|
|
1020
|
+
"field, or set NOT NULL in the builder UI once the column is backfilled.";
|
|
1021
|
+
/**
|
|
1022
|
+
* Resolve the required/defaultValue options for one planned field.
|
|
1023
|
+
*
|
|
1024
|
+
* A v1 field that is required but has no default cannot be created NOT NULL, and
|
|
1025
|
+
* that must NOT abort the migration: the field is created nullable and the
|
|
1026
|
+
* downgrade is recorded so the user can restore the constraint deliberately.
|
|
1027
|
+
*/
|
|
1028
|
+
function _requiredOpts(entity, f, downgrades) {
|
|
1029
|
+
if (!(f.required ?? false)) {
|
|
1030
|
+
return { required: false };
|
|
1031
|
+
}
|
|
1032
|
+
if (_NO_DEFAULT_VALUE_TYPES.has(String(f.type ?? ""))) {
|
|
1033
|
+
return { required: true }; // defaultValue does not apply — notNull needs none
|
|
1034
|
+
}
|
|
1035
|
+
// `default_value` is put on every planned field by _planFields (from the v1
|
|
1036
|
+
// property); a plan built elsewhere that omits it downgrades, it never guesses.
|
|
1037
|
+
const raw = f.default_value;
|
|
1038
|
+
const defaultValue = raw === null || raw === undefined ? "" : String(raw).trim();
|
|
1039
|
+
if (defaultValue !== "") {
|
|
1040
|
+
return { required: true, defaultValue };
|
|
1041
|
+
}
|
|
1042
|
+
downgrades.push({
|
|
1043
|
+
entity,
|
|
1044
|
+
field: f.name,
|
|
1045
|
+
type: f.type ?? null,
|
|
1046
|
+
v1_required: true,
|
|
1047
|
+
created_as: "nullable",
|
|
1048
|
+
reason: "required in v1 but the plan carries no default_value; the 2.0 builder refuses " +
|
|
1049
|
+
"NOT NULL without one and no default is invented here",
|
|
1050
|
+
});
|
|
1051
|
+
return { required: false };
|
|
1052
|
+
}
|
|
991
1053
|
/**
|
|
992
1054
|
* Apply the plan to the active Suppa 2.0 tenant, idempotently. Two-pass for relations.
|
|
993
1055
|
*
|
|
@@ -998,6 +1060,7 @@ async function _runWrite(action, fn) {
|
|
|
998
1060
|
*/
|
|
999
1061
|
export async function _execute(plan, mode = "create") {
|
|
1000
1062
|
const details = [];
|
|
1063
|
+
const requiredDowngrades = [];
|
|
1001
1064
|
const existingEntities = await _liveEntityNames();
|
|
1002
1065
|
// Pass 1: entities + scalar + enum fields.
|
|
1003
1066
|
for (const ent of plan.entities) {
|
|
@@ -1030,7 +1093,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1030
1093
|
continue;
|
|
1031
1094
|
}
|
|
1032
1095
|
const step = await _runWrite(`add_field:${f.name}`, () => entityTools.addField(name, f.name, f.type, f.title, {
|
|
1033
|
-
|
|
1096
|
+
..._requiredOpts(name, f, requiredDowngrades),
|
|
1034
1097
|
subType: f.sub_type ?? null,
|
|
1035
1098
|
maxLength: f.max_length ?? null,
|
|
1036
1099
|
decimalPlaces: f.decimal_places ?? null,
|
|
@@ -1057,7 +1120,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1057
1120
|
}
|
|
1058
1121
|
}
|
|
1059
1122
|
const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(name, f.name, f.type ?? "enum", f.title, {
|
|
1060
|
-
|
|
1123
|
+
..._requiredOpts(name, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
|
|
1061
1124
|
enumName: f.enum_name,
|
|
1062
1125
|
}));
|
|
1063
1126
|
step.entity = name;
|
|
@@ -1081,7 +1144,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1081
1144
|
continue;
|
|
1082
1145
|
}
|
|
1083
1146
|
const step = await _runWrite(`add_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type, f.title, {
|
|
1084
|
-
|
|
1147
|
+
..._requiredOpts(tpName, f, requiredDowngrades),
|
|
1085
1148
|
subType: f.sub_type ?? null,
|
|
1086
1149
|
maxLength: f.max_length ?? null,
|
|
1087
1150
|
decimalPlaces: f.decimal_places ?? null,
|
|
@@ -1103,7 +1166,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1103
1166
|
}
|
|
1104
1167
|
}
|
|
1105
1168
|
const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type ?? "enum", f.title, {
|
|
1106
|
-
|
|
1169
|
+
..._requiredOpts(tpName, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
|
|
1107
1170
|
enumName: f.enum_name,
|
|
1108
1171
|
}));
|
|
1109
1172
|
step.entity = tpName;
|
|
@@ -1147,7 +1210,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1147
1210
|
continue;
|
|
1148
1211
|
}
|
|
1149
1212
|
const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(name, f.name, f.type, f.title, {
|
|
1150
|
-
|
|
1213
|
+
..._requiredOpts(name, f, requiredDowngrades),
|
|
1151
1214
|
relationEntity: f.relation_entity,
|
|
1152
1215
|
}));
|
|
1153
1216
|
step.entity = name;
|
|
@@ -1185,7 +1248,7 @@ export async function _execute(plan, mode = "create") {
|
|
|
1185
1248
|
continue;
|
|
1186
1249
|
}
|
|
1187
1250
|
const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(tp.name, f.name, f.type, f.title, {
|
|
1188
|
-
|
|
1251
|
+
..._requiredOpts(tp.name, f, requiredDowngrades),
|
|
1189
1252
|
relationEntity: f.relation_entity,
|
|
1190
1253
|
}));
|
|
1191
1254
|
step.entity = tp.name;
|
|
@@ -1221,6 +1284,8 @@ export async function _execute(plan, mode = "create") {
|
|
|
1221
1284
|
executed: true,
|
|
1222
1285
|
mode,
|
|
1223
1286
|
summary: _summarize(details),
|
|
1287
|
+
required_downgrades: requiredDowngrades,
|
|
1288
|
+
notes: requiredDowngrades.length > 0 ? [_DOWNGRADE_NOTE] : [],
|
|
1224
1289
|
verify,
|
|
1225
1290
|
details,
|
|
1226
1291
|
};
|
package/dist/tools/tasks.js
CHANGED
|
@@ -202,7 +202,13 @@ export async function createTask(title, description = "", assignedToId = null, p
|
|
|
202
202
|
const result = await insertEntity("Tasks", [fields]);
|
|
203
203
|
return jsonResponse(result.length ? result[0] : null);
|
|
204
204
|
}
|
|
205
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Update fields on an existing task.
|
|
207
|
+
*
|
|
208
|
+
* Every field written here is a scalar or a single {id} reference, so there is
|
|
209
|
+
* no merge path: a list-valued field would be REPLACED wholesale. Adding to /
|
|
210
|
+
* removing from a task's list field goes through updateRecord's merge/unmerge.
|
|
211
|
+
*/
|
|
206
212
|
export async function updateTask(taskId, title = null, description = null, assignedToId = null, projectId = null, workflowId = null, stageId = null, typeId = null, priorityId = null, deadline = null) {
|
|
207
213
|
const fields = {};
|
|
208
214
|
if (title !== null) {
|
|
@@ -243,7 +249,11 @@ export async function updateTask(taskId, title = null, description = null, assig
|
|
|
243
249
|
const result = await updateEntity("Tasks", taskId, fields);
|
|
244
250
|
return jsonResponse(result);
|
|
245
251
|
}
|
|
246
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Soft-delete a task by ID: /remove sets deletedAt and keeps the row, so this is
|
|
254
|
+
* reversible (restore is UI-only until 1.3.0) — nothing is purged. The task does
|
|
255
|
+
* stop appearing in normal reads.
|
|
256
|
+
*/
|
|
247
257
|
export async function deleteTask(taskId) {
|
|
248
258
|
const result = await removeEntity("Tasks", [makeFilter("id", taskId)]);
|
|
249
259
|
return jsonResponse(result);
|
package/dist/utils.js
CHANGED
|
@@ -128,6 +128,78 @@ function matchesExpectation(value, expect) {
|
|
|
128
128
|
// "any" -> object or array (Python default expect=(dict, list))
|
|
129
129
|
return isArray || isPlainObject;
|
|
130
130
|
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// merge / unmerge pre-flight
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
/**
|
|
135
|
+
* NO client-side cap on list length lives here, deliberately. The platform's
|
|
136
|
+
* documented 500 is a bound on RECORDS MATCHED, not on items sent:
|
|
137
|
+
* docs/superpowers/specs/captures/api-entity-builder-data.txt:396 — "The platform
|
|
138
|
+
* reads the current values before writing, so the operation is bounded: matching
|
|
139
|
+
* more than 500 records fails with Cannot perform 'merge'/'unmerge': update query
|
|
140
|
+
* returned maximum allowed records; limit is 500." That depends on the update's
|
|
141
|
+
* conditions, which this pure check never sees (and suppa_update_record targets a
|
|
142
|
+
* single record by id, so it cannot hit it). Refusing a long list here would have
|
|
143
|
+
* been this server inventing a rule the platform does not have.
|
|
144
|
+
*/
|
|
145
|
+
/**
|
|
146
|
+
* Check the `merge` / `unmerge` lists of an update against the fields being
|
|
147
|
+
* sent, BEFORE any request goes out.
|
|
148
|
+
*
|
|
149
|
+
* An update REPLACES a list-valued field; `merge` (add the listed items) and
|
|
150
|
+
* `unmerge` (remove them) opt out of that per field name. A name the platform
|
|
151
|
+
* cannot line up with a list in `fields` is not an error there — it is silently
|
|
152
|
+
* ignored, i.e. the list gets replaced anyway and the caller is told the update
|
|
153
|
+
* succeeded. That is exactly the data loss this guard exists to prevent, so we
|
|
154
|
+
* refuse instead.
|
|
155
|
+
*
|
|
156
|
+
* Pure. Returns one message per problem; an empty array means "safe to send".
|
|
157
|
+
*/
|
|
158
|
+
export function mergeListProblems(fields, merge = [], unmerge = []) {
|
|
159
|
+
const problems = [];
|
|
160
|
+
const both = merge.filter((n) => unmerge.includes(n));
|
|
161
|
+
for (const name of [...new Set(both)]) {
|
|
162
|
+
problems.push(`'${name}' appears in both merge and unmerge — one update cannot add and ` +
|
|
163
|
+
"remove the same field. Send two updates, or drop it from one list.");
|
|
164
|
+
}
|
|
165
|
+
const seen = new Set();
|
|
166
|
+
for (const [list, label] of [
|
|
167
|
+
[merge, "merge"],
|
|
168
|
+
[unmerge, "unmerge"],
|
|
169
|
+
]) {
|
|
170
|
+
for (const name of list) {
|
|
171
|
+
const key = `${label}:${name}`;
|
|
172
|
+
if (seen.has(key) || both.includes(name)) {
|
|
173
|
+
continue; // already reported
|
|
174
|
+
}
|
|
175
|
+
seen.add(key);
|
|
176
|
+
if (!Object.prototype.hasOwnProperty.call(fields, name)) {
|
|
177
|
+
problems.push(`'${name}' is listed in ${label} but is not in the fields being sent — ` +
|
|
178
|
+
`${label} only applies to a field you also write. Add "${name}": ` +
|
|
179
|
+
`[{"id": N}, ...] to fields_json, or drop '${name}' from ${label}.`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// data.txt:394 — "Every field named in merge / unmerge must hold an array in
|
|
183
|
+
// fields, otherwise the request fails with Field <name> is not an array."
|
|
184
|
+
const value = fields[name];
|
|
185
|
+
if (!Array.isArray(value)) {
|
|
186
|
+
problems.push(`'${name}' is listed in ${label} but its value is not an array (got ` +
|
|
187
|
+
`${typeName(value)}) — ${label} only applies to list-valued fields. ` +
|
|
188
|
+
`Send "${name}": [{"id": N}, ...], or drop '${name}' from ${label}.`);
|
|
189
|
+
}
|
|
190
|
+
// Length is NOT checked: see the note above mergeListProblems — the
|
|
191
|
+
// platform's 500 bounds MATCHED RECORDS, not items in the list.
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return problems;
|
|
195
|
+
}
|
|
196
|
+
/** mergeListProblems as a guard: throws one combined, actionable Error. */
|
|
197
|
+
export function assertMergeLists(fields, merge = [], unmerge = []) {
|
|
198
|
+
const problems = mergeListProblems(fields, merge, unmerge);
|
|
199
|
+
if (problems.length > 0) {
|
|
200
|
+
throw new Error(`Refused before writing: ${problems.join(" ")}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
131
203
|
/** Python-ish type name for error messages. */
|
|
132
204
|
function typeName(value) {
|
|
133
205
|
if (value === null) {
|
|
@@ -373,8 +445,15 @@ export function buildFileUpload(meta, filePath) {
|
|
|
373
445
|
/**
|
|
374
446
|
* Approval-gate response returned by a mutating tool called without confirm=true.
|
|
375
447
|
* The operation is NOT performed.
|
|
448
|
+
*
|
|
449
|
+
* For a delete the message states the real semantics: the platform's /remove is
|
|
450
|
+
* a SOFT delete (it sets deletedAt), so the row survives and the delete is
|
|
451
|
+
* reversible. Describing it as permanent would be a lie that pushes agents into
|
|
452
|
+
* refusing routine cleanups — the gate is here because the record vanishes from
|
|
453
|
+
* every normal read, not because the data is destroyed.
|
|
376
454
|
*/
|
|
377
455
|
export function confirmRequired(action, target, proposedChanges) {
|
|
456
|
+
const isDelete = action.trim().toLowerCase().startsWith("delete");
|
|
378
457
|
const body = {
|
|
379
458
|
status: "confirmation_required",
|
|
380
459
|
action,
|
|
@@ -382,8 +461,17 @@ export function confirmRequired(action, target, proposedChanges) {
|
|
|
382
461
|
message: `⚠️ APPROVAL REQUIRED before this ${action} — it was NOT performed. ` +
|
|
383
462
|
"Do not proceed on your own: show the target to the user (read the record " +
|
|
384
463
|
"first if it may be important), get explicit approval, then re-call this tool " +
|
|
385
|
-
"with confirm=true."
|
|
464
|
+
"with confirm=true." +
|
|
465
|
+
(isDelete
|
|
466
|
+
? " Semantics: this is a SOFT delete — it sets deletedAt, the row remains " +
|
|
467
|
+
"in the database and the delete is reversible (restore in the Suppa UI; " +
|
|
468
|
+
"this server has no restore tool yet). It is NOT a permanent purge, but " +
|
|
469
|
+
"the record does disappear from every normal read."
|
|
470
|
+
: ""),
|
|
386
471
|
};
|
|
472
|
+
if (isDelete) {
|
|
473
|
+
body.delete_semantics = "soft — sets deletedAt, row remains, reversible";
|
|
474
|
+
}
|
|
387
475
|
if (proposedChanges !== undefined) {
|
|
388
476
|
body.proposed_changes = proposedChanges;
|
|
389
477
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "suppa-mcp": "dist/bin.js" },
|
|
@@ -44,12 +44,15 @@ Confirm all 5 before writing anything:
|
|
|
44
44
|
3. `default` is a SQL expression string — `'false'`, `"'draft'"` — never a JS value; a JS value is rejected at migration time.
|
|
45
45
|
4. Scalars only via `@Column({ type: FieldTypeEnum.X })`; relations/enums/files are NEVER declared via `@Column` — use the `@ManyToOne`/`@ManyToMany`/`@OneToMany`/`@ManyToManyBackRef`/`@Enum`/`@MultiEnum`/`@File`/`@MultiFile` families.
|
|
46
46
|
5. Relation targets are thunks — `() => Target`, never the class itself — or circular imports break.
|
|
47
|
-
6.
|
|
48
|
-
7.
|
|
49
|
-
8.
|
|
50
|
-
9.
|
|
51
|
-
10.
|
|
52
|
-
11.
|
|
47
|
+
6. Do not pass the optional `inverse` selector to `@ManyToOne`/`@ManyToMany` — write `@ManyToOne(() => Target, { … })`. Add one only when the target class declares the paired back-reference and you are deliberately linking the two sides. An `inverse` must select a RELATION property on the target (`(task) => task.project`); `(e) => e.id` is always wrong — `id` is a system column, not a back-reference.
|
|
48
|
+
7. If an option isn't in the reference tables (`references/entities.md`, `references/seeds.md`, `references/registration.md`), it doesn't exist — stop and ask, don't guess.
|
|
49
|
+
8. Every entity class must appear in some `forFeature()`'s `entities` array; every seed in its `seeds` array, dependencies first — `workflowsSeed` before `stageWorkflowsSeed`.
|
|
50
|
+
9. Seeds: every record carries all `importKeyFields` (or `$key`); relations are referenced by the target's import-key object, never a numeric id; no system columns; no `$readAccess`/`$updateAccess`/`$instanceAccess`; no reverse `@OneToMany` field, even as `[]`.
|
|
51
|
+
10. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
|
|
52
|
+
11. Renames need `key` set on `@Entity()`/`@Column()` BEFORE the rename ships — otherwise it's a drop-and-create, not a rename.
|
|
53
|
+
12. `subType` refines `type` and means three unrelated things depending on the base type — `Timestamp` → `'date' | 'time' | 'timestamp'`, `Text` → `'encrypted'`, `Enum`/`MultiEnum` → the enum's global name. Never pass `subType` by hand on an `@Enum`/`@MultiEnum` field: the decorator fills it from its first argument (or derives `<ClassName>.<propertyName>`), and a hand-written one either duplicates that or silently disagrees with the value that resolves `{ value: 'active' }` on insert. Any other `(type, subType)` pair does not exist.
|
|
54
|
+
13. `subType` is **immutable after creation**, with one exception: toggling `'encrypted'` on or off. The Builder API answers `Field subType cannot be changed.` to anything else — so choosing `Timestamp` where you needed `subType: 'date'` is not a conversion you can ship later, it is a NEW field plus a removal of the old one (see `references/registration.md` for what removal leaves behind). Get date-vs-timestamp right the first time. To CLEAR a subtype you must write `subType: null` explicitly — deleting the line does nothing, because an omitted key is dropped from the sync payload and the stored subtype survives.
|
|
55
|
+
14. Repeating rows owned by one parent record are a **tabular part**, never a plain entity: `type: 'tabular-part'` + `relationEntityName` (the parent's `@Entity()` name) + a `@ManyToOne` field named exactly `owner` pointing at the parent class — all three required, the platform infers none of them. Put `owner` FIRST in `importKeyFields` — it scopes the business key to the parent, or rows collide across different parents.
|
|
53
56
|
|
|
54
57
|
## Decorator decision table
|
|
55
58
|
|
|
@@ -57,16 +60,22 @@ Confirm all 5 before writing anything:
|
|
|
57
60
|
|---|---|
|
|
58
61
|
| Repeating rows owned by one parent record (checklist items, order lines, attendees) | **Tabular part** — `type: 'tabular-part'` + `relationEntityName` + a `@ManyToOne` field named `owner` on `@Entity()`; see `templates/tabular-part.template.ts` and `references/tabular-parts.md` |
|
|
59
62
|
| Scalar column (text/numeric/integer/boolean/timestamp/json/uuid/multi-language/bytea/tsvector/multi-type/icon) | `@Column({ type: FieldTypeEnum.<Member> })` |
|
|
63
|
+
| Date-only column (no time part) | `@Column({ type: FieldTypeEnum.Timestamp, subType: 'date' })` — there is **no** `FieldTypeEnum.Date` |
|
|
64
|
+
| Time-only column | `@Column({ type: FieldTypeEnum.Timestamp, subType: 'time' })` — there is **no** `FieldTypeEnum.Time` |
|
|
65
|
+
| Date **and** time | `@Column({ type: FieldTypeEnum.Timestamp })` — omitted `subType` already means `timestamp` |
|
|
66
|
+
| Text encrypted at rest | `@Column({ type: FieldTypeEnum.Text, subType: 'encrypted' })` — Text only; see rule 13 for what it costs |
|
|
60
67
|
| Fixed single-select value set | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
|
|
61
68
|
| Fixed multi-select value set | `@MultiEnum(...)` — same signature as `@Enum` |
|
|
62
|
-
| Foreign key on this entity | `@ManyToOne(
|
|
63
|
-
| Pivot table between two entities | `@ManyToMany(
|
|
64
|
-
| Reverse side of a `@ManyToMany` | `@ManyToManyBackRef(
|
|
65
|
-
| Reverse side of a `@ManyToOne` | `@OneToMany(
|
|
69
|
+
| Foreign key on this entity | `@ManyToOne(() => Target, options?)` — **no inverse** |
|
|
70
|
+
| Pivot table between two entities | `@ManyToMany(() => Target, options?)` — **no inverse** |
|
|
71
|
+
| Reverse side of a `@ManyToMany` | `@ManyToManyBackRef(() => Target, (t) => t.<thisRelationProp>, options?)` |
|
|
72
|
+
| Reverse side of a `@ManyToOne` | `@OneToMany(() => Target, (t) => t.<thisRelationProp>, options?)` |
|
|
66
73
|
| Single attachment | `@File({ title })` |
|
|
67
74
|
| Multiple attachments | `@MultiFile({ title })` |
|
|
68
75
|
|
|
69
|
-
`target` is always a thunk, `() => Target`. `inverse` is
|
|
76
|
+
`target` is always a thunk, `() => Target`. The `inverse` selector is REQUIRED on `@OneToMany`/`@ManyToManyBackRef` and OPTIONAL on `@ManyToOne`/`@ManyToMany` — omit it there by default. When you do write one, it must select the property on the TARGET class that holds the other side of this relation (e.g. `(task) => task.project`) — never `.id`, never a scalar column.
|
|
77
|
+
|
|
78
|
+
**What `subType: 'encrypted'` costs.** The platform forces the column's `unique`, `searchable`, `canFilter`, `canSort` and `canGroup` to `false` and clears `maxLength`, `minLength` and `mask`, whatever you declared — the ciphertext envelope can't satisfy a plaintext constraint or be read by an index. So an encrypted column cannot be searched, filtered, sorted or grouped: if users need any of that, split the field and keep the searchable part in a separate plaintext column. It is also rejected inside a `MultiType` field and on any non-Text type.
|
|
70
79
|
|
|
71
80
|
## Naming conventions
|
|
72
81
|
|
|
@@ -150,6 +159,8 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
|
|
|
150
159
|
|
|
151
160
|
`validate-suppa-schema.mjs` exits `0` on a clean run, `1` when errors are found, `2` on a usage error or a missing path. The gate requires exit `0` — warnings alone do not block.
|
|
152
161
|
|
|
162
|
+
The validator parses with the TypeScript compiler API, read from the app repo you point it at (a Suppa application compiles with `tsc`, so it has one). If it reports `cannot resolve 'typescript'`, run `npm install` in that repo — or `npm i -D typescript` if it genuinely has none.
|
|
163
|
+
|
|
153
164
|
## Troubleshooting
|
|
154
165
|
|
|
155
166
|
| Symptom | Cause | Validator code |
|
|
@@ -161,6 +172,13 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
|
|
|
161
172
|
| Back reference can't insert | A reverse `@OneToMany` field is present in a seed record, possibly as `[]` | E204 |
|
|
162
173
|
| A renamed entity or field appears as a new one | No `key` option was set | W602 |
|
|
163
174
|
| `default` value is rejected | A JavaScript value was passed instead of a SQL expression string | E103 |
|
|
175
|
+
| Generated relation has an inverse selector that fails to typecheck | An `inverse` was passed to `@ManyToOne`/`@ManyToMany`, where it's optional and usually omitted | W609/E111 — drop the selector, write `@ManyToOne(() => Target, { … })` |
|
|
176
|
+
| Migration rejects the column, or a date field ships as a full `timestamp` | The `(type, subType)` pair isn't one the doc allows — `Timestamp` takes `'date'`/`'time'`/`'timestamp'`, `Text` takes `'encrypted'`, nothing else | E112 |
|
|
177
|
+
| `Encrypted subtype is only allowed on text fields` | `subType: 'encrypted'` on a non-Text column | E112 |
|
|
178
|
+
| An enum field resolves to the wrong enum, or its values fail to insert | `subType` was written by hand on `@Enum`/`@MultiEnum` instead of being left to the decorator | E113 |
|
|
179
|
+
| `Field subType cannot be changed.` | A subtype change other than the `'encrypted'` toggle — add a NEW field instead of converting | rule 13, not statically checkable |
|
|
180
|
+
| A removed `subType` line is still in effect | An omitted key is dropped from the sync payload — clear it with `subType: null` | rule 13, not statically checkable |
|
|
181
|
+
| `inverse` points at `id` | `id` is a system column, never a back-reference — an `inverse` must select the RELATION property on the target holding the other side | E111 |
|
|
164
182
|
| A re-added field already contains old data | Same name means the same key, so the soft-deleted field was restored with its column — this is a runtime migration outcome, not statically checkable | documented-only, see references/registration.md |
|
|
165
183
|
| A removed field is still present after a reload | The removal pass was skipped because the system user could not be resolved | documented-only, see references/registration.md |
|
|
166
184
|
| The table has columns such as `title_1730457600000` | Leftovers from removed fields — renaming is how the platform removes a column; nothing cleans them up | documented-only, see references/registration.md |
|
|
@@ -169,5 +187,5 @@ Step 1 exists to catch exactly this: an unregistered class is E301 and the gate
|
|
|
169
187
|
| Duplicate tabular-part rows across different parents | `owner` is missing from `importKeyFields`, so the key is matched globally instead of per-parent | E110 |
|
|
170
188
|
| A tabular part's rows land on/read from the wrong parent | `owner`'s `@ManyToOne` target resolves to an entity whose `@Entity()` name doesn't match `relationEntityName` | E109 |
|
|
171
189
|
| A tabular part's business key isn't scoped to its parent | `owner` is present in `importKeyFields` but not first | W607 |
|
|
172
|
-
| Validator warns W606 | Content delivered via spread or reference — options, `default`, `importKeyFields`, seed records, enum refs, `$key`, autoload paths, registration arrays, tabular-part `type`/`relationEntityName` — is not statically verifiable; the matching check is skipped. Inline it so the validator can check | W606 |
|
|
190
|
+
| Validator warns W606 | Content delivered via spread or reference — options, `default`, `subType`, `importKeyFields`, seed records, enum refs, `$key`, autoload paths, registration arrays, tabular-part `type`/`relationEntityName` — is not statically verifiable; the matching check is skipped. Inline it so the validator can check | W606 |
|
|
173
191
|
| Validator warns W608 | No `tsconfig.json` at the given root, so `experimentalDecorators`/`emitDecoratorMetadata` could not be verified — point the validator at the app root | W608 |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Entity declaration — verbatim rules
|
|
2
2
|
|
|
3
|
-
Transcribed from docs.modern-expo.com/backend/application-developing/migrations.html (captured 2026-08-
|
|
3
|
+
Transcribed from docs.modern-expo.com/backend/application-developing/migrations.html (captured 2026-08-04). If an option is not in these tables, it does not exist — stop and ask.
|
|
4
4
|
|
|
5
5
|
## A Minimal Entity
|
|
6
6
|
|
|
@@ -113,6 +113,7 @@ deadline: string;
|
|
|
113
113
|
| Option | Type | Description |
|
|
114
114
|
|---|---|---|
|
|
115
115
|
| type | FieldTypeEnum | Column type. Take the value from FieldTypeEnum (see below). |
|
|
116
|
+
| subType | string \| null | Refines type — see subType. |
|
|
116
117
|
| name | string | Column name. Defaults to the property name. |
|
|
117
118
|
| nullable | boolean | Allow NULL. |
|
|
118
119
|
| primary | boolean | Mark as primary key. |
|
|
@@ -161,6 +162,91 @@ import { FieldTypeEnum } from '@suppa/sdk';
|
|
|
161
162
|
> **TIP**
|
|
162
163
|
> FieldTypeEnum covers scalar columns only. Relations, enums and files are declared with their own decorators — @ManyToOne, @ManyToMany, @OneToMany, @Enum, @MultiEnum, @File, @MultiFile — and never with @Column({ type: ... }). The SDK also exports RelationTypeEnum with those relation kinds, but you do not pass it manually; each decorator sets it for you.
|
|
163
164
|
|
|
165
|
+
## `subType` — Refining a Column Type
|
|
166
|
+
|
|
167
|
+
`subType` is a second, narrower classification on top of `type`. It is a plain string, and the thing to understand before using it is that **it means three unrelated things depending on the base type**:
|
|
168
|
+
|
|
169
|
+
| Base type | `subType` | Effect |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `Timestamp` | `'date'`, `'time'`, `'timestamp'` | Chooses the physical column type. Omitted means `timestamp`. |
|
|
172
|
+
| `Text` | `'encrypted'` | The value is encrypted at rest. |
|
|
173
|
+
| `Enum`, `MultiEnum` | The global enum name | Identifies which enum the field draws from. Set by the decorator — never by hand. |
|
|
174
|
+
|
|
175
|
+
There is no enum for these values in the SDK. Write the string.
|
|
176
|
+
|
|
177
|
+
### Dates and Times
|
|
178
|
+
|
|
179
|
+
`FieldTypeEnum` has no `Date` or `Time` member. A date-only or time-only column is `Timestamp` plus a `subType`:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
@Column({ name: 'deadline', type: FieldTypeEnum.Timestamp })
|
|
183
|
+
deadline: string; // timestamp
|
|
184
|
+
|
|
185
|
+
@Column({ name: 'birthday', type: FieldTypeEnum.Timestamp, subType: 'date' })
|
|
186
|
+
birthday: string; // date
|
|
187
|
+
|
|
188
|
+
@Column({ name: 'opensAt', type: FieldTypeEnum.Timestamp, subType: 'time' })
|
|
189
|
+
opensAt: string; // time
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The subtype becomes the column type verbatim, so `subType: 'date'` produces a real Postgres `date` column — not a `timestamp` that the UI renders without a time part.
|
|
193
|
+
|
|
194
|
+
### Encrypted Text
|
|
195
|
+
|
|
196
|
+
`subType: 'encrypted'` on a text field stores the value as an AES-GCM envelope (`v1:iv:tag:ct`) instead of plaintext:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
@Column({
|
|
200
|
+
name: 'payload',
|
|
201
|
+
type: FieldTypeEnum.Text,
|
|
202
|
+
subType: 'encrypted',
|
|
203
|
+
nullable: false,
|
|
204
|
+
})
|
|
205
|
+
payload: string;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The platform rejects the combinations that cannot work:
|
|
209
|
+
|
|
210
|
+
| Rule | Error |
|
|
211
|
+
|---|---|
|
|
212
|
+
| Only on a `text` field. | `Encrypted subtype is only allowed on text fields` |
|
|
213
|
+
| Not inside a multi-type field, and not as one of its sub-fields. | `Encrypted subtype is not allowed inside a multi-type field` |
|
|
214
|
+
|
|
215
|
+
It also forces off everything that would need to read the plaintext, whatever you declared:
|
|
216
|
+
|
|
217
|
+
- `unique` becomes `false`;
|
|
218
|
+
- the `searchable`, `canFilter`, `canSort` and `canGroup` options become `false`;
|
|
219
|
+
- `maxLength`, `minLength` and `mask` are cleared — the envelope never matches a plaintext length or mask constraint, so those `CHECK`s are dropped.
|
|
220
|
+
|
|
221
|
+
Turning encryption on for an existing field encrypts the rows already in the table; turning it off decrypts them. A row that fails to decrypt aborts the backfill rather than overwriting ciphertext with a marker.
|
|
222
|
+
|
|
223
|
+
> **TIP**
|
|
224
|
+
> Plan for the lost capabilities before encrypting a field. An encrypted column cannot be searched, filtered, sorted, or grouped — if users need any of that, keep the searchable part in a separate plaintext field.
|
|
225
|
+
|
|
226
|
+
### Enums Set It For You
|
|
227
|
+
|
|
228
|
+
For an enum field, `subType` holds the enum's **global name** — the value that lets the platform resolve `{ value: 'active' }` to the right enum record on insert. `@Enum()` and `@MultiEnum()` fill it from their first argument:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
@Enum('StageWorkflows.status', StageStatusEnum, StageStatus, { nullable: false })
|
|
232
|
+
status: StageStatusEnum; // subType = 'StageWorkflows.status'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Called without an explicit global name, the SDK derives `<ClassName>.<propertyName>`. Either way, do not pass `subType` yourself on an enum field.
|
|
236
|
+
|
|
237
|
+
### Changing a Subtype
|
|
238
|
+
|
|
239
|
+
Through the Builder API a subtype change is rejected outright:
|
|
240
|
+
|
|
241
|
+
```txt
|
|
242
|
+
Field subType cannot be changed.
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The one permitted transition is the encryption toggle — setting `'encrypted'`, or clearing it. Treat the date/time choice as **fixed at creation**: if a field was created as `timestamp` and should have been `date`, add a new field rather than trying to convert it, since the physical column type would have to change under existing data. See Removing and Re-Adding a Field for what happens to the old one.
|
|
246
|
+
|
|
247
|
+
> **WARNING**
|
|
248
|
+
> To clear a subtype, write `subType: null` explicitly. Deleting the line does nothing — an omitted key is dropped from the sync payload, so the stored subtype stays as it was.
|
|
249
|
+
|
|
164
250
|
## Relations
|
|
165
251
|
|
|
166
252
|
Relation decorators take a thunk returning the target class — `() => Workflows` — which keeps circular imports working:
|
|
@@ -10,7 +10,7 @@ The API migration path and this code path share one authority: `classifyV1Field(
|
|
|
10
10
|
| `numeric` | `@Column({ type: FieldTypeEnum.Numeric })` |
|
|
11
11
|
| `integer` | `@Column({ type: FieldTypeEnum.Integer })` |
|
|
12
12
|
| `boolean` | `@Column({ type: FieldTypeEnum.Boolean })` |
|
|
13
|
-
| `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` |
|
|
13
|
+
| `timestamp` | `@Column({ type: FieldTypeEnum.Timestamp })` — plus `subType: 'date'` when `classifyV1Field` returns `v2SubType: 'date'` (see below) |
|
|
14
14
|
| `json` | `@Column({ type: FieldTypeEnum.JSON })` |
|
|
15
15
|
| `uuid` | `@Column({ type: FieldTypeEnum.UUID })` |
|
|
16
16
|
| `multi-language` | `@Column({ type: FieldTypeEnum.MultiLang })` |
|
|
@@ -30,9 +30,19 @@ The API migration path and this code path share one authority: `classifyV1Field(
|
|
|
30
30
|
|
|
31
31
|
If `classifyV1Field` returns `kind = 'skip'` — a system/structural field, an unsupported relation sub_type, or an unrecognized v1 type — the field must still appear in the generated class as a `// SKIPPED: <field> — <reason>` comment, using the classifier's own note as `<reason>`. Omitting it is not an option: the generated code must account for every v1 field, migrated or not.
|
|
32
32
|
|
|
33
|
+
## `v2SubType` — date-only v1 fields
|
|
34
|
+
|
|
35
|
+
`classifyV1Field` returns `v2SubType: 'date'` for a v1 date-only field. That maps to a documented option: `FieldTypeEnum.Timestamp` + `subType: 'date'`, which the platform turns into a real Postgres `date` column.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
@Column({ name: 'birthday', type: FieldTypeEnum.Timestamp, subType: 'date' })
|
|
39
|
+
birthday: string;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Get it right the first time: `subType` is immutable after creation except for the `'encrypted'` toggle, so a field created as plain `timestamp` cannot later be converted to `date` — it has to be replaced by a new field. Never emit `subType` on an `@Enum`/`@MultiEnum` field; the decorator writes it.
|
|
43
|
+
|
|
33
44
|
## Documented open edges
|
|
34
45
|
|
|
35
|
-
- `v2SubType: 'date'` (date-only v1 fields): `@Column()` has no documented `subType` option — emit `FieldTypeEnum.Timestamp` plus `// TODO: date-only in v1 — @Column has no documented date subtype; confirm rendering`.
|
|
36
46
|
- Icon duality: default scalar `FieldTypeEnum.Icon`; relation form only if v1 reports `type: relation` targeting icons.
|
|
37
47
|
- Lossy mappings carry the classifier's note as a trailing comment, e.g. `// v1 html_text → text (2.0 has no rich-text type)`.
|
|
38
48
|
|