@decaf-ts/decorator-validation 1.5.9 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +0 -0
- package/README.md +0 -0
- package/dist/decorator-validation.js +2 -0
- package/dist/{decorator-validation.bundle.min.js.LICENSE.txt → decorator-validation.js.LICENSE.txt} +0 -0
- package/dist/esm/decorator-validation.js +2 -0
- package/dist/esm/{decorator-validation.bundle.min.esm.js.LICENSE.txt → decorator-validation.js.LICENSE.txt} +0 -0
- package/{lib/esm → dist/types}/index.d.ts +1 -1
- package/{lib/esm → dist/types}/model/Model.d.ts +0 -0
- package/{lib/esm → dist/types}/model/ModelErrorDefinition.d.ts +0 -0
- package/{lib/esm → dist/types}/model/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/model/construction.d.ts +0 -0
- package/{lib/esm → dist/types}/model/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/model/index.d.ts +0 -0
- package/{lib/esm → dist/types}/model/types.d.ts +0 -0
- package/{lib/esm → dist/types}/model/validation.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/dates.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/hashing.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/index.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/registry.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/serialization.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/strings.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/types.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validation.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/DateValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/EmailValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/ListValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MaxLengthValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MaxValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MinLengthValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/MinValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/PasswordValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/PatternValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/RequiredValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/StepValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/TypeValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/URLValidator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/Validator.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/decorators.d.ts +0 -0
- package/dist/types/validation/Validators/index.d.ts +17 -0
- package/{lib/esm → dist/types}/validation/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/index.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/types.d.ts +0 -0
- package/lib/esm/index.js +3 -1
- package/lib/esm/model/Model.js +2 -0
- package/lib/esm/model/ModelErrorDefinition.js +2 -0
- package/lib/esm/model/constants.js +2 -0
- package/lib/esm/model/construction.js +2 -0
- package/lib/esm/model/decorators.js +2 -0
- package/lib/esm/model/index.js +2 -0
- package/lib/esm/model/types.js +2 -0
- package/lib/esm/model/validation.js +2 -0
- package/lib/esm/utils/constants.js +2 -0
- package/lib/esm/utils/dates.js +2 -0
- package/lib/esm/utils/decorators.js +2 -0
- package/lib/esm/utils/hashing.js +2 -0
- package/lib/esm/utils/index.js +2 -0
- package/lib/esm/utils/registry.js +2 -0
- package/lib/esm/utils/serialization.js +2 -0
- package/lib/esm/utils/strings.js +2 -0
- package/lib/esm/utils/types.js +2 -0
- package/lib/esm/validation/Validation.js +2 -0
- package/lib/esm/validation/Validators/DateValidator.js +2 -0
- package/lib/esm/validation/Validators/EmailValidator.js +2 -0
- package/lib/esm/validation/Validators/ListValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxValidator.js +2 -0
- package/lib/esm/validation/Validators/MinLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MinValidator.js +2 -0
- package/lib/esm/validation/Validators/PasswordValidator.js +2 -0
- package/lib/esm/validation/Validators/PatternValidator.js +2 -0
- package/lib/esm/validation/Validators/RequiredValidator.js +2 -0
- package/lib/esm/validation/Validators/StepValidator.js +2 -0
- package/lib/esm/validation/Validators/TypeValidator.js +2 -0
- package/lib/esm/validation/Validators/URLValidator.js +2 -0
- package/lib/esm/validation/Validators/Validator.js +2 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +2 -0
- package/lib/esm/validation/Validators/constants.js +2 -0
- package/lib/esm/validation/Validators/decorators.js +2 -0
- package/lib/esm/validation/Validators/index.js +2 -34
- package/lib/esm/validation/decorators.js +2 -0
- package/lib/esm/validation/index.js +2 -0
- package/lib/esm/validation/types.js +2 -0
- package/lib/index.cjs +3 -1
- package/lib/model/Model.cjs +2 -0
- package/lib/model/ModelErrorDefinition.cjs +2 -0
- package/lib/model/constants.cjs +2 -0
- package/lib/model/construction.cjs +2 -0
- package/lib/model/decorators.cjs +2 -0
- package/lib/model/index.cjs +2 -0
- package/lib/model/types.cjs +2 -0
- package/lib/model/validation.cjs +2 -0
- package/lib/utils/constants.cjs +2 -0
- package/lib/utils/dates.cjs +2 -0
- package/lib/utils/decorators.cjs +2 -0
- package/lib/utils/hashing.cjs +2 -0
- package/lib/utils/index.cjs +2 -0
- package/lib/utils/registry.cjs +2 -0
- package/lib/utils/serialization.cjs +2 -0
- package/lib/utils/strings.cjs +2 -0
- package/lib/utils/types.cjs +2 -0
- package/lib/validation/Validation.cjs +2 -0
- package/lib/validation/Validators/DateValidator.cjs +2 -0
- package/lib/validation/Validators/EmailValidator.cjs +2 -0
- package/lib/validation/Validators/ListValidator.cjs +2 -0
- package/lib/validation/Validators/MaxLengthValidator.cjs +2 -0
- package/lib/validation/Validators/MaxValidator.cjs +2 -0
- package/lib/validation/Validators/MinLengthValidator.cjs +2 -0
- package/lib/validation/Validators/MinValidator.cjs +2 -0
- package/lib/validation/Validators/PasswordValidator.cjs +2 -0
- package/lib/validation/Validators/PatternValidator.cjs +2 -0
- package/lib/validation/Validators/RequiredValidator.cjs +2 -0
- package/lib/validation/Validators/StepValidator.cjs +2 -0
- package/lib/validation/Validators/TypeValidator.cjs +2 -0
- package/lib/validation/Validators/URLValidator.cjs +2 -0
- package/lib/validation/Validators/Validator.cjs +2 -0
- package/lib/validation/Validators/ValidatorRegistry.cjs +2 -0
- package/lib/validation/Validators/constants.cjs +2 -0
- package/lib/validation/Validators/decorators.cjs +2 -0
- package/lib/validation/Validators/index.cjs +2 -35
- package/lib/validation/decorators.cjs +2 -0
- package/lib/validation/index.cjs +2 -0
- package/lib/validation/types.cjs +2 -0
- package/package.json +3 -2
- package/dist/decorator-validation.bundle.min.js +0 -2
- package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
- package/lib/esm/validation/Validators/index.d.ts +0 -51
- package/lib/index.d.ts +0 -42
- package/lib/model/Model.d.ts +0 -204
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/index.d.ts +0 -7
- package/lib/model/types.d.ts +0 -79
- package/lib/model/validation.d.ts +0 -14
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/hashing.d.ts +0 -38
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/serialization.d.ts +0 -53
- package/lib/utils/strings.d.ts +0 -25
- package/lib/utils/types.d.ts +0 -29
- package/lib/validation/Validation.d.ts +0 -51
- package/lib/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -28
- package/lib/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/validation/Validators/TypeValidator.d.ts +0 -25
- package/lib/validation/Validators/URLValidator.d.ts +0 -27
- package/lib/validation/Validators/Validator.d.ts +0 -41
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.d.ts +0 -134
package/lib/model/types.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
2
|
-
import { Model } from "./Model";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Typo of a Model builder function
|
|
5
|
-
* @memberOf module:decorator-validation.Construction
|
|
6
|
-
* @category Construction
|
|
7
|
-
*/
|
|
8
|
-
export type ModelBuilderFunction = <T extends Model>(self: T, obj?: T | Record<string, any>) => T;
|
|
9
|
-
/**
|
|
10
|
-
* @summary Definition of a Model Constructor Argument
|
|
11
|
-
*
|
|
12
|
-
* @memberOf module:decorator-validation.Model
|
|
13
|
-
* @category Model
|
|
14
|
-
*
|
|
15
|
-
* @see ModelConstructor
|
|
16
|
-
*/
|
|
17
|
-
export type ModelArg<T> = T | Record<string, any>;
|
|
18
|
-
/**
|
|
19
|
-
* @summary Definition of a Class Constructor
|
|
20
|
-
* @description Generic type for Constructor functions
|
|
21
|
-
*
|
|
22
|
-
* @typedef Constructor
|
|
23
|
-
*
|
|
24
|
-
* @param {any[]} [args]
|
|
25
|
-
* @memberOf module:decorator-validation.Model
|
|
26
|
-
* @category Model
|
|
27
|
-
*/
|
|
28
|
-
export type Constructor<T> = {
|
|
29
|
-
new (...args: any[]): T;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* @summary Definition of a Model Constructor
|
|
33
|
-
* @description Generic type for all Model Constructor functions
|
|
34
|
-
*
|
|
35
|
-
* @typedef ModelConstructor
|
|
36
|
-
*
|
|
37
|
-
* @param {ModelArg<T>} [model]
|
|
38
|
-
* @param {any[]} [args]
|
|
39
|
-
* @memberOf module:decorator-validation.Model
|
|
40
|
-
* @category Construction
|
|
41
|
-
*/
|
|
42
|
-
export type ModelConstructor<T extends Model> = {
|
|
43
|
-
new (model?: ModelArg<T>, ...args: any[]): T;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* @summary Defines the Validation API for validatable models
|
|
47
|
-
* @interface Validatable
|
|
48
|
-
*
|
|
49
|
-
* @category Validation
|
|
50
|
-
*/
|
|
51
|
-
export interface Validatable {
|
|
52
|
-
/**
|
|
53
|
-
* @summary Validates the model and returns the {@link ModelErrorDefinition} if any
|
|
54
|
-
* @param {any} [args]
|
|
55
|
-
*
|
|
56
|
-
* @method
|
|
57
|
-
*/
|
|
58
|
-
hasErrors(...args: any[]): ModelErrorDefinition | undefined;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @summary Serializable interface
|
|
62
|
-
*
|
|
63
|
-
* @interface Serializable
|
|
64
|
-
*
|
|
65
|
-
* @category Serialization
|
|
66
|
-
*/
|
|
67
|
-
export interface Serializable {
|
|
68
|
-
/**
|
|
69
|
-
* @summary serializes the model
|
|
70
|
-
* @method
|
|
71
|
-
*/
|
|
72
|
-
serialize(): string;
|
|
73
|
-
}
|
|
74
|
-
export interface Hashable {
|
|
75
|
-
hash(): string;
|
|
76
|
-
}
|
|
77
|
-
export interface Comparable<T> {
|
|
78
|
-
equals(other: T, ...args: any[]): boolean;
|
|
79
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
2
|
-
import { Model } from "./Model";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Analyses the decorations of the properties and validates the obj according to them
|
|
5
|
-
*
|
|
6
|
-
* @typedef T extends Model
|
|
7
|
-
* @prop {T} obj Model object to validate
|
|
8
|
-
* @prop {string[]} [propsToIgnore] object properties to ignore in the validation
|
|
9
|
-
*
|
|
10
|
-
* @function validate
|
|
11
|
-
* @memberOf module:decorator-validation.Validation
|
|
12
|
-
* @category Validation
|
|
13
|
-
*/
|
|
14
|
-
export declare function validate<T extends Model>(obj: T, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
|
package/lib/utils/constants.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Defines the various Model keys used for reflection
|
|
3
|
-
*
|
|
4
|
-
* @property {string} REFLECT prefix to all other keys
|
|
5
|
-
* @property {string} TYPE type key
|
|
6
|
-
* @property {string} PARAMS method params key
|
|
7
|
-
* @property {string} RETURN method return key
|
|
8
|
-
* @property {string} MODEL model key
|
|
9
|
-
* @property {string} ANCHOR anchor key. will serve as a ghost property in the model
|
|
10
|
-
*
|
|
11
|
-
* @constant ModelKeys
|
|
12
|
-
* @memberOf module:decorator-validation.Model
|
|
13
|
-
* @category Model
|
|
14
|
-
*/
|
|
15
|
-
export declare enum ModelKeys {
|
|
16
|
-
REFLECT = "decaf.model.",
|
|
17
|
-
TYPE = "design:type",
|
|
18
|
-
PARAMS = "design:paramtypes",
|
|
19
|
-
RETURN = "design:returntype",
|
|
20
|
-
MODEL = "model",
|
|
21
|
-
ANCHOR = "__model",
|
|
22
|
-
CONSTRUCTION = "constructed-by",
|
|
23
|
-
ATTRIBUTE = "__attributes",
|
|
24
|
-
HASHING = "hashing",
|
|
25
|
-
SERIALIZATION = "serialization"
|
|
26
|
-
}
|
package/lib/utils/dates.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Reverses the process from {@link formatDate}
|
|
4
|
-
*
|
|
5
|
-
* @param {string} date the date string to be converted back into date
|
|
6
|
-
* @param {string} format the date format
|
|
7
|
-
* @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?)
|
|
8
|
-
*
|
|
9
|
-
* @function dateFromFormat
|
|
10
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
11
|
-
* @category Format
|
|
12
|
-
*/
|
|
13
|
-
export declare function dateFromFormat(date: string, format: string): Date;
|
|
14
|
-
/**
|
|
15
|
-
* @summary Binds a date format to a string
|
|
16
|
-
* @param {Date} [date]
|
|
17
|
-
* @param {string} [format]
|
|
18
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
19
|
-
* @category Utilities
|
|
20
|
-
*/
|
|
21
|
-
export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* @summary Helper function to be used instead of instanceOf Date
|
|
24
|
-
* @param date
|
|
25
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
26
|
-
* @category Validation
|
|
27
|
-
*/
|
|
28
|
-
export declare function isValidDate(date: any): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* @summary Util function to pad numbers
|
|
31
|
-
* @param {number} num
|
|
32
|
-
*
|
|
33
|
-
* @return {string}
|
|
34
|
-
*
|
|
35
|
-
* @function twoDigitPad
|
|
36
|
-
* @memberOf module:decorator-validation.Utils.Format
|
|
37
|
-
* @category Format
|
|
38
|
-
*/
|
|
39
|
-
export declare function twoDigitPad(num: number): string;
|
|
40
|
-
/**
|
|
41
|
-
* @summary Date Format Handling
|
|
42
|
-
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
43
|
-
*
|
|
44
|
-
* <pre>
|
|
45
|
-
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
46
|
-
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
47
|
-
* You can display date, time, AM/PM, etc.
|
|
48
|
-
*
|
|
49
|
-
* Date and Time Patterns
|
|
50
|
-
* yy = 2-digit year; yyyy = full year
|
|
51
|
-
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
52
|
-
* EEEE = full weekday name; EEE = short weekday name
|
|
53
|
-
* d = digit day; dd = 2-digit day
|
|
54
|
-
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
55
|
-
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
56
|
-
* s = seconds; ss = 2-digit seconds
|
|
57
|
-
* S = miliseconds
|
|
58
|
-
* </pre>
|
|
59
|
-
*
|
|
60
|
-
* @param {Date} date
|
|
61
|
-
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
62
|
-
* @return {string} the formatted date
|
|
63
|
-
*
|
|
64
|
-
* @function formatDate
|
|
65
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
66
|
-
* @category Format
|
|
67
|
-
*/
|
|
68
|
-
export declare function formatDate(date: Date, patternStr?: string): string;
|
|
69
|
-
/**
|
|
70
|
-
* @summary Parses a date from a specified format
|
|
71
|
-
* @param {string} format
|
|
72
|
-
* @param {string | Date | number} [v]
|
|
73
|
-
* @memberOf module:decorator-validation.Utils.Dates
|
|
74
|
-
* @category Format
|
|
75
|
-
*/
|
|
76
|
-
export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
|
package/lib/utils/hashing.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Mimics Java's String's Hash implementation
|
|
3
|
-
*
|
|
4
|
-
* @param {string | number | symbol | Date} obj
|
|
5
|
-
* @return {number} hash value of obj
|
|
6
|
-
*
|
|
7
|
-
* @function hashCode
|
|
8
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
9
|
-
* @category Hashing
|
|
10
|
-
*/
|
|
11
|
-
export declare function hashCode(obj: string | number | symbol | Date): string;
|
|
12
|
-
/**
|
|
13
|
-
* @summary Defines teh type for a Hashing function
|
|
14
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
15
|
-
* @category Hashing
|
|
16
|
-
*/
|
|
17
|
-
export type HashingFunction = (value: any, ...args: any[]) => string;
|
|
18
|
-
/**
|
|
19
|
-
* @summary Hashes an object by combining the hash of all its properties
|
|
20
|
-
*
|
|
21
|
-
* @param {Record<string, any>} obj
|
|
22
|
-
* @return {string} the resulting hash
|
|
23
|
-
*
|
|
24
|
-
* @function hashObj
|
|
25
|
-
* @memberOf module:decorator-validation.Utils.Hashing
|
|
26
|
-
* @category Hashing
|
|
27
|
-
*/
|
|
28
|
-
export declare function hashObj(obj: Record<string, any> | any[]): string;
|
|
29
|
-
export declare const DefaultHashingMethod = "default";
|
|
30
|
-
export declare class Hashing {
|
|
31
|
-
private static current;
|
|
32
|
-
private static cache;
|
|
33
|
-
private constructor();
|
|
34
|
-
private static get;
|
|
35
|
-
static register(key: string, func: HashingFunction, setDefault?: boolean): void;
|
|
36
|
-
static hash(obj: any, method?: string, ...args: any[]): any;
|
|
37
|
-
static setDefault(method: string): void;
|
|
38
|
-
}
|
package/lib/utils/index.d.ts
DELETED
package/lib/utils/registry.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "../model/types";
|
|
2
|
-
import { Serializer } from "./types";
|
|
3
|
-
import { Model } from "../model/Model";
|
|
4
|
-
export declare const DefaultSerializationMethod = "json";
|
|
5
|
-
/**
|
|
6
|
-
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
7
|
-
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
8
|
-
* and therefore should not be used for hashing purposes
|
|
9
|
-
*
|
|
10
|
-
* To keep dependencies low, we will not implement this, but we recommend
|
|
11
|
-
* implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries
|
|
12
|
-
*
|
|
13
|
-
* @class JSONSerializer
|
|
14
|
-
* @implements Serializer
|
|
15
|
-
*
|
|
16
|
-
* @category Serialization
|
|
17
|
-
*/
|
|
18
|
-
export declare class JSONSerializer<T extends Model> implements Serializer<T> {
|
|
19
|
-
constructor();
|
|
20
|
-
/**
|
|
21
|
-
* @summary prepares the model for serialization
|
|
22
|
-
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
23
|
-
* so the object can be recognized upon deserialization
|
|
24
|
-
*
|
|
25
|
-
* @param {T} model
|
|
26
|
-
* @protected
|
|
27
|
-
*/
|
|
28
|
-
protected preSerialize(model: T): Record<string, any>;
|
|
29
|
-
/**
|
|
30
|
-
* @summary Rebuilds a model from a serialization
|
|
31
|
-
* @param {string} str
|
|
32
|
-
*
|
|
33
|
-
* @throws {Error} If it fails to parse the string, or to build the model
|
|
34
|
-
*/
|
|
35
|
-
deserialize(str: string): T;
|
|
36
|
-
/**
|
|
37
|
-
* @summary Serializes a model
|
|
38
|
-
* @param {T} model
|
|
39
|
-
*
|
|
40
|
-
* @throws {Error} if fails to serialize
|
|
41
|
-
*/
|
|
42
|
-
serialize(model: T): string;
|
|
43
|
-
}
|
|
44
|
-
export declare class Serialization {
|
|
45
|
-
private static current;
|
|
46
|
-
private static cache;
|
|
47
|
-
private constructor();
|
|
48
|
-
private static get;
|
|
49
|
-
static register(key: string, func: Constructor<Serializer<any>>, setDefault?: boolean): void;
|
|
50
|
-
static serialize(obj: any, method?: string, ...args: any[]): any;
|
|
51
|
-
static deserialize(obj: string, method?: string, ...args: any[]): any;
|
|
52
|
-
static setDefault(method: string): void;
|
|
53
|
-
}
|
package/lib/utils/strings.d.ts
DELETED
|
@@ -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/utils/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Model } from "../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
|
-
* @param args
|
|
14
|
-
* @method
|
|
15
|
-
*
|
|
16
|
-
* @throws {Error}
|
|
17
|
-
*/
|
|
18
|
-
serialize(model: T, ...args: any[]): string;
|
|
19
|
-
/**
|
|
20
|
-
* @summary Rebuilds a model from serialization
|
|
21
|
-
* @param {string} str
|
|
22
|
-
*
|
|
23
|
-
* @param args
|
|
24
|
-
* @method
|
|
25
|
-
*
|
|
26
|
-
* @throws {Error}
|
|
27
|
-
*/
|
|
28
|
-
deserialize(str: string, ...args: any[]): T;
|
|
29
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validators/Validator";
|
|
2
|
-
import { IValidatorRegistry, ValidatorDefinition } from "./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,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { DateValidatorOptions } 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<DateValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {Date | string} value
|
|
19
|
-
* @param {DateValidatorOptions} [options]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
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
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {PatternValidatorOptions} [options]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { ListValidatorOptions } 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<ListValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {any[] | Set<any>} value
|
|
19
|
-
* @param {ListValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: any[] | Set<any>, options: ListValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MaxLengthValidatorOptions } from "../types";
|
|
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<MaxLengthValidatorOptions> {
|
|
15
|
-
constructor(message?: string);
|
|
16
|
-
/**
|
|
17
|
-
* @summary Validates a model
|
|
18
|
-
*
|
|
19
|
-
* @param {string} value
|
|
20
|
-
* @param {MaxLengthValidatorOptions} options
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: string | any[], options: MaxLengthValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MaxValidatorOptions } 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<MaxValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a Model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {MaxValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: number | Date | string, options: MaxValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MinLengthValidatorOptions } 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<MinLengthValidatorOptions> {
|
|
15
|
-
constructor(message?: string);
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {string | Array} value
|
|
19
|
-
* @param {MinLengthValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @memberOf MinLengthValidator
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: string | any[], options: MinLengthValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MinValidatorOptions } 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<MinValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates Model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {MaxValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: number | Date | string, options: MinValidatorOptions): string | undefined;
|
|
28
|
-
}
|