@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
@@ -0,0 +1,17 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** A provider's constructor parameter is a class token or carries a named-token injector. */
3
+ export declare const providerParamToken: RuleModule;
4
+ /** A persistence class exists only where the manager may be held. */
5
+ export declare const noRepositoryClass: RuleModule;
6
+ /** The double marker word an identifier carries, else null. */
7
+ export declare const doubleWordOf: (name: string) => string | null;
8
+ /** Production source names no test double. */
9
+ export declare const noTestDoubleInSource: RuleModule;
10
+ /** The rules this law contributes to the plugin. */
11
+ export declare const rules: {
12
+ "provider-param-token": RuleModule;
13
+ "no-repository-class": RuleModule;
14
+ "no-test-double-in-source": RuleModule;
15
+ };
16
+ /** Every rule of this law ships at `error`. */
17
+ export declare const recommended: Recommended;
@@ -20,50 +20,48 @@
20
20
  * Every question about a type asks where the type is DECLARED (`typeOrigins`), every question about a path asks the HFS
21
21
  * slot view. A name is read only for the fixed vocabulary of the double markers, as whole words.
22
22
  */
23
- import ts from "typescript"
24
- import { paramParts } from "./lib/ast.mjs"
25
- import { hfsOf, inTestWorld } from "./lib/hfs.mjs"
26
- import { isSpecFile, normalizePath } from "./lib/path.mjs"
27
- import { implementsMigration, inCli, isMigrationFile, mayHoldEntityManager } from "./lib/persistence.mjs"
28
- import { typed, typeOrigins } from "./lib/types.mjs"
29
-
23
+ import ts from "typescript";
24
+ import { paramParts } from "./lib/ast.js";
25
+ import { hfsOf, inTestWorld } from "./lib/hfs.js";
26
+ import { isSpecFile, normalizePath } from "./lib/path.js";
27
+ import { implementsMigration, inCli, isMigrationFile, mayHoldEntityManager } from "./lib/persistence.js";
28
+ import { typed, typeOrigins } from "./lib/types.js";
30
29
  // -- provider-param-token --------------------------------------------------------------------------
31
-
32
30
  /** The convention's injector vocabulary: `Inject` or `Inject<Thing>`. */
33
- const INJECT_NAME = /^Inject(?:[A-Z][A-Za-z0-9]*)?$/
34
-
31
+ const INJECT_NAME = /^Inject(?:[A-Z][A-Za-z0-9]*)?$/;
35
32
  /** True when a decorator expression is a call of an `Inject*` function, or of anything typed `TypedParameterDecorator<T>`. */
36
33
  const isInjector = (context, decorator) => {
37
- const expression = decorator.expression
38
- const callee = expression.type === "CallExpression" ? expression.callee : expression
39
- const name = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : ""
40
- if (INJECT_NAME.test(name)) return true
41
- if (expression.type !== "CallExpression") return false
42
- const { checker, toTs } = typed(context)
43
- const tsCall = toTs(expression)
44
- return Boolean(tsCall && checker.getTypeAtLocation(tsCall).aliasSymbol?.name === "TypedParameterDecorator")
45
- }
46
-
34
+ const expression = decorator.expression;
35
+ const callee = expression.type === "CallExpression" ? expression.callee : expression;
36
+ const name = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : "";
37
+ if (INJECT_NAME.test(name))
38
+ return true;
39
+ if (expression.type !== "CallExpression")
40
+ return false;
41
+ const { checker, toTs } = typed(context);
42
+ const tsCall = toTs(expression);
43
+ return Boolean(tsCall && checker.getTypeAtLocation(tsCall).aliasSymbol?.name === "TypedParameterDecorator");
44
+ };
47
45
  /** True when a class is a Nest provider-like: it carries a class decorator declared by a `@nestjs/*` package. */
48
- const isNestClass = (context, node) =>
49
- (node.decorators ?? []).some((decorator) => {
50
- const callee = decorator.expression.type === "CallExpression" ? decorator.expression.callee : decorator.expression
51
- return typeOrigins(context, callee).some((origin) => origin.module !== null && origin.module.startsWith("@nestjs/"))
52
- })
53
-
46
+ const isNestClass = (context, node) => (node.decorators ?? []).some((decorator) => {
47
+ const callee = decorator.expression.type === "CallExpression" ? decorator.expression.callee : decorator.expression;
48
+ return typeOrigins(context, callee).some((origin) => origin.module !== null && origin.module.startsWith("@nestjs/"));
49
+ });
54
50
  /** True when a written type is a plain reference to one class: the token Nest resolves from the emitted metadata. */
