@starci/eslint-canon-be 3.4.57 → 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 (197) hide show
  1. package/CHANGELOG.md +19 -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 +22 -14
  177. package/runtime/knowledge/hfs/rules.yaml +23 -0
  178. package/runtime/scripts/lib/package-at.mjs +5 -5
  179. package/async-discipline.mjs +0 -83
  180. package/comments.mjs +0 -416
  181. package/edge-hardening.mjs +0 -139
  182. package/health-ready.mjs +0 -539
  183. package/jwt-alg.mjs +0 -45
  184. package/lib/ast.mjs +0 -88
  185. package/lib/import-source.mjs +0 -104
  186. package/lib/specifier.mjs +0 -27
  187. package/lib/subject-values.mjs +0 -55
  188. package/lib/types.mjs +0 -133
  189. package/log-safety.mjs +0 -303
  190. package/module-layering.mjs +0 -270
  191. package/naming.mjs +0 -251
  192. package/observability.mjs +0 -241
  193. package/resilience.mjs +0 -304
  194. package/service-isolation.mjs +0 -75
  195. package/spec-no-skip.mjs +0 -85
  196. package/testing.mjs +0 -384
  197. package/type-safety.mjs +0 -323
@@ -1,217 +1,238 @@
1
1
  /** R263 extends inbox dedupe to scalar delivery ids and signed raw-body intakes. */
2
- import ts from "typescript"
3
- import { walk } from "./ast.mjs"
4
- import { hfsOf } from "./hfs.mjs"
5
- import { baseName, isOwnedType, ownerNameOf } from "./ports.mjs"
6
- import { resolveVariable } from "./transactions.mjs"
7
- import { isPackageType, typed } from "./types.mjs"
8
- import { webhookIntakeProcessesDelivery } from "./webhook-handoff-intake.mjs"
9
-
10
- const DELIVERY_ID = /Id$/
11
-
2
+ import ts from "typescript";
3
+ import { memberKeyValue, nameOrValue, walk } from "./ast.js";
4
+ import { hfsOf } from "./hfs.js";
5
+ import { baseName, isOwnedType, ownerNameOf } from "./ports.js";
6
+ import { resolveVariable } from "./transactions.js";
7
+ import { isPackageType, typed } from "./types.js";
8
+ import { webhookIntakeProcessesDelivery } from "./webhook-handoff-intake.js";
9
+ const DELIVERY_ID = /Id$/;
12
10
  /** The slot of provider webhook doors (`<provider>.webhook.ts`), the only entrance of a delivery intake. */
13
- const DOOR_SLOT = "be.feature.webhooks.http"
14
-
11
+ const DOOR_SLOT = "be.feature.webhooks.http";
15
12
  /** The method declarations each program's webhook doors call, computed once per program. */
16
- const reachedByProgram = new WeakMap()
17
-
13
+ const reachedByProgram = new WeakMap();
18
14
  /** Declarations a call resolves to: its signature's declaration and its (alias-resolved) callee symbol's declarations. */
19
15
  const calledDeclarations = (checker, call) => {
20
- const expression = call.expression
16
+ const expression = call.expression;
21
17
  const name = ts.isPropertyAccessExpression(expression) ? expression.name
22
- : ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression
23
- const symbol = checker.getSymbolAtLocation(name)
24
- const target = symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
25
- return [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])].filter(Boolean)
26
- }
27
-
18
+ : ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression;
19
+ const symbol = checker.getSymbolAtLocation(name);
20
+ const target = symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
21
+ return [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])].filter((declaration) => Boolean(declaration));
22
+ };
28
23
  /** Every method a webhook door file (slot be.feature.webhooks.http, `*.webhook.ts`) calls, by resolved declaration. */
29
24
  const doorCalledDeclarations = (context, hfs) => {
30
- const { program, checker } = typed(context)
31
- const cached = reachedByProgram.get(program)
32
- if (cached) return cached
33
- const reached = new Set()
25
+ const { program, checker } = typed(context);
26
+ const cached = reachedByProgram.get(program);
27
+ if (cached)
28
+ return cached;
29
+ const reached = new Set();
34
30
  for (const source of program.getSourceFiles()) {
35
- if (hfs.slotOf(source.fileName) !== DOOR_SLOT || !baseName(source.fileName).endsWith(".webhook.ts")) continue
31
+ if (hfs.slotOf(source.fileName) !== DOOR_SLOT || !baseName(source.fileName).endsWith(".webhook.ts"))
32
+ continue;
36
33
  const visit = (node) => {
37
- if (ts.isCallExpression(node)) for (const declaration of calledDeclarations(checker, node)) reached.add(declaration)
38
- ts.forEachChild(node, visit)
39
- }
40
- visit(source)
34
+ if (ts.isCallExpression(node))
35
+ for (const declaration of calledDeclarations(checker, node))
36
+ reached.add(declaration);
37
+ ts.forEachChild(node, visit);
38
+ };
39
+ visit(source);
41
40
  }
