@tanstack/svelte-query 6.2.1 → 6.2.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"createBaseQuery.svelte.d.ts","sourceRoot":"","sources":["../src/createBaseQuery.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,QAAQ,CACf,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAC3E,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CA6EtC"}
1
+ {"version":3,"file":"createBaseQuery.svelte.d.ts","sourceRoot":"","sources":["../src/createBaseQuery.svelte.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,QAAQ,CACf,sBAAsB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAC3E,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAkGtC"}
@@ -1,3 +1,4 @@
1
+ import { onDestroy } from 'svelte';
1
2
  import { useIsRestoring } from './useIsRestoring.js';
2
3
  import { useQueryClient } from './useQueryClient.js';
3
4
  import { createRawRef } from './containers.svelte.js';
@@ -32,13 +33,30 @@ export function createBaseQuery(options, Observer, queryClient) {
32
33
  const [query, update] = createRawRef(
33
34
  // svelte-ignore state_referenced_locally - intentional, initial value
34
35
  createResult());
35
- $effect(() => {
36
- const unsubscribe = isRestoring.current
36
+ // The following is convoluted but necessary:
37
+ // Call eagerly so subscription happens on the server and on suspended branches in the client...
38
+ let unsubscribe = isRestoring.current && typeof window !== 'undefined'
39
+ ? () => undefined
40
+ : observer.subscribe(() => update(createResult()));
41
+ // ...but also watch for state changes to resubscribe, and because Svelte right now doesn't
42
+ // run onDestroy on components with pending work that are destroyed again before they are resolved...
43
+ watchChanges(() => [isRestoring.current, observer], 'pre', () => {
44
+ unsubscribe();
45
+ unsubscribe = isRestoring.current
37
46
  ? () => undefined
38
47
  : observer.subscribe(() => update(createResult()));
39
48
  observer.updateResult();
40
49
  return unsubscribe;
41
50
  });
51
+ // ...and finally also cleanup via onDestroy because that one runs on the server whereas $effect.pre does not.
52
+ // (in a try-catch because it theoretically can be called in a non-component context - that should not happen
53
+ // but it would be a breaking change technically to error out here. SSR-safe because this wouldn't be called during SSR if it was not in a component)
54
+ try {
55
+ onDestroy(() => {
56
+ unsubscribe();
57
+ });
58
+ }
59
+ catch (e) { }
42
60
  watchChanges(() => resolvedOptions, 'pre', () => {
43
61
  observer.setOptions(resolvedOptions);
44
62
  });
@@ -1,9 +1,42 @@
1
1
  import type { DefaultError, InfiniteData, QueryClient, QueryKey } from '@tanstack/query-core';
2
2
  import type { Accessor, CreateInfiniteQueryOptions, CreateInfiniteQueryResult, DefinedCreateInfiniteQueryResult } from './types.js';
3
3
  import type { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions } from './infiniteQueryOptions.js';
4
+ /**
5
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
6
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
7
+ *
8
+ * This overload is selected when `initialData` is set.
9
+ *
10
+ * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
11
+ * like `queryClient.infiniteQuery`.
12
+ * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
13
+ * `createInfiniteQuery`, with `initialData` set, wrapped in an {@link Accessor} so options can be reactive.
14
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
15
+ * be used.
16
+ * @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
17
+ * to page through the query.
18
+ */
4
19
  export declare function createInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: Accessor<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): DefinedCreateInfiniteQueryResult<TData, TError>;
20
+ /**
21
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
22
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
23
+ *
24
+ * This overload is selected when `initialData` is not set.
25
+ *
26
+ * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
27
+ * like `queryClient.infiniteQuery`.
28
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
29
+ * `createInfiniteQuery`, wrapped in an {@link Accessor} so options can be reactive.
30
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
31
+ * be used.
32
+ * @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
33
+ * to page through the query.
34
+ */
5
35
  export declare function createInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: Accessor<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
6
36
  /**
37
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
38
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
39
+ *
7
40
  * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
8
41
  * like `queryClient.infiniteQuery`.
9
42
  * @param options - The {@link CreateInfiniteQueryOptions} to use — everything you can pass to
@@ -1 +1 @@
1
- {"version":3,"file":"createInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/createInfiniteQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,QAAQ,EAET,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,QAAQ,EACR,0BAA0B,EAC1B,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,iCAAiC,EACjC,mCAAmC,EACpC,MAAM,2BAA2B,CAAA;AAElC,wBAAgB,mBAAmB,CACjC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,OAAO,EAAE,QAAQ,CACf,iCAAiC,CAC/B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,SAAS,EACT,UAAU,CACX,CACF,EACD,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,gCAAgC,CAAC,KAAK,EAA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C,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA"}
@@ -65,6 +65,8 @@ export type QueriesResults<T extends Array<any>, TResults extends Array<any> = [
65
65
  [K in keyof T]: GetCreateQueryResult<T[K]>;
66
66
  };
67
67
  /**
68
+ * The `createQueries` function can be used to fetch a variable number of queries.
69
+ *
68
70
  * @param createQueriesOptions - The `queries` array to run, and an optional `combine` function, wrapped in an
69
71
  * {@link Accessor} so options can be reactive.
70
72
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context
@@ -1 +1 @@
1
- {"version":3,"file":"createQueries.svelte.d.ts","sourceRoot":"","sources":["../src/createQueries.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EAET,8BAA8B,EAC9B,WAAW,EACX,aAAa,EACb,QAAQ,EACR,YAAY,EACb,MAAM,sBAAsB,CAAA;AAI7B,KAAK,kCAAkC,CACrC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,SAAS,CACX,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAC1D,iBAAiB,CAClB,GAAG;IACF,eAAe,CAAC,EAAE,YAAY,GAAG,8BAA8B,CAAC,YAAY,CAAC,CAAA;CAC9E,CAAA;AAGD,KAAK,aAAa,GAAG,EAAE,CAAA;AAGvB,KAAK,yBAAyB,GAAG,MAAM,CAAA;AAEvC,KAAK,qCAAqC,CAAC,CAAC,IAE1C,CAAC,SAAS;IACR,WAAW,EAAE,MAAM,YAAY,CAAA;IAC/B,KAAK,CAAC,EAAE,MAAM,MAAM,CAAA;IACpB,IAAI,E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AG,cAAc,CAAC,CAAC,CAAC,CAAC,GAC/B,SAAS;QACP,GAAG;aAAG,CAAC,IAAI,MAAM,CAAC,GAAG,qCAAqC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAAE;KACnE,CAAA;IACL,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAA;CACzD,CAAC,EACF,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,eAAe,CAoDjB"}
@@ -3,6 +3,8 @@ import { useIsRestoring } from './useIsRestoring.js';
3
3
  import { createRawRef } from './containers.svelte.js';
4
4
  import { useQueryClient } from './useQueryClient.js';
5
5
  /**
6
+ * The `createQueries` function can be used to fetch a variable number of queries.
7
+ *
6
8
  * @param createQueriesOptions - The `queries` array to run, and an optional `combine` function, wrapped in an
7
9
  * {@link Accessor} so options can be reactive.
8
10
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context
@@ -2,6 +2,9 @@ import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core';
2
2
  import type { Accessor, CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types.js';
3
3
  import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './queryOptions.js';
4
4
  /**
5
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
6
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
7
+ *
5
8
  * @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
6
9
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `createQuery`,
7
10
  * wrapped in an {@link Accessor} so options can be reactive.
@@ -62,6 +65,9 @@ import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './q
62
65
  */
63
66
  export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: Accessor<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: Accessor<QueryClient>): CreateQueryResult<TData, TError>;
64
67
  /**
68
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
69
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
70
+ *
65
71
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
66
72
  *
67
73
  * @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
@@ -1 +1 @@
1
- {"version":3,"file":"createQuery.d.ts","sourceRoot":"","sources":["../src/createQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/E,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,WAAW,CACzB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,QAAQ,CACf,2BAA2B,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,CACpE,EACD,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,WAAW,CACzB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,QAAQ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AY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,CACpE,EACD,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,WAAW,CACzB,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,QAAQ,CACf,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,CAClE,EACD,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,wBAAwB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;AACH,wBAAgB,WAAW,CACzB,YAAY,EACZ,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,EAC7E,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,GAClC,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA"}
@@ -1,6 +1,9 @@
1
1
  import { ReactiveValue } from './containers.svelte.js';
2
2
  import type { QueryClient, QueryFilters } from '@tanstack/query-core';
3
3
  /**
4
+ * The `useIsFetching` function returns the `number` of the queries that your application is loading or
5
+ * fetching in the background (useful for app-wide loading indicators).
6
+ *
4
7
  * @param filters - {@link QueryFilters} to narrow down which queries to count. Omit to count every fetching
5
8
  * query.
6
9
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
@@ -1 +1 @@
1
- {"version":3,"file":"useIsFetching.svelte.d.ts","sourceRoot":"","sources":["../src/useIsFetching.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,YAAY,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,aAAa,CAAC,MAAM,CAAC,CAQvB"}
1
+ {"version":3,"file":"useIsFetching.svelte.d.ts","sourceRoot":"","sources":["../src/useIsFetching.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,YAAY,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,aAAa,CAAC,MAAM,CAAC,CAQvB"}
@@ -1,6 +1,9 @@
1
1
  import { ReactiveValue } from './containers.svelte.js';
2
2
  import { useQueryClient } from './useQueryClient.js';
3
3
  /**
4
+ * The `useIsFetching` function returns the `number` of the queries that your application is loading or
5
+ * fetching in the background (useful for app-wide loading indicators).
6
+ *
4
7
  * @param filters - {@link QueryFilters} to narrow down which queries to count. Omit to count every fetching
5
8
  * query.
6
9
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
@@ -1,7 +1,7 @@
1
1
  import { ReactiveValue } from './containers.svelte.js';
2
2
  import type { MutationFilters, QueryClient } from '@tanstack/query-core';
3
3
  /**
4
- * `useIsMutating` is an optional hook that returns the `number` of mutations that your application is
4
+ * `useIsMutating` is an optional function that returns the `number` of mutations that your application is
5
5
  * running (useful for app-wide loading indicators).
6
6
  *
7
7
  * @param filters - {@link MutationFilters} to narrow down which mutations to count.
@@ -1,7 +1,7 @@
1
1
  import { useQueryClient } from './useQueryClient.js';
2
2
  import { ReactiveValue } from './containers.svelte.js';
3
3
  /**
4
- * `useIsMutating` is an optional hook that returns the `number` of mutations that your application is
4
+ * `useIsMutating` is an optional function that returns the `number` of mutations that your application is
5
5
  * running (useful for app-wide loading indicators).
6
6
  *
7
7
  * @param filters - {@link MutationFilters} to narrow down which mutations to count.
@@ -1,3 +1,23 @@
1
1
  import type { Box } from './containers.svelte.js';
2
+ /**
3
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
4
+ * check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
5
+ * race conditions between the restore and mounting queries.
6
+ *
7
+ * @returns A reactive box — read `.current` for `true` while a persisted client is being restored, `false`
8
+ * otherwise.
9
+ * @example
10
+ * ```svelte
11
+ * <script lang="ts">
12
+ * import { useIsRestoring } from '@tanstack/svelte-query'
13
+ *
14
+ * const isRestoring = useIsRestoring()
15
+ * </script>
16
+ *
17
+ * {#if isRestoring.current}
18
+ * <div>Restoring cached data...</div>
19
+ * {/if}
20
+ * ```
21
+ */
2
22
  export declare function useIsRestoring(): Box<boolean>;
3
23
  //# sourceMappingURL=useIsRestoring.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIsRestoring.d.ts","sourceRoot":"","sources":["../src/useIsRestoring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;AAEjD,wBAAgB,cAAc,IAAI,GAAG,CAAC,OAAO,CAAC,CAE7C"}
1
+ {"version":3,"file":"useIsRestoring.d.ts","sourceRoot":"","sources":["../src/useIsRestoring.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,IAAI,GAAG,CAAC,OAAO,CAAC,CAE7C"}
@@ -1,4 +1,24 @@
1
1
  import { getIsRestoringContext } from './context.js';
2
+ /**
3
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
4
+ * check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
5
+ * race conditions between the restore and mounting queries.
6
+ *
7
+ * @returns A reactive box — read `.current` for `true` while a persisted client is being restored, `false`
8
+ * otherwise.
9
+ * @example
10
+ * ```svelte
11
+ * <script lang="ts">
12
+ * import { useIsRestoring } from '@tanstack/svelte-query'
13
+ *
14
+ * const isRestoring = useIsRestoring()
15
+ * </script>
16
+ *
17
+ * {#if isRestoring.current}
18
+ * <div>Restoring cached data...</div>
19
+ * {/if}
20
+ * ```
21
+ */
2
22
  export function useIsRestoring() {
3
23
  return getIsRestoringContext();
4
24
  }
@@ -1,3 +1,23 @@
1
1
  import type { QueryClient } from '@tanstack/query-core';
2
+ /**
3
+ * The `useQueryClient` function returns the current `QueryClient` instance.
4
+ *
5
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
6
+ * be used.
7
+ * @returns The current `QueryClient` instance.
8
+ * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
9
+ * @example
10
+ * ```svelte
11
+ * <script lang="ts">
12
+ * import { useQueryClient } from '@tanstack/svelte-query'
13
+ *
14
+ * const queryClient = useQueryClient()
15
+ *
16
+ * function refreshPosts() {
17
+ * queryClient.invalidateQueries({ queryKey: ['posts'] })
18
+ * }
19
+ * </script>
20
+ * ```
21
+ */
2
22
  export declare function useQueryClient(queryClient?: QueryClient): QueryClient;
3
23
  //# sourceMappingURL=useQueryClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQueryClient.d.ts","sourceRoot":"","sources":["../src/useQueryClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,wBAAgB,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,WAAW,CAGrE"}
1
+ {"version":3,"file":"useQueryClient.d.ts","sourceRoot":"","sources":["../src/useQueryClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,WAAW,CAGrE"}
@@ -1,4 +1,24 @@
1
1
  import { getQueryClientContext } from './context.js';
2
+ /**
3
+ * The `useQueryClient` function returns the current `QueryClient` instance.
4
+ *
5
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
6
+ * be used.
7
+ * @returns The current `QueryClient` instance.
8
+ * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
9
+ * @example
10
+ * ```svelte
11
+ * <script lang="ts">
12
+ * import { useQueryClient } from '@tanstack/svelte-query'
13
+ *
14
+ * const queryClient = useQueryClient()
15
+ *
16
+ * function refreshPosts() {
17
+ * queryClient.invalidateQueries({ queryKey: ['posts'] })
18
+ * }
19
+ * </script>
20
+ * ```
21
+ */
2
22
  export function useQueryClient(queryClient) {
3
23
  if (queryClient)
4
24
  return queryClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-query",
3
- "version": "6.2.1",
3
+ "version": "6.2.3",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
5
5
  "author": "Lachlan Collins",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "!src/__tests__"
40
40
  ],
41
41
  "dependencies": {
42
- "@tanstack/query-core": "5.103.1"
42
+ "@tanstack/query-core": "5.103.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@sveltejs/package": "^2.5.8",
@@ -1,3 +1,4 @@
1
+ import { onDestroy } from 'svelte'
1
2
  import { useIsRestoring } from './useIsRestoring.js'
2
3
  import { useQueryClient } from './useQueryClient.js'
3
4
  import { createRawRef } from './containers.svelte.js'
@@ -71,13 +72,34 @@ export function createBaseQuery<
71
72
  createResult(),
72
73
  )
73
74
 
74
- $effect(() => {
75
- const unsubscribe = isRestoring.current
75
+ // The following is convoluted but necessary:
76
+ // Call eagerly so subscription happens on the server and on suspended branches in the client...
77
+ let unsubscribe =
78
+ isRestoring.current && typeof window !== 'undefined'
76
79
  ? () => undefined
77
80
  : observer.subscribe(() => update(createResult()))
78
- observer.updateResult()
79
- return unsubscribe
80
- })
81
+ // ...but also watch for state changes to resubscribe, and because Svelte right now doesn't
82
+ // run onDestroy on components with pending work that are destroyed again before they are resolved...
83
+ watchChanges(
84
+ () => [isRestoring.current, observer] as const,
85
+ 'pre',
86
+ () => {
87
+ unsubscribe()
88
+ unsubscribe = isRestoring.current
89
+ ? () => undefined
90
+ : observer.subscribe(() => update(createResult()))
91
+ observer.updateResult()
92
+ return unsubscribe
93
+ },
94
+ )
95
+ // ...and finally also cleanup via onDestroy because that one runs on the server whereas $effect.pre does not.
96
+ // (in a try-catch because it theoretically can be called in a non-component context - that should not happen
97
+ // but it would be a breaking change technically to error out here. SSR-safe because this wouldn't be called during SSR if it was not in a component)
98
+ try {
99
+ onDestroy(() => {
100
+ unsubscribe()
101
+ })
102
+ } catch (e) {}
81
103
 
82
104
  watchChanges(
83
105
  () => resolvedOptions,
@@ -18,6 +18,21 @@ import type {
18
18
  UndefinedInitialDataInfiniteOptions,
19
19
  } from './infiniteQueryOptions.js'
20
20
 
21
+ /**
22
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
23
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
24
+ *
25
+ * This overload is selected when `initialData` is set.
26
+ *
27
+ * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
28
+ * like `queryClient.infiniteQuery`.
29
+ * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
30
+ * `createInfiniteQuery`, with `initialData` set, wrapped in an {@link Accessor} so options can be reactive.
31
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
32
+ * be used.
33
+ * @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
34
+ * to page through the query.
35
+ */
21
36
  export function createInfiniteQuery<
22
37
  TQueryFnData = unknown,
23
38
  TError = DefaultError,
@@ -37,6 +52,21 @@ export function createInfiniteQuery<
37
52
  queryClient?: Accessor<QueryClient>,
38
53
  ): DefinedCreateInfiniteQueryResult<TData, TError>
39
54
 
55
+ /**
56
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
57
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
58
+ *
59
+ * This overload is selected when `initialData` is not set.
60
+ *
61
+ * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
62
+ * like `queryClient.infiniteQuery`.
63
+ * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
64
+ * `createInfiniteQuery`, wrapped in an {@link Accessor} so options can be reactive.
65
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
66
+ * be used.
67
+ * @returns The current query result, plus `fetchNextPage`/`fetchPreviousPage`/`hasNextPage`/`hasPreviousPage`
68
+ * to page through the query.
69
+ */
40
70
  export function createInfiniteQuery<
41
71
  TQueryFnData = unknown,
42
72
  TError = DefaultError,
@@ -57,6 +87,9 @@ export function createInfiniteQuery<
57
87
  ): CreateInfiniteQueryResult<TData, TError>
58
88
 
59
89
  /**
90
+ * The options for `createInfiniteQuery` are identical to `createQuery`, with the addition of
91
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
92
+ *
60
93
  * @see {@link infiniteQueryOptions} to share these options between `createInfiniteQuery` and imperative APIs
61
94
  * like `queryClient.infiniteQuery`.
62
95
  * @param options - The {@link CreateInfiniteQueryOptions} to use — everything you can pass to
@@ -187,6 +187,8 @@ export type QueriesResults<
187
187
  : { [K in keyof T]: GetCreateQueryResult<T[K]> }
188
188
 
189
189
  /**
190
+ * The `createQueries` function can be used to fetch a variable number of queries.
191
+ *
190
192
  * @param createQueriesOptions - The `queries` array to run, and an optional `combine` function, wrapped in an
191
193
  * {@link Accessor} so options can be reactive.
192
194
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context
@@ -13,6 +13,9 @@ import type {
13
13
  } from './queryOptions.js'
14
14
 
15
15
  /**
16
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
17
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
18
+ *
16
19
  * @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
17
20
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `createQuery`,
18
21
  * wrapped in an {@link Accessor} so options can be reactive.
@@ -84,6 +87,9 @@ export function createQuery<
84
87
  ): CreateQueryResult<TData, TError>
85
88
 
86
89
  /**
90
+ * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
91
+ * The query runs when the options call for it — `enabled: false` skips the initial fetch.
92
+ *
87
93
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.
88
94
  *
89
95
  * @see {@link queryOptions} to share these options between `createQuery` and imperative APIs like `queryClient.query`.
@@ -3,6 +3,9 @@ import { useQueryClient } from './useQueryClient.js'
3
3
  import type { QueryClient, QueryFilters } from '@tanstack/query-core'
4
4
 
5
5
  /**
6
+ * The `useIsFetching` function returns the `number` of the queries that your application is loading or
7
+ * fetching in the background (useful for app-wide loading indicators).
8
+ *
6
9
  * @param filters - {@link QueryFilters} to narrow down which queries to count. Omit to count every fetching
7
10
  * query.
8
11
  * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
@@ -3,7 +3,7 @@ import { ReactiveValue } from './containers.svelte.js'
3
3
  import type { MutationFilters, QueryClient } from '@tanstack/query-core'
4
4
 
5
5
  /**
6
- * `useIsMutating` is an optional hook that returns the `number` of mutations that your application is
6
+ * `useIsMutating` is an optional function that returns the `number` of mutations that your application is
7
7
  * running (useful for app-wide loading indicators).
8
8
  *
9
9
  * @param filters - {@link MutationFilters} to narrow down which mutations to count.
@@ -1,6 +1,26 @@
1
1
  import { getIsRestoringContext } from './context.js'
2
2
  import type { Box } from './containers.svelte.js'
3
3
 
4
+ /**
5
+ * If you are using `PersistQueryClientProvider`, you can also use the `useIsRestoring` function alongside it to
6
+ * check if a restore is currently in progress. `createQuery` and friends also check this internally to avoid
7
+ * race conditions between the restore and mounting queries.
8
+ *
9
+ * @returns A reactive box — read `.current` for `true` while a persisted client is being restored, `false`
10
+ * otherwise.
11
+ * @example
12
+ * ```svelte
13
+ * <script lang="ts">
14
+ * import { useIsRestoring } from '@tanstack/svelte-query'
15
+ *
16
+ * const isRestoring = useIsRestoring()
17
+ * </script>
18
+ *
19
+ * {#if isRestoring.current}
20
+ * <div>Restoring cached data...</div>
21
+ * {/if}
22
+ * ```
23
+ */
4
24
  export function useIsRestoring(): Box<boolean> {
5
25
  return getIsRestoringContext()
6
26
  }
@@ -1,6 +1,26 @@
1
1
  import { getQueryClientContext } from './context.js'
2
2
  import type { QueryClient } from '@tanstack/query-core'
3
3
 
4
+ /**
5
+ * The `useQueryClient` function returns the current `QueryClient` instance.
6
+ *
7
+ * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
8
+ * be used.
9
+ * @returns The current `QueryClient` instance.
10
+ * @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
11
+ * @example
12
+ * ```svelte
13
+ * <script lang="ts">
14
+ * import { useQueryClient } from '@tanstack/svelte-query'
15
+ *
16
+ * const queryClient = useQueryClient()
17
+ *
18
+ * function refreshPosts() {
19
+ * queryClient.invalidateQueries({ queryKey: ['posts'] })
20
+ * }
21
+ * </script>
22
+ * ```
23
+ */
4
24
  export function useQueryClient(queryClient?: QueryClient): QueryClient {
5
25
  if (queryClient) return queryClient
6
26
  return getQueryClientContext()