@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,164 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadPrompts = loadPrompts;
37
+ exports.prompt = prompt;
38
+ const node_stream_1 = require("node:stream");
39
+ const core_1 = require("@lakutata/core");
40
+ /**
41
+ * The property names of the secrets, prompted without echo
42
+ */
43
+ const SECRET = /pass(word)?|secret|token|api[-_]?key|credential/i;
44
+ /**
45
+ * The prompts, undefined when @inquirer/prompts is not installed
46
+ */
47
+ let prompts;
48
+ /**
49
+ * Load the prompts
50
+ */
51
+ function loadPrompts() {
52
+ prompts ??= Promise.resolve().then(() => __importStar(require('@inquirer/prompts'))).catch(() => undefined);
53
+ return prompts;
54
+ }
55
+ /**
56
+ * The type of a property, without null
57
+ * @param schema
58
+ */
59
+ function typeOf(schema) {
60
+ const types = [].concat(schema.type ?? []).filter((type) => type !== 'null');
61
+ if (types.length)
62
+ return types[0];
63
+ if (schema.enum?.length)
64
+ return typeof schema.enum[0];
65
+ return undefined;
66
+ }
67
+ /**
68
+ * Validate an answer by the rules of its property in the DTO of the action
69
+ * @param dto
70
+ * @param property
71
+ */
72
+ function validator(dto, property) {
73
+ let field;
74
+ try {
75
+ field = dto.Schema().extract(property).label(property);
76
+ }
77
+ catch {
78
+ //A property without its own rule is validated with the whole input
79
+ return async () => true;
80
+ }
81
+ return async (value) => {
82
+ try {
83
+ await core_1.DTO.validateAsync(value, field);
84
+ return true;
85
+ }
86
+ catch (error) {
87
+ return error.errMsg ?? error.message;
88
+ }
89
+ };
90
+ }
91
+ /**
92
+ * Prompt for the required properties missing from the input of an action, when @inquirer/prompts is installed
93
+ * @param action
94
+ * @param data
95
+ * @param streams
96
+ * @param describe the description of a property in the language of the user
97
+ * @param say the text of the prompts in the language of the user
98
+ */
99
+ async function prompt(action, data, streams, describe = (property) => action.jsonSchema.properties?.[property]?.description, say = (key, text) => text) {
100
+ const schema = action.jsonSchema;
101
+ const missing = (schema.required ?? []).filter((property) => data[property] === undefined && schema.properties?.[property]?.default === undefined);
102
+ if (!missing.length)
103
+ return;
104
+ const inquirer = await loadPrompts();
105
+ if (!inquirer)
106
+ return;
107
+ for (const property of missing) {
108
+ //A prompt ends its output once answered, the output of the adapter is kept open
109
+ const output = new node_stream_1.PassThrough();
110
+ output.pipe(streams.output, { end: false });
111
+ try {
112
+ data[property] = await ask(inquirer, action, property, schema.properties?.[property] ?? {}, { input: streams.input, output: output, signal: streams.signal }, describe(property), say);
113
+ }
114
+ finally {
115
+ output.unpipe(streams.output);
116
+ }
117
+ }
118
+ }
119
+ /**
120
+ * Ask for a property
121
+ * @param inquirer
122
+ * @param action
123
+ * @param property
124
+ * @param propertySchema
125
+ * @param context
126
+ * @param description the description of the property in the language of the user
127
+ * @param say the text of the prompts in the language of the user
128
+ */
129
+ async function ask(inquirer, action, property, propertySchema, context, description, say) {
130
+ const message = description ? `${description} (${property})` : property;
131
+ const validate = validator(action.dto, property);
132
+ const type = typeOf(propertySchema);
133
+ const choices = (values) => values.map((value) => ({ name: String(value), value: value }));
134
+ if (type === 'boolean')
135
+ return await inquirer.confirm({ message: message }, context);
136
+ if (propertySchema.enum)
137
+ return await inquirer.select({ message: message, choices: choices(propertySchema.enum) }, context);
138
+ if (type === 'array' && propertySchema.items?.enum)
139
+ return await inquirer.checkbox({ message: message, choices: choices(propertySchema.items.enum), validate: (selected) => validate(selected.map((choice) => choice.value)) }, context);
140
+ if (type === 'number' || type === 'integer')
141
+ return await inquirer.number({ message: message, required: true, step: type === 'integer' ? 1 : 'any', validate: validate }, context);
142
+ if (type === 'string' && (propertySchema.format === 'password' || SECRET.test(property)))
143
+ return await inquirer.password({ message: message, mask: '*', validate: validate }, context);
144
+ //The arrays are separated by commas, the objects are written in JSON
145
+ const parse = (answer) => {
146
+ if (type === 'array')
147
+ return answer.split(',').map((item) => item.trim()).filter((item) => !!item);
148
+ if (type === 'object')
149
+ return JSON.parse(answer);
150
+ return answer;
151
+ };
152
+ return parse(await inquirer.input({
153
+ message: message,
154
+ required: true,
155
+ validate: async (value) => {
156
+ try {
157
+ return await validate(parse(value));
158
+ }
159
+ catch {
160
+ return say('prompt.json', 'Not a JSON object');
161
+ }
162
+ }
163
+ }, context));
164
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The width of a text in a terminal, the wide characters taking two columns
3
+ * @param text
4
+ */
5
+ export declare function displayWidth(text: string): number;
6
+ /**
7
+ * Wrap a text to a width, as commander does, the lines of wide characters wrapped between them
8
+ * @param text
9
+ * @param width
10
+ * @param minimum the width under which the text is not wrapped
11
+ */
12
+ export declare function boxWrap(text: string, width: number, minimum?: number): string;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayWidth = displayWidth;
4
+ exports.boxWrap = boxWrap;
5
+ const node_util_1 = require("node:util");
6
+ /**
7
+ * The wide characters of the terminals: the Chinese, Japanese and Korean ones, the full width forms
8
+ */
9
+ const WIDE = '\\u1100-\\u115F\\u2E80-\\u303E\\u3041-\\u33FF\\u3400-\\u4DBF\\u4E00-\\u9FFF\\uA000-\\uA4CF\\uAC00-\\uD7A3\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFF60\\uFFE0-\\uFFE6\\u{20000}-\\u{3FFFD}';
10
+ /**
11
+ * The punctuation which does not start a line
12
+ */
13
+ const CLOSING = '、。,.:;!?)」』】〕〉》%,.:;!?)\\]}';
14
+ /**
15
+ * The punctuation which does not end a line
16
+ */
17
+ const OPENING = '(「『【〔〈《(\\[{';
18
+ const WIDE_CHARACTER = new RegExp(`[${WIDE}]`, 'u');
19
+ /**
20
+ * The chunks of a line the wrapping keeps whole: a word, or a wide character, with the punctuation opening and
21
+ * closing it
22
+ */
23
+ const CHUNK = new RegExp(`\\s*[${OPENING}]*(?:[${WIDE}]|[^\\s${WIDE}]+)[${CLOSING}]*`, 'gu');
24
+ /**
25
+ * The width of a text in a terminal, the wide characters taking two columns
26
+ * @param text
27
+ */
28
+ function displayWidth(text) {
29
+ let width = 0;
30
+ for (const character of (0, node_util_1.stripVTControlCharacters)(text))
31
+ width += WIDE_CHARACTER.test(character) ? 2 : 1;
32
+ return width;
33
+ }
34
+ /**
35
+ * Wrap a text to a width, as commander does, the lines of wide characters wrapped between them
36
+ * @param text
37
+ * @param width
38
+ * @param minimum the width under which the text is not wrapped
39
+ */
40
+ function boxWrap(text, width, minimum = 40) {
41
+ if (width < minimum)
42
+ return text;
43
+ const wrapped = [];
44
+ for (const line of text.split(/\r\n|\n/)) {
45
+ const chunks = line.match(CHUNK);
46
+ if (!chunks) {
47
+ wrapped.push('');
48
+ continue;
49
+ }
50
+ let current = chunks.shift();
51
+ let currentWidth = displayWidth(current);
52
+ for (const chunk of chunks) {
53
+ const chunkWidth = displayWidth(chunk);
54
+ if (currentWidth + chunkWidth <= width) {
55
+ current += chunk;
56
+ currentWidth += chunkWidth;
57
+ continue;
58
+ }
59
+ wrapped.push(current);
60
+ //The space at the break removed
61
+ current = chunk.trimStart();
62
+ currentWidth = displayWidth(current);
63
+ }
64
+ wrapped.push(current);
65
+ }
66
+ return wrapped.join('\n');
67
+ }
@@ -0,0 +1,203 @@
1
+ import type { EntrypointAdapter } from '../../channel/EntrypointAdapter.js';
2
+ import type { MiddlewareDefinition } from '../../lib/Middleware.js';
3
+ import { ServiceContext } from '../../context/ServiceContext.js';
4
+ /**
5
+ * The part of Electron's `WebContents` (a renderer) that {@link electronIPCServiceEntrypoint} uses: the sender of the
6
+ * invocations and the receiver of the events pushed to its pages.
7
+ */
8
+ export type IPCSender = {
9
+ /**
10
+ * Listen once to the renderer's destruction, which aborts its requests in progress and removes its clients.
11
+ * @param event The `'destroyed'` event.
12
+ * @param listener Called when the renderer is destroyed.
13
+ */
14
+ once(event: 'destroyed', listener: () => void): unknown;
15
+ /**
16
+ * Remove a `'destroyed'` listener (`removeListener` is used without it).
17
+ * @param event The `'destroyed'` event.
18
+ * @param listener The listener to remove.
19
+ */
20
+ off?(event: 'destroyed', listener: () => void): unknown;
21
+ /**
22
+ * Remove a `'destroyed'` listener, when `off` is missing.
23
+ * @param event The `'destroyed'` event.
24
+ * @param listener The listener to remove.
25
+ */
26
+ removeListener?(event: 'destroyed', listener: () => void): unknown;
27
+ /**
28
+ * Send a message to the renderer's main frame, used to push an event to a client without a known frame.
29
+ * @param channel The IPC channel.
30
+ * @param args The message's arguments.
31
+ */
32
+ send?(channel: string, ...args: unknown[]): void;
33
+ /**
34
+ * Send a message to a frame of the renderer, used to push an event to the page of a client.
35
+ * @param frame The frame's process id and frame id.
36
+ * @param channel The IPC channel.
37
+ * @param args The message's arguments.
38
+ */
39
+ sendToFrame?(frame: [number, number], channel: string, ...args: unknown[]): void;
40
+ /**
41
+ * Tell whether the renderer is destroyed; its clients are then dropped instead of receiving the events.
42
+ * @returns Whether the renderer is destroyed.
43
+ */
44
+ isDestroyed?(): boolean;
45
+ };
46
+ /**
47
+ * The part of Electron's `IpcMainInvokeEvent` that {@link electronIPCServiceEntrypoint} uses, given to the service
48
+ * actions through {@link ipcEventOfContext}.
49
+ */
50
+ export type IPCInvokeEvent = {
51
+ /**
52
+ * The renderer that invoked.
53
+ */
54
+ readonly sender: IPCSender;
55
+ /**
56
+ * The id of the renderer process of the invoking frame.
57
+ */
58
+ readonly processId?: number;
59
+ /**
60
+ * The id of the invoking frame within its process.
61
+ */
62
+ readonly frameId?: number;
63
+ /**
64
+ * The invoking frame; a frame without `parent` is the main frame of its window.
65
+ */
66
+ readonly senderFrame?: {
67
+ readonly parent?: unknown;
68
+ } | null;
69
+ };
70
+ /**
71
+ * The part of Electron's `ipcMain` that {@link electronIPCServiceEntrypoint} uses (give a stand-in in the tests).
72
+ */
73
+ export type IPCMain = {
74
+ /**
75
+ * Handle the invocations of a channel (`ipcRenderer.invoke`).
76
+ * @param channel The IPC channel.
77
+ * @param listener Answers an invocation with its result.
78
+ */
79
+ handle(channel: string, listener: (event: any, ...args: any[]) => unknown): void;
80
+ /**
81
+ * Remove the handler of a channel, when the adapter closes.
82
+ * @param channel The IPC channel.
83
+ */
84
+ removeHandler(channel: string): void;
85
+ /**
86
+ * Listen to the messages of a channel (`ipcRenderer.send`), used for the event subscriptions; without it, the pages
87
+ * are registered as clients only when they invoke with their id.
88
+ * @param channel The IPC channel.
89
+ * @param listener Called with each message.
90
+ */
91
+ on?(channel: string, listener: (event: any, ...args: any[]) => void): unknown;
92
+ /**
93
+ * Remove the listeners of a channel, when the adapter closes.
94
+ * @param channel The IPC channel.
95
+ */
96
+ removeAllListeners?(channel: string): unknown;
97
+ };
98
+ /**
99
+ * The options of {@link electronIPCServiceEntrypoint}.
100
+ */
101
+ export type ElectronIPCServiceEntrypointOptions = {
102
+ /**
103
+ * The adapter name, to tell apart several service adapters of one entrypoint.
104
+ */
105
+ name?: string;
106
+ /**
107
+ * The IPC channel of the requests (`ipcRenderer.invoke(channel, data, clientId)`). The events pushed to the pages are
108
+ * sent on `<channel>:event`, and a page subscribes to them by sending its client id on `<channel>:subscribe`.
109
+ * @default 'lakutata:service'
110
+ */
111
+ channel?: string;
112
+ /**
113
+ * The `ipcMain` to serve the requests on.
114
+ * @default the `ipcMain` of Electron's main process
115
+ */
116
+ ipcMain?: IPCMain;
117
+ /**
118
+ * The middlewares of this adapter's actions, run after the entrypoint's global middlewares.
119
+ */
120
+ middlewares?: MiddlewareDefinition[];
121
+ };
122
+ /**
123
+ * Get the IPC event of a service action's request, when {@link electronIPCServiceEntrypoint} serves it (to reach the
124
+ * invoking renderer or frame).
125
+ * @param context The service action's context (`this.context` in a controller).
126
+ * @returns The IPC event (Electron's `IpcMainInvokeEvent`, typed as `Event`), or `undefined` when another adapter serves
127
+ * the request.
128
+ * @example
129
+ * ```typescript
130
+ * import {Controller, ServiceContext} from 'lakutata/com/entrypoint'
131
+ * import {ipcEventOfContext} from 'lakutata/adapter/electron'
132
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
133
+ * import type {IpcMainInvokeEvent} from 'electron'
134
+ *
135
+ * class WindowController extends Controller {
136
+ * //ipcRenderer.invoke('lakutata:service', {cmd: 'window.url'})
137
+ * @ServiceAction({cmd: 'window.url'})
138
+ * public async url(): Promise<string | undefined> {
139
+ * return ipcEventOfContext<IpcMainInvokeEvent>(this.context as ServiceContext)?.sender.getURL()
140
+ * }
141
+ * }
142
+ * ```
143
+ */
144
+ export declare function ipcEventOfContext<Event extends IPCInvokeEvent = IPCInvokeEvent>(context: ServiceContext): Event | undefined;
145
+ /**
146
+ * Create a service adapter of an entrypoint served over Electron's IPC, in the main process. It needs the optional
147
+ * peer dependency `electron`: without the `ipcMain` option, the entrypoint fails to start outside Electron's main
148
+ * process.
149
+ *
150
+ * A renderer invokes the channel with the action's pattern and input, and optionally its client id:
151
+ * `ipcRenderer.invoke('lakutata:service', {cmd: 'echo', text: 'hi'}, clientId)`. The invocation resolves to
152
+ * `{success, error, payload}` (see `ServiceResponseCodec`): `payload` is the result, or `error` the whole error object
153
+ * when the action failed (no matching action, validation…).
154
+ *
155
+ * Each page is a client, identified by the id it gives (a non-empty string of at most 200 characters), which its
156
+ * requests carry as `ServiceContext.clientId`. A page registers by sending its id on `<channel>:subscribe` (or with
157
+ * any invocation giving it); a page reloaded in the same frame replaces its previous id. The events pushed by
158
+ * `Entrypoint.notify` and `Entrypoint.broadcast` are sent to the page's frame on `<channel>:event` with the event name
159
+ * and its arguments array. A destroyed renderer drops its clients.
160
+ *
161
+ * When a renderer is destroyed, its requests in progress are aborted (their abort signal fires). When the entrypoint
162
+ * stops, the new invocations resolve to an `EntrypointStoppedException` error; once the requests in progress end, the
163
+ * IPC handlers are removed.
164
+ * @param options The adapter options; by default it serves the channel `'lakutata:service'` on Electron's `ipcMain`.
165
+ * @returns The adapter, to give to the `service` option of `buildEntrypoints`.
166
+ * @example
167
+ * ```typescript
168
+ * import {Application} from 'lakutata'
169
+ * import {buildEntrypoints, Controller} from 'lakutata/com/entrypoint'
170
+ * import {ServiceAction} from 'lakutata/decorator/ctrl'
171
+ * import {electronIPCServiceEntrypoint} from 'lakutata/adapter/electron'
172
+ * import type {IpcRenderer, IpcRendererEvent} from 'electron'
173
+ *
174
+ * class EchoController extends Controller {
175
+ * @ServiceAction({cmd: 'echo'})
176
+ * public async echo(input: {text: string}): Promise<string> {
177
+ * return input.text
178
+ * }
179
+ * }
180
+ *
181
+ * //In the main process
182
+ * Application.run({
183
+ * id: 'desktop.app',
184
+ * name: 'Desktop',
185
+ * components: {
186
+ * entrypoint: buildEntrypoints({
187
+ * controllers: [EchoController],
188
+ * service: electronIPCServiceEntrypoint()
189
+ * })
190
+ * }
191
+ * })
192
+ *
193
+ * //In the preload script of a window
194
+ * declare const ipcRenderer: IpcRenderer
195
+ * const clientId: string = crypto.randomUUID()
196
+ * //The events pushed by entrypoint.notify(clientId, 'progress', 50)
197
+ * ipcRenderer.on('lakutata:service:event', (event: IpcRendererEvent, name: string, args: unknown[]): void => console.log(name, ...args))
198
+ * ipcRenderer.send('lakutata:service:subscribe', clientId)
199
+ * //{success: true, error: null, payload: 'hi'}
200
+ * console.log(await ipcRenderer.invoke('lakutata:service', {cmd: 'echo', text: 'hi'}, clientId))
201
+ * ```
202
+ */
203
+ export declare function electronIPCServiceEntrypoint(options?: ElectronIPCServiceEntrypointOptions): EntrypointAdapter<ServiceContext>;