@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,116 @@
1
+ import { Controller, type ControllerProperty } from '../lib/Controller.js';
2
+ import { MethodDecorator, ActionPattern, DTO } from '@lakutata/core';
3
+ import { ActionOptions } from '../lib/ActionOptions.js';
4
+ import { ServiceContext } from '../context/ServiceContext.js';
5
+ /**
6
+ * Expose the controller method as a service action, addressed by a pattern that the messages of the service adapters
7
+ * must match. Without a DTO, the input is accepted as it is.
8
+ * A service adapter (`socketIOServiceEntrypoint`, `jsonRPCServiceEntrypoint`, `electronIPCServiceEntrypoint`,
9
+ * `httpServiceEntrypoint`) receives a message, an object, and dispatches it to the action whose pattern it matches. The
10
+ * input is the message without the keys of the pattern; the middlewares run, the input is validated against the DTO
11
+ * (the defaults applied, the unknown keys removed), the access control runs when `acl` is set, then the method receives
12
+ * the validated input as a plain object.
13
+ * The value returned is sent back to the caller: `{success: true, error: null, payload}` for the Socket.IO, Electron
14
+ * and HTTP service adapters, the `result` of the response for JSON-RPC. An error is sent as `{success: false, error,
15
+ * payload: null}`, `error` holding its properties (`errno`, `errMsg`, `statusCode`, `message`…); JSON-RPC answers it as
16
+ * an error response. A message no pattern matches fails with `ControllerActionNotFoundException`.
17
+ * @param pattern The pattern of the action: an object (nested 2 levels at most) whose keys the messages must hold with
18
+ * the same values; a string value may be a glob (`'user.*'`, `*` any characters, `?` one). The most specific pattern
19
+ * matching a message wins. The controller's `@Prefix({pattern})` is merged into it.
20
+ * @returns The method decorator.
21
+ * @throws {InvalidActionPatternDepthException} When the class is declared, if the pattern is nested more than 2 levels.
22
+ * @example
23
+ * ```typescript
24
+ * import {Application, DTO} from 'lakutata'
25
+ * import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
26
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
27
+ * import {Expect} from 'lakutata/decorator/dto'
28
+ * import {socketIOServiceEntrypoint} from 'lakutata/adapter/socket.io'
29
+ *
30
+ * class TransferDTO extends DTO {
31
+ * @Expect(DTO.String().required())
32
+ * public to!: string
33
+ *
34
+ * @Expect(DTO.Number().positive().required())
35
+ * public amount!: number
36
+ * }
37
+ *
38
+ * class AccountController extends Controller {
39
+ * //The message {resource: 'account', act: 'transfer', to: 'ada', amount: 5}: the input is {to: 'ada', amount: 5},
40
+ * //the caller receives {success: true, error: null, payload: {to: 'ada', amount: 5, done: true}}; without an
41
+ * //amount, {success: false, error: {errno: 'E_INVALID_VALUE', …}, payload: null}
42
+ * @ServiceAction({resource: 'account', act: 'transfer'}, TransferDTO, {acl: true})
43
+ * public async transfer(input: TransferDTO): Promise<{ to: string, amount: number, done: boolean }> {
44
+ * return {to: input.to, amount: input.amount, done: true}
45
+ * }
46
+ *
47
+ * //Any message whose act starts with "audit.", its other keys accepted as they are
48
+ * @ServiceAction({resource: 'account', act: 'audit.*'})
49
+ * public async audit(input: Record<string, unknown>): Promise<void> {
50
+ * console.log(input)
51
+ * }
52
+ * }
53
+ *
54
+ * Application.run(() => ({
55
+ * id: 'bank.app',
56
+ * name: 'Bank',
57
+ * components: {
58
+ * entrypoint: buildEntrypoints({
59
+ * controllers: [AccountController],
60
+ * service: socketIOServiceEntrypoint({port: 3000})
61
+ * })
62
+ * },
63
+ * bootstrap: ['entrypoint']
64
+ * }))
65
+ * ```
66
+ */
67
+ export declare function ServiceAction<ClassPrototype extends Controller, Method>(pattern: ActionPattern): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
68
+ /**
69
+ * Expose the controller method as a service action addressed by a pattern, its input validated against a DTO. The input
70
+ * is the message without the keys of the pattern; the method receives it validated, as a plain object. The value
71
+ * returned is sent back as `{success: true, error: null, payload}`, an error as `{success: false, error, payload:
72
+ * null}` (a JSON-RPC result or error response).
73
+ * @param pattern The pattern of the action: an object (nested 2 levels at most) whose keys the messages must hold with
74
+ * the same values; a string value may be a glob (`'user.*'`, `*` any characters, `?` one). The most specific pattern
75
+ * matching a message wins. The controller's `@Prefix({pattern})` is merged into it.
76
+ * @param dtoConstructor The DTO class validating the input: the message without the keys of the pattern.
77
+ * @returns The method decorator.
78
+ * @throws {InvalidActionPatternDepthException} When the class is declared, if the pattern is nested more than 2 levels.
79
+ */
80
+ export declare function ServiceAction<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(pattern: ActionPattern, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
81
+ /**
82
+ * Expose the controller method as a service action addressed by a pattern, with action options; the input, the message
83
+ * without the keys of the pattern, is accepted as it is. The value returned is sent back as `{success: true, error:
84
+ * null, payload}`, an error as `{success: false, error, payload: null}` (a JSON-RPC result or error response).
85
+ * @param pattern The pattern of the action: an object (nested 2 levels at most) whose keys the messages must hold with
86
+ * the same values; a string value may be a glob (`'user.*'`, `*` any characters, `?` one). The most specific pattern
87
+ * matching a message wins. The controller's `@Prefix({pattern})` is merged into it.
88
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in
89
+ * the service actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an
90
+ * access rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
91
+ * @returns The method decorator.
92
+ * @throws {InvalidActionPatternDepthException} When the class is declared, if the pattern is nested more than 2 levels.
93
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
94
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
95
+ * nor a class extending `Middleware`.
96
+ */
97
+ export declare function ServiceAction<ClassPrototype extends Controller, Method>(pattern: ActionPattern, actionOptions: ActionOptions<ServiceContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
98
+ /**
99
+ * Expose the controller method as a service action addressed by a pattern, its input validated against a DTO, with
100
+ * action options. The input is the message without the keys of the pattern; the method receives it validated, as a
101
+ * plain object. The value returned is sent back as `{success: true, error: null, payload}`, an error as `{success:
102
+ * false, error, payload: null}` (a JSON-RPC result or error response).
103
+ * @param pattern The pattern of the action: an object (nested 2 levels at most) whose keys the messages must hold with
104
+ * the same values; a string value may be a glob (`'user.*'`, `*` any characters, `?` one). The most specific pattern
105
+ * matching a message wins. The controller's `@Prefix({pattern})` is merged into it.
106
+ * @param dtoConstructor The DTO class validating the input: the message without the keys of the pattern.
107
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in
108
+ * the service actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an
109
+ * access rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
110
+ * @returns The method decorator.
111
+ * @throws {InvalidActionPatternDepthException} When the class is declared, if the pattern is nested more than 2 levels.
112
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
113
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
114
+ * nor a class extending `Middleware`.
115
+ */
116
+ export declare function ServiceAction<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(pattern: ActionPattern, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<ServiceContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServiceAction = ServiceAction;
4
+ const ControllerEntrypoint_js_1 = require("../lib/ControllerEntrypoint.js");
5
+ const GetActionDTOAndOptions_js_1 = require("../lib/GetActionDTOAndOptions.js");
6
+ function ServiceAction(pattern, dtoConstructorOrOptions, options) {
7
+ return (target, propertyKey, descriptor) => {
8
+ const [dtoConstructor, actionOptions] = (0, GetActionDTOAndOptions_js_1.getActionDTOAndOptions)(dtoConstructorOrOptions, options);
9
+ (0, ControllerEntrypoint_js_1.registerServiceAction)(pattern, target, propertyKey, dtoConstructor, actionOptions);
10
+ return descriptor;
11
+ };
12
+ }
@@ -0,0 +1,52 @@
1
+ import { MiddlewareDefinition } from '../lib/Middleware.js';
2
+ /**
3
+ * Add middlewares to all the actions of a controller (on the class) or to one action (on the method). A middleware is a
4
+ * function `(invocation, next) => Promise<unknown>` or a class extending `Middleware`, created in the container of each
5
+ * request (its dependencies injected). It receives the request's context, whose data is the input before validation,
6
+ * and returns the result of `next()` (the rest of the pipeline), or another value without calling it, which is then
7
+ * answered instead of the action's result; an error it throws is answered as the action's error.
8
+ *
9
+ * The order of a request: the entrypoint's `middlewares`, the adapter's `middlewares`, the ones of the controller classes
10
+ * (the parent classes first), of the action options, of the action method, then the input validation, the access
11
+ * control and the action. Several `@UseMiddlewares` on a target run from top to bottom, the middlewares of each in their
12
+ * order. The middlewares of a method are taken from the nearest class declaring them for it: an overriding method
13
+ * replaces them.
14
+ * @param middlewares The middleware functions and classes, in their running order.
15
+ * @returns The class or method decorator.
16
+ * @throws {InvalidMiddlewareException} When the decorator is called, if a middleware is neither a function nor a class
17
+ * extending `Middleware`.
18
+ * @example
19
+ * ```typescript
20
+ * import {Controller, Middleware, type ActionInvocation, type Next} from 'lakutata/com/entrypoint'
21
+ * import {GET, UseMiddlewares} from 'lakutata/decorator/ctrl'
22
+ *
23
+ * //A middleware function: logs the duration of each action of the controller
24
+ * async function Timing(invocation: ActionInvocation, next: Next): Promise<unknown> {
25
+ * const started: number = Date.now()
26
+ * try {
27
+ * return await next()
28
+ * } finally {
29
+ * console.log(`${invocation.action.name}: ${Date.now() - started}ms`)
30
+ * }
31
+ * }
32
+ *
33
+ * //A middleware class: answers without running the action during a maintenance
34
+ * class Maintenance extends Middleware {
35
+ * public async handle(invocation: ActionInvocation, next: Next): Promise<unknown> {
36
+ * if (process.env.MAINTENANCE) return {maintenance: true}
37
+ * return await next()
38
+ * }
39
+ * }
40
+ *
41
+ * @UseMiddlewares(Timing)
42
+ * class StatusController extends Controller {
43
+ * //Timing, then Maintenance, then the action
44
+ * @GET('/status')
45
+ * @UseMiddlewares(Maintenance)
46
+ * public async status(): Promise<{ ok: boolean }> {
47
+ * return {ok: true}
48
+ * }
49
+ * }
50
+ * ```
51
+ */
52
+ export declare function UseMiddlewares(...middlewares: MiddlewareDefinition[]): (target: object, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseMiddlewares = UseMiddlewares;
4
+ const Middleware_js_1 = require("../lib/Middleware.js");
5
+ /**
6
+ * Add middlewares to all the actions of a controller (on the class) or to one action (on the method). A middleware is a
7
+ * function `(invocation, next) => Promise<unknown>` or a class extending `Middleware`, created in the container of each
8
+ * request (its dependencies injected). It receives the request's context, whose data is the input before validation,
9
+ * and returns the result of `next()` (the rest of the pipeline), or another value without calling it, which is then
10
+ * answered instead of the action's result; an error it throws is answered as the action's error.
11
+ *
12
+ * The order of a request: the entrypoint's `middlewares`, the adapter's `middlewares`, the ones of the controller classes
13
+ * (the parent classes first), of the action options, of the action method, then the input validation, the access
14
+ * control and the action. Several `@UseMiddlewares` on a target run from top to bottom, the middlewares of each in their
15
+ * order. The middlewares of a method are taken from the nearest class declaring them for it: an overriding method
16
+ * replaces them.
17
+ * @param middlewares The middleware functions and classes, in their running order.
18
+ * @returns The class or method decorator.
19
+ * @throws {InvalidMiddlewareException} When the decorator is called, if a middleware is neither a function nor a class
20
+ * extending `Middleware`.
21
+ * @example
22
+ * ```typescript
23
+ * import {Controller, Middleware, type ActionInvocation, type Next} from 'lakutata/com/entrypoint'
24
+ * import {GET, UseMiddlewares} from 'lakutata/decorator/ctrl'
25
+ *
26
+ * //A middleware function: logs the duration of each action of the controller
27
+ * async function Timing(invocation: ActionInvocation, next: Next): Promise<unknown> {
28
+ * const started: number = Date.now()
29
+ * try {
30
+ * return await next()
31
+ * } finally {
32
+ * console.log(`${invocation.action.name}: ${Date.now() - started}ms`)
33
+ * }
34
+ * }
35
+ *
36
+ * //A middleware class: answers without running the action during a maintenance
37
+ * class Maintenance extends Middleware {
38
+ * public async handle(invocation: ActionInvocation, next: Next): Promise<unknown> {
39
+ * if (process.env.MAINTENANCE) return {maintenance: true}
40
+ * return await next()
41
+ * }
42
+ * }
43
+ *
44
+ * @UseMiddlewares(Timing)
45
+ * class StatusController extends Controller {
46
+ * //Timing, then Maintenance, then the action
47
+ * @GET('/status')
48
+ * @UseMiddlewares(Maintenance)
49
+ * public async status(): Promise<{ ok: boolean }> {
50
+ * return {ok: true}
51
+ * }
52
+ * }
53
+ * ```
54
+ */
55
+ function UseMiddlewares(...middlewares) {
56
+ (0, Middleware_js_1.validateMiddlewares)(middlewares);
57
+ return (target, propertyKey) => (0, Middleware_js_1.addMiddlewares)(target, propertyKey, middlewares);
58
+ }
@@ -0,0 +1,87 @@
1
+ import { Controller, type ControllerProperty } from '../../lib/Controller.js';
2
+ import { DTO, MethodDecorator } from '@lakutata/core';
3
+ import { ActionOptions } from '../../lib/ActionOptions.js';
4
+ import { HTTPContext } from '../../context/HTTPContext.js';
5
+ /**
6
+ * Expose the controller method as an HTTP DELETE action on a route, to delete a resource: the shorthand of
7
+ * `@HTTPAction(route, 'delete', …)`. The adapter assembles the input: by default, the query string merged with the
8
+ * parsed body (JSON or URL encoded), then the route parameters over them. The middlewares run, the input is validated
9
+ * against the DTO (the defaults applied, the unknown keys removed; without a DTO, it is accepted as it is), the access
10
+ * control runs when `acl` is set, then the method receives the validated input as a plain object. The query values and
11
+ * the route parameters are strings and the DTO schemas are strict: convert them with `.strict(false)`. The value
12
+ * returned is answered by the adapter's responder: as JSON by default, with the status 204 for `undefined`;
13
+ * `Result.status()` sets a status and headers. An error thrown is answered as `{errno, errMsg}` with the first 4xx
14
+ * `statusCode` along its causes (400 for an invalid input), else its own `statusCode`, else 500.
15
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
16
+ * prepended to it.
17
+ * @returns The method decorator.
18
+ * @example
19
+ * ```typescript
20
+ * import {DTO} from 'lakutata'
21
+ * import {Controller} from 'lakutata/com/entrypoint'
22
+ * import {DELETE} from 'lakutata/decorator/ctrl'
23
+ * import {Expect} from 'lakutata/decorator/dto'
24
+ *
25
+ * class SessionIdDTO extends DTO {
26
+ * @Expect(DTO.String().uuid().required())
27
+ * public id!: string
28
+ * }
29
+ *
30
+ * class SessionController extends Controller {
31
+ * //DELETE /sessions/<uuid>: answered with the status 204 (no content), an invalid id with the status 400
32
+ * @DELETE('/sessions/:id', SessionIdDTO, {acl: true})
33
+ * public async revoke(input: SessionIdDTO): Promise<void> {
34
+ * console.log(`revoke ${input.id}`)
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ export declare function DELETE<ClassPrototype extends Controller, Method>(r: string): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
40
+ /**
41
+ * Expose the controller method as an HTTP DELETE action on a route, its input validated against a DTO: the shorthand of
42
+ * `@HTTPAction(route, 'delete', …)`. The input is the query string merged with the parsed body, then the route
43
+ * parameters over them (the default of the adapters); the method receives it validated, as a plain object. The value
44
+ * returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status (400 for an invalid
45
+ * input, else 500 by default).
46
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
47
+ * prepended to it.
48
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
49
+ * convert them with `.strict(false)`.
50
+ * @returns The method decorator.
51
+ */
52
+ export declare function DELETE<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
53
+ /**
54
+ * Expose the controller method as an HTTP DELETE action on a route, with action options: the shorthand of
55
+ * `@HTTPAction(route, 'delete', …)`. The input is the query string merged with the parsed body, then the route
56
+ * parameters over them (the default of the adapters), accepted as it is. The value returned is answered as JSON (204
57
+ * for `undefined`), an error as `{errno, errMsg}` with its status (500 by default).
58
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
59
+ * prepended to it.
60
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
61
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
62
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
63
+ * @returns The method decorator.
64
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
65
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
66
+ * nor a class extending `Middleware`.
67
+ */
68
+ export declare function DELETE<ClassPrototype extends Controller, Method>(r: string, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
69
+ /**
70
+ * Expose the controller method as an HTTP DELETE action on a route, its input validated against a DTO, with action
71
+ * options: the shorthand of `@HTTPAction(route, 'delete', …)`. The input is the query string merged with the parsed
72
+ * body, then the route parameters over them (the default of the adapters); the method receives it validated, as a plain
73
+ * object. The value returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status
74
+ * (400 for an invalid input, else 500 by default).
75
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
76
+ * prepended to it.
77
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
78
+ * convert them with `.strict(false)`.
79
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
80
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
81
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
82
+ * @returns The method decorator.
83
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
84
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
85
+ * nor a class extending `Middleware`.
86
+ */
87
+ export declare function DELETE<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DELETE = DELETE;
4
+ const HTTPAction_js_1 = require("../HTTPAction.js");
5
+ function DELETE(r, dtoConstructorOrOptions, options) {
6
+ return (0, HTTPAction_js_1.HTTPAction)(r, 'delete', dtoConstructorOrOptions, options);
7
+ }
@@ -0,0 +1,89 @@
1
+ import { Controller, type ControllerProperty } from '../../lib/Controller.js';
2
+ import { DTO, MethodDecorator } from '@lakutata/core';
3
+ import { ActionOptions } from '../../lib/ActionOptions.js';
4
+ import { HTTPContext } from '../../context/HTTPContext.js';
5
+ /**
6
+ * Expose the controller method as an HTTP GET action on a route, to read a resource: the shorthand of
7
+ * `@HTTPAction(route, 'get', …)`. The adapter assembles the input: by default, the query string merged with the parsed
8
+ * body (JSON or URL encoded), then the route parameters over them. The middlewares run, the input is validated against
9
+ * the DTO (the defaults applied, the unknown keys removed; without a DTO, it is accepted as it is), the access control
10
+ * runs when `acl` is set, then the method receives the validated input as a plain object. The query values and the
11
+ * route parameters are strings and the DTO schemas are strict: convert them with `.strict(false)`. The value returned
12
+ * is answered by the adapter's responder: as JSON by default, with the status 204 for `undefined`; `Result.status()`
13
+ * sets a status and headers. An error thrown is answered as `{errno, errMsg}` with the first 4xx `statusCode` along its
14
+ * causes (400 for an invalid input), else its own `statusCode`, else 500.
15
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
16
+ * prepended to it.
17
+ * @returns The method decorator.
18
+ * @example
19
+ * ```typescript
20
+ * import {DTO} from 'lakutata'
21
+ * import {Controller} from 'lakutata/com/entrypoint'
22
+ * import {GET} from 'lakutata/decorator/ctrl'
23
+ * import {Expect} from 'lakutata/decorator/dto'
24
+ *
25
+ * class UserIdDTO extends DTO {
26
+ * //A route parameter is a string: converted to a number
27
+ * @Expect(DTO.Number().integer().min(1).strict(false).required())
28
+ * public id!: number
29
+ * }
30
+ *
31
+ * class UserController extends Controller {
32
+ * //GET /users/42: answered with the JSON {"id": 42, "name": "user42"}; GET /users/abc: the status 400 and
33
+ * //{"errno": "E_INVALID_VALUE", "errMsg": …}
34
+ * @GET('/users/:id', UserIdDTO)
35
+ * public async get(input: UserIdDTO): Promise<{ id: number, name: string }> {
36
+ * return {id: input.id, name: `user${input.id}`}
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ export declare function GET<ClassPrototype extends Controller, Method>(r: string): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
42
+ /**
43
+ * Expose the controller method as an HTTP GET action on a route, its input validated against a DTO: the shorthand of
44
+ * `@HTTPAction(route, 'get', …)`. The input is the query string merged with the parsed body, then the route parameters
45
+ * over them (the default of the adapters); the method receives it validated, as a plain object. The value returned is
46
+ * answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status (400 for an invalid input, else
47
+ * 500 by default).
48
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
49
+ * prepended to it.
50
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
51
+ * convert them with `.strict(false)`.
52
+ * @returns The method decorator.
53
+ */
54
+ export declare function GET<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
55
+ /**
56
+ * Expose the controller method as an HTTP GET action on a route, with action options: the shorthand of
57
+ * `@HTTPAction(route, 'get', …)`. The input is the query string merged with the parsed body, then the route parameters
58
+ * over them (the default of the adapters), accepted as it is. The value returned is answered as JSON (204 for
59
+ * `undefined`), an error as `{errno, errMsg}` with its status (500 by default).
60
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
61
+ * prepended to it.
62
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
63
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
64
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
65
+ * @returns The method decorator.
66
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
67
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
68
+ * nor a class extending `Middleware`.
69
+ */
70
+ export declare function GET<ClassPrototype extends Controller, Method>(r: string, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
71
+ /**
72
+ * Expose the controller method as an HTTP GET action on a route, its input validated against a DTO, with action
73
+ * options: the shorthand of `@HTTPAction(route, 'get', …)`. The input is the query string merged with the parsed body,
74
+ * then the route parameters over them (the default of the adapters); the method receives it validated, as a plain
75
+ * object. The value returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status
76
+ * (400 for an invalid input, else 500 by default).
77
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
78
+ * prepended to it.
79
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
80
+ * convert them with `.strict(false)`.
81
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
82
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
83
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
84
+ * @returns The method decorator.
85
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
86
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
87
+ * nor a class extending `Middleware`.
88
+ */
89
+ export declare function GET<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GET = GET;
4
+ const HTTPAction_js_1 = require("../HTTPAction.js");
5
+ function GET(r, dtoConstructorOrOptions, options) {
6
+ return (0, HTTPAction_js_1.HTTPAction)(r, 'get', dtoConstructorOrOptions, options);
7
+ }
@@ -0,0 +1,84 @@
1
+ import { Controller, type ControllerProperty } from '../../lib/Controller.js';
2
+ import { DTO, MethodDecorator } from '@lakutata/core';
3
+ import { ActionOptions } from '../../lib/ActionOptions.js';
4
+ import { HTTPContext } from '../../context/HTTPContext.js';
5
+ /**
6
+ * Expose the controller method as an HTTP HEAD action on a route, to answer the headers of a resource without its body:
7
+ * the shorthand of `@HTTPAction(route, 'head', …)`. The adapter assembles the input: by default, the query string
8
+ * merged with the parsed body (JSON or URL encoded), then the route parameters over them. The middlewares run, the
9
+ * input is validated against the DTO (the defaults applied, the unknown keys removed; without a DTO, it is accepted as
10
+ * it is), the access control runs when `acl` is set, then the method receives the validated input as a plain object.
11
+ * The query values and the route parameters are strings and the DTO schemas are strict: convert them with
12
+ * `.strict(false)`. The value returned is answered by the adapter's responder: as JSON by default, with the status 204
13
+ * for `undefined`; `Result.status()` sets a status and headers. An error thrown is answered as `{errno, errMsg}` with
14
+ * the first 4xx `statusCode` along its causes (400 for an invalid input), else its own `statusCode`, else 500.
15
+ * With Fastify, a GET action also answers the HEAD requests of its route unless the route has a HEAD action.
16
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
17
+ * prepended to it.
18
+ * @returns The method decorator.
19
+ * @example
20
+ * ```typescript
21
+ * import {Controller, Result, type StatusResult} from 'lakutata/com/entrypoint'
22
+ * import {HEAD} from 'lakutata/decorator/ctrl'
23
+ *
24
+ * class HealthController extends Controller {
25
+ * //HEAD /health: answered with the status 200 and the header X-Health, without a body
26
+ * @HEAD('/health')
27
+ * public async health(): Promise<StatusResult> {
28
+ * return Result.status(200, undefined, {'X-Health': 'ok'})
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ export declare function HEAD<ClassPrototype extends Controller, Method>(r: string): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
34
+ /**
35
+ * Expose the controller method as an HTTP HEAD action on a route, its input validated against a DTO: the shorthand of
36
+ * `@HTTPAction(route, 'head', …)`. The input is the query string merged with the parsed body, then the route parameters
37
+ * over them (the default of the adapters); the method receives it validated, as a plain object. The value returned is
38
+ * answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status (400 for an invalid input, else
39
+ * 500 by default).
40
+ * With Fastify, a GET action also answers the HEAD requests of its route unless the route has a HEAD action.
41
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
42
+ * prepended to it.
43
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
44
+ * convert them with `.strict(false)`.
45
+ * @returns The method decorator.
46
+ */
47
+ export declare function HEAD<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
48
+ /**
49
+ * Expose the controller method as an HTTP HEAD action on a route, with action options: the shorthand of
50
+ * `@HTTPAction(route, 'head', …)`. The input is the query string merged with the parsed body, then the route parameters
51
+ * over them (the default of the adapters), accepted as it is. The value returned is answered as JSON (204 for
52
+ * `undefined`), an error as `{errno, errMsg}` with its status (500 by default).
53
+ * With Fastify, a GET action also answers the HEAD requests of its route unless the route has a HEAD action.
54
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
55
+ * prepended to it.
56
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
57
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
58
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
59
+ * @returns The method decorator.
60
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
61
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
62
+ * nor a class extending `Middleware`.
63
+ */
64
+ export declare function HEAD<ClassPrototype extends Controller, Method>(r: string, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
65
+ /**
66
+ * Expose the controller method as an HTTP HEAD action on a route, its input validated against a DTO, with action
67
+ * options: the shorthand of `@HTTPAction(route, 'head', …)`. The input is the query string merged with the parsed body,
68
+ * then the route parameters over them (the default of the adapters); the method receives it validated, as a plain
69
+ * object. The value returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status
70
+ * (400 for an invalid input, else 500 by default).
71
+ * With Fastify, a GET action also answers the HEAD requests of its route unless the route has a HEAD action.
72
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
73
+ * prepended to it.
74
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
75
+ * convert them with `.strict(false)`.
76
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
77
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
78
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
79
+ * @returns The method decorator.
80
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
81
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
82
+ * nor a class extending `Middleware`.
83
+ */
84
+ export declare function HEAD<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HEAD = HEAD;
4
+ const HTTPAction_js_1 = require("../HTTPAction.js");
5
+ function HEAD(r, dtoConstructorOrOptions, options) {
6
+ return (0, HTTPAction_js_1.HTTPAction)(r, 'head', dtoConstructorOrOptions, options);
7
+ }
@@ -0,0 +1,80 @@
1
+ import { Controller, type ControllerProperty } from '../../lib/Controller.js';
2
+ import { DTO, MethodDecorator } from '@lakutata/core';
3
+ import { ActionOptions } from '../../lib/ActionOptions.js';
4
+ import { HTTPContext } from '../../context/HTTPContext.js';
5
+ /**
6
+ * Expose the controller method as an HTTP OPTIONS action on a route, to describe the communication options of a
7
+ * resource: the shorthand of `@HTTPAction(route, 'options', …)`. The adapter assembles the input: by default, the query
8
+ * string merged with the parsed body (JSON or URL encoded), then the route parameters over them. The middlewares run,
9
+ * the input is validated against the DTO (the defaults applied, the unknown keys removed; without a DTO, it is accepted
10
+ * as it is), the access control runs when `acl` is set, then the method receives the validated input as a plain object.
11
+ * The query values and the route parameters are strings and the DTO schemas are strict: convert them with
12
+ * `.strict(false)`. The value returned is answered by the adapter's responder: as JSON by default, with the status 204
13
+ * for `undefined`; `Result.status()` sets a status and headers. An error thrown is answered as `{errno, errMsg}` with
14
+ * the first 4xx `statusCode` along its causes (400 for an invalid input), else its own `statusCode`, else 500.
15
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
16
+ * prepended to it.
17
+ * @returns The method decorator.
18
+ * @example
19
+ * ```typescript
20
+ * import {Controller, Result, type StatusResult} from 'lakutata/com/entrypoint'
21
+ * import {OPTIONS} from 'lakutata/decorator/ctrl'
22
+ *
23
+ * class UploadController extends Controller {
24
+ * //OPTIONS /uploads: answered with the status 204 and the header Allow
25
+ * @OPTIONS('/uploads')
26
+ * public async options(): Promise<StatusResult> {
27
+ * return Result.status(204, undefined, {Allow: 'OPTIONS, POST'})
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function OPTIONS<ClassPrototype extends Controller, Method>(r: string): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
33
+ /**
34
+ * Expose the controller method as an HTTP OPTIONS action on a route, its input validated against a DTO: the shorthand
35
+ * of `@HTTPAction(route, 'options', …)`. The input is the query string merged with the parsed body, then the route
36
+ * parameters over them (the default of the adapters); the method receives it validated, as a plain object. The value
37
+ * returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status (400 for an invalid
38
+ * input, else 500 by default).
39
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
40
+ * prepended to it.
41
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
42
+ * convert them with `.strict(false)`.
43
+ * @returns The method decorator.
44
+ */
45
+ export declare function OPTIONS<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
46
+ /**
47
+ * Expose the controller method as an HTTP OPTIONS action on a route, with action options: the shorthand of
48
+ * `@HTTPAction(route, 'options', …)`. The input is the query string merged with the parsed body, then the route
49
+ * parameters over them (the default of the adapters), accepted as it is. The value returned is answered as JSON (204
50
+ * for `undefined`), an error as `{errno, errMsg}` with its status (500 by default).
51
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
52
+ * prepended to it.
53
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
54
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
55
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
56
+ * @returns The method decorator.
57
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
58
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
59
+ * nor a class extending `Middleware`.
60
+ */
61
+ export declare function OPTIONS<ClassPrototype extends Controller, Method>(r: string, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
62
+ /**
63
+ * Expose the controller method as an HTTP OPTIONS action on a route, its input validated against a DTO, with action
64
+ * options: the shorthand of `@HTTPAction(route, 'options', …)`. The input is the query string merged with the parsed
65
+ * body, then the route parameters over them (the default of the adapters); the method receives it validated, as a plain
66
+ * object. The value returned is answered as JSON (204 for `undefined`), an error as `{errno, errMsg}` with its status
67
+ * (400 for an invalid input, else 500 by default).
68
+ * @param r The route, in the syntax of the HTTP adapter (`/users/:id`); the controller's `@Prefix({route})` is
69
+ * prepended to it.
70
+ * @param dtoConstructor The DTO class validating the input; the query values and the route parameters are strings,
71
+ * convert them with `.strict(false)`.
72
+ * @param actionOptions The action options: `acl` runs the access control rules (false by default); `name` (unique in the
73
+ * HTTP actions, `ClassName:method` by default), `description` and `groups` describe the action; `rule` is an access
74
+ * rule of the action; `middlewares` run before the ones `@UseMiddlewares` adds to the method.
75
+ * @returns The method decorator.
76
+ * @throws {InvalidValueException} When the class is declared, if the action options are invalid.
77
+ * @throws {InvalidMiddlewareException} When the class is declared, if a middleware of the options is neither a function
78
+ * nor a class extending `Middleware`.
79
+ */
80
+ export declare function OPTIONS<ClassPrototype extends Controller, Method, DTOConstructor extends typeof DTO = typeof DTO>(r: string, dtoConstructor: DTOConstructor, actionOptions: ActionOptions<HTTPContext>): MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPTIONS = OPTIONS;
4
+ const HTTPAction_js_1 = require("../HTTPAction.js");
5
+ function OPTIONS(r, dtoConstructorOrOptions, options) {
6
+ return (0, HTTPAction_js_1.HTTPAction)(r, 'options', dtoConstructorOrOptions, options);
7
+ }