@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
@@ -10,25 +10,23 @@
10
10
  * class declared by that owner, typeorm receivers and query builders) and by the slot view (`be.feature.jobs.steps`, `be.feature.jobs`); the
11
11
  * only names read are the contract's own members `runKey`, `jobId` and `expectedFencingToken`.
12
12
  */
13
- import ts from "typescript"
14
- import { walk } from "./lib/ast.mjs"
15
- import { writtenEntityOrigins } from "./lib/entity-writes.mjs"
16
- import { hfsOf, inTestWorld } from "./lib/hfs.mjs"
17
- import { baseName, isOwnedType, ownerNameOf } from "./lib/ports.mjs"
18
- import { typeOrigins, typed } from "./lib/types.mjs"
19
-
20
- const isJobClaimsType = (context, node) => isOwnedType(context, node, { name: "JobClaims", capability: "jobs", tier: "platform" })
21
- const isJobStepType = (context, node) => isOwnedType(context, node, { name: "JobStep", capability: "jobs", tier: "platform" })
22
- const isFencedProcessorType = (context, node) => isOwnedType(context, node, { name: "FencedProcessor", capability: "jobs", tier: "platform" })
23
- const isRunKeyType = (context, node) => isOwnedType(context, node, { name: "RunKey", capability: "jobs", tier: "platform" })
24
-
13
+ import ts from "typescript";
14
+ import { walk } from "./lib/ast.js";
15
+ import { writtenEntityOrigins } from "./lib/entity-writes.js";
16
+ import { hfsOf, inTestWorld } from "./lib/hfs.js";
17
+ import { baseName, isOwnedType, ownerNameOf } from "./lib/ports.js";
18
+ import { typeOrigins, typed } from "./lib/types.js";
19
+ const isJobClaimsType = (context, node) => isOwnedType(context, node, { name: "JobClaims", capability: "jobs", tier: "platform" });
20
+ const isJobStepType = (context, node) => isOwnedType(context, node, { name: "JobStep", capability: "jobs", tier: "platform" });
21
+ const isFencedProcessorType = (context, node) => isOwnedType(context, node, { name: "FencedProcessor", capability: "jobs", tier: "platform" });
22
+ const isRunKeyType = (context, node) => isOwnedType(context, node, { name: "RunKey", capability: "jobs", tier: "platform" });
25
23
  /** True for a file of the owner itself, and for the test composition. */
26
24
  const isOwnerOrTest = (hfs, file) => {
27
- const tier = hfs.tierOf(file)
28
- if (tier === "e2e" || tier === "fixtures" || inTestWorld(hfs, file)) return true
29
- return tier === "platform" && ownerNameOf(hfs, file) === "jobs"
30
- }
31
-
25
+ const tier = hfs.tierOf(file);
26
+ if (tier === "e2e" || tier === "fixtures" || inTestWorld(hfs, file))
27
+ return true;
28
+ return tier === "platform" && ownerNameOf(hfs, file) === "jobs";
29
+ };
32
30
  /** A write to an entity that `platform/jobs` declares (the job row) is made only by `platform/jobs`. */
33
31
  export const jobWriteOwner = {
34
32
  meta: {
@@ -40,34 +38,33 @@ export const jobWriteOwner = {
40
38
  },
41
39
  },
42
40
  create(context) {
43
- const hfs = hfsOf(context)
44
- if (isOwnerOrTest(hfs, context.filename)) return {}
41
+ const hfs = hfsOf(context);
42
+ if (isOwnerOrTest(hfs, context.filename))
43
+ return {};
45
44
  return {
46
45
  CallExpression(node) {
47
- const origins = writtenEntityOrigins(context, node)
48
- if (!origins.some((origin) => hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === "jobs" && hfs.slotOf(origin.file) === "be.persistence")) return
49
- context.report({ node, messageId: "foreign", data: { call: context.sourceCode.getText(node.callee) } })
46
+ const origins = writtenEntityOrigins(context, node);
47
+ if (!origins.some((origin) => hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === "jobs" && hfs.slotOf(origin.file) === "be.persistence"))
48
+ return;
49
+ context.report({ node, messageId: "foreign", data: { call: context.sourceCode.getText(node.callee) } });
50
50
  },
51
- }
51
+ };
52
52
  },
