@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,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;