@tanstack/react-db 0.5.12 → 1.0.0-rc.1
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/dist/cjs/live-query-internals.cjs.map +1 -1
- package/dist/cjs/live-query-internals.d.cts +3 -1
- package/dist/cjs/source-id-bindings.cjs +9 -42
- package/dist/cjs/source-id-bindings.cjs.map +1 -1
- package/dist/cjs/source-id-bindings.d.cts +6 -17
- package/dist/cjs/useLiveInfiniteQuery.cjs +93 -173
- package/dist/cjs/useLiveInfiniteQuery.cjs.map +1 -1
- package/dist/cjs/useLiveInfiniteQuery.d.cts +3 -14
- package/dist/cjs/useLiveQuery.cjs +187 -224
- package/dist/cjs/useLiveQuery.cjs.map +1 -1
- package/dist/cjs/useLiveQuery.d.cts +37 -136
- package/dist/cjs/useLiveSuspenseQuery.cjs +71 -64
- package/dist/cjs/useLiveSuspenseQuery.cjs.map +1 -1
- package/dist/cjs/useLiveSuspenseQuery.d.cts +10 -9
- package/dist/cjs/usePacedMutations.cjs.map +1 -1
- package/dist/cjs/usePacedMutations.d.cts +1 -1
- package/dist/esm/live-query-internals.d.ts +3 -1
- package/dist/esm/live-query-internals.js.map +1 -1
- package/dist/esm/source-id-bindings.d.ts +6 -17
- package/dist/esm/source-id-bindings.js +9 -40
- package/dist/esm/source-id-bindings.js.map +1 -1
- package/dist/esm/useLiveInfiniteQuery.d.ts +3 -14
- package/dist/esm/useLiveInfiniteQuery.js +95 -175
- package/dist/esm/useLiveInfiniteQuery.js.map +1 -1
- package/dist/esm/useLiveQuery.d.ts +37 -136
- package/dist/esm/useLiveQuery.js +189 -226
- package/dist/esm/useLiveQuery.js.map +1 -1
- package/dist/esm/useLiveSuspenseQuery.d.ts +10 -9
- package/dist/esm/useLiveSuspenseQuery.js +71 -64
- package/dist/esm/useLiveSuspenseQuery.js.map +1 -1
- package/dist/esm/usePacedMutations.d.ts +1 -1
- package/dist/esm/usePacedMutations.js.map +1 -1
- package/package.json +3 -3
- package/skills/react-db/SKILL.md +24 -15
- package/src/live-query-internals.ts +3 -0
- package/src/source-id-bindings.ts +16 -62
- package/src/useLiveInfiniteQuery.ts +138 -296
- package/src/useLiveQuery.ts +329 -495
- package/src/useLiveSuspenseQuery.ts +122 -132
- package/src/usePacedMutations.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Collection, CollectionImpl, CollectionStatus, Context, DbClient, GetResult, InferResultType, InitialQueryBuilder, LiveQueryCollectionConfig, LiveQueryIdentityScope, LiveQueryKey, LiveQuerySourceIdClaims, LiveQueryStatusFlags, NonSingleResult, PooledLiveQueries, QueryBuilder, SingleResult } from '@tanstack/db';
|
|
2
2
|
export type DerivedIdentityProfiler = {
|
|
3
3
|
renderCount: number;
|
|
4
4
|
totalMs: number;
|
|
@@ -6,7 +6,7 @@ export type DerivedIdentityProfiler = {
|
|
|
6
6
|
warned: boolean;
|
|
7
7
|
};
|
|
8
8
|
export type UseLiveQueryStatus = CollectionStatus | `disabled`;
|
|
9
|
-
export type LiveQueryKey
|
|
9
|
+
export type { LiveQueryKey };
|
|
10
10
|
type UseLiveQueryConfigOptions<TContext extends Context> = Omit<LiveQueryCollectionConfig<TContext>, `query`> & {
|
|
11
11
|
/**
|
|
12
12
|
* Explicit identity for queries that contain opaque functional variants or
|
|
@@ -16,29 +16,34 @@ type UseLiveQueryConfigOptions<TContext extends Context> = Omit<LiveQueryCollect
|
|
|
16
16
|
queryKey?: LiveQueryKey;
|
|
17
17
|
/** Override the nearest DbProvider for this query. */
|
|
18
18
|
client?: DbClient;
|
|
19
|
+
/**
|
|
20
|
+
* Pass `pooledLiveQueries` to share one partition among equality-filtered
|
|
21
|
+
* queries of one shape. Suspense and DbClient queries never pool.
|
|
22
|
+
*/
|
|
23
|
+
pool?: PooledLiveQueries;
|
|
19
24
|
};
|
|
20
25
|
type ConfiguredQueryBuilder<TContext extends Context> = Extract<LiveQueryCollectionConfig<TContext>[`query`], QueryBuilder<TContext>>;
|
|
21
26
|
export type UseLiveQueryConfig<TContext extends Context> = UseLiveQueryConfigOptions<TContext> & Pick<LiveQueryCollectionConfig<TContext>, `query`>;
|
|
22
27
|
export type ConditionalUseLiveQueryConfig<TContext extends Context> = UseLiveQueryConfigOptions<TContext> & {
|
|
23
28
|
query: ConfiguredQueryBuilder<TContext> | ((q: InitialQueryBuilder) => ConfiguredQueryBuilder<TContext> | undefined | null);
|
|
24
29
|
};
|
|
25
|
-
export declare function warnDeprecatedDepsArray(hookName?: `useLiveQuery` | `useLiveInfiniteQuery`): void;
|
|
26
30
|
export declare function prepareQueryValue(value: unknown, dbClient: DbClient | undefined, deferredCollections: Set<CollectionImpl<any, string | number, any, any, any>>): unknown;
|
|
27
31
|
type DerivedQueryPreparation = {
|
|
28
|
-
status: `hashable`;
|
|
29
32
|
value: unknown;
|
|
30
33
|
identityDeps: Array<unknown>;
|
|
31
|
-
} | {
|
|
32
|
-
status: `unhashable`;
|
|
33
|
-
value: unknown;
|
|
34
|
-
error: UnhashableQueryIRError;
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
export declare function
|
|
35
|
+
/** How a hook checks a prepared query whose identity it compares. */
|
|
36
|
+
export declare function getIdentityScope(claims: LiveQuerySourceIdClaims, dbClient: DbClient | undefined, hookName: string): LiveQueryIdentityScope;
|
|
37
|
+
/**
|
|
38
|
+
* Prepare a query without `queryKey`, derive its identity, and claim its
|
|
39
|
+
* source Collection IDs. A query whose IR has no stable identity throws
|
|
40
|
+
* `UnhashableQueryIRError`. The hook's render boundary releases the sync
|
|
41
|
+
* starts a rejected render deferred.
|
|
42
|
+
*/
|
|
43
|
+
export declare function prepareDerivedQuery(value: unknown, profiler: DerivedIdentityProfiler, scope: LiveQueryIdentityScope, deferredCollections: Set<CollectionImpl<any, string | number, any, any, any>>): DerivedQueryPreparation;
|
|
38
44
|
/**
|
|
39
45
|
* Create a live query using a query function.
|
|
40
46
|
* @param queryFn - Query function that defines what data to fetch
|
|
41
|
-
* @param deps - Deprecated array of dependencies that trigger query re-execution when changed
|
|
42
47
|
* @returns Object with reactive data, state, and status information
|
|
43
48
|
* @example
|
|
44
49
|
* // Prefer config object syntax
|
|
@@ -91,12 +96,12 @@ export declare function warnUnhashableDerivedIdentity(error: UnhashableQueryIREr
|
|
|
91
96
|
*
|
|
92
97
|
* @example
|
|
93
98
|
* // Handle loading and error states
|
|
94
|
-
* const { data, isLoading,
|
|
99
|
+
* const { data, isLoading, isLoadingError, status } = useLiveQuery({
|
|
95
100
|
* query: (q) => q.from({ todos: todoCollection })
|
|
96
101
|
* })
|
|
97
102
|
*
|
|
98
103
|
* if (isLoading) return <div>Loading...</div>
|
|
99
|
-
* if (
|
|
104
|
+
* if (isLoadingError) return <div>Error: {status}</div>
|
|
100
105
|
*
|
|
101
106
|
* return (
|
|
102
107
|
* <ul>
|
|
@@ -104,85 +109,44 @@ export declare function warnUnhashableDerivedIdentity(error: UnhashableQueryIREr
|
|
|
104
109
|
* </ul>
|
|
105
110
|
* )
|
|
106
111
|
*/
|
|
107
|
-
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext
|
|
112
|
+
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>): {
|
|
108
113
|
state: Map<string | number, GetResult<TContext>>;
|
|
109
114
|
data: InferResultType<TContext>;
|
|
110
115
|
collection: Collection<GetResult<TContext>, string | number, {}>;
|
|
111
116
|
status: CollectionStatus;
|
|
112
|
-
isLoading: boolean;
|
|
113
|
-
isReady: boolean;
|
|
114
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
115
|
-
isPersistedReady: boolean;
|
|
116
|
-
persistedError: unknown | undefined;
|
|
117
|
-
isIdle: boolean;
|
|
118
|
-
isError: boolean;
|
|
119
|
-
isCleanedUp: boolean;
|
|
120
117
|
isEnabled: true;
|
|
121
|
-
};
|
|
122
|
-
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | undefined | null
|
|
118
|
+
} & LiveQueryStatusFlags;
|
|
119
|
+
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | undefined | null): {
|
|
123
120
|
state: Map<string | number, GetResult<TContext>> | undefined;
|
|
124
121
|
data: InferResultType<TContext> | undefined;
|
|
125
122
|
collection: Collection<GetResult<TContext>, string | number, {}> | undefined;
|
|
126
123
|
status: UseLiveQueryStatus;
|
|
127
|
-
isLoading: boolean;
|
|
128
|
-
isReady: boolean;
|
|
129
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
130
|
-
isPersistedReady: boolean;
|
|
131
|
-
persistedError: unknown | undefined;
|
|
132
|
-
isIdle: boolean;
|
|
133
|
-
isError: boolean;
|
|
134
|
-
isCleanedUp: boolean;
|
|
135
124
|
isEnabled: boolean;
|
|
136
|
-
};
|
|
137
|
-
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => LiveQueryCollectionConfig<TContext> | undefined | null
|
|
125
|
+
} & LiveQueryStatusFlags;
|
|
126
|
+
export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => LiveQueryCollectionConfig<TContext> | undefined | null): {
|
|
138
127
|
state: Map<string | number, GetResult<TContext>> | undefined;
|
|
139
128
|
data: InferResultType<TContext> | undefined;
|
|
140
129
|
collection: Collection<GetResult<TContext>, string | number, {}> | undefined;
|
|
141
130
|
status: UseLiveQueryStatus;
|
|
142
|
-
isLoading: boolean;
|
|
143
|
-
isReady: boolean;
|
|
144
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
145
|
-
isPersistedReady: boolean;
|
|
146
|
-
persistedError: unknown | undefined;
|
|
147
|
-
isIdle: boolean;
|
|
148
|
-
isError: boolean;
|
|
149
|
-
isCleanedUp: boolean;
|
|
150
131
|
isEnabled: boolean;
|
|
151
|
-
};
|
|
152
|
-
export declare function useLiveQuery<TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(queryFn: (q: InitialQueryBuilder) => Collection<TResult, TKey, TUtils> | undefined | null
|
|
132
|
+
} & LiveQueryStatusFlags;
|
|
133
|
+
export declare function useLiveQuery<TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(queryFn: (q: InitialQueryBuilder) => Collection<TResult, TKey, TUtils> | undefined | null): {
|
|
153
134
|
state: Map<TKey, TResult> | undefined;
|
|
154
135
|
data: Array<TResult> | undefined;
|
|
155
136
|
collection: Collection<TResult, TKey, TUtils> | undefined;
|
|
156
137
|
status: UseLiveQueryStatus;
|
|
157
|
-
isLoading: boolean;
|
|
158
|
-
isReady: boolean;
|
|
159
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
160
|
-
isPersistedReady: boolean;
|
|
161
|
-
persistedError: unknown | undefined;
|
|
162
|
-
isIdle: boolean;
|
|
163
|
-
isError: boolean;
|
|
164
|
-
isCleanedUp: boolean;
|
|
165
138
|
isEnabled: boolean;
|
|
166
|
-
};
|
|
167
|
-
export declare function useLiveQuery<TContext extends Context, TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | LiveQueryCollectionConfig<TContext> | Collection<TResult, TKey, TUtils> | undefined | null
|
|
139
|
+
} & LiveQueryStatusFlags;
|
|
140
|
+
export declare function useLiveQuery<TContext extends Context, TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | LiveQueryCollectionConfig<TContext> | Collection<TResult, TKey, TUtils> | undefined | null): {
|
|
168
141
|
state: Map<string | number, GetResult<TContext>> | Map<TKey, TResult> | undefined;
|
|
169
142
|
data: InferResultType<TContext> | Array<TResult> | undefined;
|
|
170
143
|
collection: Collection<GetResult<TContext>, string | number, {}> | Collection<TResult, TKey, TUtils> | undefined;
|
|
171
144
|
status: UseLiveQueryStatus;
|
|
172
|
-
isLoading: boolean;
|
|
173
|
-
isReady: boolean;
|
|
174
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
175
|
-
isPersistedReady: boolean;
|
|
176
|
-
persistedError: unknown | undefined;
|
|
177
|
-
isIdle: boolean;
|
|
178
|
-
isError: boolean;
|
|
179
|
-
isCleanedUp: boolean;
|
|
180
145
|
isEnabled: boolean;
|
|
181
|
-
};
|
|
146
|
+
} & LiveQueryStatusFlags;
|
|
182
147
|
/**
|
|
183
148
|
* Create a live query using configuration object
|
|
184
149
|
* @param config - Configuration object with query and options
|
|
185
|
-
* @param deps - Deprecated array of dependencies that trigger query re-execution when changed
|
|
186
150
|
* @returns Object with reactive data, state, and status information
|
|
187
151
|
* @example
|
|
188
152
|
* // Basic config object usage
|
|
@@ -204,12 +168,12 @@ export declare function useLiveQuery<TContext extends Context, TResult extends o
|
|
|
204
168
|
*
|
|
205
169
|
* @example
|
|
206
170
|
* // Handle all states uniformly
|
|
207
|
-
* const { data, isLoading, isReady,
|
|
171
|
+
* const { data, isLoading, isReady, isLoadingError } = useLiveQuery({
|
|
208
172
|
* query: (q) => q.from({ items: itemCollection })
|
|
209
173
|
* })
|
|
210
174
|
*
|
|
211
175
|
* if (isLoading) return <div>Loading...</div>
|
|
212
|
-
* if (
|
|
176
|
+
* if (isLoadingError) return <div>Something went wrong</div>
|
|
213
177
|
* if (!isReady) return <div>Preparing...</div>
|
|
214
178
|
*
|
|
215
179
|
* return <div>{data.length} items loaded</div>
|
|
@@ -219,61 +183,15 @@ export declare function useLiveQuery<TContext extends Context>(config: UseLiveQu
|
|
|
219
183
|
data: InferResultType<TContext>;
|
|
220
184
|
collection: Collection<GetResult<TContext>, string | number, {}>;
|
|
221
185
|
status: CollectionStatus;
|
|
222
|
-
isLoading: boolean;
|
|
223
|
-
isReady: boolean;
|
|
224
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
225
|
-
isPersistedReady: boolean;
|
|
226
|
-
persistedError: unknown | undefined;
|
|
227
|
-
isIdle: boolean;
|
|
228
|
-
isError: boolean;
|
|
229
|
-
isCleanedUp: boolean;
|
|
230
186
|
isEnabled: true;
|
|
231
|
-
};
|
|
187
|
+
} & LiveQueryStatusFlags;
|
|
232
188
|
export declare function useLiveQuery<TContext extends Context>(config: ConditionalUseLiveQueryConfig<TContext>): {
|
|
233
189
|
state: Map<string | number, GetResult<TContext>> | undefined;
|
|
234
190
|
data: InferResultType<TContext> | undefined;
|
|
235
191
|
collection: Collection<GetResult<TContext>, string | number, {}> | undefined;
|
|
236
192
|
status: UseLiveQueryStatus;
|
|
237
|
-
isLoading: boolean;
|
|
238
|
-
isReady: boolean;
|
|
239
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
240
|
-
isPersistedReady: boolean;
|
|
241
|
-
persistedError: unknown | undefined;
|
|
242
|
-
isIdle: boolean;
|
|
243
|
-
isError: boolean;
|
|
244
|
-
isCleanedUp: boolean;
|
|
245
|
-
isEnabled: boolean;
|
|
246
|
-
};
|
|
247
|
-
export declare function useLiveQuery<TContext extends Context>(config: LiveQueryCollectionConfig<TContext>, deps?: Array<unknown>): {
|
|
248
|
-
state: Map<string | number, GetResult<TContext>>;
|
|
249
|
-
data: InferResultType<TContext>;
|
|
250
|
-
collection: Collection<GetResult<TContext>, string | number, {}>;
|
|
251
|
-
status: CollectionStatus;
|
|
252
|
-
isLoading: boolean;
|
|
253
|
-
isReady: boolean;
|
|
254
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
255
|
-
isPersistedReady: boolean;
|
|
256
|
-
persistedError: unknown | undefined;
|
|
257
|
-
isIdle: boolean;
|
|
258
|
-
isError: boolean;
|
|
259
|
-
isCleanedUp: boolean;
|
|
260
|
-
isEnabled: true;
|
|
261
|
-
};
|
|
262
|
-
export declare function useLiveQuery<TContext extends Context>(config: ConditionalUseLiveQueryConfig<TContext>, deps: Array<unknown>): {
|
|
263
|
-
state: Map<string | number, GetResult<TContext>> | undefined;
|
|
264
|
-
data: InferResultType<TContext> | undefined;
|
|
265
|
-
collection: Collection<GetResult<TContext>, string | number, {}> | undefined;
|
|
266
|
-
status: UseLiveQueryStatus;
|
|
267
|
-
isLoading: boolean;
|
|
268
|
-
isReady: boolean;
|
|
269
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
270
|
-
isPersistedReady: boolean;
|
|
271
|
-
persistedError: unknown | undefined;
|
|
272
|
-
isIdle: boolean;
|
|
273
|
-
isError: boolean;
|
|
274
|
-
isCleanedUp: boolean;
|
|
275
193
|
isEnabled: boolean;
|
|
276
|
-
};
|
|
194
|
+
} & LiveQueryStatusFlags;
|
|
277
195
|
/**
|
|
278
196
|
* Subscribe to an existing live query collection
|
|
279
197
|
* @param liveQueryCollection - Pre-created live query collection to subscribe to
|
|
@@ -296,10 +214,10 @@ export declare function useLiveQuery<TContext extends Context>(config: Condition
|
|
|
296
214
|
*
|
|
297
215
|
* @example
|
|
298
216
|
* // Handle states consistently
|
|
299
|
-
* const { data, isLoading,
|
|
217
|
+
* const { data, isLoading, isLoadingError } = useLiveQuery(sharedCollection)
|
|
300
218
|
*
|
|
301
219
|
* if (isLoading) return <div>Loading...</div>
|
|
302
|
-
* if (
|
|
220
|
+
* if (isLoadingError) return <div>Error loading data</div>
|
|
303
221
|
*
|
|
304
222
|
* return <div>{data.map(item => <Item key={item.id} {...item} />)}</div>
|
|
305
223
|
*/
|
|
@@ -308,31 +226,14 @@ export declare function useLiveQuery<TResult extends object, TKey extends string
|
|
|
308
226
|
data: Array<TResult>;
|
|
309
227
|
collection: Collection<TResult, TKey, TUtils>;
|
|
310
228
|
status: CollectionStatus;
|
|
311
|
-
isLoading: boolean;
|
|
312
|
-
isReady: boolean;
|
|
313
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
314
|
-
isPersistedReady: boolean;
|
|
315
|
-
persistedError: unknown | undefined;
|
|
316
|
-
isIdle: boolean;
|
|
317
|
-
isError: boolean;
|
|
318
|
-
isCleanedUp: boolean;
|
|
319
229
|
isEnabled: true;
|
|
320
|
-
};
|
|
230
|
+
} & LiveQueryStatusFlags;
|
|
321
231
|
export declare function useLiveQuery<TResult extends object, TKey extends string | number, TUtils extends Record<string, any>>(liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult): {
|
|
322
232
|
state: Map<TKey, TResult>;
|
|
323
233
|
data: TResult | undefined;
|
|
324
234
|
collection: Collection<TResult, TKey, TUtils> & SingleResult;
|
|
325
235
|
status: CollectionStatus;
|
|
326
|
-
isLoading: boolean;
|
|
327
|
-
isReady: boolean;
|
|
328
|
-
persistedStatus: LiveQueryPersistedStatus;
|
|
329
|
-
isPersistedReady: boolean;
|
|
330
|
-
persistedError: unknown | undefined;
|
|
331
|
-
isIdle: boolean;
|
|
332
|
-
isError: boolean;
|
|
333
|
-
isCleanedUp: boolean;
|
|
334
236
|
isEnabled: true;
|
|
335
|
-
};
|
|
237
|
+
} & LiveQueryStatusFlags;
|
|
336
238
|
/** @internal Shared implementation for the Suspense wrapper. */
|
|
337
|
-
export declare function useLiveQueryForSuspense(configOrQueryOrCollection: any
|
|
338
|
-
export {};
|
|
239
|
+
export declare function useLiveQueryForSuspense(configOrQueryOrCollection: any): any;
|