@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.
Files changed (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,212 +0,0 @@
1
- import path from 'node:path';
2
- import { isComposeGroup, machineKit } from './machine-ast.mjs';
3
- import { callName } from './jwt-ast.mjs';
4
- import { isTestWorldSlot } from '../test-world-slot.mjs';
5
- import { byCodeUnit } from '../../lib/list.mjs';
6
- /**
7
- * R45 `register-once` (BE_MODULE_SHAPE), the module graph read from the app roots (owner rule of 2026-09-30, the
8
- * reference's `CodingModule imports DeviceModule` shape). Each capability has one representative module: the only module
9
- * of the capability an app registers, once, in `apps/<app>/src/app.module.ts` as `X.register({ isGlobal: true, ... })`, or in a
10
- * composition group `apps/<app>/src/compose/<area>.ts` the root spreads (an app root here means the root and its groups).
11
- * It may split itself into sub-modules imported as `imports: [Sub.register({})]`; a sub-module is never in an app and has one
12
- * importer, its parent. Over every `@Module` class of the program:
13
- *
14
- * - a module in an app root's imports (a `X.register(...)` call or a listed class, helpers of the root included) is
15
- * listed once there, is imported by no other module, and, when it is a capability module of src/modules, is registered
16
- * with the literal `isGlobal: true` (a bare capability class is not a registration);
17
- * - a module imported by a non-app module (as `Sub.register({})`) has exactly one importer and appears in no app root; the one exception is
18
- * the feature case: a feature's application module is imported by each protocol module of the same feature;
19
- * - `isGlobal: true` appears only in an app root.
20
- */
21
- export const REGISTER_ONCE_RULE_IDS = ['BE_MODULE_SHAPE'];
22
- const RULE = 'BE_MODULE_SHAPE';
23
- const CAPABILITY_TIERS = new Set(['domain', 'platform', 'integrations']);
24
- const isRegisterCall = (ts, node) => callName(ts, node) === 'register';
25
- function moduleDeclarations(graph, kit, ts) {
26
- const modules = new Map(); // declaration -> {name, file, capability}
27
- for (const file of graph.files.values()) {
28
- const checker = kit.checkerOf(file.sourceFile);
29
- for (const statement of file.sourceFile.statements) {
30
- if (!ts.isClassDeclaration(statement) || !statement.name)
31
- continue;
32
- const decorators = kit.decorators(statement);
33
- const isModule = decorators.some(decorator => {
34
- const call = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
35
- const binding = kit.importBinding(checker, call);
36
- return binding?.module === '@nestjs/common' && binding.name === 'Module';
37
- });
38
- if (isModule)
39
- modules.set(statement, { name: statement.name.text, file, capability: CAPABILITY_TIERS.has(file.tier ?? '') });
40
- }
41
- }
42
- return modules;
43
- }
44
- function targetOf(kit, modules, checker, node) {
45
- const declarations = kit.declarationsOf(checker, node);
46
- for (const declaration of declarations) {
47
- const info = modules.get(declaration);
48
- if (info)
49
- return { declaration, ...info };
50
- }
51
- return null;
52
- }
53
- function enclosingModule(ts, modules, node) {
54
- for (let current = node.parent; current; current = current.parent) {
55
- if (ts.isClassDeclaration(current) && modules.has(current))
56
- return current;
57
- }
58
- return null;
59
- }
60
- /** Records the reference an element of an imports list, or a register call, makes to a module. */
61
- function noteReference(scan, element, viaImports) {
62
- const { ts, kit, modules, checker, file, seen, references, isAppRoot } = scan;
63
- if (seen.has(element))
64
- return;
65
- const call = isRegisterCall(ts, element);
66
- if (ts.isCallExpression(element) && !call)
67
- return;
68
- const target = targetOf(kit, modules, checker, call ? element.expression.expression : element);
69
- if (!target)
70
- return;
71
- seen.add(element);
72
- const owner = enclosingModule(ts, modules, element);
73
- references.push({ file, node: element, target, register: call, viaImports, importer: owner ?? file.rel, importerOwner: file.owner?.root ?? null,
74
- options: call ? element.arguments[0] ?? null : null, root: isAppRoot(file) });
75
- }
76
- const isImportsList = (scan, node) => scan.ts.isPropertyAssignment(node) && scan.kit.propertyNameText(node.name) === 'imports' && scan.ts.isArrayLiteralExpression(node.initializer);
77
- const isStrayGlobal = (scan, node) => scan.ts.isPropertyAssignment(node) && scan.kit.propertyNameText(node.name) === 'isGlobal'
78
- && node.initializer.kind === scan.ts.SyntaxKind.TrueKeyword && !scan.isAppRoot(scan.file) && !scan.isWorld(scan.file);
79
- // A composition group's module list is any array of the group: the root spreads it into its imports.
80
- const isGroupList = (scan, node) => scan.ts.isArrayLiteralExpression(node) && isComposeGroup(scan.file.rel);
81
- function visitReferenceNode(scan, node) {
82
- if (isImportsList(scan, node)) {
83
- for (const element of node.initializer.elements)
84
- noteReference(scan, element, true);
85
- }
86
- else if (isGroupList(scan, node)) {
87
- for (const element of node.elements)
88
- noteReference(scan, element, true);
89
- }
90
- else if (callName(scan.ts, node) === 'register' && !scan.seen.has(node)) {
91
- noteReference(scan, node, false);
92
- }
93
- if (isStrayGlobal(scan, node)) {
94
- scan.report(scan.file, node, '`isGlobal: true` appears only in the app root (apps/<app>/src/app.module.ts or a group of apps/<app>/src/compose/), where the representative module of a capability is registered; a module never decides its own globality.');
95
- }
96
- return true;
97
- }
98
- function moduleReferences(graph, kit, ts, modules, isWorld, isAppRoot, report) {
99
- // The references to modules: importer (the enclosing module class, else the file), target, node, whether it is a register call.
100
- const references = [];
101
- for (const file of graph.files.values()) {
102
- if (isWorld(file))
103
- continue; // the test composition root assembles modules; it is not a module importer
104
- const scan = { ts, kit, modules, file, isWorld, isAppRoot, report, references, checker: kit.checkerOf(file.sourceFile), seen: new Set() };
105
- kit.walk(file.sourceFile, (node) => visitReferenceNode(scan, node));
106
- }
107
- return references;
108
- }
109
- function isTrueGlobal(kit, ts, options) {
110
- if (!options || !ts.isObjectLiteralExpression(options))
111
- return false;
112
- const property = kit.propertyOf(options, 'isGlobal');
113
- return property !== undefined && ts.isPropertyAssignment(property) && property.initializer.kind === ts.SyntaxKind.TrueKeyword;
114
- }
115
- function appRegistrations(rootReferences, appOf) {
116
- const inApps = new Map(); // module declaration -> Set(app names)
117
- for (const item of rootReferences) {
118
- const app = appOf(item.file) ?? item.file.rel;
119
- let apps = inApps.get(item.target.declaration);
120
- if (!apps) {
121
- apps = new Set();
122
- inApps.set(item.target.declaration, apps);
123
- }
124
- apps.add(app);
125
- }
126
- return inApps;
127
- }
128
- function reportDuplicateAppModules(config, rootReferences, appOf, report) {
129
- for (const app of config.apps) {
130
- const seenInApp = new Map();
131
- for (const item of rootReferences.filter(entry => appOf(entry.file) === app.name)) {
132
- if (seenInApp.has(item.target.declaration)) {
133
- report(item.file, item.node, `${item.target.name} is registered more than once in the root of app ${app.name}; a module is listed once per app.`, { module: item.target.name, app: app.name });
134
- }
135
- else
136
- seenInApp.set(item.target.declaration, item.node);
137
- }
138
- }
139
- }
140
- function reportCapabilityRegistrations(rootReferences, kit, ts, report) {
141
- for (const item of rootReferences) {
142
- if (!item.target.capability || !item.viaImports && !item.register)
143
- continue;
144
- if (!item.register)
145
- report(item.file, item.node, `${item.target.name} is listed in imports as a bare class; the representative module of a capability is registered in the app root as ${item.target.name}.register({ isGlobal: true, ...options }).`, { module: item.target.name });
146
- else if (!isTrueGlobal(kit, ts, item.options))
147
- report(item.file, item.node, `${item.target.name} is registered in the app root without the literal \`isGlobal: true\`; write ${item.target.name}.register({ isGlobal: true, ...options }).`, { module: item.target.name });
148
- }
149
- }
150
- /** The references that import a module from a non-app module, grouped by the imported module declaration. */
151
- function importersByModule(references) {
152
- const importersOf = new Map(); // module declaration -> [reference]
153
- for (const item of references.filter(entry => !entry.root && entry.viaImports)) {
154
- let importers = importersOf.get(item.target.declaration);
155
- if (!importers) {
156
- importers = [];
157
- importersOf.set(item.target.declaration, importers);
158
- }
159
- importers.push(item);
160
- }
161
- return importersOf;
162
- }
163
- function reportSharedSubModule(target, list, report) {
164
- const distinct = [...new Set(list.map(item => item.importer))];
165
- const targetOwner = target.file.owner;
166
- const featureCase = target.file.tier === 'feature' && targetOwner && list.every(item => item.importerOwner === targetOwner.root);
167
- if (distinct.length <= 1 || featureCase)
168
- return;
169
- for (const item of list.filter(entry => entry.importer !== list[0]?.importer)) {
170
- report(item.file, item.node, `${target.name} is imported by ${distinct.length} modules; a sub-module has exactly one importer, its parent. Another capability's module is consumed through its Inject*() decorators, never imported.`, { module: target.name });
171
- }
172
- }
173
- function reportNonAppImporters(references, modules, inApps, report) {
174
- // Non-app importers: no importer of an app-registered module, exactly one importer otherwise (the feature case excepted).
175
- for (const [declaration, list] of importersByModule(references)) {
176
- const target = modules.get(declaration);
177
- if (!target)
178
- continue;
179
- const apps = inApps.get(declaration);
180
- if (!apps) {
181
- reportSharedSubModule(target, list, report);
182
- continue;
183
- }
184
- for (const item of list) {
185
- report(item.file, item.node, `${target.name} is registered in the root of app ${[...apps].sort(byCodeUnit).join(', ')}, so no other module imports it; consume it through its Inject*() decorators.`, { module: target.name });
186
- }
187
- }
188
- }
189
- export function checkRegisterOnce(input) {
190
- const { config, graph } = input;
191
- const kit = machineKit(input);
192
- const { ts } = kit;
193
- const violations = [];
194
- const report = (file, node, message, extra = {}) => { violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra }); };
195
- const isAppRoot = file => Boolean(file.slot?.startsWith('be.app.')) && (path.posix.basename(file.rel) === 'app.module.ts' || isComposeGroup(file.rel));
196
- // The test world (slot be.tests.world) is the test composition root: useTestWorld registers capability modules with
197
- // `isGlobal: true` the way an app root does. A spec (integration, contract, e2e) is not a composition root.
198
- const isWorld = file => isTestWorldSlot(file.slot);
199
- const appOf = file => config.apps.find(app => file.rel === `apps/${app.name}/src/app.module.ts`
200
- || (isComposeGroup(file.rel) && file.rel.startsWith(`apps/${app.name}/src/compose/`)))?.name ?? null;
201
- const modules = moduleDeclarations(graph, kit, ts);
202
- const references = moduleReferences(graph, kit, ts, modules, isWorld, isAppRoot, report);
203
- const rootReferences = references.filter(item => item.root);
204
- const inApps = appRegistrations(rootReferences, appOf);
205
- // App roots: each module is listed once, capability modules are registered with isGlobal true.
206
- reportDuplicateAppModules(config, rootReferences, appOf, report);
207
- reportCapabilityRegistrations(rootReferences, kit, ts, report);
208
- reportNonAppImporters(references, modules, inApps, report);
209
- return { violations, coverage: { status: 'checked', apps: config.apps.filter(app => kit.appRoot(app.name)).length, modules: modules.size,
210
- capabilityModules: [...modules.values()].filter(item => item.capability).length, registrations: references.filter(item => item.register).length,
211
- rootImports: rootReferences.length } };
212
- }
@@ -1,372 +0,0 @@
1
- import path from 'node:path';
2
- import { canonical } from './config.mjs';
3
- import { referencedExports, relativePath, unwrapExpression } from './typescript.mjs';
4
- import { commonJsRequireReasons, decoratorCallee, moduleExportsOf, mutableDecoratorKind, nodeDecorators, programSourcesOf, selectedNode, valueSymbol } from './ast-walks.mjs';
5
- import { sourceLocation } from '../../lib/ts-ast.mjs';
6
- import { byCodeUnit } from '../../lib/list.mjs';
7
- const REGISTRATION_RULE_IDS = ['BE_MODULE_HANDLER_REGISTRATION', 'BE_MODULE_PROVIDER_REREGISTRATION'];
8
- const FRAMEWORK = new Map([
9
- ['Module', '@nestjs/common'],
10
- ['CommandHandler', '@nestjs/cqrs'],
11
- ['QueryHandler', '@nestjs/cqrs'],
12
- ]);
13
- function frameworkDecorator(ts, checker, decorator, targets) {
14
- const selected = selectedNode(ts, decoratorCallee(ts, decorator));
15
- if (!selected)
16
- return null;
17
- const symbol = valueSymbol(ts, checker, selected);
18
- for (const [name, target] of targets)
19
- if (symbol === target)
20
- return name;
21
- return null;
22
- }
23
- /* This module's framework map keys decorator names, not symbols - invert it (first name wins, as the old
24
- * `for...of` scan did) for the shared symbol-keyed lookup. */
25
- const mutableFrameworkAlias = (ts, checker, decorator, targets) => {
26
- const bySymbol = new Map();
27
- for (const [name, symbol] of targets)
28
- if (!bySymbol.has(symbol))
29
- bySymbol.set(symbol, name);
30
- return mutableDecoratorKind(ts, checker, decorator, bySymbol);
31
- };
32
- function collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons) {
33
- const bound = moduleExportsOf(context.ts, checker, statement);
34
- if (!bound || ![...FRAMEWORK.values()].includes(bound.specifier))
35
- return;
36
- const expected = new Set([...FRAMEWORK].filter(([, packageName]) => packageName === bound.specifier).map(([name]) => name));
37
- const selected = referencedExports(context.ts, statement, expected);
38
- if (!selected.length)
39
- return;
40
- if (!bound.symbol) {
41
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${bound.specifier}`);
42
- return;
43
- }
44
- for (const name of selected) {
45
- const target = bound.exports.get(name);
46
- if (!target) {
47
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${name} from ${bound.specifier}`);
48
- continue;
49
- }
50
- targets.set(name, target);
51
- }
52
- }
53
- function frameworkTargets(config, context, checker, localFiles) {
54
- const targets = new Map();
55
- const reasons = [];
56
- const files = programSourcesOf(context, checker, localFiles);
57
- if (!files)
58
- return { targets, reasons: ['a TypeScript program checker could not be associated with its source'] };
59
- for (const sourceFile of files) {
60
- for (const statement of sourceFile.statements)
61
- collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons);
62
- commonJsRequireReasons(context.ts, checker, sourceFile, (specifier) => [...FRAMEWORK.values()].includes(specifier), reasons, relativePath(config.root, sourceFile.fileName), 'whose decorator identity cannot be proved', 'Nest framework binding');
63
- }
64
- return { targets, reasons };
65
- }
66
- function classToken(ts, checker, node, localFiles) {
67
- const symbol = valueSymbol(ts, checker, node);
68
- const declarations = (symbol?.getDeclarations?.() ?? []).filter((declaration) => ts.isClassDeclaration(declaration)) ?? [];
69
- const local = declarations.filter(declaration => localFiles.has(canonical(declaration.getSourceFile().fileName)));
70
- const keys = [...new Set(local.map(declaration => `${canonical(declaration.getSourceFile().fileName)}#${declaration.getStart(declaration.getSourceFile())}`))];
71
- return { key: keys.length === 1 ? keys[0] ?? null : null, external: declarations.length > 0 && local.length === 0 };
72
- }
73
- function localClassKey(ts, checker, node, localFiles) {
74
- return classToken(ts, checker, node, localFiles).key;
75
- }
76
- function propertyName(ts, property) {
77
- if (!property.name)
78
- return null;
79
- if (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name))
80
- return property.name.text;
81
- return null;
82
- }
83
- function inspectTokenElement(ts, checker, element, localFiles, field, tokens) {
84
- if (ts.isSpreadElement(element))
85
- return true;
86
- let key;
87
- let node = element;
88
- if (ts.isObjectLiteralExpression(element)) {
89
- if (element.properties.some(property => ts.isSpreadAssignment(property)))
90
- return true;
91
- const providers = element.properties.filter(property => propertyName(ts, property) === 'provide');
92
- const [provider] = providers;
93
- if (providers.length !== 1 || !provider || !ts.isPropertyAssignment(provider))
94
- return true;
95
- node = provider.initializer;
96
- key = localClassKey(ts, checker, node, localFiles);
97
- }
98
- else {
99
- const token = classToken(ts, checker, element, localFiles);
100
- key = token.key;
101
- if (!key)
102
- return field === 'providers' && !token.external;
103
- }
104
- if (key) {
105
- let nodes = tokens.get(key);
106
- if (!nodes) {
107
- nodes = [];
108
- tokens.set(key, nodes);
109
- }
110
- nodes.push(node);
111
- }
112
- return false;
113
- }
114
- function tokenEntries(ts, checker, initializer, localFiles, field) {
115
- const array = unwrapExpression(ts, initializer);
116
- if (!ts.isArrayLiteralExpression(array))
117
- return { tokens: new Map(), unknown: true };
118
- const tokens = new Map();
119
- let unknown = false;
120
- for (const element of array.elements) {
121
- if (inspectTokenElement(ts, checker, element, localFiles, field, tokens))
122
- unknown = true;
123
- }
124
- return { tokens, unknown };
125
- }
126
- function metadataTokens(ts, checker, metadata, field, localFiles) {
127
- const object = unwrapExpression(ts, metadata);
128
- if (!ts.isObjectLiteralExpression(object))
129
- return { tokens: new Map(), unknown: true };
130
- if (object.properties.some(property => ts.isSpreadAssignment(property)))
131
- return { tokens: new Map(), unknown: true };
132
- const matches = object.properties.filter(property => propertyName(ts, property) === field);
133
- if (!matches.length)
134
- return { tokens: new Map(), unknown: false };
135
- const [match] = matches;
136
- if (matches.length !== 1 || !match || !ts.isPropertyAssignment(match))
137
- return { tokens: new Map(), unknown: true };
138
- return tokenEntries(ts, checker, match.initializer, localFiles, field);
139
- }
140
- function moduleRecord(config, context, sourceFile, declaration, decorator, checker, localFiles) {
141
- const call = decorator.expression;
142
- const location = declaration.name ?? declaration;
143
- const base = {
144
- key: declaration.name ? localClassKey(context.ts, checker, declaration.name, localFiles) : null,
145
- name: declaration.name?.text ?? '(anonymous)',
146
- path: relativePath(config.root, sourceFile.fileName),
147
- ...sourceLocation(sourceFile, location),
148
- providers: new Map(),
149
- exports: new Map(),
150
- unknown: false,
151
- };
152
- const [metadata] = context.ts.isCallExpression(call) ? call.arguments : [];
153
- if (!context.ts.isCallExpression(call) || call.arguments.length !== 1 || !metadata || !base.key)
154
- return { ...base, unknown: true };
155
- const providers = metadataTokens(context.ts, checker, metadata, 'providers', localFiles);
156
- const exports = metadataTokens(context.ts, checker, metadata, 'exports', localFiles);
157
- return { ...base, providers: providers.tokens, exports: exports.tokens, unknown: providers.unknown || exports.unknown };
158
- }
159
- function registrationFinding(module, node, ruleId, message, extra = {}) {
160
- return { ruleId, path: module.path, ...sourceLocation(node.getSourceFile(), node), module: module.name, message, ...extra };
161
- }
162
- const modulesByFileOf = (config, modules) => {
163
- const byFile = new Map();
164
- for (const module of modules) {
165
- const file = canonical(path.resolve(config.root, ...module.path.split('/')));
166
- let list = byFile.get(file);
167
- if (!list) {
168
- list = [];
169
- byFile.set(file, list);
170
- }
171
- list.push(module);
172
- }
173
- return byFile;
174
- };
175
- /** The modules whose file the runtime import edges reach from `rootFile`, in first-visit order; each is added to `bound`. */
176
- const reachableModules = (context, byFile, rootFile, bound) => {
177
- const queue = [rootFile];
178
- const seen = new Set();
179
- const reachable = [];
180
- for (const file of queue) {
181
- if (seen.has(file))
182
- continue;
183
- seen.add(file);
184
- for (const module of byFile.get(file) ?? []) {
185
- reachable.push(module);
186
- bound.add(module);
187
- }
188
- for (const edge of context.edges.get(file) ?? [])
189
- if (edge.runtime && !seen.has(edge.to))
190
- queue.push(edge.to);
191
- }
192
- return reachable;
193
- };
194
- /** A module belongs to an app only when its runtime source is reachable from that app's composition root. */
195
- function applicationGraphs(config, context, modules) {
196
- const roots = modules.filter(module => /^apps\/[^/]+\/src\/app\.module\.ts$/.test(module.path))
197
- .sort((a, b) => a.path.localeCompare(b.path));
198
- // Small architecture fixtures without app composition retain the original single-graph relation.
199
- if (!roots.length)
200
- return [modules];
201
- const byFile = modulesByFileOf(config, modules);
202
- const bound = new Set();
203
- const graphs = roots.map(root => reachableModules(context, byFile, canonical(path.resolve(config.root, ...root.path.split('/'))), bound));
204
- // A module outside every proven app graph can still contain a duplicate in its own metadata.
205
- return [...graphs, ...modules.filter(module => !bound.has(module)).map(module => [module])];
206
- }
207
- function decoratorKinds(ts, checker, node, framework) {
208
- return nodeDecorators(ts, node).map(decorator => ({ decorator, kind: frameworkDecorator(ts, checker, decorator, framework.targets) }));
209
- }
210
- function recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, reasons) {
211
- for (const { decorator, kind } of kinds) {
212
- const dynamic = kind ? null : mutableFrameworkAlias(ts, checker, decorator, framework.targets);
213
- if (dynamic)
214
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} uses mutable ${dynamic} decorator identity`);
215
- }
216
- }
217
- function recordModuleDecorator(site, node, kinds, found) {
218
- const { config, context, sourceFile, checker, localFiles } = site;
219
- const { modules, reasons } = found;
220
- const moduleDecorators = kinds.filter(item => item.kind === 'Module');
221
- const [moduleDecorator] = moduleDecorators;
222
- if (moduleDecorators.length === 1 && moduleDecorator)
223
- modules.push(moduleRecord(config, context, sourceFile, node, moduleDecorator.decorator, checker, localFiles));
224
- else if (moduleDecorators.length > 1)
225
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved @Module decorators`);
226
- }
227
- function recordHandlerDecorator(site, node, kinds, found) {
228
- const { config, context, sourceFile, checker, localFiles } = site;
229
- const { handlers, reasons } = found;
230
- const { ts } = context;
231
- const handlerDecorators = kinds.filter((item) => item.kind === 'CommandHandler' || item.kind === 'QueryHandler');
232
- const [handlerDecorator] = handlerDecorators;
233
- if (handlerDecorators.length === 1 && handlerDecorator)
234
- handlers.push({
235
- key: node.name ? localClassKey(ts, checker, node.name, localFiles) : null,
236
- name: node.name?.text ?? '(anonymous)',
237
- kind: handlerDecorator.kind,
238
- path: relativePath(config.root, sourceFile.fileName),
239
- ...sourceLocation(sourceFile, node.name ?? node),
240
- });
241
- else if (handlerDecorators.length > 1)
242
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved CQRS handler decorators`);
243
- }
244
- function inspectRegistrationClass(site, node, found) {
245
- const { config, context, sourceFile, checker, framework } = site;
246
- const { ts } = context;
247
- if (!ts.isClassDeclaration(node))
248
- return;
249
- const kinds = decoratorKinds(ts, checker, node, framework);
250
- recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, found.reasons);
251
- recordModuleDecorator(site, node, kinds, found);
252
- recordHandlerDecorator(site, node, kinds, found);
253
- }
254
- function discoverRegistrations(config, context, localFiles) {
255
- const modules = [];
256
- const handlers = [];
257
- const reasons = [];
258
- const found = { modules, handlers, reasons };
259
- const frameworkByChecker = new Map();
260
- for (const sourceFile of context.files) {
261
- const checker = context.checkerFor(sourceFile.fileName);
262
- if (!checker)
263
- continue;
264
- let framework = frameworkByChecker.get(checker);
265
- if (!framework) {
266
- framework = frameworkTargets(config, context, checker, localFiles);
267
- frameworkByChecker.set(checker, framework);
268
- }
269
- reasons.push(...framework.reasons);
270
- const site = { config, context, sourceFile, checker, localFiles, framework };
271
- const visit = (node) => {
272
- inspectRegistrationClass(site, node, found);
273
- context.ts.forEachChild(node, visit);
274
- };
275
- visit(sourceFile);
276
- }
277
- return { modules, handlers, reasons };
278
- }
279
- function providerOwnersOf(modules) {
280
- const providerOwners = new Map();
281
- for (const module of modules) {
282
- for (const key of module.providers.keys()) {
283
- if (!module.exports.has(key))
284
- continue;
285
- let owners = providerOwners.get(key);
286
- if (!owners) {
287
- owners = [];
288
- providerOwners.set(key, owners);
289
- }
290
- owners.push(module);
291
- }
292
- }
293
- return providerOwners;
294
- }
295
- const byModulePath = (a, b) => a.module.path.localeCompare(b.module.path) || a.node.getStart() - b.node.getStart();
296
- /** The registrations of `key` in a graph that follow the first one of its owner module: the owner registers it once, every other is a duplicate. */
297
- const duplicateRegistrations = (graph, key, owner) => {
298
- const registrations = graph.flatMap(module => (module.providers.get(key) ?? []).map((node) => ({ module, node })))
299
- .sort(byModulePath);
300
- let keptOwnerRegistration = false;
301
- return registrations.filter(registration => {
302
- if (registration.module !== owner || keptOwnerRegistration)
303
- return true;
304
- keptOwnerRegistration = true;
305
- return false;
306
- });
307
- };
308
- function reregistrationViolations(config, context, modules, providerOwners) {
309
- const violations = [];
310
- const reportedRegistrations = new Set();
311
- const report = (key, owner, duplicate) => {
312
- const identity = `${key}\0${duplicate.module.path}\0${duplicate.node.getStart()}`;
313
- if (reportedRegistrations.has(identity))
314
- return;
315
- reportedRegistrations.add(identity);
316
- violations.push(registrationFinding(duplicate.module, duplicate.node, 'BE_MODULE_PROVIDER_REREGISTRATION', `Class-token provider exported by ${owner.name} is registered again by ${duplicate.module.name} in one application graph; import the owning module and preserve one class-token registration.`, { ownerModule: owner.name, ownerPath: owner.path }));
317
- };
318
- for (const graph of applicationGraphs(config, context, modules))
319
- for (const [key] of providerOwners) {
320
- const owners = graph.filter(module => module.providers.has(key) && module.exports.has(key))
321
- .sort((a, b) => a.path.localeCompare(b.path));
322
- const [owner] = owners;
323
- if (!owner)
324
- continue;
325
- for (const duplicate of duplicateRegistrations(graph, key, owner))
326
- report(key, owner, duplicate);
327
- }
328
- return violations;
329
- }
330
- function handlerRegistrationViolations(modules, handlers, selected) {
331
- const violations = [];
332
- for (const handler of handlers.filter(item => item.key && selected.handlerDecorators.includes(item.kind))) {
333
- const registrations = modules.flatMap(module => (module.providers.get(handler.key ?? '') ?? []).map((node) => ({ module, node })));
334
- if (registrations.length !== 1)
335
- violations.push({
336
- ruleId: 'BE_MODULE_HANDLER_REGISTRATION', path: handler.path, line: handler.line, column: handler.column,
337
- handler: handler.name, decorator: handler.kind,
338
- message: registrations.length === 0
339
- ? `${handler.kind} ${handler.name} is not registered as a direct class-token provider in a resolved Nest module.`
340
- : `${handler.kind} ${handler.name} has multiple direct module registrations; one owner must preserve its handler identity.`,
341
- modules: registrations.map(registration => ({ name: registration.module.name, path: registration.module.path,
342
- ...sourceLocation(registration.node.getSourceFile(), registration.node) })),
343
- });
344
- }
345
- return violations;
346
- }
347
- /** Prove only static exported class-token identity and selected CQRS handler registration. */
348
- export function checkModuleRegistration(config, context) {
349
- const selected = config.backend.moduleRegistration;
350
- if (!selected)
351
- return { violations: [], coverage: { status: 'unavailable', reason: 'hfs.json does not select Nest module-registration identity checks' } };
352
- const localFiles = new Set(context.files.map(file => canonical(file.fileName)));
353
- const { modules, handlers, reasons } = discoverRegistrations(config, context, localFiles);
354
- for (const module of modules)
355
- if (module.unknown)
356
- reasons.push(`${module.path} has dynamic or unresolvable @Module providers/exports metadata`);
357
- for (const handler of handlers) {
358
- if (!handler.key)
359
- reasons.push(`${handler.path} handler class identity is not resolvable`);
360
- if (!selected.handlerDecorators.includes(handler.kind))
361
- reasons.push(`${handler.path} uses unselected ${handler.kind}`);
362
- }
363
- const providerOwners = providerOwnersOf(modules);
364
- const violations = reregistrationViolations(config, context, modules, providerOwners);
365
- violations.push(...handlerRegistrationViolations(modules, handlers, selected));
366
- const coverage = reasons.length
367
- ? { status: 'unavailable', reason: 'one or more Nest module-registration relations are not statically provable', details: [...new Set(reasons)].sort(byCodeUnit) }
368
- : { status: 'checked', modules: modules.length, exportedClassTokenProviders: providerOwners.size, handlers: handlers.length,
369
- selectedHandlerDecorators: selected.handlerDecorators };
370
- return { violations, coverage };
371
- }
372
- export { REGISTRATION_RULE_IDS };