@decaf-ts/decorator-validation 1.15.0 → 1.17.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 +4 -4
- 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,22 @@
|
|
|
1
|
+
import { ModelErrors } from "../validation/types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Helper Class to hold the error results
|
|
4
|
+
* @description holds error results in an 'indexable' manner
|
|
5
|
+
* while still providing the same result on toString
|
|
6
|
+
*
|
|
7
|
+
* @param {ModelErrors} errors
|
|
8
|
+
*
|
|
9
|
+
* @class ModelErrorDefinition
|
|
10
|
+
*
|
|
11
|
+
* @category Model
|
|
12
|
+
*/
|
|
13
|
+
export declare class ModelErrorDefinition {
|
|
14
|
+
[indexer: string]: Record<string, string | undefined> | (() => string | undefined);
|
|
15
|
+
constructor(errors: ModelErrors);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Outputs the class to a nice readable string
|
|
18
|
+
*
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModelErrors } from "../validation/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Helper Class to hold the error results
|
|
4
|
+
* @description holds error results in an 'indexable' manner
|
|
5
|
+
* while still providing the same result on toString
|
|
6
|
+
*
|
|
7
|
+
* @param {ModelErrors} errors
|
|
8
|
+
*
|
|
9
|
+
* @class ModelErrorDefinition
|
|
10
|
+
*
|
|
11
|
+
* @category Model
|
|
12
|
+
*/
|
|
13
|
+
export declare class ModelErrorDefinition {
|
|
14
|
+
[indexer: string]: Record<string, string | undefined> | (() => string | undefined);
|
|
15
|
+
constructor(errors: ModelErrors);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Outputs the class to a nice readable string
|
|
18
|
+
*
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { ModelBuilderFunction, ModelConstructor } from "./types.cjs";
|
|
3
|
+
import { type Model } from "./Model.cjs";
|
|
4
|
+
import { BuilderRegistry } from "../utils/registry.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* @description Registry type for storing and retrieving model constructors
|
|
7
|
+
* @summary The ModelRegistry type defines a registry for model constructors that extends
|
|
8
|
+
* the BuilderRegistry interface. It provides a standardized way to register, retrieve,
|
|
9
|
+
* and build model instances, enabling the model system to work with different types of models.
|
|
10
|
+
*
|
|
11
|
+
* @interface ModelRegistry
|
|
12
|
+
* @template T Type of model that can be registered, must extend Model
|
|
13
|
+
* @extends BuilderRegistry<T>
|
|
14
|
+
* @memberOf module:decorator-validation
|
|
15
|
+
* @category Model
|
|
16
|
+
*/
|
|
17
|
+
export type ModelRegistry<T extends Model> = BuilderRegistry<T>;
|
|
18
|
+
/**
|
|
19
|
+
* @description Registry manager for model constructors that enables serialization and rebuilding
|
|
20
|
+
* @summary The ModelRegistryManager implements the ModelRegistry interface and provides
|
|
21
|
+
* functionality for registering, retrieving, and building model instances. It maintains
|
|
22
|
+
* a cache of model constructors indexed by name, allowing for efficient lookup and instantiation.
|
|
23
|
+
* This class is essential for the serialization and deserialization of model objects.
|
|
24
|
+
*
|
|
25
|
+
* @param {function(Record<string, any>): boolean} [testFunction] - Function to test if an object is a model, defaults to {@link Model#isModel}
|
|
26
|
+
*
|
|
27
|
+
* @class ModelRegistryManager
|
|
28
|
+
* @template M Type of model that can be registered, must extend Model
|
|
29
|
+
* @implements ModelRegistry<M>
|
|
30
|
+
* @category Model
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Create a model registry
|
|
35
|
+
* const registry = new ModelRegistryManager();
|
|
36
|
+
*
|
|
37
|
+
* // Register a model class
|
|
38
|
+
* registry.register(User);
|
|
39
|
+
*
|
|
40
|
+
* // Retrieve a model constructor by name
|
|
41
|
+
* const UserClass = registry.get("User");
|
|
42
|
+
*
|
|
43
|
+
* // Build a model instance from a plain object
|
|
44
|
+
* const userData = { name: "John", age: 30 };
|
|
45
|
+
* const user = registry.build(userData, "User");
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @mermaid
|
|
49
|
+
* sequenceDiagram
|
|
50
|
+
* participant C as Client
|
|
51
|
+
* participant R as ModelRegistryManager
|
|
52
|
+
* participant M as Model Class
|
|
53
|
+
*
|
|
54
|
+
* C->>R: new ModelRegistryManager(testFunction)
|
|
55
|
+
* C->>R: register(ModelClass)
|
|
56
|
+
* R->>R: Store in cache
|
|
57
|
+
* C->>R: get("ModelName")
|
|
58
|
+
* R-->>C: ModelClass constructor
|
|
59
|
+
* C->>R: build(data, "ModelName")
|
|
60
|
+
* R->>R: Get constructor from cache
|
|
61
|
+
* R->>M: new ModelClass(data)
|
|
62
|
+
* M-->>R: Model instance
|
|
63
|
+
* R-->>C: Model instance
|
|
64
|
+
*/
|
|
65
|
+
export declare class ModelRegistryManager<M extends Model<true | false>> implements ModelRegistry<M> {
|
|
66
|
+
private cache;
|
|
67
|
+
private readonly testFunction;
|
|
68
|
+
constructor(testFunction?: (obj: Record<string, any>) => boolean);
|
|
69
|
+
/**
|
|
70
|
+
* @description Registers a model constructor with the registry
|
|
71
|
+
* @summary Adds a model constructor to the registry cache, making it available for
|
|
72
|
+
* later retrieval and instantiation. If no name is provided, the constructor's name
|
|
73
|
+
* property is used as the key in the registry.
|
|
74
|
+
*
|
|
75
|
+
* @param {ModelConstructor<M>} constructor - The model constructor to register
|
|
76
|
+
* @param {string} [name] - Optional name to register the constructor under, defaults to constructor.name
|
|
77
|
+
* @return {void}
|
|
78
|
+
* @throws {Error} If the constructor is not a function
|
|
79
|
+
*/
|
|
80
|
+
register(constructor: ModelConstructor<M>, name?: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* @summary Gets a registered Model {@link ModelConstructor}
|
|
83
|
+
* @param {string} name
|
|
84
|
+
*/
|
|
85
|
+
get(name: string): ModelConstructor<M> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* @param {Record<string, any>} obj
|
|
88
|
+
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
89
|
+
*
|
|
90
|
+
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
91
|
+
*/
|
|
92
|
+
build(obj?: Record<string, any>, clazz?: string): M;
|
|
93
|
+
/**
|
|
94
|
+
* @description Configures the global model builder function
|
|
95
|
+
* @summary Sets the Global {@link ModelBuilderFunction} used for building model instances
|
|
96
|
+
*
|
|
97
|
+
* @param {ModelBuilderFunction} [builder] - The builder function to set as the global builder
|
|
98
|
+
* @return {void}
|
|
99
|
+
*/
|
|
100
|
+
static setBuilder(builder?: ModelBuilderFunction): void;
|
|
101
|
+
/**
|
|
102
|
+
* @description Retrieves the currently configured global model builder function
|
|
103
|
+
* @summary Returns the current global {@link ModelBuilderFunction} used for building model instances
|
|
104
|
+
*
|
|
105
|
+
* @return {ModelBuilderFunction | undefined} - The current global builder function or undefined if not set
|
|
106
|
+
*/
|
|
107
|
+
static getBuilder(): ModelBuilderFunction | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* @description Copies and rebuilds properties from a source object to a model instance, handling nested models
|
|
110
|
+
* @summary Repopulates the instance with properties from the new Model Object, recursively rebuilding nested models
|
|
111
|
+
*
|
|
112
|
+
* @template T
|
|
113
|
+
* @param {T} self - The target model instance to update
|
|
114
|
+
* @param {T | Record<string, any>} [obj] - The source object containing properties to copy
|
|
115
|
+
* @return {T} - The updated model instance with rebuilt nested models
|
|
116
|
+
*
|
|
117
|
+
* @mermaid
|
|
118
|
+
* sequenceDiagram
|
|
119
|
+
* participant C as Client
|
|
120
|
+
* participant M as Model.fromModel
|
|
121
|
+
* participant B as Model.build
|
|
122
|
+
* participant R as Reflection
|
|
123
|
+
*
|
|
124
|
+
* C->>M: fromModel(self, obj)
|
|
125
|
+
* M->>M: Get attributes from self
|
|
126
|
+
* loop For each property
|
|
127
|
+
* M->>M: Copy property from obj to self
|
|
128
|
+
* alt Property is a model
|
|
129
|
+
* M->>M: Check if property is a model
|
|
130
|
+
* M->>B: build(property, modelType)
|
|
131
|
+
* B-->>M: Return built model
|
|
132
|
+
* else Property is a complex type
|
|
133
|
+
* M->>R: Get property decorators
|
|
134
|
+
* R-->>M: Return decorators
|
|
135
|
+
* M->>M: Filter type decorators
|
|
136
|
+
* alt Property is Array/Set with list decorator
|
|
137
|
+
* M->>M: Process each item in collection
|
|
138
|
+
* loop For each item
|
|
139
|
+
* M->>B: build(item, itemModelType)
|
|
140
|
+
* B-->>M: Return built model
|
|
141
|
+
* end
|
|
142
|
+
* else Property is another model type
|
|
143
|
+
* M->>B: build(property, propertyType)
|
|
144
|
+
* B-->>M: Return built model
|
|
145
|
+
* end
|
|
146
|
+
* end
|
|
147
|
+
* end
|
|
148
|
+
* M-->>C: Return updated self
|
|
149
|
+
*/
|
|
150
|
+
static fromModel<T extends Model>(self: T, obj?: T | Record<string, any>): T;
|
|
151
|
+
/**
|
|
152
|
+
* @description Provides access to the current model registry
|
|
153
|
+
* @summary Returns the current {@link ModelRegistryManager} instance, creating one if it doesn't exist
|
|
154
|
+
*
|
|
155
|
+
* @return {ModelRegistry<any>} - The current model registry, defaults to a new {@link ModelRegistryManager} if not set
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
static getRegistry(): BuilderRegistry<any>;
|
|
159
|
+
/**
|
|
160
|
+
* @description Configures the model registry to be used by the Model system
|
|
161
|
+
* @summary Sets the current model registry to a custom implementation
|
|
162
|
+
*
|
|
163
|
+
* @param {BuilderRegistry<any>} modelRegistry - The new implementation of Registry to use
|
|
164
|
+
* @return {void}
|
|
165
|
+
*/
|
|
166
|
+
static setRegistry(modelRegistry: BuilderRegistry<any>): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @summary Bulk Registers Models
|
|
170
|
+
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
171
|
+
*
|
|
172
|
+
* @template M extends Model
|
|
173
|
+
* @param {Array<Constructor<M>> | Array<{name: string, constructor: Constructor<M>}>} [models]
|
|
174
|
+
*
|
|
175
|
+
* @memberOf module:decorator-validation
|
|
176
|
+
* @category Model
|
|
177
|
+
*/
|
|
178
|
+
export declare function bulkModelRegister<M extends Model>(...models: (Constructor<M> | {
|
|
179
|
+
name: string;
|
|
180
|
+
constructor: Constructor<M>;
|
|
181
|
+
})[]): void;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { ModelBuilderFunction, ModelConstructor } from "./types.js";
|
|
3
|
+
import { type Model } from "./Model.js";
|
|
4
|
+
import { BuilderRegistry } from "../utils/registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* @description Registry type for storing and retrieving model constructors
|
|
7
|
+
* @summary The ModelRegistry type defines a registry for model constructors that extends
|
|
8
|
+
* the BuilderRegistry interface. It provides a standardized way to register, retrieve,
|
|
9
|
+
* and build model instances, enabling the model system to work with different types of models.
|
|
10
|
+
*
|
|
11
|
+
* @interface ModelRegistry
|
|
12
|
+
* @template T Type of model that can be registered, must extend Model
|
|
13
|
+
* @extends BuilderRegistry<T>
|
|
14
|
+
* @memberOf module:decorator-validation
|
|
15
|
+
* @category Model
|
|
16
|
+
*/
|
|
17
|
+
export type ModelRegistry<T extends Model> = BuilderRegistry<T>;
|
|
18
|
+
/**
|
|
19
|
+
* @description Registry manager for model constructors that enables serialization and rebuilding
|
|
20
|
+
* @summary The ModelRegistryManager implements the ModelRegistry interface and provides
|
|
21
|
+
* functionality for registering, retrieving, and building model instances. It maintains
|
|
22
|
+
* a cache of model constructors indexed by name, allowing for efficient lookup and instantiation.
|
|
23
|
+
* This class is essential for the serialization and deserialization of model objects.
|
|
24
|
+
*
|
|
25
|
+
* @param {function(Record<string, any>): boolean} [testFunction] - Function to test if an object is a model, defaults to {@link Model#isModel}
|
|
26
|
+
*
|
|
27
|
+
* @class ModelRegistryManager
|
|
28
|
+
* @template M Type of model that can be registered, must extend Model
|
|
29
|
+
* @implements ModelRegistry<M>
|
|
30
|
+
* @category Model
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Create a model registry
|
|
35
|
+
* const registry = new ModelRegistryManager();
|
|
36
|
+
*
|
|
37
|
+
* // Register a model class
|
|
38
|
+
* registry.register(User);
|
|
39
|
+
*
|
|
40
|
+
* // Retrieve a model constructor by name
|
|
41
|
+
* const UserClass = registry.get("User");
|
|
42
|
+
*
|
|
43
|
+
* // Build a model instance from a plain object
|
|
44
|
+
* const userData = { name: "John", age: 30 };
|
|
45
|
+
* const user = registry.build(userData, "User");
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @mermaid
|
|
49
|
+
* sequenceDiagram
|
|
50
|
+
* participant C as Client
|
|
51
|
+
* participant R as ModelRegistryManager
|
|
52
|
+
* participant M as Model Class
|
|
53
|
+
*
|
|
54
|
+
* C->>R: new ModelRegistryManager(testFunction)
|
|
55
|
+
* C->>R: register(ModelClass)
|
|
56
|
+
* R->>R: Store in cache
|
|
57
|
+
* C->>R: get("ModelName")
|
|
58
|
+
* R-->>C: ModelClass constructor
|
|
59
|
+
* C->>R: build(data, "ModelName")
|
|
60
|
+
* R->>R: Get constructor from cache
|
|
61
|
+
* R->>M: new ModelClass(data)
|
|
62
|
+
* M-->>R: Model instance
|
|
63
|
+
* R-->>C: Model instance
|
|
64
|
+
*/
|
|
65
|
+
export declare class ModelRegistryManager<M extends Model<true | false>> implements ModelRegistry<M> {
|
|
66
|
+
private cache;
|
|
67
|
+
private readonly testFunction;
|
|
68
|
+
constructor(testFunction?: (obj: Record<string, any>) => boolean);
|
|
69
|
+
/**
|
|
70
|
+
* @description Registers a model constructor with the registry
|
|
71
|
+
* @summary Adds a model constructor to the registry cache, making it available for
|
|
72
|
+
* later retrieval and instantiation. If no name is provided, the constructor's name
|
|
73
|
+
* property is used as the key in the registry.
|
|
74
|
+
*
|
|
75
|
+
* @param {ModelConstructor<M>} constructor - The model constructor to register
|
|
76
|
+
* @param {string} [name] - Optional name to register the constructor under, defaults to constructor.name
|
|
77
|
+
* @return {void}
|
|
78
|
+
* @throws {Error} If the constructor is not a function
|
|
79
|
+
*/
|
|
80
|
+
register(constructor: ModelConstructor<M>, name?: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* @summary Gets a registered Model {@link ModelConstructor}
|
|
83
|
+
* @param {string} name
|
|
84
|
+
*/
|
|
85
|
+
get(name: string): ModelConstructor<M> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* @param {Record<string, any>} obj
|
|
88
|
+
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
89
|
+
*
|
|
90
|
+
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
91
|
+
*/
|
|
92
|
+
build(obj?: Record<string, any>, clazz?: string): M;
|
|
93
|
+
/**
|
|
94
|
+
* @description Configures the global model builder function
|
|
95
|
+
* @summary Sets the Global {@link ModelBuilderFunction} used for building model instances
|
|
96
|
+
*
|
|
97
|
+
* @param {ModelBuilderFunction} [builder] - The builder function to set as the global builder
|
|
98
|
+
* @return {void}
|
|
99
|
+
*/
|
|
100
|
+
static setBuilder(builder?: ModelBuilderFunction): void;
|
|
101
|
+
/**
|
|
102
|
+
* @description Retrieves the currently configured global model builder function
|
|
103
|
+
* @summary Returns the current global {@link ModelBuilderFunction} used for building model instances
|
|
104
|
+
*
|
|
105
|
+
* @return {ModelBuilderFunction | undefined} - The current global builder function or undefined if not set
|
|
106
|
+
*/
|
|
107
|
+
static getBuilder(): ModelBuilderFunction | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* @description Copies and rebuilds properties from a source object to a model instance, handling nested models
|
|
110
|
+
* @summary Repopulates the instance with properties from the new Model Object, recursively rebuilding nested models
|
|
111
|
+
*
|
|
112
|
+
* @template T
|
|
113
|
+
* @param {T} self - The target model instance to update
|
|
114
|
+
* @param {T | Record<string, any>} [obj] - The source object containing properties to copy
|
|
115
|
+
* @return {T} - The updated model instance with rebuilt nested models
|
|
116
|
+
*
|
|
117
|
+
* @mermaid
|
|
118
|
+
* sequenceDiagram
|
|
119
|
+
* participant C as Client
|
|
120
|
+
* participant M as Model.fromModel
|
|
121
|
+
* participant B as Model.build
|
|
122
|
+
* participant R as Reflection
|
|
123
|
+
*
|
|
124
|
+
* C->>M: fromModel(self, obj)
|
|
125
|
+
* M->>M: Get attributes from self
|
|
126
|
+
* loop For each property
|
|
127
|
+
* M->>M: Copy property from obj to self
|
|
128
|
+
* alt Property is a model
|
|
129
|
+
* M->>M: Check if property is a model
|
|
130
|
+
* M->>B: build(property, modelType)
|
|
131
|
+
* B-->>M: Return built model
|
|
132
|
+
* else Property is a complex type
|
|
133
|
+
* M->>R: Get property decorators
|
|
134
|
+
* R-->>M: Return decorators
|
|
135
|
+
* M->>M: Filter type decorators
|
|
136
|
+
* alt Property is Array/Set with list decorator
|
|
137
|
+
* M->>M: Process each item in collection
|
|
138
|
+
* loop For each item
|
|
139
|
+
* M->>B: build(item, itemModelType)
|
|
140
|
+
* B-->>M: Return built model
|
|
141
|
+
* end
|
|
142
|
+
* else Property is another model type
|
|
143
|
+
* M->>B: build(property, propertyType)
|
|
144
|
+
* B-->>M: Return built model
|
|
145
|
+
* end
|
|
146
|
+
* end
|
|
147
|
+
* end
|
|
148
|
+
* M-->>C: Return updated self
|
|
149
|
+
*/
|
|
150
|
+
static fromModel<T extends Model>(self: T, obj?: T | Record<string, any>): T;
|
|
151
|
+
/**
|
|
152
|
+
* @description Provides access to the current model registry
|
|
153
|
+
* @summary Returns the current {@link ModelRegistryManager} instance, creating one if it doesn't exist
|
|
154
|
+
*
|
|
155
|
+
* @return {ModelRegistry<any>} - The current model registry, defaults to a new {@link ModelRegistryManager} if not set
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
static getRegistry(): BuilderRegistry<any>;
|
|
159
|
+
/**
|
|
160
|
+
* @description Configures the model registry to be used by the Model system
|
|
161
|
+
* @summary Sets the current model registry to a custom implementation
|
|
162
|
+
*
|
|
163
|
+
* @param {BuilderRegistry<any>} modelRegistry - The new implementation of Registry to use
|
|
164
|
+
* @return {void}
|
|
165
|
+
*/
|
|
166
|
+
static setRegistry(modelRegistry: BuilderRegistry<any>): void;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @summary Bulk Registers Models
|
|
170
|
+
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
171
|
+
*
|
|
172
|
+
* @template M extends Model
|
|
173
|
+
* @param {Array<Constructor<M>> | Array<{name: string, constructor: Constructor<M>}>} [models]
|
|
174
|
+
*
|
|
175
|
+
* @memberOf module:decorator-validation
|
|
176
|
+
* @category Model
|
|
177
|
+
*/
|
|
178
|
+
export declare function bulkModelRegister<M extends Model>(...models: (Constructor<M> | {
|
|
179
|
+
name: string;
|
|
180
|
+
constructor: Constructor<M>;
|
|
181
|
+
})[]): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Enumeration of JavaScript primitive type identifiers used by the model system.
|
|
3
|
+
* @summary References the relevant JS primitives and standardizes their string representations across the library.
|
|
4
|
+
* @property {string} STRING references the string primitive
|
|
5
|
+
* @property {string} NUMBER references the number primitive
|
|
6
|
+
* @property {string} BOOLEAN references the boolean primitive
|
|
7
|
+
* @property {string} BIGINT references the bigint primitive
|
|
8
|
+
* @enum Primitives
|
|
9
|
+
* @readonly
|
|
10
|
+
* @memberOf module:decorator-validation
|
|
11
|
+
*/
|
|
12
|
+
export declare enum Primitives {
|
|
13
|
+
/** references the string primitive */
|
|
14
|
+
STRING = "string",
|
|
15
|
+
/** references the number primitive */
|
|
16
|
+
NUMBER = "number",
|
|
17
|
+
/** references the boolean primitive */
|
|
18
|
+
BOOLEAN = "boolean",
|
|
19
|
+
/** references the bigint primitive */
|
|
20
|
+
BIGINT = "bigint"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @description Reserved model names which are excluded from model rebuilding.
|
|
24
|
+
* @summary References the Reserved model names to ignore during Model rebuilding to avoid interfering with native types and special cases.
|
|
25
|
+
* @property {string} STRING
|
|
26
|
+
* @property {string} OBJECT
|
|
27
|
+
* @property {string} NUMBER
|
|
28
|
+
* @property {string} BOOLEAN
|
|
29
|
+
* @property {string} BIGINT
|
|
30
|
+
* @property {string} DATE
|
|
31
|
+
* @enum ReservedModels
|
|
32
|
+
* @readonly
|
|
33
|
+
* @memberOf module:decorator-validation
|
|
34
|
+
*/
|
|
35
|
+
export declare const ReservedModels: {
|
|
36
|
+
/** reserved name for string */
|
|
37
|
+
STRING: StringConstructor;
|
|
38
|
+
/** reserved name for object */
|
|
39
|
+
OBJECT: ObjectConstructor;
|
|
40
|
+
/** reserved name for number */
|
|
41
|
+
NUMBER: NumberConstructor;
|
|
42
|
+
/** reserved name for boolean */
|
|
43
|
+
BOOLEAN: BooleanConstructor;
|
|
44
|
+
/** reserved name for bigint */
|
|
45
|
+
BIGINT: BigIntConstructor;
|
|
46
|
+
/** reserved name for Date */
|
|
47
|
+
DATE: DateConstructor;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @description Basic supported JavaScript types used by the validation system.
|
|
51
|
+
* @summary References the basic supported JS types as strings that can be used for type checking and metadata.
|
|
52
|
+
* @typedef {Object} JsTypes
|
|
53
|
+
* @property {"string"} string String primitive identifier
|
|
54
|
+
* @property {"array"} array Array type identifier
|
|
55
|
+
* @property {"number"} number Number primitive identifier
|
|
56
|
+
* @property {"boolean"} boolean Boolean primitive identifier
|
|
57
|
+
* @property {"symbol"} symbol Symbol primitive identifier
|
|
58
|
+
* @property {"function"} function Function type identifier
|
|
59
|
+
* @property {"object"} object Object type identifier
|
|
60
|
+
* @property {"undefined"} undefined Undefined type identifier
|
|
61
|
+
* @property {"null"} null Null value identifier
|
|
62
|
+
* @property {"bigint"} BIGINT BigInt primitive identifier
|
|
63
|
+
* @memberOf module:decorator-validation
|
|
64
|
+
*/
|
|
65
|
+
export declare const jsTypes: string[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Enumeration of JavaScript primitive type identifiers used by the model system.
|
|
3
|
+
* @summary References the relevant JS primitives and standardizes their string representations across the library.
|
|
4
|
+
* @property {string} STRING references the string primitive
|
|
5
|
+
* @property {string} NUMBER references the number primitive
|
|
6
|
+
* @property {string} BOOLEAN references the boolean primitive
|
|
7
|
+
* @property {string} BIGINT references the bigint primitive
|
|
8
|
+
* @enum Primitives
|
|
9
|
+
* @readonly
|
|
10
|
+
* @memberOf module:decorator-validation
|
|
11
|
+
*/
|
|
12
|
+
export declare enum Primitives {
|
|
13
|
+
/** references the string primitive */
|
|
14
|
+
STRING = "string",
|
|
15
|
+
/** references the number primitive */
|
|
16
|
+
NUMBER = "number",
|
|
17
|
+
/** references the boolean primitive */
|
|
18
|
+
BOOLEAN = "boolean",
|
|
19
|
+
/** references the bigint primitive */
|
|
20
|
+
BIGINT = "bigint"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @description Reserved model names which are excluded from model rebuilding.
|
|
24
|
+
* @summary References the Reserved model names to ignore during Model rebuilding to avoid interfering with native types and special cases.
|
|
25
|
+
* @property {string} STRING
|
|
26
|
+
* @property {string} OBJECT
|
|
27
|
+
* @property {string} NUMBER
|
|
28
|
+
* @property {string} BOOLEAN
|
|
29
|
+
* @property {string} BIGINT
|
|
30
|
+
* @property {string} DATE
|
|
31
|
+
* @enum ReservedModels
|
|
32
|
+
* @readonly
|
|
33
|
+
* @memberOf module:decorator-validation
|
|
34
|
+
*/
|
|
35
|
+
export declare const ReservedModels: {
|
|
36
|
+
/** reserved name for string */
|
|
37
|
+
STRING: StringConstructor;
|
|
38
|
+
/** reserved name for object */
|
|
39
|
+
OBJECT: ObjectConstructor;
|
|
40
|
+
/** reserved name for number */
|
|
41
|
+
NUMBER: NumberConstructor;
|
|
42
|
+
/** reserved name for boolean */
|
|
43
|
+
BOOLEAN: BooleanConstructor;
|
|
44
|
+
/** reserved name for bigint */
|
|
45
|
+
BIGINT: BigIntConstructor;
|
|
46
|
+
/** reserved name for Date */
|
|
47
|
+
DATE: DateConstructor;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @description Basic supported JavaScript types used by the validation system.
|
|
51
|
+
* @summary References the basic supported JS types as strings that can be used for type checking and metadata.
|
|
52
|
+
* @typedef {Object} JsTypes
|
|
53
|
+
* @property {"string"} string String primitive identifier
|
|
54
|
+
* @property {"array"} array Array type identifier
|
|
55
|
+
* @property {"number"} number Number primitive identifier
|
|
56
|
+
* @property {"boolean"} boolean Boolean primitive identifier
|
|
57
|
+
* @property {"symbol"} symbol Symbol primitive identifier
|
|
58
|
+
* @property {"function"} function Function type identifier
|
|
59
|
+
* @property {"object"} object Object type identifier
|
|
60
|
+
* @property {"undefined"} undefined Undefined type identifier
|
|
61
|
+
* @property {"null"} null Null value identifier
|
|
62
|
+
* @property {"bigint"} BIGINT BigInt primitive identifier
|
|
63
|
+
* @memberOf module:decorator-validation
|
|
64
|
+
*/
|
|
65
|
+
export declare const jsTypes: string[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Model } from "./Model.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* @description Helper function to create an instance by invoking a constructor with dynamic arguments.
|
|
4
|
+
* @summary Overrides standard construction patterns by wrapping the given constructor to allow spread argument invocation while preserving the prototype chain.
|
|
5
|
+
* @template M the model instance type
|
|
6
|
+
* @param {any} constructor The constructor function to invoke.
|
|
7
|
+
* @param {...any[]} args Optional arguments to pass to the constructor.
|
|
8
|
+
* @return {M} The newly constructed instance.
|
|
9
|
+
* @function construct
|
|
10
|
+
* @memberOf module:decorator-validation
|
|
11
|
+
*/
|
|
12
|
+
export declare function construct<M extends Model>(constructor: any, ...args: any[]): M;
|
|
13
|
+
/**
|
|
14
|
+
* @description Recursively finds the last prototype in the chain before reaching Object.prototype.
|
|
15
|
+
* @summary Walks up the prototype chain to locate the most derived prototype that still precedes the base Object prototype.
|
|
16
|
+
* @param {object} obj The object whose prototype chain will be inspected.
|
|
17
|
+
* @return {object} The last prototype before Object.prototype, or the input object if its prototype is Object.prototype.
|
|
18
|
+
* @function findLastProtoBeforeObject
|
|
19
|
+
* @memberOf module:decorator-validation
|
|
20
|
+
*/
|
|
21
|
+
export declare function findLastProtoBeforeObject(obj: object): object;
|
|
22
|
+
/**
|
|
23
|
+
* @description Binds the Model class as the root prototype of the provided instance when not already a Model.
|
|
24
|
+
* @summary Ensures objects created outside of the Model inheritance chain gain Model as their ultimate prototype to access model utilities.
|
|
25
|
+
* @param {unknown} obj The object to bind to the Model prototype chain.
|
|
26
|
+
* @return {void}
|
|
27
|
+
* @function bindModelPrototype
|
|
28
|
+
* @mermaid
|
|
29
|
+
* sequenceDiagram
|
|
30
|
+
* participant Caller
|
|
31
|
+
* participant Fn as bindModelPrototype
|
|
32
|
+
* participant M as Model.prototype
|
|
33
|
+
* Caller->>Fn: obj
|
|
34
|
+
* alt obj instanceof Model
|
|
35
|
+
* Fn-->>Caller: return
|
|
36
|
+
* else obj chain ends at Object.prototype
|
|
37
|
+
* Fn->>Fn: setPrototypeOf(obj, M)
|
|
38
|
+
* Fn-->>Caller: return
|
|
39
|
+
* else deep prototype chain
|
|
40
|
+
* Fn->>Fn: walk prototypes
|
|
41
|
+
* Fn->>Fn: setPrototypeOf(last, M)
|
|
42
|
+
* Fn-->>Caller: return
|
|
43
|
+
* end
|
|
44
|
+
* @memberOf module:decorator-validation
|
|
45
|
+
*/
|
|
46
|
+
export declare function bindModelPrototype(obj: unknown): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Model } from "./Model.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description Helper function to create an instance by invoking a constructor with dynamic arguments.
|
|
4
|
+
* @summary Overrides standard construction patterns by wrapping the given constructor to allow spread argument invocation while preserving the prototype chain.
|
|
5
|
+
* @template M the model instance type
|
|
6
|
+
* @param {any} constructor The constructor function to invoke.
|
|
7
|
+
* @param {...any[]} args Optional arguments to pass to the constructor.
|
|
8
|
+
* @return {M} The newly constructed instance.
|
|
9
|
+
* @function construct
|
|
10
|
+
* @memberOf module:decorator-validation
|
|
11
|
+
*/
|
|
12
|
+
export declare function construct<M extends Model>(constructor: any, ...args: any[]): M;
|
|
13
|
+
/**
|
|
14
|
+
* @description Recursively finds the last prototype in the chain before reaching Object.prototype.
|
|
15
|
+
* @summary Walks up the prototype chain to locate the most derived prototype that still precedes the base Object prototype.
|
|
16
|
+
* @param {object} obj The object whose prototype chain will be inspected.
|
|
17
|
+
* @return {object} The last prototype before Object.prototype, or the input object if its prototype is Object.prototype.
|
|
18
|
+
* @function findLastProtoBeforeObject
|
|
19
|
+
* @memberOf module:decorator-validation
|
|
20
|
+
*/
|
|
21
|
+
export declare function findLastProtoBeforeObject(obj: object): object;
|
|
22
|
+
/**
|
|
23
|
+
* @description Binds the Model class as the root prototype of the provided instance when not already a Model.
|
|
24
|
+
* @summary Ensures objects created outside of the Model inheritance chain gain Model as their ultimate prototype to access model utilities.
|
|
25
|
+
* @param {unknown} obj The object to bind to the Model prototype chain.
|
|
26
|
+
* @return {void}
|
|
27
|
+
* @function bindModelPrototype
|
|
28
|
+
* @mermaid
|
|
29
|
+
* sequenceDiagram
|
|
30
|
+
* participant Caller
|
|
31
|
+
* participant Fn as bindModelPrototype
|
|
32
|
+
* participant M as Model.prototype
|
|
33
|
+
* Caller->>Fn: obj
|
|
34
|
+
* alt obj instanceof Model
|
|
35
|
+
* Fn-->>Caller: return
|
|
36
|
+
* else obj chain ends at Object.prototype
|
|
37
|
+
* Fn->>Fn: setPrototypeOf(obj, M)
|
|
38
|
+
* Fn-->>Caller: return
|
|
39
|
+
* else deep prototype chain
|
|
40
|
+
* Fn->>Fn: walk prototypes
|
|
41
|
+
* Fn->>Fn: setPrototypeOf(last, M)
|
|
42
|
+
* Fn-->>Caller: return
|
|
43
|
+
* end
|
|
44
|
+
* @memberOf module:decorator-validation
|
|
45
|
+
*/
|
|
46
|
+
export declare function bindModelPrototype(obj: unknown): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Base decorator for model classes.
|
|
3
|
+
* @summary This decorator wraps the original constructor to bind the Model prototype, run a builder function, and register the model.
|
|
4
|
+
* @param {any} original The original constructor of the class.
|
|
5
|
+
* @return {any} The new constructor with added model functionality.
|
|
6
|
+
* @function modelBaseDecorator
|
|
7
|
+
* @memberOf module:decorator-validation
|
|
8
|
+
*/
|
|
9
|
+
export declare function modelBaseDecorator(original: any): any;
|
|
10
|
+
/**
|
|
11
|
+
* @summary Defines a class as a Model class
|
|
12
|
+
* @description
|
|
13
|
+
*
|
|
14
|
+
* - Registers the class under the model registry so it can be easily rebuilt;
|
|
15
|
+
* - Overrides the class constructor;
|
|
16
|
+
* - Runs the global {@link ModelBuilderFunction} if defined;
|
|
17
|
+
*
|
|
18
|
+
* @function model
|
|
19
|
+
*
|
|
20
|
+
* @category Class Decorators
|
|
21
|
+
*/
|
|
22
|
+
export declare function model(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
23
|
+
/**
|
|
24
|
+
* @summary Defines the hashing algorithm to use on the model
|
|
25
|
+
* @description
|
|
26
|
+
*
|
|
27
|
+
* - Registers the class under the model registry so it can be easily rebuilt;
|
|
28
|
+
* - Overrides the class constructor;
|
|
29
|
+
* - Runs the global {@link ModelBuilderFunction} if defined;
|
|
30
|
+
*
|
|
31
|
+
* @param {string} algorithm the algorithm to use
|
|
32
|
+
*
|
|
33
|
+
* @function hashedBy
|
|
34
|
+
*
|
|
35
|
+
* @category Class Decorators
|
|
36
|
+
*/
|
|
37
|
+
export declare function hashedBy(algorithm: string, ...args: any[]): (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|
|
38
|
+
/**
|
|
39
|
+
* @summary Defines the serialization algorithm to use on the model
|
|
40
|
+
*
|
|
41
|
+
* @param {string} serializer the algorithm to use
|
|
42
|
+
*
|
|
43
|
+
* @function serializedBy
|
|
44
|
+
*
|
|
45
|
+
* @category Class Decorators
|
|
46
|
+
*/
|
|
47
|
+
export declare function serializedBy(serializer: string, ...args: any[]): (model: any, prop?: any, descriptor?: PropertyDescriptor | number) => void;
|