@starci/eslint-canon-fe 9.5.23 → 9.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/docs/button-intent.md +1 -1
  3. package/package.json +1 -1
  4. package/runtime/bundle.json +192 -0
  5. package/runtime/engine/by-code-unit.mjs +6 -6
  6. package/runtime/engine/model-config.mjs +98 -76
  7. package/runtime/engine/orca-config.mjs +22 -17
  8. package/runtime/engine/release-config.mjs +22 -18
  9. package/runtime/engine/removed-vocabulary.mjs +21 -20
  10. package/runtime/engine/resources-config.mjs +42 -35
  11. package/runtime/engine/runtime-root.mjs +11 -13
  12. package/runtime/engine/secrets.mjs +170 -102
  13. package/runtime/engine/sonar-config.mjs +16 -13
  14. package/runtime/engine/temp-root.mjs +3 -9
  15. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  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,240 +1,291 @@
1
- /**
2
- * The repeated shapes taught by the BE scaffold are wiring, not copied decisions. Match their imported
3
- * ports and their small bodies, never a filename suffix or an entire decorated class: a custom method
4
- * or an extra statement still goes through the clone check.
5
- */
6
1
  import { nameText } from '../../lib/ts-ast.mjs';
7
2
  import { importsOf, unwrapExpression } from '../../lib/ts-analysis.mjs';
8
3
  import { nodeDecorators } from './ast-walks.mjs';
9
4
  import { canonJsxCloneNodes } from './canon-jsx-clones.mjs';
10
-
11
5
  const READ_METHODS = new Set(['find', 'findBy', 'findAndCount', 'findOne', 'findOneBy', 'findOneOrFail', 'findOneByOrFail']);
12
-
13
- const unwrap = (ts, node) => unwrapExpression(ts, node, { awaitExpressions: true, typeAssertions: false });
14
-
6
+ function unwrap(ts, node) {
7
+ return node === null ? null : unwrapExpression(ts, node, { awaitExpressions: true, typeAssertions: false });
8
+ }
9
+ const identifierText = (ts, name) => (name && ts.isIdentifier(name) ? name.text : undefined);
10
+ const isIdentifierParameter = (ts, parameter) => ts.isIdentifier(parameter.name);
15
11
  const imported = (env, node, name, source) => {
16
- if (!node || !env.ts.isIdentifier(node)) return false;
17
- const binding = env.imports.get(node.text);
18
- return binding?.name === name && binding.source === source;
12
+ if (!node || !env.ts.isIdentifier(node))
13
+ return false;
14
+ const binding = env.imports.get(node.text);
15
+ return binding?.name === name && binding.source === source;
19
16
  };
20
-
21
17
  const decoratorsHave = (env, node, name, source) => nodeDecorators(env.ts, node)
22
- .some(decorator => imported(env, env.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression, name, source));
23
-
18
+ .some(decorator => imported(env, env.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression, name, source));
24
19
  const portType = (env, node, name, source) => Boolean(node && env.ts.isTypeReferenceNode(node) && imported(env, node.typeName, name, source));
25
-
26
20
  /** Data moves between shapes here; operators, arbitrary calls and executable callbacks remain compared. */
