framework-do-dede 1.0.22 → 1.0.24

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 +1 @@
1
- export declare function Storage(): (target: any, propertyKey: string) => void;
1
+ export declare function Storage(gatewayName: string): (target: any, propertyKey: string) => void;
@@ -1,20 +1,26 @@
1
1
  import { Registry } from "../di/registry";
2
2
  import { StorageGateway } from "../protocols/StorageGateway";
3
- export function Storage() {
3
+ import { Log } from "../utils/Log";
4
+ import { Testing } from "../utils/Testing";
5
+ export function Storage(gatewayName) {
4
6
  return function (target, propertyKey) {
5
- const designType = Reflect.getMetadata('design:type', target, propertyKey);
6
- if (!(designType?.prototype instanceof StorageGateway)) {
7
- throw new Error(`@Storage() can only be used with StorageGateway subclasses`);
7
+ if (Testing.isEnabled()) {
8
+ Log.info(`@Storage ${gatewayName} is ignored in testing mode`);
9
+ return;
8
10
  }
9
- const gatewayName = designType.name;
11
+ // Verifica se a classe está registrada
10
12
  if (!Registry.has(gatewayName)) {
11
13
  throw new Error(`StorageGateway ${gatewayName} not registered`);
12
14
  }
15
+ const GatewayClass = Registry.resolve(gatewayName);
16
+ // Valida se a classe registrada é uma subclasse de StorageGateway
17
+ if (!(GatewayClass instanceof StorageGateway)) {
18
+ throw new Error(`${gatewayName} is not a valid StorageGateway`);
19
+ }
13
20
  const instanceSymbol = Symbol();
14
21
  Object.defineProperty(target, propertyKey, {
15
22
  get: function () {
16
23
  if (!this[instanceSymbol]) {
17
- const GatewayClass = Registry.resolve(gatewayName);
18
24
  this[instanceSymbol] = GatewayClass;
19
25
  }
20
26
  return this[instanceSymbol];
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Conte
3
3
  import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
4
4
  import { Validation, HttpMiddleware, UseCase, CreateRepository, ExistsById, DeleteRepository, UpdateRepository, RestoreRepository, RestoreManyRepository, RequestMetricsHandler, RequestData, RequestMetrics, HttpServerError, StorageGateway } from './protocols';
5
5
  import { Entity } from './domain/Entity';
6
+ import { Testing } from './utils/Testing';
6
7
  declare class UseCaseHandler {
7
8
  static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: RequestData): T;
8
9
  }
9
- export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, ExistsById, RestoreManyRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage };
10
+ export { UseCase, HttpMiddleware, Validation, RequestMetricsHandler, RequestMetrics, HttpServerError, CreateRepository, DeleteRepository, UpdateRepository, RestoreRepository, ExistsById, RestoreManyRepository, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage, Testing };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Conte
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 { Testing } from './utils/Testing';
6
7
  class UseCaseHandler {
7
8
  static load(useCaseClass, request) {
8
9
  const instance = Registry.classLoader(useCaseClass);
@@ -16,4 +17,4 @@ class UseCaseHandler {
16
17
  return instance;
17
18
  }
18
19
  }
19
- export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, Storage };
20
+ export { Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, Storage, Testing };
@@ -1,5 +1,5 @@
1
1
  export declare abstract class StorageGateway {
2
2
  save(file: File, path: string): Promise<void>;
3
- get(key: string): Promise<void>;
4
- delete(key: string): Promise<void>;
3
+ get(key: string): Promise<string>;
4
+ delete(key: string): Promise<boolean>;
5
5
  }
@@ -0,0 +1,6 @@
1
+ export declare class Testing {
2
+ private static enabled;
3
+ static enable(): void;
4
+ static disable(): void;
5
+ static isEnabled(): typeof Testing.isEnabled;
6
+ }
@@ -0,0 +1,12 @@
1
+ export class Testing {
2
+ static enabled = false;
3
+ static enable() {
4
+ this.enabled = true;
5
+ }
6
+ static disable() {
7
+ this.enabled = false;
8
+ }
9
+ static isEnabled() {
10
+ return this.isEnabled;
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",