@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,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScheduleChannel = exports.ServiceChannel = exports.CLIChannel = exports.HTTPChannel = void 0;
4
+ const utils_1 = require("@lakutata/utils");
5
+ const Channel_js_1 = require("./Channel.js");
6
+ const PatternManager_js_1 = require("../lib/pattern/PatternManager.js");
7
+ const StringifyPattern_js_1 = require("../lib/StringifyPattern.js");
8
+ const Prefix_js_1 = require("../lib/Prefix.js");
9
+ const BaseContext_js_1 = require("../context/BaseContext.js");
10
+ const ControllerActionNotFoundException_js_1 = require("../exceptions/ControllerActionNotFoundException.js");
11
+ const UnsetValue_js_1 = require("../lib/UnsetValue.js");
12
+ /**
13
+ * A lookup by exact key, falling back to the glob patterns
14
+ * @param entries
15
+ * @param key
16
+ * @param subject
17
+ */
18
+ function exactMatcher(entries, key, subject) {
19
+ const exact = new Map();
20
+ const patterns = new PatternManager_js_1.PatternManager();
21
+ for (const entry of entries) {
22
+ exact.set(key(entry.details.pattern), entry);
23
+ patterns.add(entry.details.pattern, entry);
24
+ }
25
+ return {
26
+ match: (context) => {
27
+ const pattern = subject(context);
28
+ const entry = exact.get(key(pattern)) ?? patterns.find(pattern);
29
+ return entry ? { entry: entry } : undefined;
30
+ }
31
+ };
32
+ }
33
+ /**
34
+ * The key of an HTTP action
35
+ * @param pattern
36
+ */
37
+ function httpKey(pattern) {
38
+ return `${pattern.method}\u0000${pattern.route}`;
39
+ }
40
+ /**
41
+ * The HTTP channel, addressed by route and method
42
+ */
43
+ exports.HTTPChannel = (0, Channel_js_1.defineChannel)({
44
+ name: 'http',
45
+ kind: 'request',
46
+ contextType: BaseContext_js_1.ContextType.HTTP,
47
+ identify: (pattern) => pattern.route,
48
+ describe: (pattern) => ({ route: pattern.route }),
49
+ prefix: (prefix, pattern) => prefix.route === undefined ? undefined : { ...pattern, route: (0, Prefix_js_1.prefixRoute)(prefix.route, pattern.route) },
50
+ createMatcher: (entries) => exactMatcher(entries, httpKey, (context) => ({
51
+ route: context.route,
52
+ method: context.method
53
+ })),
54
+ notFound: (context) => new ControllerActionNotFoundException_js_1.ControllerActionNotFoundException('Route \'{route}\' not found', context)
55
+ });
56
+ /**
57
+ * The CLI channel, addressed by command
58
+ */
59
+ exports.CLIChannel = (0, Channel_js_1.defineChannel)({
60
+ name: 'cli',
61
+ kind: 'request',
62
+ contextType: BaseContext_js_1.ContextType.CLI,
63
+ identify: (pattern) => pattern.command,
64
+ describe: (pattern) => ({ command: pattern.command }),
65
+ prefix: (prefix, pattern) => prefix.command === undefined ? undefined : { command: (0, Prefix_js_1.prefixCommand)(prefix.command, pattern.command) },
66
+ createMatcher: (entries) => exactMatcher(entries, (pattern) => pattern.command, (context) => ({ command: context.command })),
67
+ notFound: () => new ControllerActionNotFoundException_js_1.ControllerActionNotFoundException('Command not found')
68
+ });
69
+ /**
70
+ * The service channel, addressed by pattern
71
+ */
72
+ exports.ServiceChannel = (0, Channel_js_1.defineChannel)({
73
+ name: 'service',
74
+ kind: 'request',
75
+ contextType: BaseContext_js_1.ContextType.SERVICE,
76
+ identify: (pattern) => (0, StringifyPattern_js_1.stringifyPattern)(pattern),
77
+ describe: (pattern) => ({ pattern: pattern }),
78
+ prefix: (prefix, pattern) => prefix.pattern === undefined ? undefined : (0, Prefix_js_1.prefixPattern)(prefix.pattern, pattern),
79
+ createMatcher: (entries) => {
80
+ const patterns = new PatternManager_js_1.PatternManager();
81
+ for (const entry of entries)
82
+ patterns.add(entry.details.pattern, entry);
83
+ return {
84
+ match: (context) => {
85
+ const entry = patterns.find(context.input);
86
+ return entry ? { entry: entry } : undefined;
87
+ }
88
+ };
89
+ },
90
+ //The keys of the pattern are not a part of the action input
91
+ prepare: (entry, context) => {
92
+ const patternPaths = (0, utils_1.getObjectPropertyPaths)(entry.details.pattern);
93
+ patternPaths.forEach((path) => (0, UnsetValue_js_1.unsetValue)(context.data, path));
94
+ const checkPatternPaths = (0, utils_1.uniqueArray)(patternPaths
95
+ .map((path) => path.substring(0, path.lastIndexOf('.')))
96
+ .filter((path) => !!path));
97
+ checkPatternPaths.forEach((path) => {
98
+ let target = context.data;
99
+ path.split('.').forEach((key) => target = target[key] ? target[key] : undefined);
100
+ if (target && !Object.keys(target).length)
101
+ (0, UnsetValue_js_1.unsetValue)(context.data, path);
102
+ });
103
+ },
104
+ notFound: () => new ControllerActionNotFoundException_js_1.ControllerActionNotFoundException('Controller action not found')
105
+ });
106
+ /**
107
+ * The schedule channel: no external caller, each action is run by the timers of the schedule adapter.
108
+ * The address of an action is its schedule, with the key telling apart the actions of a same schedule
109
+ */
110
+ exports.ScheduleChannel = (0, Channel_js_1.defineChannel)({
111
+ name: 'schedule',
112
+ kind: 'trigger',
113
+ contextType: BaseContext_js_1.ContextType.SCHEDULE,
114
+ identify: (pattern) => `${pattern.schedule}#${pattern.key}`,
115
+ describe: (pattern) => {
116
+ const { key, ...schedule } = pattern;
117
+ void key;
118
+ return schedule;
119
+ },
120
+ createMatcher: (entries) => ({
121
+ //The runs are dispatched to their action: a context is matched by its schedule
122
+ match: (context) => {
123
+ const entry = entries.find((candidate) => candidate.details.pattern.schedule === context.schedule);
124
+ return entry ? { entry: entry } : undefined;
125
+ }
126
+ }),
127
+ notFound: (context) => new ControllerActionNotFoundException_js_1.ControllerActionNotFoundException('No action is scheduled {schedule}', { schedule: context.schedule })
128
+ });
@@ -0,0 +1,196 @@
1
+ import type { ActionPattern } from '@lakutata/core';
2
+ import type { BaseContext } from '../context/BaseContext.js';
3
+ import type { ActionDetails } from '../lib/ControllerEntrypoint.js';
4
+ import type { PrefixOptions } from '../lib/Prefix.js';
5
+ import type { BaseActionInfo } from '../Entrypoint.js';
6
+ /**
7
+ * How the requests of a channel arrive:
8
+ * - `request`: a caller waits for the result (HTTP, CLI, service, MCP, D-Bus).
9
+ * - `delivery`: no caller waits, the adapter acknowledges the outcome (message queues).
10
+ * - `trigger`: no external caller, the adapter runs the actions on its own (schedules).
11
+ */
12
+ export type ChannelKind = 'request' | 'delivery' | 'trigger';
13
+ /**
14
+ * An action of a channel, as given to {@link ChannelDefinition.createMatcher}: one per address.
15
+ */
16
+ export interface ChannelEntry {
17
+ /**
18
+ * The action's details: its address (`details.pattern`), controller, method, DTO and options.
19
+ */
20
+ readonly details: ActionDetails;
21
+ /**
22
+ * The action's description, with the fields of {@link ChannelDefinition.describe}.
23
+ */
24
+ readonly info: BaseActionInfo & Record<string, unknown>;
25
+ }
26
+ /**
27
+ * The action matching a request, with the parameters taken from its address.
28
+ */
29
+ export interface ChannelMatch {
30
+ /**
31
+ * The matching action: one of the entries given to {@link ChannelDefinition.createMatcher}.
32
+ */
33
+ readonly entry: ChannelEntry;
34
+ /**
35
+ * The parameters taken from the request's address (such as route parameters); they are merged into the action's
36
+ * input and take precedence over the request's data.
37
+ */
38
+ readonly params?: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * The lookup of a channel's actions, created by {@link ChannelDefinition.createMatcher}.
42
+ */
43
+ export interface ChannelMatcher {
44
+ /**
45
+ * Find the action of a request.
46
+ * @param context The request's context.
47
+ * @returns The matching action, `undefined` when none matches (the request then fails with
48
+ * {@link ChannelDefinition.notFound}).
49
+ */
50
+ match(context: BaseContext): ChannelMatch | undefined;
51
+ }
52
+ /**
53
+ * A channel: how the actions declare their addresses and how a request finds its action. The entrypoint package
54
+ * defines `http`, `cli`, `service` and `schedule`; a package providing another transport defines its channel with
55
+ * {@link defineChannel} and registers the actions of its decorators with `registerControllerAction`.
56
+ */
57
+ export interface ChannelDefinition {
58
+ /**
59
+ * The channel's name, which is also the key of its adapters in the entrypoint options.
60
+ */
61
+ readonly name: string;
62
+ /**
63
+ * How the channel's requests arrive.
64
+ */
65
+ readonly kind: ChannelKind;
66
+ /**
67
+ * The `type` of the channel's request contexts; the access control rules are selected by it.
68
+ */
69
+ readonly contextType: string;
70
+ /**
71
+ * Check, and possibly normalize, an address when an action is declared and when a controller prefix is applied to
72
+ * it; throw to reject it.
73
+ * @param address The address given to the action decorator.
74
+ * @returns The address to register.
75
+ */
76
+ validate?(address: ActionPattern): ActionPattern;
77
+ /**
78
+ * The text identifying an address, from which the action's id is derived: two addresses with the same text are
79
+ * the same action.
80
+ * @param address The action's address.
81
+ * @returns The identifying text.
82
+ */
83
+ identify(address: ActionPattern): string;
84
+ /**
85
+ * The fields describing an address in the action's description (such as `{route}` for HTTP).
86
+ * @param address The action's address.
87
+ * @returns The fields added to the action's description.
88
+ */
89
+ describe(address: ActionPattern): Record<string, unknown>;
90
+ /**
91
+ * Apply a controller's prefixes to an address; without this method the channel's addresses are not prefixed.
92
+ * @param prefix The controller's prefixes (set with `@Prefix`).
93
+ * @param address The action's address.
94
+ * @returns The prefixed address, `undefined` when the prefixes do not concern the channel.
95
+ */
96
+ prefix?(prefix: PrefixOptions, address: ActionPattern): ActionPattern | undefined;
97
+ /**
98
+ * Create the lookup of the channel's actions, once when the entrypoint starts.
99
+ * @param entries The channel's actions, one per address.
100
+ * @returns The lookup.
101
+ */
102
+ createMatcher(entries: ChannelEntry[]): ChannelMatcher;
103
+ /**
104
+ * Prepare a matched request's context before its dispatch (the service channel removes the pattern keys from the
105
+ * data). Not called for the requests dispatched to an action directly (`ChannelRuntime.dispatchTo`).
106
+ * @param entry The matched action.
107
+ * @param context The request's context, changed in place.
108
+ */
109
+ prepare?(entry: ChannelEntry, context: BaseContext): void;
110
+ /**
111
+ * The error a request matching no action fails with.
112
+ * @param context The request's context.
113
+ * @returns The error to throw.
114
+ */
115
+ notFound(context: BaseContext): Error;
116
+ }
117
+ /**
118
+ * Define a channel. A package providing a channel defines it when it is loaded; defining the same definition object
119
+ * again does nothing.
120
+ * @param definition The channel's definition.
121
+ * @returns The same definition.
122
+ * @throws {InvalidChannelException} When another definition already has the name.
123
+ * @example
124
+ * ```typescript
125
+ * import {Controller, ControllerActionNotFoundException, type BaseContext, type ControllerProperty} from 'lakutata/com/entrypoint'
126
+ * import {defineChannel, registerControllerAction, type ChannelEntry} from '@lakutata/entrypoint/channel'
127
+ * import {FlexibleDTO} from 'lakutata/dtos'
128
+ *
129
+ * //A channel of the messages of a queue, addressed by their topic
130
+ * export const QueueChannel = defineChannel({
131
+ * name: 'queue',
132
+ * kind: 'delivery',
133
+ * contextType: 'QUEUE',
134
+ * identify: (address): string => address.topic,
135
+ * describe: (address): Record<string, unknown> => ({topic: address.topic}),
136
+ * createMatcher: (entries: ChannelEntry[]) => ({
137
+ * match: (context: BaseContext) => {
138
+ * const entry: ChannelEntry | undefined = entries.find(candidate => candidate.details.pattern.topic === context.topic)
139
+ * return entry ? {entry: entry} : undefined
140
+ * }
141
+ * }),
142
+ * notFound: (context: BaseContext): Error => new ControllerActionNotFoundException('No action handles the topic {topic}', {topic: context.topic})
143
+ * })
144
+ *
145
+ * //The decorator declaring the actions of the channel
146
+ * export function OnMessage(topic: string) {
147
+ * return <ClassPrototype extends Controller>(target: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>): void => {
148
+ * registerControllerAction(QueueChannel, target, propertyKey, {topic: topic}, FlexibleDTO, {})
149
+ * }
150
+ * }
151
+ * ```
152
+ */
153
+ export declare function defineChannel<Definition extends ChannelDefinition>(definition: Definition): Definition;
154
+ /**
155
+ * Get a defined channel.
156
+ * @param name The channel's name.
157
+ * @returns The channel's definition.
158
+ * @throws {InvalidChannelException} When no channel has the name.
159
+ * @example
160
+ * ```typescript
161
+ * import {getChannel, type ChannelDefinition} from '@lakutata/entrypoint/channel'
162
+ *
163
+ * const http: ChannelDefinition = getChannel('http')
164
+ * console.log(http.kind, http.contextType) //request HTTP
165
+ * ```
166
+ */
167
+ export declare function getChannel(name: string): ChannelDefinition;
168
+ /**
169
+ * Whether a channel is defined.
170
+ * @param name The channel's name.
171
+ * @returns `true` when a channel has the name.
172
+ * @example
173
+ * ```typescript
174
+ * import {hasChannel} from '@lakutata/entrypoint/channel'
175
+ *
176
+ * console.log(hasChannel('schedule')) //true
177
+ * console.log(hasChannel('queue')) //false until a package defines it
178
+ * ```
179
+ */
180
+ export declare function hasChannel(name: string): boolean;
181
+ /**
182
+ * Find the channel whose requests have a context type.
183
+ * @param contextType The `type` of a request context (`HTTP`, `CLI`…).
184
+ * @returns The first channel defined with the context type, `undefined` when there is none.
185
+ * @example
186
+ * ```typescript
187
+ * import {ContextType, type BaseContext} from 'lakutata/com/entrypoint'
188
+ * import {getChannelByContextType} from '@lakutata/entrypoint/channel'
189
+ *
190
+ * declare const context: BaseContext
191
+ *
192
+ * console.log(getChannelByContextType(ContextType.SERVICE)?.name) //service
193
+ * console.log(getChannelByContextType(context.type)?.name)
194
+ * ```
195
+ */
196
+ export declare function getChannelByContextType(contextType: string): ChannelDefinition | undefined;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineChannel = defineChannel;
4
+ exports.getChannel = getChannel;
5
+ exports.hasChannel = hasChannel;
6
+ exports.getChannelByContextType = getChannelByContextType;
7
+ const InvalidChannelException_js_1 = require("../exceptions/InvalidChannelException.js");
8
+ const channels = new Map();
9
+ /**
10
+ * Define a channel. A package providing a channel defines it when it is loaded; defining the same definition object
11
+ * again does nothing.
12
+ * @param definition The channel's definition.
13
+ * @returns The same definition.
14
+ * @throws {InvalidChannelException} When another definition already has the name.
15
+ * @example
16
+ * ```typescript
17
+ * import {Controller, ControllerActionNotFoundException, type BaseContext, type ControllerProperty} from 'lakutata/com/entrypoint'
18
+ * import {defineChannel, registerControllerAction, type ChannelEntry} from '@lakutata/entrypoint/channel'
19
+ * import {FlexibleDTO} from 'lakutata/dtos'
20
+ *
21
+ * //A channel of the messages of a queue, addressed by their topic
22
+ * export const QueueChannel = defineChannel({
23
+ * name: 'queue',
24
+ * kind: 'delivery',
25
+ * contextType: 'QUEUE',
26
+ * identify: (address): string => address.topic,
27
+ * describe: (address): Record<string, unknown> => ({topic: address.topic}),
28
+ * createMatcher: (entries: ChannelEntry[]) => ({
29
+ * match: (context: BaseContext) => {
30
+ * const entry: ChannelEntry | undefined = entries.find(candidate => candidate.details.pattern.topic === context.topic)
31
+ * return entry ? {entry: entry} : undefined
32
+ * }
33
+ * }),
34
+ * notFound: (context: BaseContext): Error => new ControllerActionNotFoundException('No action handles the topic {topic}', {topic: context.topic})
35
+ * })
36
+ *
37
+ * //The decorator declaring the actions of the channel
38
+ * export function OnMessage(topic: string) {
39
+ * return <ClassPrototype extends Controller>(target: ClassPrototype, propertyKey: ControllerProperty<ClassPrototype>): void => {
40
+ * registerControllerAction(QueueChannel, target, propertyKey, {topic: topic}, FlexibleDTO, {})
41
+ * }
42
+ * }
43
+ * ```
44
+ */
45
+ function defineChannel(definition) {
46
+ const defined = channels.get(definition.name);
47
+ if (defined && defined !== definition)
48
+ throw new InvalidChannelException_js_1.InvalidChannelException('The channel "{0}" is already defined', [definition.name]);
49
+ channels.set(definition.name, definition);
50
+ return definition;
51
+ }
52
+ /**
53
+ * Get a defined channel.
54
+ * @param name The channel's name.
55
+ * @returns The channel's definition.
56
+ * @throws {InvalidChannelException} When no channel has the name.
57
+ * @example
58
+ * ```typescript
59
+ * import {getChannel, type ChannelDefinition} from '@lakutata/entrypoint/channel'
60
+ *
61
+ * const http: ChannelDefinition = getChannel('http')
62
+ * console.log(http.kind, http.contextType) //request HTTP
63
+ * ```
64
+ */
65
+ function getChannel(name) {
66
+ const definition = channels.get(name);
67
+ if (!definition)
68
+ throw new InvalidChannelException_js_1.InvalidChannelException('The channel "{0}" is not defined', [name]);
69
+ return definition;
70
+ }
71
+ /**
72
+ * Whether a channel is defined.
73
+ * @param name The channel's name.
74
+ * @returns `true` when a channel has the name.
75
+ * @example
76
+ * ```typescript
77
+ * import {hasChannel} from '@lakutata/entrypoint/channel'
78
+ *
79
+ * console.log(hasChannel('schedule')) //true
80
+ * console.log(hasChannel('queue')) //false until a package defines it
81
+ * ```
82
+ */
83
+ function hasChannel(name) {
84
+ return channels.has(name);
85
+ }
86
+ /**
87
+ * Find the channel whose requests have a context type.
88
+ * @param contextType The `type` of a request context (`HTTP`, `CLI`…).
89
+ * @returns The first channel defined with the context type, `undefined` when there is none.
90
+ * @example
91
+ * ```typescript
92
+ * import {ContextType, type BaseContext} from 'lakutata/com/entrypoint'
93
+ * import {getChannelByContextType} from '@lakutata/entrypoint/channel'
94
+ *
95
+ * declare const context: BaseContext
96
+ *
97
+ * console.log(getChannelByContextType(ContextType.SERVICE)?.name) //service
98
+ * console.log(getChannelByContextType(context.type)?.name)
99
+ * ```
100
+ */
101
+ function getChannelByContextType(contextType) {
102
+ for (const definition of channels.values())
103
+ if (definition.contextType === contextType)
104
+ return definition;
105
+ return undefined;
106
+ }
@@ -0,0 +1,195 @@
1
+ import type { ActionPattern, BaseObject, DTO, IBaseObjectConstructor, JSONSchema, Module, Schema } from '@lakutata/core';
2
+ import type { Controller } from '../lib/Controller.js';
3
+ import type { BaseContext } from '../context/BaseContext.js';
4
+ import type { BaseActionInfo } from '../Entrypoint.js';
5
+ import type { MiddlewareDefinition } from '../lib/Middleware.js';
6
+ import type { ChannelDefinition } from './Channel.js';
7
+ /**
8
+ * The options of a request dispatched by an adapter ({@link ChannelRuntime.dispatch}).
9
+ */
10
+ export interface DispatchOptions {
11
+ /**
12
+ * Aborts the request (its client went away, its deadline passed): the controller's `signal` aborts, the request's
13
+ * container is destroyed and the dispatch resolves to `undefined` at once. A request whose signal is already
14
+ * aborted is not run.
15
+ */
16
+ readonly signal?: AbortSignal;
17
+ /**
18
+ * The parameters the transport took from the request's address (such as route parameters); they are merged into
19
+ * the action's input and take precedence over the request's data and the matcher's parameters.
20
+ */
21
+ readonly params?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * The description of an action given to the adapters ({@link ChannelRuntime.actions}): one per address (an HTTP route
25
+ * declared for two methods has two), with the fields of its channel (`route`, `command`, `pattern`…).
26
+ */
27
+ export type ChannelActionInfo = BaseActionInfo & Record<string, unknown> & {
28
+ /**
29
+ * The action's address in its channel (`{route, method}` for HTTP, `{command}` for CLI, the pattern for service),
30
+ * with its controller prefix.
31
+ */
32
+ readonly address: ActionPattern;
33
+ /**
34
+ * The DTO validating the action's input (`FlexibleDTO`, accepting any input, when the action declares none).
35
+ */
36
+ readonly dto: typeof DTO;
37
+ /**
38
+ * The schema of the action's result, declared with `@Return`; `undefined` without it.
39
+ */
40
+ readonly returnSchema: Schema | undefined;
41
+ };
42
+ /**
43
+ * What the entrypoint gives an adapter when it starts it ({@link EntrypointAdapter.start}): the channel's actions and
44
+ * the functions dispatching the requests to them.
45
+ */
46
+ export interface ChannelRuntime<Context extends BaseContext = BaseContext> {
47
+ /**
48
+ * The adapter's channel.
49
+ */
50
+ readonly channel: ChannelDefinition;
51
+ /**
52
+ * The module owning the entrypoint (the application).
53
+ */
54
+ readonly module: Module;
55
+ /**
56
+ * The channel's actions, one per address.
57
+ */
58
+ readonly actions: ReadonlyArray<ChannelActionInfo>;
59
+ /**
60
+ * The entrypoint's controller classes, for the channels serving what the controllers declare besides their actions
61
+ * (their prefixes, their metadata).
62
+ */
63
+ readonly controllers: ReadonlyArray<IBaseObjectConstructor<Controller>>;
64
+ /**
65
+ * Get an object from the entrypoint's container, such as a component the adapter uses (an autoloaded class is
66
+ * registered on first use).
67
+ * @param target The object's registration name or symbol, or its class.
68
+ * @returns The object, once created and initialized.
69
+ * @throws {Error} When the object is not registered or fails to be created.
70
+ */
71
+ getObject<T extends BaseObject>(target: string | symbol | IBaseObjectConstructor<T>): Promise<T>;
72
+ /**
73
+ * Resolves once every adapter of the entrypoint started and the application launched (its objects and its
74
+ * bootstrap are ready), for the adapters acting on their own rather than on requests (running a command,
75
+ * triggering the schedules). Without an application (a bare container) it never resolves unless the entrypoint's
76
+ * `launched()` is called.
77
+ */
78
+ readonly ready: Promise<void>;
79
+ /**
80
+ * Dispatch a request to the action it matches: the request runs in a container of its own, through the
81
+ * middlewares, the input validation, the access control and the action. It is tracked as in progress until it
82
+ * ends, so the entrypoint waits for it when it stops.
83
+ * @param context The request's context, of the channel's context class.
84
+ * @param options The request's abort signal and address parameters.
85
+ * @returns The action's result; `undefined` when the request is aborted by its signal.
86
+ * @throws {Error} The channel's not-found error when no action matches (`ControllerActionNotFoundException` for
87
+ * the built-in channels), the input validation error, the access control's denial (`AccessDeniedException`), the
88
+ * error of a middleware or of the action, or `EntrypointStoppedException` when the entrypoint stopped before the
89
+ * request completed.
90
+ */
91
+ dispatch(context: Context, options?: DispatchOptions): Promise<unknown>;
92
+ /**
93
+ * Dispatch a request to a given action without matching it, for the channels binding a trigger to each action
94
+ * (schedules, subscriptions); the request runs as with {@link ChannelRuntime.dispatch}.
95
+ * @param action One of the objects of {@link ChannelRuntime.actions} (compared by identity, not a copy).
96
+ * @param context The request's context, of the channel's context class.
97
+ * @param options The request's abort signal and address parameters.
98
+ * @returns The action's result; `undefined` when the request is aborted by its signal.
99
+ * @throws {Error} The channel's not-found error when the action is not one of the runtime's, and the errors of
100
+ * {@link ChannelRuntime.dispatch}.
101
+ */
102
+ dispatchTo(action: ChannelActionInfo, context: Context, options?: DispatchOptions): Promise<unknown>;
103
+ }
104
+ /**
105
+ * An adapter: a transport receiving a channel's requests (an HTTP server, a CLI parser, a socket server, the
106
+ * scheduler). It is given to the entrypoint options under its channel's key; the entrypoint starts it when it
107
+ * initializes and stops it, then closes it, when it is destroyed. The adapter packages export functions creating them
108
+ * (`expressHTTPEntrypoint()`, `scheduleEntrypoint()`…).
109
+ */
110
+ export interface EntrypointAdapter<Context extends BaseContext = BaseContext> {
111
+ /**
112
+ * The adapter's channel, which is also its key in the entrypoint options.
113
+ */
114
+ readonly channel: string;
115
+ /**
116
+ * The channel's definition, defined by the entrypoint before it starts the adapter (for the packages defining their
117
+ * channel with their adapter).
118
+ */
119
+ readonly definition?: ChannelDefinition;
120
+ /**
121
+ * The adapter's name, to tell apart the adapters of a channel.
122
+ */
123
+ readonly name?: string;
124
+ /**
125
+ * The middlewares run around the requests of this adapter, after the entrypoint's and before the controller's and
126
+ * the action's.
127
+ */
128
+ readonly middlewares?: MiddlewareDefinition[];
129
+ /**
130
+ * Start receiving requests. The entrypoint starts its adapters one after the other and awaits each; a rejection
131
+ * fails the entrypoint's initialization.
132
+ * @param runtime The channel's actions and the functions dispatching the requests.
133
+ */
134
+ start(runtime: ChannelRuntime<Context>): void | Promise<void>;
135
+ /**
136
+ * Stop receiving requests; the entrypoint then waits for the requests in progress (aborting them after its
137
+ * `shutdownTimeout`) before it calls {@link EntrypointAdapter.close}.
138
+ */
139
+ stop?(): void | Promise<void>;
140
+ /**
141
+ * Release the resources (connections, servers) once the requests in progress ended or were aborted.
142
+ */
143
+ close?(): void | Promise<void>;
144
+ /**
145
+ * Push an event to a client of the adapter (a window's renderer, a socket); its listeners receive the arguments.
146
+ * Called by {@link Entrypoint.notify}.
147
+ * @param clientId The client's id, as set in its requests' contexts (`ServiceContext.clientId`).
148
+ * @param event The event's name.
149
+ * @param args The arguments given to the client's listeners.
150
+ * @returns Whether the adapter has the client.
151
+ */
152
+ notify?(clientId: string, event: string, args: unknown[]): boolean;
153
+ /**
154
+ * Push an event to every client of the adapter. Called by {@link Entrypoint.broadcast}.
155
+ * @param event The event's name.
156
+ * @param args The arguments given to the clients' listeners.
157
+ * @returns The number of clients the event was pushed to.
158
+ */
159
+ broadcast?(event: string, args: unknown[]): number;
160
+ }
161
+ /**
162
+ * Whether a value is an adapter: an object with a string `channel` and a `start` function.
163
+ * @param value The value to check.
164
+ * @returns `true` when the value is an adapter.
165
+ * @example
166
+ * ```typescript
167
+ * import {expressHTTPEntrypoint} from 'lakutata/adapter/express'
168
+ * import {isEntrypointAdapter} from '@lakutata/entrypoint/channel'
169
+ *
170
+ * console.log(isEntrypointAdapter(expressHTTPEntrypoint())) //true
171
+ * console.log(isEntrypointAdapter({channel: 'http'})) //false: no start function
172
+ * ```
173
+ */
174
+ export declare function isEntrypointAdapter(value: unknown): value is EntrypointAdapter;
175
+ /**
176
+ * Map the commands of CLI actions to the JSON schemas of their input, as a CLI adapter builds its commands from.
177
+ * @param actions The CLI channel's actions ({@link ChannelRuntime.actions} of a CLI adapter).
178
+ * @returns Each command mapped to its input's JSON schema; an action without command is mapped under `undefined`.
179
+ * @example
180
+ * ```typescript
181
+ * import {type CLIContext, type EntrypointAdapter} from 'lakutata/com/entrypoint'
182
+ * import {commandMap} from '@lakutata/entrypoint/channel'
183
+ *
184
+ * //A CLI adapter printing the commands and their options
185
+ * export const HelpCLIEntrypoint: EntrypointAdapter<CLIContext> = {
186
+ * channel: 'cli',
187
+ * start: (runtime): void => {
188
+ * for (const [command, schema] of commandMap(runtime.actions)) {
189
+ * console.log(command, Object.keys(schema.properties ?? {}).join(' '))
190
+ * }
191
+ * }
192
+ * }
193
+ * ```
194
+ */
195
+ export declare function commandMap(actions: ReadonlyArray<ChannelActionInfo>): Map<string, JSONSchema>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEntrypointAdapter = isEntrypointAdapter;
4
+ exports.commandMap = commandMap;
5
+ /**
6
+ * Whether a value is an adapter: an object with a string `channel` and a `start` function.
7
+ * @param value The value to check.
8
+ * @returns `true` when the value is an adapter.
9
+ * @example
10
+ * ```typescript
11
+ * import {expressHTTPEntrypoint} from 'lakutata/adapter/express'
12
+ * import {isEntrypointAdapter} from '@lakutata/entrypoint/channel'
13
+ *
14
+ * console.log(isEntrypointAdapter(expressHTTPEntrypoint())) //true
15
+ * console.log(isEntrypointAdapter({channel: 'http'})) //false: no start function
16
+ * ```
17
+ */
18
+ function isEntrypointAdapter(value) {
19
+ return !!value && typeof value === 'object' && typeof value.channel === 'string' && typeof value.start === 'function';
20
+ }
21
+ /**
22
+ * Map the commands of CLI actions to the JSON schemas of their input, as a CLI adapter builds its commands from.
23
+ * @param actions The CLI channel's actions ({@link ChannelRuntime.actions} of a CLI adapter).
24
+ * @returns Each command mapped to its input's JSON schema; an action without command is mapped under `undefined`.
25
+ * @example
26
+ * ```typescript
27
+ * import {type CLIContext, type EntrypointAdapter} from 'lakutata/com/entrypoint'
28
+ * import {commandMap} from '@lakutata/entrypoint/channel'
29
+ *
30
+ * //A CLI adapter printing the commands and their options
31
+ * export const HelpCLIEntrypoint: EntrypointAdapter<CLIContext> = {
32
+ * channel: 'cli',
33
+ * start: (runtime): void => {
34
+ * for (const [command, schema] of commandMap(runtime.actions)) {
35
+ * console.log(command, Object.keys(schema.properties ?? {}).join(' '))
36
+ * }
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ function commandMap(actions) {
42
+ return new Map(actions.map((action) => [action.command, action.jsonSchema]));
43
+ }