@mrciphersmith/keryx 0.4.28 → 0.4.30
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/dist/cli.js +4916 -3655
- package/dist/core.js +91 -28
- package/dist/keryx-general-worker-entry.js +413 -240
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +3 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
- package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
- package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
- package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,14 +7,12 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# MobX patterns
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
composed in a MobX + React codebase.
|
|
10
|
+
MobX design patterns and anti-patterns, narrowing the common architecture
|
|
11
|
+
rules to how state, actions, and reactions compose in a MobX + React codebase.
|
|
13
12
|
|
|
14
13
|
## The async action shape
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
loading/error/data state:
|
|
15
|
+
Store method that calls an API and updates loading/error/data state:
|
|
18
16
|
|
|
19
17
|
```typescript
|
|
20
18
|
private performFetch = async () => {
|
|
@@ -44,79 +42,28 @@ private performFetch = async () => {
|
|
|
44
42
|
};
|
|
45
43
|
```
|
|
46
44
|
|
|
47
|
-
Anti-pattern: mutating `this.loading`/`this.items`
|
|
48
|
-
`await` with no `runInAction` — this throws under `enforceActions: "observed"`
|
|
49
|
-
and silently misses the reaction under looser settings, either way
|
|
50
|
-
producing a UI that does not update.
|
|
45
|
+
Anti-pattern: mutating `this.loading`/`this.items` after the `await` without `runInAction`.
|
|
51
46
|
|
|
52
47
|
## `flow` as an alternative to `runInAction`
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
avoids repeating `runInAction` around every post-`await` mutation, since
|
|
56
|
-
the whole generator body already runs inside one action:
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { flow } from "mobx";
|
|
60
|
-
|
|
61
|
-
fetchItems = flow(function* (this: ItemStore) {
|
|
62
|
-
this.loading = true;
|
|
63
|
-
try {
|
|
64
|
-
this.items = yield this.service.getAll();
|
|
65
|
-
} finally {
|
|
66
|
-
this.loading = false;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Use `flow` when a store's async methods are mostly sequential awaits with
|
|
72
|
-
state writes in between; keep plain `async`/`runInAction` when a method
|
|
73
|
-
needs to interleave with non-MobX async code (`Promise.all`, cancellation
|
|
74
|
-
tokens) where the generator form adds friction.
|
|
49
|
+
Use `flow` (generator-based action) for a store whose async methods are mostly sequential awaits with state writes in between; keep plain `async`/`runInAction` when a method interleaves with non-MobX async code (`Promise.all`, cancellation tokens).
|
|
75
50
|
|
|
76
51
|
## Reaction ownership and disposal
|
|
77
52
|
|
|
78
|
-
- `reaction`/`autorun`/`when` created
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
every disposer in `dispose()`.
|
|
82
|
-
- Prefer `reaction(() => selector, handler)` over `autorun` when the
|
|
83
|
-
handler should only run in response to a specific observable changing,
|
|
84
|
-
not on every observable it happens to read — `autorun` re-subscribes to
|
|
85
|
-
everything it touches on each run, which can widen its dependency set
|
|
86
|
-
unintentionally.
|
|
87
|
-
- A component should not create a raw `autorun`/`reaction` in its render
|
|
88
|
-
body; either derive the value with `@computed` in the store and let
|
|
89
|
-
`observer` handle re-rendering, or start the reaction in a `useEffect`
|
|
90
|
-
and dispose it in the cleanup function.
|
|
53
|
+
- A `reaction`/`autorun`/`when` created in a store belongs to its lifecycle: push the disposer into a `disposers: IReactionDisposer[]` array in the constructor (or an `init()` called by the parent) and call every disposer in `dispose()`.
|
|
54
|
+
- Prefer `reaction(() => selector, handler)` over `autorun` when the handler should run only when a specific observable changes.
|
|
55
|
+
- A component does not create a raw `autorun`/`reaction` in its render body; derive with `@computed` in the store, or start the reaction in `useEffect` and dispose it in the cleanup.
|
|
91
56
|
|
|
92
57
|
## Bidirectional store sync needs an equality guard
|
|
93
58
|
|
|
94
|
-
When Store A writes to Store B and
|
|
95
|
-
the reverse direction with `if (newValue !== currentValue)` before
|
|
96
|
-
propagating, or the two stores bounce a change back and forth forever.
|
|
97
|
-
See `rules/coding-style.mdc` for where that callback belongs (private,
|
|
98
|
-
not a public UI action).
|
|
59
|
+
When Store A writes to Store B and B writes back to A, guard the reverse direction with `if (newValue !== currentValue)` before propagating. See `rules/coding-style.mdc` for where that callback belongs (private, not a public UI action).
|
|
99
60
|
|
|
100
61
|
## View↔Store boundary
|
|
101
62
|
|
|
102
|
-
- A component reads store state and calls store actions; it does not
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
outside that component's tree mutates the same field.
|
|
106
|
-
- Data loading triggered by mounting belongs in the owning store's
|
|
107
|
-
`init()`/`onMount()`, called by the *parent* store or the top-level
|
|
108
|
-
provider — not scattered across every consuming component's
|
|
109
|
-
`useEffect`, which makes it impossible to reason about how many times a
|
|
110
|
-
fetch fires as the tree re-renders.
|
|
111
|
-
- A store must not import a React component or hook; it may accept
|
|
112
|
-
plain callback props for the rare case a parent needs to react to a
|
|
113
|
-
child store's internal event.
|
|
63
|
+
- A component reads store state and calls store actions; it does not keep a parallel copy of store state in `useState`.
|
|
64
|
+
- Mount-triggered data loading belongs in the owning store's `init()`/`onMount()`, called by the parent store or top-level provider, not in each consuming component's `useEffect`.
|
|
65
|
+
- A store must not import a React component or hook; it may accept plain callback props when a parent must react to a child store's internal event.
|
|
114
66
|
|
|
115
67
|
## Anti-pattern: computed-as-action
|
|
116
68
|
|
|
117
|
-
A `@computed` getter
|
|
118
|
-
side-effecting write inside it runs outside an explicit action
|
|
119
|
-
transaction and MobX will throw ("computed value is allowed to be
|
|
120
|
-
mutated only through action") the moment `enforceActions` is on. If a
|
|
121
|
-
"derived" value also needs to cache an expensive side effect, that is an
|
|
122
|
-
action-triggered `reaction`, not a computed.
|
|
69
|
+
A `@computed` getter never mutates state. A derived value that also needs an expensive side effect is an action-triggered `reaction`, not a computed.
|
|
@@ -7,50 +7,23 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# MobX security
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this file `extends`; this file covers the risks that are specific to
|
|
14
|
-
putting sensitive data in observable state.
|
|
10
|
+
Narrows the common OWASP-style rules to MobX state management. General
|
|
11
|
+
web-security concerns come from the common and React rules this file
|
|
12
|
+
`extends`; this file covers sensitive data in observable state.
|
|
15
13
|
|
|
16
14
|
## Do not put secrets in long-lived observable state
|
|
17
15
|
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
`autorun`/`reaction` to `localStorage`) is exposed to any code with
|
|
21
|
-
access to that store instance and to any DevTools-based MobX inspector
|
|
22
|
-
attached to the page. Keep secrets out of observable state; pass them
|
|
23
|
-
through a request layer that does not put them on a reactive object a
|
|
24
|
-
component tree (and any debugging tool observing it) can read.
|
|
25
|
-
- If a `reaction`/`autorun` persists store state to `localStorage`/
|
|
26
|
-
`sessionStorage` (a common MobX pattern for "remember this UI state"),
|
|
27
|
-
explicitly exclude any field carrying a token, PII, or payment data from
|
|
28
|
-
what gets serialized — persist a derived, scrubbed snapshot, not the
|
|
29
|
-
whole store.
|
|
16
|
+
- Keep a token, API key, or credential out of an `@observable` field on a store that survives the session (not cleared on logout, or persisted by `autorun`/`reaction` to `localStorage`); pass secrets through a request layer.
|
|
17
|
+
- When a `reaction`/`autorun` persists store state to `localStorage`/`sessionStorage`, exclude any field carrying a token, PII, or payment data; persist a derived, scrubbed snapshot, not the whole store.
|
|
30
18
|
|
|
31
19
|
## Untrusted data into observable state is still untrusted
|
|
32
20
|
|
|
33
|
-
- Assigning server or user-supplied HTML/markdown into an observable
|
|
34
|
-
field does not sanitize it. If that field is later rendered with
|
|
35
|
-
`dangerouslySetInnerHTML` in an `observer` component, the same XSS risk
|
|
36
|
-
applies as any other React render path — sanitize before it reaches the
|
|
37
|
-
observable, not by trusting MobX's reactivity to be a security boundary
|
|
38
|
-
(see `rules/security.mdc` in the `react` pack this one extends).
|
|
21
|
+
- Assigning server or user-supplied HTML/markdown into an observable does not sanitize it; sanitize before it reaches the observable if it is later rendered with `dangerouslySetInnerHTML` (see `rules/security.mdc` in the `react` pack).
|
|
39
22
|
|
|
40
23
|
## Reaction-driven side effects and SSRF/open-redirect risk
|
|
41
24
|
|
|
42
|
-
-
|
|
43
|
-
observable URL or hostname field must validate that value the same way
|
|
44
|
-
a request-time input would be validated — an attacker who can influence
|
|
45
|
-
the observable (e.g. via a query param synced into the store) can
|
|
46
|
-
otherwise trigger a request to an attacker-chosen host purely through
|
|
47
|
-
state changes, with no obvious call site to audit.
|
|
25
|
+
- Validate an observable URL or hostname that a `reaction`/`autorun` uses for `fetch`/navigation as a request-time input would be (e.g. a query param synced into the store).
|
|
48
26
|
|
|
49
27
|
## Disposal prevents stale-store data leaks across users/sessions
|
|
50
28
|
|
|
51
|
-
-
|
|
52
|
-
user's data in memory and observable to any component that still holds
|
|
53
|
-
a reference (e.g. a lingering `reaction` on a background tab). Call
|
|
54
|
-
`dispose()` on session/user change for any store holding
|
|
55
|
-
user-scoped data, not just to free memory — to stop rendering or
|
|
56
|
-
syncing stale, now-unauthorized data.
|
|
29
|
+
- Call `dispose()` on session/user change for any store holding user-scoped data, to stop rendering or syncing stale, now-unauthorized data (e.g. a lingering `reaction` on a background tab).
|
|
@@ -7,57 +7,28 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# MobX testing
|
|
9
9
|
|
|
10
|
-
Narrows the common testing rules to
|
|
11
|
-
|
|
12
|
-
concerns for React components themselves still come from the `react`
|
|
13
|
-
pack's own `rules/testing.mdc`.
|
|
10
|
+
Narrows the common testing rules to MobX stores, actions, and reactions;
|
|
11
|
+
React component testing comes from the `react` pack's `rules/testing.mdc`.
|
|
14
12
|
|
|
15
13
|
## Store tests are plain unit tests
|
|
16
14
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
— no React Testing Library render is needed. Co-locate the test next to
|
|
20
|
-
the store (`xyz.store.test.ts` beside `xyz.store.ts`), matching the
|
|
21
|
-
project's existing test-file convention.
|
|
22
|
-
- Mock the store's injected dependencies (an API service passed into the
|
|
23
|
-
constructor), not MobX itself — MobX's reactivity is the thing under
|
|
24
|
-
test, not something to stub out.
|
|
15
|
+
- Test a store with no React dependency by constructing it and calling its actions/reading its computeds, with no React Testing Library render. Co-locate the test (`xyz.store.test.ts` beside `xyz.store.ts`), matching the project's convention.
|
|
16
|
+
- Mock the store's injected dependencies (an API service passed to the constructor), not MobX.
|
|
25
17
|
|
|
26
18
|
## Awaiting async actions and reactions
|
|
27
19
|
|
|
28
|
-
- After
|
|
29
|
-
|
|
30
|
-
predicate on the resulting state (`await when(() => !store.loading)`)
|
|
31
|
-
before asserting — do not assert immediately after the call and rely on
|
|
32
|
-
a fixed `setTimeout`/sleep, which is both slower and flaky.
|
|
33
|
-
- When asserting on a value only a `reaction`/`autorun` sets, wait for
|
|
34
|
-
that reaction to have run (`await when(() => condition)`, or `await
|
|
35
|
-
Promise.resolve()` for microtask-only sync reactions) rather than
|
|
36
|
-
asserting synchronously right after the triggering mutation.
|
|
20
|
+
- After an async action, `await` its returned promise (plain `async` method) or `await when(() => !store.loading)` before asserting; no fixed `setTimeout`/sleep.
|
|
21
|
+
- For a value only a `reaction`/`autorun` sets, wait for it (`await when(() => condition)`, or `await Promise.resolve()` for microtask-only sync reactions) before asserting.
|
|
37
22
|
|
|
38
23
|
## `enforceActions` in tests
|
|
39
24
|
|
|
40
|
-
- Keep `enforceActions` at the project's real (usually `"observed"` or
|
|
41
|
-
|
|
42
|
-
convenience — a test that mutates observable state outside an action
|
|
43
|
-
should fail the same way production code would, since that failure is
|
|
44
|
-
exactly the bug class these tests exist to catch.
|
|
45
|
-
- If a test genuinely needs to seed store state directly (bypassing
|
|
46
|
-
actions, e.g. to set up a precondition), wrap that seeding assignment
|
|
47
|
-
in `runInAction` rather than disabling `enforceActions` for the whole
|
|
48
|
-
suite.
|
|
25
|
+
- Keep `enforceActions` at the project's real setting (usually `"observed"` or `"always"`); do not relax it to `"never"`.
|
|
26
|
+
- To seed store state directly, wrap the assignment in `runInAction` rather than disabling `enforceActions` for the suite.
|
|
49
27
|
|
|
50
28
|
## Testing disposal and reaction cleanup
|
|
51
29
|
|
|
52
|
-
- Assert that `dispose()`
|
|
53
|
-
mutation after `dispose()` and confirm the disposed reaction's effect
|
|
54
|
-
did not run again — a leaked, undisposed `autorun`/`reaction` is a real
|
|
55
|
-
bug that a naive "does dispose() throw" test will not catch.
|
|
30
|
+
- Assert that `dispose()` stops a store's reactions: mutate after `dispose()` and confirm the reaction's effect did not run again.
|
|
56
31
|
|
|
57
32
|
## Component tests still need `observer`-aware setup
|
|
58
33
|
|
|
59
|
-
-
|
|
60
|
-
mutation the same way production code would (through the store's own
|
|
61
|
-
action) and then assert on the rendered output after that action
|
|
62
|
-
resolves — do not directly reassign an observable field the component
|
|
63
|
-
reads and expect the same ordering guarantees an action provides.
|
|
34
|
+
- When rendering an `observer` component, trigger the mutation through the store's own action and assert after it resolves; do not reassign an observable field the component reads.
|
|
@@ -8,63 +8,50 @@ metadata:
|
|
|
8
8
|
# NestJS coding style
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic style rules, and `ts-js-node`'s
|
|
11
|
-
own TypeScript conventions, to NestJS
|
|
12
|
-
providers, and dependency injection. Applies only to `*.ts` files
|
|
13
|
-
NestJS project.
|
|
11
|
+
own TypeScript conventions, to the official NestJS idiom: decorator-driven
|
|
12
|
+
modules, providers, and dependency injection. Applies only to `*.ts` files
|
|
13
|
+
in a NestJS project.
|
|
14
14
|
|
|
15
15
|
## Naming and file layout
|
|
16
16
|
|
|
17
|
-
- One artifact per file, named after its role
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(`UsersController`, `UsersService`, `UsersModule`), `PascalCase`.
|
|
17
|
+
- One artifact per file, named after its role (`<name>.controller.ts`,
|
|
18
|
+
`.service.ts`, `.module.ts`, `.dto.ts`, `.guard.ts`, `.interceptor.ts`,
|
|
19
|
+
`.filter.ts`, `.pipe.ts`), the Nest CLI generator convention; no guard or
|
|
20
|
+
interceptor folded into a controller file.
|
|
21
|
+
- Class names end in the file-role suffix (`UsersController`, `UsersService`,
|
|
22
|
+
`UsersModule`).
|
|
24
23
|
- Injection tokens for non-class providers (`useValue`/`useFactory`) are
|
|
25
24
|
`UPPER_SNAKE_CASE` string constants or `Symbol()`s exported from a single
|
|
26
|
-
`tokens.ts`/`constants.ts`,
|
|
27
|
-
every injection site.
|
|
25
|
+
`tokens.ts`/`constants.ts`, not inline string literals.
|
|
28
26
|
|
|
29
27
|
## Decorators and typing
|
|
30
28
|
|
|
31
|
-
- Every constructor-injected dependency is typed explicitly
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
from a typed service call — never `Promise<any>`.
|
|
29
|
+
- Every constructor-injected dependency is typed explicitly; never widen it
|
|
30
|
+
to `any` to sidestep a circular-import error, fix the cycle (see
|
|
31
|
+
`rules/patterns.mdc`).
|
|
32
|
+
- Every controller method's return type is explicit or inferred from a typed
|
|
33
|
+
service call, never `Promise<any>`.
|
|
37
34
|
- DTOs are typed classes with `class-validator`/`class-transformer`
|
|
38
|
-
decorators, never plain `interface`s for request bodies
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
a class with no constructor dependencies — omitting it is a common cause
|
|
44
|
-
of a confusing DI resolution failure covered in
|
|
45
|
-
`skills/nestjs-build-fix/SKILL.md`.
|
|
35
|
+
decorators, never plain `interface`s for request bodies (see
|
|
36
|
+
`rules/security.mdc` and the repo's `nestjs-dto.mdc` rule, which owns the
|
|
37
|
+
DTO decorator checklist).
|
|
38
|
+
- `@Injectable()` on every class registered as a provider, even one with no
|
|
39
|
+
constructor dependencies (see `skills/nestjs-build-fix/SKILL.md`).
|
|
46
40
|
|
|
47
41
|
## Imports and module boundaries
|
|
48
42
|
|
|
49
|
-
- Import providers only from the module that exports them;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let an `@Module()` decorator grow past what fits on one screen without
|
|
56
|
-
splitting the feature into sub-modules.
|
|
57
|
-
- Barrel files (`index.ts` re-exporting a feature's public surface) export
|
|
58
|
-
only what other modules are meant to import — not internal providers,
|
|
59
|
-
guards, or DTOs used solely inside the module.
|
|
43
|
+
- Import providers only from the module that exports them; import the
|
|
44
|
+
feature module, or add the provider to its `exports`, rather than reaching
|
|
45
|
+
into another feature's `*.service.ts`.
|
|
46
|
+
- Keep an `@Module()` within one screen; split the feature into sub-modules
|
|
47
|
+
past that.
|
|
48
|
+
- Barrel files export only what other modules are meant to import.
|
|
60
49
|
|
|
61
50
|
## Errors
|
|
62
51
|
|
|
63
|
-
- Throw a
|
|
64
|
-
`BadRequestException`, `ConflictException
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
same thing unchanged; catch only where you add context (wrap with a
|
|
70
|
-
domain-specific exception) or where you genuinely handle it.
|
|
52
|
+
- Throw a built-in NestJS exception (`NotFoundException`,
|
|
53
|
+
`BadRequestException`, `ConflictException`) or a project subclass of
|
|
54
|
+
`HttpException`, never a bare `throw new Error(...)` where an HTTP response
|
|
55
|
+
is expected.
|
|
56
|
+
- Catch in a service only to add context (wrap in a domain-specific
|
|
57
|
+
exception) or to handle it, not to log and rethrow unchanged.
|
|
@@ -7,77 +7,57 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# NestJS patterns
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
Module/provider/request-pipeline design for NestJS (official NestJS
|
|
11
|
+
documentation) and its recurring anti-patterns. Applies only to `*.ts` files
|
|
12
|
+
in a NestJS project; general TypeScript design guidance comes from
|
|
13
|
+
`ts-js-node`'s own rules.
|
|
14
14
|
|
|
15
15
|
## Module and provider design
|
|
16
16
|
|
|
17
|
-
- A feature module owns its controllers, services, and
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
class field) except where a truly optional dependency needs
|
|
28
|
-
`@Optional()` — constructor injection makes required dependencies
|
|
29
|
-
visible in the type signature and fails fast at module-compile time.
|
|
30
|
-
- Default provider scope (`Default`/Singleton) is correct for stateless
|
|
31
|
-
services. Reach for `Scope.REQUEST` only when the provider genuinely
|
|
32
|
-
needs per-request state (e.g. the current user from a request-scoped
|
|
33
|
-
`REQUEST` token); a `REQUEST`-scoped provider re-instantiates its entire
|
|
34
|
-
injection subtree per request, which has a real performance cost — do
|
|
35
|
-
not default to it "to be safe."
|
|
17
|
+
- A feature module owns its controllers, services, and their providers;
|
|
18
|
+
imports other feature modules only for providers it consumes, exports only
|
|
19
|
+
what others should inject.
|
|
20
|
+
- Break a real circular dependency with `forwardRef()` on both sides, but
|
|
21
|
+
first reconsider the boundary; prefer a shared third module both depend on.
|
|
22
|
+
- Constructor injection over property injection (`@Inject()` on a field)
|
|
23
|
+
except a truly optional dependency with `@Optional()`.
|
|
24
|
+
- Default (Singleton) scope for stateless services; `Scope.REQUEST` only when
|
|
25
|
+
the provider needs per-request state (e.g. the `REQUEST` token), since it
|
|
26
|
+
re-instantiates its injection subtree per request.
|
|
36
27
|
|
|
37
28
|
## Guards, interceptors, pipes, and filters
|
|
38
29
|
|
|
39
|
-
- Cross-cutting concerns (auth, logging, response shaping, validation)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- A guard, interceptor, or pipe class stays free of business logic: a guard
|
|
53
|
-
decides allow/deny, an interceptor transforms/observes the
|
|
54
|
-
request-response stream, a pipe transforms/validates one argument. Move
|
|
55
|
-
any decision that needs several service calls into the service layer and
|
|
56
|
-
have the guard call that service.
|
|
30
|
+
- Cross-cutting concerns (auth, logging, response shaping, validation) go in
|
|
31
|
+
a guard/interceptor/pipe/filter, not inline per controller method.
|
|
32
|
+
- Register a concern that applies to nearly every route as a global provider
|
|
33
|
+
via `APP_GUARD`/`APP_INTERCEPTOR`/`APP_PIPE`/`APP_FILTER` in a module's
|
|
34
|
+
`providers` (inside Nest's DI graph, unlike `app.useGlobalGuards()`), not
|
|
35
|
+
by decorating every controller.
|
|
36
|
+
- When a global guard protects most routes, mark exceptions with a custom
|
|
37
|
+
decorator read via `Reflector` (e.g. `@Public()`); an undecorated route
|
|
38
|
+
must not be silently open via the guard's fallback.
|
|
39
|
+
- A guard only decides allow/deny, an interceptor transforms/observes the
|
|
40
|
+
request-response stream, a pipe transforms/validates one argument; a
|
|
41
|
+
decision needing several service calls moves to the service layer, which
|
|
42
|
+
the guard calls.
|
|
57
43
|
|
|
58
44
|
## Controllers vs. services
|
|
59
45
|
|
|
60
|
-
- A controller method parses/validates input (
|
|
61
|
-
delegates to exactly one service call
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
calls that a service method could compose instead.
|
|
46
|
+
- A controller method parses/validates input (DTO + `ValidationPipe`),
|
|
47
|
+
delegates to exactly one service call, and shapes the HTTP response; no
|
|
48
|
+
direct repository/ORM calls, business-rule branching, or orchestration of
|
|
49
|
+
several service calls a service method could compose.
|
|
65
50
|
- A service method has an explicit return type and throws a Nest HTTP
|
|
66
51
|
exception (see `rules/coding-style.mdc`) or a domain error the caller
|
|
67
|
-
translates
|
|
68
|
-
|
|
52
|
+
translates; it imports `Request`/`Response` only for a documented
|
|
53
|
+
streaming/file-download case.
|
|
69
54
|
|
|
70
55
|
## Anti-patterns to avoid
|
|
71
56
|
|
|
72
|
-
- Injecting
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
factory provider with the matching lifecycle hook.
|
|
80
|
-
- Business rules encoded only as `@Roles()`/`@Permissions()` decorator
|
|
81
|
-
strings scattered per-endpoint with no single source of truth for what
|
|
82
|
-
each role can do — centralize the role/permission matrix so a guard
|
|
83
|
-
reads it instead of re-deriving it per route.
|
|
57
|
+
- Injecting `ModuleRef` or `moduleRef.get(Provider, { strict: false })` to
|
|
58
|
+
route around a missing `imports`/`exports` entry; fix the module graph.
|
|
59
|
+
- A `useValue`/`useFactory` provider whose factory acquires a resource (e.g.
|
|
60
|
+
opens a connection) without a matching `OnModuleDestroy` hook.
|
|
61
|
+
- Role/permission rules as scattered per-endpoint `@Roles()`/`@Permissions()`
|
|
62
|
+
strings with no single source of truth; centralize the matrix and have a
|
|
63
|
+
guard read it.
|
|
@@ -7,67 +7,47 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# NestJS security
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`review-backend` skill and the project's ORM rules, not duplicated here.
|
|
10
|
+
Request-pipeline risks for a NestJS application, narrowing the OWASP-style
|
|
11
|
+
guidance in the common rules. Applies only to `*.ts` files in a NestJS
|
|
12
|
+
project; SQL/ORM-specific injection risk is covered by the `review-backend`
|
|
13
|
+
skill and the project's ORM rules, not duplicated here.
|
|
15
14
|
|
|
16
15
|
## Input validation
|
|
17
16
|
|
|
18
|
-
- Every controller method
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
`APP_PIPE` provider)
|
|
22
|
-
some controllers omit is
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
extra field the client sends still reaches the handler untouched.
|
|
29
|
-
- Never trust a query/param value's type from the route alone — a route
|
|
30
|
-
param typed `id: string` in the controller signature is still a raw
|
|
31
|
-
string at runtime; convert and validate it (`ParseIntPipe`,
|
|
32
|
-
`ParseUUIDPipe`, or a DTO with `@IsInt()`/`@IsUUID()`) rather than
|
|
33
|
-
passing it straight to a repository call.
|
|
17
|
+
- Every controller method accepting a body, query, or route param has a typed
|
|
18
|
+
DTO class validated by a global `ValidationPipe`, registered once
|
|
19
|
+
(`app.useGlobalPipes(new ValidationPipe(...))` in `main.ts`, or an
|
|
20
|
+
`APP_PIPE` provider); a per-controller `@UsePipes(ValidationPipe)` that
|
|
21
|
+
some controllers omit is a gap.
|
|
22
|
+
- `whitelist: true` and `forbidNonWhitelisted: true` on the global
|
|
23
|
+
`ValidationPipe`.
|
|
24
|
+
- Convert and validate a route/query param (`ParseIntPipe`, `ParseUUIDPipe`,
|
|
25
|
+
or a DTO with `@IsInt()`/`@IsUUID()`) rather than passing the raw string to
|
|
26
|
+
a repository call.
|
|
34
27
|
|
|
35
28
|
## AuthN/AuthZ
|
|
36
29
|
|
|
37
|
-
- Protect every route
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
`
|
|
45
|
-
query param that claims who the caller is.
|
|
46
|
-
- A role/permission check belongs in a guard evaluated before the handler
|
|
47
|
-
runs, not as an `if` inside the service after data has already been
|
|
48
|
-
fetched or mutated.
|
|
30
|
+
- Protect every non-public route with a guard (`@UseGuards(...)` or a global
|
|
31
|
+
`APP_GUARD`); an undecorated route in an otherwise-guarded controller is a
|
|
32
|
+
gap to confirm, not assume safe.
|
|
33
|
+
- Read the authenticated principal from the guard-populated request (e.g. a
|
|
34
|
+
`@CurrentUser()` decorator backed by `request.user`), never from a
|
|
35
|
+
client-supplied header, body field, or query param.
|
|
36
|
+
- A role/permission check belongs in a guard before the handler runs, not an
|
|
37
|
+
`if` in the service after data is fetched or mutated.
|
|
49
38
|
|
|
50
39
|
## Response and error handling
|
|
51
40
|
|
|
52
41
|
- An exception filter (global `APP_FILTER`, or `app.useGlobalFilters(...)`)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- Use NestJS's built-in `HttpException` subclasses (or your own subclass of
|
|
58
|
-
`HttpException`) for expected error conditions so the status code and
|
|
59
|
-
the response shape stay in the framework's own exception-filter
|
|
60
|
-
pipeline, instead of manually setting `response.status(...)` in a
|
|
61
|
-
controller and bypassing filters.
|
|
42
|
+
translates an unexpected internal error into a generic response; no raw
|
|
43
|
+
`error.message`/`error.stack` in the response body.
|
|
44
|
+
- Use `HttpException` subclasses for expected errors, not manual
|
|
45
|
+
`response.status(...)` in a controller that bypasses filters.
|
|
62
46
|
|
|
63
47
|
## Secrets and configuration
|
|
64
48
|
|
|
65
49
|
- Read secrets (API keys, DB credentials, JWT signing keys) through
|
|
66
|
-
`ConfigService`/`@nestjs/config
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- Do not log a full request/response body in an interceptor or middleware
|
|
71
|
-
applied globally without redacting known-sensitive DTO fields (passwords,
|
|
72
|
-
tokens, card numbers) — a broad request logger is a common accidental
|
|
73
|
-
secret-leak path into log storage.
|
|
50
|
+
`ConfigService`/`@nestjs/config`; no hardcoded value, and no `useFactory`
|
|
51
|
+
fallback to a literal secret when an env var is unset.
|
|
52
|
+
- No global request/response body logging in an interceptor or middleware
|
|
53
|
+
without redacting sensitive DTO fields (passwords, tokens, card numbers).
|