From c1369c2cf457c1230cb6fc336cb37de8a5ba4f0d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 13 Jan 2023 17:40:46 +0100 Subject: [PATCH] backend-plugin-api: update API report + fixes Signed-off-by: Patrik Oldsberg --- packages/backend-plugin-api/api-report.md | 151 ++++++++++++++---- .../src/services/system/types.ts | 24 +-- 2 files changed, 133 insertions(+), 42 deletions(-) diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 33190277c9..59338fdf42 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -126,22 +126,86 @@ export function createExtensionPoint( config: ExtensionPointConfig, ): ExtensionPoint; -// @public (undocumented) +// @public export function createServiceFactory< TService, - TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends { [name in string]: ServiceRef; }, - TOpts extends [options?: object] = [], + TOpts extends object | undefined = undefined, +>( + config: RootServiceFactoryConfig, +): () => ServiceFactory; + +// @public +export function createServiceFactory< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, + TOpts extends object | undefined = undefined, +>( + config: (options?: TOpts) => RootServiceFactoryConfig, +): (options?: TOpts) => ServiceFactory; + +// @public +export function createServiceFactory< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, + TOpts extends object | undefined = undefined, +>( + config: (options: TOpts) => RootServiceFactoryConfig, +): (options: TOpts) => ServiceFactory; + +// @public +export function createServiceFactory< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, + TContext = undefined, + TOpts extends object | undefined = undefined, +>( + config: PluginServiceFactoryConfig, +): () => ServiceFactory; + +// @public +export function createServiceFactory< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, + TContext = undefined, + TOpts extends object | undefined = undefined, +>( + config: ( + options?: TOpts, + ) => PluginServiceFactoryConfig, +): (options?: TOpts) => ServiceFactory; + +// @public +export function createServiceFactory< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, + TContext = undefined, + TOpts extends object | undefined = undefined, >( config: - | ServiceFactoryConfig + | PluginServiceFactoryConfig | (( - ...options: TOpts - ) => ServiceFactoryConfig), -): (...params: TOpts) => ServiceFactory; + options: TOpts, + ) => PluginServiceFactoryConfig), +): (options: TOpts) => ServiceFactory; // @public export function createServiceRef( @@ -229,6 +293,30 @@ export interface PluginMetadataService { getId(): string; } +// @public (undocumented) +export interface PluginServiceFactoryConfig< + TService, + TContext, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, +> { + // (undocumented) + createRootContext?( + deps: ServiceRefsToInstances, + ): Promise; + // (undocumented) + deps: TDeps; + // (undocumented) + factory( + deps: ServiceRefsToInstances, + context: TContext, + ): Promise; + // (undocumented) + service: ServiceRef; +} + // @public export type ReadTreeOptions = { filter?( @@ -284,6 +372,22 @@ export interface RootLifecycleService extends LifecycleService {} // @public (undocumented) export interface RootLoggerService extends LoggerService {} +// @public (undocumented) +export interface RootServiceFactoryConfig< + TService, + TImpl extends TService, + TDeps extends { + [name in string]: ServiceRef; + }, +> { + // (undocumented) + deps: TDeps; + // (undocumented) + factory(deps: ServiceRefsToInstances): Promise; + // (undocumented) + service: ServiceRef; +} + // @public (undocumented) export interface SchedulerService extends PluginTaskScheduler {} @@ -323,36 +427,17 @@ export type ServiceFactory = deps: { [key in string]: ServiceRef; }; - factory(deps: { + createRootContext?(deps: { [key in string]: unknown; - }): Promise< - (deps: { + }): Promise; + factory( + deps: { [key in string]: unknown; - }) => Promise - >; + }, + context: unknown, + ): Promise; }; -// @public (undocumented) -export interface ServiceFactoryConfig< - TService, - TScope extends 'root' | 'plugin', - TImpl extends TService, - TDeps extends { - [name in string]: ServiceRef; - }, -> { - // (undocumented) - deps: TDeps; - // (undocumented) - factory( - deps: ServiceRefsToInstances, - ): TScope extends 'root' - ? Promise - : Promise<(deps: ServiceRefsToInstances) => Promise>; - // (undocumented) - service: ServiceRef; -} - // @public export type ServiceFactoryOrFunction = | ServiceFactory diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 618ef1b7b6..f4489b168b 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -166,10 +166,10 @@ export interface PluginServiceFactoryConfig< } /** - * Creates a root scoped service factory. + * Creates a root scoped service factory without options. * * @public - * @param config + * @param config - The service factory configuration. */ export function createServiceFactory< TService, @@ -183,7 +183,7 @@ export function createServiceFactory< * Creates a root scoped service factory with optional options. * * @public - * @param config + * @param config - The service factory configuration. */ export function createServiceFactory< TService, @@ -194,10 +194,10 @@ export function createServiceFactory< config: (options?: TOpts) => RootServiceFactoryConfig, ): (options?: TOpts) => ServiceFactory; /** - * Creates a plugin scoped service factory with required options. + * Creates a root scoped service factory with required options. * * @public - * @param config + * @param config - The service factory configuration. */ export function createServiceFactory< TService, @@ -208,10 +208,10 @@ export function createServiceFactory< config: (options: TOpts) => RootServiceFactoryConfig, ): (options: TOpts) => ServiceFactory; /** - * Creates a plugin scoped service factory with optional options. + * Creates a plugin scoped service factory without options. * * @public - * @param config + * @param config - The service factory configuration. */ export function createServiceFactory< TService, @@ -223,10 +223,10 @@ export function createServiceFactory< config: PluginServiceFactoryConfig, ): () => ServiceFactory; /** - * Creates a plugin scoped service factory with required options. + * Creates a plugin scoped service factory with optional options. * * @public - * @param config + * @param config - The service factory configuration. */ export function createServiceFactory< TService, @@ -239,6 +239,12 @@ export function createServiceFactory< options?: TOpts, ) => PluginServiceFactoryConfig, ): (options?: TOpts) => ServiceFactory; +/** + * Creates a plugin scoped service factory with required options. + * + * @public + * @param config - The service factory configuration. + */ export function createServiceFactory< TService, TImpl extends TService,