@starci/eslint-canon-be 3.8.19 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- package/runtime/scripts/lib/yaml-cached.mjs +4 -4
|
@@ -1,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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (ts.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const statementCall = (ts, statement) => (ts.isReturnStatement(statement) || ts.isExpressionStatement(statement)) ? unwrap(ts, statement.expression) : null;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
&& ts.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
}
|