@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,96 @@
1
+ /**
2
+ * Type-aware helpers: a rule asks what a node IS (its TypeScript type and where that type is declared), never what it
3
+ * is called. `starciBeConfig` turns typed linting on for every file (`parserOptions.projectService`), so these
4
+ * helpers refuse to run without the program instead of falling back to a name match: a rule that silently degrades to
5
+ * a heuristic is the loophole the owner closed.
6
+ */
7
+ import ts from "typescript";
8
+ import type { ParserServicesWithTypeInformation } from "@typescript-eslint/utils";
9
+ import type { Context, Node } from "./rule.js";
10
+ /** The TypeScript services of the linted file: the program, its checker and the ESTree to TS node map. */
11
+ export interface Typed {
12
+ readonly program: ts.Program;
13
+ readonly checker: ts.TypeChecker;
14
+ readonly toTs: ParserServicesWithTypeInformation["esTreeNodeToTSNodeMap"]["get"];
15
+ }
16
+ /** Where a type is declared: the symbol name, the forward-slash file and the package (null for the repository's own source). */
17
+ export interface TypeOrigin {
18
+ readonly name: string;
19
+ readonly file: string;
20
+ readonly module: string | null;
21
+ }
22
+ /**
23
+ * The TypeScript services of the file being linted.
24
+ *
25
+ * @param context - The ESLint rule context.
26
+ * @returns The program, its checker and the ESTree to TS node map.
27
+ */
28
+ export declare const typed: (context: Context) => Typed;
29
+ /**
30
+ * Where the type of an ESTree node (or of a type annotation node) is declared.
31
+ *
32
+ * @param context - The ESLint rule context.
33
+ * @param node - An expression, identifier, parameter or type node.
34
+ * @returns Each declaration's symbol name, forward-slash file path and package; `[]` for a primitive or an anonymous type.
35
+ */
36
+ export declare const typeOrigins: (context: Context, node: Node) => TypeOrigin[];
37
+ /**
38
+ * Where a TypeScript type is declared, for a rule that already holds a type from the checker (an alias argument, a call signature return).
39
+ *
40
+ * @param checker - The program's type checker.
41
+ * @param type - A TypeScript type.
42
+ * @returns The declaration origins, as `typeOrigins` returns them.
43
+ */
44
+ export declare const originsOfType: (checker: ts.TypeChecker, type: ts.Type | undefined) => TypeOrigin[];
45
+ /** Whether a value is a TypeScript node (it carries a numeric `kind`). */
46
+ export declare const isTsNode: (value: unknown) => value is ts.Node;
47
+ /**
48
+ * The TypeScript node a node holds under `key` (`body`, `initializer`, `expression`), or undefined when it holds none: the typed
49
+ * form of reading `declaration?.body` off a declaration whose kind is not known.
50
+ */
51
+ export declare const childNode: (node: ts.Node | null | undefined, key: string) => ts.Node | undefined;
52
+ /** A symbol after alias resolution (`import { X as Y }` gives X), or the symbol itself. */
53
+ export declare const resolvedSymbol: (checker: ts.TypeChecker, symbol: ts.Symbol | undefined) => ts.Symbol | undefined;
54
+ /**
55
+ * The package a declaration belongs to: the name of an enclosing `declare module "<pkg>"`, else the package directory
56
+ * of a `node_modules/<pkg>/` (or `node_modules/@scope/<pkg>/`) file, else null for the repository's own source.
57
+ */
58
+ export declare const moduleOf: (declaration: ts.Node, file: string) => string | null;
59
+ /**
60
+ * True when the node's type is the named type declared in a file whose path satisfies `fromFile`.
61
+ *
62
+ * @param context - The ESLint rule context.
63
+ * @param node - The node to type.
64
+ * @param name - The declared symbol name (`EntityManager`).
65
+ * @param fromFile - Filter on the declaring file (a package path, a slot).
66
+ * @returns Whether one of the node's type origins matches.
67
+ */
68
+ export declare const isTypeNamed: (context: Context, node: Node, name: string, fromFile?: (file: string) => boolean) => boolean;
69
+ /**
70
+ * True when the node's type is `name` declared by the package `pkg` (`typeorm`, `@nestjs/cqrs`).
71
+ *
72
+ * @param context - The ESLint rule context.
73
+ * @param node - The node to type.
74
+ * @param name - The declared symbol name.
75
+ * @param pkg - The package that declares it.
76
+ * @returns Whether the node's type is that package's `name`.
77
+ */
78
+ export declare const isPackageType: (context: Context, node: Node, name: string, pkg: string) => boolean;
79
+ /**
80
+ * The package that declares the value an expression names (`APP_GUARD` and `Injectable` of `@nestjs/*`), after alias resolution, or
81
+ * null for the repository's own declaration, an unresolved name or an expression that names no symbol.
82
+ *
83
+ * @param context - The ESLint rule context.
84
+ * @param node - An identifier, member expression or call (its callee is read).
85
+ * @returns The package name.
86
+ */
87
+ export declare const packageOfExport: (context: Context, node: Node) => string | null;
88
+ /**
89
+ * True when the node is a reference to a value the package `pkg` exports (`APP_GUARD` of `@nestjs/core`). A local constant of the same name is not.
90
+ *
91
+ * @param context - The ESLint rule context.
92
+ * @param node - An identifier or member expression.
93
+ * @param pkg - The package that must declare the referenced value.
94
+ * @returns Whether the node references an export of that package.
95
+ */
96
+ export declare const isPackageExport: (context: Context, node: Node, pkg: string) => boolean;
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Type-aware helpers: a rule asks what a node IS (its TypeScript type and where that type is declared), never what it
3
+ * is called. `starciBeConfig` turns typed linting on for every file (`parserOptions.projectService`), so these
4
+ * helpers refuse to run without the program instead of falling back to a name match: a rule that silently degrades to
5
+ * a heuristic is the loophole the owner closed.
6
+ */
7
+ import ts from "typescript";
8
+ /**
9
+ * The TypeScript services of the file being linted.
10
+ *
11
+ * @param context - The ESLint rule context.
12
+ * @returns The program, its checker and the ESTree to TS node map.
13
+ */
14
+ export const typed = (context) => {
15
+ const services = context.sourceCode?.parserServices ?? context.parserServices;
16
+ const program = services?.program;
17
+ const map = services?.esTreeNodeToTSNodeMap;
18
+ if (!program || !map) {
19
+ throw new Error(`${context.id ?? "a starci-be rule"} needs typed linting (parserOptions.projectService); lint through starciBeConfig, which turns it on`);
20
+ }
21
+ return { program, checker: program.getTypeChecker(), toTs: (node) => map.get(node) };
22
+ };
23
+ /**
24
+ * The declarations of a type: those of its alias (a written `type Repo = Repository<T>`) and those of its own symbol, each
25
+ * after alias resolution (an imported type alias resolves to its target). Both are origins, so a rename by alias hides nothing.
26
+ */
27
+ const declarationsOf = (checker, type) => {
28
+ if (!type)
29
+ return [];
30
+ return [type.aliasSymbol, type.getSymbol?.()].flatMap((symbol) => {
31
+ if (!symbol)
32
+ return [];
33
+ const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
34
+ return target.getDeclarations?.() ?? [];
35
+ });
36
+ };
37
+ /**
38
+ * Where the type of an ESTree node (or of a type annotation node) is declared.
39
+ *
40
+ * @param context - The ESLint rule context.
41
+ * @param node - An expression, identifier, parameter or type node.
42
+ * @returns Each declaration's symbol name, forward-slash file path and package; `[]` for a primitive or an anonymous type.
43
+ */
44
+ export const typeOrigins = (context, node) => {
45
+ const { checker, toTs } = typed(context);
46
+ const tsNode = toTs(node);
47
+ if (!tsNode)
48
+ return [];
49
+ return originsOfType(checker, ts.isTypeNode(tsNode) ? checker.getTypeFromTypeNode(tsNode) : checker.getTypeAtLocation(tsNode));
50
+ };
51
+ /**
52
+ * Where a TypeScript type is declared, for a rule that already holds a type from the checker (an alias argument, a call signature return).
53
+ *
54
+ * @param checker - The program's type checker.
55
+ * @param type - A TypeScript type.
56
+ * @returns The declaration origins, as `typeOrigins` returns them.
57
+ */
58
+ export const originsOfType = (checker, type) => {
59
+ const parts = type?.isUnion?.() ? type.types : [type];
60
+ return parts.flatMap((part) => declarationsOf(checker, part).map((declaration) => {
61
+ const file = String(declaration.getSourceFile().fileName).replace(/\\/g, "/");
62
+ return { name: identifierNameOf(declaration), file, module: moduleOf(declaration, file) };
63
+ }));
64
+ };
65
+ /** Whether a value is a TypeScript node (it carries a numeric `kind`). */
66
+ export const isTsNode = (value) => typeof value === "object" && value !== null && "kind" in value && typeof value.kind === "number";
67
+ /**
68
+ * The TypeScript node a node holds under `key` (`body`, `initializer`, `expression`), or undefined when it holds none: the typed
69
+ * form of reading `declaration?.body` off a declaration whose kind is not known.
70
+ */
71
+ export const childNode = (node, key) => {
72
+ if (!node)
73
+ return undefined;
74
+ const value = Reflect.get(node, key);
75
+ return isTsNode(value) ? value : undefined;
76
+ };
77
+ /** A symbol after alias resolution (`import { X as Y }` gives X), or the symbol itself. */
78
+ export const resolvedSymbol = (checker, symbol) => (symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol);
79
+ /** The text of a declaration's own `name` when that name is an identifier, else "". */
80
+ const identifierNameOf = (declaration) => {
81
+ const name = "name" in declaration ? declaration.name : undefined;
82
+ return isTsNode(name) && ts.isIdentifier(name) ? name.text : "";
83
+ };
84
+ /**
85
+ * The package a declaration belongs to: the name of an enclosing `declare module "<pkg>"`, else the package directory
86
+ * of a `node_modules/<pkg>/` (or `node_modules/@scope/<pkg>/`) file, else null for the repository's own source.
87
+ */
88
+ export const moduleOf = (declaration, file) => {
89
+ for (let node = declaration.parent; node; node = node.parent) {
90
+ if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name))
91
+ return node.name.text;
92
+ }
93
+ const match = /\/node_modules\/((?:@[^/]+\/)?[^/]+)\//.exec(file);
94
+ return match?.[1] ?? null;
95
+ };
96
+ /**
97
+ * True when the node's type is the named type declared in a file whose path satisfies `fromFile`.
98
+ *
99
+ * @param context - The ESLint rule context.
100
+ * @param node - The node to type.
101
+ * @param name - The declared symbol name (`EntityManager`).
102
+ * @param fromFile - Filter on the declaring file (a package path, a slot).
103
+ * @returns Whether one of the node's type origins matches.
104
+ */
105
+ export const isTypeNamed = (context, node, name, fromFile = () => true) => typeOrigins(context, node).some((origin) => origin.name === name && fromFile(origin.file));
106
+ /**
107
+ * True when the node's type is `name` declared by the package `pkg` (`typeorm`, `@nestjs/cqrs`).
108
+ *
109
+ * @param context - The ESLint rule context.
110
+ * @param node - The node to type.
111
+ * @param name - The declared symbol name.
112
+ * @param pkg - The package that declares it.
113
+ * @returns Whether the node's type is that package's `name`.
114
+ */
115
+ export const isPackageType = (context, node, name, pkg) => typeOrigins(context, node).some((origin) => origin.name === name && origin.module === pkg);
116
+ /**
117
+ * The package that declares the value an expression names (`APP_GUARD` and `Injectable` of `@nestjs/*`), after alias resolution, or
118
+ * null for the repository's own declaration, an unresolved name or an expression that names no symbol.
119
+ *
120
+ * @param context - The ESLint rule context.
121
+ * @param node - An identifier, member expression or call (its callee is read).
122
+ * @returns The package name.
123
+ */
124
+ export const packageOfExport = (context, node) => {
125
+ const { checker, toTs } = typed(context);
126
+ let tsNode = toTs(node);
127
+ if (!tsNode)
128
+ return null;
129
+ if (ts.isCallExpression(tsNode))
130
+ tsNode = tsNode.expression;
131
+ const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(tsNode) ? tsNode.name : tsNode);
132
+ if (!symbol)
133
+ return null;
134
+ const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
135
+ for (const declaration of target.getDeclarations?.() ?? []) {
136
+ const module = moduleOf(declaration, String(declaration.getSourceFile().fileName).replace(/\\/g, "/"));
137
+ if (module !== null)
138
+ return module;
139
+ }
140
+ return null;
141
+ };
142
+ /**
143
+ * True when the node is a reference to a value the package `pkg` exports (`APP_GUARD` of `@nestjs/core`). A local constant of the same name is not.
144
+ *
145
+ * @param context - The ESLint rule context.
146
+ * @param node - An identifier or member expression.
147
+ * @param pkg - The package that must declare the referenced value.
148
+ * @returns Whether the node references an export of that package.
149
+ */
150
+ export const isPackageExport = (context, node, pkg) => packageOfExport(context, node) === pkg;
@@ -0,0 +1,48 @@
1
+ import type { HfsUnitRole, HfsView } from "./hfs.js";
2
+ /** A unit-tested role, or an optional logic role whose spec the coverage slot asks for. */
3
+ export interface SpecRole {
4
+ readonly role: string;
5
+ readonly spec: string;
6
+ readonly slot?: string;
7
+ readonly exempt?: readonly string[];
8
+ readonly optional?: boolean;
9
+ }
10
+ /** The file name of a linted path. */
11
+ export declare const baseOf: (filename: string) => string;
12
+ /**
13
+ * Whether a file is a unit spec.
14
+ *
15
+ * @param {object} hfs - The HFS view.
16
+ * @param {string} filename - The linted file.
17
+ * @returns {boolean} True for a `*.spec.ts` that is not a spec of another test kind.
18
+ */
19
+ export declare const isUnitSpecFile: (hfs: HfsView, filename: string) => boolean;
20
+ /** Whether a file is a `<name>.service.spec.ts` unit spec. */
21
+ export declare const isServiceSpecFile: (hfs: HfsView, filename: string) => boolean;
22
+ /**
23
+ * The unit-tested roles of the back end: `ruleParams.be.unitRoles` of the slot manifest, the ONE list (`[{ role, spec, slot? }]`).
24
+ *
25
+ * @param {object} hfs - The HFS view.
26
+ * @returns {ReadonlyArray<{ role: string, spec: string, slot?: string }>} The roles.
27
+ */
28
+ export declare const unitRoles: (hfs: HfsView) => readonly HfsUnitRole[];
29
+ /**
30
+ * The unit-tested role whose spec a file is (`<name>.<role>.spec.ts`, in the role's slot), or null.
31
+ *
32
+ * @param {object} hfs - The HFS view.
33
+ * @param {string} filename - The linted file.
34
+ * @returns {object | null} The role entry.
35
+ */
36
+ export declare const unitRoleOfSpec: (hfs: HfsView, filename: string) => SpecRole | null;
37
+ /** Whether a file is the spec of a value role (`ruleParams.be.valueRoles`: a zod schema): its subject is a declared value, so the spec parses it and builds no testing module. */
38
+ export declare const isValueRoleSpec: (hfs: HfsView, filename: string) => boolean;
39
+ /**
40
+ * The unit-tested role whose subject a file is (`<name>.<role>.ts`, in the role's slot, outside the test tree), or null.
41
+ *
42
+ * @param {object} hfs - The HFS view.
43
+ * @param {string} filename - The linted file.
44
+ * @returns {object | null} The role entry.
45
+ */
46
+ export declare const unitRoleOfSubject: (hfs: HfsView, filename: string) => HfsUnitRole | null;
47
+ /** The door a `<name>.<role>.spec.ts` of a feature kind tests, or null: `payment.webhook.spec.ts` gives `payment.webhook.ts`. */
48
+ export declare const doorOfSpec: (hfs: HfsView, filename: string) => string | null;
@@ -9,14 +9,11 @@
9
9
  * (`<provider>.webhook.spec.ts`, `<channel>.gateway.spec.ts`, `<channel>.subscription.spec.ts` beside its door, in the kind's slot);
10
10
  * the quality rules of R48 judge the service specs.
11
11
  */
12
- import { basename } from "node:path"
13
-
12
+ import { basename } from "node:path";
14
13
  /** The slots whose `*.spec.ts` files are not unit specs: the other test kinds and world infrastructure. */
15
- const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit"])
16
-
14
+ const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit"]);
17
15
  /** The file name of a linted path. */
18
- export const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"))
19
-
16
+ export const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"));
20
17
  /**
21
18
  * Whether a file is a unit spec.
22
19
  *
@@ -25,34 +22,29 @@ export const baseOf = (filename) => basename(String(filename || "").replace(/\\/
25
22
  * @returns {boolean} True for a `*.spec.ts` that is not a spec of another test kind.
26
23
  */
27
24
  export const isUnitSpecFile = (hfs, filename) => {
28
- if (!/\.spec\.[cm]?ts$/.test(baseOf(filename))) return false
29
- const found = hfs.classify(filename)
30
- return !OTHER_KIND_SLOTS.has(found.slot ?? "") && !OTHER_KIND_SLOTS.has(found.nearest?.slot ?? "")
31
- }
32
-
25
+ if (!/\.spec\.[cm]?ts$/.test(baseOf(filename)))
26
+ return false;
27
+ const found = hfs.classify(filename);
28
+ return !OTHER_KIND_SLOTS.has(found.slot ?? "") && !OTHER_KIND_SLOTS.has(found.nearest?.slot ?? "");
29
+ };
33
30
  /** Whether a file is a `<name>.service.spec.ts` unit spec. */
