implement extension point
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-search-backend-module-catalog': patch
|
||||
---
|
||||
|
||||
Breaking change in the alpha export `searchModuleCatalogCollator`: Moved collator settings from module options into app-config. You are now expected to set up the catalog collator under the `search.collators.catalog` configuration key.
|
||||
Breaking change in the alpha export `searchModuleCatalogCollator`: Moved collator settings from module options into app-config. You are now expected to set up the catalog collator under the `search.collators.catalog` configuration key. There is also a new `catalogCollatorExtensionPoint` extension point for the module, wherein you can set custom transformers.
|
||||
|
||||
@@ -5,16 +5,18 @@
|
||||
```ts
|
||||
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 const searchModuleCatalogCollator: (
|
||||
options?: SearchModuleCatalogCollatorOptions | undefined,
|
||||
) => BackendFeature;
|
||||
|
||||
// @alpha
|
||||
export type SearchModuleCatalogCollatorOptions = {
|
||||
entityTransformer?: CatalogCollatorEntityTransformer;
|
||||
export type CatalogCollatorExtensionPoint = {
|
||||
setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void;
|
||||
};
|
||||
|
||||
// @alpha
|
||||
export const catalogCollatorExtensionPoint: ExtensionPoint<CatalogCollatorExtensionPoint>;
|
||||
|
||||
// @alpha
|
||||
export const searchModuleCatalogCollator: () => BackendFeature;
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
createExtensionPoint,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';
|
||||
import {
|
||||
@@ -32,57 +33,78 @@ import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-back
|
||||
import { readScheduleConfigOptions } from './collators/config';
|
||||
|
||||
/**
|
||||
* Options for {@link searchModuleCatalogCollator}.
|
||||
* Options for {@link catalogCollatorExtensionPoint}.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export type SearchModuleCatalogCollatorOptions = {
|
||||
export type CatalogCollatorExtensionPoint = {
|
||||
/**
|
||||
* Allows you to customize how entities are shaped into documents.
|
||||
*/
|
||||
entityTransformer?: CatalogCollatorEntityTransformer;
|
||||
setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extension point for customizing how catalog entities are shaped into
|
||||
* documents for the search backend, when using
|
||||
* {@link searchModuleCatalogCollator}.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogCollatorExtensionPoint =
|
||||
createExtensionPoint<CatalogCollatorExtensionPoint>({
|
||||
id: 'search.catalogCollator.extension',
|
||||
});
|
||||
|
||||
/**
|
||||
* Search backend module for the Catalog index.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const searchModuleCatalogCollator = createBackendModule(
|
||||
(options?: SearchModuleCatalogCollatorOptions) => ({
|
||||
moduleId: 'catalogCollator',
|
||||
pluginId: 'search',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
config: coreServices.rootConfig,
|
||||
discovery: coreServices.discovery,
|
||||
tokenManager: coreServices.tokenManager,
|
||||
scheduler: coreServices.scheduler,
|
||||
indexRegistry: searchIndexRegistryExtensionPoint,
|
||||
catalog: catalogServiceRef,
|
||||
},
|
||||
async init({
|
||||
config,
|
||||
discovery,
|
||||
tokenManager,
|
||||
scheduler,
|
||||
indexRegistry,
|
||||
catalog,
|
||||
}) {
|
||||
indexRegistry.addCollator({
|
||||
schedule: scheduler.createScheduledTaskRunner(
|
||||
readScheduleConfigOptions(config),
|
||||
),
|
||||
factory: DefaultCatalogCollatorFactory.fromConfig(config, {
|
||||
entityTransformer: options?.entityTransformer,
|
||||
discovery,
|
||||
tokenManager,
|
||||
catalogClient: catalog,
|
||||
}),
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
export const searchModuleCatalogCollator = createBackendModule({
|
||||
moduleId: 'catalogCollator',
|
||||
pluginId: 'search',
|
||||
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: {
|
||||
config: coreServices.rootConfig,
|
||||
discovery: coreServices.discovery,
|
||||
tokenManager: coreServices.tokenManager,
|
||||
scheduler: coreServices.scheduler,
|
||||
indexRegistry: searchIndexRegistryExtensionPoint,
|
||||
catalog: catalogServiceRef,
|
||||
},
|
||||
async init({
|
||||
config,
|
||||
discovery,
|
||||
tokenManager,
|
||||
scheduler,
|
||||
indexRegistry,
|
||||
catalog,
|
||||
}) {
|
||||
indexRegistry.addCollator({
|
||||
schedule: scheduler.createScheduledTaskRunner(
|
||||
readScheduleConfigOptions(config),
|
||||
),
|
||||
factory: DefaultCatalogCollatorFactory.fromConfig(config, {
|
||||
entityTransformer,
|
||||
discovery,
|
||||
tokenManager,
|
||||
catalogClient: catalog,
|
||||
}),
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user