@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,15 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** Every property of an input class carries the validators its type calls for. */
|
|
3
|
+
export declare const inputBounded: RuleModule;
|
|
4
|
+
/** Reads are paged by cursor: no `skip`, `offset`, `OFFSET` or page number anywhere. */
|
|
5
|
+
export declare const noOffsetPagination: RuleModule;
|
|
6
|
+
/** A door opened for a handshake or a webhook is on the strict rate-limit tier. */
|
|
7
|
+
export declare const authDoorStrictRateTier: RuleModule;
|
|
8
|
+
/** The rules this law contributes to the plugin. */
|
|
9
|
+
export declare const rules: {
|
|
10
|
+
"input-bounded": RuleModule;
|
|
11
|
+
"no-offset-pagination": RuleModule;
|
|
12
|
+
"auth-door-strict-rate-tier": RuleModule;
|
|
13
|
+
};
|
|
14
|
+
/** All start at error: no baseline exists, and the repositories' fix lanes clear the debt. */
|
|
15
|
+
export declare const recommended: Recommended;
|
|
@@ -16,55 +16,57 @@
|
|
|
16
16
|
* argument is `RateTier.Strict` of `platform/http-security`, on the method or on its class. A sign-in, sign-up,
|
|
17
17
|
* password-reset or callback door on the default tier is the brute-force path the strict tier exists for.
|
|
18
18
|
*/
|
|
19
|
-
import { isTransportSlot } from "./lib/transport-slots.
|
|
20
|
-
import ts from "typescript"
|
|
21
|
-
import { decoratorName, keyName, staticText } from "./lib/ast.
|
|
22
|
-
import { importsFrom, isOwnedEnumMember, partsOf, presentParts, typeOf } from "./lib/declared.
|
|
23
|
-
import { hfsOf } from "./lib/hfs.
|
|
24
|
-
import { normalizePath } from "./lib/path.
|
|
25
|
-
import { isPackageType, typed } from "./lib/types.
|
|
26
|
-
|
|
19
|
+
import { isTransportSlot } from "./lib/transport-slots.js";
|
|
20
|
+
import ts from "typescript";
|
|
21
|
+
import { decoratorName, keyName, staticText } from "./lib/ast.js";
|
|
22
|
+
import { importsFrom, isOwnedEnumMember, partsOf, presentParts, typeOf } from "./lib/declared.js";
|
|
23
|
+
import { hfsOf } from "./lib/hfs.js";
|
|
24
|
+
import { normalizePath } from "./lib/path.js";
|
|
25
|
+
import { isPackageType, typed } from "./lib/types.js";
|
|
27
26
|
/** True when the file sits in a transport slot inside a `dto/` folder, judged by the slot and the owner-relative path. */
|
|
28
27
|
const isTransportDto = (hfs, filename) => {
|
|
29
|
-
const slot = hfs.slotOf(filename) ?? ""
|
|
30
|
-
if (!isTransportSlot(slot) && !slot.startsWith("be.feature.transport."))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const INPUT_FILE = /\.(?:input|args|request)\.ts
|
|
35
|
-
const INPUT_DECORATORS = new Set(["InputType", "ArgsType"])
|
|
36
|
-
|
|
37
|
-
const decoratorsOf = (node) => node.decorators ?? []
|
|
38
|
-
|
|
28
|
+
const slot = hfs.slotOf(filename) ?? "";
|
|
29
|
+
if (!isTransportSlot(slot) && !slot.startsWith("be.feature.transport."))
|
|
30
|
+
return false;
|
|
31
|
+
return hfs.relative(filename).split("/").slice(0, -1).includes("dto");
|
|
32
|
+
};
|
|
33
|
+
const INPUT_FILE = /\.(?:input|args|request)\.ts$/;
|
|
34
|
+
const INPUT_DECORATORS = new Set(["InputType", "ArgsType"]);
|
|
35
|
+
const decoratorsOf = (node) => ("decorators" in node ? node.decorators ?? [] : []);
|
|
39
36
|
/** The imported names of the decorators a member carries, mapped through the file's `class-validator`/`class-transformer` imports. */
|
|
40
37
|
const boundsOf = (member, validators, transformers) => {
|
|
41
|
-
const names = new Set()
|
|
38
|
+
const names = new Set();
|
|
42
39
|
for (const decorator of decoratorsOf(member)) {
|
|
43
|
-
const local = decoratorName(decorator)
|
|
44
|
-
if (local === null)
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const local = decoratorName(decorator);
|
|
41
|
+
if (local === null)
|
|
42
|
+
continue;
|
|
43
|
+
const validator = validators.get(local);
|
|
44
|
+
if (validator !== undefined)
|
|
45
|
+
names.add(validator);
|
|
46
|
+
if (transformers.has(local))
|
|
47
|
+
names.add(`transform:${transformers.get(local)}`);
|
|
47
48
|
}
|
|
48
|
-
return names
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const NOT_NESTED = new Set(["Date", "Array", "ReadonlyArray", "Map", "Set", "Buffer", "Promise"])
|
|
53
|
-
|
|
49
|
+
return names;
|
|
50
|
+
};
|
|
51
|
+
const STRINGY = ts.TypeFlags.String | ts.TypeFlags.StringLiteral | ts.TypeFlags.TemplateLiteral;
|
|
52
|
+
const NOT_NESTED = new Set(["Date", "Array", "ReadonlyArray", "Map", "Set", "Buffer", "Promise"]);
|
|
54
53
|
/** What a property's type obliges: `enum`, `string`, `array`, `nested` or null for a scalar with no further bound. */
|
|
55
54
|
const obligationOf = (checker, type) => {
|
|
56
|
-
const parts = presentParts(type)
|
|
57
|
-
if (parts.length === 0)
|
|
58
|
-
|
|
59
|
-
if (parts.every((part) => part.flags &
|
|
60
|
-
|
|
61
|
-
if (parts.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const parts = presentParts(type);
|
|
56
|
+
if (parts.length === 0)
|
|
57
|
+
return null;
|
|
58
|
+
if (parts.every((part) => part.flags & ts.TypeFlags.EnumLike))
|
|
59
|
+
return "enum";
|
|
60
|
+
if (parts.every((part) => part.flags & STRINGY))
|
|
61
|
+
return "string";
|
|
62
|
+
if (parts.some((part) => (checker.isArrayType?.(part) ?? false) || part.getSymbol()?.name === "Array" || part.getSymbol()?.name === "ReadonlyArray"))
|
|
63
|
+
return "array";
|
|
64
|
+
if (parts.some((part) => part.flags & ts.TypeFlags.Object && !NOT_NESTED.has(part.getSymbol()?.name ?? "") && part.getCallSignatures().length === 0))
|
|
65
|
+
return "nested";
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
65
68
|
/** True when a string-typed property can only hold a fixed set of literals (`"paid" | "failed"`): a membership validator bounds it as `@MaxLength` does. */
|
|
66
|
-
const isLiteralSet = (type) => presentParts(type).every((part) => part.flags & ts.TypeFlags.StringLiteral)
|
|
67
|
-
|
|
69
|
+
const isLiteralSet = (type) => presentParts(type).every((part) => part.flags & ts.TypeFlags.StringLiteral);
|
|
68
70
|
/** Every property of an input class carries the validators its type calls for. */
|
|
69
71
|
export const inputBounded = {
|
|
70
72
|
meta: {
|
|
@@ -72,8 +74,7 @@ export const inputBounded = {
|
|
|
72
74
|
docs: { description: "Every property of an input class is validated and bounded by its type." },
|
|
73
75
|
schema: [],
|
|
74
76
|
messages: {
|
|
75
|
-
missing:
|
|
76
|
-
"`{{name}}` has no `class-validator` decorator, so the wire may deliver any value here. Add the validators the field needs (`@IsString() @MaxLength(n)`, `@IsInt() @Min(0) @Max(n)`, `@IsEnum(E)`, `@IsArray() @ArrayMaxSize(n)`, `@IsOptional()` for a nullable field).",
|
|
77
|
+
missing: "`{{name}}` has no `class-validator` decorator, so the wire may deliver any value here. Add the validators the field needs (`@IsString() @MaxLength(n)`, `@IsInt() @Min(0) @Max(n)`, `@IsEnum(E)`, `@IsArray() @ArrayMaxSize(n)`, `@IsOptional()` for a nullable field).",
|
|
77
78
|
string: "`{{name}}` is a `string` with no `@MaxLength(n)`, so a string of any length is accepted. Bound it with `@MaxLength`.",
|
|
78
79
|
enum: "`{{name}}` is enum-typed with no `@IsEnum(...)`, so any string is accepted. Add `@IsEnum(TheEnum)`.",
|
|
79
80
|
array: "`{{name}}` is an array with no `@ArrayMaxSize(n)`, so an array of any count is accepted. Bound it with `@ArrayMaxSize`.",
|
|
@@ -81,50 +82,54 @@ export const inputBounded = {
|
|
|
81
82
|
},
|
|
82
83
|
},
|
|
83
84
|
create(context) {
|
|
84
|
-
const hfs = hfsOf(context)
|
|
85
|
-
const filename = normalizePath(context.filename)
|
|
86
|
-
const sourceCode = context.sourceCode
|
|
87
|
-
const { checker } = typed(context)
|
|
88
|
-
const fileIsInput = isTransportDto(hfs, filename) && INPUT_FILE.test(filename)
|
|
89
|
-
let validators = new Map()
|
|
90
|
-
let transformers = new Map()
|
|
85
|
+
const hfs = hfsOf(context);
|
|
86
|
+
const filename = normalizePath(context.filename);
|
|
87
|
+
const sourceCode = context.sourceCode;
|
|
88
|
+
const { checker } = typed(context);
|
|
89
|
+
const fileIsInput = isTransportDto(hfs, filename) && INPUT_FILE.test(filename);
|
|
90
|
+
let validators = new Map();
|
|
91
|
+
let transformers = new Map();
|
|
91
92
|
const checkClass = (node) => {
|
|
92
|
-
const target = node.parent?.type === "ExportNamedDeclaration" || node.parent?.type === "ExportDefaultDeclaration" ? node.parent : node
|
|
93
|
-
const decorated = [...decoratorsOf(node), ...decoratorsOf(target)].map(decoratorName).some((name) => INPUT_DECORATORS.has(name))
|
|
94
|
-
if (!fileIsInput && !decorated)
|
|
93
|
+
const target = node.parent?.type === "ExportNamedDeclaration" || node.parent?.type === "ExportDefaultDeclaration" ? node.parent : node;
|
|
94
|
+
const decorated = [...decoratorsOf(node), ...decoratorsOf(target)].map(decoratorName).some((name) => INPUT_DECORATORS.has(name));
|
|
95
|
+
if (!fileIsInput && !decorated)
|
|
96
|
+
return;
|
|
95
97
|
for (const member of node.body.body) {
|
|
96
|
-
if (member.type !== "PropertyDefinition" || member.static || member.computed || member.key.type !== "Identifier")
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
const
|
|
98
|
+
if (member.type !== "PropertyDefinition" || member.static || member.computed || member.key.type !== "Identifier")
|
|
99
|
+
continue;
|
|
100
|
+
const name = sourceCode.getText(member.key);
|
|
101
|
+
const have = boundsOf(member, validators, transformers);
|
|
102
|
+
const validated = [...have].some((entry) => !entry.startsWith("transform:"));
|
|
100
103
|
if (!validated) {
|
|
101
|
-
context.report({ node: member.key, messageId: "missing", data: { name } })
|
|
102
|
-
continue
|
|
104
|
+
context.report({ node: member.key, messageId: "missing", data: { name } });
|
|
105
|
+
continue;
|
|
103
106
|
}
|
|
104
|
-
const obligation = obligationOf(checker, typeOf(context, member))
|
|
105
|
-
const memberType = typeOf(context, member)
|
|
106
|
-
const boundedByMembership = obligation === "string" && isLiteralSet(memberType) && (have.has("IsIn") || have.has("Equals"))
|
|
107
|
-
if (obligation === "string" && !have.has("MaxLength") && !boundedByMembership)
|
|
108
|
-
|
|
109
|
-
else if (obligation === "
|
|
110
|
-
|
|
107
|
+
const obligation = obligationOf(checker, typeOf(context, member));
|
|
108
|
+
const memberType = typeOf(context, member);
|
|
109
|
+
const boundedByMembership = obligation === "string" && isLiteralSet(memberType) && (have.has("IsIn") || have.has("Equals"));
|
|
110
|
+
if (obligation === "string" && !have.has("MaxLength") && !boundedByMembership)
|
|
111
|
+
context.report({ node: member.key, messageId: "string", data: { name } });
|
|
112
|
+
else if (obligation === "enum" && !have.has("IsEnum"))
|
|
113
|
+
context.report({ node: member.key, messageId: "enum", data: { name } });
|
|
114
|
+
else if (obligation === "array" && !have.has("ArrayMaxSize"))
|
|
115
|
+
context.report({ node: member.key, messageId: "array", data: { name } });
|
|
116
|
+
else if (obligation === "nested" && !(have.has("ValidateNested") && have.has("transform:Type")))
|
|
117
|
+
context.report({ node: member.key, messageId: "nested", data: { name } });
|
|
111
118
|
}
|
|
112
|
-
}
|
|
119
|
+
};
|
|
113
120
|
return {
|
|
114
121
|
Program(node) {
|
|
115
|
-
validators = importsFrom(node, (source) => source === "class-validator")
|
|
116
|
-
transformers = importsFrom(node, (source) => source === "class-transformer")
|
|
122
|
+
validators = importsFrom(node, (source) => source === "class-validator");
|
|
123
|
+
transformers = importsFrom(node, (source) => source === "class-transformer");
|
|
117
124
|
},
|
|
118
125
|
ClassDeclaration: checkClass,
|
|
119
126
|
ClassExpression: checkClass,
|
|
120
|
-
}
|
|
127
|
+
};
|
|
121
128
|
},
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const OFFSET_KEYWORD = /\bOFFSET\b/i
|
|
127
|
-
|
|
129
|
+
};
|
|
130
|
+
const PAGE_PROPERTIES = new Set(["page", "pageNumber", "offset"]);
|
|
131
|
+
const OFFSET_KEYS = new Set(["skip", "offset"]);
|
|
132
|
+
const OFFSET_KEYWORD = /\bOFFSET\b/i;
|
|
128
133
|
/** Reads are paged by cursor: no `skip`, `offset`, `OFFSET` or page number anywhere. */
|
|
129
134
|
export const noOffsetPagination = {
|
|
130
135
|
meta: {
|
|
@@ -138,63 +143,68 @@ export const noOffsetPagination = {
|
|
|
138
143
|
},
|
|
139
144
|
},
|
|
140
145
|
create(context) {
|
|
141
|
-
const hfs = hfsOf(context)
|
|
142
|
-
const filename = normalizePath(context.filename)
|
|
143
|
-
const { checker } = typed(context)
|
|
144
|
-
const inDto = isTransportDto(hfs, filename)
|
|
146
|
+
const hfs = hfsOf(context);
|
|
147
|
+
const filename = normalizePath(context.filename);
|
|
148
|
+
const { checker } = typed(context);
|
|
149
|
+
const inDto = isTransportDto(hfs, filename);
|
|
145
150
|
return {
|
|
146
151
|
CallExpression(node) {
|
|
147
|
-
const callee = node.callee
|
|
148
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
const callee = node.callee;
|
|
153
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
154
|
+
return;
|
|
155
|
+
const method = callee.property.name;
|
|
156
|
+
if (!isPackageType(context, callee.object, "EntityManager", "typeorm"))
|
|
157
|
+
return;
|
|
151
158
|
if (method === "query") {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
const first = node.arguments[0];
|
|
160
|
+
const text = staticText(first);
|
|
161
|
+
if (first && text !== null && OFFSET_KEYWORD.test(text))
|
|
162
|
+
context.report({ node: first, messageId: "sql" });
|
|
163
|
+
return;
|
|
155
164
|
}
|
|
156
|
-
if (!method.startsWith("find"))
|
|
165
|
+
if (!method.startsWith("find"))
|
|
166
|
+
return;
|
|
157
167
|
for (const argument of node.arguments) {
|
|
158
|
-
const type = typeOf(context, argument)
|
|
159
|
-
if (!type)
|
|
168
|
+
const type = typeOf(context, argument);
|
|
169
|
+
if (!type)
|
|
170
|
+
continue;
|
|
160
171
|
for (const property of checker.getPropertiesOfType(type)) {
|
|
161
|
-
if (!OFFSET_KEYS.has(property.name))
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
if (!OFFSET_KEYS.has(property.name))
|
|
173
|
+
continue;
|
|
174
|
+
const literal = argument.type === "ObjectExpression" ? argument.properties.find((item) => item.type === "Property" && keyName(item.key) === property.name) : null;
|
|
175
|
+
context.report({ node: literal ?? argument, messageId: "option", data: { key: property.name } });
|
|
164
176
|
}
|
|
165
177
|
}
|
|
166
178
|
},
|
|
167
179
|
TaggedTemplateExpression(node) {
|
|
168
|
-
const tag = node.tag
|
|
169
|
-
const isSql = (tag.type === "Identifier" && tag.name === "sql") || (tag.type === "MemberExpression" && !tag.computed && keyName(tag.property) === "sql")
|
|
170
|
-
if (isSql && node.quasi.quasis.some((quasi) => OFFSET_KEYWORD.test(quasi.value.cooked ?? "")))
|
|
180
|
+
const tag = node.tag;
|
|
181
|
+
const isSql = (tag.type === "Identifier" && tag.name === "sql") || (tag.type === "MemberExpression" && !tag.computed && keyName(tag.property) === "sql");
|
|
182
|
+
if (isSql && node.quasi.quasis.some((quasi) => OFFSET_KEYWORD.test(quasi.value.cooked ?? "")))
|
|
183
|
+
context.report({ node: node.quasi, messageId: "sql" });
|
|
171
184
|
},
|
|
172
185
|
PropertyDefinition(node) {
|
|
173
|
-
if (!inDto || node.static || node.computed || node.key.type !== "Identifier")
|
|
174
|
-
|
|
186
|
+
if (!inDto || node.static || node.computed || node.key.type !== "Identifier")
|
|
187
|
+
return;
|
|
188
|
+
if (PAGE_PROPERTIES.has(node.key.name))
|
|
189
|
+
context.report({ node: node.key, messageId: "field", data: { name: node.key.name } });
|
|
175
190
|
},
|
|
176
|
-
}
|
|
191
|
+
};
|
|
177
192
|
},
|
|
178
|
-
}
|
|
179
|
-
|
|
193
|
+
};
|
|
180
194
|
/** The `PublicReason` members whose doors are the brute-force and forgery paths: they owe the strict tier. */
|
|
181
|
-
const STRICT_REASONS = new Set(["AuthHandshake", "SignedWebhook"])
|
|
182
|
-
|
|
195
|
+
const STRICT_REASONS = new Set(["AuthHandshake", "SignedWebhook"]);
|
|
183
196
|
/** The member names of an enum-typed value, when every part of its type is a member of the owned enum; else []. */
|
|
184
|
-
const ownedMembers = (context, node, enumName, tier, capability) =>
|
|
185
|
-
isOwnedEnumMember(context, node, enumName, tier, capability) ? partsOf(typeOf(context, node)).map((part) => part.getSymbol()?.name ?? "") : []
|
|
186
|
-
|
|
197
|
+
const ownedMembers = (context, node, enumName, tier, capability) => isOwnedEnumMember(context, node, enumName, tier, capability) ? partsOf(typeOf(context, node)).map((part) => part.getSymbol()?.name ?? "") : [];
|
|
187
198
|
/** The arguments of a decorator call (`@X(a, b)`), or [] for a bare `@X`. */
|
|
188
|
-
const argumentsOf = (decorator) => (decorator.expression.type === "CallExpression" ? decorator.expression.arguments : [])
|
|
189
|
-
|
|
199
|
+
const argumentsOf = (decorator) => (decorator.expression.type === "CallExpression" ? decorator.expression.arguments : []);
|
|
190
200
|
/** The `reason` value of an opening decorator's options object (`@Public({ reason })`), or null. */
|
|
191
201
|
const reasonOf = (decorator) => {
|
|
192
|
-
const options = argumentsOf(decorator)[0]
|
|
193
|
-
if (options?.type !== "ObjectExpression")
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
202
|
+
const options = argumentsOf(decorator)[0];
|
|
203
|
+
if (options?.type !== "ObjectExpression")
|
|
204
|
+
return null;
|
|
205
|
+
const property = options.properties.find((item) => item.type === "Property" && !item.computed && keyName(item.key) === "reason");
|
|
206
|
+
return property ? property.value : null;
|
|
207
|
+
};
|
|
198
208
|
/** A door opened for a handshake or a webhook is on the strict rate-limit tier. */
|
|
199
209
|
export const authDoorStrictRateTier = {
|
|
200
210
|
meta: {
|
|
@@ -207,41 +217,42 @@ export const authDoorStrictRateTier = {
|
|
|
207
217
|
},
|
|
208
218
|
create(context) {
|
|
209
219
|
const isStrict = (decorator) => argumentsOf(decorator).some((argument) => {
|
|
210
|
-
const members = ownedMembers(context, argument, "RateTier", "platform", "http-security")
|
|
211
|
-
return members.length > 0 && members.every((name) => name === "Strict")
|
|
212
|
-
})
|
|
220
|
+
const members = ownedMembers(context, argument, "RateTier", "platform", "http-security");
|
|
221
|
+
return members.length > 0 && members.every((name) => name === "Strict");
|
|
222
|
+
});
|
|
213
223
|
const judge = (target, enclosing) => {
|
|
214
224
|
for (const decorator of target.decorators ?? []) {
|
|
215
|
-
const reason = reasonOf(decorator)
|
|
216
|
-
if (reason === null)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
|
|
225
|
+
const reason = reasonOf(decorator);
|
|
226
|
+
if (reason === null)
|
|
227
|
+
continue;
|
|
228
|
+
const opened = ownedMembers(context, reason, "PublicReason", "domain", "identity").find((name) => STRICT_REASONS.has(name));
|
|
229
|
+
if (opened === undefined)
|
|
230
|
+
continue;
|
|
231
|
+
if ([...(target.decorators ?? []), ...(enclosing?.decorators ?? [])].some(isStrict))
|
|
232
|
+
continue;
|
|
233
|
+
context.report({ node: decorator, messageId: "strict", data: { reason: opened } });
|
|
221
234
|
}
|
|
222
|
-
}
|
|
235
|
+
};
|
|
223
236
|
return {
|
|
224
237
|
ClassDeclaration(node) {
|
|
225
|
-
judge(node, null)
|
|
238
|
+
judge(node, null);
|
|
226
239
|
},
|
|
227
240
|
MethodDefinition(node) {
|
|
228
|
-
const owner = node.parent?.parent
|
|
229
|
-
judge(node, owner?.type === "ClassDeclaration" || owner?.type === "ClassExpression" ? owner : null)
|
|
241
|
+
const owner = node.parent?.parent;
|
|
242
|
+
judge(node, owner?.type === "ClassDeclaration" || owner?.type === "ClassExpression" ? owner : null);
|
|
230
243
|
},
|
|
231
|
-
}
|
|
244
|
+
};
|
|
232
245
|
},
|
|
233
|
-
}
|
|
234
|
-
|
|
246
|
+
};
|
|
235
247
|
/** The rules this law contributes to the plugin. */
|
|
236
248
|
export const rules = {
|
|
237
249
|
"input-bounded": inputBounded,
|
|
238
250
|
"no-offset-pagination": noOffsetPagination,
|
|
239
251
|
"auth-door-strict-rate-tier": authDoorStrictRateTier,
|
|
240
|
-
}
|
|
241
|
-
|
|
252
|
+
};
|
|
242
253
|
/** All start at error: no baseline exists, and the repositories' fix lanes clear the debt. */
|
|
243
254
|
export const recommended = {
|
|
244
255
|
"starci-be/input-bounded": "error",
|
|
245
256
|
"starci-be/no-offset-pagination": "error",
|
|
246
257
|
"starci-be/auth-door-strict-rate-tier": "error",
|
|
247
|
-
}
|
|
258
|
+
};
|
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** A write to an entity that `platform/jobs` declares (the job row) is made only by `platform/jobs`. */
|
|
3
|
+
export declare const jobWriteOwner: RuleModule;
|
|
4
|
+
/** Calls on the `JobClaims` port, and what a guarded write is: required token, no cast to get around it, and `JobFencedOut` is not swallowed. */
|
|
5
|
+
export declare const jobFenceRequired: RuleModule;
|
|
6
|
+
/** The class of an external effect of a step passes the key `JobClaims.runKey` made. */
|
|
7
|
+
export declare const jobRunKey: RuleModule;
|
|
8
|
+
/** A processor extends the fenced base and is named after its job; a step implements `JobStep` in `steps/`. */
|
|
9
|
+
export declare const jobShape: RuleModule;
|
|
10
|
+
export declare const rules: {
|
|
11
|
+
"job-write-owner": RuleModule;
|
|
12
|
+
"job-fence-required": RuleModule;
|
|
13
|
+
"job-run-key": RuleModule;
|
|
14
|
+
"job-shape": RuleModule;
|
|
15
|
+
};
|
|
16
|
+
/** The level these laws ask for: `error`, switched off nowhere. */
|
|
17
|
+
export declare const recommended: Recommended;
|