55
51
  const isClassToken = (context, annotation) => {
56
- if (annotation.type !== "TSTypeReference") return false
57
- const { checker, toTs } = typed(context)
58
- const tsNode = toTs(annotation)
59
- if (!tsNode) return false
60
- const type = checker.getTypeFromTypeNode(tsNode)
61
- const symbol = type.getSymbol()
62
- if (!symbol || (symbol.flags & ts.SymbolFlags.Class) === 0) return false
63
- const declaration = symbol.declarations?.find((entry) => ts.isClassDeclaration(entry) || ts.isClassExpression(entry))
64
- return Boolean(declaration)
65
- }
66
-
52
+ if (annotation.type !== "TSTypeReference")
53
+ return false;
54
+ const { checker, toTs } = typed(context);
55
+ const tsNode = toTs(annotation);
56
+ if (!tsNode)
57
+ return false;
58
+ const type = checker.getTypeFromTypeNode(tsNode);
59
+ const symbol = type.getSymbol();
60
+ if (!symbol || (symbol.flags & ts.SymbolFlags.Class) === 0)
61
+ return false;
62
+ const declaration = symbol.declarations?.find((entry) => ts.isClassDeclaration(entry) || ts.isClassExpression(entry));
63
+ return Boolean(declaration);
64
+ };
67
65
  /** A provider's constructor parameter is a class token or carries a named-token injector. */
68
66
  export const providerParamToken = {
69
67
  meta: {
@@ -71,65 +69,68 @@ export const providerParamToken = {
71
69
  docs: { description: "A constructor parameter of a Nest provider is typed by a class or carries an `Inject<Thing>()` decorator bound to a named token." },
72
70
  schema: [],
73
71
  messages: {
74
- untokened:
75
- "`{{name}}` is injected with no token Nest can resolve: its type `{{type}}` is not a class and the parameter carries no `Inject<Thing>()`. A primitive, a `Map`, a union, a function type or an interface has no runtime identity. Declare a `unique symbol` token and an `Inject<Thing>()` in the owner's `<owner>.decorators.ts` and decorate the parameter, or inject the class that owns the value.",
76
- unannotated:
77
- "`{{name}}` is injected without a type annotation, so nothing names its token. Annotate it with a class, or decorate it with the owner's `Inject<Thing>()`.",
72
+ untokened: "`{{name}}` is injected with no token Nest can resolve: its type `{{type}}` is not a class and the parameter carries no `Inject<Thing>()`. A primitive, a `Map`, a union, a function type or an interface has no runtime identity. Declare a `unique symbol` token and an `Inject<Thing>()` in the owner's `<owner>.decorators.ts` and decorate the parameter, or inject the class that owns the value.",
73
+ unannotated: "`{{name}}` is injected without a type annotation, so nothing names its token. Annotate it with a class, or decorate it with the owner's `Inject<Thing>()`.",
78
74
  },
79
75
  },
80
76
  create(context) {
81
- const sourceCode = context.sourceCode
77
+ const sourceCode = context.sourceCode;
82
78
  const check = (classNode) => {
83
- if (!isNestClass(context, classNode)) return
79
+ if (!isNestClass(context, classNode))
80
+ return;
84
81
  for (const member of classNode.body.body) {
85
- if (member.type !== "MethodDefinition" || member.kind !== "constructor" || !member.value?.params) continue
82
+ if (member.type !== "MethodDefinition" || member.kind !== "constructor" || !member.value?.params)
83
+ continue;
86
84
  for (const param of member.value.params) {
87
- const { target, decorators } = paramParts(param)
88
- if (decorators.some((decorator) => isInjector(context, decorator))) continue
89
- const name = target.type === "Identifier" ? target.name : sourceCode.getText(target)
90
- const annotation = target.typeAnnotation?.typeAnnotation
91
- if (!annotation) context.report({ node: target, messageId: "unannotated", data: { name } })
92
- else if (!isClassToken(context, annotation)) context.report({ node: target, messageId: "untokened", data: { name, type: sourceCode.getText(annotation) } })
85
+ const { target, decorators } = paramParts(param);
86
+ if (decorators.some((decorator) => isInjector(context, decorator)))
87
+ continue;
88
+ const name = target.type === "Identifier" ? target.name : sourceCode.getText(target);
89
+ const annotation = target.typeAnnotation?.typeAnnotation;
90
+ if (!annotation)
91
+ context.report({ node: target, messageId: "unannotated", data: { name } });
92
+ else if (!isClassToken(context, annotation))
93
+ context.report({ node: target, messageId: "untokened", data: { name, type: sourceCode.getText(annotation) } });
93
94
  }
94
95
  }
95
- }
96
- return { ClassDeclaration: check, ClassExpression: check }
96
+ };
97
+ return { ClassDeclaration: check, ClassExpression: check };
97
98
  },
98
- }
99
-
99
+ };
100
100
  // -- no-repository-class ---------------------------------------------------------------------------
