@lakutata/entrypoint 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +183 -0
  3. package/THIRD_PARTY_NOTICES.md +206 -0
  4. package/dist/cjs/Entrypoint.d.ts +868 -0
  5. package/dist/cjs/Entrypoint.js +998 -0
  6. package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
  7. package/dist/cjs/adapter/commander/CommanderCLIEntrypoint.js +439 -0
  8. package/dist/cjs/adapter/commander/Prompt.d.ts +22 -0
  9. package/dist/cjs/adapter/commander/Prompt.js +164 -0
  10. package/dist/cjs/adapter/commander/Width.d.ts +12 -0
  11. package/dist/cjs/adapter/commander/Width.js +67 -0
  12. package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
  13. package/dist/cjs/adapter/electron/ElectronIPCServiceEntrypoint.js +249 -0
  14. package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
  15. package/dist/cjs/adapter/express/ExpressHTTPEntrypoint.js +301 -0
  16. package/dist/cjs/adapter/express/Responders.d.ts +89 -0
  17. package/dist/cjs/adapter/express/Responders.js +71 -0
  18. package/dist/cjs/adapter/express/StaticUI.d.ts +83 -0
  19. package/dist/cjs/adapter/express/StaticUI.js +104 -0
  20. package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
  21. package/dist/cjs/adapter/fastify/FastifyHTTPEntrypoint.js +339 -0
  22. package/dist/cjs/adapter/fastify/Responders.d.ts +88 -0
  23. package/dist/cjs/adapter/fastify/Responders.js +77 -0
  24. package/dist/cjs/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
  25. package/dist/cjs/adapter/http/HTTPServiceEntrypoint.js +257 -0
  26. package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
  27. package/dist/cjs/adapter/jsonrpc/JSONRPCProtocol.js +187 -0
  28. package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
  29. package/dist/cjs/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +397 -0
  30. package/dist/cjs/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
  31. package/dist/cjs/adapter/schedule/ScheduleEntrypoint.js +275 -0
  32. package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
  33. package/dist/cjs/adapter/socket.io/SocketIOServiceEntrypoint.js +216 -0
  34. package/dist/cjs/channel/BuiltinChannels.d.ts +18 -0
  35. package/dist/cjs/channel/BuiltinChannels.js +128 -0
  36. package/dist/cjs/channel/Channel.d.ts +196 -0
  37. package/dist/cjs/channel/Channel.js +106 -0
  38. package/dist/cjs/channel/EntrypointAdapter.d.ts +195 -0
  39. package/dist/cjs/channel/EntrypointAdapter.js +43 -0
  40. package/dist/cjs/context/BaseContext.d.ts +75 -0
  41. package/dist/cjs/context/BaseContext.js +90 -0
  42. package/dist/cjs/context/CLIContext.d.ts +38 -0
  43. package/dist/cjs/context/CLIContext.js +53 -0
  44. package/dist/cjs/context/HTTPContext.d.ts +52 -0
  45. package/dist/cjs/context/HTTPContext.js +78 -0
  46. package/dist/cjs/context/ScheduleContext.d.ts +47 -0
  47. package/dist/cjs/context/ScheduleContext.js +65 -0
  48. package/dist/cjs/context/ServiceContext.d.ts +47 -0
  49. package/dist/cjs/context/ServiceContext.js +62 -0
  50. package/dist/cjs/decorators/CLIAction.d.ts +120 -0
  51. package/dist/cjs/decorators/CLIAction.js +13 -0
  52. package/dist/cjs/decorators/HTTPAction.d.ts +178 -0
  53. package/dist/cjs/decorators/HTTPAction.js +14 -0
  54. package/dist/cjs/decorators/Prefix.d.ts +44 -0
  55. package/dist/cjs/decorators/Prefix.js +48 -0
  56. package/dist/cjs/decorators/Schedule.d.ts +120 -0
  57. package/dist/cjs/decorators/Schedule.js +64 -0
  58. package/dist/cjs/decorators/ServiceAction.d.ts +116 -0
  59. package/dist/cjs/decorators/ServiceAction.js +12 -0
  60. package/dist/cjs/decorators/UseMiddlewares.d.ts +52 -0
  61. package/dist/cjs/decorators/UseMiddlewares.js +58 -0
  62. package/dist/cjs/decorators/http/DELETE.d.ts +87 -0
  63. package/dist/cjs/decorators/http/DELETE.js +7 -0
  64. package/dist/cjs/decorators/http/GET.d.ts +89 -0
  65. package/dist/cjs/decorators/http/GET.js +7 -0
  66. package/dist/cjs/decorators/http/HEAD.d.ts +84 -0
  67. package/dist/cjs/decorators/http/HEAD.js +7 -0
  68. package/dist/cjs/decorators/http/OPTIONS.d.ts +80 -0
  69. package/dist/cjs/decorators/http/OPTIONS.js +7 -0
  70. package/dist/cjs/decorators/http/PATCH.d.ts +90 -0
  71. package/dist/cjs/decorators/http/PATCH.js +7 -0
  72. package/dist/cjs/decorators/http/POST.d.ts +91 -0
  73. package/dist/cjs/decorators/http/POST.js +7 -0
  74. package/dist/cjs/decorators/http/PUT.d.ts +92 -0
  75. package/dist/cjs/decorators/http/PUT.js +7 -0
  76. package/dist/cjs/exceptions/AccessDeniedException.d.ts +10 -0
  77. package/dist/cjs/exceptions/AccessDeniedException.js +17 -0
  78. package/dist/cjs/exceptions/ControllerActionNotFoundException.d.ts +9 -0
  79. package/dist/cjs/exceptions/ControllerActionNotFoundException.js +16 -0
  80. package/dist/cjs/exceptions/DuplicateActionNameException.d.ts +8 -0
  81. package/dist/cjs/exceptions/DuplicateActionNameException.js +15 -0
  82. package/dist/cjs/exceptions/EntrypointStoppedException.d.ts +9 -0
  83. package/dist/cjs/exceptions/EntrypointStoppedException.js +16 -0
  84. package/dist/cjs/exceptions/InvalidActionGroupException.d.ts +4 -0
  85. package/dist/cjs/exceptions/InvalidActionGroupException.js +11 -0
  86. package/dist/cjs/exceptions/InvalidChannelException.d.ts +8 -0
  87. package/dist/cjs/exceptions/InvalidChannelException.js +15 -0
  88. package/dist/cjs/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
  89. package/dist/cjs/exceptions/InvalidEntrypointAdapterException.js +16 -0
  90. package/dist/cjs/exceptions/InvalidMiddlewareException.d.ts +8 -0
  91. package/dist/cjs/exceptions/InvalidMiddlewareException.js +15 -0
  92. package/dist/cjs/exceptions/InvalidPrefixException.d.ts +8 -0
  93. package/dist/cjs/exceptions/InvalidPrefixException.js +15 -0
  94. package/dist/cjs/exceptions/MiddlewareNextCalledException.d.ts +8 -0
  95. package/dist/cjs/exceptions/MiddlewareNextCalledException.js +15 -0
  96. package/dist/cjs/exceptions/RouteNotFoundException.d.ts +9 -0
  97. package/dist/cjs/exceptions/RouteNotFoundException.js +16 -0
  98. package/dist/cjs/exceptions/ServiceInvokeException.d.ts +11 -0
  99. package/dist/cjs/exceptions/ServiceInvokeException.js +14 -0
  100. package/dist/cjs/exports/CTRLDecorators.d.ts +13 -0
  101. package/dist/cjs/exports/CTRLDecorators.js +38 -0
  102. package/dist/cjs/exports/Channel.d.ts +14 -0
  103. package/dist/cjs/exports/Channel.js +33 -0
  104. package/dist/cjs/exports/CommanderAdapter.d.ts +1 -0
  105. package/dist/cjs/exports/CommanderAdapter.js +8 -0
  106. package/dist/cjs/exports/ElectronAdapter.d.ts +1 -0
  107. package/dist/cjs/exports/ElectronAdapter.js +9 -0
  108. package/dist/cjs/exports/Entrypoint.d.ts +24 -0
  109. package/dist/cjs/exports/Entrypoint.js +55 -0
  110. package/dist/cjs/exports/ExpressAdapter.d.ts +4 -0
  111. package/dist/cjs/exports/ExpressAdapter.js +15 -0
  112. package/dist/cjs/exports/FastifyAdapter.d.ts +4 -0
  113. package/dist/cjs/exports/FastifyAdapter.js +14 -0
  114. package/dist/cjs/exports/JSONRPCAdapter.d.ts +2 -0
  115. package/dist/cjs/exports/JSONRPCAdapter.js +11 -0
  116. package/dist/cjs/exports/SocketIOAdapter.d.ts +1 -0
  117. package/dist/cjs/exports/SocketIOAdapter.js +9 -0
  118. package/dist/cjs/lib/AccessControl.d.ts +118 -0
  119. package/dist/cjs/lib/AccessControl.js +208 -0
  120. package/dist/cjs/lib/AccessControlRule.d.ts +91 -0
  121. package/dist/cjs/lib/AccessControlRule.js +76 -0
  122. package/dist/cjs/lib/ActionOptions.d.ts +67 -0
  123. package/dist/cjs/lib/ActionOptions.js +67 -0
  124. package/dist/cjs/lib/ActionResult.d.ts +28 -0
  125. package/dist/cjs/lib/ActionResult.js +28 -0
  126. package/dist/cjs/lib/ApplicationOf.d.ts +6 -0
  127. package/dist/cjs/lib/ApplicationOf.js +14 -0
  128. package/dist/cjs/lib/Controller.d.ts +59 -0
  129. package/dist/cjs/lib/Controller.js +64 -0
  130. package/dist/cjs/lib/ControllerEntrypoint.d.ts +168 -0
  131. package/dist/cjs/lib/ControllerEntrypoint.js +239 -0
  132. package/dist/cjs/lib/GetActionDTOAndOptions.d.ts +29 -0
  133. package/dist/cjs/lib/GetActionDTOAndOptions.js +49 -0
  134. package/dist/cjs/lib/HTTPErrors.d.ts +55 -0
  135. package/dist/cjs/lib/HTTPErrors.js +52 -0
  136. package/dist/cjs/lib/Middleware.d.ts +146 -0
  137. package/dist/cjs/lib/Middleware.js +144 -0
  138. package/dist/cjs/lib/Prefix.d.ts +98 -0
  139. package/dist/cjs/lib/Prefix.js +151 -0
  140. package/dist/cjs/lib/Result.d.ts +173 -0
  141. package/dist/cjs/lib/Result.js +153 -0
  142. package/dist/cjs/lib/ServiceResponseCodec.d.ts +82 -0
  143. package/dist/cjs/lib/ServiceResponseCodec.js +117 -0
  144. package/dist/cjs/lib/StringifyPattern.d.ts +7 -0
  145. package/dist/cjs/lib/StringifyPattern.js +58 -0
  146. package/dist/cjs/lib/UnsetValue.d.ts +12 -0
  147. package/dist/cjs/lib/UnsetValue.js +216 -0
  148. package/dist/cjs/lib/pattern/GlobPattern.d.ts +34 -0
  149. package/dist/cjs/lib/pattern/GlobPattern.js +68 -0
  150. package/dist/cjs/lib/pattern/PatternManager.d.ts +103 -0
  151. package/dist/cjs/lib/pattern/PatternManager.js +233 -0
  152. package/dist/cjs/lib/schedule/Cron.d.ts +56 -0
  153. package/dist/cjs/lib/schedule/Cron.js +282 -0
  154. package/dist/cjs/package.json +1 -0
  155. package/dist/cjs/types/CLIContextParams.d.ts +14 -0
  156. package/dist/cjs/types/CLIContextParams.js +2 -0
  157. package/dist/cjs/types/ErrorDescription.d.ts +14 -0
  158. package/dist/cjs/types/ErrorDescription.js +2 -0
  159. package/dist/cjs/types/HTTPContextParams.d.ts +27 -0
  160. package/dist/cjs/types/HTTPContextParams.js +2 -0
  161. package/dist/cjs/types/ScheduleContextParams.d.ts +21 -0
  162. package/dist/cjs/types/ScheduleContextParams.js +2 -0
  163. package/dist/cjs/types/ServiceContextParams.d.ts +16 -0
  164. package/dist/cjs/types/ServiceContextParams.js +2 -0
  165. package/dist/esm/Entrypoint.js +985 -0
  166. package/dist/esm/adapter/commander/CommanderCLIEntrypoint.js +433 -0
  167. package/dist/esm/adapter/commander/Prompt.js +127 -0
  168. package/dist/esm/adapter/commander/Width.js +63 -0
  169. package/dist/esm/adapter/electron/ElectronIPCServiceEntrypoint.js +212 -0
  170. package/dist/esm/adapter/express/ExpressHTTPEntrypoint.js +295 -0
  171. package/dist/esm/adapter/express/Responders.js +66 -0
  172. package/dist/esm/adapter/express/StaticUI.js +96 -0
  173. package/dist/esm/adapter/fastify/FastifyHTTPEntrypoint.js +333 -0
  174. package/dist/esm/adapter/fastify/Responders.js +73 -0
  175. package/dist/esm/adapter/http/HTTPServiceEntrypoint.js +253 -0
  176. package/dist/esm/adapter/jsonrpc/JSONRPCProtocol.js +182 -0
  177. package/dist/esm/adapter/jsonrpc/JSONRPCServiceEntrypoint.js +361 -0
  178. package/dist/esm/adapter/schedule/ScheduleEntrypoint.js +272 -0
  179. package/dist/esm/adapter/socket.io/SocketIOServiceEntrypoint.js +212 -0
  180. package/dist/esm/channel/BuiltinChannels.js +125 -0
  181. package/dist/esm/channel/Channel.js +100 -0
  182. package/dist/esm/channel/EntrypointAdapter.js +39 -0
  183. package/dist/esm/context/BaseContext.js +87 -0
  184. package/dist/esm/context/CLIContext.js +49 -0
  185. package/dist/esm/context/HTTPContext.js +74 -0
  186. package/dist/esm/context/ScheduleContext.js +61 -0
  187. package/dist/esm/context/ServiceContext.js +58 -0
  188. package/dist/esm/decorators/CLIAction.js +10 -0
  189. package/dist/esm/decorators/HTTPAction.js +11 -0
  190. package/dist/esm/decorators/Prefix.js +45 -0
  191. package/dist/esm/decorators/Schedule.js +61 -0
  192. package/dist/esm/decorators/ServiceAction.js +9 -0
  193. package/dist/esm/decorators/UseMiddlewares.js +55 -0
  194. package/dist/esm/decorators/http/DELETE.js +4 -0
  195. package/dist/esm/decorators/http/GET.js +4 -0
  196. package/dist/esm/decorators/http/HEAD.js +4 -0
  197. package/dist/esm/decorators/http/OPTIONS.js +4 -0
  198. package/dist/esm/decorators/http/PATCH.js +4 -0
  199. package/dist/esm/decorators/http/POST.js +4 -0
  200. package/dist/esm/decorators/http/PUT.js +4 -0
  201. package/dist/esm/exceptions/AccessDeniedException.js +13 -0
  202. package/dist/esm/exceptions/ControllerActionNotFoundException.js +12 -0
  203. package/dist/esm/exceptions/DuplicateActionNameException.js +11 -0
  204. package/dist/esm/exceptions/EntrypointStoppedException.js +12 -0
  205. package/dist/esm/exceptions/InvalidActionGroupException.js +7 -0
  206. package/dist/esm/exceptions/InvalidChannelException.js +11 -0
  207. package/dist/esm/exceptions/InvalidEntrypointAdapterException.js +12 -0
  208. package/dist/esm/exceptions/InvalidMiddlewareException.js +11 -0
  209. package/dist/esm/exceptions/InvalidPrefixException.js +11 -0
  210. package/dist/esm/exceptions/MiddlewareNextCalledException.js +11 -0
  211. package/dist/esm/exceptions/RouteNotFoundException.js +12 -0
  212. package/dist/esm/exceptions/ServiceInvokeException.js +10 -0
  213. package/dist/esm/exports/CTRLDecorators.js +19 -0
  214. package/dist/esm/exports/Channel.js +11 -0
  215. package/dist/esm/exports/CommanderAdapter.js +1 -0
  216. package/dist/esm/exports/ElectronAdapter.js +1 -0
  217. package/dist/esm/exports/Entrypoint.js +22 -0
  218. package/dist/esm/exports/ExpressAdapter.js +3 -0
  219. package/dist/esm/exports/FastifyAdapter.js +3 -0
  220. package/dist/esm/exports/JSONRPCAdapter.js +2 -0
  221. package/dist/esm/exports/SocketIOAdapter.js +1 -0
  222. package/dist/esm/lib/AccessControl.js +204 -0
  223. package/dist/esm/lib/AccessControlRule.js +72 -0
  224. package/dist/esm/lib/ActionOptions.js +63 -0
  225. package/dist/esm/lib/ActionResult.js +24 -0
  226. package/dist/esm/lib/ApplicationOf.js +11 -0
  227. package/dist/esm/lib/Controller.js +61 -0
  228. package/dist/esm/lib/ControllerEntrypoint.js +229 -0
  229. package/dist/esm/lib/GetActionDTOAndOptions.js +46 -0
  230. package/dist/esm/lib/HTTPErrors.js +48 -0
  231. package/dist/esm/lib/Middleware.js +134 -0
  232. package/dist/esm/lib/Prefix.js +143 -0
  233. package/dist/esm/lib/Result.js +147 -0
  234. package/dist/esm/lib/ServiceResponseCodec.js +113 -0
  235. package/dist/esm/lib/StringifyPattern.js +55 -0
  236. package/dist/esm/lib/UnsetValue.js +213 -0
  237. package/dist/esm/lib/pattern/GlobPattern.js +64 -0
  238. package/dist/esm/lib/pattern/PatternManager.js +229 -0
  239. package/dist/esm/lib/schedule/Cron.js +277 -0
  240. package/dist/esm/types/CLIContextParams.js +1 -0
  241. package/dist/esm/types/ErrorDescription.js +1 -0
  242. package/dist/esm/types/HTTPContextParams.js +1 -0
  243. package/dist/esm/types/ScheduleContextParams.js +1 -0
  244. package/dist/esm/types/ServiceContextParams.js +1 -0
  245. package/dist/types/Entrypoint.d.ts +868 -0
  246. package/dist/types/adapter/commander/CommanderCLIEntrypoint.d.ts +192 -0
  247. package/dist/types/adapter/commander/Prompt.d.ts +22 -0
  248. package/dist/types/adapter/commander/Width.d.ts +12 -0
  249. package/dist/types/adapter/electron/ElectronIPCServiceEntrypoint.d.ts +203 -0
  250. package/dist/types/adapter/express/ExpressHTTPEntrypoint.d.ts +172 -0
  251. package/dist/types/adapter/express/Responders.d.ts +89 -0
  252. package/dist/types/adapter/express/StaticUI.d.ts +83 -0
  253. package/dist/types/adapter/fastify/FastifyHTTPEntrypoint.d.ts +156 -0
  254. package/dist/types/adapter/fastify/Responders.d.ts +88 -0
  255. package/dist/types/adapter/http/HTTPServiceEntrypoint.d.ts +117 -0
  256. package/dist/types/adapter/jsonrpc/JSONRPCProtocol.d.ts +194 -0
  257. package/dist/types/adapter/jsonrpc/JSONRPCServiceEntrypoint.d.ts +154 -0
  258. package/dist/types/adapter/schedule/ScheduleEntrypoint.d.ts +86 -0
  259. package/dist/types/adapter/socket.io/SocketIOServiceEntrypoint.d.ts +138 -0
  260. package/dist/types/channel/BuiltinChannels.d.ts +18 -0
  261. package/dist/types/channel/Channel.d.ts +196 -0
  262. package/dist/types/channel/EntrypointAdapter.d.ts +195 -0
  263. package/dist/types/context/BaseContext.d.ts +75 -0
  264. package/dist/types/context/CLIContext.d.ts +38 -0
  265. package/dist/types/context/HTTPContext.d.ts +52 -0
  266. package/dist/types/context/ScheduleContext.d.ts +47 -0
  267. package/dist/types/context/ServiceContext.d.ts +47 -0
  268. package/dist/types/decorators/CLIAction.d.ts +120 -0
  269. package/dist/types/decorators/HTTPAction.d.ts +178 -0
  270. package/dist/types/decorators/Prefix.d.ts +44 -0
  271. package/dist/types/decorators/Schedule.d.ts +120 -0
  272. package/dist/types/decorators/ServiceAction.d.ts +116 -0
  273. package/dist/types/decorators/UseMiddlewares.d.ts +52 -0
  274. package/dist/types/decorators/http/DELETE.d.ts +87 -0
  275. package/dist/types/decorators/http/GET.d.ts +89 -0
  276. package/dist/types/decorators/http/HEAD.d.ts +84 -0
  277. package/dist/types/decorators/http/OPTIONS.d.ts +80 -0
  278. package/dist/types/decorators/http/PATCH.d.ts +90 -0
  279. package/dist/types/decorators/http/POST.d.ts +91 -0
  280. package/dist/types/decorators/http/PUT.d.ts +92 -0
  281. package/dist/types/exceptions/AccessDeniedException.d.ts +10 -0
  282. package/dist/types/exceptions/ControllerActionNotFoundException.d.ts +9 -0
  283. package/dist/types/exceptions/DuplicateActionNameException.d.ts +8 -0
  284. package/dist/types/exceptions/EntrypointStoppedException.d.ts +9 -0
  285. package/dist/types/exceptions/InvalidActionGroupException.d.ts +4 -0
  286. package/dist/types/exceptions/InvalidChannelException.d.ts +8 -0
  287. package/dist/types/exceptions/InvalidEntrypointAdapterException.d.ts +9 -0
  288. package/dist/types/exceptions/InvalidMiddlewareException.d.ts +8 -0
  289. package/dist/types/exceptions/InvalidPrefixException.d.ts +8 -0
  290. package/dist/types/exceptions/MiddlewareNextCalledException.d.ts +8 -0
  291. package/dist/types/exceptions/RouteNotFoundException.d.ts +9 -0
  292. package/dist/types/exceptions/ServiceInvokeException.d.ts +11 -0
  293. package/dist/types/exports/CTRLDecorators.d.ts +13 -0
  294. package/dist/types/exports/Channel.d.ts +14 -0
  295. package/dist/types/exports/CommanderAdapter.d.ts +1 -0
  296. package/dist/types/exports/ElectronAdapter.d.ts +1 -0
  297. package/dist/types/exports/Entrypoint.d.ts +24 -0
  298. package/dist/types/exports/ExpressAdapter.d.ts +4 -0
  299. package/dist/types/exports/FastifyAdapter.d.ts +4 -0
  300. package/dist/types/exports/JSONRPCAdapter.d.ts +2 -0
  301. package/dist/types/exports/SocketIOAdapter.d.ts +1 -0
  302. package/dist/types/lib/AccessControl.d.ts +118 -0
  303. package/dist/types/lib/AccessControlRule.d.ts +91 -0
  304. package/dist/types/lib/ActionOptions.d.ts +67 -0
  305. package/dist/types/lib/ActionResult.d.ts +28 -0
  306. package/dist/types/lib/ApplicationOf.d.ts +6 -0
  307. package/dist/types/lib/Controller.d.ts +59 -0
  308. package/dist/types/lib/ControllerEntrypoint.d.ts +168 -0
  309. package/dist/types/lib/GetActionDTOAndOptions.d.ts +29 -0
  310. package/dist/types/lib/HTTPErrors.d.ts +55 -0
  311. package/dist/types/lib/Middleware.d.ts +146 -0
  312. package/dist/types/lib/Prefix.d.ts +98 -0
  313. package/dist/types/lib/Result.d.ts +173 -0
  314. package/dist/types/lib/ServiceResponseCodec.d.ts +82 -0
  315. package/dist/types/lib/StringifyPattern.d.ts +7 -0
  316. package/dist/types/lib/UnsetValue.d.ts +12 -0
  317. package/dist/types/lib/pattern/GlobPattern.d.ts +34 -0
  318. package/dist/types/lib/pattern/PatternManager.d.ts +103 -0
  319. package/dist/types/lib/schedule/Cron.d.ts +56 -0
  320. package/dist/types/types/CLIContextParams.d.ts +14 -0
  321. package/dist/types/types/ErrorDescription.d.ts +14 -0
  322. package/dist/types/types/HTTPContextParams.d.ts +27 -0
  323. package/dist/types/types/ScheduleContextParams.d.ts +21 -0
  324. package/dist/types/types/ServiceContextParams.d.ts +16 -0
  325. package/package.json +152 -0