34
- export const isServiceSpecFile = (hfs, filename) => /\.service\.spec\.ts$/.test(baseOf(filename)) && isUnitSpecFile(hfs, filename)
35
-
31
+ export const isServiceSpecFile = (hfs, filename) => /\.service\.spec\.ts$/.test(baseOf(filename)) && isUnitSpecFile(hfs, filename);
36
32
  /**
37
33
  * The unit-tested roles of the back end: `ruleParams.be.unitRoles` of the slot manifest, the ONE list (`[{ role, spec, slot? }]`).
38
34
  *
39
35
  * @param {object} hfs - The HFS view.
40
36
  * @returns {ReadonlyArray<{ role: string, spec: string, slot?: string }>} The roles.
41
37
  */
42
- export const unitRoles = (hfs) => hfs.ruleParams.unitRoles ?? []
43
-
38
+ export const unitRoles = (hfs) => hfs.ruleParams.unitRoles ?? [];
44
39
  /** Whether the slot that owns a file is measured at 100 per file (`coverage: required`): the home of the optional specs of the logic roles. */
45
40
  const inCoverageSlot = (hfs, filename) => {
46
- const slot = hfs.slotOf(filename)
47
- return slot !== null && hfs.slot(slot)?.coverage === "required"
48
- }
49
-
41
+ const slot = hfs.slotOf(filename);
42
+ return slot !== null && hfs.slot(slot)?.coverage === "required";
43
+ };
50
44
  /** The roles whose spec is legal but not required: every logic role that is not a spec-required unit role. */