101
-
102
101
  /** The typeorm types whose presence in a member makes the class a persistence class. */
103
- const PERSISTENCE_TYPES = new Set(["EntityManager", "Repository", "TreeRepository", "MongoRepository", "DataSource", "QueryRunner"])
104
-
102
+ const PERSISTENCE_TYPES = new Set(["EntityManager", "Repository", "TreeRepository", "MongoRepository", "DataSource", "QueryRunner"]);
105
103
  /** The persistence type a written type annotation names (by declaration origin), else null. */
106
104
  const persistenceTypeOf = (context, annotation) => {
107
- if (!annotation) return null
108
- const origin = typeOrigins(context, annotation).find((entry) => entry.module === "typeorm" && PERSISTENCE_TYPES.has(entry.name))
109
- return origin ? origin.name : null
110
- }
111
-
105
+ if (!annotation)
106
+ return null;
107
+ const origin = typeOrigins(context, annotation).find((entry) => entry.module === "typeorm" && PERSISTENCE_TYPES.has(entry.name));
108
+ return origin ? origin.name : null;
109
+ };
112
110
  /** The first member of a class that takes, holds or returns a persistence type: `{ member, type }`, else null. */
113
111
  const persistenceMember = (context, classNode) => {
114
112
  for (const member of classNode.body.body) {
115
113
  if (member.type === "PropertyDefinition" || member.type === "AccessorProperty") {
116
- const type = persistenceTypeOf(context, member.typeAnnotation?.typeAnnotation)
117
- if (type) return { member, type }
118
- continue
114
+ const type = persistenceTypeOf(context, member.typeAnnotation?.typeAnnotation);
115
+ if (type)
116
+ return { member, type };
117
+ continue;
119
118
  }
120
- if (member.type !== "MethodDefinition" || !member.value) continue
121
- const fn = member.value
119
+ if (member.type !== "MethodDefinition" || !member.value)
120
+ continue;
121
+ const fn = member.value;
122
122
  for (const param of fn.params ?? []) {
123
- const { target } = paramParts(param)
124
- const type = persistenceTypeOf(context, target.typeAnnotation?.typeAnnotation)
125
- if (type) return { member, type }
123
+ const { target } = paramParts(param);
124
+ const type = persistenceTypeOf(context, target.typeAnnotation?.typeAnnotation);
125
+ if (type)
126
+ return { member, type };
126
127
  }
127
- const returned = persistenceTypeOf(context, fn.returnType?.typeAnnotation)
128
- if (returned) return { member, type: returned }
128
+ const returned = persistenceTypeOf(context, fn.returnType?.typeAnnotation);
129
+ if (returned)
130
+ return { member, type: returned };
129
131
  }
130
- return null
131
- }
132
-
132
+ return null;
133
+ };
133
134
  /** A persistence class exists only where the manager may be held. */
