framework-do-dede 3.1.0 → 3.2.0

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.
@@ -25,6 +25,7 @@ export interface Input<T, K = any> {
25
25
  data: T;
26
26
  context?: K;
27
27
  }
28
+ type BodyFilter = "restrict" | "none";
28
29
  export declare function Controller(basePath?: string): (target: any) => void;
29
30
  export declare function Tracing<R>(tracer: Tracer<R>): (target: any, propertyKey?: string) => void;
30
31
  export declare function getControllers(): any[];
@@ -37,6 +38,8 @@ export declare function Post(config?: {
37
38
  params?: string[];
38
39
  query?: string[];
39
40
  headers?: string[];
41
+ body?: string[];
42
+ bodyFilter?: BodyFilter;
40
43
  responseType?: 'json' | 'text' | 'html';
41
44
  }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
42
45
  export declare function Get(config?: {
@@ -53,6 +56,8 @@ export declare function Put(config?: {
53
56
  params?: string[];
54
57
  query?: string[];
55
58
  headers?: string[];
59
+ body?: string[];
60
+ bodyFilter?: BodyFilter;
56
61
  responseType?: 'json' | 'text' | 'html';
57
62
  }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
58
63
  export declare function Patch(config?: {
@@ -61,6 +66,8 @@ export declare function Patch(config?: {
61
66
  params?: string[];
62
67
  query?: string[];
63
68
  headers?: string[];
69
+ body?: string[];
70
+ bodyFilter?: BodyFilter;
64
71
  responseType?: 'json' | 'text' | 'html';
65
72
  }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
66
73
  export declare function Delete(config?: {
@@ -69,5 +76,8 @@ export declare function Delete(config?: {
69
76
  params?: string[];
70
77
  query?: string[];
71
78
  headers?: string[];
79
+ body?: string[];
80
+ bodyFilter?: BodyFilter;
72
81
  responseType?: 'json' | 'text' | 'html';
73
82
  }): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
83
+ export {};
@@ -66,6 +66,8 @@ export function Post(config = {}) {
66
66
  params: config.params,
67
67
  query: config.query,
68
68
  headers: config.headers,
69
+ body: config.body,
70
+ bodyFilter: config.bodyFilter || 'none',
69
71
  statusCode: config.statusCode || 200,
70
72
  responseType: config.responseType || 'json'
71
73
  }, target, propertyKey);
@@ -92,6 +94,8 @@ export function Put(config = {}) {
92
94
  params: config.params,
93
95
  query: config.query,
94
96
  headers: config.headers,
97
+ body: config.body,
98
+ bodyFilter: config.bodyFilter || 'none',
95
99
  statusCode: config.statusCode || 200,
96
100
  responseType: config.responseType || 'json'
97
101
  }, target, propertyKey);
@@ -105,6 +109,8 @@ export function Patch(config = {}) {
105
109
  params: config.params,
106
110
  query: config.query,
107
111
  headers: config.headers,
112
+ body: config.body,
113
+ bodyFilter: config.bodyFilter || 'none',
108
114
  statusCode: config.statusCode || 200,
109
115
  responseType: config.responseType || 'json'
110
116
  }, target, propertyKey);
@@ -118,6 +124,8 @@ export function Delete(config = {}) {
118
124
  params: config.params,
119
125
  query: config.query,
120
126
  headers: config.headers,
127
+ body: config.body,
128
+ bodyFilter: config.bodyFilter || 'none',
121
129
  statusCode: config.statusCode || 200,
122
130
  responseType: config.responseType || 'json'
123
131
  }, target, propertyKey);
@@ -4,7 +4,7 @@ import { FrameworkError } from "../http/errors/framework";
4
4
  import { CustomServerError } from "./errors/server";
5
5
  export default class ControllerHandler {
6
6
  constructor(httpServer, port) {
7
- for (const { handler, middlewares, method, route, statusCode, params, query, headers, responseType } of this.registryControllers()) {
7
+ for (const { handler, middlewares, method, route, statusCode, params, query, headers, body, bodyFilter, responseType } of this.registryControllers()) {
8
8
  httpServer.register({
9
9
  method,
10
10
  route,
@@ -28,11 +28,12 @@ export default class ControllerHandler {
28
28
  const filterParams = this.filter(input.params, params);
29
29
  const filterQueryParams = this.filter(input.query, query);
30
30
  const filterHeaders = this.filter(input.headers, headers);
31
- let body = input.body || {};
32
- if (Object.keys(body).length > 0) {
33
- body = this.normalizeBracketNotation(body);
31
+ const normalizeBody = this.normalizeBracketNotation(body);
32
+ let filterBody = this.filter(normalizeBody, body);
33
+ if (bodyFilter === 'none') {
34
+ filterBody = { ...normalizeBody, ...filterBody };
34
35
  }
35
- mergedParams = { ...filterHeaders, ...filterParams, ...filterQueryParams, ...body };
36
+ mergedParams = { ...filterHeaders, ...filterParams, ...filterQueryParams, ...filterBody };
36
37
  request = { data: mergedParams, context: {} };
37
38
  middlewaresExecuted = await this.executeMiddlewares(middlewares, request);
38
39
  const response = await handler.instance[handler.methodName](request);
@@ -120,6 +121,8 @@ export default class ControllerHandler {
120
121
  params: routeConfig.params,
121
122
  query: routeConfig.query,
122
123
  headers: routeConfig.headers,
124
+ body: routeConfig.body,
125
+ bodyFilter: routeConfig.bodyFilter,
123
126
  statusCode: routeConfig.statusCode,
124
127
  handler: {
125
128
  instance,
@@ -18,6 +18,8 @@ export type HttpServerParams = {
18
18
  statusCode?: number;
19
19
  params?: string[];
20
20
  query?: string[];
21
+ body?: string[];
22
+ bodyFilter?: 'none' | 'restrict';
21
23
  headers?: string[];
22
24
  };
23
25
  type FrameworkWeb = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",