@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
@@ -19,15 +19,14 @@
19
19
  * R265 resolves composition from types, including renamed constructors, factories, maps and scheduler tables. All
20
20
  * three rules ask the slot view which entry a file matches; none keeps a path of its own.
21
21
  */
22
- import { lineCount } from "./runtime/scripts/lib/line-count.mjs"
23
- import ts from "typescript"
24
- import { APP_ENV_ROLE, APP_OPTIONS_ROLE, appRoleOf } from "./lib/app-roles.mjs"
25
- import { hfsOf } from "./lib/hfs.mjs"
26
- import { isOwnedBy } from "./lib/declared.mjs"
27
- import { keyName, staticText } from "./lib/ast.mjs"
28
- import { isDeclarationFile, normalizePath } from "./lib/path.mjs"
29
- import { moduleOf, originsOfType, packageOfExport, typed } from "./lib/types.mjs"
30
-
22
+ import { lineCount } from "../runtime/scripts/lib/line-count.mjs";
23
+ import ts from "typescript";
24
+ import { APP_ENV_ROLE, APP_OPTIONS_ROLE, appRoleOf } from "./lib/app-roles.js";
25
+ import { hfsOf } from "./lib/hfs.js";
26
+ import { isOwnedBy } from "./lib/declared.js";
27
+ import { keyName, staticText } from "./lib/ast.js";
28
+ import { isDeclarationFile, normalizePath } from "./lib/path.js";
29
+ import { childNode, moduleOf, originsOfType, packageOfExport, resolvedSymbol as resolveAlias, typed } from "./lib/types.js";
31
30
  /** Static factories that register a Nest module (a dynamic module), a queue or a flow producer. */
32
31
  const REGISTRATION_CALLS = new Set([
33
32
  "register",
@@ -39,55 +38,53 @@ const REGISTRATION_CALLS = new Set([
39
38
  "registerQueue",
40
39
  "registerQueueAsync",
41
40
  "registerFlowProducer",
42
- ])
43
-
41
+ ]);
44
42
  /** Keys whose array value is a composition list whatever it holds. */
45
- const COMPOSITION_KEYS = new Set(["imports", "modules", "schedulers", "processors"])
46
-
43
+ const COMPOSITION_KEYS = new Set(["imports", "modules", "schedulers", "processors"]);
47
44
  /** A name that is a Nest module class. */
48
- const MODULE_NAME = /Module$/
45
+ const MODULE_NAME = /Module$/;
49
46
  /** A name that is a list of modules, queues, schedulers or processors (the operand of a spread). */
50
- const LIST_NAME = /(?:Modules|Queues|Schedulers|Processors)$/
47
+ const LIST_NAME = /(?:Modules|Queues|Schedulers|Processors)$/;
51
48
  /** A call that builds a scheduler entry or a queue registration: `orderExpirySchedulerOf(...)`, `ordersQueue(...)`. */
52
- const ENTRY_CALL = /(?:Scheduler|Queue)(?:Of)?$/
53
-
49
+ const ENTRY_CALL = /(?:Scheduler|Queue)(?:Of)?$/;
54
50
  /** Type-only wrappers do not change whether an expression composes modules. */
