framework-do-dede 0.0.19 → 0.0.21
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/controller.d.ts +1 -1
- package/dist/decorators/controller.js +20 -8
- package/dist/decorators/entity.d.ts +1 -0
- package/dist/decorators/entity.js +8 -0
- package/dist/decorators/index.d.ts +2 -1
- package/dist/decorators/index.js +2 -1
- package/dist/domain/Entity.d.ts +4 -0
- package/dist/domain/Entity.js +10 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Validation } from "../protocols/Validation";
|
|
2
2
|
import { HttpMiddleware } from "../protocols";
|
|
3
3
|
export declare function Controller(basePath: string): (target: any) => void;
|
|
4
|
-
export declare function Middleware(middlewareClass: new () => HttpMiddleware): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
4
|
+
export declare function Middleware(middlewareClass: new (...args: any[]) => HttpMiddleware): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
5
|
export declare function Post(config?: {
|
|
6
6
|
path?: string;
|
|
7
7
|
statusCode?: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { FrameworkError } from "../http/FrameworkError";
|
|
2
2
|
import { Registry } from "../di/registry";
|
|
3
|
-
const middlewares = new Map();
|
|
4
3
|
export function Controller(basePath) {
|
|
5
4
|
return function (target) {
|
|
6
5
|
Reflect.defineMetadata('basePath', basePath, target);
|
|
@@ -9,17 +8,30 @@ export function Controller(basePath) {
|
|
|
9
8
|
Registry.addDependency('controllers', target);
|
|
10
9
|
};
|
|
11
10
|
}
|
|
11
|
+
// export function Middleware(middlewareClass: new () => HttpMiddleware) {
|
|
12
|
+
// return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
13
|
+
// if (typeof middlewareClass.prototype.execute !== 'function') {
|
|
14
|
+
// throw new FrameworkError('The concrete class does not implement the Middleware interface.');
|
|
15
|
+
// }
|
|
16
|
+
// // Retrieve existing middlewares for this method or initialize an empty array
|
|
17
|
+
// const middlewares: HttpMiddleware[] = Reflect.getMetadata('middlewares', target, propertyKey) || [];
|
|
18
|
+
// // Create a new instance of the middleware and add it to the array
|
|
19
|
+
// const middlewareInstance = new middlewareClass();
|
|
20
|
+
// middlewares.push(middlewareInstance);
|
|
21
|
+
// // Update the metadata with the new array of middleware instances
|
|
22
|
+
// Reflect.defineMetadata('middlewares', middlewares, target, propertyKey);
|
|
23
|
+
// };
|
|
24
|
+
// }
|
|
12
25
|
export function Middleware(middlewareClass) {
|
|
13
26
|
return function (target, propertyKey, descriptor) {
|
|
14
|
-
if (
|
|
15
|
-
throw new FrameworkError('
|
|
27
|
+
if (!middlewareClass.prototype.execute) {
|
|
28
|
+
throw new FrameworkError('Middleware must implement execute()');
|
|
16
29
|
}
|
|
17
|
-
//
|
|
30
|
+
// Get existing middlewares or initialize empty array
|
|
18
31
|
const middlewares = Reflect.getMetadata('middlewares', target, propertyKey) || [];
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Update the metadata with the new array of middleware instances
|
|
32
|
+
// Store the middleware class reference
|
|
33
|
+
middlewares.push(middlewareClass);
|
|
34
|
+
// Update metadata
|
|
23
35
|
Reflect.defineMetadata('middlewares', middlewares, target, propertyKey);
|
|
24
36
|
};
|
|
25
37
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Restrict(): (target: any, propertyKey: string) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware } from './controller';
|
|
2
2
|
import { Auth } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
|
|
4
|
+
import { Restrict } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict };
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Controller, Post, Get, Put, Delete, Patch, Validator, Middleware } from './controller';
|
|
2
2
|
import { Auth } from './usecase';
|
|
3
3
|
import { Inject } from './di';
|
|
4
|
-
|
|
4
|
+
import { Restrict } from './entity';
|
|
5
|
+
export { Controller, Middleware, Validator, Post, Get, Put, Delete, Patch, Auth, Inject, Restrict };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export class Entity {
|
|
2
|
+
attributes() {
|
|
3
|
+
const ctor = this.constructor;
|
|
4
|
+
const restrictedProps = ctor._restrictedProperties || new Set();
|
|
5
|
+
return Object.fromEntries(Object.entries(this).filter(([key]) => !restrictedProps.has(key)));
|
|
6
|
+
}
|
|
7
|
+
toSave() {
|
|
8
|
+
return Object.fromEntries(Object.entries(this).filter(([, value]) => value != undefined));
|
|
9
|
+
}
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Dede, Register as DedeRegister, Options as DedeOptions } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject } from './decorators';
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Validation, HttpMiddleware, UseCase } from './protocols';
|
|
5
|
+
import { Entity } from './domain/Entity';
|
|
5
6
|
declare class RequestData {
|
|
6
7
|
headers: any;
|
|
7
8
|
data: any;
|
|
@@ -11,4 +12,4 @@ declare class RequestData {
|
|
|
11
12
|
declare class UseCaseHandler {
|
|
12
13
|
static load<T extends UseCase<any, any>>(useCaseClass: new (...args: any[]) => T, request?: RequestData): T;
|
|
13
14
|
}
|
|
14
|
-
export { UseCase, HttpMiddleware, Validation, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject };
|
|
15
|
+
export { UseCase, HttpMiddleware, Validation, RequestData, Dede, DedeRegister, DedeOptions, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Dede } from './dede';
|
|
2
|
-
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject } from './decorators';
|
|
2
|
+
import { Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Restrict } from './decorators';
|
|
3
3
|
import { BadRequest, Conflict, Forbidden, HttpServer, NotFound, ServerError, Unauthorized, UnprocessableEntity } from './http';
|
|
4
4
|
import { Registry } from './di/registry';
|
|
5
|
+
import { Entity } from './domain/Entity';
|
|
5
6
|
class RequestData {
|
|
6
7
|
headers;
|
|
7
8
|
data;
|
|
@@ -23,4 +24,4 @@ class UseCaseHandler {
|
|
|
23
24
|
return instance;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
export { RequestData, Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject };
|
|
27
|
+
export { RequestData, Dede, UseCaseHandler, ServerError, BadRequest, Conflict, Forbidden, HttpServer, NotFound, Unauthorized, UnprocessableEntity, Controller, Post, Put, Get, Delete, Patch, Validator, Middleware, Auth, Inject, Entity, Restrict };
|