@starci/eslint-canon-be 3.8.20 → 3.9.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 +16 -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,6 +1,5 @@
1
1
  import { contextModelOf, connectionsComposedBy } from './context-map.mjs';
2
2
  import { machineKit } from './machine-ast.mjs';
3
-
4
3
  /**
5
4
  * R174 `context-owner` (BE_CONTEXT_OWNER). A connection of hfs.json IS a bounded context, and its `owner` is the one service app that composes it:
6
5
  * - an api or worker app passes to the database module registration (or lists in its options) only the connections it owns (a monolith's one
@@ -14,77 +13,90 @@ import { machineKit } from './machine-ast.mjs';
14
13
  * name pattern. A runner app with a registration whose connection name cannot be resolved is not judged for missing connections.
15
14
  */
16
15
  export const CONTEXT_OWNER_RULE_IDS = ['BE_CONTEXT_OWNER'];
17
-
18
16
  const RULE = 'BE_CONTEXT_OWNER';
19
17
  const SERVICE_KINDS = new Set(['api', 'worker']);
20
18
  const RUNNER_KINDS = new Set(['migrate', 'cli']);
21
-
22
19
  // What each app composes: [{connection, file, node}] from the database module registration and from the registration literals under its files.
23
20
  const compositionsOf = (kit, resolver, model, appOf) => {
24
- const composed = new Map(resolver.repo.apps.map(app => [app.name, { items: [], unresolved: false }]));
25
- for (const app of resolver.repo.apps) {
26
- for (const item of connectionsComposedBy(kit, app.name).items) composed.get(app.name).items.push(item);
27
- }
28
- for (const site of model.registrations) {
29
- const app = appOf(site.file.rel);
30
- if (!app || !composed.has(app)) continue;
31
- if (site.connection === null) composed.get(app).unresolved = true;
32
- else composed.get(app).items.push({ connection: site.connection, file: site.file, node: site.node });
33
- }
34
- return composed;
21
+ const apps = resolver.repo.apps;
22
+ const composed = new Map(apps.map((app) => [app.name, { items: [], unresolved: false }]));
23
+ for (const app of apps) {
24
+ const entry = composed.get(app.name);
25
+ if (!entry)
26
+ continue;
27
+ for (const item of connectionsComposedBy(kit, app.name).items)
28
+ entry.items.push(item);
29
+ }
30
+ for (const site of model.registrations) {
31
+ const app = appOf(site.file.rel);
32
+ const entry = app ? composed.get(app) : undefined;
33
+ if (!app || !entry)
34
+ continue;
35
+ if (site.connection === null)
36
+ entry.unresolved = true;
37
+ else
38
+ entry.items.push({ connection: site.connection, file: site.file, node: site.node });
39
+ }
40
+ return composed;
35
41
  };
36
-
37
42
  // A service app composes only the connections it owns; a runner app composes every declared connection with tables.
