@starci/eslint-canon-be 3.5.0 → 3.6.1

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 (198) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +13 -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-view.d.ts +127 -0
  78. package/dist/lib/hfs-view.js +1 -0
  79. package/dist/lib/hfs.d.ts +34 -0
  80. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  81. package/dist/lib/import-source.d.ts +63 -0
  82. package/dist/lib/import-source.js +134 -0
  83. package/dist/lib/path.d.ts +8 -0
  84. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  85. package/dist/lib/persistence.d.ts +115 -0
  86. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  87. package/dist/lib/ports.d.ts +70 -0
  88. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  89. package/dist/lib/rule.d.ts +31 -0
  90. package/dist/lib/rule.js +2 -0
  91. package/dist/lib/runtime-root.d.ts +4 -0
  92. package/dist/lib/runtime-root.js +10 -0
  93. package/dist/lib/schema-values.d.ts +13 -0
  94. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  95. package/dist/lib/specifier.d.ts +12 -0
  96. package/dist/lib/specifier.js +29 -0
  97. package/dist/lib/subject-values.d.ts +4 -0
  98. package/dist/lib/subject-values.js +61 -0
  99. package/dist/lib/transactions.d.ts +18 -0
  100. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  101. package/dist/lib/transport-slots.d.ts +17 -0
  102. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  103. package/dist/lib/types.d.ts +96 -0
  104. package/dist/lib/types.js +150 -0
  105. package/dist/lib/unit-spec.d.ts +48 -0
  106. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  107. package/dist/lib/webhook-ack.d.ts +4 -0
  108. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  109. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  110. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  111. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  112. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  113. package/dist/lib/webhook-handoff.d.ts +15 -0
  114. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  115. package/dist/lib/webhook-verifiers.d.ts +20 -0
  116. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  117. package/dist/lib/why.d.ts +9 -0
  118. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  119. package/dist/log-safety.d.ts +20 -0
  120. package/dist/log-safety.js +308 -0
  121. package/dist/module-layering.d.ts +42 -0
  122. package/dist/module-layering.js +257 -0
  123. package/dist/module-shape.d.ts +47 -0
  124. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  125. package/dist/naming.d.ts +49 -0
  126. package/dist/naming.js +246 -0
  127. package/dist/observability.d.ts +25 -0
  128. package/dist/observability.js +245 -0
  129. package/dist/operations.d.ts +23 -0
  130. package/{operations.mjs → dist/operations.js} +410 -332
  131. package/dist/project-graph.d.ts +9 -0
  132. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  133. package/dist/projections.d.ts +11 -0
  134. package/{projections.mjs → dist/projections.js} +60 -57
  135. package/dist/query-safety.d.ts +21 -0
  136. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  137. package/dist/realtime.d.ts +15 -0
  138. package/{realtime.mjs → dist/realtime.js} +108 -106
  139. package/dist/resilience.d.ts +15 -0
  140. package/dist/resilience.js +319 -0
  141. package/dist/schema-authority.d.ts +15 -0
  142. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  143. package/dist/service-deps.d.ts +17 -0
  144. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  145. package/dist/service-isolation.d.ts +8 -0
  146. package/dist/service-isolation.js +76 -0
  147. package/dist/size-budget.d.ts +9 -0
  148. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  149. package/dist/sonar-parity.d.ts +5 -0
  150. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  151. package/dist/spec-no-skip.d.ts +9 -0
  152. package/dist/spec-no-skip.js +81 -0
  153. package/dist/spec-quality.d.ts +10 -0
  154. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  155. package/dist/suppression.d.ts +26 -0
  156. package/{suppression.mjs → dist/suppression.js} +30 -45
  157. package/dist/temporal.d.ts +9 -0
  158. package/{temporal.mjs → dist/temporal.js} +75 -65
  159. package/dist/test-world.d.ts +28 -0
  160. package/{test-world.mjs → dist/test-world.js} +102 -83
  161. package/dist/testing.d.ts +51 -0
  162. package/dist/testing.js +368 -0
  163. package/dist/third-party-owner.d.ts +8 -0
  164. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  165. package/dist/transport.d.ts +24 -0
  166. package/{transport.mjs → dist/transport.js} +279 -240
  167. package/dist/type-safety.d.ts +25 -0
  168. package/dist/type-safety.js +297 -0
  169. package/dist/unit-spec.d.ts +30 -0
  170. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  171. package/dist/uploads.d.ts +9 -0
  172. package/{uploads.mjs → dist/uploads.js} +62 -54
  173. package/dist/user-copy.d.ts +9 -0
  174. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  175. package/dist/webhooks.d.ts +16 -0
  176. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  177. package/package.json +23 -8
  178. package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
  179. package/runtime/scripts/hfs/repo-identity.mjs +5 -4
  180. package/async-discipline.mjs +0 -83
  181. package/comments.mjs +0 -416
  182. package/edge-hardening.mjs +0 -139
  183. package/health-ready.mjs +0 -539
  184. package/jwt-alg.mjs +0 -45
  185. package/lib/ast.mjs +0 -88
  186. package/lib/import-source.mjs +0 -104
  187. package/lib/specifier.mjs +0 -27
  188. package/lib/subject-values.mjs +0 -55
  189. package/lib/types.mjs +0 -133
  190. package/log-safety.mjs +0 -303
  191. package/module-layering.mjs +0 -270
  192. package/naming.mjs +0 -251
  193. package/observability.mjs +0 -241
  194. package/resilience.mjs +0 -304
  195. package/service-isolation.mjs +0 -75
  196. package/spec-no-skip.mjs +0 -85
  197. package/testing.mjs +0 -384
  198. package/type-safety.mjs +0 -323
