@starci/eslint-canon-be 3.8.19 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  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
@@ -1,338 +1,372 @@
1
1
  import path from 'node:path';
2
2
  import { canonical } from './config.mjs';
3
3
  import { referencedExports, relativePath, unwrapExpression } from './typescript.mjs';
4
- import { commonJsRequireReasons, decoratorCallee, moduleExportsOf, mutableDecoratorKind, programSourcesOf, selectedNode, valueSymbol } from './ast-walks.mjs';
4
+ import { commonJsRequireReasons, decoratorCallee, moduleExportsOf, mutableDecoratorKind, nodeDecorators, programSourcesOf, selectedNode, valueSymbol } from './ast-walks.mjs';
5
5
  import { sourceLocation } from '../../lib/ts-ast.mjs';
6
6
  import { byCodeUnit } from '../../lib/list.mjs';
7
-
8
7
  const REGISTRATION_RULE_IDS = ['BE_MODULE_HANDLER_REGISTRATION', 'BE_MODULE_PROVIDER_REREGISTRATION'];
9
8
  const FRAMEWORK = new Map([
10
- ['Module', '@nestjs/common'],
11
- ['CommandHandler', '@nestjs/cqrs'],
12
- ['QueryHandler', '@nestjs/cqrs'],
9
+ ['Module', '@nestjs/common'],
10
+ ['CommandHandler', '@nestjs/cqrs'],
11
+ ['QueryHandler', '@nestjs/cqrs'],
13
12
  ]);
14
-
15
13
  function frameworkDecorator(ts, checker, decorator, targets) {
16
- const selected = selectedNode(ts, decoratorCallee(ts, decorator));
17
- if (!selected) return null;
18
- const symbol = valueSymbol(ts, checker, selected);
19
- for (const [name, target] of targets) if (symbol === target) return name;
20
- return null;
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;
21
22
  }
22
-
23
23
  /* This module's framework map keys decorator names, not symbols - invert it (first name wins, as the old
24
24
  * `for...of` scan did) for the shared symbol-keyed lookup. */
25
25
  const mutableFrameworkAlias = (ts, checker, decorator, targets) => {
26
- const bySymbol = new Map();
27
- for (const [name, symbol] of targets) if (!bySymbol.has(symbol)) bySymbol.set(symbol, name);
28
- return mutableDecoratorKind(ts, checker, decorator, bySymbol);
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);
29
31
  };
30
-
31
32
  function collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons) {
32
- const bound = moduleExportsOf(context.ts, checker, statement);
33
- if (!bound || ![...FRAMEWORK.values()].includes(bound.specifier)) return;
34
- const expected = new Set([...FRAMEWORK].filter(([, packageName]) => packageName === bound.specifier).map(([name]) => name));
35
- const selected = referencedExports(context.ts, statement, expected);
36
- if (!selected.length) return;
37
- if (!bound.symbol) {
38
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${bound.specifier}`);
39
- return;
40
- }
41
- for (const name of selected) {
42
- const target = bound.exports.get(name);
43
- if (!target) {
44
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${name} from ${bound.specifier}`);
45
- continue;
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);
46
51
  }
47
- targets.set(name, target);
48
- }
49
52
  }
50
-
51
53
  function frameworkTargets(config, context, checker, localFiles) {
52
- const targets = new Map();
53
- const reasons = [];
54
- const files = programSourcesOf(context, checker, localFiles);
55
- if (!files) return { targets, reasons: ['a TypeScript program checker could not be associated with its source'] };
56
- for (const sourceFile of files) {
57
- for (const statement of sourceFile.statements) collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons);
58
- commonJsRequireReasons(context.ts, checker, sourceFile, (specifier) => [...FRAMEWORK.values()].includes(specifier),
59
- reasons, relativePath(config.root, sourceFile.fileName), 'whose decorator identity cannot be proved', 'Nest framework binding');
60
- }
61
- return { targets, reasons };
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 };
62
65
  }
