From c0a287a79b9f802d754e3570526ae4df8e1921d2 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Wed, 15 May 2024 16:45:55 +0200 Subject: [PATCH 1/4] refactor: extract `isDatabaseConflictError` to plugin api Signed-off-by: Camila Belo --- packages/backend-common/api-report.md | 5 +++-- packages/backend-common/src/database/index.ts | 1 - packages/backend-common/src/deprecated/index.ts | 14 +++++++++++--- packages/backend-plugin-api/api-report.md | 3 +++ .../backend-plugin-api/src/services/index.ts | 1 + .../src/services/utilities/database.ts} | 0 .../src/services/utilities/index.ts | 17 +++++++++++++++++ .../src/database/DefaultProviderDatabase.ts | 6 ++++-- .../catalog-backend/src/database/conversion.ts | 2 +- .../refreshState/insertUnprocessedEntity.ts | 6 ++++-- 10 files changed, 44 insertions(+), 11 deletions(-) rename packages/{backend-common/src/database/util.ts => backend-plugin-api/src/services/utilities/database.ts} (100%) create mode 100644 packages/backend-plugin-api/src/services/utilities/index.ts diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index 42df32dc1d..0d1655be28 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -35,6 +35,7 @@ import { HostDiscovery as HostDiscovery_2 } from '@backstage/backend-app-api'; import { HttpAuthService } from '@backstage/backend-plugin-api'; import { IdentityService } from '@backstage/backend-plugin-api'; import { isChildPath as isChildPath_2 } from '@backstage/backend-plugin-api'; +import { isDatabaseConflictError as isDatabaseConflictError_2 } from '@backstage/backend-plugin-api'; import { KubeConfig } from '@kubernetes/client-node'; import { LifecycleService } from '@backstage/backend-plugin-api'; import { LoadConfigOptionsRemote } from '@backstage/config-loader'; @@ -538,8 +539,8 @@ export const HostDiscovery: typeof HostDiscovery_2; // @public @deprecated (undocumented) export const isChildPath: typeof isChildPath_2; -// @public -export function isDatabaseConflictError(e: unknown): boolean; +// @public @deprecated (undocumented) +export const isDatabaseConflictError: typeof isDatabaseConflictError_2; // @public export class KubernetesContainerRunner implements ContainerRunner { diff --git a/packages/backend-common/src/database/index.ts b/packages/backend-common/src/database/index.ts index a0a61ccdd0..77d75653b8 100644 --- a/packages/backend-common/src/database/index.ts +++ b/packages/backend-common/src/database/index.ts @@ -21,4 +21,3 @@ export type { } from './DatabaseManager'; export type { PluginDatabaseManager } from './types'; -export { isDatabaseConflictError } from './util'; diff --git a/packages/backend-common/src/deprecated/index.ts b/packages/backend-common/src/deprecated/index.ts index 708e358bfc..d9ca795c3a 100644 --- a/packages/backend-common/src/deprecated/index.ts +++ b/packages/backend-common/src/deprecated/index.ts @@ -17,6 +17,7 @@ export * from './scm'; import { + isDatabaseConflictError as _isDatabaseConflictError, resolvePackagePath as _resolvePackagePath, resolveSafeChildPath as _resolveSafeChildPath, isChildPath as _isChildPath, @@ -24,21 +25,28 @@ import { /** * @public - * @deprecated This type is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. + * @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. + * Please use the `isDatabaseConflictError` function from the `@backstage/backend-plugin-api` package instead. + */ +export const isDatabaseConflictError = _isDatabaseConflictError; + +/** + * @public + * @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. * Please use the `resolvePackagePath` function from the `@backstage/backend-plugin-api` package instead. */ export const resolvePackagePath = _resolvePackagePath; /** * @public - * @deprecated This type is deprecated and will be removed in a future release, see + * @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. * Please use the `resolveSafeChildPath` function from the `@backstage/backend-plugin-api` package instead. */ export const resolveSafeChildPath = _resolveSafeChildPath; /** * @public - * @deprecated This type is deprecated and will be removed in a future release, see + * @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493. * Please use the `isChildPath` function from the `@backstage/cli-common` package instead. */ export const isChildPath = _isChildPath; diff --git a/packages/backend-plugin-api/api-report.md b/packages/backend-plugin-api/api-report.md index 932ccc74ab..860907c12c 100644 --- a/packages/backend-plugin-api/api-report.md +++ b/packages/backend-plugin-api/api-report.md @@ -354,6 +354,9 @@ export interface IdentityService extends IdentityApi {} export { isChildPath }; +// @public +export function isDatabaseConflictError(e: unknown): boolean; + // @public (undocumented) export interface LifecycleService { addShutdownHook( diff --git a/packages/backend-plugin-api/src/services/index.ts b/packages/backend-plugin-api/src/services/index.ts index dd24127b88..01d3da444b 100644 --- a/packages/backend-plugin-api/src/services/index.ts +++ b/packages/backend-plugin-api/src/services/index.ts @@ -16,3 +16,4 @@ export * from './definitions'; export * from './system'; +export * from './utilities'; diff --git a/packages/backend-common/src/database/util.ts b/packages/backend-plugin-api/src/services/utilities/database.ts similarity index 100% rename from packages/backend-common/src/database/util.ts rename to packages/backend-plugin-api/src/services/utilities/database.ts diff --git a/packages/backend-plugin-api/src/services/utilities/index.ts b/packages/backend-plugin-api/src/services/utilities/index.ts new file mode 100644 index 0000000000..0eec4f3e84 --- /dev/null +++ b/packages/backend-plugin-api/src/services/utilities/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2024 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 { isDatabaseConflictError } from './database'; diff --git a/plugins/catalog-backend/src/database/DefaultProviderDatabase.ts b/plugins/catalog-backend/src/database/DefaultProviderDatabase.ts index 5b016438e3..94026fbfa0 100644 --- a/plugins/catalog-backend/src/database/DefaultProviderDatabase.ts +++ b/plugins/catalog-backend/src/database/DefaultProviderDatabase.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { isDatabaseConflictError } from '@backstage/backend-common'; import { stringifyEntityRef } from '@backstage/catalog-model'; import { DeferredEntity } from '@backstage/plugin-catalog-node'; import { Knex } from 'knex'; @@ -34,7 +33,10 @@ import { Transaction, } from './types'; import { generateStableHash } from './util'; -import { LoggerService } from '@backstage/backend-plugin-api'; +import { + LoggerService, + isDatabaseConflictError, +} from '@backstage/backend-plugin-api'; // The number of items that are sent per batch to the database layer, when // doing .batchInsert calls to knex. This needs to be low enough to not cause diff --git a/plugins/catalog-backend/src/database/conversion.ts b/plugins/catalog-backend/src/database/conversion.ts index 827ae9b367..32de149572 100644 --- a/plugins/catalog-backend/src/database/conversion.ts +++ b/plugins/catalog-backend/src/database/conversion.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { isDatabaseConflictError } from '@backstage/backend-common'; +import { isDatabaseConflictError } from '@backstage/backend-plugin-api'; import { ConflictError, InputError } from '@backstage/errors'; import { DateTime } from 'luxon'; diff --git a/plugins/catalog-backend/src/database/operations/refreshState/insertUnprocessedEntity.ts b/plugins/catalog-backend/src/database/operations/refreshState/insertUnprocessedEntity.ts index d6309c27fc..195dbe1f2c 100644 --- a/plugins/catalog-backend/src/database/operations/refreshState/insertUnprocessedEntity.ts +++ b/plugins/catalog-backend/src/database/operations/refreshState/insertUnprocessedEntity.ts @@ -18,8 +18,10 @@ import { Entity, stringifyEntityRef } from '@backstage/catalog-model'; import { Knex } from 'knex'; import { DbRefreshStateRow } from '../../tables'; import { v4 as uuid } from 'uuid'; -import { isDatabaseConflictError } from '@backstage/backend-common'; -import { LoggerService } from '@backstage/backend-plugin-api'; +import { + LoggerService, + isDatabaseConflictError, +} from '@backstage/backend-plugin-api'; /** * Attempts to insert a new refresh state row for the given entity, returning From 17791889eaec70f7228dda607b13f839ccfdf059 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Thu, 16 May 2024 09:27:14 +0200 Subject: [PATCH 2/4] docs: add changeset files Signed-off-by: Camila Belo --- .changeset/eighty-kings-dress.md | 5 +++++ .changeset/wet-crabs-guess.md | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 .changeset/eighty-kings-dress.md create mode 100644 .changeset/wet-crabs-guess.md diff --git a/.changeset/eighty-kings-dress.md b/.changeset/eighty-kings-dress.md new file mode 100644 index 0000000000..f83c2ab2b2 --- /dev/null +++ b/.changeset/eighty-kings-dress.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-common': patch +--- + +In preparation to the new backend system stable release, the `isDatabaseConnectionError` helper have been moved to the `backend-plugin-api` package and deprecated from `backend-common`. diff --git a/.changeset/wet-crabs-guess.md b/.changeset/wet-crabs-guess.md new file mode 100644 index 0000000000..e15e56e77d --- /dev/null +++ b/.changeset/wet-crabs-guess.md @@ -0,0 +1,6 @@ +--- +'@backstage/backend-plugin-api': patch +'@backstage/plugin-catalog-backend': patch +--- + +Start using the `isDatabaseConflictError` helper from the `backend-plugin-api` package in order to avoid dependency with the soon to deprecate `backend-common` package. From c1745b609f3c0bb7b04879e0a69146671e13de64 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Fri, 17 May 2024 14:25:51 +0200 Subject: [PATCH 3/4] Update .changeset/wet-crabs-guess.md Co-authored-by: Patrik Oldsberg Signed-off-by: Camila Belo --- .changeset/wet-crabs-guess.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wet-crabs-guess.md b/.changeset/wet-crabs-guess.md index e15e56e77d..c8a9282a47 100644 --- a/.changeset/wet-crabs-guess.md +++ b/.changeset/wet-crabs-guess.md @@ -3,4 +3,4 @@ '@backstage/plugin-catalog-backend': patch --- -Start using the `isDatabaseConflictError` helper from the `backend-plugin-api` package in order to avoid dependency with the soon to deprecate `backend-common` package. +Start using the `isDatabaseConflictError` helper from the `@backstage/backend-plugin-api` package in order to avoid dependency with the soon to deprecate `@backstage/backend-common` package. From c09d8df635cff2db4b2e195d5193f0f756cfb0ae Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Fri, 17 May 2024 14:26:01 +0200 Subject: [PATCH 4/4] Update .changeset/eighty-kings-dress.md Co-authored-by: Patrik Oldsberg Signed-off-by: Camila Belo --- .changeset/eighty-kings-dress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eighty-kings-dress.md b/.changeset/eighty-kings-dress.md index f83c2ab2b2..52aab627ab 100644 --- a/.changeset/eighty-kings-dress.md +++ b/.changeset/eighty-kings-dress.md @@ -2,4 +2,4 @@ '@backstage/backend-common': patch --- -In preparation to the new backend system stable release, the `isDatabaseConnectionError` helper have been moved to the `backend-plugin-api` package and deprecated from `backend-common`. +In preparation to the new backend system stable release, the `isDatabaseConflictError` helper have been moved to the `@backstage/backend-plugin-api` package and deprecated from `@backstage/backend-common`.