@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
@@ -2,177 +2,187 @@ import path from 'node:path';
2
2
  import { canonical } from './config.mjs';
3
3
  import { hasAnyFlag, sourceLocation } from '../../lib/ts-ast.mjs';
4
4
  import { byCodeUnit } from '../../lib/list.mjs';
5
-
6
5
  const HELPER_DEPTH = 4;
7
-
8
6
  const checkerOf = (env, sourceFile) => env.context.checkerFor(sourceFile.fileName);
9
-
10
7
  function aliased(env, checker, symbol) {
11
- const { ts } = env;
12
- const seen = new Set();
13
- let current = symbol;
14
- while (current && hasAnyFlag(current.flags, ts.SymbolFlags.Alias) && !seen.has(current)) {
15
- seen.add(current);
16
- let target;
17
- try { target = checker.getAliasedSymbol(current); } catch { break; }
18
- if (!target || target === current || !(target.declarations?.length)) break;
19
- current = target;
20
- }
21
- return current;
22
- }
23
-
8
+ const { ts } = env;
9
+ const seen = new Set();
10
+ let current = symbol;
11
+ while (current && hasAnyFlag(current.flags, ts.SymbolFlags.Alias) && !seen.has(current)) {
12
+ seen.add(current);
13
+ let target;
14
+ try {
15
+ target = checker.getAliasedSymbol(current);
16
+ }
17
+ catch {
18
+ break;
19
+ }
20
+ if (!target || target === current || !(target.declarations?.length))
21
+ break;
22
+ current = target;
23
+ }
24
+ return current;
25
+ }
24
26
  function symbolAt(env, checker, node) {
25
- const { ts } = env;
26
- if (!node) return null;
27
- if (ts.isShorthandPropertyAssignment(node.parent ?? {}) && node.parent.name === node) return checker.getShorthandAssignmentValueSymbol(node.parent) ?? null;
28
- return checker.getSymbolAtLocation(node) ?? null;
27
+ const { ts } = env;
28
+ if (!node)
29
+ return null;
30
+ const parent = node.parent;
31
+ if (parent && ts.isShorthandPropertyAssignment(parent) && parent.name === node)
32
+ return checker.getShorthandAssignmentValueSymbol(parent) ?? null;
33
+ return checker.getSymbolAtLocation(node) ?? null;
29
34
  }
30
-
31
35
  /** {name, module} when `target` is bound directly by an import specifier, default import or namespace import, else null. */
32
36
  function ownImportBinding(env, checker, target) {
33
- const { ts } = env;
34
- const declaration = symbolAt(env, checker, target)?.declarations?.[0];
35
- if (!declaration) return null;
36
- if (ts.isImportSpecifier(declaration)) return { name: (declaration.propertyName ?? declaration.name).text, module: declaration.parent.parent.parent.moduleSpecifier.text };
37
- if (ts.isImportClause(declaration)) return { name: 'default', module: declaration.parent.moduleSpecifier.text };
38
- if (ts.isNamespaceImport(declaration)) return { name: '*', module: declaration.parent.parent.moduleSpecifier.text };
39
- return null;
40
- }
41
-
37
+ const { ts } = env;
38
+ const declaration = symbolAt(env, checker, target)?.declarations?.[0];
39
+ if (!declaration)
40
+ return null;
41
+ // The module specifier of an import declaration is always a string literal in a program that parses.
42
+ if (ts.isImportSpecifier(declaration))
43
+ return { name: (declaration.propertyName ?? declaration.name).text, module: declaration.parent.parent.parent.moduleSpecifier.text };
44
+ if (ts.isImportClause(declaration))
45
+ return { name: 'default', module: declaration.parent.moduleSpecifier.text };
46
+ if (ts.isNamespaceImport(declaration))
47
+ return { name: '*', module: declaration.parent.parent.moduleSpecifier.text };
48
+ return null;
49
+ }
42
50
  /** {name, module} when `node` (identifier, or namespace.member) is bound by an import from a module specifier, else null. */
