@decaf-ts/decorator-validation 1.5.9 → 1.5.10
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 +0 -0
- package/README.md +0 -0
- package/dist/decorator-validation.js +2 -0
- package/dist/{decorator-validation.bundle.min.js.LICENSE.txt → decorator-validation.js.LICENSE.txt} +0 -0
- package/dist/esm/decorator-validation.js +2 -0
- package/dist/esm/{decorator-validation.bundle.min.esm.js.LICENSE.txt → decorator-validation.js.LICENSE.txt} +0 -0
- package/{lib/esm → dist/types}/index.d.ts +1 -1
- package/{lib/esm → dist/types}/model/Model.d.ts +0 -0
- package/{lib/esm → dist/types}/model/ModelErrorDefinition.d.ts +0 -0
- package/{lib/esm → dist/types}/model/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/model/construction.d.ts +0 -0
- package/{lib/esm → dist/types}/model/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/model/index.d.ts +0 -0
- package/{lib/esm → dist/types}/model/types.d.ts +0 -0
- package/{lib/esm → dist/types}/model/validation.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/dates.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/hashing.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/index.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/registry.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/serialization.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/strings.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/types.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validation.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/DateValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/EmailValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/ListValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MaxLengthValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MaxValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MinLengthValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MinValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/PasswordValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/PatternValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/RequiredValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/StepValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/TypeValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/URLValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/Validator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/decorators.d.ts +0 -0
- package/dist/types/validation/Validators/index.d.ts +17 -0
- package/{lib/esm → dist/types}/validation/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/index.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/types.d.ts +0 -0
- package/lib/esm/index.js +3 -1
- package/lib/esm/model/Model.js +2 -0
- package/lib/esm/model/ModelErrorDefinition.js +2 -0
- package/lib/esm/model/constants.js +2 -0
- package/lib/esm/model/construction.js +2 -0
- package/lib/esm/model/decorators.js +2 -0
- package/lib/esm/model/index.js +2 -0
- package/lib/esm/model/types.js +2 -0
- package/lib/esm/model/validation.js +2 -0
- package/lib/esm/utils/constants.js +2 -0
- package/lib/esm/utils/dates.js +2 -0
- package/lib/esm/utils/decorators.js +2 -0
- package/lib/esm/utils/hashing.js +2 -0
- package/lib/esm/utils/index.js +2 -0
- package/lib/esm/utils/registry.js +2 -0
- package/lib/esm/utils/serialization.js +2 -0
- package/lib/esm/utils/strings.js +2 -0
- package/lib/esm/utils/types.js +2 -0
- package/lib/esm/validation/Validation.js +2 -0
- package/lib/esm/validation/Validators/DateValidator.js +2 -0
- package/lib/esm/validation/Validators/EmailValidator.js +2 -0
- package/lib/esm/validation/Validators/ListValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxValidator.js +2 -0
- package/lib/esm/validation/Validators/MinLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MinValidator.js +2 -0
- package/lib/esm/validation/Validators/PasswordValidator.js +2 -0
- package/lib/esm/validation/Validators/PatternValidator.js +2 -0
- package/lib/esm/validation/Validators/RequiredValidator.js +2 -0
- package/lib/esm/validation/Validators/StepValidator.js +2 -0
- package/lib/esm/validation/Validators/TypeValidator.js +2 -0
- package/lib/esm/validation/Validators/URLValidator.js +2 -0
- package/lib/esm/validation/Validators/Validator.js +2 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +2 -0
- package/lib/esm/validation/Validators/constants.js +2 -0
- package/lib/esm/validation/Validators/decorators.js +2 -0
- package/lib/esm/validation/Validators/index.js +2 -34
- package/lib/esm/validation/decorators.js +2 -0
- package/lib/esm/validation/index.js +2 -0
- package/lib/esm/validation/types.js +2 -0
- package/lib/index.cjs +3 -1
- package/lib/model/Model.cjs +2 -0
- package/lib/model/ModelErrorDefinition.cjs +2 -0
- package/lib/model/constants.cjs +2 -0
- package/lib/model/construction.cjs +2 -0
- package/lib/model/decorators.cjs +2 -0
- package/lib/model/index.cjs +2 -0
- package/lib/model/types.cjs +2 -0
- package/lib/model/validation.cjs +2 -0
- package/lib/utils/constants.cjs +2 -0
- package/lib/utils/dates.cjs +2 -0
- package/lib/utils/decorators.cjs +2 -0
- package/lib/utils/hashing.cjs +2 -0
- package/lib/utils/index.cjs +2 -0
- package/lib/utils/registry.cjs +2 -0
- package/lib/utils/serialization.cjs +2 -0
- package/lib/utils/strings.cjs +2 -0
- package/lib/utils/types.cjs +2 -0
- package/lib/validation/Validation.cjs +2 -0
- package/lib/validation/Validators/DateValidator.cjs +2 -0
- package/lib/validation/Validators/EmailValidator.cjs +2 -0
- package/lib/validation/Validators/ListValidator.cjs +2 -0
- package/lib/validation/Validators/MaxLengthValidator.cjs +2 -0
- package/lib/validation/Validators/MaxValidator.cjs +2 -0
- package/lib/validation/Validators/MinLengthValidator.cjs +2 -0
- package/lib/validation/Validators/MinValidator.cjs +2 -0
- package/lib/validation/Validators/PasswordValidator.cjs +2 -0
- package/lib/validation/Validators/PatternValidator.cjs +2 -0
- package/lib/validation/Validators/RequiredValidator.cjs +2 -0
- package/lib/validation/Validators/StepValidator.cjs +2 -0
- package/lib/validation/Validators/TypeValidator.cjs +2 -0
- package/lib/validation/Validators/URLValidator.cjs +2 -0
- package/lib/validation/Validators/Validator.cjs +2 -0
- package/lib/validation/Validators/ValidatorRegistry.cjs +2 -0
- package/lib/validation/Validators/constants.cjs +2 -0
- package/lib/validation/Validators/decorators.cjs +2 -0
- package/lib/validation/Validators/index.cjs +2 -35
- package/lib/validation/decorators.cjs +2 -0
- package/lib/validation/index.cjs +2 -0
- package/lib/validation/types.cjs +2 -0
- package/package.json +2 -2
- package/dist/decorator-validation.bundle.min.js +0 -2
- package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
- package/lib/esm/validation/Validators/index.d.ts +0 -51
- package/lib/index.d.ts +0 -42
- package/lib/model/Model.d.ts +0 -204
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/index.d.ts +0 -7
- package/lib/model/types.d.ts +0 -79
- package/lib/model/validation.d.ts +0 -14
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/hashing.d.ts +0 -38
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/serialization.d.ts +0 -53
- package/lib/utils/strings.d.ts +0 -25
- package/lib/utils/types.d.ts +0 -29
- package/lib/validation/Validation.d.ts +0 -51
- package/lib/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -28
- package/lib/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/validation/Validators/TypeValidator.d.ts +0 -25
- package/lib/validation/Validators/URLValidator.d.ts +0 -27
- package/lib/validation/Validators/Validator.d.ts +0 -41
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.d.ts +0 -134
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Handles Password Validation
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [errorMessage] defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
7
|
-
*
|
|
8
|
-
* @class PasswordValidator
|
|
9
|
-
* @extends PatternValidator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class PasswordValidator extends PatternValidator {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see PatternValidator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
3
|
-
export declare const regexpParser: RegExp;
|
|
4
|
-
/**
|
|
5
|
-
* @summary Pattern Validator
|
|
6
|
-
*
|
|
7
|
-
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
8
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
9
|
-
*
|
|
10
|
-
* @class PatternValidator
|
|
11
|
-
* @extends Validator
|
|
12
|
-
*
|
|
13
|
-
* @category Validators
|
|
14
|
-
*/
|
|
15
|
-
export declare class PatternValidator extends Validator<PatternValidatorOptions> {
|
|
16
|
-
constructor(message?: string);
|
|
17
|
-
/**
|
|
18
|
-
* @summary parses and validates a pattern
|
|
19
|
-
*
|
|
20
|
-
* @param {string} pattern
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
private getPattern;
|
|
24
|
-
/**
|
|
25
|
-
* @summary Validates a Model
|
|
26
|
-
*
|
|
27
|
-
* @param {string} value
|
|
28
|
-
* @param {PatternValidatorOptions} options
|
|
29
|
-
*
|
|
30
|
-
* @return {string | undefined}
|
|
31
|
-
*
|
|
32
|
-
* @override
|
|
33
|
-
*
|
|
34
|
-
* @see Validator#hasErrors
|
|
35
|
-
*/
|
|
36
|
-
hasErrors(value: string, options: PatternValidatorOptions): string | undefined;
|
|
37
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { ValidatorOptions } 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 {ValidatorOptions} [options={}]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: any, options?: ValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { StepValidatorOptions } 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<StepValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {number} step
|
|
20
|
-
* @param {StepValidatorOptions} options
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: number | string, options: StepValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { TypeValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Required Validator
|
|
5
|
-
*
|
|
6
|
-
* @class RequiredValidator
|
|
7
|
-
* @extends Validator
|
|
8
|
-
*
|
|
9
|
-
* @category Validators
|
|
10
|
-
*/
|
|
11
|
-
export declare class TypeValidator extends Validator<TypeValidatorOptions> {
|
|
12
|
-
constructor(message?: string);
|
|
13
|
-
/**
|
|
14
|
-
* @summary Validates a model
|
|
15
|
-
* @param {string} value
|
|
16
|
-
* @param {TypeValidatorOptions} options
|
|
17
|
-
*
|
|
18
|
-
* @return {string | undefined}
|
|
19
|
-
*
|
|
20
|
-
* @override
|
|
21
|
-
*
|
|
22
|
-
* @see Validator#hasErrors
|
|
23
|
-
*/
|
|
24
|
-
hasErrors(value: any, options: TypeValidatorOptions): string | undefined;
|
|
25
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
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
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
19
|
-
*
|
|
20
|
-
* @return {string | undefined}
|
|
21
|
-
*
|
|
22
|
-
* @override
|
|
23
|
-
*
|
|
24
|
-
* @see Validator#hasErrors
|
|
25
|
-
*/
|
|
26
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
27
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ValidatorOptions } 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<V extends ValidatorOptions = ValidatorOptions> {
|
|
15
|
-
readonly message: string;
|
|
16
|
-
readonly acceptedTypes?: string[];
|
|
17
|
-
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
18
|
-
/**
|
|
19
|
-
* @summary builds the error message
|
|
20
|
-
* @param {string} message
|
|
21
|
-
* @param {any[]} args
|
|
22
|
-
* @protected
|
|
23
|
-
*/
|
|
24
|
-
protected getMessage(message: string, ...args: any[]): string;
|
|
25
|
-
/**
|
|
26
|
-
* @summary Validates type
|
|
27
|
-
* @param {any} unbound
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
|
-
private checkTypeAndHasErrors;
|
|
31
|
-
/**
|
|
32
|
-
* @summary Validates an attribute
|
|
33
|
-
* @param {any} value
|
|
34
|
-
* @param {ValidatorOptions} [options] Validate options for customizing the model validation behavior
|
|
35
|
-
*
|
|
36
|
-
* @abstract
|
|
37
|
-
*
|
|
38
|
-
* @see Model#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
abstract hasErrors(value: any, options?: V): string | undefined;
|
|
41
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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 customKeyCache;
|
|
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
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
VALIDATOR: string;
|
|
26
|
-
REQUIRED: string;
|
|
27
|
-
MIN: string;
|
|
28
|
-
MAX: string;
|
|
29
|
-
STEP: string;
|
|
30
|
-
MIN_LENGTH: string;
|
|
31
|
-
MAX_LENGTH: string;
|
|
32
|
-
PATTERN: string;
|
|
33
|
-
EMAIL: string;
|
|
34
|
-
URL: string;
|
|
35
|
-
DATE: string;
|
|
36
|
-
TYPE: string;
|
|
37
|
-
PASSWORD: string;
|
|
38
|
-
LIST: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* @summary list of month names
|
|
42
|
-
* @description Stores month names. Can be changed for localization purposes
|
|
43
|
-
*
|
|
44
|
-
* @constant MONTH_NAMES
|
|
45
|
-
* @memberOf module:decorator-validation.Validation
|
|
46
|
-
* @category Validation
|
|
47
|
-
*/
|
|
48
|
-
export declare const MONTH_NAMES: string[];
|
|
49
|
-
/**
|
|
50
|
-
* @summary list of names of days of the week
|
|
51
|
-
* @description Stores names for days of the week. Can be changed for localization purposes
|
|
52
|
-
*
|
|
53
|
-
* @constant DAYS_OF_WEEK_NAMES
|
|
54
|
-
* @memberOf module:decorator-validation.Validation
|
|
55
|
-
* @category Validation
|
|
56
|
-
*/
|
|
57
|
-
export declare const DAYS_OF_WEEK_NAMES: string[];
|
|
58
|
-
/**
|
|
59
|
-
* @summary Defines the default error messages
|
|
60
|
-
*
|
|
61
|
-
* @property {string} REQUIRED default error message
|
|
62
|
-
* @property {string} MIN default error message
|
|
63
|
-
* @property {string} MAX default error message
|
|
64
|
-
* @property {string} MIN_LENGTH default error message
|
|
65
|
-
* @property {string} MAX_LENGTH default error message
|
|
66
|
-
* @property {string} PATTERN default error message
|
|
67
|
-
* @property {string} EMAIL default error message
|
|
68
|
-
* @property {string} URL default error message
|
|
69
|
-
* @property {string} TYPE default error message
|
|
70
|
-
* @property {string} STEP default error message
|
|
71
|
-
* @property {string} DATE default error message
|
|
72
|
-
* @property {string} DEFAULT default error message
|
|
73
|
-
* @property {string} PASSWORD default error message
|
|
74
|
-
* @property {string} LIST default error message
|
|
75
|
-
* @property {string} LIST_INSIDE default error message
|
|
76
|
-
* @property {string} MODEL_NOT_FOUND default error message
|
|
77
|
-
*
|
|
78
|
-
* @constant DEFAULT_ERROR_MESSAGES
|
|
79
|
-
* @memberOf module:decorator-validation.Validation
|
|
80
|
-
* @category Validation
|
|
81
|
-
*/
|
|
82
|
-
export declare const DEFAULT_ERROR_MESSAGES: Record<string, string>;
|
|
83
|
-
/**
|
|
84
|
-
* @summary Defines the various default regexp patterns used
|
|
85
|
-
*
|
|
86
|
-
* @enum DEFAULT_PATTERNS
|
|
87
|
-
* @memberOf module:decorator-validation.Validation
|
|
88
|
-
* @category Validation
|
|
89
|
-
*/
|
|
90
|
-
export declare const DEFAULT_PATTERNS: {
|
|
91
|
-
EMAIL: RegExp;
|
|
92
|
-
URL: RegExp;
|
|
93
|
-
PASSWORD: {
|
|
94
|
-
CHAR8_ONE_OF_EACH: RegExp;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { ModelConstructor } from "../model/types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Marks the property as required.
|
|
5
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}
|
|
6
|
-
*
|
|
7
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
8
|
-
*
|
|
9
|
-
* @function required
|
|
10
|
-
*
|
|
11
|
-
* @category Decorators
|
|
12
|
-
*/
|
|
13
|
-
export declare function required(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
14
|
-
/**
|
|
15
|
-
* @summary Defines a minimum value for the property
|
|
16
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN}
|
|
17
|
-
*
|
|
18
|
-
* @param {number | Date} value
|
|
19
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
20
|
-
*
|
|
21
|
-
* @function min
|
|
22
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
23
|
-
* @category Decorators
|
|
24
|
-
*/
|
|
25
|
-
export declare function min(value: number | Date | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
26
|
-
/**
|
|
27
|
-
* @summary Defines a maximum value for the property
|
|
28
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
|
|
29
|
-
*
|
|
30
|
-
* @param {number | Date} value
|
|
31
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
32
|
-
*
|
|
33
|
-
* @function max
|
|
34
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
35
|
-
* @category Decorators
|
|
36
|
-
*/
|
|
37
|
-
export declare function max(value: number | Date | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
38
|
-
/**
|
|
39
|
-
* @summary Defines a step value for the property
|
|
40
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
|
|
41
|
-
*
|
|
42
|
-
* @param {number} value
|
|
43
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
44
|
-
*
|
|
45
|
-
* @function step
|
|
46
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
47
|
-
* @category Decorators
|
|
48
|
-
*/
|
|
49
|
-
export declare function step(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
50
|
-
/**
|
|
51
|
-
* @summary Defines a minimum length for the property
|
|
52
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
|
|
53
|
-
*
|
|
54
|
-
* @param {string} value
|
|
55
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
56
|
-
*
|
|
57
|
-
* @function minlength
|
|
58
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
59
|
-
* @category Decorators
|
|
60
|
-
*/
|
|
61
|
-
export declare function minlength(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
62
|
-
/**
|
|
63
|
-
* @summary Defines a maximum length for the property
|
|
64
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
|
|
65
|
-
*
|
|
66
|
-
* @param {string} value
|
|
67
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
68
|
-
*
|
|
69
|
-
* @function maxlength
|
|
70
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
71
|
-
* @category Decorators
|
|
72
|
-
*/
|
|
73
|
-
export declare function maxlength(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
74
|
-
/**
|
|
75
|
-
* @summary Defines a RegExp pattern the property must respect
|
|
76
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
|
|
77
|
-
*
|
|
78
|
-
* @param {string} value
|
|
79
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
80
|
-
*
|
|
81
|
-
* @function pattern
|
|
82
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
83
|
-
* @category Decorators
|
|
84
|
-
*/
|
|
85
|
-
export declare function pattern(value: RegExp | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
86
|
-
/**
|
|
87
|
-
* @summary Defines the property as an email
|
|
88
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
|
|
89
|
-
*
|
|
90
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
91
|
-
*
|
|
92
|
-
* @function email
|
|
93
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
94
|
-
* @category Decorators
|
|
95
|
-
*/
|
|
96
|
-
export declare function email(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
97
|
-
/**
|
|
98
|
-
* @summary Defines the property as an URL
|
|
99
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
|
|
100
|
-
*
|
|
101
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
102
|
-
*
|
|
103
|
-
* @function url
|
|
104
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
105
|
-
* @category Decorators
|
|
106
|
-
*/
|
|
107
|
-
export declare function url(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
108
|
-
/**
|
|
109
|
-
* @summary Enforces type verification
|
|
110
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
|
|
111
|
-
*
|
|
112
|
-
* @param {string[] | string} types accepted types
|
|
113
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
114
|
-
*
|
|
115
|
-
* @function type
|
|
116
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
117
|
-
* @category Decorators
|
|
118
|
-
*/
|
|
119
|
-
export declare function type(types: string[] | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
120
|
-
/**
|
|
121
|
-
* @summary Date Handler Decorator
|
|
122
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
|
|
123
|
-
*
|
|
124
|
-
* Will enforce serialization according to the selected format
|
|
125
|
-
*
|
|
126
|
-
* @param {string} format accepted format according to {@link formatDate}
|
|
127
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
128
|
-
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link DateValidator}
|
|
129
|
-
*
|
|
130
|
-
* @function date
|
|
131
|
-
*
|
|
132
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
133
|
-
* @category Decorators
|
|
134
|
-
*/
|
|
135
|
-
export declare function date(format?: string, message?: string): (target: Record<string, any>, propertyKey?: any) => any;
|
|
136
|
-
/**
|
|
137
|
-
* @summary Password Handler Decorator
|
|
138
|
-
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
|
|
139
|
-
*
|
|
140
|
-
* @param {RegExp} [pattern] defaults to {@link PasswordPatterns#CHAR8_ONE_OF_EACH}
|
|
141
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
142
|
-
* @param {Constructor<Validator>} [validator] Defaults to {@link PasswordValidator}
|
|
143
|
-
*
|
|
144
|
-
* @function password
|
|
145
|
-
*
|
|
146
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
147
|
-
* @category Decorators
|
|
148
|
-
*/
|
|
149
|
-
export declare function password(pattern?: RegExp, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
150
|
-
/**
|
|
151
|
-
* @summary List Decorator
|
|
152
|
-
* @description Also sets the {@link type} to the provided collection
|
|
153
|
-
*
|
|
154
|
-
* @param {ModelConstructor} clazz
|
|
155
|
-
* @param {string} [collection] The collection being used. defaults to Array
|
|
156
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
157
|
-
* @param {Constructor<Validator>} [validator] defaults to {@link ListValidator}
|
|
158
|
-
*
|
|
159
|
-
* @function list
|
|
160
|
-
*
|
|
161
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
162
|
-
* @category Decorators
|
|
163
|
-
*/
|
|
164
|
-
export declare function list(clazz: ModelConstructor<any> | ModelConstructor<any>[], collection?: "Array" | "Set", message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
165
|
-
/**
|
|
166
|
-
* @summary Set Decorator
|
|
167
|
-
* @description Wrapper for {@link list} with the 'Set' Collection
|
|
168
|
-
*
|
|
169
|
-
* @param {ModelConstructor} clazz
|
|
170
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
171
|
-
* @param {Constructor<Validator>} [validator]
|
|
172
|
-
*
|
|
173
|
-
* @function set
|
|
174
|
-
*
|
|
175
|
-
* @memberOf module:decorator-validation.Decorators.Validation
|
|
176
|
-
* @category Decorators
|
|
177
|
-
*/
|
|
178
|
-
export declare function set(clazz: ModelConstructor<any>, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { DecoratorMetadata } from "@decaf-ts/reflection";
|
|
2
|
-
import { Constructor } from "../model";
|
|
3
|
-
import { Validator } from "./Validators";
|
|
4
|
-
import { IRegistry } from "../utils";
|
|
5
|
-
/**
|
|
6
|
-
* @summary Type for validation decorator metadata
|
|
7
|
-
* @memberOf module:decorator-validation.Reflection
|
|
8
|
-
* @category Reflection
|
|
9
|
-
*/
|
|
10
|
-
export type ValidationMetadata = {
|
|
11
|
-
[indexer: string]: any;
|
|
12
|
-
args?: any[];
|
|
13
|
-
message: string;
|
|
14
|
-
types?: string[];
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* @summary Type for a validator property decorator definition
|
|
18
|
-
* @memberOf module:decorator-validation.Validation
|
|
19
|
-
* @category Validation
|
|
20
|
-
*/
|
|
21
|
-
export type ValidationPropertyDecoratorDefinition = {
|
|
22
|
-
prop: string | symbol;
|
|
23
|
-
decorators: ValidationDecoratorDefinition[];
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @summary Type for a validator decorator definition
|
|
27
|
-
* @memberOf module:decorator-validation.Validation
|
|
28
|
-
* @category Validation
|
|
29
|
-
*/
|
|
30
|
-
export type ValidationDecoratorDefinition = DecoratorMetadata & {
|
|
31
|
-
props: ValidationElementDefinition;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* @summary Type for a validator element metadata
|
|
35
|
-
* @memberOf module:decorator-validation.Validation
|
|
36
|
-
* @category Validation
|
|
37
|
-
*/
|
|
38
|
-
export type ValidationElementDefinition = {
|
|
39
|
-
[indexer: string]: any;
|
|
40
|
-
value?: string | number;
|
|
41
|
-
message: string;
|
|
42
|
-
types?: string[];
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* @summary Type for a model errors
|
|
46
|
-
* @memberOf module:decorator-validation.Validation
|
|
47
|
-
* @category Validation
|
|
48
|
-
*/
|
|
49
|
-
export type ModelErrors = Record<string, Record<string, string | undefined>>;
|
|
50
|
-
/**
|
|
51
|
-
* @summary Util type for {@link Validator} configuration
|
|
52
|
-
* @memberOf module:decorator-validation.Validation
|
|
53
|
-
* @category Validation
|
|
54
|
-
*/
|
|
55
|
-
export type ValidatorDefinition = {
|
|
56
|
-
validator: Constructor<Validator>;
|
|
57
|
-
validationKey: string;
|
|
58
|
-
save: boolean;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* @summary Base API for a {@link Validator} registry
|
|
62
|
-
*
|
|
63
|
-
* @interface ValidatorRegistry
|
|
64
|
-
* @extends IRegistry
|
|
65
|
-
*
|
|
66
|
-
* @category Validation
|
|
67
|
-
*/
|
|
68
|
-
export interface IValidatorRegistry<T extends Validator> extends IRegistry<T> {
|
|
69
|
-
/**
|
|
70
|
-
* @summary retrieves the custom keys
|
|
71
|
-
* @method
|
|
72
|
-
*/
|
|
73
|
-
getCustomKeys(): Record<string, string>;
|
|
74
|
-
/**
|
|
75
|
-
* @summary Retrieves the Registered validator keys
|
|
76
|
-
* @return {string[]} the registered validators keys
|
|
77
|
-
* @method
|
|
78
|
-
*/
|
|
79
|
-
getKeys(): string[];
|
|
80
|
-
/**
|
|
81
|
-
* @summary Registers the provided validators onto the registry
|
|
82
|
-
*
|
|
83
|
-
* @typedef T extends Validator
|
|
84
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
85
|
-
* @method
|
|
86
|
-
*/
|
|
87
|
-
register<T extends Validator>(...validator: (T | ValidatorDefinition)[]): void;
|
|
88
|
-
/**
|
|
89
|
-
* @summary Retrieves the Validator constructor if registered
|
|
90
|
-
*
|
|
91
|
-
* @typedef T extends Validator
|
|
92
|
-
* @param {string} key one of the {@link ValidationKeys}
|
|
93
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
94
|
-
* @method
|
|
95
|
-
*/
|
|
96
|
-
get<T extends Validator>(key: string): T | undefined;
|
|
97
|
-
}
|
|
98
|
-
export type ValidatorOptions = {
|
|
99
|
-
message?: string;
|
|
100
|
-
};
|
|
101
|
-
export interface URLValidatorOptions extends ValidatorOptions {
|
|
102
|
-
types: string | string[] | {
|
|
103
|
-
name: string;
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export interface TypeValidatorOptions extends ValidatorOptions {
|
|
107
|
-
types: string | string[] | {
|
|
108
|
-
name: string;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
export interface StepValidatorOptions extends ValidatorOptions {
|
|
112
|
-
step: number | string;
|
|
113
|
-
}
|
|
114
|
-
export interface PatternValidatorOptions extends ValidatorOptions {
|
|
115
|
-
pattern?: RegExp | string;
|
|
116
|
-
}
|
|
117
|
-
export interface MinValidatorOptions extends ValidatorOptions {
|
|
118
|
-
min: number | Date | string;
|
|
119
|
-
}
|
|
120
|
-
export interface MinLengthValidatorOptions extends ValidatorOptions {
|
|
121
|
-
minLength: number;
|
|
122
|
-
}
|
|
123
|
-
export interface MaxValidatorOptions extends ValidatorOptions {
|
|
124
|
-
max: number | Date | string;
|
|
125
|
-
}
|
|
126
|
-
export interface MaxLengthValidatorOptions extends ValidatorOptions {
|
|
127
|
-
maxLength: number;
|
|
128
|
-
}
|
|
129
|
-
export interface ListValidatorOptions extends ValidatorOptions {
|
|
130
|
-
clazz: string[];
|
|
131
|
-
}
|
|
132
|
-
export interface DateValidatorOptions extends ValidatorOptions {
|
|
133
|
-
format?: string;
|
|
134
|
-
}
|