55
- const WRAPPERS = new Set(["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "TSInstantiationExpression", "ChainExpression"])
56
- const unwrap = (node) => {
57
- while (node && WRAPPERS.has(node.type)) node = node.expression
58
- return node
51
+ const WRAPPERS = new Set(["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "TSInstantiationExpression", "ChainExpression"]);
52
+ const isWrapper = (node) => node !== null && node !== undefined && WRAPPERS.has(node.type);
53
+ function unwrap(node) {
54
+ while (isWrapper(node))
55
+ node = node.expression;
56
+ return node;
59
57
  }
60
-
61
58
  /** The known name of a member, including a static computed string. */
62
- const memberName = (node) => node.computed ? staticText(node.property) : keyName(node.property)
63
-
59
+ const memberName = (node) => node.computed ? staticText(node.property) : keyName(node.property);
64
60
  /** The last name of an identifier or a statically named member expression, else null. */
65
61
  const lastName = (node) => {
66
- node = unwrap(node)
67
- if (node?.type === "Identifier") return node.name
68
- if (node?.type === "MemberExpression") return memberName(node)
69
- return null
70
- }
71
-
72
- /** What an array element composes (`module`, `registration`, `scheduler`, `list`), or null when it is plain options data. */
62
+ node = unwrap(node);
63
+ if (node?.type === "Identifier")
64
+ return node.name;
65
+ if (node?.type === "MemberExpression")
66
+ return memberName(node);
67
+ return null;
68
+ };
73
69
  const compositionOf = (element) => {
74
- element = unwrap(element)
75
- if (!element) return null
70
+ element = unwrap(element);
71
+ if (!element)
72
+ return null;
76
73
  if (element.type === "SpreadElement") {
77
- const argument = unwrap(element.argument)
78
- const spread = argument?.type === "CallExpression" ? lastName(argument.callee) : lastName(argument)
79
- return spread !== null && (LIST_NAME.test(spread) || MODULE_NAME.test(spread)) ? "list" : null
74
+ const argument = unwrap(element.argument);
75
+ const spread = argument?.type === "CallExpression" ? lastName(argument.callee) : lastName(argument);
76
+ return spread !== null && (LIST_NAME.test(spread) || MODULE_NAME.test(spread)) ? "list" : null;
80
77
  }
81
78
  if (element.type === "CallExpression") {
82
- const callee = unwrap(element.callee)
83
- if (callee.type === "MemberExpression" && REGISTRATION_CALLS.has(memberName(callee))) return "registration"
84
- const name = lastName(callee)
85
- return name !== null && ENTRY_CALL.test(name) ? "scheduler" : null
79
+ const callee = unwrap(element.callee);
80
+ if (callee.type === "MemberExpression" && REGISTRATION_CALLS.has(memberName(callee)))
81
+ return "registration";
82
+ const name = lastName(callee);
83
+ return name !== null && ENTRY_CALL.test(name) ? "scheduler" : null;
86
84
  }
87
- const name = lastName(element)
88
- return name !== null && MODULE_NAME.test(name) ? "module" : null
89
- }
90
-
85
+ const name = lastName(element);
86
+ return name !== null && MODULE_NAME.test(name) ? "module" : null;
87
+ };
91
88
  /** Env parsing and options bindings hold no module, queue or scheduler composition. */
92
89
  export const appOptionsCompositionFree = {
93
90
  meta: {
@@ -101,108 +98,135 @@ export const appOptionsCompositionFree = {
101
98
  },
102
99
  },
103
100
  create(context) {
104
- const filename = normalizePath(context.filename || context.getFilename())
105
- if (isDeclarationFile(filename)) return {}
106
- const role = appRoleOf(hfsOf(context), filename)?.entry
107
- if (role !== APP_OPTIONS_ROLE && role !== APP_ENV_ROLE) return {}
108
- const judged = new WeakSet()
101
+ const filename = normalizePath(context.filename || context.getFilename());
102
+ if (isDeclarationFile(filename))
103
+ return {};
104
+ const role = appRoleOf(hfsOf(context), filename)?.entry;
105
+ if (role !== APP_OPTIONS_ROLE && role !== APP_ENV_ROLE)
106
+ return {};
107
+ const judged = new WeakSet();
109
108
  return {
110
109
  CallExpression(node) {
111
- if (role !== APP_ENV_ROLE) return
112
- let element = node
113
- while (WRAPPERS.has(element.parent?.type)) element = element.parent
114
- if (element.parent?.type === "ArrayExpression") return
115
- const what = compositionOf(node)
116
- if (what !== "registration" && what !== "scheduler") return
117
- context.report({ node, messageId: "call", data: { what: what === "registration" ? "registration call" : "scheduler or queue call" } })
110
+ if (role !== APP_ENV_ROLE)
111
+ return;
112
+ let element = node;
113
+ while (isWrapper(element.parent))
114
+ element = element.parent;
115
+ if (element.parent?.type === "ArrayExpression")
116
+ return;
117
+ const what = compositionOf(node);
118
+ if (what !== "registration" && what !== "scheduler")
119
+ return;
120
+ context.report({ node, messageId: "call", data: { what: what === "registration" ? "registration call" : "scheduler or queue call" } });
118
121
  },
119
122
  Property(node) {
120
- const value = unwrap(node.value)
121
- if (value?.type !== "ArrayExpression") return
122
- const key = node.computed ? staticText(node.key) : keyName(node.key)
123
- if (key === null || !COMPOSITION_KEYS.has(key)) return
124
- judged.add(value)
125
- context.report({ node, messageId: "list", data: { key, role } })
123
+ const value = unwrap(node.value);
124
+ if (value?.type !== "ArrayExpression")
125
+ return;
126
+ const key = node.computed ? staticText(node.key) : keyName(node.key);
127
+ if (key === null || !COMPOSITION_KEYS.has(key))
128
+ return;
129
+ judged.add(value);
130
+ context.report({ node, messageId: "list", data: { key, role } });
126
131
  },
127
132
  "ArrayExpression:exit"(node) {
128
- if (judged.has(node)) return
129
- const what = node.elements.map(compositionOf).find((kind) => kind !== null)
130
- if (what === undefined) return
131
- const label = { module: "Nest module", registration: "module or queue registration", scheduler: "scheduler or queue entry", list: "spread of a module, queue or scheduler list" }[what]
132
- context.report({ node, messageId: "element", data: { what: label, role } })
133
+ if (judged.has(node))
134
+ return;
135
+ const what = node.elements.map(compositionOf).find((kind) => kind !== null);
136
+ if (what === undefined)
137
+ return;
138
+ const label = { module: "Nest module", registration: "module or queue registration", scheduler: "scheduler or queue entry", list: "spread of a module, queue or scheduler list" }[what];
139
+ context.report({ node, messageId: "element", data: { what: label, role } });
133
140
  },
134
- }
141
+ };
135
142
  },
136
- }
137
-
143
+ };
144
+ /** Whether a type is a reference to a generic type (it carries a `target`), the only kind `getTypeArguments` reads arguments from. */
145
+ const isTypeReference = (type) => "target" in type;
138
146
  /** Composition is a value's type, independent of the spelling of its class, factory or helper. */
139
147
  const compositionTypes = (checker) => {
140
148
  const propertyType = (type, name) => {
141
- const property = type.getProperty(name)
142
- const declaration = property?.valueDeclaration ?? property?.getDeclarations?.()?.[0]
143
- return declaration ? checker.getTypeOfSymbolAtLocation(property, declaration) : null
144
- }
145
- const constructor = (type) => (type?.getConstructSignatures().length ?? 0) > 0
146
- const dynamicModule = (type) => constructor(propertyType(type, "module"))
149
+ const property = type.getProperty(name);
150
+ const declaration = property?.valueDeclaration ?? property?.getDeclarations?.()?.[0];
151
+ return property && declaration ? checker.getTypeOfSymbolAtLocation(property, declaration) : null;
152
+ };
153
+ const constructor = (type) => (type?.getConstructSignatures().length ?? 0) > 0;
154
+ const dynamicModule = (type) => constructor(propertyType(type, "module"));
147
155
  const moduleConstructor = (type) => {
148
- if (!constructor(type)) return false
156
+ if (!constructor(type))
157
+ return false;
149
158
  for (const declaration of type.getSymbol()?.getDeclarations?.() ?? []) {
150
- if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration)) continue
159
+ if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration))
160
+ continue;
151
161
  for (const decorator of ts.getDecorators(declaration) ?? []) {
152
- const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
153
- const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(expression) ? expression.name : expression)
154
- const resolved = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
155
- if (resolved?.name === "Module" && resolved.getDeclarations()?.some((origin) => moduleOf(origin, normalizePath(origin.getSourceFile().fileName)) === "@nestjs/common")) return true
162
+ const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
163
+ const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(expression) ? expression.name : expression);
164
+ const resolved = resolveAlias(checker, symbol);
165
+ if (resolved?.name === "Module" && resolved.getDeclarations()?.some((origin) => moduleOf(origin, normalizePath(origin.getSourceFile().fileName)) === "@nestjs/common"))
166
+ return true;
156
167
  }
