@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
@@ -20,24 +20,22 @@
20
20
  * A combined domain proof and intake counts as the delegation. `.spec.ts` and `.d.ts` are never judged, and neither is a file whose tier is not
21
21
  * `feature` or whose role is not a thin role. A clean thin file is never flagged: that is the bar.
22
22
  */
23
- import { keyName, walk } from "./lib/ast.mjs"
24
- import { aliasTarget, callsOf, decoratorsFrom, injectedMembers } from "./lib/doors.mjs"
25
- import { hfsOf } from "./lib/hfs.mjs"
26
- import { importOf, isImportedFrom } from "./lib/import-source.mjs"
27
- import { baseName, isLoggerType, isOwnedType } from "./lib/ports.mjs"
28
- import { firstWebhookVerification, isWebhookDomainServiceType } from "./lib/webhook-verifiers.mjs"
29
- import { isWebhookForbiddenReceiver } from "./lib/webhook-handoff.mjs"
30
- import { isProviderAcknowledgement } from "./lib/webhook-ack.mjs"
31
-
23
+ import { keyName, walk } from "./lib/ast.js";
24
+ import { aliasTarget, callsOf, decoratorsFrom, injectedMembers } from "./lib/doors.js";
25
+ import { hfsOf } from "./lib/hfs.js";
26
+ import { importOf, isImportedFrom } from "./lib/import-source.js";
27
+ import { baseName, isLoggerType, isOwnedType } from "./lib/ports.js";
28
+ import { firstWebhookVerification, isWebhookDomainServiceType } from "./lib/webhook-verifiers.js";
29
+ import { isWebhookForbiddenReceiver } from "./lib/webhook-handoff.js";
30
+ import { isProviderAcknowledgement } from "./lib/webhook-ack.js";
32
31
  /** The statements and expressions that are a decision, a repetition or an exit: none lives in a thin file. */
