@decaf-ts/decorator-validation 1.20.0 → 1.21.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/README.md +1 -1
- package/dist/decorator-validation.cjs +1 -1
- package/dist/decorator-validation.cjs.map +1 -1
- package/dist/decorator-validation.js +1 -1
- package/dist/decorator-validation.js.map +1 -1
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/types/constants/index.d.cts +2 -2
- package/lib/types/constants/index.d.mts +2 -2
- package/lib/types/index.d.cts +8 -7
- package/lib/types/index.d.mts +8 -7
- package/lib/types/model/Builder.d.cts +3 -3
- package/lib/types/model/Builder.d.mts +3 -3
- package/lib/types/model/Model.d.cts +4 -4
- package/lib/types/model/Model.d.mts +4 -4
- package/lib/types/model/ModelErrorDefinition.d.cts +1 -1
- package/lib/types/model/ModelErrorDefinition.d.mts +1 -1
- package/lib/types/model/ModelRegistry.d.cts +3 -3
- package/lib/types/model/ModelRegistry.d.mts +3 -3
- package/lib/types/model/construction.d.cts +1 -1
- package/lib/types/model/construction.d.mts +1 -1
- package/lib/types/model/index.d.cts +10 -10
- package/lib/types/model/index.d.mts +10 -10
- package/lib/types/model/types.d.cts +3 -3
- package/lib/types/model/types.d.mts +3 -3
- package/lib/types/model/utils.d.cts +1 -1
- package/lib/types/model/utils.d.mts +1 -1
- package/lib/types/model/validation.d.cts +3 -3
- package/lib/types/model/validation.d.mts +3 -3
- package/lib/types/overrides/Metadata.d.cts +3 -3
- package/lib/types/overrides/Metadata.d.mts +3 -3
- package/lib/types/overrides/index.d.cts +3 -3
- package/lib/types/overrides/index.d.mts +3 -3
- package/lib/types/overrides/types.d.cts +1 -1
- package/lib/types/overrides/types.d.mts +1 -1
- package/lib/types/types/index.d.cts +1 -1
- package/lib/types/types/index.d.mts +1 -1
- package/lib/types/types/validation.d.cts +2 -2
- package/lib/types/types/validation.d.mts +2 -2
- package/lib/types/utils/index.d.cts +11 -11
- package/lib/types/utils/index.d.mts +11 -11
- package/lib/types/utils/serialization.d.cts +1 -1
- package/lib/types/utils/serialization.d.mts +1 -1
- package/lib/types/utils/serializers.d.cts +2 -2
- package/lib/types/utils/serializers.d.mts +2 -2
- package/lib/types/utils/types.d.cts +1 -1
- package/lib/types/utils/types.d.mts +1 -1
- package/lib/types/validation/Validation.d.cts +2 -2
- package/lib/types/validation/Validation.d.mts +2 -2
- package/lib/types/validation/Validators/AsyncValidator.d.cts +3 -3
- package/lib/types/validation/Validators/AsyncValidator.d.mts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.cts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.mts +3 -3
- package/lib/types/validation/Validators/DateValidator.d.cts +2 -2
- package/lib/types/validation/Validators/DateValidator.d.mts +2 -2
- package/lib/types/validation/Validators/DiffValidator.d.cts +3 -3
- package/lib/types/validation/Validators/DiffValidator.d.mts +3 -3
- package/lib/types/validation/Validators/EmailValidator.d.cts +2 -2
- package/lib/types/validation/Validators/EmailValidator.d.mts +2 -2
- package/lib/types/validation/Validators/EqualsValidator.d.cts +3 -3
- package/lib/types/validation/Validators/EqualsValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/ListValidator.d.cts +2 -2
- package/lib/types/validation/Validators/ListValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.mts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.cts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.mts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.cts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.mts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.cts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.mts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.cts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.mts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.cts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.mts +2 -2
- package/lib/types/validation/Validators/Validator.d.cts +3 -3
- package/lib/types/validation/Validators/Validator.d.mts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +3 -3
- package/lib/types/validation/Validators/decorators.d.cts +1 -1
- package/lib/types/validation/Validators/decorators.d.mts +1 -1
- package/lib/types/validation/Validators/index.d.cts +26 -26
- package/lib/types/validation/Validators/index.d.mts +26 -26
- package/lib/types/validation/decorators.d.cts +2 -2
- package/lib/types/validation/decorators.d.mts +2 -2
- package/lib/types/validation/index.d.cts +4 -4
- package/lib/types/validation/index.d.mts +4 -4
- package/lib/types/validation/types.d.cts +2 -2
- package/lib/types/validation/types.d.mts +2 -2
- package/package.json +9 -1
- package/lib/types/constants/errors.d.ts +0 -17
- package/lib/types/constants/index.d.ts +0 -2
- package/lib/types/constants/validation.d.ts +0 -16
- package/lib/types/index.d.ts +0 -20
- package/lib/types/model/Builder.d.ts +0 -86
- package/lib/types/model/Model.d.ts +0 -286
- package/lib/types/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/types/model/ModelRegistry.d.ts +0 -181
- package/lib/types/model/constants.d.ts +0 -65
- package/lib/types/model/construction.d.ts +0 -46
- package/lib/types/model/decorators.d.ts +0 -47
- package/lib/types/model/index.d.ts +0 -10
- package/lib/types/model/types.d.ts +0 -145
- package/lib/types/model/utils.d.ts +0 -13
- package/lib/types/model/validation.d.ts +0 -92
- package/lib/types/overrides/Metadata.d.ts +0 -132
- package/lib/types/overrides/index.d.ts +0 -4
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/overrides/types.d.ts +0 -17
- package/lib/types/types/index.d.ts +0 -1
- package/lib/types/types/validation.d.ts +0 -28
- package/lib/types/utils/DateBuilder.d.ts +0 -121
- package/lib/types/utils/PathProxy.d.ts +0 -43
- package/lib/types/utils/constants.d.ts +0 -32
- package/lib/types/utils/dates.d.ts +0 -86
- package/lib/types/utils/equality.d.ts +0 -56
- package/lib/types/utils/hashing.d.ts +0 -82
- package/lib/types/utils/index.d.ts +0 -11
- package/lib/types/utils/registry.d.ts +0 -68
- package/lib/types/utils/serialization.d.ts +0 -12
- package/lib/types/utils/serializers.d.ts +0 -41
- package/lib/types/utils/strings.d.ts +0 -25
- package/lib/types/utils/types.d.ts +0 -35
- package/lib/types/validation/Validation.d.ts +0 -53
- package/lib/types/validation/Validators/AsyncValidator.d.ts +0 -72
- package/lib/types/validation/Validators/BaseValidator.d.ts +0 -118
- package/lib/types/validation/Validators/DateValidator.d.ts +0 -60
- package/lib/types/validation/Validators/DiffValidator.d.ts +0 -29
- package/lib/types/validation/Validators/EmailValidator.d.ts +0 -60
- package/lib/types/validation/Validators/EqualsValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/ListValidator.d.ts +0 -66
- package/lib/types/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MaxValidator.d.ts +0 -74
- package/lib/types/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MinValidator.d.ts +0 -74
- package/lib/types/validation/Validators/OptionValidator.d.ts +0 -29
- package/lib/types/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/types/validation/Validators/PatternValidator.d.ts +0 -103
- package/lib/types/validation/Validators/RequiredValidator.d.ts +0 -74
- package/lib/types/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/types/validation/Validators/TypeValidator.d.ts +0 -79
- package/lib/types/validation/Validators/URLValidator.d.ts +0 -61
- package/lib/types/validation/Validators/Validator.d.ts +0 -65
- package/lib/types/validation/Validators/ValidatorRegistry.d.ts +0 -41
- package/lib/types/validation/Validators/constants.d.ts +0 -157
- package/lib/types/validation/Validators/decorators.d.ts +0 -12
- package/lib/types/validation/Validators/index.d.ts +0 -26
- package/lib/types/validation/Validators/utils.d.ts +0 -75
- package/lib/types/validation/decorators.d.ts +0 -313
- package/lib/types/validation/index.d.ts +0 -9
- package/lib/types/validation/types.d.ts +0 -309
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @summary Reverses the process from {@link formatDate}
|
|
3
|
-
*
|
|
4
|
-
* @param {string} date the date string to be converted back into date
|
|
5
|
-
* @param {string} format the date format
|
|
6
|
-
* @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?)
|
|
7
|
-
*
|
|
8
|
-
* @function dateFromFormat
|
|
9
|
-
* @memberOf module:decorator-validation
|
|
10
|
-
* @category Model
|
|
11
|
-
*/
|
|
12
|
-
export declare function dateFromFormat(date: string, format: string): Date;
|
|
13
|
-
/**
|
|
14
|
-
* @description Binds a specific date format to a Date object's toString and toISOString methods using a Proxy
|
|
15
|
-
* @summary Wraps a Date object in a Proxy to return a formatted string when toString or toISOString is called.
|
|
16
|
-
* This function uses the Proxy API to intercept method calls and return the date formatted according
|
|
17
|
-
* to the specified format string, while maintaining all other Date functionality.
|
|
18
|
-
* The proxied Date maintains instanceof Date checks and behaves identically to a Date object.
|
|
19
|
-
* @param {Date} [date] The Date object to modify
|
|
20
|
-
* @param {string} [format] The format string to use for formatting the date
|
|
21
|
-
* @return {Date|undefined} A proxied Date object or undefined if no date was provided
|
|
22
|
-
* @function bindDateToString
|
|
23
|
-
* @memberOf module:decorator-validation
|
|
24
|
-
* @category Model
|
|
25
|
-
*/
|
|
26
|
-
export declare function bindDateToString(date: Date | undefined, format: string): Date | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* @description Safely checks if a value is a valid Date object
|
|
29
|
-
* @summary A utility function that determines if a value is a valid Date object.
|
|
30
|
-
* This function is more reliable than using instanceof Date as it also checks
|
|
31
|
-
* that the date is not NaN, which can happen with invalid date strings.
|
|
32
|
-
* @param {any} date The value to check
|
|
33
|
-
* @return {boolean} True if the value is a valid Date object, false otherwise
|
|
34
|
-
* @function isValidDate
|
|
35
|
-
* @memberOf module:decorator-validation
|
|
36
|
-
* @category Validation
|
|
37
|
-
*/
|
|
38
|
-
export declare function isValidDate(date: any): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* @summary Util function to pad numbers
|
|
41
|
-
* @param {number} num
|
|
42
|
-
*
|
|
43
|
-
* @return {string}
|
|
44
|
-
*
|
|
45
|
-
* @function twoDigitPad
|
|
46
|
-
* @memberOf module:decorator-validation
|
|
47
|
-
* @category Model
|
|
48
|
-
*/
|
|
49
|
-
export declare function twoDigitPad(num: number): string;
|
|
50
|
-
/**
|
|
51
|
-
* @summary Date Format Handling
|
|
52
|
-
* @description Code from {@link https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date}
|
|
53
|
-
*
|
|
54
|
-
* <pre>
|
|
55
|
-
* Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
|
|
56
|
-
* I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
|
|
57
|
-
* You can display date, time, AM/PM, etc.
|
|
58
|
-
*
|
|
59
|
-
* Date and Time Patterns
|
|
60
|
-
* yy = 2-digit year; yyyy = full year
|
|
61
|
-
* M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
|
|
62
|
-
* EEEE = full weekday name; EEE = short weekday name
|
|
63
|
-
* d = digit day; dd = 2-digit day
|
|
64
|
-
* h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
|
|
65
|
-
* m = minutes; mm = 2-digit minutes; aaa = AM/PM
|
|
66
|
-
* s = seconds; ss = 2-digit seconds
|
|
67
|
-
* S = miliseconds
|
|
68
|
-
* </pre>
|
|
69
|
-
*
|
|
70
|
-
* @param {Date} date
|
|
71
|
-
* @param {string} [patternStr] defaults to 'yyyy/MM/dd'
|
|
72
|
-
* @return {string} the formatted date
|
|
73
|
-
*
|
|
74
|
-
* @function formatDate
|
|
75
|
-
* @memberOf module:decorator-validation
|
|
76
|
-
* @category Model
|
|
77
|
-
*/
|
|
78
|
-
export declare function formatDate(date: Date, patternStr?: string): string;
|
|
79
|
-
/**
|
|
80
|
-
* @summary Parses a date from a specified format
|
|
81
|
-
* @param {string} format
|
|
82
|
-
* @param {string | Date | number} [v]
|
|
83
|
-
* @memberOf module:decorator-validation
|
|
84
|
-
* @category Model
|
|
85
|
-
*/
|
|
86
|
-
export declare function parseDate(format: string, v?: string | Date | number): Date | undefined;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Enhanced algorithm for deep comparison of any two values with optional ignored properties
|
|
3
|
-
* @summary Performs a deep equality check between two values, handling various types including primitives, objects, arrays, dates, and more
|
|
4
|
-
* @param {unknown} a - First value to compare
|
|
5
|
-
* @param {unknown} b - Second value to compare
|
|
6
|
-
* @param {string[]} propsToIgnore - A list of property names to ignore during comparison
|
|
7
|
-
* @return {boolean} Returns true if the values are deeply equal, false otherwise
|
|
8
|
-
* @function isEqual
|
|
9
|
-
* @mermaid
|
|
10
|
-
* sequenceDiagram
|
|
11
|
-
* participant Caller
|
|
12
|
-
* participant isEqual
|
|
13
|
-
* participant Recursion
|
|
14
|
-
*
|
|
15
|
-
* Caller->>isEqual: isEqual(a, b, propsToIgnore)
|
|
16
|
-
* Note over isEqual: Check simple cases (identity, null, primitives)
|
|
17
|
-
*
|
|
18
|
-
* alt a === b
|
|
19
|
-
* isEqual-->>Caller: true (with special case for +0/-0)
|
|
20
|
-
* else a or b is null
|
|
21
|
-
* isEqual-->>Caller: a === b
|
|
22
|
-
* else different types
|
|
23
|
-
* isEqual-->>Caller: false
|
|
24
|
-
* else both NaN
|
|
25
|
-
* isEqual-->>Caller: true
|
|
26
|
-
* else primitive types
|
|
27
|
-
* isEqual-->>Caller: a === b
|
|
28
|
-
* else both Date objects
|
|
29
|
-
* isEqual-->>Caller: Compare timestamps
|
|
30
|
-
* else both RegExp objects
|
|
31
|
-
* isEqual-->>Caller: Compare string representations
|
|
32
|
-
* else both Error objects
|
|
33
|
-
* isEqual-->>Caller: Compare name and message
|
|
34
|
-
* else both Arrays
|
|
35
|
-
* Note over isEqual: Check length
|
|
36
|
-
* loop For each element
|
|
37
|
-
* isEqual->>Recursion: isEqual(a[i], b[i], propsToIgnore)
|
|
38
|
-
* end
|
|
39
|
-
* else both Maps or Sets
|
|
40
|
-
* Note over isEqual: Compare size and entries
|
|
41
|
-
* else both TypedArrays
|
|
42
|
-
* Note over isEqual: Compare byte by byte
|
|
43
|
-
* else both Objects
|
|
44
|
-
* Note over isEqual: Filter keys by propsToIgnore
|
|
45
|
-
* Note over isEqual: Compare key counts
|
|
46
|
-
* loop For each key
|
|
47
|
-
* isEqual->>Recursion: isEqual(a[key], b[key], propsToIgnore)
|
|
48
|
-
* end
|
|
49
|
-
* Note over isEqual: Check Symbol properties
|
|
50
|
-
* Note over isEqual: Compare prototypes
|
|
51
|
-
* end
|
|
52
|
-
*
|
|
53
|
-
* isEqual-->>Caller: Comparison result
|
|
54
|
-
* @memberOf module:decorator-validation
|
|
55
|
-
*/
|
|
56
|
-
export declare function isEqual(a: unknown, b: unknown, ...propsToIgnore: string[]): boolean;
|
|
@@ -1,82 +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
|
|
9
|
-
* @category Model
|
|
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
|
|
15
|
-
* @category Model
|
|
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
|
|
26
|
-
* @category Model
|
|
27
|
-
*/
|
|
28
|
-
export declare function hashObj(obj: Record<string, any> | any[]): string;
|
|
29
|
-
export declare const DefaultHashingMethod = "default";
|
|
30
|
-
/**
|
|
31
|
-
* @description Manages hashing methods and provides a unified hashing interface
|
|
32
|
-
* @summary A utility class that provides a registry for different hashing functions and methods to hash objects.
|
|
33
|
-
* The class maintains a cache of registered hashing functions and allows setting a default hashing method.
|
|
34
|
-
* It prevents direct instantiation and provides static methods for registration and hashing.
|
|
35
|
-
*
|
|
36
|
-
* @class Hashing
|
|
37
|
-
* @category Model
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* // Register a custom hashing function
|
|
42
|
-
* Hashing.register('md5', (obj) => createMD5Hash(obj), true);
|
|
43
|
-
*
|
|
44
|
-
* // Hash an object using default method
|
|
45
|
-
* const hash1 = Hashing.hash(myObject);
|
|
46
|
-
*
|
|
47
|
-
* // Hash using specific method
|
|
48
|
-
* const hash2 = Hashing.hash(myObject, 'md5');
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare class Hashing {
|
|
52
|
-
/**
|
|
53
|
-
* @description Current default hashing method identifier
|
|
54
|
-
* @private
|
|
55
|
-
*/
|
|
56
|
-
private static current;
|
|
57
|
-
/**
|
|
58
|
-
* @description Cache of registered hashing functions
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
private static cache;
|
|
62
|
-
private constructor();
|
|
63
|
-
/**
|
|
64
|
-
* @description Retrieves a registered hashing function
|
|
65
|
-
* @summary Fetches a hashing function from the cache by its key. Throws an error if the method is not registered.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} key - The identifier of the hashing function to retrieve
|
|
68
|
-
* @return {HashingFunction} The requested hashing function
|
|
69
|
-
* @private
|
|
70
|
-
*/
|
|
71
|
-
private static get;
|
|
72
|
-
/**
|
|
73
|
-
* @description Registers a new hashing function
|
|
74
|
-
* @summary Adds a new hashing function to the registry. Optionally sets it as the default method.
|
|
75
|
-
* Throws an error if a method with the same key is already registered.
|
|
76
|
-
*
|
|
77
|
-
* @param {string} key - The identifier for the hashing function
|
|
78
|
-
*/
|
|
79
|
-
static register(key: string, func: HashingFunction, setDefault?: boolean): void;
|
|
80
|
-
static hash(obj: any, method?: string, ...args: any[]): any;
|
|
81
|
-
static setDefault(method: string): void;
|
|
82
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
export * from "./DateBuilder";
|
|
3
|
-
export * from "./dates";
|
|
4
|
-
export * from "./equality";
|
|
5
|
-
export * from "./hashing";
|
|
6
|
-
export * from "./PathProxy";
|
|
7
|
-
export * from "./registry";
|
|
8
|
-
export * from "./serializers";
|
|
9
|
-
export * from "./serialization";
|
|
10
|
-
export * from "./strings";
|
|
11
|
-
export * from "./types";
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Basic interface for Registries
|
|
4
|
-
*
|
|
5
|
-
* @interface IRegistry
|
|
6
|
-
*
|
|
7
|
-
* @category Model
|
|
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
|
-
* @template T
|
|
34
|
-
* @interface BuilderRegistry<T>
|
|
35
|
-
*
|
|
36
|
-
* @category Model
|
|
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,12 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
-
import { Serializer } from "./types";
|
|
3
|
-
export declare class Serialization {
|
|
4
|
-
private static current;
|
|
5
|
-
private static cache;
|
|
6
|
-
private constructor();
|
|
7
|
-
private static get;
|
|
8
|
-
static register(key: string, func: Constructor<Serializer<any>>, setDefault?: boolean): void;
|
|
9
|
-
static serialize(obj: any, method?: string, ...args: any[]): any;
|
|
10
|
-
static deserialize(obj: string, method?: string, ...args: any[]): any;
|
|
11
|
-
static setDefault(method: string): void;
|
|
12
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Serializer } from "./types";
|
|
2
|
-
import { Model } from "../model/Model";
|
|
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 Model
|
|
15
|
-
*/
|
|
16
|
-
export declare class JSONSerializer<T extends Model<boolean>> implements Serializer<T> {
|
|
17
|
-
constructor();
|
|
18
|
-
/**
|
|
19
|
-
* @summary prepares the model for serialization
|
|
20
|
-
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
21
|
-
* so the object can be recognized upon deserialization
|
|
22
|
-
*
|
|
23
|
-
* @param {T} model
|
|
24
|
-
* @protected
|
|
25
|
-
*/
|
|
26
|
-
protected preSerialize(model: T, ...args: any[]): Record<string, any>;
|
|
27
|
-
/**
|
|
28
|
-
* @summary Rebuilds a model from a serialization
|
|
29
|
-
* @param {string} str
|
|
30
|
-
*
|
|
31
|
-
* @throws {Error} If it fails to parse the string, or to build the model
|
|
32
|
-
*/
|
|
33
|
-
deserialize(str: string, ...args: any[]): T;
|
|
34
|
-
/**
|
|
35
|
-
* @summary Serializes a model
|
|
36
|
-
* @param {T} model
|
|
37
|
-
*
|
|
38
|
-
* @throws {Error} if fails to serialize
|
|
39
|
-
*/
|
|
40
|
-
serialize(model: T, ...args: any[]): string;
|
|
41
|
-
}
|
|
@@ -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
|
|
10
|
-
* @category Model
|
|
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
|
|
23
|
-
* @category Model
|
|
24
|
-
*/
|
|
25
|
-
export declare const sf: typeof stringFormat;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Model } from "../model";
|
|
2
|
-
/**
|
|
3
|
-
* @description Interface for serializing and deserializing model objects
|
|
4
|
-
* @summary Defines the contract for classes that can convert model objects to and from string representations.
|
|
5
|
-
* Serializers are used to persist models or transmit them over networks.
|
|
6
|
-
*
|
|
7
|
-
* @interface Serializer
|
|
8
|
-
* @template T Type of model that can be serialized, must extend Model
|
|
9
|
-
* @memberOf module:decorator-validation
|
|
10
|
-
* @category Model
|
|
11
|
-
*/
|
|
12
|
-
export interface Serializer<M extends Model> {
|
|
13
|
-
/**
|
|
14
|
-
* @description Converts a model object to a string representation
|
|
15
|
-
* @summary Serializes a model instance into a string format that can be stored or transmitted.
|
|
16
|
-
* Additional arguments can be provided to customize the serialization process.
|
|
17
|
-
*
|
|
18
|
-
* @param {T} model - The model instance to serialize
|
|
19
|
-
* @param {...any} args - Additional arguments for the serialization process
|
|
20
|
-
* @return {string} The serialized representation of the model
|
|
21
|
-
* @throws {Error} If the model cannot be serialized
|
|
22
|
-
*/
|
|
23
|
-
serialize(model: M, ...args: any[]): string;
|
|
24
|
-
/**
|
|
25
|
-
* @description Reconstructs a model object from its string representation
|
|
26
|
-
* @summary Deserializes a string back into a model instance.
|
|
27
|
-
* Additional arguments can be provided to customize the deserialization process.
|
|
28
|
-
*
|
|
29
|
-
* @param {string} str - The serialized string to convert back to a model
|
|
30
|
-
* @param {...any} args - Additional arguments for the deserialization process
|
|
31
|
-
* @return {T} The reconstructed model instance
|
|
32
|
-
* @throws {Error} If the string cannot be deserialized into a valid model
|
|
33
|
-
*/
|
|
34
|
-
deserialize(str: string, ...args: any[]): M;
|
|
35
|
-
}
|
|
@@ -1,53 +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
|
-
static registerDecorator(key: string, decorator: (...args: any[]) => PropertyDecorator): void;
|
|
52
|
-
static decoratorFromKey(key: string): any;
|
|
53
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { ValidatorOptions } from "../types";
|
|
2
|
-
import type { PathProxy } from "../../utils";
|
|
3
|
-
import { BaseValidator } from "./BaseValidator";
|
|
4
|
-
/**
|
|
5
|
-
* @description
|
|
6
|
-
* Abstract class for defining asynchronous validators.
|
|
7
|
-
*
|
|
8
|
-
* This class extends the base `Validator` and enforces that any implementation
|
|
9
|
-
* of `hasErrors` must be asynchronous, always returning a Promise.
|
|
10
|
-
*
|
|
11
|
-
* Use this when the validation process involves asynchronous operations,
|
|
12
|
-
* such as API calls, database lookups, or time-based checks (e.g., timeouts).
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Example of an asynchronous validator that compares value against a timeout
|
|
17
|
-
* class TimeoutValidator extends AsyncValidator<{ timeout?: number }> {
|
|
18
|
-
* constructor(message: string = "Validation failed due to timeout") {
|
|
19
|
-
* super(message);
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* async hasErrors(value: number, options?: { timeout?: number }) {
|
|
23
|
-
* const delay = options?.timeout ?? 100;
|
|
24
|
-
*
|
|
25
|
-
* // async call
|
|
26
|
-
* await new Promise(res => setTimeout(res, delay));
|
|
27
|
-
*
|
|
28
|
-
* if (value > delay) {
|
|
29
|
-
* // Rejects the validation after waiting the delay if value is greater
|
|
30
|
-
* return Promise.resolve(this.getMessage());
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* // Passes the validation after waiting the delay
|
|
34
|
-
* return Promise.resolve(undefined);
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* // Example usage:
|
|
39
|
-
* const validator = new TimeoutValidator();
|
|
40
|
-
*
|
|
41
|
-
* async function runValidation() {
|
|
42
|
-
* const error = await validator.hasErrors(50, { timeout: 100 });
|
|
43
|
-
* if (error) {
|
|
44
|
-
* return console.error('Validation error:', error);
|
|
45
|
-
* }
|
|
46
|
-
* console.log('Value is valid');
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* await runValidation();
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* - If `value > timeout`, the validator waits for the delay and then rejects with an error.
|
|
53
|
-
* - If `value <= timeout`, the validator waits for the delay and resolves successfully with `undefined`.
|
|
54
|
-
*
|
|
55
|
-
* @see {@link Validator} For the base synchronous validator.
|
|
56
|
-
*/
|
|
57
|
-
export declare abstract class AsyncValidator<V extends ValidatorOptions> extends BaseValidator<V, true> {
|
|
58
|
-
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
59
|
-
/**
|
|
60
|
-
* @description
|
|
61
|
-
* Asynchronously validates a value.
|
|
62
|
-
*
|
|
63
|
-
* @template V - Type of the option object that can be passed to the validator
|
|
64
|
-
* @param {any} value - The value to validate
|
|
65
|
-
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
66
|
-
* @param {PathProxy<any>} proxy -
|
|
67
|
-
* @return Promise<string | undefined> Error message if validation fails, undefined if validation passes
|
|
68
|
-
*
|
|
69
|
-
* @see {@link Validator}
|
|
70
|
-
*/
|
|
71
|
-
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): Promise<string | undefined>;
|
|
72
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { ValidatorOptions } from "../types";
|
|
2
|
-
import type { PathProxy } from "../../utils";
|
|
3
|
-
import type { ConditionalAsync } from "../../types";
|
|
4
|
-
/**
|
|
5
|
-
* @description Abstract base class for all validators in the validation framework.
|
|
6
|
-
* @summary The BaseValidator class provides the foundation for all synchronous and asynchronous validator implementations.
|
|
7
|
-
* It handles type checking, error message formatting, and defines the interface that all validators must implement.
|
|
8
|
-
* This class is designed to be extended by specific validator classes that define their own validation logic.
|
|
9
|
-
*
|
|
10
|
-
* @template V - Validator options type
|
|
11
|
-
* @template IsAsync - Whether the validator is async (true) or sync (false). Default `false`.
|
|
12
|
-
*
|
|
13
|
-
* @param {boolean} async - Defines if the validator is async (must match the subclass signature)
|
|
14
|
-
* @param {string} message - Default error message to display when validation fails (defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT})
|
|
15
|
-
* @param {string[]} acceptedTypes - Type names that this validator accepts (used for runtime type checking)
|
|
16
|
-
*
|
|
17
|
-
* @class BaseValidator
|
|
18
|
-
* @abstract
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Example of a synchronous validator
|
|
22
|
-
* class SyncValidator extends BaseValidator<SomeOptions, false> {
|
|
23
|
-
* constructor() {
|
|
24
|
-
* super(false, "Sync validation failed", String.name);
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* public hasErrors(value: any, options?: SomeOptions): string | undefined {
|
|
28
|
-
* if (typeof value !== "string") return this.getMessage(this.message);
|
|
29
|
-
* return undefined;
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* // Example of an asynchronous custom validator
|
|
35
|
-
* class AsyncValidator extends BaseValidator<SomeOptions, true> {
|
|
36
|
-
* constructor() {
|
|
37
|
-
* super(true, "Async validation failed", String.name);
|
|
38
|
-
* }
|
|
39
|
-
*
|
|
40
|
-
* public async hasErrors(value: any, options?: SomeOptions): Promise<string | undefined> {
|
|
41
|
-
* const result = await someAsyncCheck(value);
|
|
42
|
-
* if (!result) return this.getMessage(this.message);
|
|
43
|
-
* return undefined;
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* @mermaid
|
|
48
|
-
* sequenceDiagram
|
|
49
|
-
* participant C as Client
|
|
50
|
-
* participant V as Validator Subclass
|
|
51
|
-
* participant B as BaseValidator
|
|
52
|
-
*
|
|
53
|
-
* C->>V: new CustomValidator(async, message)
|
|
54
|
-
* V->>B: super(async, message, acceptedTypes)
|
|
55
|
-
* B->>B: Store message, async flag, and accepted types
|
|
56
|
-
* B->>B: Optionally wrap hasErrors with type checking
|
|
57
|
-
* C->>V: hasErrors(value, options)
|
|
58
|
-
* alt value type not in acceptedTypes
|
|
59
|
-
* B-->>C: Type error message
|
|
60
|
-
* else value type is accepted
|
|
61
|
-
* V->>V: Custom validation logic
|
|
62
|
-
* V-->>C: Validation result
|
|
63
|
-
* end
|
|
64
|
-
*
|
|
65
|
-
* @category Validators
|
|
66
|
-
*/
|
|
67
|
-
export declare abstract class BaseValidator<V extends ValidatorOptions = ValidatorOptions, Async extends boolean = false> {
|
|
68
|
-
readonly message: string;
|
|
69
|
-
readonly acceptedTypes?: string[];
|
|
70
|
-
readonly async?: Async;
|
|
71
|
-
protected constructor(async: Async, message?: string, ...acceptedTypes: string[]);
|
|
72
|
-
/**
|
|
73
|
-
* @description Formats an error message with optional arguments
|
|
74
|
-
* @summary Creates a formatted error message by replacing placeholders with provided arguments.
|
|
75
|
-
* This method uses the string formatting utility to generate consistent error messages
|
|
76
|
-
* across all validators.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} message - The message template with placeholders
|
|
79
|
-
* @param {...any} args - Values to insert into the message template
|
|
80
|
-
* @return {string} The formatted error message
|
|
81
|
-
* @protected
|
|
82
|
-
*/
|
|
83
|
-
protected getMessage(message: string, ...args: any[]): string;
|
|
84
|
-
/**
|
|
85
|
-
* @description Creates a type-checking wrapper around the hasErrors method
|
|
86
|
-
* @summary Wraps the hasErrors method with type validation logic to ensure that
|
|
87
|
-
* the value being validated is of an accepted type before performing specific validation.
|
|
88
|
-
* This method is called during construction if acceptedTypes are provided.
|
|
89
|
-
*
|
|
90
|
-
* @param {Function} unbound - The original hasErrors method to be wrapped
|
|
91
|
-
* @return {Function} A new function that performs type checking before calling the original method
|
|
92
|
-
* @private
|
|
93
|
-
*/
|
|
94
|
-
private checkTypeAndHasErrors;
|
|
95
|
-
/**
|
|
96
|
-
* @description Validates a value against specific validation rules
|
|
97
|
-
* @summary Abstract method that must be implemented by all validator subclasses.
|
|
98
|
-
* This method contains the core validation logic that determines whether a value
|
|
99
|
-
* is valid according to the specific rules of the validator. If the value is valid,
|
|
100
|
-
* the method returns undefined; otherwise, it returns an error message.
|
|
101
|
-
*
|
|
102
|
-
* @template V - Type of the options object that can be passed to the validator
|
|
103
|
-
* @param {any} value - The value to validate
|
|
104
|
-
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
105
|
-
* @param {PathProxy<any>} proxy -
|
|
106
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
107
|
-
*
|
|
108
|
-
* @abstract
|
|
109
|
-
*
|
|
110
|
-
* @see Model#validate
|
|
111
|
-
*/
|
|
112
|
-
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): ConditionalAsync<Async, string | undefined>;
|
|
113
|
-
/**
|
|
114
|
-
* @summary Duck typing for Validators
|
|
115
|
-
* @param val
|
|
116
|
-
*/
|
|
117
|
-
static isValidator(val: any): boolean;
|
|
118
|
-
}
|