@catbee/utils 0.0.8-next.0 → 0.0.8-rc.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 (284) hide show
  1. package/README.md +1 -2
  2. package/build/esm/config.d.ts +122 -0
  3. package/build/esm/config.js +133 -0
  4. package/build/esm/config.js.map +1 -0
  5. package/build/esm/index.d.ts +27 -0
  6. package/build/esm/index.js +50 -0
  7. package/build/esm/index.js.map +1 -0
  8. package/build/esm/servers/server.builder.d.ts +508 -0
  9. package/build/esm/servers/server.builder.js +702 -0
  10. package/build/esm/servers/server.builder.js.map +1 -0
  11. package/build/esm/servers/server.d.ts +256 -0
  12. package/build/esm/servers/server.js +1248 -0
  13. package/build/esm/servers/server.js.map +1 -0
  14. package/build/esm/types/api-response.d.ts +152 -0
  15. package/build/esm/types/api-response.js +34 -0
  16. package/build/esm/types/api-response.js.map +1 -0
  17. package/build/esm/types/index.d.ts +125 -0
  18. package/build/esm/types/index.js +25 -0
  19. package/build/esm/types/index.js.map +1 -0
  20. package/build/esm/types/server.d.ts +268 -0
  21. package/build/esm/types/server.js +25 -0
  22. package/build/esm/types/server.js.map +1 -0
  23. package/build/esm/utils/array.utils.d.ts +168 -0
  24. package/build/esm/utils/array.utils.js +382 -0
  25. package/build/esm/utils/array.utils.js.map +1 -0
  26. package/build/esm/utils/async.utils.d.ts +265 -0
  27. package/build/esm/utils/async.utils.js +896 -0
  28. package/build/esm/utils/async.utils.js.map +1 -0
  29. package/build/esm/utils/cache.utils.d.ts +153 -0
  30. package/build/esm/utils/cache.utils.js +499 -0
  31. package/build/esm/utils/cache.utils.js.map +1 -0
  32. package/build/esm/utils/context-store.utils.d.ts +189 -0
  33. package/build/esm/utils/context-store.utils.js +307 -0
  34. package/build/esm/utils/context-store.utils.js.map +1 -0
  35. package/build/esm/utils/crypto.utils.d.ts +160 -0
  36. package/build/esm/utils/crypto.utils.js +375 -0
  37. package/build/esm/utils/crypto.utils.js.map +1 -0
  38. package/build/esm/utils/date.utils.d.ts +159 -0
  39. package/build/esm/utils/date.utils.js +389 -0
  40. package/build/esm/utils/date.utils.js.map +1 -0
  41. package/build/esm/utils/decorators.utils.d.ts +508 -0
  42. package/build/esm/utils/decorators.utils.js +1057 -0
  43. package/build/esm/utils/decorators.utils.js.map +1 -0
  44. package/build/esm/utils/dir.utils.d.ts +196 -0
  45. package/build/esm/utils/dir.utils.js +998 -0
  46. package/build/esm/utils/dir.utils.js.map +1 -0
  47. package/build/esm/utils/env.utils.d.ts +377 -0
  48. package/build/esm/utils/env.utils.js +873 -0
  49. package/build/esm/utils/env.utils.js.map +1 -0
  50. package/build/esm/utils/exception.utils.d.ts +230 -0
  51. package/build/esm/utils/exception.utils.js +559 -0
  52. package/build/esm/utils/exception.utils.js.map +1 -0
  53. package/build/esm/utils/fs.utils.d.ts +164 -0
  54. package/build/esm/utils/fs.utils.js +580 -0
  55. package/build/esm/utils/fs.utils.js.map +1 -0
  56. package/build/esm/utils/http-status-codes.d.ts +266 -0
  57. package/build/esm/utils/http-status-codes.js +295 -0
  58. package/build/esm/utils/http-status-codes.js.map +1 -0
  59. package/build/esm/utils/id.utils.d.ts +36 -0
  60. package/build/esm/utils/id.utils.js +87 -0
  61. package/build/esm/utils/id.utils.js.map +1 -0
  62. package/build/esm/utils/logger.utils.d.ts +160 -0
  63. package/build/esm/utils/logger.utils.js +341 -0
  64. package/build/esm/utils/logger.utils.js.map +1 -0
  65. package/build/esm/utils/middleware.utils.d.ts +100 -0
  66. package/build/esm/utils/middleware.utils.js +325 -0
  67. package/build/esm/utils/middleware.utils.js.map +1 -0
  68. package/build/esm/utils/obj.utils.d.ts +124 -0
  69. package/build/esm/utils/obj.utils.js +519 -0
  70. package/build/esm/utils/obj.utils.js.map +1 -0
  71. package/build/esm/utils/performance.utils.d.ts +136 -0
  72. package/build/esm/utils/performance.utils.js +376 -0
  73. package/build/esm/utils/performance.utils.js.map +1 -0
  74. package/build/esm/utils/request.utils.d.ts +86 -0
  75. package/build/esm/utils/request.utils.js +223 -0
  76. package/build/esm/utils/request.utils.js.map +1 -0
  77. package/build/esm/utils/response.utils.d.ts +163 -0
  78. package/build/esm/utils/response.utils.js +284 -0
  79. package/build/esm/utils/response.utils.js.map +1 -0
  80. package/build/esm/utils/stream.utils.d.ts +88 -0
  81. package/build/esm/utils/stream.utils.js +284 -0
  82. package/build/esm/utils/stream.utils.js.map +1 -0
  83. package/build/esm/utils/string.utils.d.ts +93 -0
  84. package/build/esm/utils/string.utils.js +169 -0
  85. package/build/esm/utils/string.utils.js.map +1 -0
  86. package/build/esm/utils/type.utils.d.ts +90 -0
  87. package/build/esm/utils/type.utils.js +190 -0
  88. package/build/esm/utils/type.utils.js.map +1 -0
  89. package/build/esm/utils/url.utils.d.ts +141 -0
  90. package/build/esm/utils/url.utils.js +381 -0
  91. package/build/esm/utils/url.utils.js.map +1 -0
  92. package/build/esm/utils/validate.utils.d.ts +177 -0
  93. package/build/esm/utils/validate.utils.js +336 -0
  94. package/build/esm/utils/validate.utils.js.map +1 -0
  95. package/build/esnext/config.d.ts +122 -0
  96. package/build/esnext/config.js +133 -0
  97. package/build/esnext/config.js.map +1 -0
  98. package/build/esnext/index.d.ts +27 -0
  99. package/build/esnext/index.js +50 -0
  100. package/build/esnext/index.js.map +1 -0
  101. package/build/esnext/servers/server.builder.d.ts +508 -0
  102. package/build/esnext/servers/server.builder.js +657 -0
  103. package/build/esnext/servers/server.builder.js.map +1 -0
  104. package/build/esnext/servers/server.d.ts +256 -0
  105. package/build/esnext/servers/server.js +955 -0
  106. package/build/esnext/servers/server.js.map +1 -0
  107. package/build/esnext/types/api-response.d.ts +152 -0
  108. package/build/esnext/types/api-response.js +34 -0
  109. package/build/esnext/types/api-response.js.map +1 -0
  110. package/build/esnext/types/index.d.ts +125 -0
  111. package/build/esnext/types/index.js +25 -0
  112. package/build/esnext/types/index.js.map +1 -0
  113. package/build/esnext/types/server.d.ts +268 -0
  114. package/build/esnext/types/server.js +25 -0
  115. package/build/esnext/types/server.js.map +1 -0
  116. package/build/esnext/utils/array.utils.d.ts +168 -0
  117. package/build/esnext/utils/array.utils.js +345 -0
  118. package/build/esnext/utils/array.utils.js.map +1 -0
  119. package/build/esnext/utils/async.utils.d.ts +265 -0
  120. package/build/esnext/utils/async.utils.js +620 -0
  121. package/build/esnext/utils/async.utils.js.map +1 -0
  122. package/build/esnext/utils/cache.utils.d.ts +153 -0
  123. package/build/esnext/utils/cache.utils.js +293 -0
  124. package/build/esnext/utils/cache.utils.js.map +1 -0
  125. package/build/esnext/utils/context-store.utils.d.ts +189 -0
  126. package/build/esnext/utils/context-store.utils.js +289 -0
  127. package/build/esnext/utils/context-store.utils.js.map +1 -0
  128. package/build/esnext/utils/crypto.utils.d.ts +160 -0
  129. package/build/esnext/utils/crypto.utils.js +276 -0
  130. package/build/esnext/utils/crypto.utils.js.map +1 -0
  131. package/build/esnext/utils/date.utils.d.ts +159 -0
  132. package/build/esnext/utils/date.utils.js +384 -0
  133. package/build/esnext/utils/date.utils.js.map +1 -0
  134. package/build/esnext/utils/decorators.utils.d.ts +508 -0
  135. package/build/esnext/utils/decorators.utils.js +877 -0
  136. package/build/esnext/utils/decorators.utils.js.map +1 -0
  137. package/build/esnext/utils/dir.utils.d.ts +196 -0
  138. package/build/esnext/utils/dir.utils.js +477 -0
  139. package/build/esnext/utils/dir.utils.js.map +1 -0
  140. package/build/esnext/utils/env.utils.d.ts +377 -0
  141. package/build/esnext/utils/env.utils.js +785 -0
  142. package/build/esnext/utils/env.utils.js.map +1 -0
  143. package/build/esnext/utils/exception.utils.d.ts +230 -0
  144. package/build/esnext/utils/exception.utils.js +381 -0
  145. package/build/esnext/utils/exception.utils.js.map +1 -0
  146. package/build/esnext/utils/fs.utils.d.ts +164 -0
  147. package/build/esnext/utils/fs.utils.js +349 -0
  148. package/build/esnext/utils/fs.utils.js.map +1 -0
  149. package/build/esnext/utils/http-status-codes.d.ts +266 -0
  150. package/build/esnext/utils/http-status-codes.js +295 -0
  151. package/build/esnext/utils/http-status-codes.js.map +1 -0
  152. package/build/esnext/utils/id.utils.d.ts +36 -0
  153. package/build/esnext/utils/id.utils.js +84 -0
  154. package/build/esnext/utils/id.utils.js.map +1 -0
  155. package/build/esnext/utils/logger.utils.d.ts +160 -0
  156. package/build/esnext/utils/logger.utils.js +300 -0
  157. package/build/esnext/utils/logger.utils.js.map +1 -0
  158. package/build/esnext/utils/middleware.utils.d.ts +100 -0
  159. package/build/esnext/utils/middleware.utils.js +236 -0
  160. package/build/esnext/utils/middleware.utils.js.map +1 -0
  161. package/build/esnext/utils/obj.utils.d.ts +124 -0
  162. package/build/esnext/utils/obj.utils.js +413 -0
  163. package/build/esnext/utils/obj.utils.js.map +1 -0
  164. package/build/esnext/utils/performance.utils.d.ts +136 -0
  165. package/build/esnext/utils/performance.utils.js +271 -0
  166. package/build/esnext/utils/performance.utils.js.map +1 -0
  167. package/build/esnext/utils/request.utils.d.ts +86 -0
  168. package/build/esnext/utils/request.utils.js +186 -0
  169. package/build/esnext/utils/request.utils.js.map +1 -0
  170. package/build/esnext/utils/response.utils.d.ts +163 -0
  171. package/build/esnext/utils/response.utils.js +247 -0
  172. package/build/esnext/utils/response.utils.js.map +1 -0
  173. package/build/esnext/utils/stream.utils.d.ts +88 -0
  174. package/build/esnext/utils/stream.utils.js +210 -0
  175. package/build/esnext/utils/stream.utils.js.map +1 -0
  176. package/build/esnext/utils/string.utils.d.ts +93 -0
  177. package/build/esnext/utils/string.utils.js +165 -0
  178. package/build/esnext/utils/string.utils.js.map +1 -0
  179. package/build/esnext/utils/type.utils.d.ts +90 -0
  180. package/build/esnext/utils/type.utils.js +187 -0
  181. package/build/esnext/utils/type.utils.js.map +1 -0
  182. package/build/esnext/utils/url.utils.d.ts +141 -0
  183. package/build/esnext/utils/url.utils.js +304 -0
  184. package/build/esnext/utils/url.utils.js.map +1 -0
  185. package/build/esnext/utils/validate.utils.d.ts +177 -0
  186. package/build/esnext/utils/validate.utils.js +320 -0
  187. package/build/esnext/utils/validate.utils.js.map +1 -0
  188. package/build/src/config.d.ts +122 -0
  189. package/build/src/config.js +138 -0
  190. package/build/src/config.js.map +1 -0
  191. package/build/src/index.d.ts +27 -0
  192. package/build/src/index.js +69 -0
  193. package/build/src/index.js.map +1 -0
  194. package/build/src/servers/server.builder.d.ts +508 -0
  195. package/build/src/servers/server.builder.js +661 -0
  196. package/build/src/servers/server.builder.js.map +1 -0
  197. package/build/src/servers/server.d.ts +256 -0
  198. package/build/src/servers/server.js +962 -0
  199. package/build/src/servers/server.js.map +1 -0
  200. package/build/src/types/api-response.d.ts +152 -0
  201. package/build/src/types/api-response.js +37 -0
  202. package/build/src/types/api-response.js.map +1 -0
  203. package/build/src/types/index.d.ts +125 -0
  204. package/build/src/types/index.js +26 -0
  205. package/build/src/types/index.js.map +1 -0
  206. package/build/src/types/server.d.ts +268 -0
  207. package/build/src/types/server.js +26 -0
  208. package/build/src/types/server.js.map +1 -0
  209. package/build/src/utils/array.utils.d.ts +168 -0
  210. package/build/src/utils/array.utils.js +364 -0
  211. package/build/src/utils/array.utils.js.map +1 -0
  212. package/build/src/utils/async.utils.d.ts +265 -0
  213. package/build/src/utils/async.utils.js +641 -0
  214. package/build/src/utils/async.utils.js.map +1 -0
  215. package/build/src/utils/cache.utils.d.ts +153 -0
  216. package/build/src/utils/cache.utils.js +297 -0
  217. package/build/src/utils/cache.utils.js.map +1 -0
  218. package/build/src/utils/context-store.utils.d.ts +189 -0
  219. package/build/src/utils/context-store.utils.js +296 -0
  220. package/build/src/utils/context-store.utils.js.map +1 -0
  221. package/build/src/utils/crypto.utils.d.ts +160 -0
  222. package/build/src/utils/crypto.utils.js +293 -0
  223. package/build/src/utils/crypto.utils.js.map +1 -0
  224. package/build/src/utils/date.utils.d.ts +159 -0
  225. package/build/src/utils/date.utils.js +396 -0
  226. package/build/src/utils/date.utils.js.map +1 -0
  227. package/build/src/utils/decorators.utils.d.ts +508 -0
  228. package/build/src/utils/decorators.utils.js +896 -0
  229. package/build/src/utils/decorators.utils.js.map +1 -0
  230. package/build/src/utils/dir.utils.d.ts +196 -0
  231. package/build/src/utils/dir.utils.js +501 -0
  232. package/build/src/utils/dir.utils.js.map +1 -0
  233. package/build/src/utils/env.utils.d.ts +377 -0
  234. package/build/src/utils/env.utils.js +789 -0
  235. package/build/src/utils/env.utils.js.map +1 -0
  236. package/build/src/utils/exception.utils.d.ts +230 -0
  237. package/build/src/utils/exception.utils.js +407 -0
  238. package/build/src/utils/exception.utils.js.map +1 -0
  239. package/build/src/utils/fs.utils.d.ts +164 -0
  240. package/build/src/utils/fs.utils.js +372 -0
  241. package/build/src/utils/fs.utils.js.map +1 -0
  242. package/build/src/utils/http-status-codes.d.ts +266 -0
  243. package/build/src/utils/http-status-codes.js +298 -0
  244. package/build/src/utils/http-status-codes.js.map +1 -0
  245. package/build/src/utils/id.utils.d.ts +36 -0
  246. package/build/src/utils/id.utils.js +91 -0
  247. package/build/src/utils/id.utils.js.map +1 -0
  248. package/build/src/utils/logger.utils.d.ts +160 -0
  249. package/build/src/utils/logger.utils.js +346 -0
  250. package/build/src/utils/logger.utils.js.map +1 -0
  251. package/build/src/utils/middleware.utils.d.ts +100 -0
  252. package/build/src/utils/middleware.utils.js +244 -0
  253. package/build/src/utils/middleware.utils.js.map +1 -0
  254. package/build/src/utils/obj.utils.d.ts +124 -0
  255. package/build/src/utils/obj.utils.js +429 -0
  256. package/build/src/utils/obj.utils.js.map +1 -0
  257. package/build/src/utils/performance.utils.d.ts +136 -0
  258. package/build/src/utils/performance.utils.js +278 -0
  259. package/build/src/utils/performance.utils.js.map +1 -0
  260. package/build/src/utils/request.utils.d.ts +86 -0
  261. package/build/src/utils/request.utils.js +195 -0
  262. package/build/src/utils/request.utils.js.map +1 -0
  263. package/build/src/utils/response.utils.d.ts +163 -0
  264. package/build/src/utils/response.utils.js +260 -0
  265. package/build/src/utils/response.utils.js.map +1 -0
  266. package/build/src/utils/stream.utils.d.ts +88 -0
  267. package/build/src/utils/stream.utils.js +218 -0
  268. package/build/src/utils/stream.utils.js.map +1 -0
  269. package/build/src/utils/string.utils.d.ts +93 -0
  270. package/build/src/utils/string.utils.js +179 -0
  271. package/build/src/utils/string.utils.js.map +1 -0
  272. package/build/src/utils/type.utils.d.ts +90 -0
  273. package/build/src/utils/type.utils.js +196 -0
  274. package/build/src/utils/type.utils.js.map +1 -0
  275. package/build/src/utils/url.utils.d.ts +141 -0
  276. package/build/src/utils/url.utils.js +317 -0
  277. package/build/src/utils/url.utils.js.map +1 -0
  278. package/build/src/utils/validate.utils.d.ts +177 -0
  279. package/build/src/utils/validate.utils.js +345 -0
  280. package/build/src/utils/validate.utils.js.map +1 -0
  281. package/package.json +66 -12
  282. package/build/index.cjs +0 -6888
  283. package/build/index.d.ts +0 -5242
  284. package/build/index.mjs +0 -6615
