framework-do-dede 2.0.12 → 2.0.13
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/dist/handlers/index.d.ts
CHANGED
package/dist/handlers/index.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { USE_CASE_DECORATORS } from "../decorators/usecase";
|
|
2
|
+
import { Registry } from "../di/registry";
|
|
3
|
+
export default class UseCaseHandler {
|
|
4
|
+
static load(useCaseClass, request) {
|
|
5
|
+
const instance = Registry.classLoader(useCaseClass);
|
|
6
|
+
const useCaseDecorators = Reflect.getMetadata(USE_CASE_DECORATORS, useCaseClass) || [];
|
|
7
|
+
const useCaseDecoratorsInstances = [];
|
|
8
|
+
for (const useCaseDecorator of useCaseDecorators) {
|
|
9
|
+
useCaseDecoratorsInstances.push(Registry.classLoader(useCaseDecorator));
|
|
10
|
+
}
|
|
11
|
+
const context = request;
|
|
12
|
+
const contextMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
13
|
+
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
14
|
+
if (context?.middlewareData?.[middlewareKey]) {
|
|
15
|
+
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
16
|
+
for (let index = 0; index < useCaseDecoratorsInstances.length; index++) {
|
|
17
|
+
useCaseDecoratorsInstances[index][propertyKey] = context.middlewareData[middlewareKey];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const originalExecute = instance.execute.bind(instance);
|
|
22
|
+
instance.execute = async (input) => {
|
|
23
|
+
for await (const useCaseDecoratorsInstance of useCaseDecoratorsInstances) {
|
|
24
|
+
await useCaseDecoratorsInstance.execute(input);
|
|
25
|
+
}
|
|
26
|
+
return originalExecute(input);
|
|
27
|
+
};
|
|
28
|
+
return instance;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,5 @@ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middl
|
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsBy, NotExistsBy, DeleteRepository, DeleteRepositoryBy, UpdateRepository, RestoreRepository, RestoreRepositoryBy, RestoreManyRepository, RequestMetricsHandler, Request, RequestMetrics, HttpServerError, StorageGateway } from './protocols';
|
|
5
5
|
import { Entity } from './domain/Entity';
|
|
6
|
-
|
|
7
|
-
static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: Request): T;
|
|
8
|
-
}
|
|
6
|
+
import { UseCaseHandler } from './handlers';
|
|
9
7
|
export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, DeleteRepositoryBy, UpdateRepository, RestoreRepository, RestoreRepositoryBy, ExistsBy, NotExistsBy, RestoreManyRepository, Request, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage, Expose };
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,6 @@
|
|
|
1
1
|
import { Dede } from './dede';
|
|
2
2
|
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, Expose } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
|
-
import { Registry } from './di/registry';
|
|
5
4
|
import { Entity } from './domain/Entity';
|
|
6
|
-
import {
|
|
7
|
-
class UseCaseHandler {
|
|
8
|
-
static load(useCaseClass, request) {
|
|
9
|
-
const instance = Registry.classLoader(useCaseClass);
|
|
10
|
-
const useCaseDecorators = Reflect.getMetadata(USE_CASE_DECORATORS, useCaseClass) || [];
|
|
11
|
-
const useCaseDecoratorsInstances = [];
|
|
12
|
-
for (const useCaseDecorator of useCaseDecorators) {
|
|
13
|
-
useCaseDecoratorsInstances.push(Registry.classLoader(useCaseDecorator));
|
|
14
|
-
}
|
|
15
|
-
const context = request;
|
|
16
|
-
const contextMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
17
|
-
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
18
|
-
if (context?.middlewareData?.[middlewareKey]) {
|
|
19
|
-
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
20
|
-
for (let index = 0; index < useCaseDecoratorsInstances.length; index++) {
|
|
21
|
-
useCaseDecoratorsInstances[index][propertyKey] = context.middlewareData[middlewareKey];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const originalExecute = instance.execute.bind(instance);
|
|
26
|
-
instance.execute = async (input) => {
|
|
27
|
-
for await (const useCaseDecoratorsInstance of useCaseDecoratorsInstances) {
|
|
28
|
-
await useCaseDecoratorsInstance.execute(input);
|
|
29
|
-
}
|
|
30
|
-
return originalExecute(input);
|
|
31
|
-
};
|
|
32
|
-
return instance;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
5
|
+
import { UseCaseHandler } from './handlers';
|
|
35
6
|
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, Storage, Expose };
|