jimpex 7.0.1 → 8.0.0

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 (388) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +1 -1
  3. package/README.md +446 -434
  4. package/dist/app/index.d.ts +13 -0
  5. package/dist/app/index.js +19 -0
  6. package/dist/app/index.js.map +1 -0
  7. package/dist/app/jimpex.d.ts +13 -0
  8. package/dist/app/jimpex.js +440 -0
  9. package/dist/app/jimpex.js.map +1 -0
  10. package/dist/controllers/common/config.d.ts +78 -0
  11. package/dist/controllers/common/config.js +89 -0
  12. package/dist/controllers/common/config.js.map +1 -0
  13. package/dist/controllers/common/health.d.ts +82 -0
  14. package/dist/controllers/common/health.js +97 -0
  15. package/dist/controllers/common/health.js.map +1 -0
  16. package/dist/controllers/common/index.d.ts +21 -0
  17. package/dist/controllers/common/index.js +21 -0
  18. package/dist/controllers/common/index.js.map +1 -0
  19. package/dist/controllers/common/statics.d.ts +215 -0
  20. package/dist/controllers/common/statics.js +202 -0
  21. package/dist/controllers/common/statics.js.map +1 -0
  22. package/dist/controllers/index.d.ts +24 -0
  23. package/dist/controllers/index.js +20 -0
  24. package/dist/controllers/index.js.map +1 -0
  25. package/dist/controllers/utils/gateway.d.ts +724 -0
  26. package/dist/controllers/utils/gateway.js +425 -0
  27. package/dist/controllers/utils/gateway.js.map +1 -0
  28. package/dist/controllers/utils/index.d.ts +16 -0
  29. package/dist/controllers/utils/index.js +19 -0
  30. package/dist/controllers/utils/index.js.map +1 -0
  31. package/dist/esm/app/index.js +2 -0
  32. package/dist/esm/app/index.js.map +1 -0
  33. package/dist/esm/app/jimpex.js +415 -0
  34. package/dist/esm/app/jimpex.js.map +1 -0
  35. package/dist/esm/chunk-T2T6Q22Z.js +11 -0
  36. package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
  37. package/dist/esm/controllers/common/config.js +62 -0
  38. package/dist/esm/controllers/common/config.js.map +1 -0
  39. package/dist/esm/controllers/common/health.js +70 -0
  40. package/dist/esm/controllers/common/health.js.map +1 -0
  41. package/dist/esm/controllers/common/index.js +4 -0
  42. package/dist/esm/controllers/common/index.js.map +1 -0
  43. package/dist/esm/controllers/common/statics.js +173 -0
  44. package/dist/esm/controllers/common/statics.js.map +1 -0
  45. package/dist/esm/controllers/index.js +3 -0
  46. package/dist/esm/controllers/index.js.map +1 -0
  47. package/dist/esm/controllers/utils/gateway.js +404 -0
  48. package/dist/esm/controllers/utils/gateway.js.map +1 -0
  49. package/dist/esm/controllers/utils/index.js +2 -0
  50. package/dist/esm/controllers/utils/index.js.map +1 -0
  51. package/dist/esm/index.js +7 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/middlewares/common/errorHandler.js +92 -0
  54. package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
  55. package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
  56. package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
  57. package/dist/esm/middlewares/common/hsts.js +53 -0
  58. package/dist/esm/middlewares/common/hsts.js.map +1 -0
  59. package/dist/esm/middlewares/common/index.js +4 -0
  60. package/dist/esm/middlewares/common/index.js.map +1 -0
  61. package/dist/esm/middlewares/html/fastHTML.js +104 -0
  62. package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
  63. package/dist/esm/middlewares/html/index.js +3 -0
  64. package/dist/esm/middlewares/html/index.js.map +1 -0
  65. package/dist/esm/middlewares/html/showHTML.js +68 -0
  66. package/dist/esm/middlewares/html/showHTML.js.map +1 -0
  67. package/dist/esm/middlewares/index.js +4 -0
  68. package/dist/esm/middlewares/index.js.map +1 -0
  69. package/dist/esm/middlewares/utils/index.js +2 -0
  70. package/dist/esm/middlewares/utils/index.js.map +1 -0
  71. package/dist/esm/middlewares/utils/versionValidator.js +101 -0
  72. package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
  73. package/dist/esm/services/common/appError.js +52 -0
  74. package/dist/esm/services/common/appError.js.map +1 -0
  75. package/dist/esm/services/common/httpError.js +19 -0
  76. package/dist/esm/services/common/httpError.js.map +1 -0
  77. package/dist/esm/services/common/index.js +17 -0
  78. package/dist/esm/services/common/index.js.map +1 -0
  79. package/dist/esm/services/common/sendFile.js +27 -0
  80. package/dist/esm/services/common/sendFile.js.map +1 -0
  81. package/dist/esm/services/frontend/frontendFs.js +38 -0
  82. package/dist/esm/services/frontend/frontendFs.js.map +1 -0
  83. package/dist/esm/services/frontend/index.js +11 -0
  84. package/dist/esm/services/frontend/index.js.map +1 -0
  85. package/dist/esm/services/html/htmlGenerator.js +144 -0
  86. package/dist/esm/services/html/htmlGenerator.js.map +1 -0
  87. package/dist/esm/services/html/index.js +11 -0
  88. package/dist/esm/services/html/index.js.map +1 -0
  89. package/dist/esm/services/http/apiClient.js +71 -0
  90. package/dist/esm/services/http/apiClient.js.map +1 -0
  91. package/dist/esm/services/http/http.js +125 -0
  92. package/dist/esm/services/http/http.js.map +1 -0
  93. package/dist/esm/services/http/index.js +17 -0
  94. package/dist/esm/services/http/index.js.map +1 -0
  95. package/dist/esm/services/http/responsesBuilder.js +105 -0
  96. package/dist/esm/services/http/responsesBuilder.js.map +1 -0
  97. package/dist/esm/services/index.js +6 -0
  98. package/dist/esm/services/index.js.map +1 -0
  99. package/dist/esm/services/utils/ensureBearerToken.js +78 -0
  100. package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
  101. package/dist/esm/services/utils/index.js +11 -0
  102. package/dist/esm/services/utils/index.js.map +1 -0
  103. package/dist/esm/types/events.js +1 -0
  104. package/dist/esm/types/events.js.map +1 -0
  105. package/dist/esm/types/express.js +1 -0
  106. package/dist/esm/types/express.js.map +1 -0
  107. package/dist/esm/types/http.js +1 -0
  108. package/dist/esm/types/http.js.map +1 -0
  109. package/dist/esm/types/index.js +7 -0
  110. package/dist/esm/types/index.js.map +1 -0
  111. package/dist/esm/types/options.js +1 -0
  112. package/dist/esm/types/options.js.map +1 -0
  113. package/dist/esm/types/utils.js +1 -0
  114. package/dist/esm/types/utils.js.map +1 -0
  115. package/dist/esm/types/wootils.js +1 -0
  116. package/dist/esm/types/wootils.js.map +1 -0
  117. package/dist/esm/utils/fns/index.js +5 -0
  118. package/dist/esm/utils/fns/index.js.map +1 -0
  119. package/dist/esm/utils/fns/others.js +6 -0
  120. package/dist/esm/utils/fns/others.js.map +1 -0
  121. package/dist/esm/utils/fns/routes.js +25 -0
  122. package/dist/esm/utils/fns/routes.js.map +1 -0
  123. package/dist/esm/utils/fns/statuses.js +6 -0
  124. package/dist/esm/utils/fns/statuses.js.map +1 -0
  125. package/dist/esm/utils/fns/text.js +6 -0
  126. package/dist/esm/utils/fns/text.js.map +1 -0
  127. package/dist/esm/utils/index.js +3 -0
  128. package/dist/esm/utils/index.js.map +1 -0
  129. package/dist/esm/utils/wrappers.js +41 -0
  130. package/dist/esm/utils/wrappers.js.map +1 -0
  131. package/dist/index.d.ts +46 -0
  132. package/dist/index.js +24 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/jimpex-7eaee271.d.ts +1278 -0
  135. package/dist/middlewares/common/errorHandler.d.ts +131 -0
  136. package/dist/middlewares/common/errorHandler.js +119 -0
  137. package/dist/middlewares/common/errorHandler.js.map +1 -0
  138. package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
  139. package/dist/middlewares/common/forceHTTPS.js +68 -0
  140. package/dist/middlewares/common/forceHTTPS.js.map +1 -0
  141. package/dist/middlewares/common/hsts.d.ts +109 -0
  142. package/dist/middlewares/common/hsts.js +80 -0
  143. package/dist/middlewares/common/hsts.js.map +1 -0
  144. package/dist/middlewares/common/index.d.ts +21 -0
  145. package/dist/middlewares/common/index.js +21 -0
  146. package/dist/middlewares/common/index.js.map +1 -0
  147. package/dist/middlewares/html/fastHTML.d.ts +180 -0
  148. package/dist/middlewares/html/fastHTML.js +131 -0
  149. package/dist/middlewares/html/fastHTML.js.map +1 -0
  150. package/dist/middlewares/html/index.d.ts +21 -0
  151. package/dist/middlewares/html/index.js +20 -0
  152. package/dist/middlewares/html/index.js.map +1 -0
  153. package/dist/middlewares/html/showHTML.d.ts +127 -0
  154. package/dist/middlewares/html/showHTML.js +95 -0
  155. package/dist/middlewares/html/showHTML.js.map +1 -0
  156. package/dist/middlewares/index.d.ts +30 -0
  157. package/dist/middlewares/index.js +21 -0
  158. package/dist/middlewares/index.js.map +1 -0
  159. package/dist/middlewares/utils/index.d.ts +19 -0
  160. package/dist/middlewares/utils/index.js +19 -0
  161. package/dist/middlewares/utils/index.js.map +1 -0
  162. package/dist/middlewares/utils/versionValidator.d.ts +214 -0
  163. package/dist/middlewares/utils/versionValidator.js +128 -0
  164. package/dist/middlewares/utils/versionValidator.js.map +1 -0
  165. package/dist/services/common/appError.d.ts +138 -0
  166. package/dist/services/common/appError.js +80 -0
  167. package/dist/services/common/appError.js.map +1 -0
  168. package/dist/services/common/httpError.d.ts +79 -0
  169. package/dist/services/common/httpError.js +44 -0
  170. package/dist/services/common/httpError.js.map +1 -0
  171. package/dist/services/common/index.d.ts +47 -0
  172. package/dist/services/common/index.js +41 -0
  173. package/dist/services/common/index.js.map +1 -0
  174. package/dist/services/common/sendFile.d.ts +102 -0
  175. package/dist/services/common/sendFile.js +51 -0
  176. package/dist/services/common/sendFile.js.map +1 -0
  177. package/dist/services/frontend/frontendFs.d.ts +96 -0
  178. package/dist/services/frontend/frontendFs.js +71 -0
  179. package/dist/services/frontend/frontendFs.js.map +1 -0
  180. package/dist/services/frontend/index.d.ts +40 -0
  181. package/dist/services/frontend/index.js +35 -0
  182. package/dist/services/frontend/index.js.map +1 -0
  183. package/dist/services/html/htmlGenerator.d.ts +237 -0
  184. package/dist/services/html/htmlGenerator.js +171 -0
  185. package/dist/services/html/htmlGenerator.js.map +1 -0
  186. package/dist/services/html/index.d.ts +43 -0
  187. package/dist/services/html/index.js +35 -0
  188. package/dist/services/html/index.js.map +1 -0
  189. package/dist/services/http/apiClient.d.ts +169 -0
  190. package/dist/services/http/apiClient.js +96 -0
  191. package/dist/services/http/apiClient.js.map +1 -0
  192. package/dist/services/http/http.d.ts +175 -0
  193. package/dist/services/http/http.js +158 -0
  194. package/dist/services/http/http.js.map +1 -0
  195. package/dist/services/http/index.d.ts +50 -0
  196. package/dist/services/http/index.js +41 -0
  197. package/dist/services/http/index.js.map +1 -0
  198. package/dist/services/http/responsesBuilder.d.ts +178 -0
  199. package/dist/services/http/responsesBuilder.js +132 -0
  200. package/dist/services/http/responsesBuilder.js.map +1 -0
  201. package/dist/services/index.d.ts +33 -0
  202. package/dist/services/index.js +23 -0
  203. package/dist/services/index.js.map +1 -0
  204. package/dist/services/utils/ensureBearerToken.d.ts +157 -0
  205. package/dist/services/utils/ensureBearerToken.js +105 -0
  206. package/dist/services/utils/ensureBearerToken.js.map +1 -0
  207. package/dist/services/utils/index.d.ts +43 -0
  208. package/dist/services/utils/index.js +35 -0
  209. package/dist/services/utils/index.js.map +1 -0
  210. package/dist/types/events.d.ts +13 -0
  211. package/dist/types/events.js +17 -0
  212. package/dist/types/events.js.map +1 -0
  213. package/dist/types/express.d.ts +10 -0
  214. package/dist/types/express.js +17 -0
  215. package/dist/types/express.js.map +1 -0
  216. package/dist/types/http.d.ts +79 -0
  217. package/dist/types/http.js +17 -0
  218. package/dist/types/http.js.map +1 -0
  219. package/dist/types/index.d.ts +14 -0
  220. package/dist/types/index.js +24 -0
  221. package/dist/types/index.js.map +1 -0
  222. package/dist/types/options.d.ts +13 -0
  223. package/dist/types/options.js +17 -0
  224. package/dist/types/options.js.map +1 -0
  225. package/dist/types/utils.d.ts +48 -0
  226. package/dist/types/utils.js +17 -0
  227. package/dist/types/utils.js.map +1 -0
  228. package/dist/types/wootils.d.ts +4 -0
  229. package/dist/types/wootils.js +17 -0
  230. package/dist/types/wootils.js.map +1 -0
  231. package/dist/utils/fns/index.d.ts +5 -0
  232. package/dist/utils/fns/index.js +22 -0
  233. package/dist/utils/fns/index.js.map +1 -0
  234. package/dist/utils/fns/others.d.ts +17 -0
  235. package/dist/utils/fns/others.js +29 -0
  236. package/dist/utils/fns/others.js.map +1 -0
  237. package/dist/utils/fns/routes.d.ts +39 -0
  238. package/dist/utils/fns/routes.js +51 -0
  239. package/dist/utils/fns/routes.js.map +1 -0
  240. package/dist/utils/fns/statuses.d.ts +45 -0
  241. package/dist/utils/fns/statuses.js +35 -0
  242. package/dist/utils/fns/statuses.js.map +1 -0
  243. package/dist/utils/fns/text.d.ts +9 -0
  244. package/dist/utils/fns/text.js +29 -0
  245. package/dist/utils/fns/text.js.map +1 -0
  246. package/dist/utils/index.d.ts +18 -0
  247. package/dist/utils/index.js +20 -0
  248. package/dist/utils/index.js.map +1 -0
  249. package/dist/utils/wrappers.d.ts +13 -0
  250. package/dist/utils/wrappers.js +68 -0
  251. package/dist/utils/wrappers.js.map +1 -0
  252. package/examples/basic/404.html +12 -0
  253. package/examples/basic/README.md +30 -0
  254. package/examples/basic/app.ts +18 -0
  255. package/examples/basic/controller.ts +45 -0
  256. package/examples/basic/index.ts +19 -0
  257. package/examples/basic/middleware.ts +13 -0
  258. package/examples/basic/service.ts +11 -0
  259. package/package.json +59 -38
  260. package/src/app/index.ts +1 -0
  261. package/src/app/jimpex.ts +743 -0
  262. package/src/controllers/common/config.ts +115 -0
  263. package/src/controllers/common/health.ts +128 -0
  264. package/src/controllers/common/index.ts +3 -0
  265. package/src/controllers/common/statics.ts +380 -0
  266. package/src/controllers/index.ts +2 -0
  267. package/src/controllers/utils/gateway.ts +1186 -0
  268. package/src/controllers/utils/index.ts +1 -0
  269. package/src/index.ts +6 -0
  270. package/src/middlewares/common/errorHandler.ts +203 -0
  271. package/src/middlewares/common/forceHTTPS.ts +83 -0
  272. package/src/middlewares/common/hsts.ts +135 -0
  273. package/src/middlewares/common/index.ts +3 -0
  274. package/src/middlewares/html/fastHTML.ts +255 -0
  275. package/src/middlewares/html/index.ts +2 -0
  276. package/src/middlewares/html/showHTML.ts +165 -0
  277. package/src/middlewares/index.ts +3 -0
  278. package/src/middlewares/utils/index.ts +1 -0
  279. package/src/middlewares/utils/versionValidator.ts +289 -0
  280. package/src/services/common/appError.ts +158 -0
  281. package/src/services/common/httpError.ts +74 -0
  282. package/src/services/common/index.ts +29 -0
  283. package/src/services/common/sendFile.ts +106 -0
  284. package/src/services/frontend/frontendFs.ts +101 -0
  285. package/src/services/frontend/index.ts +21 -0
  286. package/src/services/html/htmlGenerator.ts +356 -0
  287. package/src/services/html/index.ts +21 -0
  288. package/src/services/http/apiClient.ts +221 -0
  289. package/src/services/http/http.ts +286 -0
  290. package/src/services/http/index.ts +29 -0
  291. package/src/services/http/responsesBuilder.ts +265 -0
  292. package/src/services/index.ts +5 -0
  293. package/src/services/utils/ensureBearerToken.ts +202 -0
  294. package/src/services/utils/index.ts +21 -0
  295. package/src/types/events.ts +303 -0
  296. package/src/types/express.ts +21 -0
  297. package/src/types/http.ts +77 -0
  298. package/src/types/index.ts +6 -0
  299. package/src/types/options.ts +248 -0
  300. package/src/types/utils.ts +52 -0
  301. package/src/types/wootils.ts +4 -0
  302. package/src/utils/fns/index.ts +4 -0
  303. package/src/utils/fns/others.ts +15 -0
  304. package/src/utils/fns/routes.ts +64 -0
  305. package/src/utils/fns/statuses.ts +44 -0
  306. package/src/utils/fns/text.ts +8 -0
  307. package/src/utils/index.ts +2 -0
  308. package/src/utils/wrappers.ts +537 -0
  309. package/tsconfig.json +5 -8
  310. package/tsup.config.ts +10 -0
  311. package/src/app/index.js +0 -692
  312. package/src/constants/eventNames.js +0 -48
  313. package/src/constants/index.js +0 -7
  314. package/src/controllers/common/configuration.js +0 -116
  315. package/src/controllers/common/health.js +0 -79
  316. package/src/controllers/common/index.js +0 -7
  317. package/src/controllers/common/statics.js +0 -336
  318. package/src/controllers/index.js +0 -9
  319. package/src/controllers/utils/gateway.js +0 -1039
  320. package/src/controllers/utils/index.js +0 -3
  321. package/src/index.js +0 -30
  322. package/src/middlewares/common/errorHandler.js +0 -185
  323. package/src/middlewares/common/forceHTTPS.js +0 -80
  324. package/src/middlewares/common/hsts.js +0 -122
  325. package/src/middlewares/common/index.js +0 -7
  326. package/src/middlewares/html/fastHTML.js +0 -298
  327. package/src/middlewares/html/index.js +0 -5
  328. package/src/middlewares/html/showHTML.js +0 -167
  329. package/src/middlewares/index.js +0 -11
  330. package/src/middlewares/utils/index.js +0 -3
  331. package/src/middlewares/utils/versionValidator.js +0 -261
  332. package/src/services/common/appError.js +0 -136
  333. package/src/services/common/httpError.js +0 -60
  334. package/src/services/common/index.js +0 -25
  335. package/src/services/common/sendFile.js +0 -68
  336. package/src/services/frontend/frontendFs.js +0 -85
  337. package/src/services/frontend/index.js +0 -17
  338. package/src/services/html/htmlGenerator.js +0 -391
  339. package/src/services/html/index.js +0 -17
  340. package/src/services/http/apiClient.js +0 -148
  341. package/src/services/http/http.js +0 -256
  342. package/src/services/http/index.js +0 -25
  343. package/src/services/http/responsesBuilder.js +0 -193
  344. package/src/services/index.js +0 -15
  345. package/src/services/utils/ensureBearerToken.js +0 -147
  346. package/src/services/utils/index.js +0 -19
  347. package/src/types.js +0 -377
  348. package/src/utils/functions.js +0 -78
  349. package/src/utils/wrappers.js +0 -131
  350. package/types/app/index.d.ts +0 -417
  351. package/types/constants/eventNames.d.ts +0 -93
  352. package/types/constants/index.d.ts +0 -2
  353. package/types/controllers/common/configuration.d.ts +0 -71
  354. package/types/controllers/common/health.d.ts +0 -55
  355. package/types/controllers/common/index.d.ts +0 -4
  356. package/types/controllers/common/statics.d.ts +0 -271
  357. package/types/controllers/index.d.ts +0 -3
  358. package/types/controllers/utils/gateway.d.ts +0 -947
  359. package/types/controllers/utils/index.d.ts +0 -2
  360. package/types/index.d.ts +0 -15
  361. package/types/middlewares/common/errorHandler.d.ts +0 -143
  362. package/types/middlewares/common/forceHTTPS.d.ts +0 -64
  363. package/types/middlewares/common/hsts.d.ts +0 -111
  364. package/types/middlewares/common/index.d.ts +0 -4
  365. package/types/middlewares/html/fastHTML.d.ts +0 -238
  366. package/types/middlewares/html/index.d.ts +0 -3
  367. package/types/middlewares/html/showHTML.d.ts +0 -128
  368. package/types/middlewares/index.d.ts +0 -4
  369. package/types/middlewares/utils/index.d.ts +0 -2
  370. package/types/middlewares/utils/versionValidator.d.ts +0 -247
  371. package/types/services/common/appError.d.ts +0 -89
  372. package/types/services/common/httpError.d.ts +0 -37
  373. package/types/services/common/index.d.ts +0 -18
  374. package/types/services/common/sendFile.d.ts +0 -56
  375. package/types/services/frontend/frontendFs.d.ts +0 -72
  376. package/types/services/frontend/index.d.ts +0 -3
  377. package/types/services/html/htmlGenerator.d.ts +0 -298
  378. package/types/services/html/index.d.ts +0 -3
  379. package/types/services/http/apiClient.d.ts +0 -141
  380. package/types/services/http/http.d.ts +0 -159
  381. package/types/services/http/index.d.ts +0 -18
  382. package/types/services/http/responsesBuilder.d.ts +0 -140
  383. package/types/services/index.d.ts +0 -6
  384. package/types/services/utils/ensureBearerToken.d.ts +0 -137
  385. package/types/services/utils/index.d.ts +0 -16
  386. package/types/types.d.ts +0 -280
  387. package/types/utils/functions.d.ts +0 -55
  388. package/types/utils/wrappers.d.ts +0 -127
