Merge pull request #16710 from backstage/search/backend-system-migration
[Search] Migrate search to new backend system
This commit is contained in:
@@ -3,18 +3,14 @@
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
/// <reference types="node" />
|
||||
|
||||
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 type { ToolDocument as ToolDocument_2 } from '@backstage/plugin-search-backend-module-explore';
|
||||
import { ToolDocumentCollatorFactory as ToolDocumentCollatorFactory_2 } from '@backstage/plugin-search-backend-module-explore';
|
||||
import type { ToolDocumentCollatorFactoryOptions as ToolDocumentCollatorFactoryOptions_2 } from '@backstage/plugin-search-backend-module-explore';
|
||||
|
||||
// @public (undocumented)
|
||||
export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
@@ -40,27 +36,13 @@ export class StaticExploreToolProvider implements ExploreToolProvider {
|
||||
getTools(request: GetExploreToolsRequest): Promise<GetExploreToolsResponse>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface ToolDocument extends IndexableDocument, ExploreTool {}
|
||||
// @public @deprecated (undocumented)
|
||||
export type ToolDocument = ToolDocument_2;
|
||||
|
||||
// @public
|
||||
export class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
// (undocumented)
|
||||
execute(): AsyncGenerator<ToolDocument>;
|
||||
// (undocumented)
|
||||
static fromConfig(
|
||||
_config: Config,
|
||||
options: ToolDocumentCollatorFactoryOptions,
|
||||
): ToolDocumentCollatorFactory;
|
||||
// (undocumented)
|
||||
getCollator(): Promise<Readable>;
|
||||
// (undocumented)
|
||||
readonly type: string;
|
||||
}
|
||||
// @public @deprecated (undocumented)
|
||||
export const ToolDocumentCollatorFactory: typeof ToolDocumentCollatorFactory_2;
|
||||
|
||||
// @public
|
||||
export type ToolDocumentCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
logger: Logger;
|
||||
};
|
||||
// @public @deprecated (undocumented)
|
||||
export type ToolDocumentCollatorFactoryOptions =
|
||||
ToolDocumentCollatorFactoryOptions_2;
|
||||
```
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export * from './search';
|
||||
export * from './service';
|
||||
export * from './tools';
|
||||
|
||||
@@ -28,3 +27,28 @@ export * from './tools';
|
||||
* @internal Example only - do not use in production
|
||||
*/
|
||||
export { exampleTools } from './example/exampleTools';
|
||||
|
||||
import { ToolDocumentCollatorFactory as _ToolDocumentCollatorFactory } from '@backstage/plugin-search-backend-module-explore';
|
||||
import type {
|
||||
ToolDocument as _ToolDocument,
|
||||
ToolDocumentCollatorFactoryOptions as _ToolDocumentCollatorFactoryOptions,
|
||||
} from '@backstage/plugin-search-backend-module-explore';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated import from `@backstage/search-backend-module-explore` instead
|
||||
*/
|
||||
export const ToolDocumentCollatorFactory = _ToolDocumentCollatorFactory;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated import from `@backstage/search-backend-module-explore` instead
|
||||
*/
|
||||
export type ToolDocument = _ToolDocument;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated import from `@backstage/search-backend-module-explore` instead
|
||||
*/
|
||||
export type ToolDocumentCollatorFactoryOptions =
|
||||
_ToolDocumentCollatorFactoryOptions;
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 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 { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ExploreTool } from '@backstage/plugin-explore-common';
|
||||
import {
|
||||
DocumentCollatorFactory,
|
||||
IndexableDocument,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import fetch from 'node-fetch';
|
||||
import { Readable } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
/**
|
||||
* Extended IndexableDocument with explore tool specific properties
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ToolDocument extends IndexableDocument, ExploreTool {}
|
||||
|
||||
/**
|
||||
* The options for the {@link ToolDocumentCollatorFactory}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type ToolDocumentCollatorFactoryOptions = {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
/**
|
||||
* Search collator responsible for collecting explore tools to index.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
|
||||
public readonly type: string = 'tools';
|
||||
|
||||
private readonly discovery: PluginEndpointDiscovery;
|
||||
private readonly logger: Logger;
|
||||
|
||||
private constructor(options: ToolDocumentCollatorFactoryOptions) {
|
||||
this.discovery = options.discovery;
|
||||
this.logger = options.logger;
|
||||
}
|
||||
|
||||
static fromConfig(
|
||||
_config: Config,
|
||||
options: ToolDocumentCollatorFactoryOptions,
|
||||
) {
|
||||
return new ToolDocumentCollatorFactory(options);
|
||||
}
|
||||
|
||||
async getCollator() {
|
||||
return Readable.from(this.execute());
|
||||
}
|
||||
|
||||
async *execute(): AsyncGenerator<ToolDocument> {
|
||||
this.logger.info('Starting collation of explore tools');
|
||||
|
||||
const tools = await this.fetchTools();
|
||||
|
||||
for (const tool of tools) {
|
||||
yield {
|
||||
...tool,
|
||||
text: tool.description,
|
||||
location: tool.url,
|
||||
};
|
||||
}
|
||||
|
||||
this.logger.info('Finished collation of explore tools');
|
||||
}
|
||||
|
||||
private async fetchTools() {
|
||||
const baseUrl = await this.discovery.getBaseUrl('explore');
|
||||
const response = await fetch(`${baseUrl}/tools`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to explore fetch tools, ${response.status}: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.tools;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 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 { ToolDocumentCollatorFactory } from './ToolDocumentCollatorFactory';
|
||||
export type {
|
||||
ToolDocument,
|
||||
ToolDocumentCollatorFactoryOptions,
|
||||
} from './ToolDocumentCollatorFactory';
|
||||
Reference in New Issue
Block a user