@backstage/frontend-app-api 0.7.5-next.3 → 0.9.0-next.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/CHANGELOG.md +66 -0
- package/dist/core-app-api/src/apis/system/ApiRegistry.esm.js +50 -0
- package/dist/core-app-api/src/apis/system/ApiRegistry.esm.js.map +1 -0
- package/dist/extensions/Root.esm.js +19 -0
- package/dist/extensions/Root.esm.js.map +1 -0
- package/dist/frontend-plugin-api/src/wiring/createExtension.esm.js.map +1 -1
- package/dist/frontend-plugin-api/src/wiring/createExtensionOverrides.esm.js.map +1 -1
- package/dist/frontend-plugin-api/src/wiring/{createPlugin.esm.js → createFrontendPlugin.esm.js} +1 -1
- package/dist/frontend-plugin-api/src/wiring/createFrontendPlugin.esm.js.map +1 -0
- package/dist/frontend-plugin-api/src/wiring/resolveExtensionDefinition.esm.js.map +1 -1
- package/dist/index.d.ts +2 -10
- package/dist/tree/instantiateAppNodeTree.esm.js +8 -5
- package/dist/tree/instantiateAppNodeTree.esm.js.map +1 -1
- package/dist/tree/resolveAppNodeSpecs.esm.js +1 -1
- package/dist/tree/resolveAppNodeSpecs.esm.js.map +1 -1
- package/dist/tree/resolveAppTree.esm.js +40 -20
- package/dist/tree/resolveAppTree.esm.js.map +1 -1
- package/dist/wiring/createApp.esm.js +114 -165
- package/dist/wiring/createApp.esm.js.map +1 -1
- package/package.json +7 -6
- package/dist/apis/implementations/ComponentsApi/DefaultComponentsApi.esm.js +0 -30
- package/dist/apis/implementations/ComponentsApi/DefaultComponentsApi.esm.js.map +0 -1
- package/dist/apis/implementations/IconsApi/DefaultIconsApi.esm.js +0 -15
- package/dist/apis/implementations/IconsApi/DefaultIconsApi.esm.js.map +0 -1
- package/dist/app/src/components/Root/LogoFull.esm.js +0 -33
- package/dist/app/src/components/Root/LogoFull.esm.js.map +0 -1
- package/dist/app/src/components/Root/LogoIcon.esm.js +0 -33
- package/dist/app/src/components/Root/LogoIcon.esm.js.map +0 -1
- package/dist/app-defaults/src/defaults/apis.esm.js +0 -221
- package/dist/app-defaults/src/defaults/apis.esm.js.map +0 -1
- package/dist/app-defaults/src/defaults/components.esm.js +0 -46
- package/dist/app-defaults/src/defaults/components.esm.js.map +0 -1
- package/dist/app-defaults/src/defaults/icons.esm.js +0 -51
- package/dist/app-defaults/src/defaults/icons.esm.js.map +0 -1
- package/dist/core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js +0 -89
- package/dist/core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js.map +0 -1
- package/dist/core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js +0 -76
- package/dist/core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js.map +0 -1
- package/dist/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js +0 -234
- package/dist/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js.map +0 -1
- package/dist/core-app-api/src/app/AppThemeProvider.esm.js +0 -60
- package/dist/core-app-api/src/app/AppThemeProvider.esm.js.map +0 -1
- package/dist/core-app-api/src/app/isProtectedApp.esm.js +0 -8
- package/dist/core-app-api/src/app/isProtectedApp.esm.js.map +0 -1
- package/dist/core-app-api/src/lib/subjects.esm.js +0 -69
- package/dist/core-app-api/src/lib/subjects.esm.js.map +0 -1
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js +0 -13
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js.map +0 -1
- package/dist/core-plugin-api/src/translation/TranslationResource.esm.js +0 -13
- package/dist/core-plugin-api/src/translation/TranslationResource.esm.js.map +0 -1
- package/dist/extensions/App.esm.js +0 -42
- package/dist/extensions/App.esm.js.map +0 -1
- package/dist/extensions/AppLayout.esm.js +0 -34
- package/dist/extensions/AppLayout.esm.js.map +0 -1
- package/dist/extensions/AppNav.esm.js +0 -64
- package/dist/extensions/AppNav.esm.js.map +0 -1
- package/dist/extensions/AppRoot.esm.js +0 -124
- package/dist/extensions/AppRoot.esm.js.map +0 -1
- package/dist/extensions/AppRoutes.esm.js +0 -43
- package/dist/extensions/AppRoutes.esm.js.map +0 -1
- package/dist/extensions/components.esm.js +0 -52
- package/dist/extensions/components.esm.js.map +0 -1
- package/dist/extensions/elements.esm.js +0 -26
- package/dist/extensions/elements.esm.js.map +0 -1
- package/dist/extensions/themes.esm.js +0 -23
- package/dist/extensions/themes.esm.js.map +0 -1
- package/dist/frontend-plugin-api/src/wiring/createPlugin.esm.js.map +0 -1
- package/dist/routing/RouteTracker.esm.js +0 -69
- package/dist/routing/RouteTracker.esm.js.map +0 -1
- package/dist/tree/createAppTree.esm.js +0 -21
- package/dist/tree/createAppTree.esm.js.map +0 -1
- package/dist/wiring/InternalAppContext.esm.js +0 -6
- package/dist/wiring/InternalAppContext.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAppNodeSpecs.esm.js","sources":["../../src/tree/resolveAppNodeSpecs.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 BackstagePlugin,\n Extension,\n ExtensionOverrides,\n FrontendFeature,\n} from '@backstage/frontend-plugin-api';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExtensionOverrides } from '../../../frontend-plugin-api/src/wiring/createExtensionOverrides';\nimport { ExtensionParameters } from './readAppExtensionsConfig';\nimport { AppNodeSpec } from '@backstage/frontend-plugin-api';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalBackstagePlugin } from '../../../frontend-plugin-api/src/wiring/createPlugin';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExtension } from '../../../frontend-plugin-api/src/wiring/resolveExtensionDefinition';\n\n/** @internal */\nexport function resolveAppNodeSpecs(options: {\n features?: FrontendFeature[];\n builtinExtensions?: Extension<unknown>[];\n parameters?: Array<ExtensionParameters>;\n forbidden?: Set<string>;\n}): AppNodeSpec[] {\n const {\n builtinExtensions = [],\n parameters = [],\n forbidden = new Set(),\n features = [],\n } = options;\n\n const plugins = features.filter(\n (f): f is BackstagePlugin => f.$$type === '@backstage/BackstagePlugin',\n );\n const overrides = features.filter(\n (f): f is ExtensionOverrides =>\n f.$$type === '@backstage/ExtensionOverrides',\n );\n\n const pluginExtensions = plugins.flatMap(source => {\n return toInternalBackstagePlugin(source).extensions.map(extension => ({\n ...extension,\n source,\n }));\n });\n const overrideExtensions = overrides.flatMap(\n override => toInternalExtensionOverrides(override).extensions,\n );\n\n // Prevent core override\n if (pluginExtensions.some(({ id }) => forbidden.has(id))) {\n const pluginsStr = pluginExtensions\n .filter(({ id }) => forbidden.has(id))\n .map(({ source }) => `'${source.id}'`)\n .join(', ');\n const forbiddenStr = [...forbidden].map(id => `'${id}'`).join(', ');\n throw new Error(\n `It is forbidden to override the following extension(s): ${forbiddenStr}, which is done by the following plugin(s): ${pluginsStr}`,\n );\n }\n\n if (overrideExtensions.some(({ id }) => forbidden.has(id))) {\n const forbiddenStr = [...forbidden].map(id => `'${id}'`).join(', ');\n throw new Error(\n `It is forbidden to override the following extension(s): ${forbiddenStr}, which is done by one or more extension overrides`,\n );\n }\n const overrideExtensionIds = overrideExtensions.map(({ id }) => id);\n if (overrideExtensionIds.length !== new Set(overrideExtensionIds).size) {\n const counts = new Map<string, number>();\n for (const id of overrideExtensionIds) {\n counts.set(id, (counts.get(id) ?? 0) + 1);\n }\n const duplicated = Array.from(counts.entries())\n .filter(([, count]) => count > 1)\n .map(([id]) => id);\n throw new Error(\n `The following extensions had duplicate overrides: ${duplicated.join(\n ', ',\n )}`,\n );\n }\n\n const configuredExtensions = [\n ...pluginExtensions.map(({ source, ...extension }) => {\n const internalExtension = toInternalExtension(extension);\n return {\n extension: internalExtension,\n params: {\n source,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined as unknown,\n },\n };\n }),\n ...builtinExtensions.map(extension => {\n const internalExtension = toInternalExtension(extension);\n return {\n extension: internalExtension,\n params: {\n source: undefined,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined as unknown,\n },\n };\n }),\n ];\n\n // Install all extension overrides\n for (const extension of overrideExtensions) {\n const internalExtension = toInternalExtension(extension);\n\n // Check if our override is overriding an extension that already exists\n const index = configuredExtensions.findIndex(\n e => e.extension.id === extension.id,\n );\n if (index !== -1) {\n // Only implementation, attachment point and default disabled status are overridden, the source is kept\n configuredExtensions[index].extension = internalExtension;\n configuredExtensions[index].params.attachTo = internalExtension.attachTo;\n configuredExtensions[index].params.disabled = internalExtension.disabled;\n } else {\n // Add the extension as a new one when not overriding an existing one\n configuredExtensions.push({\n extension: internalExtension,\n params: {\n source: undefined,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined,\n },\n });\n }\n }\n\n const duplicatedExtensionIds = new Set<string>();\n const duplicatedExtensionData = configuredExtensions.reduce<\n Record<string, Record<string, number>>\n >((data, { extension, params }) => {\n const extensionId = extension.id;\n const extensionData = data?.[extensionId];\n if (extensionData) duplicatedExtensionIds.add(extensionId);\n const pluginId = params.source?.id ?? 'internal';\n const pluginCount = extensionData?.[pluginId] ?? 0;\n return {\n ...data,\n [extensionId]: { ...extensionData, [pluginId]: pluginCount + 1 },\n };\n }, {});\n\n if (duplicatedExtensionIds.size > 0) {\n throw new Error(\n `The following extensions are duplicated: ${Array.from(\n duplicatedExtensionIds,\n )\n .map(\n extensionId =>\n `The extension '${extensionId}' was provided ${Object.keys(\n duplicatedExtensionData[extensionId],\n )\n .map(\n pluginId =>\n `${duplicatedExtensionData[extensionId][pluginId]} time(s) by the plugin '${pluginId}'`,\n )\n .join(' and ')}`,\n )\n .join(', ')}`,\n );\n }\n\n const order = new Map<string, (typeof configuredExtensions)[number]>();\n for (const overrideParam of parameters) {\n const extensionId = overrideParam.id;\n\n if (forbidden.has(extensionId)) {\n throw new Error(\n `Configuration of the '${extensionId}' extension is forbidden`,\n );\n }\n\n const existing = configuredExtensions.find(\n e => e.extension.id === extensionId,\n );\n if (existing) {\n if (overrideParam.attachTo) {\n existing.params.attachTo = overrideParam.attachTo;\n }\n if (overrideParam.config) {\n // TODO: merge config?\n existing.params.config = overrideParam.config;\n }\n if (\n Boolean(existing.params.disabled) !== Boolean(overrideParam.disabled)\n ) {\n existing.params.disabled = Boolean(overrideParam.disabled);\n }\n order.set(extensionId, existing);\n } else {\n throw new Error(`Extension ${extensionId} does not exist`);\n }\n }\n\n const orderedExtensions = [\n ...order.values(),\n ...configuredExtensions.filter(e => !order.has(e.extension.id)),\n ];\n\n return orderedExtensions.map(param => ({\n id: param.extension.id,\n attachTo: param.params.attachTo,\n extension: param.extension,\n disabled: param.params.disabled,\n source: param.params.source,\n config: param.params.config,\n }));\n}\n"],"names":[],"mappings":";;;;AAgCO,SAAS,oBAAoB,OAKlB,EAAA;AAChB,EAAM,MAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,aAAa,EAAC;AAAA,IACd,SAAA,uBAAgB,GAAI,EAAA;AAAA,IACpB,WAAW,EAAC;AAAA,GACV,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,UAAU,QAAS,CAAA,MAAA;AAAA,IACvB,CAAC,CAA4B,KAAA,CAAA,CAAE,MAAW,KAAA,4BAAA;AAAA,GAC5C,CAAA;AACA,EAAA,MAAM,YAAY,QAAS,CAAA,MAAA;AAAA,IACzB,CAAC,CACC,KAAA,CAAA,CAAE,MAAW,KAAA,+BAAA;AAAA,GACjB,CAAA;AAEA,EAAM,MAAA,gBAAA,G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AAAA,KAC3D;AAAA,GACF;AAEA,EAAA,MAAM,iBAAoB,GAAA;AAAA,IACxB,GAAG,MAAM,MAAO,EAAA;AAAA,IAChB,GAAG,oBAAqB,CAAA,MAAA,CAAO,CAAK,CAAA,KAAA,CAAC,MAAM,GAAI,CAAA,CAAA,CAAE,SAAU,CAAA,EAAE,CAAC,CAAA;AAAA,GAChE,CAAA;AAEA,EAAO,OAAA,iBAAA,CAAkB,IAAI,CAAU,KAAA,MAAA;AAAA,IACrC,EAAA,EAAI,MAAM,SAAU,CAAA,EAAA;AAAA,IACpB,QAAA,EAAU,MAAM,MAAO,CAAA,QAAA;AAAA,IACvB,WAAW,KAAM,CAAA,SAAA;AAAA,IACjB,QAAA,EAAU,MAAM,MAAO,CAAA,QAAA;AAAA,IACvB,MAAA,EAAQ,MAAM,MAAO,CAAA,MAAA;AAAA,IACrB,MAAA,EAAQ,MAAM,MAAO,CAAA,MAAA;AAAA,GACrB,CAAA,CAAA,CAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"resolveAppNodeSpecs.esm.js","sources":["../../src/tree/resolveAppNodeSpecs.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 BackstagePlugin,\n Extension,\n ExtensionOverrides,\n FrontendFeature,\n} from '@backstage/frontend-plugin-api';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExtensionOverrides } from '../../../frontend-plugin-api/src/wiring/createExtensionOverrides';\nimport { ExtensionParameters } from './readAppExtensionsConfig';\nimport { AppNodeSpec } from '@backstage/frontend-plugin-api';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalBackstagePlugin } from '../../../frontend-plugin-api/src/wiring/createFrontendPlugin';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExtension } from '../../../frontend-plugin-api/src/wiring/resolveExtensionDefinition';\n\n/** @internal */\nexport function resolveAppNodeSpecs(options: {\n features?: FrontendFeature[];\n builtinExtensions?: Extension<any, any>[];\n parameters?: Array<ExtensionParameters>;\n forbidden?: Set<string>;\n}): AppNodeSpec[] {\n const {\n builtinExtensions = [],\n parameters = [],\n forbidden = new Set(),\n features = [],\n } = options;\n\n const plugins = features.filter(\n (f): f is BackstagePlugin => f.$$type === '@backstage/BackstagePlugin',\n );\n const overrides = features.filter(\n (f): f is ExtensionOverrides =>\n f.$$type === '@backstage/ExtensionOverrides',\n );\n\n const pluginExtensions = plugins.flatMap(source => {\n return toInternalBackstagePlugin(source).extensions.map(extension => ({\n ...extension,\n source,\n }));\n });\n const overrideExtensions = overrides.flatMap(\n override => toInternalExtensionOverrides(override).extensions,\n );\n\n // Prevent core override\n if (pluginExtensions.some(({ id }) => forbidden.has(id))) {\n const pluginsStr = pluginExtensions\n .filter(({ id }) => forbidden.has(id))\n .map(({ source }) => `'${source.id}'`)\n .join(', ');\n const forbiddenStr = [...forbidden].map(id => `'${id}'`).join(', ');\n throw new Error(\n `It is forbidden to override the following extension(s): ${forbiddenStr}, which is done by the following plugin(s): ${pluginsStr}`,\n );\n }\n\n if (overrideExtensions.some(({ id }) => forbidden.has(id))) {\n const forbiddenStr = [...forbidden].map(id => `'${id}'`).join(', ');\n throw new Error(\n `It is forbidden to override the following extension(s): ${forbiddenStr}, which is done by one or more extension overrides`,\n );\n }\n const overrideExtensionIds = overrideExtensions.map(({ id }) => id);\n if (overrideExtensionIds.length !== new Set(overrideExtensionIds).size) {\n const counts = new Map<string, number>();\n for (const id of overrideExtensionIds) {\n counts.set(id, (counts.get(id) ?? 0) + 1);\n }\n const duplicated = Array.from(counts.entries())\n .filter(([, count]) => count > 1)\n .map(([id]) => id);\n throw new Error(\n `The following extensions had duplicate overrides: ${duplicated.join(\n ', ',\n )}`,\n );\n }\n\n const configuredExtensions = [\n ...pluginExtensions.map(({ source, ...extension }) => {\n const internalExtension = toInternalExtension(extension);\n return {\n extension: internalExtension,\n params: {\n source,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined as unknown,\n },\n };\n }),\n ...builtinExtensions.map(extension => {\n const internalExtension = toInternalExtension(extension);\n return {\n extension: internalExtension,\n params: {\n source: undefined,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined as unknown,\n },\n };\n }),\n ];\n\n // Install all extension overrides\n for (const extension of overrideExtensions) {\n const internalExtension = toInternalExtension(extension);\n\n // Check if our override is overriding an extension that already exists\n const index = configuredExtensions.findIndex(\n e => e.extension.id === extension.id,\n );\n if (index !== -1) {\n // Only implementation, attachment point and default disabled status are overridden, the source is kept\n configuredExtensions[index].extension = internalExtension;\n configuredExtensions[index].params.attachTo = internalExtension.attachTo;\n configuredExtensions[index].params.disabled = internalExtension.disabled;\n } else {\n // Add the extension as a new one when not overriding an existing one\n configuredExtensions.push({\n extension: internalExtension,\n params: {\n source: undefined,\n attachTo: internalExtension.attachTo,\n disabled: internalExtension.disabled,\n config: undefined,\n },\n });\n }\n }\n\n const duplicatedExtensionIds = new Set<string>();\n const duplicatedExtensionData = configuredExtensions.reduce<\n Record<string, Record<string, number>>\n >((data, { extension, params }) => {\n const extensionId = extension.id;\n const extensionData = data?.[extensionId];\n if (extensionData) duplicatedExtensionIds.add(extensionId);\n const pluginId = params.source?.id ?? 'internal';\n const pluginCount = extensionData?.[pluginId] ?? 0;\n return {\n ...data,\n [extensionId]: { ...extensionData, [pluginId]: pluginCount + 1 },\n };\n }, {});\n\n if (duplicatedExtensionIds.size > 0) {\n throw new Error(\n `The following extensions are duplicated: ${Array.from(\n duplicatedExtensionIds,\n )\n .map(\n extensionId =>\n `The extension '${extensionId}' was provided ${Object.keys(\n duplicatedExtensionData[extensionId],\n )\n .map(\n pluginId =>\n `${duplicatedExtensionData[extensionId][pluginId]} time(s) by the plugin '${pluginId}'`,\n )\n .join(' and ')}`,\n )\n .join(', ')}`,\n );\n }\n\n const order = new Map<string, (typeof configuredExtensions)[number]>();\n for (const overrideParam of parameters) {\n const extensionId = overrideParam.id;\n\n if (forbidden.has(extensionId)) {\n throw new Error(\n `Configuration of the '${extensionId}' extension is forbidden`,\n );\n }\n\n const existing = configuredExtensions.find(\n e => e.extension.id === extensionId,\n );\n if (existing) {\n if (overrideParam.attachTo) {\n existing.params.attachTo = overrideParam.attachTo;\n }\n if (overrideParam.config) {\n // TODO: merge config?\n existing.params.config = overrideParam.config;\n }\n if (\n Boolean(existing.params.disabled) !== Boolean(overrideParam.disabled)\n ) {\n existing.params.disabled = Boolean(overrideParam.disabled);\n }\n order.set(extensionId, existing);\n } else {\n throw new Error(`Extension ${extensionId} does not exist`);\n }\n }\n\n const orderedExtensions = [\n ...order.values(),\n ...configuredExtensions.filter(e => !order.has(e.extension.id)),\n ];\n\n return orderedExtensions.map(param => ({\n id: param.extension.id,\n attachTo: param.params.attachTo,\n extension: param.extension,\n disabled: param.params.disabled,\n source: param.params.source,\n config: param.params.config,\n }));\n}\n"],"names":[],"mappings":";;;;AAgCO,SAAS,oBAAoB,OAKlB,EAAA;AAChB,EAAM,MAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,aAAa,EAAC;AAAA,IACd,SAAA,uBAAgB,GAAI,EAAA;AAAA,IACpB,WAAW,EAAC;AAAA,GACV,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,UAAU,QAAS,CAAA,MAAA;AAAA,IACvB,CAAC,CAA4B,KAAA,CAAA,CAAE,MAAW,KAAA,4BAAA;AAAA,GAC5C,CAAA;AACA,EAAA,MAAM,YAAY,QAAS,CAAA,MAAA;AAAA,IACzB,CAAC,CACC,KAAA,CAAA,CAAE,MAAW,KA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CAAa,UAAA,EAAA,WAAW,CAAiB,eAAA,CAAA,CAAA,CAAA;AAAA,KAC3D;AAAA,GACF;AAEA,EAAA,MAAM,iBAAoB,GAAA;AAAA,IACxB,GAAG,MAAM,MAAO,EAAA;AAAA,IAChB,GAAG,oBAAqB,CAAA,MAAA,CAAO,CAAK,CAAA,KAAA,CAAC,MAAM,GAAI,CAAA,CAAA,CAAE,SAAU,CAAA,EAAE,CAAC,CAAA;AAAA,GAChE,CAAA;AAEA,EAAO,OAAA,iBAAA,CAAkB,IAAI,CAAU,KAAA,MAAA;AAAA,IACrC,EAAA,EAAI,MAAM,SAAU,CAAA,EAAA;AAAA,IACpB,QAAA,EAAU,MAAM,MAAO,CAAA,QAAA;AAAA,IACvB,WAAW,KAAM,CAAA,SAAA;AAAA,IACjB,QAAA,EAAU,MAAM,MAAO,CAAA,QAAA;AAAA,IACvB,MAAA,EAAQ,MAAM,MAAO,CAAA,MAAA;AAAA,IACrB,MAAA,EAAQ,MAAM,MAAO,CAAA,MAAA;AAAA,GACrB,CAAA,CAAA,CAAA;AACJ;;;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { toInternalExtension } from '../frontend-plugin-api/src/wiring/resolveExtensionDefinition.esm.js';
|
|
2
|
+
|
|
1
3
|
function indent(str) {
|
|
2
4
|
return str.replace(/^/gm, " ");
|
|
3
5
|
}
|
|
@@ -11,8 +13,7 @@ class SerializableAppNode {
|
|
|
11
13
|
constructor(spec) {
|
|
12
14
|
this.spec = spec;
|
|
13
15
|
}
|
|
14
|
-
setParent(parent) {
|
|
15
|
-
const input = this.spec.attachTo.input;
|
|
16
|
+
setParent(parent, input) {
|
|
16
17
|
this.edges.attachedTo = { node: parent, input };
|
|
17
18
|
const parentInputEdges = parent.edges.attachments.get(input);
|
|
18
19
|
if (parentInputEdges) {
|
|
@@ -44,36 +45,55 @@ class SerializableAppNode {
|
|
|
44
45
|
].join("\n");
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
function makeRedirectKey(attachTo) {
|
|
49
|
+
return `${attachTo.id}%${attachTo.input}`;
|
|
50
|
+
}
|
|
51
|
+
const isValidAttachmentPoint = (attachTo, nodes) => {
|
|
52
|
+
if (!nodes.has(attachTo.id)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return attachTo.input in toInternalExtension(nodes.get(attachTo.id).spec.extension).inputs;
|
|
56
|
+
};
|
|
47
57
|
function resolveAppTree(rootNodeId, specs) {
|
|
48
58
|
const nodes = /* @__PURE__ */ new Map();
|
|
49
|
-
|
|
50
|
-
const orphansByParent = /* @__PURE__ */ new Map();
|
|
59
|
+
const redirectTargetsByKey = /* @__PURE__ */ new Map();
|
|
51
60
|
for (const spec of specs) {
|
|
52
61
|
if (nodes.has(spec.id)) {
|
|
53
62
|
throw new Error(`Unexpected duplicate extension id '${spec.id}'`);
|
|
54
63
|
}
|
|
55
64
|
const node = new SerializableAppNode(spec);
|
|
56
65
|
nodes.set(spec.id, node);
|
|
66
|
+
const internal = toInternalExtension(spec.extension);
|
|
67
|
+
for (const [inputName, input] of Object.entries(internal.inputs)) {
|
|
68
|
+
if (input.replaces) {
|
|
69
|
+
for (const replace of input.replaces) {
|
|
70
|
+
const key = makeRedirectKey(replace);
|
|
71
|
+
if (redirectTargetsByKey.has(key)) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Duplicate redirect target for input '${inputName}' in extension '${spec.id}'`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
redirectTargetsByKey.set(key, { id: spec.id, input: inputName });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const orphans = new Array();
|
|
82
|
+
let rootNode = void 0;
|
|
83
|
+
for (const node of nodes.values()) {
|
|
84
|
+
const spec = node.spec;
|
|
57
85
|
if (spec.id === rootNodeId) {
|
|
58
86
|
rootNode = node;
|
|
59
87
|
} else {
|
|
60
|
-
|
|
88
|
+
let attachTo = node.spec.attachTo;
|
|
89
|
+
if (!isValidAttachmentPoint(attachTo, nodes)) {
|
|
90
|
+
attachTo = redirectTargetsByKey.get(makeRedirectKey(attachTo)) ?? attachTo;
|
|
91
|
+
}
|
|
92
|
+
const parent = nodes.get(attachTo.id);
|
|
61
93
|
if (parent) {
|
|
62
|
-
node.setParent(parent);
|
|
94
|
+
node.setParent(parent, attachTo.input);
|
|
63
95
|
} else {
|
|
64
|
-
|
|
65
|
-
if (orphanNodesForParent) {
|
|
66
|
-
orphanNodesForParent.push(node);
|
|
67
|
-
} else {
|
|
68
|
-
orphansByParent.set(spec.attachTo.id, [node]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const orphanedChildren = orphansByParent.get(spec.id);
|
|
73
|
-
if (orphanedChildren) {
|
|
74
|
-
orphansByParent.delete(spec.id);
|
|
75
|
-
for (const orphan of orphanedChildren) {
|
|
76
|
-
orphan.setParent(node);
|
|
96
|
+
orphans.push(node);
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
}
|
|
@@ -83,7 +103,7 @@ function resolveAppTree(rootNodeId, specs) {
|
|
|
83
103
|
return {
|
|
84
104
|
root: rootNode,
|
|
85
105
|
nodes,
|
|
86
|
-
orphans
|
|
106
|
+
orphans
|
|
87
107
|
};
|
|
88
108
|
}
|
|
89
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveAppTree.esm.js","sources":["../../src/tree/resolveAppTree.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 AppTree,\n AppNode,\n AppNodeInstance,\n AppNodeSpec,\n} from '@backstage/frontend-plugin-api';\n\nfunction indent(str: string) {\n return str.replace(/^/gm, ' ');\n}\n\n/** @internal */\nclass SerializableAppNode implements AppNode {\n public readonly spec: AppNodeSpec;\n public readonly edges = {\n attachedTo: undefined as { node: AppNode; input: string } | undefined,\n attachments: new Map<string, SerializableAppNode[]>(),\n };\n public readonly instance?: AppNodeInstance;\n\n constructor(spec: AppNodeSpec) {\n this.spec = spec;\n }\n\n setParent(parent: SerializableAppNode) {\n const input = this.spec.attachTo.input;\n\n this.edges.attachedTo = { node: parent, input };\n\n const parentInputEdges = parent.edges.attachments.get(input);\n if (parentInputEdges) {\n parentInputEdges.push(this);\n } else {\n parent.edges.attachments.set(input, [this]);\n }\n }\n\n toJSON() {\n const dataRefs = this.instance && [...this.instance.getDataRefs()];\n return {\n id: this.spec.id,\n output:\n dataRefs && dataRefs.length > 0\n ? dataRefs.map(ref => ref.id)\n : undefined,\n attachments:\n this.edges.attachments.size > 0\n ? Object.fromEntries(this.edges.attachments)\n : undefined,\n };\n }\n\n toString(): string {\n const dataRefs = this.instance && [...this.instance.getDataRefs()];\n const out =\n dataRefs && dataRefs.length > 0\n ? ` out=[${[...dataRefs].map(r => r.id).join(', ')}]`\n : '';\n\n if (this.edges.attachments.size === 0) {\n return `<${this.spec.id}${out} />`;\n }\n\n return [\n `<${this.spec.id}${out}>`,\n ...[...this.edges.attachments.entries()].map(([k, v]) =>\n indent([`${k} [`, ...v.map(e => indent(e.toString())), `]`].join('\\n')),\n ),\n `</${this.spec.id}>`,\n ].join('\\n');\n }\n}\n\n/**\n * Build the app tree by iterating through all node specs and constructing the app\n * tree with all attachments in the same order as they appear in the input specs array.\n * @internal\n */\nexport function resolveAppTree(\n rootNodeId: string,\n specs: AppNodeSpec[],\n): AppTree {\n const nodes = new Map<string, SerializableAppNode>();\n\n // A node with the provided rootNodeId must be found in the tree, and it must not be attached to anything\n let rootNode: AppNode | undefined = undefined;\n\n // While iterating through the inputs specs we keep track of all nodes that were created\n // before their parent, and attach them later when the parent is created.\n // As we find the parents and attach the children, we remove them from this map. This means\n // that after iterating through all input specs, this will be a map for each root node.\n const orphansByParent = new Map<\n string /* parentId */,\n SerializableAppNode[]\n >();\n\n for (const spec of specs) {\n // The main check with a more helpful error message happens in resolveAppNodeSpecs\n if (nodes.has(spec.id)) {\n throw new Error(`Unexpected duplicate extension id '${spec.id}'`);\n }\n\n const node = new SerializableAppNode(spec);\n nodes.set(spec.id, node);\n\n // TODO: For now we simply ignore the attachTo spec of the root node, but it'd be cleaner if we could avoid defining it\n if (spec.id === rootNodeId) {\n rootNode = node;\n } else {\n const parent = nodes.get(spec.attachTo.id);\n if (parent) {\n node.setParent(parent);\n } else {\n const orphanNodesForParent = orphansByParent.get(spec.attachTo.id);\n if (orphanNodesForParent) {\n orphanNodesForParent.push(node);\n } else {\n orphansByParent.set(spec.attachTo.id, [node]);\n }\n }\n }\n\n const orphanedChildren = orphansByParent.get(spec.id);\n if (orphanedChildren) {\n orphansByParent.delete(spec.id);\n for (const orphan of orphanedChildren) {\n orphan.setParent(node);\n }\n }\n }\n\n if (!rootNode) {\n throw new Error(`No root node with id '${rootNodeId}' found in app tree`);\n }\n\n return {\n root: rootNode,\n nodes,\n orphans: Array.from(orphansByParent.values()).flat(),\n };\n}\n"],"names":[],"mappings":"AAuBA,SAAS,OAAO,GAAa,EAAA;AAC3B,EAAO,OAAA,GAAA,CAAI,OAAQ,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAChC,CAAA;AAGA,MAAM,mBAAuC,CAAA;AAAA,EAC3B,IAAA,CAAA;AAAA,EACA,KAAQ,GAAA;AAAA,IACtB,UAAY,EAAA,KAAA,CAAA;AAAA,IACZ,WAAA,sBAAiB,GAAmC,EAAA;AAAA,GACtD,CAAA;AAAA,EACgB,QAAA,CAAA;AAAA,EAEhB,YAAY,IAAmB,EAAA;AAC7B,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA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;AAEA,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAA,MAAM,IAAI,KAAA,CAAM,CAAyB,sBAAA,EAAA,UAAU,CAAqB,mBAAA,CAAA,CAAA,CAAA;AAAA,GAC1E;AAEA,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,QAAA;AAAA,IACN,KAAA;AAAA,IACA,SAAS,KAAM,CAAA,IAAA,CAAK,gBAAgB,MAAO,EAAC,EAAE,IAAK,EAAA;AAAA,GACrD,CAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"resolveAppTree.esm.js","sources":["../../src/tree/resolveAppTree.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 AppTree,\n AppNode,\n AppNodeInstance,\n AppNodeSpec,\n} from '@backstage/frontend-plugin-api';\n\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalExtension } from '../../../frontend-plugin-api/src/wiring/resolveExtensionDefinition';\n\nfunction indent(str: string) {\n return str.replace(/^/gm, ' ');\n}\n\n/** @internal */\nclass SerializableAppNode implements AppNode {\n public readonly spec: AppNodeSpec;\n public readonly edges = {\n attachedTo: undefined as { node: AppNode; input: string } | undefined,\n attachments: new Map<string, SerializableAppNode[]>(),\n };\n public readonly instance?: AppNodeInstance;\n\n constructor(spec: AppNodeSpec) {\n this.spec = spec;\n }\n\n setParent(parent: SerializableAppNode, input: string) {\n this.edges.attachedTo = { node: parent, input };\n\n const parentInputEdges = parent.edges.attachments.get(input);\n if (parentInputEdges) {\n parentInputEdges.push(this);\n } else {\n parent.edges.attachments.set(input, [this]);\n }\n }\n\n toJSON() {\n const dataRefs = this.instance && [...this.instance.getDataRefs()];\n return {\n id: this.spec.id,\n output:\n dataRefs && dataRefs.length > 0\n ? dataRefs.map(ref => ref.id)\n : undefined,\n attachments:\n this.edges.attachments.size > 0\n ? Object.fromEntries(this.edges.attachments)\n : undefined,\n };\n }\n\n toString(): string {\n const dataRefs = this.instance && [...this.instance.getDataRefs()];\n const out =\n dataRefs && dataRefs.length > 0\n ? ` out=[${[...dataRefs].map(r => r.id).join(', ')}]`\n : '';\n\n if (this.edges.attachments.size === 0) {\n return `<${this.spec.id}${out} />`;\n }\n\n return [\n `<${this.spec.id}${out}>`,\n ...[...this.edges.attachments.entries()].map(([k, v]) =>\n indent([`${k} [`, ...v.map(e => indent(e.toString())), `]`].join('\\n')),\n ),\n `</${this.spec.id}>`,\n ].join('\\n');\n }\n}\n\nfunction makeRedirectKey(attachTo: { id: string; input: string }) {\n return `${attachTo.id}%${attachTo.input}`;\n}\n\nconst isValidAttachmentPoint = (\n attachTo: { id: string; input: string },\n nodes: Map<string, SerializableAppNode>,\n) => {\n if (!nodes.has(attachTo.id)) {\n return false;\n }\n\n return (\n attachTo.input in\n toInternalExtension(nodes.get(attachTo.id)!.spec.extension).inputs\n );\n};\n\n/**\n * Build the app tree by iterating through all node specs and constructing the app\n * tree with all attachments in the same order as they appear in the input specs array.\n * @internal\n */\nexport function resolveAppTree(\n rootNodeId: string,\n specs: AppNodeSpec[],\n): AppTree {\n const nodes = new Map<string, SerializableAppNode>();\n\n const redirectTargetsByKey = new Map<string, { id: string; input: string }>();\n\n for (const spec of specs) {\n // The main check with a more helpful error message happens in resolveAppNodeSpecs\n if (nodes.has(spec.id)) {\n throw new Error(`Unexpected duplicate extension id '${spec.id}'`);\n }\n\n const node = new SerializableAppNode(spec);\n nodes.set(spec.id, node);\n\n const internal = toInternalExtension(spec.extension);\n for (const [inputName, input] of Object.entries(internal.inputs)) {\n if (input.replaces) {\n for (const replace of input.replaces) {\n const key = makeRedirectKey(replace);\n if (redirectTargetsByKey.has(key)) {\n throw new Error(\n `Duplicate redirect target for input '${inputName}' in extension '${spec.id}'`,\n );\n }\n redirectTargetsByKey.set(key, { id: spec.id, input: inputName });\n }\n }\n }\n }\n\n const orphans = new Array<SerializableAppNode>();\n\n // A node with the provided rootNodeId must be found in the tree, and it must not be attached to anything\n let rootNode: AppNode | undefined = undefined;\n\n for (const node of nodes.values()) {\n const spec = node.spec;\n\n // TODO: For now we simply ignore the attachTo spec of the root node, but it'd be cleaner if we could avoid defining it\n if (spec.id === rootNodeId) {\n rootNode = node;\n } else {\n let attachTo = node.spec.attachTo;\n\n if (!isValidAttachmentPoint(attachTo, nodes)) {\n attachTo =\n redirectTargetsByKey.get(makeRedirectKey(attachTo)) ?? attachTo;\n }\n\n const parent = nodes.get(attachTo.id);\n if (parent) {\n node.setParent(parent, attachTo.input);\n } else {\n orphans.push(node);\n }\n }\n }\n\n if (!rootNode) {\n throw new Error(`No root node with id '${rootNodeId}' found in app tree`);\n }\n\n return {\n root: rootNode,\n nodes,\n orphans,\n };\n}\n"],"names":[],"mappings":";;AA0BA,SAAS,OAAO,GAAa,EAAA;AAC3B,EAAO,OAAA,GAAA,CAAI,OAAQ,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAChC,CAAA;AAGA,MAAM,mBAAuC,CAAA;AAAA,EAC3B,IAAA,CAAA;AAAA,EACA,KAAQ,GAAA;AAAA,IACtB,UAAY,EAAA,KAAA,CAAA;AAAA,IACZ,WAAA,sBAAiB,GAAmC,EAAA;AAAA,GACtD,CAAA;AAAA,EACgB,QAAA,CAAA;AAAA,EAEhB,YAAY,IAAmB,EAAA;AAC7B,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GACd;AAAA,EAEA,SAAA,CAAU,QAA6B,KAAe,EAAA;AACpD,IAAA,IAAA,CAAK,KAAM,CAAA,UAAA,GAAa,EAAE,IAAA,EAAM,QAAQ,KAAM,EAAA,CAAA;AA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|
-
import { AppRoutes } from '../extensions/AppRoutes.esm.js';
|
|
6
|
-
import { AppLayout } from '../extensions/AppLayout.esm.js';
|
|
7
|
-
import { AppNav } from '../extensions/AppNav.esm.js';
|
|
8
|
-
import { discoveryApiRef, errorApiRef, fetchApiRef, featureFlagsApiRef, identityApiRef, appThemeApiRef, configApiRef } from '@backstage/core-plugin-api';
|
|
3
|
+
import { createApiFactory, appTreeApiRef, routeResolutionApiRef, coreExtensionData, ApiBlueprint } from '@backstage/frontend-plugin-api';
|
|
4
|
+
import { configApiRef, identityApiRef, featureFlagsApiRef } from '@backstage/core-plugin-api';
|
|
9
5
|
import { getAvailableFeatures } from './discovery.esm.js';
|
|
10
|
-
import { ApiFactoryRegistry,
|
|
11
|
-
import { isProtectedApp } from '../core-app-api/src/app/isProtectedApp.esm.js';
|
|
12
|
-
import { AppThemeProvider } from '../core-app-api/src/app/AppThemeProvider.esm.js';
|
|
13
|
-
import { AppIdentityProxy } from '../core-app-api/src/apis/implementations/IdentityApi/AppIdentityProxy.esm.js';
|
|
14
|
-
import { LocalStorageFeatureFlags } from '../core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js';
|
|
6
|
+
import { ApiFactoryRegistry, ApiResolver } from '@backstage/core-app-api';
|
|
15
7
|
import { defaultConfigLoaderSync } from '../core-app-api/src/app/defaultConfigLoader.esm.js';
|
|
16
8
|
import { overrideBaseUrlConfigs } from '../core-app-api/src/app/overrideBaseUrlConfigs.esm.js';
|
|
17
|
-
import { AppLanguageSelector } from '../core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js';
|
|
18
|
-
import { I18nextTranslationApi } from '../core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js';
|
|
19
9
|
import { resolveExtensionDefinition } from '../frontend-plugin-api/src/wiring/resolveExtensionDefinition.esm.js';
|
|
20
|
-
import { apis } from '../app-defaults/src/defaults/apis.esm.js';
|
|
21
|
-
import '@material-ui/core/Button';
|
|
22
|
-
import '@backstage/core-components';
|
|
23
|
-
import 'react-router-dom';
|
|
24
|
-
import { icons } from '../app-defaults/src/defaults/icons.esm.js';
|
|
25
|
-
import '@backstage/theme';
|
|
26
|
-
import '@material-ui/icons/Brightness2';
|
|
27
|
-
import '@material-ui/icons/WbSunny';
|
|
28
|
-
import { LightTheme, DarkTheme } from '../extensions/themes.esm.js';
|
|
29
|
-
import { oauthRequestDialogAppRootElement, alertDisplayAppRootElement } from '../extensions/elements.esm.js';
|
|
30
10
|
import { extractRouteInfoFromAppNode } from '../routing/extractRouteInfoFromAppNode.esm.js';
|
|
31
|
-
import { appLanguageApiRef, translationApiRef } from '@backstage/core-plugin-api/alpha';
|
|
32
11
|
import { RouteResolver } from '../routing/RouteResolver.esm.js';
|
|
33
12
|
import { resolveRouteBindings } from '../routing/resolveRouteBindings.esm.js';
|
|
34
13
|
import { collectRouteIds } from '../routing/collectRouteIds.esm.js';
|
|
35
|
-
import {
|
|
36
|
-
import { DefaultProgressComponent, DefaultErrorBoundaryComponent, DefaultNotFoundErrorPageComponent } from '../extensions/components.esm.js';
|
|
37
|
-
import { InternalAppContext } from './InternalAppContext.esm.js';
|
|
38
|
-
import { AppRoot } from '../extensions/AppRoot.esm.js';
|
|
39
|
-
import { toInternalBackstagePlugin } from '../frontend-plugin-api/src/wiring/createPlugin.esm.js';
|
|
14
|
+
import { toInternalBackstagePlugin } from '../frontend-plugin-api/src/wiring/createFrontendPlugin.esm.js';
|
|
40
15
|
import { toInternalExtensionOverrides } from '../frontend-plugin-api/src/wiring/createExtensionOverrides.esm.js';
|
|
41
|
-
import { DefaultComponentsApi } from '../apis/implementations/ComponentsApi/DefaultComponentsApi.esm.js';
|
|
42
|
-
import { DefaultIconsApi } from '../apis/implementations/IconsApi/DefaultIconsApi.esm.js';
|
|
43
16
|
import { stringifyError } from '@backstage/errors';
|
|
44
17
|
import { getBasePath } from '../routing/getBasePath.esm.js';
|
|
18
|
+
import { Root } from '../extensions/Root.esm.js';
|
|
19
|
+
import { resolveAppTree } from '../tree/resolveAppTree.esm.js';
|
|
20
|
+
import { resolveAppNodeSpecs } from '../tree/resolveAppNodeSpecs.esm.js';
|
|
21
|
+
import { readAppExtensionsConfig } from '../tree/readAppExtensionsConfig.esm.js';
|
|
22
|
+
import { instantiateAppNodeTree } from '../tree/instantiateAppNodeTree.esm.js';
|
|
23
|
+
import { ApiRegistry } from '../core-app-api/src/apis/system/ApiRegistry.esm.js';
|
|
24
|
+
import { AppIdentityProxy } from '../core-app-api/src/apis/implementations/IdentityApi/AppIdentityProxy.esm.js';
|
|
25
|
+
import appPlugin from '@backstage/plugin-app';
|
|
45
26
|
|
|
46
|
-
const DefaultApis = apis.map((factory) => createApiExtension({ factory }));
|
|
47
|
-
const builtinExtensions = [
|
|
48
|
-
App,
|
|
49
|
-
AppRoot,
|
|
50
|
-
AppRoutes,
|
|
51
|
-
AppNav,
|
|
52
|
-
AppLayout,
|
|
53
|
-
DefaultProgressComponent,
|
|
54
|
-
DefaultErrorBoundaryComponent,
|
|
55
|
-
DefaultNotFoundErrorPageComponent,
|
|
56
|
-
LightTheme,
|
|
57
|
-
DarkTheme,
|
|
58
|
-
oauthRequestDialogAppRootElement,
|
|
59
|
-
alertDisplayAppRootElement,
|
|
60
|
-
...DefaultApis
|
|
61
|
-
].map((def) => resolveExtensionDefinition(def));
|
|
62
27
|
function deduplicateFeatures(allFeatures) {
|
|
63
28
|
const features = Array.from(new Set(allFeatures));
|
|
64
29
|
const seenIds = /* @__PURE__ */ new Set();
|
|
@@ -101,7 +66,6 @@ function createApp(options) {
|
|
|
101
66
|
}
|
|
102
67
|
}
|
|
103
68
|
const app = createSpecializedApp({
|
|
104
|
-
icons: options?.icons,
|
|
105
69
|
config,
|
|
106
70
|
features: [...discoveredFeatures, ...providedFeatures],
|
|
107
71
|
bindRoutes: options?.bindRoutes
|
|
@@ -115,52 +79,94 @@ function createApp(options) {
|
|
|
115
79
|
}
|
|
116
80
|
};
|
|
117
81
|
}
|
|
82
|
+
class AppTreeApiProxy {
|
|
83
|
+
constructor(tree) {
|
|
84
|
+
this.tree = tree;
|
|
85
|
+
}
|
|
86
|
+
#safeToUse = false;
|
|
87
|
+
getTree() {
|
|
88
|
+
if (!this.#safeToUse) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`You can't access the AppTreeApi during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return { tree: this.tree };
|
|
94
|
+
}
|
|
95
|
+
initialize() {
|
|
96
|
+
this.#safeToUse = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class RouteResolutionApiProxy {
|
|
100
|
+
constructor(tree, routeBindings, basePath) {
|
|
101
|
+
this.tree = tree;
|
|
102
|
+
this.routeBindings = routeBindings;
|
|
103
|
+
this.basePath = basePath;
|
|
104
|
+
}
|
|
105
|
+
#delegate;
|
|
106
|
+
#routeObjects;
|
|
107
|
+
resolve(anyRouteRef, options) {
|
|
108
|
+
if (!this.#delegate) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`You can't access the RouteResolver during initialization of the app tree. Please move occurrences of this out of the initialization of the factory`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return this.#delegate.resolve(anyRouteRef, options);
|
|
114
|
+
}
|
|
115
|
+
initialize() {
|
|
116
|
+
const routeInfo = extractRouteInfoFromAppNode(this.tree.root);
|
|
117
|
+
this.#delegate = new RouteResolver(
|
|
118
|
+
routeInfo.routePaths,
|
|
119
|
+
routeInfo.routeParents,
|
|
120
|
+
routeInfo.routeObjects,
|
|
121
|
+
this.routeBindings,
|
|
122
|
+
this.basePath
|
|
123
|
+
);
|
|
124
|
+
this.#routeObjects = routeInfo.routeObjects;
|
|
125
|
+
return routeInfo;
|
|
126
|
+
}
|
|
127
|
+
getRouteObjects() {
|
|
128
|
+
return this.#routeObjects;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
118
131
|
function createSpecializedApp(options) {
|
|
119
132
|
const {
|
|
120
|
-
features:
|
|
133
|
+
features: featuresWithoutApp = [],
|
|
121
134
|
config = new ConfigReader({}, "empty-config")
|
|
122
135
|
} = options ?? {};
|
|
123
|
-
const features = deduplicateFeatures(
|
|
124
|
-
const tree =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
config,
|
|
133
|
-
collectRouteIds(features)
|
|
136
|
+
const features = deduplicateFeatures([appPlugin, ...featuresWithoutApp]);
|
|
137
|
+
const tree = resolveAppTree(
|
|
138
|
+
"root",
|
|
139
|
+
resolveAppNodeSpecs({
|
|
140
|
+
features,
|
|
141
|
+
builtinExtensions: [resolveExtensionDefinition(Root)],
|
|
142
|
+
parameters: readAppExtensionsConfig(config),
|
|
143
|
+
forbidden: /* @__PURE__ */ new Set(["root"])
|
|
144
|
+
})
|
|
134
145
|
);
|
|
135
|
-
const
|
|
136
|
-
const
|
|
146
|
+
const factories = createApiFactories({ tree });
|
|
147
|
+
const appTreeApi = new AppTreeApiProxy(tree);
|
|
148
|
+
const routeResolutionApi = new RouteResolutionApiProxy(
|
|
137
149
|
tree,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
routeInfo.routeParents,
|
|
143
|
-
routeInfo.routeObjects,
|
|
144
|
-
routeBindings,
|
|
145
|
-
getBasePath(config)
|
|
150
|
+
resolveRouteBindings(
|
|
151
|
+
options?.bindRoutes,
|
|
152
|
+
config,
|
|
153
|
+
collectRouteIds(features)
|
|
146
154
|
),
|
|
147
|
-
|
|
155
|
+
getBasePath(config)
|
|
148
156
|
);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
}
|
|
157
|
+
const appIdentityProxy = new AppIdentityProxy();
|
|
158
|
+
const apiHolder = createApiHolder({
|
|
159
|
+
factories,
|
|
160
|
+
staticFactories: [
|
|
161
|
+
createApiFactory(appTreeApiRef, appTreeApi),
|
|
162
|
+
createApiFactory(configApiRef, config),
|
|
163
|
+
createApiFactory(routeResolutionApiRef, routeResolutionApi),
|
|
164
|
+
createApiFactory(identityApiRef, appIdentityProxy)
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
instantiateAppNodeTree(tree.root, apiHolder);
|
|
168
|
+
routeResolutionApi.initialize();
|
|
169
|
+
appTreeApi.initialize();
|
|
164
170
|
const featureFlagApi = apiHolder.get(featureFlagsApiRef);
|
|
165
171
|
if (featureFlagApi) {
|
|
166
172
|
for (const feature of features) {
|
|
@@ -180,96 +186,39 @@ function createSpecializedApp(options) {
|
|
|
180
186
|
}
|
|
181
187
|
}
|
|
182
188
|
const rootEl = tree.root.instance.getData(coreExtensionData.reactElement);
|
|
183
|
-
const AppComponent = () =>
|
|
184
|
-
InternalAppContext.Provider,
|
|
185
|
-
{
|
|
186
|
-
value: { appIdentityProxy, routeObjects: routeInfo.routeObjects }
|
|
187
|
-
},
|
|
188
|
-
rootEl
|
|
189
|
-
)));
|
|
189
|
+
const AppComponent = () => rootEl;
|
|
190
190
|
return {
|
|
191
191
|
createRoot() {
|
|
192
192
|
return /* @__PURE__ */ React.createElement(AppComponent, null);
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function createApiFactories(options) {
|
|
197
|
+
const emptyApiHolder = ApiRegistry.from([]);
|
|
198
|
+
const factories = new Array();
|
|
199
|
+
for (const apiNode of options.tree.root.edges.attachments.get("apis") ?? []) {
|
|
200
|
+
instantiateAppNodeTree(apiNode, emptyApiHolder);
|
|
201
|
+
const apiFactory = apiNode.instance?.getData(ApiBlueprint.dataRefs.factory);
|
|
202
|
+
if (!apiFactory) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`No API factory found in for extension ${apiNode.spec.id}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
factories.push(apiFactory);
|
|
208
|
+
}
|
|
209
|
+
return factories;
|
|
210
|
+
}
|
|
211
|
+
function createApiHolder(options) {
|
|
197
212
|
const factoryRegistry = new ApiFactoryRegistry();
|
|
198
|
-
const
|
|
199
|
-
const themeExtensions = tree.root.edges.attachments.get("themes")?.map((e) => e.instance?.getData(createThemeExtension.themeDataRef)).filter((x) => !!x) ?? [];
|
|
200
|
-
const translationResources = tree.root.edges.attachments.get("translations")?.map(
|
|
201
|
-
(e) => e.instance?.getData(createTranslationExtension.translationDataRef)
|
|
202
|
-
).filter(
|
|
203
|
-
(x) => !!x
|
|
204
|
-
) ?? [];
|
|
205
|
-
const extensionIcons = tree.root.edges.attachments.get("icons")?.map((e) => e.instance?.getData(IconBundleBlueprint.dataRefs.icons)).reduce((acc, bundle) => ({ ...acc, ...bundle }), {});
|
|
206
|
-
for (const factory of pluginApis) {
|
|
213
|
+
for (const factory of options.factories) {
|
|
207
214
|
factoryRegistry.register("default", factory);
|
|
208
215
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
factory: () => new LocalStorageFeatureFlags()
|
|
213
|
-
});
|
|
214
|
-
factoryRegistry.register("static", {
|
|
215
|
-
api: identityApiRef,
|
|
216
|
-
deps: {},
|
|
217
|
-
factory: () => appIdentityProxy
|
|
218
|
-
});
|
|
219
|
-
factoryRegistry.register("static", {
|
|
220
|
-
api: appTreeApiRef,
|
|
221
|
-
deps: {},
|
|
222
|
-
factory: () => ({
|
|
223
|
-
getTree: () => ({ tree })
|
|
224
|
-
})
|
|
225
|
-
});
|
|
226
|
-
factoryRegistry.register("static", {
|
|
227
|
-
api: routeResolutionApiRef,
|
|
228
|
-
deps: {},
|
|
229
|
-
factory: () => routeResolutionApi
|
|
230
|
-
});
|
|
231
|
-
factoryRegistry.register("static", {
|
|
232
|
-
api: componentsApiRef,
|
|
233
|
-
deps: {},
|
|
234
|
-
factory: () => DefaultComponentsApi.fromTree(tree)
|
|
235
|
-
});
|
|
236
|
-
factoryRegistry.register("static", {
|
|
237
|
-
api: iconsApiRef,
|
|
238
|
-
deps: {},
|
|
239
|
-
factory: () => new DefaultIconsApi({ ...icons, ...extensionIcons, ...icons$1 })
|
|
240
|
-
});
|
|
241
|
-
factoryRegistry.register("static", {
|
|
242
|
-
api: appThemeApiRef,
|
|
243
|
-
deps: {},
|
|
244
|
-
// TODO: add extension for registering themes
|
|
245
|
-
factory: () => AppThemeSelector.createWithStorage(themeExtensions)
|
|
246
|
-
});
|
|
247
|
-
factoryRegistry.register("static", {
|
|
248
|
-
api: appLanguageApiRef,
|
|
249
|
-
deps: {},
|
|
250
|
-
factory: () => AppLanguageSelector.createWithStorage()
|
|
251
|
-
});
|
|
252
|
-
factoryRegistry.register("static", {
|
|
253
|
-
api: configApiRef,
|
|
254
|
-
deps: {},
|
|
255
|
-
factory: () => configApi
|
|
256
|
-
});
|
|
257
|
-
factoryRegistry.register("static", {
|
|
258
|
-
api: appLanguageApiRef,
|
|
259
|
-
deps: {},
|
|
260
|
-
factory: () => AppLanguageSelector.createWithStorage()
|
|
261
|
-
});
|
|
262
|
-
factoryRegistry.register("static", {
|
|
263
|
-
api: translationApiRef,
|
|
264
|
-
deps: { languageApi: appLanguageApiRef },
|
|
265
|
-
factory: ({ languageApi }) => I18nextTranslationApi.create({
|
|
266
|
-
languageApi,
|
|
267
|
-
resources: translationResources
|
|
268
|
-
})
|
|
269
|
-
});
|
|
216
|
+
for (const factory of options.staticFactories) {
|
|
217
|
+
factoryRegistry.register("static", factory);
|
|
218
|
+
}
|
|
270
219
|
ApiResolver.validateFactories(factoryRegistry, factoryRegistry.getAllApis());
|
|
271
220
|
return new ApiResolver(factoryRegistry);
|
|
272
221
|
}
|
|
273
222
|
|
|
274
|
-
export {
|
|
223
|
+
export { createApp, createSpecializedApp };
|
|
275
224
|
//# sourceMappingURL=createApp.esm.js.map
|