42
- reachedByProgram.set(program, reached)
43
- return reached
44
- }
45
-
41
+ reachedByProgram.set(program, reached);
42
+ return reached;
43
+ };
46
44
  /** A method is a webhook delivery intake only when a webhook door's call resolves to it. */
47
45
  const isDoorIntake = (context, hfs, method) => {
48
- const declaration = typed(context).toTs(method)
49
- return !!declaration && doorCalledDeclarations(context, hfs).has(declaration)
50
- }
51
-
46
+ const declaration = typed(context).toTs(method);
47
+ return !!declaration && doorCalledDeclarations(context, hfs).has(declaration);
48
+ };
52
49
  /** Defaults keep the same first-parameter binding. */
53
- const parameterOf = (parameter) => parameter?.type === "AssignmentPattern" ? parameter.left : parameter
54
-
50
+ const parameterOf = (parameter) => parameter?.type === "AssignmentPattern" ? parameter.left : parameter;
55
51
  /** The extra delivery contracts missed by the existing eventId-object rule. */
56
52
  const deliveryKey = (context, method) => {
57
- const first = parameterOf(method.value.params[0])
58
- if (!first) return null
59
- if (first.type === "Identifier" && DELIVERY_ID.test(first.name)) return { parameter: first }
60
- const { checker, toTs } = typed(context)
61
- const type = checker.getTypeAtLocation(toTs(first))
62
- const parts = type.isUnion() ? type.types : [type]
63
- const ids = [...new Set(parts.flatMap((part) => checker.getPropertiesOfType(part).map((property) => property.getName()).filter((name) => DELIVERY_ID.test(name))))]
64
- if (ids.length) return { parameter: first, properties: ids }
53
+ const first = parameterOf(method.value.params[0]);
54
+ if (!first)
55
+ return null;
56
+ if (first.type === "Identifier" && DELIVERY_ID.test(first.name))
57
+ return { parameter: first };
58
+ const { checker, toTs } = typed(context);
59
+ const type = checker.getTypeAtLocation(toTs(first));
60
+ const parts = type.isUnion() ? type.types : [type];
61
+ const ids = [...new Set(parts.flatMap((part) => checker.getPropertiesOfType(part).map((property) => property.getName()).filter((name) => DELIVERY_ID.test(name))))];
62
+ if (ids.length)
63
+ return { parameter: first, properties: ids };
65
64
  const raw = first.type === "Identifier" && first.name === "rawBody"
66
- && method.value.params.slice(1).some((parameter) => parameterOf(parameter)?.name === "signature")
67
- || parts.some((part) => checker.getPropertyOfType(part, "rawBody") && checker.getPropertyOfType(part, "signature"))
65
+ && method.value.params.slice(1).some((parameter) => {
66
+ const bound = parameterOf(parameter);
67
+ return bound?.type === "Identifier" && bound.name === "signature";
68
+ })
69
+ || parts.some((part) => checker.getPropertyOfType(part, "rawBody") && checker.getPropertyOfType(part, "signature"));
68
70
  // A declared verifier class proves authenticity; its ordinary domain intake owns dedupe.
69
- const owner = method.parent?.parent
70
- if (raw && !/(?:Verifier|verify)$/.test(owner?.id?.name ?? "")) return { parameter: first, raw: true }
71
- return null
72
- }
73
-
71
+ const owner = method.parent?.parent;
72
+ const ownerName = owner?.type === "ClassDeclaration" || owner?.type === "ClassExpression" ? owner.id?.name : undefined;
73
+ if (raw && !/(?:Verifier|verify)$/.test(ownerName ?? ""))
74
+ return { parameter: first, raw: true };
75
+ return null;
76
+ };
74
77
  /** Identifiers are compared by lexical binding, so a same-spelled shadow is not a key. */
75
78
  const sameBinding = (context, left, right) => left?.type === "Identifier" && right?.type === "Identifier"
76
79
  && resolveVariable(context.sourceCode, left) !== null
