Merge pull request #15957 from backstage/freben/reg

break into dedicated plugin and module registration points
This commit is contained in:
Fredrik Adelöw
2023-01-25 18:46:51 +01:00
committed by GitHub
5 changed files with 96 additions and 12 deletions
@@ -15,6 +15,8 @@
*/
import {
BackendModuleRegistrationPoints,
BackendPluginRegistrationPoints,
BackendRegistrationPoints,
BackendFeature,
ExtensionPoint,
@@ -71,7 +73,7 @@ export interface BackendPluginConfig {
* @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
*/
id: string;
register(reg: BackendRegistrationPoints): void;
register(reg: BackendPluginRegistrationPoints): void;
}
/**
@@ -109,9 +111,7 @@ export interface BackendModuleConfig {
* Should exactly match the `id` of the plugin that the module extends.
*/
moduleId: string;
register(
reg: Omit<BackendRegistrationPoints, 'registerExtensionPoint'>,
): void;
register(reg: BackendModuleRegistrationPoints): void;
}
/**
@@ -136,8 +136,9 @@ export function createBackendModule<TOptions extends [options?: object] = []>(
return () => ({
id: `${config.pluginId}.${config.moduleId}`,
register(register: BackendRegistrationPoints) {
// TODO: Hide registerExtensionPoint
return config.register(register);
return config.register({
registerInit: register.registerInit.bind(register),
});
},
});
}
@@ -30,6 +30,8 @@ export {
createExtensionPoint,
} from './factories';
export type {
BackendModuleRegistrationPoints,
BackendPluginRegistrationPoints,
BackendRegistrationPoints,
BackendFeature,
ExtensionPoint,
@@ -35,7 +35,13 @@ export type ExtensionPoint<T> = {
$$ref: 'extension-point';
};
/** @public */
/**
* The callbacks passed to the `register` method of a backend feature; this is
* essentially a superset of {@link BackendPluginRegistrationPoints} and
* {@link BackendModuleRegistrationPoints}.
*
* @public
*/
export interface BackendRegistrationPoints {
registerExtensionPoint<TExtensionPoint>(
ref: ExtensionPoint<TExtensionPoint>,
@@ -49,6 +55,38 @@ export interface BackendRegistrationPoints {
}): void;
}
/**
* The callbacks passed to the `register` method of a backend plugin.
*
* @public
*/
export interface BackendPluginRegistrationPoints {
registerExtensionPoint<TExtensionPoint>(
ref: ExtensionPoint<TExtensionPoint>,
impl: TExtensionPoint,
): void;
registerInit<Deps extends { [name in string]: unknown }>(options: {
deps: {
[name in keyof Deps]: ServiceRef<Deps[name]>;
};
init(deps: Deps): Promise<void>;
}): void;
}
/**
* The callbacks passed to the `register` method of a backend module.
*
* @public
*/
export interface BackendModuleRegistrationPoints {
registerInit<Deps extends { [name in string]: unknown }>(options: {
deps: {
[name in keyof Deps]: ServiceRef<Deps[name]> | ExtensionPoint<Deps[name]>;
};
init(deps: Deps): Promise<void>;
}): void;
}
/** @public */
export interface BackendFeature {
// TODO(Rugvip): Try to get rid of the ID at this level, allowing for a feature to register multiple features as a bundle