quantum-flow 1.0.1

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.
Files changed (102) hide show
  1. package/.prettierrc.json +9 -0
  2. package/README.md +37 -0
  3. package/dist/app/aws/index.d.ts +1 -0
  4. package/dist/app/aws/index.js +17 -0
  5. package/dist/app/aws/lambda.d.ts +13 -0
  6. package/dist/app/aws/lambda.js +241 -0
  7. package/dist/app/http/Application.d.ts +23 -0
  8. package/dist/app/http/Application.js +208 -0
  9. package/dist/app/http/Socket.d.ts +16 -0
  10. package/dist/app/http/Socket.js +32 -0
  11. package/dist/app/http/decorators.d.ts +7 -0
  12. package/dist/app/http/decorators.js +81 -0
  13. package/dist/app/http/index.d.ts +3 -0
  14. package/dist/app/http/index.js +19 -0
  15. package/dist/app/http/websocket/WebsocetService.d.ts +20 -0
  16. package/dist/app/http/websocket/WebsocetService.js +41 -0
  17. package/dist/app/http/websocket/WebsocketServer.d.ts +30 -0
  18. package/dist/app/http/websocket/WebsocketServer.js +221 -0
  19. package/dist/constants.d.ts +16 -0
  20. package/dist/constants.js +24 -0
  21. package/dist/core/Controller.d.ts +43 -0
  22. package/dist/core/Controller.js +159 -0
  23. package/dist/core/Endpoint.d.ts +8 -0
  24. package/dist/core/Endpoint.js +43 -0
  25. package/dist/core/index.d.ts +4 -0
  26. package/dist/core/index.js +19 -0
  27. package/dist/core/utils/extractors.d.ts +15 -0
  28. package/dist/core/utils/extractors.js +29 -0
  29. package/dist/core/utils/helpers.d.ts +4 -0
  30. package/dist/core/utils/helpers.js +22 -0
  31. package/dist/core/utils/index.d.ts +3 -0
  32. package/dist/core/utils/index.js +19 -0
  33. package/dist/core/utils/websocket.d.ts +8 -0
  34. package/dist/core/utils/websocket.js +45 -0
  35. package/dist/types/common.d.ts +47 -0
  36. package/dist/types/common.js +2 -0
  37. package/dist/types/controller.d.ts +4 -0
  38. package/dist/types/controller.js +2 -0
  39. package/dist/types/http.d.ts +18 -0
  40. package/dist/types/http.js +2 -0
  41. package/dist/types/index.d.ts +5 -0
  42. package/dist/types/index.js +21 -0
  43. package/dist/types/lambda.d.ts +26 -0
  44. package/dist/types/lambda.js +2 -0
  45. package/dist/types/websocket.d.ts +55 -0
  46. package/dist/types/websocket.js +2 -0
  47. package/dist/utils/controller.d.ts +9 -0
  48. package/dist/utils/controller.js +111 -0
  49. package/dist/utils/helper.d.ts +1 -0
  50. package/dist/utils/helper.js +24 -0
  51. package/dist/utils/index.d.ts +7 -0
  52. package/dist/utils/index.js +23 -0
  53. package/dist/utils/multipart.d.ts +15 -0
  54. package/dist/utils/multipart.js +109 -0
  55. package/dist/utils/parsers.d.ts +4 -0
  56. package/dist/utils/parsers.js +76 -0
  57. package/dist/utils/server.d.ts +4 -0
  58. package/dist/utils/server.js +46 -0
  59. package/dist/utils/transform.d.ts +1 -0
  60. package/dist/utils/transform.js +23 -0
  61. package/dist/utils/validate.d.ts +1 -0
  62. package/dist/utils/validate.js +46 -0
  63. package/dist/validators/Validate.d.ts +3 -0
  64. package/dist/validators/Validate.js +40 -0
  65. package/dist/validators/index.d.ts +1 -0
  66. package/dist/validators/index.js +17 -0
  67. package/eslint.config.mjs +84 -0
  68. package/nodemon.json +5 -0
  69. package/package.json +70 -0
  70. package/src/app/aws/index.ts +1 -0
  71. package/src/app/aws/lambda.ts +283 -0
  72. package/src/app/http/Application.ts +250 -0
  73. package/src/app/http/Socket.ts +38 -0
  74. package/src/app/http/decorators.ts +115 -0
  75. package/src/app/http/index.ts +3 -0
  76. package/src/app/http/websocket/WebsocetService.ts +44 -0
  77. package/src/app/http/websocket/WebsocketServer.ts +262 -0
  78. package/src/constants.ts +25 -0
  79. package/src/core/Controller.ts +229 -0
  80. package/src/core/Endpoint.ts +39 -0
  81. package/src/core/index.ts +14 -0
  82. package/src/core/utils/extractors.ts +32 -0
  83. package/src/core/utils/helpers.ts +22 -0
  84. package/src/core/utils/index.ts +3 -0
  85. package/src/core/utils/websocket.ts +45 -0
  86. package/src/types/common.ts +60 -0
  87. package/src/types/controller.ts +2 -0
  88. package/src/types/http.ts +19 -0
  89. package/src/types/index.ts +5 -0
  90. package/src/types/lambda.ts +28 -0
  91. package/src/types/websocket.ts +57 -0
  92. package/src/utils/controller.ts +143 -0
  93. package/src/utils/helper.ts +24 -0
  94. package/src/utils/index.ts +7 -0
  95. package/src/utils/multipart.ts +93 -0
  96. package/src/utils/parsers.ts +87 -0
  97. package/src/utils/server.ts +49 -0
  98. package/src/utils/transform.ts +24 -0
  99. package/src/utils/validate.ts +53 -0
  100. package/src/validators/Validate.ts +48 -0
  101. package/src/validators/index.ts +1 -0
  102. package/tsconfig.json +51 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USE = exports.DELETE = exports.PATCH = exports.PUT = exports.POST = exports.GET = void 0;
