@starci/eslint-canon-be 3.8.20 → 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.
- package/CHANGELOG.md +8 -0
- 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/rules.yaml +6 -6
- 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,7 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { machineKit } from './machine-ast.mjs';
|
|
3
3
|
import { propertyValue } from './function-spec-providers.mjs';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* R50 `transport-owner` (FE_TRANSPORT_OWNER), the machine half of the eslint transport rules. ESLint judges one file at a time by
|
|
7
6
|
* the spelling of a call; the machine judges the repository by what the checker resolves. The browser calls the back end through
|
|
@@ -28,7 +27,6 @@ import { propertyValue } from './function-spec-providers.mjs';
|
|
|
28
27
|
* transport client layer and not by a fetch of its own.
|
|
29
28
|
*/
|
|
30
29
|
export const TRANSPORT_OWNER_RULE_IDS = ['FE_TRANSPORT_OWNER'];
|
|
31
|
-
|
|
32
30
|
const RULE = 'FE_TRANSPORT_OWNER';
|
|
33
31
|
/** Packages that send HTTP requests: a second transport when a file imports one (axios only outside the api owner). */
|
|
34
32
|
const HTTP_LIBRARIES = new Set(['axios', 'ky', 'ky-universal', 'got', 'node-fetch', 'undici', 'cross-fetch', 'isomorphic-fetch', 'superagent', 'ofetch', 'whatwg-fetch']);
|
|
@@ -47,199 +45,207 @@ const OPERATION_SLOTS = new Set(['fe.modules.api', PACKAGE_API_SLOT]);
|
|
|
47
45
|
const OPERATION_FILE = /^(?:query|mutation|subscription)-[^/]+\.ts$/u;
|
|
48
46
|
const STREAM_OPERATION_FILE = /^stream-[^/]+\.ts$/u;
|
|
49
47
|
const NO_CLIENT = "the repository has no transport client. Create the one Apollo client folder (packages/<family>-api/src/graphql/clients/, or the only app's modules/api/graphql/clients/) and call the back end through it.";
|
|
50
|
-
|
|
51
48
|
/** True when `node` names the global fetch: no import, and no declaration outside a lib declaration file. */
|
|
52
49
|
function isGlobalObjectFetch(ts, node) {
|
|
53
|
-
|
|
50
|
+
return ts.isPropertyAccessExpression(node) && node.name.text === 'fetch' && ts.isIdentifier(node.expression) && GLOBAL_OBJECTS.has(node.expression.text);
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
function isDeclarationName(ts, parent, node) {
|
|
57
|
-
|
|
53
|
+
return (ts.isPropertyAssignment(parent) || ts.isPropertyDeclaration(parent) || ts.isMethodDeclaration(parent) || ts.isBindingElement(parent) || ts.isParameter(parent) || ts.isVariableDeclaration(parent)) && parent.name === node;
|
|
58
54
|
}
|
|
59
|
-
|
|
60
55
|
function isTypeOrImportPosition(ts, parent) {
|
|
61
|
-
|
|
56
|
+
return ts.isTypeQueryNode(parent) || ts.isQualifiedName(parent) || ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent) || ts.isPropertySignature(parent);
|
|
62
57
|
}
|
|
63
|
-
|
|
64
58
|
function isGlobalFetch(ts, kit, checker, node) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
if (!ts.isIdentifier(node))
|
|
60
|
+
return isGlobalObjectFetch(ts, node);
|
|
61
|
+
if (node.text !== 'fetch')
|
|
62
|
+
return false;
|
|
63
|
+
if (kit.importBinding(checker, node))
|
|
64
|
+
return false;
|
|
65
|
+
const parent = node.parent;
|
|
66
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === node)
|
|
67
|
+
return false;
|
|
68
|
+
// A type position (`typeof fetch`, `typeof globalThis.fetch`) names the type of fetch and sends nothing.
|
|
69
|
+
if (isTypeOrImportPosition(ts, parent))
|
|
70
|
+
return false;
|
|
71
|
+
if (isDeclarationName(ts, parent, node))
|
|
72
|
+
return false;
|
|
73
|
+
const declarations = kit.declarationsOf(checker, node);
|
|
74
|
+
return declarations.every((declaration) => declaration.getSourceFile().isDeclarationFile);
|
|
75
|
+
}
|
|
77
76
|
/** Findings on every copy when there are several, and on an app's own copy in a repository where several apps call the back end. */
|
|
78
77
|
function reportMultiplicity(items, noun, callingApps, report) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
const list = items.map((item) => item.root).join(', ');
|
|
79
|
+
for (const item of items) {
|
|
80
|
+
if (items.length > 1) {
|
|
81
|
+
report(item, item.sourceFile, `The repository has ${items.length} ${noun}s (${list}); it has exactly one: the api package's (packages/<family>-api/src/graphql/) when the apps share it, or the only app's. Keep one and delete the others.`);
|
|
82
|
+
}
|
|
83
|
+
else if ((item.slot === APP_CLIENT_SLOT || item.slot === APP_OUTCOME_SLOT) && callingApps.length > 1) {
|
|
84
|
+
report(item, item.sourceFile, `${item.root} is an app's ${noun} in a repository of ${callingApps.length} apps that call the back end (${callingApps.join(', ')}); a repository where several apps call the back end keeps its one ${noun} in the api package (packages/<family>-api/src/graphql/).`);
|
|
85
|
+
}
|
|
85
86
|
}
|
|
86
|
-
}
|
|
87
87
|
}
|
|
88
|
-
|
|
89
88
|
function globalFetchUse(ts, kit, checker, node) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
if (ts.isPropertyAccessExpression(node) && isGlobalFetch(ts, kit, checker, node))
|
|
90
|
+
return 'property';
|
|
91
|
+
if (ts.isIdentifier(node) && isGlobalFetch(ts, kit, checker, node))
|
|
92
|
+
return 'identifier';
|
|
93
|
+
return null;
|
|
93
94
|
}
|
|
94
|
-
|
|
95
95
|
function moduleSpecifierOf(ts, node) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node))
|
|
97
|
+
return node.moduleSpecifier;
|
|
98
|
+
if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === 'require')))
|
|
99
|
+
return node.arguments[0];
|
|
100
|
+
return null;
|
|
99
101
|
}
|
|
100
|
-
|
|
101
102
|
function isApolloClientConstruction(ts, kit, checker, node) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
if (!ts.isNewExpression(node))
|
|
104
|
+
return false;
|
|
105
|
+
const binding = kit.importBinding(checker, node.expression);
|
|
106
|
+
return Boolean(binding?.name === 'ApolloClient' && binding.module.startsWith('@apollo/client'));
|
|
105
107
|
}
|
|
106
|
-
|
|
107
108
|
/** The one auth door of the session issuer's client (`modules/auth/auth-door.ts`, slot fe.modules.auth): it calls the app's own auth doors with axios. */
|
|
108
109
|
const isAuthDoor = (file) => file.slot === 'fe.modules.auth' && path.posix.basename(file.rel) === 'auth-door.ts';
|
|
109
|
-
|
|
110
110
|
function inspectLibraryImport({ ts, file, node, transport, report }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
111
|
+
const specifier = moduleSpecifierOf(ts, node);
|
|
112
|
+
if (!specifier || !ts.isStringLiteralLike(specifier))
|
|
113
|
+
return;
|
|
114
|
+
const library = specifier.text.split('/')[0];
|
|
115
|
+
if (!HTTP_LIBRARIES.has(library) || (library === REST_LIBRARY && (API_OWNER_SLOTS.has(file.slot) || isAuthDoor(file))))
|
|
116
|
+
return;
|
|
117
|
+
const where = library === REST_LIBRARY
|
|
118
|
+
? 'axios belongs to the api owner (modules/api/rest, the api package) and the auth door (modules/auth/auth-door.ts) only: call their functions'
|
|
119
|
+
: `the transport is Apollo GraphQL (${transport}) with axios for the rest calls of modules/api/rest`;
|
|
120
|
+
report(file, node, `${specifier.text} is a second HTTP transport in ${file.rel}; ${where}.`, { library: specifier.text });
|
|
121
|
+
}
|
|
121
122
|
/** True when a call of fetch declares, in its init object literal, the request header accept: "text/event-stream". */
|
|
122
123
|
function asksForEventStream(ts, node) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
const call = node.parent && ts.isCallExpression(node.parent) && node.parent.expression === node ? node.parent : null;
|
|
125
|
+
const init = call?.arguments[1];
|
|
126
|
+
if (!init || !ts.isObjectLiteralExpression(init))
|
|
127
|
+
return false;
|
|
128
|
+
const headers = propertyValue(ts, init, 'headers');
|
|
129
|
+
const accept = headers && ts.isObjectLiteralExpression(headers) ? propertyValue(ts, headers, 'accept') : null;
|
|
130
|
+
return Boolean(accept && ts.isStringLiteralLike(accept) && accept.text === 'text/event-stream');
|
|
131
|
+
}
|
|
131
132
|
function inspectTransportNode(scope, node) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
const { ts, kit, checker, file, isClient, owned, report } = scope;
|
|
134
|
+
const fetchUse = globalFetchUse(ts, kit, checker, node);
|
|
135
|
+
if (fetchUse !== null) {
|
|
136
|
+
if (isClient)
|
|
137
|
+
return false;
|
|
138
|
+
if (file.slot === STREAM_SLOT) {
|
|
139
|
+
if (!asksForEventStream(ts, node))
|
|
140
|
+
report(file, node, `${file.rel} fetches something other than an event stream; the stream reader folder reads server-sent events only (accept: "text/event-stream"), every other request is an operation of modules/api run by Apollo or axios.`);
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (fetchUse === 'property')
|
|
144
|
+
report(file, node, `${node.getText(file.sourceFile)} reaches the global fetch outside the transport client; ${owned}`);
|
|
145
|
+
else
|
|
146
|
+
report(file, node, `fetch is used outside the transport client (called, aliased or passed as a value); ${owned}`);
|
|
147
|
+
return false;
|
|
139
148
|
}
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
inspectLibraryImport({ ...scope, node });
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
+
if (!isClient && isApolloClientConstruction(ts, kit, checker, node))
|
|
150
|
+
report(file, node, `${file.rel} constructs an ApolloClient outside the transport client folder; ${owned}`);
|
|
151
|
+
inspectLibraryImport({ ...scope, node });
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
149
154
|
/** True when the operation imports the client folder, or (from an app) the api package that holds it. */
|
|
150
155
|
function reachesClient(graph, file, clientRels) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
return graph.edges.some((edge) => {
|
|
157
|
+
if (edge.from !== file.rel || !edge.runtime)
|
|
158
|
+
return false;
|
|
159
|
+
if (clientRels.has(edge.to))
|
|
160
|
+
return true;
|
|
161
|
+
return file.slot !== PACKAGE_API_SLOT && (graph.files.get(edge.to)?.slot ?? '').startsWith(PACKAGE_API_SLOT);
|
|
162
|
+
});
|
|
156
163
|
}
|
|
157
|
-
|
|
158
164
|
/** True for a stream operation of the app's api layer: `modules/api/sse/<area>/stream-<channel>.ts`. */
|
|
159
165
|
function isStreamOperation(file) {
|
|
160
|
-
|
|
166
|
+
return file.slot === 'fe.modules.api' && STREAM_OPERATION_FILE.test(path.posix.basename(file.rel)) && path.posix.basename(path.posix.dirname(path.posix.dirname(file.rel))) === 'sse';
|
|
161
167
|
}
|
|
162
|
-
|
|
163
168
|
/** True when the stream operation imports a file of the stream reader folder. */
|
|
164
169
|
function reachesStreamReader(graph, file) {
|
|
165
|
-
|
|
170
|
+
return graph.edges.some((edge) => edge.from === file.rel && edge.runtime && graph.files.get(edge.to)?.slot === STREAM_SLOT);
|
|
166
171
|
}
|
|
167
|
-
|
|
168
172
|
/** Only a stream operation (or the reader folder itself) imports the stream reader: a REST call, a GraphQL operation or a hook never does. */
|
|
169
173
|
function inspectReaderImporters({ files, graph, report }) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function inspectTransportFiles({ files, graph, kit, ts, clientRels, transport, owned, report }) {
|
|
180
|
-
const appsWithFiles = new Set();
|
|
181
|
-
let operations = 0;
|
|
182
|
-
for (const file of files) {
|
|
183
|
-
if (file.bindings?.app) appsWithFiles.add(file.bindings.app);
|
|
184
|
-
const scope = { ts, kit, checker: kit.checkerOf(file.sourceFile), file, isClient: clientRels.has(file.rel), transport, owned, report };
|
|
185
|
-
kit.walk(file.sourceFile, node => inspectTransportNode(scope, node));
|
|
186
|
-
if (OPERATION_SLOTS.has(file.slot) && OPERATION_FILE.test(path.posix.basename(file.rel))) {
|
|
187
|
-
operations += 1;
|
|
188
|
-
if (!reachesClient(graph, file, clientRels)) report(file, file.sourceFile, `${file.rel} is a GraphQL operation that does not import the transport client; an operation runs through the repository's one Apollo client, never through its own transport.`);
|
|
174
|
+
const byRel = new Map(files.map((file) => [file.rel, file]));
|
|
175
|
+
for (const edge of graph.edges) {
|
|
176
|
+
if (!edge.runtime || graph.files.get(edge.to)?.slot !== STREAM_SLOT)
|
|
177
|
+
continue;
|
|
178
|
+
const from = byRel.get(edge.from);
|
|
179
|
+
if (!from || from.slot === STREAM_SLOT || isStreamOperation(from))
|
|
180
|
+
continue;
|
|
181
|
+
report(from, from.sourceFile, `${from.rel} imports the stream reader (modules/api/sse/clients); only a stream operation (sse/<area>/stream-<channel>.ts) reads a server-sent-events stream.`);
|
|
189
182
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
183
|
+
}
|
|
184
|
+
function inspectTransportFiles({ files, graph, kit, ts, clientRels, transport, owned, report }) {
|
|
185
|
+
const appsWithFiles = new Set();
|
|
186
|
+
let operations = 0;
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
if (file.bindings?.app)
|
|
189
|
+
appsWithFiles.add(file.bindings.app);
|
|
190
|
+
const scope = { ts, kit, checker: kit.checkerOf(file.sourceFile), file, isClient: clientRels.has(file.rel), transport, owned, report };
|
|
191
|
+
kit.walk(file.sourceFile, (node) => inspectTransportNode(scope, node));
|
|
192
|
+
if (OPERATION_SLOTS.has(file.slot) && OPERATION_FILE.test(path.posix.basename(file.rel))) {
|
|
193
|
+
operations += 1;
|
|
194
|
+
if (!reachesClient(graph, file, clientRels))
|
|
195
|
+
report(file, file.sourceFile, `${file.rel} is a GraphQL operation that does not import the transport client; an operation runs through the repository's one Apollo client, never through its own transport.`);
|
|
196
|
+
}
|
|
197
|
+
if (isStreamOperation(file)) {
|
|
198
|
+
operations += 1;
|
|
199
|
+
if (!reachesStreamReader(graph, file))
|
|
200
|
+
report(file, file.sourceFile, `${file.rel} is a stream operation that does not import the stream reader (modules/api/sse/clients); a stream operation runs on the transport client layer's reader, never on a fetch of its own.`);
|
|
201
|
+
}
|
|
193
202
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return { appsWithFiles, operations };
|
|
203
|
+
inspectReaderImporters({ files, graph, report });
|
|
204
|
+
return { appsWithFiles, operations };
|
|
197
205
|
}
|
|
198
|
-
|
|
199
206
|
/**
|
|
200
207
|
* The declared Next apps that call the back end: those holding a file of an api owner slot (modules/api, the app client, the app
|
|
201
208
|
* union) or importing a file of the api package. An app with neither shares no transport.
|
|
202
209
|
*/
|
|
203
210
|
function transportApps(nextApps, files, graph) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
const byRel = new Map(files.map((file) => [file.rel, file]));
|
|
212
|
+
const calling = new Set(files.filter((file) => API_OWNER_SLOTS.has(file.slot) && file.slot !== PACKAGE_API_SLOT).map((file) => file.bindings?.app));
|
|
213
|
+
for (const edge of graph.edges) {
|
|
214
|
+
const app = byRel.get(edge.from)?.bindings?.app;
|
|
215
|
+
if (app && (byRel.get(edge.to)?.slot ?? '').startsWith(PACKAGE_API_SLOT))
|
|
216
|
+
calling.add(app);
|
|
217
|
+
}
|
|
218
|
+
return nextApps.map((item) => item.name).filter((name) => calling.has(name));
|
|
219
|
+
}
|
|
213
220
|
/** One instance per client folder (its slot root), carried by the folder's first file. */
|
|
214
221
|
function clientInstances(clients) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
const byRoot = new Map();
|
|
223
|
+
for (const file of [...clients].sort((a, b) => a.rel.localeCompare(b.rel)))
|
|
224
|
+
if (!byRoot.has(file.root))
|
|
225
|
+
byRoot.set(file.root, file);
|
|
226
|
+
return [...byRoot.values()];
|
|
218
227
|
}
|
|
219
|
-
|
|
220
228
|
export function checkTransportOwner(input) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const { appsWithFiles, operations } = inspectTransportFiles({ files, graph, kit, ts, clientRels, transport, owned, report });
|
|
244
|
-
return { violations, coverage: { status: 'checked', apps: appsWithFiles.size, operations, clients: instances.length, outcomes: outcomes.length } };
|
|
229
|
+
const { graph } = input;
|
|
230
|
+
const kit = machineKit(input);
|
|
231
|
+
const { ts, resolver } = kit;
|
|
232
|
+
const violations = [];
|
|
233
|
+
const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
234
|
+
const nextApps = resolver.repo.apps.filter((item) => item.kind === 'next');
|
|
235
|
+
const files = [...graph.files.values()].filter((file) => Boolean(file.slot) && file.tier !== 'e2e').map((file) => {
|
|
236
|
+
const classified = resolver.classifyPath(file.rel);
|
|
237
|
+
return { ...file, root: classified.root ?? file.rel, bindings: classified.bindings };
|
|
238
|
+
});
|
|
239
|
+
const clients = files.filter((file) => CLIENT_SLOTS.has(file.slot));
|
|
240
|
+
const instances = clientInstances(clients);
|
|
241
|
+
const outcomes = files.filter((file) => resolver.slot(file.slot)?.outcomeHome === true).map((file) => ({ ...file, root: file.rel }));
|
|
242
|
+
const clientRels = new Set(clients.map((file) => file.rel));
|
|
243
|
+
const transport = instances.length ? instances.map((item) => item.root).join(', ') : 'no client exists yet';
|
|
244
|
+
const owned = instances.length ? `the repository has one transport (${transport}). Call the back end through a modules/api operation and take its GraphQLResponse.` : NO_CLIENT;
|
|
245
|
+
// Exactly one client folder and one GraphQLResponse union per repository.
|
|
246
|
+
const calling = transportApps(nextApps, files, graph);
|
|
247
|
+
reportMultiplicity(instances, 'transport client', calling, report);
|
|
248
|
+
reportMultiplicity(outcomes, 'GraphQLResponse union', calling, report);
|
|
249
|
+
const { appsWithFiles, operations } = inspectTransportFiles({ files, graph, kit, ts, clientRels, transport, owned, report });
|
|
250
|
+
return { violations, coverage: { status: 'checked', apps: appsWithFiles.size, operations, clients: instances.length, outcomes: outcomes.length } };
|
|
245
251
|
}
|