43
51
  function importBinding(env, checker, node) {
44
- const { ts } = env;
45
- if (ts.isIdentifier(node)) return ownImportBinding(env, checker, node);
46
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
47
- const namespace = ownImportBinding(env, checker, node.expression);
48
- return namespace?.name === '*' ? { name: node.name.text, module: namespace.module } : null;
49
- }
50
- return null;
51
- }
52
-
52
+ const { ts } = env;
53
+ if (ts.isIdentifier(node))
54
+ return ownImportBinding(env, checker, node);
55
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
56
+ const namespace = ownImportBinding(env, checker, node.expression);
57
+ return namespace?.name === '*' ? { name: node.name.text, module: namespace.module } : null;
58
+ }
59
+ return null;
60
+ }
53
61
  function isImportOf(env, checker, node, name, moduleName) {
54
- const binding = importBinding(env, checker, node);
55
- return Boolean(binding) && binding.name === name && binding.module === moduleName;
62
+ const binding = importBinding(env, checker, node);
63
+ return binding !== null && binding.name === name && binding.module === moduleName;
56
64
  }
57
-
58
65
  /** The declarations `node` resolves to through aliases. */
59
66
  const declarationsOf = (env, checker, node) => aliased(env, checker, symbolAt(env, checker, node))?.declarations ?? [];
60
-
61
67
  /** The repository-relative graph path of the file declaring `declaration`, or null when it is outside the program. */
62
68
  const graphPath = (env, declaration) => env.graph.abs(canonical(declaration.getSourceFile().fileName));
63
-
64
69
  const graphFile = (env, rel) => env.graph.files.get(rel) ?? null;
65
-
66
70
  /** The capability (owner) root, slot and tier of a declaration, or null. */
67
71
  function ownerOfDeclaration(env, declaration) {
68
- const rel = graphPath(env, declaration);
69
- const file = rel ? graphFile(env, rel) : null;
70
- return file?.owner ? { rel, root: file.owner.root, slot: file.owner.slot, tier: file.tier, name: path.posix.basename(file.owner.root) } : null;
72
+ const rel = graphPath(env, declaration);
73
+ const file = rel ? graphFile(env, rel) : null;
74
+ return rel && file?.owner ? { rel, root: file.owner.root, slot: file.owner.slot, tier: file.tier, name: path.posix.basename(file.owner.root) } : null;
71
75
  }
72
-
73
76
  /** The string a node evaluates to: a literal, or a const whose type is a string literal. */
74
77
  function stringValue(env, checker, node) {
75
- const { ts } = env;
76
- if (!node) return null;
77
- if (ts.isStringLiteralLike(node)) return node.text;
78
- let type;
79
- try { type = checker.getTypeAtLocation(node); } catch { return null; }
80
- if (type?.isStringLiteral?.()) return type.value;
81
- const declaration = declarationsOf(env, checker, ts.isPropertyAccessExpression(node) ? node.name : node)[0];
82
- if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer) return stringValue(env, checker, declaration.initializer);
83
- return null;
84
- }
85
-
78
+ const { ts } = env;
79
+ if (!node)
80
+ return null;
81
+ if (ts.isStringLiteralLike(node))
82
+ return node.text;
83
+ let type;
84
+ try {
85
+ type = checker.getTypeAtLocation(node);
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ if (type?.isStringLiteral?.())
91
+ return type.value;
92
+ const declaration = declarationsOf(env, checker, ts.isPropertyAccessExpression(node) ? node.name : node)[0];
93
+ if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer)
94
+ return stringValue(env, checker, declaration.initializer);
95
+ return null;
96
+ }
86
97
  function walk(env, node, visit) {
87
- const step = child => {
88
- if (visit(child) === false) return;
89
- env.ts.forEachChild(child, step);
90
- };
91
- step(node);
98
+ const step = (child) => {
99
+ if (visit(child) === false)
100
+ return;
101
+ env.ts.forEachChild(child, step);
102
+ };
103
+ step(node);
92
104
  }
93
-
94
105
  const decorators = (env, node) => (env.ts.canHaveDecorators?.(node) ? env.ts.getDecorators(node) ?? [] : []);
