@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
@@ -1,325 +1,351 @@
1
1
  /** BE-IDEMPOTENCY-3: marked client commands preserve their key and execute through the transactional inbox. */
2
- import ts from "typescript"
3
- import { hfsOf } from "./hfs.mjs"
4
- import { baseName, ownerNameOf } from "./ports.mjs"
5
- import { moduleOf, originsOfType, typed } from "./types.mjs"
6
- import { isTransportSlot } from "./transport-slots.mjs"
7
-
2
+ import ts from "typescript";
3
+ import { hfsOf } from "./hfs.js";
4
+ import { baseName, ownerNameOf } from "./ports.js";
5
+ import { childNode, moduleOf, originsOfType, resolvedSymbol, typed } from "./types.js";
6
+ import { isTransportSlot } from "./transport-slots.js";
7
+ const ASSIGNING_PREFIXES = [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken];
8
8
  /** Imported aliases and namespace access resolve to the declaring value. */
9
9
  const valueSymbol = (checker, expression, seen = new Set()) => {
10
- if (!expression || seen.has(expression)) return undefined
11
- seen.add(expression)
12
- const name = ts.isPropertyAccessExpression(expression) ? expression.name : expression
10
+ if (!expression || seen.has(expression))
11
+ return undefined;
12
+ seen.add(expression);
13
+ const name = ts.isPropertyAccessExpression(expression) ? expression.name : expression;
13
14
  const symbol = name.parent && ts.isShorthandPropertyAssignment(name.parent) && name.parent.name === name
14
- ? checker.getShorthandAssignmentValueSymbol(name.parent) : checker.getSymbolAtLocation(name)
15
- const target = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
15
+ ? checker.getShorthandAssignmentValueSymbol(name.parent) : checker.getSymbolAtLocation(name);
16
+ const target = resolvedSymbol(checker, symbol);
16
17
  const alias = target?.getDeclarations()?.find((declaration) => ts.isVariableDeclaration(declaration)
17
- && declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer
18
- && (ts.isIdentifier(declaration.initializer) || ts.isPropertyAccessExpression(declaration.initializer)))
19
- return alias ? valueSymbol(checker, alias.initializer, seen) : target
20
- }
21
-
18
+ && Boolean(declaration.parent.flags & ts.NodeFlags.Const) && Boolean(declaration.initializer)
19
+ && (declaration.initializer !== undefined && (ts.isIdentifier(declaration.initializer) || ts.isPropertyAccessExpression(declaration.initializer))));
20
+ return alias ? valueSymbol(checker, alias.initializer, seen) : target;
21
+ };
22
22
  /** The genuine decorator belongs to its platform capability, rather than merely sharing a name. */
23
23
  const ownedValue = (checker, hfs, expression, name, capability) => {
24
- const symbol = valueSymbol(checker, expression)
24
+ const symbol = valueSymbol(checker, expression);
25
25
  return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => {
26
- const file = declaration.getSourceFile().fileName
27
- return moduleOf(declaration, file) === null && hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === capability
28
- })
29
- }
30
-
26
+ const file = declaration.getSourceFile().fileName;
27
+ return moduleOf(declaration, file) === null && hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === capability;
28
+ });
29
+ };
31
30
  /** A resolved decorator declaration and its call arguments. */
32
31
  const decorators = (checker, node) => (ts.getDecorators(node) ?? []).map((decorator) => {
33
- const call = decorator.expression
34
- const expression = ts.isCallExpression(call) ? call.expression : call
35
- const symbol = valueSymbol(checker, expression)
36
- return { expression, symbol, args: ts.isCallExpression(call) ? call.arguments : [], called: ts.isCallExpression(call) }
37
- })
38
-
32
+ const call = decorator.expression;
33
+ const expression = ts.isCallExpression(call) ? call.expression : call;
34
+ const symbol = valueSymbol(checker, expression);
35
+ return { expression, symbol, args: ts.isCallExpression(call) ? call.arguments : [], called: ts.isCallExpression(call) };
36
+ });
39
37
  /** Whether the class carries the platform inbox's effectful marker. */
40
38
  const effectful = (checker, hfs, node) => decorators(checker, node).some((decorator) => decorator.called
41
- && decorator.args.length === 0 && ownedValue(checker, hfs, decorator.expression, "Effectful", "inbox"))
42
-
39
+ && decorator.args.length === 0 && ownedValue(checker, hfs, decorator.expression, "Effectful", "inbox"));
43
40
  /** A package declaration establishes framework identity even through an import alias. */
44
41
  const fromPackage = (checker, expression, name, pkg) => {
45
- const symbol = valueSymbol(checker, expression)
46
- return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => moduleOf(declaration, declaration.getSourceFile().fileName) === pkg)
47
- }
48
-
42
+ const symbol = valueSymbol(checker, expression);
43
+ return symbol?.name === name && symbol.getDeclarations()?.some((declaration) => moduleOf(declaration, declaration.getSourceFile().fileName) === pkg);
44
+ };
49
45
  /** Class inheritance keeps the Nest Command identity without relying on local spelling. */
