refactor: deprecate cache implementation and types

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2024-06-13 09:53:39 +02:00
parent b68439587c
commit e171620164
20 changed files with 89 additions and 121 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
Move `cache` implementation and types to the `@backstage/backend-defaults` package.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Remove dependency with `@backstage/backend-commons` package.
+1
View File
@@ -92,6 +92,7 @@
"jest-haste-map@^29.7.0": "patch:jest-haste-map@npm%3A29.7.0#./.yarn/patches/jest-haste-map-npm-29.7.0-e3be419eff.patch"
},
"dependencies": {
"@backstage/backend-defaults": "workspace:^",
"@backstage/errors": "workspace:^",
"@manypkg/get-packages": "^1.1.3",
"@useoptic/optic": "^0.50.10"
+10 -24
View File
@@ -17,9 +17,11 @@ import { BackendFeature } from '@backstage/backend-plugin-api';
import { BitbucketCloudIntegration } from '@backstage/integration';
import { BitbucketIntegration } from '@backstage/integration';
import { BitbucketServerIntegration } from '@backstage/integration';
import { CacheManager as CacheManager_2 } from '@backstage/backend-defaults/cache';
import { CacheManagerOptions as CacheManagerOptions_2 } from '@backstage/backend-defaults/cache';
import { CacheService } from '@backstage/backend-plugin-api';
import { CacheServiceOptions } from '@backstage/backend-plugin-api';
import type { CacheServiceSetOptions } from '@backstage/backend-plugin-api';
import { CacheServiceSetOptions } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import cors from 'cors';
import { DiscoveryService } from '@backstage/backend-plugin-api';
@@ -43,6 +45,7 @@ import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { MergeResult } from 'isomorphic-git';
import { PermissionsService } from '@backstage/backend-plugin-api';
import { PluginCacheManager as PluginCacheManager_2 } from '@backstage/backend-defaults/cache';
import { DatabaseService as PluginDatabaseManager } from '@backstage/backend-plugin-api';
import { PluginMetadataService } from '@backstage/backend-plugin-api';
import { PushResult } from 'isomorphic-git';
@@ -119,25 +122,11 @@ export type CacheClientOptions = CacheServiceOptions;
// @public @deprecated (undocumented)
export type CacheClientSetOptions = CacheServiceSetOptions;
// @public
export class CacheManager {
forPlugin(pluginId: string): {
getClient(options?: CacheServiceOptions): CacheService;
};
static fromConfig(
config: Config,
options?: {
logger?: LoggerService;
onError?: (err: Error) => void;
},
): CacheManager;
}
// @public @deprecated (undocumented)
export const CacheManager: typeof CacheManager_2;
// @public
export type CacheManagerOptions = {
logger?: LoggerService;
onError?: (err: Error) => void;
};
// @public @deprecated (undocumented)
export type CacheManagerOptions = CacheManagerOptions_2;
// @public
export function cacheToPluginCacheManager(cache: CacheService): {
@@ -471,11 +460,8 @@ export function makeLegacyPlugin<
// @public @deprecated
export function notFoundHandler(): RequestHandler;
// @public (undocumented)
export interface PluginCacheManager {
// (undocumented)
getClient(options?: CacheServiceOptions): CacheService;
}
// @public @deprecated (undocumented)
export type PluginCacheManager = PluginCacheManager_2;
export { PluginDatabaseManager };
+1
View File
@@ -59,6 +59,7 @@
"@aws-sdk/client-s3": "^3.350.0",
"@aws-sdk/credential-providers": "^3.350.0",
"@aws-sdk/types": "^3.347.0",
"@backstage/backend-defaults": "workspace:^",
"@backstage/backend-dev-utils": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/cli-common": "workspace:^",
-2
View File
@@ -15,5 +15,3 @@
*/
export { cacheToPluginCacheManager } from './cacheToPluginCacheManager';
export * from './reexport';
export * from './types';
-29
View File
@@ -1,29 +0,0 @@
/*
* 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.
*/
/*
* NOTE(freben): This is a temporary hack. We use cross-package imports so that
* we do not have to maintain double implementations for the time being, until
* backend-common is properly removed.
*/
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
export { CacheManager } from '../../../backend-defaults/src/entrypoints/cache/CacheManager';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
export {
type PluginCacheManager,
type CacheManagerOptions,
} from '../../../backend-defaults/src/entrypoints/cache/types';
-39
View File
@@ -1,39 +0,0 @@
/*
* Copyright 2020 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 type {
CacheService,
CacheServiceSetOptions,
CacheServiceOptions,
} from '@backstage/backend-plugin-api';
/**
* @public
* @deprecated Use `CacheService` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClient = CacheService;
/**
* @public
* @deprecated Use `CacheServiceSetOptions` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClientSetOptions = CacheServiceSetOptions;
/**
* @public
* @deprecated Use `CacheServiceOptions` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClientOptions = CacheServiceOptions;
@@ -17,12 +17,57 @@
export * from './scm';
import {
CacheManager as _CacheManager,
CacheManagerOptions as _CacheManagerOptions,
PluginCacheManager as _PluginCacheManager,
} from '@backstage/backend-defaults/cache';
import {
CacheService,
CacheServiceOptions,
CacheServiceSetOptions,
isDatabaseConflictError as _isDatabaseConflictError,
resolvePackagePath as _resolvePackagePath,
resolveSafeChildPath as _resolveSafeChildPath,
isChildPath as _isChildPath,
} from '@backstage/backend-plugin-api';
/**
* @public
* @deprecated Use `CacheManager` from the `@backstage/backend-defaults` package instead
*/
export const CacheManager = _CacheManager;
/**
* @public
* @deprecated Use `CacheManagerOptions` from the `@backstage/backend-defaults` package instead
*/
export type CacheManagerOptions = _CacheManagerOptions;
/**
* @public
* @deprecated Use `PluginCacheManager` from the `@backstage/backend-defaults` package instead
*/
export type PluginCacheManager = _PluginCacheManager;
/**
* @public
* @deprecated Use `CacheService` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClient = CacheService;
/**
* @public
* @deprecated Use `CacheServiceSetOptions` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClientSetOptions = CacheServiceSetOptions;
/**
* @public
* @deprecated Use `CacheServiceOptions` from the `@backstage/backend-plugin-api` package instead
*/
export type CacheClientOptions = CacheServiceOptions;
/**
* @public
* @deprecated This function is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493.
@@ -7,7 +7,6 @@ import { Config } from '@backstage/config';
import { DatabaseService } from '@backstage/backend-plugin-api';
import { LifecycleService } from '@backstage/backend-plugin-api';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { PluginMetadataService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
@@ -34,7 +33,7 @@ export type DatabaseManagerOptions = {
// @public (undocumented)
export const databaseServiceFactory: () => ServiceFactory<
PluginDatabaseManager,
DatabaseService,
'plugin'
>;
-1
View File
@@ -88,7 +88,6 @@
"@aws-sdk/credential-providers": "^3.350.0",
"@aws-sdk/types": "^3.347.0",
"@backstage/backend-app-api": "workspace:^",
"@backstage/backend-common": "workspace:^",
"@backstage/backend-dev-utils": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { DatabaseManager } from '@backstage/backend-common';
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
import { DatabaseManager } from '../database';
/**
* @public
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { BackendLifecycleImpl } from './rootLifecycleServiceFactory';
import { mockServices } from '@backstage/backend-test-utils';
describe('lifecycleService', () => {
it('should execute registered shutdown hook', async () => {
const service = new BackendLifecycleImpl(getVoidLogger());
const service = new BackendLifecycleImpl(mockServices.logger.mock());
const hook = jest.fn();
service.addShutdownHook(() => hook());
// should not execute the hook more than once.
@@ -30,7 +30,7 @@ describe('lifecycleService', () => {
});
it('should not throw errors', async () => {
const service = new BackendLifecycleImpl(getVoidLogger());
const service = new BackendLifecycleImpl(mockServices.logger.mock());
service.addShutdownHook(() => {
throw new Error('oh no');
});
@@ -38,7 +38,7 @@ describe('lifecycleService', () => {
});
it('should not throw async errors', async () => {
const service = new BackendLifecycleImpl(getVoidLogger());
const service = new BackendLifecycleImpl(mockServices.logger.mock());
service.addShutdownHook(async () => {
throw new Error('oh no');
});
@@ -46,7 +46,7 @@ describe('lifecycleService', () => {
});
it('should reject hooks after trigger', async () => {
const service = new BackendLifecycleImpl(getVoidLogger());
const service = new BackendLifecycleImpl(mockServices.logger.mock());
await service.startup();
expect(() => {
service.addStartupHook(() => {});
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { Knex } from 'knex';
import { DB_MIGRATIONS_TABLE } from './tables';
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { LocalTaskWorker } from './LocalTaskWorker';
import { mockServices } from '@backstage/backend-test-utils';
describe('LocalTaskWorker', () => {
const logger = getVoidLogger();
const logger = mockServices.logger.mock();
it('runs the happy path (with iso duration) and handles cancellation', async () => {
const fn = jest.fn();
@@ -14,8 +14,11 @@
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils';
import {
TestDatabaseId,
TestDatabases,
mockServices,
} from '@backstage/backend-test-utils';
import { ConflictError, NotFoundError } from '@backstage/errors';
import { Duration } from 'luxon';
import { migrateBackendTasks } from '../database/migrateBackendTasks';
@@ -53,7 +56,7 @@ describe('PluginTaskManagerImpl', () => {
await migrateBackendTasks(knex);
const manager = new PluginTaskSchedulerImpl(
async () => knex,
getVoidLogger(),
mockServices.logger.mock(),
);
return { knex, manager };
}
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { TestDatabases } from '@backstage/backend-test-utils';
import { TestDatabases, mockServices } from '@backstage/backend-test-utils';
import { Knex } from 'knex';
import { Duration } from 'luxon';
import waitForExpect from 'wait-for-expect';
@@ -36,7 +35,7 @@ const getTask = async (knex: Knex): Promise<DbTasksRow> => {
};
describe('PluginTaskSchedulerJanitor', () => {
const logger = getVoidLogger();
const logger = mockServices.logger.mock();
const databases = TestDatabases.create({
ids: [
/* 'MYSQL_8' not supported yet */
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import { getVoidLogger } from '@backstage/backend-common';
import { TestDatabases } from '@backstage/backend-test-utils';
import { TestDatabases, mockServices } from '@backstage/backend-test-utils';
import { DateTime, Duration } from 'luxon';
import waitForExpect from 'wait-for-expect';
import { migrateBackendTasks } from '../database/migrateBackendTasks';
@@ -27,7 +26,7 @@ import { TaskSettingsV2 } from './types';
jest.setTimeout(60_000);
describe('TaskWorker', () => {
const logger = getVoidLogger();
const logger = mockServices.logger.mock();
const databases = TestDatabases.create();
const testScopedSignal = createTestScopedSignal();
-5
View File
@@ -20,9 +20,4 @@
* @packageDocumentation
*/
// This import is here as a workaround for a cyclic dependency bug where
// backend-common must be loaded before backend-app-api
// TODO(Rugvip): Remove this once backend-common is no longer used by backend-app-api
import '@backstage/backend-common';
export { createBackend } from './CreateBackend';
+2 -1
View File
@@ -3518,6 +3518,7 @@ __metadata:
"@aws-sdk/credential-providers": ^3.350.0
"@aws-sdk/types": ^3.347.0
"@aws-sdk/util-stream-node": ^3.350.0
"@backstage/backend-defaults": "workspace:^"
"@backstage/backend-dev-utils": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
@@ -3605,7 +3606,6 @@ __metadata:
"@aws-sdk/types": ^3.347.0
"@aws-sdk/util-stream-node": ^3.350.0
"@backstage/backend-app-api": "workspace:^"
"@backstage/backend-common": "workspace:^"
"@backstage/backend-dev-utils": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
@@ -39568,6 +39568,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "root@workspace:."
dependencies:
"@backstage/backend-defaults": "workspace:^"
"@backstage/cli": "workspace:*"
"@backstage/codemods": "workspace:*"
"@backstage/create-app": "workspace:*"