@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,31 @@
|
|
|
1
|
+
import { makeAutoObservable } from "mobx";
|
|
2
|
+
import { LocalStorage as LocalStorageAbstraction, LocalStorageRepository } from "./abstractions.js";
|
|
3
|
+
import { createImplementation } from "@webiny/di";
|
|
4
|
+
class LocalStorageImpl {
|
|
5
|
+
constructor(repo) {
|
|
6
|
+
this.repo = repo;
|
|
7
|
+
makeAutoObservable(this);
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
return this.repo.get(key);
|
|
11
|
+
}
|
|
12
|
+
set(key, value) {
|
|
13
|
+
this.repo.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
remove(key) {
|
|
16
|
+
this.repo.remove(key);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.repo.clear();
|
|
20
|
+
}
|
|
21
|
+
keys() {
|
|
22
|
+
return this.repo.keys();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const LocalStorage = createImplementation({
|
|
26
|
+
abstraction: LocalStorageAbstraction,
|
|
27
|
+
implementation: LocalStorageImpl,
|
|
28
|
+
dependencies: [LocalStorageRepository]
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=LocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["makeAutoObservable","LocalStorage","LocalStorageAbstraction","LocalStorageRepository","createImplementation","LocalStorageImpl","constructor","repo","get","key","set","value","remove","clear","keys","abstraction","implementation","dependencies"],"sources":["LocalStorage.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport { LocalStorage as LocalStorageAbstraction, LocalStorageRepository } from \"./abstractions.js\";\nimport { createImplementation } from \"@webiny/di\";\n\nclass LocalStorageImpl implements LocalStorageAbstraction.Interface {\n constructor(private readonly repo: LocalStorageRepository.Interface) {\n makeAutoObservable(this);\n }\n\n get<T = string>(key: string) {\n return this.repo.get<T>(key);\n }\n set<T = string>(key: string, value: T) {\n this.repo.set(key, value);\n }\n remove(key: string) {\n this.repo.remove(key);\n }\n clear() {\n this.repo.clear();\n }\n keys() {\n return this.repo.keys();\n }\n}\n\nexport const LocalStorage = createImplementation({\n abstraction: LocalStorageAbstraction,\n implementation: LocalStorageImpl,\n dependencies: [LocalStorageRepository]\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,MAAM;AACzC,SAASC,YAAY,IAAIC,uBAAuB,EAAEC,sBAAsB;AACxE,SAASC,oBAAoB,QAAQ,YAAY;AAEjD,MAAMC,gBAAgB,CAA8C;EAChEC,WAAWA,CAAkBC,IAAsC,EAAE;IAAA,KAAxCA,IAAsC,GAAtCA,IAAsC;IAC/DP,kBAAkB,CAAC,IAAI,CAAC;EAC5B;EAEAQ,GAAGA,CAAaC,GAAW,EAAE;IACzB,OAAO,IAAI,CAACF,IAAI,CAACC,GAAG,CAAIC,GAAG,CAAC;EAChC;EACAC,GAAGA,CAAaD,GAAW,EAAEE,KAAQ,EAAE;IACnC,IAAI,CAACJ,IAAI,CAACG,GAAG,CAACD,GAAG,EAAEE,KAAK,CAAC;EAC7B;EACAC,MAAMA,CAACH,GAAW,EAAE;IAChB,IAAI,CAACF,IAAI,CAACK,MAAM,CAACH,GAAG,CAAC;EACzB;EACAI,KAAKA,CAAA,EAAG;IACJ,IAAI,CAACN,IAAI,CAACM,KAAK,CAAC,CAAC;EACrB;EACAC,IAAIA,CAAA,EAAG;IACH,OAAO,IAAI,CAACP,IAAI,CAACO,IAAI,CAAC,CAAC;EAC3B;AACJ;AAEA,OAAO,MAAMb,YAAY,GAAGG,oBAAoB,CAAC;EAC7CW,WAAW,EAAEb,uBAAuB;EACpCc,cAAc,EAAEX,gBAAgB;EAChCY,YAAY,EAAE,CAACd,sBAAsB;AACzC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LocalStorageRepository as LocalStorageRepositoryAbstraction, LocalStorageConfig, LocalStorageGateway } from "./abstractions.js";
|
|
2
|
+
export declare class LocalStorageRepositoryImpl implements LocalStorageRepositoryAbstraction.Interface {
|
|
3
|
+
private gateway;
|
|
4
|
+
private readonly prefix;
|
|
5
|
+
private store;
|
|
6
|
+
private unsubscribe?;
|
|
7
|
+
constructor(gateway: LocalStorageGateway.Interface, config: LocalStorageConfig.Interface);
|
|
8
|
+
private withPrefix;
|
|
9
|
+
private stripPrefix;
|
|
10
|
+
private bootstrap;
|
|
11
|
+
private subscribeToChanges;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
has(key: string): boolean;
|
|
14
|
+
get<T = string>(key: string): T | undefined;
|
|
15
|
+
set<T = string>(key: string, value: T): void;
|
|
16
|
+
remove(key: string): void;
|
|
17
|
+
clear(): void;
|
|
18
|
+
keys(): string[];
|
|
19
|
+
}
|
|
20
|
+
export declare const LocalStorageRepository: import("@webiny/di").Implementation<typeof LocalStorageRepositoryImpl>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { makeAutoObservable, runInAction } from "mobx";
|
|
2
|
+
import { LocalStorageRepository as LocalStorageRepositoryAbstraction, LocalStorageConfig, LocalStorageGateway } from "./abstractions.js";
|
|
3
|
+
import { createImplementation } from "@webiny/di";
|
|
4
|
+
export class LocalStorageRepositoryImpl {
|
|
5
|
+
store = new Map();
|
|
6
|
+
constructor(gateway, config) {
|
|
7
|
+
this.gateway = gateway;
|
|
8
|
+
this.prefix = config.prefix || "";
|
|
9
|
+
makeAutoObservable(this);
|
|
10
|
+
this.bootstrap();
|
|
11
|
+
this.subscribeToChanges();
|
|
12
|
+
}
|
|
13
|
+
withPrefix(key) {
|
|
14
|
+
return this.prefix ? `${this.prefix}:${key}` : key;
|
|
15
|
+
}
|
|
16
|
+
stripPrefix(key) {
|
|
17
|
+
return this.prefix ? key.replace(new RegExp(`^${this.prefix}:`), "") : key;
|
|
18
|
+
}
|
|
19
|
+
bootstrap() {
|
|
20
|
+
const all = this.gateway.getAll();
|
|
21
|
+
for (const [key, value] of Object.entries(all)) {
|
|
22
|
+
if (!this.prefix || key.startsWith(this.prefix + ":")) {
|
|
23
|
+
this.store.set(this.stripPrefix(key), value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
subscribeToChanges() {
|
|
28
|
+
this.unsubscribe = this.gateway.subscribe(ev => {
|
|
29
|
+
runInAction(() => {
|
|
30
|
+
if (ev instanceof StorageEvent && ev.key) {
|
|
31
|
+
if (!this.prefix || ev.key.startsWith(this.prefix + ":")) {
|
|
32
|
+
const cleanKey = this.stripPrefix(ev.key);
|
|
33
|
+
if (ev.newValue !== null) {
|
|
34
|
+
try {
|
|
35
|
+
this.store.set(cleanKey, JSON.parse(ev.newValue));
|
|
36
|
+
} catch {
|
|
37
|
+
this.store.set(cleanKey, ev.newValue);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
this.store.delete(cleanKey);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (ev instanceof CustomEvent) {
|
|
45
|
+
const {
|
|
46
|
+
key,
|
|
47
|
+
value,
|
|
48
|
+
action
|
|
49
|
+
} = ev.detail;
|
|
50
|
+
if (!this.prefix || key.startsWith(this.prefix + ":")) {
|
|
51
|
+
const cleanKey = this.stripPrefix(key);
|
|
52
|
+
if (action === "set") {
|
|
53
|
+
this.store.set(cleanKey, value);
|
|
54
|
+
}
|
|
55
|
+
if (action === "remove") {
|
|
56
|
+
this.store.delete(cleanKey);
|
|
57
|
+
}
|
|
58
|
+
if (action === "clear") {
|
|
59
|
+
this.store.clear();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
destroy() {
|
|
67
|
+
this.unsubscribe?.();
|
|
68
|
+
}
|
|
69
|
+
has(key) {
|
|
70
|
+
return this.store.has(key);
|
|
71
|
+
}
|
|
72
|
+
get(key) {
|
|
73
|
+
return this.store.get(key);
|
|
74
|
+
}
|
|
75
|
+
set(key, value) {
|
|
76
|
+
this.gateway.set(this.withPrefix(key), value);
|
|
77
|
+
}
|
|
78
|
+
remove(key) {
|
|
79
|
+
this.gateway.remove(this.withPrefix(key));
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
this.gateway.clear();
|
|
83
|
+
this.store.clear();
|
|
84
|
+
}
|
|
85
|
+
keys() {
|
|
86
|
+
return Array.from(this.store.keys());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export const LocalStorageRepository = createImplementation({
|
|
90
|
+
abstraction: LocalStorageRepositoryAbstraction,
|
|
91
|
+
implementation: LocalStorageRepositoryImpl,
|
|
92
|
+
dependencies: [LocalStorageGateway, LocalStorageConfig]
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=LocalStorageRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["makeAutoObservable","runInAction","LocalStorageRepository","LocalStorageRepositoryAbstraction","LocalStorageConfig","LocalStorageGateway","createImplementation","LocalStorageRepositoryImpl","store","Map","constructor","gateway","config","prefix","bootstrap","subscribeToChanges","withPrefix","key","stripPrefix","replace","RegExp","all","getAll","value","Object","entries","startsWith","set","unsubscribe","subscribe","ev","StorageEvent","cleanKey","newValue","JSON","parse","delete","CustomEvent","action","detail","clear","destroy","has","get","remove","keys","Array","from","abstraction","implementation","dependencies"],"sources":["LocalStorageRepository.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport {\n LocalStorageRepository as LocalStorageRepositoryAbstraction,\n LocalStorageConfig,\n LocalStorageGateway\n} from \"./abstractions.js\";\nimport { createImplementation } from \"@webiny/di\";\n\nexport class LocalStorageRepositoryImpl implements LocalStorageRepositoryAbstraction.Interface {\n private readonly prefix: string;\n private store = new Map<string, unknown>();\n private unsubscribe?: () => void;\n\n constructor(\n private gateway: LocalStorageGateway.Interface,\n config: LocalStorageConfig.Interface\n ) {\n this.prefix = config.prefix || \"\";\n makeAutoObservable(this);\n\n this.bootstrap();\n this.subscribeToChanges();\n }\n\n private withPrefix(key: string): string {\n return this.prefix ? `${this.prefix}:${key}` : key;\n }\n\n private stripPrefix(key: string): string {\n return this.prefix ? key.replace(new RegExp(`^${this.prefix}:`), \"\") : key;\n }\n\n private bootstrap() {\n const all = this.gateway.getAll();\n for (const [key, value] of Object.entries(all)) {\n if (!this.prefix || key.startsWith(this.prefix + \":\")) {\n this.store.set(this.stripPrefix(key), value);\n }\n }\n }\n\n private subscribeToChanges() {\n this.unsubscribe = this.gateway.subscribe(ev => {\n runInAction(() => {\n if (ev instanceof StorageEvent && ev.key) {\n if (!this.prefix || ev.key.startsWith(this.prefix + \":\")) {\n const cleanKey = this.stripPrefix(ev.key);\n if (ev.newValue !== null) {\n try {\n this.store.set(cleanKey, JSON.parse(ev.newValue));\n } catch {\n this.store.set(cleanKey, ev.newValue);\n }\n } else {\n this.store.delete(cleanKey);\n }\n }\n }\n if (ev instanceof CustomEvent) {\n const { key, value, action } = ev.detail;\n if (!this.prefix || key.startsWith(this.prefix + \":\")) {\n const cleanKey = this.stripPrefix(key);\n if (action === \"set\") {\n this.store.set(cleanKey, value);\n }\n if (action === \"remove\") {\n this.store.delete(cleanKey);\n }\n if (action === \"clear\") {\n this.store.clear();\n }\n }\n }\n });\n });\n }\n\n destroy() {\n this.unsubscribe?.();\n }\n\n has(key: string) {\n return this.store.has(key);\n }\n get<T = string>(key: string) {\n return this.store.get(key) as T | undefined;\n }\n set<T = string>(key: string, value: T) {\n this.gateway.set(this.withPrefix(key), value);\n }\n remove(key: string) {\n this.gateway.remove(this.withPrefix(key));\n }\n clear() {\n this.gateway.clear();\n this.store.clear();\n }\n keys(): string[] {\n return Array.from(this.store.keys());\n }\n}\n\nexport const LocalStorageRepository = createImplementation({\n abstraction: LocalStorageRepositoryAbstraction,\n implementation: LocalStorageRepositoryImpl,\n dependencies: [LocalStorageGateway, LocalStorageConfig]\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,WAAW,QAAQ,MAAM;AACtD,SACIC,sBAAsB,IAAIC,iCAAiC,EAC3DC,kBAAkB,EAClBC,mBAAmB;AAEvB,SAASC,oBAAoB,QAAQ,YA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C,KAAK,CAAC,CAAC;YACtB;UACJ;QACJ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN;EAEAC,OAAOA,CAAA,EAAG;IACN,IAAI,CAACb,WAAW,GAAG,CAAC;EACxB;EAEAc,GAAGA,CAACzB,GAAW,EAAE;IACb,OAAO,IAAI,CAACT,KAAK,CAACkC,GAAG,CAACzB,GAAG,CAAC;EAC9B;EACA0B,GAAGA,CAAa1B,GAAW,EAAE;IACzB,OAAO,IAAI,CAACT,KAAK,CAACmC,GAAG,CAAC1B,GAAG,CAAC;EAC9B;EACAU,GAAGA,CAAaV,GAAW,EAAEM,KAAQ,EAAE;IACnC,IAAI,CAACZ,OAAO,CAACgB,GAAG,CAAC,IAAI,CAACX,UAAU,CAACC,GAAG,CAAC,EAAEM,KAAK,CAAC;EACjD;EACAqB,MAAMA,CAAC3B,GAAW,EAAE;IAChB,IAAI,CAACN,OAAO,CAACiC,MAAM,CAAC,IAAI,CAAC5B,UAAU,CAACC,GAAG,CAAC,CAAC;EAC7C;EACAuB,KAAKA,CAAA,EAAG;IACJ,IAAI,CAAC7B,OAAO,CAAC6B,KAAK,CAAC,CAAC;IACpB,IAAI,CAAChC,KAAK,CAACgC,KAAK,CAAC,CAAC;EACtB;EACAK,IAAIA,CAAA,EAAa;IACb,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACvC,KAAK,CAACqC,IAAI,CAAC,CAAC,CAAC;EACxC;AACJ;AAEA,OAAO,MAAM3C,sBAAsB,GAAGI,oBAAoB,CAAC;EACvD0C,WAAW,EAAE7C,iCAAiC;EAC9C8C,cAAc,EAAE1C,0BAA0B;EAC1C2C,YAAY,EAAE,CAAC7C,mBAAmB,EAAED,kBAAkB;AAC1D,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Abstraction } from "@webiny/di";
|
|
2
|
+
/** Gateway: raw IO into localStorage (or other storage). */
|
|
3
|
+
export interface ILocalStorageGateway {
|
|
4
|
+
get<T = string>(key: string): T | null;
|
|
5
|
+
set<T = string>(key: string, value: T): void;
|
|
6
|
+
remove(key: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
getAll(): Record<string, unknown>;
|
|
9
|
+
subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const LocalStorageGateway: Abstraction<ILocalStorageGateway>;
|
|
12
|
+
export declare namespace LocalStorageGateway {
|
|
13
|
+
type Interface = ILocalStorageGateway;
|
|
14
|
+
}
|
|
15
|
+
/** Repository: reactive state (MobX), synchronized with gateway. */
|
|
16
|
+
export interface ILocalStorageRepository {
|
|
17
|
+
has(key: string): boolean;
|
|
18
|
+
get<T = string>(key: string): T | undefined;
|
|
19
|
+
set<T = string>(key: string, value: T): void;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
clear(): void;
|
|
22
|
+
keys(): string[];
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const LocalStorageRepository: Abstraction<ILocalStorageRepository>;
|
|
26
|
+
export declare namespace LocalStorageRepository {
|
|
27
|
+
type Interface = ILocalStorageRepository;
|
|
28
|
+
}
|
|
29
|
+
/** Config: configure key prefixes, etc. */
|
|
30
|
+
export interface ILocalStorageConfig {
|
|
31
|
+
prefix?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare const LocalStorageConfig: Abstraction<ILocalStorageConfig>;
|
|
34
|
+
export declare namespace LocalStorageConfig {
|
|
35
|
+
type Interface = ILocalStorageConfig;
|
|
36
|
+
}
|
|
37
|
+
/** Service: thin façade, delegates to repository for consumers. */
|
|
38
|
+
export interface ILocalStorage {
|
|
39
|
+
get<T = string>(key: string): T | undefined;
|
|
40
|
+
set<T = string>(key: string, value: T): void;
|
|
41
|
+
remove(key: string): void;
|
|
42
|
+
clear(): void;
|
|
43
|
+
keys(): string[];
|
|
44
|
+
}
|
|
45
|
+
export declare const LocalStorage: Abstraction<ILocalStorage>;
|
|
46
|
+
export declare namespace LocalStorage {
|
|
47
|
+
type Interface = ILocalStorage;
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Abstraction } from "@webiny/di";
|
|
2
|
+
|
|
3
|
+
/** Gateway: raw IO into localStorage (or other storage). */
|
|
4
|
+
|
|
5
|
+
export const LocalStorageGateway = new Abstraction("LocalStorageGateway");
|
|
6
|
+
|
|
7
|
+
/** Repository: reactive state (MobX), synchronized with gateway. */
|
|
8
|
+
|
|
9
|
+
export const LocalStorageRepository = new Abstraction("LocalStorageRepository");
|
|
10
|
+
|
|
11
|
+
/** Config: configure key prefixes, etc. */
|
|
12
|
+
|
|
13
|
+
export const LocalStorageConfig = new Abstraction("LocalStorageConfig");
|
|
14
|
+
|
|
15
|
+
/** Service: thin façade, delegates to repository for consumers. */
|
|
16
|
+
|
|
17
|
+
export const LocalStorage = new Abstraction("LocalStorage");
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Abstraction","LocalStorageGateway","LocalStorageRepository","LocalStorageConfig","LocalStorage"],"sources":["abstractions.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\n/** Gateway: raw IO into localStorage (or other storage). */\nexport interface ILocalStorageGateway {\n get<T = string>(key: string): T | null;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n getAll(): Record<string, unknown>;\n subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;\n}\n\nexport const LocalStorageGateway = new Abstraction<ILocalStorageGateway>(\"LocalStorageGateway\");\n\nexport namespace LocalStorageGateway {\n export type Interface = ILocalStorageGateway;\n}\n\n/** Repository: reactive state (MobX), synchronized with gateway. */\nexport interface ILocalStorageRepository {\n has(key: string): boolean;\n get<T = string>(key: string): T | undefined;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n keys(): string[];\n destroy(): void;\n}\n\nexport const LocalStorageRepository = new Abstraction<ILocalStorageRepository>(\n \"LocalStorageRepository\"\n);\n\nexport namespace LocalStorageRepository {\n export type Interface = ILocalStorageRepository;\n}\n\n/** Config: configure key prefixes, etc. */\nexport interface ILocalStorageConfig {\n prefix?: string;\n}\n\nexport const LocalStorageConfig = new Abstraction<ILocalStorageConfig>(\"LocalStorageConfig\");\n\nexport namespace LocalStorageConfig {\n export type Interface = ILocalStorageConfig;\n}\n\n/** Service: thin façade, delegates to repository for consumers. */\nexport interface ILocalStorage {\n get<T = string>(key: string): T | undefined;\n set<T = string>(key: string, value: T): void;\n remove(key: string): void;\n clear(): void;\n keys(): string[];\n}\n\nexport const LocalStorage = new Abstraction<ILocalStorage>(\"LocalStorage\");\n\nexport namespace LocalStorage {\n export type Interface = ILocalStorage;\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,YAAY;;AAExC;;AAUA,OAAO,MAAMC,mBAAmB,GAAG,IAAID,WAAW,CAAuB,qBAAqB,CAAC;;AAM/F;;AAWA,OAAO,MAAME,sBAAsB,GAAG,IAAIF,WAAW,CACjD,wBACJ,CAAC;;AAMD;;AAKA,OAAO,MAAMG,kBAAkB,GAAG,IAAIH,WAAW,CAAsB,oBAAoB,CAAC;;AAM5F;;AASA,OAAO,MAAMI,YAAY,GAAG,IAAIJ,WAAW,CAAgB,cAAc,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalStorageFeature wires together:
|
|
3
|
+
* - BrowserLocalStorageGateway (default gateway)
|
|
4
|
+
* - LocalStorageRepository (reactive MobX mirror)
|
|
5
|
+
* - LocalStorage (thin consumer-facing facade)
|
|
6
|
+
*/
|
|
7
|
+
export declare const LocalStorageFeature: import("~/shared/di/createFeature.js").FeatureDefinition<{
|
|
8
|
+
localStorageService: import("./abstractions.js").ILocalStorage;
|
|
9
|
+
localStorageConfig: import("./abstractions.js").ILocalStorageConfig;
|
|
10
|
+
}, [config?: {
|
|
11
|
+
prefix?: string;
|
|
12
|
+
} | undefined]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LocalStorageConfig, LocalStorageGateway, LocalStorage as Abstraction } from "./abstractions.js";
|
|
2
|
+
import { BrowserLocalStorageGateway } from "./BrowserLocalStorageGateway.js";
|
|
3
|
+
import { LocalStorageRepository } from "./LocalStorageRepository.js";
|
|
4
|
+
import { LocalStorage } from "./LocalStorage.js";
|
|
5
|
+
import { createFeature } from "../../shared/di/createFeature.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* LocalStorageFeature wires together:
|
|
9
|
+
* - BrowserLocalStorageGateway (default gateway)
|
|
10
|
+
* - LocalStorageRepository (reactive MobX mirror)
|
|
11
|
+
* - LocalStorage (thin consumer-facing facade)
|
|
12
|
+
*/
|
|
13
|
+
export const LocalStorageFeature = createFeature({
|
|
14
|
+
name: "LocalStorage",
|
|
15
|
+
register(container, config = {}) {
|
|
16
|
+
// Register config (tenant prefix, etc.)
|
|
17
|
+
container.registerInstance(LocalStorageConfig, config);
|
|
18
|
+
|
|
19
|
+
// Gateway: browser localStorage
|
|
20
|
+
container.registerInstance(LocalStorageGateway, new BrowserLocalStorageGateway());
|
|
21
|
+
|
|
22
|
+
// Repository & Service
|
|
23
|
+
container.register(LocalStorageRepository).inSingletonScope();
|
|
24
|
+
container.register(LocalStorage).inSingletonScope();
|
|
25
|
+
},
|
|
26
|
+
resolve(container) {
|
|
27
|
+
return {
|
|
28
|
+
localStorageService: container.resolve(Abstraction),
|
|
29
|
+
localStorageConfig: container.resolve(LocalStorageConfig)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LocalStorageConfig","LocalStorageGateway","LocalStorage","Abstraction","BrowserLocalStorageGateway","LocalStorageRepository","createFeature","LocalStorageFeature","name","register","container","config","registerInstance","inSingletonScope","resolve","localStorageService","localStorageConfig"],"sources":["feature.ts"],"sourcesContent":["import {\n LocalStorageConfig,\n LocalStorageGateway,\n LocalStorage as Abstraction\n} from \"./abstractions.js\";\nimport { BrowserLocalStorageGateway } from \"./BrowserLocalStorageGateway.js\";\nimport { LocalStorageRepository } from \"./LocalStorageRepository.js\";\nimport { LocalStorage } from \"./LocalStorage.js\";\nimport { createFeature } from \"~/shared/di/createFeature.js\";\n\n/**\n * LocalStorageFeature wires together:\n * - BrowserLocalStorageGateway (default gateway)\n * - LocalStorageRepository (reactive MobX mirror)\n * - LocalStorage (thin consumer-facing facade)\n */\nexport const LocalStorageFeature = createFeature({\n name: \"LocalStorage\",\n register(container, config: { prefix?: string } = {}) {\n // Register config (tenant prefix, etc.)\n container.registerInstance(LocalStorageConfig, config);\n\n // Gateway: browser localStorage\n container.registerInstance(LocalStorageGateway, new BrowserLocalStorageGateway());\n\n // Repository & Service\n container.register(LocalStorageRepository).inSingletonScope();\n container.register(LocalStorage).inSingletonScope();\n },\n resolve(container) {\n return {\n localStorageService: container.resolve(Abstraction),\n localStorageConfig: container.resolve(LocalStorageConfig)\n };\n }\n});\n"],"mappings":"AAAA,SACIA,kBAAkB,EAClBC,mBAAmB,EACnBC,YAAY,IAAIC,WAAW;AAE/B,SAASC,0BAA0B;AACnC,SAASC,sBAAsB;AAC/B,SAASH,YAAY;AACrB,SAASI,aAAa;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,GAAGD,aAAa,CAAC;EAC7CE,IAAI,EAAE,cAAc;EACpBC,QAAQA,CAACC,SAAS,EAAEC,MAA2B,GAAG,CAAC,CAAC,EAAE;IAClD;IACAD,SAAS,CAACE,gBAAgB,CAACZ,kBAAkB,EAAEW,MAAM,CAAC;;IAEtD;IACAD,SAAS,CAACE,gBAAgB,CAACX,mBAAmB,EAAE,IAAIG,0BAA0B,CAAC,CAAC,CAAC;;IAEjF;IACAM,SAAS,CAACD,QAAQ,CAACJ,sBAAsB,CAAC,CAACQ,gBAAgB,CAAC,CAAC;IAC7DH,SAAS,CAACD,QAAQ,CAACP,YAAY,CAAC,CAACW,gBAAgB,CAAC,CAAC;EACvD,CAAC;EACDC,OAAOA,CAACJ,SAAS,EAAE;IACf,OAAO;MACHK,mBAAmB,EAAEL,SAAS,CAACI,OAAO,CAACX,WAAW,CAAC;MACnDa,kBAAkB,EAAEN,SAAS,CAACI,OAAO,CAACd,kBAAkB;IAC5D,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LocalStorage, LocalStorageGateway, LocalStorageRepository, LocalStorageConfig } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LocalStorage","LocalStorageGateway","LocalStorageRepository","LocalStorageConfig"],"sources":["index.ts"],"sourcesContent":["export {\n LocalStorage,\n LocalStorageGateway,\n LocalStorageRepository,\n LocalStorageConfig\n} from \"./abstractions.js\";\n"],"mappings":"AAAA,SACIA,YAAY,EACZC,mBAAmB,EACnBC,sBAAsB,EACtBC,kBAAkB","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MainGraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { GraphQLClient } from "../../features/graphqlClient/abstractions.js";
|
|
3
|
+
import { EnvConfig } from "../../features/envConfig/index.js";
|
|
4
|
+
declare class MainGraphQLClientImpl implements MainGraphQLClient.Interface {
|
|
5
|
+
private client;
|
|
6
|
+
private readonly endpoint;
|
|
7
|
+
constructor(envConfig: EnvConfig.Interface, client: GraphQLClient.Interface);
|
|
8
|
+
execute<TResult = any, TVariables = any>(params: MainGraphQLClient.Request<TVariables>): Promise<TResult>;
|
|
9
|
+
}
|
|
10
|
+
export declare const DefaultMainGraphQLClient: import("@webiny/di").Implementation<typeof MainGraphQLClientImpl>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/di";
|
|
2
|
+
import { MainGraphQLClient } from "./abstractions.js";
|
|
3
|
+
import { GraphQLClient } from "../graphqlClient/abstractions.js";
|
|
4
|
+
import { EnvConfig } from "../envConfig/index.js";
|
|
5
|
+
class MainGraphQLClientImpl {
|
|
6
|
+
constructor(envConfig, client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.endpoint = envConfig.get("graphqlApiUrl");
|
|
9
|
+
}
|
|
10
|
+
async execute(params) {
|
|
11
|
+
return this.client.execute({
|
|
12
|
+
endpoint: this.endpoint,
|
|
13
|
+
...params
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const DefaultMainGraphQLClient = createImplementation({
|
|
18
|
+
abstraction: MainGraphQLClient,
|
|
19
|
+
implementation: MainGraphQLClientImpl,
|
|
20
|
+
dependencies: [EnvConfig, GraphQLClient]
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=MainGraphQLClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createImplementation","MainGraphQLClient","GraphQLClient","EnvConfig","MainGraphQLClientImpl","constructor","envConfig","client","endpoint","get","execute","params","DefaultMainGraphQLClient","abstraction","implementation","dependencies"],"sources":["MainGraphQLClient.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { MainGraphQLClient } from \"./abstractions.js\";\nimport { GraphQLClient } from \"~/features/graphqlClient/abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\nclass MainGraphQLClientImpl implements MainGraphQLClient.Interface {\n private readonly endpoint: string;\n\n constructor(\n envConfig: EnvConfig.Interface,\n private client: GraphQLClient.Interface\n ) {\n this.endpoint = envConfig.get(\"graphqlApiUrl\");\n }\n\n async execute<TResult = any, TVariables = any>(\n params: MainGraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n return this.client.execute({ endpoint: this.endpoint, ...params });\n }\n}\n\nexport const DefaultMainGraphQLClient = createImplementation({\n abstraction: MainGraphQLClient,\n implementation: MainGraphQLClientImpl,\n dependencies: [EnvConfig, GraphQLClient]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,iBAAiB;AAC1B,SAASC,aAAa;AACtB,SAASC,SAAS;AAElB,MAAMC,qBAAqB,CAAwC;EAG/DC,WAAWA,CACPC,SAA8B,EACtBC,MAA+B,EACzC;IAAA,KADUA,MAA+B,GAA/BA,MAA+B;IAEvC,IAAI,CAACC,QAAQ,GAAGF,SAAS,CAACG,GAAG,CAAC,eAAe,CAAC;EAClD;EAEA,MAAMC,OAAOA,CACTC,MAA6C,EAC7B;IAChB,OAAO,IAAI,CAACJ,MAAM,CAACG,OAAO,CAAC;MAAEF,QAAQ,EAAE,IAAI,CAACA,QAAQ;MAAE,GAAGG;IAAO,CAAC,CAAC;EACtE;AACJ;AAEA,OAAO,MAAMC,wBAAwB,GAAGZ,oBAAoB,CAAC;EACzDa,WAAW,EAAEZ,iBAAiB;EAC9Ba,cAAc,EAAEV,qBAAqB;EACrCW,YAAY,EAAE,CAACZ,SAAS,EAAED,aAAa;AAC3C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DocumentNode } from "graphql";
|
|
2
|
+
type IHeaders = Record<string, string | number | undefined>;
|
|
3
|
+
type MainGraphQLRequest<TVariables = any> = {
|
|
4
|
+
query: DocumentNode | string;
|
|
5
|
+
variables?: TVariables;
|
|
6
|
+
headers?: IHeaders;
|
|
7
|
+
};
|
|
8
|
+
export interface IMainGraphQLClient {
|
|
9
|
+
execute<TResult = any, TVariables = any>(params: MainGraphQLRequest<TVariables>): Promise<TResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare const MainGraphQLClient: import("@webiny/di").Abstraction<IMainGraphQLClient>;
|
|
12
|
+
export declare namespace MainGraphQLClient {
|
|
13
|
+
type Headers = IHeaders;
|
|
14
|
+
type Interface = IMainGraphQLClient;
|
|
15
|
+
type Request<TVariables = any> = MainGraphQLRequest<TVariables>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","MainGraphQLClient"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype MainGraphQLRequest<TVariables = any> = {\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IMainGraphQLClient {\n execute<TResult = any, TVariables = any>(\n params: MainGraphQLRequest<TVariables>\n ): Promise<TResult>;\n}\n\nexport const MainGraphQLClient = createAbstraction<IMainGraphQLClient>(\"MainGraphQLClient\");\n\nexport namespace MainGraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IMainGraphQLClient;\n export type Request<TVariables = any> = MainGraphQLRequest<TVariables>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAiBzD,OAAO,MAAMC,iBAAiB,GAAGD,iBAAiB,CAAqB,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MainGraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { DefaultMainGraphQLClient } from "./MainGraphQLClient.js";
|
|
3
|
+
import { createFeature } from "../../shared/di/createFeature.js";
|
|
4
|
+
export const MainGraphQLClientFeature = createFeature({
|
|
5
|
+
name: "MainGraphQLClient",
|
|
6
|
+
register(container) {
|
|
7
|
+
container.register(DefaultMainGraphQLClient).inSingletonScope();
|
|
8
|
+
},
|
|
9
|
+
resolve(container) {
|
|
10
|
+
return {
|
|
11
|
+
client: container.resolve(MainGraphQLClient)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MainGraphQLClient","DefaultMainGraphQLClient","createFeature","MainGraphQLClientFeature","name","register","container","inSingletonScope","resolve","client"],"sources":["feature.ts"],"sourcesContent":["import { MainGraphQLClient } from \"./abstractions.js\";\nimport { DefaultMainGraphQLClient } from \"./MainGraphQLClient.js\";\nimport { createFeature } from \"~/shared/di/createFeature.js\";\n\nexport const MainGraphQLClientFeature = createFeature({\n name: \"MainGraphQLClient\",\n register(container) {\n container.register(DefaultMainGraphQLClient).inSingletonScope();\n },\n resolve(container) {\n return {\n client: container.resolve(MainGraphQLClient)\n };\n }\n});\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,wBAAwB;AACjC,SAASC,aAAa;AAEtB,OAAO,MAAMC,wBAAwB,GAAGD,aAAa,CAAC;EAClDE,IAAI,EAAE,mBAAmB;EACzBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACJ,wBAAwB,CAAC,CAACM,gBAAgB,CAAC,CAAC;EACnE,CAAC;EACDC,OAAOA,CAACF,SAAS,EAAE;IACf,OAAO;MACHG,MAAM,EAAEH,SAAS,CAACE,OAAO,CAACR,iBAAiB;IAC/C,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MainGraphQLClient } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MainGraphQLClient"],"sources":["index.ts"],"sourcesContent":["export { MainGraphQLClient } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { History } from "history";
|
|
3
|
+
import type { RouteDefinition, RouteTransitionGuardConfig, GuardDisposer } from "./abstractions.js";
|
|
4
|
+
import { RouterGateway } from "./abstractions.js";
|
|
5
|
+
export declare class HistoryRouterGateway implements RouterGateway.Interface {
|
|
6
|
+
private readonly history;
|
|
7
|
+
private readonly router;
|
|
8
|
+
private stopListening;
|
|
9
|
+
private unblock;
|
|
10
|
+
private guards;
|
|
11
|
+
constructor(history: History, baseUrl: string);
|
|
12
|
+
addGuard(config: RouteTransitionGuardConfig): GuardDisposer;
|
|
13
|
+
goToRoute(name: string, params: z.ZodTypeAny): void;
|
|
14
|
+
setRoutes(routes: RouteDefinition[]): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
pushState(url: string): void;
|
|
17
|
+
private resolvePathname;
|
|
18
|
+
private findBlockingGuard;
|
|
19
|
+
private installBlocker;
|
|
20
|
+
private removeBlocker;
|
|
21
|
+
private removeBlockerAndRetry;
|
|
22
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { RouteUrl } from "./RouteUrl.js";
|
|
2
|
+
import { Router } from "./Router.js";
|
|
3
|
+
export class HistoryRouterGateway {
|
|
4
|
+
guards = new Set();
|
|
5
|
+
constructor(history, baseUrl) {
|
|
6
|
+
this.history = history;
|
|
7
|
+
this.router = new Router(baseUrl);
|
|
8
|
+
this.stopListening = history.listen(async ({
|
|
9
|
+
location
|
|
10
|
+
}) => {
|
|
11
|
+
const queryParams = Object.fromEntries(new URLSearchParams(location.search).entries());
|
|
12
|
+
this.resolvePathname(location.pathname, queryParams);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
addGuard(config) {
|
|
16
|
+
const hadGuards = this.guards.size > 0;
|
|
17
|
+
this.guards.add(config);
|
|
18
|
+
if (!hadGuards) {
|
|
19
|
+
this.installBlocker();
|
|
20
|
+
}
|
|
21
|
+
return () => {
|
|
22
|
+
this.guards.delete(config);
|
|
23
|
+
if (this.guards.size === 0) {
|
|
24
|
+
this.removeBlocker();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
goToRoute(name, params) {
|
|
29
|
+
const route = this.router.findRoute(name);
|
|
30
|
+
if (!route) {
|
|
31
|
+
console.warn(`Route "${name}" not found.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const baseUrl = this.router.getBaseUrl();
|
|
35
|
+
this.history.push(RouteUrl.fromPattern(route.path, params, baseUrl));
|
|
36
|
+
}
|
|
37
|
+
setRoutes(routes) {
|
|
38
|
+
this.router.setRoutes(routes);
|
|
39
|
+
const queryParams = Object.fromEntries(new URLSearchParams(this.history.location.search).entries());
|
|
40
|
+
const currentPathname = this.history.location.pathname;
|
|
41
|
+
this.resolvePathname(currentPathname, queryParams);
|
|
42
|
+
}
|
|
43
|
+
destroy() {
|
|
44
|
+
this.stopListening();
|
|
45
|
+
this.removeBlocker();
|
|
46
|
+
this.guards.clear();
|
|
47
|
+
}
|
|
48
|
+
pushState(url) {
|
|
49
|
+
this.history.push(url);
|
|
50
|
+
}
|
|
51
|
+
async resolvePathname(pathname, queryParams) {
|
|
52
|
+
const result = this.router.resolve(pathname, queryParams);
|
|
53
|
+
if (!result) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const {
|
|
57
|
+
matchedRoute,
|
|
58
|
+
onMatch
|
|
59
|
+
} = result;
|
|
60
|
+
onMatch(matchedRoute);
|
|
61
|
+
}
|
|
62
|
+
findBlockingGuard() {
|
|
63
|
+
for (const config of this.guards) {
|
|
64
|
+
if (config.guard()) {
|
|
65
|
+
return config;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
installBlocker() {
|
|
71
|
+
if (this.unblock) {
|
|
72
|
+
this.unblock();
|
|
73
|
+
}
|
|
74
|
+
this.unblock = this.history.block(tx => {
|
|
75
|
+
const blockingGuard = this.findBlockingGuard();
|
|
76
|
+
if (blockingGuard) {
|
|
77
|
+
let resolved = false;
|
|
78
|
+
blockingGuard.onBlocked({
|
|
79
|
+
continue: () => {
|
|
80
|
+
if (!resolved) {
|
|
81
|
+
resolved = true;
|
|
82
|
+
this.removeBlockerAndRetry(tx);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
cancel: () => {
|
|
86
|
+
resolved = true;
|
|
87
|
+
// Do nothing — history v5 already reverted the URL.
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
this.removeBlockerAndRetry(tx);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
removeBlocker() {
|
|
96
|
+
if (this.unblock) {
|
|
97
|
+
this.unblock();
|
|
98
|
+
this.unblock = undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
removeBlockerAndRetry(tx) {
|
|
102
|
+
// We must remove the blocker before retrying because history v5's
|
|
103
|
+
// allowTx() always returns false when any blocker is registered.
|
|
104
|
+
this.removeBlocker();
|
|
105
|
+
|
|
106
|
+
// Listen for the next navigation to complete, then reinstall the
|
|
107
|
+
// blocker only if guards are still active.
|
|
108
|
+
const unlisten = this.history.listen(() => {
|
|
109
|
+
unlisten();
|
|
110
|
+
if (this.guards.size > 0) {
|
|
111
|
+
this.installBlocker();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
tx.retry();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=HistoryRouterGateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RouteUrl","Router","HistoryRouterGateway","guards","Set","constructor","history","baseUrl","router","stopListening","listen","location","queryParams","Object","fromEntries","URLSearchParams","search","entries","resolvePathname","pathname","addGuard","config","hadGuards","size","add","installBlocker","delete","removeBlocker","goToRoute","name","params","route","findRoute","console","warn","getBaseUrl","push","fromPattern","path","setRoutes","routes","currentPathname","destroy","clear","pushState","url","result","resolve","matchedRoute","onMatch","findBlockingGuard","guard","undefined","unblock","block","tx","blockingGuard","resolved","onBlocked","continue","removeBlockerAndRetry","cancel","unlisten","retry"],"sources":["HistoryRouterGateway.ts"],"sourcesContent":["import type { z } from \"zod\";\nimport type { History } from \"history\";\nimport type { RouteDefinition, RouteTransitionGuardConfig, GuardDisposer } from \"./abstractions.js\";\nimport { RouterGateway } from \"./abstractions.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\nimport { Router } from \"./Router.js\";\n\nexport class HistoryRouterGateway implements RouterGateway.Interface {\n private readonly history: History;\n private readonly router: Router;\n private stopListening: () => void;\n private unblock: (() => void) | undefined;\n private guards = new Set<RouteTransitionGuardConfig>();\n\n constructor(history: History, baseUrl: string) {\n this.history = history;\n this.router = new Router(baseUrl);\n\n this.stopListening = history.listen(async ({ location }) => {\n const queryParams = Object.fromEntries(new URLSearchParams(location.search).entries());\n this.resolvePathname(location.pathname, queryParams);\n });\n }\n\n addGuard(config: RouteTransitionGuardConfig): GuardDisposer {\n const hadGuards = this.guards.size > 0;\n this.guards.add(config);\n if (!hadGuards) {\n this.installBlocker();\n }\n return () => {\n this.guards.delete(config);\n if (this.guards.size === 0) {\n this.removeBlocker();\n }\n };\n }\n\n goToRoute(name: string, params: z.ZodTypeAny): void {\n const route = this.router.findRoute(name);\n if (!route) {\n console.warn(`Route \"${name}\" not found.`);\n return;\n }\n\n const baseUrl = this.router.getBaseUrl();\n this.history.push(RouteUrl.fromPattern(route.path, params, baseUrl));\n }\n\n setRoutes(routes: RouteDefinition[]) {\n this.router.setRoutes(routes);\n\n const queryParams = Object.fromEntries(\n new URLSearchParams(this.history.location.search).entries()\n );\n const currentPathname = this.history.location.pathname;\n this.resolvePathname(currentPathname, queryParams);\n }\n\n destroy(): void {\n this.stopListening();\n this.removeBlocker();\n this.guards.clear();\n }\n\n pushState(url: string): void {\n this.history.push(url);\n }\n\n private async resolvePathname(pathname: string, queryParams?: Record<string, unknown>) {\n const result = this.router.resolve(pathname, queryParams);\n if (!result) {\n return;\n }\n\n const { matchedRoute, onMatch } = result;\n\n onMatch(matchedRoute);\n }\n\n private findBlockingGuard(): RouteTransitionGuardConfig | undefined {\n for (const config of this.guards) {\n if (config.guard()) {\n return config;\n }\n }\n return undefined;\n }\n\n private installBlocker(): void {\n if (this.unblock) {\n this.unblock();\n }\n\n this.unblock = this.history.block(tx => {\n const blockingGuard = this.findBlockingGuard();\n if (blockingGuard) {\n let resolved = false;\n\n blockingGuard.onBlocked({\n continue: () => {\n if (!resolved) {\n resolved = true;\n this.removeBlockerAndRetry(tx);\n }\n },\n cancel: () => {\n resolved = true;\n // Do nothing — history v5 already reverted the URL.\n }\n });\n } else {\n this.removeBlockerAndRetry(tx);\n }\n });\n }\n\n private removeBlocker(): void {\n if (this.unblock) {\n this.unblock();\n this.unblock = undefined;\n }\n }\n\n private removeBlockerAndRetry(tx: { retry: () => void }): void {\n // We must remove the blocker before retrying because history v5's\n // allowTx() always returns false when any blocker is registered.\n this.removeBlocker();\n\n // Listen for the next navigation to complete, then reinstall the\n // blocker only if guards are still active.\n const unlisten = this.history.listen(() => {\n unlisten();\n if (this.guards.size > 0) {\n this.installBlocker();\n }\n });\n\n tx.retry();\n }\n}\n"],"mappings":"AAIA,SAASA,QAAQ;AACjB,SAASC,MAAM;AAEf,OAAO,MAAMC,oBAAoB,CAAoC;EAKzDC,MAAM,GAAG,IAAIC,GAAG,CAA6B,CAAC;EAEtDC,WAAWA,CAACC,OAAgB,EAAEC,OAAe,EAAE;IAC3C,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACE,MAAM,GAAG,IAAIP,MAAM,CAACM,OAAO,CAAC;IAEjC,IAAI,CAACE,aAAa,GAAGH,OAAO,CAACI,MAAM,CAAC,OAAO;MAAEC;IAAS,CAAC,KAAK;MACxD,MAAMC,WAAW,GAAGC,MAAM,CAACC,WAAW,CAAC,IAAIC,eAAe,CAACJ,QAAQ,CAACK,MAAM,CAAC,CAACC,OAAO,CAAC,CAAC,CAAC;MACtF,IAAI,CAACC,eAAe,CAACP,QAAQ,CAACQ,QAAQ,EAAEP,WAAW,CAAC;IACxD,CAAC,CAAC;EACN;EAEAQ,QAAQA,CAACC,MAAkC,EAAiB;IACxD,MAAMC,SAAS,GAAG,IAAI,CAACnB,MAAM,CAACoB,IAAI,GAAG,CAAC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