@@ -0,0 +1,1057 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ var __assign = (this && this.__assign) || function () {
25
+ __assign = Object.assign || function(t) {
26
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
27
+ s = arguments[i];
28
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
+ t[p] = s[p];
30
+ }
31
+ return t;
32
+ };
33
+ return __assign.apply(this, arguments);
34
+ };
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __generator = (this && this.__generator) || function (thisArg, body) {
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
+ function verb(n) { return function (v) { return step([n, v]); }; }
48
+ function step(op) {
49
+ if (f) throw new TypeError("Generator is already executing.");
50
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
+ if (y = 0, t) op = [op[0] & 2, t.value];
53
+ switch (op[0]) {
54
+ case 0: case 1: t = op; break;
55
+ case 4: _.label++; return { value: op[1], done: false };
56
+ case 5: _.label++; y = op[1]; op = [0]; continue;
57
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
+ default:
59
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
+ if (t[2]) _.ops.pop();
64
+ _.trys.pop(); continue;
65
+ }
66
+ op = body.call(thisArg, _);
67
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
+ }
70
+ };
71
+ var __read = (this && this.__read) || function (o, n) {
72
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
73
+ if (!m) return o;
74
+ var i = m.call(o), r, ar = [], e;
75
+ try {
76
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
77
+ }
78
+ catch (error) { e = { error: error }; }
79
+ finally {
80
+ try {
81
+ if (r && !r.done && (m = i["return"])) m.call(i);
82
+ }
83
+ finally { if (e) throw e.error; }
84
+ }
85
+ return ar;
86
+ };
87
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
88
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
89
+ if (ar || !(i in from)) {
90
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
91
+ ar[i] = from[i];
92
+ }
93
+ }
94
+ return to.concat(ar || Array.prototype.slice.call(from));
95
+ };
96
+ var __values = (this && this.__values) || function(o) {
97
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
98
+ if (m) return m.call(o);
99
+ if (o && typeof o.length === "number") return {
100
+ next: function () {
101
+ if (o && i >= o.length) o = void 0;
102
+ return { value: o && o[i++], done: !o };
103
+ }
104
+ };
105
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
106
+ };
107
+ import 'reflect-metadata';
108
+ import { getLogger } from './logger.utils';
109
+ import { createFinalErrorResponse } from './response.utils';
110
+ import { HttpStatusCodes } from './http-status-codes';
111
+ import { rateLimit } from 'express-rate-limit';
112
+ import { TTLCache } from './cache.utils';
113
+ // Metadata keys
114
+ var ROUTES_KEY = Symbol('routes');
115
+ var MIDDLEWARE_KEY = Symbol('middlewares');
116
+ var PARAMS_KEY = Symbol('params');
117
+ var HTTP_CODE_KEY = Symbol('httpCode');
118
+ var HEADER_KEY = Symbol('headers');
119
+ var BEFORE_KEY = Symbol('before');
120
+ var AFTER_KEY = Symbol('after');
121
+ var ROLES_KEY = Symbol('roles');
122
+ var REDIRECT_KEY = Symbol('redirect');
123
+ var CACHE_KEY = Symbol('cache');
124
+ var RATE_LIMIT_KEY = Symbol('rateLimit');
125
+ var CONTENT_TYPE_KEY = Symbol('contentType');
126
+ var VERSION_KEY = Symbol('version');
127
+ var TIMEOUT_KEY = Symbol('timeout');
128
+ var LOG_KEY = Symbol('log');
129
+ /**
130
+ * RateLimiter cache that uses TTLCache for automatic TTL and LRU handling.
131
+ */
132
+ var RateLimiterCache = /** @class */ (function () {
133
+ function RateLimiterCache(maxSize, ttlMs) {
134
+ if (maxSize === void 0) { maxSize = 100; }
135
+ if (ttlMs === void 0) { ttlMs = 5 * 60 * 1000; }
136
+ this.cache = new TTLCache({
137
+ maxSize: maxSize,
138
+ ttlMs: ttlMs
139
+ });
140
+ }
141
+ RateLimiterCache.prototype.generateKey = function (options) {
142
+ return "".concat(options.max, ":").concat(options.windowMs, ":").concat(options.standardHeaders, ":").concat(options.legacyHeaders);
143
+ };
144
+ RateLimiterCache.prototype.get = function (options) {
145
+ var key = this.generateKey(options);
146
+ var cached = this.cache.get(key);
147
+ if (cached) {
148
+ return cached.limiter;
149
+ }
150
+ // Create new limiter
151
+ var limiter = rateLimit(__assign(__assign({}, options), { handler: function (req, res) {
152
+ var errorResponse = createFinalErrorResponse(req, HttpStatusCodes.TOO_MANY_REQUESTS, 'Too Many Requests');
153
+ res.status(HttpStatusCodes.TOO_MANY_REQUESTS).json(errorResponse);
154
+ } }));
155
+ // Store in cache
156
+ this.cache.set(key, {
157
+ limiter: limiter,
158
+ config: key
159
+ });
160
+ return limiter;
161
+ };
162
+ RateLimiterCache.prototype.clear = function () {
163
+ this.cache.clear();
164
+ };
165
+ RateLimiterCache.prototype.size = function () {
166
+ return this.cache.size();
167
+ };
168
+ RateLimiterCache.prototype.destroy = function () {
169
+ this.cache.destroy();
170
+ };
171
+ return RateLimiterCache;
172
+ }());
173
+ export { RateLimiterCache };
174
+ // Global cache instance
175
+ var rateLimiterCache = new RateLimiterCache();
176
+ function normalizeHeaderValue(value) {
177
+ if (typeof value === 'undefined')
178
+ return undefined;
179
+ if (typeof value === 'string')
180
+ return value;
181
+ if (Array.isArray(value) && value.every(function (item) { return typeof item === 'string'; })) {
182
+ return value;
183
+ }
184
+ return String(value);
185
+ }
186
+ /**
187
+ * Factory function that creates HTTP method decorators.
188
+ *
189
+ * @param method - HTTP method to create decorator for
190
+ * @returns A method decorator function
191
+ */
192
+ function createRouteDecorator(method) {
193
+ return function (path) {
194
+ return function (target, propertyKey, descriptor) {
195
+ var routes = Reflect.getMetadata(ROUTES_KEY, target.constructor) || [];
196
+ routes.push({
197
+ path: path,
198
+ method: method,
199
+ handlerName: propertyKey
200
+ });
201
+ Reflect.defineMetadata(ROUTES_KEY, routes, target.constructor);
202
+ };
203
+ };
204
+ }
205
+ /**
206
+ * Decorator for GET HTTP method routes.
207
+ *
208
+ * @param path - URL path for the route
209
+ * @returns Method decorator
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * @Get('/users')
214
+ * getUsers() {
215
+ * return this.userService.findAll();
216
+ * }
217
+ * ```
218
+ */
219
+ export var Get = createRouteDecorator('get');
220
+ /**
221
+ * Decorator for POST HTTP method routes.
222
+ *
223
+ * @param path - URL path for the route
224
+ * @returns Method decorator
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * @Post('/users')
229
+ * createUser(@Body() userData: any) {
230
+ * return this.userService.create(userData);
231
+ * }
232
+ * ```
233
+ */
234
+ export var Post = createRouteDecorator('post');
235
+ /**
236
+ * Decorator for PUT HTTP method routes.
237
+ *
238
+ * @param path - URL path for the route
239
+ * @returns Method decorator
240
+ */
241
+ export var Put = createRouteDecorator('put');
242
+ /**
243
+ * Decorator for PATCH HTTP method routes.
244
+ *
245
+ * @param path - URL path for the route
246
+ * @returns Method decorator
247
+ */
248
+ export var Patch = createRouteDecorator('patch');
249
+ /**
250
+ * Decorator for DELETE HTTP method routes.
251
+ *
252
+ * @param path - URL path for the route
253
+ * @returns Method decorator
254
+ */
255
+ export var Delete = createRouteDecorator('delete');
256
+ /**
257
+ * Decorator for OPTIONS HTTP method routes.
258
+ *
259
+ * @param path - URL path for the route
260
+ * @returns Method decorator
261
+ */
262
+ export var Options = createRouteDecorator('options');
263
+ /**
264
+ * Decorator for HEAD HTTP method routes.
265
+ *
266
+ * @param path - URL path for the route
267
+ * @returns Method decorator
268
+ */
269
+ export var Head = createRouteDecorator('head');
270
+ /**
271
+ * Decorator for TRACE HTTP method routes.
272
+ *
273
+ * @param path - URL path for the route
274
+ * @returns Method decorator
275
+ */
276
+ export var Trace = createRouteDecorator('trace');
277
+ /**
278
+ * Decorator for CONNECT HTTP method routes.
279
+ *
280
+ * @param path - URL path for the route
281
+ * @returns Method decorator
282
+ */
283
+ export var Connect = createRouteDecorator('connect');
284
+ /**
285
+ * Decorator that marks a class as a controller with a base path.
286
+ * Used as the entry point for routing configuration.
287
+ *
288
+ * @param basePath - Base URL path for all routes in this controller
289
+ * @returns Class decorator
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * @Controller('/api/users')
294
+ * class UserController {
295
+ * // Controller methods...
296
+ * }
297
+ * ```
298
+ */
299
+ export function Controller(basePath) {
300
+ return function (target) {
301
+ Reflect.defineMetadata('basePath', basePath, target);
302
+ };
303
+ }
304
+ /**
305
+ * Decorator that applies middleware to a controller method.
306
+ * Multiple middlewares can be applied and will execute in order.
307
+ *
308
+ * @param middlewares - Express middleware functions to apply
309
+ * @returns Method decorator
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * @Get('/protected')
314
+ * @Use(authMiddleware, loggingMiddleware)
315
+ * getProtectedResource() {
316
+ * // This route is protected by auth middleware
317
+ * }
318
+ * ```
319
+ */
320
+ export function Use() {
321
+ var middlewares = [];
322
+ for (var _i = 0; _i < arguments.length; _i++) {
323
+ middlewares[_i] = arguments[_i];
324
+ }
325
+ return function (target, propertyKey, _descriptor) {
326
+ var existing = Reflect.getMetadata(MIDDLEWARE_KEY, target, propertyKey) || [];
327
+ Reflect.defineMetadata(MIDDLEWARE_KEY, __spreadArray(__spreadArray([], __read(existing), false), __read(middlewares), false), target, propertyKey);
328
+ };
329
+ }
330
+ /**
331
+ * Factory function that creates parameter decorators.
332
+ *
333
+ * @param type - Parameter type to extract from request
334
+ * @param key - Optional fixed key for extraction
335
+ * @returns Parameter decorator function
336
+ */
337
+ function createParamDecorator(type, key) {
338
+ return function (paramKey) {
339
+ return function (target, propertyKey, parameterIndex) {
340
+ var params = Reflect.getMetadata(PARAMS_KEY, target, propertyKey) || [];
341
+ // Ensure parameters are ordered by index
342
+ params.push({ index: parameterIndex, type: type, key: paramKey || key });
343
+ params.sort(function (a, b) { return a.index - b.index; });
344
+ Reflect.defineMetadata(PARAMS_KEY, params, target, propertyKey);
345
+ };
346
+ };
347
+ }
348
+ /**
349
+ * Decorator that extracts query parameters from request.
350
+ *
351
+ * @param paramKey - Optional key to extract specific query parameter
352
+ * @returns Parameter decorator
353
+ *
354
+ * @example
355
+ * ```ts
356
+ * @Get('/search')
357
+ * search(@Query('term') searchTerm: string) {
358
+ * // searchTerm will contain the value of req.query.term
359
+ * }
360
+ * ```
361
+ */
362
+ export var Query = createParamDecorator('query');
363
+ /**
364
+ * Decorator that extracts route parameters from request.
365
+ *
366
+ * @param paramKey - Optional key to extract specific route parameter
367
+ * @returns Parameter decorator
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * @Get('/users/:id')
372
+ * getUser(@Param('id') userId: string) {
373
+ * // userId will contain the value of req.params.id
374
+ * }
375
+ * ```
376
+ */
377
+ export var Param = createParamDecorator('param');
378
+ /**
379
+ * Decorator that extracts body or body property from request.
380
+ *
381
+ * @param paramKey - Optional key to extract specific body property
382
+ * @returns Parameter decorator
383
+ *
384
+ * @example
385
+ * ```ts
386
+ * @Post('/users')
387
+ * createUser(@Body() userData: any) {
388
+ * // userData will contain the entire req.body
389
+ * }
390
+ *
391
+ * @Post('/update')
392
+ * updateName(@Body('name') name: string) {
393
+ * // name will contain the value of req.body.name
394
+ * }
395
+ * ```
396
+ */
397
+ export var Body = createParamDecorator('body');
398
+ /**
399
+ * Decorator that injects the entire request object.
400
+ *
401
+ * @returns Parameter decorator
402
+ *
403
+ * @example
404
+ * ```ts
405
+ * @Get('/complex')
406
+ * complex(@Req() req: Request) {
407
+ * // Access the full request object
408
+ * console.log(req.headers);
409
+ * }
410
+ * ```
411
+ */
412
+ export var Req = createParamDecorator('req');
413
+ /**
414
+ * Decorator that injects the response object.
415
+ *
416
+ * @returns Parameter decorator
417
+ *
418
+ * @example
419
+ * ```ts
420
+ * @Get('/custom')
421
+ * custom(@Res() res: Response) {
422
+ * // Direct access to response object
423
+ * return res.status(201).send('Created');
424
+ * }
425
+ * ```
426
+ */
427
+ export var Res = createParamDecorator('res');
428
+ /**
429
+ * Decorator that sets a custom HTTP status code for a response.
430
+ *
431
+ * @param status - HTTP status code to use
432
+ * @returns Method decorator
433
+ *
434
+ * @example
435
+ * ```ts
436
+ * @Post('/users')
437
+ * @HttpCode(201)
438
+ * createUser(@Body() userData: any) {
439
+ * // Response will have 201 Created status code
440
+ * return { id: '123', ...userData };
441
+ * }
442
+ * ```
443
+ */
444
+ export function HttpCode(status) {
445
+ return function (target, propertyKey, _descriptor) {
446
+ Reflect.defineMetadata(HTTP_CODE_KEY, status, target, propertyKey);
447
+ };
448
+ }
449
+ /**
450
+ * Decorator that adds a custom HTTP header to the response.
451
+ *
452
+ * @param header - Header name-value pairs or a single header name and value
453
+ * @param value - Header value if a single header name is provided
454
+ * @returns Method decorator
455
+ *
456
+ * @example
457
+ * ```ts
458
+ * @Get('/data')
459
+ * @Header('Cache-Control', 'max-age=60')
460
+ * getData() {
461
+ * // Response will include the Cache-Control header
462
+ * return { data: '...' };
463
+ * }
464
+ */
465
+ export function Header(name, value) {
466
+ return Headers(name, value);
467
+ }
468
+ /**
469
+ * Decorator that adds a custom HTTP headers to the response.
470
+ *
471
+ * @param headers - Header name-value pairs or a single header name and value
472
+ * @param value - Header value if a single header name is provided
473
+ * @returns Method decorator
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * @Get('/data')
478
+ * @Headers('Cache-Control', 'max-age=60')
479
+ * getData() {
480
+ * // Response will include the Cache-Control header
481
+ * return { data: '...' };
482
+ * }
483
+ *
484
+ * @Get('/data/:id')
485
+ * @Headers({
486
+ * 'Cache-Control': 'max-age=60',
487
+ * 'X-Custom-Header': 'custom-value',
488
+ * 'Content-Security-Policy': "default-src 'self'"
489
+ * })
490
+ * getData() {
491
+ * // Response will include all specified headers
492
+ * return { data: '...' };
493
+ * }
494
+ *
495
+ * ```
496
+ */
497
+ export function Headers(headers, value) {
498
+ return function (target, propertyKey) {
499
+ var _a;
500
+ var existing = Reflect.getMetadata(HEADER_KEY, target, propertyKey) || {};
501
+ var newHeaders = typeof headers === 'string' ? (_a = {}, _a[headers] = value, _a) : headers;
502
+ Reflect.defineMetadata(HEADER_KEY, __assign(__assign({}, existing), newHeaders), target, propertyKey);
503
+ };
504
+ }
505
+ /**
506
+ * Decorator that registers a function to run before route handler execution.
507
+ * Useful for pre-processing or logging.
508
+ *
509
+ * @param fn - Function to execute before the handler
510
+ * @returns Method decorator
511
+ *
512
+ * @example
513
+ * ```ts
514
+ * @Get('/users/:id')
515
+ * @Before((req, res) => console.log(`Accessing user ${req.params.id}`))
516
+ * getUser(@Param('id') id: string) {
517
+ * // Function will log before this handler runs
518
+ * }
519
+ * ```
520
+ */
521
+ export function Before(fn) {
522
+ return function (target, propertyKey, _descriptor) {
523
+ var hooks = Reflect.getMetadata(BEFORE_KEY, target, propertyKey) || [];
524
+ hooks.push(fn);
525
+ Reflect.defineMetadata(BEFORE_KEY, hooks, target, propertyKey);
526
+ };
527
+ }
528
+ /**
529
+ * Decorator that registers a function to run after route handler execution.
530
+ * Can access the handler's result.
531
+ *
532
+ * @param fn - Function to execute after the handler
533
+ * @returns Method decorator
534
+ *
535
+ * @example
536
+ * ```ts
537
+ * @Get('/users/:id')
538
+ * @After((req, res, result) => console.log(`User data sent: ${JSON.stringify(result)}`))
539
+ * getUser(@Param('id') id: string) {
540
+ * // After this handler, the function will log the returned data
541
+ * return { id, name: 'Example' };
542
+ * }
543
+ * ```
544
+ */
545
+ export function After(fn) {
546
+ return function (target, propertyKey, _descriptor) {
547
+ var hooks = Reflect.getMetadata(AFTER_KEY, target, propertyKey) || [];
548
+ hooks.push(fn);
549
+ Reflect.defineMetadata(AFTER_KEY, hooks, target, propertyKey);
550
+ };
551
+ }
552
+ /**
553
+ * Decorator that requires specific roles for accessing a route.
554
+ * Must be used with authentication middleware.
555
+ *
556
+ * @param roles - List of roles that can access this route
557
+ * @returns Method decorator
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * @Get('/admin/settings')
562
+ * @Roles('admin', 'superuser')
563
+ * getSettings() {
564
+ * // Only admins and superusers can access
565
+ * return { settings: [...] };
566
+ * }
567
+ * ```
568
+ */
569
+ export function Roles() {
570
+ var roles = [];
571
+ for (var _i = 0; _i < arguments.length; _i++) {
572
+ roles[_i] = arguments[_i];
573
+ }
574
+ return function (target, propertyKey, _descriptor) {
575
+ Reflect.defineMetadata(ROLES_KEY, roles, target, propertyKey);
576
+ };
577
+ }
578
+ /**
579
+ * Decorator that redirects to another URL.
580
+ *
581
+ * @param url - URL to redirect to (can be absolute or relative)
582
+ * @param statusCode - HTTP status code for redirect (default: 302)
583
+ * @returns Method decorator
584
+ *
585
+ * @example
586
+ * ```ts
587
+ * @Get('/old-path')
588
+ * @Redirect('/new-path', 301)
589
+ * redirectToNewPath() {
590
+ * // This method won't be executed; automatic redirect happens
591
+ * }
592
+ *
593
+ * @Get('/dynamic-redirect')
594
+ * @Redirect()
595
+ * getDynamicRedirect() {
596
+ * // Return an object with url and optionally statusCode
597
+ * return { url: '/calculated-path', statusCode: 307 };
598
+ * }
599
+ * ```
600
+ */
601
+ export function Redirect(url, statusCode) {
602
+ if (statusCode === void 0) { statusCode = 302; }
603
+ return function (target, propertyKey, descriptor) {
604
+ // Store the redirect information in metadata
605
+ Reflect.defineMetadata(REDIRECT_KEY, { url: url, statusCode: statusCode }, target, propertyKey);
606
+ return descriptor;
607
+ };
608
+ }
609
+ /**
610
+ * Decorator that adds caching to a route response.
611
+ *
612
+ * @param ttlSeconds - Time to live in seconds for the cache
613
+ * @returns Method decorator
614
+ *
615
+ * @example
616
+ * ```ts
617
+ * @Get('/data')
618
+ * @Cache(300) // Cache for 5 minutes
619
+ * getData() {
620
+ * return { data: 'expensive operation result' };
621
+ * }
622
+ * ```
623
+ */
624
+ export function Cache(ttlSeconds) {
625
+ return function (target, propertyKey, _descriptor) {
626
+ Reflect.defineMetadata(CACHE_KEY, { ttlSeconds: ttlSeconds }, target, propertyKey);
627
+ };
628
+ }
629
+ /**
630
+ * Decorator that applies rate limiting to a route.
631
+ * Note: Requires 'express-rate-limit' package to be installed.
632
+ *
633
+ * @param limit - Maximum number of requests allowed in the window
634
+ * @param windowMs - Time window in milliseconds
635
+ * @returns Method decorator
636
+ *
637
+ * Default Options:
638
+ * - standardHeaders: true
639
+ * - legacyHeaders: false
640
+ *
641
+ * @example
642
+ * ```ts
643
+ * @Post('/login')
644
+ * @RateLimit({ max: 5, windowMs: 60000, standardHeaders: true, legacyHeaders: false }) // 5 requests per minute
645
+ * login(@Body() credentials: LoginDto) {
646
+ * return this.authService.login(credentials);
647
+ * }
648
+ * ```
649
+ */
650
+ export function RateLimit(options) {
651
+ var opts = __assign({ standardHeaders: true, legacyHeaders: false }, options);
652
+ return function (target, propertyKey, _descriptor) {
653
+ Reflect.defineMetadata(RATE_LIMIT_KEY, opts, target, propertyKey);
654
+ };
655
+ }
656
+ /**
657
+ * Decorator that sets the content type for the response.
658
+ *
659
+ * @param type - MIME type for the response
660
+ * @returns Method decorator
661
+ *
662
+ * @example
663
+ * ```ts
664
+ * @Get('/download')
665
+ * @ContentType('application/pdf')
666
+ * downloadPdf() {
667
+ * return this.fileService.generatePdf();
668
+ * }
669
+ * ```
670
+ */
671
+ export function ContentType(type) {
672
+ return function (target, propertyKey, _descriptor) {
673
+ Reflect.defineMetadata(CONTENT_TYPE_KEY, { type: type }, target, propertyKey);
674
+ };
675
+ }
676
+ /**
677
+ * Decorator that adds API versioning to a route.
678
+ *
679
+ * @param version - Version string for the API endpoint
680
+ * @param options - Versioning options
681
+ * @returns Method decorator
682
+ *
683
+ * Default Options:
684
+ * - addPrefix: true
685
+ * - addHeader: true
686
+ * - headerName: 'X-API-Version'
687
+ *
688
+ * @example
689
+ * ```ts
690
+ *
691
+ * @Get('/users')
692
+ * @Version('v2')
693
+ * getUsersV2() {
694
+ * return this.userService.findAllV2();
695
+ * }
696
+ *
697
+ * @Get('/users')
698
+ * @Version('v2', { addPrefix: true, addHeader: true, headerName: 'X-API-Version' })
699
+ * getUsersV2() {
700
+ * // Route becomes /v2/users
701
+ * return this.userService.findAllV2();
702
+ * }
703
+ * ```
704
+ */
705
+ export function Version(version, options) {
706
+ var opts = __assign({ addPrefix: true, addHeader: true, headerName: 'X-API-Version' }, options);
707
+ return function (target, propertyKey, _descriptor) {
708
+ Reflect.defineMetadata(VERSION_KEY, { version: version, options: opts }, target, propertyKey);
709
+ };
710
+ }
711
+ /**
712
+ * Decorator that sets a timeout for route execution.
713
+ *
714
+ * @param ms - Timeout in milliseconds
715
+ * @returns Method decorator
716
+ *
717
+ * @example
718
+ * ```ts
719
+ * @Get('/slow-operation')
720
+ * @Timeout(30000) // 30 second timeout
721
+ * slowOperation() {
722
+ * return this.heavyService.processData();
723
+ * }
724
+ * ```
725
+ */
726
+ export function Timeout(ms) {
727
+ return function (target, propertyKey, _descriptor) {
728
+ Reflect.defineMetadata(TIMEOUT_KEY, { ms: ms }, target, propertyKey);
729
+ };
730
+ }
731
+ /**
732
+ * Decorator that adds comprehensive logging to a route.
733
+ *
734
+ * @param options - Logging configuration options
735
+ * @returns Method decorator
736
+ *
737
+ * Default Options:
738
+ * - logEntry: true
739
+ * - logExit: true
740
+ * - logBody: false
741
+ * - logParams: false
742
+ * - logResponse: false
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * @Post('/users')
747
+ * @Log({
748
+ * logEntry: true,
749
+ * logExit: true,
750
+ * logBody: true,
751
+ * logParams: true,
752
+ * logResponse: false
753
+ * })
754
+ * createUser(@Body() userData: any) {
755
+ * return this.userService.create(userData);
756
+ * }
757
+ * ```
758
+ */
759
+ export function Log(options) {
760
+ return function (target, propertyKey, _descriptor) {
761
+ var config = __assign({ logEntry: true, logExit: true, logBody: false, logParams: false, logResponse: false }, options);
762
+ Reflect.defineMetadata(LOG_KEY, config, target, propertyKey);
763
+ };
764
+ }
765
+ /**
766
+ * Registers all controller classes with the provided router.
767
+ * This function processes all decorators and sets up the Express routes.
768
+ *
769
+ * @param router - Express router instance
770
+ * @param controllers - Array of controller classes
771
+ */
772
+ export function registerControllers(router, controllers) {
773
+ var _this = this;
774
+ controllers.forEach(function (ControllerClass) {
775
+ var instance = new ControllerClass();
776
+ var basePath = Reflect.getMetadata('basePath', ControllerClass) || '';
777
+ var routes = Reflect.getMetadata(ROUTES_KEY, ControllerClass) || [];
778
+ // Get controller-level decorators (fallback values)
779
+ var controllerRateLimit = Reflect.getMetadata(RATE_LIMIT_KEY, ControllerClass);
780
+ var controllerCache = Reflect.getMetadata(CACHE_KEY, ControllerClass);
781
+ var controllerTimeout = Reflect.getMetadata(TIMEOUT_KEY, ControllerClass);
782
+ var controllerVersion = Reflect.getMetadata(VERSION_KEY, ControllerClass);
783
+ var controllerRoles = Reflect.getMetadata(ROLES_KEY, ControllerClass);
784
+ var controllerLogConfig = Reflect.getMetadata(LOG_KEY, ControllerClass);
785
+ var controllerHeaders = Reflect.getMetadata(HEADER_KEY, ControllerClass) || {};
786
+ routes.forEach(function (_a) {
787
+ var _b;
788
+ var _c;
789
+ var path = _a.path, method = _a.method, handlerName = _a.handlerName;
790
+ var middlewares = Reflect.getMetadata(MIDDLEWARE_KEY, instance, handlerName) || [];
791
+ var params = Reflect.getMetadata(PARAMS_KEY, instance, handlerName) || [];
792
+ var httpCode = Reflect.getMetadata(HTTP_CODE_KEY, instance, handlerName);
793
+ // Merge controller-level and method-level headers
794
+ var methodHeaders = Reflect.getMetadata(HEADER_KEY, instance, handlerName) || {};
795
+ var headers = __assign(__assign({}, controllerHeaders), methodHeaders);
796
+ var beforeHooks = Reflect.getMetadata(BEFORE_KEY, instance, handlerName) || [];
797
+ var afterHooks = Reflect.getMetadata(AFTER_KEY, instance, handlerName) || [];
798
+ var redirect = Reflect.getMetadata(REDIRECT_KEY, instance, handlerName);
799
+ var contentType = Reflect.getMetadata(CONTENT_TYPE_KEY, instance, handlerName);
800
+ // Use method-level decorators if present, otherwise fall back to controller-level
801
+ var roles = Reflect.getMetadata(ROLES_KEY, instance, handlerName) || controllerRoles || [];
802
+ var cache = Reflect.getMetadata(CACHE_KEY, instance, handlerName) || controllerCache;
803
+ var rateLimitOptions = Reflect.getMetadata(RATE_LIMIT_KEY, instance, handlerName) || controllerRateLimit;
804
+ var version = Reflect.getMetadata(VERSION_KEY, instance, handlerName) || controllerVersion;
805
+ var timeout = Reflect.getMetadata(TIMEOUT_KEY, instance, handlerName) || controllerTimeout;
806
+ var logConfig = Reflect.getMetadata(LOG_KEY, instance, handlerName) || controllerLogConfig;
807
+ // Create rate limiter for this specific route if needed
808
+ var rateLimiter = null;
809
+ if (rateLimitOptions) {
810
+ try {
811
+ rateLimiter = rateLimiterCache.get(rateLimitOptions);
812
+ }
813
+ catch (err) {
814
+ getLogger().warn({ err: err }, 'express-rate-limit not available, skipping rate limiting for this route');
815
+ }
816
+ }
817
+ var finalPath = path;
818
+ if ((_c = version === null || version === void 0 ? void 0 : version.options) === null || _c === void 0 ? void 0 : _c.addPrefix) {
819
+ finalPath = "/".concat(version.version).concat(path);
820
+ }
821
+ var handler = function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
822
+ var timeoutId, timedOut, logger, logData, errorResponse, beforeHooks_1, beforeHooks_1_1, fn, e_1_1, args_1, result, awaited, _a, redirectUrl, redirectStatus, _b, _c, _d, k, v, normalized, logger, logData, afterHooks_1, afterHooks_1_1, fn, e_2_1, err_1;
823
+ var e_1, _e, _f, e_3, _g, e_2, _h;
824
+ var _j, _k, _l, _m;
825
+ return __generator(this, function (_o) {
826
+ switch (_o.label) {
827
+ case 0:
828
+ // Set start time for duration tracking
829
+ req['startTime'] = Date.now();
830
+ timedOut = false;
831
+ _o.label = 1;
832
+ case 1:
833
+ _o.trys.push([1, 23, , 24]);
834
+ // Handle timeout setup
835
+ if (timeout) {
836
+ timeoutId = setTimeout(function () {
837
+ if (!res.headersSent && !timedOut) {
838
+ timedOut = true;
839
+ var errorResponse = createFinalErrorResponse(req, HttpStatusCodes.REQUEST_TIMEOUT, 'Request timed out');
840
+ res.status(HttpStatusCodes.REQUEST_TIMEOUT).json(errorResponse);
841
+ }
842
+ }, timeout.ms);
843
+ }
844
+ if (timedOut)
845
+ return [2 /*return*/];
846
+ if (!rateLimiter) return [3 /*break*/, 3];
847
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
848
+ rateLimiter(req, res, function (err) {
849
+ if (err)
850
+ reject(err);
851
+ else
852
+ resolve();
853
+ });
854
+ })];
855
+ case 2:
856
+ _o.sent();
857
+ _o.label = 3;
858
+ case 3:
859
+ // Handle content type
860
+ if (!res.headersSent && contentType) {
861
+ res.setHeader('Content-Type', contentType.type);
862
+ }
863
+ // Handle versioning header
864
+ if (((_j = version === null || version === void 0 ? void 0 : version.options) === null || _j === void 0 ? void 0 : _j.addHeader) && ((_k = version === null || version === void 0 ? void 0 : version.options) === null || _k === void 0 ? void 0 : _k.headerName) && (version === null || version === void 0 ? void 0 : version.version)) {
865
+ if (!res.headersSent) {
866
+ res.setHeader(version.options.headerName, version.version);
867
+ }
868
+ }
869
+ // Handle caching
870
+ if (cache && !res.headersSent) {
871
+ res.setHeader('Cache-Control', "public, max-age=".concat(cache.ttlSeconds));
872
+ }
873
+ // Handle logging - entry
874
+ if (logConfig === null || logConfig === void 0 ? void 0 : logConfig.logEntry) {
875
+ logger = getLogger();
876
+ logData = {
877
+ method: req.method,
878
+ url: req.originalUrl || req.url,
879
+ userAgent: req.get('User-Agent')
880
+ };
881
+ if (logConfig.logParams) {
882
+ logData.params = req.params;
883
+ logData.query = req.query;
884
+ }
885
+ if (logConfig.logBody)
886
+ logData.body = req.body;
887
+ logger.info({ entry: logData }, 'Route Entry:');
888
+ }
889
+ // Handle roles-based access control
890
+ if (roles.length && !((_m = (_l = req === null || req === void 0 ? void 0 : req.user) === null || _l === void 0 ? void 0 : _l.roles) === null || _m === void 0 ? void 0 : _m.some(function (role) { return roles.includes(role); }))) {
891
+ errorResponse = createFinalErrorResponse(req, HttpStatusCodes.FORBIDDEN, 'Forbidden Insufficient Roles');
892
+ res.status(HttpStatusCodes.FORBIDDEN).json(errorResponse);
893
+ if (timeoutId) {
894
+ clearTimeout(timeoutId);
895
+ }
896
+ return [2 /*return*/];
897
+ }
898
+ // Process static redirect if configured
899
+ if (redirect && redirect.url) {
900
+ if (timeoutId) {
901
+ clearTimeout(timeoutId);
902
+ }
903
+ return [2 /*return*/, res.redirect(redirect.statusCode, redirect.url)];
904
+ }
905
+ _o.label = 4;
906
+ case 4:
907
+ _o.trys.push([4, 9, 10, 11]);
908
+ beforeHooks_1 = __values(beforeHooks), beforeHooks_1_1 = beforeHooks_1.next();
909
+ _o.label = 5;
910
+ case 5:
911
+ if (!!beforeHooks_1_1.done) return [3 /*break*/, 8];
912
+ fn = beforeHooks_1_1.value;
913
+ return [4 /*yield*/, fn(req, res)];
914
+ case 6:
915
+ _o.sent();
916
+ _o.label = 7;
917
+ case 7:
918
+ beforeHooks_1_1 = beforeHooks_1.next();
919
+ return [3 /*break*/, 5];
920
+ case 8: return [3 /*break*/, 11];
921
+ case 9:
922
+ e_1_1 = _o.sent();
923
+ e_1 = { error: e_1_1 };
924
+ return [3 /*break*/, 11];
925
+ case 10:
926
+ try {
927
+ if (beforeHooks_1_1 && !beforeHooks_1_1.done && (_e = beforeHooks_1.return)) _e.call(beforeHooks_1);
928
+ }
929
+ finally { if (e_1) throw e_1.error; }
930
+ return [7 /*endfinally*/];
931
+ case 11:
932
+ args_1 = [];
933
+ if (params.length) {
934
+ params.forEach(function (_a) {
935
+ var _b;
936
+ var index = _a.index, type = _a.type, key = _a.key;
937
+ switch (type) {
938
+ case 'query':
939
+ args_1[index] = key ? req.query[key] : req.query;
940
+ break;
941
+ case 'param':
942
+ args_1[index] = key ? req.params[key] : req.params;
943
+ break;
944
+ case 'body':
945
+ args_1[index] = key ? (_b = req.body) === null || _b === void 0 ? void 0 : _b[key] : req.body;
946
+ break;
947
+ case 'req':
948
+ args_1[index] = req;
949
+ break;
950
+ case 'res':
951
+ args_1[index] = res;
952
+ break;
953
+ }
954
+ });
955
+ }
956
+ result = (_f = instance)[handlerName].apply(_f, __spreadArray([], __read(args_1), false));
957
+ if (!(result instanceof Promise)) return [3 /*break*/, 13];
958
+ return [4 /*yield*/, result];
959
+ case 12:
960
+ _a = _o.sent();
961
+ return [3 /*break*/, 14];
962
+ case 13:
963
+ _a = result;
964
+ _o.label = 14;
965
+ case 14:
966
+ awaited = _a;
967
+ // Clear timeout if operation completed
968
+ if (timeoutId) {
969
+ clearTimeout(timeoutId);
970
+ }
971
+ if (timedOut)
972
+ return [2 /*return*/];
973
+ // Handle dynamic redirects
974
+ if (redirect && awaited && typeof awaited === 'object' && 'url' in awaited) {
975
+ redirectUrl = awaited.url;
976
+ redirectStatus = awaited.statusCode || redirect.statusCode;
977
+ return [2 /*return*/, res.redirect(redirectStatus, redirectUrl)];
978
+ }
979
+ if (!res.headersSent && typeof awaited !== 'undefined') {
980
+ if (httpCode)
981
+ res.status(httpCode);
982
+ try {
983
+ for (_b = __values(Object.entries(headers)), _c = _b.next(); !_c.done; _c = _b.next()) {
984
+ _d = __read(_c.value, 2), k = _d[0], v = _d[1];
985
+ normalized = normalizeHeaderValue(v);
986
+ if (typeof normalized !== 'undefined') {
987
+ res.set(k, normalized);
988
+ }
989
+ }
990
+ }
991
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
992
+ finally {
993
+ try {
994
+ if (_c && !_c.done && (_g = _b.return)) _g.call(_b);
995
+ }
996
+ finally { if (e_3) throw e_3.error; }
997
+ }
998
+ res.json(awaited);
999
+ }
1000
+ // Handle logging - exit
1001
+ if (logConfig === null || logConfig === void 0 ? void 0 : logConfig.logExit) {
1002
+ logger = getLogger();
1003
+ logData = {
1004
+ method: req.method,
1005
+ url: req.originalUrl || req.url,
1006
+ statusCode: res.statusCode,
1007
+ duration: "".concat(Date.now() - req.startTime, "ms")
1008
+ };
1009
+ if (logConfig.logResponse)
1010
+ logData.response = awaited;
1011
+ logger.info({ exit: logData }, 'Route Exit:');
1012
+ }
1013
+ _o.label = 15;
1014
+ case 15:
1015
+ _o.trys.push([15, 20, 21, 22]);
1016
+ afterHooks_1 = __values(afterHooks), afterHooks_1_1 = afterHooks_1.next();
1017
+ _o.label = 16;
1018
+ case 16:
1019
+ if (!!afterHooks_1_1.done) return [3 /*break*/, 19];
1020
+ fn = afterHooks_1_1.value;
1021
+ return [4 /*yield*/, fn(req, res, awaited)];
1022
+ case 17:
1023
+ _o.sent();
1024
+ _o.label = 18;
1025
+ case 18:
1026
+ afterHooks_1_1 = afterHooks_1.next();
1027
+ return [3 /*break*/, 16];
1028
+ case 19: return [3 /*break*/, 22];
1029
+ case 20:
1030
+ e_2_1 = _o.sent();
1031
+ e_2 = { error: e_2_1 };
1032
+ return [3 /*break*/, 22];
1033
+ case 21:
1034
+ try {
1035
+ if (afterHooks_1_1 && !afterHooks_1_1.done && (_h = afterHooks_1.return)) _h.call(afterHooks_1);
1036
+ }
1037
+ finally { if (e_2) throw e_2.error; }
1038
+ return [7 /*endfinally*/];
1039
+ case 22: return [3 /*break*/, 24];
1040
+ case 23:
1041
+ err_1 = _o.sent();
1042
+ if (timeoutId) {
1043
+ clearTimeout(timeoutId);
1044
+ }
1045
+ next(err_1);
1046
+ return [3 /*break*/, 24];
1047
+ case 24: return [2 /*return*/];
1048
+ }
1049
+ });
1050
+ }); };
1051
+ (_b = router)[method].apply(_b, __spreadArray(__spreadArray([basePath + finalPath], __read(middlewares), false), [handler], false));
1052
+ });
1053
+ });
1054
+ }
1055
+ // Export for testing purposes
1056
+ export { rateLimiterCache };
1057
+ //# sourceMappingURL=decorators.utils.js.map