@decaf-ts/decorator-validation 1.10.5 → 1.11.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/README.md +1 -1
- package/dist/decorator-validation.cjs +1 -1
- package/dist/decorator-validation.cjs.map +1 -1
- package/dist/decorator-validation.js +1 -1
- package/dist/decorator-validation.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/model/Builder.d.ts +84 -0
- package/lib/esm/model/Builder.js +395 -129
- package/lib/esm/model/Builder.js.map +1 -1
- package/lib/esm/model/Model.d.ts +21 -19
- package/lib/esm/model/Model.js +112 -105
- package/lib/esm/model/Model.js.map +1 -1
- package/lib/esm/model/constants.d.ts +8 -8
- package/lib/esm/model/constants.js +8 -9
- package/lib/esm/model/constants.js.map +1 -1
- package/lib/esm/model/decorators.d.ts +2 -12
- package/lib/esm/model/decorators.js +5 -39
- package/lib/esm/model/decorators.js.map +1 -1
- package/lib/esm/model/index.d.ts +1 -0
- package/lib/esm/model/index.js +1 -0
- package/lib/esm/model/index.js.map +1 -1
- package/lib/esm/model/types.d.ts +0 -12
- package/lib/esm/model/utils.d.ts +0 -3
- package/lib/esm/model/utils.js +0 -10
- package/lib/esm/model/utils.js.map +1 -1
- package/lib/esm/model/validation.d.ts +4 -37
- package/lib/esm/model/validation.js +30 -106
- package/lib/esm/model/validation.js.map +1 -1
- package/lib/esm/overrides/Metadata.d.ts +128 -0
- package/lib/esm/overrides/Metadata.js +2 -0
- package/lib/esm/overrides/Metadata.js.map +1 -0
- package/lib/esm/overrides/index.d.ts +3 -0
- package/lib/esm/overrides/index.js +4 -0
- package/lib/esm/overrides/index.js.map +1 -0
- package/lib/esm/overrides/overrides.d.ts +1 -0
- package/lib/esm/overrides/overrides.js +79 -0
- package/lib/esm/overrides/overrides.js.map +1 -0
- package/lib/esm/overrides/types.d.ts +9 -0
- package/lib/esm/overrides/types.js +2 -0
- package/lib/esm/overrides/types.js.map +1 -0
- package/lib/esm/types/validation.d.ts +4 -2
- package/lib/esm/utils/constants.d.ts +4 -18
- package/lib/esm/utils/constants.js +4 -17
- package/lib/esm/utils/constants.js.map +1 -1
- package/lib/esm/utils/dates.d.ts +0 -1
- package/lib/esm/utils/dates.js +0 -1
- package/lib/esm/utils/dates.js.map +1 -1
- package/lib/esm/utils/equality.d.ts +56 -0
- package/lib/esm/utils/equality.js +160 -0
- package/lib/esm/utils/equality.js.map +1 -0
- package/lib/esm/utils/index.d.ts +1 -2
- package/lib/esm/utils/index.js +1 -2
- package/lib/esm/utils/index.js.map +1 -1
- package/lib/esm/utils/registry.d.ts +1 -1
- package/lib/esm/utils/serialization.d.ts +2 -2
- package/lib/esm/utils/serialization.js +10 -2
- package/lib/esm/utils/serialization.js.map +1 -1
- package/lib/esm/utils/types.d.ts +0 -102
- package/lib/esm/validation/Validation.d.ts +2 -3
- package/lib/esm/validation/Validation.js +11 -6
- package/lib/esm/validation/Validation.js.map +1 -1
- package/lib/esm/validation/Validators/BaseValidator.js +7 -3
- package/lib/esm/validation/Validators/BaseValidator.js.map +1 -1
- package/lib/esm/validation/Validators/DiffValidator.js +1 -1
- package/lib/esm/validation/Validators/DiffValidator.js.map +1 -1
- package/lib/esm/validation/Validators/EqualsValidator.js +1 -1
- package/lib/esm/validation/Validators/EqualsValidator.js.map +1 -1
- package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js +1 -1
- package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
- package/lib/esm/validation/Validators/LessThanOrEqualValidator.js +1 -1
- package/lib/esm/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
- package/lib/esm/validation/Validators/ListValidator.js +4 -4
- package/lib/esm/validation/Validators/ListValidator.js.map +1 -1
- package/lib/esm/validation/Validators/MaxLengthValidator.js +3 -2
- package/lib/esm/validation/Validators/MaxLengthValidator.js.map +1 -1
- package/lib/esm/validation/Validators/MaxValidator.js +1 -1
- package/lib/esm/validation/Validators/MaxValidator.js.map +1 -1
- package/lib/esm/validation/Validators/MinLengthValidator.js +3 -2
- package/lib/esm/validation/Validators/MinLengthValidator.js.map +1 -1
- package/lib/esm/validation/Validators/MinValidator.js +1 -1
- package/lib/esm/validation/Validators/MinValidator.js.map +1 -1
- package/lib/esm/validation/Validators/OptionValidator.d.ts +29 -0
- package/lib/esm/validation/Validators/OptionValidator.js +61 -0
- package/lib/esm/validation/Validators/OptionValidator.js.map +1 -0
- package/lib/esm/validation/Validators/TypeValidator.js +2 -2
- package/lib/esm/validation/Validators/TypeValidator.js.map +1 -1
- package/lib/esm/validation/Validators/constants.d.ts +2 -1
- package/lib/esm/validation/Validators/constants.js +3 -2
- package/lib/esm/validation/Validators/constants.js.map +1 -1
- package/lib/esm/validation/Validators/decorators.d.ts +1 -1
- package/lib/esm/validation/Validators/decorators.js +2 -2
- package/lib/esm/validation/Validators/decorators.js.map +1 -1
- package/lib/esm/validation/Validators/index.d.ts +1 -0
- package/lib/esm/validation/Validators/index.js +1 -0
- package/lib/esm/validation/Validators/index.js.map +1 -1
- package/lib/esm/validation/Validators/utils.d.ts +33 -0
- package/lib/esm/validation/Validators/utils.js +62 -0
- package/lib/esm/validation/Validators/utils.js.map +1 -1
- package/lib/esm/validation/decorators.d.ts +28 -17
- package/lib/esm/validation/decorators.js +86 -55
- package/lib/esm/validation/decorators.js.map +1 -1
- package/lib/esm/validation/types.d.ts +15 -5
- package/lib/esm/validation/types.js.map +1 -1
- package/lib/index.cjs +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js.map +1 -1
- package/lib/model/Builder.cjs +399 -128
- package/lib/model/Builder.d.ts +84 -0
- package/lib/model/Builder.js.map +1 -1
- package/lib/model/Model.cjs +114 -107
- package/lib/model/Model.d.ts +21 -19
- package/lib/model/Model.js.map +1 -1
- package/lib/model/constants.cjs +8 -9
- package/lib/model/constants.d.ts +8 -8
- package/lib/model/constants.js.map +1 -1
- package/lib/model/decorators.cjs +4 -39
- package/lib/model/decorators.d.ts +2 -12
- package/lib/model/decorators.js.map +1 -1
- package/lib/model/index.cjs +1 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js.map +1 -1
- package/lib/model/types.d.ts +0 -12
- package/lib/model/utils.cjs +0 -12
- package/lib/model/utils.d.ts +0 -3
- package/lib/model/utils.js.map +1 -1
- package/lib/model/validation.cjs +30 -108
- package/lib/model/validation.d.ts +4 -37
- package/lib/model/validation.js.map +1 -1
- package/lib/overrides/Metadata.cjs +3 -0
- package/lib/overrides/Metadata.d.ts +128 -0
- package/lib/overrides/Metadata.js.map +1 -0
- package/lib/overrides/index.cjs +20 -0
- package/lib/overrides/index.d.ts +3 -0
- package/lib/overrides/index.js.map +1 -0
- package/lib/overrides/overrides.cjs +81 -0
- package/lib/overrides/overrides.d.ts +1 -0
- package/lib/overrides/overrides.js.map +1 -0
- package/lib/overrides/types.cjs +3 -0
- package/lib/overrides/types.d.ts +9 -0
- package/lib/overrides/types.js.map +1 -0
- package/lib/types/validation.d.ts +4 -2
- package/lib/utils/constants.cjs +5 -18
- package/lib/utils/constants.d.ts +4 -18
- package/lib/utils/constants.js.map +1 -1
- package/lib/utils/dates.cjs +0 -1
- package/lib/utils/dates.d.ts +0 -1
- package/lib/utils/dates.js.map +1 -1
- package/lib/utils/equality.cjs +163 -0
- package/lib/utils/equality.d.ts +56 -0
- package/lib/utils/equality.js.map +1 -0
- package/lib/utils/index.cjs +1 -2
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/registry.d.ts +1 -1
- package/lib/utils/serialization.cjs +10 -2
- package/lib/utils/serialization.d.ts +2 -2
- package/lib/utils/serialization.js.map +1 -1
- package/lib/utils/types.d.ts +0 -102
- package/lib/validation/Validation.cjs +11 -6
- package/lib/validation/Validation.d.ts +2 -3
- package/lib/validation/Validation.js.map +1 -1
- package/lib/validation/Validators/BaseValidator.cjs +7 -3
- package/lib/validation/Validators/BaseValidator.js.map +1 -1
- package/lib/validation/Validators/DiffValidator.cjs +2 -2
- package/lib/validation/Validators/DiffValidator.js.map +1 -1
- package/lib/validation/Validators/EqualsValidator.cjs +2 -2
- package/lib/validation/Validators/EqualsValidator.js.map +1 -1
- package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +2 -2
- package/lib/validation/Validators/GreaterThanOrEqualValidator.js.map +1 -1
- package/lib/validation/Validators/LessThanOrEqualValidator.cjs +2 -2
- package/lib/validation/Validators/LessThanOrEqualValidator.js.map +1 -1
- package/lib/validation/Validators/ListValidator.cjs +4 -4
- package/lib/validation/Validators/ListValidator.js.map +1 -1
- package/lib/validation/Validators/MaxLengthValidator.cjs +3 -2
- package/lib/validation/Validators/MaxLengthValidator.js.map +1 -1
- package/lib/validation/Validators/MaxValidator.cjs +1 -1
- package/lib/validation/Validators/MaxValidator.js.map +1 -1
- package/lib/validation/Validators/MinLengthValidator.cjs +3 -2
- package/lib/validation/Validators/MinLengthValidator.js.map +1 -1
- package/lib/validation/Validators/MinValidator.cjs +1 -1
- package/lib/validation/Validators/MinValidator.js.map +1 -1
- package/lib/validation/Validators/OptionValidator.cjs +64 -0
- package/lib/validation/Validators/OptionValidator.d.ts +29 -0
- package/lib/validation/Validators/OptionValidator.js.map +1 -0
- package/lib/validation/Validators/TypeValidator.cjs +2 -2
- package/lib/validation/Validators/TypeValidator.js.map +1 -1
- package/lib/validation/Validators/constants.cjs +5 -4
- package/lib/validation/Validators/constants.d.ts +2 -1
- package/lib/validation/Validators/constants.js.map +1 -1
- package/lib/validation/Validators/decorators.cjs +3 -3
- package/lib/validation/Validators/decorators.d.ts +1 -1
- package/lib/validation/Validators/decorators.js.map +1 -1
- package/lib/validation/Validators/index.cjs +1 -0
- package/lib/validation/Validators/index.d.ts +1 -0
- package/lib/validation/Validators/index.js.map +1 -1
- package/lib/validation/Validators/utils.cjs +66 -0
- package/lib/validation/Validators/utils.d.ts +33 -0
- package/lib/validation/Validators/utils.js.map +1 -1
- package/lib/validation/decorators.cjs +102 -69
- package/lib/validation/decorators.d.ts +28 -17
- package/lib/validation/decorators.js.map +1 -1
- package/lib/validation/types.d.ts +15 -5
- package/lib/validation/types.js.map +1 -1
- package/package.json +2 -3
- package/lib/esm/utils/Decoration.d.ts +0 -135
- package/lib/esm/utils/Decoration.js +0 -227
- package/lib/esm/utils/Decoration.js.map +0 -1
- package/lib/esm/utils/decorators.d.ts +0 -38
- package/lib/esm/utils/decorators.js +0 -64
- package/lib/esm/utils/decorators.js.map +0 -1
- package/lib/utils/Decoration.cjs +0 -231
- package/lib/utils/Decoration.d.ts +0 -135
- package/lib/utils/Decoration.js.map +0 -1
- package/lib/utils/decorators.cjs +0 -68
- package/lib/utils/decorators.d.ts +0 -38
- package/lib/utils/decorators.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decaf-ts/decorator-validation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "simple decorator based validation engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"@decaf-ts/utils": "latest"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@decaf-ts/decoration": "latest"
|
|
82
|
-
"@decaf-ts/reflection": "latest"
|
|
81
|
+
"@decaf-ts/decoration": "latest"
|
|
83
82
|
}
|
|
84
83
|
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { DecorationBuilderBuild, DecorationBuilderEnd, DecorationBuilderMid, DecorationBuilderStart, FlavourResolver, IDecorationBuilder } from "./types";
|
|
2
|
-
export type DecoratorTypes = ClassDecorator | PropertyDecorator | MethodDecorator;
|
|
3
|
-
export type DecoratorFactory = (...args: any[]) => DecoratorTypes;
|
|
4
|
-
export type DecoratorFactoryArgs = {
|
|
5
|
-
decorator: DecoratorFactory;
|
|
6
|
-
args?: any[];
|
|
7
|
-
transform?: (args: any[]) => any[];
|
|
8
|
-
};
|
|
9
|
-
export type DecoratorData = DecoratorTypes | DecoratorFactoryArgs;
|
|
10
|
-
/**
|
|
11
|
-
* @description A decorator management class that handles flavoured decorators
|
|
12
|
-
* @summary The Decoration class provides a builder pattern for creating and managing decorators with different flavours.
|
|
13
|
-
* It supports registering, extending, and applying decorators with context-aware flavour resolution.
|
|
14
|
-
* The class implements a fluent interface for defining, extending, and applying decorators with different flavours,
|
|
15
|
-
* allowing for framework-specific decorator implementations while maintaining a consistent API.
|
|
16
|
-
* @template T Type of the decorator (ClassDecorator | PropertyDecorator | MethodDecorator)
|
|
17
|
-
* @param {string} [flavour] Optional flavour parameter for the decorator context
|
|
18
|
-
* @class
|
|
19
|
-
* @category Model
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* // Create a new decoration for 'component' with default flavour
|
|
23
|
-
* const componentDecorator = new Decoration()
|
|
24
|
-
* .for('component')
|
|
25
|
-
* .define(customComponentDecorator);
|
|
26
|
-
*
|
|
27
|
-
* // Create a flavoured decoration
|
|
28
|
-
* const vueComponent = new Decoration('vue')
|
|
29
|
-
* .for('component')
|
|
30
|
-
* .define(vueComponentDecorator);
|
|
31
|
-
*
|
|
32
|
-
* // Apply the decoration
|
|
33
|
-
* @componentDecorator
|
|
34
|
-
* class MyComponent {}
|
|
35
|
-
* ```
|
|
36
|
-
* @mermaid
|
|
37
|
-
* sequenceDiagram
|
|
38
|
-
* participant C as Client
|
|
39
|
-
* participant D as Decoration
|
|
40
|
-
* participant R as FlavourResolver
|
|
41
|
-
* participant F as DecoratorFactory
|
|
42
|
-
*
|
|
43
|
-
* C->>D: new Decoration(flavour)
|
|
44
|
-
* C->>D: for(key)
|
|
45
|
-
* C->>D: define(decorators)
|
|
46
|
-
* D->>D: register(key, flavour, decorators)
|
|
47
|
-
* D->>F: decoratorFactory(key, flavour)
|
|
48
|
-
* F->>R: resolve(target)
|
|
49
|
-
* R-->>F: resolved flavour
|
|
50
|
-
* F->>F: apply decorators
|
|
51
|
-
* F-->>C: decorated target
|
|
52
|
-
*/
|
|
53
|
-
export declare class Decoration implements IDecorationBuilder {
|
|
54
|
-
private flavour;
|
|
55
|
-
/**
|
|
56
|
-
* @description Static map of registered decorators
|
|
57
|
-
* @summary Stores all registered decorators organized by key and flavour
|
|
58
|
-
*/
|
|
59
|
-
private static decorators;
|
|
60
|
-
/**
|
|
61
|
-
* @description Function to resolve flavour from a target
|
|
62
|
-
* @summary Resolver function that determines the appropriate flavour for a given target
|
|
63
|
-
*/
|
|
64
|
-
private static flavourResolver;
|
|
65
|
-
/**
|
|
66
|
-
* @description Set of decorators for the current context
|
|
67
|
-
*/
|
|
68
|
-
private decorators?;
|
|
69
|
-
/**
|
|
70
|
-
* @description Set of additional decorators
|
|
71
|
-
*/
|
|
72
|
-
private extras?;
|
|
73
|
-
/**
|
|
74
|
-
* @description Current decorator key
|
|
75
|
-
*/
|
|
76
|
-
private key?;
|
|
77
|
-
constructor(flavour?: string);
|
|
78
|
-
/**
|
|
79
|
-
* @description Sets the key for the decoration builder
|
|
80
|
-
* @summary Initializes a new decoration chain with the specified key
|
|
81
|
-
* @param {string} key The identifier for the decorator
|
|
82
|
-
* @return {DecorationBuilderMid} Builder instance for method chaining
|
|
83
|
-
*/
|
|
84
|
-
for(key: string): DecorationBuilderMid;
|
|
85
|
-
/**
|
|
86
|
-
* @description Adds decorators to the current context
|
|
87
|
-
* @summary Internal method to add decorators with addon support
|
|
88
|
-
* @param {boolean} [addon=false] Whether the decorators are addons
|
|
89
|
-
* @param decorators Array of decorators
|
|
90
|
-
* @return {this} Current instance for chaining
|
|
91
|
-
*/
|
|
92
|
-
private decorate;
|
|
93
|
-
/**
|
|
94
|
-
* @description Defines the base decorators
|
|
95
|
-
* @summary Sets the primary decorators for the current context
|
|
96
|
-
* @param decorators Decorators to define
|
|
97
|
-
* @return Builder instance for finishing the chain
|
|
98
|
-
*/
|
|
99
|
-
define(...decorators: DecoratorData[]): DecorationBuilderEnd & DecorationBuilderBuild;
|
|
100
|
-
/**
|
|
101
|
-
* @description Extends existing decorators
|
|
102
|
-
* @summary Adds additional decorators to the current context
|
|
103
|
-
* @param decorators Additional decorators
|
|
104
|
-
* @return {DecorationBuilderBuild} Builder instance for building the decorator
|
|
105
|
-
*/
|
|
106
|
-
extend(...decorators: DecoratorData[]): DecorationBuilderBuild;
|
|
107
|
-
protected decoratorFactory(key: string, f?: string): (target: object, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => {
|
|
108
|
-
target: object;
|
|
109
|
-
propertyKey: any;
|
|
110
|
-
descriptor: TypedPropertyDescriptor<any> | undefined;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* @description Creates the final decorator function
|
|
114
|
-
* @summary Builds and returns the decorator factory function
|
|
115
|
-
* @return {function(any, any?, TypedPropertyDescriptor?): any} The generated decorator function
|
|
116
|
-
*/
|
|
117
|
-
apply(): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
118
|
-
/**
|
|
119
|
-
* @description Registers decorators for a specific key and flavour
|
|
120
|
-
* @summary Internal method to store decorators in the static registry
|
|
121
|
-
* @param {string} key Decorator key
|
|
122
|
-
* @param {string} flavour Decorator flavour
|
|
123
|
-
* @param [decorators] Primary decorators
|
|
124
|
-
* @param [extras] Additional decorators
|
|
125
|
-
*/
|
|
126
|
-
private static register;
|
|
127
|
-
/**
|
|
128
|
-
* @description Sets the global flavour resolver
|
|
129
|
-
* @summary Configures the function used to determine decorator flavours
|
|
130
|
-
* @param {FlavourResolver} resolver Function to resolve flavours
|
|
131
|
-
*/
|
|
132
|
-
static setFlavourResolver(resolver: FlavourResolver): void;
|
|
133
|
-
static for(key: string): DecorationBuilderMid;
|
|
134
|
-
static flavouredAs(flavour: string): DecorationBuilderStart;
|
|
135
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { DefaultFlavour } from "./constants.js";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
-
function defaultFlavourResolver(target) {
|
|
4
|
-
return DefaultFlavour;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @description A decorator management class that handles flavoured decorators
|
|
8
|
-
* @summary The Decoration class provides a builder pattern for creating and managing decorators with different flavours.
|
|
9
|
-
* It supports registering, extending, and applying decorators with context-aware flavour resolution.
|
|
10
|
-
* The class implements a fluent interface for defining, extending, and applying decorators with different flavours,
|
|
11
|
-
* allowing for framework-specific decorator implementations while maintaining a consistent API.
|
|
12
|
-
* @template T Type of the decorator (ClassDecorator | PropertyDecorator | MethodDecorator)
|
|
13
|
-
* @param {string} [flavour] Optional flavour parameter for the decorator context
|
|
14
|
-
* @class
|
|
15
|
-
* @category Model
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Create a new decoration for 'component' with default flavour
|
|
19
|
-
* const componentDecorator = new Decoration()
|
|
20
|
-
* .for('component')
|
|
21
|
-
* .define(customComponentDecorator);
|
|
22
|
-
*
|
|
23
|
-
* // Create a flavoured decoration
|
|
24
|
-
* const vueComponent = new Decoration('vue')
|
|
25
|
-
* .for('component')
|
|
26
|
-
* .define(vueComponentDecorator);
|
|
27
|
-
*
|
|
28
|
-
* // Apply the decoration
|
|
29
|
-
* @componentDecorator
|
|
30
|
-
* class MyComponent {}
|
|
31
|
-
* ```
|
|
32
|
-
* @mermaid
|
|
33
|
-
* sequenceDiagram
|
|
34
|
-
* participant C as Client
|
|
35
|
-
* participant D as Decoration
|
|
36
|
-
* participant R as FlavourResolver
|
|
37
|
-
* participant F as DecoratorFactory
|
|
38
|
-
*
|
|
39
|
-
* C->>D: new Decoration(flavour)
|
|
40
|
-
* C->>D: for(key)
|
|
41
|
-
* C->>D: define(decorators)
|
|
42
|
-
* D->>D: register(key, flavour, decorators)
|
|
43
|
-
* D->>F: decoratorFactory(key, flavour)
|
|
44
|
-
* F->>R: resolve(target)
|
|
45
|
-
* R-->>F: resolved flavour
|
|
46
|
-
* F->>F: apply decorators
|
|
47
|
-
* F-->>C: decorated target
|
|
48
|
-
*/
|
|
49
|
-
export class Decoration {
|
|
50
|
-
/**
|
|
51
|
-
* @description Static map of registered decorators
|
|
52
|
-
* @summary Stores all registered decorators organized by key and flavour
|
|
53
|
-
*/
|
|
54
|
-
static { this.decorators = {}; }
|
|
55
|
-
/**
|
|
56
|
-
* @description Function to resolve flavour from a target
|
|
57
|
-
* @summary Resolver function that determines the appropriate flavour for a given target
|
|
58
|
-
*/
|
|
59
|
-
static { this.flavourResolver = defaultFlavourResolver; }
|
|
60
|
-
constructor(flavour = DefaultFlavour) {
|
|
61
|
-
this.flavour = flavour;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @description Sets the key for the decoration builder
|
|
65
|
-
* @summary Initializes a new decoration chain with the specified key
|
|
66
|
-
* @param {string} key The identifier for the decorator
|
|
67
|
-
* @return {DecorationBuilderMid} Builder instance for method chaining
|
|
68
|
-
*/
|
|
69
|
-
for(key) {
|
|
70
|
-
this.key = key;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @description Adds decorators to the current context
|
|
75
|
-
* @summary Internal method to add decorators with addon support
|
|
76
|
-
* @param {boolean} [addon=false] Whether the decorators are addons
|
|
77
|
-
* @param decorators Array of decorators
|
|
78
|
-
* @return {this} Current instance for chaining
|
|
79
|
-
*/
|
|
80
|
-
decorate(addon = false, ...decorators) {
|
|
81
|
-
if (!this.key)
|
|
82
|
-
throw new Error("key must be provided before decorators can be added");
|
|
83
|
-
if ((!decorators || !decorators.length) &&
|
|
84
|
-
!addon &&
|
|
85
|
-
this.flavour !== DefaultFlavour)
|
|
86
|
-
throw new Error("Must provide overrides or addons to override or extend decaf's decorators");
|
|
87
|
-
if (this.flavour === DefaultFlavour && addon)
|
|
88
|
-
throw new Error("Default flavour cannot be extended");
|
|
89
|
-
this[addon ? "extras" : "decorators"] = new Set([
|
|
90
|
-
...(this[addon ? "extras" : "decorators"] || new Set()).values(),
|
|
91
|
-
...decorators,
|
|
92
|
-
]);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* @description Defines the base decorators
|
|
97
|
-
* @summary Sets the primary decorators for the current context
|
|
98
|
-
* @param decorators Decorators to define
|
|
99
|
-
* @return Builder instance for finishing the chain
|
|
100
|
-
*/
|
|
101
|
-
define(...decorators) {
|
|
102
|
-
return this.decorate(false, ...decorators);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* @description Extends existing decorators
|
|
106
|
-
* @summary Adds additional decorators to the current context
|
|
107
|
-
* @param decorators Additional decorators
|
|
108
|
-
* @return {DecorationBuilderBuild} Builder instance for building the decorator
|
|
109
|
-
*/
|
|
110
|
-
extend(...decorators) {
|
|
111
|
-
return this.decorate(true, ...decorators);
|
|
112
|
-
}
|
|
113
|
-
decoratorFactory(key, f = DefaultFlavour) {
|
|
114
|
-
const contextDecorator = function contextDecorator(target, propertyKey, descriptor) {
|
|
115
|
-
const flavour = Decoration.flavourResolver(target);
|
|
116
|
-
const cache = Decoration.decorators[key];
|
|
117
|
-
let decorators;
|
|
118
|
-
const extras = cache[flavour]
|
|
119
|
-
? cache[flavour].extras
|
|
120
|
-
: cache[DefaultFlavour].extras;
|
|
121
|
-
const extraArgs = [
|
|
122
|
-
...(cache[DefaultFlavour].extras
|
|
123
|
-
? cache[DefaultFlavour].extras.values()
|
|
124
|
-
: []),
|
|
125
|
-
].reduce((accum, e, i) => {
|
|
126
|
-
if (e.args)
|
|
127
|
-
accum[i] = e.args;
|
|
128
|
-
return accum;
|
|
129
|
-
}, {});
|
|
130
|
-
if (cache &&
|
|
131
|
-
cache[flavour] &&
|
|
132
|
-
cache[flavour].decorators &&
|
|
133
|
-
cache[flavour].decorators.size) {
|
|
134
|
-
decorators = cache[flavour].decorators;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
decorators = cache[DefaultFlavour].decorators;
|
|
138
|
-
}
|
|
139
|
-
const decoratorArgs = [
|
|
140
|
-
...cache[DefaultFlavour].decorators.values(),
|
|
141
|
-
].reduce((accum, e, i) => {
|
|
142
|
-
if (e.args)
|
|
143
|
-
accum[i] = e.args;
|
|
144
|
-
return accum;
|
|
145
|
-
}, {});
|
|
146
|
-
const toApply = [
|
|
147
|
-
...(decorators ? decorators.values() : []),
|
|
148
|
-
...(extras ? extras.values() : []),
|
|
149
|
-
];
|
|
150
|
-
return toApply.reduce((_, d, i) => {
|
|
151
|
-
switch (typeof d) {
|
|
152
|
-
case "object": {
|
|
153
|
-
const { decorator, args, transform } = d;
|
|
154
|
-
const argz = args || i < (decorators ? decorators.size : 0)
|
|
155
|
-
? decoratorArgs[i]
|
|
156
|
-
: extraArgs[i - (decorators ? decorators.size : 0)] ||
|
|
157
|
-
(decorators ? decoratorArgs[i - decorators.size] : []);
|
|
158
|
-
const transformed = transform
|
|
159
|
-
? transform(argz || [])
|
|
160
|
-
: argz || [];
|
|
161
|
-
return decorator(...transformed)(target, propertyKey, descriptor);
|
|
162
|
-
}
|
|
163
|
-
case "function":
|
|
164
|
-
return d(target, propertyKey, descriptor);
|
|
165
|
-
default:
|
|
166
|
-
throw new Error(`Unexpected decorator type: ${typeof d}`);
|
|
167
|
-
}
|
|
168
|
-
}, { target, propertyKey, descriptor });
|
|
169
|
-
};
|
|
170
|
-
Object.defineProperty(contextDecorator, "name", {
|
|
171
|
-
value: [f, key].join("_decorator_for_"),
|
|
172
|
-
writable: false,
|
|
173
|
-
});
|
|
174
|
-
return contextDecorator;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* @description Creates the final decorator function
|
|
178
|
-
* @summary Builds and returns the decorator factory function
|
|
179
|
-
* @return {function(any, any?, TypedPropertyDescriptor?): any} The generated decorator function
|
|
180
|
-
*/
|
|
181
|
-
apply() {
|
|
182
|
-
if (!this.key)
|
|
183
|
-
throw new Error("No key provided for the decoration builder");
|
|
184
|
-
Decoration.register(this.key, this.flavour, this.decorators || new Set(), this.extras);
|
|
185
|
-
return this.decoratorFactory(this.key, this.flavour);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* @description Registers decorators for a specific key and flavour
|
|
189
|
-
* @summary Internal method to store decorators in the static registry
|
|
190
|
-
* @param {string} key Decorator key
|
|
191
|
-
* @param {string} flavour Decorator flavour
|
|
192
|
-
* @param [decorators] Primary decorators
|
|
193
|
-
* @param [extras] Additional decorators
|
|
194
|
-
*/
|
|
195
|
-
static register(key, flavour, decorators, extras) {
|
|
196
|
-
if (!key) {
|
|
197
|
-
throw new Error("No key provided for the decoration builder");
|
|
198
|
-
}
|
|
199
|
-
if (!decorators)
|
|
200
|
-
throw new Error("No decorators provided for the decoration builder");
|
|
201
|
-
if (!flavour)
|
|
202
|
-
throw new Error("No flavour provided for the decoration builder");
|
|
203
|
-
if (!Decoration.decorators[key])
|
|
204
|
-
Decoration.decorators[key] = {};
|
|
205
|
-
if (!Decoration.decorators[key][flavour])
|
|
206
|
-
Decoration.decorators[key][flavour] = {};
|
|
207
|
-
if (decorators)
|
|
208
|
-
Decoration.decorators[key][flavour].decorators = decorators;
|
|
209
|
-
if (extras)
|
|
210
|
-
Decoration.decorators[key][flavour].extras = extras;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* @description Sets the global flavour resolver
|
|
214
|
-
* @summary Configures the function used to determine decorator flavours
|
|
215
|
-
* @param {FlavourResolver} resolver Function to resolve flavours
|
|
216
|
-
*/
|
|
217
|
-
static setFlavourResolver(resolver) {
|
|
218
|
-
Decoration.flavourResolver = resolver;
|
|
219
|
-
}
|
|
220
|
-
static for(key) {
|
|
221
|
-
return new Decoration().for(key);
|
|
222
|
-
}
|
|
223
|
-
static flavouredAs(flavour) {
|
|
224
|
-
return new Decoration(flavour);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
//# sourceMappingURL=Decoration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3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;IACjC,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Property decorator factory for model attributes
|
|
3
|
-
* @summary Creates a decorator that marks class properties as model attributes
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [key=ModelKeys.ATTRIBUTE] - The metadata key under which to store the property name
|
|
6
|
-
* @return {function(object, any?): void} - Decorator function that registers the property
|
|
7
|
-
* @function prop
|
|
8
|
-
* @category Property Decorators
|
|
9
|
-
*
|
|
10
|
-
* @mermaid
|
|
11
|
-
* sequenceDiagram
|
|
12
|
-
* participant D as Decorator
|
|
13
|
-
* participant M as Model
|
|
14
|
-
*
|
|
15
|
-
* D->>M: Check if key exists
|
|
16
|
-
* alt key exists
|
|
17
|
-
* M-->>D: Return existing props array
|
|
18
|
-
* else key doesn't exist
|
|
19
|
-
* D->>M: Create new props array
|
|
20
|
-
* end
|
|
21
|
-
* D->>M: Check if property exists
|
|
22
|
-
* alt property not in array
|
|
23
|
-
* D->>M: Add property to array
|
|
24
|
-
* end
|
|
25
|
-
*/
|
|
26
|
-
export declare function prop(key?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
27
|
-
/**
|
|
28
|
-
* @description Combined property decorator factory for metadata and attribute marking
|
|
29
|
-
* @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
|
|
30
|
-
*
|
|
31
|
-
* @template V
|
|
32
|
-
* @param {string} key - The metadata key
|
|
33
|
-
* @param {V} value - The metadata value to associate with the property
|
|
34
|
-
* @return {Function} - Combined decorator function
|
|
35
|
-
* @function propMetadata
|
|
36
|
-
* @category Property Decorators
|
|
37
|
-
*/
|
|
38
|
-
export declare function propMetadata<V>(key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { apply, metadata } from "@decaf-ts/reflection";
|
|
2
|
-
import { ModelKeys } from "./constants.js";
|
|
3
|
-
import { Decoration } from "./Decoration.js";
|
|
4
|
-
/**
|
|
5
|
-
* @description Property decorator factory for model attributes
|
|
6
|
-
* @summary Creates a decorator that marks class properties as model attributes
|
|
7
|
-
*
|
|
8
|
-
* @param {string} [key=ModelKeys.ATTRIBUTE] - The metadata key under which to store the property name
|
|
9
|
-
* @return {function(object, any?): void} - Decorator function that registers the property
|
|
10
|
-
* @function prop
|
|
11
|
-
* @category Property Decorators
|
|
12
|
-
*
|
|
13
|
-
* @mermaid
|
|
14
|
-
* sequenceDiagram
|
|
15
|
-
* participant D as Decorator
|
|
16
|
-
* participant M as Model
|
|
17
|
-
*
|
|
18
|
-
* D->>M: Check if key exists
|
|
19
|
-
* alt key exists
|
|
20
|
-
* M-->>D: Return existing props array
|
|
21
|
-
* else key doesn't exist
|
|
22
|
-
* D->>M: Create new props array
|
|
23
|
-
* end
|
|
24
|
-
* D->>M: Check if property exists
|
|
25
|
-
* alt property not in array
|
|
26
|
-
* D->>M: Add property to array
|
|
27
|
-
* end
|
|
28
|
-
*/
|
|
29
|
-
export function prop(key = ModelKeys.ATTRIBUTE) {
|
|
30
|
-
return Decoration.for(key)
|
|
31
|
-
.define(function prop(model, propertyKey) {
|
|
32
|
-
let props;
|
|
33
|
-
if (Object.prototype.hasOwnProperty.call(model, key)) {
|
|
34
|
-
props = model[key];
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
Object.defineProperty(model, key, {
|
|
38
|
-
enumerable: false,
|
|
39
|
-
configurable: false,
|
|
40
|
-
writable: false,
|
|
41
|
-
value: [],
|
|
42
|
-
});
|
|
43
|
-
props = model[key];
|
|
44
|
-
}
|
|
45
|
-
if (!props.includes(propertyKey))
|
|
46
|
-
props.push(propertyKey);
|
|
47
|
-
})
|
|
48
|
-
.apply();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @description Combined property decorator factory for metadata and attribute marking
|
|
52
|
-
* @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
|
|
53
|
-
*
|
|
54
|
-
* @template V
|
|
55
|
-
* @param {string} key - The metadata key
|
|
56
|
-
* @param {V} value - The metadata value to associate with the property
|
|
57
|
-
* @return {Function} - Combined decorator function
|
|
58
|
-
* @function propMetadata
|
|
59
|
-
* @category Property Decorators
|
|
60
|
-
*/
|
|
61
|
-
export function propMetadata(key, value) {
|
|
62
|
-
return apply(prop(), metadata(key, value));
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/utils/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAoB;AACxC,OAAO,EAAE,UAAU,EAAE,wBAAqB;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,IAAI,CAAC,MAAc,SAAS,CAAC,SAAS;IACpD,OAAO,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;SACvB,MAAM,CAAC,SAAS,IAAI,CAAC,KAAa,EAAE,WAAiB;QACpD,IAAI,KAAe,CAAC;QACpB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACrD,KAAK,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;gBAChC,UAAU,EAAE,KAAK;gBACjB,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,KAAK;gBACf,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;YACH,KAAK,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAqB,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,WAAqB,CAAC,CAAC;IACtC,CAAC,CAAC;SACD,KAAK,EAAE,CAAC;AACb,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAI,GAAW,EAAE,KAAQ;IACnD,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAI,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAChD,CAAC"}
|