53
- }
54
-
53
+ };
55
54
  /** The names the guarded-write contract fixes: the target job and the token the writer holds. */
56
- const TARGET = "jobId"
57
- const TOKEN = "expectedFencingToken"
55
+ const TARGET = "jobId";
56
+ const TOKEN = "expectedFencingToken";
58
57
  /** The property of a claimed job that holds the token it carries. */
59
- const CARRIED = "fencingToken"
60
-
58
+ const CARRIED = "fencingToken";
61
59
  /** A property of a TypeScript type by name, or undefined. */
62
- const propertyOf = (type, name) => type.getProperty(name)
63
-
60
+ const propertyOf = (type, name) => type.getProperty(name);
64
61
  /** True when the property is a required `number`. */
65
62
  const isRequiredNumber = (checker, property, location) => {
66
- if (!property || (property.flags & ts.SymbolFlags.Optional) !== 0) return false
67
- const type = checker.getTypeOfSymbolAtLocation(property, location)
68
- return (type.flags & ts.TypeFlags.Number) !== 0
69
- }
70
-
63
+ if (!property || (property.flags & ts.SymbolFlags.Optional) !== 0)
64
+ return false;
65
+ const type = checker.getTypeOfSymbolAtLocation(property, location);
66
+ return (type.flags & ts.TypeFlags.Number) !== 0;
67
+ };
71
68
  /** Calls on the `JobClaims` port, and what a guarded write is: required token, no cast to get around it, and `JobFencedOut` is not swallowed. */
72
69
  export const jobFenceRequired = {
73
70
  meta: {
@@ -81,45 +78,57 @@ export const jobFenceRequired = {
81
78
  },
82
79
  },
83
80
  create(context) {
84
- const hfs = hfsOf(context)
85
- const owner = isOwnerOrTest(hfs, context.filename)
86
- const { checker, toTs } = typed(context)
87
- const claimsCall = (node) => node.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && isJobClaimsType(context, node.callee.object)
81
+ const hfs = hfsOf(context);
82
+ const owner = isOwnerOrTest(hfs, context.filename);
83
+ const { checker, toTs } = typed(context);
84
+ const claimsCall = (node) => node.type === "CallExpression" && node.callee.type === "MemberExpression" && !node.callee.computed && isJobClaimsType(context, node.callee.object);
88
85
  return {
89
86
  // The declaration side: in the owner, each member of the port that takes a job requires the token.
90
87
  TSMethodSignature(node) {
91
- if (!owner || hfs.tierOf(context.filename) !== "platform" || !isJobClaimsType(context, node.parent.parent?.id ?? node.parent)) return
92
- const first = node.params?.[0]
93
- if (!first) return
94
- const tsNode = toTs(first)
95
- const type = tsNode ? checker.getTypeAtLocation(tsNode) : undefined
88
+ const holder = node.parent.parent;
89
+ const holderId = holder && "id" in holder ? holder.id : undefined;
90
+ if (!owner || hfs.tierOf(context.filename) !== "platform" || !isJobClaimsType(context, holderId ?? node.parent))
91
+ return;
92
+ const first = node.params?.[0];
93
+ if (!first)
94
+ return;
95
+ const tsNode = toTs(first);
96
+ const type = tsNode ? checker.getTypeAtLocation(tsNode) : undefined;
96
97
  // A parameter that already carries the token (the claimed job itself) is a derivation, not a write.
97
- if (!type || !propertyOf(type, TARGET) || propertyOf(type, CARRIED)) return
98
+ if (!type || !propertyOf(type, TARGET) || propertyOf(type, CARRIED))
99
+ return;
98
100
  if (!isRequiredNumber(checker, propertyOf(type, TOKEN), tsNode)) {
99
- context.report({ node: first, messageId: "optionalToken", data: { method: node.key?.name ?? "this method", target: TARGET, token: TOKEN } })
101
+ const methodName = node.key && "name" in node.key ? node.key.name : undefined;
102
+ context.report({ node: first, messageId: "optionalToken", data: { method: methodName ?? "this method", target: TARGET, token: TOKEN } });
100
103
  }
101
104
  },
102
105
  CallExpression(node) {
103
- if (owner || !claimsCall(node)) return
106
+ if (owner || !claimsCall(node))
107
+ return;
104
108
  for (const argument of node.arguments) {
105
109
  walk(argument, (child) => {
106
- if (child.type === "TSAsExpression" || child.type === "TSTypeAssertion" || child.type === "TSNonNullExpression") context.report({ node: child, messageId: "cast", data: { call: context.sourceCode.getText(node.callee) } })
107
- })
110
+ if (child.type === "TSAsExpression" || child.type === "TSTypeAssertion" || child.type === "TSNonNullExpression")
111
+ context.report({ node: child, messageId: "cast", data: { call: context.sourceCode.getText(node.callee) } });
112
+ });
108
113
  }
109
114
  },
110
115
  TryStatement(node) {
111
- if (owner || !node.handler) return
112
- let writes = false
113
- walk(node.block, (child) => { if (claimsCall(child)) writes = true })
114
- if (!writes) return
115
- let rethrows = false
116
- walk(node.handler.body, (child) => { if (child.type === "ThrowStatement") rethrows = true })
117
- if (!rethrows) context.report({ node: node.handler, messageId: "swallowed" })
116
+ if (owner || !node.handler)
117
+ return;
118
+ let writes = false;
119
+ walk(node.block, (child) => { if (claimsCall(child))
120
+ writes = true; });
121
+ if (!writes)
122
+ return;
123
+ let rethrows = false;
124
+ walk(node.handler.body, (child) => { if (child.type === "ThrowStatement")
125
+ rethrows = true; });
126
+ if (!rethrows)
127
+ context.report({ node: node.handler, messageId: "swallowed" });
118
128
  },
119
- }
129
+ };
120
130
  },
