@decaf-ts/decorator-validation 1.19.0 → 1.21.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/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/constants/index.d.cts +2 -2
- package/lib/types/constants/index.d.mts +2 -2
- package/lib/types/index.d.cts +7 -7
- package/lib/types/index.d.mts +7 -7
- package/lib/types/model/Builder.d.cts +3 -3
- package/lib/types/model/Builder.d.mts +3 -3
- package/lib/types/model/Model.d.cts +4 -4
- package/lib/types/model/Model.d.mts +4 -4
- package/lib/types/model/ModelErrorDefinition.d.cts +1 -1
- package/lib/types/model/ModelErrorDefinition.d.mts +1 -1
- package/lib/types/model/ModelRegistry.d.cts +3 -3
- package/lib/types/model/ModelRegistry.d.mts +3 -3
- package/lib/types/model/construction.d.cts +1 -1
- package/lib/types/model/construction.d.mts +1 -1
- package/lib/types/model/index.d.cts +10 -10
- package/lib/types/model/index.d.mts +10 -10
- package/lib/types/model/types.d.cts +3 -3
- package/lib/types/model/types.d.mts +3 -3
- package/lib/types/model/utils.d.cts +1 -1
- package/lib/types/model/utils.d.mts +1 -1
- package/lib/types/model/validation.d.cts +3 -3
- package/lib/types/model/validation.d.mts +3 -3
- package/lib/types/overrides/Metadata.d.cts +3 -3
- package/lib/types/overrides/Metadata.d.mts +3 -3
- package/lib/types/overrides/index.d.cts +3 -3
- package/lib/types/overrides/index.d.mts +3 -3
- package/lib/types/overrides/types.d.cts +1 -1
- package/lib/types/overrides/types.d.mts +1 -1
- package/lib/types/types/index.d.cts +1 -1
- package/lib/types/types/index.d.mts +1 -1
- package/lib/types/types/validation.d.cts +2 -2
- package/lib/types/types/validation.d.mts +2 -2
- package/lib/types/utils/index.d.cts +11 -11
- package/lib/types/utils/index.d.mts +11 -11
- package/lib/types/utils/serialization.d.cts +1 -1
- package/lib/types/utils/serialization.d.mts +1 -1
- package/lib/types/utils/serializers.d.cts +2 -2
- package/lib/types/utils/serializers.d.mts +2 -2
- package/lib/types/utils/types.d.cts +1 -1
- package/lib/types/utils/types.d.mts +1 -1
- package/lib/types/validation/Validation.d.cts +2 -2
- package/lib/types/validation/Validation.d.mts +2 -2
- package/lib/types/validation/Validators/AsyncValidator.d.cts +3 -3
- package/lib/types/validation/Validators/AsyncValidator.d.mts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.cts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.mts +3 -3
- package/lib/types/validation/Validators/DateValidator.d.cts +2 -2
- package/lib/types/validation/Validators/DateValidator.d.mts +2 -2
- package/lib/types/validation/Validators/DiffValidator.d.cts +3 -3
- package/lib/types/validation/Validators/DiffValidator.d.mts +3 -3
- package/lib/types/validation/Validators/EmailValidator.d.cts +2 -2
- package/lib/types/validation/Validators/EmailValidator.d.mts +2 -2
- package/lib/types/validation/Validators/EqualsValidator.d.cts +3 -3
- package/lib/types/validation/Validators/EqualsValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/ListValidator.d.cts +2 -2
- package/lib/types/validation/Validators/ListValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.mts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.cts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.mts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.cts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.mts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.cts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.mts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.cts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.mts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.cts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.mts +2 -2
- package/lib/types/validation/Validators/Validator.d.cts +3 -3
- package/lib/types/validation/Validators/Validator.d.mts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +3 -3
- package/lib/types/validation/Validators/decorators.d.cts +1 -1
- package/lib/types/validation/Validators/decorators.d.mts +1 -1
- package/lib/types/validation/Validators/index.d.cts +26 -26
- package/lib/types/validation/Validators/index.d.mts +26 -26
- package/lib/types/validation/decorators.d.cts +2 -2
- package/lib/types/validation/decorators.d.mts +2 -2
- package/lib/types/validation/index.d.cts +4 -4
- package/lib/types/validation/index.d.mts +4 -4
- package/lib/types/validation/types.d.cts +2 -2
- package/lib/types/validation/types.d.mts +2 -2
- package/package.json +1 -1
- package/lib/types/constants/errors.d.ts +0 -17
- package/lib/types/constants/index.d.ts +0 -2
- package/lib/types/constants/validation.d.ts +0 -16
- package/lib/types/index.d.ts +0 -20
- package/lib/types/model/Builder.d.ts +0 -86
- package/lib/types/model/Model.d.ts +0 -286
- package/lib/types/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/types/model/ModelRegistry.d.ts +0 -181
- package/lib/types/model/constants.d.ts +0 -65
- package/lib/types/model/construction.d.ts +0 -46
- package/lib/types/model/decorators.d.ts +0 -47
- package/lib/types/model/index.d.ts +0 -10
- package/lib/types/model/types.d.ts +0 -145
- package/lib/types/model/utils.d.ts +0 -13
- package/lib/types/model/validation.d.ts +0 -92
- package/lib/types/overrides/Metadata.d.ts +0 -132
- package/lib/types/overrides/index.d.ts +0 -4
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/overrides/types.d.ts +0 -17
- package/lib/types/types/index.d.ts +0 -1
- package/lib/types/types/validation.d.ts +0 -28
- package/lib/types/utils/DateBuilder.d.ts +0 -121
- package/lib/types/utils/PathProxy.d.ts +0 -43
- package/lib/types/utils/constants.d.ts +0 -32
- package/lib/types/utils/dates.d.ts +0 -86
- package/lib/types/utils/equality.d.ts +0 -56
- package/lib/types/utils/hashing.d.ts +0 -82
- package/lib/types/utils/index.d.ts +0 -11
- package/lib/types/utils/registry.d.ts +0 -68
- package/lib/types/utils/serialization.d.ts +0 -12
- package/lib/types/utils/serializers.d.ts +0 -41
- package/lib/types/utils/strings.d.ts +0 -25
- package/lib/types/utils/types.d.ts +0 -35
- package/lib/types/validation/Validation.d.ts +0 -53
- package/lib/types/validation/Validators/AsyncValidator.d.ts +0 -72
- package/lib/types/validation/Validators/BaseValidator.d.ts +0 -118
- package/lib/types/validation/Validators/DateValidator.d.ts +0 -60
- package/lib/types/validation/Validators/DiffValidator.d.ts +0 -29
- package/lib/types/validation/Validators/EmailValidator.d.ts +0 -60
- package/lib/types/validation/Validators/EqualsValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/ListValidator.d.ts +0 -66
- package/lib/types/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MaxValidator.d.ts +0 -74
- package/lib/types/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MinValidator.d.ts +0 -74
- package/lib/types/validation/Validators/OptionValidator.d.ts +0 -29
- package/lib/types/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/types/validation/Validators/PatternValidator.d.ts +0 -103
- package/lib/types/validation/Validators/RequiredValidator.d.ts +0 -74
- package/lib/types/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/types/validation/Validators/TypeValidator.d.ts +0 -79
- package/lib/types/validation/Validators/URLValidator.d.ts +0 -61
- package/lib/types/validation/Validators/Validator.d.ts +0 -65
- package/lib/types/validation/Validators/ValidatorRegistry.d.ts +0 -41
- package/lib/types/validation/Validators/constants.d.ts +0 -157
- package/lib/types/validation/Validators/decorators.d.ts +0 -12
- package/lib/types/validation/Validators/index.d.ts +0 -26
- package/lib/types/validation/Validators/utils.d.ts +0 -75
- package/lib/types/validation/decorators.d.ts +0 -313
- package/lib/types/validation/index.d.ts +0 -9
- package/lib/types/validation/types.d.ts +0 -309
|
@@ -1,65 +0,0 @@
|
|
|
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[];
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Model } from "./Model";
|
|
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;
|
|
@@ -1,47 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./constants";
|
|
2
|
-
export * from "./construction";
|
|
3
|
-
export * from "./decorators";
|
|
4
|
-
export * from "./ModelRegistry";
|
|
5
|
-
export * from "./Model";
|
|
6
|
-
export * from "./ModelErrorDefinition";
|
|
7
|
-
export * from "./Builder";
|
|
8
|
-
export * from "./types";
|
|
9
|
-
export * from "./validation";
|
|
10
|
-
export * from "./utils";
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import type { ConditionalAsync } from "../types";
|
|
2
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
3
|
-
import { Model } from "./Model";
|
|
4
|
-
/**
|
|
5
|
-
* @description Function type for building model instances from objects
|
|
6
|
-
* @summary Type definition for a model builder function that populates model properties
|
|
7
|
-
* @template T
|
|
8
|
-
* @param {T} self - The target model instance to populate
|
|
9
|
-
* @param {T | Record<string, any>} [obj] - The source object containing properties to copy
|
|
10
|
-
* @return {T} - The populated model instance
|
|
11
|
-
* @typedef ModelBuilderFunction
|
|
12
|
-
* @memberOf module:decorator-validation
|
|
13
|
-
*/
|
|
14
|
-
export type ModelBuilderFunction = <T extends Model>(self: T, obj?: T | Record<string, any>) => T;
|
|
15
|
-
/**
|
|
16
|
-
* @description Type representing valid argument types for model constructors
|
|
17
|
-
* @summary Definition of a Model Constructor Argument that can be a complete model, partial model, or plain object
|
|
18
|
-
* @template T
|
|
19
|
-
* @typedef ModelArg
|
|
20
|
-
* @memberOf module:decorator-validation
|
|
21
|
-
* @see ModelConstructor
|
|
22
|
-
*/
|
|
23
|
-
export type ModelArg<T> = T | Partial<T> | Record<string, any>;
|
|
24
|
-
/**
|
|
25
|
-
* @description Specialized constructor type for Model classes
|
|
26
|
-
* @summary Definition of a Model Constructor that creates instances of Model subclasses
|
|
27
|
-
* @template T
|
|
28
|
-
* @param {ModelArg<T>} [model] - Initial data to populate the model with
|
|
29
|
-
* @param {any[]} [args] - Additional constructor arguments
|
|
30
|
-
* @return {T} - An instance of the model class
|
|
31
|
-
* @typedef ModelConstructor
|
|
32
|
-
* @memberOf module:decorator-validation
|
|
33
|
-
*/
|
|
34
|
-
export type ModelConstructor<T extends Model> = {
|
|
35
|
-
new (model?: ModelArg<T>, ...args: any[]): T;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* @description Interface for objects that can be validated.
|
|
39
|
-
* @summary Defines the Validation API for validation behavior on models, supporting both synchronous and asynchronous validations.
|
|
40
|
-
* Implementers must provide a `hasErrors` method that performs the validation and returns either validation errors or undefined if validation passes.
|
|
41
|
-
*
|
|
42
|
-
* @template Async - A boolean flag indicating whether the validation is asynchronous (`true`) or synchronous (`false`).
|
|
43
|
-
*
|
|
44
|
-
* @param {any[]} [args] - Optional arguments to control validation behavior passed to the validation method.
|
|
45
|
-
*
|
|
46
|
-
* @interface Validatable
|
|
47
|
-
* @category Model
|
|
48
|
-
* @memberOf module:decorator-validation
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* // Synchronous validation example
|
|
53
|
-
* class SyncModel implements Validatable<false> {
|
|
54
|
-
* hasErrors(...args: any[]): ModelErrorDefinition | undefined {
|
|
55
|
-
* // perform synchronous validation logic
|
|
56
|
-
* return undefined; // or return errors if invalid
|
|
57
|
-
* }
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* // Asynchronous validation example
|
|
61
|
-
* class AsyncModel implements Validatable<true> {
|
|
62
|
-
* async hasErrors(...args: any[]): Promise<ModelErrorDefinition | undefined> {
|
|
63
|
-
* // perform asynchronous validation logic
|
|
64
|
-
* return undefined; // or return errors if invalid
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export interface Validatable<Async extends boolean = false> {
|
|
70
|
-
/**
|
|
71
|
-
* @description Validates the object against its validation rules.
|
|
72
|
-
* @summary Validates the model and returns the {@link ModelErrorDefinition} if any errors exist, or `undefined` if no errors.
|
|
73
|
-
*
|
|
74
|
-
* @param {any[]} [args] - Optional arguments that may influence validation logic.
|
|
75
|
-
* @return {ConditionalAsync<Async, ModelErrorDefinition | undefined>} Validation errors or undefined, conditionally wrapped in a Promise if asynchronous.
|
|
76
|
-
*
|
|
77
|
-
* @method
|
|
78
|
-
*/
|
|
79
|
-
hasErrors(...args: any[]): ConditionalAsync<Async, ModelErrorDefinition | undefined>;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @description Interface for objects that can be serialized to string
|
|
83
|
-
* @summary Defines the serialization API for model objects
|
|
84
|
-
* @interface Serializable
|
|
85
|
-
* @memberOf module:decorator-validation
|
|
86
|
-
* @category Model
|
|
87
|
-
*/
|
|
88
|
-
export interface Serializable {
|
|
89
|
-
/**
|
|
90
|
-
* @description Converts the object to a serialized string representation
|
|
91
|
-
* @summary Serializes the model to a string format
|
|
92
|
-
* @return {string} - The serialized string representation
|
|
93
|
-
* @method
|
|
94
|
-
*/
|
|
95
|
-
serialize(...args: any[]): string;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @description Interface for objects that can generate a hash representation
|
|
99
|
-
* @summary Defines the hashing API for model objects
|
|
100
|
-
* @interface Hashable
|
|
101
|
-
* @memberOf module:decorator-validation
|
|
102
|
-
* @category Model
|
|
103
|
-
*/
|
|
104
|
-
export interface Hashable {
|
|
105
|
-
/**
|
|
106
|
-
* @description Generates a unique hash string for the object
|
|
107
|
-
* @summary Creates a hash string representation of the object
|
|
108
|
-
* @return {string} - Hash value representing the object
|
|
109
|
-
* @method
|
|
110
|
-
*/
|
|
111
|
-
hash(...args: any[]): string;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* @description Interface for objects that can be compared with other objects
|
|
115
|
-
* @summary Defines the equality comparison API for model objects
|
|
116
|
-
* @template T
|
|
117
|
-
* @interface Comparable
|
|
118
|
-
* @memberOf module:decorator-validation
|
|
119
|
-
* @category Model
|
|
120
|
-
*/
|
|
121
|
-
export interface Comparable {
|
|
122
|
-
/**
|
|
123
|
-
* @description Determines if this object is equal to another object
|
|
124
|
-
* @summary Compares this object with another for equality
|
|
125
|
-
* @param {T} other - The object to compare with
|
|
126
|
-
* @param {any[]} [args] - Additional arguments for comparison
|
|
127
|
-
* @return {boolean} - True if the objects are equal, false otherwise
|
|
128
|
-
* @method
|
|
129
|
-
*/
|
|
130
|
-
equals<T extends Model>(this: T, other: T, ...args: any[]): boolean;
|
|
131
|
-
compare<T extends Model>(this: T, other: T, ...args: any[]): Comparison<T> | undefined;
|
|
132
|
-
}
|
|
133
|
-
export type SetterKeyFor<OBJ, K extends keyof OBJ> = `set${Capitalize<string & K>}`;
|
|
134
|
-
export type SetterFor<OBJ, K extends keyof OBJ, R> = (value: OBJ[K]) => R;
|
|
135
|
-
export type Builder<OUT, ARGS extends any[] = any[], IN = OUT> = {
|
|
136
|
-
[K in keyof OUT as K extends keyof Model | "build" ? never : K]: OUT[K];
|
|
137
|
-
} & {
|
|
138
|
-
[K in keyof OUT as K extends keyof Model | "build" ? never : SetterKeyFor<OUT, K>]: SetterFor<OUT, K, IN>;
|
|
139
|
-
} & {
|
|
140
|
-
build: (...args: ARGS) => OUT | Promise<OUT>;
|
|
141
|
-
};
|
|
142
|
-
export type Comparison<M, K extends keyof M = keyof M> = Record<K, {
|
|
143
|
-
other: M[K] | undefined;
|
|
144
|
-
current: M[K] | undefined;
|
|
145
|
-
}>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ConditionalAsync } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* Wraps a value in a Promise if the `async` flag is true.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The type of the value being wrapped.
|
|
6
|
-
* @template Async - A boolean type that determines if the result should be wrapped in a Promise.
|
|
7
|
-
*
|
|
8
|
-
* @param value - The value to return directly or wrap in a Promise.
|
|
9
|
-
* @param async - If true, the value is wrapped in a resolved Promise. If false or undefined, the value is returned as-is.
|
|
10
|
-
*
|
|
11
|
-
* @returns The original value or a Promise resolving to it, depending on the `async` flag.
|
|
12
|
-
*/
|
|
13
|
-
export declare function toConditionalPromise<T, Async extends boolean>(value: T, async?: Async): ConditionalAsync<Async, T>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ModelErrorDefinition } from "./ModelErrorDefinition";
|
|
2
|
-
import type { Model } from "./Model";
|
|
3
|
-
import { ConditionalAsync } from "../types";
|
|
4
|
-
export declare function validateChildValue<M extends Model>(prop: string, childValue: any, parentModel: M, allowedTypes: string[], async: boolean, ...propsToIgnore: string[]): string | undefined | ModelErrorDefinition | Promise<string | undefined | ModelErrorDefinition>;
|
|
5
|
-
/**
|
|
6
|
-
* @description Retrieves nested properties to ignore for child validation
|
|
7
|
-
* @param parentProp - The property of the parent model
|
|
8
|
-
* @param propsToIgnore - Properties to ignore from the parent model
|
|
9
|
-
* @returns An array of properties to ignore for the child model
|
|
10
|
-
*/
|
|
11
|
-
export declare function getChildNestedPropsToIgnore(parentProp: string, ...propsToIgnore: string[]): string[];
|
|
12
|
-
export declare function validateDecorator<M extends Model, Async extends boolean = false>(model: M, value: any, decorator: any, async?: Async): ConditionalAsync<Async, string | undefined>;
|
|
13
|
-
/**
|
|
14
|
-
* @description
|
|
15
|
-
* Executes validation logic for a set of decorators applied to a model's property, handling both
|
|
16
|
-
* synchronous and asynchronous validations, including support for nested validations and lists.
|
|
17
|
-
*
|
|
18
|
-
* @summary
|
|
19
|
-
* Iterates over an array of decorator metadata objects and applies each validation rule to the
|
|
20
|
-
* provided value. For list decorators (`ValidationKeys.LIST`), it performs element-wise validation,
|
|
21
|
-
* supporting nested model validation and type checks. If the `async` flag is set, asynchronous
|
|
22
|
-
* validation is supported using `Promise.all`. The result is a record mapping validation keys to
|
|
23
|
-
* error messages, or `undefined` if no errors are found.
|
|
24
|
-
*
|
|
25
|
-
* @template M - A type parameter extending `Model`, representing the model type being validated.
|
|
26
|
-
* @template Async - A boolean indicating whether validation should be performed asynchronously.
|
|
27
|
-
*
|
|
28
|
-
* @param {M} model - The model instance that the validation is associated with.
|
|
29
|
-
* @param {string} prop - The model field name
|
|
30
|
-
* @param {any} value - The value to be validated against the provided decorators.
|
|
31
|
-
* @param {DecoratorMetadataAsync} decorators - An object of metadata representing validation decorators.
|
|
32
|
-
* @param {Async} [async] - Optional flag indicating whether validation should be performed asynchronously.
|
|
33
|
-
*
|
|
34
|
-
* @return {ConditionalAsync<Async, Record<string, string>> | undefined}
|
|
35
|
-
* Returns either a record of validation errors (keyed by the decorator key) or `undefined` if no errors are found.
|
|
36
|
-
* If `async` is true, the return value is a Promise resolving to the same structure.
|
|
37
|
-
*
|
|
38
|
-
* @function validateDecorators
|
|
39
|
-
*/
|
|
40
|
-
export declare function validateDecorators<M extends Model, Async extends boolean = false>(model: M, prop: string, value: any, decorators: any, async?: Async, ...propsToIgnore: string[]): ConditionalAsync<Async, Record<string, string> | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* @function validate
|
|
43
|
-
* @template M
|
|
44
|
-
* @template Async
|
|
45
|
-
* @memberOf module:decorator-validation
|
|
46
|
-
* @category Model
|
|
47
|
-
*
|
|
48
|
-
* @description
|
|
49
|
-
* Validates the properties of a {@link Model} instance using registered decorators.
|
|
50
|
-
* Supports both synchronous and asynchronous validation flows, depending on the `async` flag.
|
|
51
|
-
*
|
|
52
|
-
* @summary
|
|
53
|
-
* This function inspects a given model object, identifies decorated properties that require validation,
|
|
54
|
-
* and applies the corresponding validation rules. It also supports nested model validation and gracefully
|
|
55
|
-
* merges any validation errors. For collections (Array/Set), it enforces the presence of the `@list` decorator
|
|
56
|
-
* and checks the type of elements. If a property is a nested model, it will call `hasErrors` on it and flatten
|
|
57
|
-
* the nested error keys using dot notation.
|
|
58
|
-
*
|
|
59
|
-
* @param {M} model - The model instance to be validated. Must extend from {@link Model}.
|
|
60
|
-
* @param {Async} [async] - A flag indicating whether validation should be asynchronous.
|
|
61
|
-
* @param {...string} propsToIgnore - A variadic list of property names that should be skipped during validation.
|
|
62
|
-
*
|
|
63
|
-
* @returns {ConditionalAsync<Async, ModelErrorDefinition | undefined>}
|
|
64
|
-
* Returns either a {@link ModelErrorDefinition} containing validation errors,
|
|
65
|
-
* or `undefined` if no errors are found. When `async` is `true`, returns a Promise.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link Model}
|
|
68
|
-
* @see {@link ModelErrorDefinition}
|
|
69
|
-
* @see {@link validateDecorators}
|
|
70
|
-
* @see {@link getValidatableProperties}
|
|
71
|
-
*
|
|
72
|
-
* @mermaid
|
|
73
|
-
* sequenceDiagram
|
|
74
|
-
* participant Caller
|
|
75
|
-
* participant validate
|
|
76
|
-
* participant getValidatableProperties
|
|
77
|
-
* participant validateDecorators
|
|
78
|
-
* participant ModelInstance
|
|
79
|
-
* Caller->>validate: call with obj, async, propsToIgnore
|
|
80
|
-
* validate->>getValidatableProperties: retrieve decorated props
|
|
81
|
-
* loop for each property
|
|
82
|
-
* validate->>validateDecorators: validate using decorators
|
|
83
|
-
* alt is nested model
|
|
84
|
-
* validate->>ModelInstance: call hasErrors()
|
|
85
|
-
* end
|
|
86
|
-
* end
|
|
87
|
-
* alt async
|
|
88
|
-
* validate->>validate: Promise.allSettled for errors
|
|
89
|
-
* end
|
|
90
|
-
* validate-->>Caller: return ModelErrorDefinition | undefined
|
|
91
|
-
*/
|
|
92
|
-
export declare function validate<M extends Model<boolean>, Async extends boolean = false>(model: M, async: Async, ...propsToIgnore: string[]): ConditionalAsync<Async, ModelErrorDefinition | undefined>;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Model } from "../model/Model";
|
|
2
|
-
import "@decaf-ts/decoration";
|
|
3
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
-
import { designTypeReturn, ExtendedMetadata } from "./types";
|
|
5
|
-
import { ValidationMetadata } from "../validation/types";
|
|
6
|
-
declare module "@decaf-ts/decoration" {
|
|
7
|
-
namespace Metadata {
|
|
8
|
-
/**
|
|
9
|
-
* @description Retrieves validation metadata for a specific property of a model
|
|
10
|
-
* @summary Fetches validation rules and constraints that were applied to a property
|
|
11
|
-
* via decorators. The optional key parameter allows drilling down to specific
|
|
12
|
-
* validation types (e.g., 'required', 'min', 'max').
|
|
13
|
-
*
|
|
14
|
-
* @template M - The model type extending from Model
|
|
15
|
-
* @param {Constructor<M>} model - The constructor of the target model class
|
|
16
|
-
* @param {keyof M} property - The property name to retrieve validation for
|
|
17
|
-
* @param {string} [key] - Optional specific validation key to retrieve (e.g., 'required', 'pattern')
|
|
18
|
-
* @return {any} The validation metadata object or value at the specified key
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* class User extends Model {
|
|
22
|
-
* @required()
|
|
23
|
-
* @maxLength(100)
|
|
24
|
-
* name!: string;
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* // Get all validation metadata for 'name'
|
|
28
|
-
* const validations = Metadata.validationFor(User, 'name');
|
|
29
|
-
*
|
|
30
|
-
* // Get specific validation metadata
|
|
31
|
-
* const required = Metadata.validationFor(User, 'name', 'required');
|
|
32
|
-
*/
|
|
33
|
-
function validationFor<M extends Model, P extends keyof M = keyof M, K extends string = string>(this: Metadata, model: Constructor<M>, property?: keyof M, key?: string): (K extends string ? ValidationMetadata : P extends keyof M ? Record<string, ValidationMetadata> : Record<keyof M, Record<string, ValidationMetadata>>) | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* @description Retrieves all validatable for a model
|
|
36
|
-
* @param model
|
|
37
|
-
*/
|
|
38
|
-
function validatableProperties<M extends Model>(model: Constructor<M>, ...propsToIgnore: string[]): string[];
|
|
39
|
-
/**
|
|
40
|
-
* @description Retrieves extended metadata for a model or a specific key within it
|
|
41
|
-
* @summary When called with a constructor only, returns the entire metadata object
|
|
42
|
-
* associated with the model, including validation rules, property types, relationships,
|
|
43
|
-
* and other decorator-applied metadata. This override extends the base Metadata.get
|
|
44
|
-
* method with type-safe support for ExtendedMetadata.
|
|
45
|
-
*
|
|
46
|
-
* @template M - The model type
|
|
47
|
-
* @template META - The extended metadata type, defaults to ExtendedMetadata<M>
|
|
48
|
-
* @param {Constructor<M>} model - The target constructor used to locate the metadata record
|
|
49
|
-
* @param {keyof M} prop - Optional property of the model.
|
|
50
|
-
* @return {META|undefined} The complete metadata object for the model, or undefined if no metadata exists
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* class Article extends Model {
|
|
54
|
-
* @pk()
|
|
55
|
-
* @type(Number)
|
|
56
|
-
* id!: number;
|
|
57
|
-
*
|
|
58
|
-
* @required()
|
|
59
|
-
* @maxLength(200)
|
|
60
|
-
* title!: string;
|
|
61
|
-
*
|
|
62
|
-
* @oneToMany(() => Comment, { update: true, delete: true }, true)
|
|
63
|
-
* comments!: Comment[];
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
* // Get all metadata for the Article model
|
|
67
|
-
* const metadata = Metadata.get<Article>(Article);
|
|
68
|
-
* // metadata contains:
|
|
69
|
-
* // - property definitions
|
|
70
|
-
* // - validation rules
|
|
71
|
-
* // - relationship mappings
|
|
72
|
-
* // - primary key information
|
|
73
|
-
* // - column mappings
|
|
74
|
-
*
|
|
75
|
-
* @remarks
|
|
76
|
-
* The @ts-expect-error directive is used because this declaration intentionally
|
|
77
|
-
* overrides the signature from the base module to provide enhanced type information
|
|
78
|
-
* specific to the decorator-validation system.
|
|
79
|
-
*/
|
|
80
|
-
function get<M, META extends ExtendedMetadata<M> = ExtendedMetadata<M>>(model: Constructor<M>, prop?: keyof M): META | undefined;
|
|
81
|
-
/**
|
|
82
|
-
* @description Retrieves the original constructor name for a model
|
|
83
|
-
* @summary Fetches the original constructor name for a model from the metadata of a model.
|
|
84
|
-
*
|
|
85
|
-
* @template M - The model type extending from Model
|
|
86
|
-
* @param {Constructor<M>} model - The constructor of the target model class
|
|
87
|
-
* @return {string} The metadata object or value
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* class User extends Model {
|
|
91
|
-
*
|
|
92
|
-
* // Get the constructor name for 'User'
|
|
93
|
-
* const constName = Metadata.modelName(User);
|
|
94
|
-
*/
|
|
95
|
-
function modelName<M>(model: Constructor<M>): string;
|
|
96
|
-
/**
|
|
97
|
-
* @description Retrieves all allowed types for a model or a property
|
|
98
|
-
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
99
|
-
*
|
|
100
|
-
* @template M - The model type extending from Model
|
|
101
|
-
* @param {Constructor<M>} model - The constructor of the target model class
|
|
102
|
-
* @param {keyof M} property - The property name to retrieve validation for
|
|
103
|
-
* @return {any[]} An array of the allowed types
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* class User extends Model {
|
|
107
|
-
*
|
|
108
|
-
* // Get all validation metadata for 'User'
|
|
109
|
-
* const allowedTypes = Metadata.meallowedTypestadata(User);
|
|
110
|
-
*/
|
|
111
|
-
function allowedTypes<M>(model: Constructor<M>, property?: keyof M): any[];
|
|
112
|
-
/**
|
|
113
|
-
* @description Retrieves all allowed types for a model or a property
|
|
114
|
-
* @summary Retrieves all allowed types for a model or a property from it's metadata.
|
|
115
|
-
*
|
|
116
|
-
* @template model - The model type extending from Model
|
|
117
|
-
* @param {Constructor<M>} model - The constructor of the target model class
|
|
118
|
-
* @param {keyof M} property - The property name to retrieve validation for
|
|
119
|
-
* @return {designTypeReturn} An object of the designtypes
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* class User extends Model {
|
|
123
|
-
*
|
|
124
|
-
* // Get the designtypes for property name
|
|
125
|
-
* const { designTypes, designType } = Metadata.getPropDesignTypes(User.constructor, 'name');
|
|
126
|
-
*/
|
|
127
|
-
function getPropDesignTypes<M>(model: Constructor<M>, property: keyof M): designTypeReturn;
|
|
128
|
-
function isModel(target: Record<string, any>): boolean;
|
|
129
|
-
function isPropertyModel<M extends Model>(target: M, attribute: string): boolean | string | undefined;
|
|
130
|
-
function getAttributes<V extends Model>(model: Constructor<V> | V): string[];
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./Metadata";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BasicMetadata } from "@decaf-ts/decoration";
|
|
2
|
-
import { ValidatorOptions } from "../validation/types";
|
|
3
|
-
export type ExtendedMetadata<M> = BasicMetadata<M> & {
|
|
4
|
-
validation: Record<keyof M, ValidatorOptions>;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* @description Return type for design type information.
|
|
8
|
-
* @summary Defines the structure of the return type for functions that provide design type information.
|
|
9
|
-
* @property {any[]} designTypes An array of design types.
|
|
10
|
-
* @property {any} designType The primary design type.
|
|
11
|
-
* @typedef {object} designTypeReturn
|
|
12
|
-
* @memberOf module:decorator-validation
|
|
13
|
-
*/
|
|
14
|
-
export type designTypeReturn = {
|
|
15
|
-
designTypes: any[];
|
|
16
|
-
designType: any;
|
|
17
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./validation";
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Model } from "../model/Model";
|
|
2
|
-
import { ModelErrorDefinition } from "../model/ModelErrorDefinition";
|
|
3
|
-
/**
|
|
4
|
-
* @description Conditionally wraps a type in a `Promise` based on the `Async` flag.
|
|
5
|
-
* @summary Utility type that resolves to `T` if `Async` is `false`, or to `Promise<T>` if `Async` is `true`.
|
|
6
|
-
* Used to abstract the return type of functions that may be either synchronous or asynchronous depending on a flag.
|
|
7
|
-
*
|
|
8
|
-
* @template Async A boolean flag indicating whether the result should be asynchronous (`true`) or synchronous (`false`).
|
|
9
|
-
* @template T The base type to return directly or to wrap in a `Promise`.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Synchronous result
|
|
14
|
-
* type SyncResult: string | number = ConditionalAsync<false, string | number>;
|
|
15
|
-
*
|
|
16
|
-
* // Asynchronous result
|
|
17
|
-
* type AsyncResult: Promise<string | number> = ConditionalAsync<true, string | number>;
|
|
18
|
-
* ```
|
|
19
|
-
* @memberOf module:decorator-validation
|
|
20
|
-
*/
|
|
21
|
-
export type ConditionalAsync<Async extends boolean, T> = Async extends true ? Promise<T> : T;
|
|
22
|
-
export type DecoratorMetadataAsync = {
|
|
23
|
-
async?: boolean;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated
|
|
27
|
-
*/
|
|
28
|
-
export type ModelConditionalAsync<M> = M extends Model<true> ? Promise<ModelErrorDefinition | undefined> : ModelErrorDefinition | undefined;
|