63
-
64
66
  function classToken(ts, checker, node, localFiles) {
65
- const symbol = valueSymbol(ts, checker, node);
66
- const declarations = (symbol?.getDeclarations?.() ?? []).filter(declaration => ts.isClassDeclaration(declaration)) ?? [];
67
- const local = declarations.filter(declaration => localFiles.has(canonical(declaration.getSourceFile().fileName)));
68
- const keys = [...new Set(local.map(declaration => `${canonical(declaration.getSourceFile().fileName)}#${declaration.getStart(declaration.getSourceFile())}`))];
69
- return { key: keys.length === 1 ? keys[0] : null, external: declarations.length > 0 && local.length === 0 };
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 };
70
72
  }
71
-
72
73
  function localClassKey(ts, checker, node, localFiles) {
73
- return classToken(ts, checker, node, localFiles).key;
74
+ return classToken(ts, checker, node, localFiles).key;
74
75
  }
75
-
76
76
  function propertyName(ts, property) {
77
- if (!property.name) return null;
78
- if (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) return property.name.text;
79
- return null;
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;
80
82
  }
81
-
82
83
  function inspectTokenElement(ts, checker, element, localFiles, field, tokens) {
83
- if (ts.isSpreadElement(element)) return true;
84
- let key;
85
- let node = element;
86
- if (ts.isObjectLiteralExpression(element)) {
87
- if (element.properties.some(property => ts.isSpreadAssignment(property))) return true;
88
- const providers = element.properties.filter(property => propertyName(ts, property) === 'provide');
89
- if (providers.length !== 1 || !ts.isPropertyAssignment(providers[0])) return true;
90
- node = providers[0].initializer;
91
- key = localClassKey(ts, checker, node, localFiles);
92
- } else {
93
- const token = classToken(ts, checker, element, localFiles);
94
- key = token.key;
95
- if (!key) return field === 'providers' && !token.external;
96
- }
97
- if (key) {
98
- if (!tokens.has(key)) tokens.set(key, []);
99
- tokens.get(key).push(node);
100
- }
101
- return false;
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;
102
113
  }
103
-
104
114
  function tokenEntries(ts, checker, initializer, localFiles, field) {
105
- initializer = unwrapExpression(ts, initializer);
106
- if (!ts.isArrayLiteralExpression(initializer)) return { tokens: new Map(), unknown: true };
107
- const tokens = new Map();
108
- let unknown = false;
109
- for (const element of initializer.elements) {
110
- if (inspectTokenElement(ts, checker, element, localFiles, field, tokens)) unknown = true;
111
- }
112
- return { tokens, unknown };
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 };
113
125
  }
114
-
115
126
  function metadataTokens(ts, checker, metadata, field, localFiles) {
116
- metadata = unwrapExpression(ts, metadata);
117
- if (!ts.isObjectLiteralExpression(metadata)) return { tokens: new Map(), unknown: true };
118
- if (metadata.properties.some(property => ts.isSpreadAssignment(property))) return { tokens: new Map(), unknown: true };
119
- const matches = metadata.properties.filter(property => propertyName(ts, property) === field);
120
- if (!matches.length) return { tokens: new Map(), unknown: false };
121
- if (matches.length !== 1 || !ts.isPropertyAssignment(matches[0])) return { tokens: new Map(), unknown: true };
122
- return tokenEntries(ts, checker, matches[0].initializer, localFiles, field);
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);
123
139
  }