33
- const BRANCH_NODES = new Set(["IfStatement", "SwitchStatement", "ConditionalExpression", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement", "TryStatement", "ThrowStatement", "LogicalExpression"])
34
-
32
+ const BRANCH_NODES = new Set(["IfStatement", "SwitchStatement", "ConditionalExpression", "ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement", "TryStatement", "ThrowStatement", "LogicalExpression"]);
35
33
  /** The expressions that compute a value (a `TemplateLiteral` with an expression joins them). */
36
- const COMPUTE_NODES = new Set(["BinaryExpression", "UnaryExpression", "UpdateExpression", "AssignmentExpression"])
37
-
34
+ const COMPUTE_NODES = new Set(["BinaryExpression", "UnaryExpression", "UpdateExpression", "AssignmentExpression"]);
38
35
  /** The nodes a function can be: the walk for calls and the nesting test use the same set. */
39
- const FUNCTION_NODES = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression", "MethodDefinition"])
40
-
36
+ const FUNCTION_NODES = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression", "MethodDefinition"]);
37
+ /** Whether a node is one of the `FUNCTION_NODES` types. */
38
+ const isFunctionRoot = (node) => FUNCTION_NODES.has(node.type);
41
39
  /** What one decision or loop node is called in a message. */
42
40
  const BRANCH_WHAT = {
43
41
  IfStatement: "an `if`",
@@ -50,47 +48,37 @@ const BRANCH_WHAT = {
50
48
  DoWhileStatement: "a `do-while`",
51
49
  TryStatement: "a `try`",
52
50
  ThrowStatement: "a `throw`",
53
- }
54
-
51
+ };
55
52
  /** The wraps a call may sit under while still being the call of its statement. */
56
- const STATEMENT_WRAPPERS = new Set(["AwaitExpression", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "ChainExpression"])
57
-
53
+ const STATEMENT_WRAPPERS = new Set(["AwaitExpression", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "ChainExpression"]);
58
54
  /** The closed-vocabulary role a file name carries (`<name>.<role>.ts` gives `<role>`), or null. */
59
- const roleOf = (filename) => /\.([a-z][a-z0-9-]*)\.ts$/.exec(baseName(filename))?.[1] ?? null
60
-
55
+ const roleOf = (filename) => /\.([a-z][a-z0-9-]*)\.ts$/.exec(baseName(filename))?.[1] ?? null;
61
56
  /** The `WebhookSignatureService` of `platform/http-security` - the `verify` a webhook door may call. */
62
- const isSignatureReceiver = (context, node) => isOwnedType(context, node, { name: "WebhookSignatureService", capability: "http-security", tier: "platform" })
63
-
57
+ const isSignatureReceiver = (context, node) => isOwnedType(context, node, { name: "WebhookSignatureService", capability: "http-security", tier: "platform" });
64
58
  /** The shape conversions a mapper may make on a value it received: a collection mapped item by item and a date written as text. They decide nothing and compute nothing. */
65
- const MAPPER_SHAPE_METHODS = new Set(["map", "toISOString"])
66
-
59
+ const MAPPER_SHAPE_METHODS = new Set(["map", "toISOString"]);
67
60
  /** The `JobClaims` port of `platform/jobs` - the fence a job step records itself through (`advance`, `runKey`): bookkeeping the fenced-job pattern requires, free beside the step's one delegating call. */
68
- const isClaimsReceiver = (context, node) => isOwnedType(context, node, { name: "JobClaims", capability: "jobs", tier: "platform" })
69
-
61
+ const isClaimsReceiver = (context, node) => isOwnedType(context, node, { name: "JobClaims", capability: "jobs", tier: "platform" });
70
62
  /** The `Logger` port of `platform/logging` - the one call that is always free. */
71
- const isLoggerReceiver = isLoggerType
72
-
63
+ const isLoggerReceiver = isLoggerType;
73
64
  /** A direct, non-computed member call; other callee shapes keep their ordinary call classification. */
74
- const memberOf = (callee) => callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee : null
75
-
65
+ const memberOf = (callee) => callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee : null;
76
66
  /** Nest-commander's group help is transport bookkeeping in a CLI door. */
77
67
  const isCliHelp = (role, member) => role === "cli" && member?.property.name === "help" && member.object.type === "MemberExpression"
78
- && member.object.object.type === "ThisExpression" && member.object.property.type === "Identifier" && member.object.property.name === "command"
79
-
68
+ && member.object.object.type === "ThisExpression" && member.object.property.type === "Identifier" && member.object.property.name === "command";
80
69
  /** A signed number inside the validated immutable provider literal is data, rather than door computation. */
81
70
  const isLiteralAcknowledgementInitializer = (context, hfs, node) => {
82
- let child = node
71
+ let child = node;
83
72
  for (let parent = node.parent; parent; parent = parent.parent) {
84
- if (parent.type === "VariableDeclarator") return parent.init === child && isProviderAcknowledgement(context, hfs, parent.id)
85
- child = parent
73
+ if (parent.type === "VariableDeclarator")
74
+ return parent.init === child && isProviderAcknowledgement(context, hfs, parent.id);
75
+ child = parent;
86
76
  }
87
- return false
88
- }
89
-
77
+ return false;
78
+ };
90
79
  /** A signed numeric literal in a TypeScript type annotation executes no expression. */
91
80
  const isSignedNumericLiteralType = (node) => node.type === "UnaryExpression" && node.parent?.type === "TSLiteralType"
92
- && ["+", "-"].includes(node.operator) && node.argument.type === "Literal" && typeof node.argument.value === "number"
93
-
81
+ && ["+", "-"].includes(node.operator) && node.argument.type === "Literal" && typeof node.argument.value === "number";
94
82
  /** The name of a thin file's law is `feature-thin` (R203). */
95
83
  export const featureThin = {
96
84
  meta: {
@@ -105,32 +93,37 @@ export const featureThin = {
105
93
  },
106
94
  },
107
95
  create(context) {
108
- const hfs = hfsOf(context)
109
- const name = baseName(context.filename)
110
- if (name.endsWith(".spec.ts") || name.endsWith(".d.ts")) return {}
111
- const role = roleOf(name)
112
- if (role === null || !(hfs.ruleParams.thinRoles ?? []).includes(role)) return {}
113
- if (hfs.tierOf(context.filename) !== "feature") return {}
114
- const sourceCode = context.sourceCode
115
- const mapperFile = role === "mapper"
116
- const webhookDoor = role === "webhook" && hfs.slotOf(context.filename) === "be.feature.webhooks.http"
117
-
96
+ const hfs = hfsOf(context);
97
+ const name = baseName(context.filename);
98
+ if (name.endsWith(".spec.ts") || name.endsWith(".d.ts"))
99
+ return {};
100
+ const role = roleOf(name);
101
+ if (role === null || !(hfs.ruleParams.thinRoles ?? []).includes(role))
102
+ return {};
103
+ if (hfs.tierOf(context.filename) !== "feature")
104
+ return {};
105
+ const sourceCode = context.sourceCode;
106
+ const mapperFile = role === "mapper";
107
+ const webhookDoor = role === "webhook" && hfs.slotOf(context.filename) === "be.feature.webhooks.http";
118
108
  /** The injected member names of a class: constructor parameter properties and properties carrying an injector decorator. */
119
- const memberNames = new Map()
109
+ const memberNames = new Map();
120
110
  const injectedNamesOf = (classNode) => {
121
- if (memberNames.has(classNode)) return memberNames.get(classNode)
122
- const names = new Set()
111
+ const known = memberNames.get(classNode);
112
+ if (known)
113
+ return known;
114
+ const names = new Set();
123
115
  for (const { node } of injectedMembers(context, classNode)) {
124
- if (node.type === "TSParameterProperty" && node.parameter.type === "Identifier") names.add(node.parameter.name)
116
+ if (node.type === "TSParameterProperty" && node.parameter.type === "Identifier")
117
+ names.add(node.parameter.name);
125
118
  else if (node.type === "PropertyDefinition") {
126
- const key = keyName(node.key)
127
- if (key !== null) names.add(key)
119
+ const key = keyName(node.key);
120
+ if (key !== null)
121
+ names.add(key);
128
122
  }
129
123
  }
130
- memberNames.set(classNode, names)
131
- return names
132
- }
133
-
124
+ memberNames.set(classNode, names);
125
+ return names;
126
+ };
134
127
  /**
135
128
  * The class `this` binds at a node's position: the nearest enclosing class, or null when a non-arrow
136
129
  * function or an object-literal method rebinds `this` in between (a method's own `FunctionExpression`
@@ -138,157 +131,178 @@ export const featureThin = {
138
131
  */
139
132
  const thisClassOf = (node) => {
140
133
  for (let parent = node.parent; parent; parent = parent.parent) {
141
- if (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") return parent
142
- if (parent.type === "FunctionDeclaration") return null
143
- if (parent.type === "FunctionExpression" && parent.parent?.type !== "MethodDefinition") return null
134
+ if (parent.type === "ClassDeclaration" || parent.type === "ClassExpression")
135
+ return parent;
136
+ if (parent.type === "FunctionDeclaration")
137
+ return null;
138
+ if (parent.type === "FunctionExpression" && parent.parent?.type !== "MethodDefinition")
139
+ return null;
144
140
  }
145
- return null
146
- }
147
-
141
+ return null;
142
+ };
148
143
  /** The member name of `this.<member>` the call's receiver names, when it is an injected member of the enclosing class. */
149
144
  const injectedMemberOf = (object, call) => {
150
- if (object.type !== "MemberExpression" || object.computed || object.object.type !== "ThisExpression" || object.property.type !== "Identifier") return null
151
- const classNode = thisClassOf(call)
152
- if (classNode === null) return null
153
- const member = object.property.name
154
- return injectedNamesOf(classNode).has(member) ? member : null
155
- }
156
-
145
+ if (object.type !== "MemberExpression" || object.computed || object.object.type !== "ThisExpression" || object.property.type !== "Identifier")
146
+ return null;
147
+ const classNode = thisClassOf(call);
148
+ if (classNode === null)
149
+ return null;
150
+ const member = object.property.name;
151
+ return injectedNamesOf(classNode).has(member) ? member : null;
152
+ };
157
153
  /** True for an imported pure `*.mapper.ts` function, resolved through any facade re-exports to its declaration. */
158
154
  const isMapperCall = (callee) => {
159
- if (callee.type !== "Identifier" || importOf(context, callee) === null) return false
160
- const declarations = aliasTarget(context, callee)?.getDeclarations() ?? []
161
- return declarations.length > 0 && declarations.every((declaration) => roleOf(declaration.getSourceFile().fileName) === "mapper")
162
- }
163
-
155
+ if (callee.type !== "Identifier" || importOf(context, callee) === null)
156
+ return false;
157
+ const declarations = aliasTarget(context, callee)?.getDeclarations() ?? [];
158
+ return declarations.length > 0 && declarations.every((declaration) => roleOf(declaration.getSourceFile().fileName) === "mapper");
159
+ };
164
160
  /** True for a call `f(...)` where `f` is imported and its declaration lives outside the feature tier (a function of the modules). */
