framework-do-dede 2.0.13 → 2.0.15
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UseCase } from "../protocols";
|
|
2
2
|
export declare const USE_CASE_DECORATORS: unique symbol;
|
|
3
3
|
export declare function Context(middlewareKey: string): (target: any, propertyKey: string) => void;
|
|
4
|
-
export declare function DecorateUseCase(useCases: (new (...args: any[]) => UseCase<any, any>) | Array<new (...args: any[]) => UseCase<any, any>>): ClassDecorator;
|
|
4
|
+
export declare function DecorateUseCase(useCases: (new (...args: any[]) => UseCase<any, any> | UseCase<any, any>) | Array<new (...args: any[]) => UseCase<any, any> | UseCase<any, any>>): ClassDecorator;
|
|
@@ -6,16 +6,25 @@ export default class UseCaseHandler {
|
|
|
6
6
|
const useCaseDecorators = Reflect.getMetadata(USE_CASE_DECORATORS, useCaseClass) || [];
|
|
7
7
|
const useCaseDecoratorsInstances = [];
|
|
8
8
|
for (const useCaseDecorator of useCaseDecorators) {
|
|
9
|
-
|
|
9
|
+
if (typeof useCaseDecorator === 'function') {
|
|
10
|
+
const instanceDecorator = Registry.classLoader(useCaseDecorator);
|
|
11
|
+
const contextDecoratorsMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
12
|
+
contextDecoratorsMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
13
|
+
if (context?.middlewareData?.[middlewareKey]) {
|
|
14
|
+
instanceDecorator[propertyKey] = context.middlewareData[middlewareKey];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
useCaseDecoratorsInstances.push(instanceDecorator);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
useCaseDecoratorsInstances.push(useCaseDecorator);
|
|
21
|
+
}
|
|
10
22
|
}
|
|
11
23
|
const context = request;
|
|
12
24
|
const contextMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
13
25
|
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
14
26
|
if (context?.middlewareData?.[middlewareKey]) {
|
|
15
27
|
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
16
|
-
for (let index = 0; index < useCaseDecoratorsInstances.length; index++) {
|
|
17
|
-
useCaseDecoratorsInstances[index][propertyKey] = context.middlewareData[middlewareKey];
|
|
18
|
-
}
|
|
19
28
|
}
|
|
20
29
|
});
|
|
21
30
|
const originalExecute = instance.execute.bind(instance);
|