124
-
125
140
  function moduleRecord(config, context, sourceFile, declaration, decorator, checker, localFiles) {
126
- const call = decorator.expression;
127
- const location = declaration.name ?? declaration;
128
- const base = {
129
- key: declaration.name ? localClassKey(context.ts, checker, declaration.name, localFiles) : null,
130
- name: declaration.name?.text ?? '(anonymous)',
131
- path: relativePath(config.root, sourceFile.fileName),
132
- ...sourceLocation(sourceFile, location),
133
- providers: new Map(),
134
- exports: new Map(),
135
- unknown: false,
136
- };
137
- if (!context.ts.isCallExpression(call) || call.arguments.length !== 1 || !base.key) return { ...base, unknown: true };
138
- const providers = metadataTokens(context.ts, checker, call.arguments[0], 'providers', localFiles);
139
- const exports = metadataTokens(context.ts, checker, call.arguments[0], 'exports', localFiles);
140
- return { ...base, providers: providers.tokens, exports: exports.tokens, unknown: providers.unknown || exports.unknown };
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 };
141
158
  }
142
-
143
159
  function registrationFinding(module, node, ruleId, message, extra = {}) {
144
- return { ruleId, path: module.path, ...sourceLocation(node.getSourceFile(), node), module: module.name, message, ...extra };
160
+ return { ruleId, path: module.path, ...sourceLocation(node.getSourceFile(), node), module: module.name, message, ...extra };
145
161
  }
146
-
147
162
  const modulesByFileOf = (config, modules) => {
148
- const byFile = new Map();
149
- for (const module of modules) {
150
- const file = canonical(path.resolve(config.root, ...module.path.split('/')));
151
- if (!byFile.has(file)) byFile.set(file, []);
152
- byFile.get(file).push(module);
153
- }
154
- return byFile;
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;
155
174
  };
156
-
157
175
  /** The modules whose file the runtime import edges reach from `rootFile`, in first-visit order; each is added to `bound`. */
158
176
  const reachableModules = (context, byFile, rootFile, bound) => {
159
- const queue = [rootFile];
160
- const seen = new Set();
161
- const reachable = [];
162
- for (const file of queue) {
163
- if (seen.has(file)) continue;
164
- seen.add(file);
165
- for (const module of byFile.get(file) ?? []) {
166
- reachable.push(module);
167
- bound.add(module);
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);
168
191
  }
169
- for (const edge of context.edges.get(file) ?? []) if (edge.runtime && !seen.has(edge.to)) queue.push(edge.to);
170
- }
171
- return reachable;
192
+ return reachable;
172
193
  };
173
-
174
194
  /** A module belongs to an app only when its runtime source is reachable from that app's composition root. */
175
195
  function applicationGraphs(config, context, modules) {
176
- const roots = modules.filter(module => /^apps\/[^/]+\/src\/app\.module\.ts$/.test(module.path))
177
- .sort((a, b) => a.path.localeCompare(b.path));
178
- // Small architecture fixtures without app composition retain the original single-graph relation.
179
- if (!roots.length) return [modules];
180
- const byFile = modulesByFileOf(config, modules);
181
- const bound = new Set();
182
- const graphs = roots.map(root => reachableModules(context, byFile, canonical(path.resolve(config.root, ...root.path.split('/'))), bound));
183
- // A module outside every proven app graph can still contain a duplicate in its own metadata.
184
- return [...graphs, ...modules.filter(module => !bound.has(module)).map(module => [module])];
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])];
185
206
  }
186
-
187
207
  function decoratorKinds(ts, checker, node, framework) {
188
- const decorators = ts.canHaveDecorators(node) ? ts.getDecorators(node) ?? [] : node.decorators ?? [];
189
- return decorators.map(decorator => ({ decorator, kind: frameworkDecorator(ts, checker, decorator, framework.targets) }));
208
+ return nodeDecorators(ts, node).map(decorator => ({ decorator, kind: frameworkDecorator(ts, checker, decorator, framework.targets) }));
190
209
  }
191
-
192
210
  function recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, reasons) {
193
- for (const { decorator, kind } of kinds) {
194
- const dynamic = kind ? null : mutableFrameworkAlias(ts, checker, decorator, framework.targets);
195
- if (dynamic) reasons.push(`${relativePath(config.root, sourceFile.fileName)} uses mutable ${dynamic} decorator identity`);
196
- }
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
+ }
197
216
  }
