backend-plugin-api: make ServiceFactory backend feature

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-08-10 23:36:43 +02:00
committed by Patrik Oldsberg
parent 916886098a
commit d175692fd7
5 changed files with 23 additions and 21 deletions
@@ -15,6 +15,7 @@
*/
export type {
BackendFeature,
ServiceRef,
ServiceRefConfig,
ServiceFactory,
@@ -51,9 +51,7 @@ export type ServiceRef<
export interface ServiceFactory<
TService = unknown,
TScope extends 'plugin' | 'root' = 'plugin' | 'root',
> {
$$type: '@backstage/ServiceFactory';
> extends BackendFeature {
service: ServiceRef<TService, TScope>;
}
@@ -87,6 +85,20 @@ export interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
) => Promise<ServiceFactoryOrFunction>;
}
/** @internal */
export interface BackendFeatureFactory<
TOptions extends [options?: object] = [],
> {
(...options: TOptions): BackendFeature;
$$type: '@backstage/BackendFeatureFactory';
}
/** @public */
export interface BackendFeature {
// NOTE: This type is opaque in order to simplify future API evolution.
$$type: '@backstage/BackendFeature';
}
/**
* Creates a new service definition. This overload is used to create plugin scoped services.
*
@@ -248,7 +260,7 @@ export function createServiceFactory<
if (anyConf.service.scope === 'root') {
const c = anyConf as RootServiceFactoryConfig<TService, TImpl, TDeps>;
return {
$$type: '@backstage/ServiceFactory',
$$type: '@backstage/BackendFeature',
version: 'v1',
service: c.service,
deps: c.deps,
@@ -262,7 +274,7 @@ export function createServiceFactory<
TDeps
>;
return {
$$type: '@backstage/ServiceFactory',
$$type: '@backstage/BackendFeature',
version: 'v1',
service: c.service,
...('createRootContext' in c
@@ -14,14 +14,16 @@
* limitations under the License.
*/
import {
BackendFeature,
BackendFeatureFactory,
} from '../services/system/types';
import {
BackendModuleRegistrationPoints,
BackendPluginRegistrationPoints,
ExtensionPoint,
InternalBackendModuleRegistration,
InternalBackendPluginRegistration,
BackendFeatureFactory,
BackendFeature,
} from './types';
/**
@@ -27,6 +27,5 @@ export {
export type {
BackendModuleRegistrationPoints,
BackendPluginRegistrationPoints,
BackendFeature,
ExtensionPoint,
} from './types';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ServiceRef } from '../services/system/types';
import { BackendFeature, ServiceRef } from '../services/system/types';
/**
* TODO
@@ -71,18 +71,6 @@ export interface BackendModuleRegistrationPoints {
}): void;
}
/** @internal */
export interface BackendFeatureFactory {
(): BackendFeature;
$$type: '@backstage/BackendFeatureFactory';
}
/** @public */
export interface BackendFeature {
// NOTE: This type is opaque in order to simplify future API evolution.
$$type: '@backstage/BackendFeature';
}
/** @internal */
export interface InternalBackendFeature extends BackendFeature {
version: 'v1';