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.
@@ -115,7 +115,7 @@ export class Entity {
115
115
  }
116
116
  }
117
117
  for (const property of Object.keys(this)) {
118
- if (typeof property === 'function')
118
+ if (typeof this[property] === 'function')
119
119
  continue;
120
120
  // @ts-ignore
121
121
  if (this.constructor.strategyId === property)
@@ -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
- export declare function DecorateUseCase(useCases: UseCase<any, any> | (new (...args: any[]) => UseCase<any, any>) | Array<UseCase<any, any> | (new (...args: any[]) => UseCase<any, any>)>): ClassDecorator;
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(useCases) {
13
- return function (target) {
14
- const decorators = Array.isArray(useCases) ? useCases : [useCases];
15
- Reflect.defineMetadata(USE_CASE_DECORATORS, decorators, target);
16
- return target;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "3.0.24",
3
+ "version": "3.0.26",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",