core-api: make it possible for plugins to include ApiFactories
This commit is contained in:
@@ -324,6 +324,18 @@ export class PrivateAppImpl implements BackstageApp {
|
||||
registry.register('default', factory);
|
||||
}
|
||||
|
||||
for (const plugin of this.plugins) {
|
||||
for (const factory of plugin.getApis()) {
|
||||
if (!registry.register('default', factory)) {
|
||||
throw new Error(
|
||||
`Plugin ${plugin.getId()} tried to register duplicate or forbidden API factory for ${
|
||||
factory.implements
|
||||
}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const factory of this.apis) {
|
||||
if (!registry.register('app', factory)) {
|
||||
throw new Error(
|
||||
|
||||
@@ -24,9 +24,11 @@ import {
|
||||
} from './types';
|
||||
import { validateBrowserCompat, validateFlagName } from '../app/FeatureFlags';
|
||||
import { RouteRef } from '../routing';
|
||||
import { AnyApiFactory } from '../apis';
|
||||
|
||||
export type PluginConfig = {
|
||||
id: string;
|
||||
apis?: Iterable<AnyApiFactory>;
|
||||
register?(hooks: PluginHooks): void;
|
||||
};
|
||||
|
||||
@@ -65,6 +67,10 @@ export class PluginImpl {
|
||||
return this.config.id;
|
||||
}
|
||||
|
||||
getApis(): Iterable<AnyApiFactory> {
|
||||
return this.config.apis ?? [];
|
||||
}
|
||||
|
||||
output(): PluginOutput[] {
|
||||
if (this.storedOutput) {
|
||||
return this.storedOutput;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import { ComponentType } from 'react';
|
||||
import { RouteRef } from '../routing';
|
||||
import { AnyApiFactory } from '../apis';
|
||||
|
||||
export type RouteOptions = {
|
||||
// Whether the route path must match exactly, defaults to true.
|
||||
@@ -70,4 +71,5 @@ export type PluginOutput =
|
||||
export type BackstagePlugin = {
|
||||
getId(): string;
|
||||
output(): PluginOutput[];
|
||||
getApis(): Iterable<AnyApiFactory>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user