Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(experimental_createQueryPersister): Add removeQueries#10186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3d35acb39084af9d425b076317f4d8867e470d9d0f235beebe52bb4f73589e08bd48b6448c3cb544d211a60f320f7d5744a22eadfFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/query-persist-client-core': minor | ||
| --- | ||
| Add removeQueries to experimental_createQueryPersister | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -301,12 +301,54 @@ export function experimental_createQueryPersister<TStorageValue = string>({ | ||
| } | ||
| } | ||
| async function removeQueries( | ||
| filters: Pick<QueryFilters, 'queryKey' | 'exact'> = {}, | ||
| ): Promise<void> { | ||
| const { exact, queryKey } = filters | ||
| if (storage?.entries) { | ||
| const entries = await storage.entries() | ||
| const storageKeyPrefix = `${prefix}-` | ||
| for (const [key, value] of entries) { | ||
| if (key.startsWith(storageKeyPrefix)) { | ||
| if (!queryKey) { | ||
| await storage.removeItem(key) | ||
| continue | ||
| } | ||
| let persistedQuery: PersistedQuery | ||
| try { | ||
| persistedQuery = await deserialize(value) | ||
| } catch { | ||
rklomp marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| await storage.removeItem(key) | ||
| continue | ||
| } | ||
| if (exact) { | ||
| if (persistedQuery.queryHash !== hashKey(queryKey)) { | ||
| continue | ||
| } | ||
| } else if (!partialMatchKey(persistedQuery.queryKey, queryKey)) { | ||
| continue | ||
| } | ||
| await storage.removeItem(key) | ||
rklomp marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| } else if (process.env.NODE_ENV === 'development') { | ||
| throw new Error( | ||
| 'Provided storage does not implement `entries` method. Removal of stored entries is not possible without ability to iterate over storage items.', | ||
| ) | ||
rklomp marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| return { | ||
| persisterFn, | ||
| persistQuery, | ||
| persistQueryByKey, | ||
| retrieveQuery, | ||
| persisterGc, | ||
| restoreQueries, | ||
| removeQueries, | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.