@starci/eslint-canon-be 3.5.0 → 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.
- package/CHANGELOG.md +15 -0
- package/README.md +11 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +17 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +17 -10
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- 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)))
|
|
29
|
-
|
|
30
|
-
|
|
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))
|
|
65
|
-
|
|
66
|
-
|
|
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."))
|
|
86
|
-
|
|
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) ?? ""))
|
|
95
|
-
|
|
96
|
-
|
|
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.
|
|
4
|
-
import { typed } from "./types.
|
|
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)))
|
|
9
|
-
|
|
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)
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
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))
|
|
24
|
-
|
|
25
|
-
if (
|
|
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")
|
|
36
|
-
|
|
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)
|
|
44
|
-
|
|
45
|
-
|
|
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)
|
|
51
|
-
|
|
52
|
-
if (ts.
|
|
53
|
-
|
|
54
|
-
if (ts.
|
|
55
|
-
|
|
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)
|
|
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")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
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))
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
if (!
|
|
85
|
-
|
|
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
|
+
};
|