@starci/eslint-canon-be 3.18.4 → 3.19.1
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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs-view.d.ts +5 -0
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/schema-authority.js +66 -2
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { machineKit, pascal } from './machine-ast.mjs';
|
|
3
|
-
import { treeOf } from './required-files.mjs';
|
|
4
|
-
import { DATABASE_DIR } from './connection-map.mjs';
|
|
5
|
-
import { collectRegistrations, isPerConnection, persistenceOfFactory } from './context-map.mjs';
|
|
6
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
7
|
-
/**
|
|
8
|
-
* R35 `schema-owner` (BE_SCHEMA_OWNER, BE-CONVENTION 1.4.6). Schema lives with the capability that owns the table:
|
|
9
|
-
*
|
|
10
|
-
* - a TypeORM `@Entity` class and a class implementing `MigrationInterface` sit in `persistence/entities/` and
|
|
11
|
-
* `persistence/migrations/` of a domain or platform capability (slot be.persistence), and nowhere else; a file in a
|
|
12
|
-
* folder named `entities` or `migrations` outside be.persistence is refused too;
|
|
13
|
-
* - `persistence/connection.ts` declares `<c>Entities` / `<c>Migrations`, the arrays the apps register; a capability has no
|
|
14
|
-
* `CONNECTION` alias (C0 lead decision 2026-09-30): its connection is the one those arrays are REGISTERED on, in the
|
|
15
|
-
* `entities` / `migrations` of a connection literal of `DatabaseModule.register` and of the cli app. The arrays are
|
|
16
|
-
* registered under exactly one connection across all apps, that connection is declared in hfs.json, and every
|
|
17
|
-
* `Inject<Conn>EntityManager()` used inside the capability is that same connection;
|
|
18
|
-
* - the capability's `index.ts` exports `<c>Entities` when it has entities and `<c>Migrations` when it has migrations
|
|
19
|
-
* (`<c>` the camelCase capability name), and no other name coming from `persistence/`;
|
|
20
|
-
* - a migration file is `<epochMs13>-<kebab-name>.ts`, holds a class `<Pascal><epochMs13>` and a `name` property equal to
|
|
21
|
-
* that class name, and has no unit spec beside it.
|
|
22
|
-
*
|
|
23
|
-
* Lite (persistence.md BE-PERSISTENCE-3, ruling lite-persistence-typeorm-entities) has entities and no be migration: the
|
|
24
|
-
* capability's `persistence/entities/index.ts` declares `<c>Entities`, its `index.ts` exports that one persistence name, and
|
|
25
|
-
* `platform/database/entities.ts` names it in `PRIMARY_ENTITIES`, the one list the app composition registers; there is a
|
|
26
|
-
* single primary connection, so the per-connection checks do not apply.
|
|
27
|
-
*/
|
|
28
|
-
export const SCHEMA_OWNER_RULE_IDS = ['BE_SCHEMA_OWNER'];
|
|
29
|
-
const RULE = 'BE_SCHEMA_OWNER';
|
|
30
|
-
const PERSISTENCE_SLOT = 'be.persistence';
|
|
31
|
-
const SCHEMA_FOLDERS = new Set(['entities', 'migrations']);
|
|
32
|
-
const MIGRATION_FILE = /^(\d{13})-([a-z0-9]+(?:-[a-z0-9]+)*)\.ts$/u;
|
|
33
|
-
/** The lite entity list every capability's `<c>Entities` is named in (BE-PERSISTENCE-3). */
|
|
34
|
-
const LITE_ENTITY_LIST = `${DATABASE_DIR}/entities.ts`;
|
|
35
|
-
const camel = (name) => { const text = pascal(name); return text.charAt(0).toLowerCase() + text.slice(1); };
|
|
36
|
-
function noteSchemaOwner(found, persistence, kind) {
|
|
37
|
-
const key = path.posix.dirname(persistence.root);
|
|
38
|
-
let entry = found.get(key);
|
|
39
|
-
if (!entry) {
|
|
40
|
-
entry = { name: persistence.capability, entities: false, migrations: false };
|
|
41
|
-
found.set(key, entry);
|
|
42
|
-
}
|
|
43
|
-
entry[kind] = true;
|
|
44
|
-
}
|
|
45
|
-
function reportSchemaFolders(tree, resolver, plain) {
|
|
46
|
-
for (const rel of [...tree.files].sort(byCodeUnit)) {
|
|
47
|
-
const classified = resolver.classifyPath(rel);
|
|
48
|
-
if (classified.status === 'no-slot' || !classified.slot?.startsWith('be.') || classified.slot === PERSISTENCE_SLOT)
|
|
49
|
-
continue;
|
|
50
|
-
const folder = rel.split('/').slice(0, -1).find(segment => SCHEMA_FOLDERS.has(segment));
|
|
51
|
-
if (folder)
|
|
52
|
-
plain(rel, `${rel} sits in a ${folder}/ folder outside the persistence of a capability; ${folder} live only in src/modules/{domain,platform}/<capability>/persistence/${folder}/ of the capability that owns the table.`, { folder });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function reportMigrationPaths(tree, persistenceOf, plain) {
|
|
56
|
-
for (const rel of [...tree.files].sort(byCodeUnit)) {
|
|
57
|
-
const persistence = persistenceOf(rel);
|
|
58
|
-
if (persistence?.folder !== 'migrations')
|
|
59
|
-
continue;
|
|
60
|
-
if (/\.spec\.[cm]?tsx?$/u.test(rel))
|
|
61
|
-
plain(rel, `${rel} is a unit spec of a migration; a migration has no spec, the e2e run over the same migrations is its proof. Delete it.`);
|
|
62
|
-
else if (!MIGRATION_FILE.test(persistence.below.at(-1) ?? '') || persistence.below.length !== 2)
|
|
63
|
-
plain(rel, `${rel} is not named <epochMs13>-<kebab-name>.ts (13 digits of epoch milliseconds, a dash, a kebab-case name) directly in persistence/migrations/.`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function isEntityDeclaration(kit, checker, statement) {
|
|
67
|
-
return kit.decorators(statement).some(decorator => {
|
|
68
|
-
const call = kit.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
69
|
-
return kit.isImportOf(checker, call, 'Entity', 'typeorm');
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function isMigrationDeclaration(kit, checker, statement) {
|
|
73
|
-
const heritage = (statement.heritageClauses ?? []).flatMap(clause => clause.types.map(type => type.expression));
|
|
74
|
-
return heritage.some(expression => kit.isImportOf(checker, expression, 'MigrationInterface', 'typeorm'));
|
|
75
|
-
}
|
|
76
|
-
function inspectEntityDeclaration(resolver, file, statement, persistence, found, report) {
|
|
77
|
-
// The table of a projection belongs to the projection that alone writes it: `<name>.projection-entity.ts` of slot be.projections.
|
|
78
|
-
const ownProjectionTable = resolver.classifyPath(file.rel).slot === 'be.projections' && file.rel.endsWith('.projection-entity.ts');
|
|
79
|
-
if (ownProjectionTable)
|
|
80
|
-
noteSchemaOwner(found, { root: path.posix.join(path.posix.dirname(file.rel), 'persistence'), capability: path.posix.basename(path.posix.dirname(file.rel)) }, 'entities');
|
|
81
|
-
else if (persistence?.folder !== 'entities')
|
|
82
|
-
report(file, statement.name, `Entity ${statement.name.text} is declared outside persistence/entities/ of a domain or platform capability; an entity lives with the capability that owns its table, in src/modules/{domain,platform}/<capability>/persistence/entities/<table>.entity.ts.`, { class: statement.name.text });
|
|
83
|
-
else
|
|
84
|
-
noteSchemaOwner(found, persistence, 'entities');
|
|
85
|
-
}
|
|
86
|
-
function inspectMigrationDeclaration(kit, file, statement, persistence, checker, found, report) {
|
|
87
|
-
const ts = kit.ts;
|
|
88
|
-
if (persistence?.folder !== 'migrations') {
|
|
89
|
-
report(file, statement.name, `Migration ${statement.name.text} is declared outside persistence/migrations/ of a domain or platform capability; a migration lives with the capability that owns the table, in persistence/migrations/<epochMs13>-<kebab-name>.ts.`, { class: statement.name.text });
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
noteSchemaOwner(found, persistence, 'migrations');
|
|
93
|
-
const match = MIGRATION_FILE.exec(path.posix.basename(file.rel));
|
|
94
|
-
if (!match)
|
|
95
|
-
return;
|
|
96
|
-
const [, epoch = '', kebab = ''] = match;
|
|
97
|
-
const expected = `${pascal(kebab)}${epoch}`;
|
|
98
|
-
if (statement.name.text !== expected)
|
|
99
|
-
report(file, statement.name, `Migration class ${statement.name.text} must be named ${expected}: the PascalCase of the file name followed by its 13-digit epoch, because TypeORM reads the timestamp from the class name.`, { class: statement.name.text, expected });
|
|
100
|
-
const nameProperty = statement.members.find((member) => ts.isPropertyDeclaration(member) && kit.propertyNameText(member.name) === 'name');
|
|
101
|
-
const nameValue = nameProperty?.initializer ? kit.stringValue(checker, nameProperty.initializer) : null;
|
|
102
|
-
if (nameValue !== statement.name.text)
|
|
103
|
-
report(file, nameProperty ?? statement.name, `Migration ${statement.name.text} must declare \`name = "${statement.name.text}"\`, equal to its class name; TypeORM records that value in its migrations table.`, { class: statement.name.text });
|
|
104
|
-
}
|
|
105
|
-
function inspectSchemaClass(scan, site, declaration) {
|
|
106
|
-
const { kit, found, counts, report } = scan;
|
|
107
|
-
const { file, persistence, checker } = site;
|
|
108
|
-
const ts = kit.ts;
|
|
109
|
-
if (!ts.isClassDeclaration(declaration) || !declaration.name)
|
|
110
|
-
return;
|
|
111
|
-
const statement = declaration; // reason: the guard above proved the class has a name
|
|
112
|
-
const isEntity = isEntityDeclaration(kit, checker, statement);
|
|
113
|
-
const isMigration = isMigrationDeclaration(kit, checker, statement);
|
|
114
|
-
if (isEntity) {
|
|
115
|
-
counts.entities += 1;
|
|
116
|
-
inspectEntityDeclaration(kit.resolver, file, statement, persistence, found, report);
|
|
117
|
-
}
|
|
118
|
-
if (!isMigration)
|
|
119
|
-
return;
|
|
120
|
-
counts.migrations += 1;
|
|
121
|
-
inspectMigrationDeclaration(kit, file, statement, persistence, checker, found, report);
|
|
122
|
-
}
|
|
123
|
-
function inspectSchemaFiles(input, kit, persistenceOf, found, report) {
|
|
124
|
-
const { graph } = input;
|
|
125
|
-
const counts = { entities: 0, migrations: 0 };
|
|
126
|
-
const scan = { kit, found, counts, report };
|
|
127
|
-
for (const file of graph.files.values()) {
|
|
128
|
-
const persistence = persistenceOf(file.rel);
|
|
129
|
-
const checker = kit.checkerOf(file.sourceFile);
|
|
130
|
-
for (const statement of file.sourceFile.statements)
|
|
131
|
-
inspectSchemaClass(scan, { file, persistence, checker }, statement);
|
|
132
|
-
}
|
|
133
|
-
return counts;
|
|
134
|
-
}
|
|
135
|
-
function reportRegistrationSites(registered, connections, resolver, report) {
|
|
136
|
-
for (const [key, { name, connections: sites }] of registered) {
|
|
137
|
-
for (const [connection, site] of sites) {
|
|
138
|
-
if (!connections.has(connection))
|
|
139
|
-
report(site.file, site.node, `The ${name} capability is registered on connection "${connection}", which hfs.json does not declare (declared: ${[...connections].sort(byCodeUnit).join(', ') || 'none'}); the tables of a capability live on one declared connection.`, { connection, capability: name });
|
|
140
|
-
}
|
|
141
|
-
if (sites.size > 1 && !isPerConnection(resolver, key, name)) {
|
|
142
|
-
const all = [...sites.keys()].sort(byCodeUnit).join(' and ');
|
|
143
|
-
for (const [connection, site] of [...sites].slice(1))
|
|
144
|
-
report(site.file, site.node, `The ${name} capability's entities and migrations are registered on connections ${all}; a capability's tables live on exactly one connection, so register its arrays under one connection across every app.`, { connection, capability: name });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/** The identifiers a file of the graph declares or names, for the lite list checks. */
|
|
149
|
-
function identifiersOf(ts, file) {
|
|
150
|
-
const names = new Set();
|
|
151
|
-
const visit = (node) => { if (ts.isIdentifier(node))
|
|
152
|
-
names.add(node.text); ts.forEachChild(node, visit); };
|
|
153
|
-
if (file)
|
|
154
|
-
visit(file.sourceFile);
|
|
155
|
-
return names;
|
|
156
|
-
}
|
|
157
|
-
/** The names of the variables a file's top-level variable statements declare (undefined for a destructuring pattern). */
|
|
158
|
-
function variableNames(ts, file) {
|
|
159
|
-
return new Set((file?.sourceFile.statements.filter(ts.isVariableStatement).flatMap(statement => statement.declarationList.declarations) ?? []).map(item => ts.isIdentifier(item.name) ? item.name.text : undefined));
|
|
160
|
-
}
|
|
161
|
-
function reportLiteEntityArrays(key, kinds, graph, ts, plain) {
|
|
162
|
-
const wanted = `${camel(kinds.name)}Entities`;
|
|
163
|
-
const listFile = `${key}/persistence/entities/index.ts`;
|
|
164
|
-
const declared = variableNames(ts, graph.files.get(listFile));
|
|
165
|
-
if (!declared.has(wanted))
|
|
166
|
-
plain(listFile, `${listFile} must export ${wanted}, the entities of the ${kinds.name} capability, the one file that lists them.`, { capability: kinds.name });
|
|
167
|
-
if (!identifiersOf(ts, graph.files.get(LITE_ENTITY_LIST)).has(wanted))
|
|
168
|
-
plain(LITE_ENTITY_LIST, `The ${kinds.name} capability has entities but ${LITE_ENTITY_LIST} does not name ${wanted} in PRIMARY_ENTITIES; list it there by name, the one list the app composition registers.`, { capability: kinds.name });
|
|
169
|
-
}
|
|
170
|
-
function reportDeclaredPersistenceArrays(key, kinds, registered, graph, ts, plain) {
|
|
171
|
-
if (!registered.get(key)?.connections.size)
|
|
172
|
-
plain(`${key}/persistence/connection.ts`, `The ${kinds.name} capability has entities or migrations but no app registers them; add ${camel(kinds.name)}Entities and ${camel(kinds.name)}Migrations to a connection of DatabaseModule.register and of the cli app.`, { capability: kinds.name });
|
|
173
|
-
const declared = variableNames(ts, graph.files.get(`${key}/persistence/connection.ts`));
|
|
174
|
-
for (const [kind, has] of [['Entities', kinds.entities], ['Migrations', kinds.migrations]]) {
|
|
175
|
-
if (has && !declared.has(`${camel(kinds.name)}${kind}`))
|
|
176
|
-
plain(`${key}/persistence/connection.ts`, `${key}/persistence/connection.ts must export ${camel(kinds.name)}${kind}, the ${kind.toLowerCase()} of the ${kinds.name} capability, the one file that lists them for the apps.`, { capability: kinds.name });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function reportEntityManagerUse(kit, capability, file, checker, report) {
|
|
180
|
-
const { kinds, only, home, connections } = capability;
|
|
181
|
-
kit.walk(file.sourceFile, (node) => {
|
|
182
|
-
if (!kit.ts.isCallExpression(node))
|
|
183
|
-
return;
|
|
184
|
-
const declaration = kit.declarationsOf(checker, node.expression)[0];
|
|
185
|
-
const rel = declaration ? kit.graphPath(declaration) : null;
|
|
186
|
-
const used = rel ? [...connections].find(name => rel === `${DATABASE_DIR}/${name}.decorators.ts`) : null;
|
|
187
|
-
if (used && only.size > 1 && !only.has(used))
|
|
188
|
-
report(file, node, `${file.rel} injects the entity manager of connection ${used}, but the ${kinds.name} capability's tables are registered on ${[...only.keys()].sort(byCodeUnit).join(' and ')}; register the capability on ${used} too or inject one of its connections.`, { connection: used, expected: [...only.keys()].sort(byCodeUnit).join(','), capability: kinds.name });
|
|
189
|
-
else if (used && only.size === 1 && used !== home)
|
|
190
|
-
report(file, node, `${file.rel} injects the entity manager of connection ${used}, but the ${kinds.name} capability's tables are registered on ${home}; a capability reads only its own database, so use Inject${pascal(home)}EntityManager or move the tables.`, { connection: used, expected: home, capability: kinds.name });
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
function reportEntityManagerUses(input, kit, key, kinds, only, connections, report) {
|
|
194
|
-
const capability = { kinds, only, home: [...only.keys()][0] ?? '', connections };
|
|
195
|
-
for (const file of input.graph.files.values()) {
|
|
196
|
-
if (!file.rel.startsWith(`${key}/`))
|
|
197
|
-
continue;
|
|
198
|
-
reportEntityManagerUse(kit, capability, file, kit.checkerOf(file.sourceFile), report);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function reportFoundCapability(input, kit, key, kinds, view) {
|
|
202
|
-
const { registered, connections, plain, report } = view;
|
|
203
|
-
const { graph } = input;
|
|
204
|
-
const { resolver } = kit;
|
|
205
|
-
if (view.lite) {
|
|
206
|
-
reportLiteEntityArrays(key, kinds, graph, kit.ts, plain);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
reportDeclaredPersistenceArrays(key, kinds, registered, graph, kit.ts, plain);
|
|
210
|
-
const only = registered.get(key)?.connections;
|
|
211
|
-
if (!only || only.size < 1)
|
|
212
|
-
return;
|
|
213
|
-
// A per-connection platform capability (event-bus, jobs) lives on every connection that uses it; any other on exactly one (reported above).
|
|
214
|
-
const perConnection = only.size > 1 && isPerConnection(resolver, key, kinds.name);
|
|
215
|
-
if (only.size > 1 && !perConnection)
|
|
216
|
-
return;
|
|
217
|
-
reportEntityManagerUses(input, kit, key, kinds, only, connections, report);
|
|
218
|
-
}
|
|
219
|
-
function reportFoundCapabilities(input, kit, found, registered, connections, plain, report) {
|
|
220
|
-
const view = { registered, connections, plain, report, lite: kit.resolver.repo?.edition === 'lite' };
|
|
221
|
-
for (const [key, kinds] of found)
|
|
222
|
-
reportFoundCapability(input, kit, key, kinds, view);
|
|
223
|
-
}
|
|
224
|
-
function reportPersistenceExport(capabilityRoot, index, statement, element, wanted, report) {
|
|
225
|
-
const from = statement.moduleSpecifier?.text; // reason: an export-from specifier is a string literal
|
|
226
|
-
const inPersistence = from?.startsWith('.') && path.posix.join(capabilityRoot, from).split('/').includes('persistence');
|
|
227
|
-
if (inPersistence && !Object.values(wanted).includes(element.name.text)) {
|
|
228
|
-
report(index, element, `${element.name.text} is exported from persistence/; the persistence of a capability is exposed only as ${Object.values(wanted).join(' and ')}.`, { name: element.name.text });
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function addStatementExports(kit, capabilityRoot, index, statement, wanted, report, exported) {
|
|
232
|
-
const ts = kit.ts;
|
|
233
|
-
if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
234
|
-
for (const element of statement.exportClause.elements) {
|
|
235
|
-
exported.add(element.name.text);
|
|
236
|
-
reportPersistenceExport(capabilityRoot, index, statement, element, wanted, report);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else if (ts.isVariableStatement(statement) && kit.isExported(statement)) {
|
|
240
|
-
for (const declaration of statement.declarationList.declarations)
|
|
241
|
-
if (ts.isIdentifier(declaration.name))
|
|
242
|
-
exported.add(declaration.name.text);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function collectIndexExports(kit, capabilityRoot, index, wanted, report) {
|
|
246
|
-
const exported = new Set();
|
|
247
|
-
for (const statement of index.sourceFile.statements)
|
|
248
|
-
addStatementExports(kit, capabilityRoot, index, statement, wanted, report, exported);
|
|
249
|
-
return exported;
|
|
250
|
-
}
|
|
251
|
-
function reportCapabilityIndex(input, kit, capabilityRoot, kinds, report) {
|
|
252
|
-
const { graph } = input;
|
|
253
|
-
const index = graph.files.get(`${capabilityRoot}/index.ts`);
|
|
254
|
-
if (!index)
|
|
255
|
-
return;
|
|
256
|
-
const lite = kit.resolver.repo?.edition === 'lite';
|
|
257
|
-
const wanted = lite ? { Entities: `${camel(kinds.name)}Entities` } : { Entities: `${camel(kinds.name)}Entities`, Migrations: `${camel(kinds.name)}Migrations` };
|
|
258
|
-
const exported = collectIndexExports(kit, capabilityRoot, index, wanted, report);
|
|
259
|
-
for (const [kind, has] of [['Entities', kinds.entities], ['Migrations', kinds.migrations]]) {
|
|
260
|
-
if (has && wanted[kind] && !exported.has(wanted[kind]))
|
|
261
|
-
report(index, index.sourceFile, `${capabilityRoot}/index.ts must export ${wanted[kind]}, the ${kind.toLowerCase()} of the capability; apps concatenate them per connection into DatabaseModule.register.`, { capability: kinds.name, expected: wanted[kind] });
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function reportCapabilityIndexes(input, kit, found, report) {
|
|
265
|
-
// The owner's index exports `<c>Entities` and `<c>Migrations`, the only persistence names.
|
|
266
|
-
for (const [capabilityRoot, kinds] of found)
|
|
267
|
-
reportCapabilityIndex(input, kit, capabilityRoot, kinds, report);
|
|
268
|
-
}
|
|
269
|
-
export function checkSchemaOwner(input) {
|
|
270
|
-
const { config, graph } = input;
|
|
271
|
-
const kit = machineKit(input);
|
|
272
|
-
const { resolver } = kit;
|
|
273
|
-
const connections = new Set(resolver.repo.connections.map((item) => item.name));
|
|
274
|
-
const violations = [];
|
|
275
|
-
const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
276
|
-
const plain = (rel, message, extra = {}) => violations.push({ ruleId: RULE, path: rel, line: 1, column: 1, message, ...extra });
|
|
277
|
-
const persistenceOf = persistenceOfFactory(resolver);
|
|
278
|
-
const tree = treeOf(config.root);
|
|
279
|
-
reportSchemaFolders(tree, resolver, plain);
|
|
280
|
-
reportMigrationPaths(tree, persistenceOf, plain);
|
|
281
|
-
const found = new Map(); // capability root -> {name, entities, migrations}
|
|
282
|
-
const counts = inspectSchemaFiles(input, kit, persistenceOf, found, report);
|
|
283
|
-
const { registered, registrations } = collectRegistrations({ kit, graph, persistenceOf });
|
|
284
|
-
reportRegistrationSites(registered, connections, resolver, report);
|
|
285
|
-
reportFoundCapabilities(input, kit, found, registered, connections, plain, report);
|
|
286
|
-
reportCapabilityIndexes(input, kit, found, report);
|
|
287
|
-
return { violations, coverage: { status: 'checked', entities: counts.entities, migrations: counts.migrations, capabilities: found.size, connections: connections.size, registrations } };
|
|
288
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { sourceLocation } from '../../lib/ts-ast.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* The front end serves no API (owner ruling 2026-10-13, both editions, every app): it calls the back end through Apollo GraphQL and
|
|
4
|
-
* axios in modules/api and never runs server code of its own.
|
|
5
|
-
*
|
|
6
|
-
* - FE_SERVER_ACTION_FORBIDDEN: a `"use server"` directive anywhere in a front-end source file, in the file's directive prologue
|
|
7
|
-
* (a Server Action module) or in the prologue of any function body (an inline Server Action), apps and packages alike;
|
|
8
|
-
* - FE_ROUTE_HANDLER_FORBIDDEN: a route handler (`route.ts`, `route.js` and their module variants) under `apps/<app>/src/app/` other than the
|
|
9
|
-
* liveness probe `health/live/route.ts`.
|
|
10
|
-
*
|
|
11
|
-
* The check is provider-independent: it runs for every front-end repository.
|
|
12
|
-
*/
|
|
13
|
-
export const SERVER_ACTION_RULE_IDS = Object.freeze(['FE_SERVER_ACTION_FORBIDDEN', 'FE_ROUTE_HANDLER_FORBIDDEN']);
|
|
14
|
-
const SERVER_ACTION = 'FE_SERVER_ACTION_FORBIDDEN';
|
|
15
|
-
const ROUTE_HANDLER = 'FE_ROUTE_HANDLER_FORBIDDEN';
|
|
16
|
-
const ROUTE_FILE = /^apps\/([^/]+)\/src\/app\/(?:.+\/)?route\.[cm]?[jt]s$/u;
|
|
17
|
-
const isDirective = (ts, statement) => ts.isExpressionStatement(statement) && ts.isStringLiteral(statement.expression);
|
|
18
|
-
/** The statement nodes of a directive prologue: the leading string-literal expression statements. */
|
|
19
|
-
function prologue(ts, statements) {
|
|
20
|
-
const directives = [];
|
|
21
|
-
for (const statement of statements ?? []) {
|
|
22
|
-
if (!isDirective(ts, statement))
|
|
23
|
-
break;
|
|
24
|
-
directives.push(statement);
|
|
25
|
-
}
|
|
26
|
-
return directives;
|
|
27
|
-
}
|
|
28
|
-
const useServerIn = (ts, statements) => prologue(ts, statements).find(statement => statement.expression.text === 'use server') ?? null;
|
|
29
|
-
/** Every `"use server"` directive of one source file: the file-level one and each function-level one. */
|
|
30
|
-
function serverDirectives(ts, sourceFile) {
|
|
31
|
-
const found = [];
|
|
32
|
-
const fileLevel = useServerIn(ts, sourceFile.statements);
|
|
33
|
-
if (fileLevel)
|
|
34
|
-
found.push({ node: fileLevel, level: 'file' });
|
|
35
|
-
const visit = (node) => {
|
|
36
|
-
// a function with a block body: declaration, expression, arrow, method, constructor or accessor
|
|
37
|
-
if (ts.isFunctionLike(node) && 'body' in node && node.body && ts.isBlock(node.body)) {
|
|
38
|
-
const inline = useServerIn(ts, node.body.statements);
|
|
39
|
-
if (inline)
|
|
40
|
-
found.push({ node: inline, level: 'function' });
|
|
41
|
-
}
|
|
42
|
-
ts.forEachChild(node, visit);
|
|
43
|
-
};
|
|
44
|
-
ts.forEachChild(sourceFile, visit);
|
|
45
|
-
return found;
|
|
46
|
-
}
|
|
47
|
-
function serverActionViolations(ts, file) {
|
|
48
|
-
return serverDirectives(ts, file.sourceFile).map(({ node, level }) => ({
|
|
49
|
-
ruleId: SERVER_ACTION, path: file.rel, ...sourceLocation(file.sourceFile, node), level,
|
|
50
|
-
message: `${file.rel} declares a ${level}-level "use server" directive: the front end runs no Server Action. Call the back end through a modules/api GraphQL operation (or a rest call) from an SWR hook, and move the server work into a be feature.`,
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
function routeHandlerViolation(file) {
|
|
54
|
-
const match = ROUTE_FILE.exec(file.rel);
|
|
55
|
-
if (!match)
|
|
56
|
-
return null;
|
|
57
|
-
if (file.rel === `apps/${match[1]}/src/app/health/live/route.ts`)
|
|
58
|
-
return null;
|
|
59
|
-
return {
|
|
60
|
-
ruleId: ROUTE_HANDLER, path: file.rel, line: 1, column: 1,
|
|
61
|
-
message: `${file.rel} is a front-end route handler outside health/live/route.ts: the front end serves no API. Webhooks, cron, public APIs and third-party callbacks belong to be features; the browser reaches the back end through modules/api.`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/** The FE machine check of both bans over every source file of the front-end program. */
|
|
65
|
-
export function checkServerActions({ graph, context }) {
|
|
66
|
-
const ts = context.ts;
|
|
67
|
-
const violations = [];
|
|
68
|
-
let routes = 0;
|
|
69
|
-
for (const file of graph.files.values()) {
|
|
70
|
-
violations.push(...serverActionViolations(ts, file));
|
|
71
|
-
const route = routeHandlerViolation(file);
|
|
72
|
-
if (ROUTE_FILE.test(file.rel))
|
|
73
|
-
routes += 1;
|
|
74
|
-
if (route)
|
|
75
|
-
violations.push(route);
|
|
76
|
-
}
|
|
77
|
-
return { violations, coverage: { status: 'checked', files: graph.files.size, routes } };
|
|
78
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// side-boundary.mjs - what counts as an import that leaves a side of an app (ARCH_INTERNAL_IMPORT_OUTSIDE).
|
|
2
|
-
// A side (be/ or fe/) imports nothing of the app outside itself: the root holds no source and the other side is another program; a
|
|
3
|
-
// declared read of the OTHER side (be/contracts/) is codegen input, never an import. A declared read of a tree the APP ROOT owns
|
|
4
|
-
// (db/types/, sides.<side>.reads of the slot manifest) is the one thing both sides do import: the generated database types.
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { isInside, slash } from './config.mjs';
|
|
7
|
-
const OTHER_SIDE = /^(be|fe)\//;
|
|
8
|
-
/** True when `target` (an absolute path) lies in a tree of the app root that the side declares it reads (`reads` of the side declaration). */
|
|
9
|
-
const readsAppTree = (config, target) => (config.hfs?.repo?.reads ?? [])
|
|
10
|
-
.some((read) => !OTHER_SIDE.test(read) && isInside(path.join(config.packageRoot, read), target));
|
|
11
|
-
/** Whether an import of `target` leaves the side the machine judges (config.root) for the app (config.packageRoot), declared app-root reads excepted. */
|
|
12
|
-
export const crossesSide = (config, target) => config.packageRoot !== undefined && config.packageRoot !== config.root
|
|
13
|
-
&& isInside(config.packageRoot, target) && !isInside(config.root, target) && !slash(target).includes('/node_modules/') && !readsAppTree(config, target);
|