@webiny/app 6.3.0-beta.4 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +70 -77
- package/App.js.map +1 -1
- package/AppContainer.js +3 -6
- package/AppContainer.js.map +1 -1
- package/apollo-client/InMemoryCache.js +11 -13
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.js +26 -38
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
- package/components/Image.js +11 -17
- package/components/Image.js.map +1 -1
- package/components/index.js +0 -2
- package/config/RouterConfig/Route.js +23 -28
- package/config/RouterConfig/Route.js.map +1 -1
- package/config/RouterConfig.js +11 -10
- package/config/RouterConfig.js.map +1 -1
- package/config.js +19 -20
- package/config.js.map +1 -1
- package/contexts/Ui/index.js +26 -28
- package/contexts/Ui/index.js.map +1 -1
- package/core/Plugin.js +7 -9
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.js +15 -34
- package/core/Plugins.js.map +1 -1
- package/core/Provider.js +5 -13
- package/core/Provider.js.map +1 -1
- package/core/createProvider.js +3 -6
- package/core/createProvider.js.map +1 -1
- package/core/createProviderPlugin.js +8 -13
- package/core/createProviderPlugin.js.map +1 -1
- package/errors/AuthenticationErrorEvent.js +8 -5
- package/errors/AuthenticationErrorEvent.js.map +1 -1
- package/errors/NetworkErrorEvent.js +8 -5
- package/errors/NetworkErrorEvent.js.map +1 -1
- package/errors/abstractions.js +3 -2
- package/errors/abstractions.js.map +1 -1
- package/errors/index.js +1 -4
- package/exports/admin/env-config.js +0 -2
- package/exports/admin/graphql-client.js +0 -2
- package/exports/admin/local-storage.js +0 -2
- package/exports/admin/router.js +0 -2
- package/exports/admin/security.js +0 -2
- package/exports/admin.js +0 -2
- package/features/envConfig/EnvConfig.js +12 -13
- package/features/envConfig/EnvConfig.js.map +1 -1
- package/features/envConfig/abstractions.js +2 -1
- package/features/envConfig/abstractions.js.map +1 -1
- package/features/envConfig/feature.js +9 -8
- package/features/envConfig/feature.js.map +1 -1
- package/features/envConfig/index.js +0 -2
- package/features/eventPublisher/EventPublisher.js +13 -21
- package/features/eventPublisher/EventPublisher.js.map +1 -1
- package/features/eventPublisher/abstractions.js +7 -9
- package/features/eventPublisher/abstractions.js.map +1 -1
- package/features/eventPublisher/feature.js +13 -12
- package/features/eventPublisher/feature.js.map +1 -1
- package/features/eventPublisher/index.js +1 -3
- package/features/graphqlClient/AuthenticationErrorPublishing.js +26 -26
- package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -1
- package/features/graphqlClient/BatchingGraphQLClient.js +104 -149
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
- package/features/graphqlClient/FetchGraphQLClient.js +41 -48
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
- package/features/graphqlClient/NetworkErrorPublishing.js +35 -42
- package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -1
- package/features/graphqlClient/RequestValue.js +42 -41
- package/features/graphqlClient/RequestValue.js.map +1 -1
- package/features/graphqlClient/RetryGraphQLClient.js +36 -45
- package/features/graphqlClient/RetryGraphQLClient.js.map +1 -1
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +383 -356
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
- package/features/graphqlClient/abstractions.js +2 -1
- package/features/graphqlClient/abstractions.js.map +1 -1
- package/features/graphqlClient/feature.js +14 -20
- package/features/graphqlClient/feature.js.map +1 -1
- package/features/graphqlClient/index.js +0 -2
- package/features/graphqlClient/types.js +0 -3
- package/features/localStorage/BrowserLocalStorageGateway.js +56 -63
- package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -1
- package/features/localStorage/LocalStorage.js +27 -24
- package/features/localStorage/LocalStorage.js.map +1 -1
- package/features/localStorage/LocalStorageRepository.js +75 -88
- package/features/localStorage/LocalStorageRepository.js.map +1 -1
- package/features/localStorage/abstractions.js +5 -16
- package/features/localStorage/abstractions.js.map +1 -1
- package/features/localStorage/feature.js +17 -28
- package/features/localStorage/feature.js.map +1 -1
- package/features/localStorage/index.js +1 -3
- package/features/mainGraphQLClient/MainGraphQLClient.js +18 -14
- package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -1
- package/features/mainGraphQLClient/abstractions.js +2 -1
- package/features/mainGraphQLClient/abstractions.js.map +1 -1
- package/features/mainGraphQLClient/feature.js +11 -10
- package/features/mainGraphQLClient/feature.js.map +1 -1
- package/features/mainGraphQLClient/index.js +0 -2
- package/features/router/HistoryRouterGateway.js +75 -105
- package/features/router/HistoryRouterGateway.js.map +1 -1
- package/features/router/HistoryRouterGateway.test.js +184 -193
- package/features/router/HistoryRouterGateway.test.js.map +1 -1
- package/features/router/Route.js +38 -54
- package/features/router/Route.js.map +1 -1
- package/features/router/RouteUrl.js +84 -217
- package/features/router/RouteUrl.js.map +1 -1
- package/features/router/Router.js +67 -124
- package/features/router/Router.js.map +1 -1
- package/features/router/RouterPresenter.js +44 -49
- package/features/router/RouterPresenter.js.map +1 -1
- package/features/router/RouterRepository.js +103 -111
- package/features/router/RouterRepository.js.map +1 -1
- package/features/router/RouterRepository.test.js +119 -150
- package/features/router/RouterRepository.test.js.map +1 -1
- package/features/router/abstractions.js +4 -14
- package/features/router/abstractions.js.map +1 -1
- package/features/router/feature.js +13 -12
- package/features/router/feature.js.map +1 -1
- package/features/router/index.js +1 -3
- package/helpers/InterfaceGenerator/date.js +0 -3
- package/helpers/InterfaceGenerator/id.js +0 -3
- package/helpers/InterfaceGenerator/identity.js +0 -3
- package/helpers/InterfaceGenerator/index.js +0 -3
- package/helpers/InterfaceGenerator/numeric.js +0 -3
- package/helpers/InterfaceGenerator/truthful.js +0 -3
- package/hooks/useAutocomplete/index.js +0 -2
- package/hooks/useAutocomplete/useAutocomplete.js +12 -15
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +2 -1
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +2 -1
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +2 -1
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.js +0 -2
- package/hooks/useDataList/functions/searchDataByKey.js +9 -14
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.js +0 -2
- package/hooks/useDataList/useDataList.js +131 -152
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.js +0 -2
- package/hooks/useDataList/utils/prepareLoadListParams.js +25 -34
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandler.js +12 -16
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.js +18 -20
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.js +7 -6
- package/hooks/useRegisterLegacyPlugin.js.map +1 -1
- package/hooks/useUi.js +2 -3
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +8 -4
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.js +0 -2
- package/index.js +6 -11
- package/package.json +13 -13
- package/plugins/AddQuerySelectionPlugin.js +36 -61
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +12 -11
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.js +20 -22
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.js +16 -15
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.js +19 -21
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +39 -45
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +18 -22
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +21 -29
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +6 -15
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/Typography.js +9 -14
- package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js +19 -0
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +11 -18
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.js +41 -58
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +9 -14
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.js +23 -32
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/components/Image.js +8 -15
- package/plugins/components/Image.js.map +1 -1
- package/plugins/image.js +94 -133
- package/plugins/image.js.map +1 -1
- package/plugins/index.js +35 -59
- package/plugins/index.js.map +1 -1
- package/presentation/envConfig/useEnvConfig.js +4 -8
- package/presentation/envConfig/useEnvConfig.js.map +1 -1
- package/presentation/localStorage/index.js +0 -2
- package/presentation/localStorage/useLocalStorage.js +10 -16
- package/presentation/localStorage/useLocalStorage.js.map +1 -1
- package/presentation/localStorage/useLocalStorageValue.js +15 -13
- package/presentation/localStorage/useLocalStorageValue.js.map +1 -1
- package/presentation/localStorage/useLocalStorageValues.js +23 -30
- package/presentation/localStorage/useLocalStorageValues.js.map +1 -1
- package/presentation/router/RouteElementRegistry.js +22 -25
- package/presentation/router/RouteElementRegistry.js.map +1 -1
- package/presentation/router/abstractions.js +2 -1
- package/presentation/router/abstractions.js.map +1 -1
- package/presentation/router/components/Redirect.js +8 -10
- package/presentation/router/components/Redirect.js.map +1 -1
- package/presentation/router/components/RouteContent.js +14 -17
- package/presentation/router/components/RouteContent.js.map +1 -1
- package/presentation/router/components/RouteLink.js +11 -16
- package/presentation/router/components/RouteLink.js.map +1 -1
- package/presentation/router/components/SimpleLink.js +18 -24
- package/presentation/router/components/SimpleLink.js.map +1 -1
- package/presentation/router/hooks/useRoute.js +15 -23
- package/presentation/router/hooks/useRoute.js.map +1 -1
- package/presentation/router/hooks/useRouter.js +22 -23
- package/presentation/router/hooks/useRouter.js.map +1 -1
- package/presentation/router/index.js +0 -2
- package/presentation/router/types.js +0 -3
- package/react-butterfiles/Files.js +148 -217
- package/react-butterfiles/Files.js.map +1 -1
- package/react-butterfiles/index.js +2 -1
- package/react-butterfiles/index.js.map +1 -1
- package/react-butterfiles/utils/generateId.js +2 -3
- package/react-butterfiles/utils/generateId.js.map +1 -1
- package/react-butterfiles/utils/readFileContent.js +9 -13
- package/react-butterfiles/utils/readFileContent.js.map +1 -1
- package/renderApp.js +7 -6
- package/renderApp.js.map +1 -1
- package/router.js +0 -3
- package/rslib-runtime.js +14 -0
- package/rslib-runtime.js.map +1 -0
- package/shared/di/DiContainerProvider.js +8 -12
- package/shared/di/DiContainerProvider.js.map +1 -1
- package/shared/di/createFeature.js +7 -8
- package/shared/di/createFeature.js.map +1 -1
- package/shared/di/useFeature.js +7 -3
- package/shared/di/useFeature.js.map +1 -1
- package/static/svg/close_24px.33adaadc.svg +1 -0
- package/types.js +0 -3
- package/utils/createGenericContext.js +17 -21
- package/utils/createGenericContext.js.map +1 -1
- package/utils/createHashing.js +13 -16
- package/utils/createHashing.js.map +1 -1
- package/utils/index.js +0 -2
- package/utils/legacyPluginToReactComponent.js +11 -10
- package/utils/legacyPluginToReactComponent.js.map +1 -1
- package/components/index.js.map +0 -1
- package/errors/index.js.map +0 -1
- package/exports/admin/env-config.js.map +0 -1
- package/exports/admin/graphql-client.js.map +0 -1
- package/exports/admin/local-storage.js.map +0 -1
- package/exports/admin/router.js.map +0 -1
- package/exports/admin/security.js.map +0 -1
- package/exports/admin.js.map +0 -1
- package/features/envConfig/index.js.map +0 -1
- package/features/eventPublisher/index.js.map +0 -1
- package/features/graphqlClient/index.js.map +0 -1
- package/features/graphqlClient/types.js.map +0 -1
- package/features/localStorage/index.js.map +0 -1
- package/features/mainGraphQLClient/index.js.map +0 -1
- package/features/router/index.js.map +0 -1
- package/helpers/InterfaceGenerator/date.js.map +0 -1
- package/helpers/InterfaceGenerator/id.js.map +0 -1
- package/helpers/InterfaceGenerator/identity.js.map +0 -1
- package/helpers/InterfaceGenerator/index.js.map +0 -1
- package/helpers/InterfaceGenerator/numeric.js.map +0 -1
- package/helpers/InterfaceGenerator/truthful.js.map +0 -1
- package/hooks/useAutocomplete/index.js.map +0 -1
- package/hooks/useDataList/functions/index.js.map +0 -1
- package/hooks/useDataList/index.js.map +0 -1
- package/hooks/useDataList/utils/index.js.map +0 -1
- package/i18n/index.js.map +0 -1
- package/index.js.map +0 -1
- package/presentation/localStorage/index.js.map +0 -1
- package/presentation/router/index.js.map +0 -1
- package/presentation/router/types.js.map +0 -1
- package/router.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/localStorage/LocalStorageRepository.js","sources":["../../../src/features/localStorage/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"],"names":["LocalStorageRepositoryImpl","gateway","config","Map","makeAutoObservable","key","RegExp","all","value","Object","ev","runInAction","StorageEvent","cleanKey","JSON","CustomEvent","action","Array","LocalStorageRepository","createImplementation","LocalStorageRepositoryAbstraction","LocalStorageGateway","LocalStorageConfig"],"mappings":";;;AAQO,MAAMA;IAKT,YACYC,OAAsC,EAC9CC,MAAoC,CACtC;aAFUD,OAAO,GAAPA;aAJJ,KAAK,GAAG,IAAIE;QAOhB,IAAI,CAAC,MAAM,GAAGD,OAAO,MAAM,IAAI;QAC/BE,mBAAmB,IAAI;QAEvB,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,kBAAkB;IAC3B;IAEQ,WAAWC,GAAW,EAAU;QACpC,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAAEA,KAAK,GAAGA;IACnD;IAEQ,YAAYA,GAAW,EAAU;QACrC,OAAO,IAAI,CAAC,MAAM,GAAGA,IAAI,OAAO,CAAC,IAAIC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAMD;IAC3E;IAEQ,YAAY;QAChB,MAAME,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM;QAC/B,KAAK,MAAM,CAACF,KAAKG,MAAM,IAAIC,OAAO,OAAO,CAACF,KACtC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAIF,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,MAC7C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAACA,MAAMG;IAGlD;IAEQ,qBAAqB;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAACE,CAAAA;YACtCC,YAAY;gBACR,IAAID,cAAcE,gBAAgBF,GAAG,GAAG,EACpC;oBAAA,IAAI,CAAC,IAAI,CAAC,MAAM,IAAIA,GAAG,GAAG,C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AAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAACA;IACxC;IACA,QAAQ;QACJ,IAAI,CAAC,OAAO,CAAC,KAAK;QAClB,IAAI,CAAC,KAAK,CAAC,KAAK;IACpB;IACA,OAAiB;QACb,OAAOY,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI;IACrC;AACJ;AAEO,MAAMC,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAqBC;KAAmB;AAC3D"}
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { Abstraction } from "@webiny/di";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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");
|
|
2
|
+
const LocalStorageGateway = new Abstraction("LocalStorageGateway");
|
|
3
|
+
const LocalStorageRepository = new Abstraction("LocalStorageRepository");
|
|
4
|
+
const LocalStorageConfig = new Abstraction("LocalStorageConfig");
|
|
5
|
+
const LocalStorage = new Abstraction("LocalStorage");
|
|
6
|
+
export { LocalStorage, LocalStorageConfig, LocalStorageGateway, LocalStorageRepository };
|
|
18
7
|
|
|
19
8
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/localStorage/abstractions.js","sources":["../../../src/features/localStorage/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"],"names":["LocalStorageGateway","Abstraction","LocalStorageRepository","LocalStorageConfig","LocalStorage"],"mappings":";AAYO,MAAMA,sBAAsB,IAAIC,YAAkC;AAiBlE,MAAMC,yBAAyB,IAAID,YACtC;AAYG,MAAME,qBAAqB,IAAIF,YAAiC;AAehE,MAAMG,eAAe,IAAIH,YAA2B"}
|
|
@@ -1,34 +1,23 @@
|
|
|
1
|
-
import { LocalStorageConfig, LocalStorageGateway
|
|
1
|
+
import { LocalStorage, LocalStorageConfig, LocalStorageGateway } from "./abstractions.js";
|
|
2
2
|
import { BrowserLocalStorageGateway } from "./BrowserLocalStorageGateway.js";
|
|
3
3
|
import { LocalStorageRepository } from "./LocalStorageRepository.js";
|
|
4
|
-
import { LocalStorage } from "./LocalStorage.js";
|
|
4
|
+
import { LocalStorage as external_LocalStorage_js_LocalStorage } from "./LocalStorage.js";
|
|
5
5
|
import { createFeature } from "../../shared/di/createFeature.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
}
|
|
6
|
+
const LocalStorageFeature = createFeature({
|
|
7
|
+
name: "LocalStorage",
|
|
8
|
+
register (container, config = {}) {
|
|
9
|
+
container.registerInstance(LocalStorageConfig, config);
|
|
10
|
+
container.registerInstance(LocalStorageGateway, new BrowserLocalStorageGateway());
|
|
11
|
+
container.register(LocalStorageRepository).inSingletonScope();
|
|
12
|
+
container.register(external_LocalStorage_js_LocalStorage).inSingletonScope();
|
|
13
|
+
},
|
|
14
|
+
resolve (container) {
|
|
15
|
+
return {
|
|
16
|
+
localStorageService: container.resolve(LocalStorage),
|
|
17
|
+
localStorageConfig: container.resolve(LocalStorageConfig)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
32
20
|
});
|
|
21
|
+
export { LocalStorageFeature };
|
|
33
22
|
|
|
34
23
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/localStorage/feature.js","sources":["../../../src/features/localStorage/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"],"names":["LocalStorageFeature","createFeature","container","config","LocalStorageConfig","LocalStorageGateway","BrowserLocalStorageGateway","LocalStorageRepository","LocalStorage","Abstraction"],"mappings":";;;;;AAgBO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS,EAAEC,SAA8B,CAAC,CAAC;QAEhDD,UAAU,gBAAgB,CAACE,oBAAoBD;QAG/CD,UAAU,gBAAgB,CAACG,qBAAqB,IAAIC;QAGpDJ,UAAU,QAAQ,CAACK,wBAAwB,gBAAgB;QAC3DL,UAAU,QAAQ,CAACM,uCAAc,gBAAgB;IACrD;IACA,SAAQN,SAAS;QACb,OAAO;YACH,qBAAqBA,UAAU,OAAO,CAACO;YACvC,oBAAoBP,UAAU,OAAO,CAACE;QAC1C;IACJ;AACJ"}
|
|
@@ -3,21 +3,25 @@ import { MainGraphQLClient } from "./abstractions.js";
|
|
|
3
3
|
import { GraphQLClient } from "../graphqlClient/abstractions.js";
|
|
4
4
|
import { EnvConfig } from "../envConfig/index.js";
|
|
5
5
|
class MainGraphQLClientImpl {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const DefaultMainGraphQLClient = createImplementation({
|
|
18
|
+
abstraction: MainGraphQLClient,
|
|
19
|
+
implementation: MainGraphQLClientImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
EnvConfig,
|
|
22
|
+
GraphQLClient
|
|
23
|
+
]
|
|
21
24
|
});
|
|
25
|
+
export { DefaultMainGraphQLClient };
|
|
22
26
|
|
|
23
27
|
//# sourceMappingURL=MainGraphQLClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/mainGraphQLClient/MainGraphQLClient.js","sources":["../../../src/features/mainGraphQLClient/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"],"names":["MainGraphQLClientImpl","envConfig","client","params","DefaultMainGraphQLClient","createImplementation","MainGraphQLClient","EnvConfig","GraphQLClient"],"mappings":";;;;AAKA,MAAMA;IAGF,YACIC,SAA8B,EACtBC,MAA+B,CACzC;aADUA,MAAM,GAANA;QAER,IAAI,CAAC,QAAQ,GAAGD,UAAU,GAAG,CAAC;IAClC;IAEA,MAAM,QACFE,MAA6C,EAC7B;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAAE,UAAU,IAAI,CAAC,QAAQ;YAAE,GAAGA,MAAM;QAAC;IACpE;AACJ;AAEO,MAAMC,2BAA2BC,qBAAqB;IACzD,aAAaC;IACb,gBAAgBN;IAChB,cAAc;QAACO;QAAWC;KAAc;AAC5C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/admin";
|
|
2
|
-
|
|
2
|
+
const MainGraphQLClient = createAbstraction("MainGraphQLClient");
|
|
3
|
+
export { MainGraphQLClient };
|
|
3
4
|
|
|
4
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/mainGraphQLClient/abstractions.js","sources":["../../../src/features/mainGraphQLClient/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"],"names":["MainGraphQLClient","createAbstraction"],"mappings":";AAiBO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { MainGraphQLClient } from "./abstractions.js";
|
|
2
2
|
import { DefaultMainGraphQLClient } from "./MainGraphQLClient.js";
|
|
3
3
|
import { createFeature } from "../../shared/di/createFeature.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
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
14
|
});
|
|
15
|
+
export { MainGraphQLClientFeature };
|
|
15
16
|
|
|
16
17
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/mainGraphQLClient/feature.js","sources":["../../../src/features/mainGraphQLClient/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"],"names":["MainGraphQLClientFeature","createFeature","container","DefaultMainGraphQLClient","MainGraphQLClient"],"mappings":";;;AAIO,MAAMA,2BAA2BC,cAAc;IAClD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,0BAA0B,gBAAgB;IACjE;IACA,SAAQD,SAAS;QACb,OAAO;YACH,QAAQA,UAAU,OAAO,CAACE;QAC9B;IACJ;AACJ"}
|
|
@@ -1,118 +1,88 @@
|
|
|
1
1
|
import { RouteUrl } from "./RouteUrl.js";
|
|
2
2
|
import { Router } from "./Router.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
class HistoryRouterGateway {
|
|
4
|
+
constructor(history, baseUrl){
|
|
5
|
+
this.guards = new Set();
|
|
6
|
+
this.history = history;
|
|
7
|
+
this.router = new Router(baseUrl);
|
|
8
|
+
this.stopListening = history.listen(async ({ location })=>{
|
|
9
|
+
const queryParams = Object.fromEntries(new URLSearchParams(location.search).entries());
|
|
10
|
+
this.resolvePathname(location.pathname, queryParams);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
addGuard(config) {
|
|
14
|
+
const hadGuards = this.guards.size > 0;
|
|
15
|
+
this.guards.add(config);
|
|
16
|
+
if (!hadGuards) this.installBlocker();
|
|
17
|
+
return ()=>{
|
|
18
|
+
this.guards.delete(config);
|
|
19
|
+
if (0 === this.guards.size) this.removeBlocker();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
goToRoute(name, params) {
|
|
23
|
+
const route = this.router.findRoute(name);
|
|
24
|
+
if (!route) return void console.warn(`Route "${name}" not found.`);
|
|
25
|
+
const baseUrl = this.router.getBaseUrl();
|
|
26
|
+
this.history.push(RouteUrl.fromPattern(route.path, params, baseUrl));
|
|
20
27
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
setRoutes(routes) {
|
|
29
|
+
this.router.setRoutes(routes);
|
|
30
|
+
const queryParams = Object.fromEntries(new URLSearchParams(this.history.location.search).entries());
|
|
31
|
+
const currentPathname = this.history.location.pathname;
|
|
32
|
+
this.resolvePathname(currentPathname, queryParams);
|
|
33
|
+
}
|
|
34
|
+
destroy() {
|
|
35
|
+
this.stopListening();
|
|
24
36
|
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;
|
|
37
|
+
this.guards.clear();
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
39
|
+
pushState(url) {
|
|
40
|
+
this.history.push(url);
|
|
55
41
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
findBlockingGuard() {
|
|
63
|
-
for (const config of this.guards) {
|
|
64
|
-
if (config.guard()) {
|
|
65
|
-
return config;
|
|
66
|
-
}
|
|
42
|
+
async resolvePathname(pathname, queryParams) {
|
|
43
|
+
const result = this.router.resolve(pathname, queryParams);
|
|
44
|
+
if (!result) return;
|
|
45
|
+
const { matchedRoute, onMatch } = result;
|
|
46
|
+
onMatch(matchedRoute);
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
installBlocker() {
|
|
71
|
-
if (this.unblock) {
|
|
72
|
-
this.unblock();
|
|
48
|
+
findBlockingGuard() {
|
|
49
|
+
for (const config of this.guards)if (config.guard()) return config;
|
|
73
50
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
51
|
+
installBlocker() {
|
|
52
|
+
if (this.unblock) this.unblock();
|
|
53
|
+
this.unblock = this.history.block((tx)=>{
|
|
54
|
+
const blockingGuard = this.findBlockingGuard();
|
|
55
|
+
if (blockingGuard) {
|
|
56
|
+
let resolved = false;
|
|
57
|
+
blockingGuard.onBlocked({
|
|
58
|
+
continue: ()=>{
|
|
59
|
+
if (!resolved) {
|
|
60
|
+
resolved = true;
|
|
61
|
+
this.removeBlockerAndRetry(tx);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
cancel: ()=>{
|
|
65
|
+
resolved = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} else this.removeBlockerAndRetry(tx);
|
|
89
69
|
});
|
|
90
|
-
} else {
|
|
91
|
-
this.removeBlockerAndRetry(tx);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
removeBlocker() {
|
|
96
|
-
if (this.unblock) {
|
|
97
|
-
this.unblock();
|
|
98
|
-
this.unblock = undefined;
|
|
99
70
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
tx.retry();
|
|
115
|
-
}
|
|
71
|
+
removeBlocker() {
|
|
72
|
+
if (this.unblock) {
|
|
73
|
+
this.unblock();
|
|
74
|
+
this.unblock = void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
removeBlockerAndRetry(tx) {
|
|
78
|
+
this.removeBlocker();
|
|
79
|
+
const unlisten = this.history.listen(()=>{
|
|
80
|
+
unlisten();
|
|
81
|
+
if (this.guards.size > 0) this.installBlocker();
|
|
82
|
+
});
|
|
83
|
+
tx.retry();
|
|
84
|
+
}
|
|
116
85
|
}
|
|
86
|
+
export { HistoryRouterGateway };
|
|
117
87
|
|
|
118
88
|
//# sourceMappingURL=HistoryRouterGateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/router/HistoryRouterGateway.js","sources":["../../../src/features/router/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"],"names":["HistoryRouterGateway","history","baseUrl","Set","Router","location","queryParams","Object","URLSearchParams","config","hadGuards","name","params","route","console","RouteUrl","routes","currentPathname","url","pathname","result","matchedRoute","onMatch","tx","blockingGuard","resolved","undefined","unlisten"],"mappings":";;AAOO,MAAMA;IAOT,YAAYC,OAAgB,EAAEC,OAAe,CAAE;aAFvC,MAAM,GAAG,IAAIC;QAGjB,IAAI,CAAC,OAAO,GAAGF;QACf,IAAI,CAAC,MAAM,GAAG,IAAIG,OAAOF;QAEzB,IAAI,CAAC,aAAa,GAAGD,QAAQ,MAAM,CAAC,OAAO,EAAEI,QAAQ,EAAE;YACnD,MAAMC,cAAcC,OAAO,WAAW,CAAC,IAAIC,gBAAgBH,SAAS,MAAM,EAAE,OAAO;YACnF,IAAI,CAAC,eAAe,CAACA,SAAS,QAAQ,EAAEC;QAC5C;IACJ;IAEA,SAASG,MAAkC,EAAiB;QACxD,MAAMC,YAAY,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG;QACrC,IAAI,CAAC,MAAM,CAAC,GAAG,CAACD;QAChB,IAAI,CAACC,WACD,IAAI,CAAC,cAAc;QAEvB,OAAO;YACH,IAAI,CAAC,MAAM,CAAC,MAAM,CAACD;YACnB,IAAI,AAAqB,MAArB,IAAI,CAAC,MAAM,CAAC,IAAI,EAChB,IAAI,CAAC,aAAa;QAE1B;IACJ;IAEA,UAAUE,IAAY,EAAEC,MAAoB,EAAQ;Q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