@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +8 -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,176 +1,192 @@
1
- // Infer lexical request identities for SWR hooks without a declared lifecycle contract.
2
1
  import { unwrapExpression } from './typescript.mjs';
3
2
  import { anyDescendant, normalizedSymbol } from './ast-walks.mjs';
4
3
  import { sourceLocation } from '../../lib/ts-ast.mjs';
5
4
  import { functionNode, constInitializer, inferredSymbol } from './next-data-symbols.mjs';
6
-
7
- export function inferredFetcher(ts, checker, expression, seen = new Set()) {
8
- if (!expression) return null;
9
- expression = unwrapExpression(ts, expression);
10
- if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) return expression;
11
- const symbol = normalizedSymbol(ts, checker, expression);
12
- if (!symbol || seen.has(symbol)) return null;
13
- for (const declaration of symbol.getDeclarations?.() ?? []) {
14
- const fn = functionNode(ts, declaration);
15
- if (fn) return fn;
16
- }
17
- const initializer = constInitializer(ts, symbol);
18
- return initializer ? inferredFetcher(ts, checker, initializer, new Set(seen).add(symbol)) : null;
19
- }
20
-
5
+ export function inferredFetcher(ts, checker, input, seen = new Set()) {
6
+ if (!input)
7
+ return null;
8
+ const expression = unwrapExpression(ts, input);
9
+ if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression))
10
+ return expression;
11
+ const symbol = normalizedSymbol(ts, checker, expression);
12
+ if (!symbol || seen.has(symbol))
13
+ return null;
14
+ for (const declaration of symbol.getDeclarations?.() ?? []) {
15
+ const fn = functionNode(ts, declaration);
16
+ if (fn)
17
+ return fn;
18
+ }
19
+ const initializer = constInitializer(ts, symbol);
20
+ return initializer ? inferredFetcher(ts, checker, initializer, new Set(seen).add(symbol)) : null;
21
+ }
21
22
  function importedIdentityReference(ts, checker, expression) {
22
- const reference = ts.isShorthandPropertyAssignment(expression.parent)
23
- ? checker.getShorthandAssignmentValueSymbol(expression.parent) : checker.getSymbolAtLocation(expression);
24
- return (reference?.getDeclarations?.() ?? []).some(declaration => ts.isImportSpecifier(declaration)
25
- || ts.isImportClause(declaration) || ts.isNamespaceImport(declaration) || ts.isImportEqualsDeclaration(declaration));
23
+ const reference = ts.isShorthandPropertyAssignment(expression.parent)
24
+ ? checker.getShorthandAssignmentValueSymbol(expression.parent) : checker.getSymbolAtLocation(expression);
25
+ return (reference?.getDeclarations?.() ?? []).some(declaration => ts.isImportSpecifier(declaration)
26
+ || ts.isImportClause(declaration) || ts.isNamespaceImport(declaration) || ts.isImportEqualsDeclaration(declaration));
26
27
  }
27
-
28
28
  function identifierIdentityAccess(ts, checker, expression, seen) {
29
- const imported = importedIdentityReference(ts, checker, expression);
30
- const symbol = inferredSymbol(ts, checker, expression);
31
- const initializer = symbol && !seen.has(symbol) ? constInitializer(ts, symbol) : null;
32
- if (initializer) {
33
- const alias = identityAccess(ts, checker, initializer, new Set(seen).add(symbol));
34
- if (alias) return { ...alias, imported: imported || alias.imported };
35
- }
36
- return { symbol, parts: [expression.text], imported };
37
- }
38
-
29
+ const imported = importedIdentityReference(ts, checker, expression);
30
+ const symbol = inferredSymbol(ts, checker, expression);
31
+ const initializer = symbol && !seen.has(symbol) ? constInitializer(ts, symbol) : null;
32
+ if (initializer && symbol) {
33
+ const alias = identityAccess(ts, checker, initializer, new Set(seen).add(symbol));
34
+ if (alias)
35
+ return { ...alias, imported: imported || alias.imported };
36
+ }
37
+ return { symbol, parts: [expression.text], imported };
38
+ }
39
39
  function isSelectedMember(ts, expression) {
40
- return ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)
41
- && ts.isStringLiteralLike(expression.argumentExpression);
40
+ return ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)
41
+ && ts.isStringLiteralLike(expression.argumentExpression);
42
42
  }