198
-
199
217
  function recordModuleDecorator(site, node, kinds, found) {
200
- const { config, context, sourceFile, checker, localFiles } = site;
201
- const { modules, reasons } = found;
202
- const moduleDecorators = kinds.filter(item => item.kind === 'Module');
203
- if (moduleDecorators.length === 1) modules.push(moduleRecord(config, context, sourceFile, node, moduleDecorators[0].decorator, checker, localFiles));
204
- else if (moduleDecorators.length > 1) reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved @Module decorators`);
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`);
205
226
  }
206
-
207
227
  function recordHandlerDecorator(site, node, kinds, found) {
208
- const { config, context, sourceFile, checker, localFiles } = site;
209
- const { handlers, reasons } = found;
210
- const { ts } = context;
211
- const handlerDecorators = kinds.filter(item => item.kind === 'CommandHandler' || item.kind === 'QueryHandler');
212
- if (handlerDecorators.length === 1) handlers.push({
213
- key: node.name ? localClassKey(ts, checker, node.name, localFiles) : null,
214
- name: node.name?.text ?? '(anonymous)',
215
- kind: handlerDecorators[0].kind,
216
- path: relativePath(config.root, sourceFile.fileName),
217
- ...sourceLocation(sourceFile, node.name ?? node),
218
- });
219
- else if (handlerDecorators.length > 1) reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved CQRS handler decorators`);
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`);
220
243
  }
221
-
222
244
  function inspectRegistrationClass(site, node, found) {
223
- const { config, context, sourceFile, checker, framework } = site;
224
- const { ts } = context;
225
- if (!ts.isClassDeclaration(node)) return;
226
- const kinds = decoratorKinds(ts, checker, node, framework);
227
- recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, found.reasons);
228
- recordModuleDecorator(site, node, kinds, found);
229
- recordHandlerDecorator(site, node, kinds, 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);
230
253
  }
231
-
232
254
  function discoverRegistrations(config, context, localFiles) {
233
- const modules = [];
234
- const handlers = [];
235
- const reasons = [];
236
- const found = { modules, handlers, reasons };
237
- const frameworkByChecker = new Map();
238
- for (const sourceFile of context.files) {
239
- const checker = context.checkerFor(sourceFile.fileName);
240
- if (!frameworkByChecker.has(checker)) frameworkByChecker.set(checker, frameworkTargets(config, context, checker, localFiles));
241
- const framework = frameworkByChecker.get(checker);
242
- reasons.push(...framework.reasons);
243
- const site = { config, context, sourceFile, checker, localFiles, framework };
244
- const visit = node => {
245
- inspectRegistrationClass(site, node, found);
246
- context.ts.forEachChild(node, visit);
247
- };
248
- visit(sourceFile);
249
- }
250
- return { modules, handlers, reasons };
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 };
251
278
  }
252
-
253
279
  function providerOwnersOf(modules) {
254
- const providerOwners = new Map();
255
- for (const module of modules) {
256
- for (const key of module.providers.keys()) {
257
- if (!module.exports.has(key)) continue;
258
- if (!providerOwners.has(key)) providerOwners.set(key, []);
259
- providerOwners.get(key).push(module);
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
+ }
260
292
  }
261
- }
262
- return providerOwners;
293
+ return providerOwners;
263
294
  }
264
-
265
295
  const byModulePath = (a, b) => a.module.path.localeCompare(b.module.path) || a.node.getStart() - b.node.getStart();
266
-
267
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. */
268
297
  const duplicateRegistrations = (graph, key, owner) => {
269
- const registrations = graph.flatMap(module => (module.providers.get(key) ?? []).map(node => ({ module, node })))
270
- .sort(byModulePath);
271
- let keptOwnerRegistration = false;
272
- return registrations.filter(registration => {
273
- if (registration.module !== owner || keptOwnerRegistration) return true;
274
- keptOwnerRegistration = true;
275
- return false;
276
- });
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
+ });
277
307
  };