165
161
  const isModulesCall = (callee) => {
166
- if (callee.type !== "Identifier" || importOf(context, callee) === null) return false
167
- const symbol = aliasTarget(context, callee)
168
- return (symbol?.getDeclarations() ?? []).some((declaration) => hfs.tierOf(declaration.getSourceFile().fileName) !== "feature")
169
- }
170
-
162
+ if (callee.type !== "Identifier" || importOf(context, callee) === null)
163
+ return false;
164
+ const symbol = aliasTarget(context, callee);
165
+ return (symbol?.getDeclarations() ?? []).some((declaration) => hfs.tierOf(declaration.getSourceFile().fileName) !== "feature");
166
+ };
171
167
  /** True when the call IS the statement it sits in: `f(...)`, `await f(...)`, `return (await) f(...)`, or the whole body of a concise arrow. */
172
168
  const isStatementCall = (call) => {
173
- let current = call
174
- while (STATEMENT_WRAPPERS.has(current.parent?.type)) current = current.parent
175
- const parent = current.parent
176
- return parent?.type === "ExpressionStatement" || parent?.type === "ReturnStatement" || (parent?.type === "ArrowFunctionExpression" && parent.body === current)
177
- }
178
-
169
+ let current = call;
170
+ while (current.parent && STATEMENT_WRAPPERS.has(current.parent.type))
171
+ current = current.parent;
172
+ const parent = current.parent;
173
+ return parent?.type === "ExpressionStatement" || parent?.type === "ReturnStatement" || (parent?.type === "ArrowFunctionExpression" && parent.body === current);
174
+ };
179
175
  /**
180
176
  * What one call is to a thin file: `delegating` (the one call into the modules a file may make),
181
177
  * `free` (a mapper, a logger method, a webhook `verify`, a job step's `JobClaims` fence call, a modules function in a mapping position)
182
178
  * or `call` (a call a thin file does not make). A `mapper` file holds only mapper calls and `new`.
183
179
  */