157
168
  }
158
169
  // A factory returning DynamicModule identifies a module even if it has no decorator or conventional name.
159
170
  return type.getProperties().some((property) => {
160
- const factory = propertyType(type, property.name)
161
- return factory?.getCallSignatures().some((signature) => dynamicModule(checker.getReturnTypeOfSignature(signature)))
162
- })
163
- }
171
+ const factory = propertyType(type, property.name);
172
+ return factory?.getCallSignatures().some((signature) => dynamicModule(checker.getReturnTypeOfSignature(signature)));
173
+ });
174
+ };
164
175
  const arrayElement = (type) => checker.isArrayType(type) || checker.isTupleType(type)
165
176
  ? checker.getIndexTypeOfType(type, ts.IndexKind.Number)
166
- : type.getSymbol()?.name === "ReadonlyArray" ? checker.getTypeArguments(type)[0] : null
167
- const MAX_DEPTH = 12
177
+ : type.getSymbol()?.name === "ReadonlyArray" ? (isTypeReference(type) ? checker.getTypeArguments(type)[0] : undefined) : null;
178
+ const MAX_DEPTH = 12;
168
179
  const contains = (type, constructors = false, seen = new Set(), depth = 0) => {
169
180
  // A library type graph (the application, an HTTP adapter) can be deep and cyclic through member types: a bounded walk never overflows the stack.
170
- if (depth > MAX_DEPTH) return false
171
- if (!type || seen.has(type) || type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.TypeParameter)) return false
172
- seen.add(type)
173
- if (type.isUnionOrIntersection()) return type.types.some((part) => contains(part, constructors, new Set(seen), depth + 1))
181
+ if (depth > MAX_DEPTH)
182
+ return false;
183
+ if (!type || seen.has(type) || type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.TypeParameter))
184
+ return false;
185
+ seen.add(type);
186
+ if (type.isUnionOrIntersection())
187
+ return type.types.some((part) => contains(part, constructors, new Set(seen), depth + 1));
174
188
  // Async bootstrap returns Promise<void>; walk its result rather than recursively instantiating .then/.catch.
175
- const awaited = checker.getAwaitedType(type)
176
- if (awaited && awaited !== type) return contains(awaited, constructors, seen, depth + 1)
177
- const origins = originsOfType(checker, type)
178
- if (origins.some((origin) => origin.module === "@nestjs/common" && ["DynamicModule", "Type", "Provider"].includes(origin.name))) return true
179
- if (constructor(type)) return constructors || moduleConstructor(type)
180
- if (dynamicModule(type)) return true
181
- const properties = new Set(type.getProperties().map((property) => property.name))
182
- if (properties.has("provide") && ["useClass", "useFactory", "useValue", "useExisting"].some((key) => properties.has(key))) return true
183
- if (properties.has("queue") && ["cron", "everyMs", "pattern", "repeat"].some((key) => properties.has(key))) return true
189
+ const awaited = checker.getAwaitedType(type);
190
+ if (awaited && awaited !== type)
191
+ return contains(awaited, constructors, seen, depth + 1);
192
+ const origins = originsOfType(checker, type);
193
+ if (origins.some((origin) => origin.module === "@nestjs/common" && ["DynamicModule", "Type", "Provider"].includes(origin.name)))
194
+ return true;
195
+ if (constructor(type))
196
+ return constructors || moduleConstructor(type);
197
+ if (dynamicModule(type))
198
+ return true;
199
+ const properties = new Set(type.getProperties().map((property) => property.name));
200
+ if (properties.has("provide") && ["useClass", "useFactory", "useValue", "useExisting"].some((key) => properties.has(key)))
201
+ return true;
202
+ if (properties.has("queue") && ["cron", "everyMs", "pattern", "repeat"].some((key) => properties.has(key)))
203
+ return true;
184
204
  // Primitive options values and their library methods never compose an app.
185
- if (!(type.flags & ts.TypeFlags.Object)) return false
186
- const element = arrayElement(type)
187
- if (element) return contains(element, true, seen, depth + 1)
205
+ if (!(type.flags & ts.TypeFlags.Object))
206
+ return false;
207
+ const element = arrayElement(type);
208
+ if (element)
209
+ return contains(element, true, seen, depth + 1);
188
210
  // Index signatures retain the Type<unknown> contract of a module map, unlike a plain adapter port map.
189
211
  for (const index of checker.getIndexInfosOfType(type)) {
190
- if (contains(index.type, false, new Set(seen), depth + 1)) return true
212
+ if (contains(index.type, false, new Set(seen), depth + 1))
213
+ return true;
191
214
  }
192
215
  for (const signature of type.getCallSignatures()) {
193
- if (contains(checker.getReturnTypeOfSignature(signature), false, new Set(seen), depth + 1)) return true
216
+ if (contains(checker.getReturnTypeOfSignature(signature), false, new Set(seen), depth + 1))
217
+ return true;
194
218
  }
195
- return type.getProperties().some((property) => contains(propertyType(type, property.name), false, new Set(seen), depth + 1))
196
- }
219
+ return type.getProperties().some((property) => contains(propertyType(type, property.name), false, new Set(seen), depth + 1));
220
+ };
197
221
  const typedList = (type) => {
198
- const element = arrayElement(type)
199
- if (!element || element.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) return false
200
- const parts = element.isUnion() ? element.types : [element]
201
- return parts.every((part) => contains(part, true))
202
- }
203
- return { arrayElement, contains, typedList }
204
- }
205
-
222
+ const element = arrayElement(type);
223
+ if (!element || element.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
224
+ return false;
225
+ const parts = element.isUnion() ? element.types : [element];
226
+ return parts.every((part) => contains(part, true));
227
+ };
228
+ return { arrayElement, contains, typedList };
229
+ };
206
230
  /** R265: app values compose only in typed groups, never in env/options/bootstrap lists. */