@@ -0,0 +1,9 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** An `async` function awaits something. */
3
+ export declare const asyncNeedsAwait: RuleModule;
4
+ /** The rules this law contributes to the plugin. */
5
+ export declare const rules: {
6
+ "async-needs-await": RuleModule;
7
+ };
8
+ /** Starts at error: no baseline exists, and the repositories' fix lanes clear the debt. */
9
+ export declare const recommended: Recommended;
@@ -0,0 +1,77 @@
1
+ import { walk } from "./lib/ast.js";
2
+ import { isDeclarationFile } from "./lib/path.js";
3
+ /** Whether the function body awaits, ignoring nested functions (each is judged alone). */
4
+ const awaits = (fn) => {
5
+ let found = false;
6
+ walk(fn.body, (node) => {
7
+ if (found)
8
+ return;
9
+ if (node.type === "AwaitExpression")
10
+ found = true;
11
+ else if (node.type === "ForOfStatement" && node.await)
12
+ found = true;
13
+ }, { intoFunctions: false });
14
+ return found;
15
+ };
16
+ /** Whether the function is a method whose `async` a base class, interface or decorator fixes. */
17
+ const asyncIsContractual = (fn) => {
18
+ const method = fn.parent?.type === "MethodDefinition" ? fn.parent : null;
19
+ if (!method)
20
+ return false;
21
+ if (method.decorators?.length > 0)
22
+ return true;
23
+ if (method.override)
24
+ return true;
25
+ const klass = method.parent?.parent;
26
+ if (klass && (klass.superClass || (klass.implements && klass.implements.length > 0)))
27
+ return true;
28
+ return false;
29
+ };
30
+ /** An `async` function awaits something. */
31
+ export const asyncNeedsAwait = {
32
+ meta: {
33
+ type: "problem",
34
+ docs: { description: "An `async` function contains an `await`, or it is not `async`." },
35
+ schema: [],
36
+ messages: {
37
+ noAwait: "This `async` function never awaits. It promises asynchronous work and does none, so a thrown error becomes a rejected promise for no reason and a reader looks for a suspension that is not there. Remove `async` and return the value or the promise the body already holds; where the signature must return a `Promise`, return `Promise.resolve(value)`.",
38
+ },
39
+ },
40
+ create(context) {
41
+ const filename = context.filename || context.getFilename();
42
+ if (isDeclarationFile(filename))
43
+ return {};
44
+ const check = (node) => {
45
+ if (!node.async || node.generator || !node.body)
46
+ return;
47
+ if (node.body.type !== "BlockStatement" && node.type === "ArrowFunctionExpression") {
48
+ // an expression body has no statements to await inside; `async () => x` is judged by the expression itself
49
+ let has = false;
50
+ walk(node.body, (child) => {
51
+ if (child.type === "AwaitExpression")
52
+ has = true;
53
+ }, { intoFunctions: false });
54
+ if (!has)
55
+ context.report({ node, messageId: "noAwait" });
56
+ return;
57
+ }
58
+ if (asyncIsContractual(node))
59
+ return;
60
+ if (!awaits(node))
61
+ context.report({ node, messageId: "noAwait" });
62
+ };
63
+ return {
64
+ FunctionDeclaration: check,
65
+ FunctionExpression: check,
66
+ ArrowFunctionExpression: check,
67
+ };
68
+ },
69
+ };
70
+ /** The rules this law contributes to the plugin. */
71
+ export const rules = {
72
+ "async-needs-await": asyncNeedsAwait,
73
+ };
74
+ /** Starts at error: no baseline exists, and the repositories' fix lanes clear the debt. */
75
+ export const recommended = {
76
+ "starci-be/async-needs-await": "error",
77
+ };
@@ -0,0 +1,12 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** No route picks its own guard: the global APP_GUARD chain decides. */
3
+ export declare const noAuthUseGuards: RuleModule;
4
+ /** A guard never calls, extends or receives another guard: the app registers each one as its own APP_GUARD. */
5
+ export declare const noGuardInjectsGuard: RuleModule;
6
+ /** Every rule this module ships, by the name a config switches it on under. */
7
+ export declare const rules: {
8
+ "no-auth-use-guards": RuleModule;
9
+ "no-guard-injects-guard": RuleModule;
10
+ };
11
+ /** The level a consuming repository switches this on at. */
12
+ export declare const recommended: Recommended;
@@ -9,18 +9,18 @@
9
9
  * This rule replaces `identity-needs-guard`, which asked a door that read the caller's identity to carry a guard: with
