(
queryClient: QueryClient,
filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},
)
| 248 | } |
| 249 | |
| 250 | async function restoreQueries( |
| 251 | queryClient: QueryClient, |
| 252 | filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {}, |
| 253 | ): Promise<void> { |
| 254 | const { exact, queryKey } = filters |
| 255 | |
| 256 | if (storage?.entries) { |
| 257 | const entries = await storage.entries() |
| 258 | for (const [key, value] of entries) { |
| 259 | if (key.startsWith(prefix)) { |
| 260 | const persistedQuery = await deserialize(value) |
| 261 | |
| 262 | if (isExpiredOrBusted(persistedQuery)) { |
| 263 | await storage.removeItem(key) |
| 264 | continue |
| 265 | } |
| 266 | |
| 267 | if (queryKey) { |
| 268 | if (exact) { |
| 269 | if (persistedQuery.queryHash !== hashKey(queryKey)) { |
| 270 | continue |
| 271 | } |
| 272 | } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) { |
| 273 | continue |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | queryClient.setQueryData( |
| 278 | persistedQuery.queryKey, |
| 279 | persistedQuery.state.data, |
| 280 | { |
| 281 | updatedAt: persistedQuery.state.dataUpdatedAt, |
| 282 | }, |
| 283 | ) |
| 284 | } |
| 285 | } |
| 286 | } else if (process.env.NODE_ENV === 'development') { |
| 287 | throw new Error( |
| 288 | 'Provided storage does not implement `entries` method. Restoration of all stored entries is not possible without ability to iterate over storage items.', |
| 289 | ) |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return { |
| 294 | persisterFn, |
nothing calls this directly
no test coverage detected
searching dependent graphs…