27
21
  function mapping(env, input, allowCall = () => false) {
28
- const { ts } = env;
29
- const node = unwrap(ts, input);
30
- if (!node) return false;
31
- if (ts.isIdentifier(node) || ts.isLiteralExpression(node) || [ts.SyntaxKind.NullKeyword, ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.ThisKeyword].includes(node.kind)) return true;
32
- if (ts.isPropertyAccessExpression(node)) return mapping(env, node.expression, allowCall);
33
- if (ts.isObjectLiteralExpression(node)) return node.properties.every(property => {
34
- if (ts.isShorthandPropertyAssignment(property)) return !property.objectAssignmentInitializer;
35
- if (ts.isSpreadAssignment(property)) return mapping(env, property.expression, allowCall);
36
- return ts.isPropertyAssignment(property) && nameText(ts, property.name) !== null && mapping(env, property.initializer, allowCall);
37
- });
38
- if (ts.isArrayLiteralExpression(node)) return node.elements.every(item => mapping(env, ts.isSpreadElement(item) ? item.expression : item, allowCall));
39
- return ts.isCallExpression(node) && allowCall(node);
40
- }
41
-
42
- const parameterNames = (ts, method) => new Set(method.parameters.filter(parameter => ts.isIdentifier(parameter.name)).map(parameter => parameter.name.text));
43
- const propertyParameters = (ts, constructor) => new Set((constructor?.parameters ?? []).filter(parameter => parameter.modifiers?.length && ts.isIdentifier(parameter.name)).map(parameter => parameter.name.text));
22
+ const { ts } = env;
23
+ const node = unwrap(ts, input);
24
+ if (!node)
25
+ return false;
26
+ if (ts.isIdentifier(node) || ts.isLiteralExpression(node) || [ts.SyntaxKind.NullKeyword, ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.ThisKeyword].includes(node.kind))
27
+ return true;
28
+ if (ts.isPropertyAccessExpression(node))
29
+ return mapping(env, node.expression, allowCall);
30
+ if (ts.isObjectLiteralExpression(node))
31
+ return node.properties.every(property => {
32
+ if (ts.isShorthandPropertyAssignment(property))
33
+ return !property.objectAssignmentInitializer;
34
+ if (ts.isSpreadAssignment(property))
35
+ return mapping(env, property.expression, allowCall);
36
+ return ts.isPropertyAssignment(property) && nameText(ts, property.name) !== null && mapping(env, property.initializer, allowCall);
37
+ });
38
+ if (ts.isArrayLiteralExpression(node))
39
+ return node.elements.every(item => mapping(env, ts.isSpreadElement(item) ? item.expression : item, allowCall));
40
+ return ts.isCallExpression(node) && allowCall(node);
41
+ }
42
+ const parameterNames = (ts, method) => new Set(method.parameters.filter((parameter) => isIdentifierParameter(ts, parameter)).map(parameter => parameter.name.text));
43
+ const propertyParameters = (ts, constructor) => {
44
+ const parameters = constructor?.parameters ?? [];
45
+ return new Set(parameters.filter((parameter) => !!parameter.modifiers?.length && isIdentifierParameter(ts, parameter)).map(parameter => parameter.name.text));
46
+ };
44
47
  const inertParameters = (ts, constructor) => constructor.parameters.every(parameter => ts.isIdentifier(parameter.name) && !parameter.initializer);
45
-
46
48
  function receiverMember(ts, call) {
47
- if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression)) return null;
48
- const receiver = call.expression.expression;
49
- return ts.isPropertyAccessExpression(receiver) && receiver.expression.kind === ts.SyntaxKind.ThisKeyword ? receiver.name.text : null;
50
- }
51
-
52
- const statementCall = (ts, statement) => (ts.isReturnStatement(statement) || ts.isExpressionStatement(statement)) ? unwrap(ts, statement.expression) : null;
53
-
54
- function delegation(env, method, statement, members, allowCall = () => false) {
55
- const call = statementCall(env.ts, statement);
56
- return Boolean(call && env.ts.isCallExpression(call) && members.has(receiverMember(env.ts, call))
57
- && call.arguments.every(argument => mapping(env, argument, allowCall)));
58
- }
59
-
49
+ if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression))
50
+ return null;
51
+ const receiver = call.expression.expression;
52
+ return ts.isPropertyAccessExpression(receiver) && receiver.expression.kind === ts.SyntaxKind.ThisKeyword ? receiver.name.text : null;
53
+ }
54
+ const statementCall = (ts, statement) => ((statement && (ts.isReturnStatement(statement) || ts.isExpressionStatement(statement))) ? unwrap(ts, statement.expression) : null);
55
+ function delegation(env, _method, statement, members, allowCall = () => false) {
56
+ const call = statementCall(env.ts, statement);
57
+ return Boolean(call && env.ts.isCallExpression(call) && members.has(receiverMember(env.ts, call))
58
+ && call.arguments.every(argument => mapping(env, argument, allowCall)));
59
+ }
60
60
  function canonicalConstructor(env, constructor, logger = false) {
61
- if (!constructor?.body || !inertParameters(env.ts, constructor)) return false;
62
- if (!logger) return constructor.body.statements.length === 0;
63
- const parameters = constructor.parameters.filter(parameter => decoratorsHave(env, parameter, 'InjectLogger', '@modules/platform/logging'));
64
- if (parameters.length !== 1 || constructor.body.statements.length !== 1) return false;
65
- const call = statementCall(env.ts, constructor.body.statements[0]);
66
- return Boolean(call && env.ts.isCallExpression(call) && call.expression.kind === env.ts.SyntaxKind.SuperKeyword
67
- && call.arguments.length === 1 && env.ts.isIdentifier(call.arguments[0]) && call.arguments[0].text === parameters[0].name.text);
68
- }
69
-
61
+ if (!constructor?.body || !inertParameters(env.ts, constructor))
62
+ return false;
63
+ if (!logger)
64
+ return constructor.body.statements.length === 0;
65
+ const parameters = constructor.parameters.filter(parameter => decoratorsHave(env, parameter, 'InjectLogger', '@modules/platform/logging'));
66
+ if (parameters.length !== 1 || constructor.body.statements.length !== 1)
67
+ return false;
68
+ const call = statementCall(env.ts, constructor.body.statements[0]);
69
+ if (!call || !env.ts.isCallExpression(call))
70
+ return false;
71
+ const [argument] = call.arguments;
72
+ return call.expression.kind === env.ts.SyntaxKind.SuperKeyword
73
+ && call.arguments.length === 1 && argument !== undefined && env.ts.isIdentifier(argument) && argument.text === identifierText(env.ts, parameters[0]?.name);
74
+ }
70
75
  function hasHeritage(env, declaration, name, source, kind) {
71
- return declaration.heritageClauses?.some(clause => clause.token === kind && clause.types.some(type => imported(env, type.expression, name, source))) ?? false;
76
+ return declaration.heritageClauses?.some(clause => clause.token === kind && clause.types.some(type => imported(env, type.expression, name, source))) ?? false;
72
77
  }
