backend-plugin-api: add ServiceFactoryOrFunction type

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-03 13:45:50 +01:00
parent 043f4e5678
commit ecc6bfe4c9
9 changed files with 36 additions and 9 deletions
+6 -1
View File
@@ -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>>;
}
/**