278
-
279
308
  function reregistrationViolations(config, context, modules, providerOwners) {
280
- const violations = [];
281
- const reportedRegistrations = new Set();
282
- const report = (key, owner, duplicate) => {
283
- const identity = `${key}\0${duplicate.module.path}\0${duplicate.node.getStart()}`;
284
- if (reportedRegistrations.has(identity)) return;
285
- reportedRegistrations.add(identity);
286
- violations.push(registrationFinding(duplicate.module, duplicate.node,
287
- 'BE_MODULE_PROVIDER_REREGISTRATION',
288
- `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.`,
289
- { ownerModule: owner.name, ownerPath: owner.path }));
290
- };
291
- for (const graph of applicationGraphs(config, context, modules)) for (const [key] of providerOwners) {
292
- const owners = graph.filter(module => module.providers.has(key) && module.exports.has(key))
293
- .sort((a, b) => a.path.localeCompare(b.path));
294
- if (!owners.length) continue;
295
- for (const duplicate of duplicateRegistrations(graph, key, owners[0])) report(key, owners[0], duplicate);
296
- }
297
- return violations;
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;
298
329
  }
299
-
300
330
  function handlerRegistrationViolations(modules, handlers, selected) {
301
- const violations = [];
302
- for (const handler of handlers.filter(item => item.key && selected.handlerDecorators.includes(item.kind))) {
303
- const registrations = modules.flatMap(module => (module.providers.get(handler.key) ?? []).map(node => ({ module, node })));
304
- if (registrations.length !== 1) violations.push({
305
- ruleId: 'BE_MODULE_HANDLER_REGISTRATION', path: handler.path, line: handler.line, column: handler.column,
306
- handler: handler.name, decorator: handler.kind,
307
- message: registrations.length === 0
308
- ? `${handler.kind} ${handler.name} is not registered as a direct class-token provider in a resolved Nest module.`
309
- : `${handler.kind} ${handler.name} has multiple direct module registrations; one owner must preserve its handler identity.`,
310
- modules: registrations.map(registration => ({ name: registration.module.name, path: registration.module.path,
311
- ...sourceLocation(registration.node.getSourceFile(), registration.node) })),
312
- });
313
- }
314
- return violations;
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;
315
346
  }
316
-
317
347
  /** Prove only static exported class-token identity and selected CQRS handler registration. */
318
348
  export function checkModuleRegistration(config, context) {
319
- const selected = config.backend.moduleRegistration;
320
- if (!selected) return { violations: [], coverage: { status: 'unavailable', reason: 'hfs.json does not select Nest module-registration identity checks' } };
321
- const localFiles = new Set(context.files.map(file => canonical(file.fileName)));
322
- const { modules, handlers, reasons } = discoverRegistrations(config, context, localFiles);
323
- for (const module of modules) if (module.unknown) reasons.push(`${module.path} has dynamic or unresolvable @Module providers/exports metadata`);
324
- for (const handler of handlers) {
325
- if (!handler.key) reasons.push(`${handler.path} handler class identity is not resolvable`);
326
- if (!selected.handlerDecorators.includes(handler.kind)) reasons.push(`${handler.path} uses unselected ${handler.kind}`);
327
- }
328
- const providerOwners = providerOwnersOf(modules);
329
- const violations = reregistrationViolations(config, context, modules, providerOwners);
330
- violations.push(...handlerRegistrationViolations(modules, handlers, selected));
331
- const coverage = reasons.length
332
- ? { status: 'unavailable', reason: 'one or more Nest module-registration relations are not statically provable', details: [...new Set(reasons)].sort(byCodeUnit) }
333
- : { status: 'checked', modules: modules.length, exportedClassTokenProviders: providerOwners.size, handlers: handlers.length,
334
- selectedHandlerDecorators: selected.handlerDecorators };
335
- return { violations, coverage };
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 };
336
371
  }
337
-
338
372
  export { REGISTRATION_RULE_IDS };