73
-
74
78
  function fenceStatement(env, statement, claims, job) {
75
- const call = statementCall(env.ts, statement);
76
- if (!call || !env.ts.isCallExpression(call) || receiverMember(env.ts, call) !== claims || call.expression.name.text !== 'advance' || call.arguments.length !== 1) return false;
77
- const options = unwrap(env.ts, call.arguments[0]);
78
- if (!env.ts.isObjectLiteralExpression(options) || options.properties.length !== 3) return false;
79
- const properties = new Map(options.properties.filter(env.ts.isPropertyAssignment).map(property => [nameText(env.ts, property.name), property.initializer]));
80
- const jobField = (node, field) => env.ts.isPropertyAccessExpression(node) && env.ts.isIdentifier(node.expression) && node.expression.text === job && node.name.text === field;
81
- return jobField(properties.get('jobId') ?? {}, 'jobId') && jobField(properties.get('expectedFencingToken') ?? {}, 'fencingToken')
82
- && mapping(env, properties.get('step'));
83
- }
84
-
79
+ const call = statementCall(env.ts, statement);
80
+ if (!call || !env.ts.isCallExpression(call) || receiverMember(env.ts, call) !== claims || !env.ts.isPropertyAccessExpression(call.expression)
81
+ || call.expression.name.text !== 'advance' || call.arguments.length !== 1)
82
+ return false;
83
+ const options = unwrap(env.ts, call.arguments[0]);
84
+ if (!options || !env.ts.isObjectLiteralExpression(options) || options.properties.length !== 3)
85
+ return false;
86
+ const properties = new Map(options.properties.filter(env.ts.isPropertyAssignment).map((property) => [nameText(env.ts, property.name), property.initializer]));
87
+ const jobField = (node, field) => node !== undefined && env.ts.isPropertyAccessExpression(node) && env.ts.isIdentifier(node.expression) && node.expression.text === job && node.name.text === field;
88
+ return jobField(properties.get('jobId'), 'jobId') && jobField(properties.get('expectedFencingToken'), 'fencingToken')
89
+ && mapping(env, properties.get('step'));
90
+ }
85
91
  function jobMethods(env, declaration, constructor, excluded) {
86
- const claims = constructor?.parameters.find(parameter => portType(env, parameter.type, 'JobClaims', '@modules/platform/jobs')
87
- && decoratorsHave(env, parameter, 'InjectJobClaims', '@modules/platform/jobs'));
88
- if (!claims || !env.ts.isIdentifier(claims.name)) return;
89
- const members = propertyParameters(env.ts, constructor);
90
- const runKey = call => receiverMember(env.ts, call) === claims.name.text && call.expression.name.text === 'runKey'
91
- && call.arguments.length === 2 && call.arguments.every(argument => mapping(env, argument));
92
- for (const method of declaration.members) {
93
- if (!env.ts.isMethodDeclaration(method) || nameText(env.ts, method.name) !== 'run' || !method.body || method.parameters.length !== 1
94
- || !portType(env, method.parameters[0].type, 'ClaimedJob', '@modules/platform/jobs')) continue;
95
- const statements = method.body.statements;
96
- const job = [...parameterNames(env.ts, method)][0];
97
- if (!statements.length || !fenceStatement(env, statements[0], claims.name.text, job)) continue;
98
- if (statements.length === 1 || (statements.length === 2 && delegation(env, method, statements[1], members, runKey))) excluded.add(method);
99
- else excluded.add(statements[0]);
100
- }
101
- if (canonicalConstructor(env, constructor)) excluded.add(constructor);
102
- }
103
-
92
+ const claims = constructor?.parameters.find(parameter => portType(env, parameter.type, 'JobClaims', '@modules/platform/jobs')
93
+ && decoratorsHave(env, parameter, 'InjectJobClaims', '@modules/platform/jobs'));
94
+ if (!claims || !env.ts.isIdentifier(claims.name))
95
+ return;
96
+ const claimsName = claims.name.text;
97
+ const members = propertyParameters(env.ts, constructor);
98
+ const runKey = (call) => receiverMember(env.ts, call) === claimsName && env.ts.isPropertyAccessExpression(call.expression) && call.expression.name.text === 'runKey'
99
+ && call.arguments.length === 2 && call.arguments.every(argument => mapping(env, argument));
100
+ for (const method of declaration.members) {
101
+ if (!env.ts.isMethodDeclaration(method) || nameText(env.ts, method.name) !== 'run' || !method.body || method.parameters.length !== 1
102
+ || !portType(env, method.parameters[0]?.type, 'ClaimedJob', '@modules/platform/jobs'))
103
+ continue;
104
+ const statements = method.body.statements;
105
+ const job = [...parameterNames(env.ts, method)][0];
106
+ const first = statements[0];
107
+ if (!first || !fenceStatement(env, first, claimsName, job))
108
+ continue;
109
+ if (statements.length === 1 || (statements.length === 2 && delegation(env, method, statements[1], members, runKey)))
110
+ excluded.add(method);
111
+ else
112
+ excluded.add(first);
113
+ }
114
+ if (canonicalConstructor(env, constructor))
115
+ excluded.add(constructor);
116
+ }
104
117
  function queueMethods(env, declaration, constructor, excluded) {
105
- const outbox = constructor?.parameters.find(parameter => portType(env, parameter.type, 'QueueOutbox', '@modules/platform/queue')
106
- && decoratorsHave(env, parameter, 'InjectQueueOutbox', '@modules/platform/queue'));
107
- if (!outbox || !env.ts.isIdentifier(outbox.name)) return;
108
- for (const method of declaration.members) {
109
- if (!env.ts.isMethodDeclaration(method) || method.body?.statements.length !== 1) continue;
110
- const call = statementCall(env.ts, method.body.statements[0]);
111
- if (call && env.ts.isCallExpression(call) && receiverMember(env.ts, call) === outbox.name.text && call.expression.name.text === 'write'
112
- && call.arguments.length === 3 && call.arguments.every(argument => mapping(env, argument))) excluded.add(method);
113
- }
114
- if (canonicalConstructor(env, constructor)) excluded.add(constructor);
115
- }
116
-
118
+ const outbox = constructor?.parameters.find(parameter => portType(env, parameter.type, 'QueueOutbox', '@modules/platform/queue')
119
+ && decoratorsHave(env, parameter, 'InjectQueueOutbox', '@modules/platform/queue'));
120
+ if (!outbox || !env.ts.isIdentifier(outbox.name))
121
+ return;
122
+ for (const method of declaration.members) {
123
+ if (!env.ts.isMethodDeclaration(method) || method.body?.statements.length !== 1)
124
+ continue;
125
+ const call = statementCall(env.ts, method.body.statements[0]);
126
+ if (call && env.ts.isCallExpression(call) && receiverMember(env.ts, call) === outbox.name.text && env.ts.isPropertyAccessExpression(call.expression) && call.expression.name.text === 'write'
127
+ && call.arguments.length === 3 && call.arguments.every(argument => mapping(env, argument)))
128
+ excluded.add(method);
129
+ }
130
+ if (canonicalConstructor(env, constructor))
131
+ excluded.add(constructor);
132
+ }
117
133
  function rowMapper(env, call, row) {
118
- const { ts } = env;
119
- if (!call) return false;
120
- if (ts.isObjectLiteralExpression(unwrap(ts, call))) return mapping(env, call, iso => ts.isPropertyAccessExpression(iso.expression)
121
- && iso.expression.name.text === 'toISOString' && iso.arguments.length === 0 && mapping(env, iso.expression.expression));
122
- if (!ts.isCallExpression(call) || call.arguments.length !== 1 || !ts.isIdentifier(call.arguments[0]) || call.arguments[0].text !== row || !ts.isIdentifier(call.expression)) return false;
123
- const binding = env.imports.get(call.expression.text);
124
- return Boolean(binding && /\.rows(?:\.[cm]?ts)?$/.test(binding.source)) || env.mappers.has(call.expression.text);
125
- }
126
-
134
+ const { ts } = env;
135
+ if (!call)
136
+ return false;
137
+ if (ts.isObjectLiteralExpression(unwrap(ts, call)))
138
+ return mapping(env, call, iso => ts.isPropertyAccessExpression(iso.expression)
139
+ && iso.expression.name.text === 'toISOString' && iso.arguments.length === 0 && mapping(env, iso.expression.expression));
140
+ if (!ts.isCallExpression(call) || call.arguments.length !== 1)
141
+ return false;
142
+ const [argument] = call.arguments;
143
+ if (!argument || !ts.isIdentifier(argument) || argument.text !== row || !ts.isIdentifier(call.expression))
144
+ return false;
145
+ const binding = env.imports.get(call.expression.text);
146
+ return Boolean(binding && /\.rows(?:\.[cm]?ts)?$/.test(binding.source ?? '')) || env.mappers.has(call.expression.text);
147
+ }
127
148
  function readResult(env, expression, row) {
128
- const { ts } = env;
129
- const node = unwrap(ts, expression);
130
- if (!node) return false;
131
- if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'map'
132
- && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === row && node.arguments.length === 1) {
133
- const mapper = unwrap(ts, node.arguments[0]);
134
- if (ts.isIdentifier(mapper)) return env.mappers.has(mapper.text) || /\.rows(?:\.[cm]?ts)?$/.test(env.imports.get(mapper.text)?.source ?? '');
135
- return ts.isArrowFunction(mapper) && mapper.parameters.length === 1 && !ts.isBlock(mapper.body) && rowMapper(env, unwrap(ts, mapper.body), mapper.parameters[0].name.text);
136
- }
137
- if (!ts.isConditionalExpression(node)) return rowMapper(env, node, row);
138
- const condition = unwrap(ts, node.condition);
139
- const simpleNull = ts.isBinaryExpression(condition) && [ts.SyntaxKind.EqualsEqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken].includes(condition.operatorToken.kind)
140
- && ts.isIdentifier(condition.left) && condition.left.text === row && condition.right.kind === ts.SyntaxKind.NullKeyword;
141
- if (!(simpleNull || (ts.isIdentifier(condition) && condition.text === row))) return false;
142
- return [node.whenTrue, node.whenFalse].every(branch => unwrap(ts, branch).kind === ts.SyntaxKind.NullKeyword || rowMapper(env, unwrap(ts, branch), row));
143
- }
144
-
149
+ const { ts } = env;
150
+ const node = unwrap(ts, expression);
151
+ if (!node)
152
+ return false;
153
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'map'
154
+ && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === row && node.arguments.length === 1) {
155
+ const mapper = unwrap(ts, node.arguments[0]);
156
+ if (!mapper)
157
+ return false;
158
+ if (ts.isIdentifier(mapper))
159
+ return env.mappers.has(mapper.text) || /\.rows(?:\.[cm]?ts)?$/.test(env.imports.get(mapper.text)?.source ?? '');
160
+ return ts.isArrowFunction(mapper) && mapper.parameters.length === 1 && !ts.isBlock(mapper.body) && rowMapper(env, unwrap(ts, mapper.body), identifierText(ts, mapper.parameters[0]?.name));
161
+ }
162
+ if (!ts.isConditionalExpression(node))
163
+ return rowMapper(env, node, row);
164
+ const condition = unwrap(ts, node.condition);
165
+ const simpleNull = ts.isBinaryExpression(condition) && [ts.SyntaxKind.EqualsEqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken].includes(condition.operatorToken.kind)
166
+ && ts.isIdentifier(condition.left) && condition.left.text === row && condition.right.kind === ts.SyntaxKind.NullKeyword;
167
+ if (!(simpleNull || (ts.isIdentifier(condition) && condition.text === row)))
168
+ return false;
169
+ return [node.whenTrue, node.whenFalse].every(branch => unwrap(ts, branch).kind === ts.SyntaxKind.NullKeyword || rowMapper(env, unwrap(ts, branch), row));
170
+ }
145
171
  function readCall(env, call, managers) {
146
- const { ts } = env;
147
- if (!ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression) || !managers.has(receiverMember(ts, call))) return false;
148
- if (READ_METHODS.has(call.expression.name.text)) return call.arguments.length <= 2 && call.arguments.every(argument => mapping(env, argument));
149
- const sql = call.arguments[0];
150
- return call.expression.name.text === 'query' && sql && ts.isIdentifier(sql) && /^(?:FIND|LIST)_/.test(sql.text)
151
- && /\.sql(?:\.[cm]?ts)?$/.test(env.imports.get(sql.text)?.source ?? '') && call.arguments.every(argument => mapping(env, argument));
152
- }
153
-
172
+ const { ts } = env;
173
+ if (!call || !ts.isCallExpression(call) || !ts.isPropertyAccessExpression(call.expression) || !managers.has(receiverMember(ts, call)))
174
+ return false;
175
+ if (READ_METHODS.has(call.expression.name.text))
176
+ return call.arguments.length <= 2 && call.arguments.every(argument => mapping(env, argument));
177
+ const sql = call.arguments[0];
178
+ return Boolean(call.expression.name.text === 'query' && sql && ts.isIdentifier(sql) && /^(?:FIND|LIST)_/.test(sql.text)
179
+ && /\.sql(?:\.[cm]?ts)?$/.test(env.imports.get(sql.text)?.source ?? '') && call.arguments.every(argument => mapping(env, argument)));
180
+ }
154
181
  function ownedRead(env, statement) {
155
- const { ts } = env;
156
- const call = statementCall(ts, statement);
157
- if (!call || !ts.isCallExpression(call) || !imported(env, call.expression, 'requireOwnedEntity', '@modules/platform/database') || call.arguments.length !== 5) return false;
158
- if (!call.arguments.slice(0, 4).every(argument => mapping(env, argument))) return false;
159
- const callback = unwrap(ts, call.arguments[4]);
160
- if (!ts.isArrowFunction(callback) || callback.parameters.length || !ts.isBlock(callback.body) || callback.body.statements.length !== 1) return false;
161
- const thrown = callback.body.statements[0];
162
- if (!ts.isThrowStatement(thrown) || !thrown.expression || !ts.isNewExpression(thrown.expression) || thrown.expression.arguments?.length !== 1) return false;
163
- const options = thrown.expression.arguments[0];
164
- if (!ts.isObjectLiteralExpression(options) || !mapping(env, options)) return false;
165
- const code = options.properties.find(property => ts.isPropertyAssignment(property) && nameText(ts, property.name) === 'code');
166
- return Boolean(code && ts.isPropertyAccessExpression(code.initializer) && code.initializer.name.text === 'NotFound');
167
- }
168
-
182
+ const { ts } = env;
183
+ const call = statementCall(ts, statement);
184
+ if (!call || !ts.isCallExpression(call) || !imported(env, call.expression, 'requireOwnedEntity', '@modules/platform/database') || call.arguments.length !== 5)
185
+ return false;
186
+ if (!call.arguments.slice(0, 4).every(argument => mapping(env, argument)))
187
+ return false;
188
+ const callback = unwrap(ts, call.arguments[4]);
189
+ if (!callback || !ts.isArrowFunction(callback) || callback.parameters.length || !ts.isBlock(callback.body) || callback.body.statements.length !== 1)
190
+ return false;
191
+ const thrown = callback.body.statements[0];
192
+ if (!thrown || !ts.isThrowStatement(thrown) || !thrown.expression || !ts.isNewExpression(thrown.expression) || thrown.expression.arguments?.length !== 1)
193
+ return false;
194
+ const options = thrown.expression.arguments[0];
195
+ if (!options || !ts.isObjectLiteralExpression(options) || !mapping(env, options))
196
+ return false;
197
+ const code = options.properties.find((property) => ts.isPropertyAssignment(property) && nameText(ts, property.name) === 'code');
198
+ return Boolean(code && ts.isPropertyAccessExpression(code.initializer) && code.initializer.name.text === 'NotFound');
199
+ }
169
200
  function readMethods(env, declaration, constructor, excluded) {
170
- const managers = new Set((constructor?.parameters ?? []).filter(parameter => portType(env, parameter.type, 'EntityManager', 'typeorm')
171
- && nodeDecorators(env.ts, parameter).some(decorator => {
172
- const call = env.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
173
- const binding = env.ts.isIdentifier(call) ? env.imports.get(call.text) : null;
174
- return binding?.source === '@modules/platform/database' && /^Inject.*EntityManager$/.test(binding.name);
175
- })).map(parameter => parameter.name.text));
176
- for (const method of declaration.members) {
177
- if (!env.ts.isMethodDeclaration(method) || !method.body) continue;
178
- const statements = method.body.statements;
179
- if (statements.length === 1 && ownedRead(env, statements[0])) { excluded.add(method); continue; }
180
- if (statements.length !== 2 || !env.ts.isVariableStatement(statements[0]) || !env.ts.isReturnStatement(statements[1])) continue;
181
- const variables = statements[0].declarationList.declarations;
182
- if (variables.length !== 1 || !env.ts.isIdentifier(variables[0].name) || !variables[0].initializer) continue;
183
- const call = unwrap(env.ts, variables[0].initializer);
184
- if (readCall(env, call, managers) && readResult(env, statements[1].expression, variables[0].name.text)) excluded.add(method);
185
- }
186
- if (managers.size && canonicalConstructor(env, constructor)) excluded.add(constructor);
187
- }
188
-
201
+ const managers = new Set((constructor?.parameters ?? []).filter(parameter => portType(env, parameter.type, 'EntityManager', 'typeorm')
202
+ && nodeDecorators(env.ts, parameter).some(decorator => {
203
+ const call = env.ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
204
+ const binding = env.ts.isIdentifier(call) ? env.imports.get(call.text) : null;
205
+ return binding?.source === '@modules/platform/database' && /^Inject.*EntityManager$/.test(binding.name);
206
+ })).map(parameter => identifierText(env.ts, parameter.name)));
207
+ for (const method of declaration.members) {
208
+ if (!env.ts.isMethodDeclaration(method) || !method.body)
209
+ continue;
210
+ const statements = method.body.statements;
211
+ const [first, second] = statements;
212
+ if (statements.length === 1 && first && ownedRead(env, first)) {
213
+ excluded.add(method);
214
+ continue;
215
+ }
216
+ if (statements.length !== 2 || !first || !second || !env.ts.isVariableStatement(first) || !env.ts.isReturnStatement(second))
217
+ continue;
218
+ const variables = first.declarationList.declarations;
219
+ const [variable] = variables;
220
+ if (variables.length !== 1 || !variable || !env.ts.isIdentifier(variable.name) || !variable.initializer)
221
+ continue;
222
+ const call = unwrap(env.ts, variable.initializer);
223
+ if (readCall(env, call, managers) && readResult(env, second.expression, variable.name.text))
224
+ excluded.add(method);
225
+ }
226
+ if (managers.size && canonicalConstructor(env, constructor))
227
+ excluded.add(constructor);
228
+ }
189
229
  function queueDefinition(env, node) {
190
- const { ts } = env;
191
- if (!env.topLevelVariables.has(node) || !node.initializer) return false;
192
- const value = unwrap(ts, node.initializer);
193
- if (ts.isCallExpression(value) && imported(env, value.expression, 'defineQueue', '@modules/platform/queue'))
194
- return value.arguments.length === 1 && ts.isObjectLiteralExpression(unwrap(ts, value.arguments[0])) && mapping(env, value.arguments[0]);
195
- if (!ts.isArrowFunction(value) || !portType(env, value.type, 'QueueSchedulerDefinition', '@modules/platform/queue')) return false;
196
- const body = ts.isBlock(value.body) && value.body.statements.length === 1 && ts.isReturnStatement(value.body.statements[0]) ? value.body.statements[0].expression : value.body;
197
- const object = unwrap(ts, body);
198
- return Boolean(object && ts.isObjectLiteralExpression(object) && mapping(env, object));
199
- }
200
-
230
+ const { ts } = env;
231
+ if (!env.topLevelVariables.has(node) || !ts.isVariableDeclaration(node) || !node.initializer)
232
+ return false;
233
+ const value = unwrap(ts, node.initializer);
234
+ if (ts.isCallExpression(value) && imported(env, value.expression, 'defineQueue', '@modules/platform/queue'))
235
+ return value.arguments.length === 1 && value.arguments[0] !== undefined && ts.isObjectLiteralExpression(unwrap(ts, value.arguments[0])) && mapping(env, value.arguments[0]);
236
+ if (!ts.isArrowFunction(value) || !portType(env, value.type, 'QueueSchedulerDefinition', '@modules/platform/queue'))
237
+ return false;
238
+ const returned = ts.isBlock(value.body) && value.body.statements.length === 1 ? value.body.statements[0] : undefined;
239
+ const body = returned && ts.isReturnStatement(returned) ? returned.expression : value.body;
240
+ const object = unwrap(ts, body);
241
+ return Boolean(object && ts.isObjectLiteralExpression(object) && mapping(env, object));
242
+ }
201
243
  function canonEnvironment(ts, sourceFile) {
202
- const env = { ts, imports: importsOf(ts, sourceFile, { moduleKey: 'source', stringLiteralsOnly: true }), mappers: new Set(), topLevelVariables: new Set(), topLevelClasses: new Set(sourceFile.statements.filter(ts.isClassDeclaration)) };
203
- for (const statement of sourceFile.statements) {
204
- if (!ts.isVariableStatement(statement)) continue;
205
- for (const variable of statement.declarationList.declarations) {
206
- env.topLevelVariables.add(variable);
207
- const value = variable.initializer && unwrap(ts, variable.initializer);
208
- if (ts.isIdentifier(variable.name) && value && ts.isArrowFunction(value) && ts.isObjectLiteralExpression(unwrap(ts, value.body)) && mapping(env, value.body)) env.mappers.add(variable.name.text);
244
+ const env = { ts, imports: importsOf(ts, sourceFile, { moduleKey: 'source', stringLiteralsOnly: true }), mappers: new Set(), topLevelVariables: new Set(), topLevelClasses: new Set(sourceFile.statements.filter(ts.isClassDeclaration)) };
245
+ for (const statement of sourceFile.statements) {
246
+ if (!ts.isVariableStatement(statement))
247
+ continue;
248
+ for (const variable of statement.declarationList.declarations) {
249
+ env.topLevelVariables.add(variable);
250
+ const value = variable.initializer && unwrap(ts, variable.initializer);
251
+ if (ts.isIdentifier(variable.name) && value && ts.isArrowFunction(value) && ts.isObjectLiteralExpression(unwrap(ts, value.body)) && mapping(env, value.body))
252
+ env.mappers.add(variable.name.text);
253
+ }
209
254
  }
210
- }
211
- return env;
255
+ return env;
212
256
  }
213
-
214
257
  function classScaffolding(env, node, excluded) {
215
- const { ts } = env;
216
- const constructor = node.members.find(ts.isConstructorDeclaration);
217
- if (hasHeritage(env, node, 'ICQRSHandler', '@modules/platform/cqrs', ts.SyntaxKind.ExtendsKeyword)
218
- && ['CommandHandler', 'QueryHandler'].some(name => decoratorsHave(env, node, name, '@nestjs/cqrs'))) {
219
- if (canonicalConstructor(env, constructor, true)) excluded.add(constructor);
220
- const members = propertyParameters(ts, constructor);
221
- for (const method of node.members) if (ts.isMethodDeclaration(method) && nameText(ts, method.name) === 'process'
222
- && method.body?.statements.length === 1 && delegation(env, method, method.body.statements[0], members)) excluded.add(method);
223
- }
224
- if (hasHeritage(env, node, 'JobStep', '@modules/platform/jobs', ts.SyntaxKind.ImplementsKeyword)) jobMethods(env, node, constructor, excluded);
225
- queueMethods(env, node, constructor, excluded);
226
- readMethods(env, node, constructor, excluded);
227
- }
228
-
258
+ const { ts } = env;
259
+ const constructor = node.members.find(ts.isConstructorDeclaration);
260
+ if (hasHeritage(env, node, 'ICQRSHandler', '@modules/platform/cqrs', ts.SyntaxKind.ExtendsKeyword)
261
+ && ['CommandHandler', 'QueryHandler'].some(name => decoratorsHave(env, node, name, '@nestjs/cqrs'))) {
262
+ if (canonicalConstructor(env, constructor, true))
263
+ excluded.add(constructor);
264
+ const members = propertyParameters(ts, constructor);
265
+ for (const method of node.members)
266
+ if (ts.isMethodDeclaration(method) && nameText(ts, method.name) === 'process'
267
+ && method.body?.statements.length === 1 && delegation(env, method, method.body.statements[0], members))
268
+ excluded.add(method);
269
+ }
270
+ if (hasHeritage(env, node, 'JobStep', '@modules/platform/jobs', ts.SyntaxKind.ImplementsKeyword))
271
+ jobMethods(env, node, constructor, excluded);
272
+ queueMethods(env, node, constructor, excluded);
273
+ readMethods(env, node, constructor, excluded);
274
+ }
229
275
  export function canonCloneNodes(ts, sourceFile, profile) {
230
- if (profile === 'fe') return canonJsxCloneNodes(ts, sourceFile);
231
- const excluded = new Set();
232
- const env = canonEnvironment(ts, sourceFile);
233
- const visit = node => {
234
- if (queueDefinition(env, node)) { excluded.add(node); return; }
235
- if (env.topLevelClasses.has(node)) classScaffolding(env, node, excluded);
236
- ts.forEachChild(node, visit);
237
- };
238
- visit(sourceFile);
239
- return excluded;
276
+ if (profile === 'fe')
277
+ return canonJsxCloneNodes(ts, sourceFile);
278
+ const excluded = new Set();
279
+ const env = canonEnvironment(ts, sourceFile);
280
+ const visit = (node) => {
281
+ if (queueDefinition(env, node)) {
282
+ excluded.add(node);
283
+ return;
284
+ }
285
+ if (env.topLevelClasses.has(node) && ts.isClassDeclaration(node))
286
+ classScaffolding(env, node, excluded);
287
+ ts.forEachChild(node, visit);
288
+ };
289
+ visit(sourceFile);
290
+ return excluded;
240
291
  }