@heliosjs/core 1.0.2

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 (152) hide show
  1. package/README.md +540 -0
  2. package/dist/Controller.d.ts +54 -0
  3. package/dist/Controller.js +168 -0
  4. package/dist/Controller.js.map +1 -0
  5. package/dist/Endpoint.d.ts +73 -0
  6. package/dist/Endpoint.js +126 -0
  7. package/dist/Endpoint.js.map +1 -0
  8. package/dist/constants.d.ts +25 -0
  9. package/dist/constants.js +34 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/decorators.d.ts +94 -0
  12. package/dist/decorators.js +107 -0
  13. package/dist/decorators.js.map +1 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.js +29 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/types/core/common.d.ts +44 -0
  18. package/dist/types/core/common.js +15 -0
  19. package/dist/types/core/common.js.map +1 -0
  20. package/dist/types/core/controller.d.ts +78 -0
  21. package/dist/types/core/controller.js +3 -0
  22. package/dist/types/core/controller.js.map +1 -0
  23. package/dist/types/core/cors.d.ts +10 -0
  24. package/dist/types/core/cors.js +3 -0
  25. package/dist/types/core/cors.js.map +1 -0
  26. package/dist/types/core/error.d.ts +72 -0
  27. package/dist/types/core/error.js +19 -0
  28. package/dist/types/core/error.js.map +1 -0
  29. package/dist/types/core/index.d.ts +9 -0
  30. package/dist/types/core/index.js +26 -0
  31. package/dist/types/core/index.js.map +1 -0
  32. package/dist/types/core/multipart.d.ts +8 -0
  33. package/dist/types/core/multipart.js +3 -0
  34. package/dist/types/core/multipart.js.map +1 -0
  35. package/dist/types/core/request.d.ts +65 -0
  36. package/dist/types/core/request.js +3 -0
  37. package/dist/types/core/request.js.map +1 -0
  38. package/dist/types/core/response.d.ts +49 -0
  39. package/dist/types/core/response.js +3 -0
  40. package/dist/types/core/response.js.map +1 -0
  41. package/dist/types/core/sanitize.d.ts +8 -0
  42. package/dist/types/core/sanitize.js +3 -0
  43. package/dist/types/core/sanitize.js.map +1 -0
  44. package/dist/types/core/sse.d.ts +37 -0
  45. package/dist/types/core/sse.js +3 -0
  46. package/dist/types/core/sse.js.map +1 -0
  47. package/dist/types/ws/index.d.ts +50 -0
  48. package/dist/types/ws/index.js +3 -0
  49. package/dist/types/ws/index.js.map +1 -0
  50. package/dist/utils/core/controller.d.ts +25 -0
  51. package/dist/utils/core/controller.js +219 -0
  52. package/dist/utils/core/controller.js.map +1 -0
  53. package/dist/utils/core/cors.d.ts +8 -0
  54. package/dist/utils/core/cors.js +128 -0
  55. package/dist/utils/core/cors.js.map +1 -0
  56. package/dist/utils/core/endpoint.d.ts +3 -0
  57. package/dist/utils/core/endpoint.js +28 -0
  58. package/dist/utils/core/endpoint.js.map +1 -0
  59. package/dist/utils/core/error/apperror.d.ts +31 -0
  60. package/dist/utils/core/error/apperror.js +131 -0
  61. package/dist/utils/core/error/apperror.js.map +1 -0
  62. package/dist/utils/core/error/authorizations.d.ts +7 -0
  63. package/dist/utils/core/error/authorizations.js +17 -0
  64. package/dist/utils/core/error/authorizations.js.map +1 -0
  65. package/dist/utils/core/error/base.d.ts +20 -0
  66. package/dist/utils/core/error/base.js +52 -0
  67. package/dist/utils/core/error/base.js.map +1 -0
  68. package/dist/utils/core/error/dependencyFailed.d.ts +7 -0
  69. package/dist/utils/core/error/dependencyFailed.js +17 -0
  70. package/dist/utils/core/error/dependencyFailed.js.map +1 -0
  71. package/dist/utils/core/error/duplicateEntry.d.ts +7 -0
  72. package/dist/utils/core/error/duplicateEntry.js +17 -0
  73. package/dist/utils/core/error/duplicateEntry.js.map +1 -0
  74. package/dist/utils/core/error/forbidden.d.ts +7 -0
  75. package/dist/utils/core/error/forbidden.js +17 -0
  76. package/dist/utils/core/error/forbidden.js.map +1 -0
  77. package/dist/utils/core/error/helpers.d.ts +8 -0
  78. package/dist/utils/core/error/helpers.js +144 -0
  79. package/dist/utils/core/error/helpers.js.map +1 -0
  80. package/dist/utils/core/error/index.d.ts +12 -0
  81. package/dist/utils/core/error/index.js +29 -0
  82. package/dist/utils/core/error/index.js.map +1 -0
  83. package/dist/utils/core/error/invalidState.d.ts +7 -0
  84. package/dist/utils/core/error/invalidState.js +17 -0
  85. package/dist/utils/core/error/invalidState.js.map +1 -0
  86. package/dist/utils/core/error/notfound.d.ts +7 -0
  87. package/dist/utils/core/error/notfound.js +18 -0
  88. package/dist/utils/core/error/notfound.js.map +1 -0
  89. package/dist/utils/core/error/rateLimit.d.ts +7 -0
  90. package/dist/utils/core/error/rateLimit.js +17 -0
  91. package/dist/utils/core/error/rateLimit.js.map +1 -0
  92. package/dist/utils/core/error/serviceUnavailable.d.ts +7 -0
  93. package/dist/utils/core/error/serviceUnavailable.js +17 -0
  94. package/dist/utils/core/error/serviceUnavailable.js.map +1 -0
  95. package/dist/utils/core/error/validation.d.ts +10 -0
  96. package/dist/utils/core/error/validation.js +20 -0
  97. package/dist/utils/core/error/validation.js.map +1 -0
  98. package/dist/utils/core/headers.d.ts +2 -0
  99. package/dist/utils/core/headers.js +10 -0
  100. package/dist/utils/core/headers.js.map +1 -0
  101. package/dist/utils/core/helper.d.ts +6 -0
  102. package/dist/utils/core/helper.js +66 -0
  103. package/dist/utils/core/helper.js.map +1 -0
  104. package/dist/utils/core/index.d.ts +10 -0
  105. package/dist/utils/core/index.js +27 -0
  106. package/dist/utils/core/index.js.map +1 -0
  107. package/dist/utils/core/multipart.d.ts +9 -0
  108. package/dist/utils/core/multipart.js +207 -0
  109. package/dist/utils/core/multipart.js.map +1 -0
  110. package/dist/utils/core/request.d.ts +100 -0
  111. package/dist/utils/core/request.js +218 -0
  112. package/dist/utils/core/request.js.map +1 -0
  113. package/dist/utils/core/response.d.ts +48 -0
  114. package/dist/utils/core/response.js +269 -0
  115. package/dist/utils/core/response.js.map +1 -0
  116. package/dist/utils/core/routeWalker.d.ts +2 -0
  117. package/dist/utils/core/routeWalker.js +115 -0
  118. package/dist/utils/core/routeWalker.js.map +1 -0
  119. package/dist/utils/core/sanitize.d.ts +30 -0
  120. package/dist/utils/core/sanitize.js +134 -0
  121. package/dist/utils/core/sanitize.js.map +1 -0
  122. package/dist/utils/shared/index.d.ts +2 -0
  123. package/dist/utils/shared/index.js +19 -0
  124. package/dist/utils/shared/index.js.map +1 -0
  125. package/dist/utils/shared/parsers.d.ts +11 -0
  126. package/dist/utils/shared/parsers.js +133 -0
  127. package/dist/utils/shared/parsers.js.map +1 -0
  128. package/dist/utils/shared/validate.d.ts +1 -0
  129. package/dist/utils/shared/validate.js +41 -0
  130. package/dist/utils/shared/validate.js.map +1 -0
  131. package/dist/utils/socket/index.d.ts +3 -0
  132. package/dist/utils/socket/index.js +20 -0
  133. package/dist/utils/socket/index.js.map +1 -0
  134. package/dist/utils/socket/server.d.ts +33 -0
  135. package/dist/utils/socket/server.js +218 -0
  136. package/dist/utils/socket/server.js.map +1 -0
  137. package/dist/utils/socket/service.d.ts +20 -0
  138. package/dist/utils/socket/service.js +42 -0
  139. package/dist/utils/socket/service.js.map +1 -0
  140. package/dist/utils/socket/socket.d.ts +16 -0
  141. package/dist/utils/socket/socket.js +33 -0
  142. package/dist/utils/socket/socket.js.map +1 -0
  143. package/dist/utils/sse/index.d.ts +2 -0
  144. package/dist/utils/sse/index.js +19 -0
  145. package/dist/utils/sse/index.js.map +1 -0
  146. package/dist/utils/sse/server.d.ts +14 -0
  147. package/dist/utils/sse/server.js +85 -0
  148. package/dist/utils/sse/server.js.map +1 -0
  149. package/dist/utils/sse/service.d.ts +17 -0
  150. package/dist/utils/sse/service.js +40 -0
  151. package/dist/utils/sse/service.js.map +1 -0
  152. package/package.json +37 -0
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Controller = Controller;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ require("reflect-metadata");
6
+ const constants_1 = require("./constants");
7
+ const core_1 = require("./utils/core");
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
+ */
29
+ function Controller(config, middlewares = []) {
30
+ // Handle both string and config object
31
+ const routePrefix = typeof config === 'string' ? config : config.prefix;
32
+ const controllers = typeof config === 'object' ? config.controllers : undefined;
33
+ const controllerMiddlewares = typeof config === 'object' ? [...(config.middlewares || []), ...middlewares] : middlewares;
34
+ let interceptor = typeof config === 'object' && typeof config.interceptor === 'function' && config.interceptor;
35
+ return function (constructor) {
36
+ const proto = constructor.prototype;
37
+ Reflect.defineMetadata('controller:name', constructor.name, proto);
38
+ Reflect.defineMetadata(constants_1.ROUTE_PREFIX, routePrefix, proto);
39
+ Reflect.defineMetadata(constants_1.MIDDLEWARES, controllerMiddlewares, proto);
40
+ Reflect.defineMetadata(constants_1.CONTROLLERS, controllers || [], proto);
41
+ Reflect.defineMetadata(constants_1.INTERCEPTOR, interceptor, proto);
42
+ for (const key of Object.getOwnPropertyNames(proto)) {
43
+ if (key === 'constructor')
44
+ continue;
45
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
46
+ if (!descriptor || typeof descriptor.value !== 'function')
47
+ continue;
48
+ Object.defineProperty(proto, key, descriptor);
49
+ }
50
+ return class extends constructor {
51
+ ws;
52
+ sse;
53
+ executeControllerMethod = core_1.executeControllerMethod;
54
+ getControllerMethods = core_1.getControllerMethods;
55
+ routePrefix;
56
+ middlewares = [];
57
+ interceptor;
58
+ subControllers = [];
59
+ errorHandler;
60
+ cors;
61
+ sanitizers;
62
+ constructor(...args) {
63
+ super(...args);
64
+ this.lookupWS();
65
+ this.lookupSSE();
66
+ }
67
+ handleRequest = async (request, response) => {
68
+ const middlewares = this.middlewares
69
+ .concat(Reflect.getMetadata(constants_1.MIDDLEWARES, proto))
70
+ .concat(Reflect.getMetadata(constants_1.USE_MIDDLEWARE, constructor))
71
+ .filter((el) => !!el);
72
+ const routePrefix = this.routePrefix ?? Reflect.getMetadata(constants_1.ROUTE_PREFIX, proto) ?? '/';
73
+ const interceptor = this.interceptor ?? Reflect.getMetadata(constants_1.INTERCEPTOR, proto);
74
+ const subControllers = this.subControllers.concat(Reflect.getMetadata(constants_1.CONTROLLERS, proto)) ?? [];
75
+ const errorHandler = this.errorHandler ?? Reflect.getMetadata(constants_1.CATCH, constructor);
76
+ const cors = this.cors ?? Reflect.getMetadata(constants_1.CORS_METADATA, proto);
77
+ const sanitizers = this.sanitizers ?? Reflect.getMetadata(constants_1.SANITIZE, proto) ?? [];
78
+ const context = {
79
+ controllerInstance: this,
80
+ controllerMeta: {
81
+ routePrefix,
82
+ middlewares,
83
+ interceptor,
84
+ subControllers,
85
+ errorHandler,
86
+ cors,
87
+ sanitizers,
88
+ },
89
+ path: (request.requestUrl.pathname ?? '').replace(/^\/+/g, ''),
90
+ method: request.method.toUpperCase(),
91
+ middlewareChain: [],
92
+ interceptorChain: [],
93
+ sanitizersChain: [],
94
+ corsChain: [cors],
95
+ errorHandlerChain: [errorHandler],
96
+ subPath: routePrefix,
97
+ };
98
+ try {
99
+ const done = await (0, core_1.routeWalker)(context, request, response);
100
+ if (!done) {
101
+ response.status = 404;
102
+ response.data = 'Route not found';
103
+ return false;
104
+ }
105
+ return true;
106
+ }
107
+ catch (err) {
108
+ response.error(err);
109
+ return true;
110
+ }
111
+ };
112
+ lookupWS() {
113
+ const connection = this.getWSHandlers('connection');
114
+ const message = this.getWSHandlers('message');
115
+ const error = this.getWSHandlers('error');
116
+ const close = this.getWSHandlers('close');
117
+ const topics = this.getWSHandlers('topics');
118
+ if ([...connection, ...message, ...error, ...close, ...topics].length === 0) {
119
+ return;
120
+ }
121
+ this.ws = { handlers: { connection, message, close, error }, topics };
122
+ }
123
+ lookupSSE() {
124
+ const connection = this.getSSEHandlers('connection');
125
+ const error = this.getSSEHandlers('error');
126
+ const close = this.getSSEHandlers('close');
127
+ if ([...connection, ...error, ...close].length === 0) {
128
+ return;
129
+ }
130
+ this.sse = { handlers: { connection, close, error } };
131
+ }
132
+ getSSEController() {
133
+ return {
134
+ instance: this,
135
+ handlers: {
136
+ connection: this.getSSEHandlers('connection'),
137
+ close: this.getSSEHandlers('close'),
138
+ error: this.getSSEHandlers('error'),
139
+ },
140
+ };
141
+ }
142
+ getWSHandlers(type) {
143
+ const handlers = Reflect.getMetadata(constants_1.WS_HANDLER, this.constructor) || [];
144
+ return this.typedHandlers(handlers, type);
145
+ }
146
+ getSSEHandlers(type) {
147
+ const handlers = Reflect.getMetadata(constants_1.SSE_METADATA_KEY, this.constructor) || [];
148
+ return this.typedHandlers(handlers, type);
149
+ }
150
+ getWSTopics() {
151
+ const topics = Reflect.getMetadata(constants_1.WS_TOPIC_KEY, this.constructor) || [];
152
+ return topics.map((t) => ({
153
+ ...t,
154
+ fn: this[t.method].bind(this),
155
+ }));
156
+ }
157
+ typedHandlers = (handlers, type) => {
158
+ return handlers
159
+ .filter((h) => h.type === type)
160
+ .map((h) => ({
161
+ ...h,
162
+ fn: this[h.method].bind(this),
163
+ }));
164
+ };
165
+ };
166
+ };
167
+ }
168
+ //# sourceMappingURL=Controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Controller.js","sourceRoot":"","sources":["../src/Controller.ts"],"names":[],"mappings":";;AAqDA,gCAqKC;AA1ND,uDAAuD;AACvD,4BAA0B;AAC1B,2CAYqB;AAgBrB,uCAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,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AAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;qBACnC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC;oBAChB,GAAG,CAAC;oBACJ,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC9B,CAAC,CAAC,CAAC;YACR,CAAC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { HTTP_METHODS, MiddlewareCB } from './types/core';
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', 'ANY').
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
+ */
16
+ export declare function Endpoint(method: HTTP_METHODS, pathPattern?: string, middlewares?: MiddlewareCB[]): (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?: MiddlewareCB[]) => (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?: MiddlewareCB[]) => (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?: MiddlewareCB[]) => (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?: MiddlewareCB[]) => (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?: MiddlewareCB[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
57
+ /**
58
+ * Shortcut decorator for HTTP OPTIONS method.
59
+ *
60
+ * @param pathPattern - Optional route pattern string.
61
+ * @param middlewares - Optional array of middlewares.
62
+ * @returns Method decorator for DELETE endpoint.
63
+ */
64
+ export declare const OPTIONS: (pathPattern?: string, middlewares?: MiddlewareCB[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
65
+ /**
66
+ * Shortcut decorator for HTTP HEAD method.
67
+ *
68
+ * @param pathPattern - Optional route pattern string.
69
+ * @param middlewares - Optional array of middlewares.
70
+ * @returns Method decorator for DELETE endpoint.
71
+ */
72
+ export declare const HEAD: (pathPattern?: string, middlewares?: MiddlewareCB[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
73
+ export declare function ANY(middlewares?: MiddlewareCB[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HEAD = exports.OPTIONS = exports.DELETE = exports.PATCH = exports.PUT = exports.POST = exports.GET = void 0;
4
+ exports.Endpoint = Endpoint;
5
+ exports.ANY = ANY;
6
+ const constants_1 = require("./constants");
7
+ const core_1 = require("./types/core");
8
+ /**
9
+ * Method decorator to define HTTP method and route pattern metadata on controller methods.
10
+ *
11
+ * This decorator maps a controller method to an HTTP endpoint by specifying the HTTP method
12
+ * (e.g., GET, POST) and an optional route pattern.
13
+ *
14
+ * It also allows attaching middlewares that will be applied when the endpoint is accessed.
15
+ *
16
+ * @param method - The HTTP method (e.g., 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'ANY').
17
+ * @param pathPattern - Optional route pattern string to match the endpoint path.
18
+ * @param middlewares - Optional array of middlewares to apply to this endpoint.
19
+ *
20
+ * @returns A method decorator function.
21
+ */
22
+ function Endpoint(method, pathPattern, middlewares) {
23
+ return function (target, propertyKey, descriptor) {
24
+ const originalMethod = descriptor.value;
25
+ if (!originalMethod) {
26
+ console.warn('❌ originalMethod is undefined!');
27
+ return descriptor;
28
+ }
29
+ if (method && pathPattern) {
30
+ Reflect.defineMetadata(constants_1.ENDPOINT, [method, pathPattern, middlewares], target, propertyKey);
31
+ }
32
+ return descriptor;
33
+ };
34
+ }
35
+ /**
36
+ * Shortcut decorator for HTTP GET method.
37
+ *
38
+ * @param pathPattern - Optional route pattern string.
39
+ * @param middlewares - Optional array of middlewares.
40
+ * @returns Method decorator for GET endpoint.
41
+ */
42
+ const GET = (pathPattern, middlewares) => {
43
+ return Endpoint(core_1.HTTP_METHODS.GET, pathPattern, middlewares);
44
+ };
45
+ exports.GET = GET;
46
+ /**
47
+ * Shortcut decorator for HTTP POST method.
48
+ *
49
+ * @param pathPattern - Optional route pattern string.
50
+ * @param middlewares - Optional array of middlewares.
51
+ * @returns Method decorator for POST endpoint.
52
+ */
53
+ const POST = (pathPattern, middlewares) => {
54
+ return Endpoint(core_1.HTTP_METHODS.POST, pathPattern, middlewares);
55
+ };
56
+ exports.POST = POST;
57
+ /**
58
+ * Shortcut decorator for HTTP PUT method.
59
+ *
60
+ * @param pathPattern - Optional route pattern string.
61
+ * @param middlewares - Optional array of middlewares.
62
+ * @returns Method decorator for PUT endpoint.
63
+ */
64
+ const PUT = (pathPattern, middlewares) => {
65
+ return Endpoint(core_1.HTTP_METHODS.PUT, pathPattern, middlewares);
66
+ };
67
+ exports.PUT = PUT;
68
+ /**
69
+ * Shortcut decorator for HTTP PATCH method.
70
+ *
71
+ * @param pathPattern - Optional route pattern string.
72
+ * @param middlewares - Optional array of middlewares.
73
+ * @returns Method decorator for PATCH endpoint.
74
+ */
75
+ const PATCH = (pathPattern, middlewares) => {
76
+ return Endpoint(core_1.HTTP_METHODS.PATCH, pathPattern, middlewares);
77
+ };
78
+ exports.PATCH = PATCH;
79
+ /**
80
+ * Shortcut decorator for HTTP DELETE method.
81
+ *
82
+ * @param pathPattern - Optional route pattern string.
83
+ * @param middlewares - Optional array of middlewares.
84
+ * @returns Method decorator for DELETE endpoint.
85
+ */
86
+ const DELETE = (pathPattern, middlewares) => {
87
+ return Endpoint(core_1.HTTP_METHODS.DELETE, pathPattern, middlewares);
88
+ };
89
+ exports.DELETE = DELETE;
90
+ /**
91
+ * Shortcut decorator for HTTP OPTIONS method.
92
+ *
93
+ * @param pathPattern - Optional route pattern string.
94
+ * @param middlewares - Optional array of middlewares.
95
+ * @returns Method decorator for DELETE endpoint.
96
+ */
97
+ const OPTIONS = (pathPattern, middlewares) => {
98
+ return Endpoint(core_1.HTTP_METHODS.OPTIONS, pathPattern, middlewares);
99
+ };
100
+ exports.OPTIONS = OPTIONS;
101
+ /**
102
+ * Shortcut decorator for HTTP HEAD method.
103
+ *
104
+ * @param pathPattern - Optional route pattern string.
105
+ * @param middlewares - Optional array of middlewares.
106
+ * @returns Method decorator for DELETE endpoint.
107
+ */
108
+ const HEAD = (pathPattern, middlewares) => {
109
+ return Endpoint(core_1.HTTP_METHODS.HEAD, pathPattern, middlewares);
110
+ };
111
+ exports.HEAD = HEAD;
112
+ // /**
113
+ // * Shortcut decorator for middleware usage on routes.
114
+ // *
115
+ // * @param pathPattern - Optional route pattern string.
116
+ // * @param middlewares - Optional array of middlewares.
117
+ // * @returns Method decorator for middleware usage.
118
+ // */
119
+ function ANY(middlewares) {
120
+ return function (target, propertyKey, descriptor) {
121
+ Reflect.defineMetadata(constants_1.ENDPOINT, ['ANY', '/'], target, propertyKey);
122
+ Reflect.defineMetadata(constants_1.MIDDLEWARES, middlewares || [], target, propertyKey);
123
+ return descriptor;
124
+ };
125
+ }
126
+ //# sourceMappingURL=Endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../src/Endpoint.ts"],"names":[],"mappings":";;;AAiBA,4BAeC;AAqFD,kBAMC;AA3HD,2CAAoD;AACpD,uCAA0D;AAE1D;;;;;;;;;;;;;GAaG;AACH,SAAgB,QAAQ,CAAC,MAAoB,EAAE,WAAoB,EAAE,WAA4B;IAC/F,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAC/E,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;YAC/C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,MAAM,IAAI,WAAW,EAAE,CAAC;YAC1B,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5F,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACI,MAAM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G,CAAC,WAAoB,EAAE,WAA4B,EAAE,EAAE;IACzE,OAAO,QAAQ,CAAC,mBAAY,CAAC,IAAI,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf;AAEF,MAAM;AACN,wDAAwD;AACxD,KAAK;AACL,yDAAyD;AACzD,yDAAyD;AACzD,qDAAqD;AACrD,MAAM;AACN,SAAgB,GAAG,CAAC,WAA4B;IAC9C,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;QAC/E,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,OAAO,CAAC,cAAc,CAAC,uBAAW,EAAE,WAAW,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5E,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ export declare const PARAM_METADATA_KEY = "design:parameters";
2
+ export declare const APP_METADATA_KEY = "app:configuration";
3
+ export declare const ROUTE_PREFIX = "route:prefix";
4
+ export declare const ROUTE_MIDDLEWARES = "route:middlewares";
5
+ export declare const MIDDLEWARES = "controller:middlewares";
6
+ export declare const CONTROLLERS = "app:controllers";
7
+ export declare const INTERCEPTOR = "app:interceptors";
8
+ export declare const ENDPOINT = "route:endpoints";
9
+ export declare const OK_METADATA_KEY = "custom:ok";
10
+ export declare const SERVER_CONFIG_KEY = "server:config";
11
+ export declare const USE_MIDDLEWARE = "controller:usemiddleware";
12
+ export declare const WS_HANDLER = "websocket:handler";
13
+ export declare const WS_TOPIC_KEY = "websocket:topic";
14
+ export declare const WS_SERVICE_KEY = "websocket:service";
15
+ export declare const INTECEPT = "server:intercept";
16
+ export declare const CATCH = "server:catch";
17
+ export declare const SANITIZE = "action:sanitize";
18
+ export declare const STOPPED = "\n\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n\u2551 \uD83D\uDC4B Server stopped \u2551\n\u2551 \uD83D\uDCCA Status: STOPPED \u2551\n\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n ";
19
+ export declare const OK_STATUSES: number[];
20
+ export declare const TO_VALIDATE: string[];
21
+ export declare const CORS_METADATA = "cors:config";
22
+ export declare const SSE_METADATA_KEY = "sse:handlers";
23
+ export declare const SSE_TOPIC_KEY = "sse:topics";
24
+ export declare const SSE_SERVICE_KEY = "sse:service";
25
+ export declare const STATIC_METADATA_KEY = "static:config";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STATIC_METADATA_KEY = exports.SSE_SERVICE_KEY = exports.SSE_TOPIC_KEY = exports.SSE_METADATA_KEY = exports.CORS_METADATA = exports.TO_VALIDATE = exports.OK_STATUSES = exports.STOPPED = exports.SANITIZE = exports.CATCH = exports.INTECEPT = exports.WS_SERVICE_KEY = exports.WS_TOPIC_KEY = exports.WS_HANDLER = exports.USE_MIDDLEWARE = exports.SERVER_CONFIG_KEY = exports.OK_METADATA_KEY = exports.ENDPOINT = exports.INTERCEPTOR = exports.CONTROLLERS = exports.MIDDLEWARES = exports.ROUTE_MIDDLEWARES = exports.ROUTE_PREFIX = exports.APP_METADATA_KEY = exports.PARAM_METADATA_KEY = void 0;
4
+ exports.PARAM_METADATA_KEY = 'design:parameters';
5
+ exports.APP_METADATA_KEY = 'app:configuration';
6
+ exports.ROUTE_PREFIX = 'route:prefix';
7
+ exports.ROUTE_MIDDLEWARES = 'route:middlewares';
8
+ exports.MIDDLEWARES = 'controller:middlewares';
9
+ exports.CONTROLLERS = 'app:controllers';
10
+ exports.INTERCEPTOR = 'app:interceptors';
11
+ exports.ENDPOINT = 'route:endpoints';
12
+ exports.OK_METADATA_KEY = 'custom:ok';
13
+ exports.SERVER_CONFIG_KEY = 'server:config';
14
+ exports.USE_MIDDLEWARE = 'controller:usemiddleware';
15
+ exports.WS_HANDLER = 'websocket:handler';
16
+ exports.WS_TOPIC_KEY = 'websocket:topic';
17
+ exports.WS_SERVICE_KEY = 'websocket:service';
18
+ exports.INTECEPT = 'server:intercept';
19
+ exports.CATCH = 'server:catch';
20
+ exports.SANITIZE = 'action:sanitize';
21
+ exports.STOPPED = `
22
+ ╔════════════════════════════════════════╗
23
+ ║ 👋 Server stopped ║
24
+ ║ 📊 Status: STOPPED ║
25
+ ╚════════════════════════════════════════╝
26
+ `;
27
+ exports.OK_STATUSES = [200, 201, 202, 203, 204, 205, 206, 207, 208, 226];
28
+ exports.TO_VALIDATE = ['headers', 'params', 'multipart', 'query', 'body'];
29
+ exports.CORS_METADATA = 'cors:config';
30
+ exports.SSE_METADATA_KEY = 'sse:handlers';
31
+ exports.SSE_TOPIC_KEY = 'sse:topics';
32
+ exports.SSE_SERVICE_KEY = 'sse:service';
33
+ exports.STATIC_METADATA_KEY = 'static:config';
34
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,gBAAgB,GAAG,mBAAmB,CAAC;AACvC,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AACxC,QAAA,WAAW,GAAG,wBAAwB,CAAC;AACvC,QAAA,WAAW,GAAG,iBAAiB,CAAC;AAChC,QAAA,WAAW,GAAG,kBAAkB,CAAC;AACjC,QAAA,QAAQ,GAAG,iBAAiB,CAAC;AAC7B,QAAA,eAAe,GAAG,WAAW,CAAC;AAE9B,QAAA,iBAAiB,GAAG,eAAe,CAAC;AACpC,QAAA,cAAc,GAAG,0BAA0B,CAAC;AAE5C,QAAA,UAAU,GAAG,mBAAmB,CAAC;AACjC,QAAA,YAAY,GAAG,iBAAiB,CAAC;AACjC,QAAA,cAAc,GAAG,mBAAmB,CAAC;AACrC,QAAA,QAAQ,GAAG,kBAAkB,CAAC;AAC9B,QAAA,KAAK,GAAG,cAAc,CAAC;AACvB,QAAA,QAAQ,GAAG,iBAAiB,CAAC;AAE7B,QAAA,OAAO,GAAG;;;;;WAKZ,CAAC;AAEC,QAAA,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACjE,QAAA,WAAW,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAElE,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9B,QAAA,gBAAgB,GAAG,cAAc,CAAC;AAClC,QAAA,aAAa,GAAG,YAAY,CAAC;AAC7B,QAAA,eAAe,GAAG,aAAa,CAAC;AAChC,QAAA,mBAAmB,GAAG,eAAe,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Parameter decorator to extract and validate the request body.
3
+ *
4
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
5
+ *
6
+ * Usage:
7
+ * ```ts
8
+ * @Body() body: any
9
+ * @Body(UserDto) user: UserDto
10
+ * ```
11
+ */
12
+ export declare const Body: (dto?: any) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
13
+ /**
14
+ * Parameter decorator to extract route parameters.
15
+ *
16
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
17
+ * @param {string} [name] - Optional name of the parameter to extract.
18
+ *
19
+ * Usage:
20
+ * ```ts
21
+ * @Params() params: any
22
+ * @Params('id') id: string
23
+ * @Params(UserParamsDto) params: UserParamsDto
24
+ * ```
25
+ */
26
+ export declare const Params: (dto?: any, name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
27
+ /**
28
+ * Parameter decorator to extract query parameters.
29
+ *
30
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
31
+ * @param {string} [name] - Optional name of the query parameter to extract.
32
+ *
33
+ * Usage:
34
+ * ```ts
35
+ * @Query() query: any
36
+ * @Query('search') search: string
37
+ * @Query(SearchDto) query: SearchDto
38
+ * ```
39
+ */
40
+ export declare const Query: (dto?: any, name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
41
+ /**
42
+ * Parameter decorator to inject the entire request object.
43
+ *
44
+ * Usage:
45
+ * ```ts
46
+ * @Request() req: Request
47
+ * ```
48
+ */
49
+ export declare const Request: () => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
50
+ /**
51
+ * Parameter decorator to extract headers from the request.
52
+ *
53
+ * @param {string} [name] - Optional name of the header to extract.
54
+ *
55
+ * Usage:
56
+ * ```ts
57
+ * @Headers() headers: Headers
58
+ * @Headers('authorization') authHeader: string
59
+ * ```
60
+ */
61
+ export declare const Headers: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
62
+ /**
63
+ * Parameter decorator to extract cookies from the request.
64
+ *
65
+ * @param {string} [name] - Optional name of the cookie to extract.
66
+ *
67
+ * Usage:
68
+ * ```ts
69
+ * @Cookies() cookies: any
70
+ * @Cookies('sessionId') sessionId: string
71
+ * ```
72
+ */
73
+ export declare const Cookies: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
74
+ /**
75
+ * Parameter decorator to extract multipart form data.
76
+ *
77
+ * @param {string} [name] - Optional name of the multipart field to extract.
78
+ *
79
+ * Usage:
80
+ * ```ts
81
+ * @Files() multipartData: any
82
+ * @Files('file') file: File
83
+ * ```
84
+ */
85
+ export declare const Files: (name?: string) => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
86
+ /**
87
+ * Parameter decorator to inject the response object.
88
+ *
89
+ * Usage:
90
+ * ```ts
91
+ * @Response() res: Response
92
+ * ```
93
+ */
94
+ export declare const Response: () => (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Response = exports.Files = exports.Cookies = exports.Headers = exports.Request = exports.Query = exports.Params = exports.Body = void 0;
4
+ const core_1 = require("./utils/core");
5
+ /**
6
+ * Parameter decorator to extract and validate the request body.
7
+ *
8
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
9
+ *
10
+ * Usage:
11
+ * ```ts
12
+ * @Body() body: any
13
+ * @Body(UserDto) user: UserDto
14
+ * ```
15
+ */
16
+ const Body = (dto) => (0, core_1.createParamDecorator)('body', dto);
17
+ exports.Body = Body;
18
+ /**
19
+ * Parameter decorator to extract route parameters.
20
+ *
21
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
22
+ * @param {string} [name] - Optional name of the parameter to extract.
23
+ *
24
+ * Usage:
25
+ * ```ts
26
+ * @Params() params: any
27
+ * @Params('id') id: string
28
+ * @Params(UserParamsDto) params: UserParamsDto
29
+ * ```
30
+ */
31
+ const Params = (dto, name) => (0, core_1.createParamDecorator)('params', typeof dto == 'string' ? undefined : dto, (name ?? typeof dto == 'string') ? dto : name);
32
+ exports.Params = Params;
33
+ /**
34
+ * Parameter decorator to extract query parameters.
35
+ *
36
+ * @param {any} [dto] - Optional DTO class for validation and transformation.
37
+ * @param {string} [name] - Optional name of the query parameter to extract.
38
+ *
39
+ * Usage:
40
+ * ```ts
41
+ * @Query() query: any
42
+ * @Query('search') search: string
43
+ * @Query(SearchDto) query: SearchDto
44
+ * ```
45
+ */
46
+ const Query = (dto, name) => (0, core_1.createParamDecorator)('query', typeof dto == 'string' ? undefined : dto, typeof dto == 'string' ? dto : name);
47
+ exports.Query = Query;
48
+ /**
49
+ * Parameter decorator to inject the entire request object.
50
+ *
51
+ * Usage:
52
+ * ```ts
53
+ * @Request() req: Request
54
+ * ```
55
+ */
56
+ const Request = () => (0, core_1.createParamDecorator)('request');
57
+ exports.Request = Request;
58
+ /**
59
+ * Parameter decorator to extract headers from the request.
60
+ *
61
+ * @param {string} [name] - Optional name of the header to extract.
62
+ *
63
+ * Usage:
64
+ * ```ts
65
+ * @Headers() headers: Headers
66
+ * @Headers('authorization') authHeader: string
67
+ * ```
68
+ */
69
+ const Headers = (name) => (0, core_1.createParamDecorator)('headers', undefined, name);
70
+ exports.Headers = Headers;
71
+ /**
72
+ * Parameter decorator to extract cookies from the request.
73
+ *
74
+ * @param {string} [name] - Optional name of the cookie to extract.
75
+ *
76
+ * Usage:
77
+ * ```ts
78
+ * @Cookies() cookies: any
79
+ * @Cookies('sessionId') sessionId: string
80
+ * ```
81
+ */
82
+ const Cookies = (name) => (0, core_1.createParamDecorator)('cookies', undefined, name);
83
+ exports.Cookies = Cookies;
84
+ /**
85
+ * Parameter decorator to extract multipart form data.
86
+ *
87
+ * @param {string} [name] - Optional name of the multipart field to extract.
88
+ *
89
+ * Usage:
90
+ * ```ts
91
+ * @Files() multipartData: any
92
+ * @Files('file') file: File
93
+ * ```
94
+ */
95
+ const Files = (name) => (0, core_1.createParamDecorator)('multipart', undefined, name);
96
+ exports.Files = Files;
97
+ /**
98
+ * Parameter decorator to inject the response object.
99
+ *
100
+ * Usage:
101
+ * ```ts
102
+ * @Response() res: Response
103
+ * ```
104
+ */
105
+ const Response = () => (0, core_1.createParamDecorator)('response');
106
+ exports.Response = Response;
107
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAEpD;;;;;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