106
+ // reason: getCombinedModifierFlags reads only the modifiers, which a VariableStatement carries as well as a Declaration.
95
107
  const isExported = (env, node) => hasAnyFlag(env.ts.getCombinedModifierFlags?.(node), env.ts.ModifierFlags.Export);
96
-
97
108
  function propertyNameText(env, name) {
98
- if (!name) return null;
99
- if (env.ts.isIdentifier(name) || env.ts.isStringLiteralLike(name)) return name.text;
100
- return null;
109
+ if (!name)
110
+ return null;
111
+ if (env.ts.isIdentifier(name) || env.ts.isStringLiteralLike(name))
112
+ return name.text;
113
+ return null;
101
114
  }
102
-
103
115
  /** The object literal properties of `literal` by static name. */
104
116
  const propertyOf = (env, literal, key) => literal.properties
105
- .find(property => (env.ts.isPropertyAssignment(property) || env.ts.isShorthandPropertyAssignment(property)) && propertyNameText(env, property.name) === key);
106
-
117
+ .find((property) => (env.ts.isPropertyAssignment(property) || env.ts.isShorthandPropertyAssignment(property)) && propertyNameText(env, property.name) === key);
107
118
  const valueOfProperty = (env, property) => (env.ts.isPropertyAssignment(property) ? property.initializer : property.name);
108
-
109
- const at = (env, rel, sourceFile, node, extra = {}) => ({ path: rel, ...sourceLocation(sourceFile, node), ...extra });
110
-
119
+ const at = (_env, rel, sourceFile, node, extra = {}) => ({ path: rel, ...sourceLocation(sourceFile, node), ...extra });
111
120
  /** The app root file of an app (apps/<name>/src/app.module.ts), or null when the program does not hold it. */
112
121
  const appRoot = (env, name) => graphFile(env, `apps/${name}/src/app.module.ts`);
113
-
114
122
  /**
115
123
  * Whether a repository-relative file is a composition group of an app: `apps/<app>/src/compose/<area>.ts`, the module list of
116
124
  * one area that the app root spreads into its imports (slot allows `compose/<area>.ts` of every be.app.* slot).
117
125
  */
118
- export const isComposeGroup = rel => /^apps\/[^/]+\/src\/compose\/[^/]+\.ts$/.test(rel) && !/\.(?:spec|d)\.ts$/.test(rel);
119
-
126
+ export const isComposeGroup = (rel) => /^apps\/[^/]+\/src\/compose\/[^/]+\.ts$/.test(rel) && !/\.(?:spec|d)\.ts$/.test(rel);
120
127
  /** The app root and the composition groups of an app, in path order (the root first); [] when the program holds no root. */
121
128
  const appCompositionFiles = (env, name) => {
122
- const root = appRoot(env, name);
123
- if (!root) return [];
124
- const prefix = `apps/${name}/src/compose/`;
125
- const groups = [...env.graph.files.values()].filter(file => file.rel.startsWith(prefix) && isComposeGroup(file.rel));
126
- return [root, ...groups.sort((a, b) => byCodeUnit(a.rel, b.rel))];
129
+ const root = appRoot(env, name);
130
+ if (!root)
131
+ return [];
132
+ const prefix = `apps/${name}/src/compose/`;
133
+ const groups = [...env.graph.files.values()].filter(file => file.rel.startsWith(prefix) && isComposeGroup(file.rel));
134
+ return [root, ...groups.sort((a, b) => byCodeUnit(a.rel, b.rel))];
127
135
  };
128
-
129
136
  /** The body a call or a spread identifier resolves to when it is a function or a const declared in a file of the program (not a package), else null. */
