suppa-mcp-2 1.2.3 → 1.3.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/README.md +419 -391
- package/dist/bin.js +1 -1
- package/dist/httpClient.js +230 -5
- package/dist/server.js +590 -82
- package/dist/tools/docs.js +12 -3
- package/dist/tools/entity.js +1275 -94
- package/dist/tools/migrate.js +84 -6
- package/dist/tools/tasks.js +12 -2
- package/dist/utils.js +202 -1
- package/package.json +13 -4
- package/skills/suppa-entity-code/SKILL.md +15 -2
- 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 +73 -3
- package/skills/suppa-entity-code/templates/entity.template.ts +13 -0
package/dist/tools/migrate.js
CHANGED
|
@@ -604,6 +604,15 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
604
604
|
title: ftitle,
|
|
605
605
|
type: cls.v2Type,
|
|
606
606
|
required,
|
|
607
|
+
// Builder Field Options (builder.txt:60, keys :66-73). Null = "send none",
|
|
608
|
+
// which is what 1.0 tells us: it has no equivalent metadata, so nothing is
|
|
609
|
+
// invented here. The key exists so an EDITED plan can carry them —
|
|
610
|
+
// {"searchable": true, "showInTable": true} — and _execute forwards it.
|
|
611
|
+
options: null,
|
|
612
|
+
// The v1 default must travel with the planned field: _requiredOpts reads
|
|
613
|
+
// `default_value` off the PLAN, so a plan that omits it downgrades every
|
|
614
|
+
// required field to nullable and the notNull path is never taken.
|
|
615
|
+
default_value: p.default_value ?? null,
|
|
607
616
|
relation_entity: v2Target ?? (target ? normalizeEntityName(target) : null),
|
|
608
617
|
target_in_set: inSet,
|
|
609
618
|
};
|
|
@@ -630,8 +639,10 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
630
639
|
title: ftitle,
|
|
631
640
|
type: cls.v2Type,
|
|
632
641
|
required,
|
|
642
|
+
default_value: p.default_value ?? null,
|
|
633
643
|
enum_name: _enumNameFor(v2EntName, v2Fname),
|
|
634
644
|
values,
|
|
645
|
+
options: null, // see relation_fields above — builder.txt:60 / :66-73
|
|
635
646
|
});
|
|
636
647
|
continue;
|
|
637
648
|
}
|
|
@@ -642,10 +653,12 @@ async function _planFields(props, entName, v2EntName, targetResolver, entIndex,
|
|
|
642
653
|
title: ftitle,
|
|
643
654
|
type: cls.v2Type,
|
|
644
655
|
required,
|
|
656
|
+
default_value: p.default_value ?? null,
|
|
645
657
|
sub_type: cls.v2SubType,
|
|
646
658
|
max_length: cls.v2Type === "text" ? maxLength : null,
|
|
647
659
|
decimal_places: cls.v2Type === "numeric" ? decimalPlaces : null,
|
|
648
660
|
multilingual: cls.multilingual,
|
|
661
|
+
options: null, // see relation_fields above — builder.txt:60 / :66-73
|
|
649
662
|
};
|
|
650
663
|
if (cls.note) {
|
|
651
664
|
field.note = cls.note;
|
|
@@ -988,6 +1001,62 @@ async function _runWrite(action, fn) {
|
|
|
988
1001
|
}
|
|
989
1002
|
return { action, status: "created", result: parsed };
|
|
990
1003
|
}
|
|
1004
|
+
// Types the 2.0 builder marks notNull WITHOUT a defaultValue: the doc's
|
|
1005
|
+
// "Relation types" group, whose values live in a join/side table
|
|
1006
|
+
// (docs/superpowers/specs/captures/api-entity-builder-builder.txt:43 —
|
|
1007
|
+
// "defaultValue ... Not applicable to relations, enums, or unique fields";
|
|
1008
|
+
// :63 lists the group). Mirrors NO_DEFAULT_VALUE_FIELD_TYPES in tools/entity.ts,
|
|
1009
|
+
// kept local so the migrator decides before the write instead of learning from a
|
|
1010
|
+
// failed one — entity.js is module-mocked in the migrator's tests.
|
|
1011
|
+
const _NO_DEFAULT_VALUE_TYPES = new Set([
|
|
1012
|
+
"many-to-one",
|
|
1013
|
+
"one-to-many",
|
|
1014
|
+
"many-to-many",
|
|
1015
|
+
"many-to-many-backref",
|
|
1016
|
+
"enum",
|
|
1017
|
+
"multi-enum",
|
|
1018
|
+
"file",
|
|
1019
|
+
"multi-file",
|
|
1020
|
+
]);
|
|
1021
|
+
const _DOWNGRADE_NOTE = "Some fields that are required in Suppa 1.0 were created NULLABLE here: the 2.0 " +
|
|
1022
|
+
"builder refuses NOT NULL without a defaultValue, and this migrator will not " +
|
|
1023
|
+
"invent one — the value empty rows should carry is a data decision, not a " +
|
|
1024
|
+
"migration detail. See required_downgrades. To restore the constraint: add " +
|
|
1025
|
+
'"default_value" to those fields in the plan (a SQL expression or literal, e.g. ' +
|
|
1026
|
+
"\"0\", \"'draft'\", \"now()\") and re-run in gap-fill mode after dropping the " +
|
|
1027
|
+
"field, or set NOT NULL in the builder UI once the column is backfilled.";
|
|
1028
|
+
/**
|
|
1029
|
+
* Resolve the required/defaultValue options for one planned field.
|
|
1030
|
+
*
|
|
1031
|
+
* A v1 field that is required but has no default cannot be created NOT NULL, and
|
|
1032
|
+
* that must NOT abort the migration: the field is created nullable and the
|
|
1033
|
+
* downgrade is recorded so the user can restore the constraint deliberately.
|
|
1034
|
+
*/
|
|
1035
|
+
function _requiredOpts(entity, f, downgrades) {
|
|
1036
|
+
if (!(f.required ?? false)) {
|
|
1037
|
+
return { required: false };
|
|
1038
|
+
}
|
|
1039
|
+
if (_NO_DEFAULT_VALUE_TYPES.has(String(f.type ?? ""))) {
|
|
1040
|
+
return { required: true }; // defaultValue does not apply — notNull needs none
|
|
1041
|
+
}
|
|
1042
|
+
// `default_value` is put on every planned field by _planFields (from the v1
|
|
1043
|
+
// property); a plan built elsewhere that omits it downgrades, it never guesses.
|
|
1044
|
+
const raw = f.default_value;
|
|
1045
|
+
const defaultValue = raw === null || raw === undefined ? "" : String(raw).trim();
|
|
1046
|
+
if (defaultValue !== "") {
|
|
1047
|
+
return { required: true, defaultValue };
|
|
1048
|
+
}
|
|
1049
|
+
downgrades.push({
|
|
1050
|
+
entity,
|
|
1051
|
+
field: f.name,
|
|
1052
|
+
type: f.type ?? null,
|
|
1053
|
+
v1_required: true,
|
|
1054
|
+
created_as: "nullable",
|
|
1055
|
+
reason: "required in v1 but the plan carries no default_value; the 2.0 builder refuses " +
|
|
1056
|
+
"NOT NULL without one and no default is invented here",
|
|
1057
|
+
});
|
|
1058
|
+
return { required: false };
|
|
1059
|
+
}
|
|
991
1060
|
/**
|
|
992
1061
|
* Apply the plan to the active Suppa 2.0 tenant, idempotently. Two-pass for relations.
|
|
993
1062
|
*
|
|
@@ -998,6 +1067,7 @@ async function _runWrite(action, fn) {
|
|
|
998
1067
|
*/
|
|
999
1068
|
export async function _execute(plan, mode = "create") {
|
|
1000
1069
|
const details = [];
|
|
1070
|
+
const requiredDowngrades = [];
|
|
1001
1071
|
const existingEntities = await _liveEntityNames();
|
|
1002
1072
|
// Pass 1: entities + scalar + enum fields.
|
|
1003
1073
|
for (const ent of plan.entities) {
|
|
@@ -1030,10 +1100,11 @@ export async function _execute(plan, mode = "create") {
|
|
|
1030
1100
|
continue;
|
|
1031
1101
|
}
|
|
1032
1102
|
const step = await _runWrite(`add_field:${f.name}`, () => entityTools.addField(name, f.name, f.type, f.title, {
|
|
1033
|
-
|
|
1103
|
+
..._requiredOpts(name, f, requiredDowngrades),
|
|
1034
1104
|
subType: f.sub_type ?? null,
|
|
1035
1105
|
maxLength: f.max_length ?? null,
|
|
1036
1106
|
decimalPlaces: f.decimal_places ?? null,
|
|
1107
|
+
options: f.options ?? null, // builder.txt:60 — plan-carried Field Options
|
|
1037
1108
|
}));
|
|
1038
1109
|
step.entity = name;
|
|
1039
1110
|
details.push(step);
|
|
@@ -1057,8 +1128,9 @@ export async function _execute(plan, mode = "create") {
|
|
|
1057
1128
|
}
|
|
1058
1129
|
}
|
|
1059
1130
|
const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(name, f.name, f.type ?? "enum", f.title, {
|
|
1060
|
-
|
|
1131
|
+
..._requiredOpts(name, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
|
|
1061
1132
|
enumName: f.enum_name,
|
|
1133
|
+
options: f.options ?? null, // builder.txt:60
|
|
1062
1134
|
}));
|
|
1063
1135
|
step.entity = name;
|
|
1064
1136
|
details.push(step);
|
|
@@ -1081,10 +1153,11 @@ export async function _execute(plan, mode = "create") {
|
|
|
1081
1153
|
continue;
|
|
1082
1154
|
}
|
|
1083
1155
|
const step = await _runWrite(`add_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type, f.title, {
|
|
1084
|
-
|
|
1156
|
+
..._requiredOpts(tpName, f, requiredDowngrades),
|
|
1085
1157
|
subType: f.sub_type ?? null,
|
|
1086
1158
|
maxLength: f.max_length ?? null,
|
|
1087
1159
|
decimalPlaces: f.decimal_places ?? null,
|
|
1160
|
+
options: f.options ?? null, // builder.txt:60
|
|
1088
1161
|
}));
|
|
1089
1162
|
step.entity = tpName;
|
|
1090
1163
|
details.push(step);
|
|
@@ -1103,8 +1176,9 @@ export async function _execute(plan, mode = "create") {
|
|
|
1103
1176
|
}
|
|
1104
1177
|
}
|
|
1105
1178
|
const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type ?? "enum", f.title, {
|
|
1106
|
-
|
|
1179
|
+
..._requiredOpts(tpName, { ...f, type: f.type ?? "enum" }, requiredDowngrades),
|
|
1107
1180
|
enumName: f.enum_name,
|
|
1181
|
+
options: f.options ?? null, // builder.txt:60
|
|
1108
1182
|
}));
|
|
1109
1183
|
step.entity = tpName;
|
|
1110
1184
|
details.push(step);
|
|
@@ -1147,8 +1221,9 @@ export async function _execute(plan, mode = "create") {
|
|
|
1147
1221
|
continue;
|
|
1148
1222
|
}
|
|
1149
1223
|
const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(name, f.name, f.type, f.title, {
|
|
1150
|
-
|
|
1224
|
+
..._requiredOpts(name, f, requiredDowngrades),
|
|
1151
1225
|
relationEntity: f.relation_entity,
|
|
1226
|
+
options: f.options ?? null, // builder.txt:60
|
|
1152
1227
|
}));
|
|
1153
1228
|
step.entity = name;
|
|
1154
1229
|
details.push(step);
|
|
@@ -1185,8 +1260,9 @@ export async function _execute(plan, mode = "create") {
|
|
|
1185
1260
|
continue;
|
|
1186
1261
|
}
|
|
1187
1262
|
const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(tp.name, f.name, f.type, f.title, {
|
|
1188
|
-
|
|
1263
|
+
..._requiredOpts(tp.name, f, requiredDowngrades),
|
|
1189
1264
|
relationEntity: f.relation_entity,
|
|
1265
|
+
options: f.options ?? null, // builder.txt:60
|
|
1190
1266
|
}));
|
|
1191
1267
|
step.entity = tp.name;
|
|
1192
1268
|
details.push(step);
|
|
@@ -1221,6 +1297,8 @@ export async function _execute(plan, mode = "create") {
|
|
|
1221
1297
|
executed: true,
|
|
1222
1298
|
mode,
|
|
1223
1299
|
summary: _summarize(details),
|
|
1300
|
+
required_downgrades: requiredDowngrades,
|
|
1301
|
+
notes: requiredDowngrades.length > 0 ? [_DOWNGRADE_NOTE] : [],
|
|
1224
1302
|
verify,
|
|
1225
1303
|
details,
|
|
1226
1304
|
};
|
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
|
@@ -9,6 +9,117 @@ import { extname, basename } from "node:path";
|
|
|
9
9
|
export function makeFilter(field, value, comparator = "=") {
|
|
10
10
|
return { field, value, comparator };
|
|
11
11
|
}
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Conditions: flat filters AND nested groups
|
|
14
|
+
//
|
|
15
|
+
// Shared objects, captures/api-entity-builder-data.txt:33-42 —
|
|
16
|
+
// Condition: operator (string, required, "and or or", :35)
|
|
17
|
+
// filters (object[], required, "Filters, or NESTED CONDITION
|
|
18
|
+
// OBJECTS", :36)
|
|
19
|
+
// Filter: field (string, required, "Field path, e.g. owner.id", :39)
|
|
20
|
+
// comparator (string, required, :40)
|
|
21
|
+
// value (any, required, :41)
|
|
22
|
+
// function (string, optional, "Field function", :42)
|
|
23
|
+
//
|
|
24
|
+
// Because a Condition's `filters` may hold Conditions, an expression like
|
|
25
|
+
// (status=open AND owner=me) OR priority=high is one payload:
|
|
26
|
+
// {"operator": "or", "filters": [
|
|
27
|
+
// {"operator": "and", "filters": [
|
|
28
|
+
// {"field": "status.value", "value": "open", "comparator": "="},
|
|
29
|
+
// {"field": "owner.id", "value": "$current-user", "comparator": "="}]},
|
|
30
|
+
// {"field": "priority.value", "value": "high", "comparator": "="}]}
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/** data.txt:35 — the only two condition operators. */
|
|
33
|
+
export const CONDITION_OPERATORS = ["and", "or"];
|
|
34
|
+
/** Comparators that stand alone — the platform ignores any value sent with them. */
|
|
35
|
+
const VALUELESS_COMPARATORS = new Set(["is null", "is not null", "isnull", "isnotnull"]);
|
|
36
|
+
/** Build a nested condition group (data.txt:33-36). */
|
|
37
|
+
export function makeCondition(operator, nodes) {
|
|
38
|
+
return normalizeConditionNode({ operator, filters: nodes }, "condition");
|
|
39
|
+
}
|
|
40
|
+
/** True for a node that is a group rather than a leaf filter. */
|
|
41
|
+
export function isConditionNode(node) {
|
|
42
|
+
return (node !== null &&
|
|
43
|
+
typeof node === "object" &&
|
|
44
|
+
!Array.isArray(node) &&
|
|
45
|
+
"operator" in node);
|
|
46
|
+
}
|
|
47
|
+
function isPlainObj(v) {
|
|
48
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate + normalize ONE node: either a flat filter or a nested condition
|
|
52
|
+
* group. Flat "f=v" filters (what makeFilter produces, used across the tasks /
|
|
53
|
+
* docs / forms tools) pass through with their keys unchanged — this only adds
|
|
54
|
+
* the nested case and refuses shapes the platform would silently mis-read.
|
|
55
|
+
*
|
|
56
|
+
* Accepts the documented group shape {"operator": "or", "filters": [...]} and
|
|
57
|
+
* the shorthand {"or": [...]} / {"and": [...]}, which normalizes to it.
|
|
58
|
+
*/
|
|
59
|
+
export function normalizeConditionNode(node, path = "filters_json") {
|
|
60
|
+
if (!isPlainObj(node)) {
|
|
61
|
+
throw new Error(`${path} must be a filter object {"field", "value", "comparator"} or a ` +
|
|
62
|
+
`condition group {"operator": "and"|"or", "filters": [...]} — got ${typeName(node)}.`);
|
|
63
|
+
}
|
|
64
|
+
// Shorthand: {"or": [...]} / {"and": [...]}.
|
|
65
|
+
for (const op of CONDITION_OPERATORS) {
|
|
66
|
+
if (op in node && !("operator" in node)) {
|
|
67
|
+
return normalizeConditionNode({ operator: op, filters: node[op] }, path);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if ("operator" in node || "filters" in node) {
|
|
71
|
+
const rawOp = node.operator;
|
|
72
|
+
const operator = typeof rawOp === "string" ? rawOp.trim().toLowerCase() : "";
|
|
73
|
+
if (!CONDITION_OPERATORS.includes(operator)) {
|
|
74
|
+
throw new Error(`${path}: a condition group needs "operator": "and" or "or" ` +
|
|
75
|
+
`(data.txt:35) — got ${JSON.stringify(rawOp ?? null)}.`);
|
|
76
|
+
}
|
|
77
|
+
const rawFilters = node.filters;
|
|
78
|
+
if (!Array.isArray(rawFilters)) {
|
|
79
|
+
throw new Error(`${path}: a condition group needs "filters": [...] — an array of filters ` +
|
|
80
|
+
"or nested groups (data.txt:36).");
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
operator: operator,
|
|
84
|
+
filters: rawFilters.map((child, i) => normalizeConditionNode(child, `${path}[${i}]`)),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Leaf filter.
|
|
88
|
+
const field = node.field;
|
|
89
|
+
if (typeof field !== "string" || !field.trim()) {
|
|
90
|
+
throw new Error(`${path}: a filter needs "field" — a field name or dotted path such as ` +
|
|
91
|
+
'"owner.id" (data.txt:39). Nested groups instead need "operator" + "filters".');
|
|
92
|
+
}
|
|
93
|
+
const rawCmp = node.comparator;
|
|
94
|
+
if (rawCmp !== undefined && rawCmp !== null && typeof rawCmp !== "string") {
|
|
95
|
+
throw new Error(`${path}: "comparator" must be a string (data.txt:40).`);
|
|
96
|
+
}
|
|
97
|
+
const comparator = (rawCmp ?? "=").trim() || "=";
|
|
98
|
+
if (!("value" in node) && !VALUELESS_COMPARATORS.has(comparator.toLowerCase())) {
|
|
99
|
+
throw new Error(`${path}: a filter needs "value" (data.txt:41) — only 'is null' / ` +
|
|
100
|
+
"'is not null' may omit it.");
|
|
101
|
+
}
|
|
102
|
+
const out = {
|
|
103
|
+
field: field.trim(),
|
|
104
|
+
value: "value" in node ? node.value : null,
|
|
105
|
+
comparator,
|
|
106
|
+
};
|
|
107
|
+
if (typeof node.function === "string" && node.function.trim()) {
|
|
108
|
+
out.function = node.function.trim(); // data.txt:42 — optional field function
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Normalize a list of filters/groups (the `filters` of the top-level Condition).
|
|
114
|
+
* A single object is tolerated as a one-element list, as before.
|
|
115
|
+
*/
|
|
116
|
+
export function normalizeConditionNodes(nodes, path = "filters_json") {
|
|
117
|
+
if (nodes === null || nodes === undefined) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
const list = Array.isArray(nodes) ? nodes : [nodes];
|
|
121
|
+
return list.map((n, i) => normalizeConditionNode(n, `${path}[${i}]`));
|
|
122
|
+
}
|
|
12
123
|
/**
|
|
13
124
|
* Parse human-friendly deadline strings into ISO datetime.
|
|
14
125
|
*
|
|
@@ -128,6 +239,78 @@ function matchesExpectation(value, expect) {
|
|
|
128
239
|
// "any" -> object or array (Python default expect=(dict, list))
|
|
129
240
|
return isArray || isPlainObject;
|
|
130
241
|
}
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
// merge / unmerge pre-flight
|
|
244
|
+
// ---------------------------------------------------------------------------
|
|
245
|
+
/**
|
|
246
|
+
* NO client-side cap on list length lives here, deliberately. The platform's
|
|
247
|
+
* documented 500 is a bound on RECORDS MATCHED, not on items sent:
|
|
248
|
+
* docs/superpowers/specs/captures/api-entity-builder-data.txt:396 — "The platform
|
|
249
|
+
* reads the current values before writing, so the operation is bounded: matching
|
|
250
|
+
* more than 500 records fails with Cannot perform 'merge'/'unmerge': update query
|
|
251
|
+
* returned maximum allowed records; limit is 500." That depends on the update's
|
|
252
|
+
* conditions, which this pure check never sees (and suppa_update_record targets a
|
|
253
|
+
* single record by id, so it cannot hit it). Refusing a long list here would have
|
|
254
|
+
* been this server inventing a rule the platform does not have.
|
|
255
|
+
*/
|
|
256
|
+
/**
|
|
257
|
+
* Check the `merge` / `unmerge` lists of an update against the fields being
|
|
258
|
+
* sent, BEFORE any request goes out.
|
|
259
|
+
*
|
|
260
|
+
* An update REPLACES a list-valued field; `merge` (add the listed items) and
|
|
261
|
+
* `unmerge` (remove them) opt out of that per field name. A name the platform
|
|
262
|
+
* cannot line up with a list in `fields` is not an error there — it is silently
|
|
263
|
+
* ignored, i.e. the list gets replaced anyway and the caller is told the update
|
|
264
|
+
* succeeded. That is exactly the data loss this guard exists to prevent, so we
|
|
265
|
+
* refuse instead.
|
|
266
|
+
*
|
|
267
|
+
* Pure. Returns one message per problem; an empty array means "safe to send".
|
|
268
|
+
*/
|
|
269
|
+
export function mergeListProblems(fields, merge = [], unmerge = []) {
|
|
270
|
+
const problems = [];
|
|
271
|
+
const both = merge.filter((n) => unmerge.includes(n));
|
|
272
|
+
for (const name of [...new Set(both)]) {
|
|
273
|
+
problems.push(`'${name}' appears in both merge and unmerge — one update cannot add and ` +
|
|
274
|
+
"remove the same field. Send two updates, or drop it from one list.");
|
|
275
|
+
}
|
|
276
|
+
const seen = new Set();
|
|
277
|
+
for (const [list, label] of [
|
|
278
|
+
[merge, "merge"],
|
|
279
|
+
[unmerge, "unmerge"],
|
|
280
|
+
]) {
|
|
281
|
+
for (const name of list) {
|
|
282
|
+
const key = `${label}:${name}`;
|
|
283
|
+
if (seen.has(key) || both.includes(name)) {
|
|
284
|
+
continue; // already reported
|
|
285
|
+
}
|
|
286
|
+
seen.add(key);
|
|
287
|
+
if (!Object.prototype.hasOwnProperty.call(fields, name)) {
|
|
288
|
+
problems.push(`'${name}' is listed in ${label} but is not in the fields being sent — ` +
|
|
289
|
+
`${label} only applies to a field you also write. Add "${name}": ` +
|
|
290
|
+
`[{"id": N}, ...] to fields_json, or drop '${name}' from ${label}.`);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
// data.txt:394 — "Every field named in merge / unmerge must hold an array in
|
|
294
|
+
// fields, otherwise the request fails with Field <name> is not an array."
|
|
295
|
+
const value = fields[name];
|
|
296
|
+
if (!Array.isArray(value)) {
|
|
297
|
+
problems.push(`'${name}' is listed in ${label} but its value is not an array (got ` +
|
|
298
|
+
`${typeName(value)}) — ${label} only applies to list-valued fields. ` +
|
|
299
|
+
`Send "${name}": [{"id": N}, ...], or drop '${name}' from ${label}.`);
|
|
300
|
+
}
|
|
301
|
+
// Length is NOT checked: see the note above mergeListProblems — the
|
|
302
|
+
// platform's 500 bounds MATCHED RECORDS, not items in the list.
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return problems;
|
|
306
|
+
}
|
|
307
|
+
/** mergeListProblems as a guard: throws one combined, actionable Error. */
|
|
308
|
+
export function assertMergeLists(fields, merge = [], unmerge = []) {
|
|
309
|
+
const problems = mergeListProblems(fields, merge, unmerge);
|
|
310
|
+
if (problems.length > 0) {
|
|
311
|
+
throw new Error(`Refused before writing: ${problems.join(" ")}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
131
314
|
/** Python-ish type name for error messages. */
|
|
132
315
|
function typeName(value) {
|
|
133
316
|
if (value === null) {
|
|
@@ -373,8 +556,15 @@ export function buildFileUpload(meta, filePath) {
|
|
|
373
556
|
/**
|
|
374
557
|
* Approval-gate response returned by a mutating tool called without confirm=true.
|
|
375
558
|
* The operation is NOT performed.
|
|
559
|
+
*
|
|
560
|
+
* For a delete the message states the real semantics: the platform's /remove is
|
|
561
|
+
* a SOFT delete (it sets deletedAt), so the row survives and the delete is
|
|
562
|
+
* reversible. Describing it as permanent would be a lie that pushes agents into
|
|
563
|
+
* refusing routine cleanups — the gate is here because the record vanishes from
|
|
564
|
+
* every normal read, not because the data is destroyed.
|
|
376
565
|
*/
|
|
377
566
|
export function confirmRequired(action, target, proposedChanges) {
|
|
567
|
+
const isDelete = action.trim().toLowerCase().startsWith("delete");
|
|
378
568
|
const body = {
|
|
379
569
|
status: "confirmation_required",
|
|
380
570
|
action,
|
|
@@ -382,8 +572,19 @@ export function confirmRequired(action, target, proposedChanges) {
|
|
|
382
572
|
message: `⚠️ APPROVAL REQUIRED before this ${action} — it was NOT performed. ` +
|
|
383
573
|
"Do not proceed on your own: show the target to the user (read the record " +
|
|
384
574
|
"first if it may be important), get explicit approval, then re-call this tool " +
|
|
385
|
-
"with confirm=true."
|
|
575
|
+
"with confirm=true." +
|
|
576
|
+
(isDelete
|
|
577
|
+
? " Semantics: this is a SOFT delete — it sets deletedAt, the row remains " +
|
|
578
|
+
"in the database and the delete is reversible with suppa_restore_record " +
|
|
579
|
+
"(find the row again with deleted_scope='deleted'). It is NOT the platform's " +
|
|
580
|
+
"permanent delete, which this server does not expose, but the record does " +
|
|
581
|
+
"disappear from every normal read."
|
|
582
|
+
: ""),
|
|
386
583
|
};
|
|
584
|
+
if (isDelete) {
|
|
585
|
+
body.delete_semantics =
|
|
586
|
+
"soft — sets deletedAt, row remains, reversible via suppa_restore_record";
|
|
587
|
+
}
|
|
387
588
|
if (proposedChanges !== undefined) {
|
|
388
589
|
body.proposed_changes = proposedChanges;
|
|
389
590
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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
|
-
"bin": {
|
|
6
|
+
"bin": {
|
|
7
|
+
"suppa-mcp": "dist/bin.js"
|
|
8
|
+
},
|
|
7
9
|
"main": "dist/bin.js",
|
|
8
|
-
"files": [
|
|
9
|
-
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"skills",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
10
19
|
"scripts": {
|
|
11
20
|
"build": "tsc",
|
|
12
21
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
@@ -50,7 +50,9 @@ Confirm all 5 before writing anything:
|
|
|
50
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
51
|
10. Autoload paths (`entitiesPath`/`seedsPath`) point at `dist/`, never `src/` — autoloading reads compiled output.
|
|
52
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.
|
|
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.
|
|
54
56
|
|
|
55
57
|
## Decorator decision table
|
|
56
58
|
|
|
@@ -58,6 +60,10 @@ Confirm all 5 before writing anything:
|
|
|
58
60
|
|---|---|
|
|
59
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` |
|
|
60
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 |
|
|
61
67
|
| Fixed single-select value set | `@Enum('<Entity>.<field>', <Field>Enum, <Field>Titles?, options?)` |
|
|
62
68
|
| Fixed multi-select value set | `@MultiEnum(...)` — same signature as `@Enum` |
|
|
63
69
|
| Foreign key on this entity | `@ManyToOne(() => Target, options?)` — **no inverse** |
|
|
@@ -69,6 +75,8 @@ Confirm all 5 before writing anything:
|
|
|
69
75
|
|
|
70
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.
|
|
71
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.
|
|
79
|
+
|
|
72
80
|
## Naming conventions
|
|
73
81
|
|
|
74
82
|
| Thing | Convention | Example |
|
|
@@ -165,6 +173,11 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
165
173
|
| A renamed entity or field appears as a new one | No `key` option was set | W602 |
|
|
166
174
|
| `default` value is rejected | A JavaScript value was passed instead of a SQL expression string | E103 |
|
|
167
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 |
|
|
168
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 |
|
|
169
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 |
|
|
170
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 |
|
|
@@ -174,5 +187,5 @@ The validator parses with the TypeScript compiler API, read from the app repo yo
|
|
|
174
187
|
| Duplicate tabular-part rows across different parents | `owner` is missing from `importKeyFields`, so the key is matched globally instead of per-parent | E110 |
|
|
175
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 |
|
|
176
189
|
| A tabular part's business key isn't scoped to its parent | `owner` is present in `importKeyFields` but not first | W607 |
|
|
177
|
-
| 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 |
|
|
178
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:
|