121
- }
122
-
131
+ };
123
132
  /** The class of an external effect of a step passes the key `JobClaims.runKey` made. */
124
133
  export const jobRunKey = {
125
134
  meta: {
@@ -132,27 +141,30 @@ export const jobRunKey = {
132
141
  },
133
142
  },
134
143
  create(context) {
135
- const hfs = hfsOf(context)
136
- if (hfs.slotOf(context.filename) !== "be.feature.jobs.steps") return {}
144
+ const hfs = hfsOf(context);
145
+ if (hfs.slotOf(context.filename) !== "be.feature.jobs.steps")
146
+ return {};
137
147
  return {
138
148
  CallExpression(node) {
139
- const callee = node.callee
140
- if (callee.type !== "MemberExpression" || callee.computed) return
141
- const origins = typeOrigins(context, callee.object)
142
- if (!origins.some((origin) => origin.module === null && hfs.tierOf(origin.file) === "integrations")) return
143
- const keyArguments = node.arguments.filter((argument) => isRunKeyType(context, argument))
149
+ const callee = node.callee;
150
+ if (callee.type !== "MemberExpression" || callee.computed)
151
+ return;
152
+ const origins = typeOrigins(context, callee.object);
153
+ if (!origins.some((origin) => origin.module === null && hfs.tierOf(origin.file) === "integrations"))
154
+ return;
155
+ const keyArguments = node.arguments.filter((argument) => isRunKeyType(context, argument));
144
156
  if (keyArguments.length === 0) {
145
- context.report({ node, messageId: "missing", data: { call: context.sourceCode.getText(callee) } })
146
- return
157
+ context.report({ node, messageId: "missing", data: { call: context.sourceCode.getText(callee) } });
158
+ return;
147
159
  }
148
160
  for (const argument of keyArguments) {
149
- walk(argument, (child) => { if (child.type === "TSAsExpression" || child.type === "TSTypeAssertion") context.report({ node: child, messageId: "forged" }) })
161
+ walk(argument, (child) => { if (child.type === "TSAsExpression" || child.type === "TSTypeAssertion")
162
+ context.report({ node: child, messageId: "forged" }); });
150
163
  }
151
164
  },
152
- }
165
+ };
153
166
  },
