@webiny/app 6.0.0-beta.0 → 6.0.0-rc.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 (435) hide show
  1. package/App.d.ts +6 -13
  2. package/App.js +70 -83
  3. package/App.js.map +1 -1
  4. package/AppContainer.d.ts +23 -0
  5. package/AppContainer.js +9 -0
  6. package/AppContainer.js.map +1 -0
  7. package/README.md +7 -15
  8. package/apollo-client/InMemoryCache.d.ts +3 -2
  9. package/apollo-client/InMemoryCache.js +16 -48
  10. package/apollo-client/InMemoryCache.js.map +1 -1
  11. package/apollo-client/IntrospectionFragmentMatcher.d.ts +2 -2
  12. package/apollo-client/IntrospectionFragmentMatcher.js +33 -50
  13. package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
  14. package/components/Image.d.ts +1 -2
  15. package/components/Image.js +11 -19
  16. package/components/Image.js.map +1 -1
  17. package/components/index.d.ts +1 -2
  18. package/components/index.js +1 -19
  19. package/components/index.js.map +1 -1
  20. package/config/RouterConfig/Route.d.ts +29 -0
  21. package/config/RouterConfig/Route.js +33 -0
  22. package/config/RouterConfig/Route.js.map +1 -0
  23. package/config/RouterConfig.d.ts +31 -0
  24. package/config/RouterConfig.js +18 -0
  25. package/config/RouterConfig.js.map +1 -0
  26. package/config.d.ts +1 -1
  27. package/config.js +7 -13
  28. package/config.js.map +1 -1
  29. package/contexts/Ui/index.d.ts +2 -2
  30. package/contexts/Ui/index.js +28 -52
  31. package/contexts/Ui/index.js.map +1 -1
  32. package/core/DebounceRender.js +13 -24
  33. package/core/DebounceRender.js.map +1 -1
  34. package/core/Plugin.d.ts +1 -1
  35. package/core/Plugin.js +11 -19
  36. package/core/Plugin.js.map +1 -1
  37. package/core/Plugins.d.ts +1 -1
  38. package/core/Plugins.js +20 -25
  39. package/core/Plugins.js.map +1 -1
  40. package/core/Provider.d.ts +1 -1
  41. package/core/Provider.js +9 -13
  42. package/core/Provider.js.map +1 -1
  43. package/core/Routes.d.ts +2 -1
  44. package/core/Routes.js +13 -23
  45. package/core/Routes.js.map +1 -1
  46. package/core/createProvider.d.ts +7 -3
  47. package/core/createProvider.js +3 -9
  48. package/core/createProvider.js.map +1 -1
  49. package/core/createProviderPlugin.d.ts +1 -1
  50. package/core/createProviderPlugin.js +4 -10
  51. package/core/createProviderPlugin.js.map +1 -1
  52. package/errors/AuthenticationErrorEvent.d.ts +9 -0
  53. package/errors/AuthenticationErrorEvent.js +10 -0
  54. package/errors/AuthenticationErrorEvent.js.map +1 -0
  55. package/errors/NetworkErrorEvent.d.ts +15 -0
  56. package/errors/NetworkErrorEvent.js +10 -0
  57. package/errors/NetworkErrorEvent.js.map +1 -0
  58. package/errors/abstractions.d.ts +12 -0
  59. package/errors/abstractions.js +5 -0
  60. package/errors/abstractions.js.map +1 -0
  61. package/errors/index.d.ts +6 -0
  62. package/errors/index.js +6 -0
  63. package/errors/index.js.map +1 -0
  64. package/exports/admin/envConfig.d.ts +1 -0
  65. package/exports/admin/envConfig.js +3 -0
  66. package/exports/admin/envConfig.js.map +1 -0
  67. package/exports/admin/graphqlClient.d.ts +1 -0
  68. package/exports/admin/graphqlClient.js +3 -0
  69. package/exports/admin/graphqlClient.js.map +1 -0
  70. package/exports/admin/localStorage.d.ts +2 -0
  71. package/exports/admin/localStorage.js +4 -0
  72. package/exports/admin/localStorage.js.map +1 -0
  73. package/exports/admin/router.d.ts +4 -0
  74. package/exports/admin/router.js +6 -0
  75. package/exports/admin/router.js.map +1 -0
  76. package/exports/admin/security.d.ts +1 -0
  77. package/exports/admin/security.js +3 -0
  78. package/exports/admin/security.js.map +1 -0
  79. package/exports/admin.d.ts +6 -0
  80. package/exports/admin.js +8 -0
  81. package/exports/admin.js.map +1 -0
  82. package/features/envConfig/EnvConfig.d.ts +6 -0
  83. package/features/envConfig/EnvConfig.js +14 -0
  84. package/features/envConfig/EnvConfig.js.map +1 -0
  85. package/features/envConfig/abstractions.d.ts +27 -0
  86. package/features/envConfig/abstractions.js +4 -0
  87. package/features/envConfig/abstractions.js.map +1 -0
  88. package/features/envConfig/feature.d.ts +17 -0
  89. package/features/envConfig/feature.js +14 -0
  90. package/features/envConfig/feature.js.map +1 -0
  91. package/features/envConfig/index.d.ts +1 -0
  92. package/features/envConfig/index.js +3 -0
  93. package/features/envConfig/index.js.map +1 -0
  94. package/features/eventPublisher/EventPublisher.d.ts +8 -0
  95. package/features/eventPublisher/EventPublisher.js +27 -0
  96. package/features/eventPublisher/EventPublisher.js.map +1 -0
  97. package/features/eventPublisher/abstractions.d.ts +18 -0
  98. package/features/eventPublisher/abstractions.js +14 -0
  99. package/features/eventPublisher/abstractions.js.map +1 -0
  100. package/features/eventPublisher/feature.d.ts +1 -0
  101. package/features/eventPublisher/feature.js +11 -0
  102. package/features/eventPublisher/feature.js.map +1 -0
  103. package/features/eventPublisher/index.d.ts +3 -0
  104. package/features/eventPublisher/index.js +4 -0
  105. package/features/eventPublisher/index.js.map +1 -0
  106. package/features/graphqlClient/AuthenticationErrorPublishing.d.ts +13 -0
  107. package/features/graphqlClient/AuthenticationErrorPublishing.js +35 -0
  108. package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -0
  109. package/features/graphqlClient/BatchingGraphQLClient.d.ts +18 -0
  110. package/features/graphqlClient/BatchingGraphQLClient.js +164 -0
  111. package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -0
  112. package/features/graphqlClient/FetchGraphQLClient.d.ts +10 -0
  113. package/features/graphqlClient/FetchGraphQLClient.js +62 -0
  114. package/features/graphqlClient/FetchGraphQLClient.js.map +1 -0
  115. package/features/graphqlClient/NetworkErrorPublishing.d.ts +14 -0
  116. package/features/graphqlClient/NetworkErrorPublishing.js +55 -0
  117. package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -0
  118. package/features/graphqlClient/RequestValue.d.ts +20 -0
  119. package/features/graphqlClient/RequestValue.js +42 -0
  120. package/features/graphqlClient/RequestValue.js.map +1 -0
  121. package/features/graphqlClient/RetryGraphQLClient.d.ts +18 -0
  122. package/features/graphqlClient/RetryGraphQLClient.js +54 -0
  123. package/features/graphqlClient/RetryGraphQLClient.js.map +1 -0
  124. package/features/graphqlClient/__tests__/GraphQLClient.test.d.ts +1 -0
  125. package/features/graphqlClient/__tests__/GraphQLClient.test.js +350 -0
  126. package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -0
  127. package/features/graphqlClient/abstractions.d.ts +17 -0
  128. package/features/graphqlClient/abstractions.js +4 -0
  129. package/features/graphqlClient/abstractions.js.map +1 -0
  130. package/features/graphqlClient/feature.d.ts +6 -0
  131. package/features/graphqlClient/feature.js +31 -0
  132. package/features/graphqlClient/feature.js.map +1 -0
  133. package/features/graphqlClient/index.d.ts +1 -0
  134. package/features/graphqlClient/index.js +3 -0
  135. package/features/graphqlClient/index.js.map +1 -0
  136. package/features/graphqlClient/types.d.ts +5 -0
  137. package/features/graphqlClient/types.js +3 -0
  138. package/features/graphqlClient/types.js.map +1 -0
  139. package/features/localStorage/BrowserLocalStorageGateway.d.ts +9 -0
  140. package/features/localStorage/BrowserLocalStorageGateway.js +68 -0
  141. package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -0
  142. package/features/localStorage/LocalStorage.d.ts +12 -0
  143. package/features/localStorage/LocalStorage.js +31 -0
  144. package/features/localStorage/LocalStorage.js.map +1 -0
  145. package/features/localStorage/LocalStorageRepository.d.ts +20 -0
  146. package/features/localStorage/LocalStorageRepository.js +95 -0
  147. package/features/localStorage/LocalStorageRepository.js.map +1 -0
  148. package/features/localStorage/abstractions.d.ts +48 -0
  149. package/features/localStorage/abstractions.js +19 -0
  150. package/features/localStorage/abstractions.js.map +1 -0
  151. package/features/localStorage/feature.d.ts +12 -0
  152. package/features/localStorage/feature.js +34 -0
  153. package/features/localStorage/feature.js.map +1 -0
  154. package/features/localStorage/index.d.ts +1 -0
  155. package/features/localStorage/index.js +3 -0
  156. package/features/localStorage/index.js.map +1 -0
  157. package/features/router/HistoryRouterGateway.d.ts +18 -0
  158. package/features/router/HistoryRouterGateway.js +82 -0
  159. package/features/router/HistoryRouterGateway.js.map +1 -0
  160. package/features/router/HistoryRouterGateway.test.d.ts +1 -0
  161. package/features/router/HistoryRouterGateway.test.js +204 -0
  162. package/features/router/HistoryRouterGateway.test.js.map +1 -0
  163. package/features/router/Route.d.ts +19 -0
  164. package/features/router/Route.js +59 -0
  165. package/features/router/Route.js.map +1 -0
  166. package/features/router/RouteUrl.d.ts +85 -0
  167. package/features/router/RouteUrl.js +232 -0
  168. package/features/router/RouteUrl.js.map +1 -0
  169. package/features/router/Router.d.ts +45 -0
  170. package/features/router/Router.js +129 -0
  171. package/features/router/Router.js.map +1 -0
  172. package/features/router/RouterPresenter.d.ts +17 -0
  173. package/features/router/RouterPresenter.js +45 -0
  174. package/features/router/RouterPresenter.js.map +1 -0
  175. package/features/router/RouterRepository.d.ts +21 -0
  176. package/features/router/RouterRepository.js +71 -0
  177. package/features/router/RouterRepository.js.map +1 -0
  178. package/features/router/RouterRepository.test.d.ts +1 -0
  179. package/features/router/RouterRepository.test.js +154 -0
  180. package/features/router/RouterRepository.test.js.map +1 -0
  181. package/features/router/abstractions.d.ts +68 -0
  182. package/features/router/abstractions.js +15 -0
  183. package/features/router/abstractions.js.map +1 -0
  184. package/features/router/feature.d.ts +4 -0
  185. package/features/router/feature.js +18 -0
  186. package/features/router/feature.js.map +1 -0
  187. package/features/router/index.d.ts +1 -0
  188. package/features/router/index.js +3 -0
  189. package/features/router/index.js.map +1 -0
  190. package/helpers/InterfaceGenerator/date.d.ts +15 -0
  191. package/helpers/InterfaceGenerator/date.js +3 -0
  192. package/helpers/InterfaceGenerator/date.js.map +1 -0
  193. package/helpers/InterfaceGenerator/id.d.ts +23 -0
  194. package/helpers/InterfaceGenerator/id.js +3 -0
  195. package/helpers/InterfaceGenerator/id.js.map +1 -0
  196. package/helpers/InterfaceGenerator/identity.d.ts +10 -0
  197. package/helpers/InterfaceGenerator/identity.js +3 -0
  198. package/helpers/InterfaceGenerator/identity.js.map +1 -0
  199. package/helpers/InterfaceGenerator/index.d.ts +5 -0
  200. package/helpers/InterfaceGenerator/index.js +3 -0
  201. package/helpers/InterfaceGenerator/index.js.map +1 -0
  202. package/helpers/InterfaceGenerator/numeric.d.ts +12 -0
  203. package/helpers/InterfaceGenerator/numeric.js +3 -0
  204. package/helpers/InterfaceGenerator/numeric.js.map +1 -0
  205. package/helpers/InterfaceGenerator/truthful.d.ts +7 -0
  206. package/helpers/InterfaceGenerator/truthful.js +3 -0
  207. package/helpers/InterfaceGenerator/truthful.js.map +1 -0
  208. package/hooks/useAutocomplete/index.d.ts +1 -1
  209. package/hooks/useAutocomplete/index.js +1 -12
  210. package/hooks/useAutocomplete/index.js.map +1 -1
  211. package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
  212. package/hooks/useAutocomplete/useAutocomplete.js +6 -16
  213. package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
  214. package/hooks/useDataList/functions/getData.js +2 -11
  215. package/hooks/useDataList/functions/getData.js.map +1 -1
  216. package/hooks/useDataList/functions/getError.js +2 -11
  217. package/hooks/useDataList/functions/getError.js.map +1 -1
  218. package/hooks/useDataList/functions/getMeta.js +2 -11
  219. package/hooks/useDataList/functions/getMeta.js.map +1 -1
  220. package/hooks/useDataList/functions/index.d.ts +3 -3
  221. package/hooks/useDataList/functions/index.js +3 -27
  222. package/hooks/useDataList/functions/index.js.map +1 -1
  223. package/hooks/useDataList/functions/searchDataByKey.js +4 -10
  224. package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
  225. package/hooks/useDataList/index.d.ts +1 -1
  226. package/hooks/useDataList/index.js +1 -12
  227. package/hooks/useDataList/index.js.map +1 -1
  228. package/hooks/useDataList/useDataList.d.ts +2 -3
  229. package/hooks/useDataList/useDataList.js +74 -94
  230. package/hooks/useDataList/useDataList.js.map +1 -1
  231. package/hooks/useDataList/utils/index.d.ts +1 -2
  232. package/hooks/useDataList/utils/index.js +1 -20
  233. package/hooks/useDataList/utils/index.js.map +1 -1
  234. package/hooks/useDataList/utils/prepareLoadListParams.js +10 -16
  235. package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
  236. package/hooks/useHandler.js +7 -12
  237. package/hooks/useHandler.js.map +1 -1
  238. package/hooks/useHandlers.d.ts +3 -3
  239. package/hooks/useHandlers.js +11 -17
  240. package/hooks/useHandlers.js.map +1 -1
  241. package/hooks/useRegisterLegacyPlugin.d.ts +2 -0
  242. package/hooks/useRegisterLegacyPlugin.js +11 -0
  243. package/hooks/useRegisterLegacyPlugin.js.map +1 -0
  244. package/hooks/useUi.d.ts +1 -1
  245. package/hooks/useUi.js +4 -10
  246. package/hooks/useUi.js.map +1 -1
  247. package/i18n/i18n.js +5 -13
  248. package/i18n/i18n.js.map +1 -1
  249. package/i18n/index.d.ts +1 -1
  250. package/i18n/index.js +1 -13
  251. package/i18n/index.js.map +1 -1
  252. package/index.d.ts +23 -14
  253. package/index.js +25 -165
  254. package/index.js.map +1 -1
  255. package/package.json +26 -29
  256. package/plugins/AddQuerySelectionPlugin.d.ts +2 -2
  257. package/plugins/AddQuerySelectionPlugin.js +61 -107
  258. package/plugins/AddQuerySelectionPlugin.js.map +1 -1
  259. package/plugins/ApolloCacheObjectIdPlugin.js +12 -31
  260. package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
  261. package/plugins/ApolloDynamicLink.d.ts +3 -2
  262. package/plugins/ApolloDynamicLink.js +19 -46
  263. package/plugins/ApolloDynamicLink.js.map +1 -1
  264. package/plugins/ApolloLinkPlugin.d.ts +1 -1
  265. package/plugins/ApolloLinkPlugin.js +18 -37
  266. package/plugins/ApolloLinkPlugin.js.map +1 -1
  267. package/plugins/ConsoleLinkPlugin.d.ts +1 -1
  268. package/plugins/ConsoleLinkPlugin.js +20 -41
  269. package/plugins/ConsoleLinkPlugin.js.map +1 -1
  270. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +8 -13
  271. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +35 -58
  272. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
  273. package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.d.ts +14 -0
  274. package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +31 -0
  275. package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -0
  276. package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.d.ts +2 -0
  277. package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +31 -0
  278. package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -0
  279. package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +4 -5
  280. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -12
  281. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
  282. package/plugins/NetworkErrorLinkPlugin/Typography.d.ts +8 -0
  283. package/plugins/NetworkErrorLinkPlugin/Typography.js +18 -0
  284. package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -0
  285. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +3 -3
  286. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +10 -20
  287. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
  288. package/plugins/NetworkErrorLinkPlugin.d.ts +4 -1
  289. package/plugins/NetworkErrorLinkPlugin.js +60 -37
  290. package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
  291. package/plugins/OmitTypenameLinkPlugin.d.ts +1 -1
  292. package/plugins/OmitTypenameLinkPlugin.js +11 -30
  293. package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
  294. package/plugins/TenantHeaderLinkPlugin.d.ts +3 -3
  295. package/plugins/TenantHeaderLinkPlugin.js +29 -48
  296. package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
  297. package/plugins/components/Image.d.ts +6 -0
  298. package/plugins/components/Image.js +19 -0
  299. package/plugins/components/Image.js.map +1 -0
  300. package/plugins/image.d.ts +1 -1
  301. package/plugins/image.js +46 -53
  302. package/plugins/image.js.map +1 -1
  303. package/plugins/index.d.ts +5 -5
  304. package/plugins/index.js +31 -53
  305. package/plugins/index.js.map +1 -1
  306. package/presentation/localStorage/index.d.ts +3 -0
  307. package/presentation/localStorage/index.js +5 -0
  308. package/presentation/localStorage/index.js.map +1 -0
  309. package/presentation/localStorage/useLocalStorage.d.ts +6 -0
  310. package/presentation/localStorage/useLocalStorage.js +21 -0
  311. package/presentation/localStorage/useLocalStorage.js.map +1 -0
  312. package/presentation/localStorage/useLocalStorageValue.d.ts +1 -0
  313. package/presentation/localStorage/useLocalStorageValue.js +20 -0
  314. package/presentation/localStorage/useLocalStorageValue.js.map +1 -0
  315. package/presentation/localStorage/useLocalStorageValues.d.ts +5 -0
  316. package/presentation/localStorage/useLocalStorageValues.js +39 -0
  317. package/presentation/localStorage/useLocalStorageValues.js.map +1 -0
  318. package/presentation/router/RouteElementRegistry.d.ts +14 -0
  319. package/presentation/router/RouteElementRegistry.js +32 -0
  320. package/presentation/router/RouteElementRegistry.js.map +1 -0
  321. package/presentation/router/abstractions.d.ts +13 -0
  322. package/presentation/router/abstractions.js +4 -0
  323. package/presentation/router/abstractions.js.map +1 -0
  324. package/presentation/router/components/RouteContent.d.ts +2 -0
  325. package/presentation/router/components/RouteContent.js +17 -0
  326. package/presentation/router/components/RouteContent.js.map +1 -0
  327. package/presentation/router/components/RouteLink.d.ts +50 -0
  328. package/presentation/router/components/RouteLink.js +22 -0
  329. package/presentation/router/components/RouteLink.js.map +1 -0
  330. package/presentation/router/components/SimpleLink.d.ts +44 -0
  331. package/presentation/router/components/SimpleLink.js +30 -0
  332. package/presentation/router/components/SimpleLink.js.map +1 -0
  333. package/presentation/router/hooks/useRoute.d.ts +6 -0
  334. package/presentation/router/hooks/useRoute.js +30 -0
  335. package/presentation/router/hooks/useRoute.js.map +1 -0
  336. package/presentation/router/hooks/useRouter.d.ts +7 -0
  337. package/presentation/router/hooks/useRouter.js +26 -0
  338. package/presentation/router/hooks/useRouter.js.map +1 -0
  339. package/presentation/router/index.d.ts +4 -0
  340. package/presentation/router/index.js +5 -0
  341. package/presentation/router/index.js.map +1 -0
  342. package/presentation/router/types.d.ts +5 -0
  343. package/presentation/router/types.js +3 -0
  344. package/presentation/router/types.js.map +1 -0
  345. package/react-butterfiles/Files.d.ts +69 -0
  346. package/react-butterfiles/Files.js +227 -0
  347. package/react-butterfiles/Files.js.map +1 -0
  348. package/react-butterfiles/file.todo +1 -0
  349. package/react-butterfiles/index.d.ts +2 -0
  350. package/react-butterfiles/index.js +4 -0
  351. package/react-butterfiles/index.js.map +1 -0
  352. package/react-butterfiles/utils/generateId.d.ts +1 -0
  353. package/react-butterfiles/utils/generateId.js +5 -0
  354. package/react-butterfiles/utils/generateId.js.map +1 -0
  355. package/react-butterfiles/utils/readFileContent.d.ts +1 -0
  356. package/react-butterfiles/utils/readFileContent.js +15 -0
  357. package/react-butterfiles/utils/readFileContent.js.map +1 -0
  358. package/renderApp.d.ts +1 -1
  359. package/renderApp.js +4 -11
  360. package/renderApp.js.map +1 -1
  361. package/router.d.ts +5 -0
  362. package/router.js +8 -0
  363. package/router.js.map +1 -0
  364. package/shared/di/DiContainerProvider.d.ts +8 -0
  365. package/shared/di/DiContainerProvider.js +17 -0
  366. package/shared/di/DiContainerProvider.js.map +1 -0
  367. package/shared/di/createFeature.d.ts +11 -0
  368. package/shared/di/createFeature.js +11 -0
  369. package/shared/di/createFeature.js.map +1 -0
  370. package/shared/di/useFeature.d.ts +2 -0
  371. package/shared/di/useFeature.js +18 -0
  372. package/shared/di/useFeature.js.map +1 -0
  373. package/types.d.ts +16 -13
  374. package/types.js +1 -12
  375. package/types.js.map +1 -1
  376. package/utils/createGenericContext.d.ts +13 -0
  377. package/utils/createGenericContext.js +25 -0
  378. package/utils/createGenericContext.js.map +1 -0
  379. package/utils/createHashing.d.ts +2 -0
  380. package/utils/createHashing.js +18 -0
  381. package/utils/createHashing.js.map +1 -0
  382. package/utils/index.d.ts +2 -8
  383. package/utils/index.js +2 -93
  384. package/utils/index.js.map +1 -1
  385. package/utils/legacyPluginToReactComponent.d.ts +7 -0
  386. package/utils/legacyPluginToReactComponent.js +14 -0
  387. package/utils/legacyPluginToReactComponent.js.map +1 -0
  388. package/components/Routes.d.ts +0 -2
  389. package/components/Routes.js +0 -46
  390. package/components/Routes.js.map +0 -1
  391. package/components/View.d.ts +0 -8
  392. package/components/View.js +0 -31
  393. package/components/View.js.map +0 -1
  394. package/core/AddRoute.d.ts +0 -17
  395. package/core/AddRoute.js +0 -21
  396. package/core/AddRoute.js.map +0 -1
  397. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +0 -14
  398. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +0 -30
  399. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +0 -1
  400. package/hooks/useDataList/utils/types.d.ts +0 -40
  401. package/hooks/useDataList/utils/types.js +0 -7
  402. package/hooks/useDataList/utils/types.js.map +0 -1
  403. package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -10
  404. package/plugins/LocaleHeaderLinkPlugin.js +0 -49
  405. package/plugins/LocaleHeaderLinkPlugin.js.map +0 -1
  406. package/plugins/RoutePlugin.d.ts +0 -12
  407. package/plugins/RoutePlugin.js +0 -35
  408. package/plugins/RoutePlugin.js.map +0 -1
  409. package/plugins/ViewPlugin.d.ts +0 -14
  410. package/plugins/ViewPlugin.js +0 -40
  411. package/plugins/ViewPlugin.js.map +0 -1
  412. package/utils/getApiUrl.d.ts +0 -1
  413. package/utils/getApiUrl.js +0 -12
  414. package/utils/getApiUrl.js.map +0 -1
  415. package/utils/getGqlApiUrl.d.ts +0 -1
  416. package/utils/getGqlApiUrl.js +0 -12
  417. package/utils/getGqlApiUrl.js.map +0 -1
  418. package/utils/getHeadlessCmsGqlApiUrl.d.ts +0 -5
  419. package/utils/getHeadlessCmsGqlApiUrl.js +0 -18
  420. package/utils/getHeadlessCmsGqlApiUrl.js.map +0 -1
  421. package/utils/getLocaleCode.d.ts +0 -6
  422. package/utils/getLocaleCode.js +0 -43
  423. package/utils/getLocaleCode.js.map +0 -1
  424. package/utils/getPrerenderId.d.ts +0 -6
  425. package/utils/getPrerenderId.js +0 -11
  426. package/utils/getPrerenderId.js.map +0 -1
  427. package/utils/getTenantId.d.ts +0 -6
  428. package/utils/getTenantId.js +0 -35
  429. package/utils/getTenantId.js.map +0 -1
  430. package/utils/isLocalhost.d.ts +0 -1
  431. package/utils/isLocalhost.js +0 -15
  432. package/utils/isLocalhost.js.map +0 -1
  433. package/utils/isPrerendering.d.ts +0 -1
  434. package/utils/isPrerendering.js +0 -11
  435. package/utils/isPrerendering.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["RouteUrl","patternCache","Map","constructor","pattern","params","baseUrl","normalizeBaseUrl","fromPattern","routeUrl","generate","match","pathname","undefined","matchPathname","pathKeys","extractPathKeys","url","replacePathParams","queryString","buildQueryString","startsWith","slice","length","compiled","get","compilePattern","set","regex","keys","forEach","key","index","value","decodeURIComponent","Set","paramRegex","exec","add","replace","_","encodeURIComponent","String","queryParams","has","Object","searchParams","URLSearchParams","Array","isArray","v","append","toString","normalized","endsWith","regexPattern","push","RegExp"],"sources":["RouteUrl.ts"],"sourcesContent":["interface Params {\n [key: string]: any;\n}\n\ninterface MatchResult {\n params: Record<string, string>;\n}\n\n/**\n * Utility class for route URL pattern matching and generation.\n * Handles simple route patterns with :param syntax (e.g., /cms/entries/:modelId).\n *\n * Public API uses static methods, which internally construct RouteUrl instances\n * to handle the logic through proper instance methods.\n */\nexport class RouteUrl {\n private static patternCache = new Map<string, { regex: RegExp; keys: string[] }>();\n\n private readonly pattern: string;\n private readonly params: Params | undefined;\n private readonly baseUrl: string;\n\n private constructor(pattern: string, params?: Params, baseUrl?: string) {\n this.pattern = pattern;\n this.params = params;\n this.baseUrl = this.normalizeBaseUrl(baseUrl);\n }\n\n /**\n * Generate a URL from a route pattern and parameters.\n * Path parameters are injected into the pattern, remaining parameters become query strings.\n *\n * @param pattern - Route pattern (e.g., '/security/api-keys/:id')\n * @param params - Parameters object (e.g., { id: 123, new: true })\n * @param baseUrl - Optional base URL to prepend (e.g., '/tenant123')\n * @returns Generated URL string\n *\n * @example\n * RouteUrl.fromPattern('/security/api-keys/:id', { id: 123, new: true })\n * // Returns: '/security/api-keys/123?new=true'\n *\n * @example\n * RouteUrl.fromPattern('/file-manager', {}, '/tenant123')\n * // Returns: '/tenant123/file-manager'\n */\n static fromPattern(pattern: string, params?: Params, baseUrl?: string): string {\n const routeUrl = new RouteUrl(pattern, params, baseUrl);\n return routeUrl.generate();\n }\n\n /**\n * Match a pathname against a route pattern and extract parameters.\n * If baseUrl is provided, it will be stripped from the pathname before matching.\n *\n * @param pathname - The pathname to match (e.g., '/tenant123/security/api-keys/123')\n * @param pattern - Route pattern (e.g., '/security/api-keys/:id')\n * @param baseUrl - Optional base URL to strip before matching (e.g., '/tenant123')\n * @returns Object with extracted params if matched, null otherwise\n *\n * @example\n * RouteUrl.match('/security/api-keys/123', '/security/api-keys/:id')\n * // Returns: { params: { id: '123' } }\n *\n * @example\n * RouteUrl.match('/tenant123/file-manager', '/file-manager', '/tenant123')\n * // Returns: { params: {} }\n */\n static match(pathname: string, pattern: string, baseUrl?: string): MatchResult | null {\n const routeUrl = new RouteUrl(pattern, undefined, baseUrl);\n return routeUrl.matchPathname(pathname);\n }\n\n /**\n * Generate a URL from the instance's pattern, params, and baseUrl.\n */\n private generate(): string {\n if (!this.params) {\n return this.baseUrl + this.pattern;\n }\n\n // Extract path parameter names from pattern\n const pathKeys = this.extractPathKeys();\n\n // Replace :param with actual values\n let url = this.replacePathParams();\n\n // Handle empty url\n if (!url || url === \"\") {\n url = \"/\";\n }\n\n // Prepend baseUrl\n url = this.baseUrl + url;\n\n // Add query parameters for keys not used in the path\n const queryString = this.buildQueryString(pathKeys);\n if (queryString) {\n url += `?${queryString}`;\n }\n\n return url;\n }\n\n /**\n * Match a pathname against the instance's pattern.\n */\n private matchPathname(pathname: string): MatchResult | null {\n // Strip baseUrl from pathname if provided\n if (this.baseUrl && pathname.startsWith(this.baseUrl)) {\n pathname = pathname.slice(this.baseUrl.length) || \"/\";\n } else if (this.baseUrl) {\n // pathname doesn't start with baseUrl, no match\n return null;\n }\n\n // Handle wildcard pattern\n if (this.pattern === \"*\" || this.pattern === \"(.*)\") {\n return { params: {} };\n }\n\n // Get or create cached pattern\n let compiled = RouteUrl.patternCache.get(this.pattern);\n if (!compiled) {\n compiled = this.compilePattern();\n RouteUrl.patternCache.set(this.pattern, compiled);\n }\n\n const match = pathname.match(compiled.regex);\n if (!match) {\n return null;\n }\n\n // Extract parameters from capture groups\n const params: Record<string, string> = {};\n compiled.keys.forEach((key, index) => {\n const value = match[index + 1];\n if (value !== undefined) {\n params[key] = decodeURIComponent(value);\n }\n });\n\n return { params };\n }\n\n /**\n * Extract path parameter names from the pattern.\n */\n private extractPathKeys(): Set<string> {\n const pathKeys = new Set<string>();\n const paramRegex = /:([a-zA-Z_][a-zA-Z0-9_]*)/g;\n let match;\n while ((match = paramRegex.exec(this.pattern)) !== null) {\n pathKeys.add(match[1]);\n }\n return pathKeys;\n }\n\n /**\n * Replace :param placeholders with actual values from params.\n */\n private replacePathParams(): string {\n return this.pattern.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, key) => {\n const value = this.params![key];\n if (value === undefined || value === null) {\n return \"\";\n }\n return encodeURIComponent(String(value));\n });\n }\n\n /**\n * Build query string from params that are not path parameters.\n */\n private buildQueryString(pathKeys: Set<string>): string {\n const queryParams: Record<string, any> = {};\n\n for (const key in this.params) {\n if (!pathKeys.has(key)) {\n queryParams[key] = this.params[key];\n }\n }\n\n if (Object.keys(queryParams).length === 0) {\n return \"\";\n }\n\n const searchParams = new URLSearchParams();\n\n for (const key in queryParams) {\n const value = queryParams[key];\n if (value !== undefined && value !== null) {\n if (Array.isArray(value)) {\n value.forEach(v => searchParams.append(key, String(v)));\n } else {\n searchParams.append(key, String(value));\n }\n }\n }\n\n return searchParams.toString();\n }\n\n /**\n * Normalize baseUrl by ensuring it starts with / and doesn't end with /\n */\n private normalizeBaseUrl(baseUrl?: string): string {\n if (!baseUrl || baseUrl === \"/\") {\n return \"\";\n }\n\n let normalized = baseUrl;\n\n // Ensure it starts with /\n if (!normalized.startsWith(\"/\")) {\n normalized = \"/\" + normalized;\n }\n\n // Remove trailing /\n if (normalized.endsWith(\"/\")) {\n normalized = normalized.slice(0, -1);\n }\n\n return normalized;\n }\n\n /**\n * Compile the instance's pattern into a regex and extract parameter names.\n */\n private compilePattern(): { regex: RegExp; keys: string[] } {\n const keys: string[] = [];\n\n // Escape special regex characters except for :param syntax\n let regexPattern = this.pattern\n .replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\") // Escape special chars\n .replace(/\\\\\\*/g, \".*\"); // Handle * wildcard (already escaped by above)\n\n // Replace :param with capture groups\n regexPattern = regexPattern.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, key) => {\n keys.push(key);\n return \"([^/]+)\"; // Match any non-slash characters\n });\n\n // Create regex that matches the entire pathname\n const regex = new RegExp(`^${regexPattern}$`);\n\n return { regex, keys };\n }\n}\n"],"mappings":"AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,CAAC;EAClB,OAAeC,YAAY,GAAG,IAAIC,GAAG,CAA4C,CAAC;EAM1EC,WAAWA,CAACC,OAAe,EAAEC,MAAe,EAAEC,OAAgB,EAAE;IACpE,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,OAAO,GAAG,IAAI,CAACC,gBAAgB,CAACD,OAAO,CAAC;EACjD;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACI,OAAO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H,KAAK,GAAG,IAAI6B,MAAM,CAAC,IAAIF,YAAY,GAAG,CAAC;IAE7C,OAAO;MAAE3B,KAAK;MAAEC;IAAK,CAAC;EAC1B;AACJ","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ import type { RouteDefinition, MatchedRoute } from "./abstractions.js";
