@webiny/app 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 -6
- package/App.js +26 -32
- package/App.js.map +1 -1
- package/README.md +7 -15
- package/apollo-client/InMemoryCache.js +2 -2
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/components/Image.d.ts +1 -2
- package/components/Image.js +1 -1
- package/components/Image.js.map +1 -1
- package/components/index.d.ts +1 -2
- package/components/index.js +1 -2
- package/components/index.js.map +1 -1
- package/config/RouterConfig/Route.d.ts +9 -10
- package/config/RouterConfig/Route.js +5 -14
- package/config/RouterConfig/Route.js.map +1 -1
- package/config/RouterConfig.d.ts +10 -11
- package/config/RouterConfig.js +1 -1
- package/config/RouterConfig.js.map +1 -1
- package/contexts/Ui/index.js.map +1 -1
- package/core/Plugin.d.ts +1 -1
- package/core/Plugin.js +2 -2
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.d.ts +2 -2
- package/core/Plugins.js +5 -4
- package/core/Plugins.js.map +1 -1
- package/core/Provider.d.ts +1 -1
- package/core/Provider.js +1 -1
- package/core/Provider.js.map +1 -1
- package/core/createProviderPlugin.js +1 -1
- 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/env-config.d.ts +2 -0
- package/exports/admin/env-config.js +4 -0
- package/exports/admin/env-config.js.map +1 -0
- package/exports/admin/graphql-client.d.ts +1 -0
- package/exports/admin/graphql-client.js +3 -0
- package/exports/admin/graphql-client.js.map +1 -0
- package/exports/admin/local-storage.d.ts +2 -0
- package/exports/admin/local-storage.js +4 -0
- package/exports/admin/local-storage.js.map +1 -0
- package/exports/admin/router.d.ts +5 -0
- package/exports/admin/router.js +7 -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 +7 -0
- package/exports/admin.js +9 -0
- package/exports/admin.js.map +1 -0
- package/features/envConfig/EnvConfig.d.ts +7 -0
- package/features/envConfig/EnvConfig.js +17 -0
- package/features/envConfig/EnvConfig.js.map +1 -0
- package/features/envConfig/abstractions.d.ts +28 -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 +3 -0
- package/features/eventPublisher/feature.js +16 -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 +16 -0
- package/features/graphqlClient/BatchingGraphQLClient.js +163 -0
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -0
- package/features/graphqlClient/FetchGraphQLClient.d.ts +7 -0
- package/features/graphqlClient/FetchGraphQLClient.js +58 -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 +21 -0
- package/features/graphqlClient/RequestValue.js +45 -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 +370 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -0
- package/features/graphqlClient/abstractions.d.ts +18 -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.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/mainGraphQLClient/MainGraphQLClient.d.ts +11 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js +23 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -0
- package/features/mainGraphQLClient/abstractions.d.ts +17 -0
- package/features/mainGraphQLClient/abstractions.js +4 -0
- package/features/mainGraphQLClient/abstractions.js.map +1 -0
- package/features/mainGraphQLClient/feature.d.ts +3 -0
- package/features/mainGraphQLClient/feature.js +16 -0
- package/features/mainGraphQLClient/feature.js.map +1 -0
- package/features/mainGraphQLClient/index.d.ts +1 -0
- package/features/mainGraphQLClient/index.js +3 -0
- package/features/mainGraphQLClient/index.js.map +1 -0
- package/features/router/HistoryRouterGateway.d.ts +22 -0
- package/features/router/HistoryRouterGateway.js +118 -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 +21 -0
- package/features/router/RouterPresenter.js +57 -0
- package/features/router/RouterPresenter.js.map +1 -0
- package/features/router/RouterRepository.d.ts +30 -0
- package/features/router/RouterRepository.js +125 -0
- package/features/router/RouterRepository.js.map +1 -0
- package/features/router/RouterRepository.test.d.ts +1 -0
- package/features/router/RouterRepository.test.js +169 -0
- package/features/router/RouterRepository.test.js.map +1 -0
- package/features/router/abstractions.d.ts +81 -0
- package/features/router/abstractions.js +17 -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 +2 -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 -1
- package/hooks/useAutocomplete/index.js.map +1 -1
- package/hooks/useAutocomplete/useAutocomplete.js +3 -6
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +1 -1
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +1 -1
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +1 -1
- 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 -3
- package/hooks/useDataList/functions/index.js.map +1 -1
- package/hooks/useDataList/index.d.ts +1 -1
- package/hooks/useDataList/index.js +1 -1
- package/hooks/useDataList/index.js.map +1 -1
- package/hooks/useDataList/useDataList.d.ts +0 -1
- package/hooks/useDataList/useDataList.js +6 -26
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.d.ts +1 -2
- package/hooks/useDataList/utils/index.js +1 -2
- package/hooks/useDataList/utils/index.js.map +1 -1
- package/hooks/useDataList/utils/prepareLoadListParams.js +1 -1
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.d.ts +1 -1
- package/hooks/useRegisterLegacyPlugin.js.map +1 -1
- package/hooks/useUi.d.ts +1 -1
- package/hooks/useUi.js +1 -1
- package/hooks/useUi.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/i18n/index.js +1 -1
- package/i18n/index.js.map +1 -1
- package/index.d.ts +23 -15
- package/index.js +22 -14
- package/index.js.map +1 -1
- package/package.json +33 -28
- package/plugins/AddQuerySelectionPlugin.d.ts +1 -1
- package/plugins/AddQuerySelectionPlugin.js +1 -1
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.d.ts +1 -1
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.d.ts +1 -1
- package/plugins/ConsoleLinkPlugin.js +1 -1
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +8 -13
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +15 -26
- 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 +3 -3
- 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 +4 -13
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.d.ts +4 -1
- package/plugins/NetworkErrorLinkPlugin.js +47 -7
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.d.ts +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +1 -1
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.d.ts +2 -2
- package/plugins/TenantHeaderLinkPlugin.js +2 -4
- 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 +2 -2
- package/plugins/image.js.map +1 -1
- package/plugins/index.d.ts +3 -3
- package/plugins/index.js +1 -1
- package/plugins/index.js.map +1 -1
- package/presentation/envConfig/useEnvConfig.d.ts +6 -0
- package/presentation/envConfig/useEnvConfig.js +13 -0
- package/presentation/envConfig/useEnvConfig.js.map +1 -0
- 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/Redirect.d.ts +14 -0
- package/presentation/router/components/Redirect.js +15 -0
- package/presentation/router/components/Redirect.js.map +1 -0
- package/presentation/router/components/RouteContent.d.ts +2 -0
- package/presentation/router/components/RouteContent.js +23 -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 +11 -0
- package/presentation/router/hooks/useRouter.js +30 -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 +3 -3
- 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 +1 -1
- package/react-butterfiles/index.js.map +1 -1
- package/renderApp.d.ts +1 -1
- 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 +8 -0
- package/shared/di/useFeature.js.map +1 -0
- package/types.d.ts +7 -4
- package/types.js +1 -12
- package/types.js.map +1 -1
- package/utils/index.d.ts +2 -10
- package/utils/index.js +2 -10
- package/utils/index.js.map +1 -1
- package/utils/legacyPluginToReactComponent.js +1 -1
- package/utils/legacyPluginToReactComponent.js.map +1 -1
- package/components/Routes.d.ts +0 -2
- package/components/Routes.js +0 -36
- package/components/Routes.js.map +0 -1
- package/components/View.d.ts +0 -8
- package/components/View.js +0 -19
- package/components/View.js.map +0 -1
- package/core/DebounceRender.d.ts +0 -12
- package/core/DebounceRender.js +0 -31
- package/core/DebounceRender.js.map +0 -1
- package/core/Routes.d.ts +0 -6
- package/core/Routes.js +0 -34
- package/core/Routes.js.map +0 -1
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +0 -14
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +0 -26
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +0 -1
- package/hooks/useDataList/utils/types.d.ts +0 -40
- package/hooks/useDataList/utils/types.js.map +0 -1
- package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -10
- package/plugins/LocaleHeaderLinkPlugin.js +0 -32
- package/plugins/LocaleHeaderLinkPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -12
- package/plugins/RoutePlugin.js +0 -16
- package/plugins/RoutePlugin.js.map +0 -1
- package/plugins/ViewPlugin.d.ts +0 -14
- package/plugins/ViewPlugin.js +0 -19
- package/plugins/ViewPlugin.js.map +0 -1
- package/utils/getApiUrl.d.ts +0 -1
- package/utils/getApiUrl.js +0 -5
- package/utils/getApiUrl.js.map +0 -1
- package/utils/getGqlApiUrl.d.ts +0 -1
- package/utils/getGqlApiUrl.js +0 -6
- package/utils/getGqlApiUrl.js.map +0 -1
- package/utils/getHeadlessCmsGqlApiUrl.d.ts +0 -5
- package/utils/getHeadlessCmsGqlApiUrl.js +0 -12
- package/utils/getHeadlessCmsGqlApiUrl.js.map +0 -1
- package/utils/getLocaleCode.d.ts +0 -6
- package/utils/getLocaleCode.js +0 -33
- package/utils/getLocaleCode.js.map +0 -1
- package/utils/getPrerenderId.d.ts +0 -6
- package/utils/getPrerenderId.js +0 -5
- package/utils/getPrerenderId.js.map +0 -1
- package/utils/getTenantId.d.ts +0 -6
- package/utils/getTenantId.js +0 -45
- package/utils/getTenantId.js.map +0 -1
- package/utils/isLocalhost.d.ts +0 -1
- package/utils/isLocalhost.js +0 -7
- package/utils/isLocalhost.js.map +0 -1
- package/utils/isPrerendering.d.ts +0 -1
- package/utils/isPrerendering.js +0 -5
- package/utils/isPrerendering.js.map +0 -1
- /package/{hooks/useDataList/utils → features/graphqlClient}/types.js +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { describe, it, beforeEach, expect, vi } from "vitest";
|
|
2
|
+
import { createMemoryHistory } from "history";
|
|
3
|
+
import { HistoryRouterGateway } from "./HistoryRouterGateway.js";
|
|
4
|
+
import { RouteUrl } from "./RouteUrl.js";
|
|
5
|
+
const wait = () => new Promise(resolve => setTimeout(resolve, 10));
|
|
6
|
+
describe("Router Gateway", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
it("should execute onMatch when history changes", async () => {
|
|
11
|
+
const spyHome = vi.fn();
|
|
12
|
+
const spyLogin = vi.fn();
|
|
13
|
+
const spyDynamic = vi.fn();
|
|
14
|
+
|
|
15
|
+
// Create `history` and set the initial pathname to an unknown route
|
|
16
|
+
const history = createMemoryHistory();
|
|
17
|
+
history.replace("/__unknown__");
|
|
18
|
+
const gateway = new HistoryRouterGateway(history, "");
|
|
19
|
+
gateway.setRoutes([{
|
|
20
|
+
name: "home",
|
|
21
|
+
path: "/",
|
|
22
|
+
onMatch: spyHome
|
|
23
|
+
}, {
|
|
24
|
+
name: "login",
|
|
25
|
+
path: "/login",
|
|
26
|
+
onMatch: spyLogin
|
|
27
|
+
}, {
|
|
28
|
+
name: "test",
|
|
29
|
+
path: "/dynamic-route/:name",
|
|
30
|
+
onMatch: spyDynamic
|
|
31
|
+
}]);
|
|
32
|
+
history.push("/login");
|
|
33
|
+
await wait();
|
|
34
|
+
history.push("/");
|
|
35
|
+
await wait();
|
|
36
|
+
history.push("/dynamic-route/cars");
|
|
37
|
+
await wait();
|
|
38
|
+
history.push("/login");
|
|
39
|
+
await wait();
|
|
40
|
+
history.push("/dynamic-route/blogs");
|
|
41
|
+
await wait();
|
|
42
|
+
history.push("/dynamic-route/blogs?search=123");
|
|
43
|
+
await wait();
|
|
44
|
+
expect(spyLogin).toHaveBeenCalledTimes(2);
|
|
45
|
+
expect(spyLogin).toHaveBeenNthCalledWith(1, {
|
|
46
|
+
name: "login",
|
|
47
|
+
path: "/login",
|
|
48
|
+
pathname: "/login",
|
|
49
|
+
params: {}
|
|
50
|
+
});
|
|
51
|
+
expect(spyLogin).toHaveBeenNthCalledWith(2, {
|
|
52
|
+
name: "login",
|
|
53
|
+
path: "/login",
|
|
54
|
+
pathname: "/login",
|
|
55
|
+
params: {}
|
|
56
|
+
});
|
|
57
|
+
expect(spyHome).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(spyHome).toHaveBeenLastCalledWith({
|
|
59
|
+
name: "home",
|
|
60
|
+
path: "/",
|
|
61
|
+
pathname: "/",
|
|
62
|
+
params: {}
|
|
63
|
+
});
|
|
64
|
+
expect(spyDynamic).toHaveBeenCalledTimes(3);
|
|
65
|
+
expect(spyDynamic).toHaveBeenNthCalledWith(1, {
|
|
66
|
+
name: "test",
|
|
67
|
+
path: "/dynamic-route/:name",
|
|
68
|
+
pathname: "/dynamic-route/cars",
|
|
69
|
+
params: {
|
|
70
|
+
name: "cars"
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
expect(spyDynamic).toHaveBeenNthCalledWith(2, {
|
|
74
|
+
name: "test",
|
|
75
|
+
path: "/dynamic-route/:name",
|
|
76
|
+
pathname: "/dynamic-route/blogs",
|
|
77
|
+
params: {
|
|
78
|
+
name: "blogs"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
expect(spyDynamic).toHaveBeenNthCalledWith(3, {
|
|
82
|
+
name: "test",
|
|
83
|
+
path: "/dynamic-route/:name",
|
|
84
|
+
pathname: "/dynamic-route/blogs",
|
|
85
|
+
params: {
|
|
86
|
+
name: "blogs",
|
|
87
|
+
search: "123"
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it("should generate route URLs", async () => {
|
|
92
|
+
const urls = [RouteUrl.fromPattern("/"), RouteUrl.fromPattern("/login", {}), RouteUrl.fromPattern("/login", {
|
|
93
|
+
redirect: "/",
|
|
94
|
+
reason: "login"
|
|
95
|
+
}), RouteUrl.fromPattern("/dynamic-route/:name", {
|
|
96
|
+
name: "cars"
|
|
97
|
+
}), RouteUrl.fromPattern("/dynamic-route", {
|
|
98
|
+
folderId: "696556831e485d00027a1a0b#0001"
|
|
99
|
+
})];
|
|
100
|
+
expect(urls).toEqual(["/", "/login", "/login?redirect=%2F&reason=login", "/dynamic-route/cars", "/dynamic-route?folderId=696556831e485d00027a1a0b%230001"]);
|
|
101
|
+
});
|
|
102
|
+
it("should handle baseUrl for route matching and URL generation", async () => {
|
|
103
|
+
const spyFileManager = vi.fn();
|
|
104
|
+
const spyHome = vi.fn();
|
|
105
|
+
|
|
106
|
+
// Create history with a tenant prefix
|
|
107
|
+
const history = createMemoryHistory();
|
|
108
|
+
history.replace("/tenant123/__unknown__");
|
|
109
|
+
const gateway = new HistoryRouterGateway(history, "/tenant123");
|
|
110
|
+
gateway.setRoutes([{
|
|
111
|
+
name: "home",
|
|
112
|
+
path: "/",
|
|
113
|
+
onMatch: spyHome
|
|
114
|
+
}, {
|
|
115
|
+
name: "fileManager",
|
|
116
|
+
path: "/file-manager",
|
|
117
|
+
onMatch: spyFileManager
|
|
118
|
+
}]);
|
|
119
|
+
|
|
120
|
+
// Navigate to /tenant123/file-manager
|
|
121
|
+
history.push("/tenant123/file-manager");
|
|
122
|
+
await wait();
|
|
123
|
+
|
|
124
|
+
// Should match the /file-manager route
|
|
125
|
+
expect(spyFileManager).toHaveBeenCalledTimes(1);
|
|
126
|
+
expect(spyFileManager).toHaveBeenCalledWith({
|
|
127
|
+
name: "fileManager",
|
|
128
|
+
path: "/file-manager",
|
|
129
|
+
pathname: "/tenant123/file-manager",
|
|
130
|
+
params: {}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Test URL generation with baseUrl
|
|
134
|
+
const urlWithBase = RouteUrl.fromPattern("/file-manager", {}, "/tenant123");
|
|
135
|
+
expect(urlWithBase).toBe("/tenant123/file-manager");
|
|
136
|
+
const urlWithBaseAndParams = RouteUrl.fromPattern("/file-manager", {
|
|
137
|
+
folder: "abc"
|
|
138
|
+
}, "/tenant123");
|
|
139
|
+
expect(urlWithBaseAndParams).toBe("/tenant123/file-manager?folder=abc");
|
|
140
|
+
});
|
|
141
|
+
it("should properly sort routes with wildcards always at the bottom", async () => {
|
|
142
|
+
const spyWildcard = vi.fn();
|
|
143
|
+
const spySpecific = vi.fn();
|
|
144
|
+
const spyHome = vi.fn();
|
|
145
|
+
const history = createMemoryHistory();
|
|
146
|
+
// Start at a non-matching path to avoid initial route resolution
|
|
147
|
+
history.replace("/initial");
|
|
148
|
+
const gateway = new HistoryRouterGateway(history, "");
|
|
149
|
+
|
|
150
|
+
// Add wildcard first, then home route
|
|
151
|
+
// Note: setRoutes will trigger route resolution for current path (/initial)
|
|
152
|
+
gateway.setRoutes([{
|
|
153
|
+
name: "wildcard",
|
|
154
|
+
path: "*",
|
|
155
|
+
onMatch: spyWildcard
|
|
156
|
+
}, {
|
|
157
|
+
name: "home",
|
|
158
|
+
path: "/",
|
|
159
|
+
onMatch: spyHome
|
|
160
|
+
}]);
|
|
161
|
+
|
|
162
|
+
// Wildcard should have matched /initial
|
|
163
|
+
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
164
|
+
vi.clearAllMocks();
|
|
165
|
+
|
|
166
|
+
// Now add a specific route after the wildcard - this should re-sort and keep wildcard at bottom
|
|
167
|
+
// Note: setRoutes will trigger route resolution again for /initial, matching wildcard again
|
|
168
|
+
gateway.setRoutes([{
|
|
169
|
+
name: "specific",
|
|
170
|
+
path: "/specific-route",
|
|
171
|
+
onMatch: spySpecific
|
|
172
|
+
}]);
|
|
173
|
+
|
|
174
|
+
// Wildcard should match /initial again after re-sorting
|
|
175
|
+
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
176
|
+
vi.clearAllMocks();
|
|
177
|
+
|
|
178
|
+
// Navigate to the specific route
|
|
179
|
+
history.push("/specific-route");
|
|
180
|
+
await wait();
|
|
181
|
+
|
|
182
|
+
// Should match the specific route, not the wildcard
|
|
183
|
+
expect(spySpecific).toHaveBeenCalledTimes(1);
|
|
184
|
+
expect(spyWildcard).toHaveBeenCalledTimes(0);
|
|
185
|
+
expect(spyHome).toHaveBeenCalledTimes(0);
|
|
186
|
+
|
|
187
|
+
// Navigate to home
|
|
188
|
+
history.push("/");
|
|
189
|
+
await wait();
|
|
190
|
+
|
|
191
|
+
// Should match home route
|
|
192
|
+
expect(spyHome).toHaveBeenCalledTimes(1);
|
|
193
|
+
expect(spyWildcard).toHaveBeenCalledTimes(0);
|
|
194
|
+
|
|
195
|
+
// Navigate to unknown route
|
|
196
|
+
history.push("/unknown");
|
|
197
|
+
await wait();
|
|
198
|
+
|
|
199
|
+
// Should match wildcard
|
|
200
|
+
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
//# sourceMappingURL=HistoryRouterGateway.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["describe","it","beforeEach","expect","vi","createMemoryHistory","HistoryRouterGateway","RouteUrl","wait","Promise","resolve","setTimeout","clearAllMocks","spyHome","fn","spyLogin","spyDynamic","history","replace","gateway","setRoutes","name","path","onMatch","push","toHaveBeenCalledTimes","toHaveBeenNthCalledWith","pathname","params","toHaveBeenLastCalledWith","search","urls","fromPattern","redirect","reason","folderId","toEqual","spyFileManager","toHaveBeenCalledWith","urlWithBase","toBe","urlWithBaseAndParams","folder","spyWildcard","spySpecific"],"sources":["HistoryRouterGateway.test.ts"],"sourcesContent":["import { describe, it, beforeEach, expect, vi } from \"vitest\";\nimport { createMemoryHistory } from \"history\";\nimport { HistoryRouterGateway } from \"./HistoryRouterGateway.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\nconst wait = () => new Promise(resolve => setTimeout(resolve, 10));\n\ndescribe(\"Router Gateway\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"should execute onMatch when history changes\", async () => {\n const spyHome = vi.fn();\n const spyLogin = vi.fn();\n const spyDynamic = vi.fn();\n\n // Create `history` and set the initial pathname to an unknown route\n const history = createMemoryHistory();\n history.replace(\"/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"login\", path: \"/login\", onMatch: spyLogin },\n { name: \"test\", path: \"/dynamic-route/:name\", onMatch: spyDynamic }\n ]);\n\n history.push(\"/login\");\n await wait();\n history.push(\"/\");\n await wait();\n history.push(\"/dynamic-route/cars\");\n await wait();\n history.push(\"/login\");\n await wait();\n history.push(\"/dynamic-route/blogs\");\n await wait();\n history.push(\"/dynamic-route/blogs?search=123\");\n await wait();\n\n expect(spyLogin).toHaveBeenCalledTimes(2);\n expect(spyLogin).toHaveBeenNthCalledWith(1, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyLogin).toHaveBeenNthCalledWith(2, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyHome).toHaveBeenLastCalledWith({\n name: \"home\",\n path: \"/\",\n pathname: \"/\",\n params: {}\n });\n expect(spyDynamic).toHaveBeenCalledTimes(3);\n expect(spyDynamic).toHaveBeenNthCalledWith(1, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/cars\",\n params: {\n name: \"cars\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(2, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(3, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\",\n search: \"123\"\n }\n });\n });\n\n it(\"should generate route URLs\", async () => {\n const urls = [\n RouteUrl.fromPattern(\"/\"),\n RouteUrl.fromPattern(\"/login\", {}),\n RouteUrl.fromPattern(\"/login\", { redirect: \"/\", reason: \"login\" }),\n RouteUrl.fromPattern(\"/dynamic-route/:name\", { name: \"cars\" }),\n RouteUrl.fromPattern(\"/dynamic-route\", { folderId: \"696556831e485d00027a1a0b#0001\" })\n ];\n expect(urls).toEqual([\n \"/\",\n \"/login\",\n \"/login?redirect=%2F&reason=login\",\n \"/dynamic-route/cars\",\n \"/dynamic-route?folderId=696556831e485d00027a1a0b%230001\"\n ]);\n });\n\n it(\"should handle baseUrl for route matching and URL generation\", async () => {\n const spyFileManager = vi.fn();\n const spyHome = vi.fn();\n\n // Create history with a tenant prefix\n const history = createMemoryHistory();\n history.replace(\"/tenant123/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"/tenant123\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"fileManager\", path: \"/file-manager\", onMatch: spyFileManager }\n ]);\n\n // Navigate to /tenant123/file-manager\n history.push(\"/tenant123/file-manager\");\n await wait();\n\n // Should match the /file-manager route\n expect(spyFileManager).toHaveBeenCalledTimes(1);\n expect(spyFileManager).toHaveBeenCalledWith({\n name: \"fileManager\",\n path: \"/file-manager\",\n pathname: \"/tenant123/file-manager\",\n params: {}\n });\n\n // Test URL generation with baseUrl\n const urlWithBase = RouteUrl.fromPattern(\"/file-manager\", {}, \"/tenant123\");\n expect(urlWithBase).toBe(\"/tenant123/file-manager\");\n\n const urlWithBaseAndParams = RouteUrl.fromPattern(\n \"/file-manager\",\n { folder: \"abc\" },\n \"/tenant123\"\n );\n expect(urlWithBaseAndParams).toBe(\"/tenant123/file-manager?folder=abc\");\n });\n\n it(\"should properly sort routes with wildcards always at the bottom\", async () => {\n const spyWildcard = vi.fn();\n const spySpecific = vi.fn();\n const spyHome = vi.fn();\n\n const history = createMemoryHistory();\n // Start at a non-matching path to avoid initial route resolution\n history.replace(\"/initial\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n\n // Add wildcard first, then home route\n // Note: setRoutes will trigger route resolution for current path (/initial)\n gateway.setRoutes([\n { name: \"wildcard\", path: \"*\", onMatch: spyWildcard },\n { name: \"home\", path: \"/\", onMatch: spyHome }\n ]);\n\n // Wildcard should have matched /initial\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Now add a specific route after the wildcard - this should re-sort and keep wildcard at bottom\n // Note: setRoutes will trigger route resolution again for /initial, matching wildcard again\n gateway.setRoutes([{ name: \"specific\", path: \"/specific-route\", onMatch: spySpecific }]);\n\n // Wildcard should match /initial again after re-sorting\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Navigate to the specific route\n history.push(\"/specific-route\");\n await wait();\n\n // Should match the specific route, not the wildcard\n expect(spySpecific).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n expect(spyHome).toHaveBeenCalledTimes(0);\n\n // Navigate to home\n history.push(\"/\");\n await wait();\n\n // Should match home route\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n\n // Navigate to unknown route\n history.push(\"/unknown\");\n await wait();\n\n // Should match wildcard\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7D,SAASC,mBAAmB,QAAQ,SAAS;AAC7C,SAASC,oBAAoB;AAC7B,SAASC,QAAQ;AAEjB,MAAMC,IAAI,GAAGA,CAAA,KAAM,IAAIC,OAAO,CAACC,OAAO,IAAIC,UAAU,CAACD,OAAO,EAAE,EAAE,CAAC,CAAC;AAElEV,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC7BE,UAAU,CAAC,MAAM;IACbE,EAAE,CAACQ,aAAa,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFX,EAAE,CAAC,6CAA6C,EAAE,YAAY;IAC1D,MAAMY,OAAO,GAAGT,EAAE,CAACU,EAAE,CAAC,CAAC;IACvB,MAAMC,QAAQ,GAAGX,EAAE,CAACU,EAAE,CAAC,CA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ACAV,MAAM,CAACwC,WAAW,CAAC,CAAClB,qBAAqB,CAAC,CAAC,CAAC;IAC5CrB,EAAE,CAACQ,aAAa,CAAC,CAAC;;IAElB;IACA;IACAO,OAAO,CAACC,SAAS,CAAC,CAAC;MAAEC,IAAI,EAAE,UAAU;MAAEC,IAAI,EAAE,iBAAiB;MAAEC,OAAO,EAAEqB;IAAY,CAAC,CAAC,CAAC;;IAExF;IACAzC,MAAM,CAACwC,WAAW,CAAC,CAAClB,qBAAqB,CAAC,CAAC,CAAC;IAC5CrB,EAAE,CAACQ,aAAa,CAAC,CAAC;;IAElB;IACAK,OAAO,CAACO,IAAI,CAAC,iBAAiB,CAAC;IAC/B,MAAMhB,IAAI,CAAC,CAAC;;IAEZ;IACAL,MAAM,CAACyC,WAAW,CAAC,CAACnB,qBAAqB,CAAC,CAAC,CAAC;IAC5CtB,MAAM,CAACwC,WAAW,CAAC,CAAClB,qBAAqB,CAAC,CAAC,CAAC;IAC5CtB,MAAM,CAACU,OAAO,CAAC,CAACY,qBAAqB,CAAC,CAAC,CAAC;;IAExC;IACAR,OAAO,CAACO,IAAI,CAAC,GAAG,CAAC;IACjB,MAAMhB,IAAI,CAAC,CAAC;;IAEZ;IACAL,MAAM,CAACU,OAAO,CAAC,CAACY,qBAAqB,CAAC,CAAC,CAAC;IACxCtB,MAAM,CAACwC,WAAW,CAAC,CAAClB,qBAAqB,CAAC,CAAC,CAAC;;IAE5C;IACAR,OAAO,CAACO,IAAI,CAAC,UAAU,CAAC;IACxB,MAAMhB,IAAI,CAAC,CAAC;;IAEZ;IACAL,MAAM,CAACwC,WAAW,CAAC,CAAClB,qBAAqB,CAAC,CAAC,CAAC;EAChD,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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.looseObject(this.coerceParams(paramsSchema)) : 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 instanceof z.ZodOptional) {
|
|
27
|
+
isOptional = true;
|
|
28
|
+
base = base.unwrap();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// unwrap nullable
|
|
32
|
+
if (base instanceof z.ZodNullable) {
|
|
33
|
+
isNullable = true;
|
|
34
|
+
base = base.unwrap();
|
|
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","looseObject","coerceParams","name","path","shape","result","key","Object","entries","base","isOptional","isNullable","ZodOptional","unwrap","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 ? z.looseObject(this.coerceParams(paramsSchema)) : 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 instanceof z.ZodOptional) {\n isOptional = true;\n base = base.unwrap() as z.ZodTypeAny;\n }\n\n // unwrap nullable\n if (base instanceof z.ZodNullable) {\n isNullable = true;\n base = base.unwrap() as z.ZodTypeAny;\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,GAAGJ,CAAC,CAACQ,WAAW,CAAC,IAAI,CAACC,YAAY,CAACL,YAAY,CAAC,CAAC,GAAGE,SAAS;EAC3F;EAEA,IAAII,IAAIA,CAAA,EAAG;IACP,OAAO,IAAI,CAACP,KAAK,CAACO,IAAI;EAC1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ZD,IAAI,GAAGA,IAAI,CAACc,QAAQ,CAAC,CAAC;MAC1B;MAEAlB,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
|