backend-plugin-api: add ServiceFactoryOrFunction type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/backend-defaults': patch
|
||||
'@backstage/backend-app-api': patch
|
||||
---
|
||||
|
||||
Use new `ServiceFactoryOrFunction` type.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-plugin-api': patch
|
||||
---
|
||||
|
||||
Added `ServiceFactoryOrFunction` type, for use when either a `ServiceFactory` or `() => ServiceFactory` can be used.
|
||||
@@ -19,6 +19,7 @@ import { RootLifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { RootLoggerService } from '@backstage/backend-plugin-api';
|
||||
import { SchedulerService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactoryOrFunction } from '@backstage/backend-plugin-api';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
import { TokenManagerService } from '@backstage/backend-plugin-api';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
@@ -51,7 +52,7 @@ export function createSpecializedBackend(
|
||||
// @public (undocumented)
|
||||
export interface CreateSpecializedBackendOptions {
|
||||
// (undocumented)
|
||||
services: (ServiceFactory | (() => ServiceFactory))[];
|
||||
services: ServiceFactoryOrFunction[];
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
import {
|
||||
BackendFeature,
|
||||
ExtensionPoint,
|
||||
ServiceFactory,
|
||||
ServiceRef,
|
||||
ServiceFactoryOrFunction,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ export interface BackendRegisterInit {
|
||||
* @public
|
||||
*/
|
||||
export interface CreateSpecializedBackendOptions {
|
||||
services: (ServiceFactory | (() => ServiceFactory))[];
|
||||
services: ServiceFactoryOrFunction[];
|
||||
}
|
||||
|
||||
export interface ServiceHolder {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
```ts
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactoryOrFunction } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public (undocumented)
|
||||
export function createBackend(options?: CreateBackendOptions): Backend;
|
||||
@@ -12,6 +12,6 @@ export function createBackend(options?: CreateBackendOptions): Backend;
|
||||
// @public (undocumented)
|
||||
export interface CreateBackendOptions {
|
||||
// (undocumented)
|
||||
services?: (ServiceFactory | (() => ServiceFactory))[];
|
||||
services?: ServiceFactoryOrFunction[];
|
||||
}
|
||||
```
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
tokenManagerFactory,
|
||||
urlReaderFactory,
|
||||
} from '@backstage/backend-app-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactoryOrFunction } from '@backstage/backend-plugin-api';
|
||||
|
||||
export const defaultServiceFactories = [
|
||||
cacheFactory(),
|
||||
@@ -55,7 +55,7 @@ export const defaultServiceFactories = [
|
||||
* @public
|
||||
*/
|
||||
export interface CreateBackendOptions {
|
||||
services?: (ServiceFactory | (() => ServiceFactory))[];
|
||||
services?: ServiceFactoryOrFunction[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -347,6 +347,11 @@ export interface ServiceFactoryConfig<
|
||||
service: ServiceRef<TService, TScope>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type ServiceFactoryOrFunction<TService = unknown> =
|
||||
| ServiceFactory<TService>
|
||||
| (() => ServiceFactory<TService>);
|
||||
|
||||
// @public
|
||||
export type ServiceRef<
|
||||
TService,
|
||||
@@ -364,7 +369,7 @@ export interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
|
||||
// (undocumented)
|
||||
defaultFactory?: (
|
||||
service: ServiceRef<TService, TScope>,
|
||||
) => Promise<ServiceFactory<TService> | (() => ServiceFactory<TService>)>;
|
||||
) => Promise<ServiceFactoryOrFunction<TService>>;
|
||||
// (undocumented)
|
||||
id: string;
|
||||
// (undocumented)
|
||||
|
||||
@@ -20,5 +20,6 @@ export type {
|
||||
TypesToServiceRef,
|
||||
ServiceFactory,
|
||||
ServiceFactoryConfig,
|
||||
ServiceFactoryOrFunction,
|
||||
} from './types';
|
||||
export { createServiceRef, createServiceFactory } from './types';
|
||||
|
||||
@@ -71,13 +71,22 @@ export type ServiceFactory<TService = unknown> =
|
||||
>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents either a {@link ServiceFactory} or a function that returns one.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type ServiceFactoryOrFunction<TService = unknown> =
|
||||
| ServiceFactory<TService>
|
||||
| (() => ServiceFactory<TService>);
|
||||
|
||||
/** @public */
|
||||
export interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
|
||||
id: string;
|
||||
scope?: TScope;
|
||||
defaultFactory?: (
|
||||
service: ServiceRef<TService, TScope>,
|
||||
) => Promise<ServiceFactory<TService> | (() => ServiceFactory<TService>)>;
|
||||
) => Promise<ServiceFactoryOrFunction<TService>>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user