framework-do-dede 2.0.9 → 2.0.10

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.
@@ -2,6 +2,7 @@ import { Validation } from "../protocols/Validation";
2
2
  import { HttpMiddleware, RequestMetricsHandler } from "../protocols";
3
3
  export declare function Controller(basePath: string): (target: any) => void;
4
4
  export declare function Middleware(middlewareClass: new (...args: any[]) => HttpMiddleware): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
5
+ export declare function Middlewares(middlewareClasses: (new (...args: any[]) => HttpMiddleware)[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
5
6
  export declare function Post(config?: {
6
7
  path?: string;
7
8
  statusCode?: number;
@@ -13,11 +13,27 @@ export function Middleware(middlewareClass) {
13
13
  if (!middlewareClass.prototype.execute) {
14
14
  throw new FrameworkError('Middleware must implement execute()');
15
15
  }
16
+ Reflect.getMetadata('context', middlewareClass) || [];
16
17
  const middlewares = Reflect.getMetadata('middlewares', target, propertyKey) || [];
17
18
  middlewares.push(middlewareClass);
18
19
  Reflect.defineMetadata('middlewares', middlewares, target, propertyKey);
19
20
  };
20
21
  }
22
+ export function Middlewares(middlewareClasses) {
23
+ return function (target, propertyKey, descriptor) {
24
+ for (const middlewareClass of middlewareClasses) {
25
+ if (!middlewareClass.prototype.execute) {
26
+ throw new FrameworkError('Middleware must implement execute()');
27
+ }
28
+ Reflect.getMetadata('context', middlewareClass) || [];
29
+ }
30
+ const existingMiddlewares = Reflect.getMetadata('middlewares', target, propertyKey) || [];
31
+ // Add the new middleware classes to the list
32
+ existingMiddlewares.push(...middlewareClasses);
33
+ // Update the metadata with the combined list
34
+ Reflect.defineMetadata('middlewares', existingMiddlewares, target, propertyKey);
35
+ };
36
+ }
21
37
  export function Post(config = {}) {
22
38
  return function (target, propertyKey, descriptor) {
23
39
  Reflect.defineMetadata('route', {
@@ -1,6 +1,6 @@
1
- import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metrics, OffConsoleLog } from './controller';
1
+ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middlewares, Metrics, OffConsoleLog } from './controller';
2
2
  import { Context } 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, 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, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
@@ -1,6 +1,6 @@
1
- import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Metrics, OffConsoleLog } from './controller';
1
+ import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware, Middlewares, Metrics, OffConsoleLog } from './controller';
2
2
  import { Context } 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, 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, Inject, Restrict, DbColumn, Storage, Expose, VirtualProperty };
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, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, Expose } from './decorators';
2
+ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, 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, 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, Inject, Entity, Restrict, DbColumn, VirtualProperty, Metrics, OffConsoleLog, StorageGateway, Storage, Expose };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Dede } from './dede';
2
- import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Context, Inject, Restrict, Metrics, DbColumn, VirtualProperty, OffConsoleLog, Storage, Expose } from './decorators';
2
+ import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Middlewares, Context, 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';
@@ -16,4 +16,4 @@ class UseCaseHandler {
16
16
  return instance;
17
17
  }
18
18
  }
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, Expose };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",