51
- const optionalRoles = (hfs) => (hfs.ruleParams.logicRoles ?? []).filter((role) => !unitRoles(hfs).some((unit) => unit.role === role)).map((role) => ({ role, spec: `${role}.spec`, optional: true }))
52
-
45
+ const optionalRoles = (hfs) => (hfs.ruleParams.logicRoles ?? []).filter((role) => !unitRoles(hfs).some((unit) => unit.role === role)).map((role) => ({ role, spec: `${role}.spec`, optional: true }));
53
46
  /** Whether a role admits a file by its slot (a role with no slot admits any slot; an optional logic role only a coverage-required slot). */
54
- const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverageSlot(hfs, filename) : role.slot === undefined || hfs.slotOf(filename) === role.slot)
55
-
47
+ const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverageSlot(hfs, filename) : role.slot === undefined || hfs.slotOf(filename) === role.slot);
56
48
  /**
57
49
  * The unit-tested role whose spec a file is (`<name>.<role>.spec.ts`, in the role's slot), or null.
58
50
  *
@@ -61,17 +53,16 @@ const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverage
61
53
  * @returns {object | null} The role entry.
62
54
  */
63
55
  export const unitRoleOfSpec = (hfs, filename) => {
64
- if (!isUnitSpecFile(hfs, filename)) return null
65
- const name = baseOf(filename)
66
- return [...unitRoles(hfs), ...optionalRoles(hfs)].find((role) => name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null
67
- }
68
-
56
+ if (!isUnitSpecFile(hfs, filename))
57
+ return null;
58
+ const name = baseOf(filename);
59
+ return [...unitRoles(hfs), ...optionalRoles(hfs)].find((role) => name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null;
60
+ };
69
61
  /** Whether a file is the spec of a value role (`ruleParams.be.valueRoles`: a zod schema): its subject is a declared value, so the spec parses it and builds no testing module. */
70
62
  export const isValueRoleSpec = (hfs, filename) => {
71
- const role = unitRoleOfSpec(hfs, filename)?.role
72
- return role !== undefined && (hfs.ruleParams.valueRoles ?? []).includes(role)
73
- }
74
-
63
+ const role = unitRoleOfSpec(hfs, filename)?.role;
64
+ return role !== undefined && (hfs.ruleParams.valueRoles ?? []).includes(role);
65
+ };
75
66
  /**
76
67
  * The unit-tested role whose subject a file is (`<name>.<role>.ts`, in the role's slot, outside the test tree), or null.
77
68
  *
@@ -80,18 +71,18 @@ export const isValueRoleSpec = (hfs, filename) => {
80
71
  * @returns {object | null} The role entry.
81
72
  */
