@adaas/a-server 0.0.22 → 0.0.23

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 (516) hide show
  1. package/.conf/tsconfig.base.json +79 -0
  2. package/.conf/tsconfig.browser.json +32 -0
  3. package/.conf/tsconfig.node.json +33 -0
  4. package/LICENSE +10 -19
  5. package/dist/browser/index.d.mts +1669 -0
  6. package/dist/browser/index.mjs +2869 -0
  7. package/dist/browser/index.mjs.map +1 -0
  8. package/dist/node/A-Request.entity-8_9MCXT2.d.ts +533 -0
  9. package/dist/node/A-Request.entity-r905O60G.d.mts +533 -0
  10. package/dist/node/A-Response.entity-BVYAc6-8.d.mts +318 -0
  11. package/dist/node/A-Response.entity-CRc-t-vr.d.ts +318 -0
  12. package/dist/node/channels/A-Http/A-Http.channel.constants.d.mts +9 -0
  13. package/dist/node/channels/A-Http/A-Http.channel.constants.d.ts +9 -0
  14. package/dist/node/channels/A-Http/A-Http.channel.constants.js +13 -0
  15. package/dist/node/channels/A-Http/A-Http.channel.constants.js.map +1 -0
  16. package/dist/node/channels/A-Http/A-Http.channel.constants.mjs +12 -0
  17. package/dist/node/channels/A-Http/A-Http.channel.constants.mjs.map +1 -0
  18. package/dist/node/channels/A-Http/A-Http.channel.d.mts +23 -0
  19. package/dist/node/channels/A-Http/A-Http.channel.d.ts +23 -0
  20. package/dist/node/channels/A-Http/A-Http.channel.error.d.mts +7 -0
  21. package/dist/node/channels/A-Http/A-Http.channel.error.d.ts +7 -0
  22. package/dist/node/channels/A-Http/A-Http.channel.error.js +11 -0
  23. package/dist/node/channels/A-Http/A-Http.channel.error.js.map +1 -0
  24. package/dist/node/channels/A-Http/A-Http.channel.error.mjs +10 -0
  25. package/dist/node/channels/A-Http/A-Http.channel.error.mjs.map +1 -0
  26. package/dist/node/channels/A-Http/A-Http.channel.js +122 -0
  27. package/dist/node/channels/A-Http/A-Http.channel.js.map +1 -0
  28. package/dist/node/channels/A-Http/A-Http.channel.mjs +110 -0
  29. package/dist/node/channels/A-Http/A-Http.channel.mjs.map +1 -0
  30. package/dist/node/channels/A-Http/A-Http.channel.types.d.mts +67 -0
  31. package/dist/node/channels/A-Http/A-Http.channel.types.d.ts +67 -0
  32. package/dist/node/channels/A-Http/A-Http.channel.types.js +4 -0
  33. package/dist/node/channels/A-Http/A-Http.channel.types.js.map +1 -0
  34. package/dist/node/channels/A-Http/A-Http.channel.types.mjs +3 -0
  35. package/dist/node/channels/A-Http/A-Http.channel.types.mjs.map +1 -0
  36. package/dist/node/channels/A-Websockets/A-Websockets.channel.d.mts +7 -0
  37. package/dist/node/channels/A-Websockets/A-Websockets.channel.d.ts +7 -0
  38. package/dist/node/channels/A-Websockets/A-Websockets.channel.js +13 -0
  39. package/dist/node/channels/A-Websockets/A-Websockets.channel.js.map +1 -0
  40. package/dist/node/channels/A-Websockets/A-Websockets.channel.mjs +12 -0
  41. package/dist/node/channels/A-Websockets/A-Websockets.channel.mjs.map +1 -0
  42. package/dist/node/chunk-EQQGB2QZ.mjs +15 -0
  43. package/dist/node/chunk-EQQGB2QZ.mjs.map +1 -0
  44. package/dist/node/constants/env.constants.d.mts +12 -0
  45. package/dist/node/constants/env.constants.d.ts +12 -0
  46. package/dist/node/constants/env.constants.js +23 -0
  47. package/dist/node/constants/env.constants.js.map +1 -0
  48. package/dist/node/constants/env.constants.mjs +22 -0
  49. package/dist/node/constants/env.constants.mjs.map +1 -0
  50. package/dist/node/controllers/A-CommandController/A-CommandController.component.d.mts +29 -0
  51. package/dist/node/controllers/A-CommandController/A-CommandController.component.d.ts +29 -0
  52. package/dist/node/controllers/A-CommandController/A-CommandController.component.js +55 -0
  53. package/dist/node/controllers/A-CommandController/A-CommandController.component.js.map +1 -0
  54. package/dist/node/controllers/A-CommandController/A-CommandController.component.mjs +43 -0
  55. package/dist/node/controllers/A-CommandController/A-CommandController.component.mjs.map +1 -0
  56. package/dist/node/controllers/A-EntityController/A-EntityController.component.d.mts +44 -0
  57. package/dist/node/controllers/A-EntityController/A-EntityController.component.d.ts +44 -0
  58. package/dist/node/controllers/A-EntityController/A-EntityController.component.js +189 -0
  59. package/dist/node/controllers/A-EntityController/A-EntityController.component.js.map +1 -0
  60. package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs +177 -0
  61. package/dist/node/controllers/A-EntityController/A-EntityController.component.mjs.map +1 -0
  62. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.d.mts +2 -0
  63. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.d.ts +2 -0
  64. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.js +4 -0
  65. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.js.map +1 -0
  66. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.mjs +3 -0
  67. package/dist/node/controllers/A-EntityController/A-EntityController.component.types.mjs.map +1 -0
  68. package/dist/node/controllers/A-ListingController/A-ListingController.component.d.mts +28 -0
  69. package/dist/node/controllers/A-ListingController/A-ListingController.component.d.ts +28 -0
  70. package/dist/node/controllers/A-ListingController/A-ListingController.component.js +59 -0
  71. package/dist/node/controllers/A-ListingController/A-ListingController.component.js.map +1 -0
  72. package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs +47 -0
  73. package/dist/node/controllers/A-ListingController/A-ListingController.component.mjs.map +1 -0
  74. package/dist/node/controllers/A-ListingController/A-ListingController.types.d.mts +2 -0
  75. package/dist/node/controllers/A-ListingController/A-ListingController.types.d.ts +2 -0
  76. package/dist/node/controllers/A-ListingController/A-ListingController.types.js +4 -0
  77. package/dist/node/controllers/A-ListingController/A-ListingController.types.js.map +1 -0
  78. package/dist/node/controllers/A-ListingController/A-ListingController.types.mjs +3 -0
  79. package/dist/node/controllers/A-ListingController/A-ListingController.types.mjs.map +1 -0
  80. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.mts +30 -0
  81. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +30 -0
  82. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +46 -0
  83. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -0
  84. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs +34 -0
  85. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.component.mjs.map +1 -0
  86. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.d.mts +2 -0
  87. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.d.ts +2 -0
  88. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.js +4 -0
  89. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.js.map +1 -0
  90. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.mjs +3 -0
  91. package/dist/node/controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.mjs.map +1 -0
  92. package/dist/node/index.d.mts +51 -0
  93. package/dist/node/index.d.ts +51 -0
  94. package/dist/node/index.js +320 -0
  95. package/dist/node/index.js.map +1 -0
  96. package/dist/node/index.mjs +48 -0
  97. package/dist/node/index.mjs.map +1 -0
  98. package/dist/node/lib/A-Request/A-HttpRequestData.context.d.mts +12 -0
  99. package/dist/node/lib/A-Request/A-HttpRequestData.context.d.ts +12 -0
  100. package/dist/node/lib/A-Request/A-HttpRequestData.context.js +25 -0
  101. package/dist/node/lib/A-Request/A-HttpRequestData.context.js.map +1 -0
  102. package/dist/node/lib/A-Request/A-HttpRequestData.context.mjs +24 -0
  103. package/dist/node/lib/A-Request/A-HttpRequestData.context.mjs.map +1 -0
  104. package/dist/node/lib/A-Request/A-HttpServerRequest.context.d.mts +39 -0
  105. package/dist/node/lib/A-Request/A-HttpServerRequest.context.d.ts +39 -0
  106. package/dist/node/lib/A-Request/A-HttpServerRequest.context.js +56 -0
  107. package/dist/node/lib/A-Request/A-HttpServerRequest.context.js.map +1 -0
  108. package/dist/node/lib/A-Request/A-HttpServerRequest.context.mjs +55 -0
  109. package/dist/node/lib/A-Request/A-HttpServerRequest.context.mjs.map +1 -0
  110. package/dist/node/lib/A-Request/A-Request.constants.d.mts +18 -0
  111. package/dist/node/lib/A-Request/A-Request.constants.d.ts +18 -0
  112. package/dist/node/lib/A-Request/A-Request.constants.js +22 -0
  113. package/dist/node/lib/A-Request/A-Request.constants.js.map +1 -0
  114. package/dist/node/lib/A-Request/A-Request.constants.mjs +22 -0
  115. package/dist/node/lib/A-Request/A-Request.constants.mjs.map +1 -0
  116. package/dist/node/lib/A-Request/A-Request.entity.d.mts +17 -0
  117. package/dist/node/lib/A-Request/A-Request.entity.d.ts +17 -0
  118. package/dist/node/lib/A-Request/A-Request.entity.js +651 -0
  119. package/dist/node/lib/A-Request/A-Request.entity.js.map +1 -0
  120. package/dist/node/lib/A-Request/A-Request.entity.mjs +639 -0
  121. package/dist/node/lib/A-Request/A-Request.entity.mjs.map +1 -0
  122. package/dist/node/lib/A-Request/A-Request.env.d.mts +37 -0
  123. package/dist/node/lib/A-Request/A-Request.env.d.ts +37 -0
  124. package/dist/node/lib/A-Request/A-Request.env.js +39 -0
  125. package/dist/node/lib/A-Request/A-Request.env.js.map +1 -0
  126. package/dist/node/lib/A-Request/A-Request.env.mjs +38 -0
  127. package/dist/node/lib/A-Request/A-Request.env.mjs.map +1 -0
  128. package/dist/node/lib/A-Request/A-Request.error.d.mts +11 -0
  129. package/dist/node/lib/A-Request/A-Request.error.d.ts +11 -0
  130. package/dist/node/lib/A-Request/A-Request.error.js +15 -0
  131. package/dist/node/lib/A-Request/A-Request.error.js.map +1 -0
  132. package/dist/node/lib/A-Request/A-Request.error.mjs +14 -0
  133. package/dist/node/lib/A-Request/A-Request.error.mjs.map +1 -0
  134. package/dist/node/lib/A-Request/A-Request.helper.d.mts +105 -0
  135. package/dist/node/lib/A-Request/A-Request.helper.d.ts +105 -0
  136. package/dist/node/lib/A-Request/A-Request.helper.js +181 -0
  137. package/dist/node/lib/A-Request/A-Request.helper.js.map +1 -0
  138. package/dist/node/lib/A-Request/A-Request.helper.mjs +180 -0
  139. package/dist/node/lib/A-Request/A-Request.helper.mjs.map +1 -0
  140. package/dist/node/lib/A-Request/A-Request.types.d.mts +17 -0
  141. package/dist/node/lib/A-Request/A-Request.types.d.ts +17 -0
  142. package/dist/node/lib/A-Request/A-Request.types.js +14 -0
  143. package/dist/node/lib/A-Request/A-Request.types.js.map +1 -0
  144. package/dist/node/lib/A-Request/A-Request.types.mjs +14 -0
  145. package/dist/node/lib/A-Request/A-Request.types.mjs.map +1 -0
  146. package/dist/node/lib/A-Response/A-Response.constants.d.mts +24 -0
  147. package/dist/node/lib/A-Response/A-Response.constants.d.ts +24 -0
  148. package/dist/node/lib/A-Response/A-Response.constants.js +28 -0
  149. package/dist/node/lib/A-Response/A-Response.constants.js.map +1 -0
  150. package/dist/node/lib/A-Response/A-Response.constants.mjs +28 -0
  151. package/dist/node/lib/A-Response/A-Response.constants.mjs.map +1 -0
  152. package/dist/node/lib/A-Response/A-Response.entity.d.mts +20 -0
  153. package/dist/node/lib/A-Response/A-Response.entity.d.ts +20 -0
  154. package/dist/node/lib/A-Response/A-Response.entity.js +544 -0
  155. package/dist/node/lib/A-Response/A-Response.entity.js.map +1 -0
  156. package/dist/node/lib/A-Response/A-Response.entity.mjs +532 -0
  157. package/dist/node/lib/A-Response/A-Response.entity.mjs.map +1 -0
  158. package/dist/node/lib/A-Response/A-Response.env.d.mts +2 -0
  159. package/dist/node/lib/A-Response/A-Response.env.d.ts +2 -0
  160. package/dist/node/lib/A-Response/A-Response.env.js +4 -0
  161. package/dist/node/lib/A-Response/A-Response.env.js.map +1 -0
  162. package/dist/node/lib/A-Response/A-Response.env.mjs +3 -0
  163. package/dist/node/lib/A-Response/A-Response.env.mjs.map +1 -0
  164. package/dist/node/lib/A-Response/A-Response.error.d.mts +6 -0
  165. package/dist/node/lib/A-Response/A-Response.error.d.ts +6 -0
  166. package/dist/node/lib/A-Response/A-Response.error.js +10 -0
  167. package/dist/node/lib/A-Response/A-Response.error.js.map +1 -0
  168. package/dist/node/lib/A-Response/A-Response.error.mjs +9 -0
  169. package/dist/node/lib/A-Response/A-Response.error.mjs.map +1 -0
  170. package/dist/node/lib/A-Response/A-Response.types.d.mts +20 -0
  171. package/dist/node/lib/A-Response/A-Response.types.d.ts +20 -0
  172. package/dist/node/lib/A-Response/A-Response.types.js +4 -0
  173. package/dist/node/lib/A-Response/A-Response.types.js.map +1 -0
  174. package/dist/node/lib/A-Response/A-Response.types.mjs +3 -0
  175. package/dist/node/lib/A-Response/A-Response.types.mjs.map +1 -0
  176. package/dist/node/lib/A-Server/A-HttpServer.constants.d.mts +7 -0
  177. package/dist/node/lib/A-Server/A-HttpServer.constants.d.ts +7 -0
  178. package/dist/node/lib/A-Server/A-HttpServer.constants.js +11 -0
  179. package/dist/node/lib/A-Server/A-HttpServer.constants.js.map +1 -0
  180. package/dist/node/lib/A-Server/A-HttpServer.constants.mjs +11 -0
  181. package/dist/node/lib/A-Server/A-HttpServer.constants.mjs.map +1 -0
  182. package/dist/node/lib/A-Server/A-HttpServer.container.d.mts +50 -0
  183. package/dist/node/lib/A-Server/A-HttpServer.container.d.ts +50 -0
  184. package/dist/node/lib/A-Server/A-HttpServer.container.js +194 -0
  185. package/dist/node/lib/A-Server/A-HttpServer.container.js.map +1 -0
  186. package/dist/node/lib/A-Server/A-HttpServer.container.mjs +182 -0
  187. package/dist/node/lib/A-Server/A-HttpServer.container.mjs.map +1 -0
  188. package/dist/node/lib/A-Server/A-HttpServer.error.d.mts +54 -0
  189. package/dist/node/lib/A-Server/A-HttpServer.error.d.ts +54 -0
  190. package/dist/node/lib/A-Server/A-HttpServer.error.js +118 -0
  191. package/dist/node/lib/A-Server/A-HttpServer.error.js.map +1 -0
  192. package/dist/node/lib/A-Server/A-HttpServer.error.mjs +117 -0
  193. package/dist/node/lib/A-Server/A-HttpServer.error.mjs.map +1 -0
  194. package/dist/node/lib/A-Server/A-HttpServer.types.d.mts +19 -0
  195. package/dist/node/lib/A-Server/A-HttpServer.types.d.ts +19 -0
  196. package/dist/node/lib/A-Server/A-HttpServer.types.js +4 -0
  197. package/dist/node/lib/A-Server/A-HttpServer.types.js.map +1 -0
  198. package/dist/node/lib/A-Server/A-HttpServer.types.mjs +3 -0
  199. package/dist/node/lib/A-Server/A-HttpServer.types.mjs.map +1 -0
  200. package/dist/node/lib/A-Server/A-Server.context.d.mts +22 -0
  201. package/dist/node/lib/A-Server/A-Server.context.d.ts +22 -0
  202. package/dist/node/lib/A-Server/A-Server.context.js +24 -0
  203. package/dist/node/lib/A-Server/A-Server.context.js.map +1 -0
  204. package/dist/node/lib/A-Server/A-Server.context.mjs +23 -0
  205. package/dist/node/lib/A-Server/A-Server.context.mjs.map +1 -0
  206. package/dist/node/lib/A-Server/A-Server.error.d.mts +14 -0
  207. package/dist/node/lib/A-Server/A-Server.error.d.ts +14 -0
  208. package/dist/node/lib/A-Server/A-Server.error.js +26 -0
  209. package/dist/node/lib/A-Server/A-Server.error.js.map +1 -0
  210. package/dist/node/lib/A-Server/A-Server.error.mjs +25 -0
  211. package/dist/node/lib/A-Server/A-Server.error.mjs.map +1 -0
  212. package/dist/node/lib/A-Server/A-Server.types.d.mts +26 -0
  213. package/dist/node/lib/A-Server/A-Server.types.d.ts +26 -0
  214. package/dist/node/lib/A-Server/A-Server.types.js +4 -0
  215. package/dist/node/lib/A-Server/A-Server.types.js.map +1 -0
  216. package/dist/node/lib/A-Server/A-Server.types.mjs +3 -0
  217. package/dist/node/lib/A-Server/A-Server.types.mjs.map +1 -0
  218. package/dist/node/lib/A-ServerController/A-ServerController.component.d.mts +29 -0
  219. package/dist/node/lib/A-ServerController/A-ServerController.component.d.ts +29 -0
  220. package/dist/node/lib/A-ServerController/A-ServerController.component.js +49 -0
  221. package/dist/node/lib/A-ServerController/A-ServerController.component.js.map +1 -0
  222. package/dist/node/lib/A-ServerController/A-ServerController.component.mjs +37 -0
  223. package/dist/node/lib/A-ServerController/A-ServerController.component.mjs.map +1 -0
  224. package/dist/node/lib/A-ServerController/A-ServerController.types.d.mts +2 -0
  225. package/dist/node/lib/A-ServerController/A-ServerController.types.d.ts +2 -0
  226. package/dist/node/lib/A-ServerController/A-ServerController.types.js +4 -0
  227. package/dist/node/lib/A-ServerController/A-ServerController.types.js.map +1 -0
  228. package/dist/node/lib/A-ServerController/A-ServerController.types.mjs +3 -0
  229. package/dist/node/lib/A-ServerController/A-ServerController.types.mjs.map +1 -0
  230. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.mts +49 -0
  231. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.d.ts +49 -0
  232. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js +91 -0
  233. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.js.map +1 -0
  234. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs +90 -0
  235. package/dist/node/lib/A-ServerEntityList/A-EntityList.entity.mjs.map +1 -0
  236. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.mts +22 -0
  237. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.d.ts +22 -0
  238. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.js +10 -0
  239. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.js.map +1 -0
  240. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.mjs +10 -0
  241. package/dist/node/lib/A-ServerEntityList/A-EntityList.types.mjs.map +1 -0
  242. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.d.mts +13 -0
  243. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.d.ts +13 -0
  244. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.js +32 -0
  245. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.js.map +1 -0
  246. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.mjs +31 -0
  247. package/dist/node/lib/A-ServerListQuery/A-ServerListQueryFilter.context.mjs.map +1 -0
  248. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.mts +48 -0
  249. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.d.ts +48 -0
  250. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js +88 -0
  251. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.js.map +1 -0
  252. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs +76 -0
  253. package/dist/node/lib/A-ServerLogger/A-ServerLogger.component.mjs.map +1 -0
  254. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.d.mts +24 -0
  255. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.d.ts +24 -0
  256. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.js +33 -0
  257. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.js.map +1 -0
  258. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.mjs +33 -0
  259. package/dist/node/lib/A-ServerLogger/A-ServerLogger.constants.mjs.map +1 -0
  260. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.d.mts +12 -0
  261. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.d.ts +12 -0
  262. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.js +4 -0
  263. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.js.map +1 -0
  264. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.mjs +3 -0
  265. package/dist/node/lib/A-ServerLogger/A-ServerLogger.types.mjs.map +1 -0
  266. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.d.mts +6 -0
  267. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.d.ts +6 -0
  268. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.js +18 -0
  269. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.js.map +1 -0
  270. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.mjs +17 -0
  271. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.component.mjs.map +1 -0
  272. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.d.mts +2 -0
  273. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.d.ts +2 -0
  274. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.js +4 -0
  275. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.js.map +1 -0
  276. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.mjs +3 -0
  277. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.constants.mjs.map +1 -0
  278. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.d.mts +2 -0
  279. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.d.ts +2 -0
  280. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.js +4 -0
  281. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.js.map +1 -0
  282. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.mjs +3 -0
  283. package/dist/node/lib/A-ServerMiddleware/A-ServerMiddleware.types.mjs.map +1 -0
  284. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.mts +31 -0
  285. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.d.ts +31 -0
  286. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.js +90 -0
  287. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.js.map +1 -0
  288. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.mjs +78 -0
  289. package/dist/node/lib/A-ServerProxy/A-ServerProxy.component.mjs.map +1 -0
  290. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.d.mts +9 -0
  291. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.d.ts +9 -0
  292. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.js +14 -0
  293. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.js.map +1 -0
  294. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.mjs +14 -0
  295. package/dist/node/lib/A-ServerProxy/A-ServerProxy.constants.mjs.map +1 -0
  296. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.d.mts +36 -0
  297. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.d.ts +36 -0
  298. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.js +60 -0
  299. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.js.map +1 -0
  300. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.mjs +59 -0
  301. package/dist/node/lib/A-ServerProxy/A-ServerProxy.context.mjs.map +1 -0
  302. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.d.mts +23 -0
  303. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.d.ts +23 -0
  304. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.js +4 -0
  305. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.js.map +1 -0
  306. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.mjs +3 -0
  307. package/dist/node/lib/A-ServerProxy/A-ServerProxy.types.mjs.map +1 -0
  308. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.d.mts +20 -0
  309. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.d.ts +20 -0
  310. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.js +25 -0
  311. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.js.map +1 -0
  312. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.mjs +24 -0
  313. package/dist/node/lib/A-ServerRoute/A-ServerRoute.constants.mjs.map +1 -0
  314. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.d.mts +15 -0
  315. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.d.ts +15 -0
  316. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.js +24 -0
  317. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.js.map +1 -0
  318. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.mjs +23 -0
  319. package/dist/node/lib/A-ServerRoute/A-ServerRoute.entity.mjs.map +1 -0
  320. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.d.mts +6 -0
  321. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.d.ts +6 -0
  322. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.js +4 -0
  323. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.js.map +1 -0
  324. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.mjs +3 -0
  325. package/dist/node/lib/A-ServerRoute/A-ServerRoute.types.mjs.map +1 -0
  326. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.mts +84 -0
  327. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.d.ts +84 -0
  328. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.js +194 -0
  329. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.js.map +1 -0
  330. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.mjs +184 -0
  331. package/dist/node/lib/A-ServerRouter/A-ServerRouter.component.mjs.map +1 -0
  332. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.d.mts +6 -0
  333. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.d.ts +6 -0
  334. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.js +10 -0
  335. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.js.map +1 -0
  336. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.mjs +10 -0
  337. package/dist/node/lib/A-ServerRouter/A-ServerRouter.constants.mjs.map +1 -0
  338. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.d.mts +16 -0
  339. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.d.ts +16 -0
  340. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.js +40 -0
  341. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.js.map +1 -0
  342. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.mjs +39 -0
  343. package/dist/node/lib/A-ServerRouter/A-ServerRouter.meta.mjs.map +1 -0
  344. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.d.mts +24 -0
  345. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.d.ts +24 -0
  346. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.js +4 -0
  347. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.js.map +1 -0
  348. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.mjs +3 -0
  349. package/dist/node/lib/A-ServerRouter/A-ServerRouter.types.mjs.map +1 -0
  350. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.d.mts +16 -0
  351. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.d.ts +16 -0
  352. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.js +25 -0
  353. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.js.map +1 -0
  354. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.mjs +24 -0
  355. package/dist/node/lib/A-ServerRouter/A-ServerRouterDefine.decorator.mjs.map +1 -0
  356. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.mts +65 -0
  357. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.d.ts +65 -0
  358. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.js +260 -0
  359. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.js.map +1 -0
  360. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.mjs +248 -0
  361. package/dist/node/lib/A-ServerStatic/A-ServerStatic.component.mjs.map +1 -0
  362. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.d.mts +110 -0
  363. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.d.ts +110 -0
  364. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.js +180 -0
  365. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.js.map +1 -0
  366. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.mjs +179 -0
  367. package/dist/node/lib/A-ServerStatic/A-ServerStatic.context.mjs.map +1 -0
  368. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.d.mts +8 -0
  369. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.d.ts +8 -0
  370. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.js +4 -0
  371. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.js.map +1 -0
  372. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.mjs +3 -0
  373. package/dist/node/lib/A-ServerStatic/A-ServerStatic.types.mjs.map +1 -0
  374. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.mts +29 -0
  375. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.d.ts +29 -0
  376. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js +62 -0
  377. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.js.map +1 -0
  378. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs +50 -0
  379. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.component.mjs.map +1 -0
  380. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.d.mts +5 -0
  381. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.d.ts +5 -0
  382. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.js +14 -0
  383. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.js.map +1 -0
  384. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.mjs +14 -0
  385. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.constants.mjs.map +1 -0
  386. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.d.mts +9 -0
  387. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.d.ts +9 -0
  388. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.js +4 -0
  389. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.js.map +1 -0
  390. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.mjs +3 -0
  391. package/dist/node/middlewares/A-ServerCORS/A_ServerCORS.types.mjs.map +1 -0
  392. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.mts +24 -0
  393. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.d.ts +24 -0
  394. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.js +94 -0
  395. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.js.map +1 -0
  396. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.mjs +82 -0
  397. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.component.mjs.map +1 -0
  398. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.d.mts +2 -0
  399. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.d.ts +2 -0
  400. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.js +4 -0
  401. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.js.map +1 -0
  402. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.mjs +3 -0
  403. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.error.mjs.map +1 -0
  404. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.d.mts +2 -0
  405. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.d.ts +2 -0
  406. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.js +4 -0
  407. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.js.map +1 -0
  408. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.mjs +3 -0
  409. package/dist/node/repositories/A-EntityRepository/A-EntityRepository.types.mjs.map +1 -0
  410. package/examples/simple-server/commands/SignIn.command.ts +17 -1
  411. package/examples/simple-server/components/Test.controller.ts +8 -7
  412. package/examples/simple-server/components/Users.repository.ts +28 -26
  413. package/examples/simple-server/concept.ts +56 -66
  414. package/examples/simple-server/entities/User/User.entity.ts +17 -7
  415. package/jest.config.ts +24 -10
  416. package/package.json +267 -25
  417. package/src/channels/A-Http/A-Http.channel.constants.ts +6 -7
  418. package/src/channels/A-Http/A-Http.channel.error.ts +2 -2
  419. package/src/channels/A-Http/A-Http.channel.ts +76 -125
  420. package/src/channels/A-Http/A-Http.channel.types.ts +6 -3
  421. package/src/channels/A-Websockets/A-Websockets.channel.ts +1 -1
  422. package/src/{components → controllers}/A-CommandController/A-CommandController.component.ts +16 -10
  423. package/src/{components → controllers}/A-EntityController/A-EntityController.component.ts +24 -28
  424. package/src/{components → controllers}/A-ListingController/A-ListingController.component.ts +10 -12
  425. package/src/{components → controllers}/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +11 -11
  426. package/src/index.ts +58 -63
  427. package/src/lib/A-Request/A-HttpRequestData.context.ts +30 -0
  428. package/src/lib/A-Request/A-HttpServerRequest.context.ts +103 -0
  429. package/src/lib/A-Request/A-Request.constants.ts +30 -0
  430. package/src/lib/A-Request/A-Request.entity.ts +844 -0
  431. package/src/lib/A-Request/A-Request.env.ts +50 -0
  432. package/src/lib/A-Request/A-Request.error.ts +11 -0
  433. package/src/lib/A-Request/A-Request.helper.ts +276 -0
  434. package/src/lib/A-Request/A-Request.types.ts +284 -0
  435. package/src/lib/A-Request/README.md +567 -0
  436. package/src/lib/A-Response/A-Response.constants.ts +24 -0
  437. package/src/lib/A-Response/A-Response.entity.ts +689 -0
  438. package/src/lib/A-Response/A-Response.error.ts +6 -0
  439. package/src/lib/A-Response/A-Response.types.ts +127 -0
  440. package/src/lib/A-Response/README.md +793 -0
  441. package/src/lib/A-Server/A-HttpServer.constants.ts +9 -0
  442. package/src/lib/A-Server/A-HttpServer.container.ts +251 -0
  443. package/src/lib/A-Server/A-HttpServer.error.ts +165 -0
  444. package/src/lib/A-Server/A-HttpServer.types.ts +37 -0
  445. package/src/{context/A-Server/A_Server.context.ts → lib/A-Server/A-Server.context.ts} +6 -7
  446. package/src/lib/A-Server/A-Server.error.ts +26 -0
  447. package/src/{components/A-ServerError/A-ServerError.types.ts → lib/A-Server/A-Server.types.ts} +8 -0
  448. package/src/{components/A-Controller/A-Controller.component.ts → lib/A-ServerController/A-ServerController.component.ts} +5 -5
  449. package/src/{entities/A_EntityList/A_EntityList.entity.ts → lib/A-ServerEntityList/A-EntityList.entity.ts} +2 -2
  450. package/src/{entities/A_EntityList/A_EntityList.entity.types.ts → lib/A-ServerEntityList/A-EntityList.types.ts} +2 -2
  451. package/src/{context/A-ListQueryFilter/A_ListQueryFilter.context.ts → lib/A-ServerListQuery/A-ServerListQueryFilter.context.ts} +1 -1
  452. package/src/lib/A-ServerLogger/A-ServerLogger.component.ts +121 -0
  453. package/src/lib/A-ServerLogger/A-ServerLogger.types.ts +13 -0
  454. package/src/lib/A-ServerMiddleware/A-ServerMiddleware.component.ts +17 -0
  455. package/src/{components → lib}/A-ServerProxy/A-ServerProxy.component.ts +17 -12
  456. package/src/{context/A-ProxyConfig/A_ProxyConfig.constants.ts → lib/A-ServerProxy/A-ServerProxy.constants.ts} +1 -1
  457. package/src/{context/A-ProxyConfig/A_ProxyConfig.context.ts → lib/A-ServerProxy/A-ServerProxy.context.ts} +4 -4
  458. package/src/{context/A-ProxyConfig/A_ProxyConfig.types.ts → lib/A-ServerProxy/A-ServerProxy.types.ts} +4 -4
  459. package/src/lib/A-ServerRoute/A-ServerRoute.constants.ts +20 -0
  460. package/src/lib/A-ServerRoute/A-ServerRoute.entity.ts +48 -0
  461. package/src/lib/A-ServerRoute/A-ServerRoute.types.ts +6 -0
  462. package/src/{components/A-Router/A-Router.component.ts → lib/A-ServerRouter/A-ServerRouter.component.ts} +77 -97
  463. package/src/lib/A-ServerRouter/A-ServerRouter.constants.ts +8 -0
  464. package/src/lib/A-ServerRouter/A-ServerRouter.meta.ts +48 -0
  465. package/src/lib/A-ServerRouter/A-ServerRouter.types.ts +27 -0
  466. package/src/lib/A-ServerRouter/A-ServerRouterDefine.decorator.ts +37 -0
  467. package/src/{components/A-StaticLoader/A-StaticLoader.component.ts → lib/A-ServerStatic/A-ServerStatic.component.ts} +73 -54
  468. package/src/{context/A-StaticConfig/A-StaticConfig.context.ts → lib/A-ServerStatic/A-ServerStatic.context.ts} +16 -6
  469. package/src/{components → middlewares}/A-ServerCORS/A_ServerCORS.component.ts +16 -13
  470. package/src/{components/A-ServerCORS/A_ServerCORS.component.defaults.ts → middlewares/A-ServerCORS/A_ServerCORS.constants.ts} +2 -2
  471. package/src/{components → repositories}/A-EntityRepository/A-EntityRepository.component.ts +39 -30
  472. package/tests/A-HttpChannel.test.ts +41 -48
  473. package/tests/A-HttpServerError.test.ts +204 -0
  474. package/tests/A-Request.test.ts +351 -0
  475. package/tsconfig.json +40 -50
  476. package/tsup.config.ts +111 -13
  477. package/dist/index.d.mts +0 -855
  478. package/dist/index.d.ts +0 -855
  479. package/dist/index.js +0 -2179
  480. package/dist/index.js.map +0 -1
  481. package/dist/index.mjs +0 -2144
  482. package/dist/index.mjs.map +0 -1
  483. package/examples/microservices-server/components/controllers/Statistics.controller.ts +0 -18
  484. package/examples/microservices-server/components/repositories/Memory.repository.ts +0 -66
  485. package/examples/microservices-server/concept.ts +0 -43
  486. package/examples/microservices-server/context/MemoryStore.context.ts +0 -31
  487. package/examples/microservices-server/entities/Order.entity.ts +0 -7
  488. package/examples/microservices-server/entities/User.entity.ts +0 -8
  489. package/src/components/A-Router/A-Router.component.types.ts +0 -38
  490. package/src/components/A-ServerError/A-ServerError.class.ts +0 -98
  491. package/src/components/A-ServerLogger/A_ServerLogger.component.ts +0 -194
  492. package/src/components/A-ServerLogger/A_ServerLogger.component.types.ts +0 -14
  493. package/src/containers/A-Service/A-Service.container.ts +0 -218
  494. package/src/containers/A-Service/A-Service.container.types.ts +0 -46
  495. package/src/context/A-EntityFactory/A-EntityFactory.context.ts +0 -163
  496. package/src/context/A-EntityFactory/A-EntityFactory.context.types.ts +0 -11
  497. package/src/context/A-HttpChannel/A-HttpChannel.context.ts +0 -36
  498. package/src/context/A-Server/A_Server.context.types.ts +0 -9
  499. package/src/entities/A-Request/A-Request.entity.ts +0 -163
  500. package/src/entities/A-Request/A-Request.entity.types.ts +0 -41
  501. package/src/entities/A-Response/A-Response.entity.ts +0 -194
  502. package/src/entities/A-Response/A-Response.entity.types.ts +0 -26
  503. package/src/entities/A-Route/A-Route.entity.ts +0 -117
  504. package/tests/A-Service.test.ts +0 -18
  505. /package/src/{components → controllers}/A-EntityController/A-EntityController.component.types.ts +0 -0
  506. /package/src/{components/A-Controller/A-Controller.component.types.ts → controllers/A-ListingController/A-ListingController.types.ts} +0 -0
  507. /package/src/{components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.types.ts → controllers/A-ServerHealthMonitor/A-ServerHealthMonitor.types.ts} +0 -0
  508. /package/src/{components/A-EntityRepository/A-EntityRepository.error.ts → lib/A-Response/A-Response.env.ts} +0 -0
  509. /package/src/{components/A-EntityRepository/A-EntityRepository.types.ts → lib/A-ServerController/A-ServerController.types.ts} +0 -0
  510. /package/src/{components → lib}/A-ServerLogger/A-ServerLogger.constants.ts +0 -0
  511. /package/src/{components/A-ListingController/A-ListingController.component.types.ts → lib/A-ServerMiddleware/A-ServerMiddleware.constants.ts} +0 -0
  512. /package/src/{components/A-ServerError/A-ServerError.constants.ts → lib/A-ServerMiddleware/A-ServerMiddleware.types.ts} +0 -0
  513. /package/src/{components/A-StaticLoader/A-StaticLoader.component.types.ts → lib/A-ServerStatic/A-ServerStatic.types.ts} +0 -0
  514. /package/src/{components/A-ServerCORS/A_ServerCORS.component.types.ts → middlewares/A-ServerCORS/A_ServerCORS.types.ts} +0 -0
  515. /package/src/{context/A-StaticConfig/A-StaticConfig.context.types.ts → repositories/A-EntityRepository/A-EntityRepository.error.ts} +0 -0
  516. /package/src/{entities/A-Route/A-Route.entity.types.ts → repositories/A-EntityRepository/A-EntityRepository.types.ts} +0 -0