77
- && resolveVariable(context.sourceCode, left) === resolveVariable(context.sourceCode, right)
78
-
80
+ && resolveVariable(context.sourceCode, left) === resolveVariable(context.sourceCode, right);
79
81
  /** A decoded key comes from the raw input or a later delivery-id parameter, never a widened constant. */
80
82
  const rawKeySource = (context, expression, key, seen = new Set()) => {
81
- if (!expression || seen.has(expression)) return false
82
- seen.add(expression)
83
- let sourced = false
83
+ if (!expression || seen.has(expression))
84
+ return false;
85
+ seen.add(expression);
86
+ let sourced = false;
84
87
  walk(expression, (node) => {
85
- if (node.type !== "Identifier") return
86
- if (sameBinding(context, node, key.parameter)) sourced = true
87
- const variable = resolveVariable(context.sourceCode, node)
88
+ if (node.type !== "Identifier")
89
+ return;
90
+ if (sameBinding(context, node, key.parameter))
91
+ sourced = true;
92
+ const variable = resolveVariable(context.sourceCode, node);
88
93
  for (const definition of variable?.defs ?? []) {
89
94
  if (definition.type === "Parameter" && (DELIVERY_ID.test(node.name)
90
95
  || node.parent?.type === "MemberExpression" && node.parent.object === node
91
- && DELIVERY_ID.test(node.parent.computed ? node.parent.property.value : node.parent.property.name))) sourced = true
92
- if (definition.type === "Variable" && rawKeySource(context, definition.node.init, key, seen)) sourced = true
96
+ && DELIVERY_ID.test(String(memberKeyValue(node.parent)))))
97
+ sourced = true;
98
+ if (definition.type === "Variable" && rawKeySource(context, definition.node.init, key, seen))
99
+ sourced = true;
93
100
  }
94
- }, { intoFunctions: false })
95
- return sourced
96
- }
97
-
101
+ }, { intoFunctions: false });
102
+ return sourced;
103
+ };
98
104
  /** Scalar ids and object ids must actually key the claim; a raw payload itself is never a delivery key. */
99
105
  const usesKey = (context, argument, key) => {
100
- if (!argument) return false
106
+ if (!argument)
107
+ return false;
101
108
  if (key.raw) {
102
- if (sameBinding(context, argument, key.parameter) || argument.type === "Literal") return false
109
+ if (sameBinding(context, argument, key.parameter) || argument.type === "Literal")
110
+ return false;
103
111
  const name = argument.type === "Identifier" ? argument.name
104
- : argument.type === "MemberExpression" ? argument.computed ? argument.property.value : argument.property.name : null
105
- if (!name || !DELIVERY_ID.test(name)) return false
106
- const { checker, toTs } = typed(context)
107
- const type = checker.getTypeAtLocation(toTs(argument))
108
- const parts = type.isUnion() ? type.types : [type]
112
+ : argument.type === "MemberExpression" ? memberKeyValue(argument) : null;
113
+ if (!name || !DELIVERY_ID.test(String(name)))
114
+ return false;
115
+ const { checker, toTs } = typed(context);
116
+ const type = checker.getTypeAtLocation(toTs(argument));
117
+ const parts = type.isUnion() ? type.types : [type];
109
118
  return parts.every((part) => part.flags & ts.TypeFlags.StringLike && !(part.flags & ts.TypeFlags.StringLiteral))
110
- && rawKeySource(context, argument, key)
119
+ && rawKeySource(context, argument, key);
111
120
  }
112
121
  if (key.parameter.type === "ObjectPattern") {
113
122
  return key.parameter.properties.some((property) => property.type === "Property"
114
- && key.properties?.includes(property.key.name ?? property.key.value)
115
- && sameBinding(context, argument, parameterOf(property.value)))
123
+ && key.properties?.some((name) => name === nameOrValue(property.key))
124
+ && sameBinding(context, argument, parameterOf(property.value)));
116
125
  }
117
- if (!key.properties) return sameBinding(context, argument, key.parameter)
126
+ if (!key.properties)
127
+ return sameBinding(context, argument, key.parameter);
118
128
  return argument.type === "MemberExpression" && !argument.optional
119
129
  && sameBinding(context, argument.object, key.parameter)
120
- && key.properties.includes(argument.computed ? argument.property.value : argument.property.name)
121
- }
122
-
130
+ && key.properties.some((name) => name === memberKeyValue(argument));
131
+ };
123
132
  /** Find the first completed await, without treating a nested helper as work performed here. */