134
135
  export const noRepositoryClass = {
135
136
  meta: {
@@ -137,67 +138,66 @@ export const noRepositoryClass = {
137
138
  docs: { description: "A class with a member typed `EntityManager`, `Repository`, `DataSource` or `QueryRunner` lives only in an application handler, a domain service, a platform persistence capability, the cli app, the test world or a migration." },
138
139
  schema: [],
139
140
  messages: {
140
- statements:
141
- "`{{name}}` is exported and takes an `EntityManager` as its first parameter: a statement module is a repository without a class. Put the SQL text in `<name>.sql.ts` and run it with `this.entityManager.query(...)` from the capability `*.service.ts` or the application `*.handler.ts`; only `platform/database`, the cli (`apps/cli`, `src/features/cli`) and `src/tests` take a manager in a free function.",
142
- repository:
143
- "`{{name}}` takes or holds a `{{type}}` in `{{member}}` but is not an application handler, a domain service or a platform persistence capability. A class wrapping the manager per entity is a repository whatever it is called: it hides which connection and transaction a call runs in and cannot be unit-tested with a token double. Move the queries into the handler or the domain service that owns the use, and call the injected EntityManager directly.",
141
+ statements: "`{{name}}` is exported and takes an `EntityManager` as its first parameter: a statement module is a repository without a class. Put the SQL text in `<name>.sql.ts` and run it with `this.entityManager.query(...)` from the capability `*.service.ts` or the application `*.handler.ts`; only `platform/database`, the cli (`apps/cli`, `src/features/cli`) and `src/tests` take a manager in a free function.",
142
+ repository: "`{{name}}` takes or holds a `{{type}}` in `{{member}}` but is not an application handler, a domain service or a platform persistence capability. A class wrapping the manager per entity is a repository whatever it is called: it hides which connection and transaction a call runs in and cannot be unit-tested with a token double. Move the queries into the handler or the domain service that owns the use, and call the injected EntityManager directly.",
144
143
  },
145
144
  },
146
145
  create(context) {
147
- const hfs = hfsOf(context)
148
- const filename = context.filename || context.getFilename()
149
- const file = normalizePath(filename)
150
- if (mayHoldEntityManager(hfs, file) || inCli(hfs, file) || inTestWorld(hfs, file) || isMigrationFile(hfs, file) || (hfs.slotOf(file) ?? "").startsWith("be.tests.")) return {}
146
+ const hfs = hfsOf(context);
147
+ const filename = context.filename || context.getFilename();
148
+ const file = normalizePath(filename);
149
+ if (mayHoldEntityManager(hfs, file) || inCli(hfs, file) || inTestWorld(hfs, file) || isMigrationFile(hfs, file) || (hfs.slotOf(file) ?? "").startsWith("be.tests."))
150
+ return {};
151
151
  const check = (node) => {
152
- if (implementsMigration(context, node)) return
153
- const found = persistenceMember(context, node)
154
- if (!found) return
155
- const key = found.member.key
156
- const member = found.member.kind === "constructor" ? "constructor" : key?.type === "Identifier" ? key.name : "a member"
157
- context.report({ node: node.id ?? node, messageId: "repository", data: { name: node.id?.name ?? "this class", type: found.type, member } })
158
- }
152
+ if (implementsMigration(context, node))
153
+ return;
154
+ const found = persistenceMember(context, node);
155
+ if (!found)
156
+ return;
157
+ const key = found.member.key;
158
+ const member = "kind" in found.member && found.member.kind === "constructor" ? "constructor" : key?.type === "Identifier" ? key.name : "a member";
159
+ context.report({ node: node.id ?? node, messageId: "repository", data: { name: node.id?.name ?? "this class", type: found.type, member } });
160
+ };
159
161
  /** An exported function whose first parameter is an EntityManager is a statement module: the same wrapper without a class. */
160
162
  const checkFunction = (fn, id) => {
161
- const first = fn.params?.[0]
162
- if (!first) return
163
- const { target } = paramParts(first)
164
- if (persistenceTypeOf(context, target.typeAnnotation?.typeAnnotation) !== "EntityManager") return
165
- context.report({ node: id, messageId: "statements", data: { name: id.name ?? "this function" } })
166
- }
163
+ const first = fn.params?.[0];
164
+ if (!first)
165
+ return;
166
+ const { target } = paramParts(first);
167
+ if (persistenceTypeOf(context, target.typeAnnotation?.typeAnnotation) !== "EntityManager")
168
+ return;
169
+ context.report({ node: id, messageId: "statements", data: { name: id.name ?? "this function" } });
170
+ };
167
171
  return {
168
172
  ClassDeclaration: check,
169
173
  ClassExpression: check,
170
174
  ExportNamedDeclaration(node) {
171
- const declaration = node.declaration
172
- if (declaration?.type === "FunctionDeclaration" && declaration.id) checkFunction(declaration, declaration.id)
175
+ const declaration = node.declaration;
176
+ if (declaration?.type === "FunctionDeclaration" && declaration.id)
177
+ checkFunction(declaration, declaration.id);
173
178
  if (declaration?.type === "VariableDeclaration") {
174
179
  for (const entry of declaration.declarations) {
175
- if (entry.id.type === "Identifier" && entry.init && (entry.init.type === "ArrowFunctionExpression" || entry.init.type === "FunctionExpression")) checkFunction(entry.init, entry.id)
180
+ if (entry.id.type === "Identifier" && entry.init && (entry.init.type === "ArrowFunctionExpression" || entry.init.type === "FunctionExpression"))
181
+ checkFunction(entry.init, entry.id);
176
182
  }
177
183
  }
178
184
  },
179
- }
185
+ };
180
186
  },
