@valkyrjaio/valkyrja 26.0.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 (498) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +136 -0
  3. package/package.json +63 -0
  4. package/src/Valkyrja/Application/Constant/ApplicationInfo.ts +26 -0
  5. package/src/Valkyrja/Application/Constant/ApplicationServiceId.ts +16 -0
  6. package/src/Valkyrja/Application/Data/CliConfig.ts +51 -0
  7. package/src/Valkyrja/Application/Data/Config.ts +31 -0
  8. package/src/Valkyrja/Application/Data/Contract/CliConfigContract.ts +27 -0
  9. package/src/Valkyrja/Application/Data/Contract/ConfigContract.ts +31 -0
  10. package/src/Valkyrja/Application/Data/Contract/HttpConfigContract.ts +26 -0
  11. package/src/Valkyrja/Application/Data/HttpConfig.ts +41 -0
  12. package/src/Valkyrja/Application/Directory/Directory.ts +80 -0
  13. package/src/Valkyrja/Application/Entry/Abstract/App.ts +117 -0
  14. package/src/Valkyrja/Application/Entry/Abstract/WorkerHttp.ts +83 -0
  15. package/src/Valkyrja/Application/Entry/Cli.ts +34 -0
  16. package/src/Valkyrja/Application/Entry/Http.ts +41 -0
  17. package/src/Valkyrja/Application/Kernel/ChildApplication.ts +63 -0
  18. package/src/Valkyrja/Application/Kernel/Contract/ApplicationContract.ts +34 -0
  19. package/src/Valkyrja/Application/Kernel/Valkyrja.ts +141 -0
  20. package/src/Valkyrja/Application/Provider/ApplicationComponentProvider.ts +39 -0
  21. package/src/Valkyrja/Application/Provider/CliApplicationComponentProvider.ts +30 -0
  22. package/src/Valkyrja/Application/Provider/CliWithHttpApplicationComponentProvider.ts +32 -0
  23. package/src/Valkyrja/Application/Provider/Contract/ComponentProviderContract.ts +28 -0
  24. package/src/Valkyrja/Application/Provider/Contract/PublishableComponentProviderContract.ts +20 -0
  25. package/src/Valkyrja/Application/Provider/HttpApplicationComponentProvider.ts +20 -0
  26. package/src/Valkyrja/Application/Throwable/Contract/ApplicationThrowable.ts +12 -0
  27. package/src/Valkyrja/Application/Throwable/Exception/Abstract/ApplicationInvalidArgumentException.ts +16 -0
  28. package/src/Valkyrja/Application/Throwable/Exception/Abstract/ApplicationRuntimeException.ts +14 -0
  29. package/src/Valkyrja/Cli/Interaction/Argument/Argument.ts +25 -0
  30. package/src/Valkyrja/Cli/Interaction/Argument/Contract/ArgumentContract.ts +19 -0
  31. package/src/Valkyrja/Cli/Interaction/Argument/Factory/ArgumentFactory.ts +16 -0
  32. package/src/Valkyrja/Cli/Interaction/Constant/CliInteractionServiceId.ts +16 -0
  33. package/src/Valkyrja/Cli/Interaction/Data/CliInteractionConfig.ts +18 -0
  34. package/src/Valkyrja/Cli/Interaction/Data/Contract/CliInteractionConfigContract.ts +20 -0
  35. package/src/Valkyrja/Cli/Interaction/Enum/BackgroundColor.ts +33 -0
  36. package/src/Valkyrja/Cli/Interaction/Enum/ExitCode.ts +30 -0
  37. package/src/Valkyrja/Cli/Interaction/Enum/OptionType.ts +13 -0
  38. package/src/Valkyrja/Cli/Interaction/Enum/Style.ts +33 -0
  39. package/src/Valkyrja/Cli/Interaction/Enum/TextColor.ts +33 -0
  40. package/src/Valkyrja/Cli/Interaction/Format/BackgroundColorFormat.ts +17 -0
  41. package/src/Valkyrja/Cli/Interaction/Format/Contract/FormatContract.ts +21 -0
  42. package/src/Valkyrja/Cli/Interaction/Format/Format.ts +38 -0
  43. package/src/Valkyrja/Cli/Interaction/Format/StyleFormat.ts +17 -0
  44. package/src/Valkyrja/Cli/Interaction/Format/TextColorFormat.ts +17 -0
  45. package/src/Valkyrja/Cli/Interaction/Formatter/Contract/FormatterContract.ts +22 -0
  46. package/src/Valkyrja/Cli/Interaction/Formatter/ErrorFormatter.ts +20 -0
  47. package/src/Valkyrja/Cli/Interaction/Formatter/Formatter.ts +46 -0
  48. package/src/Valkyrja/Cli/Interaction/Formatter/HighlightedTextFormatter.ts +18 -0
  49. package/src/Valkyrja/Cli/Interaction/Formatter/QuestionFormatter.ts +18 -0
  50. package/src/Valkyrja/Cli/Interaction/Formatter/SuccessFormatter.ts +20 -0
  51. package/src/Valkyrja/Cli/Interaction/Formatter/WarningFormatter.ts +20 -0
  52. package/src/Valkyrja/Cli/Interaction/Input/Contract/InputContract.ts +36 -0
  53. package/src/Valkyrja/Cli/Interaction/Input/Factory/InputFactory.ts +47 -0
  54. package/src/Valkyrja/Cli/Interaction/Input/Input.ts +106 -0
  55. package/src/Valkyrja/Cli/Interaction/Message/Answer.ts +130 -0
  56. package/src/Valkyrja/Cli/Interaction/Message/Banner.ts +41 -0
  57. package/src/Valkyrja/Cli/Interaction/Message/Contract/AnswerContract.ts +32 -0
  58. package/src/Valkyrja/Cli/Interaction/Message/Contract/MessageContract.ts +26 -0
  59. package/src/Valkyrja/Cli/Interaction/Message/Contract/ProgressContract.ts +23 -0
  60. package/src/Valkyrja/Cli/Interaction/Message/Contract/QuestionContract.ts +26 -0
  61. package/src/Valkyrja/Cli/Interaction/Message/ErrorMessage.ts +17 -0
  62. package/src/Valkyrja/Cli/Interaction/Message/Header.ts +111 -0
  63. package/src/Valkyrja/Cli/Interaction/Message/Message.ts +64 -0
  64. package/src/Valkyrja/Cli/Interaction/Message/Messages.ts +28 -0
  65. package/src/Valkyrja/Cli/Interaction/Message/NewLine.ts +17 -0
  66. package/src/Valkyrja/Cli/Interaction/Message/Progress.ts +44 -0
  67. package/src/Valkyrja/Cli/Interaction/Message/Question.ts +91 -0
  68. package/src/Valkyrja/Cli/Interaction/Message/SuccessMessage.ts +17 -0
  69. package/src/Valkyrja/Cli/Interaction/Message/WarningMessage.ts +17 -0
  70. package/src/Valkyrja/Cli/Interaction/Option/Contract/OptionContract.ts +27 -0
  71. package/src/Valkyrja/Cli/Interaction/Option/Factory/OptionFactory.ts +60 -0
  72. package/src/Valkyrja/Cli/Interaction/Option/Option.ts +61 -0
  73. package/src/Valkyrja/Cli/Interaction/Output/Contract/EmptyOutputContract.ts +18 -0
  74. package/src/Valkyrja/Cli/Interaction/Output/Contract/FileOutputContract.ts +21 -0
  75. package/src/Valkyrja/Cli/Interaction/Output/Contract/OutputContract.ts +41 -0
  76. package/src/Valkyrja/Cli/Interaction/Output/Contract/PlainOutputContract.ts +18 -0
  77. package/src/Valkyrja/Cli/Interaction/Output/Contract/StreamOutputContract.ts +21 -0
  78. package/src/Valkyrja/Cli/Interaction/Output/EmptyOutput.ts +18 -0
  79. package/src/Valkyrja/Cli/Interaction/Output/Factory/Contract/OutputFactoryContract.ts +38 -0
  80. package/src/Valkyrja/Cli/Interaction/Output/Factory/OutputFactory.ts +88 -0
  81. package/src/Valkyrja/Cli/Interaction/Output/FileOutput.ts +41 -0
  82. package/src/Valkyrja/Cli/Interaction/Output/Output.ts +163 -0
  83. package/src/Valkyrja/Cli/Interaction/Output/PlainOutput.ts +18 -0
  84. package/src/Valkyrja/Cli/Interaction/Output/StreamOutput.ts +41 -0
  85. package/src/Valkyrja/Cli/Interaction/Provider/CliInteractionComponentProvider.ts +39 -0
  86. package/src/Valkyrja/Cli/Interaction/Provider/CliInteractionServiceProvider.ts +46 -0
  87. package/src/Valkyrja/Cli/Interaction/Throwable/Contract/CliInteractionThrowable.ts +12 -0
  88. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/Abstract/CliInteractionInvalidArgumentException.ts +16 -0
  89. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/Abstract/CliInteractionRuntimeException.ts +14 -0
  90. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionExpectedQuestionOutputException.ts +12 -0
  91. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionInvalidEmptyValueException.ts +12 -0
  92. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionInvalidNonEmptyValueException.ts +12 -0
  93. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionInvalidOptionNameException.ts +12 -0
  94. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionNoFormatterException.ts +12 -0
  95. package/src/Valkyrja/Cli/Interaction/Throwable/Exception/CliInteractionNoValidationCallableException.ts +12 -0
  96. package/src/Valkyrja/Cli/Interaction/Writer/Contract/WriterContract.ts +22 -0
  97. package/src/Valkyrja/Cli/Interaction/Writer/QuestionWriter.ts +86 -0
  98. package/src/Valkyrja/Cli/Middleware/Constant/CliMiddlewareServiceId.ts +22 -0
  99. package/src/Valkyrja/Cli/Middleware/Contract/ExitedMiddlewareContract.ts +22 -0
  100. package/src/Valkyrja/Cli/Middleware/Contract/InputReceivedMiddlewareContract.ts +22 -0
  101. package/src/Valkyrja/Cli/Middleware/Contract/RouteDispatchedMiddlewareContract.ts +28 -0
  102. package/src/Valkyrja/Cli/Middleware/Contract/RouteMatchedMiddlewareContract.ts +27 -0
  103. package/src/Valkyrja/Cli/Middleware/Contract/RouteNotMatchedMiddlewareContract.ts +26 -0
  104. package/src/Valkyrja/Cli/Middleware/Contract/ThrowableCaughtMiddlewareContract.ts +27 -0
  105. package/src/Valkyrja/Cli/Middleware/Handler/Abstract/Handler.ts +48 -0
  106. package/src/Valkyrja/Cli/Middleware/Handler/Contract/ExitedHandlerContract.ts +22 -0
  107. package/src/Valkyrja/Cli/Middleware/Handler/Contract/HandlerContract.ts +33 -0
  108. package/src/Valkyrja/Cli/Middleware/Handler/Contract/InputReceivedHandlerContract.ts +22 -0
  109. package/src/Valkyrja/Cli/Middleware/Handler/Contract/RouteDispatchedHandlerContract.ts +23 -0
  110. package/src/Valkyrja/Cli/Middleware/Handler/Contract/RouteMatchedHandlerContract.ts +23 -0
  111. package/src/Valkyrja/Cli/Middleware/Handler/Contract/RouteNotMatchedHandlerContract.ts +22 -0
  112. package/src/Valkyrja/Cli/Middleware/Handler/Contract/ThrowableCaughtHandlerContract.ts +22 -0
  113. package/src/Valkyrja/Cli/Middleware/Handler/ExitedHandler.ts +24 -0
  114. package/src/Valkyrja/Cli/Middleware/Handler/InputReceivedHandler.ts +24 -0
  115. package/src/Valkyrja/Cli/Middleware/Handler/RouteDispatchedHandler.ts +25 -0
  116. package/src/Valkyrja/Cli/Middleware/Handler/RouteMatchedHandler.ts +25 -0
  117. package/src/Valkyrja/Cli/Middleware/Handler/RouteNotMatchedHandler.ts +24 -0
  118. package/src/Valkyrja/Cli/Middleware/Handler/ThrowableCaughtHandler.ts +29 -0
  119. package/src/Valkyrja/Cli/Middleware/Provider/CliMiddlewareComponentProvider.ts +39 -0
  120. package/src/Valkyrja/Cli/Middleware/Provider/CliMiddlewareServiceProvider.ts +119 -0
  121. package/src/Valkyrja/Cli/Middleware/Throwable/Contract/CliMiddlewareThrowable.ts +12 -0
  122. package/src/Valkyrja/Cli/Middleware/Throwable/Exception/Abstract/CliMiddlewareInvalidArgumentException.ts +16 -0
  123. package/src/Valkyrja/Cli/Middleware/Throwable/Exception/Abstract/CliMiddlewareRuntimeException.ts +14 -0
  124. package/src/Valkyrja/Cli/Routing/Collection/Contract/RouteCollectionContract.ts +26 -0
  125. package/src/Valkyrja/Cli/Routing/Collection/RouteCollection.ts +60 -0
  126. package/src/Valkyrja/Cli/Routing/Collector/Contract/RouteCollectorContract.ts +20 -0
  127. package/src/Valkyrja/Cli/Routing/Constant/CliRoutingServiceId.ts +16 -0
  128. package/src/Valkyrja/Cli/Routing/Constant/OptionName.ts +17 -0
  129. package/src/Valkyrja/Cli/Routing/Constant/OptionShortName.ts +17 -0
  130. package/src/Valkyrja/Cli/Routing/Controller/Controller.ts +18 -0
  131. package/src/Valkyrja/Cli/Routing/Data/Abstract/Parameter.ts +91 -0
  132. package/src/Valkyrja/Cli/Routing/Data/ArgumentParameter.ts +99 -0
  133. package/src/Valkyrja/Cli/Routing/Data/CliRoutingData.ts +14 -0
  134. package/src/Valkyrja/Cli/Routing/Data/Contract/ArgumentParameterContract.ts +29 -0
  135. package/src/Valkyrja/Cli/Routing/Data/Contract/CliRoutingConfigContract.ts +18 -0
  136. package/src/Valkyrja/Cli/Routing/Data/Contract/OptionParameterContract.ts +41 -0
  137. package/src/Valkyrja/Cli/Routing/Data/Contract/ParameterContract.ts +32 -0
  138. package/src/Valkyrja/Cli/Routing/Data/Contract/RouteContract.ts +57 -0
  139. package/src/Valkyrja/Cli/Routing/Data/Option/HelpOptionParameter.ts +30 -0
  140. package/src/Valkyrja/Cli/Routing/Data/Option/NoInteractionOptionParameter.ts +30 -0
  141. package/src/Valkyrja/Cli/Routing/Data/Option/QuietOptionParameter.ts +30 -0
  142. package/src/Valkyrja/Cli/Routing/Data/Option/SilentOptionParameter.ts +30 -0
  143. package/src/Valkyrja/Cli/Routing/Data/Option/VersionOptionParameter.ts +30 -0
  144. package/src/Valkyrja/Cli/Routing/Data/OptionParameter.ts +188 -0
  145. package/src/Valkyrja/Cli/Routing/Data/Route.ts +211 -0
  146. package/src/Valkyrja/Cli/Routing/Dispatcher/Contract/RouterContract.ts +23 -0
  147. package/src/Valkyrja/Cli/Routing/Dispatcher/Router.ts +155 -0
  148. package/src/Valkyrja/Cli/Routing/Enum/ArgumentMode.ts +13 -0
  149. package/src/Valkyrja/Cli/Routing/Enum/ArgumentValueMode.ts +13 -0
  150. package/src/Valkyrja/Cli/Routing/Enum/OptionMode.ts +13 -0
  151. package/src/Valkyrja/Cli/Routing/Enum/OptionValueMode.ts +14 -0
  152. package/src/Valkyrja/Cli/Routing/Provider/CliRoutingCliRouteProvider.ts +111 -0
  153. package/src/Valkyrja/Cli/Routing/Provider/CliRoutingComponentProvider.ts +40 -0
  154. package/src/Valkyrja/Cli/Routing/Provider/CliRoutingServiceProvider.ts +88 -0
  155. package/src/Valkyrja/Cli/Routing/Provider/Contract/CliRouteProviderContract.ts +20 -0
  156. package/src/Valkyrja/Cli/Routing/Throwable/Contract/CliRoutingThrowable.ts +12 -0
  157. package/src/Valkyrja/Cli/Routing/Throwable/Exception/Abstract/CliRoutingInvalidArgumentException.ts +16 -0
  158. package/src/Valkyrja/Cli/Routing/Throwable/Exception/Abstract/CliRoutingRuntimeException.ts +14 -0
  159. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingArgumentValuesValidationException.ts +12 -0
  160. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingInvalidArgumentNameException.ts +12 -0
  161. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingInvalidHelpTextCallableException.ts +12 -0
  162. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingInvalidOptionNameException.ts +12 -0
  163. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingInvalidOptionWithValueException.ts +12 -0
  164. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingInvalidRouteNameException.ts +12 -0
  165. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingNoCastException.ts +12 -0
  166. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingNoHelpTextException.ts +12 -0
  167. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingNoOutputDispatchException.ts +12 -0
  168. package/src/Valkyrja/Cli/Routing/Throwable/Exception/CliRoutingOptionValuesValidationException.ts +12 -0
  169. package/src/Valkyrja/Cli/Server/Command/HelpCommand.ts +313 -0
  170. package/src/Valkyrja/Cli/Server/Command/ListBashCommand.ts +44 -0
  171. package/src/Valkyrja/Cli/Server/Command/ListCommand.ts +98 -0
  172. package/src/Valkyrja/Cli/Server/Command/VersionCommand.ts +34 -0
  173. package/src/Valkyrja/Cli/Server/Constant/CliServerServiceId.ts +28 -0
  174. package/src/Valkyrja/Cli/Server/Constant/CommandName.ts +16 -0
  175. package/src/Valkyrja/Cli/Server/Data/Contract/CliHelpCommandConfigContract.ts +20 -0
  176. package/src/Valkyrja/Cli/Server/Data/Contract/CliNoInteractionConfigContract.ts +19 -0
  177. package/src/Valkyrja/Cli/Server/Data/Contract/CliQuietInteractionConfigContract.ts +19 -0
  178. package/src/Valkyrja/Cli/Server/Data/Contract/CliSilentInteractionConfigContract.ts +19 -0
  179. package/src/Valkyrja/Cli/Server/Data/Contract/CliVersionCommandConfigContract.ts +20 -0
  180. package/src/Valkyrja/Cli/Server/Handler/Contract/InputHandlerContract.ts +17 -0
  181. package/src/Valkyrja/Cli/Server/Handler/InputHandler.ts +112 -0
  182. package/src/Valkyrja/Cli/Server/Middleware/InputReceived/CheckForHelpOptionsMiddleware.ts +30 -0
  183. package/src/Valkyrja/Cli/Server/Middleware/InputReceived/CheckForVersionOptionsMiddleware.ts +29 -0
  184. package/src/Valkyrja/Cli/Server/Middleware/InputReceived/CheckGlobalInteractionOptionsMiddleware.ts +52 -0
  185. package/src/Valkyrja/Cli/Server/Middleware/RouteNotMatched/CheckCommandForTypoMiddleware.ts +119 -0
  186. package/src/Valkyrja/Cli/Server/Middleware/ThrowableCaught/LogThrowableCaughtMiddleware.ts +32 -0
  187. package/src/Valkyrja/Cli/Server/Middleware/ThrowableCaught/OutputThrowableCaughtMiddleware.ts +57 -0
  188. package/src/Valkyrja/Cli/Server/Provider/CliServerComponentProvider.ts +39 -0
  189. package/src/Valkyrja/Cli/Server/Provider/CliServerServiceProvider.ts +269 -0
  190. package/src/Valkyrja/Cli/Server/Support/Exiter.ts +32 -0
  191. package/src/Valkyrja/Cli/Server/Throwable/Contract/CliServerThrowable.ts +12 -0
  192. package/src/Valkyrja/Cli/Server/Throwable/Exception/Abstract/CliServerInvalidArgumentException.ts +16 -0
  193. package/src/Valkyrja/Cli/Server/Throwable/Exception/Abstract/CliServerRuntimeException.ts +14 -0
  194. package/src/Valkyrja/Cli/Throwable/Contract/CliThrowable.ts +12 -0
  195. package/src/Valkyrja/Cli/Throwable/Exception/Abstract/CliInvalidArgumentException.ts +14 -0
  196. package/src/Valkyrja/Cli/Throwable/Exception/Abstract/CliRuntimeException.ts +14 -0
  197. package/src/Valkyrja/Container/Constant/ContainerServiceId.ts +13 -0
  198. package/src/Valkyrja/Container/Data/ContainerData.ts +31 -0
  199. package/src/Valkyrja/Container/Enum/InvalidReferenceMode.ts +13 -0
  200. package/src/Valkyrja/Container/Manager/ChildContainer.ts +69 -0
  201. package/src/Valkyrja/Container/Manager/Container.ts +244 -0
  202. package/src/Valkyrja/Container/Manager/Contract/ContainerContract.ts +31 -0
  203. package/src/Valkyrja/Container/Manager/Contract/ProvidersAwareContract.ts +17 -0
  204. package/src/Valkyrja/Container/Provider/ContainerComponentProvider.ts +39 -0
  205. package/src/Valkyrja/Container/Provider/ContainerServiceProvider.ts +33 -0
  206. package/src/Valkyrja/Container/Provider/Contract/ServiceProviderContract.ts +20 -0
  207. package/src/Valkyrja/Container/Throwable/Contract/ContainerThrowable.ts +12 -0
  208. package/src/Valkyrja/Container/Throwable/Exception/Abstract/ContainerInvalidArgumentException.ts +16 -0
  209. package/src/Valkyrja/Container/Throwable/Exception/Abstract/ContainerRuntimeException.ts +14 -0
  210. package/src/Valkyrja/Container/Throwable/Exception/ContainerInvalidPublishCallbackException.ts +12 -0
  211. package/src/Valkyrja/Container/Throwable/Exception/ContainerInvalidReferenceException.ts +17 -0
  212. package/src/Valkyrja/Event/Constant/EventServiceId.ts +12 -0
  213. package/src/Valkyrja/Event/Data/Contract/ListenerContract.ts +25 -0
  214. package/src/Valkyrja/Event/Data/EventData.ts +15 -0
  215. package/src/Valkyrja/Event/Provider/Contract/ListenerProviderContract.ts +20 -0
  216. package/src/Valkyrja/Http/Client/Manager/Contract/ClientContract.ts +15 -0
  217. package/src/Valkyrja/Http/Client/Manager/LogClient.ts +28 -0
  218. package/src/Valkyrja/Http/Client/Manager/NullClient.ts +20 -0
  219. package/src/Valkyrja/Http/Client/Throwable/Contract/HttpClientThrowable.ts +12 -0
  220. package/src/Valkyrja/Http/Client/Throwable/Exception/Abstract/HttpClientInvalidArgumentException.ts +16 -0
  221. package/src/Valkyrja/Http/Client/Throwable/Exception/Abstract/HttpClientRuntimeException.ts +14 -0
  222. package/src/Valkyrja/Http/Message/Constant/ContentTypeValue.ts +22 -0
  223. package/src/Valkyrja/Http/Message/Constant/HeaderName.ts +60 -0
  224. package/src/Valkyrja/Http/Message/Constant/HeaderValue.ts +12 -0
  225. package/src/Valkyrja/Http/Message/Constant/HttpMessageServiceId.ts +13 -0
  226. package/src/Valkyrja/Http/Message/Constant/Port.ts +19 -0
  227. package/src/Valkyrja/Http/Message/Contract/MessageContract.ts +21 -0
  228. package/src/Valkyrja/Http/Message/Enum/ProtocolVersion.ts +15 -0
  229. package/src/Valkyrja/Http/Message/Enum/RequestMethod.ts +35 -0
  230. package/src/Valkyrja/Http/Message/Enum/SameSite.ts +14 -0
  231. package/src/Valkyrja/Http/Message/Enum/StatusCode.ts +152 -0
  232. package/src/Valkyrja/Http/Message/Enum/StatusText.ts +73 -0
  233. package/src/Valkyrja/Http/Message/File/Collection/Contract/UploadedFileCollectionContract.ts +20 -0
  234. package/src/Valkyrja/Http/Message/File/Collection/UploadedFileCollection.ts +83 -0
  235. package/src/Valkyrja/Http/Message/File/Constant/UploadErrorExceptionMessage.ts +20 -0
  236. package/src/Valkyrja/Http/Message/File/Contract/UploadedFileContract.ts +22 -0
  237. package/src/Valkyrja/Http/Message/File/Enum/UploadError.ts +19 -0
  238. package/src/Valkyrja/Http/Message/File/Factory/UploadedFileFactory.ts +34 -0
  239. package/src/Valkyrja/Http/Message/File/Throwable/Contract/UploadedFileThrowable.ts +12 -0
  240. package/src/Valkyrja/Http/Message/File/Throwable/Exception/Abstract/UploadedFileInvalidArgumentException.ts +15 -0
  241. package/src/Valkyrja/Http/Message/File/Throwable/Exception/Abstract/UploadedFileRuntimeException.ts +15 -0
  242. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileAlreadyMovedException.ts +12 -0
  243. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidDirectoryException.ts +12 -0
  244. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidFilesArrayStructureException.ts +12 -0
  245. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidKeyException.ts +12 -0
  246. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidParamException.ts +12 -0
  247. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidTmpNameException.ts +12 -0
  248. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidUploadErrorException.ts +12 -0
  249. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidUploadedFileException.ts +12 -0
  250. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileInvalidValueException.ts +12 -0
  251. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileMoveFailureException.ts +12 -0
  252. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileUnableToWriteFileException.ts +12 -0
  253. package/src/Valkyrja/Http/Message/File/Throwable/Exception/UploadedFileUploadErrorException.ts +48 -0
  254. package/src/Valkyrja/Http/Message/File/UploadedFile.ts +156 -0
  255. package/src/Valkyrja/Http/Message/Header/Collection/Contract/HeaderCollectionContract.ts +23 -0
  256. package/src/Valkyrja/Http/Message/Header/Collection/HeaderCollection.ts +117 -0
  257. package/src/Valkyrja/Http/Message/Header/ContentType.ts +18 -0
  258. package/src/Valkyrja/Http/Message/Header/Contract/HeaderContract.ts +21 -0
  259. package/src/Valkyrja/Http/Message/Header/Factory/CookieFactory.ts +35 -0
  260. package/src/Valkyrja/Http/Message/Header/Factory/HeaderFactory.ts +79 -0
  261. package/src/Valkyrja/Http/Message/Header/Header.ts +104 -0
  262. package/src/Valkyrja/Http/Message/Header/Location.ts +18 -0
  263. package/src/Valkyrja/Http/Message/Header/Referer.ts +18 -0
  264. package/src/Valkyrja/Http/Message/Header/SetCookie.ts +18 -0
  265. package/src/Valkyrja/Http/Message/Header/Throwable/Contract/HttpHeaderThrowable.ts +12 -0
  266. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/Abstract/HttpHeaderInvalidArgumentException.ts +15 -0
  267. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/Abstract/HttpHeaderRuntimeException.ts +13 -0
  268. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderInvalidHeaderNameException.ts +12 -0
  269. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderInvalidHeaderParamException.ts +12 -0
  270. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderInvalidNameException.ts +12 -0
  271. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderInvalidValueException.ts +12 -0
  272. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderUnsupportedMethodException.ts +12 -0
  273. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderUnsupportedOffsetSetException.ts +12 -0
  274. package/src/Valkyrja/Http/Message/Header/Throwable/Exception/HttpHeaderUnsupportedOffsetUnsetException.ts +12 -0
  275. package/src/Valkyrja/Http/Message/Header/Value/Component/Component.ts +54 -0
  276. package/src/Valkyrja/Http/Message/Header/Value/Component/Contract/ComponentContract.ts +16 -0
  277. package/src/Valkyrja/Http/Message/Header/Value/Contract/CookieContract.ts +35 -0
  278. package/src/Valkyrja/Http/Message/Header/Value/Contract/ValueContract.ts +17 -0
  279. package/src/Valkyrja/Http/Message/Header/Value/Cookie.ts +165 -0
  280. package/src/Valkyrja/Http/Message/Header/Value/Value.ts +56 -0
  281. package/src/Valkyrja/Http/Message/Param/Abstract/ParamCollection.ts +63 -0
  282. package/src/Valkyrja/Http/Message/Param/AttributeParamCollection.ts +13 -0
  283. package/src/Valkyrja/Http/Message/Param/Contract/AttributeParamCollectionContract.ts +12 -0
  284. package/src/Valkyrja/Http/Message/Param/Contract/CookieParamCollectionContract.ts +12 -0
  285. package/src/Valkyrja/Http/Message/Param/Contract/ParamCollectionContract.ts +18 -0
  286. package/src/Valkyrja/Http/Message/Param/Contract/ParsedBodyParamCollectionContract.ts +12 -0
  287. package/src/Valkyrja/Http/Message/Param/Contract/ParsedJsonParamCollectionContract.ts +12 -0
  288. package/src/Valkyrja/Http/Message/Param/Contract/QueryParamCollectionContract.ts +12 -0
  289. package/src/Valkyrja/Http/Message/Param/Contract/ServerParamCollectionContract.ts +12 -0
  290. package/src/Valkyrja/Http/Message/Param/CookieParamCollection.ts +13 -0
  291. package/src/Valkyrja/Http/Message/Param/ParsedBodyParamCollection.ts +15 -0
  292. package/src/Valkyrja/Http/Message/Param/ParsedJsonParamCollection.ts +13 -0
  293. package/src/Valkyrja/Http/Message/Param/QueryParamCollection.ts +13 -0
  294. package/src/Valkyrja/Http/Message/Param/ServerParamCollection.ts +15 -0
  295. package/src/Valkyrja/Http/Message/Provider/HttpMessageServiceProvider.ts +30 -0
  296. package/src/Valkyrja/Http/Message/Request/Contract/JsonServerRequestContract.ts +16 -0
  297. package/src/Valkyrja/Http/Message/Request/Contract/RequestContract.ts +21 -0
  298. package/src/Valkyrja/Http/Message/Request/Contract/ServerRequestContract.ts +32 -0
  299. package/src/Valkyrja/Http/Message/Request/Factory/RequestFactory.ts +106 -0
  300. package/src/Valkyrja/Http/Message/Request/JsonServerRequest.ts +76 -0
  301. package/src/Valkyrja/Http/Message/Request/Request.ts +109 -0
  302. package/src/Valkyrja/Http/Message/Request/ServerRequest.ts +116 -0
  303. package/src/Valkyrja/Http/Message/Request/Throwable/Contract/HttpRequestThrowable.ts +12 -0
  304. package/src/Valkyrja/Http/Message/Request/Throwable/Exception/Abstract/HttpRequestInvalidArgumentException.ts +15 -0
  305. package/src/Valkyrja/Http/Message/Request/Throwable/Exception/Abstract/HttpRequestRuntimeException.ts +13 -0
  306. package/src/Valkyrja/Http/Message/Request/Throwable/Exception/HttpRequestInvalidMethodException.ts +12 -0
  307. package/src/Valkyrja/Http/Message/Request/Throwable/Exception/HttpRequestInvalidRequestTargetException.ts +12 -0
  308. package/src/Valkyrja/Http/Message/Response/Contract/EmptyResponseContract.ts +12 -0
  309. package/src/Valkyrja/Http/Message/Response/Contract/HtmlResponseContract.ts +12 -0
  310. package/src/Valkyrja/Http/Message/Response/Contract/JsonResponseContract.ts +24 -0
  311. package/src/Valkyrja/Http/Message/Response/Contract/RedirectResponseContract.ts +26 -0
  312. package/src/Valkyrja/Http/Message/Response/Contract/ResponseContract.ts +23 -0
  313. package/src/Valkyrja/Http/Message/Response/Contract/TextResponseContract.ts +12 -0
  314. package/src/Valkyrja/Http/Message/Response/EmptyResponse.ts +22 -0
  315. package/src/Valkyrja/Http/Message/Response/Factory/Contract/ResponseFactoryContract.ts +44 -0
  316. package/src/Valkyrja/Http/Message/Response/Factory/ResponseFactory.ts +64 -0
  317. package/src/Valkyrja/Http/Message/Response/HtmlResponse.ts +36 -0
  318. package/src/Valkyrja/Http/Message/Response/JsonResponse.ts +111 -0
  319. package/src/Valkyrja/Http/Message/Response/RedirectResponse.ts +101 -0
  320. package/src/Valkyrja/Http/Message/Response/Response.ts +81 -0
  321. package/src/Valkyrja/Http/Message/Response/TextResponse.ts +44 -0
  322. package/src/Valkyrja/Http/Message/Response/Throwable/Contract/HttpResponseThrowable.ts +12 -0
  323. package/src/Valkyrja/Http/Message/Response/Throwable/Exception/Abstract/HttpResponseInvalidArgumentException.ts +15 -0
  324. package/src/Valkyrja/Http/Message/Response/Throwable/Exception/Abstract/HttpResponseRuntimeException.ts +15 -0
  325. package/src/Valkyrja/Http/Message/Response/Throwable/Exception/HttpRequestInvalidJsonCallbackException.ts +12 -0
  326. package/src/Valkyrja/Http/Message/Response/Throwable/Exception/HttpRequestInvalidRedirectStatusCodeException.ts +12 -0
  327. package/src/Valkyrja/Http/Message/Response/XmlResponse.ts +40 -0
  328. package/src/Valkyrja/Http/Message/Stream/Contract/StreamContract.ts +27 -0
  329. package/src/Valkyrja/Http/Message/Stream/Enum/Mode.ts +47 -0
  330. package/src/Valkyrja/Http/Message/Stream/Enum/ModeTranslation.ts +14 -0
  331. package/src/Valkyrja/Http/Message/Stream/Factory/StreamFactory.ts +83 -0
  332. package/src/Valkyrja/Http/Message/Stream/Stream.ts +140 -0
  333. package/src/Valkyrja/Http/Message/Stream/Throwable/Contract/HttpStreamThrowable.ts +12 -0
  334. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/Abstract/HttpStreamInvalidArgumentException.ts +15 -0
  335. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/Abstract/HttpStreamRuntimeException.ts +13 -0
  336. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamInvalidLengthException.ts +12 -0
  337. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamInvalidStreamException.ts +12 -0
  338. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamNoStreamAvailableException.ts +12 -0
  339. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamStreamReadException.ts +12 -0
  340. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamStreamSeekException.ts +12 -0
  341. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamStreamTellException.ts +12 -0
  342. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamStreamWriteException.ts +12 -0
  343. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamUnreadableStreamException.ts +12 -0
  344. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamUnseekableStreamException.ts +12 -0
  345. package/src/Valkyrja/Http/Message/Stream/Throwable/Exception/HttpStreamUnwritableStreamException.ts +12 -0
  346. package/src/Valkyrja/Http/Message/Throwable/Contract/HttpMessageThrowable.ts +12 -0
  347. package/src/Valkyrja/Http/Message/Throwable/Exception/Abstract/HttpMessageInvalidArgumentException.ts +15 -0
  348. package/src/Valkyrja/Http/Message/Throwable/Exception/Abstract/HttpMessageRuntimeException.ts +13 -0
  349. package/src/Valkyrja/Http/Message/Throwable/Exception/HttpNotFoundResponseException.ts +22 -0
  350. package/src/Valkyrja/Http/Message/Throwable/Exception/HttpRedirectResponseException.ts +42 -0
  351. package/src/Valkyrja/Http/Message/Throwable/Exception/HttpResponseException.ts +44 -0
  352. package/src/Valkyrja/Http/Message/Trait/Message.ts +77 -0
  353. package/src/Valkyrja/Http/Message/Uri/Contract/UriContract.ts +37 -0
  354. package/src/Valkyrja/Http/Message/Uri/Data/HostPortAccumulator.ts +15 -0
  355. package/src/Valkyrja/Http/Message/Uri/Enum/Scheme.ts +14 -0
  356. package/src/Valkyrja/Http/Message/Uri/Factory/UriFactory.ts +152 -0
  357. package/src/Valkyrja/Http/Message/Uri/Throwable/Contract/HttpUriThrowable.ts +12 -0
  358. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/Abstract/HttpUriInvalidArgumentException.ts +15 -0
  359. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/Abstract/HttpUriRuntimeException.ts +13 -0
  360. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/HttpUriInvalidFromStringException.ts +12 -0
  361. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/HttpUriInvalidPathException.ts +12 -0
  362. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/HttpUriInvalidPortException.ts +12 -0
  363. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/HttpUriInvalidQueryException.ts +12 -0
  364. package/src/Valkyrja/Http/Message/Uri/Throwable/Exception/NoPortExceptionHttpUri.ts +12 -0
  365. package/src/Valkyrja/Http/Message/Uri/Type/Port.ts +39 -0
  366. package/src/Valkyrja/Http/Message/Uri/Uri.ts +191 -0
  367. package/src/Valkyrja/Http/Middleware/Constant/HttpMiddlewareServiceId.ts +24 -0
  368. package/src/Valkyrja/Http/Middleware/Contract/RequestReceivedMiddlewareContract.ts +19 -0
  369. package/src/Valkyrja/Http/Middleware/Contract/RouteDispatchedMiddlewareContract.ts +22 -0
  370. package/src/Valkyrja/Http/Middleware/Contract/RouteMatchedMiddlewareContract.ts +21 -0
  371. package/src/Valkyrja/Http/Middleware/Contract/RouteNotMatchedMiddlewareContract.ts +20 -0
  372. package/src/Valkyrja/Http/Middleware/Contract/SendingResponseMiddlewareContract.ts +20 -0
  373. package/src/Valkyrja/Http/Middleware/Contract/TerminatedMiddlewareContract.ts +16 -0
  374. package/src/Valkyrja/Http/Middleware/Contract/ThrowableCaughtMiddlewareContract.ts +21 -0
  375. package/src/Valkyrja/Http/Middleware/Handler/Abstract/Handler.ts +50 -0
  376. package/src/Valkyrja/Http/Middleware/Handler/Contract/HandlerContract.ts +29 -0
  377. package/src/Valkyrja/Http/Middleware/Handler/Contract/RequestReceivedHandlerContract.ts +17 -0
  378. package/src/Valkyrja/Http/Middleware/Handler/Contract/RouteDispatchedHandlerContract.ts +18 -0
  379. package/src/Valkyrja/Http/Middleware/Handler/Contract/RouteMatchedHandlerContract.ts +18 -0
  380. package/src/Valkyrja/Http/Middleware/Handler/Contract/RouteNotMatchedHandlerContract.ts +17 -0
  381. package/src/Valkyrja/Http/Middleware/Handler/Contract/SendingResponseHandlerContract.ts +17 -0
  382. package/src/Valkyrja/Http/Middleware/Handler/Contract/TerminatedHandlerContract.ts +17 -0
  383. package/src/Valkyrja/Http/Middleware/Handler/Contract/ThrowableCaughtHandlerContract.ts +17 -0
  384. package/src/Valkyrja/Http/Middleware/Handler/RequestReceivedHandler.ts +25 -0
  385. package/src/Valkyrja/Http/Middleware/Handler/RouteDispatchedHandler.ts +30 -0
  386. package/src/Valkyrja/Http/Middleware/Handler/RouteMatchedHandler.ts +26 -0
  387. package/src/Valkyrja/Http/Middleware/Handler/RouteNotMatchedHandler.ts +25 -0
  388. package/src/Valkyrja/Http/Middleware/Handler/SendingResponseHandler.ts +25 -0
  389. package/src/Valkyrja/Http/Middleware/Handler/TerminatedHandler.ts +24 -0
  390. package/src/Valkyrja/Http/Middleware/Handler/ThrowableCaughtHandler.ts +25 -0
  391. package/src/Valkyrja/Http/Middleware/Throwable/Contract/HttpMiddlewareThrowable.ts +12 -0
  392. package/src/Valkyrja/Http/Middleware/Throwable/Exception/Abstract/HttpMiddlewareInvalidArgumentException.ts +16 -0
  393. package/src/Valkyrja/Http/Middleware/Throwable/Exception/Abstract/HttpMiddlewareRuntimeException.ts +14 -0
  394. package/src/Valkyrja/Http/Routing/Cli/Command/Constant/CommandName.ts +12 -0
  395. package/src/Valkyrja/Http/Routing/Cli/Command/ListCommand.ts +95 -0
  396. package/src/Valkyrja/Http/Routing/Collection/Contract/RouteCollectionContract.ts +28 -0
  397. package/src/Valkyrja/Http/Routing/Collection/RouteCollection.ts +227 -0
  398. package/src/Valkyrja/Http/Routing/Collector/Contract/RouteCollectorContract.ts +14 -0
  399. package/src/Valkyrja/Http/Routing/Constant/HttpRoutingServiceId.ts +21 -0
  400. package/src/Valkyrja/Http/Routing/Constant/Regex.ts +57 -0
  401. package/src/Valkyrja/Http/Routing/Controller/Controller.ts +18 -0
  402. package/src/Valkyrja/Http/Routing/Data/Contract/DynamicRouteContract.ts +19 -0
  403. package/src/Valkyrja/Http/Routing/Data/Contract/ParameterContract.ts +28 -0
  404. package/src/Valkyrja/Http/Routing/Data/Contract/RouteContract.ts +69 -0
  405. package/src/Valkyrja/Http/Routing/Data/DynamicRoute.ts +83 -0
  406. package/src/Valkyrja/Http/Routing/Data/HttpRoutingData.ts +22 -0
  407. package/src/Valkyrja/Http/Routing/Data/Parameter.ts +104 -0
  408. package/src/Valkyrja/Http/Routing/Data/Route.ts +252 -0
  409. package/src/Valkyrja/Http/Routing/Dispatcher/Contract/RouterContract.ts +17 -0
  410. package/src/Valkyrja/Http/Routing/Dispatcher/Router.ts +102 -0
  411. package/src/Valkyrja/Http/Routing/Factory/Contract/RoutingResponseFactoryContract.ts +21 -0
  412. package/src/Valkyrja/Http/Routing/Factory/RoutingResponseFactory.ts +33 -0
  413. package/src/Valkyrja/Http/Routing/Matcher/Contract/MatcherContract.ts +17 -0
  414. package/src/Valkyrja/Http/Routing/Matcher/Matcher.ts +109 -0
  415. package/src/Valkyrja/Http/Routing/Processor/Contract/ProcessorContract.ts +14 -0
  416. package/src/Valkyrja/Http/Routing/Processor/Processor.ts +108 -0
  417. package/src/Valkyrja/Http/Routing/Provider/Contract/HttpRouteProviderContract.ts +21 -0
  418. package/src/Valkyrja/Http/Routing/Provider/HttpRoutingCliComponentProvider.ts +39 -0
  419. package/src/Valkyrja/Http/Routing/Provider/HttpRoutingCliRouteProvider.ts +42 -0
  420. package/src/Valkyrja/Http/Routing/Throwable/Contract/HttpRoutingThrowable.ts +12 -0
  421. package/src/Valkyrja/Http/Routing/Throwable/Exception/Abstract/HttpRoutingInvalidArgumentException.ts +16 -0
  422. package/src/Valkyrja/Http/Routing/Throwable/Exception/Abstract/HttpRoutingRuntimeException.ts +14 -0
  423. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidDynamicRouteNameException.ts +12 -0
  424. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidMethodTypeException.ts +12 -0
  425. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidParameterRegexException.ts +12 -0
  426. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidRouteNameException.ts +12 -0
  427. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidRouteParameterException.ts +12 -0
  428. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidRoutePathException.ts +12 -0
  429. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingInvalidRouteRegexException.ts +12 -0
  430. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingNoCastException.ts +12 -0
  431. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingNoRequestStructException.ts +12 -0
  432. package/src/Valkyrja/Http/Routing/Throwable/Exception/HttpRoutingNoResponseStructException.ts +12 -0
  433. package/src/Valkyrja/Http/Routing/Url/Contract/UrlContract.ts +12 -0
  434. package/src/Valkyrja/Http/Routing/Url/Url.ts +27 -0
  435. package/src/Valkyrja/Http/Server/Constant/HttpServerServiceId.ts +14 -0
  436. package/src/Valkyrja/Http/Server/Handler/Contract/ExceptionResponseRequestHandlerContract.ts +15 -0
  437. package/src/Valkyrja/Http/Server/Handler/Contract/RequestHandlerContract.ts +20 -0
  438. package/src/Valkyrja/Http/Server/Handler/RequestHandler.ts +141 -0
  439. package/src/Valkyrja/Http/Server/Middleware/RequestReceived/RedirectTrailingSlashMiddleware.ts +47 -0
  440. package/src/Valkyrja/Http/Server/Middleware/RouteMatched/ResponseStructMiddleware.ts +45 -0
  441. package/src/Valkyrja/Http/Server/Middleware/SendingResponse/NoCacheResponseMiddleware.ts +36 -0
  442. package/src/Valkyrja/Http/Server/Middleware/ThrowableCaught/LogThrowableCaughtMiddleware.ts +32 -0
  443. package/src/Valkyrja/Http/Server/Throwable/Contract/HttpServerThrowable.ts +12 -0
  444. package/src/Valkyrja/Http/Server/Throwable/Exception/Abstract/HttpServerInvalidArgumentException.ts +16 -0
  445. package/src/Valkyrja/Http/Server/Throwable/Exception/Abstract/HttpServerRuntimeException.ts +14 -0
  446. package/src/Valkyrja/Http/Struct/Contract/StructContract.ts +13 -0
  447. package/src/Valkyrja/Http/Struct/Request/Abstract/JsonRequestStruct.ts +33 -0
  448. package/src/Valkyrja/Http/Struct/Request/Abstract/ParsedBodyRequestStruct.ts +21 -0
  449. package/src/Valkyrja/Http/Struct/Request/Abstract/QueryRequestStruct.ts +21 -0
  450. package/src/Valkyrja/Http/Struct/Request/Abstract/RequestStruct.ts +36 -0
  451. package/src/Valkyrja/Http/Struct/Request/Contract/RequestStructContract.ts +16 -0
  452. package/src/Valkyrja/Http/Struct/Response/Abstract/ResponseStruct.ts +31 -0
  453. package/src/Valkyrja/Http/Struct/Response/Contract/ResponseStructContract.ts +14 -0
  454. package/src/Valkyrja/Http/Struct/Throwable/Contract/HttpStructThrowable.ts +12 -0
  455. package/src/Valkyrja/Http/Struct/Throwable/Exception/Abstract/HttpStructInvalidArgumentException.ts +15 -0
  456. package/src/Valkyrja/Http/Struct/Throwable/Exception/Abstract/HttpStructRuntimeException.ts +13 -0
  457. package/src/Valkyrja/Http/Struct/Throwable/Exception/HttpStructJsonServerRequestExpectedException.ts +12 -0
  458. package/src/Valkyrja/Http/Throwable/Contract/HttpThrowable.ts +12 -0
  459. package/src/Valkyrja/Http/Throwable/Exception/Abstract/HttpInvalidArgumentException.ts +13 -0
  460. package/src/Valkyrja/Http/Throwable/Exception/Abstract/HttpRuntimeException.ts +13 -0
  461. package/src/Valkyrja/Log/Logger/Contract/LoggerContract.ts +22 -0
  462. package/src/Valkyrja/Throwable/Constant/ThrowableServiceId.ts +12 -0
  463. package/src/Valkyrja/Throwable/Contract/ValkyrjaThrowable.ts +12 -0
  464. package/src/Valkyrja/Throwable/Exception/Abstract/ValkyrjaInvalidArgumentException.ts +18 -0
  465. package/src/Valkyrja/Throwable/Exception/Abstract/ValkyrjaRuntimeException.ts +18 -0
  466. package/src/Valkyrja/Throwable/Handler/Abstract/ThrowableHandler.ts +22 -0
  467. package/src/Valkyrja/Throwable/Handler/Contract/ThrowableHandlerContract.ts +18 -0
  468. package/src/Valkyrja/Type/Data/Cast.ts +16 -0
  469. package/src/Valkyrja/Type/Object/Factory/ObjectFactory.ts +14 -0
  470. package/src/Valkyrja/Validation/Constant/ErrorMessage.ts +33 -0
  471. package/src/Valkyrja/Validation/Rule/Abstract/Rule.ts +30 -0
  472. package/src/Valkyrja/Validation/Rule/Contract/RuleContract.ts +14 -0
  473. package/src/Valkyrja/Validation/Rule/Int/GreaterThan.ts +24 -0
  474. package/src/Valkyrja/Validation/Rule/Int/LessThan.ts +24 -0
  475. package/src/Valkyrja/Validation/Rule/Is/Email.ts +16 -0
  476. package/src/Valkyrja/Validation/Rule/Is/Equal.ts +24 -0
  477. package/src/Valkyrja/Validation/Rule/Is/IsBool.ts +16 -0
  478. package/src/Valkyrja/Validation/Rule/Is/IsEmpty.ts +16 -0
  479. package/src/Valkyrja/Validation/Rule/Is/IsNumeric.ts +16 -0
  480. package/src/Valkyrja/Validation/Rule/Is/IsString.ts +16 -0
  481. package/src/Valkyrja/Validation/Rule/Is/NotEmpty.ts +16 -0
  482. package/src/Valkyrja/Validation/Rule/Is/NotEqual.ts +24 -0
  483. package/src/Valkyrja/Validation/Rule/Is/Required.ts +16 -0
  484. package/src/Valkyrja/Validation/Rule/String/Alpha.ts +16 -0
  485. package/src/Valkyrja/Validation/Rule/String/Contains.ts +24 -0
  486. package/src/Valkyrja/Validation/Rule/String/EndsWith.ts +24 -0
  487. package/src/Valkyrja/Validation/Rule/String/Lowercase.ts +16 -0
  488. package/src/Valkyrja/Validation/Rule/String/Max.ts +24 -0
  489. package/src/Valkyrja/Validation/Rule/String/Min.ts +24 -0
  490. package/src/Valkyrja/Validation/Rule/String/Regex.ts +24 -0
  491. package/src/Valkyrja/Validation/Rule/String/StartsWith.ts +24 -0
  492. package/src/Valkyrja/Validation/Rule/String/Uppercase.ts +16 -0
  493. package/src/Valkyrja/Validation/Throwable/Contract/ValidationThrowable.ts +12 -0
  494. package/src/Valkyrja/Validation/Throwable/Exception/Abstract/ValidationInvalidArgumentException.ts +15 -0
  495. package/src/Valkyrja/Validation/Throwable/Exception/Abstract/ValidationRuntimeException.ts +13 -0
  496. package/src/Valkyrja/Validation/Throwable/Exception/ValidationRuleFailureException.ts +12 -0
  497. package/src/Valkyrja/Validation/Validator/Contract/ValidatorContract.ts +18 -0
  498. package/src/Valkyrja/Validation/Validator/Validator.ts +57 -0
