quantum-flow 1.0.1 → 1.0.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.
Files changed (70) hide show
  1. package/README.md +245 -17
  2. package/dist/app/aws/lambda.d.ts +1 -1
  3. package/dist/app/aws/lambda.js +2 -2
  4. package/dist/app/http/Application.d.ts +1 -1
  5. package/dist/app/http/Application.js +2 -2
  6. package/dist/app/http/decorators.d.ts +1 -1
  7. package/dist/app/http/decorators.js +1 -1
  8. package/dist/app/http/websocket/WebsocetService.d.ts +1 -1
  9. package/dist/app/http/websocket/WebsocketServer.d.ts +1 -1
  10. package/dist/core/Controller.d.ts +24 -3
  11. package/dist/core/Controller.js +26 -5
  12. package/dist/core/Endpoint.d.ts +63 -7
  13. package/dist/core/Endpoint.js +69 -13
  14. package/dist/core/index.d.ts +7 -1
  15. package/dist/core/utils/extractors.d.ts +31 -1
  16. package/dist/core/utils/extractors.js +31 -1
  17. package/dist/core/utils/helpers.d.ts +13 -0
  18. package/dist/core/utils/helpers.js +14 -1
  19. package/dist/core/utils/websocket.d.ts +26 -1
  20. package/dist/core/utils/websocket.js +26 -1
  21. package/dist/examples/controllers/index.d.ts +2 -0
  22. package/dist/examples/controllers/index.js +18 -0
  23. package/dist/examples/controllers/socket.d.ts +24 -0
  24. package/dist/examples/controllers/socket.js +107 -0
  25. package/dist/examples/controllers/user.d.ts +3 -0
  26. package/dist/examples/controllers/user.js +55 -0
  27. package/dist/examples/server.d.ts +1 -0
  28. package/dist/examples/server.js +48 -0
  29. package/dist/utils/controller.d.ts +1 -1
  30. package/dist/utils/controller.js +2 -2
  31. package/dist/utils/server.d.ts +1 -1
  32. package/dist/utils/server.js +1 -1
  33. package/dist/utils/transform.js +0 -1
  34. package/package.json +20 -6
  35. package/.prettierrc.json +0 -9
  36. package/eslint.config.mjs +0 -84
  37. package/nodemon.json +0 -5
  38. package/src/app/aws/index.ts +0 -1
  39. package/src/app/aws/lambda.ts +0 -283
  40. package/src/app/http/Application.ts +0 -250
  41. package/src/app/http/Socket.ts +0 -38
  42. package/src/app/http/decorators.ts +0 -115
  43. package/src/app/http/index.ts +0 -3
  44. package/src/app/http/websocket/WebsocetService.ts +0 -44
  45. package/src/app/http/websocket/WebsocketServer.ts +0 -262
  46. package/src/constants.ts +0 -25
  47. package/src/core/Controller.ts +0 -229
  48. package/src/core/Endpoint.ts +0 -39
  49. package/src/core/index.ts +0 -14
  50. package/src/core/utils/extractors.ts +0 -32
  51. package/src/core/utils/helpers.ts +0 -22
  52. package/src/core/utils/index.ts +0 -3
  53. package/src/core/utils/websocket.ts +0 -45
  54. package/src/types/common.ts +0 -60
  55. package/src/types/controller.ts +0 -2
  56. package/src/types/http.ts +0 -19
  57. package/src/types/index.ts +0 -5
  58. package/src/types/lambda.ts +0 -28
  59. package/src/types/websocket.ts +0 -57
  60. package/src/utils/controller.ts +0 -143
  61. package/src/utils/helper.ts +0 -24
  62. package/src/utils/index.ts +0 -7
  63. package/src/utils/multipart.ts +0 -93
  64. package/src/utils/parsers.ts +0 -87
  65. package/src/utils/server.ts +0 -49
  66. package/src/utils/transform.ts +0 -24
  67. package/src/utils/validate.ts +0 -53
  68. package/src/validators/Validate.ts +0 -48
  69. package/src/validators/index.ts +0 -1
  70. package/tsconfig.json +0 -51
package/README.md CHANGED
@@ -1,37 +1,265 @@
1
- # Your Package Name
1
+ # Project Overview
2
2
 
