@decaf-ts/decorator-validation 1.4.21 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/dist/decorator-validation.bundle.min.js +1 -1
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -0
- package/dist/esm/decorator-validation.bundle.min.esm.js +1 -1
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/model/Model.d.ts +1 -2
- package/lib/esm/model/Model.js +3 -4
- package/lib/esm/model/ModelErrorDefinition.d.ts +0 -0
- package/lib/esm/model/ModelErrorDefinition.js +0 -0
- package/lib/esm/model/Registry.d.ts +0 -0
- package/lib/esm/model/Registry.js +0 -0
- package/lib/esm/model/constants.d.ts +0 -0
- package/lib/esm/model/constants.js +0 -0
- package/lib/esm/model/construction.d.ts +0 -0
- package/lib/esm/model/construction.js +0 -0
- package/lib/esm/model/decorators.d.ts +0 -0
- package/lib/esm/model/decorators.js +0 -0
- package/lib/esm/model/index.d.ts +0 -0
- package/lib/esm/model/index.js +0 -0
- package/lib/esm/model/types.d.ts +0 -0
- package/lib/esm/model/types.js +0 -0
- package/lib/esm/model/utils.d.ts +0 -0
- package/lib/esm/model/utils.js +0 -0
- package/lib/esm/model/validation.d.ts +0 -0
- package/lib/esm/model/validation.js +3 -2
- package/lib/esm/utils/constants.d.ts +0 -0
- package/lib/esm/utils/constants.js +0 -0
- package/lib/esm/utils/dates.d.ts +0 -0
- package/lib/esm/utils/dates.js +0 -0
- package/lib/esm/utils/decorators.d.ts +0 -0
- package/lib/esm/utils/decorators.js +0 -0
- package/lib/esm/utils/hashing.d.ts +0 -0
- package/lib/esm/utils/hashing.js +0 -0
- package/lib/esm/utils/index.d.ts +0 -0
- package/lib/esm/utils/index.js +0 -0
- package/lib/esm/utils/registry.d.ts +0 -0
- package/lib/esm/utils/registry.js +0 -0
- package/lib/esm/utils/serialization.d.ts +0 -0
- package/lib/esm/utils/serialization.js +0 -0
- package/lib/esm/utils/strings.d.ts +0 -0
- package/lib/esm/utils/strings.js +0 -0
- package/lib/esm/validation/Validation.d.ts +0 -0
- package/lib/esm/validation/Validation.js +0 -0
- package/lib/esm/validation/Validators/DateValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/DateValidator.js +6 -5
- package/lib/esm/validation/Validators/EmailValidator.d.ts +3 -4
- package/lib/esm/validation/Validators/EmailValidator.js +7 -5
- package/lib/esm/validation/Validators/ListValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/ListValidator.js +4 -5
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MaxLengthValidator.js +4 -5
- package/lib/esm/validation/Validators/MaxValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MaxValidator.js +5 -5
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MinLengthValidator.js +5 -6
- package/lib/esm/validation/Validators/MinValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MinValidator.js +5 -5
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +3 -4
- package/lib/esm/validation/Validators/PasswordValidator.js +6 -4
- package/lib/esm/validation/Validators/PatternValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/PatternValidator.js +5 -5
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +3 -3
- package/lib/esm/validation/Validators/RequiredValidator.js +7 -5
- package/lib/esm/validation/Validators/StepValidator.d.ts +7 -4
- package/lib/esm/validation/Validators/StepValidator.js +5 -5
- package/lib/esm/validation/Validators/TypeValidator.d.ts +9 -7
- package/lib/esm/validation/Validators/TypeValidator.js +4 -4
- package/lib/esm/validation/Validators/URLValidator.d.ts +9 -3
- package/lib/esm/validation/Validators/URLValidator.js +3 -3
- package/lib/esm/validation/Validators/Validator.d.ts +6 -3
- package/lib/esm/validation/Validators/Validator.js +0 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -0
- package/lib/esm/validation/Validators/constants.d.ts +0 -0
- package/lib/esm/validation/Validators/constants.js +0 -0
- package/lib/esm/validation/Validators/decorators.d.ts +0 -0
- package/lib/esm/validation/Validators/decorators.js +0 -0
- package/lib/esm/validation/Validators/index.d.ts +0 -0
- package/lib/esm/validation/Validators/index.js +0 -0
- package/lib/esm/validation/Validators/types.d.ts +0 -0
- package/lib/esm/validation/Validators/types.js +0 -0
- package/lib/esm/validation/decorators.d.ts +0 -0
- package/lib/esm/validation/decorators.js +7 -7
- package/lib/esm/validation/index.d.ts +0 -0
- package/lib/esm/validation/index.js +0 -0
- package/lib/esm/validation/types.d.ts +0 -0
- package/lib/esm/validation/types.js +0 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/model/Model.cjs +3 -4
- package/lib/model/Model.d.ts +1 -2
- package/lib/model/ModelErrorDefinition.cjs +0 -0
- package/lib/model/ModelErrorDefinition.d.ts +0 -0
- package/lib/model/Registry.cjs +0 -0
- package/lib/model/Registry.d.ts +0 -0
- package/lib/model/constants.cjs +0 -0
- package/lib/model/constants.d.ts +0 -0
- package/lib/model/construction.cjs +0 -0
- package/lib/model/construction.d.ts +0 -0
- package/lib/model/decorators.cjs +0 -0
- package/lib/model/decorators.d.ts +0 -0
- package/lib/model/index.cjs +0 -0
- package/lib/model/index.d.ts +0 -0
- package/lib/model/types.cjs +0 -0
- package/lib/model/types.d.ts +0 -0
- package/lib/model/utils.cjs +0 -0
- package/lib/model/utils.d.ts +0 -0
- package/lib/model/validation.cjs +3 -2
- package/lib/model/validation.d.ts +0 -0
- package/lib/utils/constants.cjs +0 -0
- package/lib/utils/constants.d.ts +0 -0
- package/lib/utils/dates.cjs +0 -0
- package/lib/utils/dates.d.ts +0 -0
- package/lib/utils/decorators.cjs +0 -0
- package/lib/utils/decorators.d.ts +0 -0
- package/lib/utils/hashing.cjs +0 -0
- package/lib/utils/hashing.d.ts +0 -0
- package/lib/utils/index.cjs +0 -0
- package/lib/utils/index.d.ts +0 -0
- package/lib/utils/registry.cjs +0 -0
- package/lib/utils/registry.d.ts +0 -0
- package/lib/utils/serialization.cjs +0 -0
- package/lib/utils/serialization.d.ts +0 -0
- package/lib/utils/strings.cjs +0 -0
- package/lib/utils/strings.d.ts +0 -0
- package/lib/validation/Validation.cjs +0 -0
- package/lib/validation/Validation.d.ts +0 -0
- package/lib/validation/Validators/DateValidator.cjs +5 -4
- package/lib/validation/Validators/DateValidator.d.ts +7 -5
- package/lib/validation/Validators/EmailValidator.cjs +6 -4
- package/lib/validation/Validators/EmailValidator.d.ts +3 -4
- package/lib/validation/Validators/ListValidator.cjs +4 -5
- package/lib/validation/Validators/ListValidator.d.ts +7 -5
- package/lib/validation/Validators/MaxLengthValidator.cjs +4 -5
- package/lib/validation/Validators/MaxLengthValidator.d.ts +7 -5
- package/lib/validation/Validators/MaxValidator.cjs +4 -4
- package/lib/validation/Validators/MaxValidator.d.ts +7 -5
- package/lib/validation/Validators/MinLengthValidator.cjs +4 -5
- package/lib/validation/Validators/MinLengthValidator.d.ts +7 -5
- package/lib/validation/Validators/MinValidator.cjs +4 -4
- package/lib/validation/Validators/MinValidator.d.ts +7 -5
- package/lib/validation/Validators/PasswordValidator.cjs +6 -4
- package/lib/validation/Validators/PasswordValidator.d.ts +3 -4
- package/lib/validation/Validators/PatternValidator.cjs +4 -4
- package/lib/validation/Validators/PatternValidator.d.ts +7 -5
- package/lib/validation/Validators/RequiredValidator.cjs +6 -4
- package/lib/validation/Validators/RequiredValidator.d.ts +3 -3
- package/lib/validation/Validators/StepValidator.cjs +4 -4
- package/lib/validation/Validators/StepValidator.d.ts +7 -4
- package/lib/validation/Validators/TypeValidator.cjs +4 -4
- package/lib/validation/Validators/TypeValidator.d.ts +9 -7
- package/lib/validation/Validators/URLValidator.cjs +3 -3
- package/lib/validation/Validators/URLValidator.d.ts +9 -3
- package/lib/validation/Validators/Validator.cjs +0 -0
- package/lib/validation/Validators/Validator.d.ts +6 -3
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -0
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/lib/validation/Validators/constants.cjs +0 -0
- package/lib/validation/Validators/constants.d.ts +0 -0
- package/lib/validation/Validators/decorators.cjs +0 -0
- package/lib/validation/Validators/index.cjs +0 -0
- package/lib/validation/Validators/types.cjs +0 -0
- package/lib/validation/decorators.cjs +7 -7
- package/lib/validation/decorators.d.ts +0 -0
- package/lib/validation/index.cjs +0 -0
- package/lib/validation/index.d.ts +0 -0
- package/lib/validation/types.cjs +0 -0
- package/lib/validation/types.d.ts +0 -0
- package/package.json +1 -1
- package/lib/validation/Validators/decorators.d.ts +0 -12
|
@@ -28,8 +28,7 @@ let TypeValidator = class TypeValidator extends Validator {
|
|
|
28
28
|
/**
|
|
29
29
|
* @summary Validates a model
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {TypeValidatorOptions} options
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,9 +36,10 @@ let TypeValidator = class TypeValidator extends Validator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Validator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
39
|
+
hasErrors(value, options) {
|
|
41
40
|
if (value === undefined)
|
|
42
|
-
return; //
|
|
41
|
+
return; // Don't try and enforce type if undefined
|
|
42
|
+
const { types, message } = options;
|
|
43
43
|
if (!Reflection.evaluateDesignTypes(value, types))
|
|
44
44
|
return this.getMessage(message || this.message, typeof types === "string"
|
|
45
45
|
? types
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
1
|
+
import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
|
|
2
|
+
import { ValidatorOptions } from "./Validator";
|
|
3
|
+
export interface URLValidatorOptions extends ValidatorOptions {
|
|
4
|
+
types: string | string[] | {
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* @summary URL Validator
|
|
4
10
|
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
@@ -14,7 +20,7 @@ export declare class URLValidator extends PatternValidator {
|
|
|
14
20
|
* @summary Validates a model
|
|
15
21
|
*
|
|
16
22
|
* @param {string} value
|
|
17
|
-
* @param {
|
|
23
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
18
24
|
*
|
|
19
25
|
* @return {string | undefined}
|
|
20
26
|
*
|
|
@@ -22,5 +28,5 @@ export declare class URLValidator extends PatternValidator {
|
|
|
22
28
|
*
|
|
23
29
|
* @see Validator#hasErrors
|
|
24
30
|
*/
|
|
25
|
-
hasErrors(value: string,
|
|
31
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
26
32
|
}
|
|
@@ -27,7 +27,7 @@ let URLValidator = class URLValidator extends PatternValidator {
|
|
|
27
27
|
* @summary Validates a model
|
|
28
28
|
*
|
|
29
29
|
* @param {string} value
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
31
31
|
*
|
|
32
32
|
* @return {string | undefined}
|
|
33
33
|
*
|
|
@@ -35,8 +35,8 @@ let URLValidator = class URLValidator extends PatternValidator {
|
|
|
35
35
|
*
|
|
36
36
|
* @see Validator#hasErrors
|
|
37
37
|
*/
|
|
38
|
-
hasErrors(value,
|
|
39
|
-
return super.hasErrors(value, pattern || DEFAULT_PATTERNS.URL
|
|
38
|
+
hasErrors(value, options = {}) {
|
|
39
|
+
return super.hasErrors(value, { ...options, pattern: options.pattern || DEFAULT_PATTERNS.URL });
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
URLValidator = __decorate([
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type ValidatorOptions = {
|
|
2
|
+
message?: string;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* @summary Base Implementation for Validators
|
|
3
6
|
* @description Provides the underlying functionality for {@link Validator}s
|
|
@@ -10,7 +13,7 @@
|
|
|
10
13
|
* @abstract
|
|
11
14
|
* @category Validators
|
|
12
15
|
*/
|
|
13
|
-
export declare abstract class Validator {
|
|
16
|
+
export declare abstract class Validator<V extends ValidatorOptions = ValidatorOptions> {
|
|
14
17
|
readonly message: string;
|
|
15
18
|
readonly acceptedTypes?: string[];
|
|
16
19
|
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
@@ -30,11 +33,11 @@ export declare abstract class Validator {
|
|
|
30
33
|
/**
|
|
31
34
|
* @summary Validates an attribute
|
|
32
35
|
* @param {any} value
|
|
33
|
-
* @param {
|
|
36
|
+
* @param {ValidatorOptions} [options] Validate options for customizing the model validation behavior
|
|
34
37
|
*
|
|
35
38
|
* @abstract
|
|
36
39
|
*
|
|
37
40
|
* @see Model#hasErrors
|
|
38
41
|
*/
|
|
39
|
-
abstract hasErrors(value: any,
|
|
42
|
+
abstract hasErrors(value: any, options?: V): string | undefined;
|
|
40
43
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -32,7 +32,7 @@ export function required(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
|
|
|
32
32
|
*/
|
|
33
33
|
export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
|
|
34
34
|
return propMetadata(Validation.key(ValidationKeys.MIN), {
|
|
35
|
-
|
|
35
|
+
min: value,
|
|
36
36
|
message: message,
|
|
37
37
|
types: [Number.name, Date.name],
|
|
38
38
|
});
|
|
@@ -50,7 +50,7 @@ export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
|
|
|
50
50
|
*/
|
|
51
51
|
export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
|
|
52
52
|
return propMetadata(Validation.key(ValidationKeys.MAX), {
|
|
53
|
-
|
|
53
|
+
max: value,
|
|
54
54
|
message: message,
|
|
55
55
|
types: [Number.name, Date.name],
|
|
56
56
|
});
|
|
@@ -68,7 +68,7 @@ export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
|
|
|
68
68
|
*/
|
|
69
69
|
export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
|
|
70
70
|
return propMetadata(Validation.key(ValidationKeys.STEP), {
|
|
71
|
-
|
|
71
|
+
step: value,
|
|
72
72
|
message: message,
|
|
73
73
|
types: [Number.name],
|
|
74
74
|
});
|
|
@@ -86,7 +86,7 @@ export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
|
|
|
86
86
|
*/
|
|
87
87
|
export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
|
|
88
88
|
return propMetadata(Validation.key(ValidationKeys.MIN_LENGTH), {
|
|
89
|
-
|
|
89
|
+
minLength: value,
|
|
90
90
|
message: message,
|
|
91
91
|
types: [String.name, Array.name, Set.name],
|
|
92
92
|
});
|
|
@@ -104,7 +104,7 @@ export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
|
|
|
104
104
|
*/
|
|
105
105
|
export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
|
|
106
106
|
return propMetadata(Validation.key(ValidationKeys.MAX_LENGTH), {
|
|
107
|
-
|
|
107
|
+
maxLength: value,
|
|
108
108
|
message: message,
|
|
109
109
|
types: [String.name, Array.name, Set.name],
|
|
110
110
|
});
|
|
@@ -122,7 +122,7 @@ export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
|
|
|
122
122
|
*/
|
|
123
123
|
export function pattern(value, message = DEFAULT_ERROR_MESSAGES.PATTERN) {
|
|
124
124
|
return propMetadata(Validation.key(ValidationKeys.PATTERN), {
|
|
125
|
-
|
|
125
|
+
pattern: typeof value === "string" ? value : value.toString(),
|
|
126
126
|
message: message,
|
|
127
127
|
types: [String.name],
|
|
128
128
|
});
|
|
@@ -265,7 +265,7 @@ export function password(pattern = DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_EACH,
|
|
|
265
265
|
*/
|
|
266
266
|
export function list(clazz, collection = "Array", message = DEFAULT_ERROR_MESSAGES.LIST) {
|
|
267
267
|
return propMetadata(Validation.key(ValidationKeys.LIST), {
|
|
268
|
-
|
|
268
|
+
clazz: Array.isArray(clazz) ? clazz.map((c) => c.name) : [clazz.name],
|
|
269
269
|
type: collection,
|
|
270
270
|
message: message,
|
|
271
271
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/index.cjs
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/model/Model.cjs
CHANGED
|
@@ -78,7 +78,6 @@ class Model {
|
|
|
78
78
|
* @summary Deserializes a Model
|
|
79
79
|
* @param {string} str
|
|
80
80
|
*
|
|
81
|
-
* @param args
|
|
82
81
|
* @throws {Error} If it fails to parse the string, or if it fails to build the model
|
|
83
82
|
*/
|
|
84
83
|
static deserialize(str) {
|
|
@@ -153,7 +152,7 @@ class Model {
|
|
|
153
152
|
if (allDecorators.length) {
|
|
154
153
|
const listDec = allDecorators.find((d) => d.key === constants_2.ValidationKeys.LIST);
|
|
155
154
|
if (listDec) {
|
|
156
|
-
const clazzName = listDec.props.
|
|
155
|
+
const clazzName = listDec.props.clazz.find((t) => !constants_3.jsTypes.includes(t.toLowerCase()));
|
|
157
156
|
if (c === "Array")
|
|
158
157
|
self[prop] = self[prop].map((el) => {
|
|
159
158
|
return ["object", "function"].includes(typeof el) &&
|
|
@@ -274,8 +273,8 @@ class Model {
|
|
|
274
273
|
static equals(obj1, obj2, ...exceptions) {
|
|
275
274
|
return (0, reflection_1.isEqual)(obj1, obj2, ...exceptions);
|
|
276
275
|
}
|
|
277
|
-
static hasErrors(model, ...
|
|
278
|
-
return (0, validation_1.validate)(model, ...
|
|
276
|
+
static hasErrors(model, ...propsToIgnore) {
|
|
277
|
+
return (0, validation_1.validate)(model, ...propsToIgnore);
|
|
279
278
|
}
|
|
280
279
|
static serialize(model) {
|
|
281
280
|
const metadata = Reflect.getMetadata(Model.key(constants_1.ModelKeys.SERIALIZATION), model.constructor);
|
package/lib/model/Model.d.ts
CHANGED
|
@@ -55,7 +55,6 @@ export declare abstract class Model implements Validatable, Serializable, Hashab
|
|
|
55
55
|
* @summary Deserializes a Model
|
|
56
56
|
* @param {string} str
|
|
57
57
|
*
|
|
58
|
-
* @param args
|
|
59
58
|
* @throws {Error} If it fails to parse the string, or if it fails to build the model
|
|
60
59
|
*/
|
|
61
60
|
static deserialize(str: string): any;
|
|
@@ -127,7 +126,7 @@ export declare abstract class Model implements Validatable, Serializable, Hashab
|
|
|
127
126
|
static getMetadata<V extends Model>(model: V): any;
|
|
128
127
|
static getAttributes<V extends Model>(model: Constructor<V> | V): string[];
|
|
129
128
|
static equals<V extends Model>(obj1: V, obj2: V, ...exceptions: any[]): boolean;
|
|
130
|
-
static hasErrors<V extends Model>(model: V, ...
|
|
129
|
+
static hasErrors<V extends Model>(model: V, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
|
|
131
130
|
static serialize<V extends Model>(model: V): any;
|
|
132
131
|
static hash<V extends Model>(model: V): any;
|
|
133
132
|
/**
|
|
File without changes
|
|
File without changes
|
package/lib/model/Registry.cjs
CHANGED
|
File without changes
|
package/lib/model/Registry.d.ts
CHANGED
|
File without changes
|
package/lib/model/constants.cjs
CHANGED
|
File without changes
|
package/lib/model/constants.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/model/decorators.cjs
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/model/index.cjs
CHANGED
|
File without changes
|
package/lib/model/index.d.ts
CHANGED
|
File without changes
|
package/lib/model/types.cjs
CHANGED
|
File without changes
|
package/lib/model/types.d.ts
CHANGED
|
File without changes
|
package/lib/model/utils.cjs
CHANGED
|
File without changes
|
package/lib/model/utils.d.ts
CHANGED
|
File without changes
|
package/lib/model/validation.cjs
CHANGED
|
@@ -46,9 +46,10 @@ function validate(obj, ...propsToIgnore) {
|
|
|
46
46
|
if (!validator) {
|
|
47
47
|
throw new Error(`Missing validator for ${decorator.key}`);
|
|
48
48
|
}
|
|
49
|
-
const
|
|
49
|
+
const decoratorProps = decorator.key === constants_1.ModelKeys.TYPE
|
|
50
50
|
? [decorator.props]
|
|
51
|
-
:
|
|
51
|
+
: (decorator.props || {});
|
|
52
|
+
const err = validator.hasErrors(obj[prop.toString()], decoratorProps);
|
|
52
53
|
if (err) {
|
|
53
54
|
errs = errs || {};
|
|
54
55
|
errs[decorator.key] = err;
|
|
File without changes
|
package/lib/utils/constants.cjs
CHANGED
|
File without changes
|
package/lib/utils/constants.d.ts
CHANGED
|
File without changes
|
package/lib/utils/dates.cjs
CHANGED
|
File without changes
|
package/lib/utils/dates.d.ts
CHANGED
|
File without changes
|
package/lib/utils/decorators.cjs
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/utils/hashing.cjs
CHANGED
|
File without changes
|
package/lib/utils/hashing.d.ts
CHANGED
|
File without changes
|
package/lib/utils/index.cjs
CHANGED
|
File without changes
|
package/lib/utils/index.d.ts
CHANGED
|
File without changes
|
package/lib/utils/registry.cjs
CHANGED
|
File without changes
|
package/lib/utils/registry.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/utils/strings.cjs
CHANGED
|
File without changes
|
package/lib/utils/strings.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -31,8 +31,7 @@ let DateValidator = class DateValidator extends Validator_1.Validator {
|
|
|
31
31
|
* @summary Validates a model
|
|
32
32
|
*
|
|
33
33
|
* @param {Date | string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {DateValidatorOptions} [options]
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,13 +39,15 @@ let DateValidator = class DateValidator extends Validator_1.Validator {
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options = {}) {
|
|
44
43
|
if (value === undefined)
|
|
45
44
|
return;
|
|
46
45
|
if (typeof value === "string")
|
|
47
46
|
value = new Date(value);
|
|
48
|
-
if (Number.isNaN(value.getDate()))
|
|
47
|
+
if (Number.isNaN(value.getDate())) {
|
|
48
|
+
const { message = "" } = options;
|
|
49
49
|
return this.getMessage(message || this.message);
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
exports.DateValidator = DateValidator;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface DateValidatorOptions extends ValidatorOptions {
|
|
3
|
+
format?: string;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Date Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class DateValidator extends Validator {
|
|
15
|
+
export declare class DateValidator extends Validator<DateValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates a model
|
|
16
19
|
*
|
|
17
20
|
* @param {Date | string} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {DateValidatorOptions} [options]
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -24,5 +26,5 @@ export declare class DateValidator extends Validator {
|
|
|
24
26
|
*
|
|
25
27
|
* @see Validator#hasErrors
|
|
26
28
|
*/
|
|
27
|
-
hasErrors(value: Date | string,
|
|
29
|
+
hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
|
|
28
30
|
}
|
|
@@ -31,8 +31,7 @@ let EmailValidator = class EmailValidator extends PatternValidator_1.PatternVali
|
|
|
31
31
|
* @summary Validates a model
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {PatternValidatorOptions} [options]
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,8 +39,11 @@ let EmailValidator = class EmailValidator extends PatternValidator_1.PatternVali
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
44
|
-
return super.hasErrors(value,
|
|
42
|
+
hasErrors(value, options = {}) {
|
|
43
|
+
return super.hasErrors(value, {
|
|
44
|
+
...options,
|
|
45
|
+
pattern: options?.pattern || constants_1.DEFAULT_PATTERNS.EMAIL,
|
|
46
|
+
});
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
exports.EmailValidator = EmailValidator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
1
|
+
import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
|
|
2
2
|
/**
|
|
3
3
|
* @summary Email Validator
|
|
4
4
|
*
|
|
@@ -15,8 +15,7 @@ export declare class EmailValidator extends PatternValidator {
|
|
|
15
15
|
* @summary Validates a model
|
|
16
16
|
*
|
|
17
17
|
* @param {string} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
18
|
+
* @param {PatternValidatorOptions} [options]
|
|
20
19
|
*
|
|
21
20
|
* @return {string | undefined}
|
|
22
21
|
*
|
|
@@ -24,5 +23,5 @@ export declare class EmailValidator extends PatternValidator {
|
|
|
24
23
|
*
|
|
25
24
|
* @see Validator#hasErrors
|
|
26
25
|
*/
|
|
27
|
-
hasErrors(value: string,
|
|
26
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
28
27
|
}
|
|
@@ -31,8 +31,7 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
|
|
|
31
31
|
* @summary Validates a model
|
|
32
32
|
*
|
|
33
33
|
* @param {any[] | Set<any>} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {ListValidatorOptions} options
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,10 +39,10 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options) {
|
|
44
43
|
if (!value || (Array.isArray(value) ? !value.length : !value.size))
|
|
45
44
|
return;
|
|
46
|
-
clazz = Array.isArray(clazz) ? clazz : [clazz];
|
|
45
|
+
const clazz = Array.isArray(options.clazz) ? options.clazz : [options.clazz];
|
|
47
46
|
let val, isValid = true;
|
|
48
47
|
for (let i = 0; i < (Array.isArray(value) ? value.length : value.size); i++) {
|
|
49
48
|
val = value[i];
|
|
@@ -59,7 +58,7 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
|
|
|
59
58
|
}
|
|
60
59
|
return isValid
|
|
61
60
|
? undefined
|
|
62
|
-
: this.getMessage(message || this.message, clazz);
|
|
61
|
+
: this.getMessage(options.message || this.message, clazz);
|
|
63
62
|
}
|
|
64
63
|
};
|
|
65
64
|
exports.ListValidator = ListValidator;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface ListValidatorOptions extends ValidatorOptions {
|
|
3
|
+
clazz: string[];
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary List Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class ListValidator extends Validator {
|
|
15
|
+
export declare class ListValidator extends Validator<ListValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates a model
|
|
16
19
|
*
|
|
17
20
|
* @param {any[] | Set<any>} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {ListValidatorOptions} options
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -24,5 +26,5 @@ export declare class ListValidator extends Validator {
|
|
|
24
26
|
*
|
|
25
27
|
* @see Validator#hasErrors
|
|
26
28
|
*/
|
|
27
|
-
hasErrors(value: any[] | Set<any>,
|
|
29
|
+
hasErrors(value: any[] | Set<any>, options: ListValidatorOptions): string | undefined;
|
|
28
30
|
}
|
|
@@ -32,8 +32,7 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator_1.Validator
|
|
|
32
32
|
* @summary Validates a model
|
|
33
33
|
*
|
|
34
34
|
* @param {string} value
|
|
35
|
-
* @param {
|
|
36
|
-
* @param {string} [message]
|
|
35
|
+
* @param {MaxLengthValidatorOptions} options
|
|
37
36
|
*
|
|
38
37
|
* @return {string | undefined}
|
|
39
38
|
*
|
|
@@ -41,11 +40,11 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator_1.Validator
|
|
|
41
40
|
*
|
|
42
41
|
* @see Validator#hasErrors
|
|
43
42
|
*/
|
|
44
|
-
hasErrors(value,
|
|
43
|
+
hasErrors(value, options) {
|
|
45
44
|
if (typeof value === "undefined")
|
|
46
45
|
return;
|
|
47
|
-
return value.length >
|
|
48
|
-
? this.getMessage(message || this.message,
|
|
46
|
+
return value.length > options.maxLength
|
|
47
|
+
? this.getMessage(options.message || this.message, options.maxLength)
|
|
49
48
|
: undefined;
|
|
50
49
|
}
|
|
51
50
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface MaxLengthValidatorOptions extends ValidatorOptions {
|
|
3
|
+
maxLength: number;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Maximum Length Validator
|
|
4
7
|
* @description Validates strings and Arrays on their maximum length
|
|
@@ -10,14 +13,13 @@ import { Validator } from "./Validator";
|
|
|
10
13
|
*
|
|
11
14
|
* @category Validators
|
|
12
15
|
*/
|
|
13
|
-
export declare class MaxLengthValidator extends Validator {
|
|
16
|
+
export declare class MaxLengthValidator extends Validator<MaxLengthValidatorOptions> {
|
|
14
17
|
constructor(message?: string);
|
|
15
18
|
/**
|
|
16
19
|
* @summary Validates a model
|
|
17
20
|
*
|
|
18
21
|
* @param {string} value
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {string} [message]
|
|
22
|
+
* @param {MaxLengthValidatorOptions} options
|
|
21
23
|
*
|
|
22
24
|
* @return {string | undefined}
|
|
23
25
|
*
|
|
@@ -25,5 +27,5 @@ export declare class MaxLengthValidator extends Validator {
|
|
|
25
27
|
*
|
|
26
28
|
* @see Validator#hasErrors
|
|
27
29
|
*/
|
|
28
|
-
hasErrors(value: string | any[],
|
|
30
|
+
hasErrors(value: string | any[], options: MaxLengthValidatorOptions): string | undefined;
|
|
29
31
|
}
|
|
@@ -31,8 +31,7 @@ let MaxValidator = class MaxValidator extends Validator_1.Validator {
|
|
|
31
31
|
* @summary Validates a Model
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {MaxValidatorOptions} options
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,16 +39,17 @@ let MaxValidator = class MaxValidator extends Validator_1.Validator {
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options) {
|
|
44
43
|
if (typeof value === "undefined")
|
|
45
44
|
return;
|
|
45
|
+
let { max } = options;
|
|
46
46
|
if (value instanceof Date && !(max instanceof Date)) {
|
|
47
47
|
max = new Date(max);
|
|
48
48
|
if (Number.isNaN(max.getDate()))
|
|
49
49
|
throw new Error("Invalid Max param defined");
|
|
50
50
|
}
|
|
51
51
|
return value > max
|
|
52
|
-
? this.getMessage(message || this.message, max)
|
|
52
|
+
? this.getMessage(options.message || this.message, max)
|
|
53
53
|
: undefined;
|
|
54
54
|
}
|
|
55
55
|
};
|