184
180
  const classifyMapperOrCli = (member, call) => {
185
- if (mapperFile && member !== null && MAPPER_SHAPE_METHODS.has(member.property.name) && injectedMemberOf(member.object, call) === null) return "free"
186
- if (isCliHelp(role, member)) return "free"
187
- return mapperFile ? "call" : null
188
- }
189
-
181
+ if (mapperFile && member !== null && MAPPER_SHAPE_METHODS.has(member.property.name) && injectedMemberOf(member.object, call) === null)
182
+ return "free";
183
+ if (isCliHelp(role, member))
184
+ return "free";
185
+ return mapperFile ? "call" : null;
186
+ };
190
187
  /** The free bookkeeping calls beside an injected member's one delegate. */
191
188
  const classifyInjected = (member) => {
192
- if (webhookDoor && isWebhookForbiddenReceiver(context, hfs, member.object)) return "call"
193
- if (isLoggerReceiver(context, member.object)) return "free"
194
- if (role === "webhook" && member.property.name === "verify" && isSignatureReceiver(context, member.object)) return "free"
195
- if (role === "step" && isClaimsReceiver(context, member.object)) return "free"
196
- return "delegating"
197
- }
198
-
189
+ if (webhookDoor && isWebhookForbiddenReceiver(context, hfs, member.object))
190
+ return "call";
191
+ if (isLoggerReceiver(context, member.object))
192
+ return "free";
193
+ if (role === "webhook" && member.property.name === "verify" && isSignatureReceiver(context, member.object))
194
+ return "free";
195
+ if (role === "step" && isClaimsReceiver(context, member.object))
196
+ return "free";
197
+ return "delegating";
198
+ };
199
199
  const classify = (call) => {
200
- const callee = call.callee
201
- if (callee.type === "Identifier" && isMapperCall(callee)) return "free"
202
- const member = memberOf(callee)
203
- const special = classifyMapperOrCli(member, call)
204
- if (special !== null) return special
205
- if (member !== null && injectedMemberOf(member.object, call) !== null) return classifyInjected(member)
206
- if (callee.type === "Identifier" && isModulesCall(callee)) return isStatementCall(call) ? "delegating" : "free"
207
- return "call"
208
- }
209
-
200
+ const callee = call.callee;
201
+ if (callee.type === "Identifier" && isMapperCall(callee))
202
+ return "free";
203
+ const member = memberOf(callee);
204
+ const special = classifyMapperOrCli(member, call);
205
+ if (special !== null)
206
+ return special;
207
+ if (member !== null && injectedMemberOf(member.object, call) !== null)
208
+ return classifyInjected(member);
209
+ if (callee.type === "Identifier" && isModulesCall(callee))
210
+ return isStatementCall(call) ? "delegating" : "free";
211
+ return "call";
212
+ };
210
213
  /** Every root function of the file (a method body, function or arrow not nested in another function and not inside a decorator subtree). */