82
73
  export const unitRoleOfSubject = (hfs, filename) => {
83
- const name = baseOf(filename)
84
- const slot = hfs.slotOf(filename)
85
- if (!slot || slot.startsWith("be.tests.")) return null
86
- return unitRoles(hfs).find((role) => name.endsWith(`.${role.role}.ts`) && !name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null
87
- }
88
-
74
+ const name = baseOf(filename);
75
+ const slot = hfs.slotOf(filename);
76
+ if (!slot || slot.startsWith("be.tests."))
77
+ return null;
78
+ return unitRoles(hfs).find((role) => name.endsWith(`.${role.role}.ts`) && !name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null;
79
+ };
89
80
  /** The slots of the feature kinds whose door carries its own unit spec beside it. */
90
- const DOOR_SPEC_SLOTS = new Set(["be.feature.webhooks.http", "be.feature.realtime.graphql", "be.feature.realtime.websocket", "be.feature.realtime.sse"])
91
-
81
+ const DOOR_SPEC_SLOTS = new Set(["be.feature.webhooks.http", "be.feature.realtime.graphql", "be.feature.realtime.websocket", "be.feature.realtime.sse"]);
92
82
  /** The door a `<name>.<role>.spec.ts` of a feature kind tests, or null: `payment.webhook.spec.ts` gives `payment.webhook.ts`. */
93
83
  export const doorOfSpec = (hfs, filename) => {
94
- if (!isUnitSpecFile(hfs, filename) || !DOOR_SPEC_SLOTS.has(hfs.slotOf(filename) ?? "")) return null
95
- const match = /^(.+.(?:webhook|gateway|subscription|controller)).spec.ts$/.exec(baseOf(filename))
96
- return match ? `${match[1]}.ts` : null
97
- }
84
+ if (!isUnitSpecFile(hfs, filename) || !DOOR_SPEC_SLOTS.has(hfs.slotOf(filename) ?? ""))
85
+ return null;
86
+ const match = /^(.+.(?:webhook|gateway|subscription|controller)).spec.ts$/.exec(baseOf(filename));
87
+ return match ? `${match[1]}.ts` : null;
88
+ };
@@ -0,0 +1,4 @@
1
+ import type { Context, Node } from "./rule.js";
2
+ import type { HfsView } from "./hfs.js";
3
+ /** A return names the declared PROVIDER_ACK itself, with identity and ownership resolved by TypeScript/HFS. */
4
+ export declare const isProviderAcknowledgement: (context: Context, hfs: HfsView, expression: Node | null | undefined) => boolean;
@@ -1,87 +1,103 @@
1
1
  /** A provider's only POST body is its own exported, immutable literal acknowledgement. */
