@tanstack/lit-query 0.2.26 → 0.2.27

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.
@@ -9,10 +9,8 @@ import type {
9
9
  /**
10
10
  * Brands infinite query options so the `queryKey` carries the infinite query
11
11
  * data and error types across TanStack Query APIs.
12
- *
13
12
  * @param options - Infinite query options to preserve and brand.
14
13
  * @returns The same options object with a typed `queryKey`.
15
- *
16
14
  * @example
17
15
  * ```ts
18
16
  * import { infiniteQueryOptions } from '@tanstack/lit-query'
@@ -5,10 +5,8 @@ import type {
5
5
 
6
6
  /**
7
7
  * Preserves and types mutation options for reuse across Lit Query APIs.
8
- *
9
8
  * @param options - Mutation options to preserve.
10
9
  * @returns The same options object.
11
- *
12
10
  * @example
13
11
  * ```ts
14
12
  * import { mutationOptions } from '@tanstack/lit-query'
@@ -3,15 +3,30 @@ type TrackableQueryObserver<TResult extends object> = {
3
3
  trackResult: (result: TResult) => unknown
4
4
  }
5
5
 
6
+ /**
7
+ * Wraps observer results with property tracking when `notifyOnChangeProps` is
8
+ * not set, so the observer only notifies about the properties the host reads.
9
+ */
6
10
  export class QueryObserverResultTracker<TResult extends object> {
7
11
  private result: TResult | undefined
8
12
  private usesTracking = false
9
13
 
14
+ /**
15
+ * Forgets the last result, so the next `update` returns a result again.
16
+ */
10
17
  reset(): void {
11
18
  this.result = undefined
12
19
  this.usesTracking = false
13
20
  }
14
21
 
22
+ /**
23
+ * Returns the result to expose, tracked through the observer when it uses
24
+ * property tracking.
25
+ * @param observer - The observer the result comes from, if any.
26
+ * @param result - The latest result of the observer.
27
+ * @returns The result to expose, or `undefined` if neither the result nor
28
+ * the tracking mode changed since the last call.
29
+ */
15
30
  update(
16
31
  observer: TrackableQueryObserver<TResult> | undefined,
17
32
  result: TResult,
@@ -23,7 +23,8 @@ export type DefinedInitialDataOptions<
23
23
  'queryFn'
24
24
  > & {
25
25
  initialData:
26
- NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)
26
+ | NonUndefinedGuard<TQueryFnData>
27
+ | (() => NonUndefinedGuard<TQueryFnData>)
27
28
  queryFn?: QueryFunction<TQueryFnData, TQueryKey>
28
29
  }
29
30
 
@@ -75,10 +76,8 @@ export type UndefinedInitialDataOptions<
75
76
  /**
76
77
  * Brands query options so the `queryKey` carries the query function data and
77
78
  * error types across TanStack Query APIs.
78
- *
79
79
  * @param options - Query options to preserve and brand.
80
80
  * @returns The same options object with a typed `queryKey`.
81
- *
82
81
  * @example
83
82
  * ```ts
84
83
  * import { queryOptions } from '@tanstack/lit-query'
@@ -104,7 +103,6 @@ export function queryOptions<
104
103
  /**
105
104
  * Brands query options so the `queryKey` carries the query function data and
106
105
  * error types across TanStack Query APIs.
107
- *
108
106
  * @param options - Query options to preserve and brand.
109
107
  * @returns The same options object with a typed `queryKey`.
110
108
  */
@@ -122,7 +120,6 @@ export function queryOptions<
122
120
  /**
123
121
  * Brands query options so the `queryKey` carries the query function data and
124
122
  * error types across TanStack Query APIs.
125
- *
126
123
  * @param options - Query options to preserve and brand.
127
124
  * @returns The same options object with a typed `queryKey`.
128
125
  */
@@ -31,7 +31,7 @@ class IsFetchingController extends BaseController<number> {
31
31
  this.result = this.computeValue()
32
32
  }
33
33
 
34
- protected onConnected(): void {
34
+ protected override onConnected(): void {
35
35
  if (!this.syncClient()) {
36
36
  this.setResult(0)
37
37
  return
@@ -41,13 +41,13 @@ class IsFetchingController extends BaseController<number> {
41
41
  this.setResult(this.computeValue())
42
42
  }
43
43
 
44
- protected onDisconnected(): void {
44
+ protected override onDisconnected(): void {
45
45
  this.unsubscribe?.()
46
46
  this.unsubscribe = undefined
47
47
  this.syncClient()
48
48
  }
49
49
 
50
- protected onHostUpdate(): void {
50
+ protected override onHostUpdate(): void {
51
51
  if (typeof this.filters !== 'function') {
52
52
  return
53
53
  }
@@ -55,7 +55,7 @@ class IsFetchingController extends BaseController<number> {
55
55
  this.setResult(this.syncClient() ? this.computeValue() : 0)
56
56
  }
57
57
 
58
- protected onQueryClientChanged(): void {
58
+ protected override onQueryClientChanged(): void {
59
59
  if (!this.syncClient()) {
60
60
  this.setResult(0)
61
61
  return
@@ -116,14 +116,12 @@ class IsFetchingController extends BaseController<number> {
116
116
  * When `filters` is a function, it is re-read during host updates so the count
117
117
  * can follow reactive host state. If `queryClient` is omitted, the controller
118
118
  * resolves the client from the nearest connected `QueryClientProvider`.
119
- *
120
119
  * @param host - The Lit reactive controller host that owns the cache
121
120
  * subscription.
122
121
  * @param filters - Query filters, or a getter that returns query filters.
123
122
  * @param queryClient - Optional explicit query client. Provide this for
124
123
  * controllers that should not resolve a client from Lit context.
125
124
  * @returns An accessor for the current number of matching fetching queries.
126
- *
127
125
  * @example
128
126
  * ```ts
129
127
  * import { LitElement, html } from 'lit'
@@ -31,7 +31,7 @@ class IsMutatingController extends BaseController<number> {
31
31
  this.result = this.computeValue()
32
32
  }
33
33
 
34
- protected onConnected(): void {
34
+ protected override onConnected(): void {
35
35
  if (!this.syncClient()) {
36
36
  this.setResult(0)
37
37
  return
@@ -41,13 +41,13 @@ class IsMutatingController extends BaseController<number> {
41
41
  this.setResult(this.computeValue())
42
42
  }
43
43
 
44
- protected onDisconnected(): void {
44
+ protected override onDisconnected(): void {
45
45
  this.unsubscribe?.()
46
46
  this.unsubscribe = undefined
47
47
  this.syncClient()
48
48
  }
49
49
 
50
- protected onHostUpdate(): void {
50
+ protected override onHostUpdate(): void {
51
51
  if (typeof this.filters !== 'function') {
52
52
  return
53
53
  }
@@ -55,7 +55,7 @@ class IsMutatingController extends BaseController<number> {
55
55
  this.setResult(this.syncClient() ? this.computeValue() : 0)
56
56
  }
57
57
 
58
- protected onQueryClientChanged(): void {
58
+ protected override onQueryClientChanged(): void {
59
59
  if (!this.syncClient()) {
60
60
  this.setResult(0)
61
61
  return
@@ -116,14 +116,12 @@ class IsMutatingController extends BaseController<number> {
116
116
  * When `filters` is a function, it is re-read during host updates so the count
117
117
  * can follow reactive host state. If `queryClient` is omitted, the controller
118
118
  * resolves the client from the nearest connected `QueryClientProvider`.
119
- *
120
119
  * @param host - The Lit reactive controller host that owns the cache
121
120
  * subscription.
122
121
  * @param filters - Mutation filters, or a getter that returns mutation filters.
123
122
  * @param queryClient - Optional explicit query client. Provide this for
124
123
  * controllers that should not resolve a client from Lit context.
125
124
  * @returns An accessor for the current number of matching pending mutations.
126
- *
127
125
  * @example
128
126
  * ```ts
129
127
  * import { LitElement, html } from 'lit'
@@ -50,7 +50,7 @@ class MutationStateController<TResult> extends BaseController<Array<TResult>> {
50
50
  this.result = this.computeState()
51
51
  }
52
52
 
53
- protected onConnected(): void {
53
+ protected override onConnected(): void {
54
54
  if (!this.syncClient()) {
55
55
  this.setMutationState([])
56
56
  return
@@ -60,13 +60,13 @@ class MutationStateController<TResult> extends BaseController<Array<TResult>> {
60
60
  this.setMutationState(this.computeState())
61
61
  }
62
62
 
63
- protected onDisconnected(): void {
63
+ protected override onDisconnected(): void {
64
64
  this.unsubscribe?.()
65
65
  this.unsubscribe = undefined
66
66
  this.syncClient()
67
67
  }
68
68
 
69
- protected onHostUpdate(): void {
69
+ protected override onHostUpdate(): void {
70
70
  if (!this.shouldRefreshOnHostUpdate()) {
71
71
  return
72
72
  }
@@ -74,7 +74,7 @@ class MutationStateController<TResult> extends BaseController<Array<TResult>> {
74
74
  this.setMutationState(this.syncClient() ? this.computeState() : [])
75
75
  }
76
76
 
77
- protected onQueryClientChanged(): void {
77
+ protected override onQueryClientChanged(): void {
78
78
  if (!this.syncClient()) {
79
79
  this.setMutationState([])
80
80
  return
@@ -160,14 +160,12 @@ class MutationStateController<TResult> extends BaseController<Array<TResult>> {
160
160
  * the selection can follow reactive host state. If `queryClient` is omitted,
161
161
  * the controller resolves the client from the nearest connected
162
162
  * `QueryClientProvider`.
163
- *
164
163
  * @param host - The Lit reactive controller host that owns the mutation cache
165
164
  * subscription.
166
165
  * @param options - Mutation state filters and optional selector.
167
166
  * @param queryClient - Optional explicit query client. Provide this for
168
167
  * controllers that should not resolve a client from Lit context.
169
168
  * @returns An accessor for the selected mutation state array.
170
- *
171
169
  * @example
172
170
  * ```ts
173
171
  * import { LitElement, html } from 'lit'