2
+ interface ResolveResult {
3
+ matchedRoute: MatchedRoute;
4
+ onMatch: (route: MatchedRoute) => void;
5
+ }
6
+ /**
7
+ * Router manages a collection of route definitions and resolves pathnames to matched routes.
8
+ */
9
+ export declare class Router {
10
+ private routes;
11
+ private baseUrl;
12
+ constructor(baseUrl?: string);
13
+ /**
14
+ * Set or update route definitions. Routes with the same name will be replaced.
15
+ *
16
+ * @param routes - Array of route definitions to add
17
+ */
18
+ setRoutes(routes: RouteDefinition[]): void;
19
+ /**
20
+ * Find a route by name.
21
+ *
22
+ * @param name - Route name to find
23
+ * @returns Route definition if found, undefined otherwise
24
+ */
25
+ findRoute(name: string): RouteDefinition | undefined;
26
+ /**
27
+ * Resolve a pathname to a matched route.
28
+ * The pathname will be matched against patterns after stripping the baseUrl.
29
+ *
30
+ * @param pathname - The pathname to resolve (e.g., '/tenant123/cms/entries/123')
31
+ * @param queryParams - Optional query parameters to merge into route params
32
+ * @returns Matched route with onMatch callback, or null if no route matches
33
+ */
34
+ resolve(pathname: string, queryParams?: Record<string, unknown>): ResolveResult | null;
35
+ /**
36
+ * Get the current baseUrl.
37
+ */
38
+ getBaseUrl(): string;
39
+ /**
40
+ * Sort routes to ensure proper matching order.
41
+ * Wildcard routes (*) and index routes (/) are moved to the bottom.
42
+ */
43
+ private sortRoutes;
44
+ }
45
+ export {};
@@ -0,0 +1,129 @@
1
+ import { RouteUrl } from "./RouteUrl.js";
2
+ /**
3
+ * Router manages a collection of route definitions and resolves pathnames to matched routes.
4
+ */
5
+ export class Router {
6
+ routes = [];
7
+ constructor(baseUrl = "") {
8
+ this.baseUrl = baseUrl;
9
+ }
10
+
11
+ /**
12
+ * Set or update route definitions. Routes with the same name will be replaced.
13
+ *
14
+ * @param routes - Array of route definitions to add
15
+ */
16
+ setRoutes(routes) {
17
+ routes.forEach(route => {
18
+ const index = this.routes.findIndex(r => r.name === route.name);
19
+ if (index > -1) {
20
+ this.routes[index] = route;
21
+ } else {
22
+ this.routes.push(route);
23
+ }
24
+ });
25
+ this.sortRoutes();
26
+ }
27
+
28
+ /**
29
+ * Find a route by name.
30
+ *
31
+ * @param name - Route name to find
32
+ * @returns Route definition if found, undefined otherwise
33
+ */
34
+ findRoute(name) {
35
+ return this.routes.find(r => r.name === name);
36
+ }
37
+
38
+ /**
39
+ * Resolve a pathname to a matched route.
40
+ * The pathname will be matched against patterns after stripping the baseUrl.
41
+ *
42
+ * @param pathname - The pathname to resolve (e.g., '/tenant123/cms/entries/123')
43
+ * @param queryParams - Optional query parameters to merge into route params
44
+ * @returns Matched route with onMatch callback, or null if no route matches
45
+ */
46
+ resolve(pathname, queryParams) {
47
+ for (const route of this.routes) {
48
+ const pattern = route.path === "*" ? "(.*)" : route.path;
49
+ const matchResult = RouteUrl.match(pathname, pattern, this.baseUrl);
50
+ if (matchResult) {
51
+ const matchedRoute = {
52
+ name: route.name,
53
+ path: route.path,
54
+ pathname,
55
+ params: {
56
+ ...matchResult.params,
57
+ ...(queryParams || {})
58
+ }
59
+ };
60
+ const onMatch = matched => {
61
+ route.onMatch(matched);
62
+ };
63
+ return {
64
+ matchedRoute,
65
+ onMatch
66
+ };
67
+ }
68
+ }
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Get the current baseUrl.
74
+ */
75
+ getBaseUrl() {
76
+ return this.baseUrl;
77
+ }
78
+
79
+ /**
80
+ * Sort routes to ensure proper matching order.
81
+ * Wildcard routes (*) and index routes (/) are moved to the bottom.
82
+ */
83
+ sortRoutes() {
84
+ const INDEX_PATH = "/";
85
+ const WILDCARD_PATTERNS = ["*", "(.*)"];
86
+ this.routes.sort((a, b) => {
87
+ const pathA = a.path || "*";
88
+ const pathB = b.path || "*";
89
+ const isWildcardA = WILDCARD_PATTERNS.includes(pathA);
90
+ const isWildcardB = WILDCARD_PATTERNS.includes(pathB);
91
+ const isIndexA = pathA === INDEX_PATH;
92
+ const isIndexB = pathB === INDEX_PATH;
93
+
94
+ // Both are wildcards or both are index - maintain order
95
+ if (isWildcardA && isWildcardB || isIndexA && isIndexB) {
96
+ return 0;
97
+ }
98
+
99
+ // Index path should come before wildcard
100
+ if (isIndexA && isWildcardB) {
101
+ return -1;
102
+ }
103
+ if (isWildcardA && isIndexB) {
104
+ return 1;
105
+ }
106
+
107
+ // Push wildcards to the bottom
108
+ if (isWildcardA) {
109
+ return 1;
110
+ }
111
+ if (isWildcardB) {
112
+ return -1;
113
+ }
114
+
115
+ // Push index to the bottom (but above wildcards)
116
+ if (isIndexA) {
117
+ return 1;
118
+ }
119
+ if (isIndexB) {
120
+ return -1;
121
+ }
122
+
123
+ // All other routes maintain their order
124
+ return 0;
125
+ });
126
+ }
127
+ }
128
+
129
+ //# sourceMappingURL=Router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["RouteUrl","Router","routes","constructor","baseUrl","setRoutes","forEach","route","index","findIndex","r","name","push","sortRoutes","findRoute","find","resolve","pathname","queryParams","pattern","path","matchResult","match","matchedRoute","params","onMatch","matched","getBaseUrl","INDEX_PATH","WILDCARD_PATTERNS","sort","a","b","pathA","pathB","isWildcardA","includes","isWildcardB","isIndexA","isIndexB"],"sources":["Router.ts"],"sourcesContent":["import type { RouteDefinition, MatchedRoute } from \"./abstractions.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\ninterface ResolveResult {\n matchedRoute: MatchedRoute;\n onMatch: (route: MatchedRoute) => void;\n}\n\n/**\n * Router manages a collection of route definitions and resolves pathnames to matched routes.\n */\nexport class Router {\n private routes: RouteDefinition[] = [];\n private baseUrl: string;\n\n constructor(baseUrl: string = \"\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Set or update route definitions. Routes with the same name will be replaced.\n *\n * @param routes - Array of route definitions to add\n */\n setRoutes(routes: RouteDefinition[]): void {\n routes.forEach(route => {\n const index = this.routes.findIndex(r => r.name === route.name);\n\n if (index > -1) {\n this.routes[index] = route;\n } else {\n this.routes.push(route);\n }\n });\n\n this.sortRoutes();\n }\n\n /**\n * Find a route by name.\n *\n * @param name - Route name to find\n * @returns Route definition if found, undefined otherwise\n */\n findRoute(name: string): RouteDefinition | undefined {\n return this.routes.find(r => r.name === name);\n }\n\n /**\n * Resolve a pathname to a matched route.\n * The pathname will be matched against patterns after stripping the baseUrl.\n *\n * @param pathname - The pathname to resolve (e.g., '/tenant123/cms/entries/123')\n * @param queryParams - Optional query parameters to merge into route params\n * @returns Matched route with onMatch callback, or null if no route matches\n */\n resolve(pathname: string, queryParams?: Record<string, unknown>): ResolveResult | null {\n for (const route of this.routes) {\n const pattern = route.path === \"*\" ? \"(.*)\" : route.path;\n const matchResult = RouteUrl.match(pathname, pattern, this.baseUrl);\n\n if (matchResult) {\n const matchedRoute: MatchedRoute = {\n name: route.name,\n path: route.path,\n pathname,\n params: { ...matchResult.params, ...(queryParams || {}) }\n };\n\n const onMatch = (matched: MatchedRoute) => {\n route.onMatch(matched);\n };\n\n return { matchedRoute, onMatch };\n }\n }\n\n return null;\n }\n\n /**\n * Get the current baseUrl.\n */\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n /**\n * Sort routes to ensure proper matching order.\n * Wildcard routes (*) and index routes (/) are moved to the bottom.\n */\n private sortRoutes(): void {\n const INDEX_PATH = \"/\";\n const WILDCARD_PATTERNS = [\"*\", \"(.*)\"];\n\n this.routes.sort((a, b) => {\n const pathA = a.path || \"*\";\n const pathB = b.path || \"*\";\n\n const isWildcardA = WILDCARD_PATTERNS.includes(pathA);\n const isWildcardB = WILDCARD_PATTERNS.includes(pathB);\n const isIndexA = pathA === INDEX_PATH;\n const isIndexB = pathB === INDEX_PATH;\n\n // Both are wildcards or both are index - maintain order\n if ((isWildcardA && isWildcardB) || (isIndexA && isIndexB)) {\n return 0;\n }\n\n // Index path should come before wildcard\n if (isIndexA && isWildcardB) {\n return -1;\n }\n if (isWildcardA && isIndexB) {\n return 1;\n }\n\n // Push wildcards to the bottom\n if (isWildcardA) {\n return 1;\n }\n if (isWildcardB) {\n return -1;\n }\n\n // Push index to the bottom (but above wildcards)\n if (isIndexA) {\n return 1;\n }\n if (isIndexB) {\n return -1;\n }\n\n // All other routes maintain their order\n return 0;\n });\n }\n}\n"],"mappings":"AACA,SAASA,QAAQ;AAOjB;AACA;AACA;AACA,OAAO,MAAMC,MAAM,CAAC;EACRC,MAAM,GAAsB,EAAE;EAGtCC,WAAWA,CAACC,OAAe,GAAG,EAAE,EAAE;IAC9B,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;;EAEA;AACJ;AACA;AACA;AACA;EACIC,SAASA,CAACH,MAAyB,EAAQ;IACvCA,MAAM,CAACI,OAAO,CAACC,KAAK,IAAI;MACpB,MAAMC,KAAK,GAAG,IAAI,CAACN,MAAM,CAACO,SAAS,CAACC,CAAC,IAAIA,CAAC,CAACC,IAAI,KAAKJ,KAAK,CAACI,IAAI,CAAC;MAE/D,IAAIH,KAAK,GAAG,CAAC,CAAC,EAAE;QACZ,IAAI,CAACN,MAAM,CAACM,KAAK,CAAC,GAAGD,KAAK;MAC9B,CAAC,MAAM;QACH,IAAI,CAACL,MAAM,CAACU,IAAI,CAACL,KAAK,CAAC;MAC3B;IACJ,CAAC,CAAC;IAEF,IAAI,CAACM,UAAU,CAAC,CAAC;EACrB;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACIC,SAASA,CAACH,IAAY,EAA+B;IACjD,OAAO,IAAI,CAACT,MAAM,CAACa,IAAI,CAACL,CAAC,IAAIA,CAAC,CAACC,IAAI,KAAKA,IAAI,CAAC;EACjD;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIK,OAAOA,CAACC,QAAgB,EAAEC,WAAqC,EAAwB;IACnF,KAAK,MAAMX,KAAK,IAAI,IAAI,CAACL,MAAM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MACrC,MAAMW,QAAQ,GAAGL,KAAK,KAAKN,UAAU;;MAErC;MACA,IAAKO,WAAW,IAAIE,WAAW,IAAMC,QAAQ,IAAIC,QAAS,EAAE;QACxD,OAAO,CAAC;MACZ;;MAEA;MACA,IAAID,QAAQ,IAAID,WAAW,EAAE;QACzB,OAAO,CAAC,CAAC;MACb;MACA,IAAIF,WAAW,IAAII,QAAQ,EAAE;QACzB,OAAO,CAAC;MACZ;;MAEA;MACA,IAAIJ,WAAW,EAAE;QACb,OAAO,CAAC;MACZ;MACA,IAAIE,WAAW,EAAE;QACb,OAAO,CAAC,CAAC;MACb;;MAEA;MACA,IAAIC,QAAQ,EAAE;QACV,OAAO,CAAC;MACZ;MACA,IAAIC,QAAQ,EAAE;QACV,OAAO,CAAC,CAAC;MACb;;MAEA;MACA,OAAO,CAAC;IACZ,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import { Route } from "./Route.js";
2
+ import { RouterRepository, RouterPresenter as Abstraction, type OnRouteExit } from "./abstractions.js";
3
+ declare class RouterPresenterImpl implements Abstraction.Interface {
4
+ private routerRepository;
5
+ constructor(routerRepository: RouterRepository.Interface);
6
+ get vm(): {
7
+ currentRoute: import("./abstractions.js").MatchedRoute<Record<string, any>> | undefined;
8
+ };
9
+ bootstrap: (routes: Route[]) => void;
10
+ goToRoute: (route: any, params?: any) => void;
11
+ setRouteParams: (cb: any) => void;
12
+ getLink: (route: any, params?: any) => string;
13
+ onRouteExit: (cb: OnRouteExit) => void;
14
+ destroy: () => void;
15
+ }
16
+ export declare const RouterPresenter: import("@webiny/di").Implementation<typeof RouterPresenterImpl>;
17
+ export {};
@@ -0,0 +1,45 @@
1
+ import { makeAutoObservable, toJS } from "mobx";
2
+ import { createImplementation } from "@webiny/di";
3
+ import { RouterRepository, RouterPresenter as Abstraction } from "./abstractions.js";
4
+ class RouterPresenterImpl {
5
+ constructor(routerRepository) {
6
+ this.routerRepository = routerRepository;
7
+ makeAutoObservable(this);
8
+ }
9
+ get vm() {
10
+ return {
11
+ currentRoute: toJS(this.routerRepository.getMatchedRoute())
12
+ };
13
+ }
14
+ bootstrap = routes => {
15
+ this.routerRepository.registerRoutes(routes);
16
+ };
17
+ goToRoute = (route, params) => {
18
+ this.routerRepository.goToRoute(route, params);
19
+ };
20
+ setRouteParams = cb => {
21
+ const currentRoute = this.routerRepository.getCurrentRoute();
22
+ if (!currentRoute) {
23
+ return;
24
+ }
25
+ const matchedRoute = this.routerRepository.getMatchedRoute();
26
+ const newParams = cb(matchedRoute?.params ?? {});
27
+ this.goToRoute(currentRoute, newParams);
28
+ };
29
+ getLink = (route, params) => {
30
+ return this.routerRepository.getLink(route, params);
31
+ };
32
+ onRouteExit = cb => {
33
+ this.routerRepository.onRouteExit(cb);
34
+ };
35
+ destroy = () => {
36
+ this.routerRepository.destroy();
37
+ };
38
+ }
39
+ export const RouterPresenter = createImplementation({
40
+ abstraction: Abstraction,
41
+ implementation: RouterPresenterImpl,
42
+ dependencies: [RouterRepository]
43
+ });
44
+
45
+ //# sourceMappingURL=RouterPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","toJS","createImplementation","RouterRepository","RouterPresenter","Abstraction","RouterPresenterImpl","constructor","routerRepository","vm","currentRoute","getMatchedRoute","bootstrap","routes","registerRoutes","goToRoute","route","params","setRouteParams","cb","getCurrentRoute","matchedRoute","newParams","getLink","onRouteExit","destroy","abstraction","implementation","dependencies"],"sources":["RouterPresenter.ts"],"sourcesContent":["import { makeAutoObservable, toJS } from \"mobx\";\nimport { createImplementation } from \"@webiny/di\";\nimport { Route } from \"./Route.js\";\nimport {\n RouterRepository,\n RouterPresenter as Abstraction,\n type OnRouteExit\n} from \"./abstractions.js\";\n\nclass RouterPresenterImpl implements Abstraction.Interface {\n private routerRepository: RouterRepository.Interface;\n\n constructor(routerRepository: RouterRepository.Interface) {\n this.routerRepository = routerRepository;\n\n makeAutoObservable(this);\n }\n\n get vm() {\n return {\n currentRoute: toJS(this.routerRepository.getMatchedRoute())\n };\n }\n\n bootstrap = (routes: Route[]) => {\n this.routerRepository.registerRoutes(routes);\n };\n\n goToRoute = (route: any, params?: any) => {\n this.routerRepository.goToRoute(route, params);\n };\n\n setRouteParams = (cb: any) => {\n const currentRoute = this.routerRepository.getCurrentRoute();\n if (!currentRoute) {\n return;\n }\n\n const matchedRoute = this.routerRepository.getMatchedRoute();\n const newParams = cb(matchedRoute?.params ?? {});\n this.goToRoute(currentRoute, newParams);\n };\n\n getLink = (route: any, params?: any) => {\n return this.routerRepository.getLink(route, params);\n };\n\n onRouteExit = (cb: OnRouteExit) => {\n this.routerRepository.onRouteExit(cb);\n };\n\n destroy = () => {\n this.routerRepository.destroy();\n };\n}\n\nexport const RouterPresenter = createImplementation({\n abstraction: Abstraction,\n implementation: RouterPresenterImpl,\n dependencies: [RouterRepository]\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,IAAI,QAAQ,MAAM;AAC/C,SAASC,oBAAoB,QAAQ,YAAY;AAEjD,SACIC,gBAAgB,EAChBC,eAAe,IAAIC,WAAW;AAIlC,MAAMC,mBAAmB,CAAkC;EAGvDC,WAAWA,CAACC,gBAA4C,EAAE;IACtD,IAAI,CAACA,gBAAgB,GAAGA,gBAAgB;IAExCR,kBAAkB,CAAC,IAAI,CAAC;EAC5B;EAEA,IAAIS,EAAEA,CAAA,EAAG;IACL,OAAO;MACHC,YAAY,EAAET,IAAI,CAAC,IAAI,CAACO,gBAAgB,CAACG,eAAe,CAAC,CAAC;IAC9D,CAAC;EACL;EAEAC,SAAS,GAAIC,MAAe,IAAK;IAC7B,IAAI,CAACL,gBAAgB,CAACM,cAAc,CAACD,MAAM,CAAC;EAChD,CAAC;EAEDE,SAAS,GAAGA,CAACC,KAAU,EAAEC,MAAY,KAAK;IACtC,IAAI,CAACT,gBAAgB,CAACO,SAAS,CAACC,KAAK,EAAEC,MAAM,CAAC;EAClD,CAAC;EAEDC,cAAc,GAAIC,EAAO,IAAK;IAC1B,MAAMT,YAAY,GAAG,IAAI,CAACF,gBAAgB,CAACY,eAAe,CAAC,CAAC;IAC5D,IAAI,CAACV,YAAY,EAAE;MACf;IACJ;IAEA,MAAMW,YAAY,GAAG,IAAI,CAACb,gBAAgB,CAACG,eAAe,CAAC,CAAC;IAC5D,MAAMW,SAAS,GAAGH,EAAE,CAACE,YAAY,EAAEJ,MAAM,IAAI,CAAC,CAAC,CAAC;IAChD,IAAI,CAACF,SAAS,CAACL,YAAY,EAAEY,SAAS,CAAC;EAC3C,CAAC;EAEDC,OAAO,GAAGA,CAACP,KAAU,EAAEC,MAAY,KAAK;IACpC,OAAO,IAAI,CAACT,gBAAgB,CAACe,OAAO,CAACP,KAAK,EAAEC,MAAM,CAAC;EACvD,CAAC;EAEDO,WAAW,GAAIL,EAAe,IAAK;IAC/B,IAAI,CAACX,gBAAgB,CAACgB,WAAW,CAACL,EAAE,CAAC;EACzC,CAAC;EAEDM,OAAO,GAAGA,CAAA,KAAM;IACZ,IAAI,CAACjB,gBAAgB,CAACiB,OAAO,CAAC,CAAC;EACnC,CAAC;AACL;AAEA,OAAO,MAAMrB,eAAe,GAAGF,oBAAoB,CAAC;EAChDwB,WAAW,EAAErB,WAAW;EACxBsB,cAAc,EAAErB,mBAAmB;EACnCsB,YAAY,EAAE,CAACzB,gBAAgB;AACnC,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ import type { MatchedRoute, OnRouteExit } from "./abstractions.js";
2
+ import * as Abstractions from "./abstractions.js";
3
+ import { Route, RouteParamsDefinition, RouteParamsInfer } from "./Route.js";
4
+ declare class RouterRepositoryImpl implements Abstractions.RouterRepository.Interface {
5
+ private gateway;
6
+ private currentRoute;
7
+ private routes;
8
+ constructor(gateway: Abstractions.RouterGateway.Interface);
9
+ getMatchedRoute(): MatchedRoute<Record<string, any>> | undefined;
10
+ getCurrentRoute(): Route<any> | undefined;
11
+ registerRoutes: (routes: Route[]) => void;
12
+ getLink<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, params?: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined): string;
13
+ goToRoute<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, params: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined): void;
14
+ onRouteExit(cb: OnRouteExit): void;
15
+ destroy(): void;
16
+ private routeWithAction;
17
+ private transitionToRoute;
18
+ private getRouteByName;
19
+ }
20
+ export declare const RouterRepository: import("@webiny/di").Implementation<typeof RouterRepositoryImpl>;
21
+ export {};
@@ -0,0 +1,71 @@
1
+ import { makeAutoObservable, runInAction } from "mobx";
2
+ import * as Abstractions from "./abstractions.js";
3
+ import { createImplementation } from "@webiny/di";
4
+ import { RouteUrl } from "./RouteUrl.js";
5
+ const INIT_ROUTE = {
6
+ name: "__init__",
7
+ path: "",
8
+ pathname: "",
9
+ params: {}
10
+ };
11
+ class RouterRepositoryImpl {
12
+ currentRoute = INIT_ROUTE;
13
+ routes = [];
14
+ constructor(gateway) {
15
+ this.gateway = gateway;
16
+ makeAutoObservable(this);
17
+ }
18
+ getMatchedRoute() {
19
+ return this.currentRoute.name !== INIT_ROUTE.name ? this.currentRoute : undefined;
20
+ }
21
+ getCurrentRoute() {
22
+ return this.routes.find(route => route.name === this.currentRoute.name);
23
+ }
24
+ registerRoutes = routes => {
25
+ this.routes = routes;
26
+ const routesWithAction = routes.map(this.routeWithAction);
27
+ this.gateway.setRoutes(routesWithAction);
28
+ };
29
+ getLink(route, params) {
30
+ return RouteUrl.fromPattern(route.path, params);
31
+ }
32
+ goToRoute(route, params) {
33
+ this.gateway.goToRoute(route.name, params);
34
+ }
35
+ onRouteExit(cb) {
36
+ this.gateway.onRouteExit(cb);
37
+ }
38
+ destroy() {
39
+ this.gateway.destroy();
40
+ }
41
+ routeWithAction = route => {
42
+ return {
43
+ name: route.name,
44
+ path: route.path,
45
+ onMatch: this.transitionToRoute.bind(this)
46
+ };
47
+ };
48
+ async transitionToRoute(matchedRoute) {
49
+ const route = this.getRouteByName(matchedRoute.name);
50
+ if (!route) {
51
+ return;
52
+ }
53
+ const params = route.params ? route.params.parse(matchedRoute.params) : matchedRoute.params;
54
+ runInAction(() => {
55
+ Object.assign(this.currentRoute, {
56
+ ...matchedRoute,
57
+ params
58
+ });
59
+ });
60
+ }
61
+ getRouteByName(name) {
62
+ return this.routes.find(existingRoute => existingRoute.name === name);
63
+ }
64
+ }
65
+ export const RouterRepository = createImplementation({
66
+ implementation: RouterRepositoryImpl,
67
+ abstraction: Abstractions.RouterRepository,
68
+ dependencies: [Abstractions.RouterGateway]
69
+ });
70
+
71
+ //# sourceMappingURL=RouterRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["makeAutoObservable","runInAction","Abstractions","createImplementation","RouteUrl","INIT_ROUTE","name","path","pathname","params","RouterRepositoryImpl","currentRoute","routes","constructor","gateway","getMatchedRoute","undefined","getCurrentRoute","find","route","registerRoutes","routesWithAction","map","routeWithAction","setRoutes","getLink","fromPattern","goToRoute","onRouteExit","cb","destroy","onMatch","transitionToRoute","bind","matchedRoute","getRouteByName","parse","Object","assign","existingRoute","RouterRepository","implementation","abstraction","dependencies","RouterGateway"],"sources":["RouterRepository.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport type { MatchedRoute, RouteDefinition, OnRouteExit } from \"./abstractions.js\";\nimport * as Abstractions from \"./abstractions.js\";\nimport { Route, RouteParamsDefinition, RouteParamsInfer } from \"./Route.js\";\nimport { createImplementation } from \"@webiny/di\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\nconst INIT_ROUTE = { name: \"__init__\", path: \"\", pathname: \"\", params: {} };\n\nclass RouterRepositoryImpl implements Abstractions.RouterRepository.Interface {\n private gateway: Abstractions.RouterGateway.Interface;\n private currentRoute: MatchedRoute = INIT_ROUTE;\n private routes: Route<any>[] = [];\n\n constructor(gateway: Abstractions.RouterGateway.Interface) {\n this.gateway = gateway;\n\n makeAutoObservable(this);\n }\n\n getMatchedRoute() {\n return this.currentRoute.name !== INIT_ROUTE.name ? this.currentRoute : undefined;\n }\n\n getCurrentRoute(): Route<any> | undefined {\n return this.routes.find(route => route.name === this.currentRoute.name);\n }\n\n registerRoutes = (routes: Route[]) => {\n this.routes = routes;\n const routesWithAction = routes.map<RouteDefinition>(this.routeWithAction);\n\n this.gateway.setRoutes(routesWithAction);\n };\n\n getLink<TParams extends RouteParamsDefinition | undefined>(\n route: Route<TParams>,\n params?: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined\n ): string {\n return RouteUrl.fromPattern(route.path, params);\n }\n\n goToRoute<TParams extends RouteParamsDefinition | undefined>(\n route: Route<TParams>,\n params: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined\n ): void {\n this.gateway.goToRoute(route.name, params);\n }\n\n onRouteExit(cb: OnRouteExit): void {\n this.gateway.onRouteExit(cb);\n }\n\n destroy() {\n this.gateway.destroy();\n }\n\n private routeWithAction = (route: Route<any>) => {\n return {\n name: route.name,\n path: route.path,\n onMatch: this.transitionToRoute.bind(this)\n };\n };\n\n private async transitionToRoute(matchedRoute: MatchedRoute) {\n const route = this.getRouteByName(matchedRoute.name);\n if (!route) {\n return;\n }\n\n const params = route.params ? route.params.parse(matchedRoute.params) : matchedRoute.params;\n\n runInAction(() => {\n Object.assign(this.currentRoute, {\n ...matchedRoute,\n params\n });\n });\n }\n\n private getRouteByName(name: string) {\n return this.routes.find(existingRoute => existingRoute.name === name);\n }\n}\n\nexport const RouterRepository = createImplementation({\n implementation: RouterRepositoryImpl,\n abstraction: Abstractions.RouterRepository,\n dependencies: [Abstractions.RouterGateway]\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,WAAW,QAAQ,MAAM;AAEtD,OAAO,KAAKC,YAAY;AAExB,SAASC,oBAAoB,QAAQ,YAAY;AACjD,SAASC,QAAQ;AAEjB,MAAMC,UAAU,GAAG;EAAEC,IAAI,EAAE,UAAU;EAAEC,IAAI,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EAEQP,eAAe,GAAIJ,KAAiB,IAAK;IAC7C,OAAO;MACHb,IAAI,EAAEa,KAAK,CAACb,IAAI;MAChBC,IAAI,EAAEY,KAAK,CAACZ,IAAI;MAChBwB,OAAO,EAAE,IAAI,CAACC,iBAAiB,CAACC,IAAI,CAAC,IAAI;IAC7C,CAAC;EACL,CAAC;EAED,MAAcD,iBAAiBA,CAACE,YAA0B,EAAE;IACxD,MAAMf,KAAK,GAAG,IAAI,CAACgB,cAAc,CAACD,YAAY,CAAC5B,IAAI,CAAC;IACpD,IAAI,CAACa,KAAK,EAAE;MACR;IACJ;IAEA,MAAMV,MAAM,GAAGU,KAAK,CAACV,MAAM,GAAGU,KAAK,CAACV,MAAM,CAAC2B,KAAK,CAACF,YAAY,CAACzB,MAAM,CAAC,GAAGyB,YAAY,CAACzB,MAAM;IAE3FR,WAAW,CAAC,MAAM;MACdoC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC3B,YAAY,EAAE;QAC7B,GAAGuB,YAAY;QACfzB;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN;EAEQ0B,cAAcA,CAAC7B,IAAY,EAAE;IACjC,OAAO,IAAI,CAACM,MAAM,CAACM,IAAI,CAACqB,aAAa,IAAIA,aAAa,CAACjC,IAAI,KAAKA,IAAI,CAAC;EACzE;AACJ;AAEA,OAAO,MAAMkC,gBAAgB,GAAGrC,oBAAoB,CAAC;EACjDsC,cAAc,EAAE/B,oBAAoB;EACpCgC,WAAW,EAAExC,YAAY,CAACsC,gBAAgB;EAC1CG,YAAY,EAAE,CAACzC,YAAY,CAAC0C,aAAa;AAC7C,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,154 @@
1
+ import { describe, it, beforeEach, expect, vi } from "vitest";
2
+ import { createMemoryHistory } from "history";
3
+ import { HistoryRouterGateway } from "./HistoryRouterGateway.js";
4
+ import { RouterRepository } from "./RouterRepository.js";
5
+ import { Route } from "./Route.js";
6
+ const wait = () => new Promise(resolve => setTimeout(resolve, 10));
7
+ const loginRouteDef = new Route({
8
+ name: "login",
9
+ path: "/login"
10
+ });
11
+ const userRouteDef = new Route({
12
+ name: "userById",
13
+ path: "/users/:id",
14
+ params: zod => {
15
+ return {
16
+ id: zod.string()
17
+ };
18
+ }
19
+ });
20
+ const allRoutes = [new Route({
21
+ name: "home",
22
+ path: "/"
23
+ }), loginRouteDef, userRouteDef];
24
+ const loginRoute = {
25
+ name: "login",
26
+ path: "/login",
27
+ pathname: "/login",
28
+ params: {}
29
+ };
30
+ const userRoute = id => {
31
+ return {
32
+ name: "userById",
33
+ path: "/users/:id",
34
+ pathname: `/users/${id}`,
35
+ params: {
36
+ id
37
+ }
38
+ };
39
+ };
40
+ const createRepository = (routes = allRoutes) => {
41
+ const history = createMemoryHistory();
42
+ history.replace("/__unknown__");
43
+ const gateway = new HistoryRouterGateway(history, "");
44
+ const repository = new RouterRepository(gateway);
45
+ repository.registerRoutes(routes);
46
+ return {
47
+ repository,
48
+ history
49
+ };
50
+ };
51
+ describe("Router Repository", () => {
52
+ beforeEach(() => {
53
+ vi.clearAllMocks();
54
+ });
55
+ it("state should contain current route", async () => {
56
+ const {
57
+ repository,
58
+ history
59
+ } = createRepository();
60
+ history.push("/login");
61
+ await wait();
62
+ expect(repository.getMatchedRoute()).toEqual(loginRoute);
63
+ });
64
+ it("route guard should allow or prevent route transition", async () => {
65
+ const {
66
+ repository,
67
+ history
68
+ } = createRepository();
69
+ history.push("/login");
70
+ await wait();
71
+
72
+ // This guard should prevent the transition.
73
+ // The Repository should stay where it was, and the `history` should restore the previous URL.
74
+ repository.onRouteExit(({
75
+ cancel
76
+ }) => {
77
+ cancel();
78
+ });
79
+
80
+ // Trigger a history location change (imagine a click on "Back" button in the browser).
81
+ history.push("/users/123");
82
+ await wait();
83
+ expect(repository.getMatchedRoute()).toEqual(loginRoute);
84
+
85
+ // This guard should allow the transition.
86
+ repository.onRouteExit(guard => {
87
+ guard.continue();
88
+ });
89
+
90
+ // Trigger a history location change (imagine a click on "Back" button in the browser).
91
+ history.push("/users/123");
92
+ await wait();
93
+ expect(repository.getMatchedRoute()).toEqual(userRoute("123"));
94
+ });
95
+ it("route guard should be unset after route transition", async () => {
96
+ const guardSpy = vi.fn();
97
+ const {
98
+ repository,
99
+ history
100
+ } = createRepository();
101
+ history.push("/login");
102
+ await wait();
103
+
104
+ // This guard should prevent the transition.
105
+ // The Repository should stay where it was, and the `history` should restore the previous URL.
106
+ repository.onRouteExit(guard => {
107
+ guardSpy();
108
+ guard.continue();
109
+ });
110
+
111
+ // Trigger a history location change (imagine a click on "Back" button in the browser).
112
+ history.push("/users/123");
113
+ await wait();
114
+ expect(repository.getMatchedRoute()).toEqual(userRoute("123"));
115
+ expect(guardSpy).toHaveBeenCalledTimes(1);
116
+ vi.resetAllMocks();
117
+
118
+ // Trigger a history location change (imagine a click on "Back" button in the browser).
119
+ history.push("/login");
120
+ await wait();
121
+ expect(repository.getMatchedRoute()).toEqual(loginRoute);
122
+ expect(guardSpy).toHaveBeenCalledTimes(0);
123
+ });
124
+ it("should go to the right route", async () => {
125
+ const {
126
+ repository
127
+ } = createRepository();
128
+ repository.goToRoute(userRouteDef, {
129
+ id: "5"
130
+ });
131
+ await wait();
132
+ expect(repository.getMatchedRoute()).toEqual(userRoute("5"));
133
+ });
134
+ it("should generate a valid route link", async () => {
135
+ const {
136
+ repository
137
+ } = createRepository();
138
+ expect(repository.getLink(loginRouteDef)).toEqual("/login");
139
+ expect(repository.getLink(userRouteDef, {
140
+ id: "1"
141
+ })).toEqual("/users/1");
142
+ });
143
+ it("should generate a valid route link when no routes are registered", async () => {
144
+ const {
145
+ repository
146
+ } = createRepository([]);
147
+ expect(repository.getLink(loginRouteDef)).toEqual("/login");
148
+ expect(repository.getLink(userRouteDef, {
149
+ id: "1"
150
+ })).toEqual("/users/1");
151
+ });
152
+ });
153
+
154
+ //# sourceMappingURL=RouterRepository.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["describe","it","beforeEach","expect","vi","createMemoryHistory","HistoryRouterGateway","RouterRepository","Route","wait","Promise","resolve","setTimeout","loginRouteDef","name","path","userRouteDef","params","zod","id","string","allRoutes","loginRoute","pathname","userRoute","createRepository","routes","history","replace","gateway","repository","registerRoutes","clearAllMocks","push","getMatchedRoute","toEqual","onRouteExit","cancel","guard","continue","guardSpy","fn","toHaveBeenCalledTimes","resetAllMocks","goToRoute","getLink"],"sources":["RouterRepository.test.ts"],"sourcesContent":["import { describe, it, beforeEach, expect, vi } from \"vitest\";\nimport { createMemoryHistory } from \"history\";\nimport { HistoryRouterGateway } from \"./HistoryRouterGateway.js\";\nimport { RouterRepository } from \"./RouterRepository.js\";\nimport { Route } from \"./Route.js\";\n\nconst wait = () => new Promise(resolve => setTimeout(resolve, 10));\n\nconst loginRouteDef = new Route({ name: \"login\", path: \"/login\" });\n\nconst userRouteDef = new Route({\n name: \"userById\",\n path: \"/users/:id\",\n params: zod => {\n return {\n id: zod.string()\n };\n }\n});\n\nconst allRoutes: Route<any>[] = [\n new Route({ name: \"home\", path: \"/\" }),\n loginRouteDef,\n userRouteDef\n];\n\nconst loginRoute = {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n};\n\nconst userRoute = (id: string) => {\n return {\n name: \"userById\",\n path: \"/users/:id\",\n pathname: `/users/${id}`,\n params: {\n id\n }\n };\n};\n\nconst createRepository = (routes = allRoutes) => {\n const history = createMemoryHistory();\n history.replace(\"/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n const repository = new RouterRepository(gateway);\n\n repository.registerRoutes(routes);\n\n return { repository, history };\n};\n\ndescribe(\"Router Repository\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"state should contain current route\", async () => {\n const { repository, history } = createRepository();\n history.push(\"/login\");\n await wait();\n\n expect(repository.getMatchedRoute()).toEqual(loginRoute);\n });\n\n it(\"route guard should allow or prevent route transition\", async () => {\n const { repository, history } = createRepository();\n history.push(\"/login\");\n await wait();\n\n // This guard should prevent the transition.\n // The Repository should stay where it was, and the `history` should restore the previous URL.\n repository.onRouteExit(({ cancel }) => {\n cancel();\n });\n\n // Trigger a history location change (imagine a click on \"Back\" button in the browser).\n history.push(\"/users/123\");\n await wait();\n\n expect(repository.getMatchedRoute()).toEqual(loginRoute);\n\n // This guard should allow the transition.\n repository.onRouteExit(guard => {\n guard.continue();\n });\n\n // Trigger a history location change (imagine a click on \"Back\" button in the browser).\n history.push(\"/users/123\");\n await wait();\n\n expect(repository.getMatchedRoute()).toEqual(userRoute(\"123\"));\n });\n\n it(\"route guard should be unset after route transition\", async () => {\n const guardSpy = vi.fn();\n const { repository, history } = createRepository();\n history.push(\"/login\");\n await wait();\n\n // This guard should prevent the transition.\n // The Repository should stay where it was, and the `history` should restore the previous URL.\n repository.onRouteExit(guard => {\n guardSpy();\n guard.continue();\n });\n\n // Trigger a history location change (imagine a click on \"Back\" button in the browser).\n history.push(\"/users/123\");\n await wait();\n\n expect(repository.getMatchedRoute()).toEqual(userRoute(\"123\"));\n expect(guardSpy).toHaveBeenCalledTimes(1);\n vi.resetAllMocks();\n\n // Trigger a history location change (imagine a click on \"Back\" button in the browser).\n history.push(\"/login\");\n await wait();\n\n expect(repository.getMatchedRoute()).toEqual(loginRoute);\n expect(guardSpy).toHaveBeenCalledTimes(0);\n });\n\n it(\"should go to the right route\", async () => {\n const { repository } = createRepository();\n repository.goToRoute(userRouteDef, { id: \"5\" });\n await wait();\n expect(repository.getMatchedRoute()).toEqual(userRoute(\"5\"));\n });\n\n it(\"should generate a valid route link\", async () => {\n const { repository } = createRepository();\n\n expect(repository.getLink(loginRouteDef)).toEqual(\"/login\");\n expect(repository.getLink(userRouteDef, { id: \"1\" })).toEqual(\"/users/1\");\n });\n\n it(\"should generate a valid route link when no routes are registered\", async () => {\n const { repository } = createRepository([]);\n\n expect(repository.getLink(loginRouteDef)).toEqual(\"/login\");\n expect(repository.getLink(userRouteDef, { id: \"1\" })).toEqual(\"/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AE,CAAC,8BAA8B,EAAE,YAAY;IAC3C,MAAM;MAAE6B;IAAW,CAAC,GAAGL,gBAAgB,CAAC,CAAC;IACzCK,UAAU,CAACc,SAAS,CAAC5B,YAAY,EAAE;MAAEG,EAAE,EAAE;IAAI,CAAC,CAAC;IAC/C,MAAMV,IAAI,CAAC,CAAC;IACZN,MAAM,CAAC2B,UAAU,CAACI,eAAe,CAAC,CAAC,CAAC,CAACC,OAAO,CAACX,SAAS,CAAC,GAAG,CAAC,CAAC;EAChE,CAAC,CAAC;EAEFvB,EAAE,CAAC,oCAAoC,EAAE,YAAY;IACjD,MAAM;MAAE6B;IAAW,CAAC,GAAGL,gBAAgB,CAAC,CAAC;IAEzCtB,MAAM,CAAC2B,UAAU,CAACe,OAAO,CAAChC,aAAa,CAAC,CAAC,CAACsB,OAAO,CAAC,QAAQ,CAAC;IAC3DhC,MAAM,CAAC2B,UAAU,CAACe,OAAO,CAAC7B,YAAY,EAAE;MAAEG,EAAE,EAAE;IAAI,CAAC,CAAC,CAAC,CAACgB,OAAO,CAAC,UAAU,CAAC;EAC7E,CAAC,CAAC;EAEFlC,EAAE,CAAC,kEAAkE,EAAE,YAAY;IAC/E,MAAM;MAAE6B;IAAW,CAAC,GAAGL,gBAAgB,CAAC,EAAE,CAAC;IAE3CtB,MAAM,CAAC2B,UAAU,CAACe,OAAO,CAAChC,aAAa,CAAC,CAAC,CAACsB,OAAO,CAAC,QAAQ,CAAC;IAC3DhC,MAAM,CAAC2B,UAAU,CAACe,OAAO,CAAC7B,YAAY,EAAE;MAAEG,EAAE,EAAE;IAAI,CAAC,CAAC,CAAC,CAACgB,OAAO,CAAC,UAAU,CAAC;EAC7E,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,68 @@
1
+ import { Abstraction } from "@webiny/di";
2
+ import type { Route, RouteParamsDefinition, RouteParamsInfer } from "./Route.js";
3
+ import type { RequiredKeysOf } from "type-fest";
4
+ /***** Presenter *****/
5
+ export type RouteParamsArgs<TParams extends RouteParamsDefinition | undefined> = TParams extends RouteParamsDefinition ? RequiredKeysOf<RouteParamsInfer<TParams>> extends never ? [params?: RouteParamsInfer<TParams>] : [params: RouteParamsInfer<TParams>] : [];
6
+ interface RouterViewModel {
7
+ currentRoute: MatchedRoute | undefined;
8
+ }
9
+ export interface IRouterPresenter {
10
+ vm: RouterViewModel;
11
+ bootstrap(routes: Route[]): void;
12
+ goToRoute<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, ...args: RouteParamsArgs<TParams>): void;
13
+ getLink<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, ...args: RouteParamsArgs<TParams>): string;
14
+ setRouteParams<T extends Record<string, any>>(cb: (params: T) => T): void;
15
+ onRouteExit(cb: OnRouteExit): void;
16
+ destroy(): void;
17
+ }
18
+ export declare const RouterPresenter: Abstraction<IRouterPresenter>;
19
+ export declare namespace RouterPresenter {
20
+ type Interface = IRouterPresenter;
21
+ }
22
+ /***** Repository *****/
23
+ export interface MatchedRoute<TParams = Record<string, any>> {
24
+ name: string;
25
+ pathname: string;
26
+ path: string;
27
+ params: TParams;
28
+ }
29
+ interface IRouterRepository {
30
+ onRouteExit(cb: OnRouteExit): void;
31
+ getMatchedRoute(): MatchedRoute | undefined;
32
+ getCurrentRoute(): Route<any> | undefined;
33
+ goToRoute<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, params: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined): void;
34
+ getLink<TParams extends RouteParamsDefinition | undefined>(route: Route<TParams>, params: TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined): string;
35
+ registerRoutes(routes: Route[]): void;
36
+ destroy(): void;
37
+ }
38
+ export declare const RouterRepository: Abstraction<IRouterRepository>;
39
+ export declare namespace RouterRepository {
40
+ type Interface = IRouterRepository;
41
+ }
42
+ /***** Gateway *****/
43
+ export interface RouteDefinition {
44
+ name: string;
45
+ path: string;
46
+ onMatch(route: MatchedRoute): void;
47
+ }
48
+ export type TransitionController = {
49
+ continue: () => void;
50
+ cancel: () => void;
51
+ };
52
+ export interface OnRouteExit {
53
+ (controller: TransitionController): void;
54
+ }
55
+ interface IRouterGateway {
56
+ setRoutes(routes: RouteDefinition[]): void;
57
+ goToRoute(name: string, params?: {
58
+ [k: string]: any;
59
+ }): void;
60
+ pushState(url: string): void;
61
+ onRouteExit(cb: OnRouteExit): void;
62
+ destroy(): void;
63
+ }
64
+ export declare const RouterGateway: Abstraction<IRouterGateway>;
65
+ export declare namespace RouterGateway {
66
+ type Interface = IRouterGateway;
67
+ }
68
+ export {};