From 634abc1a41a678155ee1a7039bf3a1012348b362 Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Mon, 24 Jan 2022 14:46:11 +0000 Subject: [PATCH] search: move DocumentTypeInfo to search-common Signed-off-by: MT Lewis --- .changeset/nasty-dodos-complain.md | 3 ++- packages/search-common/api-report.md | 7 +++++++ packages/search-common/src/types.ts | 13 +++++++++++++ plugins/search-backend-node/api-report.md | 9 +-------- plugins/search-backend-node/package.json | 1 - plugins/search-backend-node/src/IndexBuilder.ts | 10 +--------- plugins/search-backend-node/src/index.ts | 1 - plugins/search-backend/api-report.md | 2 +- plugins/search-backend/package.json | 2 +- .../src/service/AuthorizedSearchEngine.ts | 2 +- plugins/search-backend/src/service/router.ts | 7 ++----- 11 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.changeset/nasty-dodos-complain.md b/.changeset/nasty-dodos-complain.md index 24e53f08d8..f81ddfd97a 100644 --- a/.changeset/nasty-dodos-complain.md +++ b/.changeset/nasty-dodos-complain.md @@ -2,4 +2,5 @@ '@backstage/search-common': patch --- -Add optional visibilityPermission property to DocumentCollator type +- Add optional visibilityPermission property to DocumentCollator type +- Add new DocumentTypeInfo type for housing information about the document types stored in a search engine. diff --git a/packages/search-common/api-report.md b/packages/search-common/api-report.md index ec5a671d33..65f9f25180 100644 --- a/packages/search-common/api-report.md +++ b/packages/search-common/api-report.md @@ -25,6 +25,13 @@ export interface DocumentDecorator { readonly types?: string[]; } +// Warning: (ae-missing-release-tag) "DocumentTypeInfo" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export type DocumentTypeInfo = { + visibilityPermission?: Permission; +}; + // Warning: (ae-missing-release-tag) "IndexableDocument" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public diff --git a/packages/search-common/src/types.ts b/packages/search-common/src/types.ts index 8dd4c58b0e..4e61767ea0 100644 --- a/packages/search-common/src/types.ts +++ b/packages/search-common/src/types.ts @@ -68,6 +68,19 @@ export interface IndexableDocument { }; } +/** + * Information about a specific document type. Intended to be used in the + * {@link @backstage/search-backend-node#IndexBuilder} to collect information + * about the types stored in the index. + */ +export type DocumentTypeInfo = { + /** + * The {@link @backstage/plugin-permission-common#Permission} that controls + * visibility of resources associated with this collator's documents. + */ + visibilityPermission?: Permission; +}; + /** * Interface that must be implemented in order to expose new documents to * search. diff --git a/plugins/search-backend-node/api-report.md b/plugins/search-backend-node/api-report.md index 41ef31645e..1929009760 100644 --- a/plugins/search-backend-node/api-report.md +++ b/plugins/search-backend-node/api-report.md @@ -5,22 +5,15 @@ ```ts import { DocumentCollator } from '@backstage/search-common'; import { DocumentDecorator } from '@backstage/search-common'; +import { DocumentTypeInfo } from '@backstage/search-common'; import { IndexableDocument } from '@backstage/search-common'; import { Logger as Logger_2 } from 'winston'; import { default as lunr_2 } from 'lunr'; -import { Permission } from '@backstage/plugin-permission-common'; import { QueryTranslator } from '@backstage/search-common'; import { SearchEngine } from '@backstage/search-common'; import { SearchQuery } from '@backstage/search-common'; import { SearchResultSet } from '@backstage/search-common'; -// Warning: (ae-missing-release-tag) "DocumentTypeInfo" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type DocumentTypeInfo = { - visibilityPermission?: Permission; -}; - // Warning: (ae-missing-release-tag) "IndexBuilder" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) diff --git a/plugins/search-backend-node/package.json b/plugins/search-backend-node/package.json index d6ff59773e..09de7f16ee 100644 --- a/plugins/search-backend-node/package.json +++ b/plugins/search-backend-node/package.json @@ -20,7 +20,6 @@ "clean": "backstage-cli clean" }, "dependencies": { - "@backstage/plugin-permission-common": "^0.4.0-next.0", "@backstage/search-common": "^0.2.1", "winston": "^3.2.1", "lunr": "^2.3.9", diff --git a/plugins/search-backend-node/src/IndexBuilder.ts b/plugins/search-backend-node/src/IndexBuilder.ts index 5029e644f5..92adb03d7d 100644 --- a/plugins/search-backend-node/src/IndexBuilder.ts +++ b/plugins/search-backend-node/src/IndexBuilder.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { Permission } from '@backstage/plugin-permission-common'; import { DocumentCollator, DocumentDecorator, + DocumentTypeInfo, IndexableDocument, SearchEngine, } from '@backstage/search-common'; @@ -38,14 +38,6 @@ type IndexBuilderOptions = { logger: Logger; }; -export type DocumentTypeInfo = { - /** - * The {@link @backstage/plugin-permission-common#Permission} that controls - * visibility of resources associated with this collator's documents. - */ - visibilityPermission?: Permission; -}; - export class IndexBuilder { private collators: Record; private decorators: Record; diff --git a/plugins/search-backend-node/src/index.ts b/plugins/search-backend-node/src/index.ts index 006d9c6edc..d49ef195f2 100644 --- a/plugins/search-backend-node/src/index.ts +++ b/plugins/search-backend-node/src/index.ts @@ -21,7 +21,6 @@ */ export { IndexBuilder } from './IndexBuilder'; -export type { DocumentTypeInfo } from './IndexBuilder'; export { Scheduler } from './Scheduler'; export { LunrSearchEngine } from './engines'; diff --git a/plugins/search-backend/api-report.md b/plugins/search-backend/api-report.md index 125bd6cc1d..796f54c09d 100644 --- a/plugins/search-backend/api-report.md +++ b/plugins/search-backend/api-report.md @@ -4,7 +4,7 @@ ```ts import { Config } from '@backstage/config'; -import { DocumentTypeInfo } from '@backstage/plugin-search-backend-node'; +import { DocumentTypeInfo } from '@backstage/search-common'; import express from 'express'; import { Logger as Logger_2 } from 'winston'; import { PermissionAuthorizer } from '@backstage/plugin-permission-common'; diff --git a/plugins/search-backend/package.json b/plugins/search-backend/package.json index 4ff4e98e52..1db6a0a910 100644 --- a/plugins/search-backend/package.json +++ b/plugins/search-backend/package.json @@ -23,7 +23,7 @@ "@backstage/backend-common": "^0.10.4", "@backstage/config": "^0.1.13", "@backstage/errors": "^0.2.0", - "@backstage/search-common": "^0.2.0", + "@backstage/search-common": "^0.2.1", "@backstage/plugin-auth-backend": "^0.7.0-next.0", "@backstage/plugin-permission-common": "^0.4.0-next.0", "@backstage/plugin-permission-node": "^0.4.0-next.0", diff --git a/plugins/search-backend/src/service/AuthorizedSearchEngine.ts b/plugins/search-backend/src/service/AuthorizedSearchEngine.ts index 6f33307f6f..7d39230bf5 100644 --- a/plugins/search-backend/src/service/AuthorizedSearchEngine.ts +++ b/plugins/search-backend/src/service/AuthorizedSearchEngine.ts @@ -23,6 +23,7 @@ import { PermissionAuthorizer, } from '@backstage/plugin-permission-common'; import { + DocumentTypeInfo, IndexableDocument, QueryRequestOptions, QueryTranslator, @@ -31,7 +32,6 @@ import { SearchResult, SearchResultSet, } from '@backstage/search-common'; -import { DocumentTypeInfo } from '@backstage/plugin-search-backend-node'; import { Config } from '@backstage/config'; export function decodePageCursor(pageCursor?: string): { page: number } { diff --git a/plugins/search-backend/src/service/router.ts b/plugins/search-backend/src/service/router.ts index f8cf2ae95b..28a3247919 100644 --- a/plugins/search-backend/src/service/router.ts +++ b/plugins/search-backend/src/service/router.ts @@ -24,11 +24,8 @@ import { Config } from '@backstage/config'; import { JsonObject, JsonValue } from '@backstage/types'; import { IdentityClient } from '@backstage/plugin-auth-backend'; import { PermissionAuthorizer } from '@backstage/plugin-permission-common'; -import { SearchResultSet } from '@backstage/search-common'; -import { - DocumentTypeInfo, - SearchEngine, -} from '@backstage/plugin-search-backend-node'; +import { DocumentTypeInfo, SearchResultSet } from '@backstage/search-common'; +import { SearchEngine } from '@backstage/plugin-search-backend-node'; import { AuthorizedSearchEngine } from './AuthorizedSearchEngine'; const jsonObjectSchema: z.ZodSchema = z.lazy(() => {