@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.
Files changed (195) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +11 -2
  3. package/dist/ambient-id.d.ts +9 -0
  4. package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
  5. package/dist/app-composition.d.ts +21 -0
  6. package/{app-composition.mjs → dist/app-composition.js} +396 -300
  7. package/dist/async-discipline.d.ts +9 -0
  8. package/dist/async-discipline.js +77 -0
  9. package/dist/authorization.d.ts +12 -0
  10. package/{authorization.mjs → dist/authorization.js} +53 -59
  11. package/dist/boundary-schema.d.ts +15 -0
  12. package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
  13. package/dist/builders.d.ts +21 -0
  14. package/{builders.mjs → dist/builders.js} +162 -146
  15. package/dist/cli.d.ts +15 -0
  16. package/{cli.mjs → dist/cli.js} +97 -82
  17. package/dist/comments.d.ts +52 -0
  18. package/dist/comments.js +412 -0
  19. package/dist/config-owner.d.ts +24 -0
  20. package/{config-owner.mjs → dist/config-owner.js} +256 -219
  21. package/dist/connections.d.ts +12 -0
  22. package/{connections.mjs → dist/connections.js} +138 -140
  23. package/dist/cookies.d.ts +9 -0
  24. package/{cookies.mjs → dist/cookies.js} +58 -58
  25. package/dist/cqrs.d.ts +27 -0
  26. package/{cqrs.mjs → dist/cqrs.js} +341 -282
  27. package/dist/data-access.d.ts +50 -0
  28. package/{data-access.mjs → dist/data-access.js} +238 -243
  29. package/dist/default-deny.d.ts +15 -0
  30. package/{default-deny.mjs → dist/default-deny.js} +103 -88
  31. package/dist/e2e-flow.d.ts +25 -0
  32. package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
  33. package/dist/edge-hardening.d.ts +10 -0
  34. package/dist/edge-hardening.js +173 -0
  35. package/dist/error-handling.d.ts +21 -0
  36. package/{error-handling.mjs → dist/error-handling.js} +289 -239
  37. package/dist/event-bus.d.ts +14 -0
  38. package/{event-bus.mjs → dist/event-bus.js} +146 -129
  39. package/dist/feature-thin.d.ts +12 -0
  40. package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
  41. package/dist/function-budget.d.ts +7 -0
  42. package/{function-budget.mjs → dist/function-budget.js} +24 -27
  43. package/dist/health-ready.d.ts +10 -0
  44. package/dist/health-ready.js +703 -0
  45. package/dist/idempotency.d.ts +10 -0
  46. package/{idempotency.mjs → dist/idempotency.js} +296 -226
  47. package/dist/index.d.ts +54 -0
  48. package/{index.mjs → dist/index.js} +91 -109
  49. package/dist/infra-owner.d.ts +18 -0
  50. package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
  51. package/dist/injection.d.ts +30 -0
  52. package/{injection.mjs → dist/injection.js} +397 -344
  53. package/dist/input-bounds.d.ts +15 -0
  54. package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
  55. package/dist/jobs.d.ts +17 -0
  56. package/{jobs.mjs → dist/jobs.js} +116 -99
  57. package/dist/jwt-alg.d.ts +6 -0
  58. package/dist/jwt-alg.js +49 -0
  59. package/dist/lib/app-roles.d.ts +25 -0
  60. package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
  61. package/dist/lib/ast.d.ts +40 -0
  62. package/dist/lib/ast.js +100 -0
  63. package/dist/lib/client-idempotency.d.ts +3 -0
  64. package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
  65. package/dist/lib/config.d.ts +36 -0
  66. package/{lib/config.mjs → dist/lib/config.js} +24 -27
  67. package/dist/lib/db-writes.d.ts +29 -0
  68. package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
  69. package/dist/lib/declared.d.ts +77 -0
  70. package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
  71. package/dist/lib/doors.d.ts +50 -0
  72. package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
  73. package/dist/lib/edition.d.ts +25 -0
  74. package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
  75. package/dist/lib/entity-writes.d.ts +7 -0
  76. package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
  77. package/dist/lib/hfs.d.ts +34 -0
  78. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  79. package/dist/lib/import-source.d.ts +63 -0
  80. package/dist/lib/import-source.js +134 -0
  81. package/dist/lib/path.d.ts +8 -0
  82. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  83. package/dist/lib/persistence.d.ts +115 -0
  84. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  85. package/dist/lib/ports.d.ts +70 -0
  86. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  87. package/dist/lib/rule.d.ts +31 -0
  88. package/dist/lib/rule.js +2 -0
  89. package/dist/lib/runtime-root.d.ts +4 -0
  90. package/dist/lib/runtime-root.js +10 -0
  91. package/dist/lib/schema-values.d.ts +13 -0
  92. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  93. package/dist/lib/specifier.d.ts +12 -0
  94. package/dist/lib/specifier.js +29 -0
  95. package/dist/lib/subject-values.d.ts +4 -0
  96. package/dist/lib/subject-values.js +61 -0
  97. package/dist/lib/transactions.d.ts +18 -0
  98. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  99. package/dist/lib/transport-slots.d.ts +17 -0
  100. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  101. package/dist/lib/types.d.ts +96 -0
  102. package/dist/lib/types.js +150 -0
  103. package/dist/lib/unit-spec.d.ts +48 -0
  104. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  105. package/dist/lib/webhook-ack.d.ts +4 -0
  106. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  107. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  108. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  109. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  110. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  111. package/dist/lib/webhook-handoff.d.ts +15 -0
  112. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  113. package/dist/lib/webhook-verifiers.d.ts +20 -0
  114. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  115. package/dist/lib/why.d.ts +9 -0
  116. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  117. package/dist/log-safety.d.ts +20 -0
  118. package/dist/log-safety.js +308 -0
  119. package/dist/module-layering.d.ts +42 -0
  120. package/dist/module-layering.js +257 -0
  121. package/dist/module-shape.d.ts +47 -0
  122. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  123. package/dist/naming.d.ts +49 -0
  124. package/dist/naming.js +246 -0
  125. package/dist/observability.d.ts +25 -0
  126. package/dist/observability.js +245 -0
  127. package/dist/operations.d.ts +23 -0
  128. package/{operations.mjs → dist/operations.js} +410 -332
  129. package/dist/project-graph.d.ts +9 -0
  130. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  131. package/dist/projections.d.ts +11 -0
  132. package/{projections.mjs → dist/projections.js} +60 -57
  133. package/dist/query-safety.d.ts +21 -0
  134. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  135. package/dist/realtime.d.ts +15 -0
  136. package/{realtime.mjs → dist/realtime.js} +108 -106
  137. package/dist/resilience.d.ts +15 -0
  138. package/dist/resilience.js +319 -0
  139. package/dist/schema-authority.d.ts +15 -0
  140. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  141. package/dist/service-deps.d.ts +17 -0
  142. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  143. package/dist/service-isolation.d.ts +8 -0
  144. package/dist/service-isolation.js +76 -0
  145. package/dist/size-budget.d.ts +9 -0
  146. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  147. package/dist/sonar-parity.d.ts +5 -0
  148. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  149. package/dist/spec-no-skip.d.ts +9 -0
  150. package/dist/spec-no-skip.js +81 -0
  151. package/dist/spec-quality.d.ts +10 -0
  152. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  153. package/dist/suppression.d.ts +26 -0
  154. package/{suppression.mjs → dist/suppression.js} +30 -45
  155. package/dist/temporal.d.ts +9 -0
  156. package/{temporal.mjs → dist/temporal.js} +75 -65
  157. package/dist/test-world.d.ts +28 -0
  158. package/{test-world.mjs → dist/test-world.js} +102 -83
  159. package/dist/testing.d.ts +51 -0
  160. package/dist/testing.js +368 -0
  161. package/dist/third-party-owner.d.ts +8 -0
  162. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  163. package/dist/transport.d.ts +24 -0
  164. package/{transport.mjs → dist/transport.js} +279 -240
  165. package/dist/type-safety.d.ts +25 -0
  166. package/dist/type-safety.js +297 -0
  167. package/dist/unit-spec.d.ts +30 -0
  168. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  169. package/dist/uploads.d.ts +9 -0
  170. package/{uploads.mjs → dist/uploads.js} +62 -54
  171. package/dist/user-copy.d.ts +9 -0
  172. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  173. package/dist/webhooks.d.ts +16 -0
  174. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  175. package/package.json +17 -8
  176. package/runtime/knowledge/hfs/canon-pins.yaml +17 -10
  177. package/async-discipline.mjs +0 -83
  178. package/comments.mjs +0 -416
  179. package/edge-hardening.mjs +0 -139
  180. package/health-ready.mjs +0 -539
  181. package/jwt-alg.mjs +0 -45
  182. package/lib/ast.mjs +0 -88
  183. package/lib/import-source.mjs +0 -104
  184. package/lib/specifier.mjs +0 -27
  185. package/lib/subject-values.mjs +0 -55
  186. package/lib/types.mjs +0 -133
  187. package/log-safety.mjs +0 -303
  188. package/module-layering.mjs +0 -270
  189. package/naming.mjs +0 -251
  190. package/observability.mjs +0 -241
  191. package/resilience.mjs +0 -304
  192. package/service-isolation.mjs +0 -75
  193. package/spec-no-skip.mjs +0 -85
  194. package/testing.mjs +0 -384
  195. 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.mjs"