38
43
  const judgeComposition = (app, { items, unresolved }, { owners, model, kit, once }) => {
39
- if (SERVICE_KINDS.has(app.kind)) {
40
- for (const { connection, file, node } of items) {
41
- const owner = owners.get(connection);
42
- if (owner && owner !== app.name) {
43
- once(`${app.name}|${connection}`, { ...kit.at(file.rel, file.sourceFile, node), message: `App ${app.name} composes connection ${connection}, the context owned by app ${owner}; an app composes only the contexts it owns. Reach that context through the API or the events of ${owner}.`, connection, app: app.name, owner });
44
- }
44
+ if (SERVICE_KINDS.has(app.kind)) {
45
+ for (const { connection, file, node } of items) {
46
+ const owner = owners.get(connection);
47
+ if (owner && owner !== app.name) {
48
+ once(`${app.name}|${connection}`, { ...kit.at(file.rel, file.sourceFile, node), message: `App ${app.name} composes connection ${connection}, the context owned by app ${owner}; an app composes only the contexts it owns. Reach that context through the API or the events of ${owner}.`, connection, app: app.name, owner });
49
+ }
50
+ }
45
51
  }
46
- } else if (RUNNER_KINDS.has(app.kind) && !unresolved) {
47
- const root = kit.appRoot(app.name);
48
- const present = new Set(items.map(item => item.connection));
49
- const held = new Set([...model.registered.values()].flatMap(entry => [...entry.connections.keys()]));
50
- for (const connection of owners.keys()) {
51
- if (!root || present.has(connection) || !held.has(connection) || !items.length) continue;
52
- once(`${app.name}|missing|${connection}`, { ...kit.at(root.rel, root.sourceFile, root.sourceFile), message: `The ${app.kind} app ${app.name} does not compose connection ${connection}; migrations run only through it, once per connection, so it registers every declared connection that holds tables.`, connection, app: app.name });
52
+ else if (RUNNER_KINDS.has(app.kind) && !unresolved) {
53
+ const root = kit.appRoot(app.name);
54
+ const present = new Set(items.map(item => item.connection));
55
+ const held = new Set([...model.registered.values()].flatMap(entry => [...entry.connections.keys()]));
56
+ for (const connection of owners.keys()) {
57
+ if (!root || present.has(connection) || !held.has(connection) || !items.length)
58
+ continue;
59
+ once(`${app.name}|missing|${connection}`, { ...kit.at(root.rel, root.sourceFile, root.sourceFile), message: `The ${app.kind} app ${app.name} does not compose connection ${connection}; migrations run only through it, once per connection, so it registers every declared connection that holds tables.`, connection, app: app.name });
60
+ }
53
61
  }
54
- }
55
- return items.length;
62
+ return items.length;
56
63
  };
57
-
58
64
  export function checkContextOwner(input) {
59
- const { graph } = input;
60
- const kit = machineKit(input);
61
- const { resolver } = kit;
62
- const model = contextModelOf(kit, graph);
63
- const violations = [];
64
- const owners = new Map(resolver.repo.connections.map(connection => [connection.name, connection.owner]));
65
- let compositions = 0;
66
- let imports = 0;
67
- const seen = new Set();
68
- const once = (key, violation) => { if (!seen.has(key)) { seen.add(key); violations.push({ ruleId: RULE, ...violation }); } };
69
- const appOf = rel => { const classified = resolver.classifyPath(rel); return classified.slot?.startsWith('be.app.') ? classified.bindings?.app ?? null : null; };
70
-
71
- const composed = compositionsOf(kit, resolver, model, appOf);
72
-
73
- for (const app of resolver.repo.apps) {
74
- compositions += judgeComposition(app, composed.get(app.name), { owners, model, kit, once });
75
- }
76
-
77
- const kinds = new Map(resolver.repo.apps.map(app => [app.name, app.kind]));
78
- for (const edge of graph.edges) {
79
- const app = appOf(edge.from);
80
- if (!app || !SERVICE_KINDS.has(kinds.get(app))) continue;
81
- const context = model.contextOfFile(edge.to);
82
- if (!context) continue;
83
- imports += 1;
84
- const owner = owners.get(context);
85
- if (owner && owner !== app) {
86
- once(`${edge.from}|${edge.to}`, { path: edge.from, line: edge.line, column: edge.column, message: `App ${app} imports ${graph.files.get(edge.to).owner.root}, a capability of context ${context} owned by app ${owner}; an app composes only the contexts it owns, so use the API or the events of ${owner} instead.`, connection: context, app, owner });
65
+ const { graph } = input;
66
+ const kit = machineKit(input);
67
+ const { resolver } = kit;
68
+ const model = contextModelOf(kit, graph);
69
+ const violations = [];
70
+ const connections = resolver.repo.connections;
71
+ const apps = resolver.repo.apps;
72
+ const owners = new Map(connections.map((connection) => [connection.name, connection.owner]));
73
+ let compositions = 0;
74
+ let imports = 0;
75
+ const seen = new Set();
76
+ const once = (key, violation) => { if (!seen.has(key)) {
77
+ seen.add(key);
78
+ violations.push({ ruleId: RULE, ...violation });
79
+ } };
80
+ const appOf = (rel) => { const classified = resolver.classifyPath(rel); return classified.slot?.startsWith('be.app.') ? classified.bindings?.app ?? null : null; };
81
+ const composed = compositionsOf(kit, resolver, model, appOf);
82
+ for (const app of apps) {
83
+ const composition = composed.get(app.name);
84
+ if (composition)
85
+ compositions += judgeComposition(app, composition, { owners, model, kit, once });
86
+ }
87
+ const kinds = new Map(apps.map((app) => [app.name, app.kind]));
88
+ for (const edge of graph.edges) {
89
+ const app = appOf(edge.from);
90
+ if (!app || !SERVICE_KINDS.has(kinds.get(app) ?? ''))
91
+ continue;
92
+ const context = model.contextOfFile(edge.to);
93
+ if (!context)
94
+ continue;
95
+ imports += 1;
96
+ const owner = owners.get(context);
97
+ if (owner && owner !== app) {
98
+ once(`${edge.from}|${edge.to}`, { path: edge.from, line: edge.line, column: edge.column, message: `App ${app} imports ${graph.files.get(edge.to)?.owner?.root}, a capability of context ${context} owned by app ${owner}; an app composes only the contexts it owns, so use the API or the events of ${owner} instead.`, connection: context, app, owner });
99
+ }
87
100
  }
88
- }
89
- return { violations, coverage: { status: 'checked', apps: resolver.repo.apps.length, compositions, contextImports: imports } };
101
+ return { violations, coverage: { status: 'checked', apps: apps.length, compositions, contextImports: imports } };
90
102
  }
@@ -1,7 +1,6 @@
1
1
  import { contextModelOf } from './context-map.mjs';
2
2
  import { machineKit } from './machine-ast.mjs';
3
3
  import { byCodeUnit } from '../../lib/list.mjs';
4
-
5
4
  /**
6
5
  * R178 `context-platform-tables` (BE_CONTEXT_PLATFORM_TABLES). A platform capability the manifest lists as `perConnection` (the event-bus outbox,
7
6
  * the job table) keeps its tables on EVERY connection that uses it: when a call into the capability passes the entity manager of connection C
@@ -10,52 +9,57 @@ import { byCodeUnit } from '../../lib/list.mjs';
10
9
  * whose manager origin cannot be proven is not judged.
11
10
  */
12
11
  export const CONTEXT_PLATFORM_TABLES_RULE_IDS = ['BE_CONTEXT_PLATFORM_TABLES'];
13
-
14
12
  const RULE = 'BE_CONTEXT_PLATFORM_TABLES';
15
-
16
13
  function perConnectionHome(kit, model, checker, file, node) {
17
- const { ts } = kit;
18
- const callee = ts.isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression;
19
- const home = kit.declarationsOf(checker, callee).map(kit.ownerOfDeclaration).find(Boolean);
20
- if (!home || !model.perConnection.has(home.root) || file.owner?.root === home.root) return undefined;
21
- return home;
14
+ const { ts } = kit;
15
+ const callee = ts.isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression;
16
+ const home = kit.declarationsOf(checker, callee).map(kit.ownerOfDeclaration).find(Boolean);
17
+ if (!home || !model.perConnection.has(home.root) || file.owner?.root === home.root)
18
+ return undefined;
19
+ return home;
22
20
  }
23
-
24
21
  function unregisteredViolations(kit, model, scope, home, connections, seen) {
25
- const { file, node } = scope;
26
- const registeredOn = model.registered.get(home.root)?.connections ?? new Map();
27
- const violations = [];
28
- for (const connection of connections) {
29
- if (registeredOn.has(connection)) continue;
30
- const key = `${file.rel}|${node.getStart()}|${connection}`;
31
- if (seen.has(key)) continue;
32
- seen.add(key);
33
- violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message: `${file.rel} passes the entity manager of connection ${connection} to ${home.name}, but the tables of ${home.name} are not registered on ${connection} (registered: ${[...registeredOn.keys()].sort(byCodeUnit).join(', ') || 'none'}); register its entities and migrations on ${connection} too, so the table exists in the database of that context.`, connection, capability: home.name });
34
- }
35
- return violations;
22
+ const { file, node } = scope;
23
+ const registeredOn = model.registered.get(home.root)?.connections ?? new Map();
24
+ const violations = [];
25
+ for (const connection of connections) {
26
+ if (registeredOn.has(connection))
27
+ continue;
28
+ const key = `${file.rel}|${node.getStart()}|${connection}`;
29
+ if (seen.has(key))
30
+ continue;
31
+ seen.add(key);
32
+ violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message: `${file.rel} passes the entity manager of connection ${connection} to ${home.name}, but the tables of ${home.name} are not registered on ${connection} (registered: ${[...registeredOn.keys()].sort(byCodeUnit).join(', ') || 'none'}); register its entities and migrations on ${connection} too, so the table exists in the database of that context.`, connection, capability: home.name });
33
+ }
34
+ return violations;
36
35
  }
