@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.
- package/CHANGELOG.md +16 -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,149 +1,163 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { pascal } from './machine-ast.mjs';
|
|
3
3
|
import { DATABASE_DIR } from './connection-map.mjs';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
4
|
+
const camel = (name) => { const text = pascal(name); return text.charAt(0).toLowerCase() + text.slice(1); };
|
|
5
|
+
function unparenWhile(node, isWrapper) {
|
|
6
|
+
let current = node;
|
|
7
|
+
while (current && isWrapper(current))
|
|
8
|
+
current = current.expression;
|
|
9
|
+
return current;
|
|
10
|
+
}
|
|
13
11
|
const isExpressionWrapper = (ts, node) => ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node);
|
|
14
|
-
|
|
15
|
-
const unparenRegistration = (ts, node) => unparenWhile(node, current =>
|
|
16
|
-
|
|
12
|
+
const isRegistrationWrapper = (ts, node) => isExpressionWrapper(ts, node) || Boolean(ts.isSatisfiesExpression?.(node));
|
|
13
|
+
const unparenRegistration = (ts, node) => unparenWhile(node, (current) => isRegistrationWrapper(ts, current));
|
|
17
14
|
const returnedExpression = (ts, declaration) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const fn = ts.isVariableDeclaration(declaration) && declaration.initializer ? unparenRegistration(ts, declaration.initializer) : declaration;
|
|
16
|
+
if (!(ts.isArrowFunction(fn) || ts.isFunctionDeclaration(fn) || ts.isFunctionExpression(fn) || ts.isMethodDeclaration(fn)) || !fn.body)
|
|
17
|
+
return null;
|
|
18
|
+
if (!ts.isBlock(fn.body))
|
|
19
|
+
return fn.body;
|
|
20
|
+
const statements = fn.body.statements.filter(ts.isReturnStatement);
|
|
21
|
+
return statements.length === 1 ? statements[0]?.expression ?? null : null;
|
|
23
22
|
};
|
|
24
|
-
|
|
25
23
|
/** Every `name:` property assignment of an object literal over the program: [{declaration, initializer, checker}], memoised per name. */
|
|
26
24
|
const assignmentsOf = (ctx, name) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
const cached = ctx.propertySources.get(name);
|
|
26
|
+
if (cached)
|
|
27
|
+
return cached;
|
|
28
|
+
const { kit } = ctx;
|
|
29
|
+
const { ts } = kit;
|
|
30
|
+
const list = [];
|
|
31
|
+
for (const file of ctx.graph.files.values()) {
|
|
32
|
+
if (!file.sourceFile.text.includes(name))
|
|
33
|
+
continue;
|
|
34
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
35
|
+
kit.walk(file.sourceFile, (node) => {
|
|
36
|
+
if (ts.isPropertyAssignment(node) && kit.propertyNameText(node.name) === name && ts.isObjectLiteralExpression(node.parent)) {
|
|
37
|
+
// the property of the type the literal is checked against, so a typed const and a typed return meet the same declaration
|
|
38
|
+
const contextual = checker.getContextualType(node.parent)?.getProperty(name);
|
|
39
|
+
const symbol = contextual ?? checker.getSymbolAtLocation(node.name);
|
|
40
|
+
list.push({ declaration: symbol?.declarations?.[0] ?? null, initializer: node.initializer, checker });
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
ctx.propertySources.set(name, list);
|
|
46
|
+
return list;
|
|
46
47
|
};
|
|
47
|
-
|
|
48
48
|
const nameOfLiteral = (ctx, checker, literal, depth) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const { kit } = ctx;
|
|
50
|
+
const own = kit.propertyOf(literal, 'name');
|
|
51
|
+
if (own)
|
|
52
|
+
return kit.stringValue(checker, kit.valueOfProperty(own));
|
|
53
|
+
for (const property of literal.properties) {
|
|
54
|
+
if (!kit.ts.isSpreadAssignment(property))
|
|
55
|
+
continue;
|
|
56
|
+
const value = nameOfExpression(ctx, checker, property.expression, depth + 1);
|
|
57
|
+
if (value)
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
58
61
|
};
|
|
59
|
-
|
|
60
62
|
const nameFromCall = (ctx, checker, node, depth) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const { kit } = ctx;
|
|
64
|
+
const declarations = kit.declarationsOf(checker, node.expression);
|
|
65
|
+
for (const declaration of declarations) {
|
|
66
|
+
const body = returnedExpression(kit.ts, declaration);
|
|
67
|
+
const value = body ? nameOfExpression(ctx, kit.checkerOf(declaration.getSourceFile()), body, depth + 1) : null;
|
|
68
|
+
if (value)
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
68
72
|
};
|
|
69
|
-
|
|
70
73
|
const nameFromIdentifier = (ctx, checker, node, depth) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const { kit } = ctx;
|
|
75
|
+
const declaration = kit.declarationsOf(checker, node)[0];
|
|
76
|
+
return declaration && kit.ts.isVariableDeclaration(declaration) && declaration.initializer
|
|
77
|
+
? nameOfExpression(ctx, kit.checkerOf(declaration.getSourceFile()), declaration.initializer, depth + 1) : null;
|
|
75
78
|
};
|
|
76
|
-
|
|
77
79
|
/** True when `declaration` is a property of the `<app>.env.ts` reader's own interface that sits beside the options file declaring `target`: the reader feeds the options value, so its property is the same slot. */
|
|
78
80
|
const feedsOptions = (declaration, target) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const home = declaration?.getSourceFile().fileName ?? '';
|
|
82
|
+
return home.endsWith('.env.ts') && path.posix.dirname(home) === path.posix.dirname(target.getSourceFile().fileName);
|
|
81
83
|
};
|
|
82
|
-
|
|
83
84
|
const nameFromProperty = (ctx, checker, node, depth) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
const target = ctx.kit.declarationsOf(checker, node.name)[0];
|
|
86
|
+
if (!target)
|
|
87
|
+
return null;
|
|
88
|
+
const names = new Set(assignmentsOf(ctx, node.name.text).filter(item => item.declaration === target || feedsOptions(item.declaration, target))
|
|
89
|
+
.map(item => nameOfExpression(ctx, item.checker, item.initializer, depth + 1)).filter(Boolean));
|
|
90
|
+
return names.size === 1 ? [...names][0] ?? null : null;
|
|
89
91
|
};
|
|
90
|
-
|
|
91
92
|
function nameOfExpression(ctx, checker, expression, depth) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
const { ts } = ctx.kit;
|
|
94
|
+
const node = unparenRegistration(ts, expression);
|
|
95
|
+
if (!node || depth > 5)
|
|
96
|
+
return null;
|
|
97
|
+
if (ts.isObjectLiteralExpression(node))
|
|
98
|
+
return nameOfLiteral(ctx, checker, node, depth);
|
|
99
|
+
if (ts.isCallExpression(node))
|
|
100
|
+
return nameFromCall(ctx, checker, node, depth);
|
|
101
|
+
if (ts.isIdentifier(node))
|
|
102
|
+
return nameFromIdentifier(ctx, checker, node, depth);
|
|
103
|
+
if (ts.isPropertyAccessExpression(node))
|
|
104
|
+
return nameFromProperty(ctx, checker, node, depth);
|
|
105
|
+
return null;
|
|
100
106
|
}
|
|
101
|
-
|
|
102
107
|
const isCapabilityArray = (owner, name) => owner?.below.length === 1 && owner.below[0] === 'connection.ts' && [`${camel(owner.capability)}Entities`, `${camel(owner.capability)}Migrations`].includes(name);
|
|
103
|
-
|
|
104
108
|
const arrayDeclarationOf = (kit, checker, node) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
const { ts } = kit;
|
|
110
|
+
const declaration = kit.declarationsOf(checker, ts.isPropertyAccessExpression(node) ? node.name : node)[0];
|
|
111
|
+
// the identifier name was just checked, so the declaration is a named variable
|
|
112
|
+
return declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) ? declaration : null;
|
|
108
113
|
};
|
|
109
|
-
|
|
110
114
|
/** The capability arrays (`<c>Entities` / `<c>Migrations` of persistence/connection.ts) an expression lists. */
|
|
111
115
|
function arraysIn(ctx, checker, expression, out, depth) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
116
|
+
const { kit } = ctx;
|
|
117
|
+
const { ts } = kit;
|
|
118
|
+
const node = unparenRegistration(ts, expression);
|
|
119
|
+
if (!node || depth > 6)
|
|
120
|
+
return;
|
|
121
|
+
if (ts.isArrayLiteralExpression(node)) {
|
|
122
|
+
for (const element of node.elements) {
|
|
123
|
+
arraysIn(ctx, checker, ts.isSpreadElement(element) ? element.expression : element, out, depth + 1);
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (!ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node))
|
|
128
|
+
return;
|
|
129
|
+
const declaration = arrayDeclarationOf(kit, checker, node);
|
|
130
|
+
if (!declaration)
|
|
131
|
+
return;
|
|
132
|
+
const rel = kit.graphPath(declaration);
|
|
133
|
+
const owner = rel ? ctx.persistenceOf(rel) : null;
|
|
134
|
+
if (isCapabilityArray(owner, declaration.name.text)) {
|
|
135
|
+
out.push({ key: path.posix.dirname(owner.root), name: owner.capability });
|
|
136
|
+
}
|
|
137
|
+
else if (declaration.initializer)
|
|
138
|
+
arraysIn(ctx, kit.checkerOf(declaration.getSourceFile()), declaration.initializer, out, depth + 1);
|
|
128
139
|
}
|
|
129
|
-
|
|
130
140
|
const registrationArrays = (ctx, checker, literal) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
const arrays = [];
|
|
142
|
+
for (const key of ['entities', 'migrations']) {
|
|
143
|
+
const property = ctx.kit.propertyOf(literal, key);
|
|
144
|
+
if (property)
|
|
145
|
+
arraysIn(ctx, checker, ctx.kit.valueOfProperty(property), arrays, 0);
|
|
146
|
+
}
|
|
147
|
+
return arrays;
|
|
137
148
|
};
|
|
138
|
-
|
|
139
149
|
const recordRegistration = (registered, arrays, connection, site) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
for (const { key, name } of new Map(arrays.map((item) => [item.key, item])).values()) {
|
|
151
|
+
let entry = registered.get(key);
|
|
152
|
+
if (!entry) {
|
|
153
|
+
entry = { name, connections: new Map() };
|
|
154
|
+
registered.set(key, entry);
|
|
155
|
+
}
|
|
156
|
+
const sites = entry.connections;
|
|
157
|
+
if (!sites.has(connection))
|
|
158
|
+
sites.set(connection, site);
|
|
159
|
+
}
|
|
145
160
|
};
|
|
146
|
-
|
|
147
161
|
/**
|
|
148
162
|
* Where the persistence arrays of every capability are registered: the object literals (`DatabaseModule.register` connections and the
|
|
149
163
|
* migrate/cli app's) that list `<c>Entities` / `<c>Migrations` of a capability's `persistence/connection.ts` under a connection `name`.
|
|
@@ -154,92 +168,98 @@ const recordRegistration = (registered, arrays, connection, site) => {
|
|
|
154
168
|
* `registered`: capability root -> its name and the connections it is registered on (first site each).
|
|
155
169
|
*/
|
|
156
170
|
export function collectRegistrations({ kit, graph, persistenceOf }) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
const { ts } = kit;
|
|
172
|
+
const ctx = { kit, graph, persistenceOf, propertySources: new Map() }; // property name -> [{declaration, initializer, checker}] over the program
|
|
173
|
+
const all = []; // every registration literal: {file, node, connection | null when the name cannot be resolved}
|
|
174
|
+
const registered = new Map(); // capability root -> {name, connections: Map(connection -> first site)}
|
|
175
|
+
let registrations = 0;
|
|
176
|
+
for (const file of graph.files.values()) {
|
|
177
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
178
|
+
kit.walk(file.sourceFile, (node) => {
|
|
179
|
+
if (!ts.isObjectLiteralExpression(node))
|
|
180
|
+
return;
|
|
181
|
+
const arrays = registrationArrays(ctx, checker, node);
|
|
182
|
+
if (!arrays.length)
|
|
183
|
+
return;
|
|
184
|
+
registrations += 1;
|
|
185
|
+
const connection = nameOfLiteral(ctx, checker, node, 0);
|
|
186
|
+
all.push({ file, node, connection });
|
|
187
|
+
if (connection !== null)
|
|
188
|
+
recordRegistration(registered, arrays, connection, { file, node });
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return { registered, registrations, all };
|
|
175
192
|
}
|
|
176
|
-
|
|
177
193
|
const PERSISTENCE_SLOT = 'be.persistence';
|
|
178
194
|
/** The slot tiers whose capabilities belong to a bounded context: the domain and the projections (a projection is owned by the context whose connection holds its tables). */
|
|
179
195
|
const CONTEXT_TIERS = new Set(['domain', 'projections']);
|
|
180
|
-
|
|
181
196
|
/** True for a platform capability the manifest lists as `perConnection` (its tables exist on every connection that uses it); `root` is the capability root. */
|
|
182
197
|
export const isPerConnection = (resolver, root, name) => root.split('/').includes('platform') && (resolver.slot(PERSISTENCE_SLOT)?.perConnection ?? []).includes(name);
|
|
183
|
-
|
|
184
198
|
/**
|
|
185
199
|
* `persistenceOf(rel)`: {root, capability, folder, below} of a be.persistence file (`folder` the directory below persistence/, '' at its root),
|
|
186
200
|
* null for any other file. `root` is the persistence root, its dirname the capability root.
|
|
187
201
|
*/
|
|
188
|
-
export const persistenceOfFactory = resolver => rel => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
202
|
+
export const persistenceOfFactory = (resolver) => (rel) => {
|
|
203
|
+
const classified = resolver.classifyPath(rel);
|
|
204
|
+
if (classified.slot !== PERSISTENCE_SLOT)
|
|
205
|
+
return null;
|
|
206
|
+
const below = rel.slice(classified.root.length + 1).split('/');
|
|
207
|
+
return { root: classified.root, capability: path.posix.basename(path.posix.dirname(classified.root)), folder: below.length > 1 ? below[0] ?? '' : '', below };
|
|
193
208
|
};
|
|
194
|
-
|
|
195
209
|
/** The declared connection named by a decorator whose callee is declared in src/modules/platform/database/<conn>.decorators.ts, else null. */
|
|
196
210
|
const connectionOfDecorators = (kit, declared, checker, declaration) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
211
|
+
const { ts } = kit;
|
|
212
|
+
const decorators = kit.decorators(declaration);
|
|
213
|
+
for (const decorator of decorators) {
|
|
214
|
+
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
215
|
+
const targets = kit.declarationsOf(checker, callee);
|
|
216
|
+
for (const target of targets) {
|
|
217
|
+
const rel = kit.graphPath(target);
|
|
218
|
+
const name = rel ? [...declared.keys()].find(connection => rel === `${DATABASE_DIR}/${connection}.decorators.ts`) : null;
|
|
219
|
+
if (name)
|
|
220
|
+
return name;
|
|
221
|
+
}
|
|
204
222
|
}
|
|
205
|
-
|
|
206
|
-
return null;
|
|
223
|
+
return null;
|
|
207
224
|
};
|
|
208
|
-
|
|
209
225
|
const managerTarget = (ts, node) => {
|
|
210
|
-
|
|
211
|
-
|
|
226
|
+
if (ts.isPropertyAccessExpression(node))
|
|
227
|
+
return node.name;
|
|
228
|
+
return ts.isIdentifier(node) ? node : null;
|
|
212
229
|
};
|
|
213
|
-
|
|
214
230
|
/** The receiver expression of the `.transaction(callback)` call whose first callback parameter is `declaration`, else null. */
|
|
215
231
|
const transactionReceiver = (ts, declaration) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
const callback = declaration.parent;
|
|
233
|
+
if (!ts.isParameter(declaration) || !(ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) || callback.parameters[0] !== declaration)
|
|
234
|
+
return null;
|
|
235
|
+
const call = callback.parent;
|
|
236
|
+
if (!ts.isCallExpression(call) || !call.arguments.includes(callback) || !ts.isPropertyAccessExpression(call.expression) || call.expression.name.text !== 'transaction')
|
|
237
|
+
return null;
|
|
238
|
+
return call.expression.expression;
|
|
221
239
|
};
|
|
222
|
-
|
|
223
240
|
/**
|
|
224
241
|
* The declared connection whose entity manager `expression` is: a property or parameter injected with `Inject<Conn>EntityManager`, or the
|
|
225
242
|
* manager parameter of the callback of a `.transaction(...)` on such a manager. Null when the origin cannot be proven (never guessed).
|
|
226
243
|
*/
|
|
227
244
|
function connectionOfManagerIn(kit, declared, checker, expression, depth = 0) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
245
|
+
const { ts } = kit;
|
|
246
|
+
const node = unparenWhile(expression, (current) => isExpressionWrapper(ts, current));
|
|
247
|
+
if (!node || depth > 4)
|
|
248
|
+
return null;
|
|
249
|
+
const target = managerTarget(ts, node);
|
|
250
|
+
if (!target)
|
|
251
|
+
return null;
|
|
252
|
+
const declaration = kit.declarationsOf(checker, target)[0];
|
|
253
|
+
if (!declaration)
|
|
254
|
+
return null;
|
|
255
|
+
if (ts.isPropertyDeclaration(declaration) || ts.isParameter(declaration)) {
|
|
256
|
+
const direct = connectionOfDecorators(kit, declared, checker, declaration);
|
|
257
|
+
if (direct)
|
|
258
|
+
return direct;
|
|
259
|
+
}
|
|
260
|
+
const receiver = transactionReceiver(ts, declaration);
|
|
261
|
+
return receiver ? connectionOfManagerIn(kit, declared, checker, receiver, depth + 1) : null;
|
|
241
262
|
}
|
|
242
|
-
|
|
243
263
|
/**
|
|
244
264
|
* The bounded-context model of a program: which context (declared connection) each capability belongs to, and which connection an expression's
|
|
245
265
|
* entity manager is. A context is a connection; a capability belongs to the one declared connection its persistence arrays are registered on
|
|
@@ -248,75 +268,88 @@ function connectionOfManagerIn(kit, declared, checker, expression, depth = 0) {
|
|
|
248
268
|
* transaction callback parameter's receiver. Nothing is matched by a variable name.
|
|
249
269
|
*/
|
|
250
270
|
const MODELS = new WeakMap();
|
|
251
|
-
|
|
252
271
|
export function contextModelOf(kit, graph) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
272
|
+
const cached = MODELS.get(graph);
|
|
273
|
+
if (cached)
|
|
274
|
+
return cached;
|
|
275
|
+
const { ts, resolver } = kit;
|
|
276
|
+
const persistenceOf = persistenceOfFactory(resolver);
|
|
277
|
+
const connections = resolver.repo.connections;
|
|
278
|
+
const declared = new Map(connections.map((connection) => [connection.name, connection]));
|
|
279
|
+
const { registered, all } = collectRegistrations({ kit, graph, persistenceOf });
|
|
280
|
+
const perConnection = new Set();
|
|
281
|
+
const contextOfRoot = new Map(); // capability root -> declared connection name (single registration only)
|
|
282
|
+
for (const [root, { name, connections: sites }] of registered) {
|
|
283
|
+
if (isPerConnection(resolver, root, name)) {
|
|
284
|
+
perConnection.add(root);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const names = [...sites.keys()].filter(connection => declared.has(connection));
|
|
288
|
+
const [only] = names;
|
|
289
|
+
if (names.length === 1 && only !== undefined)
|
|
290
|
+
contextOfRoot.set(root, only);
|
|
291
|
+
}
|
|
292
|
+
/** The declared connection a capability root belongs to, or null (no registration, several, or a per-connection platform capability). */
|
|
293
|
+
const contextOfCapability = (root) => contextOfRoot.get(root) ?? null;
|
|
294
|
+
/** The context of the capability owning `rel` when that capability is of a context tier (domain, projections), else null: only these are bounded contexts. */
|
|
295
|
+
const contextOfFile = (rel) => {
|
|
296
|
+
const file = graph.files.get(rel);
|
|
297
|
+
if (!file?.owner || !CONTEXT_TIERS.has(file.tier ?? ''))
|
|
298
|
+
return null;
|
|
299
|
+
return contextOfCapability(file.owner.root);
|
|
300
|
+
};
|
|
301
|
+
const model = {
|
|
302
|
+
declared, registered, registrations: all, perConnection, contextOfCapability, contextOfFile,
|
|
303
|
+
connectionOfManager: (checker, expression) => connectionOfManagerIn(kit, declared, checker, expression),
|
|
304
|
+
unparen: node => unparenWhile(node, (current) => isExpressionWrapper(ts, current)),
|
|
305
|
+
};
|
|
306
|
+
MODELS.set(graph, model);
|
|
307
|
+
return model;
|
|
280
308
|
}
|
|
281
|
-
|
|
282
309
|
const composedConnection = (kit, declared, checker, inner) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
310
|
+
const { ts } = kit;
|
|
311
|
+
const parent = inner.parent;
|
|
312
|
+
if ((ts.isPropertyAssignment(parent) || ts.isPropertyAccessExpression(parent)) && parent.name === inner)
|
|
313
|
+
return null;
|
|
314
|
+
if (!(ts.isIdentifier(inner) || ts.isStringLiteralLike(inner) || ts.isPropertyAccessExpression(inner)))
|
|
315
|
+
return null;
|
|
316
|
+
const value = kit.stringValue(checker, inner);
|
|
317
|
+
return value !== null && declared.has(value) ? value : null;
|
|
289
318
|
};
|
|
290
|
-
|
|
291
319
|
const collectComposedConnections = (kit, declared, checker, call, file, items) => {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
320
|
+
for (const argument of call.arguments) {
|
|
321
|
+
kit.walk(argument, (inner) => {
|
|
322
|
+
const value = composedConnection(kit, declared, checker, inner);
|
|
323
|
+
if (value === null)
|
|
324
|
+
return true;
|
|
325
|
+
items.push({ connection: value, node: inner, file });
|
|
326
|
+
return false;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
300
329
|
};
|
|
301
|
-
|
|
302
330
|
/**
|
|
303
331
|
* The declared connection names the composition of `app` (its root app.module.ts and the composition groups of compose/) passes to
|
|
304
332
|
* the database module registration, as [{connection, node, file}] in path then source order.
|
|
305
333
|
*/
|
|
306
334
|
export function connectionsComposedBy(kit, app) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
335
|
+
const { ts } = kit;
|
|
336
|
+
const files = kit.appCompositionFiles(app);
|
|
337
|
+
if (!files.length)
|
|
338
|
+
return { root: null, items: [] };
|
|
339
|
+
const connections = kit.resolver.repo.connections;
|
|
340
|
+
const declared = new Set(connections.map(connection => connection.name));
|
|
341
|
+
const items = [];
|
|
342
|
+
for (const file of files) {
|
|
343
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
344
|
+
kit.walk(file.sourceFile, (node) => {
|
|
345
|
+
if (!(ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'register'))
|
|
346
|
+
return;
|
|
347
|
+
const declarations = kit.declarationsOf(checker, node.expression.expression);
|
|
348
|
+
const owner = declarations.map(kit.ownerOfDeclaration).find(Boolean);
|
|
349
|
+
if (owner?.tier !== 'platform' || owner.name !== 'database')
|
|
350
|
+
return;
|
|
351
|
+
collectComposedConnections(kit, declared, checker, node, file, items);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return { root: files[0] ?? null, items };
|
|
322
355
|
}
|