@starci/eslint-canon-fe 9.5.23 → 9.6.2

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.
Files changed (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/docs/button-intent.md +1 -1
  3. package/package.json +1 -1
  4. package/runtime/bundle.json +192 -0
  5. package/runtime/engine/by-code-unit.mjs +6 -6
  6. package/runtime/engine/model-config.mjs +98 -76
  7. package/runtime/engine/orca-config.mjs +22 -17
  8. package/runtime/engine/release-config.mjs +22 -18
  9. package/runtime/engine/removed-vocabulary.mjs +21 -20
  10. package/runtime/engine/resources-config.mjs +42 -35
  11. package/runtime/engine/runtime-root.mjs +11 -13
  12. package/runtime/engine/secrets.mjs +170 -102
  13. package/runtime/engine/sonar-config.mjs +16 -13
  14. package/runtime/engine/temp-root.mjs +3 -9
  15. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -4,7 +4,6 @@ import { treeOf } from './required-files.mjs';
4
4
  import { DATABASE_DIR } from './connection-map.mjs';
5
5
  import { collectRegistrations, isPerConnection, persistenceOfFactory } from './context-map.mjs';
6
6
  import { byCodeUnit } from '../../lib/list.mjs';
7
-
8
7
  /**
9
8
  * R35 `schema-owner` (BE_SCHEMA_OWNER, BE-CONVENTION 1.4.6). Schema lives with the capability that owns the table:
10
9
  *
@@ -27,237 +26,263 @@ import { byCodeUnit } from '../../lib/list.mjs';
27
26
  * single primary connection, so the per-connection checks do not apply.
28
27
  */
29
28
  export const SCHEMA_OWNER_RULE_IDS = ['BE_SCHEMA_OWNER'];
30
-
31
29
  const RULE = 'BE_SCHEMA_OWNER';
32
30
  const PERSISTENCE_SLOT = 'be.persistence';
33
31
  const SCHEMA_FOLDERS = new Set(['entities', 'migrations']);
34
32
  const MIGRATION_FILE = /^(\d{13})-([a-z0-9]+(?:-[a-z0-9]+)*)\.ts$/u;
35
33
  /** The lite entity list every capability's `<c>Entities` is named in (BE-PERSISTENCE-3). */
36
34
  const LITE_ENTITY_LIST = `${DATABASE_DIR}/entities.ts`;
37
- const camel = name => { const text = pascal(name); return text[0].toLowerCase() + text.slice(1); };
38
-
35
+ const camel = (name) => { const text = pascal(name); return text.charAt(0).toLowerCase() + text.slice(1); };
39
36
  function noteSchemaOwner(found, persistence, kind) {
40
- const key = path.posix.dirname(persistence.root);
41
- if (!found.has(key)) found.set(key, { name: persistence.capability, entities: false, migrations: false });
42
- found.get(key)[kind] = true;
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;
43
44
  }
44
-
45
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) continue;
49
- const folder = rel.split('/').slice(0, -1).find(segment => SCHEMA_FOLDERS.has(segment));
50
- if (folder) 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 });
51
- }
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
+ }
52
54
  }
53
-
54
55
  function reportMigrationPaths(tree, persistenceOf, plain) {
55
- for (const rel of [...tree.files].sort(byCodeUnit)) {
56
- const persistence = persistenceOf(rel);
57
- if (persistence?.folder !== 'migrations') continue;
58
- if (/\.spec\.[cm]?tsx?$/u.test(rel)) 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.`);
59
- else if (!MIGRATION_FILE.test(persistence.below.at(-1)) || persistence.below.length !== 2) 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/.`);
60
- }
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
+ }
61
65
  }
62
-
63
66
  function isEntityDeclaration(kit, checker, statement) {
64
- return kit.decorators(statement).some(decorator => {
65
- const call = kit.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
66
- return kit.isImportOf(checker, call, 'Entity', 'typeorm');
67
- });
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
+ });
68
71
  }
69
-
70
72
  function isMigrationDeclaration(kit, checker, statement) {
71
- const heritage = (statement.heritageClauses ?? []).flatMap(clause => clause.types.map(type => type.expression));
72
- return heritage.some(expression => kit.isImportOf(checker, expression, 'MigrationInterface', 'typeorm'));
73
+ const heritage = (statement.heritageClauses ?? []).flatMap(clause => clause.types.map(type => type.expression));
74
+ return heritage.some(expression => kit.isImportOf(checker, expression, 'MigrationInterface', 'typeorm'));
73
75
  }