50
46
  const commandType = (checker, type, seen = new Set()) => {
51
- if (!type || seen.has(type)) return false
52
- seen.add(type)
53
- if (originsOfType(checker, type).some((origin) => origin.name === "Command" && origin.module === "@nestjs/cqrs")) return true
54
- return type.isClassOrInterface() && (checker.getBaseTypes(type) ?? []).some((base) => commandType(checker, base, seen))
55
- }
56
-
47
+ if (!type || seen.has(type))
48
+ return false;
49
+ seen.add(type);
50
+ if (originsOfType(checker, type).some((origin) => origin.name === "Command" && origin.module === "@nestjs/cqrs"))
51
+ return true;
52
+ return type.isClassOrInterface() && (checker.getBaseTypes(type) ?? []).some((base) => commandType(checker, base, seen));
53
+ };
57
54
  /** Required strings exclude optional properties, undefined, null and unconstrained types. */
58
55
  const requiredString = (checker, type, property) => {
59
- const member = checker.getPropertyOfType(type, property)
60
- if (!member || member.flags & ts.SymbolFlags.Optional) return false
61
- const declaration = member.valueDeclaration ?? member.declarations?.[0]
62
- if (!declaration) return false
63
- const value = checker.getTypeOfSymbolAtLocation(member, declaration)
64
- return (value.isUnion() ? value.types : [value]).every((part) => !!(part.flags & ts.TypeFlags.StringLike))
65
- }
66
-
56
+ const member = checker.getPropertyOfType(type, property);
57
+ if (!member || member.flags & ts.SymbolFlags.Optional)
58
+ return false;
59
+ const declaration = member.valueDeclaration ?? member.declarations?.[0];
60
+ if (!declaration)
61
+ return false;
62
+ const value = checker.getTypeOfSymbolAtLocation(member, declaration);
63
+ return (value.isUnion() ? value.types : [value]).every((part) => !!(part.flags & ts.TypeFlags.StringLike));
64
+ };
67
65
  /** Canonical ExecuteParams carries the request, while a direct client params object carries its own key. */
68
66
  const keyContract = (checker, type) => {
69
- if (requiredString(checker, type, "idempotencyKey")) return true
70
- const request = checker.getPropertyOfType(type, "request")
71
- const declaration = request?.valueDeclaration ?? request?.declarations?.[0]
72
- return !!declaration && !(request.flags & ts.SymbolFlags.Optional)
73
- && requiredString(checker, checker.getTypeOfSymbolAtLocation(request, declaration), "idempotencyKey")
74
- }
75
-
67
+ if (requiredString(checker, type, "idempotencyKey"))
68
+ return true;
69
+ const request = checker.getPropertyOfType(type, "request");
70
+ const declaration = request?.valueDeclaration ?? request?.declarations?.[0];
71
+ return !!declaration && !!request && !(request.flags & ts.SymbolFlags.Optional)
72
+ && requiredString(checker, checker.getTypeOfSymbolAtLocation(request, declaration), "idempotencyKey");
73
+ };
76
74
  /** A sole returned expression admits an optional await and inline expression-bodied callbacks. */
77
75
  const returned = (body) => {
78
- if (!body) return null
79
- let expression = ts.isBlock(body) ? body.statements.length === 1 && ts.isReturnStatement(body.statements[0]) ? body.statements[0].expression : null : body
80
- while (expression && ts.isParenthesizedExpression(expression)) expression = expression.expression
81
- return expression && ts.isAwaitExpression(expression) ? expression.expression : expression
82
- }
83
-
76
+ if (!body)
77
+ return null;
78
+ const only = ts.isBlock(body) ? body.statements[0] : undefined;
79
+ let expression = ts.isBlock(body) ? body.statements.length === 1 && only !== undefined && ts.isReturnStatement(only) ? only.expression : null : body;
80
+ while (expression && ts.isParenthesizedExpression(expression))
81
+ expression = expression.expression;
82
+ return expression && ts.isAwaitExpression(expression) ? expression.expression : expression;
83
+ };
84
84
  /** Only a literal member name has a statically proved operation. */
85
- const memberName = (expression) => ts.isPropertyAccessExpression(expression) ? expression.name.text : null
86
-
85
+ const memberName = (expression) => ts.isPropertyAccessExpression(expression) ? expression.name.text : null;
87
86
  /** Computed literal names have ordinary last-write semantics; dynamic names could overwrite any field. */
88
87
  const propertyName = (name) => ts.isComputedPropertyName(name)
89
88
  ? ts.isStringLiteralLike(name.expression) ? name.expression.text : null
90
- : ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null
91
-
89
+ : ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
92
90
  /** Property mappings retain their last assignment, including spreads, as JavaScript does. */
93
91
  const propertyValue = (checker, expression, name) => {
94
- if (!expression) return null
95
- if (!ts.isObjectLiteralExpression(expression)) return checker.getPropertyOfType(checker.getTypeAtLocation(expression), name) ? { base: expression, name } : null
96
- let result = null
92
+ if (!expression)
93
+ return null;
94
+ if (!ts.isObjectLiteralExpression(expression))
95
+ return checker.getPropertyOfType(checker.getTypeAtLocation(expression), name) ? { base: expression, name } : null;
96
+ let result = null;
97
97
  for (const property of expression.properties) {
98
98
  if (ts.isSpreadAssignment(property)) {
99
- const type = checker.getTypeAtLocation(property.expression)
100
- if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown) || checker.getIndexTypeOfType(type, ts.IndexKind.String)) result = null
101
- else if (checker.getPropertyOfType(type, name)) result = { base: property.expression, name }
102
- } else if (propertyName(property.name) === null) result = null
99
+ const type = checker.getTypeAtLocation(property.expression);
100
+ if (type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown) || checker.getIndexTypeOfType(type, ts.IndexKind.String))
101
+ result = null;
102
+ else if (checker.getPropertyOfType(type, name))
103
+ result = { base: property.expression, name };
104
+ }
105
+ else if (propertyName(property.name) === null) {
106
+ result = null;
107
+ }
103
108
  else if (propertyName(property.name) === name) {
104
109
  result = ts.isPropertyAssignment(property) ? { expression: property.initializer }
105
- : ts.isShorthandPropertyAssignment(property) ? { expression: property.name } : null
110
+ : ts.isShorthandPropertyAssignment(property) ? { expression: property.name } : null;
106
111
  }
