@decaf-ts/decorator-validation 1.4.21 → 1.5.2
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/package.json +15 -9
- package/dist/decorator-validation.bundle.min.js +0 -2
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -14
- package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -14
- package/lib/esm/index.d.ts +0 -42
- package/lib/esm/index.js +0 -42
- package/lib/esm/model/Model.d.ts +0 -139
- package/lib/esm/model/Model.js +0 -297
- package/lib/esm/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/esm/model/ModelErrorDefinition.js +0 -52
- package/lib/esm/model/Registry.d.ts +0 -59
- package/lib/esm/model/Registry.js +0 -73
- package/lib/esm/model/constants.d.ts +0 -56
- package/lib/esm/model/constants.js +0 -69
- package/lib/esm/model/construction.d.ts +0 -29
- package/lib/esm/model/construction.js +0 -63
- package/lib/esm/model/decorators.d.ts +0 -25
- package/lib/esm/model/decorators.js +0 -62
- package/lib/esm/model/index.d.ts +0 -9
- package/lib/esm/model/index.js +0 -9
- package/lib/esm/model/types.d.ts +0 -79
- package/lib/esm/model/types.js +0 -1
- package/lib/esm/model/utils.d.ts +0 -11
- package/lib/esm/model/utils.js +0 -25
- package/lib/esm/model/validation.d.ts +0 -14
- package/lib/esm/model/validation.js +0 -134
- package/lib/esm/utils/constants.d.ts +0 -26
- package/lib/esm/utils/constants.js +0 -27
- package/lib/esm/utils/dates.d.ts +0 -76
- package/lib/esm/utils/dates.js +0 -243
- package/lib/esm/utils/decorators.d.ts +0 -2
- package/lib/esm/utils/decorators.js +0 -18
- package/lib/esm/utils/hashing.d.ts +0 -52
- package/lib/esm/utils/hashing.js +0 -99
- package/lib/esm/utils/index.d.ts +0 -7
- package/lib/esm/utils/index.js +0 -7
- package/lib/esm/utils/registry.d.ts +0 -68
- package/lib/esm/utils/registry.js +0 -1
- package/lib/esm/utils/serialization.d.ts +0 -79
- package/lib/esm/utils/serialization.js +0 -88
- package/lib/esm/utils/strings.d.ts +0 -25
- package/lib/esm/utils/strings.js +0 -31
- package/lib/esm/validation/Validation.d.ts +0 -51
- package/lib/esm/validation/Validation.js +0 -71
- package/lib/esm/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/DateValidator.js +0 -53
- package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/EmailValidator.js +0 -48
- package/lib/esm/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/ListValidator.js +0 -66
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/MaxLengthValidator.js +0 -53
- package/lib/esm/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/MaxValidator.js +0 -57
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/MinLengthValidator.js +0 -53
- package/lib/esm/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/MinValidator.js +0 -57
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/PasswordValidator.js +0 -48
- package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/esm/validation/Validators/PatternValidator.js +0 -70
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/RequiredValidator.js +0 -55
- package/lib/esm/validation/Validators/StepValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/StepValidator.js +0 -52
- package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/TypeValidator.js +0 -60
- package/lib/esm/validation/Validators/URLValidator.d.ts +0 -26
- package/lib/esm/validation/Validators/URLValidator.js +0 -46
- package/lib/esm/validation/Validators/Validator.d.ts +0 -40
- package/lib/esm/validation/Validators/Validator.js +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -80
- package/lib/esm/validation/Validators/constants.d.ts +0 -96
- package/lib/esm/validation/Validators/constants.js +0 -134
- package/lib/esm/validation/Validators/decorators.d.ts +0 -12
- package/lib/esm/validation/Validators/decorators.js +0 -25
- package/lib/esm/validation/Validators/index.d.ts +0 -52
- package/lib/esm/validation/Validators/index.js +0 -52
- package/lib/esm/validation/Validators/types.d.ts +0 -51
- package/lib/esm/validation/Validators/types.js +0 -1
- package/lib/esm/validation/decorators.d.ts +0 -178
- package/lib/esm/validation/decorators.js +0 -288
- package/lib/esm/validation/index.d.ts +0 -4
- package/lib/esm/validation/index.js +0 -4
- package/lib/esm/validation/types.d.ts +0 -46
- package/lib/esm/validation/types.js +0 -1
- package/lib/index.cjs +0 -59
- package/lib/index.d.ts +0 -42
- package/lib/model/Model.cjs +0 -301
- package/lib/model/Model.d.ts +0 -139
- package/lib/model/ModelErrorDefinition.cjs +0 -56
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/Registry.cjs +0 -78
- package/lib/model/Registry.d.ts +0 -59
- package/lib/model/constants.cjs +0 -72
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/construction.cjs +0 -68
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/decorators.cjs +0 -67
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/index.cjs +0 -25
- package/lib/model/index.d.ts +0 -9
- package/lib/model/types.cjs +0 -2
- package/lib/model/types.d.ts +0 -79
- package/lib/model/utils.cjs +0 -29
- package/lib/model/utils.d.ts +0 -11
- package/lib/model/validation.cjs +0 -137
- package/lib/model/validation.d.ts +0 -14
- package/lib/utils/constants.cjs +0 -30
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/dates.cjs +0 -251
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/decorators.cjs +0 -22
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/hashing.cjs +0 -106
- package/lib/utils/hashing.d.ts +0 -52
- package/lib/utils/index.cjs +0 -23
- package/lib/utils/index.d.ts +0 -7
- package/lib/utils/registry.cjs +0 -2
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/serialization.cjs +0 -93
- package/lib/utils/serialization.d.ts +0 -79
- package/lib/utils/strings.cjs +0 -35
- package/lib/utils/strings.d.ts +0 -25
- package/lib/validation/Validation.cjs +0 -75
- package/lib/validation/Validation.d.ts +0 -51
- package/lib/validation/Validators/DateValidator.cjs +0 -56
- package/lib/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/validation/Validators/EmailValidator.cjs +0 -51
- package/lib/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/validation/Validators/ListValidator.cjs +0 -69
- package/lib/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/validation/Validators/MaxLengthValidator.cjs +0 -56
- package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MaxValidator.cjs +0 -60
- package/lib/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/validation/Validators/MinLengthValidator.cjs +0 -56
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MinValidator.cjs +0 -60
- package/lib/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/validation/Validators/PasswordValidator.cjs +0 -51
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/validation/Validators/PatternValidator.cjs +0 -73
- package/lib/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/validation/Validators/RequiredValidator.cjs +0 -58
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/validation/Validators/StepValidator.cjs +0 -55
- package/lib/validation/Validators/StepValidator.d.ts +0 -28
- package/lib/validation/Validators/TypeValidator.cjs +0 -63
- package/lib/validation/Validators/TypeValidator.d.ts +0 -27
- package/lib/validation/Validators/URLValidator.cjs +0 -49
- package/lib/validation/Validators/URLValidator.d.ts +0 -26
- package/lib/validation/Validators/Validator.cjs +0 -51
- package/lib/validation/Validators/Validator.d.ts +0 -40
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -85
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/constants.cjs +0 -137
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/Validators/decorators.cjs +0 -28
- package/lib/validation/Validators/decorators.d.ts +0 -12
- package/lib/validation/Validators/index.cjs +0 -69
- package/lib/validation/Validators/types.cjs +0 -2
- package/lib/validation/decorators.cjs +0 -304
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/index.cjs +0 -20
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.cjs +0 -2
- package/lib/validation/types.d.ts +0 -46
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Model } from "../model/Model";
|
|
2
|
-
import { ModelKeys } from "./constants";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
5
|
-
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
6
|
-
* and therefore should not be used for hashing purposes
|
|
7
|
-
*
|
|
8
|
-
* To keep dependencies low, we will not implement this, but we recommend
|
|
9
|
-
* implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries
|
|
10
|
-
*
|
|
11
|
-
* @class JSONSerializer
|
|
12
|
-
* @implements Serializer
|
|
13
|
-
*
|
|
14
|
-
* @category Serialization
|
|
15
|
-
*/
|
|
16
|
-
export class JSONSerializer {
|
|
17
|
-
/**
|
|
18
|
-
* @summary prepares the model for serialization
|
|
19
|
-
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
20
|
-
* so the object can be recognized upon deserialization
|
|
21
|
-
*
|
|
22
|
-
* @param {T} model
|
|
23
|
-
* @protected
|
|
24
|
-
*/
|
|
25
|
-
preSerialize(model) {
|
|
26
|
-
// TODO: nested preserialization (so increase performance when deserializing)
|
|
27
|
-
const toSerialize = Object.assign({}, model);
|
|
28
|
-
const metadata = Model.getMetadata(model);
|
|
29
|
-
toSerialize[ModelKeys.ANCHOR] = metadata || model.constructor.name;
|
|
30
|
-
return toSerialize;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @summary Rebuilds a model from a serialization
|
|
34
|
-
* @param {string} str
|
|
35
|
-
*
|
|
36
|
-
* @throws {Error} If it fails to parse the string, or to build the model
|
|
37
|
-
*/
|
|
38
|
-
deserialize(str) {
|
|
39
|
-
const deserialization = JSON.parse(str);
|
|
40
|
-
const className = deserialization[ModelKeys.ANCHOR];
|
|
41
|
-
if (!className)
|
|
42
|
-
throw new Error("Could not find class reference in serialized model");
|
|
43
|
-
const model = Model.build(deserialization, className);
|
|
44
|
-
return model;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @summary Serializes a model
|
|
48
|
-
* @param {T} model
|
|
49
|
-
*
|
|
50
|
-
* @throws {Error} if fails to serialize
|
|
51
|
-
*/
|
|
52
|
-
serialize(model) {
|
|
53
|
-
return JSON.stringify(this.preSerialize(model));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export const DefaultSerializationMethod = "json";
|
|
57
|
-
export class Serialization {
|
|
58
|
-
static { this.current = DefaultSerializationMethod; }
|
|
59
|
-
static { this.cache = {
|
|
60
|
-
json: new JSONSerializer(),
|
|
61
|
-
}; }
|
|
62
|
-
constructor() { }
|
|
63
|
-
static get(key) {
|
|
64
|
-
if (key in this.cache)
|
|
65
|
-
return this.cache[key];
|
|
66
|
-
throw new Error(`No serialization method registered under ${key}`);
|
|
67
|
-
}
|
|
68
|
-
static register(key, func, setDefault = false) {
|
|
69
|
-
if (key in this.cache)
|
|
70
|
-
throw new Error(`Serialization method ${key} already registered`);
|
|
71
|
-
this.cache[key] = new func();
|
|
72
|
-
if (setDefault)
|
|
73
|
-
this.current = key;
|
|
74
|
-
}
|
|
75
|
-
static serialize(obj, method, ...args) {
|
|
76
|
-
if (!method)
|
|
77
|
-
return this.get(this.current).serialize(obj, ...args);
|
|
78
|
-
return this.get(method).serialize(obj, ...args);
|
|
79
|
-
}
|
|
80
|
-
static deserialize(obj, method, ...args) {
|
|
81
|
-
if (!method)
|
|
82
|
-
return this.get(this.current).deserialize(obj, ...args);
|
|
83
|
-
return this.get(method).deserialize(obj, ...args);
|
|
84
|
-
}
|
|
85
|
-
static setDefault(method) {
|
|
86
|
-
this.current = this.get(method);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
3
|
-
*
|
|
4
|
-
* @param {string} string
|
|
5
|
-
* @param {Array<string | number>} [args] replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
6
|
-
* @return {string} formatted string
|
|
7
|
-
*
|
|
8
|
-
* @function stringFormat
|
|
9
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
10
|
-
* @category Format
|
|
11
|
-
*/
|
|
12
|
-
export declare function stringFormat(string: string, ...args: (string | number)[]): string;
|
|
13
|
-
/**
|
|
14
|
-
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
15
|
-
* @description alias for {@link stringFormat}
|
|
16
|
-
*
|
|
17
|
-
* @param {string} string
|
|
18
|
-
* @param {string} args replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
19
|
-
* @return {string} formatted string
|
|
20
|
-
*
|
|
21
|
-
* @function sf
|
|
22
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
23
|
-
* @category Format
|
|
24
|
-
*/
|
|
25
|
-
export declare const sf: typeof stringFormat;
|
package/lib/esm/utils/strings.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
3
|
-
*
|
|
4
|
-
* @param {string} string
|
|
5
|
-
* @param {Array<string | number>} [args] replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
6
|
-
* @return {string} formatted string
|
|
7
|
-
*
|
|
8
|
-
* @function stringFormat
|
|
9
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
10
|
-
* @category Format
|
|
11
|
-
*/
|
|
12
|
-
export function stringFormat(string, ...args) {
|
|
13
|
-
return string.replace(/{(\d+)}/g, function (match, number) {
|
|
14
|
-
return typeof args[number] !== "undefined"
|
|
15
|
-
? args[number].toString()
|
|
16
|
-
: "undefined";
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
21
|
-
* @description alias for {@link stringFormat}
|
|
22
|
-
*
|
|
23
|
-
* @param {string} string
|
|
24
|
-
* @param {string} args replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
25
|
-
* @return {string} formatted string
|
|
26
|
-
*
|
|
27
|
-
* @function sf
|
|
28
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
29
|
-
* @category Format
|
|
30
|
-
*/
|
|
31
|
-
export const sf = stringFormat;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validators/Validator";
|
|
2
|
-
import { IValidatorRegistry, ValidatorDefinition } from "./Validators/types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Static class acting as a namespace for the Validation
|
|
5
|
-
*
|
|
6
|
-
* @class Validation
|
|
7
|
-
* @static
|
|
8
|
-
*
|
|
9
|
-
* @category Validation
|
|
10
|
-
*/
|
|
11
|
-
export declare class Validation {
|
|
12
|
-
private static actingValidatorRegistry?;
|
|
13
|
-
private constructor();
|
|
14
|
-
/**
|
|
15
|
-
* @summary Defines the acting ValidatorRegistry
|
|
16
|
-
*
|
|
17
|
-
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
18
|
-
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
19
|
-
*/
|
|
20
|
-
static setRegistry(validatorRegistry: IValidatorRegistry<Validator>, migrationHandler?: (validator: Validator) => Validator): void;
|
|
21
|
-
/**
|
|
22
|
-
* @summary Returns the current ValidatorRegistry
|
|
23
|
-
*
|
|
24
|
-
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
25
|
-
*/
|
|
26
|
-
private static getRegistry;
|
|
27
|
-
/**
|
|
28
|
-
* @summary Retrieves a validator
|
|
29
|
-
*
|
|
30
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
31
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
32
|
-
*/
|
|
33
|
-
static get<T extends Validator>(validatorKey: string): T | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* @summary Registers the provided validators onto the registry
|
|
36
|
-
*
|
|
37
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
38
|
-
*/
|
|
39
|
-
static register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
40
|
-
/**
|
|
41
|
-
* @summary Builds the key to store as Metadata under Reflections
|
|
42
|
-
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
43
|
-
*
|
|
44
|
-
* @param {string} key
|
|
45
|
-
*/
|
|
46
|
-
static key(key: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* @summary Returns all registered validation keys
|
|
49
|
-
*/
|
|
50
|
-
static keys(): string[];
|
|
51
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { ValidatorRegistry } from "./Validators/ValidatorRegistry";
|
|
2
|
-
import { ValidationKeys } from "./Validators/constants";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Static class acting as a namespace for the Validation
|
|
5
|
-
*
|
|
6
|
-
* @class Validation
|
|
7
|
-
* @static
|
|
8
|
-
*
|
|
9
|
-
* @category Validation
|
|
10
|
-
*/
|
|
11
|
-
export class Validation {
|
|
12
|
-
static { this.actingValidatorRegistry = undefined; }
|
|
13
|
-
constructor() { }
|
|
14
|
-
/**
|
|
15
|
-
* @summary Defines the acting ValidatorRegistry
|
|
16
|
-
*
|
|
17
|
-
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
18
|
-
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
19
|
-
*/
|
|
20
|
-
static setRegistry(validatorRegistry, migrationHandler) {
|
|
21
|
-
if (migrationHandler && Validation.actingValidatorRegistry)
|
|
22
|
-
Validation.actingValidatorRegistry.getKeys().forEach((k) => {
|
|
23
|
-
const validator = validatorRegistry.get(k);
|
|
24
|
-
if (validator)
|
|
25
|
-
validatorRegistry.register(migrationHandler(validator));
|
|
26
|
-
});
|
|
27
|
-
Validation.actingValidatorRegistry = validatorRegistry;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @summary Returns the current ValidatorRegistry
|
|
31
|
-
*
|
|
32
|
-
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
33
|
-
*/
|
|
34
|
-
static getRegistry() {
|
|
35
|
-
if (!Validation.actingValidatorRegistry)
|
|
36
|
-
Validation.actingValidatorRegistry = new ValidatorRegistry();
|
|
37
|
-
return Validation.actingValidatorRegistry;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @summary Retrieves a validator
|
|
41
|
-
*
|
|
42
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
43
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
44
|
-
*/
|
|
45
|
-
static get(validatorKey) {
|
|
46
|
-
return Validation.getRegistry().get(validatorKey);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @summary Registers the provided validators onto the registry
|
|
50
|
-
*
|
|
51
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
52
|
-
*/
|
|
53
|
-
static register(...validator) {
|
|
54
|
-
return Validation.getRegistry().register(...validator);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @summary Builds the key to store as Metadata under Reflections
|
|
58
|
-
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
59
|
-
*
|
|
60
|
-
* @param {string} key
|
|
61
|
-
*/
|
|
62
|
-
static key(key) {
|
|
63
|
-
return ValidationKeys.REFLECT + key;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @summary Returns all registered validation keys
|
|
67
|
-
*/
|
|
68
|
-
static keys() {
|
|
69
|
-
return this.getRegistry().getKeys();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Date Validator
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
6
|
-
*
|
|
7
|
-
* @class DateValidator
|
|
8
|
-
* @extends Validator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class DateValidator extends Validator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {Date | string} value
|
|
18
|
-
* @param {string} format
|
|
19
|
-
* @param {string} [message]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: Date | string, format: string, message?: string): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { ValidationKeys, DEFAULT_ERROR_MESSAGES } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Date Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
17
|
-
*
|
|
18
|
-
* @class DateValidator
|
|
19
|
-
* @extends Validator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let DateValidator = class DateValidator extends Validator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.DATE) {
|
|
25
|
-
super(message, Number.name, Date.name, String.name);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {Date | string} value
|
|
31
|
-
* @param {string} format
|
|
32
|
-
* @param {string} [message]
|
|
33
|
-
*
|
|
34
|
-
* @return {string | undefined}
|
|
35
|
-
*
|
|
36
|
-
* @override
|
|
37
|
-
*
|
|
38
|
-
* @see Validator#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
hasErrors(value, format, message) {
|
|
41
|
-
if (value === undefined)
|
|
42
|
-
return;
|
|
43
|
-
if (typeof value === "string")
|
|
44
|
-
value = new Date(value);
|
|
45
|
-
if (Number.isNaN(value.getDate()))
|
|
46
|
-
return this.getMessage(message || this.message);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
DateValidator = __decorate([
|
|
50
|
-
validator(ValidationKeys.DATE),
|
|
51
|
-
__metadata("design:paramtypes", [String])
|
|
52
|
-
], DateValidator);
|
|
53
|
-
export { DateValidator };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Email Validator
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
6
|
-
*
|
|
7
|
-
* @class EmailValidator
|
|
8
|
-
* @extends PatternValidator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class EmailValidator extends PatternValidator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @param {RegExp} [pattern]
|
|
19
|
-
* @param {string} [message]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: string, pattern?: RegExp, message?: string): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { ValidationKeys, DEFAULT_ERROR_MESSAGES, DEFAULT_PATTERNS, } from "./constants";
|
|
11
|
-
import { PatternValidator } from "./PatternValidator";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Email Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
17
|
-
*
|
|
18
|
-
* @class EmailValidator
|
|
19
|
-
* @extends PatternValidator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let EmailValidator = class EmailValidator extends PatternValidator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.EMAIL) {
|
|
25
|
-
super(message);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {RegExp} [pattern]
|
|
32
|
-
* @param {string} [message]
|
|
33
|
-
*
|
|
34
|
-
* @return {string | undefined}
|
|
35
|
-
*
|
|
36
|
-
* @override
|
|
37
|
-
*
|
|
38
|
-
* @see Validator#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
hasErrors(value, pattern, message) {
|
|
41
|
-
return super.hasErrors(value, pattern || DEFAULT_PATTERNS.EMAIL, message);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
EmailValidator = __decorate([
|
|
45
|
-
validator(ValidationKeys.EMAIL),
|
|
46
|
-
__metadata("design:paramtypes", [String])
|
|
47
|
-
], EmailValidator);
|
|
48
|
-
export { EmailValidator };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary List Validator
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
6
|
-
*
|
|
7
|
-
* @class ListValidator
|
|
8
|
-
* @extends Validator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class ListValidator extends Validator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {any[] | Set<any>} value
|
|
18
|
-
* @param {string} clazz
|
|
19
|
-
* @param {string} [message]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: any[] | Set<any>, clazz: string[], message?: string): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary List Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
17
|
-
*
|
|
18
|
-
* @class ListValidator
|
|
19
|
-
* @extends Validator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let ListValidator = class ListValidator extends Validator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.LIST) {
|
|
25
|
-
super(message, Array.name, Set.name);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {any[] | Set<any>} value
|
|
31
|
-
* @param {string} clazz
|
|
32
|
-
* @param {string} [message]
|
|
33
|
-
*
|
|
34
|
-
* @return {string | undefined}
|
|
35
|
-
*
|
|
36
|
-
* @override
|
|
37
|
-
*
|
|
38
|
-
* @see Validator#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
hasErrors(value, clazz, message) {
|
|
41
|
-
if (!value || (Array.isArray(value) ? !value.length : !value.size))
|
|
42
|
-
return;
|
|
43
|
-
clazz = Array.isArray(clazz) ? clazz : [clazz];
|
|
44
|
-
let val, isValid = true;
|
|
45
|
-
for (let i = 0; i < (Array.isArray(value) ? value.length : value.size); i++) {
|
|
46
|
-
val = value[i];
|
|
47
|
-
switch (typeof val) {
|
|
48
|
-
case "object":
|
|
49
|
-
case "function":
|
|
50
|
-
isValid = clazz.includes(val.constructor?.name);
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
isValid = clazz.some((c) => typeof val === c.toLowerCase());
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return isValid
|
|
58
|
-
? undefined
|
|
59
|
-
: this.getMessage(message || this.message, clazz);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
ListValidator = __decorate([
|
|
63
|
-
validator(ValidationKeys.LIST),
|
|
64
|
-
__metadata("design:paramtypes", [String])
|
|
65
|
-
], ListValidator);
|
|
66
|
-
export { ListValidator };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Maximum Length Validator
|
|
4
|
-
* @description Validates strings and Arrays on their maximum length
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
7
|
-
*
|
|
8
|
-
* @class MinLengthValidator
|
|
9
|
-
* @extends Validator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class MaxLengthValidator extends Validator {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {number} maxlength
|
|
20
|
-
* @param {string} [message]
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: string | any[], maxlength: number, message?: string): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { ValidationKeys, DEFAULT_ERROR_MESSAGES } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Maximum Length Validator
|
|
15
|
-
* @description Validates strings and Arrays on their maximum length
|
|
16
|
-
*
|
|
17
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
18
|
-
*
|
|
19
|
-
* @class MinLengthValidator
|
|
20
|
-
* @extends Validator
|
|
21
|
-
*
|
|
22
|
-
* @category Validators
|
|
23
|
-
*/
|
|
24
|
-
let MaxLengthValidator = class MaxLengthValidator extends Validator {
|
|
25
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
|
|
26
|
-
super(message, String.name, Array.name);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @summary Validates a model
|
|
30
|
-
*
|
|
31
|
-
* @param {string} value
|
|
32
|
-
* @param {number} maxlength
|
|
33
|
-
* @param {string} [message]
|
|
34
|
-
*
|
|
35
|
-
* @return {string | undefined}
|
|
36
|
-
*
|
|
37
|
-
* @override
|
|
38
|
-
*
|
|
39
|
-
* @see Validator#hasErrors
|
|
40
|
-
*/
|
|
41
|
-
hasErrors(value, maxlength, message) {
|
|
42
|
-
if (typeof value === "undefined")
|
|
43
|
-
return;
|
|
44
|
-
return value.length > maxlength
|
|
45
|
-
? this.getMessage(message || this.message, maxlength)
|
|
46
|
-
: undefined;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
MaxLengthValidator = __decorate([
|
|
50
|
-
validator(ValidationKeys.MAX_LENGTH),
|
|
51
|
-
__metadata("design:paramtypes", [String])
|
|
52
|
-
], MaxLengthValidator);
|
|
53
|
-
export { MaxLengthValidator };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Max Validator
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
6
|
-
*
|
|
7
|
-
* @class MaxValidator
|
|
8
|
-
* @extends Validator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class MaxValidator extends Validator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a Model
|
|
16
|
-
*
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @param {number | Date | string} max
|
|
19
|
-
* @param {string} [message]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: number | Date | string, max: number | Date | string, message?: string): string | undefined;
|
|
28
|
-
}
|