43
-
44
43
  function selectedMemberKey(ts, expression) {
45
- return ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
46
- }
47
-
48
- function identityAccess(ts, checker, expression, seen = new Set()) {
49
- expression = unwrapExpression(ts, expression);
50
- if (ts.isIdentifier(expression)) return identifierIdentityAccess(ts, checker, expression, seen);
51
- if (isSelectedMember(ts, expression)) {
52
- const base = identityAccess(ts, checker, expression.expression, seen);
53
- return base ? { ...base, parts: [...base.parts, selectedMemberKey(ts, expression)] } : null;
54
- }
55
- return null;
56
- }
57
-
44
+ return ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
45
+ }
46
+ function identityAccess(ts, checker, input, seen = new Set()) {
47
+ const expression = unwrapExpression(ts, input);
48
+ if (ts.isIdentifier(expression))
49
+ return identifierIdentityAccess(ts, checker, expression, seen);
50
+ if (isSelectedMember(ts, expression)) {
51
+ const base = identityAccess(ts, checker, expression.expression, seen);
52
+ return base ? { ...base, parts: [...base.parts, selectedMemberKey(ts, expression)] } : null;
53
+ }
54
+ return null;
55
+ }
58
56
  function containerWritten(ts, checker, symbol, source) {
59
- const rootSymbol = expression => {
60
- expression = unwrapExpression(ts, expression);
61
- while (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) expression = unwrapExpression(ts, expression.expression);
62
- return ts.isIdentifier(expression) ? inferredSymbol(ts, checker, expression) : null;
63
- };
64
- return anyDescendant(ts, source, node => {
65
- if (ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment
66
- && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment) return rootSymbol(node.left) === symbol;
67
- if (ts.isDeleteExpression(node)) return rootSymbol(node.expression) === symbol;
68
- if (ts.isPostfixUnaryExpression(node) || ts.isPrefixUnaryExpression(node)
69
- && [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken].includes(node.operator)) return rootSymbol(node.operand) === symbol;
70
- return false;
71
- });
72
- }
73
-
57
+ const incrementOperators = [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken];
58
+ const rootSymbol = (input) => {
59
+ let expression = unwrapExpression(ts, input);
60
+ while (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression))
61
+ expression = unwrapExpression(ts, expression.expression);
62
+ return ts.isIdentifier(expression) ? inferredSymbol(ts, checker, expression) : null;
63
+ };
64
+ return anyDescendant(ts, source, (node) => {
65
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment
66
+ && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment)
67
+ return rootSymbol(node.left) === symbol;
68
+ if (ts.isDeleteExpression(node))
69
+ return rootSymbol(node.expression) === symbol;
70
+ if (ts.isPostfixUnaryExpression(node) || ts.isPrefixUnaryExpression(node)
71
+ && incrementOperators.includes(node.operator))
72
+ return rootSymbol(node.operand) === symbol;
73
+ return false;
74
+ });
75
+ }
74
76
  function selectedRequestAlias(ts, checker, expression, seen) {
75
- const symbol = inferredSymbol(ts, checker, expression);
76
- const initializer = symbol && !seen.has(symbol) ? constInitializer(ts, symbol) : null;
77
- if (!initializer) return null;
78
- const value = unwrapExpression(ts, initializer);
79
- if (ts.isObjectLiteralExpression(value) && (initializer.getSourceFile() !== expression.getSourceFile()
80
- || containerWritten(ts, checker, symbol, expression.getSourceFile()))) return null;
81
- if (ts.isObjectLiteralExpression(value) || ts.isIdentifier(value) || ts.isPropertyAccessExpression(value)
82
- || ts.isElementAccessExpression(value)) return { symbol, value };
83
- return null;
84
- }
85
-
77
+ const symbol = inferredSymbol(ts, checker, expression);
78
+ const initializer = symbol && !seen.has(symbol) ? constInitializer(ts, symbol) : null;
79
+ if (!initializer || !symbol)
80
+ return null;
81
+ const value = unwrapExpression(ts, initializer);
82
+ if (ts.isObjectLiteralExpression(value) && (initializer.getSourceFile() !== expression.getSourceFile()
83
+ || containerWritten(ts, checker, symbol, expression.getSourceFile())))
84
+ return null;
85
+ if (ts.isObjectLiteralExpression(value) || ts.isIdentifier(value) || ts.isPropertyAccessExpression(value)
86
+ || ts.isElementAccessExpression(value))
87
+ return { symbol, value };
88
+ return null;
89
+ }
86
90
  function selectedRequestProperty(ts, object, key) {
87
- if (!ts.isObjectLiteralExpression(object) || !object.properties.every(property => ts.isPropertyAssignment(property)
88
- || ts.isShorthandPropertyAssignment(property))) return null;
89
- return [...object.properties].reverse().find(candidate => (ts.isIdentifier(candidate.name)
90
- || ts.isStringLiteralLike(candidate.name)) && candidate.name.text === key) ?? null;
91
- }
92
-
93
- function selectedRequestValue(ts, checker, expression, seen = new Set()) {
94
- expression = unwrapExpression(ts, expression);
95
- if (ts.isIdentifier(expression)) {
96
- const alias = selectedRequestAlias(ts, checker, expression, seen);
97
- return alias ? selectedRequestValue(ts, checker, alias.value, new Set(seen).add(alias.symbol)) : expression;
98
- }
99
- if (!isSelectedMember(ts, expression)) return expression;
100
- const object = selectedRequestValue(ts, checker, expression.expression, seen);
101
- const property = selectedRequestProperty(ts, object, selectedMemberKey(ts, expression));
102
- if (!property) return expression;
103
- const value = ts.isShorthandPropertyAssignment(property) ? property.name : property.initializer;
104
- return selectedRequestValue(ts, checker, value, seen);
105
- }
106
-
91
+ if (!ts.isObjectLiteralExpression(object) || !object.properties.every((property) => ts.isPropertyAssignment(property)
92
+ || ts.isShorthandPropertyAssignment(property)))
93
+ return null;
94
+ return [...object.properties].reverse().find(candidate => (ts.isIdentifier(candidate.name)
95
+ || ts.isStringLiteralLike(candidate.name)) && candidate.name.text === key) ?? null;
96
+ }
97
+ function selectedRequestValue(ts, checker, input, seen = new Set()) {
98
+ const expression = unwrapExpression(ts, input);
99
+ if (ts.isIdentifier(expression)) {
100
+ const alias = selectedRequestAlias(ts, checker, expression, seen);
101
+ return alias ? selectedRequestValue(ts, checker, alias.value, new Set(seen).add(alias.symbol)) : expression;
102
+ }
103
+ if (!isSelectedMember(ts, expression))
104
+ return expression;
105
+ const object = selectedRequestValue(ts, checker, expression.expression, seen);
106
+ const property = selectedRequestProperty(ts, object, selectedMemberKey(ts, expression));
107
+ if (!property)
108
+ return expression;
109
+ const value = ts.isShorthandPropertyAssignment(property) ? property.name : property.initializer;
110
+ return selectedRequestValue(ts, checker, value, seen);
111
+ }
107
112
  function capturedInput(ts, access, region) {
108
- const declarations = access.symbol?.getDeclarations?.() ?? [];
109
- return declarations.some(declaration => {
110
- if (declaration.getSourceFile() === region.getSourceFile() && declaration.pos >= region.pos && declaration.end <= region.end) return false;
111
- if (declaration.getSourceFile().isDeclarationFile && !access.imported) return false;
112
- return access.imported || ts.isVariableDeclaration(declaration) || ts.isParameter(declaration) || ts.isBindingElement(declaration);
113
- });
114
- }
115
-
113
+ const declarations = access.symbol?.getDeclarations?.() ?? [];
114
+ return declarations.some(declaration => {
115
+ if (declaration.getSourceFile() === region.getSourceFile() && declaration.pos >= region.pos && declaration.end <= region.end)
116
+ return false;
117
+ if (declaration.getSourceFile().isDeclarationFile && !access.imported)
118
+ return false;
119
+ return access.imported || ts.isVariableDeclaration(declaration) || ts.isParameter(declaration) || ts.isBindingElement(declaration);
120
+ });
121
+ }
116
122
  function capturedIdentityAlias(ts, access, seen) {
117
- // Follow transparent aliases and request objects, so {id} and an alias of id carry the same identity.
118
- if (access.parts.length !== 1 || seen.has(access.symbol)) return null;
119
- const initializer = constInitializer(ts, access.symbol);
120
- if (!initializer) return null;
121
- const value = unwrapExpression(ts, initializer);
122
- return ts.isCallExpression(value) || ts.isAwaitExpression(value) || ts.isNewExpression(value) ? null : value;
123
- }
124
-
123
+ // Follow transparent aliases and request objects, so {id} and an alias of id carry the same identity.
124
+ if (access.parts.length !== 1 || (access.symbol ? seen.has(access.symbol) : false))
125
+ return null;
126
+ const initializer = constInitializer(ts, access.symbol);
127
+ if (!initializer)
128
+ return null;
129
+ const value = unwrapExpression(ts, initializer);
130
+ return ts.isCallExpression(value) || ts.isAwaitExpression(value) || ts.isNewExpression(value) ? null : value;
131
+ }
125
132
  function recordInferredIdentity(scope, access, seen, visit) {
126
- const { ts, call, region, reasons, identities } = scope;
127
- if (access?.imported && !(access.symbol?.getDeclarations?.() ?? []).length) {
128
- reasons.push(`${call.source.fileName}:${sourceLocation(call.source, call.node).line} imported SWR request input ${access.parts.join('.')} cannot be resolved; dataLifecycle is required to declare identities`);
133
+ const { ts, call, region, reasons, identities } = scope;
134
+ if (access?.imported && !(access.symbol?.getDeclarations?.() ?? []).length) {
135
+ reasons.push(`${call.source.fileName}:${sourceLocation(call.source, call.node).line} imported SWR request input ${access.parts.join('.')} cannot be resolved; dataLifecycle is required to declare identities`);
136
+ return true;
137
+ }
138
+ if (!access || !capturedInput(ts, access, region))
139
+ return false;
140
+ const alias = capturedIdentityAlias(ts, access, seen);
141
+ if (alias && access.symbol)
142
+ visit(alias, new Set(seen).add(access.symbol));
143
+ else {
144
+ const binding = access.parts.join('.');
145
+ identities.set(binding, { id: binding, binding, ...access, gatesRequest: false, resource: call.kind === 'mutation' });
146
+ }
129
147
  return true;
130
- }
131
- if (!access || !capturedInput(ts, access, region)) return false;
132
- const alias = capturedIdentityAlias(ts, access, seen);
133
- if (alias) visit(alias, new Set(seen).add(access.symbol));
134
- else {
135
- const binding = access.parts.join('.');
136
- identities.set(binding, { id: binding, binding, ...access, gatesRequest: false, resource: call.kind === 'mutation' });
137
- }
138
- return true;
139
- }
140
-
148
+ }
141
149
  function visitRequestChildren(ts, node, seen, visit) {
142
- if (ts.isPropertyAssignment(node)) { visit(node.initializer, seen); return; }
143
- // A method name is not a request input; its receiver and arguments can be.
144
- if (ts.isCallExpression(node)) {
145
- const callee = unwrapExpression(ts, node.expression);
146
- if (ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) visit(callee.expression, seen);
147
- for (const argument of node.arguments) visit(argument, seen);
148
- return;
149
- }
150
- if (ts.isVariableDeclaration(node)) {
151
- if (node.initializer) visit(node.initializer, seen);
152
- return;
153
- }
154
- ts.forEachChild(node, child => { visit(child, seen); });
155
- }
156
-
150
+ if (ts.isPropertyAssignment(node)) {
151
+ visit(node.initializer, seen);
152
+ return;
153
+ }
154
+ // A method name is not a request input; its receiver and arguments can be.
155
+ if (ts.isCallExpression(node)) {
156
+ const callee = unwrapExpression(ts, node.expression);
157
+ if (ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee))
158
+ visit(callee.expression, seen);
159
+ for (const argument of node.arguments)
160
+ visit(argument, seen);
161
+ return;
162
+ }
163
+ if (ts.isVariableDeclaration(node)) {
164
+ if (node.initializer)
165
+ visit(node.initializer, seen);
166
+ return;
167
+ }
168
+ ts.forEachChild(node, (child) => { visit(child, seen); });
169
+ }
157
170
  /** Infer lexical request inputs; parameters declared inside the fetcher are supplied by SWR. */