107
112
  }
108
- return result
109
- }
110
-
113
+ return result;
114
+ };
111
115
  /** A property path is rooted in the same lexical parameter, so a renamed or shadowed value cannot invent a key. */
112
116
  const parameterPath = (checker, expression, parameter) => {
113
- const path = []
114
- let current = expression
117
+ const path = [];
118
+ let current = expression;
115
119
  while (current && ts.isPropertyAccessExpression(current) && !current.questionDotToken) {
116
- path.unshift(current.name.text)
117
- current = current.expression
120
+ path.unshift(current.name.text);
121
+ current = current.expression;
118
122
  }
119
- return current && ts.isIdentifier(current) && valueSymbol(checker, current) === valueSymbol(checker, parameter.name) ? path : null
120
- }
121
-
123
+ return current && ts.isIdentifier(current) && valueSymbol(checker, current) === valueSymbol(checker, parameter.name) ? path : null;
124
+ };
122
125
  /** A mapped field has the expected path from the original parameter. */
123
126
  const mappedFrom = (checker, mapping, parameter, paths) => {
124
- if (!mapping) return false
125
- const path = parameterPath(checker, mapping.expression ?? mapping.base, parameter)
126
- if (!path) return false
127
- if (mapping.name) path.push(mapping.name)
128
- return paths.some((expected) => path.length === expected.length && path.every((part, index) => part === expected[index]))
129
- }
130
-
127
+ if (!mapping)
128
+ return false;
129
+ const path = parameterPath(checker, mapping.expression ?? mapping.base, parameter);
130
+ if (!path)
131
+ return false;
132
+ if (mapping.name)
133
+ path.push(mapping.name);
134
+ return paths.some((expected) => path.length === expected.length && path.every((part, index) => part === expected[index]));
135
+ };
131
136
  /** Type origins bind the transactional manager and inbox port to their actual owners. */
132
- const hasOrigin = (checker, hfs, expression, name, pkg, capability) => !!expression && originsOfType(checker, checker.getTypeAtLocation(expression)).some((origin) =>
133
- origin.name === name && origin.module === pkg && (!capability || hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === capability))
134
-
137
+ const hasOrigin = (checker, hfs, expression, name, pkg, capability) => !!expression && originsOfType(checker, checker.getTypeAtLocation(expression)).some((origin) => origin.name === name && origin.module === pkg && (!capability || hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === capability));
135
138
  /** Rejects visible calls, writes, constructions and explicit getter accesses before the inbox claim. */
136
139
  const pureEnvelope = (checker, expression) => {
137
- let pure = true
140
+ let pure = true;
138
141
  const visit = (node) => {
139
142
  if (ts.isCallExpression(node) || ts.isNewExpression(node) || ts.isAwaitExpression(node)
140
143
  || ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment
141
- || ts.isPrefixUnaryExpression(node) && [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken].includes(node.operator)
142
- || ts.isPostfixUnaryExpression(node)) pure = false
143
- if (ts.isPropertyAccessExpression(node) && valueSymbol(checker, node)?.getDeclarations()?.some(ts.isGetAccessorDeclaration)) pure = false
144
- ts.forEachChild(node, visit)
145
- }
146
- visit(expression)
147
- return pure
148
- }
149
-
144
+ || ts.isPrefixUnaryExpression(node) && ASSIGNING_PREFIXES.includes(node.operator)
145
+ || ts.isPostfixUnaryExpression(node))
146
+ pure = false;
147
+ if (ts.isPropertyAccessExpression(node) && valueSymbol(checker, node)?.getDeclarations()?.some(ts.isGetAccessorDeclaration))
148
+ pure = false;
149
+ ts.forEachChild(node, visit);
150
+ };
151
+ visit(expression);
152
+ return pure;
153
+ };
150
154
  /** The service returns its transaction, whose actual callback returns the inbox execution with that callback's own manager. */