@@ -0,0 +1,252 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { RequestMethod } from '../../Message/Enum/RequestMethod.js';
11
+ import { HttpRoutingNoRequestStructException } from '../Throwable/Exception/HttpRoutingNoRequestStructException.js';
12
+ import { HttpRoutingNoResponseStructException } from '../Throwable/Exception/HttpRoutingNoResponseStructException.js';
13
+
14
+ import type { ContainerContract } from '../../../Container/Manager/Contract/ContainerContract.js';
15
+ import type { ResponseContract } from '../../Message/Response/Contract/ResponseContract.js';
16
+ import type { RouteDispatchedMiddlewareContract } from '../../Middleware/Contract/RouteDispatchedMiddlewareContract.js';
17
+ import type { RouteMatchedMiddlewareContract } from '../../Middleware/Contract/RouteMatchedMiddlewareContract.js';
18
+ import type { SendingResponseMiddlewareContract } from '../../Middleware/Contract/SendingResponseMiddlewareContract.js';
19
+ import type { TerminatedMiddlewareContract } from '../../Middleware/Contract/TerminatedMiddlewareContract.js';
20
+ import type { ThrowableCaughtMiddlewareContract } from '../../Middleware/Contract/ThrowableCaughtMiddlewareContract.js';
21
+ import type { RequestStructContract } from '../../Struct/Request/Contract/RequestStructContract.js';
22
+ import type { ResponseStructContract } from '../../Struct/Response/Contract/ResponseStructContract.js';
23
+ import type { RouteContract } from './Contract/RouteContract.js';
24
+ import { ObjectFactory } from '../../../Type/Object/Factory/ObjectFactory.js';
25
+
26
+ export class Route implements RouteContract {
27
+ protected handler: (container: ContainerContract, route: RouteContract) => ResponseContract;
28
+
29
+ constructor(
30
+ protected path: string,
31
+ protected name: string,
32
+ handler: (container: ContainerContract, route: RouteContract) => ResponseContract,
33
+ protected requestMethods: RequestMethod[] = [RequestMethod.HEAD, RequestMethod.GET],
34
+ protected routeMatchedMiddleware: Array<new (...args: unknown[]) => RouteMatchedMiddlewareContract> = [],
35
+ protected routeDispatchedMiddleware: Array<new (...args: unknown[]) => RouteDispatchedMiddlewareContract> = [],
36
+ protected throwableCaughtMiddleware: Array<new (...args: unknown[]) => ThrowableCaughtMiddlewareContract> = [],
37
+ protected sendingResponseMiddleware: Array<new (...args: unknown[]) => SendingResponseMiddlewareContract> = [],
38
+ protected terminatedMiddleware: Array<new (...args: unknown[]) => TerminatedMiddlewareContract> = [],
39
+ protected requestStruct: RequestStructContract | null = null,
40
+ protected responseStruct: ResponseStructContract | null = null,
41
+ ) {
42
+ this.handler = handler;
43
+ }
44
+
45
+ getPath(): string {
46
+ return this.path;
47
+ }
48
+
49
+ withPath(path: string): this {
50
+ const clone = ObjectFactory.clone(this);
51
+ clone.path = this.getFilteredPath(path);
52
+ return clone;
53
+ }
54
+
55
+ withAddedPath(path: string): this {
56
+ const clone = ObjectFactory.clone(this);
57
+ clone.path = this.getFilteredPath(this.getFilteredPath(this.path) + this.getFilteredPath(path));
58
+ return clone;
59
+ }
60
+
61
+ getName(): string {
62
+ return this.name;
63
+ }
64
+
65
+ withName(name: string): this {
66
+ const clone = ObjectFactory.clone(this);
67
+ clone.name = name;
68
+ return clone;
69
+ }
70
+
71
+ withAddedName(name: string): this {
72
+ const clone = ObjectFactory.clone(this);
73
+ clone.name = this.name + name;
74
+ return clone;
75
+ }
76
+
77
+ getHandler(): (container: ContainerContract, route: RouteContract) => ResponseContract {
78
+ return this.handler;
79
+ }
80
+
81
+ withHandler(handler: (container: ContainerContract, route: RouteContract) => ResponseContract): this {
82
+ const clone = ObjectFactory.clone(this);
83
+ clone.handler = handler;
84
+ return clone;
85
+ }
86
+
87
+ getRequestMethods(): RequestMethod[] {
88
+ return this.requestMethods;
89
+ }
90
+
91
+ hasRequestMethod(requestMethod: RequestMethod): boolean {
92
+ return this.requestMethods.includes(requestMethod);
93
+ }
94
+
95
+ withRequestMethods(...requestMethods: RequestMethod[]): this {
96
+ const clone = ObjectFactory.clone(this);
97
+ clone.requestMethods = requestMethods;
98
+ return clone;
99
+ }
100
+
101
+ withAddedRequestMethods(...requestMethods: RequestMethod[]): this {
102
+ const clone = ObjectFactory.clone(this);
103
+ const existing = [...this.requestMethods];
104
+
105
+ for (const method of requestMethods) {
106
+ if (!existing.includes(method)) {
107
+ existing.push(method);
108
+ }
109
+ }
110
+
111
+ clone.requestMethods = existing;
112
+ return clone;
113
+ }
114
+
115
+ getRouteMatchedMiddleware(): Array<new (...args: unknown[]) => RouteMatchedMiddlewareContract> {
116
+ return this.routeMatchedMiddleware;
117
+ }
118
+
119
+ withRouteMatchedMiddleware(...middleware: Array<new (...args: unknown[]) => RouteMatchedMiddlewareContract>): this {
120
+ const clone = ObjectFactory.clone(this);
121
+ clone.routeMatchedMiddleware = middleware;
122
+ return clone;
123
+ }
124
+
125
+ withAddedRouteMatchedMiddleware(
126
+ ...middleware: Array<new (...args: unknown[]) => RouteMatchedMiddlewareContract>
127
+ ): this {
128
+ const clone = ObjectFactory.clone(this);
129
+ clone.routeMatchedMiddleware = [...this.routeMatchedMiddleware, ...middleware];
130
+ return clone;
131
+ }
132
+
133
+ getRouteDispatchedMiddleware(): Array<new (...args: unknown[]) => RouteDispatchedMiddlewareContract> {
134
+ return this.routeDispatchedMiddleware;
135
+ }
136
+
137
+ withRouteDispatchedMiddleware(
138
+ ...middleware: Array<new (...args: unknown[]) => RouteDispatchedMiddlewareContract>
139
+ ): this {
140
+ const clone = ObjectFactory.clone(this);
141
+ clone.routeDispatchedMiddleware = middleware;
142
+ return clone;
143
+ }
144
+
145
+ withAddedRouteDispatchedMiddleware(
146
+ ...middleware: Array<new (...args: unknown[]) => RouteDispatchedMiddlewareContract>
147
+ ): this {
148
+ const clone = ObjectFactory.clone(this);
149
+ clone.routeDispatchedMiddleware = [...this.routeDispatchedMiddleware, ...middleware];
150
+ return clone;
151
+ }
152
+
153
+ getThrowableCaughtMiddleware(): Array<new (...args: unknown[]) => ThrowableCaughtMiddlewareContract> {
154
+ return this.throwableCaughtMiddleware;
155
+ }
156
+
157
+ withThrowableCaughtMiddleware(
158
+ ...middleware: Array<new (...args: unknown[]) => ThrowableCaughtMiddlewareContract>
159
+ ): this {
160
+ const clone = ObjectFactory.clone(this);
161
+ clone.throwableCaughtMiddleware = middleware;
162
+ return clone;
163
+ }
164
+
165
+ withAddedThrowableCaughtMiddleware(
166
+ ...middleware: Array<new (...args: unknown[]) => ThrowableCaughtMiddlewareContract>
167
+ ): this {
168
+ const clone = ObjectFactory.clone(this);
169
+ clone.throwableCaughtMiddleware = [...this.throwableCaughtMiddleware, ...middleware];
170
+ return clone;
171
+ }
172
+
173
+ getSendingResponseMiddleware(): Array<new (...args: unknown[]) => SendingResponseMiddlewareContract> {
174
+ return this.sendingResponseMiddleware;
175
+ }
176
+
177
+ withSendingResponseMiddleware(
178
+ ...middleware: Array<new (...args: unknown[]) => SendingResponseMiddlewareContract>
179
+ ): this {
180
+ const clone = ObjectFactory.clone(this);
181
+ clone.sendingResponseMiddleware = middleware;
182
+ return clone;
183
+ }
184
+
185
+ withAddedSendingResponseMiddleware(
186
+ ...middleware: Array<new (...args: unknown[]) => SendingResponseMiddlewareContract>
187
+ ): this {
188
+ const clone = ObjectFactory.clone(this);
189
+ clone.sendingResponseMiddleware = [...this.sendingResponseMiddleware, ...middleware];
190
+ return clone;
191
+ }
192
+
193
+ getTerminatedMiddleware(): Array<new (...args: unknown[]) => TerminatedMiddlewareContract> {
194
+ return this.terminatedMiddleware;
195
+ }
196
+
197
+ withTerminatedMiddleware(...middleware: Array<new (...args: unknown[]) => TerminatedMiddlewareContract>): this {
198
+ const clone = ObjectFactory.clone(this);
199
+ clone.terminatedMiddleware = middleware;
200
+ return clone;
201
+ }
202
+
203
+ withAddedTerminatedMiddleware(
204
+ ...middleware: Array<new (...args: unknown[]) => TerminatedMiddlewareContract>
205
+ ): this {
206
+ const clone = ObjectFactory.clone(this);
207
+ clone.terminatedMiddleware = [...this.terminatedMiddleware, ...middleware];
208
+ return clone;
209
+ }
210
+
211
+ hasRequestStruct(): boolean {
212
+ return this.requestStruct !== null;
213
+ }
214
+
215
+ getRequestStruct(): RequestStructContract {
216
+ if (this.requestStruct === null) {
217
+ throw new HttpRoutingNoRequestStructException('No request struct was set for this route');
218
+ }
219
+
220
+ return this.requestStruct;
221
+ }
222
+
223
+ withRequestStruct(requestStruct: RequestStructContract): this {
224
+ const clone = ObjectFactory.clone(this);
225
+ clone.requestStruct = requestStruct;
226
+ return clone;
227
+ }
228
+
229
+ hasResponseStruct(): boolean {
230
+ return this.responseStruct !== null;
231
+ }
232
+
233
+ getResponseStruct(): ResponseStructContract {
234
+ if (this.responseStruct === null) {
235
+ throw new HttpRoutingNoResponseStructException('No response struct was set for this route');
236
+ }
237
+
238
+ return this.responseStruct;
239
+ }
240
+
241
+ withResponseStruct(responseStruct: ResponseStructContract): this {
242
+ const clone = ObjectFactory.clone(this);
243
+ clone.responseStruct = responseStruct;
244
+ return clone;
245
+ }
246
+
247
+ protected getFilteredPath(path: string): string {
248
+ const trimmed = path.replace(/^\/+|\/+$/g, '');
249
+
250
+ return trimmed === '' ? '/' : '/' + trimmed;
251
+ }
252
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { ServerRequestContract } from '../../../Message/Request/Contract/ServerRequestContract.js';
11
+ import type { ResponseContract } from '../../../Message/Response/Contract/ResponseContract.js';
12
+ import type { RouteContract } from '../../Data/Contract/RouteContract.js';
13
+
14
+ export interface RouterContract {
15
+ dispatch(request: ServerRequestContract): ResponseContract;
16
+ dispatchRoute(request: ServerRequestContract, route: RouteContract): ResponseContract;
17
+ }
@@ -0,0 +1,102 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Container } from '../../../Container/Manager/Container.js';
11
+ import { RequestMethod } from '../../Message/Enum/RequestMethod.js';
12
+ import { StatusCode } from '../../Message/Enum/StatusCode.js';
13
+ import { ResponseFactory } from '../../Message/Response/Factory/ResponseFactory.js';
14
+ import { RouteDispatchedHandler } from '../../Middleware/Handler/RouteDispatchedHandler.js';
15
+ import { RouteMatchedHandler } from '../../Middleware/Handler/RouteMatchedHandler.js';
16
+ import { RouteNotMatchedHandler } from '../../Middleware/Handler/RouteNotMatchedHandler.js';
17
+ import { SendingResponseHandler } from '../../Middleware/Handler/SendingResponseHandler.js';
18
+ import { TerminatedHandler } from '../../Middleware/Handler/TerminatedHandler.js';
19
+ import { ThrowableCaughtHandler } from '../../Middleware/Handler/ThrowableCaughtHandler.js';
20
+ import { Matcher } from '../Matcher/Matcher.js';
21
+
22
+ import type { ContainerContract } from '../../../Container/Manager/Contract/ContainerContract.js';
23
+ import type { ServerRequestContract } from '../../Message/Request/Contract/ServerRequestContract.js';
24
+ import type { ResponseContract } from '../../Message/Response/Contract/ResponseContract.js';
25
+ import type { ResponseFactoryContract } from '../../Message/Response/Factory/Contract/ResponseFactoryContract.js';
26
+ import type { RouteDispatchedHandlerContract } from '../../Middleware/Handler/Contract/RouteDispatchedHandlerContract.js';
27
+ import type { RouteMatchedHandlerContract } from '../../Middleware/Handler/Contract/RouteMatchedHandlerContract.js';
28
+ import type { RouteNotMatchedHandlerContract } from '../../Middleware/Handler/Contract/RouteNotMatchedHandlerContract.js';
29
+ import type { SendingResponseHandlerContract } from '../../Middleware/Handler/Contract/SendingResponseHandlerContract.js';
30
+ import type { TerminatedHandlerContract } from '../../Middleware/Handler/Contract/TerminatedHandlerContract.js';
31
+ import type { ThrowableCaughtHandlerContract } from '../../Middleware/Handler/Contract/ThrowableCaughtHandlerContract.js';
32
+ import type { RouteContract } from '../Data/Contract/RouteContract.js';
33
+ import type { MatcherContract } from '../Matcher/Contract/MatcherContract.js';
34
+ import type { RouterContract } from './Contract/RouterContract.js';
35
+
36
+ export class Router implements RouterContract {
37
+ constructor(
38
+ protected container: ContainerContract = new Container(),
39
+ protected matcher: MatcherContract = new Matcher(),
40
+ protected responseFactory: ResponseFactoryContract = new ResponseFactory(),
41
+ protected throwableCaughtHandler: ThrowableCaughtHandlerContract = new ThrowableCaughtHandler(),
42
+ protected routeMatchedHandler: RouteMatchedHandlerContract = new RouteMatchedHandler(),
43
+ protected routeNotMatchedHandler: RouteNotMatchedHandlerContract = new RouteNotMatchedHandler(),
44
+ protected routeDispatchedHandler: RouteDispatchedHandlerContract = new RouteDispatchedHandler(),
45
+ protected sendingResponseHandler: SendingResponseHandlerContract = new SendingResponseHandler(),
46
+ protected terminatedHandler: TerminatedHandlerContract = new TerminatedHandler(),
47
+ ) {}
48
+
49
+ dispatch(request: ServerRequestContract): ResponseContract {
50
+ const matchedRoute = this.attemptToMatchRoute(request);
51
+
52
+ if (!(matchedRoute instanceof Object && 'getPath' in matchedRoute)) {
53
+ return this.routeNotMatchedHandler.routeNotMatched(request, matchedRoute);
54
+ }
55
+
56
+ return this.dispatchRoute(request, matchedRoute);
57
+ }
58
+
59
+ dispatchRoute(request: ServerRequestContract, route: RouteContract): ResponseContract {
60
+ this.routeMatched(route);
61
+
62
+ const routeAfterMiddleware = this.routeMatchedHandler.routeMatched(request, route);
63
+
64
+ if (!('getPath' in routeAfterMiddleware)) {
65
+ return routeAfterMiddleware;
66
+ }
67
+
68
+ const matchedRoute = routeAfterMiddleware;
69
+
70
+ this.container.setSingleton('RouteContract', matchedRoute);
71
+
72
+ const handler = matchedRoute.getHandler();
73
+ const response = handler(this.container, matchedRoute);
74
+
75
+ return this.routeDispatchedHandler.routeDispatched(request, response, matchedRoute);
76
+ }
77
+
78
+ protected attemptToMatchRoute(request: ServerRequestContract): RouteContract | ResponseContract {
79
+ const requestPath = decodeURIComponent(request.getUri().getPath());
80
+ const route = this.matcher.match(requestPath, request.getMethod());
81
+
82
+ if (route !== null) {
83
+ return route;
84
+ }
85
+
86
+ if (this.matcher.match(requestPath, RequestMethod.ANY) !== null) {
87
+ return this.responseFactory.createResponse(null, StatusCode.METHOD_NOT_ALLOWED);
88
+ }
89
+
90
+ return this.responseFactory.createResponse(null, StatusCode.NOT_FOUND);
91
+ }
92
+
93
+ protected routeMatched(route: RouteContract): void {
94
+ this.routeMatchedHandler.add(...route.getRouteMatchedMiddleware());
95
+ this.routeDispatchedHandler.add(...route.getRouteDispatchedMiddleware());
96
+ this.throwableCaughtHandler.add(...route.getThrowableCaughtMiddleware());
97
+ this.sendingResponseHandler.add(...route.getSendingResponseMiddleware());
98
+ this.terminatedHandler.add(...route.getTerminatedMiddleware());
99
+
100
+ this.container.setSingleton('RouteContract', route);
101
+ }
102
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { StatusCode } from '../../../Message/Enum/StatusCode.js';
11
+ import type { HeaderCollectionContract } from '../../../Message/Header/Collection/Contract/HeaderCollectionContract.js';
12
+ import type { RedirectResponseContract } from '../../../Message/Response/Contract/RedirectResponseContract.js';
13
+
14
+ export interface RoutingResponseFactoryContract {
15
+ createRouteRedirectResponse(
16
+ name: string,
17
+ data?: Record<string, string | number>,
18
+ statusCode?: StatusCode,
19
+ headers?: HeaderCollectionContract,
20
+ ): RedirectResponseContract;
21
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { StatusCode } from '../../Message/Enum/StatusCode.js';
11
+ import type { HeaderCollectionContract } from '../../Message/Header/Collection/Contract/HeaderCollectionContract.js';
12
+ import type { RedirectResponseContract } from '../../Message/Response/Contract/RedirectResponseContract.js';
13
+ import type { ResponseFactoryContract } from '../../Message/Response/Factory/Contract/ResponseFactoryContract.js';
14
+ import type { UrlContract } from '../Url/Contract/UrlContract.js';
15
+ import type { RoutingResponseFactoryContract } from './Contract/RoutingResponseFactoryContract.js';
16
+
17
+ export class RoutingResponseFactory implements RoutingResponseFactoryContract {
18
+ constructor(
19
+ protected responseFactory: ResponseFactoryContract,
20
+ protected url: UrlContract,
21
+ ) {}
22
+
23
+ createRouteRedirectResponse(
24
+ name: string,
25
+ data: Record<string, string | number> = {},
26
+ statusCode?: StatusCode,
27
+ headers?: HeaderCollectionContract,
28
+ ): RedirectResponseContract {
29
+ const url = this.url.getUrl(name, data);
30
+
31
+ return this.responseFactory.createRedirectResponse(url, statusCode, headers);
32
+ }
33
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { RequestMethod } from '../../../Message/Enum/RequestMethod.js';
11
+ import type { RouteContract } from '../../Data/Contract/RouteContract.js';
12
+
13
+ export interface MatcherContract {
14
+ match(path: string, requestMethod: RequestMethod): RouteContract | null;
15
+ matchStatic(path: string, requestMethod: RequestMethod): RouteContract | null;
16
+ matchDynamic(path: string, requestMethod: RequestMethod): RouteContract | null;
17
+ }
@@ -0,0 +1,109 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { RouteCollection } from '../Collection/RouteCollection.js';
11
+ import { HttpRoutingInvalidRoutePathException } from '../Throwable/Exception/HttpRoutingInvalidRoutePathException.js';
12
+
13
+ import type { RequestMethod } from '../../Message/Enum/RequestMethod.js';
14
+ import type { DynamicRouteContract } from '../Data/Contract/DynamicRouteContract.js';
15
+ import type { ParameterContract } from '../Data/Contract/ParameterContract.js';
16
+ import type { RouteContract } from '../Data/Contract/RouteContract.js';
17
+ import type { RouteCollectionContract } from '../Collection/Contract/RouteCollectionContract.js';
18
+ import type { MatcherContract } from './Contract/MatcherContract.js';
19
+
20
+ export class Matcher implements MatcherContract {
21
+ constructor(protected collection: RouteCollectionContract = new RouteCollection()) {}
22
+
23
+ match(path: string, requestMethod: RequestMethod): RouteContract | null {
24
+ const normalizedPath = '/' + path.replace(/^\/+|\/+$/g, '');
25
+ const route = this.matchStatic(normalizedPath, requestMethod);
26
+
27
+ return route ?? this.matchDynamic(normalizedPath, requestMethod);
28
+ }
29
+
30
+ matchStatic(path: string, requestMethod: RequestMethod): RouteContract | null {
31
+ if (this.collection.hasPath(path, requestMethod)) {
32
+ return Object.assign(
33
+ Object.create(
34
+ Object.getPrototypeOf(this.collection.getByPath(path, requestMethod)) as object | null,
35
+ ) as RouteContract,
36
+ this.collection.getByPath(path, requestMethod),
37
+ );
38
+ }
39
+
40
+ return null;
41
+ }
42
+
43
+ matchDynamic(path: string, requestMethod: RequestMethod): RouteContract | null {
44
+ const regexes = this.collection.getRegexes(requestMethod);
45
+
46
+ for (const [regex] of Object.entries(regexes)) {
47
+ if (regex === '') {
48
+ continue;
49
+ }
50
+
51
+ const re = new RegExp(regex);
52
+ const matches = re.exec(path);
53
+
54
+ if (matches !== null) {
55
+ return this.processArguments(this.collection.getByRegex(regex, requestMethod), matches);
56
+ }
57
+ }
58
+
59
+ return null;
60
+ }
61
+
62
+ protected processArguments(route: DynamicRouteContract, matches: RegExpExecArray): DynamicRouteContract {
63
+ const parameters = route.getParameters();
64
+
65
+ if (parameters.length === 0) {
66
+ throw new HttpRoutingInvalidRoutePathException('Route parameters must not be empty');
67
+ }
68
+
69
+ const namedGroups = matches.groups ?? {};
70
+ const parametersWithValues: ParameterContract[] = [];
71
+
72
+ for (const parameter of parameters) {
73
+ const name = parameter.getName();
74
+ const match = namedGroups[name] ?? parameter.getDefault();
75
+
76
+ if (match === null || match === undefined) {
77
+ parametersWithValues.push(parameter);
78
+ continue;
79
+ }
80
+
81
+ const value = this.checkAndCastMatchValue(parameter, match as string);
82
+
83
+ parametersWithValues.push(parameter.withValue(value));
84
+ }
85
+
86
+ return route.withParameters(...parametersWithValues);
87
+ }
88
+
89
+ protected checkAndCastMatchValue(parameter: ParameterContract, match: string): unknown {
90
+ if (parameter.hasCast()) {
91
+ return this.castMatchValue(parameter, match);
92
+ }
93
+
94
+ return match;
95
+ }
96
+
97
+ protected castMatchValue(parameter: ParameterContract, match: string): unknown {
98
+ const cast = parameter.getCast();
99
+ const type = (cast.type as unknown as { fromValue: (v: unknown) => { asValue: () => unknown } }).fromValue(
100
+ match,
101
+ );
102
+
103
+ if (cast.convert) {
104
+ return type.asValue();
105
+ }
106
+
107
+ return type;
108
+ }
109
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import type { RouteContract } from '../../Data/Contract/RouteContract.js';
11
+
12
+ export interface ProcessorContract {
13
+ route(route: RouteContract): RouteContract;
14
+ }
@@ -0,0 +1,108 @@
1
+ /*
2
+ * This file is part of the Valkyrja package.
3
+ *
4
+ * (c) Melech Mizrachi <melechmizrachi@gmail.com>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Regex } from '../Constant/Regex.js';
11
+ import { HttpRoutingInvalidRoutePathException } from '../Throwable/Exception/HttpRoutingInvalidRoutePathException.js';
12
+
13
+ import type { DynamicRouteContract } from '../Data/Contract/DynamicRouteContract.js';
14
+ import type { ParameterContract } from '../Data/Contract/ParameterContract.js';
15
+ import type { RouteContract } from '../Data/Contract/RouteContract.js';
16
+ import type { ProcessorContract } from './Contract/ProcessorContract.js';
17
+
18
+ export class Processor implements ProcessorContract {
19
+ route(route: RouteContract): RouteContract {
20
+ const path = '/' + route.getPath().replace(/^\/+|\/+$/g, '');
21
+
22
+ route = route.withPath(path);
23
+
24
+ if (this.isDynamicRoute(route) && route.getPath().includes('{')) {
25
+ route = this.modifyRegex(route);
26
+ }
27
+
28
+ return route;
29
+ }
30
+
31
+ protected isDynamicRoute(route: RouteContract): route is DynamicRouteContract {
32
+ return 'getRegex' in route && typeof (route as DynamicRouteContract).getRegex === 'function';
33
+ }
34
+
35
+ protected modifyRegex(route: DynamicRouteContract): RouteContract {
36
+ if (route.getRegex() !== '') {
37
+ return route;
38
+ }
39
+
40
+ let regex = route.getPath().replace(/\//g, Regex.PATH);
41
+
42
+ const parameters = route.getParameters();
43
+
44
+ for (const parameter of parameters) {
45
+ const processed = this.processParameterInRegex(parameter, regex);
46
+
47
+ regex = this.replaceParameterNameInRegex(route, processed, regex);
48
+ }
49
+
50
+ regex = Regex.START + regex + Regex.END;
51
+
52
+ return route.withRegex(regex);
53
+ }
54
+
55
+ protected processParameterInRegex(parameter: ParameterContract, regex: string): ParameterContract {
56
+ if (parameter.isOptional() || regex.includes(parameter.getName() + '?')) {
57
+ return parameter.withIsOptional(true);
58
+ }
59
+
60
+ return parameter;
61
+ }
62
+
63
+ protected replaceParameterNameInRegex(route: RouteContract, parameter: ParameterContract, regex: string): string {
64
+ const nameReplacement = this.getRegexParameterNameReplacement(parameter);
65
+
66
+ if (!regex.includes(nameReplacement)) {
67
+ throw new HttpRoutingInvalidRoutePathException(`${route.getPath()} is missing ${nameReplacement}`);
68
+ }
69
+
70
+ const parameterRegex = this.getParameterRegex(parameter);
71
+
72
+ return regex.replace(nameReplacement, parameterRegex);
73
+ }
74
+
75
+ protected getRegexParameterNameReplacement(parameter: ParameterContract): string {
76
+ const isOptional = parameter.isOptional();
77
+
78
+ return (isOptional ? Regex.PATH : '') + '{' + parameter.getName() + (isOptional ? '?' : '') + '}';
79
+ }
80
+
81
+ protected getParameterRegex(parameter: ParameterContract): string {
82
+ return (
83
+ this.getParameterRegexOptionalCaptureGroupStart(parameter) +
84
+ this.getParameterRegexCaptureGroupStart(parameter) +
85
+ this.getParameterRegexNameCaptureGroup(parameter) +
86
+ parameter.getRegex() +
87
+ this.getParameterRegexCaptureGroupEnd(parameter)
88
+ );
89
+ }
90
+
91
+ protected getParameterRegexOptionalCaptureGroupStart(parameter: ParameterContract): string {
92
+ return parameter.isOptional() ? Regex.START_OPTIONAL_CAPTURE_GROUP : '';
93
+ }
94
+
95
+ protected getParameterRegexCaptureGroupStart(parameter: ParameterContract): string {
96
+ return !parameter.shouldCapture() ? Regex.START_NON_CAPTURE_GROUP : Regex.START_CAPTURE_GROUP;
97
+ }
98
+
99
+ protected getParameterRegexNameCaptureGroup(parameter: ParameterContract): string {
100
+ return parameter.shouldCapture()
101
+ ? Regex.START_CAPTURE_GROUP_NAME + parameter.getName() + Regex.END_CAPTURE_GROUP_NAME
102
+ : '';
103
+ }
104
+
105
+ protected getParameterRegexCaptureGroupEnd(parameter: ParameterContract): string {
106
+ return parameter.isOptional() ? Regex.END_OPTIONAL_CAPTURE_GROUP : Regex.END_CAPTURE_GROUP;
107
+ }
108
+ }