From b5bc997fa6bef51811c0e37031ecbe67ecb2c164 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Sun, 16 Jun 2024 08:56:49 +0200 Subject: [PATCH] refactor: remove inline cache types Signed-off-by: Camila Belo --- .changeset/late-badgers-rest.md | 5 ++++ packages/backend-defaults/api-report-cache.md | 9 ++----- .../src/entrypoints/cache/CacheManager.ts | 27 +++---------------- 3 files changed, 10 insertions(+), 31 deletions(-) create mode 100644 .changeset/late-badgers-rest.md diff --git a/.changeset/late-badgers-rest.md b/.changeset/late-badgers-rest.md new file mode 100644 index 0000000000..51d37fb45a --- /dev/null +++ b/.changeset/late-badgers-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-defaults': patch +--- + +Refactor cache manager inline types. diff --git a/packages/backend-defaults/api-report-cache.md b/packages/backend-defaults/api-report-cache.md index 2cd2f3efc9..c41d553ac8 100644 --- a/packages/backend-defaults/api-report-cache.md +++ b/packages/backend-defaults/api-report-cache.md @@ -11,15 +11,10 @@ import { ServiceFactory } from '@backstage/backend-plugin-api'; // @public export class CacheManager { - forPlugin(pluginId: string): { - getClient(options?: CacheServiceOptions): CacheService; - }; + forPlugin(pluginId: string): PluginCacheManager; static fromConfig( config: Config, - options?: { - logger?: LoggerService; - onError?: (err: Error) => void; - }, + options?: CacheManagerOptions, ): CacheManager; } diff --git a/packages/backend-defaults/src/entrypoints/cache/CacheManager.ts b/packages/backend-defaults/src/entrypoints/cache/CacheManager.ts index 70f952ea46..89fabfe977 100644 --- a/packages/backend-defaults/src/entrypoints/cache/CacheManager.ts +++ b/packages/backend-defaults/src/entrypoints/cache/CacheManager.ts @@ -15,24 +15,16 @@ */ import { - CacheService, CacheServiceOptions, LoggerService, } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import Keyv from 'keyv'; import { DefaultCacheClient } from './CacheClient'; -import { CacheManagerOptions } from './types'; +import { CacheManagerOptions, PluginCacheManager } from './types'; type StoreFactory = (pluginId: string, defaultTtl: number | undefined) => Keyv; -/* - * TODO(freben): This class intentionally inlines the CacheManagerOptions and - * PluginCacheManager types, to not break the api reports in backend-common - * which re-exports it. When backend-common is deprecated, we can stop inlining - * those types. - */ - /** * Implements a Cache Manager which will automatically create new cache clients * for plugins when requested. All requested cache clients are created with the @@ -66,18 +58,7 @@ export class CacheManager { */ static fromConfig( config: Config, - options: { - /** - * An optional logger for use by the PluginCacheManager. - */ - logger?: LoggerService; - - /** - * An optional handler for connection errors emitted from the underlying data - * store. - */ - onError?: (err: Error) => void; - } = {}, + options: CacheManagerOptions = {}, ): CacheManager { // If no `backend.cache` config is provided, instantiate the CacheManager // with an in-memory cache client. @@ -126,9 +107,7 @@ export class CacheManager { * @param pluginId - The plugin that the cache manager should be created for. * Plugin names should be unique. */ - forPlugin(pluginId: string): { - getClient(options?: CacheServiceOptions): CacheService; - } { + forPlugin(pluginId: string): PluginCacheManager { return { getClient: (defaultOptions = {}) => { const clientFactory = (options: CacheServiceOptions) => {