154
- }
155
-
167
+ };
156
168
  /** A processor extends the fenced base and is named after its job; a step implements `JobStep` in `steps/`. */
157
169
  export const jobShape = {
158
170
  meta: {
@@ -168,47 +180,52 @@ export const jobShape = {
168
180
  },
169
181
  },
170
182
  create(context) {
171
- const hfs = hfsOf(context)
172
- const file = context.filename
173
- const found = hfs.classify(file)
174
- const base = baseName(file)
175
- const isProcessorFile = base.endsWith(".processor.ts")
176
- const isStepFile = base.endsWith(".step.ts")
177
- const inJob = found.slot === "be.feature.jobs.queue"
178
- const inSteps = found.slot === "be.feature.jobs.steps"
179
- const inPlatform = hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === "jobs"
183
+ const hfs = hfsOf(context);
184
+ const file = context.filename;
185
+ const found = hfs.classify(file);
186
+ const base = baseName(file);
187
+ const isProcessorFile = base.endsWith(".processor.ts");
188
+ const isStepFile = base.endsWith(".step.ts");
189
+ const inJob = found.slot === "be.feature.jobs.queue";
190
+ const inSteps = found.slot === "be.feature.jobs.steps";
191
+ const inPlatform = hfs.tierOf(file) === "platform" && ownerNameOf(hfs, file) === "jobs";
180
192
  const check = (node) => {
181
- const name = node.id?.name ?? "this class"
182
- const extendsFenced = node.superClass ? isFencedProcessorType(context, node.superClass) : false
183
- const implementsStep = (node.implements ?? []).some((entry) => isJobStepType(context, entry))
193
+ const name = node.id?.name ?? "this class";
194
+ const extendsFenced = node.superClass ? isFencedProcessorType(context, node.superClass) : false;
195
+ const implementsStep = (node.implements ?? []).some((entry) => isJobStepType(context, entry));
184
196
  if (isProcessorFile && !inPlatform) {
185
- if (!inJob) context.report({ node: node.id ?? node, messageId: "processorPlacement", data: { name } })
197
+ if (!inJob)
198
+ context.report({ node: node.id ?? node, messageId: "processorPlacement", data: { name } });
186
199
  else {
187
- const stem = base.slice(0, -".processor.ts".length)
188
- if (found.bindings?.job !== undefined && found.bindings.job !== stem) context.report({ node: node.id ?? node, messageId: "processorStem", data: { job: found.bindings.job, stem } })
189
- if (!extendsFenced) context.report({ node: node.id ?? node, messageId: "notFenced", data: { name } })
200
+ const stem = base.slice(0, -".processor.ts".length);
201
+ if (found.bindings?.job !== undefined && found.bindings.job !== stem)
202
+ context.report({ node: node.id ?? node, messageId: "processorStem", data: { job: found.bindings.job, stem } });
203
+ if (!extendsFenced)
204
+ context.report({ node: node.id ?? node, messageId: "notFenced", data: { name } });
190
205
  }
191
206
  }
192
207
  if (isStepFile) {
193
- if (!inSteps) context.report({ node: node.id ?? node, messageId: "stepPlacement", data: { name } })
194
- else if (!implementsStep) context.report({ node: node.id ?? node, messageId: "notStep", data: { name } })
195
- } else if (implementsStep && !inPlatform) context.report({ node: node.id ?? node, messageId: "stepPlacement", data: { name } })
196
- }
197
- return { ClassDeclaration: check, ClassExpression: check }
208
+ if (!inSteps)
209
+ context.report({ node: node.id ?? node, messageId: "stepPlacement", data: { name } });
210
+ else if (!implementsStep)
211
+ context.report({ node: node.id ?? node, messageId: "notStep", data: { name } });
212
+ }
213
+ else if (implementsStep && !inPlatform)
214
+ context.report({ node: node.id ?? node, messageId: "stepPlacement", data: { name } });
215
+ };
216
+ return { ClassDeclaration: check, ClassExpression: check };
198
217
  },