4
+ exports.Endpoint = Endpoint;
5
+ const _constants_1 = require("@constants");
6
+ function Endpoint(method, pathPattern, middlewares) {
7
+ return function (target, propertyKey, descriptor) {
8
+ const originalMethod = descriptor.value;
9
+ if (!originalMethod) {
10
+ console.warn('❌ originalMethod is undefined!');
11
+ return descriptor;
12
+ }
13
+ if (method && pathPattern) {
14
+ Reflect.defineMetadata(_constants_1.ENDPOINT, [method, pathPattern], target, propertyKey);
15
+ Reflect.defineMetadata('middlewares', middlewares || [], target, propertyKey);
16
+ }
17
+ return descriptor;
18
+ };
19
+ }
20
+ const GET = (pathPattern, middelwares) => {
21
+ return Endpoint('GET', pathPattern, middelwares);
22
+ };
23
+ exports.GET = GET;
24
+ const POST = (pathPattern, middelwares) => {
25
+ return Endpoint('POST', pathPattern, middelwares);
26
+ };
27
+ exports.POST = POST;
28
+ const PUT = (pathPattern, middelwares) => {
29
+ return Endpoint('PUT', pathPattern, middelwares);
30
+ };
31
+ exports.PUT = PUT;
32
+ const PATCH = (pathPattern, middelwares) => {
33
+ return Endpoint('PATCH', pathPattern, middelwares);
34
+ };
35
+ exports.PATCH = PATCH;
36
+ const DELETE = (pathPattern, middelwares) => {
37
+ return Endpoint('DELETE', pathPattern, middelwares);
38
+ };
39
+ exports.DELETE = DELETE;
40
+ const USE = (pathPattern, middelwares) => {
41
+ return Endpoint('USE', pathPattern, middelwares);
42
+ };
43
+ exports.USE = USE;
@@ -0,0 +1,4 @@
1
+ export { EndpointResponse, IController, Interceptor, Middleware, Request, Router, WebSocketClient, WebSocketEvent, WebSocketMessage, } from '@types';
2
+ export * from './Controller';
3
+ export * from './Endpoint';
4
+ export * from './utils';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Controller"), exports);
18
+ __exportStar(require("./Endpoint"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,15 @@
1
+ import { ParamDecoratorType } from '@types';
2
+ export interface ParamMetadata {
3
+ index: number;
4
+ type: ParamDecoratorType;
5
+ dto?: any;
6
+ name?: string;
7
+ }
8
+ export declare const Body: (dto?: any) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
9
+ export declare const Params: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
10
+ export declare const Query: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
11
+ export declare const Request: () => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
12
+ export declare const Headers: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
13
+ export declare const Cookies: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
14
+ export declare const Multipart: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
15
+ export declare const Response: () => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Response = exports.Multipart = exports.Cookies = exports.Headers = exports.Request = exports.Query = exports.Params = exports.Body = void 0;
4
+ const _constants_1 = require("@constants");
5
+ function createParamDecorator(type, dto, name) {
6
+ return function (target, propertyKey, parameterIndex) {
7
+ const existingParams = Reflect.getMetadata(_constants_1.PARAM_METADATA_KEY, target, propertyKey) || [];
8
+ existingParams.push({ index: parameterIndex, type, dto, name });
9
+ existingParams.sort((a, b) => a.index - b.index);
10
+ Reflect.defineMetadata(_constants_1.PARAM_METADATA_KEY, existingParams, target, propertyKey);
11
+ const saved = Reflect.getMetadata(_constants_1.PARAM_METADATA_KEY, target, propertyKey);
12
+ };
13
+ }
14
+ const Body = (dto) => createParamDecorator('body', dto);
15
+ exports.Body = Body;
16
+ const Params = (name) => createParamDecorator('params', undefined, name);
17
+ exports.Params = Params;
18
+ const Query = (name) => createParamDecorator('query', undefined, name);
19
+ exports.Query = Query;
20
+ const Request = () => createParamDecorator('request');
21
+ exports.Request = Request;
22
+ const Headers = (name) => createParamDecorator('headers', undefined, name);
23
+ exports.Headers = Headers;
24
+ const Cookies = (name) => createParamDecorator('cookies', undefined, name);
25
+ exports.Cookies = Cookies;
26
+ const Multipart = (name) => createParamDecorator('multipart', undefined, name);
27
+ exports.Multipart = Multipart;
28
+ const Response = () => createParamDecorator('response');
29
+ exports.Response = Response;
@@ -0,0 +1,4 @@
1
+ export declare function Status(status: number): (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
2
+ export declare const Ok200: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
3
+ export declare const Ok201: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
4
+ export declare const Ok204: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ok204 = exports.Ok201 = exports.Ok200 = void 0;
4
+ exports.Status = Status;
5
+ const _constants_1 = require("@constants");
6
+ function Status(status) {
7
+ return function (target, propertyKey, descriptor) {
8
+ if (!propertyKey) {
9
+ Reflect.defineMetadata(_constants_1.OK_METADATA_KEY, status, target.prototype || target);
10
+ return;
11
+ }
12
+ if (descriptor) {
13
+ Reflect.defineMetadata(_constants_1.OK_METADATA_KEY, status, target, propertyKey);
14
+ }
15
+ };
16
+ }
17
+ const Ok200 = () => Status(200);
18
+ exports.Ok200 = Ok200;
19
+ const Ok201 = () => Status(201);
20
+ exports.Ok201 = Ok201;
21
+ const Ok204 = () => Status(204);
22
+ exports.Ok204 = Ok204;
@@ -0,0 +1,3 @@
1
+ export * from './extractors';
2
+ export * from './helpers';
3
+ export * from './websocket';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./extractors"), exports);
18
+ __exportStar(require("./helpers"), exports);
19
+ __exportStar(require("./websocket"), exports);
@@ -0,0 +1,8 @@
1
+ import { WebSocketHandlerType } from '@types';
2
+ export declare function OnWS(type: WebSocketHandlerType, topic?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
3
+ export declare function OnConnection(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
4
+ export declare function OnMessage(topic?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
5
+ export declare function OnClose(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
6
+ export declare function OnError(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
7
+ export declare function Subscribe(topic: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
8
+ export declare function InjectWS(): (target: any, propertyKey: string, parameterIndex: number) => void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnWS = OnWS;
4
+ exports.OnConnection = OnConnection;
5
+ exports.OnMessage = OnMessage;
6
+ exports.OnClose = OnClose;
7
+ exports.OnError = OnError;
8
+ exports.Subscribe = Subscribe;
9
+ exports.InjectWS = InjectWS;
10
+ const _constants_1 = require("@constants");
11
+ function OnWS(type, topic) {
12
+ return function (target, propertyKey, descriptor) {
13
+ const handlers = Reflect.getMetadata(_constants_1.WS_METADATA_KEY, target.constructor) || [];
14
+ handlers.push({ type, topic, method: propertyKey });
15
+ Reflect.defineMetadata(_constants_1.WS_METADATA_KEY, handlers, target.constructor);
16
+ return descriptor;
17
+ };
18
+ }
19
+ function OnConnection() {
20
+ return OnWS('connection');
21
+ }
22
+ function OnMessage(topic) {
23
+ return OnWS('message', topic);
24
+ }
25
+ function OnClose() {
26
+ return OnWS('close');
27
+ }
28
+ function OnError() {
29
+ return OnWS('error');
30
+ }
31
+ function Subscribe(topic) {
32
+ return function (target, propertyKey, descriptor) {
33
+ const topics = Reflect.getMetadata(_constants_1.WS_TOPIC_KEY, target.constructor) || [];
34
+ topics.push({ topic, method: propertyKey });
35
+ Reflect.defineMetadata(_constants_1.WS_TOPIC_KEY, topics, target.constructor);
36
+ return descriptor;
37
+ };
38
+ }
39
+ function InjectWS() {
40
+ return function (target, propertyKey, parameterIndex) {
41
+ const existingParams = Reflect.getMetadata(_constants_1.WS_SERVICE_KEY, target, propertyKey) || [];
42
+ existingParams.push({ index: parameterIndex });
43
+ Reflect.defineMetadata(_constants_1.WS_SERVICE_KEY, existingParams, target, propertyKey);
44
+ };
45
+ }
@@ -0,0 +1,47 @@
1
+ import { IncomingHttpHeaders, ServerResponse } from 'http';
2
+ type P_Q = Record<string, string | undefined> | null | unknown;
3
+ export type Request<B = unknown, Q extends P_Q = unknown, P extends P_Q = unknown> = {
4
+ method: string;
5
+ url: URL;
6
+ headers: IncomingHttpHeaders;
7
+ query?: Q;
8
+ params?: P;
9
+ body: B;
10
+ isBase64Encoded?: boolean;
11
+ };
12
+ export type Router = (req: Request, res?: ServerResponse) => Promise<{
13
+ status: number;
14
+ data: any;
15
+ message?: string;
16
+ }>;
17
+ export type EndpointResponse<T = any> = {
18
+ status: number;
19
+ data?: T;
20
+ error?: any;
21
+ };
22
+ export type AxiosQuery = {
23
+ data?: {
24
+ [key: string]: any;
25
+ };
26
+ headers?: {
27
+ [key: string]: any;
28
+ };
29
+ params?: {
30
+ [key: string]: any;
31
+ };
32
+ url: string;
33
+ method: 'POST' | 'GET' | 'PATCH' | 'DELETE';
34
+ };
35
+ export interface IController {
36
+ handleRequest: Router;
37
+ }
38
+ export type Middleware = (req: Request, res?: ServerResponse) => Promise<Request> | Request;
39
+ export type Interceptor = (data: any, req?: Request, res?: ServerResponse) => Promise<unknown> | unknown;
40
+ export type ParamDecoratorType = 'body' | 'params' | 'query' | 'request' | 'headers' | 'cookies' | 'response' | 'multipart';
41
+ export interface ParamMetadata {
42
+ index: number;
43
+ type: ParamDecoratorType;
44
+ dto?: any;
45
+ name?: string;
46
+ }
47
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export type ControllerClass = {
2
+ new (...args: any[]): any;
3
+ };
4
+ export type ControllerInstance = InstanceType<ControllerClass>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ export interface ServerConfig {
2
+ port?: number;
3
+ host?: string;
4
+ globalMiddlewares?: any[];
5
+ globalInterceptors?: any[];
6
+ globalErrorHandler?: any;
7
+ controllers?: any[];
8
+ websocket?: {
9
+ enabled: boolean;
10
+ path?: string;
11
+ lazy?: boolean;
12
+ };
13
+ }
14
+ export type Conf = ServerConfig & {
15
+ globalMiddlewares?: any[];
16
+ globalInterceptors?: any[];
17
+ globalErrorHandler?: any;
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './common';
2
+ export * from './controller';
3
+ export * from './http';
4
+ export * from './lambda';
5
+ export * from './websocket';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./common"), exports);
18
+ __exportStar(require("./controller"), exports);
19
+ __exportStar(require("./http"), exports);
20
+ __exportStar(require("./lambda"), exports);
21
+ __exportStar(require("./websocket"), exports);
@@ -0,0 +1,26 @@
1
+ import { APIGatewayProxyEvent, Context } from 'aws-lambda';
2
+ export interface LambdaRequest {
3
+ method: string;
4
+ path: string;
5
+ headers: Record<string, string | string[]>;
6
+ query: Record<string, string | string[]>;
7
+ body: any;
8
+ params: Record<string, string>;
9
+ cookies: Record<string, string>;
10
+ raw: APIGatewayProxyEvent;
11
+ context: Context;
12
+ isBase64Encoded: boolean;
13
+ requestId: string;
14
+ stage: string;
15
+ sourceIp: string;
16
+ userAgent: string;
17
+ url: URL;
18
+ }
19
+ export interface LambdaResponse {
20
+ statusCode: number;
21
+ headers?: Record<string, string>;
22
+ body: string;
23
+ isBase64Encoded?: boolean;
24
+ multiValueHeaders?: Record<string, string[]>;
25
+ cookies?: string[];
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,55 @@
1
+ import WebSocket from 'ws';
2
+ export type WebSocketHandlerType = 'connection' | 'message' | 'close' | 'error';
3
+ export interface WebSocketMessage {
4
+ type: string;
5
+ topic?: string;
6
+ data: any;
7
+ clientId?: string;
8
+ }
9
+ export interface WebSocketEvent {
10
+ type: WebSocketHandlerType;
11
+ client: WebSocketClient;
12
+ message?: WebSocketMessage;
13
+ data?: any;
14
+ }
15
+ export interface WebSocketClient {
16
+ id: string;
17
+ socket: WebSocket;
18
+ topics: Set<string>;
19
+ data: Record<string, any>;
20
+ connectedAt: Date;
21
+ }
22
+ export interface WebSocketMessage {
23
+ type: string;
24
+ topic?: string;
25
+ data: any;
26
+ clientId?: string;
27
+ }
28
+ export interface WebSocketStats {
29
+ clients: number;
30
+ topics: Array<{
31
+ topic: string;
32
+ subscribers: number;
33
+ }>;
34
+ }
35
+ export interface IWebSocketService {
36
+ sendToClient(clientId: string, message: any): boolean;
37
+ publishToTopic(topic: string, data: any, exclude?: string[]): void;
38
+ broadcast(message: any, excludeClientId?: string): void;
39
+ getStats(): {
40
+ clients: number;
41
+ topics: Array<{
42
+ topic: string;
43
+ subscribers: number;
44
+ }>;
45
+ };
46
+ isAvailable(): boolean;
47
+ }
48
+ export interface IWebSocketServer {
49
+ sendToClient(clientId: string, message: any): boolean;
50
+ publishToTopic(topic: string, data: any, exclude: string[]): void;
51
+ broadcast(message: any, excludeClientId?: string): void;
52
+ getStats(): WebSocketStats;
53
+ subscribeToTopic(client: WebSocketClient, topic: string): void;
54
+ unsubscribeFromTopic(client: WebSocketClient, topic: string): void;
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { ControllerInstance } from '@types';
2
+ import { ServerResponse } from 'http';
3
+ export declare const executeControllerMethod: (controller: ControllerInstance, propertyName: string, payload: any, response?: ServerResponse) => Promise<any>;
4
+ export declare const getControllerMethods: (controller: ControllerInstance) => {
5
+ name: string;
6
+ httpMethod: string;
7
+ pattern: string;
8
+ middlewares?: Array<(req: any, res?: ServerResponse) => any>;
9
+ }[];
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getControllerMethods = exports.executeControllerMethod = void 0;
4
+ const _utils_1 = require("@utils");
5
+ const WebsocetService_1 = require("../app/http/websocket/WebsocetService");
6
+ const validate_1 = require("./validate");
7
+ const _constants_1 = require("@constants");
8
+ const getBodyAndMultipart = (payload) => {
9
+ let body = payload.body;
10
+ let multipart;
11
+ if (_utils_1.MultipartProcessor.isMultipart({ headers: payload.headers })) {
12
+ try {
13
+ const { fields, files } = _utils_1.MultipartProcessor.parse({
14
+ body: payload.rawBody || payload.body,
15
+ headers: payload.headers,
16
+ isBase64Encoded: payload.isBase64Encoded,
17
+ });
18
+ multipart = files;
19
+ body = fields;
20
+ }
21
+ catch (error) {
22
+ console.error('❌ Multipart parsing error:', error);
23
+ throw { status: 400, message: 'Invalid multipart data' };
24
+ }
25
+ }
26
+ return { multipart, body };
27
+ };
28
+ const executeControllerMethod = async (controller, propertyName, payload, response) => {
29
+ const fn = controller[propertyName];
30
+ if (typeof fn !== 'function')
31
+ return null;
32
+ const endpointMeta = Reflect.getMetadata(_constants_1.ENDPOINT, controller, propertyName);
33
+ if (!endpointMeta)
34
+ return null;
35
+ const methodMiddlewares = Reflect.getMetadata(_constants_1.MIDDLEWARES, controller, propertyName) || [];
36
+ for (let i = 0; i < methodMiddlewares.length; i++) {
37
+ const middleware = methodMiddlewares[i];
38
+ const result = await middleware(payload);
39
+ if (result) {
40
+ payload = { ...payload, ...result };
41
+ }
42
+ }
43
+ const prototype = Object.getPrototypeOf(controller);
44
+ const paramMetadata = Reflect.getMetadata(_constants_1.PARAM_METADATA_KEY, prototype, propertyName) || [];
45
+ const { body, multipart } = getBodyAndMultipart(payload);
46
+ if (paramMetadata.length === 0) {
47
+ return fn.call(controller, payload);
48
+ }
49
+ const args = [];
50
+ const wsParams = Reflect.getMetadata(_constants_1.WS_SERVICE_KEY, controller, propertyName) || [];
51
+ const totalParams = Math.max(paramMetadata.length ? Math.max(...paramMetadata.map((p) => p.index)) + 1 : 0, wsParams.length ? Math.max(...wsParams.map((p) => p.index)) + 1 : 0);
52
+ for (let i = 0; i < totalParams; i++) {
53
+ const wsParam = wsParams.find((p) => p.index === i);
54
+ if (wsParam) {
55
+ args[i] = WebsocetService_1.WebSocketService.getInstance();
56
+ continue;
57
+ }
58
+ const param = paramMetadata.find((p) => p.index === i);
59
+ if (!param) {
60
+ args[i] = undefined;
61
+ continue;
62
+ }
63
+ let value = param.name ? payload[param.type]?.[param.name] : payload[param.type];
64
+ if (param.type === 'multipart') {
65
+ value = multipart;
66
+ }
67
+ if (param.type === 'request') {
68
+ value = payload;
69
+ }
70
+ if (param.type === 'response') {
71
+ value = response;
72
+ }
73
+ if (param.type === 'response') {
74
+ value = response;
75
+ }
76
+ if (param.type === 'body') {
77
+ value = body;
78
+ }
79
+ if (_constants_1.TO_VALIDATE.includes(param.type)) {
80
+ value = await (0, validate_1.validate)(param.dto, value);
81
+ }
82
+ args[i] = value;
83
+ }
84
+ return fn.apply(controller, args);
85
+ };
86
+ exports.executeControllerMethod = executeControllerMethod;
87
+ const getControllerMethods = (controller) => {
88
+ const methods = [];
89
+ let proto = Object.getPrototypeOf(controller);
90
+ while (proto && proto !== Object.prototype) {
91
+ const propertyNames = Object.getOwnPropertyNames(proto);
92
+ for (const propertyName of propertyNames) {
93
+ if (propertyName === 'constructor')
94
+ continue;
95
+ const endpointMeta = Reflect.getMetadata(_constants_1.ENDPOINT, proto, propertyName);
96
+ if (endpointMeta) {
97
+ const [httpMethod, pattern] = endpointMeta;
98
+ const methodMiddlewares = Reflect.getMetadata(_constants_1.MIDDLEWARES, proto, propertyName);
99
+ methods.push({
100
+ name: propertyName,
101
+ httpMethod,
102
+ pattern,
103
+ middlewares: methodMiddlewares,
104
+ });
105
+ }
106
+ }
107
+ proto = Object.getPrototypeOf(proto);
108
+ }
109
+ return methods;
110
+ };
111
+ exports.getControllerMethods = getControllerMethods;
@@ -0,0 +1 @@
1
+ export declare const matchRoute: (routePattern: string, actualPath: string) => Record<string, string> | null;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.matchRoute = void 0;
5
+ const matchRoute = (routePattern, actualPath) => {
6
+ const routeParts = routePattern.split('/').filter(Boolean);
7
+ const pathParts = actualPath.split('/').filter(Boolean);
8
+ if (routeParts.length !== pathParts.length)
9
+ return null;
10
+ const params = {};
11
+ for (let i = 0; i < routeParts.length; i++) {
12
+ const routePart = routeParts[i];
13
+ const pathPart = pathParts[i];
14
+ if (routePart.startsWith(':')) {
15
+ const paramName = routePart.slice(1);
16
+ params[paramName] = decodeURIComponent(pathPart);
17
+ }
18
+ else if (routePart !== pathPart) {
19
+ return null;
20
+ }
21
+ }
22
+ return params;
23
+ };
24
+ exports.matchRoute = matchRoute;
@@ -0,0 +1,7 @@
1
+ export * from './controller';
2
+ export * from './helper';
3
+ export * from './multipart';
4
+ export * from './parsers';
5
+ export * from './server';
6
+ export * from './transform';
7
+ export * from './validate';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./controller"), exports);
18
+ __exportStar(require("./helper"), exports);
19
+ __exportStar(require("./multipart"), exports);
20
+ __exportStar(require("./parsers"), exports);
21
+ __exportStar(require("./server"), exports);
22
+ __exportStar(require("./transform"), exports);
23
+ __exportStar(require("./validate"), exports);
@@ -0,0 +1,15 @@
1
+ export interface MultipartFile {
2
+ fieldname: string;
3
+ filename: string;
4
+ contentType: string;
5
+ data: Buffer;
6
+ size: number;
7
+ encoding?: string;
8
+ }
9
+ export declare class MultipartProcessor {
10
+ static parse(request: any): {
11
+ fields: Record<string, any>;
12
+ files: Record<string, MultipartFile | MultipartFile[]>;
13
+ };
14
+ static isMultipart(request: any): boolean;
15
+ }