@backstage/frontend-plugin-api 0.11.0-next.1 → 0.11.0-next.2

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/analytics/useAnalytics.esm.js +1 -1
  3. package/dist/apis/definitions/AppTreeApi.esm.js.map +1 -1
  4. package/dist/apis/definitions/DialogApi.esm.js.map +1 -1
  5. package/dist/apis/definitions/SwappableComponentsApi.esm.js +8 -0
  6. package/dist/apis/definitions/SwappableComponentsApi.esm.js.map +1 -0
  7. package/dist/blueprints/PageBlueprint.esm.js +10 -0
  8. package/dist/blueprints/PageBlueprint.esm.js.map +1 -1
  9. package/dist/blueprints/SignInPageBlueprint.esm.js +8 -0
  10. package/dist/blueprints/SignInPageBlueprint.esm.js.map +1 -1
  11. package/dist/blueprints/SwappableComponentBlueprint.esm.js +27 -0
  12. package/dist/blueprints/SwappableComponentBlueprint.esm.js.map +1 -0
  13. package/dist/components/DefaultSwappableComponents.esm.js +16 -0
  14. package/dist/components/DefaultSwappableComponents.esm.js.map +1 -0
  15. package/dist/components/ErrorBoundary.esm.js +3 -2
  16. package/dist/components/ErrorBoundary.esm.js.map +1 -1
  17. package/dist/components/ExtensionBoundary.esm.js +2 -10
  18. package/dist/components/ExtensionBoundary.esm.js.map +1 -1
  19. package/dist/components/createSwappableComponent.esm.js +52 -0
  20. package/dist/components/createSwappableComponent.esm.js.map +1 -0
  21. package/dist/frontend-internal/src/wiring/InternalSwappableComponentRef.esm.js +9 -0
  22. package/dist/frontend-internal/src/wiring/InternalSwappableComponentRef.esm.js.map +1 -0
  23. package/dist/frontend-internal/src/wiring/createExtensionDataContainer.esm.js +4 -1
  24. package/dist/frontend-internal/src/wiring/createExtensionDataContainer.esm.js.map +1 -1
  25. package/dist/index.d.ts +244 -86
  26. package/dist/index.esm.js +4 -4
  27. package/dist/routing/useRouteRef.esm.js +1 -1
  28. package/dist/wiring/createExtension.esm.js +7 -0
  29. package/dist/wiring/createExtension.esm.js.map +1 -1
  30. package/dist/wiring/createExtensionBlueprint.esm.js +1 -0
  31. package/dist/wiring/createExtensionBlueprint.esm.js.map +1 -1
  32. package/dist/wiring/createFrontendModule.esm.js.map +1 -1
  33. package/dist/wiring/createFrontendPlugin.esm.js +2 -6
  34. package/dist/wiring/createFrontendPlugin.esm.js.map +1 -1
  35. package/dist/wiring/resolveInputOverrides.esm.js +3 -0
  36. package/dist/wiring/resolveInputOverrides.esm.js.map +1 -1
  37. package/package.json +4 -4
  38. package/dist/apis/definitions/ComponentsApi.esm.js +0 -12
  39. package/dist/apis/definitions/ComponentsApi.esm.js.map +0 -1
  40. package/dist/components/coreComponentRefs.esm.js +0 -19
  41. package/dist/components/coreComponentRefs.esm.js.map +0 -1
  42. package/dist/components/createComponentRef.esm.js +0 -12
  43. package/dist/components/createComponentRef.esm.js.map +0 -1
  44. package/dist/extensions/createComponentExtension.esm.js +0 -43
  45. package/dist/extensions/createComponentExtension.esm.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createExtensionBlueprint.esm.js","sources":["../../src/wiring/createExtensionBlueprint.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { ApiHolder, AppNode } from '../apis';\nimport { Expand } from '@backstage/types';\nimport { OpaqueType } from '@internal/opaque';\nimport {\n ExtensionAttachToSpec,\n ExtensionDefinition,\n ResolvedExtensionInputs,\n VerifyExtensionFactoryOutput,\n createExtension,\n ctxParamsSymbol,\n} from './createExtension';\nimport { z } from 'zod';\nimport { ExtensionInput } from './createExtensionInput';\nimport { ExtensionDataRef, ExtensionDataValue } from './createExtensionDataRef';\nimport { createExtensionDataContainer } from '@internal/frontend';\nimport {\n ResolveInputValueOverrides,\n resolveInputOverrides,\n} from './resolveInputOverrides';\nimport { ExtensionDataContainer } from './types';\n\n/**\n * A function used to define a parameter mapping function in order to facilitate\n * advanced parameter typing for extension blueprints.\n *\n * @remarks\n *\n * This function is primarily intended to enable the use of inferred type\n * parameters for blueprint params, but it can also be used to transoform the\n * params before they are handed ot the blueprint.\n *\n * The function must return an object created with\n * {@link createExtensionBlueprintParams}.\n *\n * @public\n */\nexport type ExtensionBlueprintDefineParams<\n TParams extends object = object,\n TInput = any,\n> = (params: TInput) => ExtensionBlueprintParams<TParams>;\n\n/**\n * An opaque type that represents a set of parameters to be passed to a blueprint.\n *\n * @remarks\n *\n * Created with {@link createExtensionBlueprintParams}.\n *\n * @public\n */\nexport type ExtensionBlueprintParams<T extends object = object> = {\n $$type: '@backstage/BlueprintParams';\n T: T;\n};\n\nconst OpaqueBlueprintParams = OpaqueType.create<{\n public: ExtensionBlueprintParams;\n versions: {\n version: 'v1';\n params: object;\n };\n}>({\n type: '@backstage/BlueprintParams',\n versions: ['v1'],\n});\n\n/**\n * Wraps a plain blueprint parameter object in an opaque {@link ExtensionBlueprintParams} object.\n *\n * This is used in the definition of the `defineParams` option of {@link ExtensionBlueprint}.\n *\n * @public\n * @param params - The plain blueprint parameter object to wrap.\n * @returns The wrapped blueprint parameter object.\n */\nexport function createExtensionBlueprintParams<T extends object = object>(\n params: T,\n): ExtensionBlueprintParams<T> {\n return OpaqueBlueprintParams.createInstance('v1', { T: null as any, params });\n}\n\n/**\n * @public\n */\nexport type CreateExtensionBlueprintOptions<\n TKind extends string,\n TParams extends object | ExtensionBlueprintDefineParams,\n UOutput extends ExtensionDataRef,\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n TConfigSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n TDataRefs extends { [name in string]: ExtensionDataRef },\n> = {\n kind: TKind;\n attachTo: ExtensionAttachToSpec;\n disabled?: boolean;\n inputs?: TInputs;\n output: Array<UOutput>;\n config?: {\n schema: TConfigSchema;\n };\n /**\n * This option is used to further refine the blueprint params. When this\n * option is used, the blueprint will require params to be passed in callback\n * form. This function can both transform the params before they are handed to\n * the blueprint factory, but importantly it also allows you to define\n * inferred type parameters for your blueprint params.\n *\n * @example\n * Blueprint definition with inferred type parameters:\n * ```ts\n * const ExampleBlueprint = createExtensionBlueprint({\n * kind: 'example',\n * attachTo: { id: 'example', input: 'example' },\n * output: [exampleComponentDataRef, exampleFetcherDataRef],\n * defineParams<T>(params: {\n * component(props: ExampleProps<T>): JSX.Element | null\n * fetcher(options: FetchOptions): Promise<FetchResult<T>>\n * }) {\n * return createExtensionBlueprintParams(params);\n * },\n * *factory(params) {\n * yield exampleComponentDataRef(params.component)\n * yield exampleFetcherDataRef(params.fetcher)\n * },\n * });\n * ```\n *\n * @example\n * Usage of the above example blueprint:\n * ```ts\n * const example = ExampleBlueprint.make({\n * params: defineParams => defineParams({\n * component: ...,\n * fetcher: ...,\n * }),\n * });\n * ```\n */\n defineParams?: TParams extends ExtensionBlueprintDefineParams\n ? TParams\n : 'The defineParams option must be a function if provided, see the docs for details';\n factory(\n params: TParams extends ExtensionBlueprintDefineParams\n ? ReturnType<TParams>['T']\n : TParams,\n context: {\n node: AppNode;\n apis: ApiHolder;\n config: {\n [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;\n };\n inputs: Expand<ResolvedExtensionInputs<TInputs>>;\n },\n ): Iterable<UFactoryOutput>;\n\n dataRefs?: TDataRefs;\n} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>;\n\n/** @public */\nexport type ExtensionBlueprintParameters = {\n kind: string;\n params?: object | ExtensionBlueprintDefineParams;\n configInput?: { [K in string]: any };\n config?: { [K in string]: any };\n output?: ExtensionDataRef;\n inputs?: {\n [KName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n };\n dataRefs?: { [name in string]: ExtensionDataRef };\n};\n\n/** @ignore */\ntype ParamsFactory<TDefiner extends ExtensionBlueprintDefineParams> = (\n defineParams: TDefiner,\n) => ReturnType<TDefiner>;\n\n/**\n * Represents any form of params input that can be passed to a blueprint.\n * This also includes the invalid form of passing a plain params object to a blueprint that uses a definition callback.\n *\n * @ignore\n */\ntype AnyParamsInput<TParams extends object | ExtensionBlueprintDefineParams> =\n TParams extends ExtensionBlueprintDefineParams<infer IParams>\n ? IParams | ParamsFactory<TParams>\n : TParams | ParamsFactory<ExtensionBlueprintDefineParams<TParams, TParams>>;\n\n/**\n * @public\n */\nexport interface ExtensionBlueprint<\n // TParamsMapper extends (params: any) => object,\n T extends ExtensionBlueprintParameters = ExtensionBlueprintParameters,\n> {\n dataRefs: T['dataRefs'];\n\n make<\n TName extends string | undefined,\n TParamsInput extends AnyParamsInput<NonNullable<T['params']>>,\n >(args: {\n name?: TName;\n attachTo?: ExtensionAttachToSpec;\n disabled?: boolean;\n params: TParamsInput extends ExtensionBlueprintDefineParams\n ? TParamsInput\n : T['params'] extends ExtensionBlueprintDefineParams\n ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `<blueprint>.make({ params: defineParams => defineParams(<params>) })`'\n : T['params'];\n }): ExtensionDefinition<{\n kind: T['kind'];\n name: string | undefined extends TName ? undefined : TName;\n config: T['config'];\n configInput: T['configInput'];\n output: T['output'];\n inputs: T['inputs'];\n params: T['params'];\n }>;\n\n /**\n * Creates a new extension from the blueprint.\n *\n * You must either pass `params` directly, or define a `factory` that can\n * optionally call the original factory with the same params.\n */\n makeWithOverrides<\n TName extends string | undefined,\n TExtensionConfigSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n UNewOutput extends ExtensionDataRef,\n TExtraInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n >(args: {\n name?: TName;\n attachTo?: ExtensionAttachToSpec;\n disabled?: boolean;\n inputs?: TExtraInputs & {\n [KName in keyof T['inputs']]?: `Error: Input '${KName &\n string}' is already defined in parent definition`;\n };\n output?: Array<UNewOutput>;\n config?: {\n schema: TExtensionConfigSchema & {\n [KName in keyof T['config']]?: `Error: Config key '${KName &\n string}' is already defined in parent schema`;\n };\n };\n factory(\n originalFactory: <\n TParamsInput extends AnyParamsInput<NonNullable<T['params']>>,\n >(\n params: TParamsInput extends ExtensionBlueprintDefineParams\n ? TParamsInput\n : T['params'] extends ExtensionBlueprintDefineParams\n ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `originalFactory(defineParams => defineParams(<params>))`'\n : T['params'],\n context?: {\n config?: T['config'];\n inputs?: ResolveInputValueOverrides<NonNullable<T['inputs']>>;\n },\n ) => ExtensionDataContainer<NonNullable<T['output']>>,\n context: {\n node: AppNode;\n apis: ApiHolder;\n config: T['config'] & {\n [key in keyof TExtensionConfigSchema]: z.infer<\n ReturnType<TExtensionConfigSchema[key]>\n >;\n };\n inputs: Expand<ResolvedExtensionInputs<T['inputs'] & TExtraInputs>>;\n },\n ): Iterable<UFactoryOutput> &\n VerifyExtensionFactoryOutput<\n ExtensionDataRef extends UNewOutput\n ? NonNullable<T['output']>\n : UNewOutput,\n UFactoryOutput\n >;\n }): ExtensionDefinition<{\n config: (string extends keyof TExtensionConfigSchema\n ? {}\n : {\n [key in keyof TExtensionConfigSchema]: z.infer<\n ReturnType<TExtensionConfigSchema[key]>\n >;\n }) &\n T['config'];\n configInput: (string extends keyof TExtensionConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TExtensionConfigSchema]: ReturnType<\n TExtensionConfigSchema[key]\n >;\n }>\n >) &\n T['configInput'];\n output: ExtensionDataRef extends UNewOutput ? T['output'] : UNewOutput;\n inputs: T['inputs'] & TExtraInputs;\n kind: T['kind'];\n name: string | undefined extends TName ? undefined : TName;\n params: T['params'];\n }>;\n}\n\nfunction unwrapParamsFactory<TParams extends object>(\n // Allow `Function` because `typeof <object> === 'function'` allows it, but in practice this should always be a param factory\n params: ParamsFactory<ExtensionBlueprintDefineParams> | Function,\n defineParams: ExtensionBlueprintDefineParams,\n kind: string,\n): TParams {\n const paramDefinition = (\n params as ParamsFactory<ExtensionBlueprintDefineParams>\n )(defineParams);\n try {\n return OpaqueBlueprintParams.toInternal(paramDefinition).params as TParams;\n } catch (e) {\n throw new TypeError(\n `Invalid invocation of blueprint with kind '${kind}', the parameter definition callback function did not return a valid parameter definition object; Caused by: ${e.message}`,\n );\n }\n}\n\nfunction unwrapParams<TParams extends object>(\n params: object | ParamsFactory<ExtensionBlueprintDefineParams> | string,\n ctx: { node: AppNode; [ctxParamsSymbol]?: any },\n defineParams: ExtensionBlueprintDefineParams | undefined,\n kind: string,\n): TParams {\n const overrideParams = ctx[ctxParamsSymbol] as\n | object\n | ParamsFactory<ExtensionBlueprintDefineParams>\n | undefined;\n\n if (defineParams) {\n if (overrideParams) {\n if (typeof overrideParams !== 'function') {\n throw new TypeError(\n `Invalid extension override of blueprint with kind '${kind}', the override params were passed as a plain object, but this blueprint requires them to be passed in callback form`,\n );\n }\n return unwrapParamsFactory(overrideParams, defineParams, kind);\n }\n\n if (typeof params !== 'function') {\n throw new TypeError(\n `Invalid invocation of blueprint with kind '${kind}', the parameters where passed as a plain object, but this blueprint requires them to be passed in callback form`,\n );\n }\n return unwrapParamsFactory(params, defineParams, kind);\n }\n\n const base =\n typeof params === 'function'\n ? unwrapParamsFactory<TParams>(\n params,\n createExtensionBlueprintParams,\n kind,\n )\n : (params as TParams);\n const overrides =\n typeof overrideParams === 'function'\n ? unwrapParamsFactory<TParams>(\n overrideParams,\n createExtensionBlueprintParams,\n kind,\n )\n : (overrideParams as Partial<TParams>);\n\n return {\n ...base,\n ...overrides,\n };\n}\n\n/**\n * A simpler replacement for wrapping up `createExtension` inside a kind or type. This allows for a cleaner API for creating\n * types and instances of those types.\n *\n * @public\n */\nexport function createExtensionBlueprint<\n TParams extends object | ExtensionBlueprintDefineParams,\n UOutput extends ExtensionDataRef,\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n TConfigSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n TKind extends string,\n TDataRefs extends { [name in string]: ExtensionDataRef } = never,\n>(\n options: CreateExtensionBlueprintOptions<\n TKind,\n TParams,\n UOutput,\n TInputs,\n TConfigSchema,\n UFactoryOutput,\n TDataRefs\n >,\n): ExtensionBlueprint<{\n kind: TKind;\n params: TParams;\n // This inference and remapping back to ExtensionDataRef eliminates any occurrences ConfigurationExtensionDataRef\n output: UOutput extends ExtensionDataRef<\n infer IData,\n infer IId,\n infer IConfig\n >\n ? ExtensionDataRef<IData, IId, IConfig>\n : never;\n inputs: string extends keyof TInputs ? {} : TInputs;\n config: string extends keyof TConfigSchema\n ? {}\n : { [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>> };\n configInput: string extends keyof TConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;\n }>\n >;\n dataRefs: TDataRefs;\n}> {\n const defineParams = options.defineParams as\n | ExtensionBlueprintDefineParams\n | undefined;\n\n return {\n dataRefs: options.dataRefs,\n make(args) {\n return createExtension({\n kind: options.kind,\n name: args.name,\n attachTo: args.attachTo ?? options.attachTo,\n disabled: args.disabled ?? options.disabled,\n inputs: options.inputs,\n output: options.output as ExtensionDataRef[],\n config: options.config,\n factory: ctx =>\n options.factory(\n unwrapParams(args.params, ctx, defineParams, options.kind),\n ctx,\n ) as Iterable<ExtensionDataValue<any, any>>,\n }) as ExtensionDefinition;\n },\n makeWithOverrides(args) {\n return createExtension({\n kind: options.kind,\n name: args.name,\n attachTo: args.attachTo ?? options.attachTo,\n disabled: args.disabled ?? options.disabled,\n inputs: { ...args.inputs, ...options.inputs },\n output: (args.output ?? options.output) as ExtensionDataRef[],\n config:\n options.config || args.config\n ? {\n schema: {\n ...options.config?.schema,\n ...args.config?.schema,\n },\n }\n : undefined,\n factory: ctx => {\n const { node, config, inputs, apis } = ctx;\n return args.factory(\n (innerParams, innerContext) => {\n return createExtensionDataContainer<\n UOutput extends ExtensionDataRef<\n infer IData,\n infer IId,\n infer IConfig\n >\n ? ExtensionDataRef<IData, IId, IConfig>\n : never\n >(\n options.factory(\n unwrapParams(innerParams, ctx, defineParams, options.kind),\n {\n apis,\n node,\n config: (innerContext?.config ?? config) as any,\n inputs: resolveInputOverrides(\n options.inputs,\n inputs,\n innerContext?.inputs,\n ) as any,\n },\n ) as Iterable<any>,\n options.output,\n );\n },\n {\n apis,\n node,\n config: config as any,\n inputs: inputs as any,\n },\n ) as Iterable<ExtensionDataValue<any, any>>;\n },\n }) as ExtensionDefinition;\n },\n } as ExtensionBlueprint<{\n kind: TKind;\n params: TParams;\n output: any;\n inputs: string extends keyof TInputs ? {} : TInputs;\n config: string extends keyof TConfigSchema\n ? {}\n : {\n [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;\n };\n configInput: string extends keyof TConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;\n }>\n >;\n dataRefs: TDataRefs;\n }>;\n}\n"],"names":[],"mappings":";;;;;AAuEA,MAAM,qBAAA,GAAwB,WAAW,MAMtC,CAAA;AAAA,EACD,IAAM,EAAA,4BAAA;AAAA,EACN,QAAA,EAAU,CAAC,IAAI;AACjB,CAAC,CAAA;AAWM,SAAS,+BACd,MAC6B,EAAA;AAC7B,EAAA,OAAO,sBAAsB,cAAe,CAAA,IAAA,EAAM,EAAE,CAAG,EAAA,IAAA,EAAa,QAA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,MACnB,GAAA;AAAA,UACE,MAAQ,EAAA;AAAA,YACN,GAAG,QAAQ,MAAQ,EAAA,MAAA;AAAA,YACnB,GAAG,KAAK,MAAQ,EAAA;AAAA;AAClB,SAEF,GAAA,KAAA,CAAA;AAAA,QACN,SAAS,CAAO,GAAA,KAAA;AACd,UAAA,MAAM,EAAE,IAAA,EAAM,MAAQ,EAAA,MAAA,EAAQ,MAAS,GAAA,GAAA;AACvC,UAAA,OAAO,IAAK,CAAA,OAAA;AAAA,YACV,CAAC,aAAa,YAAiB,KAAA;AAC7B,cAAO,OAAA,4BAAA;AAAA,gBASL,OAAQ,CAAA,OAAA;AAAA,kBACN,YAAa,CAAA,WAAA,EAAa,GAAK,EAAA,YAAA,EAAc,QAAQ,IAAI,CAAA;AAAA,kBACzD;AAAA,oBACE,IAAA;AAAA,oBACA,IAAA;AAAA,oBACA,MAAA,EAAS,cAAc,MAAU,IAAA,MAAA;AAAA,oBACjC,MAAQ,EAAA,qBAAA;AAAA,sBACN,OAAQ,CAAA,MAAA;AAAA,sBACR,MAAA;AAAA,sBACA,YAAc,EAAA;AAAA;AAChB;AACF,iBACF;AAAA,gBACA,OAAQ,CAAA;AAAA,eACV;AAAA,aACF;AAAA,YACA;AAAA,cACE,IAAA;AAAA,cACA,IAAA;AAAA,cACA,MAAA;AAAA,cACA;AAAA;AACF,WACF;AAAA;AACF,OACD,CAAA;AAAA;AACH,GACF;AAmBF;;;;"}
1
+ {"version":3,"file":"createExtensionBlueprint.esm.js","sources":["../../src/wiring/createExtensionBlueprint.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { ApiHolder, AppNode } from '../apis';\nimport { Expand } from '@backstage/types';\nimport { OpaqueType } from '@internal/opaque';\nimport {\n ExtensionAttachToSpec,\n ExtensionDefinition,\n ResolvedExtensionInputs,\n VerifyExtensionFactoryOutput,\n createExtension,\n ctxParamsSymbol,\n} from './createExtension';\nimport { z } from 'zod';\nimport { ExtensionInput } from './createExtensionInput';\nimport { ExtensionDataRef, ExtensionDataValue } from './createExtensionDataRef';\nimport { createExtensionDataContainer } from '@internal/frontend';\nimport {\n ResolvedInputValueOverrides,\n resolveInputOverrides,\n} from './resolveInputOverrides';\nimport { ExtensionDataContainer } from './types';\nimport { PageBlueprint } from '../blueprints/PageBlueprint';\n\n/**\n * A function used to define a parameter mapping function in order to facilitate\n * advanced parameter typing for extension blueprints.\n *\n * @remarks\n *\n * This function is primarily intended to enable the use of inferred type\n * parameters for blueprint params, but it can also be used to transoform the\n * params before they are handed ot the blueprint.\n *\n * The function must return an object created with\n * {@link createExtensionBlueprintParams}.\n *\n * @public\n */\nexport type ExtensionBlueprintDefineParams<\n TParams extends object = object,\n TInput = any,\n> = (params: TInput) => ExtensionBlueprintParams<TParams>;\n\n/**\n * An opaque type that represents a set of parameters to be passed to a blueprint.\n *\n * @remarks\n *\n * Created with {@link createExtensionBlueprintParams}.\n *\n * @public\n */\nexport type ExtensionBlueprintParams<T extends object = object> = {\n $$type: '@backstage/BlueprintParams';\n T: T;\n};\n\nconst OpaqueBlueprintParams = OpaqueType.create<{\n public: ExtensionBlueprintParams;\n versions: {\n version: 'v1';\n params: object;\n };\n}>({\n type: '@backstage/BlueprintParams',\n versions: ['v1'],\n});\n\n/**\n * Wraps a plain blueprint parameter object in an opaque {@link ExtensionBlueprintParams} object.\n *\n * This is used in the definition of the `defineParams` option of {@link ExtensionBlueprint}.\n *\n * @public\n * @param params - The plain blueprint parameter object to wrap.\n * @returns The wrapped blueprint parameter object.\n */\nexport function createExtensionBlueprintParams<T extends object = object>(\n params: T,\n): ExtensionBlueprintParams<T> {\n return OpaqueBlueprintParams.createInstance('v1', { T: null as any, params });\n}\n\n/**\n * @public\n */\nexport type CreateExtensionBlueprintOptions<\n TKind extends string,\n TParams extends object | ExtensionBlueprintDefineParams,\n UOutput extends ExtensionDataRef,\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n TConfigSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n TDataRefs extends { [name in string]: ExtensionDataRef },\n> = {\n kind: TKind;\n attachTo: ExtensionAttachToSpec;\n disabled?: boolean;\n inputs?: TInputs;\n output: Array<UOutput>;\n config?: {\n schema: TConfigSchema;\n };\n /**\n * This option is used to further refine the blueprint params. When this\n * option is used, the blueprint will require params to be passed in callback\n * form. This function can both transform the params before they are handed to\n * the blueprint factory, but importantly it also allows you to define\n * inferred type parameters for your blueprint params.\n *\n * @example\n * Blueprint definition with inferred type parameters:\n * ```ts\n * const ExampleBlueprint = createExtensionBlueprint({\n * kind: 'example',\n * attachTo: { id: 'example', input: 'example' },\n * output: [exampleComponentDataRef, exampleFetcherDataRef],\n * defineParams<T>(params: {\n * component(props: ExampleProps<T>): JSX.Element | null\n * fetcher(options: FetchOptions): Promise<FetchResult<T>>\n * }) {\n * return createExtensionBlueprintParams(params);\n * },\n * *factory(params) {\n * yield exampleComponentDataRef(params.component)\n * yield exampleFetcherDataRef(params.fetcher)\n * },\n * });\n * ```\n *\n * @example\n * Usage of the above example blueprint:\n * ```ts\n * const example = ExampleBlueprint.make({\n * params: defineParams => defineParams({\n * component: ...,\n * fetcher: ...,\n * }),\n * });\n * ```\n */\n defineParams?: TParams extends ExtensionBlueprintDefineParams\n ? TParams\n : 'The defineParams option must be a function if provided, see the docs for details';\n factory(\n params: TParams extends ExtensionBlueprintDefineParams\n ? ReturnType<TParams>['T']\n : TParams,\n context: {\n node: AppNode;\n apis: ApiHolder;\n config: {\n [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;\n };\n inputs: Expand<ResolvedExtensionInputs<TInputs>>;\n },\n ): Iterable<UFactoryOutput>;\n\n dataRefs?: TDataRefs;\n} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>;\n\n/** @public */\nexport type ExtensionBlueprintParameters = {\n kind: string;\n params?: object | ExtensionBlueprintDefineParams;\n configInput?: { [K in string]: any };\n config?: { [K in string]: any };\n output?: ExtensionDataRef;\n inputs?: {\n [KName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n };\n dataRefs?: { [name in string]: ExtensionDataRef };\n};\n\n/** @ignore */\ntype ParamsFactory<TDefiner extends ExtensionBlueprintDefineParams> = (\n defineParams: TDefiner,\n) => ReturnType<TDefiner>;\n\n/**\n * Represents any form of params input that can be passed to a blueprint.\n * This also includes the invalid form of passing a plain params object to a blueprint that uses a definition callback.\n *\n * @ignore\n */\ntype AnyParamsInput<TParams extends object | ExtensionBlueprintDefineParams> =\n TParams extends ExtensionBlueprintDefineParams<infer IParams>\n ? IParams | ParamsFactory<TParams>\n : TParams | ParamsFactory<ExtensionBlueprintDefineParams<TParams, TParams>>;\n\n/**\n * @public\n */\nexport interface ExtensionBlueprint<\n T extends ExtensionBlueprintParameters = ExtensionBlueprintParameters,\n> {\n dataRefs: T['dataRefs'];\n\n make<\n TName extends string | undefined,\n TParamsInput extends AnyParamsInput<NonNullable<T['params']>>,\n >(args: {\n name?: TName;\n attachTo?: ExtensionAttachToSpec;\n disabled?: boolean;\n params: TParamsInput extends ExtensionBlueprintDefineParams\n ? TParamsInput\n : T['params'] extends ExtensionBlueprintDefineParams\n ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `<blueprint>.make({ params: defineParams => defineParams(<params>) })`'\n : T['params'];\n }): ExtensionDefinition<{\n kind: T['kind'];\n name: string | undefined extends TName ? undefined : TName;\n config: T['config'];\n configInput: T['configInput'];\n output: T['output'];\n inputs: T['inputs'];\n params: T['params'];\n }>;\n\n /**\n * Creates a new extension from the blueprint.\n *\n * You must either pass `params` directly, or define a `factory` that can\n * optionally call the original factory with the same params.\n */\n makeWithOverrides<\n TName extends string | undefined,\n TExtensionConfigSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n UNewOutput extends ExtensionDataRef,\n TExtraInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n >(args: {\n name?: TName;\n attachTo?: ExtensionAttachToSpec;\n disabled?: boolean;\n inputs?: TExtraInputs & {\n [KName in keyof T['inputs']]?: `Error: Input '${KName &\n string}' is already defined in parent definition`;\n };\n output?: Array<UNewOutput>;\n config?: {\n schema: TExtensionConfigSchema & {\n [KName in keyof T['config']]?: `Error: Config key '${KName &\n string}' is already defined in parent schema`;\n };\n };\n factory(\n originalFactory: <\n TParamsInput extends AnyParamsInput<NonNullable<T['params']>>,\n >(\n params: TParamsInput extends ExtensionBlueprintDefineParams\n ? TParamsInput\n : T['params'] extends ExtensionBlueprintDefineParams\n ? 'Error: This blueprint uses advanced parameter types and requires you to pass parameters as using the following callback syntax: `originalFactory(defineParams => defineParams(<params>))`'\n : T['params'],\n context?: {\n config?: T['config'];\n inputs?: ResolvedInputValueOverrides<NonNullable<T['inputs']>>;\n },\n ) => ExtensionDataContainer<NonNullable<T['output']>>,\n context: {\n node: AppNode;\n apis: ApiHolder;\n config: T['config'] & {\n [key in keyof TExtensionConfigSchema]: z.infer<\n ReturnType<TExtensionConfigSchema[key]>\n >;\n };\n inputs: Expand<ResolvedExtensionInputs<T['inputs'] & TExtraInputs>>;\n },\n ): Iterable<UFactoryOutput> &\n VerifyExtensionFactoryOutput<\n ExtensionDataRef extends UNewOutput\n ? NonNullable<T['output']>\n : UNewOutput,\n UFactoryOutput\n >;\n }): ExtensionDefinition<{\n config: (string extends keyof TExtensionConfigSchema\n ? {}\n : {\n [key in keyof TExtensionConfigSchema]: z.infer<\n ReturnType<TExtensionConfigSchema[key]>\n >;\n }) &\n T['config'];\n configInput: (string extends keyof TExtensionConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TExtensionConfigSchema]: ReturnType<\n TExtensionConfigSchema[key]\n >;\n }>\n >) &\n T['configInput'];\n output: ExtensionDataRef extends UNewOutput ? T['output'] : UNewOutput;\n inputs: T['inputs'] & TExtraInputs;\n kind: T['kind'];\n name: string | undefined extends TName ? undefined : TName;\n params: T['params'];\n }>;\n}\n\nfunction unwrapParamsFactory<TParams extends object>(\n // Allow `Function` because `typeof <object> === 'function'` allows it, but in practice this should always be a param factory\n params: ParamsFactory<ExtensionBlueprintDefineParams> | Function,\n defineParams: ExtensionBlueprintDefineParams,\n kind: string,\n): TParams {\n const paramDefinition = (\n params as ParamsFactory<ExtensionBlueprintDefineParams>\n )(defineParams);\n try {\n return OpaqueBlueprintParams.toInternal(paramDefinition).params as TParams;\n } catch (e) {\n throw new TypeError(\n `Invalid invocation of blueprint with kind '${kind}', the parameter definition callback function did not return a valid parameter definition object; Caused by: ${e.message}`,\n );\n }\n}\n\nfunction unwrapParams<TParams extends object>(\n params: object | ParamsFactory<ExtensionBlueprintDefineParams> | string,\n ctx: { node: AppNode; [ctxParamsSymbol]?: any },\n defineParams: ExtensionBlueprintDefineParams | undefined,\n kind: string,\n): TParams {\n const overrideParams = ctx[ctxParamsSymbol] as\n | object\n | ParamsFactory<ExtensionBlueprintDefineParams>\n | undefined;\n\n if (defineParams) {\n if (overrideParams) {\n if (typeof overrideParams !== 'function') {\n throw new TypeError(\n `Invalid extension override of blueprint with kind '${kind}', the override params were passed as a plain object, but this blueprint requires them to be passed in callback form`,\n );\n }\n return unwrapParamsFactory(overrideParams, defineParams, kind);\n }\n\n if (typeof params !== 'function') {\n throw new TypeError(\n `Invalid invocation of blueprint with kind '${kind}', the parameters where passed as a plain object, but this blueprint requires them to be passed in callback form`,\n );\n }\n return unwrapParamsFactory(params, defineParams, kind);\n }\n\n const base =\n typeof params === 'function'\n ? unwrapParamsFactory<TParams>(\n params,\n createExtensionBlueprintParams,\n kind,\n )\n : (params as TParams);\n const overrides =\n typeof overrideParams === 'function'\n ? unwrapParamsFactory<TParams>(\n overrideParams,\n createExtensionBlueprintParams,\n kind,\n )\n : (overrideParams as Partial<TParams>);\n\n return {\n ...base,\n ...overrides,\n };\n}\n\n/**\n * Creates a new extension blueprint that encapsulates the creation of\n * extensions of particular kinds.\n *\n * @remarks\n *\n * For details on how blueprints work, see the\n * {@link https://backstage.io/docs/frontend-system/architecture/extension-blueprints | documentation for extension blueprints}\n * in the frontend system documentation.\n *\n * Extension blueprints make it much easier for users to create new extensions\n * for your plugin. Rather than letting them use {@link createExtension}\n * directly, you can define a set of parameters and default factory for your\n * blueprint, removing a lot of the boilerplate and complexity that is otherwise\n * needed to create an extension.\n *\n * Each blueprint has its own `kind` that helps identify and group the\n * extensions that have been created with it. For example the\n * {@link PageBlueprint} has the kind `'page'`, and extensions created with it\n * will be given the ID `'page:<plugin-id>[/<name>]'`. Blueprints should always\n * be exported as `<PascalCaseKind>Blueprint`.\n *\n * When creating a blueprint the type of the parameters are inferred from the\n * `factory` function that you provide. The exception to that is when you need\n * your blueprint to include inferred type parameters, in which case you need to\n * use the `defineParams` option. See the documentation for the `defineParams`\n * option for more details on how that works.\n *\n * @example\n * ```tsx\n * // In your plugin library\n * export const GreetingBlueprint = createExtensionBlueprint({\n * kind: 'greeting',\n * attachTo: { id: 'example', input: 'greetings' },\n * output: [coreExtensionData.reactElement],\n * factory(params: { greeting: string }) {\n * return [coreExtensionData.reactElement(<h1>{params.greeting}</h1>)];\n * },\n * });\n *\n * // Someone using your blueprint in their plugin\n * const exampleGreeting = GreetingBlueprint.make({\n * params: {\n * greeting: 'Hello, world!',\n * },\n * });\n * ```\n * @public\n */\nexport function createExtensionBlueprint<\n TParams extends object | ExtensionBlueprintDefineParams,\n UOutput extends ExtensionDataRef,\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n TConfigSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n UFactoryOutput extends ExtensionDataValue<any, any>,\n TKind extends string,\n TDataRefs extends { [name in string]: ExtensionDataRef } = never,\n>(\n options: CreateExtensionBlueprintOptions<\n TKind,\n TParams,\n UOutput,\n TInputs,\n TConfigSchema,\n UFactoryOutput,\n TDataRefs\n >,\n): ExtensionBlueprint<{\n kind: TKind;\n params: TParams;\n // This inference and remapping back to ExtensionDataRef eliminates any occurrences ConfigurationExtensionDataRef\n output: UOutput extends ExtensionDataRef<\n infer IData,\n infer IId,\n infer IConfig\n >\n ? ExtensionDataRef<IData, IId, IConfig>\n : never;\n inputs: string extends keyof TInputs ? {} : TInputs;\n config: string extends keyof TConfigSchema\n ? {}\n : { [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>> };\n configInput: string extends keyof TConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;\n }>\n >;\n dataRefs: TDataRefs;\n}> {\n const defineParams = options.defineParams as\n | ExtensionBlueprintDefineParams\n | undefined;\n\n return {\n dataRefs: options.dataRefs,\n make(args) {\n return createExtension({\n kind: options.kind,\n name: args.name,\n attachTo: args.attachTo ?? options.attachTo,\n disabled: args.disabled ?? options.disabled,\n inputs: options.inputs,\n output: options.output as ExtensionDataRef[],\n config: options.config,\n factory: ctx =>\n options.factory(\n unwrapParams(args.params, ctx, defineParams, options.kind),\n ctx,\n ) as Iterable<ExtensionDataValue<any, any>>,\n }) as ExtensionDefinition;\n },\n makeWithOverrides(args) {\n return createExtension({\n kind: options.kind,\n name: args.name,\n attachTo: args.attachTo ?? options.attachTo,\n disabled: args.disabled ?? options.disabled,\n inputs: { ...args.inputs, ...options.inputs },\n output: (args.output ?? options.output) as ExtensionDataRef[],\n config:\n options.config || args.config\n ? {\n schema: {\n ...options.config?.schema,\n ...args.config?.schema,\n },\n }\n : undefined,\n factory: ctx => {\n const { node, config, inputs, apis } = ctx;\n return args.factory(\n (innerParams, innerContext) => {\n return createExtensionDataContainer<\n UOutput extends ExtensionDataRef<\n infer IData,\n infer IId,\n infer IConfig\n >\n ? ExtensionDataRef<IData, IId, IConfig>\n : never\n >(\n options.factory(\n unwrapParams(innerParams, ctx, defineParams, options.kind),\n {\n apis,\n node,\n config: (innerContext?.config ?? config) as any,\n inputs: resolveInputOverrides(\n options.inputs,\n inputs,\n innerContext?.inputs,\n ) as any,\n },\n ) as Iterable<any>,\n 'original blueprint factory',\n options.output,\n );\n },\n {\n apis,\n node,\n config: config as any,\n inputs: inputs as any,\n },\n ) as Iterable<ExtensionDataValue<any, any>>;\n },\n }) as ExtensionDefinition;\n },\n } as ExtensionBlueprint<{\n kind: TKind;\n params: TParams;\n output: any;\n inputs: string extends keyof TInputs ? {} : TInputs;\n config: string extends keyof TConfigSchema\n ? {}\n : {\n [key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;\n };\n configInput: string extends keyof TConfigSchema\n ? {}\n : z.input<\n z.ZodObject<{\n [key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;\n }>\n >;\n dataRefs: TDataRefs;\n }>;\n}\n"],"names":[],"mappings":";;;;;AAwEA,MAAM,qBAAA,GAAwB,WAAW,MAMtC,CAAA;AAAA,EACD,IAAM,EAAA,4BAAA;AAAA,EACN,QAAA,EAAU,CAAC,IAAI;AACjB,CAAC,CAAA;AAWM,SAAS,+BACd,MAC6B,EAAA;AAC7B,EAAA,OAAO,sBAAsB,cAAe,CAAA,IAAA,EAAM,EAAE,CAAG,EAAA,IAAA,EAAa,QAAQ,CAAA;AAC9E;AA+OA,SAAS,mBAAA,CAEP,MACA,EAAA,YAAA,EACA,IACS,EAAA;AACT,EAAM,MAAA,eAAA,GACJ,OACA,YAAY,CAAA;AACd,EAAI,IAAA;AACF,IAAO,OAAA,q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AAA,QACN,SAAS,CAAO,GAAA,KAAA;AACd,UAAA,MAAM,EAAE,IAAA,EAAM,MAAQ,EAAA,MAAA,EAAQ,MAAS,GAAA,GAAA;AACvC,UAAA,OAAO,IAAK,CAAA,OAAA;AAAA,YACV,CAAC,aAAa,YAAiB,KAAA;AAC7B,cAAO,OAAA,4BAAA;AAAA,gBASL,OAAQ,CAAA,OAAA;AAAA,kBACN,YAAa,CAAA,WAAA,EAAa,GAAK,EAAA,YAAA,EAAc,QAAQ,IAAI,CAAA;AAAA,kBACzD;AAAA,oBACE,IAAA;AAAA,oBACA,IAAA;AAAA,oBACA,MAAA,EAAS,cAAc,MAAU,IAAA,MAAA;AAAA,oBACjC,MAAQ,EAAA,qBAAA;AAAA,sBACN,OAAQ,CAAA,MAAA;AAAA,sBACR,MAAA;AAAA,sBACA,YAAc,EAAA;AAAA;AAChB;AACF,iBACF;AAAA,gBACA,4BAAA;AAAA,gBACA,OAAQ,CAAA;AAAA,eACV;AAAA,aACF;AAAA,YACA;AAAA,cACE,IAAA;AAAA,cACA,IAAA;AAAA,cACA,MAAA;AAAA,cACA;AAAA;AACF,WACF;AAAA;AACF,OACD,CAAA;AAAA;AACH,GACF;AAmBF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFrontendModule.esm.js","sources":["../../src/wiring/createFrontendModule.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 { OpaqueExtensionDefinition } from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { FeatureFlagConfig } from './types';\n\n/** @public */\nexport interface CreateFrontendModuleOptions<\n TPluginId extends string,\n TExtensions extends readonly ExtensionDefinition[],\n> {\n pluginId: TPluginId;\n extensions?: TExtensions;\n featureFlags?: FeatureFlagConfig[];\n}\n\n/** @public */\nexport interface FrontendModule {\n readonly $$type: '@backstage/FrontendModule';\n readonly pluginId: string;\n}\n\n/** @internal */\nexport interface InternalFrontendModule extends FrontendModule {\n readonly version: 'v1';\n readonly extensions: Extension<unknown>[];\n readonly featureFlags: FeatureFlagConfig[];\n}\n\n/** @public */\nexport function createFrontendModule<\n TId extends string,\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(options: CreateFrontendModuleOptions<TId, TExtensions>): FrontendModule {\n const { pluginId } = options;\n\n const extensions = new Array<Extension<any>>();\n const extensionDefinitionsById = new Map<\n string,\n typeof OpaqueExtensionDefinition.TInternal\n >();\n\n for (const def of options.extensions ?? []) {\n const internal = OpaqueExtensionDefinition.toInternal(def);\n const ext = resolveExtensionDefinition(def, { namespace: pluginId });\n extensions.push(ext);\n extensionDefinitionsById.set(ext.id, {\n ...internal,\n namespace: pluginId,\n });\n }\n\n if (extensions.length !== extensionDefinitionsById.size) {\n const extensionIds = extensions.map(e => e.id);\n const duplicates = Array.from(\n new Set(\n extensionIds.filter((id, index) => extensionIds.indexOf(id) !== index),\n ),\n );\n // TODO(Rugvip): This could provide some more information about the kind + name of the extensions\n throw new Error(\n `Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(\n ', ',\n )}`,\n );\n }\n\n return {\n $$type: '@backstage/FrontendModule',\n version: 'v1',\n pluginId,\n featureFlags: options.featureFlags ?? [],\n extensions,\n toString() {\n return `Module{pluginId=${pluginId}}`;\n },\n } as InternalFrontendModule;\n}\n\n/** @internal */\nexport function isInternalFrontendModule(opaque: {\n $$type: string;\n}): opaque is InternalFrontendModule {\n if (opaque.$$type === '@backstage/FrontendModule') {\n // Make sure we throw if invalid\n toInternalFrontendModule(opaque as FrontendModule);\n return true;\n }\n return false;\n}\n\n/** @internal */\nexport function toInternalFrontendModule(\n plugin: FrontendModule,\n): InternalFrontendModule {\n const internal = plugin as InternalFrontendModule;\n if (internal.$$type !== '@backstage/FrontendModule') {\n throw new Error(`Invalid plugin instance, bad type '${internal.$$type}'`);\n }\n if (internal.version !== 'v1') {\n throw new Error(\n `Invalid plugin instance, bad version '${internal.version}'`,\n );\n }\n return internal;\n}\n"],"names":[],"mappings":";;;AAgDO,SAAS,qBAGd,OAAwE,EAAA;AACxE,EAAM,MAAA,EAAE,UAAa,GAAA,OAAA;AAErB,EAAM,MAAA,UAAA,GAAa,IAAI,KAAsB,EAAA;AAC7C,EAAM,MAAA,wBAAA,uBAA+B,GAGnC,EAAA;AAEF,EAAA,KAAA,MAAW,GAAO,IAAA,OAAA,CAAQ,UAAc,IAAA,EAAI,EAAA;AAC1C,IAAM,MAAA,QAAA,GAAW,yBAA0B,CAAA,UAAA,CAAW,GAAG,CAAA;AACzD,IAAA,MAAM,MAAM,0BAA2B,CAAA,GAAA,EAAK,EAAE,SAAA,EAAW,UAAU,CAAA;AACnE,IAAA,UAAA,CAAW,KAAK,GAAG,CAAA;AACnB,IAAyB,wBAAA,CAAA,GAAA,CAAI,IAAI,EAAI,EAAA;AAAA,MACnC,GAAG,QAAA;AAAA,MACH,SAAW,EAAA;AAAA,KACZ,CAAA;AAAA;AAGH,EAAI,IAAA,UAAA,CAAW,MAAW,KAAA,wBAAA,CAAyB,IAAM,EAAA;AACvD,IAAA,MAAM,YAAe,GAAA,UAAA,CAAW,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,EAAE,CAAA;AAC7C,IAAA,MAAM,aAAa,KAAM,CAAA,IAAA;AAAA,MACvB,IAAI,GAAA;AAAA,QACF,YAAA,CAAa,OAAO,CAAC,EAAA,EAAI,UAAU,YAAa,CAAA,OAAA,CAAQ,EAAE,CAAA,KAAM,KAAK;AAAA;AACvE,KACF;AAEA,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,QAAQ,CAAA,iCAAA,EAAoC,UAAW,CAAA,IAAA;AAAA,QAChE;AAAA,OACD,CAAA;AAAA,KACH;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,MAAQ,EAAA,2BAAA;AAAA,IACR,OAAS,EAAA,IAAA;AAAA,IACT,QAAA;AAAA,IACA,YAAA,EAAc,OAAQ,CAAA,YAAA,IAAgB,EAAC;AAAA,IACvC,UAAA;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,mBAAmB,QAAQ,CAAA,CAAA,CAAA;AAAA;AACpC,GACF;AACF;;;;"}
1
+ {"version":3,"file":"createFrontendModule.esm.js","sources":["../../src/wiring/createFrontendModule.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 { OpaqueExtensionDefinition } from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { FeatureFlagConfig } from './types';\n\n/** @public */\nexport interface CreateFrontendModuleOptions<\n TPluginId extends string,\n TExtensions extends readonly ExtensionDefinition[],\n> {\n pluginId: TPluginId;\n extensions?: TExtensions;\n featureFlags?: FeatureFlagConfig[];\n}\n\n/** @public */\nexport interface FrontendModule {\n readonly $$type: '@backstage/FrontendModule';\n readonly pluginId: string;\n}\n\n/** @internal */\nexport interface InternalFrontendModule extends FrontendModule {\n readonly version: 'v1';\n readonly extensions: Extension<unknown>[];\n readonly featureFlags: FeatureFlagConfig[];\n}\n\n/**\n * Creates a new module that can be installed in a Backstage app.\n *\n * @remarks\n *\n * Modules are used to add or override extensions for an existing plugin. If a\n * module provides an extension with the same ID as one provided by the plugin,\n * the extension provided by the module will always take precedence.\n *\n * Every module is created for a specific plugin by providing the\n * unique ID of the plugin that the module should be installed for. If that\n * plugin is not present in the app, the module will be ignored and have no\n * effect.\n *\n * For more information on how modules work, see the\n * {@link https://backstage.io/docs/frontend-system/architecture/extension-overrides#creating-a-frontend-module | documentation for modules}\n * in the frontend system documentation.\n *\n * It is recommended to name the module variable of the form `<pluginId>Module<ModuleName>`.\n *\n * @example\n *\n * ```tsx\n * import { createFrontendModule } from '@backstage/frontend-plugin-api';\n *\n * export const exampleModuleCustomPage = createFrontendModule({\n * pluginId: 'example',\n * extensions: [\n * // Overrides the default page for the 'example' plugin\n * PageBlueprint.make({\n * path: '/example',\n * loader: () => import('./CustomPage').then(m => <m.CustomPage />),\n * }),\n * ],\n * });\n * ```\n *\n * @public\n */\nexport function createFrontendModule<\n TId extends string,\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(options: CreateFrontendModuleOptions<TId, TExtensions>): FrontendModule {\n const { pluginId } = options;\n\n const extensions = new Array<Extension<any>>();\n const extensionDefinitionsById = new Map<\n string,\n typeof OpaqueExtensionDefinition.TInternal\n >();\n\n for (const def of options.extensions ?? []) {\n const internal = OpaqueExtensionDefinition.toInternal(def);\n const ext = resolveExtensionDefinition(def, { namespace: pluginId });\n extensions.push(ext);\n extensionDefinitionsById.set(ext.id, {\n ...internal,\n namespace: pluginId,\n });\n }\n\n if (extensions.length !== extensionDefinitionsById.size) {\n const extensionIds = extensions.map(e => e.id);\n const duplicates = Array.from(\n new Set(\n extensionIds.filter((id, index) => extensionIds.indexOf(id) !== index),\n ),\n );\n // TODO(Rugvip): This could provide some more information about the kind + name of the extensions\n throw new Error(\n `Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(\n ', ',\n )}`,\n );\n }\n\n return {\n $$type: '@backstage/FrontendModule',\n version: 'v1',\n pluginId,\n featureFlags: options.featureFlags ?? [],\n extensions,\n toString() {\n return `Module{pluginId=${pluginId}}`;\n },\n } as InternalFrontendModule;\n}\n\n/** @internal */\nexport function isInternalFrontendModule(opaque: {\n $$type: string;\n}): opaque is InternalFrontendModule {\n if (opaque.$$type === '@backstage/FrontendModule') {\n // Make sure we throw if invalid\n toInternalFrontendModule(opaque as FrontendModule);\n return true;\n }\n return false;\n}\n\n/** @internal */\nexport function toInternalFrontendModule(\n plugin: FrontendModule,\n): InternalFrontendModule {\n const internal = plugin as InternalFrontendModule;\n if (internal.$$type !== '@backstage/FrontendModule') {\n throw new Error(`Invalid plugin instance, bad type '${internal.$$type}'`);\n }\n if (internal.version !== 'v1') {\n throw new Error(\n `Invalid plugin instance, bad version '${internal.version}'`,\n );\n }\n return internal;\n}\n"],"names":[],"mappings":";;;AAsFO,SAAS,qBAGd,OAAwE,EAAA;AACxE,EAAM,MAAA,EAAE,UAAa,GAAA,OAAA;AAErB,EAAM,MAAA,UAAA,GAAa,IAAI,KAAsB,EAAA;AAC7C,EAAM,MAAA,wBAAA,uBAA+B,GAGnC,EAAA;AAEF,EAAA,KAAA,MAAW,GAAO,IAAA,OAAA,CAAQ,UAAc,IAAA,EAAI,EAAA;AAC1C,IAAM,MAAA,QAAA,GAAW,yBAA0B,CAAA,UAAA,CAAW,GAAG,CAAA;AACzD,IAAA,MAAM,MAAM,0BAA2B,CAAA,GAAA,EAAK,EAAE,SAAA,EAAW,UAAU,CAAA;AACnE,IAAA,UAAA,CAAW,KAAK,GAAG,CAAA;AACnB,IAAyB,wBAAA,CAAA,GAAA,CAAI,IAAI,EAAI,EAAA;AAAA,MACnC,GAAG,QAAA;AAAA,MACH,SAAW,EAAA;AAAA,KACZ,CAAA;AAAA;AAGH,EAAI,IAAA,UAAA,CAAW,MAAW,KAAA,wBAAA,CAAyB,IAAM,EAAA;AACvD,IAAA,MAAM,YAAe,GAAA,UAAA,CAAW,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,EAAE,CAAA;AAC7C,IAAA,MAAM,aAAa,KAAM,CAAA,IAAA;AAAA,MACvB,IAAI,GAAA;AAAA,QACF,YAAA,CAAa,OAAO,CAAC,EAAA,EAAI,UAAU,YAAa,CAAA,OAAA,CAAQ,EAAE,CAAA,KAAM,KAAK;AAAA;AACvE,KACF;AAEA,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,QAAA,EAAW,QAAQ,CAAA,iCAAA,EAAoC,UAAW,CAAA,IAAA;AAAA,QAChE;AAAA,OACD,CAAA;AAAA,KACH;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,MAAQ,EAAA,2BAAA;AAAA,IACR,OAAS,EAAA,IAAA;AAAA,IACT,QAAA;AAAA,IACA,YAAA,EAAc,OAAQ,CAAA,YAAA,IAAgB,EAAC;AAAA,IACvC,UAAA;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,mBAAmB,QAAQ,CAAA,CAAA,CAAA;AAAA;AACpC,GACF;AACF;;;;"}
@@ -1,14 +1,10 @@
1
1
  import { resolveExtensionDefinition } from './resolveExtensionDefinition.esm.js';
2
2
  import { OpaqueFrontendPlugin } from '../frontend-internal/src/wiring/InternalFrontendPlugin.esm.js';
3
+ import '../frontend-internal/src/wiring/InternalSwappableComponentRef.esm.js';
3
4
  import { OpaqueExtensionDefinition } from '../frontend-internal/src/wiring/InternalExtensionDefinition.esm.js';
4
5
 
5
6
  function createFrontendPlugin(options) {
6
- const pluginId = "pluginId" in options ? options.pluginId : options.id;
7
- if (!pluginId) {
8
- throw new Error(
9
- "Either 'id' or 'pluginId' must be provided to createFrontendPlugin"
10
- );
11
- }
7
+ const pluginId = options.pluginId;
12
8
  const extensions = new Array();
13
9
  const extensionDefinitionsById = /* @__PURE__ */ new Map();
14
10
  for (const def of options.extensions ?? []) {
@@ -1 +1 @@
1
- {"version":3,"file":"createFrontendPlugin.esm.js","sources":["../../src/wiring/createFrontendPlugin.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 OpaqueExtensionDefinition,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { FeatureFlagConfig } from './types';\nimport { MakeSortedExtensionsMap } from './MakeSortedExtensionsMap';\nimport { JsonObject } from '@backstage/types';\nimport { RouteRef, SubRouteRef, ExternalRouteRef } from '../routing';\n\n/**\n * Information about the plugin.\n *\n * @public\n * @remarks\n *\n * This interface is intended to be extended via [module\n * augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)\n * in order to add fields that are specific to each project.\n *\n * For example, one might add a `slackChannel` field that is read from the\n * opaque manifest file.\n *\n * See the options for `createApp` for more information about how to\n * customize the parsing of manifest files.\n */\nexport interface FrontendPluginInfo {\n /**\n * The name of the package that implements the plugin.\n */\n packageName?: string;\n\n /**\n * The version of the plugin, typically the version of the package.json file.\n */\n version?: string;\n\n /**\n * As short description of the plugin, typically the description field in\n * package.json.\n */\n description?: string;\n\n /**\n * The owner entity references of the plugin.\n */\n ownerEntityRefs?: string[];\n\n /**\n * Links related to the plugin.\n */\n links?: Array<{ title: string; url: string }>;\n}\n\n/**\n * Options for providing information for a plugin.\n *\n * @public\n */\nexport type FrontendPluginInfoOptions = {\n /**\n * A loader function for the package.json file for the plugin.\n */\n packageJson?: () => Promise<{ name: string } & JsonObject>;\n /**\n * A loader function for an opaque manifest file for the plugin.\n */\n manifest?: () => Promise<JsonObject>;\n};\n\n/** @public */\nexport interface FrontendPlugin<\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {\n [name in string]: RouteRef | SubRouteRef;\n },\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {\n [name in string]: ExternalRouteRef;\n },\n TExtensionMap extends { [id in string]: ExtensionDefinition } = {\n [id in string]: ExtensionDefinition;\n },\n> {\n readonly $$type: '@backstage/FrontendPlugin';\n readonly id: string;\n readonly routes: TRoutes;\n readonly externalRoutes: TExternalRoutes;\n\n /**\n * Loads the plugin info.\n */\n info(): Promise<FrontendPluginInfo>;\n getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];\n withOverrides(options: {\n extensions: Array<ExtensionDefinition>;\n\n /**\n * Overrides the original info loaders of the plugin one by one.\n */\n info?: FrontendPluginInfoOptions;\n }): FrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;\n}\n\n/** @public */\nexport interface PluginOptions<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef },\n TExternalRoutes extends { [name in string]: ExternalRouteRef },\n TExtensions extends readonly ExtensionDefinition[],\n> {\n pluginId: TId;\n routes?: TRoutes;\n externalRoutes?: TExternalRoutes;\n extensions?: TExtensions;\n featureFlags?: FeatureFlagConfig[];\n info?: FrontendPluginInfoOptions;\n}\n\n/** @public */\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {},\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options: PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n>;\n/**\n * @public\n * @deprecated The `id` option is deprecated, use `pluginId` instead.\n */\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {},\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options: Omit<\n PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n 'pluginId'\n > & { id: string },\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n>;\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {},\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options:\n | PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>\n | (Omit<\n PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n 'pluginId'\n > & { id: string }),\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n> {\n const pluginId = 'pluginId' in options ? options.pluginId : options.id;\n if (!pluginId) {\n throw new Error(\n \"Either 'id' or 'pluginId' must be provided to createFrontendPlugin\",\n );\n }\n const extensions = new Array<Extension<any>>();\n const extensionDefinitionsById = new Map<\n string,\n typeof OpaqueExtensionDefinition.TInternal\n >();\n\n for (const def of options.extensions ?? []) {\n const internal = OpaqueExtensionDefinition.toInternal(def);\n const ext = resolveExtensionDefinition(def, { namespace: pluginId });\n extensions.push(ext);\n extensionDefinitionsById.set(ext.id, {\n ...internal,\n namespace: pluginId,\n });\n }\n\n if (extensions.length !== extensionDefinitionsById.size) {\n const extensionIds = extensions.map(e => e.id);\n const duplicates = Array.from(\n new Set(\n extensionIds.filter((id, index) => extensionIds.indexOf(id) !== index),\n ),\n );\n // TODO(Rugvip): This could provide some more information about the kind + name of the extensions\n throw new Error(\n `Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(\n ', ',\n )}`,\n );\n }\n\n return OpaqueFrontendPlugin.createInstance('v1', {\n id: pluginId,\n routes: options.routes ?? ({} as TRoutes),\n externalRoutes: options.externalRoutes ?? ({} as TExternalRoutes),\n featureFlags: options.featureFlags ?? [],\n extensions: extensions,\n infoOptions: options.info,\n\n // This method is overridden when the plugin instance is installed in an app\n async info() {\n throw new Error(\n `Attempted to load plugin info for plugin '${pluginId}', but the plugin instance is not installed in an app`,\n );\n },\n getExtension(id) {\n const ext = extensionDefinitionsById.get(id);\n if (!ext) {\n throw new Error(\n `Attempted to get non-existent extension '${id}' from plugin '${pluginId}'`,\n );\n }\n return ext;\n },\n toString() {\n return `Plugin{id=${pluginId}}`;\n },\n withOverrides(overrides) {\n const overriddenExtensionIds = new Set(\n overrides.extensions.map(\n e => resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n const nonOverriddenExtensions = (options.extensions ?? []).filter(\n e =>\n !overriddenExtensionIds.has(\n resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n return createFrontendPlugin({\n ...options,\n pluginId,\n extensions: [...nonOverriddenExtensions, ...overrides.extensions],\n info: {\n ...options.info,\n ...overrides.info,\n },\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;AAyKO,SAAS,qBAMd,OAUA,EAAA;AACA,EAAA,MAAM,QAAW,GAAA,UAAA,IAAc,OAAU,GAAA,OAAA,CAAQ,WAAW,OAAQ,CAAA,EAAA;AACpE,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAEF,EAAM,MAAA,UAAA,GAAa,IAAI,KAAsB,EAAA;AAC7C,EAAM,MAAA,wBAAA,uBAA+B,GAGnC,EAAA;AAEF,EAAA,KAAA,MAAW,GAAO,IAAA,OAAA,CAAQ,UAAc,IAAA,EAAI,EAAA;AAC1C,IAAM,MAAA,QAAA,GAAW,yBAA0B,CAAA,UAAA,CAAW,GAAG,CAAA;AACzD,IAAA,MAAM,MAAM,0BAA2B,CAAA,GAAA,EAAK,EAAE,SAAA,EAAW,UAAU,CAAA;AACnE,IAAA,UAAA,CAAW,KAAK,GAAG,CAAA;AACnB,IAAyB,wBAAA,CAAA,GAAA,CAAI,IAAI,EAAI,EAAA;AAAA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CAAA;AAAA,SAC1E;AAAA;AAEF,MAAO,OAAA,GAAA;AAAA,KACT;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,aAAa,QAAQ,CAAA,CAAA,CAAA;AAAA,KAC9B;AAAA,IACA,cAAc,SAAW,EAAA;AACvB,MAAA,MAAM,yBAAyB,IAAI,GAAA;AAAA,QACjC,UAAU,UAAW,CAAA,GAAA;AAAA,UACnB,OAAK,0BAA2B,CAAA,CAAA,EAAG,EAAE,SAAW,EAAA,QAAA,EAAU,CAAE,CAAA;AAAA;AAC9D,OACF;AACA,MAAA,MAAM,uBAA2B,GAAA,CAAA,OAAA,CAAQ,UAAc,IAAA,EAAI,EAAA,MAAA;AAAA,QACzD,CAAA,CAAA,KACE,CAAC,sBAAuB,CAAA,GAAA;AAAA,UACtB,2BAA2B,CAAG,EAAA,EAAE,SAAW,EAAA,QAAA,EAAU,CAAE,CAAA;AAAA;AACzD,OACJ;AACA,MAAA,OAAO,oBAAqB,CAAA;AAAA,QAC1B,GAAG,OAAA;AAAA,QACH,QAAA;AAAA,QACA,YAAY,CAAC,GAAG,uBAAyB,EAAA,GAAG,UAAU,UAAU,CAAA;AAAA,QAChE,IAAM,EAAA;AAAA,UACJ,GAAG,OAAQ,CAAA,IAAA;AAAA,UACX,GAAG,SAAU,CAAA;AAAA;AACf,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"createFrontendPlugin.esm.js","sources":["../../src/wiring/createFrontendPlugin.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 OpaqueExtensionDefinition,\n OpaqueFrontendPlugin,\n} from '@internal/frontend';\nimport { ExtensionDefinition } from './createExtension';\nimport {\n Extension,\n resolveExtensionDefinition,\n} from './resolveExtensionDefinition';\nimport { FeatureFlagConfig } from './types';\nimport { MakeSortedExtensionsMap } from './MakeSortedExtensionsMap';\nimport { JsonObject } from '@backstage/types';\nimport { RouteRef, SubRouteRef, ExternalRouteRef } from '../routing';\n\n/**\n * Information about the plugin.\n *\n * @public\n * @remarks\n *\n * This interface is intended to be extended via [module\n * augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)\n * in order to add fields that are specific to each project.\n *\n * For example, one might add a `slackChannel` field that is read from the\n * opaque manifest file.\n *\n * See the options for `createApp` for more information about how to\n * customize the parsing of manifest files.\n */\nexport interface FrontendPluginInfo {\n /**\n * The name of the package that implements the plugin.\n */\n packageName?: string;\n\n /**\n * The version of the plugin, typically the version of the package.json file.\n */\n version?: string;\n\n /**\n * As short description of the plugin, typically the description field in\n * package.json.\n */\n description?: string;\n\n /**\n * The owner entity references of the plugin.\n */\n ownerEntityRefs?: string[];\n\n /**\n * Links related to the plugin.\n */\n links?: Array<{ title: string; url: string }>;\n}\n\n/**\n * Options for providing information for a plugin.\n *\n * @public\n */\nexport type FrontendPluginInfoOptions = {\n /**\n * A loader function for the package.json file for the plugin.\n */\n packageJson?: () => Promise<{ name: string } & JsonObject>;\n /**\n * A loader function for an opaque manifest file for the plugin.\n */\n manifest?: () => Promise<JsonObject>;\n};\n\n/** @public */\nexport interface FrontendPlugin<\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {\n [name in string]: RouteRef | SubRouteRef;\n },\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {\n [name in string]: ExternalRouteRef;\n },\n TExtensionMap extends { [id in string]: ExtensionDefinition } = {\n [id in string]: ExtensionDefinition;\n },\n> {\n readonly $$type: '@backstage/FrontendPlugin';\n readonly id: string;\n readonly routes: TRoutes;\n readonly externalRoutes: TExternalRoutes;\n\n /**\n * Loads the plugin info.\n */\n info(): Promise<FrontendPluginInfo>;\n getExtension<TId extends keyof TExtensionMap>(id: TId): TExtensionMap[TId];\n withOverrides(options: {\n extensions: Array<ExtensionDefinition>;\n\n /**\n * Overrides the original info loaders of the plugin one by one.\n */\n info?: FrontendPluginInfoOptions;\n }): FrontendPlugin<TRoutes, TExternalRoutes, TExtensionMap>;\n}\n\n/** @public */\nexport interface PluginOptions<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef },\n TExternalRoutes extends { [name in string]: ExternalRouteRef },\n TExtensions extends readonly ExtensionDefinition[],\n> {\n pluginId: TId;\n routes?: TRoutes;\n externalRoutes?: TExternalRoutes;\n extensions?: TExtensions;\n featureFlags?: FeatureFlagConfig[];\n info?: FrontendPluginInfoOptions;\n}\n\n/**\n * Creates a new plugin that can be installed in a Backstage app.\n *\n * @remarks\n *\n * Every plugin is created with a unique ID and a set of extensions\n * that are installed as part of the plugin.\n *\n * For more information on how plugins work, see the\n * {@link https://backstage.io/docs/frontend-system/building-plugins/index | documentation for plugins}\n * in the frontend system documentation.\n *\n * @example\n *\n * ```tsx\n * import { createFrontendPlugin } from '@backstage/frontend-plugin-api';\n *\n * export const examplePlugin = createFrontendPlugin({\n * pluginId: 'example',\n * extensions: [\n * PageBlueprint.make({\n * path: '/example',\n * loader: () => import('./ExamplePage').then(m => <m.ExamplePage />),\n * }),\n * ],\n * });\n * ```\n *\n * @public\n */\nexport function createFrontendPlugin<\n TId extends string,\n TRoutes extends { [name in string]: RouteRef | SubRouteRef } = {},\n TExternalRoutes extends { [name in string]: ExternalRouteRef } = {},\n TExtensions extends readonly ExtensionDefinition[] = [],\n>(\n options: PluginOptions<TId, TRoutes, TExternalRoutes, TExtensions>,\n): FrontendPlugin<\n TRoutes,\n TExternalRoutes,\n MakeSortedExtensionsMap<TExtensions[number], TId>\n> {\n const pluginId = options.pluginId;\n\n const extensions = new Array<Extension<any>>();\n const extensionDefinitionsById = new Map<\n string,\n typeof OpaqueExtensionDefinition.TInternal\n >();\n\n for (const def of options.extensions ?? []) {\n const internal = OpaqueExtensionDefinition.toInternal(def);\n const ext = resolveExtensionDefinition(def, { namespace: pluginId });\n extensions.push(ext);\n extensionDefinitionsById.set(ext.id, {\n ...internal,\n namespace: pluginId,\n });\n }\n\n if (extensions.length !== extensionDefinitionsById.size) {\n const extensionIds = extensions.map(e => e.id);\n const duplicates = Array.from(\n new Set(\n extensionIds.filter((id, index) => extensionIds.indexOf(id) !== index),\n ),\n );\n // TODO(Rugvip): This could provide some more information about the kind + name of the extensions\n throw new Error(\n `Plugin '${pluginId}' provided duplicate extensions: ${duplicates.join(\n ', ',\n )}`,\n );\n }\n\n return OpaqueFrontendPlugin.createInstance('v1', {\n id: pluginId,\n routes: options.routes ?? ({} as TRoutes),\n externalRoutes: options.externalRoutes ?? ({} as TExternalRoutes),\n featureFlags: options.featureFlags ?? [],\n extensions: extensions,\n infoOptions: options.info,\n\n // This method is overridden when the plugin instance is installed in an app\n async info() {\n throw new Error(\n `Attempted to load plugin info for plugin '${pluginId}', but the plugin instance is not installed in an app`,\n );\n },\n getExtension(id) {\n const ext = extensionDefinitionsById.get(id);\n if (!ext) {\n throw new Error(\n `Attempted to get non-existent extension '${id}' from plugin '${pluginId}'`,\n );\n }\n return ext;\n },\n toString() {\n return `Plugin{id=${pluginId}}`;\n },\n withOverrides(overrides) {\n const overriddenExtensionIds = new Set(\n overrides.extensions.map(\n e => resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n const nonOverriddenExtensions = (options.extensions ?? []).filter(\n e =>\n !overriddenExtensionIds.has(\n resolveExtensionDefinition(e, { namespace: pluginId }).id,\n ),\n );\n return createFrontendPlugin({\n ...options,\n pluginId,\n extensions: [...nonOverriddenExtensions, ...overrides.extensions],\n info: {\n ...options.info,\n ...overrides.info,\n },\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;;AAuKO,SAAS,qBAMd,OAKA,EAAA;AACA,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,CAAA,IAAA;AAAA,UACX,GAAG,SAAU,CAAA;AAAA;AACf,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { createExtensionDataContainer } from '../frontend-internal/src/wiring/createExtensionDataContainer.esm.js';
2
+ import '../frontend-internal/src/wiring/InternalSwappableComponentRef.esm.js';
2
3
  import '../frontend-internal/src/wiring/InternalExtensionDefinition.esm.js';
3
4
  import '../frontend-internal/src/wiring/InternalFrontendPlugin.esm.js';
4
5
 
@@ -24,6 +25,7 @@ function resolveInputOverrides(declaredInputs, inputs, inputOverrides) {
24
25
  if (providedData) {
25
26
  const providedContainer = createExtensionDataContainer(
26
27
  providedData,
28
+ "extension input override",
27
29
  declaredInput.extensionData
28
30
  );
29
31
  if (!originalInput) {
@@ -55,6 +57,7 @@ function resolveInputOverrides(declaredInputs, inputs, inputOverrides) {
55
57
  newInputs[name] = providedData.map((data, i) => {
56
58
  const providedContainer = createExtensionDataContainer(
57
59
  data,
60
+ "extension input override",
58
61
  declaredInput.extensionData
59
62
  );
60
63
  return Object.assign(providedContainer, {
@@ -1 +1 @@
1
- {"version":3,"file":"resolveInputOverrides.esm.js","sources":["../../src/wiring/resolveInputOverrides.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { AppNode } from '../apis';\nimport { Expand } from '@backstage/types';\nimport { ResolvedExtensionInput } from './createExtension';\nimport { createExtensionDataContainer } from '@internal/frontend';\nimport {\n ExtensionDataRef,\n ExtensionDataRefToValue,\n ExtensionDataValue,\n} from './createExtensionDataRef';\nimport { ExtensionInput } from './createExtensionInput';\nimport { ExtensionDataContainer } from './types';\n\n/** @public */\nexport type ResolveInputValueOverrides<\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n } = {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n> = Expand<\n {\n [KName in keyof TInputs as TInputs[KName] extends ExtensionInput<\n any,\n {\n optional: infer IOptional extends boolean;\n singleton: boolean;\n }\n >\n ? IOptional extends true\n ? never\n : KName\n : never]: TInputs[KName] extends ExtensionInput<\n infer IDataRefs,\n { optional: boolean; singleton: infer ISingleton extends boolean }\n >\n ? ISingleton extends true\n ? Iterable<ExtensionDataRefToValue<IDataRefs>>\n : Array<Iterable<ExtensionDataRefToValue<IDataRefs>>>\n : never;\n } & {\n [KName in keyof TInputs as TInputs[KName] extends ExtensionInput<\n any,\n {\n optional: infer IOptional extends boolean;\n singleton: boolean;\n }\n >\n ? IOptional extends true\n ? KName\n : never\n : never]?: TInputs[KName] extends ExtensionInput<\n infer IDataRefs,\n { optional: boolean; singleton: infer ISingleton extends boolean }\n >\n ? ISingleton extends true\n ? Iterable<ExtensionDataRefToValue<IDataRefs>>\n : Array<Iterable<ExtensionDataRefToValue<IDataRefs>>>\n : never;\n }\n>;\n\nfunction expectArray<T>(value: T | T[]): T[] {\n return value as T[];\n}\nfunction expectItem<T>(value: T | T[]): T {\n return value as T;\n}\n\n/** @internal */\nexport function resolveInputOverrides(\n declaredInputs?: {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n inputs?: {\n [KName in string]?:\n | ({ node: AppNode } & ExtensionDataContainer<any>)\n | Array<{ node: AppNode } & ExtensionDataContainer<any>>;\n },\n inputOverrides?: ResolveInputValueOverrides,\n) {\n if (!declaredInputs || !inputs || !inputOverrides) {\n return inputs;\n }\n\n const newInputs: typeof inputs = {};\n for (const name in declaredInputs) {\n if (!Object.hasOwn(declaredInputs, name)) {\n continue;\n }\n const declaredInput = declaredInputs[name];\n const providedData = inputOverrides[name];\n if (declaredInput.config.singleton) {\n const originalInput = expectItem(inputs[name]);\n if (providedData) {\n const providedContainer = createExtensionDataContainer(\n providedData as Iterable<ExtensionDataValue<any, any>>,\n declaredInput.extensionData,\n );\n if (!originalInput) {\n throw new Error(\n `attempted to override data of input '${name}' but it is not present in the original inputs`,\n );\n }\n newInputs[name] = Object.assign(providedContainer, {\n node: (originalInput as ResolvedExtensionInput<any>).node,\n }) as any;\n }\n } else {\n const originalInput = expectArray(inputs[name]);\n if (!Array.isArray(providedData)) {\n throw new Error(\n `override data provided for input '${name}' must be an array`,\n );\n }\n\n // Regular inputs can be overridden in two different ways:\n // 1) Forward a subset of the original inputs in a new order\n // 2) Provide new data for each original input\n\n // First check if all inputs are being removed\n if (providedData.length === 0) {\n newInputs[name] = [];\n } else {\n // Check how many of the provided data items have a node property, i.e. is a forwarded input\n const withNodesCount = providedData.filter(d => 'node' in d).length;\n if (withNodesCount === 0) {\n if (originalInput.length !== providedData.length) {\n throw new Error(\n `override data provided for input '${name}' must match the length of the original inputs`,\n );\n }\n newInputs[name] = providedData.map((data, i) => {\n const providedContainer = createExtensionDataContainer(\n data as Iterable<ExtensionDataValue<any, any>>,\n declaredInput.extensionData,\n );\n return Object.assign(providedContainer, {\n node: (originalInput[i] as ResolvedExtensionInput<any>).node,\n }) as any;\n });\n } else if (withNodesCount === providedData.length) {\n newInputs[name] = providedData as any;\n } else {\n throw new Error(\n `override data for input '${name}' may not mix forwarded inputs with data overrides`,\n );\n }\n }\n }\n }\n return newInputs;\n}\n"],"names":[],"mappings":";;;;AAmFA,SAAS,YAAe,KAAqB,EAAA;AAC3C,EAAO,OAAA,KAAA;AACT;AACA,SAAS,WAAc,KAAmB,EAAA;AACxC,EAAO,OAAA,KAAA;AACT;AAGgB,SAAA,qBAAA,CACd,cAMA,EAAA,MAAA,EAKA,cACA,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AAA;AAEL,QAAA,MAAM,iBAAiB,YAAa,CAAA,MAAA,CAAO,CAAK,CAAA,KAAA,MAAA,IAAU,CAAC,CAAE,CAAA,MAAA;AAC7D,QAAA,IAAI,mBAAmB,CAAG,EAAA;AACxB,UAAI,IAAA,aAAA,CAAc,MAAW,KAAA,YAAA,CAAa,MAAQ,EAAA;AAChD,YAAA,MAAM,IAAI,KAAA;AAAA,cACR,qCAAqC,IAAI,CAAA,8CAAA;AAAA,aAC3C;AAAA;AAEF,UAAA,SAAA,CAAU,IAAI,CAAI,GAAA,YAAA,CAAa,GAAI,CAAA,CAAC,MAAM,CAAM,KAAA;AAC9C,YAAA,MAAM,iBAAoB,GAAA,4BAAA;AAAA,cACxB,IAAA;AAAA,cACA,aAAc,CAAA;AAAA,aAChB;AACA,YAAO,OAAA,MAAA,CAAO,OAAO,iBAAmB,EAAA;AAAA,cACtC,IAAA,EAAO,aAAc,CAAA,CAAC,CAAkC,CAAA;AAAA,aACzD,CAAA;AAAA,WACF,CAAA;AAAA,SACH,MAAA,IAAW,cAAmB,KAAA,YAAA,CAAa,MAAQ,EAAA;AACjD,UAAA,SAAA,CAAU,IAAI,CAAI,GAAA,YAAA;AAAA,SACb,MAAA;AACL,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,4BAA4B,IAAI,CAAA,kDAAA;AAAA,WAClC;AAAA;AACF;AACF;AACF;AAEF,EAAO,OAAA,SAAA;AACT;;;;"}
1
+ {"version":3,"file":"resolveInputOverrides.esm.js","sources":["../../src/wiring/resolveInputOverrides.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { AppNode } from '../apis';\nimport { Expand } from '@backstage/types';\nimport { ResolvedExtensionInput } from './createExtension';\nimport { createExtensionDataContainer } from '@internal/frontend';\nimport {\n ExtensionDataRef,\n ExtensionDataRefToValue,\n ExtensionDataValue,\n} from './createExtensionDataRef';\nimport { ExtensionInput } from './createExtensionInput';\nimport { ExtensionDataContainer } from './types';\n\n/** @ignore */\nexport type ResolvedInputValueOverrides<\n TInputs extends {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n } = {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n> = Expand<\n {\n [KName in keyof TInputs as TInputs[KName] extends ExtensionInput<\n any,\n {\n optional: infer IOptional extends boolean;\n singleton: boolean;\n }\n >\n ? IOptional extends true\n ? never\n : KName\n : never]: TInputs[KName] extends ExtensionInput<\n infer IDataRefs,\n { optional: boolean; singleton: infer ISingleton extends boolean }\n >\n ? ISingleton extends true\n ? Iterable<ExtensionDataRefToValue<IDataRefs>>\n : Array<Iterable<ExtensionDataRefToValue<IDataRefs>>>\n : never;\n } & {\n [KName in keyof TInputs as TInputs[KName] extends ExtensionInput<\n any,\n {\n optional: infer IOptional extends boolean;\n singleton: boolean;\n }\n >\n ? IOptional extends true\n ? KName\n : never\n : never]?: TInputs[KName] extends ExtensionInput<\n infer IDataRefs,\n { optional: boolean; singleton: infer ISingleton extends boolean }\n >\n ? ISingleton extends true\n ? Iterable<ExtensionDataRefToValue<IDataRefs>>\n : Array<Iterable<ExtensionDataRefToValue<IDataRefs>>>\n : never;\n }\n>;\n\nfunction expectArray<T>(value: T | T[]): T[] {\n return value as T[];\n}\nfunction expectItem<T>(value: T | T[]): T {\n return value as T;\n}\n\n/** @internal */\nexport function resolveInputOverrides(\n declaredInputs?: {\n [inputName in string]: ExtensionInput<\n ExtensionDataRef,\n { optional: boolean; singleton: boolean }\n >;\n },\n inputs?: {\n [KName in string]?:\n | ({ node: AppNode } & ExtensionDataContainer<any>)\n | Array<{ node: AppNode } & ExtensionDataContainer<any>>;\n },\n inputOverrides?: ResolvedInputValueOverrides,\n) {\n if (!declaredInputs || !inputs || !inputOverrides) {\n return inputs;\n }\n\n const newInputs: typeof inputs = {};\n for (const name in declaredInputs) {\n if (!Object.hasOwn(declaredInputs, name)) {\n continue;\n }\n const declaredInput = declaredInputs[name];\n const providedData = inputOverrides[name];\n if (declaredInput.config.singleton) {\n const originalInput = expectItem(inputs[name]);\n if (providedData) {\n const providedContainer = createExtensionDataContainer(\n providedData as Iterable<ExtensionDataValue<any, any>>,\n 'extension input override',\n declaredInput.extensionData,\n );\n if (!originalInput) {\n throw new Error(\n `attempted to override data of input '${name}' but it is not present in the original inputs`,\n );\n }\n newInputs[name] = Object.assign(providedContainer, {\n node: (originalInput as ResolvedExtensionInput<any>).node,\n }) as any;\n }\n } else {\n const originalInput = expectArray(inputs[name]);\n if (!Array.isArray(providedData)) {\n throw new Error(\n `override data provided for input '${name}' must be an array`,\n );\n }\n\n // Regular inputs can be overridden in two different ways:\n // 1) Forward a subset of the original inputs in a new order\n // 2) Provide new data for each original input\n\n // First check if all inputs are being removed\n if (providedData.length === 0) {\n newInputs[name] = [];\n } else {\n // Check how many of the provided data items have a node property, i.e. is a forwarded input\n const withNodesCount = providedData.filter(d => 'node' in d).length;\n if (withNodesCount === 0) {\n if (originalInput.length !== providedData.length) {\n throw new Error(\n `override data provided for input '${name}' must match the length of the original inputs`,\n );\n }\n newInputs[name] = providedData.map((data, i) => {\n const providedContainer = createExtensionDataContainer(\n data as Iterable<ExtensionDataValue<any, any>>,\n 'extension input override',\n declaredInput.extensionData,\n );\n return Object.assign(providedContainer, {\n node: (originalInput[i] as ResolvedExtensionInput<any>).node,\n }) as any;\n });\n } else if (withNodesCount === providedData.length) {\n newInputs[name] = providedData as any;\n } else {\n throw new Error(\n `override data for input '${name}' may not mix forwarded inputs with data overrides`,\n );\n }\n }\n }\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
3
+ "version": "0.11.0-next.2",
4
4
  "backstage": {
5
5
  "role": "web-library"
6
6
  },
@@ -31,7 +31,7 @@
31
31
  "test": "backstage-cli package test"
32
32
  },
33
33
  "dependencies": {
34
- "@backstage/core-components": "0.17.5-next.1",
34
+ "@backstage/core-components": "0.17.5-next.2",
35
35
  "@backstage/core-plugin-api": "1.10.9",
36
36
  "@backstage/types": "1.2.1",
37
37
  "@backstage/version-bridge": "1.0.11",
@@ -41,8 +41,8 @@
41
41
  "zod-to-json-schema": "^3.21.4"
42
42
  },
43
43
  "devDependencies": {
44
- "@backstage/cli": "0.34.0-next.1",
45
- "@backstage/frontend-app-api": "0.12.0-next.2",
44
+ "@backstage/cli": "0.34.0-next.2",
45
+ "@backstage/frontend-app-api": "0.12.0-next.3",
46
46
  "@backstage/frontend-test-utils": "0.3.5-next.2",
47
47
  "@backstage/test-utils": "1.7.11-next.0",
48
48
  "@testing-library/jest-dom": "^6.0.0",
@@ -1,12 +0,0 @@
1
- import { createApiRef, useApi } from '@backstage/core-plugin-api';
2
-
3
- const componentsApiRef = createApiRef({
4
- id: "core.components"
5
- });
6
- function useComponentRef(ref) {
7
- const componentsApi = useApi(componentsApiRef);
8
- return componentsApi.getComponent(ref);
9
- }
10
-
11
- export { componentsApiRef, useComponentRef };
12
- //# sourceMappingURL=ComponentsApi.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ComponentsApi.esm.js","sources":["../../../src/apis/definitions/ComponentsApi.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 { ComponentType } from 'react';\nimport { createApiRef, useApi } from '@backstage/core-plugin-api';\nimport { ComponentRef } from '../../components';\n\n/**\n * API for looking up components based on component refs.\n *\n * @public\n */\nexport interface ComponentsApi {\n // TODO: Should component refs also provide the default implementation so that we're guaranteed to get a component?\n getComponent<T extends {}>(ref: ComponentRef<T>): ComponentType<T>;\n}\n\n/**\n * The `ApiRef` of {@link ComponentsApi}.\n *\n * @public\n */\nexport const componentsApiRef = createApiRef<ComponentsApi>({\n id: 'core.components',\n});\n\n/**\n * @public\n * Returns the component associated with the given ref.\n */\nexport function useComponentRef<T extends {}>(\n ref: ComponentRef<T>,\n): ComponentType<T> {\n const componentsApi = useApi(componentsApiRef);\n return componentsApi.getComponent<T>(ref);\n}\n"],"names":[],"mappings":";;AAmCO,MAAM,mBAAmB,YAA4B,CAAA;AAAA,EAC1D,EAAI,EAAA;AACN,CAAC;AAMM,SAAS,gBACd,GACkB,EAAA;AAClB,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAO,OAAA,aAAA,CAAc,aAAgB,GAAG,CAAA;AAC1C;;;;"}
@@ -1,19 +0,0 @@
1
- import { createComponentRef } from './createComponentRef.esm.js';
2
-
3
- const coreProgressComponentRef = createComponentRef({
4
- id: "core.components.progress"
5
- });
6
- const coreNotFoundErrorPageComponentRef = createComponentRef({
7
- id: "core.components.notFoundErrorPage"
8
- });
9
- const coreErrorBoundaryFallbackComponentRef = createComponentRef({
10
- id: "core.components.errorBoundaryFallback"
11
- });
12
- const coreComponentRefs = {
13
- progress: coreProgressComponentRef,
14
- notFoundErrorPage: coreNotFoundErrorPageComponentRef,
15
- errorBoundaryFallback: coreErrorBoundaryFallbackComponentRef
16
- };
17
-
18
- export { coreComponentRefs };
19
- //# sourceMappingURL=coreComponentRefs.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coreComponentRefs.esm.js","sources":["../../src/components/coreComponentRefs.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 CoreErrorBoundaryFallbackProps,\n CoreNotFoundErrorPageProps,\n CoreProgressProps,\n} from '../types';\nimport { createComponentRef } from './createComponentRef';\n\nconst coreProgressComponentRef = createComponentRef<CoreProgressProps>({\n id: 'core.components.progress',\n});\n\nconst coreNotFoundErrorPageComponentRef =\n createComponentRef<CoreNotFoundErrorPageProps>({\n id: 'core.components.notFoundErrorPage',\n });\n\nconst coreErrorBoundaryFallbackComponentRef =\n createComponentRef<CoreErrorBoundaryFallbackProps>({\n id: 'core.components.errorBoundaryFallback',\n });\n\n/** @public */\nexport const coreComponentRefs = {\n progress: coreProgressComponentRef,\n notFoundErrorPage: coreNotFoundErrorPageComponentRef,\n errorBoundaryFallback: coreErrorBoundaryFallbackComponentRef,\n};\n"],"names":[],"mappings":";;AAuBA,MAAM,2BAA2B,kBAAsC,CAAA;AAAA,EACrE,EAAI,EAAA;AACN,CAAC,CAAA;AAED,MAAM,oCACJ,kBAA+C,CAAA;AAAA,EAC7C,EAAI,EAAA;AACN,CAAC,CAAA;AAEH,MAAM,wCACJ,kBAAmD,CAAA;AAAA,EACjD,EAAI,EAAA;AACN,CAAC,CAAA;AAGI,MAAM,iBAAoB,GAAA;AAAA,EAC/B,QAAU,EAAA,wBAAA;AAAA,EACV,iBAAmB,EAAA,iCAAA;AAAA,EACnB,qBAAuB,EAAA;AACzB;;;;"}
@@ -1,12 +0,0 @@
1
- function createComponentRef(options) {
2
- const { id } = options;
3
- return {
4
- id,
5
- toString() {
6
- return `ComponentRef{id=${id}}`;
7
- }
8
- };
9
- }
10
-
11
- export { createComponentRef };
12
- //# sourceMappingURL=createComponentRef.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createComponentRef.esm.js","sources":["../../src/components/createComponentRef.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\n/** @public */\nexport type ComponentRef<T extends {} = {}> = {\n id: string;\n T: T;\n};\n\n/** @public */\nexport function createComponentRef<T extends {} = {}>(options: {\n id: string;\n}): ComponentRef<T> {\n const { id } = options;\n return {\n id,\n toString() {\n return `ComponentRef{id=${id}}`;\n },\n } as ComponentRef<T>;\n}\n"],"names":[],"mappings":"AAuBO,SAAS,mBAAsC,OAElC,EAAA;AAClB,EAAM,MAAA,EAAE,IAAO,GAAA,OAAA;AACf,EAAO,OAAA;AAAA,IACL,EAAA;AAAA,IACA,QAAW,GAAA;AACT,MAAA,OAAO,mBAAmB,EAAE,CAAA,CAAA,CAAA;AAAA;AAC9B,GACF;AACF;;;;"}
@@ -1,43 +0,0 @@
1
- import { lazy } from 'react';
2
- import '../wiring/coreExtensionData.esm.js';
3
- import { createExtension } from '../wiring/createExtension.esm.js';
4
- import { createExtensionDataRef } from '../wiring/createExtensionDataRef.esm.js';
5
- import '../wiring/createExtensionBlueprint.esm.js';
6
-
7
- function createComponentExtension(options) {
8
- return createExtension({
9
- kind: "component",
10
- name: options.name ?? options.ref.id,
11
- attachTo: { id: "api:app/components", input: "components" },
12
- disabled: options.disabled,
13
- output: [createComponentExtension.componentDataRef],
14
- factory() {
15
- if ("sync" in options.loader) {
16
- return [
17
- createComponentExtension.componentDataRef({
18
- ref: options.ref,
19
- impl: options.loader.sync()
20
- })
21
- ];
22
- }
23
- const lazyLoader = options.loader.lazy;
24
- const ExtensionComponent = lazy(
25
- () => lazyLoader().then((Component) => ({
26
- default: Component
27
- }))
28
- );
29
- return [
30
- createComponentExtension.componentDataRef({
31
- ref: options.ref,
32
- impl: ExtensionComponent
33
- })
34
- ];
35
- }
36
- });
37
- }
38
- ((createComponentExtension2) => {
39
- createComponentExtension2.componentDataRef = createExtensionDataRef().with({ id: "core.component.component" });
40
- })(createComponentExtension || (createComponentExtension = {}));
41
-
42
- export { createComponentExtension };
43
- //# sourceMappingURL=createComponentExtension.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createComponentExtension.esm.js","sources":["../../src/extensions/createComponentExtension.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 { lazy, ComponentType } from 'react';\nimport { createExtension, createExtensionDataRef } from '../wiring';\nimport { ComponentRef } from '../components';\n\n/** @public */\nexport function createComponentExtension<TProps extends {}>(options: {\n ref: ComponentRef<TProps>;\n name?: string;\n disabled?: boolean;\n loader:\n | {\n lazy: () => Promise<ComponentType<TProps>>;\n }\n | {\n sync: () => ComponentType<TProps>;\n };\n}) {\n return createExtension({\n kind: 'component',\n name: options.name ?? options.ref.id,\n attachTo: { id: 'api:app/components', input: 'components' },\n disabled: options.disabled,\n output: [createComponentExtension.componentDataRef],\n factory() {\n if ('sync' in options.loader) {\n return [\n createComponentExtension.componentDataRef({\n ref: options.ref,\n impl: options.loader.sync() as ComponentType,\n }),\n ];\n }\n const lazyLoader = options.loader.lazy;\n const ExtensionComponent = lazy(() =>\n lazyLoader().then(Component => ({\n default: Component,\n })),\n ) as unknown as ComponentType;\n\n return [\n createComponentExtension.componentDataRef({\n ref: options.ref,\n impl: ExtensionComponent,\n }),\n ];\n },\n });\n}\n\n/** @public */\nexport namespace createComponentExtension {\n export const componentDataRef = createExtensionDataRef<{\n ref: ComponentRef;\n impl: ComponentType;\n }>().with({ id: 'core.component.component' });\n}\n"],"names":["createComponentExtension"],"mappings":";;;;;;AAqBO,SAAS,yBAA4C,OAWzD,EAAA;AACD,EAAA,OAAO,eAAgB,CAAA;AAAA,IACrB,IAAM,EAAA,WAAA;AAAA,IACN,IAAM,EAAA,OAAA,CAAQ,IAAQ,IAAA,OAAA,CAAQ,GAAI,CAAA,EAAA;AAAA,IAClC,QAAU,EAAA,EAAE,EAAI,EAAA,oBAAA,EAAsB,OAAO,YAAa,EAAA;AAAA,IAC1D,UAAU,OAAQ,CAAA,QAAA;AAAA,IAClB,MAAA,EAAQ,CAAC,wBAAA,CAAyB,gBAAgB,CAAA;AAAA,IAClD,OAAU,GAAA;AACR,MAAI,IAAA,MAAA,IAAU,QAAQ,MAAQ,EAAA;AAC5B,QAAO,OAAA;AAAA,UACL,yBAAyB,gBAAiB,CAAA;AAAA,YACxC,KAAK,OAAQ,CAAA,GAAA;AAAA,YACb,IAAA,EAAM,OAAQ,CAAA,MAAA,CAAO,IAAK;AAAA,WAC3B;AAAA,SACH;AAAA;AAEF,MAAM,MAAA,UAAA,GAAa,QAAQ,MAAO,CAAA,IAAA;AAClC,MAAA,MAAM,kBAAqB,GAAA,IAAA;AAAA,QAAK,MAC9B,UAAA,EAAa,CAAA,IAAA,CAAK,CAAc,SAAA,MAAA;AAAA,UAC9B,OAAS,EAAA;AAAA,SACT,CAAA;AAAA,OACJ;AAEA,MAAO,OAAA;AAAA,QACL,yBAAyB,gBAAiB,CAAA;AAAA,UACxC,KAAK,OAAQ,CAAA,GAAA;AAAA,UACb,IAAM,EAAA;AAAA,SACP;AAAA,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