3
- Description of your package.
3
+ This project is a decorator-based API framework supporting both HTTP and WebSocket servers. It is designed to simplify the creation of scalable and maintainable APIs with features such as controllers, middlewares, interceptors, error handling, and WebSocket support. Additionally, it supports AWS Lambda integration for serverless deployments.
4
4
 
5
- ## Installation
5
+ # Installation
6
+
7
+ To install dependencies and build the project, run:
6
8
 
7
9
  ```bash
8
- npm install your-package-name
10
+ yarn install
11
+ # or npm install
12
+
13
+ yarn build
14
+ # or npm run build
9
15
  ```
10
16
 
11
- ## Usage
17
+ # Usage
18
+
19
+ ## Defining Controllers
20
+
21
+ Use the `@Controller` decorator to define controllers with options such as prefix, sub-controllers, middlewares, and interceptors.
12
22
 
13
23
  ```typescript
14
- import { greet } from 'your-package-name';
24
+ import { Controller } from 'quantum-flow/core';
15
25
 
16
- console.log(greet('World'));
26
+ @Controller({
27
+ prefix: 'api',
28
+ controllers: [UserController, SocketController],
29
+ interceptors: [(resp) => resp],
30
+ })
31
+ class RootController {}
17
32
  ```
18
33
 
19
- ## Build
34
+ ## Creating a Server
20
35
 
21
- To build the package, run:
36
+ Use the `@Server` decorator with configuration options like port, host, controllers, and WebSocket enablement.
22
37
 
