@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,193 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { DecoratorMetadata } from "../validation";
|
|
3
|
+
import { Model } from "../model";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Util function to retrieve the decorators for the provided Property
|
|
6
|
+
*
|
|
7
|
+
* @param {string} annotationPrefix
|
|
8
|
+
* @param {any} target
|
|
9
|
+
* @param {string | symbol} propertyName
|
|
10
|
+
* @param {boolean} [ignoreType] defaults to false. decides if the {@link ModelKeys.TYPE} is ignored or not
|
|
11
|
+
* @param {boolean} [recursive] defaults to true. decides if it should climb the prototypal tree searching for more decorators on that property
|
|
12
|
+
* @param {DecoratorMetadata[]} [accumulator] used when recursive is true, to cache decorators while it climbs the prototypal tree
|
|
13
|
+
*
|
|
14
|
+
* @function getPropertyDecorators
|
|
15
|
+
* @memberOf module:decorator-validation.Reflection
|
|
16
|
+
* @category Reflection
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPropertyDecorators(annotationPrefix: string, target: any, propertyName: string | symbol, ignoreType?: boolean, recursive?: boolean, accumulator?: DecoratorMetadata[]): {
|
|
19
|
+
prop: string;
|
|
20
|
+
decorators: DecoratorMetadata[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @summary gets the prop type from the decorator
|
|
24
|
+
* @param {any} model
|
|
25
|
+
* @param {string | symbol} propKey
|
|
26
|
+
* @return {string | undefined}
|
|
27
|
+
*
|
|
28
|
+
* @function geTypeFromDecorators
|
|
29
|
+
*
|
|
30
|
+
* @memberOf module:decorator-validation.Reflection
|
|
31
|
+
*/
|
|
32
|
+
export declare function getTypeFromDecorator(model: any, propKey: string | symbol): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Retrieves the decorators for an object's properties prefixed by {@param prefixes}
|
|
35
|
+
*
|
|
36
|
+
* @param {T} model
|
|
37
|
+
* @param {string[]} prefixes
|
|
38
|
+
*
|
|
39
|
+
* @function getAllPropertyDecorators
|
|
40
|
+
*
|
|
41
|
+
* @memberOf module:db-decorators.Reflection
|
|
42
|
+
*/
|
|
43
|
+
export declare const getAllPropertyDecorators: <T extends Model>(model: T, ...prefixes: string[]) => Record<string, any> | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* @summary Retrieves all properties of an object
|
|
46
|
+
* @description
|
|
47
|
+
* - and of all its prototypes if {@param climbTree} until it reaches {@param stopAt} (or ends the prototype chain)
|
|
48
|
+
*
|
|
49
|
+
* @param obj
|
|
50
|
+
* @param {boolean} [climbTree] default to true
|
|
51
|
+
* @param {string} [stopAt] defaults to 'Object'
|
|
52
|
+
*
|
|
53
|
+
* @function getAllProperties
|
|
54
|
+
*
|
|
55
|
+
* @memberOf module:decorator-validation.Model
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAllProperties(obj: Record<any, any>, climbTree?: boolean, stopAt?: string): string[];
|
|
58
|
+
/**
|
|
59
|
+
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
60
|
+
*
|
|
61
|
+
* @param {string} string
|
|
62
|
+
* @param {string} args replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
63
|
+
* @return {string} formatted string
|
|
64
|
+
*
|
|
65
|
+
* @function stringFormat
|
|
66
|
+
* @memberOf module:decorator-validation.Utils.Format
|
|
67
|
+
* @category Format
|
|
68
|
+
*/
|
|
69
|
+
export declare function stringFormat(string: string, ...args: string[]): string;
|
|
70
|
+
/**
|
|
71
|
+
* @summary Deep Object Comparison
|
|
72
|
+
* @description algorithm from {@link https://stackoverflow.com/questions/30476150/javascript-deep-comparison-recursively-objects-and-properties}
|
|
73
|
+
* but with optional ignored properties
|
|
74
|
+
*
|
|
75
|
+
* @param {any} a
|
|
76
|
+
* @param {any} b
|
|
77
|
+
* @param {string} [propsToIgnore]
|
|
78
|
+
*
|
|
79
|
+
* @function isEqual
|
|
80
|
+
* @memberOf module:decorator-validation.Utils.Equality
|
|
81
|
+
* @category Validation
|
|
82
|
+
*/
|
|
83
|
+
export declare function isEqual(a: any, b: any, ...propsToIgnore: string[]): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* @summary Mimics Java's String's Hash implementation
|
|
86
|
+
*
|
|
87
|
+
* @param {string | number | symbol | Date} obj
|
|
88
|
+
* @return {number} hash value of obj
|
|
89
|
+
*
|
|
90
|
+
* @function hashCode
|
|
91
|
+
* @memberOf module:decorator-validation.Utils.Hashing
|
|
92
|
+
* @category Hashing
|
|
93
|
+
*/
|
|
94
|
+
export declare function hashCode(obj: string | number | symbol | Date): number;
|
|
95
|
+
/**
|
|
96
|
+
* @summary Defines teh type for a Hashing function
|
|
97
|
+
* @memberOf module:decorator-validation.Utils.Hashing
|
|
98
|
+
* @category Hashing
|
|
99
|
+
*/
|
|
100
|
+
export type HashingFunction = (value: any) => string | number;
|
|
101
|
+
/**
|
|
102
|
+
* @summary Hashes an object serializing it and then hashing the string
|
|
103
|
+
* @description The Serialization algorithm used by default (JSON.stringify)
|
|
104
|
+
* is not deterministic and should not be used for hashing
|
|
105
|
+
*
|
|
106
|
+
* @param {Record<string, any>} obj
|
|
107
|
+
* @return {string} the resulting hash
|
|
108
|
+
*
|
|
109
|
+
* @function hashSerialization
|
|
110
|
+
* @memberOf module:decorator-validation.Utils.Hashing
|
|
111
|
+
*
|
|
112
|
+
* @category Hashing
|
|
113
|
+
*/
|
|
114
|
+
export declare function hashSerialization(obj: Record<string, any> | any[]): number;
|
|
115
|
+
/**
|
|
116
|
+
* @summary Hashes an object by combining the hash of all its properties
|
|
117
|
+
*
|
|
118
|
+
* @param {Record<string, any>} obj
|
|
119
|
+
* @return {string} the resulting hash
|
|
120
|
+
*
|
|
121
|
+
* @function hashObj
|
|
122
|
+
* @memberOf module:decorator-validation.Utils.Hashing
|
|
123
|
+
* @category Hashing
|
|
124
|
+
*/
|
|
125
|
+
export declare function hashObj(obj: Record<string, any> | any[]): string | number;
|
|
126
|
+
/**
|
|
127
|
+
* @summary For Serialization/deserialization purposes.
|
|
128
|
+
* @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
|
|
129
|
+
*
|
|
130
|
+
* @function isModel
|
|
131
|
+
* @memberOf module:decorator-validation.Validation
|
|
132
|
+
* @category Validation
|
|
133
|
+
*/
|
|
134
|
+
export declare function isModel(target: Record<string, any>): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* @summary Util function to retrieve the Class decorators
|
|
137
|
+
*
|
|
138
|
+
* @function getClassDecorators
|
|
139
|
+
* @memberOf module:decorator-validation.Reflection
|
|
140
|
+
* @category Reflection
|
|
141
|
+
*/
|
|
142
|
+
export declare function getClassDecorators(annotationPrefix: string, target: any): {
|
|
143
|
+
key: string;
|
|
144
|
+
props: any;
|
|
145
|
+
}[];
|
|
146
|
+
/**
|
|
147
|
+
* @summary Util function to check a type according to a typeName
|
|
148
|
+
*
|
|
149
|
+
* @param {any} value
|
|
150
|
+
* @param {string} acceptedType
|
|
151
|
+
* @return {boolean} true for a match, false otherwise
|
|
152
|
+
*
|
|
153
|
+
* @function checkType
|
|
154
|
+
* @memberOf module:decorator-validation.Validation
|
|
155
|
+
* @category Validation
|
|
156
|
+
*/
|
|
157
|
+
export declare function checkType(value: any, acceptedType: string): any;
|
|
158
|
+
/**
|
|
159
|
+
* @summary Util function to check a type according multiple possibilities
|
|
160
|
+
* @param {any} value
|
|
161
|
+
* @param {string[]} acceptedTypes
|
|
162
|
+
* @return {boolean} true if any is a match, false otherwise
|
|
163
|
+
*
|
|
164
|
+
* @function checkTypes
|
|
165
|
+
* @memberOf module:decorator-validation.Validation
|
|
166
|
+
* @category Validation
|
|
167
|
+
*/
|
|
168
|
+
export declare function checkTypes(value: any, acceptedTypes: string[]): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* @summary The model type
|
|
171
|
+
*
|
|
172
|
+
* @param {any} value
|
|
173
|
+
* @param {string | string[] | {name: string}} types
|
|
174
|
+
*
|
|
175
|
+
* @function evaluateDesignTypes
|
|
176
|
+
* @memberOf module:decorator-validation.Validation
|
|
177
|
+
* @category Validation
|
|
178
|
+
*/
|
|
179
|
+
export declare function evaluateDesignTypes(value: any, types: string | string[] | {
|
|
180
|
+
name: string;
|
|
181
|
+
}): any;
|
|
182
|
+
/**
|
|
183
|
+
* @summary Reverses the process from {@link formatDate}
|
|
184
|
+
*
|
|
185
|
+
* @param {string} date the date string to be converted back into date
|
|
186
|
+
* @param {string} format the date format
|
|
187
|
+
* @return {Date} the date from the format or the standard new Date({@prop date}) if the string couldn't be parsed (are you sure the format matches the string?)
|
|
188
|
+
*
|
|
189
|
+
* @function dateFromFormat
|
|
190
|
+
* @memberOf module:decorator-validation.Utils.Dates
|
|
191
|
+
* @category Format
|
|
192
|
+
*/
|
|
193
|
+
export declare function dateFromFormat(date: string, format: string): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"reflect-metadata";import{MONTH_NAMES}from"../validation";import{ModelKeys}from"./constants";import{Model}from"../model";function getPropertyDecorators(e,r,t,o=!1,a=!0,n){o=function(r,o,a,t=!1,e){e=Reflect.getMetadataKeys(o,a).filter(e=>!t&&e===ModelKeys.TYPE||e.toString().startsWith(r)).reduce((e,t)=>{t={key:t!==ModelKeys.TYPE?t.substring(r.length):t,props:Reflect.getMetadata(t,o,a)};return e.concat(t)},e||[]);return{prop:a.toString(),decorators:e}}(e,r,t,o,n);return a&&Object.getPrototypeOf(r)!==Object.prototype?getPropertyDecorators(e,Object.getPrototypeOf(r.constructor),t,!0,a,o.decorators):{prop:o.prop,decorators:function(e){const t={};return e.filter(e=>e.key in t?(isEqual(e.props,t[e.key])||console.log(stringFormat("Found a similar decorator for the {0} property of a {1} model but with different attributes. The original one will be kept",e.key,r.constructor.name)),!1):(t[e.key.toString()]=e.props,!0))}(o.decorators)}}function getTypeFromDecorator(e,t){var e=getPropertyDecorators(ModelKeys.REFLECT,e,t,!1);return e&&e.decorators&&"Function"!==(e=(t=e.decorators.shift()).props?t.props.name:void 0)?e:void 0}const getAllPropertyDecorators=function(n,...e){if(e&&e.length)return Object.getOwnPropertyNames(n).reduce((o,a)=>(e.forEach((e,t)=>{var r,e=getPropertyDecorators(e,n,a,0!==t);t=o=o||{},r=a,(e=e.decorators)&&e.length&&(t[r]||(t[r]=[]),t[r].push(...e))}),o),void 0)};function getAllProperties(e,t=!0,r="Object"){const o=[];let a=e;do{Object.getOwnPropertyNames(a).forEach(function(e){-1===o.indexOf(e)&&o.push(e)})}while(function(){if(t){var e=Object.getPrototypeOf(a);if(e&&e.constructor.name!==r)return a=e}}());return o}function stringFormat(e,...r){return e.replace(/{(\d+)}/g,function(e,t){return void 0!==r[t]?r[t]:e})}function isEqual(t,r,...o){var e;return t===r||(t instanceof Date&&r instanceof Date?t.getTime()===r.getTime():!t||!r||"object"!=typeof t&&"object"!=typeof r?t===r:null!=t&&null!=r&&typeof t==typeof r&&t.prototype===r.prototype&&(e=Object.keys(t).filter(e=>-1===o.indexOf(e))).length===Object.keys(r).filter(e=>-1===o.indexOf(e)).length&&e.every(e=>-1!==o.indexOf(e)||isEqual(t[e],r[e],...o)))}function hashCode(t){t=String(t);let r=0;for(let e=0;e<t.length;e++){var o=t.charCodeAt(e);r=(r<<5)-r+o,r&=r}return r}function hashSerialization(e){return hashCode(Model.serialize(e))}function hashObj(e){function o(e){return void 0===e?"":-1!==["string","number","symbol"].indexOf(typeof e)?r(e.toString()):e instanceof Date?r(e.getTime()):(Array.isArray(e)?e:Object.values(e)).reduce(t,void 0)}const t=function(e,t){var r=o(t);return"string"==typeof r?o((e||"")+o(t)):(e=((e=e||0)<<5)-e+r)&e},r=hashCode;e=Object.values(e).reduce(t,0);return"number"==typeof e?Math.abs(e):e}function isModel(e){return!!e[ModelKeys.ANCHOR]||!!getClassDecorators(ModelKeys.REFLECT,e).find(e=>e.key===ModelKeys.MODEL&&e.props&&e.props.class)}function getClassDecorators(r,o){return Reflect.getOwnMetadataKeys(o.constructor).filter(e=>e.toString().startsWith(r)).reduce((e,t)=>{t={key:t.substring(r.length),props:Reflect.getMetadata(t,o.constructor)};return e.concat(t)},[])}function checkType(e,t){return typeof e===t||e.constructor&&e.constructor.name.toLowerCase()===t.toLowerCase()}function checkTypes(t,e){return!e.every(e=>!checkType(t,e))}function evaluateDesignTypes(e,t){switch(typeof t){case"string":return checkType(e,t);case"object":return Array.isArray(t)?checkTypes(e,t):!0;case"function":return t.name&&"Object"!==t.name?checkType(e,t.name):!0;default:return!0}}function dateFromFormat(e,t){let r=t;r.match(/hh/)?r=r.replace("hh","(?<hour>\\d{2})"):r.match(/h/)?r=r.replace("h","(?<hour>\\d{1,2})"):r.match(/HH/)?r=r.replace("HH","(?<hour>\\d{2})"):r.match(/H/)&&(r=r.replace("H","(?<hour>\\d{1,2})")),r.match(/mm/)?r=r.replace("mm","(?<minutes>\\d{2})"):r.match(/m/)&&(r=r.replace("m","(?<minutes>\\d{1,2})")),r.match(/ss/)?r=r.replace("ss","(?<seconds>\\d{2})"):r.match(/s/)&&(r=r.replace("s","(?<seconds>\\d{1,2})")),r.match(/dd/)?r=r.replace("dd","(?<day>\\d{2})"):r.match(/d/)&&(r=r.replace("d","(?<day>\\d{1,2})")),r.match(/EEEE/)?r=r.replace("EEEE","(?<dayofweek>\\w+)"):r.match(/EEEE/)&&(r=r.replace("EEE","(?<dayofweek>\\w+)")),r.match(/yyyy/)?r=r.replace("yyyy","(?<year>\\d{4})"):r.match(/yy/)&&(r=r.replace("yy","(?<year>\\d{2})")),r.match(/MMMM/)?r=r.replace("MMMM","(?<monthname>\\w+)"):r.match(/MMM/)&&(r=r.replace("MMM","(?<monthnamesmall>\\w+)")),r.match(/MM/)?r=r.replace("MM","(?<month>\\d{2})"):r.match(/M/)&&(r=r.replace("M","(?<month>\\d{1,2})")),r=r.replace("S","(?<milis>\\d{1,3})").replace("aaa","(?<ampm>\\w{2})");t=new RegExp(r,"g").exec(e);if(!t||!t.groups)return new Date(e);function o(e){return!e||(e=parseInt(e),isNaN(e))?0:e}var a=o(t.groups.year),n=o(t.groups.day),c=t.groups.ampm;let s=o(t.groups.hour);c&&(s="PM"===c?s+12:s);var c=o(t.groups.minutes),i=o(t.groups.seconds),p=o(t.groups.milis),u=t.groups.monthname;const l=t.groups.monthnamesmall;let d=t.groups.month;if(u)d=MONTH_NAMES.indexOf(u);else if(l){t=MONTH_NAMES.find(e=>e.toLowerCase().startsWith(l.toLowerCase()));if(!t)return new Date(e);d=MONTH_NAMES.indexOf(t)}else d=o(""+d);return new Date(a,d-1,n,s,c,i,p)}export{getPropertyDecorators,getTypeFromDecorator,getAllPropertyDecorators,getAllProperties,stringFormat,isEqual,hashCode,hashSerialization,hashObj,isModel,getClassDecorators,checkType,checkTypes,evaluateDesignTypes,dateFromFormat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./general";export*from"./registry";export*from"./serialization";export*from"./constants";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Constructor } from "../model/types";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Basic interface for Registries
|
|
4
|
+
*
|
|
5
|
+
* @interface IRegistry
|
|
6
|
+
*
|
|
7
|
+
* @category Utilities
|
|
8
|
+
*/
|
|
9
|
+
export interface IRegistry<T> {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Registers an Object
|
|
12
|
+
*
|
|
13
|
+
* @param {T} obj
|
|
14
|
+
* @param {any[]} args
|
|
15
|
+
*
|
|
16
|
+
* @method
|
|
17
|
+
*/
|
|
18
|
+
register(obj: T | any, ...args: any[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* @summary Retrieves an Object if it can find it
|
|
21
|
+
*
|
|
22
|
+
* @param {any} key
|
|
23
|
+
* @param {any[]} args
|
|
24
|
+
* @return {T | undefined}
|
|
25
|
+
*
|
|
26
|
+
* @method
|
|
27
|
+
*/
|
|
28
|
+
get(key: any, ...args: any[]): T | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @summary Basic Builder Registry Interface
|
|
32
|
+
*
|
|
33
|
+
* @typedef T
|
|
34
|
+
* @interface BuilderRegistry<T>
|
|
35
|
+
*
|
|
36
|
+
* @category Construction
|
|
37
|
+
*/
|
|
38
|
+
export interface BuilderRegistry<T> extends IRegistry<Constructor<T>> {
|
|
39
|
+
/**
|
|
40
|
+
* @summary Retrieves an Builder Object by name if it can
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name
|
|
43
|
+
* @param {any[]} args
|
|
44
|
+
*
|
|
45
|
+
* @method
|
|
46
|
+
*/
|
|
47
|
+
get(name: string, ...args: any[]): Constructor<T> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @summary Registers a constructor by name
|
|
50
|
+
*
|
|
51
|
+
* @param {Constructor<T>} [constructor]
|
|
52
|
+
* @param {name} name
|
|
53
|
+
* @param {any[]} args
|
|
54
|
+
*
|
|
55
|
+
* @method
|
|
56
|
+
*/
|
|
57
|
+
register(constructor: Constructor<T>, name?: string, ...args: any[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Builds an Object by name
|
|
60
|
+
*
|
|
61
|
+
* @param {{}} obj
|
|
62
|
+
* @param {any[]} args
|
|
63
|
+
* @return T
|
|
64
|
+
*
|
|
65
|
+
* @method
|
|
66
|
+
*/
|
|
67
|
+
build(obj: Record<string, any> | T, ...args: any[]): T;
|
|
68
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Model } from "../model/Model";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Helper in serialization
|
|
4
|
+
*
|
|
5
|
+
* @interface Serializer
|
|
6
|
+
* @category Serialization
|
|
7
|
+
*/
|
|
8
|
+
export interface Serializer<T extends Model> {
|
|
9
|
+
/**
|
|
10
|
+
* @summary Serializes a model
|
|
11
|
+
* @param {T} model
|
|
12
|
+
*
|
|
13
|
+
* @method
|
|
14
|
+
*
|
|
15
|
+
* @throws {Error}
|
|
16
|
+
*/
|
|
17
|
+
serialize(model: T): string;
|
|
18
|
+
/**
|
|
19
|
+
* @summary Rebuilds a model from serialization
|
|
20
|
+
* @param {string} str
|
|
21
|
+
*
|
|
22
|
+
* @method
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error}
|
|
25
|
+
*/
|
|
26
|
+
deserialize(str: string): T;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
30
|
+
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
31
|
+
* and therefore should not be used for hashing purposes
|
|
32
|
+
*
|
|
33
|
+
* To keep dependencies low, we will not implement this, but we recommend
|
|
34
|
+
* implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries
|
|
35
|
+
*
|
|
36
|
+
* @class JSONSerializer
|
|
37
|
+
* @implements Serializer
|
|
38
|
+
*
|
|
39
|
+
* @category Serialization
|
|
40
|
+
*/
|
|
41
|
+
export declare class JSONSerializer<T extends Model> implements Serializer<T> {
|
|
42
|
+
/**
|
|
43
|
+
* @summary prepares the model for serialization
|
|
44
|
+
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
45
|
+
* so the object can be recognized upon deserialization
|
|
46
|
+
*
|
|
47
|
+
* @param {T} model
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
protected preSerialize(model: T): {} & T;
|
|
51
|
+
/**
|
|
52
|
+
* @summary Rebuilds a model from a serialization
|
|
53
|
+
* @param {string} str
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} If it fails to parse the string, or to build the model
|
|
56
|
+
*/
|
|
57
|
+
deserialize(str: string): T;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Serializes a model
|
|
60
|
+
* @param {T} model
|
|
61
|
+
*
|
|
62
|
+
* @throws {Error} if fails to serialize
|
|
63
|
+
*/
|
|
64
|
+
serialize(model: T): string;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Model}from"../model/Model";import{ModelKeys}from"./constants";class JSONSerializer{preSerialize(e){var r=Object.assign({},e);return r[ModelKeys.ANCHOR]=e[ModelKeys.ANCHOR],r}deserialize(e){e=JSON.parse(e);return Model.build(e)}serialize(e){return JSON.stringify(this.preSerialize(e))}}export{JSONSerializer};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IValidatorRegistry, Validator, ValidatorDefinition } from "./Validators";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Static class acting as a namespace for the Validation
|
|
4
|
+
*
|
|
5
|
+
* @class Validation
|
|
6
|
+
* @static
|
|
7
|
+
*
|
|
8
|
+
* @category Validation
|
|
9
|
+
*/
|
|
10
|
+
export declare class Validation {
|
|
11
|
+
private static actingValidatorRegistry?;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @summary Defines the acting ValidatorRegistry
|
|
15
|
+
*
|
|
16
|
+
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
17
|
+
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
18
|
+
*/
|
|
19
|
+
static setRegistry(validatorRegistry: IValidatorRegistry<Validator>, migrationHandler?: (validator: Validator) => Validator): void;
|
|
20
|
+
/**
|
|
21
|
+
* @summary Returns the current ValidatorRegistry
|
|
22
|
+
*
|
|
23
|
+
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
24
|
+
*/
|
|
25
|
+
private static getRegistry;
|
|
26
|
+
/**
|
|
27
|
+
* @summary Retrieves a validator
|
|
28
|
+
*
|
|
29
|
+
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
30
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
31
|
+
*/
|
|
32
|
+
static get<T extends Validator>(validatorKey: string): T | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Registers the provided validators onto the registry
|
|
35
|
+
*
|
|
36
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
37
|
+
*/
|
|
38
|
+
static register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{TypeValidator,ValidatorRegistry}from"./Validators";import{ModelKeys}from"../utils";class Validation{static{this.actingValidatorRegistry=void 0}constructor(){}static setRegistry(i,a){a&&Validation.actingValidatorRegistry&&Validation.actingValidatorRegistry.getKeys().forEach(t=>{t=i.get(t);t&&i.register(a(t))}),Validation.actingValidatorRegistry=i}static getRegistry(){return Validation.actingValidatorRegistry||(Validation.actingValidatorRegistry=new ValidatorRegistry({validator:TypeValidator,validationKey:ModelKeys.TYPE,save:!1})),Validation.actingValidatorRegistry}static get(t){return Validation.getRegistry().get(t)}static register(...t){return Validation.getRegistry().register(...t)}}export{Validation};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Date Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
7
|
+
*
|
|
8
|
+
* @class DateValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class DateValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a model
|
|
17
|
+
*
|
|
18
|
+
* @param {Date | string} value
|
|
19
|
+
* @param {string} format
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: Date | string, format: string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class DateValidator extends Validator{constructor(a=DEFAULT_ERROR_MESSAGES.DATE){super(ValidationKeys.DATE,a,Number.name,Date.name,String.name)}hasErrors(a,t,e){if(void 0!==a)return"string"==typeof a&&(a=new Date(a)),isNaN(a.getDate())?this.getMessage(e||this.message):void 0}}export{DateValidator};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Errors } from "../types";
|
|
2
|
+
import { PatternValidator } from "./PatternValidator";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Email Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
7
|
+
*
|
|
8
|
+
* @class EmailValidator
|
|
9
|
+
* @extends PatternValidator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class EmailValidator extends PatternValidator {
|
|
14
|
+
private static readonly emailPat;
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";import{PatternValidator}from"./PatternValidator";class EmailValidator extends PatternValidator{static{this.emailPat=/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/}constructor(a=DEFAULT_ERROR_MESSAGES.EMAIL){super(ValidationKeys.EMAIL,a)}hasErrors(a,t){return super.hasErrors(a,EmailValidator.emailPat,t)}}export{EmailValidator};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary List Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
7
|
+
*
|
|
8
|
+
* @class ListValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class ListValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a model
|
|
17
|
+
*
|
|
18
|
+
* @param {any[] | Set<any>} value
|
|
19
|
+
* @param {string} clazz
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any[] | Set<any>, clazz: string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{DEFAULT_ERROR_MESSAGES,ValidationKeys}from"./constants";class ListValidator extends Validator{constructor(t=DEFAULT_ERROR_MESSAGES.LIST){super(ValidationKeys.LIST,t,Array.name,Set.name)}hasErrors(r,a,e){var s;if(r&&(Array.isArray(r)?r.length:r.size))for(let t=0;t<(Array.isArray(r)?r.length:r.size);t++)switch(typeof(s=r[t])){case"object":case"function":if(s.constructor&&s.constructor.name===a)break;return this.getMessage(e||this.message,a);default:if(typeof s!==a)return this.getMessage(e||this.message,a)}}}export{ListValidator};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Errors } from "../types";
|
|
2
|
+
import { Validator } from "./Validator";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Maximum Length Validator
|
|
5
|
+
* @description Validates strings and Arrays on their maximum length
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
8
|
+
*
|
|
9
|
+
* @class MinLengthValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class MaxLengthValidator extends Validator {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {number} maxlength
|
|
21
|
+
* @param {string} [message]
|
|
22
|
+
*
|
|
23
|
+
* @return Errors
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
*
|
|
27
|
+
* @see Validator#hasErrors
|
|
28
|
+
*/
|
|
29
|
+
hasErrors(value: string | any[], maxlength: number, message?: string): Errors;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class MaxLengthValidator extends Validator{constructor(a=DEFAULT_ERROR_MESSAGES.MAX_LENGTH){super(ValidationKeys.MAX_LENGTH,a,String.name,Array.name)}hasErrors(a,t,r){return void 0!==a&&a.length>t?this.getMessage(r||this.message,t):void 0}}export{MaxLengthValidator};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Max Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
7
|
+
*
|
|
8
|
+
* @class MaxValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class MaxValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates a Model
|
|
17
|
+
*
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {number | Date | string} max
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: number | Date | string, max: number | Date | string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class MaxValidator extends Validator{constructor(a=DEFAULT_ERROR_MESSAGES.MAX){super(ValidationKeys.MAX,a,"number","Date","string")}hasErrors(a,t,e){if(void 0!==a){if(a instanceof Date&&!(t instanceof Date)&&(t=new Date(t),isNaN(t.getDate())))throw new Error("Invalid Max param defined");return t<a?this.getMessage(e||this.message,t):void 0}}}export{MaxValidator};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Minimum Length Validator
|
|
5
|
+
* @description Validates strings and Arrays on their minimum length
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
8
|
+
*
|
|
9
|
+
* @class MinLengthValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class MinLengthValidator extends Validator {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {string | Array} value
|
|
19
|
+
* @param {number} minlength
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @memberOf MinLengthValidator
|
|
25
|
+
* @override
|
|
26
|
+
*
|
|
27
|
+
* @see Validator#hasErrors
|
|
28
|
+
*/
|
|
29
|
+
hasErrors(value: string | any[], minlength: number, message?: string): Errors;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class MinLengthValidator extends Validator{constructor(t=DEFAULT_ERROR_MESSAGES.MIN_LENGTH){super(ValidationKeys.MIN_LENGTH,t,String.name,Array.name)}hasErrors(t,a,r){return void 0!==t&&t.length<a?this.getMessage(r||this.message,a):void 0}}export{MinLengthValidator};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Min Validator
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
7
|
+
*
|
|
8
|
+
* @class MinValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
*/
|
|
13
|
+
export declare class MinValidator extends Validator {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
/**
|
|
16
|
+
* @summary Validates Model
|
|
17
|
+
*
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {number | Date | string} min
|
|
20
|
+
* @param {string} [message]
|
|
21
|
+
*
|
|
22
|
+
* @return Errors
|
|
23
|
+
*
|
|
24
|
+
* @override
|
|
25
|
+
*
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: number | Date | string, min: number | Date | string, message?: string): Errors;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Validator}from"./Validator";import{ValidationKeys,DEFAULT_ERROR_MESSAGES}from"./constants";class MinValidator extends Validator{constructor(a=DEFAULT_ERROR_MESSAGES.MIN){super(ValidationKeys.MIN,a,"number","Date","string")}hasErrors(a,t,i){if(void 0!==a){if(a instanceof Date&&!(t instanceof Date)&&(t=new Date(t),isNaN(t.getDate())))throw new Error("Invalid Min param defined");return a<t?this.getMessage(i||this.message,t):void 0}}}export{MinValidator};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PatternValidator } from "./PatternValidator";
|
|
2
|
+
import { Errors } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Handles Password Validation
|
|
5
|
+
*
|
|
6
|
+
* @param {string} [errorMessage] defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
7
|
+
* @param {RegExp} [passwordPattern] defaults to {@link PasswordPatterns.CHAR8_ONE_OF_EACH}
|
|
8
|
+
*
|
|
9
|
+
* @class PasswordValidator
|
|
10
|
+
* @extends PatternValidator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class PasswordValidator extends PatternValidator {
|
|
15
|
+
readonly pattern: RegExp;
|
|
16
|
+
constructor(errorMessage?: string, passwordPattern?: RegExp);
|
|
17
|
+
/**
|
|
18
|
+
* @summary Validates a model
|
|
19
|
+
*
|
|
20
|
+
* @param {string} value
|
|
21
|
+
* @param {RegExp} [pattern]
|
|
22
|
+
* @param {string} [message]
|
|
23
|
+
*
|
|
24
|
+
* @return Errors
|
|
25
|
+
*
|
|
26
|
+
* @override
|
|
27
|
+
*
|
|
28
|
+
* @see PatternValidator#hasErrors
|
|
29
|
+
*/
|
|
30
|
+
hasErrors(value: string, pattern: RegExp, message?: string): Errors;
|
|
31
|
+
}
|