199
- }
200
-
218
+ };
201
219
  export const rules = {
202
220
  "job-write-owner": jobWriteOwner,
203
221
  "job-fence-required": jobFenceRequired,
204
222
  "job-run-key": jobRunKey,
205
223
  "job-shape": jobShape,
206
- }
207
-
224
+ };
208
225
  /** The level these laws ask for: `error`, switched off nowhere. */
209
226
  export const recommended = {
210
227
  "starci-be/job-write-owner": "error",
211
228
  "starci-be/job-fence-required": "error",
212
229
  "starci-be/job-run-key": "error",
213
230
  "starci-be/job-shape": "error",
214
- }
231
+ };
@@ -0,0 +1,6 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ export declare const jwtAlgPinned: RuleModule;
3
+ export declare const rules: {
4
+ "jwt-alg-pinned": RuleModule;
5
+ };
6
+ export declare const recommended: Recommended;
@@ -0,0 +1,49 @@
1
+ /** R260 BE_JWT_ALG_PINNED: remote JWT verification pins algorithms, configuration and principal role. */
2
+ import ts from "typescript";
3
+ import { typed } from "./lib/types.js";
4
+ import { isDeclarationFile } from "./lib/path.js";
5
+ import { jwtPolicyProblems } from "../runtime/scripts/hfs/architecture/supabase-ast.mjs";
6
+ /** The text of a module specifier (a string literal), or undefined for any other expression. */
7
+ const specifierText = (specifier) => ("text" in specifier ? specifier.text : undefined);
8
+ /** Recognize jose imports and aliases through their declarations, including namespace imports. */
9
+ const joseVerifier = (checker, expression, seen = new Set()) => {
10
+ if (!expression || seen.has(expression))
11
+ return false;
12
+ seen.add(expression);
13
+ if (ts.isPropertyAccessExpression(expression)) {
14
+ if (expression.name.text !== "jwtVerify")
15
+ return false;
16
+ return checker.getSymbolAtLocation(expression.expression)?.declarations?.some(declaration => ts.isNamespaceImport(declaration) && specifierText(declaration.parent.parent.moduleSpecifier) === "jose") ?? false;
17
+ }
18
+ return checker.getSymbolAtLocation(expression)?.declarations?.some(declaration => {
19
+ if (ts.isImportSpecifier(declaration))
20
+ return (declaration.propertyName ?? declaration.name).text === "jwtVerify"
21
+ && specifierText(declaration.parent.parent.parent.moduleSpecifier) === "jose";
22
+ return ts.isVariableDeclaration(declaration) && declaration.initializer && joseVerifier(checker, declaration.initializer, seen);
23
+ }) ?? false;
24
+ };
25
+ export const jwtAlgPinned = {
26
+ meta: {
27
+ type: "problem",
28
+ docs: { description: "R260 BE_JWT_ALG_PINNED: literal secure algorithms, config issuer and authenticated principal role." },
29
+ schema: [],
30
+ messages: { pinned: "{{detail}}" },
31
+ },
32
+ create(context) {
33
+ if (isDeclarationFile(context.filename || context.getFilename()))
34
+ return {};
35
+ const { checker, toTs } = typed(context);
36
+ return {
37
+ CallExpression(node) {
38
+ const call = toTs(node);
39
+ if (!call || !joseVerifier(checker, call.expression))
40
+ return;
41
+ const problems = jwtPolicyProblems(ts, checker, call);
42
+ if (problems.length)
43
+ context.report({ node, messageId: "pinned", data: { detail: problems.join(" ") } });
44
+ },
45
+ };
46
+ },
47
+ };
48
+ export const rules = { "jwt-alg-pinned": jwtAlgPinned };
49
+ export const recommended = { "starci-be/jwt-alg-pinned": "error" };
@@ -0,0 +1,25 @@
1
+ import type { HfsView } from "./hfs.js";
2
+ /** The options of an app. */
3
+ export declare const APP_OPTIONS_ROLE = "<app>.options.ts";
4
+ /** The environment parsing of an app. */
5
+ export declare const APP_ENV_ROLE = "<app>.env.ts";
6
+ /**
7
+ * The app-slot entry a file matches (`main.ts`, `app.module.ts`, `<app>.env.ts`, `<app>.options.ts`, `compose/<area>.ts`, ...), or null for a
8
+ * file outside the `be.app.*` slots or one its slot does not name.
9
+ *
10
+ * @param {object} hfs - The HFS view of the repository.
11
+ * @param {string} filename - The linted file.
12
+ * @returns {{slot: string, entry: string} | null} The app slot and the entry the file matches.
13
+ */
14
+ export declare const appRoleOf: (hfs: HfsView, filename: string) => {
15
+ slot: string;
16
+ entry: string;
17
+ } | null;
18
+ /**
19
+ * Whether a file composes the app: its root `app.module.ts` or a composition group `compose/<area>.ts`.
20
+ *
21
+ * @param {object} hfs - The HFS view of the repository.
22
+ * @param {string} filename - The linted file.
23
+ * @returns {boolean} True for a composition file of a back-end app.
24
+ */
25
+ export declare const isAppComposition: (hfs: HfsView, filename: string) => boolean;
@@ -8,17 +8,15 @@
8
8
  * - `<app>.options.ts` the options types and port bindings (provider maps); no environment reads.
