@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
|
@@ -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,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,
|
|
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,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,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,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"}
|
package/dist/createQuery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { createBaseQuery } from './createBaseQuery.js';
|
|
2
|
+
import { createBaseQuery } from './createBaseQuery.svelte.js';
|
|
3
3
|
export function createQuery(options, queryClient) {
|
|
4
4
|
return createBaseQuery(options, QueryObserver, queryClient);
|
|
5
5
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,17 @@ export * from '@tanstack/query-core';
|
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export * from './context.js';
|
|
4
4
|
export { createQuery } from './createQuery.js';
|
|
5
|
-
export type { QueriesResults, QueriesOptions } from './createQueries.js';
|
|
5
|
+
export type { QueriesResults, QueriesOptions } from './createQueries.svelte.js';
|
|
6
6
|
export type { DefinedInitialDataOptions, UndefinedInitialDataOptions, } from './queryOptions.js';
|
|
7
7
|
export { queryOptions } from './queryOptions.js';
|
|
8
|
-
export { createQueries } from './createQueries.js';
|
|
8
|
+
export { createQueries } from './createQueries.svelte.js';
|
|
9
9
|
export { createInfiniteQuery } from './createInfiniteQuery.js';
|
|
10
10
|
export { infiniteQueryOptions } from './infiniteQueryOptions.js';
|
|
11
|
-
export { createMutation } from './createMutation.js';
|
|
12
|
-
export { useMutationState } from './useMutationState.js';
|
|
11
|
+
export { createMutation } from './createMutation.svelte.js';
|
|
12
|
+
export { useMutationState } from './useMutationState.svelte.js';
|
|
13
13
|
export { useQueryClient } from './useQueryClient.js';
|
|
14
|
-
export { useIsFetching } from './useIsFetching.js';
|
|
15
|
-
export { useIsMutating } from './useIsMutating.js';
|
|
14
|
+
export { useIsFetching } from './useIsFetching.svelte.js';
|
|
15
|
+
export { useIsMutating } from './useIsMutating.svelte.js';
|
|
16
16
|
export { useIsRestoring } from './useIsRestoring.js';
|
|
17
17
|
export { useHydrate } from './useHydrate.js';
|
|
18
18
|
export { default as HydrationBoundary } from './HydrationBoundary.svelte';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAA;AAGpC,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,sBAAsB,CAAA;AAGpC,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/E,YAAY,EACV,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACzE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -6,14 +6,14 @@ export * from './types.js';
|
|
|
6
6
|
export * from './context.js';
|
|
7
7
|
export { createQuery } from './createQuery.js';
|
|
8
8
|
export { queryOptions } from './queryOptions.js';
|
|
9
|
-
export { createQueries } from './createQueries.js';
|
|
9
|
+
export { createQueries } from './createQueries.svelte.js';
|
|
10
10
|
export { createInfiniteQuery } from './createInfiniteQuery.js';
|
|
11
11
|
export { infiniteQueryOptions } from './infiniteQueryOptions.js';
|
|
12
|
-
export { createMutation } from './createMutation.js';
|
|
13
|
-
export { useMutationState } from './useMutationState.js';
|
|
12
|
+
export { createMutation } from './createMutation.svelte.js';
|
|
13
|
+
export { useMutationState } from './useMutationState.svelte.js';
|
|
14
14
|
export { useQueryClient } from './useQueryClient.js';
|
|
15
|
-
export { useIsFetching } from './useIsFetching.js';
|
|
16
|
-
export { useIsMutating } from './useIsMutating.js';
|
|
15
|
+
export { useIsFetching } from './useIsFetching.svelte.js';
|
|
16
|
+
export { useIsMutating } from './useIsMutating.svelte.js';
|
|
17
17
|
export { useIsRestoring } from './useIsRestoring.js';
|
|
18
18
|
export { useHydrate } from './useHydrate.js';
|
|
19
19
|
export { default as HydrationBoundary } from './HydrationBoundary.svelte';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export type StoreOrVal<T> = T | Readable<T>;
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { DefaultError, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, Mutation, MutationFilters, MutationObserverOptions, MutationObserverResult, MutationState, OmitKeyof, Override, QueryClient, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
|
|
3
|
+
export type Accessor<T> = () => T;
|
|
5
4
|
/** Options for createBaseQuery */
|
|
6
5
|
export type CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>;
|
|
7
6
|
/** Result from createBaseQuery */
|
|
8
|
-
export type CreateBaseQueryResult<TData = unknown, TError = DefaultError> =
|
|
7
|
+
export type CreateBaseQueryResult<TData = unknown, TError = DefaultError> = QueryObserverResult<TData, TError>;
|
|
9
8
|
/** Options for createQuery */
|
|
10
9
|
export type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>;
|
|
11
10
|
/** Result from createQuery */
|
|
@@ -13,9 +12,9 @@ export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBa
|
|
|
13
12
|
/** Options for createInfiniteQuery */
|
|
14
13
|
export type CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>;
|
|
15
14
|
/** Result from createInfiniteQuery */
|
|
16
|
-
export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> =
|
|
15
|
+
export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverResult<TData, TError>;
|
|
17
16
|
/** Options for createBaseQuery with initialData */
|
|
18
|
-
export type DefinedCreateBaseQueryResult<TData = unknown, TError = DefaultError> =
|
|
17
|
+
export type DefinedCreateBaseQueryResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError>;
|
|
19
18
|
/** Options for createQuery with initialData */
|
|
20
19
|
export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError> = DefinedCreateBaseQueryResult<TData, TError>;
|
|
21
20
|
/** Options for createMutation */
|
|
@@ -28,10 +27,14 @@ export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVa
|
|
|
28
27
|
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult>;
|
|
29
28
|
};
|
|
30
29
|
/** Result from createMutation */
|
|
31
|
-
export type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> =
|
|
30
|
+
export type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TOnMutateResult = unknown> = CreateBaseMutationResult<TData, TError, TVariables, TOnMutateResult>;
|
|
32
31
|
/** Options for useMutationState */
|
|
33
32
|
export type MutationStateOptions<TResult = MutationState> = {
|
|
34
33
|
filters?: MutationFilters;
|
|
35
34
|
select?: (mutation: Mutation<unknown, DefaultError, unknown, unknown>) => TResult;
|
|
36
35
|
};
|
|
36
|
+
export type QueryClientProviderProps = {
|
|
37
|
+
client: QueryClient;
|
|
38
|
+
children: Snippet;
|
|
39
|
+
};
|
|
37
40
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAC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EAAE,WAAW,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactiveValue } from './containers.svelte.js';
|
|
2
|
+
import type { QueryClient, QueryFilters } from '@tanstack/query-core';
|
|
3
|
+
export declare function useIsFetching(filters?: QueryFilters, queryClient?: QueryClient): ReactiveValue<number>;
|
|
4
|
+
//# sourceMappingURL=useIsFetching.svelte.d.ts.map
|
|
@@ -0,0 +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,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,YAAY,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,aAAa,CAAC,MAAM,CAAC,CAQvB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactiveValue } from './containers.svelte.js';
|
|
2
|
+
import { useQueryClient } from './useQueryClient.js';
|
|
3
|
+
export function useIsFetching(filters, queryClient) {
|
|
4
|
+
const client = useQueryClient(queryClient);
|
|
5
|
+
const queryCache = client.getQueryCache();
|
|
6
|
+
return new ReactiveValue(() => client.isFetching(filters), (update) => queryCache.subscribe(update));
|
|
7
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ReactiveValue } from './containers.svelte.js';
|
|
2
|
+
import type { MutationFilters, QueryClient } from '@tanstack/query-core';
|
|
3
|
+
export declare function useIsMutating(filters?: MutationFilters, queryClient?: QueryClient): ReactiveValue<number>;
|
|
4
|
+
//# sourceMappingURL=useIsMutating.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMutating.svelte.d.ts","sourceRoot":"","sources":["../src/useIsMutating.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAExE,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,eAAe,EACzB,WAAW,CAAC,EAAE,WAAW,GACxB,aAAa,CAAC,MAAM,CAAC,CAQvB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useQueryClient } from './useQueryClient.js';
|
|
2
|
+
import { ReactiveValue } from './containers.svelte.js';
|
|
3
|
+
export function useIsMutating(filters, queryClient) {
|
|
4
|
+
const client = useQueryClient(queryClient);
|
|
5
|
+
const cache = client.getMutationCache();
|
|
6
|
+
return new ReactiveValue(() => client.isMutating(filters), (update) => cache.subscribe(update));
|
|
7
|
+
}
|
package/dist/useIsRestoring.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function useIsRestoring():
|
|
1
|
+
import type { Box } from './containers.svelte.js';
|
|
2
|
+
export declare function useIsRestoring(): Box<boolean>;
|
|
3
3
|
//# 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,
|
|
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,5 +1,4 @@
|
|
|
1
1
|
import type { MutationState, QueryClient } from '@tanstack/query-core';
|
|
2
|
-
import type { Readable } from 'svelte/store';
|
|
3
2
|
import type { MutationStateOptions } from './types.js';
|
|
4
|
-
export declare function useMutationState<TResult = MutationState>(options?: MutationStateOptions<TResult>, queryClient?: QueryClient):
|
|
5
|
-
//# sourceMappingURL=useMutationState.d.ts.map
|
|
3
|
+
export declare function useMutationState<TResult = MutationState>(options?: MutationStateOptions<TResult>, queryClient?: QueryClient): Array<TResult>;
|
|
4
|
+
//# sourceMappingURL=useMutationState.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMutationState.svelte.d.ts","sourceRoot":"","sources":["../src/useMutationState.svelte.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AActD,wBAAgB,gBAAgB,CAAC,OAAO,GAAG,aAAa,EACtD,OAAO,GAAE,oBAAoB,CAAC,OAAO,CAAM,EAC3C,WAAW,CAAC,EAAE,WAAW,GACxB,KAAK,CAAC,OAAO,CAAC,CA+BhB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { replaceEqualDeep } from '@tanstack/query-core';
|
|
2
|
+
import { useQueryClient } from './useQueryClient.js';
|
|
3
|
+
function getResult(mutationCache, options) {
|
|
4
|
+
return mutationCache
|
|
5
|
+
.findAll(options.filters)
|
|
6
|
+
.map((mutation) => (options.select ? options.select(mutation) : mutation.state));
|
|
7
|
+
}
|
|
8
|
+
export function useMutationState(options = {}, queryClient) {
|
|
9
|
+
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
10
|
+
const result = $state(getResult(mutationCache, options));
|
|
11
|
+
$effect(() => {
|
|
12
|
+
const unsubscribe = mutationCache.subscribe(() => {
|
|
13
|
+
const nextResult = replaceEqualDeep(result, getResult(mutationCache, options));
|
|
14
|
+
if (result !== nextResult) {
|
|
15
|
+
Object.assign(result, nextResult);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return unsubscribe;
|
|
19
|
+
});
|
|
20
|
+
/* $effect(() => {
|
|
21
|
+
mutationCache.subscribe(() => {
|
|
22
|
+
const nextResult = replaceEqualDeep(
|
|
23
|
+
result.current,
|
|
24
|
+
getResult(mutationCache, optionsRef),
|
|
25
|
+
)
|
|
26
|
+
if (result.current !== nextResult) {
|
|
27
|
+
result = nextResult
|
|
28
|
+
//notifyManager.schedule(onStoreChange)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}) */
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
type Getter<T> = () => T;
|
|
2
|
+
export declare const watchChanges: <T>(sources: Getter<T> | Array<Getter<T>>, flush: "post" | "pre", effect: (values: T | Array<T>, previousValues: T | undefined | Array<T | undefined>) => void) => void;
|
|
3
|
+
export {};
|
|
4
|
+
//# sourceMappingURL=utils.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.svelte.d.ts","sourceRoot":"","sources":["../src/utils.svelte.ts"],"names":[],"mappings":"AAeA,KAAK,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAA;AACxB,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,SAAS,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EACrC,OAAO,MAAM,GAAG,KAAK,EACrB,QAAQ,CACN,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EACpB,cAAc,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC,GAAG,SAAS,CAAC,KACjD,IAAI,SAqBV,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { untrack } from 'svelte';
|
|
2
|
+
// modified from the great https://github.com/svecosystem/runed
|
|
3
|
+
function runEffect(flush, effect) {
|
|
4
|
+
switch (flush) {
|
|
5
|
+
case 'post':
|
|
6
|
+
$effect(effect);
|
|
7
|
+
break;
|
|
8
|
+
case 'pre':
|
|
9
|
+
$effect.pre(effect);
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const watchChanges = (sources, flush, effect) => {
|
|
14
|
+
let active = false;
|
|
15
|
+
let previousValues = Array.isArray(sources)
|
|
16
|
+
? []
|
|
17
|
+
: undefined;
|
|
18
|
+
runEffect(flush, () => {
|
|
19
|
+
const values = Array.isArray(sources)
|
|
20
|
+
? sources.map((source) => source())
|
|
21
|
+
: sources();
|
|
22
|
+
if (!active) {
|
|
23
|
+
active = true;
|
|
24
|
+
previousValues = values;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const cleanup = untrack(() => effect(values, previousValues));
|
|
28
|
+
previousValues = values;
|
|
29
|
+
return cleanup;
|
|
30
|
+
});
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
|
|
5
5
|
"author": "Lachlan Collins",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"type": "github",
|
|
15
15
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
16
|
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"tanstack",
|
|
19
|
+
"query",
|
|
20
|
+
"svelte"
|
|
21
|
+
],
|
|
17
22
|
"type": "module",
|
|
18
23
|
"types": "dist/index.d.ts",
|
|
19
24
|
"module": "dist/index.js",
|
|
@@ -34,19 +39,20 @@
|
|
|
34
39
|
"!src/__tests__"
|
|
35
40
|
],
|
|
36
41
|
"dependencies": {
|
|
37
|
-
"@tanstack/query-core": "5.90.
|
|
42
|
+
"@tanstack/query-core": "5.90.3"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@sveltejs/package": "^2.4.0",
|
|
41
46
|
"@sveltejs/vite-plugin-svelte": "^5.1.1",
|
|
42
47
|
"@testing-library/svelte": "^5.2.8",
|
|
48
|
+
"@typescript-eslint/parser": "^8.44.1",
|
|
43
49
|
"eslint-plugin-svelte": "^3.11.0",
|
|
44
50
|
"svelte": "^5.39.3",
|
|
45
51
|
"svelte-check": "^4.3.1",
|
|
46
52
|
"@tanstack/query-test-utils": "0.0.0"
|
|
47
53
|
},
|
|
48
54
|
"peerDependencies": {
|
|
49
|
-
"svelte": "^
|
|
55
|
+
"svelte": "^5.25.0"
|
|
50
56
|
},
|
|
51
57
|
"scripts": {
|
|
52
58
|
"clean": "premove ./dist ./coverage ./.svelte-kit ./dist-ts",
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useHydrate } from './useHydrate.js'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
3
4
|
import type {
|
|
4
5
|
DehydratedState,
|
|
5
6
|
HydrateOptions,
|
|
6
7
|
QueryClient,
|
|
7
8
|
} from '@tanstack/query-core'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
type Props = {
|
|
11
|
+
children: Snippet
|
|
12
|
+
state: DehydratedState
|
|
13
|
+
options: HydrateOptions | undefined
|
|
14
|
+
queryClient: QueryClient | undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
children,
|
|
19
|
+
state,
|
|
20
|
+
options = undefined,
|
|
21
|
+
queryClient = undefined,
|
|
22
|
+
}: Props = $props()
|
|
12
23
|
|
|
13
24
|
useHydrate(state, options, queryClient)
|
|
14
25
|
</script>
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
{@render children()}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { onDestroy, onMount } from 'svelte'
|
|
3
3
|
import { QueryClient } from '@tanstack/query-core'
|
|
4
4
|
import { setQueryClientContext } from './context.js'
|
|
5
|
+
import type { QueryClientProviderProps } from './types.js'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
const { client = new QueryClient(), children }: QueryClientProviderProps =
|
|
8
|
+
$props()
|
|
7
9
|
|
|
8
10
|
onMount(() => {
|
|
9
11
|
client.mount()
|
|
@@ -16,4 +18,4 @@
|
|
|
16
18
|
})
|
|
17
19
|
</script>
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
{@render children()}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { SvelteSet, createSubscriber } from 'svelte/reactivity'
|
|
2
|
+
|
|
3
|
+
type VoidFn = () => void
|
|
4
|
+
type Subscriber = (update: VoidFn) => void | VoidFn
|
|
5
|
+
|
|
6
|
+
export type Box<T> = { current: T }
|
|
7
|
+
|
|
8
|
+
export class ReactiveValue<T> implements Box<T> {
|
|
9
|
+
#fn
|
|
10
|
+
#subscribe
|
|
11
|
+
|
|
12
|
+
constructor(fn: () => T, onSubscribe: Subscriber) {
|
|
13
|
+
this.#fn = fn
|
|
14
|
+
this.#subscribe = createSubscriber((update) => onSubscribe(update))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get current() {
|
|
18
|
+
this.#subscribe()
|
|
19
|
+
return this.#fn()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Makes all of the top-level keys of an object into $state.raw fields whose initial values
|
|
25
|
+
* are the same as in the original object. Does not mutate the original object. Provides an `update`
|
|
26
|
+
* function that _can_ (but does not have to be) be used to replace all of the object's top-level keys
|
|
27
|
+
* with the values of the new object, while maintaining the original root object's reference.
|
|
28
|
+
*/
|
|
29
|
+
export function createRawRef<T extends {} | Array<unknown>>(
|
|
30
|
+
init: T,
|
|
31
|
+
): [T, (newValue: T) => void] {
|
|
32
|
+
const refObj = (Array.isArray(init) ? [] : {}) as T
|
|
33
|
+
const hiddenKeys = new SvelteSet<PropertyKey>()
|
|
34
|
+
const out = new Proxy(refObj, {
|
|
35
|
+
set(target, prop, value, receiver) {
|
|
36
|
+
hiddenKeys.delete(prop)
|
|
37
|
+
if (prop in target) {
|
|
38
|
+
return Reflect.set(target, prop, value, receiver)
|
|
39
|
+
}
|
|
40
|
+
let state = $state.raw(value)
|
|
41
|
+
Object.defineProperty(target, prop, {
|
|
42
|
+
configurable: true,
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: () => {
|
|
45
|
+
// If this is a lazy value, we need to call it.
|
|
46
|
+
// We can't do something like typeof state === 'function'
|
|
47
|
+
// because the value could actually be a function that we don't want to call.
|
|
48
|
+
return state && isBranded(state) ? state() : state
|
|
49
|
+
},
|
|
50
|
+
set: (v) => {
|
|
51
|
+
state = v
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
return true
|
|
55
|
+
},
|
|
56
|
+
has: (target, prop) => {
|
|
57
|
+
if (hiddenKeys.has(prop)) {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
return prop in target
|
|
61
|
+
},
|
|
62
|
+
ownKeys(target) {
|
|
63
|
+
return Reflect.ownKeys(target).filter((key) => !hiddenKeys.has(key))
|
|
64
|
+
},
|
|
65
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
66
|
+
if (hiddenKeys.has(prop)) {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
return Reflect.getOwnPropertyDescriptor(target, prop)
|
|
70
|
+
},
|
|
71
|
+
deleteProperty(target, prop) {
|
|
72
|
+
if (prop in target) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
// We need to set the value to undefined to signal to the listeners that the value has changed.
|
|
75
|
+
// If we just deleted it, the reactivity system wouldn't have any idea that the value was gone.
|
|
76
|
+
target[prop] = undefined
|
|
77
|
+
hiddenKeys.add(prop)
|
|
78
|
+
if (Array.isArray(target)) {
|
|
79
|
+
target.length--
|
|
80
|
+
}
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
return false
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
function update(newValue: T) {
|
|
88
|
+
const existingKeys = Object.keys(out)
|
|
89
|
+
const newKeys = Object.keys(newValue)
|
|
90
|
+
const keysToRemove = existingKeys.filter((key) => !newKeys.includes(key))
|
|
91
|
+
for (const key of keysToRemove) {
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
delete out[key]
|
|
94
|
+
}
|
|
95
|
+
for (const key of newKeys) {
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
// This craziness is required because Tanstack Query defines getters for all of the keys on the object.
|
|
98
|
+
// These getters track property access, so if we access all of them here, we'll end up tracking everything.
|
|
99
|
+
// So we wrap the property access in a special function that we can identify later to lazily access the value.
|
|
100
|
+
// (See above)
|
|
101
|
+
out[key] = brand(() => newValue[key])
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// we can't pass `init` directly into the proxy because it'll never set the state fields
|
|
106
|
+
// (because (prop in target) will always be true)
|
|
107
|
+
update(init)
|
|
108
|
+
|
|
109
|
+
return [out, update]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const lazyBrand = Symbol('LazyValue')
|
|
113
|
+
type Branded<T extends () => unknown> = T & { [lazyBrand]: true }
|
|
114
|
+
|
|
115
|
+
function brand<T extends () => unknown>(fn: T): Branded<T> {
|
|
116
|
+
// @ts-expect-error
|
|
117
|
+
fn[lazyBrand] = true
|
|
118
|
+
return fn as Branded<T>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isBranded<T extends () => unknown>(fn: T): fn is Branded<T> {
|
|
122
|
+
return Boolean((fn as Branded<T>)[lazyBrand])
|
|
123
|
+
}
|
package/src/context.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { getContext, setContext } from 'svelte'
|
|
2
|
-
import { readable } from 'svelte/store'
|
|
3
2
|
import type { QueryClient } from '@tanstack/query-core'
|
|
4
|
-
import type {
|
|
3
|
+
import type { Box } from './containers.svelte'
|
|
5
4
|
|
|
6
|
-
const _contextKey = '
|
|
5
|
+
const _contextKey = Symbol('QueryClient')
|
|
7
6
|
|
|
8
7
|
/** Retrieves a Client from Svelte's context */
|
|
9
8
|
export const getQueryClientContext = (): QueryClient => {
|
|
10
|
-
const client = getContext(_contextKey)
|
|
9
|
+
const client = getContext<QueryClient | undefined>(_contextKey)
|
|
11
10
|
if (!client) {
|
|
12
11
|
throw new Error(
|
|
13
12
|
'No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?',
|
|
14
13
|
)
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
return client
|
|
16
|
+
return client
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/** Sets a QueryClient on Svelte's context */
|
|
@@ -22,21 +21,21 @@ export const setQueryClientContext = (client: QueryClient): void => {
|
|
|
22
21
|
setContext(_contextKey, client)
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
const _isRestoringContextKey = '
|
|
24
|
+
const _isRestoringContextKey = Symbol('isRestoring')
|
|
26
25
|
|
|
27
26
|
/** Retrieves a `isRestoring` from Svelte's context */
|
|
28
|
-
export const getIsRestoringContext = ():
|
|
27
|
+
export const getIsRestoringContext = (): Box<boolean> => {
|
|
29
28
|
try {
|
|
30
|
-
const isRestoring = getContext<
|
|
29
|
+
const isRestoring = getContext<Box<boolean> | undefined>(
|
|
31
30
|
_isRestoringContextKey,
|
|
32
31
|
)
|
|
33
|
-
return isRestoring
|
|
32
|
+
return isRestoring ?? { current: false }
|
|
34
33
|
} catch (error) {
|
|
35
|
-
return
|
|
34
|
+
return { current: false }
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
/** Sets a `isRestoring` on Svelte's context */
|
|
40
|
-
export const setIsRestoringContext = (isRestoring:
|
|
39
|
+
export const setIsRestoringContext = (isRestoring: Box<boolean>): void => {
|
|
41
40
|
setContext(_isRestoringContextKey, isRestoring)
|
|
42
41
|
}
|