207
231
  export const appCompositionTyped = {
208
232
  meta: {
@@ -216,125 +240,169 @@ export const appCompositionTyped = {
216
240
  },
217
241
  },
218
242
  create(context) {
219
- const filename = normalizePath(context.filename || context.getFilename())
220
- if (isDeclarationFile(filename)) return {}
221
- const role = appRoleOf(hfsOf(context), filename)?.entry
222
- if (![APP_ENV_ROLE, APP_OPTIONS_ROLE, "main.ts", "compose/<area>.ts"].includes(role)) return {}
223
- const { checker, toTs } = typed(context)
224
- const { arrayElement, contains, typedList } = compositionTypes(checker)
225
- const reported = new WeakSet()
243
+ const filename = normalizePath(context.filename || context.getFilename());
244
+ if (isDeclarationFile(filename))
245
+ return {};
246
+ const role = appRoleOf(hfsOf(context), filename)?.entry;
247
+ const typedRoles = [APP_ENV_ROLE, APP_OPTIONS_ROLE, "main.ts", "compose/<area>.ts"];
248
+ if (!typedRoles.includes(role))
249
+ return {};
250
+ const { checker, toTs } = typed(context);
251
+ const { arrayElement, contains, typedList } = compositionTypes(checker);
252
+ const reported = new WeakSet();
226
253
  const hasReport = (node) => {
227
- for (let ancestor = node; ancestor; ancestor = ancestor.parent) if (reported.has(ancestor)) return true
228
- return false
229
- }
254
+ for (let ancestor = node; ancestor; ancestor = ancestor.parent)
255
+ if (reported.has(ancestor))
256
+ return true;
257
+ return false;
258
+ };
230
259
  const report = (node, messageId) => {
231
- if (hasReport(node)) return
232
- reported.add(node)
233
- context.report({ node, messageId, data: { role } })
234
- }
235
- const typeOf = (node) => checker.getTypeAtLocation(toTs(node))
260
+ if (hasReport(node))
261
+ return;
262
+ reported.add(node);
263
+ context.report({ node, messageId, data: { role } });
264
+ };
265
+ const typeOf = (node) => checker.getTypeAtLocation(toTs(node));
266
+ const bootCalls = ["create", "createApplicationContext", "createMicroservice"];
236
267
  const bootstrapArgument = (node) => {
237
268
  // The root module's registration belongs here; inline lists and metadata still belong in compose/.
238
- if (role !== "main.ts" || node.type !== "CallExpression") return false
239
- let expression = node
240
- while (WRAPPERS.has(expression.parent?.type)) expression = expression.parent
241
- const parent = expression.parent
242
- if (parent?.type !== "CallExpression" || !parent.arguments.includes(expression) || parent.callee.type !== "MemberExpression") return false
243
- const owner = (callee) => packageOfExport(context, callee) ?? packageOfExport(context, callee.object)
269
+ if (role !== "main.ts" || node.type !== "CallExpression")
270
+ return false;
271
+ let expression = node;
272
+ while (isWrapper(expression.parent))
273
+ expression = expression.parent;
274
+ const parent = expression.parent;
275
+ if (parent?.type !== "CallExpression" || !parent.arguments.some((argument) => argument === expression) || parent.callee.type !== "MemberExpression")
276
+ return false;
277
+ const owner = (callee) => packageOfExport(context, callee) ?? packageOfExport(context, callee.object);
244
278
  // An api boots through NestFactory; a cli app boots its root module through nest-commander's CommandFactory.run (R148).
245
- return (["create", "createApplicationContext", "createMicroservice"].includes(memberName(parent.callee)) && owner(parent.callee) === "@nestjs/core")
246
- || (memberName(parent.callee) === "run" && parent.arguments[0] === expression && owner(parent.callee) === "nest-commander")
247
- }
279
+ return (bootCalls.includes(memberName(parent.callee)) && owner(parent.callee) === "@nestjs/core")
280
+ || (memberName(parent.callee) === "run" && parent.arguments[0] === expression && owner(parent.callee) === "nest-commander");
281
+ };
248
282
  const checkValue = (node) => {
249
- if (role === "compose/<area>.ts" || hasReport(node) || bootstrapArgument(node)) return
250
- if (contains(typeOf(node))) report(node, "outside")
251
- }
283
+ if (role === "compose/<area>.ts" || hasReport(node) || bootstrapArgument(node))
284
+ return;
285
+ if (contains(typeOf(node)))
286
+ report(node, "outside");
287
+ };
252
288
  const checkGroup = (node, value, annotation) => {
253
- if (role !== "compose/<area>.ts") return
254
- const type = typeOf(value)
255
- const signatures = type.getCallSignatures()
256
- const result = signatures.length ? checker.getReturnTypeOfSignature(signatures[0]) : type
289
+ if (role !== "compose/<area>.ts")
290
+ return;
291
+ const type = typeOf(value);
292
+ const signatures = type.getCallSignatures();
293
+ const first = signatures[0];
294
+ const result = first ? checker.getReturnTypeOfSignature(first) : type;
257
295
  if (signatures.length && !arrayElement(result) && !contains(result)) {
258
- report(node, "business")
259
- return
296
+ report(node, "business");
297
+ return;
260
298
  }
261
- if (!annotation || !typedList(result)) report(node, "group")
262
- }
299
+ if (!annotation || !typedList(result))
300
+ report(node, "group");
301
+ };
263
302
  const annotationOf = (node) => {
264
- if (!node) return null
265
- if (node.type === "TSSatisfiesExpression") return node.typeAnnotation
266
- if (WRAPPERS.has(node.type)) return annotationOf(node.expression)
267
- if (node.type === "VariableDeclarator") return node.id.typeAnnotation ?? annotationOf(node.init)
268
- if (node.returnType) return node.returnType
269
- if (node.type !== "Identifier") return null
270
- const symbol = checker.getSymbolAtLocation(toTs(node))
271
- const resolved = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
303
+ if (!node)
304
+ return null;
305
+ if (node.type === "TSSatisfiesExpression")
306
+ return node.typeAnnotation;
307
+ if (isWrapper(node))
308
+ return annotationOf(node.expression);
309
+ if (node.type === "VariableDeclarator")
310
+ return node.id.typeAnnotation ?? annotationOf(node.init);
311
+ if ("returnType" in node && node.returnType)
312
+ return node.returnType;
313
+ if (node.type !== "Identifier")
314
+ return null;
315
+ const symbol = checker.getSymbolAtLocation(toTs(node));
316
+ const resolved = resolveAlias(checker, symbol);
272
317
  return resolved?.getDeclarations()?.some((declaration) => {
273
- const initializer = declaration.initializer
274
- return declaration.type || initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer) || ts.isSatisfiesExpression(initializer)) && initializer.type
275
- }) ?? false
276
- }
318
+ const initializer = childNode(declaration, "initializer");
319
+ return childNode(declaration, "type") || initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer) || ts.isSatisfiesExpression(initializer)) && initializer.type;
320
+ }) ?? false;
321
+ };
277
322
  return {
278
323
  ExportNamedDeclaration(node) {
279
- if (role !== "compose/<area>.ts" || node.exportKind === "type") return
280
- const declaration = node.declaration
324
+ if (role !== "compose/<area>.ts" || node.exportKind === "type")
325
+ return;
326
+ const declaration = node.declaration;
281
327
  if (!declaration) {
282
328
  for (const specifier of node.specifiers) {
283
- if (specifier.exportKind !== "type") checkGroup(specifier, specifier.local, annotationOf(specifier.local))
329
+ if (specifier.exportKind !== "type")
330
+ checkGroup(specifier, specifier.local, annotationOf(specifier.local));
284
331
  }
285
- return
332
+ return;
286
333
  }
287
- if (declaration.type === "FunctionDeclaration" && declaration.body) checkGroup(declaration, declaration, declaration.returnType)
288
- if (declaration.type !== "VariableDeclaration") return
334
+ if (declaration.type === "FunctionDeclaration" && declaration.body)
335
+ checkGroup(declaration, declaration, declaration.returnType);
336
+ if (declaration.type !== "VariableDeclaration")
337
+ return;
289
338
  for (const binding of declaration.declarations) {
290
- if (!binding.init) continue
291
- checkGroup(binding, binding.id, annotationOf(binding))
339
+ if (!binding.init)
340
+ continue;
341
+ checkGroup(binding, binding.id, annotationOf(binding));
292
342
  }
293
343
  },
294
344
  ExportDefaultDeclaration(node) {
295
- if (role === "compose/<area>.ts") checkGroup(node, node.declaration, annotationOf(node.declaration))
345
+ if (role === "compose/<area>.ts")
346
+ checkGroup(node, node.declaration, annotationOf(node.declaration));
296
347
  },
297
348
  VariableDeclarator(node) {
298
- if (node.init) checkValue(node.init)
349
+ if (node.init)
350
+ checkValue(node.init);
299
351
  },
300
352
  FunctionDeclaration(node) {
301
- if (node.body && role !== "compose/<area>.ts" && contains(typeOf(node))) report(node, "outside")
353
+ if (node.body && role !== "compose/<area>.ts" && contains(typeOf(node)))
354
+ report(node, "outside");
302
355
  },
303
356
  ArrowFunctionExpression(node) {
304
- if (role !== "compose/<area>.ts" || hasReport(node)) return
305
- const signature = typeOf(node).getCallSignatures()[0]
306
- if (signature && !contains(checker.getReturnTypeOfSignature(signature))) report(node, "business")
357
+ if (role !== "compose/<area>.ts" || hasReport(node))
358
+ return;
359
+ const signature = typeOf(node).getCallSignatures()[0];
360
+ if (signature && !contains(checker.getReturnTypeOfSignature(signature)))
361
+ report(node, "business");
307
362
  },
308
- IfStatement(node) { if (role === "compose/<area>.ts") report(node, "business") },
309
- SwitchStatement(node) { if (role === "compose/<area>.ts") report(node, "business") },
310
- ConditionalExpression(node) { if (role === "compose/<area>.ts") report(node, "business") },
311
- ForStatement(node) { if (role === "compose/<area>.ts") report(node, "business") },
312
- ForOfStatement(node) { if (role === "compose/<area>.ts") report(node, "business") },
313
- WhileStatement(node) { if (role === "compose/<area>.ts") report(node, "business") },
363
+ IfStatement(node) { if (role === "compose/<area>.ts")
364
+ report(node, "business"); },
365
+ SwitchStatement(node) { if (role === "compose/<area>.ts")
366
+ report(node, "business"); },
367
+ ConditionalExpression(node) { if (role === "compose/<area>.ts")
368
+ report(node, "business"); },
369
+ ForStatement(node) { if (role === "compose/<area>.ts")
370
+ report(node, "business"); },
371
+ ForOfStatement(node) { if (role === "compose/<area>.ts")
372
+ report(node, "business"); },
373
+ WhileStatement(node) { if (role === "compose/<area>.ts")
374
+ report(node, "business"); },
314
375
  ArrayExpression: checkValue,
315
376
  ObjectExpression: checkValue,
316
377
  CallExpression: checkValue,
317
378
  ReturnStatement(node) {
318
- if (node.argument) checkValue(node.argument)
379
+ if (node.argument)
380
+ checkValue(node.argument);
319
381
  },
320
- }
382
+ };
321
383
  },