211
214
  const rootFunctionsOf = (program) => {
212
- const roots = []
215
+ const roots = [];
213
216
  walk(program, (node) => {
214
- if (!FUNCTION_NODES.has(node.type)) return
217
+ if (!isFunctionRoot(node))
218
+ return;
215
219
  for (let parent = node.parent; parent; parent = parent.parent) {
216
- if (parent.type === "Decorator" || FUNCTION_NODES.has(parent.type)) return
220
+ if (parent.type === "Decorator" || FUNCTION_NODES.has(parent.type))
221
+ return;
217
222
  }
218
- if (node.type === "MethodDefinition" && node.kind === "constructor") return
219
- roots.push(node)
220
- })
221
- return roots
222
- }
223
-
223
+ if (node.type === "MethodDefinition" && node.kind === "constructor")
224
+ return;
225
+ roots.push(node);
226
+ });
227
+ return roots;
228
+ };
224
229
  /** The name a `many` message reports for a function root. */
225
230
  const nameOf = (fn) => {
226
- if (fn.type === "MethodDefinition") return keyName(fn.key) ?? "the method"
227
- if (fn.type === "FunctionDeclaration" && fn.id?.type === "Identifier") return fn.id.name
228
- const parent = fn.parent
229
- if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier") return parent.id.name
230
- if ((parent?.type === "PropertyDefinition" || parent?.type === "Property") && keyName(parent.key)) return keyName(parent.key)
231
- return "the function"
232
- }
233
-
234
- const visitors = {}
231
+ if (fn.type === "MethodDefinition")
232
+ return keyName(fn.key) ?? "the method";
233
+ if (fn.type === "FunctionDeclaration" && fn.id?.type === "Identifier")
234
+ return fn.id.name;
235
+ const parent = fn.parent;
236
+ if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier")
237
+ return parent.id.name;
238
+ if ((parent?.type === "PropertyDefinition" || parent?.type === "Property") && keyName(parent.key))
239
+ return keyName(parent.key);
240
+ return "the function";
241
+ };
242
+ const visitors = {};
235
243
  for (const type of BRANCH_NODES) {
236
- visitors[type] = (node) => context.report({ node, messageId: "branch", data: { what: type === "LogicalExpression" ? `a \`${node.operator}\`` : BRANCH_WHAT[type], role } })
244
+ visitors[type] = (node) => context.report({ node, messageId: "branch", data: { what: node.type === "LogicalExpression" ? `a \`${node.operator}\`` : BRANCH_WHAT[type], role } });
237
245
  }
238
246
  for (const type of COMPUTE_NODES) {
239
247
  visitors[type] = (node) => {
240
- if (isSignedNumericLiteralType(node)) return
241
- if (webhookDoor && isLiteralAcknowledgementInitializer(context, hfs, node)) return
242
- context.report({ node, messageId: "compute", data: { what: `an \`${node.operator}\``, role } })
243
- }
248
+ if (isSignedNumericLiteralType(node))
249
+ return;
250
+ if (webhookDoor && isLiteralAcknowledgementInitializer(context, hfs, node))
251
+ return;
252
+ context.report({ node, messageId: "compute", data: { what: `an \`${node.operator}\``, role } });
253
+ };
244
254
  }