181
- }
182
-
187
+ };
183
188
  // -- no-test-double-in-source ----------------------------------------------------------------------
184
-
185
189
  /** The words that mark a test double. */
186
- const DOUBLE_WORDS = new Set(["mock", "fake", "stub"])
187
-
190
+ const DOUBLE_WORDS = new Set(["mock", "fake", "stub"]);
188
191
  /**
189
192
  * The words of an identifier: `MockExpertAgentService` gives `Mock Expert Agent Service`, `fakeClock` gives `fake Clock`,
190
193
  * `FAKE_CLOCK` gives `FAKE CLOCK`, `HTTPStub` gives `HTTP Stub`. A word is whole: `Faker` and `Mockingbird` are not `Fake`
191
194
  * and `Mock`.
192
195
  */
193
- const wordsOf = (name) =>
194
- name
195
- .split(/[^A-Za-z0-9]+/)
196
- .flatMap((part) => part.match(/[A-Z]+(?![a-z])|[A-Z]?[a-z]+|[0-9]+/g) ?? [])
197
-
196
+ const wordsOf = (name) => name
197
+ .split(/[^A-Za-z0-9]+/)
198
+ .flatMap((part) => part.match(/[A-Z]+(?![a-z])|[A-Z]?[a-z]+|[0-9]+/g) ?? []);
198
199
  /** The double marker word an identifier carries, else null. */
199
- export const doubleWordOf = (name) => wordsOf(name).find((word) => DOUBLE_WORDS.has(word.toLowerCase())) ?? null
200
-
200
+ export const doubleWordOf = (name) => wordsOf(name).find((word) => DOUBLE_WORDS.has(word.toLowerCase())) ?? null;
201
201
  /** Production source names no test double. */
202
202
  export const noTestDoubleInSource = {
203
203
  meta: {
@@ -205,39 +205,42 @@ export const noTestDoubleInSource = {
205
205
  docs: { description: "A class, function or constant of production source is not named `Mock*`, `Fake*` or `Stub*`." },
206
206
  schema: [],
207
207
  messages: {
208
- double:
209
- "`{{name}}` carries the test-double word `{{word}}` in production source. A double belongs in a spec or `src/tests`; a production offline or deterministic driver is an options-driven adapter of the port (its behaviour chosen by the module's options), renamed for what it does (`TemplateCatalogAdapter`, `OfflineDrafter`), and selected by configuration, never by being a mock.",
208
+ double: "`{{name}}` carries the test-double word `{{word}}` in production source. A double belongs in a spec or `src/tests`; a production offline or deterministic driver is an options-driven adapter of the port (its behaviour chosen by the module's options), renamed for what it does (`TemplateCatalogAdapter`, `OfflineDrafter`), and selected by configuration, never by being a mock.",
210
209
  },
211
210
  },
212
211
  create(context) {
213
- const hfs = hfsOf(context)
214
- const filename = context.filename || context.getFilename()
215
- if (isSpecFile(filename) || (hfs.slotOf(filename) ?? "").startsWith("be.tests.")) return {}
212
+ const hfs = hfsOf(context);
213
+ const filename = context.filename || context.getFilename();
214
+ if (isSpecFile(filename) || (hfs.slotOf(filename) ?? "").startsWith("be.tests."))
215
+ return {};
216
216
  const report = (id) => {
217
- const word = doubleWordOf(id.name)
218
- if (word) context.report({ node: id, messageId: "double", data: { name: id.name, word } })
219
- }
217
+ const word = doubleWordOf(id.name);
218
+ if (word)
219
+ context.report({ node: id, messageId: "double", data: { name: id.name, word } });
220
+ };
220
221
  return {
221
- ClassDeclaration(node) { if (node.id) report(node.id) },
222
- ClassExpression(node) { if (node.id) report(node.id) },
223
- FunctionDeclaration(node) { if (node.id) report(node.id) },
222
+ ClassDeclaration(node) { if (node.id)
223
+ report(node.id); },
224
+ ClassExpression(node) { if (node.id)
225
+ report(node.id); },
226
+ FunctionDeclaration(node) { if (node.id)
227
+ report(node.id); },
224
228
  VariableDeclarator(node) {
225
- if (node.id.type === "Identifier" && node.parent?.parent?.type === "ExportNamedDeclaration") report(node.id)
229
+ if (node.id.type === "Identifier" && node.parent?.parent?.type === "ExportNamedDeclaration")
230
+ report(node.id);
226
231
  },
227
- }
232
+ };
228
233
  },
