@tanstack/svelte-query 5.0.0-alpha.0 → 5.0.0-alpha.2
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/build/lib/createBaseQuery.d.ts +2 -2
- package/build/lib/createBaseQuery.js +23 -19
- package/build/lib/createInfiniteQuery.d.ts +3 -3
- package/build/lib/createInfiniteQuery.js +3 -1
- package/build/lib/createMutation.d.ts +3 -3
- package/build/lib/createMutation.js +6 -5
- package/build/lib/createQueries.d.ts +5 -5
- package/build/lib/createQueries.js +10 -10
- package/build/lib/createQuery.d.ts +6 -6
- package/build/lib/types.d.ts +16 -15
- package/build/lib/utils.d.ts +3 -0
- package/build/lib/utils.js +3 -0
- package/package.json +2 -2
- package/src/__tests__/CreateQueries.svelte +1 -1
- package/src/__tests__/CreateQuery.svelte +13 -2
- package/src/__tests__/createQuery.test.ts +36 -0
- package/src/createBaseQuery.ts +43 -36
- package/src/createInfiniteQuery.ts +13 -9
- package/src/createMutation.ts +15 -9
- package/src/createQueries.ts +16 -16
- package/src/createQuery.ts +16 -13
- package/src/types.ts +18 -18
- package/src/utils.ts +8 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import type { CreateBaseQueryOptions, CreateBaseQueryResult } from './types';
|
|
3
|
-
export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey
|
|
2
|
+
import type { CreateBaseQueryOptions, CreateBaseQueryResult, WritableOrVal } from './types';
|
|
3
|
+
export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: WritableOrVal<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>>, Observer: typeof QueryObserver, queryClient?: QueryClient): CreateBaseQueryResult<TData, TError>;
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
import { notifyManager } from '@tanstack/query-core';
|
|
2
2
|
import { useQueryClient } from './useQueryClient';
|
|
3
|
-
import { derived, readable } from 'svelte/store';
|
|
3
|
+
import { derived, get, readable, writable } from 'svelte/store';
|
|
4
|
+
import { isWritable } from './utils';
|
|
4
5
|
export function createBaseQuery(options, Observer, queryClient) {
|
|
5
6
|
const client = useQueryClient(queryClient);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
const optionsStore = isWritable(options) ? options : writable(options);
|
|
8
|
+
const defaultedOptionsStore = derived(optionsStore, ($options) => {
|
|
9
|
+
const defaultedOptions = client.defaultQueryOptions($options);
|
|
10
|
+
defaultedOptions._optimisticResults = 'optimistic';
|
|
11
|
+
// Include callbacks in batch renders
|
|
12
|
+
if (defaultedOptions.onError) {
|
|
13
|
+
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
|
14
|
+
}
|
|
15
|
+
if (defaultedOptions.onSuccess) {
|
|
16
|
+
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
17
|
+
}
|
|
18
|
+
if (defaultedOptions.onSettled) {
|
|
19
|
+
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
20
|
+
}
|
|
21
|
+
return defaultedOptions;
|
|
22
|
+
});
|
|
23
|
+
const observer = new Observer(client, get(defaultedOptionsStore));
|
|
24
|
+
defaultedOptionsStore.subscribe(($defaultedOptions) => {
|
|
21
25
|
// Do not notify on updates because of changes in the options because
|
|
22
26
|
// these changes should already be reflected in the optimistic result.
|
|
23
|
-
observer.setOptions(defaultedOptions, { listeners: false });
|
|
27
|
+
observer.setOptions($defaultedOptions, { listeners: false });
|
|
24
28
|
});
|
|
25
29
|
const result = readable(observer.getCurrentResult(), (set) => {
|
|
26
30
|
return observer.subscribe(notifyManager.batchCalls(set));
|
|
27
31
|
});
|
|
28
32
|
const { subscribe } = derived(result, ($result) => {
|
|
29
|
-
$result = observer.getOptimisticResult(
|
|
30
|
-
return !
|
|
33
|
+
$result = observer.getOptimisticResult(get(defaultedOptionsStore));
|
|
34
|
+
return !get(defaultedOptionsStore).notifyOnChangeProps
|
|
31
35
|
? observer.trackResult($result)
|
|
32
36
|
: $result;
|
|
33
37
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { QueryKey, QueryClient,
|
|
2
|
-
import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult } from './types';
|
|
3
|
-
export declare function createInfiniteQuery<TQueryFnData, TError =
|
|
1
|
+
import type { QueryKey, QueryClient, DefaultError, InfiniteData } from '@tanstack/query-core';
|
|
2
|
+
import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult, WritableOrVal } from './types';
|
|
3
|
+
export declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: WritableOrVal<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>>, queryClient?: QueryClient): CreateInfiniteQueryResult<TData, TError>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
2
|
import { createBaseQuery } from './createBaseQuery';
|
|
3
3
|
export function createInfiniteQuery(options, queryClient) {
|
|
4
|
-
return createBaseQuery(options,
|
|
4
|
+
return createBaseQuery(options,
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
6
|
+
InfiniteQueryObserver, queryClient);
|
|
5
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { QueryClient,
|
|
2
|
-
import type { CreateMutationOptions, CreateMutationResult } from './types';
|
|
3
|
-
export declare function createMutation<TData = unknown, TError =
|
|
1
|
+
import type { QueryClient, DefaultError } from '@tanstack/query-core';
|
|
2
|
+
import type { CreateMutationOptions, CreateMutationResult, WritableOrVal } from './types';
|
|
3
|
+
export declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: WritableOrVal<CreateMutationOptions<TData, TError, TVariables, TContext>>, queryClient?: QueryClient): CreateMutationResult<TData, TError, TVariables, TContext>;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { readable, derived } from 'svelte/store';
|
|
1
|
+
import { readable, derived, writable, get } from 'svelte/store';
|
|
2
2
|
import { MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
3
3
|
import { useQueryClient } from './useQueryClient';
|
|
4
|
+
import { isWritable } from './utils';
|
|
4
5
|
export function createMutation(options, queryClient) {
|
|
5
6
|
const client = useQueryClient(queryClient);
|
|
6
|
-
|
|
7
|
+
const optionsStore = isWritable(options) ? options : writable(options);
|
|
8
|
+
const observer = new MutationObserver(client, get(optionsStore));
|
|
7
9
|
let mutate;
|
|
8
|
-
|
|
9
|
-
observer = $observer;
|
|
10
|
+
optionsStore.subscribe(($options) => {
|
|
10
11
|
mutate = (variables, mutateOptions) => {
|
|
11
12
|
observer.mutate(variables, mutateOptions).catch(noop);
|
|
12
13
|
};
|
|
13
|
-
observer.setOptions(options);
|
|
14
|
+
observer.setOptions($options);
|
|
14
15
|
});
|
|
15
16
|
const result = readable(observer.getCurrentResult(), (set) => {
|
|
16
17
|
return observer.subscribe(notifyManager.batchCalls((val) => set(val)));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { QueryKey, QueryFunction, QueryClient, QueriesPlaceholderDataFunction, QueryObserverResult,
|
|
1
|
+
import type { QueryKey, QueryFunction, QueryClient, QueriesPlaceholderDataFunction, QueryObserverResult, DefaultError } from '@tanstack/query-core';
|
|
2
2
|
import { type Readable } from 'svelte/store';
|
|
3
|
-
import type { CreateQueryOptions } from './types';
|
|
4
|
-
declare type CreateQueryOptionsForCreateQueries<TQueryFnData = unknown, TError =
|
|
3
|
+
import type { CreateQueryOptions, WritableOrVal } from './types';
|
|
4
|
+
declare type CreateQueryOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'placeholderData'> & {
|
|
5
5
|
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
|
|
6
6
|
};
|
|
7
7
|
declare type MAXIMUM_DEPTH = 20;
|
|
@@ -44,10 +44,10 @@ export declare type QueriesOptions<T extends any[], Result extends any[] = [], D
|
|
|
44
44
|
/**
|
|
45
45
|
* QueriesResults reducer recursively maps type param to results
|
|
46
46
|
*/
|
|
47
|
-
export declare type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? QueryObserverResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>[] ? QueryObserverResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ?
|
|
47
|
+
export declare type QueriesResults<T extends any[], Result extends any[] = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? QueryObserverResult[] : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>[] ? QueryObserverResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>[] : QueryObserverResult[];
|
|
48
48
|
export declare type CreateQueriesResult<T extends any[]> = Readable<QueriesResults<T>>;
|
|
49
49
|
export declare function createQueries<T extends any[]>({ queries, queryClient, }: {
|
|
50
|
-
queries:
|
|
50
|
+
queries: WritableOrVal<[...QueriesOptions<T>]>;
|
|
51
51
|
queryClient?: QueryClient;
|
|
52
52
|
}): CreateQueriesResult<T>;
|
|
53
53
|
export {};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core';
|
|
2
|
-
import { readable } from 'svelte/store';
|
|
2
|
+
import { derived, get, readable, writable } from 'svelte/store';
|
|
3
3
|
import { useQueryClient } from './useQueryClient';
|
|
4
|
+
import { isWritable } from './utils';
|
|
4
5
|
export function createQueries({ queries, queryClient, }) {
|
|
5
6
|
const client = useQueryClient(queryClient);
|
|
6
7
|
// const isRestoring = useIsRestoring()
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const queriesStore = isWritable(queries) ? queries : writable(queries);
|
|
9
|
+
const defaultedQueriesStore = derived(queriesStore, ($queries) => {
|
|
10
|
+
return $queries.map((options) => {
|
|
9
11
|
const defaultedOptions = client.defaultQueryOptions(options);
|
|
10
12
|
// Make sure the results are already in fetching state before subscribing or updating options
|
|
11
13
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
12
14
|
return defaultedOptions;
|
|
13
15
|
});
|
|
14
|
-
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
readable(observer).subscribe(($observer) => {
|
|
18
|
-
observer = $observer;
|
|
16
|
+
});
|
|
17
|
+
const observer = new QueriesObserver(client, get(defaultedQueriesStore));
|
|
18
|
+
defaultedQueriesStore.subscribe(($defaultedQueries) => {
|
|
19
19
|
// Do not notify on updates because of changes in the options because
|
|
20
20
|
// these changes should already be reflected in the optimistic result.
|
|
21
|
-
observer.setQueries(defaultedQueries, { listeners: false });
|
|
21
|
+
observer.setQueries($defaultedQueries, { listeners: false });
|
|
22
22
|
});
|
|
23
|
-
const { subscribe } = readable(observer.getOptimisticResult(
|
|
23
|
+
const { subscribe } = readable(observer.getOptimisticResult(get(defaultedQueriesStore)), (set) => {
|
|
24
24
|
return observer.subscribe(notifyManager.batchCalls(set));
|
|
25
25
|
});
|
|
26
26
|
return { subscribe };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { QueryKey, QueryClient,
|
|
2
|
-
import type { DefinedCreateQueryResult, CreateQueryOptions, CreateQueryResult } from './types';
|
|
3
|
-
declare type UndefinedInitialDataOptions<TQueryFnData = unknown, TError =
|
|
1
|
+
import type { QueryKey, QueryClient, DefaultError } from '@tanstack/query-core';
|
|
2
|
+
import type { DefinedCreateQueryResult, CreateQueryOptions, CreateQueryResult, WritableOrVal } from './types';
|
|
3
|
+
declare type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
4
4
|
initialData?: undefined;
|
|
5
5
|
};
|
|
6
|
-
declare type DefinedInitialDataOptions<TQueryFnData = unknown, TError =
|
|
6
|
+
declare type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
7
7
|
initialData: TQueryFnData | (() => TQueryFnData);
|
|
8
8
|
};
|
|
9
|
-
export declare function createQuery<TQueryFnData = unknown, TError =
|
|
10
|
-
export declare function createQuery<TQueryFnData = unknown, TError =
|
|
9
|
+
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: WritableOrVal<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: QueryClient): CreateQueryResult<TData, TError>;
|
|
10
|
+
export declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: WritableOrVal<DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>>, queryClient?: QueryClient): DefinedCreateQueryResult<TData, TError>;
|
|
11
11
|
export {};
|
package/build/lib/types.d.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import type { InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutationObserverResult, QueryObserverOptions, QueryObserverResult, QueryKey, MutationObserverOptions, MutateFunction, DefinedQueryObserverResult,
|
|
1
|
+
import type { InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutationObserverResult, QueryObserverOptions, QueryObserverResult, QueryKey, MutationObserverOptions, MutateFunction, DefinedQueryObserverResult, DefaultError } from '@tanstack/query-core';
|
|
2
2
|
import type { QueryClient } from '@tanstack/query-core';
|
|
3
|
-
import type { Readable } from 'svelte/store';
|
|
3
|
+
import type { Readable, Writable } from 'svelte/store';
|
|
4
|
+
export declare type WritableOrVal<T> = T | Writable<T>;
|
|
4
5
|
export interface ContextOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Use this to pass your Svelte Query context. Otherwise, `defaultContext` will be used.
|
|
7
8
|
*/
|
|
8
9
|
context?: QueryClient | undefined;
|
|
9
10
|
}
|
|
10
|
-
export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError =
|
|
11
|
+
export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends ContextOptions, QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
|
|
11
12
|
}
|
|
12
|
-
export interface CreateBaseQueryResult<TData = unknown, TError =
|
|
13
|
+
export interface CreateBaseQueryResult<TData = unknown, TError = DefaultError> extends Readable<QueryObserverResult<TData, TError>> {
|
|
13
14
|
}
|
|
14
|
-
export interface CreateQueryOptions<TQueryFnData = unknown, TError =
|
|
15
|
+
export interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> {
|
|
15
16
|
}
|
|
16
|
-
export interface CreateQueryResult<TData = unknown, TError =
|
|
17
|
+
export interface CreateQueryResult<TData = unknown, TError = DefaultError> extends CreateBaseQueryResult<TData, TError> {
|
|
17
18
|
}
|
|
18
|
-
export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError =
|
|
19
|
+
export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam> {
|
|
19
20
|
}
|
|
20
|
-
export declare type CreateInfiniteQueryResult<TData = unknown, TError =
|
|
21
|
-
export declare type DefinedCreateBaseQueryResult<TData = unknown, TError =
|
|
22
|
-
export declare type DefinedCreateQueryResult<TData = unknown, TError =
|
|
23
|
-
export interface CreateMutationOptions<TData = unknown, TError =
|
|
21
|
+
export declare type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = Readable<InfiniteQueryObserverResult<TData, TError>>;
|
|
22
|
+
export declare type DefinedCreateBaseQueryResult<TData = unknown, TError = DefaultError> = Readable<DefinedQueryObserverResult<TData, TError>>;
|
|
23
|
+
export declare type DefinedCreateQueryResult<TData = unknown, TError = DefaultError> = DefinedCreateBaseQueryResult<TData, TError>;
|
|
24
|
+
export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends ContextOptions, Omit<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted' | 'variables'> {
|
|
24
25
|
}
|
|
25
|
-
export declare type CreateMutateFunction<TData = unknown, TError =
|
|
26
|
-
export declare type CreateMutateAsyncFunction<TData = unknown, TError =
|
|
27
|
-
export declare type CreateBaseMutationResult<TData = unknown, TError =
|
|
26
|
+
export declare type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
|
|
27
|
+
export declare type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
|
|
28
|
+
export declare type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
|
|
28
29
|
mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
|
|
29
30
|
}> & {
|
|
30
31
|
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
|
|
31
32
|
};
|
|
32
|
-
export interface CreateMutationResult<TData = unknown, TError =
|
|
33
|
+
export interface CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> extends Readable<CreateBaseMutationResult<TData, TError, TVariables, TContext>> {
|
|
33
34
|
}
|
|
34
35
|
declare type Override<A, B> = {
|
|
35
36
|
[K in keyof A]: K extends keyof B ? B[K] : A[K];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-query",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.2",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
|
|
5
5
|
"author": "Dre Johnson",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"vitest": "^0.27.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tanstack/query-core": "5.0.0-alpha.
|
|
31
|
+
"@tanstack/query-core": "5.0.0-alpha.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"svelte": "^3.54.0"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { setQueryClientContext } from '../context'
|
|
4
4
|
import type { QueriesOptions } from '../createQueries'
|
|
5
5
|
|
|
6
|
-
export let options: { queries:
|
|
6
|
+
export let options: { queries: [...QueriesOptions<any>] }
|
|
7
7
|
|
|
8
8
|
const queryClient = new QueryClient()
|
|
9
9
|
setQueryClientContext(queryClient)
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
createQuery,
|
|
4
|
+
QueryClient,
|
|
5
|
+
type CreateQueryOptions,
|
|
6
|
+
type WritableOrVal,
|
|
7
|
+
} from '../index'
|
|
3
8
|
import { setQueryClientContext } from '../context'
|
|
4
9
|
|
|
5
|
-
export let options: CreateQueryOptions<any
|
|
10
|
+
export let options: WritableOrVal<CreateQueryOptions<any>>
|
|
6
11
|
|
|
7
12
|
const queryClient = new QueryClient()
|
|
8
13
|
setQueryClientContext(queryClient)
|
|
@@ -17,3 +22,9 @@
|
|
|
17
22
|
{:else if $query.isSuccess}
|
|
18
23
|
<p>Success</p>
|
|
19
24
|
{/if}
|
|
25
|
+
|
|
26
|
+
<ul>
|
|
27
|
+
{#each $query.data ?? [] as entry}
|
|
28
|
+
<li>id: {entry.id}</li>
|
|
29
|
+
{/each}
|
|
30
|
+
</ul>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
2
|
import { render, waitFor } from '@testing-library/svelte'
|
|
3
|
+
import { writable } from 'svelte/store'
|
|
3
4
|
import CreateQuery from './CreateQuery.svelte'
|
|
4
5
|
import { sleep } from './utils'
|
|
6
|
+
import type { CreateQueryOptions, WritableOrVal } from '../types'
|
|
5
7
|
|
|
6
8
|
describe('createQuery', () => {
|
|
7
9
|
it('Render and wait for success', async () => {
|
|
@@ -25,4 +27,38 @@ describe('createQuery', () => {
|
|
|
25
27
|
expect(rendered.getByText('Success')).toBeInTheDocument()
|
|
26
28
|
})
|
|
27
29
|
})
|
|
30
|
+
|
|
31
|
+
it('should keep previous data when returned as placeholder data', async () => {
|
|
32
|
+
const options: WritableOrVal<CreateQueryOptions> = writable({
|
|
33
|
+
queryKey: ['test', [1]],
|
|
34
|
+
queryFn: async ({ queryKey }) => {
|
|
35
|
+
await sleep(50)
|
|
36
|
+
const ids = queryKey[1]
|
|
37
|
+
if (!ids || !Array.isArray(ids)) return []
|
|
38
|
+
return ids.map((id) => ({ id }))
|
|
39
|
+
},
|
|
40
|
+
placeholderData: (previousData: { id: number }[]) => previousData,
|
|
41
|
+
})
|
|
42
|
+
const rendered = render(CreateQuery, { props: { options } })
|
|
43
|
+
|
|
44
|
+
expect(rendered.queryByText('id: 1')).not.toBeInTheDocument()
|
|
45
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument()
|
|
46
|
+
|
|
47
|
+
await sleep(100)
|
|
48
|
+
|
|
49
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument()
|
|
50
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument()
|
|
51
|
+
|
|
52
|
+
options.update((o) => ({ ...o, queryKey: ['test', [1, 2]] }))
|
|
53
|
+
|
|
54
|
+
await sleep(0)
|
|
55
|
+
|
|
56
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument()
|
|
57
|
+
expect(rendered.queryByText('id: 2')).not.toBeInTheDocument()
|
|
58
|
+
|
|
59
|
+
await sleep(100)
|
|
60
|
+
|
|
61
|
+
expect(rendered.queryByText('id: 1')).toBeInTheDocument()
|
|
62
|
+
expect(rendered.queryByText('id: 2')).toBeInTheDocument()
|
|
63
|
+
})
|
|
28
64
|
})
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'
|
|
2
2
|
import { notifyManager } from '@tanstack/query-core'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
CreateBaseQueryOptions,
|
|
5
|
+
CreateBaseQueryResult,
|
|
6
|
+
WritableOrVal,
|
|
7
|
+
} from './types'
|
|
4
8
|
import { useQueryClient } from './useQueryClient'
|
|
5
|
-
import { derived, readable } from 'svelte/store'
|
|
9
|
+
import { derived, get, readable, writable } from 'svelte/store'
|
|
10
|
+
import { isWritable } from './utils'
|
|
6
11
|
|
|
7
12
|
export function createBaseQuery<
|
|
8
13
|
TQueryFnData,
|
|
@@ -11,52 +16,54 @@ export function createBaseQuery<
|
|
|
11
16
|
TQueryData,
|
|
12
17
|
TQueryKey extends QueryKey,
|
|
13
18
|
>(
|
|
14
|
-
options:
|
|
15
|
-
TQueryFnData,
|
|
16
|
-
TError,
|
|
17
|
-
TData,
|
|
18
|
-
TQueryData,
|
|
19
|
-
TQueryKey
|
|
19
|
+
options: WritableOrVal<
|
|
20
|
+
CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
|
|
20
21
|
>,
|
|
21
22
|
Observer: typeof QueryObserver,
|
|
22
23
|
queryClient?: QueryClient,
|
|
23
24
|
): CreateBaseQueryResult<TData, TError> {
|
|
24
25
|
const client = useQueryClient(queryClient)
|
|
25
|
-
const defaultedOptions = client.defaultQueryOptions(options)
|
|
26
|
-
defaultedOptions._optimisticResults = 'optimistic'
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
const optionsStore = isWritable(options) ? options : writable(options)
|
|
28
|
+
|
|
29
|
+
const defaultedOptionsStore = derived(optionsStore, ($options) => {
|
|
30
|
+
const defaultedOptions = client.defaultQueryOptions($options)
|
|
31
|
+
defaultedOptions._optimisticResults = 'optimistic'
|
|
32
|
+
|
|
33
|
+
// Include callbacks in batch renders
|
|
34
|
+
if (defaultedOptions.onError) {
|
|
35
|
+
defaultedOptions.onError = notifyManager.batchCalls(
|
|
36
|
+
defaultedOptions.onError,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (defaultedOptions.onSuccess) {
|
|
41
|
+
defaultedOptions.onSuccess = notifyManager.batchCalls(
|
|
42
|
+
defaultedOptions.onSuccess,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (defaultedOptions.onSettled) {
|
|
47
|
+
defaultedOptions.onSettled = notifyManager.batchCalls(
|
|
48
|
+
defaultedOptions.onSettled,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return defaultedOptions
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const observer = new Observer<
|
|
29
56
|
TQueryFnData,
|
|
30
57
|
TError,
|
|
31
58
|
TData,
|
|
32
59
|
TQueryData,
|
|
33
60
|
TQueryKey
|
|
34
|
-
>(client,
|
|
35
|
-
|
|
36
|
-
// Include callbacks in batch renders
|
|
37
|
-
if (defaultedOptions.onError) {
|
|
38
|
-
defaultedOptions.onError = notifyManager.batchCalls(
|
|
39
|
-
defaultedOptions.onError,
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (defaultedOptions.onSuccess) {
|
|
44
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(
|
|
45
|
-
defaultedOptions.onSuccess,
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (defaultedOptions.onSettled) {
|
|
50
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(
|
|
51
|
-
defaultedOptions.onSettled,
|
|
52
|
-
)
|
|
53
|
-
}
|
|
61
|
+
>(client, get(defaultedOptionsStore))
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
observer = $observer
|
|
63
|
+
defaultedOptionsStore.subscribe(($defaultedOptions) => {
|
|
57
64
|
// Do not notify on updates because of changes in the options because
|
|
58
65
|
// these changes should already be reflected in the optimistic result.
|
|
59
|
-
observer.setOptions(defaultedOptions, { listeners: false })
|
|
66
|
+
observer.setOptions($defaultedOptions, { listeners: false })
|
|
60
67
|
})
|
|
61
68
|
|
|
62
69
|
const result = readable(observer.getCurrentResult(), (set) => {
|
|
@@ -64,8 +71,8 @@ export function createBaseQuery<
|
|
|
64
71
|
})
|
|
65
72
|
|
|
66
73
|
const { subscribe } = derived(result, ($result) => {
|
|
67
|
-
$result = observer.getOptimisticResult(
|
|
68
|
-
return !
|
|
74
|
+
$result = observer.getOptimisticResult(get(defaultedOptionsStore))
|
|
75
|
+
return !get(defaultedOptionsStore).notifyOnChangeProps
|
|
69
76
|
? observer.trackResult($result)
|
|
70
77
|
: $result
|
|
71
78
|
})
|
|
@@ -2,35 +2,39 @@ import type {
|
|
|
2
2
|
QueryObserver,
|
|
3
3
|
QueryKey,
|
|
4
4
|
QueryClient,
|
|
5
|
-
|
|
5
|
+
DefaultError,
|
|
6
6
|
InfiniteData,
|
|
7
7
|
} from '@tanstack/query-core'
|
|
8
8
|
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
9
9
|
import type {
|
|
10
10
|
CreateInfiniteQueryOptions,
|
|
11
11
|
CreateInfiniteQueryResult,
|
|
12
|
+
WritableOrVal,
|
|
12
13
|
} from './types'
|
|
13
14
|
import { createBaseQuery } from './createBaseQuery'
|
|
14
15
|
|
|
15
16
|
export function createInfiniteQuery<
|
|
16
17
|
TQueryFnData,
|
|
17
|
-
TError =
|
|
18
|
+
TError = DefaultError,
|
|
18
19
|
TData = InfiniteData<TQueryFnData>,
|
|
19
20
|
TQueryKey extends QueryKey = QueryKey,
|
|
20
21
|
TPageParam = unknown,
|
|
21
22
|
>(
|
|
22
|
-
options:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
options: WritableOrVal<
|
|
24
|
+
CreateInfiniteQueryOptions<
|
|
25
|
+
TQueryFnData,
|
|
26
|
+
TError,
|
|
27
|
+
TData,
|
|
28
|
+
TQueryFnData,
|
|
29
|
+
TQueryKey,
|
|
30
|
+
TPageParam
|
|
31
|
+
>
|
|
29
32
|
>,
|
|
30
33
|
queryClient?: QueryClient,
|
|
31
34
|
): CreateInfiniteQueryResult<TData, TError> {
|
|
32
35
|
return createBaseQuery(
|
|
33
36
|
options,
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
34
38
|
InfiniteQueryObserver as typeof QueryObserver,
|
|
35
39
|
queryClient,
|
|
36
40
|
) as CreateInfiniteQueryResult<TData, TError>
|
package/src/createMutation.ts
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
|
-
import { readable, derived } from 'svelte/store'
|
|
2
|
-
import type { QueryClient,
|
|
1
|
+
import { readable, derived, writable, get } from 'svelte/store'
|
|
2
|
+
import type { QueryClient, DefaultError } from '@tanstack/query-core'
|
|
3
3
|
import { MutationObserver, notifyManager } from '@tanstack/query-core'
|
|
4
4
|
import type {
|
|
5
5
|
CreateMutateFunction,
|
|
6
6
|
CreateMutationOptions,
|
|
7
7
|
CreateMutationResult,
|
|
8
|
+
WritableOrVal,
|
|
8
9
|
} from './types'
|
|
9
10
|
import { useQueryClient } from './useQueryClient'
|
|
11
|
+
import { isWritable } from './utils'
|
|
10
12
|
|
|
11
13
|
export function createMutation<
|
|
12
14
|
TData = unknown,
|
|
13
|
-
TError =
|
|
15
|
+
TError = DefaultError,
|
|
14
16
|
TVariables = void,
|
|
15
17
|
TContext = unknown,
|
|
16
18
|
>(
|
|
17
|
-
options:
|
|
19
|
+
options: WritableOrVal<
|
|
20
|
+
CreateMutationOptions<TData, TError, TVariables, TContext>
|
|
21
|
+
>,
|
|
18
22
|
queryClient?: QueryClient,
|
|
19
23
|
): CreateMutationResult<TData, TError, TVariables, TContext> {
|
|
20
24
|
const client = useQueryClient(queryClient)
|
|
21
|
-
|
|
25
|
+
|
|
26
|
+
const optionsStore = isWritable(options) ? options : writable(options)
|
|
27
|
+
|
|
28
|
+
const observer = new MutationObserver<TData, TError, TVariables, TContext>(
|
|
22
29
|
client,
|
|
23
|
-
|
|
30
|
+
get(optionsStore),
|
|
24
31
|
)
|
|
25
32
|
let mutate: CreateMutateFunction<TData, TError, TVariables, TContext>
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
observer = $observer
|
|
34
|
+
optionsStore.subscribe(($options) => {
|
|
29
35
|
mutate = (variables, mutateOptions) => {
|
|
30
36
|
observer.mutate(variables, mutateOptions).catch(noop)
|
|
31
37
|
}
|
|
32
|
-
observer.setOptions(options)
|
|
38
|
+
observer.setOptions($options)
|
|
33
39
|
})
|
|
34
40
|
|
|
35
41
|
const result = readable(observer.getCurrentResult(), (set) => {
|
package/src/createQueries.ts
CHANGED
|
@@ -4,20 +4,21 @@ import type {
|
|
|
4
4
|
QueryClient,
|
|
5
5
|
QueriesPlaceholderDataFunction,
|
|
6
6
|
QueryObserverResult,
|
|
7
|
-
|
|
7
|
+
DefaultError,
|
|
8
8
|
} from '@tanstack/query-core'
|
|
9
9
|
|
|
10
10
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
11
|
-
import { readable, type Readable } from 'svelte/store'
|
|
11
|
+
import { derived, get, readable, writable, type Readable } from 'svelte/store'
|
|
12
12
|
|
|
13
|
-
import type { CreateQueryOptions } from './types'
|
|
13
|
+
import type { CreateQueryOptions, WritableOrVal } from './types'
|
|
14
14
|
import { useQueryClient } from './useQueryClient'
|
|
15
|
+
import { isWritable } from './utils'
|
|
15
16
|
|
|
16
17
|
// This defines the `CreateQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
|
|
17
18
|
// `placeholderData` function does not have a parameter
|
|
18
19
|
type CreateQueryOptionsForCreateQueries<
|
|
19
20
|
TQueryFnData = unknown,
|
|
20
|
-
TError =
|
|
21
|
+
TError = DefaultError,
|
|
21
22
|
TData = TQueryFnData,
|
|
22
23
|
TQueryKey extends QueryKey = QueryKey,
|
|
23
24
|
> = Omit<
|
|
@@ -144,7 +145,7 @@ export type QueriesResults<
|
|
|
144
145
|
? // Dynamic-size (homogenous) CreateQueryOptions array: map directly to array of results
|
|
145
146
|
QueryObserverResult<
|
|
146
147
|
unknown extends TData ? TQueryFnData : TData,
|
|
147
|
-
unknown extends TError ?
|
|
148
|
+
unknown extends TError ? DefaultError : TError
|
|
148
149
|
>[]
|
|
149
150
|
: // Fallback
|
|
150
151
|
QueryObserverResult[]
|
|
@@ -155,34 +156,33 @@ export function createQueries<T extends any[]>({
|
|
|
155
156
|
queries,
|
|
156
157
|
queryClient,
|
|
157
158
|
}: {
|
|
158
|
-
queries:
|
|
159
|
+
queries: WritableOrVal<[...QueriesOptions<T>]>
|
|
159
160
|
queryClient?: QueryClient
|
|
160
161
|
}): CreateQueriesResult<T> {
|
|
161
162
|
const client = useQueryClient(queryClient)
|
|
162
163
|
// const isRestoring = useIsRestoring()
|
|
163
164
|
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
const queriesStore = isWritable(queries) ? queries : writable(queries)
|
|
166
|
+
|
|
167
|
+
const defaultedQueriesStore = derived(queriesStore, ($queries) => {
|
|
168
|
+
return $queries.map((options) => {
|
|
166
169
|
const defaultedOptions = client.defaultQueryOptions(options)
|
|
167
170
|
// Make sure the results are already in fetching state before subscribing or updating options
|
|
168
171
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
169
172
|
|
|
170
173
|
return defaultedOptions
|
|
171
174
|
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const defaultedQueries = getDefaultQuery(queries)
|
|
175
|
-
let observer = new QueriesObserver(client, defaultedQueries)
|
|
175
|
+
})
|
|
176
|
+
const observer = new QueriesObserver(client, get(defaultedQueriesStore))
|
|
176
177
|
|
|
177
|
-
|
|
178
|
-
observer = $observer
|
|
178
|
+
defaultedQueriesStore.subscribe(($defaultedQueries) => {
|
|
179
179
|
// Do not notify on updates because of changes in the options because
|
|
180
180
|
// these changes should already be reflected in the optimistic result.
|
|
181
|
-
observer.setQueries(defaultedQueries, { listeners: false })
|
|
181
|
+
observer.setQueries($defaultedQueries, { listeners: false })
|
|
182
182
|
})
|
|
183
183
|
|
|
184
184
|
const { subscribe } = readable(
|
|
185
|
-
observer.getOptimisticResult(
|
|
185
|
+
observer.getOptimisticResult(get(defaultedQueriesStore)) as any,
|
|
186
186
|
(set) => {
|
|
187
187
|
return observer.subscribe(notifyManager.batchCalls(set))
|
|
188
188
|
},
|
package/src/createQuery.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { QueryObserver } from '@tanstack/query-core'
|
|
2
|
-
import type {
|
|
3
|
-
QueryKey,
|
|
4
|
-
QueryClient,
|
|
5
|
-
RegisteredError,
|
|
6
|
-
} from '@tanstack/query-core'
|
|
2
|
+
import type { QueryKey, QueryClient, DefaultError } from '@tanstack/query-core'
|
|
7
3
|
import { createBaseQuery } from './createBaseQuery'
|
|
8
4
|
import type {
|
|
9
5
|
DefinedCreateQueryResult,
|
|
10
6
|
CreateQueryOptions,
|
|
11
7
|
CreateQueryResult,
|
|
8
|
+
WritableOrVal,
|
|
12
9
|
} from './types'
|
|
13
10
|
|
|
14
11
|
type UndefinedInitialDataOptions<
|
|
15
12
|
TQueryFnData = unknown,
|
|
16
|
-
TError =
|
|
13
|
+
TError = DefaultError,
|
|
17
14
|
TData = TQueryFnData,
|
|
18
15
|
TQueryKey extends QueryKey = QueryKey,
|
|
19
16
|
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
@@ -22,7 +19,7 @@ type UndefinedInitialDataOptions<
|
|
|
22
19
|
|
|
23
20
|
type DefinedInitialDataOptions<
|
|
24
21
|
TQueryFnData = unknown,
|
|
25
|
-
TError =
|
|
22
|
+
TError = DefaultError,
|
|
26
23
|
TData = TQueryFnData,
|
|
27
24
|
TQueryKey extends QueryKey = QueryKey,
|
|
28
25
|
> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
@@ -31,31 +28,37 @@ type DefinedInitialDataOptions<
|
|
|
31
28
|
|
|
32
29
|
export function createQuery<
|
|
33
30
|
TQueryFnData = unknown,
|
|
34
|
-
TError =
|
|
31
|
+
TError = DefaultError,
|
|
35
32
|
TData = TQueryFnData,
|
|
36
33
|
TQueryKey extends QueryKey = QueryKey,
|
|
37
34
|
>(
|
|
38
|
-
options:
|
|
35
|
+
options: WritableOrVal<
|
|
36
|
+
UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
37
|
+
>,
|
|
39
38
|
queryClient?: QueryClient,
|
|
40
39
|
): CreateQueryResult<TData, TError>
|
|
41
40
|
|
|
42
41
|
export function createQuery<
|
|
43
42
|
TQueryFnData = unknown,
|
|
44
|
-
TError =
|
|
43
|
+
TError = DefaultError,
|
|
45
44
|
TData = TQueryFnData,
|
|
46
45
|
TQueryKey extends QueryKey = QueryKey,
|
|
47
46
|
>(
|
|
48
|
-
options:
|
|
47
|
+
options: WritableOrVal<
|
|
48
|
+
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
49
|
+
>,
|
|
49
50
|
queryClient?: QueryClient,
|
|
50
51
|
): DefinedCreateQueryResult<TData, TError>
|
|
51
52
|
|
|
52
53
|
export function createQuery<
|
|
53
54
|
TQueryFnData,
|
|
54
|
-
TError =
|
|
55
|
+
TError = DefaultError,
|
|
55
56
|
TData = TQueryFnData,
|
|
56
57
|
TQueryKey extends QueryKey = QueryKey,
|
|
57
58
|
>(
|
|
58
|
-
options:
|
|
59
|
+
options: WritableOrVal<
|
|
60
|
+
CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
61
|
+
>,
|
|
59
62
|
queryClient?: QueryClient,
|
|
60
63
|
) {
|
|
61
64
|
return createBaseQuery(options, QueryObserver, queryClient)
|
package/src/types.ts
CHANGED
|
@@ -8,10 +8,12 @@ import type {
|
|
|
8
8
|
MutationObserverOptions,
|
|
9
9
|
MutateFunction,
|
|
10
10
|
DefinedQueryObserverResult,
|
|
11
|
-
|
|
11
|
+
DefaultError,
|
|
12
12
|
} from '@tanstack/query-core'
|
|
13
13
|
import type { QueryClient } from '@tanstack/query-core'
|
|
14
|
-
import type { Readable } from 'svelte/store'
|
|
14
|
+
import type { Readable, Writable } from 'svelte/store'
|
|
15
|
+
|
|
16
|
+
export type WritableOrVal<T> = T | Writable<T>
|
|
15
17
|
|
|
16
18
|
export interface ContextOptions {
|
|
17
19
|
/**
|
|
@@ -22,21 +24,19 @@ export interface ContextOptions {
|
|
|
22
24
|
|
|
23
25
|
export interface CreateBaseQueryOptions<
|
|
24
26
|
TQueryFnData = unknown,
|
|
25
|
-
TError =
|
|
27
|
+
TError = DefaultError,
|
|
26
28
|
TData = TQueryFnData,
|
|
27
29
|
TQueryData = TQueryFnData,
|
|
28
30
|
TQueryKey extends QueryKey = QueryKey,
|
|
29
31
|
> extends ContextOptions,
|
|
30
32
|
QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {}
|
|
31
33
|
|
|
32
|
-
export interface CreateBaseQueryResult<
|
|
33
|
-
TData
|
|
34
|
-
TError = RegisteredError,
|
|
35
|
-
> extends Readable<QueryObserverResult<TData, TError>> {}
|
|
34
|
+
export interface CreateBaseQueryResult<TData = unknown, TError = DefaultError>
|
|
35
|
+
extends Readable<QueryObserverResult<TData, TError>> {}
|
|
36
36
|
|
|
37
37
|
export interface CreateQueryOptions<
|
|
38
38
|
TQueryFnData = unknown,
|
|
39
|
-
TError =
|
|
39
|
+
TError = DefaultError,
|
|
40
40
|
TData = TQueryFnData,
|
|
41
41
|
TQueryKey extends QueryKey = QueryKey,
|
|
42
42
|
> extends CreateBaseQueryOptions<
|
|
@@ -47,12 +47,12 @@ export interface CreateQueryOptions<
|
|
|
47
47
|
TQueryKey
|
|
48
48
|
> {}
|
|
49
49
|
|
|
50
|
-
export interface CreateQueryResult<TData = unknown, TError =
|
|
50
|
+
export interface CreateQueryResult<TData = unknown, TError = DefaultError>
|
|
51
51
|
extends CreateBaseQueryResult<TData, TError> {}
|
|
52
52
|
|
|
53
53
|
export interface CreateInfiniteQueryOptions<
|
|
54
54
|
TQueryFnData = unknown,
|
|
55
|
-
TError =
|
|
55
|
+
TError = DefaultError,
|
|
56
56
|
TData = TQueryFnData,
|
|
57
57
|
TQueryData = TQueryFnData,
|
|
58
58
|
TQueryKey extends QueryKey = QueryKey,
|
|
@@ -68,22 +68,22 @@ export interface CreateInfiniteQueryOptions<
|
|
|
68
68
|
|
|
69
69
|
export type CreateInfiniteQueryResult<
|
|
70
70
|
TData = unknown,
|
|
71
|
-
TError =
|
|
71
|
+
TError = DefaultError,
|
|
72
72
|
> = Readable<InfiniteQueryObserverResult<TData, TError>>
|
|
73
73
|
|
|
74
74
|
export type DefinedCreateBaseQueryResult<
|
|
75
75
|
TData = unknown,
|
|
76
|
-
TError =
|
|
76
|
+
TError = DefaultError,
|
|
77
77
|
> = Readable<DefinedQueryObserverResult<TData, TError>>
|
|
78
78
|
|
|
79
79
|
export type DefinedCreateQueryResult<
|
|
80
80
|
TData = unknown,
|
|
81
|
-
TError =
|
|
81
|
+
TError = DefaultError,
|
|
82
82
|
> = DefinedCreateBaseQueryResult<TData, TError>
|
|
83
83
|
|
|
84
84
|
export interface CreateMutationOptions<
|
|
85
85
|
TData = unknown,
|
|
86
|
-
TError =
|
|
86
|
+
TError = DefaultError,
|
|
87
87
|
TVariables = void,
|
|
88
88
|
TContext = unknown,
|
|
89
89
|
> extends ContextOptions,
|
|
@@ -94,7 +94,7 @@ export interface CreateMutationOptions<
|
|
|
94
94
|
|
|
95
95
|
export type CreateMutateFunction<
|
|
96
96
|
TData = unknown,
|
|
97
|
-
TError =
|
|
97
|
+
TError = DefaultError,
|
|
98
98
|
TVariables = void,
|
|
99
99
|
TContext = unknown,
|
|
100
100
|
> = (
|
|
@@ -103,14 +103,14 @@ export type CreateMutateFunction<
|
|
|
103
103
|
|
|
104
104
|
export type CreateMutateAsyncFunction<
|
|
105
105
|
TData = unknown,
|
|
106
|
-
TError =
|
|
106
|
+
TError = DefaultError,
|
|
107
107
|
TVariables = void,
|
|
108
108
|
TContext = unknown,
|
|
109
109
|
> = MutateFunction<TData, TError, TVariables, TContext>
|
|
110
110
|
|
|
111
111
|
export type CreateBaseMutationResult<
|
|
112
112
|
TData = unknown,
|
|
113
|
-
TError =
|
|
113
|
+
TError = DefaultError,
|
|
114
114
|
TVariables = unknown,
|
|
115
115
|
TContext = unknown,
|
|
116
116
|
> = Override<
|
|
@@ -122,7 +122,7 @@ export type CreateBaseMutationResult<
|
|
|
122
122
|
|
|
123
123
|
export interface CreateMutationResult<
|
|
124
124
|
TData = unknown,
|
|
125
|
-
TError =
|
|
125
|
+
TError = DefaultError,
|
|
126
126
|
TVariables = unknown,
|
|
127
127
|
TContext = unknown,
|
|
128
128
|
> extends Readable<
|
package/src/utils.ts
ADDED