2
- import ts from "typescript"
3
- import { aliasTarget } from "./doors.mjs"
4
- import { typed } from "./types.mjs"
5
-
2
+ import ts from "typescript";
3
+ import { aliasTarget } from "./doors.js";
4
+ import { typed } from "./types.js";
6
5
  /** Static wrappers carry a type, never permission to compute the acknowledgement. */
7
6
  const unwrap = (node) => {
8
- while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node))) node = node.expression
9
- return node
10
- }
11
-
7
+ while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node)))
8
+ node = node.expression;
9
+ return node;
10
+ };
12
11
  /** A scalar literal includes JSON null and a signed numeric literal, but no identifier or template. */
12
+ const SCALAR_KEYWORDS = [ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.NullKeyword];
13
+ const SIGNS = [ts.SyntaxKind.PlusToken, ts.SyntaxKind.MinusToken];
13
14
  const scalarLiteral = (node) => {
14
- if (!node) return false
15
- if (ts.isStringLiteral(node) || ts.isNumericLiteral(node)) return true
16
- if ([ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.NullKeyword].includes(node.kind)) return true
17
- return ts.isPrefixUnaryExpression(node) && [ts.SyntaxKind.PlusToken, ts.SyntaxKind.MinusToken].includes(node.operator) && ts.isNumericLiteral(node.operand)
18
- }
19
-
15
+ if (!node)
16
+ return false;
17
+ if (ts.isStringLiteral(node) || ts.isNumericLiteral(node))
18
+ return true;
19
+ if (SCALAR_KEYWORDS.includes(node.kind))
20
+ return true;
21
+ return ts.isPrefixUnaryExpression(node) && SIGNS.includes(node.operator) && ts.isNumericLiteral(node.operand);
22
+ };
20
23
  /** Literal data recursively excludes spreads, computed keys, methods, accessors and input references. */