229
- }
230
-
234
+ };
231
235
  /** The rules this law contributes to the plugin. */
232
236
  export const rules = {
233
237
  "provider-param-token": providerParamToken,
234
238
  "no-repository-class": noRepositoryClass,
235
239
  "no-test-double-in-source": noTestDoubleInSource,
236
- }
237
-
240
+ };
238
241
  /** Every rule of this law ships at `error`. */
239
242
  export const recommended = {
240
243
  "starci-be/provider-param-token": "error",
241
244
  "starci-be/no-repository-class": "error",
242
245
  "starci-be/no-test-double-in-source": "error",
243
- }
246
+ };
@@ -0,0 +1,8 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** A file of one service app imports no file of a sibling service app. */
3
+ export declare const serviceIsolation: RuleModule;
4
+ export declare const rules: {
5
+ "service-isolation": RuleModule;
6
+ };
7
+ /** The level this law asks for: `error`, switched off nowhere. */
8
+ export declare const recommended: Recommended;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The rule that keeps the services of one product apart (catalog R168 `BE_SERVICE_ISOLATION`).
3
+ *
4
+ * A back-end service is a Nest app at `be/apps/<service>/` of the one repository; services share the `be/src` libraries and talk
5
+ * to each other only through the wire (a client of the sibling's API, or the events of its vendored contract under
6
+ * `be/contracts/<service>/`). One service importing a file of another service's `apps/<other>/` folder reaches into a sibling's
7
+ * composition and options, which makes the two one deployable. The check asks the HFS slot view which app owns a file (the owner of
8
+ * an `apps/<app>/src/` slot) for both the importing file and the file the specifier resolves to, through a relative path or the
9
+ * program's own `compilerOptions.paths`; it never matches a path by name.
10
+ */
11
+ import { posix } from "node:path";
12
+ import { hfsOf } from "./lib/hfs.js";
13
+ import { resolveAlias } from "./lib/specifier.js";
14
+ /** The app slots: the slot ids of a service app's `apps/<app>/src/` folder. */
15
+ const isAppSlot = (slotId) => typeof slotId === "string" && slotId.startsWith("be.app.");
16
+ const isRelative = (specifier) => specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../");
17
+ /** Calls `check(node, specifier)` for every import and re-export that names a module. */
18
+ const onSpecifiers = (check) => ({
19
+ ImportExpression(node) {
20
+ check(node.source, node.source.type === "Literal" ? node.source.value : undefined);
21
+ },
22
+ ImportDeclaration(node) {
23
+ check(node.source, node.source.value);
24
+ },
25
+ ExportNamedDeclaration(node) {
26
+ if (node.source)
27
+ check(node.source, node.source.value);
28
+ },
29
+ ExportAllDeclaration(node) {
30
+ if (node.source)
31
+ check(node.source, node.source.value);
32
+ },
33
+ });
34
+ /** A file of one service app imports no file of a sibling service app. */
35
+ export const serviceIsolation = {
36
+ meta: {
37
+ type: "problem",
38
+ docs: { description: "A service app (`apps/<service>/`) imports no file of a sibling service app; services share only the `src` libraries and meet through the wire." },
39
+ schema: [],
40
+ messages: {
41
+ sibling: "`{{specifier}}` reaches into the service app `{{other}}` from `{{self}}`. Services share only the `src` libraries; call the sibling through its API client or consume its events through the vendored contract (`be/contracts/{{other}}/`).",
42
+ },
43
+ },
44
+ create(context) {
45
+ const filename = context.filename || context.getFilename();
46
+ const hfs = hfsOf(context);
47
+ if (!isAppSlot(hfs.slotOf(filename)))
48
+ return {};
49
+ const self = hfs.ownerOf(filename);
50
+ if (!self)
51
+ return {};
52
+ return onSpecifiers((node, specifier) => {
53
+ if (typeof specifier !== "string")
54
+ return;
55
+ const target = isRelative(specifier)
56
+ ? posix.normalize(`${posix.dirname(filename.replaceAll("\\", "/"))}/${specifier}`)
57
+ : resolveAlias(context, specifier)?.target;
58
+ if (!target)
59
+ return;
60
+ const reached = [`${target}.ts`, `${target}/index.ts`].find((candidate) => isAppSlot(hfs.slotOf(candidate)));
61
+ if (!reached)
62
+ return;
63
+ const other = hfs.ownerOf(reached);
64
+ if (!other || other === self)
65
+ return;
66
+ context.report({ node, messageId: "sibling", data: { specifier, self: posix.basename(posix.dirname(self)), other: posix.basename(posix.dirname(other)) } });
67
+ });
68
+ },
69
+ };
70
+ export const rules = {
71
+ "service-isolation": serviceIsolation,
72
+ };
73
+ /** The level this law asks for: `error`, switched off nowhere. */
74
+ export const recommended = {
75
+ "starci-be/service-isolation": "error",
76
+ };
@@ -0,0 +1,9 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** The ratchet: a file over the budget must not be new and must not grow. */
3
+ export declare const fileSizeGrowth: RuleModule;
4
+ /** The rules this law contributes to the plugin. */
5
+ export declare const rules: {
6
+ "file-size-growth": RuleModule;
7
+ };
8
+ /** The ratchet is an error. */
9
+ export declare const recommended: Recommended;
@@ -15,17 +15,14 @@
15
15
  * file are source files like any other. A migration is exempt (a file of the `be.persistence` slot named
16
16
  * `<timestamp>-<name>.ts`: append-only, never edited), and so is a declaration file.
