@starci/eslint-canon-be 3.4.57 → 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 +19 -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 +22 -14
- package/runtime/knowledge/hfs/rules.yaml +23 -0
- package/runtime/scripts/lib/package-at.mjs +5 -5
- 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,140 +1,163 @@
|
|
|
1
1
|
/** R263: a receipt transaction records and publishes; a reactor/job processes after commit. */
|
|
2
|
-
import ts from "typescript"
|
|
3
|
-
import { baseName, ownerNameOf } from "./ports.
|
|
4
|
-
import { originsOfType, typed } from "./types.
|
|
5
|
-
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { baseName, ownerNameOf } from "./ports.js";
|
|
4
|
+
import { childNode, originsOfType, resolvedSymbol, typed } from "./types.js";
|
|
6
5
|
/** Imported aliases and overload signatures retain the implementation's actual body. */
|
|
7
6
|
const bodiesOf = (checker, call) => {
|
|
8
|
-
const expression = call.expression
|
|
9
|
-
let name = expression
|
|
10
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const expression = call.expression;
|
|
8
|
+
let name = expression;
|
|
9
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
10
|
+
name = expression.name;
|
|
11
|
+
if (ts.isElementAccessExpression(expression))
|
|
12
|
+
name = expression.argumentExpression;
|
|
13
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
14
|
+
const target = resolvedSymbol(checker, symbol);
|
|
15
|
+
const declarations = [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])];
|
|
16
|
+
return [...new Set(declarations.map((declaration) => childNode(declaration, "body") ?? childNode(childNode(declaration, "initializer"), "body")).filter((body) => Boolean(body)))];
|
|
17
|
+
};
|
|
18
18
|
/** Receiver ownership is established by its declared type, including aliases and inherited ports; `accepts` also sees the type it came from. */
|
|
19
19
|
const hasOrigin = (checker, receiver, accepts, seen = new Set()) => {
|
|
20
|
-
const type = receiver && checker.getTypeAtLocation(receiver)
|
|
20
|
+
const type = receiver && checker.getTypeAtLocation(receiver);
|
|
21
21
|
const read = (current) => {
|
|
22
|
-
if (!current || seen.has(current))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
22
|
+
if (!current || seen.has(current))
|
|
23
|
+
return false;
|
|
24
|
+
seen.add(current);
|
|
25
|
+
if (originsOfType(checker, current).some((origin) => accepts(origin, current)))
|
|
26
|
+
return true;
|
|
27
|
+
const parts = current.isUnionOrIntersection() ? current.types : [];
|
|
28
|
+
const bases = current.isClassOrInterface() ? checker.getBaseTypes(current) ?? [] : [];
|
|
29
|
+
return [...parts, ...bases].some(read);
|
|
30
|
+
};
|
|
31
|
+
return read(type);
|
|
32
|
+
};
|
|
32
33
|
/** Bracket access with a literal key has the same meaning as a dotted method/property. */
|
|
33
34
|
const memberName = (expression) => {
|
|
34
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
36
|
+
return expression.name.text;
|
|
37
|
+
if (ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression))
|
|
38
|
+
return expression.argumentExpression.text;
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
39
41
|
/** A callback named process is the former in-transaction processing contract, including aliases and methods. */
|
|
40
42
|
const isProcessCallback = (checker, node) => {
|
|
41
|
-
if (!(ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node)))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (!(ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node)))
|
|
44
|
+
return false;
|
|
45
|
+
const name = ts.isComputedPropertyName(node.name) ? node.name.expression : node.name;
|
|
46
|
+
if (!(ts.isIdentifier(name) || ts.isStringLiteralLike(name)) || name.text !== "process")
|
|
47
|
+
return false;
|
|
48
|
+
return !!childNode(node, "body") || checker.getTypeAtLocation(childNode(node, "initializer") ?? node.name).getCallSignatures().length > 0;
|
|
49
|
+
};
|
|
47
50
|
/** Persisting receipt data and publishing through platform ports are allowed; domain/CQRS processing is deferred. */
|
|
48
51
|
const isBusinessOrigin = (hfs, origin) => {
|
|
49
|
-
if (origin.module === "@nestjs/cqrs")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
if (origin.module === "@nestjs/cqrs")
|
|
53
|
+
return ["CommandBus", "QueryBus"].includes(origin.name);
|
|
54
|
+
return origin.module === null && hfs.tierOf(origin.file) === "domain" && baseName(origin.file).endsWith(".service.ts");
|
|
55
|
+
};
|
|
53
56
|
/**
|
|
54
57
|
* A domain receipt port records a delivery and processes nothing: a class with no base class whose constructor takes only platform
|
|
55
58
|
* ports (and TypeORM), at least one of them the platform `Inbox`. It cannot reach another domain service or the CQRS buses, so a call
|
|
56
59
|
* on it inside the receipt transaction is the inbox record itself (owner ruling 2026-10-17 "Theo y tro": the owner delegated the decision to main).
|
|
57
60
|
*/
|
|
58
61
|
const isReceiptPort = (checker, hfs, type) => {
|
|
59
|
-
const declaration = type.getSymbol()?.getDeclarations()?.find(ts.isClassDeclaration)
|
|
60
|
-
const constructor = declaration && !declaration.heritageClauses ? declaration.members.find(ts.isConstructorDeclaration) : undefined
|
|
61
|
-
if (!constructor || constructor.parameters.length === 0)
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const declaration = type.getSymbol()?.getDeclarations()?.find(ts.isClassDeclaration);
|
|
63
|
+
const constructor = declaration && !declaration.heritageClauses ? declaration.members.find(ts.isConstructorDeclaration) : undefined;
|
|
64
|
+
if (!constructor || constructor.parameters.length === 0)
|
|
65
|
+
return false;
|
|
66
|
+
const dependencies = constructor.parameters.map((parameter) => originsOfType(checker, checker.getTypeAtLocation(parameter)));
|
|
67
|
+
const isPort = (origin) => origin.module === "typeorm" || (origin.module === null && hfs.tierOf(origin.file) === "platform");
|
|
68
|
+
const isInbox = (origin) => origin.module === null && origin.name === "Inbox" && hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === "inbox";
|
|
69
|
+
return dependencies.every((origins) => origins.length > 0 && origins.every(isPort)) && dependencies.some((origins) => origins.some(isInbox));
|
|
70
|
+
};
|
|
68
71
|
/** The transaction port's package establishes when the callback runs before commit. */
|
|
69
72
|
const isTransactionCall = (checker, call, receiver) => memberName(call.expression) === "transaction"
|
|
70
|
-
&& hasOrigin(checker, receiver, (origin) => origin.module === "typeorm" && ["EntityManager", "DataSource"].includes(origin.name))
|
|
71
|
-
|
|
73
|
+
&& hasOrigin(checker, receiver, (origin) => origin.module === "typeorm" && ["EntityManager", "DataSource"].includes(origin.name));
|
|
72
74
|
/** Extracting, binding or destructuring a method preserves its domain/bus receiver. */
|
|
73
75
|
const isBusinessCall = (checker, hfs, expression, seen = new Set()) => {
|
|
74
|
-
if (!expression || seen.has(expression))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (!expression || seen.has(expression))
|
|
77
|
+
return false;
|
|
78
|
+
seen.add(expression);
|
|
79
|
+
const accepts = (origin, type) => isBusinessOrigin(hfs, origin) && !isReceiptPort(checker, hfs, type);
|
|
80
|
+
if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression))
|
|
81
|
+
return isBusinessCall(checker, hfs, expression.expression, seen);
|
|
78
82
|
if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
|
|
79
|
-
if (hasOrigin(checker, expression.expression, accepts))
|
|
80
|
-
|
|
83
|
+
if (hasOrigin(checker, expression.expression, accepts))
|
|
84
|
+
return true;
|
|
85
|
+
if (["bind", "call", "apply"].includes(memberName(expression) ?? ""))
|
|
86
|
+
return isBusinessCall(checker, hfs, expression.expression, seen);
|
|
81
87
|
}
|
|
82
|
-
if (ts.isCallExpression(expression))
|
|
88
|
+
if (ts.isCallExpression(expression))
|
|
89
|
+
return isBusinessCall(checker, hfs, expression.expression, seen);
|
|
83
90
|
const name = ts.isPropertyAccessExpression(expression) ? expression.name
|
|
84
|
-
: ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression
|
|
85
|
-
const symbol = checker.getSymbolAtLocation(name)
|
|
86
|
-
const target =
|
|
91
|
+
: ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression;
|
|
92
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
93
|
+
const target = resolvedSymbol(checker, symbol);
|
|
87
94
|
return target?.getDeclarations()?.some((declaration) => {
|
|
88
|
-
if (ts.isBindingElement(declaration))
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
95
|
+
if (ts.isBindingElement(declaration))
|
|
96
|
+
return hasOrigin(checker, childNode(declaration.parent.parent, "initializer"), accepts);
|
|
97
|
+
return isBusinessCall(checker, hfs, childNode(declaration, "initializer"), seen);
|
|
98
|
+
}) ?? false;
|
|
99
|
+
};
|
|
93
100
|
/** Passing a const callback into transaction does not move its work past commit. */
|
|
94
101
|
const callbackBodies = (checker, expression, seen = new Set()) => {
|
|
95
|
-
if (!expression || seen.has(expression))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
if (!expression || seen.has(expression))
|
|
103
|
+
return [];
|
|
104
|
+
seen.add(expression);
|
|
105
|
+
const body = childNode(expression, "body");
|
|
106
|
+
if (body)
|
|
107
|
+
return [body];
|
|
108
|
+
if (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression))
|
|
109
|
+
return callbackBodies(checker, expression.expression, seen);
|
|
110
|
+
if (ts.isCallExpression(expression) && memberName(expression.expression) === "bind")
|
|
111
|
+
return callbackBodies(checker, childNode(expression.expression, "expression"), seen);
|
|
112
|
+
const reference = ts.isPropertyAccessExpression(expression) ? expression.name : expression;
|
|
113
|
+
const symbol = checker.getSymbolAtLocation(reference);
|
|
114
|
+
return symbol?.getDeclarations()?.flatMap((declaration) => {
|
|
115
|
+
const declared = childNode(declaration, "body");
|
|
116
|
+
return declared ? [declared] : callbackBodies(checker, childNode(declaration, "initializer"), seen);
|
|
117
|
+
}) ?? [];
|
|
118
|
+
};
|
|
105
119
|
/** Old inline process callbacks and business dispatch inside the receipt transaction violate handoff. */
|
|
106
120
|
const processesDelivery = (checker, hfs, body) => {
|
|
107
|
-
let found = false
|
|
108
|
-
const
|
|
121
|
+
let found = false;
|
|
122
|
+
const outside = new Set();
|
|
123
|
+
const inside = new Set();
|
|
109
124
|
const visit = (node, inTransaction = false) => {
|
|
110
|
-
const nodes =
|
|
111
|
-
if (found || nodes.has(node))
|
|
112
|
-
|
|
113
|
-
|
|
125
|
+
const nodes = inTransaction ? inside : outside;
|
|
126
|
+
if (found || nodes.has(node))
|
|
127
|
+
return;
|
|
128
|
+
nodes.add(node);
|
|
129
|
+
if (isProcessCallback(checker, node))
|
|
130
|
+
found = true;
|
|
114
131
|
if (ts.isCallExpression(node)) {
|
|
115
|
-
if (inTransaction && isBusinessCall(checker, hfs, node.expression))
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
if (inTransaction && isBusinessCall(checker, hfs, node.expression))
|
|
133
|
+
found = true;
|
|
134
|
+
const callee = node.expression;
|
|
135
|
+
if ((ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) && isTransactionCall(checker, node, callee.expression)) {
|
|
118
136
|
for (const argument of node.arguments) {
|
|
119
|
-
visit(argument, true)
|
|
120
|
-
for (const callback of callbackBodies(checker, argument))
|
|
137
|
+
visit(argument, true);
|
|
138
|
+
for (const callback of callbackBodies(checker, argument))
|
|
139
|
+
visit(callback, true);
|
|
121
140
|
}
|
|
122
|
-
return
|
|
141
|
+
return;
|
|
123
142
|
}
|
|
124
|
-
if (inTransaction)
|
|
143
|
+
if (inTransaction)
|
|
144
|
+
for (const callback of callbackBodies(checker, node.expression))
|
|
145
|
+
visit(callback, true);
|
|
125
146
|
}
|
|
126
|
-
ts.forEachChild(node, (child) => visit(child, inTransaction))
|
|
127
|
-
}
|
|
128
|
-
visit(body)
|
|
129
|
-
return found
|
|
130
|
-
}
|
|
131
|
-
|
|
147
|
+
ts.forEachChild(node, (child) => visit(child, inTransaction));
|
|
148
|
+
};
|
|
149
|
+
visit(body);
|
|
150
|
+
return found;
|
|
151
|
+
};
|
|
132
152
|
/** Inspect the linted intake method or the implementation resolved at a webhook door's domain call. */
|
|
133
153
|
export const webhookIntakeProcessesDelivery = (context, hfs, node) => {
|
|
134
|
-
const { checker, toTs } = typed(context)
|
|
135
|
-
const reference = toTs(node)
|
|
136
|
-
if (!reference)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
const { checker, toTs } = typed(context);
|
|
155
|
+
const reference = toTs(node);
|
|
156
|
+
if (!reference)
|
|
157
|
+
return false;
|
|
158
|
+
const own = childNode(reference, "body");
|
|
159
|
+
let bodies = own ? [own] : [];
|
|
160
|
+
if (ts.isCallExpression(reference))
|
|
161
|
+
bodies = [reference, ...bodiesOf(checker, reference)];
|
|
162
|
+
return bodies.some((body) => processesDelivery(checker, hfs, body));
|
|
163
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
2
|
+
import type { Context, Node } from "./rule.js";
|
|
3
|
+
import type { HfsView } from "./hfs.js";
|
|
4
|
+
/** A bus or feature handler receiver is never a webhook's delegating call. */
|
|
5
|
+
export declare const isWebhookForbiddenReceiver: (context: Context, hfs: HfsView, node: Node) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Forbidden import sites in a door or its declaring HTTP module. Named, type-only, namespace, dynamic and re-exported
|
|
8
|
+
* imports all resolve to the actual export; an inline import type is judged by its resolved type.
|
|
9
|
+
*/
|
|
10
|
+
export declare const webhookForbiddenReferences: (context: Context, hfs: HfsView, program: TSESTree.Program) => Node[];
|
|
11
|
+
/**
|
|
12
|
+
* Inspect a resolved domain intake's own body, closures included. Dynamic receivers, erased types, external signatures and
|
|
13
|
+
* calls through further helpers remain semantic review: this check does not prove the full inbox/outbox transaction.
|
|
14
|
+
*/
|
|
15
|
+
export declare const webhookIntakeDispatchesCommand: (context: Context, hfs: HfsView, call: Node) => boolean;
|
|
@@ -1,138 +1,145 @@
|
|
|
1
1
|
/** Typed webhook handoff checks: the HTTP door records a delivery; only a later consumer dispatches commands. */
|
|
2
|
-
import ts from "typescript"
|
|
3
|
-
import { walk } from "./ast.
|
|
4
|
-
import { injectedMembers } from "./doors.
|
|
5
|
-
import { moduleReferences } from "./import-source.
|
|
6
|
-
import { baseName } from "./ports.
|
|
7
|
-
import { moduleOf, originsOfType, typed } from "./types.
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const BUSES = new Set(["CommandBus", "QueryBus"])
|
|
11
|
-
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { walk } from "./ast.js";
|
|
4
|
+
import { injectedMembers } from "./doors.js";
|
|
5
|
+
import { moduleReferences, visitModuleReference } from "./import-source.js";
|
|
6
|
+
import { baseName } from "./ports.js";
|
|
7
|
+
import { childNode, moduleOf, originsOfType, resolvedSymbol, typed } from "./types.js";
|
|
8
|
+
const CQRS = "@nestjs/cqrs";
|
|
9
|
+
const BUSES = new Set(["CommandBus", "QueryBus"]);
|
|
12
10
|
/** A feature handler has a feature owner and the closed handler role, regardless of its imported alias. */
|
|
13
|
-
const isFeatureHandler = (hfs, file) => hfs.tierOf(file) === "feature" && baseName(file).endsWith(".handler.ts")
|
|
14
|
-
|
|
11
|
+
const isFeatureHandler = (hfs, file) => hfs.tierOf(file) === "feature" && baseName(file).endsWith(".handler.ts");
|
|
15
12
|
/** The bus's package and declared name, or the feature handler's declaring file, establish the forbidden origin. */
|
|
16
|
-
const forbiddenOrigin = (hfs, origin, buses) =>
|
|
17
|
-
(origin.module === CQRS && buses.has(origin.name)) || isFeatureHandler(hfs, origin.file)
|
|
18
|
-
|
|
13
|
+
const forbiddenOrigin = (hfs, origin, buses) => (origin.module === CQRS && buses.has(origin.name)) || isFeatureHandler(hfs, origin.file);
|
|
19
14
|
/** Include unions, intersections and class inheritance, so an alias or a subclass cannot conceal the bus. */
|
|
20
15
|
const hasForbiddenType = (checker, hfs, type, buses = BUSES, seen = new Set()) => {
|
|
21
|
-
if (!type || seen.has(type))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
if (!type || seen.has(type))
|
|
17
|
+
return false;
|
|
18
|
+
seen.add(type);
|
|
19
|
+
if (originsOfType(checker, type).some((origin) => forbiddenOrigin(hfs, origin, buses)))
|
|
20
|
+
return true;
|
|
21
|
+
const parts = type.isUnionOrIntersection() ? type.types : [];
|
|
22
|
+
const bases = type.isClassOrInterface() ? checker.getBaseTypes(type) ?? [] : [];
|
|
23
|
+
return [...parts, ...bases].some((part) => hasForbiddenType(checker, hfs, part, buses, seen));
|
|
24
|
+
};
|
|
29
25
|
/** A bus or feature handler receiver is never a webhook's delegating call. */
|
|
30
26
|
export const isWebhookForbiddenReceiver = (context, hfs, node) => {
|
|
31
|
-
const { checker, toTs } = typed(context)
|
|
32
|
-
const reference = toTs(node)
|
|
33
|
-
return reference ? hasForbiddenType(checker, hfs, checker.getTypeAtLocation(reference)) : false
|
|
34
|
-
}
|
|
35
|
-
|
|
27
|
+
const { checker, toTs } = typed(context);
|
|
28
|
+
const reference = toTs(node);
|
|
29
|
+
return reference ? hasForbiddenType(checker, hfs, checker.getTypeAtLocation(reference)) : false;
|
|
30
|
+
};
|
|
36
31
|
/** Resolve an imported/exported alias once before inspecting the actual declaration. */
|
|
37
|
-
const targetOf = (checker, symbol) =>
|
|
38
|
-
|
|
32
|
+
const targetOf = (checker, symbol) => resolvedSymbol(checker, symbol);
|
|
39
33
|
/** A module export's origin, including a bus subclass or an alias of its type. */
|
|
40
34
|
const forbiddenExport = (checker, hfs, original) => {
|
|
41
|
-
const symbol = targetOf(checker, original)
|
|
42
|
-
if (!symbol)
|
|
43
|
-
|
|
35
|
+
const symbol = targetOf(checker, original);
|
|
36
|
+
if (!symbol)
|
|
37
|
+
return false;
|
|
38
|
+
const declarations = symbol.getDeclarations() ?? [];
|
|
44
39
|
if (declarations.some((declaration) => {
|
|
45
|
-
const file = declaration.getSourceFile().fileName.replace(/\\/g, "/")
|
|
46
|
-
return isFeatureHandler(hfs, file) || (moduleOf(declaration, file) === CQRS && BUSES.has(symbol.getName()))
|
|
47
|
-
}))
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
40
|
+
const file = declaration.getSourceFile().fileName.replace(/\\/g, "/");
|
|
41
|
+
return isFeatureHandler(hfs, file) || (moduleOf(declaration, file) === CQRS && BUSES.has(symbol.getName()));
|
|
42
|
+
}))
|
|
43
|
+
return true;
|
|
44
|
+
const [first] = declarations;
|
|
45
|
+
if (first === undefined)
|
|
46
|
+
return false;
|
|
47
|
+
const type = checker.getTypeOfSymbolAtLocation(symbol, first);
|
|
48
|
+
if (hasForbiddenType(checker, hfs, type))
|
|
49
|
+
return true;
|
|
51
50
|
return !!(symbol.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Interface | ts.SymbolFlags.TypeAlias))
|
|
52
|
-
&& hasForbiddenType(checker, hfs, checker.getDeclaredTypeOfSymbol(symbol))
|
|
53
|
-
}
|
|
54
|
-
|
|
51
|
+
&& hasForbiddenType(checker, hfs, checker.getDeclaredTypeOfSymbol(symbol));
|
|
52
|
+
};
|
|
55
53
|
/** Inspect selected exports of the referenced module, so barrels and renamed imports keep their real owner. */
|
|
56
54
|
const forbiddenModuleReference = (checker, toTs, hfs, reference) => {
|
|
57
|
-
const { source, value, names } = reference
|
|
58
|
-
if (value === CQRS && names.some((name) => BUSES.has(name) || name === "*" || name === "default"))
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const { source, value, names } = reference;
|
|
56
|
+
if (value === CQRS && names.some((name) => BUSES.has(name ?? "") || name === "*" || name === "default"))
|
|
57
|
+
return true;
|
|
58
|
+
const sourceNode = toTs(source);
|
|
59
|
+
const module = sourceNode ? targetOf(checker, checker.getSymbolAtLocation(sourceNode)) : null;
|
|
60
|
+
if (!module)
|
|
61
|
+
return false;
|
|
62
|
+
const exports = checker.getExportsOfModule(module);
|
|
63
|
+
const wholeModule = names.includes("*") || (names.includes("default") && !exports.some((symbol) => symbol.getName() === "default"));
|
|
64
|
+
return exports.some((symbol) => (wholeModule || names.includes(symbol.getName())) && forbiddenExport(checker, hfs, symbol));
|
|
65
|
+
};
|
|
67
66
|
/**
|
|
68
67
|
* Forbidden import sites in a door or its declaring HTTP module. Named, type-only, namespace, dynamic and re-exported
|
|
69
68
|
* imports all resolve to the actual export; an inline import type is judged by its resolved type.
|
|
70
69
|
*/
|
|
71
70
|
export const webhookForbiddenReferences = (context, hfs, program) => {
|
|
72
|
-
const { checker, toTs } = typed(context)
|
|
73
|
-
const nodes = new Set()
|
|
71
|
+
const { checker, toTs } = typed(context);
|
|
72
|
+
const nodes = new Set();
|
|
74
73
|
const visitors = moduleReferences((reference) => {
|
|
75
|
-
if (forbiddenModuleReference(checker, toTs, hfs, reference))
|
|
76
|
-
|
|
74
|
+
if (forbiddenModuleReference(checker, toTs, hfs, reference))
|
|
75
|
+
nodes.add(reference.node);
|
|
76
|
+
});
|
|
77
77
|
walk(program, (node) => {
|
|
78
|
-
visitors
|
|
79
|
-
if (node.type !== "TSImportType")
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
visitModuleReference(visitors, node);
|
|
79
|
+
if (node.type !== "TSImportType")
|
|
80
|
+
return;
|
|
81
|
+
const typeNode = toTs(node);
|
|
82
|
+
if (typeNode && hasForbiddenType(checker, hfs, checker.getTypeAtLocation(typeNode)))
|
|
83
|
+
nodes.add(node);
|
|
84
|
+
});
|
|
83
85
|
// An ambiently supplied type still cannot be injected; an import finding already refuses the same dependency.
|
|
84
|
-
if (nodes.size === 0)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
86
|
+
if (nodes.size === 0)
|
|
87
|
+
walk(program, (node) => {
|
|
88
|
+
if (node.type !== "ClassDeclaration")
|
|
89
|
+
return;
|
|
90
|
+
for (const member of injectedMembers(context, node)) {
|
|
91
|
+
if (member.annotation && isWebhookForbiddenReceiver(context, hfs, member.annotation))
|
|
92
|
+
nodes.add(member.node);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return [...nodes];
|
|
96
|
+
};
|
|
93
97
|
/** The symbol of a called member, including a statically resolved bracket access. */
|
|
94
98
|
const calledSymbol = (checker, expression) => {
|
|
95
|
-
if (ts.isPropertyAccessExpression(expression))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
100
|
+
return targetOf(checker, checker.getSymbolAtLocation(expression.name));
|
|
101
|
+
if (ts.isElementAccessExpression(expression))
|
|
102
|
+
return targetOf(checker, checker.getSymbolAtLocation(expression.argumentExpression));
|
|
103
|
+
return targetOf(checker, checker.getSymbolAtLocation(expression));
|
|
104
|
+
};
|
|
100
105
|
/** Overload declarations point back to their implementation; arrow-valued service members also carry a body. */
|
|
101
106
|
const bodyOf = (declaration) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
const body = childNode(declaration, "body");
|
|
108
|
+
if (body)
|
|
109
|
+
return body;
|
|
110
|
+
const initializer = childNode(declaration, "initializer");
|
|
111
|
+
return initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)) ? initializer.body : null;
|
|
112
|
+
};
|
|
107
113
|
/** Bodies the checker actually resolves at the intake call, never every other method of the service. */
|
|
108
114
|
const calledBodies = (checker, call) => {
|
|
109
|
-
const signature = checker.getResolvedSignature(call)?.declaration
|
|
110
|
-
const declarations = calledSymbol(checker, call.expression)?.getDeclarations() ?? []
|
|
111
|
-
return [...new Set([signature, ...declarations].map(bodyOf).filter(Boolean))]
|
|
112
|
-
}
|
|
113
|
-
|
|
115
|
+
const signature = checker.getResolvedSignature(call)?.declaration;
|
|
116
|
+
const declarations = calledSymbol(checker, call.expression)?.getDeclarations() ?? [];
|
|
117
|
+
return [...new Set([signature, ...declarations].map((declaration) => bodyOf(declaration)).filter((body) => Boolean(body)))];
|
|
118
|
+
};
|
|
114
119
|
/** A method body dispatches on a CQRS bus or feature handler when the receiver's genuine declared type proves it. */
|
|
115
120
|
const dispatchesCommand = (checker, hfs, body) => {
|
|
116
|
-
let found = false
|
|
121
|
+
let found = false;
|
|
117
122
|
const visit = (node) => {
|
|
118
|
-
if (found)
|
|
123
|
+
if (found)
|
|
124
|
+
return;
|
|
119
125
|
if (ts.isCallExpression(node) && (ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
|
|
120
|
-
const type = checker.getTypeAtLocation(node.expression.expression)
|
|
121
|
-
if (hasForbiddenType(checker, hfs, type))
|
|
126
|
+
const type = checker.getTypeAtLocation(node.expression.expression);
|
|
127
|
+
if (hasForbiddenType(checker, hfs, type))
|
|
128
|
+
found = true;
|
|
122
129
|
}
|
|
123
|
-
ts.forEachChild(node, visit)
|
|
124
|
-
}
|
|
125
|
-
visit(body)
|
|
126
|
-
return found
|
|
127
|
-
}
|
|
128
|
-
|
|
130
|
+
ts.forEachChild(node, visit);
|
|
131
|
+
};
|
|
132
|
+
visit(body);
|
|
133
|
+
return found;
|
|
134
|
+
};
|
|
129
135
|
/**
|
|
130
136
|
* Inspect a resolved domain intake's own body, closures included. Dynamic receivers, erased types, external signatures and
|
|
131
137
|
* calls through further helpers remain semantic review: this check does not prove the full inbox/outbox transaction.
|
|
132
138
|
*/
|
|
133
139
|
export const webhookIntakeDispatchesCommand = (context, hfs, call) => {
|
|
134
|
-
const { checker, toTs } = typed(context)
|
|
135
|
-
const reference = toTs(call)
|
|
136
|
-
if (!reference || !ts.isCallExpression(reference))
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
const { checker, toTs } = typed(context);
|
|
141
|
+
const reference = toTs(call);
|
|
142
|
+
if (!reference || !ts.isCallExpression(reference))
|
|
143
|
+
return false;
|
|
144
|
+
return calledBodies(checker, reference).some((body) => dispatchesCommand(checker, hfs, body));
|
|
145
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
2
|
+
import type { Context, Node } from "./rule.js";
|
|
3
|
+
import type { HfsView } from "./hfs.js";
|
|
4
|
+
/** A webhook challenge handler's first statements: the verification call, the bound result and the echoing return. */
|
|
5
|
+
export interface WebhookChallenge {
|
|
6
|
+
readonly call: TSESTree.CallExpression;
|
|
7
|
+
readonly result: TSESTree.Identifier | null;
|
|
8
|
+
readonly echo: TSESTree.Statement | undefined;
|
|
9
|
+
readonly statements: TSESTree.Statement[];
|
|
10
|
+
}
|
|
11
|
+
/** The shared platform proof, identified by its declared owner. */
|
|
12
|
+
export declare const isWebhookSignatureType: (context: Context, node: Node) => boolean;
|
|
13
|
+
/** A service declared by a domain owner, rather than a similarly named local or package type. */
|
|
14
|
+
export declare const isWebhookDomainServiceType: (context: Context, hfs: HfsView, node: Node) => boolean;
|
|
15
|
+
/** POST's first statement remains the proof itself, before the intake or acknowledgement. */
|
|
16
|
+
export declare const firstWebhookVerification: (context: Context, hfs: HfsView, method: TSESTree.MethodDefinition) => TSESTree.CallExpression | null;
|
|
17
|
+
/** The optional GET proves once, binding its result with const or returning the verifier call directly. */
|
|
18
|
+
export declare const firstWebhookChallenge: (context: Context, hfs: HfsView, method: TSESTree.MethodDefinition) => WebhookChallenge | null;
|
|
19
|
+
/** The GET echoes only the original proof's value, with no intervening work or transformation. */
|
|
20
|
+
export declare const isWebhookChallengeReturn: (context: Context, node: Node, challenge: WebhookChallenge | null | undefined) => boolean;
|