23
- ```bash
24
- npm run build
38
+ ```typescript
39
+ import { Server, Port, Host, Use, Intercept, Catch, HttpServer } from 'quantum-flow/http';
40
+
41
+ @Server({
42
+ controllers: [RootController],
43
+ })
44
+ @Port(3000)
45
+ @Host('localhost')
46
+ @Use((res: any) => res)
47
+ @Intercept((data, req, res) => data)
48
+ @Catch((error) => error)
49
+ class App {}
50
+
51
+ const server = new HttpServer(App);
52
+
53
+ server.listen().catch(console.error);
25
54
  ```
26
55
 
27
- ## Test
56
+ ## Middlewares, Interceptors, and Error Handlers
28
57
 
29
- To run tests, run:
58
+ - Use `@Use` to apply middlewares.
59
+ - Use `@Intercept` to apply interceptors.
60
+ - Use `@Catch` to handle errors.
61
+ - Use `@Port` and `@Host` to configure server port and host.
30
62
 
31
- ```bash
32
- npm run test
63
+ ## Request decorators
64
+
65
+ - Use `@Body` to handle request bodies.
66
+ - Use `@Headers` to access request headers.
67
+ - Use `@Query` to handle query parameters.
68
+ - Use `@Params` to access route parameters.
69
+ - Use `@Host` to configure the server host.
70
+ - Use `@Port` to configure the server port.
71
+ - Use `@Multipart` for handling multipart/form-data requests.
72
+ - Use `@Request` to access the entire request object.
73
+ - Use `@Response` to access the response object.
74
+
75
+ # AWS Lambda Support
76
+
77
+ Use `LambdaAdapter` to convert API Gateway events to requests and responses. Create Lambda handlers from controllers.
78
+
79
+ ```typescript
80
+ Example Lambda handler creation
81
+ import { LambdaAdapter } from 'quantum-flow/aws';
82
+ export const handler = LambdaAdapter.createHandler(RootController);
83
+ ```
84
+
85
+ # WebSocket Support
86
+
87
+ Enable WebSocket in the server configuration and register WebSocket controllers.
88
+
89
+ ```typescript
90
+ @Controller('socket')
91
+ export class Socket {
92
+ @OnConnection()
93
+ onConnection(event: WebSocketEvent) {
94
+ console.log(`✅ Connected: ${event.client.id}`);
95
+
96
+ // Send greeting ONLY to this client
97
+ event.client.socket.send(
98
+ JSON.stringify({
99
+ type: 'welcome',
100
+ data: { message: 'Welcome!' },
101
+ }),
102
+ );
103
+ }
104
+
105
+ /**
106
+ * 2. @Subscribe - AUTOMATIC broadcast to all subscribers
107
+ * No need to use WebSocketService!
108
+ */
109
+ @Subscribe('chat')
110
+ onChatMessage(event: WebSocketEvent) {
111
+ // This method is called for EACH subscriber
112
+ // The message is ALREADY automatically broadcast to all!
113
+
114
+ const msg = event.message?.data;
115
+ console.log(`💬 Message in chat: ${msg?.text}`);
116
+
117
+ // You can add logic, but no need to broadcast
118
+ if (msg?.text.includes('bad')) {
119
+ // If return empty, the message will not be sent
120
+ return;
121
+ }
122
+
123
+ // That's it, the message will be sent to subscribers automatically!
124
+ }
125
+
126
+ /**
127
+ * 3. @Subscribe for another room
128
+ */
129
+ @Subscribe('news')
130
+ onNewsMessage(event: WebSocketEvent) {
131
+ console.log(`📰 News: ${event.message?.data.title}`);
132
+ // Automatic broadcast to all subscribed to 'news'
133
+ }
134
+
135
+ /**
136
+ * 4. @OnMessage for commands (without WebSocketService)
137
+ */
138
+ @OnMessage('ping')
139
+ onPing(event: WebSocketEvent) {
140
+ // Send response only to this client
141
+ event.client.socket.send(
142
+ JSON.stringify({
143
+ type: 'pong',
144
+ data: { time: Date.now() },
145
+ }),
146
+ );
147
+ }
148
+
149
+ /**
150
+ * 5. @OnMessage for subscription
151
+ */
152
+ @OnMessage('subscribe')
153
+ onSubscribe(event: WebSocketEvent) {
154
+ const topic = event.message?.data.topic;
155
+ console.log(`📌 Client ${event.client.id} subscribed to ${topic}`);
156
+
157
+ // Server will save the subscription automatically, no need to do anything!
158
+ // Just confirm
159
+ event.client.socket.send(
160
+ JSON.stringify({
161
+ type: 'subscribed',
162
+ topic,
163
+ data: { success: true },
164
+ }),
165
+ );
166
+ }
167
+ }
168
+ @Server({
169
+ controllers: [Socket],
170
+ websocket: { enabled: true },
171
+ })
172
+ @Use(middleware)
173
+ class App {}
174
+ ```
175
+
176
+ # Usage
177
+
178
+ You can use controllers and server functionality by importing controllers and creating server instances as shown in the examples above. Use your preferred testing framework to write unit and integration tests.
179
+
180
+ # Project Structure
181
+
182
+ - `quantum-flow/http` - Main application source code for HTTP servers.
183
+ - `quantum-flow/aws` - Main application source code AWS Lambda.
184
+ - `quantum-flow/core` - Core framework components like Controller and Endpoint.
185
+
186
+ ---
187
+
188
+ # Decorators
189
+
190
+ ### Server
191
+
192
+ Class decorator to configure the server with options like controllers, global middlewares, and interceptors.
193
+
194
+ ```typescript
195
+ @Server({ controllers: [RootController] })
196
+ class App {}
197
+ ```
198
+
199
+ ### Use
200
+
201
+ Class decorator to add global middlewares to the server.
202
+
203
+ ```typescript
204
+ @Use(middleware)
205
+ class App {}
33
206
  ```
34
207
 
35
- ## License
208
+ ### Intercept
209
+
210
+ Class decorator to add global interceptors to the server.
211
+
212
+ ```typescript
213
+ @Intercept(interceptor)
214
+ class App {}
215
+ ```
36
216
 
37
- MIT
217
+ ### Catch
218
+
219
+ Class decorator to set a global error handler for the server.
220
+
221
+ ```typescript
222
+ @Catch((error) => {
223
+ return { message: 'Internal Server Error' };
224
+ })
225
+ class App {}
226
+ ```
227
+
228
+ ### Port
229
+
230
+ Class decorator to set the server port.
231
+
232
+ ```typescript
233
+ @Port(3000)
234
+ class App {}
235
+ ```
236
+
237
+ ### Host
238
+
239
+ Class decorator to set the server host.
240
+
241
+ ```typescript
242
+ @Host('localhost')
243
+ class App {}
244
+ ```
245
+
246
+ ### Validate
247
+
248
+ Method or class decorator to validate request parameters (query, body, params, headers) against a DTO class using class-validator.
249
+
250
+ ```typescript
251
+ class UserDTO {
252
+ @IsEmail()
253
+ email: string;
254
+
255
+ @Length(6, 20)
256
+ password: string;
257
+ }
258
+
259
+ class UserController {
260
+ @POST('/')
261
+ async createUser(@Body(UserDTO) user: UserDTO, @Query() query) {
262
+ // Your logic here
263
+ }
264
+ }
265
+ ```
@@ -1,5 +1,5 @@
1
1
  import { APIGatewayProxyEvent, APIGatewayProxyResult, Context, Handler } from 'aws-lambda';