151
155
  const transactionalClient = (checker, hfs, method) => {
152
- const transaction = returned(method.body)
153
- if (!transaction || !ts.isCallExpression(transaction) || transaction.questionDotToken || transaction.expression.questionDotToken || memberName(transaction.expression) !== "transaction"
154
- || !hasOrigin(checker, hfs, transaction.expression.expression, "EntityManager", "typeorm")) return false
155
- const first = transaction.arguments[0]
156
+ const transaction = returned(method.body);
157
+ if (!transaction || !ts.isCallExpression(transaction) || transaction.questionDotToken || childNode(transaction.expression, "questionDotToken") || memberName(transaction.expression) !== "transaction"
158
+ || !hasOrigin(checker, hfs, childNode(transaction.expression, "expression"), "EntityManager", "typeorm"))
159
+ return false;
160
+ const first = transaction.arguments[0];
156
161
  const callback = transaction.arguments.length === 1 ? first : transaction.arguments.length === 2
157
- && ts.isStringLiteral(first) && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.text) ? transaction.arguments[1] : null
158
- if (!callback || ![ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.FunctionExpression].includes(callback.kind)
159
- || callback.parameters.length !== 1 || !ts.isIdentifier(callback.parameters[0].name)) return false
160
- const execution = returned(callback.body)
161
- if (!execution || !ts.isCallExpression(execution) || execution.questionDotToken || execution.expression.questionDotToken || memberName(execution.expression) !== "runClient"
162
- || !hasOrigin(checker, hfs, execution.expression.expression, "Inbox", null, "inbox") || execution.arguments.length !== 3) return false
163
- const [envelope, manager, effect] = execution.arguments
164
- const original = method.parameters[0]
162
+ && first !== undefined && ts.isStringLiteral(first) && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.text) ? transaction.arguments[1] : null;
163
+ const callbackParameter = callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) ? callback.parameters[0] : undefined;
164
+ if (!callback || !(ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))
165
+ || callback.parameters.length !== 1 || !callbackParameter || !ts.isIdentifier(callbackParameter.name))
166
+ return false;
167
+ const execution = returned(callback.body);
168
+ if (!execution || !ts.isCallExpression(execution) || execution.questionDotToken || childNode(execution.expression, "questionDotToken") || memberName(execution.expression) !== "runClient"
169
+ || !hasOrigin(checker, hfs, childNode(execution.expression, "expression"), "Inbox", null, "inbox") || execution.arguments.length !== 3)
170
+ return false;
171
+ const [envelope, manager, effect] = execution.arguments;
172
+ const original = method.parameters[0];
165
173
  if (!original || !ts.isIdentifier(original.name) || !requiredString(checker, checker.getTypeAtLocation(original), "idempotencyKey")
166
- || !ts.isIdentifier(manager) || valueSymbol(checker, manager) !== valueSymbol(checker, callback.parameters[0].name)
174
+ || !manager || !envelope || !effect
175
+ || !ts.isIdentifier(manager) || valueSymbol(checker, manager) !== valueSymbol(checker, callbackParameter.name)
167
176
  || !hasOrigin(checker, hfs, manager, "EntityManager", "typeorm") || !ts.isObjectLiteralExpression(envelope)
168
- || ![ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.FunctionExpression].includes(effect.kind) || effect.parameters.length !== 0
169
- || !pureEnvelope(checker, envelope)) return false
170
- const key = propertyValue(checker, envelope, "idempotencyKey")
171
- const principal = propertyValue(checker, envelope, "principalId")
172
- const operation = propertyValue(checker, envelope, "operation")?.expression
177
+ || !(ts.isArrowFunction(effect) || ts.isFunctionExpression(effect)) || effect.parameters.length !== 0
178
+ || !pureEnvelope(checker, envelope))
179
+ return false;
180
+ const key = propertyValue(checker, envelope, "idempotencyKey");
181
+ const principal = propertyValue(checker, envelope, "principalId");
182
+ const operation = propertyValue(checker, envelope, "operation")?.expression;
173
183
  return mappedFrom(checker, key, original, [["idempotencyKey"]]) && !!principal?.expression
174
184
  && (parameterPath(checker, principal.expression, original)?.length ?? 0) > 0
175
185
  && !!operation && ts.isStringLiteralLike(operation) && operation.text.length > 0
176
- && !!propertyValue(checker, envelope, "request")
177
- }
178
-
186
+ && !!propertyValue(checker, envelope, "request");
187
+ };
179
188
  /** The CommandHandler decorator resolves its marked command declaration. */
180
189
  const handledCommand = (checker, hfs, node) => {
181
190
  for (const decorator of decorators(checker, node)) {
182
- if (!fromPackage(checker, decorator.expression, "CommandHandler", "@nestjs/cqrs") || decorator.args.length !== 1) continue
183
- const command = valueSymbol(checker, decorator.args[0])?.getDeclarations()?.find(ts.isClassDeclaration)
184
- if (command && effectful(checker, hfs, command)) return command
191
+ if (!fromPackage(checker, decorator.expression, "CommandHandler", "@nestjs/cqrs") || decorator.args.length !== 1)
192
+ continue;
193
+ const command = valueSymbol(checker, decorator.args[0])?.getDeclarations()?.find(ts.isClassDeclaration);
194
+ if (command && effectful(checker, hfs, command))
195
+ return command;
185
196
  }
186
- return null
187
- }
188
-
197
+ return null;
198
+ };
189
199
  /** A marked handler delegates once to a concrete domain service and preserves the request's key. */
190
200
  const delegatedMethod = (checker, hfs, handler) => {
191
- const process = handler.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "process")
192
- const call = returned(process?.body)
193
- if (!process || process.parameters.length !== 1 || !ts.isIdentifier(process.parameters[0].name)
194
- || !call || !ts.isCallExpression(call) || call.questionDotToken || call.expression.questionDotToken || call.arguments.length !== 1) return null
195
- const method = checker.getResolvedSignature(call)?.declaration
201
+ const process = handler.members.find((member) => ts.isMethodDeclaration(member) && member.name.getText() === "process");
202
+ const call = returned(process?.body);
203
+ const command = process?.parameters[0];
204
+ if (!process || process.parameters.length !== 1 || !command || !ts.isIdentifier(command.name)
205
+ || !call || !ts.isCallExpression(call) || call.questionDotToken || childNode(call.expression, "questionDotToken") || call.arguments.length !== 1)
206
+ return null;
207
+ const method = checker.getResolvedSignature(call)?.declaration;
196
208
  if (!method || !ts.isMethodDeclaration(method) || !method.body
197
- || hfs.tierOf(method.getSourceFile().fileName) !== "domain" || !baseName(method.getSourceFile().fileName).endsWith(".service.ts")) return null
198
- const mapping = propertyValue(checker, call.arguments[0], "idempotencyKey")
199
- return mappedFrom(checker, mapping, process.parameters[0], [["params", "idempotencyKey"], ["params", "request", "idempotencyKey"]]) ? method : null
200
- }
201
-
209
+ || hfs.tierOf(method.getSourceFile().fileName) !== "domain" || !baseName(method.getSourceFile().fileName).endsWith(".service.ts"))
210
+ return null;
211
+ const mapping = propertyValue(checker, call.arguments[0], "idempotencyKey");
212
+ return mappedFrom(checker, mapping, command, [["params", "idempotencyKey"], ["params", "request", "idempotencyKey"]]) ? method : null;
213
+ };
202
214
  /** Every reached service method is judged when that file is linted, including changed domain files. */