124
133
  const firstAwait = (body) => {
125
- let result = null
134
+ let result = null;
126
135
  walk(body, (node) => {
127
- if (node.type === "AwaitExpression" && (!result || node.range[1] < result.range[1])) result = node
128
- }, { intoFunctions: false })
129
- return result
130
- }
131
-
136
+ if (node.type === "AwaitExpression" && (!result || node.range[1] < result.range[1]))
137
+ result = node;
138
+ }, { intoFunctions: false });
139
+ return result;
140
+ };
132
141
  /** A parameter's binding cannot be overwritten before the claim and still prove the delivered id. */
133
142
  const preservesKey = (context, key, call) => {
134
- const parameter = key.raw ? call.arguments[1] : key.parameter
135
- if (parameter.type !== "Identifier") return true
136
- const variable = resolveVariable(context.sourceCode, parameter)
137
- return variable && !variable.references.some((reference) => reference.isWrite() && !reference.init
138
- && reference.identifier.range[0] < call.range[1])
139
- }
140
-
143
+ const parameter = key.raw ? call.arguments[1] : key.parameter;
144
+ if (parameter?.type !== "Identifier")
145
+ return true;
146
+ const variable = resolveVariable(context.sourceCode, parameter);
147
+ return variable !== null && !variable.references.some((reference) => reference.isWrite() && !reference.init
148
+ && reference.identifier.range[0] < call.range[1]);
149
+ };
141
150
  /** Scalar/DTO claims are the first statement; a raw intake may first bind its decoded key. */
142
151
  const claimsBeforeWork = (context, body, statement, key, call) => {
143
- const index = body.body.indexOf(statement)
144
- if (index === 0) return true
145
- if (index < 0 || !key.raw) return false
146
- const dependencies = new Set()
152
+ const index = body.body.findIndex((entry) => entry === statement);
153
+ if (index === 0)
154
+ return true;
155
+ if (index < 0 || !key.raw)
156
+ return false;
157
+ const dependencies = new Set();
147
158
  const read = (expression) => {
148
- if (!expression) return
159
+ if (!expression)
160
+ return;
149
161
  walk(expression, (node) => {
150
- if (node.type !== "Identifier") return
151
- const variable = resolveVariable(context.sourceCode, node)
152
- if (!variable || dependencies.has(variable)) return
153
- dependencies.add(variable)
154
- for (const definition of variable.defs) if (definition.type === "Variable") read(definition.node.init)
155
- }, { intoFunctions: false })
156
- }
157
- read(call.arguments[1])
162
+ if (node.type !== "Identifier")
163
+ return;
164
+ const variable = resolveVariable(context.sourceCode, node);
165
+ if (!variable || dependencies.has(variable))
166
+ return;
167
+ dependencies.add(variable);
168
+ for (const definition of variable.defs)
169
+ if (definition.type === "Variable")
170
+ read(definition.node.init);
171
+ }, { intoFunctions: false });
172
+ };
173
+ read(call.arguments[1]);
158
174
  return body.body.slice(0, index).every((entry) => entry.type === "VariableDeclaration" && entry.kind === "const"
159
- && entry.declarations.every((declaration) => declaration.id.type === "Identifier" && dependencies.has(resolveVariable(context.sourceCode, declaration.id))))
160
- }
161
-
175
+ && entry.declarations.every((declaration) => declaration.id.type === "Identifier" && dependencies.has(resolveVariable(context.sourceCode, declaration.id))));
176
+ };
162
177
  /** A claim cannot be made conditionally or after another operation in its own statement. */
163
178
  const priorWork = (expression, call) => {
164
- let found = false
179
+ let found = false;
165
180
  walk(expression, (node) => {
166
181
  if (node !== call && ["CallExpression", "NewExpression", "AssignmentExpression", "UpdateExpression", "ConditionalExpression", "LogicalExpression"].includes(node.type)
167
- && node.range[1] < call.range[1]) found = true
168
- }, { intoFunctions: false })
169
- return found
170
- }
171
-
182
+ && node.range[1] < call.range[1])
183
+ found = true;
184
+ }, { intoFunctions: false });
185
+ return found;
186
+ };
172
187
  /** Select TypeORM's actual inline transaction callback, never a later ignored callback. */
