From cb13a6c04ecade94c21c5e7b2c28252d5a573bc6 Mon Sep 17 00:00:00 2001 From: Joseph Axisa Date: Wed, 12 Apr 2023 23:14:29 +0000 Subject: [PATCH] feedback --- packages/embed-services/src/ItemList.spec.ts | 14 ++++++++++++++ packages/embed-services/src/ItemList.ts | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/embed-services/src/ItemList.spec.ts b/packages/embed-services/src/ItemList.spec.ts index 2ee013316..785a821da 100644 --- a/packages/embed-services/src/ItemList.spec.ts +++ b/packages/embed-services/src/ItemList.spec.ts @@ -123,6 +123,20 @@ describe('ItemList', () => { it('returns undefined if item not found', () => { const actual = ItemList.find('name', 'bogus') expect(actual).toBeUndefined() + + expect(ItemList.find('name', 'barName')).toEqual(items[1]) + }) + }) + + describe('getCacheDefault', () => { + it('gets the default', () => { + const actual = ItemList.getCacheDefault() + expect(actual).toBe(true) + }) + + it('gets value from itemCache option when specified', () => { + const actual = ItemList.getCacheDefault({ itemCache: false }) + expect(actual).toBe(false) }) }) }) diff --git a/packages/embed-services/src/ItemList.ts b/packages/embed-services/src/ItemList.ts index 30410a0cd..053eaf76c 100644 --- a/packages/embed-services/src/ItemList.ts +++ b/packages/embed-services/src/ItemList.ts @@ -29,6 +29,11 @@ import { EntityService } from './EntityService' export const DEFAULT_TTL = 900 // 15 minutes +export interface GetOptions { + itemCache?: boolean + [key: string]: any +} + export interface IItemList { /** Cache time to live in seconds, defaults to 15 minutes */ readonly timeToLive: number @@ -42,7 +47,7 @@ export interface IItemList { } export interface IEntityService extends IItemList { - get(id: string, cache?: boolean, ...options: any[]): Promise + get(id: string, options?: GetOptions): Promise set(id: string, item: T): Promise getAll(...options: any[]): Promise> delete(id: string): void @@ -111,4 +116,13 @@ export abstract class ItemList> | T | undefined } + + /** + * Gets the cache option value if present, otherwise defaults to true + * @param options to check + */ + getCacheDefault(options?: GetOptions) { + const cache = options && 'itemCache' in options ? options.itemCache : true + return cache + } }