@tanstack/svelte-query 5.90.2 → 6.0.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.
Files changed (89) hide show
  1. package/dist/HydrationBoundary.svelte +15 -4
  2. package/dist/HydrationBoundary.svelte.d.ts +9 -19
  3. package/dist/HydrationBoundary.svelte.d.ts.map +1 -1
  4. package/dist/QueryClientProvider.svelte +4 -2
  5. package/dist/QueryClientProvider.svelte.d.ts +4 -19
  6. package/dist/QueryClientProvider.svelte.d.ts.map +1 -1
  7. package/dist/containers.svelte.d.ts +19 -0
  8. package/dist/containers.svelte.d.ts.map +1 -0
  9. package/dist/containers.svelte.js +118 -0
  10. package/dist/context.d.ts +3 -3
  11. package/dist/context.d.ts.map +1 -1
  12. package/dist/context.js +4 -5
  13. package/dist/createBaseQuery.svelte.d.ts +10 -0
  14. package/dist/createBaseQuery.svelte.d.ts.map +1 -0
  15. package/dist/createBaseQuery.svelte.js +58 -0
  16. package/dist/createInfiniteQuery.d.ts +2 -2
  17. package/dist/createInfiniteQuery.d.ts.map +1 -1
  18. package/dist/createInfiniteQuery.js +1 -1
  19. package/dist/createMutation.svelte.d.ts +8 -0
  20. package/dist/createMutation.svelte.d.ts.map +1 -0
  21. package/dist/createMutation.svelte.js +50 -0
  22. package/dist/createQueries.svelte.d.ts +76 -0
  23. package/dist/createQueries.svelte.d.ts.map +1 -0
  24. package/dist/createQueries.svelte.js +39 -0
  25. package/dist/createQuery.d.ts +4 -4
  26. package/dist/createQuery.d.ts.map +1 -1
  27. package/dist/createQuery.js +1 -1
  28. package/dist/index.d.ts +6 -6
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +5 -5
  31. package/dist/types.d.ts +11 -8
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/useIsFetching.svelte.d.ts +4 -0
  34. package/dist/useIsFetching.svelte.d.ts.map +1 -0
  35. package/dist/useIsFetching.svelte.js +7 -0
  36. package/dist/useIsMutating.svelte.d.ts +4 -0
  37. package/dist/useIsMutating.svelte.d.ts.map +1 -0
  38. package/dist/useIsMutating.svelte.js +7 -0
  39. package/dist/useIsRestoring.d.ts +2 -2
  40. package/dist/useIsRestoring.d.ts.map +1 -1
  41. package/dist/{useMutationState.d.ts → useMutationState.svelte.d.ts} +2 -3
  42. package/dist/useMutationState.svelte.d.ts.map +1 -0
  43. package/dist/useMutationState.svelte.js +33 -0
  44. package/dist/utils.svelte.d.ts +4 -0
  45. package/dist/utils.svelte.d.ts.map +1 -0
  46. package/dist/utils.svelte.js +31 -0
  47. package/package.json +9 -3
  48. package/src/HydrationBoundary.svelte +15 -4
  49. package/src/QueryClientProvider.svelte +4 -2
  50. package/src/containers.svelte.ts +123 -0
  51. package/src/context.ts +10 -11
  52. package/src/createBaseQuery.svelte.ts +107 -0
  53. package/src/createInfiniteQuery.ts +4 -4
  54. package/src/createMutation.svelte.ts +91 -0
  55. package/src/{createQueries.ts → createQueries.svelte.ts} +86 -96
  56. package/src/createQuery.ts +15 -17
  57. package/src/index.ts +6 -6
  58. package/src/types.ts +12 -9
  59. package/src/useIsFetching.svelte.ts +16 -0
  60. package/src/useIsMutating.svelte.ts +16 -0
  61. package/src/useIsRestoring.ts +2 -2
  62. package/src/useMutationState.svelte.ts +56 -0
  63. package/src/utils.svelte.ts +44 -0
  64. package/dist/createBaseQuery.d.ts +0 -4
  65. package/dist/createBaseQuery.d.ts.map +0 -1
  66. package/dist/createBaseQuery.js +0 -40
  67. package/dist/createMutation.d.ts +0 -4
  68. package/dist/createMutation.d.ts.map +0 -1
  69. package/dist/createMutation.js +0 -25
  70. package/dist/createQueries.d.ts +0 -77
  71. package/dist/createQueries.d.ts.map +0 -1
  72. package/dist/createQueries.js +0 -40
  73. package/dist/useIsFetching.d.ts +0 -4
  74. package/dist/useIsFetching.d.ts.map +0 -1
  75. package/dist/useIsFetching.js +0 -20
  76. package/dist/useIsMutating.d.ts +0 -4
  77. package/dist/useIsMutating.d.ts.map +0 -1
  78. package/dist/useIsMutating.js +0 -20
  79. package/dist/useMutationState.d.ts.map +0 -1
  80. package/dist/useMutationState.js +0 -23
  81. package/dist/utils.d.ts +0 -4
  82. package/dist/utils.d.ts.map +0 -1
  83. package/dist/utils.js +0 -3
  84. package/src/createBaseQuery.ts +0 -85
  85. package/src/createMutation.ts +0 -54
  86. package/src/useIsFetching.ts +0 -30
  87. package/src/useIsMutating.ts +0 -30
  88. package/src/useMutationState.ts +0 -49
  89. package/src/utils.ts +0 -8