322
- }
323
-
384
+ };
324
385
  /** Resolve an imported or local binding without relying on its local spelling. */
325
386
  const resolvedSymbol = (checker, node) => {
326
- const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node)
327
- return symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
328
- }
329
-
387
+ const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node);
388
+ return resolveAlias(checker, symbol);
389
+ };
390
+ /** Whether a value is a TypeScript symbol (it carries numeric `flags` and an `escapedName`). */
391
+ const isSymbol = (value) => typeof value === "object" && value !== null && "flags" in value && typeof value.flags === "number" && "escapedName" in value;
392
+ /** The symbol the binder gave a node (a module's own symbol for an external-module source file), if any. */
393
+ const ownSymbol = (node) => {
394
+ const value = Reflect.get(node, "symbol");
395
+ return isSymbol(value) ? value : undefined;
396
+ };
330
397
  /** The app's declared name comes from its matching env filename, not its kind's slot name. */
331
398
  const appEnvNames = (filename, role) => {
332
- const root = filename.slice(0, filename.lastIndexOf("/"))
333
- const app = role === APP_ENV_ROLE ? filename.split("/").at(-1).slice(0, -".env.ts".length) : root.split("/").at(-2)
334
- const pascal = app.replace(/(?:^|[-_])([a-z\d])/g, (_, letter) => letter.toUpperCase())
335
- return { file: `${root}/${app}.env.ts`, reader: `read${pascal}Env` }
336
- }
337
-
399
+ const root = filename.slice(0, filename.lastIndexOf("/"));
400
+ const app = role === APP_ENV_ROLE ? (filename.split("/").at(-1) ?? "").slice(0, -".env.ts".length) : root.split("/").at(-2);
401
+ if (app === undefined)
402
+ throw new TypeError("Cannot read properties of undefined (reading 'replace')");
403
+ const pascal = app.replace(/(?:^|[-_])([a-z\d])/g, (_, letter) => letter.toUpperCase());
404
+ return { file: `${root}/${app}.env.ts`, reader: `read${pascal}Env` };
405
+ };
338
406
  /** R289: the typed app env reader owns parsing; main acquires one source and delegates once. */