245
255
  visitors.TemplateLiteral = (node) => {
246
- if (node.expressions.length > 0) context.report({ node, messageId: "compute", data: { what: "a template literal with an expression", role } })
247
- }
256
+ if (node.expressions.length > 0)
257
+ context.report({ node, messageId: "compute", data: { what: "a template literal with an expression", role } });
258
+ };
248
259
  visitors["Program:exit"] = (program) => {
249
260
  for (const root of rootFunctionsOf(program)) {
250
- const body = root.type === "MethodDefinition" ? root.value?.body : root.body
251
- if (!body) continue
261
+ const body = root.type === "MethodDefinition" ? root.value?.body : root.body;
262
+ if (!body)
263
+ continue;
252
264
  const proof = role === "webhook" && hfs.slotOf(context.filename) === "be.feature.webhooks.http" && root.type === "MethodDefinition" && decoratorsFrom(context, root, "@nestjs/common", "Post").length > 0
253
- ? firstWebhookVerification(context, hfs, root) : null
254
- const separateDomainProof = proof !== null && callsOf(root).filter(({ receiver }) => receiver !== null && isWebhookDomainServiceType(context, hfs, receiver)).length > 1
255
- let delegating = 0
265
+ ? firstWebhookVerification(context, hfs, root) : null;
266
+ const separateDomainProof = proof !== null && root.type === "MethodDefinition" && callsOf(root).filter(({ receiver }) => receiver !== null && isWebhookDomainServiceType(context, hfs, receiver)).length > 1;
267
+ let delegating = 0;
256
268
  walk(body, (node) => {
257
- if (node.type !== "CallExpression") return
258
- const classified = classify(node)
259
- const kind = separateDomainProof && node === proof && classified === "delegating" ? "free" : classified
260
- if (kind === "call") context.report({ node, messageId: "call", data: { what: sourceCode.getText(node.callee), webhook: role === "webhook" ? ", plus `verify` of the signature service" : "" } })
269
+ if (node.type !== "CallExpression")
270
+ return;
271
+ const classified = classify(node);
272
+ const kind = separateDomainProof && node === proof && classified === "delegating" ? "free" : classified;
273
+ if (kind === "call")
274
+ context.report({ node, messageId: "call", data: { what: sourceCode.getText(node.callee), webhook: role === "webhook" ? ", plus `verify` of the signature service" : "" } });
261
275
  else if (kind === "delegating") {
262
- delegating += 1
263
- if (delegating === 2) context.report({ node, messageId: "many", data: { name: nameOf(root) } })
276
+ delegating += 1;
277
+ if (delegating === 2)
278
+ context.report({ node, messageId: "many", data: { name: nameOf(root) } });
264
279
  }
265
- })
280
+ });
266
281
  }
267
- }
268
- return visitors
282
+ };
283
+ return visitors;
269
284
  },
270
- }
271
-
285
+ };
272
286
  /** A declaration's signed numeric literal is still data, including an enum member or a constant. */
273
287
  const isSignedNumericLiteral = (node) => node.type === "UnaryExpression" && ["+", "-"].includes(node.operator)
274
- && node.argument.type === "Literal" && typeof node.argument.value === "number"
275
-
288
+ && node.argument.type === "Literal" && typeof node.argument.value === "number";
276
289
  /** A DTO's decorator application declares metadata; calls inside its arguments remain ordinary executable calls. */
277
- const isDecoratorApplication = (node) => node.parent?.type === "Decorator" && node.parent.expression === node
278
-
290
+ const isDecoratorApplication = (node) => node.parent?.type === "Decorator" && node.parent.expression === node;
279
291
  /** A Nest command/query constructor initializes its data base through the required, argument-free super call. */
280
292
  const isCqrsDataConstructor = (context, node) => {
281
- if (node.callee.type !== "Super" || node.arguments.length !== 0) return false
293
+ if (node.callee.type !== "Super" || node.arguments.length !== 0)
294
+ return false;
282
295
  for (let parent = node.parent; parent; parent = parent.parent) {
283
296
  if (parent.type === "MethodDefinition") {
284
- const declaration = parent.parent?.parent
285
- return parent.kind === "constructor" && isImportedFrom(context, declaration?.superClass, "@nestjs/cqrs", ["Command", "Query"])
297
+ const declaration = parent.parent?.parent;
298
+ const superClass = declaration?.type === "ClassDeclaration" || declaration?.type === "ClassExpression" ? declaration.superClass : undefined;
299
+ return parent.kind === "constructor" && isImportedFrom(context, superClass, "@nestjs/cqrs", ["Command", "Query"]);
286
300
  }
287
- if (["FunctionDeclaration", "ArrowFunctionExpression"].includes(parent.type)) return false
301
+ if (["FunctionDeclaration", "ArrowFunctionExpression"].includes(parent.type))
302
+ return false;
288
303
  }
289
- return false
290
- }
291
-
304
+ return false;
305
+ };
292
306
  /**
293
307
  * `registerEnumType(...)` of `@nestjs/graphql` at module top level of a `<name>.type.ts` file of the GraphQL transport slot
294
308
  * (`be.transport.graphql`). It declares a schema enum: `starci app emit` loads only the resolver, scalar and `include` module files, so the
@@ -298,8 +312,7 @@ const isCqrsDataConstructor = (context, node) => {
298
312
  const isEnumRegistration = (context, hfs, node, role) => role === "type"
299
313
  && hfs.slotOf(context.filename) === "be.transport.graphql"
300
314
  && node.parent?.type === "ExpressionStatement" && node.parent.parent?.type === "Program"
301
- && isImportedFrom(context, node.callee, "@nestjs/graphql", ["registerEnumType"])
302
-
315
+ && isImportedFrom(context, node.callee, "@nestjs/graphql", ["registerEnumType"]);
303
316
  /** Non-door feature roles declare data; renaming a policy or a guard must never hide business logic from R203. */