37
-
38
36
  export function checkContextPlatformTables(input) {
39
- const { graph } = input;
40
- const kit = machineKit(input);
41
- const { ts } = kit;
42
- const model = contextModelOf(kit, graph);
43
- const violations = [];
44
- const counts = { calls: 0, unproven: 0 };
45
- if (!model.perConnection.size) return { violations, coverage: { status: 'checked', perConnectionCapabilities: 0, ...counts } };
46
- const seen = new Set();
47
- for (const file of graph.files.values()) {
48
- const checker = kit.checkerOf(file.sourceFile);
49
- kit.walk(file.sourceFile, node => {
50
- if (!ts.isCallExpression(node)) return true;
51
- const home = perConnectionHome(kit, model, checker, file, node);
52
- if (!home) return true;
53
- counts.calls += 1;
54
- const connections = new Set(node.arguments.map(argument => model.connectionOfManager(checker, argument)).filter(Boolean));
55
- if (!connections.size) { counts.unproven += 1; return true; }
56
- violations.push(...unregisteredViolations(kit, model, { file, node }, home, connections, seen));
57
- return true;
58
- });
59
- }
60
- return { violations, coverage: { status: 'checked', perConnectionCapabilities: model.perConnection.size, ...counts } };
37
+ const { graph } = input;
38
+ const kit = machineKit(input);
39
+ const { ts } = kit;
40
+ const model = contextModelOf(kit, graph);
41
+ const violations = [];
42
+ const counts = { calls: 0, unproven: 0 };
43
+ if (!model.perConnection.size)
44
+ return { violations, coverage: { status: 'checked', perConnectionCapabilities: 0, ...counts } };
45
+ const seen = new Set();
46
+ for (const file of graph.files.values()) {
47
+ const checker = kit.checkerOf(file.sourceFile);
48
+ kit.walk(file.sourceFile, (node) => {
49
+ if (!ts.isCallExpression(node))
50
+ return true;
51
+ const home = perConnectionHome(kit, model, checker, file, node);
52
+ if (!home)
53
+ return true;
54
+ counts.calls += 1;
55
+ const connections = new Set(node.arguments.map(argument => model.connectionOfManager(checker, argument)).filter((connection) => Boolean(connection)));
56
+ if (!connections.size) {
57
+ counts.unproven += 1;
58
+ return true;
59
+ }
60
+ violations.push(...unregisteredViolations(kit, model, { file, node }, home, connections, seen));
61
+ return true;
62
+ });
63
+ }
64
+ return { violations, coverage: { status: 'checked', perConnectionCapabilities: model.perConnection.size, ...counts } };
61
65
  }
