quantum-flow 1.3.2 → 1.3.5
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.
|
@@ -36,7 +36,7 @@ class HttpServer extends Socket_1.Socket {
|
|
|
36
36
|
║ 🔌 Port: ${this.config.port}
|
|
37
37
|
║ 🔌 Websocket: ${!!this.config.websocket}
|
|
38
38
|
║ 🔧 Global Middlewares: ${this.config.middlewares?.length || 0}
|
|
39
|
-
║ 🔧 Error
|
|
39
|
+
║ 🔧 Error handler: ${!this.config.errorHandler}
|
|
40
40
|
║ 🎯 Global Interceptors: ${!!this.config.interceptor?.length}
|
|
41
41
|
║ 📦 Controllers: ${_constants_1.STATISTIC.controllers}
|
|
42
42
|
║ 📦 Routes: ${_constants_1.STATISTIC.routes}
|
|
@@ -141,9 +141,7 @@ class HttpServer extends Socket_1.Socket {
|
|
|
141
141
|
let processed = appRequest;
|
|
142
142
|
for (const middleware of this.config.middlewares?.reverse() || []) {
|
|
143
143
|
const result = await middleware(processed, request, response);
|
|
144
|
-
|
|
145
|
-
processed = result;
|
|
146
|
-
}
|
|
144
|
+
processed = result ?? processed;
|
|
147
145
|
}
|
|
148
146
|
return processed;
|
|
149
147
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppRequest, ControllerClass, ControllerConfig, ControllerInstance, InterceptorCB, RouteContext } from '../types/index.js';
|
|
1
|
+
import { AppRequest, ControllerClass, ControllerConfig, ControllerInstance, InterceptorCB, MiddlewareCB, RouteContext } from '../types/index.js';
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
4
|
/**
|
|
@@ -45,8 +45,8 @@ export declare function Controller(config: string | ControllerConfig, middleware
|
|
|
45
45
|
name: string;
|
|
46
46
|
pathParams: Record<string, string>;
|
|
47
47
|
priority: number;
|
|
48
|
-
methodMiddlewares:
|
|
49
|
-
methodInterceptors:
|
|
48
|
+
methodMiddlewares: MiddlewareCB[];
|
|
49
|
+
methodInterceptors: InterceptorCB[];
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
} & T;
|
package/dist/core/Controller.js
CHANGED
|
@@ -70,6 +70,7 @@ function Controller(config, middlewares = []) {
|
|
|
70
70
|
super(...args);
|
|
71
71
|
}
|
|
72
72
|
async getResponse(data) {
|
|
73
|
+
let y;
|
|
73
74
|
try {
|
|
74
75
|
let appResponse = await this.executeControllerMethod(data.controllerInstance, data.name, data.payload, data.request, data.response);
|
|
75
76
|
let status = appResponse.status ?? 200;
|
|
@@ -159,7 +160,7 @@ function Controller(config, middlewares = []) {
|
|
|
159
160
|
let payload = { ...context.appRequest, params: pathParams };
|
|
160
161
|
for (const mw of allMiddlewares) {
|
|
161
162
|
const mwResult = await mw(payload, context.request, context.response);
|
|
162
|
-
payload =
|
|
163
|
+
payload = mwResult ?? payload;
|
|
163
164
|
}
|
|
164
165
|
return this.getResponse({
|
|
165
166
|
interceptors: [...context.interceptorChain, controllerMeta.interceptor].filter((el) => !!el),
|
|
@@ -59,6 +59,11 @@ exports.User = User = __decorate([
|
|
|
59
59
|
(0, core_1.Controller)({
|
|
60
60
|
prefix: 'user',
|
|
61
61
|
controllers: [userMetadata_1.UserMetadata],
|
|
62
|
+
middlewares: [
|
|
63
|
+
(req) => {
|
|
64
|
+
return req;
|
|
65
|
+
},
|
|
66
|
+
],
|
|
62
67
|
interceptor: (data, req, res) => {
|
|
63
68
|
return { data, intercepted: true };
|
|
64
69
|
},
|
package/dist/types/common.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type AxiosQuery = {
|
|
|
38
38
|
export interface IController {
|
|
39
39
|
handleRequest: Router;
|
|
40
40
|
}
|
|
41
|
-
export type MiddlewareCB = (appRequest: AppRequest, request?: IncomingMessage,
|
|
41
|
+
export type MiddlewareCB = (appRequest: AppRequest, request?: IncomingMessage, response?: ServerResponse) => void | Promise<AppRequest> | AppRequest;
|
|
42
42
|
export type InterceptorCB = (data: any, req?: IncomingMessage, res?: ServerResponse) => Promise<unknown> | unknown;
|
|
43
43
|
export type ErrorCB = (error: Error, req?: IncomingMessage, res?: ServerResponse) => Promise<ResponseWithStatus> | ResponseWithStatus;
|
|
44
44
|
export type ParamDecoratorType = 'body' | 'params' | 'query' | 'request' | 'headers' | 'cookies' | 'response' | 'multipart' | 'event' | 'context';
|