203
- const reachedByProgram = new WeakMap()
215
+ const reachedByProgram = new WeakMap();
204
216
  const reachedServices = (checker, program, hfs) => {
205
- const cached = reachedByProgram.get(program)
206
- if (cached) return cached
207
- const methods = new Set()
217
+ const cached = reachedByProgram.get(program);
218
+ if (cached)
219
+ return cached;
220
+ const methods = new Set();
208
221
  for (const source of program.getSourceFiles()) {
209
- if (hfs.slotOf(source.fileName) !== "be.feature.application") continue
222
+ if (hfs.slotOf(source.fileName) !== "be.feature.application")
223
+ continue;
210
224
  const visit = (node) => {
211
225
  if (ts.isClassDeclaration(node) && handledCommand(checker, hfs, node)) {
212
- const method = delegatedMethod(checker, hfs, node)
213
- if (method) methods.add(method)
226
+ const method = delegatedMethod(checker, hfs, node);
227
+ if (method)
228
+ methods.add(method);
214
229
  }
215
- ts.forEachChild(node, visit)
216
- }
217
- visit(source)
230
+ ts.forEachChild(node, visit);
231
+ };
232
+ visit(source);
218
233
  }
219
- reachedByProgram.set(program, methods)
220
- return methods
221
- }
222
-
234
+ reachedByProgram.set(program, methods);
235
+ return methods;
236
+ };
223
237
  /** Genuine validators must reject empty, optional and overlong wire keys. */
224
238
  const boundedKey = (checker, declaration) => {
225
- if (!declaration || !ts.isPropertyDeclaration(declaration) || declaration.questionToken
226
- || propertyName(declaration.name) === null
227
- || !requiredString(checker, checker.getTypeAtLocation(declaration.parent), propertyName(declaration.name))) return false
228
- const validators = decorators(checker, declaration).filter((decorator) => decorator.called && decorator.symbol?.getDeclarations()?.some((item) => moduleOf(item, item.getSourceFile().fileName) === "class-validator"))
229
- const has = (name) => validators.some((decorator) => decorator.symbol.name === name)
230
- const bound = (name, accepts) => validators.some((decorator) => decorator.symbol.name === name
231
- && decorator.args.length > 0 && ts.isNumericLiteral(decorator.args[0]) && accepts(Number(decorator.args[0].text)))
239
+ if (!declaration || !ts.isPropertyDeclaration(declaration) || declaration.questionToken)
240
+ return false;
241
+ const key = propertyName(declaration.name);
242
+ if (key === null || !requiredString(checker, checker.getTypeAtLocation(declaration.parent), key))
243
+ return false;
244
+ const validators = decorators(checker, declaration).filter((decorator) => decorator.called && decorator.symbol?.getDeclarations()?.some((item) => moduleOf(item, item.getSourceFile().fileName) === "class-validator"));
245
+ const has = (name) => validators.some((decorator) => decorator.symbol?.name === name);
246
+ const bound = (name, accepts) => validators.some((decorator) => {
247
+ const first = decorator.args[0];
248
+ return decorator.symbol?.name === name
249
+ && decorator.args.length > 0 && first !== undefined && ts.isNumericLiteral(first) && accepts(Number(first.text));
250
+ });
232
251
  return !has("IsOptional") && !has("ValidateIf") && (has("IsUUID") || has("IsString")
233
- && bound("MinLength", (value) => value >= 1) && bound("MaxLength", (value) => value >= 1 && value <= 64))
234
- }
235
-
252
+ && bound("MinLength", (value) => value >= 1) && bound("MaxLength", (value) => value >= 1 && value <= 64));
253
+ };
236
254
  /** Follow object mappings to their original property declarations rather than trusting an annotated return type. */
237
255
  const propertySymbol = (checker, expression, path) => {
238
- if (path.length === 0) return valueSymbol(checker, expression)
256
+ const [head, ...rest] = path;
257
+ if (head === undefined)
258
+ return valueSymbol(checker, expression);
239
259
  if (ts.isObjectLiteralExpression(expression)) {
240
- const mapping = propertyValue(checker, expression, path[0])
241
- if (!mapping) return undefined
242
- return mapping.expression ? propertySymbol(checker, mapping.expression, path.slice(1))
243
- : propertySymbol(checker, mapping.base, [mapping.name, ...path.slice(1)])
260
+ const mapping = propertyValue(checker, expression, head);
261
+ if (!mapping)
262
+ return undefined;
263
+ return mapping.expression ? propertySymbol(checker, mapping.expression, rest)
264
+ : propertySymbol(checker, mapping.base, [mapping.name, ...rest]);
244
265
  }
245
- let type = checker.getTypeAtLocation(expression)
246
- let symbol
266
+ let type = checker.getTypeAtLocation(expression);
267
+ let symbol;
247
268
  for (const name of path) {
248
- symbol = checker.getPropertyOfType(type, name)
249
- const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0]
250
- if (!declaration) return undefined
251
- type = checker.getTypeOfSymbolAtLocation(symbol, declaration)
269
+ symbol = checker.getPropertyOfType(type, name);
270
+ const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
271
+ if (!declaration || !symbol)
272
+ return undefined;
273
+ type = checker.getTypeOfSymbolAtLocation(symbol, declaration);
252
274
  }
