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,1287 +0,0 @@
1
- import { ExpressMiddlewareLike } from './types/express.mjs';
2
- import { JimpexServer, JimpexServerInstance, JimpexHTTPSCredentials } from './types/http.mjs';
3
- import { NoStringIndex, DeepPartial, DeepReadonly } from './types/utils.mjs';
4
- import '@homer0/path-utils';
5
- import { SimpleLogger } from '@homer0/simple-logger';
6
- import { SimpleConfig } from '@homer0/simple-config';
7
- import { EventsHub } from '@homer0/events-hub';
8
- import { Router, Express } from 'express';
9
- import 'node-fetch';
10
- import 'https';
11
- import 'http';
12
- import * as _homer0_jimple from '@homer0/jimple';
13
- import { ProviderRegisterFn as ProviderRegisterFn$1, GenericCurriedFn, Jimple } from '@homer0/jimple';
14
-
15
- /**
16
- * The base payload the events emitted by the application send.
17
- *
18
- * @template T Extra properties beside the reference to the application.
19
- * @group Services/Events
20
- */
21
- type EventPayload<T = Record<string, unknown>> = {
22
- /**
23
- * A reference to the application.
24
- */
25
- app: Jimpex;
26
- } & T;
27
- /**
28
- * A dictionary with the events emitted by the application and their payloads.
29
- *
30
- * @group Services/Events
31
- */
32
- interface JimpexEvents {
33
- /**
34
- * Called right before creating the server and calling `listen` on it.
35
- */
36
- beforeStart: EventPayload;
37
- /**
38
- * Called once the server confirmed that is listening.
39
- */
40
- start: EventPayload;
41
- /**
42
- * Called after the controllers and middlewares have been mounted.
43
- */
44
- afterStart: EventPayload;
45
- /**
46
- * Called after the `onStart` callback has been called.
47
- */
48
- afterStartCallback: EventPayload;
49
- /**
50
- * Called before closing the server instance.
51
- */
52
- beforeStop: EventPayload;
53
- /**
54
- * Called after the server instance has been closed.
55
- */
56
- afterStop: EventPayload;
57
- /**
58
- * Called every time a new route is mounted in the application.
59
- */
60
- routeAdded: EventPayload<{
61
- route: string;
62
- }>;
63
- }
64
- /**
65
- * The events emitted by the application.
66
- *
67
- * @group Services/Events
68
- */
69
- type JimpexEventName = keyof JimpexEvents;
70
- /**
71
- * The type of the payload sent by a specific event.
72
- *
73
- * @template EventName The literal type of the event, to obtain the type of the
74
- * payload.
75
- * @group Services/Events
76
- */
77
- type JimpexEventPayload<EventName extends JimpexEventName> = JimpexEvents[EventName];
78
- /**
79
- * A dictionary of the reducer events and their targets.
80
- *
81
- * @group Services/Events
82
- */
83
- interface JimpexReducerEventTargets {
84
- /**
85
- * It gets called before mounting a router/middleware for a specific route.
86
- */
87
- controllerWillBeMounted: Router | ExpressMiddlewareLike;
88
- /**
89
- * It gets called before using a middleware without route.
90
- */
91
- middlewareWillBeUsed: ExpressMiddlewareLike;
92
- }
93
- /**
94
- * A dictionary of the payloads the reducer events the application uses.
95
- *
96
- * @group Services/Events
97
- */
98
- interface JimpexReducerEventPayloads {
99
- /**
100
- * It gets called before mounting a router/middleware for a specific route.
101
- */
102
- controllerWillBeMounted: EventPayload<{
103
- /**
104
- * The route in which the controller will be mounted.
105
- */
106
- route: string;
107
- /**
108
- * A reference for the controller/middleware before being "connected".
109
- */
110
- controller: Controller | Middleware;
111
- }>;
112
- /**
113
- * It gets called before using a middleware without route.
114
- */
115
- middlewareWillBeUsed: EventPayload;
116
- }
117
- /**
118
- * The reducer events used by the application.
119
- *
120
- * @group Services/Events
121
- */
122
- type JimpexReducerEventName = keyof JimpexReducerEventTargets;
123
- /**
124
- * The type of the target of a specific reducer event.
125
- *
126
- * @template EventName The literal type of the event, to obtain the type of the
127
- * target.
128
- * @group Services/Events
129
- */
130
- type JimpexReducerEventTarget<EventName extends JimpexReducerEventName> = JimpexReducerEventTargets[EventName];
131
- /**
132
- * The type of the payload of a specific reducer event.
133
- *
134
- * @template EventName The literal type of the event, to obtain the type of the
135
- * payload.
136
- * @group Services/Events
137
- */
138
- type JimpexReducerEventPayload<EventName extends JimpexReducerEventName> = JimpexReducerEventPayloads[EventName];
139
- /**
140
- * The name of the events o reducer events emitted/used by the application.
141
- * This generic type exists because the listener for both types are added using the same
142
- * method.
143
- *
144
- * @group Services/Events
145
- */
146
- type JimpexEventNameLike = JimpexEventName | JimpexReducerEventName;
147
- /**
148
- * The definition of a listener for an event or a reducer event.
149
- *
150
- * @template EventName The literal type of the event, to validate whether the
151
- * parameters should be for a reducer event or an event.
152
- * @group Services/Events
153
- */
154
- type JimpexEventListener<EventName extends JimpexEventNameLike> = EventName extends JimpexEventName ? (payload: JimpexEventPayload<EventName>) => void : EventName extends JimpexReducerEventName ? (target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => JimpexReducerEventTarget<EventName> : never;
155
- /**
156
- * The `events` service Jimpex uses.
157
- * This is an alternative declaration of the `EventsHub` class that uses the interfaces
158
- * and types from this project.
159
- *
160
- * @group Services
161
- * @group Services/Events
162
- */
163
- type Events = {
164
- /**
165
- * Adds a new event listener.
166
- *
167
- * @param event The name of the event.
168
- * @param listener The listener function.
169
- * @returns An unsubscribe function to remove the listener.
170
- * @template EventName The literal type of the event, to generate the type of the
171
- * listener.
172
- * @example
173
- *
174
- * const unsubscribe = events.on('afterStart', ({ app }) => {
175
- * app.getLogger().info('Hello world!');
176
- * unsubscribe();
177
- * });
178
- *
179
- */
180
- on: <EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>) => () => boolean;
181
- /**
182
- * Adds an event listener that will only be executed once.
183
- *
184
- * @param event The name of the event.
185
- * @param listener The listener function.
186
- * @returns An unsubscribe function to remove the listener.
187
- * @template EventName The literal type of the event, to generate the type of the
188
- * listener.
189
- * @example
190
- *
191
- * events.once('afterStart', ({ app }) => {
192
- * app.getLogger().info('Hello world!');
193
- * unsubscribe();
194
- * });
195
- *
196
- */
197
- once: <EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>) => () => boolean;
198
- /**
199
- * Emits an event and call all its listeners.
200
- *
201
- * @param event The name of the events.
202
- * @param payload Context information for the event.
203
- * @template EventName The literal type of the event, to generate the type of the
204
- * payload.
205
- * @example
206
- *
207
- * // Extend the interface to type the payload.
208
- * interface JimpexEvents {
209
- * myEvent: { message: string };
210
- * }
211
- * // Add the listener.
212
- * events.on('myEvent', ({ message }) => {
213
- * console.log('Event received:', message);
214
- * });
215
- * // Trigger the event.
216
- * events.emit('myEvent', { message: 'Hello' });
217
- * // prints "Event received: Hello"
218
- *
219
- */
220
- emit: <EventName extends JimpexEventName>(event: JimpexEventName, payload: JimpexEventPayload<EventName>) => void;
221
- /**
222
- * Asynchronously reduces a target using an event. It's like emit, but the event
223
- * listeners return a modified (or not) version of the `target`.
224
- *
225
- * @param event The name of the event.
226
- * @param target The variable to reduce with the reducers/listeners.
227
- * @param payload Context information for the event.
228
- * @returns A version of the `target` processed by the listeners.
229
- * @template EventName The literal type of the event, to generate the types of the
230
- * target and the payload.
231
- * @example
232
- *
233
- * // Extend the interface to type the target.
234
- * interface JimpexReducerEventTargets {
235
- * myReducer: unknown[];
236
- * }
237
- * // Extend the interface to type the payload.
238
- * interface JimpexReducerEventPayloads {
239
- * myReducer: {
240
- * message: string;
241
- * };
242
- * }
243
- * // Add the reducer.
244
- * events.on('myReducer', async (target, { message }) => {
245
- * const data = await fetch('https://api.example.com/' + message);
246
- * target.push(data);
247
- * return target;
248
- * });
249
- * // Trigger the event.
250
- * const result = await events.reduce('myReducer', [], { message: 'Hello' });
251
- * // result would be a list of data fetched from the API.
252
- *
253
- */
254
- reduce: <EventName extends JimpexReducerEventName>(event: JimpexReducerEventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => Promise<JimpexReducerEventTarget<EventName>>;
255
- /**
256
- * Synchronously reduces a target using an event. It's like emit, but the events
257
- * listener return a modified (or not) version of the `target`.
258
- *
259
- * @param event The name of the event.
260
- * @param target The variable to reduce with the reducers/listeners.
261
- * @param payload Context information for the event.
262
- * @returns A version of the `target` processed by the listeners.
263
- * @template EventName The literal type of the event, to generate the types of the
264
- * target and the payload.
265
- * @example
266
- *
267
- * // Extend the interface to type the target.
268
- * interface JimpexReducerEventTargets {
269
- * myReducer: string[];
270
- * }
271
- * // Extend the interface to type the payload.
272
- * interface JimpexReducerEventPayloads {
273
- * myReducer: {
274
- * message: string;
275
- * };
276
- * }
277
- * // Add the reducer.
278
- * events.on('myReducer', (target, { message }) => {
279
- * target.push(message);
280
- * return target;
281
- * });
282
- * // Trigger the event.
283
- * events.reduce('event', [], 'Hello');
284
- * // returns ['Hello']
285
- *
286
- */
287
- reduceSync: <EventName extends JimpexReducerEventName>(event: JimpexReducerEventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => JimpexReducerEventTarget<EventName>;
288
- };
289
-
290
- /**
291
- * The options for the application's configuration service.
292
- *
293
- * @see {@link https://www.npmjs.com/package/@homer0/simple-config}
294
- * @group Jimpex
295
- */
296
- type JimpexConfigOptions = {
297
- /**
298
- * The default settings for the configuration. If no external configuration is used,
299
- * this needs to include a `port` property.
300
- */
301
- default: unknown;
302
- /**
303
- * The name of the application, used for external configuration files.
304
- *
305
- * @default 'app'
306
- */
307
- name: string;
308
- /**
309
- * The path to where external configuration files are stored. Relative to the project
310
- * root.
311
- *
312
- * @default 'config/'
313
- */
314
- path: string;
315
- /**
316
- * Whether the configuration files are inside a sub directory or not. If `true`, a
317
- * configuration path would be `config/[app-name]/[file]`.
318
- *
319
- * @default false
320
- */
321
- hasFolder: boolean;
322
- /**
323
- * Whether or not to check for the environment variable and load a configuration file
324
- * based on its value.
325
- *
326
- * @default true
327
- */
328
- loadFromEnvironment: boolean;
329
- /**
330
- * The name of the environment variable that will be used to set the active
331
- * configuration.
332
- *
333
- * @default 'CONFIG'
334
- */
335
- environmentVariable: string;
336
- /**
337
- * The name of the default configuration file.
338
- *
339
- * @default '[app-name].config.js'
340
- */
341
- defaultConfigFilename: string;
342
- /**
343
- * The name format of other external configuration files.
344
- *
345
- * @default '[app-name].[config-name].config.js'
346
- */
347
- filenameFormat: string;
348
- };
349
- /**
350
- * The options for the middleware that serves static files.
351
- *
352
- * @group Jimpex
353
- */
354
- type JimpexStaticsOptions = {
355
- /**
356
- * Whether or not to enable the middleware.
357
- *
358
- * @default true
359
- */
360
- enabled: boolean;
361
- /**
362
- * If `true`, the path to the statics folder will be relative to the project root
363
- * directory, otherwise, it will be relative to the directory where the app executable
364
- * file is located.
365
- *
366
- * @default false
367
- */
368
- onHome: boolean;
369
- /**
370
- * The name of both the route and the folder, relative to whatever you defined with the
371
- * `onHome` option.
372
- *
373
- * @default 'statics'
374
- */
375
- route: string;
376
- /**
377
- * By default, the folder will be the same as the `route`,
378
- * but you can use this option to define a relative path that won't affect the route.
379
- *
380
- * @default ''
381
- */
382
- folder?: string;
383
- };
384
- /**
385
- * The options for the Express application.
386
- *
387
- * @group Jimpex
388
- */
389
- type JimpexExpressOptions = {
390
- /**
391
- * Whether or not to enable the `trust proxy` option.
392
- *
393
- * @default true
394
- */
395
- trustProxy: boolean;
396
- /**
397
- * Whether or not to remove the `x-powered-by` header.
398
- *
399
- * @default true
400
- */
401
- disableXPoweredBy: boolean;
402
- /**
403
- * Whether or not to add the `compression` middleware.
404
- *
405
- * @default true
406
- */
407
- compression: boolean;
408
- /**
409
- * Whether or not to add the `body-parser` middleware.
410
- *
411
- * @default true
412
- */
413
- bodyParser: boolean;
414
- /**
415
- * Whether or not to add the `multer` middleware.
416
- *
417
- * @see {@link https://www.npmjs.com/package/multer}
418
- */
419
- multer: boolean;
420
- };
421
- /**
422
- * The options to configure the application executable path.
423
- *
424
- * @group Jimpex
425
- */
426
- type JimpexPathOptions = {
427
- /**
428
- * A "hardcoded" path to the application executable file.
429
- *
430
- * @default ''
431
- */
432
- appPath?: string;
433
- /**
434
- * If `true`, it will try to figure out the parent file path, and use its directory as
435
- * the path.
436
- *
437
- * @default true
438
- */
439
- useParentPath: boolean;
440
- };
441
- /**
442
- * The options to enable some of the default services Jimpex comes with.
443
- *
444
- * @group Jimpex
445
- */
446
- type JimpexServicesOptions = {
447
- /**
448
- * Whether or not to register all the `common` services: `appError`, `httpError`, and
449
- * `sendFile`.
450
- *
451
- * @default true
452
- */
453
- common: boolean;
454
- /**
455
- * Whether or not to register the `http` services: `apiClient`, `http`, and
456
- * `responsesBuilder`.
457
- *
458
- * @default true
459
- */
460
- http: boolean;
461
- /**
462
- * Whether or not to register the `utils` services: `ensureBearerToken`.
463
- */
464
- utils: boolean;
465
- };
466
- /**
467
- * The format in which the application's health status can be returned.
468
- * It's either a simple boolean, or a more detailed object.
469
- *
470
- * @group Jimpex
471
- */
472
- type JimpexHealthStatus = boolean | {
473
- isHealthy?: boolean;
474
- services?: Record<string, boolean>;
475
- };
476
- /**
477
- * Returns the application health status. This is normally used by the `healthController`.
478
- *
479
- * @group Jimpex
480
- */
481
- type JimpexHealthCheckFn = (app: Jimpex) => Promise<JimpexHealthStatus>;
482
- /**
483
- * The options to create a new instance of Jimpex.
484
- *
485
- * @group Jimpex
486
- */
487
- type JimpexOptions = {
488
- /**
489
- * The size limit for the requests payload.
490
- *
491
- * @default '15MB'
492
- */
493
- filesizeLimit: string;
494
- /**
495
- * Whether or not to call the `boot` method after initialization. This is useful if you
496
- * want to register/overwrite services only on certain contexts, like a dev environment.
497
- *
498
- * @default true
499
- */
500
- boot: boolean;
501
- /**
502
- * The options to configure the application executable path.
503
- */
504
- path: JimpexPathOptions;
505
- /**
506
- * Options for the configuration service.
507
- *
508
- * @see {@link https://www.npmjs.com/package/@homer0/simple-config}
509
- */
510
- config: JimpexConfigOptions;
511
- /**
512
- * Options for the middleware that serves static files.
513
- */
514
- statics: JimpexStaticsOptions;
515
- /**
516
- * Options for the Express application.
517
- */
518
- express: JimpexExpressOptions;
519
- /**
520
- * Options to manage the default services.
521
- */
522
- services: JimpexServicesOptions;
523
- /**
524
- * A function that will be used to check the application health status.
525
- */
526
- healthCheck: JimpexHealthCheckFn;
527
- };
528
- /**
529
- * The function called when the application starts listening for requests.
530
- *
531
- * @group Jimpex
532
- */
533
- type JimpexStartCallback = (config: SimpleConfig) => void;
534
-
535
- /**
536
- * The function a provider uses to configure a resource in the container.
537
- *
538
- * @group Wrappers
539
- */
540
- type ProviderRegisterFn = ProviderRegisterFn$1<Jimpex>;
541
- /**
542
- * Creates an object that can configure/extend the container by registering services and
543
- * resources.
544
- *
545
- * @example
546
- *
547
- * class APIClient {}
548
- * const apiClientProvider = provider((app) => {
549
- * app.set('apiClient', () => new APIClient());
550
- * });
551
- *
552
- * @group Wrappers
553
- */
554
- declare const provider: (register: ProviderRegisterFn$1<Jimpex>) => _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>;
555
- /**
556
- * Creates an object like a provider, but that it can also be used as a function, as it
557
- * normally expose options for the resources it will configure.
558
- *
559
- * @example
560
- *
561
- * <caption>Registering as a common provider</caption>
562
- *
563
- * const apiClientProvider = providerCreator(
564
- * ({ serviceName = 'apiClient' }) =>
565
- * (app) => {
566
- * app.set(serviceName, () => new APIClient());
567
- * },
568
- * );
569
- *
570
- * container.register(apiClientProvider);
571
- *
572
- * @example
573
- *
574
- * <caption>Registering a created provider</caption>
575
- *
576
- * container.register(
577
- * apiClientProvider({
578
- * serviceName: 'myApiClient',
579
- * }),
580
- * );
581
- *
582
- * @group Wrappers
583
- */
584
- declare const providerCreator: <CreatorFn extends GenericCurriedFn<ProviderRegisterFn$1<Jimpex>>>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, ProviderRegisterFn$1<Jimpex>>;
585
- /**
586
- * Creates a collection of providers that can be registered one by one, or all at once.
587
- *
588
- * @example
589
- *
590
- * <caption>Registering all the providers at once</caption>
591
- *
592
- * const collection = providers({
593
- * apiClient: apiClientProvider,
594
- * http: httpProvider,
595
- * });
596
- *
597
- * container.register(collection);
598
- *
599
- * @example
600
- *
601
- * <caption>Registering one by one</caption>
602
- *
603
- * container.register(collection.http);
604
- *
605
- * @group Wrappers
606
- */
607
- declare const providers: <ItemsParam>(items: ItemsParam & Record<string, _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>>) => ItemsParam & Record<string, _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>> & {
608
- provider: true;
609
- } & {
610
- register: ProviderRegisterFn$1<Jimpex>;
611
- } & Record<string, unknown>;
612
- /**
613
- * An object that can configure/extend the container by registering services and
614
- * resources.
615
- *
616
- * @group Wrappers
617
- */
618
- type Provider = ReturnType<typeof provider>;
619
- /**
620
- * A provider creator is like a provider, but it can also be used as a function, and it
621
- * expose options for the resources it will configure.
622
- *
623
- * @group Wrappers
624
- */
625
- type ProviderCreator = ReturnType<typeof providerCreator>;
626
- /**
627
- * A collection of providers that can be registered one by one, or all at once.
628
- *
629
- * @group Wrappers
630
- */
631
- type Providers = ReturnType<typeof providers>;
632
- /**
633
- * A union of all types that can be registered in the provider with a `register` function.
634
- *
635
- * @group Wrappers
636
- */
637
- type ProviderLike = Provider | ProviderCreator | Providers;
638
- /**
639
- * The function a controller uses to mount a controller/middleware in the container.
640
- *
641
- * @param container The reference to the Jimpex container.
642
- * @param route The route on which the controller will be mounted on.
643
- * @group Wrappers
644
- */
645
- type ControllerConnectFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route: string) => Router | ExpressMiddlewareLike;
646
- /**
647
- * Generates a routes controller for the application container to mount.
648
- *
649
- * @param connect A function that will be called the moment the application mounts the
650
- * controller, and that is in charge of registering routes and
651
- * middlewares.
652
- * @example
653
- *
654
- * const myController = controller((app) => {
655
- * const router = app.getRouter();
656
- * const ctrl = new MyController();
657
- * return router.get('...', ctrl.doSomething()).post('...', ctrl.doSomethingElse());
658
- * });
659
- *
660
- * // ...
661
- * container.mount('/charo', myController);
662
- *
663
- * @group Wrappers
664
- */
665
- declare const controller: (connect: ControllerConnectFn) => _homer0_jimple.Resource<"controller", "connect", ControllerConnectFn>;
666
- /**
667
- * A high order function that generates a controller. It's used on the definitions of a
668
- * controller creator.
669
- *
670
- * @group Wrappers
671
- */
672
- type ControllerCreatorFn = GenericCurriedFn<ControllerConnectFn>;
673
- /**
674
- * Generates a configurable routes controller for the application to mount. It's
675
- * configurable because the `creator`, instead of just being sent to the container to
676
- * mount, it can also be called as a function with custom parameters the controller can
677
- * receive.
678
- *
679
- * @param creator A function that will generate a controller.
680
- * @example
681
- *
682
- * <caption>Basic usage</caption>
683
- *
684
- * const myController = controllerCreator((options = {}) => (app) => {
685
- * const router = app.getRouter();
686
- * const ctrl = new MyController(options);
687
- * return router.get('...', ctrl.doSomething()).post('...', ctrl.doSomethingElse());
688
- * });
689
- *
690
- * // ...
691
- * container.mount('/charo', myController);
692
- *
693
- * @example
694
- *
695
- * <caption>Custom parameters</caption>
696
- *
697
- * container.mount('/pili', myController({ foo: 'bar' }));
698
- *
699
- * @group Wrappers
700
- */
701
- declare const controllerCreator: <CreatorFn extends ControllerCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"controller", "connect", CreatorFn, ControllerConnectFn>;
702
- /**
703
- * A resource that will define middlewares for specific routes.
704
- *
705
- * @group Wrappers
706
- */
707
- type Controller = ReturnType<typeof controller>;
708
- /**
709
- * A controller creator is like a controller, but it can also be used as a function, and
710
- * it can receive custom parameters to configure its behavior.
711
- *
712
- * @group Wrappers
713
- */
714
- type ControllerCreator = ReturnType<typeof controllerCreator>;
715
- /**
716
- * The function a controller provider uses to configure/extend the container before
717
- * returning an actual controller.
718
- *
719
- * @param container The reference to the Jimpex container.
720
- * @param route The route on which the controller will be mounted on.
721
- * @group Wrappers
722
- */
723
- type ControllerProviderRegisterFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route: string) => Controller;
724
- /**
725
- * Creates a "controller provider", which is a controller that can configure/extend the
726
- * container before the application mounts it.
727
- *
728
- * @param register A function that will be called the moment the application mounts
729
- * the controller provider.
730
- * @example
731
- *
732
- * class MyController {}
733
- * const myControllerProvider = controllerProvider((app) => {
734
- * app.set('myController', () => new MyController());
735
- * return controller(() => {
736
- * const ctrl = app.get<MyController>('myController');
737
- * const router = app.getRouter();
738
- * return router.get('/', ctrl.doSomething());
739
- * });
740
- * });
741
- *
742
- * @group Wrappers
743
- */
744
- declare const controllerProvider: (register: ControllerProviderRegisterFn) => _homer0_jimple.Resource<"provider", "register", ControllerProviderRegisterFn>;
745
- /**
746
- * A high order function that generates a controller provider. It's used on the
747
- * definitions of a controller provider creator.
748
- *
749
- * @group Wrappers
750
- */
751
- type ControllerProviderCreatorFn = GenericCurriedFn<ControllerProviderRegisterFn>;
752
- /**
753
- * Generates a configurable controller provider for the application to mount. This is a
754
- * mix of a controller creator and a controller provider: it gives you the flexibility of
755
- * the creator, with the resources of the provider.
756
- *
757
- * @param creator A function that will generate a controller provider.
758
- * @example
759
- *
760
- * <caption>Basic usage</caption>
761
- *
762
- * class MyController {}
763
- * const myControllerProvider = controllerProviderCreator(
764
- * ({ serviceName = 'myController' }) =>
765
- * (app) => {
766
- * app.set(serviceName, () => new MyController());
767
- * return controller(() => {
768
- * const ctrl = app.get<MyController>(serviceName);
769
- * const router = app.getRouter();
770
- * return router.get('/', ctrl.doSomething());
771
- * });
772
- * },
773
- * );
774
- *
775
- * // ...
776
- * container.mount('/charo', myControllerProvider);
777
- *
778
- * @example
779
- *
780
- * <caption>Custom parameters</caption>
781
- *
782
- * container.mount('/pili', myControllerProvider({ serviceName: 'something' }));
783
- *
784
- * @group Wrappers
785
- */
786
- declare const controllerProviderCreator: <CreatorFn extends ControllerProviderCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, ControllerProviderRegisterFn>;
787
- /**
788
- * A special kind of controller that can be used to configure/extend the container before
789
- * returning an actual controller.
790
- *
791
- * @group Wrappers
792
- */
793
- type ControllerProvider = ReturnType<typeof controllerProvider>;
794
- /**
795
- * A "creator version" of a controller provider: a controller that can be used to
796
- * configure/extend the container before returning an actual controller, but that can also
797
- * be called as a function, and it can receive custom parameters to configure its
798
- * behavior.
799
- *
800
- * @group Wrappers
801
- */
802
- type ControllerProviderCreator = ReturnType<typeof controllerProviderCreator>;
803
- /**
804
- * The function a middleware uses to mount itself in the container.
805
- *
806
- * @param container The reference to the Jimpex container.
807
- * @param route This is optional because the implementation can use it as a
808
- * "global widdleware", or for a specific route.
809
- * @returns The resource can choose to be enabled or not by returning the function, or
810
- * `undefined`.
811
- * @group Wrappers
812
- */
813
- type MiddlewareConnectFn = <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route?: string) => Router | ExpressMiddlewareLike | undefined;
814
- /**
815
- * Generates a middleware for the application container to mount.
816
- *
817
- * @param connect A function that will be called the moment the application tries to
818
- * mount the middleware.
819
- * @example
820
- *
821
- * <caption>Basic usage</caption>
822
- *
823
- * const myMiddleware = controller((app) => {
824
- * const responsesBuilder = app.get<ResponsesBuilder>('responsesBuilder');
825
- * return (_, res) => {
826
- * responsesBuilder.json({ res, data: { hello: 'world' } });
827
- * };
828
- * });
829
- *
830
- * // ...
831
- * container.use(myMiddleware);
832
- *
833
- * @example
834
- *
835
- * <caption>On a specific route</caption>
836
- *
837
- * container.mount('/charo', myMiddleware);
838
- *
839
- * @group Wrappers
840
- */
841
- declare const middleware: (connect: MiddlewareConnectFn) => _homer0_jimple.Resource<"middleware", "connect", MiddlewareConnectFn>;
842
- /**
843
- * A high order function that generates a middleware. It's used on the definitions of a
844
- * middleware creator.
845
- *
846
- * @group Wrappers
847
- */
848
- type MiddlewareCreatorFn = GenericCurriedFn<MiddlewareConnectFn>;
849
- /**
850
- * Generates a configurable middleware for the application to use. It's configurable
851
- * because the `creator`, instead of just being sent to the container to mount, it can
852
- * also be called as a function with custom parameters the middleware can receive.
853
- *
854
- * @param creator A function that will generate a middleware.
855
- * @example
856
- *
857
- * <caption>Basic usage</caption>
858
- *
859
- * const myMiddleware = middlewareCreator((options = {}) => (app) => {
860
- * const message = options.message || 'Hello Charo!';
861
- * const responsesBuilder = app.get<ResponsesBuilder>('responsesBuilder');
862
- * return (_, res) => {
863
- * responsesBuilder.json({ res, data: { message } });
864
- * };
865
- * });
866
- *
867
- * // ...
868
- * container.use(myMiddleware);
869
- *
870
- * @example
871
- *
872
- * <caption>Custom parameters</caption>
873
- *
874
- * container.use(myMiddleware({ message: 'Hello Pili!' }));
875
- *
876
- * @group Wrappers
877
- */
878
- declare const middlewareCreator: <CreatorFn extends MiddlewareCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"middleware", "connect", CreatorFn, MiddlewareConnectFn>;
879
- /**
880
- * A resource that will define middlewares the application can use.
881
- *
882
- * @group Wrappers
883
- */
884
- type Middleware = ReturnType<typeof middleware>;
885
- /**
886
- * A middleware creator is like a middleware, but i can also be used as a function, and it
887
- * can receive custom parameters to configure its behavior.
888
- *
889
- * @group Wrappers
890
- */
891
- type MiddlewareCreator = ReturnType<typeof middlewareCreator>;
892
- /**
893
- * The function a middelware provider uses to configure/extend the container before
894
- * returning an actual middleware.
895
- *
896
- * @param container The reference to the Jimpex container.
897
- * @param route This is available only in the case the middleware is mounted on a
898
- * specific route.
899
- * @group Wrappers
900
- */
901
- type MiddlewareProviderRegisterFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route?: string) => Middleware;
902
- /**
903
- * Creates a "middleware provider", which is a middleware that can configure/extend the
904
- * container before the application uses it.
905
- *
906
- * @param register A function that will be called the moment the application uses the
907
- * middleware provider.
908
- * @example
909
- *
910
- * class MyServiceWithMiddleware {
911
- * constructor(private readonly responsesBuilder: ResponsesBuilder) {}
912
- * getMiddleware() {
913
- * return (_, res) => {
914
- * this.responsesBuilder.json({ res, data: { message } });
915
- * };
916
- * }
917
- * }
918
- *
919
- * const myMiddlewareProvider = middlewareProvider((app) => {
920
- * app.set(
921
- * 'myMiddleware',
922
- * () => new MyServiceWithMiddleware(app.get('responsesBuilder')),
923
- * );
924
- * return middleware(() =>
925
- * app.get<MyServiceWithMiddleware>('myMiddleware').getMiddleware(),
926
- * );
927
- * });
928
- *
929
- * @group Wrappers
930
- */
931
- declare const middlewareProvider: (register: MiddlewareProviderRegisterFn) => _homer0_jimple.Resource<"provider", "register", MiddlewareProviderRegisterFn>;
932
- /**
933
- * A high order function that generates a middleware provider. It's used on the
934
- * definitions of a middleware provider creator.
935
- *
936
- * @group Wrappers
937
- */
938
- type MiddlewareProviderCreatorFn = GenericCurriedFn<MiddlewareProviderRegisterFn>;
939
- /**
940
- * Generates a configurable middleware provider for the application to use. This is a mix
941
- * of a middleware creator and a middleware provider: it gives you the flexibility of the
942
- * creator, with the resources of the provider.
943
- *
944
- * @param creator A function that will generate a middleware provider.
945
- * @example
946
- *
947
- * <caption>Basic usage</caption>
948
- *
949
- * class MyServiceWithMiddleware {
950
- * constructor(private readonly responsesBuilder: ResponsesBuilder) {}
951
- * getMiddleware() {
952
- * return (_, res) => {
953
- * this.responsesBuilder.json({ res, data: { message } });
954
- * };
955
- * }
956
- * }
957
- * const myMiddlewareProvider = middlewareProviderCreator(
958
- * ({ serviceName = 'myMiddleware' }) =>
959
- * (app) => {
960
- * app.set(
961
- * serviceName,
962
- * () => new MyServiceWithMiddleware(app.get('responsesBuilder')),
963
- * );
964
- * return middleware(() =>
965
- * app.get<MyServiceWithMiddleware>(serviceName).getMiddleware(),
966
- * );
967
- * },
968
- * );
969
- *
970
- * // ...
971
- * container.use(myMiddlewareProvider);
972
- *
973
- * @example
974
- *
975
- * <caption>Custom parameters</caption>
976
- *
977
- * container.use(myMiddlewareProvider({ serviceName: 'something' }));
978
- *
979
- * @group Wrappers
980
- */
981
- declare const middlewareProviderCreator: <CreatorFn extends MiddlewareProviderCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, MiddlewareProviderRegisterFn>;
982
- /**
983
- * A special kind of middleware that can be used to configure/extend the container before
984
- * returning an actual middleware.
985
- *
986
- * @group Wrappers
987
- */
988
- type MiddlewareProvider = ReturnType<typeof middlewareProvider>;
989
- /**
990
- * A "creator version" of a middleware provider: a middleware that can be used to
991
- * configure/extend the container before returning an actual middleware, but that can also
992
- * be called as a function, and it can receive custom parameters to configure its
993
- * behavior.
994
- *
995
- * @group Wrappers
996
- */
997
- type MiddlewareProviderCreator = ReturnType<typeof middlewareProviderCreator>;
998
- /**
999
- * A union types of the different kinds of middlewares that can be used by the
1000
- * application.
1001
- *
1002
- * @group Wrappers
1003
- */
1004
- type MiddlewareLike = NoStringIndex<Middleware> | NoStringIndex<MiddlewareProvider> | ExpressMiddlewareLike;
1005
- /**
1006
- * A union types of the different kinds of controllers that can be mounted by the
1007
- * application.
1008
- *
1009
- * @group Wrappers
1010
- */
1011
- type ControllerLike = NoStringIndex<Controller> | NoStringIndex<ControllerProvider> | MiddlewareLike;
1012
-
1013
- /**
1014
- * Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container,
1015
- * and Express, one of the most popular web frameworks for Node.
1016
- *
1017
- * @group Jimpex
1018
- * @todo Implement `helmet`.
1019
- */
1020
- declare class Jimpex extends Jimple {
1021
- /**
1022
- * The customization settings for the application.
1023
- */
1024
- protected _options: JimpexOptions;
1025
- /**
1026
- * The Express application Jimpex uses under the hood.
1027
- */
1028
- protected _express: Express;
1029
- /**
1030
- * Since the configuration service has an async initialization, the class uses this flag
1031
- * internally to validate if the configuration has been initialized or not.
1032
- */
1033
- protected _configReady: boolean;
1034
- /**
1035
- * A reference to the actuall HTTP the application will use. This can vary depending on
1036
- * whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
1037
- * the `express` property; if HTTPS is enabled, it will be an `https` server; and if
1038
- * HTTP2 is enabled, it will be an `spdy` server.
1039
- */
1040
- protected _server?: JimpexServer;
1041
- /**
1042
- * The instance of the server that is listening for requests.
1043
- */
1044
- protected _instance?: JimpexServerInstance;
1045
- /**
1046
- * A list of functions that implement controllers and middlewares. When the application
1047
- * starts, the queue will be processed and those controllers and middlewares will be
1048
- * added to the server instance. The reason they are not added directly like with a
1049
- * regular Express implementation is that services on Jimple use lazy loading, and
1050
- * adding middlewares and controllers as they come could cause errors if they depend on
1051
- * services that are not yet registered.
1052
- */
1053
- protected _mountQueue: Array<(server: Express) => void>;
1054
- /**
1055
- * A list with all the top routes controlled by the application. Every time a controller
1056
- * is mounted, its route will be added here.
1057
- */
1058
- protected _controlledRoutes: string[];
1059
- /**
1060
- * @param options Preferences to customize the application.
1061
- * @param config The default settings for the configuration service. It's a
1062
- * shortcuit for `options.config.default`
1063
- */
1064
- constructor(options?: DeepPartial<JimpexOptions>, config?: unknown);
1065
- /**
1066
- * This is where the app would register all its specific services, middlewares and controllers.
1067
- */
1068
- boot(): void;
1069
- /**
1070
- * Disables the server TLS validation. Meant to be used for development purposes.
1071
- */
1072
- disableTLSValidation(): void;
1073
- /**
1074
- * Starts the app server.
1075
- *
1076
- * @param onStart A callback function to be called when the server actually starts.
1077
- * @returns The server instance.
1078
- */
1079
- start(onStart?: JimpexStartCallback): Promise<JimpexServerInstance>;
1080
- /**
1081
- * This is an alias of `start`. The idea is for it to be used on serverless platforms,
1082
- * where you don't get to start your app, you just have export it.
1083
- *
1084
- * @param port In case the configuration doesn't already have it,
1085
- * this is the port where the application will use to run. If this
1086
- * parameter is used, the method will overwrite the `port`
1087
- * setting on the configuration service.
1088
- * @param onStart A callback function to be called when the server starts.
1089
- * @returns The server instance.
1090
- */
1091
- listen(port?: number, onStart?: JimpexStartCallback): Promise<JimpexServerInstance>;
1092
- /**
1093
- * Stops the server instance.
1094
- */
1095
- stop(): void;
1096
- /**
1097
- * Mounts a route controller or a middleware into a server routes.
1098
- *
1099
- * @param route The route for the controller/middleware.
1100
- * @param controller The controller/middleware resource to be mounted.
1101
- */
1102
- mount(route: string, controller: ControllerLike): void;
1103
- /**
1104
- * Adds a global middleware to the application.
1105
- *
1106
- * @param middleware The middleware resource to be added.
1107
- */
1108
- use(middleware: MiddlewareLike): void;
1109
- getConfig(): SimpleConfig;
1110
- getConfig<T = unknown>(setting: string | string[], asArray?: boolean): T;
1111
- /**
1112
- * Creates a new router instance.
1113
- */
1114
- getRouter(): Router;
1115
- /**
1116
- * The logger service.
1117
- */
1118
- get logger(): SimpleLogger;
1119
- /**
1120
- * The Express application Jimpex uses under the hood.
1121
- */
1122
- get express(): Express;
1123
- /**
1124
- * The server instance that gets created when the app is started.
1125
- */
1126
- get instance(): JimpexServerInstance | undefined;
1127
- /**
1128
- * The application customization options.
1129
- */
1130
- get options(): DeepReadonly<JimpexOptions>;
1131
- /**
1132
- * Gets the events service.
1133
- */
1134
- get eventsHub(): EventsHub;
1135
- /**
1136
- * A list of the routes that have controllers mounted on them.
1137
- */
1138
- get routes(): string[];
1139
- /**
1140
- * Adds a listener for an application event.
1141
- *
1142
- * @param eventName The name of the event to listen for.
1143
- * @param listener The listener function.
1144
- * @returns A function to unsubscribe the listener.
1145
- * @template EventName The name of the event, to match the type of the listener
1146
- * function.
1147
- */
1148
- on<EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>): () => boolean;
1149
- /**
1150
- * Adds a listener for an application event that will only be execuded once: the first
1151
- * time the event is triggered.
1152
- *
1153
- * @param eventName The name of the event to listen for.
1154
- * @param listener The listener function.
1155
- * @returns A function to unsubscribe the listener.
1156
- * @template EventName The name of the event, to match the type of the listener
1157
- * function.
1158
- */
1159
- once<EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>): () => boolean;
1160
- /**
1161
- * Based on the application options, it returns wheter the application is healthy or
1162
- * not.
1163
- */
1164
- isHealthy(): ReturnType<JimpexHealthCheckFn>;
1165
- /**
1166
- * This method is like a "lifecycle method", it gets executed on the constructor right
1167
- * before the "boot step". The idea is for the method to be a helper when the
1168
- * application is defined by subclassing {@link Jimpex}: the application could register
1169
- * all important services here and the routes on boot, then, if the implementation needs
1170
- * to access or overwrite a something, it can send `boot: false`, access/register what
1171
- * it needs, and then call `boot()`. That would be impossible for an application without
1172
- * overwriting the constructor and the boot functionality.
1173
- */
1174
- protected _init(): void;
1175
- /**
1176
- * It generates overwrites for the application options when it gets created. This method
1177
- * is a helper for when the application is defined by subclassing {@link Jimpex}: It's
1178
- * highly probable that if the application needs to change the default options, it would
1179
- * want to do it right from the class, instead of having to do it on every
1180
- * implementation. A way to do it would be overwriting the constructor and calling
1181
- * `super` with the custom overwrites, but this method exists so that won't be
1182
- * necessary: when creating the `options`, the constructor will merge the result of this
1183
- * method on top of the default ones.
1184
- */
1185
- protected _initOptions(): DeepPartial<JimpexOptions>;
1186
- /**
1187
- * Registers the "core services" on the container: logger, events, utils, etc.
1188
- */
1189
- protected _setupCoreServices(): void;
1190
- /**
1191
- * Configures the Express application based on the class options.
1192
- */
1193
- protected _setupExpress(): void;
1194
- /**
1195
- * Adds a static folder to the application.
1196
- *
1197
- * @param route The route to add the folder to.
1198
- * @param folder The path to the folder in the file system. If not defined, it will
1199
- * be use the same value as `route`. The path could be relative to the
1200
- * project root, or where the application executable is located,
1201
- * depending on the value of the `onHome` parameter.
1202
- * @param onHome If `true`, the path to the folder will be relative to the project
1203
- * root. If `false`, it will be relative to where the application
1204
- * executable is located.
1205
- */
1206
- protected _addStaticsFolder(route: string, folder?: string, onHome?: boolean): void;
1207
- /**
1208
- * This helper method validates the `path` options in order to register the `app`
1209
- * location in the `pathUtils` service. The `app` location should be the path to where
1210
- * the application executable is located, but due to how ESM works, we can't infer it
1211
- * from the `module` object, so we need either recieved as the `appPath` setting, or try
1212
- * to get it from the parent module.
1213
- *
1214
- * @throws If the method should use the path from the parent module, but can't find
1215
- * it.
1216
- */
1217
- protected _configurePath(): void;
1218
- /**
1219
- * Setups the configuration service. The new configuration service requires async calls
1220
- * in order to load the configuration files (as it uses `import` instead of `require`),
1221
- * so it can't be instantiated as the other services.
1222
- * This method is called just before starting the application.
1223
- */
1224
- protected _setupConfig(): Promise<void>;
1225
- /**
1226
- * Loads the ESM modules that are needed by Jimpex. This is called just before the starting
1227
- * the application so they'll be available for all the services.
1228
- */
1229
- protected _loadESMModules(): Promise<void>;
1230
- /**
1231
- * Processes the resources from the mount queue (added with {@link Jimpex.mount} and
1232
- * {@link Jimpex.use}), and adds them to the Express application.
1233
- */
1234
- protected _mountResources(): void;
1235
- /**
1236
- * Emits an event using the `events` service.
1237
- *
1238
- * @param name The name of the event to emit.
1239
- * @param payload The event payload.
1240
- * @template EventName The literal name of the event, to type the event payload.
1241
- */
1242
- protected _emitEvent<EventName extends JimpexEventName>(name: EventName, payload: JimpexEventPayload<EventName>): void;
1243
- /**
1244
- * Sends a target object to a list of reducer events so they can modify or replace it.
1245
- *
1246
- * @param name The name of the event to use.
1247
- * @param target The object to reduce with the event.
1248
- * @param payload Extra context for the listeners.
1249
- */
1250
- protected _reduceWithEvent<EventName extends JimpexReducerEventName>(name: EventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>): JimpexReducerEventTarget<EventName>;
1251
- /**
1252
- * Loads the contents of a dictionary of credentials files that need to be used to
1253
- * configure HTTPS.
1254
- *
1255
- * @param credentialsInfo The dictionary where the keys are the type of credentials
1256
- * (`ca`, `cert`, `key`) and the values are the paths to the
1257
- * files.
1258
- * @param onHome If this is `true`, the path of the files will be relative
1259
- * to the project root. If it is `false`, it will be relative
1260
- * to where the application executable is located.
1261
- * @returns
1262
- */
1263
- protected _loadCredentials(credentialsInfo: JimpexHTTPSCredentials, onHome?: boolean): Promise<JimpexHTTPSCredentials>;
1264
- /**
1265
- * Validates the configuration and chooses the server the application needs to use: If
1266
- * HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use
1267
- * the native HTTPS server; otherwise, it will be just the Express instance.
1268
- *
1269
- * @returns {Server}
1270
- * @throws {Error} If HTTP2 is enabled but HTTPS is not.
1271
- * @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.
1272
- * @throws {Error} If HTTPS is enabled and no creadentials are found.
1273
- * @access protected
1274
- * @ignore
1275
- */
1276
- protected _createServer(): Promise<JimpexServer>;
1277
- }
1278
- /**
1279
- * Shorthand for `new Jimpex()`.
1280
- *
1281
- * @param args The same parameters as the {@link Jimpex} constructor.
1282
- * @returns A new instance of {@link Jimpex}.
1283
- * @group Jimpex
1284
- */
1285
- declare const jimpex: (options?: DeepPartial<JimpexOptions> | undefined, config?: unknown) => Jimpex;
1286
-
1287
- export { type MiddlewareProvider as $, type Providers as A, type ProviderLike as B, type ControllerConnectFn as C, controller as D, type EventPayload as E, type ControllerCreatorFn as F, controllerCreator as G, type Controller as H, type ControllerCreator as I, Jimpex as J, type ControllerProviderRegisterFn as K, controllerProvider as L, type ControllerProviderCreatorFn as M, controllerProviderCreator as N, type ControllerProvider as O, type ProviderRegisterFn as P, type ControllerProviderCreator as Q, type MiddlewareConnectFn as R, middleware as S, type MiddlewareCreatorFn as T, middlewareCreator as U, type Middleware as V, type MiddlewareCreator as W, type MiddlewareProviderRegisterFn as X, middlewareProvider as Y, type MiddlewareProviderCreatorFn as Z, middlewareProviderCreator as _, type JimpexEvents as a, type MiddlewareProviderCreator as a0, type MiddlewareLike as a1, type ControllerLike as a2, type JimpexEventName as b, type JimpexEventPayload as c, type JimpexReducerEventTargets as d, type JimpexReducerEventPayloads as e, type JimpexReducerEventName as f, type JimpexReducerEventTarget as g, type JimpexReducerEventPayload as h, type JimpexEventNameLike as i, jimpex as j, type JimpexEventListener as k, type Events as l, type JimpexConfigOptions as m, type JimpexStaticsOptions as n, type JimpexExpressOptions as o, type JimpexPathOptions as p, type JimpexServicesOptions as q, type JimpexHealthStatus as r, type JimpexHealthCheckFn as s, type JimpexOptions as t, type JimpexStartCallback as u, provider as v, providerCreator as w, providers as x, type Provider as y, type ProviderCreator as z };