@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,143 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { DTO } from '@lakutata/core';
11
+ import { Expect, IndexSignature } from '@lakutata/core/decorator/dto';
12
+ import { InvalidPrefixException } from '../exceptions/InvalidPrefixException.js';
13
+ /**
14
+ * A controller's action prefixes, given to `@Prefix`. The packages of the other channels add their own prefix keys
15
+ * (declaration merging); the keys are kept even when not declared here.
16
+ * @example
17
+ * ```typescript
18
+ * import {Controller} from 'lakutata/com/entrypoint'
19
+ * import {CLIAction, GET, Prefix, ServiceAction} from 'lakutata/decorator/ctrl'
20
+ *
21
+ * //GET /users/:id, the command user:get, the pattern {resource: 'user', act: 'get'}
22
+ * @Prefix({route: '/users', command: 'user', pattern: {resource: 'user'}})
23
+ * class UserController extends Controller {
24
+ * @GET('/:id')
25
+ * @CLIAction('get')
26
+ * @ServiceAction({act: 'get'})
27
+ * public async get(input: {id: string}): Promise<{id: string}> {
28
+ * return {id: input.id}
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ let PrefixOptions = class PrefixOptions extends DTO {
34
+ };
35
+ __decorate([
36
+ Expect(DTO.String().optional()),
37
+ __metadata("design:type", String)
38
+ ], PrefixOptions.prototype, "route", void 0);
39
+ __decorate([
40
+ Expect(DTO.String().optional()),
41
+ __metadata("design:type", String)
42
+ ], PrefixOptions.prototype, "command", void 0);
43
+ __decorate([
44
+ Expect(DTO.Object().optional()),
45
+ __metadata("design:type", Object)
46
+ ], PrefixOptions.prototype, "pattern", void 0);
47
+ PrefixOptions = __decorate([
48
+ IndexSignature(DTO.Any())
49
+ ], PrefixOptions);
50
+ export { PrefixOptions };
51
+ const CONTROLLER_PREFIX = Symbol('ENTRYPOINT.CONTROLLER.PREFIX');
52
+ /**
53
+ * Set a controller class's prefixes, merged over the ones already set on the class (by the decorators of the other
54
+ * channels). Used by `@Prefix` and by the prefix decorators of the packages providing a channel.
55
+ * @param controller The controller class.
56
+ * @param options The prefixes to set.
57
+ * @throws {Error} When the merged prefixes are invalid (the validation error of {@link PrefixOptions}).
58
+ * @example
59
+ * ```typescript
60
+ * import {Controller} from 'lakutata/com/entrypoint'
61
+ * import {setPrefix} from '@lakutata/entrypoint/channel'
62
+ *
63
+ * //A decorator of a "queue" channel prefixing the topics of a controller
64
+ * export function TopicPrefix(topic: string) {
65
+ * return (target: typeof Controller): void => setPrefix(target, {topic: topic})
66
+ * }
67
+ * ```
68
+ */
69
+ export function setPrefix(controller, options) {
70
+ const own = Reflect.getOwnMetadata(CONTROLLER_PREFIX, controller);
71
+ Reflect.defineMetadata(CONTROLLER_PREFIX, PrefixOptions.validate({ ...own, ...options }), controller);
72
+ }
73
+ /**
74
+ * Get a controller's prefixes: the ones of the class, or else of its nearest parent class declaring them (they are not
75
+ * merged across the hierarchy).
76
+ * @param controller The controller class.
77
+ * @returns The prefixes, `undefined` when neither the class nor its parents declare any.
78
+ * @example
79
+ * ```typescript
80
+ * import {Controller} from 'lakutata/com/entrypoint'
81
+ * import {Prefix} from 'lakutata/decorator/ctrl'
82
+ * import {getPrefix} from '@lakutata/entrypoint/channel'
83
+ *
84
+ * @Prefix({route: '/users'})
85
+ * class UserController extends Controller {
86
+ * }
87
+ *
88
+ * class AdminController extends UserController {
89
+ * }
90
+ *
91
+ * console.log(getPrefix(AdminController)?.route) //'/users'
92
+ * ```
93
+ */
94
+ export function getPrefix(controller) {
95
+ for (let current = controller; current && current !== Function.prototype; current = Object.getPrototypeOf(current)) {
96
+ const prefix = Reflect.getOwnMetadata(CONTROLLER_PREFIX, current);
97
+ if (prefix)
98
+ return prefix;
99
+ }
100
+ return undefined;
101
+ }
102
+ /**
103
+ * Join a route prefix and a route
104
+ * @param prefix
105
+ * @param route
106
+ */
107
+ export function prefixRoute(prefix, route) {
108
+ const segments = [prefix, route].map((part) => part.replace(/^\/+|\/+$/g, '')).filter(Boolean);
109
+ return `/${segments.join('/')}`;
110
+ }
111
+ /**
112
+ * Join a command prefix and a command
113
+ * @param prefix
114
+ * @param command
115
+ */
116
+ export function prefixCommand(prefix, command) {
117
+ return command ? `${prefix}:${command}` : prefix;
118
+ }
119
+ /**
120
+ * Merge a pattern prefix into a pattern, a key cannot have different values
121
+ * @param prefix
122
+ * @param pattern
123
+ * @param path
124
+ */
125
+ export function prefixPattern(prefix, pattern, path = '') {
126
+ const merged = { ...pattern };
127
+ for (const [key, value] of Object.entries(prefix)) {
128
+ if (!(key in merged)) {
129
+ merged[key] = value;
130
+ }
131
+ else if (value !== null && typeof value === 'object' && merged[key] !== null && typeof merged[key] === 'object') {
132
+ merged[key] = prefixPattern(value, merged[key], `${path}${key}.`);
133
+ }
134
+ else if (merged[key] !== value) {
135
+ throw new InvalidPrefixException('The pattern prefix sets "{key}" to {prefix}, the pattern sets it to {pattern}', {
136
+ key: `${path}${key}`,
137
+ prefix: JSON.stringify(value),
138
+ pattern: JSON.stringify(merged[key])
139
+ });
140
+ }
141
+ }
142
+ return merged;
143
+ }
@@ -0,0 +1,147 @@
1
+ import { ActionResult } from './ActionResult.js';
2
+ /**
3
+ * A result with a status and headers: the HTTP adapters set them on the response and send the data with their
4
+ * responder; the CLI adapter outputs the data. Build it with `Result.status()`.
5
+ * @example
6
+ * ```typescript
7
+ * import {Controller, Result, type StatusResult} from 'lakutata/com/entrypoint'
8
+ * import {POST} from 'lakutata/decorator/ctrl'
9
+ *
10
+ * class OrderController extends Controller {
11
+ * //201 Created, with the location of the order
12
+ * @POST('/orders')
13
+ * public async create(): Promise<StatusResult> {
14
+ * return Result.status(201, {id: 42}, {Location: '/orders/42'})
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export class StatusResult extends ActionResult {
20
+ /**
21
+ * Create a result with a status and headers.
22
+ * @param status The HTTP status.
23
+ * @param payload The data sent.
24
+ * @param headers The response headers.
25
+ */
26
+ constructor(status, payload, headers = {}) {
27
+ super();
28
+ this.status = status;
29
+ this.payload = payload;
30
+ this.headers = headers;
31
+ }
32
+ /**
33
+ * The data sent with the status.
34
+ */
35
+ get data() {
36
+ return this.payload;
37
+ }
38
+ }
39
+ /**
40
+ * A file: a path, a buffer or a stream. The HTTP adapters send it with its options; the CLI adapter writes its
41
+ * content to stdout. Build it with `Result.file()`.
42
+ * @example
43
+ * ```typescript
44
+ * import {Readable} from 'node:stream'
45
+ * import {Controller, Result, type FileResult} from 'lakutata/com/entrypoint'
46
+ * import {GET} from 'lakutata/decorator/ctrl'
47
+ *
48
+ * class ReportController extends Controller {
49
+ * //A file on disk, downloaded as report.pdf
50
+ * @GET('/report')
51
+ * public async report(): Promise<FileResult> {
52
+ * return Result.file('./reports/latest.pdf', {filename: 'report.pdf', etag: 'v1'})
53
+ * }
54
+ *
55
+ * //A stream, with its content type
56
+ * @GET('/export')
57
+ * public async export(): Promise<FileResult> {
58
+ * return Result.file(Readable.from(['id,name\n', '1,Ada\n']), {contentType: 'text/csv'})
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export class FileResult extends ActionResult {
64
+ /**
65
+ * Create a file result.
66
+ * @param source The file's path (resolved from the working directory), its content, or a stream of its content.
67
+ * @param options How the file is sent.
68
+ */
69
+ constructor(source, options = {}) {
70
+ super();
71
+ this.source = source;
72
+ this.options = options;
73
+ }
74
+ /**
75
+ * The file's source.
76
+ */
77
+ get data() {
78
+ return this.source;
79
+ }
80
+ }
81
+ /**
82
+ * A stream of events: Server-Sent Events for the HTTP adapters, each event's data written as a line by the CLI
83
+ * adapter. Build it with `Result.events()`.
84
+ *
85
+ * The producer runs after the action returned, once the request's container is destroyed: it must only use objects
86
+ * living longer than the request (the components), not the controller's request-scoped dependencies.
87
+ * @example
88
+ * ```typescript
89
+ * import {Controller, Result, type EventsResult} from 'lakutata/com/entrypoint'
90
+ * import {GET} from 'lakutata/decorator/ctrl'
91
+ *
92
+ * class ClockController extends Controller {
93
+ * //The time every second until the client leaves
94
+ * @GET('/clock')
95
+ * public async clock(): Promise<EventsResult> {
96
+ * return Result.events(async (send, signal): Promise<void> => {
97
+ * while (!signal.aborted) {
98
+ * send({now: new Date().toISOString()}, 'tick')
99
+ * await new Promise((resolve): unknown => setTimeout(resolve, 1000))
100
+ * }
101
+ * })
102
+ * }
103
+ * }
104
+ * ```
105
+ */
106
+ export class EventsResult extends ActionResult {
107
+ /**
108
+ * Create an event stream result.
109
+ * @param producer Produces the events.
110
+ */
111
+ constructor(producer) {
112
+ super();
113
+ this.producer = producer;
114
+ }
115
+ /**
116
+ * Always `undefined`: an event stream has no data of its own.
117
+ */
118
+ get data() {
119
+ return undefined;
120
+ }
121
+ }
122
+ /**
123
+ * Build the results an action returns to describe its output beyond its data.
124
+ */
125
+ export const Result = {
126
+ /**
127
+ * Build a result with a status and headers.
128
+ * @param status The HTTP status.
129
+ * @param data The data sent.
130
+ * @param headers The response headers.
131
+ * @returns The {@link StatusResult}.
132
+ */
133
+ status: (status, data, headers) => new StatusResult(status, data, headers),
134
+ /**
135
+ * Build a file result.
136
+ * @param source The file's path (resolved from the working directory), its content, or a stream of its content.
137
+ * @param options How the file is sent.
138
+ * @returns The {@link FileResult}.
139
+ */
140
+ file: (source, options) => new FileResult(source, options),
141
+ /**
142
+ * Build an event stream result (Server-Sent Events for HTTP).
143
+ * @param producer Produces the events, after the action returned.
144
+ * @returns The {@link EventsResult}.
145
+ */
146
+ events: (producer) => new EventsResult(producer)
147
+ };
@@ -0,0 +1,113 @@
1
+ import { ServiceInvokeException } from '../exceptions/ServiceInvokeException.js';
2
+ import { ActionResult } from './ActionResult.js';
3
+ import { StatusResult } from './Result.js';
4
+ /**
5
+ * Encode the results and failures of service invocations as {@link ServiceResponse}s, and decode them on the
6
+ * caller's side. Used by the service adapters and the service clients; all its methods are static.
7
+ * @example
8
+ * ```typescript
9
+ * import {ServiceResponseCodec, type ServiceResponse} from '@lakutata/entrypoint/channel'
10
+ *
11
+ * //On the service side
12
+ * const ok: ServiceResponse = ServiceResponseCodec.encode({id: 1}, false)
13
+ * const failed: ServiceResponse = ServiceResponseCodec.encodeError(new Error('Not found'))
14
+ *
15
+ * //On the caller side
16
+ * console.log(ServiceResponseCodec.decode(ok)) //{id: 1}
17
+ * try {
18
+ * ServiceResponseCodec.decode(failed, 'order.service')
19
+ * } catch (error) {
20
+ * console.log((error as Error).message) //Not found (a ServiceInvokeException whose service is order.service)
21
+ * }
22
+ * ```
23
+ */
24
+ export class ServiceResponseCodec {
25
+ /**
26
+ * Copy an error into a serializable object: its own properties (message, stack, errno, errMsg, statusCode…). The
27
+ * values are copied as they are, not deeply.
28
+ * @param error The error; a value which is not an object gives `{message: String(error)}`.
29
+ * @returns The copy.
30
+ */
31
+ static errorObject(error) {
32
+ if (!error || typeof error !== 'object')
33
+ return { message: String(error) };
34
+ const errorObject = {};
35
+ Object.getOwnPropertyNames(error).forEach((property) => errorObject[property] = error[property]);
36
+ return errorObject;
37
+ }
38
+ /**
39
+ * Encode the failure of a service invocation.
40
+ * @param error The error, copied with {@link ServiceResponseCodec.errorObject}.
41
+ * @returns A failed response.
42
+ */
43
+ static encodeError(error) {
44
+ return this.encode(this.errorObject(error), true);
45
+ }
46
+ /**
47
+ * The payload of an action's result for the service transports: the data of a `StatusResult` (its status and
48
+ * headers are HTTP's), the result itself otherwise.
49
+ * @param result The value the action returned.
50
+ * @returns The payload to send.
51
+ * @throws {TypeError} When it is a `FileResult` or an `EventsResult`, which only the HTTP adapters can send.
52
+ */
53
+ static payload(result) {
54
+ if (result instanceof StatusResult)
55
+ return result.data;
56
+ if (result instanceof ActionResult)
57
+ throw new TypeError(`The service transports cannot send a ${result.constructor.name}: only the HTTP adapters send files and event streams`);
58
+ return result;
59
+ }
60
+ /**
61
+ * Encode a service response.
62
+ * @param data The result (a `StatusResult` sent as its data, see {@link ServiceResponseCodec.payload}), or the
63
+ * error when `isError` is `true` (stored as it is: use {@link ServiceResponseCodec.encodeError} to make an error
64
+ * serializable).
65
+ * @param isError Whether `data` is an error.
66
+ * @returns The response.
67
+ * @throws {TypeError} When the result is a `FileResult` or an `EventsResult`.
68
+ */
69
+ static encode(data, isError) {
70
+ if (!isError)
71
+ data = this.payload(data);
72
+ return isError ? {
73
+ success: false,
74
+ error: data,
75
+ payload: null
76
+ } : {
77
+ success: true,
78
+ error: null,
79
+ payload: data
80
+ };
81
+ }
82
+ /**
83
+ * Decode a service response: return its payload, or throw its error.
84
+ * @param response The response.
85
+ * @param serviceId The invoked service's id, set to the exception's `service`.
86
+ * @returns The payload of a successful response.
87
+ * @throws {ServiceInvokeException} When the response is a failure: its message is the remote error's message
88
+ * (`Unknown Error` without one), the remote error's enumerable properties (errno, statusCode…) are copied onto it,
89
+ * the read-only ones skipped.
90
+ */
91
+ static decode(response, serviceId) {
92
+ if (!response.success) {
93
+ const remoteError = response.error;
94
+ const serviceInvokeException = new ServiceInvokeException(remoteError?.message || 'Unknown Error');
95
+ //The properties of the remote error are copied one by one, the read-only ones (such as the name of a NatsError) are skipped
96
+ if (remoteError && typeof remoteError === 'object') {
97
+ for (const key of Object.keys(remoteError)) {
98
+ try {
99
+ serviceInvokeException[key] = remoteError[key];
100
+ }
101
+ catch {
102
+ //A read-only property
103
+ }
104
+ }
105
+ }
106
+ //The service invoked, whatever the remote error holds
107
+ if (serviceId)
108
+ serviceInvokeException.service = serviceId;
109
+ throw serviceInvokeException;
110
+ }
111
+ return response.payload;
112
+ }
113
+ }
@@ -0,0 +1,55 @@
1
+ import { sortArray } from '@lakutata/utils';
2
+ function patternToArrayPair(pattern) {
3
+ switch (typeof pattern) {
4
+ case 'string':
5
+ return pattern;
6
+ case 'boolean':
7
+ return pattern ? 'true' : 'false';
8
+ case 'number':
9
+ return pattern.toString();
10
+ case 'bigint':
11
+ return undefined;
12
+ case 'symbol':
13
+ return undefined;
14
+ case 'function':
15
+ return undefined;
16
+ case 'undefined':
17
+ return undefined;
18
+ case 'object': {
19
+ if (Array.isArray(pattern)) {
20
+ const arrayData = [];
21
+ sortArray(pattern, { order: 'asc' }).forEach((item) => {
22
+ const newItem = patternToArrayPair(item);
23
+ if (newItem === undefined)
24
+ return;
25
+ arrayData.push(newItem);
26
+ });
27
+ return arrayData;
28
+ }
29
+ else {
30
+ const keys = sortArray(Object.keys(pattern), { order: 'asc' });
31
+ const data = [];
32
+ keys.forEach((key) => {
33
+ const item = patternToArrayPair(pattern[key]);
34
+ if (item === undefined)
35
+ return;
36
+ data.push([key, item]);
37
+ });
38
+ return data;
39
+ }
40
+ }
41
+ default:
42
+ return undefined;
43
+ }
44
+ }
45
+ /**
46
+ * Stringify pattern object
47
+ * @param pattern
48
+ * @constructor
49
+ */
50
+ export function stringifyPattern(pattern) {
51
+ let pairArr = patternToArrayPair(pattern);
52
+ while (pairArr.find((value) => Array.isArray(value)))
53
+ pairArr = pairArr.flat();
54
+ return pairArr.join(':');
55
+ }
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Derived from index.js of unset-value 2.0.1, has-value 2.0.2, get-value 3.0.1, has-values 2.0.1, kind-of 6.0.3 and
3
+ * isobject 4.1.1 (MIT, see THIRD_PARTY_NOTICES.md): the removal of the properties of the patterns from the inputs of
4
+ * the actions, as 2.x
5
+ */
6
+ function isObjectValue(val) {
7
+ return val != null && typeof val === 'object' && !Array.isArray(val);
8
+ }
9
+ /**
10
+ * The type of a value (kind-of)
11
+ * @param val
12
+ */
13
+ function kindOf(val) {
14
+ if (val === undefined)
15
+ return 'undefined';
16
+ if (val === null)
17
+ return 'null';
18
+ const type = typeof val;
19
+ if (type === 'boolean' || type === 'string' || type === 'number' || type === 'symbol')
20
+ return type;
21
+ if (type === 'function')
22
+ return ctorName(val) === 'GeneratorFunction' ? 'generatorfunction' : 'function';
23
+ if (Array.isArray(val))
24
+ return 'array';
25
+ if (val.constructor && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val))
26
+ return 'buffer';
27
+ if (isArguments(val))
28
+ return 'arguments';
29
+ if (val instanceof Date || (typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function'))
30
+ return 'date';
31
+ if (val instanceof Error || (typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'))
32
+ return 'error';
33
+ if (val instanceof RegExp || (typeof val.flags === 'string' && typeof val.ignoreCase === 'boolean' && typeof val.multiline === 'boolean' && typeof val.global === 'boolean'))
34
+ return 'regexp';
35
+ switch (ctorName(val)) {
36
+ case 'Symbol':
37
+ return 'symbol';
38
+ case 'Promise':
39
+ return 'promise';
40
+ case 'WeakMap':
41
+ return 'weakmap';
42
+ case 'WeakSet':
43
+ return 'weakset';
44
+ case 'Map':
45
+ return 'map';
46
+ case 'Set':
47
+ return 'set';
48
+ case 'Int8Array':
49
+ case 'Uint8Array':
50
+ case 'Uint8ClampedArray':
51
+ case 'Int16Array':
52
+ case 'Uint16Array':
53
+ case 'Int32Array':
54
+ case 'Uint32Array':
55
+ case 'Float32Array':
56
+ case 'Float64Array':
57
+ return ctorName(val).toLowerCase();
58
+ }
59
+ if (typeof val.throw === 'function' && typeof val.return === 'function' && typeof val.next === 'function')
60
+ return 'generator';
61
+ const tag = Object.prototype.toString.call(val);
62
+ switch (tag) {
63
+ case '[object Object]':
64
+ return 'object';
65
+ case '[object Map Iterator]':
66
+ return 'mapiterator';
67
+ case '[object Set Iterator]':
68
+ return 'setiterator';
69
+ case '[object String Iterator]':
70
+ return 'stringiterator';
71
+ case '[object Array Iterator]':
72
+ return 'arrayiterator';
73
+ }
74
+ return tag.slice(8, -1).toLowerCase().replace(/\s/g, '');
75
+ }
76
+ function ctorName(val) {
77
+ return typeof val.constructor === 'function' ? val.constructor.name : null;
78
+ }
79
+ function isArguments(val) {
80
+ try {
81
+ if (typeof val.length === 'number' && typeof val.callee === 'function')
82
+ return true;
83
+ }
84
+ catch (error) {
85
+ if (error.message.indexOf('callee') !== -1)
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ /**
91
+ * Whether a value has a value (has-values): not undefined, an empty string, array, object, map or set, an empty
92
+ * regular expression, buffer or error message
93
+ * @param val
94
+ */
95
+ function hasValues(val) {
96
+ switch (kindOf(val)) {
97
+ case 'boolean':
98
+ case 'date':
99
+ case 'function':
100
+ case 'null':
101
+ case 'number':
102
+ return true;
103
+ case 'undefined':
104
+ return false;
105
+ case 'regexp':
106
+ return val.source !== '(?:)' && val.source !== '';
107
+ case 'buffer':
108
+ return val.toString() !== '';
109
+ case 'error':
110
+ return val.message !== '';
111
+ case 'string':
112
+ case 'arguments':
113
+ return val.length !== 0;
114
+ case 'file':
115
+ case 'map':
116
+ case 'set':
117
+ return val.size !== 0;
118
+ case 'array':
119
+ case 'object':
120
+ for (const key of Object.keys(val))
121
+ if (hasValues(val[key]))
122
+ return true;
123
+ return false;
124
+ default:
125
+ return true;
126
+ }
127
+ }
128
+ function isValidObject(val) {
129
+ return isObjectValue(val) || Array.isArray(val) || typeof val === 'function';
130
+ }
131
+ /**
132
+ * The value of a path (get-value): a key holding the whole path first, the keys escaping their dots ("a\.b"), the keys
133
+ * containing dots
134
+ * @param target
135
+ * @param path
136
+ */
137
+ function getValue(target, path) {
138
+ if (!isValidObject(target))
139
+ return target;
140
+ const isArray = Array.isArray(path);
141
+ if (typeof path !== 'string' && !isArray)
142
+ return target;
143
+ if (typeof path === 'string' && path in target)
144
+ return target[path];
145
+ const segs = isArray ? path : path.split('.');
146
+ const len = segs.length;
147
+ let idx = 0;
148
+ do {
149
+ let prop = segs[idx];
150
+ if (typeof prop === 'number')
151
+ prop = String(prop);
152
+ while (prop && prop.slice(-1) === '\\')
153
+ prop = prop.slice(0, -1) + '.' + (segs[++idx] || '');
154
+ if (prop in target) {
155
+ target = target[prop];
156
+ }
157
+ else {
158
+ let hasProp = false;
159
+ let n = idx + 1;
160
+ while (n < len) {
161
+ prop = prop + '.' + segs[n++];
162
+ if ((hasProp = prop in target)) {
163
+ target = target[prop];
164
+ idx = n - 1;
165
+ break;
166
+ }
167
+ }
168
+ if (!hasProp)
169
+ return undefined;
170
+ }
171
+ } while (++idx < len && isValidObject(target));
172
+ return idx === len ? target : undefined;
173
+ }
174
+ /**
175
+ * Whether a path has a value (has-value)
176
+ * @param obj
177
+ * @param path
178
+ */
179
+ function hasValue(obj, path) {
180
+ const isObject = obj != null && (typeof obj === 'object' || typeof obj === 'function');
181
+ if (isObject && (typeof path === 'string' || Array.isArray(path)))
182
+ return hasValues(getValue(obj, path));
183
+ return false;
184
+ }
185
+ /**
186
+ * Remove a property of an object by its path (unset-value): a key holding the whole path first, the keys escaping
187
+ * their dots ("a\.b"); a property without value (has-value) is kept
188
+ * @param obj
189
+ * @param prop
190
+ */
191
+ export function unsetValue(obj, prop) {
192
+ if (!isObjectValue(obj))
193
+ throw new TypeError('expected an object.');
194
+ const isArray = Array.isArray(prop);
195
+ if (!isArray && Object.prototype.hasOwnProperty.call(obj, prop)) {
196
+ delete obj[prop];
197
+ return true;
198
+ }
199
+ if (hasValue(obj, prop)) {
200
+ const segs = isArray ? prop.slice() : prop.split('.');
201
+ let last = segs.pop();
202
+ while (segs.length && segs[segs.length - 1].slice(-1) === '\\')
203
+ last = segs.pop().slice(0, -1) + '.' + last;
204
+ while (segs.length) {
205
+ const key = segs.shift();
206
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype')
207
+ throw new Error(`Cannot set unsafe key: "${key}"`);
208
+ obj = obj[key];
209
+ }
210
+ return delete obj[last];
211
+ }
212
+ return true;
213
+ }