Skip to content

Commit

Permalink
v1.0.5-alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
tasmidur21 committed Feb 3, 2024
1 parent d1537f8 commit d044bd7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Nodejs Validation Schema Rules
# Dynamic Validation Rules
[![NPM Downloads](https://img.shields.io/npm/dw/%40tasmidur%2Fnodejs-validation-schema-rules)](https://www.npmjs.com/package/@tasmidur/nodejs-dynamic-validation-rules)
[![npm](https://img.shields.io/npm/v/%40tasmidur%2Fnodejs-validation-schema-rules)](https://www.npmjs.com/package/indexeddb-orm)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand All @@ -15,14 +15,14 @@ This tool generates preliminary validation rules for popular libraries such as [
npm install @tasmidur/nodejs-dynamic-validation-rules
yarn add @tasmidur/nodejs-dynamic-validation-rules
```
Then run `ndVr init` if you install the package globally otherwise `npm run ndVr init` for ".schema-config.js"
Then run `ndVr init` if you install the package globally otherwise `npm run ndVr init` for `schema.config.js`.

```bash
ndVr init
npm run ndVr init
ndVr init
npm run ndVr init
```

Modify the ".schema-config.js"
Modify the `schema.config.js`

```javascript
require("dotenv").config();
Expand Down Expand Up @@ -53,25 +53,25 @@ module.exports = schemaConfig;

## Usage

The `ndVr joi -t my_table -db mysql -c column1,column2` command generates validation rules for a specified database table and its columns. It creates a request validation rules based on the chosen validation library (choices: "joi", "validatorjs", "vine"). The generated rules can be used to enforce data integrity and validate incoming requests in your application.
The `ndVr joi -t my_table -db mysql -c column1,column2` command generates validation rules for a specified database table and its columns. It creates a validation rules based on the chosen validation libraries like `joi`, "validatorjs", "vine". The generated rules can be used to enforce data integrity and validate incoming requests in your application.

Options:
- -db, --database: Specify the type of database (e.g., "mysql", "postgres", "sqlite").
- -db, --database: Specify the type of database (e.g., `mysql`, `postgres`, `sqlite`).
- -t, --table: Specify the name of the database table for which rules should be generated.
- -c, --columns: Specify the column names of the table to generate rules for.
- -h, --help: Display help for the command.

Examples:
- Generate rules for a MySQL table named "users" with columns "id" and "name":
- Generate rules for a MySQL table named `users` with columns `id` and `name`:

```bash
npm run ndVr joi -t users -db mysql -c id,name
npm run ndVr joi -t users -db mysql -c id,name
```

- Generate rules for a PostgreSQL table named "users" with a request validation file using "validatorJs":
- Generate rules for a PostgreSQL table named `users` with a validation library `validatorJs`:

```bash
npm run ndVr validatorJs -t users -db mysql -c id,name
npm run ndVr validatorJs -t users -db mysql -c id,name
```

as same as for sqlite.
Expand All @@ -98,7 +98,7 @@ CREATE TABLE data_types (
Now if you run:

```bash
npm run ndVr joi -db sqlite -t data_types
npm run ndVr joi -db sqlite -t data_types
```

You'll get:
Expand Down Expand Up @@ -144,7 +144,7 @@ ________________________________________________________________________________
### Always skip columns
To always skip columns add it in the ".schema-config.js" file, under `skipColumns` attribute.
To always skip columns add it in the `schema-config.js` file, under `skipColumns` attribute.
```javascript
skipColumns: (process.env.SKIP_COLUMNS || 'created_at,updated_at,deleted_at').split(',')
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tasmidur/nodejs-dynamic-validation-rules",
"name": "dynamic-validation-rules",
"version": "v1.0.5-alpha",
"description": "This tool generates preliminary validation rules for popular libraries such as JOI, ValidatorJS and @vinejs/vine",
"description": "This tool generates basic validation rules for popular libraries such as JOI, ValidatorJS and @vinejs/vine",
"bin": {
"ndVr": "dist/cli.js"
},
Expand All @@ -25,10 +25,14 @@
"schema",
"nodejs-validation",
"dynamic-schema",
"dynamic-validation-rules-from-db",
"joi schema",
"validatorjs schema",
"vine js schema"
"dynamic-rules",
"dynamic-validation-rules",
"joi validation rules",
"validatorjs validation rules",
"vineJs validation rules",
"vinejs@vine validation rules",
"mysql schema rules",
"postgres schema rules"
],
"author": "Md Tasmidur Rahman <[email protected]> (https://tasmidur.netlify.app)",
"repository": {
Expand Down
8 changes: 1 addition & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ program
.requiredOption('-t, --table <table>', 'Specify the table name')
.action(async (schemaType,cmd) => {
try {
/** TODO:
* .addOption(new Option('-rv, --request-validation [request-validation]', 'The request validation file type').choices([REQUEST_VALIDATION_TYPE_JOI, REQUEST_VALIDATION_TYPE_VALIDATORJS, REQUEST_VALIDATION_TYPE_VINE]))
.option('-f, --request-file <request-file>', 'Specify the request validator file name')
*/
const { table, database, columns = ""} = cmd;
// Parse the options
const options = {
columns: columns.split(',').filter(Boolean),
validationSchemaType: schemaType,
Expand All @@ -56,11 +51,10 @@ program
}
});

// Generate and print documentation for the options
program.on('--help', () => {
console.log('');
console.log('Examples:');
console.log('$ nodeSchema make-rules -t my_table -db mysql -c column1,column2 -st joi');
console.log('$ ndVr joi -t my_table -db mysql -c column1,column2');
});

// Parse the command line arguments
Expand Down

0 comments on commit d044bd7

Please sign in to comment.