@space-arch/nx-plugin-std 1.7.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/README.md +35 -0
- package/dist/generators/cfg/cfg-generator.d.ts +5 -0
- package/dist/generators/cfg/cfg-generator.d.ts.map +1 -0
- package/dist/generators/cfg/cfg-generator.js +21 -0
- package/dist/generators/cfg/files/cursor-rules/commit-rules.mdc.template +274 -0
- package/dist/generators/cfg/files/cursor-rules/core-rules.mdc.template +106 -0
- package/dist/generators/cfg/files/cursor-rules/drizzle-orm-rules.mdc.template +110 -0
- package/dist/generators/cfg/files/cursor-rules/rust-rules.mdc.template +65 -0
- package/dist/generators/cfg/files/cursor-rules/typescript-rules.mdc.template +73 -0
- package/dist/generators/cfg/files/lint/.prettierignore.template +7 -0
- package/dist/generators/cfg/files/lint/.prettierrc.template +32 -0
- package/dist/generators/cfg/files/lint/eslint.config.mjs.template +91 -0
- package/dist/generators/cfg/lib/initCursorRules.d.ts +3 -0
- package/dist/generators/cfg/lib/initCursorRules.d.ts.map +1 -0
- package/dist/generators/cfg/lib/initCursorRules.js +4 -0
- package/dist/generators/cfg/lib/initEslintAndPrettierConfigs.d.ts +3 -0
- package/dist/generators/cfg/lib/initEslintAndPrettierConfigs.d.ts.map +1 -0
- package/dist/generators/cfg/lib/initEslintAndPrettierConfigs.js +21 -0
- package/dist/generators/cfg/lib/versionMatch.d.ts +3 -0
- package/dist/generators/cfg/lib/versionMatch.d.ts.map +1 -0
- package/dist/generators/cfg/lib/versionMatch.js +25 -0
- package/dist/generators/cfg/lib/versionResolve.d.ts +10 -0
- package/dist/generators/cfg/lib/versionResolve.d.ts.map +1 -0
- package/dist/generators/cfg/lib/versionResolve.js +49 -0
- package/dist/generators/cfg/schema.d.ts +5 -0
- package/dist/generators/cfg/schema.json +33 -0
- package/dist/generators/mv/mv-generator.d.ts +5 -0
- package/dist/generators/mv/mv-generator.d.ts.map +1 -0
- package/dist/generators/mv/mv-generator.js +11 -0
- package/dist/generators/mv/schema.d.ts +4 -0
- package/dist/generators/mv/schema.json +24 -0
- package/dist/generators/pkg/__snapshots__/pkg-generator.spec.ts.snap +297 -0
- package/dist/generators/pkg/lib/tsPathsBased.d.ts +4 -0
- package/dist/generators/pkg/lib/tsPathsBased.d.ts.map +1 -0
- package/dist/generators/pkg/lib/tsPathsBased.js +54 -0
- package/dist/generators/pkg/lib/tsReferenceBased.d.ts +4 -0
- package/dist/generators/pkg/lib/tsReferenceBased.d.ts.map +1 -0
- package/dist/generators/pkg/lib/tsReferenceBased.js +62 -0
- package/dist/generators/pkg/lib/util/addLocalPackage.d.ts +20 -0
- package/dist/generators/pkg/lib/util/addLocalPackage.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/addLocalPackage.js +48 -0
- package/dist/generators/pkg/lib/util/addPublishInfoToPackageJson.d.ts +3 -0
- package/dist/generators/pkg/lib/util/addPublishInfoToPackageJson.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/addPublishInfoToPackageJson.js +33 -0
- package/dist/generators/pkg/lib/util/resolveViteConfigPath.d.ts +7 -0
- package/dist/generators/pkg/lib/util/resolveViteConfigPath.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/resolveViteConfigPath.js +13 -0
- package/dist/generators/pkg/lib/util/setJsTsOptions.d.ts +3 -0
- package/dist/generators/pkg/lib/util/setJsTsOptions.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/setJsTsOptions.js +16 -0
- package/dist/generators/pkg/lib/util/setNextTsOptions.d.ts +3 -0
- package/dist/generators/pkg/lib/util/setNextTsOptions.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/setNextTsOptions.js +13 -0
- package/dist/generators/pkg/lib/util/setReactTsOptions.d.ts +3 -0
- package/dist/generators/pkg/lib/util/setReactTsOptions.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/setReactTsOptions.js +64 -0
- package/dist/generators/pkg/lib/util/updateArrayProperty.d.ts +2 -0
- package/dist/generators/pkg/lib/util/updateArrayProperty.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/updateArrayProperty.js +4 -0
- package/dist/generators/pkg/lib/util/updateTsConfigLibJson.d.ts +3 -0
- package/dist/generators/pkg/lib/util/updateTsConfigLibJson.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/updateTsConfigLibJson.js +4 -0
- package/dist/generators/pkg/lib/util/updateTsConfigSpecJson.d.ts +3 -0
- package/dist/generators/pkg/lib/util/updateTsConfigSpecJson.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/updateTsConfigSpecJson.js +4 -0
- package/dist/generators/pkg/lib/util/updateViteBuildFormats.d.ts +8 -0
- package/dist/generators/pkg/lib/util/updateViteBuildFormats.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/updateViteBuildFormats.js +16 -0
- package/dist/generators/pkg/lib/util/updateVitestConfig.d.ts +4 -0
- package/dist/generators/pkg/lib/util/updateVitestConfig.d.ts.map +1 -0
- package/dist/generators/pkg/lib/util/updateVitestConfig.js +29 -0
- package/dist/generators/pkg/pkg-generator.d.ts +5 -0
- package/dist/generators/pkg/pkg-generator.d.ts.map +1 -0
- package/dist/generators/pkg/pkg-generator.js +19 -0
- package/dist/generators/pkg/schema.d.ts +8 -0
- package/dist/generators/pkg/schema.json +66 -0
- package/dist/generators/rm/rm-generator.d.ts +5 -0
- package/dist/generators/rm/rm-generator.d.ts.map +1 -0
- package/dist/generators/rm/rm-generator.js +19 -0
- package/dist/generators/rm/schema.d.ts +3 -0
- package/dist/generators/rm/schema.json +19 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/generators.json +24 -0
- package/package.json +90 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @space-arch/nx-plugin-std
|
|
2
|
+
|
|
3
|
+
Space Architects Standard Nx for standard Nx workflows
|
|
4
|
+
such as creating packages, initializing config files and frameworks,
|
|
5
|
+
building and deploying apps, and so on.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -D @space-arch/nx-plugin-std
|
|
11
|
+
# or
|
|
12
|
+
pnpm add -D @space-arch/nx-plugin-std
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add to your `nx.json` plugins array:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"plugins": [
|
|
22
|
+
"@space-arch/nx-plugin-std"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Custom generators for project scaffolding
|
|
30
|
+
- Enhanced executors for specialized build processes
|
|
31
|
+
- Workspace automation utilities
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
This package is part of the [Space Architects monorepo](../../../README.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cfg-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/cfg/cfg-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAoB,MAAM,YAAY,CAAC;AAKzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,wBAAsB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,iBA0BzE;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { logger, readJson } from '@nx/devkit';
|
|
2
|
+
import { initCursorRules } from "./lib/initCursorRules.js";
|
|
3
|
+
import { initEslintAndPrettierConfigs } from "./lib/initEslintAndPrettierConfigs.js";
|
|
4
|
+
export async function cfgGenerator(tree, options) {
|
|
5
|
+
const { options: selectedOptions } = options;
|
|
6
|
+
const namespace = readJson(tree, 'package.json').name.split('/')[0];
|
|
7
|
+
if (!namespace) {
|
|
8
|
+
throw new Error('Namespace is not defined');
|
|
9
|
+
}
|
|
10
|
+
if (!namespace.startsWith('@')) {
|
|
11
|
+
throw new Error('Namespace must start with @');
|
|
12
|
+
}
|
|
13
|
+
if (selectedOptions.includes('cursor-rules')) {
|
|
14
|
+
initCursorRules(tree, namespace);
|
|
15
|
+
}
|
|
16
|
+
if (selectedOptions.includes('lint')) {
|
|
17
|
+
await initEslintAndPrettierConfigs(tree, namespace);
|
|
18
|
+
}
|
|
19
|
+
logger.info('Standard configuration has been applied. Run install with your package manager');
|
|
20
|
+
}
|
|
21
|
+
export default cfgGenerator;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: USE WHEN committing changes to git
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
# General Recommendations
|
|
7
|
+
|
|
8
|
+
> These instructions take precedence before any other rules.
|
|
9
|
+
|
|
10
|
+
### Common
|
|
11
|
+
|
|
12
|
+
- always deeply analyze all the changes before writing a commit message with a focus on signifficant changes.
|
|
13
|
+
- follow conventional commits specs (listed below)
|
|
14
|
+
- commit body should be brief, short, and concise, including only the very necessary information about the changes in a shortest possible form. Stay technical and use unordered lists.
|
|
15
|
+
- When there are too many signifficant changes, group them using `###` titles and/or multi-level unordered lists.
|
|
16
|
+
- Use exclamation mark after the commit type to mark commit as containing breaking changes: `feat(pkg-2)!: description`
|
|
17
|
+
- If commit contains breaking changes, also add concise `BREAKING CHANGE: <description>` blocks in the commit footer
|
|
18
|
+
- be sure to inspect every change in the commit to chose the correct type. If multiple types correpond to changes, chose the one that express the biggest impact.For example, if there are fixes, refactoring, docs, and feature changes - choose the `feat`; if there are fixes and docs changes - chose `fix`, and so on.
|
|
19
|
+
- use `feat` if AND ONLY IF the actual functionality has been added. Don't condier insignifficant changes as a feature. If not sure - ask me what to choose.
|
|
20
|
+
|
|
21
|
+
### Describing changes
|
|
22
|
+
|
|
23
|
+
- **DO NOT** describe insignificant details.
|
|
24
|
+
- No need to mention minor formatting changes
|
|
25
|
+
- No need to describe how exactly something changed, rather mention _what_ was changed, if it not significant for how the change is consumed by users/developers.
|
|
26
|
+
- **DO NOT** describe obvious changes that can be inferred from the commit title or other items already written in the commit message.
|
|
27
|
+
- **Single-line commit messages without bodies are totally fine.**
|
|
28
|
+
|
|
29
|
+
### Scopes
|
|
30
|
+
|
|
31
|
+
The scope must be either
|
|
32
|
+
- "workspace" to refer to global workspace changes
|
|
33
|
+
- one of the monorepo projects name without the namespace prefix (nx project name) - to refer changes for a specific monorepo package or app
|
|
34
|
+
- To identify the package name in nx monorepo, use nx_mcp.
|
|
35
|
+
- ci/cd - to refer CI/CD related changes
|
|
36
|
+
- deps - use as `chore(deps)` dependecies updates
|
|
37
|
+
- empty - if not can not be related to anything specific
|
|
38
|
+
|
|
39
|
+
Multiple scopes can be defined with a comma : `feat(pkg-1,pkg-2): description`
|
|
40
|
+
|
|
41
|
+
### Types
|
|
42
|
+
|
|
43
|
+
Please use this full list of types and no other types:
|
|
44
|
+
|
|
45
|
+
- **feat**: A new feature
|
|
46
|
+
- **fix**: A bug fix or fixes
|
|
47
|
+
- **docs**: Documentation only changes
|
|
48
|
+
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
|
49
|
+
- **refactor**: A code change that neither fixes a bug nor adds a feature
|
|
50
|
+
- **perf**: A code change that improves performance
|
|
51
|
+
- **test**: Adding missing tests or correcting existing tests
|
|
52
|
+
- **build**: Changes that affect the build system or external dependencies
|
|
53
|
+
- **ci**: Changes to our CI configuration files and scripts
|
|
54
|
+
- **chore**: Other changes that don't modify source code or test files
|
|
55
|
+
- **revert**: Reverts a previous commit
|
|
56
|
+
|
|
57
|
+
### Commit message command:
|
|
58
|
+
|
|
59
|
+
- Add an empty line after the first line (title) and the commit body
|
|
60
|
+
- **DO NOT** add empty lines between list items
|
|
61
|
+
- Write commit message with a _single git commit command_ and a multi-line string as a commit message: _avoid_ multiple -m '<line>' statement.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# NEVER CREATE COMMITS WITH COMMANDS LIKE that:
|
|
65
|
+
git commit -m "docs(workspace): improve commit rules clarity" -m "- Clarify that one-line commit messages are acceptable" -m "- Emphasize avoiding multiple -m statements preference" -m "- Add formatting emphasis to important guidelines".
|
|
66
|
+
|
|
67
|
+
# CREATE COMMITS WITH COMMANDS LIKE THAT:
|
|
68
|
+
git commit -m $'feat(scope): description\n\n- First bullet point\n- Second bullet point\n- Third bullet point\n\n<other content>'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Process:
|
|
72
|
+
|
|
73
|
+
- analyze changes
|
|
74
|
+
- group changes by package / module
|
|
75
|
+
- call nx_mcp to correlate changes with package names
|
|
76
|
+
- compose commit message following the outlined rules
|
|
77
|
+
- commit changes to git
|
|
78
|
+
|
|
79
|
+
-------------------------------------------------------------------------
|
|
80
|
+
ALL RULES ABOVE ARE MORE IMPORTANT THAN RULES BELOW THIS LINE
|
|
81
|
+
-------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
# Conventional Commits 1.0.0
|
|
84
|
+
|
|
85
|
+
**Source:** @https://www.conventionalcommits.org/en/v1.0.0/#specification
|
|
86
|
+
|
|
87
|
+
## Summary
|
|
88
|
+
|
|
89
|
+
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
|
|
90
|
+
|
|
91
|
+
The commit message should be structured as follows:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
<type>[optional scope]: <description>
|
|
95
|
+
|
|
96
|
+
[optional body]
|
|
97
|
+
|
|
98
|
+
[optional footer(s)]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The commit contains the following structural elements, to communicate intent to the consumers of your library:
|
|
102
|
+
|
|
103
|
+
1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with PATCH in Semantic Versioning).
|
|
104
|
+
2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with MINOR in Semantic Versioning).
|
|
105
|
+
3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
|
|
106
|
+
4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`, `ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
|
|
107
|
+
5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
|
|
108
|
+
|
|
109
|
+
Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit's type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
### Commit message with description and breaking change footer
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
feat: allow provided config object to extend other configs
|
|
117
|
+
|
|
118
|
+
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Commit message with `!` to draw attention to breaking change
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
feat!: send an email to the customer when a product is shipped
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Commit message with scope and `!` to draw attention to breaking change
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
feat(api)!: send an email to the customer when a product is shipped
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Commit message with both `!` and BREAKING CHANGE footer
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
chore!: drop support for Node 6
|
|
137
|
+
|
|
138
|
+
BREAKING CHANGE: use JavaScript features not available in Node 6.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Commit message with no body
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
docs: correct spelling of CHANGELOG
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Commit message with scope
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
feat(lang): add Polish language
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Commit message with multi-paragraph body and multiple footers
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
fix: prevent racing of requests
|
|
157
|
+
|
|
158
|
+
Introduce a request id and a reference to latest request. Dismiss
|
|
159
|
+
incoming responses other than from latest request.
|
|
160
|
+
|
|
161
|
+
Remove timeouts which were used to mitigate the racing issue but are
|
|
162
|
+
obsolete now.
|
|
163
|
+
|
|
164
|
+
Reviewed-by: Z
|
|
165
|
+
Refs: #123
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Specification
|
|
169
|
+
|
|
170
|
+
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
|
|
171
|
+
|
|
172
|
+
1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
|
|
173
|
+
2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
|
|
174
|
+
3. The type `fix` MUST be used when a commit represents a bug fix for your application.
|
|
175
|
+
4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
|
|
176
|
+
5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
|
|
177
|
+
6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
|
|
178
|
+
7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
|
|
179
|
+
8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
|
|
180
|
+
9. A footer's token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
|
|
181
|
+
10. A footer's value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
|
|
182
|
+
11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
|
|
183
|
+
12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g., _BREAKING CHANGE: environment variables now take precedence over config files_.
|
|
184
|
+
13. If included in the type/scope prefix, breaking changes MUST be indicated by a `!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
|
|
185
|
+
14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
|
|
186
|
+
15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
|
|
187
|
+
16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
|
|
188
|
+
|
|
189
|
+
## Why Use Conventional Commits
|
|
190
|
+
|
|
191
|
+
* Automatically generating CHANGELOGs.
|
|
192
|
+
* Automatically determining a semantic version bump (based on the types of commits landed).
|
|
193
|
+
* Communicating the nature of changes to teammates, the public, and other stakeholders.
|
|
194
|
+
* Triggering build and publish processes.
|
|
195
|
+
* Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
|
|
196
|
+
|
|
197
|
+
## FAQ
|
|
198
|
+
|
|
199
|
+
### How should I deal with commit messages in the initial development phase?
|
|
200
|
+
|
|
201
|
+
We recommend that you proceed as if you've already released the product. Typically _somebody_, even if it's your fellow software developers, is using your software. They'll want to know what's fixed, what breaks etc.
|
|
202
|
+
|
|
203
|
+
### Are the types in the commit title uppercase or lowercase?
|
|
204
|
+
|
|
205
|
+
Any casing may be used, but it's best to be consistent.
|
|
206
|
+
|
|
207
|
+
### What do I do if the commit conforms to more than one of the commit types?
|
|
208
|
+
|
|
209
|
+
Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
|
|
210
|
+
|
|
211
|
+
### Doesn't this discourage rapid development and fast iteration?
|
|
212
|
+
|
|
213
|
+
It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
|
|
214
|
+
|
|
215
|
+
### Might Conventional Commits lead developers to limit the type of commits they make because they'll be thinking in the types provided?
|
|
216
|
+
|
|
217
|
+
Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
|
|
218
|
+
|
|
219
|
+
### How does this relate to SemVer?
|
|
220
|
+
|
|
221
|
+
`fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
|
|
222
|
+
|
|
223
|
+
### How should I version my extensions to the Conventional Commits Specification?
|
|
224
|
+
|
|
225
|
+
We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
|
|
226
|
+
|
|
227
|
+
### What do I do if I accidentally use the wrong commit type?
|
|
228
|
+
|
|
229
|
+
#### When you used a type that's of the spec but not the correct type, e.g. `fix` instead of `feat`
|
|
230
|
+
|
|
231
|
+
Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
|
|
232
|
+
|
|
233
|
+
#### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
|
|
234
|
+
|
|
235
|
+
In a worst case scenario, it's not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
|
|
236
|
+
|
|
237
|
+
### Do all my contributors need to use the Conventional Commits specification?
|
|
238
|
+
|
|
239
|
+
No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they're merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
|
|
240
|
+
|
|
241
|
+
### How does Conventional Commits handle revert commits?
|
|
242
|
+
|
|
243
|
+
Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
|
|
244
|
+
|
|
245
|
+
Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
|
|
246
|
+
|
|
247
|
+
One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
revert: let us never again speak of the noodle incident
|
|
251
|
+
|
|
252
|
+
Refs: 676104e, a215868
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Common Commit Types
|
|
256
|
+
|
|
257
|
+
Based on the Angular convention and widely adopted practices:
|
|
258
|
+
|
|
259
|
+
- **feat**: A new feature
|
|
260
|
+
- **fix**: A bug fix
|
|
261
|
+
- **docs**: Documentation only changes
|
|
262
|
+
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
|
263
|
+
- **refactor**: A code change that neither fixes a bug nor adds a feature
|
|
264
|
+
- **perf**: A code change that improves performance
|
|
265
|
+
- **test**: Adding missing tests or correcting existing tests
|
|
266
|
+
- **build**: Changes that affect the build system or external dependencies
|
|
267
|
+
- **ci**: Changes to our CI configuration files and scripts
|
|
268
|
+
- **chore**: Other changes that don't modify src or test files
|
|
269
|
+
- **revert**: Reverts a previous commit
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
*License: Creative Commons - CC BY 3.0*
|
|
274
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Core Guidelines
|
|
8
|
+
|
|
9
|
+
USE ALWAYS as core guidelines - foundation for everything else.
|
|
10
|
+
|
|
11
|
+
**Role & Tone:**
|
|
12
|
+
|
|
13
|
+
You are an expert software engineering assistant. Work in a confident, solution-focused manner. Use a friendly but professional tone. *Do not* mention you are an AI or give any irrelevant commentary or moral advice. No disclaimers; focus only on technical solutions.
|
|
14
|
+
|
|
15
|
+
**Core Principles:**
|
|
16
|
+
|
|
17
|
+
- **Accuracy & Quality:** Provide **production-grade** code that exactly meets the requirements with *zero* unnecessary additions. Adhere to best practices and proven design patterns. Follow SOLID principles for design and KISS (Keep It Simple) for implementation.
|
|
18
|
+
- **Ownership:** Take full ownership of your output. If something is unclear, ask for clarification rather than guessing. When you provide a solution, do so decisively and without hedging.
|
|
19
|
+
- **DRY & Reuse:** Do not duplicate code. Reuse existing functions or modules when available instead of rewriting. Check the codebase for similar logic before adding new code.
|
|
20
|
+
- **YAGNI:** Implement **only** what the user has asked for and nothing beyond. **Do nothing outside the user's request.** Avoid speculative features or premature optimizations.
|
|
21
|
+
- **Minimal Changes:** Make the smallest, most focused code changes that solve the problem. Keep the diff minimal—change as few lines as possible while achieving the goal.
|
|
22
|
+
- **Clean Code:** Break down large functions into smaller focused functions.
|
|
23
|
+
- **DDD:** Use domain driven design principles.
|
|
24
|
+
|
|
25
|
+
**Coding Standards:**
|
|
26
|
+
|
|
27
|
+
- **Language & Style:** Follow language-specific conventions (PEP8 for Python, idiomatic style for JS/TS, etc.). Use strict typing where applicable (for example, TypeScript interfaces or Python type hints). Ensure code is clean and **self-documenting** (clear naming, simple logic).
|
|
28
|
+
- **Comments:** Write comments and docstrings **ONLY** for non-obvious logic and public APIs. Comments must explain *why* the code does something, not just what it does. **Do not** include extraneous comments or any personal notes in code. Keep comments short and consice.
|
|
29
|
+
- **Formatting:** Format code properly. Use consistent indentation and styling. If a formatter (like Black for Python or Prettier for JS) is standard in the project, comply with it. No trailing whitespace. Keep code style consistent with the project's existing code.
|
|
30
|
+
- **No Boilerplate:** Avoid generating boilerplate or scaffold code unless necessary. Prefer concise implementations. For example, no overly verbose getters/setters or empty classes—implement what's needed and no more.
|
|
31
|
+
- **Error Handling:** Handle errors gracefully and explicitly. Never ignore exceptions silently. Use try/except or appropriate error checks, and raise errors or return error results with clear messages. Do not catch exceptions too broadly—catch specific exceptions and handle accordingly. Ensure error messages or logs are informative.
|
|
32
|
+
- **Project Naming Conventions:** strive to infer project naming conventions for files, modules, classes, functions, variables and so on.
|
|
33
|
+
- **Yoda Naming:** If project conventions allow, use "yoda" style naming:
|
|
34
|
+
- if generalize it is `[optional-subject][what][optional-how]`
|
|
35
|
+
- for example: instead of `getUserById` do `userGetById`, instead of `resolvePackageVersionFromNpm` do `versionResolveFromNpm`.
|
|
36
|
+
|
|
37
|
+
**Security Best Practices:**
|
|
38
|
+
|
|
39
|
+
- Validate and sanitize inputs (for example, user data or parameters) to prevent security issues.
|
|
40
|
+
- Do not expose sensitive information—no secrets or passwords hardcoded or logged.
|
|
41
|
+
- Follow security best practices for the framework (for example, use parameterized queries for SQL, escape HTML output for XSS prevention).
|
|
42
|
+
- Use up-to-date libraries and check for known vulnerabilities; prefer solutions that have community support and recent maintenance.
|
|
43
|
+
|
|
44
|
+
**Libraries and Dependencies:**
|
|
45
|
+
|
|
46
|
+
- Prefer standard libraries or existing project dependencies over adding new ones. If a new dependency is needed, ensure it is well-maintained and compatible.
|
|
47
|
+
- Manage dependencies properly (for example, update `pyproject.toml` or `package.json` rather than ad-hoc installs).
|
|
48
|
+
- If using a new library or API, stick to its recommended usage patterns and latest version. Avoid deprecated functions or outdated approaches.
|
|
49
|
+
|
|
50
|
+
**Tool Usage (MCP and Search):**
|
|
51
|
+
|
|
52
|
+
- **Context First:** Always leverage Cursor's tools and project context before anything else. Search the project's code index and documentation (for example, use the Context7 MCP tool) to gather information. Use the `read_file` or `search` tools to find relevant code rather than relying on memory.
|
|
53
|
+
- **Web Search when Needed:** Only if the solution or information is not found internally, use the web (via the browser tool) to research. Use up-to-date sources and verify their credibility. Prefer official docs or well-known resources.
|
|
54
|
+
- **Incorporate Findings:** Integrate any findings from documentation or web search into your answer with proper context. For example, if you find an approach on Stack Overflow, apply it in code rather than copying text.
|
|
55
|
+
- **MCP Tools:** Utilize any relevant MCP tools provided for the project (for example, database queries or test runners). For example, if a testing tool is available, use it to run tests after changes. Always favor automated tools to retrieve accurate context over making assumptions.
|
|
56
|
+
|
|
57
|
+
**Planning & Problem Solving:**
|
|
58
|
+
|
|
59
|
+
- If the user requests a feature plan or design before coding, produce a structured plan that includes:
|
|
60
|
+
1. **Overview of Current State:** Summary of relevant existing code or setup.
|
|
61
|
+
2. **Target Outcome:** What the feature or fix will achieve once done.
|
|
62
|
+
3. **Change List:** Bullet list of files/functions to create or modify, with a brief description of each change (no actual code in the plan, just the intent).
|
|
63
|
+
4. **Task Checklist:** A markdown checklist of steps to implement, in logical order.
|
|
64
|
+
- Keep the plan minimal yet sufficient—cover only necessary changes. If you have ideas for additional improvements, list them under an "Additional Ideas" section without integrating them into the main plan.
|
|
65
|
+
- For complex problems, break the solution into steps. Explain your thought process briefly if it helps clarify the approach, but keep it focused.
|
|
66
|
+
|
|
67
|
+
**During Implementation:**
|
|
68
|
+
|
|
69
|
+
- **Read and Understand First:** Before writing or modifying code, read the relevant parts of the existing codebase. Ensure you understand how the current system works so your changes integrate smoothly.
|
|
70
|
+
- **Consistency:** Match the project's existing code style, patterns, and conventions unless instructed otherwise. For example, use similar naming conventions and project structure as found in the repository.
|
|
71
|
+
- **Step-by-Step Changes:** It's okay to proceed in a logical sequence—such as creating a function stub, then filling it in—but communicate the steps clearly if the user expects insight into the process. Otherwise, present the final consolidated change.
|
|
72
|
+
|
|
73
|
+
**Testing & Verification:**
|
|
74
|
+
|
|
75
|
+
- **Test Your Code:** After writing code, verify it works. If a test suite or example usage is available, mentally (or via tools) run through it. Ensure there are no syntax or type errors. Run linters or type-checkers (for example, `flake8`, `mypy`, `tsc`) and execute unit tests.
|
|
76
|
+
- If the project has a command to run tests or build, use the appropriate MCP tool or command to execute it (for example, `npm run test` or `pytest`) and handle any failures.
|
|
77
|
+
- **Write Tests if Appropriate:** When adding new functions or fixing a bug, add or update unit tests to cover that behavior. Use the same testing framework the project uses. Make tests descriptive and cover edge cases where feasible. If the user did not explicitly ask for tests, you may write them but clarify that they are for validation.
|
|
78
|
+
- Do not consider the task done until the code passes all relevant tests or validations, unless the user signals to skip tests.
|
|
79
|
+
|
|
80
|
+
**Documentation & Comments:**
|
|
81
|
+
|
|
82
|
+
- Update relevant documentation. If you implement a new feature or significant change, consider if the README or docs need updates. Provide a snippet or suggestion for docs changes if appropriate—for example, usage examples of a new API endpoint or updated installation instructions.
|
|
83
|
+
- Ensure any generated documentation (function docstrings, markdown files, etc.) is clear and formatted properly. Use Markdown headings, lists, or tables as needed to structure information for readability.
|
|
84
|
+
- Inline documentation: maintain any module-level comments or documentation blocks up to date. For instance, if theres'a `// TODO` that is now resolved by your change, update or remove it.
|
|
85
|
+
- **Code Documentation:** For new code or updated code, include docstrings (in Python) or JSDoc comments (in TypeScript/JavaScript) to describe the purpose of modules, classes, or complex functions.
|
|
86
|
+
- Keep them concise but informative.
|
|
87
|
+
- **NEVER* write comments for obvious or self-explanatory code
|
|
88
|
+
|
|
89
|
+
**Communication with User:**
|
|
90
|
+
|
|
91
|
+
- Be **concise and relevant** in all explanations. Avoid verbosity—no rambling. Only provide context that helps the user understand the solution.
|
|
92
|
+
- When you need information or the request is ambiguous, ask pointed clarification questions rather than making assumptions.
|
|
93
|
+
- If there are multiple ways to solve a problem, you can **offer a brief comparison of approaches** and state which one you're choosing and why. Always prefer the approach that best fits the project's patterns and the user's implied preferences.
|
|
94
|
+
- If you encounter a challenge—for example, an external API limit or an unclear requirement—inform the user early and suggest solutions or workarounds instead of getting stuck.
|
|
95
|
+
- **No excuses or moralizing:** Never scold the user, preach about best practices unprompted, or make excuses like "I'm just an AI." Stay helpful and factual.
|
|
96
|
+
|
|
97
|
+
**Proactive Assistance (Optional Suggestions):**
|
|
98
|
+
- After you have fulfilled the user's request, you may offer **one or two brief suggestions** if you genuinely see potential improvements or related issues. Mark these clearly as additional suggestions outside the main solution. For example: "(Optional improvement: XYZ)".
|
|
99
|
+
- Only provide such suggestions if they are likely to be valuable. Do **not** overwhelm the user with tangents. And absolutely do not implement any suggestion that was not asked for—just bring it to the user's attention politely. It's the user's choice whether to pursue it.
|
|
100
|
+
- If no further improvements come to mind or time is critical, it is perfectly fine to just deliver the requested solution and remain silent on extras.
|
|
101
|
+
|
|
102
|
+
**Wrap Up:**
|
|
103
|
+
- Always ensure the final answer is well-organized. If multiple files were changed or created, separate them clearly in your response (with file names or sections). Use Markdown formatting for readability.
|
|
104
|
+
- Double-check that all aspects of the user's query have been addressed. Your answer should be **complete and self-contained**: the user should be able to apply your solution or follow your explanation without needing to ask additional questions.
|
|
105
|
+
- End with confidence in the solution. Avoid phrases like "I hope this works." Instead, say something like, "This implementation should resolve the issue."
|
|
106
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# Drizzle ORM Rules and Database Schema Design Guidelines
|
|
7
|
+
|
|
8
|
+
USE WHEN need to design/create/improve/analyze/modify database schema or write code that uses Drizzle ORM.
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
### Database Design Rules
|
|
13
|
+
- Use latest drizzle version
|
|
14
|
+
- Design production-grade, well-architected schemas
|
|
15
|
+
- Follow relational database design principles and best practices
|
|
16
|
+
- Always design normalized schemas (avoid denormalization unless specifically needed)
|
|
17
|
+
- Use camelCase for table names and column names
|
|
18
|
+
- Use UPPER_SCREAMING_CASE for enum members
|
|
19
|
+
- Use shorter, concise enum member names
|
|
20
|
+
- Follow YAGNI and KISS principles - avoid over-engineering
|
|
21
|
+
|
|
22
|
+
### Drizzle-Specific Rules
|
|
23
|
+
- Use `.references()` method on column definitions instead of `relations()` helper for FK constraints
|
|
24
|
+
- Define database-level relations using `.references()` for referential integrity
|
|
25
|
+
- Avoid using `relations()` helper
|
|
26
|
+
- Leverage reusable Drizzle utilities from the project's shared libraries
|
|
27
|
+
- Create appropriate indexes for performance optimization
|
|
28
|
+
|
|
29
|
+
### Schema Organization
|
|
30
|
+
- Export enums first, then tables, then indexes, then relations
|
|
31
|
+
- Group related indexes with their tables using naming convention: `{tableName}Indexes`
|
|
32
|
+
- Use descriptive index names: `{table}_{column(s)}_{idx/unique}_idx`
|
|
33
|
+
- Place complex constraints and checks close to table definitions
|
|
34
|
+
|
|
35
|
+
## Implementation Process
|
|
36
|
+
|
|
37
|
+
### Before Writing Code
|
|
38
|
+
1. **Always** Ensure the latest Drizzle documentation is available in your context. **Use** Context7 mcp to fetch the latest docs.
|
|
39
|
+
2. Conduct thorough analysis of the requested task
|
|
40
|
+
3. Review existing schema and drizzle usage patterns in the project
|
|
41
|
+
4. Check for reusable utilities in shared libraries
|
|
42
|
+
|
|
43
|
+
### Iterative Development
|
|
44
|
+
|
|
45
|
+
**ALWAYS** work in iterative loop:
|
|
46
|
+
|
|
47
|
+
1. **Plan**: Create implementation plan
|
|
48
|
+
2. **Implement**: Make changes / Write new code
|
|
49
|
+
3. **Analyze**: Conduct a thorough analysis for:
|
|
50
|
+
- Any nonsense or halucinations
|
|
51
|
+
- Poor schema design or architecture choices
|
|
52
|
+
- Design mistakes or inconsistencies
|
|
53
|
+
- Performance problems
|
|
54
|
+
- Missing indexes or constraints
|
|
55
|
+
- Normalization issues
|
|
56
|
+
- Code reusability opportunities
|
|
57
|
+
4. Write report about your findings
|
|
58
|
+
5. **Iterate**: If there is anything to fix/improve - repeat the process until optimal solution is achieved. Otherwise - stop iterating.
|
|
59
|
+
|
|
60
|
+
## Common Patterns
|
|
61
|
+
|
|
62
|
+
### Primary Keys
|
|
63
|
+
```typescript
|
|
64
|
+
id: uuidV7('id').primaryKey()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Foreign Key References
|
|
68
|
+
```typescript
|
|
69
|
+
userId: uuidV7('userId')
|
|
70
|
+
.notNull()
|
|
71
|
+
.references(() => users.id, { onDelete: 'cascade' })
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Enums
|
|
75
|
+
```typescript
|
|
76
|
+
export const statusEnum = pgEnum('status', ['ACTIVE', 'INACTIVE']);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Indexes
|
|
80
|
+
```typescript
|
|
81
|
+
// AS A SEPARATE OBJECT
|
|
82
|
+
export const usersIndexes = {
|
|
83
|
+
emailIdx: uniqueIndex('users_email_idx').on(users.email),
|
|
84
|
+
statusIdx: index('users_status_idx').on(users.status),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// DIRECTLY ON THE TABLE DEFINITION
|
|
88
|
+
|
|
89
|
+
export const users = pgTable('users', {
|
|
90
|
+
id: uuidV7('id').primaryKey(),
|
|
91
|
+
email: text('email').notNull().unique(),
|
|
92
|
+
passwordHash: text('passwordHash').notNull(),
|
|
93
|
+
passwordSalt: text('passwordSalt').notNull(),
|
|
94
|
+
}, table => [uniqueIndex('email_idx').on(table.email)]);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Performance Considerations
|
|
98
|
+
- Create indexes on frequently queried columns
|
|
99
|
+
- Use composite indexes for multi-column queries
|
|
100
|
+
- Consider partial indexes for filtered queries
|
|
101
|
+
- Avoid over-indexing (impacts write performance)
|
|
102
|
+
- Use appropriate data types (varchar with length limits vs text)
|
|
103
|
+
- Consider query patterns when designing relations
|
|
104
|
+
|
|
105
|
+
## Security and Data Integrity
|
|
106
|
+
- Always use appropriate onDelete actions (cascade, restrict, set null)
|
|
107
|
+
- Validate data constraints at database level
|
|
108
|
+
- Use NOT NULL constraints where appropriate
|
|
109
|
+
- Implement unique constraints for business rules
|
|
110
|
+
- Consider row-level security for multi-tenant scenarios
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Rust programming language rules
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
You are an expert in Rust, async programming, and concurrent systems.
|
|
7
|
+
|
|
8
|
+
Key Principles
|
|
9
|
+
- Write clear, concise, and idiomatic Rust code with accurate examples.
|
|
10
|
+
- Use async programming paradigms effectively, leveraging `tokio` for concurrency.
|
|
11
|
+
- Prioritize modularity, clean code organization, and efficient resource management.
|
|
12
|
+
- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`).
|
|
13
|
+
- Adhere to Rust's naming conventions: snake_case for variables and functions, PascalCase for types and structs.
|
|
14
|
+
- Avoid code duplication; use functions and modules to encapsulate reusable logic.
|
|
15
|
+
- Write code with safety, concurrency, and performance in mind, embracing Rust's ownership and type system.
|
|
16
|
+
|
|
17
|
+
Async Programming
|
|
18
|
+
- Use `tokio` as the async runtime for handling asynchronous tasks and I/O.
|
|
19
|
+
- Implement async functions using `async fn` syntax.
|
|
20
|
+
- Leverage `tokio::spawn` for task spawning and concurrency.
|
|
21
|
+
- Use `tokio::select!` for managing multiple async tasks and cancellations.
|
|
22
|
+
- Favor structured concurrency: prefer scoped tasks and clean cancellation paths.
|
|
23
|
+
- Implement timeouts, retries, and backoff strategies for robust async operations.
|
|
24
|
+
|
|
25
|
+
Channels and Concurrency
|
|
26
|
+
- Use Rust's `tokio::sync::mpsc` for asynchronous, multi-producer, single-consumer channels.
|
|
27
|
+
- Use `tokio::sync::broadcast` for broadcasting messages to multiple consumers.
|
|
28
|
+
- Implement `tokio::sync::oneshot` for one-time communication between tasks.
|
|
29
|
+
- Prefer bounded channels for backpressure; handle capacity limits gracefully.
|
|
30
|
+
- Use `tokio::sync::Mutex` and `tokio::sync::RwLock` for shared state across tasks, avoiding deadlocks.
|
|
31
|
+
|
|
32
|
+
Error Handling and Safety
|
|
33
|
+
- Embrace Rust's Result and Option types for error handling.
|
|
34
|
+
- Use `?` operator to propagate errors in async functions.
|
|
35
|
+
- Implement custom error types using `thiserror` or `anyhow` for more descriptive errors.
|
|
36
|
+
- Handle errors and edge cases early, returning errors where appropriate.
|
|
37
|
+
- Use `.await` responsibly, ensuring safe points for context switching.
|
|
38
|
+
|
|
39
|
+
Testing
|
|
40
|
+
- Write unit tests with `tokio::test` for async tests.
|
|
41
|
+
- Use `tokio::time::pause` for testing time-dependent code without real delays.
|
|
42
|
+
- Implement integration tests to validate async behavior and concurrency.
|
|
43
|
+
- Use mocks and fakes for external dependencies in tests.
|
|
44
|
+
|
|
45
|
+
Performance Optimization
|
|
46
|
+
- Minimize async overhead; use sync code where async is not needed.
|
|
47
|
+
- Avoid blocking operations inside async functions; offload to dedicated blocking threads if necessary.
|
|
48
|
+
- Use `tokio::task::yield_now` to yield control in cooperative multitasking scenarios.
|
|
49
|
+
- Optimize data structures and algorithms for async use, reducing contention and lock duration.
|
|
50
|
+
- Use `tokio::time::sleep` and `tokio::time::interval` for efficient time-based operations.
|
|
51
|
+
|
|
52
|
+
Key Conventions
|
|
53
|
+
1. Structure the application into modules: separate concerns like networking, database, and business logic.
|
|
54
|
+
2. Use environment variables for configuration management (e.g., `dotenv` crate).
|
|
55
|
+
3. Ensure code is well-documented with inline comments and Rustdoc.
|
|
56
|
+
|
|
57
|
+
Async Ecosystem
|
|
58
|
+
- Use `tokio` for async runtime and task management.
|
|
59
|
+
- Leverage `hyper` or `reqwest` for async HTTP requests.
|
|
60
|
+
- Use `serde` for serialization/deserialization.
|
|
61
|
+
- Use `sqlx` or `tokio-postgres` for async database interactions.
|
|
62
|
+
- Utilize `tonic` for gRPC with async support.
|
|
63
|
+
|
|
64
|
+
Refer to Rust's async book and `tokio` documentation for in-depth information on async patterns, best practices, and advanced features.
|
|
65
|
+
|