framework-do-dede 3.0.25 → 3.0.27

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
- 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
  }
@@ -150,11 +150,17 @@ export default class ControllerHandler {
150
150
  statusCode: error.getStatusCode()
151
151
  };
152
152
  }
153
+ const debugError = {
154
+ sourceUrl: error.sourceURL,
155
+ line: error.line,
156
+ column: error.column,
157
+ };
153
158
  error = new InternalServerError(error.message, httpServer.getDefaultMessageError());
154
159
  return {
155
160
  message: error.message,
156
161
  statusCode: error.getStatusCode(),
157
162
  unexpectedError: error instanceof InternalServerError ? error.getUnexpectedError() : undefined,
163
+ ...debugError
158
164
  };
159
165
  }
160
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "3.0.25",
3
+ "version": "3.0.27",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",