suppa-mcp-2 1.9.0 → 1.10.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/dist/bin.js +6 -0
- package/dist/server.js +6 -5
- package/dist/version.js +5 -0
- package/package.json +1 -1
- package/skills/suppa-entity-code/SKILL.md +6 -5
- package/skills/suppa-entity-code/references/tabular-parts.md +9 -0
- package/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs +207 -23
- package/skills/suppa-entity-code/templates/entity.template.ts +10 -5
- package/skills/suppa-entity-code/templates/seed.template.ts +6 -1
package/dist/bin.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
9
|
import { buildServer } from "./server.js";
|
|
10
|
+
import { refreshLatestVersionInBackground } from "./version.js";
|
|
10
11
|
// Safety net: a long-running MCP stdio server must never be killed by a stray
|
|
11
12
|
// async rejection or a synchronous throw in some callback (a background token
|
|
12
13
|
// refresh, an aborted login-loopback request, a write to a closed socket…).
|
|
@@ -26,6 +27,11 @@ process.on("uncaughtException", (err) => {
|
|
|
26
27
|
try {
|
|
27
28
|
const server = buildServer();
|
|
28
29
|
await server.connect(new StdioServerTransport());
|
|
30
|
+
// Only once the server is actually serving, and detached: refresh the cached
|
|
31
|
+
// "newest published version" so the NEXT session's instructions can say the
|
|
32
|
+
// running build is behind. Never awaited, never fatal, skipped entirely when
|
|
33
|
+
// SUPPA_MCP_NO_UPDATE_CHECK is set.
|
|
34
|
+
refreshLatestVersionInBackground();
|
|
29
35
|
}
|
|
30
36
|
catch (e) {
|
|
31
37
|
process.stderr.write(`[suppa-mcp] fatal startup error: ${e instanceof Error ? e.stack || e.message : String(e)}\n`);
|
package/dist/server.js
CHANGED
|
@@ -20,7 +20,7 @@ import * as automation from "./tools/automation.js";
|
|
|
20
20
|
import * as auth from "./auth.js";
|
|
21
21
|
import * as tenants from "./tenants.js";
|
|
22
22
|
import { confirmRequired, jsonResponse } from "./utils.js";
|
|
23
|
-
import { PACKAGE_NAME, PACKAGE_VERSION, knownLatest, isOutdated, refreshLatestVersion,
|
|
23
|
+
import { PACKAGE_NAME, PACKAGE_VERSION, knownLatest, isOutdated, refreshLatestVersion, upgradeNotice, } from "./version.js";
|
|
24
24
|
export { PACKAGE_VERSION };
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
26
26
|
// Tool-behavior hints (MCP spec): clients use these for auto-approval policies.
|
|
@@ -316,10 +316,11 @@ export function buildServer() {
|
|
|
316
316
|
// Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
|
|
317
317
|
TOOL_NAMES.length = 0;
|
|
318
318
|
PROMPT_NAMES.length = 0;
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
|
|
319
|
+
// NOTE: the registry refresh is NOT fired here. buildServer() is called by
|
|
320
|
+
// tests and by any host that just wants the tool list, and a network request
|
|
321
|
+
// as a side effect of constructing an object is intrusive — it also showed up
|
|
322
|
+
// in tests that instrument global fetch and count calls. bin.ts fires it once,
|
|
323
|
+
// after the transport is connected.
|
|
323
324
|
const server = new McpServer({ name: "suppa-2.0", version: PACKAGE_VERSION }, { instructions: INSTRUCTIONS + upgradeNotice() });
|
|
324
325
|
const reg = (name, cfg, handler) => {
|
|
325
326
|
server.registerTool(name, {
|
package/dist/version.js
CHANGED
|
@@ -105,6 +105,11 @@ export function isOutdated() {
|
|
|
105
105
|
* registry cannot delay a single tool call.
|
|
106
106
|
*/
|
|
107
107
|
export async function refreshLatestVersion(force = false) {
|
|
108
|
+
// An air-gapped or policy-restricted environment can turn the lookup off
|
|
109
|
+
// entirely; everything else keeps working, and nothing is ever claimed about
|
|
110
|
+
// being outdated without evidence.
|
|
111
|
+
if (process.env.SUPPA_MCP_NO_UPDATE_CHECK)
|
|
112
|
+
return readCache()?.latest ?? null;
|
|
108
113
|
const cached = readCache();
|
|
109
114
|
if (!force && cached && Date.now() - cached.checked_at < CACHE_TTL_MS)
|
|
110
115
|
return cached.latest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suppa-mcp-2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.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": {
|
|
@@ -52,7 +52,7 @@ Confirm all 5 before writing anything:
|
|
|
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
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
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. **Every relation property carries its TypeScript type, and the type says what the decorator says.** `@ManyToOne` holds ONE row — `owner: ProductMatrixEntity;` — while `@ManyToMany`, `@OneToMany` and `@ManyToManyBackRef` hold many — `envs: ApplicationEnvsEntity[];`. Type it optional (`owner?: Target`) unless the relation is `nullable: false`. An untyped relation property is `any` to every consumer of the entity
|
|
55
|
+
14. **Every relation property carries its TypeScript type, and the type says what the decorator says.** `@ManyToOne` holds ONE row — `owner: ProductMatrixEntity;` — while `@ManyToMany`, `@OneToMany` and `@ManyToManyBackRef` hold many — `envs: ApplicationEnvsEntity[];`. Type it optional (`owner?: Target`) unless the relation is `nullable: false`. An untyped relation property is `any` to every consumer of the entity — and so is one typed `any`. E114/E115/W610/W615.
|
|
56
56
|
15. **Enum member keys are PascalCase** — `NotFilled = 'Not filled'`. The key is the identifier the code reads; the string on the right is what the platform stores, and the two need not match. W611.
|
|
57
57
|
16. **Never write an option that already holds its default value.** The platform applies `canGroup: true`, `canSort: true`, `showInTable: true`, `editFromTable: true`, `canFilter: true`, `readOnly: false`, `searchable: false` on its own. Declare one of these ONLY where the field departs from it; repeating defaults on every field buries the one option that actually differs. W612, and it fails the gate.
|
|
58
58
|
**This rule outranks the surrounding code.** An existing app repo very often has entities that restate all seven on every field — that is the habit this rule exists to stop, not a local convention to match. Write the new file clean; leave the old ones alone unless asked. The same goes for the platform's captured API docs: `api-entity-builder-builder.txt:66-73` lists these defaults as `false`, which live tenants contradict — a field created with no options comes back visible, sortable, groupable, filterable and editable.
|
|
@@ -212,20 +212,21 @@ If that prints nothing, the entity is not registered.
|
|
|
212
212
|
## Close-out gate (all steps, in order — no "done" before all pass)
|
|
213
213
|
|
|
214
214
|
```
|
|
215
|
-
1.
|
|
215
|
+
1. suppa_validate_entity_code(path=<app-root>) # passed: true
|
|
216
|
+
(or on the command line, same checker: node <this-skill-dir>/scripts/validate-suppa-schema.mjs <app-root> # exit 0)
|
|
216
217
|
(installed via npm: node_modules/suppa-mcp-2/skills/suppa-entity-code/scripts/validate-suppa-schema.mjs)
|
|
217
218
|
2. npx tsc --noEmit # in the app repo
|
|
218
219
|
3. push, then reload: POST /core/applications/:appId/reload
|
|
219
220
|
4. verify the tenant converged: suppa_describe_entity('<EntityName>')
|
|
220
221
|
```
|
|
221
222
|
|
|
222
|
-
Step 1 exists to catch exactly this: an unregistered class is E301 and the gate fails. Never report done on an unrun gate.
|
|
223
|
+
Step 1 exists to catch exactly this: an unregistered class is E301 and the gate fails. Never report done on an unrun gate. **The pass criterion is exit `0` / `passed: true`, not "0 errors"** — a run can print `0 error(s)` and still exit 1 on a rule violation.
|
|
223
224
|
|
|
224
225
|
`validate-suppa-schema.mjs` exits `0` on a clean run, `1` on violations, `2` on a usage error or a missing path. The gate requires exit `0`.
|
|
225
226
|
|
|
226
|
-
**Two classes of finding block it.** Errors (`E…`) always do. So do the *rule violations* — `W607`, `W609`, `W610`, `W611`, `W612`, `W613` —
|
|
227
|
+
**Two classes of finding block it.** Errors (`E…`) always do. So do the *rule violations* — `W607`, `W609`, `W610`, `W611`, `W612`, `W613`, `W615` — the codes that name a HOUSE RULE (rules 14-18) broken on a specific line, because a rule that only warns is a rule that gets ignored (that is exactly how an entity shipped with seven restated defaults on every field). Everything else is advisory and never blocks: `W601`-`W606` and `W608`, `W614`, which report what the checker could not see or could not verify, plus style advice the doc itself does not mandate.
|
|
227
228
|
|
|
228
|
-
`--no-strict` demotes the rule violations back to warnings. It exists for a legacy repo you are not cleaning up in this pass; it is not for making your own new file pass
|
|
229
|
+
`--no-strict` demotes the rule violations back to warnings. It exists for a legacy repo you are not cleaning up in this pass; it is not for making your own new file pass, and the run says so — demoted findings print as `[rule violation, demoted]` and the summary ends with `NOT a clean run`. `W613` argues from absence ("nothing references this name"), so it only blocks when a DIRECTORY was given: the checker then scans every `.ts` from the application's package root, including services and DTOs it never parses, so a name used anywhere in the repo counts as referenced. On an explicit file list it can only warn.
|
|
229
230
|
|
|
230
231
|
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@5` if it genuinely has none. Pin the major: plain `typescript` now installs 7.x, whose main entry exports only version info and carries no compiler API.
|
|
231
232
|
|
|
@@ -48,6 +48,15 @@ export class TaskChecklistItems extends SystemBaseEntity {
|
|
|
48
48
|
})
|
|
49
49
|
owner?: Tasks;
|
|
50
50
|
|
|
51
|
+
> **HOUSE RULE — write `owner` as NOT NULL (SKILL.md rules 14 and 18).**
|
|
52
|
+
> The doc's snippet above leaves `nullable` unset, which makes the parent link
|
|
53
|
+
> optional and types it `owner?: Tasks`. A tabular-part row only exists inside a
|
|
54
|
+
> parent, and `owner` is the FIRST `importKeyFields` entry — a null there breaks
|
|
55
|
+
> the business key it is supposed to scope. Declare `nullable: false` and type it
|
|
56
|
+
> `owner: Tasks` (no `?`), as `templates/tabular-part.template.ts` does. W610
|
|
57
|
+
> checks the two agree, whichever you choose; only `nullable: false` is correct
|
|
58
|
+
> here.
|
|
59
|
+
|
|
51
60
|
@Column({
|
|
52
61
|
name: 'title',
|
|
53
62
|
title: { en: 'Title', uk: 'Назва' },
|
|
@@ -294,7 +294,12 @@ function isFunctionLike(ts, n) {
|
|
|
294
294
|
* rather than inventing a mismatch.
|
|
295
295
|
*/
|
|
296
296
|
function propertyTypeInfo(ts, member) {
|
|
297
|
-
|
|
297
|
+
// A property states its type after the name; a set accessor states it on its
|
|
298
|
+
// parameter. Reading only the former would report a decorated setter as
|
|
299
|
+
// "no TypeScript type" (E114) when it has one.
|
|
300
|
+
const node =
|
|
301
|
+
member.type ??
|
|
302
|
+
(ts.isSetAccessorDeclaration?.(member) ? member.parameters?.[0]?.type : undefined);
|
|
298
303
|
if (!node) return null;
|
|
299
304
|
const sf = member.getSourceFile();
|
|
300
305
|
let t = node;
|
|
@@ -360,7 +365,14 @@ function booleanValue(ts, node) {
|
|
|
360
365
|
* suggested 'Значення', a warning with no action in it.
|
|
361
366
|
*/
|
|
362
367
|
function isPascalCase(name) {
|
|
363
|
-
|
|
368
|
+
// Upper-first, letters and digits only, and NOT all-caps: `DRAFT` and
|
|
369
|
+
// `NOTFILLED` passed the first test while `DRAFT_ORDER` failed, so the
|
|
370
|
+
// SCREAMING spellings — the ones a v1 import produces — sailed through the
|
|
371
|
+
// very rule that exists to stop them. A single-letter key (`A`) is upper-case
|
|
372
|
+
// by necessity and stays legal.
|
|
373
|
+
if (!/^\p{Lu}[\p{L}\p{N}]*$/u.test(name)) return false;
|
|
374
|
+
const hasLower = /\p{Ll}/u.test(name);
|
|
375
|
+
return hasLower || name.length === 1;
|
|
364
376
|
}
|
|
365
377
|
/**
|
|
366
378
|
* The property name an inverse selector's body accesses off its own single
|
|
@@ -512,7 +524,15 @@ function analyzeEntities(ts, sf, model) {
|
|
|
512
524
|
columnNames: new Set(), // literal `name` options of @Column/relations
|
|
513
525
|
};
|
|
514
526
|
for (const member of node.members) {
|
|
515
|
-
|
|
527
|
+
// Accessors carry decorators too. Skipping everything that was not a
|
|
528
|
+
// property declaration made a field declared as `@Column(…) get x()`
|
|
529
|
+
// invisible to EVERY rule at once — no type check, no option check, no
|
|
530
|
+
// enum check, and a completely silent exit 0.
|
|
531
|
+
const isField =
|
|
532
|
+
ts.isPropertyDeclaration(member) ||
|
|
533
|
+
ts.isGetAccessorDeclaration(member) ||
|
|
534
|
+
ts.isSetAccessorDeclaration(member);
|
|
535
|
+
if (!isField || !member.name) continue;
|
|
516
536
|
const propName =
|
|
517
537
|
ts.isIdentifier(member.name) || ts.isStringLiteral(member.name)
|
|
518
538
|
? member.name.text
|
|
@@ -880,11 +900,26 @@ function checkDefaultFieldOptions(ts, sf, propName, prop, findings) {
|
|
|
880
900
|
}
|
|
881
901
|
const scopes = [];
|
|
882
902
|
if (prop.optionsNode) scopes.push(unwrapExpr(ts, prop.optionsNode));
|
|
883
|
-
// …and
|
|
884
|
-
|
|
885
|
-
|
|
903
|
+
// …and every nested `options: { … }` level, whichever shape the SDK takes.
|
|
904
|
+
// Unwrapping exactly one level left `options.options.options` unchecked.
|
|
905
|
+
for (let i = 0; i < scopes.length && i < 8; i++) {
|
|
906
|
+
const nested = objectMap(ts, scopes[i]).get("options");
|
|
886
907
|
const unwrapped = nested && unwrapExpr(ts, nested);
|
|
887
|
-
if (unwrapped && ts.isObjectLiteralExpression(unwrapped)
|
|
908
|
+
if (unwrapped && ts.isObjectLiteralExpression(unwrapped) && !scopes.includes(unwrapped)) {
|
|
909
|
+
scopes.push(unwrapped);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
// A spread hides whatever it carries. @Column has its own spread warning and
|
|
913
|
+
// the relations get one from checkRelationTyping (naming W610), so this covers
|
|
914
|
+
// the kinds that had none at all — a spread there silenced the default-option
|
|
915
|
+
// rule without a word.
|
|
916
|
+
if (!["column", ...RELATION_KINDS].includes(prop.kind)) {
|
|
917
|
+
for (const scope of scopes) {
|
|
918
|
+
for (const spread of spreadElements(ts, scope)) {
|
|
919
|
+
findings.push(finding(ts, sf, spread, "W606",
|
|
920
|
+
`'${propName}' (@${prop.decorator.name}) spreads its options, and spread content cannot be read statically — the default-option check (W612) is skipped for whatever it carries. Inline the options to restore it.`));
|
|
921
|
+
}
|
|
922
|
+
}
|
|
888
923
|
}
|
|
889
924
|
// Not for @Enum/@MultiEnum: their options slot is ambiguous with an inline
|
|
890
925
|
// TITLES map (see the extractor), and a titles map is BUILT from computed
|
|
@@ -1111,7 +1146,6 @@ function analyzeEnums(ts, sf, model) {
|
|
|
1111
1146
|
// That is the exact shape that shipped. The site lets the check discount
|
|
1112
1147
|
// occurrences inside the very property that declares the name.
|
|
1113
1148
|
if (ts.isStringLiteral(node)) {
|
|
1114
|
-
model.stringLiteralCounts.set(node.text, (model.stringLiteralCounts.get(node.text) ?? 0) + 1);
|
|
1115
1149
|
const sites = model.stringLiteralSites.get(node.text) ?? [];
|
|
1116
1150
|
sites.push({ file: sf.fileName, start: node.getStart(sf), end: node.getEnd() });
|
|
1117
1151
|
model.stringLiteralSites.set(node.text, sites);
|
|
@@ -1683,12 +1717,20 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
|
|
|
1683
1717
|
const model = {
|
|
1684
1718
|
entities: new Map(), entityByName: new Map(),
|
|
1685
1719
|
seeds: [], modules: [], stringEnums: new Map(),
|
|
1686
|
-
enumDeclarations: [],
|
|
1720
|
+
enumDeclarations: [], stringLiteralSites: new Map(),
|
|
1687
1721
|
externalTexts: [],
|
|
1688
1722
|
};
|
|
1689
1723
|
const findings = [];
|
|
1690
|
-
// the CLI deduped; the exported API did not, and duplicated seeds duplicated
|
|
1691
|
-
|
|
1724
|
+
// the CLI deduped; the exported API did not, and duplicated seeds duplicated
|
|
1725
|
+
// findings. Dedup is CASE-INSENSITIVE on Windows: the same file named twice
|
|
1726
|
+
// under different case parsed twice, and W613 read the second copy as an
|
|
1727
|
+
// external reference to the enum name declared in the first.
|
|
1728
|
+
const seenFiles = new Map();
|
|
1729
|
+
for (const f of files) {
|
|
1730
|
+
const key = canonical(f);
|
|
1731
|
+
if (!seenFiles.has(key)) seenFiles.set(key, resolve(f));
|
|
1732
|
+
}
|
|
1733
|
+
const uniqueFiles = [...seenFiles.values()];
|
|
1692
1734
|
const sources = uniqueFiles.map((f) =>
|
|
1693
1735
|
ts.createSourceFile(f, readFileSync(f, "utf-8"), ts.ScriptTarget.Latest, true),
|
|
1694
1736
|
);
|
|
@@ -1746,7 +1788,13 @@ export function validateSchema({ files = [], rootDir = null } = {}) {
|
|
|
1746
1788
|
*/
|
|
1747
1789
|
function collectExternalTexts(rootDir, analyzed) {
|
|
1748
1790
|
if (!rootDir) return [];
|
|
1749
|
-
|
|
1791
|
+
// Scan from the PACKAGE root, not from whatever directory was pointed at.
|
|
1792
|
+
// Pointing the gate at src/common/database/entities is a normal thing to do,
|
|
1793
|
+
// and scanning only that subtree missed the seed one directory over — so a
|
|
1794
|
+
// correctly-declared global enum was reported as referenced by nothing, and
|
|
1795
|
+
// failed the gate.
|
|
1796
|
+
const searchRoot = packageRootFor(rootDir);
|
|
1797
|
+
const skip = new Set(analyzed.map((f) => canonical(f)));
|
|
1750
1798
|
const texts = [];
|
|
1751
1799
|
(function walk(dir) {
|
|
1752
1800
|
let entries;
|
|
@@ -1766,7 +1814,7 @@ function collectExternalTexts(rootDir, analyzed) {
|
|
|
1766
1814
|
}
|
|
1767
1815
|
if (st.isDirectory()) {
|
|
1768
1816
|
walk(p);
|
|
1769
|
-
} else if ((name.endsWith(".ts") || name.endsWith(".tsx")) && !skip.has(
|
|
1817
|
+
} else if ((name.endsWith(".ts") || name.endsWith(".tsx")) && !skip.has(canonical(p))) {
|
|
1770
1818
|
try {
|
|
1771
1819
|
texts.push(readFileSync(p, "utf-8"));
|
|
1772
1820
|
} catch {
|
|
@@ -1774,10 +1822,35 @@ function collectExternalTexts(rootDir, analyzed) {
|
|
|
1774
1822
|
}
|
|
1775
1823
|
}
|
|
1776
1824
|
}
|
|
1777
|
-
})(
|
|
1825
|
+
})(searchRoot);
|
|
1778
1826
|
return texts;
|
|
1779
1827
|
}
|
|
1780
1828
|
|
|
1829
|
+
/**
|
|
1830
|
+
* One spelling per physical file. On Windows `D:\App\x.ts` and `d:\app\X.ts`
|
|
1831
|
+
* are the same file, and `resolve()` keeps them distinct: the same entity was
|
|
1832
|
+
* analyzed twice, so a global enum name declared once appeared in "two files"
|
|
1833
|
+
* and W613 read the duplicate as an external reference — the gate went green.
|
|
1834
|
+
*/
|
|
1835
|
+
function canonical(p) {
|
|
1836
|
+
const abs = resolve(p);
|
|
1837
|
+
return process.platform === "win32" ? abs.toLowerCase() : abs;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* The nearest ancestor holding a package.json — the application's real root.
|
|
1842
|
+
* Falls back to the directory given, so a loose folder of entities still works.
|
|
1843
|
+
*/
|
|
1844
|
+
function packageRootFor(dir) {
|
|
1845
|
+
let current = resolve(dir);
|
|
1846
|
+
while (true) {
|
|
1847
|
+
if (existsSync(join(current, "package.json"))) return current;
|
|
1848
|
+
const parent = dirname(current);
|
|
1849
|
+
if (parent === current) return resolve(dir);
|
|
1850
|
+
current = parent;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1781
1854
|
// ── discovery ──
|
|
1782
1855
|
export function discoverFiles(rootDir) {
|
|
1783
1856
|
const files = [];
|
|
@@ -1795,7 +1868,49 @@ export function discoverFiles(rootDir) {
|
|
|
1795
1868
|
}
|
|
1796
1869
|
}
|
|
1797
1870
|
})(resolve(rootDir));
|
|
1798
|
-
return files.sort();
|
|
1871
|
+
return [...new Set([...files, ...importedEnumModules(files)])].sort();
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Files the schema IMPORTS that declare enums — a repo very often keeps its
|
|
1876
|
+
* value sets in `enums.ts` or `common/enums/status.ts` rather than beside the
|
|
1877
|
+
* entity. Those files are not *.entity.ts and hold no forFeature, so nothing
|
|
1878
|
+
* parsed them: the PascalCase-member rule (W611) silently did not apply to any
|
|
1879
|
+
* shared enum, which is most of them.
|
|
1880
|
+
*
|
|
1881
|
+
* Only files reached by a RELATIVE import from an already-discovered file are
|
|
1882
|
+
* added, one hop, so the rule never wanders into application code that has
|
|
1883
|
+
* nothing to do with the schema.
|
|
1884
|
+
*/
|
|
1885
|
+
function importedEnumModules(files) {
|
|
1886
|
+
const found = [];
|
|
1887
|
+
const seen = new Set(files.map((f) => canonical(f)));
|
|
1888
|
+
for (const file of files) {
|
|
1889
|
+
let text;
|
|
1890
|
+
try {
|
|
1891
|
+
text = readFileSync(file, "utf-8");
|
|
1892
|
+
} catch {
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
for (const m of text.matchAll(/from\s+['"](\.[^'"]*)['"]/g)) {
|
|
1896
|
+
const base = join(dirname(file), m[1]);
|
|
1897
|
+
for (const candidate of [`${base}.ts`, join(base, "index.ts")]) {
|
|
1898
|
+
if (seen.has(canonical(candidate)) || !existsSync(candidate)) continue;
|
|
1899
|
+
let body;
|
|
1900
|
+
try {
|
|
1901
|
+
body = readFileSync(candidate, "utf-8");
|
|
1902
|
+
} catch {
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
// Only for the enum declarations: a file that declares none adds
|
|
1906
|
+
// nothing but parse time and the risk of unrelated findings.
|
|
1907
|
+
if (!/\benum\s+\w+\s*\{/.test(body)) continue;
|
|
1908
|
+
seen.add(canonical(candidate));
|
|
1909
|
+
found.push(candidate);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
return found;
|
|
1799
1914
|
}
|
|
1800
1915
|
|
|
1801
1916
|
// ── CLI ──
|
|
@@ -1804,15 +1919,40 @@ const isMain =
|
|
|
1804
1919
|
if (isMain) {
|
|
1805
1920
|
const argv = process.argv.slice(2);
|
|
1806
1921
|
// Default is strict: the authoring rules block. --no-strict is the escape for
|
|
1807
|
-
// a legacy repo whose existing entities restate defaults everywhere.
|
|
1808
|
-
|
|
1809
|
-
|
|
1922
|
+
// a legacy repo whose existing entities restate defaults everywhere. Flags are
|
|
1923
|
+
// LAST-WINS, so `--no-strict --strict` means strict — an accepted flag that
|
|
1924
|
+
// silently could not override its opposite is worse than an unknown one.
|
|
1925
|
+
// Everything after `--` is a path, so a directory really named --no-strict is
|
|
1926
|
+
// reachable.
|
|
1927
|
+
const terminator = argv.indexOf("--");
|
|
1928
|
+
const flagArgs = terminator === -1 ? argv : argv.slice(0, terminator);
|
|
1929
|
+
const pathArgs = terminator === -1 ? [] : argv.slice(terminator + 1);
|
|
1930
|
+
let strict = true;
|
|
1931
|
+
for (const a of flagArgs) {
|
|
1932
|
+
if (a === "--no-strict") strict = false;
|
|
1933
|
+
else if (a === "--strict") strict = true;
|
|
1934
|
+
}
|
|
1935
|
+
const args = [
|
|
1936
|
+
...flagArgs.filter((a) => a !== "--no-strict" && a !== "--strict"),
|
|
1937
|
+
...pathArgs,
|
|
1938
|
+
];
|
|
1939
|
+
const unknownFlag = args.find((a) => a.startsWith("--"));
|
|
1940
|
+
if (unknownFlag) {
|
|
1941
|
+
console.error(
|
|
1942
|
+
`validate-suppa-schema: unknown option '${unknownFlag}'. ` +
|
|
1943
|
+
"Only --strict (default) and --no-strict are options; put a path that starts with -- after '--'.",
|
|
1944
|
+
);
|
|
1945
|
+
process.exit(2);
|
|
1946
|
+
}
|
|
1810
1947
|
if (args.length === 0) {
|
|
1811
|
-
console.error(
|
|
1948
|
+
console.error(
|
|
1949
|
+
"usage: node validate-suppa-schema.mjs [--strict|--no-strict] [--] <app-root-or-files...>",
|
|
1950
|
+
);
|
|
1812
1951
|
process.exit(2);
|
|
1813
1952
|
}
|
|
1814
1953
|
let rootDir = null;
|
|
1815
1954
|
const files = [];
|
|
1955
|
+
const explicitFiles = [];
|
|
1816
1956
|
for (const a of args) {
|
|
1817
1957
|
const p = resolve(a);
|
|
1818
1958
|
if (!existsSync(p)) {
|
|
@@ -1824,9 +1964,37 @@ if (isMain) {
|
|
|
1824
1964
|
files.push(...discoverFiles(p));
|
|
1825
1965
|
} else {
|
|
1826
1966
|
files.push(p);
|
|
1967
|
+
explicitFiles.push(p);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
// A named file that carries no schema at all — a README, a tsconfig, a util —
|
|
1971
|
+
// produced "0 error(s) … across 1 file(s)" and exit 0. That reads as "checked
|
|
1972
|
+
// and clean" when nothing was checked, which is how a gate lies.
|
|
1973
|
+
const schemaless = explicitFiles.filter((p) => {
|
|
1974
|
+
if (/\.(entity|seed)\.ts$/.test(p)) return false;
|
|
1975
|
+
try {
|
|
1976
|
+
const text = readFileSync(p, "utf-8");
|
|
1977
|
+
return !/EntityModule\.forFeature|@Entity\s*\(|createSeed\s*\(/.test(text);
|
|
1978
|
+
} catch {
|
|
1979
|
+
return true;
|
|
1827
1980
|
}
|
|
1981
|
+
});
|
|
1982
|
+
if (schemaless.length && schemaless.length === explicitFiles.length && rootDir === null) {
|
|
1983
|
+
console.error(
|
|
1984
|
+
`validate-suppa-schema: none of the given files contain schema code ` +
|
|
1985
|
+
`(${schemaless.map((p) => displayPath(process.cwd(), p)).join(", ")}). ` +
|
|
1986
|
+
"Expected *.entity.ts, *.seed.ts, or a .ts file containing EntityModule.forFeature — " +
|
|
1987
|
+
"nothing was analyzed, so nothing was verified.",
|
|
1988
|
+
);
|
|
1989
|
+
process.exit(2);
|
|
1828
1990
|
}
|
|
1829
|
-
|
|
1991
|
+
// Same physical file spelled two ways is one file (see canonical()).
|
|
1992
|
+
const seenArgs = new Map();
|
|
1993
|
+
for (const f of files) {
|
|
1994
|
+
const key = canonical(f);
|
|
1995
|
+
if (!seenArgs.has(key)) seenArgs.set(key, f);
|
|
1996
|
+
}
|
|
1997
|
+
const dedupedFiles = [...seenArgs.values()];
|
|
1830
1998
|
if (dedupedFiles.length === 0) {
|
|
1831
1999
|
// Exit 0 here meant a mistyped root passed the close-out gate: SKILL.md
|
|
1832
2000
|
// makes that exit code the whole gate, so "0 error(s) across 0 file(s)"
|
|
@@ -1857,16 +2025,26 @@ if (isMain) {
|
|
|
1857
2025
|
strict &&
|
|
1858
2026
|
RULE_WARNINGS.includes(f.code) &&
|
|
1859
2027
|
(wholeRepo || !RULE_WARNINGS_NEEDING_WHOLE_REPO.includes(f.code));
|
|
2028
|
+
// A rule violation that --no-strict demoted is still a rule violation. Printing
|
|
2029
|
+
// it as a plain [warning] left no trace that the escape hatch was used, so a
|
|
2030
|
+
// green run under --no-strict was indistinguishable from a clean one.
|
|
2031
|
+
const demoted = (f) =>
|
|
2032
|
+
!strict &&
|
|
2033
|
+
RULE_WARNINGS.includes(f.code) &&
|
|
2034
|
+
(wholeRepo || !RULE_WARNINGS_NEEDING_WHOLE_REPO.includes(f.code));
|
|
1860
2035
|
for (const f of res.findings) {
|
|
1861
|
-
const level = blocks(f) ? "rule violation" : f.level;
|
|
2036
|
+
const level = blocks(f) ? "rule violation" : demoted(f) ? "rule violation, demoted" : f.level;
|
|
1862
2037
|
console.log(
|
|
1863
2038
|
`${displayPath(process.cwd(), f.file)}:${f.line}:${f.col} ${f.code} [${level}] ${f.message}`,
|
|
1864
2039
|
);
|
|
1865
2040
|
}
|
|
1866
2041
|
const blocked = res.findings.filter(blocks);
|
|
1867
|
-
const
|
|
2042
|
+
const demotedCount = res.findings.filter(demoted).length;
|
|
2043
|
+
const advisory = res.warnings.length - blocked.length - demotedCount;
|
|
1868
2044
|
console.log(
|
|
1869
|
-
`\n${res.errors.length} error(s), ${blocked.length} rule violation(s),
|
|
2045
|
+
`\n${res.errors.length} error(s), ${blocked.length} rule violation(s), ` +
|
|
2046
|
+
(demotedCount ? `${demotedCount} demoted by --no-strict, ` : "") +
|
|
2047
|
+
`${advisory} advisory warning(s) ` +
|
|
1870
2048
|
`across ${dedupedFiles.length} file(s) (option catalog: ${res.sdkSource}).`,
|
|
1871
2049
|
);
|
|
1872
2050
|
if (blocked.length) {
|
|
@@ -1875,5 +2053,11 @@ if (isMain) {
|
|
|
1875
2053
|
`Rule violations (${codes}) fail the gate. Fix them, or pass --no-strict to record them as warnings instead.`,
|
|
1876
2054
|
);
|
|
1877
2055
|
}
|
|
2056
|
+
if (demotedCount) {
|
|
2057
|
+
console.log(
|
|
2058
|
+
`NOT a clean run: ${demotedCount} authoring-rule violation(s) were demoted by --no-strict. ` +
|
|
2059
|
+
"Drop the flag to see the gate's real verdict.",
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
1878
2062
|
process.exit(res.errors.length + blocked.length > 0 ? 1 : 0);
|
|
1879
2063
|
}
|
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
import { __TargetEntity__ } from './__target-entity__.entity';
|
|
20
20
|
|
|
21
21
|
// Fixed value set? Declare a string enum + optional per-value titles map.
|
|
22
|
-
//
|
|
22
|
+
// A global name '__EntityName__.__field__' is how seeds and other entities
|
|
23
|
+
// reference these values — declare one ONLY if something does (rule 17).
|
|
23
24
|
export enum __Field__Enum {
|
|
24
25
|
Active = 'active',
|
|
25
26
|
Done = 'done',
|
|
@@ -89,13 +90,17 @@ export class __EntityName__ extends SystemBaseEntity {
|
|
|
89
90
|
// __backRefs__: __TargetEntity__[];
|
|
90
91
|
|
|
91
92
|
// Fixed choices — @Enum/@MultiEnum, NEVER @Column({ type: 'enum' }).
|
|
92
|
-
// LOCAL enum
|
|
93
|
-
// name <ClassName>.<propertyName>.
|
|
93
|
+
// LOCAL enum — the DEFAULT, and what most enum fields should be: no first
|
|
94
|
+
// argument, and the decorator derives the name <ClassName>.<propertyName>.
|
|
94
95
|
@Enum(__Field__Enum, __Field__Titles, { nullable: false })
|
|
95
96
|
__field__: __Field__Enum;
|
|
96
97
|
|
|
97
|
-
// GLOBAL enum — pass the name FIRST, and
|
|
98
|
-
// across entities or referenced from a seed
|
|
98
|
+
// GLOBAL enum — pass the name FIRST, and ONLY when the value set is shared
|
|
99
|
+
// across entities or referenced from a seed. NOTE: seed.template.ts writes
|
|
100
|
+
// `{ name: '__EntityName__.__field__', value: … }`, which IS such a
|
|
101
|
+
// reference — so if you keep that line in the seed, this field's enum is
|
|
102
|
+
// global and the name belongs here. Delete the seed's enum line, or use the
|
|
103
|
+
// declaration below; do not leave the pair half-and-half.
|
|
99
104
|
// @Enum('__EntityName__.__field__', __Field__Enum, __Field__Titles, { nullable: false })
|
|
100
105
|
// __field__: __Field__Enum;
|
|
101
106
|
|
|
@@ -18,7 +18,12 @@ export const __camelCasePlural__Seed = createSeed(EntityNamesEnum.__EntityName__
|
|
|
18
18
|
// Relation: reference by the TARGET's importKeyFields — NEVER numeric id.
|
|
19
19
|
__target__: { name: 'Default' },
|
|
20
20
|
|
|
21
|
-
// Enum: { name: '<global enum name>', value: '<enum value>' }.
|
|
21
|
+
// Enum: { name: '<global enum name>', value: '<enum value>' }.
|
|
22
|
+
// NAMING AN ENUM HERE MAKES IT GLOBAL (SKILL.md rule 17): the entity's
|
|
23
|
+
// @Enum must then pass that same name as its FIRST argument. If the enum
|
|
24
|
+
// belongs to one field only, drop this line and let the field's value be
|
|
25
|
+
// set by the user instead — do not name an enum the entity declares
|
|
26
|
+
// locally.
|
|
22
27
|
__field__: {
|
|
23
28
|
name: '__EntityName__.__field__',
|
|
24
29
|
value: __Field__Enum.Active,
|