74
-
75
76
  function inspectEntityDeclaration(resolver, file, statement, persistence, found, report) {
76
- // The table of a projection belongs to the projection that alone writes it: `<name>.projection-entity.ts` of slot be.projections.
77
- const ownProjectionTable = resolver.classifyPath(file.rel).slot === 'be.projections' && file.rel.endsWith('.projection-entity.ts');
78
- if (ownProjectionTable) noteSchemaOwner(found, { root: path.posix.join(path.posix.dirname(file.rel), 'persistence'), capability: path.posix.basename(path.posix.dirname(file.rel)) }, 'entities');
79
- else if (persistence?.folder !== 'entities') 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 });
80
- else noteSchemaOwner(found, persistence, 'entities');
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');
81
85
  }
82
-
83
86
  function inspectMigrationDeclaration(kit, file, statement, persistence, checker, found, report) {
84
- if (persistence?.folder !== 'migrations') {
85
- 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 });
86
- return;
87
- }
88
- noteSchemaOwner(found, persistence, 'migrations');
89
- const match = MIGRATION_FILE.exec(path.posix.basename(file.rel));
90
- if (!match) return;
91
- const expected = `${pascal(match[2])}${match[1]}`;
92
- if (statement.name.text !== expected) 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 });
93
- const nameProperty = statement.members.find(member => kit.ts.isPropertyDeclaration(member) && kit.propertyNameText(member.name) === 'name');
94
- const nameValue = nameProperty?.initializer ? kit.stringValue(checker, nameProperty.initializer) : null;
95
- if (nameValue !== statement.name.text) 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 });
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 });
96
104
  }
97
-
98
- function inspectSchemaClass(scan, site, statement) {
99
- const { kit, found, counts, report } = scan;
100
- const { file, persistence, checker } = site;
101
- if (!kit.ts.isClassDeclaration(statement) || !statement.name) return;
102
- const isEntity = isEntityDeclaration(kit, checker, statement);
103
- const isMigration = isMigrationDeclaration(kit, checker, statement);
104
- if (isEntity) {
105
- counts.entities += 1;
106
- inspectEntityDeclaration(kit.resolver, file, statement, persistence, found, report);
107
- }
108
- if (!isMigration) return;
109
- counts.migrations += 1;
110
- inspectMigrationDeclaration(kit, file, statement, persistence, checker, found, report);
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);
111
122
  }
112
-
113
123
  function inspectSchemaFiles(input, kit, persistenceOf, found, report) {
114
- const { graph } = input;
115
- const counts = { entities: 0, migrations: 0 };
116
- const scan = { kit, found, counts, report };
117
- for (const file of graph.files.values()) {
118
- const persistence = persistenceOf(file.rel);
119
- const checker = kit.checkerOf(file.sourceFile);
120
- for (const statement of file.sourceFile.statements) inspectSchemaClass(scan, { file, persistence, checker }, statement);
121
- }
122
- return counts;
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;
123
134
  }
124
-
125
135
  function reportRegistrationSites(registered, connections, resolver, report) {
126
- for (const [key, { name, connections: sites }] of registered) {
127
- for (const [connection, site] of sites) {
128
- if (!connections.has(connection)) 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 });
129
- }
130
- if (sites.size > 1 && !isPerConnection(resolver, key, name)) {
131
- const all = [...sites.keys()].sort(byCodeUnit).join(' and ');
132
- for (const [connection, site] of [...sites].slice(1)) 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 });
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
+ }
133
146
  }
134
- }
135
147
  }
136
-
137
148
  /** The identifiers a file of the graph declares or names, for the lite list checks. */
138
149
  function identifiersOf(ts, file) {
139
- const names = new Set();
140
- const visit = node => { if (ts.isIdentifier(node)) names.add(node.text); ts.forEachChild(node, visit); };
141
- if (file) visit(file.sourceFile);
142
- return names;
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));
143
160
  }