17
17
  */
18
- import { basename } from "node:path"
19
- import { hfsOf } from "./lib/hfs.mjs"
20
- import { recordedLines } from "./runtime/scripts/api/git/recorded-lines.mjs"
21
- import { hardGrowthLines, lineCount } from "./runtime/scripts/lib/line-count.mjs"
22
-
18
+ import { basename } from "node:path";
19
+ import { hfsOf } from "./lib/hfs.js";
20
+ import { recordedLines } from "../runtime/scripts/api/git/recorded-lines.mjs";
21
+ import { hardGrowthLines, lineCount } from "../runtime/scripts/lib/line-count.mjs";
23
22
  /** A migration is a file of the persistence slot named `<timestamp>-<name>.ts`. */
24
- const isMigration = (hfs, filename) => hfs.slotOf(filename) === "be.persistence" && /^\d{13,14}-[^/]+\.[cm]?ts$/.test(basename(filename))
25
-
23
+ const isMigration = (hfs, filename) => hfs.slotOf(filename) === "be.persistence" && /^\d{13,14}-[^/]+\.[cm]?ts$/.test(basename(filename));
26
24
  /** Whether a file is a source file this budget governs. */
27
- const governed = (hfs, filename) => /\.[cm]?tsx?$/.test(filename) && !/\.d\.[cm]?ts$/.test(filename) && !isMigration(hfs, filename)
28
-
25
+ const governed = (hfs, filename) => /\.[cm]?tsx?$/.test(filename) && !/\.d\.[cm]?ts$/.test(filename) && !isMigration(hfs, filename);
29
26
  /** The ratchet: a file over the budget must not be new and must not grow. */