@@ -1,6 +1,5 @@
1
1
  import { contextModelOf } from './context-map.mjs';
2
2
  import { machineKit } from './machine-ast.mjs';
3
-
4
3
  /**
5
4
  * R176 `context-transaction` (BE_CONTEXT_TRANSACTION). One transaction touches one context's connection. In the callback of
6
5
  * `<manager>.transaction(async (manager) => ...)`, where `<manager>` is proven to be the entity manager of connection C (an
@@ -10,64 +9,67 @@ import { machineKit } from './machine-ast.mjs';
10
9
  * Work that spans contexts is a saga of one transaction per context, linked by events. A receiver whose connection cannot be proven is not judged.
11
10
  */
12
11
  export const CONTEXT_TRANSACTION_RULE_IDS = ['BE_CONTEXT_TRANSACTION'];
13
-
14
12
  const RULE = 'BE_CONTEXT_TRANSACTION';
15
-
16
13
  const SPAN_ADVICE = "one transaction touches one context's connection. Span contexts with a saga: one transaction per context, linked by events.";
17
-
18
14
  /** Reports an entity manager of another connection, or a call into another context's capability, found inside a transaction callback. */
19
15
  function inspectInner(scope, file, checker, connection, inner) {
20
- const { ts, kit, model, graph, report } = scope;
21
- if (ts.isPropertyAccessExpression(inner)) {
22
- const other = model.connectionOfManager(checker, inner);
23
- if (other && other !== connection) report(file, inner, `A transaction on connection ${connection} uses the entity manager of connection ${other}; ${SPAN_ADVICE}`, { connection, other });
24
- }
25
- if (!ts.isCallExpression(inner)) return;
26
- const callee = ts.isPropertyAccessExpression(inner.expression) ? inner.expression.name : inner.expression;
27
- const declaration = kit.declarationsOf(checker, callee)[0];
28
- const rel = declaration ? kit.graphPath(declaration) : null;
29
- const context = rel ? model.contextOfFile(rel) : null;
30
- if (context && context !== connection) {
31
- report(file, inner, `A transaction on connection ${connection} calls ${graph.files.get(rel).owner.root} of context ${context}; ${SPAN_ADVICE}`, { connection, other: context });
32
- }
16
+ const { ts, kit, model, graph, report } = scope;
17
+ if (ts.isPropertyAccessExpression(inner)) {
18
+ const other = model.connectionOfManager(checker, inner);
19
+ if (other && other !== connection)
20
+ report(file, inner, `A transaction on connection ${connection} uses the entity manager of connection ${other}; ${SPAN_ADVICE}`, { connection, other });
21
+ }
22
+ if (!ts.isCallExpression(inner))
23
+ return;
24
+ const callee = ts.isPropertyAccessExpression(inner.expression) ? inner.expression.name : inner.expression;
25
+ const declaration = kit.declarationsOf(checker, callee)[0];
26
+ const rel = declaration ? kit.graphPath(declaration) : null;
27
+ const context = rel ? model.contextOfFile(rel) : null;
28
+ if (rel && context && context !== connection) {
29
+ report(file, inner, `A transaction on connection ${connection} calls ${graph.files.get(rel)?.owner?.root} of context ${context}; ${SPAN_ADVICE}`, { connection, other: context });
30
+ }
33
31
  }