@@ -0,0 +1,868 @@
1
+ import { Component, ActionPattern, Module, JSONSchema, Container, DTO, type IBaseObjectConstructor } from '@lakutata/core';
2
+ import { CLIContext } from './context/CLIContext.js';
3
+ import { HTTPContext } from './context/HTTPContext.js';
4
+ import { ServiceContext } from './context/ServiceContext.js';
5
+ import { ScheduleContext } from './context/ScheduleContext.js';
6
+ import { ActionDetails, ActionPatternMap } from './lib/ControllerEntrypoint.js';
7
+ import { Controller } from './lib/Controller.js';
8
+ import { AccessControl } from './lib/AccessControl.js';
9
+ import { BaseContext } from './context/BaseContext.js';
10
+ import { AccessControlRule } from './lib/AccessControlRule.js';
11
+ import { ActionInvocation, InvocationRunner, MiddlewareDefinition } from './lib/Middleware.js';
12
+ import { ChannelDefinition, ChannelEntry, ChannelMatcher } from './channel/Channel.js';
13
+ import { ChannelActionInfo, DispatchOptions, EntrypointAdapter } from './channel/EntrypointAdapter.js';
14
+ import './channel/BuiltinChannels.js';
15
+ export { ContextType, BaseContext } from './context/BaseContext.js';
16
+ export { CLIContext } from './context/CLIContext.js';
17
+ export { HTTPContext } from './context/HTTPContext.js';
18
+ export { ServiceContext } from './context/ServiceContext.js';
19
+ export { ScheduleContext } from './context/ScheduleContext.js';
20
+ export { type HTTPContextParams } from './types/HTTPContextParams.js';
21
+ export { type CLIContextParams } from './types/CLIContextParams.js';
22
+ export { type ServiceContextParams } from './types/ServiceContextParams.js';
23
+ export { type ScheduleContextParams } from './types/ScheduleContextParams.js';
24
+ /**
25
+ * A CLI entrypoint in the style of lakutata 2.x: a function the entrypoint calls once when it starts (initialized: the
26
+ * objects it gets may inject the entrypoint), which reads the command line and runs its commands through the handler.
27
+ * A promise it returns is awaited, its rejection fails the entrypoint's startup (2.x did not await it). Prefer an
28
+ * adapter (`commanderCLIEntrypoint` of `lakutata/adapter/commander`) for new code.
29
+ * @param module The module owning the entrypoint (the application).
30
+ * @param cliMap The CLI actions' commands, each with the JSON schema of its input.
31
+ * @param handler Runs a command: dispatches a {@link CLIContext} to the matching action.
32
+ * @param registerDestroy Registers a function run when the entrypoint stops.
33
+ */
34
+ export type CLIEntrypoint = (module: Module, cliMap: CLIMap, handler: CLIEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => unknown;
35
+ /**
36
+ * An HTTP entrypoint in the style of lakutata 2.x: a function the entrypoint calls once when it starts (initialized:
37
+ * the objects it gets, such as an authenticator of the requests, may inject the entrypoint), which starts a server and
38
+ * passes its requests to the handler. A promise it returns is awaited, its rejection fails the entrypoint's startup
39
+ * (2.x did not await it). Prefer an adapter (`expressHTTPEntrypoint` of `lakutata/adapter/express`,
40
+ * `fastifyHTTPEntrypoint` of `lakutata/adapter/fastify`) for new code.
41
+ * @param module The module owning the entrypoint (the application).
42
+ * @param routeMap The HTTP actions' routes, each with its methods.
43
+ * @param handler Runs a request: dispatches an {@link HTTPContext} to the matching action.
44
+ * @param registerDestroy Registers a function run when the entrypoint stops (closing the server).
45
+ */
46
+ export type HTTPEntrypoint = (module: Module, routeMap: HTTPRouteMap, handler: HTTPEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => unknown;
47
+ /**
48
+ * A service entrypoint in the style of lakutata 2.x: a function the entrypoint calls once when it starts (initialized:
49
+ * the objects it gets may inject the entrypoint), which receives the service requests of a transport and passes them
50
+ * to the handler. A promise it returns is awaited, its rejection fails the entrypoint's startup (2.x did not await it).
51
+ * Prefer an adapter (`socketIOServiceEntrypoint`, `jsonRPCServiceEntrypoint`, `electronIPCServiceEntrypoint`) for new code.
52
+ * @param module The module owning the entrypoint (the application).
53
+ * @param handler Runs a request: dispatches a {@link ServiceContext} to the action whose pattern matches its input.
54
+ * @param registerDestroy Registers a function run when the entrypoint stops.
55
+ */
56
+ export type ServiceEntrypoint = (module: Module, handler: ServiceEntrypointHandler, registerDestroy: EntrypointDestroyerRegistrar) => unknown;
57
+ /**
58
+ * The CLI actions given to a {@link CLIEntrypoint}: each command mapped to the JSON schema of its input (its DTO).
59
+ */
60
+ export type CLIMap = Map<string, JSONSchema>;
61
+ /**
62
+ * The HTTP actions given to an {@link HTTPEntrypoint}: each route (with its controller prefix) mapped to the set of
63
+ * its HTTP methods (`GET`, `POST`…).
64
+ */
65
+ export type HTTPRouteMap<HTTPMethods = string> = Map<string, Set<HTTPMethods>>;
66
+ /**
67
+ * Dispatch a CLI request to the action of its command, given to a {@link CLIEntrypoint}.
68
+ * The promise resolves to the action's result; it rejects with a `ControllerActionNotFoundException` when no action
69
+ * has the command, and with the error of the input validation, the access control or the action. Aborting the
70
+ * controller cancels the request: its result is dropped and the promise resolves to `undefined`; a request aborted
71
+ * before it starts is not run at all.
72
+ * @param context The request: its command and its data (the input of the action).
73
+ * @param abortController Aborts the request, for example when its client goes away.
74
+ * @returns The action's result.
75
+ */
76
+ export type CLIEntrypointHandler<T = unknown> = (context: CLIContext, abortController?: AbortController) => Promise<T>;
77
+ /**
78
+ * Dispatch an HTTP request to the action of its route and method, given to an {@link HTTPEntrypoint}.
79
+ * The promise resolves to the action's result; it rejects with a `ControllerActionNotFoundException` when no action
80
+ * matches, and with the error of the input validation, the access control or the action. Aborting the controller
81
+ * cancels the request: its result is dropped and the promise resolves to `undefined`; a request aborted before it
82
+ * starts is not run at all.
83
+ * @param context The request: its route, method, data (the input of the action), request and response.
84
+ * @param abortController Aborts the request, for example when its connection closes.
85
+ * @returns The action's result.
86
+ */
87
+ export type HTTPEntrypointHandler<T = unknown> = (context: HTTPContext, abortController?: AbortController) => Promise<T>;
88
+ /**
89
+ * Dispatch a service request to the action whose pattern matches its input, given to a {@link ServiceEntrypoint}.
90
+ * The promise resolves to the action's result; it rejects with a `ControllerActionNotFoundException` when no action
91
+ * matches, and with the error of the input validation, the access control or the action. Aborting the controller
92
+ * cancels the request: its result is dropped and the promise resolves to `undefined`; a request aborted before it
93
+ * starts is not run at all.
94
+ * @param context The request: its data, matched against the actions' patterns (the pattern keys are removed from the
95
+ * action's input).
96
+ * @param abortController Aborts the request, for example when its client disconnects.
97
+ * @returns The action's result.
98
+ */
99
+ export type ServiceEntrypointHandler<T = unknown> = (context: ServiceContext, abortController?: AbortController) => Promise<T>;
100
+ /**
101
+ * A function releasing what a 2.x entrypoint started (a server, a connection), run when the entrypoint stops; the
102
+ * entrypoint then waits for the requests in progress.
103
+ */
104
+ export type EntrypointDestroyer = () => void | Promise<void>;
105
+ /**
106
+ * Register an {@link EntrypointDestroyer}, given to the 2.x entrypoints. The destroyers registered by an entrypoint run
107
+ * together (not in order) when it stops; their failures are thrown from the entrypoint's destruction.
108
+ * @param destroyer The function run when the entrypoint stops.
109
+ */
110
+ export type EntrypointDestroyerRegistrar = (destroyer: EntrypointDestroyer) => void;
111
+ /**
112
+ * The options of the {@link Entrypoint} component: its controllers, middlewares and access rules, and the adapters
113
+ * receiving the requests of each channel. Any other key is the name of a channel and takes that channel's adapters
114
+ * (the packages providing a channel add their key to this interface by declaration merging); an adapter given under
115
+ * another channel's key, or a key which is neither an option nor an adapter, fails the entrypoint's initialization
116
+ * with an `InvalidEntrypointAdapterException`.
117
+ * Build them with {@link buildEntrypoints}.
118
+ */
119
+ export interface EntrypointOptions {
120
+ /**
121
+ * The controller classes whose actions the entrypoint serves. They are registered in the entrypoint's container;
122
+ * an action declared in a parent controller is served by each registered subclass.
123
+ */
124
+ controllers: IBaseObjectConstructor<Controller>[];
125
+ /**
126
+ * The middlewares run around every action of every channel, in order, before the ones of the adapter, of the
127
+ * controller class and of the action.
128
+ * @default []
129
+ */
130
+ middlewares?: MiddlewareDefinition[];
131
+ /**
132
+ * The access control rule classes checked for the actions declared with `acl: true`, in order; a rule is skipped
133
+ * for the contexts not in its `supportContextTypes`.
134
+ * @default []
135
+ */
136
+ rules?: IBaseObjectConstructor<AccessControlRule>[];
137
+ /**
138
+ * The time in milliseconds given to the requests in progress when the entrypoint stops; the ones still running
139
+ * after it are aborted, and fail with an `EntrypointStoppedException`.
140
+ * @default 30000
141
+ */
142
+ shutdownTimeout?: number;
143
+ /**
144
+ * The CLI action groups: each group id (used in the actions' `groups` option) mapped to its display name. An action
145
+ * in a group not listed here fails the entrypoint's initialization with an `InvalidActionGroupException`.
146
+ * @default {}
147
+ */
148
+ cliActionGroups?: Record<string, string>;
149
+ /**
150
+ * The adapters (or 2.x entrypoint functions) receiving the CLI requests, such as `commanderCLIEntrypoint()`.
151
+ */
152
+ cli?: CLIEntrypoint | EntrypointAdapter<CLIContext> | (CLIEntrypoint | EntrypointAdapter<CLIContext>)[];
153
+ /**
154
+ * The HTTP action groups: each group id (used in the actions' `groups` option) mapped to its display name. An
155
+ * action in a group not listed here fails the entrypoint's initialization with an `InvalidActionGroupException`.
156
+ * @default {}
157
+ */
158
+ httpActionGroups?: Record<string, string>;
159
+ /**
160
+ * The adapters (or 2.x entrypoint functions) receiving the HTTP requests, such as `expressHTTPEntrypoint()`.
161
+ */
162
+ http?: HTTPEntrypoint | EntrypointAdapter<HTTPContext> | (HTTPEntrypoint | EntrypointAdapter<HTTPContext>)[];
163
+ /**
164
+ * The service action groups: each group id (used in the actions' `groups` option) mapped to its display name. An
165
+ * action in a group not listed here fails the entrypoint's initialization with an `InvalidActionGroupException`.
166
+ * @default {}
167
+ */
168
+ serviceActionGroups?: Record<string, string>;
169
+ /**
170
+ * The adapters (or 2.x entrypoint functions) receiving the service requests, such as `socketIOServiceEntrypoint()`.
171
+ */
172
+ service?: ServiceEntrypoint | EntrypointAdapter<ServiceContext> | (ServiceEntrypoint | EntrypointAdapter<ServiceContext>)[];
173
+ /**
174
+ * The schedule adapter running the actions declared with `@Schedule` (`scheduleEntrypoint()`); without it they
175
+ * never run.
176
+ */
177
+ schedule?: EntrypointAdapter<ScheduleContext> | EntrypointAdapter<ScheduleContext>[];
178
+ }
179
+ /**
180
+ * The description of a controller action in a channel, as listed by {@link Entrypoint.getActions}, given to the
181
+ * access control rules and, extended with the address, to the adapters.
182
+ */
183
+ export interface BaseActionInfo {
184
+ /**
185
+ * The action's id: a UUID derived from the controller, the method and the address, stable across restarts.
186
+ */
187
+ readonly id: string;
188
+ /**
189
+ * Whether the action is checked by the access control rules (its `acl` option).
190
+ */
191
+ readonly acl: boolean;
192
+ /**
193
+ * The action's name: its `name` option, `ControllerClass:method` by default. It is unique within a channel among
194
+ * the controller methods (the addresses of one method share its name).
195
+ */
196
+ readonly name: string;
197
+ /**
198
+ * The action's description: its `description` option, empty by default.
199
+ */
200
+ readonly description: string;
201
+ /**
202
+ * The ids of the action's groups (its `groups` option).
203
+ */
204
+ readonly groups: string[];
205
+ /**
206
+ * The class name of the controller serving the action.
207
+ */
208
+ readonly controller: string;
209
+ /**
210
+ * The name of the controller method running the action.
211
+ */
212
+ readonly method: string;
213
+ /**
214
+ * The JSON schema of the action's input (its DTO).
215
+ */
216
+ readonly jsonSchema: JSONSchema;
217
+ }
218
+ /**
219
+ * The description of an HTTP action.
220
+ */
221
+ export interface HTTPActionInfo extends BaseActionInfo {
222
+ /**
223
+ * The action's route, with its controller prefix.
224
+ */
225
+ readonly route: string;
226
+ }
227
+ /**
228
+ * The description of a service action.
229
+ */
230
+ export interface ServiceActionInfo extends BaseActionInfo {
231
+ /**
232
+ * The pattern the requests' input matches, with its controller prefix.
233
+ */
234
+ readonly pattern: ActionPattern;
235
+ }
236
+ /**
237
+ * The description of a CLI action.
238
+ */
239
+ export interface CLIActionInfo extends BaseActionInfo {
240
+ /**
241
+ * The action's command, with its controller prefix.
242
+ */
243
+ readonly command: string;
244
+ }
245
+ /**
246
+ * A group of actions of a channel, as listed by {@link Entrypoint.getActions}.
247
+ */
248
+ export interface ActionGroupInfo<T extends BaseActionInfo> {
249
+ /**
250
+ * The group's id, as used in the actions' `groups` option.
251
+ */
252
+ readonly id: string;
253
+ /**
254
+ * The group's display name, from the entrypoint's action group options (`httpActionGroups`…); `undefined` for the
255
+ * channels without such an option.
256
+ */
257
+ readonly name: string;
258
+ /**
259
+ * The actions in the group.
260
+ */
261
+ actions: T[];
262
+ }
263
+ /**
264
+ * The actions of a channel, and the groups they belong to.
265
+ */
266
+ export interface EntrypointActions<T extends BaseActionInfo> {
267
+ /**
268
+ * The groups used by the actions, each with its actions; an action may be in several groups.
269
+ */
270
+ readonly groups: ActionGroupInfo<T>[];
271
+ /**
272
+ * Every action of the channel, grouped or not.
273
+ */
274
+ readonly actions: T[];
275
+ }
276
+ /**
277
+ * Type a CLI entrypoint in the style of lakutata 2.x; the function is returned as it is.
278
+ * @param entrypoint The function the entrypoint calls when it starts, with the module, the commands, the request
279
+ * handler and the destroyer registrar.
280
+ * @returns The same function, to give to the `cli` option of {@link buildEntrypoints}.
281
+ * @example
282
+ * ```typescript
283
+ * import {Application} from 'lakutata'
284
+ * import {buildCLIEntrypoint, buildEntrypoints, CLIContext, Controller} from 'lakutata/com/entrypoint'
285
+ * import {CLIAction} from 'lakutata/decorator/ctrl'
286
+ *
287
+ * class VersionController extends Controller {
288
+ * @CLIAction('version')
289
+ * public async version(): Promise<string> {
290
+ * return '1.0.0'
291
+ * }
292
+ * }
293
+ *
294
+ * Application.run(() => ({
295
+ * id: 'tool.app',
296
+ * name: 'Tool',
297
+ * components: {
298
+ * entrypoint: buildEntrypoints({
299
+ * controllers: [VersionController],
300
+ * //Run the command given as the first argument once the entrypoint starts
301
+ * cli: buildCLIEntrypoint(async (module, cliMap, handler): Promise<void> => {
302
+ * const command: string = process.argv[2] ?? 'version'
303
+ * if (cliMap.has(command)) console.log(await handler(new CLIContext({command: command, data: {}})))
304
+ * })
305
+ * })
306
+ * }
307
+ * }))
308
+ * ```
309
+ */
310
+ export declare const buildCLIEntrypoint: (entrypoint: CLIEntrypoint) => CLIEntrypoint;
311
+ /**
312
+ * Type an HTTP entrypoint in the style of lakutata 2.x; the function is returned as it is.
313
+ * @param entrypoint The function the entrypoint calls when it starts, with the module, the routes, the request handler
314
+ * and the destroyer registrar.
315
+ * @returns The same function, to give to the `http` option of {@link buildEntrypoints}.
316
+ * @example
317
+ * ```typescript
318
+ * import {createServer, type Server} from 'node:http'
319
+ * import {Application} from 'lakutata'
320
+ * import {buildEntrypoints, buildHTTPEntrypoint, Controller, HTTPContext} from 'lakutata/com/entrypoint'
321
+ * import {GET} from 'lakutata/decorator/ctrl'
322
+ *
323
+ * class HealthController extends Controller {
324
+ * @GET('/health')
325
+ * public async health(): Promise<{status: string}> {
326
+ * return {status: 'ok'}
327
+ * }
328
+ * }
329
+ *
330
+ * Application.run(() => ({
331
+ * id: 'api.app',
332
+ * name: 'API',
333
+ * components: {
334
+ * entrypoint: buildEntrypoints({
335
+ * controllers: [HealthController],
336
+ * http: buildHTTPEntrypoint((module, routeMap, handler, registerDestroy): void => {
337
+ * const server: Server = createServer(async (request, response): Promise<void> => {
338
+ * const route: string = (request.url ?? '/').split('?')[0]
339
+ * const method: string = request.method ?? 'GET'
340
+ * if (!routeMap.get(route)?.has(method)) {
341
+ * response.writeHead(404).end()
342
+ * return
343
+ * }
344
+ * const abortController: AbortController = new AbortController()
345
+ * response.on('close', (): void => abortController.abort())
346
+ * try {
347
+ * const context: HTTPContext = new HTTPContext({route, method, request, response, data: {}})
348
+ * response.end(JSON.stringify(await handler(context, abortController)))
349
+ * } catch (error) {
350
+ * response.writeHead(500).end((error as Error).message)
351
+ * }
352
+ * }).listen(3000)
353
+ * registerDestroy((): Promise<void> => new Promise((resolve): void => void server.close((): void => resolve())))
354
+ * })
355
+ * })
356
+ * }
357
+ * }))
358
+ * ```
359
+ */
360
+ export declare const buildHTTPEntrypoint: (entrypoint: HTTPEntrypoint) => HTTPEntrypoint;
361
+ /**
362
+ * Type a service entrypoint in the style of lakutata 2.x; the function is returned as it is.
363
+ * @param entrypoint The function the entrypoint calls when it starts, with the module, the request handler and the
364
+ * destroyer registrar.
365
+ * @returns The same function, to give to the `service` option of {@link buildEntrypoints}.
366
+ * @example
367
+ * ```typescript
368
+ * import {EventEmitter} from 'node:events'
369
+ * import {Application} from 'lakutata'
370
+ * import {buildEntrypoints, buildServiceEntrypoint, Controller, ServiceContext} from 'lakutata/com/entrypoint'
371
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
372
+ *
373
+ * declare const bus: EventEmitter
374
+ *
375
+ * class MathController extends Controller {
376
+ * @ServiceAction({ctrl: 'math', act: 'add'})
377
+ * public async add(input: {a: number, b: number}): Promise<number> {
378
+ * return input.a + input.b
379
+ * }
380
+ * }
381
+ *
382
+ * Application.run(() => ({
383
+ * id: 'math.app',
384
+ * name: 'Math',
385
+ * components: {
386
+ * entrypoint: buildEntrypoints({
387
+ * controllers: [MathController],
388
+ * //Each message of the bus is a request: its data matched against the patterns of the actions
389
+ * service: buildServiceEntrypoint((module, handler, registerDestroy): void => {
390
+ * const listener = async (data: Record<string, any>, reply: (result: unknown) => void): Promise<void> => {
391
+ * reply(await handler(new ServiceContext({data: data})))
392
+ * }
393
+ * bus.on('request', listener)
394
+ * registerDestroy((): void => void bus.off('request', listener))
395
+ * })
396
+ * })
397
+ * }
398
+ * }))
399
+ * ```
400
+ */
401
+ export declare const buildServiceEntrypoint: (entrypoint: ServiceEntrypoint) => ServiceEntrypoint;
402
+ /**
403
+ * Type the options of the {@link Entrypoint} component; they are returned as they are. The applications of the
404
+ * `lakutata` package declare the entrypoint as the component `entrypoint`: give these options to it.
405
+ * @param options The controllers, middlewares, access rules and the adapters of each channel.
406
+ * @returns The same options, to declare as the `entrypoint` component.
407
+ * @example
408
+ * ```typescript
409
+ * import {Application, DTO} from 'lakutata'
410
+ * import {buildEntrypoints, Controller, scheduleEntrypoint} from 'lakutata/com/entrypoint'
411
+ * import {GET, POST, Schedule} from 'lakutata/decorator/ctrl'
412
+ * import {Expect} from 'lakutata/decorator/dto'
413
+ * import {expressHTTPEntrypoint} from 'lakutata/adapter/express'
414
+ *
415
+ * class CreateOrderDTO extends DTO {
416
+ * @Expect(DTO.String().required())
417
+ * public product: string
418
+ * }
419
+ *
420
+ * class OrderController extends Controller {
421
+ * @GET('/orders', {name: 'listOrders', groups: ['orders']})
422
+ * public async list(): Promise<string[]> {
423
+ * return []
424
+ * }
425
+ *
426
+ * @POST('/orders', CreateOrderDTO, {name: 'createOrder', groups: ['orders']})
427
+ * public async create(input: CreateOrderDTO): Promise<{product: string}> {
428
+ * return {product: input.product}
429
+ * }
430
+ *
431
+ * @Schedule('0 * * * *')
432
+ * public async purge(): Promise<void> {
433
+ * }
434
+ * }
435
+ *
436
+ * Application.run(() => ({
437
+ * id: 'shop.app',
438
+ * name: 'Shop',
439
+ * components: {
440
+ * entrypoint: buildEntrypoints({
441
+ * controllers: [OrderController],
442
+ * httpActionGroups: {orders: 'Orders'},
443
+ * shutdownTimeout: 10000,
444
+ * http: expressHTTPEntrypoint({port: 3000}),
445
+ * schedule: scheduleEntrypoint()
446
+ * })
447
+ * }
448
+ * }))
449
+ * ```
450
+ */
451
+ export declare const buildEntrypoints: (options: EntrypointOptions) => EntrypointOptions;
452
+ /**
453
+ * A dispatchable action: its details, its information and its middlewares (controller, options, method)
454
+ */
455
+ type ActionEntry = ChannelEntry & {
456
+ readonly middlewares: MiddlewareDefinition[];
457
+ readonly address: ChannelActionInfo;
458
+ };
459
+ /**
460
+ * The actions of a channel
461
+ */
462
+ type ChannelState = {
463
+ readonly definition: ChannelDefinition;
464
+ readonly entries: ActionEntry[];
465
+ readonly infos: Map<string, BaseActionInfo & Record<string, unknown>>;
466
+ readonly matcher: ChannelMatcher;
467
+ };
468
+ /**
469
+ * A request in progress
470
+ */
471
+ type InflightRequest = {
472
+ readonly abortController: AbortController;
473
+ promise?: Promise<unknown>;
474
+ };
475
+ /**
476
+ * A started adapter
477
+ */
478
+ type StartedAdapter = {
479
+ readonly adapter: EntrypointAdapter<any>;
480
+ readonly inflight: Set<InflightRequest>;
481
+ };
482
+ /**
483
+ * The entrypoint component: it serves the controllers' actions to the requests of every channel (HTTP, CLI, service,
484
+ * schedule, and the channels of other packages), each received by the adapters configured for its channel.
485
+ *
486
+ * The applications of the `lakutata` package declare it as the component `entrypoint`: configure it with
487
+ * {@link buildEntrypoints}. When it initializes, it registers the controllers and checks their actions (their groups and
488
+ * the uniqueness of their names); then, in its startup, it starts the adapters in order (the objects their hooks get may
489
+ * inject the entrypoint; the objects getting the entrypoint wait for its adapters); it is ready (the adapters acting on
490
+ * their own, such as the schedules, begin) once the application has launched. Each request runs in a scope of its own: its middlewares,
491
+ * then a new controller instance receiving its context and signal, the validation of its input, the access control
492
+ * and the action; the scope is destroyed when the request ends.
493
+ *
494
+ * When it is destroyed, it stops the adapters in reverse order: each stops receiving requests, the requests in progress
495
+ * get `shutdownTimeout` milliseconds to complete and are then aborted (failing with an `EntrypointStoppedException`),
496
+ * and the adapter is closed.
497
+ * @example
498
+ * ```typescript
499
+ * import {Application, Component} from 'lakutata'
500
+ * import {buildEntrypoints, Controller, Entrypoint, ServiceContext} from 'lakutata/com/entrypoint'
501
+ * import {GET, ServiceAction} from 'lakutata/decorator/ctrl'
502
+ * import {Inject} from 'lakutata/decorator/di'
503
+ * import {expressHTTPEntrypoint} from 'lakutata/adapter/express'
504
+ * import {socketIOServiceEntrypoint} from 'lakutata/adapter/socket.io'
505
+ *
506
+ * class ChatController extends Controller {
507
+ * @Inject('entrypoint')
508
+ * protected readonly entrypoint: Entrypoint
509
+ *
510
+ * //Served over HTTP: GET /rooms
511
+ * @GET('/rooms')
512
+ * public async rooms(): Promise<string[]> {
513
+ * return ['general']
514
+ * }
515
+ *
516
+ * //Served over Socket.IO, the message pushed to every client
517
+ * @ServiceAction({act: 'say'})
518
+ * public async say(input: {text: string}): Promise<number> {
519
+ * const from: string | undefined = (this.context as ServiceContext).clientId
520
+ * return this.entrypoint.broadcast('message', from, input.text)
521
+ * }
522
+ * }
523
+ *
524
+ * Application
525
+ * .run(() => ({
526
+ * id: 'chat.app',
527
+ * name: 'Chat',
528
+ * components: {
529
+ * entrypoint: buildEntrypoints({
530
+ * controllers: [ChatController],
531
+ * http: expressHTTPEntrypoint({port: 3000}),
532
+ * service: socketIOServiceEntrypoint({port: 3001})
533
+ * })
534
+ * }
535
+ * }))
536
+ * .onLaunched(async (app: Application): Promise<void> => {
537
+ * const entrypoint: Entrypoint = await app.getObject<Entrypoint>('entrypoint')
538
+ * console.log(entrypoint.getHttpActions().actions.map(action => action.route)) //['/rooms']
539
+ * })
540
+ * ```
541
+ */
542
+ export declare class Entrypoint extends Component {
543
+ #private;
544
+ /**
545
+ * Whether an option which is not a configurable property is accepted: the adapters given under a channel's key,
546
+ * and the 2.x entrypoint functions under `cli`, `http` and `service`. The container calls it when it checks the
547
+ * component's options.
548
+ * @param name The option's key.
549
+ * @param value The option's value: one item or an array.
550
+ * @returns `true` when every item is an adapter, or a function under a 2.x channel's key.
551
+ */
552
+ static acceptsOption(name: string, value: unknown): boolean;
553
+ /**
554
+ * The class running the access control of the actions declared with `acl: true` or a `rule`; a subclass of the
555
+ * entrypoint may replace it with a subclass of {@link AccessControl}.
556
+ * @protected
557
+ */
558
+ protected readonly accessControl: typeof AccessControl;
559
+ /**
560
+ * The controller classes whose actions the entrypoint serves.
561
+ * @default []
562
+ * @protected
563
+ */
564
+ protected readonly controllers: IBaseObjectConstructor<Controller>[];
565
+ /**
566
+ * The middlewares run around every action of every channel, before the ones of the adapter, of the controller class
567
+ * and of the action.
568
+ * @default []
569
+ * @protected
570
+ */
571
+ protected readonly middlewares: MiddlewareDefinition[];
572
+ /**
573
+ * The access control rule classes checked for the actions declared with `acl: true`.
574
+ * @default []
575
+ * @protected
576
+ */
577
+ protected readonly rules: IBaseObjectConstructor<AccessControlRule>[];
578
+ /**
579
+ * The time in milliseconds given to the requests in progress when the entrypoint stops, before they are aborted.
580
+ * @default 30000
581
+ * @protected
582
+ */
583
+ protected readonly shutdownTimeout: number;
584
+ /**
585
+ * The CLI action groups: each group id mapped to its display name.
586
+ * @default {}
587
+ * @protected
588
+ */
589
+ protected readonly cliActionGroups: Record<string, string>;
590
+ /**
591
+ * The HTTP action groups: each group id mapped to its display name.
592
+ * @default {}
593
+ * @protected
594
+ */
595
+ protected readonly httpActionGroups: Record<string, string>;
596
+ /**
597
+ * The service action groups: each group id mapped to its display name.
598
+ * @default {}
599
+ * @protected
600
+ */
601
+ protected readonly serviceActionGroups: Record<string, string>;
602
+ /**
603
+ * The adapters (or 2.x entrypoint functions) receiving the CLI requests.
604
+ * @protected
605
+ */
606
+ protected readonly cli?: CLIEntrypoint | EntrypointAdapter | (CLIEntrypoint | EntrypointAdapter)[];
607
+ /**
608
+ * The adapters (or 2.x entrypoint functions) receiving the HTTP requests.
609
+ * @protected
610
+ */
611
+ protected readonly http?: HTTPEntrypoint | EntrypointAdapter | (HTTPEntrypoint | EntrypointAdapter)[];
612
+ /**
613
+ * The adapters (or 2.x entrypoint functions) receiving the service requests.
614
+ * @protected
615
+ */
616
+ protected readonly service?: ServiceEntrypoint | EntrypointAdapter | (ServiceEntrypoint | EntrypointAdapter)[];
617
+ /**
618
+ * Register the controllers and the middleware classes and check the actions: once initialized, the entrypoint can be
619
+ * got by the other objects (its actions listed by `getHttpActions()`…), the adapters start in {@link startup}.
620
+ * @throws {InvalidMiddlewareException} When a middleware is neither a function nor a {@link Middleware} subclass.
621
+ * @throws {InvalidEntrypointAdapterException} When an option is neither an entrypoint option nor an adapter of its
622
+ * channel.
623
+ * @throws {InvalidActionGroupException} When an action is in a group missing from its channel's action groups.
624
+ * @throws {DuplicateActionNameException} When two actions of a channel have the same name.
625
+ * @protected
626
+ */
627
+ protected init(): Promise<void>;
628
+ /**
629
+ * Start the adapters in order, once the entrypoint is initialized: the objects their hooks get (an authenticator of
630
+ * the requests adding its middleware to an HTTP server) may inject the entrypoint. The objects getting the
631
+ * entrypoint wait for the adapters, and fail when one fails to start (a port in use).
632
+ * @protected
633
+ */
634
+ protected startup(): Promise<void>;
635
+ /**
636
+ * Mark the entrypoint ready: the application has launched (in a bare container, once its adapters started).
637
+ * @protected
638
+ */
639
+ protected launched(): Promise<void>;
640
+ /**
641
+ * Stop the adapters, before the scopes of the requests in progress and the controllers are destroyed (see
642
+ * {@link Entrypoint.stopAdapters}).
643
+ * @protected
644
+ */
645
+ protected beforeDestroy(): Promise<void>;
646
+ /**
647
+ * Stop the adapters in reverse order, once (a second call returns the same promise): each adapter stops receiving
648
+ * requests, its requests in progress get `shutdownTimeout` milliseconds before they are aborted, then it is closed.
649
+ * Every adapter is stopped even when another fails.
650
+ * @returns Resolves once every adapter is closed.
651
+ * @throws {AggregateError} When several adapters failed to stop or close; a single failure is thrown as it is.
652
+ * @protected
653
+ */
654
+ protected stopAdapters(): Promise<void>;
655
+ /**
656
+ * The adapters of the options: every option which is not an entrypoint option is a channel's key; a 2.x entrypoint
657
+ * function is wrapped in an adapter, the channel of an adapter carrying its definition is defined.
658
+ * @returns The adapters, in the order of the options.
659
+ * @throws {InvalidEntrypointAdapterException} When an adapter is given under another channel's key, its channel is
660
+ * not defined, or the option is neither an adapter nor a 2.x function of `cli`, `http` or `service`.
661
+ * @protected
662
+ */
663
+ protected configuredAdapters(): EntrypointAdapter<any>[];
664
+ /**
665
+ * Wrap a 2.x entrypoint function in an adapter: it is called when the adapter starts, in the entrypoint's
666
+ * {@link startup} (the entrypoint initialized: the objects it gets may inject the entrypoint, as in 2.x), and the
667
+ * promise of an asynchronous builder is awaited — its failure fails the entrypoint's startup, so the application's
668
+ * launch (2.x did not await it: the application launched without its server, the failure an unhandled rejection).
669
+ * Its registered destroyers run when the adapter stops.
670
+ * @param channel The channel: `cli`, `http` or `service`.
671
+ * @param callback The {@link CLIEntrypoint}, {@link HTTPEntrypoint} or {@link ServiceEntrypoint}.
672
+ * @returns The adapter.
673
+ * @protected
674
+ */
675
+ protected legacyAdapter(channel: string, callback: Function): EntrypointAdapter<any>;
676
+ /**
677
+ * Collect the actions of a channel: their descriptions, their middlewares and the channel's lookup.
678
+ * @param definition The channel.
679
+ * @param actions The actions bound to the entrypoint for the channel, by address.
680
+ * @returns The channel's state.
681
+ * @protected
682
+ */
683
+ protected createChannelState(definition: ChannelDefinition, actions: ActionPatternMap): ChannelState;
684
+ /**
685
+ * Check a channel's actions: their groups are defined (when the channel has action groups) and their names unique.
686
+ * @param type The channel's name used in the error messages (`HTTP`, `CLI`…).
687
+ * @param actionInfoMap The channel's action descriptions by id; nothing is checked when it is `undefined`.
688
+ * @param actionGroups The channel's action groups; the groups are not checked without them.
689
+ * @param option The option holding the action groups, named in the error message.
690
+ * @throws {InvalidActionGroupException} When an action is in a group missing from `actionGroups`.
691
+ * @throws {DuplicateActionNameException} When two actions have the same name.
692
+ * @protected
693
+ */
694
+ protected checkActions(type: string, actionInfoMap: Map<string, BaseActionInfo> | undefined, actionGroups?: Record<string, string>, option?: string): void;
695
+ /**
696
+ * Start an adapter, giving it the runtime of its channel (its actions and the dispatch functions).
697
+ * @param adapter The adapter.
698
+ * @throws {InvalidChannelException} When the adapter's channel is not defined.
699
+ * @protected
700
+ */
701
+ protected startAdapter(adapter: EntrypointAdapter<any>): Promise<void>;
702
+ /**
703
+ * Wait for a stopped adapter's requests in progress; abort the ones still running after `shutdownTimeout`
704
+ * milliseconds with an {@link EntrypointStoppedException}.
705
+ * @param started The adapter and its requests in progress.
706
+ * @protected
707
+ */
708
+ protected drain(started: StartedAdapter): Promise<void>;
709
+ /**
710
+ * Run an action in its request's container: create the controller with the request's context and signal, validate
711
+ * the input (the request's data, overridden by the address parameters), check the access and call the action
712
+ * method with the validated input.
713
+ * @param details The action.
714
+ * @param invocation The request.
715
+ * @returns The action's result.
716
+ * @throws {Error} The input validation error, the access control's denial ({@link AccessDeniedException} or the
717
+ * rule's error), or the action's error.
718
+ * @protected
719
+ */
720
+ protected runAction(details: ActionDetails, invocation: ActionInvocation): Promise<unknown>;
721
+ /**
722
+ * Validate an action's input. An invalid input of a request with a language is validated again in it, so the
723
+ * error is in that language (a valid input is validated once, with the default settings).
724
+ * @param dtoConstructor The action's DTO.
725
+ * @param data The input to validate.
726
+ * @param locale The request's language (`context.locale`).
727
+ * @returns The validated input, with its defaults and conversions applied.
728
+ * @throws {Error} The validation error.
729
+ * @protected
730
+ */
731
+ protected validateInput(dtoConstructor: typeof DTO, data: Record<string, any>, locale?: string): Promise<Record<string, any>>;
732
+ /**
733
+ * Dispatch a request to an action in a new request container, tracked as in progress for its adapter until it
734
+ * ends. A request whose signal is already aborted is not run and resolves to `undefined`.
735
+ * @param started The adapter receiving the request.
736
+ * @param entry The action.
737
+ * @param runner The action's middleware pipeline.
738
+ * @param context The request's context.
739
+ * @param options The request's abort signal and address parameters.
740
+ * @returns The action's result, `undefined` when the request is aborted by its client.
741
+ * @protected
742
+ */
743
+ protected dispatch(started: StartedAdapter, entry: ActionEntry, runner: InvocationRunner, context: BaseContext, options: DispatchOptions): Promise<unknown>;
744
+ /**
745
+ * Execute a request in a new request container, destroyed when it ends. An aborted request settles at once: its
746
+ * container is destroyed and its result or error dropped.
747
+ * @param entry The action.
748
+ * @param runner The action's middleware pipeline.
749
+ * @param context The request's context.
750
+ * @param signal The request's abort signal.
751
+ * @param params The parameters taken from the request's address.
752
+ * @returns The action's result, `undefined` when the request is aborted by its client.
753
+ * @throws {EntrypointStoppedException} When the request is aborted because the entrypoint stopped.
754
+ * @protected
755
+ */
756
+ protected execute(entry: ActionEntry, runner: InvocationRunner, context: BaseContext, signal: AbortSignal, params?: Record<string, unknown>): Promise<unknown>;
757
+ /**
758
+ * The descriptions of a channel's actions.
759
+ * @param channel The channel's name.
760
+ * @returns The descriptions, empty when the channel has no actions.
761
+ * @protected
762
+ */
763
+ protected actionInfos<T extends BaseActionInfo>(channel: string): T[];
764
+ /**
765
+ * The descriptions of the HTTP actions.
766
+ * @protected
767
+ */
768
+ protected get HTTP_ACTIONS(): HTTPActionInfo[];
769
+ /**
770
+ * The descriptions of the service actions.
771
+ * @protected
772
+ */
773
+ protected get SERVICE_ACTIONS(): ServiceActionInfo[];
774
+ /**
775
+ * The descriptions of the CLI actions.
776
+ * @protected
777
+ */
778
+ protected get CLI_ACTIONS(): CLIActionInfo[];
779
+ /**
780
+ * The actions of a channel, with the groups they belong to.
781
+ * @param channel The channel's name.
782
+ * @param actionGroups The group names by id.
783
+ * @returns The actions and their groups.
784
+ * @protected
785
+ */
786
+ protected getEntrypointActions<T extends BaseActionInfo>(channel: string, actionGroups?: Record<string, string>): EntrypointActions<T>;
787
+ /**
788
+ * The group ids used by the actions but missing from the action groups.
789
+ * @param actionInfoMap The action descriptions by id.
790
+ * @param actionGroups The group names by id.
791
+ * @returns The missing group ids, each once.
792
+ * @protected
793
+ */
794
+ protected findInvalidActionGroupIds(actionInfoMap: Map<string, BaseActionInfo>, actionGroups: Record<string, string>): string[];
795
+ /**
796
+ * The names shared by the actions of several controller methods (the addresses of one method, such as its two
797
+ * routes, share its name).
798
+ * @param actionInfoMap The action descriptions by id.
799
+ * @returns The duplicate names, each once.
800
+ * @protected
801
+ */
802
+ protected findDuplicateActionNames(actionInfoMap: Map<string, BaseActionInfo>): string[];
803
+ /**
804
+ * Check the access to an action with {@link Entrypoint.accessControl}.
805
+ * @param rules The access control rule classes.
806
+ * @param runtimeContainer The request's container, where the rules are created.
807
+ * @param context The request's context.
808
+ * @param input The validated input.
809
+ * @param details The action.
810
+ * @throws {AccessDeniedException} When a rule denies the access (or the error a rule throws).
811
+ * @protected
812
+ */
813
+ protected runAccessControl(rules: IBaseObjectConstructor<AccessControlRule>[], runtimeContainer: Container, context: CLIContext | HTTPContext | ServiceContext, input: Record<string, any>, details: ActionDetails): Promise<void>;
814
+ /**
815
+ * Push an event to a client of the adapters which have clients (an Electron window's renderer, a Socket.IO
816
+ * socket); its listeners receive the arguments. The client of a service request is its `context.clientId`.
817
+ * @param clientId The client's id.
818
+ * @param event The event's name.
819
+ * @param args The arguments given to the client's listeners.
820
+ * @returns Whether an adapter has the client; `false` when it is gone or no adapter has clients.
821
+ */
822
+ notify(clientId: string, event: string, ...args: unknown[]): boolean;
823
+ /**
824
+ * Push an event to every client of the adapters which have clients (Electron windows, Socket.IO sockets); their
825
+ * listeners receive the arguments.
826
+ * @param event The event's name.
827
+ * @param args The arguments given to the clients' listeners.
828
+ * @returns The number of clients the event was pushed to.
829
+ */
830
+ broadcast(event: string, ...args: unknown[]): number;
831
+ /**
832
+ * The HTTP action groups configured by the `httpActionGroups` option.
833
+ * @returns The group names by id.
834
+ */
835
+ getHttpActionGroups(): Record<string, string>;
836
+ /**
837
+ * The service action groups configured by the `serviceActionGroups` option.
838
+ * @returns The group names by id.
839
+ */
840
+ getServiceActionGroups(): Record<string, string>;
841
+ /**
842
+ * The CLI action groups configured by the `cliActionGroups` option.
843
+ * @returns The group names by id.
844
+ */
845
+ getCliActionGroups(): Record<string, string>;
846
+ /**
847
+ * The HTTP actions, with the groups they belong to (named after `httpActionGroups`).
848
+ * @returns The actions and their groups.
849
+ */
850
+ getHttpActions(): EntrypointActions<HTTPActionInfo>;
851
+ /**
852
+ * The service actions, with the groups they belong to (named after `serviceActionGroups`).
853
+ * @returns The actions and their groups.
854
+ */
855
+ getServiceActions(): EntrypointActions<ServiceActionInfo>;
856
+ /**
857
+ * The CLI actions, with the groups they belong to (named after `cliActionGroups`).
858
+ * @returns The actions and their groups.
859
+ */
860
+ getCliActions(): EntrypointActions<CLIActionInfo>;
861
+ /**
862
+ * The actions of any channel, with the groups they belong to; the groups have no name (use the methods of the
863
+ * built-in channels, such as {@link Entrypoint.getHttpActions}, for named groups).
864
+ * @param channel The channel's name (`http`, `cli`, `service`, `schedule`, or a channel of another package).
865
+ * @returns The actions and their groups, empty when the channel has no actions.
866
+ */
867
+ getActions<T extends BaseActionInfo = BaseActionInfo & Record<string, unknown>>(channel: string): EntrypointActions<T>;
868
+ }