@starci/eslint-canon-be 3.5.0 → 3.6.1
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 +21 -0
- package/README.md +13 -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-view.d.ts +127 -0
- package/dist/lib/hfs-view.js +1 -0
- 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 +23 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
- package/runtime/scripts/hfs/repo-identity.mjs +5 -4
- 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
|
@@ -21,27 +21,15 @@
|
|
|
21
21
|
* - `no-external-call-in-transaction` (R82) - inside a transaction callback, no call through a receiver typed from
|
|
22
22
|
* `integrations/**`, `HttpClient` or `MessagePublisher`, and no `fetch`.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
import
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
declaredInjectorNames,
|
|
31
|
-
inDatabaseCapability,
|
|
32
|
-
inCli,
|
|
33
|
-
implementsMigration,
|
|
34
|
-
infraTypeOf,
|
|
35
|
-
injectionSites,
|
|
36
|
-
isMigrationFile,
|
|
37
|
-
} from "./lib/persistence.mjs"
|
|
38
|
-
import { isPackageType, originsOfType, typed, typeOrigins } from "./lib/types.mjs"
|
|
39
|
-
|
|
24
|
+
import ts from "typescript";
|
|
25
|
+
import { nameOrValue, walk } from "./lib/ast.js";
|
|
26
|
+
import { hfsOf, inTestWorld } from "./lib/hfs.js";
|
|
27
|
+
import { resolveVariable, transactionCallback } from "./lib/transactions.js";
|
|
28
|
+
import { declaredInjectorNames, inDatabaseCapability, inCli, implementsMigration, infraTypeOf, injectionSites, isMigrationFile, } from "./lib/persistence.js";
|
|
29
|
+
import { isPackageType, originsOfType, typed, typeOrigins } from "./lib/types.js";
|
|
40
30
|
/** The `typeorm` repository types no class receives. */
|
|
41
|
-
const REPOSITORY_TYPES = ["Repository", "TreeRepository", "MongoRepository"]
|
|
42
|
-
|
|
31
|
+
const REPOSITORY_TYPES = ["Repository", "TreeRepository", "MongoRepository"];
|
|
43
32
|
// -- R83: the injector ---------------------------------------------------------------------------------
|
|
44
|
-
|
|
45
33
|
/** A constructor parameter typed `EntityManager` carries the named injector of a declared connection. */
|
|
46
34
|
export const mustInjectEntityManager = {
|
|
47
35
|
meta: {
|
|
@@ -49,163 +37,180 @@ export const mustInjectEntityManager = {
|
|
|
49
37
|
docs: { description: "An injected `EntityManager` carries the named injector of a declared connection." },
|
|
50
38
|
schema: [],
|
|
51
39
|
messages: {
|
|
52
|
-
undecorated:
|
|
53
|
-
"`EntityManager` is injected without a named injector. The type alone does not say WHICH database this is; only `{{expected}}` names a declared connection (from `hfs.json`), and a lookalike or a bare `InjectEntityManager()` names none. Inject it with the injector of the connection this class reads.",
|
|
40
|
+
undecorated: "`EntityManager` is injected without a named injector. The type alone does not say WHICH database this is; only `{{expected}}` names a declared connection (from `hfs.json`), and a lookalike or a bare `InjectEntityManager()` names none. Inject it with the injector of the connection this class reads.",
|
|
54
41
|
},
|
|
55
42
|
},
|
|
56
43
|
create(context) {
|
|
57
|
-
const hfs = hfsOf(context)
|
|
58
|
-
const expected = declaredInjectorNames(hfs)
|
|
44
|
+
const hfs = hfsOf(context);
|
|
45
|
+
const expected = declaredInjectorNames(hfs);
|
|
59
46
|
return injectionSites(({ node, kind, decorators, annotation }) => {
|
|
60
|
-
if (kind !== "param" || !annotation || infraTypeOf(context, annotation) !== "EntityManager")
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
if (kind !== "param" || !annotation || infraTypeOf(context, annotation) !== "EntityManager")
|
|
48
|
+
return;
|
|
49
|
+
if (decorators.some((name) => expected.includes(name)))
|
|
50
|
+
return;
|
|
51
|
+
context.report({ node, messageId: "undecorated", data: { expected: expected.join("` or `") || "no injector (declare the connection in hfs.json)" } });
|
|
52
|
+
});
|
|
64
53
|
},
|
|
65
|
-
}
|
|
66
|
-
|
|
54
|
+
};
|
|
67
55
|
/** The shared manager is injected by name, as a constructor parameter, and called directly. */
|
|
68
56
|
export const namedEntityManagerOnly = {
|
|
69
57
|
meta: {
|
|
70
58
|
type: "problem",
|
|
71
59
|
docs: {
|
|
72
|
-
description:
|
|
73
|
-
"No property injection of an `EntityManager`, `DataSource` or `QueryRunner`; a `DataSource` or `QueryRunner` only in the platform database capability, the cli app and the test world (`src/tests/world`); no `getRepository`.",
|
|
60
|
+
description: "No property injection of an `EntityManager`, `DataSource` or `QueryRunner`; a `DataSource` or `QueryRunner` only in the platform database capability, the cli app and the test world (`src/tests/world`); no `getRepository`.",
|
|
74
61
|
},
|
|
75
62
|
schema: [],
|
|
76
63
|
messages: {
|
|
77
|
-
property:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
token:
|
|
84
|
-
"This provider is bound to a `{{type}}`. A token that resolves to a connection object is a second door to the database: only `platform/database`, the cli app and the test world provide one.",
|
|
85
|
-
wrapper:
|
|
86
|
-
"`{{wrapper}}` exposes a `{{type}}` through `{{member}}`, and this class receives it. A connection wrapper is not a service dependency: inject the shared EntityManager with its named injector and call it directly.",
|
|
87
|
-
getRepository:
|
|
88
|
-
"`.getRepository(...)` binds a handle to ONE entity and hides which connection it came from. Call the shared manager directly: `manager.find(Entity, ...)`, `manager.save(Entity, ...)`, `tx.insert(Entity, ...)`.",
|
|
64
|
+
property: "`{{type}}` is injected as a class property. Property injection hides the dependency from the constructor and the app module. Receive the named-injector `EntityManager` as a constructor parameter.",
|
|
65
|
+
infra: "`{{type}}` is injected here. A `DataSource` or `QueryRunner` is built and held only by the platform database capability, the cli app and the test world in `src/tests/world`; specs take `world.db.<connection>`; everything else injects the shared `EntityManager` through its named injector and calls it directly.",
|
|
66
|
+
exposed: "`{{type}}` is written here outside the platform database capability, the cli app and the test world. A wrapper service that returns, holds or hands out a connection is the same door as injecting it: the connection is opened and held only by `platform/database`, and everything else calls the shared EntityManager through its named injector.",
|
|
67
|
+
token: "This provider is bound to a `{{type}}`. A token that resolves to a connection object is a second door to the database: only `platform/database`, the cli app and the test world provide one.",
|
|
68
|
+
wrapper: "`{{wrapper}}` exposes a `{{type}}` through `{{member}}`, and this class receives it. A connection wrapper is not a service dependency: inject the shared EntityManager with its named injector and call it directly.",
|
|
69
|
+
getRepository: "`.getRepository(...)` binds a handle to ONE entity and hides which connection it came from. Call the shared manager directly: `manager.find(Entity, ...)`, `manager.save(Entity, ...)`, `tx.insert(Entity, ...)`.",
|
|
89
70
|
},
|
|
90
71
|
},
|
|
91
72
|
create(context) {
|
|
92
|
-
const hfs = hfsOf(context)
|
|
93
|
-
const filename = context.filename || context.getFilename()
|
|
94
|
-
const mayHoldConnections = inDatabaseCapability(hfs, filename) || inCli(hfs, filename) || inTestWorld(hfs, filename) || isMigrationFile(hfs, filename)
|
|
95
|
-
const CONNECTION_TYPES = new Set(["DataSource", "QueryRunner"])
|
|
73
|
+
const hfs = hfsOf(context);
|
|
74
|
+
const filename = context.filename || context.getFilename();
|
|
75
|
+
const mayHoldConnections = inDatabaseCapability(hfs, filename) || inCli(hfs, filename) || inTestWorld(hfs, filename) || isMigrationFile(hfs, filename);
|
|
76
|
+
const CONNECTION_TYPES = new Set(["DataSource", "QueryRunner"]);
|
|
96
77
|
/** The connection type (DataSource / QueryRunner) a value or written type is declared as, else null. */
|
|
97
78
|
const connectionTypeOf = (node) => {
|
|
98
|
-
const type = infraTypeOf(context, node)
|
|
99
|
-
return type !== null && CONNECTION_TYPES.has(type) ? type : null
|
|
100
|
-
}
|
|
79
|
+
const type = infraTypeOf(context, node);
|
|
80
|
+
return type !== null && CONNECTION_TYPES.has(type) ? type : null;
|
|
81
|
+
};
|
|
101
82
|
/** The connection type of a checker type (awaited), else null. */
|
|
102
83
|
const connectionOfType = (type) => {
|
|
103
|
-
if (!type)
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
if (!type)
|
|
85
|
+
return null;
|
|
86
|
+
const { checker } = typed(context);
|
|
87
|
+
const awaited = checker.getAwaitedType(type) ?? type;
|
|
88
|
+
const origin = originsOfType(checker, awaited).find((entry) => entry.module === "typeorm" && CONNECTION_TYPES.has(entry.name));
|
|
89
|
+
return origin ? origin.name : null;
|
|
90
|
+
};
|
|
109
91
|
/** True when the node sits inside a class that implements typeorm's `MigrationInterface` (it receives a `QueryRunner` by contract). */
|
|
110
92
|
const insideMigrationClass = (node) => {
|
|
111
93
|
for (let current = node.parent; current; current = current.parent) {
|
|
112
|
-
if ((current.type === "ClassDeclaration" || current.type === "ClassExpression") && implementsMigration(context, current))
|
|
94
|
+
if ((current.type === "ClassDeclaration" || current.type === "ClassExpression") && implementsMigration(context, current))
|
|
95
|
+
return true;
|
|
113
96
|
}
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
116
99
|
/** The annotation of the constructor parameter or class property that contains this type node, else null. */
|
|
117
100
|
const siteAnnotationOf = (node) => {
|
|
118
101
|
for (let current = node.parent; current; current = current.parent) {
|
|
119
|
-
if (current.type !== "TSTypeAnnotation")
|
|
120
|
-
|
|
121
|
-
const
|
|
102
|
+
if (current.type !== "TSTypeAnnotation")
|
|
103
|
+
continue;
|
|
104
|
+
const owner = current.parent;
|
|
105
|
+
const isProperty = owner?.type === "PropertyDefinition";
|
|
122
106
|
const isParam = owner?.type === "Identifier" && (owner.parent?.type === "TSParameterProperty"
|
|
123
|
-
|| (owner.parent?.type === "FunctionExpression" && owner.parent.parent?.type === "MethodDefinition" && owner.parent.parent.kind === "constructor"))
|
|
124
|
-
return isProperty || isParam ? current.typeAnnotation : null
|
|
107
|
+
|| (owner.parent?.type === "FunctionExpression" && owner.parent.parent?.type === "MethodDefinition" && owner.parent.parent.kind === "constructor"));
|
|
108
|
+
return isProperty || isParam ? current.typeAnnotation : null;
|
|
125
109
|
}
|
|
126
|
-
return null
|
|
127
|
-
}
|
|
110
|
+
return null;
|
|
111
|
+
};
|
|
128
112
|
/** The member of a repository-declared class type that hands out a connection: `{ member, type, wrapper }`, else null. */
|
|
129
113
|
const exposedConnection = (annotation) => {
|
|
130
|
-
const { checker, toTs } = typed(context)
|
|
131
|
-
const tsNode = toTs(annotation)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
114
|
+
const { checker, toTs } = typed(context);
|
|
115
|
+
const tsNode = toTs(annotation);
|
|
116
|
+
// every type annotation maps to a TypeScript type node; the kind check only tells the compiler so
|
|
117
|
+
if (!tsNode || !ts.isTypeNode(tsNode))
|
|
118
|
+
return null;
|
|
119
|
+
const type = checker.getTypeFromTypeNode(tsNode);
|
|
120
|
+
const symbol = type.getSymbol();
|
|
121
|
+
const declaration = symbol && symbol.flags & ts.SymbolFlags.Class ? symbol.declarations?.[0] : null;
|
|
122
|
+
if (!symbol || !declaration || declaration.getSourceFile().fileName.replace(/\\/g, "/").includes("/node_modules/"))
|
|
123
|
+
return null;
|
|
137
124
|
for (const property of checker.getPropertiesOfType(type)) {
|
|
138
|
-
if (property.declarations?.some((entry) => ts.getCombinedModifierFlags(entry) & (ts.ModifierFlags.Private | ts.ModifierFlags.Protected)))
|
|
139
|
-
|
|
125
|
+
if (property.declarations?.some((entry) => ts.getCombinedModifierFlags(entry) & (ts.ModifierFlags.Private | ts.ModifierFlags.Protected)))
|
|
126
|
+
continue;
|
|
127
|
+
const memberType = checker.getTypeOfSymbolAtLocation(property, tsNode);
|
|
140
128
|
for (const candidate of [memberType, ...memberType.getCallSignatures().map((signature) => signature.getReturnType())]) {
|
|
141
|
-
const found = connectionOfType(candidate)
|
|
142
|
-
if (found)
|
|
129
|
+
const found = connectionOfType(candidate);
|
|
130
|
+
if (found)
|
|
131
|
+
return { member: property.getName(), type: found, wrapper: symbol.getName() };
|
|
143
132
|
}
|
|
144
133
|
}
|
|
145
|
-
return null
|
|
146
|
-
}
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
147
136
|
return {
|
|
148
137
|
...injectionSites(({ node, kind, annotation }) => {
|
|
149
|
-
if (!annotation)
|
|
150
|
-
|
|
138
|
+
if (!annotation)
|
|
139
|
+
return;
|
|
140
|
+
const type = infraTypeOf(context, annotation);
|
|
151
141
|
if (!type) {
|
|
152
|
-
const wrapper = kind === "param" && !mayHoldConnections ? exposedConnection(annotation) : null
|
|
153
|
-
if (wrapper)
|
|
154
|
-
|
|
142
|
+
const wrapper = kind === "param" && !mayHoldConnections ? exposedConnection(annotation) : null;
|
|
143
|
+
if (wrapper)
|
|
144
|
+
context.report({ node, messageId: "wrapper", data: wrapper });
|
|
145
|
+
return;
|
|
155
146
|
}
|
|
156
|
-
if (kind === "property")
|
|
157
|
-
|
|
147
|
+
if (kind === "property")
|
|
148
|
+
context.report({ node, messageId: "property", data: { type } });
|
|
149
|
+
else if (type !== "EntityManager" && !mayHoldConnections)
|
|
150
|
+
context.report({ node, messageId: "infra", data: { type } });
|
|
158
151
|
}),
|
|
159
152
|
TSTypeReference(node) {
|
|
160
|
-
if (mayHoldConnections)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
if (mayHoldConnections)
|
|
154
|
+
return;
|
|
155
|
+
const type = connectionTypeOf(node);
|
|
156
|
+
if (!type || insideMigrationClass(node))
|
|
157
|
+
return;
|
|
158
|
+
const site = siteAnnotationOf(node);
|
|
159
|
+
if (site && infraTypeOf(context, site))
|
|
160
|
+
return;
|
|
161
|
+
context.report({ node, messageId: "exposed", data: { type } });
|
|
166
162
|
},
|
|
167
163
|
AwaitExpression(node) {
|
|
168
|
-
if (mayHoldConnections || insideMigrationClass(node))
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
164
|
+
if (mayHoldConnections || insideMigrationClass(node))
|
|
165
|
+
return;
|
|
166
|
+
const { checker, toTs } = typed(context);
|
|
167
|
+
const tsNode = toTs(node);
|
|
168
|
+
const type = tsNode ? connectionOfType(checker.getTypeAtLocation(tsNode)) : null;
|
|
169
|
+
if (type)
|
|
170
|
+
context.report({ node, messageId: "exposed", data: { type } });
|
|
173
171
|
},
|
|
174
172
|
Property(node) {
|
|
175
|
-
if (mayHoldConnections || node.parent?.type !== "ObjectExpression" || node.computed)
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
if (mayHoldConnections || node.parent?.type !== "ObjectExpression" || node.computed)
|
|
174
|
+
return;
|
|
175
|
+
if ((node.key.type === "Identifier" ? node.key.name : node.key.value) !== "provide")
|
|
176
|
+
return;
|
|
177
|
+
const { checker, toTs } = typed(context);
|
|
178
178
|
for (const sibling of node.parent.properties) {
|
|
179
|
-
if (sibling.type !== "Property" || sibling.computed || sibling.key.type !== "Identifier")
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
179
|
+
if (sibling.type !== "Property" || sibling.computed || sibling.key.type !== "Identifier")
|
|
180
|
+
continue;
|
|
181
|
+
const tsNode = toTs(sibling.value);
|
|
182
|
+
if (!tsNode)
|
|
183
|
+
continue;
|
|
184
|
+
const type = checker.getTypeAtLocation(tsNode);
|
|
185
|
+
const provided = sibling.key.name === "useValue" ? type : sibling.key.name === "useFactory" ? type.getCallSignatures()[0]?.getReturnType() : null;
|
|
186
|
+
const found = connectionOfType(provided);
|
|
187
|
+
if (found)
|
|
188
|
+
context.report({ node, messageId: "token", data: { type: found } });
|
|
186
189
|
}
|
|
187
190
|
},
|
|
188
191
|
CallExpression(node) {
|
|
189
|
-
const callee = node.callee
|
|
190
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
191
|
-
|
|
192
|
-
if (
|
|
192
|
+
const callee = node.callee;
|
|
193
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
194
|
+
return;
|
|
195
|
+
if (callee.property.name !== "getRepository")
|
|
196
|
+
return;
|
|
197
|
+
if (infraTypeOf(context, callee.object))
|
|
198
|
+
context.report({ node, messageId: "getRepository" });
|
|
193
199
|
},
|
|
194
|
-
}
|
|
200
|
+
};
|
|
195
201
|
},
|
|
196
|
-
}
|
|
197
|
-
|
|
202
|
+
};
|
|
198
203
|
// -- R83: repositories ---------------------------------------------------------------------------------
|
|
199
|
-
|
|
200
204
|
/** Whether a type reference sits on a parameter or property already reported through its `@InjectRepository` decorator. */
|
|
201
205
|
const carriesInjectRepository = (node) => {
|
|
202
206
|
for (let owner = node.parent; owner && owner.type !== "ClassBody"; owner = owner.parent) {
|
|
203
|
-
const
|
|
204
|
-
|
|
207
|
+
const decorators = "decorators" in owner ? owner.decorators : undefined;
|
|
208
|
+
const decorated = (decorators ?? []).some((decorator) => decorator.expression.type === "CallExpression" && decorator.expression.callee.type === "Identifier" && decorator.expression.callee.name === "InjectRepository");
|
|
209
|
+
if (decorated)
|
|
210
|
+
return true;
|
|
205
211
|
}
|
|
206
|
-
return false
|
|
207
|
-
}
|
|
208
|
-
|
|
212
|
+
return false;
|
|
213
|
+
};
|
|
209
214
|
/** Persistence never arrives as a repository. */
|
|
210
215
|
export const noInjectedRepository = {
|
|
211
216
|
meta: {
|
|
@@ -213,37 +218,36 @@ export const noInjectedRepository = {
|
|
|
213
218
|
docs: { description: "Persistence goes through the shared `EntityManager`, never a repository." },
|
|
214
219
|
schema: [],
|
|
215
220
|
messages: {
|
|
216
|
-
repo:
|
|
217
|
-
|
|
218
|
-
forFeature:
|
|
219
|
-
"`TypeOrmModule.forFeature(...)` registers repositories, and this back end has none. Register the entities once on the connection in the platform database capability and call the shared EntityManager.",
|
|
221
|
+
repo: "Inject the shared EntityManager with the named injector and call it directly. A repository is bound to ONE entity, so it cannot carry a transaction into a second table - and a use case that grows a second write then has to be rewritten rather than extended.",
|
|
222
|
+
forFeature: "`TypeOrmModule.forFeature(...)` registers repositories, and this back end has none. Register the entities once on the connection in the platform database capability and call the shared EntityManager.",
|
|
220
223
|
},
|
|
221
224
|
},
|
|
222
225
|
create(context) {
|
|
223
226
|
return {
|
|
224
227
|
Decorator(node) {
|
|
225
|
-
const expression = node.expression
|
|
228
|
+
const expression = node.expression;
|
|
226
229
|
if (expression.type === "CallExpression" && expression.callee.type === "Identifier" && expression.callee.name === "InjectRepository") {
|
|
227
|
-
context.report({ node, messageId: "repo" })
|
|
230
|
+
context.report({ node, messageId: "repo" });
|
|
228
231
|
}
|
|
229
232
|
},
|
|
230
233
|
TSTypeReference(node) {
|
|
231
|
-
if (!REPOSITORY_TYPES.some((name) => isPackageType(context, node, name, "typeorm")))
|
|
232
|
-
|
|
234
|
+
if (!REPOSITORY_TYPES.some((name) => isPackageType(context, node, name, "typeorm")))
|
|
235
|
+
return;
|
|
236
|
+
if (!carriesInjectRepository(node))
|
|
237
|
+
context.report({ node, messageId: "repo" });
|
|
233
238
|
},
|
|
234
239
|
CallExpression(node) {
|
|
235
|
-
const callee = node.callee
|
|
236
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
240
|
+
const callee = node.callee;
|
|
241
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
242
|
+
return;
|
|
237
243
|
if (callee.property.name === "forFeature" && isPackageType(context, callee.object, "TypeOrmModule", "@nestjs/typeorm")) {
|
|
238
|
-
context.report({ node, messageId: "forFeature" })
|
|
244
|
+
context.report({ node, messageId: "forFeature" });
|
|
239
245
|
}
|
|
240
246
|
},
|
|
241
|
-
}
|
|
247
|
+
};
|
|
242
248
|
},
|
|
243
|
-
}
|
|
244
|
-
|
|
249
|
+
};
|
|
245
250
|
// -- DATA-3 ----------------------------------------------------------------------------------------
|
|
246
|
-
|
|
247
251
|
/** An entity names its table, so a class rename cannot become a dropped table. */
|
|
248
252
|
export const requireEntityTableName = {
|
|
249
253
|
meta: {
|
|
@@ -251,57 +255,51 @@ export const requireEntityTableName = {
|
|
|
251
255
|
docs: { description: "`@Entity()` names its table explicitly." },
|
|
252
256
|
schema: [],
|
|
253
257
|
messages: {
|
|
254
|
-
inferred:
|
|
255
|
-
"`@Entity()` here lets the ORM infer the table name from the class name, so renaming the class renames the table - which `synchronize` performs as a DROP and CREATE rather than a migration. A class rename is a refactor; a dropped table is an outage. Name the table.",
|
|
258
|
+
inferred: "`@Entity()` here lets the ORM infer the table name from the class name, so renaming the class renames the table - which `synchronize` performs as a DROP and CREATE rather than a migration. A class rename is a refactor; a dropped table is an outage. Name the table.",
|
|
256
259
|
},
|
|
257
260
|
},
|
|
258
261
|
create(context) {
|
|
259
262
|
/** Both `@Entity("t")` and `@Entity({ name: "t" })` name the table. */
|
|
260
|
-
const isTableName = (argument) =>
|
|
261
|
-
(argument.type === "Literal" && typeof argument.value === "string") || argument.type === "TemplateLiteral"
|
|
263
|
+
const isTableName = (argument) => (argument.type === "Literal" && typeof argument.value === "string") || argument.type === "TemplateLiteral";
|
|
262
264
|
return {
|
|
263
265
|
Decorator(node) {
|
|
264
|
-
const expression = node.expression
|
|
265
|
-
if (expression.type !== "CallExpression")
|
|
266
|
-
|
|
266
|
+
const expression = node.expression;
|
|
267
|
+
if (expression.type !== "CallExpression")
|
|
268
|
+
return;
|
|
269
|
+
if (expression.callee.type !== "Identifier" || expression.callee.name !== "Entity")
|
|
270
|
+
return;
|
|
267
271
|
// The options form is not a stylistic variant to discourage: it is the ONLY form that can
|
|
268
272
|
// also carry a schema qualifier, so rejecting it would push an author to delete the schema
|
|
269
273
|
// to satisfy the rule - a worse outcome than the inferred name this exists to prevent.
|
|
270
|
-
const named = expression.arguments.some(
|
|
271
|
-
(argument
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
&&
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
&& (property.key.name === "name" || property.key.value === "name")
|
|
279
|
-
&& isTableName(property.value),
|
|
280
|
-
)),
|
|
281
|
-
)
|
|
282
|
-
if (!named) context.report({ node, messageId: "inferred" })
|
|
274
|
+
const named = expression.arguments.some((argument) => isTableName(argument)
|
|
275
|
+
|| (argument.type === "ObjectExpression"
|
|
276
|
+
&& argument.properties.some((property) => property.type === "Property"
|
|
277
|
+
&& !property.computed
|
|
278
|
+
&& nameOrValue(property.key) === "name"
|
|
279
|
+
&& isTableName(property.value))));
|
|
280
|
+
if (!named)
|
|
281
|
+
context.report({ node, messageId: "inferred" });
|
|
283
282
|
},
|
|
284
|
-
}
|
|
283
|
+
};
|
|
285
284
|
},
|
|
286
|
-
}
|
|
287
|
-
|
|
285
|
+
};
|
|
288
286
|
// -- transactions ----------------------------------------------------------------------------------
|
|
289
|
-
|
|
290
287
|
/** The leftmost expression of a member chain: `this.deps.em` gives the `this`. */
|
|
291
288
|
const rootOf = (expression) => {
|
|
292
|
-
let current = expression
|
|
293
|
-
while (current.type === "MemberExpression" || current.type === "TSNonNullExpression")
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
289
|
+
let current = expression;
|
|
290
|
+
while (current.type === "MemberExpression" || current.type === "TSNonNullExpression")
|
|
291
|
+
current = current.type === "MemberExpression" ? current.object : current.expression;
|
|
292
|
+
return current;
|
|
293
|
+
};
|
|
297
294
|
/** Whether an identifier position reads a value (a property name, a key or a type name does not). */
|
|
298
295
|
const readsValue = (node) => {
|
|
299
|
-
const parent = node.parent
|
|
300
|
-
if (parent.type === "MemberExpression" && parent.property === node && !parent.computed)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
296
|
+
const parent = node.parent;
|
|
297
|
+
if (parent.type === "MemberExpression" && parent.property === node && !parent.computed)
|
|
298
|
+
return false;
|
|
299
|
+
if (parent.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand)
|
|
300
|
+
return false;
|
|
301
|
+
return !parent.type.startsWith("TS");
|
|
302
|
+
};
|
|
305
303
|
/** Everything inside a transaction receives the transactional manager, not one declared outside it. */
|
|
306
304
|
export const noOuterManagerInTransaction = {
|
|
307
305
|
meta: {
|
|
@@ -309,40 +307,41 @@ export const noOuterManagerInTransaction = {
|
|
|
309
307
|
docs: { description: "Inside `<manager>.transaction(async (tx) => ...)`, every call uses `tx`, never another `EntityManager` declared outside the callback." },
|
|
310
308
|
schema: [],
|
|
311
309
|
messages: {
|
|
312
|
-
outerManager:
|
|
313
|
-
"`{{name}}` is an EntityManager from OUTSIDE this transaction callback. A call through it runs and commits on its own, which is how half a write survives a rollback. Use the manager the callback received.",
|
|
310
|
+
outerManager: "`{{name}}` is an EntityManager from OUTSIDE this transaction callback. A call through it runs and commits on its own, which is how half a write survives a rollback. Use the manager the callback received.",
|
|
314
311
|
},
|
|
315
312
|
},
|
|
316
313
|
create(context) {
|
|
317
|
-
const sourceCode = context.sourceCode || context.getSourceCode()
|
|
314
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
318
315
|
/** Whether the value written at `node` was declared outside the callback spanning `range`. */
|
|
319
316
|
const declaredOutside = (node, range) => {
|
|
320
|
-
const root = rootOf(node)
|
|
321
|
-
if (root.type === "ThisExpression")
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
317
|
+
const root = rootOf(node);
|
|
318
|
+
if (root.type === "ThisExpression")
|
|
319
|
+
return true;
|
|
320
|
+
if (root.type !== "Identifier")
|
|
321
|
+
return false;
|
|
322
|
+
const variable = resolveVariable(sourceCode, root);
|
|
323
|
+
const declaration = variable?.defs[0]?.name;
|
|
324
|
+
return declaration ? (declaration.range[0] < range[0] || declaration.range[1] > range[1]) : false;
|
|
325
|
+
};
|
|
327
326
|
return {
|
|
328
327
|
CallExpression(node) {
|
|
329
|
-
const callback = transactionCallback(context, node)
|
|
330
|
-
if (!callback)
|
|
328
|
+
const callback = transactionCallback(context, node);
|
|
329
|
+
if (!callback)
|
|
330
|
+
return;
|
|
331
331
|
walk(callback.body, (child) => {
|
|
332
|
-
const isReference = child.type === "MemberExpression" || (child.type === "Identifier" && readsValue(child))
|
|
333
|
-
if (!isReference || infraTypeOf(context, child) !== "EntityManager")
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
const isReference = child.type === "MemberExpression" || (child.type === "Identifier" && readsValue(child));
|
|
333
|
+
if (!isReference || infraTypeOf(context, child) !== "EntityManager")
|
|
334
|
+
return;
|
|
335
|
+
if (declaredOutside(child, callback.range))
|
|
336
|
+
context.report({ node: child, messageId: "outerManager", data: { name: sourceCode.getText(child) } });
|
|
337
|
+
});
|
|
336
338
|
},
|
|
337
|
-
}
|
|
339
|
+
};
|
|
338
340
|
},
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
+
};
|
|
341
342
|
// -- DATA-5 (Rule 6) --------------------------------------------------------------------------------
|
|
342
|
-
|
|
343
343
|
/** Relation decorators whose `eager` option can grant the relation to every caller. */
|
|
344
|
-
const RELATION_DECORATORS = /^(?:ManyToOne|OneToOne|OneToMany|ManyToMany)
|
|
345
|
-
|
|
344
|
+
const RELATION_DECORATORS = /^(?:ManyToOne|OneToOne|OneToMany|ManyToMany)$/;
|
|
346
345
|
/** A relation is asked for by the call site that needs it; the entity grants no relation eagerly. */
|
|
347
346
|
export const noEagerRelation = {
|
|
348
347
|
meta: {
|
|
@@ -352,53 +351,53 @@ export const noEagerRelation = {
|
|
|
352
351
|
},
|
|
353
352
|
schema: [],
|
|
354
353
|
messages: {
|
|
355
|
-
eager:
|
|
356
|
-
"`@{{decorator}}(..., { eager: true })` grants this relation to every caller whether it asked for it or not, so a query that wants one column now pays for the whole tree. State the relation in the `relations` the call site writes, and drop `eager` here.",
|
|
354
|
+
eager: "`@{{decorator}}(..., { eager: true })` grants this relation to every caller whether it asked for it or not, so a query that wants one column now pays for the whole tree. State the relation in the `relations` the call site writes, and drop `eager` here.",
|
|
357
355
|
},
|
|
358
356
|
},
|
|
359
357
|
create(context) {
|
|
360
358
|
return {
|
|
361
359
|
Decorator(node) {
|
|
362
|
-
const expression = node.expression
|
|
363
|
-
if (expression.type !== "CallExpression")
|
|
364
|
-
|
|
360
|
+
const expression = node.expression;
|
|
361
|
+
if (expression.type !== "CallExpression")
|
|
362
|
+
return;
|
|
363
|
+
if (expression.callee.type !== "Identifier" || !RELATION_DECORATORS.test(expression.callee.name))
|
|
364
|
+
return;
|
|
365
365
|
for (const argument of expression.arguments) {
|
|
366
|
-
if (argument.type !== "ObjectExpression")
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (!eagerProperty) continue
|
|
366
|
+
if (argument.type !== "ObjectExpression")
|
|
367
|
+
continue;
|
|
368
|
+
const eagerProperty = argument.properties.find((property) => property.type === "Property"
|
|
369
|
+
&& !property.computed
|
|
370
|
+
&& nameOrValue(property.key) === "eager");
|
|
371
|
+
if (!eagerProperty)
|
|
372
|
+
continue;
|
|
374
373
|
if (eagerProperty.value.type === "Literal" && eagerProperty.value.value === true) {
|
|
375
|
-
context.report({ node, messageId: "eager", data: { decorator: expression.callee.name } })
|
|
374
|
+
context.report({ node, messageId: "eager", data: { decorator: expression.callee.name } });
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
377
|
},
|
|
379
|
-
}
|
|
378
|
+
};
|
|
380
379
|
},
|
|
381
|
-
}
|
|
382
|
-
|
|
380
|
+
};
|
|
383
381
|
// -- R82 ---------------------------------------------------------------------------------------------
|
|
384
|
-
|
|
385
382
|
/** The platform types whose calls leave the process. */
|
|
386
|
-
const PLATFORM_EXTERNAL_TYPES = new Set(["HttpClient", "MessagePublisher"])
|
|
387
|
-
|
|
383
|
+
const PLATFORM_EXTERNAL_TYPES = new Set(["HttpClient", "MessagePublisher"]);
|
|
388
384
|
/** Every receiver of a call chain, outermost first: `this.stripe.charges.create()` gives `this.stripe.charges`, `this.stripe`, `this`. */
|
|
389
385
|
const receiversOf = (callee) => {
|
|
390
|
-
const receivers = []
|
|
391
|
-
let current = callee.type === "MemberExpression" ? callee.object : null
|
|
386
|
+
const receivers = [];
|
|
387
|
+
let current = callee.type === "MemberExpression" ? callee.object : null;
|
|
392
388
|
while (current) {
|
|
393
|
-
receivers.push(current)
|
|
394
|
-
if (current.type === "MemberExpression")
|
|
395
|
-
|
|
396
|
-
else if (current.type === "
|
|
397
|
-
|
|
389
|
+
receivers.push(current);
|
|
390
|
+
if (current.type === "MemberExpression")
|
|
391
|
+
current = current.object;
|
|
392
|
+
else if (current.type === "CallExpression")
|
|
393
|
+
current = current.callee.type === "MemberExpression" ? current.callee.object : null;
|
|
394
|
+
else if (current.type === "TSNonNullExpression")
|
|
395
|
+
current = current.expression;
|
|
396
|
+
else
|
|
397
|
+
current = null;
|
|
398
398
|
}
|
|
399
|
-
return receivers
|
|
400
|
-
}
|
|
401
|
-
|
|
399
|
+
return receivers;
|
|
400
|
+
};
|
|
402
401
|
/** No transaction spans an external call: commit first, then call out (or write an outbox message inside the transaction). */
|
|
403
402
|
export const noExternalCallInTransaction = {
|
|
404
403
|
meta: {
|
|
@@ -406,35 +405,32 @@ export const noExternalCallInTransaction = {
|
|
|
406
405
|
docs: { description: "An HTTP, SDK or publish call does not run inside `<manager>.transaction(async (tx) => ...)`." },
|
|
407
406
|
schema: [],
|
|
408
407
|
messages: {
|
|
409
|
-
external:
|
|
410
|
-
"`{{call}}` runs inside `.transaction(...)`. A database transaction held open for as long as an external call takes means: the call fails after the transaction already did its work and now has to be undone by hand, or the call succeeds and the transaction then rolls back, and the two systems disagree with no way back. Commit the transaction, then make the call - or write an outbox message inside the transaction and let a worker deliver it after commit.",
|
|
408
|
+
external: "`{{call}}` runs inside `.transaction(...)`. A database transaction held open for as long as an external call takes means: the call fails after the transaction already did its work and now has to be undone by hand, or the call succeeds and the transaction then rolls back, and the two systems disagree with no way back. Commit the transaction, then make the call - or write an outbox message inside the transaction and let a worker deliver it after commit.",
|
|
411
409
|
},
|
|
412
410
|
},
|
|
413
411
|
create(context) {
|
|
414
|
-
const hfs = hfsOf(context)
|
|
415
|
-
const sourceCode = context.sourceCode || context.getSourceCode()
|
|
412
|
+
const hfs = hfsOf(context);
|
|
413
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
416
414
|
/** Whether a value's type is declared in `integrations/**` or is the platform `HttpClient` / `MessagePublisher`. */
|
|
417
|
-
const isExternalReceiver = (node) =>
|
|
418
|
-
typeOrigins(context, node).some(
|
|
419
|
-
(origin) => hfs.tierOf(origin.file) === "integrations" || (PLATFORM_EXTERNAL_TYPES.has(origin.name) && hfs.slotOf(origin.file) === "be.platform"),
|
|
420
|
-
)
|
|
415
|
+
const isExternalReceiver = (node) => typeOrigins(context, node).some((origin) => hfs.tierOf(origin.file) === "integrations" || (PLATFORM_EXTERNAL_TYPES.has(origin.name) && hfs.slotOf(origin.file) === "be.platform"));
|
|
421
416
|
return {
|
|
422
417
|
CallExpression(node) {
|
|
423
|
-
const callback = transactionCallback(context, node)
|
|
424
|
-
if (!callback)
|
|
418
|
+
const callback = transactionCallback(context, node);
|
|
419
|
+
if (!callback)
|
|
420
|
+
return;
|
|
425
421
|
walk(callback.body, (child) => {
|
|
426
|
-
if (child.type !== "CallExpression")
|
|
427
|
-
|
|
428
|
-
const
|
|
422
|
+
if (child.type !== "CallExpression")
|
|
423
|
+
return;
|
|
424
|
+
const { callee } = child;
|
|
425
|
+
const globalFetch = callee.type === "Identifier" && callee.name === "fetch" && !resolveVariable(sourceCode, callee)?.defs.length;
|
|
429
426
|
if (globalFetch || receiversOf(callee).some(isExternalReceiver)) {
|
|
430
|
-
context.report({ node: child, messageId: "external", data: { call: sourceCode.getText(callee).slice(0, 60) } })
|
|
427
|
+
context.report({ node: child, messageId: "external", data: { call: sourceCode.getText(callee).slice(0, 60) } });
|
|
431
428
|
}
|
|
432
|
-
})
|
|
429
|
+
});
|
|
433
430
|
},
|
|
434
|
-
}
|
|
431
|
+
};
|
|
435
432
|
},
|
|
436
|
-
}
|
|
437
|
-
|
|
433
|
+
};
|
|
438
434
|
/** The rules this law contributes to the plugin. */
|
|
439
435
|
export const rules = {
|
|
440
436
|
"must-inject-entity-manager": mustInjectEntityManager,
|
|
@@ -444,8 +440,7 @@ export const rules = {
|
|
|
444
440
|
"no-eager-relation": noEagerRelation,
|
|
445
441
|
"no-external-call-in-transaction": noExternalCallInTransaction,
|
|
446
442
|
"named-entity-manager-only": namedEntityManagerOnly,
|
|
447
|
-
}
|
|
448
|
-
|
|
443
|
+
};
|
|
449
444
|
/** Every rule of this law ships at `error`; a repository is fixed before it adopts the plugin, never given a weaker level. */
|
|
450
445
|
export const recommended = {
|
|
451
446
|
"starci-be/must-inject-entity-manager": "error",
|
|
@@ -455,4 +450,4 @@ export const recommended = {
|
|
|
455
450
|
"starci-be/no-eager-relation": "error",
|
|
456
451
|
"starci-be/no-external-call-in-transaction": "error",
|
|
457
452
|
"starci-be/named-entity-manager-only": "error",
|
|
458
|
-
}
|
|
453
|
+
};
|