@tanstack/svelte-db 0.4.1 → 0.5.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.
@@ -110,6 +110,15 @@ export function useLiveInfiniteQuery(queryFnOrCollection, config, deps = []) {
110
110
  get isReady() {
111
111
  return snapshot.isReady;
112
112
  },
113
+ get persistedStatus() {
114
+ return snapshot.persistedStatus;
115
+ },
116
+ get isPersistedReady() {
117
+ return snapshot.isPersistedReady;
118
+ },
119
+ get persistedError() {
120
+ return snapshot.persistedError;
121
+ },
113
122
  get isIdle() {
114
123
  return snapshot.isIdle;
115
124
  },
@@ -1,4 +1,4 @@
1
- import type { Collection, CollectionStatus, Context, DbClient, GetResult, InferResultType, InitialQueryBuilder, LiveQueryCollectionConfig, LiveQueryKey, NonSingleResult, QueryBuilder, SingleResult } from '@tanstack/db';
1
+ import type { Collection, CollectionStatus, Context, DbClient, GetResult, InferResultType, InitialQueryBuilder, LiveQueryCollectionConfig, LiveQueryKey, LiveQueryPersistedStatus, NonSingleResult, QueryBuilder, SingleResult } from '@tanstack/db';
2
2
  /**
3
3
  * Return type for useLiveQuery hook
4
4
  * @property state - Reactive Map of query results (key → item)
@@ -18,10 +18,18 @@ export interface UseLiveQueryReturn<T extends object, TData = Array<T>> {
18
18
  status: CollectionStatus;
19
19
  isLoading: boolean;
20
20
  isReady: boolean;
21
+ persistedStatus: LiveQueryPersistedStatus;
22
+ isPersistedReady: boolean;
23
+ persistedError: unknown | undefined;
21
24
  isIdle: boolean;
22
25
  isError: boolean;
23
26
  isCleanedUp: boolean;
24
27
  }
28
+ type InferConditionalResultType<TContext extends Context> = TContext extends SingleResult ? InferResultType<TContext> | [] : InferResultType<TContext>;
29
+ export type ConditionalUseLiveQueryReturn<T extends object, TData = Array<T>> = Omit<UseLiveQueryReturn<T, TData>, `collection` | `status`> & {
30
+ collection: Collection<T, string | number, {}> | null;
31
+ status: CollectionStatus | `disabled`;
32
+ };
25
33
  export interface UseLiveQueryReturnWithCollection<T extends object, TKey extends string | number, TUtils extends Record<string, any>, TData = Array<T>> {
26
34
  state: Map<TKey, T>;
27
35
  data: TData;
@@ -29,6 +37,9 @@ export interface UseLiveQueryReturnWithCollection<T extends object, TKey extends
29
37
  status: CollectionStatus;
30
38
  isLoading: boolean;
31
39
  isReady: boolean;
40
+ persistedStatus: LiveQueryPersistedStatus;
41
+ isPersistedReady: boolean;
42
+ persistedError: unknown | undefined;
32
43
  isIdle: boolean;
33
44
  isError: boolean;
34
45
  isCleanedUp: boolean;
@@ -127,7 +138,7 @@ export type UseLiveQueryConfig<TContext extends Context> = LiveQueryCollectionCo
127
138
  * // {/if}
128
139
  */
129
140
  export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext>, deps?: Array<() => unknown>): UseLiveQueryReturn<GetResult<TContext>, InferResultType<TContext>>;
130
- export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | undefined | null, deps?: Array<() => unknown>): UseLiveQueryReturn<GetResult<TContext>, InferResultType<TContext> | undefined>;
141
+ export declare function useLiveQuery<TContext extends Context>(queryFn: (q: InitialQueryBuilder) => QueryBuilder<TContext> | undefined | null, deps?: Array<() => unknown>): ConditionalUseLiveQueryReturn<GetResult<TContext>, InferConditionalResultType<TContext>>;
131
142
  /**
132
143
  * Create a live query using configuration object
133
144
  * @param config - Configuration object with query and options
@@ -123,9 +123,13 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
123
123
  let internalData = $state(Array.from(initialSnapshot.state?.values() ?? []));
124
124
  // Track collection status reactively
125
125
  let status = $state(initialSnapshot.status);
126
+ let persistedStatus = $state(initialSnapshot.persistedStatus);
127
+ let persistedError = $state.raw(initialSnapshot.persistedError);
126
128
  const syncFromObserver = (observer, changes) => {
127
129
  const snapshot = observer.getSnapshot();
128
130
  status = snapshot.status;
131
+ persistedStatus = snapshot.persistedStatus;
132
+ persistedError = snapshot.persistedError;
129
133
  untrack(() => {
130
134
  if (changes && changes.length > 0) {
131
135
  for (const change of changes) {
@@ -198,6 +202,15 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
198
202
  get isReady() {
199
203
  return status === `ready` || status === `disabled`;
200
204
  },
205
+ get persistedStatus() {
206
+ return persistedStatus;
207
+ },
208
+ get isPersistedReady() {
209
+ return persistedStatus === `ready`;
210
+ },
211
+ get persistedError() {
212
+ return persistedError;
213
+ },
201
214
  get isIdle() {
202
215
  return status === `idle`;
203
216
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-db",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Svelte integration for @tanstack/db",
5
5
  "author": "Kyle Mathews",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/db": "0.9.2"
38
+ "@tanstack/db": "0.11.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "svelte": "^5.0.0"