@webiny/app 5.44.1-beta.0 → 5.45.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.d.ts +5 -13
- package/App.js +70 -87
- package/App.js.map +1 -1
- package/AppContainer.d.ts +23 -0
- package/AppContainer.js +9 -0
- package/AppContainer.js.map +1 -0
- package/README.md +7 -15
- package/apollo-client/InMemoryCache.d.ts +3 -2
- package/apollo-client/InMemoryCache.js +16 -47
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.d.ts +2 -2
- package/apollo-client/IntrospectionFragmentMatcher.js +33 -50
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
- package/components/Image.d.ts +1 -2
- package/components/Image.js +11 -19
- package/components/Image.js.map +1 -1
- package/components/index.d.ts +1 -2
- package/components/index.js +1 -19
- package/components/index.js.map +1 -1
- package/config/RouterConfig/Route.d.ts +29 -0
- package/config/RouterConfig/Route.js +33 -0
- package/config/RouterConfig/Route.js.map +1 -0
- package/config/RouterConfig.d.ts +31 -0
- package/config/RouterConfig.js +18 -0
- package/config/RouterConfig.js.map +1 -0
- package/config.js +9 -15
- package/config.js.map +1 -1
- package/contexts/Ui/index.js +28 -52
- package/contexts/Ui/index.js.map +1 -1
- package/core/DebounceRender.js +13 -24
- package/core/DebounceRender.js.map +1 -1
- package/core/Plugin.d.ts +1 -1
- package/core/Plugin.js +11 -19
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.d.ts +1 -1
- package/core/Plugins.js +20 -25
- package/core/Plugins.js.map +1 -1
- package/core/Provider.d.ts +1 -1
- package/core/Provider.js +9 -13
- package/core/Provider.js.map +1 -1
- package/core/Routes.d.ts +2 -1
- package/core/Routes.js +13 -23
- package/core/Routes.js.map +1 -1
- package/core/createProvider.d.ts +2 -2
- package/core/createProvider.js +1 -7
- package/core/createProvider.js.map +1 -1
- package/core/createProviderPlugin.d.ts +1 -1
- package/core/createProviderPlugin.js +4 -10
- package/core/createProviderPlugin.js.map +1 -1
- package/errors/AuthenticationErrorEvent.d.ts +9 -0
- package/errors/AuthenticationErrorEvent.js +10 -0
- package/errors/AuthenticationErrorEvent.js.map +1 -0
- package/errors/NetworkErrorEvent.d.ts +15 -0
- package/errors/NetworkErrorEvent.js +10 -0
- package/errors/NetworkErrorEvent.js.map +1 -0
- package/errors/abstractions.d.ts +12 -0
- package/errors/abstractions.js +5 -0
- package/errors/abstractions.js.map +1 -0
- package/errors/index.d.ts +6 -0
- package/errors/index.js +6 -0
- package/errors/index.js.map +1 -0
- package/exports/admin/envConfig.d.ts +1 -0
- package/exports/admin/envConfig.js +3 -0
- package/exports/admin/envConfig.js.map +1 -0
- package/exports/admin/graphqlClient.d.ts +1 -0
- package/exports/admin/graphqlClient.js +3 -0
- package/exports/admin/graphqlClient.js.map +1 -0
- package/exports/admin/localStorage.d.ts +2 -0
- package/exports/admin/localStorage.js +4 -0
- package/exports/admin/localStorage.js.map +1 -0
- package/exports/admin/router.d.ts +4 -0
- package/exports/admin/router.js +6 -0
- package/exports/admin/router.js.map +1 -0
- package/exports/admin/security.d.ts +1 -0
- package/exports/admin/security.js +3 -0
- package/exports/admin/security.js.map +1 -0
- package/exports/admin.d.ts +6 -0
- package/exports/admin.js +8 -0
- package/exports/admin.js.map +1 -0
- package/features/envConfig/EnvConfig.d.ts +6 -0
- package/features/envConfig/EnvConfig.js +14 -0
- package/features/envConfig/EnvConfig.js.map +1 -0
- package/features/envConfig/abstractions.d.ts +27 -0
- package/features/envConfig/abstractions.js +4 -0
- package/features/envConfig/abstractions.js.map +1 -0
- package/features/envConfig/feature.d.ts +17 -0
- package/features/envConfig/feature.js +14 -0
- package/features/envConfig/feature.js.map +1 -0
- package/features/envConfig/index.d.ts +1 -0
- package/features/envConfig/index.js +3 -0
- package/features/envConfig/index.js.map +1 -0
- package/features/eventPublisher/EventPublisher.d.ts +8 -0
- package/features/eventPublisher/EventPublisher.js +27 -0
- package/features/eventPublisher/EventPublisher.js.map +1 -0
- package/features/eventPublisher/abstractions.d.ts +18 -0
- package/features/eventPublisher/abstractions.js +14 -0
- package/features/eventPublisher/abstractions.js.map +1 -0
- package/features/eventPublisher/feature.d.ts +1 -0
- package/features/eventPublisher/feature.js +11 -0
- package/features/eventPublisher/feature.js.map +1 -0
- package/features/eventPublisher/index.d.ts +3 -0
- package/features/eventPublisher/index.js +4 -0
- package/features/eventPublisher/index.js.map +1 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.d.ts +13 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js +35 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -0
- package/features/graphqlClient/BatchingGraphQLClient.d.ts +18 -0
- package/features/graphqlClient/BatchingGraphQLClient.js +164 -0
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -0
- package/features/graphqlClient/FetchGraphQLClient.d.ts +10 -0
- package/features/graphqlClient/FetchGraphQLClient.js +62 -0
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -0
- package/features/graphqlClient/NetworkErrorPublishing.d.ts +14 -0
- package/features/graphqlClient/NetworkErrorPublishing.js +55 -0
- package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -0
- package/features/graphqlClient/RequestValue.d.ts +20 -0
- package/features/graphqlClient/RequestValue.js +42 -0
- package/features/graphqlClient/RequestValue.js.map +1 -0
- package/features/graphqlClient/RetryGraphQLClient.d.ts +18 -0
- package/features/graphqlClient/RetryGraphQLClient.js +54 -0
- package/features/graphqlClient/RetryGraphQLClient.js.map +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.d.ts +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +350 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -0
- package/features/graphqlClient/abstractions.d.ts +17 -0
- package/features/graphqlClient/abstractions.js +4 -0
- package/features/graphqlClient/abstractions.js.map +1 -0
- package/features/graphqlClient/feature.d.ts +6 -0
- package/features/graphqlClient/feature.js +31 -0
- package/features/graphqlClient/feature.js.map +1 -0
- package/features/graphqlClient/index.d.ts +1 -0
- package/features/graphqlClient/index.js +3 -0
- package/features/graphqlClient/index.js.map +1 -0
- package/features/graphqlClient/types.d.ts +5 -0
- package/features/graphqlClient/types.js +3 -0
- package/features/graphqlClient/types.js.map +1 -0
- package/features/localStorage/BrowserLocalStorageGateway.d.ts +9 -0
- package/features/localStorage/BrowserLocalStorageGateway.js +68 -0
- package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -0
- package/features/localStorage/LocalStorage.d.ts +12 -0
- package/features/localStorage/LocalStorage.js +31 -0
- package/features/localStorage/LocalStorage.js.map +1 -0
- package/features/localStorage/LocalStorageRepository.d.ts +20 -0
- package/features/localStorage/LocalStorageRepository.js +95 -0
- package/features/localStorage/LocalStorageRepository.js.map +1 -0
- package/features/localStorage/abstractions.d.ts +48 -0
- package/features/localStorage/abstractions.js +19 -0
- package/features/localStorage/abstractions.js.map +1 -0
- package/features/localStorage/feature.d.ts +12 -0
- package/features/localStorage/feature.js +34 -0
- package/features/localStorage/feature.js.map +1 -0
- package/features/localStorage/index.d.ts +1 -0
- package/features/localStorage/index.js +3 -0
- package/features/localStorage/index.js.map +1 -0
- package/features/router/HistoryRouterGateway.d.ts +18 -0
- package/features/router/HistoryRouterGateway.js +82 -0
- package/features/router/HistoryRouterGateway.js.map +1 -0
- package/features/router/HistoryRouterGateway.test.d.ts +1 -0
- package/features/router/HistoryRouterGateway.test.js +204 -0
- package/features/router/HistoryRouterGateway.test.js.map +1 -0
- package/features/router/Route.d.ts +19 -0
- package/features/router/Route.js +59 -0
- package/features/router/Route.js.map +1 -0
- package/features/router/RouteUrl.d.ts +85 -0
- package/features/router/RouteUrl.js +232 -0
- package/features/router/RouteUrl.js.map +1 -0
- package/features/router/Router.d.ts +45 -0
- package/features/router/Router.js +129 -0
- package/features/router/Router.js.map +1 -0
- package/features/router/RouterPresenter.d.ts +17 -0
- package/features/router/RouterPresenter.js +45 -0
- package/features/router/RouterPresenter.js.map +1 -0
- package/features/router/RouterRepository.d.ts +21 -0
- package/features/router/RouterRepository.js +71 -0
- package/features/router/RouterRepository.js.map +1 -0
- package/features/router/RouterRepository.test.d.ts +1 -0
- package/features/router/RouterRepository.test.js +154 -0
- package/features/router/RouterRepository.test.js.map +1 -0
- package/features/router/abstractions.d.ts +68 -0
- package/features/router/abstractions.js +15 -0
- package/features/router/abstractions.js.map +1 -0
- package/features/router/feature.d.ts +4 -0
- package/features/router/feature.js +18 -0
- package/features/router/feature.js.map +1 -0
- package/features/router/index.d.ts +1 -0
- package/features/router/index.js +3 -0
- package/features/router/index.js.map +1 -0
- package/helpers/InterfaceGenerator/date.d.ts +15 -0
- package/helpers/InterfaceGenerator/date.js +3 -0
- package/helpers/InterfaceGenerator/date.js.map +1 -0
- package/helpers/InterfaceGenerator/id.d.ts +23 -0
- package/helpers/InterfaceGenerator/id.js +3 -0
- package/helpers/InterfaceGenerator/id.js.map +1 -0
- package/helpers/InterfaceGenerator/identity.d.ts +10 -0
- package/helpers/InterfaceGenerator/identity.js +3 -0
- package/helpers/InterfaceGenerator/identity.js.map +1 -0
- package/helpers/InterfaceGenerator/index.d.ts +5 -0
- package/helpers/InterfaceGenerator/index.js +3 -0
- package/helpers/InterfaceGenerator/index.js.map +1 -0
- package/helpers/InterfaceGenerator/numeric.d.ts +12 -0
- package/helpers/InterfaceGenerator/numeric.js +3 -0
- package/helpers/InterfaceGenerator/numeric.js.map +1 -0
- package/helpers/InterfaceGenerator/truthful.d.ts +7 -0
- package/helpers/InterfaceGenerator/truthful.js +3 -0
- package/helpers/InterfaceGenerator/truthful.js.map +1 -0
- package/hooks/useAutocomplete/index.d.ts +1 -1
- package/hooks/useAutocomplete/index.js +1 -12
- package/hooks/useAutocomplete/index.js.map +1 -1
- package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
- package/hooks/useAutocomplete/useAutocomplete.js +6 -16
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +2 -11
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +2 -11
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +2 -11
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.d.ts +3 -3
- package/hooks/useDataList/functions/index.js +3 -27
- package/hooks/useDataList/functions/index.js.map +1 -1
- package/hooks/useDataList/functions/searchDataByKey.js +4 -10
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.d.ts +1 -1
- package/hooks/useDataList/index.js +1 -12
- package/hooks/useDataList/index.js.map +1 -1
- package/hooks/useDataList/useDataList.d.ts +2 -3
- package/hooks/useDataList/useDataList.js +74 -94
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.d.ts +1 -2
- package/hooks/useDataList/utils/index.js +1 -20
- package/hooks/useDataList/utils/index.js.map +1 -1
- package/hooks/useDataList/utils/prepareLoadListParams.js +10 -16
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandler.js +7 -12
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.js +11 -17
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.d.ts +1 -1
- package/hooks/useRegisterLegacyPlugin.js +5 -11
- package/hooks/useRegisterLegacyPlugin.js.map +1 -1
- package/hooks/useUi.d.ts +1 -1
- package/hooks/useUi.js +4 -10
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +5 -13
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/i18n/index.js +1 -13
- package/i18n/index.js.map +1 -1
- package/index.d.ts +23 -15
- package/index.js +25 -177
- package/index.js.map +1 -1
- package/package.json +25 -22
- package/plugins/AddQuerySelectionPlugin.d.ts +2 -2
- package/plugins/AddQuerySelectionPlugin.js +61 -107
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +12 -31
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.d.ts +3 -2
- package/plugins/ApolloDynamicLink.js +19 -46
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.d.ts +1 -1
- package/plugins/ApolloLinkPlugin.js +18 -37
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.d.ts +1 -1
- package/plugins/ConsoleLinkPlugin.js +20 -41
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +8 -13
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +35 -58
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.d.ts +14 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +31 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.d.ts +2 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +31 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +4 -5
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -12
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/Typography.d.ts +8 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js +18 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +3 -3
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +10 -25
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.d.ts +4 -1
- package/plugins/NetworkErrorLinkPlugin.js +60 -37
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.d.ts +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +11 -30
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.d.ts +3 -3
- package/plugins/TenantHeaderLinkPlugin.js +29 -48
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/components/Image.d.ts +6 -0
- package/plugins/components/Image.js +19 -0
- package/plugins/components/Image.js.map +1 -0
- package/plugins/image.d.ts +1 -1
- package/plugins/image.js +46 -53
- package/plugins/image.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +31 -53
- package/plugins/index.js.map +1 -1
- package/presentation/localStorage/index.d.ts +3 -0
- package/presentation/localStorage/index.js +5 -0
- package/presentation/localStorage/index.js.map +1 -0
- package/presentation/localStorage/useLocalStorage.d.ts +6 -0
- package/presentation/localStorage/useLocalStorage.js +21 -0
- package/presentation/localStorage/useLocalStorage.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValue.d.ts +1 -0
- package/presentation/localStorage/useLocalStorageValue.js +20 -0
- package/presentation/localStorage/useLocalStorageValue.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValues.d.ts +5 -0
- package/presentation/localStorage/useLocalStorageValues.js +39 -0
- package/presentation/localStorage/useLocalStorageValues.js.map +1 -0
- package/presentation/router/RouteElementRegistry.d.ts +14 -0
- package/presentation/router/RouteElementRegistry.js +32 -0
- package/presentation/router/RouteElementRegistry.js.map +1 -0
- package/presentation/router/abstractions.d.ts +13 -0
- package/presentation/router/abstractions.js +4 -0
- package/presentation/router/abstractions.js.map +1 -0
- package/presentation/router/components/RouteContent.d.ts +2 -0
- package/presentation/router/components/RouteContent.js +17 -0
- package/presentation/router/components/RouteContent.js.map +1 -0
- package/presentation/router/components/RouteLink.d.ts +50 -0
- package/presentation/router/components/RouteLink.js +22 -0
- package/presentation/router/components/RouteLink.js.map +1 -0
- package/presentation/router/components/SimpleLink.d.ts +44 -0
- package/presentation/router/components/SimpleLink.js +30 -0
- package/presentation/router/components/SimpleLink.js.map +1 -0
- package/presentation/router/hooks/useRoute.d.ts +6 -0
- package/presentation/router/hooks/useRoute.js +30 -0
- package/presentation/router/hooks/useRoute.js.map +1 -0
- package/presentation/router/hooks/useRouter.d.ts +7 -0
- package/presentation/router/hooks/useRouter.js +26 -0
- package/presentation/router/hooks/useRouter.js.map +1 -0
- package/presentation/router/index.d.ts +4 -0
- package/presentation/router/index.js +5 -0
- package/presentation/router/index.js.map +1 -0
- package/presentation/router/types.d.ts +5 -0
- package/presentation/router/types.js +3 -0
- package/presentation/router/types.js.map +1 -0
- package/react-butterfiles/Files.js +208 -235
- package/react-butterfiles/Files.js.map +1 -1
- package/react-butterfiles/file.todo +1 -0
- package/react-butterfiles/index.d.ts +1 -1
- package/react-butterfiles/index.js +2 -8
- package/react-butterfiles/index.js.map +1 -1
- package/react-butterfiles/utils/generateId.js +1 -7
- package/react-butterfiles/utils/generateId.js.map +1 -1
- package/react-butterfiles/utils/readFileContent.js +4 -10
- package/react-butterfiles/utils/readFileContent.js.map +1 -1
- package/renderApp.d.ts +1 -1
- package/renderApp.js +4 -11
- package/renderApp.js.map +1 -1
- package/router.d.ts +5 -0
- package/router.js +8 -0
- package/router.js.map +1 -0
- package/shared/di/DiContainerProvider.d.ts +8 -0
- package/shared/di/DiContainerProvider.js +17 -0
- package/shared/di/DiContainerProvider.js.map +1 -0
- package/shared/di/createFeature.d.ts +11 -0
- package/shared/di/createFeature.js +11 -0
- package/shared/di/createFeature.js.map +1 -0
- package/shared/di/useFeature.d.ts +2 -0
- package/shared/di/useFeature.js +18 -0
- package/shared/di/useFeature.js.map +1 -0
- package/types.d.ts +9 -6
- package/types.js +1 -12
- package/types.js.map +1 -1
- package/utils/createGenericContext.js +13 -22
- package/utils/createGenericContext.js.map +1 -1
- package/utils/createHashing.js +9 -15
- package/utils/createHashing.js.map +1 -1
- package/utils/index.d.ts +2 -10
- package/utils/index.js +2 -115
- package/utils/index.js.map +1 -1
- package/utils/legacyPluginToReactComponent.d.ts +1 -1
- package/utils/legacyPluginToReactComponent.js +5 -11
- package/utils/legacyPluginToReactComponent.js.map +1 -1
- package/components/Routes.d.ts +0 -2
- package/components/Routes.js +0 -46
- package/components/Routes.js.map +0 -1
- package/components/View.d.ts +0 -8
- package/components/View.js +0 -31
- package/components/View.js.map +0 -1
- package/core/AddRoute.d.ts +0 -21
- package/core/AddRoute.js +0 -21
- package/core/AddRoute.js.map +0 -1
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +0 -14
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +0 -30
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +0 -1
- package/hooks/useDataList/utils/types.d.ts +0 -40
- package/hooks/useDataList/utils/types.js +0 -7
- package/hooks/useDataList/utils/types.js.map +0 -1
- package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -10
- package/plugins/LocaleHeaderLinkPlugin.js +0 -49
- package/plugins/LocaleHeaderLinkPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -12
- package/plugins/RoutePlugin.js +0 -35
- package/plugins/RoutePlugin.js.map +0 -1
- package/plugins/ViewPlugin.d.ts +0 -14
- package/plugins/ViewPlugin.js +0 -40
- package/plugins/ViewPlugin.js.map +0 -1
- package/utils/getApiUrl.d.ts +0 -1
- package/utils/getApiUrl.js +0 -12
- package/utils/getApiUrl.js.map +0 -1
- package/utils/getGqlApiUrl.d.ts +0 -1
- package/utils/getGqlApiUrl.js +0 -12
- package/utils/getGqlApiUrl.js.map +0 -1
- package/utils/getHeadlessCmsGqlApiUrl.d.ts +0 -5
- package/utils/getHeadlessCmsGqlApiUrl.js +0 -18
- package/utils/getHeadlessCmsGqlApiUrl.js.map +0 -1
- package/utils/getLocaleCode.d.ts +0 -6
- package/utils/getLocaleCode.js +0 -43
- package/utils/getLocaleCode.js.map +0 -1
- package/utils/getPrerenderId.d.ts +0 -6
- package/utils/getPrerenderId.js +0 -11
- package/utils/getPrerenderId.js.map +0 -1
- package/utils/getTenantId.d.ts +0 -6
- package/utils/getTenantId.js +0 -51
- package/utils/getTenantId.js.map +0 -1
- package/utils/isLocalhost.d.ts +0 -1
- package/utils/isLocalhost.js +0 -15
- package/utils/isLocalhost.js.map +0 -1
- package/utils/isPrerendering.d.ts +0 -1
- package/utils/isPrerendering.js +0 -11
- package/utils/isPrerendering.js.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export type RouteParamsDefinition = Record<string, z.ZodTypeAny>;
|
|
3
|
+
export type RouteParamsInfer<T extends RouteParamsDefinition | undefined> = T extends RouteParamsDefinition ? z.infer<z.ZodObject<T> & {
|
|
4
|
+
[k: string]: any;
|
|
5
|
+
}> : never;
|
|
6
|
+
export interface RouteParams<TParams extends RouteParamsDefinition | undefined> {
|
|
7
|
+
name: string;
|
|
8
|
+
path: `/${string}` | `*`;
|
|
9
|
+
params?: (zod: typeof z) => TParams;
|
|
10
|
+
}
|
|
11
|
+
export declare class Route<TParams extends RouteParamsDefinition | undefined = undefined> {
|
|
12
|
+
private readonly route;
|
|
13
|
+
private readonly schema;
|
|
14
|
+
constructor(route: RouteParams<TParams>);
|
|
15
|
+
get name(): string;
|
|
16
|
+
get path(): `/${string}` | "*";
|
|
17
|
+
get params(): TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined;
|
|
18
|
+
private coerceParams;
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export class Route {
|
|
3
|
+
constructor(route) {
|
|
4
|
+
this.route = route;
|
|
5
|
+
const paramsSchema = route.params ? route.params(z) : undefined;
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
this.schema = paramsSchema ? z.object(this.coerceParams(paramsSchema)).passthrough() : undefined;
|
|
8
|
+
}
|
|
9
|
+
get name() {
|
|
10
|
+
return this.route.name;
|
|
11
|
+
}
|
|
12
|
+
get path() {
|
|
13
|
+
return this.route.path;
|
|
14
|
+
}
|
|
15
|
+
get params() {
|
|
16
|
+
return this.schema;
|
|
17
|
+
}
|
|
18
|
+
coerceParams(shape) {
|
|
19
|
+
const result = {};
|
|
20
|
+
for (const [key, schema] of Object.entries(shape)) {
|
|
21
|
+
let base = schema;
|
|
22
|
+
let isOptional = false;
|
|
23
|
+
let isNullable = false;
|
|
24
|
+
|
|
25
|
+
// unwrap optional
|
|
26
|
+
if (base._def.typeName === z.ZodFirstPartyTypeKind.ZodOptional) {
|
|
27
|
+
isOptional = true;
|
|
28
|
+
base = base._def.innerType;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// unwrap nullable
|
|
32
|
+
if (base._def.typeName === z.ZodFirstPartyTypeKind.ZodNullable) {
|
|
33
|
+
isNullable = true;
|
|
34
|
+
base = base._def.innerType;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// replace with coerced
|
|
38
|
+
if (base instanceof z.ZodString) {
|
|
39
|
+
base = z.coerce.string();
|
|
40
|
+
} else if (base instanceof z.ZodNumber) {
|
|
41
|
+
base = z.coerce.number();
|
|
42
|
+
} else if (base instanceof z.ZodBoolean) {
|
|
43
|
+
base = z.coerce.boolean();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// rewrap optional/nullable
|
|
47
|
+
if (isNullable) {
|
|
48
|
+
base = base.nullable();
|
|
49
|
+
}
|
|
50
|
+
if (isOptional) {
|
|
51
|
+
base = base.optional();
|
|
52
|
+
}
|
|
53
|
+
result[key] = base;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=Route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","Route","constructor","route","paramsSchema","params","undefined","schema","object","coerceParams","passthrough","name","path","shape","result","key","Object","entries","base","isOptional","isNullable","_def","typeName","ZodFirstPartyTypeKind","ZodOptional","innerType","ZodNullable","ZodString","coerce","string","ZodNumber","number","ZodBoolean","boolean","nullable","optional"],"sources":["Route.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport type RouteParamsDefinition = Record<string, z.ZodTypeAny>;\n\nexport type RouteParamsInfer<T extends RouteParamsDefinition | undefined> =\n T extends RouteParamsDefinition ? z.infer<z.ZodObject<T> & { [k: string]: any }> : never;\n\nexport interface RouteParams<TParams extends RouteParamsDefinition | undefined> {\n name: string;\n path: `/${string}` | `*`;\n params?: (zod: typeof z) => TParams;\n}\n\nexport class Route<TParams extends RouteParamsDefinition | undefined = undefined> {\n private readonly route: RouteParams<TParams>;\n private readonly schema: TParams extends RouteParamsDefinition\n ? RouteParamsInfer<TParams>\n : undefined;\n\n constructor(route: RouteParams<TParams>) {\n this.route = route;\n const paramsSchema = route.params ? route.params(z) : undefined;\n // @ts-expect-error\n this.schema = paramsSchema\n ? z.object(this.coerceParams(paramsSchema)).passthrough()\n : undefined;\n }\n\n get name() {\n return this.route.name;\n }\n\n get path() {\n return this.route.path;\n }\n\n get params(): TParams extends RouteParamsDefinition ? RouteParamsInfer<TParams> : undefined {\n return this.schema;\n }\n\n private coerceParams<T extends Record<string, z.ZodTypeAny>>(shape: T) {\n const result: Record<string, z.ZodTypeAny> = {};\n for (const [key, schema] of Object.entries(shape)) {\n let base = schema as z.ZodTypeAny;\n let isOptional = false;\n let isNullable = false;\n\n // unwrap optional\n if (base._def.typeName === z.ZodFirstPartyTypeKind.ZodOptional) {\n isOptional = true;\n base = base._def.innerType;\n }\n\n // unwrap nullable\n if (base._def.typeName === z.ZodFirstPartyTypeKind.ZodNullable) {\n isNullable = true;\n base = base._def.innerType;\n }\n\n // replace with coerced\n if (base instanceof z.ZodString) {\n base = z.coerce.string();\n } else if (base instanceof z.ZodNumber) {\n base = z.coerce.number();\n } else if (base instanceof z.ZodBoolean) {\n base = z.coerce.boolean();\n }\n\n // rewrap optional/nullable\n if (isNullable) {\n base = base.nullable();\n }\n if (isOptional) {\n base = base.optional();\n }\n\n result[key] = base;\n }\n return result;\n }\n}\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AAavB,OAAO,MAAMC,KAAK,CAAgE;EAM9EC,WAAWA,CAACC,KAA2B,EAAE;IACrC,IAAI,CAACA,KAAK,GAAGA,KAAK;IAClB,MAAMC,YAAY,GAAGD,KAAK,CAACE,MAAM,GAAGF,KAAK,CAACE,MAAM,CAACL,CAAC,CAAC,GAAGM,SAAS;IAC/D;IACA,IAAI,CAACC,MAAM,GAAGH,YAAY,GACpBJ,CAAC,CAACQ,MAAM,CAAC,IAAI,CAACC,YAAY,CAACL,YAAY,CAAC,CAAC,CAACM,WAAW,CAAC,CAAC,GACvDJ,SAAS;EACnB;EAEA,IAAIK,IAAIA,CAAA,EAAG;IACP,OAAO,IAAI,CAACR,KAAK,CAACQ,IAAI;EAC1B;EAEA,IAAIC,IAAIA,CAAA,EAAG;IACP,OAAO,IAAI,CAACT,KAAK,CAACS,IAAI;EAC1B;EAEA,IAAIP,MAAMA,CAAA,EAAkF;IACxF,OAAO,IAAI,CAACE,MAAM;EACtB;EAEQE,YAAYA,CAAyCI,KAAQ,EAAE;IACnE,MAAMC,MAAoC,GAAG,CAAC,CAAC;IAC/C,KAAK,MAAM,CAACC,GAAG,EAAER,MAAM,CAAC,IAAIS,MAAM,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MAC/C,IAAIK,IAAI,GAAGX,MAAsB;MACjC,IAAIY,UAAU,GAAG,KAAK;MACtB,IAAIC,UAAU,GAAG,KAAK;;MAEtB;MACA,IAAIF,IAAI,CAACG,IAAI,CAACC,QAAQ,KAAKtB,CAAC,CAACuB,qBAAqB,CAACC,WAAW,EAAE;QAC5DL,UAAU,GAAG,IAAI;QACjBD,IAAI,GAAGA,IAAI,CAACG,IAAI,CAACI,SAAS;MAC9B;;MAEA;MACA,IAAIP,IAAI,CAACG,IAAI,CAACC,QAAQ,KAAKtB,CAAC,CAACuB,qBAAqB,CAACG,WAAW,EAAE;QAC5DN,UAAU,GAAG,IAAI;QACjBF,IAAI,GAAGA,IAAI,CAACG,IAAI,CAACI,SAAS;MAC9B;;MAEA;MACA,IAAIP,IAAI,YAAYlB,CAAC,CAAC2B,SAAS,EAAE;QAC7BT,IAAI,GAAGlB,CAAC,CAAC4B,MAAM,CAACC,MAAM,CAAC,CAAC;MAC5B,CAAC,MAAM,IAAIX,IAAI,YAAYlB,CAAC,CAAC8B,SAAS,EAAE;QACpCZ,IAAI,GAAGlB,CAAC,CAAC4B,MAAM,CAACG,MAAM,CAAC,CAAC;MAC5B,CAAC,MAAM,IAAIb,IAAI,YAAYlB,CAAC,CAACgC,UAAU,EAAE;QACrCd,IAAI,GAAGlB,CAAC,CAAC4B,MAAM,CAACK,OAAO,CAAC,CAAC;MAC7B;;MAEA;MACA,IAAIb,UAAU,EAAE;QACZF,IAAI,GAAGA,IAAI,CAACgB,QAAQ,CAAC,CAAC;MAC1B;MACA,IAAIf,UAAU,EAAE;QACZD,IAAI,GAAGA,IAAI,CAACiB,QAAQ,CAAC,CAAC;MAC1B;MAEArB,MAAM,CAACC,GAAG,CAAC,GAAGG,IAAI;IACtB;IACA,OAAOJ,MAAM;EACjB;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
interface Params {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
interface MatchResult {
|
|
5
|
+
params: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Utility class for route URL pattern matching and generation.
|
|
9
|
+
* Handles simple route patterns with :param syntax (e.g., /cms/entries/:modelId).
|
|
10
|
+
*
|
|
11
|
+
* Public API uses static methods, which internally construct RouteUrl instances
|
|
12
|
+
* to handle the logic through proper instance methods.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RouteUrl {
|
|
15
|
+
private static patternCache;
|
|
16
|
+
private readonly pattern;
|
|
17
|
+
private readonly params;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Generate a URL from a route pattern and parameters.
|
|
22
|
+
* Path parameters are injected into the pattern, remaining parameters become query strings.
|
|
23
|
+
*
|
|
24
|
+
* @param pattern - Route pattern (e.g., '/security/api-keys/:id')
|
|
25
|
+
* @param params - Parameters object (e.g., { id: 123, new: true })
|
|
26
|
+
* @param baseUrl - Optional base URL to prepend (e.g., '/tenant123')
|
|
27
|
+
* @returns Generated URL string
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* RouteUrl.fromPattern('/security/api-keys/:id', { id: 123, new: true })
|
|
31
|
+
* // Returns: '/security/api-keys/123?new=true'
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* RouteUrl.fromPattern('/file-manager', {}, '/tenant123')
|
|
35
|
+
* // Returns: '/tenant123/file-manager'
|
|
36
|
+
*/
|
|
37
|
+
static fromPattern(pattern: string, params?: Params, baseUrl?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Match a pathname against a route pattern and extract parameters.
|
|
40
|
+
* If baseUrl is provided, it will be stripped from the pathname before matching.
|
|
41
|
+
*
|
|
42
|
+
* @param pathname - The pathname to match (e.g., '/tenant123/security/api-keys/123')
|
|
43
|
+
* @param pattern - Route pattern (e.g., '/security/api-keys/:id')
|
|
44
|
+
* @param baseUrl - Optional base URL to strip before matching (e.g., '/tenant123')
|
|
45
|
+
* @returns Object with extracted params if matched, null otherwise
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* RouteUrl.match('/security/api-keys/123', '/security/api-keys/:id')
|
|
49
|
+
* // Returns: { params: { id: '123' } }
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* RouteUrl.match('/tenant123/file-manager', '/file-manager', '/tenant123')
|
|
53
|
+
* // Returns: { params: {} }
|
|
54
|
+
*/
|
|
55
|
+
static match(pathname: string, pattern: string, baseUrl?: string): MatchResult | null;
|
|
56
|
+
/**
|
|
57
|
+
* Generate a URL from the instance's pattern, params, and baseUrl.
|
|
58
|
+
*/
|
|
59
|
+
private generate;
|
|
60
|
+
/**
|
|
61
|
+
* Match a pathname against the instance's pattern.
|
|
62
|
+
*/
|
|
63
|
+
private matchPathname;
|
|
64
|
+
/**
|
|
65
|
+
* Extract path parameter names from the pattern.
|
|
66
|
+
*/
|
|
67
|
+
private extractPathKeys;
|
|
68
|
+
/**
|
|
69
|
+
* Replace :param placeholders with actual values from params.
|
|
70
|
+
*/
|
|
71
|
+
private replacePathParams;
|
|
72
|
+
/**
|
|
73
|
+
* Build query string from params that are not path parameters.
|
|
74
|
+
*/
|
|
75
|
+
private buildQueryString;
|
|
76
|
+
/**
|
|
77
|
+
* Normalize baseUrl by ensuring it starts with / and doesn't end with /
|
|
78
|
+
*/
|
|
79
|
+
private normalizeBaseUrl;
|
|
80
|
+
/**
|
|
81
|
+
* Compile the instance's pattern into a regex and extract parameter names.
|
|
82
|
+
*/
|
|
83
|
+
private compilePattern;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for route URL pattern matching and generation.
|
|
3
|
+
* Handles simple route patterns with :param syntax (e.g., /cms/entries/:modelId).
|
|
4
|
+
*
|
|
5
|
+
* Public API uses static methods, which internally construct RouteUrl instances
|
|
6
|
+
* to handle the logic through proper instance methods.
|
|
7
|
+
*/
|
|
8
|
+
export class RouteUrl {
|
|
9
|
+
static patternCache = new Map();
|
|
10
|
+
constructor(pattern, params, baseUrl) {
|
|
11
|
+
this.pattern = pattern;
|
|
12
|
+
this.params = params;
|
|
13
|
+
this.baseUrl = this.normalizeBaseUrl(baseUrl);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generate a URL from a route pattern and parameters.
|
|
18
|
+
* Path parameters are injected into the pattern, remaining parameters become query strings.
|
|
19
|
+
*
|
|
20
|
+
* @param pattern - Route pattern (e.g., '/security/api-keys/:id')
|
|
21
|
+
* @param params - Parameters object (e.g., { id: 123, new: true })
|
|
22
|
+
* @param baseUrl - Optional base URL to prepend (e.g., '/tenant123')
|
|
23
|
+
* @returns Generated URL string
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* RouteUrl.fromPattern('/security/api-keys/:id', { id: 123, new: true })
|
|
27
|
+
* // Returns: '/security/api-keys/123?new=true'
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* RouteUrl.fromPattern('/file-manager', {}, '/tenant123')
|
|
31
|
+
* // Returns: '/tenant123/file-manager'
|
|
32
|
+
*/
|
|
33
|
+
static fromPattern(pattern, params, baseUrl) {
|
|
34
|
+
const routeUrl = new RouteUrl(pattern, params, baseUrl);
|
|
35
|
+
return routeUrl.generate();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Match a pathname against a route pattern and extract parameters.
|
|
40
|
+
* If baseUrl is provided, it will be stripped from the pathname before matching.
|
|
41
|
+
*
|
|
42
|
+
* @param pathname - The pathname to match (e.g., '/tenant123/security/api-keys/123')
|
|
43
|
+
* @param pattern - Route pattern (e.g., '/security/api-keys/:id')
|
|
44
|
+
* @param baseUrl - Optional base URL to strip before matching (e.g., '/tenant123')
|
|
45
|
+
* @returns Object with extracted params if matched, null otherwise
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* RouteUrl.match('/security/api-keys/123', '/security/api-keys/:id')
|
|
49
|
+
* // Returns: { params: { id: '123' } }
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* RouteUrl.match('/tenant123/file-manager', '/file-manager', '/tenant123')
|
|
53
|
+
* // Returns: { params: {} }
|
|
54
|
+
*/
|
|
55
|
+
static match(pathname, pattern, baseUrl) {
|
|
56
|
+
const routeUrl = new RouteUrl(pattern, undefined, baseUrl);
|
|
57
|
+
return routeUrl.matchPathname(pathname);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generate a URL from the instance's pattern, params, and baseUrl.
|
|
62
|
+
*/
|
|
63
|
+
generate() {
|
|
64
|
+
if (!this.params) {
|
|
65
|
+
return this.baseUrl + this.pattern;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Extract path parameter names from pattern
|
|
69
|
+
const pathKeys = this.extractPathKeys();
|
|
70
|
+
|
|
71
|
+
// Replace :param with actual values
|
|
72
|
+
let url = this.replacePathParams();
|
|
73
|
+
|
|
74
|
+
// Handle empty url
|
|
75
|
+
if (!url || url === "") {
|
|
76
|
+
url = "/";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Prepend baseUrl
|
|
80
|
+
url = this.baseUrl + url;
|
|
81
|
+
|
|
82
|
+
// Add query parameters for keys not used in the path
|
|
83
|
+
const queryString = this.buildQueryString(pathKeys);
|
|
84
|
+
if (queryString) {
|
|
85
|
+
url += `?${queryString}`;
|
|
86
|
+
}
|
|
87
|
+
return url;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Match a pathname against the instance's pattern.
|
|
92
|
+
*/
|
|
93
|
+
matchPathname(pathname) {
|
|
94
|
+
// Strip baseUrl from pathname if provided
|
|
95
|
+
if (this.baseUrl && pathname.startsWith(this.baseUrl)) {
|
|
96
|
+
pathname = pathname.slice(this.baseUrl.length) || "/";
|
|
97
|
+
} else if (this.baseUrl) {
|
|
98
|
+
// pathname doesn't start with baseUrl, no match
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Handle wildcard pattern
|
|
103
|
+
if (this.pattern === "*" || this.pattern === "(.*)") {
|
|
104
|
+
return {
|
|
105
|
+
params: {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Get or create cached pattern
|
|
110
|
+
let compiled = RouteUrl.patternCache.get(this.pattern);
|
|
111
|
+
if (!compiled) {
|
|
112
|
+
compiled = this.compilePattern();
|
|
113
|
+
RouteUrl.patternCache.set(this.pattern, compiled);
|
|
114
|
+
}
|
|
115
|
+
const match = pathname.match(compiled.regex);
|
|
116
|
+
if (!match) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Extract parameters from capture groups
|
|
121
|
+
const params = {};
|
|
122
|
+
compiled.keys.forEach((key, index) => {
|
|
123
|
+
const value = match[index + 1];
|
|
124
|
+
if (value !== undefined) {
|
|
125
|
+
params[key] = decodeURIComponent(value);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
params
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Extract path parameter names from the pattern.
|
|
135
|
+
*/
|
|
136
|
+
extractPathKeys() {
|
|
137
|
+
const pathKeys = new Set();
|
|
138
|
+
const paramRegex = /:([a-zA-Z_][a-zA-Z0-9_]*)/g;
|
|
139
|
+
let match;
|
|
140
|
+
while ((match = paramRegex.exec(this.pattern)) !== null) {
|
|
141
|
+
pathKeys.add(match[1]);
|
|
142
|
+
}
|
|
143
|
+
return pathKeys;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Replace :param placeholders with actual values from params.
|
|
148
|
+
*/
|
|
149
|
+
replacePathParams() {
|
|
150
|
+
return this.pattern.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, key) => {
|
|
151
|
+
const value = this.params[key];
|
|
152
|
+
if (value === undefined || value === null) {
|
|
153
|
+
return "";
|
|
154
|
+
}
|
|
155
|
+
return encodeURIComponent(String(value));
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Build query string from params that are not path parameters.
|
|
161
|
+
*/
|
|
162
|
+
buildQueryString(pathKeys) {
|
|
163
|
+
const queryParams = {};
|
|
164
|
+
for (const key in this.params) {
|
|
165
|
+
if (!pathKeys.has(key)) {
|
|
166
|
+
queryParams[key] = this.params[key];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (Object.keys(queryParams).length === 0) {
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
const searchParams = new URLSearchParams();
|
|
173
|
+
for (const key in queryParams) {
|
|
174
|
+
const value = queryParams[key];
|
|
175
|
+
if (value !== undefined && value !== null) {
|
|
176
|
+
if (Array.isArray(value)) {
|
|
177
|
+
value.forEach(v => searchParams.append(key, String(v)));
|
|
178
|
+
} else {
|
|
179
|
+
searchParams.append(key, String(value));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return searchParams.toString();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Normalize baseUrl by ensuring it starts with / and doesn't end with /
|
|
188
|
+
*/
|
|
189
|
+
normalizeBaseUrl(baseUrl) {
|
|
190
|
+
if (!baseUrl || baseUrl === "/") {
|
|
191
|
+
return "";
|
|
192
|
+
}
|
|
193
|
+
let normalized = baseUrl;
|
|
194
|
+
|
|
195
|
+
// Ensure it starts with /
|
|
196
|
+
if (!normalized.startsWith("/")) {
|
|
197
|
+
normalized = "/" + normalized;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Remove trailing /
|
|
201
|
+
if (normalized.endsWith("/")) {
|
|
202
|
+
normalized = normalized.slice(0, -1);
|
|
203
|
+
}
|
|
204
|
+
return normalized;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Compile the instance's pattern into a regex and extract parameter names.
|
|
209
|
+
*/
|
|
210
|
+
compilePattern() {
|
|
211
|
+
const keys = [];
|
|
212
|
+
|
|
213
|
+
// Escape special regex characters except for :param syntax
|
|
214
|
+
let regexPattern = this.pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&") // Escape special chars
|
|
215
|
+
.replace(/\\\*/g, ".*"); // Handle * wildcard (already escaped by above)
|
|
216
|
+
|
|
217
|
+
// Replace :param with capture groups
|
|
218
|
+
regexPattern = regexPattern.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, key) => {
|
|
219
|
+
keys.push(key);
|
|
220
|
+
return "([^/]+)"; // Match any non-slash characters
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Create regex that matches the entire pathname
|
|
224
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
225
|
+
return {
|
|
226
|
+
regex,
|
|
227
|
+
keys
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
//# sourceMappingURL=RouteUrl.js.map
|
|
@@ -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;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,CAAC,CAAC;IACtB,CAAC,CAAC;;IAEF;IACA,MAAMH,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;AAC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MACrD,MAAMI,WAAW,GAAGR,iBAAiB,CAACO,QAAQ,CAACF,KAAK,CAAC;MACrD,MAAMI,QAAQ,GAAGL,KAAK,KAAKL,UAAU;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 {};
|