130
137
  function helperBodyOf(env, checker, node) {
131
- const { ts } = env;
132
- const target = ts.isCallExpression(node) ? node.expression : node;
133
- for (const declaration of declarationsOf(env, checker, ts.isPropertyAccessExpression(target) ? target.name : target)) {
134
- if (!graphPath(env, declaration)) continue;
135
- if (ts.isFunctionDeclaration(declaration) && declaration.body) return { declaration, body: declaration.body };
136
- if (ts.isVariableDeclaration(declaration) && declaration.initializer) return { declaration, body: declaration.initializer };
137
- }
138
- return null;
139
- }
140
-
138
+ const { ts } = env;
139
+ const target = ts.isCallExpression(node) ? node.expression : node;
140
+ for (const declaration of declarationsOf(env, checker, ts.isPropertyAccessExpression(target) ? target.name : target)) {
141
+ if (!graphPath(env, declaration))
142
+ continue;
143
+ if (ts.isFunctionDeclaration(declaration) && declaration.body)
144
+ return { declaration, body: declaration.body };
145
+ if (ts.isVariableDeclaration(declaration) && declaration.initializer)
146
+ return { declaration, body: declaration.initializer };
147
+ }
148
+ return null;
149
+ }
141
150
  /** The provider entry of an object literal that provides `name` imported from `moduleName`, or null. */
142
151
  function providerEntry(env, search, checker, literal, anchor) {
143
- const provide = propertyOf(env, literal, 'provide');
144
- if (!provide || !isImportOf(env, checker, valueOfProperty(env, provide), search.name, search.moduleName)) return null;
145
- const use = propertyOf(env, literal, 'useClass');
146
- return { node: anchor ?? literal, useClass: use ? valueOfProperty(env, use) : null, checker };
152
+ const provide = propertyOf(env, literal, 'provide');
153
+ if (!provide || !isImportOf(env, checker, valueOfProperty(env, provide), search.name, search.moduleName))
154
+ return null;
155
+ const use = propertyOf(env, literal, 'useClass');
156
+ return { node: anchor ?? literal, useClass: use ? valueOfProperty(env, use) : null, checker };
147
157
  }
148
-
149
158
  /** The expression that may reference a helper: the argument of a spread, or the call itself. */
150
159
  function helperReferenceOf(ts, node) {
151
- if (ts.isSpreadElement(node)) return node.expression;
152
- return ts.isCallExpression(node) ? node : null;
160
+ if (ts.isSpreadElement(node))
161
+ return node.expression;
162
+ return ts.isCallExpression(node) ? node : null;
153
163
  }
154
-
155
164
  function followHelper(env, search, checker, node, anchor, depth) {
156
- const reference = helperReferenceOf(env.ts, node);
157
- if (!reference || depth >= HELPER_DEPTH) return;
158
- const helper = helperBodyOf(env, checker, reference);
159
- if (!helper || search.seen.has(helper.declaration)) return;
160
- search.seen.add(helper.declaration);
161
- scanProviders(env, search, helper.body, anchor ?? node, depth + 1);
162
- }
163
-
165
+ const reference = helperReferenceOf(env.ts, node);
166
+ if (!reference || depth >= HELPER_DEPTH)
167
+ return;
168
+ const helper = helperBodyOf(env, checker, reference);
169
+ if (!helper || search.seen.has(helper.declaration))
170
+ return;
171
+ search.seen.add(helper.declaration);
172
+ scanProviders(env, search, helper.body, anchor ?? node, depth + 1);
173
+ }
164
174
  function scanProviders(env, search, root, anchor, depth) {
165
- const checker = checkerOf(env, root.getSourceFile());
166
- walk(env, root, node => {
167
- if (!env.ts.isObjectLiteralExpression(node)) {
168
- followHelper(env, search, checker, node, anchor, depth);
169
- return;
170
- }
171
- const entry = providerEntry(env, search, checker, node, anchor);
172
- if (entry) search.found.push(entry);
173
- });
175
+ const checker = checkerOf(env, root.getSourceFile());
176
+ walk(env, root, node => {
177
+ if (!env.ts.isObjectLiteralExpression(node)) {
178
+ followHelper(env, search, checker, node, anchor, depth);
179
+ return;
180
+ }
181
+ const entry = providerEntry(env, search, checker, node, anchor);
182
+ if (entry)
183
+ search.found.push(entry);
184
+ });
174
185
  }
