@tanstack/lit-query 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/build/legacy/index.cjs +1585 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +781 -0
- package/build/legacy/index.d.cts.map +1 -0
- package/build/legacy/index.d.ts +781 -0
- package/build/legacy/index.d.ts.map +1 -0
- package/build/legacy/index.js +1561 -0
- package/build/legacy/index.js.map +1 -0
- package/build/modern/index.cjs +1569 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +781 -0
- package/build/modern/index.d.cts.map +1 -0
- package/build/modern/index.d.ts +781 -0
- package/build/modern/index.d.ts.map +1 -0
- package/build/modern/index.js +1545 -0
- package/build/modern/index.js.map +1 -0
- package/package.json +27 -30
- package/src/createInfiniteQueryController.ts +0 -1
- package/src/createMutationController.ts +9 -7
- package/src/createQueriesController.ts +0 -2
- package/src/createQueryController.ts +0 -1
- package/src/infiniteQueryOptions.ts +10 -4
- package/dist/QueryClientProvider.d.ts +0 -85
- package/dist/QueryClientProvider.d.ts.map +0 -1
- package/dist/QueryClientProvider.js +0 -137
- package/dist/QueryClientProvider.js.map +0 -1
- package/dist/accessor.d.ts +0 -32
- package/dist/accessor.d.ts.map +0 -1
- package/dist/accessor.js +0 -12
- package/dist/accessor.js.map +0 -1
- package/dist/context.d.ts +0 -59
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -100
- package/dist/context.js.map +0 -1
- package/dist/controllers/BaseController.d.ts +0 -39
- package/dist/controllers/BaseController.d.ts.map +0 -1
- package/dist/controllers/BaseController.js +0 -213
- package/dist/controllers/BaseController.js.map +0 -1
- package/dist/createInfiniteQueryController.d.ts +0 -76
- package/dist/createInfiniteQueryController.d.ts.map +0 -1
- package/dist/createInfiniteQueryController.js +0 -248
- package/dist/createInfiniteQueryController.js.map +0 -1
- package/dist/createMutationController.d.ts +0 -79
- package/dist/createMutationController.d.ts.map +0 -1
- package/dist/createMutationController.js +0 -193
- package/dist/createMutationController.js.map +0 -1
- package/dist/createQueriesController.d.ts +0 -145
- package/dist/createQueriesController.d.ts.map +0 -1
- package/dist/createQueriesController.js +0 -367
- package/dist/createQueriesController.js.map +0 -1
- package/dist/createQueryController.d.ts +0 -67
- package/dist/createQueryController.d.ts.map +0 -1
- package/dist/createQueryController.js +0 -238
- package/dist/createQueryController.js.map +0 -1
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/infiniteQueryOptions.d.ts +0 -21
- package/dist/infiniteQueryOptions.d.ts.map +0 -1
- package/dist/infiniteQueryOptions.js +0 -22
- package/dist/infiniteQueryOptions.js.map +0 -1
- package/dist/mutationOptions.d.ts +0 -19
- package/dist/mutationOptions.d.ts.map +0 -1
- package/dist/mutationOptions.js +0 -20
- package/dist/mutationOptions.js.map +0 -1
- package/dist/queryObserverResultTracker.d.ts +0 -14
- package/dist/queryObserverResultTracker.d.ts.map +0 -1
- package/dist/queryObserverResultTracker.js +0 -18
- package/dist/queryObserverResultTracker.js.map +0 -1
- package/dist/queryOptions.d.ts +0 -62
- package/dist/queryOptions.d.ts.map +0 -1
- package/dist/queryOptions.js +0 -4
- package/dist/queryOptions.js.map +0 -1
- package/dist/types.d.ts +0 -31
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/useIsFetching.d.ts +0 -45
- package/dist/useIsFetching.d.ts.map +0 -1
- package/dist/useIsFetching.js +0 -116
- package/dist/useIsFetching.js.map +0 -1
- package/dist/useIsMutating.d.ts +0 -45
- package/dist/useIsMutating.d.ts.map +0 -1
- package/dist/useIsMutating.js +0 -116
- package/dist/useIsMutating.js.map +0 -1
- package/dist/useMutationState.d.ts +0 -57
- package/dist/useMutationState.d.ts.map +0 -1
- package/dist/useMutationState.js +0 -136
- package/dist/useMutationState.js.map +0 -1
- package/dist-cjs/QueryClientProvider.d.cts +0 -84
- package/dist-cjs/QueryClientProvider.js +0 -141
- package/dist-cjs/QueryClientProvider.js.map +0 -1
- package/dist-cjs/accessor.d.cts +0 -31
- package/dist-cjs/accessor.js +0 -16
- package/dist-cjs/accessor.js.map +0 -1
- package/dist-cjs/context.d.cts +0 -58
- package/dist-cjs/context.js +0 -109
- package/dist-cjs/context.js.map +0 -1
- package/dist-cjs/controllers/BaseController.d.cts +0 -38
- package/dist-cjs/controllers/BaseController.js +0 -217
- package/dist-cjs/controllers/BaseController.js.map +0 -1
- package/dist-cjs/createInfiniteQueryController.d.cts +0 -75
- package/dist-cjs/createInfiniteQueryController.js +0 -251
- package/dist-cjs/createInfiniteQueryController.js.map +0 -1
- package/dist-cjs/createMutationController.d.cts +0 -78
- package/dist-cjs/createMutationController.js +0 -196
- package/dist-cjs/createMutationController.js.map +0 -1
- package/dist-cjs/createQueriesController.d.cts +0 -144
- package/dist-cjs/createQueriesController.js +0 -370
- package/dist-cjs/createQueriesController.js.map +0 -1
- package/dist-cjs/createQueryController.d.cts +0 -66
- package/dist-cjs/createQueryController.js +0 -241
- package/dist-cjs/createQueryController.js.map +0 -1
- package/dist-cjs/index.d.cts +0 -23
- package/dist-cjs/index.js +0 -49
- package/dist-cjs/index.js.map +0 -1
- package/dist-cjs/infiniteQueryOptions.d.cts +0 -20
- package/dist-cjs/infiniteQueryOptions.js +0 -25
- package/dist-cjs/infiniteQueryOptions.js.map +0 -1
- package/dist-cjs/mutationOptions.d.cts +0 -18
- package/dist-cjs/mutationOptions.js +0 -23
- package/dist-cjs/mutationOptions.js.map +0 -1
- package/dist-cjs/package.json +0 -3
- package/dist-cjs/queryObserverResultTracker.d.cts +0 -13
- package/dist-cjs/queryObserverResultTracker.js +0 -22
- package/dist-cjs/queryObserverResultTracker.js.map +0 -1
- package/dist-cjs/queryOptions.d.cts +0 -61
- package/dist-cjs/queryOptions.js +0 -7
- package/dist-cjs/queryOptions.js.map +0 -1
- package/dist-cjs/types.d.cts +0 -30
- package/dist-cjs/types.js +0 -3
- package/dist-cjs/types.js.map +0 -1
- package/dist-cjs/useIsFetching.d.cts +0 -44
- package/dist-cjs/useIsFetching.js +0 -119
- package/dist-cjs/useIsFetching.js.map +0 -1
- package/dist-cjs/useIsMutating.d.cts +0 -44
- package/dist-cjs/useIsMutating.js +0 -119
- package/dist-cjs/useIsMutating.js.map +0 -1
- package/dist-cjs/useMutationState.d.cts +0 -56
- package/dist-cjs/useMutationState.js +0 -139
- package/dist-cjs/useMutationState.js.map +0 -1
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
import { DataTag, DefaultError, DefinedQueryObserverResult, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, InitialDataFunction, MutateFunction, Mutation, MutationFilters, MutationObserverOptions, MutationObserverResult, MutationState, NonUndefinedGuard, OmitKeyof, QueryClient, QueryFilters, QueryFunction, QueryKey, QueryObserverOptions, QueryObserverResult, SkipToken, ThrowOnError } from "@tanstack/query-core";
|
|
2
|
+
import { LitElement, ReactiveControllerHost, TemplateResult } from "lit";
|
|
3
|
+
export * from "@tanstack/query-core";
|
|
4
|
+
//#region src/accessor.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A value that can be passed directly or read from a zero-argument getter.
|
|
7
|
+
*
|
|
8
|
+
* Lit Query APIs read function accessors during host updates, so the getter can
|
|
9
|
+
* depend on reactive host state.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const staticKey: Accessor<readonly unknown[]> = ['todos']
|
|
14
|
+
* const reactiveKey: Accessor<readonly unknown[]> = () => ['todos', this.userId]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type Accessor<T> = T | (() => T);
|
|
18
|
+
/**
|
|
19
|
+
* A callable accessor with a `current` property for reading the latest
|
|
20
|
+
* controller result.
|
|
21
|
+
*
|
|
22
|
+
* Controller creators and cache state helpers return this shape so render code
|
|
23
|
+
* can use either `result()` or `result.current`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const query = this.todos()
|
|
28
|
+
* const sameQuery = this.todos.current
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
type ValueAccessor<T> = (() => T) & {
|
|
32
|
+
readonly current: T;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/context.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Lit context key used by `QueryClientProvider` and host-bound APIs to share a
|
|
38
|
+
* `QueryClient` through the DOM tree.
|
|
39
|
+
*
|
|
40
|
+
* Most applications use `QueryClientProvider` instead of interacting with this
|
|
41
|
+
* context directly.
|
|
42
|
+
*/
|
|
43
|
+
declare const queryClientContext: {
|
|
44
|
+
__context__: QueryClient;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Registers a `QueryClient` as a process-local fallback for APIs that resolve a
|
|
48
|
+
* client without an explicit argument.
|
|
49
|
+
*
|
|
50
|
+
* `QueryClientProvider` calls this automatically while it is connected. Prefer
|
|
51
|
+
* passing an explicit client or rendering under a provider when possible.
|
|
52
|
+
*
|
|
53
|
+
* @param client - The query client to register as the current default.
|
|
54
|
+
*/
|
|
55
|
+
declare function registerDefaultQueryClient(client: QueryClient): void;
|
|
56
|
+
/**
|
|
57
|
+
* Unregisters a client previously registered with
|
|
58
|
+
* `registerDefaultQueryClient`.
|
|
59
|
+
*
|
|
60
|
+
* `QueryClientProvider` calls this automatically when it disconnects.
|
|
61
|
+
*
|
|
62
|
+
* @param client - The query client registration to release.
|
|
63
|
+
*/
|
|
64
|
+
declare function unregisterDefaultQueryClient(client: QueryClient): void;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the registered default `QueryClient`, if exactly one default client is
|
|
67
|
+
* available.
|
|
68
|
+
*
|
|
69
|
+
* @returns The default query client, or `undefined` when there is no registered
|
|
70
|
+
* client or more than one registered client.
|
|
71
|
+
*/
|
|
72
|
+
declare function getDefaultQueryClient(): QueryClient | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Resolves the current default `QueryClient` registered by a connected
|
|
75
|
+
* `QueryClientProvider`.
|
|
76
|
+
*
|
|
77
|
+
* This helper is useful outside a Lit reactive controller when a single
|
|
78
|
+
* provider is mounted. It throws if no client is registered or if multiple
|
|
79
|
+
* clients are mounted and the default would be ambiguous.
|
|
80
|
+
*
|
|
81
|
+
* @returns The single registered query client.
|
|
82
|
+
*/
|
|
83
|
+
declare function useQueryClient(): QueryClient;
|
|
84
|
+
/**
|
|
85
|
+
* Resolves an explicit `QueryClient` or falls back to `useQueryClient`.
|
|
86
|
+
*
|
|
87
|
+
* @param explicit - Optional client supplied by the caller.
|
|
88
|
+
* @returns The explicit client when provided, otherwise the current default
|
|
89
|
+
* client.
|
|
90
|
+
*/
|
|
91
|
+
declare function resolveQueryClient(explicit?: QueryClient): QueryClient;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/QueryClientProvider.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Lit element that provides a `QueryClient` to descendant Lit Query
|
|
96
|
+
* controllers through Lit context.
|
|
97
|
+
*
|
|
98
|
+
* The `client` is a property, not an attribute. When rendering this element in
|
|
99
|
+
* a Lit template, bind it with property binding: `.client=${queryClient}`.
|
|
100
|
+
* The provider throws if it connects without a client, or if an already
|
|
101
|
+
* connected provider has its client cleared.
|
|
102
|
+
*
|
|
103
|
+
* This class is not registered as a custom element by the package. Applications
|
|
104
|
+
* must register either a subclass or the class itself with
|
|
105
|
+
* `customElements.define`.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { html, LitElement } from 'lit'
|
|
110
|
+
* import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
|
|
111
|
+
*
|
|
112
|
+
* const queryClient = new QueryClient()
|
|
113
|
+
*
|
|
114
|
+
* class AppQueryProvider extends QueryClientProvider {
|
|
115
|
+
* constructor() {
|
|
116
|
+
* super()
|
|
117
|
+
* this.client = queryClient
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
*
|
|
121
|
+
* customElements.define('app-query-provider', AppQueryProvider)
|
|
122
|
+
*
|
|
123
|
+
* class AppRoot extends LitElement {
|
|
124
|
+
* render() {
|
|
125
|
+
* return html`<app-query-provider><todos-view></todos-view></app-query-provider>`
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { html } from 'lit'
|
|
133
|
+
* import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
|
|
134
|
+
*
|
|
135
|
+
* const queryClient = new QueryClient()
|
|
136
|
+
*
|
|
137
|
+
* customElements.define('query-client-provider', QueryClientProvider)
|
|
138
|
+
*
|
|
139
|
+
* const view = html`
|
|
140
|
+
* <query-client-provider .client=${queryClient}>
|
|
141
|
+
* <todos-view></todos-view>
|
|
142
|
+
* </query-client-provider>
|
|
143
|
+
* `
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare class QueryClientProvider extends LitElement {
|
|
147
|
+
/** @internal */
|
|
148
|
+
static properties: {
|
|
149
|
+
client: {
|
|
150
|
+
attribute: boolean;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* The `QueryClient` provided to descendant controllers and global fallback
|
|
155
|
+
* helpers while this provider is connected.
|
|
156
|
+
*
|
|
157
|
+
* Bind this as a property in Lit templates with `.client=${queryClient}`.
|
|
158
|
+
*/
|
|
159
|
+
client: QueryClient;
|
|
160
|
+
private readonly contextProvider;
|
|
161
|
+
private mountedClient;
|
|
162
|
+
constructor();
|
|
163
|
+
/** @internal */
|
|
164
|
+
connectedCallback(): void;
|
|
165
|
+
/** @internal */
|
|
166
|
+
disconnectedCallback(): void;
|
|
167
|
+
/** @internal */
|
|
168
|
+
protected willUpdate(changedProperties: Map<PropertyKey, unknown>): void;
|
|
169
|
+
/** @internal */
|
|
170
|
+
render(): TemplateResult;
|
|
171
|
+
private mountClient;
|
|
172
|
+
private unmountClient;
|
|
173
|
+
private requireClient;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/createInfiniteQueryController.d.ts
|
|
177
|
+
/**
|
|
178
|
+
* Options accepted by `createInfiniteQueryController`.
|
|
179
|
+
*
|
|
180
|
+
* This is the Lit adapter shape for `InfiniteQueryObserverOptions`. Pass it
|
|
181
|
+
* directly or through an `Accessor` when the options depend on Lit host state.
|
|
182
|
+
*/
|
|
183
|
+
type CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>;
|
|
184
|
+
/**
|
|
185
|
+
* Accessor returned by `createInfiniteQueryController`.
|
|
186
|
+
*
|
|
187
|
+
* Call the accessor or read its `current` property to get the latest infinite
|
|
188
|
+
* query result. The attached methods delegate to the active infinite query
|
|
189
|
+
* observer.
|
|
190
|
+
*/
|
|
191
|
+
type InfiniteQueryResultAccessor<TData, TError> = ValueAccessor<InfiniteQueryObserverResult<TData, TError>> & {
|
|
192
|
+
/** Refetches the current infinite query. */
|
|
193
|
+
refetch: InfiniteQueryObserverResult<TData, TError>['refetch'];
|
|
194
|
+
/** Fetches the next page for the current infinite query. */
|
|
195
|
+
fetchNextPage: InfiniteQueryObserverResult<TData, TError>['fetchNextPage'];
|
|
196
|
+
/** Fetches the previous page for the current infinite query. */
|
|
197
|
+
fetchPreviousPage: InfiniteQueryObserverResult<TData, TError>['fetchPreviousPage'];
|
|
198
|
+
/** Removes the controller from its Lit host and unsubscribes observers. */
|
|
199
|
+
destroy: () => void;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Creates a Lit reactive controller that subscribes the host to an infinite
|
|
203
|
+
* query.
|
|
204
|
+
*
|
|
205
|
+
* The returned accessor is callable and also exposes `current`, `refetch`,
|
|
206
|
+
* `fetchNextPage`, `fetchPreviousPage`, and `destroy`. When `options` is a
|
|
207
|
+
* function, it is re-read during host updates so query keys and options can
|
|
208
|
+
* follow reactive host state.
|
|
209
|
+
*
|
|
210
|
+
* If `queryClient` is omitted, the controller resolves the client from the
|
|
211
|
+
* nearest connected `QueryClientProvider`.
|
|
212
|
+
*
|
|
213
|
+
* @param host - The Lit reactive controller host that owns the infinite query
|
|
214
|
+
* subscription.
|
|
215
|
+
* @param options - Infinite query observer options, or a getter that returns
|
|
216
|
+
* options.
|
|
217
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
218
|
+
* controllers that should not resolve a client from Lit context.
|
|
219
|
+
* @returns An accessor for the latest infinite query result with page helper
|
|
220
|
+
* methods.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* import { LitElement, html } from 'lit'
|
|
225
|
+
* import { createInfiniteQueryController } from '@tanstack/lit-query'
|
|
226
|
+
*
|
|
227
|
+
* class ProjectsView extends LitElement {
|
|
228
|
+
* private readonly projects = createInfiniteQueryController(this, {
|
|
229
|
+
* queryKey: ['projects'],
|
|
230
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
231
|
+
* initialPageParam: 0,
|
|
232
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
233
|
+
* })
|
|
234
|
+
*
|
|
235
|
+
* render() {
|
|
236
|
+
* const query = this.projects()
|
|
237
|
+
*
|
|
238
|
+
* return html`
|
|
239
|
+
* <button ?disabled=${!query.hasNextPage} @click=${() => this.projects.fetchNextPage()}>
|
|
240
|
+
* Load more
|
|
241
|
+
* </button>
|
|
242
|
+
* `
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
declare function createInfiniteQueryController<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(host: ReactiveControllerHost, options: Accessor<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: QueryClient): InfiniteQueryResultAccessor<TData, TError>;
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/createMutationController.d.ts
|
|
250
|
+
/**
|
|
251
|
+
* Options accepted by `createMutationController`.
|
|
252
|
+
*
|
|
253
|
+
* This is the Lit adapter shape for `MutationObserverOptions`. Pass it directly
|
|
254
|
+
* or through an `Accessor` when the options depend on Lit host state.
|
|
255
|
+
*/
|
|
256
|
+
type CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>;
|
|
257
|
+
/**
|
|
258
|
+
* Accessor returned by `createMutationController`.
|
|
259
|
+
*
|
|
260
|
+
* Call the accessor or read its `current` property to get the latest mutation
|
|
261
|
+
* result. The attached methods delegate to the active mutation observer.
|
|
262
|
+
*/
|
|
263
|
+
type MutationResultAccessor<TData, TError, TVariables, TOnMutateResult> = ValueAccessor<MutationObserverResult<TData, TError, TVariables, TOnMutateResult>> & {
|
|
264
|
+
/**
|
|
265
|
+
* Starts the mutation and swallows the returned promise.
|
|
266
|
+
*
|
|
267
|
+
* Throws synchronously if no `QueryClient` can be resolved.
|
|
268
|
+
*/
|
|
269
|
+
mutate: (...args: Parameters<MutateFunction<TData, TError, TVariables, TOnMutateResult>>) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Starts the mutation and returns the observer promise.
|
|
272
|
+
*
|
|
273
|
+
* Rejects if no `QueryClient` can be resolved.
|
|
274
|
+
*/
|
|
275
|
+
mutateAsync: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>['mutate'];
|
|
276
|
+
/** Resets the mutation observer to its idle state. */
|
|
277
|
+
reset: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>['reset'];
|
|
278
|
+
/** Removes the controller from its Lit host and unsubscribes observers. */
|
|
279
|
+
destroy: () => void;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Creates a Lit reactive controller that subscribes the host to a mutation.
|
|
283
|
+
*
|
|
284
|
+
* The returned accessor is callable and also exposes `current`, `mutate`,
|
|
285
|
+
* `mutateAsync`, `reset`, and `destroy`. When `options` is a function, it is
|
|
286
|
+
* re-read during host updates so mutation options can follow reactive host
|
|
287
|
+
* state.
|
|
288
|
+
*
|
|
289
|
+
* If `queryClient` is omitted, the controller resolves the client from the
|
|
290
|
+
* nearest connected `QueryClientProvider`.
|
|
291
|
+
*
|
|
292
|
+
* @param host - The Lit reactive controller host that owns the mutation
|
|
293
|
+
* subscription.
|
|
294
|
+
* @param options - Mutation observer options, or a getter that returns options.
|
|
295
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
296
|
+
* controllers that should not resolve a client from Lit context.
|
|
297
|
+
* @returns An accessor for the latest mutation result with mutation helper
|
|
298
|
+
* methods.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { LitElement, html } from 'lit'
|
|
303
|
+
* import { createMutationController } from '@tanstack/lit-query'
|
|
304
|
+
*
|
|
305
|
+
* class AddTodoForm extends LitElement {
|
|
306
|
+
* private readonly addTodo = createMutationController(this, {
|
|
307
|
+
* mutationFn: (title: string) =>
|
|
308
|
+
* fetch('/api/todos', { method: 'POST', body: JSON.stringify({ title }) }),
|
|
309
|
+
* })
|
|
310
|
+
*
|
|
311
|
+
* render() {
|
|
312
|
+
* const mutation = this.addTodo()
|
|
313
|
+
*
|
|
314
|
+
* return html`
|
|
315
|
+
* <button ?disabled=${mutation.isPending} @click=${() => this.addTodo.mutate('Ship docs')}>
|
|
316
|
+
* Add todo
|
|
317
|
+
* </button>
|
|
318
|
+
* `
|
|
319
|
+
* }
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
declare function createMutationController<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>(host: ReactiveControllerHost, options: Accessor<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>>, queryClient?: QueryClient): MutationResultAccessor<TData, TError, TVariables, TOnMutateResult>;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/createQueriesController.d.ts
|
|
326
|
+
/**
|
|
327
|
+
* Options for one query inside `createQueriesController`.
|
|
328
|
+
*
|
|
329
|
+
* This mirrors `QueryObserverOptions` and is used by the tuple inference that
|
|
330
|
+
* maps each input query to its corresponding result.
|
|
331
|
+
*/
|
|
332
|
+
type CreateQueriesInput<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>;
|
|
333
|
+
type CreateQueriesInputForController<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueriesInput<TQueryFnData, TError, TData, TQueryKey>, never>;
|
|
334
|
+
type MAXIMUM_DEPTH = 20;
|
|
335
|
+
type SkipTokenForCreateQueries = symbol;
|
|
336
|
+
type GetCreateQueriesInput<T> = T extends {
|
|
337
|
+
queryFnData: infer TQueryFnData;
|
|
338
|
+
error?: infer TError;
|
|
339
|
+
data: infer TData;
|
|
340
|
+
} ? CreateQueriesInputForController<TQueryFnData, TError, TData> : T extends {
|
|
341
|
+
queryFnData: infer TQueryFnData;
|
|
342
|
+
error?: infer TError;
|
|
343
|
+
} ? CreateQueriesInputForController<TQueryFnData, TError> : T extends {
|
|
344
|
+
data: infer TData;
|
|
345
|
+
error?: infer TError;
|
|
346
|
+
} ? CreateQueriesInputForController<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? CreateQueriesInputForController<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? CreateQueriesInputForController<TQueryFnData, TError> : T extends [infer TQueryFnData] ? CreateQueriesInputForController<TQueryFnData> : T extends {
|
|
347
|
+
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipTokenForCreateQueries;
|
|
348
|
+
select?: (data: any) => infer TData;
|
|
349
|
+
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
350
|
+
} ? CreateQueriesInputForController<TQueryFnData, unknown extends TError ? DefaultError : TError, unknown extends TData ? TQueryFnData : TData, TQueryKey> : CreateQueriesInputForController;
|
|
351
|
+
type GetDefinedOrUndefinedCreateQueriesResult<T, TData, TError = unknown> = T extends {
|
|
352
|
+
initialData?: infer TInitialData;
|
|
353
|
+
} ? unknown extends TInitialData ? QueryObserverResult<TData, TError> : TInitialData extends TData ? DefinedQueryObserverResult<TData, TError> : TInitialData extends (() => infer TInitialDataResult) ? unknown extends TInitialDataResult ? QueryObserverResult<TData, TError> : TInitialDataResult extends TData ? DefinedQueryObserverResult<TData, TError> : QueryObserverResult<TData, TError> : QueryObserverResult<TData, TError> : QueryObserverResult<TData, TError>;
|
|
354
|
+
type GetCreateQueriesResult<T> = T extends {
|
|
355
|
+
queryFnData: any;
|
|
356
|
+
error?: infer TError;
|
|
357
|
+
data: infer TData;
|
|
358
|
+
} ? GetDefinedOrUndefinedCreateQueriesResult<T, TData, TError> : T extends {
|
|
359
|
+
queryFnData: infer TQueryFnData;
|
|
360
|
+
error?: infer TError;
|
|
361
|
+
} ? GetDefinedOrUndefinedCreateQueriesResult<T, TQueryFnData, TError> : T extends {
|
|
362
|
+
data: infer TData;
|
|
363
|
+
error?: infer TError;
|
|
364
|
+
} ? GetDefinedOrUndefinedCreateQueriesResult<T, TData, TError> : T extends [any, infer TError, infer TData] ? GetDefinedOrUndefinedCreateQueriesResult<T, TData, TError> : T extends [infer TQueryFnData, infer TError] ? GetDefinedOrUndefinedCreateQueriesResult<T, TQueryFnData, TError> : T extends [infer TQueryFnData] ? GetDefinedOrUndefinedCreateQueriesResult<T, TQueryFnData> : T extends {
|
|
365
|
+
queryFn?: QueryFunction<infer TQueryFnData, any> | SkipTokenForCreateQueries;
|
|
366
|
+
select?: (data: any) => infer TData;
|
|
367
|
+
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
368
|
+
} ? GetDefinedOrUndefinedCreateQueriesResult<T, unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError> : QueryObserverResult;
|
|
369
|
+
type CreateQueriesOptions<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueriesInputForController> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetCreateQueriesInput<Head>] : T extends [infer Head, ...infer Tails] ? CreateQueriesOptions<[...Tails], [...TResults, GetCreateQueriesInput<Head>], [...TDepth, 1]> : ReadonlyArray<unknown> extends T ? T : T extends Array<CreateQueriesInputForController<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<CreateQueriesInputForController<TQueryFnData, TError, TData, TQueryKey>> : Array<CreateQueriesInputForController>;
|
|
370
|
+
/**
|
|
371
|
+
* Tuple of query results inferred from the query inputs passed to
|
|
372
|
+
* `createQueriesController`.
|
|
373
|
+
*/
|
|
374
|
+
type CreateQueriesResults<T extends Array<any>, TResults extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<QueryObserverResult> : T extends [] ? [] : T extends [infer Head] ? [...TResults, GetCreateQueriesResult<Head>] : T extends [infer Head, ...infer Tails] ? CreateQueriesResults<[...Tails], [...TResults, GetCreateQueriesResult<Head>], [...TDepth, 1]> : { [K in keyof T]: GetCreateQueriesResult<T[K]>; };
|
|
375
|
+
/**
|
|
376
|
+
* Options accepted by `createQueriesController`.
|
|
377
|
+
*
|
|
378
|
+
* `queries` can be a static list or a getter that returns the current list.
|
|
379
|
+
* `combine` can reshape the array of query results into a single value for the
|
|
380
|
+
* returned accessor.
|
|
381
|
+
*/
|
|
382
|
+
type CreateQueriesControllerOptions<TQueryOptions extends Array<any> = Array<any>, TCombinedResult = CreateQueriesResults<TQueryOptions>> = {
|
|
383
|
+
/** Query options to observe, or a getter that returns the current options. */
|
|
384
|
+
queries: Accessor<readonly [...CreateQueriesOptions<TQueryOptions>] | readonly [...{ [K in keyof TQueryOptions]: GetCreateQueriesInput<TQueryOptions[K]>; }]>;
|
|
385
|
+
/** Optional function that combines the query result array into one value. */
|
|
386
|
+
combine?: (result: CreateQueriesResults<TQueryOptions>) => TCombinedResult;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* Accessor returned by `createQueriesController`.
|
|
390
|
+
*
|
|
391
|
+
* Call the accessor or read its `current` property to get the latest combined
|
|
392
|
+
* value.
|
|
393
|
+
*/
|
|
394
|
+
type QueriesResultAccessor<TCombinedResult> = ValueAccessor<TCombinedResult> & {
|
|
395
|
+
/** Removes the controller from its Lit host and unsubscribes observers. */
|
|
396
|
+
destroy: () => void;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Creates a Lit reactive controller that subscribes the host to multiple
|
|
400
|
+
* queries.
|
|
401
|
+
*
|
|
402
|
+
* The returned accessor is callable and also exposes `current` and `destroy`.
|
|
403
|
+
* When `options` or `options.queries` is a function, it is re-read during host
|
|
404
|
+
* updates so the query list can follow reactive host state.
|
|
405
|
+
*
|
|
406
|
+
* If `queryClient` is omitted, the controller resolves the client from the
|
|
407
|
+
* nearest connected `QueryClientProvider`.
|
|
408
|
+
*
|
|
409
|
+
* @param host - The Lit reactive controller host that owns the queries
|
|
410
|
+
* subscription.
|
|
411
|
+
* @param options - Queries controller options, or a getter that returns options.
|
|
412
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
413
|
+
* controllers that should not resolve a client from Lit context.
|
|
414
|
+
* @returns An accessor for the latest query results, or the value returned by
|
|
415
|
+
* `combine`.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* import { LitElement, html } from 'lit'
|
|
420
|
+
* import { createQueriesController } from '@tanstack/lit-query'
|
|
421
|
+
*
|
|
422
|
+
* class DashboardView extends LitElement {
|
|
423
|
+
* private readonly dashboard = createQueriesController(this, {
|
|
424
|
+
* queries: [
|
|
425
|
+
* { queryKey: ['stats'], queryFn: fetchStats },
|
|
426
|
+
* { queryKey: ['projects'], queryFn: fetchProjects },
|
|
427
|
+
* ],
|
|
428
|
+
* combine: ([stats, projects]) => ({
|
|
429
|
+
* stats: stats.data,
|
|
430
|
+
* projects: projects.data ?? [],
|
|
431
|
+
* isPending: stats.isPending || projects.isPending,
|
|
432
|
+
* }),
|
|
433
|
+
* })
|
|
434
|
+
*
|
|
435
|
+
* render() {
|
|
436
|
+
* const dashboard = this.dashboard()
|
|
437
|
+
* return html`<p>Projects: ${dashboard.projects.length}</p>`
|
|
438
|
+
* }
|
|
439
|
+
* }
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare function createQueriesController<TQueryOptions extends Array<any>, TCombinedResult = CreateQueriesResults<TQueryOptions>>(host: ReactiveControllerHost, options: Accessor<CreateQueriesControllerOptions<TQueryOptions, TCombinedResult>>, queryClient?: QueryClient): QueriesResultAccessor<TCombinedResult>;
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/createQueryController.d.ts
|
|
445
|
+
/**
|
|
446
|
+
* Options accepted by `createQueryController`.
|
|
447
|
+
*
|
|
448
|
+
* This is the Lit adapter shape for `QueryObserverOptions`. It can be passed
|
|
449
|
+
* directly to `createQueryController`, or wrapped in an `Accessor` when the
|
|
450
|
+
* options depend on Lit host state.
|
|
451
|
+
*/
|
|
452
|
+
type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
|
|
453
|
+
/**
|
|
454
|
+
* Accessor returned by `createQueryController`.
|
|
455
|
+
*
|
|
456
|
+
* Call the accessor or read its `current` property to get the latest query
|
|
457
|
+
* result. The attached methods delegate to the active query observer.
|
|
458
|
+
*/
|
|
459
|
+
type QueryResultAccessor<TData, TError> = ValueAccessor<QueryObserverResult<TData, TError>> & {
|
|
460
|
+
/** Refetches the current query. */
|
|
461
|
+
refetch: QueryObserverResult<TData, TError>['refetch'];
|
|
462
|
+
/** Resolves with an optimistic query result, fetching first when needed. */
|
|
463
|
+
suspense: () => Promise<QueryObserverResult<TData, TError>>;
|
|
464
|
+
/** Removes the controller from its Lit host and unsubscribes observers. */
|
|
465
|
+
destroy: () => void;
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* Creates a Lit reactive controller that subscribes the host to a single query.
|
|
469
|
+
*
|
|
470
|
+
* The returned accessor is callable and also exposes `current`, `refetch`,
|
|
471
|
+
* `suspense`, and `destroy`. When `options` is a function, it is re-read during
|
|
472
|
+
* host updates so query keys and options can follow reactive host state.
|
|
473
|
+
*
|
|
474
|
+
* If `queryClient` is omitted, the controller resolves the client from the
|
|
475
|
+
* nearest connected `QueryClientProvider`.
|
|
476
|
+
*
|
|
477
|
+
* @param host - The Lit reactive controller host that owns the query
|
|
478
|
+
* subscription.
|
|
479
|
+
* @param options - Query observer options, or a getter that returns options.
|
|
480
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
481
|
+
* controllers that should not resolve a client from Lit context.
|
|
482
|
+
* @returns An accessor for the latest query result with query helper methods.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* import { LitElement, html } from 'lit'
|
|
487
|
+
* import { createQueryController } from '@tanstack/lit-query'
|
|
488
|
+
*
|
|
489
|
+
* class TodosView extends LitElement {
|
|
490
|
+
* private readonly todos = createQueryController(this, {
|
|
491
|
+
* queryKey: ['todos'],
|
|
492
|
+
* queryFn: async () => fetch('/api/todos').then((r) => r.json()),
|
|
493
|
+
* })
|
|
494
|
+
*
|
|
495
|
+
* render() {
|
|
496
|
+
* const query = this.todos()
|
|
497
|
+
*
|
|
498
|
+
* if (query.isPending) return html`Loading...`
|
|
499
|
+
* if (query.isError) return html`Error`
|
|
500
|
+
*
|
|
501
|
+
* return html`<ul>${query.data.map((todo) => html`<li>${todo.title}</li>`)}</ul>`
|
|
502
|
+
* }
|
|
503
|
+
* }
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
declare function createQueryController<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(host: ReactiveControllerHost, options: Accessor<CreateQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, queryClient?: QueryClient): QueryResultAccessor<TData, TError>;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/useIsFetching.d.ts
|
|
509
|
+
/**
|
|
510
|
+
* Accessor returned by `useIsFetching`.
|
|
511
|
+
*
|
|
512
|
+
* Call the accessor or read its `current` property to get the number of
|
|
513
|
+
* currently fetching queries that match the filters.
|
|
514
|
+
*/
|
|
515
|
+
type IsFetchingAccessor = ValueAccessor<number> & {
|
|
516
|
+
destroy: () => void;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* Creates a Lit reactive controller that tracks how many matching queries are
|
|
520
|
+
* currently fetching.
|
|
521
|
+
*
|
|
522
|
+
* When `filters` is a function, it is re-read during host updates so the count
|
|
523
|
+
* can follow reactive host state. If `queryClient` is omitted, the controller
|
|
524
|
+
* resolves the client from the nearest connected `QueryClientProvider`.
|
|
525
|
+
*
|
|
526
|
+
* @param host - The Lit reactive controller host that owns the cache
|
|
527
|
+
* subscription.
|
|
528
|
+
* @param filters - Query filters, or a getter that returns query filters.
|
|
529
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
530
|
+
* controllers that should not resolve a client from Lit context.
|
|
531
|
+
* @returns An accessor for the current number of matching fetching queries.
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```ts
|
|
535
|
+
* import { LitElement, html } from 'lit'
|
|
536
|
+
* import { useIsFetching } from '@tanstack/lit-query'
|
|
537
|
+
*
|
|
538
|
+
* class TodosStatus extends LitElement {
|
|
539
|
+
* private readonly todosFetching = useIsFetching(this, {
|
|
540
|
+
* queryKey: ['todos'],
|
|
541
|
+
* })
|
|
542
|
+
*
|
|
543
|
+
* render() {
|
|
544
|
+
* return html`<span>${this.todosFetching()} active todo fetches</span>`
|
|
545
|
+
* }
|
|
546
|
+
* }
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
declare function useIsFetching(host: ReactiveControllerHost, filters?: Accessor<QueryFilters>, queryClient?: QueryClient): IsFetchingAccessor;
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/useIsMutating.d.ts
|
|
552
|
+
/**
|
|
553
|
+
* Accessor returned by `useIsMutating`.
|
|
554
|
+
*
|
|
555
|
+
* Call the accessor or read its `current` property to get the number of
|
|
556
|
+
* currently pending mutations that match the filters.
|
|
557
|
+
*/
|
|
558
|
+
type IsMutatingAccessor = ValueAccessor<number> & {
|
|
559
|
+
destroy: () => void;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* Creates a Lit reactive controller that tracks how many matching mutations are
|
|
563
|
+
* currently pending.
|
|
564
|
+
*
|
|
565
|
+
* When `filters` is a function, it is re-read during host updates so the count
|
|
566
|
+
* can follow reactive host state. If `queryClient` is omitted, the controller
|
|
567
|
+
* resolves the client from the nearest connected `QueryClientProvider`.
|
|
568
|
+
*
|
|
569
|
+
* @param host - The Lit reactive controller host that owns the cache
|
|
570
|
+
* subscription.
|
|
571
|
+
* @param filters - Mutation filters, or a getter that returns mutation filters.
|
|
572
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
573
|
+
* controllers that should not resolve a client from Lit context.
|
|
574
|
+
* @returns An accessor for the current number of matching pending mutations.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```ts
|
|
578
|
+
* import { LitElement, html } from 'lit'
|
|
579
|
+
* import { useIsMutating } from '@tanstack/lit-query'
|
|
580
|
+
*
|
|
581
|
+
* class MutationStatus extends LitElement {
|
|
582
|
+
* private readonly savesPending = useIsMutating(this, {
|
|
583
|
+
* mutationKey: ['save-project'],
|
|
584
|
+
* })
|
|
585
|
+
*
|
|
586
|
+
* render() {
|
|
587
|
+
* return html`<span>${this.savesPending()} saves pending</span>`
|
|
588
|
+
* }
|
|
589
|
+
* }
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
declare function useIsMutating(host: ReactiveControllerHost, filters?: Accessor<MutationFilters>, queryClient?: QueryClient): IsMutatingAccessor;
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/useMutationState.d.ts
|
|
595
|
+
/**
|
|
596
|
+
* Options accepted by `useMutationState`.
|
|
597
|
+
*/
|
|
598
|
+
type MutationStateOptions<TResult> = {
|
|
599
|
+
/** Filters used to select mutations from the mutation cache. */
|
|
600
|
+
filters?: Accessor<MutationFilters>;
|
|
601
|
+
/** Maps each matching mutation to the value returned by the accessor. */
|
|
602
|
+
select?: (mutation: Mutation) => TResult;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Accessor returned by `useMutationState`.
|
|
606
|
+
*
|
|
607
|
+
* Call the accessor or read its `current` property to get the selected state for
|
|
608
|
+
* matching mutations.
|
|
609
|
+
*/
|
|
610
|
+
type MutationStateAccessor<TResult> = ValueAccessor<TResult[]> & {
|
|
611
|
+
/** Removes the controller from its Lit host and unsubscribes observers. */
|
|
612
|
+
destroy: () => void;
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Creates a Lit reactive controller that selects state from matching mutations
|
|
616
|
+
* in the mutation cache.
|
|
617
|
+
*
|
|
618
|
+
* When `options.filters` is a function, it is re-read during host updates so
|
|
619
|
+
* the selection can follow reactive host state. If `queryClient` is omitted,
|
|
620
|
+
* the controller resolves the client from the nearest connected
|
|
621
|
+
* `QueryClientProvider`.
|
|
622
|
+
*
|
|
623
|
+
* @param host - The Lit reactive controller host that owns the mutation cache
|
|
624
|
+
* subscription.
|
|
625
|
+
* @param options - Mutation state filters and optional selector.
|
|
626
|
+
* @param queryClient - Optional explicit query client. Provide this for
|
|
627
|
+
* controllers that should not resolve a client from Lit context.
|
|
628
|
+
* @returns An accessor for the selected mutation state array.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```ts
|
|
632
|
+
* import { LitElement, html } from 'lit'
|
|
633
|
+
* import { useMutationState } from '@tanstack/lit-query'
|
|
634
|
+
*
|
|
635
|
+
* class PendingUploads extends LitElement {
|
|
636
|
+
* private readonly uploads = useMutationState(this, {
|
|
637
|
+
* filters: { mutationKey: ['upload'], status: 'pending' },
|
|
638
|
+
* select: (mutation) => mutation.state.variables as File,
|
|
639
|
+
* })
|
|
640
|
+
*
|
|
641
|
+
* render() {
|
|
642
|
+
* return html`<span>${this.uploads().length} uploads pending</span>`
|
|
643
|
+
* }
|
|
644
|
+
* }
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function useMutationState<TResult = MutationState<unknown, unknown, unknown, unknown>>(host: ReactiveControllerHost, options?: MutationStateOptions<TResult>, queryClient?: QueryClient): MutationStateAccessor<TResult>;
|
|
648
|
+
//#endregion
|
|
649
|
+
//#region src/queryOptions.d.ts
|
|
650
|
+
/**
|
|
651
|
+
* Query options with `initialData` that guarantees defined query data.
|
|
652
|
+
*/
|
|
653
|
+
type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'queryFn'> & {
|
|
654
|
+
initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
|
|
655
|
+
queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
|
|
656
|
+
};
|
|
657
|
+
/**
|
|
658
|
+
* Query options where `queryFn` is present and not a `skipToken`.
|
|
659
|
+
*/
|
|
660
|
+
type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'queryFn'> & {
|
|
661
|
+
queryFn?: Exclude<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>['queryFn'], SkipToken | undefined>;
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Query options where `initialData` can be omitted or undefined.
|
|
665
|
+
*/
|
|
666
|
+
type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
|
|
667
|
+
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Brands query options so the `queryKey` carries the query function data and
|
|
671
|
+
* error types across TanStack Query APIs.
|
|
672
|
+
*
|
|
673
|
+
* @param options - Query options to preserve and brand.
|
|
674
|
+
* @returns The same options object with a typed `queryKey`.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```ts
|
|
678
|
+
* import { queryOptions } from '@tanstack/lit-query'
|
|
679
|
+
*
|
|
680
|
+
* const todosOptions = queryOptions({
|
|
681
|
+
* queryKey: ['todos'],
|
|
682
|
+
* queryFn: fetchTodos,
|
|
683
|
+
* initialData: [],
|
|
684
|
+
* })
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
688
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* Brands query options so the `queryKey` carries the query function data and
|
|
692
|
+
* error types across TanStack Query APIs.
|
|
693
|
+
*
|
|
694
|
+
* @param options - Query options to preserve and brand.
|
|
695
|
+
* @returns The same options object with a typed `queryKey`.
|
|
696
|
+
*/
|
|
697
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
698
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
699
|
+
};
|
|
700
|
+
/**
|
|
701
|
+
* Brands query options so the `queryKey` carries the query function data and
|
|
702
|
+
* error types across TanStack Query APIs.
|
|
703
|
+
*
|
|
704
|
+
* @param options - Query options to preserve and brand.
|
|
705
|
+
* @returns The same options object with a typed `queryKey`.
|
|
706
|
+
*/
|
|
707
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
708
|
+
queryKey: DataTag<TQueryKey, TQueryFnData, TError>;
|
|
709
|
+
};
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/infiniteQueryOptions.d.ts
|
|
712
|
+
/**
|
|
713
|
+
* Brands infinite query options so the `queryKey` carries the infinite query
|
|
714
|
+
* data and error types across TanStack Query APIs.
|
|
715
|
+
*
|
|
716
|
+
* @param options - Infinite query options to preserve and brand.
|
|
717
|
+
* @returns The same options object with a typed `queryKey`.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* import { infiniteQueryOptions } from '@tanstack/lit-query'
|
|
722
|
+
*
|
|
723
|
+
* const projectsOptions = infiniteQueryOptions({
|
|
724
|
+
* queryKey: ['projects'],
|
|
725
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
726
|
+
* initialPageParam: 0,
|
|
727
|
+
* getNextPageParam: (lastPage) => lastPage.nextCursor,
|
|
728
|
+
* })
|
|
729
|
+
* ```
|
|
730
|
+
*/
|
|
731
|
+
declare function infiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
732
|
+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
733
|
+
};
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/mutationOptions.d.ts
|
|
736
|
+
/**
|
|
737
|
+
* Preserves and types mutation options for reuse across Lit Query APIs.
|
|
738
|
+
*
|
|
739
|
+
* @param options - Mutation options to preserve.
|
|
740
|
+
* @returns The same options object.
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```ts
|
|
744
|
+
* import { mutationOptions } from '@tanstack/lit-query'
|
|
745
|
+
*
|
|
746
|
+
* const addTodoOptions = mutationOptions({
|
|
747
|
+
* mutationKey: ['add-todo'],
|
|
748
|
+
* mutationFn: (title: string) => addTodo(title),
|
|
749
|
+
* })
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
declare function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>(options: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>): MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>;
|
|
753
|
+
//#endregion
|
|
754
|
+
//#region src/types.d.ts
|
|
755
|
+
/**
|
|
756
|
+
* Accessor-wrapped options accepted by `createQueryController`.
|
|
757
|
+
*/
|
|
758
|
+
type QueryControllerOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Accessor<CreateQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>;
|
|
759
|
+
/**
|
|
760
|
+
* Result object produced by a Lit query controller.
|
|
761
|
+
*/
|
|
762
|
+
type QueryControllerResult<TData = unknown, TError = DefaultError> = QueryObserverResult<TData, TError>;
|
|
763
|
+
/**
|
|
764
|
+
* Accessor-wrapped options accepted by `createInfiniteQueryController`.
|
|
765
|
+
*/
|
|
766
|
+
type InfiniteQueryControllerOptions<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Accessor<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>;
|
|
767
|
+
/**
|
|
768
|
+
* Accessor-wrapped options accepted by `createMutationController`.
|
|
769
|
+
*/
|
|
770
|
+
type MutationControllerOptions<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = Accessor<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>>;
|
|
771
|
+
/**
|
|
772
|
+
* Result object produced by a Lit mutation controller.
|
|
773
|
+
*/
|
|
774
|
+
type MutationControllerResult<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown> = MutationObserverResult<TData, TError, TVariables, TOnMutateResult>;
|
|
775
|
+
/**
|
|
776
|
+
* Accessor-wrapped options accepted by `createQueriesController`.
|
|
777
|
+
*/
|
|
778
|
+
type QueriesControllerOptions<TQueryOptions extends Array<any> = Array<any>, TCombinedResult = CreateQueriesResults<TQueryOptions>> = Accessor<CreateQueriesControllerOptions<TQueryOptions, TCombinedResult>>;
|
|
779
|
+
//#endregion
|
|
780
|
+
export { type Accessor, type CreateInfiniteQueryOptions, type CreateMutationOptions, type CreateQueriesControllerOptions, type CreateQueriesInput, type CreateQueryOptions, type DefinedInitialDataOptions, type InfiniteQueryControllerOptions, type InfiniteQueryResultAccessor, type IsFetchingAccessor, type IsMutatingAccessor, type MutationControllerOptions, type MutationControllerResult, type MutationResultAccessor, type MutationStateAccessor, type MutationStateOptions, type QueriesControllerOptions, type QueriesResultAccessor, QueryClientProvider, type QueryControllerOptions, type QueryControllerResult, type QueryResultAccessor, type UndefinedInitialDataOptions, type UnusedSkipTokenOptions, type ValueAccessor, createInfiniteQueryController, createMutationController, createQueriesController, createQueryController, getDefaultQueryClient, infiniteQueryOptions, mutationOptions, queryClientContext, queryOptions, registerDefaultQueryClient, resolveQueryClient, unregisterDefaultQueryClient, useIsFetching, useIsMutating, useMutationState, useQueryClient };
|
|
781
|
+
//# sourceMappingURL=index.d.ts.map
|