253
- return symbol
254
- }
255
-
275
+ return symbol;
276
+ };
256
277
  /** A key mapped by a pure function must come from its actual argument, never a constant or captured replacement. */
257
278
  const mappedKeySymbol = (checker, mapping, bindings = new Map()) => {
258
- if (!mapping) return undefined
259
- const path = mapping.name ? [mapping.name] : []
260
- let expression = mapping.expression ?? mapping.base
279
+ if (!mapping)
280
+ return undefined;
281
+ const path = mapping.name ? [mapping.name] : [];
282
+ let expression = mapping.expression ?? mapping.base;
261
283
  while (ts.isPropertyAccessExpression(expression) && !expression.questionDotToken) {
262
- path.unshift(expression.name.text)
263
- expression = expression.expression
284
+ path.unshift(expression.name.text);
285
+ expression = expression.expression;
264
286
  }
265
- const actual = bindings.get(valueSymbol(checker, expression))
266
- if (actual) return propertySymbol(checker, actual, path)
267
- return bindings.size > 0 ? undefined : propertySymbol(checker, expression, path)
268
- }
269
-
287
+ const actual = bindings.get(valueSymbol(checker, expression));
288
+ if (actual)
289
+ return propertySymbol(checker, actual, path);
290
+ return bindings.size > 0 ? undefined : propertySymbol(checker, expression, path);
291
+ };
270
292
  /** A mapper is proved by its sole pure return expression and original argument bindings, not its function name. */
271
293
  const requestKey = (checker, expression) => {
272
- if (!ts.isCallExpression(expression)) return mappedKeySymbol(checker, propertyValue(checker, expression, "idempotencyKey"))
273
- const mapper = checker.getResolvedSignature(expression)?.declaration
274
- const body = returned(mapper?.body)
294
+ if (!ts.isCallExpression(expression))
295
+ return mappedKeySymbol(checker, propertyValue(checker, expression, "idempotencyKey"));
296
+ const mapper = checker.getResolvedSignature(expression)?.declaration;
297
+ const body = returned(childNode(mapper, "body"));
275
298
  if (!mapper || !body || expression.questionDotToken || mapper.parameters.length !== expression.arguments.length
276
- || mapper.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword)
277
- || !pureEnvelope(checker, body) || expression.arguments.some((argument) => !pureEnvelope(checker, argument))) return undefined
278
- const bindings = new Map()
299
+ || (ts.canHaveModifiers(mapper) ? ts.getModifiers(mapper) : undefined)?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword)
300
+ || !pureEnvelope(checker, body) || expression.arguments.some((argument) => !pureEnvelope(checker, argument)))
301
+ return undefined;
302
+ const bindings = new Map();
279
303
  for (const [index, parameter] of mapper.parameters.entries()) {
280
- if (!ts.isIdentifier(parameter.name) || parameter.initializer || parameter.dotDotDotToken) return undefined
281
- bindings.set(valueSymbol(checker, parameter.name), expression.arguments[index])
304
+ if (!ts.isIdentifier(parameter.name) || childNode(parameter, "initializer") || childNode(parameter, "dotDotDotToken"))
305
+ return undefined;
306
+ bindings.set(valueSymbol(checker, parameter.name), expression.arguments[index]);
282
307
  }
283
- return mappedKeySymbol(checker, propertyValue(checker, body, "idempotencyKey"), bindings)
284
- }
285
-
308
+ return mappedKeySymbol(checker, propertyValue(checker, body, "idempotencyKey"), bindings);
309
+ };
286
310
  /** Follow the constructor's key mapping to the original DTO property, including a whole ExecuteParams value. */
287
311
  const constructionKey = (checker, construction) => {
288
- const params = construction.arguments?.[0]
289
- const request = propertyValue(checker, params, "request")
290
- let nestedSymbol
312
+ const params = construction.arguments?.[0];
313
+ const request = propertyValue(checker, params, "request");
314
+ let nestedSymbol;
291
315
  if (request?.base) {
292
- const property = checker.getPropertyOfType(checker.getTypeAtLocation(request.base), request.name)
293
- const declaration = property?.valueDeclaration ?? property?.declarations?.[0]
294
- if (declaration) nestedSymbol = checker.getPropertyOfType(checker.getTypeOfSymbolAtLocation(property, declaration), "idempotencyKey")
316
+ const property = checker.getPropertyOfType(checker.getTypeAtLocation(request.base), request.name);
317
+ const declaration = property?.valueDeclaration ?? property?.declarations?.[0];
318
+ if (declaration && property)
319
+ nestedSymbol = checker.getPropertyOfType(checker.getTypeOfSymbolAtLocation(property, declaration), "idempotencyKey");
295
320
  }
296
321
  return nestedSymbol ?? (request?.expression ? requestKey(checker, request.expression)
297
- : mappedKeySymbol(checker, propertyValue(checker, params, "idempotencyKey")))
298
- }
299
-
322
+ : mappedKeySymbol(checker, propertyValue(checker, params, "idempotencyKey")));
323
+ };
300
324
  /** Only DTO key declarations that reach an effectful command carry this rule's transport obligation. */