175
-
176
186
  /**
177
187
  * The `{ provide: <token>, ... }` provider literals of `file` whose token is `name` imported from `moduleName`, in source order.
178
188
  * A call or a spread of a function or a const declared in another file of the program is followed (to a depth of four), so a
@@ -180,11 +190,10 @@ function scanProviders(env, search, root, anchor, depth) {
180
190
  * call or spread inside the app root (where the entry is provided), its `useClass` and `checker` those of the helper's file.
181
191
  */
182
192
  function providersOf(env, file, name, moduleName) {
183
- const search = { name, moduleName, found: [], seen: new Set() };
184
- scanProviders(env, search, file.sourceFile, null, 0);
185
- return search.found.sort((a, b) => a.node.getStart() - b.node.getStart());
193
+ const search = { name, moduleName, found: [], seen: new Set() };
194
+ scanProviders(env, search, file.sourceFile, null, 0);
195
+ return search.found.sort((a, b) => a.node.getStart() - b.node.getStart());
186
196
  }
187
-
188
197
  /**
189
198
  * The small TypeScript reading kit the R33/R38/R39/R41/R45/R84/R86 machine checks share (connection-map, sql-owner,
190
199
  * register-once, error-masked, default-deny-app-guard, entrypoint-only-in-apps, error-home). Everything is decided by
@@ -192,33 +201,32 @@ function providersOf(env, file, name, moduleName) {
192
201
  * recognised by the package it is imported from, a capability class by the file that declares it.
193
202
  */
194
203
  export function machineKit({ context, graph }) {
195
- const env = { ts: context.ts, context, graph };
196
- const bound = operation => (...args) => operation(env, ...args);
197
- return {
198
- ts: env.ts,
199
- resolver: graph.resolver,
200
- providersOf: bound(providersOf),
201
- checkerOf: bound(checkerOf),
202
- aliased: bound(aliased),
203
- symbolAt: bound(symbolAt),
204
- importBinding: bound(importBinding),
205
- isImportOf: bound(isImportOf),
206
- declarationsOf: bound(declarationsOf),
207
- graphPath: bound(graphPath),
208
- graphFile: bound(graphFile),
209
- ownerOfDeclaration: bound(ownerOfDeclaration),
210
- stringValue: bound(stringValue),
211
- walk: bound(walk),
212
- decorators: bound(decorators),
213
- isExported: bound(isExported),
214
- propertyNameText: bound(propertyNameText),
215
- propertyOf: bound(propertyOf),
216
- valueOfProperty: bound(valueOfProperty),
217
- at: bound(at),
218
- appRoot: bound(appRoot),
219
- appCompositionFiles: bound(appCompositionFiles),
220
- };
221
- }
222
-
223
- export const upperSnake = name => name.replaceAll('-', '_').toUpperCase();
224
- export const pascal = name => name.split('-').filter(Boolean).map(part => part[0].toUpperCase() + part.slice(1)).join('');
204
+ const env = { ts: context.ts, context, graph };
205
+ const bound = (operation) => (...args) => operation(env, ...args);
206
+ return {
207
+ ts: env.ts,
208
+ resolver: graph.resolver,
209
+ providersOf: bound(providersOf),
210
+ checkerOf: bound(checkerOf),
211
+ aliased: bound(aliased),
212
+ symbolAt: bound(symbolAt),
213
+ importBinding: bound(importBinding),
214
+ isImportOf: bound(isImportOf),
215
+ declarationsOf: bound(declarationsOf),
216
+ graphPath: bound(graphPath),
217
+ graphFile: bound(graphFile),
218
+ ownerOfDeclaration: bound(ownerOfDeclaration),
219
+ stringValue: bound(stringValue),
220
+ walk: bound(walk),
221
+ decorators: bound(decorators),
222
+ isExported: bound(isExported),
223
+ propertyNameText: bound(propertyNameText),
224
+ propertyOf: bound(propertyOf),
225
+ valueOfProperty: bound(valueOfProperty),
226
+ at: bound(at),
227
+ appRoot: bound(appRoot),
228
+ appCompositionFiles: bound(appCompositionFiles),
229
+ };
230
+ }
231
+ export const upperSnake = (name) => name.replaceAll('-', '_').toUpperCase();
232
+ export const pascal = (name) => name.split('-').filter(Boolean).map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('');
@@ -4,30 +4,29 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { managedGroupOf } from '../edition-slots.mjs';
6
6
  import { loadSlotManifest } from '../slots.mjs';
