@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.
- package/dist/HydrationBoundary.svelte +15 -4
- package/dist/HydrationBoundary.svelte.d.ts +9 -19
- package/dist/HydrationBoundary.svelte.d.ts.map +1 -1
- package/dist/QueryClientProvider.svelte +4 -2
- package/dist/QueryClientProvider.svelte.d.ts +4 -19
- package/dist/QueryClientProvider.svelte.d.ts.map +1 -1
- package/dist/containers.svelte.d.ts +19 -0
- package/dist/containers.svelte.d.ts.map +1 -0
- package/dist/containers.svelte.js +118 -0
- package/dist/context.d.ts +3 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +4 -5
- package/dist/createBaseQuery.svelte.d.ts +10 -0
- package/dist/createBaseQuery.svelte.d.ts.map +1 -0
- package/dist/createBaseQuery.svelte.js +58 -0
- package/dist/createInfiniteQuery.d.ts +2 -2
- package/dist/createInfiniteQuery.d.ts.map +1 -1
- package/dist/createInfiniteQuery.js +1 -1
- package/dist/createMutation.svelte.d.ts +8 -0
- package/dist/createMutation.svelte.d.ts.map +1 -0
- package/dist/createMutation.svelte.js +50 -0
- package/dist/createQueries.svelte.d.ts +76 -0
- package/dist/createQueries.svelte.d.ts.map +1 -0
- package/dist/createQueries.svelte.js +39 -0
- package/dist/createQuery.d.ts +4 -4
- package/dist/createQuery.d.ts.map +1 -1
- package/dist/createQuery.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/types.d.ts +11 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/useIsFetching.svelte.d.ts +4 -0
- package/dist/useIsFetching.svelte.d.ts.map +1 -0
- package/dist/useIsFetching.svelte.js +7 -0
- package/dist/useIsMutating.svelte.d.ts +4 -0
- package/dist/useIsMutating.svelte.d.ts.map +1 -0
- package/dist/useIsMutating.svelte.js +7 -0
- package/dist/useIsRestoring.d.ts +2 -2
- package/dist/useIsRestoring.d.ts.map +1 -1
- package/dist/{useMutationState.d.ts → useMutationState.svelte.d.ts} +2 -3
- package/dist/useMutationState.svelte.d.ts.map +1 -0
- package/dist/useMutationState.svelte.js +33 -0
- package/dist/utils.svelte.d.ts +4 -0
- package/dist/utils.svelte.d.ts.map +1 -0
- package/dist/utils.svelte.js +31 -0
- package/package.json +9 -3
- package/src/HydrationBoundary.svelte +15 -4
- package/src/QueryClientProvider.svelte +4 -2
- package/src/containers.svelte.ts +123 -0
- package/src/context.ts +10 -11
- package/src/createBaseQuery.svelte.ts +107 -0
- package/src/createInfiniteQuery.ts +4 -4
- package/src/createMutation.svelte.ts +91 -0
- package/src/{createQueries.ts → createQueries.svelte.ts} +86 -96
- package/src/createQuery.ts +15 -17
- package/src/index.ts +6 -6
- package/src/types.ts +12 -9
- package/src/useIsFetching.svelte.ts +16 -0
- package/src/useIsMutating.svelte.ts +16 -0
- package/src/useIsRestoring.ts +2 -2
- package/src/useMutationState.svelte.ts +56 -0
- package/src/utils.svelte.ts +44 -0
- package/dist/createBaseQuery.d.ts +0 -4
- package/dist/createBaseQuery.d.ts.map +0 -1
- package/dist/createBaseQuery.js +0 -40
- package/dist/createMutation.d.ts +0 -4
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -25
- package/dist/createQueries.d.ts +0 -77
- package/dist/createQueries.d.ts.map +0 -1
- package/dist/createQueries.js +0 -40
- package/dist/useIsFetching.d.ts +0 -4
- package/dist/useIsFetching.d.ts.map +0 -1
- package/dist/useIsFetching.js +0 -20
- package/dist/useIsMutating.d.ts +0 -4
- package/dist/useIsMutating.d.ts.map +0 -1
- package/dist/useIsMutating.js +0 -20
- package/dist/useMutationState.d.ts.map +0 -1
- package/dist/useMutationState.js +0 -23
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -3
- package/src/createBaseQuery.ts +0 -85
- package/src/createMutation.ts +0 -54
- package/src/useIsFetching.ts +0 -30
- package/src/useIsMutating.ts +0 -30
- package/src/useMutationState.ts +0 -49
- package/src/utils.ts +0 -8
package/src/createMutation.ts
DELETED
|
@@ -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
|
-
}
|
package/src/useIsFetching.ts
DELETED
|
@@ -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
|
-
}
|
package/src/useIsMutating.ts
DELETED
|
@@ -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
|
-
}
|
package/src/useMutationState.ts
DELETED
|
@@ -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