@decaf-ts/decorator-validation 1.6.5 → 1.7.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.
Files changed (148) hide show
  1. package/dist/decorator-validation.cjs +1199 -386
  2. package/dist/decorator-validation.esm.cjs +1155 -341
  3. package/lib/constants/index.cjs +1 -1
  4. package/lib/esm/index.d.ts +5 -37
  5. package/lib/esm/index.js +6 -38
  6. package/lib/esm/model/Model.d.ts +107 -35
  7. package/lib/esm/model/Model.js +110 -45
  8. package/lib/esm/model/constants.d.ts +3 -3
  9. package/lib/esm/model/constants.js +4 -4
  10. package/lib/esm/model/construction.d.ts +3 -3
  11. package/lib/esm/model/construction.js +4 -4
  12. package/lib/esm/model/decorators.d.ts +3 -3
  13. package/lib/esm/model/decorators.js +2 -3
  14. package/lib/esm/model/index.d.ts +1 -0
  15. package/lib/esm/model/index.js +2 -1
  16. package/lib/esm/model/types.d.ts +30 -11
  17. package/lib/esm/model/types.js +1 -1
  18. package/lib/esm/model/utils.d.ts +3 -0
  19. package/lib/esm/model/utils.js +11 -0
  20. package/lib/esm/model/validation.d.ts +5 -5
  21. package/lib/esm/model/validation.js +8 -9
  22. package/lib/esm/utils/Decoration.d.ts +123 -0
  23. package/lib/esm/utils/Decoration.js +192 -0
  24. package/lib/esm/utils/constants.d.ts +27 -9
  25. package/lib/esm/utils/constants.js +28 -10
  26. package/lib/esm/utils/dates.d.ts +26 -16
  27. package/lib/esm/utils/dates.js +27 -17
  28. package/lib/esm/utils/decorators.d.ts +41 -0
  29. package/lib/esm/utils/decorators.js +42 -1
  30. package/lib/esm/utils/hashing.d.ts +50 -6
  31. package/lib/esm/utils/hashing.js +49 -5
  32. package/lib/esm/utils/index.d.ts +1 -0
  33. package/lib/esm/utils/index.js +2 -1
  34. package/lib/esm/utils/registry.d.ts +3 -3
  35. package/lib/esm/utils/registry.js +1 -1
  36. package/lib/esm/utils/serialization.d.ts +1 -1
  37. package/lib/esm/utils/serialization.js +4 -3
  38. package/lib/esm/utils/strings.d.ts +4 -4
  39. package/lib/esm/utils/strings.js +5 -5
  40. package/lib/esm/utils/types.d.ts +123 -16
  41. package/lib/esm/utils/types.js +1 -1
  42. package/lib/esm/validation/Validators/DateValidator.d.ts +40 -8
  43. package/lib/esm/validation/Validators/DateValidator.js +41 -9
  44. package/lib/esm/validation/Validators/EmailValidator.d.ts +39 -7
  45. package/lib/esm/validation/Validators/EmailValidator.js +40 -8
  46. package/lib/esm/validation/Validators/ListValidator.d.ts +44 -6
  47. package/lib/esm/validation/Validators/ListValidator.js +45 -7
  48. package/lib/esm/validation/Validators/MaxValidator.d.ts +52 -6
  49. package/lib/esm/validation/Validators/MaxValidator.js +53 -7
  50. package/lib/esm/validation/Validators/MinValidator.d.ts +52 -6
  51. package/lib/esm/validation/Validators/MinValidator.js +53 -7
  52. package/lib/esm/validation/Validators/PatternValidator.d.ts +75 -9
  53. package/lib/esm/validation/Validators/PatternValidator.js +76 -10
  54. package/lib/esm/validation/Validators/RequiredValidator.d.ts +52 -6
  55. package/lib/esm/validation/Validators/RequiredValidator.js +53 -7
  56. package/lib/esm/validation/Validators/TypeValidator.d.ts +60 -6
  57. package/lib/esm/validation/Validators/TypeValidator.js +69 -7
  58. package/lib/esm/validation/Validators/URLValidator.d.ts +41 -7
  59. package/lib/esm/validation/Validators/URLValidator.js +42 -8
  60. package/lib/esm/validation/Validators/Validator.d.ts +76 -16
  61. package/lib/esm/validation/Validators/Validator.js +68 -11
  62. package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +1 -7
  63. package/lib/esm/validation/Validators/ValidatorRegistry.js +4 -11
  64. package/lib/esm/validation/decorators.d.ts +50 -40
  65. package/lib/esm/validation/decorators.js +102 -53
  66. package/lib/esm/validation/types.d.ts +146 -28
  67. package/lib/esm/validation/types.js +1 -1
  68. package/lib/index.cjs +7 -39
  69. package/lib/index.d.ts +5 -37
  70. package/lib/model/Model.cjs +114 -51
  71. package/lib/model/Model.d.ts +107 -35
  72. package/lib/model/constants.cjs +4 -4
  73. package/lib/model/constants.d.ts +3 -3
  74. package/lib/model/construction.cjs +4 -4
  75. package/lib/model/construction.d.ts +3 -3
  76. package/lib/model/decorators.cjs +3 -4
  77. package/lib/model/decorators.d.ts +3 -3
  78. package/lib/model/index.cjs +2 -1
  79. package/lib/model/index.d.ts +1 -0
  80. package/lib/model/types.cjs +1 -1
  81. package/lib/model/types.d.ts +30 -11
  82. package/lib/model/utils.cjs +15 -0
  83. package/lib/model/utils.d.ts +3 -0
  84. package/lib/model/validation.cjs +11 -12
  85. package/lib/model/validation.d.ts +5 -5
  86. package/lib/utils/Decoration.cjs +196 -0
  87. package/lib/utils/Decoration.d.ts +123 -0
  88. package/lib/utils/constants.cjs +29 -11
  89. package/lib/utils/constants.d.ts +27 -9
  90. package/lib/utils/dates.cjs +28 -18
  91. package/lib/utils/dates.d.ts +26 -16
  92. package/lib/utils/decorators.cjs +42 -1
  93. package/lib/utils/decorators.d.ts +41 -0
  94. package/lib/utils/hashing.cjs +49 -5
  95. package/lib/utils/hashing.d.ts +50 -6
  96. package/lib/utils/index.cjs +2 -1
  97. package/lib/utils/index.d.ts +1 -0
  98. package/lib/utils/registry.cjs +1 -1
  99. package/lib/utils/registry.d.ts +3 -3
  100. package/lib/utils/serialization.cjs +5 -4
  101. package/lib/utils/serialization.d.ts +1 -1
  102. package/lib/utils/strings.cjs +5 -5
  103. package/lib/utils/strings.d.ts +4 -4
  104. package/lib/utils/types.cjs +1 -1
  105. package/lib/utils/types.d.ts +123 -16
  106. package/lib/validation/Validation.cjs +1 -1
  107. package/lib/validation/Validators/DateValidator.cjs +41 -9
  108. package/lib/validation/Validators/DateValidator.d.ts +40 -8
  109. package/lib/validation/Validators/DiffValidator.cjs +1 -1
  110. package/lib/validation/Validators/EmailValidator.cjs +40 -8
  111. package/lib/validation/Validators/EmailValidator.d.ts +39 -7
  112. package/lib/validation/Validators/EqualsValidator.cjs +1 -1
  113. package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +1 -1
  114. package/lib/validation/Validators/GreaterThanValidator.cjs +1 -1
  115. package/lib/validation/Validators/LessThanOrEqualValidator.cjs +1 -1
  116. package/lib/validation/Validators/LessThanValidator.cjs +1 -1
  117. package/lib/validation/Validators/ListValidator.cjs +45 -7
  118. package/lib/validation/Validators/ListValidator.d.ts +44 -6
  119. package/lib/validation/Validators/MaxLengthValidator.cjs +1 -1
  120. package/lib/validation/Validators/MaxValidator.cjs +53 -7
  121. package/lib/validation/Validators/MaxValidator.d.ts +52 -6
  122. package/lib/validation/Validators/MinLengthValidator.cjs +1 -1
  123. package/lib/validation/Validators/MinValidator.cjs +53 -7
  124. package/lib/validation/Validators/MinValidator.d.ts +52 -6
  125. package/lib/validation/Validators/PasswordValidator.cjs +1 -1
  126. package/lib/validation/Validators/PatternValidator.cjs +76 -10
  127. package/lib/validation/Validators/PatternValidator.d.ts +75 -9
  128. package/lib/validation/Validators/RequiredValidator.cjs +53 -7
  129. package/lib/validation/Validators/RequiredValidator.d.ts +52 -6
  130. package/lib/validation/Validators/StepValidator.cjs +1 -1
  131. package/lib/validation/Validators/TypeValidator.cjs +71 -9
  132. package/lib/validation/Validators/TypeValidator.d.ts +60 -6
  133. package/lib/validation/Validators/URLValidator.cjs +42 -8
  134. package/lib/validation/Validators/URLValidator.d.ts +41 -7
  135. package/lib/validation/Validators/Validator.cjs +69 -12
  136. package/lib/validation/Validators/Validator.d.ts +76 -16
  137. package/lib/validation/Validators/ValidatorRegistry.cjs +4 -12
  138. package/lib/validation/Validators/ValidatorRegistry.d.ts +1 -7
  139. package/lib/validation/Validators/constants.cjs +2 -2
  140. package/lib/validation/Validators/decorators.cjs +2 -2
  141. package/lib/validation/Validators/index.cjs +1 -1
  142. package/lib/validation/Validators/utils.cjs +3 -3
  143. package/lib/validation/decorators.cjs +105 -56
  144. package/lib/validation/decorators.d.ts +50 -40
  145. package/lib/validation/index.cjs +1 -1
  146. package/lib/validation/types.cjs +1 -1
  147. package/lib/validation/types.d.ts +146 -28
  148. package/package.json +2 -1
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uc3RhbnRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSwrQ0FBNkIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG4iXX0=
18
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29uc3RhbnRzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSxtREFBNkIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG4iXX0=
@@ -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.6.5";
11
+ export declare const VERSION = "1.7.0";
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.6.5";
44
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291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BQWEsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQG1vZHVsZSBkZWNvcmF0b3ItdmFsaWRhdGlvblxuICogQGRlc2NyaXB0aW9uIFR5cGVTY3JpcHQgZGVjb3JhdG9yLWJhc2VkIHZhbGlkYXRpb24gbGlicmFyeVxuICogQHN1bW1hcnkgVGhpcyBtb2R1bGUgcHJvdmlkZXMgYSBjb21wcmVoZW5zaXZlIHZhbGlkYXRpb24gZnJhbWV3b3JrIHVzaW5nIFR5cGVTY3JpcHQgZGVjb3JhdG9ycy5cbiAqIEl0IGV4cG9zZXMgdXRpbGl0eSBmdW5jdGlvbnMsIHZhbGlkYXRpb24gZGVjb3JhdG9ycywgYW5kIG1vZGVsLXJlbGF0ZWQgZnVuY3Rpb25hbGl0eSBmb3JcbiAqIGltcGxlbWVudGluZyB0eXBlLXNhZmUsIGRlY2xhcmF0aXZlIHZhbGlkYXRpb24gaW4gVHlwZVNjcmlwdCBhcHBsaWNhdGlvbnMuXG4gKi9cbmV4cG9ydCAqIGZyb20gXCIuL3V0aWxzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9tb2RlbFwiO1xuXG5leHBvcnQgY29uc3QgVkVSU0lPTiA9IFwiIyNWRVJTSU9OIyNcIjtcbiJdfQ==
@@ -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
- * @summary For Serialization/deserialization purposes.
7
- * @description Reads the {@link ModelKeys.ANCHOR} property of a {@link Model} to discover the class to instantiate
8
- *
9
- * @function isModel
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
- * @extends BuilderRegistry<Model>
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
- * @summary Util class to enable serialization and correct rebuilding
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} anchorKey defaults to {@link ModelKeys.ANCHOR}. The property name where the registered class name is stored;
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
- * @implements ModelRegistry
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<T extends Model> implements ModelRegistry<T> {
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
- * @summary register new Models
40
- * @param {any} constructor
41
- * @param {string} [name] when not defined, the name of the constructor will be used
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<T>, name?: string): void;
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<T> | undefined;
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): T;
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
- * @param {Array<Constructor<T>> | Array<{name: string, constructor: Constructor<T>}>} [models]
97
+ * @template M extends Model
98
+ * @param {Array<Constructor<M>> | Array<{name: string, constructor: Constructor<M>}>} [models]
62
99
  *
63
- * @memberOf module:decorator-validation.Model
100
+ * @memberOf module:decorator-validation
64
101
  * @category Model
65
102
  */
66
- export declare function bulkModelRegister<T extends Model>(...models: (Constructor<T> | {
103
+ export declare function bulkModelRegister<M extends Model>(...models: (Constructor<M> | {
67
104
  name: string;
68
- constructor: Constructor<T>;
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 | {}} model base object from which to populate properties from
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<V extends Model>(model: V): any;
230
+ static getMetadata<M extends Model>(model: M): any;
193
231
  static getAttributes<V extends Model>(model: Constructor<V> | V): string[];
194
- static equals<V extends Model>(obj1: V, obj2: V, ...exceptions: any[]): boolean;
195
- static hasErrors<V extends Model>(model: V, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
196
- static serialize<V extends Model>(model: V): any;
197
- static hash<V extends Model>(model: V): any;
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
  }