304
317
  export const featureLogicRole = {
305
318
  meta: {
@@ -311,45 +324,49 @@ export const featureLogicRole = {
311
324
  },
312
325
  },
313
326
  create(context) {
314
- const hfs = hfsOf(context)
315
- const name = baseName(context.filename)
316
- if (name.endsWith(".spec.ts") || name.endsWith(".d.ts")) return {}
317
- const role = roleOf(name)
318
- if (role === null || (hfs.ruleParams.thinRoles ?? []).includes(role)) return {}
319
- if (hfs.tierOf(context.filename) !== "feature") return {}
327
+ const hfs = hfsOf(context);
328
+ const name = baseName(context.filename);
329
+ if (name.endsWith(".spec.ts") || name.endsWith(".d.ts"))
330
+ return {};
331
+ const role = roleOf(name);
332
+ if (role === null || (hfs.ruleParams.thinRoles ?? []).includes(role))
333
+ return {};
334
+ if (hfs.tierOf(context.filename) !== "feature")
335
+ return {};
320
336
  // The feature's Nest composition is governed by the module laws. A module suffix in support/ is still support.
321
- if (["module", "module-definition"].includes(role) && hfs.slotOf(context.filename) !== "be.feature.application.support") return {}
322
-
323
- const report = (node, what) => context.report({ node, messageId: "logic", data: { what, role } })
324
- const visitors = {}
337
+ if (["module", "module-definition"].includes(role) && hfs.slotOf(context.filename) !== "be.feature.application.support")
338
+ return {};
339
+ const report = (node, what) => context.report({ node, messageId: "logic", data: { what, role } });
340
+ const visitors = {};
325
341
  for (const type of BRANCH_NODES) {
326
- visitors[type] = (node) => report(node, type === "LogicalExpression" ? `a \`${node.operator}\`` : BRANCH_WHAT[type])
342
+ visitors[type] = (node) => report(node, node.type === "LogicalExpression" ? `a \`${node.operator}\`` : BRANCH_WHAT[type]);
327
343
  }
328
344
  for (const type of COMPUTE_NODES) {
329
345
  visitors[type] = (node) => {
330
- if (!isSignedNumericLiteral(node)) report(node, `an \`${node.operator}\``)
331
- }
346
+ if (!isSignedNumericLiteral(node))
347
+ report(node, `an \`${node.operator}\``);
348
+ };
332
349
  }
333
350
  visitors.TemplateLiteral = (node) => {
334
- if (node.expressions.length > 0) report(node, "a template literal with an expression")
335
- }
351
+ if (node.expressions.length > 0)
352
+ report(node, "a template literal with an expression");
353
+ };
336
354
  visitors.CallExpression = (node) => {
337
- if (!isDecoratorApplication(node) && !isCqrsDataConstructor(context, node) && !isEnumRegistration(context, hfs, node, role)) report(node, `the call \`${context.sourceCode.getText(node.callee)}\``)
338
- }
339
- visitors.TaggedTemplateExpression = (node) => report(node, `the tagged call \`${context.sourceCode.getText(node.tag)}\``)
340
- visitors.NewExpression = (node) => report(node, `the construction \`${context.sourceCode.getText(node.callee)}\``)
341
- return visitors
355
+ if (!isDecoratorApplication(node) && !isCqrsDataConstructor(context, node) && !isEnumRegistration(context, hfs, node, role))
356
+ report(node, `the call \`${context.sourceCode.getText(node.callee)}\``);
357
+ };
358
+ visitors.TaggedTemplateExpression = (node) => report(node, `the tagged call \`${context.sourceCode.getText(node.tag)}\``);
359
+ visitors.NewExpression = (node) => report(node, `the construction \`${context.sourceCode.getText(node.callee)}\``);
360
+ return visitors;
342
361
  },
343
- }
344
-
362
+ };
345
363
  /** The rules this law contributes to the plugin. */
346
364
  export const rules = {
347
365
  "feature-thin": featureThin,
348
366
  "feature-logic-role": featureLogicRole,
349
- }
350
-
367
+ };
351
368
  /** Every rule of this law at `error`. */
