Skip to content

Commit d5ca386

Browse files
committed
docs: improve README
1 parent 16aceff commit d5ca386

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

README.md

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
# mongodb-query-validator
22

3-
<!-- ![tests](https://github.com/simonecorsi/mongodb-query-validator/workflows/test/badge.svg) -->
4-
5-
> ✅ Zero Dependency MongoDB Query Operator Validator, why bother the database when you can save network rount-trip and CPU cycles?
3+
> ✅ Zero Dependency MongoDB Query Operator Validator. Why bother the database when you can save network round trips and CPU cycles?
64
75
## Table of Contents
86

97
<!-- toc -->
10-
118
- [About](#about)
129
* [Benefits](#benefits)
1310
* [Use Cases](#use-cases)
1411
- [Installation](#installation)
1512
- [Usage](#usage)
16-
- [Valid query Operators](#valid-query-operators)
13+
- [API](#api)
14+
- [Valid query operators](#valid-query-operators)
1715
- [Contributing](#contributing)
16+
- [Development](#development)
1817
- [License](#license)
1918
- [Contact](#contact)
20-
2119
<!-- tocstop -->
2220

2321
## About
2422

25-
Do you ever find yourself squinting at your MongoDB queries, only to realize you've made a tiny typo that's causing a big headache? We've been there too. That's why we built this nifty little tool – to save you from those pesky errors and wasted database trips.
23+
Do you ever find yourself squinting at your MongoDB queries, only to realize you've made a tiny typo that's causing a big headache? We've been there too. That's why this library exists: to catch those mistakes before they hit the database.
2624

2725
### Benefits
2826

29-
- **Error-Free Queries**: Say goodbye to query typos and syntax errors. Our validator catches them before they cause any trouble.
30-
- **Efficiency Boost**: Streamline your development process by validating queries upfront, saving you time and resources.
27+
- **Error-Free Queries**Say goodbye to query typos and syntax errors. The validator catches them before they cause trouble.
28+
- **Efficiency Boost** Streamline your development process by validating queries upfront, saving you time and resources.
3129

3230
### Use Cases
3331

34-
- **Production Systems**: Enhance the robustness of production systems by validating queries before executing them in live environments, minimizing downtime and errors.
35-
- **Development Environments**: Validate queries during development to catch errors early and streamline the debugging process.
36-
- **Testing Processes**: Integrate query validation into testing pipelines to ensure query correctness and reliability.
37-
38-
<!-- GETTING STARTED -->
32+
- **Production Systems** – Validate queries before executing them in live environments to minimize downtime and errors.
33+
- **Development Environments** – Catch mistakes early while you're building features.
34+
- **Testing Processes** – Integrate query validation into your testing pipelines to ensure correctness and reliability.
3935

4036
## Installation
4137

@@ -45,47 +41,60 @@ npm i --save mongodb-query-validator
4541
yarn add mongodb-query-validator
4642
```
4743

48-
<!-- USAGE EXAMPLES -->
49-
5044
## Usage
5145

5246
```ts
53-
import { validateQuery } from './src/index';
47+
import { validateQuery } from 'mongodb-query-validator';
5448

5549
const { isValidQuery } = validateQuery({ myField: { nested: { $gte: 123 } } });
5650
// isValidQuery = true
5751

58-
const { isValidQuery, invalidFields } = validateQuery({
52+
const { isValidQuery: valid, invalidFields } = validateQuery({
5953
myField: { nested: { $exist: true } },
6054
});
61-
// isValidQuery = false
62-
// invalidFields = ["myField.nexted.$exist"]
55+
// valid = false
56+
// invalidFields = ["myField.nested.$exist"]
6357
```
6458

65-
## Valid query Operators
59+
## API
60+
61+
`validateQuery(query[, maxDepth])`
6662

67-
You can find all supported query operator [here](./src/allowed.ts)
63+
- **query** – An object representing your MongoDB query.
64+
- **maxDepth** *(optional)* – Limit how deep the validator should traverse nested objects. `0` (default) means unlimited depth.
65+
66+
Returns an object with:
67+
68+
- `isValidQuery``true` if no invalid operators are found.
69+
- `invalidFields` – an array of paths to the invalid fields.
70+
71+
Type definitions are available in [`types/index.d.ts`](./types/index.d.ts).
72+
73+
## Valid query operators
74+
75+
The full list of supported operators can be found in [`src/allowed.ts`](./src/allowed.ts).
6876

6977
## Contributing
7078

71-
Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.
79+
Contributions are welcome! Please use [Conventional Commits](https://www.conventionalcommits.org/) when crafting your commit messages.
7280

73-
This projects uses [commitlint](https://commitlint.js.org/) with Angular configuration so be sure to use standard commit format or PR won't be accepted.
81+
1. Fork the repository and create your branch (`git checkout -b feat/my-feature`).
82+
2. Install dependencies with `npm i`.
83+
3. Add your changes and tests.
84+
4. Run the test suite with `npm test`.
85+
5. Commit using the `feat`, `fix`, or other conventional prefixes.
86+
6. Push your branch and open a pull request.
7487

75-
1. Fork the Project
76-
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
77-
3. Commit your Changes (`git commit -m 'feat(scope): some AmazingFeature'`)
78-
4. Push to the Branch (`git push origin feature/AmazingFeature`)
79-
5. Open a Pull Request
88+
## Development
8089

81-
<!-- LICENSE -->
90+
- **Build**`npm run build` compiles TypeScript to `dist/`.
91+
- **Tests**`npm test` runs the tap test suite. Use this before submitting PRs.
92+
- **Coverage**`npm run coverage` generates an HTML coverage report.
8293

8394
## License
8495

85-
Distributed under the MIT License. See `LICENSE` for more information.
86-
87-
<!-- CONTACT -->
96+
Distributed under the MIT License. See [`LICENSE`](LICENSE.md) for more information.
8897

8998
## Contact
9099

91-
Simone Corsi - [@im_simonecorsi](https://twitter.com/im_simonecorsi)
100+
Simone Corsi [@im_simonecorsi](https://twitter.com/im_simonecorsi)

0 commit comments

Comments
 (0)