173
188
  const claimBody = (context, body) => {
174
- if (body.body.length !== 1) return { body, manager: null }
175
- const statement = body.body[0]
189
+ if (body.body.length !== 1)
190
+ return { body, manager: null };
191
+ const [statement] = body.body;
192
+ if (!statement)
193
+ return { body, manager: null };
176
194
  const expression = statement.type === "ReturnStatement" ? statement.argument
177
- : statement.type === "ExpressionStatement" && statement.expression.type === "AwaitExpression" ? statement.expression : null
178
- const call = expression?.type === "AwaitExpression" ? expression.argument : expression
179
- const callee = call?.callee
180
- if (call?.type !== "CallExpression" || callee.type !== "MemberExpression" || callee.computed
195
+ : statement.type === "ExpressionStatement" && statement.expression.type === "AwaitExpression" ? statement.expression : null;
196
+ const call = expression?.type === "AwaitExpression" ? expression.argument : expression;
197
+ if (call?.type !== "CallExpression")
198
+ return { body, manager: null };
199
+ const callee = call.callee;
200
+ if (callee.type !== "MemberExpression" || callee.computed
181
201
  || callee.property.name !== "transaction" || !isPackageType(context, callee.object, "EntityManager", "typeorm")
182
- || priorWork(call, call)) return { body, manager: null }
183
- const first = call.arguments[0]
202
+ || priorWork(call, call))
203
+ return { body, manager: null };
204
+ const first = call.arguments[0];
184
205
  const callback = call.arguments.length === 1 ? first
185
- : call.arguments.length === 2 && first.type === "Literal"
186
- && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.value) ? call.arguments[1] : null
187
- if (!callback || !["ArrowFunctionExpression", "FunctionExpression"].includes(callback.type)
188
- || !callback.async || callback.body.type !== "BlockStatement" || callback.params.length !== 1) return { body, manager: null }
189
- const manager = callback.params[0]
190
- return manager.type === "Identifier" && isPackageType(context, manager, "EntityManager", "typeorm")
191
- ? { body: callback.body, manager } : { body, manager: null }
192
- }
193
-
206
+ : call.arguments.length === 2 && first?.type === "Literal" && typeof first.value === "string"
207
+ && ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.value) ? call.arguments[1] : null;
208
+ if (!callback || (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression")
209
+ || !callback.async || callback.body.type !== "BlockStatement" || callback.params.length !== 1)
210
+ return { body, manager: null };
211
+ const manager = callback.params[0];
212
+ return manager?.type === "Identifier" && isPackageType(context, manager, "EntityManager", "typeorm")
213
+ ? { body: callback.body, manager } : { body, manager: null };
214
+ };
194
215
  /** Match an immediate false refusal with no work before the return. */
195
216
  const rejectsDuplicate = (context, awaited, body) => {
196
217
  const rejects = (test, target) => test?.type === "UnaryExpression" && test.operator === "!" && (test.argument === target || sameBinding(context, test.argument, target))
197
218
  || test?.type === "BinaryExpression" && test.operator === "==="
198
219
  && ((test.left === target && test.right.type === "Literal" && test.right.value === false)
199
- || (test.right === target && test.left.type === "Literal" && test.left.value === false))
220
+ || (test.right === target && test.left.type === "Literal" && test.left.value === false));
200
221
  const returns = (statement) => statement?.type === "ReturnStatement" && !statement.argument
201
- || statement?.type === "BlockStatement" && statement.body.length === 1 && returns(statement.body[0])
202
- const parent = awaited.parent
203
- if (["UnaryExpression", "BinaryExpression"].includes(parent.type)) {
204
- const branch = parent.parent
205
- return body.body.includes(branch) && branch.type === "IfStatement" && rejects(branch.test, awaited) && returns(branch.consequent)
222
+ || statement?.type === "BlockStatement" && statement.body.length === 1 && returns(statement.body[0]);
223
+ const parent = awaited.parent;
224
+ if (parent.type === "UnaryExpression" || parent.type === "BinaryExpression") {
225
+ const branch = parent.parent;
226
+ return body.body.some((entry) => entry === branch) && branch.type === "IfStatement" && rejects(branch.test, awaited) && returns(branch.consequent);
206
227
  }
207
- if (parent.type !== "VariableDeclarator" || parent.id.type !== "Identifier" || parent.init !== awaited) return false
208
- const declaration = parent.parent
209
- const index = body.body.indexOf(declaration)
210
- const branch = body.body[index + 1]
228
+ if (parent.type !== "VariableDeclarator" || parent.id.type !== "Identifier" || parent.init !== awaited)
229
+ return false;
230
+ const declaration = parent.parent;
231
+ const index = body.body.indexOf(declaration);
232
+ const branch = body.body[index + 1];
211
233
  return index !== -1 && declaration.declarations.length === 1
212
- && branch?.type === "IfStatement" && rejects(branch.test, parent.id) && returns(branch.consequent)
213
- }
214
-
234
+ && branch?.type === "IfStatement" && rejects(branch.test, parent.id) && returns(branch.consequent);
235
+ };
215
236
  /** A public service intake with a delivery key claims that same key first and refuses replays. */
