apollographql / apollo-cache-persist

🎏 Simple persistence for all Apollo Cache implementations
MIT License
1.39k stars 118 forks source link

feat(types): turn `LocalForageWrapper` into a generic class #528

Open charpeni opened 5 months ago

charpeni commented 5 months ago

LocalForageWrapper is currently typed as string | object | null, but it solely depends on whether we serialize or not.

Also, localForage (and IndexedDB) supports storing more than string or object, it supports the following JS objects:

I didn't want to introduce a breaking change by changing the type, so instead, I turned LocalForageWrapper into a generic class expecting a type for LocalForage and defaulting to string | object | null (current value).

It means that if you're storing binary data in IndexedDB, you can provide the type as such: LocalForageWrapper<Uint8Array>.