use alpha exports
Signed-off-by: Emma Indal <emma.indahl@gmail.com> Co-authored-by: Camila Loiola <camilaibs@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ 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 { searchPlugin } from '@backstage/plugin-search-backend';
|
||||
import { searchPlugin } from '@backstage/plugin-search-backend/alpha';
|
||||
import { searchIndexRegistry } from './plugins/search';
|
||||
|
||||
const backend = createBackend();
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node';
|
||||
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';
|
||||
|
||||
@@ -6,9 +6,22 @@
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
"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"
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
ElasticSearchCustomIndexTemplate,
|
||||
ElasticSearchQueryTranslator,
|
||||
ElasticSearchSearchEngine,
|
||||
} from './engines';
|
||||
|
||||
export type ElasticSearchEngineModuleOptions = {
|
||||
translator?: ElasticSearchQueryTranslator;
|
||||
indexTemplate?: ElasticSearchCustomIndexTemplate;
|
||||
};
|
||||
|
||||
export const elasticSearchEngineModule = createBackendModule(
|
||||
(options?: ElasticSearchEngineModuleOptions) => ({
|
||||
moduleId: 'elasticSearchEngineModule',
|
||||
pluginId: 'search',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger, config }) {
|
||||
const searchEngine = await ElasticSearchSearchEngine.fromConfig({
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
config: config,
|
||||
});
|
||||
searchEngineRegistry.setSearchEngine(searchEngine);
|
||||
// set custom translator if available
|
||||
if (options?.translator) {
|
||||
searchEngine.setTranslator(options.translator);
|
||||
}
|
||||
|
||||
// set custom index template if available
|
||||
if (options?.indexTemplate) {
|
||||
searchEngine.setIndexTemplate(options.indexTemplate);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
+1
-46
@@ -30,17 +30,9 @@ import { ElasticSearchClientWrapper } from './ElasticSearchClientWrapper';
|
||||
import { ElasticSearchCustomIndexTemplate } from './types';
|
||||
import { ElasticSearchSearchEngineIndexer } from './ElasticSearchSearchEngineIndexer';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
MissingIndexError,
|
||||
searchEngineRegistryExtensionPoint,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
import { MissingIndexError } from '@backstage/plugin-search-backend-node';
|
||||
import esb from 'elastic-builder';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
export type { ElasticSearchClientOptions };
|
||||
|
||||
@@ -529,40 +521,3 @@ export async function createElasticSearchClientOptions(
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
export type ElasticSearchEngineModuleOptions = {
|
||||
translator?: ElasticSearchQueryTranslator;
|
||||
indexTemplate?: ElasticSearchCustomIndexTemplate;
|
||||
};
|
||||
|
||||
export const elasticSearchEngineModule = createBackendModule(
|
||||
(options?: ElasticSearchEngineModuleOptions) => ({
|
||||
moduleId: 'elasticSearchEngineModule',
|
||||
pluginId: 'search',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger, config }) {
|
||||
const searchEngine = await ElasticSearchSearchEngine.fromConfig({
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
config: config,
|
||||
});
|
||||
searchEngineRegistry.setSearchEngine(searchEngine);
|
||||
// set custom translator if available
|
||||
if (options?.translator) {
|
||||
searchEngine.setTranslator(options.translator);
|
||||
}
|
||||
|
||||
// set custom index template if available
|
||||
if (options?.indexTemplate) {
|
||||
searchEngine.setIndexTemplate(options.indexTemplate);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
export {
|
||||
decodePageCursor as decodeElasticSearchPageCursor,
|
||||
ElasticSearchSearchEngine,
|
||||
elasticSearchEngineModule,
|
||||
} from './ElasticSearchSearchEngine';
|
||||
export { isOpenSearchCompatible } from './ElasticSearchClientOptions';
|
||||
export type {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
export {
|
||||
decodeElasticSearchPageCursor,
|
||||
ElasticSearchSearchEngine,
|
||||
elasticSearchEngineModule,
|
||||
isOpenSearchCompatible,
|
||||
} from './engines';
|
||||
export type {
|
||||
|
||||
@@ -6,9 +6,22 @@
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
"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"
|
||||
@@ -24,6 +37,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/config": "workspace:^",
|
||||
"@backstage/plugin-search-backend-node": "workspace:^",
|
||||
"@backstage/plugin-search-common": "workspace:^",
|
||||
|
||||
@@ -30,11 +30,6 @@ import {
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node';
|
||||
|
||||
/**
|
||||
* Search query that the Postgres search engine understands.
|
||||
@@ -249,24 +244,3 @@ export function decodePageCursor(pageCursor?: string): { page: number } {
|
||||
export function encodePageCursor({ page }: { page: number }): string {
|
||||
return Buffer.from(`${page}`, 'utf-8').toString('base64');
|
||||
}
|
||||
|
||||
export const pgSearchEngineModule = createBackendModule({
|
||||
moduleId: 'pgSearchEngineModule',
|
||||
pluginId: 'search',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
database: coreServices.database,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, database, config }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await PgSearchEngine.fromConfig(config, {
|
||||
database: database,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { PgSearchEngine, pgSearchEngineModule } from './PgSearchEngine';
|
||||
export { PgSearchEngine } from './PgSearchEngine';
|
||||
export type {
|
||||
ConcretePgSearchQuery,
|
||||
PgSearchQueryTranslatorOptions,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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';
|
||||
|
||||
export const pgSearchEngineModule = createBackendModule({
|
||||
moduleId: 'pgSearchEngineModule',
|
||||
pluginId: 'search',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
database: coreServices.database,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, database, config }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await PgSearchEngine.fromConfig(config, {
|
||||
database: database,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -6,9 +6,22 @@
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
"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": "node-library"
|
||||
|
||||
+45
-6
@@ -15,19 +15,42 @@
|
||||
*/
|
||||
|
||||
import { Logger } from 'winston';
|
||||
|
||||
import {
|
||||
createServiceRef,
|
||||
createServiceFactory,
|
||||
coreServices,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
DocumentTypeInfo,
|
||||
SearchEngine,
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
|
||||
import {
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
} from './types';
|
||||
|
||||
import { IndexBuilder } from './IndexBuilder';
|
||||
import { Scheduler } from './Scheduler';
|
||||
import {
|
||||
IndexBuilderServiceBuildOptions,
|
||||
SearchIndexBuilderService,
|
||||
} from './types';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
export interface SearchIndexBuilderService {
|
||||
build(options: IndexBuilderServiceBuildOptions): Promise<{
|
||||
scheduler: Scheduler;
|
||||
}>;
|
||||
getDocumentTypes(): Record<string, DocumentTypeInfo>;
|
||||
}
|
||||
|
||||
export interface SearchIndexRegistryExtensionPoint {
|
||||
addCollator(options: RegisterCollatorParameters): void;
|
||||
addDecorator(options: RegisterDecoratorParameters): void;
|
||||
}
|
||||
|
||||
export interface SearchEngineRegistryExtensionPoint {
|
||||
setSearchEngine(searchEngine: SearchEngine): void;
|
||||
}
|
||||
|
||||
type DefaultSearchIndexBuilderServiceOptions = {
|
||||
logger: Logger;
|
||||
@@ -85,3 +108,19 @@ export const searchIndexBuilderService =
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export const searchEngineRegistryExtensionPoint =
|
||||
createExtensionPoint<SearchEngineRegistryExtensionPoint>({
|
||||
id: 'search.engine.registry',
|
||||
});
|
||||
|
||||
export const searchIndexRegistryExtensionPoint =
|
||||
createExtensionPoint<SearchIndexRegistryExtensionPoint>({
|
||||
id: 'search.index.registry',
|
||||
});
|
||||
|
||||
export type IndexBuilderServiceBuildOptions = {
|
||||
searchEngine: SearchEngine;
|
||||
collators: RegisterCollatorParameters[];
|
||||
decorators: RegisterDecoratorParameters[];
|
||||
};
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
coreServices,
|
||||
createBackendModule,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { searchEngineRegistryExtensionPoint } from '../extensions';
|
||||
import { searchEngineRegistryExtensionPoint } from '../alpha';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,15 +33,9 @@ export type {
|
||||
IndexBuilderOptions,
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
SearchIndexRegistryExtensionPoint,
|
||||
SearchEngineRegistryExtensionPoint,
|
||||
} from './types';
|
||||
export * from './errors';
|
||||
export * from './indexing';
|
||||
export * from './test-utils';
|
||||
|
||||
export type { ScheduleTaskParameters } from './Scheduler';
|
||||
|
||||
// TODO: export as alfa subpath
|
||||
export * from './services';
|
||||
export * from './extensions';
|
||||
|
||||
@@ -18,11 +18,9 @@ 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.
|
||||
@@ -59,24 +57,3 @@ export interface RegisterDecoratorParameters {
|
||||
*/
|
||||
factory: DocumentDecoratorFactory;
|
||||
}
|
||||
|
||||
export type IndexBuilderServiceBuildOptions = {
|
||||
searchEngine: SearchEngine;
|
||||
collators: RegisterCollatorParameters[];
|
||||
decorators: RegisterDecoratorParameters[];
|
||||
};
|
||||
export interface SearchIndexBuilderService {
|
||||
build(options: IndexBuilderServiceBuildOptions): Promise<{
|
||||
scheduler: Scheduler;
|
||||
}>;
|
||||
getDocumentTypes(): Record<string, DocumentTypeInfo>;
|
||||
}
|
||||
|
||||
export interface SearchIndexRegistryExtensionPoint {
|
||||
addCollator(options: RegisterCollatorParameters): void;
|
||||
addDecorator(options: RegisterDecoratorParameters): void;
|
||||
}
|
||||
|
||||
export interface SearchEngineRegistryExtensionPoint {
|
||||
setSearchEngine(searchEngine: SearchEngine): void;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,22 @@
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
"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"
|
||||
|
||||
+1
-15
@@ -14,18 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
SearchEngineRegistryExtensionPoint,
|
||||
SearchIndexRegistryExtensionPoint,
|
||||
} from './types';
|
||||
|
||||
export const searchEngineRegistryExtensionPoint =
|
||||
createExtensionPoint<SearchEngineRegistryExtensionPoint>({
|
||||
id: 'search.engine.registry',
|
||||
});
|
||||
|
||||
export const searchIndexRegistryExtensionPoint =
|
||||
createExtensionPoint<SearchIndexRegistryExtensionPoint>({
|
||||
id: 'search.index.registry',
|
||||
});
|
||||
export { searchPlugin } from './plugin';
|
||||
@@ -21,4 +21,3 @@
|
||||
*/
|
||||
|
||||
export * from './service/router';
|
||||
export * from './plugin';
|
||||
|
||||
@@ -19,16 +19,18 @@ import {
|
||||
createBackendPlugin,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
LunrSearchEngine,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
import {
|
||||
searchIndexBuilderService,
|
||||
searchIndexRegistryExtensionPoint,
|
||||
SearchIndexRegistryExtensionPoint,
|
||||
searchEngineRegistryExtensionPoint,
|
||||
RegisterCollatorParameters,
|
||||
RegisterDecoratorParameters,
|
||||
SearchEngineRegistryExtensionPoint,
|
||||
LunrSearchEngine,
|
||||
} from '@backstage/plugin-search-backend-node';
|
||||
searchEngineRegistryExtensionPoint,
|
||||
} from '@backstage/plugin-search-backend-node/alpha';
|
||||
|
||||
import { createRouter } from './service/router';
|
||||
import { SearchEngine } from '@backstage/plugin-search-common';
|
||||
|
||||
@@ -7796,6 +7796,7 @@ __metadata:
|
||||
resolution: "@backstage/plugin-search-backend-module-pg@workspace:plugins/search-backend-module-pg"
|
||||
dependencies:
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/config": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user