21
24
  const literalData = (expression) => {
22
- const node = unwrap(expression)
23
- if (scalarLiteral(node)) return true
24
- if (node && ts.isArrayLiteralExpression(node)) return node.elements.every(literalData)
25
- if (!node || !ts.isObjectLiteralExpression(node)) return false
25
+ const node = unwrap(expression);
26
+ if (scalarLiteral(node))
27
+ return true;
28
+ if (node && ts.isArrayLiteralExpression(node))
29
+ return node.elements.every((element) => literalData(element));
30
+ if (!node || !ts.isObjectLiteralExpression(node))
31
+ return false;
26
32
  return node.properties.every((property) => ts.isPropertyAssignment(property)
27
33
  && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name))
28
- && literalData(property.initializer))
29
- }
30
-
34
+ && literalData(property.initializer));
35
+ };
31
36
  /** The declaration has a const assertion anywhere in its static initializer wrappers. */
32
37
  const constAsserted = (expression) => {
33
- let node = expression
38
+ let node = expression;
34
39
  while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node))) {
35
- if (ts.isAsExpression(node) && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const") return true
36
- node = node.expression
40
+ if (ts.isAsExpression(node) && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const")
41
+ return true;
42
+ node = node.expression;
37
43
  }
38
- return false
39
- }
40
-
44
+ return false;
45
+ };
41
46
  /** A readonly literal annotation cannot widen the provider's fixed body to arbitrary data. */
