diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 30e58237af..3344576db8 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -66,10 +66,10 @@ export interface BackendRegistrationPoints { } // @public (undocumented) -export const cacheServiceRef: ServiceRef; +export const cacheServiceRef: ServiceRef; // @public (undocumented) -export const configServiceRef: ServiceRef; +export const configServiceRef: ServiceRef; // @public (undocumented) export function createBackendModule< @@ -105,22 +105,25 @@ export function createExtensionPoint(options: { // @public (undocumented) export function createServiceFactory< TService, + TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends { - [name in string]: unknown; + [name in string]: ServiceRef; }, TOpts extends | { [name in string]: unknown; } | undefined = undefined, ->(factory: { - service: ServiceRef; - deps: TypesToServiceRef; +>(config: { + service: ServiceRef; + deps: TDeps; factory( - deps: DepsToDepFactories, + deps: ServiceRefsToInstances, options: TOpts, - ): Promise>; + ): TScope extends 'root' + ? Promise + : Promise<(deps: ServiceRefsToInstances) => Promise>; }): undefined extends TOpts ? (options?: TOpts) => ServiceFactory : (options: TOpts) => ServiceFactory; @@ -128,21 +131,26 @@ export function createServiceFactory< // @public (undocumented) export function createServiceRef(options: { id: string; + scope?: 'plugin'; defaultFactory?: ( - service: ServiceRef, + service: ServiceRef, ) => Promise | (() => ServiceFactory)>; -}): ServiceRef; +}): ServiceRef; // @public (undocumented) -export const databaseServiceRef: ServiceRef; +export function createServiceRef(options: { + id: string; + scope: 'root'; + defaultFactory?: ( + service: ServiceRef, + ) => Promise | (() => ServiceFactory)>; +}): ServiceRef; // @public (undocumented) -export type DepsToDepFactories = { - [key in keyof T]: (pluginId: string) => Promise; -}; +export const databaseServiceRef: ServiceRef; // @public (undocumented) -export const discoveryServiceRef: ServiceRef; +export const discoveryServiceRef: ServiceRef; // @public export type ExtensionPoint = { @@ -152,9 +160,6 @@ export type ExtensionPoint = { $$ref: 'extension-point'; }; -// @public (undocumented) -export type FactoryFunc = (pluginId: string) => Promise; - // @public (undocumented) export interface HttpRouterService { // (undocumented) @@ -162,7 +167,7 @@ export interface HttpRouterService { } // @public (undocumented) -export const httpRouterServiceRef: ServiceRef; +export const httpRouterServiceRef: ServiceRef; // @public (undocumented) export interface Logger { @@ -173,7 +178,7 @@ export interface Logger { } // @public (undocumented) -export const loggerServiceRef: ServiceRef; +export const loggerServiceRef: ServiceRef; // @public (undocumented) export function loggerToWinstonLogger( @@ -183,33 +188,66 @@ export function loggerToWinstonLogger( // @public (undocumented) export const permissionsServiceRef: ServiceRef< - PermissionAuthorizer | PermissionEvaluator + PermissionAuthorizer | PermissionEvaluator, + 'plugin' >; // @public (undocumented) -export const schedulerServiceRef: ServiceRef; +export interface PluginMetadata { + // (undocumented) + getId(): string; +} // @public (undocumented) -export type ServiceFactory = { - service: ServiceRef; - deps: { - [key in string]: ServiceRef; - }; - factory(deps: { - [key in string]: unknown; - }): Promise>; -}; +export const pluginMetadataServiceRef: ServiceRef; + +// @public (undocumented) +export const rootLoggerServiceRef: ServiceRef; + +// @public (undocumented) +export const schedulerServiceRef: ServiceRef; + +// @public (undocumented) +export type ServiceFactory = + | { + scope: 'root'; + service: ServiceRef; + deps: { + [key in string]: ServiceRef; + }; + factory(deps: { + [key in string]: unknown; + }): Promise; + } + | { + scope: 'plugin'; + service: ServiceRef; + deps: { + [key in string]: ServiceRef; + }; + factory(deps: { + [key in string]: unknown; + }): Promise< + (deps: { + [key in string]: unknown; + }) => Promise + >; + }; // @public -export type ServiceRef = { +export type ServiceRef< + TService, + TScope extends 'root' | 'plugin' = 'root' | 'plugin', +> = { id: string; - T: T; + scope: TScope; + T: TService; toString(): string; $$ref: 'service'; }; // @public (undocumented) -export const tokenManagerServiceRef: ServiceRef; +export const tokenManagerServiceRef: ServiceRef; // @public (undocumented) export type TypesToServiceRef = { @@ -217,5 +255,5 @@ export type TypesToServiceRef = { }; // @public (undocumented) -export const urlReaderServiceRef: ServiceRef; +export const urlReaderServiceRef: ServiceRef; ``` diff --git a/packages/backend-plugin-api/src/services/definitions/index.ts b/packages/backend-plugin-api/src/services/definitions/index.ts index 44ccb62978..e5f032ef60 100644 --- a/packages/backend-plugin-api/src/services/definitions/index.ts +++ b/packages/backend-plugin-api/src/services/definitions/index.ts @@ -28,3 +28,4 @@ export { permissionsServiceRef } from './permissionsServiceRef'; export { schedulerServiceRef } from './schedulerServiceRef'; export { rootLoggerServiceRef } from './rootLoggerServiceRef'; export { pluginMetadataServiceRef } from './pluginMetadataServiceRef'; +export type { PluginMetadata } from './pluginMetadataServiceRef'; diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index a7bce3d220..d20fd6fd8f 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -69,9 +69,7 @@ export type ServiceFactory = >; }; -/** - * @public - */ +/** @public */ export function createServiceRef(options: { id: string; scope?: 'plugin'; @@ -79,6 +77,7 @@ export function createServiceRef(options: { service: ServiceRef, ) => Promise | (() => ServiceFactory)>; }): ServiceRef; +/** @public */ export function createServiceRef(options: { id: string; scope: 'root'; diff --git a/plugins/catalog-node/api-report.md b/plugins/catalog-node/api-report.md index 3873e3376d..525516be54 100644 --- a/plugins/catalog-node/api-report.md +++ b/plugins/catalog-node/api-report.md @@ -109,7 +109,7 @@ export type CatalogProcessorResult = | CatalogProcessorRefreshKeysResult; // @alpha -export const catalogServiceRef: ServiceRef; +export const catalogServiceRef: ServiceRef; // @public export type DeferredEntity = {