34
-
35
32
  /** Judges a `.transaction(...)` call: counts it as proven or unproven and inspects its callback body; any other node is skipped. */
36
33
  function inspectTransaction(scope, file, checker, node) {
37
- const { ts, kit, model, counts } = scope;
38
- if (!(ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'transaction')) return;
39
- const callback = node.arguments.find(argument => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
40
- if (!callback) return;
41
- const connection = model.connectionOfManager(checker, node.expression.expression);
42
- if (!connection) { counts.unproven += 1; return; }
43
- counts.transactions += 1;
44
- kit.walk(callback.body, inner => {
45
- inspectInner(scope, file, checker, connection, inner);
46
- return true;
47
- });
34
+ const { ts, kit, model, counts } = scope;
35
+ if (!(ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'transaction'))
36
+ return;
37
+ const callback = node.arguments.find(argument => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
38
+ if (!callback)
39
+ return;
40
+ const connection = model.connectionOfManager(checker, node.expression.expression);
41
+ if (!connection) {
42
+ counts.unproven += 1;
43
+ return;
44
+ }
45
+ counts.transactions += 1;
46
+ kit.walk(callback.body, inner => {
47
+ inspectInner(scope, file, checker, connection, inner);
48
+ return true;
49
+ });
48
50
  }
49
-
50
51
  export function checkContextTransaction(input) {
51
- const { graph } = input;
52
- const kit = machineKit(input);
53
- const { ts } = kit;
54
- const model = contextModelOf(kit, graph);
55
- const violations = [];
56
- const counts = { transactions: 0, unproven: 0 };
57
- const seen = new Set();
58
- const report = (file, node, message, extra) => {
59
- const key = `${file.rel}|${node.getStart()}|${message}`;
60
- if (seen.has(key)) return;
61
- seen.add(key);
62
- violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
63
- };
64
- const scope = { ts, kit, model, graph, report, counts };
65
- for (const file of graph.files.values()) {
66
- const checker = kit.checkerOf(file.sourceFile);
67
- kit.walk(file.sourceFile, node => {
68
- inspectTransaction(scope, file, checker, node);
69
- return true;
70
- });
71
- }
72
- return { violations, coverage: { status: 'checked', transactions: counts.transactions, unproven: counts.unproven } };
52
+ const { graph } = input;
53
+ const kit = machineKit(input);
54
+ const { ts } = kit;
55
+ const model = contextModelOf(kit, graph);
56
+ const violations = [];
57
+ const counts = { transactions: 0, unproven: 0 };
58
+ const seen = new Set();
59
+ const report = (file, node, message, extra) => {
60
+ const key = `${file.rel}|${node.getStart()}|${message}`;
61
+ if (seen.has(key))
62
+ return;
63
+ seen.add(key);
64
+ violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
65
+ };
66
+ const scope = { ts, kit, model, graph, report, counts };
67
+ for (const file of graph.files.values()) {
68
+ const checker = kit.checkerOf(file.sourceFile);
69
+ kit.walk(file.sourceFile, node => {
70
+ inspectTransaction(scope, file, checker, node);
71
+ return true;
72
+ });
73
+ }
74
+ return { violations, coverage: { status: 'checked', transactions: counts.transactions, unproven: counts.unproven } };
73
75
  }