9
9
  * - `compose/<area>.ts` a composition group: the module list of one area of the app, spread by the root.
10
10
  */
11
- import { normalizePath } from "./path.mjs"
12
-
11
+ import { normalizePath } from "./path.js";
13
12
  /** The composition root of an app. */
14
- const APP_ROOT_ROLE = "app.module.ts"
13
+ const APP_ROOT_ROLE = "app.module.ts";
15
14
  /** The options of an app. */
16
- export const APP_OPTIONS_ROLE = "<app>.options.ts"
15
+ export const APP_OPTIONS_ROLE = "<app>.options.ts";
17
16
  /** The environment parsing of an app. */
18
- export const APP_ENV_ROLE = "<app>.env.ts"
17
+ export const APP_ENV_ROLE = "<app>.env.ts";
19
18
  /** A composition group of an app. */
20
- const COMPOSE_GROUP_ROLE = "compose/<area>.ts"
21
-
19
+ const COMPOSE_GROUP_ROLE = "compose/<area>.ts";
22
20
  /**
23
21
  * The app-slot entry a file matches (`main.ts`, `app.module.ts`, `<app>.env.ts`, `<app>.options.ts`, `compose/<area>.ts`, ...), or null for a
24
22
  * file outside the `be.app.*` slots or one its slot does not name.
@@ -28,13 +26,13 @@ const COMPOSE_GROUP_ROLE = "compose/<area>.ts"
28
26
  * @returns {{slot: string, entry: string} | null} The app slot and the entry the file matches.
29
27
  */
30
28
  export const appRoleOf = (hfs, filename) => {
31
- const file = normalizePath(filename)
32
- const slot = hfs.slotOf(file) ?? ""
33
- if (!slot.startsWith("be.app.") || typeof hfs.allows !== "function") return null
34
- const verdict = hfs.allows(file)
35
- return verdict?.allowed && verdict.entry ? { slot, entry: verdict.entry } : null
36
- }
37
-
29
+ const file = normalizePath(filename);
30
+ const slot = hfs.slotOf(file) ?? "";
31
+ if (!slot.startsWith("be.app.") || typeof hfs.allows !== "function")
32
+ return null;
33
+ const verdict = hfs.allows(file);
34
+ return verdict?.allowed && verdict.entry ? { slot, entry: verdict.entry } : null;
35
+ };
38
36
  /**
39
37
  * Whether a file composes the app: its root `app.module.ts` or a composition group `compose/<area>.ts`.
40
38
  *
@@ -43,6 +41,6 @@ export const appRoleOf = (hfs, filename) => {
43
41
  * @returns {boolean} True for a composition file of a back-end app.
44
42
  */