301
- const keysByProgram = new WeakMap()
325
+ const keysByProgram = new WeakMap();
302
326
  const reachedKeys = (checker, program, hfs) => {
303
- const cached = keysByProgram.get(program)
304
- if (cached) return cached
305
- const keys = new Set()
327
+ const cached = keysByProgram.get(program);
328
+ if (cached)
329
+ return cached;
330
+ const keys = new Set();
306
331
  for (const source of program.getSourceFiles()) {
307
- if (!isTransportSlot(hfs.slotOf(source.fileName))) continue
332
+ if (!isTransportSlot(hfs.slotOf(source.fileName)))
333
+ continue;
308
334
  const visit = (node) => {
309
335
  if (ts.isNewExpression(node)) {
310
- const command = valueSymbol(checker, node.expression)?.getDeclarations()?.find(ts.isClassDeclaration)
336
+ const command = valueSymbol(checker, node.expression)?.getDeclarations()?.find(ts.isClassDeclaration);
311
337
  if (command && effectful(checker, hfs, command)) {
312
- for (const declaration of constructionKey(checker, node)?.getDeclarations() ?? []) keys.add(declaration)
338
+ for (const declaration of constructionKey(checker, node)?.getDeclarations() ?? [])
339
+ keys.add(declaration);
313
340
  }
314
341
  }
315
- ts.forEachChild(node, visit)
316
- }
317
- visit(source)
342
+ ts.forEachChild(node, visit);
343
+ };
344
+ visit(source);
318
345
  }
319
- keysByProgram.set(program, keys)
320
- return keys
321
- }
322
-
346
+ keysByProgram.set(program, keys);
347
+ return keys;
348
+ };
323
349
  /** Effectful commands carry a bounded client key to the one atomic domain inbox execution. */