216
237
  export const webhookInboxKey = {
217
238
  meta: {
@@ -224,26 +245,32 @@ export const webhookInboxKey = {
224
245
  },
225
246
  },
226
247
  create(context) {
227
- const hfs = hfsOf(context)
228
- const slot = hfs.slotOf(context.filename)
229
- if (!slot || slot.startsWith("be.tests.") || !baseName(context.filename).endsWith(".service.ts")) return {}
230
- if (slot.startsWith("be.platform") && ["event-bus", "http-security"].includes(ownerNameOf(hfs, context.filename))) return {}
248
+ const hfs = hfsOf(context);
249
+ const slot = hfs.slotOf(context.filename);
250
+ if (!slot || slot.startsWith("be.tests.") || !baseName(context.filename).endsWith(".service.ts"))
251
+ return {};
252
+ if (slot.startsWith("be.platform") && ["event-bus", "http-security"].includes(ownerNameOf(hfs, context.filename) ?? ""))
253
+ return {};
231
254
  return {
232
255
  MethodDefinition(method) {
233
256
  if (method.kind !== "method" || method.static || method.key.type === "PrivateIdentifier" || !method.value.body
234
- || ["private", "protected"].includes(method.accessibility)) return
257
+ || method.accessibility === "private" || method.accessibility === "protected")
258
+ return;
235
259
  // A service no webhook door reaches is an ordinary domain service, whatever its first parameter is called.
236
- if (!isDoorIntake(context, hfs, method)) return
237
- const key = deliveryKey(context, method)
238
- if (!key) return
239
- if (webhookIntakeProcessesDelivery(context, hfs, method)) context.report({ node: method.key, messageId: "handoff" })
240
- const { body, manager } = claimBody(context, method.value.body)
241
- const awaited = firstAwait(body)
242
- const call = awaited?.argument
243
- const parent = awaited?.parent
260
+ if (!isDoorIntake(context, hfs, method))
261
+ return;
262
+ const key = deliveryKey(context, method);
263
+ if (!key)
264
+ return;
265
+ if (webhookIntakeProcessesDelivery(context, hfs, method))
266
+ context.report({ node: method.key, messageId: "handoff" });
267
+ const { body, manager } = claimBody(context, method.value.body);
268
+ const awaited = firstAwait(body);
269
+ const call = awaited?.argument;
270
+ const parent = awaited?.parent;
244
271
  const statement = parent?.type === "VariableDeclarator" ? parent.parent
245
- : ["UnaryExpression", "BinaryExpression"].includes(parent?.type) ? parent.parent : parent
246
- const claims = call?.type === "CallExpression" && !call.optional
272
+ : parent?.type === "UnaryExpression" || parent?.type === "BinaryExpression" ? parent.parent : parent;
273
+ const claims = awaited !== null && call?.type === "CallExpression" && !call.optional
247
274
  && call.callee.type === "MemberExpression" && !call.callee.computed && !call.callee.optional
248
275
  && call.callee.property.name === "claim" && call.arguments.length >= 2
249
276
  && isOwnedType(context, call.callee.object, { name: "Inbox", capability: "inbox", tier: "platform" })
@@ -252,9 +279,10 @@ export const webhookInboxKey = {
252
279
  && (!manager || sameBinding(context, call.arguments[2], manager))
253
280
  && claimsBeforeWork(context, body, statement, key, call)
254
281
  && !priorWork(statement, call)
255
- && rejectsDuplicate(context, awaited, body)
256
- if (!claims) context.report({ node: method.key, messageId: "key" })
282
+ && rejectsDuplicate(context, awaited, body);
283
+ if (!claims)
284
+ context.report({ node: method.key, messageId: "key" });
257
285
  },
258
- }
286
+ };
259
287
  },
260
- }
288
+ };
@@ -0,0 +1,4 @@
1
+ import type { Context, Node } from "./rule.js";
2
+ import type { HfsView } from "./hfs.js";
3
+ /** Inspect the linted intake method or the implementation resolved at a webhook door's domain call. */
4
+ export declare const webhookIntakeProcessesDelivery: (context: Context, hfs: HfsView, node: Node) => boolean;