45
43
  export const isAppComposition = (hfs, filename) => {
46
- const role = appRoleOf(hfs, filename)?.entry
47
- return role === APP_ROOT_ROLE || role === COMPOSE_GROUP_ROLE
48
- }
44
+ const role = appRoleOf(hfs, filename)?.entry;
45
+ return role === APP_ROOT_ROLE || role === COMPOSE_GROUP_ROLE;
46
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Small AST helpers the HFS laws share, so each rule states its question instead of its traversal.
3
+ *
4
+ * Nothing here touches disk or the type checker: a rule reads one file's syntax and its path.
5
+ */
6
+ import type { TSESTree } from "@typescript-eslint/utils";
7
+ import { type Node } from "./rule.js";
8
+ /** How far a walk goes: `intoFunctions: false` stops at nested function boundaries. */
9
+ export interface WalkOptions {
10
+ readonly intoFunctions?: boolean;
11
+ }
12
+ /**
13
+ * Visits `node` and every descendant, depth first.
14
+ *
15
+ * @param node - The subtree root.
16
+ * @param visit - Called with each node.
17
+ * @param options - `intoFunctions: false` stops at nested function boundaries.
18
+ */
19
+ export declare const walk: (node: Node | null | undefined, visit: (child: Node) => void, { intoFunctions }?: WalkOptions) => void;
20
+ /** True when any node of the subtree satisfies `predicate`. */
21
+ export declare const some: (node: Node | null | undefined, predicate: (child: Node) => boolean, options?: WalkOptions) => boolean;
22
+ /** The name a property key, identifier or string literal spells, else null. */
23
+ export declare const keyName: (node: Node | null | undefined) => string | null;
24
+ /** The parameter a constructor or function declares, with its wrapper and default unwrapped, and every decorator on any layer. */
25
+ export interface ParamParts {
26
+ readonly target: TSESTree.BindingName | TSESTree.RestElement;
27
+ readonly decorators: TSESTree.Decorator[];
28
+ }
29
+ /** The decorators of a constructor parameter: on the parameter, its wrapper (`private readonly x`) or its inner identifier. */
30
+ export declare const paramParts: (param: TSESTree.Parameter) => ParamParts;
31
+ /** The name of a decorator (`@Foo` or `@Foo(...)`), else null. */
32
+ export declare const decoratorName: (decorator: TSESTree.Decorator | null | undefined) => string | null;
33
+ /** True for a string literal or a template without substitutions, giving its text via `staticText`. */
34
+ export declare const staticText: (node: Node | null | undefined) => string | null;
35
+ /** `node.name ?? node.value` of any node: an identifier's name, else a literal's value (undefined when it has neither). */
36
+ export declare const nameOrValue: (node: Node | null | undefined) => unknown;
37
+ /** The key a member expression reads: `a.b` gives "b", `a["b"]` gives the literal's value (undefined for a computed non-literal). */
38
+ export declare const memberKeyValue: (member: TSESTree.MemberExpression) => unknown;
39
+ /** Splits `webhookSecret`, `WEBHOOK_SECRET` and `webhook-secret` into lower-case words. */
40
+ export declare const wordsOf: (name: unknown) => string[];
@@ -0,0 +1,100 @@
1
+ import { isNode } from "./rule.js";
2
+ const SKIP_KEYS = new Set(["parent", "loc", "range", "tokens", "comments"]);
3
+ const FUNCTION_TYPES = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
4
+ /**
5
+ * Visits `node` and every descendant, depth first.
6
+ *
7
+ * @param node - The subtree root.
8
+ * @param visit - Called with each node.
9
+ * @param options - `intoFunctions: false` stops at nested function boundaries.
10
+ */
11
+ export const walk = (node, visit, { intoFunctions = true } = {}) => {
12
+ if (!isNode(node))
13
+ return;
14
+ visit(node);
15
+ const entries = Object.entries(node);
16
+ for (const [key, value] of entries) {
17
+ if (SKIP_KEYS.has(key))
18
+ continue;
19
+ if (Array.isArray(value)) {
20
+ for (const child of value) {
21
+ if (!isNode(child))
22
+ continue;
23
+ if (!intoFunctions && FUNCTION_TYPES.has(child.type))
24
+ continue;
25
+ walk(child, visit, { intoFunctions });
26
+ }
27
+ }
28
+ else if (isNode(value)) {
29
+ if (!intoFunctions && FUNCTION_TYPES.has(value.type))
30
+ continue;
31
+ walk(value, visit, { intoFunctions });
32
+ }
33
+ }
34
+ };
35
+ /** True when any node of the subtree satisfies `predicate`. */
36
+ export const some = (node, predicate, options) => {
37
+ let found = false;
38
+ walk(node, (child) => {
39
+ if (!found && predicate(child))
40
+ found = true;
41
+ }, options);
42
+ return found;
43
+ };
44
+ /** The name a property key, identifier or string literal spells, else null. */
45
+ export const keyName = (node) => {
46
+ if (!node)
47
+ return null;
48
+ if (node.type === "Identifier")
49
+ return node.name;
50
+ if (node.type === "Literal" && typeof node.value === "string")
51
+ return node.value;
52
+ if (node.type === "PrivateIdentifier")
53
+ return node.name;
54
+ return null;
55
+ };
56
+ /** The decorators of a constructor parameter: on the parameter, its wrapper (`private readonly x`) or its inner identifier. */
57
+ export const paramParts = (param) => {
58
+ const inner = param.type === "TSParameterProperty" ? param.parameter : param;
59
+ const target = inner.type === "AssignmentPattern" ? inner.left : inner;
60
+ return { target, decorators: [...new Set([...(param.decorators ?? []), ...(inner.decorators ?? []), ...(target.decorators ?? [])])] };
61
+ };
62
+ /** The name of a decorator (`@Foo` or `@Foo(...)`), else null. */
63
+ export const decoratorName = (decorator) => {
64
+ const expression = decorator?.expression;
65
+ if (!expression)
66
+ return null;
67
+ if (expression.type === "Identifier")
68
+ return expression.name;
69
+ if (expression.type === "CallExpression" && expression.callee.type === "Identifier")
70
+ return expression.callee.name;
71
+ return null;
72
+ };
73
+ /** True for a string literal or a template without substitutions, giving its text via `staticText`. */
74
+ export const staticText = (node) => {
75
+ if (!node)
76
+ return null;
77
+ if (node.type === "Literal" && typeof node.value === "string")
78
+ return node.value;
79
+ if (node.type === "TemplateLiteral" && node.expressions.length === 0)
80
+ return node.quasis.map((q) => q.value.cooked ?? "").join("");
81
+ return null;
82
+ };
83
+ /** `node.name ?? node.value` of any node: an identifier's name, else a literal's value (undefined when it has neither). */
84
+ export const nameOrValue = (node) => {
85
+ if (!node)
86
+ return undefined;
87
+ const name = "name" in node ? node.name : undefined;
88
+ if (name !== undefined && name !== null)
89
+ return name;
90
+ return "value" in node ? node.value : undefined;
91
+ };
92
+ /** The key a member expression reads: `a.b` gives "b", `a["b"]` gives the literal's value (undefined for a computed non-literal). */
93
+ export const memberKeyValue = (member) => (member.computed ? ("value" in member.property ? member.property.value : undefined) : member.property.name);
94
+ /** Splits `webhookSecret`, `WEBHOOK_SECRET` and `webhook-secret` into lower-case words. */
95
+ export const wordsOf = (name) => String(name)
96
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
97
+ .replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
98
+ .split(/[^A-Za-z0-9]+/)
99
+ .filter(Boolean)
100
+ .map((word) => word.toLowerCase());
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from "./rule.js";
2
+ /** Effectful commands carry a bounded client key to the one atomic domain inbox execution. */
3
+ export declare const mutationIdempotent: RuleModule;