From 53d8f4fb8c4e95c093219710c479e8a828654030 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 11 Jan 2023 14:30:50 +0100 Subject: [PATCH 1/7] backend-plugin-api: refactor feature factories with new option callback pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Co-authored-by: blam Co-authored-by: Johan Haals Signed-off-by: Patrik Oldsberg --- packages/backend-plugin-api/src/types.ts | 8 ++++ .../src/wiring/factories.test.ts | 48 +++++++++---------- .../src/wiring/factories.ts | 41 ++++++++++------ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/packages/backend-plugin-api/src/types.ts b/packages/backend-plugin-api/src/types.ts index 6da3bafe17..1bd9d43390 100644 --- a/packages/backend-plugin-api/src/types.ts +++ b/packages/backend-plugin-api/src/types.ts @@ -21,6 +21,14 @@ */ export type MaybeOptions = object | undefined; +/** + * @ignore + */ +export type FactoryFunctionConfig = + | TConfig + | ((options: TOptions) => TConfig) + | (() => TConfig); + /** * Helper type that makes the options argument optional if options are not required. * diff --git a/packages/backend-plugin-api/src/wiring/factories.test.ts b/packages/backend-plugin-api/src/wiring/factories.test.ts index cf67e411d5..dbdf0ead14 100644 --- a/packages/backend-plugin-api/src/wiring/factories.test.ts +++ b/packages/backend-plugin-api/src/wiring/factories.test.ts @@ -32,10 +32,10 @@ describe('createExtensionPoint', () => { describe('createBackendPlugin', () => { it('should create a BackendPlugin', () => { - const plugin = createBackendPlugin({ + const plugin = createBackendPlugin((_options: { a: string }) => ({ id: 'x', - register(_reg, _options: { a: string }) {}, - }); + register() {}, + })); expect(plugin).toBeDefined(); expect(plugin({ a: 'a' })).toBeDefined(); expect(plugin({ a: 'a' }).id).toBe('x'); @@ -46,10 +46,10 @@ describe('createBackendPlugin', () => { }); it('should create plugins with optional options', () => { - const plugin = createBackendPlugin({ + const plugin = createBackendPlugin((_options?: { a: string }) => ({ id: 'x', - register(_reg, _options?: { a: string }) {}, - }); + register() {}, + })); expect(plugin).toBeDefined(); expect(plugin({ a: 'a' })).toBeDefined(); expect(plugin()).toBeDefined(); @@ -73,10 +73,10 @@ describe('createBackendPlugin', () => { interface TestOptions { a: string; } - const plugin = createBackendPlugin({ + const plugin = createBackendPlugin((_options: TestOptions) => ({ id: 'x', - register(_reg, _options: TestOptions) {}, - }); + register() {}, + })); expect(plugin).toBeDefined(); expect(plugin({ a: 'a' })).toBeDefined(); expect(plugin({ a: 'a' }).id).toBe('x'); @@ -90,10 +90,10 @@ describe('createBackendPlugin', () => { interface TestOptions { a: string; } - const plugin = createBackendPlugin({ + const plugin = createBackendPlugin((_options?: TestOptions) => ({ id: 'x', - register(_reg, _options?: TestOptions) {}, - }); + register() {}, + })); expect(plugin).toBeDefined(); expect(plugin({ a: 'a' })).toBeDefined(); expect(plugin()).toBeDefined(); @@ -104,11 +104,11 @@ describe('createBackendPlugin', () => { describe('createBackendModule', () => { it('should create a BackendModule', () => { - const mod = createBackendModule({ + const mod = createBackendModule((_options: { a: string }) => ({ pluginId: 'x', moduleId: 'y', - register(_reg, _options: { a: string }) {}, - }); + register() {}, + })); expect(mod).toBeDefined(); expect(mod({ a: 'a' })).toBeDefined(); expect(mod({ a: 'a' }).id).toBe('x.y'); @@ -119,11 +119,11 @@ describe('createBackendModule', () => { }); it('should create modules with optional options', () => { - const mod = createBackendModule({ + const mod = createBackendModule((_options?: { a: string }) => ({ pluginId: 'x', moduleId: 'y', - register(_reg, _options?: { a: string }) {}, - }); + register() {}, + })); expect(mod).toBeDefined(); expect(mod({ a: 'a' })).toBeDefined(); expect(mod()).toBeDefined(); @@ -148,11 +148,11 @@ describe('createBackendModule', () => { interface TestOptions { a: string; } - const mod = createBackendModule({ + const mod = createBackendModule((_options: TestOptions) => ({ pluginId: 'x', moduleId: 'y', - register(_reg, _options: TestOptions) {}, - }); + register() {}, + })); expect(mod).toBeDefined(); expect(mod({ a: 'a' })).toBeDefined(); expect(mod({ a: 'a' }).id).toBe('x.y'); @@ -166,11 +166,11 @@ describe('createBackendModule', () => { interface TestOptions { a: string; } - const mod = createBackendModule({ + const mod = createBackendModule((_options?: TestOptions) => ({ pluginId: 'x', moduleId: 'y', - register(_reg, _options?: TestOptions) {}, - }); + register() {}, + })); expect(mod).toBeDefined(); expect(mod({ a: 'a' })).toBeDefined(); expect(mod()).toBeDefined(); diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index 4c384840cd..c9ccc9c0aa 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { FactoryFunctionWithOptions, MaybeOptions } from '../types'; +import { + FactoryFunctionWithOptions, + MaybeOptions, + FactoryFunctionConfig, +} from '../types'; import { BackendRegistrationPoints, BackendFeature, @@ -43,30 +47,28 @@ export function createExtensionPoint( } /** @public */ -export interface BackendPluginConfig { +export interface BackendPluginConfig { id: string; - register(reg: BackendRegistrationPoints, options: TOptions): void; + register(reg: BackendRegistrationPoints): void; } /** @public */ export function createBackendPlugin( - config: BackendPluginConfig, + config: FactoryFunctionConfig, ): FactoryFunctionWithOptions { - return (options?: TOptions) => ({ - id: config.id, - register(register: BackendRegistrationPoints) { - return config.register(register, options!); - }, - }); + if (typeof config === 'function') { + return config as FactoryFunctionWithOptions; + } + + return () => config; } /** @public */ -export interface BackendModuleConfig { +export interface BackendModuleConfig { pluginId: string; moduleId: string; register( reg: Omit, - options: TOptions, ): void; } @@ -85,13 +87,22 @@ export interface BackendModuleConfig { * The `pluginId` should exactly match the `id` of the plugin that the module extends. */ export function createBackendModule( - config: BackendModuleConfig, + config: FactoryFunctionConfig, ): FactoryFunctionWithOptions { - return (options?: TOptions) => ({ + if (typeof config === 'function') { + return (options?: TOptions) => { + const c = config(options!); + return { + id: `${c.pluginId}.${c.moduleId}`, + register: c.register, + }; + }; + } + return () => ({ id: `${config.pluginId}.${config.moduleId}`, register(register: BackendRegistrationPoints) { // TODO: Hide registerExtensionPoint - return config.register(register, options!); + return config.register(register); }, }); } From 4ed8ac14e028f16d1c24069ff68f8d7bf5859e3d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 11 Jan 2023 14:51:04 +0100 Subject: [PATCH 2/7] backend-plugin-api: refactor service factory to use new option callback pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Co-authored-by: blam Co-authored-by: Johan Haals Signed-off-by: Patrik Oldsberg --- .../src/services/system/types.test.ts | 96 +++++++++---------- .../src/services/system/types.ts | 27 ++++-- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/packages/backend-plugin-api/src/services/system/types.test.ts b/packages/backend-plugin-api/src/services/system/types.test.ts index 0e02f38d3f..4d39ba0f62 100644 --- a/packages/backend-plugin-api/src/services/system/types.test.ts +++ b/packages/backend-plugin-api/src/services/system/types.test.ts @@ -43,13 +43,13 @@ describe('createServiceFactory', () => { it('should create a meta factory with optional options', () => { const ref = createServiceRef({ id: 'x' }); - const metaFactory = createServiceFactory({ + const metaFactory = createServiceFactory((_opts?: { x: number }) => ({ service: ref, deps: {}, - async factory(_deps, _opts?: { x: number }) { + async factory() { return async () => 'x'; }, - }); + })); expect(metaFactory).toEqual(expect.any(Function)); // @ts-expect-error @@ -67,13 +67,13 @@ describe('createServiceFactory', () => { it('should create a meta factory with required options', () => { const ref = createServiceRef({ id: 'x' }); - const metaFactory = createServiceFactory({ + const metaFactory = createServiceFactory((_opts: { x: number }) => ({ service: ref, deps: {}, - async factory(_deps, _opts: { x: number }) { + async factory() { return async () => 'x'; }, - }); + })); expect(metaFactory).toEqual(expect.any(Function)); // @ts-expect-error @@ -96,13 +96,13 @@ describe('createServiceFactory', () => { x: number; } const ref = createServiceRef({ id: 'x' }); - const metaFactory = createServiceFactory({ + const metaFactory = createServiceFactory((_opts?: TestOptions) => ({ service: ref, deps: {}, - async factory(_deps, _opts?: TestOptions) { + async factory() { return async () => 'x'; }, - }); + })); expect(metaFactory).toEqual(expect.any(Function)); // @ts-expect-error @@ -123,13 +123,13 @@ describe('createServiceFactory', () => { x: number; } const ref = createServiceRef({ id: 'x' }); - const metaFactory = createServiceFactory({ + const metaFactory = createServiceFactory((_opts: TestOptions) => ({ service: ref, deps: {}, - async factory(_deps, _opts: TestOptions) { + async factory() { return async () => 'x'; }, - }); + })); expect(metaFactory).toEqual(expect.any(Function)); // @ts-expect-error @@ -149,78 +149,78 @@ describe('createServiceFactory', () => { it('should only allow objects as options', () => { const ref = createServiceRef({ id: 'x' }); - const metaFactory = createServiceFactory({ + // @ts-expect-error + const metaFactory = createServiceFactory((_opts: string) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: string) { + async factory() { return async () => 'x'; }, - }); + })); expect(metaFactory).toEqual(expect.any(Function)); - createServiceFactory({ + // @ts-expect-error + createServiceFactory((_opts: number) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: number) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: symbol) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: symbol) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: bigint) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: bigint) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: 'string') => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: 'string') { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: Array) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: Array) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: Map) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: Map) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: Set) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: Set) { + async factory() { return async () => 'x'; }, - }); - createServiceFactory({ + })); + // @ts-expect-error + createServiceFactory((_opts: null) => ({ service: ref, deps: {}, - // @ts-expect-error - async factory(_deps, _opts: null) { + async factory() { return async () => 'x'; }, - }); + })); }); }); diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index ffbbdb5f0c..89528f9fc4 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { FactoryFunctionWithOptions, MaybeOptions } from '../../types'; +import { + FactoryFunctionConfig, + FactoryFunctionWithOptions, + MaybeOptions, +} from '../../types'; /** * TODO @@ -144,13 +148,11 @@ export interface ServiceFactoryConfig< TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends { [name in string]: ServiceRef }, - TOpts extends MaybeOptions = undefined, > { service: ServiceRef; deps: TDeps; factory( deps: ServiceRefsToInstances, - options: TOpts, ): TScope extends 'root' ? Promise : Promise<(deps: ServiceRefsToInstances) => Promise>; @@ -166,15 +168,20 @@ export function createServiceFactory< TDeps extends { [name in string]: ServiceRef }, TOpts extends MaybeOptions = undefined, >( - config: ServiceFactoryConfig, + config: FactoryFunctionConfig< + ServiceFactoryConfig, + TOpts + >, ): FactoryFunctionWithOptions, TOpts> { - return (options?: TOpts) => + if (typeof config === 'function') { + return (opts?: TOpts) => { + const c = config(opts!); + return { ...c, scope: c.service.scope } as ServiceFactory; + }; + } + return () => ({ + ...config, scope: config.service.scope, - service: config.service, - deps: config.deps, - factory(deps: ServiceRefsToInstances) { - return config.factory(deps, options!); - }, } as ServiceFactory); } From 01a318f75d978f793c086a25738561c12af10ecf Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 11 Jan 2023 14:59:33 +0100 Subject: [PATCH 3/7] updates to use new option factory callback pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Co-authored-by: blam Co-authored-by: Johan Haals Signed-off-by: Patrik Oldsberg --- .../httpRouter/httpRouterFactory.ts | 40 +++--- .../src/wiring/ServiceRegistry.test.ts | 2 +- plugins/app-backend/src/service/appPlugin.ts | 6 +- ...talIngestionEntityProviderCatalogModule.ts | 85 ++++++------ .../src/ScaffolderPlugin.ts | 128 +++++++++--------- 5 files changed, 132 insertions(+), 129 deletions(-) diff --git a/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterFactory.ts b/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterFactory.ts index f1fc089ea3..8787b1ad9e 100644 --- a/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterFactory.ts +++ b/packages/backend-app-api/src/services/implementations/httpRouter/httpRouterFactory.ts @@ -23,30 +23,32 @@ import { Handler } from 'express'; /** * @public */ -export type HttpRouterFactoryOptions = { +export interface HttpRouterFactoryOptions { /** * A callback used to generate the path for each plugin, defaults to `/api/{pluginId}`. */ getPath(pluginId: string): string; -}; +} /** @public */ -export const httpRouterFactory = createServiceFactory({ - service: coreServices.httpRouter, - deps: { - plugin: coreServices.pluginMetadata, - rootHttpRouter: coreServices.rootHttpRouter, - }, - async factory({ rootHttpRouter }, options?: HttpRouterFactoryOptions) { - const getPath = options?.getPath ?? (id => `/api/${id}`); +export const httpRouterFactory = createServiceFactory( + (options?: HttpRouterFactoryOptions) => ({ + service: coreServices.httpRouter, + deps: { + plugin: coreServices.pluginMetadata, + rootHttpRouter: coreServices.rootHttpRouter, + }, + async factory({ rootHttpRouter }) { + const getPath = options?.getPath ?? (id => `/api/${id}`); - return async ({ plugin }) => { - const path = getPath(plugin.getId()); - return { - use(handler: Handler) { - rootHttpRouter.use(path, handler); - }, + return async ({ plugin }) => { + const path = getPath(plugin.getId()); + return { + use(handler: Handler) { + rootHttpRouter.use(path, handler); + }, + }; }; - }; - }, -}); + }, + }), +); diff --git a/packages/backend-app-api/src/wiring/ServiceRegistry.test.ts b/packages/backend-app-api/src/wiring/ServiceRegistry.test.ts index 9348f59d64..405a2fc630 100644 --- a/packages/backend-app-api/src/wiring/ServiceRegistry.test.ts +++ b/packages/backend-app-api/src/wiring/ServiceRegistry.test.ts @@ -143,7 +143,7 @@ describe('ServiceRegistry', () => { const factory = createServiceFactory({ service: ref1, deps: { rootDep: ref2 }, - async factory({ rootDep }) { + factory: async ({ rootDep }) => { return async () => ({ x: rootDep.x }); }, }); diff --git a/plugins/app-backend/src/service/appPlugin.ts b/plugins/app-backend/src/service/appPlugin.ts index 2c0c73c71b..b12a8d6877 100644 --- a/plugins/app-backend/src/service/appPlugin.ts +++ b/plugins/app-backend/src/service/appPlugin.ts @@ -70,9 +70,9 @@ export type AppPluginOptions = { * The App plugin is responsible for serving the frontend app bundle and static assets. * @alpha */ -export const appPlugin = createBackendPlugin({ +export const appPlugin = createBackendPlugin((options: AppPluginOptions) => ({ id: 'app', - register(env, options: AppPluginOptions) { + register(env) { env.registerInit({ deps: { logger: coreServices.logger, @@ -101,4 +101,4 @@ export const appPlugin = createBackendPlugin({ }, }); }, -}); +})); diff --git a/plugins/catalog-backend-module-incremental-ingestion/src/module/incrementalIngestionEntityProviderCatalogModule.ts b/plugins/catalog-backend-module-incremental-ingestion/src/module/incrementalIngestionEntityProviderCatalogModule.ts index 0ecb45292c..b173b2d2ef 100644 --- a/plugins/catalog-backend-module-incremental-ingestion/src/module/incrementalIngestionEntityProviderCatalogModule.ts +++ b/plugins/catalog-backend-module-incremental-ingestion/src/module/incrementalIngestionEntityProviderCatalogModule.ts @@ -31,51 +31,50 @@ import { WrapperProviders } from './WrapperProviders'; * @alpha */ export const incrementalIngestionEntityProviderCatalogModule = - createBackendModule({ - pluginId: 'catalog', - moduleId: 'incrementalIngestionEntityProvider', - register( - env, - options: { - providers: Array<{ - provider: IncrementalEntityProvider; - options: IncrementalEntityProviderOptions; - }>; - }, - ) { - env.registerInit({ - deps: { - catalog: catalogProcessingExtensionPoint, - config: coreServices.config, - database: coreServices.database, - httpRouter: coreServices.httpRouter, - logger: coreServices.logger, - scheduler: coreServices.scheduler, - }, - async init({ - catalog, - config, - database, - httpRouter, - logger, - scheduler, - }) { - const client = await database.getClient(); - - const providers = new WrapperProviders({ + createBackendModule( + (options: { + providers: Array<{ + provider: IncrementalEntityProvider; + options: IncrementalEntityProviderOptions; + }>; + }) => ({ + pluginId: 'catalog', + moduleId: 'incrementalIngestionEntityProvider', + register(env) { + env.registerInit({ + deps: { + catalog: catalogProcessingExtensionPoint, + config: coreServices.config, + database: coreServices.database, + httpRouter: coreServices.httpRouter, + logger: coreServices.logger, + scheduler: coreServices.scheduler, + }, + async init({ + catalog, config, + database, + httpRouter, logger, - client, scheduler, - }); + }) { + const client = await database.getClient(); - for (const entry of options.providers) { - const wrapped = providers.wrap(entry.provider, entry.options); - catalog.addEntityProvider(wrapped); - } + const providers = new WrapperProviders({ + config, + logger, + client, + scheduler, + }); - httpRouter.use(await providers.adminRouter()); - }, - }); - }, - }); + for (const entry of options.providers) { + const wrapped = providers.wrap(entry.provider, entry.options); + catalog.addEntityProvider(wrapped); + } + + httpRouter.use(await providers.adminRouter()); + }, + }); + }, + }), + ); diff --git a/plugins/scaffolder-backend/src/ScaffolderPlugin.ts b/plugins/scaffolder-backend/src/ScaffolderPlugin.ts index 5d4c16e2dc..71472abda6 100644 --- a/plugins/scaffolder-backend/src/ScaffolderPlugin.ts +++ b/plugins/scaffolder-backend/src/ScaffolderPlugin.ts @@ -70,72 +70,74 @@ export const scaffolderActionsExtensionPoint = * Catalog plugin * @alpha */ -export const scaffolderPlugin = createBackendPlugin({ - id: 'scaffolder', - register(env, options: ScaffolderPluginOptions) { - const actionsExtensions = new ScaffolderActionsExtensionPointImpl(); - env.registerExtensionPoint( - scaffolderActionsExtensionPoint, - actionsExtensions, - ); +export const scaffolderPlugin = createBackendPlugin( + (options: ScaffolderPluginOptions) => ({ + id: 'scaffolder', + register(env) { + const actionsExtensions = new ScaffolderActionsExtensionPointImpl(); + env.registerExtensionPoint( + scaffolderActionsExtensionPoint, + actionsExtensions, + ); - env.registerInit({ - deps: { - logger: coreServices.logger, - config: coreServices.config, - reader: coreServices.urlReader, - permissions: coreServices.permissions, - database: coreServices.database, - httpRouter: coreServices.httpRouter, - catalogClient: catalogServiceRef, - }, - async init({ - logger, - config, - reader, - database, - httpRouter, - catalogClient, - }) { - const { - additionalTemplateFilters, - taskBroker, - taskWorkers, - additionalTemplateGlobals, - } = options; - const log = loggerToWinstonLogger(logger); + env.registerInit({ + deps: { + logger: coreServices.logger, + config: coreServices.config, + reader: coreServices.urlReader, + permissions: coreServices.permissions, + database: coreServices.database, + httpRouter: coreServices.httpRouter, + catalogClient: catalogServiceRef, + }, + async init({ + logger, + config, + reader, + database, + httpRouter, + catalogClient, + }) { + const { + additionalTemplateFilters, + taskBroker, + taskWorkers, + additionalTemplateGlobals, + } = options; + const log = loggerToWinstonLogger(logger); - const actions = options.actions || [ - ...actionsExtensions.actions, - ...createBuiltinActions({ - integrations: ScmIntegrations.fromConfig(config), + const actions = options.actions || [ + ...actionsExtensions.actions, + ...createBuiltinActions({ + integrations: ScmIntegrations.fromConfig(config), + catalogClient, + reader, + config, + additionalTemplateFilters, + additionalTemplateGlobals, + }), + ]; + + const actionIds = actions.map(action => action.id).join(', '); + log.info( + `Starting scaffolder with the following actions enabled ${actionIds}`, + ); + + const router = await createRouter({ + logger: log, + config, + database, catalogClient, reader, - config, + actions, + taskBroker, + taskWorkers, additionalTemplateFilters, additionalTemplateGlobals, - }), - ]; - - const actionIds = actions.map(action => action.id).join(', '); - log.info( - `Starting scaffolder with the following actions enabled ${actionIds}`, - ); - - const router = await createRouter({ - logger: log, - config, - database, - catalogClient, - reader, - actions, - taskBroker, - taskWorkers, - additionalTemplateFilters, - additionalTemplateGlobals, - }); - httpRouter.use(router); - }, - }); - }, -}); + }); + httpRouter.use(router); + }, + }); + }, + }), +); From ce660bfd3d1fe27a54c13e920315947b1688236e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Jan 2023 01:12:22 +0100 Subject: [PATCH 4/7] backend-plugin-api: make factory funcs use params and switch service factories to new pattern Signed-off-by: Patrik Oldsberg --- .../src/services/system/types.test.ts | 95 +++++++++++++++++-- .../src/services/system/types.ts | 18 ++-- packages/backend-plugin-api/src/types.ts | 19 +--- .../src/wiring/factories.ts | 20 ++-- 4 files changed, 108 insertions(+), 44 deletions(-) diff --git a/packages/backend-plugin-api/src/services/system/types.test.ts b/packages/backend-plugin-api/src/services/system/types.test.ts index 4d39ba0f62..9cbc45151d 100644 --- a/packages/backend-plugin-api/src/services/system/types.test.ts +++ b/packages/backend-plugin-api/src/services/system/types.test.ts @@ -16,9 +16,12 @@ import { createServiceFactory, createServiceRef } from './types'; +const ref = createServiceRef({ id: 'x' }); +const rootDep = createServiceRef({ id: 'y', scope: 'root' }); +const pluginDep = createServiceRef({ id: 'z' }); + describe('createServiceFactory', () => { it('should create a meta factory with no options', () => { - const ref = createServiceRef({ id: 'x' }); const metaFactory = createServiceFactory({ service: ref, deps: {}, @@ -37,12 +40,12 @@ describe('createServiceFactory', () => { metaFactory({ x: 1 }); // @ts-expect-error metaFactory(null); + // @ts-expect-error metaFactory(undefined); metaFactory(); }); it('should create a meta factory with optional options', () => { - const ref = createServiceRef({ id: 'x' }); const metaFactory = createServiceFactory((_opts?: { x: number }) => ({ service: ref, deps: {}, @@ -66,7 +69,6 @@ describe('createServiceFactory', () => { }); it('should create a meta factory with required options', () => { - const ref = createServiceRef({ id: 'x' }); const metaFactory = createServiceFactory((_opts: { x: number }) => ({ service: ref, deps: {}, @@ -95,7 +97,6 @@ describe('createServiceFactory', () => { interface TestOptions { x: number; } - const ref = createServiceRef({ id: 'x' }); const metaFactory = createServiceFactory((_opts?: TestOptions) => ({ service: ref, deps: {}, @@ -122,7 +123,6 @@ describe('createServiceFactory', () => { interface TestOptions { x: number; } - const ref = createServiceRef({ id: 'x' }); const metaFactory = createServiceFactory((_opts: TestOptions) => ({ service: ref, deps: {}, @@ -147,8 +147,91 @@ describe('createServiceFactory', () => { metaFactory(); }); + it('should create factory with required options and dependencies', () => { + interface TestOptions { + x: number; + } + + function unused(..._any: any[]) {} + + const metaFactory = createServiceFactory((_opts: TestOptions) => ({ + service: ref, + deps: { + root: rootDep, + plugin: pluginDep, + }, + async factory({ root }) { + const root1: number = root; + // @ts-expect-error + const root2: string = root; + return async ({ plugin }) => { + const plugin3: boolean = plugin; + // @ts-expect-error + const plugin4: number = plugin; + unused(root1, root2, plugin3, plugin4); + return 'x'; + }; + }, + })); + expect(metaFactory).toEqual(expect.any(Function)); + + // @ts-expect-error + metaFactory('string'); + // @ts-expect-error + metaFactory({}); + metaFactory({ x: 1 }); + // @ts-expect-error + metaFactory({ x: 1, y: 2 }); + // @ts-expect-error + metaFactory(null); + // @ts-expect-error + metaFactory(undefined); + // @ts-expect-error + metaFactory(); + }); + + it('should create factory with optional options and dependencies', () => { + interface TestOptions { + x: number; + } + + function unused(..._any: any[]) {} + + const metaFactory = createServiceFactory((_opts?: TestOptions) => ({ + service: ref, + deps: { + root: rootDep, + plugin: pluginDep, + }, + async factory({ root }) { + const root1: number = root; + // @ts-expect-error + const root2: string = root; + return async ({ plugin }) => { + const plugin3: boolean = plugin; + // @ts-expect-error + const plugin4: number = plugin; + unused(root1, root2, plugin3, plugin4); + return 'x'; + }; + }, + })); + expect(metaFactory).toEqual(expect.any(Function)); + + // @ts-expect-error + metaFactory('string'); + // @ts-expect-error + metaFactory({}); + metaFactory({ x: 1 }); + // @ts-expect-error + metaFactory({ x: 1, y: 2 }); + // @ts-expect-error + metaFactory(null); + metaFactory(undefined); + metaFactory(); + }); + it('should only allow objects as options', () => { - const ref = createServiceRef({ id: 'x' }); // @ts-expect-error const metaFactory = createServiceFactory((_opts: string) => ({ service: ref, diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 89528f9fc4..e9fd7bf971 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import { - FactoryFunctionConfig, - FactoryFunctionWithOptions, - MaybeOptions, -} from '../../types'; +import { FactoryFunctionConfig, FactoryFunction } from '../../types'; /** * TODO @@ -137,9 +133,7 @@ type ServiceRefsToInstances< T extends { [key in string]: ServiceRef }, TScope extends 'root' | 'plugin' = 'root' | 'plugin', > = { - [name in { - [key in keyof T]: T[key] extends ServiceRef ? key : never; - }[keyof T]]: T[name] extends ServiceRef ? TImpl : never; + [key in keyof T as T[key]['scope'] extends TScope ? key : never]: T[key]['T']; }; /** @public */ @@ -166,16 +160,16 @@ export function createServiceFactory< TScope extends 'root' | 'plugin', TImpl extends TService, TDeps extends { [name in string]: ServiceRef }, - TOpts extends MaybeOptions = undefined, + TOpts extends [options?: object] = [], >( config: FactoryFunctionConfig< ServiceFactoryConfig, TOpts >, -): FactoryFunctionWithOptions, TOpts> { +): FactoryFunction, TOpts> { if (typeof config === 'function') { - return (opts?: TOpts) => { - const c = config(opts!); + return (...opts: TOpts) => { + const c = config(...opts); return { ...c, scope: c.service.scope } as ServiceFactory; }; } diff --git a/packages/backend-plugin-api/src/types.ts b/packages/backend-plugin-api/src/types.ts index 1bd9d43390..a9f2316662 100644 --- a/packages/backend-plugin-api/src/types.ts +++ b/packages/backend-plugin-api/src/types.ts @@ -15,26 +15,17 @@ */ /** - * Base type for options objects that aren't required. - * * @ignore */ -export type MaybeOptions = object | undefined; - -/** - * @ignore - */ -export type FactoryFunctionConfig = +export type FactoryFunctionConfig = | TConfig - | ((options: TOptions) => TConfig) - | (() => TConfig); + | ((...params: TParams) => TConfig); /** * Helper type that makes the options argument optional if options are not required. * * @ignore */ -export type FactoryFunctionWithOptions = - undefined extends TOptions - ? (options?: TOptions) => TResult - : (options: TOptions) => TResult; +export type FactoryFunction = ( + ...params: TParams +) => TResult; diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index c9ccc9c0aa..134471f7c1 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -14,11 +14,7 @@ * limitations under the License. */ -import { - FactoryFunctionWithOptions, - MaybeOptions, - FactoryFunctionConfig, -} from '../types'; +import { FactoryFunction, FactoryFunctionConfig } from '../types'; import { BackendRegistrationPoints, BackendFeature, @@ -53,11 +49,11 @@ export interface BackendPluginConfig { } /** @public */ -export function createBackendPlugin( +export function createBackendPlugin( config: FactoryFunctionConfig, -): FactoryFunctionWithOptions { +): FactoryFunction { if (typeof config === 'function') { - return config as FactoryFunctionWithOptions; + return config as FactoryFunction; } return () => config; @@ -86,12 +82,12 @@ export interface BackendModuleConfig { * * The `pluginId` should exactly match the `id` of the plugin that the module extends. */ -export function createBackendModule( +export function createBackendModule( config: FactoryFunctionConfig, -): FactoryFunctionWithOptions { +): FactoryFunction { if (typeof config === 'function') { - return (options?: TOptions) => { - const c = config(options!); + return (...options: TOptions) => { + const c = config(...options); return { id: `${c.pluginId}.${c.moduleId}`, register: c.register, From ecbec4ec4c2069a80e409138a4a6f57ff2c8ce45 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Jan 2023 10:21:47 +0100 Subject: [PATCH 5/7] changesets: added changeset for factory refactor Signed-off-by: Patrik Oldsberg --- .changeset/rich-bags-call.md | 8 ++++++++ .changeset/slow-pumas-tap.md | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/rich-bags-call.md create mode 100644 .changeset/slow-pumas-tap.md diff --git a/.changeset/rich-bags-call.md b/.changeset/rich-bags-call.md new file mode 100644 index 0000000000..ef9691bf74 --- /dev/null +++ b/.changeset/rich-bags-call.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch +'@backstage/plugin-scaffolder-backend': patch +'@backstage/backend-app-api': patch +'@backstage/plugin-app-backend': patch +--- + +Internal refactor to match new options pattern in the experimental backend system. diff --git a/.changeset/slow-pumas-tap.md b/.changeset/slow-pumas-tap.md new file mode 100644 index 0000000000..eabcb5fd94 --- /dev/null +++ b/.changeset/slow-pumas-tap.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-plugin-api': minor +--- + +Updated all factory function creators to accept options as a top-level callback rather than extra parameter to the main factory function. From d1e86013ef35ed70fde15cbd89a0c1ee2198a06c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Jan 2023 10:57:11 +0100 Subject: [PATCH 6/7] update API reports for backend system factory function refactor Signed-off-by: Patrik Oldsberg --- packages/backend-app-api/api-report.md | 101 ++++++++++-------- packages/backend-plugin-api/api-report.md | 30 +++--- plugins/app-backend/api-report.md | 6 +- .../catalog-backend-module-aws/api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 18 ++-- .../api-report.md | 8 +- plugins/catalog-backend/api-report.md | 3 +- .../api-report.md | 8 +- .../events-backend-module-azure/api-report.md | 8 +- .../api-report.md | 8 +- .../api-report.md | 5 +- .../api-report.md | 7 +- .../api-report.md | 7 +- plugins/events-backend/api-report.md | 3 +- plugins/scaffolder-backend/api-report.md | 10 +- 21 files changed, 159 insertions(+), 119 deletions(-) diff --git a/packages/backend-app-api/api-report.md b/packages/backend-app-api/api-report.md index b1356e93e3..57f146aad8 100644 --- a/packages/backend-app-api/api-report.md +++ b/packages/backend-app-api/api-report.md @@ -13,6 +13,7 @@ import { ErrorRequestHandler } from 'express'; import { Express as Express_2 } from 'express'; import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { Handler } from 'express'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { HelmetOptions } from 'helmet'; import * as http from 'http'; import { HttpRouterService } from '@backstage/backend-plugin-api'; @@ -46,14 +47,13 @@ export interface Backend { } // @public (undocumented) -export const cacheFactory: ( - options?: undefined, -) => ServiceFactory; +export const cacheFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) -export const configFactory: ( - options?: undefined, -) => ServiceFactory; +export const configFactory: FactoryFunction, []>; // @public export function createHttpServer( @@ -76,9 +76,10 @@ export interface CreateSpecializedBackendOptions { } // @public (undocumented) -export const databaseFactory: ( - options?: undefined, -) => ServiceFactory; +export const databaseFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public export class DefaultRootHttpRouter implements RootHttpRouterService { @@ -96,9 +97,10 @@ export interface DefaultRootHttpRouterOptions { } // @public (undocumented) -export const discoveryFactory: ( - options?: undefined, -) => ServiceFactory; +export const discoveryFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public export interface ExtendedHttpServer extends http.Server { @@ -111,14 +113,15 @@ export interface ExtendedHttpServer extends http.Server { } // @public (undocumented) -export const httpRouterFactory: ( - options?: HttpRouterFactoryOptions | undefined, -) => ServiceFactory; +export const httpRouterFactory: FactoryFunction< + ServiceFactory, + [options?: HttpRouterFactoryOptions | undefined] +>; // @public (undocumented) -export type HttpRouterFactoryOptions = { +export interface HttpRouterFactoryOptions { getPath(pluginId: string): string; -}; +} // @public export type HttpServerCertificateOptions = @@ -144,9 +147,10 @@ export type HttpServerOptions = { }; // @public (undocumented) -export const identityFactory: ( - options?: IdentityFactoryOptions | undefined, -) => ServiceFactory; +export const identityFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public export type IdentityFactoryOptions = { @@ -155,14 +159,13 @@ export type IdentityFactoryOptions = { }; // @public -export const lifecycleFactory: ( - options?: undefined, -) => ServiceFactory; +export const lifecycleFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) -export const loggerFactory: ( - options?: undefined, -) => ServiceFactory; +export const loggerFactory: FactoryFunction, []>; // @public export class MiddlewareFactory { @@ -190,9 +193,10 @@ export interface MiddlewareFactoryOptions { } // @public (undocumented) -export const permissionsFactory: ( - options?: undefined, -) => ServiceFactory; +export const permissionsFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public export function readCorsOptions(config?: Config): CorsOptions; @@ -220,9 +224,10 @@ export interface RootHttpRouterConfigureOptions { } // @public (undocumented) -export const rootHttpRouterFactory: ( - options?: RootHttpRouterFactoryOptions | undefined, -) => ServiceFactory; +export const rootHttpRouterFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) export type RootHttpRouterFactoryOptions = { @@ -231,19 +236,22 @@ export type RootHttpRouterFactoryOptions = { }; // @public -export const rootLifecycleFactory: ( - options?: undefined, -) => ServiceFactory; +export const rootLifecycleFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) -export const rootLoggerFactory: ( - options?: undefined, -) => ServiceFactory; +export const rootLoggerFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) -export const schedulerFactory: ( - options?: undefined, -) => ServiceFactory; +export const schedulerFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) export type ServiceOrExtensionPoint = @@ -251,12 +259,11 @@ export type ServiceOrExtensionPoint = | ServiceRef; // @public (undocumented) -export const tokenManagerFactory: ( - options?: undefined, -) => ServiceFactory; +export const tokenManagerFactory: FactoryFunction< + ServiceFactory, + [] +>; // @public (undocumented) -export const urlReaderFactory: ( - options?: undefined, -) => ServiceFactory; +export const urlReaderFactory: FactoryFunction, []>; ``` diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 213815f782..848744297e 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -23,7 +23,7 @@ export interface BackendFeature { } // @public (undocumented) -export interface BackendModuleConfig { +export interface BackendModuleConfig { // (undocumented) moduleId: string; // (undocumented) @@ -31,16 +31,15 @@ export interface BackendModuleConfig { // (undocumented) register( reg: Omit, - options: TOptions, ): void; } // @public (undocumented) -export interface BackendPluginConfig { +export interface BackendPluginConfig { // (undocumented) id: string; // (undocumented) - register(reg: BackendRegistrationPoints, options: TOptions): void; + register(reg: BackendRegistrationPoints): void; } // @public (undocumented) @@ -113,14 +112,14 @@ export namespace coreServices { } // @public -export function createBackendModule( - config: BackendModuleConfig, -): FactoryFunctionWithOptions; +export function createBackendModule( + config: FactoryFunctionConfig, +): FactoryFunction; // @public (undocumented) -export function createBackendPlugin( - config: BackendPluginConfig, -): FactoryFunctionWithOptions; +export function createBackendPlugin( + config: FactoryFunctionConfig, +): FactoryFunction; // @public (undocumented) export function createExtensionPoint( @@ -135,10 +134,13 @@ export function createServiceFactory< TDeps extends { [name in string]: ServiceRef; }, - TOpts extends MaybeOptions = undefined, + TOpts extends [options?: object] = [], >( - config: ServiceFactoryConfig, -): FactoryFunctionWithOptions, TOpts>; + config: FactoryFunctionConfig< + ServiceFactoryConfig, + TOpts + >, +): FactoryFunction, TOpts>; // @public export function createServiceRef( @@ -337,14 +339,12 @@ export interface ServiceFactoryConfig< TDeps extends { [name in string]: ServiceRef; }, - TOpts extends MaybeOptions = undefined, > { // (undocumented) deps: TDeps; // (undocumented) factory( deps: ServiceRefsToInstances, - options: TOpts, ): TScope extends 'root' ? Promise : Promise<(deps: ServiceRefsToInstances) => Promise>; diff --git a/plugins/app-backend/api-report.md b/plugins/app-backend/api-report.md index b52132ef51..1a430879e8 100644 --- a/plugins/app-backend/api-report.md +++ b/plugins/app-backend/api-report.md @@ -6,11 +6,15 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import express from 'express'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; // @alpha -export const appPlugin: (options: AppPluginOptions) => BackendFeature; +export const appPlugin: FactoryFunction< + BackendFeature, + [options: AppPluginOptions] +>; // @alpha (undocumented) export type AppPluginOptions = { diff --git a/plugins/catalog-backend-module-aws/api-report.md b/plugins/catalog-backend-module-aws/api-report.md index a911fb5ebb..a054c48428 100644 --- a/plugins/catalog-backend-module-aws/api-report.md +++ b/plugins/catalog-backend-module-aws/api-report.md @@ -11,6 +11,7 @@ import { Config } from '@backstage/config'; import { Credentials } from 'aws-sdk'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -90,7 +91,8 @@ export class AwsS3EntityProvider implements EntityProvider { } // @alpha -export const awsS3EntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const awsS3EntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/catalog-backend-module-azure/api-report.md b/plugins/catalog-backend-module-azure/api-report.md index 84ffaf39e9..e7599a4d31 100644 --- a/plugins/catalog-backend-module-azure/api-report.md +++ b/plugins/catalog-backend-module-azure/api-report.md @@ -9,6 +9,7 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -58,7 +59,8 @@ export class AzureDevOpsEntityProvider implements EntityProvider { } // @alpha -export const azureDevOpsEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const azureDevOpsEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/catalog-backend-module-bitbucket-cloud/api-report.md b/plugins/catalog-backend-module-bitbucket-cloud/api-report.md index 480395e477..af9aa834ec 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/api-report.md +++ b/plugins/catalog-backend-module-bitbucket-cloud/api-report.md @@ -11,6 +11,7 @@ import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; import { EventParams } from '@backstage/plugin-events-node'; import { Events } from '@backstage/plugin-bitbucket-cloud-common'; import { EventSubscriber } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { TaskRunner } from '@backstage/backend-tasks'; @@ -48,7 +49,8 @@ export class BitbucketCloudEntityProvider } // @alpha (undocumented) -export const bitbucketCloudEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const bitbucketCloudEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/catalog-backend-module-bitbucket-server/api-report.md b/plugins/catalog-backend-module-bitbucket-server/api-report.md index a38a4d8c35..41ed476c13 100644 --- a/plugins/catalog-backend-module-bitbucket-server/api-report.md +++ b/plugins/catalog-backend-module-bitbucket-server/api-report.md @@ -9,6 +9,7 @@ import { Config } from '@backstage/config'; import { Entity } from '@backstage/catalog-model'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -69,9 +70,10 @@ export class BitbucketServerEntityProvider implements EntityProvider { } // @alpha (undocumented) -export const bitbucketServerEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const bitbucketServerEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; // @public (undocumented) export type BitbucketServerListOptions = { diff --git a/plugins/catalog-backend-module-gerrit/api-report.md b/plugins/catalog-backend-module-gerrit/api-report.md index 45847ea93d..99387a1b60 100644 --- a/plugins/catalog-backend-module-gerrit/api-report.md +++ b/plugins/catalog-backend-module-gerrit/api-report.md @@ -7,6 +7,7 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { TaskRunner } from '@backstage/backend-tasks'; @@ -31,9 +32,10 @@ export class GerritEntityProvider implements EntityProvider { } // @alpha (undocumented) -export const gerritEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const gerritEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/catalog-backend-module-github/api-report.md b/plugins/catalog-backend-module-github/api-report.md index 78ffd5b018..e09658dfc1 100644 --- a/plugins/catalog-backend-module-github/api-report.md +++ b/plugins/catalog-backend-module-github/api-report.md @@ -13,6 +13,7 @@ import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; import { EventParams } from '@backstage/plugin-events-node'; import { EventSubscriber } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GithubCredentialsProvider } from '@backstage/integration'; import { GithubIntegrationConfig } from '@backstage/integration'; import { graphql } from '@octokit/graphql'; @@ -101,9 +102,10 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { } // @alpha -export const githubEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const githubEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; // @public (undocumented) export class GithubLocationAnalyzer implements ScmLocationAnalyzer { diff --git a/plugins/catalog-backend-module-gitlab/api-report.md b/plugins/catalog-backend-module-gitlab/api-report.md index 9ed90a2c42..21b0d9fdc3 100644 --- a/plugins/catalog-backend-module-gitlab/api-report.md +++ b/plugins/catalog-backend-module-gitlab/api-report.md @@ -9,6 +9,7 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -34,9 +35,10 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider { } // @alpha -export const gitlabDiscoveryEntityProviderCatalogModule: ( - options?: undefined, -) => BackendFeature; +export const gitlabDiscoveryEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; // @public export class GitLabDiscoveryProcessor implements CatalogProcessor { diff --git a/plugins/catalog-backend-module-incremental-ingestion/api-report.md b/plugins/catalog-backend-module-incremental-ingestion/api-report.md index 387e505c33..5dc0c45551 100644 --- a/plugins/catalog-backend-module-incremental-ingestion/api-report.md +++ b/plugins/catalog-backend-module-incremental-ingestion/api-report.md @@ -10,6 +10,7 @@ import { CatalogBuilder } from '@backstage/plugin-catalog-backend'; import type { Config } from '@backstage/config'; import type { DeferredEntity } from '@backstage/plugin-catalog-backend'; import type { DurationObjectUnits } from 'luxon'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import type { Logger } from 'winston'; import type { PermissionEvaluator } from '@backstage/plugin-permission-common'; import type { PluginDatabaseManager } from '@backstage/backend-common'; @@ -68,12 +69,17 @@ export interface IncrementalEntityProviderOptions { } // @alpha -export const incrementalIngestionEntityProviderCatalogModule: (options: { - providers: { - provider: IncrementalEntityProvider; - options: IncrementalEntityProviderOptions; - }[]; -}) => BackendFeature; +export const incrementalIngestionEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [ + options: { + providers: { + provider: IncrementalEntityProvider; + options: IncrementalEntityProviderOptions; + }[]; + }, + ] +>; // @public (undocumented) export type PluginEnvironment = { diff --git a/plugins/catalog-backend-module-msgraph/api-report.md b/plugins/catalog-backend-module-msgraph/api-report.md index 921d682b89..9a0f8cc0db 100644 --- a/plugins/catalog-backend-module-msgraph/api-report.md +++ b/plugins/catalog-backend-module-msgraph/api-report.md @@ -9,6 +9,7 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GroupEntity } from '@backstage/catalog-model'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; @@ -135,9 +136,10 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { } // @alpha -export const microsoftGraphOrgEntityProviderCatalogModule: ( - options?: MicrosoftGraphOrgEntityProviderCatalogModuleOptions | undefined, -) => BackendFeature; +export const microsoftGraphOrgEntityProviderCatalogModule: FactoryFunction< + BackendFeature, + [] +>; // @alpha export interface MicrosoftGraphOrgEntityProviderCatalogModuleOptions { diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 3e6c5ef676..ac5d42a6e9 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -34,6 +34,7 @@ import { EntityProvider } from '@backstage/plugin-catalog-node'; import { EntityProviderConnection } from '@backstage/plugin-catalog-node'; import { EntityProviderMutation } from '@backstage/plugin-catalog-node'; import { EntityRelationSpec } from '@backstage/plugin-catalog-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GetEntitiesRequest } from '@backstage/catalog-client'; import { JsonValue } from '@backstage/types'; import { LocationEntityV1alpha1 } from '@backstage/catalog-model'; @@ -237,7 +238,7 @@ export type CatalogPermissionRule< > = PermissionRule; // @alpha -export const catalogPlugin: (options?: undefined) => BackendFeature; +export const catalogPlugin: FactoryFunction; // @public export interface CatalogProcessingEngine { diff --git a/plugins/events-backend-module-aws-sqs/api-report.md b/plugins/events-backend-module-aws-sqs/api-report.md index 79a422c9f3..b50ba0884e 100644 --- a/plugins/events-backend-module-aws-sqs/api-report.md +++ b/plugins/events-backend-module-aws-sqs/api-report.md @@ -7,6 +7,7 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventBroker } from '@backstage/plugin-events-node'; import { EventPublisher } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -23,7 +24,8 @@ export class AwsSqsConsumingEventPublisher implements EventPublisher { } // @alpha -export const awsSqsConsumingEventPublisherEventsModule: ( - options?: undefined, -) => BackendFeature; +export const awsSqsConsumingEventPublisherEventsModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/events-backend-module-azure/api-report.md b/plugins/events-backend-module-azure/api-report.md index 510ec91c47..d974bfee6b 100644 --- a/plugins/events-backend-module-azure/api-report.md +++ b/plugins/events-backend-module-azure/api-report.md @@ -5,6 +5,7 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -15,7 +16,8 @@ export class AzureDevOpsEventRouter extends SubTopicEventRouter { } // @alpha -export const azureDevOpsEventRouterEventsModule: ( - options?: undefined, -) => BackendFeature; +export const azureDevOpsEventRouterEventsModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/events-backend-module-bitbucket-cloud/api-report.md b/plugins/events-backend-module-bitbucket-cloud/api-report.md index 0e4acfac91..69f5570cf5 100644 --- a/plugins/events-backend-module-bitbucket-cloud/api-report.md +++ b/plugins/events-backend-module-bitbucket-cloud/api-report.md @@ -5,6 +5,7 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -15,7 +16,8 @@ export class BitbucketCloudEventRouter extends SubTopicEventRouter { } // @alpha -export const bitbucketCloudEventRouterEventsModule: ( - options?: undefined, -) => BackendFeature; +export const bitbucketCloudEventRouterEventsModule: FactoryFunction< + BackendFeature, + [] +>; ``` diff --git a/plugins/events-backend-module-gerrit/api-report.md b/plugins/events-backend-module-gerrit/api-report.md index 268e5970fa..868505f773 100644 --- a/plugins/events-backend-module-gerrit/api-report.md +++ b/plugins/events-backend-module-gerrit/api-report.md @@ -5,6 +5,7 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -15,7 +16,5 @@ export class GerritEventRouter extends SubTopicEventRouter { } // @alpha -export const gerritEventRouterEventsModule: ( - options?: undefined, -) => BackendFeature; +export const gerritEventRouterEventsModule: FactoryFunction; ``` diff --git a/plugins/events-backend-module-github/api-report.md b/plugins/events-backend-module-github/api-report.md index b2a4425ae6..3b8905f6b0 100644 --- a/plugins/events-backend-module-github/api-report.md +++ b/plugins/events-backend-module-github/api-report.md @@ -6,6 +6,7 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventParams } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { RequestValidator } from '@backstage/plugin-events-node'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; @@ -22,10 +23,8 @@ export class GithubEventRouter extends SubTopicEventRouter { } // @alpha -export const githubEventRouterEventsModule: ( - options?: undefined, -) => BackendFeature; +export const githubEventRouterEventsModule: FactoryFunction; // @alpha -export const githubWebhookEventsModule: (options?: undefined) => BackendFeature; +export const githubWebhookEventsModule: FactoryFunction; ``` diff --git a/plugins/events-backend-module-gitlab/api-report.md b/plugins/events-backend-module-gitlab/api-report.md index 8f130902a2..4900b548a9 100644 --- a/plugins/events-backend-module-gitlab/api-report.md +++ b/plugins/events-backend-module-gitlab/api-report.md @@ -6,6 +6,7 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventParams } from '@backstage/plugin-events-node'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { RequestValidator } from '@backstage/plugin-events-node'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; @@ -20,10 +21,8 @@ export class GitlabEventRouter extends SubTopicEventRouter { } // @alpha -export const gitlabEventRouterEventsModule: ( - options?: undefined, -) => BackendFeature; +export const gitlabEventRouterEventsModule: FactoryFunction; // @alpha -export const gitlabWebhookEventsModule: (options?: undefined) => BackendFeature; +export const gitlabWebhookEventsModule: FactoryFunction; ``` diff --git a/plugins/events-backend/api-report.md b/plugins/events-backend/api-report.md index 69d7600ed3..87700237b9 100644 --- a/plugins/events-backend/api-report.md +++ b/plugins/events-backend/api-report.md @@ -9,6 +9,7 @@ import { EventBroker } from '@backstage/plugin-events-node'; import { EventPublisher } from '@backstage/plugin-events-node'; import { EventSubscriber } from '@backstage/plugin-events-node'; import express from 'express'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { HttpPostIngressOptions } from '@backstage/plugin-events-node'; import { Logger } from 'winston'; @@ -29,7 +30,7 @@ export class EventsBackend { } // @alpha -export const eventsPlugin: (options?: undefined) => BackendFeature; +export const eventsPlugin: FactoryFunction; // @public export class HttpPostIngressEventPublisher implements EventPublisher { diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index c89ead6d2b..29590f76b1 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -13,6 +13,7 @@ import { Config } from '@backstage/config'; import { createPullRequest } from 'octokit-plugin-create-pull-request'; import { Entity } from '@backstage/catalog-model'; import express from 'express'; +import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GithubCredentialsProvider } from '@backstage/integration'; import { IdentityApi } from '@backstage/plugin-auth-node'; import { JsonObject } from '@backstage/types'; @@ -625,7 +626,7 @@ export type RunCommandOptions = { }; // @alpha -export const scaffolderCatalogModule: (options?: undefined) => BackendFeature; +export const scaffolderCatalogModule: FactoryFunction; // @public (undocumented) export class ScaffolderEntitiesProcessor implements CatalogProcessor { @@ -642,9 +643,10 @@ export class ScaffolderEntitiesProcessor implements CatalogProcessor { } // @alpha -export const scaffolderPlugin: ( - options: ScaffolderPluginOptions, -) => BackendFeature; +export const scaffolderPlugin: FactoryFunction< + BackendFeature, + [options: ScaffolderPluginOptions] +>; // @alpha export type ScaffolderPluginOptions = { From 635287ead1ba4ce35df323bf8103bc7f4638db00 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Jan 2023 14:42:18 +0100 Subject: [PATCH 7/7] backend-plugin-api: remove factory function helper types Signed-off-by: Patrik Oldsberg --- packages/backend-app-api/api-report.md | 69 +++++-------------- packages/backend-plugin-api/api-report.md | 19 ++--- .../src/services/system/types.ts | 13 ++-- packages/backend-plugin-api/src/types.ts | 31 --------- .../src/wiring/factories.ts | 11 ++- .../next/implementations/mockConfigService.ts | 16 +++-- plugins/app-backend/api-report.md | 6 +- .../catalog-backend-module-aws/api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 18 ++--- .../api-report.md | 6 +- plugins/catalog-backend/api-report.md | 3 +- .../api-report.md | 6 +- .../events-backend-module-azure/api-report.md | 6 +- .../api-report.md | 6 +- .../api-report.md | 3 +- .../api-report.md | 5 +- .../api-report.md | 5 +- plugins/events-backend/api-report.md | 3 +- plugins/scaffolder-backend/api-report.md | 10 ++- 25 files changed, 76 insertions(+), 202 deletions(-) delete mode 100644 packages/backend-plugin-api/src/types.ts diff --git a/packages/backend-app-api/api-report.md b/packages/backend-app-api/api-report.md index 57f146aad8..199b0863de 100644 --- a/packages/backend-app-api/api-report.md +++ b/packages/backend-app-api/api-report.md @@ -13,7 +13,6 @@ import { ErrorRequestHandler } from 'express'; import { Express as Express_2 } from 'express'; import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { Handler } from 'express'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { HelmetOptions } from 'helmet'; import * as http from 'http'; import { HttpRouterService } from '@backstage/backend-plugin-api'; @@ -47,13 +46,10 @@ export interface Backend { } // @public (undocumented) -export const cacheFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const cacheFactory: () => ServiceFactory; // @public (undocumented) -export const configFactory: FactoryFunction, []>; +export const configFactory: () => ServiceFactory; // @public export function createHttpServer( @@ -76,10 +72,7 @@ export interface CreateSpecializedBackendOptions { } // @public (undocumented) -export const databaseFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const databaseFactory: () => ServiceFactory; // @public export class DefaultRootHttpRouter implements RootHttpRouterService { @@ -97,10 +90,7 @@ export interface DefaultRootHttpRouterOptions { } // @public (undocumented) -export const discoveryFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const discoveryFactory: () => ServiceFactory; // @public export interface ExtendedHttpServer extends http.Server { @@ -113,10 +103,9 @@ export interface ExtendedHttpServer extends http.Server { } // @public (undocumented) -export const httpRouterFactory: FactoryFunction< - ServiceFactory, - [options?: HttpRouterFactoryOptions | undefined] ->; +export const httpRouterFactory: ( + options?: HttpRouterFactoryOptions | undefined, +) => ServiceFactory; // @public (undocumented) export interface HttpRouterFactoryOptions { @@ -147,10 +136,7 @@ export type HttpServerOptions = { }; // @public (undocumented) -export const identityFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const identityFactory: () => ServiceFactory; // @public export type IdentityFactoryOptions = { @@ -159,13 +145,10 @@ export type IdentityFactoryOptions = { }; // @public -export const lifecycleFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const lifecycleFactory: () => ServiceFactory; // @public (undocumented) -export const loggerFactory: FactoryFunction, []>; +export const loggerFactory: () => ServiceFactory; // @public export class MiddlewareFactory { @@ -193,10 +176,7 @@ export interface MiddlewareFactoryOptions { } // @public (undocumented) -export const permissionsFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const permissionsFactory: () => ServiceFactory; // @public export function readCorsOptions(config?: Config): CorsOptions; @@ -224,10 +204,7 @@ export interface RootHttpRouterConfigureOptions { } // @public (undocumented) -export const rootHttpRouterFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const rootHttpRouterFactory: () => ServiceFactory; // @public (undocumented) export type RootHttpRouterFactoryOptions = { @@ -236,22 +213,13 @@ export type RootHttpRouterFactoryOptions = { }; // @public -export const rootLifecycleFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const rootLifecycleFactory: () => ServiceFactory; // @public (undocumented) -export const rootLoggerFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const rootLoggerFactory: () => ServiceFactory; // @public (undocumented) -export const schedulerFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const schedulerFactory: () => ServiceFactory; // @public (undocumented) export type ServiceOrExtensionPoint = @@ -259,11 +227,8 @@ export type ServiceOrExtensionPoint = | ServiceRef; // @public (undocumented) -export const tokenManagerFactory: FactoryFunction< - ServiceFactory, - [] ->; +export const tokenManagerFactory: () => ServiceFactory; // @public (undocumented) -export const urlReaderFactory: FactoryFunction, []>; +export const urlReaderFactory: () => ServiceFactory; ``` diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 848744297e..33190277c9 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -113,13 +113,13 @@ export namespace coreServices { // @public export function createBackendModule( - config: FactoryFunctionConfig, -): FactoryFunction; + config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig), +): (...params: TOptions) => BackendFeature; // @public (undocumented) export function createBackendPlugin( - config: FactoryFunctionConfig, -): FactoryFunction; + config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig), +): (...params: TOptions) => BackendFeature; // @public (undocumented) export function createExtensionPoint( @@ -136,11 +136,12 @@ export function createServiceFactory< }, TOpts extends [options?: object] = [], >( - config: FactoryFunctionConfig< - ServiceFactoryConfig, - TOpts - >, -): FactoryFunction, TOpts>; + config: + | ServiceFactoryConfig + | (( + ...options: TOpts + ) => ServiceFactoryConfig), +): (...params: TOpts) => ServiceFactory; // @public export function createServiceRef( diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index e9fd7bf971..34c0a50005 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import { FactoryFunctionConfig, FactoryFunction } from '../../types'; - /** * TODO * @@ -162,11 +160,12 @@ export function createServiceFactory< TDeps extends { [name in string]: ServiceRef }, TOpts extends [options?: object] = [], >( - config: FactoryFunctionConfig< - ServiceFactoryConfig, - TOpts - >, -): FactoryFunction, TOpts> { + config: + | ServiceFactoryConfig + | (( + ...options: TOpts + ) => ServiceFactoryConfig), +): (...params: TOpts) => ServiceFactory { if (typeof config === 'function') { return (...opts: TOpts) => { const c = config(...opts); diff --git a/packages/backend-plugin-api/src/types.ts b/packages/backend-plugin-api/src/types.ts deleted file mode 100644 index a9f2316662..0000000000 --- a/packages/backend-plugin-api/src/types.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @ignore - */ -export type FactoryFunctionConfig = - | TConfig - | ((...params: TParams) => TConfig); - -/** - * Helper type that makes the options argument optional if options are not required. - * - * @ignore - */ -export type FactoryFunction = ( - ...params: TParams -) => TResult; diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index 134471f7c1..31a64778f2 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { FactoryFunction, FactoryFunctionConfig } from '../types'; import { BackendRegistrationPoints, BackendFeature, @@ -50,10 +49,10 @@ export interface BackendPluginConfig { /** @public */ export function createBackendPlugin( - config: FactoryFunctionConfig, -): FactoryFunction { + config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig), +): (...params: TOptions) => BackendFeature { if (typeof config === 'function') { - return config as FactoryFunction; + return config; } return () => config; @@ -83,8 +82,8 @@ export interface BackendModuleConfig { * The `pluginId` should exactly match the `id` of the plugin that the module extends. */ export function createBackendModule( - config: FactoryFunctionConfig, -): FactoryFunction { + config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig), +): (...params: TOptions) => BackendFeature { if (typeof config === 'function') { return (...options: TOptions) => { const c = config(...options); diff --git a/packages/backend-test-utils/src/next/implementations/mockConfigService.ts b/packages/backend-test-utils/src/next/implementations/mockConfigService.ts index 78a670585d..a5578b866f 100644 --- a/packages/backend-test-utils/src/next/implementations/mockConfigService.ts +++ b/packages/backend-test-utils/src/next/implementations/mockConfigService.ts @@ -22,10 +22,12 @@ import { ConfigReader } from '@backstage/config'; import { JsonObject } from '@backstage/types'; /** @public */ -export const mockConfigFactory = createServiceFactory({ - service: coreServices.config, - deps: {}, - async factory(_, options?: { data?: JsonObject }) { - return new ConfigReader(options?.data, 'mock-config'); - }, -}); +export const mockConfigFactory = createServiceFactory( + (options?: { data?: JsonObject }) => ({ + service: coreServices.config, + deps: {}, + async factory() { + return new ConfigReader(options?.data, 'mock-config'); + }, + }), +); diff --git a/plugins/app-backend/api-report.md b/plugins/app-backend/api-report.md index 1a430879e8..b52132ef51 100644 --- a/plugins/app-backend/api-report.md +++ b/plugins/app-backend/api-report.md @@ -6,15 +6,11 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import express from 'express'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; // @alpha -export const appPlugin: FactoryFunction< - BackendFeature, - [options: AppPluginOptions] ->; +export const appPlugin: (options: AppPluginOptions) => BackendFeature; // @alpha (undocumented) export type AppPluginOptions = { diff --git a/plugins/catalog-backend-module-aws/api-report.md b/plugins/catalog-backend-module-aws/api-report.md index a054c48428..63b85f223b 100644 --- a/plugins/catalog-backend-module-aws/api-report.md +++ b/plugins/catalog-backend-module-aws/api-report.md @@ -11,7 +11,6 @@ import { Config } from '@backstage/config'; import { Credentials } from 'aws-sdk'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -91,8 +90,5 @@ export class AwsS3EntityProvider implements EntityProvider { } // @alpha -export const awsS3EntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const awsS3EntityProviderCatalogModule: () => BackendFeature; ``` diff --git a/plugins/catalog-backend-module-azure/api-report.md b/plugins/catalog-backend-module-azure/api-report.md index e7599a4d31..5ffae14b6b 100644 --- a/plugins/catalog-backend-module-azure/api-report.md +++ b/plugins/catalog-backend-module-azure/api-report.md @@ -9,7 +9,6 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -59,8 +58,5 @@ export class AzureDevOpsEntityProvider implements EntityProvider { } // @alpha -export const azureDevOpsEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const azureDevOpsEntityProviderCatalogModule: () => BackendFeature; ``` diff --git a/plugins/catalog-backend-module-bitbucket-cloud/api-report.md b/plugins/catalog-backend-module-bitbucket-cloud/api-report.md index af9aa834ec..7ad6b3b3e0 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/api-report.md +++ b/plugins/catalog-backend-module-bitbucket-cloud/api-report.md @@ -11,7 +11,6 @@ import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; import { EventParams } from '@backstage/plugin-events-node'; import { Events } from '@backstage/plugin-bitbucket-cloud-common'; import { EventSubscriber } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { TaskRunner } from '@backstage/backend-tasks'; @@ -49,8 +48,5 @@ export class BitbucketCloudEntityProvider } // @alpha (undocumented) -export const bitbucketCloudEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const bitbucketCloudEntityProviderCatalogModule: () => BackendFeature; ``` diff --git a/plugins/catalog-backend-module-bitbucket-server/api-report.md b/plugins/catalog-backend-module-bitbucket-server/api-report.md index 41ed476c13..213f5d2573 100644 --- a/plugins/catalog-backend-module-bitbucket-server/api-report.md +++ b/plugins/catalog-backend-module-bitbucket-server/api-report.md @@ -9,7 +9,6 @@ import { Config } from '@backstage/config'; import { Entity } from '@backstage/catalog-model'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -70,10 +69,7 @@ export class BitbucketServerEntityProvider implements EntityProvider { } // @alpha (undocumented) -export const bitbucketServerEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const bitbucketServerEntityProviderCatalogModule: () => BackendFeature; // @public (undocumented) export type BitbucketServerListOptions = { diff --git a/plugins/catalog-backend-module-gerrit/api-report.md b/plugins/catalog-backend-module-gerrit/api-report.md index 99387a1b60..870937f7ec 100644 --- a/plugins/catalog-backend-module-gerrit/api-report.md +++ b/plugins/catalog-backend-module-gerrit/api-report.md @@ -7,7 +7,6 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { TaskRunner } from '@backstage/backend-tasks'; @@ -32,10 +31,7 @@ export class GerritEntityProvider implements EntityProvider { } // @alpha (undocumented) -export const gerritEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const gerritEntityProviderCatalogModule: () => BackendFeature; // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/catalog-backend-module-github/api-report.md b/plugins/catalog-backend-module-github/api-report.md index e09658dfc1..a66ec712c7 100644 --- a/plugins/catalog-backend-module-github/api-report.md +++ b/plugins/catalog-backend-module-github/api-report.md @@ -13,7 +13,6 @@ import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; import { EventParams } from '@backstage/plugin-events-node'; import { EventSubscriber } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GithubCredentialsProvider } from '@backstage/integration'; import { GithubIntegrationConfig } from '@backstage/integration'; import { graphql } from '@octokit/graphql'; @@ -102,10 +101,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { } // @alpha -export const githubEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const githubEntityProviderCatalogModule: () => BackendFeature; // @public (undocumented) export class GithubLocationAnalyzer implements ScmLocationAnalyzer { diff --git a/plugins/catalog-backend-module-gitlab/api-report.md b/plugins/catalog-backend-module-gitlab/api-report.md index 21b0d9fdc3..36713d2427 100644 --- a/plugins/catalog-backend-module-gitlab/api-report.md +++ b/plugins/catalog-backend-module-gitlab/api-report.md @@ -9,7 +9,6 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -35,10 +34,7 @@ export class GitlabDiscoveryEntityProvider implements EntityProvider { } // @alpha -export const gitlabDiscoveryEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const gitlabDiscoveryEntityProviderCatalogModule: () => BackendFeature; // @public export class GitLabDiscoveryProcessor implements CatalogProcessor { diff --git a/plugins/catalog-backend-module-incremental-ingestion/api-report.md b/plugins/catalog-backend-module-incremental-ingestion/api-report.md index 5dc0c45551..387e505c33 100644 --- a/plugins/catalog-backend-module-incremental-ingestion/api-report.md +++ b/plugins/catalog-backend-module-incremental-ingestion/api-report.md @@ -10,7 +10,6 @@ import { CatalogBuilder } from '@backstage/plugin-catalog-backend'; import type { Config } from '@backstage/config'; import type { DeferredEntity } from '@backstage/plugin-catalog-backend'; import type { DurationObjectUnits } from 'luxon'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import type { Logger } from 'winston'; import type { PermissionEvaluator } from '@backstage/plugin-permission-common'; import type { PluginDatabaseManager } from '@backstage/backend-common'; @@ -69,17 +68,12 @@ export interface IncrementalEntityProviderOptions { } // @alpha -export const incrementalIngestionEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [ - options: { - providers: { - provider: IncrementalEntityProvider; - options: IncrementalEntityProviderOptions; - }[]; - }, - ] ->; +export const incrementalIngestionEntityProviderCatalogModule: (options: { + providers: { + provider: IncrementalEntityProvider; + options: IncrementalEntityProviderOptions; + }[]; +}) => BackendFeature; // @public (undocumented) export type PluginEnvironment = { diff --git a/plugins/catalog-backend-module-msgraph/api-report.md b/plugins/catalog-backend-module-msgraph/api-report.md index 9a0f8cc0db..a5abdc17c6 100644 --- a/plugins/catalog-backend-module-msgraph/api-report.md +++ b/plugins/catalog-backend-module-msgraph/api-report.md @@ -9,7 +9,6 @@ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; import { Config } from '@backstage/config'; import { EntityProvider } from '@backstage/plugin-catalog-backend'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GroupEntity } from '@backstage/catalog-model'; import { LocationSpec } from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; @@ -136,10 +135,7 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { } // @alpha -export const microsoftGraphOrgEntityProviderCatalogModule: FactoryFunction< - BackendFeature, - [] ->; +export const microsoftGraphOrgEntityProviderCatalogModule: () => BackendFeature; // @alpha export interface MicrosoftGraphOrgEntityProviderCatalogModuleOptions { diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index ac5d42a6e9..6ff9ac4b1f 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -34,7 +34,6 @@ import { EntityProvider } from '@backstage/plugin-catalog-node'; import { EntityProviderConnection } from '@backstage/plugin-catalog-node'; import { EntityProviderMutation } from '@backstage/plugin-catalog-node'; import { EntityRelationSpec } from '@backstage/plugin-catalog-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GetEntitiesRequest } from '@backstage/catalog-client'; import { JsonValue } from '@backstage/types'; import { LocationEntityV1alpha1 } from '@backstage/catalog-model'; @@ -238,7 +237,7 @@ export type CatalogPermissionRule< > = PermissionRule; // @alpha -export const catalogPlugin: FactoryFunction; +export const catalogPlugin: () => BackendFeature; // @public export interface CatalogProcessingEngine { diff --git a/plugins/events-backend-module-aws-sqs/api-report.md b/plugins/events-backend-module-aws-sqs/api-report.md index b50ba0884e..ede18f2787 100644 --- a/plugins/events-backend-module-aws-sqs/api-report.md +++ b/plugins/events-backend-module-aws-sqs/api-report.md @@ -7,7 +7,6 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventBroker } from '@backstage/plugin-events-node'; import { EventPublisher } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; @@ -24,8 +23,5 @@ export class AwsSqsConsumingEventPublisher implements EventPublisher { } // @alpha -export const awsSqsConsumingEventPublisherEventsModule: FactoryFunction< - BackendFeature, - [] ->; +export const awsSqsConsumingEventPublisherEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend-module-azure/api-report.md b/plugins/events-backend-module-azure/api-report.md index d974bfee6b..2e13a7ed4a 100644 --- a/plugins/events-backend-module-azure/api-report.md +++ b/plugins/events-backend-module-azure/api-report.md @@ -5,7 +5,6 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -16,8 +15,5 @@ export class AzureDevOpsEventRouter extends SubTopicEventRouter { } // @alpha -export const azureDevOpsEventRouterEventsModule: FactoryFunction< - BackendFeature, - [] ->; +export const azureDevOpsEventRouterEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend-module-bitbucket-cloud/api-report.md b/plugins/events-backend-module-bitbucket-cloud/api-report.md index 69f5570cf5..c47252ce17 100644 --- a/plugins/events-backend-module-bitbucket-cloud/api-report.md +++ b/plugins/events-backend-module-bitbucket-cloud/api-report.md @@ -5,7 +5,6 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -16,8 +15,5 @@ export class BitbucketCloudEventRouter extends SubTopicEventRouter { } // @alpha -export const bitbucketCloudEventRouterEventsModule: FactoryFunction< - BackendFeature, - [] ->; +export const bitbucketCloudEventRouterEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend-module-gerrit/api-report.md b/plugins/events-backend-module-gerrit/api-report.md index 868505f773..c8d4a7c9b6 100644 --- a/plugins/events-backend-module-gerrit/api-report.md +++ b/plugins/events-backend-module-gerrit/api-report.md @@ -5,7 +5,6 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; import { EventParams } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; // @public @@ -16,5 +15,5 @@ export class GerritEventRouter extends SubTopicEventRouter { } // @alpha -export const gerritEventRouterEventsModule: FactoryFunction; +export const gerritEventRouterEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend-module-github/api-report.md b/plugins/events-backend-module-github/api-report.md index 3b8905f6b0..4f14bce789 100644 --- a/plugins/events-backend-module-github/api-report.md +++ b/plugins/events-backend-module-github/api-report.md @@ -6,7 +6,6 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventParams } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { RequestValidator } from '@backstage/plugin-events-node'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; @@ -23,8 +22,8 @@ export class GithubEventRouter extends SubTopicEventRouter { } // @alpha -export const githubEventRouterEventsModule: FactoryFunction; +export const githubEventRouterEventsModule: () => BackendFeature; // @alpha -export const githubWebhookEventsModule: FactoryFunction; +export const githubWebhookEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend-module-gitlab/api-report.md b/plugins/events-backend-module-gitlab/api-report.md index 4900b548a9..2a88295032 100644 --- a/plugins/events-backend-module-gitlab/api-report.md +++ b/plugins/events-backend-module-gitlab/api-report.md @@ -6,7 +6,6 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import { EventParams } from '@backstage/plugin-events-node'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { RequestValidator } from '@backstage/plugin-events-node'; import { SubTopicEventRouter } from '@backstage/plugin-events-node'; @@ -21,8 +20,8 @@ export class GitlabEventRouter extends SubTopicEventRouter { } // @alpha -export const gitlabEventRouterEventsModule: FactoryFunction; +export const gitlabEventRouterEventsModule: () => BackendFeature; // @alpha -export const gitlabWebhookEventsModule: FactoryFunction; +export const gitlabWebhookEventsModule: () => BackendFeature; ``` diff --git a/plugins/events-backend/api-report.md b/plugins/events-backend/api-report.md index 87700237b9..28437772ae 100644 --- a/plugins/events-backend/api-report.md +++ b/plugins/events-backend/api-report.md @@ -9,7 +9,6 @@ import { EventBroker } from '@backstage/plugin-events-node'; import { EventPublisher } from '@backstage/plugin-events-node'; import { EventSubscriber } from '@backstage/plugin-events-node'; import express from 'express'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { HttpPostIngressOptions } from '@backstage/plugin-events-node'; import { Logger } from 'winston'; @@ -30,7 +29,7 @@ export class EventsBackend { } // @alpha -export const eventsPlugin: FactoryFunction; +export const eventsPlugin: () => BackendFeature; // @public export class HttpPostIngressEventPublisher implements EventPublisher { diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 29590f76b1..21026c203c 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -13,7 +13,6 @@ import { Config } from '@backstage/config'; import { createPullRequest } from 'octokit-plugin-create-pull-request'; import { Entity } from '@backstage/catalog-model'; import express from 'express'; -import { FactoryFunction } from '@backstage/backend-plugin-api/src/types'; import { GithubCredentialsProvider } from '@backstage/integration'; import { IdentityApi } from '@backstage/plugin-auth-node'; import { JsonObject } from '@backstage/types'; @@ -626,7 +625,7 @@ export type RunCommandOptions = { }; // @alpha -export const scaffolderCatalogModule: FactoryFunction; +export const scaffolderCatalogModule: () => BackendFeature; // @public (undocumented) export class ScaffolderEntitiesProcessor implements CatalogProcessor { @@ -643,10 +642,9 @@ export class ScaffolderEntitiesProcessor implements CatalogProcessor { } // @alpha -export const scaffolderPlugin: FactoryFunction< - BackendFeature, - [options: ScaffolderPluginOptions] ->; +export const scaffolderPlugin: ( + options: ScaffolderPluginOptions, +) => BackendFeature; // @alpha export type ScaffolderPluginOptions = {