2
- import { LambdaRequest, LambdaResponse } from '@types';
2
+ import { LambdaRequest, LambdaResponse } from '../../types/index.js';
3
3
  export declare class LambdaAdapter {
4
4
  private static getHeaderValue;
5
5
  static toRequest(event: APIGatewayProxyEvent, context: Context): LambdaRequest;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LambdaAdapter = void 0;
4
- const _constants_1 = require("@constants");
5
- const _utils_1 = require("@utils");
4
+ const _constants_1 = require("../../constants.js");
5
+ const _utils_1 = require("../../utils/index.js");
6
6
  class LambdaAdapter {
7
7
  static getHeaderValue(headers, headerName) {
8
8
  const value = headers?.[headerName] || headers?.[headerName.toLowerCase()];
@@ -1,4 +1,4 @@
1
- import { ServerConfig } from '@types';
1
+ import { ServerConfig } from '../../types/index.js';
2
2
  import http from 'http';
3
3
  import { Socket } from './Socket';
4
4
  export declare class HttpServer extends Socket {
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HttpServer = void 0;
7
- const _constants_1 = require("@constants");
8
- const _utils_1 = require("@utils");
7
+ const _constants_1 = require("../../constants.js");
8
+ const _utils_1 = require("../../utils/index.js");
9
9
  const http_1 = __importDefault(require("http"));
10
10
  const Socket_1 = require("./Socket");
11
11
  const WebsocetService_1 = require("./websocket/WebsocetService");
@@ -1,4 +1,4 @@
1
- import { Conf, Interceptor } from '@types';
1
+ import { Conf, Interceptor } from '../../types/index.js';
2
2
  export declare function Server(config?: Conf): (target: any) => any;
3
3
  export declare function Use(middleware: any): (target: any) => any;
4
4
  export declare function Intercept(interceptor: Interceptor): (target: any) => any;
@@ -6,7 +6,7 @@ exports.Intercept = Intercept;
6
6
  exports.Catch = Catch;
7
7
  exports.Port = Port;
8
8
  exports.Host = Host;
9
- const _constants_1 = require("@constants");
9
+ const _constants_1 = require("../../constants.js");
10
10
  function Server(config = {}) {
11
11
  return function (target) {
12
12
  const existingConfig = Reflect.getMetadata(_constants_1.SERVER_CONFIG_KEY, target) || {};
@@ -1,4 +1,4 @@
1
- import { IWebSocketService } from '@types';
1
+ import { IWebSocketService } from '../../../types/index.js';
2
2
  import { WebSocketServer } from './WebsocketServer';
3
3
  export declare class WebSocketService implements IWebSocketService {
4
4
  private static instance;
@@ -1,4 +1,4 @@
1
- import { WebSocketClient } from '@types';
1
+ import { WebSocketClient } from '../../../types/index.js';
2
2
  import http from 'http';
3
3
  export declare class WebSocketServer {
4
4
  private wss;
@@ -1,4 +1,4 @@
1
- import { Interceptor, Middleware } from '@types';
1
+ import { Interceptor, Middleware } from '../types/index.js';
2
2
  import { ServerResponse } from 'http';
3
3
  import 'reflect-metadata';
4
4
  type ControllerClass = {
@@ -11,11 +11,32 @@ interface ControllerConfig {
11
11
  controllers?: ControllerClass[];
12
12
  interceptors?: Array<(...args: any[]) => any> | ((...args: any[]) => any);
13
13
  }
14
+ /**
15
+ * Class decorator to define a controller with optional configuration.
16
+ *
17
+ * This decorator can be used with a string prefix or a configuration object.
18
+ * It sets up metadata for route prefix, middlewares, sub-controllers, and interceptors.
19
+ *
20
+ * It wraps all controller methods to handle errors gracefully by catching exceptions
21
+ * and returning a standardized error response.
22
+ *
23
+ * The decorated controller class is extended with methods to:
24
+ * - execute controller methods with proper context and error handling
25
+ * - retrieve controller methods metadata
26
+ * - handle incoming requests by matching routes, applying middlewares and interceptors,
27
+ * and returning appropriate responses
28
+ *
29
+ * @param config - Either a string representing the route prefix or a configuration object
30
+ * containing prefix, middlewares, sub-controllers, and interceptors.
31
+ * @param middlewares - Additional interceptors to apply at the controller level.
32
+ *
33
+ * @returns A class decorator function that enhances the controller class.
34
+ */
14
35
  export declare function Controller(config: string | ControllerConfig, middlewares?: Array<Interceptor>): <T extends ControllerClass>(constructor: T) => {
15
36
  new (...args: any[]): {
16
37
  [x: string]: any;
17
- executeControllerMethod: (controller: import("@types").ControllerInstance, propertyName: string, payload: any, response?: ServerResponse) => Promise<any>;
18
- getControllerMethods: (controller: import("@types").ControllerInstance) => {
38
+ executeControllerMethod: (controller: import("../types/index.js").ControllerInstance, propertyName: string, payload: any, response?: ServerResponse) => Promise<any>;
39
+ getControllerMethods: (controller: import("../types/index.js").ControllerInstance) => {
19
40
  name: string;
20
41
  httpMethod: string;
21
42
  pattern: string;
@@ -2,9 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Controller = Controller;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
- const _constants_1 = require("@constants");
6
- const _utils_1 = require("@utils");
5
+ const _constants_1 = require("../constants.js");
6
+ const _utils_1 = require("../utils/index.js");
7
7
  require("reflect-metadata");
8
+ /**
9
+ * Class decorator to define a controller with optional configuration.
10
+ *
11
+ * This decorator can be used with a string prefix or a configuration object.
12
+ * It sets up metadata for route prefix, middlewares, sub-controllers, and interceptors.
13
+ *
14
+ * It wraps all controller methods to handle errors gracefully by catching exceptions
15
+ * and returning a standardized error response.
16
+ *
17
+ * The decorated controller class is extended with methods to:
18
+ * - execute controller methods with proper context and error handling
19
+ * - retrieve controller methods metadata
20
+ * - handle incoming requests by matching routes, applying middlewares and interceptors,
21
+ * and returning appropriate responses
22
+ *
23
+ * @param config - Either a string representing the route prefix or a configuration object
24
+ * containing prefix, middlewares, sub-controllers, and interceptors.
25
+ * @param middlewares - Additional interceptors to apply at the controller level.
26
+ *
27
+ * @returns A class decorator function that enhances the controller class.
28
+ */
8
29
  function Controller(config, middlewares = []) {
9
30
  // Handle both string and config object
10
31
  const routePrefix = typeof config === 'string' ? config : config.prefix;
@@ -78,7 +99,7 @@ function Controller(config, middlewares = []) {
78
99
  }
79
100
  handleRequest = async (request, response) => {
80
101
  const method = request.method;
81
- const path = (request.url.path ?? request.url.pathname ?? '').replace(/^\/+/, '');
102
+ const path = (request.url.path ?? request.url.pathname ?? '').replace(/^\/+/g, '');
82
103
  const baseInterceptors = Reflect.getMetadata(_constants_1.INTERCEPTORS, proto);
83
104
  const routePrefix = Reflect.getMetadata(_constants_1.ROUTE_PREFIX, proto) || '';
84
105
  const middlewares = Reflect.getMetadata(_constants_1.MIDDLEWARES, proto) || [];
@@ -98,7 +119,7 @@ function Controller(config, middlewares = []) {
98
119
  const fullPattern = [routePrefix, controllerPrefix, methodInfo.pattern]
99
120
  .filter(Boolean)
100
121
  .join('/')
101
- .replace(/\/+/g, '/');
122
+ .replace(/\/+ /g, '/');
102
123
  const pathParams = (0, _utils_1.matchRoute)(fullPattern, path);
103
124
  if (pathParams) {
104
125
  let payload = { ...request, params: pathParams };
@@ -133,7 +154,7 @@ function Controller(config, middlewares = []) {
133
154
  const fullPattern = [routePrefix, routePattern]
134
155
  .filter(Boolean)
135
156
  .join('/')
136
- .replace(/\/+/g, '/');
157
+ .replace(/\/+ /g, '/');
137
158
  const pathParams = (0, _utils_1.matchRoute)(fullPattern, path);
138
159
  if (pathParams) {
139
160
  let payload = { ...request, params: pathParams };
@@ -1,8 +1,64 @@
1
- import { Middleware } from '@types';
1
+ import { Middleware } from '../types/index.js';
2
+ /**
3
+ * Method decorator to define HTTP method and route pattern metadata on controller methods.
4
+ *
5
+ * This decorator maps a controller method to an HTTP endpoint by specifying the HTTP method
6
+ * (e.g., GET, POST) and an optional route pattern.
7
+ *
8
+ * It also allows attaching middlewares that will be applied when the endpoint is accessed.
9
+ *
10
+ * @param method - The HTTP method (e.g., 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'USE').
11
+ * @param pathPattern - Optional route pattern string to match the endpoint path.
12
+ * @param middlewares - Optional array of middlewares to apply to this endpoint.
13
+ *
14
+ * @returns A method decorator function.
15
+ */
2
16
  export declare function Endpoint(method: string, pathPattern?: string, middlewares?: Middleware[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
3
- export declare const GET: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
4
- export declare const POST: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
5
- export declare const PUT: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
6
- export declare const PATCH: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
7
- export declare const DELETE: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
8
- export declare const USE: (pathPattern?: string, middelwares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
17
+ /**
18
+ * Shortcut decorator for HTTP GET method.
19
+ *
20
+ * @param pathPattern - Optional route pattern string.
21
+ * @param middlewares - Optional array of middlewares.
22
+ * @returns Method decorator for GET endpoint.
23
+ */
24
+ export declare const GET: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
25
+ /**
26
+ * Shortcut decorator for HTTP POST method.
27
+ *
28
+ * @param pathPattern - Optional route pattern string.
29
+ * @param middlewares - Optional array of middlewares.
30
+ * @returns Method decorator for POST endpoint.
31
+ */
32
+ export declare const POST: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
33
+ /**
34
+ * Shortcut decorator for HTTP PUT method.
35
+ *
36
+ * @param pathPattern - Optional route pattern string.
37
+ * @param middlewares - Optional array of middlewares.
38
+ * @returns Method decorator for PUT endpoint.
39
+ */
40
+ export declare const PUT: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
41
+ /**
42
+ * Shortcut decorator for HTTP PATCH method.
43
+ *
44
+ * @param pathPattern - Optional route pattern string.
45
+ * @param middlewares - Optional array of middlewares.
46
+ * @returns Method decorator for PATCH endpoint.
47
+ */
48
+ export declare const PATCH: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
49
+ /**
50
+ * Shortcut decorator for HTTP DELETE method.
51
+ *
52
+ * @param pathPattern - Optional route pattern string.
53
+ * @param middlewares - Optional array of middlewares.
54
+ * @returns Method decorator for DELETE endpoint.
55
+ */
56
+ export declare const DELETE: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
57
+ /**
58
+ * Shortcut decorator for middleware usage on routes.
59
+ *
60
+ * @param pathPattern - Optional route pattern string.
61
+ * @param middlewares - Optional array of middlewares.
62
+ * @returns Method decorator for middleware usage.
63
+ */
64
+ export declare const USE: (pathPattern?: string, middlewares?: Middleware[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -2,7 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USE = exports.DELETE = exports.PATCH = exports.PUT = exports.POST = exports.GET = void 0;
4
4
  exports.Endpoint = Endpoint;
5
- const _constants_1 = require("@constants");
5
+ const _constants_1 = require("../constants.js");
6
+ /**
7
+ * Method decorator to define HTTP method and route pattern metadata on controller methods.
8
+ *
9
+ * This decorator maps a controller method to an HTTP endpoint by specifying the HTTP method
10
+ * (e.g., GET, POST) and an optional route pattern.
11
+ *
12
+ * It also allows attaching middlewares that will be applied when the endpoint is accessed.
13
+ *
14
+ * @param method - The HTTP method (e.g., 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'USE').
15
+ * @param pathPattern - Optional route pattern string to match the endpoint path.
16
+ * @param middlewares - Optional array of middlewares to apply to this endpoint.
17
+ *
18
+ * @returns A method decorator function.
19
+ */
6
20
  function Endpoint(method, pathPattern, middlewares) {
7
21
  return function (target, propertyKey, descriptor) {
8
22
  const originalMethod = descriptor.value;
@@ -17,27 +31,69 @@ function Endpoint(method, pathPattern, middlewares) {
17
31
  return descriptor;
18
32
  };
19
33
  }
20
- const GET = (pathPattern, middelwares) => {
21
- return Endpoint('GET', pathPattern, middelwares);
34
+ /**
35
+ * Shortcut decorator for HTTP GET method.
36
+ *
37
+ * @param pathPattern - Optional route pattern string.
38
+ * @param middlewares - Optional array of middlewares.
39
+ * @returns Method decorator for GET endpoint.
40
+ */
41
+ const GET = (pathPattern, middlewares) => {
42
+ return Endpoint('GET', pathPattern, middlewares);
22
43
  };
23
44
  exports.GET = GET;
24
- const POST = (pathPattern, middelwares) => {
25
- return Endpoint('POST', pathPattern, middelwares);
45
+ /**
46
+ * Shortcut decorator for HTTP POST method.
47
+ *
48
+ * @param pathPattern - Optional route pattern string.
49
+ * @param middlewares - Optional array of middlewares.
50
+ * @returns Method decorator for POST endpoint.
51
+ */
52
+ const POST = (pathPattern, middlewares) => {
53
+ return Endpoint('POST', pathPattern, middlewares);
26
54
  };
27
55
  exports.POST = POST;
28
- const PUT = (pathPattern, middelwares) => {
29
- return Endpoint('PUT', pathPattern, middelwares);
56
+ /**
57
+ * Shortcut decorator for HTTP PUT method.
58
+ *
59
+ * @param pathPattern - Optional route pattern string.
60
+ * @param middlewares - Optional array of middlewares.
61
+ * @returns Method decorator for PUT endpoint.
62
+ */
63
+ const PUT = (pathPattern, middlewares) => {
64
+ return Endpoint('PUT', pathPattern, middlewares);
30
65
  };
31
66
  exports.PUT = PUT;
32
- const PATCH = (pathPattern, middelwares) => {
33
- return Endpoint('PATCH', pathPattern, middelwares);
67
+ /**
68
+ * Shortcut decorator for HTTP PATCH method.
69
+ *
70
+ * @param pathPattern - Optional route pattern string.
71
+ * @param middlewares - Optional array of middlewares.
72
+ * @returns Method decorator for PATCH endpoint.
73
+ */
74
+ const PATCH = (pathPattern, middlewares) => {
75
+ return Endpoint('PATCH', pathPattern, middlewares);
34
76
  };
35
77
  exports.PATCH = PATCH;
36
- const DELETE = (pathPattern, middelwares) => {
37
- return Endpoint('DELETE', pathPattern, middelwares);
78
+ /**
79
+ * Shortcut decorator for HTTP DELETE method.
80
+ *
81
+ * @param pathPattern - Optional route pattern string.
82
+ * @param middlewares - Optional array of middlewares.
83
+ * @returns Method decorator for DELETE endpoint.
84
+ */
85
+ const DELETE = (pathPattern, middlewares) => {
86
+ return Endpoint('DELETE', pathPattern, middlewares);
38
87
  };
39
88
  exports.DELETE = DELETE;
40
- const USE = (pathPattern, middelwares) => {
41
- return Endpoint('USE', pathPattern, middelwares);
89
+ /**
90
+ * Shortcut decorator for middleware usage on routes.
91
+ *
92
+ * @param pathPattern - Optional route pattern string.
93
+ * @param middlewares - Optional array of middlewares.
94
+ * @returns Method decorator for middleware usage.
95
+ */
96
+ const USE = (pathPattern, middlewares) => {
97
+ return Endpoint('USE', pathPattern, middlewares);
42
98
  };
43
99
  exports.USE = USE;
@@ -1,4 +1,10 @@
1
- export { EndpointResponse, IController, Interceptor, Middleware, Request, Router, WebSocketClient, WebSocketEvent, WebSocketMessage, } from '@types';
1
+ /**
2
+ * Re-exports core decorators and types related to controllers and endpoints.
3
+ *
4
+ * This module provides centralized exports for controller and endpoint decorators,
5
+ * as well as related types and utility functions used throughout the core framework.
6
+ */
7
+ export { EndpointResponse, IController, Interceptor, Middleware, Request, Router, WebSocketClient, WebSocketEvent, WebSocketMessage, } from '../types/index.js';
2
8
  export * from './Controller';
3
9
  export * from './Endpoint';
4
10
  export * from './utils';