10
10
  * default-deny the guard is global, so there is nothing left for the door to carry.
11
11
  */
12
- import { importsFrom } from "./lib/declared.mjs"
13
-
12
+ import { importsFrom } from "./lib/declared.js";
13
+ import { isNode } from "./lib/rule.js";
14
14
  /** True when the decorator expression names `UseGuards`, however it was imported. */
15
15
  const isUseGuards = (decorator, aliases) => {
16
- const expression = decorator.expression.type === "CallExpression" ? decorator.expression.callee : decorator.expression
17
- if (expression.type === "Identifier") return expression.name === "UseGuards" || aliases.get(expression.name) === "UseGuards"
16
+ const expression = decorator.expression.type === "CallExpression" ? decorator.expression.callee : decorator.expression;
17
+ if (expression.type === "Identifier")
18
+ return expression.name === "UseGuards" || aliases.get(expression.name) === "UseGuards";
18
19
  if (expression.type === "MemberExpression" && !expression.computed && expression.property.type === "Identifier") {
19
- return expression.property.name === "UseGuards" && expression.object.type === "Identifier" && aliases.get(expression.object.name) === "*"
20
+ return expression.property.name === "UseGuards" && expression.object.type === "Identifier" && aliases.get(expression.object.name) === "*";
20
21
  }
21
- return false
22
- }
23
-
22
+ return false;
23
+ };
24
24
  /** No route picks its own guard: the global APP_GUARD chain decides. */
25
25
  export const noAuthUseGuards = {
26
26
  meta: {
@@ -28,60 +28,56 @@ export const noAuthUseGuards = {
28
28
  docs: { description: "`@UseGuards(...)` is not used: authentication and authorization are the global APP_GUARD chain." },
29
29
  schema: [],
30
30
  messages: {
31
- useGuards:
32
- "`@UseGuards(...)` picks a guard per door, so a door can forget it. Authentication and authorization are the global `APP_GUARD` chain of the app; delete this decorator, and open a door only with `@Public({ reason: PublicReason.X })`.",
31
+ useGuards: "`@UseGuards(...)` picks a guard per door, so a door can forget it. Authentication and authorization are the global `APP_GUARD` chain of the app; delete this decorator, and open a door only with `@Public({ reason: PublicReason.X })`.",
33
32
  },
34
33
  },
35
34
  create(context) {
36
- let aliases = new Map()
35
+ let aliases = new Map();
37
36
  return {
38
37
  Program(node) {
39
- aliases = importsFrom(node, () => true)
38
+ aliases = importsFrom(node, () => true);
40
39
  },
41
40
  Decorator(node) {
42
- if (isUseGuards(node, aliases)) context.report({ node, messageId: "useGuards" })
41
+ if (isUseGuards(node, aliases))
42
+ context.report({ node, messageId: "useGuards" });
43
43
  },
44
- }
44
+ };
45
45
  },
46
- }
47
-
48
- const GUARD_NAME = /Guard$/
49
-
46
+ };
47
+ const GUARD_NAME = /Guard$/;
50
48
  /** The identifier a type reference or expression ends in, or undefined. */
51
49
  const nameOf = (node) => {
52
- if (node === undefined || node === null) return undefined
53
- if (node.type === "Identifier") return node.name
54
- if (node.type === "TSQualifiedName") return node.right.name
55
- if (node.type === "MemberExpression" && !node.computed) return node.property.name
56
- return undefined
57
- }
58
-
50
+ if (node === undefined || node === null)
51
+ return undefined;
52
+ if (node.type === "Identifier")
53
+ return node.name;
54
+ if (node.type === "TSQualifiedName")
55
+ return node.right.name;
56
+ if (node.type === "MemberExpression" && !node.computed)
57
+ return node.property.name;
58
+ return undefined;
59
+ };
59
60
  /** True when the class is a guard: it implements CanActivate or is named `...Guard`. */
60
- const isGuardClass = (node) =>
61
- GUARD_NAME.test(node.id?.name ?? "") || (node.implements ?? []).some((item) => nameOf(item.expression) === "CanActivate")
62
-
61
+ const isGuardClass = (node) => GUARD_NAME.test(node.id?.name ?? "") || (node.implements ?? []).some((item) => nameOf(item.expression) === "CanActivate");
63
62
  /** True when the type mentions CanActivate or a `...Guard` class, directly or as `Type<...>` / a union member. */