@@ -0,0 +1,2869 @@
1
+ import { A_ExecutionContext } from '@adaas/a-utils/a-execution';
2
+ import { A_Feature, A_Inject, A_Error, A_IdentityHelper, A_Scope, A_Dependency, A_Concept, A_Meta, A_Entity, ASEID, A_Context, A_Fragment, A_ComponentMeta, A_Component, A_TypeGuards, A_Feature_Define, A_Feature_Extend, A_Container } from '@adaas/a-concept';
3
+ import { A_OperationContext } from '@adaas/a-utils/a-operation';
4
+ import { A_ScheduleObject } from '@adaas/a-utils/a-schedule';
5
+ import { A_Config } from '@adaas/a-utils/a-config';
6
+ import { Readable, pipeline } from 'stream';
7
+ import { A_Route } from '@adaas/a-utils/a-route';
8
+ import { A_Logger } from '@adaas/a-utils/a-logger';
9
+ import { A_Service, A_ServiceFeatures } from '@adaas/a-utils/a-service';
10
+ import { A_Polyfill } from '@adaas/a-utils/a-polyfill';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __decorateClass = (decorators, target, key, kind) => {
15
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
16
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
17
+ if (decorator = decorators[i])
18
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19
+ if (kind && result) __defProp(target, key, result);
20
+ return result;
21
+ };
22
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
23
+ var A_HttpRequestData = class extends A_ExecutionContext {
24
+ constructor(data) {
25
+ super(
26
+ "a-http-request-data"
27
+ );
28
+ this._meta.set("data", data);
29
+ }
30
+ get length() {
31
+ return this.data?.length || 0;
32
+ }
33
+ get data() {
34
+ return this._meta.get("data");
35
+ }
36
+ toString(encoding = "utf-8") {
37
+ return this.data.toString(encoding);
38
+ }
39
+ };
40
+ var A_HttpServerRequestContext = class extends A_OperationContext {
41
+ get _request() {
42
+ return super.params.request;
43
+ }
44
+ get _response() {
45
+ return super.params.response;
46
+ }
47
+ constructor(request, response) {
48
+ super("http-server-request", { request, response });
49
+ this._id = A_IdentityHelper.generateTimeId();
50
+ }
51
+ get id() {
52
+ return `[${this._request.method}]${this._request.url}-${this._id}`;
53
+ }
54
+ get buffers() {
55
+ if (!this._meta.has("buffers")) {
56
+ this._meta.set("buffers", []);
57
+ }
58
+ return this._meta.get("buffers");
59
+ }
60
+ get contentType() {
61
+ return this._request.headers["content-type"] || void 0;
62
+ }
63
+ get data() {
64
+ return this._meta.get("data");
65
+ }
66
+ set data(value) {
67
+ this._meta.set("data", value);
68
+ }
69
+ get length() {
70
+ return this.buffers.reduce((acc, buf) => acc + buf.length, 0);
71
+ }
72
+ get processingTime() {
73
+ let endTime = this._endTime;
74
+ if (!endTime) {
75
+ endTime = process.hrtime();
76
+ }
77
+ const [seconds, nanoseconds] = process.hrtime(this._startTime);
78
+ return seconds * 1e3 + nanoseconds / 1e6;
79
+ }
80
+ startProcessing() {
81
+ this._startTime = process.hrtime();
82
+ }
83
+ stopProcessing() {
84
+ this._endTime = process.hrtime();
85
+ }
86
+ };
87
+
88
+ // src/lib/A-Request/A-Request.constants.ts
89
+ var A_RequestFeatures = {
90
+ onError: "A_Request_onError",
91
+ onInit: "A_Request_onInit",
92
+ onAfterInit: "A_Request_onAfterInit",
93
+ onParse: "A_Request_onParse",
94
+ onValidate: "A_Request_onValidate",
95
+ onClose: "A_Request_onClose",
96
+ onAborted: "A_Request_onAborted",
97
+ onTimeout: "A_Request_onTimeout",
98
+ onData: "A_Request_onData",
99
+ onEnd: "A_Request_onEnd",
100
+ onBodyParse: "A_Request_onBodyParse",
101
+ onQueryParse: "A_Request_onQueryParse",
102
+ onParamsParse: "A_Request_onParamsParse",
103
+ onCookiesParse: "A_Request_onCookiesParse"
104
+ };
105
+ var _A_HttpServerError = class _A_HttpServerError extends A_Error {
106
+ /**
107
+ * Gets the appropriate title for a given HTTP status code
108
+ */
109
+ static getHttpStatusTitle(status) {
110
+ return this.HTTP_STATUS_TITLES[status] || "Unknown Error";
111
+ }
112
+ constructor(param1, param2) {
113
+ switch (true) {
114
+ // Pattern: new A_HttpServerError(404, 'The requested resource was not found')
115
+ case (typeof param1 === "number" && typeof param2 === "string"):
116
+ super({
117
+ title: _A_HttpServerError.getHttpStatusTitle(param1),
118
+ description: param2
119
+ });
120
+ this.status = param1;
121
+ break;
122
+ // Pattern: new A_HttpServerError(someErrorObject)
123
+ case param1 instanceof Error:
124
+ super(param1);
125
+ this.status = 500;
126
+ break;
127
+ // Pattern: new A_HttpServerError({ status: 500, description: '...', originalError: ... })
128
+ case (typeof param1 === "object" && param1 !== null && !(param1 instanceof Error)):
129
+ const params = param1;
130
+ if ("title" in params && params.title) {
131
+ super(params);
132
+ this.status = params.status || 500;
133
+ } else {
134
+ const title = params.status ? _A_HttpServerError.getHttpStatusTitle(params.status) : "Internal Server Error";
135
+ super({
136
+ title,
137
+ description: params.description,
138
+ code: params.code,
139
+ scope: params.scope,
140
+ link: params.link,
141
+ originalError: params.originalError
142
+ });
143
+ this.status = params.status || 500;
144
+ }
145
+ break;
146
+ default:
147
+ throw new Error("Invalid parameters provided to A_HttpServerError constructor");
148
+ }
149
+ }
150
+ fromConstructor(params) {
151
+ super.fromConstructor(params);
152
+ if (params.status) {
153
+ this.status = params.status;
154
+ }
155
+ }
156
+ toJSON() {
157
+ return {
158
+ ...super.toJSON(),
159
+ status: this.status
160
+ };
161
+ }
162
+ };
163
+ _A_HttpServerError.NotFoundErrorStatus = 404;
164
+ _A_HttpServerError.NotFoundError = "Resource Not Found";
165
+ _A_HttpServerError.InternalServerErrorStatus = 500;
166
+ _A_HttpServerError.InternalServerError = "Internal Server Error";
167
+ /**
168
+ * HTTP status code to title mapping
169
+ */
170
+ _A_HttpServerError.HTTP_STATUS_TITLES = {
171
+ // 4xx Client Errors
172
+ 400: "Bad Request",
173
+ 401: "Unauthorized",
174
+ 402: "Payment Required",
175
+ 403: "Forbidden",
176
+ 404: "Not Found",
177
+ 405: "Method Not Allowed",
178
+ 406: "Not Acceptable",
179
+ 407: "Proxy Authentication Required",
180
+ 408: "Request Timeout",
181
+ 409: "Conflict",
182
+ 410: "Gone",
183
+ 411: "Length Required",
184
+ 412: "Precondition Failed",
185
+ 413: "Payload Too Large",
186
+ 414: "URI Too Long",
187
+ 415: "Unsupported Media Type",
188
+ 416: "Range Not Satisfiable",
189
+ 417: "Expectation Failed",
190
+ 418: "I'm a teapot",
191
+ 421: "Misdirected Request",
192
+ 422: "Unprocessable Entity",
193
+ 423: "Locked",
194
+ 424: "Failed Dependency",
195
+ 425: "Too Early",
196
+ 426: "Upgrade Required",
197
+ 428: "Precondition Required",
198
+ 429: "Too Many Requests",
199
+ 431: "Request Header Fields Too Large",
200
+ 451: "Unavailable For Legal Reasons",
201
+ // 5xx Server Errors
202
+ 500: "Internal Server Error",
203
+ 501: "Not Implemented",
204
+ 502: "Bad Gateway",
205
+ 503: "Service Unavailable",
206
+ 504: "Gateway Timeout",
207
+ 505: "HTTP Version Not Supported",
208
+ 506: "Variant Also Negotiates",
209
+ 507: "Insufficient Storage",
210
+ 508: "Loop Detected",
211
+ 510: "Not Extended",
212
+ 511: "Network Authentication Required"
213
+ };
214
+ var A_HttpServerError = _A_HttpServerError;
215
+ var A_RequestError = class extends A_Error {
216
+ };
217
+ A_RequestError.RequestBodyParsingError = "Unable to parse request body";
218
+ A_RequestError.FileUploadError = "File upload error";
219
+ A_RequestError.RequestTimeoutError = "Request timed out";
220
+ A_RequestError.InvalidRequestError = "Invalid request";
221
+ A_RequestError.MissingParametersError = "Missing required parameters";
222
+
223
+ // src/lib/A-Request/A-Request.helper.ts
224
+ var A_RequestHelper = class _A_RequestHelper {
225
+ /**
226
+ * Extract URL parameters from a URL using a route pattern
227
+ * @param url - The actual URL to extract parameters from
228
+ * @param routePattern - The route pattern with parameters (e.g., "/users/:id/posts/:postId")
229
+ * @returns Object containing extracted parameters
230
+ */
231
+ static extractParams(url, routePattern) {
232
+ const cleanUrl = url.split("?")[0];
233
+ const cleanPattern = routePattern.split("?")[0];
234
+ const urlSegments = cleanUrl.split("/").filter(Boolean);
235
+ const patternSegments = cleanPattern.split("/").filter(Boolean);
236
+ const params = {};
237
+ for (let i = 0; i < patternSegments.length; i++) {
238
+ const patternSegment = patternSegments[i];
239
+ const urlSegment = urlSegments[i];
240
+ if (patternSegment.startsWith(":")) {
241
+ const paramName = patternSegment.slice(1);
242
+ if (urlSegment) {
243
+ params[paramName] = decodeURIComponent(urlSegment);
244
+ }
245
+ } else if (patternSegment !== urlSegment) {
246
+ return {};
247
+ }
248
+ }
249
+ return params;
250
+ }
251
+ /**
252
+ * Extract query parameters from URL
253
+ * @param url - The URL to extract query parameters from
254
+ * @returns Object containing query parameters
255
+ */
256
+ static extractQuery(url) {
257
+ const query = {};
258
+ const queryString = url.split("?")[1];
259
+ if (!queryString) return query;
260
+ const cleanQuery = queryString.split("#")[0];
261
+ for (const pair of cleanQuery.split("&")) {
262
+ if (!pair) continue;
263
+ const [key, value = ""] = pair.split("=");
264
+ query[decodeURIComponent(key)] = decodeURIComponent(value);
265
+ }
266
+ return query;
267
+ }
268
+ /**
269
+ * Parse cookies from Cookie header
270
+ */
271
+ static parseCookies(cookieHeader) {
272
+ const cookies = {};
273
+ if (!cookieHeader) return {};
274
+ cookieHeader.split(";").forEach((cookie) => {
275
+ const [name, ...rest] = cookie.trim().split("=");
276
+ const value = rest.join("=");
277
+ if (name && value) {
278
+ cookies[name] = decodeURIComponent(value);
279
+ }
280
+ });
281
+ return cookies;
282
+ }
283
+ /**
284
+ * Parse request body based on Content-Type
285
+ *
286
+ *
287
+ * @param context - The HTTP server request context
288
+ * @returns Parsed body data and detected body type
289
+ */
290
+ static parseRequestBody(context) {
291
+ let parsedBody;
292
+ let bodyType;
293
+ switch (true) {
294
+ case (!!context.contentType && context.contentType.includes("application/json")):
295
+ parsedBody = JSON.parse(context.data);
296
+ bodyType = "json";
297
+ break;
298
+ case (!!context.contentType && context.contentType.includes("application/x-www-form-urlencoded")):
299
+ parsedBody = _A_RequestHelper.parseFormUrlEncoded(context.data);
300
+ bodyType = "form";
301
+ break;
302
+ case (!!context.contentType && context.contentType.includes("multipart/form-data")):
303
+ const multipartResult = _A_RequestHelper.parseMultipartData(Buffer.concat(context.buffers), context.contentType);
304
+ parsedBody = {
305
+ ...multipartResult.fields,
306
+ _files: multipartResult.files
307
+ };
308
+ bodyType = "multipart";
309
+ break;
310
+ case (!!context.contentType && context.contentType.includes("text/")):
311
+ parsedBody = context.data;
312
+ bodyType = "text";
313
+ break;
314
+ default:
315
+ parsedBody = Buffer.concat(context.buffers);
316
+ bodyType = "raw";
317
+ break;
318
+ }
319
+ return {
320
+ data: parsedBody,
321
+ type: bodyType
322
+ };
323
+ }
324
+ /**
325
+ * Parse URL-encoded form data (application/x-www-form-urlencoded)
326
+ * @param body - The URL-encoded body string
327
+ * @returns Object containing form data
328
+ */
329
+ static parseFormUrlEncoded(body) {
330
+ const result = {};
331
+ if (!body) return result;
332
+ const pairs = body.split("&");
333
+ for (const pair of pairs) {
334
+ if (!pair) continue;
335
+ const [key, value = ""] = pair.split("=");
336
+ const decodedKey = decodeURIComponent(key.replace(/\+/g, " "));
337
+ const decodedValue = decodeURIComponent(value.replace(/\+/g, " "));
338
+ if (decodedKey in result) {
339
+ const existing = result[decodedKey];
340
+ if (Array.isArray(existing)) {
341
+ existing.push(decodedValue);
342
+ } else {
343
+ result[decodedKey] = [existing, decodedValue];
344
+ }
345
+ } else {
346
+ result[decodedKey] = decodedValue;
347
+ }
348
+ }
349
+ return result;
350
+ }
351
+ /**
352
+ * Parse multipart form data (for file uploads and form data)
353
+ * @param buffer - The raw buffer containing multipart data
354
+ * @param contentType - The content type header
355
+ * @returns Object containing fields and files
356
+ */
357
+ static parseMultipartData(buffer, contentType) {
358
+ const boundaryMatch = contentType.match(/boundary=(.+)/);
359
+ if (!boundaryMatch) {
360
+ throw new A_RequestError(
361
+ A_RequestError.RequestBodyParsingError,
362
+ "Missing boundary in multipart/form-data content type"
363
+ );
364
+ }
365
+ const boundary = "--" + boundaryMatch[1];
366
+ const textData = buffer.toString();
367
+ const parts = textData.split(boundary).filter((part) => part.trim() && !part.includes("--"));
368
+ const fields = {};
369
+ const files = [];
370
+ parts.forEach((part) => {
371
+ const [headers, content] = part.split("\r\n\r\n");
372
+ if (!headers || content === void 0) return;
373
+ const nameMatch = headers.match(/name="([^"]+)"/);
374
+ const filenameMatch = headers.match(/filename="([^"]+)"/);
375
+ const contentTypeMatch = headers.match(/Content-Type: ([^\r\n]+)/);
376
+ if (nameMatch) {
377
+ const fieldName = nameMatch[1];
378
+ const cleanContent = content.replace(/\r\n$/, "");
379
+ if (filenameMatch) {
380
+ const file = {
381
+ fieldName,
382
+ filename: filenameMatch[1],
383
+ encoding: "binary",
384
+ mimetype: contentTypeMatch?.[1] || "application/octet-stream",
385
+ size: Buffer.byteLength(cleanContent),
386
+ buffer: Buffer.from(cleanContent, "binary")
387
+ };
388
+ files.push(file);
389
+ } else {
390
+ fields[fieldName] = cleanContent;
391
+ }
392
+ }
393
+ });
394
+ return { fields, files };
395
+ }
396
+ };
397
+
398
+ // src/lib/A-Request/A-Request.env.ts
399
+ var A_RequestEnvVariables = {
400
+ /**
401
+ * Default request timeout in milliseconds
402
+ */
403
+ A_SERVER_REQUEST_TIMEOUT: 5e3,
404
+ /**
405
+ * Maximum request body size in bytes
406
+ */
407
+ A_SERVER_REQUEST_MAX_BODY_SIZE: 10 * 1024 * 1024,
408
+ // 10MB
409
+ /**
410
+ * Default request encoding
411
+ */
412
+ A_SERVER_REQUEST_DEFAULT_ENCODING: "utf8",
413
+ /**
414
+ * Enable automatic cookie parsing
415
+ */
416
+ A_SERVER_REQUEST_PARSE_COOKIES: true,
417
+ /**
418
+ * Enable automatic query parameter parsing
419
+ */
420
+ A_SERVER_REQUEST_PARSE_QUERY: true,
421
+ /**
422
+ * Enable automatic body parsing
423
+ */
424
+ A_SERVER_REQUEST_PARSE_BODY: true,
425
+ /**
426
+ * Enable file upload handling
427
+ */
428
+ A_SERVER_REQUEST_ENABLE_FILE_UPLOADS: false
429
+ };
430
+ var A_RequestEnvVariablesArray = Object.keys(A_RequestEnvVariables);
431
+ var _a, _b, _c, _d, _e, _f, _g;
432
+ var A_Request = class extends A_Entity {
433
+ /**
434
+ * A_Request - Comprehensive HTTP Request Processing Entity
435
+ *
436
+ * This class provides a complete wrapper around Node.js IncomingMessage with advanced features:
437
+ * - Automatic body parsing (JSON, form-data, multipart, raw)
438
+ * - Cookie and session management
439
+ * - File upload handling with easy access methods
440
+ * - Request validation
441
+ * - Middleware support
442
+ * - Type-safe parameter extraction
443
+ * - Request timing and metrics
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * const request = new A_Request({
448
+ * id: 'req-123',
449
+ * request: incomingMessage,
450
+ * scope: 'api'
451
+ * }, {
452
+ * enableFileUploads: true,
453
+ * maxBodySize: 50 * 1024 * 1024 // 50MB for file uploads
454
+ * });
455
+ *
456
+ * await request.init();
457
+ *
458
+ * // Access parsed body
459
+ * const userData = request.body;
460
+ *
461
+ * // Get typed parameters
462
+ * const userId = request.params.id;
463
+ *
464
+ * // Handle file uploads
465
+ * if (request.hasFiles()) {
466
+ * const avatar = request.getFile('avatar');
467
+ * if (avatar) {
468
+ * console.log(`Uploaded file: ${avatar.filename}`);
469
+ * console.log(`File size: ${avatar.size} bytes`);
470
+ * console.log(`File type: ${avatar.mimetype}`);
471
+ *
472
+ * // Access file buffer for processing
473
+ * const fileBuffer = avatar.buffer;
474
+ * // Save to disk, process, etc.
475
+ * }
476
+ *
477
+ * // Get all files for a specific field
478
+ * const documents = request.getFiles('documents');
479
+ * for (const doc of documents) {
480
+ * // Process each document...
481
+ * }
482
+ * }
483
+ *
484
+ * // Check specific files
485
+ * if (request.hasFile('profilePicture')) {
486
+ * const pic = request.getFile('profilePicture');
487
+ * // Process profile picture...
488
+ * }
489
+ * ```
490
+ */
491
+ constructor(params, options) {
492
+ super(params);
493
+ // =============================================
494
+ // Core Properties
495
+ // =============================================
496
+ /**
497
+ * Request processing status
498
+ */
499
+ this._listeners = /* @__PURE__ */ new Map();
500
+ this._options = {
501
+ maxBodySize: 10 * 1024 * 1024,
502
+ // 10MB default
503
+ timeout: 3e4,
504
+ // 30 seconds
505
+ encoding: "utf8",
506
+ parseCookies: true,
507
+ parseQuery: true,
508
+ parseBody: true,
509
+ enableFileUploads: false,
510
+ strictValidation: false,
511
+ ...options || {}
512
+ };
513
+ }
514
+ static get concept() {
515
+ return "a-server";
516
+ }
517
+ /**
518
+ * Creates A_Request entity from initialization data
519
+ *
520
+ * @param newEntity
521
+ */
522
+ fromNew(newEntity) {
523
+ this.aseid = new ASEID({
524
+ concept: this.constructor.concept,
525
+ scope: newEntity.scope,
526
+ entity: this.constructor.entity,
527
+ shard: newEntity.shard,
528
+ id: newEntity.id
529
+ });
530
+ this._req = newEntity.request;
531
+ }
532
+ /**
533
+ * Core HTTP request object from Node.js
534
+ */
535
+ get original() {
536
+ return this._req;
537
+ }
538
+ /**
539
+ * Parsed request body data
540
+ */
541
+ get body() {
542
+ return this._body;
543
+ }
544
+ /**
545
+ * URL route parameters (e.g., /users/:id)
546
+ */
547
+ get params() {
548
+ console.log("Extracting params using route definition:", this.url);
549
+ console.log("Extracting params using route definition:", this._routeDefinition?.path);
550
+ return A_RequestHelper.extractParams(
551
+ this.url,
552
+ this._routeDefinition?.path || ""
553
+ );
554
+ }
555
+ /**
556
+ * Query string parameters
557
+ */
558
+ get query() {
559
+ return A_RequestHelper.extractQuery(this.url);
560
+ }
561
+ /**
562
+ * Gets the parsed cookies
563
+ */
564
+ get cookies() {
565
+ if (!this._cookies) {
566
+ this._cookies = A_RequestHelper.parseCookies(this.headers["cookie"]);
567
+ }
568
+ return this._cookies;
569
+ }
570
+ /**
571
+ * Gets the request URL
572
+ */
573
+ get url() {
574
+ return this.original.url;
575
+ }
576
+ /**
577
+ * Gets the HTTP method
578
+ */
579
+ get method() {
580
+ return String(this.original.method).toUpperCase() || "DEFAULT";
581
+ }
582
+ /**
583
+ * Gets the request headers
584
+ */
585
+ get headers() {
586
+ return this.original.headers;
587
+ }
588
+ /**
589
+ * Gets the timestamp when the request was started
590
+ */
591
+ get startedAt() {
592
+ const timeId = A_IdentityHelper.parseTimeId(this.aseid.id.split("-")[0]);
593
+ return timeId ? new Date(timeId.timestamp) : void 0;
594
+ }
595
+ /**
596
+ * Gets uploaded files
597
+ */
598
+ get files() {
599
+ return this._files || [];
600
+ }
601
+ /**
602
+ * Gets user agent string
603
+ */
604
+ get userAgent() {
605
+ return this.headers?.["user-agent"] || "";
606
+ }
607
+ /**
608
+ * Gets content length
609
+ */
610
+ get contentLength() {
611
+ return this.headers?.["content-length"] ? parseInt(this.headers["content-length"], 10) : 0;
612
+ }
613
+ /**
614
+ * Check if request is secure (HTTPS)
615
+ */
616
+ get isSecure() {
617
+ return this.original.socket && "encrypted" in this.original.socket;
618
+ }
619
+ /**
620
+ * Check if request is from mobile device
621
+ */
622
+ get isMobile() {
623
+ const userAgent = this._userAgent?.toLowerCase() || "";
624
+ return /mobile|android|iphone|ipad|phone/i.test(userAgent);
625
+ }
626
+ /**
627
+ * Get request size in bytes
628
+ */
629
+ get size() {
630
+ return this._contentLength || 0;
631
+ }
632
+ /**
633
+ * Gets content type from headers
634
+ */
635
+ get contentType() {
636
+ return this.headers["content-type"] || void 0;
637
+ }
638
+ /**
639
+ * Pipes request stream to destination
640
+ */
641
+ pipe(destination, options) {
642
+ return this.original.pipe(destination, options);
643
+ }
644
+ /**
645
+ * Get a file by field name
646
+ */
647
+ getFile(fieldName) {
648
+ return this._files?.find((file) => file.fieldName === fieldName);
649
+ }
650
+ /**
651
+ * Get all files for a specific field name
652
+ */
653
+ getFiles(fieldName) {
654
+ return this._files?.filter((file) => file.fieldName === fieldName) || [];
655
+ }
656
+ /**
657
+ * Check if request has any files
658
+ */
659
+ hasFiles() {
660
+ return this._files && this._files.length > 0;
661
+ }
662
+ /**
663
+ * Check if request has a file with specific field name
664
+ */
665
+ hasFile(fieldName) {
666
+ return this._files?.some((file) => file.fieldName === fieldName) || false;
667
+ }
668
+ /**
669
+ * Get total size of all uploaded files
670
+ */
671
+ getTotalFileSize() {
672
+ return this._files?.reduce((total, file) => total + file.size, 0) || 0;
673
+ }
674
+ /**
675
+ * Get a cookie value
676
+ */
677
+ getCookie(name) {
678
+ return this._cookies[name];
679
+ }
680
+ /**
681
+ * Check if request has a specific cookie
682
+ */
683
+ hasCookie(name) {
684
+ return name in this._cookies;
685
+ }
686
+ /**
687
+ * Check if request accepts specific content type
688
+ */
689
+ accepts(contentType) {
690
+ const acceptHeader = this.headers.accept || "";
691
+ return acceptHeader.includes(contentType) || acceptHeader.includes("*/*");
692
+ }
693
+ /**
694
+ * Get request fingerprint for caching/identification
695
+ */
696
+ getFingerprint() {
697
+ const components = [
698
+ this.method,
699
+ this.url,
700
+ this._userAgent,
701
+ JSON.stringify(this.body)
702
+ ];
703
+ return Buffer.from(components.join("|")).toString("base64");
704
+ }
705
+ // --------------------------------------------------------------------------
706
+ // A-Request Event-Emitter methods
707
+ // --------------------------------------------------------------------------
708
+ /**
709
+ * Registers an event listener for a specific event
710
+ *
711
+ * @param event
712
+ * @param listener
713
+ */
714
+ on(event, listener) {
715
+ if (!this._listeners.has(event)) {
716
+ this._listeners.set(event, /* @__PURE__ */ new Set());
717
+ }
718
+ this._listeners.get(event).add(listener);
719
+ }
720
+ /**
721
+ * Removes an event listener for a specific event
722
+ *
723
+ * @param event
724
+ * @param listener
725
+ */
726
+ off(event, listener) {
727
+ this._listeners.get(event)?.delete(listener);
728
+ }
729
+ /**
730
+ * Emits an event to all registered listeners
731
+ *
732
+ * @param event
733
+ */
734
+ emit(event) {
735
+ this._listeners.get(event)?.forEach(async (listener) => {
736
+ listener(this);
737
+ });
738
+ }
739
+ /**
740
+ * Allows to use a route definition for this request
741
+ *
742
+ * @param route
743
+ */
744
+ useRoute(route) {
745
+ this._routeDefinition = route;
746
+ }
747
+ clearTimeout() {
748
+ this._timeout?.clear();
749
+ }
750
+ /**
751
+ * Initialize the request - parse cookies, query, body etc.
752
+ */
753
+ async load() {
754
+ try {
755
+ await this.call(A_RequestFeatures.onInit);
756
+ await new Promise((resolve, reject) => {
757
+ const onData = this.handleData.bind(this);
758
+ const onEnd = () => {
759
+ cleanup();
760
+ resolve();
761
+ };
762
+ const onError = (err) => {
763
+ cleanup();
764
+ reject(err);
765
+ };
766
+ const cleanup = () => {
767
+ this.original.off("data", onData);
768
+ this.original.off("end", onEnd);
769
+ this.original.off("error", onError);
770
+ };
771
+ this.original.on("data", onData);
772
+ this.original.on("end", onEnd);
773
+ this.original.on("error", onError);
774
+ });
775
+ await this.handleEnd();
776
+ } catch (error) {
777
+ const targetError = error instanceof A_HttpServerError ? error : new A_HttpServerError({
778
+ status: 500,
779
+ description: "An error occurred while processing the request.",
780
+ originalError: error
781
+ });
782
+ await this.fail(targetError);
783
+ }
784
+ this.original.on("error", (err) => {
785
+ this.fail(new A_HttpServerError({
786
+ status: 500,
787
+ description: `Request error: ${err.message}`,
788
+ originalError: err
789
+ }));
790
+ });
791
+ }
792
+ async validate() {
793
+ try {
794
+ await this.call(A_RequestFeatures.onValidate);
795
+ } catch (error) {
796
+ const targetError = error instanceof A_HttpServerError ? error : new A_HttpServerError({
797
+ status: 400,
798
+ description: ` Request Validation Failed: ${error instanceof A_Error ? error.message : "Invalid request."}`,
799
+ originalError: error
800
+ });
801
+ await this.fail(targetError);
802
+ }
803
+ }
804
+ /**
805
+ * Destroy the request A-Entity with cleanup
806
+ *
807
+ * @returns
808
+ */
809
+ async destroy() {
810
+ const targetError = A_Context.scope(this)?.resolve(A_Error);
811
+ if (!this.original.destroyed) {
812
+ this.original.destroy(targetError);
813
+ this.original.removeAllListeners();
814
+ this._listeners.clear();
815
+ return super.destroy();
816
+ }
817
+ }
818
+ /**
819
+ * Handles request failure - registers error, emits event, and destroys request
820
+ *
821
+ * [!] Destroys the request after handling the failure.
822
+ *
823
+ * @param err
824
+ */
825
+ async fail(err) {
826
+ console.log("Request failed with error:", this.method, this.url, err?.message);
827
+ if (err)
828
+ A_Context.scope(this).register(err);
829
+ this._timeout?.clear();
830
+ await this.call(A_RequestFeatures.onError);
831
+ await this.destroy();
832
+ }
833
+ // ======================================================================================
834
+ // Internal handlers for request events
835
+ // ======================================================================================
836
+ /**
837
+ * Internal helper method to handle incoming data chunks
838
+ * It creates a new scope for each data chunk, inherits the parent scope,
839
+ * and calls the onData feature with the new scope.
840
+ *
841
+ * [!] This method ensures that each data chunk is processed in isolation,
842
+ * preventing side effects between chunks.
843
+ *
844
+ * @param data
845
+ */
846
+ async handleData(data) {
847
+ const chunk = new A_HttpRequestData(data);
848
+ const scope = new A_Scope({
849
+ name: `${this.aseid.toString()}-data-chunk`,
850
+ fragments: [chunk]
851
+ }).inherit(A_Context.scope(this));
852
+ try {
853
+ scope.inherit(A_Context.scope(this));
854
+ await this.call(A_RequestFeatures.onData, scope);
855
+ scope.destroy();
856
+ } catch (error) {
857
+ scope.destroy();
858
+ await this.fail(new A_HttpServerError({
859
+ status: 500,
860
+ description: `Request data chunk error: ${error instanceof A_Error ? error.message : "Unable to process request data chunk."}`,
861
+ originalError: error
862
+ }));
863
+ }
864
+ }
865
+ /**
866
+ * Handles request close event
867
+ *
868
+ * This method is called when the request is closed prematurely.
869
+ * It triggers the onClose feature and handles any errors that occur during processing.
870
+ *
871
+ */
872
+ async handleClose() {
873
+ try {
874
+ await this.call(A_RequestFeatures.onClose);
875
+ } catch (error) {
876
+ await this.fail(new A_HttpServerError({
877
+ status: 499,
878
+ description: `Request closed error: ${error instanceof A_Error ? error.message : "Request was closed."}`,
879
+ originalError: error
880
+ }));
881
+ }
882
+ }
883
+ /**
884
+ * Handles request end event
885
+ *
886
+ * This method is called when the request has finished sending data.
887
+ * It triggers the onEnd feature and handles any errors that occur during processing.
888
+ */
889
+ async handleEnd() {
890
+ try {
891
+ await this.call(A_RequestFeatures.onEnd);
892
+ } catch (error) {
893
+ await this.fail(new A_HttpServerError({
894
+ status: 500,
895
+ description: `Request processing error: ${error instanceof A_Error ? error.message : "Unable to process request."}`,
896
+ originalError: error
897
+ }));
898
+ }
899
+ }
900
+ /**
901
+ * Handles request timeout event
902
+ *
903
+ * This method is called when the request processing exceeds the configured timeout.
904
+ * It triggers the onTimeout feature and fails the request with a timeout error.
905
+ */
906
+ async handleTimeout() {
907
+ try {
908
+ await this.call(A_RequestFeatures.onTimeout);
909
+ throw new A_HttpServerError({
910
+ status: 503,
911
+ description: `Request processing take too long and timed out. Current timeout is set to ${this._options.timeout} ms.`
912
+ });
913
+ } catch (error) {
914
+ const targetError = error instanceof A_HttpServerError ? error : new A_HttpServerError({
915
+ status: 503,
916
+ description: `Request timeout error: ${error instanceof A_Error ? error.message : "Request timed out."}`,
917
+ originalError: error
918
+ });
919
+ await this.fail(targetError);
920
+ }
921
+ }
922
+ /**
923
+ * Hook called during initialization
924
+ *
925
+ * Default Behavior: Starts request processing timer and sets up timeout handling.
926
+ */
927
+ async [_g = A_RequestFeatures.onInit](config, context, ...args) {
928
+ context.startProcessing();
929
+ const ms = Number(config?.get("A_SERVER_REQUEST_TIMEOUT") || A_RequestEnvVariables.A_SERVER_REQUEST_TIMEOUT);
930
+ this._timeout = new A_ScheduleObject(ms, this.handleTimeout.bind(this), { resolveOnClear: true });
931
+ }
932
+ /**
933
+ * Hook called on receiving data chunk
934
+ *
935
+ * Default Behavior: Accumulates data chunks into context buffers and checks for max body size.
936
+ */
937
+ async [_f = A_RequestFeatures.onData](context, chunk, ...args) {
938
+ if (context.length + chunk.length > this._options.maxBodySize) {
939
+ throw new A_RequestError(
940
+ A_RequestError.RequestBodyParsingError,
941
+ `Request body too large. Max size is ${this._options.maxBodySize} bytes.`
942
+ );
943
+ }
944
+ context.buffers.push(chunk.data);
945
+ if (!context.data)
946
+ context.data = "";
947
+ context.data += chunk.toString(this._options.encoding);
948
+ }
949
+ /**
950
+ * Hook called on request timeout
951
+ *
952
+ * Default Behavior: Stops request processing and emits timeout event.
953
+ *
954
+ * @param context
955
+ * @param args
956
+ */
957
+ async [_e = A_RequestFeatures.onTimeout](context, ...args) {
958
+ context.stopProcessing();
959
+ this._timeout?.clear();
960
+ this.emit(A_RequestFeatures.onTimeout);
961
+ }
962
+ /**
963
+ * Hook called on request close
964
+ */
965
+ async [_d = A_RequestFeatures.onClose](context, ...args) {
966
+ this.emit(A_RequestFeatures.onClose);
967
+ }
968
+ /**
969
+ * Hook called on request error
970
+ */
971
+ async [_c = A_RequestFeatures.onError](error, context, ...args) {
972
+ context.stopProcessing();
973
+ this.emit(A_RequestFeatures.onError);
974
+ }
975
+ /**
976
+ * Hook called to parse request data
977
+ */
978
+ async [_b = A_RequestFeatures.onEnd](config, context, ...args) {
979
+ const { data, type } = A_RequestHelper.parseRequestBody(context);
980
+ this._body = data;
981
+ this._bodyType = type;
982
+ }
983
+ /**
984
+ * Hook called to validate request data
985
+ */
986
+ async [_a = A_RequestFeatures.onValidate](context, ...args) {
987
+ if (!!this.contentType && this.contentType.includes("multipart/form-data") && !this._options.enableFileUploads) {
988
+ throw new A_HttpServerError({
989
+ status: 400,
990
+ description: "File uploads detected but not enabled. Set enableFileUploads: true in options."
991
+ });
992
+ }
993
+ }
994
+ /**
995
+ * Serialize request for logging/debugging
996
+ */
997
+ toJSON() {
998
+ return {
999
+ ...super.toJSON(),
1000
+ method: this.method,
1001
+ url: this.url,
1002
+ headers: this.headers,
1003
+ params: this.params,
1004
+ query: this.query,
1005
+ cookies: this._cookies,
1006
+ userAgent: this.userAgent,
1007
+ bodyType: this._bodyType,
1008
+ body: this._body,
1009
+ filesCount: this._files?.length || 0,
1010
+ totalFileSize: this.getTotalFileSize()
1011
+ };
1012
+ }
1013
+ };
1014
+ __decorateClass([
1015
+ A_Feature.Extend(),
1016
+ __decorateParam(0, A_Inject(A_Config)),
1017
+ __decorateParam(1, A_Inject(A_HttpServerRequestContext))
1018
+ ], A_Request.prototype, _g, 1);
1019
+ __decorateClass([
1020
+ A_Feature.Extend({
1021
+ before: /.*/
1022
+ }),
1023
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext)),
1024
+ __decorateParam(1, A_Inject(A_HttpRequestData))
1025
+ ], A_Request.prototype, _f, 1);
1026
+ __decorateClass([
1027
+ A_Feature.Extend({
1028
+ before: /.*/
1029
+ }),
1030
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext))
1031
+ ], A_Request.prototype, _e, 1);
1032
+ __decorateClass([
1033
+ A_Feature.Extend({
1034
+ before: /.*/
1035
+ }),
1036
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext))
1037
+ ], A_Request.prototype, _d, 1);
1038
+ __decorateClass([
1039
+ A_Feature.Extend({
1040
+ after: /.*/
1041
+ }),
1042
+ __decorateParam(0, A_Inject(A_Error)),
1043
+ __decorateParam(1, A_Inject(A_HttpServerRequestContext))
1044
+ ], A_Request.prototype, _c, 1);
1045
+ __decorateClass([
1046
+ A_Feature.Extend(),
1047
+ __decorateParam(0, A_Inject(A_Config)),
1048
+ __decorateParam(1, A_Inject(A_HttpServerRequestContext))
1049
+ ], A_Request.prototype, _b, 1);
1050
+ __decorateClass([
1051
+ A_Feature.Extend(),
1052
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext))
1053
+ ], A_Request.prototype, _a, 1);
1054
+
1055
+ // src/lib/A-Request/A-Request.types.ts
1056
+ var A_Request_Event = /* @__PURE__ */ ((A_Request_Event2) => {
1057
+ A_Request_Event2["Error"] = "error";
1058
+ A_Request_Event2["Finish"] = "finish";
1059
+ A_Request_Event2["Data"] = "data";
1060
+ A_Request_Event2["End"] = "end";
1061
+ A_Request_Event2["Close"] = "close";
1062
+ return A_Request_Event2;
1063
+ })(A_Request_Event || {});
1064
+
1065
+ // src/lib/A-Response/A-Response.constants.ts
1066
+ var A_ResponseFeatures = {
1067
+ /**
1068
+ * Event fired when an error occurs while sending the response
1069
+ */
1070
+ onError: "_A_Response_onError",
1071
+ /**
1072
+ * Event fired when the response is closed
1073
+ */
1074
+ onClose: "_A_Response_onClose",
1075
+ /**
1076
+ * Event fired when the response is finished
1077
+ */
1078
+ onFinish: "_A_Response_onFinish",
1079
+ /**
1080
+ * Event fired when the response is sent
1081
+ */
1082
+ onSend: "_A_Response_onSend",
1083
+ /**
1084
+ * Event fired when the response is redirected
1085
+ */
1086
+ onRedirect: "_A_Response_onRedirect"
1087
+ };
1088
+ var _a2, _b2, _c2;
1089
+ var A_Response = class extends A_Entity {
1090
+ constructor(params, options) {
1091
+ super(params);
1092
+ /**
1093
+ * Event listeners map for A_Response events
1094
+ */
1095
+ this._listeners = /* @__PURE__ */ new Map();
1096
+ this._options = {
1097
+ autoCompress: true,
1098
+ compressionThreshold: 1024,
1099
+ // 1KB
1100
+ enableCaching: true,
1101
+ defaultCacheMaxAge: 3600,
1102
+ // 1 hour
1103
+ enableMetrics: true,
1104
+ enableEtag: true,
1105
+ enableLastModified: true,
1106
+ charset: "utf-8",
1107
+ defaultContentType: "application/json",
1108
+ maxRedirects: 5,
1109
+ enableCookies: true,
1110
+ enableSessions: true,
1111
+ ...options || {}
1112
+ };
1113
+ }
1114
+ // =============================================
1115
+ // Static Properties
1116
+ // =============================================
1117
+ static get namespace() {
1118
+ return "a-server";
1119
+ }
1120
+ /**
1121
+ * Initialize from new entity parameters
1122
+ */
1123
+ fromNew(newEntity) {
1124
+ this.aseid = new ASEID({
1125
+ concept: A_Context.root.name,
1126
+ scope: newEntity.scope,
1127
+ entity: this.constructor.entity,
1128
+ shard: newEntity.shard,
1129
+ id: newEntity.id
1130
+ });
1131
+ this._res = newEntity.response;
1132
+ this._data = /* @__PURE__ */ new Map();
1133
+ this._cookies = /* @__PURE__ */ new Map();
1134
+ }
1135
+ /**
1136
+ * Gets the response data map
1137
+ */
1138
+ get data() {
1139
+ return this._data;
1140
+ }
1141
+ /**
1142
+ * Gets the original ServerResponse object
1143
+ */
1144
+ get original() {
1145
+ return this._res;
1146
+ }
1147
+ /**
1148
+ * Gets whether headers have been sent
1149
+ */
1150
+ get headersSent() {
1151
+ return this.original.headersSent;
1152
+ }
1153
+ /**
1154
+ * Gets the current status code
1155
+ */
1156
+ get statusCode() {
1157
+ return this.original.statusCode;
1158
+ }
1159
+ /**
1160
+ * Gets response size in bytes
1161
+ */
1162
+ get size() {
1163
+ return this.original.getHeader("Content-Length") || 0;
1164
+ }
1165
+ // ======================================================================================
1166
+ // --------------------------------------------------------------------------
1167
+ // A-Response Primary Methods
1168
+ // --------------------------------------------------------------------------
1169
+ // ======================================================================================
1170
+ /**
1171
+ * Initialize the response
1172
+ */
1173
+ async load() {
1174
+ this.original.on("error", (err) => {
1175
+ this.fail(new A_HttpServerError({
1176
+ status: 500,
1177
+ description: `Request error: ${err.message}`,
1178
+ originalError: err
1179
+ }));
1180
+ });
1181
+ }
1182
+ /**
1183
+ * Destroy the response
1184
+ */
1185
+ async destroy() {
1186
+ if (!this.original.destroyed) {
1187
+ this.original.end();
1188
+ this._listeners.clear();
1189
+ this.original.removeAllListeners();
1190
+ }
1191
+ return super.destroy();
1192
+ }
1193
+ /**
1194
+ * Handle response failure with error details
1195
+ */
1196
+ async fail(err) {
1197
+ if (err)
1198
+ A_Context.scope(this).register(err);
1199
+ await this.call(A_ResponseFeatures.onError);
1200
+ await this.destroy();
1201
+ }
1202
+ /**
1203
+ * Send a plain text or JSON response
1204
+ */
1205
+ async send(data) {
1206
+ if (this.headersSent)
1207
+ return;
1208
+ try {
1209
+ this._dataOverride = data;
1210
+ await this.call(A_ResponseFeatures.onSend);
1211
+ } catch (error) {
1212
+ await this.fail(error instanceof A_HttpServerError ? error : new A_HttpServerError({
1213
+ status: 500,
1214
+ description: "An error occurred while sending the response.",
1215
+ originalError: error
1216
+ }));
1217
+ }
1218
+ }
1219
+ /**
1220
+ * Stream response data
1221
+ */
1222
+ async stream(dataStream) {
1223
+ if (this.headersSent)
1224
+ return;
1225
+ try {
1226
+ return new Promise((resolve, reject) => {
1227
+ this.original.setHeader("Transfer-Encoding", "chunked");
1228
+ this.setDefaultResponseHeaders();
1229
+ this.setCookieHeaders();
1230
+ this.original.writeHead(this.statusCode);
1231
+ let stream;
1232
+ if (Array.isArray(dataStream)) {
1233
+ stream = new Readable({
1234
+ read() {
1235
+ if (dataStream.length > 0) {
1236
+ const chunk = dataStream.shift();
1237
+ this.push(typeof chunk === "string" ? chunk : JSON.stringify(chunk) + "\n");
1238
+ } else {
1239
+ this.push(null);
1240
+ }
1241
+ }
1242
+ });
1243
+ } else {
1244
+ stream = dataStream;
1245
+ }
1246
+ let bytesWritten = 0;
1247
+ stream.on("data", (chunk) => {
1248
+ bytesWritten += chunk.length;
1249
+ });
1250
+ stream.on("end", resolve);
1251
+ stream.on("error", reject);
1252
+ pipeline(stream, this.original, (error) => {
1253
+ if (error) {
1254
+ reject(error);
1255
+ }
1256
+ });
1257
+ });
1258
+ } catch (error) {
1259
+ await this.fail(error instanceof A_HttpServerError ? error : new A_HttpServerError({
1260
+ status: 500,
1261
+ description: "An error occurred while streaming the response. Unable to process the stream.",
1262
+ originalError: error
1263
+ }));
1264
+ }
1265
+ }
1266
+ /**
1267
+ * Redirect response
1268
+ *
1269
+ * [!] Note: This method ends the response immediately.
1270
+ */
1271
+ async redirect(url) {
1272
+ if (this.headersSent)
1273
+ return;
1274
+ try {
1275
+ this._redirectURL = url;
1276
+ await this.call(A_ResponseFeatures.onRedirect);
1277
+ } catch (error) {
1278
+ await this.fail(error instanceof A_HttpServerError ? error : new A_HttpServerError({
1279
+ status: 500,
1280
+ description: "An error occurred while redirecting the response.",
1281
+ originalError: error
1282
+ }));
1283
+ }
1284
+ }
1285
+ /**
1286
+ * Write head with status and headers
1287
+ */
1288
+ writeHead(statusCode, headers) {
1289
+ this.original.writeHead(statusCode, headers);
1290
+ return this;
1291
+ }
1292
+ /**
1293
+ * Set HTTP status code
1294
+ */
1295
+ status(code) {
1296
+ this.original.statusCode = code;
1297
+ return this;
1298
+ }
1299
+ /**
1300
+ * Set response header
1301
+ */
1302
+ setHeader(key, value) {
1303
+ this.original.setHeader(key, value);
1304
+ return this;
1305
+ }
1306
+ /**
1307
+ * Get response header
1308
+ */
1309
+ getHeader(key) {
1310
+ return this.original.getHeader(key);
1311
+ }
1312
+ /**
1313
+ * Remove response header
1314
+ */
1315
+ removeHeader(key) {
1316
+ this.original.removeHeader(key);
1317
+ return this;
1318
+ }
1319
+ /**
1320
+ * Set cookie
1321
+ */
1322
+ setCookie(name, value, options) {
1323
+ this._cookies.set(name, { value, options });
1324
+ return this;
1325
+ }
1326
+ /**
1327
+ * Clear cookie
1328
+ */
1329
+ clearCookie(name, options) {
1330
+ const clearOptions = {
1331
+ ...options,
1332
+ expires: /* @__PURE__ */ new Date(0),
1333
+ maxAge: 0
1334
+ };
1335
+ this._cookies.set(name, { value: "", options: clearOptions });
1336
+ return this;
1337
+ }
1338
+ // --------------------------------------------------------------------------
1339
+ // Response Data manipulation methods
1340
+ // --------------------------------------------------------------------------
1341
+ /**
1342
+ * Add data to response
1343
+ */
1344
+ add(key, data) {
1345
+ this._data.set(key, data);
1346
+ return this;
1347
+ }
1348
+ /**
1349
+ * Remove data from response
1350
+ */
1351
+ remove(key) {
1352
+ this._data.delete(key);
1353
+ return this;
1354
+ }
1355
+ /**
1356
+ * Get data from response
1357
+ */
1358
+ get(key) {
1359
+ return this._data.get(key);
1360
+ }
1361
+ /**
1362
+ * Check if response has data
1363
+ */
1364
+ has(key) {
1365
+ return this._data.has(key);
1366
+ }
1367
+ /**
1368
+ * Clear all response data
1369
+ */
1370
+ clear() {
1371
+ this._data.clear();
1372
+ return this;
1373
+ }
1374
+ // ======================================================================================
1375
+ // --------------------------------------------------------------------------
1376
+ // Internal handlers for request events
1377
+ // --------------------------------------------------------------------------
1378
+ // ======================================================================================
1379
+ /**
1380
+ * Handle response finish event
1381
+ *
1382
+ * @returns
1383
+ */
1384
+ handleFinish() {
1385
+ try {
1386
+ return this.call(A_ResponseFeatures.onFinish);
1387
+ } catch (error) {
1388
+ return this.fail(new A_HttpServerError({
1389
+ status: 500,
1390
+ description: `Response finish error: ${error instanceof A_Error ? error.message : "An error occurred while finishing the response."}`,
1391
+ originalError: error
1392
+ }));
1393
+ }
1394
+ }
1395
+ /**
1396
+ * Handle response close event
1397
+ */
1398
+ async handleClose() {
1399
+ try {
1400
+ await this.call(A_ResponseFeatures.onClose);
1401
+ } catch (error) {
1402
+ await this.fail(new A_HttpServerError({
1403
+ status: 499,
1404
+ description: "Client closed the connection before the response could be completed.",
1405
+ originalError: error
1406
+ }));
1407
+ }
1408
+ }
1409
+ // ======================================================================================
1410
+ // --------------------------------------------------------------------------
1411
+ // A-Request Event-Emitter methods
1412
+ // --------------------------------------------------------------------------
1413
+ // ======================================================================================
1414
+ /**
1415
+ * Registers an event listener for a specific event
1416
+ *
1417
+ * @param event
1418
+ * @param listener
1419
+ */
1420
+ on(event, listener) {
1421
+ if (!this._listeners.has(event)) {
1422
+ this._listeners.set(event, /* @__PURE__ */ new Set());
1423
+ }
1424
+ this._listeners.get(event).add(listener);
1425
+ }
1426
+ /**
1427
+ * Removes an event listener for a specific event
1428
+ *
1429
+ * @param event
1430
+ * @param listener
1431
+ */
1432
+ off(event, listener) {
1433
+ this._listeners.get(event)?.delete(listener);
1434
+ }
1435
+ /**
1436
+ * Emits an event to all registered listeners
1437
+ *
1438
+ * @param event
1439
+ */
1440
+ emit(event) {
1441
+ this._listeners.get(event)?.forEach(async (listener) => {
1442
+ listener(this);
1443
+ });
1444
+ }
1445
+ async [_c2 = A_ResponseFeatures.onSend](context, ...args) {
1446
+ const responseData = this._dataOverride || this.toResponse();
1447
+ switch (true) {
1448
+ case (!!responseData && typeof responseData === "object"):
1449
+ this.original.setHeader("Content-Type", `application/json; charset=${this._options.charset}`);
1450
+ this.setDefaultResponseHeaders();
1451
+ this.original.writeHead(this.statusCode);
1452
+ this.original.end(JSON.stringify(responseData));
1453
+ return;
1454
+ case (!!responseData && typeof responseData === "string"):
1455
+ this.original.setHeader("Content-Type", `text/plain; charset=${this._options.charset}`);
1456
+ this.setDefaultResponseHeaders();
1457
+ this.original.writeHead(this.statusCode);
1458
+ this.original.end(responseData);
1459
+ return;
1460
+ default:
1461
+ this.setDefaultResponseHeaders();
1462
+ this.original.writeHead(this.statusCode);
1463
+ this.original.end(responseData);
1464
+ return;
1465
+ }
1466
+ }
1467
+ async [_b2 = A_ResponseFeatures.onRedirect](context, ...args) {
1468
+ if (!this._redirectURL) return;
1469
+ this.original.setHeader("Location", this._redirectURL);
1470
+ if (!this.statusCode || (this.statusCode < 300 || this.statusCode > 399))
1471
+ this.status(301);
1472
+ this.original.end();
1473
+ }
1474
+ async [_a2 = A_ResponseFeatures.onError](error, context, request, ...args) {
1475
+ if (this.headersSent) {
1476
+ return;
1477
+ }
1478
+ const statusCode = error.status || 500;
1479
+ this.status(statusCode);
1480
+ const errorResponse = {
1481
+ error: {
1482
+ message: error.message,
1483
+ status: statusCode,
1484
+ description: error.description || ""
1485
+ }
1486
+ };
1487
+ this.setDefaultResponseHeaders();
1488
+ this.original.writeHead(this.statusCode);
1489
+ this.original.end(JSON.stringify(errorResponse));
1490
+ }
1491
+ // ======================================================================================
1492
+ // --------------------------------------------------------------------------
1493
+ // A-Response Helper Methods
1494
+ // --------------------------------------------------------------------------
1495
+ // ======================================================================================
1496
+ /**
1497
+ * Set standard response headers
1498
+ */
1499
+ setDefaultResponseHeaders() {
1500
+ this.original.setHeader("X-Content-Type-Options", "nosniff");
1501
+ this.original.setHeader("X-Frame-Options", "DENY");
1502
+ this.original.setHeader("X-XSS-Protection", "1; mode=block");
1503
+ this.original.setHeader("X-Request-ID", this.aseid.id);
1504
+ }
1505
+ /**
1506
+ * Set cookie headers
1507
+ */
1508
+ setCookieHeaders() {
1509
+ if (!this._options.enableCookies || this._cookies.size === 0) return;
1510
+ const cookieStrings = [];
1511
+ this._cookies.forEach(({ value, options }, name) => {
1512
+ let cookieString = `${name}=${encodeURIComponent(value)}`;
1513
+ if (options) {
1514
+ if (options.domain) cookieString += `; Domain=${options.domain}`;
1515
+ if (options.path) cookieString += `; Path=${options.path}`;
1516
+ if (options.maxAge) cookieString += `; Max-Age=${options.maxAge}`;
1517
+ if (options.expires) cookieString += `; Expires=${options.expires.toUTCString()}`;
1518
+ if (options.httpOnly) cookieString += "; HttpOnly";
1519
+ if (options.secure) cookieString += "; Secure";
1520
+ if (options.sameSite) cookieString += `; SameSite=${options.sameSite}`;
1521
+ }
1522
+ cookieStrings.push(cookieString);
1523
+ });
1524
+ this.original.setHeader("Set-Cookie", cookieStrings);
1525
+ }
1526
+ /**
1527
+ * Set cache headers
1528
+ */
1529
+ setCacheHeaders() {
1530
+ if (!this._cacheOptions) return;
1531
+ const cacheControl = [];
1532
+ if (this._cacheOptions.public) cacheControl.push("public");
1533
+ if (this._cacheOptions.private) cacheControl.push("private");
1534
+ if (this._cacheOptions.noCache) cacheControl.push("no-cache");
1535
+ if (this._cacheOptions.noStore) cacheControl.push("no-store");
1536
+ if (this._cacheOptions.mustRevalidate) cacheControl.push("must-revalidate");
1537
+ if (this._cacheOptions.proxyRevalidate) cacheControl.push("proxy-revalidate");
1538
+ if (this._cacheOptions.immutable) cacheControl.push("immutable");
1539
+ if (this._cacheOptions.maxAge !== void 0) {
1540
+ cacheControl.push(`max-age=${this._cacheOptions.maxAge}`);
1541
+ }
1542
+ if (this._cacheOptions.sMaxAge !== void 0) {
1543
+ cacheControl.push(`s-maxage=${this._cacheOptions.sMaxAge}`);
1544
+ }
1545
+ if (cacheControl.length > 0) {
1546
+ this.original.setHeader("Cache-Control", cacheControl.join(", "));
1547
+ }
1548
+ if (this._cacheOptions.etag) {
1549
+ this.original.setHeader("ETag", this._cacheOptions.etag);
1550
+ }
1551
+ if (this._cacheOptions.lastModified) {
1552
+ this.original.setHeader("Last-Modified", this._cacheOptions.lastModified.toUTCString());
1553
+ }
1554
+ }
1555
+ // ======================================================================================
1556
+ // --------------------------------------------------------------------------
1557
+ // A-Response Serialization Methods
1558
+ // --------------------------------------------------------------------------
1559
+ // ======================================================================================
1560
+ /**
1561
+ * Convert accumulated data to response object
1562
+ */
1563
+ toResponse() {
1564
+ const response = Array.from(this._data.entries()).reduce((acc, [key, value]) => {
1565
+ if (value instanceof A_Entity) {
1566
+ acc[key] = value.toJSON();
1567
+ } else {
1568
+ acc[key] = value;
1569
+ }
1570
+ return acc;
1571
+ }, {});
1572
+ return response;
1573
+ }
1574
+ /**
1575
+ * Enhanced JSON serialization for logging/debugging
1576
+ */
1577
+ toJSON() {
1578
+ return {
1579
+ ...super.toJSON(),
1580
+ status: this.statusCode,
1581
+ headersSent: this.headersSent,
1582
+ size: this.size,
1583
+ data: this.toResponse(),
1584
+ redirectURL: this._redirectURL
1585
+ };
1586
+ }
1587
+ };
1588
+ __decorateClass([
1589
+ A_Feature.Extend({
1590
+ after: /.*/
1591
+ }),
1592
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext))
1593
+ ], A_Response.prototype, _c2, 1);
1594
+ __decorateClass([
1595
+ A_Feature.Extend({
1596
+ after: /.*/
1597
+ }),
1598
+ __decorateParam(0, A_Inject(A_HttpServerRequestContext))
1599
+ ], A_Response.prototype, _b2, 1);
1600
+ __decorateClass([
1601
+ A_Feature.Extend({
1602
+ after: /.*/
1603
+ }),
1604
+ __decorateParam(0, A_Inject(A_HttpServerError)),
1605
+ __decorateParam(1, A_Inject(A_HttpServerRequestContext)),
1606
+ __decorateParam(2, A_Inject(A_Request))
1607
+ ], A_Response.prototype, _a2, 1);
1608
+ var A_ResponseError = class extends A_Error {
1609
+ };
1610
+
1611
+ // src/lib/A-Server/A-HttpServer.constants.ts
1612
+ var A_HttpServerFeatures = {
1613
+ onBeforeRequest: "_A_HTTPServer_onBeforeRequest",
1614
+ onRequest: "_A_HTTPServer_onRequest",
1615
+ onAfterRequest: "_A_HTTPServer_onAfterRequest"
1616
+ };
1617
+ var A_ServerRoute = class extends A_Route {
1618
+ constructor(param1, param2) {
1619
+ super(param1);
1620
+ this.url = param1 instanceof RegExp ? param1.source : param1;
1621
+ this.method = param2 || "GET";
1622
+ }
1623
+ toString() {
1624
+ return `${this.method}::${this.path}`;
1625
+ }
1626
+ toRegExp() {
1627
+ return new RegExp(`^${this.method}::${this.path.replace(/\/:([^\/]+)/g, "/([^/]+)")}$`);
1628
+ }
1629
+ toAFeatureExtension(extensionScope = []) {
1630
+ return new RegExp(`^${extensionScope.length ? `(${extensionScope.join("|")})` : ".*"}\\.${this.method}::${this.path.replace(/\/:([^\/]+)/g, "/([^/]+)")}$`);
1631
+ }
1632
+ };
1633
+ var A_Server = class extends A_Fragment {
1634
+ constructor(params) {
1635
+ super(params);
1636
+ this._routes = [];
1637
+ this.port = params.port;
1638
+ this._name = params.name;
1639
+ this.version = params.version || "v1";
1640
+ this._routes = params.routes || this._routes;
1641
+ }
1642
+ /**
1643
+ * A list of routes that the server will listen to
1644
+ */
1645
+ get routes() {
1646
+ return this._routes;
1647
+ }
1648
+ };
1649
+ var A_ServerLogger = class extends A_Logger {
1650
+ logRequestFinish(request, response, context) {
1651
+ this.info("green", `Request ${request.method} ${request.url} finished with status ${response.statusCode} in ${context.processingTime ?? "N/A"}ms`);
1652
+ }
1653
+ logResponseError(request, response, context, error) {
1654
+ this.info("red", `Request ${request.method} ${request.url} errored with status ${response.statusCode} in ${context.processingTime ?? "N/A"}ms`);
1655
+ this.error(error);
1656
+ }
1657
+ logStop(server) {
1658
+ this.log("red", `Server ${server.name} stopped`);
1659
+ }
1660
+ serverReady(params) {
1661
+ const processId = process.pid;
1662
+ this.info(
1663
+ "cyan",
1664
+ ` ${params.app.name} v${params.app.version || "0.0.1"} is running on port ${params.port}`,
1665
+ ` Process ID: ${processId}`,
1666
+ ` Open In Browser: http://localhost:${params.port}`,
1667
+ ``,
1668
+ `-------------------------------`,
1669
+ ` ==============================`,
1670
+ ` LISTENING... `,
1671
+ ` ==============================`
1672
+ );
1673
+ }
1674
+ /**
1675
+ * Displays a proxy routes
1676
+ *
1677
+ * @param params
1678
+ */
1679
+ proxy(params) {
1680
+ console.log(`\x1B[35m[${this.scope.name}] |${this.getTime()}| Proxy:
1681
+ ${" ".repeat(this.scopeLength + 3)}| ${params.original} -> ${params.destination}
1682
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m`);
1683
+ }
1684
+ };
1685
+ __decorateClass([
1686
+ A_Feature.Extend({
1687
+ name: A_ResponseFeatures.onSend,
1688
+ scope: [A_Response]
1689
+ }),
1690
+ __decorateParam(0, A_Inject(A_Request)),
1691
+ __decorateParam(1, A_Inject(A_Response)),
1692
+ __decorateParam(2, A_Inject(A_HttpServerRequestContext))
1693
+ ], A_ServerLogger.prototype, "logRequestFinish", 1);
1694
+ __decorateClass([
1695
+ A_Feature.Extend({
1696
+ name: A_ResponseFeatures.onError,
1697
+ scope: [A_Response]
1698
+ }),
1699
+ __decorateParam(0, A_Inject(A_Request)),
1700
+ __decorateParam(1, A_Inject(A_Response)),
1701
+ __decorateParam(2, A_Inject(A_HttpServerRequestContext)),
1702
+ __decorateParam(3, A_Inject(A_Error))
1703
+ ], A_ServerLogger.prototype, "logResponseError", 1);
1704
+ __decorateClass([
1705
+ A_Feature.Extend({
1706
+ name: A_ServiceFeatures.onAfterStop,
1707
+ scope: [A_Service]
1708
+ }),
1709
+ __decorateParam(0, A_Inject(A_Server))
1710
+ ], A_ServerLogger.prototype, "logStop", 1);
1711
+ var _a3, _b3, _c3, _d2, _e2;
1712
+ var A_HttpServer = class extends A_Service {
1713
+ static get onBeforeRequest() {
1714
+ return (target, propertyKey, descriptor) => {
1715
+ return A_Feature.Extend({
1716
+ name: A_HttpServerFeatures.onBeforeRequest,
1717
+ scope: [target.constructor]
1718
+ })(target, propertyKey, descriptor);
1719
+ };
1720
+ }
1721
+ static get onRequest() {
1722
+ return (target, propertyKey, descriptor) => {
1723
+ return A_Feature.Extend({
1724
+ name: A_HttpServerFeatures.onRequest,
1725
+ scope: [target.constructor]
1726
+ })(target, propertyKey, descriptor);
1727
+ };
1728
+ }
1729
+ static get onAfterRequest() {
1730
+ return (target, propertyKey, descriptor) => {
1731
+ return A_Feature.Extend({
1732
+ name: A_HttpServerFeatures.onAfterRequest,
1733
+ scope: [target.constructor]
1734
+ })(target, propertyKey, descriptor);
1735
+ };
1736
+ }
1737
+ async [_e2 = A_ServiceFeatures.onStart](polyfill, config) {
1738
+ const http = await polyfill.http();
1739
+ this.server = http.createServer(this.handleRequest.bind(this));
1740
+ await this.listen(config.get("A_SERVER_PORT"));
1741
+ }
1742
+ async [_d2 = A_ServiceFeatures.onAfterStart](config, logger) {
1743
+ logger.serverReady({
1744
+ port: config.get("A_SERVER_PORT"),
1745
+ app: {
1746
+ name: this.scope.name
1747
+ }
1748
+ });
1749
+ }
1750
+ async [A_ServiceFeatures.onStop](...args) {
1751
+ await this.close();
1752
+ }
1753
+ close() {
1754
+ return new Promise((resolve, reject) => {
1755
+ this.server.close(() => {
1756
+ resolve();
1757
+ });
1758
+ });
1759
+ }
1760
+ listen(port) {
1761
+ return new Promise((resolve, reject) => {
1762
+ this.server.listen(port, () => {
1763
+ resolve();
1764
+ });
1765
+ });
1766
+ }
1767
+ async [_c3 = A_HttpServerFeatures.onBeforeRequest](...args) {
1768
+ }
1769
+ async [_b3 = A_HttpServerFeatures.onRequest](...args) {
1770
+ }
1771
+ async [_a3 = A_HttpServerFeatures.onAfterRequest](...args) {
1772
+ }
1773
+ // ======================================================================================
1774
+ // ============================= A_HttpServer Methods =================================
1775
+ // ======================================================================================
1776
+ async handleRequest(request, response) {
1777
+ const route = new A_ServerRoute(
1778
+ request.url || "",
1779
+ request.method
1780
+ );
1781
+ const id = A_IdentityHelper.generateTimeId();
1782
+ const shard = `${request.method}-${route.path.replace("/", "-")}`;
1783
+ const req = new A_Request({ id, shard, request, scope: this.scope.name });
1784
+ const res = new A_Response({ id, shard, response, scope: this.scope.name });
1785
+ const context = new A_HttpServerRequestContext(request, response);
1786
+ const scope = new A_Scope({
1787
+ name: id,
1788
+ entities: [req, res],
1789
+ fragments: [route, context]
1790
+ }).inherit(this.scope);
1791
+ try {
1792
+ const onBeforeRequestFeature = new A_Feature({
1793
+ name: A_HttpServerFeatures.onBeforeRequest,
1794
+ component: this
1795
+ });
1796
+ const onRequestFeature = new A_Feature({
1797
+ name: A_HttpServerFeatures.onRequest,
1798
+ component: this
1799
+ });
1800
+ const onAfterRequestFeature = new A_Feature({
1801
+ name: A_HttpServerFeatures.onAfterRequest,
1802
+ component: this
1803
+ });
1804
+ await new Promise(async (resolve, reject) => {
1805
+ const cleanup = () => {
1806
+ onBeforeRequestFeature.interrupt();
1807
+ onRequestFeature.interrupt();
1808
+ onAfterRequestFeature.interrupt();
1809
+ req.off(A_RequestFeatures.onError, cleanup);
1810
+ req.off(A_RequestFeatures.onClose, cleanup);
1811
+ req.off(A_RequestFeatures.onTimeout, cleanup);
1812
+ reject(scope.resolve(A_Error));
1813
+ };
1814
+ req.on(A_RequestFeatures.onError, cleanup.bind(this));
1815
+ req.on(A_RequestFeatures.onClose, cleanup.bind(this));
1816
+ try {
1817
+ await req.load();
1818
+ await res.load();
1819
+ await onBeforeRequestFeature.process(scope);
1820
+ await onRequestFeature.process(scope);
1821
+ await onAfterRequestFeature.process(scope);
1822
+ req.clearTimeout();
1823
+ await res.status(200).send();
1824
+ resolve();
1825
+ } catch (error) {
1826
+ req.clearTimeout();
1827
+ reject(error);
1828
+ }
1829
+ });
1830
+ } catch (error) {
1831
+ let wrappedError;
1832
+ switch (true) {
1833
+ case error instanceof A_HttpServerError:
1834
+ wrappedError = error;
1835
+ break;
1836
+ case (error instanceof A_Error && error.originalError instanceof A_HttpServerError):
1837
+ wrappedError = error.originalError;
1838
+ break;
1839
+ default:
1840
+ wrappedError = new A_HttpServerError({
1841
+ status: 500,
1842
+ description: "An error occurred while processing the request.",
1843
+ originalError: error
1844
+ });
1845
+ break;
1846
+ }
1847
+ scope.register(wrappedError);
1848
+ await res.fail(wrappedError);
1849
+ await this.call(A_ServiceFeatures.onError, scope);
1850
+ }
1851
+ scope.destroy();
1852
+ }
1853
+ };
1854
+ __decorateClass([
1855
+ A_Feature.Extend(),
1856
+ __decorateParam(0, A_Dependency.Required()),
1857
+ __decorateParam(0, A_Inject(A_Polyfill)),
1858
+ __decorateParam(1, A_Dependency.Required()),
1859
+ __decorateParam(1, A_Inject(A_Config))
1860
+ ], A_HttpServer.prototype, _e2, 1);
1861
+ __decorateClass([
1862
+ A_Feature.Extend(),
1863
+ __decorateParam(0, A_Inject(A_Config)),
1864
+ __decorateParam(1, A_Inject(A_ServerLogger))
1865
+ ], A_HttpServer.prototype, _d2, 1);
1866
+ __decorateClass([
1867
+ A_Feature.Extend()
1868
+ ], A_HttpServer.prototype, _c3, 1);
1869
+ __decorateClass([
1870
+ A_Feature.Extend()
1871
+ ], A_HttpServer.prototype, _b3, 1);
1872
+ __decorateClass([
1873
+ A_Feature.Extend()
1874
+ ], A_HttpServer.prototype, _a3, 1);
1875
+ var A_ServerError = class extends A_Error {
1876
+ constructor() {
1877
+ super(...arguments);
1878
+ this.status = 500;
1879
+ }
1880
+ fromConstructor(params) {
1881
+ super.fromConstructor(params);
1882
+ if (params.status) {
1883
+ this.status = params.status;
1884
+ }
1885
+ }
1886
+ toJSON() {
1887
+ return {
1888
+ ...super.toJSON(),
1889
+ status: this.status
1890
+ };
1891
+ }
1892
+ };
1893
+
1894
+ // src/lib/A-ServerRoute/A-ServerRoute.constants.ts
1895
+ var A_ServerRouteHttpMethods = {
1896
+ DEFAULT: "DEFAULT",
1897
+ GET: "GET",
1898
+ POST: "POST",
1899
+ PUT: "PUT",
1900
+ DELETE: "DELETE",
1901
+ PATCH: "PATCH",
1902
+ OPTIONS: "OPTIONS",
1903
+ HEAD: "HEAD",
1904
+ CONNECT: "CONNECT",
1905
+ TRACE: "TRACE"
1906
+ };
1907
+ var A_ServerRouteProtocols = {
1908
+ HTTP: "http",
1909
+ HTTPS: "https",
1910
+ WS: "ws",
1911
+ WSS: "wss"
1912
+ };
1913
+
1914
+ // src/lib/A-ServerRouter/A-ServerRouter.constants.ts
1915
+ var A_ServerRouterMetaKeys = {
1916
+ ROUTES: "_A_ServerRouterMeta_ROUTES",
1917
+ ROUTES_CONFIGS: "_A_ServerRouterMeta_ROUTES_CONFIGS"
1918
+ };
1919
+
1920
+ // src/lib/A-ServerRouter/A-ServerRouter.meta.ts
1921
+ var A_ServerRouterMeta = class extends A_ComponentMeta {
1922
+ get routes() {
1923
+ return this.meta.get(A_ServerRouterMetaKeys.ROUTES_CONFIGS) || [];
1924
+ }
1925
+ get definitions() {
1926
+ return this.meta.get(A_ServerRouterMetaKeys.ROUTES) || /* @__PURE__ */ new Map();
1927
+ }
1928
+ addRoute(regexp, route) {
1929
+ const existingRoutes = this.meta.get(A_ServerRouterMetaKeys.ROUTES) || /* @__PURE__ */ new Map();
1930
+ existingRoutes.set(regexp.source, route);
1931
+ this.meta.set(A_ServerRouterMetaKeys.ROUTES, existingRoutes);
1932
+ const existingRoutesConfigs = this.meta.get(A_ServerRouterMetaKeys.ROUTES_CONFIGS) || [];
1933
+ existingRoutesConfigs.push(route.route);
1934
+ this.meta.set(A_ServerRouterMetaKeys.ROUTES_CONFIGS, existingRoutesConfigs);
1935
+ }
1936
+ removeRoute(route) {
1937
+ const existingRoutes = this.meta.get(A_ServerRouterMetaKeys.ROUTES) || /* @__PURE__ */ new Map();
1938
+ existingRoutes.forEach((value, key) => {
1939
+ if (value.route === route) {
1940
+ existingRoutes.delete(key);
1941
+ }
1942
+ });
1943
+ this.meta.set(A_ServerRouterMetaKeys.ROUTES, existingRoutes);
1944
+ const existingRoutesConfigs = this.meta.get(A_ServerRouterMetaKeys.ROUTES_CONFIGS) || [];
1945
+ const index = existingRoutesConfigs.indexOf(route);
1946
+ if (index !== -1) {
1947
+ existingRoutesConfigs.splice(index, 1);
1948
+ }
1949
+ this.meta.set(A_ServerRouterMetaKeys.ROUTES_CONFIGS, existingRoutesConfigs);
1950
+ }
1951
+ };
1952
+ function A_ServerRouterDefineDecorator(route) {
1953
+ return function(target, propertyKey, descriptor) {
1954
+ const meta = A_Context.meta(A_ServerRouter);
1955
+ const searchKey = route.toAFeatureExtension(["A_ServerRouter", "A_Service"]);
1956
+ meta.addRoute(searchKey, {
1957
+ component: target,
1958
+ handler: propertyKey,
1959
+ route
1960
+ });
1961
+ A_Feature_Define({
1962
+ name: searchKey.source,
1963
+ invoke: false
1964
+ })(target, propertyKey, descriptor);
1965
+ return A_Feature_Extend(searchKey)(target, propertyKey, descriptor);
1966
+ };
1967
+ }
1968
+
1969
+ // src/lib/A-ServerRouter/A-ServerRouter.component.ts
1970
+ var A_ServerRouter = class extends A_Component {
1971
+ // =======================================================
1972
+ // ================ Method Definition=====================
1973
+ // =======================================================
1974
+ /**
1975
+ * Allows to define a custom route for POST requests
1976
+ *
1977
+ * @param path
1978
+ * @returns
1979
+ */
1980
+ static Post(path) {
1981
+ return this.defineRoute({
1982
+ method: A_ServerRouteHttpMethods.POST,
1983
+ path: typeof path === "object" && "path" in path ? path.path : path,
1984
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
1985
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
1986
+ });
1987
+ }
1988
+ /**
1989
+ * Allows to define a custom route for GET requests
1990
+ *
1991
+ * @param path
1992
+ * @returns
1993
+ */
1994
+ static Get(path) {
1995
+ return this.defineRoute({
1996
+ method: A_ServerRouteHttpMethods.GET,
1997
+ path: typeof path === "object" && "path" in path ? path.path : path,
1998
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
1999
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
2000
+ });
2001
+ }
2002
+ /**
2003
+ * Allows to define a custom route for PUT requests
2004
+ *
2005
+ * @param path
2006
+ * @returns
2007
+ */
2008
+ static Put(path) {
2009
+ return this.defineRoute({
2010
+ method: A_ServerRouteHttpMethods.PUT,
2011
+ path: typeof path === "object" && "path" in path ? path.path : path,
2012
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
2013
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
2014
+ });
2015
+ }
2016
+ /**
2017
+ * Allows to define a custom route for DELETE requests
2018
+ *
2019
+ * @param path
2020
+ * @returns
2021
+ */
2022
+ static Delete(path) {
2023
+ return this.defineRoute({
2024
+ method: A_ServerRouteHttpMethods.DELETE,
2025
+ path: typeof path === "object" && "path" in path ? path.path : path,
2026
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
2027
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
2028
+ });
2029
+ }
2030
+ /**
2031
+ * Allows to define a custom route for PATCH requests
2032
+ *
2033
+ * @param path
2034
+ * @returns
2035
+ */
2036
+ static Patch(path) {
2037
+ return this.defineRoute({
2038
+ method: A_ServerRouteHttpMethods.PATCH,
2039
+ path: typeof path === "object" && "path" in path ? path.path : path,
2040
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
2041
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
2042
+ });
2043
+ }
2044
+ /**
2045
+ * Allows to define a custom route for DEFAULT requests
2046
+ *
2047
+ * @param path
2048
+ * @returns
2049
+ */
2050
+ static Default(path) {
2051
+ return this.defineRoute({
2052
+ method: A_ServerRouteHttpMethods.DEFAULT,
2053
+ path: typeof path === "object" && "path" in path ? path.path : path,
2054
+ version: typeof path === "object" && "version" in path && path.version ? path.version : "v1",
2055
+ prefix: typeof path === "object" && "prefix" in path && path.prefix ? path.prefix : "api"
2056
+ });
2057
+ }
2058
+ // static routes: Array<A_ServerRoute> = [];
2059
+ /**
2060
+ * Private method to have the same signature for all route methods
2061
+ *
2062
+ * @param method
2063
+ * @param path
2064
+ * @returns
2065
+ */
2066
+ static defineRoute(config) {
2067
+ const route = typeof config.path === "string" || config.path instanceof RegExp ? new A_ServerRoute(
2068
+ `/${config.prefix}/${config.version}${config.path instanceof RegExp ? config.path.source : config.path.startsWith("/") ? config.path : `/${config.path}`}`,
2069
+ config.method
2070
+ ) : config.path;
2071
+ return A_ServerRouterDefineDecorator(route);
2072
+ }
2073
+ async load(logger) {
2074
+ const meta = A_Context.meta(this.constructor);
2075
+ const routes = meta.routes;
2076
+ if (!routes || !routes.length) {
2077
+ logger.warning("yellow", `No routes defined for ${this.constructor.name}`);
2078
+ return;
2079
+ }
2080
+ logger.info(
2081
+ "cyan",
2082
+ `Registered Routes:`,
2083
+ `------------------------------------
2084
+ `,
2085
+ ...routes.map((route) => `[${route.method.toUpperCase()}]${" ".repeat(7 - route.method.length)} ${route.path}`)
2086
+ );
2087
+ }
2088
+ async identifyRoute(request, response, scope, config, logger, route) {
2089
+ if (route.method === "OPTIONS") {
2090
+ return;
2091
+ }
2092
+ const feature = new A_Feature({ name: route.toString(), component: this });
2093
+ if (!feature.size)
2094
+ throw new A_HttpServerError({
2095
+ status: 404,
2096
+ title: "Route Not Found",
2097
+ description: `No route found for ${request.method} ${request.url}`
2098
+ });
2099
+ for (const stage of feature) {
2100
+ const targetConstructor = stage.definition.dependency.target;
2101
+ if (A_TypeGuards.isComponentConstructor(targetConstructor)) {
2102
+ const meta = A_Context.meta(this.constructor);
2103
+ const routeDefinitions = meta.definitions;
2104
+ const routeDefinition = routeDefinitions?.get(stage.definition.name || "");
2105
+ if (routeDefinition) {
2106
+ request.useRoute(routeDefinition.route);
2107
+ }
2108
+ }
2109
+ const stageScope = new A_Scope({
2110
+ name: `a-route--${request.id}--${stage.definition.name}`
2111
+ }, {
2112
+ parent: scope
2113
+ });
2114
+ await stage.process(stageScope);
2115
+ }
2116
+ }
2117
+ };
2118
+ __decorateClass([
2119
+ A_Concept.Load(),
2120
+ __decorateParam(0, A_Inject(A_ServerLogger))
2121
+ ], A_ServerRouter.prototype, "load", 1);
2122
+ __decorateClass([
2123
+ A_Feature.Extend({
2124
+ name: A_HttpServerFeatures.onRequest
2125
+ }),
2126
+ __decorateParam(0, A_Inject(A_Request)),
2127
+ __decorateParam(1, A_Inject(A_Response)),
2128
+ __decorateParam(2, A_Inject(A_Scope)),
2129
+ __decorateParam(3, A_Inject(A_Config)),
2130
+ __decorateParam(4, A_Inject(A_Logger)),
2131
+ __decorateParam(5, A_Inject(A_ServerRoute))
2132
+ ], A_ServerRouter.prototype, "identifyRoute", 1);
2133
+ A_ServerRouter = __decorateClass([
2134
+ A_Meta.Define(A_ServerRouterMeta)
2135
+ ], A_ServerRouter);
2136
+
2137
+ // src/lib/A-ServerController/A-ServerController.component.ts
2138
+ var A_ServerController = class extends A_Component {
2139
+ async callEntityMethod(request, response, scope) {
2140
+ if (!scope.has(request.params.component))
2141
+ return;
2142
+ if (!request.params.operation || typeof request.params.operation !== "string")
2143
+ return;
2144
+ const possibleComponent = scope.resolve(request.params.component);
2145
+ if (!possibleComponent || ![A_Component, A_Container].some((c) => possibleComponent instanceof c))
2146
+ return;
2147
+ const component = possibleComponent;
2148
+ const meta = A_Context.meta(component);
2149
+ const targetFeature = meta.features().find((f) => f.name === `${component.constructor.name}.${request.params.operation}`);
2150
+ if (!targetFeature)
2151
+ return;
2152
+ await component.call(request.params.operation, scope);
2153
+ }
2154
+ };
2155
+ __decorateClass([
2156
+ A_ServerRouter.Post({
2157
+ path: "/:component/:operation",
2158
+ version: "v1",
2159
+ prefix: "a-component"
2160
+ }),
2161
+ __decorateParam(0, A_Inject(A_Request)),
2162
+ __decorateParam(1, A_Inject(A_Response)),
2163
+ __decorateParam(2, A_Inject(A_Scope))
2164
+ ], A_ServerController.prototype, "callEntityMethod", 1);
2165
+ var A_ServerEntityList = class extends A_Entity {
2166
+ constructor() {
2167
+ super(...arguments);
2168
+ this._items = [];
2169
+ this._pagination = {
2170
+ total: 0,
2171
+ page: 1,
2172
+ pageSize: 10
2173
+ };
2174
+ }
2175
+ static get scope() {
2176
+ return "a-server";
2177
+ }
2178
+ /**
2179
+ * Returns the entity constructor used for the list
2180
+ */
2181
+ get entityConstructor() {
2182
+ return this._entityConstructor;
2183
+ }
2184
+ /**
2185
+ * Returns the list of items contained in the entity list
2186
+ */
2187
+ get items() {
2188
+ return this._items;
2189
+ }
2190
+ /**
2191
+ * Returns pagination information about the entity list
2192
+ */
2193
+ get pagination() {
2194
+ return this._pagination;
2195
+ }
2196
+ /**
2197
+ * Creates a new instance of A_EntityList
2198
+ *
2199
+ * @param newEntity
2200
+ */
2201
+ fromNew(newEntity) {
2202
+ this.aseid = new ASEID({
2203
+ concept: A_Context.root.name,
2204
+ scope: "default",
2205
+ entity: "a-list" + (newEntity.name ? `.${newEntity.name}` : ""),
2206
+ id: (/* @__PURE__ */ new Date()).getTime().toString()
2207
+ });
2208
+ this._entityConstructor = newEntity.constructor;
2209
+ }
2210
+ /**
2211
+ * Allows to convert Repository Response data to EntityList instance
2212
+ *
2213
+ * [!] This method does not load the data from the repository, it only converts the data to the EntityList instance
2214
+ *
2215
+ * @param items
2216
+ * @param pagination
2217
+ */
2218
+ fromList(items, pagination) {
2219
+ this._items = items.map((item) => {
2220
+ if (item instanceof A_Entity) {
2221
+ return item;
2222
+ } else {
2223
+ const entity = new this._entityConstructor(item);
2224
+ return entity;
2225
+ }
2226
+ });
2227
+ if (pagination) {
2228
+ this._pagination = {
2229
+ total: pagination.total,
2230
+ page: pagination.page,
2231
+ pageSize: pagination.pageSize
2232
+ };
2233
+ }
2234
+ }
2235
+ /**
2236
+ * Serializes the EntityList to a JSON object
2237
+ *
2238
+ * @returns
2239
+ */
2240
+ toJSON() {
2241
+ return {
2242
+ ...super.toJSON(),
2243
+ items: this._items.map((i) => i.toJSON()),
2244
+ pagination: this._pagination
2245
+ };
2246
+ }
2247
+ };
2248
+
2249
+ // src/lib/A-ServerEntityList/A-EntityList.types.ts
2250
+ var A_SERVER_TYPES__A_EntityListEvent = /* @__PURE__ */ ((A_SERVER_TYPES__A_EntityListEvent2) => {
2251
+ A_SERVER_TYPES__A_EntityListEvent2["Load"] = "load";
2252
+ return A_SERVER_TYPES__A_EntityListEvent2;
2253
+ })(A_SERVER_TYPES__A_EntityListEvent || {});
2254
+ var A_ServerListQueryFilter = class extends A_Fragment {
2255
+ constructor(_query = {}, defaults = {}) {
2256
+ super();
2257
+ this._query = _query;
2258
+ this.defaults = defaults;
2259
+ this.parsedQuery = this.parseQueryString(_query);
2260
+ }
2261
+ get query() {
2262
+ return this._query;
2263
+ }
2264
+ get(property, defaultValue = "") {
2265
+ return this.parsedQuery[property] || this.defaults[property] || defaultValue;
2266
+ }
2267
+ parseQueryString(value = {}) {
2268
+ if (typeof value === "string") {
2269
+ return value.split("&").reduce((acc, part) => {
2270
+ const [key, val] = part.split("=");
2271
+ acc[decodeURIComponent(key)] = decodeURIComponent(val || "");
2272
+ return acc;
2273
+ }, {});
2274
+ }
2275
+ return value;
2276
+ }
2277
+ };
2278
+
2279
+ // src/lib/A-ServerLogger/A-ServerLogger.constants.ts
2280
+ var A_SERVER__A_SERVER_LOGGER_ENV_VARIABLES = {
2281
+ // ----------------------------------------------------------
2282
+ // A-ServerLogger Environment Variables
2283
+ // ----------------------------------------------------------
2284
+ // These environment variables are used by A-Concept core to configure the application
2285
+ // ----------------------------------------------------------
2286
+ /**
2287
+ * Enable logging of 200 responses
2288
+ */
2289
+ SERVER_IGNORE_LOG_200: "SERVER_IGNORE_LOG_200",
2290
+ /**
2291
+ * Enable logging of 404 responses
2292
+ */
2293
+ SERVER_IGNORE_LOG_404: "SERVER_IGNORE_LOG_404",
2294
+ /**
2295
+ * Enable logging of 500 responses
2296
+ */
2297
+ SERVER_IGNORE_LOG_500: "SERVER_IGNORE_LOG_500",
2298
+ /**
2299
+ * Enable logging of 400 responses
2300
+ */
2301
+ SERVER_IGNORE_LOG_400: "SERVER_IGNORE_LOG_400",
2302
+ /**
2303
+ * Enable logging of default responses
2304
+ */
2305
+ SERVER_IGNORE_LOG_DEFAULT: "SERVER_IGNORE_LOG_DEFAULT"
2306
+ };
2307
+ var A_ServerMiddleware = class extends A_Component {
2308
+ // static get features() {
2309
+ // // return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
2310
+ // // return A_Feature.Extend({
2311
+ // // name: A_ServerMiddlewareFeatures.onBeforeInit,
2312
+ // // scope: [target.constructor],
2313
+ // // })(target, propertyKey, descriptor);
2314
+ // // }
2315
+ // }
2316
+ };
2317
+
2318
+ // src/lib/A-ServerProxy/A-ServerProxy.constants.ts
2319
+ var PROXY_CONFIG_DEFAULTS = {
2320
+ path: "/",
2321
+ hostname: "localhost",
2322
+ port: 80,
2323
+ method: "GET",
2324
+ headers: {},
2325
+ protocol: "http"
2326
+ };
2327
+
2328
+ // src/lib/A-ServerProxy/A-ServerProxy.context.ts
2329
+ var A_ProxyConfig = class extends A_Fragment {
2330
+ constructor(configs = {}) {
2331
+ super();
2332
+ this._configs = Object.entries(configs).map(([path, config]) => {
2333
+ const targetUrl = new URL(typeof config === "string" ? config : config.hostname || "");
2334
+ const port = targetUrl.port || (targetUrl.protocol === "https:" ? "443" : "80");
2335
+ const prepared = {
2336
+ ...PROXY_CONFIG_DEFAULTS,
2337
+ ...typeof config === "string" ? {
2338
+ path,
2339
+ port: parseInt(port),
2340
+ protocol: targetUrl.protocol,
2341
+ hostname: targetUrl.hostname
2342
+ } : config
2343
+ };
2344
+ return {
2345
+ route: new A_ServerRoute(prepared.path, prepared.method),
2346
+ hostname: prepared.hostname,
2347
+ port: prepared.port,
2348
+ headers: prepared.headers,
2349
+ protocol: prepared.protocol
2350
+ };
2351
+ });
2352
+ }
2353
+ /**
2354
+ * Returns all configured proxy configs
2355
+ *
2356
+ */
2357
+ get configs() {
2358
+ return this._configs;
2359
+ }
2360
+ /**
2361
+ * Checks if a given path is configured in the proxy
2362
+ *
2363
+ * @param path
2364
+ * @returns
2365
+ */
2366
+ has(path) {
2367
+ return this._configs.some((route) => route.route.toRegExp().test(path));
2368
+ }
2369
+ /**
2370
+ * Returns the proxy configuration for a given path, if exists
2371
+ *
2372
+ * @param path
2373
+ * @returns
2374
+ */
2375
+ config(path) {
2376
+ return this._configs.find((route) => route.route.toRegExp().test(path));
2377
+ }
2378
+ };
2379
+ var A_ServerProxy = class extends A_Component {
2380
+ async load(logger, config) {
2381
+ logger.info(
2382
+ "green",
2383
+ `Proxy routes configured:`,
2384
+ ...config.configs.map((c) => `${c.route.toString()} -> ${c.protocol}//${c.hostname}:${c.port}`)
2385
+ );
2386
+ }
2387
+ async onRequest(req, res, proxyConfig, logger, polyfill, feature) {
2388
+ return new Promise(async (resolve, reject) => {
2389
+ const { method, url } = req;
2390
+ const route = new A_ServerRoute(url, method);
2391
+ const config = proxyConfig.config(route.toString());
2392
+ if (!config) {
2393
+ return resolve();
2394
+ }
2395
+ logger.log(
2396
+ "yellow",
2397
+ `Proxying request ${method} ${url} to ${config.hostname}`,
2398
+ config
2399
+ );
2400
+ const client = await (config.protocol === "https:" ? polyfill.https() : polyfill.http());
2401
+ const proxyReq = client.request(
2402
+ {
2403
+ method: config.route.method,
2404
+ hostname: config.hostname,
2405
+ port: config.port,
2406
+ headers: config.headers,
2407
+ path: route.path
2408
+ },
2409
+ (proxyRes) => {
2410
+ if (!res.headersSent) {
2411
+ res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
2412
+ }
2413
+ proxyRes.on("end", () => {
2414
+ logger.log("green", `Proxy request to ${config?.hostname} completed`);
2415
+ resolve();
2416
+ });
2417
+ proxyRes.pipe(res.original);
2418
+ }
2419
+ );
2420
+ proxyReq.on("error", (err) => reject(err));
2421
+ req.pipe(proxyReq);
2422
+ feature.interrupt();
2423
+ });
2424
+ }
2425
+ };
2426
+ __decorateClass([
2427
+ A_Concept.Load(),
2428
+ __decorateParam(0, A_Inject(A_Logger)),
2429
+ __decorateParam(1, A_Inject(A_ProxyConfig))
2430
+ ], A_ServerProxy.prototype, "load", 1);
2431
+ __decorateClass([
2432
+ A_Feature.Extend({
2433
+ name: A_HttpServerFeatures.onRequest,
2434
+ before: /.*/
2435
+ }),
2436
+ __decorateParam(0, A_Inject(A_Request)),
2437
+ __decorateParam(1, A_Inject(A_Response)),
2438
+ __decorateParam(2, A_Inject(A_ProxyConfig)),
2439
+ __decorateParam(3, A_Inject(A_Logger)),
2440
+ __decorateParam(4, A_Inject(A_Polyfill)),
2441
+ __decorateParam(5, A_Inject(A_Feature))
2442
+ ], A_ServerProxy.prototype, "onRequest", 1);
2443
+ var A_StaticConfig = class extends A_Fragment {
2444
+ constructor(directories = [], directoryConfigs = []) {
2445
+ super();
2446
+ this._aliases = /* @__PURE__ */ new Map();
2447
+ this._directoryConfigs = [];
2448
+ this.directories = directories;
2449
+ this._directoryConfigs = directoryConfigs;
2450
+ this.initializeDefaultAliases();
2451
+ this.initializeCustomAliases();
2452
+ }
2453
+ initializeDefaultAliases() {
2454
+ this.directories.forEach((dir, index) => {
2455
+ const alias = {
2456
+ alias: `/static${index > 0 ? index : ""}`,
2457
+ path: `/static${index > 0 ? index : ""}`,
2458
+ directory: dir,
2459
+ enabled: true
2460
+ };
2461
+ this._aliases.set(alias.path, alias);
2462
+ });
2463
+ }
2464
+ initializeCustomAliases() {
2465
+ this._directoryConfigs.forEach((config) => {
2466
+ const alias = {
2467
+ alias: config.alias || config.path,
2468
+ path: config.path,
2469
+ directory: config.directory,
2470
+ enabled: true
2471
+ };
2472
+ this._aliases.set(alias.path, alias);
2473
+ });
2474
+ }
2475
+ /**
2476
+ * Add a custom static file alias
2477
+ * @param alias - The URL path alias (e.g., '/assets')
2478
+ * @param directory - The local directory path
2479
+ * @param path - Optional custom path (defaults to alias)
2480
+ */
2481
+ addAlias(alias, directory, path) {
2482
+ const staticAlias = {
2483
+ alias,
2484
+ path: path || alias,
2485
+ directory,
2486
+ enabled: true
2487
+ };
2488
+ this._aliases.set(staticAlias.path, staticAlias);
2489
+ }
2490
+ /**
2491
+ * Remove a static file alias
2492
+ * @param aliasPath - The path of the alias to remove
2493
+ */
2494
+ removeAlias(aliasPath) {
2495
+ return this._aliases.delete(aliasPath);
2496
+ }
2497
+ /**
2498
+ * Enable or disable an alias
2499
+ * @param aliasPath - The path of the alias
2500
+ * @param enabled - Whether to enable or disable
2501
+ */
2502
+ setAliasEnabled(aliasPath, enabled) {
2503
+ const alias = this._aliases.get(aliasPath);
2504
+ if (alias) {
2505
+ alias.enabled = enabled;
2506
+ return true;
2507
+ }
2508
+ return false;
2509
+ }
2510
+ /**
2511
+ * Get all configured aliases
2512
+ */
2513
+ getAliases() {
2514
+ return Array.from(this._aliases.values());
2515
+ }
2516
+ /**
2517
+ * Get enabled aliases only
2518
+ */
2519
+ getEnabledAliases() {
2520
+ return Array.from(this._aliases.values()).filter((alias) => alias.enabled !== false);
2521
+ }
2522
+ /**
2523
+ * Find the best matching alias for a given request path
2524
+ * @param requestPath - The request path to match
2525
+ */
2526
+ findMatchingAlias(requestPath) {
2527
+ let bestMatch = null;
2528
+ let longestMatch = 0;
2529
+ for (const alias of this.getEnabledAliases()) {
2530
+ if (requestPath.startsWith(alias.path) && alias.path.length > longestMatch) {
2531
+ bestMatch = alias;
2532
+ longestMatch = alias.path.length;
2533
+ }
2534
+ }
2535
+ return bestMatch;
2536
+ }
2537
+ /**
2538
+ * Check if an alias exists
2539
+ * @param aliasPath - The path to check
2540
+ */
2541
+ hasAlias(aliasPath) {
2542
+ return this._aliases.has(aliasPath);
2543
+ }
2544
+ /**
2545
+ * Get a specific alias by path
2546
+ * @param aliasPath - The path of the alias
2547
+ */
2548
+ getAlias(aliasPath) {
2549
+ return this._aliases.get(aliasPath);
2550
+ }
2551
+ /**
2552
+ * Add multiple aliases at once
2553
+ * @param aliases - Array of alias configurations
2554
+ */
2555
+ addAliases(aliases) {
2556
+ aliases.forEach((config) => {
2557
+ this.addAlias(config.alias || config.path, config.directory, config.path);
2558
+ });
2559
+ }
2560
+ /**
2561
+ * Clear all aliases
2562
+ */
2563
+ clearAliases() {
2564
+ this._aliases.clear();
2565
+ }
2566
+ /**
2567
+ * Update an existing alias
2568
+ * @param aliasPath - The path of the alias to update
2569
+ * @param updates - Partial updates to apply
2570
+ */
2571
+ updateAlias(aliasPath, updates) {
2572
+ const alias = this._aliases.get(aliasPath);
2573
+ if (alias) {
2574
+ Object.assign(alias, updates);
2575
+ return true;
2576
+ }
2577
+ return false;
2578
+ }
2579
+ /**
2580
+ * Get statistics about configured aliases
2581
+ */
2582
+ getStats() {
2583
+ const aliases = this.getAliases();
2584
+ const enabled = aliases.filter((a) => a.enabled !== false);
2585
+ const disabled = aliases.filter((a) => a.enabled === false);
2586
+ const directories = [...new Set(aliases.map((a) => a.directory))];
2587
+ return {
2588
+ total: aliases.length,
2589
+ enabled: enabled.length,
2590
+ disabled: disabled.length,
2591
+ directories
2592
+ };
2593
+ }
2594
+ /**
2595
+ * Checks if a given path is configured in the proxy (legacy method)
2596
+ * @deprecated Use findMatchingAlias instead
2597
+ * @param path
2598
+ * @returns
2599
+ */
2600
+ has(path) {
2601
+ const alias = this.findMatchingAlias(path);
2602
+ return alias ? !!alias.directory : false;
2603
+ }
2604
+ /**
2605
+ * Gets the directory for a given path if configured (legacy method)
2606
+ *
2607
+ * @param path
2608
+ * @returns
2609
+ */
2610
+ get(path) {
2611
+ const alias = this.findMatchingAlias(path);
2612
+ return alias ? alias.directory : void 0;
2613
+ }
2614
+ };
2615
+ var _a4;
2616
+ var A_StaticLoader = class extends A_Component {
2617
+ async load(logger, config, polyfill) {
2618
+ this._fsPolyfill = await polyfill.fs();
2619
+ this._pathPolyfill = await polyfill.path();
2620
+ const aliases = config.getEnabledAliases();
2621
+ logger.info(
2622
+ "cyan",
2623
+ `Static aliases configured:`,
2624
+ ...aliases.map((alias) => `${alias.alias} -> ${alias.directory}`)
2625
+ );
2626
+ }
2627
+ async [_a4 = A_HttpServerFeatures.onRequest](req, res, logger, config, polyfill) {
2628
+ if (req.method !== "GET" && req.method !== "HEAD") {
2629
+ return;
2630
+ }
2631
+ const { method, url } = req;
2632
+ const route = new A_ServerRoute(url, method);
2633
+ const alias = config.findMatchingAlias(route.path);
2634
+ if (!alias) {
2635
+ return;
2636
+ }
2637
+ try {
2638
+ const fs = this._fsPolyfill || await polyfill.fs();
2639
+ const path = this._pathPolyfill || await polyfill.path();
2640
+ const staticDir = path.resolve(process.cwd(), alias.directory);
2641
+ if (!fs.existsSync(staticDir)) {
2642
+ logger.log("red", `Static directory ${staticDir} does not exist.`);
2643
+ return;
2644
+ }
2645
+ const relativePath = route.path.replace(alias.path, "");
2646
+ const safePath = this.safeFilePath(staticDir, relativePath, req.headers?.host, path, fs);
2647
+ await this.serveFile(safePath, res, logger, fs, path);
2648
+ logger.log("green", `Successfully served: ${safePath}`);
2649
+ } catch (error) {
2650
+ throw new A_HttpServerError({
2651
+ status: 500,
2652
+ title: "Static File Serving Error",
2653
+ description: `Error serving static file for ${route.path}: ${error.message}`,
2654
+ originalError: error
2655
+ });
2656
+ }
2657
+ }
2658
+ /**
2659
+ * Add a custom static file alias through the config
2660
+ * @param alias - The URL path alias (e.g., '/assets')
2661
+ * @param directory - The local directory path
2662
+ * @param path - Optional custom path (defaults to alias)
2663
+ * @param config - Static config instance
2664
+ * @param logger - Logger instance for logging
2665
+ */
2666
+ addAlias(alias, directory, config, logger, path) {
2667
+ config.addAlias(alias, directory, path);
2668
+ if (logger) {
2669
+ logger.log("cyan", `Static alias added: ${alias} -> ${directory}`);
2670
+ }
2671
+ }
2672
+ /**
2673
+ * Remove a static file alias through the config
2674
+ * @param aliasPath - The path of the alias to remove
2675
+ * @param config - Static config instance
2676
+ * @param logger - Logger instance for logging
2677
+ */
2678
+ removeAlias(aliasPath, config, logger) {
2679
+ const removed = config.removeAlias(aliasPath);
2680
+ if (removed && logger) {
2681
+ logger.log("yellow", `Static alias removed: ${aliasPath}`);
2682
+ }
2683
+ return removed;
2684
+ }
2685
+ /**
2686
+ * Get all configured aliases from config
2687
+ * @param config - Static config instance
2688
+ */
2689
+ getAliases(config) {
2690
+ return config.getAliases();
2691
+ }
2692
+ /**
2693
+ * Enable or disable an alias
2694
+ * @param aliasPath - The path of the alias
2695
+ * @param enabled - Whether to enable or disable
2696
+ * @param config - Static config instance
2697
+ * @param logger - Logger instance for logging
2698
+ */
2699
+ setAliasEnabled(aliasPath, enabled, config, logger) {
2700
+ const result = config.setAliasEnabled(aliasPath, enabled);
2701
+ if (result && logger) {
2702
+ logger.log("blue", `Static alias ${enabled ? "enabled" : "disabled"}: ${aliasPath}`);
2703
+ }
2704
+ return result;
2705
+ }
2706
+ getMimeType(ext) {
2707
+ const mimeTypes = {
2708
+ // Text
2709
+ ".html": "text/html",
2710
+ ".htm": "text/html",
2711
+ ".css": "text/css",
2712
+ ".txt": "text/plain",
2713
+ ".md": "text/markdown",
2714
+ ".xml": "application/xml",
2715
+ // JavaScript
2716
+ ".js": "application/javascript",
2717
+ ".mjs": "application/javascript",
2718
+ ".jsx": "application/javascript",
2719
+ ".ts": "application/typescript",
2720
+ ".tsx": "application/typescript",
2721
+ // JSON
2722
+ ".json": "application/json",
2723
+ ".jsonld": "application/ld+json",
2724
+ // Images
2725
+ ".png": "image/png",
2726
+ ".jpg": "image/jpeg",
2727
+ ".jpeg": "image/jpeg",
2728
+ ".gif": "image/gif",
2729
+ ".svg": "image/svg+xml",
2730
+ ".ico": "image/x-icon",
2731
+ ".webp": "image/webp",
2732
+ ".bmp": "image/bmp",
2733
+ ".tiff": "image/tiff",
2734
+ // Fonts
2735
+ ".woff": "font/woff",
2736
+ ".woff2": "font/woff2",
2737
+ ".ttf": "font/ttf",
2738
+ ".otf": "font/otf",
2739
+ ".eot": "application/vnd.ms-fontobject",
2740
+ // Audio/Video
2741
+ ".mp3": "audio/mpeg",
2742
+ ".wav": "audio/wav",
2743
+ ".mp4": "video/mp4",
2744
+ ".webm": "video/webm",
2745
+ ".ogg": "application/ogg",
2746
+ // Archives
2747
+ ".zip": "application/zip",
2748
+ ".tar": "application/x-tar",
2749
+ ".gz": "application/gzip",
2750
+ // Documents
2751
+ ".pdf": "application/pdf",
2752
+ ".doc": "application/msword",
2753
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
2754
+ ".xls": "application/vnd.ms-excel",
2755
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2756
+ };
2757
+ return mimeTypes[ext.toLowerCase()] || "application/octet-stream";
2758
+ }
2759
+ safeFilePath(staticDir, reqUrl, host = "localhost", pathPolyfill, fsPolyfill) {
2760
+ const parsedUrl = new URL(reqUrl || "/", `http://${host}`);
2761
+ let pathname = decodeURIComponent(parsedUrl.pathname);
2762
+ pathname = pathname.replace(/\.\.[\/\\]/g, "");
2763
+ let filePath = pathPolyfill.join(staticDir, pathname);
2764
+ if (!fsPolyfill.existsSync(filePath)) {
2765
+ throw new Error(`File not found: ${filePath}`);
2766
+ }
2767
+ return filePath;
2768
+ }
2769
+ serveFile(filePath, res, logger, fsPolyfill, pathPolyfill) {
2770
+ return new Promise((resolve, reject) => {
2771
+ try {
2772
+ if (fsPolyfill.existsSync(filePath)) {
2773
+ const ext = pathPolyfill.extname(filePath);
2774
+ const contentType = this.getMimeType(ext);
2775
+ const headers = {
2776
+ "Content-Type": contentType,
2777
+ "Cache-Control": this.getCacheControl(ext),
2778
+ "X-Content-Type-Options": "nosniff"
2779
+ };
2780
+ res.writeHead(200, headers);
2781
+ const stream = fsPolyfill.createReadStream(filePath);
2782
+ if (stream && res.original) {
2783
+ stream.pipe(res.original);
2784
+ stream.on("end", () => {
2785
+ resolve();
2786
+ });
2787
+ stream.on("error", (err) => {
2788
+ reject(new A_HttpServerError({
2789
+ status: 500,
2790
+ title: "File Stream Error",
2791
+ description: `Error reading file stream for ${filePath}: ${err.message}`,
2792
+ originalError: err
2793
+ }));
2794
+ });
2795
+ } else {
2796
+ reject(new A_HttpServerError({
2797
+ status: 500,
2798
+ title: "Response Stream Error",
2799
+ description: `Unable to pipe file stream for ${filePath}`
2800
+ }));
2801
+ }
2802
+ } else {
2803
+ reject(new A_HttpServerError({
2804
+ status: 404,
2805
+ title: "File Not Found",
2806
+ description: `File not found: ${filePath}`
2807
+ }));
2808
+ }
2809
+ } catch (error) {
2810
+ logger.error(`Error serving file: ${error.message}`);
2811
+ reject(new A_HttpServerError({
2812
+ status: 500,
2813
+ title: "Internal Server Error",
2814
+ description: `Error serving file: ${error.message}`,
2815
+ originalError: error
2816
+ }));
2817
+ }
2818
+ });
2819
+ }
2820
+ getCacheControl(ext) {
2821
+ const staticAssets = [".css", ".js", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".otf"];
2822
+ const dynamicContent = [".html", ".htm"];
2823
+ if (staticAssets.includes(ext.toLowerCase())) {
2824
+ return "public, max-age=31536000";
2825
+ } else if (dynamicContent.includes(ext.toLowerCase())) {
2826
+ return "public, max-age=3600";
2827
+ } else {
2828
+ return "public, max-age=86400";
2829
+ }
2830
+ }
2831
+ };
2832
+ __decorateClass([
2833
+ A_Concept.Load(),
2834
+ __decorateParam(0, A_Inject(A_Logger)),
2835
+ __decorateParam(1, A_Inject(A_StaticConfig)),
2836
+ __decorateParam(2, A_Inject(A_Polyfill))
2837
+ ], A_StaticLoader.prototype, "load", 1);
2838
+ __decorateClass([
2839
+ A_Feature.Extend({
2840
+ before: /.*/
2841
+ }),
2842
+ __decorateParam(0, A_Inject(A_Request)),
2843
+ __decorateParam(1, A_Inject(A_Response)),
2844
+ __decorateParam(2, A_Inject(A_Logger)),
2845
+ __decorateParam(3, A_Inject(A_StaticConfig)),
2846
+ __decorateParam(4, A_Inject(A_Polyfill))
2847
+ ], A_StaticLoader.prototype, _a4, 1);
2848
+
2849
+ // src/constants/env.constants.ts
2850
+ var A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES = {
2851
+ // ----------------------------------------------------------
2852
+ // A-Server Environment Variables
2853
+ // ----------------------------------------------------------
2854
+ // These environment variables are used by A-Server to configure the application
2855
+ // ----------------------------------------------------------
2856
+ /**
2857
+ * Port for the server to listen on
2858
+ * [!] Default is 3000
2859
+ * @default 3000
2860
+ */
2861
+ A_SERVER_PORT: "A_SERVER_PORT"
2862
+ };
2863
+ var A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY = [
2864
+ A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES.A_SERVER_PORT
2865
+ ];
2866
+
2867
+ export { A_HttpRequestData, A_HttpServer, A_HttpServerError, A_HttpServerFeatures, A_HttpServerRequestContext, A_ProxyConfig, A_Request, A_RequestEnvVariables, A_RequestEnvVariablesArray, A_RequestError, A_RequestFeatures, A_RequestHelper, A_Request_Event, A_Response, A_ResponseError, A_ResponseFeatures, A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES, A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_SERVER_TYPES__A_EntityListEvent, A_SERVER__A_SERVER_LOGGER_ENV_VARIABLES, A_Server, A_ServerController, A_ServerEntityList, A_ServerError, A_ServerListQueryFilter, A_ServerLogger, A_ServerMiddleware, A_ServerProxy, A_ServerRoute, A_ServerRouteHttpMethods, A_ServerRouteProtocols, A_ServerRouter, A_ServerRouterDefineDecorator, A_ServerRouterMeta, A_ServerRouterMetaKeys, A_StaticConfig, A_StaticLoader, PROXY_CONFIG_DEFAULTS };
2868
+ //# sourceMappingURL=index.mjs.map
2869
+ //# sourceMappingURL=index.mjs.map