From 1de7dd85b00185472a07edf9b03d5fe2c36b39e4 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 11:08:57 +0100 Subject: [PATCH 1/7] chore: moving the CatalogEntityDocument to catalog-common Signed-off-by: blam --- plugins/catalog-backend/api-report.md | 16 ++-------- .../search/DefaultCatalogCollatorFactory.ts | 20 +++++-------- plugins/catalog-common/api-report.md | 15 ++++++++++ plugins/catalog-common/package.json | 3 +- plugins/catalog-common/src/index.ts | 2 ++ .../src/search/CatalogEntityDocument.ts | 29 +++++++++++++++++++ plugins/catalog-common/src/search/index.ts | 16 ++++++++++ 7 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 plugins/catalog-common/src/search/CatalogEntityDocument.ts create mode 100644 plugins/catalog-common/src/search/index.ts diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index ee7b419a71..9dcb2db752 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -7,6 +7,7 @@ import { BitbucketIntegration } from '@backstage/integration'; import { CatalogApi } from '@backstage/catalog-client'; +import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; import { CompoundEntityRef } from '@backstage/catalog-model'; import { ConditionalPolicyDecision } from '@backstage/plugin-permission-node'; import { Conditions } from '@backstage/plugin-permission-node'; @@ -18,7 +19,6 @@ import express from 'express'; import { GetEntitiesRequest } from '@backstage/catalog-client'; import { GithubCredentialsProvider } from '@backstage/integration'; import { GitHubIntegrationConfig } from '@backstage/integration'; -import { IndexableDocument } from '@backstage/search-common'; import { JsonObject } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { Location as Location_2 } from '@backstage/catalog-client'; @@ -248,19 +248,7 @@ export const catalogConditions: Conditions<{ >; }>; -// @public (undocumented) -export interface CatalogEntityDocument extends IndexableDocument { - // (undocumented) - componentType: string; - // (undocumented) - kind: string; - // (undocumented) - lifecycle: string; - // (undocumented) - namespace: string; - // (undocumented) - owner: string; -} +export { CatalogEntityDocument }; // @public (undocumented) export type CatalogEnvironment = { diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts index 99377b2ca0..811ac10210 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts @@ -29,21 +29,17 @@ import { UserEntity, } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; +import { DocumentCollatorFactory } from '@backstage/search-common'; import { - DocumentCollatorFactory, - IndexableDocument, -} from '@backstage/search-common'; -import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common'; + catalogEntityReadPermission, + CatalogEntityDocument, +} from '@backstage/plugin-catalog-common'; import { Readable } from 'stream'; -/** @public */ -export interface CatalogEntityDocument extends IndexableDocument { - componentType: string; - namespace: string; - kind: string; - lifecycle: string; - owner: string; -} +/** + * @deprecated import from `@backstage/plugin-catalog-common` instead + */ +export type { CatalogEntityDocument }; /** @public */ export type DefaultCatalogCollatorFactoryOptions = { diff --git a/plugins/catalog-common/api-report.md b/plugins/catalog-common/api-report.md index 57f8c3983e..8ae9571d4c 100644 --- a/plugins/catalog-common/api-report.md +++ b/plugins/catalog-common/api-report.md @@ -3,6 +3,7 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { IndexableDocument } from '@backstage/search-common'; import { Permission } from '@backstage/plugin-permission-common'; // @alpha @@ -11,6 +12,20 @@ export const catalogEntityCreatePermission: Permission; // @alpha export const catalogEntityDeletePermission: Permission; +// @public +export interface CatalogEntityDocument extends IndexableDocument { + // (undocumented) + componentType: string; + // (undocumented) + kind: string; + // (undocumented) + lifecycle: string; + // (undocumented) + namespace: string; + // (undocumented) + owner: string; +} + // @alpha export const catalogEntityReadPermission: Permission; diff --git a/plugins/catalog-common/package.json b/plugins/catalog-common/package.json index acf4ed4aaa..bc0d3750ba 100644 --- a/plugins/catalog-common/package.json +++ b/plugins/catalog-common/package.json @@ -34,7 +34,8 @@ "clean": "backstage-cli package clean" }, "dependencies": { - "@backstage/plugin-permission-common": "^0.5.1" + "@backstage/plugin-permission-common": "^0.5.1", + "@backstage/search-common": "^0.2.4" }, "devDependencies": { "@backstage/cli": "^0.14.0" diff --git a/plugins/catalog-common/src/index.ts b/plugins/catalog-common/src/index.ts index 9eddf37452..08184eb871 100644 --- a/plugins/catalog-common/src/index.ts +++ b/plugins/catalog-common/src/index.ts @@ -31,3 +31,5 @@ export { catalogLocationCreatePermission, catalogLocationDeletePermission, } from './permissions'; + +export * from './search'; diff --git a/plugins/catalog-common/src/search/CatalogEntityDocument.ts b/plugins/catalog-common/src/search/CatalogEntityDocument.ts new file mode 100644 index 0000000000..e48cde431a --- /dev/null +++ b/plugins/catalog-common/src/search/CatalogEntityDocument.ts @@ -0,0 +1,29 @@ +/* + * 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 { IndexableDocument } from '@backstage/search-common'; + +/** + * The Document format for an Entity in the Catalog for search + * + * @public + */ +export interface CatalogEntityDocument extends IndexableDocument { + componentType: string; + namespace: string; + kind: string; + lifecycle: string; + owner: string; +} diff --git a/plugins/catalog-common/src/search/index.ts b/plugins/catalog-common/src/search/index.ts new file mode 100644 index 0000000000..82e713aba0 --- /dev/null +++ b/plugins/catalog-common/src/search/index.ts @@ -0,0 +1,16 @@ +/* + * 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 type { CatalogEntityDocument } from './CatalogEntityDocument'; From ab7b6cb7b1116ea5376e997ba2bfadb272f6dc5b Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 11:13:15 +0100 Subject: [PATCH 2/7] chore: reworking exports Signed-off-by: blam --- .changeset/small-hornets-dress.md | 6 ++++++ .../src/search/DefaultCatalogCollator.ts | 11 ++++------- plugins/catalog-backend/src/search/index.ts | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changeset/small-hornets-dress.md diff --git a/.changeset/small-hornets-dress.md b/.changeset/small-hornets-dress.md new file mode 100644 index 0000000000..6d6817977d --- /dev/null +++ b/.changeset/small-hornets-dress.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend': patch +'@backstage/plugin-catalog-common': patch +--- + +Moved the `CatalogEntityDocument` to `@backstage/plugin-catalog-common` and deprecated the export from `@backstage/plugin-catalog-backend` diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index c59318d0af..a24c6d4f67 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -29,14 +29,11 @@ import { CatalogClient, GetEntitiesRequest, } from '@backstage/catalog-client'; -import { catalogEntityReadPermission } from '@backstage/plugin-catalog-common'; -import { CatalogEntityDocument } from './DefaultCatalogCollatorFactory'; +import { + catalogEntityReadPermission, + CatalogEntityDocument, +} from '@backstage/plugin-catalog-common'; -/** - * @public - * @deprecated Upgrade to a more recent `@backstage/search-backend-node` and - * use `DefaultCatalogCollatorFactory` instead. - */ export class DefaultCatalogCollator { protected discovery: PluginEndpointDiscovery; protected locationTemplate: string; diff --git a/plugins/catalog-backend/src/search/index.ts b/plugins/catalog-backend/src/search/index.ts index 93ff0b8b32..bd54e33e59 100644 --- a/plugins/catalog-backend/src/search/index.ts +++ b/plugins/catalog-backend/src/search/index.ts @@ -16,7 +16,9 @@ export { DefaultCatalogCollatorFactory } from './DefaultCatalogCollatorFactory'; export type { DefaultCatalogCollatorFactoryOptions } from './DefaultCatalogCollatorFactory'; -export type { CatalogEntityDocument } from './DefaultCatalogCollatorFactory'; + +/** @public @deprecated use the export from `plugin-catalog-common` instead */ +export type { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; /** * todo(backstage/techdocs-core): stop exporting this in a future release. From 8b3678e120b3acd105b78bd29d6d9b2f0b3a3368 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 11:28:20 +0100 Subject: [PATCH 3/7] chore: reworking the api-report Signed-off-by: blam --- plugins/catalog-backend/api-report.md | 2 +- plugins/catalog-backend/src/search/DefaultCatalogCollator.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 9dcb2db752..ad07b002ea 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -404,7 +404,7 @@ export function createRandomRefreshInterval(options: { // @public export function createRouter(options: RouterOptions): Promise; -// @public @deprecated (undocumented) +// @public export class DefaultCatalogCollator { constructor(options: { discovery: PluginEndpointDiscovery; diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index a24c6d4f67..a577147082 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -34,6 +34,10 @@ import { CatalogEntityDocument, } from '@backstage/plugin-catalog-common'; +/** + * The DefaultCatalogCollator for Search + * @public + */ export class DefaultCatalogCollator { protected discovery: PluginEndpointDiscovery; protected locationTemplate: string; From 633019509ac78b80ab2d7fcfc339857eab710d9b Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 11:38:26 +0100 Subject: [PATCH 4/7] chore: reworking some more things Signed-off-by: blam --- plugins/catalog-backend/src/search/DefaultCatalogCollator.ts | 1 + .../src/search/DefaultCatalogCollatorFactory.ts | 1 + plugins/catalog-common/api-report.md | 4 +++- plugins/catalog-common/src/search/CatalogEntityDocument.ts | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index a577147082..7700048b14 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -126,6 +126,7 @@ export class DefaultCatalogCollator { }), text: this.getDocumentText(entity), componentType: entity.spec?.type?.toString() || 'other', + type: entity.spec?.type?.toString() || 'other', namespace: entity.metadata.namespace || 'default', kind: entity.kind, lifecycle: (entity.spec?.lifecycle as string) || '', diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts index 811ac10210..ca6395b60a 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts @@ -155,6 +155,7 @@ export class DefaultCatalogCollatorFactory implements DocumentCollatorFactory { }), text: this.getDocumentText(entity), componentType: entity.spec?.type?.toString() || 'other', + type: entity.spec?.type?.toString() || 'other', namespace: entity.metadata.namespace || 'default', kind: entity.kind, lifecycle: (entity.spec?.lifecycle as string) || '', diff --git a/plugins/catalog-common/api-report.md b/plugins/catalog-common/api-report.md index 8ae9571d4c..a73cae9994 100644 --- a/plugins/catalog-common/api-report.md +++ b/plugins/catalog-common/api-report.md @@ -14,7 +14,7 @@ export const catalogEntityDeletePermission: Permission; // @public export interface CatalogEntityDocument extends IndexableDocument { - // (undocumented) + // @deprecated (undocumented) componentType: string; // (undocumented) kind: string; @@ -24,6 +24,8 @@ export interface CatalogEntityDocument extends IndexableDocument { namespace: string; // (undocumented) owner: string; + // (undocumented) + type: string; } // @alpha diff --git a/plugins/catalog-common/src/search/CatalogEntityDocument.ts b/plugins/catalog-common/src/search/CatalogEntityDocument.ts index e48cde431a..005bc79c92 100644 --- a/plugins/catalog-common/src/search/CatalogEntityDocument.ts +++ b/plugins/catalog-common/src/search/CatalogEntityDocument.ts @@ -21,7 +21,9 @@ import { IndexableDocument } from '@backstage/search-common'; * @public */ export interface CatalogEntityDocument extends IndexableDocument { + /** @deprecated use `type` as well, as `componentType` will be removed after a few releases but we dont want to break indexing */ componentType: string; + type: string; namespace: string; kind: string; lifecycle: string; From 50b09a5fffb1bfa4540014ba11fdf4c3d7609e8d Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 11:43:31 +0100 Subject: [PATCH 5/7] chore: fix Signed-off-by: blam --- plugins/catalog-backend/api-report.md | 2 +- plugins/catalog-backend/src/search/DefaultCatalogCollator.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index ad07b002ea..9dcb2db752 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -404,7 +404,7 @@ export function createRandomRefreshInterval(options: { // @public export function createRouter(options: RouterOptions): Promise; -// @public +// @public @deprecated (undocumented) export class DefaultCatalogCollator { constructor(options: { discovery: PluginEndpointDiscovery; diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index 7700048b14..ac9a33bf62 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -35,8 +35,9 @@ import { } from '@backstage/plugin-catalog-common'; /** - * The DefaultCatalogCollator for Search * @public + * @deprecated Upgrade to a more recent `@backstage/search-backend-node` and + * use `DefaultCatalogCollatorFactory` instead. */ export class DefaultCatalogCollator { protected discovery: PluginEndpointDiscovery; From 2255bfd1c40e155184646d62ebc56673ba8269f4 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 3 Mar 2022 13:37:33 +0100 Subject: [PATCH 6/7] Apply suggestions from code review Signed-off-by: Patrik Oldsberg --- .changeset/small-hornets-dress.md | 6 +++++- plugins/catalog-common/src/search/CatalogEntityDocument.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.changeset/small-hornets-dress.md b/.changeset/small-hornets-dress.md index 6d6817977d..2bb73b1ba3 100644 --- a/.changeset/small-hornets-dress.md +++ b/.changeset/small-hornets-dress.md @@ -3,4 +3,8 @@ '@backstage/plugin-catalog-common': patch --- -Moved the `CatalogEntityDocument` to `@backstage/plugin-catalog-common` and deprecated the export from `@backstage/plugin-catalog-backend` +Moved the `CatalogEntityDocument` to `@backstage/plugin-catalog-common` and deprecated the export from `@backstage/plugin-catalog-backend`. + +A new `type` field has also been added to `CatalogEntityDocument` as a replacement for `componentType`, which is now deprecated. Both fields are still present and should be set to the same value in order to avoid issues with indexing. + +Any search customizations need to be updated to use this new `type` field instead, including any custom frontend filters, custom frontend result components, custom search decorators, or non-default Catalog collator implementations. diff --git a/plugins/catalog-common/src/search/CatalogEntityDocument.ts b/plugins/catalog-common/src/search/CatalogEntityDocument.ts index 005bc79c92..834dde2568 100644 --- a/plugins/catalog-common/src/search/CatalogEntityDocument.ts +++ b/plugins/catalog-common/src/search/CatalogEntityDocument.ts @@ -21,7 +21,7 @@ import { IndexableDocument } from '@backstage/search-common'; * @public */ export interface CatalogEntityDocument extends IndexableDocument { - /** @deprecated use `type` as well, as `componentType` will be removed after a few releases but we dont want to break indexing */ + /** @deprecated `componentType` is being renamed to `type`. During the transition both of these fields should be set to the same value, in order to avoid issues with indexing. */ componentType: string; type: string; namespace: string; From 48997f9bcffb2c5c07172eb6b594997a446dec25 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Mar 2022 14:00:23 +0100 Subject: [PATCH 7/7] fix up the exports to keep the DEPRECATION Signed-off-by: blam --- .changeset/small-hornets-dress.md | 2 +- plugins/catalog-backend/api-report.md | 7 ++++--- .../src/search/DefaultCatalogCollatorFactory.ts | 5 ----- plugins/catalog-backend/src/search/index.ts | 9 +++++++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.changeset/small-hornets-dress.md b/.changeset/small-hornets-dress.md index 2bb73b1ba3..474c3011bd 100644 --- a/.changeset/small-hornets-dress.md +++ b/.changeset/small-hornets-dress.md @@ -3,7 +3,7 @@ '@backstage/plugin-catalog-common': patch --- -Moved the `CatalogEntityDocument` to `@backstage/plugin-catalog-common` and deprecated the export from `@backstage/plugin-catalog-backend`. +**DEPRECATION**: Moved the `CatalogEntityDocument` to `@backstage/plugin-catalog-common` and deprecated the export from `@backstage/plugin-catalog-backend`. A new `type` field has also been added to `CatalogEntityDocument` as a replacement for `componentType`, which is now deprecated. Both fields are still present and should be set to the same value in order to avoid issues with indexing. diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 9dcb2db752..dfe9a8943e 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -7,7 +7,7 @@ import { BitbucketIntegration } from '@backstage/integration'; import { CatalogApi } from '@backstage/catalog-client'; -import { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; +import { CatalogEntityDocument as CatalogEntityDocument_2 } from '@backstage/plugin-catalog-common'; import { CompoundEntityRef } from '@backstage/catalog-model'; import { ConditionalPolicyDecision } from '@backstage/plugin-permission-node'; import { Conditions } from '@backstage/plugin-permission-node'; @@ -248,7 +248,8 @@ export const catalogConditions: Conditions<{ >; }>; -export { CatalogEntityDocument }; +// @public @deprecated (undocumented) +export type CatalogEntityDocument = CatalogEntityDocument_2; // @public (undocumented) export type CatalogEnvironment = { @@ -423,7 +424,7 @@ export class DefaultCatalogCollator { // (undocumented) protected discovery: PluginEndpointDiscovery; // (undocumented) - execute(): Promise; + execute(): Promise; // (undocumented) protected filter?: GetEntitiesRequest['filter']; // (undocumented) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts index ca6395b60a..440a8c8ebb 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollatorFactory.ts @@ -36,11 +36,6 @@ import { } from '@backstage/plugin-catalog-common'; import { Readable } from 'stream'; -/** - * @deprecated import from `@backstage/plugin-catalog-common` instead - */ -export type { CatalogEntityDocument }; - /** @public */ export type DefaultCatalogCollatorFactoryOptions = { discovery: PluginEndpointDiscovery; diff --git a/plugins/catalog-backend/src/search/index.ts b/plugins/catalog-backend/src/search/index.ts index bd54e33e59..eb5b1e7c22 100644 --- a/plugins/catalog-backend/src/search/index.ts +++ b/plugins/catalog-backend/src/search/index.ts @@ -17,8 +17,13 @@ export { DefaultCatalogCollatorFactory } from './DefaultCatalogCollatorFactory'; export type { DefaultCatalogCollatorFactoryOptions } from './DefaultCatalogCollatorFactory'; -/** @public @deprecated use the export from `plugin-catalog-common` instead */ -export type { CatalogEntityDocument } from '@backstage/plugin-catalog-common'; +import { CatalogEntityDocument as CatalogEntityDocumentType } from '@backstage/plugin-catalog-common'; + +/** + * @deprecated import from `@backstage/plugin-catalog-common` instead + * @public + */ +export type CatalogEntityDocument = CatalogEntityDocumentType; /** * todo(backstage/techdocs-core): stop exporting this in a future release.