64
63
  const namesGuardType = (type) => {
65
- if (type === undefined || type === null) return false
64
+ if (type === undefined || type === null)
65
+ return false;
66
66
  if (type.type === "TSTypeReference") {
67
- const name = nameOf(type.typeName)
68
- if (name === "CanActivate" || GUARD_NAME.test(name ?? "")) return true
69
- return (type.typeArguments ?? type.typeParameters)?.params?.some(namesGuardType) ?? false
67
+ const name = nameOf(type.typeName);
68
+ if (name === "CanActivate" || GUARD_NAME.test(name ?? ""))
69
+ return true;
70
+ const legacy = Reflect.get(type, "typeParameters");
71
+ return (type.typeArguments ?? (isNode(legacy) && legacy.type === "TSTypeParameterInstantiation" ? legacy : undefined))?.params?.some(namesGuardType) ?? false;
70
72
  }
71
- if (type.type === "TSUnionType" || type.type === "TSIntersectionType") return type.types.some(namesGuardType)
72
- return false
73
- }
74
-
75
- const parameterOf = (parameter) => (parameter.type === "TSParameterProperty" ? parameter.parameter : parameter)
76
-
73
+ if (type.type === "TSUnionType" || type.type === "TSIntersectionType")
74
+ return type.types.some(namesGuardType);
75
+ return false;
76
+ };
77
+ const parameterOf = (parameter) => (parameter.type === "TSParameterProperty" ? parameter.parameter : parameter);
77
78
  /** True when an `@Inject(SomeGuard)` style decorator names a guard class. */
78
- const injectsGuardToken = (parameter) =>
79
- (parameter.decorators ?? []).some(
80
- (decorator) =>
81
- decorator.expression.type === "CallExpression" &&
82
- decorator.expression.arguments.some((argument) => GUARD_NAME.test(nameOf(argument) ?? "")),
83
- )
84
-
79
+ const injectsGuardToken = (parameter) => (parameter.decorators ?? []).some((decorator) => decorator.expression.type === "CallExpression" &&
80
+ decorator.expression.arguments.some((argument) => GUARD_NAME.test(nameOf(argument) ?? "")));
85
81
  /** A guard never calls, extends or receives another guard: the app registers each one as its own APP_GUARD. */
86
82
  export const noGuardInjectsGuard = {
87
83
  meta: {
@@ -89,34 +85,32 @@ export const noGuardInjectsGuard = {
89
85
  docs: { description: "A guard class has no constructor parameter that is another guard (no CanActivate-typed parameter)." },
90
86
  schema: [],
91
87
  messages: {
92
- guardInGuard:
93
- "A guard must not inject another guard (found a `{{name}}` constructor parameter). Each guard is its own global `APP_GUARD` in the fixed order RateLimitGuard, OriginGuard, CredentialGuard, AuthGuard; share logic through a service or a port, and let metadata (`@Credential`, `@Public`) select the behavior.",
88
+ guardInGuard: "A guard must not inject another guard (found a `{{name}}` constructor parameter). Each guard is its own global `APP_GUARD` in the fixed order RateLimitGuard, OriginGuard, CredentialGuard, AuthGuard; share logic through a service or a port, and let metadata (`@Credential`, `@Public`) select the behavior.",
94
89
  },
95
90
  },
96
91
  create(context) {
97
92
  const check = (node) => {
98
- if (!isGuardClass(node)) return
99
- const constructor = node.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "constructor")
93
+ if (!isGuardClass(node))
94
+ return;
95
+ const constructor = node.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "constructor");
100
96
  for (const raw of constructor?.value.params ?? []) {
101
- const parameter = parameterOf(raw)
102
- const annotation = parameter.typeAnnotation?.typeAnnotation
97
+ const parameter = parameterOf(raw);
98
+ const annotation = parameter.typeAnnotation?.typeAnnotation;
103
99
  if (namesGuardType(annotation) || injectsGuardToken(raw) || injectsGuardToken(parameter)) {
104
- context.report({ node: raw, messageId: "guardInGuard", data: { name: parameter.name ?? "guard" } })
100
+ context.report({ node: raw, messageId: "guardInGuard", data: { name: ("name" in parameter ? parameter.name : undefined) ?? "guard" } });
105
101
  }
106
102
  }
107
- }
108
- return { ClassDeclaration: check, ClassExpression: check }
103
+ };
104
+ return { ClassDeclaration: check, ClassExpression: check };
109
105
  },
110
- }
111
-
106
+ };
112
107
  /** Every rule this module ships, by the name a config switches it on under. */
113
108
  export const rules = {
114
109
  "no-auth-use-guards": noAuthUseGuards,
115
110
  "no-guard-injects-guard": noGuardInjectsGuard,
116
- }
117
-
111
+ };
118
112
  /** The level a consuming repository switches this on at. */
