framework-do-dede 3.0.24 → 3.0.26
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.
|
@@ -6,4 +6,10 @@ export declare abstract class UseCase<UseCaseInput, UseCaseOutput, UseCaseContex
|
|
|
6
6
|
constructor(input?: Input<UseCaseInput>);
|
|
7
7
|
abstract execute(): Promise<UseCaseOutput>;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type UseCaseConstructor = new (...args: any[]) => UseCase<any, any>;
|
|
10
|
+
interface DecorateUseCaseOptions {
|
|
11
|
+
useCase: UseCaseConstructor | UseCaseConstructor[];
|
|
12
|
+
params?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
export declare function DecorateUseCase(options: DecorateUseCaseOptions): <T extends UseCaseConstructor>(target: T) => T;
|
|
15
|
+
export {};
|
|
@@ -9,10 +9,33 @@ export class UseCase {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
export function DecorateUseCase(
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export function DecorateUseCase(options) {
|
|
13
|
+
return (target) => {
|
|
14
|
+
return class extends target {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
const useCases = Array.isArray(options.useCase)
|
|
18
|
+
? options.useCase
|
|
19
|
+
: [options.useCase];
|
|
20
|
+
const self = this;
|
|
21
|
+
self._decoratorUseCases = useCases.map((UseCaseClass) => {
|
|
22
|
+
return new UseCaseClass({
|
|
23
|
+
data: this.data,
|
|
24
|
+
context: {
|
|
25
|
+
...this.context,
|
|
26
|
+
options: options.params || {}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
self._originalMethod = target.prototype.execute;
|
|
31
|
+
}
|
|
32
|
+
async execute() {
|
|
33
|
+
const self = this;
|
|
34
|
+
for (const useCase of self._decoratorUseCases) {
|
|
35
|
+
await useCase.execute();
|
|
36
|
+
}
|
|
37
|
+
return await self._originalMethod.call(this);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
17
40
|
};
|
|
18
41
|
}
|