@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,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
- return ts.isPropertyAccessExpression(node) && node.name.text === 'fetch' && ts.isIdentifier(node.expression) && GLOBAL_OBJECTS.has(node.expression.text);
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
- return (ts.isPropertyAssignment(parent) || ts.isPropertyDeclaration(parent) || ts.isMethodDeclaration(parent) || ts.isBindingElement(parent) || ts.isParameter(parent) || ts.isVariableDeclaration(parent)) && parent.name === node;
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
- return ts.isTypeQueryNode(parent) || ts.isQualifiedName(parent) || ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent) || ts.isPropertySignature(parent);
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
- if (!ts.isIdentifier(node)) return isGlobalObjectFetch(ts, node);
66
- if (node.text !== 'fetch') return false;
67
- if (kit.importBinding(checker, node)) return false;
68
- const parent = node.parent;
69
- if (ts.isPropertyAccessExpression(parent) && parent.name === node) return false;
70
- // A type position (`typeof fetch`, `typeof globalThis.fetch`) names the type of fetch and sends nothing.
71
- if (isTypeOrImportPosition(ts, parent)) return false;
72
- if (isDeclarationName(ts, parent, node)) return false;
73
- const declarations = kit.declarationsOf(checker, node);
74
- return declarations.every(declaration => declaration.getSourceFile().isDeclarationFile);
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
- const list = items.map(item => item.root).join(', ');
80
- for (const item of items) {
81
- if (items.length > 1) {
82
- 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.`);
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/).`);
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
- if (ts.isPropertyAccessExpression(node) && isGlobalFetch(ts, kit, checker, node)) return 'property';
91
- if (ts.isIdentifier(node) && isGlobalFetch(ts, kit, checker, node)) return 'identifier';
92
- return null;
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
- if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) return node.moduleSpecifier;
97
- if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === 'require'))) return node.arguments[0];
98
- return null;
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
- if (!ts.isNewExpression(node)) return false;
103
- const binding = kit.importBinding(checker, node.expression);
104
- return Boolean(binding?.name === 'ApolloClient' && binding.module.startsWith('@apollo/client'));
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
- const specifier = moduleSpecifierOf(ts, node);
112
- if (!specifier || !ts.isStringLiteralLike(specifier)) return;
113
- const library = specifier.text.split('/')[0];
114
- if (!HTTP_LIBRARIES.has(library) || (library === REST_LIBRARY && (API_OWNER_SLOTS.has(file.slot) || isAuthDoor(file)))) return;
115
- const where = library === REST_LIBRARY
116
- ? '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'
117
- : `the transport is Apollo GraphQL (${transport}) with axios for the rest calls of modules/api/rest`;
118
- report(file, node, `${specifier.text} is a second HTTP transport in ${file.rel}; ${where}.`, { library: specifier.text });
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
- const call = node.parent && ts.isCallExpression(node.parent) && node.parent.expression === node ? node.parent : null;
124
- const init = call?.arguments[1];
125
- if (!init || !ts.isObjectLiteralExpression(init)) return false;
126
- const headers = propertyValue(ts, init, 'headers');
127
- const accept = headers && ts.isObjectLiteralExpression(headers) ? propertyValue(ts, headers, 'accept') : null;
128
- return Boolean(accept && ts.isStringLiteralLike(accept) && accept.text === 'text/event-stream');
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
- const { ts, kit, checker, file, isClient, owned, report } = scope;
133
- const fetchUse = globalFetchUse(ts, kit, checker, node);
134
- if (fetchUse !== null) {
135
- if (isClient) return false;
136
- if (file.slot === STREAM_SLOT) {
137
- if (!asksForEventStream(ts, node)) 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.`);
138
- return false;
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 (fetchUse === 'property') report(file, node, `${node.getText(file.sourceFile)} reaches the global fetch outside the transport client; ${owned}`);
141
- else report(file, node, `fetch is used outside the transport client (called, aliased or passed as a value); ${owned}`);
142
- return false;
143
- }
144
- if (!isClient && isApolloClientConstruction(ts, kit, checker, node)) report(file, node, `${file.rel} constructs an ApolloClient outside the transport client folder; ${owned}`);
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
- return graph.edges.some(edge => {
152
- if (edge.from !== file.rel || !edge.runtime) return false;
153
- if (clientRels.has(edge.to)) return true;
154
- return file.slot !== PACKAGE_API_SLOT && (graph.files.get(edge.to)?.slot ?? '').startsWith(PACKAGE_API_SLOT);
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
- 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';
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
- return graph.edges.some(edge => edge.from === file.rel && edge.runtime && graph.files.get(edge.to)?.slot === STREAM_SLOT);
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
- const byRel = new Map(files.map(file => [file.rel, file]));
171
- for (const edge of graph.edges) {
172
- if (!edge.runtime || graph.files.get(edge.to)?.slot !== STREAM_SLOT) continue;
173
- const from = byRel.get(edge.from);
174
- if (!from || from.slot === STREAM_SLOT || isStreamOperation(from)) continue;
175
- 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.`);
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
- if (isStreamOperation(file)) {
191
- operations += 1;
192
- if (!reachesStreamReader(graph, file)) 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.`);
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
- inspectReaderImporters({ files, graph, report });
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
- const byRel = new Map(files.map(file => [file.rel, file]));
205
- const calling = new Set(files.filter(file => API_OWNER_SLOTS.has(file.slot) && file.slot !== PACKAGE_API_SLOT).map(file => file.bindings?.app));
206
- for (const edge of graph.edges) {
207
- const app = byRel.get(edge.from)?.bindings?.app;
208
- if (app && (byRel.get(edge.to)?.slot ?? '').startsWith(PACKAGE_API_SLOT)) calling.add(app);
209
- }
210
- return nextApps.map(item => item.name).filter(name => calling.has(name));
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
- const byRoot = new Map();
216
- for (const file of [...clients].sort((a, b) => a.rel.localeCompare(b.rel))) if (!byRoot.has(file.root)) byRoot.set(file.root, file);
217
- return [...byRoot.values()];
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
- const { graph } = input;
222
- const kit = machineKit(input);
223
- const { ts, resolver } = kit;
224
- const violations = [];
225
- const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
226
- const nextApps = resolver.repo.apps.filter(item => item.kind === 'next');
227
- const files = [...graph.files.values()].filter(file => file.slot && file.tier !== 'e2e').map(file => {
228
- const classified = resolver.classifyPath(file.rel);
229
- return { ...file, root: classified.root ?? file.rel, bindings: classified.bindings };
230
- });
231
- const clients = files.filter(file => CLIENT_SLOTS.has(file.slot));
232
- const instances = clientInstances(clients);
233
- const outcomes = files.filter(file => resolver.slot(file.slot)?.outcomeHome === true).map(file => ({ ...file, root: file.rel }));
234
- const clientRels = new Set(clients.map(file => file.rel));
235
- const transport = instances.length ? instances.map(item => item.root).join(', ') : 'no client exists yet';
236
- 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;
237
-
238
- // Exactly one client folder and one GraphQLResponse union per repository.
239
- const calling = transportApps(nextApps, files, graph);
240
- reportMultiplicity(instances, 'transport client', calling, report);
241
- reportMultiplicity(outcomes, 'GraphQLResponse union', calling, report);
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
  }