324
350
  export const mutationIdempotent = {
325
351
  meta: {
@@ -336,68 +362,90 @@ export const mutationIdempotent = {
336
362
  },
337
363
  },
338
364
  create(context) {
339
- const hfs = hfsOf(context)
340
- const slot = hfs.slotOf(context.filename)
341
- if (!slot || slot.startsWith("be.tests.")) return {}
342
- const { checker, program, toTs } = typed(context)
343
- let reached
344
- let keys
365
+ const hfs = hfsOf(context);
366
+ const slot = hfs.slotOf(context.filename);
367
+ if (!slot || slot.startsWith("be.tests."))
368
+ return {};
369
+ const { checker, program, toTs } = typed(context);
370
+ let reached;
371
+ let keys;
345
372
  return {
346
373
  Identifier(node) {
347
374
  if (hfs.tierOf(context.filename) === "platform" && ownerNameOf(hfs, context.filename) === "inbox"
348
- || !ownedValue(checker, hfs, toTs(node), "Effectful", "inbox")) return
349
- const parent = node.parent
350
- const typeOnly = parent?.type?.startsWith("TS") && !["TSAsExpression", "TSTypeAssertion", "TSNonNullExpression", "TSSatisfiesExpression", "TSInstantiationExpression"].includes(parent.type)
351
- if (["ImportSpecifier", "ExportSpecifier", "Decorator"].includes(parent?.type) || typeOnly) return
352
- if (parent?.type === "VariableDeclarator" && parent.id === node) return
353
- if (parent?.type === "Property" && parent.key === node && !parent.computed && parent.value !== node) return
354
- const reference = parent?.type === "MemberExpression" && parent.property === node ? parent : node
355
- if (reference.parent?.type === "CallExpression" && reference.parent.callee === reference) return
356
- if (reference.parent?.type === "VariableDeclarator" && reference.parent.init === reference && reference.parent.parent.kind === "const") return
357
- context.report({ node, messageId: "marker" })
375
+ || !ownedValue(checker, hfs, toTs(node), "Effectful", "inbox"))
376
+ return;
377
+ const parent = node.parent;
378
+ const typeOnly = parent?.type?.startsWith("TS") && !["TSAsExpression", "TSTypeAssertion", "TSNonNullExpression", "TSSatisfiesExpression", "TSInstantiationExpression"].includes(parent.type);
379
+ if (["ImportSpecifier", "ExportSpecifier", "Decorator"].includes(parent?.type) || typeOnly)
380
+ return;
381
+ if (parent?.type === "VariableDeclarator" && parent.id === node)
382
+ return;
383
+ if (parent?.type === "Property" && parent.key === node && !parent.computed && parent.value !== node)
384
+ return;
385
+ const reference = parent?.type === "MemberExpression" && parent.property === node ? parent : node;
386
+ if (reference.parent?.type === "CallExpression" && reference.parent.callee === reference)
387
+ return;
388
+ if (reference.parent?.type === "VariableDeclarator" && reference.parent.init === reference && reference.parent.parent.kind === "const")
389
+ return;
390
+ context.report({ node, messageId: "marker" });
358
391
  },
359
392
  CallExpression(node) {
360
- const call = toTs(node)
361
- if (ownedValue(checker, hfs, call.expression, "Effectful", "inbox") && node.parent?.type !== "Decorator") context.report({ node, messageId: "marker" })
393
+ const call = toTs(node);
394
+ if (ownedValue(checker, hfs, call.expression, "Effectful", "inbox") && node.parent?.type !== "Decorator")
395
+ context.report({ node, messageId: "marker" });
362
396
  },
363
397
  ClassDeclaration(node) {
364
- const declaration = toTs(node)
365
- const marks = decorators(checker, declaration).filter((decorator) => decorator.symbol?.name === "Effectful")
398
+ const declaration = toTs(node);
399
+ const marks = decorators(checker, declaration).filter((decorator) => decorator.symbol?.name === "Effectful");
366
400
  if (marks.length > 0) {
367
401
  if (!effectful(checker, hfs, declaration) || !commandType(checker, checker.getTypeAtLocation(declaration))) {
368
- context.report({ node: node.id ?? node, messageId: "marker" })
369
- } else {
370
- if (!(hfs.patterns ?? []).includes("idempotency")) context.report({ node: node.id ?? node, messageId: "declaration" })
371
- const constructor = declaration.members.find(ts.isConstructorDeclaration)
372
- if (!constructor || constructor.parameters.length !== 1 || !keyContract(checker, checker.getTypeAtLocation(constructor.parameters[0]))) context.report({ node: node.id ?? node, messageId: "key" })
402
+ context.report({ node: node.id ?? node, messageId: "marker" });
403
+ }
404
+ else {
405
+ if (!(hfs.patterns ?? []).includes("idempotency"))
406
+ context.report({ node: node.id ?? node, messageId: "declaration" });
407
+ const constructor = declaration.members.find(ts.isConstructorDeclaration);
408
+ const parameter = constructor?.parameters.length === 1 ? constructor.parameters[0] : undefined;
409
+ if (!constructor || !parameter || !keyContract(checker, checker.getTypeAtLocation(parameter)))
410
+ context.report({ node: node.id ?? node, messageId: "key" });
373
411
  }
374
412
  }
375
- if (!handledCommand(checker, hfs, declaration)) return
376
- const method = delegatedMethod(checker, hfs, declaration)
377
- if (!method) context.report({ node: node.id ?? node, messageId: "handler" })
378
- else if (!transactionalClient(checker, hfs, method)) context.report({ node: node.id ?? node, messageId: "transaction" })
413
+ if (!handledCommand(checker, hfs, declaration))
414
+ return;
415
+ const method = delegatedMethod(checker, hfs, declaration);
416
+ if (!method)
417
+ context.report({ node: node.id ?? node, messageId: "handler" });
418
+ else if (!transactionalClient(checker, hfs, method))
419
+ context.report({ node: node.id ?? node, messageId: "transaction" });
379
420
  },
380
421
  MethodDefinition(node) {
381
- if (hfs.tierOf(context.filename) !== "domain" || !baseName(context.filename).endsWith(".service.ts")) return
382
- reached ??= reachedServices(checker, program, hfs)
383
- const method = toTs(node)
384
- if (reached.has(method) && !transactionalClient(checker, hfs, method)) context.report({ node: node.key, messageId: "transaction" })
422
+ if (hfs.tierOf(context.filename) !== "domain" || !baseName(context.filename).endsWith(".service.ts"))
423
+ return;
424
+ reached ??= reachedServices(checker, program, hfs);
425
+ const method = toTs(node);
426
+ if (reached.has(method) && ts.isMethodDeclaration(method) && !transactionalClient(checker, hfs, method))
427
+ context.report({ node: node.key, messageId: "transaction" });
385
428
  },
386
429
  PropertyDefinition(node) {
387
- if (!isTransportSlot(slot)) return
388
- keys ??= reachedKeys(checker, program, hfs)
389
- const declaration = toTs(node)
390
- if (keys.has(declaration) && !boundedKey(checker, declaration)) context.report({ node: node.key, messageId: "validation" })
430
+ if (!isTransportSlot(slot))
431
+ return;
432
+ keys ??= reachedKeys(checker, program, hfs);
433
+ const declaration = toTs(node);
434
+ if (keys.has(declaration) && !boundedKey(checker, declaration))
435
+ context.report({ node: node.key, messageId: "validation" });
391
436
  },
392
437
  NewExpression(node) {
393
- if (!isTransportSlot(slot)) return
394
- const construction = toTs(node)
395
- const command = valueSymbol(checker, construction.expression)?.getDeclarations()?.find(ts.isClassDeclaration)
396
- if (!command || !effectful(checker, hfs, command)) return
397
- const declarations = constructionKey(checker, construction)?.getDeclarations() ?? []
398
- const localProperty = declarations.some((declaration) => ts.isPropertyDeclaration(declaration) && declaration.getSourceFile() === construction.getSourceFile())
399
- if (!localProperty && !declarations.some((declaration) => boundedKey(checker, declaration))) context.report({ node, messageId: "validation" })
438
+ if (!isTransportSlot(slot))
439
+ return;
440
+ const construction = toTs(node);
441
+ const command = valueSymbol(checker, construction.expression)?.getDeclarations()?.find(ts.isClassDeclaration);
442
+ if (!command || !effectful(checker, hfs, command))
443
+ return;
444
+ const declarations = constructionKey(checker, construction)?.getDeclarations() ?? [];
445
+ const localProperty = declarations.some((declaration) => ts.isPropertyDeclaration(declaration) && declaration.getSourceFile() === construction.getSourceFile());
446
+ if (!localProperty && !declarations.some((declaration) => boundedKey(checker, declaration)))
447
+ context.report({ node, messageId: "validation" });
400
448
  },
401
- }
449
+ };
402
450
  },
403
- }
451
+ };