119
113
  export const recommended = {
120
114
  "starci-be/no-auth-use-guards": "error",
121
115
  "starci-be/no-guard-injects-guard": "error",
122
- }
116
+ };
@@ -0,0 +1,15 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** Every schema built by this file is bounded and none accepts anything. */
3
+ export declare const schemaBounded: RuleModule;
4
+ /** Where a schema may live, and what shares a file with it. */
5
+ export declare const schemaPlace: RuleModule;
6
+ /** What a schema file holds: zod values and types, nothing that runs. */
7
+ export declare const schemaFileValuesOnly: RuleModule;
8
+ /** The rules this law contributes to the plugin. */
9
+ export declare const rules: {
10
+ "schema-bounded": RuleModule;
11
+ "schema-place": RuleModule;
12
+ "schema-file-values-only": RuleModule;
13
+ };
14
+ /** Both start at error: no baseline exists. */
15
+ export declare const recommended: Recommended;
@@ -14,73 +14,75 @@
14
14
  * `z.unknown()` and `z.json()` are refused: an unbounded array whose elements all fail validation allocates an issue each
15
15
  * (GHSA-mrhx-c7xc-m3w5), and an unbounded string is an unbounded cost whatever the zod version.
16
16
  */
17
- import { hfsOf } from "./lib/hfs.mjs"
18
- import { normalizePath } from "./lib/path.mjs"
19
- import { isTransportSlot } from "./lib/transport-slots.mjs"
20
- import { SCHEMA_TIERS, schemaFileProblems } from "./lib/schema-values.mjs"
21
-
22
- const ZOD = /^zod(?:\/|$)/
17
+ import { hfsOf } from "./lib/hfs.js";
18
+ import { normalizePath } from "./lib/path.js";
19
+ import { isTransportSlot } from "./lib/transport-slots.js";
20
+ import { SCHEMA_TIERS, schemaFileProblems } from "./lib/schema-values.js";
21
+ const ZOD = /^zod(?:\/|$)/;
23
22
  /** The imports of the other validation layer, which never share a file with a schema. */
24
- const MIXED = new Set(["class-validator", "class-transformer", "@nestjs/graphql"])
25
- const SCHEMA_FILE = /\.schema(?:\.spec)?\.ts$/
26
-
23
+ const MIXED = new Set(["class-validator", "class-transformer", "@nestjs/graphql"]);
24
+ const SCHEMA_FILE = /\.schema(?:\.spec)?\.ts$/;
27
25
  /** Constructors that build a string-valued schema and owe a `.max(n)` or `.length(n)`. */
28
- const STRINGY = new Set(["string", "email", "url", "httpUrl", "hostname", "base64", "base64url", "jwt", "emoji", "hex", "iso.datetime", "iso.date", "iso.time", "iso.duration"])
26
+ const STRINGY = new Set(["string", "email", "url", "httpUrl", "hostname", "base64", "base64url", "jwt", "emoji", "hex", "iso.datetime", "iso.date", "iso.time", "iso.duration"]);
29
27
  /** The ISO namespace constructs strings; `z.date()` instead constructs a Date-valued schema. */
30
- const ISO_STRINGY = new Set(["datetime", "date", "time", "duration"])
28
+ const ISO_STRINGY = new Set(["datetime", "date", "time", "duration"]);
31
29
  /** Constructors that build a counted container: bounded by `.max(n)`, `.length(n)` or `.size(n)`. */
32
- const COUNTED = new Set(["array", "set"])
30
+ const COUNTED = new Set(["array", "set"]);
33
31
  /** Constructors whose entry count only a refinement can bound. */
34
- const REFINED = new Set(["record", "looseRecord", "partialRecord", "map"])
32
+ const REFINED = new Set(["record", "looseRecord", "partialRecord", "map"]);
35
33
  /** Constructors that accept anything: refused outright. */
36
- const OPEN = new Set(["any", "unknown", "json"])
34
+ const OPEN = new Set(["any", "unknown", "json"]);
37
35
  /** The chain members that bound a string or a counted container. */
38
- const BOUNDING = new Set(["max", "length", "size"])
39
- const REFINING = new Set(["refine", "superRefine", "check"])
40
-
36
+ const BOUNDING = new Set(["max", "length", "size"]);
37
+ const REFINING = new Set(["refine", "superRefine", "check"]);
41
38
  /** The member names a `z.coerce.string()` style callee passes through before its constructor. */
42
- const PASS_THROUGH = new Set(["coerce"])
43
-
39
+ const PASS_THROUGH = new Set(["coerce"]);
44
40
  /** True for a bound argument that is not a way to say "no bound": absent, `Infinity`, `NaN`, a non-positive literal, `Number.MAX_*`. */
