@backstage/core-compat-api 0.2.8-next.1 → 0.2.8-next.3
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/CHANGELOG.md +20 -0
- package/dist/compatWrapper/BackwardsCompatProvider.esm.js +1 -1
- package/dist/compatWrapper/BackwardsCompatProvider.esm.js.map +1 -1
- package/dist/compatWrapper/ForwardsCompatProvider.esm.js +98 -2
- package/dist/compatWrapper/ForwardsCompatProvider.esm.js.map +1 -1
- package/dist/convertLegacyRouteRef.esm.js +41 -4
- package/dist/convertLegacyRouteRef.esm.js.map +1 -1
- package/dist/core-app-api/src/apis/system/ApiAggregator.esm.js +18 -0
- package/dist/core-app-api/src/apis/system/ApiAggregator.esm.js.map +1 -0
- package/dist/core-app-api/src/apis/system/ApiProvider.esm.js +25 -0
- package/dist/core-app-api/src/apis/system/ApiProvider.esm.js.map +1 -0
- package/dist/frontend-plugin-api/src/routing/ExternalRouteRef.esm.js.map +1 -1
- package/dist/index.d.ts +29 -2
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @backstage/core-compat-api
|
|
2
2
|
|
|
3
|
+
## 0.2.8-next.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/frontend-plugin-api@0.7.0-next.3
|
|
9
|
+
- @backstage/core-plugin-api@1.9.3
|
|
10
|
+
- @backstage/version-bridge@1.0.8
|
|
11
|
+
|
|
12
|
+
## 0.2.8-next.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 72754db: Updated usage of `useRouteRef`, which can now always return `undefined`.
|
|
17
|
+
- 16cf96c: Both `compatWrapper` and `convertLegacyRouteRef` now support converting from the new system to the old.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/frontend-plugin-api@0.7.0-next.2
|
|
20
|
+
- @backstage/core-plugin-api@1.9.3
|
|
21
|
+
- @backstage/version-bridge@1.0.8
|
|
22
|
+
|
|
3
23
|
## 0.2.8-next.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -128,5 +128,5 @@ function BackwardsCompatProvider(props) {
|
|
|
128
128
|
return /* @__PURE__ */ React.createElement(LegacyRoutingProvider, null, /* @__PURE__ */ React.createElement(LegacyAppContextProvider, null, props.children));
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
export { BackwardsCompatProvider };
|
|
131
|
+
export { BackwardsCompatProvider, toLegacyPlugin };
|
|
132
132
|
//# sourceMappingURL=BackwardsCompatProvider.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackwardsCompatProvider.esm.js","sources":["../../src/compatWrapper/BackwardsCompatProvider.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useMemo } from 'react';\nimport { ReactNode } from 'react';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { AppContextProvider } from '../../../core-app-api/src/app/AppContext';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { RouteResolver } from '../../../core-plugin-api/src/routing/useRouteRef';\nimport {\n createPlugin as createNewPlugin,\n BackstagePlugin as NewBackstagePlugin,\n appTreeApiRef,\n componentsApiRef,\n coreComponentRefs,\n iconsApiRef,\n useApi,\n routeResolutionApiRef,\n} from '@backstage/frontend-plugin-api';\nimport {\n AppComponents,\n IconComponent,\n BackstagePlugin as LegacyBackstagePlugin,\n RouteRef,\n} from '@backstage/core-plugin-api';\nimport {\n VersionedValue,\n createVersionedContext,\n createVersionedValueMap,\n getOrCreateGlobalSingleton,\n} from '@backstage/version-bridge';\nimport { convertLegacyRouteRef } from '../convertLegacyRouteRef';\n\n// Make sure that we only convert each new plugin instance to its legacy equivalent once\nconst legacyPluginStore = getOrCreateGlobalSingleton(\n 'legacy-plugin-compatibility-store',\n () => new WeakMap<NewBackstagePlugin, LegacyBackstagePlugin>(),\n);\n\nfunction toLegacyPlugin(plugin: NewBackstagePlugin): LegacyBackstagePlugin {\n let legacy = legacyPluginStore.get(plugin);\n if (legacy) {\n return legacy;\n }\n\n const errorMsg = 'Not implemented in legacy plugin compatibility layer';\n const notImplemented = () => {\n throw new Error(errorMsg);\n };\n\n legacy = {\n getId(): string {\n return plugin.id;\n },\n get routes() {\n return {};\n },\n get externalRoutes() {\n return {};\n },\n getApis: notImplemented,\n getFeatureFlags: notImplemented,\n provide: notImplemented,\n };\n\n legacyPluginStore.set(plugin, legacy);\n return legacy;\n}\n\n// TODO: Currently a very naive implementation, may need some more work\nfunction toNewPlugin(plugin: LegacyBackstagePlugin): NewBackstagePlugin {\n return createNewPlugin({\n id: plugin.getId(),\n });\n}\n\n// Recreates the old AppContext APIs using the various new APIs that replaced it\nfunction LegacyAppContextProvider(props: { children: ReactNode }) {\n const appTreeApi = useApi(appTreeApiRef);\n const componentsApi = useApi(componentsApiRef);\n const iconsApi = useApi(iconsApiRef);\n\n const appContext = useMemo(() => {\n const { tree } = appTreeApi.getTree();\n\n let gatheredPlugins: LegacyBackstagePlugin[] | undefined = undefined;\n\n const ErrorBoundaryFallback = componentsApi.getComponent(\n coreComponentRefs.errorBoundaryFallback,\n );\n const ErrorBoundaryFallbackWrapper: AppComponents['ErrorBoundaryFallback'] =\n ({ plugin, ...rest }) => (\n <ErrorBoundaryFallback\n {...rest}\n plugin={plugin && toNewPlugin(plugin)}\n />\n );\n\n return {\n getPlugins(): LegacyBackstagePlugin[] {\n if (gatheredPlugins) {\n return gatheredPlugins;\n }\n\n const pluginSet = new Set<LegacyBackstagePlugin>();\n for (const node of tree.nodes.values()) {\n const plugin = node.spec.source;\n if (plugin) {\n pluginSet.add(toLegacyPlugin(plugin));\n }\n }\n gatheredPlugins = Array.from(pluginSet);\n\n return gatheredPlugins;\n },\n\n getSystemIcon(key: string): IconComponent | undefined {\n return iconsApi.getIcon(key);\n },\n\n getSystemIcons(): Record<string, IconComponent> {\n return Object.fromEntries(\n iconsApi.listIconKeys().map(key => [key, iconsApi.getIcon(key)!]),\n );\n },\n\n getComponents(): AppComponents {\n return {\n NotFoundErrorPage: componentsApi.getComponent(\n coreComponentRefs.notFoundErrorPage,\n ),\n BootErrorPage() {\n throw new Error(\n 'The BootErrorPage app component should not be accessed by plugins',\n );\n },\n Progress: componentsApi.getComponent(coreComponentRefs.progress),\n Router() {\n throw new Error(\n 'The Router app component should not be accessed by plugins',\n );\n },\n ErrorBoundaryFallback: ErrorBoundaryFallbackWrapper,\n };\n },\n };\n }, [appTreeApi, componentsApi, iconsApi]);\n\n return (\n <AppContextProvider appContext={appContext}>\n {props.children}\n </AppContextProvider>\n );\n}\n\nconst RoutingContext = createVersionedContext<{ 1: RouteResolver }>(\n 'routing-context',\n);\n\nfunction LegacyRoutingProvider(props: { children: ReactNode }) {\n const routeResolutionApi = useApi(routeResolutionApiRef);\n\n const value = useMemo<VersionedValue<{ 1: RouteResolver }>>(() => {\n return createVersionedValueMap({\n 1: {\n resolve(anyRouteRef, location) {\n const sourcePath =\n typeof location === 'string' ? location : location.pathname ?? '';\n\n return routeResolutionApi.resolve(\n // This removes the requirement to use convertLegacyRouteRef inside plugins, but\n // they still need to converted when passed to the plugin instance\n convertLegacyRouteRef(anyRouteRef as RouteRef),\n { sourcePath },\n );\n },\n },\n });\n }, [routeResolutionApi]);\n\n return (\n <RoutingContext.Provider value={value}>\n {props.children}\n </RoutingContext.Provider>\n );\n}\n\nexport function BackwardsCompatProvider(props: { children: ReactNode }) {\n return (\n <LegacyRoutingProvider>\n <LegacyAppContextProvider>{props.children}</LegacyAppContextProvider>\n </LegacyRoutingProvider>\n );\n}\n"],"names":["createNewPlugin"],"mappings":";;;;;;AA+CA,MAAM,iBAAoB,GAAA,0BAAA;AAAA,EACxB,mCAAA;AAAA,EACA,0BAAU,OAAmD,EAAA;AAC/D,CAAA,CAAA;AAEA,SAAS,eAAe,MAAmD,EAAA;AACzE,EAAI,IAAA,MAAA,GAAS,iBAAkB,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AACzC,EAAA,IAAI,MAAQ,EAAA;AACV,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,QAAW,GAAA,sDAAA,CAAA;AACjB,EAAA,MAAM,iBAAiB,MAAM;AAC3B,IAAM,MAAA,IAAI,MAAM,QAAQ,CAAA,CAAA;AAAA,GAC1B,CAAA;AAEA,EAAS,MAAA,GAAA;AAAA,IACP,KAAgB,GAAA;AACd,MAAA,OAAO,MAAO,CAAA,EAAA,CAAA;AAAA,KAChB;AAAA,IACA,IAAI,MAAS,GAAA;AACX,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAAA,IACA,IAAI,cAAiB,GAAA;AACnB,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAAA,IACA,OAAS,EAAA,cAAA;AAAA,IACT,eAAiB,EAAA,cAAA;AAAA,IACjB,OAAS,EAAA,cAAA;AAAA,GACX,CAAA;AAEA,EAAkB,iBAAA,CAAA,GAAA,CAAI,QAAQ,MAAM,CAAA,CAAA;AACpC,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGA,SAAS,YAAY,MAAmD,EAAA;AACtE,EAAA,OAAOA,YAAgB,CAAA;AAAA,IACrB,EAAA,EAAI,OAAO,KAAM,EAAA;AAAA,GAClB,CAAA,CAAA;AACH,CAAA;AAGA,SAAS,yBAAyB,KAAgC,EAAA;AAChE,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA,CAAA;AACvC,EAAM,MAAA,aAAA,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AAO,QAAA,KAAa,QAAW,GAAA,QAAA,GAAW,SAAS,QAAY,IAAA,EAAA,CAAA;AAEjE,UAAA,OAAO,kBAAmB,CAAA,OAAA;AAAA;AAAA;AAAA,YAGxB,sBAAsB,WAAuB,CAAA;AAAA,YAC7C,EAAE,UAAW,EAAA;AAAA,WACf,CAAA;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH,EAAG,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEvB,EAAA,2CACG,cAAe,CAAA,QAAA,EAAf,EAAwB,KAAA,EAAA,EACtB,MAAM,QACT,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,wBAAwB,KAAgC,EAAA;AACtE,EAAA,2CACG,qBACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,wBAA0B,EAAA,IAAA,EAAA,KAAA,CAAM,QAAS,CAC5C,CAAA,CAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"BackwardsCompatProvider.esm.js","sources":["../../src/compatWrapper/BackwardsCompatProvider.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useMemo } from 'react';\nimport { ReactNode } from 'react';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { AppContextProvider } from '../../../core-app-api/src/app/AppContext';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { RouteResolver } from '../../../core-plugin-api/src/routing/useRouteRef';\nimport {\n createPlugin as createNewPlugin,\n BackstagePlugin as NewBackstagePlugin,\n appTreeApiRef,\n componentsApiRef,\n coreComponentRefs,\n iconsApiRef,\n useApi,\n routeResolutionApiRef,\n} from '@backstage/frontend-plugin-api';\nimport {\n AppComponents,\n IconComponent,\n BackstagePlugin as LegacyBackstagePlugin,\n RouteRef,\n} from '@backstage/core-plugin-api';\nimport {\n VersionedValue,\n createVersionedContext,\n createVersionedValueMap,\n getOrCreateGlobalSingleton,\n} from '@backstage/version-bridge';\nimport { convertLegacyRouteRef } from '../convertLegacyRouteRef';\n\n// Make sure that we only convert each new plugin instance to its legacy equivalent once\nconst legacyPluginStore = getOrCreateGlobalSingleton(\n 'legacy-plugin-compatibility-store',\n () => new WeakMap<NewBackstagePlugin, LegacyBackstagePlugin>(),\n);\n\nexport function toLegacyPlugin(\n plugin: NewBackstagePlugin,\n): LegacyBackstagePlugin {\n let legacy = legacyPluginStore.get(plugin);\n if (legacy) {\n return legacy;\n }\n\n const errorMsg = 'Not implemented in legacy plugin compatibility layer';\n const notImplemented = () => {\n throw new Error(errorMsg);\n };\n\n legacy = {\n getId(): string {\n return plugin.id;\n },\n get routes() {\n return {};\n },\n get externalRoutes() {\n return {};\n },\n getApis: notImplemented,\n getFeatureFlags: notImplemented,\n provide: notImplemented,\n };\n\n legacyPluginStore.set(plugin, legacy);\n return legacy;\n}\n\n// TODO: Currently a very naive implementation, may need some more work\nfunction toNewPlugin(plugin: LegacyBackstagePlugin): NewBackstagePlugin {\n return createNewPlugin({\n id: plugin.getId(),\n });\n}\n\n// Recreates the old AppContext APIs using the various new APIs that replaced it\nfunction LegacyAppContextProvider(props: { children: ReactNode }) {\n const appTreeApi = useApi(appTreeApiRef);\n const componentsApi = useApi(componentsApiRef);\n const iconsApi = useApi(iconsApiRef);\n\n const appContext = useMemo(() => {\n const { tree } = appTreeApi.getTree();\n\n let gatheredPlugins: LegacyBackstagePlugin[] | undefined = undefined;\n\n const ErrorBoundaryFallback = componentsApi.getComponent(\n coreComponentRefs.errorBoundaryFallback,\n );\n const ErrorBoundaryFallbackWrapper: AppComponents['ErrorBoundaryFallback'] =\n ({ plugin, ...rest }) => (\n <ErrorBoundaryFallback\n {...rest}\n plugin={plugin && toNewPlugin(plugin)}\n />\n );\n\n return {\n getPlugins(): LegacyBackstagePlugin[] {\n if (gatheredPlugins) {\n return gatheredPlugins;\n }\n\n const pluginSet = new Set<LegacyBackstagePlugin>();\n for (const node of tree.nodes.values()) {\n const plugin = node.spec.source;\n if (plugin) {\n pluginSet.add(toLegacyPlugin(plugin));\n }\n }\n gatheredPlugins = Array.from(pluginSet);\n\n return gatheredPlugins;\n },\n\n getSystemIcon(key: string): IconComponent | undefined {\n return iconsApi.getIcon(key);\n },\n\n getSystemIcons(): Record<string, IconComponent> {\n return Object.fromEntries(\n iconsApi.listIconKeys().map(key => [key, iconsApi.getIcon(key)!]),\n );\n },\n\n getComponents(): AppComponents {\n return {\n NotFoundErrorPage: componentsApi.getComponent(\n coreComponentRefs.notFoundErrorPage,\n ),\n BootErrorPage() {\n throw new Error(\n 'The BootErrorPage app component should not be accessed by plugins',\n );\n },\n Progress: componentsApi.getComponent(coreComponentRefs.progress),\n Router() {\n throw new Error(\n 'The Router app component should not be accessed by plugins',\n );\n },\n ErrorBoundaryFallback: ErrorBoundaryFallbackWrapper,\n };\n },\n };\n }, [appTreeApi, componentsApi, iconsApi]);\n\n return (\n <AppContextProvider appContext={appContext}>\n {props.children}\n </AppContextProvider>\n );\n}\n\nconst RoutingContext = createVersionedContext<{ 1: RouteResolver }>(\n 'routing-context',\n);\n\nfunction LegacyRoutingProvider(props: { children: ReactNode }) {\n const routeResolutionApi = useApi(routeResolutionApiRef);\n\n const value = useMemo<VersionedValue<{ 1: RouteResolver }>>(() => {\n return createVersionedValueMap({\n 1: {\n resolve(anyRouteRef, location) {\n const sourcePath =\n typeof location === 'string' ? location : location.pathname ?? '';\n\n return routeResolutionApi.resolve(\n // This removes the requirement to use convertLegacyRouteRef inside plugins, but\n // they still need to converted when passed to the plugin instance\n convertLegacyRouteRef(anyRouteRef as RouteRef),\n { sourcePath },\n );\n },\n },\n });\n }, [routeResolutionApi]);\n\n return (\n <RoutingContext.Provider value={value}>\n {props.children}\n </RoutingContext.Provider>\n );\n}\n\nexport function BackwardsCompatProvider(props: { children: ReactNode }) {\n return (\n <LegacyRoutingProvider>\n <LegacyAppContextProvider>{props.children}</LegacyAppContextProvider>\n </LegacyRoutingProvider>\n );\n}\n"],"names":["createNewPlugin"],"mappings":";;;;;;AA+CA,MAAM,iBAAoB,GAAA,0BAAA;AAAA,EACxB,mCAAA;AAAA,EACA,0BAAU,OAAmD,EAAA;AAC/D,CAAA,CAAA;AAEO,SAAS,eACd,MACuB,EAAA;AACvB,EAAI,IAAA,MAAA,GAAS,iBAAkB,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AACzC,EAAA,IAAI,MAAQ,EAAA;AACV,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,QAAW,GAAA,sDAAA,CAAA;AACjB,EAAA,MAAM,iBAAiB,MAAM;AAC3B,IAAM,MAAA,IAAI,MAAM,QAAQ,CAAA,CAAA;AAAA,GAC1B,CAAA;AAEA,EAAS,MAAA,GAAA;AAAA,IACP,KAAgB,GAAA;AACd,MAAA,OAAO,MAAO,CAAA,EAAA,CAAA;AAAA,KAChB;AAAA,IACA,IAAI,MAAS,GAAA;AACX,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAAA,IACA,IAAI,cAAiB,GAAA;AACnB,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAAA,IACA,OAAS,EAAA,cAAA;AAAA,IACT,eAAiB,EAAA,cAAA;AAAA,IACjB,OAAS,EAAA,cAAA;AAAA,GACX,CAAA;AAEA,EAAkB,iBAAA,CAAA,GAAA,CAAI,QAAQ,MAAM,CAAA,CAAA;AACpC,EAAO,OAAA,MAAA,CAAA;AACT,CAAA;AAGA,SAAS,YAAY,MAAmD,EAAA;AACtE,EAAA,OAAOA,YAAgB,CAAA;AAAA,IACrB,EAAA,EAAI,OAAO,KAAM,EAA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A,GAAQ,QAA8C,MAAM;AAChE,IAAA,OAAO,uBAAwB,CAAA;AAAA,MAC7B,CAAG,EAAA;AAAA,QACD,OAAA,CAAQ,aAAa,QAAU,EAAA;AAC7B,UAAA,MAAM,aACJ,OAAO,QAAA,KAAa,QAAW,GAAA,QAAA,GAAW,SAAS,QAAY,IAAA,EAAA,CAAA;AAEjE,UAAA,OAAO,kBAAmB,CAAA,OAAA;AAAA;AAAA;AAAA,YAGxB,sBAAsB,WAAuB,CAAA;AAAA,YAC7C,EAAE,UAAW,EAAA;AAAA,WACf,CAAA;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH,EAAG,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEvB,EAAA,2CACG,cAAe,CAAA,QAAA,EAAf,EAAwB,KAAA,EAAA,EACtB,MAAM,QACT,CAAA,CAAA;AAEJ,CAAA;AAEO,SAAS,wBAAwB,KAAgC,EAAA;AACtE,EAAA,2CACG,qBACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,wBAA0B,EAAA,IAAA,EAAA,KAAA,CAAM,QAAS,CAC5C,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1,7 +1,103 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useApp } from '@backstage/core-plugin-api';
|
|
2
|
+
import { componentsApiRef, iconsApiRef, routeResolutionApiRef, coreComponentRefs } from '@backstage/frontend-plugin-api';
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import { toLegacyPlugin } from './BackwardsCompatProvider.esm.js';
|
|
5
|
+
import { ApiProvider } from '../core-app-api/src/apis/system/ApiProvider.esm.js';
|
|
6
|
+
import { useVersionedContext } from '@backstage/version-bridge';
|
|
7
|
+
import { convertLegacyRouteRef } from '../convertLegacyRouteRef.esm.js';
|
|
2
8
|
|
|
9
|
+
class CompatComponentsApi {
|
|
10
|
+
#Progress;
|
|
11
|
+
#NotFoundErrorPage;
|
|
12
|
+
#ErrorBoundaryFallback;
|
|
13
|
+
constructor(app) {
|
|
14
|
+
const components = app.getComponents();
|
|
15
|
+
const ErrorBoundaryFallback = (props) => /* @__PURE__ */ React.createElement(
|
|
16
|
+
components.ErrorBoundaryFallback,
|
|
17
|
+
{
|
|
18
|
+
...props,
|
|
19
|
+
plugin: props.plugin && toLegacyPlugin(props.plugin)
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
this.#Progress = components.Progress;
|
|
23
|
+
this.#NotFoundErrorPage = components.NotFoundErrorPage;
|
|
24
|
+
this.#ErrorBoundaryFallback = ErrorBoundaryFallback;
|
|
25
|
+
}
|
|
26
|
+
getComponent(ref) {
|
|
27
|
+
switch (ref.id) {
|
|
28
|
+
case coreComponentRefs.progress.id:
|
|
29
|
+
return this.#Progress;
|
|
30
|
+
case coreComponentRefs.notFoundErrorPage.id:
|
|
31
|
+
return this.#NotFoundErrorPage;
|
|
32
|
+
case coreComponentRefs.errorBoundaryFallback.id:
|
|
33
|
+
return this.#ErrorBoundaryFallback;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(
|
|
36
|
+
`No backwards compatible component is available for ref '${ref.id}'`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
class CompatIconsApi {
|
|
42
|
+
#app;
|
|
43
|
+
constructor(app) {
|
|
44
|
+
this.#app = app;
|
|
45
|
+
}
|
|
46
|
+
getIcon(key) {
|
|
47
|
+
return this.#app.getSystemIcon(key);
|
|
48
|
+
}
|
|
49
|
+
listIconKeys() {
|
|
50
|
+
return Object.keys(this.#app.getSystemIcons());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class CompatRouteResolutionApi {
|
|
54
|
+
#routeResolver;
|
|
55
|
+
constructor(routeResolver) {
|
|
56
|
+
this.#routeResolver = routeResolver;
|
|
57
|
+
}
|
|
58
|
+
resolve(anyRouteRef, options) {
|
|
59
|
+
const legacyRef = convertLegacyRouteRef(anyRouteRef);
|
|
60
|
+
return this.#routeResolver.resolve(legacyRef, options?.sourcePath ?? "/");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class ForwardsCompatApis {
|
|
64
|
+
#componentsApi;
|
|
65
|
+
#iconsApi;
|
|
66
|
+
#routeResolutionApi;
|
|
67
|
+
constructor(app, routeResolver) {
|
|
68
|
+
this.#componentsApi = new CompatComponentsApi(app);
|
|
69
|
+
this.#iconsApi = new CompatIconsApi(app);
|
|
70
|
+
this.#routeResolutionApi = new CompatRouteResolutionApi(routeResolver);
|
|
71
|
+
}
|
|
72
|
+
get(ref) {
|
|
73
|
+
if (ref.id === componentsApiRef.id) {
|
|
74
|
+
return this.#componentsApi;
|
|
75
|
+
} else if (ref.id === iconsApiRef.id) {
|
|
76
|
+
return this.#iconsApi;
|
|
77
|
+
} else if (ref.id === routeResolutionApiRef.id) {
|
|
78
|
+
return this.#routeResolutionApi;
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function NewAppApisProvider(props) {
|
|
84
|
+
const app = useApp();
|
|
85
|
+
const versionedRouteResolverContext = useVersionedContext("routing-context");
|
|
86
|
+
if (!versionedRouteResolverContext) {
|
|
87
|
+
throw new Error("Routing context is not available");
|
|
88
|
+
}
|
|
89
|
+
const routeResolver = versionedRouteResolverContext.atVersion(1);
|
|
90
|
+
if (!routeResolver) {
|
|
91
|
+
throw new Error("RoutingContext v1 not available");
|
|
92
|
+
}
|
|
93
|
+
const appFallbackApis = useMemo(
|
|
94
|
+
() => new ForwardsCompatApis(app, routeResolver),
|
|
95
|
+
[app, routeResolver]
|
|
96
|
+
);
|
|
97
|
+
return /* @__PURE__ */ React.createElement(ApiProvider, { apis: appFallbackApis }, props.children);
|
|
98
|
+
}
|
|
3
99
|
function ForwardsCompatProvider(props) {
|
|
4
|
-
return /* @__PURE__ */ React.createElement(
|
|
100
|
+
return /* @__PURE__ */ React.createElement(NewAppApisProvider, null, props.children);
|
|
5
101
|
}
|
|
6
102
|
|
|
7
103
|
export { ForwardsCompatProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForwardsCompatProvider.esm.js","sources":["../../src/compatWrapper/ForwardsCompatProvider.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport { ReactNode } from 'react';\n\
|
|
1
|
+
{"version":3,"file":"ForwardsCompatProvider.esm.js","sources":["../../src/compatWrapper/ForwardsCompatProvider.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ApiHolder,\n ApiRef,\n AppContext,\n useApp,\n} from '@backstage/core-plugin-api';\nimport {\n AnyRouteRefParams,\n ComponentRef,\n ComponentsApi,\n CoreErrorBoundaryFallbackProps,\n CoreNotFoundErrorPageProps,\n CoreProgressProps,\n ExternalRouteRef,\n IconComponent,\n IconsApi,\n RouteFunc,\n RouteRef,\n RouteResolutionApi,\n RouteResolutionApiResolveOptions,\n SubRouteRef,\n componentsApiRef,\n coreComponentRefs,\n iconsApiRef,\n routeResolutionApiRef,\n} from '@backstage/frontend-plugin-api';\nimport React, { ComponentType, useMemo } from 'react';\nimport { ReactNode } from 'react';\nimport { toLegacyPlugin } from './BackwardsCompatProvider';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { ApiProvider } from '../../../core-app-api/src/apis/system/ApiProvider';\nimport { useVersionedContext } from '@backstage/version-bridge';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { type RouteResolver } from '../../../core-plugin-api/src/routing/useRouteRef';\nimport { convertLegacyRouteRef } from '../convertLegacyRouteRef';\n\nclass CompatComponentsApi implements ComponentsApi {\n readonly #Progress: ComponentType<CoreProgressProps>;\n readonly #NotFoundErrorPage: ComponentType<CoreNotFoundErrorPageProps>;\n readonly #ErrorBoundaryFallback: ComponentType<CoreErrorBoundaryFallbackProps>;\n\n constructor(app: AppContext) {\n const components = app.getComponents();\n const ErrorBoundaryFallback = (props: CoreErrorBoundaryFallbackProps) => (\n <components.ErrorBoundaryFallback\n {...props}\n plugin={props.plugin && toLegacyPlugin(props.plugin)}\n />\n );\n this.#Progress = components.Progress;\n this.#NotFoundErrorPage = components.NotFoundErrorPage;\n this.#ErrorBoundaryFallback = ErrorBoundaryFallback;\n }\n\n getComponent<T extends {}>(ref: ComponentRef<T>): ComponentType<T> {\n switch (ref.id) {\n case coreComponentRefs.progress.id:\n return this.#Progress as ComponentType<any>;\n case coreComponentRefs.notFoundErrorPage.id:\n return this.#NotFoundErrorPage as ComponentType<any>;\n case coreComponentRefs.errorBoundaryFallback.id:\n return this.#ErrorBoundaryFallback as ComponentType<any>;\n default:\n throw new Error(\n `No backwards compatible component is available for ref '${ref.id}'`,\n );\n }\n }\n}\n\nclass CompatIconsApi implements IconsApi {\n readonly #app: AppContext;\n\n constructor(app: AppContext) {\n this.#app = app;\n }\n\n getIcon(key: string): IconComponent | undefined {\n return this.#app.getSystemIcon(key);\n }\n\n listIconKeys(): string[] {\n return Object.keys(this.#app.getSystemIcons());\n }\n}\n\nclass CompatRouteResolutionApi implements RouteResolutionApi {\n readonly #routeResolver: RouteResolver;\n\n constructor(routeResolver: RouteResolver) {\n this.#routeResolver = routeResolver;\n }\n\n resolve<TParams extends AnyRouteRefParams>(\n anyRouteRef:\n | RouteRef<TParams>\n | SubRouteRef<TParams>\n | ExternalRouteRef<TParams>,\n options?: RouteResolutionApiResolveOptions | undefined,\n ): RouteFunc<TParams> | undefined {\n const legacyRef = convertLegacyRouteRef(anyRouteRef as RouteRef<TParams>);\n return this.#routeResolver.resolve(legacyRef, options?.sourcePath ?? '/');\n }\n}\n\nclass ForwardsCompatApis implements ApiHolder {\n readonly #componentsApi: ComponentsApi;\n readonly #iconsApi: IconsApi;\n readonly #routeResolutionApi: RouteResolutionApi;\n\n constructor(app: AppContext, routeResolver: RouteResolver) {\n this.#componentsApi = new CompatComponentsApi(app);\n this.#iconsApi = new CompatIconsApi(app);\n this.#routeResolutionApi = new CompatRouteResolutionApi(routeResolver);\n }\n\n get<T>(ref: ApiRef<any>): T | undefined {\n if (ref.id === componentsApiRef.id) {\n return this.#componentsApi as T;\n } else if (ref.id === iconsApiRef.id) {\n return this.#iconsApi as T;\n } else if (ref.id === routeResolutionApiRef.id) {\n return this.#routeResolutionApi as T;\n }\n return undefined;\n }\n}\n\nfunction NewAppApisProvider(props: { children: ReactNode }) {\n const app = useApp();\n const versionedRouteResolverContext = useVersionedContext<{\n 1: RouteResolver;\n }>('routing-context');\n if (!versionedRouteResolverContext) {\n throw new Error('Routing context is not available');\n }\n const routeResolver = versionedRouteResolverContext.atVersion(1);\n if (!routeResolver) {\n throw new Error('RoutingContext v1 not available');\n }\n\n const appFallbackApis = useMemo(\n () => new ForwardsCompatApis(app, routeResolver),\n [app, routeResolver],\n );\n\n return <ApiProvider apis={appFallbackApis}>{props.children}</ApiProvider>;\n}\n\nexport function ForwardsCompatProvider(props: { children: ReactNode }) {\n return <NewAppApisProvider>{props.children}</NewAppApisProvider>;\n}\n"],"names":[],"mappings":";;;;;;;;AAoDA,MAAM,mBAA6C,CAAA;AAAA,EACxC,SAAA,CAAA;AAAA,EACA,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,qBAAA,CAAsB,EAAI,EAAA;AAC9C,MAAA,OAAO,IAAK,CAAA,mBAAA,CAAA;AAAA,KACd;AACA,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACF,CAAA;AAEA,SAAS,mBAAmB,KAAgC,EAAA;AAC1D,EAAA,MAAM,MAAM,MAAO,EAAA,CAAA;AACnB,EAAM,MAAA,6BAAA,GAAgC,oBAEnC,iBAAiB,CAAA,CAAA;AACpB,EAAA,IAAI,CAAC,6BAA+B,EAAA;AAClC,IAAM,MAAA,IAAI,MAAM,kCAAkC,CAAA,CAAA;AAAA,GACpD;AACA,EAAM,MAAA,aAAA,GAAgB,6BAA8B,CAAA,SAAA,CAAU,CAAC,CAAA,CAAA;AAC/D,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA,CAAA;AAAA,GACnD;AAEA,EAAA,MAAM,eAAkB,GAAA,OAAA;AAAA,IACtB,MAAM,IAAI,kBAAmB,CAAA,GAAA,EAAK,aAAa,CAAA;AAAA,IAC/C,CAAC,KAAK,aAAa,CAAA;AAAA,GACrB,CAAA;AAEA,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,WAAA,EAAA,EAAY,IAAM,EAAA,eAAA,EAAA,EAAkB,MAAM,QAAS,CAAA,CAAA;AAC7D,CAAA;AAEO,SAAS,uBAAuB,KAAgC,EAAA;AACrE,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,kBAAoB,EAAA,IAAA,EAAA,KAAA,CAAM,QAAS,CAAA,CAAA;AAC7C;;;;"}
|
|
@@ -13,10 +13,49 @@ function convertLegacyRouteRefs(refs) {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
function convertLegacyRouteRef(ref) {
|
|
16
|
-
|
|
16
|
+
const isNew = "$$type" in ref;
|
|
17
|
+
const oldType = ref[routeRefType];
|
|
18
|
+
if (isNew && oldType) {
|
|
17
19
|
return ref;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
if (isNew) {
|
|
22
|
+
return convertNewToOld(
|
|
23
|
+
ref
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return convertOldToNew(ref, oldType);
|
|
27
|
+
}
|
|
28
|
+
function convertNewToOld(ref) {
|
|
29
|
+
if (ref.$$type === "@backstage/RouteRef") {
|
|
30
|
+
const newRef = toInternalRouteRef(ref);
|
|
31
|
+
return Object.assign(ref, {
|
|
32
|
+
[routeRefType]: "absolute",
|
|
33
|
+
params: newRef.getParams(),
|
|
34
|
+
title: newRef.getDescription()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (ref.$$type === "@backstage/SubRouteRef") {
|
|
38
|
+
const newRef = toInternalSubRouteRef(ref);
|
|
39
|
+
return Object.assign(ref, {
|
|
40
|
+
[routeRefType]: "sub",
|
|
41
|
+
parent: convertLegacyRouteRef(newRef.getParent()),
|
|
42
|
+
params: newRef.getParams()
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (ref.$$type === "@backstage/ExternalRouteRef") {
|
|
46
|
+
const newRef = toInternalExternalRouteRef(ref);
|
|
47
|
+
return Object.assign(ref, {
|
|
48
|
+
[routeRefType]: "external",
|
|
49
|
+
optional: true,
|
|
50
|
+
params: newRef.getParams(),
|
|
51
|
+
defaultTarget: newRef.getDefaultTarget()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Failed to convert route ref, unknown type '${ref.$$type}'`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function convertOldToNew(ref, type) {
|
|
20
59
|
if (type === "absolute") {
|
|
21
60
|
const legacyRef = ref;
|
|
22
61
|
const legacyRefStr = String(legacyRef);
|
|
@@ -76,7 +115,6 @@ function convertLegacyRouteRef(ref) {
|
|
|
76
115
|
const newRef = toInternalExternalRouteRef(
|
|
77
116
|
createExternalRouteRef({
|
|
78
117
|
params: legacyRef.params,
|
|
79
|
-
optional: legacyRef.optional,
|
|
80
118
|
defaultTarget: "getDefaultTarget" in legacyRef ? legacyRef.getDefaultTarget() : void 0
|
|
81
119
|
})
|
|
82
120
|
);
|
|
@@ -84,7 +122,6 @@ function convertLegacyRouteRef(ref) {
|
|
|
84
122
|
$$type: "@backstage/ExternalRouteRef",
|
|
85
123
|
version: "v1",
|
|
86
124
|
T: newRef.T,
|
|
87
|
-
optional: newRef.optional,
|
|
88
125
|
getParams() {
|
|
89
126
|
return newRef.getParams();
|
|
90
127
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertLegacyRouteRef.esm.js","sources":["../src/convertLegacyRouteRef.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n RouteRef as LegacyRouteRef,\n SubRouteRef as LegacySubRouteRef,\n ExternalRouteRef as LegacyExternalRouteRef,\n AnyRouteRefParams,\n} from '@backstage/core-plugin-api';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routeRefType } from '../../core-plugin-api/src/routing/types';\n\nimport {\n RouteRef,\n SubRouteRef,\n ExternalRouteRef,\n createRouteRef,\n createSubRouteRef,\n createExternalRouteRef,\n} from '@backstage/frontend-plugin-api';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalRouteRef } from '../../frontend-plugin-api/src/routing/RouteRef';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalSubRouteRef } from '../../frontend-plugin-api/src/routing/SubRouteRef';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExternalRouteRef } from '../../frontend-plugin-api/src/routing/ExternalRouteRef';\n\n/**\n * Converts a legacy route ref type to the new system.\n *\n * @public\n */\nexport type ToNewRouteRef<\n T extends LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef,\n> = T extends LegacyRouteRef<infer IParams>\n ? RouteRef<IParams>\n : T extends LegacySubRouteRef<infer IParams>\n ? SubRouteRef<IParams>\n : T extends LegacyExternalRouteRef<infer IParams, infer IOptional>\n ? ExternalRouteRef<IParams, IOptional>\n : never;\n\n/**\n * Converts a collection of legacy route refs to the new system.\n * This is particularly useful when defining plugin `routes` and `externalRoutes`.\n *\n * @public\n */\nexport function convertLegacyRouteRefs<\n TRefs extends {\n [name in string]:\n | LegacyRouteRef\n | LegacySubRouteRef\n | LegacyExternalRouteRef;\n },\n>(refs: TRefs): { [KName in keyof TRefs]: ToNewRouteRef<TRefs[KName]> } {\n return Object.fromEntries(\n Object.entries(refs).map(([name, ref]) => [\n name,\n convertLegacyRouteRef(ref as LegacyRouteRef),\n ]),\n ) as { [KName in keyof TRefs]: ToNewRouteRef<TRefs[KName]> };\n}\n\n/**\n * A temporary helper to convert a legacy route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: LegacyRouteRef<TParams>,\n): RouteRef<TParams>;\n\n/**\n * A temporary helper to convert a legacy sub route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createSubRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: LegacySubRouteRef<TParams>,\n): SubRouteRef<TParams>;\n\n/**\n * A temporary helper to convert a legacy external route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createExternalRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<\n TParams extends AnyRouteRefParams,\n TOptional extends boolean,\n>(\n ref: LegacyExternalRouteRef<TParams, TOptional>,\n): ExternalRouteRef<TParams, TOptional>;\n\nexport function convertLegacyRouteRef(\n ref: LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef,\n): RouteRef | SubRouteRef | ExternalRouteRef {\n // Ref has already been converted\n if ('$$type' in ref) {\n return ref as unknown as RouteRef | SubRouteRef | ExternalRouteRef;\n }\n\n const type = (ref as unknown as { [routeRefType]: unknown })[routeRefType];\n\n if (type === 'absolute') {\n const legacyRef = ref as LegacyRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalRouteRef(\n createRouteRef<{ [key in string]: string }>({\n params: legacyRef.params as string[],\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/RouteRef' as const,\n version: 'v1',\n T: newRef.T,\n getParams() {\n return newRef.getParams();\n },\n getDescription() {\n return legacyRefStr;\n },\n setId(id: string) {\n newRef.setId(id);\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n if (type === 'sub') {\n const legacyRef = ref as LegacySubRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalSubRouteRef(\n createSubRouteRef({\n path: legacyRef.path,\n parent: convertLegacyRouteRef(legacyRef.parent),\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/SubRouteRef' as const,\n version: 'v1',\n T: newRef.T,\n getParams() {\n return newRef.getParams();\n },\n getParent() {\n return newRef.getParent();\n },\n getDescription() {\n return legacyRefStr;\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n if (type === 'external') {\n const legacyRef = ref as LegacyExternalRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalExternalRouteRef(\n createExternalRouteRef<{ [key in string]: string }>({\n params: legacyRef.params as string[],\n optional: legacyRef.optional,\n defaultTarget:\n 'getDefaultTarget' in legacyRef\n ? (legacyRef.getDefaultTarget as () => string | undefined)()\n : undefined,\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/ExternalRouteRef' as const,\n version: 'v1',\n T: newRef.T,\n optional: newRef.optional,\n getParams() {\n return newRef.getParams();\n },\n getDescription() {\n return legacyRefStr;\n },\n // This might already be implemented in the legacy ref, but we override it just to be sure\n getDefaultTarget() {\n return newRef.getDefaultTarget();\n },\n setId(id: string) {\n newRef.setId(id);\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n\n throw new Error(`Failed to convert legacy route ref, unknown type '${type}'`);\n}\n"],"names":[],"mappings":";;;;;;AA+DO,SAAS,uBAOd,IAAsE,EAAA;AACtE,EAAA,OAAO,MAAO,CAAA,WAAA;AAAA,IACZ,MAAA,CAAO,QAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAM,EAAA,GAAG,CAAM,KAAA;AAAA,MACxC,IAAA;AAAA,MACA,sBAAsB,GAAqB,CAAA;AAAA,KAC5C,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AAyCO,SAAS,sBACd,GAC2C,EAAA;AAE3C,EAAA,IAAI,YAAY,GAAK,EAAA;AACnB,IAAO,OAAA,GAAA,CAAA;AAAA,GACT;AAEA,EAAM,MAAA,IAAA,GAAQ,IAA+C,YAAY,CAAA,CAAA;AAEzE,EAAA,IAAI,SAAS,UAAY,EAAA;AACvB,IAAA,MAAM,SAAY,GAAA,GAAA,CAAA;AAClB,IAAM,MAAA,YAAA,GAAe,OAAO,SAAS,CAAA,CAAA;AACrC,IAAA,MAAM,MAAS,GAAA,kBAAA;AAAA,MACb,cAA4C,CAAA;AAAA,QAC1C,QAAQ,SAAU,CAAA,MAAA;AAAA,OACnB,CAAA;AAAA,KACH,CAAA;AACA,IAAO,OAAA,MAAA,CAAO,OAAO,SAAW,EAAA;AAAA,MAC9B,MAAQ,EAAA,qBAAA;AAAA,MACR,OAAS,EAAA,IAAA;AAAA,MACT,GAAG,MAAO,CAAA,CAAA;AAAA,MACV,SAAY,GAAA;AACV,QAAA,OAAO,OAAO,SAAU,EAAA,CAAA;AAAA,OAC1B;AAAA,MACA,cAAiB,GAAA;AACf,QAAO,OAAA,YAAA,CAAA;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,SAAU,CAAA,QAAA;AAAA,QACpB,aACE,EAAA,kBAAA,IAAsB,SACjB,GAAA,SAAA,CAAU,kBACX,GAAA,KAAA,CAAA;AAAA,OACP,CAAA;AAAA,KACH,CAAA;AACA,IAAO,OAAA,MAAA,CAAO,OAAO,SAAW,EAAA;AAAA,MAC9B,MAAQ,EAAA,6BAAA;AAAA,MACR,OAAS,EAAA,IAAA;AAAA,MACT,GAAG,MAAO,CAAA,CAAA;AAAA,MACV,UAAU,MAAO,CAAA,QAAA;AAAA,MACjB,SAAY,GAAA;AACV,QAAA,OAAO,OAAO,SAAU,EAAA,CAAA;AAAA,OAC1B;AAAA,MACA,cAAiB,GAAA;AACf,QAAO,OAAA,YAAA,CAAA;AAAA,OACT;AAAA;AAAA,MAEA,gBAAmB,GAAA;AACjB,QAAA,OAAO,OAAO,gBAAiB,EAAA,CAAA;AAAA,OACjC;AAAA,MACA,MAAM,EAAY,EAAA;AAChB,QAAA,MAAA,CAAO,MAAM,EAAE,CAAA,CAAA;AAAA,OACjB;AAAA,MACA,QAAW,GAAA;AACT,QAAO,OAAA,YAAA,CAAA;AAAA,OACT;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAqD,kDAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA,CAAA;AAC9E;;;;"}
|
|
1
|
+
{"version":3,"file":"convertLegacyRouteRef.esm.js","sources":["../src/convertLegacyRouteRef.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n RouteRef as LegacyRouteRef,\n SubRouteRef as LegacySubRouteRef,\n ExternalRouteRef as LegacyExternalRouteRef,\n AnyRouteRefParams,\n} from '@backstage/core-plugin-api';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routeRefType } from '../../core-plugin-api/src/routing/types';\n\nimport {\n RouteRef,\n SubRouteRef,\n ExternalRouteRef,\n createRouteRef,\n createSubRouteRef,\n createExternalRouteRef,\n} from '@backstage/frontend-plugin-api';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalRouteRef } from '../../frontend-plugin-api/src/routing/RouteRef';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalSubRouteRef } from '../../frontend-plugin-api/src/routing/SubRouteRef';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExternalRouteRef } from '../../frontend-plugin-api/src/routing/ExternalRouteRef';\n\n/**\n * Converts a legacy route ref type to the new system.\n *\n * @public\n */\nexport type ToNewRouteRef<\n T extends LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef,\n> = T extends LegacyRouteRef<infer IParams>\n ? RouteRef<IParams>\n : T extends LegacySubRouteRef<infer IParams>\n ? SubRouteRef<IParams>\n : T extends LegacyExternalRouteRef<infer IParams>\n ? ExternalRouteRef<IParams>\n : never;\n\n/**\n * Converts a collection of legacy route refs to the new system.\n * This is particularly useful when defining plugin `routes` and `externalRoutes`.\n *\n * @public\n */\nexport function convertLegacyRouteRefs<\n TRefs extends {\n [name in string]:\n | LegacyRouteRef\n | LegacySubRouteRef\n | LegacyExternalRouteRef;\n },\n>(refs: TRefs): { [KName in keyof TRefs]: ToNewRouteRef<TRefs[KName]> } {\n return Object.fromEntries(\n Object.entries(refs).map(([name, ref]) => [\n name,\n convertLegacyRouteRef(ref as LegacyRouteRef),\n ]),\n ) as { [KName in keyof TRefs]: ToNewRouteRef<TRefs[KName]> };\n}\n\n/**\n * A temporary helper to convert a legacy route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: LegacyRouteRef<TParams>,\n): RouteRef<TParams>;\n\n/**\n * A temporary helper to convert a legacy sub route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createSubRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: LegacySubRouteRef<TParams>,\n): SubRouteRef<TParams>;\n\n/**\n * A temporary helper to convert a legacy external route ref to the new system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createExternalRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: LegacyExternalRouteRef<TParams>,\n): ExternalRouteRef<TParams>;\n\n/**\n * A temporary helper to convert a new route ref to the legacy system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: RouteRef<TParams>,\n): LegacyRouteRef<TParams>;\n\n/**\n * A temporary helper to convert a new sub route ref to the legacy system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createSubRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: SubRouteRef<TParams>,\n): LegacySubRouteRef<TParams>;\n\n/**\n * A temporary helper to convert a new external route ref to the legacy system.\n *\n * @public\n * @remarks\n *\n * In the future the legacy createExternalRouteRef will instead create refs compatible with both systems.\n */\nexport function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(\n ref: ExternalRouteRef<TParams>,\n): LegacyExternalRouteRef<TParams, true>;\nexport function convertLegacyRouteRef(\n ref:\n | LegacyRouteRef\n | LegacySubRouteRef\n | LegacyExternalRouteRef\n | RouteRef\n | SubRouteRef\n | ExternalRouteRef,\n):\n | RouteRef\n | SubRouteRef\n | ExternalRouteRef\n | LegacyRouteRef\n | LegacySubRouteRef\n | LegacyExternalRouteRef {\n const isNew = '$$type' in ref;\n const oldType = (ref as unknown as { [routeRefType]: unknown })[routeRefType];\n\n // Ref has already been converted\n if (isNew && oldType) {\n return ref as any;\n }\n\n if (isNew) {\n return convertNewToOld(\n ref as unknown as RouteRef | SubRouteRef | ExternalRouteRef,\n );\n }\n\n return convertOldToNew(ref, oldType);\n}\n\nfunction convertNewToOld(\n ref: RouteRef | SubRouteRef | ExternalRouteRef,\n): LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef {\n if (ref.$$type === '@backstage/RouteRef') {\n const newRef = toInternalRouteRef(ref);\n return Object.assign(ref, {\n [routeRefType]: 'absolute',\n params: newRef.getParams(),\n title: newRef.getDescription(),\n } as Omit<LegacyRouteRef, '$$routeRefType'>) as unknown as LegacyRouteRef;\n }\n if (ref.$$type === '@backstage/SubRouteRef') {\n const newRef = toInternalSubRouteRef(ref);\n return Object.assign(ref, {\n [routeRefType]: 'sub',\n parent: convertLegacyRouteRef(newRef.getParent()),\n params: newRef.getParams(),\n } as Omit<LegacySubRouteRef, '$$routeRefType' | 'path'>) as unknown as LegacySubRouteRef;\n }\n if (ref.$$type === '@backstage/ExternalRouteRef') {\n const newRef = toInternalExternalRouteRef(ref);\n return Object.assign(ref, {\n [routeRefType]: 'external',\n optional: true,\n params: newRef.getParams(),\n defaultTarget: newRef.getDefaultTarget(),\n } as Omit<LegacyExternalRouteRef, '$$routeRefType' | 'optional'>) as unknown as LegacyExternalRouteRef;\n }\n\n throw new Error(\n `Failed to convert route ref, unknown type '${(ref as any).$$type}'`,\n );\n}\n\nfunction convertOldToNew(\n ref: LegacyRouteRef | LegacySubRouteRef | LegacyExternalRouteRef,\n type: unknown,\n): RouteRef | SubRouteRef | ExternalRouteRef {\n if (type === 'absolute') {\n const legacyRef = ref as LegacyRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalRouteRef(\n createRouteRef<{ [key in string]: string }>({\n params: legacyRef.params as string[],\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/RouteRef' as const,\n version: 'v1',\n T: newRef.T,\n getParams() {\n return newRef.getParams();\n },\n getDescription() {\n return legacyRefStr;\n },\n setId(id: string) {\n newRef.setId(id);\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n if (type === 'sub') {\n const legacyRef = ref as LegacySubRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalSubRouteRef(\n createSubRouteRef({\n path: legacyRef.path,\n parent: convertLegacyRouteRef(legacyRef.parent),\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/SubRouteRef' as const,\n version: 'v1',\n T: newRef.T,\n getParams() {\n return newRef.getParams();\n },\n getParent() {\n return newRef.getParent();\n },\n getDescription() {\n return legacyRefStr;\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n if (type === 'external') {\n const legacyRef = ref as LegacyExternalRouteRef;\n const legacyRefStr = String(legacyRef);\n const newRef = toInternalExternalRouteRef(\n createExternalRouteRef<{ [key in string]: string }>({\n params: legacyRef.params as string[],\n defaultTarget:\n 'getDefaultTarget' in legacyRef\n ? (legacyRef.getDefaultTarget as () => string | undefined)()\n : undefined,\n }),\n );\n return Object.assign(legacyRef, {\n $$type: '@backstage/ExternalRouteRef' as const,\n version: 'v1',\n T: newRef.T,\n getParams() {\n return newRef.getParams();\n },\n getDescription() {\n return legacyRefStr;\n },\n // This might already be implemented in the legacy ref, but we override it just to be sure\n getDefaultTarget() {\n return newRef.getDefaultTarget();\n },\n setId(id: string) {\n newRef.setId(id);\n },\n toString() {\n return legacyRefStr;\n },\n });\n }\n\n throw new Error(`Failed to convert legacy route ref, unknown type '${type}'`);\n}\n"],"names":[],"mappings":";;;;;;AA+DO,SAAS,uBAOd,IAAsE,EAAA;AACtE,EAAA,OAAO,MAAO,CAAA,WAAA;AAAA,IACZ,MAAA,CAAO,QAAQ,IAAI,CAAA,CAAE,IAAI,CAAC,CAAC,IAAM,EAAA,GAAG,CAAM,KAAA;AA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ACV,SAAY,GAAA;AACV,QAAA,OAAO,OAAO,SAAU,EAAA,CAAA;AAAA,OAC1B;AAAA,MACA,cAAiB,GAAA;AACf,QAAO,OAAA,YAAA,CAAA;AAAA,OACT;AAAA;AAAA,MAEA,gBAAmB,GAAA;AACjB,QAAA,OAAO,OAAO,gBAAiB,EAAA,CAAA;AAAA,OACjC;AAAA,MACA,MAAM,EAAY,EAAA;AAChB,QAAA,MAAA,CAAO,MAAM,EAAE,CAAA,CAAA;AAAA,OACjB;AAAA,MACA,QAAW,GAAA;AACT,QAAO,OAAA,YAAA,CAAA;AAAA,OACT;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAqD,kDAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA,CAAA;AAC9E;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class ApiAggregator {
|
|
2
|
+
holders;
|
|
3
|
+
constructor(...holders) {
|
|
4
|
+
this.holders = holders;
|
|
5
|
+
}
|
|
6
|
+
get(apiRef) {
|
|
7
|
+
for (const holder of this.holders) {
|
|
8
|
+
const api = holder.get(apiRef);
|
|
9
|
+
if (api) {
|
|
10
|
+
return api;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ApiAggregator };
|
|
18
|
+
//# sourceMappingURL=ApiAggregator.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiAggregator.esm.js","sources":["../../../../../../core-app-api/src/apis/system/ApiAggregator.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ApiRef, ApiHolder } from '@backstage/core-plugin-api';\n\n/**\n * An ApiHolder that queries multiple other holders from for\n * an Api implementation, returning the first one encountered..\n */\nexport class ApiAggregator implements ApiHolder {\n private readonly holders: ApiHolder[];\n\n constructor(...holders: ApiHolder[]) {\n this.holders = holders;\n }\n\n get<T>(apiRef: ApiRef<T>): T | undefined {\n for (const holder of this.holders) {\n const api = holder.get(apiRef);\n if (api) {\n return api;\n }\n }\n return undefined;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,aAAmC,CAAA;AAAA,EAC7B,OAAA,CAAA;AAAA,EAEjB,eAAe,OAAsB,EAAA;AACnC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AAAA,GACjB;AAAA,EAEA,IAAO,MAAkC,EAAA;AACvC,IAAW,KAAA,MAAA,MAAA,IAAU,KAAK,OAAS,EAAA;AACjC,MAAM,MAAA,GAAA,GAAM,MAAO,CAAA,GAAA,CAAI,MAAM,CAAA,CAAA;AAC7B,MAAA,IAAI,GAAK,EAAA;AACP,QAAO,OAAA,GAAA,CAAA;AAAA,OACT;AAAA,KACF;AACA,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AACF;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { ApiAggregator } from './ApiAggregator.esm.js';
|
|
4
|
+
import { createVersionedContext, createVersionedValueMap } from '@backstage/version-bridge';
|
|
5
|
+
|
|
6
|
+
const ApiContext = createVersionedContext("api-context");
|
|
7
|
+
const ApiProvider = (props) => {
|
|
8
|
+
const { apis, children } = props;
|
|
9
|
+
const parentHolder = useContext(ApiContext)?.atVersion(1);
|
|
10
|
+
const holder = parentHolder ? new ApiAggregator(apis, parentHolder) : apis;
|
|
11
|
+
return /* @__PURE__ */ React.createElement(
|
|
12
|
+
ApiContext.Provider,
|
|
13
|
+
{
|
|
14
|
+
value: createVersionedValueMap({ 1: holder }),
|
|
15
|
+
children
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
ApiProvider.propTypes = {
|
|
20
|
+
apis: PropTypes.shape({ get: PropTypes.func.isRequired }).isRequired,
|
|
21
|
+
children: PropTypes.node
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { ApiProvider };
|
|
25
|
+
//# sourceMappingURL=ApiProvider.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiProvider.esm.js","sources":["../../../../../../core-app-api/src/apis/system/ApiProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useContext, ReactNode, PropsWithChildren } from 'react';\nimport PropTypes from 'prop-types';\nimport { ApiHolder } from '@backstage/core-plugin-api';\nimport { ApiAggregator } from './ApiAggregator';\nimport {\n createVersionedValueMap,\n createVersionedContext,\n} from '@backstage/version-bridge';\n\n/**\n * Prop types for the ApiProvider component.\n * @public\n */\nexport type ApiProviderProps = {\n apis: ApiHolder;\n children: ReactNode;\n};\n\nconst ApiContext = createVersionedContext<{ 1: ApiHolder }>('api-context');\n\n/**\n * Provides an {@link @backstage/core-plugin-api#ApiHolder} for consumption in\n * the React tree.\n *\n * @public\n */\nexport const ApiProvider = (props: PropsWithChildren<ApiProviderProps>) => {\n const { apis, children } = props;\n const parentHolder = useContext(ApiContext)?.atVersion(1);\n const holder = parentHolder ? new ApiAggregator(apis, parentHolder) : apis;\n\n return (\n <ApiContext.Provider\n value={createVersionedValueMap({ 1: holder })}\n children={children}\n />\n );\n};\n\nApiProvider.propTypes = {\n apis: PropTypes.shape({ get: PropTypes.func.isRequired }).isRequired,\n children: PropTypes.node,\n};\n"],"names":[],"mappings":";;;;;AAkCA,MAAM,UAAA,GAAa,uBAAyC,aAAa,CAAA,CAAA;AAQ5D,MAAA,WAAA,GAAc,CAAC,KAA+C,KAAA;AACzE,EAAM,MAAA,EAAE,IAAM,EAAA,QAAA,EAAa,GAAA,KAAA,CAAA;AAC3B,EAAA,MAAM,YAAe,GAAA,UAAA,CAAW,UAAU,CAAA,EAAG,UAAU,CAAC,CAAA,CAAA;AACxD,EAAA,MAAM,SAAS,YAAe,GAAA,IAAI,aAAc,CAAA,IAAA,EAAM,YAAY,CAAI,GAAA,IAAA,CAAA;AAEtE,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,UAAW,CAAA,QAAA;AAAA,IAAX;AAAA,MACC,KAAO,EAAA,uBAAA,CAAwB,EAAE,CAAA,EAAG,QAAQ,CAAA;AAAA,MAC5C,QAAA;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ,EAAA;AAEA,WAAA,CAAY,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,UAAU,KAAM,CAAA,EAAE,KAAK,SAAU,CAAA,IAAA,CAAK,UAAW,EAAC,CAAE,CAAA,UAAA;AAAA,EAC1D,UAAU,SAAU,CAAA,IAAA;AACtB,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalRouteRef.esm.js","sources":["../../../../../frontend-plugin-api/src/routing/ExternalRouteRef.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RouteRefImpl } from './RouteRef';\nimport { describeParentCallSite } from './describeParentCallSite';\nimport { AnyRouteRefParams } from './types';\n\n/**\n * Route descriptor, to be later bound to a concrete route by the app. Used to implement cross-plugin route references.\n *\n * @remarks\n *\n * See {@link https://backstage.io/docs/plugins/composability#routing-system}.\n *\n * @public\n */\nexport interface ExternalRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n
|
|
1
|
+
{"version":3,"file":"ExternalRouteRef.esm.js","sources":["../../../../../frontend-plugin-api/src/routing/ExternalRouteRef.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RouteRefImpl } from './RouteRef';\nimport { describeParentCallSite } from './describeParentCallSite';\nimport { AnyRouteRefParams } from './types';\n\n/**\n * Route descriptor, to be later bound to a concrete route by the app. Used to implement cross-plugin route references.\n *\n * @remarks\n *\n * See {@link https://backstage.io/docs/plugins/composability#routing-system}.\n *\n * @public\n */\nexport interface ExternalRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> {\n readonly $$type: '@backstage/ExternalRouteRef';\n readonly T: TParams;\n}\n\n/** @internal */\nexport interface InternalExternalRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n> extends ExternalRouteRef<TParams> {\n readonly version: 'v1';\n getParams(): string[];\n getDescription(): string;\n getDefaultTarget(): string | undefined;\n\n setId(id: string): void;\n}\n\n/** @internal */\nexport function toInternalExternalRouteRef<\n TParams extends AnyRouteRefParams = AnyRouteRefParams,\n>(resource: ExternalRouteRef<TParams>): InternalExternalRouteRef<TParams> {\n const r = resource as InternalExternalRouteRef<TParams>;\n if (r.$$type !== '@backstage/ExternalRouteRef') {\n throw new Error(`Invalid ExternalRouteRef, bad type '${r.$$type}'`);\n }\n\n return r;\n}\n\n/** @internal */\nexport function isExternalRouteRef(opaque: {\n $$type: string;\n}): opaque is ExternalRouteRef {\n return opaque.$$type === '@backstage/ExternalRouteRef';\n}\n\n/** @internal */\nclass ExternalRouteRefImpl\n extends RouteRefImpl\n implements InternalExternalRouteRef\n{\n readonly $$type = '@backstage/ExternalRouteRef' as any;\n\n constructor(\n readonly params: string[] = [],\n readonly defaultTarget: string | undefined,\n creationSite: string,\n ) {\n super(params, creationSite);\n }\n\n getDefaultTarget() {\n return this.defaultTarget;\n }\n}\n\n/**\n * Creates a route descriptor, to be later bound to a concrete route by the app. Used to implement cross-plugin route references.\n *\n * @remarks\n *\n * See {@link https://backstage.io/docs/plugins/composability#routing-system}.\n *\n * @param options - Description of the route reference to be created.\n * @public\n */\nexport function createExternalRouteRef<\n TParams extends { [param in TParamKeys]: string } | undefined = undefined,\n TParamKeys extends string = string,\n>(options?: {\n /**\n * The parameters that will be provided to the external route reference.\n */\n readonly params?: string extends TParamKeys\n ? (keyof TParams)[]\n : TParamKeys[];\n\n /**\n * The route (typically in another plugin) that this should map to by default.\n *\n * The string is expected to be on the standard `<plugin id>.<route id>` form,\n * for example `techdocs.docRoot`.\n */\n defaultTarget?: string;\n}): ExternalRouteRef<\n keyof TParams extends never\n ? undefined\n : string extends TParamKeys\n ? TParams\n : { [param in TParamKeys]: string }\n> {\n return new ExternalRouteRefImpl(\n options?.params as string[] | undefined,\n options?.defaultTarget,\n describeParentCallSite(),\n );\n}\n"],"names":[],"mappings":"AAiDO,SAAS,2BAEd,QAAwE,EAAA;AACxE,EAAA,MAAM,CAAI,GAAA,QAAA,CAAA;AACV,EAAI,IAAA,CAAA,CAAE,WAAW,6BAA+B,EAAA;AAC9C,IAAA,MAAM,IAAI,KAAA,CAAM,CAAuC,oCAAA,EAAA,CAAA,CAAE,MAAM,CAAG,CAAA,CAAA,CAAA,CAAA;AAAA,GACpE;AAEA,EAAO,OAAA,CAAA,CAAA;AACT;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ declare function convertLegacyApp(rootElement: React.JSX.Element): FrontendFeatu
|
|
|
71
71
|
*
|
|
72
72
|
* @public
|
|
73
73
|
*/
|
|
74
|
-
type ToNewRouteRef<T extends RouteRef | SubRouteRef | ExternalRouteRef> = T extends RouteRef<infer IParams> ? RouteRef$1<IParams> : T extends SubRouteRef<infer IParams> ? SubRouteRef$1<IParams> : T extends ExternalRouteRef<infer IParams
|
|
74
|
+
type ToNewRouteRef<T extends RouteRef | SubRouteRef | ExternalRouteRef> = T extends RouteRef<infer IParams> ? RouteRef$1<IParams> : T extends SubRouteRef<infer IParams> ? SubRouteRef$1<IParams> : T extends ExternalRouteRef<infer IParams> ? ExternalRouteRef$1<IParams> : never;
|
|
75
75
|
/**
|
|
76
76
|
* Converts a collection of legacy route refs to the new system.
|
|
77
77
|
* This is particularly useful when defining plugin `routes` and `externalRoutes`.
|
|
@@ -109,6 +109,33 @@ declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: S
|
|
|
109
109
|
*
|
|
110
110
|
* In the future the legacy createExternalRouteRef will instead create refs compatible with both systems.
|
|
111
111
|
*/
|
|
112
|
-
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams
|
|
112
|
+
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: ExternalRouteRef<TParams>): ExternalRouteRef$1<TParams>;
|
|
113
|
+
/**
|
|
114
|
+
* A temporary helper to convert a new route ref to the legacy system.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
* @remarks
|
|
118
|
+
*
|
|
119
|
+
* In the future the legacy createRouteRef will instead create refs compatible with both systems.
|
|
120
|
+
*/
|
|
121
|
+
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: RouteRef$1<TParams>): RouteRef<TParams>;
|
|
122
|
+
/**
|
|
123
|
+
* A temporary helper to convert a new sub route ref to the legacy system.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
* @remarks
|
|
127
|
+
*
|
|
128
|
+
* In the future the legacy createSubRouteRef will instead create refs compatible with both systems.
|
|
129
|
+
*/
|
|
130
|
+
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: SubRouteRef$1<TParams>): SubRouteRef<TParams>;
|
|
131
|
+
/**
|
|
132
|
+
* A temporary helper to convert a new external route ref to the legacy system.
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @remarks
|
|
136
|
+
*
|
|
137
|
+
* In the future the legacy createExternalRouteRef will instead create refs compatible with both systems.
|
|
138
|
+
*/
|
|
139
|
+
declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: ExternalRouteRef$1<TParams>): ExternalRouteRef<TParams, true>;
|
|
113
140
|
|
|
114
141
|
export { MultipleAnalyticsApi, NoOpAnalyticsApi, type ToNewRouteRef, compatWrapper, convertLegacyApp, convertLegacyRouteRef, convertLegacyRouteRefs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/core-compat-api",
|
|
3
|
-
"version": "0.2.8-next.
|
|
3
|
+
"version": "0.2.8-next.3",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -32,18 +32,19 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@backstage/core-plugin-api": "^1.9.3",
|
|
35
|
-
"@backstage/frontend-plugin-api": "^0.
|
|
35
|
+
"@backstage/frontend-plugin-api": "^0.7.0-next.3",
|
|
36
36
|
"@backstage/version-bridge": "^1.0.8",
|
|
37
37
|
"@types/react": "^16.13.1 || ^17.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@backstage-community/plugin-puppetdb": "^0.1.18",
|
|
41
41
|
"@backstage-community/plugin-stackstorm": "^0.1.16",
|
|
42
|
-
"@backstage/cli": "^0.27.0-next.
|
|
42
|
+
"@backstage/cli": "^0.27.0-next.4",
|
|
43
43
|
"@backstage/core-app-api": "^1.14.2-next.0",
|
|
44
|
-
"@backstage/frontend-app-api": "^0.7.5-next.
|
|
45
|
-
"@backstage/frontend-test-utils": "^0.1.12-next.
|
|
46
|
-
"@backstage/plugin-catalog": "^1.
|
|
44
|
+
"@backstage/frontend-app-api": "^0.7.5-next.3",
|
|
45
|
+
"@backstage/frontend-test-utils": "^0.1.12-next.3",
|
|
46
|
+
"@backstage/plugin-catalog": "^1.22.0-next.3",
|
|
47
|
+
"@backstage/test-utils": "^1.5.10-next.2",
|
|
47
48
|
"@oriflame/backstage-plugin-score-card": "^0.8.0",
|
|
48
49
|
"@testing-library/jest-dom": "^6.0.0",
|
|
49
50
|
"@testing-library/react": "^15.0.0"
|