suppa-mcp-2 1.33.0 → 1.34.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.33.0",
3
+ "version": "1.34.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
6
  "bin": {
@@ -215,6 +215,17 @@ For a large port the platform ships a generator rather than asking you to type i
215
215
 
216
216
  That dump shape is exactly the declaration `suppa_apply_custom_fields` reads, so a file written for the MCP tool ports to the decorator without being retyped — and vice versa.
217
217
 
218
+ ## What the API reference adds
219
+
220
+ The migrations page links to a separate [custom fields API reference](https://docs.modern-expo.com/backend/api/entity-builder/custom-fields.html) for "the full contract — projections, search, per-set attributes". Captured as `docs/superpowers/specs/captures/api-custom-fields.txt`. Six things there change how you write the class:
221
+
222
+ - **There is a per-table cap.** Active client fields per extension table are limited by `CUSTOM_FIELDS_LIMIT`, **default 200**; exceeding it answers 400 with the usage numbers. The migrations page says the cap "guards the API, not migrations" — a declaration can push a table past it, and then the API stops serving that table. Count the properties before porting a large list.
223
+ - **Sets are inherited down a hierarchy.** "When the context field relates to a hierarchical entity with `parents`, sets also apply to descendants of the `contextValue`." So a field declared for a parent context shows on records of its children; you do not declare one entry per descendant.
224
+ - **A field in several sets merges its per-set attributes**, and the rules are not "last wins": `required` — any set demanding it wins; `readOnly` — an explicit editable beats a read-only, `null` defers to the field; `defaultValue` — the first non-null in set id order.
225
+ - **The owner's schema already lists the sets.** `GET /core/schema/<E>` carries a `customFieldSets` array (`id`, `title`, `contextFieldName`, `contextValue`) beside `customFields` with their `setIds` — the cheap way to see every context at once. It is schema only; the ACTIVE set for a given record still comes from `/custom-fields/<E>/resolve`.
226
+ - **You can sort and filter through a relation custom field** — `customFields.reviewer.fullName` — because each step of the chain yields at most one row. A multi-row collection in the chain is `400 query.planner_unsupported`. Full-text search covers the extension table's own searchable TEXT fields only (not a relation's content), and the base entity must have at least one searchable field of its own.
227
+ - **Write values inline on the owner, not on the extension table.** Both paths validate against the active sets, but a direct extension-table write "bridges into an owner update after the values row is written" and is **not atomic** — the values commit first. Inline writes run inside the owner's transaction, bump `updatedAt`, and fire triggers, socket events and automations with `customFields` among the changed fields.
228
+
218
229
  ## Which route to take
219
230
 
220
231
  | Situation | Route |
@@ -30,5 +30,8 @@ export const BLOCKING_SUMMARY =
30
30
  "(E116/E117/W616/W617), extension mode — ignored entity options, no reverse relations, no primary, " +
31
31
  "no NOT NULL without a default, indexes over your own columns only (W618/E118/E119/E120/E121/E122/E123/W620), " +
32
32
  "`owner` first in a tabular part's importKeyFields (W607), no second entity class of the same name — " +
33
- "the other one is then analyzed by nothing (W619) — and no " +
34
- "`inverse` on @ManyToOne/@ManyToMany (W609)";
33
+ "the other one is then analyzed by nothing (W619), no " +
34
+ "`inverse` on @ManyToOne/@ManyToMany (W609) — and, on a @CustomFields class, never registering or " +
35
+ "decorating it, the `customFields` property name, a set on every column, no primary, no reverse " +
36
+ "relation, no NOT NULL without a default " +
37
+ "(E124/E125/E126/E127/E128/W621/W622/W623)";
@@ -71,6 +71,9 @@ export const RULE_WARNINGS = [
71
71
  "W617", // field-less entity in a file not named <name>.stub.entity.ts
72
72
  "W618", // extension declaring entity options extension mode ignores
73
73
  "W620", // relation target named by string outside an extension
74
+ "W621", // custom-field column with no customFieldSets: no record shows it
75
+ "W622", // customFieldSets contextField names no field on the owner
76
+ "W623", // options: { customFields: true } written beside @CustomFields
74
77
  ];
75
78
  /**
76
79
  * W613 argues from ABSENCE — "nothing references this name". That only holds
@@ -702,6 +705,14 @@ function analyzeEntities(ts, sf, model, opts = {}) {
702
705
  optionsNode: d.args[0] ?? null,
703
706
  nameNode: objectMap(ts, d.args[0]).get("name") ?? null,
704
707
  });
708
+ } else if (d.name === "CustomFields") {
709
+ // Not a field: it names the class that becomes the columns of the
710
+ // platform-generated {Owner}CustomFields table. Kept off
711
+ // info.properties so no field rule treats it as a column.
712
+ info.customFieldsProp = {
713
+ propName, node: member, decorator: d,
714
+ targetClass: thunkTarget(ts, sf, d.args[0]),
715
+ };
705
716
  } else if (d.name in RELATION_KIND_BY_DECORATOR) {
706
717
  // (target, options?) or (target, inverse, options?) — the options
707
718
  // object is whichever trailing argument is an object literal; the
@@ -757,6 +768,198 @@ function analyzeEntities(ts, sf, model, opts = {}) {
757
768
  });
758
769
  }
759
770
 
771
+ // ── rules: custom fields declared in code (@suppa/sdk 1.38.0) ──
772
+ /**
773
+ * `@CustomFields(() => Cls)` on an owner entity, with Cls a PLAIN class of
774
+ * columns. Transcribed from migrations.html#custom-fields (captured in
775
+ * docs/superpowers/specs/captures/migrations-custom-fields.txt).
776
+ *
777
+ * This is the one place where this checker's own habits point at the wall.
778
+ * Rule 19 says a class naming a table gets @Entity() and registration; rule 21
779
+ * says a class never passed to forFeature() is invisible. Neither reaches the
780
+ * nested class: it names no table of its own, and registering it makes the
781
+ * platform build a plain table where the generated extension table belongs —
782
+ * "writing an entity row of your own would replace it with a plain table and
783
+ * break every custom-field read and write". Nothing else would catch that, and
784
+ * the damage is silent, so it is an error rather than a warning.
785
+ */
786
+ function checkCustomFieldsClasses(ts, model, findings) {
787
+ const registered = new Set(model.modules.flatMap((m) => m.entities.names));
788
+ for (const info of model.entities.values()) {
789
+ if (info.outOfScope) continue;
790
+ const cf = info.customFieldsProp;
791
+ if (!cf) continue;
792
+
793
+ // "The property must be named `customFields`, and one class serves one
794
+ // owner. That is the name the platform gives the back reference; both rules
795
+ // fail the build loudly."
796
+ if (cf.propName !== "customFields") {
797
+ findings.push(finding(ts, info.sf, cf.node, "E125",
798
+ `@CustomFields is on a property called '${cf.propName}', but the platform names the back ` +
799
+ `reference 'customFields' and accepts no other — the build fails loudly on this. Rename the ` +
800
+ `property to customFields; the extension table is named after the OWNER either way ` +
801
+ `('${info.entityName}CustomFields'), never after the class.`));
802
+ }
803
+
804
+ // "The `@CustomFields` property implies `options: { customFields: true }`."
805
+ const optNode = info.options.get("options");
806
+ if (optNode) {
807
+ const entityOpts = objectMap(ts, optNode);
808
+ if (entityOpts.get("customFields")) {
809
+ findings.push(finding(ts, info.sf, entityOpts.get("customFields"), "W623",
810
+ `options: { customFields: … } is written beside @CustomFields, which already implies it. ` +
811
+ `Delete the option and keep the decorator — two statements of one fact drift apart.`));
812
+ }
813
+ }
814
+
815
+ const targetName = cf.targetClass;
816
+ if (!targetName) {
817
+ findings.push(finding(ts, info.sf, cf.node, "W624",
818
+ `@CustomFields target cannot be read as a thunk returning a class, so none of the ` +
819
+ `custom-field rules could run on it. Write it as @CustomFields(() => ${info.className}CustomFields).`));
820
+ continue;
821
+ }
822
+
823
+ // Registering it is the silent breaker.
824
+ if (registered.has(targetName)) {
825
+ findings.push(finding(ts, info.sf, cf.node, "E124",
826
+ `'${targetName}' is passed to EntityModule.forFeature(), but the class behind @CustomFields ` +
827
+ `is NOT an entity — "register only the owner". Registering it makes the platform build a ` +
828
+ `plain table where the generated '${info.entityName}CustomFields' belongs, which breaks every ` +
829
+ `custom-field read and write. Remove it from forFeature(); only '${info.className}' belongs there.`));
830
+ }
831
+
832
+ const binding = findLocalBinding(ts, info.sf, targetName);
833
+ if (!binding || binding.kind !== "class") {
834
+ // Declared elsewhere: the registration check above still applied, but the
835
+ // column rules need the class body. Say a check was skipped rather than
836
+ // implying the class is clean.
837
+ findings.push(finding(ts, info.sf, cf.node, "W624",
838
+ `the class '${targetName}' behind @CustomFields is not declared in this file, so its columns ` +
839
+ `were not checked (no-set columns, nullable without default, primary, reverse relations). ` +
840
+ `The doc keeps it beside the owner it serves.`));
841
+ continue;
842
+ }
843
+
844
+ const cls = binding.node;
845
+ const clsDecs = decoratorsOf(ts, cls).map((d) => decoratorCall(ts, d, info.sf)).filter(Boolean);
846
+ if (clsDecs.some((d) => d.name === "Entity")) {
847
+ findings.push(finding(ts, info.sf, cls.name ?? cls, "E124",
848
+ `'${targetName}' carries @Entity(), but the class behind @CustomFields "is not an entity, has ` +
849
+ `no @Entity(), does not extend SystemBaseEntity and is never registered". With @Entity() the ` +
850
+ `platform builds a plain table instead of the generated extension table, breaking every ` +
851
+ `custom-field read and write. Delete the decorator.`));
852
+ }
853
+ const heritage = cls.heritageClauses ?? [];
854
+ const extendsSomething = heritage.some((h) => h.token === ts.SyntaxKind.ExtendsKeyword);
855
+ if (extendsSomething) {
856
+ findings.push(finding(ts, info.sf, cls.name ?? cls, "E124",
857
+ `'${targetName}' extends a base class, but the class behind @CustomFields "does not extend ` +
858
+ `SystemBaseEntity" — the generated table already carries the owner relation and the standard ` +
859
+ `columns. Declare it as a plain class: export class ${targetName} { … }.`));
860
+ }
861
+
862
+ checkCustomFieldColumns(ts, info, cls, findings);
863
+ }
864
+ }
865
+
866
+ /** Every property of the nested class is one custom field. */
867
+ function checkCustomFieldColumns(ts, info, cls, findings) {
868
+ const ownerFields = new Set();
869
+ for (const [propName, prop] of info.properties) {
870
+ ownerFields.add(propName);
871
+ const colName = stringValue(ts, prop.nameNode);
872
+ if (colName) ownerFields.add(colName);
873
+ }
874
+
875
+ for (const member of cls.members ?? []) {
876
+ if (!member.name) continue;
877
+ const propName = ts.isIdentifier(member.name) || ts.isStringLiteral(member.name)
878
+ ? member.name.text : member.name.getText(info.sf);
879
+ const decs = decoratorsOf(ts, member).map((d) => decoratorCall(ts, d, info.sf)).filter(Boolean);
880
+ if (!decs.length) continue;
881
+
882
+ // "`primary`, `@OneToMany()` and `@ManyToManyBackRef()` are rejected" —
883
+ // the same extension-mode restrictions as any table this app does not own.
884
+ let reverse = false;
885
+ for (const d of decs) {
886
+ if (d.name === "OneToMany" || d.name === "ManyToManyBackRef") {
887
+ reverse = true;
888
+ findings.push(finding(ts, info.sf, member, "E126",
889
+ `'${propName}' uses @${d.name}(), which the platform REJECTS on a custom-field class — a ` +
890
+ `reverse relation creates a field on the other entity, and the generated extension table ` +
891
+ `is not this application's to reshape. Declare the relation on the other side.`));
892
+ }
893
+ }
894
+
895
+ // A reverse relation is not a column at all: reporting it again as a
896
+ // column with no set would say two things about one mistake.
897
+ if (reverse) continue;
898
+ const colDec = decs.find((d) => d.name === "Column") ??
899
+ decs.find((d) => d.name in RELATION_KIND_BY_DECORATOR);
900
+ if (!colDec) continue;
901
+ const opts = colDec.name === "Column"
902
+ ? objectMap(ts, colDec.args[0])
903
+ : objectMap(ts, [...colDec.args].reverse().find((a) => ts.isObjectLiteralExpression(a)));
904
+
905
+ if (opts.get("primary")) {
906
+ findings.push(finding(ts, info.sf, opts.get("primary"), "E126",
907
+ `'${propName}' declares primary, which the platform REJECTS on a custom-field class: the ` +
908
+ `generated table's key is the owner relation, not yours to redefine.`));
909
+ }
910
+
911
+ const nullable = opts.get("nullable");
912
+ const nullableIsFalse = nullable && nullable.kind === ts.SyntaxKind.FalseKeyword;
913
+ if (nullableIsFalse && !opts.get("default")) {
914
+ findings.push(finding(ts, info.sf, nullable, "E127",
915
+ `'${propName}' is nullable: false with no default. On a custom-field class "nullable: false ` +
916
+ `needs a default" — the values row may already exist for records that have no value for this ` +
917
+ `column yet. Give it a default (a SQL expression STRING), or leave it nullable.`));
918
+ }
919
+
920
+ // "A field with no set never shows up."
921
+ const inner = objectMap(ts, opts.get("options"));
922
+ const setsNode = inner.get("customFieldSets");
923
+ if (!setsNode) {
924
+ findings.push(finding(ts, info.sf, member, "W621",
925
+ `'${propName}' declares no options.customFieldSets, so no record will ever show it: a custom ` +
926
+ `field "exists in the metadata (and in GET /core/schema/${info.entityName} with an empty ` +
927
+ `setIds) but no record shows it". Declare where it applies — ` +
928
+ `options: { customFieldSets: [{ contextField: '<owner field>', contextValue: '<value>' }] } — ` +
929
+ `or, if it belongs on every record, it is an ordinary column of '${info.className}'.`));
930
+ continue;
931
+ }
932
+ if (!ts.isArrayLiteralExpression(setsNode)) {
933
+ findings.push(finding(ts, info.sf, setsNode, "W624",
934
+ `'${propName}' hands customFieldSets over by reference, so where it applies cannot be read ` +
935
+ `here and its contexts went unchecked. Write the array literally.`));
936
+ continue;
937
+ }
938
+ for (const entry of setsNode.elements) {
939
+ if (!ts.isObjectLiteralExpression(entry)) continue;
940
+ const set = objectMap(ts, entry);
941
+ const cfNode = set.get("contextField");
942
+ const cvNode = set.get("contextValue");
943
+ if (!cfNode || !cvNode) {
944
+ findings.push(finding(ts, info.sf, entry, "E128",
945
+ `'${propName}' has a customFieldSets entry without ` +
946
+ `${!cfNode ? "contextField" : "contextValue"} — a set binds the owner to ONE context value, ` +
947
+ `and both halves are required.`));
948
+ continue;
949
+ }
950
+ const cfName = stringValue(ts, cfNode);
951
+ // "contextField — Name of the field ON THE OWNER whose value decides the
952
+ // context. It must exist on the owner."
953
+ if (cfName && ownerFields.size > 0 && !ownerFields.has(cfName)) {
954
+ findings.push(finding(ts, info.sf, cfNode, "W622",
955
+ `'${propName}' keys its context on '${cfName}', which '${info.className}' does not declare — ` +
956
+ `contextField must name a field ON THE OWNER. The migration resolves the context inside the ` +
957
+ `write transaction, so an unresolvable one fails the whole start, not just this field.`));
958
+ }
959
+ }
960
+ }
961
+ }
962
+
760
963
  // ── rules: tabular parts ──
761
964
  /**
762
965
  * Doc: "Three things make an entity a tabular part. All three are required,
@@ -2778,6 +2981,7 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
2778
2981
  if (info.outOfScope) continue;
2779
2982
  checkEntity(ts, info, sdk, model, findings);
2780
2983
  }
2984
+ checkCustomFieldsClasses(ts, model, findings);
2781
2985
  for (const seed of model.seeds) checkSeed(ts, seed, model, findings);
2782
2986
  checkRegistration(ts, model, findings, rootDir, parsedByCanonical);
2783
2987
  checkTsconfig(ts, rootDir, model, findings);