From 03ae33c064aa194b45b7ba5c6a756cb7438bd633 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 9 May 2021 18:08:57 +0200 Subject: [PATCH] Prettier Signed-off-by: Eric Peterson --- packages/backend-common/src/cache/CacheClient.ts | 9 ++++++--- .../src/cache/CacheManager.test.ts | 16 ++++++++++------ .../backend-common/src/cache/CacheManager.ts | 15 +++++++++++---- packages/backend-common/src/cache/NoStore.ts | 2 -- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/backend-common/src/cache/CacheClient.ts b/packages/backend-common/src/cache/CacheClient.ts index 943de055ae..a2c048c265 100644 --- a/packages/backend-common/src/cache/CacheClient.ts +++ b/packages/backend-common/src/cache/CacheClient.ts @@ -46,7 +46,11 @@ export interface CacheClient { * optional TTL may also be provided, otherwise it defaults to the TTL that * was provided when the client was instantiated. */ - set(key: string, value: JsonValue, options?: CacheSetOptions): Promise; + set( + key: string, + value: JsonValue, + options?: CacheSetOptions, + ): Promise; /** * Removes the given key from the cache store. Resolves true if the key @@ -77,7 +81,7 @@ export class DefaultCacheClient implements CacheClient { opts: CacheSetOptions = {}, ): Promise { const k = this.getNormalizedKey(key); - return await this.client.set(k, value, opts.ttl) + return await this.client.set(k, value, opts.ttl); } async delete(key: string): Promise { @@ -99,5 +103,4 @@ export class DefaultCacheClient implements CacheClient { return createHash('md5').update(candidateKey).digest('base64'); } - } diff --git a/packages/backend-common/src/cache/CacheManager.test.ts b/packages/backend-common/src/cache/CacheManager.test.ts index 153ccfd7ac..ece4687ee6 100644 --- a/packages/backend-common/src/cache/CacheManager.test.ts +++ b/packages/backend-common/src/cache/CacheManager.test.ts @@ -53,7 +53,9 @@ describe('CacheManager', () => { CacheManager.fromConfig(config); expect(getOptionalString.mock.calls[0][0]).toEqual('backend.cache.store'); - expect(getOptionalString.mock.calls[1][0]).toEqual('backend.cache.connection'); + expect(getOptionalString.mock.calls[1][0]).toEqual( + 'backend.cache.connection', + ); }); it('does not require the backend.cache key', () => { @@ -92,7 +94,7 @@ describe('CacheManager', () => { manager.forPlugin(plugin2Id).getClient({ defaultTtl: expectedTtl }); const client = DefaultCacheClient as jest.Mock; - const cache = Keyv as unknown as jest.Mock; + const cache = (Keyv as unknown) as jest.Mock; expect(cache).toHaveBeenCalledTimes(2); expect(client).toHaveBeenCalledTimes(2); @@ -112,7 +114,7 @@ describe('CacheManager', () => { const expectedNamespace = 'test-plugin'; manager.forPlugin(expectedNamespace).getClient(); - const cache = Keyv as unknown as jest.Mock; + const cache = (Keyv as unknown) as jest.Mock; const mockCalls = cache.mock.calls.splice(-1); const callArgs = mockCalls[0]; expect(callArgs[0].store).toBeInstanceOf(NoStore); @@ -122,9 +124,11 @@ describe('CacheManager', () => { const manager = CacheManager.fromConfig(defaultConfig()); const expectedTtl = 3600; const expectedNamespace = 'test-plugin'; - manager.forPlugin(expectedNamespace).getClient({ defaultTtl: expectedTtl }); + manager + .forPlugin(expectedNamespace) + .getClient({ defaultTtl: expectedTtl }); - const cache = Keyv as unknown as jest.Mock; + const cache = (Keyv as unknown) as jest.Mock; const mockCalls = cache.mock.calls.splice(-1); const callArgs = mockCalls[0]; expect(callArgs[0]).toMatchObject({ @@ -148,7 +152,7 @@ describe('CacheManager', () => { const expectedTtl = 3600; manager.forPlugin('test').getClient({ defaultTtl: expectedTtl }); - const cache = Keyv as unknown as jest.Mock; + const cache = (Keyv as unknown) as jest.Mock; const mockCacheCalls = cache.mock.calls.splice(-1); expect(mockCacheCalls[0][0]).toMatchObject({ ttl: expectedTtl, diff --git a/packages/backend-common/src/cache/CacheManager.ts b/packages/backend-common/src/cache/CacheManager.ts index 967ff4224b..fbd7e3ba0a 100644 --- a/packages/backend-common/src/cache/CacheManager.ts +++ b/packages/backend-common/src/cache/CacheManager.ts @@ -51,7 +51,8 @@ export class CacheManager { // If no `backend.cache` config is provided, instantiate the CacheManager // with a "NoStore" cache client. const store = config.getOptionalString('backend.cache.store') || 'none'; - const connectionString = config.getOptionalString('backend.cache.connection') || ''; + const connectionString = + config.getOptionalString('backend.cache.connection') || ''; return new CacheManager(store, connectionString); } @@ -83,7 +84,10 @@ export class CacheManager { return this.storeFactories[this.store].call(this, pluginId, ttl); } - private getMemcacheClient(pluginId: string, defaultTtl: number | undefined): Keyv { + private getMemcacheClient( + pluginId: string, + defaultTtl: number | undefined, + ): Keyv { return new Keyv({ namespace: pluginId, ttl: defaultTtl, @@ -91,7 +95,10 @@ export class CacheManager { }); } - private getMemoryClient(pluginId: string, defaultTtl: number | undefined): Keyv { + private getMemoryClient( + pluginId: string, + defaultTtl: number | undefined, + ): Keyv { return new Keyv({ namespace: pluginId, ttl: defaultTtl, @@ -102,6 +109,6 @@ export class CacheManager { return new Keyv({ namespace: pluginId, store: new NoStore(), - }) + }); } } diff --git a/packages/backend-common/src/cache/NoStore.ts b/packages/backend-common/src/cache/NoStore.ts index 6acb7c0309..c89e814c93 100644 --- a/packages/backend-common/src/cache/NoStore.ts +++ b/packages/backend-common/src/cache/NoStore.ts @@ -19,7 +19,6 @@ * used when no cache store is configured in a Backstage backend instance. */ export class NoStore extends Map { - clear(): void { return; } @@ -39,5 +38,4 @@ export class NoStore extends Map { set(_key: string, _value: any): this { return this; } - }