30
27
  export const fileSizeGrowth = {
31
28
  meta: {
@@ -39,31 +36,34 @@ export const fileSizeGrowth = {
39
36
  },
40
37
  },
41
38
  create(context) {
42
- const filename = context.filename || context.getFilename()
43
- const hfs = hfsOf(context)
44
- if (!governed(hfs, filename)) return {}
45
- const max = hardGrowthLines(hfs.ruleParams.fileLines)
39
+ const filename = context.filename || context.getFilename();
40
+ const hfs = hfsOf(context);
41
+ if (!governed(hfs, filename))
42
+ return {};
43
+ const max = hardGrowthLines(hfs.ruleParams.fileLines);
46
44
  return {
47
45
  "Program:exit"(node) {
48
- const source = (context.sourceCode || context.getSourceCode()).text
49
- const lines = lineCount(source)
50
- if (lines <= max) return
51
- const recorded = recordedLines(filename, { source })
52
- const loc = { line: 1, column: 0 }
53
- if (recorded === "unavailable") context.report({ node, loc, messageId: "unavailable" })
54
- else if (recorded === null) context.report({ node, loc, messageId: "born", data: { lines, max } })
55
- else if (lines > recorded) context.report({ node, loc, messageId: "grew", data: { lines, max, recorded } })
46
+ const source = (context.sourceCode || context.getSourceCode()).text;
47
+ const lines = lineCount(source);
48
+ if (lines <= max)
49
+ return;
50
+ const recorded = recordedLines(filename, { source });
51
+ const loc = { line: 1, column: 0 };
52
+ if (recorded === "unavailable")
53
+ context.report({ node, loc, messageId: "unavailable" });
54
+ else if (recorded === null)
55
+ context.report({ node, loc, messageId: "born", data: { lines, max } });
56
+ else if (lines > recorded)
57
+ context.report({ node, loc, messageId: "grew", data: { lines, max, recorded } });
56
58
  },
57
- }
59
+ };
58
60
  },
59
- }
60
-
61
+ };
61
62
  /** The rules this law contributes to the plugin. */
62
63
  export const rules = {
63
64
  "file-size-growth": fileSizeGrowth,
64
- }
65
-
65
+ };
66
66
  /** The ratchet is an error. */
67
67
  export const recommended = {
68
68
  "starci-be/file-size-growth": "error",
69
- }
69
+ };
@@ -0,0 +1,5 @@
1
+ import type { Recommended, Rules } from "./lib/rule.js";
2
+ /** The rules this law contributes to the plugin. */
3
+ export declare const rules: Rules;
4
+ /** Starts at error: a repository's fix lane clears the debt before the rule ships. */
5
+ export declare const recommended: Recommended;
@@ -9,12 +9,12 @@
9
9
  * function that never awaits and returns no promise), are the typescript-eslint rules `no-deprecated`, `no-base-to-string` and
10
10
  * `require-await` the factory turns on.
11
11
  */
12
- import { SONAR_SYNTAX_RULES } from "./runtime/scripts/lib/sonar-syntax-rules.mjs"
13
-
14
- const NAMES = ["no-await-in-loop", "prefer-code-point", "prefer-string-raw", "no-nested-conditional", "no-void-operator", "no-unused-import", "prefer-export-from", "max-params"]
15
-
12
+ import { SONAR_SYNTAX_RULES } from "../runtime/scripts/lib/sonar-syntax-rules.mjs";
13
+ const NAMES = ["no-await-in-loop", "prefer-code-point", "prefer-string-raw", "no-nested-conditional", "no-void-operator", "no-unused-import", "prefer-export-from", "max-params"];
16
14
  /** The rules this law contributes to the plugin. */
17
- export const rules = Object.fromEntries(NAMES.map((name) => [name, SONAR_SYNTAX_RULES[name]]))
18
-
15
+ export const rules = Object.fromEntries(NAMES.flatMap((name) => {
16
+ const rule = SONAR_SYNTAX_RULES[name];
17
+ return rule ? [[name, rule]] : [];
18
+ }));
19
19
  /** Starts at error: a repository's fix lane clears the debt before the rule ships. */
20
- export const recommended = Object.fromEntries(NAMES.map((name) => [`starci-be/${name}`, "error"]))
20
+ export const recommended = Object.fromEntries(NAMES.map((name) => [`starci-be/${name}`, "error"]));
@@ -0,0 +1,9 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** A spec runs every test it declares; the skip lives in the world's contract helper. */
3
+ export declare const specNoSkip: RuleModule;
4
+ /** The rules this law contributes to the plugin. */
5
+ export declare const rules: {
6
+ "spec-no-skip": RuleModule;
7
+ };
8
+ /** Every rule of this law ships at `error`. */
9
+ export declare const recommended: Recommended;