7
-
8
7
  const TEMPLATE_ROOTS = [
9
- path.resolve(import.meta.dirname, '..', '..', '..', 'packages', 'hfs', 'templates'),
10
- path.resolve(import.meta.dirname, '..', '..', '..', '..', 'templates'),
8
+ path.resolve(import.meta.dirname, '..', '..', '..', 'packages', 'hfs', 'templates'),
9
+ path.resolve(import.meta.dirname, '..', '..', '..', '..', 'templates'),
11
10
  ];
12
11
  const managedScriptCache = new Map();
13
- const SCRIPT_ENTRY_START = String.raw`^\s*"`;
14
- const SCRIPT_ENTRY_NAME = String.raw`([^"\n]+)`;
15
- const SCRIPT_ENTRY_END = String.raw`":\s*"`;
12
+ const SCRIPT_ENTRY_START = String.raw `^\s*"`;
13
+ const SCRIPT_ENTRY_NAME = String.raw `([^"\n]+)`;
14
+ const SCRIPT_ENTRY_END = String.raw `":\s*"`;
16
15
  const SCRIPT_ENTRY = new RegExp([SCRIPT_ENTRY_START, SCRIPT_ENTRY_NAME, SCRIPT_ENTRY_END].join(''), 'gmu');
17
-
18
16
  /** The script names of a profile/edition template after its partials are expanded. */
19
17
  export function managedScriptNames(profile, edition = 'full') {
20
- const key = `${profile}:${edition}`;
21
- if (!managedScriptCache.has(key)) {
22
- const slot = loadSlotManifest().slots.find((entry) => entry.id === `${profile}.package-manifest`);
23
- const group = slot && managedGroupOf(slot, edition);
24
- const templates = group && TEMPLATE_ROOTS.find((dir) => fs.existsSync(path.join(dir, profile, group, 'package.json')));
25
- if (!templates) throw new Error(`The managed package-scripts template of profile ${profile} cannot be found next to the runtime.`);
26
- const text = fs.readFileSync(path.join(templates, profile, group, 'package.json'), 'utf8')
27
- .replace(/^\{\{> ([\w./-]+)\}\}\r?\n/gmu, (_, partial) => fs.readFileSync(path.join(templates, partial), 'utf8'));
28
- // The key is bounded by quotes, never the colon, so `[^"]` cannot backtrack; the strict script-name class filters after.
29
- const names = [...text.matchAll(SCRIPT_ENTRY)].map((match) => match[1]);
30
- managedScriptCache.set(key, new Set(names.filter((name) => /^[A-Za-z0-9:_.-]+$/.test(name))));
31
- }
32
- return managedScriptCache.get(key);
18
+ const key = `${profile}:${edition}`;
19
+ if (!managedScriptCache.has(key)) {
20
+ const slot = loadSlotManifest().slots.find((entry) => entry.id === `${profile}.package-manifest`);
21
+ const group = slot && managedGroupOf(slot, edition);
22
+ const templates = group && TEMPLATE_ROOTS.find((dir) => fs.existsSync(path.join(dir, profile, group, 'package.json')));
23
+ if (!templates)
24
+ throw new Error(`The managed package-scripts template of profile ${profile} cannot be found next to the runtime.`);
25
+ const text = fs.readFileSync(path.join(templates, profile, group, 'package.json'), 'utf8')
26
+ .replace(/^\{\{> ([\w./-]+)\}\}\r?\n/gmu, (_, partial) => fs.readFileSync(path.join(templates, partial), 'utf8'));
27
+ // The key is bounded by quotes, never the colon, so `[^"]` cannot backtrack; the strict script-name class filters after.
28
+ const names = [...text.matchAll(SCRIPT_ENTRY)].map((match) => match[1]);
29
+ managedScriptCache.set(key, new Set(names.filter((name) => /^[A-Za-z0-9:_.-]+$/.test(name))));
30
+ }
31
+ return managedScriptCache.get(key);
33
32
  }