@webiny/app 6.0.0-beta.0 → 6.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.d.ts +6 -13
- package/App.js +70 -83
- package/App.js.map +1 -1
- package/AppContainer.d.ts +23 -0
- package/AppContainer.js +9 -0
- package/AppContainer.js.map +1 -0
- package/README.md +7 -15
- package/apollo-client/InMemoryCache.d.ts +3 -2
- package/apollo-client/InMemoryCache.js +16 -48
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.d.ts +2 -2
- package/apollo-client/IntrospectionFragmentMatcher.js +33 -50
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
- package/components/Image.d.ts +1 -2
- package/components/Image.js +11 -19
- package/components/Image.js.map +1 -1
- package/components/index.d.ts +1 -2
- package/components/index.js +1 -19
- package/components/index.js.map +1 -1
- package/config/RouterConfig/Route.d.ts +29 -0
- package/config/RouterConfig/Route.js +33 -0
- package/config/RouterConfig/Route.js.map +1 -0
- package/config/RouterConfig.d.ts +31 -0
- package/config/RouterConfig.js +18 -0
- package/config/RouterConfig.js.map +1 -0
- package/config.d.ts +1 -1
- package/config.js +7 -13
- package/config.js.map +1 -1
- package/contexts/Ui/index.d.ts +2 -2
- package/contexts/Ui/index.js +28 -52
- package/contexts/Ui/index.js.map +1 -1
- package/core/DebounceRender.js +13 -24
- package/core/DebounceRender.js.map +1 -1
- package/core/Plugin.d.ts +1 -1
- package/core/Plugin.js +11 -19
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.d.ts +1 -1
- package/core/Plugins.js +20 -25
- package/core/Plugins.js.map +1 -1
- package/core/Provider.d.ts +1 -1
- package/core/Provider.js +9 -13
- package/core/Provider.js.map +1 -1
- package/core/Routes.d.ts +2 -1
- package/core/Routes.js +13 -23
- package/core/Routes.js.map +1 -1
- package/core/createProvider.d.ts +7 -3
- package/core/createProvider.js +3 -9
- package/core/createProvider.js.map +1 -1
- package/core/createProviderPlugin.d.ts +1 -1
- package/core/createProviderPlugin.js +4 -10
- package/core/createProviderPlugin.js.map +1 -1
- package/errors/AuthenticationErrorEvent.d.ts +9 -0
- package/errors/AuthenticationErrorEvent.js +10 -0
- package/errors/AuthenticationErrorEvent.js.map +1 -0
- package/errors/NetworkErrorEvent.d.ts +15 -0
- package/errors/NetworkErrorEvent.js +10 -0
- package/errors/NetworkErrorEvent.js.map +1 -0
- package/errors/abstractions.d.ts +12 -0
- package/errors/abstractions.js +5 -0
- package/errors/abstractions.js.map +1 -0
- package/errors/index.d.ts +6 -0
- package/errors/index.js +6 -0
- package/errors/index.js.map +1 -0
- package/exports/admin/envConfig.d.ts +1 -0
- package/exports/admin/envConfig.js +3 -0
- package/exports/admin/envConfig.js.map +1 -0
- package/exports/admin/graphqlClient.d.ts +1 -0
- package/exports/admin/graphqlClient.js +3 -0
- package/exports/admin/graphqlClient.js.map +1 -0
- package/exports/admin/localStorage.d.ts +2 -0
- package/exports/admin/localStorage.js +4 -0
- package/exports/admin/localStorage.js.map +1 -0
- package/exports/admin/router.d.ts +4 -0
- package/exports/admin/router.js +6 -0
- package/exports/admin/router.js.map +1 -0
- package/exports/admin/security.d.ts +1 -0
- package/exports/admin/security.js +3 -0
- package/exports/admin/security.js.map +1 -0
- package/exports/admin.d.ts +6 -0
- package/exports/admin.js +8 -0
- package/exports/admin.js.map +1 -0
- package/features/envConfig/EnvConfig.d.ts +6 -0
- package/features/envConfig/EnvConfig.js +14 -0
- package/features/envConfig/EnvConfig.js.map +1 -0
- package/features/envConfig/abstractions.d.ts +27 -0
- package/features/envConfig/abstractions.js +4 -0
- package/features/envConfig/abstractions.js.map +1 -0
- package/features/envConfig/feature.d.ts +17 -0
- package/features/envConfig/feature.js +14 -0
- package/features/envConfig/feature.js.map +1 -0
- package/features/envConfig/index.d.ts +1 -0
- package/features/envConfig/index.js +3 -0
- package/features/envConfig/index.js.map +1 -0
- package/features/eventPublisher/EventPublisher.d.ts +8 -0
- package/features/eventPublisher/EventPublisher.js +27 -0
- package/features/eventPublisher/EventPublisher.js.map +1 -0
- package/features/eventPublisher/abstractions.d.ts +18 -0
- package/features/eventPublisher/abstractions.js +14 -0
- package/features/eventPublisher/abstractions.js.map +1 -0
- package/features/eventPublisher/feature.d.ts +1 -0
- package/features/eventPublisher/feature.js +11 -0
- package/features/eventPublisher/feature.js.map +1 -0
- package/features/eventPublisher/index.d.ts +3 -0
- package/features/eventPublisher/index.js +4 -0
- package/features/eventPublisher/index.js.map +1 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.d.ts +13 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js +35 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -0
- package/features/graphqlClient/BatchingGraphQLClient.d.ts +18 -0
- package/features/graphqlClient/BatchingGraphQLClient.js +164 -0
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -0
- package/features/graphqlClient/FetchGraphQLClient.d.ts +10 -0
- package/features/graphqlClient/FetchGraphQLClient.js +62 -0
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -0
- package/features/graphqlClient/NetworkErrorPublishing.d.ts +14 -0
- package/features/graphqlClient/NetworkErrorPublishing.js +55 -0
- package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -0
- package/features/graphqlClient/RequestValue.d.ts +20 -0
- package/features/graphqlClient/RequestValue.js +42 -0
- package/features/graphqlClient/RequestValue.js.map +1 -0
- package/features/graphqlClient/RetryGraphQLClient.d.ts +18 -0
- package/features/graphqlClient/RetryGraphQLClient.js +54 -0
- package/features/graphqlClient/RetryGraphQLClient.js.map +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.d.ts +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +350 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -0
- package/features/graphqlClient/abstractions.d.ts +17 -0
- package/features/graphqlClient/abstractions.js +4 -0
- package/features/graphqlClient/abstractions.js.map +1 -0
- package/features/graphqlClient/feature.d.ts +6 -0
- package/features/graphqlClient/feature.js +31 -0
- package/features/graphqlClient/feature.js.map +1 -0
- package/features/graphqlClient/index.d.ts +1 -0
- package/features/graphqlClient/index.js +3 -0
- package/features/graphqlClient/index.js.map +1 -0
- package/features/graphqlClient/types.d.ts +5 -0
- package/features/graphqlClient/types.js +3 -0
- package/features/graphqlClient/types.js.map +1 -0
- package/features/localStorage/BrowserLocalStorageGateway.d.ts +9 -0
- package/features/localStorage/BrowserLocalStorageGateway.js +68 -0
- package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -0
- package/features/localStorage/LocalStorage.d.ts +12 -0
- package/features/localStorage/LocalStorage.js +31 -0
- package/features/localStorage/LocalStorage.js.map +1 -0
- package/features/localStorage/LocalStorageRepository.d.ts +20 -0
- package/features/localStorage/LocalStorageRepository.js +95 -0
- package/features/localStorage/LocalStorageRepository.js.map +1 -0
- package/features/localStorage/abstractions.d.ts +48 -0
- package/features/localStorage/abstractions.js +19 -0
- package/features/localStorage/abstractions.js.map +1 -0
- package/features/localStorage/feature.d.ts +12 -0
- package/features/localStorage/feature.js +34 -0
- package/features/localStorage/feature.js.map +1 -0
- package/features/localStorage/index.d.ts +1 -0
- package/features/localStorage/index.js +3 -0
- package/features/localStorage/index.js.map +1 -0
- package/features/router/HistoryRouterGateway.d.ts +18 -0
- package/features/router/HistoryRouterGateway.js +82 -0
- package/features/router/HistoryRouterGateway.js.map +1 -0
- package/features/router/HistoryRouterGateway.test.d.ts +1 -0
- package/features/router/HistoryRouterGateway.test.js +204 -0
- package/features/router/HistoryRouterGateway.test.js.map +1 -0
- package/features/router/Route.d.ts +19 -0
- package/features/router/Route.js +59 -0
- package/features/router/Route.js.map +1 -0
- package/features/router/RouteUrl.d.ts +85 -0
- package/features/router/RouteUrl.js +232 -0
- package/features/router/RouteUrl.js.map +1 -0
- package/features/router/Router.d.ts +45 -0
- package/features/router/Router.js +129 -0
- package/features/router/Router.js.map +1 -0
- package/features/router/RouterPresenter.d.ts +17 -0
- package/features/router/RouterPresenter.js +45 -0
- package/features/router/RouterPresenter.js.map +1 -0
- package/features/router/RouterRepository.d.ts +21 -0
- package/features/router/RouterRepository.js +71 -0
- package/features/router/RouterRepository.js.map +1 -0
- package/features/router/RouterRepository.test.d.ts +1 -0
- package/features/router/RouterRepository.test.js +154 -0
- package/features/router/RouterRepository.test.js.map +1 -0
- package/features/router/abstractions.d.ts +68 -0
- package/features/router/abstractions.js +15 -0
- package/features/router/abstractions.js.map +1 -0
- package/features/router/feature.d.ts +4 -0
- package/features/router/feature.js +18 -0
- package/features/router/feature.js.map +1 -0
- package/features/router/index.d.ts +1 -0
- package/features/router/index.js +3 -0
- package/features/router/index.js.map +1 -0
- package/helpers/InterfaceGenerator/date.d.ts +15 -0
- package/helpers/InterfaceGenerator/date.js +3 -0
- package/helpers/InterfaceGenerator/date.js.map +1 -0
- package/helpers/InterfaceGenerator/id.d.ts +23 -0
- package/helpers/InterfaceGenerator/id.js +3 -0
- package/helpers/InterfaceGenerator/id.js.map +1 -0
- package/helpers/InterfaceGenerator/identity.d.ts +10 -0
- package/helpers/InterfaceGenerator/identity.js +3 -0
- package/helpers/InterfaceGenerator/identity.js.map +1 -0
- package/helpers/InterfaceGenerator/index.d.ts +5 -0
- package/helpers/InterfaceGenerator/index.js +3 -0
- package/helpers/InterfaceGenerator/index.js.map +1 -0
- package/helpers/InterfaceGenerator/numeric.d.ts +12 -0
- package/helpers/InterfaceGenerator/numeric.js +3 -0
- package/helpers/InterfaceGenerator/numeric.js.map +1 -0
- package/helpers/InterfaceGenerator/truthful.d.ts +7 -0
- package/helpers/InterfaceGenerator/truthful.js +3 -0
- package/helpers/InterfaceGenerator/truthful.js.map +1 -0
- package/hooks/useAutocomplete/index.d.ts +1 -1
- package/hooks/useAutocomplete/index.js +1 -12
- package/hooks/useAutocomplete/index.js.map +1 -1
- package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
- package/hooks/useAutocomplete/useAutocomplete.js +6 -16
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +2 -11
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +2 -11
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +2 -11
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.d.ts +3 -3
- package/hooks/useDataList/functions/index.js +3 -27
- package/hooks/useDataList/functions/index.js.map +1 -1
- package/hooks/useDataList/functions/searchDataByKey.js +4 -10
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.d.ts +1 -1
- package/hooks/useDataList/index.js +1 -12
- package/hooks/useDataList/index.js.map +1 -1
- package/hooks/useDataList/useDataList.d.ts +2 -3
- package/hooks/useDataList/useDataList.js +74 -94
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.d.ts +1 -2
- package/hooks/useDataList/utils/index.js +1 -20
- package/hooks/useDataList/utils/index.js.map +1 -1
- package/hooks/useDataList/utils/prepareLoadListParams.js +10 -16
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandler.js +7 -12
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.d.ts +3 -3
- package/hooks/useHandlers.js +11 -17
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.d.ts +2 -0
- package/hooks/useRegisterLegacyPlugin.js +11 -0
- package/hooks/useRegisterLegacyPlugin.js.map +1 -0
- package/hooks/useUi.d.ts +1 -1
- package/hooks/useUi.js +4 -10
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +5 -13
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/i18n/index.js +1 -13
- package/i18n/index.js.map +1 -1
- package/index.d.ts +23 -14
- package/index.js +25 -165
- package/index.js.map +1 -1
- package/package.json +26 -29
- package/plugins/AddQuerySelectionPlugin.d.ts +2 -2
- package/plugins/AddQuerySelectionPlugin.js +61 -107
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +12 -31
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.d.ts +3 -2
- package/plugins/ApolloDynamicLink.js +19 -46
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.d.ts +1 -1
- package/plugins/ApolloLinkPlugin.js +18 -37
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.d.ts +1 -1
- package/plugins/ConsoleLinkPlugin.js +20 -41
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +8 -13
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +35 -58
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.d.ts +14 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +31 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.d.ts +2 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +31 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +4 -5
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -12
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/Typography.d.ts +8 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js +18 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +3 -3
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +10 -20
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.d.ts +4 -1
- package/plugins/NetworkErrorLinkPlugin.js +60 -37
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.d.ts +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +11 -30
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.d.ts +3 -3
- package/plugins/TenantHeaderLinkPlugin.js +29 -48
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/components/Image.d.ts +6 -0
- package/plugins/components/Image.js +19 -0
- package/plugins/components/Image.js.map +1 -0
- package/plugins/image.d.ts +1 -1
- package/plugins/image.js +46 -53
- package/plugins/image.js.map +1 -1
- package/plugins/index.d.ts +5 -5
- package/plugins/index.js +31 -53
- package/plugins/index.js.map +1 -1
- package/presentation/localStorage/index.d.ts +3 -0
- package/presentation/localStorage/index.js +5 -0
- package/presentation/localStorage/index.js.map +1 -0
- package/presentation/localStorage/useLocalStorage.d.ts +6 -0
- package/presentation/localStorage/useLocalStorage.js +21 -0
- package/presentation/localStorage/useLocalStorage.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValue.d.ts +1 -0
- package/presentation/localStorage/useLocalStorageValue.js +20 -0
- package/presentation/localStorage/useLocalStorageValue.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValues.d.ts +5 -0
- package/presentation/localStorage/useLocalStorageValues.js +39 -0
- package/presentation/localStorage/useLocalStorageValues.js.map +1 -0
- package/presentation/router/RouteElementRegistry.d.ts +14 -0
- package/presentation/router/RouteElementRegistry.js +32 -0
- package/presentation/router/RouteElementRegistry.js.map +1 -0
- package/presentation/router/abstractions.d.ts +13 -0
- package/presentation/router/abstractions.js +4 -0
- package/presentation/router/abstractions.js.map +1 -0
- package/presentation/router/components/RouteContent.d.ts +2 -0
- package/presentation/router/components/RouteContent.js +17 -0
- package/presentation/router/components/RouteContent.js.map +1 -0
- package/presentation/router/components/RouteLink.d.ts +50 -0
- package/presentation/router/components/RouteLink.js +22 -0
- package/presentation/router/components/RouteLink.js.map +1 -0
- package/presentation/router/components/SimpleLink.d.ts +44 -0
- package/presentation/router/components/SimpleLink.js +30 -0
- package/presentation/router/components/SimpleLink.js.map +1 -0
- package/presentation/router/hooks/useRoute.d.ts +6 -0
- package/presentation/router/hooks/useRoute.js +30 -0
- package/presentation/router/hooks/useRoute.js.map +1 -0
- package/presentation/router/hooks/useRouter.d.ts +7 -0
- package/presentation/router/hooks/useRouter.js +26 -0
- package/presentation/router/hooks/useRouter.js.map +1 -0
- package/presentation/router/index.d.ts +4 -0
- package/presentation/router/index.js +5 -0
- package/presentation/router/index.js.map +1 -0
- package/presentation/router/types.d.ts +5 -0
- package/presentation/router/types.js +3 -0
- package/presentation/router/types.js.map +1 -0
- package/react-butterfiles/Files.d.ts +69 -0
- package/react-butterfiles/Files.js +227 -0
- package/react-butterfiles/Files.js.map +1 -0
- package/react-butterfiles/file.todo +1 -0
- package/react-butterfiles/index.d.ts +2 -0
- package/react-butterfiles/index.js +4 -0
- package/react-butterfiles/index.js.map +1 -0
- package/react-butterfiles/utils/generateId.d.ts +1 -0
- package/react-butterfiles/utils/generateId.js +5 -0
- package/react-butterfiles/utils/generateId.js.map +1 -0
- package/react-butterfiles/utils/readFileContent.d.ts +1 -0
- package/react-butterfiles/utils/readFileContent.js +15 -0
- package/react-butterfiles/utils/readFileContent.js.map +1 -0
- package/renderApp.d.ts +1 -1
- package/renderApp.js +4 -11
- package/renderApp.js.map +1 -1
- package/router.d.ts +5 -0
- package/router.js +8 -0
- package/router.js.map +1 -0
- package/shared/di/DiContainerProvider.d.ts +8 -0
- package/shared/di/DiContainerProvider.js +17 -0
- package/shared/di/DiContainerProvider.js.map +1 -0
- package/shared/di/createFeature.d.ts +11 -0
- package/shared/di/createFeature.js +11 -0
- package/shared/di/createFeature.js.map +1 -0
- package/shared/di/useFeature.d.ts +2 -0
- package/shared/di/useFeature.js +18 -0
- package/shared/di/useFeature.js.map +1 -0
- package/types.d.ts +16 -13
- package/types.js +1 -12
- package/types.js.map +1 -1
- package/utils/createGenericContext.d.ts +13 -0
- package/utils/createGenericContext.js +25 -0
- package/utils/createGenericContext.js.map +1 -0
- package/utils/createHashing.d.ts +2 -0
- package/utils/createHashing.js +18 -0
- package/utils/createHashing.js.map +1 -0
- package/utils/index.d.ts +2 -8
- package/utils/index.js +2 -93
- package/utils/index.js.map +1 -1
- package/utils/legacyPluginToReactComponent.d.ts +7 -0
- package/utils/legacyPluginToReactComponent.js +14 -0
- package/utils/legacyPluginToReactComponent.js.map +1 -0
- package/components/Routes.d.ts +0 -2
- package/components/Routes.js +0 -46
- package/components/Routes.js.map +0 -1
- package/components/View.d.ts +0 -8
- package/components/View.js +0 -31
- package/components/View.js.map +0 -1
- package/core/AddRoute.d.ts +0 -17
- package/core/AddRoute.js +0 -21
- package/core/AddRoute.js.map +0 -1
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +0 -14
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +0 -30
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +0 -1
- package/hooks/useDataList/utils/types.d.ts +0 -40
- package/hooks/useDataList/utils/types.js +0 -7
- package/hooks/useDataList/utils/types.js.map +0 -1
- package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -10
- package/plugins/LocaleHeaderLinkPlugin.js +0 -49
- package/plugins/LocaleHeaderLinkPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -12
- package/plugins/RoutePlugin.js +0 -35
- package/plugins/RoutePlugin.js.map +0 -1
- package/plugins/ViewPlugin.d.ts +0 -14
- package/plugins/ViewPlugin.js +0 -40
- package/plugins/ViewPlugin.js.map +0 -1
- package/utils/getApiUrl.d.ts +0 -1
- package/utils/getApiUrl.js +0 -12
- package/utils/getApiUrl.js.map +0 -1
- package/utils/getGqlApiUrl.d.ts +0 -1
- package/utils/getGqlApiUrl.js +0 -12
- package/utils/getGqlApiUrl.js.map +0 -1
- package/utils/getHeadlessCmsGqlApiUrl.d.ts +0 -5
- package/utils/getHeadlessCmsGqlApiUrl.js +0 -18
- package/utils/getHeadlessCmsGqlApiUrl.js.map +0 -1
- package/utils/getLocaleCode.d.ts +0 -6
- package/utils/getLocaleCode.js +0 -43
- package/utils/getLocaleCode.js.map +0 -1
- package/utils/getPrerenderId.d.ts +0 -6
- package/utils/getPrerenderId.js +0 -11
- package/utils/getPrerenderId.js.map +0 -1
- package/utils/getTenantId.d.ts +0 -6
- package/utils/getTenantId.js +0 -35
- package/utils/getTenantId.js.map +0 -1
- package/utils/isLocalhost.d.ts +0 -1
- package/utils/isLocalhost.js +0 -15
- package/utils/isLocalhost.js.map +0 -1
- package/utils/isPrerendering.d.ts +0 -1
- package/utils/isPrerendering.js +0 -11
- package/utils/isPrerendering.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { EnvConfig } from "../envConfig/index.js";
|
|
3
|
+
class RetryGraphQLClientImpl {
|
|
4
|
+
constructor(envConfig, decoratee) {
|
|
5
|
+
this.decoratee = decoratee;
|
|
6
|
+
const gqlClientConfig = envConfig.get("graphqlClient");
|
|
7
|
+
this.maxRetries = gqlClientConfig?.retries.maxRetries ?? 3;
|
|
8
|
+
this.baseDelayMs = gqlClientConfig?.retries.delayInMillis ?? 100;
|
|
9
|
+
}
|
|
10
|
+
async execute(params) {
|
|
11
|
+
let lastError;
|
|
12
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
13
|
+
try {
|
|
14
|
+
return await this.decoratee.execute(params);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
lastError = error;
|
|
17
|
+
|
|
18
|
+
// Don't retry GraphQL errors (business logic errors)
|
|
19
|
+
// Only retry network/infrastructure errors
|
|
20
|
+
if (this.isGraphQLError(error) || this.isAuthenticationError(error) || this.isMaintenanceError(error)) {
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Don't delay after the last attempt
|
|
25
|
+
if (attempt < this.maxRetries) {
|
|
26
|
+
await this.delay(this.calculateBackoff(attempt));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw lastError;
|
|
31
|
+
}
|
|
32
|
+
isGraphQLError(error) {
|
|
33
|
+
return error.message.includes("GraphQL");
|
|
34
|
+
}
|
|
35
|
+
isAuthenticationError(error) {
|
|
36
|
+
return error.code?.includes("Authentication/");
|
|
37
|
+
}
|
|
38
|
+
isMaintenanceError(error) {
|
|
39
|
+
return error.code?.includes("Tenancy/");
|
|
40
|
+
}
|
|
41
|
+
calculateBackoff(attempt) {
|
|
42
|
+
// Exponential backoff: 100ms, 200ms, 400ms, etc.
|
|
43
|
+
return Math.pow(2, attempt) * this.baseDelayMs;
|
|
44
|
+
}
|
|
45
|
+
delay(ms) {
|
|
46
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const RetryGraphQLClient = GraphQLClient.createDecorator({
|
|
50
|
+
decorator: RetryGraphQLClientImpl,
|
|
51
|
+
dependencies: [EnvConfig]
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=RetryGraphQLClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLClient","EnvConfig","RetryGraphQLClientImpl","constructor","envConfig","decoratee","gqlClientConfig","get","maxRetries","retries","baseDelayMs","delayInMillis","execute","params","lastError","attempt","error","isGraphQLError","isAuthenticationError","isMaintenanceError","delay","calculateBackoff","message","includes","code","Math","pow","ms","Promise","resolve","setTimeout","RetryGraphQLClient","createDecorator","decorator","dependencies"],"sources":["RetryGraphQLClient.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/admin\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\nclass RetryGraphQLClientImpl implements GraphQLClient.Interface {\n private readonly maxRetries: number;\n private readonly baseDelayMs: number;\n\n constructor(\n envConfig: EnvConfig.Interface,\n private decoratee: GraphQLClient.Interface\n ) {\n const gqlClientConfig = envConfig.get(\"graphqlClient\");\n\n this.maxRetries = gqlClientConfig?.retries.maxRetries ?? 3;\n this.baseDelayMs = gqlClientConfig?.retries.delayInMillis ?? 100;\n }\n\n async execute<TResult = any, TVariables = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n return await this.decoratee.execute(params);\n } catch (error) {\n lastError = error as Error;\n\n // Don't retry GraphQL errors (business logic errors)\n // Only retry network/infrastructure errors\n if (\n this.isGraphQLError(error as Error) ||\n this.isAuthenticationError(error as BaseError) ||\n this.isMaintenanceError(error as BaseError)\n ) {\n throw error;\n }\n\n // Don't delay after the last attempt\n if (attempt < this.maxRetries) {\n await this.delay(this.calculateBackoff(attempt));\n }\n }\n }\n\n throw lastError!;\n }\n\n private isGraphQLError(error: Error): boolean {\n return error.message.includes(\"GraphQL\");\n }\n\n private isAuthenticationError(error: BaseError): boolean {\n return error.code?.includes(\"Authentication/\");\n }\n\n private isMaintenanceError(error: BaseError): boolean {\n return error.code?.includes(\"Tenancy/\");\n }\n\n private calculateBackoff(attempt: number): number {\n // Exponential backoff: 100ms, 200ms, 400ms, etc.\n return Math.pow(2, attempt) * this.baseDelayMs;\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n\nexport const RetryGraphQLClient = GraphQLClient.createDecorator({\n decorator: RetryGraphQLClientImpl,\n dependencies: [EnvConfig]\n});\n"],"mappings":"AACA,SAASA,aAAa;AACtB,SAASC,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BA,CAACH,KAAgB,EAAW;IAClD,OAAOA,KAAK,CAACQ,IAAI,EAAED,QAAQ,CAAC,UAAU,CAAC;EAC3C;EAEQF,gBAAgBA,CAACN,OAAe,EAAU;IAC9C;IACA,OAAOU,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEX,OAAO,CAAC,GAAG,IAAI,CAACL,WAAW;EAClD;EAEQU,KAAKA,CAACO,EAAU,EAAiB;IACrC,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIC,UAAU,CAACD,OAAO,EAAEF,EAAE,CAAC,CAAC;EAC1D;AACJ;AAEA,OAAO,MAAMI,kBAAkB,GAAG/B,aAAa,CAACgC,eAAe,CAAC;EAC5DC,SAAS,EAAE/B,sBAAsB;EACjCgC,YAAY,EAAE,CAACjC,SAAS;AAC5B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { Container } from "@webiny/di";
|
|
3
|
+
import { GraphQLClient } from "../abstractions.js";
|
|
4
|
+
import { FetchGraphQLClient } from "../FetchGraphQLClient.js";
|
|
5
|
+
import { BatchingGraphQLClient } from "../BatchingGraphQLClient.js";
|
|
6
|
+
import { RetryGraphQLClient } from "../RetryGraphQLClient.js";
|
|
7
|
+
import { EnvConfig } from "../../envConfig/index.js";
|
|
8
|
+
describe("GraphQLClient Feature", () => {
|
|
9
|
+
let container;
|
|
10
|
+
let mockEnvConfig;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
container = new Container();
|
|
13
|
+
mockEnvConfig = {
|
|
14
|
+
get: vi.fn(key => {
|
|
15
|
+
if (key === "graphqlApiUrl") {
|
|
16
|
+
return "https://api.example.com/graphql";
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
container.registerInstance(EnvConfig, mockEnvConfig);
|
|
22
|
+
});
|
|
23
|
+
describe("FetchGraphQLClient", () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
26
|
+
});
|
|
27
|
+
it("should execute a query successfully", async () => {
|
|
28
|
+
const mockResponse = {
|
|
29
|
+
data: {
|
|
30
|
+
user: {
|
|
31
|
+
id: "1",
|
|
32
|
+
name: "John"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
37
|
+
status: 200,
|
|
38
|
+
json: async () => mockResponse
|
|
39
|
+
});
|
|
40
|
+
const client = container.resolve(GraphQLClient);
|
|
41
|
+
const result = await client.execute({
|
|
42
|
+
query: "query GetUser { user { id name } }"
|
|
43
|
+
});
|
|
44
|
+
expect(result).toEqual(mockResponse.data);
|
|
45
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api.example.com/graphql", expect.objectContaining({
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
it("should execute a mutation successfully", async () => {
|
|
53
|
+
const mockResponse = {
|
|
54
|
+
data: {
|
|
55
|
+
createUser: {
|
|
56
|
+
id: "2",
|
|
57
|
+
name: "Jane"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
62
|
+
status: 200,
|
|
63
|
+
json: async () => mockResponse
|
|
64
|
+
});
|
|
65
|
+
const client = container.resolve(GraphQLClient);
|
|
66
|
+
const result = await client.execute({
|
|
67
|
+
query: "mutation CreateUser($name: String!) { createUser(name: $name) { id name } }",
|
|
68
|
+
variables: {
|
|
69
|
+
name: "Jane"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
expect(result).toEqual(mockResponse.data);
|
|
73
|
+
});
|
|
74
|
+
it("should include custom headers", async () => {
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
data: {
|
|
77
|
+
user: {
|
|
78
|
+
id: "1"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
83
|
+
status: 200,
|
|
84
|
+
json: async () => mockResponse
|
|
85
|
+
});
|
|
86
|
+
const client = container.resolve(GraphQLClient);
|
|
87
|
+
await client.execute({
|
|
88
|
+
query: "query GetUser { user { id } }",
|
|
89
|
+
headers: {
|
|
90
|
+
"x-tenant": "root",
|
|
91
|
+
Authorization: "Bearer token"
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
expect(global.fetch).toHaveBeenCalledWith("https://api.example.com/graphql", expect.objectContaining({
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
"x-tenant": "root",
|
|
98
|
+
Authorization: "Bearer token"
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
});
|
|
102
|
+
it("should throw on network error", async () => {
|
|
103
|
+
global.fetch = vi.fn().mockRejectedValue(new Error("Network failure"));
|
|
104
|
+
const client = container.resolve(GraphQLClient);
|
|
105
|
+
await expect(client.execute({
|
|
106
|
+
query: "query { user { id } }"
|
|
107
|
+
})).rejects.toThrow("Network error: Network failure");
|
|
108
|
+
});
|
|
109
|
+
it("should throw on GraphQL errors", async () => {
|
|
110
|
+
const mockResponse = {
|
|
111
|
+
errors: [{
|
|
112
|
+
message: "User not found"
|
|
113
|
+
}],
|
|
114
|
+
data: null
|
|
115
|
+
};
|
|
116
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
117
|
+
status: 200,
|
|
118
|
+
json: async () => mockResponse
|
|
119
|
+
});
|
|
120
|
+
const client = container.resolve(GraphQLClient);
|
|
121
|
+
await expect(client.execute({
|
|
122
|
+
query: "query { user { id } }"
|
|
123
|
+
})).rejects.toThrow("GraphQL errors");
|
|
124
|
+
});
|
|
125
|
+
it("should throw on invalid JSON response", async () => {
|
|
126
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
127
|
+
json: async () => {
|
|
128
|
+
throw new Error("Invalid JSON");
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const client = container.resolve(GraphQLClient);
|
|
132
|
+
await expect(client.execute({
|
|
133
|
+
query: "query { user { id } }"
|
|
134
|
+
})).rejects.toThrow("Failed to parse GraphQL response as JSON");
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe("BatchingGraphQLClient", () => {
|
|
138
|
+
beforeEach(() => {
|
|
139
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
140
|
+
container.registerDecorator(BatchingGraphQLClient);
|
|
141
|
+
});
|
|
142
|
+
it("should batch multiple requests within the batch window", async () => {
|
|
143
|
+
const mockResponse = [{
|
|
144
|
+
data: {
|
|
145
|
+
user: {
|
|
146
|
+
id: "1",
|
|
147
|
+
name: "John"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
data: {
|
|
152
|
+
post: {
|
|
153
|
+
id: "2",
|
|
154
|
+
title: "Hello"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}];
|
|
158
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
159
|
+
json: async () => mockResponse
|
|
160
|
+
});
|
|
161
|
+
const client = container.resolve(GraphQLClient);
|
|
162
|
+
const [result1, result2] = await Promise.all([client.execute({
|
|
163
|
+
query: "query GetUser { user { id name } }"
|
|
164
|
+
}), client.execute({
|
|
165
|
+
query: "query GetPost { post { id title } }"
|
|
166
|
+
})]);
|
|
167
|
+
expect(result1).toEqual(mockResponse[0].data);
|
|
168
|
+
expect(result2).toEqual(mockResponse[1].data);
|
|
169
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
170
|
+
const callBody = JSON.parse(global.fetch.mock.calls[0][1].body);
|
|
171
|
+
expect(callBody).toHaveLength(2);
|
|
172
|
+
});
|
|
173
|
+
it("should execute single request without batching", async () => {
|
|
174
|
+
const mockResponse = {
|
|
175
|
+
data: {
|
|
176
|
+
user: {
|
|
177
|
+
id: "1",
|
|
178
|
+
name: "John"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
183
|
+
status: 200,
|
|
184
|
+
json: async () => mockResponse
|
|
185
|
+
});
|
|
186
|
+
const client = container.resolve(GraphQLClient);
|
|
187
|
+
const result = await client.execute({
|
|
188
|
+
query: "query GetUser { user { id name } }"
|
|
189
|
+
});
|
|
190
|
+
expect(result).toEqual(mockResponse.data);
|
|
191
|
+
|
|
192
|
+
// Should use decoratee directly for single request
|
|
193
|
+
const callBody = JSON.parse(global.fetch.mock.calls[0][1].body);
|
|
194
|
+
expect(callBody).toHaveProperty("query");
|
|
195
|
+
expect(callBody).not.toBeInstanceOf(Array);
|
|
196
|
+
});
|
|
197
|
+
it("should handle mixed queries and mutations in batch", async () => {
|
|
198
|
+
const mockResponse = [{
|
|
199
|
+
data: {
|
|
200
|
+
user: {
|
|
201
|
+
id: "1"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
data: {
|
|
206
|
+
createPost: {
|
|
207
|
+
id: "2"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}];
|
|
211
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
212
|
+
status: 200,
|
|
213
|
+
json: async () => mockResponse
|
|
214
|
+
});
|
|
215
|
+
const client = container.resolve(GraphQLClient);
|
|
216
|
+
await Promise.all([client.execute({
|
|
217
|
+
query: "query { user { id } }"
|
|
218
|
+
}), client.execute({
|
|
219
|
+
query: "mutation { createPost { id } }"
|
|
220
|
+
})]);
|
|
221
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
222
|
+
const callBody = JSON.parse(global.fetch.mock.calls[0][1].body);
|
|
223
|
+
expect(callBody[0]).toHaveProperty("query");
|
|
224
|
+
expect(callBody[1]).toHaveProperty("query");
|
|
225
|
+
});
|
|
226
|
+
it("should reject all requests if batch fails", async () => {
|
|
227
|
+
global.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
228
|
+
const client = container.resolve(GraphQLClient);
|
|
229
|
+
const promises = [client.execute({
|
|
230
|
+
query: "query { user { id } }"
|
|
231
|
+
}), client.execute({
|
|
232
|
+
query: "query { post { id } }"
|
|
233
|
+
})];
|
|
234
|
+
await expect(Promise.all(promises)).rejects.toThrow("Network error");
|
|
235
|
+
});
|
|
236
|
+
it("should handle GraphQL errors in batched operations", async () => {
|
|
237
|
+
const mockResponse = [{
|
|
238
|
+
data: {
|
|
239
|
+
user: {
|
|
240
|
+
id: "1"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}, {
|
|
244
|
+
errors: [{
|
|
245
|
+
message: "Post not found"
|
|
246
|
+
}],
|
|
247
|
+
data: null
|
|
248
|
+
}];
|
|
249
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
250
|
+
json: async () => mockResponse
|
|
251
|
+
});
|
|
252
|
+
const client = container.resolve(GraphQLClient);
|
|
253
|
+
const promises = [client.execute({
|
|
254
|
+
query: "query { user { id } }"
|
|
255
|
+
}), client.execute({
|
|
256
|
+
query: "query { post { id } }"
|
|
257
|
+
})];
|
|
258
|
+
await expect(Promise.all(promises)).rejects.toThrow("GraphQL errors in operation 1");
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
describe("RetryGraphQLClient", () => {
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
264
|
+
container.registerDecorator(RetryGraphQLClient);
|
|
265
|
+
});
|
|
266
|
+
it("should retry on network errors", async () => {
|
|
267
|
+
const mockResponse = {
|
|
268
|
+
data: {
|
|
269
|
+
user: {
|
|
270
|
+
id: "1"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
global.fetch = vi.fn().mockRejectedValueOnce(new Error("Network timeout")).mockRejectedValueOnce(new Error("Network timeout")).mockResolvedValueOnce({
|
|
275
|
+
status: 200,
|
|
276
|
+
json: async () => mockResponse
|
|
277
|
+
});
|
|
278
|
+
const client = container.resolve(GraphQLClient);
|
|
279
|
+
const result = await client.execute({
|
|
280
|
+
query: "query { user { id } }"
|
|
281
|
+
});
|
|
282
|
+
expect(result).toEqual(mockResponse.data);
|
|
283
|
+
expect(global.fetch).toHaveBeenCalledTimes(3);
|
|
284
|
+
});
|
|
285
|
+
it("should not retry on GraphQL errors", async () => {
|
|
286
|
+
const mockResponse = {
|
|
287
|
+
errors: [{
|
|
288
|
+
message: "Unauthorized"
|
|
289
|
+
}],
|
|
290
|
+
data: null
|
|
291
|
+
};
|
|
292
|
+
global.fetch = vi.fn().mockResolvedValue({
|
|
293
|
+
status: 200,
|
|
294
|
+
json: async () => mockResponse
|
|
295
|
+
});
|
|
296
|
+
const client = container.resolve(GraphQLClient);
|
|
297
|
+
await expect(client.execute({
|
|
298
|
+
query: "query { user { id } }"
|
|
299
|
+
})).rejects.toThrow("GraphQL errors");
|
|
300
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
301
|
+
});
|
|
302
|
+
it("should give up after max retries", async () => {
|
|
303
|
+
global.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
304
|
+
const client = container.resolve(GraphQLClient);
|
|
305
|
+
await expect(client.execute({
|
|
306
|
+
query: "query { user { id } }"
|
|
307
|
+
})).rejects.toThrow("Network error");
|
|
308
|
+
|
|
309
|
+
// Should try 4 times: initial + 3 retries
|
|
310
|
+
expect(global.fetch).toHaveBeenCalledTimes(4);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
describe("Combined decorators (Retry + Batching)", () => {
|
|
314
|
+
beforeEach(() => {
|
|
315
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
316
|
+
container.registerDecorator(BatchingGraphQLClient);
|
|
317
|
+
container.registerDecorator(RetryGraphQLClient);
|
|
318
|
+
});
|
|
319
|
+
it("should retry batched requests on failure", async () => {
|
|
320
|
+
const mockResponse = [{
|
|
321
|
+
data: {
|
|
322
|
+
user: {
|
|
323
|
+
id: "1"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}, {
|
|
327
|
+
data: {
|
|
328
|
+
post: {
|
|
329
|
+
id: "2"
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}];
|
|
333
|
+
global.fetch = vi.fn().mockRejectedValueOnce(new Error("Network error")).mockResolvedValueOnce({
|
|
334
|
+
status: 200,
|
|
335
|
+
json: async () => mockResponse
|
|
336
|
+
});
|
|
337
|
+
const client = container.resolve(GraphQLClient);
|
|
338
|
+
const [result1, result2] = await Promise.all([client.execute({
|
|
339
|
+
query: "query { user { id } }"
|
|
340
|
+
}), client.execute({
|
|
341
|
+
query: "query { post { id } }"
|
|
342
|
+
})]);
|
|
343
|
+
expect(result1).toEqual(mockResponse[0].data);
|
|
344
|
+
expect(result2).toEqual(mockResponse[1].data);
|
|
345
|
+
expect(global.fetch).toHaveBeenCalledTimes(2);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
//# sourceMappingURL=GraphQLClient.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["describe","it","expect","vi","beforeEach","Container","GraphQLClient","FetchGraphQLClient","BatchingGraphQLClient","RetryGraphQLClient","EnvConfig","container","mockEnvConfig","get","fn","key","undefined","registerInstance","register","inSingletonScope","mockResponse","data","user","id","name","global","fetch","mockResolvedValue","status","json","client","resolve","result","execute","query","toEqual","toHaveBeenCalledWith","objectContaining","method","headers","createUser","variables","Authorization","mockRejectedValue","Error","rejects","toThrow","errors","message","registerDecorator","post","title","result1","result2","Promise","all","toHaveBeenCalledTimes","callBody","JSON","parse","mock","calls","body","toHaveLength","toHaveProperty","not","toBeInstanceOf","Array","createPost","promises","mockRejectedValueOnce","mockResolvedValueOnce"],"sources":["GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Network error: Network failure\"\n );\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"GraphQL errors\"\n );\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Failed to parse GraphQL response as JSON\"\n );\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({ query: \"query GetUser { user { id name } }\" }),\n client.execute({ query: \"query GetPost { post { id title } }\" })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"mutation { createPost { id } }\" })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({ query: \"query { user { id } }\" });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"GraphQL errors\"\n );\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Network error\"\n );\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,QAAQ,QAAQ;AAC7D,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,aAAa;AACtB,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAElBV,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACpC,IAAIW,SAAoB;EACxB,IAAIC,aAAkC;EAEtCR,UAAU,CAAC,MAAM;IACbO,SAAS,GAAG,IAAIN,SAAS,CAAC,CAAC;IAE3BO,aAAa,GAAG;MACZC,GAAG,EAAEV,EAAE,CAACW,EAAE,CAAEC,GAAW,IAAK;QACxB,IAAIA,GAAG,KAAK,eAAe,EAAE;UACzB,OAAO,iCAAiC;QAC5C;QACA,OAAOC,SAAS;MACpB,CAAC;IACL,CAAQ;IAERL,SAAS,CAACM,gBAAgB,CAACP,SAAS,EAAEE,aAAa,CAAC;EACxD,CAAC,CAAC;EAEFZ,QAAQ,CAAC,oBAAoB,EAAE,MAAM;IACjCI,UAAU,CAAC,MAAM;MACbO,SAAS,CAACO,QAAQ,CAACX,kBAAkB,CAAC,CAACY,gBAAgB,CAAC,CAAC;IAC7D,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E;UAAI;QAAE;MAAE,CAAC,CAAC;MAEvFE,MAAM,CAACC,KAAK,GAAGvB,EAAE,CACZW,EAAE,CAAC,CAAC,CACJwD,qBAAqB,CAAC,IAAI1B,KAAK,CAAC,eAAe,CAAC,CAAC,CACjD2B,qBAAqB,CAAC;QACnB3C,MAAM,EAAE,GAAG;QACXC,IAAI,EAAE,MAAAA,CAAA,KAAYT;MACtB,CAAC,CAAC;MAEN,MAAMU,MAAM,GAAGnB,SAAS,CAACoB,OAAO,CAACzB,aAAa,CAAC;MAE/C,MAAM,CAAC8C,OAAO,EAAEC,OAAO,CAAC,GAAG,MAAMC,OAAO,CAACC,GAAG,CAAC,CACzCzB,MAAM,CAACG,OAAO,CAAC;QAAEC,KAAK,EAAE;MAAwB,CAAC,CAAC,EAClDJ,MAAM,CAACG,OAAO,CAAC;QAAEC,KAAK,EAAE;MAAwB,CAAC,CAAC,CACrD,CAAC;MAEFhC,MAAM,CAACkD,OAAO,CAAC,CAACjB,OAAO,CAACf,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACmD,OAAO,CAAC,CAAClB,OAAO,CAACf,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACuB,MAAM,CAACC,KAAK,CAAC,CAAC8B,qBAAqB,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DocumentNode } from "graphql";
|
|
2
|
+
type IHeaders = Record<string, string | number | undefined>;
|
|
3
|
+
type GraphQLRequest<TVariables = any> = {
|
|
4
|
+
query: DocumentNode | string;
|
|
5
|
+
variables?: TVariables;
|
|
6
|
+
headers?: IHeaders;
|
|
7
|
+
};
|
|
8
|
+
export interface IGraphQLClient {
|
|
9
|
+
execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;
|
|
10
|
+
}
|
|
11
|
+
export declare const GraphQLClient: import("@webiny/di").Abstraction<IGraphQLClient>;
|
|
12
|
+
export declare namespace GraphQLClient {
|
|
13
|
+
type Headers = IHeaders;
|
|
14
|
+
type Interface = IGraphQLClient;
|
|
15
|
+
type Request<TVariables = any> = GraphQLRequest<TVariables>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","GraphQLClient"],"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 GraphQLRequest<TVariables = any> = {\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAczD,OAAO,MAAMC,aAAa,GAAGD,iBAAiB,CAAiB,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { BatchingGraphQLClient } from "./BatchingGraphQLClient.js";
|
|
3
|
+
import { FetchGraphQLClient } from "./FetchGraphQLClient.js";
|
|
4
|
+
import { createFeature } from "../../shared/di/createFeature.js";
|
|
5
|
+
import { RetryGraphQLClient } from "./RetryGraphQLClient.js";
|
|
6
|
+
import { NetworkErrorPublishing } from "./NetworkErrorPublishing.js";
|
|
7
|
+
import { AuthenticationErrorPublishing } from "./AuthenticationErrorPublishing.js";
|
|
8
|
+
export const GraphQLClientFeature = createFeature({
|
|
9
|
+
name: "GraphQLClient",
|
|
10
|
+
register(container, options) {
|
|
11
|
+
// Base implementation
|
|
12
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
13
|
+
|
|
14
|
+
// Optional decorators (order matters: retry wraps batching)
|
|
15
|
+
if (options.batching) {
|
|
16
|
+
container.registerDecorator(BatchingGraphQLClient);
|
|
17
|
+
}
|
|
18
|
+
if (options.retry) {
|
|
19
|
+
container.registerDecorator(RetryGraphQLClient);
|
|
20
|
+
}
|
|
21
|
+
container.registerDecorator(NetworkErrorPublishing);
|
|
22
|
+
container.registerDecorator(AuthenticationErrorPublishing);
|
|
23
|
+
},
|
|
24
|
+
resolve(container) {
|
|
25
|
+
return {
|
|
26
|
+
client: container.resolve(GraphQLClient)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLClient","BatchingGraphQLClient","FetchGraphQLClient","createFeature","RetryGraphQLClient","NetworkErrorPublishing","AuthenticationErrorPublishing","GraphQLClientFeature","name","register","container","options","inSingletonScope","batching","registerDecorator","retry","resolve","client"],"sources":["feature.ts"],"sourcesContent":["import { GraphQLClient } from \"./abstractions.js\";\nimport { BatchingGraphQLClient } from \"./BatchingGraphQLClient.js\";\nimport { FetchGraphQLClient } from \"./FetchGraphQLClient.js\";\nimport { createFeature } from \"~/shared/di/createFeature.js\";\nimport { RetryGraphQLClient } from \"./RetryGraphQLClient.js\";\nimport { NetworkErrorPublishing } from \"./NetworkErrorPublishing.js\";\nimport { AuthenticationErrorPublishing } from \"./AuthenticationErrorPublishing.js\";\n\nexport const GraphQLClientFeature = createFeature({\n name: \"GraphQLClient\",\n register(\n container,\n options: {\n batching: boolean;\n retry: boolean;\n }\n ) {\n // Base implementation\n container.register(FetchGraphQLClient).inSingletonScope();\n\n // Optional decorators (order matters: retry wraps batching)\n if (options.batching) {\n container.registerDecorator(BatchingGraphQLClient);\n }\n\n if (options.retry) {\n container.registerDecorator(RetryGraphQLClient);\n }\n\n container.registerDecorator(NetworkErrorPublishing);\n container.registerDecorator(AuthenticationErrorPublishing);\n },\n resolve(container) {\n return {\n client: container.resolve(GraphQLClient)\n };\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa;AACtB,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,aAAa;AACtB,SAASC,kBAAkB;AAC3B,SAASC,sBAAsB;AAC/B,SAASC,6BAA6B;AAEtC,OAAO,MAAMC,oBAAoB,GAAGJ,aAAa,CAAC;EAC9CK,IAAI,EAAE,eAAe;EACrBC,QAAQA,CACJC,SAAS,EACTC,OAGC,EACH;IACE;IACAD,SAAS,CAACD,QAAQ,CAACP,kBAAkB,CAAC,CAACU,gBAAgB,CAAC,CAAC;;IAEzD;IACA,IAAID,OAAO,CAACE,QAAQ,EAAE;MAClBH,SAAS,CAACI,iBAAiB,CAACb,qBAAqB,CAAC;IACtD;IAEA,IAAIU,OAAO,CAACI,KAAK,EAAE;MACfL,SAAS,CAACI,iBAAiB,CAACV,kBAAkB,CAAC;IACnD;IAEAM,SAAS,CAACI,iBAAiB,CAACT,sBAAsB,CAAC;IACnDK,SAAS,CAACI,iBAAiB,CAACR,6BAA6B,CAAC;EAC9D,CAAC;EACDU,OAAOA,CAACN,SAAS,EAAE;IACf,OAAO;MACHO,MAAM,EAAEP,SAAS,CAACM,OAAO,CAAChB,aAAa;IAC3C,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLClient } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLClient"],"sources":["index.ts"],"sourcesContent":["export { GraphQLClient } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface BatchingOptions {\n enabled?: boolean;\n batchWindowMs?: number;\n maxBatchSize?: number;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILocalStorageGateway } from "./abstractions.js";
|
|
2
|
+
export declare class BrowserLocalStorageGateway implements ILocalStorageGateway {
|
|
3
|
+
get<T = string>(key: string): T | null;
|
|
4
|
+
set<T = string>(key: string, value: T): void;
|
|
5
|
+
remove(key: string): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
getAll(): Record<string, unknown>;
|
|
8
|
+
subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class BrowserLocalStorageGateway {
|
|
2
|
+
get(key) {
|
|
3
|
+
const value = window.localStorage.getItem(key);
|
|
4
|
+
try {
|
|
5
|
+
return value ? JSON.parse(value) : null;
|
|
6
|
+
} catch {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
set(key, value) {
|
|
11
|
+
const serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
12
|
+
window.localStorage.setItem(key, serialized);
|
|
13
|
+
|
|
14
|
+
// Dispatch local event so same-tab listeners are notified.
|
|
15
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
16
|
+
detail: {
|
|
17
|
+
key,
|
|
18
|
+
value,
|
|
19
|
+
action: "set"
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
remove(key) {
|
|
24
|
+
window.localStorage.removeItem(key);
|
|
25
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
26
|
+
detail: {
|
|
27
|
+
key,
|
|
28
|
+
action: "remove"
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
window.localStorage.clear();
|
|
34
|
+
window.dispatchEvent(new CustomEvent("localstorage:changed", {
|
|
35
|
+
detail: {
|
|
36
|
+
action: "clear"
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
getAll() {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
43
|
+
const key = window.localStorage.key(i);
|
|
44
|
+
const val = this.get(key);
|
|
45
|
+
if (val !== null) {
|
|
46
|
+
result[key] = val;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Subscribe to changes (cross-tab + same-tab)
|
|
53
|
+
subscribe(listener) {
|
|
54
|
+
const handler = ev => {
|
|
55
|
+
if (ev instanceof StorageEvent || ev instanceof CustomEvent) {
|
|
56
|
+
listener(ev);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener("storage", handler);
|
|
60
|
+
window.addEventListener("localstorage:changed", handler);
|
|
61
|
+
return () => {
|
|
62
|
+
window.removeEventListener("storage", handler);
|
|
63
|
+
window.removeEventListener("localstorage:changed", handler);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=BrowserLocalStorageGateway.js.map
|