@decaf-ts/decorator-validation 1.14.0 → 1.16.0
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/lib/cjs/constants/errors.cjs +1 -0
- package/lib/cjs/constants/errors.cjs.map +1 -0
- package/lib/cjs/constants/index.cjs +1 -0
- package/lib/cjs/constants/index.cjs.map +1 -0
- package/lib/cjs/constants/validation.cjs +1 -0
- package/lib/cjs/constants/validation.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/model/Builder.cjs +49 -48
- package/lib/cjs/model/Builder.cjs.map +1 -0
- package/lib/cjs/model/Model.cjs +31 -30
- package/lib/cjs/model/Model.cjs.map +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs.map +1 -0
- package/lib/cjs/model/ModelRegistry.cjs +7 -6
- package/lib/cjs/model/ModelRegistry.cjs.map +1 -0
- package/lib/cjs/model/constants.cjs +2 -13
- package/lib/cjs/model/constants.cjs.map +1 -0
- package/lib/cjs/model/construction.cjs +5 -4
- package/lib/cjs/model/construction.cjs.map +1 -0
- package/lib/cjs/model/decorators.cjs +12 -11
- package/lib/cjs/model/decorators.cjs.map +1 -0
- package/lib/cjs/model/index.cjs +1 -0
- package/lib/cjs/model/index.cjs.map +1 -0
- package/lib/cjs/model/types.cjs +1 -0
- package/lib/cjs/model/types.cjs.map +1 -0
- package/lib/cjs/model/utils.cjs +1 -0
- package/lib/cjs/model/utils.cjs.map +1 -0
- package/lib/cjs/model/validation.cjs +33 -32
- package/lib/cjs/model/validation.cjs.map +1 -0
- package/lib/cjs/overrides/Metadata.cjs +1 -0
- package/lib/cjs/overrides/Metadata.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/overrides/overrides.cjs +20 -19
- package/lib/cjs/overrides/overrides.cjs.map +1 -0
- package/lib/cjs/overrides/types.cjs +1 -0
- package/lib/cjs/overrides/types.cjs.map +1 -0
- package/lib/cjs/types/index.cjs +1 -0
- package/lib/cjs/types/index.cjs.map +1 -0
- package/lib/cjs/types/validation.cjs +1 -0
- package/lib/cjs/types/{validation.js.map → validation.cjs.map} +1 -1
- package/lib/cjs/utils/DateBuilder.cjs +1 -0
- package/lib/cjs/utils/DateBuilder.cjs.map +1 -0
- package/lib/cjs/utils/PathProxy.cjs +9 -8
- package/lib/cjs/utils/PathProxy.cjs.map +1 -0
- package/lib/cjs/utils/constants.cjs +2 -21
- package/lib/cjs/utils/constants.cjs.map +1 -0
- package/lib/cjs/utils/dates.cjs +9 -8
- package/lib/cjs/utils/dates.cjs.map +1 -0
- package/lib/cjs/utils/equality.cjs +1 -0
- package/lib/cjs/utils/equality.cjs.map +1 -0
- package/lib/cjs/utils/hashing.cjs +6 -3
- package/lib/cjs/utils/hashing.cjs.map +1 -0
- package/lib/cjs/utils/index.cjs +1 -0
- package/lib/cjs/utils/index.cjs.map +1 -0
- package/lib/cjs/utils/registry.cjs +1 -0
- package/lib/cjs/utils/registry.cjs.map +1 -0
- package/lib/cjs/utils/serialization.cjs +3 -2
- package/lib/cjs/utils/serialization.cjs.map +1 -0
- package/lib/cjs/utils/serializers.cjs +8 -7
- package/lib/cjs/utils/serializers.cjs.map +1 -0
- package/lib/cjs/utils/strings.cjs +1 -0
- package/lib/cjs/utils/strings.cjs.map +1 -0
- package/lib/cjs/utils/types.cjs +1 -0
- package/lib/cjs/utils/types.cjs.map +1 -0
- package/lib/cjs/validation/Validation.cjs +9 -8
- package/lib/cjs/validation/Validation.cjs.map +1 -0
- package/lib/cjs/validation/Validators/AsyncValidator.cjs +5 -4
- package/lib/cjs/validation/Validators/AsyncValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/BaseValidator.cjs +8 -7
- package/lib/cjs/validation/Validators/BaseValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DateValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/DateValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DiffValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/DiffValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EmailValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/EmailValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EqualsValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/EqualsValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/LessThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ListValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/ListValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MaxValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MinValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/OptionValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/OptionValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PasswordValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/PasswordValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PatternValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/PatternValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/RequiredValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/RequiredValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/StepValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/StepValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/TypeValidator.cjs +23 -17
- package/lib/cjs/validation/Validators/TypeValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/URLValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/URLValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/Validator.cjs +5 -4
- package/lib/cjs/validation/Validators/Validator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs +4 -3
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs.map +1 -0
- package/lib/cjs/validation/Validators/constants.cjs +3 -2
- package/lib/cjs/validation/Validators/constants.cjs.map +1 -0
- package/lib/cjs/validation/Validators/decorators.cjs +5 -4
- package/lib/cjs/validation/Validators/decorators.cjs.map +1 -0
- package/lib/cjs/validation/Validators/index.cjs +1 -0
- package/lib/cjs/validation/Validators/index.cjs.map +1 -0
- package/lib/cjs/validation/Validators/utils.cjs +14 -13
- package/lib/cjs/validation/Validators/utils.cjs.map +1 -0
- package/lib/cjs/validation/decorators.cjs +70 -69
- package/lib/cjs/validation/decorators.cjs.map +1 -0
- package/lib/cjs/validation/index.cjs +1 -0
- package/lib/cjs/validation/index.cjs.map +1 -0
- package/lib/cjs/validation/types.cjs +2 -1
- package/lib/cjs/validation/types.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/constants/errors.d.cts +17 -0
- package/lib/types/constants/errors.d.mts +17 -0
- package/lib/types/constants/index.d.cts +2 -0
- package/lib/types/constants/index.d.mts +2 -0
- package/lib/types/constants/validation.d.cts +16 -0
- package/lib/types/constants/validation.d.mts +16 -0
- package/lib/types/index.d.cts +20 -0
- package/lib/types/index.d.mts +20 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/model/Builder.d.cts +86 -0
- package/lib/types/model/Builder.d.mts +86 -0
- package/lib/types/model/Model.d.cts +286 -0
- package/lib/types/model/Model.d.mts +286 -0
- package/lib/types/model/ModelErrorDefinition.d.cts +22 -0
- package/lib/types/model/ModelErrorDefinition.d.mts +22 -0
- package/lib/types/model/ModelRegistry.d.cts +181 -0
- package/lib/types/model/ModelRegistry.d.mts +181 -0
- package/lib/types/model/constants.d.cts +65 -0
- package/lib/types/model/constants.d.mts +65 -0
- package/lib/types/model/construction.d.cts +46 -0
- package/lib/types/model/construction.d.mts +46 -0
- package/lib/types/model/decorators.d.cts +47 -0
- package/lib/types/model/decorators.d.mts +47 -0
- package/lib/types/model/index.d.cts +10 -0
- package/lib/types/model/index.d.mts +10 -0
- package/lib/types/model/types.d.cts +145 -0
- package/lib/types/model/types.d.mts +145 -0
- package/lib/types/model/utils.d.cts +13 -0
- package/lib/types/model/utils.d.mts +13 -0
- package/lib/types/model/validation.d.cts +92 -0
- package/lib/types/model/validation.d.mts +92 -0
- package/lib/types/overrides/Metadata.d.cts +132 -0
- package/lib/types/overrides/Metadata.d.mts +132 -0
- package/lib/types/overrides/index.d.cts +4 -0
- package/lib/types/overrides/index.d.mts +4 -0
- package/lib/types/overrides/overrides.d.cts +1 -0
- package/lib/types/overrides/overrides.d.mts +1 -0
- package/lib/types/overrides/types.d.cts +17 -0
- package/lib/types/overrides/types.d.mts +17 -0
- package/lib/types/types/index.d.cts +1 -0
- package/lib/types/types/index.d.mts +1 -0
- package/lib/types/types/validation.d.cts +28 -0
- package/lib/types/types/validation.d.mts +28 -0
- package/lib/types/utils/DateBuilder.d.cts +121 -0
- package/lib/types/utils/DateBuilder.d.mts +121 -0
- package/lib/types/utils/PathProxy.d.cts +43 -0
- package/lib/types/utils/PathProxy.d.mts +43 -0
- package/lib/types/utils/constants.d.cts +32 -0
- package/lib/types/utils/constants.d.mts +32 -0
- package/lib/types/utils/dates.d.cts +86 -0
- package/lib/types/utils/dates.d.mts +86 -0
- package/lib/types/utils/equality.d.cts +56 -0
- package/lib/types/utils/equality.d.mts +56 -0
- package/lib/types/utils/hashing.d.cts +82 -0
- package/lib/types/utils/hashing.d.mts +82 -0
- package/lib/types/utils/index.d.cts +11 -0
- package/lib/types/utils/index.d.mts +11 -0
- package/lib/types/utils/registry.d.cts +68 -0
- package/lib/types/utils/registry.d.mts +68 -0
- package/lib/types/utils/serialization.d.cts +12 -0
- package/lib/types/utils/serialization.d.mts +12 -0
- package/lib/types/utils/serializers.d.cts +41 -0
- package/lib/types/utils/serializers.d.mts +41 -0
- package/lib/types/utils/strings.d.cts +25 -0
- package/lib/types/utils/strings.d.mts +25 -0
- package/lib/types/utils/types.d.cts +35 -0
- package/lib/types/utils/types.d.mts +35 -0
- package/lib/types/validation/Validation.d.cts +53 -0
- package/lib/types/validation/Validation.d.mts +53 -0
- package/lib/types/validation/Validators/AsyncValidator.d.cts +72 -0
- package/lib/types/validation/Validators/AsyncValidator.d.mts +72 -0
- package/lib/types/validation/Validators/BaseValidator.d.cts +118 -0
- package/lib/types/validation/Validators/BaseValidator.d.mts +118 -0
- package/lib/types/validation/Validators/DateValidator.d.cts +60 -0
- package/lib/types/validation/Validators/DateValidator.d.mts +60 -0
- package/lib/types/validation/Validators/DiffValidator.d.cts +29 -0
- package/lib/types/validation/Validators/DiffValidator.d.mts +29 -0
- package/lib/types/validation/Validators/EmailValidator.d.cts +60 -0
- package/lib/types/validation/Validators/EmailValidator.d.mts +60 -0
- package/lib/types/validation/Validators/EqualsValidator.d.cts +29 -0
- package/lib/types/validation/Validators/EqualsValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/ListValidator.d.cts +66 -0
- package/lib/types/validation/Validators/ListValidator.d.mts +66 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MaxValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MaxValidator.d.mts +74 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MinValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MinValidator.d.mts +74 -0
- package/lib/types/validation/Validators/OptionValidator.d.cts +29 -0
- package/lib/types/validation/Validators/OptionValidator.d.mts +29 -0
- package/lib/types/validation/Validators/PasswordValidator.d.cts +28 -0
- package/lib/types/validation/Validators/PasswordValidator.d.mts +28 -0
- package/lib/types/validation/Validators/PatternValidator.d.cts +103 -0
- package/lib/types/validation/Validators/PatternValidator.d.mts +103 -0
- package/lib/types/validation/Validators/RequiredValidator.d.cts +74 -0
- package/lib/types/validation/Validators/RequiredValidator.d.mts +74 -0
- package/lib/types/validation/Validators/StepValidator.d.cts +29 -0
- package/lib/types/validation/Validators/StepValidator.d.mts +29 -0
- package/lib/types/validation/Validators/TypeValidator.d.cts +79 -0
- package/lib/types/validation/Validators/TypeValidator.d.mts +79 -0
- package/lib/types/validation/Validators/URLValidator.d.cts +61 -0
- package/lib/types/validation/Validators/URLValidator.d.mts +61 -0
- package/lib/types/validation/Validators/Validator.d.cts +65 -0
- package/lib/types/validation/Validators/Validator.d.mts +65 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +41 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +41 -0
- package/lib/types/validation/Validators/constants.d.cts +157 -0
- package/lib/types/validation/Validators/constants.d.mts +157 -0
- package/lib/types/validation/Validators/decorators.d.cts +12 -0
- package/lib/types/validation/Validators/decorators.d.mts +12 -0
- package/lib/types/validation/Validators/index.d.cts +26 -0
- package/lib/types/validation/Validators/index.d.mts +26 -0
- package/lib/types/validation/Validators/utils.d.cts +75 -0
- package/lib/types/validation/Validators/utils.d.mts +75 -0
- package/lib/types/validation/decorators.d.cts +313 -0
- package/lib/types/validation/decorators.d.mts +313 -0
- package/lib/types/validation/index.d.cts +9 -0
- package/lib/types/validation/index.d.mts +9 -0
- package/lib/types/validation/types.d.cts +309 -0
- package/lib/types/validation/types.d.mts +309 -0
- package/package.json +1 -1
- package/lib/cjs/constants/errors.js.map +0 -1
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/constants/validation.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/model/Builder.js.map +0 -1
- package/lib/cjs/model/Model.js.map +0 -1
- package/lib/cjs/model/ModelErrorDefinition.js.map +0 -1
- package/lib/cjs/model/ModelRegistry.js.map +0 -1
- package/lib/cjs/model/constants.js.map +0 -1
- package/lib/cjs/model/construction.js.map +0 -1
- package/lib/cjs/model/decorators.js.map +0 -1
- package/lib/cjs/model/index.js.map +0 -1
- package/lib/cjs/model/types.js.map +0 -1
- package/lib/cjs/model/utils.js.map +0 -1
- package/lib/cjs/model/validation.js.map +0 -1
- package/lib/cjs/overrides/Metadata.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/overrides/overrides.js.map +0 -1
- package/lib/cjs/overrides/types.js.map +0 -1
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/utils/DateBuilder.js.map +0 -1
- package/lib/cjs/utils/PathProxy.js.map +0 -1
- package/lib/cjs/utils/constants.js.map +0 -1
- package/lib/cjs/utils/dates.js.map +0 -1
- package/lib/cjs/utils/equality.js.map +0 -1
- package/lib/cjs/utils/hashing.js.map +0 -1
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/registry.js.map +0 -1
- package/lib/cjs/utils/serialization.js.map +0 -1
- package/lib/cjs/utils/serializers.js.map +0 -1
- package/lib/cjs/utils/strings.js.map +0 -1
- package/lib/cjs/utils/types.js.map +0 -1
- package/lib/cjs/validation/Validation.js.map +0 -1
- package/lib/cjs/validation/Validators/AsyncValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/BaseValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DateValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DiffValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EmailValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EqualsValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/ListValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/OptionValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PasswordValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PatternValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/RequiredValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/StepValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/TypeValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/URLValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/Validator.js.map +0 -1
- package/lib/cjs/validation/Validators/ValidatorRegistry.js.map +0 -1
- package/lib/cjs/validation/Validators/constants.js.map +0 -1
- package/lib/cjs/validation/Validators/decorators.js.map +0 -1
- package/lib/cjs/validation/Validators/index.js.map +0 -1
- package/lib/cjs/validation/Validators/utils.js.map +0 -1
- package/lib/cjs/validation/decorators.js.map +0 -1
- package/lib/cjs/validation/index.js.map +0 -1
- package/lib/cjs/validation/types.js.map +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy object that provides path-based access to nested properties
|
|
3
|
+
* @template T - The type of the target object being proxied
|
|
4
|
+
*/
|
|
5
|
+
export type PathProxy<T> = T & {
|
|
6
|
+
getValueFromPath: (path: string, fallback?: any) => any;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Standard path resolution utility for accessing nested object properties.
|
|
10
|
+
* Provides consistent dot-notation access to both parent and child properties
|
|
11
|
+
* across complex object structures.
|
|
12
|
+
*
|
|
13
|
+
* - Dot-notation path resolution ('object.child.property')
|
|
14
|
+
* - Parent traversal using '../' notation
|
|
15
|
+
* - Configurable property access behavior
|
|
16
|
+
* - Null/undefined safety checks
|
|
17
|
+
*/
|
|
18
|
+
export declare class PathProxyEngine {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a path-aware proxy for the target object
|
|
21
|
+
* @template T - The type of the target object
|
|
22
|
+
* @param {T} rootTarget - The target object to proxy
|
|
23
|
+
* @param opts - Configuration options
|
|
24
|
+
* @param opts.getValue - Custom function to get property value
|
|
25
|
+
* @param opts.getParent - Custom function to get parent object
|
|
26
|
+
* @param opts.ignoreUndefined - Whether to ignore undefined values in paths
|
|
27
|
+
* @param opts.ignoreNull - Whether to ignore null values in paths
|
|
28
|
+
* @returns A proxy object with path access capabilities
|
|
29
|
+
*/
|
|
30
|
+
static create<T extends object>(rootTarget: T, opts?: {
|
|
31
|
+
getValue?: (target: T, prop: string) => any;
|
|
32
|
+
getParent?: (target: T) => any;
|
|
33
|
+
ignoreUndefined: boolean;
|
|
34
|
+
ignoreNull: boolean;
|
|
35
|
+
}): PathProxy<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Parses a path string into individual components
|
|
38
|
+
* @param path - The path string to parse (e.g., "user.address.city")
|
|
39
|
+
* @returns An array of path components
|
|
40
|
+
* @throws Error if the path is invalid
|
|
41
|
+
*/
|
|
42
|
+
private static parsePath;
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy object that provides path-based access to nested properties
|
|
3
|
+
* @template T - The type of the target object being proxied
|
|
4
|
+
*/
|
|
5
|
+
export type PathProxy<T> = T & {
|
|
6
|
+
getValueFromPath: (path: string, fallback?: any) => any;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Standard path resolution utility for accessing nested object properties.
|
|
10
|
+
* Provides consistent dot-notation access to both parent and child properties
|
|
11
|
+
* across complex object structures.
|
|
12
|
+
*
|
|
13
|
+
* - Dot-notation path resolution ('object.child.property')
|
|
14
|
+
* - Parent traversal using '../' notation
|
|
15
|
+
* - Configurable property access behavior
|
|
16
|
+
* - Null/undefined safety checks
|
|
17
|
+
*/
|
|
18
|
+
export declare class PathProxyEngine {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a path-aware proxy for the target object
|
|
21
|
+
* @template T - The type of the target object
|
|
22
|
+
* @param {T} rootTarget - The target object to proxy
|
|
23
|
+
* @param opts - Configuration options
|
|
24
|
+
* @param opts.getValue - Custom function to get property value
|
|
25
|
+
* @param opts.getParent - Custom function to get parent object
|
|
26
|
+
* @param opts.ignoreUndefined - Whether to ignore undefined values in paths
|
|
27
|
+
* @param opts.ignoreNull - Whether to ignore null values in paths
|
|
28
|
+
* @returns A proxy object with path access capabilities
|
|
29
|
+
*/
|
|
30
|
+
static create<T extends object>(rootTarget: T, opts?: {
|
|
31
|
+
getValue?: (target: T, prop: string) => any;
|
|
32
|
+
getParent?: (target: T) => any;
|
|
33
|
+
ignoreUndefined: boolean;
|
|
34
|
+
ignoreNull: boolean;
|
|
35
|
+
}): PathProxy<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Parses a path string into individual components
|
|
38
|
+
* @param path - The path string to parse (e.g., "user.address.city")
|
|
39
|
+
* @returns An array of path components
|
|
40
|
+
* @throws Error if the path is invalid
|
|
41
|
+
*/
|
|
42
|
+
private static parsePath;
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Enum containing metadata keys used for reflection in the model system
|
|
3
|
+
* @summary Defines the various Model keys used for reflection and metadata storage.
|
|
4
|
+
* These keys are used throughout the library to store and retrieve metadata about models,
|
|
5
|
+
* their properties, and their behavior.
|
|
6
|
+
*
|
|
7
|
+
* @property {string} TYPE - Key for storing design type information
|
|
8
|
+
* @property {string} MODEL - Key for identifying model metadata
|
|
9
|
+
* @property {string} ANCHOR - Anchor key that serves as a ghost property in the model
|
|
10
|
+
* @property {string} CONSTRUCTION - Key for storing construction information
|
|
11
|
+
* @property {string} ATTRIBUTE - Key for storing attribute metadata
|
|
12
|
+
* @property {string} HASHING - Key for storing hashing configuration
|
|
13
|
+
* @property {string} SERIALIZATION - Key for storing serialization configuration
|
|
14
|
+
*
|
|
15
|
+
* @enum {string}
|
|
16
|
+
* @readonly
|
|
17
|
+
* @memberOf module:decorator-validation
|
|
18
|
+
* @category Model
|
|
19
|
+
*/
|
|
20
|
+
export declare enum ModelKeys {
|
|
21
|
+
DESCRIPTION = "description",
|
|
22
|
+
TYPE = "design:type",
|
|
23
|
+
MODEL = "model",
|
|
24
|
+
ANCHOR = "__model",
|
|
25
|
+
CONSTRUCTION = "constructed-by",
|
|
26
|
+
ATTRIBUTE = "__attributes",
|
|
27
|
+
HASHING = "hashing",
|
|
28
|
+
SERIALIZATION = "serialization",
|
|
29
|
+
DECORATORS = "decorators",
|
|
30
|
+
CONSTRUCTOR = "__original"
|
|
31
|
+
}
|
|
32
|
+
export declare const DefaultSerializationMethod = "json";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Enum containing metadata keys used for reflection in the model system
|
|
3
|
+
* @summary Defines the various Model keys used for reflection and metadata storage.
|
|
4
|
+
* These keys are used throughout the library to store and retrieve metadata about models,
|
|
5
|
+
* their properties, and their behavior.
|
|
6
|
+
*
|
|
7
|
+
* @property {string} TYPE - Key for storing design type information
|
|
8
|
+
* @property {string} MODEL - Key for identifying model metadata
|
|
9
|
+
* @property {string} ANCHOR - Anchor key that serves as a ghost property in the model
|
|
10
|
+
* @property {string} CONSTRUCTION - Key for storing construction information
|
|
11
|
+
* @property {string} ATTRIBUTE - Key for storing attribute metadata
|
|
12
|
+
* @property {string} HASHING - Key for storing hashing configuration
|
|
13
|
+
* @property {string} SERIALIZATION - Key for storing serialization configuration
|
|
14
|
+
*
|
|
15
|
+
* @enum {string}
|
|
16
|
+
* @readonly
|
|
17
|
+
* @memberOf module:decorator-validation
|
|
18
|
+
* @category Model
|
|
19
|
+
*/
|
|
20
|
+
export declare enum ModelKeys {
|
|
21
|
+
DESCRIPTION = "description",
|
|
22
|
+
TYPE = "design:type",
|
|
23
|
+
MODEL = "model",
|
|
24
|
+
ANCHOR = "__model",
|
|
25
|
+
CONSTRUCTION = "constructed-by",
|
|
26
|
+
ATTRIBUTE = "__attributes",
|
|
27
|
+
HASHING = "hashing",
|
|
28
|
+
SERIALIZATION = "serialization",
|
|
29
|
+
DECORATORS = "decorators",
|
|
30
|
+
CONSTRUCTOR = "__original"
|
|
31
|
+
}
|
|
32
|
+
export declare const DefaultSerializationMethod = "json";
|
|
@@ -0,0 +1,86 @@
|
|
|
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;
|
|
@@ -0,0 +1,86 @@
|
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./constants.cjs";
|
|
2
|
+
export * from "./DateBuilder.cjs";
|
|
3
|
+
export * from "./dates.cjs";
|
|
4
|
+
export * from "./equality.cjs";
|
|
5
|
+
export * from "./hashing.cjs";
|
|
6
|
+
export * from "./PathProxy.cjs";
|
|
7
|
+
export * from "./registry.cjs";
|
|
8
|
+
export * from "./serializers.cjs";
|
|
9
|
+
export * from "./serialization.cjs";
|
|
10
|
+
export * from "./strings.cjs";
|
|
11
|
+
export * from "./types.cjs";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export * from "./DateBuilder.js";
|
|
3
|
+
export * from "./dates.js";
|
|
4
|
+
export * from "./equality.js";
|
|
5
|
+
export * from "./hashing.js";
|
|
6
|
+
export * from "./PathProxy.js";
|
|
7
|
+
export * from "./registry.js";
|
|
8
|
+
export * from "./serializers.js";
|
|
9
|
+
export * from "./serialization.js";
|
|
10
|
+
export * from "./strings.js";
|
|
11
|
+
export * from "./types.js";
|