Maybe not THAT transparent.
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
@@ -65,9 +65,9 @@ export class BitbucketUrlReader implements UrlReader {
|
||||
|
||||
// @public
|
||||
export interface CacheClient {
|
||||
delete(key: string): Promise<boolean>;
|
||||
delete(key: string): Promise<void>;
|
||||
get(key: string): Promise<JsonValue | undefined>;
|
||||
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<boolean>;
|
||||
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
||||
@@ -101,16 +101,6 @@ describe('CacheClient', () => {
|
||||
|
||||
return expect(sut.set('someKey', {})).rejects.toEqual(expectedError);
|
||||
});
|
||||
|
||||
it('resolves what underlying client resolves', async () => {
|
||||
const sut = new DefaultCacheClient({ client });
|
||||
const expectedResponse = true;
|
||||
client.set = jest.fn().mockReturnValue(expectedResponse);
|
||||
|
||||
const actualResponse = await sut.set('someKey', {});
|
||||
|
||||
return expect(actualResponse).toEqual(expectedResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CacheClient.delete', () => {
|
||||
@@ -132,15 +122,5 @@ describe('CacheClient', () => {
|
||||
|
||||
return expect(sut.delete('someKey')).rejects.toEqual(expectedError);
|
||||
});
|
||||
|
||||
it('resolves what underlying client resolves', async () => {
|
||||
const sut = new DefaultCacheClient({ client });
|
||||
const expectedResponse = false;
|
||||
client.delete = jest.fn().mockResolvedValue(expectedResponse);
|
||||
|
||||
const actualResponse = await sut.delete('someKey');
|
||||
|
||||
return expect(actualResponse).toEqual(expectedResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
-12
@@ -46,17 +46,12 @@ 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<boolean>;
|
||||
set(key: string, value: JsonValue, options?: CacheSetOptions): Promise<void>;
|
||||
|
||||
/**
|
||||
* Removes the given key from the cache store. Resolves true if the key
|
||||
* existed, or false if not.
|
||||
* Removes the given key from the cache store.
|
||||
*/
|
||||
delete(key: string): Promise<boolean>;
|
||||
delete(key: string): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,14 +74,14 @@ export class DefaultCacheClient implements CacheClient {
|
||||
key: string,
|
||||
value: JsonValue,
|
||||
opts: CacheSetOptions = {},
|
||||
): Promise<boolean> {
|
||||
): Promise<void> {
|
||||
const k = this.getNormalizedKey(key);
|
||||
return await this.client.set(k, value, opts.ttl);
|
||||
await this.client.set(k, value, opts.ttl);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<boolean> {
|
||||
async delete(key: string): Promise<void> {
|
||||
const k = this.getNormalizedKey(key);
|
||||
return await this.client.delete(k);
|
||||
await this.client.delete(k);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user