@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** `eventBus.publish(event, tx)` and a queue producer's `enqueueX(payload, tx)` are called only from `modules/domain`, inside its transaction. */
|
|
3
|
+
export declare const outboxWriteTx: RuleModule;
|
|
4
|
+
/** A message consumer is the one door of an event: placed in `transport/message`, named after its event, and it forwards the event id. */
|
|
5
|
+
export declare const eventConsumerShape: RuleModule;
|
|
6
|
+
/** A producer of a queue passes its own transaction parameter to the outbox, and nothing else writes the outbox there. */
|
|
7
|
+
export declare const queueProducerShape: RuleModule;
|
|
8
|
+
export declare const rules: {
|
|
9
|
+
"outbox-write-tx": RuleModule;
|
|
10
|
+
"event-consumer-shape": RuleModule;
|
|
11
|
+
"queue-producer-shape": RuleModule;
|
|
12
|
+
};
|
|
13
|
+
/** The level these laws ask for: `error`, switched off nowhere. */
|
|
14
|
+
export declare const recommended: Recommended;
|
|
@@ -11,77 +11,80 @@
|
|
|
11
11
|
* `platform/queue`, typeorm's `EntityManager`) and by the slot view (tiers, `be.transport.message`, `be.queues`); none matches a
|
|
12
12
|
* variable, class or method name written in the source, except the contract's own members `publish`, `eventName` and `eventId`.
|
|
13
13
|
*/
|
|
14
|
-
import ts from "typescript"
|
|
15
|
-
import { walk } from "./lib/ast.
|
|
16
|
-
import { hfsOf, inTestWorld } from "./lib/hfs.
|
|
17
|
-
import { infraTypeOf } from "./lib/persistence.
|
|
18
|
-
import { baseName, isOwnedType, ownerNameOf } from "./lib/ports.
|
|
19
|
-
import { resolveVariable, transactionCallback } from "./lib/transactions.
|
|
20
|
-
import {
|
|
21
|
-
|
|
14
|
+
import ts from "typescript";
|
|
15
|
+
import { walk } from "./lib/ast.js";
|
|
16
|
+
import { hfsOf, inTestWorld } from "./lib/hfs.js";
|
|
17
|
+
import { infraTypeOf } from "./lib/persistence.js";
|
|
18
|
+
import { baseName, isOwnedType, ownerNameOf } from "./lib/ports.js";
|
|
19
|
+
import { resolveVariable, transactionCallback } from "./lib/transactions.js";
|
|
20
|
+
import { typed } from "./lib/types.js";
|
|
22
21
|
/** The `EventBus` port of `platform/event-bus`. */
|
|
23
|
-
const isEventBusType = (context, node) => isOwnedType(context, node, { name: "EventBus", capability: "event-bus", tier: "platform" })
|
|
24
|
-
|
|
22
|
+
const isEventBusType = (context, node) => isOwnedType(context, node, { name: "EventBus", capability: "event-bus", tier: "platform" });
|
|
25
23
|
/** The `EventConsumer` port of `platform/event-bus`. */
|
|
26
|
-
const isEventConsumerType = (context, node) => isOwnedType(context, node, { name: "EventConsumer", capability: "event-bus", tier: "platform" })
|
|
27
|
-
|
|
24
|
+
const isEventConsumerType = (context, node) => isOwnedType(context, node, { name: "EventConsumer", capability: "event-bus", tier: "platform" });
|
|
28
25
|
/** The `EventDelivery` type of `platform/event-bus`. */
|
|
29
|
-
const isEventDeliveryType = (context, node) => isOwnedType(context, node, { name: "EventDelivery", capability: "event-bus", tier: "platform" })
|
|
30
|
-
|
|
26
|
+
const isEventDeliveryType = (context, node) => isOwnedType(context, node, { name: "EventDelivery", capability: "event-bus", tier: "platform" });
|
|
31
27
|
/** The `QueueOutbox` port of `platform/queue`. */
|
|
32
|
-
const isQueueOutboxType = (context, node) => isOwnedType(context, node, { name: "QueueOutbox", capability: "queue", tier: "platform" })
|
|
33
|
-
|
|
28
|
+
const isQueueOutboxType = (context, node) => isOwnedType(context, node, { name: "QueueOutbox", capability: "queue", tier: "platform" });
|
|
29
|
+
/** The platform owners of the outbox: the rules leave their own files alone. */
|
|
30
|
+
const OUTBOX_OWNERS = ["event-bus", "queue"];
|
|
34
31
|
/** True for a file the rules leave alone: the owners themselves, and the test composition (the world, e2e and fixtures). */
|
|
35
32
|
const isExempt = (hfs, file) => {
|
|
36
|
-
const tier = hfs.tierOf(file)
|
|
37
|
-
if (tier === "e2e" || tier === "fixtures" || inTestWorld(hfs, file))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const tier = hfs.tierOf(file);
|
|
34
|
+
if (tier === "e2e" || tier === "fixtures" || inTestWorld(hfs, file))
|
|
35
|
+
return true;
|
|
36
|
+
return tier === "platform" && OUTBOX_OWNERS.includes(ownerNameOf(hfs, file));
|
|
37
|
+
};
|
|
41
38
|
/** The index of the parameter of a signature declaration typed as typeorm's `EntityManager`, or -1. */
|
|
42
39
|
const transactionParameterIndex = (checker, declaration) => {
|
|
43
|
-
const parameters = declaration?.parameters ?? []
|
|
40
|
+
const parameters = declaration?.parameters ?? [];
|
|
44
41
|
return parameters.findIndex((parameter) => {
|
|
45
|
-
const type = checker.getTypeAtLocation(parameter)
|
|
46
|
-
const symbol = type.getSymbol?.()
|
|
47
|
-
return symbol?.getName() === "EntityManager" && String(symbol.declarations?.[0]?.getSourceFile().fileName ?? "").replace(/\\/g, "/").includes("/node_modules/typeorm/")
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
42
|
+
const type = checker.getTypeAtLocation(parameter);
|
|
43
|
+
const symbol = type.getSymbol?.();
|
|
44
|
+
return symbol?.getName() === "EntityManager" && String(symbol.declarations?.[0]?.getSourceFile().fileName ?? "").replace(/\\/g, "/").includes("/node_modules/typeorm/");
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
/** The `kind` a node carries (a method's `constructor`), or undefined when it carries none (what reading `.kind` off it gave). */
|
|
48
|
+
const kindOf = (node) => (node && "kind" in node ? node.kind : undefined);
|
|
51
49
|
/**
|
|
52
50
|
* What an expression passed as the transaction is: the transactional manager a `.transaction(async (manager) => ...)` callback
|
|
53
51
|
* receives, or a function parameter typed as the `EntityManager` (a helper that runs inside the caller's transaction).
|
|
54
52
|
* The injected shared manager (`this.entityManager`), a local alias and any other expression are not proof of a transaction.
|
|
55
53
|
*/
|
|
56
54
|
const isTransactionManager = (context, argument) => {
|
|
57
|
-
if (argument?.type !== "Identifier")
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
if (argument?.type !== "Identifier")
|
|
56
|
+
return false;
|
|
57
|
+
const variable = resolveVariable(context.sourceCode, argument);
|
|
58
|
+
const definition = variable?.defs[0];
|
|
59
|
+
if (definition?.type !== "Parameter")
|
|
60
|
+
return false;
|
|
61
|
+
const owner = definition.node;
|
|
62
|
+
const call = owner.parent;
|
|
63
|
+
if (call?.type === "CallExpression" && transactionCallback(context, call) === owner)
|
|
64
|
+
return true;
|
|
65
|
+
if (owner.parent?.type === "FunctionExpression" && kindOf(owner.parent.parent) === "constructor")
|
|
66
|
+
return false;
|
|
67
|
+
if (kindOf(owner.parent) === "constructor")
|
|
68
|
+
return false;
|
|
69
|
+
return infraTypeOf(context, definition.name) === "EntityManager";
|
|
70
|
+
};
|
|
69
71
|
/** The outbox-writing call a node is: `{ kind: "publish", argument }` or `{ kind: "producer", argument }`, or null. */
|
|
70
72
|
const outboxWriteOf = (context, hfs, node) => {
|
|
71
|
-
const callee = node.callee
|
|
73
|
+
const callee = node.callee;
|
|
72
74
|
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "publish" && isEventBusType(context, callee.object)) {
|
|
73
|
-
return { kind: "publish", argument: node.arguments[1], expected: 1 }
|
|
75
|
+
return { kind: "publish", argument: node.arguments[1], expected: 1 };
|
|
74
76
|
}
|
|
75
|
-
const { checker, toTs } = typed(context)
|
|
76
|
-
const tsNode = toTs(node)
|
|
77
|
-
const declaration = tsNode ? checker.getResolvedSignature(tsNode)?.declaration : undefined
|
|
78
|
-
if (!declaration)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
const { checker, toTs } = typed(context);
|
|
78
|
+
const tsNode = toTs(node);
|
|
79
|
+
const declaration = tsNode ? checker.getResolvedSignature(tsNode)?.declaration : undefined;
|
|
80
|
+
if (!declaration)
|
|
81
|
+
return null;
|
|
82
|
+
const file = declaration.getSourceFile().fileName;
|
|
83
|
+
if (hfs.tierOf(file) !== "queues")
|
|
84
|
+
return null;
|
|
85
|
+
const index = transactionParameterIndex(checker, declaration);
|
|
86
|
+
return index < 0 ? null : { kind: "producer", argument: node.arguments[index], expected: index };
|
|
87
|
+
};
|
|
85
88
|
/** `eventBus.publish(event, tx)` and a queue producer's `enqueueX(payload, tx)` are called only from `modules/domain`, inside its transaction. */
|
|
86
89
|
export const outboxWriteTx = {
|
|
87
90
|
meta: {
|
|
@@ -94,39 +97,40 @@ export const outboxWriteTx = {
|
|
|
94
97
|
},
|
|
95
98
|
},
|
|
96
99
|
create(context) {
|
|
97
|
-
const hfs = hfsOf(context)
|
|
98
|
-
if (isExempt(hfs, context.filename))
|
|
99
|
-
|
|
100
|
+
const hfs = hfsOf(context);
|
|
101
|
+
if (isExempt(hfs, context.filename))
|
|
102
|
+
return {};
|
|
103
|
+
const inDomain = hfs.tierOf(context.filename) === "domain";
|
|
100
104
|
return {
|
|
101
105
|
CallExpression(node) {
|
|
102
|
-
const write = outboxWriteOf(context, hfs, node)
|
|
103
|
-
if (!write)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const write = outboxWriteOf(context, hfs, node);
|
|
107
|
+
if (!write)
|
|
108
|
+
return;
|
|
109
|
+
const call = context.sourceCode.getText(node.callee);
|
|
110
|
+
if (!inDomain)
|
|
111
|
+
context.report({ node, messageId: "foreignTier", data: { call } });
|
|
112
|
+
else if (!isTransactionManager(context, write.argument))
|
|
113
|
+
context.report({ node, messageId: "noTransaction", data: { call } });
|
|
107
114
|
},
|
|
108
|
-
}
|
|
115
|
+
};
|
|
109
116
|
},
|
|
110
|
-
}
|
|
111
|
-
|
|
117
|
+
};
|
|
112
118
|
/** The `eventName` literal of the event class an expression names (`typeof OrderPlacedEvent` has a static `eventName`), or null. */
|
|
113
119
|
const eventNameOf = (context, expression) => {
|
|
114
|
-
const { checker, toTs } = typed(context)
|
|
115
|
-
const tsNode = toTs(expression)
|
|
116
|
-
if (!tsNode)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
const { checker, toTs } = typed(context);
|
|
121
|
+
const tsNode = toTs(expression);
|
|
122
|
+
if (!tsNode)
|
|
123
|
+
return null;
|
|
124
|
+
const property = checker.getTypeAtLocation(tsNode).getProperty("eventName");
|
|
125
|
+
if (!property)
|
|
126
|
+
return null;
|
|
127
|
+
const type = checker.getTypeOfSymbolAtLocation(property, tsNode);
|
|
128
|
+
return type.isStringLiteral() ? type.value : null;
|
|
129
|
+
};
|
|
123
130
|
/** True when the node is a `.eventId` member read on a value typed as the `EventDelivery` of `platform/event-bus`. */
|
|
124
|
-
const readsDeliveryEventId = (context, node) =>
|
|
125
|
-
node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.property.name === "eventId" && isEventDeliveryType(context, node.object)
|
|
126
|
-
|
|
131
|
+
const readsDeliveryEventId = (context, node) => node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.property.name === "eventId" && isEventDeliveryType(context, node.object);
|
|
127
132
|
/** The kebab stem of an event name: dots become dashes. */
|
|
128
|
-
const stemOfEvent = (name) => name.split(".").join("-")
|
|
129
|
-
|
|
133
|
+
const stemOfEvent = (name) => name.split(".").join("-");
|
|
130
134
|
/** A message consumer is the one door of an event: placed in `transport/message`, named after its event, and it forwards the event id. */
|
|
131
135
|
export const eventConsumerShape = {
|
|
132
136
|
meta: {
|
|
@@ -142,56 +146,68 @@ export const eventConsumerShape = {
|
|
|
142
146
|
},
|
|
143
147
|
},
|
|
144
148
|
create(context) {
|
|
145
|
-
const hfs = hfsOf(context)
|
|
146
|
-
const file = context.filename
|
|
147
|
-
if (isExempt(hfs, file))
|
|
148
|
-
|
|
149
|
-
const
|
|
149
|
+
const hfs = hfsOf(context);
|
|
150
|
+
const file = context.filename;
|
|
151
|
+
if (isExempt(hfs, file))
|
|
152
|
+
return {};
|
|
153
|
+
const inTransport = hfs.slotOf(file) === "be.transport.message";
|
|
154
|
+
const isConsumerFile = baseName(file).endsWith(".consumer.ts");
|
|
150
155
|
const check = (node) => {
|
|
151
|
-
const name = node.id?.name ?? "this class"
|
|
152
|
-
const implementsConsumer = (node.implements ?? []).some((entry) => isEventConsumerType(context, entry))
|
|
156
|
+
const name = node.id?.name ?? "this class";
|
|
157
|
+
const implementsConsumer = (node.implements ?? []).some((entry) => isEventConsumerType(context, entry));
|
|
153
158
|
if (!implementsConsumer) {
|
|
154
|
-
if (inTransport && isConsumerFile)
|
|
155
|
-
|
|
159
|
+
if (inTransport && isConsumerFile)
|
|
160
|
+
context.report({ node: node.id ?? node, messageId: "notConsumer", data: { name } });
|
|
161
|
+
return;
|
|
156
162
|
}
|
|
157
163
|
if (!inTransport || !isConsumerFile) {
|
|
158
|
-
context.report({ node: node.id ?? node, messageId: "placement", data: { name } })
|
|
159
|
-
return
|
|
164
|
+
context.report({ node: node.id ?? node, messageId: "placement", data: { name } });
|
|
165
|
+
return;
|
|
160
166
|
}
|
|
161
|
-
const eventProperty = node.body.body.find((member) => member.type === "PropertyDefinition" && !member.computed && member.key.type === "Identifier" && member.key.name === "event")
|
|
162
|
-
const event = eventProperty?.value ? eventNameOf(context, eventProperty.value) : null
|
|
163
|
-
if (event === null)
|
|
167
|
+
const eventProperty = node.body.body.find((member) => member.type === "PropertyDefinition" && !member.computed && member.key.type === "Identifier" && member.key.name === "event");
|
|
168
|
+
const event = eventProperty?.value ? eventNameOf(context, eventProperty.value) : null;
|
|
169
|
+
if (event === null)
|
|
170
|
+
context.report({ node: eventProperty ?? node.id ?? node, messageId: "eventUnknown", data: { name } });
|
|
164
171
|
else {
|
|
165
|
-
const actual = baseName(file).slice(0, -".consumer.ts".length)
|
|
166
|
-
if (stemOfEvent(event) !== actual)
|
|
172
|
+
const actual = baseName(file).slice(0, -".consumer.ts".length);
|
|
173
|
+
if (stemOfEvent(event) !== actual)
|
|
174
|
+
context.report({ node: node.id ?? node, messageId: "stem", data: { event, expected: stemOfEvent(event), actual } });
|
|
167
175
|
}
|
|
168
|
-
const handle = node.body.body.find((member) => member.type === "MethodDefinition" && !member.computed && member.key.type === "Identifier" && member.key.name === "handle")
|
|
169
|
-
const body = handle?.value?.body
|
|
170
|
-
let forwarded = false
|
|
171
|
-
if (body)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
const handle = node.body.body.find((member) => member.type === "MethodDefinition" && !member.computed && member.key.type === "Identifier" && member.key.name === "handle");
|
|
177
|
+
const body = handle?.value?.body;
|
|
178
|
+
let forwarded = false;
|
|
179
|
+
if (body)
|
|
180
|
+
walk(body, (child) => { if (readsDeliveryEventId(context, child))
|
|
181
|
+
forwarded = true; });
|
|
182
|
+
if (!forwarded)
|
|
183
|
+
context.report({ node: handle ?? node.id ?? node, messageId: "noEventId", data: { name } });
|
|
184
|
+
};
|
|
185
|
+
return { ClassDeclaration: check, ClassExpression: check };
|
|
175
186
|
},
|
|
176
|
-
}
|
|
177
|
-
|
|
187
|
+
};
|
|
178
188
|
/** The functions of an exported class or the exported functions of a `.queue.ts`: the producers. */
|
|
179
189
|
const producersOf = (program) => {
|
|
180
|
-
const found = []
|
|
190
|
+
const found = [];
|
|
181
191
|
for (const statement of program.body) {
|
|
182
|
-
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : null
|
|
183
|
-
if (!declaration)
|
|
192
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : null;
|
|
193
|
+
if (!declaration)
|
|
194
|
+
continue;
|
|
184
195
|
if (declaration.type === "FunctionDeclaration") {
|
|
185
|
-
found.push(declaration)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
196
|
+
found.push(declaration);
|
|
197
|
+
}
|
|
198
|
+
else if (declaration.type === "ClassDeclaration") {
|
|
199
|
+
for (const member of declaration.body.body)
|
|
200
|
+
if (member.type === "MethodDefinition" && member.kind === "method" && member.value)
|
|
201
|
+
found.push(member.value);
|
|
202
|
+
}
|
|
203
|
+
else if (declaration.type === "VariableDeclaration") {
|
|
204
|
+
for (const item of declaration.declarations)
|
|
205
|
+
if (item.init && (item.init.type === "ArrowFunctionExpression" || item.init.type === "FunctionExpression"))
|
|
206
|
+
found.push(item.init);
|
|
190
207
|
}
|
|
191
208
|
}
|
|
192
|
-
return found
|
|
193
|
-
}
|
|
194
|
-
|
|
209
|
+
return found;
|
|
210
|
+
};
|
|
195
211
|
/** A producer of a queue passes its own transaction parameter to the outbox, and nothing else writes the outbox there. */
|
|
196
212
|
export const queueProducerShape = {
|
|
197
213
|
meta: {
|
|
@@ -203,35 +219,36 @@ export const queueProducerShape = {
|
|
|
203
219
|
},
|
|
204
220
|
},
|
|
205
221
|
create(context) {
|
|
206
|
-
const hfs = hfsOf(context)
|
|
207
|
-
const file = context.filename
|
|
208
|
-
if (hfs.slotOf(file) !== "be.queues" || !baseName(file).endsWith(".queue.ts"))
|
|
222
|
+
const hfs = hfsOf(context);
|
|
223
|
+
const file = context.filename;
|
|
224
|
+
if (hfs.slotOf(file) !== "be.queues" || !baseName(file).endsWith(".queue.ts"))
|
|
225
|
+
return {};
|
|
209
226
|
return {
|
|
210
227
|
"Program:exit"(program) {
|
|
211
228
|
for (const producer of producersOf(program)) {
|
|
212
|
-
const parameters = producer.params.filter((param) => param.type === "Identifier")
|
|
213
|
-
const tx = parameters.find((param) => infraTypeOf(context, param) === "EntityManager")
|
|
229
|
+
const parameters = producer.params.filter((param) => param.type === "Identifier");
|
|
230
|
+
const tx = parameters.find((param) => infraTypeOf(context, param) === "EntityManager");
|
|
214
231
|
walk(producer.body, (node) => {
|
|
215
|
-
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || !isQueueOutboxType(context, node.callee.object))
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
232
|
+
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || !isQueueOutboxType(context, node.callee.object))
|
|
233
|
+
return;
|
|
234
|
+
const first = node.arguments[0];
|
|
235
|
+
const passes = tx !== undefined && first?.type === "Identifier" && first.name === tx.name && resolveVariable(context.sourceCode, first)?.defs[0]?.name === tx;
|
|
236
|
+
if (!passes)
|
|
237
|
+
context.report({ node, messageId: "noTransaction" });
|
|
238
|
+
});
|
|
220
239
|
}
|
|
221
240
|
},
|
|
222
|
-
}
|
|
241
|
+
};
|
|
223
242
|
},
|
|
224
|
-
}
|
|
225
|
-
|
|
243
|
+
};
|
|
226
244
|
export const rules = {
|
|
227
245
|
"outbox-write-tx": outboxWriteTx,
|
|
228
246
|
"event-consumer-shape": eventConsumerShape,
|
|
229
247
|
"queue-producer-shape": queueProducerShape,
|
|
230
|
-
}
|
|
231
|
-
|
|
248
|
+
};
|
|
232
249
|
/** The level these laws ask for: `error`, switched off nowhere. */
|
|
233
250
|
export const recommended = {
|
|
234
251
|
"starci-be/outbox-write-tx": "error",
|
|
235
252
|
"starci-be/event-consumer-shape": "error",
|
|
236
253
|
"starci-be/queue-producer-shape": "error",
|
|
237
|
-
}
|
|
254
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** The name of a thin file's law is `feature-thin` (R203). */
|
|
3
|
+
export declare const featureThin: RuleModule;
|
|
4
|
+
/** Non-door feature roles declare data; renaming a policy or a guard must never hide business logic from R203. */
|
|
5
|
+
export declare const featureLogicRole: RuleModule;
|
|
6
|
+
/** The rules this law contributes to the plugin. */
|
|
7
|
+
export declare const rules: {
|
|
8
|
+
"feature-thin": RuleModule;
|
|
9
|
+
"feature-logic-role": RuleModule;
|
|
10
|
+
};
|
|
11
|
+
/** Every rule of this law at `error`. */
|
|
12
|
+
export declare const recommended: Recommended;
|