339
407
  export const appEnvRequired = {
340
408
  meta: {
@@ -348,79 +416,98 @@ export const appEnvRequired = {
348
416
  },
349
417
  },
350
418
  create(context) {
351
- const filename = normalizePath(context.filename || context.getFilename())
352
- if (isDeclarationFile(filename)) return {}
353
- const hfs = hfsOf(context)
354
- const role = appRoleOf(hfs, filename)?.entry
355
- if (role !== APP_ENV_ROLE && role !== "main.ts") return {}
356
- const { checker, toTs } = typed(context)
357
- const names = appEnvNames(filename, role)
358
- const ownedEnv = (type) => originsOfType(checker, type).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"))
359
- const envValue = (node) => node && ownedEnv(checker.getTypeAtLocation(toTs(node)))
419
+ const filename = normalizePath(context.filename || context.getFilename());
420
+ if (isDeclarationFile(filename))
421
+ return {};
422
+ const hfs = hfsOf(context);
423
+ const role = appRoleOf(hfs, filename)?.entry;
424
+ if (role !== APP_ENV_ROLE && role !== "main.ts")
425
+ return {};
426
+ const { checker, toTs } = typed(context);
427
+ const names = appEnvNames(filename, role);
428
+ const ownedEnv = (type) => originsOfType(checker, type).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"));
429
+ const envValue = (node) => node && ownedEnv(checker.getTypeAtLocation(toTs(node)));
360
430
  const matchingReader = (node) => {
361
- const symbol = resolvedSymbol(checker, toTs(node))
362
- return symbol?.name === names.reader && symbol.getDeclarations()?.some((declaration) => normalizePath(declaration.getSourceFile().fileName) === names.file)
363
- }
431
+ const symbol = resolvedSymbol(checker, toTs(node));
432
+ return symbol?.name === names.reader && symbol.getDeclarations()?.some((declaration) => normalizePath(declaration.getSourceFile().fileName) === names.file);
433
+ };
364
434
  const envContract = (node) => {
365
- const source = toTs(node)
366
- if (!source.symbol) return false
367
- const exported = checker.getExportsOfModule(source.symbol)
368
- const reader = exported.find((symbol) => symbol.name === names.reader)
369
- const declaration = reader?.valueDeclaration ?? reader?.getDeclarations()?.[0]
370
- if (!declaration) return false
371
- const signatures = checker.getTypeOfSymbolAtLocation(reader, declaration).getCallSignatures()
435
+ const source = toTs(node);
436
+ const moduleSymbol = ownSymbol(source);
437
+ if (!moduleSymbol)
438
+ return false;
439
+ const exported = checker.getExportsOfModule(moduleSymbol);
440
+ const reader = exported.find((symbol) => symbol.name === names.reader);
441
+ const declaration = reader?.valueDeclaration ?? reader?.getDeclarations()?.[0];
442
+ if (!reader || !declaration)
443
+ return false;
444
+ const signatures = checker.getTypeOfSymbolAtLocation(reader, declaration).getCallSignatures();
372
445
  return signatures.some((signature) => {
373
- const parameters = signature.getParameters()
374
- if (parameters.length !== 1 || !signature.declaration?.type) return false
375
- const parameter = parameters[0]
376
- if (!parameter.valueDeclaration?.type || !ownedEnv(checker.getTypeOfSymbolAtLocation(parameter, parameter.valueDeclaration))) return false
377
- const result = checker.getReturnTypeOfSignature(signature)
446
+ const parameters = signature.getParameters();
447
+ if (parameters.length !== 1 || !signature.declaration?.type)
448
+ return false;
449
+ const parameter = parameters[0];
450
+ const valueDeclaration = parameter?.valueDeclaration;
451
+ if (!parameter || !valueDeclaration || !childNode(valueDeclaration, "type") || !ownedEnv(checker.getTypeOfSymbolAtLocation(parameter, valueDeclaration)))
452
+ return false;
453
+ const result = checker.getReturnTypeOfSignature(signature);
378
454
  return result.getSymbol()?.getDeclarations()?.some((item) => ts.isInterfaceDeclaration(item)
379
- && item.getSourceFile() === source && exported.some((symbol) => symbol.name === item.name.text))
380
- })
381
- }
382
- let sources = 0
383
- let delegates = 0
384
- let inline = false
385
- const reported = new WeakSet()
455
+ && item.getSourceFile() === source && exported.some((symbol) => symbol.name === item.name.text));
456
+ });
457
+ };
458
+ let sources = 0;
459
+ let delegates = 0;
460
+ let inline = false;
461
+ const reported = new WeakSet();
386
462
  const reportInline = (node) => {
387
- for (let parent = node; parent; parent = parent.parent) if (reported.has(parent)) return
388
- reported.add(node)
389
- inline = true
390
- context.report({ node, messageId: "inline" })
391
- }
463
+ for (let parent = node; parent; parent = parent.parent)
464
+ if (reported.has(parent))
465
+ return;
466
+ reported.add(node);
467
+ inline = true;
468
+ context.report({ node, messageId: "inline" });
469
+ };
392
470
  return {
393
471
  CallExpression(node) {
394
- if (role !== "main.ts") return
395
- const declaration = checker.getResolvedSignature(toTs(node))?.declaration
472
+ if (role !== "main.ts")
473
+ return;
474
+ const declaration = checker.getResolvedSignature(toTs(node))?.declaration;
396
475
  if (declaration && ts.isMethodDeclaration(declaration) && declaration.name.getText() === "fromProcess"
397
476
  && envValue(node) && isOwnedBy(hfs, normalizePath(declaration.getSourceFile().fileName), "platform", "config")) {
398
- sources += 1
399
- if (sources > 1 || node.arguments.length) reportInline(node)
400
- return
477
+ sources += 1;
478
+ if (sources > 1 || node.arguments.length)
479
+ reportInline(node);
480
+ return;
401
481
  }
402
482
  if (matchingReader(node.callee) && node.arguments.length === 1 && envValue(node.arguments[0])) {
403
- delegates += 1
404
- if (delegates > 1) reportInline(node)
405
- return
483
+ delegates += 1;
484
+ if (delegates > 1)
485
+ reportInline(node);
486
+ return;
406
487
  }
407
- const callee = unwrap(node.callee)
408
- if (callee.type === "MemberExpression" && envValue(callee.object) || node.arguments.some(envValue)) reportInline(node)
488
+ const callee = unwrap(node.callee);
489
+ if (callee.type === "MemberExpression" && envValue(callee.object) || node.arguments.some(envValue))
490
+ reportInline(node);
409
491
  },
410
492
  MemberExpression(node) {
411
- if (role !== "main.ts") return
412
- if (memberName(node) === "env" && lastName(node.object) === "process") reportInline(node)
413
- if (envValue(node.object) && !node.parent?.type.startsWith("CallExpression") && memberName(node) !== "fromProcess") reportInline(node)
493
+ if (role !== "main.ts")
494
+ return;
495
+ if (memberName(node) === "env" && lastName(node.object) === "process")
496
+ reportInline(node);
497
+ if (envValue(node.object) && !node.parent?.type.startsWith("CallExpression") && memberName(node) !== "fromProcess")
498
+ reportInline(node);
414
499
  },
415
500
  "Program:exit"(node) {
416
501
  if (role === APP_ENV_ROLE) {
417
- if (!envContract(node)) context.report({ node, messageId: "shape", data: names })
418
- } else if (!inline && (sources !== 1 || delegates !== 1)) context.report({ node, messageId: "delegate", data: names })
502
+ if (!envContract(node))
503
+ context.report({ node, messageId: "shape", data: names });
504
+ }
505
+ else if (!inline && (sources !== 1 || delegates !== 1))
506
+ context.report({ node, messageId: "delegate", data: names });
419
507
  },
