From b071eec7d7e93f7bf59eb4f9a78e9209e1e844c4 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 13 Oct 2024 12:58:37 +0200 Subject: [PATCH] plugins/search-backend-module-*: flip around alpha exports to stable Signed-off-by: Patrik Oldsberg --- .../report-alpha.api.md | 24 ++-- .../report.api.md | 19 ++- .../src/alpha.ts | 103 ++----------- .../src/index.ts | 8 +- .../src/{alpha.test.ts => module.test.ts} | 2 +- .../src/module.ts | 109 ++++++++++++++ .../report-alpha.api.md | 23 +-- .../report.api.md | 25 ++-- .../src/alpha.ts | 84 ++--------- .../src/index.ts | 8 +- .../src/module.ts | 90 ++++++++++++ .../report-alpha.api.md | 10 +- .../report.api.md | 7 +- .../src/alpha.ts | 69 +-------- .../src/index.ts | 7 +- .../src/{alpha.test.ts => module.test.ts} | 2 +- .../src/module.ts | 80 +++++++++++ .../report-alpha.api.md | 10 +- .../search-backend-module-pg/report.api.md | 12 +- plugins/search-backend-module-pg/src/alpha.ts | 45 +----- plugins/search-backend-module-pg/src/index.ts | 7 +- .../search-backend-module-pg/src/module.ts | 54 +++++++ .../report-alpha.api.md | 30 ++-- .../report.api.md | 28 +++- .../src/alpha.ts | 127 ++-------------- .../src/index.ts | 8 +- .../src/{alpha.test.ts => module.test.ts} | 2 +- .../src/module.ts | 135 ++++++++++++++++++ 28 files changed, 640 insertions(+), 488 deletions(-) rename plugins/search-backend-module-catalog/src/{alpha.test.ts => module.test.ts} (97%) create mode 100644 plugins/search-backend-module-catalog/src/module.ts create mode 100644 plugins/search-backend-module-elasticsearch/src/module.ts rename plugins/search-backend-module-explore/src/{alpha.test.ts => module.test.ts} (97%) create mode 100644 plugins/search-backend-module-explore/src/module.ts create mode 100644 plugins/search-backend-module-pg/src/module.ts rename plugins/search-backend-module-techdocs/src/{alpha.test.ts => module.test.ts} (97%) create mode 100644 plugins/search-backend-module-techdocs/src/module.ts diff --git a/plugins/search-backend-module-catalog/report-alpha.api.md b/plugins/search-backend-module-catalog/report-alpha.api.md index e5080fae35..8a91ccdb5e 100644 --- a/plugins/search-backend-module-catalog/report-alpha.api.md +++ b/plugins/search-backend-module-catalog/report-alpha.api.md @@ -7,17 +7,23 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogCollatorEntityTransformer } from '@backstage/plugin-search-backend-module-catalog'; import { ExtensionPoint } from '@backstage/backend-plugin-api'; -// @alpha -export type CatalogCollatorExtensionPoint = { - setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void; -}; +// Warning: (ae-forgotten-export) The symbol "CatalogCollatorExtensionPoint_2" needs to be exported by the entry point alpha.d.ts +// +// @alpha (undocumented) +export type CatalogCollatorExtensionPoint = CatalogCollatorExtensionPoint_2; -// @alpha -export const catalogCollatorExtensionPoint: ExtensionPoint; +// @alpha (undocumented) +export const catalogCollatorExtensionPoint: ExtensionPoint; -// @alpha -const _default: BackendFeature; -export default _default; +// @alpha (undocumented) +const _feature: BackendFeature; +export default _feature; + +// Warnings were encountered during analysis: +// +// src/alpha.d.ts:3:15 - (ae-undocumented) Missing documentation for "_feature". +// src/alpha.d.ts:6:1 - (ae-undocumented) Missing documentation for "CatalogCollatorExtensionPoint". +// src/alpha.d.ts:8:22 - (ae-undocumented) Missing documentation for "catalogCollatorExtensionPoint". // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-catalog/report.api.md b/plugins/search-backend-module-catalog/report.api.md index 63ecce93e1..f20907494e 100644 --- a/plugins/search-backend-module-catalog/report.api.md +++ b/plugins/search-backend-module-catalog/report.api.md @@ -8,11 +8,13 @@ import { AuthService } from '@backstage/backend-plugin-api'; import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogCollatorEntityTransformer as CatalogCollatorEntityTransformer_2 } from '@backstage/plugin-search-backend-module-catalog'; import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; import { Config } from '@backstage/config'; import { DiscoveryService } from '@backstage/backend-plugin-api'; import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; import { Entity } from '@backstage/catalog-model'; +import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { GetEntitiesRequest } from '@backstage/catalog-client'; import { Permission } from '@backstage/plugin-permission-common'; import { Readable } from 'stream'; @@ -23,6 +25,18 @@ export type CatalogCollatorEntityTransformer = ( entity: Entity, ) => Omit; +// @public +export type CatalogCollatorExtensionPoint = { + setEntityTransformer(transformer: CatalogCollatorEntityTransformer_2): void; +}; + +// @public +export const catalogCollatorExtensionPoint: ExtensionPoint; + +// @public +const _default: BackendFeature; +export default _default; + // @public (undocumented) export const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer; @@ -53,10 +67,6 @@ export type DefaultCatalogCollatorFactoryOptions = { entityTransformer?: CatalogCollatorEntityTransformer; }; -// @public (undocumented) -const _feature: BackendFeature; -export default _feature; - // Warnings were encountered during analysis: // // src/collators/CatalogCollatorEntityTransformer.d.ts:4:1 - (ae-undocumented) Missing documentation for "CatalogCollatorEntityTransformer". @@ -66,5 +76,4 @@ export default _feature; // src/collators/DefaultCatalogCollatorFactory.d.ts:51:5 - (ae-undocumented) Missing documentation for "fromConfig". // src/collators/DefaultCatalogCollatorFactory.d.ts:53:5 - (ae-undocumented) Missing documentation for "getCollator". // src/collators/defaultCatalogCollatorEntityTransformer.d.ts:3:22 - (ae-undocumented) Missing documentation for "defaultCatalogCollatorEntityTransformer". -// src/index.d.ts:7:15 - (ae-undocumented) Missing documentation for "_feature". ``` diff --git a/plugins/search-backend-module-catalog/src/alpha.ts b/plugins/search-backend-module-catalog/src/alpha.ts index 03e5bcb226..b5fbb5e0c6 100644 --- a/plugins/search-backend-module-catalog/src/alpha.ts +++ b/plugins/search-backend-module-catalog/src/alpha.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The Backstage Authors + * Copyright 2024 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. @@ -14,96 +14,17 @@ * limitations under the License. */ -/** - * @packageDocumentation - * A module for the search backend that exports Catalog modules. - */ - import { - coreServices, - createBackendModule, - createExtensionPoint, -} from '@backstage/backend-plugin-api'; -import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; -import { - CatalogCollatorEntityTransformer, - DefaultCatalogCollatorFactory, -} from '@backstage/plugin-search-backend-module-catalog'; -import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import { readScheduleConfigOptions } from './collators/config'; + default as feature, + CatalogCollatorExtensionPoint as ExtensionPoint, + catalogCollatorExtensionPoint as extensionPoint, +} from './module'; -/** - * Options for {@link catalogCollatorExtensionPoint}. - * - * @alpha - */ -export type CatalogCollatorExtensionPoint = { - /** - * Allows you to customize how entities are shaped into documents. - */ - setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void; -}; +/** @alpha */ +const _feature = feature; +export default _feature; -/** - * Extension point for customizing how catalog entities are shaped into - * documents for the search backend. - * - * @alpha - */ -export const catalogCollatorExtensionPoint = - createExtensionPoint({ - id: 'search.catalogCollator.extension', - }); - -/** - * Search backend module for the Catalog index. - * - * @alpha - */ -export default createBackendModule({ - pluginId: 'search', - moduleId: 'catalog-collator', - register(env) { - let entityTransformer: CatalogCollatorEntityTransformer | undefined; - - env.registerExtensionPoint(catalogCollatorExtensionPoint, { - setEntityTransformer(transformer) { - if (entityTransformer) { - throw new Error('setEntityTransformer can only be called once'); - } - entityTransformer = transformer; - }, - }); - - env.registerInit({ - deps: { - auth: coreServices.auth, - config: coreServices.rootConfig, - discovery: coreServices.discovery, - scheduler: coreServices.scheduler, - indexRegistry: searchIndexRegistryExtensionPoint, - catalog: catalogServiceRef, - }, - async init({ - auth, - config, - discovery, - scheduler, - indexRegistry, - catalog, - }) { - indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner( - readScheduleConfigOptions(config), - ), - factory: DefaultCatalogCollatorFactory.fromConfig(config, { - auth, - entityTransformer, - discovery, - catalogClient: catalog, - }), - }); - }, - }); - }, -}); +/** @alpha */ +export type CatalogCollatorExtensionPoint = ExtensionPoint; +/** @alpha */ +export const catalogCollatorExtensionPoint = extensionPoint; diff --git a/plugins/search-backend-module-catalog/src/index.ts b/plugins/search-backend-module-catalog/src/index.ts index 91726fb716..3e0ec59cc0 100644 --- a/plugins/search-backend-module-catalog/src/index.ts +++ b/plugins/search-backend-module-catalog/src/index.ts @@ -14,15 +14,11 @@ * limitations under the License. */ -import { default as feature } from './alpha'; - /** * @packageDocumentation * A module for the search backend that exports Catalog modules. */ +export * from './module'; +export { default } from './module'; export * from './collators'; - -/** @public */ -const _feature = feature; -export default _feature; diff --git a/plugins/search-backend-module-catalog/src/alpha.test.ts b/plugins/search-backend-module-catalog/src/module.test.ts similarity index 97% rename from plugins/search-backend-module-catalog/src/alpha.test.ts rename to plugins/search-backend-module-catalog/src/module.test.ts index 94c585161b..d05c96c8ec 100644 --- a/plugins/search-backend-module-catalog/src/alpha.test.ts +++ b/plugins/search-backend-module-catalog/src/module.test.ts @@ -16,7 +16,7 @@ import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import searchModuleCatalogCollator from './alpha'; +import searchModuleCatalogCollator from './module'; describe('searchModuleCatalogCollator', () => { it('should register the catalog collator to the search index registry extension point with factory and schedule', async () => { diff --git a/plugins/search-backend-module-catalog/src/module.ts b/plugins/search-backend-module-catalog/src/module.ts new file mode 100644 index 0000000000..3256a2b32f --- /dev/null +++ b/plugins/search-backend-module-catalog/src/module.ts @@ -0,0 +1,109 @@ +/* + * 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, + createExtensionPoint, +} from '@backstage/backend-plugin-api'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { + CatalogCollatorEntityTransformer, + DefaultCatalogCollatorFactory, +} from '@backstage/plugin-search-backend-module-catalog'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; +import { readScheduleConfigOptions } from './collators/config'; + +/** + * Options for {@link catalogCollatorExtensionPoint}. + * + * @public + */ +export type CatalogCollatorExtensionPoint = { + /** + * Allows you to customize how entities are shaped into documents. + */ + setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void; +}; + +/** + * Extension point for customizing how catalog entities are shaped into + * documents for the search backend. + * + * @public + */ +export const catalogCollatorExtensionPoint = + createExtensionPoint({ + id: 'search.catalogCollator.extension', + }); + +/** + * Search backend module for the Catalog index. + * + * @public + */ +export default createBackendModule({ + pluginId: 'search', + moduleId: 'catalog-collator', + register(env) { + let entityTransformer: CatalogCollatorEntityTransformer | undefined; + + env.registerExtensionPoint(catalogCollatorExtensionPoint, { + setEntityTransformer(transformer) { + if (entityTransformer) { + throw new Error('setEntityTransformer can only be called once'); + } + entityTransformer = transformer; + }, + }); + + env.registerInit({ + deps: { + auth: coreServices.auth, + config: coreServices.rootConfig, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + indexRegistry: searchIndexRegistryExtensionPoint, + catalog: catalogServiceRef, + }, + async init({ + auth, + config, + discovery, + scheduler, + indexRegistry, + catalog, + }) { + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner( + readScheduleConfigOptions(config), + ), + factory: DefaultCatalogCollatorFactory.fromConfig(config, { + auth, + entityTransformer, + discovery, + catalogClient: catalog, + }), + }); + }, + }); + }, +}); diff --git a/plugins/search-backend-module-elasticsearch/report-alpha.api.md b/plugins/search-backend-module-elasticsearch/report-alpha.api.md index e612215a87..344718f5e5 100644 --- a/plugins/search-backend-module-elasticsearch/report-alpha.api.md +++ b/plugins/search-backend-module-elasticsearch/report-alpha.api.md @@ -7,23 +7,24 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; import { ElasticSearchQueryTranslator } from '@backstage/plugin-search-backend-module-elasticsearch'; import { ExtensionPoint } from '@backstage/backend-plugin-api'; -// @alpha -const _default: BackendFeature; -export default _default; +// Warning: (ae-forgotten-export) The symbol "ElasticSearchQueryTranslatorExtensionPoint_2" needs to be exported by the entry point alpha.d.ts +// +// @alpha (undocumented) +export type ElasticSearchQueryTranslatorExtensionPoint = + ElasticSearchQueryTranslatorExtensionPoint_2; // @alpha (undocumented) -export interface ElasticSearchQueryTranslatorExtensionPoint { - // (undocumented) - setTranslator(translator: ElasticSearchQueryTranslator): void; -} +export const elasticsearchTranslatorExtensionPoint: ExtensionPoint; -// @alpha -export const elasticsearchTranslatorExtensionPoint: ExtensionPoint; +// @alpha (undocumented) +const _feature: BackendFeature; +export default _feature; // Warnings were encountered during analysis: // -// src/alpha.d.ts:3:1 - (ae-undocumented) Missing documentation for "ElasticSearchQueryTranslatorExtensionPoint". -// src/alpha.d.ts:4:5 - (ae-undocumented) Missing documentation for "setTranslator". +// src/alpha.d.ts:3:15 - (ae-undocumented) Missing documentation for "_feature". +// src/alpha.d.ts:6:1 - (ae-undocumented) Missing documentation for "ElasticSearchQueryTranslatorExtensionPoint". +// src/alpha.d.ts:8:22 - (ae-undocumented) Missing documentation for "elasticsearchTranslatorExtensionPoint". // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-elasticsearch/report.api.md b/plugins/search-backend-module-elasticsearch/report.api.md index 9843582b13..d1ec3b171d 100644 --- a/plugins/search-backend-module-elasticsearch/report.api.md +++ b/plugins/search-backend-module-elasticsearch/report.api.md @@ -13,6 +13,8 @@ import { BulkHelper } from '@elastic/elasticsearch/lib/Helpers'; import { BulkStats } from '@elastic/elasticsearch/lib/Helpers'; import { Config } from '@backstage/config'; import type { ConnectionOptions } from 'tls'; +import { ElasticSearchQueryTranslator as ElasticSearchQueryTranslator_2 } from '@backstage/plugin-search-backend-module-elasticsearch'; +import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { IndexableDocument } from '@backstage/plugin-search-common'; import { IndexableResultSet } from '@backstage/plugin-search-common'; import { LoggerService } from '@backstage/backend-plugin-api'; @@ -73,6 +75,10 @@ export function decodeElasticSearchPageCursor(pageCursor?: string): { page: number; }; +// @public +const _default: BackendFeature; +export default _default; + // @public (undocumented) export interface ElasticSearchAgentOptions { // (undocumented) @@ -319,6 +325,12 @@ export type ElasticSearchQueryTranslator = ( options?: ElasticSearchQueryTranslatorOptions, ) => ElasticSearchConcreteQuery; +// @public (undocumented) +export interface ElasticSearchQueryTranslatorExtensionPoint { + // (undocumented) + setTranslator(translator: ElasticSearchQueryTranslator_2): void; +} + // @public export type ElasticSearchQueryTranslatorOptions = { highlightOptions?: ElasticSearchHighlightConfig; @@ -379,6 +391,9 @@ export type ElasticSearchSearchEngineIndexerOptions = { skipRefresh?: boolean; }; +// @public +export const elasticsearchTranslatorExtensionPoint: ExtensionPoint; + // @public (undocumented) export interface ElasticSearchTransportConstructor { // (undocumented) @@ -392,10 +407,6 @@ export interface ElasticSearchTransportConstructor { }; } -// @public (undocumented) -const _feature: BackendFeature; -export default _feature; - // @public export const isOpenSearchCompatible: ( opts: ElasticSearchClientOptions, @@ -557,8 +568,6 @@ export interface OpenSearchNodeOptions { // src/engines/ElasticSearchSearchEngineIndexer.d.ts:39:5 - (ae-undocumented) Missing documentation for "initialize". // src/engines/ElasticSearchSearchEngineIndexer.d.ts:40:5 - (ae-undocumented) Missing documentation for "index". // src/engines/ElasticSearchSearchEngineIndexer.d.ts:41:5 - (ae-undocumented) Missing documentation for "finalize". -// src/index.d.ts:2:15 - (ae-undocumented) Missing documentation for "_feature". -// src/index.d.ts:4:1 - (ae-misplaced-package-tag) The @packageDocumentation comment must appear at the top of entry point *.d.ts file - -// (No @packageDocumentation comment for this package) +// src/module.d.ts:3:1 - (ae-undocumented) Missing documentation for "ElasticSearchQueryTranslatorExtensionPoint". +// src/module.d.ts:4:5 - (ae-undocumented) Missing documentation for "setTranslator". ``` diff --git a/plugins/search-backend-module-elasticsearch/src/alpha.ts b/plugins/search-backend-module-elasticsearch/src/alpha.ts index 0af5904df0..22ff705cd2 100644 --- a/plugins/search-backend-module-elasticsearch/src/alpha.ts +++ b/plugins/search-backend-module-elasticsearch/src/alpha.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The Backstage Authors + * Copyright 2024 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. @@ -13,78 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { - coreServices, - createBackendModule, - createExtensionPoint, -} from '@backstage/backend-plugin-api'; -import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import { - ElasticSearchQueryTranslator, - ElasticSearchSearchEngine, -} from '@backstage/plugin-search-backend-module-elasticsearch'; + default as feature, + ElasticSearchQueryTranslatorExtensionPoint as ExtensionPoint, + elasticsearchTranslatorExtensionPoint as extensionPoint, +} from './module'; /** @alpha */ -export interface ElasticSearchQueryTranslatorExtensionPoint { - setTranslator(translator: ElasticSearchQueryTranslator): void; -} +const _feature = feature; +export default _feature; -/** - * Extension point used to customize the ElasticSearch query translator. - * - * @alpha - */ -export const elasticsearchTranslatorExtensionPoint = - createExtensionPoint({ - id: 'search.elasticsearchEngine.translator', - }); - -/** - * Search backend module for the Elasticsearch engine. - * - * @alpha - */ -export default createBackendModule({ - pluginId: 'search', - moduleId: 'elasticsearch-engine', - register(env) { - let translator: ElasticSearchQueryTranslator | undefined; - - env.registerExtensionPoint(elasticsearchTranslatorExtensionPoint, { - setTranslator(newTranslator) { - if (translator) { - throw new Error( - 'ElasticSearch query translator may only be set once', - ); - } - translator = newTranslator; - }, - }); - - env.registerInit({ - deps: { - searchEngineRegistry: searchEngineRegistryExtensionPoint, - logger: coreServices.logger, - config: coreServices.rootConfig, - }, - async init({ searchEngineRegistry, logger, config }) { - const baseKey = 'search.elasticsearch'; - const baseConfig = config.getOptional(baseKey); - if (!baseConfig) { - logger.warn( - 'No configuration found under "search.elasticsearch" key. Skipping search engine inititalization.', - ); - return; - } - - searchEngineRegistry.setSearchEngine( - await ElasticSearchSearchEngine.fromConfig({ - logger, - config, - translator, - }), - ); - }, - }); - }, -}); +/** @alpha */ +export type ElasticSearchQueryTranslatorExtensionPoint = ExtensionPoint; +/** @alpha */ +export const elasticsearchTranslatorExtensionPoint = extensionPoint; diff --git a/plugins/search-backend-module-elasticsearch/src/index.ts b/plugins/search-backend-module-elasticsearch/src/index.ts index a25ef80260..4a9f3474b1 100644 --- a/plugins/search-backend-module-elasticsearch/src/index.ts +++ b/plugins/search-backend-module-elasticsearch/src/index.ts @@ -14,18 +14,14 @@ * limitations under the License. */ -import { default as feature } from './alpha'; - -/** @public */ -const _feature = feature; -export default _feature; - /** * A module for the search backend that implements search using ElasticSearch * * @packageDocumentation */ +export { default } from './module'; +export * from './module'; export { decodeElasticSearchPageCursor, ElasticSearchSearchEngine, diff --git a/plugins/search-backend-module-elasticsearch/src/module.ts b/plugins/search-backend-module-elasticsearch/src/module.ts new file mode 100644 index 0000000000..827c8d48b8 --- /dev/null +++ b/plugins/search-backend-module-elasticsearch/src/module.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. + */ +import { + coreServices, + createBackendModule, + createExtensionPoint, +} from '@backstage/backend-plugin-api'; +import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; +import { + ElasticSearchQueryTranslator, + ElasticSearchSearchEngine, +} from '@backstage/plugin-search-backend-module-elasticsearch'; + +/** @public */ +export interface ElasticSearchQueryTranslatorExtensionPoint { + setTranslator(translator: ElasticSearchQueryTranslator): void; +} + +/** + * Extension point used to customize the ElasticSearch query translator. + * + * @public + */ +export const elasticsearchTranslatorExtensionPoint = + createExtensionPoint({ + id: 'search.elasticsearchEngine.translator', + }); + +/** + * Search backend module for the Elasticsearch engine. + * + * @public + */ +export default createBackendModule({ + pluginId: 'search', + moduleId: 'elasticsearch-engine', + register(env) { + let translator: ElasticSearchQueryTranslator | undefined; + + env.registerExtensionPoint(elasticsearchTranslatorExtensionPoint, { + setTranslator(newTranslator) { + if (translator) { + throw new Error( + 'ElasticSearch query translator may only be set once', + ); + } + translator = newTranslator; + }, + }); + + env.registerInit({ + deps: { + searchEngineRegistry: searchEngineRegistryExtensionPoint, + logger: coreServices.logger, + config: coreServices.rootConfig, + }, + async init({ searchEngineRegistry, logger, config }) { + const baseKey = 'search.elasticsearch'; + const baseConfig = config.getOptional(baseKey); + if (!baseConfig) { + logger.warn( + 'No configuration found under "search.elasticsearch" key. Skipping search engine inititalization.', + ); + return; + } + + searchEngineRegistry.setSearchEngine( + await ElasticSearchSearchEngine.fromConfig({ + logger, + config, + translator, + }), + ); + }, + }); + }, +}); diff --git a/plugins/search-backend-module-explore/report-alpha.api.md b/plugins/search-backend-module-explore/report-alpha.api.md index 3a1eef9393..0a383dc7d0 100644 --- a/plugins/search-backend-module-explore/report-alpha.api.md +++ b/plugins/search-backend-module-explore/report-alpha.api.md @@ -5,9 +5,13 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; -// @alpha -const _default: BackendFeature; -export default _default; +// @alpha (undocumented) +const _feature: BackendFeature; +export default _feature; + +// Warnings were encountered during analysis: +// +// src/alpha.d.ts:2:15 - (ae-undocumented) Missing documentation for "_feature". // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-explore/report.api.md b/plugins/search-backend-module-explore/report.api.md index 2d8c907c00..b8ec1aa9c3 100644 --- a/plugins/search-backend-module-explore/report.api.md +++ b/plugins/search-backend-module-explore/report.api.md @@ -16,9 +16,9 @@ import { LoggerService } from '@backstage/backend-plugin-api'; import { Readable } from 'stream'; import { TokenManager } from '@backstage/backend-common'; -// @public (undocumented) -const _feature: BackendFeature; -export default _feature; +// @public +const _default: BackendFeature; +export default _default; // @public export interface ToolDocument extends IndexableDocument, ExploreTool {} @@ -53,5 +53,4 @@ export type ToolDocumentCollatorFactoryOptions = { // src/collators/ToolDocumentCollatorFactory.d.ts:37:5 - (ae-undocumented) Missing documentation for "fromConfig". // src/collators/ToolDocumentCollatorFactory.d.ts:38:5 - (ae-undocumented) Missing documentation for "getCollator". // src/collators/ToolDocumentCollatorFactory.d.ts:39:5 - (ae-undocumented) Missing documentation for "execute". -// src/index.d.ts:7:15 - (ae-undocumented) Missing documentation for "_feature". ``` diff --git a/plugins/search-backend-module-explore/src/alpha.ts b/plugins/search-backend-module-explore/src/alpha.ts index 63a13c273b..e5554e85bd 100644 --- a/plugins/search-backend-module-explore/src/alpha.ts +++ b/plugins/search-backend-module-explore/src/alpha.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The Backstage Authors + * Copyright 2024 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. @@ -14,67 +14,8 @@ * limitations under the License. */ -/** - * @packageDocumentation - * A module for the search backend that exports Explore modules. - */ +import { default as feature } from './module'; -import { - coreServices, - createBackendModule, - readSchedulerServiceTaskScheduleDefinitionFromConfig, -} from '@backstage/backend-plugin-api'; -import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; - -import { ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore'; - -/** - * Search backend module for the Explore index. - * - * @alpha - */ -export default createBackendModule({ - pluginId: 'search', - moduleId: 'explore-collator', - register(env) { - env.registerInit({ - deps: { - config: coreServices.rootConfig, - logger: coreServices.logger, - discovery: coreServices.discovery, - scheduler: coreServices.scheduler, - auth: coreServices.auth, - indexRegistry: searchIndexRegistryExtensionPoint, - }, - async init({ - config, - logger, - discovery, - scheduler, - auth, - indexRegistry, - }) { - const defaultSchedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, - }; - - const schedule = config.has('search.collators.explore.schedule') - ? readSchedulerServiceTaskScheduleDefinitionFromConfig( - config.getConfig('search.collators.explore.schedule'), - ) - : defaultSchedule; - - indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner(schedule), - factory: ToolDocumentCollatorFactory.fromConfig(config, { - discovery, - logger, - auth, - }), - }); - }, - }); - }, -}); +/** @alpha */ +const _feature = feature; +export default _feature; diff --git a/plugins/search-backend-module-explore/src/index.ts b/plugins/search-backend-module-explore/src/index.ts index 520ae90e96..d0ed56eac9 100644 --- a/plugins/search-backend-module-explore/src/index.ts +++ b/plugins/search-backend-module-explore/src/index.ts @@ -14,15 +14,10 @@ * limitations under the License. */ -import { default as feature } from './alpha'; - /** * @packageDocumentation * A module for the search backend that exports Explore modules. */ export * from './collators'; - -/** @public */ -const _feature = feature; -export default _feature; +export { default } from './module'; diff --git a/plugins/search-backend-module-explore/src/alpha.test.ts b/plugins/search-backend-module-explore/src/module.test.ts similarity index 97% rename from plugins/search-backend-module-explore/src/alpha.test.ts rename to plugins/search-backend-module-explore/src/module.test.ts index 2ba01ec478..4be26a14d1 100644 --- a/plugins/search-backend-module-explore/src/alpha.test.ts +++ b/plugins/search-backend-module-explore/src/module.test.ts @@ -16,7 +16,7 @@ import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import searchModuleExploreCollator from './alpha'; +import searchModuleExploreCollator from './module'; describe('searchModuleExploreCollator', () => { const schedule = { diff --git a/plugins/search-backend-module-explore/src/module.ts b/plugins/search-backend-module-explore/src/module.ts new file mode 100644 index 0000000000..f0ac187908 --- /dev/null +++ b/plugins/search-backend-module-explore/src/module.ts @@ -0,0 +1,80 @@ +/* + * 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, + readSchedulerServiceTaskScheduleDefinitionFromConfig, +} from '@backstage/backend-plugin-api'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + +import { ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore'; + +/** + * Search backend module for the Explore index. + * + * @public + */ +export default createBackendModule({ + pluginId: 'search', + moduleId: 'explore-collator', + register(env) { + env.registerInit({ + deps: { + config: coreServices.rootConfig, + logger: coreServices.logger, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + auth: coreServices.auth, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + logger, + discovery, + scheduler, + auth, + indexRegistry, + }) { + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; + + const schedule = config.has('search.collators.explore.schedule') + ? readSchedulerServiceTaskScheduleDefinitionFromConfig( + config.getConfig('search.collators.explore.schedule'), + ) + : defaultSchedule; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: ToolDocumentCollatorFactory.fromConfig(config, { + discovery, + logger, + auth, + }), + }); + }, + }); + }, +}); diff --git a/plugins/search-backend-module-pg/report-alpha.api.md b/plugins/search-backend-module-pg/report-alpha.api.md index b36b782f6c..c5d011b95f 100644 --- a/plugins/search-backend-module-pg/report-alpha.api.md +++ b/plugins/search-backend-module-pg/report-alpha.api.md @@ -5,9 +5,13 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; -// @alpha -const _default: BackendFeature; -export default _default; +// @alpha (undocumented) +const _feature: BackendFeature; +export default _feature; + +// Warnings were encountered during analysis: +// +// src/alpha.d.ts:2:15 - (ae-undocumented) Missing documentation for "_feature". // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-pg/report.api.md b/plugins/search-backend-module-pg/report.api.md index 380d1cdb7b..77e795321a 100644 --- a/plugins/search-backend-module-pg/report.api.md +++ b/plugins/search-backend-module-pg/report.api.md @@ -71,6 +71,10 @@ export interface DatabaseStore { transaction(fn: (tx: Knex.Transaction) => Promise): Promise; } +// @public +const _default: BackendFeature; +export default _default; + // @public (undocumented) export interface DocumentResultRow { // (undocumented) @@ -81,10 +85,6 @@ export interface DocumentResultRow { type: string; } -// @public (undocumented) -const _feature: BackendFeature; -export default _feature; - // @public (undocumented) export class PgSearchEngine implements SearchEngine { // @deprecated @@ -240,8 +240,4 @@ export interface RawDocumentRow { // src/database/types.d.ts:30:5 - (ae-undocumented) Missing documentation for "document". // src/database/types.d.ts:31:5 - (ae-undocumented) Missing documentation for "type". // src/database/types.d.ts:32:5 - (ae-undocumented) Missing documentation for "highlight". -// src/index.d.ts:2:15 - (ae-undocumented) Missing documentation for "_feature". -// src/index.d.ts:4:1 - (ae-misplaced-package-tag) The @packageDocumentation comment must appear at the top of entry point *.d.ts file - -// (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 3ee4d685e7..e5554e85bd 100644 --- a/plugins/search-backend-module-pg/src/alpha.ts +++ b/plugins/search-backend-module-pg/src/alpha.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The Backstage Authors + * Copyright 2024 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. @@ -13,42 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - coreServices, - createBackendModule, -} from '@backstage/backend-plugin-api'; -import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import { PgSearchEngine } from './PgSearchEngine'; -/** - * @alpha - * Search backend module for the Postgres engine. - */ -export default createBackendModule({ - pluginId: 'search', - moduleId: 'postgres-engine', - register(env) { - env.registerInit({ - deps: { - searchEngineRegistry: searchEngineRegistryExtensionPoint, - database: coreServices.database, - config: coreServices.rootConfig, - logger: coreServices.logger, - }, - async init({ searchEngineRegistry, database, config, logger }) { - if (await PgSearchEngine.supported(database)) { - searchEngineRegistry.setSearchEngine( - await PgSearchEngine.fromConfig(config, { - database, - logger, - }), - ); - } else { - logger.warn( - 'Postgres search engine is not supported, skipping registration of search-backend-module-pg', - ); - } - }, - }); - }, -}); +import { default as feature } from './module'; + +/** @alpha */ +const _feature = feature; +export default _feature; diff --git a/plugins/search-backend-module-pg/src/index.ts b/plugins/search-backend-module-pg/src/index.ts index eedb819593..efac60e686 100644 --- a/plugins/search-backend-module-pg/src/index.ts +++ b/plugins/search-backend-module-pg/src/index.ts @@ -14,17 +14,12 @@ * limitations under the License. */ -import { default as feature } from './alpha'; - -/** @public */ -const _feature = feature; -export default _feature; - /** * A module for the search backend that implements search using PostgreSQL * * @packageDocumentation */ +export { default } from './module'; export * from './database'; export * from './PgSearchEngine'; diff --git a/plugins/search-backend-module-pg/src/module.ts b/plugins/search-backend-module-pg/src/module.ts new file mode 100644 index 0000000000..43bdb41905 --- /dev/null +++ b/plugins/search-backend-module-pg/src/module.ts @@ -0,0 +1,54 @@ +/* + * 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 { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; +import { PgSearchEngine } from './PgSearchEngine'; + +/** + * @public + * Search backend module for the Postgres engine. + */ +export default createBackendModule({ + pluginId: 'search', + moduleId: 'postgres-engine', + register(env) { + env.registerInit({ + deps: { + searchEngineRegistry: searchEngineRegistryExtensionPoint, + database: coreServices.database, + config: coreServices.rootConfig, + logger: coreServices.logger, + }, + async init({ searchEngineRegistry, database, config, logger }) { + if (await PgSearchEngine.supported(database)) { + searchEngineRegistry.setSearchEngine( + await PgSearchEngine.fromConfig(config, { + database, + logger, + }), + ); + } else { + logger.warn( + 'Postgres search engine is not supported, skipping registration of search-backend-module-pg', + ); + } + }, + }); + }, +}); diff --git a/plugins/search-backend-module-techdocs/report-alpha.api.md b/plugins/search-backend-module-techdocs/report-alpha.api.md index 758441c12d..678f9a679d 100644 --- a/plugins/search-backend-module-techdocs/report-alpha.api.md +++ b/plugins/search-backend-module-techdocs/report-alpha.api.md @@ -8,28 +8,24 @@ import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { TechDocsCollatorDocumentTransformer } from '@backstage/plugin-search-backend-module-techdocs'; import { TechDocsCollatorEntityTransformer } from '@backstage/plugin-search-backend-module-techdocs'; -// @alpha -const _default: BackendFeature; -export default _default; +// @alpha (undocumented) +const _feature: BackendFeature; +export default _feature; + +// Warning: (ae-forgotten-export) The symbol "TechDocsCollatorEntityTransformerExtensionPoint_2" needs to be exported by the entry point alpha.d.ts +// +// @alpha (undocumented) +export type TechDocsCollatorEntityTransformerExtensionPoint = + TechDocsCollatorEntityTransformerExtensionPoint_2; // @alpha (undocumented) -export interface TechDocsCollatorEntityTransformerExtensionPoint { - // (undocumented) - setDocumentTransformer( - transformer: TechDocsCollatorDocumentTransformer, - ): void; - // (undocumented) - setTransformer(transformer: TechDocsCollatorEntityTransformer): void; -} - -// @alpha -export const techdocsCollatorEntityTransformerExtensionPoint: ExtensionPoint; +export const techdocsCollatorEntityTransformerExtensionPoint: ExtensionPoint; // Warnings were encountered during analysis: // -// src/alpha.d.ts:3:1 - (ae-undocumented) Missing documentation for "TechDocsCollatorEntityTransformerExtensionPoint". -// src/alpha.d.ts:4:5 - (ae-undocumented) Missing documentation for "setTransformer". -// src/alpha.d.ts:5:5 - (ae-undocumented) Missing documentation for "setDocumentTransformer". +// src/alpha.d.ts:3:15 - (ae-undocumented) Missing documentation for "_feature". +// src/alpha.d.ts:6:1 - (ae-undocumented) Missing documentation for "TechDocsCollatorEntityTransformerExtensionPoint". +// src/alpha.d.ts:8:22 - (ae-undocumented) Missing documentation for "techdocsCollatorEntityTransformerExtensionPoint". // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/search-backend-module-techdocs/report.api.md b/plugins/search-backend-module-techdocs/report.api.md index 90a4fa9479..9f03812e44 100644 --- a/plugins/search-backend-module-techdocs/report.api.md +++ b/plugins/search-backend-module-techdocs/report.api.md @@ -12,13 +12,20 @@ import { Config } from '@backstage/config'; import { DiscoveryService } from '@backstage/backend-plugin-api'; import { DocumentCollatorFactory } from '@backstage/plugin-search-common'; import { Entity } from '@backstage/catalog-model'; +import { ExtensionPoint } from '@backstage/backend-plugin-api'; import { HttpAuthService } from '@backstage/backend-plugin-api'; import { LoggerService } from '@backstage/backend-plugin-api'; import { Permission } from '@backstage/plugin-permission-common'; import { Readable } from 'stream'; +import { TechDocsCollatorDocumentTransformer as TechDocsCollatorDocumentTransformer_2 } from '@backstage/plugin-search-backend-module-techdocs'; +import { TechDocsCollatorEntityTransformer as TechDocsCollatorEntityTransformer_2 } from '@backstage/plugin-search-backend-module-techdocs'; import { TechDocsDocument } from '@backstage/plugin-techdocs-node'; import { TokenManager } from '@backstage/backend-common'; +// @public +const _default: BackendFeature; +export default _default; + // @public (undocumented) export const defaultTechDocsCollatorEntityTransformer: TechDocsCollatorEntityTransformer; @@ -37,10 +44,6 @@ export class DefaultTechDocsCollatorFactory implements DocumentCollatorFactory { readonly visibilityPermission: Permission; } -// @public (undocumented) -const _feature: BackendFeature; -export default _feature; - // @public (undocumented) export interface MkSearchIndexDoc { // (undocumented) @@ -74,6 +77,19 @@ export type TechDocsCollatorEntityTransformer = ( entity: Entity, ) => Partial>; +// @public (undocumented) +export interface TechDocsCollatorEntityTransformerExtensionPoint { + // (undocumented) + setDocumentTransformer( + transformer: TechDocsCollatorDocumentTransformer_2, + ): void; + // (undocumented) + setTransformer(transformer: TechDocsCollatorEntityTransformer_2): void; +} + +// @public +export const techdocsCollatorEntityTransformerExtensionPoint: ExtensionPoint; + // @public @deprecated export type TechDocsCollatorFactoryOptions = { discovery: DiscoveryService; @@ -103,5 +119,7 @@ export type TechDocsCollatorFactoryOptions = { // src/collators/TechDocsCollatorDocumentTransformer.d.ts:10:1 - (ae-undocumented) Missing documentation for "TechDocsCollatorDocumentTransformer". // src/collators/TechDocsCollatorEntityTransformer.d.ts:4:1 - (ae-undocumented) Missing documentation for "TechDocsCollatorEntityTransformer". // src/collators/defaultTechDocsCollatorEntityTransformer.d.ts:3:22 - (ae-undocumented) Missing documentation for "defaultTechDocsCollatorEntityTransformer". -// src/index.d.ts:7:15 - (ae-undocumented) Missing documentation for "_feature". +// src/module.d.ts:3:1 - (ae-undocumented) Missing documentation for "TechDocsCollatorEntityTransformerExtensionPoint". +// src/module.d.ts:4:5 - (ae-undocumented) Missing documentation for "setTransformer". +// src/module.d.ts:5:5 - (ae-undocumented) Missing documentation for "setDocumentTransformer". ``` diff --git a/plugins/search-backend-module-techdocs/src/alpha.ts b/plugins/search-backend-module-techdocs/src/alpha.ts index 88b914cf19..ecd56a9af1 100644 --- a/plugins/search-backend-module-techdocs/src/alpha.ts +++ b/plugins/search-backend-module-techdocs/src/alpha.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The Backstage Authors + * Copyright 2024 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. @@ -14,122 +14,17 @@ * limitations under the License. */ -/** - * @packageDocumentation - * A module for the search backend that exports TechDocs modules. - */ - import { - coreServices, - createBackendModule, - createExtensionPoint, - readSchedulerServiceTaskScheduleDefinitionFromConfig, -} from '@backstage/backend-plugin-api'; -import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; -import { - DefaultTechDocsCollatorFactory, - TechDocsCollatorDocumentTransformer, - TechDocsCollatorEntityTransformer, -} from '@backstage/plugin-search-backend-module-techdocs'; -import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + default as feature, + TechDocsCollatorEntityTransformerExtensionPoint as ExtensionPoint, + techdocsCollatorEntityTransformerExtensionPoint as extensionPoint, +} from './module'; /** @alpha */ -export interface TechDocsCollatorEntityTransformerExtensionPoint { - setTransformer(transformer: TechDocsCollatorEntityTransformer): void; - setDocumentTransformer( - transformer: TechDocsCollatorDocumentTransformer, - ): void; -} +const _feature = feature; +export default _feature; -/** - * Extension point used to customize the TechDocs collator entity transformer. - * - * @alpha - */ -export const techdocsCollatorEntityTransformerExtensionPoint = - createExtensionPoint({ - id: 'search.techdocsCollator.transformer', - }); - -/** - * @alpha - * Search backend module for the TechDocs index. - */ -export default createBackendModule({ - pluginId: 'search', - moduleId: 'techdocs-collator', - register(env) { - let entityTransformer: TechDocsCollatorEntityTransformer | undefined; - let documentTransformer: TechDocsCollatorDocumentTransformer | undefined; - - env.registerExtensionPoint( - techdocsCollatorEntityTransformerExtensionPoint, - { - setTransformer(newTransformer) { - if (entityTransformer) { - throw new Error( - 'TechDocs collator entity transformer may only be set once', - ); - } - entityTransformer = newTransformer; - }, - setDocumentTransformer(newTransformer) { - if (documentTransformer) { - throw new Error( - 'TechDocs collator document transformer may only be set once', - ); - } - documentTransformer = newTransformer; - }, - }, - ); - - env.registerInit({ - deps: { - config: coreServices.rootConfig, - logger: coreServices.logger, - auth: coreServices.auth, - httpAuth: coreServices.httpAuth, - discovery: coreServices.discovery, - scheduler: coreServices.scheduler, - catalog: catalogServiceRef, - indexRegistry: searchIndexRegistryExtensionPoint, - }, - async init({ - config, - logger, - auth, - httpAuth, - discovery, - scheduler, - catalog, - indexRegistry, - }) { - const defaultSchedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, - }; - - const schedule = config.has('search.collators.techdocs.schedule') - ? readSchedulerServiceTaskScheduleDefinitionFromConfig( - config.getConfig('search.collators.techdocs.schedule'), - ) - : defaultSchedule; - - indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner(schedule), - factory: DefaultTechDocsCollatorFactory.fromConfig(config, { - discovery, - auth, - httpAuth, - logger, - catalogClient: catalog, - entityTransformer, - documentTransformer, - }), - }); - }, - }); - }, -}); +/** @alpha */ +export type TechDocsCollatorEntityTransformerExtensionPoint = ExtensionPoint; +/** @alpha */ +export const techdocsCollatorEntityTransformerExtensionPoint = extensionPoint; diff --git a/plugins/search-backend-module-techdocs/src/index.ts b/plugins/search-backend-module-techdocs/src/index.ts index c8f9a93c6a..cd11b89671 100644 --- a/plugins/search-backend-module-techdocs/src/index.ts +++ b/plugins/search-backend-module-techdocs/src/index.ts @@ -14,15 +14,11 @@ * limitations under the License. */ -import { default as feature } from './alpha'; - /** * @packageDocumentation * A module for the search backend that exports TechDocs modules. */ +export { default } from './module'; +export * from './module'; export * from './collators'; - -/** @public */ -const _feature = feature; -export default _feature; diff --git a/plugins/search-backend-module-techdocs/src/alpha.test.ts b/plugins/search-backend-module-techdocs/src/module.test.ts similarity index 97% rename from plugins/search-backend-module-techdocs/src/alpha.test.ts rename to plugins/search-backend-module-techdocs/src/module.test.ts index f1875a881b..92e4366980 100644 --- a/plugins/search-backend-module-techdocs/src/alpha.test.ts +++ b/plugins/search-backend-module-techdocs/src/module.test.ts @@ -16,7 +16,7 @@ import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; -import searchModuleTechDocsCollator from './alpha'; +import searchModuleTechDocsCollator from './module'; describe('searchModuleTechDocsCollator', () => { const schedule = { diff --git a/plugins/search-backend-module-techdocs/src/module.ts b/plugins/search-backend-module-techdocs/src/module.ts new file mode 100644 index 0000000000..0114b88c2d --- /dev/null +++ b/plugins/search-backend-module-techdocs/src/module.ts @@ -0,0 +1,135 @@ +/* + * 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, + createExtensionPoint, + readSchedulerServiceTaskScheduleDefinitionFromConfig, +} from '@backstage/backend-plugin-api'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { + DefaultTechDocsCollatorFactory, + TechDocsCollatorDocumentTransformer, + TechDocsCollatorEntityTransformer, +} from '@backstage/plugin-search-backend-module-techdocs'; +import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha'; + +/** @public */ +export interface TechDocsCollatorEntityTransformerExtensionPoint { + setTransformer(transformer: TechDocsCollatorEntityTransformer): void; + setDocumentTransformer( + transformer: TechDocsCollatorDocumentTransformer, + ): void; +} + +/** + * Extension point used to customize the TechDocs collator entity transformer. + * + * @public + */ +export const techdocsCollatorEntityTransformerExtensionPoint = + createExtensionPoint({ + id: 'search.techdocsCollator.transformer', + }); + +/** + * @public + * Search backend module for the TechDocs index. + */ +export default createBackendModule({ + pluginId: 'search', + moduleId: 'techdocs-collator', + register(env) { + let entityTransformer: TechDocsCollatorEntityTransformer | undefined; + let documentTransformer: TechDocsCollatorDocumentTransformer | undefined; + + env.registerExtensionPoint( + techdocsCollatorEntityTransformerExtensionPoint, + { + setTransformer(newTransformer) { + if (entityTransformer) { + throw new Error( + 'TechDocs collator entity transformer may only be set once', + ); + } + entityTransformer = newTransformer; + }, + setDocumentTransformer(newTransformer) { + if (documentTransformer) { + throw new Error( + 'TechDocs collator document transformer may only be set once', + ); + } + documentTransformer = newTransformer; + }, + }, + ); + + env.registerInit({ + deps: { + config: coreServices.rootConfig, + logger: coreServices.logger, + auth: coreServices.auth, + httpAuth: coreServices.httpAuth, + discovery: coreServices.discovery, + scheduler: coreServices.scheduler, + catalog: catalogServiceRef, + indexRegistry: searchIndexRegistryExtensionPoint, + }, + async init({ + config, + logger, + auth, + httpAuth, + discovery, + scheduler, + catalog, + indexRegistry, + }) { + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; + + const schedule = config.has('search.collators.techdocs.schedule') + ? readSchedulerServiceTaskScheduleDefinitionFromConfig( + config.getConfig('search.collators.techdocs.schedule'), + ) + : defaultSchedule; + + indexRegistry.addCollator({ + schedule: scheduler.createScheduledTaskRunner(schedule), + factory: DefaultTechDocsCollatorFactory.fromConfig(config, { + discovery, + auth, + httpAuth, + logger, + catalogClient: catalog, + entityTransformer, + documentTransformer, + }), + }); + }, + }); + }, +});