@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,75 @@
1
+ import { DTO, type ActionPattern } from '@lakutata/core';
2
+ /**
3
+ * The kinds of the request contexts of the built-in channels, held by `BaseContext.type`.
4
+ */
5
+ export declare enum ContextType {
6
+ /**
7
+ * A command of a CLI adapter (`CLIContext`).
8
+ */
9
+ CLI = "CLI",
10
+ /**
11
+ * A request of an HTTP adapter (`HTTPContext`).
12
+ */
13
+ HTTP = "HTTP",
14
+ /**
15
+ * A message of a service adapter: Socket.IO, JSON-RPC, Electron IPC, HTTP service (`ServiceContext`).
16
+ */
17
+ SERVICE = "SERVICE",
18
+ /**
19
+ * A run of a scheduled action (`ScheduleContext`).
20
+ */
21
+ SCHEDULE = "SCHEDULE"
22
+ }
23
+ export type ContextParams<T extends {} = {}> = T & Record<string, any>;
24
+ /**
25
+ * The context of a request: what an adapter knows about it, given to the controller (`this.context`), the middlewares
26
+ * (`invocation.context`) and the access control rules. Each channel has its subclass (`HTTPContext`, `CLIContext`,
27
+ * `ServiceContext`, `ScheduleContext`); test it with `instanceof` in an action serving several channels. A context is
28
+ * a DTO: its properties are validated when it is created and when they change; it also holds the extra properties
29
+ * given by its adapter (the Socket.IO socket, the JSON-RPC request), read by the adapters' helpers
30
+ * (`socketOfContext`…). The adapters create the contexts: an application only reads them.
31
+ * @example
32
+ * ```typescript
33
+ * import {Controller, CLIContext, HTTPContext, ServiceContext} from 'lakutata/com/entrypoint'
34
+ * import {CLIAction, GET, ServiceAction} from 'lakutata/decorator/ctrl'
35
+ *
36
+ * class VersionController extends Controller {
37
+ * //One action for the three channels: the context tells them apart
38
+ * @GET('/version')
39
+ * @CLIAction('version')
40
+ * @ServiceAction({act: 'version'})
41
+ * public async version(): Promise<{ version: string, via: string }> {
42
+ * let via: string = this.context.type
43
+ * if (this.context instanceof HTTPContext) via = `${this.context.method.toUpperCase()} ${this.context.route}`
44
+ * if (this.context instanceof CLIContext) via = `the command ${this.context.command}`
45
+ * if (this.context instanceof ServiceContext) via = `the client ${this.context.clientId ?? 'unknown'}`
46
+ * return {version: '1.0.0', via: via}
47
+ * }
48
+ * }
49
+ * ```
50
+ */
51
+ export declare class BaseContext<T extends Record<string, any> = {}> extends DTO {
52
+ /**
53
+ * The kind of the context: a `ContextType` for the built-in channels, the context type declared by its channel for
54
+ * the channels of other packages.
55
+ */
56
+ readonly type: ContextType | string;
57
+ /**
58
+ * The input of the action before its validation: for HTTP the query string merged with the parsed body (the route
59
+ * parameters are merged over it when the action runs, not into it), for CLI the arguments and the options of the
60
+ * command, for a service the message without the keys of the action's pattern, for a scheduled run an empty
61
+ * object. A middleware may change it before the validation.
62
+ */
63
+ data: ActionPattern<T>;
64
+ /**
65
+ * The language of the request (a BCP 47 tag such as `'zh-CN'`), set by the i18n middleware (`I18nMiddleware` of
66
+ * `lakutata/com/i18n`): the validation errors of an invalid input are then written in it. Undefined without it.
67
+ */
68
+ locale?: string;
69
+ /**
70
+ * Create a context, validating its properties.
71
+ * @param params The properties of the context: its `type`, its `data`, and those of its channel.
72
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
73
+ */
74
+ constructor(params: ContextParams);
75
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BaseContext = exports.ContextType = void 0;
13
+ const core_1 = require("@lakutata/core");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ /**
16
+ * The kinds of the request contexts of the built-in channels, held by `BaseContext.type`.
17
+ */
18
+ var ContextType;
19
+ (function (ContextType) {
20
+ /**
21
+ * A command of a CLI adapter (`CLIContext`).
22
+ */
23
+ ContextType["CLI"] = "CLI";
24
+ /**
25
+ * A request of an HTTP adapter (`HTTPContext`).
26
+ */
27
+ ContextType["HTTP"] = "HTTP";
28
+ /**
29
+ * A message of a service adapter: Socket.IO, JSON-RPC, Electron IPC, HTTP service (`ServiceContext`).
30
+ */
31
+ ContextType["SERVICE"] = "SERVICE";
32
+ /**
33
+ * A run of a scheduled action (`ScheduleContext`).
34
+ */
35
+ ContextType["SCHEDULE"] = "SCHEDULE";
36
+ })(ContextType || (exports.ContextType = ContextType = {}));
37
+ /**
38
+ * The context of a request: what an adapter knows about it, given to the controller (`this.context`), the middlewares
39
+ * (`invocation.context`) and the access control rules. Each channel has its subclass (`HTTPContext`, `CLIContext`,
40
+ * `ServiceContext`, `ScheduleContext`); test it with `instanceof` in an action serving several channels. A context is
41
+ * a DTO: its properties are validated when it is created and when they change; it also holds the extra properties
42
+ * given by its adapter (the Socket.IO socket, the JSON-RPC request), read by the adapters' helpers
43
+ * (`socketOfContext`…). The adapters create the contexts: an application only reads them.
44
+ * @example
45
+ * ```typescript
46
+ * import {Controller, CLIContext, HTTPContext, ServiceContext} from 'lakutata/com/entrypoint'
47
+ * import {CLIAction, GET, ServiceAction} from 'lakutata/decorator/ctrl'
48
+ *
49
+ * class VersionController extends Controller {
50
+ * //One action for the three channels: the context tells them apart
51
+ * @GET('/version')
52
+ * @CLIAction('version')
53
+ * @ServiceAction({act: 'version'})
54
+ * public async version(): Promise<{ version: string, via: string }> {
55
+ * let via: string = this.context.type
56
+ * if (this.context instanceof HTTPContext) via = `${this.context.method.toUpperCase()} ${this.context.route}`
57
+ * if (this.context instanceof CLIContext) via = `the command ${this.context.command}`
58
+ * if (this.context instanceof ServiceContext) via = `the client ${this.context.clientId ?? 'unknown'}`
59
+ * return {version: '1.0.0', via: via}
60
+ * }
61
+ * }
62
+ * ```
63
+ */
64
+ let BaseContext = class BaseContext extends core_1.DTO {
65
+ /**
66
+ * Create a context, validating its properties.
67
+ * @param params The properties of the context: its `type`, its `data`, and those of its channel.
68
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
69
+ */
70
+ constructor(params) {
71
+ super(params);
72
+ }
73
+ };
74
+ exports.BaseContext = BaseContext;
75
+ __decorate([
76
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
77
+ __metadata("design:type", String)
78
+ ], BaseContext.prototype, "type", void 0);
79
+ __decorate([
80
+ (0, dto_1.Expect)(core_1.DTO.Object().pattern(core_1.DTO.String(), core_1.DTO.Any()).required()),
81
+ __metadata("design:type", Object)
82
+ ], BaseContext.prototype, "data", void 0);
83
+ __decorate([
84
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
85
+ __metadata("design:type", String)
86
+ ], BaseContext.prototype, "locale", void 0);
87
+ exports.BaseContext = BaseContext = __decorate([
88
+ (0, dto_1.IndexSignature)(core_1.DTO.Any()),
89
+ __metadata("design:paramtypes", [Object])
90
+ ], BaseContext);
@@ -0,0 +1,38 @@
1
+ import { BaseContext, type ContextParams, ContextType } from './BaseContext.js';
2
+ import { type CLIContextParams } from '../types/CLIContextParams.js';
3
+ /**
4
+ * The context of a command run by a CLI adapter (`commanderCLIEntrypoint`): `this.context` of a controller action
5
+ * declared with `@CLIAction`, when it runs as a command. Its `data` holds the positional arguments and the options of
6
+ * the command, before their validation.
7
+ * @example
8
+ * ```typescript
9
+ * import {Controller, CLIContext} from 'lakutata/com/entrypoint'
10
+ * import {CLIAction} from 'lakutata/decorator/ctrl'
11
+ *
12
+ * class CacheController extends Controller {
13
+ * //"app cache clear" prints "cache clear: done"
14
+ * @CLIAction('cache clear')
15
+ * public async clear(): Promise<string> {
16
+ * const command: string = this.context instanceof CLIContext ? this.context.command : 'unknown'
17
+ * return `${command}: done`
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export declare class CLIContext<T extends Record<string, any> = {}> extends BaseContext<T> {
23
+ /**
24
+ * Always `ContextType.CLI`.
25
+ */
26
+ readonly type: ContextType;
27
+ /**
28
+ * The command of the action as declared, its controller prefix included (`'user:get <id>'`), not the arguments
29
+ * typed by the user.
30
+ */
31
+ command: string;
32
+ /**
33
+ * Create the context of a command, validating its properties.
34
+ * @param params The command and its data.
35
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
36
+ */
37
+ constructor(params: ContextParams<CLIContextParams>);
38
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CLIContext = void 0;
13
+ const BaseContext_js_1 = require("./BaseContext.js");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ const core_1 = require("@lakutata/core");
16
+ /**
17
+ * The context of a command run by a CLI adapter (`commanderCLIEntrypoint`): `this.context` of a controller action
18
+ * declared with `@CLIAction`, when it runs as a command. Its `data` holds the positional arguments and the options of
19
+ * the command, before their validation.
20
+ * @example
21
+ * ```typescript
22
+ * import {Controller, CLIContext} from 'lakutata/com/entrypoint'
23
+ * import {CLIAction} from 'lakutata/decorator/ctrl'
24
+ *
25
+ * class CacheController extends Controller {
26
+ * //"app cache clear" prints "cache clear: done"
27
+ * @CLIAction('cache clear')
28
+ * public async clear(): Promise<string> {
29
+ * const command: string = this.context instanceof CLIContext ? this.context.command : 'unknown'
30
+ * return `${command}: done`
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ class CLIContext extends BaseContext_js_1.BaseContext {
36
+ /**
37
+ * Create the context of a command, validating its properties.
38
+ * @param params The command and its data.
39
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
40
+ */
41
+ constructor(params) {
42
+ super(params);
43
+ }
44
+ }
45
+ exports.CLIContext = CLIContext;
46
+ __decorate([
47
+ (0, dto_1.Expect)(core_1.DTO.String().valid(BaseContext_js_1.ContextType.CLI).default(BaseContext_js_1.ContextType.CLI)),
48
+ __metadata("design:type", String)
49
+ ], CLIContext.prototype, "type", void 0);
50
+ __decorate([
51
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
52
+ __metadata("design:type", String)
53
+ ], CLIContext.prototype, "command", void 0);
@@ -0,0 +1,52 @@
1
+ import { BaseContext, type ContextParams, ContextType } from './BaseContext.js';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
3
+ import { type HTTPContextParams } from '../types/HTTPContextParams.js';
4
+ /**
5
+ * The context of a request served by an HTTP adapter (`expressHTTPEntrypoint`, `fastifyHTTPEntrypoint`):
6
+ * `this.context` of a controller action declared with `@HTTPAction` or `@GET`…, when it runs for an HTTP request. It
7
+ * gives the Node.js request and response, to read or set headers; once an action has sent the response itself (its
8
+ * headers sent), the adapter writes neither its value nor its error.
9
+ * @example
10
+ * ```typescript
11
+ * import {Controller, HTTPContext} from 'lakutata/com/entrypoint'
12
+ * import {GET} from 'lakutata/decorator/ctrl'
13
+ *
14
+ * class AgentController extends Controller {
15
+ * //GET /agent: answered with the header Cache-Control and the JSON {"agent": "curl/8.0", "route": "/agent"}
16
+ * @GET('/agent')
17
+ * public async agent(): Promise<{ agent: string, route: string }> {
18
+ * if (!(this.context instanceof HTTPContext)) return {agent: '', route: ''}
19
+ * this.context.response.setHeader('Cache-Control', 'no-store')
20
+ * return {agent: this.context.request.headers['user-agent'] ?? '', route: this.context.route}
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare class HTTPContext<T extends Record<string, any> = {}> extends BaseContext<T> {
26
+ /**
27
+ * Always `ContextType.HTTP`.
28
+ */
29
+ readonly type: ContextType;
30
+ /**
31
+ * The route of the action as declared, its controller prefix included (`'/users/:id'`), not the requested path.
32
+ */
33
+ readonly route: string;
34
+ /**
35
+ * The HTTP method of the action, as declared (`'get'` for `@GET`).
36
+ */
37
+ readonly method: string;
38
+ /**
39
+ * The Node.js request (the raw request of Fastify, the Express request).
40
+ */
41
+ readonly request: IncomingMessage;
42
+ /**
43
+ * The Node.js response (the raw reply of Fastify, the Express response).
44
+ */
45
+ readonly response: ServerResponse;
46
+ /**
47
+ * Create the context of an HTTP request, validating its properties.
48
+ * @param params The route, the method, the request, the response and the data of the request.
49
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
50
+ */
51
+ constructor(params: ContextParams<HTTPContextParams>);
52
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HTTPContext = void 0;
13
+ const core_1 = require("@lakutata/core");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ const BaseContext_js_1 = require("./BaseContext.js");
16
+ const node_http_1 = require("node:http");
17
+ /**
18
+ * The context of a request served by an HTTP adapter (`expressHTTPEntrypoint`, `fastifyHTTPEntrypoint`):
19
+ * `this.context` of a controller action declared with `@HTTPAction` or `@GET`…, when it runs for an HTTP request. It
20
+ * gives the Node.js request and response, to read or set headers; once an action has sent the response itself (its
21
+ * headers sent), the adapter writes neither its value nor its error.
22
+ * @example
23
+ * ```typescript
24
+ * import {Controller, HTTPContext} from 'lakutata/com/entrypoint'
25
+ * import {GET} from 'lakutata/decorator/ctrl'
26
+ *
27
+ * class AgentController extends Controller {
28
+ * //GET /agent: answered with the header Cache-Control and the JSON {"agent": "curl/8.0", "route": "/agent"}
29
+ * @GET('/agent')
30
+ * public async agent(): Promise<{ agent: string, route: string }> {
31
+ * if (!(this.context instanceof HTTPContext)) return {agent: '', route: ''}
32
+ * this.context.response.setHeader('Cache-Control', 'no-store')
33
+ * return {agent: this.context.request.headers['user-agent'] ?? '', route: this.context.route}
34
+ * }
35
+ * }
36
+ * ```
37
+ */
38
+ class HTTPContext extends BaseContext_js_1.BaseContext {
39
+ /**
40
+ * Create the context of an HTTP request, validating its properties.
41
+ * @param params The route, the method, the request, the response and the data of the request.
42
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
43
+ */
44
+ constructor(params) {
45
+ super(params);
46
+ }
47
+ }
48
+ exports.HTTPContext = HTTPContext;
49
+ __decorate([
50
+ (0, dto_1.Expect)(core_1.DTO.String().valid(BaseContext_js_1.ContextType.HTTP).default(BaseContext_js_1.ContextType.HTTP)),
51
+ __metadata("design:type", String)
52
+ ], HTTPContext.prototype, "type", void 0);
53
+ __decorate([
54
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
55
+ __metadata("design:type", String)
56
+ ], HTTPContext.prototype, "route", void 0);
57
+ __decorate([
58
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
59
+ __metadata("design:type", String)
60
+ ], HTTPContext.prototype, "method", void 0);
61
+ __decorate([
62
+ (0, dto_1.Expect)(core_1.DTO.InstanceOf(node_http_1.IncomingMessage)),
63
+ __metadata("design:type", node_http_1.IncomingMessage
64
+ /**
65
+ * The Node.js response (the raw reply of Fastify, the Express response).
66
+ */
67
+ )
68
+ ], HTTPContext.prototype, "request", void 0);
69
+ __decorate([
70
+ (0, dto_1.Expect)(core_1.DTO.InstanceOf(node_http_1.ServerResponse)),
71
+ __metadata("design:type", node_http_1.ServerResponse
72
+ /**
73
+ * Create the context of an HTTP request, validating its properties.
74
+ * @param params The route, the method, the request, the response and the data of the request.
75
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
76
+ */
77
+ )
78
+ ], HTTPContext.prototype, "response", void 0);
@@ -0,0 +1,47 @@
1
+ import { BaseContext, type ContextParams, ContextType } from './BaseContext.js';
2
+ import { type ScheduleContextParams } from '../types/ScheduleContextParams.js';
3
+ /**
4
+ * The context of a run of a scheduled action (`scheduleEntrypoint`): `this.context` of a controller action declared
5
+ * with `@Schedule`, when the schedule runs it. Its `data` is an empty object.
6
+ * @example
7
+ * ```typescript
8
+ * import {Controller, ScheduleContext} from 'lakutata/com/entrypoint'
9
+ * import {Schedule} from 'lakutata/decorator/ctrl'
10
+ *
11
+ * class ReportController extends Controller {
12
+ * //Every hour: logs "run 1 of every 1h, planned at …", then "run 2…"
13
+ * @Schedule('1h')
14
+ * public async hourly(): Promise<void> {
15
+ * if (!(this.context instanceof ScheduleContext)) return
16
+ * const delay: number = Date.now() - this.context.scheduledAt.getTime()
17
+ * console.log(`run ${this.context.run} of ${this.context.schedule}, planned at ${this.context.scheduledAt.toISOString()} (${delay}ms late)`)
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export declare class ScheduleContext<T extends Record<string, any> = {}> extends BaseContext<T> {
23
+ /**
24
+ * Always `ContextType.SCHEDULE`.
25
+ */
26
+ readonly type: ContextType;
27
+ /**
28
+ * The schedule of the action, as a text: `'every '` and the interval as declared (`'every 30s'`, `'every 500ms'` for a
29
+ * number), or `'cron '` and the expression (`'cron 0 * * * *'`).
30
+ */
31
+ readonly schedule: string;
32
+ /**
33
+ * The time the run was planned for; the run starts at it or a little later (the time of the launch for the
34
+ * `immediate` run).
35
+ */
36
+ readonly scheduledAt: Date;
37
+ /**
38
+ * The number of the run in this process, from 1, counting the runs started (not the skipped ones).
39
+ */
40
+ readonly run: number;
41
+ /**
42
+ * Create the context of a scheduled run, validating its properties.
43
+ * @param params The schedule, the planned time, the run number and the data of the run.
44
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
45
+ */
46
+ constructor(params: ContextParams<ScheduleContextParams>);
47
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ScheduleContext = void 0;
13
+ const BaseContext_js_1 = require("./BaseContext.js");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ const core_1 = require("@lakutata/core");
16
+ /**
17
+ * The context of a run of a scheduled action (`scheduleEntrypoint`): `this.context` of a controller action declared
18
+ * with `@Schedule`, when the schedule runs it. Its `data` is an empty object.
19
+ * @example
20
+ * ```typescript
21
+ * import {Controller, ScheduleContext} from 'lakutata/com/entrypoint'
22
+ * import {Schedule} from 'lakutata/decorator/ctrl'
23
+ *
24
+ * class ReportController extends Controller {
25
+ * //Every hour: logs "run 1 of every 1h, planned at …", then "run 2…"
26
+ * @Schedule('1h')
27
+ * public async hourly(): Promise<void> {
28
+ * if (!(this.context instanceof ScheduleContext)) return
29
+ * const delay: number = Date.now() - this.context.scheduledAt.getTime()
30
+ * console.log(`run ${this.context.run} of ${this.context.schedule}, planned at ${this.context.scheduledAt.toISOString()} (${delay}ms late)`)
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ class ScheduleContext extends BaseContext_js_1.BaseContext {
36
+ /**
37
+ * Create the context of a scheduled run, validating its properties.
38
+ * @param params The schedule, the planned time, the run number and the data of the run.
39
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
40
+ */
41
+ constructor(params) {
42
+ super(params);
43
+ }
44
+ }
45
+ exports.ScheduleContext = ScheduleContext;
46
+ __decorate([
47
+ (0, dto_1.Expect)(core_1.DTO.String().valid(BaseContext_js_1.ContextType.SCHEDULE).default(BaseContext_js_1.ContextType.SCHEDULE)),
48
+ __metadata("design:type", String)
49
+ ], ScheduleContext.prototype, "type", void 0);
50
+ __decorate([
51
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
52
+ __metadata("design:type", String)
53
+ ], ScheduleContext.prototype, "schedule", void 0);
54
+ __decorate([
55
+ (0, dto_1.Expect)(core_1.DTO.Date().required()),
56
+ __metadata("design:type", Date
57
+ /**
58
+ * The number of the run in this process, from 1, counting the runs started (not the skipped ones).
59
+ */
60
+ )
61
+ ], ScheduleContext.prototype, "scheduledAt", void 0);
62
+ __decorate([
63
+ (0, dto_1.Expect)(core_1.DTO.Number().integer().min(1).required()),
64
+ __metadata("design:type", Number)
65
+ ], ScheduleContext.prototype, "run", void 0);
@@ -0,0 +1,47 @@
1
+ import { type ActionPattern } from '@lakutata/core';
2
+ import { BaseContext, type ContextParams, ContextType } from './BaseContext.js';
3
+ import { type ServiceContextParams } from '../types/ServiceContextParams.js';
4
+ /**
5
+ * The context of a message received by a service adapter (`socketIOServiceEntrypoint`, `jsonRPCServiceEntrypoint`,
6
+ * `electronIPCServiceEntrypoint`, `httpServiceEntrypoint`): `this.context` of a controller action declared with
7
+ * `@ServiceAction`, when it runs for a message. Its `input` is the whole message, matched against the actions'
8
+ * patterns; its `data` is the message without the keys of the matched pattern. The adapters' helpers give the
9
+ * transport objects (`socketOfContext`, `httpRequestOfContext`, `ipcEventOfContext`, `jsonRPCRequestOfContext`).
10
+ * @example
11
+ * ```typescript
12
+ * import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
13
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
14
+ *
15
+ * class ChatController extends Controller {
16
+ * //The message {act: 'join', room: 'lobby'}: answered with the payload {room: 'lobby', client: <the client id>}
17
+ * @ServiceAction({act: 'join'})
18
+ * public async join(input: { room: string }): Promise<{ room: string, client?: string }> {
19
+ * const client: string | undefined = this.context instanceof ServiceContext ? this.context.clientId : undefined
20
+ * return {room: input.room, client: client}
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare class ServiceContext<T extends Record<string, any> = {}> extends BaseContext<T> {
26
+ /**
27
+ * Always `ContextType.SERVICE`.
28
+ */
29
+ readonly type: ContextType;
30
+ /**
31
+ * The message as received, matched against the actions' patterns: a copy of the data given at creation, which
32
+ * keeps the keys of the pattern (they are removed from `data` once the action is matched), the nested ones
33
+ * included.
34
+ */
35
+ input: ActionPattern<T>;
36
+ /**
37
+ * The id of the client of the request (the renderer of an Electron window, a Socket.IO socket, an HTTP service
38
+ * client): `Entrypoint.notify()` pushes events to it by this id. Undefined for the transports without clients.
39
+ */
40
+ readonly clientId?: string;
41
+ /**
42
+ * Create the context of a service message, validating its properties; `input` is set to a copy of `data`.
43
+ * @param params The message (`data`), its client id, and the adapter's extra properties.
44
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
45
+ */
46
+ constructor(params: ContextParams<ServiceContextParams>);
47
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ServiceContext = void 0;
13
+ const utils_1 = require("@lakutata/utils");
14
+ const core_1 = require("@lakutata/core");
15
+ const dto_1 = require("@lakutata/core/decorator/dto");
16
+ const BaseContext_js_1 = require("./BaseContext.js");
17
+ /**
18
+ * The context of a message received by a service adapter (`socketIOServiceEntrypoint`, `jsonRPCServiceEntrypoint`,
19
+ * `electronIPCServiceEntrypoint`, `httpServiceEntrypoint`): `this.context` of a controller action declared with
20
+ * `@ServiceAction`, when it runs for a message. Its `input` is the whole message, matched against the actions'
21
+ * patterns; its `data` is the message without the keys of the matched pattern. The adapters' helpers give the
22
+ * transport objects (`socketOfContext`, `httpRequestOfContext`, `ipcEventOfContext`, `jsonRPCRequestOfContext`).
23
+ * @example
24
+ * ```typescript
25
+ * import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
26
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
27
+ *
28
+ * class ChatController extends Controller {
29
+ * //The message {act: 'join', room: 'lobby'}: answered with the payload {room: 'lobby', client: <the client id>}
30
+ * @ServiceAction({act: 'join'})
31
+ * public async join(input: { room: string }): Promise<{ room: string, client?: string }> {
32
+ * const client: string | undefined = this.context instanceof ServiceContext ? this.context.clientId : undefined
33
+ * return {room: input.room, client: client}
34
+ * }
35
+ * }
36
+ * ```
37
+ */
38
+ class ServiceContext extends BaseContext_js_1.BaseContext {
39
+ /**
40
+ * Create the context of a service message, validating its properties; `input` is set to a copy of `data`.
41
+ * @param params The message (`data`), its client id, and the adapter's extra properties.
42
+ * @throws {InvalidValueException} When a property is invalid or a required one is missing.
43
+ */
44
+ constructor(params) {
45
+ //A deep copy: the pattern keys removed from the data once matched, nested ones included, stay in the input
46
+ params = { ...params, input: (0, utils_1.cloneDeep)(params.data ?? {}) };
47
+ super(params);
48
+ }
49
+ }
50
+ exports.ServiceContext = ServiceContext;
51
+ __decorate([
52
+ (0, dto_1.Expect)(core_1.DTO.String().valid(BaseContext_js_1.ContextType.SERVICE).default(BaseContext_js_1.ContextType.SERVICE)),
53
+ __metadata("design:type", String)
54
+ ], ServiceContext.prototype, "type", void 0);
55
+ __decorate([
56
+ (0, dto_1.Expect)(core_1.DTO.Object().pattern(core_1.DTO.String(), core_1.DTO.Any()).required()),
57
+ __metadata("design:type", Object)
58
+ ], ServiceContext.prototype, "input", void 0);
59
+ __decorate([
60
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
61
+ __metadata("design:type", String)
62
+ ], ServiceContext.prototype, "clientId", void 0);