158
171
  export function inferredIdentities(context, call, region, reasons) {
159
- const { ts } = context;
160
- const identities = new Map();
161
- const scope = { ts, call, region, reasons, identities };
162
- const visit = (node, seen = new Set()) => {
163
- const selectedValue = selectedRequestValue(ts, call.checker, node);
164
- if (selectedValue !== node && selectedValue !== unwrapExpression(ts, node)) { visit(selectedValue, seen); return; }
165
- if (recordInferredIdentity(scope, identityAccess(ts, call.checker, node), seen, visit)) return;
166
- visitRequestChildren(ts, node, seen, visit);
167
- };
168
- visit(region.body ?? region);
169
- return [...identities.values()];
170
- }
171
-
172
+ const { ts } = context;
173
+ const identities = new Map();
174
+ const scope = { ts, call, region, reasons, identities };
175
+ const visit = (node, seen = new Set()) => {
176
+ const selectedValue = selectedRequestValue(ts, call.checker, node);
177
+ if (selectedValue !== node && selectedValue !== unwrapExpression(ts, node)) {
178
+ visit(selectedValue, seen);
179
+ return;
180
+ }
181
+ if (recordInferredIdentity(scope, identityAccess(ts, call.checker, node), seen, visit))
182
+ return;
183
+ visitRequestChildren(ts, node, seen, visit);
184
+ };
185
+ visit(region.body ?? region);
186
+ return [...identities.values()];
187
+ }
172
188
  export function inferredKeyBindings(context, call, reasons) {
173
- const key = call.node.arguments[0];
174
- // A key or its null guard can contain bindings that are not captured request inputs.
175
- return key ? inferredIdentities(context, call, key, reasons).map(identity => ({ ...identity, id: `key:${identity.id}`, resource: false })) : [];
189
+ const key = call.node.arguments[0];
190
+ // A key or its null guard can contain bindings that are not captured request inputs.
191
+ return key ? inferredIdentities(context, call, key, reasons).map(identity => ({ ...identity, id: `key:${identity.id}`, resource: false })) : [];
176
192
  }