@decaf-ts/decorator-validation 1.0.7
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/LICENSE.md +21 -0
- package/README.md +302 -0
- package/dist/decorator-validation.bundle.min.js +2 -0
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +14 -0
- package/dist/esm/decorator-validation.bundle.min.esm.js +2 -0
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +14 -0
- package/lib/esm/index.d.ts +61 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/model/Model.d.ts +160 -0
- package/lib/esm/model/Model.js +1 -0
- package/lib/esm/model/ModelErrorDefinition.d.ts +22 -0
- package/lib/esm/model/ModelErrorDefinition.js +3 -0
- package/lib/esm/model/Registry.d.ts +61 -0
- package/lib/esm/model/Registry.js +1 -0
- package/lib/esm/model/constants.d.ts +40 -0
- package/lib/esm/model/constants.js +1 -0
- package/lib/esm/model/construction.d.ts +45 -0
- package/lib/esm/model/construction.js +1 -0
- package/lib/esm/model/decorators.d.ts +33 -0
- package/lib/esm/model/decorators.js +1 -0
- package/lib/esm/model/index.d.ts +7 -0
- package/lib/esm/model/index.js +1 -0
- package/lib/esm/model/types.d.ts +67 -0
- package/lib/esm/model/types.js +0 -0
- package/lib/esm/utils/constants.d.ts +22 -0
- package/lib/esm/utils/constants.js +1 -0
- package/lib/esm/utils/general.d.ts +193 -0
- package/lib/esm/utils/general.js +1 -0
- package/lib/esm/utils/index.d.ts +4 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/registry.d.ts +68 -0
- package/lib/esm/utils/registry.js +0 -0
- package/lib/esm/utils/serialization.d.ts +65 -0
- package/lib/esm/utils/serialization.js +1 -0
- package/lib/esm/validation/Validation.d.ts +39 -0
- package/lib/esm/validation/Validation.js +1 -0
- package/lib/esm/validation/Validators/DateValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/DateValidator.js +1 -0
- package/lib/esm/validation/Validators/EmailValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/EmailValidator.js +1 -0
- package/lib/esm/validation/Validators/ListValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/ListValidator.js +1 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +30 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.js +1 -0
- package/lib/esm/validation/Validators/MaxValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/MaxValidator.js +1 -0
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +30 -0
- package/lib/esm/validation/Validators/MinLengthValidator.js +1 -0
- package/lib/esm/validation/Validators/MinValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/MinValidator.js +1 -0
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +31 -0
- package/lib/esm/validation/Validators/PasswordValidator.js +1 -0
- package/lib/esm/validation/Validators/PatternValidator.d.ts +38 -0
- package/lib/esm/validation/Validators/PatternValidator.js +1 -0
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +28 -0
- package/lib/esm/validation/Validators/RequiredValidator.js +1 -0
- package/lib/esm/validation/Validators/StepValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/StepValidator.js +1 -0
- package/lib/esm/validation/Validators/TypeValidator.d.ts +28 -0
- package/lib/esm/validation/Validators/TypeValidator.js +1 -0
- package/lib/esm/validation/Validators/URLValidator.d.ts +28 -0
- package/lib/esm/validation/Validators/URLValidator.js +1 -0
- package/lib/esm/validation/Validators/Validator.d.ts +42 -0
- package/lib/esm/validation/Validators/Validator.js +1 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +47 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +1 -0
- package/lib/esm/validation/Validators/constants.d.ts +91 -0
- package/lib/esm/validation/Validators/constants.js +1 -0
- package/lib/esm/validation/Validators/index.d.ts +50 -0
- package/lib/esm/validation/Validators/index.js +1 -0
- package/lib/esm/validation/Validators/types.d.ts +51 -0
- package/lib/esm/validation/Validators/types.js +0 -0
- package/lib/esm/validation/decorators.d.ts +263 -0
- package/lib/esm/validation/decorators.js +1 -0
- package/lib/esm/validation/index.d.ts +13 -0
- package/lib/esm/validation/index.js +1 -0
- package/lib/esm/validation/types.d.ts +53 -0
- package/lib/esm/validation/types.js +0 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.ts +61 -0
- package/lib/model/Model.cjs +1 -0
- package/lib/model/Model.d.ts +160 -0
- package/lib/model/ModelErrorDefinition.cjs +3 -0
- package/lib/model/ModelErrorDefinition.d.ts +22 -0
- package/lib/model/Registry.cjs +1 -0
- package/lib/model/Registry.d.ts +61 -0
- package/lib/model/constants.cjs +1 -0
- package/lib/model/constants.d.ts +40 -0
- package/lib/model/construction.cjs +1 -0
- package/lib/model/construction.d.ts +45 -0
- package/lib/model/decorators.cjs +1 -0
- package/lib/model/decorators.d.ts +33 -0
- package/lib/model/index.cjs +1 -0
- package/lib/model/index.d.ts +7 -0
- package/lib/model/types.cjs +1 -0
- package/lib/model/types.d.ts +67 -0
- package/lib/utils/constants.cjs +1 -0
- package/lib/utils/constants.d.ts +22 -0
- package/lib/utils/general.cjs +1 -0
- package/lib/utils/general.d.ts +193 -0
- package/lib/utils/index.cjs +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/registry.cjs +1 -0
- package/lib/utils/registry.d.ts +68 -0
- package/lib/utils/serialization.cjs +1 -0
- package/lib/utils/serialization.d.ts +65 -0
- package/lib/validation/Validation.cjs +1 -0
- package/lib/validation/Validation.d.ts +39 -0
- package/lib/validation/Validators/DateValidator.cjs +1 -0
- package/lib/validation/Validators/DateValidator.d.ts +29 -0
- package/lib/validation/Validators/EmailValidator.cjs +1 -0
- package/lib/validation/Validators/EmailValidator.d.ts +29 -0
- package/lib/validation/Validators/ListValidator.cjs +1 -0
- package/lib/validation/Validators/ListValidator.d.ts +29 -0
- package/lib/validation/Validators/MaxLengthValidator.cjs +1 -0
- package/lib/validation/Validators/MaxLengthValidator.d.ts +30 -0
- package/lib/validation/Validators/MaxValidator.cjs +1 -0
- package/lib/validation/Validators/MaxValidator.d.ts +29 -0
- package/lib/validation/Validators/MinLengthValidator.cjs +1 -0
- package/lib/validation/Validators/MinLengthValidator.d.ts +30 -0
- package/lib/validation/Validators/MinValidator.cjs +1 -0
- package/lib/validation/Validators/MinValidator.d.ts +29 -0
- package/lib/validation/Validators/PasswordValidator.cjs +1 -0
- package/lib/validation/Validators/PasswordValidator.d.ts +31 -0
- package/lib/validation/Validators/PatternValidator.cjs +1 -0
- package/lib/validation/Validators/PatternValidator.d.ts +38 -0
- package/lib/validation/Validators/RequiredValidator.cjs +1 -0
- package/lib/validation/Validators/RequiredValidator.d.ts +28 -0
- package/lib/validation/Validators/StepValidator.cjs +1 -0
- package/lib/validation/Validators/StepValidator.d.ts +29 -0
- package/lib/validation/Validators/TypeValidator.cjs +1 -0
- package/lib/validation/Validators/TypeValidator.d.ts +28 -0
- package/lib/validation/Validators/URLValidator.cjs +1 -0
- package/lib/validation/Validators/URLValidator.d.ts +28 -0
- package/lib/validation/Validators/Validator.cjs +1 -0
- package/lib/validation/Validators/Validator.d.ts +42 -0
- package/lib/validation/Validators/ValidatorRegistry.cjs +1 -0
- package/lib/validation/Validators/ValidatorRegistry.d.ts +47 -0
- package/lib/validation/Validators/constants.cjs +1 -0
- package/lib/validation/Validators/constants.d.ts +91 -0
- package/lib/validation/Validators/index.cjs +1 -0
- package/lib/validation/Validators/index.d.ts +50 -0
- package/lib/validation/Validators/types.cjs +1 -0
- package/lib/validation/Validators/types.d.ts +51 -0
- package/lib/validation/decorators.cjs +1 -0
- package/lib/validation/decorators.d.ts +263 -0
- package/lib/validation/index.cjs +1 -0
- package/lib/validation/index.d.ts +13 -0
- package/lib/validation/types.cjs +1 -0
- package/lib/validation/types.d.ts +53 -0
- package/package.json +96 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PatternValidator}from"./PatternValidator";import{DEFAULT_ERROR_MESSAGES,PasswordPatterns,ValidationKeys}from"./constants";class PasswordValidator extends PatternValidator{constructor(r=DEFAULT_ERROR_MESSAGES.PASSWORD,t=PasswordPatterns.CHAR8_ONE_OF_EACH){super(ValidationKeys.PASSWORD,r),this.pattern=t}hasErrors(r,t,a){return super.hasErrors(r,t||this.pattern,a||this.message)}}export{PasswordValidator};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Pattern Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
8
|
+
*
|
|
9
|
+
* @class PatternValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class PatternValidator extends Validator {
|
|
15
|
+
private static readonly regexpParser;
|
|
16
|
+
constructor(key?: string, message?: string);
|
|
17
|
+
/**
|
|
18
|
+
* @summary parses and validates a pattern
|
|
19
|
+
*
|
|
20
|
+
* @param {string} pattern
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private static getPattern;
|
|
24
|
+
/**
|
|
25
|
+
* @summary Validates a Model
|
|
26
|
+
*
|
|
27
|
+
* @param {string} value
|
|
28
|
+
* @param {RegExp | string} pattern
|
|
29
|
+
* @param {string} [message]
|
|
30
|
+
*
|
|
31
|
+
* @return Errors
|
|
32
|
+
*
|
|
33
|
+
* @override
|
|
34
|
+
*
|
|
35
|
+
* @see Validator#hasErrors
|
|
36
|
+
*/
|
|
37
|
+
hasErrors(value: string, pattern: RegExp | string, message?: string): Errors;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class PatternValidator extends Validator{static{this.regexpParser=new RegExp("^/(.+)/([gimus]*)$")}constructor(t=ValidationKeys.PATTERN,r=DEFAULT_ERROR_MESSAGES.PATTERN){super(t,r,"string")}static getPattern(t){var r;return PatternValidator.regexpParser.test(t)?(r=t.match(PatternValidator.regexpParser),new RegExp(r[1],r[2])):new RegExp(t)}hasErrors(t,r,e){if(t)return(r="string"==typeof r?PatternValidator.getPattern(r):r).lastIndex=0,r.test(t)?void 0:this.getMessage(e||this.message)}}export{PatternValidator};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Required Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
7
|
+
*
|
|
8
|
+
* @class RequiredValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class RequiredValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a model
|
|
17
|
+
*
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {string} [message]
|
|
20
|
+
*
|
|
21
|
+
* @return Errors
|
|
22
|
+
*
|
|
23
|
+
* @override
|
|
24
|
+
*
|
|
25
|
+
* @see Validator#hasErrors
|
|
26
|
+
*/
|
|
27
|
+
hasErrors(value: any, message?: string): Errors;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class RequiredValidator extends Validator{constructor(e=DEFAULT_ERROR_MESSAGES.REQUIRED){super(ValidationKeys.REQUIRED,e)}hasErrors(e,s){switch(typeof e){case"boolean":case"number":return void 0===e?this.getMessage(s||this.message):void 0;default:return e?void 0:this.getMessage(s||this.message)}}}export{RequiredValidator};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Step Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
7
|
+
*
|
|
8
|
+
* @class StepValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class StepValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a model
|
|
17
|
+
*
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {number} step
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: number | string, step: number | string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class StepValidator extends Validator{constructor(r=DEFAULT_ERROR_MESSAGES.STEP){super(ValidationKeys.STEP,r,"number","string")}hasErrors(r,t,a){return void 0!==r&&Number(r)%Number(t)!=0?this.getMessage(a||this.message,t):void 0}}export{StepValidator};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Errors } from "../types";
|
|
2
|
+
import { Validator } from "./Validator";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Required Validator
|
|
5
|
+
*
|
|
6
|
+
* @class RequiredValidator
|
|
7
|
+
* @extends Validator
|
|
8
|
+
*
|
|
9
|
+
* @category Validators
|
|
10
|
+
*/
|
|
11
|
+
export declare class TypeValidator extends Validator {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
/**
|
|
14
|
+
* @summary Validates a model
|
|
15
|
+
* @param {string} value
|
|
16
|
+
* @param {string | string[] | {name: string}} types
|
|
17
|
+
* @param {string} [message]
|
|
18
|
+
*
|
|
19
|
+
* @return Errors
|
|
20
|
+
*
|
|
21
|
+
* @override
|
|
22
|
+
*
|
|
23
|
+
* @see Validator#hasErrors
|
|
24
|
+
*/
|
|
25
|
+
hasErrors(value: any, types: string | string[] | {
|
|
26
|
+
name: string;
|
|
27
|
+
}, message?: string): Errors;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{evaluateDesignTypes}from"../../utils";import{DEFAULT_ERROR_MESSAGES}from"./constants";import{ModelKeys}from"../../utils/constants";class TypeValidator extends Validator{constructor(t=DEFAULT_ERROR_MESSAGES.TYPE){super(ModelKeys.TYPE,t)}hasErrors(t,e,r){return void 0===t||evaluateDesignTypes(t,e)?void 0:this.getMessage(r||this.message,"string"==typeof e?e:Array.isArray(e)?e.join(", "):e.name,typeof t)}}export{TypeValidator};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Errors } from "../types";
|
|
2
|
+
import { PatternValidator } from "./PatternValidator";
|
|
3
|
+
/**
|
|
4
|
+
* @summary URL Validator
|
|
5
|
+
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
6
|
+
*
|
|
7
|
+
* @class URLValidator
|
|
8
|
+
* @extends PatternValidator
|
|
9
|
+
*
|
|
10
|
+
* @category Validators
|
|
11
|
+
*/
|
|
12
|
+
export declare class URLValidator extends PatternValidator {
|
|
13
|
+
private static readonly urlPattern;
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a model
|
|
17
|
+
*
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {string} [message]
|
|
20
|
+
*
|
|
21
|
+
* @return Errors
|
|
22
|
+
*
|
|
23
|
+
* @override
|
|
24
|
+
*
|
|
25
|
+
* @see Validator#hasErrors
|
|
26
|
+
*/
|
|
27
|
+
hasErrors(value: string, message?: string): Errors;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";import{PatternValidator}from"./PatternValidator";class URLValidator extends PatternValidator{static{this.urlPattern=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i}constructor(a=DEFAULT_ERROR_MESSAGES.URL){super(ValidationKeys.URL,a)}hasErrors(a,t){return super.hasErrors(a,URLValidator.urlPattern,t)}}export{URLValidator};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Errors } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Base Implementation for Validators
|
|
4
|
+
* @description Provides the underlying functionality for {@link Validator}s
|
|
5
|
+
*
|
|
6
|
+
* @param {string} validationKey the key to register the validator under
|
|
7
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT}
|
|
8
|
+
* @param {string[]} [acceptedTypes] defines the value types this validator can validate
|
|
9
|
+
*
|
|
10
|
+
* @class Validator
|
|
11
|
+
* @abstract
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class Validator {
|
|
15
|
+
readonly validationKey: string;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly acceptedTypes?: string[];
|
|
18
|
+
protected constructor(validationKey: string, message?: string, ...acceptedTypes: string[]);
|
|
19
|
+
/**
|
|
20
|
+
* @summary builds the error message
|
|
21
|
+
* @param {string} message
|
|
22
|
+
* @param {any[]} args
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
protected getMessage(message: string, ...args: any[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* @summary Validates type
|
|
28
|
+
* @param {any} unbound
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private checkTypeAndHasErrors;
|
|
32
|
+
/**
|
|
33
|
+
* @summary Validates an attribute
|
|
34
|
+
* @param {any} value
|
|
35
|
+
* @param {any[]} args
|
|
36
|
+
*
|
|
37
|
+
* @abstract
|
|
38
|
+
*
|
|
39
|
+
* @see Model#hasErrors
|
|
40
|
+
*/
|
|
41
|
+
abstract hasErrors(value: any, ...args: any[]): Errors;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{checkTypes,stringFormat}from"../../utils";import{DEFAULT_ERROR_MESSAGES}from"./constants";class Validator{constructor(s,t=DEFAULT_ERROR_MESSAGES.DEFAULT,...e){this.validationKey=s,this.message=t,e.length&&(this.acceptedTypes=e),this.acceptedTypes&&(this.hasErrors=this.checkTypeAndHasErrors(this.hasErrors.bind(this)))}getMessage(s,...t){return stringFormat(s,...t)}checkTypeAndHasErrors(e){return function(s,...t){return void 0===s||!this.acceptedTypes||checkTypes(s,this.acceptedTypes)?e(s,...t):this.getMessage(DEFAULT_ERROR_MESSAGES.TYPE,this.acceptedTypes.join(", "),typeof s)}.bind(this)}}export{Validator};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ValidatorDefinition } from "./types";
|
|
2
|
+
import { IValidatorRegistry } from "./types";
|
|
3
|
+
import type { Validator } from "./Validator";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Duck typing for Validators
|
|
6
|
+
* @function isValidator
|
|
7
|
+
* @param val
|
|
8
|
+
*/
|
|
9
|
+
export declare function isValidator(val: any): any;
|
|
10
|
+
/**
|
|
11
|
+
* @summary Base Implementation of a Validator Registry
|
|
12
|
+
*
|
|
13
|
+
* @prop {Validator[]} [validators] the initial validators to register
|
|
14
|
+
*
|
|
15
|
+
* @class ValidatorRegistry
|
|
16
|
+
* @implements IValidatorRegistry<T>
|
|
17
|
+
*
|
|
18
|
+
* @category Validation
|
|
19
|
+
*/
|
|
20
|
+
export declare class ValidatorRegistry<T extends Validator> implements IValidatorRegistry<T> {
|
|
21
|
+
private cache;
|
|
22
|
+
private customKeyChache;
|
|
23
|
+
constructor(...validators: (ValidatorDefinition | Validator)[]);
|
|
24
|
+
/**
|
|
25
|
+
* @summary retrieves the custom keys
|
|
26
|
+
*/
|
|
27
|
+
getCustomKeys(): {
|
|
28
|
+
[indexer: string]: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* @summary retrieves the registered validators keys
|
|
32
|
+
*/
|
|
33
|
+
getKeys(): string[];
|
|
34
|
+
/**
|
|
35
|
+
* @summary Retrieves a validator
|
|
36
|
+
*
|
|
37
|
+
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
38
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
39
|
+
*/
|
|
40
|
+
get<T extends Validator>(validatorKey: string): T | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* @summary Registers the provided validators onto the registry
|
|
43
|
+
*
|
|
44
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
45
|
+
*/
|
|
46
|
+
register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function isValidator(t){return t.constructor&&t.hasErrors}class ValidatorRegistry{constructor(...t){this.cache={},this.customKeyChache={},this.register(...t)}getCustomKeys(){return Object.assign({},this.customKeyChache)}getKeys(){return Object.keys(this.cache)}get(t){var e;if(t in this.cache)return isValidator(e=this.cache[t])?e:(e=new(e.default||e),this.cache[t]=e)}register(...t){t.forEach(t=>{var e,a;isValidator(t)?t.validationKey in this.cache||(this.cache[t.validationKey]=t):({validationKey:t,validator:a,save:e}=t,t in this.cache||(this.cache[t]=a,e&&((a={})[t.toUpperCase()]=t,this.customKeyChache=Object.assign({},this.customKeyChache,a))))})}}export{isValidator,ValidatorRegistry};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary The keys used for validation
|
|
3
|
+
*
|
|
4
|
+
* @property {string} REFLECT prefixes others
|
|
5
|
+
* @property {string} REQUIRED sets as required
|
|
6
|
+
* @property {string} MIN defines min value
|
|
7
|
+
* @property {string} MAX defines max value
|
|
8
|
+
* @property {string} STEP defines step
|
|
9
|
+
* @property {string} MIN_LENGTH defines min length
|
|
10
|
+
* @property {string} MAX_LENGTH defines max length
|
|
11
|
+
* @property {string} PATTERN defines pattern
|
|
12
|
+
* @property {string} EMAIL defines email
|
|
13
|
+
* @property {string} URL defines url
|
|
14
|
+
* @property {string} DATE defines date
|
|
15
|
+
* @property {string} TYPE defines type
|
|
16
|
+
* @property {string} PASSWORD defines password
|
|
17
|
+
* @property {string} LIST defines list
|
|
18
|
+
*
|
|
19
|
+
* @constant ValidationKeys
|
|
20
|
+
* @memberOf module:decorator-validation.Validation
|
|
21
|
+
* @category Validation
|
|
22
|
+
*/
|
|
23
|
+
export declare const ValidationKeys: {
|
|
24
|
+
REFLECT: string;
|
|
25
|
+
REQUIRED: string;
|
|
26
|
+
MIN: string;
|
|
27
|
+
MAX: string;
|
|
28
|
+
STEP: string;
|
|
29
|
+
MIN_LENGTH: string;
|
|
30
|
+
MAX_LENGTH: string;
|
|
31
|
+
PATTERN: string;
|
|
32
|
+
EMAIL: string;
|
|
33
|
+
URL: string;
|
|
34
|
+
DATE: string;
|
|
35
|
+
TYPE: string;
|
|
36
|
+
PASSWORD: string;
|
|
37
|
+
LIST: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @summary list of month names
|
|
41
|
+
* @description Stores month names. Can be changed for localization purposes
|
|
42
|
+
*
|
|
43
|
+
* @constant MONTH_NAMES
|
|
44
|
+
* @memberOf module:decorator-validation.Validation
|
|
45
|
+
* @category Validation
|
|
46
|
+
*/
|
|
47
|
+
export declare const MONTH_NAMES: string[];
|
|
48
|
+
/**
|
|
49
|
+
* @summary list of names of days of the week
|
|
50
|
+
* @description Stores names for days of the week. Can be changed for localization purposes
|
|
51
|
+
*
|
|
52
|
+
* @constant DAYS_OF_WEEK_NAMES
|
|
53
|
+
* @memberOf module:decorator-validation.Validation
|
|
54
|
+
* @category Validation
|
|
55
|
+
*/
|
|
56
|
+
export declare const DAYS_OF_WEEK_NAMES: string[];
|
|
57
|
+
/**
|
|
58
|
+
* @summary Defines the default error messages
|
|
59
|
+
*
|
|
60
|
+
* @property {string} REQUIRED default error message
|
|
61
|
+
* @property {string} MIN default error message
|
|
62
|
+
* @property {string} MAX default error message
|
|
63
|
+
* @property {string} MIN_LENGTH default error message
|
|
64
|
+
* @property {string} MAX_LENGTH default error message
|
|
65
|
+
* @property {string} PATTERN default error message
|
|
66
|
+
* @property {string} EMAIL default error message
|
|
67
|
+
* @property {string} URL default error message
|
|
68
|
+
* @property {string} TYPE default error message
|
|
69
|
+
* @property {string} STEP default error message
|
|
70
|
+
* @property {string} DATE default error message
|
|
71
|
+
* @property {string} DEFAULT default error message
|
|
72
|
+
* @property {string} PASSWORD default error message
|
|
73
|
+
* @property {string} LIST default error message
|
|
74
|
+
* @property {string} LIST_INSIDE default error message
|
|
75
|
+
* @property {string} MODEL_NOT_FOUND default error message
|
|
76
|
+
*
|
|
77
|
+
* @constant DEFAULT_ERROR_MESSAGES
|
|
78
|
+
* @memberOf module:decorator-validation.Validation
|
|
79
|
+
* @category Validation
|
|
80
|
+
*/
|
|
81
|
+
export declare const DEFAULT_ERROR_MESSAGES: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* @summary Defines a Password validation regexp
|
|
84
|
+
*
|
|
85
|
+
* @enum DEFAULT_ERROR_MESSAGES
|
|
86
|
+
* @memberOf module:decorator-validation.Validation
|
|
87
|
+
* @category Validation
|
|
88
|
+
*/
|
|
89
|
+
export declare const PasswordPatterns: {
|
|
90
|
+
CHAR8_ONE_OF_EACH: RegExp;
|
|
91
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const ValidationKeys={REFLECT:"model.validation.",REQUIRED:"required",MIN:"min",MAX:"max",STEP:"step",MIN_LENGTH:"minlength",MAX_LENGTH:"maxlength",PATTERN:"pattern",EMAIL:"email",URL:"url",DATE:"date",TYPE:"type",PASSWORD:"password",LIST:"list"},MONTH_NAMES=["January","February","March","April","May","June","July","August","September","October","November","December"],DAYS_OF_WEEK_NAMES=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],DEFAULT_ERROR_MESSAGES={REQUIRED:"This field is required",MIN:"The minimum value is {0}",MAX:"The maximum value is {0}",MIN_LENGTH:"The minimum length is {0}",MAX_LENGTH:"The maximum length is {0}",PATTERN:"The value does not match the pattern",EMAIL:"The value is not a valid email",URL:"The value is not a valid URL",TYPE:"Invalid type. Expected {0}, received {1}",STEP:"Invalid value. Not a step of {0}",DATE:"Invalid value. not a valid Date",DEFAULT:"There is an Error",PASSWORD:"Must be at least 8 characters and contain one of number, lower and upper case letters, and special character (@$!%*?&_-.,)",LIST:"Invalid list of {0}",LIST_INSIDE:"Elements of list are invalid: {0}",MODEL_NOT_FOUND:"No model registered under {0}"},PasswordPatterns={CHAR8_ONE_OF_EACH:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&_\-.,])[A-Za-z\d@$!%*?&_\-.,]{8,}$/g};export{ValidationKeys,MONTH_NAMES,DAYS_OF_WEEK_NAMES,DEFAULT_ERROR_MESSAGES,PasswordPatterns};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DateValidator } from "./DateValidator";
|
|
2
|
+
import { TypeValidator } from "./TypeValidator";
|
|
3
|
+
import { PasswordValidator } from "./PasswordValidator";
|
|
4
|
+
import { StepValidator } from "./StepValidator";
|
|
5
|
+
import { URLValidator } from "./URLValidator";
|
|
6
|
+
import { PatternValidator } from "./PatternValidator";
|
|
7
|
+
import { MinValidator } from "./MinValidator";
|
|
8
|
+
import { MinLengthValidator } from "./MinLengthValidator";
|
|
9
|
+
import { MaxValidator } from "./MaxValidator";
|
|
10
|
+
import { MaxLengthValidator } from "./MaxLengthValidator";
|
|
11
|
+
import { RequiredValidator } from "./RequiredValidator";
|
|
12
|
+
import { EmailValidator } from "./EmailValidator";
|
|
13
|
+
import { ListValidator } from "./ListValidator";
|
|
14
|
+
export * from "./constants";
|
|
15
|
+
export * from "./Validator";
|
|
16
|
+
export * from "./types";
|
|
17
|
+
export * from "./ValidatorRegistry";
|
|
18
|
+
export * from "./EmailValidator";
|
|
19
|
+
export * from "./RequiredValidator";
|
|
20
|
+
export * from "./MaxLengthValidator";
|
|
21
|
+
export * from "./MaxValidator";
|
|
22
|
+
export * from "./MinLengthValidator";
|
|
23
|
+
export * from "./MinValidator";
|
|
24
|
+
export * from "./PatternValidator";
|
|
25
|
+
export * from "./URLValidator";
|
|
26
|
+
export * from "./StepValidator";
|
|
27
|
+
export * from "./DateValidator";
|
|
28
|
+
export * from "./TypeValidator";
|
|
29
|
+
export * from "./PasswordValidator";
|
|
30
|
+
/**
|
|
31
|
+
* @summary constant holding all {@link Validator}s
|
|
32
|
+
* @constant Validators
|
|
33
|
+
* @memberOf module:decorator-validation.Validation.Validators
|
|
34
|
+
* @category Validation
|
|
35
|
+
*/
|
|
36
|
+
export declare const Validators: {
|
|
37
|
+
EmailValidator: typeof EmailValidator;
|
|
38
|
+
RequiredValidator: typeof RequiredValidator;
|
|
39
|
+
MaxLengthValidator: typeof MaxLengthValidator;
|
|
40
|
+
MaxValidator: typeof MaxValidator;
|
|
41
|
+
MinLengthValidator: typeof MinLengthValidator;
|
|
42
|
+
MinValidator: typeof MinValidator;
|
|
43
|
+
PatternValidator: typeof PatternValidator;
|
|
44
|
+
URLValidator: typeof URLValidator;
|
|
45
|
+
StepValidator: typeof StepValidator;
|
|
46
|
+
DateValidator: typeof DateValidator;
|
|
47
|
+
TypeValidator: typeof TypeValidator;
|
|
48
|
+
PasswordValidator: typeof PasswordValidator;
|
|
49
|
+
ListValidator: typeof ListValidator;
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DateValidator}from"./DateValidator";import{TypeValidator}from"./TypeValidator";import{PasswordValidator}from"./PasswordValidator";import{StepValidator}from"./StepValidator";import{URLValidator}from"./URLValidator";import{PatternValidator}from"./PatternValidator";import{MinValidator}from"./MinValidator";import{MinLengthValidator}from"./MinLengthValidator";import{MaxValidator}from"./MaxValidator";import{MaxLengthValidator}from"./MaxLengthValidator";import{RequiredValidator}from"./RequiredValidator";import{EmailValidator}from"./EmailValidator";import{ListValidator}from"./ListValidator";export*from"./constants";export*from"./Validator";export*from"./types";export*from"./ValidatorRegistry";export*from"./EmailValidator";export*from"./RequiredValidator";export*from"./MaxLengthValidator";export*from"./MaxValidator";export*from"./MinLengthValidator";export*from"./MinValidator";export*from"./PatternValidator";export*from"./URLValidator";export*from"./StepValidator";export*from"./DateValidator";export*from"./TypeValidator";export*from"./PasswordValidator";const Validators={EmailValidator:EmailValidator,RequiredValidator:RequiredValidator,MaxLengthValidator:MaxLengthValidator,MaxValidator:MaxValidator,MinLengthValidator:MinLengthValidator,MinValidator:MinValidator,PatternValidator:PatternValidator,URLValidator:URLValidator,StepValidator:StepValidator,DateValidator:DateValidator,TypeValidator:TypeValidator,PasswordValidator:PasswordValidator,ListValidator:ListValidator};export{Validators};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { IRegistry } from "../../utils";
|
|
3
|
+
import { Constructor } from "../../model";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Util type for {@link Validator} configuration
|
|
6
|
+
* @memberOf module:decorator-validation.Validation
|
|
7
|
+
* @category Validation
|
|
8
|
+
*/
|
|
9
|
+
export type ValidatorDefinition = {
|
|
10
|
+
validator: Constructor<Validator>;
|
|
11
|
+
validationKey: string;
|
|
12
|
+
save: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @summary Base API for a {@link Validator} registry
|
|
16
|
+
*
|
|
17
|
+
* @interface ValidatorRegistry
|
|
18
|
+
* @extends IRegistry
|
|
19
|
+
*
|
|
20
|
+
* @category Validation
|
|
21
|
+
*/
|
|
22
|
+
export interface IValidatorRegistry<T extends Validator> extends IRegistry<T> {
|
|
23
|
+
/**
|
|
24
|
+
* @summary retrieves the custom keys
|
|
25
|
+
* @method
|
|
26
|
+
*/
|
|
27
|
+
getCustomKeys(): Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* @summary Retrieves the Registered validator keys
|
|
30
|
+
* @return {string[]} the registered validators keys
|
|
31
|
+
* @method
|
|
32
|
+
*/
|
|
33
|
+
getKeys(): string[];
|
|
34
|
+
/**
|
|
35
|
+
* @summary Registers the provided validators onto the registry
|
|
36
|
+
*
|
|
37
|
+
* @typedef T extends Validator
|
|
38
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
39
|
+
* @method
|
|
40
|
+
*/
|
|
41
|
+
register<T extends Validator>(...validator: (T | ValidatorDefinition)[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* @summary Retrieves the Validator constructor if registered
|
|
44
|
+
*
|
|
45
|
+
* @typedef T extends Validator
|
|
46
|
+
* @param {string} key one of the {@link ValidationKeys}
|
|
47
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
48
|
+
* @method
|
|
49
|
+
*/
|
|
50
|
+
get<T extends Validator>(key: string): T | undefined;
|
|
51
|
+
}
|
|
File without changes
|