@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
|
@@ -9,100 +9,95 @@
|
|
|
9
9
|
* (`CommandBus`, `QueryBus`, `RequestLocale` are judged by where they are declared); what a decorator is comes
|
|
10
10
|
* from the import that binds it. No rule tests a directory spelled in a path pattern or a variable name.
|
|
11
11
|
*/
|
|
12
|
-
import ts from "typescript"
|
|
13
|
-
import { walk } from "./lib/ast.
|
|
14
|
-
import { hfsOf } from "./lib/hfs.
|
|
15
|
-
import { decoratorArguments, decoratorCallee, importOf, isImportedFrom, moduleReferences } from "./lib/import-source.
|
|
16
|
-
import { isTransportSlot, KIND_DOOR_SLOTS } from "./lib/transport-slots.
|
|
17
|
-
import { isPackageType, typeOrigins, typed } from "./lib/types.
|
|
18
|
-
import { operationRouteEvidence, restExceptionEvidence } from "./operations.
|
|
19
|
-
|
|
12
|
+
import ts from "typescript";
|
|
13
|
+
import { walk } from "./lib/ast.js";
|
|
14
|
+
import { hfsOf } from "./lib/hfs.js";
|
|
15
|
+
import { decoratorArguments, decoratorCallee, importOf, isImportedFrom, moduleReferences } from "./lib/import-source.js";
|
|
16
|
+
import { isTransportSlot, KIND_DOOR_SLOTS } from "./lib/transport-slots.js";
|
|
17
|
+
import { isPackageType, typeOrigins, typed } from "./lib/types.js";
|
|
18
|
+
import { operationRouteEvidence, restExceptionEvidence } from "./operations.js";
|
|
20
19
|
/** The HTTP route decorators of `@nestjs/common` (`Sse` is a route too: a `text/event-stream` GET that needs its own evidence). */
|
|
21
|
-
const HTTP_ROUTES = ["Get", "Post", "Put", "Patch", "Delete", "All", "Options", "Head", "Sse"]
|
|
22
|
-
|
|
20
|
+
const HTTP_ROUTES = ["Get", "Post", "Put", "Patch", "Delete", "All", "Options", "Head", "Sse"];
|
|
23
21
|
/** The GraphQL operation decorators of `@nestjs/graphql`. */
|
|
24
|
-
const GRAPHQL_OPERATIONS = ["Query", "Mutation", "Subscription", "ResolveField"]
|
|
25
|
-
|
|
22
|
+
const GRAPHQL_OPERATIONS = ["Query", "Mutation", "Subscription", "ResolveField"];
|
|
26
23
|
/** The slot of REST doors. */
|
|
27
|
-
const HTTP_SLOT = "be.transport.http"
|
|
28
|
-
|
|
24
|
+
const HTTP_SLOT = "be.transport.http";
|
|
29
25
|
/** The slot of provider webhook doors (the REST doors of the webhook kind). */
|
|
30
|
-
const WEBHOOK_SLOT = "be.feature.webhooks.http"
|
|
31
|
-
|
|
26
|
+
const WEBHOOK_SLOT = "be.feature.webhooks.http";
|
|
32
27
|
/** The slot of server-sent-events doors (the event-stream REST doors of the realtime kind). */
|
|
33
|
-
const SSE_SLOT = "be.feature.realtime.sse"
|
|
34
|
-
|
|
28
|
+
const SSE_SLOT = "be.feature.realtime.sse";
|
|
35
29
|
/** Slots whose classes are entered through a method the framework calls on a queue. */
|
|
36
|
-
const PLAIN_ENTRY_SLOTS = new Set(["be.transport.message"])
|
|
37
|
-
|
|
30
|
+
const PLAIN_ENTRY_SLOTS = new Set(["be.transport.message"]);
|
|
38
31
|
/** True for the decorators that make a method a transport handler (a socket handler belongs to the realtime kind, which has its own laws). */
|
|
39
32
|
const isRouteDecorator = (context, decorator) => {
|
|
40
|
-
const callee = decoratorCallee(decorator)
|
|
33
|
+
const callee = decoratorCallee(decorator);
|
|
41
34
|
return isImportedFrom(context, callee, "@nestjs/common", HTTP_ROUTES)
|
|
42
|
-
|| isImportedFrom(context, callee, "@nestjs/graphql", GRAPHQL_OPERATIONS)
|
|
43
|
-
}
|
|
44
|
-
|
|
35
|
+
|| isImportedFrom(context, callee, "@nestjs/graphql", GRAPHQL_OPERATIONS);
|
|
36
|
+
};
|
|
45
37
|
/** True when the class declares (transitively through its members' decorators) nothing but is a transport door: it has handler methods. */
|
|
46
38
|
const handlerMethods = (context, node, slot) => node.body.body.filter((member) => {
|
|
47
|
-
if (member.type !== "MethodDefinition" || member.kind !== "method" || member.static)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
if (member.type !== "MethodDefinition" || member.kind !== "method" || member.static)
|
|
40
|
+
return false;
|
|
41
|
+
if ((member.decorators ?? []).some((decorator) => isRouteDecorator(context, decorator)))
|
|
42
|
+
return true;
|
|
43
|
+
return PLAIN_ENTRY_SLOTS.has(slot) && member.accessibility !== "private" && member.accessibility !== "protected";
|
|
44
|
+
});
|
|
52
45
|
/** The bus receivers of `@nestjs/cqrs`. */
|
|
53
|
-
const isBus = (context, node) => isPackageType(context, node, "CommandBus", "@nestjs/cqrs") || isPackageType(context, node, "QueryBus", "@nestjs/cqrs")
|
|
54
|
-
|
|
46
|
+
const isBus = (context, node) => isPackageType(context, node, "CommandBus", "@nestjs/cqrs") || isPackageType(context, node, "QueryBus", "@nestjs/cqrs");
|
|
55
47
|
/** True when a declaration file is owned by the capability `capability` of a platform slot. */
|
|
56
|
-
const declaredByCapability = (hfs, file, capability) => hfs.slotOf(file) === "be.platform" && hfs.ownerOf(file)?.split("/").pop() === capability
|
|
57
|
-
|
|
48
|
+
const declaredByCapability = (hfs, file, capability) => hfs.slotOf(file) === "be.platform" && hfs.ownerOf(file)?.split("/").pop() === capability;
|
|
49
|
+
/** The decorators a node carries, read off a node whose type is not known (undefined when it has none). */
|
|
50
|
+
const decoratorsOf = (node) => (node && "decorators" in node ? node.decorators : undefined);
|
|
58
51
|
// -- transport-is-thin -------------------------------------------------------------------------------------
|
|
59
|
-
|
|
60
52
|
/** What a transport class may hold, by the type of the injected value. */
|
|
61
53
|
const isAllowedInjection = (context, hfs, slot, annotation) => {
|
|
62
|
-
const origins = typeOrigins(context, annotation)
|
|
54
|
+
const origins = typeOrigins(context, annotation);
|
|
63
55
|
return origins.some((origin) => {
|
|
64
|
-
if ((origin.name === "CommandBus" || origin.name === "QueryBus") && origin.module === "@nestjs/cqrs")
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
if ((origin.name === "CommandBus" || origin.name === "QueryBus") && origin.module === "@nestjs/cqrs")
|
|
57
|
+
return true;
|
|
58
|
+
if (origin.name === "RequestLocale" && slot === HTTP_SLOT && declaredByCapability(hfs, origin.file, "i18n"))
|
|
59
|
+
return true;
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
70
63
|
/** True for a decorator that injects: `Inject` of Nest, or a function declared in a `*.decorators.ts` file, or a `@nestjs/typeorm` injector. */
|
|
71
64
|
const isInjectorDecorator = (context, decorator) => {
|
|
72
|
-
const callee = decoratorCallee(decorator)
|
|
73
|
-
if (callee?.type !== "Identifier")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (found?.source === "@nestjs/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
const callee = decoratorCallee(decorator);
|
|
66
|
+
if (callee?.type !== "Identifier")
|
|
67
|
+
return false;
|
|
68
|
+
const found = importOf(context, callee);
|
|
69
|
+
if (found?.source === "@nestjs/common" && found.imported === "Inject")
|
|
70
|
+
return true;
|
|
71
|
+
if (found?.source === "@nestjs/typeorm")
|
|
72
|
+
return true;
|
|
73
|
+
const { checker, toTs } = typed(context);
|
|
74
|
+
let symbol = checker.getSymbolAtLocation(toTs(callee));
|
|
75
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
76
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
77
|
+
return (symbol?.getDeclarations() ?? []).some((declaration) => declaration.getSourceFile().fileName.replace(/\\/g, "/").endsWith(".decorators.ts"));
|
|
78
|
+
};
|
|
83
79
|
/** Counts the bus dispatches (`<bus>.execute(...)`) a method makes, closures included. */
|
|
84
80
|
const dispatchesOf = (context, method) => {
|
|
85
|
-
let count = 0
|
|
81
|
+
let count = 0;
|
|
86
82
|
walk(method.value.body, (node) => {
|
|
87
|
-
if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "execute" && isBus(context, node.callee.object))
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "execute" && isBus(context, node.callee.object))
|
|
84
|
+
count += 1;
|
|
85
|
+
});
|
|
86
|
+
return count;
|
|
87
|
+
};
|
|
92
88
|
/** Statements and expressions that are a decision or a repetition: none of them belongs in a door. */
|
|
93
|
-
const DECISION_NODES = new Set(["IfStatement", "SwitchStatement", "ConditionalExpression", "LogicalExpression", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement", "TryStatement", "ThrowStatement"])
|
|
94
|
-
|
|
89
|
+
const DECISION_NODES = new Set(["IfStatement", "SwitchStatement", "ConditionalExpression", "LogicalExpression", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement", "TryStatement", "ThrowStatement"]);
|
|
95
90
|
/** What an injected type is to a door: `bus`, `locale`, or null. */
|
|
96
91
|
const injectedKind = (context, annotation) => {
|
|
97
|
-
const origins = typeOrigins(context, annotation)
|
|
98
|
-
if (origins.some((origin) => (origin.name === "CommandBus" || origin.name === "QueryBus") && origin.module === "@nestjs/cqrs"))
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
const origins = typeOrigins(context, annotation);
|
|
93
|
+
if (origins.some((origin) => (origin.name === "CommandBus" || origin.name === "QueryBus") && origin.module === "@nestjs/cqrs"))
|
|
94
|
+
return "bus";
|
|
95
|
+
if (origins.some((origin) => origin.name === "RequestLocale" && origin.module === null))
|
|
96
|
+
return "locale";
|
|
97
|
+
return null;
|
|
98
|
+
};
|
|
103
99
|
/** True for `this.<name>` where name is one of `names`. */
|
|
104
|
-
const isThisMember = (expression, names) => expression?.type === "MemberExpression" && !expression.computed && expression.object.type === "ThisExpression" && expression.property.type === "Identifier" && names.has(expression.property.name)
|
|
105
|
-
|
|
100
|
+
const isThisMember = (expression, names) => expression?.type === "MemberExpression" && !expression.computed && expression.object.type === "ThisExpression" && expression.property.type === "Identifier" && names.has(expression.property.name);
|
|
106
101
|
/** A door maps its input, dispatches exactly one message on the injected bus and returns the (mapped) result. */
|
|
107
102
|
export const transportIsThin = {
|
|
108
103
|
meta: {
|
|
@@ -119,126 +114,147 @@ export const transportIsThin = {
|
|
|
119
114
|
},
|
|
120
115
|
},
|
|
121
116
|
create(context) {
|
|
122
|
-
const hfs = hfsOf(context)
|
|
123
|
-
const slot = hfs.slotOf(context.filename)
|
|
117
|
+
const hfs = hfsOf(context);
|
|
118
|
+
const slot = hfs.slotOf(context.filename);
|
|
124
119
|
// a webhook or realtime door answers to its own kind laws (webhooks.mjs, realtime.mjs), not to the one-dispatch shape
|
|
125
|
-
if (!isTransportSlot(slot) || KIND_DOOR_SLOTS.includes(slot))
|
|
126
|
-
|
|
120
|
+
if (!isTransportSlot(slot) || slot === null || KIND_DOOR_SLOTS.includes(slot))
|
|
121
|
+
return {};
|
|
122
|
+
const sourceCode = context.sourceCode;
|
|
127
123
|
const isMapper = (callee) => {
|
|
128
|
-
if (callee.type !== "Identifier")
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
if (callee.type !== "Identifier")
|
|
125
|
+
return false;
|
|
126
|
+
const found = importOf(context, callee);
|
|
127
|
+
return found !== null && /(?:^|\/)[^/]+\.mapper(?:\.[cm]?[jt]s)?$/.test(found.source.replace(/\\/g, "/"));
|
|
128
|
+
};
|
|
132
129
|
/** `unwrapOutcome` of `platform/primitives`, resolved by the symbol the name binds to, not by its spelling. */
|
|
133
130
|
const isUnwrapOutcome = (callee) => {
|
|
134
|
-
if (callee.type !== "Identifier")
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
if (callee.type !== "Identifier")
|
|
132
|
+
return false;
|
|
133
|
+
const { checker, toTs } = typed(context);
|
|
134
|
+
const tsNode = toTs(callee);
|
|
135
|
+
let symbol = tsNode && checker.getSymbolAtLocation(tsNode);
|
|
136
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
137
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
138
|
+
return symbol?.getName() === "unwrapOutcome" && (symbol.getDeclarations() ?? []).some((declaration) => declaredByCapability(hfs, declaration.getSourceFile().fileName, "primitives"));
|
|
139
|
+
};
|
|
141
140
|
return {
|
|
142
141
|
ClassDeclaration(node) {
|
|
143
142
|
// A Nest module class (`@Module`) wires the door into the container (registers consumers and jobs); it is not a door.
|
|
144
|
-
if ((node.decorators ?? node.parent
|
|
145
|
-
|
|
143
|
+
if ((node.decorators ?? decoratorsOf(node.parent) ?? []).some((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Module")))
|
|
144
|
+
return;
|
|
145
|
+
const locales = new Set();
|
|
146
146
|
const classify = (name, annotation) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
if (name === null)
|
|
148
|
+
return;
|
|
149
|
+
if (injectedKind(context, annotation) === "locale")
|
|
150
|
+
locales.add(name);
|
|
151
|
+
};
|
|
152
|
+
const constructor = node.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "constructor");
|
|
151
153
|
for (const original of constructor?.value.params ?? []) {
|
|
152
|
-
const param = original.type === "TSParameterProperty" ? original.parameter : original
|
|
153
|
-
const annotation = param.typeAnnotation?.typeAnnotation
|
|
154
|
-
if (!annotation || !isAllowedInjection(context, hfs, slot, annotation))
|
|
155
|
-
|
|
154
|
+
const param = original.type === "TSParameterProperty" ? original.parameter : original;
|
|
155
|
+
const annotation = param.typeAnnotation?.typeAnnotation;
|
|
156
|
+
if (!annotation || !isAllowedInjection(context, hfs, slot, annotation))
|
|
157
|
+
context.report({ node: original, messageId: "injects", data: { what: sourceCode.getText(param) } });
|
|
158
|
+
else
|
|
159
|
+
classify(original.type === "TSParameterProperty" && param.type === "Identifier" ? param.name : null, annotation);
|
|
156
160
|
}
|
|
157
161
|
for (const member of node.body.body) {
|
|
158
|
-
if (member.type !== "PropertyDefinition" || !(member.decorators ?? []).some((decorator) => isInjectorDecorator(context, decorator)))
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
if (member.type !== "PropertyDefinition" || !(member.decorators ?? []).some((decorator) => isInjectorDecorator(context, decorator)))
|
|
163
|
+
continue;
|
|
164
|
+
const annotation = member.typeAnnotation?.typeAnnotation;
|
|
165
|
+
if (!annotation || !isAllowedInjection(context, hfs, slot, annotation))
|
|
166
|
+
context.report({ node: member, messageId: "injects", data: { what: sourceCode.getText(member) } });
|
|
167
|
+
else
|
|
168
|
+
classify(member.key.type === "Identifier" ? member.key.name : null, annotation);
|
|
162
169
|
}
|
|
163
|
-
const handlers = handlerMethods(context, node, slot)
|
|
164
|
-
if (handlers.length === 0)
|
|
170
|
+
const handlers = handlerMethods(context, node, slot);
|
|
171
|
+
if (handlers.length === 0)
|
|
172
|
+
return;
|
|
165
173
|
for (const method of node.body.body) {
|
|
166
|
-
if (method.type !== "MethodDefinition" || method.kind !== "method" || !method.value.body)
|
|
174
|
+
if (method.type !== "MethodDefinition" || method.kind !== "method" || !method.value.body)
|
|
175
|
+
continue;
|
|
167
176
|
walk(method.value.body, (child) => {
|
|
168
177
|
if (DECISION_NODES.has(child.type)) {
|
|
169
|
-
context.report({ node: child, messageId: "branch", data: { what: child.type === "LogicalExpression" ? child.operator : child.type.replace(/(Statement|Expression)$/, "").toLowerCase() } })
|
|
170
|
-
return
|
|
178
|
+
context.report({ node: child, messageId: "branch", data: { what: child.type === "LogicalExpression" ? child.operator : child.type.replace(/(Statement|Expression)$/, "").toLowerCase() } });
|
|
179
|
+
return;
|
|
171
180
|
}
|
|
172
|
-
if (child.type !== "CallExpression")
|
|
173
|
-
|
|
174
|
-
const
|
|
181
|
+
if (child.type !== "CallExpression")
|
|
182
|
+
return;
|
|
183
|
+
const callee = child.callee;
|
|
184
|
+
const member = callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee : null;
|
|
175
185
|
const allowed = (member !== null && member.property.name === "execute" && isBus(context, member.object))
|
|
176
186
|
|| (member !== null && isThisMember(member.object, locales))
|
|
177
187
|
|| isMapper(callee)
|
|
178
|
-
|| isUnwrapOutcome(callee)
|
|
179
|
-
if (!allowed)
|
|
180
|
-
|
|
188
|
+
|| isUnwrapOutcome(callee);
|
|
189
|
+
if (!allowed)
|
|
190
|
+
context.report({ node: child, messageId: "call", data: { what: sourceCode.getText(callee) } });
|
|
191
|
+
});
|
|
181
192
|
}
|
|
182
193
|
for (const method of handlers) {
|
|
183
|
-
const count = dispatchesOf(context, method)
|
|
184
|
-
const name = method.key.type === "Identifier" ? method.key.name : "this handler"
|
|
185
|
-
if (count === 0)
|
|
186
|
-
|
|
194
|
+
const count = dispatchesOf(context, method);
|
|
195
|
+
const name = method.key.type === "Identifier" ? method.key.name : "this handler";
|
|
196
|
+
if (count === 0)
|
|
197
|
+
context.report({ node: method.key, messageId: "none", data: { name } });
|
|
198
|
+
else if (count > 1)
|
|
199
|
+
context.report({ node: method.key, messageId: "many", data: { name, count: String(count) } });
|
|
187
200
|
else if ((method.decorators ?? []).some((decorator) => isRouteDecorator(context, decorator))) {
|
|
188
|
-
let returns = false
|
|
201
|
+
let returns = false;
|
|
189
202
|
walk(method.value.body, (child) => {
|
|
190
|
-
if (child.type === "ReturnStatement" && child.argument)
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
if (child.type === "ReturnStatement" && child.argument)
|
|
204
|
+
returns = true;
|
|
205
|
+
}, { intoFunctions: false });
|
|
206
|
+
if (!returns)
|
|
207
|
+
context.report({ node: method.key, messageId: "noReturn", data: { name } });
|
|
193
208
|
}
|
|
194
209
|
}
|
|
195
210
|
},
|
|
196
|
-
}
|
|
211
|
+
};
|
|
197
212
|
},
|
|
198
|
-
}
|
|
199
|
-
|
|
213
|
+
};
|
|
200
214
|
// -- no-response-envelope ----------------------------------------------------------------------------------------
|
|
201
|
-
|
|
202
215
|
/** The envelope classes and decorators BE-CONVENTION 1.6 names. */
|
|
203
|
-
const ENVELOPE_NAMES = new Set(["GraphQLTransformInterceptor", "GraphQLSuccessMessage", "AbstractGraphQLResponse", "RestTransformInterceptor"])
|
|
204
|
-
|
|
216
|
+
const ENVELOPE_NAMES = new Set(["GraphQLTransformInterceptor", "GraphQLSuccessMessage", "AbstractGraphQLResponse", "RestTransformInterceptor"]);
|
|
205
217
|
/** True when a class of this repository has an `intercept` that returns `map(...)` from rxjs over the handled response. */
|
|
206
218
|
const interceptorMapsResponse = (context, argument) => {
|
|
207
|
-
const { checker, toTs, program } = typed(context)
|
|
208
|
-
const callee = argument.type === "NewExpression" ? argument.callee : argument
|
|
209
|
-
if (callee.type !== "Identifier")
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
219
|
+
const { checker, toTs, program } = typed(context);
|
|
220
|
+
const callee = argument.type === "NewExpression" ? argument.callee : argument;
|
|
221
|
+
if (callee.type !== "Identifier")
|
|
222
|
+
return false;
|
|
223
|
+
let symbol = checker.getSymbolAtLocation(toTs(callee));
|
|
224
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
225
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
226
|
+
const declaration = (symbol?.getDeclarations() ?? []).find((candidate) => ts.isClassDeclaration(candidate) && !program.isSourceFileFromExternalLibrary(candidate.getSourceFile()) && !program.isSourceFileDefaultLibrary(candidate.getSourceFile()));
|
|
227
|
+
const intercept = declaration?.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "intercept");
|
|
228
|
+
if (!intercept)
|
|
229
|
+
return false;
|
|
230
|
+
let mapped = false;
|
|
216
231
|
const visit = (node) => {
|
|
217
|
-
if (mapped)
|
|
218
|
-
|
|
219
|
-
ts.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
232
|
+
if (mapped)
|
|
233
|
+
return;
|
|
234
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && importedFromRxjs(checker, node.expression))
|
|
235
|
+
mapped = true;
|
|
236
|
+
ts.forEachChild(node, visit);
|
|
237
|
+
};
|
|
238
|
+
visit(intercept);
|
|
239
|
+
return mapped;
|
|
240
|
+
};
|
|
225
241
|
/** True when an identifier is bound by an import of `rxjs` (or `rxjs/operators`) whose exported name is `map`. */
|
|
226
242
|
const importedFromRxjs = (checker, identifier) => {
|
|
227
|
-
const symbol = checker.getSymbolAtLocation(identifier)
|
|
228
|
-
const declaration = symbol?.getDeclarations()?.[0]
|
|
229
|
-
if (!declaration || !ts.isImportSpecifier(declaration))
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
const symbol = checker.getSymbolAtLocation(identifier);
|
|
244
|
+
const declaration = symbol?.getDeclarations()?.[0];
|
|
245
|
+
if (!declaration || !ts.isImportSpecifier(declaration))
|
|
246
|
+
return false;
|
|
247
|
+
const imported = (declaration.propertyName ?? declaration.name).text;
|
|
248
|
+
const module = ts.findAncestor(declaration, ts.isImportDeclaration)?.moduleSpecifier;
|
|
249
|
+
return imported === "map" && module !== undefined && ts.isStringLiteral(module) && (module.text === "rxjs" || module.text.startsWith("rxjs/"));
|
|
250
|
+
};
|
|
235
251
|
/** The expression a return statement hands back, without `await`, casts and parentheses. */
|
|
236
252
|
const returned = (expression) => {
|
|
237
|
-
let current = expression
|
|
238
|
-
while (current && (current.type === "AwaitExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression"))
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
253
|
+
let current = expression;
|
|
254
|
+
while (current && (current.type === "AwaitExpression" || current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression"))
|
|
255
|
+
current = current.type === "AwaitExpression" ? current.argument : current.expression;
|
|
256
|
+
return current;
|
|
257
|
+
};
|
|
242
258
|
/** No response envelope: a door returns its typed payload and failures travel as GraphQL errors. */
|
|
243
259
|
export const noResponseEnvelope = {
|
|
244
260
|
meta: {
|
|
@@ -252,52 +268,59 @@ export const noResponseEnvelope = {
|
|
|
252
268
|
},
|
|
253
269
|
},
|
|
254
270
|
create(context) {
|
|
255
|
-
const hfs = hfsOf(context)
|
|
256
|
-
const slot = hfs.slotOf(context.filename)
|
|
257
|
-
const transport = isTransportSlot(slot)
|
|
258
|
-
const declared = (
|
|
259
|
-
if (id?.type === "Identifier" && ENVELOPE_NAMES.has(id.name))
|
|
260
|
-
|
|
271
|
+
const hfs = hfsOf(context);
|
|
272
|
+
const slot = hfs.slotOf(context.filename);
|
|
273
|
+
const transport = isTransportSlot(slot);
|
|
274
|
+
const declared = (id) => {
|
|
275
|
+
if (id?.type === "Identifier" && ENVELOPE_NAMES.has(id.name))
|
|
276
|
+
context.report({ node: id, messageId: "named", data: { name: id.name } });
|
|
277
|
+
};
|
|
261
278
|
const visitors = {
|
|
262
|
-
ClassDeclaration: (node) => declared(node
|
|
263
|
-
FunctionDeclaration: (node) => declared(node
|
|
264
|
-
VariableDeclarator: (node) => declared(node
|
|
279
|
+
ClassDeclaration: (node) => declared(node.id),
|
|
280
|
+
FunctionDeclaration: (node) => declared(node.id),
|
|
281
|
+
VariableDeclarator: (node) => declared(node.id),
|
|
265
282
|
ImportSpecifier(node) {
|
|
266
|
-
const name = node.imported.type === "Identifier" ? node.imported.name : node.imported.value
|
|
267
|
-
if (ENVELOPE_NAMES.has(name))
|
|
283
|
+
const name = node.imported.type === "Identifier" ? node.imported.name : node.imported.value;
|
|
284
|
+
if (ENVELOPE_NAMES.has(name))
|
|
285
|
+
context.report({ node, messageId: "named", data: { name } });
|
|
268
286
|
},
|
|
269
|
-
}
|
|
270
|
-
if (!transport)
|
|
287
|
+
};
|
|
288
|
+
if (!transport)
|
|
289
|
+
return visitors;
|
|
271
290
|
return {
|
|
272
291
|
...visitors,
|
|
273
292
|
Decorator(node) {
|
|
274
|
-
if (!isImportedFrom(context, decoratorCallee(node), "@nestjs/common", "UseInterceptors"))
|
|
275
|
-
|
|
293
|
+
if (!isImportedFrom(context, decoratorCallee(node), "@nestjs/common", "UseInterceptors"))
|
|
294
|
+
return;
|
|
295
|
+
for (const argument of decoratorArguments(node))
|
|
296
|
+
if (interceptorMapsResponse(context, argument))
|
|
297
|
+
context.report({ node: argument, messageId: "interceptor" });
|
|
276
298
|
},
|
|
277
299
|
ReturnStatement(node) {
|
|
278
|
-
let owner = node.parent
|
|
279
|
-
while (owner && owner.type !== "FunctionExpression" && owner.type !== "ArrowFunctionExpression" && owner.type !== "FunctionDeclaration")
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
if (
|
|
300
|
+
let owner = node.parent;
|
|
301
|
+
while (owner && owner.type !== "FunctionExpression" && owner.type !== "ArrowFunctionExpression" && owner.type !== "FunctionDeclaration")
|
|
302
|
+
owner = owner.parent;
|
|
303
|
+
if (owner?.parent?.type !== "MethodDefinition")
|
|
304
|
+
return;
|
|
305
|
+
const value = returned(node.argument);
|
|
306
|
+
if (value?.type !== "ObjectExpression")
|
|
307
|
+
return;
|
|
308
|
+
const keys = new Set(value.properties.map((property) => (property.type === "Property" && !property.computed && property.key.type === "Identifier" ? property.key.name : property.type === "Property" && property.key.type === "Literal" ? String(property.key.value) : null)));
|
|
309
|
+
if (keys.has("success") && keys.has("data"))
|
|
310
|
+
context.report({ node: value, messageId: "literal" });
|
|
285
311
|
},
|
|
286
|
-
}
|
|
312
|
+
};
|
|
287
313
|
},
|
|
288
|
-
}
|
|
289
|
-
|
|
314
|
+
};
|
|
290
315
|
// -- no-graphql-json ---------------------------------------------------------------------------------------------
|
|
291
|
-
|
|
292
316
|
/** The names of the JSON scalar exports of `graphql-scalars`. */
|
|
293
|
-
const JSON_SCALARS = new Set(["GraphQLJSON", "GraphQLJSONObject", "JSON", "JSONObject", "JSONResolver", "JSONObjectResolver"])
|
|
294
|
-
|
|
317
|
+
const JSON_SCALARS = new Set(["GraphQLJSON", "GraphQLJSONObject", "JSON", "JSONObject", "JSONResolver", "JSONObjectResolver"]);
|
|
295
318
|
/** True when the type is `unknown` or an object with a string index signature of `unknown`. */
|
|
296
319
|
const isUnknownBag = (checker, type) => {
|
|
297
|
-
if ((type.flags & ts.TypeFlags.Unknown) !== 0)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
320
|
+
if ((type.flags & ts.TypeFlags.Unknown) !== 0)
|
|
321
|
+
return true;
|
|
322
|
+
return checker.getIndexInfosOfType(type).some((info) => (info.type.flags & ts.TypeFlags.Unknown) !== 0);
|
|
323
|
+
};
|
|
301
324
|
/** No free-form JSON in a door: no `GraphQLJSON`, no untyped `@Body()`, no `switch (input.operation)`. */
|
|
302
325
|
export const noGraphqlJson = {
|
|
303
326
|
meta: {
|
|
@@ -311,47 +334,62 @@ export const noGraphqlJson = {
|
|
|
311
334
|
},
|
|
312
335
|
},
|
|
313
336
|
create(context) {
|
|
314
|
-
const hfs = hfsOf(context)
|
|
315
|
-
if (!isTransportSlot(hfs.slotOf(context.filename)))
|
|
316
|
-
|
|
337
|
+
const hfs = hfsOf(context);
|
|
338
|
+
if (!isTransportSlot(hfs.slotOf(context.filename)))
|
|
339
|
+
return {};
|
|
340
|
+
const { checker, toTs } = typed(context);
|
|
317
341
|
const scalar = (node, local, importedName, source) => {
|
|
318
|
-
if (source === "graphql-type-json")
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
|
|
342
|
+
if (source === "graphql-type-json")
|
|
343
|
+
return context.report({ node, messageId: "scalar", data: { name: importedName } });
|
|
344
|
+
if (source === "graphql-scalars" && JSON_SCALARS.has(importedName))
|
|
345
|
+
return context.report({ node, messageId: "scalar", data: { name: importedName } });
|
|
346
|
+
let symbol = checker.getSymbolAtLocation(toTs(local));
|
|
347
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
348
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
349
|
+
const resolved = symbol;
|
|
350
|
+
const origin = (resolved?.getDeclarations() ?? []).some((declaration) => /\/node_modules\/(?:graphql-type-json|graphql-scalars)\//.test(declaration.getSourceFile().fileName.replace(/\\/g, "/")) && resolved !== undefined && (JSON_SCALARS.has(resolved.getName()) || resolved.getName() === "default"));
|
|
351
|
+
if (origin)
|
|
352
|
+
context.report({ node, messageId: "scalar", data: { name: importedName } });
|
|
353
|
+
};
|
|
325
354
|
return {
|
|
326
355
|
ImportSpecifier(node) {
|
|
327
|
-
|
|
356
|
+
// An import specifier always sits in an import declaration, whose source is never null.
|
|
357
|
+
const { source } = node.parent;
|
|
358
|
+
if (source === null)
|
|
359
|
+
return;
|
|
360
|
+
scalar(node, node.local, node.imported.type === "Identifier" ? node.imported.name : node.imported.value, source.value);
|
|
328
361
|
},
|
|
329
362
|
ImportDefaultSpecifier(node) {
|
|
330
|
-
scalar(node, node.local, node.local.name, node.parent.source.value)
|
|
363
|
+
scalar(node, node.local, node.local.name, node.parent.source.value);
|
|
331
364
|
},
|
|
332
365
|
MethodDefinition(node) {
|
|
333
366
|
for (const param of node.value.params) {
|
|
334
|
-
const target = param.type === "AssignmentPattern" ? param.left : param
|
|
335
|
-
if (!(target.decorators ?? []).some((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Body")))
|
|
336
|
-
|
|
337
|
-
|
|
367
|
+
const target = param.type === "AssignmentPattern" ? param.left : param;
|
|
368
|
+
if (!(target.decorators ?? []).some((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Body")))
|
|
369
|
+
continue;
|
|
370
|
+
const annotation = "typeAnnotation" in target ? target.typeAnnotation?.typeAnnotation : undefined;
|
|
371
|
+
if (!annotation)
|
|
372
|
+
continue;
|
|
373
|
+
const tsAnnotation = toTs(annotation);
|
|
374
|
+
// An annotation maps to a TS type node; the declared map also admits an identifier, read as typeOrigins reads one.
|
|
375
|
+
if (isUnknownBag(checker, ts.isTypeNode(tsAnnotation) ? checker.getTypeFromTypeNode(tsAnnotation) : checker.getTypeAtLocation(tsAnnotation)))
|
|
376
|
+
context.report({ node: target, messageId: "body" });
|
|
338
377
|
}
|
|
339
378
|
},
|
|
340
379
|
SwitchStatement(node) {
|
|
341
|
-
const discriminant = node.discriminant
|
|
342
|
-
if (discriminant.type !== "MemberExpression")
|
|
343
|
-
|
|
344
|
-
|
|
380
|
+
const discriminant = node.discriminant;
|
|
381
|
+
if (discriminant.type !== "MemberExpression")
|
|
382
|
+
return;
|
|
383
|
+
const key = discriminant.computed ? (discriminant.property.type === "Literal" ? String(discriminant.property.value) : null) : discriminant.property.name;
|
|
384
|
+
if (key === "operation")
|
|
385
|
+
context.report({ node: discriminant, messageId: "operation" });
|
|
345
386
|
},
|
|
346
|
-
}
|
|
387
|
+
};
|
|
347
388
|
},
|
|
348
|
-
}
|
|
349
|
-
|
|
389
|
+
};
|
|
350
390
|
// -- door-lives-in-features --------------------------------------------------------------------------------------
|
|
351
|
-
|
|
352
391
|
/** True for a `@Controller` decorator of `@nestjs/common`. */
|
|
353
|
-
const isController = (context, decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Controller")
|
|
354
|
-
|
|
392
|
+
const isController = (context, decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Controller");
|
|
355
393
|
/** A door is a door whatever its protocol, and every REST door lives in the `transport/http` slot of a feature or in the door slot of the webhook kind. */
|
|
356
394
|
export const doorLivesInFeatures = {
|
|
357
395
|
meta: {
|
|
@@ -363,18 +401,18 @@ export const doorLivesInFeatures = {
|
|
|
363
401
|
},
|
|
364
402
|
},
|
|
365
403
|
create(context) {
|
|
366
|
-
const slot = hfsOf(context).slotOf(context.filename)
|
|
367
|
-
if (slot === HTTP_SLOT || slot === WEBHOOK_SLOT || slot === SSE_SLOT)
|
|
404
|
+
const slot = hfsOf(context).slotOf(context.filename);
|
|
405
|
+
if (slot === HTTP_SLOT || slot === WEBHOOK_SLOT || slot === SSE_SLOT)
|
|
406
|
+
return {};
|
|
368
407
|
return {
|
|
369
408
|
Decorator(node) {
|
|
370
|
-
if (isController(context, node))
|
|
409
|
+
if (isController(context, node))
|
|
410
|
+
context.report({ node, messageId: "wrongSlot", data: { slot: slot ?? "none" } });
|
|
371
411
|
},
|
|
372
|
-
}
|
|
412
|
+
};
|
|
373
413
|
},
|
|
374
|
-
}
|
|
375
|
-
|
|
414
|
+
};
|
|
376
415
|
// -- no-capability-imports-features ------------------------------------------------------------------------------
|
|
377
|
-
|
|
378
416
|
/** A capability under `modules/` never imports a feature: a door calls into a capability, never the other way round. */
|
|
379
417
|
export const noCapabilityImportsFeatures = {
|
|
380
418
|
meta: {
|
|
@@ -386,19 +424,19 @@ export const noCapabilityImportsFeatures = {
|
|
|
386
424
|
},
|
|
387
425
|
},
|
|
388
426
|
create(context) {
|
|
389
|
-
const hfs = hfsOf(context)
|
|
390
|
-
const tier = hfs.tierOf(context.filename)
|
|
391
|
-
if (tier !== "domain" && tier !== "platform" && tier !== "integrations")
|
|
392
|
-
|
|
427
|
+
const hfs = hfsOf(context);
|
|
428
|
+
const tier = hfs.tierOf(context.filename);
|
|
429
|
+
if (tier !== "domain" && tier !== "platform" && tier !== "integrations")
|
|
430
|
+
return {};
|
|
431
|
+
const { program } = typed(context);
|
|
393
432
|
return moduleReferences(({ source, value }) => {
|
|
394
|
-
const resolved = ts.resolveModuleName(value, context.filename, program.getCompilerOptions(), ts.sys).resolvedModule?.resolvedFileName
|
|
395
|
-
if (resolved && hfs.tierOf(resolved) === "feature")
|
|
396
|
-
|
|
433
|
+
const resolved = ts.resolveModuleName(value, context.filename, program.getCompilerOptions(), ts.sys).resolvedModule?.resolvedFileName;
|
|
434
|
+
if (resolved && hfs.tierOf(resolved) === "feature")
|
|
435
|
+
context.report({ node: source, messageId: "reversed", data: { specifier: value, tier } });
|
|
436
|
+
});
|
|
397
437
|
},
|
|
398
|
-
}
|
|
399
|
-
|
|
438
|
+
};
|
|
400
439
|
// -- rest-door-needs-a-reason ------------------------------------------------------------------------------------
|
|
401
|
-
|
|
402
440
|
/** A REST door exists only where GraphQL cannot go, and each route has to show which case it is. */
|
|
403
441
|
export const restDoorNeedsAReason = {
|
|
404
442
|
meta: {
|
|
@@ -410,22 +448,24 @@ export const restDoorNeedsAReason = {
|
|
|
410
448
|
},
|
|
411
449
|
},
|
|
412
450
|
create(context) {
|
|
413
|
-
hfsOf(context)
|
|
414
|
-
const declared = operationRouteEvidence(context)
|
|
451
|
+
hfsOf(context);
|
|
452
|
+
const declared = operationRouteEvidence(context);
|
|
415
453
|
return {
|
|
416
454
|
ClassDeclaration(node) {
|
|
417
|
-
const controller = (node.decorators ?? []).find((decorator) => isController(context, decorator))
|
|
418
|
-
if (!controller)
|
|
455
|
+
const controller = (node.decorators ?? []).find((decorator) => isController(context, decorator));
|
|
456
|
+
if (!controller)
|
|
457
|
+
return;
|
|
419
458
|
for (const method of node.body.body) {
|
|
420
|
-
if (method.type !== "MethodDefinition" || method.kind !== "method" || method.static)
|
|
421
|
-
|
|
422
|
-
|
|
459
|
+
if (method.type !== "MethodDefinition" || method.kind !== "method" || method.static)
|
|
460
|
+
continue;
|
|
461
|
+
const route = (method.decorators ?? []).find((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", HTTP_ROUTES));
|
|
462
|
+
if (route && !restExceptionEvidence(context, method) && !declared(method))
|
|
463
|
+
context.report({ node: route, messageId: "unjustified" });
|
|
423
464
|
}
|
|
424
465
|
},
|
|
425
|
-
}
|
|
466
|
+
};
|
|
426
467
|
},
|
|
427
|
-
}
|
|
428
|
-
|
|
468
|
+
};
|
|
429
469
|
/** The rules this law contributes to the plugin. */
|
|
430
470
|
export const rules = {
|
|
431
471
|
"rest-door-needs-a-reason": restDoorNeedsAReason,
|
|
@@ -434,8 +474,7 @@ export const rules = {
|
|
|
434
474
|
"transport-is-thin": transportIsThin,
|
|
435
475
|
"no-response-envelope": noResponseEnvelope,
|
|
436
476
|
"no-graphql-json": noGraphqlJson,
|
|
437
|
-
}
|
|
438
|
-
|
|
477
|
+
};
|
|
439
478
|
/** Every rule of this law at `error`. */
|
|
440
479
|
export const recommended = {
|
|
441
480
|
"starci-be/rest-door-needs-a-reason": "error",
|
|
@@ -444,4 +483,4 @@ export const recommended = {
|
|
|
444
483
|
"starci-be/transport-is-thin": "error",
|
|
445
484
|
"starci-be/no-response-envelope": "error",
|
|
446
485
|
"starci-be/no-graphql-json": "error",
|
|
447
|
-
}
|
|
486
|
+
};
|