define interfaces for extension points and services
Signed-off-by: Emma Indal <emma.indahl@gmail.com> Co-authored-by: Camila Loiola <camilaibs@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createServiceRef } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
DocumentDecoratorFactory,
|
||||
DocumentTypeInfo,
|
||||
@@ -23,16 +24,20 @@ import { Transform, pipeline } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
import { Scheduler } from './Scheduler';
|
||||
import {
|
||||
IndexBuilderService,
|
||||
IndexBuilderOptions,
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
} from './types';
|
||||
|
||||
export const searchIndexBuilderRef = createServiceRef<IndexBuilderService>({
|
||||
id: 'search.index-node',
|
||||
});
|
||||
/**
|
||||
* Used for adding collators, decorators and compile them into tasks which are added to a scheduler returned to the caller.
|
||||
* @public
|
||||
*/
|
||||
export class IndexBuilder {
|
||||
export class IndexBuilder implements IndexBuilderService {
|
||||
private collators: Record<string, RegisterCollatorParameters>;
|
||||
private decorators: Record<string, DocumentDecoratorFactory[]>;
|
||||
private documentTypes: Record<string, DocumentTypeInfo>;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export { IndexBuilder } from './IndexBuilder';
|
||||
export { IndexBuilder, searchIndexBuilderRef } from './IndexBuilder';
|
||||
export { Scheduler } from './Scheduler';
|
||||
export * from './collators';
|
||||
export { LunrSearchEngine } from './engines';
|
||||
|
||||
@@ -18,9 +18,11 @@ import { TaskRunner } from '@backstage/backend-tasks';
|
||||
import {
|
||||
DocumentCollatorFactory,
|
||||
DocumentDecoratorFactory,
|
||||
DocumentTypeInfo,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { Logger } from 'winston';
|
||||
import { Scheduler } from './Scheduler';
|
||||
|
||||
/**
|
||||
* Options required to instantiate the index builder.
|
||||
@@ -57,3 +59,27 @@ export interface RegisterDecoratorParameters {
|
||||
*/
|
||||
factory: DocumentDecoratorFactory;
|
||||
}
|
||||
|
||||
export type IndexBuilderServiceBuildOptions = {
|
||||
searchEngine: SearchEngine;
|
||||
collators: RegisterCollatorParameters[];
|
||||
decorators: RegisterDecoratorParameters[];
|
||||
};
|
||||
export interface IndexBuilderService {
|
||||
build(options: IndexBuilderServiceBuildOptions): Promise<{
|
||||
scheduler: Scheduler;
|
||||
}>;
|
||||
getDocumentTypes(): Record<string, DocumentTypeInfo>;
|
||||
}
|
||||
|
||||
export interface SearchIndexRegistryExtensionPoint {
|
||||
addCollator(options: RegisterCollatorParameters): void;
|
||||
addDecorator(options: RegisterDecoratorParameters): void;
|
||||
getCollators(): RegisterCollatorParameters[];
|
||||
getDecorators(): RegisterDecoratorParameters[];
|
||||
}
|
||||
|
||||
export interface SearchEngineRegistryExtensionPoint {
|
||||
setSearchEngine(searchEngine: SearchEngine): void;
|
||||
getSearchEngine(): SearchEngine;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user