42
47
  const builtinReadonly = (node, services) => {
43
- if (!ts.isTypeReferenceNode(node) || !ts.isIdentifier(node.typeName) || node.typeName.text !== "Readonly" || node.typeArguments?.length !== 1) return false
44
- const symbol = services.checker.getSymbolAtLocation(node.typeName)
45
- return (symbol?.getDeclarations() ?? []).some((declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile()))
46
- }
47
-
48
+ if (!ts.isTypeReferenceNode(node) || !ts.isIdentifier(node.typeName) || node.typeName.text !== "Readonly" || node.typeArguments?.length !== 1)
49
+ return false;
50
+ const symbol = services.checker.getSymbolAtLocation(node.typeName);
51
+ return (symbol?.getDeclarations() ?? []).some((declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile()));
52
+ };
48
53
  /** Readonly's built-in mapped type is trusted; a locally shadowed alias is not. */
49
54
  const readonlyLiteralType = (node, services, readonly = false) => {
50
- if (!node) return false
51
- if (ts.isLiteralTypeNode(node)) return scalarLiteral(node.literal)
52
- if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword) return readonlyLiteralType(node.type, services, true)
53
- if (builtinReadonly(node, services)) return readonlyLiteralType(node.typeArguments[0], services, true)
54
- if (ts.isTupleTypeNode(node)) return readonly && node.elements.every((entry) => readonlyLiteralType(entry, services))
55
- if (!ts.isTypeLiteralNode(node) || node.members.length === 0) return false
55
+ if (!node)
56
+ return false;
57
+ if (ts.isLiteralTypeNode(node))
58
+ return scalarLiteral(node.literal);
59
+ if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword)
60
+ return readonlyLiteralType(node.type, services, true);
61
+ if (builtinReadonly(node, services))
62
+ return readonlyLiteralType(node.typeArguments?.[0], services, true);
63
+ if (ts.isTupleTypeNode(node))
64
+ return readonly && node.elements.every((entry) => readonlyLiteralType(entry, services));
65
+ if (!ts.isTypeLiteralNode(node) || node.members.length === 0)
66
+ return false;
56
67
  return node.members.every((member) => ts.isPropertySignature(member) && !member.questionToken
57
68
  && (readonly || member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword))
