snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:13:08 +05:00
commit 3a013ccdfe
3570 changed files with 490194 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
---
id: createInfiniteQueryController
title: createInfiniteQueryController
---
```ts
function createInfiniteQueryController<TQueryFnData, TError, TData, TQueryKey, TPageParam>(
host,
options,
queryClient?): InfiniteQueryResultAccessor<TData, TError>;
```
Defined in: [packages/lit-query/src/createInfiniteQueryController.ts:402](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createInfiniteQueryController.ts#L402)
Creates a Lit reactive controller that subscribes the host to an infinite
query.
The returned accessor is callable and also exposes `current`, `refetch`,
`fetchNextPage`, `fetchPreviousPage`, and `destroy`. When `options` is a
function, it is re-read during host updates so query keys and options can
follow reactive host state.
If `queryClient` is omitted, the controller resolves the client from the
nearest connected `QueryClientProvider`.
## Type Parameters
### TQueryFnData
`TQueryFnData` = `unknown`
### TError
`TError` = `Error`
### TData
`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
### TPageParam
`TPageParam` = `unknown`
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the infinite query
subscription.
### options
[`Accessor`](../type-aliases/Accessor.md)\<[`CreateInfiniteQueryOptions`](../type-aliases/CreateInfiniteQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>\>
Infinite query observer options, or a getter that returns
options.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`InfiniteQueryResultAccessor`](../type-aliases/InfiniteQueryResultAccessor.md)\<`TData`, `TError`\>
An accessor for the latest infinite query result with page helper
methods.
## Example
```ts
import { LitElement, html } from 'lit'
import { createInfiniteQueryController } from '@tanstack/lit-query'
class ProjectsView extends LitElement {
private readonly projects = createInfiniteQueryController(this, {
queryKey: ['projects'],
queryFn: ({ pageParam }) => fetchProjects(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextCursor,
})
render() {
const query = this.projects()
return html`
<button ?disabled=${!query.hasNextPage} @click=${() => this.projects.fetchNextPage()}>
Load more
</button>
`
}
}
```

View File

@@ -0,0 +1,94 @@
---
id: createMutationController
title: createMutationController
---
```ts
function createMutationController<TData, TError, TVariables, TOnMutateResult>(
host,
options,
queryClient?): MutationResultAccessor<TData, TError, TVariables, TOnMutateResult>;
```
Defined in: [packages/lit-query/src/createMutationController.ts:340](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createMutationController.ts#L340)
Creates a Lit reactive controller that subscribes the host to a mutation.
The returned accessor is callable and also exposes `current`, `mutate`,
`mutateAsync`, `reset`, and `destroy`. When `options` is a function, it is
re-read during host updates so mutation options can follow reactive host
state.
If `queryClient` is omitted, the controller resolves the client from the
nearest connected `QueryClientProvider`.
## Type Parameters
### TData
`TData` = `unknown`
### TError
`TError` = `Error`
### TVariables
`TVariables` = `void`
### TOnMutateResult
`TOnMutateResult` = `unknown`
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the mutation
subscription.
### options
[`Accessor`](../type-aliases/Accessor.md)\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>\>
Mutation observer options, or a getter that returns options.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`MutationResultAccessor`](../type-aliases/MutationResultAccessor.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
An accessor for the latest mutation result with mutation helper
methods.
## Example
```ts
import { LitElement, html } from 'lit'
import { createMutationController } from '@tanstack/lit-query'
class AddTodoForm extends LitElement {
private readonly addTodo = createMutationController(this, {
mutationFn: (title: string) =>
fetch('/api/todos', { method: 'POST', body: JSON.stringify({ title }) }),
})
render() {
const mutation = this.addTodo()
return html`
<button ?disabled=${mutation.isPending} @click=${() => this.addTodo.mutate('Ship docs')}>
Add todo
</button>
`
}
}
```

View File

@@ -0,0 +1,88 @@
---
id: createQueriesController
title: createQueriesController
---
```ts
function createQueriesController<TQueryOptions, TCombinedResult>(
host,
options,
queryClient?): QueriesResultAccessor<TCombinedResult>;
```
Defined in: [packages/lit-query/src/createQueriesController.ts:701](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createQueriesController.ts#L701)
Creates a Lit reactive controller that subscribes the host to multiple
queries.
The returned accessor is callable and also exposes `current` and `destroy`.
When `options` or `options.queries` is a function, it is re-read during host
updates so the query list can follow reactive host state.
If `queryClient` is omitted, the controller resolves the client from the
nearest connected `QueryClientProvider`.
## Type Parameters
### TQueryOptions
`TQueryOptions` *extends* `any`[]
### TCombinedResult
`TCombinedResult` = `CreateQueriesResults`\<`TQueryOptions`\>
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the queries
subscription.
### options
[`Accessor`](../type-aliases/Accessor.md)\<[`CreateQueriesControllerOptions`](../type-aliases/CreateQueriesControllerOptions.md)\<`TQueryOptions`, `TCombinedResult`\>\>
Queries controller options, or a getter that returns options.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`QueriesResultAccessor`](../type-aliases/QueriesResultAccessor.md)\<`TCombinedResult`\>
An accessor for the latest query results, or the value returned by
`combine`.
## Example
```ts
import { LitElement, html } from 'lit'
import { createQueriesController } from '@tanstack/lit-query'
class DashboardView extends LitElement {
private readonly dashboard = createQueriesController(this, {
queries: [
{ queryKey: ['stats'], queryFn: fetchStats },
{ queryKey: ['projects'], queryFn: fetchProjects },
],
combine: ([stats, projects]) => ({
stats: stats.data,
projects: projects.data ?? [],
isPending: stats.isPending || projects.isPending,
}),
})
render() {
const dashboard = this.dashboard()
return html`<p>Projects: ${dashboard.projects.length}</p>`
}
}
```

View File

@@ -0,0 +1,95 @@
---
id: createQueryController
title: createQueryController
---
```ts
function createQueryController<TQueryFnData, TError, TData, TQueryData, TQueryKey>(
host,
options,
queryClient?): QueryResultAccessor<TData, TError>;
```
Defined in: [packages/lit-query/src/createQueryController.ts:355](https://github.com/TanStack/query/blob/main/packages/lit-query/src/createQueryController.ts#L355)
Creates a Lit reactive controller that subscribes the host to a single query.
The returned accessor is callable and also exposes `current`, `refetch`,
`suspense`, and `destroy`. When `options` is a function, it is re-read during
host updates so query keys and options can follow reactive host state.
If `queryClient` is omitted, the controller resolves the client from the
nearest connected `QueryClientProvider`.
## Type Parameters
### TQueryFnData
`TQueryFnData` = `unknown`
### TError
`TError` = `Error`
### TData
`TData` = `TQueryFnData`
### TQueryData
`TQueryData` = `TQueryFnData`
### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the query
subscription.
### options
[`Accessor`](../type-aliases/Accessor.md)\<[`CreateQueryOptions`](../type-aliases/CreateQueryOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryData`, `TQueryKey`\>\>
Query observer options, or a getter that returns options.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`QueryResultAccessor`](../type-aliases/QueryResultAccessor.md)\<`TData`, `TError`\>
An accessor for the latest query result with query helper methods.
## Example
```ts
import { LitElement, html } from 'lit'
import { createQueryController } from '@tanstack/lit-query'
class TodosView extends LitElement {
private readonly todos = createQueryController(this, {
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then((r) => r.json()),
})
render() {
const query = this.todos()
if (query.isPending) return html`Loading...`
if (query.isError) return html`Error`
return html`<ul>${query.data.map((todo) => html`<li>${todo.title}</li>`)}</ul>`
}
}
```

View File

@@ -0,0 +1,23 @@
---
id: defaultShouldDehydrateMutation
title: defaultShouldDehydrateMutation
---
```ts
function defaultShouldDehydrateMutation(mutation): boolean;
```
Defined in: [packages/query-core/src/hydration.ts:177](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L177)
The default `shouldDehydrateMutation` predicate used by `dehydrate`. Only dehydrates mutations that are
currently paused (e.g. paused by `networkMode` while offline).
## Parameters
### mutation
[`Mutation`](../classes/Mutation.md)
## Returns
`boolean`

View File

@@ -0,0 +1,23 @@
---
id: defaultShouldDehydrateQuery
title: defaultShouldDehydrateQuery
---
```ts
function defaultShouldDehydrateQuery(query): boolean;
```
Defined in: [packages/query-core/src/hydration.ts:185](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L185)
The default `shouldDehydrateQuery` predicate used by `dehydrate`. Only dehydrates queries whose status is
`'success'`.
## Parameters
### query
[`Query`](../classes/Query.md)
## Returns
`boolean`

View File

@@ -0,0 +1,43 @@
---
id: dehydrate
title: dehydrate
---
```ts
function dehydrate(client, options): DehydratedState;
```
Defined in: [packages/query-core/src/hydration.ts:207](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L207)
Dehydrates a `QueryClient`'s cache (queries and mutations) into a plain, serializable `DehydratedState`,
typically to embed in server-rendered markup and later restore into a client-side `QueryClient` via `hydrate`.
Which queries/mutations are included, and how their data/errors are transformed, is controlled by `options`,
falling back to the client's `dehydrate` default options, and finally to `defaultShouldDehydrateQuery` /
`defaultShouldDehydrateMutation`.
## Parameters
### client
[`QueryClient`](../classes/QueryClient.md)
### options
[`DehydrateOptions`](../interfaces/DehydrateOptions.md) = `{}`
## Returns
[`DehydratedState`](../interfaces/DehydratedState.md)
## Example
```ts
const queryClient = new QueryClient()
await queryClient.prefetchQuery({
queryKey: ['posts'],
queryFn: getPosts,
})
const dehydratedState = dehydrate(queryClient)
```

View File

@@ -0,0 +1,43 @@
---
id: dehydrateQuery
title: dehydrateQuery
---
```ts
function dehydrateQuery(
query,
serializeData?,
shouldRedactErrors?): DehydratedQuery;
```
Defined in: [packages/query-core/src/hydration.ts:148](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L148)
Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g.
`queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the
de/rehydrated data, typically with `useQuery` on the client. If the query is still `pending`, its in-flight
promise is dehydrated too so it can be resumed on the other side instead of re-fetched.
## Parameters
### query
[`Query`](../classes/Query.md)
The query to dehydrate.
### serializeData?
`TransformerFn`
Optional transform applied to `query.state.data` before it is included in the snapshot.
### shouldRedactErrors?
(`error`) => `boolean`
Optional predicate; if it returns `false` for the promise's rejection error, that
error is kept as-is instead of being redacted.
## Returns
`DehydratedQuery`

View File

@@ -0,0 +1,52 @@
---
id: experimental_streamedQuery
title: experimental_streamedQuery
---
```ts
function experimental_streamedQuery<TQueryFnData, TData, TQueryKey>(streamFn): QueryFunction<TData, TQueryKey>;
```
Defined in: [packages/query-core/src/streamedQuery.ts:75](https://github.com/TanStack/query/blob/main/packages/query-core/src/streamedQuery.ts#L75)
This is a helper function to create a query function that streams data from an AsyncIterable.
Data will be an Array of all the chunks received.
The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
The query will stay in fetchStatus 'fetching' until the stream ends.
## Type Parameters
### TQueryFnData
`TQueryFnData` = `unknown`
### TData
`TData` = `TQueryFnData`[]
### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
## Parameters
### streamFn
`StreamedQueryParams`\<`TQueryFnData`, `TData`, `TQueryKey`\>
The function that returns an AsyncIterable to stream data from.
## Returns
[`QueryFunction`](../type-aliases/QueryFunction.md)\<`TData`, `TQueryKey`\>
## Example
```ts
await queryClient.query({
queryKey: ['data'],
queryFn: streamedQuery({
streamFn: fetchDataInChunks,
}),
})
```

View File

@@ -0,0 +1,20 @@
---
id: getDefaultQueryClient
title: getDefaultQueryClient
---
```ts
function getDefaultQueryClient(): QueryClient | undefined;
```
Defined in: [packages/lit-query/src/context.ts:72](https://github.com/TanStack/query/blob/main/packages/lit-query/src/context.ts#L72)
Returns the registered default `QueryClient`, if exactly one default client is
available.
## Returns
[`QueryClient`](../classes/QueryClient.md) \| `undefined`
The default query client, or `undefined` when there is no registered
client or more than one registered client.

View File

@@ -0,0 +1,30 @@
---
id: hashKey
title: hashKey
---
```ts
function hashKey(queryKey): string;
```
Defined in: [packages/query-core/src/utils.ts:284](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L284)
Default query & mutation keys hash function.
Hashes the value into a stable hash.
## Parameters
### queryKey
readonly `unknown`[]
## Returns
`string`
## Example
```ts
// Object keys are sorted, so key order doesn't affect the hash:
hashKey(['todos', { page: 1, filter: 'done' }]) // === '["todos",{"filter":"done","page":1}]'
```

View File

@@ -0,0 +1,49 @@
---
id: hydrate
title: hydrate
---
```ts
function hydrate(
client,
dehydratedState,
options?): void;
```
Defined in: [packages/query-core/src/hydration.ts:264](https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L264)
Restores a `DehydratedState` (as produced by `dehydrate`) into a `QueryClient`'s cache, typically to seed the
client with data already fetched on the server. `mutations` and `queries` are each optional on `dehydratedState`.
Queries not yet in the cache are built from the dehydrated snapshot; queries that already exist are only updated
when the dehydrated data is newer than what's already cached. Newly built queries have their `fetchStatus` reset
to `'idle'` so they don't hydrate stuck in a fetching state. If a dehydrated query still had an in-flight
promise, it is resumed via `query.fetch()` (reusing that promise as `initialPromise`) rather than re-invoking
`queryFn`.
## Parameters
### client
[`QueryClient`](../classes/QueryClient.md)
### dehydratedState
`Partial`\<[`DehydratedState`](../interfaces/DehydratedState.md)\>
### options?
[`HydrateOptions`](../interfaces/HydrateOptions.md)
## Returns
`void`
## Example
```ts
// dehydratedState was produced by `dehydrate` on the server
// and sent to the client, e.g. embedded in server-rendered markup.
const queryClient = new QueryClient()
hydrate(queryClient, dehydratedState)
```

View File

@@ -0,0 +1,62 @@
---
id: infiniteQueryOptions
title: infiniteQueryOptions
---
```ts
function infiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>(options): InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & object;
```
Defined in: [packages/lit-query/src/infiniteQueryOptions.ts:28](https://github.com/TanStack/query/blob/main/packages/lit-query/src/infiniteQueryOptions.ts#L28)
Brands infinite query options so the `queryKey` carries the infinite query
data and error types across TanStack Query APIs.
## Type Parameters
### TQueryFnData
`TQueryFnData` = `unknown`
### TError
`TError` = `Error`
### TData
`TData` = [`InfiniteData`](../interfaces/InfiniteData.md)\<`TQueryFnData`, `unknown`\>
### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
### TPageParam
`TPageParam` = `unknown`
## Parameters
### options
[`InfiniteQueryObserverOptions`](../interfaces/InfiniteQueryObserverOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\>
Infinite query options to preserve and brand.
## Returns
[`InfiniteQueryObserverOptions`](../interfaces/InfiniteQueryObserverOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`, `TPageParam`\> & `object`
The same options object with a typed `queryKey`.
## Example
```ts
import { infiniteQueryOptions } from '@tanstack/lit-query'
const projectsOptions = infiniteQueryOptions({
queryKey: ['projects'],
queryFn: ({ pageParam }) => fetchProjects(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextCursor,
})
```

View File

@@ -0,0 +1,24 @@
---
id: isCancelledError
title: isCancelledError
---
```ts
function isCancelledError(value): value is CancelledError;
```
Defined in: [packages/query-core/src/retryer.ts:90](https://github.com/TanStack/query/blob/main/packages/query-core/src/retryer.ts#L90)
## Parameters
### value
`any`
## Returns
`value is CancelledError`
## Deprecated
Use instanceof `CancelledError` instead.

View File

@@ -0,0 +1,40 @@
---
id: keepPreviousData
title: keepPreviousData
---
```ts
function keepPreviousData<T>(previousData): T | undefined;
```
Defined in: [packages/query-core/src/utils.ts:493](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L493)
Intended to be passed as a query's `placeholderData` option, for example
`placeholderData: keepPreviousData`. Instead of resetting the query's data to `undefined` while a new
query key is fetching, it keeps displaying the previously fetched data until the new data arrives.
## Type Parameters
### T
`T`
## Parameters
### previousData
`T` | `undefined`
## Returns
`T` \| `undefined`
## Example
```ts
new QueryObserver(queryClient, {
queryKey: ['posts', page],
queryFn: () => fetchPosts(page),
placeholderData: keepPreviousData,
})
```

View File

@@ -0,0 +1,38 @@
---
id: matchMutation
title: matchMutation
---
```ts
function matchMutation(filters, mutation): boolean;
```
Defined in: [packages/query-core/src/utils.ts:237](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L237)
Checks whether a mutation matches the given [MutationFilters](../interfaces/MutationFilters.md).
Every filter that is specified must match; filters that are left unspecified are ignored.
If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
## Parameters
### filters
[`MutationFilters`](../interfaces/MutationFilters.md)
### mutation
[`Mutation`](../classes/Mutation.md)\<`any`, `any`\>
## Returns
`boolean`
## Example
```ts
const mutationCache = queryClient.getMutationCache()
const matchingMutations = mutationCache
.getAll()
.filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
```

View File

@@ -0,0 +1,37 @@
---
id: matchQuery
title: matchQuery
---
```ts
function matchQuery(filters, query): boolean;
```
Defined in: [packages/query-core/src/utils.ts:175](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L175)
Checks whether a query matches the given [QueryFilters](../interfaces/QueryFilters.md).
Every filter that is specified must match; filters that are left unspecified are ignored.
## Parameters
### filters
[`QueryFilters`](../interfaces/QueryFilters.md)
### query
[`Query`](../classes/Query.md)\<`any`, `any`, `any`, `any`\>
## Returns
`boolean`
## Example
```ts
const queryCache = queryClient.getQueryCache()
const matchingQueries = queryCache
.getAll()
.filter((query) => matchQuery({ queryKey: ['posts'] }, query))
```

View File

@@ -0,0 +1,55 @@
---
id: mutationOptions
title: mutationOptions
---
```ts
function mutationOptions<TData, TError, TVariables, TOnMutateResult>(options): MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>;
```
Defined in: [packages/lit-query/src/mutationOptions.ts:22](https://github.com/TanStack/query/blob/main/packages/lit-query/src/mutationOptions.ts#L22)
Preserves and types mutation options for reuse across Lit Query APIs.
## Type Parameters
### TData
`TData` = `unknown`
### TError
`TError` = `Error`
### TVariables
`TVariables` = `void`
### TOnMutateResult
`TOnMutateResult` = `unknown`
## Parameters
### options
[`MutationObserverOptions`](../interfaces/MutationObserverOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
Mutation options to preserve.
## Returns
[`MutationObserverOptions`](../interfaces/MutationObserverOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
The same options object.
## Example
```ts
import { mutationOptions } from '@tanstack/lit-query'
const addTodoOptions = mutationOptions({
mutationKey: ['add-todo'],
mutationFn: (title: string) => addTodo(title),
})
```

View File

@@ -0,0 +1,32 @@
---
id: noop
title: noop
---
## Call Signature
```ts
function noop(): void;
```
Defined in: [packages/query-core/src/utils.ts:119](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L119)
A function that does nothing.
### Returns
`void`
## Call Signature
```ts
function noop(): undefined;
```
Defined in: [packages/query-core/src/utils.ts:120](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L120)
A function that does nothing.
### Returns
`undefined`

View File

@@ -0,0 +1,26 @@
---
id: partialMatchKey
title: partialMatchKey
---
```ts
function partialMatchKey(a, b): boolean;
```
Defined in: [packages/query-core/src/utils.ts:300](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L300)
Checks if key `b` partially matches with key `a`.
## Parameters
### a
readonly `unknown`[]
### b
readonly `unknown`[]
## Returns
`boolean`

View File

@@ -0,0 +1,145 @@
---
id: queryOptions
title: queryOptions
---
## Call Signature
```ts
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options): Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, never>, "queryFn"> & object & object;
```
Defined in: [packages/lit-query/src/queryOptions.ts:94](https://github.com/TanStack/query/blob/main/packages/lit-query/src/queryOptions.ts#L94)
Brands query options so the `queryKey` carries the query function data and
error types across TanStack Query APIs.
### Type Parameters
#### TQueryFnData
`TQueryFnData` = `unknown`
#### TError
`TError` = `Error`
#### TData
`TData` = `TQueryFnData`
#### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
### Parameters
#### options
[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
Query options to preserve and brand.
### Returns
`Omit`\<[`QueryObserverOptions`](../interfaces/QueryObserverOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`, `never`\>, `"queryFn"`\> & `object` & `object`
The same options object with a typed `queryKey`.
### Example
```ts
import { queryOptions } from '@tanstack/lit-query'
const todosOptions = queryOptions({
queryKey: ['todos'],
queryFn: fetchTodos,
initialData: [],
})
```
## Call Signature
```ts
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options): OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, never>, "queryFn"> & object & object;
```
Defined in: [packages/lit-query/src/queryOptions.ts:112](https://github.com/TanStack/query/blob/main/packages/lit-query/src/queryOptions.ts#L112)
Brands query options so the `queryKey` carries the query function data and
error types across TanStack Query APIs.
### Type Parameters
#### TQueryFnData
`TQueryFnData` = `unknown`
#### TError
`TError` = `Error`
#### TData
`TData` = `TQueryFnData`
#### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
### Parameters
#### options
[`UnusedSkipTokenOptions`](../type-aliases/UnusedSkipTokenOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
Query options to preserve and brand.
### Returns
[`OmitKeyof`](../type-aliases/OmitKeyof.md)\<[`QueryObserverOptions`](../interfaces/QueryObserverOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`, `never`\>, `"queryFn"`\> & `object` & `object`
The same options object with a typed `queryKey`.
## Call Signature
```ts
function queryOptions<TQueryFnData, TError, TData, TQueryKey>(options): QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, never> & object & object;
```
Defined in: [packages/lit-query/src/queryOptions.ts:130](https://github.com/TanStack/query/blob/main/packages/lit-query/src/queryOptions.ts#L130)
Brands query options so the `queryKey` carries the query function data and
error types across TanStack Query APIs.
### Type Parameters
#### TQueryFnData
`TQueryFnData` = `unknown`
#### TError
`TError` = `Error`
#### TData
`TData` = `TQueryFnData`
#### TQueryKey
`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[]
### Parameters
#### options
[`UndefinedInitialDataOptions`](../type-aliases/UndefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\>
Query options to preserve and brand.
### Returns
[`QueryObserverOptions`](../interfaces/QueryObserverOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryFnData`, `TQueryKey`, `never`\> & `object` & `object`
The same options object with a typed `queryKey`.

View File

@@ -0,0 +1,28 @@
---
id: registerDefaultQueryClient
title: registerDefaultQueryClient
---
```ts
function registerDefaultQueryClient(client): void;
```
Defined in: [packages/lit-query/src/context.ts:32](https://github.com/TanStack/query/blob/main/packages/lit-query/src/context.ts#L32)
Registers a `QueryClient` as a process-local fallback for APIs that resolve a
client without an explicit argument.
`QueryClientProvider` calls this automatically while it is connected. Prefer
passing an explicit client or rendering under a provider when possible.
## Parameters
### client
[`QueryClient`](../classes/QueryClient.md)
The query client to register as the current default.
## Returns
`void`

View File

@@ -0,0 +1,41 @@
---
id: replaceEqualDeep
title: replaceEqualDeep
---
```ts
function replaceEqualDeep<T>(
a,
b,
depth?): T;
```
Defined in: [packages/query-core/src/utils.ts:339](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L339)
This function returns `a` if `b` is deeply equal.
If not, it will replace any deeply equal children of `b` with those of `a`.
This can be used for structural sharing between JSON values for example.
## Type Parameters
### T
`T`
## Parameters
### a
`unknown`
### b
`T`
### depth?
`number`
## Returns
`T`

View File

@@ -0,0 +1,27 @@
---
id: resolveQueryClient
title: resolveQueryClient
---
```ts
function resolveQueryClient(explicit?): QueryClient;
```
Defined in: [packages/lit-query/src/context.ts:118](https://github.com/TanStack/query/blob/main/packages/lit-query/src/context.ts#L118)
Resolves an explicit `QueryClient` or falls back to `useQueryClient`.
## Parameters
### explicit?
[`QueryClient`](../classes/QueryClient.md)
Optional client supplied by the caller.
## Returns
[`QueryClient`](../classes/QueryClient.md)
The explicit client when provided, otherwise the current default
client.

View File

@@ -0,0 +1,45 @@
---
id: shouldThrowError
title: shouldThrowError
---
```ts
function shouldThrowError<T>(throwOnError, params): boolean;
```
Defined in: [packages/query-core/src/utils.ts:576](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L576)
Resolves a `throwOnError` option to a boolean.
If `throwOnError` is a function, it is called with `params` (e.g. the error and, depending on the caller,
additional context such as the query or mutation) and its result is returned, allowing the throwing
behavior to be decided per error. Otherwise, `throwOnError` itself is coerced to a boolean (`undefined`
resolves to `false`).
## Type Parameters
### T
`T` *extends* (...`args`) => `boolean`
## Parameters
### throwOnError
`boolean` | `T` | `undefined`
### params
`Parameters`\<`T`\>
## Returns
`boolean`
## Example
```ts
const throwOnError =
query.state.error && typeof options.throwOnError === 'function'
? shouldThrowError(options.throwOnError, [query.state.error, query])
: options.throwOnError
```

View File

@@ -0,0 +1,27 @@
---
id: unregisterDefaultQueryClient
title: unregisterDefaultQueryClient
---
```ts
function unregisterDefaultQueryClient(client): void;
```
Defined in: [packages/lit-query/src/context.ts:45](https://github.com/TanStack/query/blob/main/packages/lit-query/src/context.ts#L45)
Unregisters a client previously registered with
`registerDefaultQueryClient`.
`QueryClientProvider` calls this automatically when it disconnects.
## Parameters
### client
[`QueryClient`](../classes/QueryClient.md)
The query client registration to release.
## Returns
`void`

View File

@@ -0,0 +1,65 @@
---
id: useIsFetching
title: useIsFetching
---
```ts
function useIsFetching(
host,
filters,
queryClient?): IsFetchingAccessor;
```
Defined in: [packages/lit-query/src/useIsFetching.ts:147](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsFetching.ts#L147)
Creates a Lit reactive controller that tracks how many matching queries are
currently fetching.
When `filters` is a function, it is re-read during host updates so the count
can follow reactive host state. If `queryClient` is omitted, the controller
resolves the client from the nearest connected `QueryClientProvider`.
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the cache
subscription.
### filters
[`Accessor`](../type-aliases/Accessor.md)\<[`QueryFilters`](../interfaces/QueryFilters.md)\<readonly `unknown`[]\>\> = `{}`
Query filters, or a getter that returns query filters.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`IsFetchingAccessor`](../type-aliases/IsFetchingAccessor.md)
An accessor for the current number of matching fetching queries.
## Example
```ts
import { LitElement, html } from 'lit'
import { useIsFetching } from '@tanstack/lit-query'
class TodosStatus extends LitElement {
private readonly todosFetching = useIsFetching(this, {
queryKey: ['todos'],
})
render() {
return html`<span>${this.todosFetching()} active todo fetches</span>`
}
}
```

View File

@@ -0,0 +1,65 @@
---
id: useIsMutating
title: useIsMutating
---
```ts
function useIsMutating(
host,
filters,
queryClient?): IsMutatingAccessor;
```
Defined in: [packages/lit-query/src/useIsMutating.ts:147](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useIsMutating.ts#L147)
Creates a Lit reactive controller that tracks how many matching mutations are
currently pending.
When `filters` is a function, it is re-read during host updates so the count
can follow reactive host state. If `queryClient` is omitted, the controller
resolves the client from the nearest connected `QueryClientProvider`.
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the cache
subscription.
### filters
[`Accessor`](../type-aliases/Accessor.md)\<[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>\> = `{}`
Mutation filters, or a getter that returns mutation filters.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`IsMutatingAccessor`](../type-aliases/IsMutatingAccessor.md)
An accessor for the current number of matching pending mutations.
## Example
```ts
import { LitElement, html } from 'lit'
import { useIsMutating } from '@tanstack/lit-query'
class MutationStatus extends LitElement {
private readonly savesPending = useIsMutating(this, {
mutationKey: ['save-project'],
})
render() {
return html`<span>${this.savesPending()} saves pending</span>`
}
}
```

View File

@@ -0,0 +1,73 @@
---
id: useMutationState
title: useMutationState
---
```ts
function useMutationState<TResult>(
host,
options,
queryClient?): MutationStateAccessor<TResult>;
```
Defined in: [packages/lit-query/src/useMutationState.ts:192](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useMutationState.ts#L192)
Creates a Lit reactive controller that selects state from matching mutations
in the mutation cache.
When `options.filters` is a function, it is re-read during host updates so
the selection can follow reactive host state. If `queryClient` is omitted,
the controller resolves the client from the nearest connected
`QueryClientProvider`.
## Type Parameters
### TResult
`TResult` = [`MutationState`](../interfaces/MutationState.md)\<`unknown`, `unknown`, `unknown`, `unknown`\>
## Parameters
### host
`ReactiveControllerHost`
The Lit reactive controller host that owns the mutation cache
subscription.
### options
[`MutationStateOptions`](../type-aliases/MutationStateOptions.md)\<`TResult`\> = `{}`
Mutation state filters and optional selector.
### queryClient?
[`QueryClient`](../classes/QueryClient.md)
Optional explicit query client. Provide this for
controllers that should not resolve a client from Lit context.
## Returns
[`MutationStateAccessor`](../type-aliases/MutationStateAccessor.md)\<`TResult`\>
An accessor for the selected mutation state array.
## Example
```ts
import { LitElement, html } from 'lit'
import { useMutationState } from '@tanstack/lit-query'
class PendingUploads extends LitElement {
private readonly uploads = useMutationState(this, {
filters: { mutationKey: ['upload'], status: 'pending' },
select: (mutation) => mutation.state.variables as File,
})
render() {
return html`<span>${this.uploads().length} uploads pending</span>`
}
}
```

View File

@@ -0,0 +1,23 @@
---
id: useQueryClient
title: useQueryClient
---
```ts
function useQueryClient(): QueryClient;
```
Defined in: [packages/lit-query/src/context.ts:98](https://github.com/TanStack/query/blob/main/packages/lit-query/src/context.ts#L98)
Resolves the current default `QueryClient` registered by a connected
`QueryClientProvider`.
This helper is useful outside a Lit reactive controller when a single
provider is mounted. It throws if no client is registered or if multiple
clients are mounted and the default would be ambiguous.
## Returns
[`QueryClient`](../classes/QueryClient.md)
The single registered query client.