420
- }
508
+ };
421
509
  },
422
- }
423
-
510
+ };
424
511
  /** R289: module lists in the app root contain only spreads of its own compose groups. */
425
512
  export const appModuleListInline = {
426
513
  meta: {
@@ -432,43 +519,51 @@ export const appModuleListInline = {
432
519
  },
433
520
  },
434
521
  create(context) {
435
- const filename = normalizePath(context.filename || context.getFilename())
436
- if (isDeclarationFile(filename)) return {}
437
- const hfs = hfsOf(context)
438
- if (appRoleOf(hfs, filename)?.entry !== "app.module.ts") return {}
439
- const { checker, toTs } = typed(context)
440
- const { contains } = compositionTypes(checker)
441
- const composeRoot = filename.slice(0, filename.lastIndexOf("/")) + "/compose/"
522
+ const filename = normalizePath(context.filename || context.getFilename());
523
+ if (isDeclarationFile(filename))
524
+ return {};
525
+ const hfs = hfsOf(context);
526
+ if (appRoleOf(hfs, filename)?.entry !== "app.module.ts")
527
+ return {};
528
+ const { checker, toTs } = typed(context);
529
+ const { contains } = compositionTypes(checker);
530
+ const composeRoot = filename.slice(0, filename.lastIndexOf("/")) + "/compose/";
442
531
  const groupSpread = (node) => {
443
- if (node.type !== "SpreadElement") return false
444
- const value = unwrap(node.argument)
445
- const reference = value.type === "CallExpression" ? unwrap(value.callee) : value
446
- const symbol = resolvedSymbol(checker, toTs(reference))
532
+ if (node.type !== "SpreadElement")
533
+ return false;
534
+ const value = unwrap(node.argument);
535
+ const reference = value.type === "CallExpression" ? unwrap(value.callee) : value;
536
+ const symbol = resolvedSymbol(checker, toTs(reference));
447
537
  return symbol?.getDeclarations()?.some((declaration) => {
448
- const file = normalizePath(declaration.getSourceFile().fileName)
449
- return file.startsWith(composeRoot) && appRoleOf(hfs, file)?.entry === "compose/<area>.ts"
450
- }) ?? false
451
- }
452
- const globalProvider = (node) => {
453
- node = unwrap(node)
454
- if (node?.type !== "ObjectExpression") return false
455
- const binding = node.properties.find((property) => property.type === "Property" && keyName(property.key) === "provide")
456
- const value = binding && unwrap(binding.value)
457
- if (!value || !["APP_GUARD", "APP_FILTER"].includes(resolvedSymbol(checker, toTs(value))?.name)) return false
458
- return packageOfExport(context, value) === "@nestjs/core"
459
- }
538
+ const file = normalizePath(declaration.getSourceFile().fileName);
539
+ return file.startsWith(composeRoot) && appRoleOf(hfs, file)?.entry === "compose/<area>.ts";
540
+ }) ?? false;
541
+ };
542
+ const providerTokens = ["APP_GUARD", "APP_FILTER"];
543
+ const globalProvider = (element) => {
544
+ const node = unwrap(element);
545
+ if (node?.type !== "ObjectExpression")
546
+ return false;
547
+ const binding = node.properties.find((property) => property.type === "Property" && keyName(property.key) === "provide");
548
+ const value = binding && unwrap(binding.value);
549
+ if (!value || !providerTokens.includes(resolvedSymbol(checker, toTs(value))?.name))
550
+ return false;
551
+ return packageOfExport(context, value) === "@nestjs/core";
552
+ };
460
553
  return {
461
554
  ArrayExpression(node) {
462
- const parent = node.parent
463
- const key = parent?.type === "Property" ? parent.computed ? staticText(parent.key) : keyName(parent.key) : null
464
- if (![...COMPOSITION_KEYS, "providers"].includes(key) && !contains(checker.getTypeAtLocation(toTs(node)))) return
465
- const violation = node.elements.find((element) => !element || !groupSpread(element) && !(key === "providers" && globalProvider(element)))
466
- if (violation || node.elements.includes(null)) context.report({ node: violation ?? node, messageId: "inline" })
555
+ const parent = node.parent;
556
+ const key = parent?.type === "Property" ? parent.computed ? staticText(parent.key) : keyName(parent.key) : null;
557
+ const listKeys = [...COMPOSITION_KEYS, "providers"];
558
+ if (!listKeys.includes(key) && !contains(checker.getTypeAtLocation(toTs(node))))
559
+ return;
560
+ const violation = node.elements.find((element) => !element || !groupSpread(element) && !(key === "providers" && globalProvider(element)));
561
+ if (violation || node.elements.includes(null))
562
+ context.report({ node: violation ?? node, messageId: "inline" });
467
563
  },
468
- }
564
+ };
469
565
  },