58
- && readonlyLiteralType(member.type, services))
59
- }
60
-
69
+ && readonlyLiteralType(member.type, services));
70
+ };
61
71
  /** The actual symbol is exported by the source module, including a separate export declaration. */
62
72
  const exportedByModule = (checker, declaration, symbol) => {
63
- const sourceSymbol = checker.getSymbolAtLocation(declaration.getSourceFile())
64
- if (!sourceSymbol) return false
73
+ const sourceSymbol = checker.getSymbolAtLocation(declaration.getSourceFile());
74
+ if (!sourceSymbol)
75
+ return false;
65
76
  return checker.getExportsOfModule(sourceSymbol).some((entry) => {
66
- const target = entry.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(entry) : entry
67
- return entry.name === "PROVIDER_ACK" && target === symbol
68
- })
69
- }
70
-
77
+ const target = entry.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(entry) : entry;
78
+ return entry.name === "PROVIDER_ACK" && target === symbol;
79
+ });
80
+ };
71
81
  /** A return names the declared PROVIDER_ACK itself, with identity and ownership resolved by TypeScript/HFS. */
72
82
  export const isProviderAcknowledgement = (context, hfs, expression) => {
73
- if (expression?.type !== "Identifier") return false
74
- const symbol = aliasTarget(context, expression)
75
- if (!symbol || symbol.name !== "PROVIDER_ACK") return false
76
- const services = typed(context)
77
- const { checker } = services
78
- const owner = hfs.ownerOf(context.filename)
83
+ if (expression?.type !== "Identifier")
84
+ return false;
85
+ const symbol = aliasTarget(context, expression);
86
+ if (!symbol || symbol.name !== "PROVIDER_ACK")
87
+ return false;
88
+ const services = typed(context);
89
+ const { checker } = services;
90
+ const owner = hfs.ownerOf(context.filename);
79
91
  return (symbol.getDeclarations() ?? []).some((declaration) => {
80
- if (!ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const)) return false
81
- if (owner === null || hfs.ownerOf(declaration.getSourceFile().fileName) !== owner) return false
82
- if (!exportedByModule(checker, declaration, symbol)) return false
83
- const value = unwrap(declaration.initializer)
84
- if (!value || !(ts.isObjectLiteralExpression(value) || ts.isStringLiteral(value)) || !literalData(value)) return false
85
- return constAsserted(declaration.initializer) || readonlyLiteralType(declaration.type, services)
86
- })
87
- }
92
+ if (!ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const))
93
+ return false;
94
+ if (owner === null || hfs.ownerOf(declaration.getSourceFile().fileName) !== owner)
95
+ return false;
96
+ if (!exportedByModule(checker, declaration, symbol))
97
+ return false;
98
+ const value = unwrap(declaration.initializer);
99
+ if (!value || !(ts.isObjectLiteralExpression(value) || ts.isStringLiteral(value)) || !literalData(value))
100
+ return false;
101
+ return constAsserted(declaration.initializer) || readonlyLiteralType(declaration.type, services);
102
+ });
103
+ };
@@ -0,0 +1,3 @@
1
+ import type { RuleModule } from "./rule.js";
2
+ /** A public service intake with a delivery key claims that same key first and refuses replays. */
3
+ export declare const webhookInboxKey: RuleModule;