144
-
145
161
  function reportLiteEntityArrays(key, kinds, graph, ts, plain) {
146
- const wanted = `${camel(kinds.name)}Entities`;
147
- const listFile = `${key}/persistence/entities/index.ts`;
148
- const declared = new Set((graph.files.get(listFile)?.sourceFile.statements.filter(ts.isVariableStatement).flatMap(statement => statement.declarationList.declarations) ?? []).map(item => item.name.text));
149
- if (!declared.has(wanted)) plain(listFile, `${listFile} must export ${wanted}, the entities of the ${kinds.name} capability, the one file that lists them.`, { capability: kinds.name });
150
- if (!identifiersOf(ts, graph.files.get(LITE_ENTITY_LIST)).has(wanted)) 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 });
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 });
151
169
  }
152
-
153
170
  function reportDeclaredPersistenceArrays(key, kinds, registered, graph, ts, plain) {
154
- if (!registered.get(key)?.connections.size) 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 });
155
- const connectionFile = graph.files.get(`${key}/persistence/connection.ts`);
156
- const declared = new Set((connectionFile?.sourceFile.statements.filter(ts.isVariableStatement).flatMap(statement => statement.declarationList.declarations) ?? []).map(item => item.name.text));
157
- for (const [kind, has] of [['Entities', kinds.entities], ['Migrations', kinds.migrations]]) {
158
- if (has && !declared.has(`${camel(kinds.name)}${kind}`)) 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 });
159
- }
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
+ }
160
178
  }
161
-
162
179
  function reportEntityManagerUse(kit, capability, file, checker, report) {
163
- const { kinds, only, home, connections } = capability;
164
- kit.walk(file.sourceFile, node => {
165
- if (!kit.ts.isCallExpression(node)) return;
166
- const declaration = kit.declarationsOf(checker, node.expression)[0];
167
- const rel = declaration ? kit.graphPath(declaration) : null;
168
- const used = rel ? [...connections].find(name => rel === `${DATABASE_DIR}/${name}.decorators.ts`) : null;
169
- if (used && only.size > 1 && !only.has(used)) 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 });
170
- else if (used && only.size === 1 && used !== home) 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 });
171
- });
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
+ });
172
192
  }
173
-
174
193
  function reportEntityManagerUses(input, kit, key, kinds, only, connections, report) {
175
- const capability = { kinds, only, home: [...only.keys()][0], connections };
176
- for (const file of input.graph.files.values()) {
177
- if (!file.rel.startsWith(`${key}/`)) continue;
178
- reportEntityManagerUse(kit, capability, file, kit.checkerOf(file.sourceFile), report);
179
- }
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
+ }
180
200
  }
181
-
182
201
  function reportFoundCapability(input, kit, key, kinds, view) {
183
- const { registered, connections, plain, report } = view;
184
- const { graph } = input;
185
- const { resolver } = kit;
186
- if (view.lite) { reportLiteEntityArrays(key, kinds, graph, kit.ts, plain); return; }
187
- reportDeclaredPersistenceArrays(key, kinds, registered, graph, kit.ts, plain);
188
- const only = registered.get(key)?.connections;
189
- if (!only || only.size < 1) return;
190
- // A per-connection platform capability (event-bus, jobs) lives on every connection that uses it; any other on exactly one (reported above).
191
- const perConnection = only.size > 1 && isPerConnection(resolver, key, kinds.name);
192
- if (only.size > 1 && !perConnection) return;
193
- reportEntityManagerUses(input, kit, key, kinds, only, connections, report);
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);
194
218
  }
195
-
196
219
  function reportFoundCapabilities(input, kit, found, registered, connections, plain, report) {
197
- const view = { registered, connections, plain, report, lite: kit.resolver.repo?.edition === 'lite' };
198
- for (const [key, kinds] of found) reportFoundCapability(input, kit, key, kinds, view);
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);
199
223
  }
200
-
201
224
  function reportPersistenceExport(capabilityRoot, index, statement, element, wanted, report) {
202
- const from = statement.moduleSpecifier?.text;
203
- const inPersistence = from?.startsWith('.') && path.posix.join(capabilityRoot, from).split('/').includes('persistence');
204
- if (inPersistence && !Object.values(wanted).includes(element.name.text)) {
205
- 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 });
206
- }
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
+ }
207
230
  }