@@ -1,54 +0,0 @@
1
- import { derived, get, readable } from 'svelte/store'
2
- import { MutationObserver, noop, notifyManager } from '@tanstack/query-core'
3
- import { useQueryClient } from './useQueryClient.js'
4
- import { isSvelteStore } from './utils.js'
5
- import type {
6
- CreateMutateFunction,
7
- CreateMutationOptions,
8
- CreateMutationResult,
9
- StoreOrVal,
10
- } from './types.js'
11
- import type { DefaultError, QueryClient } from '@tanstack/query-core'
12
-
13
- export function createMutation<
14
- TData = unknown,
15
- TError = DefaultError,
16
- TVariables = void,
17
- TOnMutateResult = unknown,
18
- >(
19
- options: StoreOrVal<
20
- CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
21
- >,
22
- queryClient?: QueryClient,
23
- ): CreateMutationResult<TData, TError, TVariables, TOnMutateResult> {
24
- const client = useQueryClient(queryClient)
25
-
26
- const optionsStore = isSvelteStore(options) ? options : readable(options)
27
-
28
- const observer = new MutationObserver<
29
- TData,
30
- TError,
31
- TVariables,
32
- TOnMutateResult
33
- >(client, get(optionsStore))
34
- let mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>
35
-
36
- optionsStore.subscribe(($options) => {
37
- mutate = (variables, mutateOptions) => {
38
- observer.mutate(variables, mutateOptions).catch(noop)
39
- }
40
- observer.setOptions($options)
41
- })
42
-
43
- const result = readable(observer.getCurrentResult(), (set) => {
44
- return observer.subscribe(notifyManager.batchCalls((val) => set(val)))
45
- })
46
-
47
- const { subscribe } = derived(result, ($result) => ({
48
- ...$result,
49
- mutate,
50
- mutateAsync: $result.mutate,
51
- }))
52
-
53
- return { subscribe }
54
- }
@@ -1,30 +0,0 @@
1
- import { notifyManager } from '@tanstack/query-core'
2
- import { readable } from 'svelte/store'
3
- import { useQueryClient } from './useQueryClient.js'
4
- import type { Readable } from 'svelte/store'
5
- import type { QueryClient, QueryFilters } from '@tanstack/query-core'
6
-
7
- export function useIsFetching(
8
- filters?: QueryFilters,
9
- queryClient?: QueryClient,
10
- ): Readable<number> {
11
- const client = useQueryClient(queryClient)
12
- const cache = client.getQueryCache()
13
- // isFetching is the prev value initialized on mount *
14
- let isFetching = client.isFetching(filters)
15
-
16
- const { subscribe } = readable(isFetching, (set) => {
17
- return cache.subscribe(
18
- notifyManager.batchCalls(() => {
19
- const newIsFetching = client.isFetching(filters)
20
- if (isFetching !== newIsFetching) {
21
- // * and update with each change
22
- isFetching = newIsFetching
23
- set(isFetching)
24
- }
25
- }),
26
- )
27
- })
28
-
29
- return { subscribe }
30
- }
@@ -1,30 +0,0 @@
1
- import { notifyManager } from '@tanstack/query-core'
2
- import { readable } from 'svelte/store'
3
- import { useQueryClient } from './useQueryClient.js'
4
- import type { Readable } from 'svelte/store'
5
- import type { MutationFilters, QueryClient } from '@tanstack/query-core'
6
-
7
- export function useIsMutating(
8
- filters?: MutationFilters,
9
- queryClient?: QueryClient,
10
- ): Readable<number> {
11
- const client = useQueryClient(queryClient)
12
- const cache = client.getMutationCache()
13
- // isMutating is the prev value initialized on mount *
14
- let isMutating = client.isMutating(filters)
15
-
16
- const { subscribe } = readable(isMutating, (set) => {
17
- return cache.subscribe(
18
- notifyManager.batchCalls(() => {
19
- const newIisMutating = client.isMutating(filters)
20
- if (isMutating !== newIisMutating) {
21
- // * and update with each change
22
- isMutating = newIisMutating
23
- set(isMutating)
24
- }
25
- }),
26
- )
27
- })
28
-
29
- return { subscribe }
30
- }
@@ -1,49 +0,0 @@
1
- import { readable } from 'svelte/store'
2
- import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
3
- import { useQueryClient } from './useQueryClient.js'
4
- import type {
5
- MutationCache,
6
- MutationState,
7
- QueryClient,
8
- } from '@tanstack/query-core'
9
- import type { Readable } from 'svelte/store'
10
- import type { MutationStateOptions } from './types.js'
11
-
12
- function getResult<TResult = MutationState>(
13
- mutationCache: MutationCache,
14
- options: MutationStateOptions<TResult>,
15
- ): Array<TResult> {
16
- return mutationCache
17
- .findAll(options.filters)
18
- .map(
19
- (mutation): TResult =>
20
- (options.select ? options.select(mutation) : mutation.state) as TResult,
21
- )
22
- }
23
-
24
- export function useMutationState<TResult = MutationState>(
25
- options: MutationStateOptions<TResult> = {},
26
- queryClient?: QueryClient,
27
- ): Readable<Array<TResult>> {
28
- const client = useQueryClient(queryClient)
29
- const mutationCache = client.getMutationCache()
30
-
31
- let result = getResult(mutationCache, options)
32
-
33
- const { subscribe } = readable(result, (set) => {
34
- return mutationCache.subscribe(
35
- notifyManager.batchCalls(() => {
36
- const nextResult = replaceEqualDeep(
37
- result,
38
- getResult(mutationCache, options),
39
- )
40
- if (result !== nextResult) {
41
- result = nextResult
42
- set(result)
43
- }
44
- }),
45
- )
46
- })
47
-
48
- return { subscribe }
49
- }
package/src/utils.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { Readable } from 'svelte/store'
2
- import type { StoreOrVal } from './types.js'
3
-
4
- export function isSvelteStore<T extends object>(
5
- obj: StoreOrVal<T>,
6
- ): obj is Readable<T> {
7
- return 'subscribe' in obj && typeof obj.subscribe === 'function'
8
- }