diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index 8df5ace282..9859717fd5 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -30,9 +30,11 @@ "@backstage/backend-plugin-api": "workspace:^", "@backstage/plugin-app-backend": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", - "@backstage/plugin-explore-backend": "workspace:^", "@backstage/plugin-scaffolder-backend": "workspace:^", "@backstage/plugin-search-backend": "workspace:^", + "@backstage/plugin-search-backend-module-catalog": "workspace:^", + "@backstage/plugin-search-backend-module-explore": "workspace:^", + "@backstage/plugin-search-backend-module-techdocs": "workspace:^", "@backstage/plugin-search-backend-node": "workspace:^", "@backstage/plugin-techdocs-backend": "workspace:^", "@backstage/plugin-todo-backend": "workspace:^" diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 10680ca798..231343203a 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -14,24 +14,40 @@ * limitations under the License. */ -import { catalogPlugin } from '@backstage/plugin-catalog-backend/alpha'; -import { catalogModuleTemplateKind } from '@backstage/plugin-scaffolder-backend/alpha'; import { createBackend } from '@backstage/backend-defaults'; import { appPlugin } from '@backstage/plugin-app-backend/alpha'; import { todoPlugin } from '@backstage/plugin-todo-backend'; import { techdocsPlugin } from '@backstage/plugin-techdocs-backend/alpha'; +import { catalogPlugin } from '@backstage/plugin-catalog-backend/alpha'; +import { catalogModuleTemplateKind } from '@backstage/plugin-scaffolder-backend/alpha'; import { searchPlugin } from '@backstage/plugin-search-backend/alpha'; -import { searchIndexRegistry } from './plugins/search'; +import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-module-catalog/alpha'; +import { searchModuleTechDocsCollator } from '@backstage/plugin-search-backend-module-techdocs/alpha'; +import { searchModuleExploreCollator } from '@backstage/plugin-search-backend-module-explore/alpha'; const backend = createBackend(); -backend.add(catalogPlugin()); -backend.add(catalogModuleTemplateKind()); backend.add(appPlugin({ appPackageName: 'example-app' })); + +// Todo backend.add(todoPlugin()); + +// Techdocs backend.add(techdocsPlugin()); +// Catalog +backend.add(catalogPlugin()); +backend.add(catalogModuleTemplateKind()); + +// Search +const schedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, +}; backend.add(searchPlugin()); -backend.add(searchIndexRegistry()); +backend.add(searchModuleCatalogCollator({ schedule })); +backend.add(searchModuleTechDocsCollator({ schedule })); +backend.add(searchModuleExploreCollator({ schedule })); backend.start(); diff --git a/packages/backend-next/src/plugins/search.ts b/packages/backend-next/src/plugins/search.ts deleted file mode 100644 index 1329135e56..0000000000 --- a/packages/backend-next/src/plugins/search.ts +++ /dev/null @@ -1,82 +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. - */ -import { - coreServices, - createBackendModule, -} from '@backstage/backend-plugin-api'; -import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import { DefaultCatalogCollatorFactory } from '@backstage/plugin-catalog-backend'; -import { DefaultTechDocsCollatorFactory } from '@backstage/plugin-techdocs-backend'; -import { ToolDocumentCollatorFactory } from '@backstage/plugin-explore-backend'; -import { loggerToWinstonLogger } from '@backstage/backend-common'; - -export const searchIndexRegistry = createBackendModule({ - moduleId: 'searchIndexRegistry', - pluginId: 'search', - register(env) { - env.registerInit({ - deps: { - indexRegistry: searchIndexRegistryExtensionPoint, - config: coreServices.config, - discovery: coreServices.discovery, - tokenManager: coreServices.tokenManager, - logger: coreServices.logger, - scheduler: coreServices.scheduler, - }, - async init({ - indexRegistry, - config, - logger, - discovery, - tokenManager, - scheduler, - }) { - const schedule = scheduler.createScheduledTaskRunner({ - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - // A 3 second delay gives the backend server a chance to initialize before - // any collators are executed, which may attempt requests against the API. - initialDelay: { seconds: 3 }, - }); - - indexRegistry.addCollator({ - schedule, - factory: DefaultCatalogCollatorFactory.fromConfig(config, { - discovery, - tokenManager, - }), - }); - - indexRegistry.addCollator({ - schedule, - factory: DefaultTechDocsCollatorFactory.fromConfig(config, { - discovery, - logger: loggerToWinstonLogger(logger), - tokenManager, - }), - }); - - indexRegistry.addCollator({ - schedule, - factory: ToolDocumentCollatorFactory.fromConfig(config, { - discovery, - logger: loggerToWinstonLogger(logger), - }), - }); - }, - }); - }, -}); diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 5e7b2dee02..3d6a33fbf9 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -11,6 +11,7 @@ import { AnalyzeLocationGenerateEntity as AnalyzeLocationGenerateEntity_2 } from import { AnalyzeLocationRequest as AnalyzeLocationRequest_2 } from '@backstage/plugin-catalog-common'; import { AnalyzeLocationResponse as AnalyzeLocationResponse_2 } from '@backstage/plugin-catalog-common'; import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogCollatorEntityTransformer } from '@backstage/plugin-search-backend-module-catalog'; import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; import { CatalogProcessor as CatalogProcessor_2 } from '@backstage/plugin-catalog-node'; import { CatalogProcessorCache as CatalogProcessorCache_2 } from '@backstage/plugin-catalog-node'; @@ -23,8 +24,15 @@ import { CatalogProcessorRefreshKeysResult as CatalogProcessorRefreshKeysResult_ import { CatalogProcessorRelationResult as CatalogProcessorRelationResult_2 } from '@backstage/plugin-catalog-node'; import { CatalogProcessorResult as CatalogProcessorResult_2 } from '@backstage/plugin-catalog-node'; import { Config } from '@backstage/config'; +<<<<<<< HEAD import { DeferredEntity as DeferredEntity_2 } from '@backstage/plugin-catalog-node'; import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +======= +import { defaultCatalogCollatorEntityTransformer } from '@backstage/plugin-search-backend-module-catalog'; +import { DefaultCatalogCollatorFactory } from '@backstage/plugin-search-backend-module-catalog'; +import { DefaultCatalogCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-catalog'; +import { DeferredEntity } from '@backstage/plugin-catalog-node'; +>>>>>>> 56a45401d3d (feat(search): create search collator modules) import { Entity } from '@backstage/catalog-model'; import { EntityPolicy } from '@backstage/catalog-model'; import { EntityProvider as EntityProvider_2 } from '@backstage/plugin-catalog-node'; @@ -44,7 +52,11 @@ import { PermissionRule } from '@backstage/plugin-permission-node'; import { PermissionRuleParams } from '@backstage/plugin-permission-common'; import { PluginDatabaseManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; +<<<<<<< HEAD import { Readable } from 'stream'; +======= +import { processingResult } from '@backstage/plugin-catalog-node'; +>>>>>>> 56a45401d3d (feat(search): create search collator modules) import { Router } from 'express'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { TokenManager } from '@backstage/backend-common'; @@ -160,10 +172,7 @@ export class CatalogBuilder { useLegacySingleProcessorValidation(): this; } -// @public (undocumented) -export type CatalogCollatorEntityTransformer = ( - entity: Entity, -) => Omit; +export { CatalogCollatorEntityTransformer }; // @public (undocumented) export type CatalogEnvironment = { @@ -286,34 +295,11 @@ export class DefaultCatalogCollator { readonly visibilityPermission: Permission; } -// @public (undocumented) -export const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer; +export { defaultCatalogCollatorEntityTransformer }; -// @public (undocumented) -export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory { - // (undocumented) - static fromConfig( - _config: Config, - options: DefaultCatalogCollatorFactoryOptions, - ): DefaultCatalogCollatorFactory; - // (undocumented) - getCollator(): Promise; - // (undocumented) - readonly type = 'software-catalog'; - // (undocumented) - readonly visibilityPermission: Permission; -} +export { DefaultCatalogCollatorFactory }; -// @public (undocumented) -export type DefaultCatalogCollatorFactoryOptions = { - discovery: PluginEndpointDiscovery; - tokenManager: TokenManager; - locationTemplate?: string; - filter?: GetEntitiesRequest['filter']; - batchSize?: number; - catalogClient?: CatalogApi; - entityTransformer?: CatalogCollatorEntityTransformer; -}; +export { DefaultCatalogCollatorFactoryOptions }; // @public @deprecated (undocumented) export type DeferredEntity = DeferredEntity_2; diff --git a/plugins/catalog-backend/package.json b/plugins/catalog-backend/package.json index 1e837fd9ba..203a89b730 100644 --- a/plugins/catalog-backend/package.json +++ b/plugins/catalog-backend/package.json @@ -57,6 +57,7 @@ "@backstage/plugin-permission-common": "workspace:^", "@backstage/plugin-permission-node": "workspace:^", "@backstage/plugin-scaffolder-common": "workspace:^", + "@backstage/plugin-search-backend-module-catalog": "workspace:^", "@backstage/plugin-search-common": "workspace:^", "@backstage/types": "workspace:^", "@opentelemetry/api": "^1.3.0", diff --git a/plugins/catalog-backend/src/index.ts b/plugins/catalog-backend/src/index.ts index b3d2bc95c7..594b96b347 100644 --- a/plugins/catalog-backend/src/index.ts +++ b/plugins/catalog-backend/src/index.ts @@ -27,3 +27,17 @@ export * from './processing'; export * from './search'; export * from './service'; export * from './deprecated'; + +import { + DefaultCatalogCollatorFactory as _DefaultCatalogCollatorFactory, + defaultCatalogCollatorEntityTransformer as _defaultCatalogCollatorEntityTransformer, +} from '@backstage/plugin-search-backend-module-catalog'; + +/** + * @deprecated + * import from @backstage/search-backend-module-catalog instead + */ +export type { + DefaultCatalogCollatorFactoryOptions, + CatalogCollatorEntityTransformer, +} from '@backstage/plugin-search-backend-module-catalog'; diff --git a/plugins/catalog-backend/src/search/index.ts b/plugins/catalog-backend/src/search/index.ts index 3603ab2e60..50966e4c5b 100644 --- a/plugins/catalog-backend/src/search/index.ts +++ b/plugins/catalog-backend/src/search/index.ts @@ -14,11 +14,6 @@ * limitations under the License. */ -export { DefaultCatalogCollatorFactory } from './DefaultCatalogCollatorFactory'; -export type { DefaultCatalogCollatorFactoryOptions } from './DefaultCatalogCollatorFactory'; -export type { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer'; -export { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer'; - /** * todo(backstage/techdocs-core): stop exporting this in a future release. */ diff --git a/plugins/explore-backend/api-report.md b/plugins/explore-backend/api-report.md index cc112ed3cc..4bcdc07079 100644 --- a/plugins/explore-backend/api-report.md +++ b/plugins/explore-backend/api-report.md @@ -3,18 +3,14 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -/// - -import { Config } from '@backstage/config'; -import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; import { ExploreTool } from '@backstage/plugin-explore-common'; import express from 'express'; import { GetExploreToolsRequest } from '@backstage/plugin-explore-common'; import { GetExploreToolsResponse } from '@backstage/plugin-explore-common'; -import { IndexableDocument } from '@backstage/plugin-search-common'; import { Logger } from 'winston'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; -import { Readable } from 'stream'; +import { ToolDocument } from '@backstage/plugin-search-backend-module-explore'; +import { ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore'; +import { ToolDocumentCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-explore'; // @public (undocumented) export function createRouter(options: RouterOptions): Promise; @@ -40,27 +36,9 @@ export class StaticExploreToolProvider implements ExploreToolProvider { getTools(request: GetExploreToolsRequest): Promise; } -// @public -export interface ToolDocument extends IndexableDocument, ExploreTool {} +export { ToolDocument }; -// @public -export class ToolDocumentCollatorFactory implements DocumentCollatorFactory { - // (undocumented) - execute(): AsyncGenerator; - // (undocumented) - static fromConfig( - _config: Config, - options: ToolDocumentCollatorFactoryOptions, - ): ToolDocumentCollatorFactory; - // (undocumented) - getCollator(): Promise; - // (undocumented) - readonly type: string; -} +export { ToolDocumentCollatorFactory }; -// @public -export type ToolDocumentCollatorFactoryOptions = { - discovery: PluginEndpointDiscovery; - logger: Logger; -}; +export { ToolDocumentCollatorFactoryOptions }; ``` diff --git a/plugins/explore-backend/package.json b/plugins/explore-backend/package.json index 00629c8da4..ce1a22e502 100644 --- a/plugins/explore-backend/package.json +++ b/plugins/explore-backend/package.json @@ -25,6 +25,7 @@ "@backstage/backend-common": "workspace:^", "@backstage/config": "workspace:^", "@backstage/plugin-explore-common": "workspace:^", + "@backstage/plugin-search-backend-module-explore": "workspace:^", "@backstage/plugin-search-common": "workspace:^", "@types/express": "*", "express": "^4.18.1", diff --git a/plugins/explore-backend/src/index.ts b/plugins/explore-backend/src/index.ts index a0e7216621..6c456bffc2 100644 --- a/plugins/explore-backend/src/index.ts +++ b/plugins/explore-backend/src/index.ts @@ -20,7 +20,6 @@ * @packageDocumentation */ -export * from './search'; export * from './service'; export * from './tools'; @@ -28,3 +27,18 @@ export * from './tools'; * @internal Example only - do not use in production */ export { exampleTools } from './example/exampleTools'; + +/** + * @deprecated + * import from @backstage/plugin-search-backend-module-explore instead + */ +export { ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore'; + +/** + * @deprecated + * import from @backstage/plugin-search-backend-module-explore instead + */ +export type { + ToolDocument, + ToolDocumentCollatorFactoryOptions, +} from '@backstage/plugin-search-backend-module-explore'; diff --git a/plugins/search-backend-module-catalog/.eslintrc.js b/plugins/search-backend-module-catalog/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/search-backend-module-catalog/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/search-backend-module-catalog/CHANGELOG.md b/plugins/search-backend-module-catalog/CHANGELOG.md new file mode 100644 index 0000000000..c870819424 --- /dev/null +++ b/plugins/search-backend-module-catalog/CHANGELOG.md @@ -0,0 +1 @@ +# @backstage/plugin-search-backend-module-catalog diff --git a/plugins/search-backend-module-catalog/README.md b/plugins/search-backend-module-catalog/README.md new file mode 100644 index 0000000000..9860f86b1d --- /dev/null +++ b/plugins/search-backend-module-catalog/README.md @@ -0,0 +1,7 @@ +# search-backend-module-catalog + +... + +## Getting started + +... diff --git a/plugins/search-backend-module-catalog/alpha-api-report.md b/plugins/search-backend-module-catalog/alpha-api-report.md new file mode 100644 index 0000000000..e0173fce74 --- /dev/null +++ b/plugins/search-backend-module-catalog/alpha-api-report.md @@ -0,0 +1,66 @@ +## API Report File for "@backstage/plugin-search-backend-module-catalog" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackendFeature } from '@backstage/backend-plugin-api'; +import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; +import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { Entity } from '@backstage/catalog-model'; +import { GetEntitiesRequest } from '@backstage/catalog-client'; +import { Permission } from '@backstage/plugin-permission-common'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { Readable } from 'stream'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { TokenManager } from '@backstage/backend-common'; + +// @public (undocumented) +export type CatalogCollatorEntityTransformer = ( + entity: Entity, +) => Omit; + +// @public (undocumented) +export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory { + // (undocumented) + static fromConfig( + _config: Config, + options: DefaultCatalogCollatorFactoryOptions, + ): DefaultCatalogCollatorFactory; + // (undocumented) + getCollator(): Promise; + // (undocumented) + readonly type = 'software-catalog'; + // (undocumented) + readonly visibilityPermission: Permission; +} + +// @public (undocumented) +export type DefaultCatalogCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + tokenManager: TokenManager; + locationTemplate?: string; + filter?: GetEntitiesRequest['filter']; + batchSize?: number; + catalogClient?: CatalogApi; + entityTransformer?: CatalogCollatorEntityTransformer; +}; + +// @alpha +export const searchModuleCatalogCollator: ( + options: SearchModuleCatalogCollatorOptions, +) => BackendFeature; + +// @alpha +export type SearchModuleCatalogCollatorOptions = Omit< + DefaultCatalogCollatorFactoryOptions, + 'discovery' | 'tokenManager' +> & { + schedule: TaskScheduleDefinition; +}; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/search-backend-module-catalog/api-report.md b/plugins/search-backend-module-catalog/api-report.md new file mode 100644 index 0000000000..b773860fe8 --- /dev/null +++ b/plugins/search-backend-module-catalog/api-report.md @@ -0,0 +1,52 @@ +## API Report File for "@backstage/plugin-search-backend-module-catalog" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; +import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { Entity } from '@backstage/catalog-model'; +import { GetEntitiesRequest } from '@backstage/catalog-client'; +import { Permission } from '@backstage/plugin-permission-common'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { Readable } from 'stream'; +import { TokenManager } from '@backstage/backend-common'; + +// @public (undocumented) +export type CatalogCollatorEntityTransformer = ( + entity: Entity, +) => Omit; + +// @public (undocumented) +export const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer; + +// @public (undocumented) +export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory { + // (undocumented) + static fromConfig( + _config: Config, + options: DefaultCatalogCollatorFactoryOptions, + ): DefaultCatalogCollatorFactory; + // (undocumented) + getCollator(): Promise; + // (undocumented) + readonly type = 'software-catalog'; + // (undocumented) + readonly visibilityPermission: Permission; +} + +// @public (undocumented) +export type DefaultCatalogCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + tokenManager: TokenManager; + locationTemplate?: string; + filter?: GetEntitiesRequest['filter']; + batchSize?: number; + catalogClient?: CatalogApi; + entityTransformer?: CatalogCollatorEntityTransformer; +}; +``` diff --git a/plugins/search-backend-module-catalog/package.json b/plugins/search-backend-module-catalog/package.json new file mode 100644 index 0000000000..6c7b78437c --- /dev/null +++ b/plugins/search-backend-module-catalog/package.json @@ -0,0 +1,70 @@ +{ + "name": "@backstage/plugin-search-backend-module-catalog", + "description": "A module for the search backend that exports catalog modules", + "version": "1.1.4-next.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public" + }, + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.ts", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.ts" + ], + "package.json": [ + "package.json" + ] + } + }, + "backstage": { + "role": "backend-plugin-module" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack", + "clean": "backstage-cli package clean" + }, + "dependencies": { + "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", + "@backstage/backend-tasks": "workspace:^", + "@backstage/catalog-client": "workspace:^", + "@backstage/catalog-model": "workspace:^", + "@backstage/config": "workspace:^", + "@backstage/plugin-catalog-backend": "workspace:^", + "@backstage/plugin-catalog-common": "workspace:^", + "@backstage/plugin-permission-common": "workspace:^", + "@backstage/plugin-search-backend-node": "workspace:^", + "@backstage/plugin-search-common": "workspace:^", + "@elastic/elasticsearch": "^7.13.0", + "@opensearch-project/opensearch": "^2.0.0", + "aws-os-connection": "^0.2.0", + "aws-sdk": "^2.948.0", + "elastic-builder": "^2.16.0", + "lodash": "^4.17.21", + "uuid": "^8.3.2", + "winston": "^3.2.1" + }, + "devDependencies": { + "@backstage/backend-common": "workspace:^", + "@backstage/backend-test-utils": "workspace:^", + "@backstage/cli": "workspace:^", + "@elastic/elasticsearch-mock": "^1.0.0", + "@short.io/opensearch-mock": "^0.3.1", + "msw": "^1.0.0" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/search-backend-module-catalog/src/alpha.ts b/plugins/search-backend-module-catalog/src/alpha.ts new file mode 100644 index 0000000000..d4530b582b --- /dev/null +++ b/plugins/search-backend-module-catalog/src/alpha.ts @@ -0,0 +1,90 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports Catalog modules. + */ + +import { + coreServices, + createBackendModule, +} from '@backstage/backend-plugin-api'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + +import { + CatalogCollatorEntityTransformer, + DefaultCatalogCollatorFactory, + DefaultCatalogCollatorFactoryOptions, +} from './collators'; + +export type { + CatalogCollatorEntityTransformer, + DefaultCatalogCollatorFactory, + DefaultCatalogCollatorFactoryOptions, +}; + +/** + * @alpha + * Options for {@link searchModuleCatalogCollator}. + */ +export type SearchModuleCatalogCollatorOptions = Omit< + DefaultCatalogCollatorFactoryOptions, + 'discovery' | 'tokenManager' +> & { + schedule: TaskScheduleDefinition; +}; + +/** + * @alpha + * Search backend module for the Catalog index. + */ +export const searchModuleCatalogCollator = createBackendModule( + (options: SearchModuleCatalogCollatorOptions) => ({ + moduleId: 'catalogCollator', + pluginId: 'search', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + discovery: coreServices.discovery, + tokenManager: coreServices.tokenManager, + scheduler: coreServices.scheduler, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + discovery, + tokenManager, + scheduler, + indexRegistry, + }) { + const { schedule, ...rest } = options; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: DefaultCatalogCollatorFactory.fromConfig(config, { + ...rest, + discovery, + tokenManager, + }), + }); + }, + }); + }, + }), +); diff --git a/plugins/catalog-backend/src/search/CatalogCollatorEntityTransformer.ts b/plugins/search-backend-module-catalog/src/collators/CatalogCollatorEntityTransformer.ts similarity index 100% rename from plugins/catalog-backend/src/search/CatalogCollatorEntityTransformer.ts rename to plugins/search-backend-module-catalog/src/collators/CatalogCollatorEntityTransformer.ts diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.test.ts b/plugins/search-backend-module-catalog/src/collators/DefaultCatalogCollatorFactory.test.ts similarity index 100% rename from plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.test.ts rename to plugins/search-backend-module-catalog/src/collators/DefaultCatalogCollatorFactory.test.ts diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts b/plugins/search-backend-module-catalog/src/collators/DefaultCatalogCollatorFactory.ts similarity index 100% rename from plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts rename to plugins/search-backend-module-catalog/src/collators/DefaultCatalogCollatorFactory.ts diff --git a/plugins/catalog-backend/src/search/defaultCatalogCollatorEntityTransformer.test.ts b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts similarity index 100% rename from plugins/catalog-backend/src/search/defaultCatalogCollatorEntityTransformer.test.ts rename to plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.test.ts diff --git a/plugins/catalog-backend/src/search/defaultCatalogCollatorEntityTransformer.ts b/plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts similarity index 100% rename from plugins/catalog-backend/src/search/defaultCatalogCollatorEntityTransformer.ts rename to plugins/search-backend-module-catalog/src/collators/defaultCatalogCollatorEntityTransformer.ts diff --git a/plugins/search-backend-module-catalog/src/collators/index.ts b/plugins/search-backend-module-catalog/src/collators/index.ts new file mode 100644 index 0000000000..5876e71a02 --- /dev/null +++ b/plugins/search-backend-module-catalog/src/collators/index.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export { DefaultCatalogCollatorFactory } from './DefaultCatalogCollatorFactory'; +export type { DefaultCatalogCollatorFactoryOptions } from './DefaultCatalogCollatorFactory'; + +export { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer'; +export type { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer'; diff --git a/plugins/search-backend-module-catalog/src/index.ts b/plugins/search-backend-module-catalog/src/index.ts new file mode 100644 index 0000000000..7998562311 --- /dev/null +++ b/plugins/search-backend-module-catalog/src/index.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports Catalog modules. + */ + +export * from './collators'; diff --git a/plugins/search-backend-module-elasticsearch/alpha-api-report.md b/plugins/search-backend-module-elasticsearch/alpha-api-report.md index acdd14e781..fca920f3d1 100644 --- a/plugins/search-backend-module-elasticsearch/alpha-api-report.md +++ b/plugins/search-backend-module-elasticsearch/alpha-api-report.md @@ -26,17 +26,6 @@ export type ElasticSearchCustomIndexTemplateBody = { template?: Record; }; -// @alpha -export const elasticSearchEngineModule: ( - options?: ElasticsearchEngineModuleOptions | undefined, -) => BackendFeature; - -// @alpha -export type ElasticsearchEngineModuleOptions = { - translator?: ElasticSearchQueryTranslator; - indexTemplate?: ElasticSearchCustomIndexTemplate; -}; - // @public (undocumented) export type ElasticSearchHighlightConfig = { fragmentDelimiter: string; @@ -57,5 +46,16 @@ export type ElasticSearchQueryTranslatorOptions = { highlightOptions?: ElasticSearchHighlightConfig; }; +// @alpha +export const searchModuleElasticsearchEngine: ( + options?: SearchModuleElasticsearchEngineOptions | undefined, +) => BackendFeature; + +// @alpha +export type SearchModuleElasticsearchEngineOptions = { + translator?: ElasticSearchQueryTranslator; + indexTemplate?: ElasticSearchCustomIndexTemplate; +}; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-elasticsearch/src/alpha.ts b/plugins/search-backend-module-elasticsearch/src/alpha.ts index 8e75c9f603..d2ff1568f6 100644 --- a/plugins/search-backend-module-elasticsearch/src/alpha.ts +++ b/plugins/search-backend-module-elasticsearch/src/alpha.ts @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; import { coreServices, createBackendModule, } from '@backstage/backend-plugin-api'; import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + import { ElasticSearchHighlightConfig, ElasticSearchQueryTranslatorOptions, @@ -31,9 +32,9 @@ import { /** * @alpha - * Options for {@link elasticSearchEngineModule}. + * Options for {@link searchModuleElasticsearchEngine}. */ -export type ElasticsearchEngineModuleOptions = { +export type SearchModuleElasticsearchEngineOptions = { translator?: ElasticSearchQueryTranslator; indexTemplate?: ElasticSearchCustomIndexTemplate; }; @@ -42,9 +43,9 @@ export type ElasticsearchEngineModuleOptions = { * @alpha * Search backend module for the Elasticsearch engine. */ -export const elasticSearchEngineModule = createBackendModule( - (options?: ElasticsearchEngineModuleOptions) => ({ - moduleId: 'elasticSearchEngineModule', +export const searchModuleElasticsearchEngine = createBackendModule( + (options?: SearchModuleElasticsearchEngineOptions) => ({ + moduleId: 'elasticsearchEngine', pluginId: 'search', register(env) { env.registerInit({ diff --git a/plugins/search-backend-module-explore/.eslintrc.js b/plugins/search-backend-module-explore/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/search-backend-module-explore/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/search-backend-module-explore/CHANGELOG.md b/plugins/search-backend-module-explore/CHANGELOG.md new file mode 100644 index 0000000000..8640d14b73 --- /dev/null +++ b/plugins/search-backend-module-explore/CHANGELOG.md @@ -0,0 +1 @@ +# @backstage/plugin-search-backend-module-explore diff --git a/plugins/search-backend-module-explore/README.md b/plugins/search-backend-module-explore/README.md new file mode 100644 index 0000000000..bbc8392f14 --- /dev/null +++ b/plugins/search-backend-module-explore/README.md @@ -0,0 +1,7 @@ +# search-backend-module-explore + +... + +## Getting started + +... diff --git a/plugins/search-backend-module-explore/alpha-api-report.md b/plugins/search-backend-module-explore/alpha-api-report.md new file mode 100644 index 0000000000..5c5189c8bd --- /dev/null +++ b/plugins/search-backend-module-explore/alpha-api-report.md @@ -0,0 +1,56 @@ +## API Report File for "@backstage/plugin-search-backend-module-explore" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackendFeature } from '@backstage/backend-plugin-api'; +import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { ExploreTool } from '@backstage/plugin-explore-common'; +import { IndexableDocument } from '@backstage/plugin-search-common'; +import { Logger } from 'winston'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { Readable } from 'stream'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; + +// @alpha +export const searchModuleExploreCollator: ( + options: SearchModuleExploreCollatorOptions, +) => BackendFeature; + +// @alpha +export type SearchModuleExploreCollatorOptions = Omit< + ToolDocumentCollatorFactoryOptions, + 'logger' | 'discovery' +> & { + schedule: TaskScheduleDefinition; +}; + +// @public +export interface ToolDocument extends IndexableDocument, ExploreTool {} + +// @public +export class ToolDocumentCollatorFactory implements DocumentCollatorFactory { + // (undocumented) + execute(): AsyncGenerator; + // (undocumented) + static fromConfig( + _config: Config, + options: ToolDocumentCollatorFactoryOptions, + ): ToolDocumentCollatorFactory; + // (undocumented) + getCollator(): Promise; + // (undocumented) + readonly type: string; +} + +// @public +export type ToolDocumentCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + logger: Logger; +}; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/search-backend-module-explore/api-report.md b/plugins/search-backend-module-explore/api-report.md new file mode 100644 index 0000000000..80e8c0c06b --- /dev/null +++ b/plugins/search-backend-module-explore/api-report.md @@ -0,0 +1,39 @@ +## API Report File for "@backstage/plugin-search-backend-module-explore" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { ExploreTool } from '@backstage/plugin-explore-common'; +import { IndexableDocument } from '@backstage/plugin-search-common'; +import { Logger } from 'winston'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { Readable } from 'stream'; + +// @public +export interface ToolDocument extends IndexableDocument, ExploreTool {} + +// @public +export class ToolDocumentCollatorFactory implements DocumentCollatorFactory { + // (undocumented) + execute(): AsyncGenerator; + // (undocumented) + static fromConfig( + _config: Config, + options: ToolDocumentCollatorFactoryOptions, + ): ToolDocumentCollatorFactory; + // (undocumented) + getCollator(): Promise; + // (undocumented) + readonly type: string; +} + +// @public +export type ToolDocumentCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + logger: Logger; +}; +``` diff --git a/plugins/search-backend-module-explore/package.json b/plugins/search-backend-module-explore/package.json new file mode 100644 index 0000000000..356059f845 --- /dev/null +++ b/plugins/search-backend-module-explore/package.json @@ -0,0 +1,71 @@ +{ + "name": "@backstage/plugin-search-backend-module-explore", + "description": "A module for the search backend that exports explore modules", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public" + }, + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.ts", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.ts" + ], + "package.json": [ + "package.json" + ] + } + }, + "backstage": { + "role": "backend-plugin-module" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack", + "clean": "backstage-cli package clean" + }, + "dependencies": { + "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", + "@backstage/backend-tasks": "workspace:^", + "@backstage/catalog-client": "workspace:^", + "@backstage/catalog-model": "workspace:^", + "@backstage/config": "workspace:^", + "@backstage/errors": "workspace:^", + "@backstage/integration": "workspace:^", + "@backstage/plugin-catalog-common": "workspace:^", + "@backstage/plugin-explore-common": "workspace:^", + "@backstage/plugin-permission-common": "workspace:^", + "@backstage/plugin-search-backend-node": "workspace:^", + "@backstage/plugin-search-common": "workspace:^", + "@types/express": "^4.17.6", + "dockerode": "^3.3.1", + "express": "^4.17.1", + "express-promise-router": "^4.1.0", + "fs-extra": "10.1.0", + "knex": "^2.0.0", + "lodash": "^4.17.21", + "node-fetch": "^2.6.7", + "p-limit": "^3.1.0", + "winston": "^3.2.1" + }, + "devDependencies": { + "@backstage/backend-test-utils": "workspace:^", + "@backstage/cli": "workspace:^", + "msw": "^1.0.0" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/search-backend-module-explore/src/alpha.ts b/plugins/search-backend-module-explore/src/alpha.ts new file mode 100644 index 0000000000..357bb4233e --- /dev/null +++ b/plugins/search-backend-module-explore/src/alpha.ts @@ -0,0 +1,85 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports Explore modules. + */ + +import { + coreServices, + createBackendModule, +} from '@backstage/backend-plugin-api'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + +import { + ToolDocument, + ToolDocumentCollatorFactory, + ToolDocumentCollatorFactoryOptions, +} from './collators'; + +export type { + ToolDocumentCollatorFactoryOptions, + ToolDocument, + ToolDocumentCollatorFactory, +}; + +/** + * @alpha + * Options for {@link searchModuleExploreCollator}. + */ +export type SearchModuleExploreCollatorOptions = Omit< + ToolDocumentCollatorFactoryOptions, + 'logger' | 'discovery' +> & { + schedule: TaskScheduleDefinition; +}; + +/** + * @alpha + * Search backend module for the Explore index. + */ +export const searchModuleExploreCollator = createBackendModule( + (options: SearchModuleExploreCollatorOptions) => ({ + moduleId: 'exploreCollator', + pluginId: 'search', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ config, logger, discovery, scheduler, indexRegistry }) { + const { schedule, ...rest } = options; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: ToolDocumentCollatorFactory.fromConfig(config, { + ...rest, + discovery, + logger: loggerToWinstonLogger(logger), + }), + }); + }, + }); + }, + }), +); diff --git a/plugins/explore-backend/src/search/ToolDocumentCollatorFactory.ts b/plugins/search-backend-module-explore/src/collators/ToolDocumentCollatorFactory.ts similarity index 100% rename from plugins/explore-backend/src/search/ToolDocumentCollatorFactory.ts rename to plugins/search-backend-module-explore/src/collators/ToolDocumentCollatorFactory.ts diff --git a/plugins/explore-backend/src/search/index.ts b/plugins/search-backend-module-explore/src/collators/index.ts similarity index 99% rename from plugins/explore-backend/src/search/index.ts rename to plugins/search-backend-module-explore/src/collators/index.ts index 70e9414652..45f0c933e2 100644 --- a/plugins/explore-backend/src/search/index.ts +++ b/plugins/search-backend-module-explore/src/collators/index.ts @@ -15,6 +15,7 @@ */ export { ToolDocumentCollatorFactory } from './ToolDocumentCollatorFactory'; + export type { ToolDocument, ToolDocumentCollatorFactoryOptions, diff --git a/plugins/search-backend-module-explore/src/index.ts b/plugins/search-backend-module-explore/src/index.ts new file mode 100644 index 0000000000..ea94071984 --- /dev/null +++ b/plugins/search-backend-module-explore/src/index.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports Explore modules. + */ + +export * from './collators'; diff --git a/plugins/search-backend-module-pg/alpha-api-report.md b/plugins/search-backend-module-pg/alpha-api-report.md index 01a83bace4..eaee78e944 100644 --- a/plugins/search-backend-module-pg/alpha-api-report.md +++ b/plugins/search-backend-module-pg/alpha-api-report.md @@ -6,7 +6,7 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; // @alpha -export const pgSearchEngineModule: () => BackendFeature; +export const searchModulePostgresEngine: () => BackendFeature; // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-pg/src/alpha.ts b/plugins/search-backend-module-pg/src/alpha.ts index 80ce31adf6..e3e0087957 100644 --- a/plugins/search-backend-module-pg/src/alpha.ts +++ b/plugins/search-backend-module-pg/src/alpha.ts @@ -24,8 +24,8 @@ import { PgSearchEngine } from './PgSearchEngine'; * @alpha * Search backend module for the Postgres engine. */ -export const pgSearchEngineModule = createBackendModule({ - moduleId: 'pgSearchEngineModule', +export const searchModulePostgresEngine = createBackendModule({ + moduleId: 'postgresEngine', pluginId: 'search', register(env) { env.registerInit({ diff --git a/plugins/search-backend-module-techdocs/.eslintrc.js b/plugins/search-backend-module-techdocs/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/search-backend-module-techdocs/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/search-backend-module-techdocs/CHANGELOG.md b/plugins/search-backend-module-techdocs/CHANGELOG.md new file mode 100644 index 0000000000..85d533ae87 --- /dev/null +++ b/plugins/search-backend-module-techdocs/CHANGELOG.md @@ -0,0 +1 @@ +# @backstage/plugin-search-backend-module-techdocs diff --git a/plugins/search-backend-module-techdocs/README.md b/plugins/search-backend-module-techdocs/README.md new file mode 100644 index 0000000000..2711150d56 --- /dev/null +++ b/plugins/search-backend-module-techdocs/README.md @@ -0,0 +1,7 @@ +# search-backend-module-techdocs + +... + +## Getting started + +... diff --git a/plugins/search-backend-module-techdocs/alpha-api-report.md b/plugins/search-backend-module-techdocs/alpha-api-report.md new file mode 100644 index 0000000000..3360055c62 --- /dev/null +++ b/plugins/search-backend-module-techdocs/alpha-api-report.md @@ -0,0 +1,40 @@ +## API Report File for "@backstage/plugin-search-backend-module-techdocs" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackendFeature } from '@backstage/backend-plugin-api'; +import { CatalogApi } from '@backstage/catalog-client'; +import { Logger } from 'winston'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { TokenManager } from '@backstage/backend-common'; + +// @alpha +export const searchModuleTechDocsCollator: ( + options: SearchModuleTechDocsCollatorOptions, +) => BackendFeature; + +// @alpha +export type SearchModuleTechDocsCollatorOptions = Omit< + TechDocsCollatorFactoryOptions, + 'logger' | 'discovery' | 'tokenManager' +> & { + schedule: TaskScheduleDefinition; +}; + +// @public +export type TechDocsCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + logger: Logger; + tokenManager: TokenManager; + locationTemplate?: string; + catalogClient?: CatalogApi; + parallelismLimit?: number; + legacyPathCasing?: boolean; +}; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/search-backend-module-techdocs/api-report.md b/plugins/search-backend-module-techdocs/api-report.md new file mode 100644 index 0000000000..9f72b1c487 --- /dev/null +++ b/plugins/search-backend-module-techdocs/api-report.md @@ -0,0 +1,42 @@ +## API Report File for "@backstage/plugin-search-backend-module-techdocs" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { CatalogApi } from '@backstage/catalog-client'; +import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { Logger } from 'winston'; +import { Permission } from '@backstage/plugin-permission-common'; +import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { Readable } from 'stream'; +import { TokenManager } from '@backstage/backend-common'; + +// @public +export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory { + // (undocumented) + static fromConfig( + config: Config, + options: TechDocsCollatorFactoryOptions, + ): DefaultTechDocsCollatorFactory; + // (undocumented) + getCollator(): Promise; + // (undocumented) + readonly type: string; + // (undocumented) + readonly visibilityPermission: Permission; +} + +// @public +export type TechDocsCollatorFactoryOptions = { + discovery: PluginEndpointDiscovery; + logger: Logger; + tokenManager: TokenManager; + locationTemplate?: string; + catalogClient?: CatalogApi; + parallelismLimit?: number; + legacyPathCasing?: boolean; +}; +``` diff --git a/plugins/search-backend-module-techdocs/package.json b/plugins/search-backend-module-techdocs/package.json new file mode 100644 index 0000000000..555e34ebdf --- /dev/null +++ b/plugins/search-backend-module-techdocs/package.json @@ -0,0 +1,71 @@ +{ + "name": "@backstage/plugin-search-backend-module-techdocs", + "description": "A module for the search backend that exports techdocs modules", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public" + }, + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.ts", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.ts" + ], + "package.json": [ + "package.json" + ] + } + }, + "backstage": { + "role": "backend-plugin-module" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack", + "clean": "backstage-cli package clean" + }, + "dependencies": { + "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", + "@backstage/backend-tasks": "workspace:^", + "@backstage/catalog-client": "workspace:^", + "@backstage/catalog-model": "workspace:^", + "@backstage/config": "workspace:^", + "@backstage/errors": "workspace:^", + "@backstage/integration": "workspace:^", + "@backstage/plugin-catalog-common": "workspace:^", + "@backstage/plugin-permission-common": "workspace:^", + "@backstage/plugin-search-backend-node": "workspace:^", + "@backstage/plugin-search-common": "workspace:^", + "@backstage/plugin-techdocs-node": "workspace:^", + "@types/express": "^4.17.6", + "dockerode": "^3.3.1", + "express": "^4.17.1", + "express-promise-router": "^4.1.0", + "fs-extra": "10.1.0", + "knex": "^2.0.0", + "lodash": "^4.17.21", + "node-fetch": "^2.6.7", + "p-limit": "^3.1.0", + "winston": "^3.2.1" + }, + "devDependencies": { + "@backstage/backend-test-utils": "workspace:^", + "@backstage/cli": "workspace:^", + "msw": "^1.0.0" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/search-backend-module-techdocs/src/alpha.ts b/plugins/search-backend-module-techdocs/src/alpha.ts new file mode 100644 index 0000000000..f58c439c80 --- /dev/null +++ b/plugins/search-backend-module-techdocs/src/alpha.ts @@ -0,0 +1,89 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports TechDocs modules. + */ + +import { + coreServices, + createBackendModule, +} from '@backstage/backend-plugin-api'; +import { TaskScheduleDefinition } from '@backstage/backend-tasks'; +import { loggerToWinstonLogger } from '@backstage/backend-common'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + +import { + DefaultTechDocsCollatorFactory, + TechDocsCollatorFactoryOptions, +} from './collators'; + +export type { TechDocsCollatorFactoryOptions }; + +/** + * @alpha + * Options for {@link searchModuleTechDocsCollator}. + */ +export type SearchModuleTechDocsCollatorOptions = Omit< + TechDocsCollatorFactoryOptions, + 'logger' | 'discovery' | 'tokenManager' +> & { + schedule: TaskScheduleDefinition; +}; + +/** + * @alpha + * Search backend module for the TechDocs index. + */ +export const searchModuleTechDocsCollator = createBackendModule( + (options: SearchModuleTechDocsCollatorOptions) => ({ + moduleId: 'techDocsCollator', + pluginId: 'search', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + discovery: coreServices.discovery, + tokenManager: coreServices.tokenManager, + scheduler: coreServices.scheduler, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + logger, + discovery, + tokenManager, + scheduler, + indexRegistry, + }) { + const { schedule, ...rest } = options; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: DefaultTechDocsCollatorFactory.fromConfig(config, { + ...rest, + discovery, + tokenManager, + logger: loggerToWinstonLogger(logger), + }), + }); + }, + }); + }, + }), +); diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollatorFactory.test.ts b/plugins/search-backend-module-techdocs/src/collators/DefaultTechDocsCollatorFactory.test.ts similarity index 100% rename from plugins/techdocs-backend/src/search/DefaultTechDocsCollatorFactory.test.ts rename to plugins/search-backend-module-techdocs/src/collators/DefaultTechDocsCollatorFactory.test.ts diff --git a/plugins/techdocs-backend/src/search/DefaultTechDocsCollatorFactory.ts b/plugins/search-backend-module-techdocs/src/collators/DefaultTechDocsCollatorFactory.ts similarity index 100% rename from plugins/techdocs-backend/src/search/DefaultTechDocsCollatorFactory.ts rename to plugins/search-backend-module-techdocs/src/collators/DefaultTechDocsCollatorFactory.ts diff --git a/plugins/search-backend-module-techdocs/src/collators/index.ts b/plugins/search-backend-module-techdocs/src/collators/index.ts new file mode 100644 index 0000000000..8c5fd122f1 --- /dev/null +++ b/plugins/search-backend-module-techdocs/src/collators/index.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + +export { DefaultTechDocsCollatorFactory } from './DefaultTechDocsCollatorFactory'; + +export type { TechDocsCollatorFactoryOptions } from './DefaultTechDocsCollatorFactory'; diff --git a/plugins/search-backend-module-techdocs/src/index.ts b/plugins/search-backend-module-techdocs/src/index.ts new file mode 100644 index 0000000000..c28175fd61 --- /dev/null +++ b/plugins/search-backend-module-techdocs/src/index.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** + * @packageDocumentation + * A module for the search backend that exports TechDocs modules. + */ + +export * from './collators'; diff --git a/plugins/techdocs-backend/api-report.md b/plugins/techdocs-backend/api-report.md index 1f6aa1d66a..2abd9783f7 100644 --- a/plugins/techdocs-backend/api-report.md +++ b/plugins/techdocs-backend/api-report.md @@ -3,12 +3,10 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts -/// - import { CatalogApi } from '@backstage/catalog-client'; import { CatalogClient } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; -import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; +import { DefaultTechDocsCollatorFactory } from '@backstage/plugin-search-backend-module-techdocs'; import { Entity } from '@backstage/catalog-model'; import express from 'express'; import { GeneratorBuilder } from '@backstage/plugin-techdocs-node'; @@ -19,7 +17,7 @@ import { PluginCacheManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { PreparerBuilder } from '@backstage/plugin-techdocs-node'; import { PublisherBase } from '@backstage/plugin-techdocs-node'; -import { Readable } from 'stream'; +import { TechDocsCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-techdocs'; import { TechDocsDocument } from '@backstage/plugin-techdocs-node'; import { TokenManager } from '@backstage/backend-common'; import * as winston from 'winston'; @@ -47,20 +45,7 @@ export class DefaultTechDocsCollator { readonly visibilityPermission: Permission; } -// @public -export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory { - // (undocumented) - static fromConfig( - config: Config, - options: TechDocsCollatorFactoryOptions, - ): DefaultTechDocsCollatorFactory; - // (undocumented) - getCollator(): Promise; - // (undocumented) - readonly type: string; - // (undocumented) - readonly visibilityPermission: Permission; -} +export { DefaultTechDocsCollatorFactory }; // @public export interface DocsBuildStrategy { @@ -105,16 +90,7 @@ export type ShouldBuildParameters = { entity: Entity; }; -// @public -export type TechDocsCollatorFactoryOptions = { - discovery: PluginEndpointDiscovery; - logger: Logger; - tokenManager: TokenManager; - locationTemplate?: string; - catalogClient?: CatalogApi; - parallelismLimit?: number; - legacyPathCasing?: boolean; -}; +export { TechDocsCollatorFactoryOptions }; // @public export type TechDocsCollatorOptions = { diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index 1d6ca8931e..a9f7a5c9b2 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -57,6 +57,7 @@ "@backstage/integration": "workspace:^", "@backstage/plugin-catalog-common": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", + "@backstage/plugin-search-backend-module-techdocs": "workspace:^", "@backstage/plugin-search-common": "workspace:^", "@backstage/plugin-techdocs-node": "workspace:^", "@types/express": "^4.17.6", diff --git a/plugins/techdocs-backend/src/search/index.ts b/plugins/techdocs-backend/src/search/index.ts index 68e3b4edc7..0c403ef0d7 100644 --- a/plugins/techdocs-backend/src/search/index.ts +++ b/plugins/techdocs-backend/src/search/index.ts @@ -14,11 +14,20 @@ * limitations under the License. */ -export { DefaultTechDocsCollatorFactory } from './DefaultTechDocsCollatorFactory'; -export type { TechDocsCollatorFactoryOptions } from './DefaultTechDocsCollatorFactory'; - /** * todo(backstage/techdocs-core): stop exporting these in a future release. */ export { DefaultTechDocsCollator } from './DefaultTechDocsCollator'; export type { TechDocsCollatorOptions } from './DefaultTechDocsCollator'; + +/** + * @deprecated + * import from @backstage/search-backend-module-techdocs instead + */ +export type { TechDocsCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-techdocs'; + +/** + * @deprecated + * import from @backstage/search-backend-module-techdocs instead + */ +export { DefaultTechDocsCollatorFactory } from '@backstage/plugin-search-backend-module-techdocs'; diff --git a/yarn.lock b/yarn.lock index b5203fbe29..2046cd9ece 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5207,6 +5207,7 @@ __metadata: "@backstage/plugin-permission-common": "workspace:^" "@backstage/plugin-permission-node": "workspace:^" "@backstage/plugin-scaffolder-common": "workspace:^" + "@backstage/plugin-search-backend-module-catalog": "workspace:^" "@backstage/plugin-search-backend-node": "workspace:^" "@backstage/plugin-search-common": "workspace:^" "@backstage/types": "workspace:^" @@ -6048,6 +6049,7 @@ __metadata: "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/plugin-explore-common": "workspace:^" + "@backstage/plugin-search-backend-module-explore": "workspace:^" "@backstage/plugin-search-common": "workspace:^" "@types/express": "*" "@types/supertest": ^2.0.8 @@ -7768,6 +7770,37 @@ __metadata: languageName: unknown linkType: soft +"@backstage/plugin-search-backend-module-catalog@workspace:^, @backstage/plugin-search-backend-module-catalog@workspace:plugins/search-backend-module-catalog": + version: 0.0.0-use.local + resolution: "@backstage/plugin-search-backend-module-catalog@workspace:plugins/search-backend-module-catalog" + dependencies: + "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" + "@backstage/backend-tasks": "workspace:^" + "@backstage/backend-test-utils": "workspace:^" + "@backstage/catalog-client": "workspace:^" + "@backstage/catalog-model": "workspace:^" + "@backstage/cli": "workspace:^" + "@backstage/config": "workspace:^" + "@backstage/plugin-catalog-backend": "workspace:^" + "@backstage/plugin-catalog-common": "workspace:^" + "@backstage/plugin-permission-common": "workspace:^" + "@backstage/plugin-search-backend-node": "workspace:^" + "@backstage/plugin-search-common": "workspace:^" + "@elastic/elasticsearch": ^7.13.0 + "@elastic/elasticsearch-mock": ^1.0.0 + "@opensearch-project/opensearch": ^2.0.0 + "@short.io/opensearch-mock": ^0.3.1 + aws-os-connection: ^0.2.0 + aws-sdk: ^2.948.0 + elastic-builder: ^2.16.0 + lodash: ^4.17.21 + msw: ^1.0.0 + uuid: ^8.3.2 + winston: ^3.2.1 + languageName: unknown + linkType: soft + "@backstage/plugin-search-backend-module-elasticsearch@workspace:^, @backstage/plugin-search-backend-module-elasticsearch@workspace:plugins/search-backend-module-elasticsearch": version: 0.0.0-use.local resolution: "@backstage/plugin-search-backend-module-elasticsearch@workspace:plugins/search-backend-module-elasticsearch" @@ -7791,6 +7824,39 @@ __metadata: languageName: unknown linkType: soft +"@backstage/plugin-search-backend-module-explore@workspace:^, @backstage/plugin-search-backend-module-explore@workspace:plugins/search-backend-module-explore": + version: 0.0.0-use.local + resolution: "@backstage/plugin-search-backend-module-explore@workspace:plugins/search-backend-module-explore" + dependencies: + "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" + "@backstage/backend-tasks": "workspace:^" + "@backstage/backend-test-utils": "workspace:^" + "@backstage/catalog-client": "workspace:^" + "@backstage/catalog-model": "workspace:^" + "@backstage/cli": "workspace:^" + "@backstage/config": "workspace:^" + "@backstage/errors": "workspace:^" + "@backstage/integration": "workspace:^" + "@backstage/plugin-catalog-common": "workspace:^" + "@backstage/plugin-explore-common": "workspace:^" + "@backstage/plugin-permission-common": "workspace:^" + "@backstage/plugin-search-backend-node": "workspace:^" + "@backstage/plugin-search-common": "workspace:^" + "@types/express": ^4.17.6 + dockerode: ^3.3.1 + express: ^4.17.1 + express-promise-router: ^4.1.0 + fs-extra: 10.1.0 + knex: ^2.0.0 + lodash: ^4.17.21 + msw: ^1.0.0 + node-fetch: ^2.6.7 + p-limit: ^3.1.0 + winston: ^3.2.1 + languageName: unknown + linkType: soft + "@backstage/plugin-search-backend-module-pg@workspace:^, @backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg": version: 0.0.0-use.local resolution: "@backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg" @@ -7809,6 +7875,39 @@ __metadata: languageName: unknown linkType: soft +"@backstage/plugin-search-backend-module-techdocs@workspace:^, @backstage/plugin-search-backend-module-techdocs@workspace:plugins/search-backend-module-techdocs": + version: 0.0.0-use.local + resolution: "@backstage/plugin-search-backend-module-techdocs@workspace:plugins/search-backend-module-techdocs" + dependencies: + "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" + "@backstage/backend-tasks": "workspace:^" + "@backstage/backend-test-utils": "workspace:^" + "@backstage/catalog-client": "workspace:^" + "@backstage/catalog-model": "workspace:^" + "@backstage/cli": "workspace:^" + "@backstage/config": "workspace:^" + "@backstage/errors": "workspace:^" + "@backstage/integration": "workspace:^" + "@backstage/plugin-catalog-common": "workspace:^" + "@backstage/plugin-permission-common": "workspace:^" + "@backstage/plugin-search-backend-node": "workspace:^" + "@backstage/plugin-search-common": "workspace:^" + "@backstage/plugin-techdocs-node": "workspace:^" + "@types/express": ^4.17.6 + dockerode: ^3.3.1 + express: ^4.17.1 + express-promise-router: ^4.1.0 + fs-extra: 10.1.0 + knex: ^2.0.0 + lodash: ^4.17.21 + msw: ^1.0.0 + node-fetch: ^2.6.7 + p-limit: ^3.1.0 + winston: ^3.2.1 + languageName: unknown + linkType: soft + "@backstage/plugin-search-backend-node@workspace:^, @backstage/plugin-search-backend-node@workspace:plugins/search-backend-node": version: 0.0.0-use.local resolution: "@backstage/plugin-search-backend-node@workspace:plugins/search-backend-node" @@ -8371,6 +8470,7 @@ __metadata: "@backstage/integration": "workspace:^" "@backstage/plugin-catalog-common": "workspace:^" "@backstage/plugin-permission-common": "workspace:^" + "@backstage/plugin-search-backend-module-techdocs": "workspace:^" "@backstage/plugin-search-backend-node": "workspace:^" "@backstage/plugin-search-common": "workspace:^" "@backstage/plugin-techdocs-node": "workspace:^" @@ -22490,11 +22590,12 @@ __metadata: "@backstage/cli": "workspace:^" "@backstage/plugin-app-backend": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" - "@backstage/plugin-explore-backend": "workspace:^" "@backstage/plugin-scaffolder-backend": "workspace:^" "@backstage/plugin-search-backend": "workspace:^" + "@backstage/plugin-search-backend-module-catalog": "workspace:^" + "@backstage/plugin-search-backend-module-explore": "workspace:^" + "@backstage/plugin-search-backend-module-techdocs": "workspace:^" "@backstage/plugin-search-backend-node": "workspace:^" - "@backstage/plugin-techdocs-backend": "workspace:^" "@backstage/plugin-todo-backend": "workspace:^" languageName: unknown linkType: soft