@starci/eslint-canon-fe 9.5.23 → 9.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/docs/button-intent.md +1 -1
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- package/runtime/scripts/lib/yaml-cached.mjs +4 -4
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { machineKit } from './machine-ast.mjs';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* R46 `background-unowned` (BE_BACKGROUND_UNOWNED, BE-CONVENTION 1.6 and 1.13). Background work is a transport that only
|
|
6
5
|
* a worker or api app runs (an api app composes the message transport of its own service; a separate worker is opt-in):
|
|
@@ -15,226 +14,241 @@ import { machineKit } from './machine-ast.mjs';
|
|
|
15
14
|
* Classification follows statically resolved calls; ownership follows runtime imports, re-exports and the entry point's feature.
|
|
16
15
|
*/
|
|
17
16
|
export const BACKGROUND_UNOWNED_RULE_IDS = ['BE_BACKGROUND_UNOWNED'];
|
|
18
|
-
|
|
19
17
|
const RULE = 'BE_BACKGROUND_UNOWNED';
|
|
20
18
|
const BACKGROUND_ROLES = new Set(['processor', 'consumer', 'scheduler', 'saga', 'event-handler']);
|
|
21
19
|
const USER_ROLES = new Set(['resolver', 'controller']);
|
|
22
20
|
const CLASS_DECORATORS = new Map([
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
['@nestjs/bull:Processor', 'processor'], ['@nestjs/bullmq:Processor', 'processor'],
|
|
22
|
+
['@nestjs/cqrs:EventsHandler', 'event-handler'],
|
|
25
23
|
]);
|
|
26
24
|
const METHOD_DECORATORS = new Map([
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
['@nestjs/cqrs:Saga', 'saga'], ['@nestjs/event-emitter:OnEvent', 'event-handler'],
|
|
26
|
+
...['Cron', 'Interval', 'Timeout'].map((name) => [`@nestjs/schedule:${name}`, 'scheduler']),
|
|
29
27
|
]);
|
|
30
28
|
const USER_DECORATORS = new Map([['@nestjs/graphql:Resolver', 'resolver'], ['@nestjs/common:Controller', 'controller']]);
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
return parts.length >= 3 && parts.at(-1) === 'ts' ? parts.at(-2) : null;
|
|
29
|
+
const roleOf = (rel) => {
|
|
30
|
+
const parts = path.posix.basename(rel).split('.');
|
|
31
|
+
return parts.length >= 3 && parts.at(-1) === 'ts' ? parts.at(-2) ?? null : null;
|
|
35
32
|
};
|
|
36
|
-
|
|
37
33
|
const decoratedRole = (kit, checker, node, roles) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const adjacencyOf = edges => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
for (const decorator of kit.decorators(node)) {
|
|
35
|
+
const expression = decorator.expression;
|
|
36
|
+
const callee = kit.ts.isCallExpression(expression) ? expression.expression : expression;
|
|
37
|
+
const binding = kit.importBinding(checker, callee);
|
|
38
|
+
const role = binding ? roles.get(`${binding.module}:${binding.name}`) : null;
|
|
39
|
+
if (role)
|
|
40
|
+
return role;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
const adjacencyOf = (edges) => {
|
|
45
|
+
const adjacency = new Map();
|
|
46
|
+
for (const edge of edges) {
|
|
47
|
+
if (!edge.runtime)
|
|
48
|
+
continue;
|
|
49
|
+
let targets = adjacency.get(edge.from);
|
|
50
|
+
if (!targets) {
|
|
51
|
+
targets = [];
|
|
52
|
+
adjacency.set(edge.from, targets);
|
|
53
|
+
}
|
|
54
|
+
targets.push(edge.to);
|
|
55
|
+
}
|
|
56
|
+
return adjacency;
|
|
57
|
+
};
|
|
58
58
|
const closureOf = (adjacency, starts) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
const seen = new Set(starts);
|
|
60
|
+
const queue = [...starts];
|
|
61
|
+
while (queue.length) {
|
|
62
|
+
const current = queue.shift();
|
|
63
|
+
if (current === undefined)
|
|
64
|
+
break;
|
|
65
|
+
for (const next of adjacency.get(current) ?? []) {
|
|
66
|
+
if (seen.has(next))
|
|
67
|
+
continue;
|
|
68
|
+
seen.add(next);
|
|
69
|
+
queue.push(next);
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
|
-
|
|
68
|
-
return seen;
|
|
72
|
+
return seen;
|
|
69
73
|
};
|
|
70
|
-
|
|
71
74
|
const appRootsOf = (apps, graph) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const rootOf = (app) => `apps/${app.name}/src/app.module.ts`;
|
|
76
|
+
const workers = apps.filter(app => app.kind === 'worker').map(rootOf).filter(rel => graph.files.has(rel));
|
|
77
|
+
const services = apps.filter(app => app.kind === 'api').map(rootOf).filter(rel => graph.files.has(rel));
|
|
78
|
+
return { workers, composed: [...workers, ...services] };
|
|
76
79
|
};
|
|
77
|
-
|
|
78
80
|
const reportUncomposedFiles = (background, composed, workerRoots, report) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
for (const { file, role } of background) {
|
|
82
|
+
if (file.tier === 'platform' || composed.has(file.rel))
|
|
83
|
+
continue;
|
|
84
|
+
report(file, file.sourceFile, `${file.rel} is a ${role} that no service app composes${workerRoots.length ? '' : ' (hfs.json declares no worker app)'}; its module must be imported by the root module of an app of kind worker or api.`, { role });
|
|
85
|
+
}
|
|
83
86
|
};
|
|
84
|
-
|
|
85
87
|
const rootsOfRunningFeatures = (running, files) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const roots = new Set();
|
|
89
|
+
for (const { file } of running) {
|
|
90
|
+
roots.add(file.rel);
|
|
91
|
+
const owner = file.owner?.root;
|
|
92
|
+
if (owner)
|
|
93
|
+
for (const other of files.values())
|
|
94
|
+
if (other.owner?.root === owner)
|
|
95
|
+
roots.add(other.rel);
|
|
96
|
+
}
|
|
97
|
+
return roots;
|
|
98
|
+
};
|
|
95
99
|
const callableKey = (kit, node) => `${kit.graphPath(node)}:${node.getStart()}`;
|
|
100
|
+
const isCallable = (ts, node) => ts.isFunctionLike(node) && 'body' in node && Boolean(node.body);
|
|
96
101
|
const callableBody = (ts, declaration) => {
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
const node = declaration.initializer ?? declaration; // reason: only variable-like declarations carry an initializer
|
|
103
|
+
return isCallable(ts, node) ? node : null;
|
|
99
104
|
};
|
|
100
105
|
const methodMember = (ts, node) => {
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if (ts.isMethodDeclaration(node))
|
|
107
|
+
return node;
|
|
108
|
+
return ts.isPropertyDeclaration(node.parent) && node.parent.initializer === node ? node.parent : null;
|
|
103
109
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|| Boolean(decoratedRole(kit, checker, node, USER_DECORATORS));
|
|
107
|
-
|
|
110
|
+
const isUserClass = (kit, checker, node) => USER_ROLES.has(roleOf(kit.graphPath(node) ?? '') ?? '')
|
|
111
|
+
|| Boolean(decoratedRole(kit, checker, node, USER_DECORATORS));
|
|
108
112
|
const seedClass = (scope, file, checker, node, role) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
scope.background.set(file.rel, { file, role });
|
|
114
|
+
scope.contextFiles.add(file.rel);
|
|
115
|
+
for (const symbol of checker.getTypeAtLocation(node).getProperties()) {
|
|
116
|
+
for (const declaration of symbol.declarations ?? []) {
|
|
117
|
+
const body = callableBody(scope.kit.ts, declaration);
|
|
118
|
+
if (body)
|
|
119
|
+
scope.inherited.push(body);
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
|
-
}
|
|
117
122
|
};
|
|
118
|
-
|
|
119
123
|
const classContext = (scope, file, checker, node, state) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
const user = state.user || isUserClass(scope.kit, checker, node);
|
|
125
|
+
if (!state.nested && user)
|
|
126
|
+
scope.userFiles.add(file.rel);
|
|
127
|
+
let classRole = null;
|
|
128
|
+
if (!state.nested && !user) {
|
|
129
|
+
const fileRole = state.fileRole !== null && BACKGROUND_ROLES.has(state.fileRole) ? state.fileRole : null;
|
|
130
|
+
classRole = decoratedRole(scope.kit, checker, node, CLASS_DECORATORS) ?? fileRole;
|
|
131
|
+
}
|
|
132
|
+
if (classRole)
|
|
133
|
+
seedClass(scope, file, checker, node, classRole);
|
|
134
|
+
return { ...state, user, classRole };
|
|
135
|
+
};
|
|
131
136
|
const recordCallable = (scope, file, checker, node, state) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
const { kit } = scope;
|
|
138
|
+
const member = methodMember(kit.ts, node);
|
|
139
|
+
const canSeed = member && !state.user && !state.nested;
|
|
140
|
+
const role = canSeed ? decoratedRole(kit, checker, member, METHOD_DECORATORS) ?? state.classRole : null;
|
|
141
|
+
const entry = { file, node, checker, user: state.user, member, name: member ? kit.propertyNameText(member.name) : null };
|
|
142
|
+
scope.callables.set(callableKey(kit, node), entry);
|
|
143
|
+
if (role) {
|
|
144
|
+
scope.background.set(file.rel, { file, role });
|
|
145
|
+
scope.contextFiles.add(file.rel);
|
|
146
|
+
scope.seeds.push(entry);
|
|
147
|
+
}
|
|
143
148
|
};
|
|
144
|
-
|
|
145
149
|
const indexCallables = (scope, file, checker, node, state) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
153
|
-
|
|
150
|
+
const { ts } = scope.kit;
|
|
151
|
+
if (ts.isClassDeclaration(node) || ts.isClassExpression(node))
|
|
152
|
+
state = classContext(scope, file, checker, node, state);
|
|
153
|
+
const callable = ts.isFunctionLike(node);
|
|
154
|
+
if (isCallable(ts, node))
|
|
155
|
+
recordCallable(scope, file, checker, node, state);
|
|
156
|
+
const childState = { ...state, nested: state.nested || callable };
|
|
157
|
+
ts.forEachChild(node, (child) => indexCallables(scope, file, checker, child, childState));
|
|
158
|
+
};
|
|
154
159
|
/** Index callable bodies once; a resolver/controller is a barrier to background propagation. */
|
|
155
160
|
const backgroundContextOf = (graph, kit) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
const callables = new Map();
|
|
162
|
+
const background = new Map();
|
|
163
|
+
const seeds = [];
|
|
164
|
+
const inherited = [];
|
|
165
|
+
const scope = { kit, callables, background, seeds, inherited, userFiles: new Set(), contextFiles: new Set() };
|
|
166
|
+
for (const file of graph.files.values()) {
|
|
167
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
168
|
+
const fileRole = roleOf(file.rel);
|
|
169
|
+
if (fileRole !== null && BACKGROUND_ROLES.has(fileRole))
|
|
170
|
+
background.set(file.rel, { file, role: fileRole });
|
|
171
|
+
indexCallables(scope, file, checker, file.sourceFile, { fileRole, classRole: null, user: fileRole !== null && USER_ROLES.has(fileRole), nested: false });
|
|
172
|
+
}
|
|
173
|
+
// Request context overrides a file suffix; mixed files can still hold a separate background class.
|
|
174
|
+
for (const rel of scope.userFiles)
|
|
175
|
+
if (!scope.contextFiles.has(rel))
|
|
176
|
+
background.delete(rel);
|
|
177
|
+
for (const body of inherited) {
|
|
178
|
+
const entry = callables.get(callableKey(kit, body));
|
|
179
|
+
if (entry)
|
|
180
|
+
seeds.push(entry);
|
|
181
|
+
}
|
|
182
|
+
return { callables, background: [...background.values()], seeds };
|
|
183
|
+
};
|
|
176
184
|
const calledBodies = (kit, checker, call) => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
const { ts } = kit;
|
|
186
|
+
const expression = call.expression;
|
|
187
|
+
if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
|
|
188
|
+
const receiver = checker.getNonNullableType(checker.getTypeAtLocation(expression.expression));
|
|
189
|
+
if (receiver.getSymbol()?.declarations?.some(declaration => isUserClass(kit, checker, declaration)))
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
const target = ts.isPropertyAccessExpression(expression) ? expression.name : expression;
|
|
193
|
+
const declarations = [...kit.declarationsOf(checker, target)];
|
|
194
|
+
const signature = checker.getResolvedSignature(call)?.declaration;
|
|
195
|
+
if (signature)
|
|
196
|
+
declarations.push(signature);
|
|
197
|
+
return declarations.map(declaration => callableBody(ts, declaration)).filter((body) => body !== null);
|
|
198
|
+
};
|
|
190
199
|
const checkBackgroundMethods = ({ kit, context, reachable, report }) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
const { callables, seeds } = context;
|
|
201
|
+
const seen = new Set();
|
|
202
|
+
const queue = [...seeds];
|
|
203
|
+
let methods = 0;
|
|
204
|
+
while (queue.length) {
|
|
205
|
+
const entry = queue.pop();
|
|
206
|
+
if (entry === undefined)
|
|
207
|
+
break;
|
|
208
|
+
const { file, node, checker, user, member, name } = entry;
|
|
209
|
+
const key = callableKey(kit, node);
|
|
210
|
+
if (user || seen.has(key))
|
|
211
|
+
continue;
|
|
212
|
+
seen.add(key);
|
|
213
|
+
if (name && member && file.tier !== 'platform') {
|
|
214
|
+
methods += 1;
|
|
215
|
+
if (!reachable.has(file.rel))
|
|
216
|
+
report(file, member.name, `${name} is background work that no background entry point composed by a worker or api app can reach. Compose the processor, consumer, scheduler, saga or event handler that runs it in a worker or api app.`, { method: name });
|
|
217
|
+
}
|
|
218
|
+
kit.walk(node.body, (inner) => {
|
|
219
|
+
// Nested bodies run only through a resolved call or when passed as a callback.
|
|
220
|
+
if (kit.ts.isFunctionLike(inner) || kit.ts.isClassDeclaration(inner) || kit.ts.isClassExpression(inner))
|
|
221
|
+
return false;
|
|
222
|
+
if (!kit.ts.isCallExpression(inner))
|
|
223
|
+
return undefined;
|
|
224
|
+
const callbacks = inner.arguments.filter((argument) => kit.ts.isArrowFunction(argument) || kit.ts.isFunctionExpression(argument));
|
|
225
|
+
for (const body of [...calledBodies(kit, checker, inner), ...callbacks]) {
|
|
226
|
+
const called = callables.get(callableKey(kit, body));
|
|
227
|
+
if (called)
|
|
228
|
+
queue.push(called);
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
});
|
|
204
232
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (kit.ts.isFunctionLike(inner) || kit.ts.isClassDeclaration(inner) || kit.ts.isClassExpression(inner)) return false;
|
|
208
|
-
if (!kit.ts.isCallExpression(inner)) return;
|
|
209
|
-
const callbacks = inner.arguments.filter(argument => kit.ts.isArrowFunction(argument) || kit.ts.isFunctionExpression(argument));
|
|
210
|
-
for (const body of [...calledBodies(kit, checker, inner), ...callbacks]) {
|
|
211
|
-
const called = callables.get(callableKey(kit, body));
|
|
212
|
-
if (called) queue.push(called);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return methods;
|
|
217
|
-
};
|
|
218
|
-
|
|
233
|
+
return methods;
|
|
234
|
+
};
|
|
219
235
|
export function checkBackgroundUnowned(input) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const methods = checkBackgroundMethods({ kit, context, reachable, report });
|
|
239
|
-
return { violations, coverage: { status: 'checked', workers: workerRoots.length, jobsAndConsumers: background.length, composed: running.length, backgroundMethods: methods } };
|
|
236
|
+
const { graph } = input;
|
|
237
|
+
const kit = machineKit(input);
|
|
238
|
+
const { resolver } = kit;
|
|
239
|
+
const violations = [];
|
|
240
|
+
const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
241
|
+
const adjacency = adjacencyOf(graph.edges);
|
|
242
|
+
const closure = (starts) => closureOf(adjacency, starts);
|
|
243
|
+
const { workers: workerRoots, composed: appRoots } = appRootsOf(resolver.repo.apps, graph);
|
|
244
|
+
const composed = closure(appRoots);
|
|
245
|
+
const context = backgroundContextOf(graph, kit);
|
|
246
|
+
const { background } = context;
|
|
247
|
+
const running = background.filter(({ file }) => composed.has(file.rel));
|
|
248
|
+
reportUncomposedFiles(background, composed, workerRoots, report);
|
|
249
|
+
// Everything a composed background entry point can reach: its imports and its own feature's command handlers.
|
|
250
|
+
const roots = rootsOfRunningFeatures(running, graph.files);
|
|
251
|
+
const reachable = closure([...roots]);
|
|
252
|
+
const methods = checkBackgroundMethods({ kit, context, reachable, report });
|
|
253
|
+
return { violations, coverage: { status: 'checked', workers: workerRoots.length, jobsAndConsumers: background.length, composed: running.length, backgroundMethods: methods } };
|
|
240
254
|
}
|