208
-
209
231
  function addStatementExports(kit, capabilityRoot, index, statement, wanted, report, exported) {
210
- const { ts } = kit;
211
- if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
212
- for (const element of statement.exportClause.elements) {
213
- exported.add(element.name.text);
214
- reportPersistenceExport(capabilityRoot, index, statement, element, wanted, report);
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);
215
243
  }
216
- } else if (ts.isVariableStatement(statement) && kit.isExported(statement)) {
217
- for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name)) exported.add(declaration.name.text);
218
- }
219
244
  }
220
-
221
245
  function collectIndexExports(kit, capabilityRoot, index, wanted, report) {
222
- const exported = new Set();
223
- for (const statement of index.sourceFile.statements) addStatementExports(kit, capabilityRoot, index, statement, wanted, report, exported);
224
- return exported;
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;
225
250
  }
226
-
227
251
  function reportCapabilityIndex(input, kit, capabilityRoot, kinds, report) {
228
- const { graph } = input;
229
- const index = graph.files.get(`${capabilityRoot}/index.ts`);
230
- if (!index) return;
231
- const lite = kit.resolver.repo?.edition === 'lite';
232
- const wanted = lite ? { Entities: `${camel(kinds.name)}Entities` } : { Entities: `${camel(kinds.name)}Entities`, Migrations: `${camel(kinds.name)}Migrations` };
233
- const exported = collectIndexExports(kit, capabilityRoot, index, wanted, report);
234
- for (const [kind, has] of [['Entities', kinds.entities], ['Migrations', kinds.migrations]]) {
235
- if (has && wanted[kind] && !exported.has(wanted[kind])) 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] });
236
- }
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
+ }
237
263
  }
238
-
239
264
  function reportCapabilityIndexes(input, kit, found, report) {
240
- // The owner's index exports `<c>Entities` and `<c>Migrations`, the only persistence names.
241
- for (const [capabilityRoot, kinds] of found) reportCapabilityIndex(input, kit, capabilityRoot, kinds, 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);
242
268
  }
243
-
244
269
  export function checkSchemaOwner(input) {
245
- const { config, graph } = input;
246
- const kit = machineKit(input);
247
- const { resolver } = kit;
248
- const connections = new Set(resolver.repo.connections.map(item => item.name));
249
- const violations = [];
250
- const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
251
- const plain = (rel, message, extra = {}) => violations.push({ ruleId: RULE, path: rel, line: 1, column: 1, message, ...extra });
252
- const persistenceOf = persistenceOfFactory(resolver);
253
- const tree = treeOf(config.root);
254
- reportSchemaFolders(tree, resolver, plain);
255
- reportMigrationPaths(tree, persistenceOf, plain);
256
- const found = new Map(); // capability root -> {name, entities, migrations}
257
- const counts = inspectSchemaFiles(input, kit, persistenceOf, found, report);
258
- const { registered, registrations } = collectRegistrations({ kit, graph, persistenceOf });
259
- reportRegistrationSites(registered, connections, resolver, report);
260
- reportFoundCapabilities(input, kit, found, registered, connections, plain, report);
261
- reportCapabilityIndexes(input, kit, found, report);
262
- return { violations, coverage: { status: 'checked', entities: counts.entities, migrations: counts.migrations, capabilities: found.size, connections: connections.size, registrations } };
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 } };
263
288
  }
@@ -1,5 +1,4 @@
1
1
  import { sourceLocation } from '../../lib/ts-ast.mjs';
2
-
3
2
  /**
4
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
5
4
  * axios in modules/api and never runs server code of its own.
@@ -12,67 +11,68 @@ import { sourceLocation } from '../../lib/ts-ast.mjs';
12
11
  * The check is provider-independent: it runs for every front-end repository.
13
12
  */
14
13
  export const SERVER_ACTION_RULE_IDS = Object.freeze(['FE_SERVER_ACTION_FORBIDDEN', 'FE_ROUTE_HANDLER_FORBIDDEN']);
15
-
16
14
  const SERVER_ACTION = 'FE_SERVER_ACTION_FORBIDDEN';
17
15
  const ROUTE_HANDLER = 'FE_ROUTE_HANDLER_FORBIDDEN';
18
16
  const ROUTE_FILE = /^apps\/([^/]+)\/src\/app\/(?:.+\/)?route\.[cm]?[jt]s$/u;
