@starci/eslint-canon-be 3.5.0 → 3.6.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 +15 -0
- package/README.md +11 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +17 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +17 -10
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
|
@@ -1,325 +1,351 @@
|
|
|
1
1
|
/** BE-IDEMPOTENCY-3: marked client commands preserve their key and execute through the transactional inbox. */
|
|
2
|
-
import ts from "typescript"
|
|
3
|
-
import { hfsOf } from "./hfs.
|
|
4
|
-
import { baseName, ownerNameOf } from "./ports.
|
|
5
|
-
import { moduleOf, originsOfType, typed } from "./types.
|
|
6
|
-
import { isTransportSlot } from "./transport-slots.
|
|
7
|
-
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { hfsOf } from "./hfs.js";
|
|
4
|
+
import { baseName, ownerNameOf } from "./ports.js";
|
|
5
|
+
import { childNode, moduleOf, originsOfType, resolvedSymbol, typed } from "./types.js";
|
|
6
|
+
import { isTransportSlot } from "./transport-slots.js";
|
|
7
|
+
const ASSIGNING_PREFIXES = [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken];
|
|
8
8
|
/** Imported aliases and namespace access resolve to the declaring value. */
|
|
9
9
|
const valueSymbol = (checker, expression, seen = new Set()) => {
|
|
10
|
-
if (!expression || seen.has(expression))
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (!expression || seen.has(expression))
|
|
11
|
+
return undefined;
|
|
12
|
+
seen.add(expression);
|
|
13
|
+
const name = ts.isPropertyAccessExpression(expression) ? expression.name : expression;
|
|
13
14
|
const symbol = name.parent && ts.isShorthandPropertyAssignment(name.parent) && name.parent.name === name
|
|
14
|
-
? checker.getShorthandAssignmentValueSymbol(name.parent) : checker.getSymbolAtLocation(name)
|
|
15
|
-
const target =
|
|
15
|
+
? checker.getShorthandAssignmentValueSymbol(name.parent) : checker.getSymbolAtLocation(name);
|
|
16
|
+
const target = resolvedSymbol(checker, symbol);
|
|
16
17
|
const alias = target?.getDeclarations()?.find((declaration) => ts.isVariableDeclaration(declaration)
|
|
17
|
-
&& declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer
|
|
18
|
-
&& (ts.isIdentifier(declaration.initializer) || ts.isPropertyAccessExpression(declaration.initializer)))
|
|
19
|
-
return alias ? valueSymbol(checker, alias.initializer, seen) : target
|
|
20
|
-
}
|
|
21
|
-
|
|
18
|
+
&& Boolean(declaration.parent.flags & ts.NodeFlags.Const) && Boolean(declaration.initializer)
|
|
19
|
+
&& (declaration.initializer !== undefined && (ts.isIdentifier(declaration.initializer) || ts.isPropertyAccessExpression(declaration.initializer))));
|
|
20
|
+
return alias ? valueSymbol(checker, alias.initializer, seen) : target;
|
|
21
|
+
};
|
|
22
22
|
/** The genuine decorator belongs to its platform capability, rather than merely sharing a name. */
|
|
23
23
|
const ownedValue = (checker, hfs, expression, name, capability) => {
|
|
24
|
-
const symbol = valueSymbol(checker, expression)
|
|
24
|
+
const symbol = valueSymbol(checker, expression);
|
|
25
25
|
return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => {
|
|
26
|
-
const file = declaration.getSourceFile().fileName
|
|
27
|
-
return moduleOf(declaration, file) === null && hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === capability
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
26
|
+
const file = declaration.getSourceFile().fileName;
|
|
27
|
+
return moduleOf(declaration, file) === null && hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === capability;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
31
30
|
/** A resolved decorator declaration and its call arguments. */
|
|
32
31
|
const decorators = (checker, node) => (ts.getDecorators(node) ?? []).map((decorator) => {
|
|
33
|
-
const call = decorator.expression
|
|
34
|
-
const expression = ts.isCallExpression(call) ? call.expression : call
|
|
35
|
-
const symbol = valueSymbol(checker, expression)
|
|
36
|
-
return { expression, symbol, args: ts.isCallExpression(call) ? call.arguments : [], called: ts.isCallExpression(call) }
|
|
37
|
-
})
|
|
38
|
-
|
|
32
|
+
const call = decorator.expression;
|
|
33
|
+
const expression = ts.isCallExpression(call) ? call.expression : call;
|
|
34
|
+
const symbol = valueSymbol(checker, expression);
|
|
35
|
+
return { expression, symbol, args: ts.isCallExpression(call) ? call.arguments : [], called: ts.isCallExpression(call) };
|
|
36
|
+
});
|
|
39
37
|
/** Whether the class carries the platform inbox's effectful marker. */
|
|
40
38
|
const effectful = (checker, hfs, node) => decorators(checker, node).some((decorator) => decorator.called
|
|
41
|
-
&& decorator.args.length === 0 && ownedValue(checker, hfs, decorator.expression, "Effectful", "inbox"))
|
|
42
|
-
|
|
39
|
+
&& decorator.args.length === 0 && ownedValue(checker, hfs, decorator.expression, "Effectful", "inbox"));
|
|
43
40
|
/** A package declaration establishes framework identity even through an import alias. */
|
|
44
41
|
const fromPackage = (checker, expression, name, pkg) => {
|
|
45
|
-
const symbol = valueSymbol(checker, expression)
|
|
46
|
-
return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => moduleOf(declaration, declaration.getSourceFile().fileName) === pkg)
|
|
47
|
-
}
|
|
48
|
-
|
|
42
|
+
const symbol = valueSymbol(checker, expression);
|
|
43
|
+
return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => moduleOf(declaration, declaration.getSourceFile().fileName) === pkg);
|
|
44
|
+
};
|
|
49
45
|
/** Class inheritance keeps the Nest Command identity without relying on local spelling. */
|
|
50
46
|
const commandType = (checker, type, seen = new Set()) => {
|
|
51
|
-
if (!type || seen.has(type))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
if (!type || seen.has(type))
|
|
48
|
+
return false;
|
|
49
|
+
seen.add(type);
|
|
50
|
+
if (originsOfType(checker, type).some((origin) => origin.name === "Command" && origin.module === "@nestjs/cqrs"))
|
|
51
|
+
return true;
|
|
52
|
+
return type.isClassOrInterface() && (checker.getBaseTypes(type) ?? []).some((base) => commandType(checker, base, seen));
|
|
53
|
+
};
|
|
57
54
|
/** Required strings exclude optional properties, undefined, null and unconstrained types. */
|
|
58
55
|
const requiredString = (checker, type, property) => {
|
|
59
|
-
const member = checker.getPropertyOfType(type, property)
|
|
60
|
-
if (!member || member.flags & ts.SymbolFlags.Optional)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
const member = checker.getPropertyOfType(type, property);
|
|
57
|
+
if (!member || member.flags & ts.SymbolFlags.Optional)
|
|
58
|
+
return false;
|
|
59
|
+
const declaration = member.valueDeclaration ?? member.declarations?.[0];
|
|
60
|
+
if (!declaration)
|
|
61
|
+
return false;
|
|
62
|
+
const value = checker.getTypeOfSymbolAtLocation(member, declaration);
|
|
63
|
+
return (value.isUnion() ? value.types : [value]).every((part) => !!(part.flags & ts.TypeFlags.StringLike));
|
|
64
|
+
};
|
|
67
65
|
/** Canonical ExecuteParams carries the request, while a direct client params object carries its own key. */
|
|
68
66
|
const keyContract = (checker, type) => {
|
|
69
|
-
if (requiredString(checker, type, "idempotencyKey"))
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
if (requiredString(checker, type, "idempotencyKey"))
|
|
68
|
+
return true;
|
|
69
|
+
const request = checker.getPropertyOfType(type, "request");
|
|
70
|
+
const declaration = request?.valueDeclaration ?? request?.declarations?.[0];
|
|
71
|
+
return !!declaration && !!request && !(request.flags & ts.SymbolFlags.Optional)
|
|
72
|
+
&& requiredString(checker, checker.getTypeOfSymbolAtLocation(request, declaration), "idempotencyKey");
|
|
73
|
+
};
|
|
76
74
|
/** A sole returned expression admits an optional await and inline expression-bodied callbacks. */
|
|
77
75
|
const returned = (body) => {
|
|
78
|
-
if (!body)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
if (!body)
|
|
77
|
+
return null;
|
|
78
|
+
const only = ts.isBlock(body) ? body.statements[0] : undefined;
|
|
79
|
+
let expression = ts.isBlock(body) ? body.statements.length === 1 && only !== undefined && ts.isReturnStatement(only) ? only.expression : null : body;
|
|
80
|
+
while (expression && ts.isParenthesizedExpression(expression))
|
|
81
|
+
expression = expression.expression;
|
|
82
|
+
return expression && ts.isAwaitExpression(expression) ? expression.expression : expression;
|
|
83
|
+
};
|
|
84
84
|
/** Only a literal member name has a statically proved operation. */
|
|
85
|
-
const memberName = (expression) => ts.isPropertyAccessExpression(expression) ? expression.name.text : null
|
|
86
|
-
|
|
85
|
+
const memberName = (expression) => ts.isPropertyAccessExpression(expression) ? expression.name.text : null;
|
|
87
86
|
/** Computed literal names have ordinary last-write semantics; dynamic names could overwrite any field. */
|
|
88
87
|
const propertyName = (name) => ts.isComputedPropertyName(name)
|
|
89
88
|
? ts.isStringLiteralLike(name.expression) ? name.expression.text : null
|
|
90
|
-
: ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null
|
|
91
|
-
|
|
89
|
+
: ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
|
|
92
90
|
/** Property mappings retain their last assignment, including spreads, as JavaScript does. */
|
|
93
91
|
const propertyValue = (checker, expression, name) => {
|
|
94
|
-
if (!expression)
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
if (!expression)
|
|
93
|
+
return null;
|
|
94
|
+
if (!ts.isObjectLiteralExpression(expression))
|
|
95
|
+
return checker.getPropertyOfType(checker.getTypeAtLocation(expression), name) ? { base: expression, name } : null;
|
|
96
|
+
let result = null;
|
|
97
97
|
for (const property of expression.properties) {
|
|
98
98
|
if (ts.isSpreadAssignment(property)) {
|
|
99
|
-
const type = checker.getTypeAtLocation(property.expression)
|
|
100
|
-
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown) || checker.getIndexTypeOfType(type, ts.IndexKind.String))
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
const type = checker.getTypeAtLocation(property.expression);
|
|
100
|
+
if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown) || checker.getIndexTypeOfType(type, ts.IndexKind.String))
|
|
101
|
+
result = null;
|
|
102
|
+
else if (checker.getPropertyOfType(type, name))
|
|
103
|
+
result = { base: property.expression, name };
|
|
104
|
+
}
|
|
105
|
+
else if (propertyName(property.name) === null) {
|
|
106
|
+
result = null;
|
|
107
|
+
}
|
|
103
108
|
else if (propertyName(property.name) === name) {
|
|
104
109
|
result = ts.isPropertyAssignment(property) ? { expression: property.initializer }
|
|
105
|
-
: ts.isShorthandPropertyAssignment(property) ? { expression: property.name } : null
|
|
110
|
+
: ts.isShorthandPropertyAssignment(property) ? { expression: property.name } : null;
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
|
-
return result
|
|
109
|
-
}
|
|
110
|
-
|
|
113
|
+
return result;
|
|
114
|
+
};
|
|
111
115
|
/** A property path is rooted in the same lexical parameter, so a renamed or shadowed value cannot invent a key. */
|
|
112
116
|
const parameterPath = (checker, expression, parameter) => {
|
|
113
|
-
const path = []
|
|
114
|
-
let current = expression
|
|
117
|
+
const path = [];
|
|
118
|
+
let current = expression;
|
|
115
119
|
while (current && ts.isPropertyAccessExpression(current) && !current.questionDotToken) {
|
|
116
|
-
path.unshift(current.name.text)
|
|
117
|
-
current = current.expression
|
|
120
|
+
path.unshift(current.name.text);
|
|
121
|
+
current = current.expression;
|
|
118
122
|
}
|
|
119
|
-
return current && ts.isIdentifier(current) && valueSymbol(checker, current) === valueSymbol(checker, parameter.name) ? path : null
|
|
120
|
-
}
|
|
121
|
-
|
|
123
|
+
return current && ts.isIdentifier(current) && valueSymbol(checker, current) === valueSymbol(checker, parameter.name) ? path : null;
|
|
124
|
+
};
|
|
122
125
|
/** A mapped field has the expected path from the original parameter. */
|
|
123
126
|
const mappedFrom = (checker, mapping, parameter, paths) => {
|
|
124
|
-
if (!mapping)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
if (!mapping)
|
|
128
|
+
return false;
|
|
129
|
+
const path = parameterPath(checker, mapping.expression ?? mapping.base, parameter);
|
|
130
|
+
if (!path)
|
|
131
|
+
return false;
|
|
132
|
+
if (mapping.name)
|
|
133
|
+
path.push(mapping.name);
|
|
134
|
+
return paths.some((expected) => path.length === expected.length && path.every((part, index) => part === expected[index]));
|
|
135
|
+
};
|
|
131
136
|
/** Type origins bind the transactional manager and inbox port to their actual owners. */
|
|
132
|
-
const hasOrigin = (checker, hfs, expression, name, pkg, capability) => !!expression && originsOfType(checker, checker.getTypeAtLocation(expression)).some((origin) =>
|
|
133
|
-
origin.name === name && origin.module === pkg && (!capability || hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === capability))
|
|
134
|
-
|
|
137
|
+
const hasOrigin = (checker, hfs, expression, name, pkg, capability) => !!expression && originsOfType(checker, checker.getTypeAtLocation(expression)).some((origin) => origin.name === name && origin.module === pkg && (!capability || hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === capability));
|
|
135
138
|
/** Rejects visible calls, writes, constructions and explicit getter accesses before the inbox claim. */
|
|
136
139
|
const pureEnvelope = (checker, expression) => {
|
|
137
|
-
let pure = true
|
|
140
|
+
let pure = true;
|
|
138
141
|
const visit = (node) => {
|
|
139
142
|
if (ts.isCallExpression(node) || ts.isNewExpression(node) || ts.isAwaitExpression(node)
|
|
140
143
|
|| ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment
|
|
141
|
-
|| ts.isPrefixUnaryExpression(node) &&
|
|
142
|
-
|| ts.isPostfixUnaryExpression(node))
|
|
143
|
-
|
|
144
|
-
ts.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
|| ts.isPrefixUnaryExpression(node) && ASSIGNING_PREFIXES.includes(node.operator)
|
|
145
|
+
|| ts.isPostfixUnaryExpression(node))
|
|
146
|
+
pure = false;
|
|
147
|
+
if (ts.isPropertyAccessExpression(node) && valueSymbol(checker, node)?.getDeclarations()?.some(ts.isGetAccessorDeclaration))
|
|
148
|
+
pure = false;
|
|
149
|
+
ts.forEachChild(node, visit);
|
|
150
|
+
};
|
|
151
|
+
visit(expression);
|
|
152
|
+
return pure;
|
|
153
|
+
};
|
|
150
154
|
/** The service returns its transaction, whose actual callback returns the inbox execution with that callback's own manager. */
|
|
151
155
|
const transactionalClient = (checker, hfs, method) => {
|
|
152
|
-
const transaction = returned(method.body)
|
|
153
|
-
if (!transaction || !ts.isCallExpression(transaction) || transaction.questionDotToken || transaction.expression
|
|
154
|
-
|| !hasOrigin(checker, hfs, transaction.expression
|
|
155
|
-
|
|
156
|
+
const transaction = returned(method.body);
|
|
157
|
+
if (!transaction || !ts.isCallExpression(transaction) || transaction.questionDotToken || childNode(transaction.expression, "questionDotToken") || memberName(transaction.expression) !== "transaction"
|
|
158
|
+
|| !hasOrigin(checker, hfs, childNode(transaction.expression, "expression"), "EntityManager", "typeorm"))
|
|
159
|
+
return false;
|
|
160
|
+
const first = transaction.arguments[0];
|
|
156
161
|
const callback = transaction.arguments.length === 1 ? first : transaction.arguments.length === 2
|
|
157
|
-
&& ts.isStringLiteral(first) && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.text) ? transaction.arguments[1] : null
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
&& first !== undefined && ts.isStringLiteral(first) && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.text) ? transaction.arguments[1] : null;
|
|
163
|
+
const callbackParameter = callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) ? callback.parameters[0] : undefined;
|
|
164
|
+
if (!callback || !(ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))
|
|
165
|
+
|| callback.parameters.length !== 1 || !callbackParameter || !ts.isIdentifier(callbackParameter.name))
|
|
166
|
+
return false;
|
|
167
|
+
const execution = returned(callback.body);
|
|
168
|
+
if (!execution || !ts.isCallExpression(execution) || execution.questionDotToken || childNode(execution.expression, "questionDotToken") || memberName(execution.expression) !== "runClient"
|
|
169
|
+
|| !hasOrigin(checker, hfs, childNode(execution.expression, "expression"), "Inbox", null, "inbox") || execution.arguments.length !== 3)
|
|
170
|
+
return false;
|
|
171
|
+
const [envelope, manager, effect] = execution.arguments;
|
|
172
|
+
const original = method.parameters[0];
|
|
165
173
|
if (!original || !ts.isIdentifier(original.name) || !requiredString(checker, checker.getTypeAtLocation(original), "idempotencyKey")
|
|
166
|
-
|| !
|
|
174
|
+
|| !manager || !envelope || !effect
|
|
175
|
+
|| !ts.isIdentifier(manager) || valueSymbol(checker, manager) !== valueSymbol(checker, callbackParameter.name)
|
|
167
176
|
|| !hasOrigin(checker, hfs, manager, "EntityManager", "typeorm") || !ts.isObjectLiteralExpression(envelope)
|
|
168
|
-
|| !
|
|
169
|
-
|| !pureEnvelope(checker, envelope))
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const
|
|
177
|
+
|| !(ts.isArrowFunction(effect) || ts.isFunctionExpression(effect)) || effect.parameters.length !== 0
|
|
178
|
+
|| !pureEnvelope(checker, envelope))
|
|
179
|
+
return false;
|
|
180
|
+
const key = propertyValue(checker, envelope, "idempotencyKey");
|
|
181
|
+
const principal = propertyValue(checker, envelope, "principalId");
|
|
182
|
+
const operation = propertyValue(checker, envelope, "operation")?.expression;
|
|
173
183
|
return mappedFrom(checker, key, original, [["idempotencyKey"]]) && !!principal?.expression
|
|
174
184
|
&& (parameterPath(checker, principal.expression, original)?.length ?? 0) > 0
|
|
175
185
|
&& !!operation && ts.isStringLiteralLike(operation) && operation.text.length > 0
|
|
176
|
-
&& !!propertyValue(checker, envelope, "request")
|
|
177
|
-
}
|
|
178
|
-
|
|
186
|
+
&& !!propertyValue(checker, envelope, "request");
|
|
187
|
+
};
|
|
179
188
|
/** The CommandHandler decorator resolves its marked command declaration. */
|
|
180
189
|
const handledCommand = (checker, hfs, node) => {
|
|
181
190
|
for (const decorator of decorators(checker, node)) {
|
|
182
|
-
if (!fromPackage(checker, decorator.expression, "CommandHandler", "@nestjs/cqrs") || decorator.args.length !== 1)
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
if (!fromPackage(checker, decorator.expression, "CommandHandler", "@nestjs/cqrs") || decorator.args.length !== 1)
|
|
192
|
+
continue;
|
|
193
|
+
const command = valueSymbol(checker, decorator.args[0])?.getDeclarations()?.find(ts.isClassDeclaration);
|
|
194
|
+
if (command && effectful(checker, hfs, command))
|
|
195
|
+
return command;
|
|
185
196
|
}
|
|
186
|
-
return null
|
|
187
|
-
}
|
|
188
|
-
|
|
197
|
+
return null;
|
|
198
|
+
};
|
|
189
199
|
/** A marked handler delegates once to a concrete domain service and preserves the request's key. */
|
|
190
200
|
const delegatedMethod = (checker, hfs, handler) => {
|
|
191
|
-
const process = handler.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "process")
|
|
192
|
-
const call = returned(process?.body)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
const process = handler.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "process");
|
|
202
|
+
const call = returned(process?.body);
|
|
203
|
+
const command = process?.parameters[0];
|
|
204
|
+
if (!process || process.parameters.length !== 1 || !command || !ts.isIdentifier(command.name)
|
|
205
|
+
|| !call || !ts.isCallExpression(call) || call.questionDotToken || childNode(call.expression, "questionDotToken") || call.arguments.length !== 1)
|
|
206
|
+
return null;
|
|
207
|
+
const method = checker.getResolvedSignature(call)?.declaration;
|
|
196
208
|
if (!method || !ts.isMethodDeclaration(method) || !method.body
|
|
197
|
-
|| hfs.tierOf(method.getSourceFile().fileName) !== "domain" || !baseName(method.getSourceFile().fileName).endsWith(".service.ts"))
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
209
|
+
|| hfs.tierOf(method.getSourceFile().fileName) !== "domain" || !baseName(method.getSourceFile().fileName).endsWith(".service.ts"))
|
|
210
|
+
return null;
|
|
211
|
+
const mapping = propertyValue(checker, call.arguments[0], "idempotencyKey");
|
|
212
|
+
return mappedFrom(checker, mapping, command, [["params", "idempotencyKey"], ["params", "request", "idempotencyKey"]]) ? method : null;
|
|
213
|
+
};
|
|
202
214
|
/** Every reached service method is judged when that file is linted, including changed domain files. */
|
|
203
|
-
const reachedByProgram = new WeakMap()
|
|
215
|
+
const reachedByProgram = new WeakMap();
|
|
204
216
|
const reachedServices = (checker, program, hfs) => {
|
|
205
|
-
const cached = reachedByProgram.get(program)
|
|
206
|
-
if (cached)
|
|
207
|
-
|
|
217
|
+
const cached = reachedByProgram.get(program);
|
|
218
|
+
if (cached)
|
|
219
|
+
return cached;
|
|
220
|
+
const methods = new Set();
|
|
208
221
|
for (const source of program.getSourceFiles()) {
|
|
209
|
-
if (hfs.slotOf(source.fileName) !== "be.feature.application")
|
|
222
|
+
if (hfs.slotOf(source.fileName) !== "be.feature.application")
|
|
223
|
+
continue;
|
|
210
224
|
const visit = (node) => {
|
|
211
225
|
if (ts.isClassDeclaration(node) && handledCommand(checker, hfs, node)) {
|
|
212
|
-
const method = delegatedMethod(checker, hfs, node)
|
|
213
|
-
if (method)
|
|
226
|
+
const method = delegatedMethod(checker, hfs, node);
|
|
227
|
+
if (method)
|
|
228
|
+
methods.add(method);
|
|
214
229
|
}
|
|
215
|
-
ts.forEachChild(node, visit)
|
|
216
|
-
}
|
|
217
|
-
visit(source)
|
|
230
|
+
ts.forEachChild(node, visit);
|
|
231
|
+
};
|
|
232
|
+
visit(source);
|
|
218
233
|
}
|
|
219
|
-
reachedByProgram.set(program, methods)
|
|
220
|
-
return methods
|
|
221
|
-
}
|
|
222
|
-
|
|
234
|
+
reachedByProgram.set(program, methods);
|
|
235
|
+
return methods;
|
|
236
|
+
};
|
|
223
237
|
/** Genuine validators must reject empty, optional and overlong wire keys. */
|
|
224
238
|
const boundedKey = (checker, declaration) => {
|
|
225
|
-
if (!declaration || !ts.isPropertyDeclaration(declaration) || declaration.questionToken
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
|
|
239
|
+
if (!declaration || !ts.isPropertyDeclaration(declaration) || declaration.questionToken)
|
|
240
|
+
return false;
|
|
241
|
+
const key = propertyName(declaration.name);
|
|
242
|
+
if (key === null || !requiredString(checker, checker.getTypeAtLocation(declaration.parent), key))
|
|
243
|
+
return false;
|
|
244
|
+
const validators = decorators(checker, declaration).filter((decorator) => decorator.called && decorator.symbol?.getDeclarations()?.some((item) => moduleOf(item, item.getSourceFile().fileName) === "class-validator"));
|
|
245
|
+
const has = (name) => validators.some((decorator) => decorator.symbol?.name === name);
|
|
246
|
+
const bound = (name, accepts) => validators.some((decorator) => {
|
|
247
|
+
const first = decorator.args[0];
|
|
248
|
+
return decorator.symbol?.name === name
|
|
249
|
+
&& decorator.args.length > 0 && first !== undefined && ts.isNumericLiteral(first) && accepts(Number(first.text));
|
|
250
|
+
});
|
|
232
251
|
return !has("IsOptional") && !has("ValidateIf") && (has("IsUUID") || has("IsString")
|
|
233
|
-
&& bound("MinLength", (value) => value >= 1) && bound("MaxLength", (value) => value >= 1 && value <= 64))
|
|
234
|
-
}
|
|
235
|
-
|
|
252
|
+
&& bound("MinLength", (value) => value >= 1) && bound("MaxLength", (value) => value >= 1 && value <= 64));
|
|
253
|
+
};
|
|
236
254
|
/** Follow object mappings to their original property declarations rather than trusting an annotated return type. */
|
|
237
255
|
const propertySymbol = (checker, expression, path) => {
|
|
238
|
-
|
|
256
|
+
const [head, ...rest] = path;
|
|
257
|
+
if (head === undefined)
|
|
258
|
+
return valueSymbol(checker, expression);
|
|
239
259
|
if (ts.isObjectLiteralExpression(expression)) {
|
|
240
|
-
const mapping = propertyValue(checker, expression,
|
|
241
|
-
if (!mapping)
|
|
242
|
-
|
|
243
|
-
|
|
260
|
+
const mapping = propertyValue(checker, expression, head);
|
|
261
|
+
if (!mapping)
|
|
262
|
+
return undefined;
|
|
263
|
+
return mapping.expression ? propertySymbol(checker, mapping.expression, rest)
|
|
264
|
+
: propertySymbol(checker, mapping.base, [mapping.name, ...rest]);
|
|
244
265
|
}
|
|
245
|
-
let type = checker.getTypeAtLocation(expression)
|
|
246
|
-
let symbol
|
|
266
|
+
let type = checker.getTypeAtLocation(expression);
|
|
267
|
+
let symbol;
|
|
247
268
|
for (const name of path) {
|
|
248
|
-
symbol = checker.getPropertyOfType(type, name)
|
|
249
|
-
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0]
|
|
250
|
-
if (!declaration
|
|
251
|
-
|
|
269
|
+
symbol = checker.getPropertyOfType(type, name);
|
|
270
|
+
const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
|
|
271
|
+
if (!declaration || !symbol)
|
|
272
|
+
return undefined;
|
|
273
|
+
type = checker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
252
274
|
}
|
|
253
|
-
return symbol
|
|
254
|
-
}
|
|
255
|
-
|
|
275
|
+
return symbol;
|
|
276
|
+
};
|
|
256
277
|
/** A key mapped by a pure function must come from its actual argument, never a constant or captured replacement. */
|
|
257
278
|
const mappedKeySymbol = (checker, mapping, bindings = new Map()) => {
|
|
258
|
-
if (!mapping)
|
|
259
|
-
|
|
260
|
-
|
|
279
|
+
if (!mapping)
|
|
280
|
+
return undefined;
|
|
281
|
+
const path = mapping.name ? [mapping.name] : [];
|
|
282
|
+
let expression = mapping.expression ?? mapping.base;
|
|
261
283
|
while (ts.isPropertyAccessExpression(expression) && !expression.questionDotToken) {
|
|
262
|
-
path.unshift(expression.name.text)
|
|
263
|
-
expression = expression.expression
|
|
284
|
+
path.unshift(expression.name.text);
|
|
285
|
+
expression = expression.expression;
|
|
264
286
|
}
|
|
265
|
-
const actual = bindings.get(valueSymbol(checker, expression))
|
|
266
|
-
if (actual)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
287
|
+
const actual = bindings.get(valueSymbol(checker, expression));
|
|
288
|
+
if (actual)
|
|
289
|
+
return propertySymbol(checker, actual, path);
|
|
290
|
+
return bindings.size > 0 ? undefined : propertySymbol(checker, expression, path);
|
|
291
|
+
};
|
|
270
292
|
/** A mapper is proved by its sole pure return expression and original argument bindings, not its function name. */
|
|
271
293
|
const requestKey = (checker, expression) => {
|
|
272
|
-
if (!ts.isCallExpression(expression))
|
|
273
|
-
|
|
274
|
-
const
|
|
294
|
+
if (!ts.isCallExpression(expression))
|
|
295
|
+
return mappedKeySymbol(checker, propertyValue(checker, expression, "idempotencyKey"));
|
|
296
|
+
const mapper = checker.getResolvedSignature(expression)?.declaration;
|
|
297
|
+
const body = returned(childNode(mapper, "body"));
|
|
275
298
|
if (!mapper || !body || expression.questionDotToken || mapper.parameters.length !== expression.arguments.length
|
|
276
|
-
|| mapper.
|
|
277
|
-
|| !pureEnvelope(checker, body) || expression.arguments.some((argument) => !pureEnvelope(checker, argument)))
|
|
278
|
-
|
|
299
|
+
|| (ts.canHaveModifiers(mapper) ? ts.getModifiers(mapper) : undefined)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword)
|
|
300
|
+
|| !pureEnvelope(checker, body) || expression.arguments.some((argument) => !pureEnvelope(checker, argument)))
|
|
301
|
+
return undefined;
|
|
302
|
+
const bindings = new Map();
|
|
279
303
|
for (const [index, parameter] of mapper.parameters.entries()) {
|
|
280
|
-
if (!ts.isIdentifier(parameter.name) || parameter
|
|
281
|
-
|
|
304
|
+
if (!ts.isIdentifier(parameter.name) || childNode(parameter, "initializer") || childNode(parameter, "dotDotDotToken"))
|
|
305
|
+
return undefined;
|
|
306
|
+
bindings.set(valueSymbol(checker, parameter.name), expression.arguments[index]);
|
|
282
307
|
}
|
|
283
|
-
return mappedKeySymbol(checker, propertyValue(checker, body, "idempotencyKey"), bindings)
|
|
284
|
-
}
|
|
285
|
-
|
|
308
|
+
return mappedKeySymbol(checker, propertyValue(checker, body, "idempotencyKey"), bindings);
|
|
309
|
+
};
|
|
286
310
|
/** Follow the constructor's key mapping to the original DTO property, including a whole ExecuteParams value. */
|
|
287
311
|
const constructionKey = (checker, construction) => {
|
|
288
|
-
const params = construction.arguments?.[0]
|
|
289
|
-
const request = propertyValue(checker, params, "request")
|
|
290
|
-
let nestedSymbol
|
|
312
|
+
const params = construction.arguments?.[0];
|
|
313
|
+
const request = propertyValue(checker, params, "request");
|
|
314
|
+
let nestedSymbol;
|
|
291
315
|
if (request?.base) {
|
|
292
|
-
const property = checker.getPropertyOfType(checker.getTypeAtLocation(request.base), request.name)
|
|
293
|
-
const declaration = property?.valueDeclaration ?? property?.declarations?.[0]
|
|
294
|
-
if (declaration
|
|
316
|
+
const property = checker.getPropertyOfType(checker.getTypeAtLocation(request.base), request.name);
|
|
317
|
+
const declaration = property?.valueDeclaration ?? property?.declarations?.[0];
|
|
318
|
+
if (declaration && property)
|
|
319
|
+
nestedSymbol = checker.getPropertyOfType(checker.getTypeOfSymbolAtLocation(property, declaration), "idempotencyKey");
|
|
295
320
|
}
|
|
296
321
|
return nestedSymbol ?? (request?.expression ? requestKey(checker, request.expression)
|
|
297
|
-
: mappedKeySymbol(checker, propertyValue(checker, params, "idempotencyKey")))
|
|
298
|
-
}
|
|
299
|
-
|
|
322
|
+
: mappedKeySymbol(checker, propertyValue(checker, params, "idempotencyKey")));
|
|
323
|
+
};
|
|
300
324
|
/** Only DTO key declarations that reach an effectful command carry this rule's transport obligation. */
|
|
301
|
-
const keysByProgram = new WeakMap()
|
|
325
|
+
const keysByProgram = new WeakMap();
|
|
302
326
|
const reachedKeys = (checker, program, hfs) => {
|
|
303
|
-
const cached = keysByProgram.get(program)
|
|
304
|
-
if (cached)
|
|
305
|
-
|
|
327
|
+
const cached = keysByProgram.get(program);
|
|
328
|
+
if (cached)
|
|
329
|
+
return cached;
|
|
330
|
+
const keys = new Set();
|
|
306
331
|
for (const source of program.getSourceFiles()) {
|
|
307
|
-
if (!isTransportSlot(hfs.slotOf(source.fileName)))
|
|
332
|
+
if (!isTransportSlot(hfs.slotOf(source.fileName)))
|
|
333
|
+
continue;
|
|
308
334
|
const visit = (node) => {
|
|
309
335
|
if (ts.isNewExpression(node)) {
|
|
310
|
-
const command = valueSymbol(checker, node.expression)?.getDeclarations()?.find(ts.isClassDeclaration)
|
|
336
|
+
const command = valueSymbol(checker, node.expression)?.getDeclarations()?.find(ts.isClassDeclaration);
|
|
311
337
|
if (command && effectful(checker, hfs, command)) {
|
|
312
|
-
for (const declaration of constructionKey(checker, node)?.getDeclarations() ?? [])
|
|
338
|
+
for (const declaration of constructionKey(checker, node)?.getDeclarations() ?? [])
|
|
339
|
+
keys.add(declaration);
|
|
313
340
|
}
|
|
314
341
|
}
|
|
315
|
-
ts.forEachChild(node, visit)
|
|
316
|
-
}
|
|
317
|
-
visit(source)
|
|
342
|
+
ts.forEachChild(node, visit);
|
|
343
|
+
};
|
|
344
|
+
visit(source);
|
|
318
345
|
}
|
|
319
|
-
keysByProgram.set(program, keys)
|
|
320
|
-
return keys
|
|
321
|
-
}
|
|
322
|
-
|
|
346
|
+
keysByProgram.set(program, keys);
|
|
347
|
+
return keys;
|
|
348
|
+
};
|
|
323
349
|
/** Effectful commands carry a bounded client key to the one atomic domain inbox execution. */
|
|
324
350
|
export const mutationIdempotent = {
|
|
325
351
|
meta: {
|
|
@@ -336,68 +362,90 @@ export const mutationIdempotent = {
|
|
|
336
362
|
},
|
|
337
363
|
},
|
|
338
364
|
create(context) {
|
|
339
|
-
const hfs = hfsOf(context)
|
|
340
|
-
const slot = hfs.slotOf(context.filename)
|
|
341
|
-
if (!slot || slot.startsWith("be.tests."))
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
let
|
|
365
|
+
const hfs = hfsOf(context);
|
|
366
|
+
const slot = hfs.slotOf(context.filename);
|
|
367
|
+
if (!slot || slot.startsWith("be.tests."))
|
|
368
|
+
return {};
|
|
369
|
+
const { checker, program, toTs } = typed(context);
|
|
370
|
+
let reached;
|
|
371
|
+
let keys;
|
|
345
372
|
return {
|
|
346
373
|
Identifier(node) {
|
|
347
374
|
if (hfs.tierOf(context.filename) === "platform" && ownerNameOf(hfs, context.filename) === "inbox"
|
|
348
|
-
|| !ownedValue(checker, hfs, toTs(node), "Effectful", "inbox"))
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (
|
|
357
|
-
|
|
375
|
+
|| !ownedValue(checker, hfs, toTs(node), "Effectful", "inbox"))
|
|
376
|
+
return;
|
|
377
|
+
const parent = node.parent;
|
|
378
|
+
const typeOnly = parent?.type?.startsWith("TS") && !["TSAsExpression", "TSTypeAssertion", "TSNonNullExpression", "TSSatisfiesExpression", "TSInstantiationExpression"].includes(parent.type);
|
|
379
|
+
if (["ImportSpecifier", "ExportSpecifier", "Decorator"].includes(parent?.type) || typeOnly)
|
|
380
|
+
return;
|
|
381
|
+
if (parent?.type === "VariableDeclarator" && parent.id === node)
|
|
382
|
+
return;
|
|
383
|
+
if (parent?.type === "Property" && parent.key === node && !parent.computed && parent.value !== node)
|
|
384
|
+
return;
|
|
385
|
+
const reference = parent?.type === "MemberExpression" && parent.property === node ? parent : node;
|
|
386
|
+
if (reference.parent?.type === "CallExpression" && reference.parent.callee === reference)
|
|
387
|
+
return;
|
|
388
|
+
if (reference.parent?.type === "VariableDeclarator" && reference.parent.init === reference && reference.parent.parent.kind === "const")
|
|
389
|
+
return;
|
|
390
|
+
context.report({ node, messageId: "marker" });
|
|
358
391
|
},
|
|
359
392
|
CallExpression(node) {
|
|
360
|
-
const call = toTs(node)
|
|
361
|
-
if (ownedValue(checker, hfs, call.expression, "Effectful", "inbox") && node.parent?.type !== "Decorator")
|
|
393
|
+
const call = toTs(node);
|
|
394
|
+
if (ownedValue(checker, hfs, call.expression, "Effectful", "inbox") && node.parent?.type !== "Decorator")
|
|
395
|
+
context.report({ node, messageId: "marker" });
|
|
362
396
|
},
|
|
363
397
|
ClassDeclaration(node) {
|
|
364
|
-
const declaration = toTs(node)
|
|
365
|
-
const marks = decorators(checker, declaration).filter((decorator) => decorator.symbol?.name === "Effectful")
|
|
398
|
+
const declaration = toTs(node);
|
|
399
|
+
const marks = decorators(checker, declaration).filter((decorator) => decorator.symbol?.name === "Effectful");
|
|
366
400
|
if (marks.length > 0) {
|
|
367
401
|
if (!effectful(checker, hfs, declaration) || !commandType(checker, checker.getTypeAtLocation(declaration))) {
|
|
368
|
-
context.report({ node: node.id ?? node, messageId: "marker" })
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
402
|
+
context.report({ node: node.id ?? node, messageId: "marker" });
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
if (!(hfs.patterns ?? []).includes("idempotency"))
|
|
406
|
+
context.report({ node: node.id ?? node, messageId: "declaration" });
|
|
407
|
+
const constructor = declaration.members.find(ts.isConstructorDeclaration);
|
|
408
|
+
const parameter = constructor?.parameters.length === 1 ? constructor.parameters[0] : undefined;
|
|
409
|
+
if (!constructor || !parameter || !keyContract(checker, checker.getTypeAtLocation(parameter)))
|
|
410
|
+
context.report({ node: node.id ?? node, messageId: "key" });
|
|
373
411
|
}
|
|
374
412
|
}
|
|
375
|
-
if (!handledCommand(checker, hfs, declaration))
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
413
|
+
if (!handledCommand(checker, hfs, declaration))
|
|
414
|
+
return;
|
|
415
|
+
const method = delegatedMethod(checker, hfs, declaration);
|
|
416
|
+
if (!method)
|
|
417
|
+
context.report({ node: node.id ?? node, messageId: "handler" });
|
|
418
|
+
else if (!transactionalClient(checker, hfs, method))
|
|
419
|
+
context.report({ node: node.id ?? node, messageId: "transaction" });
|
|
379
420
|
},
|
|
380
421
|
MethodDefinition(node) {
|
|
381
|
-
if (hfs.tierOf(context.filename) !== "domain" || !baseName(context.filename).endsWith(".service.ts"))
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
422
|
+
if (hfs.tierOf(context.filename) !== "domain" || !baseName(context.filename).endsWith(".service.ts"))
|
|
423
|
+
return;
|
|
424
|
+
reached ??= reachedServices(checker, program, hfs);
|
|
425
|
+
const method = toTs(node);
|
|
426
|
+
if (reached.has(method) && ts.isMethodDeclaration(method) && !transactionalClient(checker, hfs, method))
|
|
427
|
+
context.report({ node: node.key, messageId: "transaction" });
|
|
385
428
|
},
|
|
386
429
|
PropertyDefinition(node) {
|
|
387
|
-
if (!isTransportSlot(slot))
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
430
|
+
if (!isTransportSlot(slot))
|
|
431
|
+
return;
|
|
432
|
+
keys ??= reachedKeys(checker, program, hfs);
|
|
433
|
+
const declaration = toTs(node);
|
|
434
|
+
if (keys.has(declaration) && !boundedKey(checker, declaration))
|
|
435
|
+
context.report({ node: node.key, messageId: "validation" });
|
|
391
436
|
},
|
|
392
437
|
NewExpression(node) {
|
|
393
|
-
if (!isTransportSlot(slot))
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
438
|
+
if (!isTransportSlot(slot))
|
|
439
|
+
return;
|
|
440
|
+
const construction = toTs(node);
|
|
441
|
+
const command = valueSymbol(checker, construction.expression)?.getDeclarations()?.find(ts.isClassDeclaration);
|
|
442
|
+
if (!command || !effectful(checker, hfs, command))
|
|
443
|
+
return;
|
|
444
|
+
const declarations = constructionKey(checker, construction)?.getDeclarations() ?? [];
|
|
445
|
+
const localProperty = declarations.some((declaration) => ts.isPropertyDeclaration(declaration) && declaration.getSourceFile() === construction.getSourceFile());
|
|
446
|
+
if (!localProperty && !declarations.some((declaration) => boundedKey(checker, declaration)))
|
|
447
|
+
context.report({ node, messageId: "validation" });
|
|
400
448
|
},
|
|
401
|
-
}
|
|
449
|
+
};
|
|
402
450
|
},
|
|
403
|
-
}
|
|
451
|
+
};
|