@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,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
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(r,a,t,e){void 0===e&&(e=t);var i=Object.getOwnPropertyDescriptor(a,t);i&&("get"in i?a.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return a[t]}}),Object.defineProperty(r,e,i)}:function(r,a,t,e){r[e=void 0===e?t:e]=a[t]}),__exportStar=this&&this.__exportStar||function(r,a){for(var t in r)"default"===t||Object.prototype.hasOwnProperty.call(a,t)||__createBinding(a,r,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Validators=void 0;const DateValidator_1=require("./DateValidator/index.cjs"),TypeValidator_1=require("./TypeValidator/index.cjs"),PasswordValidator_1=require("./PasswordValidator/index.cjs"),StepValidator_1=require("./StepValidator/index.cjs"),URLValidator_1=require("./URLValidator/index.cjs"),PatternValidator_1=require("./PatternValidator/index.cjs"),MinValidator_1=require("./MinValidator/index.cjs"),MinLengthValidator_1=require("./MinLengthValidator/index.cjs"),MaxValidator_1=require("./MaxValidator/index.cjs"),MaxLengthValidator_1=require("./MaxLengthValidator/index.cjs"),RequiredValidator_1=require("./RequiredValidator/index.cjs"),EmailValidator_1=require("./EmailValidator/index.cjs"),ListValidator_1=require("./ListValidator/index.cjs");__exportStar(require("./constants/index.cjs"),exports),__exportStar(require("./Validator/index.cjs"),exports),__exportStar(require("./types/index.cjs"),exports),__exportStar(require("./ValidatorRegistry/index.cjs"),exports),__exportStar(require("./EmailValidator/index.cjs"),exports),__exportStar(require("./RequiredValidator/index.cjs"),exports),__exportStar(require("./MaxLengthValidator/index.cjs"),exports),__exportStar(require("./MaxValidator/index.cjs"),exports),__exportStar(require("./MinLengthValidator/index.cjs"),exports),__exportStar(require("./MinValidator/index.cjs"),exports),__exportStar(require("./PatternValidator/index.cjs"),exports),__exportStar(require("./URLValidator/index.cjs"),exports),__exportStar(require("./StepValidator/index.cjs"),exports),__exportStar(require("./DateValidator/index.cjs"),exports),__exportStar(require("./TypeValidator/index.cjs"),exports),__exportStar(require("./PasswordValidator/index.cjs"),exports),exports.Validators={EmailValidator:EmailValidator_1.EmailValidator,RequiredValidator:RequiredValidator_1.RequiredValidator,MaxLengthValidator:MaxLengthValidator_1.MaxLengthValidator,MaxValidator:MaxValidator_1.MaxValidator,MinLengthValidator:MinLengthValidator_1.MinLengthValidator,MinValidator:MinValidator_1.MinValidator,PatternValidator:PatternValidator_1.PatternValidator,URLValidator:URLValidator_1.URLValidator,StepValidator:StepValidator_1.StepValidator,DateValidator:DateValidator_1.DateValidator,TypeValidator:TypeValidator_1.TypeValidator,PasswordValidator:PasswordValidator_1.PasswordValidator,ListValidator:ListValidator_1.ListValidator};
|
|
@@ -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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.set=exports.list=exports.password=exports.date=exports.parseDate=exports.formatDate=exports.twoDigitPad=exports.isValidDate=exports.bindDateToString=exports.type=exports.url=exports.email=exports.pattern=exports.maxlength=exports.minlength=exports.step=exports.max=exports.min=exports.required=exports.getValidationKey=void 0,require("reflect-metadata");const Validators_1=require("./Validators/index.cjs"),Validators_2=require("./Validators/index.cjs"),utils_1=require("../utils/index.cjs"),ListValidator_1=require("./Validators/ListValidator/index.cjs"),Validation_1=require("./Validation/index.cjs");function getValidationKey(a){return Validators_1.ValidationKeys.REFLECT+a}function required(e=Validators_1.DEFAULT_ERROR_MESSAGES.REQUIRED,i=Validators_2.RequiredValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.REQUIRED),{message:e},a,t),Validation_1.Validation.register({validator:i,validationKey:Validators_1.ValidationKeys.REQUIRED,save:!0})}}function min(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.MIN,r=Validators_2.MinValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.MIN),{value:e,message:i,types:[Number.name,Date.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.MIN,save:!0})}}function max(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.MAX,r=Validators_2.MaxValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.MAX),{value:e,message:i,types:[Number.name,Date.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.MAX,save:!0})}}function step(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.STEP,r=Validators_2.StepValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.STEP),{value:e,message:i,types:[Number.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.STEP,save:!0})}}function minlength(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.MIN_LENGTH,r=Validators_2.MinLengthValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.MIN_LENGTH),{value:e,message:i,types:[String.name,Array.name,Set.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.MIN_LENGTH,save:!0})}}function maxlength(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.MAX_LENGTH,r=Validators_2.MaxLengthValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.MAX_LENGTH),{value:e,message:i,types:[String.name,Array.name,Set.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.MAX_LENGTH,save:!0})}}function pattern(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.PATTERN,r=Validators_2.PatternValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.PATTERN),{value:"string"==typeof e?e:e.toString(),message:i,types:[String.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.PATTERN,save:!0})}}function email(e=Validators_1.DEFAULT_ERROR_MESSAGES.EMAIL,i=Validators_2.EmailValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.EMAIL),{message:e,types:[String.name]},a,t),Validation_1.Validation.register({validator:i,validationKey:Validators_1.ValidationKeys.EMAIL,save:!0})}}function url(e=Validators_1.DEFAULT_ERROR_MESSAGES.URL,i=Validators_2.URLValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.URL),{message:e,types:[String.name]},a,t),Validation_1.Validation.register({validator:i,validationKey:Validators_1.ValidationKeys.URL,save:!0})}}function type(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.TYPE,r=Validators_2.TypeValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.TYPE),{customTypes:e,message:i},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.TYPE,save:!0})}}function bindDateToString(a,t){var e;if(a)return e=()=>formatDate(a,t),Object.defineProperty(a,"toISOString",{enumerable:!1,configurable:!1,value:e}),Object.defineProperty(a,"toString",{enumerable:!1,configurable:!1,value:e}),a}function isValidDate(a){return a&&"[object Date]"===Object.prototype.toString.call(a)&&!isNaN(a)}function twoDigitPad(a){return a<10?"0"+a:a.toString()}function formatDate(a,t="yyyy/MM/dd"){var e=a.getDate(),i=a.getMonth(),r=a.getFullYear(),o=a.getHours(),s=a.getMinutes(),l=a.getSeconds(),n=a.getMilliseconds(),d=o%12,V=twoDigitPad(d),_=twoDigitPad(o),p=twoDigitPad(s),g=twoDigitPad(l),y=o<12?"AM":"PM",a=Validators_1.DAYS_OF_WEEK_NAMES[a.getDay()],E=a.substr(0,3),u=twoDigitPad(e),S=i+1,c=twoDigitPad(S),i=Validators_1.MONTH_NAMES[i],m=i.substr(0,3),r=r+"",f=r.substr(2,2);return t=-1<(t=t.replace("hh",V).replace("h",d.toString()).replace("HH",_).replace("H",o.toString()).replace("mm",p).replace("m",s.toString()).replace("ss",g).replace("s",l.toString()).replace("S",n.toString()).replace("dd",u).replace("d",e.toString()).replace("EEEE",a).replace("EEE",E).replace("yyyy",r).replace("yy",f).replace("aaa",y)).indexOf("MMM")?t.replace("MMMM",i).replace("MMM",m):t.replace("MM",c).replace("M",S.toString())}function parseDate(t,e){let a=void 0;if(e){if(e instanceof Date)try{a=(0,utils_1.dateFromFormat)(formatDate(e,t),t)}catch(a){throw new Error((0,utils_1.stringFormat)("Could not convert date {0} to format: {1}",e.toString(),t))}else if("string"==typeof e)a=(0,utils_1.dateFromFormat)(e,t);else if("number"==typeof e){var i=new Date(e);a=(0,utils_1.dateFromFormat)(formatDate(i,t),t)}else{if(!isValidDate(e))throw new Error("Invalid value provided "+e);try{var r=new Date(e);a=(0,utils_1.dateFromFormat)(formatDate(r,t),t)}catch(a){throw new Error((0,utils_1.stringFormat)("Could not convert date {0} to format: {1}",e,t))}}return bindDateToString(a,t)}}function date(r="dd/MM/yyyy",t=Validators_1.DEFAULT_ERROR_MESSAGES.DATE,o=Validators_2.DateValidator){return(a,e)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.DATE),{format:r,message:t,types:[Date.name]},a,e),Validation_1.Validation.register({validator:o,validationKey:Validators_1.ValidationKeys.DATE,save:!0});const i=new WeakMap;Object.defineProperty(a,e,{configurable:!1,set(a){var t=Object.getOwnPropertyDescriptor(this,e);t&&!t.configurable||Object.defineProperty(this,e,{enumerable:!0,configurable:!1,get:()=>i.get(this),set:a=>{var t;try{t=parseDate(r,a),i.set(this,t)}catch(a){console.error((0,utils_1.stringFormat)("Failed to parse date: {0}",a.message||a))}}}),this[e]=a},get(){console.log("here")}})}}function password(e=Validators_1.PasswordPatterns.CHAR8_ONE_OF_EACH,i=Validators_1.DEFAULT_ERROR_MESSAGES.PASSWORD,r=Validators_2.PasswordValidator){return(a,t)=>{Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.PASSWORD),{pattern:e,message:i,types:[String.name]},a,t),Validation_1.Validation.register({validator:r,validationKey:Validators_1.ValidationKeys.PASSWORD,save:!0})}}function list(e,i="Array",r=Validators_1.DEFAULT_ERROR_MESSAGES.LIST,o=ListValidator_1.ListValidator){return(a,t)=>{type(i)(a,t),Reflect.defineMetadata(getValidationKey(Validators_1.ValidationKeys.LIST),{class:e.name,type:i,message:r},a,t),Validation_1.Validation.register({validator:o,validationKey:Validators_1.ValidationKeys.LIST,save:!0})}}function set(e,i=Validators_1.DEFAULT_ERROR_MESSAGES.LIST,r){return(a,t)=>{list(e,"Set",i,r)(a,t)}}exports.getValidationKey=getValidationKey,exports.required=required,exports.min=min,exports.max=max,exports.step=step,exports.minlength=minlength,exports.maxlength=maxlength,exports.pattern=pattern,exports.email=email,exports.url=url,exports.type=type,exports.bindDateToString=bindDateToString,exports.isValidDate=isValidDate,exports.twoDigitPad=twoDigitPad,exports.formatDate=formatDate,exports.parseDate=parseDate,exports.date=date,exports.password=password,exports.list=list,exports.set=set;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Validator } from "./Validators";
|
|
3
|
+
import { Constructor, ModelConstructor } from "../model";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Builds the key to store as Metadata under Reflections
|
|
6
|
+
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
7
|
+
*
|
|
8
|
+
* @param {string} key
|
|
9
|
+
*
|
|
10
|
+
* @function getModelKey
|
|
11
|
+
* @memberOf module:decorator-validation.Utils
|
|
12
|
+
* @category Utilities
|
|
13
|
+
*/
|
|
14
|
+
export declare function getValidationKey(key: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* @summary Marks the property as required.
|
|
17
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}
|
|
18
|
+
*
|
|
19
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
20
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link RequiredValidator}
|
|
21
|
+
*
|
|
22
|
+
* @function required
|
|
23
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
24
|
+
* @category Decorators
|
|
25
|
+
*/
|
|
26
|
+
export declare function required(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Defines a minimum value for the property
|
|
29
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN}
|
|
30
|
+
*
|
|
31
|
+
* @param {number | Date} value
|
|
32
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
33
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MinValidator}
|
|
34
|
+
*
|
|
35
|
+
* @function min
|
|
36
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
37
|
+
* @category Decorators
|
|
38
|
+
*/
|
|
39
|
+
export declare function min(value: number | Date | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* @summary Defines a maximum value for the property
|
|
42
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
|
|
43
|
+
*
|
|
44
|
+
* @param {number | Date} value
|
|
45
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
46
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MaxValidator}
|
|
47
|
+
*
|
|
48
|
+
* @function max
|
|
49
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
50
|
+
* @category Decorators
|
|
51
|
+
*/
|
|
52
|
+
export declare function max(value: number | Date | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
53
|
+
/**
|
|
54
|
+
* @summary Defines a step value for the property
|
|
55
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
|
|
56
|
+
*
|
|
57
|
+
* @param {number} value
|
|
58
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
59
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link StepValidator}
|
|
60
|
+
*
|
|
61
|
+
* @function step
|
|
62
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
63
|
+
* @category Decorators
|
|
64
|
+
*/
|
|
65
|
+
export declare function step(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
66
|
+
/**
|
|
67
|
+
* @summary Defines a minimum length for the property
|
|
68
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
|
|
69
|
+
*
|
|
70
|
+
* @param {string} value
|
|
71
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
72
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MinLengthValidator}
|
|
73
|
+
*
|
|
74
|
+
* @function minlength
|
|
75
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
76
|
+
* @category Decorators
|
|
77
|
+
*/
|
|
78
|
+
export declare function minlength(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
79
|
+
/**
|
|
80
|
+
* @summary Defines a maximum length for the property
|
|
81
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
|
|
82
|
+
*
|
|
83
|
+
* @param {string} value
|
|
84
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
85
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link MaxLengthValidator}
|
|
86
|
+
*
|
|
87
|
+
* @function maxlength
|
|
88
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
89
|
+
* @category Decorators
|
|
90
|
+
*/
|
|
91
|
+
export declare function maxlength(value: number, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
92
|
+
/**
|
|
93
|
+
* @summary Defines a RegExp pattern the property must respect
|
|
94
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
|
|
95
|
+
*
|
|
96
|
+
* @param {string} value
|
|
97
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
98
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link PatternValidator}
|
|
99
|
+
*
|
|
100
|
+
* @function pattern
|
|
101
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
102
|
+
* @category Decorators
|
|
103
|
+
*/
|
|
104
|
+
export declare function pattern(value: RegExp | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
105
|
+
/**
|
|
106
|
+
* @summary Defines the property as an email
|
|
107
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
|
|
108
|
+
*
|
|
109
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
110
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link EmailValidator}
|
|
111
|
+
*
|
|
112
|
+
* @function email
|
|
113
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
114
|
+
* @category Decorators
|
|
115
|
+
*/
|
|
116
|
+
export declare function email(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
117
|
+
/**
|
|
118
|
+
* @summary Defines the property as an URL
|
|
119
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
|
|
120
|
+
*
|
|
121
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
122
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link URLValidator}
|
|
123
|
+
*
|
|
124
|
+
* @function url
|
|
125
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
126
|
+
* @category Decorators
|
|
127
|
+
*/
|
|
128
|
+
export declare function url(message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
129
|
+
/**
|
|
130
|
+
* @summary Enforces type verification
|
|
131
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
|
|
132
|
+
*
|
|
133
|
+
* @param {string[] | string} types accepted types
|
|
134
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
135
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link TypeValidator}
|
|
136
|
+
*
|
|
137
|
+
* @function type
|
|
138
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
139
|
+
* @category Decorators
|
|
140
|
+
*/
|
|
141
|
+
export declare function type(types: string[] | string, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
142
|
+
/**
|
|
143
|
+
* @summary Binds a date format to a string
|
|
144
|
+
* @param {Date} [date]
|
|
145
|
+
* @param {string} [format]
|
|
146
|
+
* @memberOf module:decorator-validation.Utils.Format
|
|
147
|
+
* @category Utilities
|
|
148
|
+
*/
|
|
149
|
+
export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* @summary Helper function to be used instead of instanceOf Date
|
|
152
|
+
* @param date
|
|
153
|
+
* @memberOf module:decorator-validation.Utils.Dates
|
|
154
|
+
* @category Validation
|
|
155
|
+
*/
|
|
156
|
+
export declare function isValidDate(date: any): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* @summary Util function to pad numbers
|
|
159
|
+
* @param {number} num
|
|
160
|
+
*
|
|
161
|
+
* @return {string}
|
|
162
|
+
*
|
|
163
|
+
* @function twoDigitPad
|
|
164
|
+
* @memberOf module:decorator-validation.Utils.Format
|
|
165
|
+
* @category Format
|
|
166
|
+
*/
|
|
167
|
+
export declare function twoDigitPad(num: number): string;
|
|
168
|
+
/**
|
|
169
|
+
* @summary Date Format Handling
|
|
170
|
+
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
171
|
+
*
|
|
172
|
+
* <pre>
|
|
173
|
+
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
174
|
+
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
175
|
+
* You can display date, time, AM/PM, etc.
|
|
176
|
+
*
|
|
177
|
+
* Date and Time Patterns
|
|
178
|
+
* yy = 2-digit year; yyyy = full year
|
|
179
|
+
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
180
|
+
* EEEE = full weekday name; EEE = short weekday name
|
|
181
|
+
* d = digit day; dd = 2-digit day
|
|
182
|
+
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
183
|
+
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
184
|
+
* s = seconds; ss = 2-digit seconds
|
|
185
|
+
* S = miliseconds
|
|
186
|
+
* </pre>
|
|
187
|
+
*
|
|
188
|
+
* @param {Date} date
|
|
189
|
+
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
190
|
+
* @return {string} the formatted date
|
|
191
|
+
*
|
|
192
|
+
* @function formatDate
|
|
193
|
+
* @memberOf module:decorator-validation.Utils.Dates
|
|
194
|
+
* @category Format
|
|
195
|
+
*/
|
|
196
|
+
export declare function formatDate(date: Date, patternStr?: string): string;
|
|
197
|
+
/**
|
|
198
|
+
* @summary Parses a date from a specified format
|
|
199
|
+
* @param {string} format
|
|
200
|
+
* @param {string | Date | number} [v]
|
|
201
|
+
* @memberOf module:decorator-validation.Utils.Dates
|
|
202
|
+
* @category Format
|
|
203
|
+
*/
|
|
204
|
+
export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* @summary Date Handler Decorator
|
|
207
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
|
|
208
|
+
*
|
|
209
|
+
* Will enforce serialization according to the selected format
|
|
210
|
+
*
|
|
211
|
+
* @param {string} format accepted format according to {@link formatDate}
|
|
212
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
213
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link DateValidator}
|
|
214
|
+
*
|
|
215
|
+
* @function date
|
|
216
|
+
*
|
|
217
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
218
|
+
* @category Decorators
|
|
219
|
+
*/
|
|
220
|
+
export declare function date(format?: string, message?: string, validator?: Constructor<Validator>): (target: Record<string, any>, propertyKey: string) => any;
|
|
221
|
+
/**
|
|
222
|
+
* @summary Password Handler Decorator
|
|
223
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
|
|
224
|
+
*
|
|
225
|
+
* @param {RegExp} [pattern] defaults to {@link PasswordPatterns#CHAR8_ONE_OF_EACH}
|
|
226
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
227
|
+
* @param {Constructor<Validator>} [validator] Defaults to {@link PasswordValidator}
|
|
228
|
+
*
|
|
229
|
+
* @function password
|
|
230
|
+
*
|
|
231
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
232
|
+
* @category Decorators
|
|
233
|
+
*/
|
|
234
|
+
export declare function password(pattern?: RegExp, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => void;
|
|
235
|
+
/**
|
|
236
|
+
* @summary List Decorator
|
|
237
|
+
* @description Also sets the {@link type} to the provided collection
|
|
238
|
+
*
|
|
239
|
+
* @param {ModelConstructor} clazz
|
|
240
|
+
* @param {string} [collection] The collection being used. defaults to Array
|
|
241
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
242
|
+
* @param {Constructor<Validator>} [validator] defaults to {@link ListValidator}
|
|
243
|
+
*
|
|
244
|
+
* @function list
|
|
245
|
+
*
|
|
246
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
247
|
+
* @category Decorators
|
|
248
|
+
*/
|
|
249
|
+
export declare function list(clazz: ModelConstructor<any>, collection?: "Array" | "Set", message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => any;
|
|
250
|
+
/**
|
|
251
|
+
* @summary Set Decorator
|
|
252
|
+
* @description Wrapper for {@link list} with the 'Set' Collection
|
|
253
|
+
*
|
|
254
|
+
* @param {ModelConstructor} clazz
|
|
255
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
256
|
+
* @param {Constructor<Validator>} [validator]
|
|
257
|
+
*
|
|
258
|
+
* @function set
|
|
259
|
+
*
|
|
260
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
261
|
+
* @category Decorators
|
|
262
|
+
*/
|
|
263
|
+
export declare function set(clazz: ModelConstructor<any>, message?: string, validator?: Constructor<Validator>): (target: any, propertyKey: string) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(r,e,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(e,t);i&&("get"in i?e.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,o,i)}:function(r,e,t,o){r[o=void 0===o?t:o]=e[t]}),__exportStar=this&&this.__exportStar||function(r,e){for(var t in r)"default"===t||Object.prototype.hasOwnProperty.call(e,t)||__createBinding(e,r,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Decorators=exports.ValidatorRegistryImp=void 0,__exportStar(require("./types/index.cjs"),exports),__exportStar(require("./Validators/index.cjs"),exports);const Validators_1=require("./Validators/index.cjs");exports.ValidatorRegistryImp=Validators_1.ValidatorRegistry,exports.Decorators=require("./decorators/index.cjs"),__exportStar(require("./decorators/index.cjs"),exports),__exportStar(require("./Validation/index.cjs"),exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./Validators";
|
|
3
|
+
import { ValidatorRegistry } from "./Validators";
|
|
4
|
+
/**
|
|
5
|
+
* @summary exports the Validator Registry
|
|
6
|
+
* @constant ValidatorRegistryImp
|
|
7
|
+
* @memberOf module:decorator-validation.Validation
|
|
8
|
+
* @category Validation
|
|
9
|
+
*/
|
|
10
|
+
export declare const ValidatorRegistryImp: typeof ValidatorRegistry;
|
|
11
|
+
export * as Decorators from "./decorators";
|
|
12
|
+
export * from "./decorators";
|
|
13
|
+
export * from "./Validation";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Validator Error type
|
|
3
|
+
* @memberOf module:decorator-validation.Validation
|
|
4
|
+
* @category Validation
|
|
5
|
+
*/
|
|
6
|
+
export type Errors = string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* @summary Type for decorator metadata
|
|
9
|
+
* @memberOf module:decorator-validation.Reflection
|
|
10
|
+
* @category Reflection
|
|
11
|
+
*/
|
|
12
|
+
export type DecoratorMetadata = {
|
|
13
|
+
key: string;
|
|
14
|
+
props: Record<string, any>;
|
|
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 = {
|
|
50
|
+
[indexer: string]: {
|
|
51
|
+
[indexer: string]: Errors;
|
|
52
|
+
};
|
|
53
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@decaf-ts/decorator-validation",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "simple decorator based validation engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"require": "./lib/index.cjs",
|
|
8
|
+
"import": "./lib/esm/index.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"do-install": "TOKEN=$(cat .token) npm install",
|
|
13
|
+
"flash-forward": "npx npm-check-updates -u && npm run do-install",
|
|
14
|
+
"reset": "rm -rf * && git checkout . && git pull && npm run do-install",
|
|
15
|
+
"build": "rimraf ./lib && rimraf ./dist && gulp dev",
|
|
16
|
+
"build:prod": "rimraf ./lib && rimraf ./dist && gulp prod",
|
|
17
|
+
"test": "jest --coverage --testPathPattern=\"/tests/unit\" --passWithNoTests --detectOpenHandles",
|
|
18
|
+
"test:integration": "jest --coverage --testPathPattern=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
|
|
19
|
+
"test:all": "jest --coverage --testPathPattern=\"/tests/(unit|integration)\" --passWithNoTests --detectOpenHandles",
|
|
20
|
+
"lint": "eslint .",
|
|
21
|
+
"lint-fix": "eslint . && eslint --fix ./src/*",
|
|
22
|
+
"prepare-release": "npm run lint-fix && npm run build:prod && npm run test && npm run docs",
|
|
23
|
+
"release": "./bin/tag-release.sh",
|
|
24
|
+
"clean-publish": "npx clean-publish",
|
|
25
|
+
"coverage": "npm run test:all && jest-coverage-badges --input \"./workdocs/coverage/coverage-summary.json\" --output \"./workdocs/badges\"",
|
|
26
|
+
"docs": "npx rimraf ./docs && mkdir docs && npm run do-install -- install better-docs taffydb && gulp docs; npm remove better-docs taffydb"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/decaf-ts/decorator-validation.git"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.0.0",
|
|
34
|
+
"npm": ">=10.0.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"lib",
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"keywords": [
|
|
41
|
+
"decorator",
|
|
42
|
+
"validation",
|
|
43
|
+
"model",
|
|
44
|
+
"orm",
|
|
45
|
+
"custom",
|
|
46
|
+
"extensible",
|
|
47
|
+
"lightweight",
|
|
48
|
+
"decaf-ts",
|
|
49
|
+
"javascript",
|
|
50
|
+
"typescript",
|
|
51
|
+
"ts"
|
|
52
|
+
],
|
|
53
|
+
"author": "Tiago Venceslau",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/decaf-ts/decorator-validation/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://github.com/decaf-ts/decorator-validation#readme",
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/jest": "^29.5.12",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
62
|
+
"clean-publish": "^4.3.0",
|
|
63
|
+
"eslint": "^8.57.0",
|
|
64
|
+
"eslint-config-prettier": "^9.1.0",
|
|
65
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
66
|
+
"gulp": "^4.0.2",
|
|
67
|
+
"gulp-if": "^3.0.0",
|
|
68
|
+
"gulp-rename": "^2.0.0",
|
|
69
|
+
"gulp-replace": "^1.1.4",
|
|
70
|
+
"gulp-run-command": "^0.0.10",
|
|
71
|
+
"gulp-sourcemaps": "^3.0.0",
|
|
72
|
+
"gulp-typescript": "^6.0.0-alpha.1",
|
|
73
|
+
"gulp-uglify": "^3.0.2",
|
|
74
|
+
"jest": "^29.7.0",
|
|
75
|
+
"jest-coverage-badges": "^1.1.2",
|
|
76
|
+
"jest-junit": "^16.0.0",
|
|
77
|
+
"jsdoc": "^4.0.2",
|
|
78
|
+
"jsdoc-mermaid": "^1.0.0",
|
|
79
|
+
"markdown-include": "^0.4.3",
|
|
80
|
+
"merge-stream": "^2.0.0",
|
|
81
|
+
"nodemon": "^3.1.0",
|
|
82
|
+
"npm-check-updates": "^16.14.15",
|
|
83
|
+
"prettier": "^3.2.5",
|
|
84
|
+
"rimraf": "^5.0.5",
|
|
85
|
+
"ts-jest": "^29.1.2",
|
|
86
|
+
"ts-loader": "^9.5.1",
|
|
87
|
+
"ts-node": "^10.9.2",
|
|
88
|
+
"typescript": "^5.4.2",
|
|
89
|
+
"vinyl-named": "^1.1.0",
|
|
90
|
+
"webpack-stream": "^7.0.0"
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"install": "^0.13.0",
|
|
94
|
+
"reflect-metadata": "^0.2.1"
|
|
95
|
+
}
|
|
96
|
+
}
|