45
41
  const isRealBound = (argument) => {
46
- if (argument === undefined) return false
47
- if (argument.type === "Identifier") return argument.name !== "Infinity" && argument.name !== "NaN" && argument.name !== "undefined"
48
- if (argument.type === "Literal") return typeof argument.value === "number" && Number.isFinite(argument.value) && argument.value > 0
42
+ if (argument === undefined)
43
+ return false;
44
+ if (argument.type === "Identifier")
45
+ return argument.name !== "Infinity" && argument.name !== "NaN" && argument.name !== "undefined";
46
+ if (argument.type === "Literal")
47
+ return typeof argument.value === "number" && Number.isFinite(argument.value) && argument.value > 0;
49
48
  if (argument.type === "MemberExpression" && !argument.computed && argument.object.type === "Identifier" && argument.object.name === "Number") {
50
- return !/^(?:MAX_|POSITIVE_INFINITY)/.test(argument.property.name ?? "")
49
+ return !/^(?:MAX_|POSITIVE_INFINITY)/.test(argument.property.name ?? "");
51
50
  }
52
- return true
53
- }
54
-
51
+ return true;
52
+ };
55
53
  /** The methods chained on `node` (`z.string().trim().max(5)` gives `trim`, `max` with their calls), outermost last. */
56
54
  const chainOf = (node) => {
57
- const calls = []
58
- let current = node
55
+ const calls = [];
56
+ let current = node;
59
57
  for (;;) {
60
- const member = current.parent
61
- if (member?.type !== "MemberExpression" || member.object !== current || member.computed || member.property.type !== "Identifier") break
62
- const call = member.parent
63
- if (call?.type !== "CallExpression" || call.callee !== member) break
64
- calls.push({ name: member.property.name, call })
65
- current = call
58
+ const member = current.parent;
59
+ if (member?.type !== "MemberExpression" || member.object !== current || member.computed || member.property.type !== "Identifier")
60
+ break;
61
+ const call = member.parent;
62
+ if (call?.type !== "CallExpression" || call.callee !== member)
63
+ break;
64
+ calls.push({ name: member.property.name, call });
65
+ current = call;
66
66
  }
67
- return calls
68
- }
69
-
67
+ return calls;
68
+ };
70
69
  /** Resolves a zod constructor, including `z.iso.datetime()` and a renamed named import of `iso`. */
71
70
  const constructorOf = (callee, namespaces, named) => {
72
- if (callee.type === "Identifier") return named.get(callee.name) ?? null
73
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return null
74
- let object = callee.object
71
+ if (callee.type === "Identifier")
72
+ return named.get(callee.name) ?? null;
73
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
74
+ return null;
75
+ let object = callee.object;
75
76
  if (ISO_STRINGY.has(callee.property.name)) {
76
- const importedIso = object.type === "Identifier" && named.get(object.name) === "iso"
77
- const namespaceIso = object.type === "MemberExpression" && !object.computed && object.property.type === "Identifier" && object.property.name === "iso" && object.object.type === "Identifier" && namespaces.has(object.object.name)
78
- if (importedIso || namespaceIso) return `iso.${callee.property.name}`
77
+ const importedIso = object.type === "Identifier" && named.get(object.name) === "iso";
78
+ const namespaceIso = object.type === "MemberExpression" && !object.computed && object.property.type === "Identifier" && object.property.name === "iso" && object.object.type === "Identifier" && namespaces.has(object.object.name);
79
+ if (importedIso || namespaceIso)
80
+ return `iso.${callee.property.name}`;
79
81
  }
80
- while (object.type === "MemberExpression" && !object.computed && object.property.type === "Identifier" && PASS_THROUGH.has(object.property.name)) object = object.object
81
- return object.type === "Identifier" && namespaces.has(object.name) ? callee.property.name : null
82
- }
83
-
82
+ while (object.type === "MemberExpression" && !object.computed && object.property.type === "Identifier" && PASS_THROUGH.has(object.property.name))
83
+ object = object.object;
84
+ return object.type === "Identifier" && namespaces.has(object.name) ? callee.property.name : null;
85
+ };
84
86
  /** Every schema built by this file is bounded and none accepts anything. */
