You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add QueryObserver state utility methods to QueryCollectionUtils (#742)
* feat: Add QueryObserver state utilities and convert error utils to getters
Adds new utilities to expose TanStack Query's QueryObserver state:
- isFetching: Check if query is currently fetching
- isRefetching: Check if query is refetching in background
- isLoading: Check if query is loading for first time
- dataUpdatedAt: Timestamp of last successful data update
- fetchStatus: Current fetch status ('fetching' | 'paused' | 'idle')
BREAKING CHANGE: Error state utilities are now getters instead of methods:
- collection.utils.lastError() → collection.utils.lastError
- collection.utils.isError() → collection.utils.isError
- collection.utils.errorCount() → collection.utils.errorCount
* refactor: Extract QueryCollectionUtilsImpl class from closure
Addresses PR feedback from samwillis: refactor QueryCollectionUtilsImpl
class to be extracted outside the function scope with required state
passed through the constructor instead of relying on closure patterns.
This improves code architecture by making dependencies explicit and
avoiding nested class definitions within functions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* chore: Update generated docs
Re-generate documentation after QueryCollectionUtilsImpl refactoring.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* chore: Re-generate documentation after build
Regenerated all documentation files after running full build.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* docs: Fix outdated comment about closure usage
Update QueryCollectionUtilsImpl class comment to accurately reflect
that it now uses explicit dependency injection instead of closure.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
Add QueryObserver state utilities and convert error utils to getters
7
+
8
+
Exposes TanStack Query's QueryObserver state through QueryCollectionUtils, providing visibility into sync status beyond just error states. Also converts existing error state utilities from methods to getters for consistency with TanStack DB/Query patterns.
9
+
10
+
**Breaking Changes:**
11
+
12
+
-`lastError()`, `isError()`, and `errorCount()` are now getters instead of methods
13
+
- Before: `collection.utils.lastError()`
14
+
- After: `collection.utils.lastError`
15
+
16
+
**New Utilities:**
17
+
18
+
-`isFetching` - Check if query is currently fetching (initial or background)
19
+
-`isRefetching` - Check if query is refetching in background
20
+
-`isLoading` - Check if query is loading for first time
21
+
-`dataUpdatedAt` - Get timestamp of last successful data update
22
+
-`fetchStatus` - Get current fetch status ('fetching' | 'paused' | 'idle')
23
+
24
+
**Use Cases:**
25
+
26
+
- Show loading indicators during background refetches
27
+
- Implement "Last updated X minutes ago" UI patterns
Defined in: [packages/query-db-collection/src/query.ts:270](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L270)
14
+
Defined in: [packages/query-db-collection/src/query.ts:370](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L370)
15
15
16
16
Creates query collection options for use with a standard Collection.
17
17
This integrates TanStack Query with TanStack DB for automatic synchronization.
@@ -64,7 +64,7 @@ Configuration options for the Query collection
Defined in: [packages/query-db-collection/src/query.ts:300](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L300)
154
+
Defined in: [packages/query-db-collection/src/query.ts:405](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L405)
155
155
156
156
Creates query collection options for use with a standard Collection.
157
157
This integrates TanStack Query with TanStack DB for automatic synchronization.
@@ -204,7 +204,7 @@ Configuration options for the Query collection
Defined in: [packages/query-db-collection/src/query.ts:328](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L328)
294
+
Defined in: [packages/query-db-collection/src/query.ts:438](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L438)
295
295
296
296
Creates query collection options for use with a standard Collection.
297
297
This integrates TanStack Query with TanStack DB for automatic synchronization.
@@ -336,7 +336,7 @@ Configuration options for the Query collection
Defined in: [packages/query-db-collection/src/query.ts:357](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L357)
426
+
Defined in: [packages/query-db-collection/src/query.ts:472](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L472)
427
427
428
428
Creates query collection options for use with a standard Collection.
429
429
This integrates TanStack Query with TanStack DB for automatic synchronization.
@@ -468,7 +468,7 @@ Configuration options for the Query collection
Copy file name to clipboardExpand all lines: docs/reference/query-db-collection/interfaces/QueryCollectionUtils.md
+66-18Lines changed: 66 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ The type of errors that can occur during queries
43
43
## Indexable
44
44
45
45
```ts
46
-
[key: string]: Fn
46
+
[key: string]: any
47
47
```
48
48
49
49
## Properties
@@ -54,7 +54,7 @@ The type of errors that can occur during queries
54
54
clearError: () =>Promise<void>;
55
55
```
56
56
57
-
Defined in: [packages/query-db-collection/src/query.ts:181](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L181)
57
+
Defined in: [packages/query-db-collection/src/query.ts:194](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L194)
58
58
59
59
Clear the error state and trigger a refetch of the query
60
60
@@ -70,52 +70,100 @@ Error if the refetch fails
70
70
71
71
***
72
72
73
-
### errorCount()
73
+
### dataUpdatedAt
74
74
75
75
```ts
76
-
errorCount: () =>number;
76
+
dataUpdatedAt:number;
77
77
```
78
78
79
-
Defined in: [packages/query-db-collection/src/query.ts:175](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L175)
79
+
Defined in: [packages/query-db-collection/src/query.ts:185](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L185)
80
+
81
+
Get timestamp of last successful data update (in milliseconds)
82
+
83
+
***
84
+
85
+
### errorCount
86
+
87
+
```ts
88
+
errorCount: number;
89
+
```
90
+
91
+
Defined in: [packages/query-db-collection/src/query.ts:177](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L177)
80
92
81
93
Get the number of consecutive sync failures.
82
94
Incremented only when query fails completely (not per retry attempt); reset on success.
83
95
84
-
#### Returns
96
+
***
85
97
86
-
`number`
98
+
### fetchStatus
99
+
100
+
```ts
101
+
fetchStatus: "idle"|"fetching"|"paused";
102
+
```
103
+
104
+
Defined in: [packages/query-db-collection/src/query.ts:187](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L187)
105
+
106
+
Get current fetch status
87
107
88
108
***
89
109
90
-
### isError()
110
+
### isError
91
111
92
112
```ts
93
-
isError: () =>boolean;
113
+
isError: boolean;
94
114
```
95
115
96
-
Defined in: [packages/query-db-collection/src/query.ts:170](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L170)
116
+
Defined in: [packages/query-db-collection/src/query.ts:172](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L172)
97
117
98
118
Check if the collection is in an error state
99
119
100
-
#### Returns
120
+
***
121
+
122
+
### isFetching
101
123
102
-
`boolean`
124
+
```ts
125
+
isFetching: boolean;
126
+
```
127
+
128
+
Defined in: [packages/query-db-collection/src/query.ts:179](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L179)
129
+
130
+
Check if query is currently fetching (initial or background)
103
131
104
132
***
105
133
106
-
### lastError()
134
+
### isLoading
107
135
108
136
```ts
109
-
lastError: () =>TError|undefined;
137
+
isLoading: boolean;
110
138
```
111
139
112
-
Defined in: [packages/query-db-collection/src/query.ts:168](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L168)
140
+
Defined in: [packages/query-db-collection/src/query.ts:183](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L183)
113
141
114
-
Get the last error encountered by the query (if any); reset on success
142
+
Check if query is loading for the first time (no data yet)
115
143
116
-
#### Returns
144
+
***
145
+
146
+
### isRefetching
147
+
148
+
```ts
149
+
isRefetching: boolean;
150
+
```
151
+
152
+
Defined in: [packages/query-db-collection/src/query.ts:181](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L181)
117
153
118
-
`TError`\|`undefined`
154
+
Check if query is refetching in background (not initial fetch)
155
+
156
+
***
157
+
158
+
### lastError
159
+
160
+
```ts
161
+
lastError: TError|undefined;
162
+
```
163
+
164
+
Defined in: [packages/query-db-collection/src/query.ts:170](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L170)
165
+
166
+
Get the last error encountered by the query (if any); reset on success
Copy file name to clipboardExpand all lines: docs/reference/type-aliases/UtilsRecord.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ title: UtilsRecord
6
6
# Type Alias: UtilsRecord
7
7
8
8
```ts
9
-
typeUtilsRecord=Record<string, Fn>;
9
+
typeUtilsRecord=Record<string, any>;
10
10
```
11
11
12
12
Defined in: [packages/db/src/types.ts:40](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L40)
13
13
14
-
A record of utility functions that can be attached to a collection
14
+
A record of utilities (functions or getters) that can be attached to a collection
0 commit comments