@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,194 @@
1
+ import type { ChannelRuntime } from '../../channel/EntrypointAdapter.js';
2
+ import { ServiceContext } from '../../context/ServiceContext.js';
3
+ /**
4
+ * The error codes of the JSON-RPC 2.0 responses sent by {@link jsonRPCServiceEntrypoint}.
5
+ */
6
+ export declare const JSONRPCErrorCode: {
7
+ /**
8
+ * The message is not valid JSON.
9
+ */
10
+ readonly PARSE_ERROR: -32700;
11
+ /**
12
+ * The message is not a JSON-RPC 2.0 request (or is an empty batch, or the HTTP request is not a `POST` to the path).
13
+ */
14
+ readonly INVALID_REQUEST: -32600;
15
+ /**
16
+ * No service action matches the request (`ControllerActionNotFoundException`).
17
+ */
18
+ readonly METHOD_NOT_FOUND: -32601;
19
+ /**
20
+ * The params are given by position without the `positionalParams` option, or fail the action's input validation
21
+ * (`InvalidValueException`).
22
+ */
23
+ readonly INVALID_PARAMS: -32602;
24
+ /**
25
+ * Reserved by the specification for the internal errors; the adapter does not send it.
26
+ */
27
+ readonly INTERNAL_ERROR: -32603;
28
+ /**
29
+ * Any other error thrown by an action (in the server error range, -32000 to -32099), with the whole error object as
30
+ * the error's `data`.
31
+ */
32
+ readonly SERVER_ERROR: -32000;
33
+ /**
34
+ * The entrypoint is stopping and refuses the new requests (`EntrypointStoppedException`).
35
+ */
36
+ readonly STOPPING: -32001;
37
+ };
38
+ /**
39
+ * A JSON-RPC 2.0 request, as a client sends it. Without an `id`, it is a notification: the action runs but no response
40
+ * is sent.
41
+ */
42
+ export type JSONRPCRequest = {
43
+ /**
44
+ * The protocol version, always `'2.0'`.
45
+ */
46
+ jsonrpc: '2.0';
47
+ /**
48
+ * The method, mapped to the service action's pattern (see `JSONRPCMappingOptions`).
49
+ */
50
+ method: string;
51
+ /**
52
+ * The params: by name (an object, merged into the action's input), or by position (an array, accepted only with the
53
+ * `positionalParams` option).
54
+ */
55
+ params?: Record<string, unknown> | unknown[];
56
+ /**
57
+ * The request id, echoed in its response; omitted for a notification.
58
+ */
59
+ id?: string | number | null;
60
+ };
61
+ /**
62
+ * A JSON-RPC 2.0 response, as the adapter sends it: either `result` or `error`.
63
+ */
64
+ export type JSONRPCResponse = {
65
+ /**
66
+ * The protocol version, always `'2.0'`.
67
+ */
68
+ jsonrpc: '2.0';
69
+ /**
70
+ * The id of the request answered; `null` when it could not be read (a parse error, an invalid request).
71
+ */
72
+ id: string | number | null;
73
+ /**
74
+ * The action's result, `null` when it returned nothing.
75
+ */
76
+ result?: unknown;
77
+ /**
78
+ * The error: its code (see {@link JSONRPCErrorCode}), its message, and for an action's error the whole error object as
79
+ * `data`.
80
+ */
81
+ error?: {
82
+ code: number;
83
+ message: string;
84
+ data?: unknown;
85
+ };
86
+ };
87
+ /**
88
+ * How {@link jsonRPCServiceEntrypoint} maps a JSON-RPC request to a service action's pattern and input.
89
+ */
90
+ export type JSONRPCMappingOptions = {
91
+ /**
92
+ * The pattern field receiving the request's method: with `'method'`, `{"method": "user.get", "params": {"id": 1}}`
93
+ * is dispatched as `{method: 'user.get', id: 1}`, the action declared with `@ServiceAction({method: 'user.get'})`.
94
+ * @default 'method'
95
+ */
96
+ methodField?: string;
97
+ /**
98
+ * Build the pattern and the input of a request's action from its method and its params, replacing `methodField` and
99
+ * `positionalParams`. A thrown error answers the request with `INVALID_PARAMS`.
100
+ */
101
+ toPattern?: (method: string, params: Record<string, unknown> | unknown[] | undefined) => Record<string, unknown>;
102
+ /**
103
+ * The input field receiving the params given by position (an array): with `'args'`, `{"method": "sum", "params":
104
+ * [1, 2]}` is dispatched as `{method: 'sum', args: [1, 2]}`.
105
+ * @default none: the params by position are refused with `INVALID_PARAMS`
106
+ */
107
+ positionalParams?: string;
108
+ };
109
+ /**
110
+ * The JSON-RPC request behind a service action's request, as {@link jsonRPCRequestOfContext} returns it.
111
+ */
112
+ export type JSONRPCRequestInfo = {
113
+ /**
114
+ * The request's method.
115
+ */
116
+ method: string;
117
+ /**
118
+ * The request's id; `undefined` for a notification (no response is sent).
119
+ */
120
+ id: string | number | null | undefined;
121
+ /**
122
+ * The transport the request came through.
123
+ */
124
+ transport: 'http' | 'websocket' | 'stdio';
125
+ };
126
+ /**
127
+ * Get the JSON-RPC request behind a service action's request, when {@link jsonRPCServiceEntrypoint} serves it (to
128
+ * tell a notification from a request, or read the transport).
129
+ * @param context The service action's context (`this.context` in a controller).
130
+ * @returns The request's method, id and transport, or `undefined` when another adapter serves the request.
131
+ * @example
132
+ * ```typescript
133
+ * import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
134
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
135
+ * import {jsonRPCRequestOfContext, type JSONRPCRequestInfo} from 'lakutata/adapter/jsonrpc'
136
+ *
137
+ * class LogController extends Controller {
138
+ * //{"jsonrpc": "2.0", "method": "log.write", "params": {"line": "started"}}: a notification, no id
139
+ * @ServiceAction({method: 'log.write'})
140
+ * public async write(input: {line: string}): Promise<void> {
141
+ * const request: JSONRPCRequestInfo | undefined = jsonRPCRequestOfContext(this.context as ServiceContext)
142
+ * console.log(`${request?.transport}: ${input.line}`)
143
+ * }
144
+ * }
145
+ * ```
146
+ */
147
+ export declare function jsonRPCRequestOfContext(context: ServiceContext): JSONRPCRequestInfo | undefined;
148
+ /**
149
+ * The context of a dispatch of a request
150
+ */
151
+ export type JSONRPCDispatch = {
152
+ runtime: ChannelRuntime<ServiceContext>;
153
+ transport: JSONRPCRequestInfo['transport'];
154
+ clientId?: string;
155
+ /**
156
+ * The properties added to the contexts (the request of HTTP, the socket)
157
+ */
158
+ extra?: Record<string, unknown>;
159
+ signal?: AbortSignal;
160
+ stopping: () => boolean;
161
+ };
162
+ /**
163
+ * The requests of JSON-RPC 2.0 dispatched to the service actions: the single ones, the batches, the notifications (no
164
+ * response); their methods given to the patterns of the actions
165
+ */
166
+ export declare class JSONRPCProtocol {
167
+ protected readonly options: JSONRPCMappingOptions;
168
+ constructor(options?: JSONRPCMappingOptions);
169
+ /**
170
+ * The pattern and the input of the action of a request
171
+ * @param request
172
+ * @protected
173
+ */
174
+ protected pattern(request: JSONRPCRequest): Record<string, unknown>;
175
+ /**
176
+ * The response of a request (none for a notification)
177
+ * @param request
178
+ * @param dispatch
179
+ * @protected
180
+ */
181
+ protected one(request: unknown, dispatch: JSONRPCDispatch): Promise<JSONRPCResponse | undefined>;
182
+ /**
183
+ * The response of a message (a request, a batch): undefined when there is none (notifications)
184
+ * @param message its text
185
+ * @param dispatch
186
+ */
187
+ handle(message: string, dispatch: JSONRPCDispatch): Promise<JSONRPCResponse | JSONRPCResponse[] | undefined>;
188
+ /**
189
+ * A notification sent to a client (an event pushed)
190
+ * @param event
191
+ * @param args
192
+ */
193
+ static notification(event: string, args: unknown[]): string;
194
+ }
@@ -0,0 +1,154 @@
1
+ import { type Server } from 'node:http';
2
+ import type { Readable, Writable } from 'node:stream';
3
+ import type { EntrypointAdapter } from '../../channel/EntrypointAdapter.js';
4
+ import type { MiddlewareDefinition } from '../../lib/Middleware.js';
5
+ import type { ServiceContext } from '../../context/ServiceContext.js';
6
+ import { type JSONRPCMappingOptions } from './JSONRPCProtocol.js';
7
+ /**
8
+ * The options of {@link jsonRPCServiceEntrypoint}: its transport, and how the requests map to the service actions (see
9
+ * {@link JSONRPCMappingOptions}).
10
+ */
11
+ export type JSONRPCServiceEntrypointOptions = JSONRPCMappingOptions & {
12
+ /**
13
+ * The adapter name, to tell apart several service adapters of one entrypoint.
14
+ */
15
+ name?: string;
16
+ /**
17
+ * The transport of the messages: `'http'` (a `POST` per message), `'websocket'` (a message per WebSocket text
18
+ * frame, with the events pushed; it needs the optional package `ws`), or `'stdio'` (the process's standard input
19
+ * and output, for a child process, with the events pushed).
20
+ * @default 'http'
21
+ */
22
+ transport?: 'http' | 'websocket' | 'stdio';
23
+ /**
24
+ * The port of the HTTP or WebSocket server; 0 picks a random free port. The entrypoint fails to start when the port
25
+ * is in use.
26
+ * @default 3000
27
+ */
28
+ port?: number;
29
+ /**
30
+ * The host or address of the HTTP or WebSocket server.
31
+ * @default all the interfaces
32
+ */
33
+ host?: string;
34
+ /**
35
+ * The path receiving the requests (HTTP) or the connections (WebSocket).
36
+ * @default '/'
37
+ */
38
+ path?: string;
39
+ /**
40
+ * The largest message, in bytes. Over HTTP a larger body is answered with 413; over WebSocket the connection is
41
+ * closed by `ws`; over stdio a larger message is skipped (the rest of its line, or the length its header declares)
42
+ * and answered with an Invalid Request error without id (`-32600`).
43
+ * @default 10485760 (10 MiB)
44
+ */
45
+ limit?: number;
46
+ /**
47
+ * How the messages are delimited on stdio: `'newline'` (one JSON message per line), or `'content-length'` (each
48
+ * message after a `Content-Length` header and a blank line, as in the Language Server Protocol). The responses and
49
+ * the notifications are written the same way.
50
+ * @default 'newline'
51
+ */
52
+ framing?: 'newline' | 'content-length';
53
+ /**
54
+ * The stream the stdio transport reads.
55
+ * @default process.stdin
56
+ */
57
+ input?: Readable;
58
+ /**
59
+ * The stream the stdio transport writes.
60
+ * @default process.stdout
61
+ */
62
+ output?: Writable;
63
+ /**
64
+ * What happens when the stdio input ends (the parent process is gone): `'application'` exits the application with
65
+ * the code 0 once the requests in progress are answered, `'none'` does nothing, or a function run once they are
66
+ * answered.
67
+ * @default 'application'
68
+ */
69
+ end?: 'application' | 'none' | (() => void | Promise<void>);
70
+ /**
71
+ * The interval between the pings of the WebSocket connections, in milliseconds; 0 sends none. A connection that has
72
+ * not answered a ping by the next one is terminated.
73
+ * @default 30000
74
+ */
75
+ heartbeat?: number;
76
+ /**
77
+ * The middlewares of this adapter's actions, run after the entrypoint's global middlewares.
78
+ */
79
+ middlewares?: MiddlewareDefinition[];
80
+ /**
81
+ * Run once the HTTP or WebSocket server listens, with the server (to read the port picked for port 0). A failure
82
+ * fails the entrypoint start. Not called with stdio.
83
+ */
84
+ listening?: (server: Server) => void | Promise<void>;
85
+ };
86
+ /**
87
+ * Create a service adapter of an entrypoint served over JSON-RPC 2.0, on HTTP, WebSocket or stdio. Only the WebSocket
88
+ * transport needs an optional peer dependency, `ws`; without it, the entrypoint fails to start.
89
+ *
90
+ * A request's method and named params become the service action's pattern and input: by default
91
+ * `{"method": "user.get", "params": {"id": 1}}` is dispatched as `{method: 'user.get', id: 1}` (see
92
+ * {@link JSONRPCMappingOptions} for the other mappings). The batches are answered with an array of responses, the
93
+ * notifications (no `id`) run without a response. The action's result is the response's `result` (`null` for none);
94
+ * its error becomes a JSON-RPC error (see {@link JSONRPCErrorCode}): `METHOD_NOT_FOUND`, `INVALID_PARAMS` for a failed
95
+ * validation, otherwise `SERVER_ERROR` with the whole error object as its `data`.
96
+ *
97
+ * Over HTTP, a message is the body of a `POST` to the path, answered with 200 and the JSON response (204 when it held
98
+ * only notifications); any other method or path is answered with 404, and the CORS headers allow any origin. Over
99
+ * WebSocket and stdio, the events pushed by `Entrypoint.notify` and `Entrypoint.broadcast` are sent as notifications,
100
+ * `{"jsonrpc": "2.0", "method": event, "params": args}`. The client id carried by `ServiceContext.clientId` is the `id`
101
+ * header or `id` query parameter of the HTTP request or of the WebSocket connection (at most 200 characters; a random
102
+ * one for a WebSocket connection without it), and `'stdio'` on stdio.
103
+ *
104
+ * When an HTTP client disconnects before its response, the action's abort signal fires. When the entrypoint stops,
105
+ * stdio stops reading, the new requests are answered with `STOPPING`, and once the requests in progress are answered
106
+ * the WebSocket connections are closed (code 1001) and the server shuts down.
107
+ * @param options The adapter options; by default it serves HTTP on port 3000 of all the interfaces, on the path `/`.
108
+ * @returns The adapter, to give to the `service` option of `buildEntrypoints`.
109
+ * @example
110
+ * ```typescript
111
+ * import {Application} from 'lakutata'
112
+ * import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
113
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
114
+ * import {jsonRPCServiceEntrypoint} from 'lakutata/adapter/jsonrpc'
115
+ * import WebSocket from 'ws'
116
+ *
117
+ * class UserController extends Controller {
118
+ * @ServiceAction({method: 'user.get'})
119
+ * public async get(input: {id: number}): Promise<{id: number, name: string}> {
120
+ * return {id: input.id, name: 'Ada'}
121
+ * }
122
+ * }
123
+ *
124
+ * Application.run({
125
+ * id: 'user.service',
126
+ * name: 'Users',
127
+ * components: {
128
+ * entrypoint: buildEntrypoints({
129
+ * controllers: [UserController],
130
+ * service: [
131
+ * //POST http://localhost:3000/rpc
132
+ * jsonRPCServiceEntrypoint({name: 'rpc-http', port: 3000, path: '/rpc'}),
133
+ * //ws://localhost:3001/rpc, with the events pushed
134
+ * jsonRPCServiceEntrypoint({name: 'rpc-ws', transport: 'websocket', port: 3001, path: '/rpc'})
135
+ * ]
136
+ * })
137
+ * }
138
+ * })
139
+ *
140
+ * //An HTTP client: {"jsonrpc": "2.0", "id": 1, "result": {"id": 1, "name": "Ada"}}
141
+ * const response: Response = await fetch('http://localhost:3000/rpc', {
142
+ * method: 'POST',
143
+ * headers: {'Content-Type': 'application/json'},
144
+ * body: JSON.stringify({jsonrpc: '2.0', id: 1, method: 'user.get', params: {id: 1}})
145
+ * })
146
+ * console.log(await response.json())
147
+ *
148
+ * //A WebSocket client, identified as client-1: the responses and the notifications arrive as messages
149
+ * const socket: WebSocket = new WebSocket('ws://localhost:3001/rpc?id=client-1')
150
+ * socket.on('open', (): void => socket.send(JSON.stringify({jsonrpc: '2.0', id: 2, method: 'user.get', params: {id: 2}})))
151
+ * socket.on('message', (data: WebSocket.RawData): void => console.log(JSON.parse(data.toString())))
152
+ * ```
153
+ */
154
+ export declare function jsonRPCServiceEntrypoint(options?: JSONRPCServiceEntrypointOptions): EntrypointAdapter<ServiceContext>;
@@ -0,0 +1,86 @@
1
+ import type { ChannelActionInfo, EntrypointAdapter } from '../../channel/EntrypointAdapter.js';
2
+ import type { MiddlewareDefinition } from '../../lib/Middleware.js';
3
+ import { ScheduleContext } from '../../context/ScheduleContext.js';
4
+ /**
5
+ * The options of {@link scheduleEntrypoint}.
6
+ */
7
+ export type ScheduleEntrypointOptions = {
8
+ /**
9
+ * The adapter name, to tell apart several schedule adapters of one entrypoint.
10
+ */
11
+ name?: string;
12
+ /**
13
+ * The middlewares of this adapter's runs, run after the entrypoint's global middlewares.
14
+ */
15
+ middlewares?: MiddlewareDefinition[];
16
+ /**
17
+ * Called when a run fails (the action, a middleware or the access control threw), with the error, the action and
18
+ * the run's context. A failed run does not stop the next ones.
19
+ * @default the error is written to the application's `log` component (`console.error` without one)
20
+ */
21
+ onError?: (error: unknown, action: ChannelActionInfo, context: ScheduleContext) => void | Promise<void>;
22
+ /**
23
+ * Called when a run is skipped, with the action, the time the run was due and why: `'overlap'` when the action's
24
+ * previous run is still in progress (an action without `overlap: true`), `'exclusive'` when another instance of the
25
+ * application holds the run's lock (an `exclusive` action). An error it throws is written to the application's
26
+ * `log` component; the schedule goes on.
27
+ */
28
+ onSkip?: (action: ChannelActionInfo, scheduledAt: Date, reason: 'overlap' | 'exclusive') => void;
29
+ };
30
+ /**
31
+ * Create the schedule adapter of an entrypoint: it runs the controller actions declared with `@Schedule`, which never
32
+ * run without it. It needs no optional dependency.
33
+ *
34
+ * The runs begin once the application has launched (all its objects, its bootstrap and the other adapters are ready).
35
+ * Each run is dispatched like a request: a new controller in its own scope, the middlewares and the access control, a
36
+ * {@link ScheduleContext} giving the schedule, the time the run was due and its number. An interval keeps its pace:
37
+ * the runs missed while the process was suspended are skipped, not caught up. An action whose previous run is still in
38
+ * progress skips its run unless it allows `overlap`.
39
+ *
40
+ * An `exclusive` action runs in one instance of the application at a time: each run first tries to acquire a lock
41
+ * named `schedule:<key>` (the `key` of its `exclusive` option, the action name by default) from the mutex component
42
+ * (the `Mutex` of `lakutata/com/mutex`, named `mutex` by default), and is skipped when another
43
+ * instance holds it; the lock is kept after the run for half of its period (30 seconds at most) so that the instances
44
+ * whose clocks are late skip it too. An exclusive action whose mutex component cannot be resolved never runs (the
45
+ * error is logged).
46
+ *
47
+ * When the entrypoint stops, no new run starts, the kept locks are released and the entrypoint waits for the runs in
48
+ * progress (aborting them after its `shutdownTimeout`).
49
+ * @param options The adapter options.
50
+ * @returns The adapter, to give to the `schedule` option of `buildEntrypoints`.
51
+ * @example
52
+ * ```typescript
53
+ * import {Application} from 'lakutata'
54
+ * import {buildEntrypoints, Controller, ScheduleContext, scheduleEntrypoint} from 'lakutata/com/entrypoint'
55
+ * import {Schedule} from 'lakutata/decorator/ctrl'
56
+ *
57
+ * class MaintenanceController extends Controller {
58
+ * //Every 5 minutes, and once the application launched
59
+ * @Schedule({every: '5m', immediate: true})
60
+ * public async purge(): Promise<void> {
61
+ * const context: ScheduleContext = this.context as ScheduleContext
62
+ * console.log(`Run ${context.run}, due at ${context.scheduledAt.toISOString()}`)
63
+ * }
64
+ *
65
+ * //Every day at 03:00 in Shanghai
66
+ * @Schedule({cron: '0 3 * * *', timezone: 'Asia/Shanghai'})
67
+ * public async report(): Promise<void> {
68
+ * }
69
+ * }
70
+ *
71
+ * Application.run({
72
+ * id: 'worker.app',
73
+ * name: 'Worker',
74
+ * components: {
75
+ * entrypoint: buildEntrypoints({
76
+ * controllers: [MaintenanceController],
77
+ * schedule: scheduleEntrypoint({
78
+ * onError: (error, action): void => console.error(`${action.name} failed`, error),
79
+ * onSkip: (action, scheduledAt, reason): void => console.warn(`${action.name} skipped (${reason})`)
80
+ * })
81
+ * })
82
+ * }
83
+ * })
84
+ * ```
85
+ */
86
+ export declare function scheduleEntrypoint(options?: ScheduleEntrypointOptions): EntrypointAdapter<ScheduleContext>;
@@ -0,0 +1,138 @@
1
+ import { Server as SocketIOServer, type ServerOptions, type Socket } from 'socket.io';
2
+ import { type Server } from 'node:http';
3
+ import type { EntrypointAdapter } from '../../channel/EntrypointAdapter.js';
4
+ import type { MiddlewareDefinition } from '../../lib/Middleware.js';
5
+ import { ServiceContext } from '../../context/ServiceContext.js';
6
+ /**
7
+ * The options of {@link socketIOServiceEntrypoint}.
8
+ */
9
+ export type SocketIOServiceEntrypointOptions = {
10
+ /**
11
+ * The adapter name, to tell apart several service adapters of one entrypoint.
12
+ */
13
+ name?: string;
14
+ /**
15
+ * The socket.io event carrying the requests: `socket.emit('message', {cmd: 'echo', …}, (response) => …)`.
16
+ * @default 'message'
17
+ */
18
+ event?: string;
19
+ /**
20
+ * The socket.io namespace receiving the requests.
21
+ * @default '/'
22
+ */
23
+ namespace?: string;
24
+ /**
25
+ * An HTTP server to attach the socket.io server to (such as the one of `expressHTTPEntrypoint`, given to its
26
+ * `before` hook), or a function returning it when the adapter starts. The adapter then does not listen itself, and
27
+ * when it stops it disconnects the sockets but leaves the HTTP server to its owner.
28
+ * @default a server of its own, listening on `port`
29
+ */
30
+ server?: Server | (() => Server);
31
+ /**
32
+ * An existing socket.io server to serve the requests on, used as is: the adapter neither makes it listen nor closes
33
+ * it, and ignores `server`, `port`, `host` and `options`.
34
+ * @default a socket.io server created by the adapter
35
+ */
36
+ io?: SocketIOServer;
37
+ /**
38
+ * The port of the adapter's own server (without `server` and `io`); 0 picks a random free port. The entrypoint fails
39
+ * to start when the port is in use.
40
+ * @default 3000
41
+ */
42
+ port?: number;
43
+ /**
44
+ * The host or address of the adapter's own server.
45
+ * @default all the interfaces
46
+ */
47
+ host?: string;
48
+ /**
49
+ * The options of the socket.io server created by the adapter (`path`, `cors`, `transports`…).
50
+ */
51
+ options?: Partial<ServerOptions>;
52
+ /**
53
+ * The middlewares of this adapter's actions, run after the entrypoint's global middlewares.
54
+ */
55
+ middlewares?: MiddlewareDefinition[];
56
+ /**
57
+ * Run once the adapter is ready, with the socket.io server and its HTTP server (`undefined` when `io` is given
58
+ * without `server`).
59
+ * A failure fails the entrypoint start.
60
+ */
61
+ listening?: (io: SocketIOServer, server: Server | undefined) => void | Promise<void>;
62
+ };
63
+ /**
64
+ * Get the socket.io socket that sent a service action's request, when {@link socketIOServiceEntrypoint} serves it (to
65
+ * read its handshake, join it to rooms, emit to it…).
66
+ * @param context The service action's context (`this.context` in a controller).
67
+ * @returns The socket, or `undefined` when another adapter serves the request.
68
+ * @example
69
+ * ```typescript
70
+ * import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
71
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
72
+ * import {socketOfContext} from 'lakutata/adapter/socket.io'
73
+ *
74
+ * class RoomController extends Controller {
75
+ * //socket.emit('message', {cmd: 'room.join', room: 'lobby'}, (response) => …)
76
+ * @ServiceAction({cmd: 'room.join'})
77
+ * public async join(input: {room: string}): Promise<void> {
78
+ * await socketOfContext(this.context as ServiceContext)?.join(input.room)
79
+ * }
80
+ * }
81
+ * ```
82
+ */
83
+ export declare function socketOfContext(context: ServiceContext): Socket | undefined;
84
+ /**
85
+ * Create a service adapter of an entrypoint served by socket.io. It needs the optional peer dependency `socket.io`
86
+ * (and `socket.io-client` on the clients).
87
+ *
88
+ * A request is an emit of the request event (`'message'` by default) whose data holds the action's pattern and input,
89
+ * with an acknowledgement callback receiving the response `{success, error, payload}` (see `ServiceResponseCodec`):
90
+ * `payload` is the result, or `error` the whole error object when the action failed (no matching action, validation…).
91
+ * An emit without an acknowledgement still runs the action.
92
+ *
93
+ * Each socket belongs to a client, identified by the id it gives when it connects (`auth.id`, else the `id` header,
94
+ * else the `id` query parameter; at most 200 characters), else by its socket id; its requests carry it as
95
+ * `ServiceContext.clientId`. The events pushed by `Entrypoint.notify` are emitted to every socket of the client, those
96
+ * of `Entrypoint.broadcast` to every socket of the namespace, with the event's arguments as the emit's arguments.
97
+ *
98
+ * When a socket disconnects, its requests in progress are aborted (their abort signal fires). When the entrypoint
99
+ * stops, the new requests are answered with an `EntrypointStoppedException` error; once the requests in progress end,
100
+ * the socket.io server is closed (the sockets disconnected, with the attached HTTP server left open).
101
+ * @param options The adapter options; by default it listens on port 3000 of all the interfaces with a server of its own.
102
+ * @returns The adapter, to give to the `service` option of `buildEntrypoints`.
103
+ * @example
104
+ * ```typescript
105
+ * import {Application} from 'lakutata'
106
+ * import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
107
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
108
+ * import {socketIOServiceEntrypoint} from 'lakutata/adapter/socket.io'
109
+ * import {io} from 'socket.io-client'
110
+ *
111
+ * class EchoController extends Controller {
112
+ * @ServiceAction({cmd: 'echo'})
113
+ * public async echo(input: {text: string}): Promise<string> {
114
+ * return input.text
115
+ * }
116
+ * }
117
+ *
118
+ * Application.run({
119
+ * id: 'echo.service',
120
+ * name: 'Echo',
121
+ * components: {
122
+ * entrypoint: buildEntrypoints({
123
+ * controllers: [EchoController],
124
+ * service: socketIOServiceEntrypoint({port: 3000, options: {cors: {origin: '*'}}})
125
+ * })
126
+ * }
127
+ * })
128
+ *
129
+ * //A client, identified as client-1 (the events pushed by entrypoint.notify('client-1', 'progress', 50) reach it)
130
+ * const socket = io('http://localhost:3000', {auth: {id: 'client-1'}})
131
+ * socket.on('progress', (percent: number): void => console.log(`${percent}%`))
132
+ * socket.emit('message', {cmd: 'echo', text: 'hi'}, (response: {success: boolean, error: unknown, payload: unknown}): void => {
133
+ * //{success: true, error: null, payload: 'hi'}
134
+ * console.log(response)
135
+ * })
136
+ * ```
137
+ */
138
+ export declare function socketIOServiceEntrypoint(options?: SocketIOServiceEntrypointOptions): EntrypointAdapter<ServiceContext>;
@@ -0,0 +1,18 @@
1
+ import { ChannelDefinition } from './Channel.js';
2
+ /**
3
+ * The HTTP channel, addressed by route and method
4
+ */
5
+ export declare const HTTPChannel: ChannelDefinition;
6
+ /**
7
+ * The CLI channel, addressed by command
8
+ */
9
+ export declare const CLIChannel: ChannelDefinition;
10
+ /**
11
+ * The service channel, addressed by pattern
12
+ */
13
+ export declare const ServiceChannel: ChannelDefinition;
14
+ /**
15
+ * The schedule channel: no external caller, each action is run by the timers of the schedule adapter.
16
+ * The address of an action is its schedule, with the key telling apart the actions of a same schedule
17
+ */
18
+ export declare const ScheduleChannel: ChannelDefinition;