generated from AthennaIO/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from AthennaIO/develop
feat(validator): add custom exists rule
- Loading branch information
Showing
16 changed files
with
666 additions
and
149 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@athenna/validator", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"description": "The Athenna validation solution. Built on top of VineJS.", | ||
"license": "MIT", | ||
"author": "João Lenon <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { ExtendHandlerType } from '#src/types' | ||
import type { ValidatorImpl } from '#src/validator/ValidatorImpl' | ||
|
||
export type ExtendReturnType = { | ||
/** | ||
* Extend error messages of all your validations. This method | ||
* doesn't save past extends, which means that if you call | ||
* it twice, only the second one will be respected. | ||
* | ||
* ```ts | ||
* Validate.extend().messages({ | ||
* // Applicable for all fields | ||
* 'required': 'The {{ field }} field is required', | ||
* 'string': 'The value of {{ field }} field must be a string', | ||
* 'email': 'The value is not a valid email address', | ||
* | ||
* // Error message only for the username field | ||
* 'username.required': 'Please choose a username for your account' | ||
* }) | ||
* ``` | ||
*/ | ||
messages: (messages: Record<string, string>) => ValidatorImpl | ||
accepted: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
date: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
record: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
tuple: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
literal: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
array: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
any: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
string: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
number: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
enum: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
boolean: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
object: (name: string, handler: ExtendHandlerType) => ValidatorImpl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @athenna/validator | ||
* | ||
* (c) João Lenon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
export type ExistsOptions = { | ||
/** | ||
* The table where the database will lookup for the data. | ||
*/ | ||
table: string | ||
|
||
/** | ||
* The column name in database. If not defined, the name | ||
* of the field in the schema will be used. | ||
* | ||
* @default 'fieldNameInYourSchema' | ||
*/ | ||
column?: string | ||
|
||
/** | ||
* Use the min field to stablish a min limit for your validation. | ||
* In some cases in your database you might have a min of 10 tuples | ||
* with the same data. Use this option to validate that the number | ||
* of fields registered in database needs to be the same or bigger | ||
* than the number defined on this option. | ||
* | ||
* @example | ||
* ```ts | ||
* const schema = this.validator.object({ | ||
* name: this.validator.string().exists({ table: 'users', min: 10 }) | ||
* }) | ||
* | ||
* const data = { name: 'lenon' } | ||
* | ||
* // Will throw if there aren't 10 users with name `lenon` | ||
* // created in database | ||
* await this.validator.validate({ schema: this.schema, data }) | ||
* ``` | ||
* @default undefined | ||
*/ | ||
min?: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @athenna/validator | ||
* | ||
* (c) João Lenon <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
export type UniqueOptions = { | ||
/** | ||
* The table where the database will lookup for the data. | ||
*/ | ||
table: string | ||
|
||
/** | ||
* The column name in database. If not defined, the name | ||
* of the field in the schema will be used. | ||
* | ||
* @default 'fieldNameInYourSchema' | ||
*/ | ||
column?: string | ||
|
||
/** | ||
* Use the max field to stablish a max limit for your validation. | ||
* In some cases in your database you might have a max of 10 tuples | ||
* with the same data. Use this option to validate that the number | ||
* of fields registered in database cannot be bigger than the number | ||
* defined on this option. | ||
* | ||
* @example | ||
* ```ts | ||
* const schema = this.validator.object({ | ||
* name: this.validator.string().unique({ table: 'users', max: 10 }) | ||
* }) | ||
* | ||
* const data = { name: 'lenon' } | ||
* | ||
* // Will throw if there are 10 users with name `lenon` | ||
* // created in database | ||
* await this.validator.validate({ schema: this.schema, data }) | ||
* ``` | ||
* @default undefined | ||
*/ | ||
max?: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.