framework-do-dede 2.0.18 → 2.0.20
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/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -2
- package/dist/decorators/services.d.ts +6 -0
- package/dist/decorators/services.js +14 -0
- package/dist/handlers/usecase.handler.js +22 -19
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -2,5 +2,5 @@ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middl
|
|
|
2
2
|
import { Context, DecorateUseCase } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
4
|
import { Restrict, DbColumn, VirtualProperty, Expose } from './entity';
|
|
5
|
-
import { Storage } from './services';
|
|
6
|
-
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
|
5
|
+
import { Storage, StorageMock } from './services';
|
|
6
|
+
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, StorageMock, Expose, VirtualProperty };
|
package/dist/decorators/index.js
CHANGED
|
@@ -2,5 +2,5 @@ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middl
|
|
|
2
2
|
import { Context, DecorateUseCase } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
4
|
import { Restrict, DbColumn, VirtualProperty, Expose } from './entity';
|
|
5
|
-
import { Storage } from './services';
|
|
6
|
-
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
|
|
5
|
+
import { Storage, StorageMock } from './services';
|
|
6
|
+
export { Controller, Middleware, Middlewares, Validator, Metrics, OffConsoleLog, Post, Get, Put, Delete, Patch, Context, DecorateUseCase, Inject, Restrict, DbColumn, Storage, StorageMock, Expose, VirtualProperty };
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { Registry } from "../di/registry";
|
|
2
|
+
export class StorageMock {
|
|
3
|
+
static enabled = false;
|
|
4
|
+
static on() {
|
|
5
|
+
StorageMock.enabled = true;
|
|
6
|
+
}
|
|
7
|
+
static off() {
|
|
8
|
+
StorageMock.enabled;
|
|
9
|
+
}
|
|
10
|
+
static isEnabled() {
|
|
11
|
+
return StorageMock.enabled;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
2
14
|
export function Storage(gatewayName) {
|
|
3
15
|
return function (target, propertyKey) {
|
|
16
|
+
if (StorageMock.isEnabled())
|
|
17
|
+
return;
|
|
4
18
|
const instanceSymbol = Symbol();
|
|
5
19
|
Object.defineProperty(target, propertyKey, {
|
|
6
20
|
get: function () {
|
|
@@ -4,37 +4,40 @@ export default class UseCaseHandler {
|
|
|
4
4
|
static load(useCaseClass, request) {
|
|
5
5
|
const useCaseDecorators = Reflect.getMetadata(USE_CASE_DECORATORS, useCaseClass) || [];
|
|
6
6
|
const useCaseDecoratorsInstances = [];
|
|
7
|
+
// Processa decorators
|
|
7
8
|
for (const useCaseDecorator of useCaseDecorators) {
|
|
9
|
+
let instance;
|
|
8
10
|
if (typeof useCaseDecorator === 'function') {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const contextDecoratorsMetadata = Reflect.getMetadata('context', useCaseDecorator) || [];
|
|
12
|
-
contextDecoratorsMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
13
|
-
if (context?.middlewareData?.[middlewareKey]) {
|
|
14
|
-
instanceDecorator[propertyKey] = context.middlewareData[middlewareKey];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
useCaseDecoratorsInstances.push(instanceDecorator);
|
|
11
|
+
// Cria instância via DI
|
|
12
|
+
instance = Registry.classLoader(useCaseDecorator);
|
|
18
13
|
}
|
|
19
14
|
else {
|
|
20
|
-
|
|
15
|
+
// Usa instância existente
|
|
16
|
+
instance = useCaseDecorator;
|
|
21
17
|
}
|
|
18
|
+
// Injeta contexto na instância (seja nova ou existente)
|
|
19
|
+
injectContext(instance, request);
|
|
20
|
+
useCaseDecoratorsInstances.push(instance);
|
|
22
21
|
}
|
|
22
|
+
// Cria e configura a instância principal
|
|
23
23
|
const instance = Registry.classLoader(useCaseClass);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
27
|
-
if (context?.middlewareData?.[middlewareKey]) {
|
|
28
|
-
instance[propertyKey] = context.middlewareData[middlewareKey];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
24
|
+
injectContext(instance, request);
|
|
25
|
+
// Decora o método execute
|
|
31
26
|
const originalExecute = instance.execute.bind(instance);
|
|
32
27
|
instance.execute = async (input) => {
|
|
33
|
-
for
|
|
34
|
-
await
|
|
28
|
+
for (const decoratorInstance of useCaseDecoratorsInstances) {
|
|
29
|
+
await decoratorInstance.execute(input);
|
|
35
30
|
}
|
|
36
31
|
return originalExecute(input);
|
|
37
32
|
};
|
|
38
33
|
return instance;
|
|
39
34
|
}
|
|
40
35
|
}
|
|
36
|
+
function injectContext(instance, request) {
|
|
37
|
+
const contextMetadata = Reflect.getMetadata('context', instance.constructor) || [];
|
|
38
|
+
contextMetadata.forEach(({ propertyKey, middlewareKey }) => {
|
|
39
|
+
if (request?.middlewareData?.[middlewareKey]) {
|
|
40
|
+
instance[propertyKey] = request.middlewareData[middlewareKey];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, 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, StorageMock, 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
|
import { UseCaseHandler } from './handlers';
|
|
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 };
|
|
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, StorageMock, Expose };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dede } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, DecorateUseCase, 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, StorageMock, Expose } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Entity } from './domain/Entity';
|
|
5
5
|
import { UseCaseHandler } from './handlers';
|
|
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 };
|
|
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, StorageMock, Expose };
|