framework-do-dede 2.0.11 → 2.0.12
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,6 +1,6 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middlewares, Metrics, OffConsoleLog } from './controller';
|
|
2
|
-
import { Context } from './usecase';
|
|
2
|
+
import { Context, DecorateUseCase } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
4
|
import { Restrict, DbColumn, VirtualProperty, Expose } from './entity';
|
|
5
5
|
import { Storage } from './services';
|
|
6
|
-
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
|
6
|
+
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middlewares, Metrics, OffConsoleLog } from './controller';
|
|
2
|
-
import { Context } from './usecase';
|
|
2
|
+
import { Context, DecorateUseCase } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
4
|
import { Restrict, DbColumn, VirtualProperty, Expose } from './entity';
|
|
5
5
|
import { Storage } from './services';
|
|
6
|
-
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
|
6
|
+
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
|
@@ -1 +1,4 @@
|
|
|
1
|
+
import { UseCase } from "../protocols";
|
|
2
|
+
export declare const USE_CASE_DECORATORS: unique symbol;
|
|
1
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;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const USE_CASE_DECORATORS = Symbol('useCaseDecorators');
|
|
1
2
|
export function Context(middlewareKey) {
|
|
2
3
|
return function (target, propertyKey) {
|
|
3
4
|
const metadata = Reflect.getMetadata('context', target.constructor) || [];
|
|
@@ -5,3 +6,10 @@ export function Context(middlewareKey) {
|
|
|
5
6
|
Reflect.defineMetadata('context', metadata, target.constructor);
|
|
6
7
|
};
|
|
7
8
|
}
|
|
9
|
+
export function DecorateUseCase(useCases) {
|
|
10
|
+
return function (target) {
|
|
11
|
+
const decorators = Array.isArray(useCases) ? useCases : [useCases];
|
|
12
|
+
Reflect.defineMetadata(USE_CASE_DECORATORS, decorators, target);
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, Expose } from './decorators';
|
|
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
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
6
|
declare class UseCaseHandler {
|
|
7
7
|
static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: Request): T;
|
|
8
8
|
}
|
|
9
|
-
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, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage, Expose };
|
|
9
|
+
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,19 +1,35 @@
|
|
|
1
1
|
import { Dede } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, Expose } from './decorators';
|
|
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
4
|
import { Registry } from './di/registry';
|
|
5
5
|
import { Entity } from './domain/Entity';
|
|
6
|
+
import { USE_CASE_DECORATORS } from './decorators/usecase';
|
|
6
7
|
class UseCaseHandler {
|
|
7
8
|
static load(useCaseClass, request) {
|
|
8
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
|
+
}
|
|
9
15
|
const context = request;
|
|
10
16
|
const contextMetadata = Reflect.getMetadata('context', useCaseClass) || [];
|
|
11
17
|
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
12
18
|
if (context?.middlewareData?.[middlewareKey]) {
|
|
13
19
|
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
20
|
+
for (let index = 0; index < useCaseDecoratorsInstances.length; index++) {
|
|
21
|
+
useCaseDecoratorsInstances[index][propertyKey] = context.middlewareData[middlewareKey];
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
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
|
+
};
|
|
16
32
|
return instance;
|
|
17
33
|
}
|
|
18
34
|
}
|
|
19
|
-
export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, Storage, Expose };
|
|
35
|
+
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 };
|