85
87
  export const schemaBounded = {
86
88
  meta: {
@@ -96,63 +98,71 @@ export const schemaBounded = {
96
98
  },
97
99
  },
98
100
  create(context) {
99
- const namespaces = new Set()
100
- const named = new Map()
101
+ const namespaces = new Set();
102
+ const named = new Map();
101
103
  return {
102
104
  ImportDeclaration(node) {
103
- if (typeof node.source.value !== "string" || !ZOD.test(node.source.value)) return
105
+ if (typeof node.source.value !== "string" || !ZOD.test(node.source.value))
106
+ return;
104
107
  for (const specifier of node.specifiers) {
105
- if (specifier.type === "ImportNamespaceSpecifier") namespaces.add(specifier.local.name)
108
+ if (specifier.type === "ImportNamespaceSpecifier")
109
+ namespaces.add(specifier.local.name);
106
110
  else if (specifier.type === "ImportSpecifier") {
107
- const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : String(specifier.imported.value)
108
- if (imported === "z") namespaces.add(specifier.local.name)
109
- else named.set(specifier.local.name, imported)
110
- } else if (specifier.type === "ImportDefaultSpecifier") namespaces.add(specifier.local.name)
111
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : String(specifier.imported.value);
112
+ if (imported === "z")
113
+ namespaces.add(specifier.local.name);
114
+ else
115
+ named.set(specifier.local.name, imported);
116
+ }
117
+ else if (specifier.type === "ImportDefaultSpecifier")
118
+ namespaces.add(specifier.local.name);
111
119
  }
112
120
  },
113
121
  CallExpression(node) {
114
- const name = constructorOf(node.callee, namespaces, named)
115
- if (name === null) return
122
+ const name = constructorOf(node.callee, namespaces, named);
123
+ if (name === null)
124
+ return;
116
125
  if (OPEN.has(name)) {
117
- context.report({ node, messageId: "open", data: { name } })
118
- return
126
+ context.report({ node, messageId: "open", data: { name } });
127
+ return;
119
128
  }
120
- const kind = STRINGY.has(name) ? "string" : COUNTED.has(name) ? "counted" : REFINED.has(name) ? "refined" : null
121
- if (kind === null) return
122
- const chain = chainOf(node)
129
+ const kind = STRINGY.has(name) ? "string" : COUNTED.has(name) ? "counted" : REFINED.has(name) ? "refined" : null;
130
+ if (kind === null)
131
+ return;
132
+ const chain = chainOf(node);
123
133
  if (kind === "refined") {
124
- if (!chain.some((entry) => REFINING.has(entry.name))) context.report({ node, messageId: "refined", data: { name } })
125
- return
134
+ if (!chain.some((entry) => REFINING.has(entry.name)))
135
+ context.report({ node, messageId: "refined", data: { name } });
136
+ return;
126
137
  }
127
- const bounds = chain.filter((entry) => BOUNDING.has(entry.name))
128
- if (bounds.length === 0) {
129
- context.report({ node, messageId: kind, data: { name } })
130
- return
138
+ const bounds = chain.filter((entry) => BOUNDING.has(entry.name));
139
+ const [first] = bounds;
140
+ if (!first) {
141
+ context.report({ node, messageId: kind, data: { name } });
142
+ return;
131
143
  }
132
- if (!bounds.some((entry) => isRealBound(entry.call.arguments[0]))) context.report({ node: bounds[0].call, messageId: "bound", data: { name: bounds[0].name } })
144
+ if (!bounds.some((entry) => isRealBound(entry.call.arguments[0])))
145
+ context.report({ node: first.call, messageId: "bound", data: { name: first.name } });
133
146
  },
134
- }
147
+ };
135
148
  },
136
- }
137
-
149
+ };
138
150
  /** The module specifiers a file references, with the node that names each (imports, re-exports, `import()` and `require()`). */
139
151
  const referenceNodes = (node) => {
140
152
  switch (node.type) {
141
153
  case "ImportDeclaration":
142
154
  case "ExportAllDeclaration":
143
155
  case "ExportNamedDeclaration":
144
- return node.source ? [node.source] : []
156
+ return node.source ? [node.source] : [];
145
157
  case "ImportExpression":
146
- return [node.source]
158
+ return [node.source];
147
159
  case "CallExpression":
148
- return node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments[0] ? [node.arguments[0]] : []
160
+ return node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments[0] ? [node.arguments[0]] : [];
149
161
  default:
150
- return []
162
+ return [];
151
163
  }
152
- }
153
-
154
- const referencesZod = (node) => referenceNodes(node).filter((source) => source.type === "Literal" && typeof source.value === "string" && ZOD.test(source.value))
155
-
164
+ };
165
+ const referencesZod = (node) => referenceNodes(node).filter((source) => source.type === "Literal" && typeof source.value === "string" && ZOD.test(source.value));
156
166
  /** Where a schema may live, and what shares a file with it. */
