suppa-mcp-2 1.1.3 → 1.1.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/dist/server.js +1 -1
- package/dist/tools/migrate.js +317 -139
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -199,7 +199,7 @@ export function buildServer() {
|
|
|
199
199
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
200
200
|
TOOL_NAMES.length = 0;
|
|
201
201
|
PROMPT_NAMES.length = 0;
|
|
202
|
-
const server = new McpServer({ name: "suppa-2.0", version: "1.1.
|
|
202
|
+
const server = new McpServer({ name: "suppa-2.0", version: "1.1.4" }, { instructions: INSTRUCTIONS });
|
|
203
203
|
const reg = (name, cfg, handler) => {
|
|
204
204
|
server.registerTool(name, {
|
|
205
205
|
description: cfg.description,
|
package/dist/tools/migrate.js
CHANGED
|
@@ -343,19 +343,21 @@ export async function readV1EntityProps(entity, expand = true, resolveEnums = tr
|
|
|
343
343
|
multiple: p.multiple === true,
|
|
344
344
|
sub_type: p.sub_type,
|
|
345
345
|
});
|
|
346
|
-
// A tabular part ("Табличні частини") is
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
346
|
+
// A tabular part ("Табличні частини") is an OWNED child: the target entity
|
|
347
|
+
// carries an `owner` relation pointing back to THIS entity. (Multi-valued
|
|
348
|
+
// many-to-many fields like `skills`/`vacancies` are shared lookups, NOT
|
|
349
|
+
// child tables — `multiple` is not the marker.) Only owned children are
|
|
350
|
+
// expanded, with the platform-managed owner field(s) hidden.
|
|
351
|
+
if (target && !isSelf && !isBuiltin) {
|
|
352
|
+
const cf = await childFields(targetKey);
|
|
353
|
+
const ownsBack = cf != null &&
|
|
354
|
+
cf.some((f) => f.name === "owner" &&
|
|
355
|
+
[String(ent.name).toLowerCase(), String(ent.alias).toLowerCase()].includes(String(f.relation_target ?? "").toLowerCase()));
|
|
356
|
+
if (ownsBack) {
|
|
357
|
+
tabularParts.push(String(p.name));
|
|
358
|
+
if (expand && cf) {
|
|
357
359
|
s.child_entity = targetKey;
|
|
358
|
-
s.child_fields = cf;
|
|
360
|
+
s.child_fields = cf.filter((f) => f.name !== "owner" && f.name !== "owner_id");
|
|
359
361
|
}
|
|
360
362
|
}
|
|
361
363
|
}
|
|
@@ -461,6 +463,114 @@ export async function readV1Enum(enumInput) {
|
|
|
461
463
|
function _enumNameFor(entityName, fieldName) {
|
|
462
464
|
return `${entityName}_${fieldName}`;
|
|
463
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Classify one 1.0 entity's props into scalar/enum/relation buckets and choose a
|
|
468
|
+
* title field. `dropNames` skips specific field names (used to drop a tabular
|
|
469
|
+
* part's `owner` field, which the platform auto-creates). Shared by top-level
|
|
470
|
+
* entities and their tabular-part children.
|
|
471
|
+
*/
|
|
472
|
+
async function _planFields(props, entName, v2EntName, targetResolver, entIndex, warnings, dropNames = new Set()) {
|
|
473
|
+
const scalarFields = [];
|
|
474
|
+
const enumFields = [];
|
|
475
|
+
const relationFields = [];
|
|
476
|
+
for (const p of props) {
|
|
477
|
+
if (!_isDict(p) || p.system) {
|
|
478
|
+
continue; // system/built-in fields are auto-created in 2.0
|
|
479
|
+
}
|
|
480
|
+
const fname = String(p.name ?? "");
|
|
481
|
+
if (dropNames.has(fname)) {
|
|
482
|
+
continue; // e.g. a tabular part's `owner` (auto-created by the platform)
|
|
483
|
+
}
|
|
484
|
+
const v2Fname = normalizeFieldName(fname);
|
|
485
|
+
const ftitle = String(p.title ?? "") || fname;
|
|
486
|
+
const ftype = String(p.type ?? "");
|
|
487
|
+
const fsub = typeof p.sub_type === "string" ? p.sub_type : null;
|
|
488
|
+
const required = !["", "never", "false"].includes(String(p.required ?? "never").toLowerCase());
|
|
489
|
+
const rawLen = p.max_length;
|
|
490
|
+
const maxLength = typeof rawLen === "number" && Number.isInteger(rawLen) && rawLen > 0 ? rawLen : null;
|
|
491
|
+
const rawPrec = p.precision;
|
|
492
|
+
const decimalPlaces = typeof rawPrec === "number" && Number.isInteger(rawPrec) && rawPrec > 0 ? rawPrec : null;
|
|
493
|
+
const cls = classifyV1Field(ftype, fsub, { isSystem: Boolean(p.system) });
|
|
494
|
+
if (cls.kind === KIND_SKIP) {
|
|
495
|
+
warnings.push(`${entName}.${fname}: ${cls.note || `unsupported type ${ftype}/${fsub}`} — skipped`);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (cls.kind === KIND_RELATION) {
|
|
499
|
+
const rel = _isDict(p.relation) ? p.relation : {};
|
|
500
|
+
const target = String(rel.relation_target_entity_name ?? "");
|
|
501
|
+
const v2Target = targetResolver[target.toLowerCase()];
|
|
502
|
+
const inSet = v2Target !== undefined;
|
|
503
|
+
if (target && !inSet) {
|
|
504
|
+
warnings.push(`${entName}.${fname}: relation target '${target}' is not in the migration set`);
|
|
505
|
+
}
|
|
506
|
+
relationFields.push({
|
|
507
|
+
v1_name: fname,
|
|
508
|
+
name: v2Fname,
|
|
509
|
+
title: ftitle,
|
|
510
|
+
type: cls.v2Type,
|
|
511
|
+
required,
|
|
512
|
+
relation_entity: v2Target ?? (target ? normalizeEntityName(target) : null),
|
|
513
|
+
target_in_set: inSet,
|
|
514
|
+
});
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (cls.kind === KIND_ENUM) {
|
|
518
|
+
const values = await _v1EnumValues(p);
|
|
519
|
+
enumFields.push({
|
|
520
|
+
v1_name: fname,
|
|
521
|
+
name: v2Fname,
|
|
522
|
+
title: ftitle,
|
|
523
|
+
type: cls.v2Type,
|
|
524
|
+
required,
|
|
525
|
+
enum_name: _enumNameFor(v2EntName, v2Fname),
|
|
526
|
+
values,
|
|
527
|
+
});
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (cls.kind === KIND_SCALAR || cls.kind === KIND_FILE) {
|
|
531
|
+
const field = {
|
|
532
|
+
v1_name: fname,
|
|
533
|
+
name: v2Fname,
|
|
534
|
+
title: ftitle,
|
|
535
|
+
type: cls.v2Type,
|
|
536
|
+
required,
|
|
537
|
+
sub_type: cls.v2SubType,
|
|
538
|
+
max_length: cls.v2Type === "text" ? maxLength : null,
|
|
539
|
+
decimal_places: cls.v2Type === "numeric" ? decimalPlaces : null,
|
|
540
|
+
multilingual: cls.multilingual,
|
|
541
|
+
};
|
|
542
|
+
if (cls.note) {
|
|
543
|
+
field.note = cls.note;
|
|
544
|
+
}
|
|
545
|
+
scalarFields.push(field);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
warnings.push(`${entName}.${fname}: unclassified field '${ftype}/${fsub}' — skipped`);
|
|
549
|
+
}
|
|
550
|
+
const scalarNames = scalarFields.map((f) => f.name);
|
|
551
|
+
const textLike = scalarFields
|
|
552
|
+
.filter((f) => f.type === "text" || f.type === "multi-language")
|
|
553
|
+
.map((f) => f.name);
|
|
554
|
+
let titleFieldName;
|
|
555
|
+
if (scalarNames.includes("name")) {
|
|
556
|
+
titleFieldName = "name";
|
|
557
|
+
}
|
|
558
|
+
else if (scalarNames.includes("title")) {
|
|
559
|
+
titleFieldName = "title";
|
|
560
|
+
}
|
|
561
|
+
else if (textLike.length > 0) {
|
|
562
|
+
titleFieldName = textLike[0];
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
titleFieldName = scalarNames.length > 0 ? scalarNames[0] : "name";
|
|
566
|
+
}
|
|
567
|
+
const allV1FieldNames = [
|
|
568
|
+
...scalarFields.map((f) => f.v1_name),
|
|
569
|
+
...enumFields.map((f) => f.v1_name),
|
|
570
|
+
...relationFields.map((f) => f.v1_name),
|
|
571
|
+
];
|
|
572
|
+
return { scalarFields, enumFields, relationFields, allV1FieldNames, titleFieldName };
|
|
573
|
+
}
|
|
464
574
|
// ---------------------------------------------------------------------------
|
|
465
575
|
// Planning
|
|
466
576
|
// ---------------------------------------------------------------------------
|
|
@@ -501,16 +611,40 @@ export async function _buildPlan(entityNames = "", includeBuiltin = false, skipR
|
|
|
501
611
|
}
|
|
502
612
|
}
|
|
503
613
|
}
|
|
504
|
-
|
|
614
|
+
// Index ALL 1.0 entities (not just selected) so relation/tabular targets can
|
|
615
|
+
// be resolved and their `builtin` flag checked even when outside the selection.
|
|
616
|
+
const entIndex = new Map();
|
|
617
|
+
for (const e of allEntities) {
|
|
618
|
+
if (!_isDict(e)) {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
const v1Name = String(e.name ?? "");
|
|
622
|
+
const alias = String(e.alias ?? "");
|
|
623
|
+
const info = {
|
|
624
|
+
v1Name,
|
|
625
|
+
alias: alias || v1Name,
|
|
626
|
+
builtin: Boolean(e.builtin),
|
|
627
|
+
id: String(e.id ?? ""),
|
|
628
|
+
};
|
|
629
|
+
if (v1Name) {
|
|
630
|
+
entIndex.set(v1Name.toLowerCase(), info);
|
|
631
|
+
}
|
|
632
|
+
if (alias) {
|
|
633
|
+
entIndex.set(alias.toLowerCase(), info);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
505
636
|
const warnings = [];
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const
|
|
510
|
-
const
|
|
637
|
+
// Fetch + cache each entity's props once (children may be fetched on demand).
|
|
638
|
+
const propsCache = new Map();
|
|
639
|
+
const fetchProps = async (id, entName) => {
|
|
640
|
+
const key = entName.toLowerCase();
|
|
641
|
+
const cached = propsCache.get(key);
|
|
642
|
+
if (cached) {
|
|
643
|
+
return cached;
|
|
644
|
+
}
|
|
511
645
|
let props;
|
|
512
646
|
try {
|
|
513
|
-
props = await _v1Request(`api/entity_props/${
|
|
647
|
+
props = await _v1Request(`api/entity_props/${id}`);
|
|
514
648
|
}
|
|
515
649
|
catch (ex) {
|
|
516
650
|
if (!(ex instanceof Error)) {
|
|
@@ -519,136 +653,98 @@ export async function _buildPlan(entityNames = "", includeBuiltin = false, skipR
|
|
|
519
653
|
warnings.push(`${entName}: failed to read props (${ex.message})`);
|
|
520
654
|
props = [];
|
|
521
655
|
}
|
|
522
|
-
|
|
523
|
-
|
|
656
|
+
const arr = Array.isArray(props) ? props : [];
|
|
657
|
+
propsCache.set(key, arr);
|
|
658
|
+
return arr;
|
|
659
|
+
};
|
|
660
|
+
// Phase A: detect tabular-part children. The reliable v1 marker is CHILD-side:
|
|
661
|
+
// a tabular part carries an `owner` relation pointing back to its parent.
|
|
662
|
+
// (Multi-valued many-to-many fields like `skills`/`vacancies` are shared
|
|
663
|
+
// lookups, NOT owned child tables — they stay normal relations.) A child is
|
|
664
|
+
// only nested when its parent is also in the migration set.
|
|
665
|
+
const selectedLower = new Set();
|
|
666
|
+
for (const e of selected) {
|
|
667
|
+
selectedLower.add(String(e.name ?? "").toLowerCase());
|
|
668
|
+
if (e.alias) {
|
|
669
|
+
selectedLower.add(String(e.alias).toLowerCase());
|
|
524
670
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
671
|
+
}
|
|
672
|
+
const ownerOf = new Map(); // childV1(lower) -> parentV1 (canonical)
|
|
673
|
+
for (const e of selected) {
|
|
674
|
+
const entName = String(e.name ?? "");
|
|
675
|
+
const props = await fetchProps(String(e.id ?? ""), entName);
|
|
676
|
+
const ownerField = props.find((p) => _isDict(p) && p.name === "owner" && p.type === "relation");
|
|
677
|
+
if (!ownerField) {
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
const rel = _isDict(ownerField.relation) ? ownerField.relation : {};
|
|
681
|
+
const parentInfo = entIndex.get(String(rel.relation_target_entity_name ?? "").toLowerCase());
|
|
682
|
+
if (parentInfo && selectedLower.has(parentInfo.v1Name.toLowerCase())) {
|
|
683
|
+
ownerOf.set(entName.toLowerCase(), parentInfo.v1Name);
|
|
684
|
+
}
|
|
685
|
+
else if (parentInfo) {
|
|
686
|
+
warnings.push(`${entName}: is a tabular part of '${parentInfo.v1Name}', which is not in the migration set — migrating standalone`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const isChild = (nameLower) => ownerOf.has(nameLower);
|
|
690
|
+
// Phase B: emit top-level entities; nest each parent's tabular-part children
|
|
691
|
+
// (dropping their platform-managed `owner` field).
|
|
692
|
+
const planEntities = [];
|
|
693
|
+
let tabularCount = 0;
|
|
694
|
+
for (const e of selected) {
|
|
695
|
+
const entName = String(e.name ?? "");
|
|
696
|
+
const entLower = entName.toLowerCase();
|
|
697
|
+
if (isChild(entLower)) {
|
|
698
|
+
const parent = ownerOf.get(entLower);
|
|
699
|
+
if (!isChild(parent.toLowerCase())) {
|
|
700
|
+
continue; // nested under its parent below (v2 supports one level)
|
|
552
701
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
702
|
+
warnings.push(`${entName}: nested tabular part (parent '${parent}' is itself a tabular part) — migrating standalone`);
|
|
703
|
+
}
|
|
704
|
+
const entTitle = String(e.alias ?? "") || entName;
|
|
705
|
+
const v2EntName = normalizeEntityName(entName);
|
|
706
|
+
const props = await fetchProps(String(e.id ?? ""), entName);
|
|
707
|
+
const pf = await _planFields(props, entName, v2EntName, targetResolver, entIndex, warnings);
|
|
708
|
+
const tabularParts = [];
|
|
709
|
+
if (!isChild(entLower)) {
|
|
710
|
+
for (const c of selected) {
|
|
711
|
+
const cName = String(c.name ?? "");
|
|
712
|
+
if (ownerOf.get(cName.toLowerCase()) !== entName) {
|
|
713
|
+
continue; // not a tabular part of this entity
|
|
564
714
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (cls.kind === KIND_ENUM) {
|
|
578
|
-
const values = await _v1EnumValues(p);
|
|
579
|
-
enumFields.push({
|
|
580
|
-
v1_name: fname,
|
|
581
|
-
name: v2Fname,
|
|
582
|
-
title: ftitle,
|
|
583
|
-
type: cls.v2Type,
|
|
584
|
-
required,
|
|
585
|
-
enum_name: _enumNameFor(v2EntName, v2Fname),
|
|
586
|
-
values,
|
|
715
|
+
const cprops = await fetchProps(String(c.id ?? ""), cName);
|
|
716
|
+
const cv2 = normalizeEntityName(cName);
|
|
717
|
+
const cf = await _planFields(cprops, cName, cv2, targetResolver, entIndex, warnings, new Set(["owner", "owner_id"]));
|
|
718
|
+
tabularParts.push({
|
|
719
|
+
v1_name: cName,
|
|
720
|
+
name: cv2,
|
|
721
|
+
title: String(c.alias ?? "") || cName,
|
|
722
|
+
title_field_name: cf.titleFieldName,
|
|
723
|
+
scalar_fields: cf.scalarFields,
|
|
724
|
+
enum_fields: cf.enumFields,
|
|
725
|
+
relation_fields: skipRelations ? [] : cf.relationFields,
|
|
726
|
+
name_map: buildNameMap(cName, cf.allV1FieldNames),
|
|
587
727
|
});
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
// Scalars + file attachments (file / multi-file are added like scalars).
|
|
591
|
-
if (cls.kind === KIND_SCALAR || cls.kind === KIND_FILE) {
|
|
592
|
-
const field = {
|
|
593
|
-
v1_name: fname,
|
|
594
|
-
name: v2Fname,
|
|
595
|
-
title: ftitle,
|
|
596
|
-
type: cls.v2Type,
|
|
597
|
-
required,
|
|
598
|
-
sub_type: cls.v2SubType,
|
|
599
|
-
max_length: cls.v2Type === "text" ? maxLength : null,
|
|
600
|
-
decimal_places: cls.v2Type === "numeric" ? decimalPlaces : null,
|
|
601
|
-
multilingual: cls.multilingual,
|
|
602
|
-
};
|
|
603
|
-
if (cls.note) {
|
|
604
|
-
field.note = cls.note;
|
|
605
|
-
}
|
|
606
|
-
scalarFields.push(field);
|
|
607
|
-
continue;
|
|
728
|
+
tabularCount++;
|
|
608
729
|
}
|
|
609
|
-
// Defensive: an unclassified kind should never reach here.
|
|
610
|
-
warnings.push(`${entName}.${fname}: unclassified field '${ftype}/${fsub}' — skipped`);
|
|
611
|
-
}
|
|
612
|
-
// Choose the entity title field: prefer 'name', then 'title', then the first
|
|
613
|
-
// text-like scalar (a number/date/boolean/icon makes a poor display title),
|
|
614
|
-
// then any scalar, else 'name'.
|
|
615
|
-
const scalarNames = scalarFields.map((f) => f.name);
|
|
616
|
-
const textLike = scalarFields
|
|
617
|
-
.filter((f) => f.type === "text" || f.type === "multi-language")
|
|
618
|
-
.map((f) => f.name);
|
|
619
|
-
let titleField;
|
|
620
|
-
if (scalarNames.includes("name")) {
|
|
621
|
-
titleField = "name";
|
|
622
|
-
}
|
|
623
|
-
else if (scalarNames.includes("title")) {
|
|
624
|
-
titleField = "title";
|
|
625
|
-
}
|
|
626
|
-
else if (textLike.length > 0) {
|
|
627
|
-
titleField = textLike[0];
|
|
628
|
-
}
|
|
629
|
-
else {
|
|
630
|
-
titleField = scalarNames.length > 0 ? scalarNames[0] : "name";
|
|
631
730
|
}
|
|
632
|
-
const allV1FieldNames = [
|
|
633
|
-
...scalarFields.map((f) => f.v1_name),
|
|
634
|
-
...enumFields.map((f) => f.v1_name),
|
|
635
|
-
...relationFields.map((f) => f.v1_name),
|
|
636
|
-
];
|
|
637
731
|
planEntities.push({
|
|
638
732
|
v1_name: entName,
|
|
639
733
|
name: v2EntName,
|
|
640
734
|
title: entTitle,
|
|
641
|
-
title_field_name:
|
|
642
|
-
scalar_fields: scalarFields,
|
|
643
|
-
enum_fields: enumFields,
|
|
644
|
-
relation_fields: relationFields,
|
|
645
|
-
|
|
735
|
+
title_field_name: pf.titleFieldName,
|
|
736
|
+
scalar_fields: pf.scalarFields,
|
|
737
|
+
enum_fields: pf.enumFields,
|
|
738
|
+
relation_fields: skipRelations ? [] : pf.relationFields,
|
|
739
|
+
tabular_parts: tabularParts,
|
|
740
|
+
name_map: buildNameMap(entName, pf.allV1FieldNames),
|
|
646
741
|
});
|
|
647
742
|
}
|
|
648
743
|
return {
|
|
649
744
|
source: config.V1_BASE_URL,
|
|
650
745
|
target: tenants.current().baseUrl,
|
|
651
746
|
entity_count: planEntities.length,
|
|
747
|
+
tabular_part_count: tabularCount,
|
|
652
748
|
entities: planEntities,
|
|
653
749
|
warnings,
|
|
654
750
|
};
|
|
@@ -857,6 +953,52 @@ export async function _execute(plan, mode = "create") {
|
|
|
857
953
|
details.push(step);
|
|
858
954
|
}
|
|
859
955
|
void live;
|
|
956
|
+
// Tabular parts: create each owned child sub-table (type="tabular-part",
|
|
957
|
+
// auto owner FK back to the parent), then add its scalar + enum fields.
|
|
958
|
+
for (const tp of (ent.tabular_parts ?? [])) {
|
|
959
|
+
const tpName = tp.name;
|
|
960
|
+
const tpStep = await _runWrite(`create_tabular_part:${tpName}`, () => entityTools.createTabularPart(name, // parent entity
|
|
961
|
+
tpName, tp.title, tp.title_field_name, false, // add the real fields ourselves
|
|
962
|
+
"text", tpName));
|
|
963
|
+
tpStep.entity = name;
|
|
964
|
+
tpStep.tabular_part = tpName;
|
|
965
|
+
details.push(tpStep);
|
|
966
|
+
const tlive = await _liveFields(tpName);
|
|
967
|
+
for (const f of tp.scalar_fields) {
|
|
968
|
+
if (f.name in tlive) {
|
|
969
|
+
details.push({ entity: tpName, action: `add_field:${f.name}`, status: "skipped", reason: "exists" });
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
const step = await _runWrite(`add_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type, f.title, {
|
|
973
|
+
required: f.required ?? false,
|
|
974
|
+
subType: f.sub_type ?? null,
|
|
975
|
+
maxLength: f.max_length ?? null,
|
|
976
|
+
decimalPlaces: f.decimal_places ?? null,
|
|
977
|
+
}));
|
|
978
|
+
step.entity = tpName;
|
|
979
|
+
details.push(step);
|
|
980
|
+
}
|
|
981
|
+
for (const f of tp.enum_fields) {
|
|
982
|
+
if (f.name in tlive) {
|
|
983
|
+
details.push({ entity: tpName, action: `add_enum_field:${f.name}`, status: "skipped", reason: "exists" });
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (f.values && f.values.length) {
|
|
987
|
+
try {
|
|
988
|
+
await entityTools.addEnumValues(f.enum_name, f.values.join(","));
|
|
989
|
+
}
|
|
990
|
+
catch {
|
|
991
|
+
// enum-values failure is reported via the field add below
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
const step = await _runWrite(`add_enum_field:${f.name}`, () => entityTools.addField(tpName, f.name, f.type ?? "enum", f.title, {
|
|
995
|
+
required: f.required ?? false,
|
|
996
|
+
enumName: f.enum_name,
|
|
997
|
+
}));
|
|
998
|
+
step.entity = tpName;
|
|
999
|
+
details.push(step);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
860
1002
|
}
|
|
861
1003
|
// Pass 2: relations (targets now exist).
|
|
862
1004
|
for (const ent of plan.entities) {
|
|
@@ -892,14 +1034,44 @@ export async function _execute(plan, mode = "create") {
|
|
|
892
1034
|
details.push(step);
|
|
893
1035
|
}
|
|
894
1036
|
}
|
|
895
|
-
//
|
|
896
|
-
const verify = {};
|
|
1037
|
+
// Pass 2b: relations declared on tabular parts (targets now exist).
|
|
897
1038
|
for (const ent of plan.entities) {
|
|
898
|
-
const
|
|
1039
|
+
for (const tp of (ent.tabular_parts ?? [])) {
|
|
1040
|
+
if (!tp.relation_fields || tp.relation_fields.length === 0) {
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
const tlive = await _liveFields(tp.name);
|
|
1044
|
+
for (const f of tp.relation_fields) {
|
|
1045
|
+
if (f.name in tlive) {
|
|
1046
|
+
details.push({ entity: tp.name, action: `add_relation:${f.name}`, status: "skipped", reason: "exists" });
|
|
1047
|
+
continue;
|
|
1048
|
+
}
|
|
1049
|
+
if (!f.relation_entity || !(f.target_in_set ?? true)) {
|
|
1050
|
+
details.push({
|
|
1051
|
+
entity: tp.name,
|
|
1052
|
+
action: `add_relation:${f.name}`,
|
|
1053
|
+
status: "skipped",
|
|
1054
|
+
reason: `relation target not in migration set (${f.relation_entity})`,
|
|
1055
|
+
});
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
const step = await _runWrite(`add_relation:${f.name}`, () => entityTools.addField(tp.name, f.name, f.type, f.title, {
|
|
1059
|
+
required: f.required ?? false,
|
|
1060
|
+
relationEntity: f.relation_entity,
|
|
1061
|
+
}));
|
|
1062
|
+
step.entity = tp.name;
|
|
1063
|
+
details.push(step);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
// Verify: re-read each entity (and each tabular part) and confirm every
|
|
1068
|
+
// planned field is present.
|
|
1069
|
+
const verify = {};
|
|
1070
|
+
const verifyOne = async (name, spec) => {
|
|
899
1071
|
const planned = [
|
|
900
|
-
...
|
|
901
|
-
...
|
|
902
|
-
...
|
|
1072
|
+
...spec.scalar_fields.map((f) => f.name),
|
|
1073
|
+
...spec.enum_fields.map((f) => f.name),
|
|
1074
|
+
...(spec.relation_fields ?? [])
|
|
903
1075
|
.filter((f) => f.relation_entity && (f.target_in_set ?? true))
|
|
904
1076
|
.map((f) => f.name),
|
|
905
1077
|
];
|
|
@@ -909,6 +1081,12 @@ export async function _execute(plan, mode = "create") {
|
|
|
909
1081
|
present: planned.filter((p) => present.has(p)).sort(),
|
|
910
1082
|
missing: planned.filter((p) => !present.has(p)).sort(),
|
|
911
1083
|
};
|
|
1084
|
+
};
|
|
1085
|
+
for (const ent of plan.entities) {
|
|
1086
|
+
await verifyOne(ent.name, ent);
|
|
1087
|
+
for (const tp of (ent.tabular_parts ?? [])) {
|
|
1088
|
+
await verifyOne(tp.name, tp);
|
|
1089
|
+
}
|
|
912
1090
|
}
|
|
913
1091
|
return {
|
|
914
1092
|
executed: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.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" },
|