From cb02b9ec63cd86b5cb15c9b4f78d2aa3bc9bb0cd Mon Sep 17 00:00:00 2001 From: "dan.castillo" Date: Tue, 28 Feb 2023 20:03:54 -0600 Subject: [PATCH] feat: add stale to ts types --- index.d.ts | 2 ++ index.test-d.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4d7bd18..6ea8350 100644 --- a/index.d.ts +++ b/index.d.ts @@ -69,6 +69,7 @@ declare function createCache( storage?: StorageInputRedis | StorageInputMemory; ttl?: number; transformer?: DataTransformer; + stale?: number; } & Events ): Cache; @@ -87,6 +88,7 @@ declare class Cache { storage?: StorageOptionsType; transformer?: DataTransformer; ttl?: number; + stale?: number; serialize?: (...args: any[]) => any; references?: (...args: any[]) => References | Promise; } & Events, diff --git a/index.test-d.ts b/index.test-d.ts index 420d9a6..5281330 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -23,6 +23,12 @@ const memoryCache = createCache({ }); expectType(memoryCache); +const cacheWithTtlAndStale = createCache({ + ttl: 1000, + stale: 1000, +}); +expectType(cacheWithTtlAndStale); + // Testing Union Types const fetchSomething = async (k: any) => { @@ -32,6 +38,7 @@ const fetchSomething = async (k: any) => { export type CachedFunctions = { fetchSomething: typeof fetchSomething; + fetchSomethingElse: typeof fetchSomething; }; const unionMemoryCache = createCache({ @@ -45,8 +52,11 @@ expectType(unionMemoryCache); unionMemoryCache.define("fetchSomething", fetchSomething); expectType(unionMemoryCache.fetchSomething); +unionMemoryCache.define("fetchSomethingElse", { ttl: 1000, stale: 1000}, fetchSomething); +expectType(unionMemoryCache.fetchSomethingElse); + const result = await unionMemoryCache.fetchSomething("test"); expectType<{ k: any }>(result); await unionMemoryCache.invalidateAll("test:*"); -await unionMemoryCache.invalidateAll(["test:1", "test:2", "test:3"], "memory"); \ No newline at end of file +await unionMemoryCache.invalidateAll(["test:1", "test:2", "test:3"], "memory");