157
167
  export const schemaPlace = {
158
168
  meta: {
@@ -167,29 +177,34 @@ export const schemaPlace = {
167
177
  },
168
178
  },
169
179
  create(context) {
170
- const hfs = hfsOf(context)
171
- const filename = normalizePath(context.filename)
172
- const slot = hfs.slotOf(filename) ?? ""
173
- const tier = hfs.tierOf(filename)
174
- const inDoor = isTransportSlot(slot) || slot.startsWith("be.transport.") || hfs.relative(filename).split("/").slice(0, -1).includes("dto")
175
- const isSchemaFile = SCHEMA_FILE.test(filename)
180
+ const hfs = hfsOf(context);
181
+ const filename = normalizePath(context.filename);
182
+ const slot = hfs.slotOf(filename) ?? "";
183
+ const tier = hfs.tierOf(filename);
184
+ const inDoor = isTransportSlot(slot) || slot.startsWith("be.transport.") || hfs.relative(filename).split("/").slice(0, -1).includes("dto");
185
+ const isSchemaFile = SCHEMA_FILE.test(filename);
176
186
  return {
177
187
  "*"(node) {
178
- const found = referencesZod(node)
179
- if (found.length === 0) return
180
- if (inDoor) context.report({ node: found[0], messageId: "door" })
181
- else if (tier === "feature") context.report({ node: found[0], messageId: "tier", data: { tier } })
182
- else if (!isSchemaFile) context.report({ node: found[0], messageId: "file" })
183
- else if (!SCHEMA_TIERS.has(tier)) context.report({ node: found[0], messageId: "tier", data: { tier: tier ?? "non-owner" } })
188
+ const [first] = referencesZod(node);
189
+ if (!first)
190
+ return;
191
+ if (inDoor)
192
+ context.report({ node: first, messageId: "door" });
193
+ else if (tier === "feature")
194
+ context.report({ node: first, messageId: "tier", data: { tier } });
195
+ else if (!isSchemaFile)
196
+ context.report({ node: first, messageId: "file" });
197
+ else if (!SCHEMA_TIERS.has(tier))
198
+ context.report({ node: first, messageId: "tier", data: { tier: tier ?? "non-owner" } });
184
199
  },
185
200
  ImportDeclaration(node) {
186
- if (!isSchemaFile || inDoor || !MIXED.has(node.source.value)) return
187
- context.report({ node: node.source, messageId: "mixed", data: { source: node.source.value } })
201
+ if (!isSchemaFile || inDoor || !MIXED.has(node.source.value))
202
+ return;
203
+ context.report({ node: node.source, messageId: "mixed", data: { source: node.source.value } });
188
204
  },
189
- }
205
+ };
190
206
  },
191
- }
192
-
207
+ };
193
208
  /** What a schema file holds: zod values and types, nothing that runs. */
194
209
  export const schemaFileValuesOnly = {
195
210
  meta: {
@@ -201,25 +216,25 @@ export const schemaFileValuesOnly = {
201
216
  },
202
217
  },
203
218
  create(context) {
204
- if (!SCHEMA_FILE.test(normalizePath(context.filename)) || context.filename.endsWith(".spec.ts")) return {}
219
+ if (!SCHEMA_FILE.test(normalizePath(context.filename)) || context.filename.endsWith(".spec.ts"))
220
+ return {};
205
221
  return {
206
222
  "Program:exit"(node) {
207
- for (const problem of schemaFileProblems(context.sourceCode.text)) context.report({ node, messageId: "logic", data: { problem } })
223
+ for (const problem of schemaFileProblems(context.sourceCode.text))
224
+ context.report({ node, messageId: "logic", data: { problem } });
208
225
  },
209
- }
226
+ };
210
227
  },
211
- }
212
-
228
+ };
213
229
  /** The rules this law contributes to the plugin. */
214
230
  export const rules = {
215
231
  "schema-bounded": schemaBounded,
216
232
  "schema-place": schemaPlace,
217
233
  "schema-file-values-only": schemaFileValuesOnly,
218
- }
219
-
234
+ };
220
235
  /** Both start at error: no baseline exists. */
221
236
  export const recommended = {
222
237
  "starci-be/schema-bounded": "error",
223
238
  "starci-be/schema-place": "error",
224
239
  "starci-be/schema-file-values-only": "error",
225
- }
240
+ };
@@ -0,0 +1,21 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** A spec arranges rows through a builder, never by writing them itself. */
3
+ export declare const specNoRawInsert: RuleModule;
4
+ /** A spec builds each persistence entity as an object literal at most once; further rows come from a builder. */
5
+ export declare const specNoRepeatedRowLiteral: RuleModule;
6
+ /** A module of the test tree that exports something creating persisted rows is a builder and lives in the builders slot. */
7
+ export declare const persistingBuilderInBuildersSlot: RuleModule;
8
+ /** A builder arranges data only: no assertion, deterministic defaults. */
9
+ export declare const builderArrangesOnly: RuleModule;
10
+ /** The test tree keeps every database constraint on. */
11
+ export declare const testsKeepConstraints: RuleModule;
12
+ /** The rules this law contributes to the plugin. */
13
+ export declare const rules: {
14
+ "persisting-builder-in-builders-slot": RuleModule;
15
+ "spec-no-raw-insert": RuleModule;
16
+ "spec-no-repeated-row-literal": RuleModule;
17
+ "builder-arranges-only": RuleModule;
18
+ "tests-keep-constraints": RuleModule;
19
+ };
20
+ /** Every rule of this law ships at `error`. */
21
+ export declare const recommended: Recommended;