14
- import { hfsOf } from "./lib/hfs.mjs"
15
- import { decoratorArguments, decoratorCallee, importOf, isImportedFrom, moduleReferences } from "./lib/import-source.mjs"
16
- import { isTransportSlot, KIND_DOOR_SLOTS } from "./lib/transport-slots.mjs"
17
- import { isPackageType, typeOrigins, typed } from "./lib/types.mjs"
18
- import { operationRouteEvidence, restExceptionEvidence } from "./operations.mjs"
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) return false
48
- if ((member.decorators ?? []).some((decorator) => isRouteDecorator(context, decorator))) return true
49
- return PLAIN_ENTRY_SLOTS.has(slot) && member.accessibility !== "private" && member.accessibility !== "protected"
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") return true
65
- if (origin.name === "RequestLocale" && slot === HTTP_SLOT && declaredByCapability(hfs, origin.file, "i18n")) return true
66
- return false
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") return false
74
- const found = importOf(context, callee)
75
- if (found?.source === "@nestjs/common" && found.imported === "Inject") return true
76
- if (found?.source === "@nestjs/typeorm") return true
77
- const { checker, toTs } = typed(context)
78
- let symbol = checker.getSymbolAtLocation(toTs(callee))
79
- if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0) symbol = checker.getAliasedSymbol(symbol)
80
- return (symbol?.getDeclarations() ?? []).some((declaration) => declaration.getSourceFile().fileName.replace(/\\/g, "/").endsWith(".decorators.ts"))
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)) count += 1
88
- })
89
- return count
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")) return "bus"
99
- if (origins.some((origin) => origin.name === "RequestLocale" && origin.module === null)) return "locale"
100
- return null
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)) return {}
126
- const sourceCode = context.sourceCode
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") return false
129
- const found = importOf(context, callee)
130
- return found !== null && /(?:^|\/)[^/]+\.mapper(?:\.[cm]?[jt]s)?$/.test(found.source.replace(/\\/g, "/"))
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") return false
135
- const { checker, toTs } = typed(context)
136
- const tsNode = toTs(callee)
137
- let symbol = tsNode && checker.getSymbolAtLocation(tsNode)
138
- if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0) symbol = checker.getAliasedSymbol(symbol)
139
- return symbol?.getName() === "unwrapOutcome" && (symbol.getDeclarations() ?? []).some((declaration) => declaredByCapability(hfs, declaration.getSourceFile().fileName, "primitives"))
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?.decorators ?? []).some((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", "Module"))) return
145
- const locales = new Set()
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
- const kind = name === null ? null : injectedKind(context, annotation)
148
- if (kind === "locale") locales.add(name)
149
- }
150
- const constructor = node.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "constructor")
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)) context.report({ node: original, messageId: "injects", data: { what: sourceCode.getText(param) } })
155
- else classify(original.type === "TSParameterProperty" && param.type === "Identifier" ? param.name : null, annotation)
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))) continue
159
- const annotation = member.typeAnnotation?.typeAnnotation
160
- if (!annotation || !isAllowedInjection(context, hfs, slot, annotation)) context.report({ node: member, messageId: "injects", data: { what: sourceCode.getText(member) } })
161
- else classify(member.key.type === "Identifier" ? member.key.name : null, annotation)
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) return
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) continue
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") return
173
- const callee = child.callee
174
- const member = callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee : null
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) context.report({ node: child, messageId: "call", data: { what: sourceCode.getText(callee) } })
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) context.report({ node: method.key, messageId: "none", data: { name } })
186
- else if (count > 1) context.report({ node: method.key, messageId: "many", data: { name, count: String(count) } })
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) returns = true
191
- }, { intoFunctions: false })
192
- if (!returns) context.report({ node: method.key, messageId: "noReturn", data: { name } })
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") return false
210
- let symbol = checker.getSymbolAtLocation(toTs(callee))
211
- if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0) symbol = checker.getAliasedSymbol(symbol)
212
- const declaration = (symbol?.getDeclarations() ?? []).find((candidate) => ts.isClassDeclaration(candidate) && !program.isSourceFileFromExternalLibrary(candidate.getSourceFile()) && !program.isSourceFileDefaultLibrary(candidate.getSourceFile()))
213
- const intercept = declaration?.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "intercept")
214
- if (!intercept) return false
215
- let mapped = false
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) return
218
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && importedFromRxjs(checker, node.expression)) mapped = true
219
- ts.forEachChild(node, visit)
220
- }
221
- visit(intercept)
222
- return mapped
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)) return false
230
- const imported = (declaration.propertyName ?? declaration.name).text
231
- const module = ts.findAncestor(declaration, ts.isImportDeclaration)?.moduleSpecifier
232
- return imported === "map" && ts.isStringLiteral(module) && (module.text === "rxjs" || module.text.startsWith("rxjs/"))
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")) current = current.type === "AwaitExpression" ? current.argument : current.expression
239
- return current
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 = (node, id) => {
259
- if (id?.type === "Identifier" && ENVELOPE_NAMES.has(id.name)) context.report({ node: id, messageId: "named", data: { name: 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, node.id),
263
- FunctionDeclaration: (node) => declared(node, node.id),
264
- VariableDeclarator: (node) => declared(node, node.id),
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)) context.report({ node, messageId: "named", data: { 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) return visitors
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")) return
275
- for (const argument of decoratorArguments(node)) if (interceptorMapsResponse(context, argument)) context.report({ node: argument, messageId: "interceptor" })
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") owner = owner.parent
280
- if (owner?.parent?.type !== "MethodDefinition") return
281
- const value = returned(node.argument)
282
- if (value?.type !== "ObjectExpression") return
283
- 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)))
284
- if (keys.has("success") && keys.has("data")) context.report({ node: value, messageId: "literal" })
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) return true
298
- return checker.getIndexInfosOfType(type).some((info) => (info.type.flags & ts.TypeFlags.Unknown) !== 0)
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))) return {}
316
- const { checker, toTs } = typed(context)
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") return context.report({ node, messageId: "scalar", data: { name: importedName } })
319
- if (source === "graphql-scalars" && JSON_SCALARS.has(importedName)) return context.report({ node, messageId: "scalar", data: { name: importedName } })
320
- let symbol = checker.getSymbolAtLocation(toTs(local))
321
- if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0) symbol = checker.getAliasedSymbol(symbol)
322
- const origin = (symbol?.getDeclarations() ?? []).some((declaration) => /\/node_modules\/(?:graphql-type-json|graphql-scalars)\//.test(declaration.getSourceFile().fileName.replace(/\\/g, "/")) && (JSON_SCALARS.has(symbol.getName()) || symbol.getName() === "default"))
323
- if (origin) context.report({ node, messageId: "scalar", data: { name: importedName } })
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
- scalar(node, node.local, node.imported.type === "Identifier" ? node.imported.name : node.imported.value, node.parent.source.value)
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"))) continue
336
- const annotation = target.typeAnnotation?.typeAnnotation
337
- if (annotation && isUnknownBag(checker, checker.getTypeFromTypeNode(toTs(annotation)))) context.report({ node: target, messageId: "body" })
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") return
343
- const key = discriminant.computed ? (discriminant.property.type === "Literal" ? String(discriminant.property.value) : null) : discriminant.property.name
344
- if (key === "operation") context.report({ node: discriminant, messageId: "operation" })
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) return {}
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)) context.report({ node, messageId: "wrongSlot", data: { slot: slot ?? "none" } })
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") return {}
392
- const { program } = typed(context)
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") context.report({ node: source, messageId: "reversed", data: { specifier: value, tier } })
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) return
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) continue
421
- const route = (method.decorators ?? []).find((decorator) => isImportedFrom(context, decoratorCallee(decorator), "@nestjs/common", HTTP_ROUTES))
422
- if (route && !restExceptionEvidence(context, method) && !declared(method)) context.report({ node: route, messageId: "unjustified" })
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
+ };