(
filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {},
)
| 320 | } |
| 321 | |
| 322 | async function removeQueries( |
| 323 | filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {}, |
| 324 | ): Promise<void> { |
| 325 | const { exact, queryKey } = filters |
| 326 | |
| 327 | if (storage?.entries) { |
| 328 | const entries = await storage.entries() |
| 329 | const storageKeyPrefix = `${prefix}-` |
| 330 | for (const [key, value] of entries) { |
| 331 | if (key.startsWith(storageKeyPrefix)) { |
| 332 | if (!queryKey) { |
| 333 | await storage.removeItem(key) |
| 334 | continue |
| 335 | } |
| 336 | |
| 337 | let persistedQuery: PersistedQuery |
| 338 | try { |
| 339 | persistedQuery = await deserialize(value) |
| 340 | } catch { |
| 341 | await storage.removeItem(key) |
| 342 | continue |
| 343 | } |
| 344 | |
| 345 | if (exact) { |
| 346 | if (persistedQuery.queryHash !== hashKey(queryKey)) { |
| 347 | continue |
| 348 | } |
| 349 | } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) { |
| 350 | continue |
| 351 | } |
| 352 | |
| 353 | await storage.removeItem(key) |
| 354 | } |
| 355 | } |
| 356 | } else if (process.env.NODE_ENV === 'development') { |
| 357 | throw new Error( |
| 358 | 'Provided storage does not implement `entries` method. Removal of stored entries is not possible without ability to iterate over storage items.', |
| 359 | ) |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return { |
| 364 | persisterFn, |
nothing calls this directly
no test coverage detected