@@ -0,0 +1,303 @@
1
+ import type { Router, ExpressMiddlewareLike } from './express';
2
+ import type { Controller, Middleware } from '../utils';
3
+ import type { Jimpex } from '../app/jimpex';
4
+ /**
5
+ * The base payload the events emitted by the application send.
6
+ *
7
+ * @template T Extra properties beside the reference to the application.
8
+ * @group Services/Events
9
+ */
10
+ export type EventPayload<T = Record<string, unknown>> = {
11
+ /**
12
+ * A reference to the application.
13
+ */
14
+ app: Jimpex;
15
+ } & T;
16
+ /**
17
+ * A dictionary with the events emitted by the application and their payloads.
18
+ *
19
+ * @group Services/Events
20
+ */
21
+ export interface JimpexEvents {
22
+ /**
23
+ * Called right before creating the server and calling `listen` on it.
24
+ */
25
+ beforeStart: EventPayload;
26
+ /**
27
+ * Called once the server confirmed that is listening.
28
+ */
29
+ start: EventPayload;
30
+ /**
31
+ * Called after the controllers and middlewares have been mounted.
32
+ */
33
+ afterStart: EventPayload;
34
+ /**
35
+ * Called after the `onStart` callback has been called.
36
+ */
37
+ afterStartCallback: EventPayload;
38
+ /**
39
+ * Called before closing the server instance.
40
+ */
41
+ beforeStop: EventPayload;
42
+ /**
43
+ * Called after the server instance has been closed.
44
+ */
45
+ afterStop: EventPayload;
46
+ /**
47
+ * Called every time a new route is mounted in the application.
48
+ */
49
+ routeAdded: EventPayload<{ route: string }>;
50
+ }
51
+ /**
52
+ * The events emitted by the application.
53
+ *
54
+ * @group Services/Events
55
+ */
56
+ export type JimpexEventName = keyof JimpexEvents;
57
+ /**
58
+ * The type of the payload sent by a specific event.
59
+ *
60
+ * @template EventName The literal type of the event, to obtain the type of the
61
+ * payload.
62
+ * @group Services/Events
63
+ */
64
+ export type JimpexEventPayload<EventName extends JimpexEventName> =
65
+ JimpexEvents[EventName];
66
+ /**
67
+ * A dictionary of the reducer events and their targets.
68
+ *
69
+ * @group Services/Events
70
+ */
71
+ export interface JimpexReducerEventTargets {
72
+ /**
73
+ * It gets called before mounting a router/middleware for a specific route.
74
+ */
75
+ controllerWillBeMounted: Router | ExpressMiddlewareLike;
76
+ /**
77
+ * It gets called before using a middleware without route.
78
+ */
79
+ middlewareWillBeUsed: ExpressMiddlewareLike;
80
+ }
81
+ /**
82
+ * A dictionary of the payloads the reducer events the application uses.
83
+ *
84
+ * @group Services/Events
85
+ */
86
+ export interface JimpexReducerEventPayloads {
87
+ /**
88
+ * It gets called before mounting a router/middleware for a specific route.
89
+ */
90
+ controllerWillBeMounted: EventPayload<{
91
+ /**
92
+ * The route in which the controller will be mounted.
93
+ */
94
+ route: string;
95
+ /**
96
+ * A reference for the controller/middleware before being "connected".
97
+ */
98
+ controller: Controller | Middleware;
99
+ }>;
100
+ /**
101
+ * It gets called before using a middleware without route.
102
+ */
103
+ middlewareWillBeUsed: EventPayload;
104
+ }
105
+ /**
106
+ * The reducer events used by the application.
107
+ *
108
+ * @group Services/Events
109
+ */
110
+ export type JimpexReducerEventName = keyof JimpexReducerEventTargets;
111
+ /**
112
+ * The type of the target of a specific reducer event.
113
+ *
114
+ * @template EventName The literal type of the event, to obtain the type of the
115
+ * target.
116
+ * @group Services/Events
117
+ */
118
+ export type JimpexReducerEventTarget<EventName extends JimpexReducerEventName> =
119
+ JimpexReducerEventTargets[EventName];
120
+ /**
121
+ * The type of the payload of a specific reducer event.
122
+ *
123
+ * @template EventName The literal type of the event, to obtain the type of the
124
+ * payload.
125
+ * @group Services/Events
126
+ */
127
+ export type JimpexReducerEventPayload<EventName extends JimpexReducerEventName> =
128
+ JimpexReducerEventPayloads[EventName];
129
+ /**
130
+ * The name of the events o reducer events emitted/used by the application.
131
+ * This generic type exists because the listener for both types are added using the same
132
+ * method.
133
+ *
134
+ * @group Services/Events
135
+ */
136
+ export type JimpexEventNameLike = JimpexEventName | JimpexReducerEventName;
137
+ /**
138
+ * The definition of a listener for an event or a reducer event.
139
+ *
140
+ * @template EventName The literal type of the event, to validate whether the
141
+ * parameters should be for a reducer event or an event.
142
+ * @group Services/Events
143
+ */
144
+ export type JimpexEventListener<EventName extends JimpexEventNameLike> =
145
+ EventName extends JimpexEventName
146
+ ? (payload: JimpexEventPayload<EventName>) => void
147
+ : EventName extends JimpexReducerEventName
148
+ ? (
149
+ target: JimpexReducerEventTarget<EventName>,
150
+ payload: JimpexReducerEventPayload<EventName>,
151
+ ) => JimpexReducerEventTarget<EventName>
152
+ : never;
153
+ /**
154
+ * The `events` service Jimpex uses.
155
+ * This is an alternative declaration of the `EventsHub` class that uses the interfaces
156
+ * and types from this project.
157
+ *
158
+ * @group Services
159
+ * @group Services/Events
160
+ */
161
+ export type Events = {
162
+ /**
163
+ * Adds a new event listener.
164
+ *
165
+ * @param event The name of the event.
166
+ * @param listener The listener function.
167
+ * @returns An unsubscribe function to remove the listener.
168
+ * @template EventName The literal type of the event, to generate the type of the
169
+ * listener.
170
+ * @example
171
+ *
172
+ * const unsubscribe = events.on('afterStart', ({ app }) => {
173
+ * app.getLogger().info('Hello world!');
174
+ * unsubscribe();
175
+ * });
176
+ *
177
+ */
178
+ on: <EventName extends JimpexEventNameLike>(
179
+ eventName: EventName,
180
+ listener: JimpexEventListener<EventName>,
181
+ ) => () => boolean;
182
+ /**
183
+ * Adds an event listener that will only be executed once.
184
+ *
185
+ * @param event The name of the event.
186
+ * @param listener The listener function.
187
+ * @returns An unsubscribe function to remove the listener.
188
+ * @template EventName The literal type of the event, to generate the type of the
189
+ * listener.
190
+ * @example
191
+ *
192
+ * events.once('afterStart', ({ app }) => {
193
+ * app.getLogger().info('Hello world!');
194
+ * unsubscribe();
195
+ * });
196
+ *
197
+ */
198
+ once: <EventName extends JimpexEventNameLike>(
199
+ eventName: EventName,
200
+ listener: JimpexEventListener<EventName>,
201
+ ) => () => boolean;
202
+ /**
203
+ * Emits an event and call all its listeners.
204
+ *
205
+ * @param event The name of the events.
206
+ * @param payload Context information for the event.
207
+ * @template EventName The literal type of the event, to generate the type of the
208
+ * payload.
209
+ * @example
210
+ *
211
+ * // Extend the interface to type the payload.
212
+ * interface JimpexEvents {
213
+ * myEvent: { message: string };
214
+ * }
215
+ * // Add the listener.
216
+ * events.on('myEvent', ({ message }) => {
217
+ * console.log('Event received:', message);
218
+ * });
219
+ * // Trigger the event.
220
+ * events.emit('myEvent', { message: 'Hello' });
221
+ * // prints "Event received: Hello"
222
+ *
223
+ */
224
+ emit: <EventName extends JimpexEventName>(
225
+ event: JimpexEventName,
226
+ payload: JimpexEventPayload<EventName>,
227
+ ) => void;
228
+ /**
229
+ * Asynchronously reduces a target using an event. It's like emit, but the event
230
+ * listeners return a modified (or not) version of the `target`.
231
+ *
232
+ * @param event The name of the event.
233
+ * @param target The variable to reduce with the reducers/listeners.
234
+ * @param payload Context information for the event.
235
+ * @returns A version of the `target` processed by the listeners.
236
+ * @template EventName The literal type of the event, to generate the types of the
237
+ * target and the payload.
238
+ * @example
239
+ *
240
+ * // Extend the interface to type the target.
241
+ * interface JimpexReducerEventTargets {
242
+ * myReducer: unknown[];
243
+ * }
244
+ * // Extend the interface to type the payload.
245
+ * interface JimpexReducerEventPayloads {
246
+ * myReducer: {
247
+ * message: string;
248
+ * };
249
+ * }
250
+ * // Add the reducer.
251
+ * events.on('myReducer', async (target, { message }) => {
252
+ * const data = await fetch('https://api.example.com/' + message);
253
+ * target.push(data);
254
+ * return target;
255
+ * });
256
+ * // Trigger the event.
257
+ * const result = await events.reduce('myReducer', [], { message: 'Hello' });
258
+ * // result would be a list of data fetched from the API.
259
+ *
260
+ */
261
+ reduce: <EventName extends JimpexReducerEventName>(
262
+ event: JimpexReducerEventName,
263
+ target: JimpexReducerEventTarget<EventName>,
264
+ payload: JimpexReducerEventPayload<EventName>,
265
+ ) => Promise<JimpexReducerEventTarget<EventName>>;
266
+ /**
267
+ * Synchronously reduces a target using an event. It's like emit, but the events
268
+ * listener return a modified (or not) version of the `target`.
269
+ *
270
+ * @param event The name of the event.
271
+ * @param target The variable to reduce with the reducers/listeners.
272
+ * @param payload Context information for the event.
273
+ * @returns A version of the `target` processed by the listeners.
274
+ * @template EventName The literal type of the event, to generate the types of the
275
+ * target and the payload.
276
+ * @example
277
+ *
278
+ * // Extend the interface to type the target.
279
+ * interface JimpexReducerEventTargets {
280
+ * myReducer: string[];
281
+ * }
282
+ * // Extend the interface to type the payload.
283
+ * interface JimpexReducerEventPayloads {
284
+ * myReducer: {
285
+ * message: string;
286
+ * };
287
+ * }
288
+ * // Add the reducer.
289
+ * events.on('myReducer', (target, { message }) => {
290
+ * target.push(message);
291
+ * return target;
292
+ * });
293
+ * // Trigger the event.
294
+ * events.reduce('event', [], 'Hello');
295
+ * // returns ['Hello']
296
+ *
297
+ */
298
+ reduceSync: <EventName extends JimpexReducerEventName>(
299
+ event: JimpexReducerEventName,
300
+ target: JimpexReducerEventTarget<EventName>,
301
+ payload: JimpexReducerEventPayload<EventName>,
302
+ ) => JimpexReducerEventTarget<EventName>;
303
+ };
@@ -0,0 +1,21 @@
1
+ import type { RequestHandler, ErrorRequestHandler } from 'express';
2
+
3
+ export type { Express, Router, Request, Response, NextFunction } from 'express';
4
+
5
+ export type ExpressMiddlewareLike = RequestHandler | ErrorRequestHandler;
6
+ export type ExpressMiddleware = RequestHandler;
7
+ export type AsyncExpressMiddleware = (
8
+ ...args: Parameters<ExpressMiddleware>
9
+ ) => Promise<void>;
10
+ export type ExpressErrorHandler = ErrorRequestHandler;
11
+ export type RouterMethod =
12
+ | 'all'
13
+ | 'get'
14
+ | 'head'
15
+ | 'post'
16
+ | 'patch'
17
+ | 'put'
18
+ | 'delete'
19
+ | 'connect'
20
+ | 'options'
21
+ | 'trace';
@@ -0,0 +1,77 @@
1
+ import type { Server as HTTPSServer } from 'https';
2
+ import type { Server as HTTPServer } from 'http';
3
+ import type { ServerOptions as SpdyServerOptions } from 'spdy';
4
+ import type { Express } from './express';
5
+
6
+ export type { Response as HTTPResponse } from 'node-fetch';
7
+
8
+ export type { HTTPSServer, HTTPServer };
9
+ /**
10
+ * @group Jimpex
11
+ */
12
+ export type JimpexServer = Express | HTTPSServer;
13
+ /**
14
+ * @group Jimpex
15
+ */
16
+ export type JimpexServerInstance = HTTPServer | HTTPSServer;
17
+ /**
18
+ * The paths to the SSL credentials. Depending on the application options, they can be
19
+ * relative to the project root, or the application executable, but they can't be
20
+ * absolute.
21
+ *
22
+ * @group Jimpex
23
+ */
24
+ export type JimpexHTTPSCredentials = {
25
+ /**
26
+ * The path to the certificate authority file.
27
+ */
28
+ ca?: string;
29
+ /**
30
+ * The path to the certificate file.
31
+ */
32
+ cert?: string;
33
+ /**
34
+ * The path to the key file.
35
+ */
36
+ key?: string;
37
+ };
38
+ /**
39
+ * The options to enable HTTP2.
40
+ *
41
+ * @group Jimpex
42
+ */
43
+ export type JimpexHTTP2Options = {
44
+ /**
45
+ * Whether or not to enable HTTP2.
46
+ */
47
+ enabled?: boolean;
48
+ /**
49
+ * Custom options for the Spdy server.
50
+ *
51
+ * @see {@link https://github.com/spdy-http2/node-spdy#options}
52
+ */
53
+ spdy?: SpdyServerOptions['spdy'];
54
+ };
55
+ /**
56
+ * The options to enable HTTPS.
57
+ *
58
+ * @group Jimpex
59
+ */
60
+ export type JimpexHTTPSOptions = {
61
+ /**
62
+ * Whether or not to enable HTTPS.
63
+ */
64
+ enabled?: boolean;
65
+ /**
66
+ * The SSL credentials, and their location.
67
+ */
68
+ credentials?: JimpexHTTPSCredentials & {
69
+ /**
70
+ * If `true`, the credentials will be located relative to the project root, otherwise,
71
+ * they will be located relative to the application executable.
72
+ *
73
+ * @default false
74
+ */
75
+ onHome?: boolean;
76
+ };
77
+ };
@@ -0,0 +1,6 @@
1
+ export * from './events';
2
+ export * from './express';
3
+ export * from './http';
4
+ export * from './options';
5
+ export * from './utils';
6
+ export * from './wootils';
@@ -0,0 +1,248 @@
1
+ import type { Config } from './wootils';
2
+ import type { Jimpex } from '../app';
3
+ /**
4
+ * The options for the application's configuration service.
5
+ *
6
+ * @see {@link https://www.npmjs.com/package/@homer0/simple-config}
7
+ * @group Jimpex
8
+ */
9
+ export type JimpexConfigOptions = {
10
+ /**
11
+ * The default settings for the configuration. If no external configuration is used,
12
+ * this needs to include a `port` property.
13
+ */
14
+ default: unknown;
15
+ /**
16
+ * The name of the application, used for external configuration files.
17
+ *
18
+ * @default 'app'
19
+ */
20
+ name: string;
21
+ /**
22
+ * The path to where external configuration files are stored. Relative to the project
23
+ * root.
24
+ *
25
+ * @default 'config/'
26
+ */
27
+ path: string;
28
+ /**
29
+ * Whether the configuration files are inside a sub directory or not. If `true`, a
30
+ * configuration path would be `config/[app-name]/[file]`.
31
+ *
32
+ * @default false
33
+ */
34
+ hasFolder: boolean;
35
+ /**
36
+ * Whether or not to check for the environment variable and load a configuration file
37
+ * based on its value.
38
+ *
39
+ * @default true
40
+ */
41
+ loadFromEnvironment: boolean;
42
+ /**
43
+ * The name of the environment variable that will be used to set the active
44
+ * configuration.
45
+ *
46
+ * @default 'CONFIG'
47
+ */
48
+ environmentVariable: string;
49
+ /**
50
+ * The name of the default configuration file.
51
+ *
52
+ * @default '[app-name].config.js'
53
+ */
54
+ defaultConfigFilename: string;
55
+ /**
56
+ * The name format of other external configuration files.
57
+ *
58
+ * @default '[app-name].[config-name].config.js'
59
+ */
60
+ filenameFormat: string;
61
+ };
62
+ /**
63
+ * The options for the middleware that serves static files.
64
+ *
65
+ * @group Jimpex
66
+ */
67
+ export type JimpexStaticsOptions = {
68
+ /**
69
+ * Whether or not to enable the middleware.
70
+ *
71
+ * @default true
72
+ */
73
+ enabled: boolean;
74
+ /**
75
+ * If `true`, the path to the statics folder will be relative to the project root
76
+ * directory, otherwise, it will be relative to the directory where the app executable
77
+ * file is located.
78
+ *
79
+ * @default false
80
+ */
81
+ onHome: boolean;
82
+ /**
83
+ * The name of both the route and the folder, relative to whatever you defined with the
84
+ * `onHome` option.
85
+ *
86
+ * @default 'statics'
87
+ */
88
+ route: string;
89
+ /**
90
+ * By default, the folder will be the same as the `route`,
91
+ * but you can use this option to define a relative path that won't affect the route.
92
+ *
93
+ * @default ''
94
+ */
95
+ folder?: string;
96
+ };
97
+ /**
98
+ * The options for the Express application.
99
+ *
100
+ * @group Jimpex
101
+ */
102
+ export type JimpexExpressOptions = {
103
+ /**
104
+ * Whether or not to enable the `trust proxy` option.
105
+ *
106
+ * @default true
107
+ */
108
+ trustProxy: boolean;
109
+ /**
110
+ * Whether or not to remove the `x-powered-by` header.
111
+ *
112
+ * @default true
113
+ */
114
+ disableXPoweredBy: boolean;
115
+ /**
116
+ * Whether or not to add the `compression` middleware.
117
+ *
118
+ * @default true
119
+ */
120
+ compression: boolean;
121
+ /**
122
+ * Whether or not to add the `body-parser` middleware.
123
+ *
124
+ * @default true
125
+ */
126
+ bodyParser: boolean;
127
+ /**
128
+ * Whether or not to add the `multer` middleware.
129
+ *
130
+ * @see {@link https://www.npmjs.com/package/multer}
131
+ */
132
+ multer: boolean;
133
+ };
134
+ /**
135
+ * The options to configure the application executable path.
136
+ *
137
+ * @group Jimpex
138
+ */
139
+ export type JimpexPathOptions = {
140
+ /**
141
+ * A "hardcoded" path to the application executable file.
142
+ *
143
+ * @default ''
144
+ */
145
+ appPath?: string;
146
+ /**
147
+ * If `true`, it will try to figure out the parent file path, and use its directory as
148
+ * the path.
149
+ *
150
+ * @default true
151
+ */
152
+ useParentPath: boolean;
153
+ };
154
+ /**
155
+ * The options to enable some of the default services Jimpex comes with.
156
+ *
157
+ * @group Jimpex
158
+ */
159
+ export type JimpexServicesOptions = {
160
+ /**
161
+ * Whether or not to register all the `common` services: `appError`, `httpError`, and
162
+ * `sendFile`.
163
+ *
164
+ * @default true
165
+ */
166
+ common: boolean;
167
+ /**
168
+ * Whether or not to register the `http` services: `apiClient`, `http`, and
169
+ * `responsesBuilder`.
170
+ *
171
+ * @default true
172
+ */
173
+ http: boolean;
174
+ /**
175
+ * Whether or not to register the `utils` services: `ensureBearerToken`.
176
+ */
177
+ utils: boolean;
178
+ };
179
+ /**
180
+ * The format in which the application's health status can be returned.
181
+ * It's either a simple boolean, or a more detailed object.
182
+ *
183
+ * @group Jimpex
184
+ */
185
+ export type JimpexHealthStatus =
186
+ | boolean
187
+ | {
188
+ isHealthy?: boolean;
189
+ services?: Record<string, boolean>;
190
+ };
191
+ /**
192
+ * Returns the application health status. This is normally used by the `healthController`.
193
+ *
194
+ * @group Jimpex
195
+ */
196
+ export type JimpexHealthCheckFn = (app: Jimpex) => Promise<JimpexHealthStatus>;
197
+ /**
198
+ * The options to create a new instance of Jimpex.
199
+ *
200
+ * @group Jimpex
201
+ */
202
+ export type JimpexOptions = {
203
+ /**
204
+ * The size limit for the requests payload.
205
+ *
206
+ * @default '15MB'
207
+ */
208
+ filesizeLimit: string;
209
+ /**
210
+ * Whether or not to call the `boot` method after initialization. This is useful if you
211
+ * want to register/overwrite services only on certain contexts, like a dev environment.
212
+ *
213
+ * @default true
214
+ */
215
+ boot: boolean;
216
+ /**
217
+ * The options to configure the application executable path.
218
+ */
219
+ path: JimpexPathOptions;
220
+ /**
221
+ * Options for the configuration service.
222
+ *
223
+ * @see {@link https://www.npmjs.com/package/@homer0/simple-config}
224
+ */
225
+ config: JimpexConfigOptions;
226
+ /**
227
+ * Options for the middleware that serves static files.
228
+ */
229
+ statics: JimpexStaticsOptions;
230
+ /**
231
+ * Options for the Express application.
232
+ */
233
+ express: JimpexExpressOptions;
234
+ /**
235
+ * Options to manage the default services.
236
+ */
237
+ services: JimpexServicesOptions;
238
+ /**
239
+ * A function that will be used to check the application health status.
240
+ */
241
+ healthCheck: JimpexHealthCheckFn;
242
+ };
243
+ /**
244
+ * The function called when the application starts listening for requests.
245
+ *
246
+ * @group Jimpex
247
+ */
248
+ export type JimpexStartCallback = (config: Config) => void;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A simple dictionary with unknown values.
3
+ *
4
+ * @group Utilities
5
+ */
6
+ export type Dict = Record<string, unknown>;
7
+ /**
8
+ * Utility to make a deep "partial" of an existing type.
9
+ *
10
+ * @template T The type to make a partial of.
11
+ * @group Utilities
12
+ */
13
+ export type DeepPartial<T> = {
14
+ [P in keyof T]?: T[P] extends (infer U)[]
15
+ ? DeepPartial<U>[]
16
+ : T[P] extends object
17
+ ? DeepPartial<T[P]>
18
+ : T[P];
19
+ };
20
+ /**
21
+ * Utility to make a deep "readonly" of an existing type.
22
+ *
23
+ * @template T The type to make a readonly of.
24
+ * @group Utilities
25
+ */
26
+ export type DeepReadonly<T> = {
27
+ readonly [P in keyof T]: T[P] extends (infer U)[]
28
+ ? DeepReadonly<U>[]
29
+ : T[P] extends object
30
+ ? DeepReadonly<T[P]>
31
+ : T[P];
32
+ };
33
+ /**
34
+ * Utility to remove string indexes from types.
35
+ *
36
+ * @template T The type to remove string indexes from.
37
+ * @example
38
+ *
39
+ * type Foo = {
40
+ * a: string;
41
+ * b: string;
42
+ * [key: string]: string;
43
+ * };
44
+ * type Bar = RemoveStringIndexes<Foo>;
45
+ * // Bar = {
46
+ * // a: string;
47
+ * // b: string;
48
+ * // };
49
+ *
50
+ * @group Utilities
51
+ */
52
+ export type NoStringIndex<T> = { [K in keyof T as string extends K ? never : K]: T[K] };
@@ -0,0 +1,4 @@
1
+ export type { PathUtils } from '@homer0/path-utils';
2
+ export type { SimpleLogger as Logger } from '@homer0/simple-logger';
3
+ export type { SimpleConfig as Config } from '@homer0/simple-config';
4
+ export type { EventsHub } from '@homer0/events-hub';