352
369
  export const recommended = {
353
370
  "starci-be/feature-thin": "error",
354
371
  "starci-be/feature-logic-role": "error",
355
- }
372
+ };
@@ -0,0 +1,7 @@
1
+ import type { Recommended, RuleModule, Rules } from "./lib/rule.js";
2
+ /** Functions, methods, constructors, accessors and callbacks all receive the same body budget. */
3
+ export declare const functionLineBudget: RuleModule;
4
+ /** The rule this law contributes to the plugin. */
5
+ export declare const rules: Rules;
6
+ /** The function budget is an error in both editions. */
7
+ export declare const recommended: Recommended;
@@ -1,12 +1,4 @@
1
- /**
2
- * R291 HFS_FUNCTION_BUDGET: every function body stays within the common line budget.
3
- *
4
- * Count the physical span of the body, including braces, comments, blank lines and nested functions.
5
- * Signatures and parameters are outside the body. An expression arrow has an expression body and
6
- * counts the expression and its wrapping parentheses, including comments and blanks inside them.
7
- */
8
- import { hfsOf } from "./lib/hfs.mjs"
9
-
1
+ import { hfsOf } from "./lib/hfs.js";
10
2
  /** Functions, methods, constructors, accessors and callbacks all receive the same body budget. */
11
3
  export const functionLineBudget = {
12
4
  meta: {
@@ -19,31 +11,36 @@ export const functionLineBudget = {
19
11
  },
20
12
  create(context) {
21
13
  // C08 adds this common parameter to the shipped manifest; keep the owner-decided cap while it lands.
22
- const max = hfsOf(context).ruleParams.functionLines ?? 80
23
- if (!Number.isInteger(max) || max < 1) throw new RangeError("ruleParams.functionLines must be a positive integer")
24
- const source = context.sourceCode || context.getSourceCode()
14
+ const max = hfsOf(context).ruleParams.functionLines ?? 80;
15
+ if (!Number.isInteger(max) || max < 1)
16
+ throw new RangeError("ruleParams.functionLines must be a positive integer");
17
+ const source = context.sourceCode || context.getSourceCode();
25
18
  const check = (node) => {
26
- if (!node.body) return
27
- let start = node.body.loc.start.line
28
- let end = node.body.loc.end.line
19
+ if (!node.body)
20
+ return;
21
+ let start = node.body.loc.start.line;
22
+ let end = node.body.loc.end.line;
29
23
  if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
30
- const arrow = source.getTokenBefore(node.body, { filter: (token) => token.value === "=>" })
31
- start = source.getTokenAfter(arrow, { includeComments: true }).loc.start.line
32
- end = node.loc.end.line
24
+ const arrow = source.getTokenBefore(node.body, { filter: (token) => token.value === "=>" });
25
+ // An expression arrow always holds its `=>` and a token after it; the guard only proves that to the types.
26
+ const after = arrow === null ? null : source.getTokenAfter(arrow, { includeComments: true });
27
+ if (after === null)
28
+ return;
29
+ start = after.loc.start.line;
30
+ end = node.loc.end.line;
33
31
  }
34
- const lines = end - start + 1
35
- if (lines > max) context.report({ node: node.body, messageId: "lines", data: { lines, max } })
36
- }
32
+ const lines = end - start + 1;
33
+ if (lines > max)
34
+ context.report({ node: node.body, messageId: "lines", data: { lines, max } });
35
+ };
37
36
  return {
38
37
  FunctionDeclaration: check,
39
38
  FunctionExpression: check,
40
39
  ArrowFunctionExpression: check,
41
- }
40
+ };
42
41
  },
43
- }
44
-
42
+ };
45
43
  /** The rule this law contributes to the plugin. */
46
- export const rules = { "function-line-budget": functionLineBudget }
47
-
44
+ export const rules = { "function-line-budget": functionLineBudget };
48
45
  /** The function budget is an error in both editions. */
49
- export const recommended = { "starci-be/function-line-budget": "error" }
46
+ export const recommended = { "starci-be/function-line-budget": "error" };
@@ -0,0 +1,10 @@
1
+ import { type Recommended, type RuleModule } from "./lib/rule.js";
2
+ /** Readiness delegation is proved through the injected service; the HTTP controller remains a thin door. */
3
+ export declare const readyReal: RuleModule;
4
+ /** Each declared API composition exposes both process-local liveness and required-dependency readiness. */
5
+ export declare const healthSignals: RuleModule;
6
+ export declare const rules: {
7
+ "ready-real": RuleModule;
8
+ "health-signals": RuleModule;
9
+ };
10
+ export declare const recommended: Recommended;