diff --git a/.changeset/cuddly-fishes-switch.md b/.changeset/cuddly-fishes-switch.md new file mode 100644 index 0000000000..75f09c16b7 --- /dev/null +++ b/.changeset/cuddly-fishes-switch.md @@ -0,0 +1,6 @@ +--- +'@backstage/backend-defaults': patch +'@backstage/backend-app-api': patch +--- + +Use new `ServiceFactoryOrFunction` type. diff --git a/.changeset/eight-mugs-draw.md b/.changeset/eight-mugs-draw.md new file mode 100644 index 0000000000..9d530e2a6d --- /dev/null +++ b/.changeset/eight-mugs-draw.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-plugin-api': patch +--- + +Added `ServiceFactoryOrFunction` type, for use when either a `ServiceFactory` or `() => ServiceFactory` can be used. diff --git a/packages/backend-app-api/api-report.md b/packages/backend-app-api/api-report.md index 1ff40c8b5d..a402150755 100644 --- a/packages/backend-app-api/api-report.md +++ b/packages/backend-app-api/api-report.md @@ -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) diff --git a/packages/backend-app-api/src/wiring/types.ts b/packages/backend-app-api/src/wiring/types.ts index 115488d596..d3c4fc48c7 100644 --- a/packages/backend-app-api/src/wiring/types.ts +++ b/packages/backend-app-api/src/wiring/types.ts @@ -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 { diff --git a/packages/backend-defaults/api-report.md b/packages/backend-defaults/api-report.md index 050ebde759..6cc58de663 100644 --- a/packages/backend-defaults/api-report.md +++ b/packages/backend-defaults/api-report.md @@ -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[]; } ``` diff --git a/packages/backend-defaults/src/CreateBackend.ts b/packages/backend-defaults/src/CreateBackend.ts index 6f9e8e39b6..bef80e4f2b 100644 --- a/packages/backend-defaults/src/CreateBackend.ts +++ b/packages/backend-defaults/src/CreateBackend.ts @@ -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[]; } /** diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 2dcd0dccb4..6dc36c83b3 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -347,6 +347,11 @@ export interface ServiceFactoryConfig< service: ServiceRef; } +// @public +export type ServiceFactoryOrFunction = + | ServiceFactory + | (() => ServiceFactory); + // @public export type ServiceRef< TService, @@ -364,7 +369,7 @@ export interface ServiceRefConfig { // (undocumented) defaultFactory?: ( service: ServiceRef, - ) => Promise | (() => ServiceFactory)>; + ) => Promise>; // (undocumented) id: string; // (undocumented) diff --git a/packages/backend-plugin-api/src/services/system/index.ts b/packages/backend-plugin-api/src/services/system/index.ts index d00c2da4bd..cd15d8127d 100644 --- a/packages/backend-plugin-api/src/services/system/index.ts +++ b/packages/backend-plugin-api/src/services/system/index.ts @@ -20,5 +20,6 @@ export type { TypesToServiceRef, ServiceFactory, ServiceFactoryConfig, + ServiceFactoryOrFunction, } from './types'; export { createServiceRef, createServiceFactory } from './types'; diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 7c3a9547b6..ffbbdb5f0c 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -71,13 +71,22 @@ export type ServiceFactory = >; }; +/** + * Represents either a {@link ServiceFactory} or a function that returns one. + * + * @public + */ +export type ServiceFactoryOrFunction = + | ServiceFactory + | (() => ServiceFactory); + /** @public */ export interface ServiceRefConfig { id: string; scope?: TScope; defaultFactory?: ( service: ServiceRef, - ) => Promise | (() => ServiceFactory)>; + ) => Promise>; } /**