470
- }
471
-
566
+ };
472
567
  /** Each composition file of an app stays within the line budget its app slot names. */
473
568
  export const appFileBudget = {
474
569
  meta: {
@@ -480,28 +575,30 @@ export const appFileBudget = {
480
575
  },
481
576
  },
482
577
  create(context) {
483
- const filename = normalizePath(context.filename || context.getFilename())
484
- if (isDeclarationFile(filename)) return {}
485
- const hfs = hfsOf(context)
486
- const role = appRoleOf(hfs, filename)
487
- const max = role ? hfs.slot(role.slot)?.budget?.[role.entry] : undefined
488
- if (!Number.isInteger(max)) return {}
578
+ const filename = normalizePath(context.filename || context.getFilename());
579
+ if (isDeclarationFile(filename))
580
+ return {};
581
+ const hfs = hfsOf(context);
582
+ const role = appRoleOf(hfs, filename);
583
+ const max = role ? hfs.slot(role.slot)?.budget?.[role.entry] : undefined;
584
+ if (!role || max === undefined || !Number.isInteger(max))
585
+ return {};
489
586
  const fix = role.entry === APP_ENV_ROLE
490
587
  ? "Keep typed, fail-fast environment parsing only here; move module composition into `compose/<area>.ts` and business code into its owning module."
491
588
  : role.entry === APP_OPTIONS_ROLE
492
- ? "Keep options types and port bindings here; move environment parsing into `<app>.env.ts` and module, queue or scheduler lists into `compose/<area>.ts`."
493
- : role.entry === "main.ts"
494
- ? "Move environment parsing into `<app>.env.ts` and module composition into `compose/<area>.ts`; keep the bootstrap here."
495
- : "Move one area of the composition into its own group `apps/<app>/src/compose/<area>.ts` and spread it in `app.module.ts`."
589
+ ? "Keep options types and port bindings here; move environment parsing into `<app>.env.ts` and module, queue or scheduler lists into `compose/<area>.ts`."
590
+ : role.entry === "main.ts"
591
+ ? "Move environment parsing into `<app>.env.ts` and module composition into `compose/<area>.ts`; keep the bootstrap here."
592
+ : "Move one area of the composition into its own group `apps/<app>/src/compose/<area>.ts` and spread it in `app.module.ts`.";
496
593
  return {
497
594
  "Program:exit"(node) {
498
- const lines = lineCount((context.sourceCode || context.getSourceCode()).text)
499
- if (lines > max) context.report({ node, loc: { line: 1, column: 0 }, messageId: "over", data: { role: role.entry, lines, max, slot: role.slot, fix } })
595
+ const lines = lineCount((context.sourceCode || context.getSourceCode()).text);
596
+ if (lines > max)
597
+ context.report({ node, loc: { line: 1, column: 0 }, messageId: "over", data: { role: role.entry, lines, max, slot: role.slot, fix } });
500
598
  },
501
- }
599
+ };
502
600
  },
503
- }
504
-
601
+ };
505
602
  /** The rules this law contributes to the plugin. */
506
603
  export const rules = {
507
604
  "app-options-composition-free": appOptionsCompositionFree,
@@ -509,8 +606,7 @@ export const rules = {
509
606
  "app-env-required": appEnvRequired,
510
607
  "app-module-list-inline": appModuleListInline,
511
608
  "app-file-budget": appFileBudget,
512
- }
513
-
609
+ };
514
610
  /** Every rule starts at error; an app already over a budget migrates its lists into compose/. */
515
611
  export const recommended = {
516
612
  "starci-be/app-options-composition-free": "error",
@@ -518,4 +614,4 @@ export const recommended = {
518
614
  "starci-be/app-env-required": "error",
519
615
  "starci-be/app-module-list-inline": "error",
520
616
  "starci-be/app-file-budget": "error",
521
- }
617
+ };