localforage and axios-extensions: Wrapping the get method to return undefined outside of a promise?

57 Views Asked by At

I'm trying to use axios-extensions and localforage to create an axios cache adapter that uses the localforage library for its storage (our codebase is dated and I'm looking to replace the old axios-cache-adapter, which is not updated for the newest axios version). I'll abstract away some of the details here to make the situation simpler:

localforage has a get method with a signature like this:

get(key: string): Promise<string | undefined>

However, the axios-extensions cache adapter function expects a method with a signature like this:

get(key: string): Promise<string> | undefined

It feels like it should be simple to write a wrapper for localforage's get, but I haven't found a way to do it yet without something ridiculous like busy-waiting. Is there any way to wrap the localforage get function in order to synchronously return undefined, even though I can't know if a field exists until the promise resolves? Do I really need to use a different library/create a patch for this one in order to do this?

0

There are 0 best solutions below