@ddd-ts-kit/eslint-plugin 0.16.0 → 0.16.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.
- package/README.fr.md +464 -0
- package/README.md +148 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/rules/application-command-query-separation.fr.md +57 -0
- package/docs/rules/application-command-query-separation.md +2 -0
- package/docs/rules/application-handler-shape.fr.md +55 -0
- package/docs/rules/application-handler-shape.md +2 -0
- package/docs/rules/aspects-outside-in.fr.md +57 -0
- package/docs/rules/aspects-outside-in.md +2 -0
- package/docs/rules/authz-actor-explicit.fr.md +73 -0
- package/docs/rules/authz-actor-explicit.md +2 -0
- package/docs/rules/authz-declared.fr.md +90 -0
- package/docs/rules/authz-declared.md +2 -0
- package/docs/rules/authz-fields-by-schema.fr.md +54 -0
- package/docs/rules/authz-fields-by-schema.md +2 -0
- package/docs/rules/authz-in-application.fr.md +91 -0
- package/docs/rules/authz-in-application.md +2 -0
- package/docs/rules/clean-blank-lines.fr.md +90 -0
- package/docs/rules/clean-blank-lines.md +2 -0
- package/docs/rules/clean-braces.fr.md +64 -0
- package/docs/rules/clean-braces.md +2 -0
- package/docs/rules/clean-file-size.fr.md +46 -0
- package/docs/rules/clean-file-size.md +2 -0
- package/docs/rules/clean-formatted.fr.md +35 -0
- package/docs/rules/clean-formatted.md +2 -0
- package/docs/rules/clean-function-ceiling.fr.md +56 -0
- package/docs/rules/clean-function-ceiling.md +2 -0
- package/docs/rules/clean-function-size.fr.md +48 -0
- package/docs/rules/clean-function-size.md +2 -0
- package/docs/rules/clean-no-commented-out-code.fr.md +51 -0
- package/docs/rules/clean-no-commented-out-code.md +2 -0
- package/docs/rules/clean-no-escape-hatch.fr.md +83 -0
- package/docs/rules/clean-no-escape-hatch.md +2 -0
- package/docs/rules/clean-no-flag-argument.fr.md +53 -0
- package/docs/rules/clean-no-flag-argument.md +2 -0
- package/docs/rules/clean-no-hash-private.fr.md +66 -0
- package/docs/rules/clean-no-hash-private.md +2 -0
- package/docs/rules/clean-no-magic-number.fr.md +62 -0
- package/docs/rules/clean-no-magic-number.md +2 -0
- package/docs/rules/clean-no-noise-comment.fr.md +58 -0
- package/docs/rules/clean-no-noise-comment.md +2 -0
- package/docs/rules/clean-one-export-per-file.fr.md +91 -0
- package/docs/rules/clean-one-export-per-file.md +2 -0
- package/docs/rules/clean-stepdown.fr.md +63 -0
- package/docs/rules/clean-stepdown.md +2 -0
- package/docs/rules/context-declared-relationship.fr.md +52 -0
- package/docs/rules/context-declared-relationship.md +2 -0
- package/docs/rules/context-extractable.fr.md +112 -0
- package/docs/rules/context-extractable.md +2 -0
- package/docs/rules/context-published-language-is-a-contract.fr.md +50 -0
- package/docs/rules/context-published-language-is-a-contract.md +2 -0
- package/docs/rules/context-published-language-only.fr.md +50 -0
- package/docs/rules/context-published-language-only.md +2 -0
- package/docs/rules/declarations-constructor-injection.fr.md +92 -0
- package/docs/rules/declarations-constructor-injection.md +2 -0
- package/docs/rules/declarations-role-declared.fr.md +118 -0
- package/docs/rules/declarations-role-declared.md +2 -0
- package/docs/rules/domain-aggregate-encapsulation.fr.md +66 -0
- package/docs/rules/domain-aggregate-encapsulation.md +2 -0
- package/docs/rules/domain-events-dispatched-on-save.fr.md +86 -0
- package/docs/rules/domain-events-dispatched-on-save.md +2 -0
- package/docs/rules/domain-events-transactional-before-commit.fr.md +95 -0
- package/docs/rules/domain-events-transactional-before-commit.md +2 -0
- package/docs/rules/domain-no-generic-error.fr.md +43 -0
- package/docs/rules/domain-no-generic-error.md +2 -0
- package/docs/rules/domain-value-object-class.fr.md +177 -0
- package/docs/rules/domain-value-object-class.md +2 -0
- package/docs/rules/domain-value-object-immutability.fr.md +55 -0
- package/docs/rules/domain-value-object-immutability.md +2 -0
- package/docs/rules/errors-constructor-not-public.fr.md +56 -0
- package/docs/rules/errors-constructor-not-public.md +2 -0
- package/docs/rules/errors-factory-name.fr.md +53 -0
- package/docs/rules/errors-factory-name.md +2 -0
- package/docs/rules/errors-through-factory.fr.md +48 -0
- package/docs/rules/errors-through-factory.md +2 -0
- package/docs/rules/event-sourcing-past-tense.fr.md +43 -0
- package/docs/rules/event-sourcing-past-tense.md +2 -0
- package/docs/rules/event-sourcing-projection-never-appends.fr.md +52 -0
- package/docs/rules/event-sourcing-projection-never-appends.md +2 -0
- package/docs/rules/event-sourcing-state-in-apply.fr.md +54 -0
- package/docs/rules/event-sourcing-state-in-apply.md +2 -0
- package/docs/rules/event-sourcing-store-behind-repository.fr.md +42 -0
- package/docs/rules/event-sourcing-store-behind-repository.md +2 -0
- package/docs/rules/event-sourcing-upcaster-required.fr.md +58 -0
- package/docs/rules/event-sourcing-upcaster-required.md +2 -0
- package/docs/rules/events-consumer-idempotent.fr.md +71 -0
- package/docs/rules/events-consumer-idempotent.md +2 -0
- package/docs/rules/events-name-format.fr.md +57 -0
- package/docs/rules/events-name-format.md +2 -0
- package/docs/rules/events-outbox-required.fr.md +60 -0
- package/docs/rules/events-outbox-required.md +2 -0
- package/docs/rules/governance-recorded-deviation.fr.md +58 -0
- package/docs/rules/governance-recorded-deviation.md +2 -0
- package/docs/rules/imports-alias-only.fr.md +77 -0
- package/docs/rules/imports-alias-only.md +2 -0
- package/docs/rules/imports-extension.fr.md +86 -0
- package/docs/rules/imports-extension.md +2 -0
- package/docs/rules/language-declared-vocabulary.fr.md +67 -0
- package/docs/rules/language-declared-vocabulary.md +2 -0
- package/docs/rules/layer-application-inward.fr.md +65 -0
- package/docs/rules/layer-application-inward.md +4 -2
- package/docs/rules/layer-domain-purity.fr.md +63 -0
- package/docs/rules/layer-domain-purity.md +4 -2
- package/docs/rules/layer-infrastructure-no-presentation.fr.md +49 -0
- package/docs/rules/layer-infrastructure-no-presentation.md +2 -0
- package/docs/rules/layer-presentation-no-infrastructure.fr.md +49 -0
- package/docs/rules/layer-presentation-no-infrastructure.md +2 -0
- package/docs/rules/lifecycle-status-through-machine.fr.md +72 -0
- package/docs/rules/lifecycle-status-through-machine.md +2 -0
- package/docs/rules/ports-abstract-class.fr.md +73 -0
- package/docs/rules/ports-abstract-class.md +2 -0
- package/docs/rules/ports-implements-never-extends.fr.md +56 -0
- package/docs/rules/ports-implements-never-extends.md +2 -0
- package/docs/rules/ports-no-concrete-dependency.fr.md +56 -0
- package/docs/rules/ports-no-concrete-dependency.md +2 -0
- package/docs/rules/ports-no-token-constant.fr.md +60 -0
- package/docs/rules/ports-no-token-constant.md +2 -0
- package/docs/rules/ports-value-import.fr.md +58 -0
- package/docs/rules/ports-value-import.md +2 -0
- package/docs/rules/presentation-controller-delegates.fr.md +60 -0
- package/docs/rules/presentation-controller-delegates.md +2 -0
- package/docs/rules/presentation-controller-shape.fr.md +53 -0
- package/docs/rules/presentation-controller-shape.md +2 -0
- package/docs/rules/presentation-guard-at-the-edge.fr.md +58 -0
- package/docs/rules/presentation-guard-at-the-edge.md +2 -0
- package/docs/rules/presentation-shared-cache-varies.fr.md +57 -0
- package/docs/rules/presentation-shared-cache-varies.md +2 -0
- package/docs/rules/process-sends-commands-only.fr.md +67 -0
- package/docs/rules/process-sends-commands-only.md +2 -0
- package/docs/rules/purity-no-ambient-randomness.fr.md +46 -0
- package/docs/rules/purity-no-ambient-randomness.md +2 -0
- package/docs/rules/purity-no-environment.fr.md +48 -0
- package/docs/rules/purity-no-environment.md +2 -0
- package/docs/rules/purity-no-system-clock.fr.md +52 -0
- package/docs/rules/purity-no-system-clock.md +2 -0
- package/docs/rules/scheduling-job-name.fr.md +60 -0
- package/docs/rules/scheduling-job-name.md +2 -0
- package/docs/rules/scheduling-job-triggers-use-case.fr.md +74 -0
- package/docs/rules/scheduling-job-triggers-use-case.md +2 -0
- package/docs/rules/schema-presentation-only.fr.md +48 -0
- package/docs/rules/schema-presentation-only.md +2 -0
- package/docs/rules/standard-no-parallel-interface.fr.md +100 -0
- package/docs/rules/standard-no-parallel-interface.md +2 -0
- package/docs/rules/test-no-mocks.fr.md +50 -0
- package/docs/rules/test-no-mocks.md +2 -0
- package/docs/rules/tracing-platform-only.fr.md +68 -0
- package/docs/rules/tracing-platform-only.md +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
**English** · [Français](README.fr.md)
|
|
2
|
+
|
|
1
3
|
# @ddd-ts-kit/eslint-plugin
|
|
2
4
|
|
|
3
5
|
AST-accurate ESLint rules for the architecture of [docs/ARCHITECTURE.md](../../docs/ARCHITECTURE.md):
|
|
@@ -10,6 +12,8 @@ Every rule reads `ddd-ts-kit.config.json` ([docs/CONFIG.md](../../docs/CONFIG.md
|
|
|
10
12
|
walking up from the linted file, and classifies the file into context and layer exactly like
|
|
11
13
|
`ddd-ts-kit check` does. It also reads `stack.style` there: see [The two styles](#the-two-styles).
|
|
12
14
|
|
|
15
|
+

|
|
16
|
+
|
|
13
17
|
## Install
|
|
14
18
|
|
|
15
19
|
```
|
|
@@ -31,14 +35,15 @@ export default dddTsKit({ tsconfigRootDir: import.meta.dirname });
|
|
|
31
35
|
|
|
32
36
|
| Layer of the config | Content |
|
|
33
37
|
|---|---|
|
|
38
|
+
| `ddd-ts-kit/ignores` | what is never linted: see `ignores` below |
|
|
34
39
|
| `@eslint/js` recommended | the baseline of ESLint |
|
|
35
|
-
| typescript-eslint `strictTypeChecked` and `stylisticTypeChecked` | with `projectService
|
|
40
|
+
| typescript-eslint `strictTypeChecked` and `stylisticTypeChecked` | with `projectService` (`ddd-ts-kit/type-information`), and without type checking on JavaScript files (`ddd-ts-kit/javascript`); `strict` and `stylistic` when `typeChecked` is `false` |
|
|
36
41
|
| `ddd-ts-kit/clean-code` | the standard rules backing section 6 of the architecture reference (below) |
|
|
37
42
|
| `ddd-ts-kit/architecture` | every rule of this plugin, at the severity of `rules.<id>` in `ddd-ts-kit.config.json`, else at its default, the two layout rules of `@stylistic/eslint-plugin` at the severity of `rules."clean/blank-lines"` and `curly` at the severity of `rules."clean/braces"` (default `error`) |
|
|
38
43
|
| `ddd-ts-kit/scripts` | `curly` on `.js`, `.mjs` and `.cjs` files, at the severity of `rules."clean/braces"`: a branch reads the same in a script |
|
|
39
44
|
| `ddd-ts-kit/inner-layers` | `no-param-reassign` with `props` in `domain/` and `application/`: no output argument |
|
|
40
45
|
| `ddd-ts-kit/aggregates` | `prefer-readonly` off in aggregates and entities, whose state is replaced by intention methods |
|
|
41
|
-
| `ddd-ts-kit/tests` | a lighter set
|
|
46
|
+
| `ddd-ts-kit/tests` | a lighter set on `*.spec.ts`, `*.test.ts`, the `test/` directory of each context and the root `test/`: `any` and `!` warn, the `no-unsafe-*` rules off, type assertions allowed |
|
|
42
47
|
|
|
43
48
|
| Option | Default | Meaning |
|
|
44
49
|
|---|---|---|
|
|
@@ -47,9 +52,22 @@ export default dddTsKit({ tsconfigRootDir: import.meta.dirname });
|
|
|
47
52
|
| `allowDefaultProject` | `['*.config.ts', '*.config.mts']` | files outside the tsconfig still linted with types |
|
|
48
53
|
| `ignores` | none | added to `dist`, `coverage`, `node_modules`, `reports`, `*.d.ts`, and `clients/*/src` when `ddd-ts-kit.config.json` has `"sdk"` (the clients the CLI generates) |
|
|
49
54
|
|
|
55
|
+
Blocks are applied in this order, and a later block wins for the files it matches. A block of
|
|
56
|
+
your own goes after the helper:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { dddTsKit } from '@ddd-ts-kit/eslint-plugin';
|
|
60
|
+
|
|
61
|
+
export default [
|
|
62
|
+
...dddTsKit({ tsconfigRootDir: import.meta.dirname, ignores: ['src/generated/**'] }),
|
|
63
|
+
// a rule the kit does not enable: purity/no-environment refuses console in domain/ and application/ only
|
|
64
|
+
{ files: ['src/**/*.ts'], rules: { 'no-console': 'error' } },
|
|
65
|
+
];
|
|
66
|
+
```
|
|
67
|
+
|
|
50
68
|
To compose a config by hand, the plugin is the default export, with two presets that hold only
|
|
51
|
-
its own rules, the three typescript-eslint rules they delegate to
|
|
52
|
-
`@stylistic/eslint-plugin`, without type information:
|
|
69
|
+
its own rules, the three typescript-eslint rules they delegate to, the two layout rules of
|
|
70
|
+
`@stylistic/eslint-plugin` and `curly`, without type information:
|
|
53
71
|
|
|
54
72
|
```js
|
|
55
73
|
import dddTsKit from '@ddd-ts-kit/eslint-plugin';
|
|
@@ -70,6 +88,104 @@ import dddTsKit, { standardRules } from '@ddd-ts-kit/eslint-plugin';
|
|
|
70
88
|
export default [{ files: ['**/*.ts'], plugins: { 'ddd-ts-kit': dddTsKit, '@stylistic': stylistic }, rules: standardRules.layout }];
|
|
71
89
|
```
|
|
72
90
|
|
|
91
|
+
### Changing a severity
|
|
92
|
+
|
|
93
|
+
The severity of a rule of the kit is written once, in `ddd-ts-kit.config.json`, where both
|
|
94
|
+
tools read it:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"rules": {
|
|
99
|
+
"clean/function-size": "error",
|
|
100
|
+
"test/no-mocks": "off"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
// instead of: a severity in eslint.config.mjs, which `ddd-ts-kit check` never sees
|
|
107
|
+
export default [...dddTsKit(), { rules: { 'ddd-ts-kit/test-no-mocks': 'off' } }];
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`"off"` in the config silences the rule even where an ESLint config enables it. Raising a
|
|
111
|
+
severity is free; lowering one under its default (`off`, or `warn` for an `error` rule) is a
|
|
112
|
+
deviation, and `ddd-ts-kit check` asks for its decision record: see
|
|
113
|
+
[Deviations](../../docs/CONFIG.md#deviations).
|
|
114
|
+
|
|
115
|
+
## A report, and what to write instead
|
|
116
|
+
|
|
117
|
+
Every message says what is wrong, what to write instead, and the rule. A handler that reads the
|
|
118
|
+
system clock, in `src/contexts/billing/application/commands/issue-invoice/issue-invoice.handler.ts`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// instead of
|
|
122
|
+
import type { IdGenerator } from '@ddd-ts-kit/kernel';
|
|
123
|
+
import { Invoice } from '@/contexts/billing/domain/aggregates/invoice.aggregate.js';
|
|
124
|
+
import type { InvoiceRepository } from '@/contexts/billing/domain/repositories/invoice.repository.js';
|
|
125
|
+
import type { IssueInvoice } from '@/contexts/billing/application/commands/issue-invoice/issue-invoice.command.js';
|
|
126
|
+
|
|
127
|
+
export class IssueInvoiceHandler {
|
|
128
|
+
constructor(
|
|
129
|
+
private readonly invoices: InvoiceRepository,
|
|
130
|
+
private readonly ids: IdGenerator,
|
|
131
|
+
) {}
|
|
132
|
+
|
|
133
|
+
async execute(command: IssueInvoice): Promise<string> {
|
|
134
|
+
const id = this.ids.next();
|
|
135
|
+
|
|
136
|
+
await this.invoices.save(Invoice.issue(id, command.customerId, new Date()));
|
|
137
|
+
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
is reported, by `npx eslint src`:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
src/contexts/billing/application/commands/issue-invoice/issue-invoice.handler.ts
|
|
147
|
+
16:68 error new Date() without argument is used in the application layer. Receive the instant as a parameter in the domain, and take it from the Clock port (`this.clock.now()`) in a handler, so that a test fixes time with FixedClock ddd-ts-kit/purity-no-system-clock
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The fix the message names: the `Clock` port, which a spec fixes with `FixedClock`.
|
|
151
|
+
|
|
152
|
+
<!-- checked sample -->
|
|
153
|
+
```ts
|
|
154
|
+
import { AuthorizedCommand, Clock, IdGenerator, type Actor } from '@ddd-ts-kit/kernel';
|
|
155
|
+
|
|
156
|
+
// the command, the aggregate and its repository port, in their own files
|
|
157
|
+
declare class IssueInvoice extends AuthorizedCommand<string> {
|
|
158
|
+
readonly customerId: string;
|
|
159
|
+
constructor(actor: Actor, customerId: string);
|
|
160
|
+
}
|
|
161
|
+
declare class Invoice {
|
|
162
|
+
static issue(id: string, customerId: string, issuedAt: Date): Invoice;
|
|
163
|
+
}
|
|
164
|
+
declare abstract class InvoiceRepository {
|
|
165
|
+
abstract save(invoice: Invoice): Promise<void>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// write: the instant comes from a port
|
|
169
|
+
export class IssueInvoiceHandler {
|
|
170
|
+
constructor(
|
|
171
|
+
private readonly invoices: InvoiceRepository,
|
|
172
|
+
private readonly clock: Clock,
|
|
173
|
+
private readonly ids: IdGenerator,
|
|
174
|
+
) {}
|
|
175
|
+
|
|
176
|
+
async execute(command: IssueInvoice): Promise<string> {
|
|
177
|
+
const id = this.ids.next();
|
|
178
|
+
|
|
179
|
+
await this.invoices.save(Invoice.issue(id, command.customerId, this.clock.now()));
|
|
180
|
+
|
|
181
|
+
return id;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
When the code is right and the rule is not, the deviation is recorded, not hidden: see the
|
|
187
|
+
suppression comment in [Settings](#settings).
|
|
188
|
+
|
|
73
189
|
## Rules
|
|
74
190
|
|
|
75
191
|
Ids are those of [docs/ARCHITECTURE.md](../../docs/ARCHITECTURE.md); the ESLint name replaces the
|
|
@@ -227,7 +343,7 @@ is not reported for following the conventions of the kit:
|
|
|
227
343
|
| `no-unnecessary-type-arguments` | off | the id type of an aggregate is part of its declaration |
|
|
228
344
|
| `consistent-type-definitions` | off | props are type aliases, states and options are interfaces |
|
|
229
345
|
| `no-empty-object-type` | interfaces allowed | `interface SessionExtensions {}` is left open for declaration merging |
|
|
230
|
-
| `no-extraneous-class` | empty classes allowed | a domain service or a fake starts empty |
|
|
346
|
+
| `no-extraneous-class` | empty classes and decorated classes allowed | a domain service or a fake starts empty; a class that carries a decorator is a declaration, whatever its body |
|
|
231
347
|
| `no-unused-vars` | `args: 'none'` | an adapter implements the whole signature of its port |
|
|
232
348
|
| `dot-notation` | index signatures allowed | `process.env['PORT']` |
|
|
233
349
|
| `no-confusing-void-expression`, `restrict-template-expressions`, `restrict-plus-operands` | arrow shorthand, numbers and booleans allowed | not coercion bugs |
|
|
@@ -261,16 +377,39 @@ editor after changing `ddd-ts-kit.config.json`.
|
|
|
261
377
|
Two things work as with the CLI checker: `rules.<id>: "off"` in the config silences the rule
|
|
262
378
|
even when the ESLint config enables it, and `// ddd-ts-kit-disable-next-line <id> -- <reason>`
|
|
263
379
|
silences one line for both tools. A suppression without a reason silences nothing, and
|
|
264
|
-
`governance/recorded-deviation` asks that the reason point to a decision record (`ADR-<number>`)
|
|
380
|
+
`governance/recorded-deviation` asks that the reason point to a decision record (`ADR-<number>`):
|
|
381
|
+
|
|
382
|
+
```ts
|
|
383
|
+
// instead of: a reason that points to no decision
|
|
384
|
+
// ddd-ts-kit-disable-next-line clean/no-flag-argument -- kept for now
|
|
385
|
+
cancel(force: boolean): void {
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
12:3 error `ddd-ts-kit-disable-next-line clean/no-flag-argument` on line 12 silences a rule without pointing to a decision. Fix the diagnostic; if the deviation is deliberate, record it with `ddd-ts-kit generate adr` (reason, scope, condition for removing it) and end the comment with `-- ADR-<number>: <reason>` ddd-ts-kit/governance-recorded-deviation
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
// write: the decision record says why, for what scope and until when
|
|
394
|
+
// ddd-ts-kit-disable-next-line clean/no-flag-argument -- ADR-0007: the legacy import sends a flag until 2027
|
|
395
|
+
cancel(force: boolean): void {
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
The id is the one of the architecture reference (`clean/no-flag-argument`), not the ESLint name,
|
|
399
|
+
and `npx ddd-ts-kit generate adr` writes the record. `eslint-disable` comments are held the same
|
|
400
|
+
way, by `clean/no-escape-hatch` and `governance/recorded-deviation`.
|
|
265
401
|
|
|
266
402
|
## With `ddd-ts-kit check`
|
|
267
403
|
|
|
268
|
-
Two tools, one set of ids, no overlap of authority.
|
|
404
|
+
Two tools, one set of ids, no overlap of authority. A third, dependency-cruiser, does not read the
|
|
405
|
+
config: it runs on a file generated from it, with its own rule names.
|
|
406
|
+
|
|
407
|
+

|
|
269
408
|
|
|
270
409
|
| Concern | Authority | Why |
|
|
271
410
|
|---|---|---|
|
|
272
|
-
| imports and boundaries (`layer/*`, `context/published-language-only`, `context/declared-relationship`, `context/published-language-is-a-contract`), `purity/*`, `clean/*`, `test/no-mocks`, `events/name-format`, `domain/*`, `application/*`, the code side of `events/outbox-required`, `events/consumer-idempotent`, `context/extractable`, `authz/*`, `aspects/outside-in`, `tracing/platform-only`, `domain-events/dispatched-on-save`, `domain-events/transactional-before-commit` on a declared class, `event-sourcing/*` (but the lock of `event-sourcing/upcaster-required`), `standard/no-parallel-interface`, `declarations/role-declared`, `ports/*`, `scheduling/*` (but the uniqueness of job names) and `governance/recorded-deviation` | this plugin | it reads the syntax tree: no false positive from a string or a comment, shadowing and arrow functions are understood |
|
|
273
|
-
| the tree (`tree/closed`, `tree/context-doc`), names and files (`naming/*`, `test/spec-required`, `test/builder-required`), the language (`language
|
|
411
|
+
| imports and boundaries (`layer/*`, `context/published-language-only`, `context/declared-relationship`, `context/published-language-is-a-contract`), `purity/*`, `clean/*`, `test/no-mocks`, `events/name-format`, `domain/*`, `application/*`, the code side of `events/outbox-required`, `events/consumer-idempotent`, `context/extractable`, `authz/*`, `aspects/outside-in`, `tracing/platform-only`, `domain-events/dispatched-on-save`, `domain-events/transactional-before-commit` on a declared class, `event-sourcing/*` (but the lock of `event-sourcing/upcaster-required`), `standard/no-parallel-interface`, `declarations/role-declared`, `ports/*`, `scheduling/*` (but the uniqueness of job names), `language/declared-vocabulary`, `errors/through-factory`, `errors/constructor-not-public`, `errors/factory-name`, `presentation/*`, `lifecycle/*`, `process/*`, `schema/presentation-only`, `imports/alias-only`, `imports/extension` and `governance/recorded-deviation` | this plugin | it reads the syntax tree: no false positive from a string or a comment, shadowing and arrow functions are understood |
|
|
412
|
+
| the tree (`tree/closed`, `tree/context-doc`), names and files (`naming/*`, `test/spec-required`, `test/builder-required`), the language (`language/glossary-term`, `language/no-technical-name`), error codes (`errors/code-unique`, `errors/known-code`), `imports/alias-declared`, `schema/no-duplicate-shape`, the config (`config/*`, `context/no-cycle`), `events/defined-in-published-language`, `composition/only-in-module`, `declarations/barrel-current`, unique consumer names and job names, one declared class per role file, of `domain-events/transactional-before-commit` the adapters of an `application/ports/` port and the phase of an explicit-style handler, the config side of the ids above (`stack.events`, lowered severities, that a decision record exists) | `ddd-ts-kit check` | they judge the project, the glossary and files that are not sources; ESLint judges one source at a time |
|
|
274
413
|
| the real dependency graph (barrels, cycles, orphans, dev dependencies in production code) | dependency-cruiser, configured by the `.dependency-cruiser.cjs` that `ddd-ts-kit depcruise-config --write` generates from the config | it resolves modules instead of classifying paths |
|
|
275
414
|
|
|
276
415
|
The CLI keeps approximating the code-level rules with regular expressions, without dependency:
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.16.
|
|
1
|
+
export declare const VERSION = "0.16.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.16.
|
|
1
|
+
export const VERSION = '0.16.1';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[English](application-command-query-separation.md) · **Français**
|
|
2
|
+
<!-- translation-of: application-command-query-separation.md sha256:71759990f27562b5 -->
|
|
3
|
+
|
|
4
|
+
# ddd-ts-kit/application-command-query-separation
|
|
5
|
+
|
|
6
|
+
Identifiant d'architecture : `application/command-query-separation` (ajouté par ce *plugin*). Sévérité par défaut : `warn` dans `recommended`, `error` dans `strict`.
|
|
7
|
+
|
|
8
|
+
S'applique à : les fichiers sous `application/queries/` d'un contexte, tests exclus.
|
|
9
|
+
|
|
10
|
+
## Pourquoi
|
|
11
|
+
|
|
12
|
+
Une requête répond et ne change jamais l'état : on peut alors la relancer, la mettre en cache et l'exécuter sur une réplique. Une requête qui enregistre est une commande avec une valeur de retour.
|
|
13
|
+
|
|
14
|
+
## Signalé
|
|
15
|
+
|
|
16
|
+
- un appel de `save`, `delete` ou `publish` sur quelque chose que tient le gestionnaire (`this.invoices.save(...)`, `this.#bus.publish(...)`)
|
|
17
|
+
|
|
18
|
+
Incorrect :
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
export class SearchInvoicesHandler {
|
|
22
|
+
async execute(query: SearchInvoicesQuery): Promise<SearchInvoicesResult> {
|
|
23
|
+
await this.audit.save(query);
|
|
24
|
+
return this.reader.read(query);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Correct :
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
export class SearchInvoicesHandler {
|
|
33
|
+
async execute(query: SearchInvoicesQuery): Promise<SearchInvoicesResult> {
|
|
34
|
+
return this.reader.read(query);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Détails
|
|
40
|
+
|
|
41
|
+
Pragmatique par conception : la règle reconnaît des noms de méthodes sur les dépendances atteintes par `this`. Un `Set` local dont on appelle `delete` n'est pas signalé.
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
`[{ "mutators": ["save", "delete", "publish"] }]` remplace la liste des noms de méthodes.
|
|
46
|
+
|
|
47
|
+
`rules."application/command-query-separation"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line application/command-query-separation -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
|
|
48
|
+
|
|
49
|
+
## Limites
|
|
50
|
+
|
|
51
|
+
- Une modification derrière un autre nom (`upsert`, `record`) demande l'option `mutators`.
|
|
52
|
+
- Une dépendance passée en argument plutôt qu'injectée n'est pas suivie.
|
|
53
|
+
- L'autre moitié du principe, une commande qui renvoie plus qu'un identifiant, est laissée à la revue.
|
|
54
|
+
|
|
55
|
+
## Avec le checker de la CLI
|
|
56
|
+
|
|
57
|
+
Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car la forme d'une classe demande un arbre syntaxique.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[English](application-handler-shape.md) · **Français**
|
|
2
|
+
<!-- translation-of: application-handler-shape.md sha256:39389c2ddda30de3 -->
|
|
3
|
+
|
|
4
|
+
# ddd-ts-kit/application-handler-shape
|
|
5
|
+
|
|
6
|
+
Identifiant d'architecture : `application/handler-shape` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
|
+
|
|
8
|
+
S'applique à : les fichiers `*.handler.ts` sous `application/` d'un contexte.
|
|
9
|
+
|
|
10
|
+
## Pourquoi
|
|
11
|
+
|
|
12
|
+
Un gestionnaire (handler) est un cas d'usage : une classe, appelée par le bus par `execute`. Une seconde méthode publique est un second cas d'usage caché dans le premier, ou une décision métier qui revient au domaine.
|
|
13
|
+
|
|
14
|
+
## Signalé
|
|
15
|
+
|
|
16
|
+
- un fichier de gestionnaire qui n'exporte aucune classe
|
|
17
|
+
- une seconde classe exportée
|
|
18
|
+
- une classe de gestionnaire sans `execute` public
|
|
19
|
+
- toute autre méthode publique ou propriété de type fonction, statiques comprises
|
|
20
|
+
|
|
21
|
+
Incorrect :
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export class IssueInvoiceHandler {
|
|
25
|
+
async handle(command: IssueInvoiceCommand): Promise<string> {}
|
|
26
|
+
computeTotal(): number {}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Correct :
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
export class IssueInvoiceHandler implements CommandHandler<IssueInvoiceCommand> {
|
|
34
|
+
async execute(command: IssueInvoiceCommand): Promise<string> {}
|
|
35
|
+
private total(): number {}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Détails
|
|
40
|
+
|
|
41
|
+
Les types, interfaces et constantes exportés à côté de la classe sont permis. Les fichiers `*.event-handler.ts` ne sont pas des gestionnaires du bus et ne sont pas jugés.
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
Aucune.
|
|
46
|
+
|
|
47
|
+
`rules."application/handler-shape"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line application/handler-shape -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
|
|
48
|
+
|
|
49
|
+
## Limites
|
|
50
|
+
|
|
51
|
+
- La signature de `execute` n'est pas vérifiée par rapport au type de la commande ou de la requête : le compilateur le fait par `CommandHandler<T>` et `QueryHandler<T>`.
|
|
52
|
+
|
|
53
|
+
## Avec le checker de la CLI
|
|
54
|
+
|
|
55
|
+
Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car la forme d'une classe demande un arbre syntaxique.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[English](aspects-outside-in.md) · **Français**
|
|
2
|
+
<!-- translation-of: aspects-outside-in.md sha256:7cfc6798c104eafe -->
|
|
3
|
+
|
|
4
|
+
# ddd-ts-kit/aspects-outside-in
|
|
5
|
+
|
|
6
|
+
Identifiant d'architecture : `aspects/outside-in`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
|
+
|
|
8
|
+
S'applique à : chaque fichier de production sous la racine des sources, sauf `infrastructure/` d'un contexte et le répertoire de la plateforme ; `domain/` et `application/` sont laissés aux règles de couche.
|
|
9
|
+
|
|
10
|
+
## Pourquoi
|
|
11
|
+
|
|
12
|
+
La journalisation, les métriques, les nouvelles tentatives (retry), le délai d'expiration (timeout), le disjoncteur (circuit breaker) et le cache s'appliquent depuis l'extérieur du code qu'ils enveloppent : la politique de toute une application se lit à un seul endroit, la racine de composition, et change sans toucher une classe. La forme décorateur est l'exception, gardée pour un adaptateur dont la politique fait partie de ce qu'est l'adaptateur (un client d'un fournisseur qui documente ses propres règles de nouvelle tentative et de délai d'expiration). Sur une route, dans un fichier de module, dans un langage publié ou dans le noyau partagé, un décorateur cache une politique là où personne n'en cherche.
|
|
13
|
+
|
|
14
|
+
## Signalé
|
|
15
|
+
|
|
16
|
+
- un import de `@ddd-ts-kit/aspects/decorators` dans `presentation/`, dans `<context>.module.ts`, dans `published-language/`, dans tout autre fichier de production d'un contexte hors de `infrastructure/`, dans le noyau partagé, dans `main.ts` et dans toute autre source sous la racine des sources (`apps/<context>/main.ts` compris)
|
|
17
|
+
|
|
18
|
+
Incorrect :
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// src/contexts/billing/presentation/http/issue-invoice.route.ts
|
|
22
|
+
import { Retry } from '@ddd-ts-kit/aspects/decorators';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Correct :
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// src/contexts/billing/billing.module.ts
|
|
29
|
+
import { retry, timeout } from '@ddd-ts-kit/aspects';
|
|
30
|
+
|
|
31
|
+
builder.bind(PaymentGateway).toClass(StripePaymentGateway, [PaymentSettings]).with(retry({ attempts: 3 }), timeout(2000));
|
|
32
|
+
|
|
33
|
+
// src/contexts/billing/infrastructure/external/stripe-payment.gateway.ts
|
|
34
|
+
import { Retry } from '@ddd-ts-kit/aspects/decorators';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Détails
|
|
38
|
+
|
|
39
|
+
Seule l'entrée `/decorators` est jugée : les enveloppes de `@ddd-ts-kit/aspects` (`retry`, `timeout`, `aspects`, les *middlewares* du bus) sont ce qu'un fichier de module et `main.ts` sont censés importer. Les imports statiques, les imports de type seul, `export ... from`, les `import()` dynamiques et `require()` sont tous lus.
|
|
40
|
+
|
|
41
|
+
Dans `domain/` et `application/`, chaque entrée de `@ddd-ts-kit/aspects` est déjà refusée par `layer-domain-purity` et `layer-application-inward` : cette règle s'y tait, pour qu'un import donne un seul signalement. Les tests et les fichiers hors de la racine des sources (scripts, fichiers de configuration) ne sont pas jugés.
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
Aucune. `platformDir` et `sourceRoot` de `ddd-ts-kit.config.json` disent où sont la plateforme et les sources.
|
|
46
|
+
|
|
47
|
+
`rules."aspects/outside-in"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line aspects/outside-in -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
|
|
48
|
+
|
|
49
|
+
## Limites
|
|
50
|
+
|
|
51
|
+
- Un décorateur réexporté par un fichier de `infrastructure/` ou de la plateforme et importé de là n'est pas suivi.
|
|
52
|
+
- Un décorateur maison construit sur `weave` ou sur un aspect de l'entrée racine n'est pas reconnu.
|
|
53
|
+
- Avec `layer/domain-purity` ou `layer/application-inward` à `off`, rien ne signale les décorateurs dans cette couche.
|
|
54
|
+
|
|
55
|
+
## Avec le checker de la CLI
|
|
56
|
+
|
|
57
|
+
`ddd-ts-kit check` signale le même identifiant à partir des spécificateurs d'import qu'il lit dans le texte des fichiers, avec les mêmes exemptions. Cette règle fait autorité.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
[English](authz-actor-explicit.md) · **Français**
|
|
2
|
+
<!-- translation-of: authz-actor-explicit.md sha256:689f93a3deae404a -->
|
|
3
|
+
|
|
4
|
+
# ddd-ts-kit/authz-actor-explicit
|
|
5
|
+
|
|
6
|
+
Identifiant d'architecture : `authz/actor-explicit`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
|
+
|
|
8
|
+
S'applique à : `domain/` et `application/` d'un contexte, tests exclus.
|
|
9
|
+
|
|
10
|
+
## Pourquoi
|
|
11
|
+
|
|
12
|
+
Un cas d'usage qui lit « l'acteur courant » dans l'air ambiant fonctionne derrière une requête HTTP et nulle part ailleurs : un gestionnaire d'événement d'intégration, un *job* planifié et un test doivent d'abord poser une variable globale, et l'oublient. L'acteur est une donnée de la commande ou de la requête, comme toute autre entrée. La `ExecutionScope` ouverte à la frontière (et `ActorContext`, une vue de celle-ci) existe pour le code à qui l'on ne passe pas le contexte : l'infrastructure et la plateforme la lisent pour les colonnes d'audit, le cloisonnement par *tenant* et la corrélation.
|
|
13
|
+
|
|
14
|
+
## Signalé
|
|
15
|
+
|
|
16
|
+
- un import de `ActorContext`, `ExecutionScope`, `AsyncLocalStorageExecutionScope`, `ScopedActorContext` ou `AsyncLocalStorage`, de n'importe quel module, comme type ou comme valeur : la classe du port est aussi son jeton d'injection, si bien qu'un import de valeur est celui que nommerait une liste de dépendances
|
|
17
|
+
- les mêmes noms atteints par un espace de noms (`kernel.ExecutionScope`, `hooks.AsyncLocalStorage`)
|
|
18
|
+
- un paramètre de constructeur typé `ActorContext` ou `ExecutionScope`
|
|
19
|
+
- un appel de `.current()` ou `.require()` sans argument sur un récepteur déclaré avec l'un de ces types, ou, quand le fichier ne montre pas sa déclaration, nommé `actors`, `scope`, `scopes`, `...actorContext` ou `...executionScope`
|
|
20
|
+
- un import des utilitaires d'infrastructure `stampCreation`, `stampUpdate` ou `tenantScopeOf`, et leur usage par un espace de noms importé (`kernel.stampCreation`)
|
|
21
|
+
|
|
22
|
+
Incorrect :
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { stampCreation, type ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
26
|
+
|
|
27
|
+
export class VoidInvoiceHandler {
|
|
28
|
+
constructor(private readonly invoices: InvoiceRepository, private readonly scope: ExecutionScope) {}
|
|
29
|
+
|
|
30
|
+
async execute(command: VoidInvoice): Promise<void> {
|
|
31
|
+
const { actor } = this.scope.require();
|
|
32
|
+
const stamp = stampCreation(this.scope, this.clock);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Correct :
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
export class VoidInvoiceHandler {
|
|
41
|
+
constructor(private readonly invoices: InvoiceRepository, private readonly access: Access) {}
|
|
42
|
+
|
|
43
|
+
async execute(command: VoidInvoice): Promise<void> {
|
|
44
|
+
await this.access.authorize(command.actor, billingPermissions['invoice.void'], invoice);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// infrastructure/persistence/drizzle-invoice.repository.ts
|
|
49
|
+
const row = { ...toRow(invoice), ...stampCreation(this.scope, this.clock), ...tenantScopeOf(this.scope) };
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Détails
|
|
53
|
+
|
|
54
|
+
`infrastructure/` et la plateforme peuvent lire la `ExecutionScope` et l'`ActorContext` pour les colonnes d'audit, le cloisonnement par *tenant*, les champs de journal et l'identifiant de corrélation, et le module lie `ActorContext` et `ExecutionScope` : rien de cela n'est jugé. Les tests ne sont pas jugés non plus, si bien que `FixedExecutionScope` et `FixedActorContext` leur restent disponibles. Un import, le paramètre de constructeur qu'il type et la lecture font trois signalements, un par ligne à changer.
|
|
55
|
+
|
|
56
|
+
Le type d'un récepteur se lit dans sa déclaration dans le même fichier (un paramètre, une variable, une propriété, une propriété de paramètre) : aucune information de type n'est nécessaire. Un récepteur nommé `scope` et déclaré avec un autre type (`AccessScope`, un concept du domaine) n'est pas signalé.
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
Aucune.
|
|
61
|
+
|
|
62
|
+
`rules."authz/actor-explicit"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line authz/actor-explicit -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
|
|
63
|
+
|
|
64
|
+
## Limites
|
|
65
|
+
|
|
66
|
+
- Un contexte ambiant atteint sous un autre nom (un port du projet qui enveloppe `ExecutionScope`, une variable de niveau module) n'est pas vu.
|
|
67
|
+
- Une réexportation par un fichier du contexte qui renomme le port n'est pas suivie.
|
|
68
|
+
- Un récepteur nommé `scope` dont la déclaration n'est pas dans le fichier (une dépendance déstructurée, une propriété d'une classe de base) est jugé par son nom : un concept du domaine appelé `scope` doté de sa propre méthode `current()` ou `require()` est signalé. Annotez la déclaration, ou enregistrez la désactivation.
|
|
69
|
+
- Une méthode du projet nommée `stampCreation`, `stampUpdate` ou `tenantScopeOf` n'est pas signalée ; un utilitaire importé sous ces noms d'un autre module que le noyau l'est.
|
|
70
|
+
|
|
71
|
+
## Avec le checker de la CLI
|
|
72
|
+
|
|
73
|
+
`ddd-ts-kit check` signale le même identifiant à partir du texte des fichiers et reste le garde-fou rapide pendant l'écriture : il ne connaît aucun type déclaré, si bien qu'il signale `.current()` et `.require()` sur tout ce qui s'appelle `scope`, `scopes` ou `...executionScope`, et un utilitaire seulement quand le fichier l'importe sous son propre nom. Cette règle fait autorité.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
[English](authz-declared.md) · **Français**
|
|
2
|
+
<!-- translation-of: authz-declared.md sha256:45bde1afe67f1b4c -->
|
|
3
|
+
|
|
4
|
+
# ddd-ts-kit/authz-declared
|
|
5
|
+
|
|
6
|
+
Identifiant d'architecture : `authz/declared`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
|
+
|
|
8
|
+
S'applique à : le fichier de module d'un contexte pour les enregistrements, chaque fichier de production pour les routes et les messages, et, dans un projet de style déclaré (`stack.style: "declared"`), les fichiers `*.command.ts` et `*.query.ts` sous `application/commands` et `application/queries` ; tests exclus.
|
|
9
|
+
|
|
10
|
+
## Pourquoi
|
|
11
|
+
|
|
12
|
+
Rien n'est accessible par défaut. Un cas d'usage ou une route qui ne dit rien de qui peut l'appeler est ouvert par accident, et l'accident se découvre en production. Dire « public » est une décision ; ne rien dire n'en est pas une.
|
|
13
|
+
|
|
14
|
+
## Signalé
|
|
15
|
+
|
|
16
|
+
- dans `<context>.module.ts` : une chaîne `<builder>.command(X)` ou `<builder>.query(X)` qui atteint `.handledBy(...)` ou `.handledByFactory(...)` sans `.requires(...)` ni `.public()`, sauf si l'on voit que la classe `X` porte `@Requires(...)` ou `@Public()`
|
|
17
|
+
- dans un projet de style déclaré : une classe exportée d'un fichier `*.command.ts` ou `*.query.ts` sous `application/commands` ou `application/queries` qui ne porte ni `@Requires(...)` ni `@Public()` de `@ddd-ts-kit/kernel/declarations`
|
|
18
|
+
- un `defineRoute({...})` dont la spécification n'a pas de propriété `security`, ou `security: undefined`
|
|
19
|
+
- un `defineRoute({...})` dont la spécification a `security: []`
|
|
20
|
+
- une classe qui étend `AuthorizedCommand` ou `AuthorizedQuery` dont le constructeur ne passe pas l'un de ses propres paramètres comme premier argument de `super(...)`
|
|
21
|
+
|
|
22
|
+
Incorrect :
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
builder.command(VoidInvoice).handledBy(VoidInvoiceHandler, [INVOICES]);
|
|
26
|
+
|
|
27
|
+
defineRoute({ method: 'POST', path: '/invoices/:id/void', operationId: 'voidInvoice', responses }, handler);
|
|
28
|
+
|
|
29
|
+
export class VoidInvoice extends AuthorizedCommand {
|
|
30
|
+
constructor(readonly invoiceId: string) {
|
|
31
|
+
super(systemActor('billing'));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// style déclaré : application/commands/issue-invoice/issue-invoice.command.ts
|
|
36
|
+
export class IssueInvoiceCommand extends AuthorizedCommand<string> {}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Correct :
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
builder.command(VoidInvoice).requires(billingPermissions['invoice.void']).handledBy(VoidInvoiceHandler, [INVOICES]);
|
|
43
|
+
builder.query(GetCatalog).public().handledBy(GetCatalogHandler, [CATALOG]);
|
|
44
|
+
|
|
45
|
+
defineRoute({ method: 'POST', path: '/invoices/:id/void', operationId: 'voidInvoice', responses, security: ['bearer'] }, handler);
|
|
46
|
+
defineRoute({ method: 'GET', path: '/catalog', operationId: 'getCatalog', responses, security: false }, handler);
|
|
47
|
+
|
|
48
|
+
export class VoidInvoice extends AuthorizedCommand {
|
|
49
|
+
constructor(actor: Actor, readonly invoiceId: string) {
|
|
50
|
+
super(actor);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// style déclaré : application/commands/issue-invoice/issue-invoice.command.ts
|
|
55
|
+
import { Requires } from '@ddd-ts-kit/kernel/declarations';
|
|
56
|
+
|
|
57
|
+
@Requires(billingPermissions['invoice.issue'])
|
|
58
|
+
export class IssueInvoiceCommand extends AuthorizedCommand<string> {}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Détails
|
|
62
|
+
|
|
63
|
+
Le type de route de `@ddd-ts-kit/http` impose déjà `security` : `defineRoute` ne compile pas sans elle et refuse une liste vide. Cette règle reste le filet, au niveau du lint, pour une définition de route construite de façon lâche : une spécification typée `any` ou transtypée, un fichier JavaScript, une enveloppe qui élargit le type.
|
|
64
|
+
|
|
65
|
+
`@Requires(...)` ou `@Public()` sur la classe du message est la déclaration, dans tout projet : un module qui enregistre un message décoré sans `.requires(...)` ni `.public()` n'est pas signalé. La classe est en vue quand elle est déclarée dans le fichier de module ou importée par son nom depuis une source du projet qui existe sur le disque, laquelle est alors analysée (syntaxe seulement). Un décorateur compte quand son nom est importé de `@ddd-ts-kit/kernel/declarations` dans le fichier de la classe, sous un alias (`{ Requires as Needs }`) ou un espace de noms (`declarations.Requires`) aussi ; un `Requires` maison ne compte pas.
|
|
66
|
+
|
|
67
|
+
Un projet de style explicite n'est jugé que sur ses enregistrements : un fichier de message sans décorateur n'y est pas signalé.
|
|
68
|
+
|
|
69
|
+
L'enregistrement est reconnu à sa forme, quel que soit le nom du builder. `super(input.actor)` est accepté quand `input` est un paramètre du constructeur. Une classe sans constructeur hérite de celui de `AuthorizedCommand`, qui prend l'acteur.
|
|
70
|
+
|
|
71
|
+
## Options
|
|
72
|
+
|
|
73
|
+
Aucune.
|
|
74
|
+
|
|
75
|
+
`rules."authz/declared"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line authz/declared -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
|
|
76
|
+
|
|
77
|
+
## Limites
|
|
78
|
+
|
|
79
|
+
- Un message enregistré atteint par un *barrel*, un export qui renomme, un import par défaut ou un espace de noms n'est pas suivi jusqu'à sa classe : son décorateur n'est pas vu et l'enregistrement est signalé.
|
|
80
|
+
- Dans un projet de style déclaré qui garde un `<context>.module.ts`, un message qui y est enregistré avec `.requires(...)` et écrit sans décorateur est quand même signalé dans son propre fichier : mettez le décorateur sur la classe.
|
|
81
|
+
- Un fichier `*.command.ts` ou `*.query.ts` qui n'exporte aucune classe n'est pas signalé ici.
|
|
82
|
+
- Un enregistrement réparti sur plusieurs instructions (`const target = builder.command(X); target.handledBy(H);`) n'est pas suivi.
|
|
83
|
+
- Un câblage écrit à la main avec `AuthorizationMap.of(requires(...), publicUseCase(...))` n'est pas lu : `authorizationMiddleware` refuse un cas d'usage non déclaré à l'exécution, et `createApplication({ authorization: 'required' })` au démarrage.
|
|
84
|
+
- Un message qui étend simplement `Command` ou `Query` alors que son enregistrement appelle `.requires(...)` s'étend sur deux fichiers et n'est pas vu ici ; le compilateur le refuse, puisque `requires` n'existe que pour un message qui porte un acteur.
|
|
85
|
+
- Une spécification de route qui n'est pas un littéral d'objet, ou qui étale un autre objet, n'est pas jugée.
|
|
86
|
+
- Que le schéma nommé dans `security` existe, et que la permission soit la bonne, n'est pas vérifié.
|
|
87
|
+
|
|
88
|
+
## Avec le checker de la CLI
|
|
89
|
+
|
|
90
|
+
`ddd-ts-kit check` signale le même identifiant à partir du texte des fichiers et reste le garde-fou rapide pendant l'écriture. Cette règle fait autorité.
|