jimpex 10.0.2 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +7 -9
  3. package/dist/app/index.d.ts +1 -1
  4. package/dist/app/index.js +1 -22
  5. package/dist/app/index.js.map +1 -1
  6. package/dist/app/jimpex.d.ts +1 -1
  7. package/dist/app/jimpex.js +100 -131
  8. package/dist/app/jimpex.js.map +1 -1
  9. package/dist/controllers/common/config.d.ts +2 -2
  10. package/dist/controllers/common/config.js +12 -39
  11. package/dist/controllers/common/config.js.map +1 -1
  12. package/dist/controllers/common/health.d.ts +4 -4
  13. package/dist/controllers/common/health.js +20 -47
  14. package/dist/controllers/common/health.js.map +1 -1
  15. package/dist/controllers/common/index.d.ts +1 -1
  16. package/dist/controllers/common/index.js +3 -26
  17. package/dist/controllers/common/index.js.map +1 -1
  18. package/dist/controllers/common/statics.d.ts +3 -3
  19. package/dist/controllers/common/statics.js +32 -65
  20. package/dist/controllers/common/statics.js.map +1 -1
  21. package/dist/controllers/index.d.ts +1 -1
  22. package/dist/controllers/index.js +2 -24
  23. package/dist/controllers/index.js.map +1 -1
  24. package/dist/controllers/utils/gateway.d.ts +5 -5
  25. package/dist/controllers/utils/gateway.js +70 -91
  26. package/dist/controllers/utils/gateway.js.map +1 -1
  27. package/dist/controllers/utils/index.d.ts +1 -1
  28. package/dist/controllers/utils/index.js +1 -22
  29. package/dist/controllers/utils/index.js.map +1 -1
  30. package/dist/{index-C6I3NCC-.d.ts → index-BlSpNHox.d.ts} +13 -13
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.js +6 -32
  33. package/dist/index.js.map +1 -1
  34. package/dist/middlewares/common/errorHandler.d.ts +5 -5
  35. package/dist/middlewares/common/errorHandler.js +31 -56
  36. package/dist/middlewares/common/errorHandler.js.map +1 -1
  37. package/dist/middlewares/common/forceHTTPS.d.ts +1 -1
  38. package/dist/middlewares/common/forceHTTPS.js +8 -35
  39. package/dist/middlewares/common/forceHTTPS.js.map +1 -1
  40. package/dist/middlewares/common/hsts.d.ts +1 -1
  41. package/dist/middlewares/common/hsts.js +12 -39
  42. package/dist/middlewares/common/hsts.js.map +1 -1
  43. package/dist/middlewares/common/index.d.ts +3 -3
  44. package/dist/middlewares/common/index.js +3 -26
  45. package/dist/middlewares/common/index.js.map +1 -1
  46. package/dist/middlewares/html/fastHTML.d.ts +4 -4
  47. package/dist/middlewares/html/fastHTML.js +43 -66
  48. package/dist/middlewares/html/fastHTML.js.map +1 -1
  49. package/dist/middlewares/html/index.d.ts +2 -2
  50. package/dist/middlewares/html/index.js +2 -24
  51. package/dist/middlewares/html/index.js.map +1 -1
  52. package/dist/middlewares/html/showHTML.d.ts +3 -3
  53. package/dist/middlewares/html/showHTML.js +25 -52
  54. package/dist/middlewares/html/showHTML.js.map +1 -1
  55. package/dist/middlewares/index.d.ts +4 -4
  56. package/dist/middlewares/index.js +3 -26
  57. package/dist/middlewares/index.js.map +1 -1
  58. package/dist/middlewares/utils/index.d.ts +3 -3
  59. package/dist/middlewares/utils/index.js +1 -22
  60. package/dist/middlewares/utils/index.js.map +1 -1
  61. package/dist/middlewares/utils/versionValidator.d.ts +5 -5
  62. package/dist/middlewares/utils/versionValidator.js +24 -51
  63. package/dist/middlewares/utils/versionValidator.js.map +1 -1
  64. package/dist/services/common/appError.d.ts +2 -2
  65. package/dist/services/common/appError.js +18 -46
  66. package/dist/services/common/appError.js.map +1 -1
  67. package/dist/services/common/httpError.d.ts +2 -2
  68. package/dist/services/common/httpError.js +7 -33
  69. package/dist/services/common/httpError.js.map +1 -1
  70. package/dist/services/common/index.d.ts +1 -1
  71. package/dist/services/common/index.js +14 -42
  72. package/dist/services/common/index.js.map +1 -1
  73. package/dist/services/common/sendFile.d.ts +1 -1
  74. package/dist/services/common/sendFile.js +4 -29
  75. package/dist/services/common/sendFile.js.map +1 -1
  76. package/dist/services/frontend/frontendFs.d.ts +2 -2
  77. package/dist/services/frontend/frontendFs.js +12 -49
  78. package/dist/services/frontend/frontendFs.js.map +1 -1
  79. package/dist/services/frontend/index.d.ts +2 -2
  80. package/dist/services/frontend/index.js +8 -34
  81. package/dist/services/frontend/index.js.map +1 -1
  82. package/dist/services/html/htmlGenerator.d.ts +5 -5
  83. package/dist/services/html/htmlGenerator.js +46 -75
  84. package/dist/services/html/htmlGenerator.js.map +1 -1
  85. package/dist/services/html/index.d.ts +2 -2
  86. package/dist/services/html/index.js +8 -34
  87. package/dist/services/html/index.js.map +1 -1
  88. package/dist/services/http/apiClient.d.ts +1 -1
  89. package/dist/services/http/apiClient.js +23 -48
  90. package/dist/services/http/apiClient.js.map +1 -1
  91. package/dist/services/http/http.d.ts +5 -5
  92. package/dist/services/http/http.js +23 -60
  93. package/dist/services/http/http.js.map +1 -1
  94. package/dist/services/http/index.d.ts +2 -2
  95. package/dist/services/http/index.js +14 -42
  96. package/dist/services/http/index.js.map +1 -1
  97. package/dist/services/http/responsesBuilder.d.ts +4 -4
  98. package/dist/services/http/responsesBuilder.js +13 -40
  99. package/dist/services/http/responsesBuilder.js.map +1 -1
  100. package/dist/services/index.d.ts +3 -3
  101. package/dist/services/index.js +5 -30
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/services/utils/ensureBearerToken.d.ts +2 -2
  104. package/dist/services/utils/ensureBearerToken.js +15 -42
  105. package/dist/services/utils/ensureBearerToken.js.map +1 -1
  106. package/dist/services/utils/index.d.ts +1 -1
  107. package/dist/services/utils/index.js +8 -34
  108. package/dist/services/utils/index.js.map +1 -1
  109. package/dist/types/events.d.ts +1 -1
  110. package/dist/types/events.js +0 -16
  111. package/dist/types/events.js.map +1 -1
  112. package/dist/types/express.js +0 -16
  113. package/dist/types/express.js.map +1 -1
  114. package/dist/types/http.js +0 -16
  115. package/dist/types/http.js.map +1 -1
  116. package/dist/types/index.d.ts +1 -1
  117. package/dist/types/index.js +6 -32
  118. package/dist/types/index.js.map +1 -1
  119. package/dist/types/options.d.ts +1 -1
  120. package/dist/types/options.js +0 -16
  121. package/dist/types/options.js.map +1 -1
  122. package/dist/types/utils.js +0 -16
  123. package/dist/types/utils.js.map +1 -1
  124. package/dist/types/wootils.js +0 -16
  125. package/dist/types/wootils.js.map +1 -1
  126. package/dist/utils/fns/index.js +4 -28
  127. package/dist/utils/fns/index.js.map +1 -1
  128. package/dist/utils/fns/others.js +2 -26
  129. package/dist/utils/fns/others.js.map +1 -1
  130. package/dist/utils/fns/routes.js +4 -31
  131. package/dist/utils/fns/routes.js.map +1 -1
  132. package/dist/utils/fns/statuses.js +3 -37
  133. package/dist/utils/fns/statuses.js.map +1 -1
  134. package/dist/utils/fns/text.js +2 -26
  135. package/dist/utils/fns/text.js.map +1 -1
  136. package/dist/utils/index.d.ts +1 -1
  137. package/dist/utils/index.js +2 -24
  138. package/dist/utils/index.js.map +1 -1
  139. package/dist/utils/wrappers.d.ts +1 -1
  140. package/dist/utils/wrappers.js +20 -48
  141. package/dist/utils/wrappers.js.map +1 -1
  142. package/eslint.config.js +19 -0
  143. package/examples/basic/app.ts +4 -4
  144. package/examples/basic/controller.ts +2 -2
  145. package/examples/basic/index.ts +4 -4
  146. package/examples/basic/middleware.ts +2 -2
  147. package/examples/basic/service.ts +1 -1
  148. package/package.json +61 -49
  149. package/pnpm-workspace.yaml +4 -0
  150. package/src/app/index.ts +1 -1
  151. package/src/app/jimpex.ts +23 -20
  152. package/src/controllers/common/config.ts +4 -4
  153. package/src/controllers/common/health.ts +9 -5
  154. package/src/controllers/common/index.ts +3 -3
  155. package/src/controllers/common/statics.ts +12 -7
  156. package/src/controllers/index.ts +2 -2
  157. package/src/controllers/utils/gateway.ts +8 -8
  158. package/src/controllers/utils/index.ts +1 -1
  159. package/src/index.ts +6 -6
  160. package/src/middlewares/common/errorHandler.ts +9 -5
  161. package/src/middlewares/common/forceHTTPS.ts +2 -2
  162. package/src/middlewares/common/hsts.ts +2 -2
  163. package/src/middlewares/common/index.ts +3 -3
  164. package/src/middlewares/html/fastHTML.ts +14 -5
  165. package/src/middlewares/html/index.ts +2 -2
  166. package/src/middlewares/html/showHTML.ts +8 -4
  167. package/src/middlewares/index.ts +3 -3
  168. package/src/middlewares/utils/index.ts +1 -1
  169. package/src/middlewares/utils/versionValidator.ts +6 -6
  170. package/src/services/common/appError.ts +1 -1
  171. package/src/services/common/httpError.ts +2 -2
  172. package/src/services/common/index.ts +7 -7
  173. package/src/services/common/sendFile.ts +2 -2
  174. package/src/services/frontend/frontendFs.ts +3 -3
  175. package/src/services/frontend/index.ts +3 -3
  176. package/src/services/html/htmlGenerator.ts +11 -13
  177. package/src/services/html/index.ts +3 -3
  178. package/src/services/http/apiClient.ts +3 -3
  179. package/src/services/http/http.ts +5 -5
  180. package/src/services/http/index.ts +7 -7
  181. package/src/services/http/responsesBuilder.ts +5 -5
  182. package/src/services/index.ts +5 -5
  183. package/src/services/utils/ensureBearerToken.ts +4 -4
  184. package/src/services/utils/index.ts +3 -3
  185. package/src/types/events.ts +8 -8
  186. package/src/types/http.ts +1 -1
  187. package/src/types/index.ts +6 -6
  188. package/src/types/options.ts +2 -2
  189. package/src/types/utils.ts +4 -4
  190. package/src/utils/fns/index.ts +4 -4
  191. package/src/utils/fns/routes.ts +1 -1
  192. package/src/utils/index.ts +2 -2
  193. package/src/utils/wrappers.ts +6 -6
  194. package/tsconfig.json +9 -4
  195. package/tsup.config.ts +1 -2
  196. package/vitest.config.ts +24 -0
  197. package/dist/app/index.d.mts +0 -14
  198. package/dist/app/jimpex.d.mts +0 -14
  199. package/dist/controllers/common/config.d.mts +0 -79
  200. package/dist/controllers/common/health.d.mts +0 -83
  201. package/dist/controllers/common/index.d.mts +0 -22
  202. package/dist/controllers/common/statics.d.mts +0 -223
  203. package/dist/controllers/index.d.mts +0 -25
  204. package/dist/controllers/utils/gateway.d.mts +0 -725
  205. package/dist/controllers/utils/index.d.mts +0 -17
  206. package/dist/esm/app/index.js +0 -2
  207. package/dist/esm/app/index.js.map +0 -1
  208. package/dist/esm/app/jimpex.js +0 -640
  209. package/dist/esm/app/jimpex.js.map +0 -1
  210. package/dist/esm/chunk-V6TY7KAL.js +0 -8
  211. package/dist/esm/chunk-V6TY7KAL.js.map +0 -1
  212. package/dist/esm/controllers/common/config.js +0 -80
  213. package/dist/esm/controllers/common/config.js.map +0 -1
  214. package/dist/esm/controllers/common/health.js +0 -88
  215. package/dist/esm/controllers/common/health.js.map +0 -1
  216. package/dist/esm/controllers/common/index.js +0 -4
  217. package/dist/esm/controllers/common/index.js.map +0 -1
  218. package/dist/esm/controllers/common/statics.js +0 -226
  219. package/dist/esm/controllers/common/statics.js.map +0 -1
  220. package/dist/esm/controllers/index.js +0 -3
  221. package/dist/esm/controllers/index.js.map +0 -1
  222. package/dist/esm/controllers/utils/gateway.js +0 -559
  223. package/dist/esm/controllers/utils/gateway.js.map +0 -1
  224. package/dist/esm/controllers/utils/index.js +0 -2
  225. package/dist/esm/controllers/utils/index.js.map +0 -1
  226. package/dist/esm/index.js +0 -7
  227. package/dist/esm/index.js.map +0 -1
  228. package/dist/esm/middlewares/common/errorHandler.js +0 -116
  229. package/dist/esm/middlewares/common/errorHandler.js.map +0 -1
  230. package/dist/esm/middlewares/common/forceHTTPS.js +0 -52
  231. package/dist/esm/middlewares/common/forceHTTPS.js.map +0 -1
  232. package/dist/esm/middlewares/common/hsts.js +0 -74
  233. package/dist/esm/middlewares/common/hsts.js.map +0 -1
  234. package/dist/esm/middlewares/common/index.js +0 -4
  235. package/dist/esm/middlewares/common/index.js.map +0 -1
  236. package/dist/esm/middlewares/html/fastHTML.js +0 -157
  237. package/dist/esm/middlewares/html/fastHTML.js.map +0 -1
  238. package/dist/esm/middlewares/html/index.js +0 -3
  239. package/dist/esm/middlewares/html/index.js.map +0 -1
  240. package/dist/esm/middlewares/html/showHTML.js +0 -100
  241. package/dist/esm/middlewares/html/showHTML.js.map +0 -1
  242. package/dist/esm/middlewares/index.js +0 -4
  243. package/dist/esm/middlewares/index.js.map +0 -1
  244. package/dist/esm/middlewares/utils/index.js +0 -2
  245. package/dist/esm/middlewares/utils/index.js.map +0 -1
  246. package/dist/esm/middlewares/utils/versionValidator.js +0 -135
  247. package/dist/esm/middlewares/utils/versionValidator.js.map +0 -1
  248. package/dist/esm/services/common/appError.js +0 -98
  249. package/dist/esm/services/common/appError.js.map +0 -1
  250. package/dist/esm/services/common/httpError.js +0 -28
  251. package/dist/esm/services/common/httpError.js.map +0 -1
  252. package/dist/esm/services/common/index.js +0 -17
  253. package/dist/esm/services/common/index.js.map +0 -1
  254. package/dist/esm/services/common/sendFile.js +0 -27
  255. package/dist/esm/services/common/sendFile.js.map +0 -1
  256. package/dist/esm/services/frontend/frontendFs.js +0 -66
  257. package/dist/esm/services/frontend/frontendFs.js.map +0 -1
  258. package/dist/esm/services/frontend/index.js +0 -11
  259. package/dist/esm/services/frontend/index.js.map +0 -1
  260. package/dist/esm/services/html/htmlGenerator.js +0 -192
  261. package/dist/esm/services/html/htmlGenerator.js.map +0 -1
  262. package/dist/esm/services/html/index.js +0 -11
  263. package/dist/esm/services/html/index.js.map +0 -1
  264. package/dist/esm/services/http/apiClient.js +0 -94
  265. package/dist/esm/services/http/apiClient.js.map +0 -1
  266. package/dist/esm/services/http/http.js +0 -180
  267. package/dist/esm/services/http/http.js.map +0 -1
  268. package/dist/esm/services/http/index.js +0 -17
  269. package/dist/esm/services/http/index.js.map +0 -1
  270. package/dist/esm/services/http/responsesBuilder.js +0 -152
  271. package/dist/esm/services/http/responsesBuilder.js.map +0 -1
  272. package/dist/esm/services/index.js +0 -6
  273. package/dist/esm/services/index.js.map +0 -1
  274. package/dist/esm/services/utils/ensureBearerToken.js +0 -94
  275. package/dist/esm/services/utils/ensureBearerToken.js.map +0 -1
  276. package/dist/esm/services/utils/index.js +0 -11
  277. package/dist/esm/services/utils/index.js.map +0 -1
  278. package/dist/esm/types/events.js +0 -1
  279. package/dist/esm/types/events.js.map +0 -1
  280. package/dist/esm/types/express.js +0 -1
  281. package/dist/esm/types/express.js.map +0 -1
  282. package/dist/esm/types/http.js +0 -1
  283. package/dist/esm/types/http.js.map +0 -1
  284. package/dist/esm/types/index.js +0 -7
  285. package/dist/esm/types/index.js.map +0 -1
  286. package/dist/esm/types/options.js +0 -1
  287. package/dist/esm/types/options.js.map +0 -1
  288. package/dist/esm/types/utils.js +0 -1
  289. package/dist/esm/types/utils.js.map +0 -1
  290. package/dist/esm/types/wootils.js +0 -1
  291. package/dist/esm/types/wootils.js.map +0 -1
  292. package/dist/esm/utils/fns/index.js +0 -5
  293. package/dist/esm/utils/fns/index.js.map +0 -1
  294. package/dist/esm/utils/fns/others.js +0 -6
  295. package/dist/esm/utils/fns/others.js.map +0 -1
  296. package/dist/esm/utils/fns/routes.js +0 -25
  297. package/dist/esm/utils/fns/routes.js.map +0 -1
  298. package/dist/esm/utils/fns/statuses.js +0 -6
  299. package/dist/esm/utils/fns/statuses.js.map +0 -1
  300. package/dist/esm/utils/fns/text.js +0 -6
  301. package/dist/esm/utils/fns/text.js.map +0 -1
  302. package/dist/esm/utils/index.js +0 -3
  303. package/dist/esm/utils/index.js.map +0 -1
  304. package/dist/esm/utils/wrappers.js +0 -41
  305. package/dist/esm/utils/wrappers.js.map +0 -1
  306. package/dist/index-Bwf7JHu9.d.mts +0 -1287
  307. package/dist/index.d.mts +0 -47
  308. package/dist/middlewares/common/errorHandler.d.mts +0 -132
  309. package/dist/middlewares/common/forceHTTPS.d.mts +0 -69
  310. package/dist/middlewares/common/hsts.d.mts +0 -110
  311. package/dist/middlewares/common/index.d.mts +0 -22
  312. package/dist/middlewares/html/fastHTML.d.mts +0 -180
  313. package/dist/middlewares/html/index.d.mts +0 -21
  314. package/dist/middlewares/html/showHTML.d.mts +0 -127
  315. package/dist/middlewares/index.d.mts +0 -30
  316. package/dist/middlewares/utils/index.d.mts +0 -20
  317. package/dist/middlewares/utils/versionValidator.d.mts +0 -215
  318. package/dist/services/common/appError.d.mts +0 -139
  319. package/dist/services/common/httpError.d.mts +0 -80
  320. package/dist/services/common/index.d.mts +0 -47
  321. package/dist/services/common/sendFile.d.mts +0 -102
  322. package/dist/services/frontend/frontendFs.d.mts +0 -96
  323. package/dist/services/frontend/index.d.mts +0 -40
  324. package/dist/services/html/htmlGenerator.d.mts +0 -237
  325. package/dist/services/html/index.d.mts +0 -43
  326. package/dist/services/http/apiClient.d.mts +0 -170
  327. package/dist/services/http/http.d.mts +0 -182
  328. package/dist/services/http/index.d.mts +0 -51
  329. package/dist/services/http/responsesBuilder.d.mts +0 -179
  330. package/dist/services/index.d.mts +0 -33
  331. package/dist/services/utils/ensureBearerToken.d.mts +0 -158
  332. package/dist/services/utils/index.d.mts +0 -44
  333. package/dist/types/events.d.mts +0 -14
  334. package/dist/types/express.d.mts +0 -10
  335. package/dist/types/http.d.mts +0 -82
  336. package/dist/types/index.d.mts +0 -14
  337. package/dist/types/options.d.mts +0 -14
  338. package/dist/types/utils.d.mts +0 -48
  339. package/dist/types/wootils.d.mts +0 -4
  340. package/dist/utils/fns/index.d.mts +0 -5
  341. package/dist/utils/fns/others.d.mts +0 -17
  342. package/dist/utils/fns/routes.d.mts +0 -39
  343. package/dist/utils/fns/statuses.d.mts +0 -45
  344. package/dist/utils/fns/text.d.mts +0 -9
  345. package/dist/utils/index.d.mts +0 -19
  346. package/dist/utils/wrappers.d.mts +0 -14
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/app/jimpex.ts"],"sourcesContent":["import * as path from 'path';\nimport fs from 'fs/promises';\nimport { createServer as createHTTPSServer } from 'https';\nimport { Jimple } from '@homer0/jimple';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { appLoggerProvider } from '@homer0/simple-logger';\nimport { envUtilsProvider } from '@homer0/env-utils';\nimport { packageInfoProvider } from '@homer0/package-info';\nimport { pathUtilsProvider } from '@homer0/path-utils';\nimport { rootFileProvider } from '@homer0/root-file';\nimport { tsAsyncImport } from '@homer0/ts-async-import';\nimport { EventsHub } from '@homer0/events-hub';\nimport { simpleConfigProvider } from '@homer0/simple-config';\nimport compression from 'compression';\nimport bodyParser from 'body-parser';\nimport multer from 'multer';\nimport {\n createServer as createSpdyServer,\n type ServerOptions as SpdyServerOptions,\n} from 'spdy';\nimport express from 'express';\nimport {\n commonServicesProvider,\n httpServicesProvider,\n utilsServicesProvider,\n} from '../services';\nimport {\n statuses,\n type Controller,\n type ControllerLike,\n type MiddlewareLike,\n type MiddlewareProvider,\n type Middleware,\n} from '../utils';\nimport type {\n DeepPartial,\n Express,\n ExpressMiddlewareLike,\n PathUtils,\n Config,\n Logger,\n JimpexOptions,\n JimpexHTTPSCredentials,\n JimpexHTTP2Options,\n JimpexHTTPSOptions,\n JimpexStartCallback,\n JimpexServer,\n JimpexServerInstance,\n JimpexEventName,\n JimpexEventPayload,\n DeepReadonly,\n JimpexReducerEventName,\n JimpexReducerEventPayload,\n JimpexReducerEventTarget,\n JimpexEventNameLike,\n JimpexEventListener,\n JimpexHealthCheckFn,\n Router,\n} from '../types';\n/**\n * Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container,\n * and Express, one of the most popular web frameworks for Node.\n *\n * @group Jimpex\n * @todo Implement `helmet`.\n */\nexport class Jimpex extends Jimple {\n /**\n * The customization settings for the application.\n */\n protected _options: JimpexOptions;\n /**\n * The Express application Jimpex uses under the hood.\n */\n protected _express: Express;\n /**\n * Since the configuration service has an async initialization, the class uses this flag\n * internally to validate if the configuration has been initialized or not.\n */\n protected _configReady: boolean = false;\n /**\n * A reference to the actuall HTTP the application will use. This can vary depending on\n * whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as\n * the `express` property; if HTTPS is enabled, it will be an `https` server; and if\n * HTTP2 is enabled, it will be an `spdy` server.\n */\n protected _server?: JimpexServer;\n /**\n * The instance of the server that is listening for requests.\n */\n protected _instance?: JimpexServerInstance;\n /**\n * A list of functions that implement controllers and middlewares. When the application\n * starts, the queue will be processed and those controllers and middlewares will be\n * added to the server instance. The reason they are not added directly like with a\n * regular Express implementation is that services on Jimple use lazy loading, and\n * adding middlewares and controllers as they come could cause errors if they depend on\n * services that are not yet registered.\n */\n protected _mountQueue: Array<(server: Express) => void> = [];\n /**\n * A list with all the top routes controlled by the application. Every time a controller\n * is mounted, its route will be added here.\n */\n protected _controlledRoutes: string[] = [];\n /**\n * @param options Preferences to customize the application.\n * @param config The default settings for the configuration service. It's a\n * shortcuit for `options.config.default`\n */\n constructor(options: DeepPartial<JimpexOptions> = {}, config: unknown = {}) {\n super();\n\n this._options = deepAssignWithOverwrite(\n {\n filesizeLimit: '15MB',\n boot: true,\n path: {\n appPath: '',\n useParentPath: true,\n },\n config: {\n default: options?.config?.default || config,\n name: 'app',\n path: 'config/',\n hasFolder: false,\n loadFromEnvironment: true,\n environmentVariable: 'CONFIG',\n defaultConfigFilename: '[app-name].config.js',\n filenameFormat: '[app-name].[config-name].config.js',\n },\n statics: {\n enabled: true,\n onHome: false,\n route: 'statics',\n },\n express: {\n trustProxy: true,\n disableXPoweredBy: true,\n compression: true,\n bodyParser: true,\n multer: true,\n },\n services: {\n common: true,\n http: true,\n utils: true,\n },\n healthCheck: () => Promise.resolve(true),\n },\n options,\n this._initOptions(),\n );\n\n this._express = express();\n\n this._setupCoreServices();\n this._setupExpress();\n this._configurePath();\n\n this._init();\n if (this._options.boot) {\n this.boot();\n }\n }\n /**\n * This is where the app would register all its specific services, middlewares and controllers.\n */\n boot(): void {}\n /**\n * Disables the server TLS validation. Meant to be used for development purposes.\n */\n disableTLSValidation() {\n // eslint-disable-next-line no-process-env, dot-notation\n process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';\n this.logger.warn('TLS validation has been disabled');\n }\n /**\n * Starts the app server.\n *\n * @param onStart A callback function to be called when the server actually starts.\n * @returns The server instance.\n */\n async start(onStart?: JimpexStartCallback): Promise<JimpexServerInstance> {\n await Promise.all([this._setupConfig(), this._loadESMModules()]);\n const config = this.getConfig();\n const port = config.get<number | undefined>('port');\n if (!port) {\n throw new Error('No port configured');\n }\n this._emitEvent('beforeStart', { app: this });\n this._server = await this._createServer();\n this._instance = this._server!.listen(port, () => {\n this._emitEvent('start', { app: this });\n this._mountResources();\n this.logger.success(`Starting on port ${port}`);\n this._emitEvent('afterStart', { app: this });\n if (onStart) {\n onStart(config);\n }\n this._emitEvent('afterStartCallback', { app: this });\n });\n\n return this._instance!;\n }\n /**\n * This is an alias of `start`. The idea is for it to be used on serverless platforms,\n * where you don't get to start your app, you just have export it.\n *\n * @param port In case the configuration doesn't already have it,\n * this is the port where the application will use to run. If this\n * parameter is used, the method will overwrite the `port`\n * setting on the configuration service.\n * @param onStart A callback function to be called when the server starts.\n * @returns The server instance.\n */\n async listen(\n port?: number,\n onStart?: JimpexStartCallback,\n ): Promise<JimpexServerInstance> {\n if (port) {\n await Promise.all([this._setupConfig(), this._loadESMModules()]);\n const config = this.getConfig();\n config.set('port', port);\n }\n\n return this.start(onStart);\n }\n /**\n * Stops the server instance.\n */\n stop(): void {\n if (!this._instance) return;\n this._emitEvent('beforeStop', { app: this });\n this._instance.close();\n this._instance = undefined;\n this._emitEvent('afterStop', { app: this });\n }\n /**\n * Mounts a route controller or a middleware into a server routes.\n *\n * @param route The route for the controller/middleware.\n * @param controller The controller/middleware resource to be mounted.\n */\n mount(route: string, controller: ControllerLike): void {\n let useController: Controller | Middleware;\n if (\n 'register' in controller &&\n typeof controller.register === 'function' &&\n controller.provider === true\n ) {\n useController = controller.register(this, route);\n } else if (\n 'connect' in controller &&\n typeof controller.connect === 'function' &&\n (('middleware' in controller && controller.middleware === true) ||\n ('controller' in controller && controller.controller === true))\n ) {\n useController = controller;\n } else {\n useController = {\n middleware: true,\n connect: () => controller as ExpressMiddlewareLike,\n };\n }\n\n this._mountQueue.push((server) => {\n const connected = useController.connect(this, route);\n if (!connected) return;\n const router = this._reduceWithEvent('controllerWillBeMounted', connected, {\n route,\n controller: useController,\n app: this,\n });\n server.use(route, router);\n this._emitEvent('routeAdded', { route, app: this });\n this._controlledRoutes.push(route);\n });\n }\n /**\n * Adds a global middleware to the application.\n *\n * @param middleware The middleware resource to be added.\n */\n use(middleware: MiddlewareLike): void {\n const useMiddleware =\n 'register' in middleware && typeof middleware.register === 'function'\n ? (middleware as MiddlewareProvider).register(this)\n : (middleware as Middleware | ExpressMiddlewareLike);\n this._mountQueue.push((server) => {\n if ('connect' in useMiddleware && typeof useMiddleware.connect === 'function') {\n const handler = useMiddleware.connect(this);\n if (handler) {\n server.use(\n this._reduceWithEvent('middlewareWillBeUsed', handler, { app: this }),\n );\n }\n\n return;\n }\n\n server.use(\n this._reduceWithEvent(\n 'middlewareWillBeUsed',\n useMiddleware as ExpressMiddlewareLike,\n { app: this },\n ),\n );\n });\n }\n\n getConfig(): Config;\n getConfig<T = unknown>(setting: string | string[], asArray?: boolean): T;\n /**\n * Gets a setting from the configuration, or the configuration itself.\n *\n * @param setting The setting or settings to be retrieved. If is not specified, it\n * will return the entire configuration.\n * @param asArray If `true` and `setting` is an array, it will return the values as\n * an array instead of an object.\n * @template T The type of the setting to be retrieved.\n */\n getConfig<T = unknown>(\n setting?: string | string[],\n asArray: boolean = false,\n ): Config | T {\n const config = this.try<Config>('config');\n if (!config) {\n throw new Error('The config service is not available until the app starts');\n }\n if (typeof setting === 'undefined') {\n return config;\n }\n\n return config.get<T>(setting, asArray);\n }\n /**\n * Creates a new router instance.\n */\n getRouter(): Router {\n return this.get('router');\n }\n /**\n * The logger service.\n */\n get logger(): Logger {\n return this.get<Logger>('logger');\n }\n /**\n * The Express application Jimpex uses under the hood.\n */\n get express(): Express {\n return this._express;\n }\n /**\n * The server instance that gets created when the app is started.\n */\n get instance(): JimpexServerInstance | undefined {\n return this._instance;\n }\n /**\n * The application customization options.\n */\n get options(): DeepReadonly<JimpexOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Gets the events service.\n */\n get eventsHub(): EventsHub {\n return this.get<EventsHub>('events');\n }\n /**\n * A list of the routes that have controllers mounted on them.\n */\n get routes(): string[] {\n return this._controlledRoutes.slice();\n }\n /**\n * Adds a listener for an application event.\n *\n * @param eventName The name of the event to listen for.\n * @param listener The listener function.\n * @returns A function to unsubscribe the listener.\n * @template EventName The name of the event, to match the type of the listener\n * function.\n */\n on<EventName extends JimpexEventNameLike>(\n eventName: EventName,\n listener: JimpexEventListener<EventName>,\n ): () => boolean {\n return this.eventsHub.on(eventName, listener);\n }\n /**\n * Adds a listener for an application event that will only be execuded once: the first\n * time the event is triggered.\n *\n * @param eventName The name of the event to listen for.\n * @param listener The listener function.\n * @returns A function to unsubscribe the listener.\n * @template EventName The name of the event, to match the type of the listener\n * function.\n */\n once<EventName extends JimpexEventNameLike>(\n eventName: EventName,\n listener: JimpexEventListener<EventName>,\n ): () => boolean {\n return this.eventsHub.once(eventName, listener);\n }\n /**\n * Based on the application options, it returns wheter the application is healthy or\n * not.\n */\n isHealthy(): ReturnType<JimpexHealthCheckFn> {\n return this._options.healthCheck(this);\n }\n /**\n * This method is like a \"lifecycle method\", it gets executed on the constructor right\n * before the \"boot step\". The idea is for the method to be a helper when the\n * application is defined by subclassing {@link Jimpex}: the application could register\n * all important services here and the routes on boot, then, if the implementation needs\n * to access or overwrite a something, it can send `boot: false`, access/register what\n * it needs, and then call `boot()`. That would be impossible for an application without\n * overwriting the constructor and the boot functionality.\n */\n protected _init(): void {}\n /**\n * It generates overwrites for the application options when it gets created. This method\n * is a helper for when the application is defined by subclassing {@link Jimpex}: It's\n * highly probable that if the application needs to change the default options, it would\n * want to do it right from the class, instead of having to do it on every\n * implementation. A way to do it would be overwriting the constructor and calling\n * `super` with the custom overwrites, but this method exists so that won't be\n * necessary: when creating the `options`, the constructor will merge the result of this\n * method on top of the default ones.\n */\n protected _initOptions(): DeepPartial<JimpexOptions> {\n return {};\n }\n /**\n * Registers the \"core services\" on the container: logger, events, utils, etc.\n */\n protected _setupCoreServices(): void {\n this.register(\n appLoggerProvider({\n serviceName: 'logger',\n }),\n );\n this.register(envUtilsProvider);\n this.register(packageInfoProvider);\n this.register(pathUtilsProvider);\n this.register(rootFileProvider);\n const { services: enabledServices } = this._options;\n if (enabledServices.common) this.register(commonServicesProvider);\n if (enabledServices.http) this.register(httpServicesProvider);\n if (enabledServices.utils) this.register(utilsServicesProvider);\n\n this.set('events', () => new EventsHub());\n this.set('statuses', () => statuses);\n }\n /**\n * Configures the Express application based on the class options.\n */\n protected _setupExpress(): void {\n const { statics, filesizeLimit, express: expressOptions } = this._options;\n if (expressOptions.trustProxy) {\n this._express.enable('trust proxy');\n }\n\n if (expressOptions.disableXPoweredBy) {\n this._express.disable('x-powered-by');\n }\n\n if (expressOptions.compression) {\n this._express.use(compression());\n }\n\n if (statics.enabled) {\n this._addStaticsFolder(statics.route, statics.folder, statics.onHome);\n }\n\n if (expressOptions.bodyParser) {\n this._express.use(\n bodyParser.json({\n limit: filesizeLimit,\n }),\n );\n this._express.use(\n bodyParser.urlencoded({\n extended: true,\n limit: filesizeLimit,\n }),\n );\n }\n\n if (expressOptions.multer) {\n this._express.use(multer().any());\n }\n\n this.set(\n 'router',\n this.factory(() => express.Router()),\n );\n }\n /**\n * Adds a static folder to the application.\n *\n * @param route The route to add the folder to.\n * @param folder The path to the folder in the file system. If not defined, it will\n * be use the same value as `route`. The path could be relative to the\n * project root, or where the application executable is located,\n * depending on the value of the `onHome` parameter.\n * @param onHome If `true`, the path to the folder will be relative to the project\n * root. If `false`, it will be relative to where the application\n * executable is located.\n */\n protected _addStaticsFolder(\n route: string,\n folder: string = '',\n onHome: boolean = false,\n ) {\n const location = onHome ? 'home' : 'app';\n const staticRoute = route.replace(/^\\/+/, '');\n const pathUtils = this.get<PathUtils>('pathUtils');\n const staticFolder = pathUtils.joinFrom(location, folder || staticRoute);\n this.mount(`/${staticRoute}`, {\n connect: () => express.static(staticFolder),\n controller: true,\n });\n }\n /**\n * This helper method validates the `path` options in order to register the `app`\n * location in the `pathUtils` service. The `app` location should be the path to where\n * the application executable is located, but due to how ESM works, we can't infer it\n * from the `module` object, so we need either recieved as the `appPath` setting, or try\n * to get it from the parent module.\n *\n * @throws If the method should use the path from the parent module, but can't find\n * it.\n */\n protected _configurePath(): void {\n const pathUtils = this.get<PathUtils>('pathUtils');\n const {\n path: { appPath, useParentPath },\n } = this._options;\n if (appPath) {\n pathUtils.addLocation('app', appPath);\n return;\n }\n let foundPath = false;\n if (useParentPath) {\n const stack = new Error().stack!;\n const stackList = stack.split('\\n');\n stackList.shift();\n const parentFromStack = stackList.find((line) => !line.includes(__filename));\n if (parentFromStack) {\n const parentFile = parentFromStack.replace(/^.*?\\s\\(([^\\s]+):\\d+:\\d+\\)/, '$1');\n if (parentFile !== parentFromStack) {\n foundPath = true;\n pathUtils.addLocation('app', path.dirname(parentFile));\n }\n }\n }\n\n if (!foundPath) {\n throw new Error(\n 'The app location cannot be determined. Please specify the appPath option.',\n );\n }\n }\n /**\n * Setups the configuration service. The new configuration service requires async calls\n * in order to load the configuration files (as it uses `import` instead of `require`),\n * so it can't be instantiated as the other services.\n * This method is called just before starting the application.\n */\n protected async _setupConfig(): Promise<void> {\n if (this._configReady) return;\n this._configReady = true;\n const { config: options } = this._options;\n\n let configsPath = options.path.replace(/\\/$/, '');\n if (options.hasFolder) {\n configsPath = `${configsPath}${path.sep}${options.name}${path.sep}`;\n }\n\n const filenameFormat = options.filenameFormat\n .replace(/\\[app-name\\]/gi, options.name)\n .replace(/\\[config-name\\]/gi, '[name]');\n const defaultConfigFilename = options.defaultConfigFilename.replace(\n /\\[app-name\\]/gi,\n options.name,\n );\n\n this.register(\n simpleConfigProvider({\n name: options.name,\n defaultConfig: options.default,\n defaultConfigFilename,\n envVarName: options.environmentVariable,\n path: configsPath,\n filenameFormat,\n }),\n );\n\n const config = this.getConfig();\n await config.loadFromFile('', true, false);\n if (options.loadFromEnvironment) {\n await config.loadFromEnv();\n }\n }\n /**\n * Loads the ESM modules that are needed by Jimpex. This is called just before the starting\n * the application so they'll be available for all the services.\n */\n protected async _loadESMModules(): Promise<void> {\n const { default: nodeFetch } =\n await tsAsyncImport<typeof import('node-fetch')>('node-fetch');\n const { default: mime } = await tsAsyncImport<typeof import('mime')>('mime');\n\n this.set('node-fetch', () => nodeFetch);\n this.set('mime', () => mime);\n }\n /**\n * Processes the resources from the mount queue (added with {@link Jimpex.mount} and\n * {@link Jimpex.use}), and adds them to the Express application.\n */\n protected _mountResources(): void {\n this._mountQueue.forEach((mount) => mount(this._express));\n this._mountQueue.length = 0;\n }\n /**\n * Emits an event using the `events` service.\n *\n * @param name The name of the event to emit.\n * @param payload The event payload.\n * @template EventName The literal name of the event, to type the event payload.\n */\n protected _emitEvent<EventName extends JimpexEventName>(\n name: EventName,\n payload: JimpexEventPayload<EventName>,\n ): void {\n this.eventsHub.emit(name, payload);\n }\n /**\n * Sends a target object to a list of reducer events so they can modify or replace it.\n *\n * @param name The name of the event to use.\n * @param target The object to reduce with the event.\n * @param payload Extra context for the listeners.\n */\n protected _reduceWithEvent<EventName extends JimpexReducerEventName>(\n name: EventName,\n target: JimpexReducerEventTarget<EventName>,\n payload: JimpexReducerEventPayload<EventName>,\n ): JimpexReducerEventTarget<EventName> {\n return this.eventsHub.reduceSync(name, target, payload);\n }\n /**\n * Loads the contents of a dictionary of credentials files that need to be used to\n * configure HTTPS.\n *\n * @param credentialsInfo The dictionary where the keys are the type of credentials\n * (`ca`, `cert`, `key`) and the values are the paths to the\n * files.\n * @param onHome If this is `true`, the path of the files will be relative\n * to the project root. If it is `false`, it will be relative\n * to where the application executable is located.\n * @returns\n */\n protected async _loadCredentials(\n credentialsInfo: JimpexHTTPSCredentials,\n onHome: boolean = true,\n ): Promise<JimpexHTTPSCredentials> {\n const location = onHome ? 'home' : 'app';\n const pathUtils = this.get<PathUtils>('pathUtils');\n const keys: Array<keyof JimpexHTTPSCredentials> = ['ca', 'cert', 'key'];\n const info = await Promise.all(\n keys.map(async (key) => {\n const filepath = credentialsInfo[key];\n if (!filepath) return undefined;\n const file = await fs.readFile(pathUtils.joinFrom(location, filepath), 'utf8');\n return {\n key,\n file,\n };\n }),\n );\n\n return info.reduce<JimpexHTTPSCredentials>((acc, item) => {\n if (item) {\n acc[item.key] = item.file;\n }\n\n return acc;\n }, {});\n }\n /**\n * Validates the configuration and chooses the server the application needs to use: If\n * HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use\n * the native HTTPS server; otherwise, it will be just the Express instance.\n *\n * @returns {Server}\n * @throws {Error} If HTTP2 is enabled but HTTPS is not.\n * @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.\n * @throws {Error} If HTTPS is enabled and no creadentials are found.\n * @access protected\n * @ignore\n */\n protected async _createServer(): Promise<JimpexServer> {\n const [http2Config = {}, httpsConfig = {}] = this.getConfig<\n [JimpexHTTP2Options, JimpexHTTPSOptions]\n >(['http2', 'https'], true);\n\n if (!http2Config.enabled && !httpsConfig.enabled) {\n return this._express;\n }\n\n if (http2Config.enabled && !httpsConfig.enabled) {\n throw new Error('HTTP2 requires for HTTPS to be enabled');\n }\n\n if (!httpsConfig.credentials) {\n throw new Error('The `credentials` object on the HTTPS settings is missing');\n }\n\n const credentials = await this._loadCredentials(\n httpsConfig.credentials,\n httpsConfig.credentials.onHome,\n );\n\n if (!Object.keys(credentials).length) {\n throw new Error('No credentials were found for HTTPS');\n }\n\n if (http2Config.enabled) {\n const serverOptions: SpdyServerOptions = {\n ...credentials,\n spdy: http2Config.spdy,\n };\n\n return createSpdyServer(serverOptions, this._express);\n }\n\n return createHTTPSServer(credentials, this._express);\n }\n}\n/**\n * Shorthand for `new Jimpex()`.\n *\n * @param args The same parameters as the {@link Jimpex} constructor.\n * @returns A new instance of {@link Jimpex}.\n * @group Jimpex\n */\nexport const jimpex = (...args: ConstructorParameters<typeof Jimpex>): Jimpex =>\n new Jimpex(...args);\n"],"mappings":";;;AAAA,YAAY,UAAU;AACtB,OAAO,QAAQ;AACf,SAAS,gBAAgB,yBAAyB;AAClD,SAAS,cAAc;AACvB,SAAS,+BAA+B;AACxC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,2BAA2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MACpB;AAEA,aAAO,iBAAiB,eAAe,KAAK,QAAQ;AAAA,IACtD;AAEA,WAAO,kBAAkB,aAAa,KAAK,QAAQ;AAAA,EACrD;AACF;AAQO,MAAM,SAAS,IAAI,SACxB,IAAI,OAAO,GAAG,IAAI;","names":[]}
@@ -1,8 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
-
5
- export {
6
- __publicField
7
- };
8
- //# sourceMappingURL=chunk-V6TY7KAL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,80 +0,0 @@
1
- import {
2
- __publicField
3
- } from "../../chunk-V6TY7KAL.js";
4
- import { controller } from "../../utils";
5
- class ConfigController {
6
- /**
7
- * @param options The options to construct the controller.
8
- */
9
- constructor({ inject }) {
10
- /**
11
- * The service in charge or building the responses.
12
- */
13
- __publicField(this, "_responsesBuilder");
14
- /**
15
- * The service in charge of the configuration.
16
- */
17
- __publicField(this, "_config");
18
- this._responsesBuilder = inject.responsesBuilder;
19
- this._config = inject.config;
20
- }
21
- /**
22
- * Creates the middleware the shows the current configuration.
23
- */
24
- showConfig() {
25
- return (_, res) => {
26
- this.respondWithConfig(res);
27
- };
28
- }
29
- /**
30
- * Creates the middleware the allows to switch the configuration.
31
- */
32
- switchConfig() {
33
- return async (req, res, next) => {
34
- const { name } = req.params;
35
- if (!name || !this._config.canSwitchConfigs()) {
36
- next();
37
- return;
38
- }
39
- try {
40
- await this._config.switch(name);
41
- this.respondWithConfig(res);
42
- } catch (error) {
43
- next(error);
44
- }
45
- };
46
- }
47
- /**
48
- * Utility to respond with the current configuration.
49
- */
50
- respondWithConfig(res) {
51
- const name = this._config.get("name");
52
- const data = {
53
- name,
54
- ...this._config.getConfig()
55
- };
56
- this._responsesBuilder.json({
57
- res,
58
- data
59
- });
60
- }
61
- }
62
- const configController = controller((app) => {
63
- const config = app.getConfig();
64
- const router = app.getRouter();
65
- if (config.get("debug.configController") !== true) {
66
- return router;
67
- }
68
- const ctrl = new ConfigController({
69
- inject: {
70
- config,
71
- responsesBuilder: app.get("responsesBuilder")
72
- }
73
- });
74
- return router.get("/", ctrl.showConfig()).get("/switch/:name", ctrl.switchConfig());
75
- });
76
- export {
77
- ConfigController,
78
- configController
79
- };
80
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/controllers/common/config.ts"],"sourcesContent":["import { controller } from '../../utils';\nimport type { ResponsesBuilder } from '../../services';\nimport type {\n Config,\n Response,\n AsyncExpressMiddleware,\n ExpressMiddleware,\n} from '../../types';\n/**\n * The options to contruct a {@link ConfigController}.\n *\n * @group Controllers/Config\n */\nexport type ConfigControllerOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n responsesBuilder: ResponsesBuilder;\n config: Config;\n };\n};\n/**\n * The controller class that allows to show and switch the application configuration.\n *\n * @group Controller Classes\n * @group Controllers/Config\n * @prettierignore\n */\nexport class ConfigController {\n /**\n * The service in charge or building the responses.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The service in charge of the configuration.\n */\n protected readonly _config: Config;\n /**\n * @param options The options to construct the controller.\n */\n constructor({ inject }: ConfigControllerOptions) {\n this._responsesBuilder = inject.responsesBuilder;\n this._config = inject.config;\n }\n /**\n * Creates the middleware the shows the current configuration.\n */\n showConfig(): ExpressMiddleware {\n return (_, res) => {\n this.respondWithConfig(res);\n };\n }\n /**\n * Creates the middleware the allows to switch the configuration.\n */\n switchConfig(): AsyncExpressMiddleware {\n return async (req, res, next) => {\n const { name } = req.params;\n if (!name || !this._config.canSwitchConfigs()) {\n next();\n return;\n }\n\n try {\n await this._config.switch(name);\n this.respondWithConfig(res);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * Utility to respond with the current configuration.\n */\n protected respondWithConfig(res: Response): void {\n const name = this._config.get<string>('name');\n const data = {\n name,\n ...this._config.getConfig<Record<string, unknown>>(),\n };\n\n this._responsesBuilder.json({\n res,\n data,\n });\n }\n}\n/**\n * This controller is kind of special as it will only mount the routes if the\n * `debug.configController` setting of the app configuration is set to `true`.\n *\n * It provides routes for:\n * - `/`: Showing the current configuration.\n * - `/switch/:name`: Switching the configuration, but only if the service allows it.\n *\n * @group Controllers\n * @group Controllers/Config\n */\nexport const configController = controller((app) => {\n const config = app.getConfig();\n const router = app.getRouter();\n if (config.get<boolean | undefined>('debug.configController') !== true) {\n return router;\n }\n\n const ctrl = new ConfigController({\n inject: {\n config,\n responsesBuilder: app.get('responsesBuilder'),\n },\n });\n\n return router.get('/', ctrl.showConfig()).get('/switch/:name', ctrl.switchConfig());\n});\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AA6BpB,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAY5B,YAAY,EAAE,OAAO,GAA4B;AARjD;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,oBAAoB,OAAO;AAChC,SAAK,UAAU,OAAO;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA,EAIA,aAAgC;AAC9B,WAAO,CAAC,GAAG,QAAQ;AACjB,WAAK,kBAAkB,GAAG;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,eAAuC;AACrC,WAAO,OAAO,KAAK,KAAK,SAAS;AAC/B,YAAM,EAAE,KAAK,IAAI,IAAI;AACrB,UAAI,CAAC,QAAQ,CAAC,KAAK,QAAQ,iBAAiB,GAAG;AAC7C,aAAK;AACL;AAAA,MACF;AAEA,UAAI;AACF,cAAM,KAAK,QAAQ,OAAO,IAAI;AAC9B,aAAK,kBAAkB,GAAG;AAAA,MAC5B,SAAS,OAAO;AACd,aAAK,KAAK;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIU,kBAAkB,KAAqB;AAC/C,UAAM,OAAO,KAAK,QAAQ,IAAY,MAAM;AAC5C,UAAM,OAAO;AAAA,MACX;AAAA,MACA,GAAG,KAAK,QAAQ,UAAmC;AAAA,IACrD;AAEA,SAAK,kBAAkB,KAAK;AAAA,MAC1B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAYO,MAAM,mBAAmB,WAAW,CAAC,QAAQ;AAClD,QAAM,SAAS,IAAI,UAAU;AAC7B,QAAM,SAAS,IAAI,UAAU;AAC7B,MAAI,OAAO,IAAyB,wBAAwB,MAAM,MAAM;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,IAAI,iBAAiB;AAAA,IAChC,QAAQ;AAAA,MACN;AAAA,MACA,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,IAC9C;AAAA,EACF,CAAC;AAED,SAAO,OAAO,IAAI,KAAK,KAAK,WAAW,CAAC,EAAE,IAAI,iBAAiB,KAAK,aAAa,CAAC;AACpF,CAAC;","names":[]}
@@ -1,88 +0,0 @@
1
- import {
2
- __publicField
3
- } from "../../chunk-V6TY7KAL.js";
4
- import { controller } from "../../utils";
5
- class HealthController {
6
- /**
7
- * @param options The options to construct the controller.
8
- */
9
- constructor({ inject }) {
10
- /**
11
- * The function that returns the health status of the application.
12
- */
13
- __publicField(this, "_getHealthStatus");
14
- /**
15
- * The service in charge or building the responses.
16
- */
17
- __publicField(this, "_responsesBuilder");
18
- /**
19
- * The service in charge of the configuration.
20
- */
21
- __publicField(this, "_config");
22
- /**
23
- * The uility service to get HTTP status codes.
24
- */
25
- __publicField(this, "_statuses");
26
- this._getHealthStatus = inject.getHealthStatus;
27
- this._responsesBuilder = inject.responsesBuilder;
28
- this._config = inject.config;
29
- this._statuses = inject.statuses;
30
- }
31
- /**
32
- * Creates the middleware the shows the application health status.
33
- */
34
- showHealth() {
35
- return async (_, res) => {
36
- const healthStatus = await this._getHealthStatus();
37
- let isHealthy;
38
- let extras;
39
- if (typeof healthStatus === "boolean") {
40
- isHealthy = healthStatus;
41
- extras = {};
42
- } else {
43
- if (typeof healthStatus.isHealthy === "boolean") {
44
- isHealthy = healthStatus.isHealthy;
45
- } else if (healthStatus.services) {
46
- isHealthy = Object.values(healthStatus.services).every(
47
- (value) => value === true
48
- );
49
- } else {
50
- isHealthy = true;
51
- }
52
- extras = {
53
- ...healthStatus.services
54
- };
55
- }
56
- const { name: config, version } = this._config.get(["name", "version"]);
57
- const status = isHealthy ? this._statuses("ok") : this._statuses("service unavailable");
58
- this._responsesBuilder.json({
59
- res,
60
- status,
61
- data: {
62
- isHealthy,
63
- status,
64
- config,
65
- version,
66
- ...extras
67
- }
68
- });
69
- };
70
- }
71
- }
72
- const healthController = controller((app) => {
73
- const router = app.getRouter();
74
- const ctrl = new HealthController({
75
- inject: {
76
- getHealthStatus: app.isHealthy.bind(app),
77
- responsesBuilder: app.get("responsesBuilder"),
78
- config: app.get("config"),
79
- statuses: app.get("statuses")
80
- }
81
- });
82
- return router.get("/", ctrl.showHealth());
83
- });
84
- export {
85
- HealthController,
86
- healthController
87
- };
88
- //# sourceMappingURL=health.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/controllers/common/health.ts"],"sourcesContent":["import { controller, type Statuses } from '../../utils';\nimport type { ResponsesBuilder } from '../../services';\nimport type { JimpexHealthStatus, Config, AsyncExpressMiddleware } from '../../types';\n/**\n * A function that will return the health status of the application.\n *\n * @group Controllers/Health\n */\nexport type GetHealthStatus = () => Promise<JimpexHealthStatus>;\n/**\n * The options to contruct a {@link HealthController}.\n *\n * @group Controllers/Health\n */\nexport type HealthControllerOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n getHealthStatus: GetHealthStatus;\n responsesBuilder: ResponsesBuilder;\n config: Config;\n statuses: Statuses;\n };\n};\n/**\n * The controller class that shows the application health status.\n *\n * @group Controller Classes\n * @group Controllers/Health\n * @prettierignore\n */\nexport class HealthController {\n /**\n * The function that returns the health status of the application.\n */\n protected readonly _getHealthStatus: GetHealthStatus;\n /**\n * The service in charge or building the responses.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The service in charge of the configuration.\n */\n protected readonly _config: Config;\n /**\n * The uility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * @param options The options to construct the controller.\n */\n constructor({ inject }: HealthControllerOptions) {\n this._getHealthStatus = inject.getHealthStatus;\n this._responsesBuilder = inject.responsesBuilder;\n this._config = inject.config;\n this._statuses = inject.statuses;\n }\n /**\n * Creates the middleware the shows the application health status.\n */\n showHealth(): AsyncExpressMiddleware {\n return async (_, res) => {\n const healthStatus = await this._getHealthStatus();\n let isHealthy: boolean;\n let extras: Record<string, unknown>;\n if (typeof healthStatus === 'boolean') {\n isHealthy = healthStatus;\n extras = {};\n } else {\n if (typeof healthStatus.isHealthy === 'boolean') {\n isHealthy = healthStatus.isHealthy;\n } else if (healthStatus.services) {\n isHealthy = Object.values(healthStatus.services).every(\n (value) => value === true,\n );\n } else {\n isHealthy = true;\n }\n\n extras = {\n ...healthStatus.services,\n };\n }\n\n const { name: config, version } = this._config.get<{\n name: string;\n version: string;\n }>(['name', 'version']);\n\n const status = isHealthy\n ? this._statuses('ok')\n : this._statuses('service unavailable');\n\n this._responsesBuilder.json({\n res,\n status,\n data: {\n isHealthy,\n status,\n config,\n version,\n ...extras,\n },\n });\n };\n }\n}\n/**\n * The controller that once mounted, it will add an endpoint to show the application\n * health status.\n *\n * @group Controllers\n * @group Controllers/Health\n */\nexport const healthController = controller((app) => {\n const router = app.getRouter();\n const ctrl = new HealthController({\n inject: {\n getHealthStatus: app.isHealthy.bind(app),\n responsesBuilder: app.get('responsesBuilder'),\n config: app.get('config'),\n statuses: app.get('statuses'),\n },\n });\n\n return router.get('/', ctrl.showHealth());\n});\n"],"mappings":";;;AAAA,SAAS,kBAAiC;AAgCnC,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EA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AAAA,MACN,iBAAiB,IAAI,UAAU,KAAK,GAAG;AAAA,MACvC,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,MAC5C,QAAQ,IAAI,IAAI,QAAQ;AAAA,MACxB,UAAU,IAAI,IAAI,UAAU;AAAA,IAC9B;AAAA,EACF,CAAC;AAED,SAAO,OAAO,IAAI,KAAK,KAAK,WAAW,CAAC;AAC1C,CAAC;","names":[]}
@@ -1,4 +0,0 @@
1
- export * from "./config";
2
- export * from "./health";
3
- export * from "./statics";
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/controllers/common/index.ts"],"sourcesContent":["export * from './config';\nexport * from './health';\nexport * from './statics';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,226 +0,0 @@
1
- import {
2
- __publicField
3
- } from "../../chunk-V6TY7KAL.js";
4
- import * as path from "path";
5
- import { deepAssignWithOverwrite } from "@homer0/deep-assign";
6
- import {
7
- controllerCreator,
8
- removeSlashes,
9
- notUndefined
10
- } from "../../utils";
11
- class StaticsController {
12
- /**
13
- * @param options The options to construct the controller.
14
- */
15
- constructor({ inject, ...options }) {
16
- /**
17
- * The service that serves static files.
18
- */
19
- __publicField(this, "_sendFile");
20
- /**
21
- * The MIME type library. Since it's an ESM only module, Jimpex loads it on boot and makes
22
- * it available on the container.
23
- */
24
- __publicField(this, "_mime");
25
- /**
26
- * The controller customization options.
27
- */
28
- __publicField(this, "_options");
29
- /**
30
- * A dictionary with the formatted definitions of the files that will be served.
31
- * It uses the files' routes as keys, for easy access in the middleware.
32
- */
33
- __publicField(this, "files");
34
- this._sendFile = inject.sendFile;
35
- this._mime = inject.mime;
36
- this._options = this._validateOptions(
37
- deepAssignWithOverwrite(
38
- {
39
- files: ["favicon.ico", "index.html"],
40
- methods: options.methods || {
41
- all: false,
42
- get: true
43
- },
44
- paths: {
45
- route: "",
46
- source: "./"
47
- }
48
- },
49
- options
50
- )
51
- );
52
- this.files = this._createFiles();
53
- }
54
- /**
55
- * Mounts the middlewares in the router in order to serve the files.
56
- *
57
- * @param router A reference to the application router.
58
- * @param middlewares A list of extra middlewares to execute before the file
59
- * middleware.
60
- */
61
- addRoutes(router, middlewares = []) {
62
- const { methods } = this._options;
63
- const use = methods.all ? ["all"] : Object.keys(methods).reduce((acc, name) => {
64
- const methodName = name;
65
- if (methods[methodName]) {
66
- acc.push(methodName);
67
- }
68
- return acc;
69
- }, []);
70
- Object.keys(this.files).forEach((route) => {
71
- const file = this.files[route];
72
- const fileMiddleware = this._getMiddleware(file);
73
- use.forEach(
74
- (method) => this._addRoute({ router, method, file, fileMiddleware, middlewares })
75
- );
76
- });
77
- return router;
78
- }
79
- /**
80
- * The controller options.
81
- */
82
- get options() {
83
- return { ...this._options };
84
- }
85
- /**
86
- * Generates the middleware that will serve the file.
87
- *
88
- * @param file The definition of the file to serve.
89
- */
90
- _getMiddleware(file) {
91
- return (_, res, next) => {
92
- const extension = path.parse(file.path).ext.substring(1);
93
- const headers = {
94
- "Content-Type": this._mime.getType(extension) || "text/html",
95
- ...file.headers
96
- };
97
- Object.entries(headers).forEach(([key, value]) => {
98
- res.setHeader(key, value);
99
- });
100
- this._sendFile({
101
- res,
102
- filepath: file.path,
103
- next
104
- });
105
- };
106
- }
107
- /**
108
- * Mounts the middleware(s) for a file in the router.
109
- *
110
- * @param options The information of the file and how it needs to be added.
111
- */
112
- _addRoute({
113
- router,
114
- method,
115
- file,
116
- fileMiddleware,
117
- middlewares
118
- }) {
119
- const { route } = file;
120
- router[method](route, [...middlewares, fileMiddleware]);
121
- }
122
- /**
123
- * Validates and formats the options sent to the constructor in order to get the final
124
- * set that will be stored in the controller.
125
- *
126
- * @param options The options to validate.
127
- * @throws If no files are specified.
128
- * @throws If methods is not defined.
129
- * @throws If no methods are enabled.
130
- * @throws If there's an invalid HTTP method.
131
- */
132
- _validateOptions(options) {
133
- if (!options.files || !options.files.length) {
134
- throw new Error("You need to specify a list of files");
135
- }
136
- if (!options.methods) {
137
- throw new Error("You need to specify which HTTP methods are allowed for the files");
138
- }
139
- const methods = Object.keys(options.methods);
140
- const atLeastOne = methods.some((method) => options.methods[method]);
141
- if (!atLeastOne) {
142
- throw new Error("You need to enable at least one HTTP method to serve the files");
143
- }
144
- const allowedMethods = [
145
- "all",
146
- "get",
147
- "head",
148
- "post",
149
- "patch",
150
- "put",
151
- "delete",
152
- "connect",
153
- "options",
154
- "trace"
155
- ];
156
- const invalid = methods.find(
157
- (method) => !allowedMethods.includes(method.toLowerCase())
158
- );
159
- if (invalid) {
160
- throw new Error(`${invalid} is not a valid HTTP method`);
161
- }
162
- const newMethods = methods.reduce((acc, method) => {
163
- acc[method.toLowerCase()] = !!options.methods[method];
164
- return acc;
165
- }, {});
166
- return {
167
- ...options,
168
- methods: newMethods
169
- };
170
- }
171
- /**
172
- * Parses the files received from the constructor's options, and formats them into
173
- * proper definitions the controller can use.
174
- */
175
- _createFiles() {
176
- const { files, paths } = this._options;
177
- const routePath = removeSlashes(paths.route, false, true);
178
- return files.reduce((acc, file) => {
179
- let src;
180
- let route;
181
- let headers;
182
- if (typeof file === "object") {
183
- ({ route, path: src, headers } = file);
184
- } else {
185
- src = file;
186
- route = file;
187
- }
188
- src = path.join(paths.source, src);
189
- route = removeSlashes(route, true, false);
190
- route = `${routePath}/${route}`;
191
- acc[route] = {
192
- path: src,
193
- route,
194
- headers: headers || {}
195
- };
196
- return acc;
197
- }, {});
198
- }
199
- }
200
- const staticsController = controllerCreator(
201
- ({ getMiddlewares, ...options } = {}) => (app) => {
202
- const router = app.getRouter();
203
- const ctrl = new StaticsController({
204
- inject: {
205
- sendFile: app.get("sendFile"),
206
- mime: app.get("mime")
207
- },
208
- ...options
209
- });
210
- let useMiddlewares;
211
- if (getMiddlewares) {
212
- useMiddlewares = getMiddlewares(app).map((middleware) => {
213
- if ("middleware" in middleware) {
214
- return middleware.connect(app);
215
- }
216
- return middleware;
217
- }).filter(notUndefined);
218
- }
219
- return ctrl.addRoutes(router, useMiddlewares);
220
- }
221
- );
222
- export {
223
- StaticsController,
224
- staticsController
225
- };
226
- //# sourceMappingURL=statics.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/controllers/common/statics.ts"],"sourcesContent":["import * as path from 'path';\nimport type mime from 'mime';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport {\n controllerCreator,\n removeSlashes,\n notUndefined,\n type MiddlewareLike,\n} from '../../utils';\nimport type { SendFile } from '../../services';\nimport type { Jimpex } from '../../app';\nimport type { DeepPartial, ExpressMiddleware, Router, RouterMethod } from '../../types';\n\ntype Mime = typeof mime;\n\n/**\n * The definition for each file the controller handles.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerFile = {\n /**\n * The route, relative to the controller root, to the file.\n */\n route: string;\n /**\n * The path to the file in the filesystem. Since the file is served using the\n * {@link SendFile} service, whether the file is relative to the project root or the\n * application executable depends on how the service is configured (relative to the\n * executable by default).\n */\n path: string;\n /**\n * A dictionary of headers for the response.\n */\n headers?: Record<string, string>;\n};\n/**\n * These are like \"master paths\" that get prepended to all the file paths and routes the\n * controller use.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerPathsOptions = {\n /**\n * A custom route to prefix all the file routes with.\n */\n route: string;\n /**\n * A custom path to prefix all the file paths with.\n */\n source: string;\n};\n/**\n * The options to customize the controller.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerOptions = {\n /**\n * A list of filenames, or definitions for the files to handle.\n */\n files: Array<string | StaticsControllerFile>;\n /**\n * A dictionary with the allowed router (HTTP) methods the controller can use to serve\n * the files. If `all` is set to `true`, the rest of the values will be ignored.\n *\n * @default {get: true, all: false}\n */\n methods: Partial<Record<RouterMethod, boolean>>;\n /**\n * The \"master paths\" the controller can use to prefix the file paths and routes.\n *\n * @default {route: '', source: './',}\n */\n paths: StaticsControllerPathsOptions;\n};\n/**\n * The options to construct a {@link StaticsController}.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerConstructorOptions =\n DeepPartial<StaticsControllerOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n mime: Mime;\n };\n };\n/**\n * A function to generate a list of middlewares that can be executed before the tontroller\n * main middleware.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerGetMiddlewaresFn = (app: Jimpex) => MiddlewareLike[];\n/**\n * The options for the controller creator that mounts {@link StaticsController}.\n *\n * @group Controllers/Statics\n */\nexport type StaticsControllerCreatorOptions = DeepPartial<StaticsControllerOptions> & {\n /**\n * A function to generate a list of middlewares that can be executed before the\n * tontroller main middleware.\n */\n getMiddlewares?: StaticsControllerGetMiddlewaresFn;\n};\n/**\n * The options for {@link StaticsController._addRoute}.\n *\n * @access protected\n * @group Controllers/Statics\n */\nexport type AddStaticRouteOptions = {\n /**\n * The reference for the router in which the middlewares will be added.\n */\n router: Router;\n /**\n * The router method in which the middlewares will be added.\n */\n method: RouterMethod;\n /**\n * The definition of the file to serve.\n */\n file: StaticsControllerFile;\n /**\n * The middleware created by {@link StaticsController}, that will serve the file.\n */\n fileMiddleware: ExpressMiddleware;\n /**\n * A list of extra middlewares to execute before the file middleware.\n */\n middlewares: ExpressMiddleware[];\n};\n\n/**\n * The controller class that allows the application to serve specific files from any\n * folder to any route without the need of mounting directories as \"static\".\n *\n * @group Controller Classes\n * @group Controllers/Statics\n * @prettierignore\n */\nexport class StaticsController {\n /**\n * The service that serves static files.\n */\n protected readonly _sendFile: SendFile;\n /**\n * The MIME type library. Since it's an ESM only module, Jimpex loads it on boot and makes\n * it available on the container.\n */\n protected readonly _mime: Mime;\n /**\n * The controller customization options.\n */\n protected _options: StaticsControllerOptions;\n /**\n * A dictionary with the formatted definitions of the files that will be served.\n * It uses the files' routes as keys, for easy access in the middleware.\n */\n protected files: Record<string, StaticsControllerFile>;\n /**\n * @param options The options to construct the controller.\n */\n constructor({ inject, ...options }: StaticsControllerConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._mime = inject.mime;\n this._options = this._validateOptions(\n deepAssignWithOverwrite(\n {\n files: ['favicon.ico', 'index.html'],\n methods: options.methods || {\n all: false,\n get: true,\n },\n paths: {\n route: '',\n source: './',\n },\n },\n options,\n ),\n );\n this.files = this._createFiles();\n }\n /**\n * Mounts the middlewares in the router in order to serve the files.\n *\n * @param router A reference to the application router.\n * @param middlewares A list of extra middlewares to execute before the file\n * middleware.\n */\n addRoutes(router: Router, middlewares: ExpressMiddleware[] = []): Router {\n const { methods } = this._options;\n const use: RouterMethod[] = methods.all\n ? ['all']\n : Object.keys(methods).reduce<RouterMethod[]>((acc, name) => {\n const methodName = name as RouterMethod;\n if (methods[methodName]) {\n acc.push(methodName);\n }\n\n return acc;\n }, []);\n\n Object.keys(this.files).forEach((route) => {\n const file = this.files[route as keyof typeof this.files]!;\n const fileMiddleware = this._getMiddleware(file);\n use.forEach((method) =>\n this._addRoute({ router, method, file, fileMiddleware, middlewares }),\n );\n });\n\n return router;\n }\n /**\n * The controller options.\n */\n get options(): Readonly<StaticsControllerOptions> {\n return { ...this._options };\n }\n /**\n * Generates the middleware that will serve the file.\n *\n * @param file The definition of the file to serve.\n */\n protected _getMiddleware(file: StaticsControllerFile): ExpressMiddleware {\n return (_, res, next) => {\n const extension = path.parse(file.path).ext.substring(1);\n const headers = {\n 'Content-Type': this._mime.getType(extension) || 'text/html',\n ...file.headers,\n };\n\n Object.entries(headers).forEach(([key, value]) => {\n res.setHeader(key, value);\n });\n\n this._sendFile({\n res,\n filepath: file.path,\n next,\n });\n };\n }\n /**\n * Mounts the middleware(s) for a file in the router.\n *\n * @param options The information of the file and how it needs to be added.\n */\n protected _addRoute({\n router,\n method,\n file,\n fileMiddleware,\n middlewares,\n }: AddStaticRouteOptions): void {\n const { route } = file;\n router[method](route, [...middlewares, fileMiddleware]);\n }\n /**\n * Validates and formats the options sent to the constructor in order to get the final\n * set that will be stored in the controller.\n *\n * @param options The options to validate.\n * @throws If no files are specified.\n * @throws If methods is not defined.\n * @throws If no methods are enabled.\n * @throws If there's an invalid HTTP method.\n */\n protected _validateOptions(\n options: StaticsControllerOptions,\n ): StaticsControllerOptions {\n if (!options.files || !options.files.length) {\n throw new Error('You need to specify a list of files');\n }\n\n if (!options.methods) {\n throw new Error('You need to specify which HTTP methods are allowed for the files');\n }\n\n const methods = Object.keys(options.methods) as RouterMethod[];\n\n const atLeastOne = methods.some((method) => options.methods[method]);\n if (!atLeastOne) {\n throw new Error('You need to enable at least one HTTP method to serve the files');\n }\n\n const allowedMethods: RouterMethod[] = [\n 'all',\n 'get',\n 'head',\n 'post',\n 'patch',\n 'put',\n 'delete',\n 'connect',\n 'options',\n 'trace',\n ];\n\n const invalid = methods.find(\n (method) => !allowedMethods.includes(method.toLowerCase() as RouterMethod),\n );\n\n if (invalid) {\n throw new Error(`${invalid} is not a valid HTTP method`);\n }\n\n const newMethods = methods.reduce<Record<string, boolean>>((acc, method) => {\n acc[method.toLowerCase()] = !!options.methods[method];\n return acc;\n }, {});\n\n return {\n ...options,\n methods: newMethods,\n };\n }\n /**\n * Parses the files received from the constructor's options, and formats them into\n * proper definitions the controller can use.\n */\n protected _createFiles(): Record<string, StaticsControllerFile> {\n const { files, paths } = this._options;\n const routePath = removeSlashes(paths.route, false, true);\n return files.reduce<Record<string, StaticsControllerFile>>((acc, file) => {\n let src;\n let route;\n let headers;\n if (typeof file === 'object') {\n ({ route, path: src, headers } = file);\n } else {\n src = file;\n route = file;\n }\n\n src = path.join(paths.source, src);\n route = removeSlashes(route, true, false);\n route = `${routePath}/${route}`;\n acc[route] = {\n path: src,\n route,\n headers: headers || {},\n };\n\n return acc;\n }, {});\n }\n}\n/**\n * A controller that allows the application to server specific files from any folder to\n * any route without the need of mounting directories as \"static\" folders.\n *\n * @group Controllers\n * @group Controllers/Statics\n */\nexport const staticsController = controllerCreator(\n ({ getMiddlewares, ...options }: StaticsControllerCreatorOptions = {}) =>\n (app) => {\n const router = app.getRouter();\n const ctrl = new StaticsController({\n inject: {\n sendFile: app.get('sendFile'),\n mime: app.get('mime'),\n },\n ...options,\n });\n\n let useMiddlewares: ExpressMiddleware[] | undefined;\n if (getMiddlewares) {\n useMiddlewares = getMiddlewares(app)\n .map((middleware) => {\n if ('middleware' in middleware) {\n return middleware.connect(app) as ExpressMiddleware | undefined;\n }\n\n return middleware as ExpressMiddleware;\n })\n .filter(notUndefined);\n }\n\n return ctrl.addRoutes(router, useMiddlewares);\n },\n);\n"],"mappings":";;;AAAA,YAAY,UAAU;AAEtB,SAAS,+BAA+B;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA4IA,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAsB7B,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAAwC;AAlBzE;AAAA;AAAA;AAAA,wBAAmB;AAKnB;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAU;AAKV;AAAA;AAAA;AAAA;AAAA,wBAAU;AAKR,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO;AACpB,SAAK,WAAW,KAAK;AAAA,MACnB;AAAA,QACE;AAAA,UACE,OAAO,CAAC,eAAe,YAAY;AAAA,UACnC,SAAS,QAAQ,WAAW;AAAA,YAC1B,KAAK;AAAA,YACL,KAAK;AAAA,UACP;AAAA,UACA,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,SAAK,QAAQ,KAAK,aAAa;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,QAAgB,cAAmC,CAAC,GAAW;AACvE,UAAM,EAAE,QAAQ,IAAI,KAAK;AACzB,UAAM,MAAsB,QAAQ,MAChC,CAAC,KAAK,IACN,OAAO,KAAK,OAAO,EAAE,OAAuB,CAAC,KAAK,SAAS;AACzD,YAAM,aAAa;AACnB,UAAI,QAAQ,UAAU,GAAG;AAC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ACN,gBAAQ;AAAA,MACV;AAEA,YAAM,KAAK,KAAK,MAAM,QAAQ,GAAG;AACjC,cAAQ,cAAc,OAAO,MAAM,KAAK;AACxC,cAAQ,GAAG,SAAS,IAAI,KAAK;AAC7B,UAAI,KAAK,IAAI;AAAA,QACX,MAAM;AAAA,QACN;AAAA,QACA,SAAS,WAAW,CAAC;AAAA,MACvB;AAEA,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,EACP;AACF;AAQO,MAAM,oBAAoB;AAAA,EAC/B,CAAC,EAAE,gBAAgB,GAAG,QAAQ,IAAqC,CAAC,MAClE,CAAC,QAAQ;AACP,UAAM,SAAS,IAAI,UAAU;AAC7B,UAAM,OAAO,IAAI,kBAAkB;AAAA,MACjC,QAAQ;AAAA,QACN,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,MAAM,IAAI,IAAI,MAAM;AAAA,MACtB;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AAED,QAAI;AACJ,QAAI,gBAAgB;AAClB,uBAAiB,eAAe,GAAG,EAChC,IAAI,CAAC,eAAe;AACnB,YAAI,gBAAgB,YAAY;AAC9B,iBAAO,WAAW,QAAQ,GAAG;AAAA,QAC/B;AAEA,eAAO;AAAA,MACT,CAAC,EACA,OAAO,YAAY;AAAA,IACxB;AAEA,WAAO,KAAK,UAAU,QAAQ,cAAc;AAAA,EAC9C;AACJ;","names":[]}
@@ -1,3 +0,0 @@
1
- export * from "./common";
2
- export * from "./utils";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/controllers/index.ts"],"sourcesContent":["export * from './common';\nexport * from './utils';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}