19
-
17
+ const isDirective = (ts, statement) => ts.isExpressionStatement(statement) && ts.isStringLiteral(statement.expression);
20
18
  /** The statement nodes of a directive prologue: the leading string-literal expression statements. */
21
19
  function prologue(ts, statements) {
22
- const directives = [];
23
- for (const statement of statements ?? []) {
24
- if (!ts.isExpressionStatement(statement) || !ts.isStringLiteral(statement.expression)) break;
25
- directives.push(statement);
26
- }
27
- return directives;
20
+ const directives = [];
21
+ for (const statement of statements ?? []) {
22
+ if (!isDirective(ts, statement))
23
+ break;
24
+ directives.push(statement);
25
+ }
26
+ return directives;
28
27
  }
29
-
30
28
  const useServerIn = (ts, statements) => prologue(ts, statements).find(statement => statement.expression.text === 'use server') ?? null;
31
-
32
29
  /** Every `"use server"` directive of one source file: the file-level one and each function-level one. */
33
30
  function serverDirectives(ts, sourceFile) {
34
- const found = [];
35
- const fileLevel = useServerIn(ts, sourceFile.statements);
36
- if (fileLevel) found.push({ node: fileLevel, level: 'file' });
37
- const visit = node => {
38
- // a function with a block body: declaration, expression, arrow, method, constructor or accessor
39
- if (ts.isFunctionLike(node) && node.body && ts.isBlock(node.body)) {
40
- const inline = useServerIn(ts, node.body.statements);
41
- if (inline) found.push({ node: inline, level: 'function' });
42
- }
43
- ts.forEachChild(node, visit);
44
- };
45
- ts.forEachChild(sourceFile, visit);
46
- return found;
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;
47
46
  }
48
-
49
47
  function serverActionViolations(ts, file) {
50
- return serverDirectives(ts, file.sourceFile).map(({ node, level }) => ({
51
- ruleId: SERVER_ACTION, path: file.rel, ...sourceLocation(file.sourceFile, node), level,
52
- 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.`,
53
- }));
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
+ }));
54
52
  }
55
-
56
53
  function routeHandlerViolation(file) {
57
- const match = ROUTE_FILE.exec(file.rel);
58
- if (!match) return null;
59
- if (file.rel === `apps/${match[1]}/src/app/health/live/route.ts`) return null;
60
- return {
61
- ruleId: ROUTE_HANDLER, path: file.rel, line: 1, column: 1,
62
- 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.`,
63
- };
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
+ };
64
63
  }
65
-
66
64
  /** The FE machine check of both bans over every source file of the front-end program. */
67
65
  export function checkServerActions({ graph, context }) {
68
- const ts = context.ts;
69
- const violations = [];
70
- let routes = 0;
71
- for (const file of graph.files.values()) {
72
- violations.push(...serverActionViolations(ts, file));
73
- const route = routeHandlerViolation(file);
74
- if (ROUTE_FILE.test(file.rel)) routes += 1;
75
- if (route) violations.push(route);
76
- }
77
- return { violations, coverage: { status: 'checked', files: graph.files.size, routes } };
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
78
  }
@@ -4,13 +4,10 @@
4
4
  // (db/types/, sides.<side>.reads of the slot manifest) is the one thing both sides do import: the generated database types.
5
5
  import path from 'node:path';
6
6
  import { isInside, slash } from './config.mjs';
7
-
8
7
  const OTHER_SIDE = /^(be|fe)\//;
9
-
10
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). */
11
9
  const readsAppTree = (config, target) => (config.hfs?.repo?.reads ?? [])
12
- .some((read) => !OTHER_SIDE.test(read) && isInside(path.join(config.packageRoot, read), target));
13
-
10
+ .some((read) => !OTHER_SIDE.test(read) && isInside(path.join(config.packageRoot, read), target));
14
11
  /** Whether an import of `target` leaves the side the machine judges (config.root) for the app (config.packageRoot), declared app-root reads excepted. */
15
12
  export const crossesSide = (config, target) => config.packageRoot !== undefined && config.packageRoot !== config.root
16
- && isInside(config.packageRoot, target) && !isInside(config.root, target) && !slash(target).includes('/node_modules/') && !readsAppTree(config, target);
13
+ && isInside(config.packageRoot, target) && !isInside(config.root, target) && !slash(target).includes('/node_modules/') && !readsAppTree(config, target);