@decaf-ts/decorator-validation 1.6.5 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorator-validation.cjs +1202 -386
- package/dist/decorator-validation.esm.cjs +1158 -341
- package/lib/constants/index.cjs +1 -1
- package/lib/esm/index.d.ts +5 -37
- package/lib/esm/index.js +6 -38
- package/lib/esm/model/Model.d.ts +107 -35
- package/lib/esm/model/Model.js +110 -45
- package/lib/esm/model/constants.d.ts +3 -3
- package/lib/esm/model/constants.js +4 -4
- package/lib/esm/model/construction.d.ts +3 -3
- package/lib/esm/model/construction.js +4 -4
- package/lib/esm/model/decorators.d.ts +3 -3
- package/lib/esm/model/decorators.js +5 -3
- package/lib/esm/model/index.d.ts +1 -0
- package/lib/esm/model/index.js +2 -1
- package/lib/esm/model/types.d.ts +30 -11
- package/lib/esm/model/types.js +1 -1
- package/lib/esm/model/utils.d.ts +3 -0
- package/lib/esm/model/utils.js +11 -0
- package/lib/esm/model/validation.d.ts +5 -5
- package/lib/esm/model/validation.js +8 -9
- package/lib/esm/utils/Decoration.d.ts +123 -0
- package/lib/esm/utils/Decoration.js +192 -0
- package/lib/esm/utils/constants.d.ts +27 -9
- package/lib/esm/utils/constants.js +28 -10
- package/lib/esm/utils/dates.d.ts +26 -16
- package/lib/esm/utils/dates.js +27 -17
- package/lib/esm/utils/decorators.d.ts +41 -0
- package/lib/esm/utils/decorators.js +42 -1
- package/lib/esm/utils/hashing.d.ts +50 -6
- package/lib/esm/utils/hashing.js +49 -5
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +2 -1
- package/lib/esm/utils/registry.d.ts +3 -3
- package/lib/esm/utils/registry.js +1 -1
- package/lib/esm/utils/serialization.d.ts +1 -1
- package/lib/esm/utils/serialization.js +4 -3
- package/lib/esm/utils/strings.d.ts +4 -4
- package/lib/esm/utils/strings.js +5 -5
- package/lib/esm/utils/types.d.ts +123 -16
- package/lib/esm/utils/types.js +1 -1
- package/lib/esm/validation/Validators/DateValidator.d.ts +40 -8
- package/lib/esm/validation/Validators/DateValidator.js +41 -9
- package/lib/esm/validation/Validators/EmailValidator.d.ts +39 -7
- package/lib/esm/validation/Validators/EmailValidator.js +40 -8
- package/lib/esm/validation/Validators/ListValidator.d.ts +44 -6
- package/lib/esm/validation/Validators/ListValidator.js +45 -7
- package/lib/esm/validation/Validators/MaxValidator.d.ts +52 -6
- package/lib/esm/validation/Validators/MaxValidator.js +53 -7
- package/lib/esm/validation/Validators/MinValidator.d.ts +52 -6
- package/lib/esm/validation/Validators/MinValidator.js +53 -7
- package/lib/esm/validation/Validators/PasswordValidator.js +1 -1
- package/lib/esm/validation/Validators/PatternValidator.d.ts +75 -9
- package/lib/esm/validation/Validators/PatternValidator.js +76 -10
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +52 -6
- package/lib/esm/validation/Validators/RequiredValidator.js +53 -7
- package/lib/esm/validation/Validators/TypeValidator.d.ts +60 -6
- package/lib/esm/validation/Validators/TypeValidator.js +69 -7
- package/lib/esm/validation/Validators/URLValidator.d.ts +41 -7
- package/lib/esm/validation/Validators/URLValidator.js +42 -8
- package/lib/esm/validation/Validators/Validator.d.ts +76 -16
- package/lib/esm/validation/Validators/Validator.js +68 -11
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +1 -7
- package/lib/esm/validation/Validators/ValidatorRegistry.js +4 -11
- package/lib/esm/validation/decorators.d.ts +50 -40
- package/lib/esm/validation/decorators.js +102 -53
- package/lib/esm/validation/types.d.ts +146 -28
- package/lib/esm/validation/types.js +1 -1
- package/lib/index.cjs +7 -39
- package/lib/index.d.ts +5 -37
- package/lib/model/Model.cjs +114 -51
- package/lib/model/Model.d.ts +107 -35
- package/lib/model/constants.cjs +4 -4
- package/lib/model/constants.d.ts +3 -3
- package/lib/model/construction.cjs +4 -4
- package/lib/model/construction.d.ts +3 -3
- package/lib/model/decorators.cjs +6 -4
- package/lib/model/decorators.d.ts +3 -3
- package/lib/model/index.cjs +2 -1
- package/lib/model/index.d.ts +1 -0
- package/lib/model/types.cjs +1 -1
- package/lib/model/types.d.ts +30 -11
- package/lib/model/utils.cjs +15 -0
- package/lib/model/utils.d.ts +3 -0
- package/lib/model/validation.cjs +11 -12
- package/lib/model/validation.d.ts +5 -5
- package/lib/utils/Decoration.cjs +196 -0
- package/lib/utils/Decoration.d.ts +123 -0
- package/lib/utils/constants.cjs +29 -11
- package/lib/utils/constants.d.ts +27 -9
- package/lib/utils/dates.cjs +28 -18
- package/lib/utils/dates.d.ts +26 -16
- package/lib/utils/decorators.cjs +42 -1
- package/lib/utils/decorators.d.ts +41 -0
- package/lib/utils/hashing.cjs +49 -5
- package/lib/utils/hashing.d.ts +50 -6
- package/lib/utils/index.cjs +2 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/registry.cjs +1 -1
- package/lib/utils/registry.d.ts +3 -3
- package/lib/utils/serialization.cjs +5 -4
- package/lib/utils/serialization.d.ts +1 -1
- package/lib/utils/strings.cjs +5 -5
- package/lib/utils/strings.d.ts +4 -4
- package/lib/utils/types.cjs +1 -1
- package/lib/utils/types.d.ts +123 -16
- package/lib/validation/Validation.cjs +1 -1
- package/lib/validation/Validators/DateValidator.cjs +41 -9
- package/lib/validation/Validators/DateValidator.d.ts +40 -8
- package/lib/validation/Validators/DiffValidator.cjs +1 -1
- package/lib/validation/Validators/EmailValidator.cjs +40 -8
- package/lib/validation/Validators/EmailValidator.d.ts +39 -7
- package/lib/validation/Validators/EqualsValidator.cjs +1 -1
- package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +1 -1
- package/lib/validation/Validators/GreaterThanValidator.cjs +1 -1
- package/lib/validation/Validators/LessThanOrEqualValidator.cjs +1 -1
- package/lib/validation/Validators/LessThanValidator.cjs +1 -1
- package/lib/validation/Validators/ListValidator.cjs +45 -7
- package/lib/validation/Validators/ListValidator.d.ts +44 -6
- package/lib/validation/Validators/MaxLengthValidator.cjs +1 -1
- package/lib/validation/Validators/MaxValidator.cjs +53 -7
- package/lib/validation/Validators/MaxValidator.d.ts +52 -6
- package/lib/validation/Validators/MinLengthValidator.cjs +1 -1
- package/lib/validation/Validators/MinValidator.cjs +53 -7
- package/lib/validation/Validators/MinValidator.d.ts +52 -6
- package/lib/validation/Validators/PasswordValidator.cjs +1 -1
- package/lib/validation/Validators/PatternValidator.cjs +76 -10
- package/lib/validation/Validators/PatternValidator.d.ts +75 -9
- package/lib/validation/Validators/RequiredValidator.cjs +53 -7
- package/lib/validation/Validators/RequiredValidator.d.ts +52 -6
- package/lib/validation/Validators/StepValidator.cjs +1 -1
- package/lib/validation/Validators/TypeValidator.cjs +71 -9
- package/lib/validation/Validators/TypeValidator.d.ts +60 -6
- package/lib/validation/Validators/URLValidator.cjs +42 -8
- package/lib/validation/Validators/URLValidator.d.ts +41 -7
- package/lib/validation/Validators/Validator.cjs +69 -12
- package/lib/validation/Validators/Validator.d.ts +76 -16
- package/lib/validation/Validators/ValidatorRegistry.cjs +4 -12
- package/lib/validation/Validators/ValidatorRegistry.d.ts +1 -7
- package/lib/validation/Validators/constants.cjs +2 -2
- package/lib/validation/Validators/decorators.cjs +2 -2
- package/lib/validation/Validators/index.cjs +1 -1
- package/lib/validation/Validators/utils.cjs +3 -3
- package/lib/validation/decorators.cjs +105 -56
- package/lib/validation/decorators.d.ts +50 -40
- package/lib/validation/index.cjs +1 -1
- package/lib/validation/types.cjs +1 -1
- package/lib/validation/types.d.ts +146 -28
- package/package.json +2 -1
package/lib/constants/index.cjs
CHANGED
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./validation.cjs"), exports);
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uc3RhbnRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSxtREFBNkIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG4iXX0=
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module decorator-validation
|
|
3
|
+
* @description TypeScript decorator-based validation library
|
|
4
|
+
* @summary This module provides a comprehensive validation framework using TypeScript decorators.
|
|
5
|
+
* It exposes utility functions, validation decorators, and model-related functionality for
|
|
6
|
+
* implementing type-safe, declarative validation in TypeScript applications.
|
|
3
7
|
*/
|
|
4
|
-
/**
|
|
5
|
-
* @summary Model definition functionality
|
|
6
|
-
* @description defines the base class and related functionality
|
|
7
|
-
*
|
|
8
|
-
* @namespace Model
|
|
9
|
-
* @memberOf module:decorator-validation
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* @summary Holds all the supported decorators
|
|
13
|
-
* @namespace Decorators
|
|
14
|
-
* @memberOf module:decorator-validation
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @summary Validation related functionality
|
|
18
|
-
* @description Defines the Model validation apis and base classes for validators
|
|
19
|
-
*
|
|
20
|
-
* @namespace Validation
|
|
21
|
-
* @memberOf module:decorator-validation
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* @namespace Dates
|
|
25
|
-
* @memberOf module:decorator-validation
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* @namespace Hashing
|
|
29
|
-
* @memberOf module:decorator-validation
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* @namespace Serialization
|
|
33
|
-
* @memberOf module:decorator-validation
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @namespace Format
|
|
37
|
-
* @memberOf module:decorator-validation
|
|
38
|
-
*/
|
|
39
|
-
export * from "./constants";
|
|
40
8
|
export * from "./utils";
|
|
41
9
|
export * from "./validation";
|
|
42
10
|
export * from "./model";
|
|
43
|
-
export declare const VERSION = "1.
|
|
11
|
+
export declare const VERSION = "1.7.1";
|
package/lib/esm/index.js
CHANGED
|
@@ -1,44 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module decorator-validation
|
|
3
|
+
* @description TypeScript decorator-based validation library
|
|
4
|
+
* @summary This module provides a comprehensive validation framework using TypeScript decorators.
|
|
5
|
+
* It exposes utility functions, validation decorators, and model-related functionality for
|
|
6
|
+
* implementing type-safe, declarative validation in TypeScript applications.
|
|
3
7
|
*/
|
|
4
|
-
/**
|
|
5
|
-
* @summary Model definition functionality
|
|
6
|
-
* @description defines the base class and related functionality
|
|
7
|
-
*
|
|
8
|
-
* @namespace Model
|
|
9
|
-
* @memberOf module:decorator-validation
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* @summary Holds all the supported decorators
|
|
13
|
-
* @namespace Decorators
|
|
14
|
-
* @memberOf module:decorator-validation
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @summary Validation related functionality
|
|
18
|
-
* @description Defines the Model validation apis and base classes for validators
|
|
19
|
-
*
|
|
20
|
-
* @namespace Validation
|
|
21
|
-
* @memberOf module:decorator-validation
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* @namespace Dates
|
|
25
|
-
* @memberOf module:decorator-validation
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* @namespace Hashing
|
|
29
|
-
* @memberOf module:decorator-validation
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* @namespace Serialization
|
|
33
|
-
* @memberOf module:decorator-validation
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @namespace Format
|
|
37
|
-
* @memberOf module:decorator-validation
|
|
38
|
-
*/
|
|
39
|
-
export * from "./constants";
|
|
40
8
|
export * from "./utils";
|
|
41
9
|
export * from "./validation";
|
|
42
10
|
export * from "./model";
|
|
43
|
-
export const VERSION = "1.
|
|
44
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
export const VERSION = "1.7.1";
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsY0FBYyxTQUFTLENBQUM7QUFDeEIsY0FBYyxjQUFjLENBQUM7QUFDN0IsY0FBYyxTQUFTLENBQUM7QUFFeEIsTUFBTSxDQUFDLE1BQU0sT0FBTyxHQUFHLGFBQWEsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQG1vZHVsZSBkZWNvcmF0b3ItdmFsaWRhdGlvblxuICogQGRlc2NyaXB0aW9uIFR5cGVTY3JpcHQgZGVjb3JhdG9yLWJhc2VkIHZhbGlkYXRpb24gbGlicmFyeVxuICogQHN1bW1hcnkgVGhpcyBtb2R1bGUgcHJvdmlkZXMgYSBjb21wcmVoZW5zaXZlIHZhbGlkYXRpb24gZnJhbWV3b3JrIHVzaW5nIFR5cGVTY3JpcHQgZGVjb3JhdG9ycy5cbiAqIEl0IGV4cG9zZXMgdXRpbGl0eSBmdW5jdGlvbnMsIHZhbGlkYXRpb24gZGVjb3JhdG9ycywgYW5kIG1vZGVsLXJlbGF0ZWQgZnVuY3Rpb25hbGl0eSBmb3JcbiAqIGltcGxlbWVudGluZyB0eXBlLXNhZmUsIGRlY2xhcmF0aXZlIHZhbGlkYXRpb24gaW4gVHlwZVNjcmlwdCBhcHBsaWNhdGlvbnMuXG4gKi9cbmV4cG9ydCAqIGZyb20gXCIuL3V0aWxzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9tb2RlbFwiO1xuXG5leHBvcnQgY29uc3QgVkVSU0lPTiA9IFwiIyNWRVJTSU9OIyNcIjtcbiJdfQ==
|
package/lib/esm/model/Model.d.ts
CHANGED
|
@@ -1,71 +1,108 @@
|
|
|
1
1
|
import { BuilderRegistry } from "../utils/registry";
|
|
2
2
|
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
3
3
|
import { Comparable, Constructor, Hashable, ModelArg, ModelBuilderFunction, ModelConstructor, Serializable, Validatable } from "./types";
|
|
4
|
-
export declare function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
5
4
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @memberOf module:decorator-validation.Validation
|
|
11
|
-
* @category Validation
|
|
12
|
-
*/
|
|
13
|
-
export declare function isModel(target: Record<string, any>): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @summary ModelRegistry Interface
|
|
5
|
+
* @description Registry type for storing and retrieving model constructors
|
|
6
|
+
* @summary The ModelRegistry type defines a registry for model constructors that extends
|
|
7
|
+
* the BuilderRegistry interface. It provides a standardized way to register, retrieve,
|
|
8
|
+
* and build model instances, enabling the model system to work with different types of models.
|
|
16
9
|
*
|
|
17
10
|
* @interface ModelRegistry
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
11
|
+
* @template T Type of model that can be registered, must extend Model
|
|
12
|
+
* @extends BuilderRegistry<T>
|
|
13
|
+
* @memberOf module:decorator-validation
|
|
20
14
|
* @category Model
|
|
21
15
|
*/
|
|
22
16
|
export type ModelRegistry<T extends Model> = BuilderRegistry<T>;
|
|
23
17
|
/**
|
|
24
|
-
* @
|
|
18
|
+
* @description Registry manager for model constructors that enables serialization and rebuilding
|
|
19
|
+
* @summary The ModelRegistryManager implements the ModelRegistry interface and provides
|
|
20
|
+
* functionality for registering, retrieving, and building model instances. It maintains
|
|
21
|
+
* a cache of model constructors indexed by name, allowing for efficient lookup and instantiation.
|
|
22
|
+
* This class is essential for the serialization and deserialization of model objects.
|
|
25
23
|
*
|
|
26
|
-
* @param {string}
|
|
27
|
-
* @param {function(Record<string, any>): boolean} [testFunction] method to test if the provided object is a Model Object. defaults to {@link isModel}
|
|
24
|
+
* @param {function(Record<string, any>): boolean} [testFunction] - Function to test if an object is a model, defaults to {@link Model#isModel}
|
|
28
25
|
*
|
|
29
26
|
* @class ModelRegistryManager
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
27
|
+
* @template M Type of model that can be registered, must extend Model
|
|
28
|
+
* @implements ModelRegistry<M>
|
|
32
29
|
* @category Model
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Create a model registry
|
|
34
|
+
* const registry = new ModelRegistryManager();
|
|
35
|
+
*
|
|
36
|
+
* // Register a model class
|
|
37
|
+
* registry.register(User);
|
|
38
|
+
*
|
|
39
|
+
* // Retrieve a model constructor by name
|
|
40
|
+
* const UserClass = registry.get("User");
|
|
41
|
+
*
|
|
42
|
+
* // Build a model instance from a plain object
|
|
43
|
+
* const userData = { name: "John", age: 30 };
|
|
44
|
+
* const user = registry.build(userData, "User");
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @mermaid
|
|
48
|
+
* sequenceDiagram
|
|
49
|
+
* participant C as Client
|
|
50
|
+
* participant R as ModelRegistryManager
|
|
51
|
+
* participant M as Model Class
|
|
52
|
+
*
|
|
53
|
+
* C->>R: new ModelRegistryManager(testFunction)
|
|
54
|
+
* C->>R: register(ModelClass)
|
|
55
|
+
* R->>R: Store in cache
|
|
56
|
+
* C->>R: get("ModelName")
|
|
57
|
+
* R-->>C: ModelClass constructor
|
|
58
|
+
* C->>R: build(data, "ModelName")
|
|
59
|
+
* R->>R: Get constructor from cache
|
|
60
|
+
* R->>M: new ModelClass(data)
|
|
61
|
+
* M-->>R: Model instance
|
|
62
|
+
* R-->>C: Model instance
|
|
33
63
|
*/
|
|
34
|
-
export declare class ModelRegistryManager<
|
|
64
|
+
export declare class ModelRegistryManager<M extends Model> implements ModelRegistry<M> {
|
|
35
65
|
private cache;
|
|
36
66
|
private readonly testFunction;
|
|
37
67
|
constructor(testFunction?: (obj: Record<string, any>) => boolean);
|
|
38
68
|
/**
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
69
|
+
* @description Registers a model constructor with the registry
|
|
70
|
+
* @summary Adds a model constructor to the registry cache, making it available for
|
|
71
|
+
* later retrieval and instantiation. If no name is provided, the constructor's name
|
|
72
|
+
* property is used as the key in the registry.
|
|
73
|
+
*
|
|
74
|
+
* @param {ModelConstructor<M>} constructor - The model constructor to register
|
|
75
|
+
* @param {string} [name] - Optional name to register the constructor under, defaults to constructor.name
|
|
76
|
+
* @return {void}
|
|
77
|
+
* @throws {Error} If the constructor is not a function
|
|
42
78
|
*/
|
|
43
|
-
register(constructor: ModelConstructor<
|
|
79
|
+
register(constructor: ModelConstructor<M>, name?: string): void;
|
|
44
80
|
/**
|
|
45
81
|
* @summary Gets a registered Model {@link ModelConstructor}
|
|
46
82
|
* @param {string} name
|
|
47
83
|
*/
|
|
48
|
-
get(name: string): ModelConstructor<
|
|
84
|
+
get(name: string): ModelConstructor<M> | undefined;
|
|
49
85
|
/**
|
|
50
86
|
* @param {Record<string, any>} obj
|
|
51
87
|
* @param {string} [clazz] when provided, it will attempt to find the matching constructor
|
|
52
88
|
*
|
|
53
89
|
* @throws Error If clazz is not found, or obj is not a {@link Model} meaning it has no {@link ModelKeys.ANCHOR} property
|
|
54
90
|
*/
|
|
55
|
-
build(obj?: Record<string, any>, clazz?: string):
|
|
91
|
+
build(obj?: Record<string, any>, clazz?: string): M;
|
|
56
92
|
}
|
|
57
93
|
/**
|
|
58
94
|
* @summary Bulk Registers Models
|
|
59
95
|
* @description Useful when using bundlers that might not evaluate all the code at once
|
|
60
96
|
*
|
|
61
|
-
* @
|
|
97
|
+
* @template M extends Model
|
|
98
|
+
* @param {Array<Constructor<M>> | Array<{name: string, constructor: Constructor<M>}>} [models]
|
|
62
99
|
*
|
|
63
|
-
* @memberOf module:decorator-validation
|
|
100
|
+
* @memberOf module:decorator-validation
|
|
64
101
|
* @category Model
|
|
65
102
|
*/
|
|
66
|
-
export declare function bulkModelRegister<
|
|
103
|
+
export declare function bulkModelRegister<M extends Model>(...models: (Constructor<M> | {
|
|
67
104
|
name: string;
|
|
68
|
-
constructor: Constructor<
|
|
105
|
+
constructor: Constructor<M>;
|
|
69
106
|
})[]): void;
|
|
70
107
|
/**
|
|
71
108
|
* @summary Abstract class representing a Validatable Model object
|
|
@@ -75,9 +112,10 @@ export declare function bulkModelRegister<T extends Model>(...models: (Construct
|
|
|
75
112
|
* - Have all their required properties marked with '!';
|
|
76
113
|
* - Have all their optional properties marked as '?':
|
|
77
114
|
*
|
|
78
|
-
* @param {Model
|
|
115
|
+
* @param {ModelArg<Model>} model base object from which to populate properties from
|
|
79
116
|
*
|
|
80
117
|
* @class Model
|
|
118
|
+
* @category Model
|
|
81
119
|
* @abstract
|
|
82
120
|
* @implements Validatable
|
|
83
121
|
* @implements Serializable
|
|
@@ -189,16 +227,50 @@ export declare abstract class Model implements Validatable, Serializable, Hashab
|
|
|
189
227
|
* @see ModelRegistry
|
|
190
228
|
*/
|
|
191
229
|
static build<T extends Model>(obj?: Record<string, any>, clazz?: string): T;
|
|
192
|
-
static getMetadata<
|
|
230
|
+
static getMetadata<M extends Model>(model: M): any;
|
|
193
231
|
static getAttributes<V extends Model>(model: Constructor<V> | V): string[];
|
|
194
|
-
static equals<
|
|
195
|
-
static hasErrors<
|
|
196
|
-
static serialize<
|
|
197
|
-
static hash<
|
|
232
|
+
static equals<M extends Model>(obj1: M, obj2: M, ...exceptions: any[]): boolean;
|
|
233
|
+
static hasErrors<M extends Model>(model: M, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
|
|
234
|
+
static serialize<M extends Model>(model: M): any;
|
|
235
|
+
static hash<M extends Model>(model: M): any;
|
|
198
236
|
/**
|
|
199
237
|
* @summary Builds the key to store as Metadata under Reflections
|
|
200
238
|
* @description concatenates {@link ModelKeys#REFLECT} with the provided key
|
|
201
239
|
* @param {string} str
|
|
202
240
|
*/
|
|
203
241
|
static key(str: string): string;
|
|
242
|
+
/**
|
|
243
|
+
* @description Determines if an object is a model instance or has model metadata
|
|
244
|
+
* @summary Checks whether a given object is either an instance of the Model class or
|
|
245
|
+
* has model metadata attached to it. This function is essential for serialization and
|
|
246
|
+
* deserialization processes, as it helps identify model objects that need special handling.
|
|
247
|
+
* It safely handles potential errors during metadata retrieval.
|
|
248
|
+
*
|
|
249
|
+
* @param {Record<string, any>} target - The object to check
|
|
250
|
+
* @return {boolean} True if the object is a model instance or has model metadata, false otherwise
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* // Check if an object is a model
|
|
255
|
+
* const user = new User({ name: "John" });
|
|
256
|
+
* const isUserModel = isModel(user); // true
|
|
257
|
+
*
|
|
258
|
+
* // Check a plain object
|
|
259
|
+
* const plainObject = { name: "John" };
|
|
260
|
+
* const isPlainObjectModel = isModel(plainObject); // false
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
static isModel(target: Record<string, any>): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* @description Checks if a property of a model is itself a model or has a model type
|
|
266
|
+
* @summary Determines whether a specific property of a model instance is either a model instance
|
|
267
|
+
* or has a type that is registered as a model. This function is used for model serialization
|
|
268
|
+
* and deserialization to properly handle nested models.
|
|
269
|
+
* @template M extends {@link Model}
|
|
270
|
+
* @param {M} target - The model instance to check
|
|
271
|
+
* @param {string} attribute - The property name to check
|
|
272
|
+
* @return {boolean | string | undefined} Returns true if the property is a model instance,
|
|
273
|
+
* the model name if the property has a model type, or undefined if not a model
|
|
274
|
+
*/
|
|
275
|
+
static isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
204
276
|
}
|