@tanstack/solid-query 5.71.7 → 5.71.8
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/dev.cjs +18 -17
- package/build/dev.js +16 -11
- package/build/index.cjs +18 -17
- package/build/index.d.cts +68 -40
- package/build/index.d.ts +68 -40
- package/build/index.js +16 -11
- package/package.json +1 -1
- package/src/QueryClient.ts +85 -0
- package/src/QueryClientProvider.tsx +1 -2
- package/src/{useBaseQuery.ts → createBaseQuery.ts} +4 -5
- package/src/{useInfiniteQuery.ts → createInfiniteQuery.ts} +14 -15
- package/src/{useMutation.ts → createMutation.ts} +10 -9
- package/src/{useQueries.ts → createQueries.ts} +26 -26
- package/src/{useQuery.ts → createQuery.ts} +13 -12
- package/src/index.ts +10 -46
- package/src/types.ts +26 -25
- package/src/useIsFetching.ts +2 -1
- package/src/useIsMutating.ts +2 -1
- package/src/useMutationState.ts +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
|
-
import { DefaultError,
|
|
1
|
+
import { QueryClient as QueryClient$1, QueryClientConfig as QueryClientConfig$1, DefaultError, DefaultOptions as DefaultOptions$1, OmitKeyof, QueryKey, QueryObserverOptions as QueryObserverOptions$1, InfiniteQueryObserverOptions as InfiniteQueryObserverOptions$1, QueryObserverResult, DefinedQueryObserverResult, DefinedInfiniteQueryObserverResult, InfiniteQueryObserverResult, MutationObserverOptions, Override, MutationObserverResult, MutateFunction, DataTag, QueryFilters, InfiniteData, MutationFilters, MutationState, Mutation, QueryFunction, ThrowOnError, QueriesPlaceholderDataFunction } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
3
|
import * as solid_js from 'solid-js';
|
|
4
4
|
import { Accessor, JSX } from 'solid-js';
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> extends OmitKeyof<QueryObserverOptions$1<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'structuralSharing'> {
|
|
7
|
+
/**
|
|
8
|
+
* Set this to a reconciliation key to enable reconciliation between query results.
|
|
9
|
+
* Set this to `false` to disable reconciliation between query results.
|
|
10
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
|
|
11
|
+
* Defaults reconciliation to false.
|
|
12
|
+
*/
|
|
13
|
+
reconcile?: string | false | ((oldData: TData | undefined, newData: TData) => TData);
|
|
14
|
+
}
|
|
15
|
+
interface InfiniteQueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions$1<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'structuralSharing'> {
|
|
16
|
+
/**
|
|
17
|
+
* Set this to a reconciliation key to enable reconciliation between query results.
|
|
18
|
+
* Set this to `false` to disable reconciliation between query results.
|
|
19
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
|
|
20
|
+
* Defaults reconciliation to false.
|
|
21
|
+
*/
|
|
22
|
+
reconcile?: string | false | ((oldData: TData | undefined, newData: TData) => TData);
|
|
23
|
+
}
|
|
24
|
+
interface DefaultOptions<TError = DefaultError> extends DefaultOptions$1<TError> {
|
|
25
|
+
queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>;
|
|
26
|
+
}
|
|
27
|
+
interface QueryClientConfig extends QueryClientConfig$1 {
|
|
28
|
+
defaultOptions?: DefaultOptions;
|
|
29
|
+
}
|
|
30
|
+
declare class QueryClient extends QueryClient$1 {
|
|
31
|
+
constructor(config?: QueryClientConfig);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, 'suspense'> {
|
|
7
35
|
/**
|
|
8
36
|
* Only applicable while rendering queries on the server with streaming.
|
|
9
37
|
* Set `deferStream` to `true` to wait for the query to resolve on the server before flushing the stream.
|
|
@@ -13,18 +41,18 @@ interface UseBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TDa
|
|
|
13
41
|
deferStream?: boolean;
|
|
14
42
|
/**
|
|
15
43
|
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
|
|
16
|
-
* The `data` property on
|
|
44
|
+
* The `data` property on createQuery is a SolidJS resource and will automatically suspend when the data is loading.
|
|
17
45
|
* Setting `suspense` to `false` will be a no-op.
|
|
18
46
|
*/
|
|
19
47
|
suspense?: boolean;
|
|
20
48
|
}
|
|
21
|
-
interface SolidQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends
|
|
49
|
+
interface SolidQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> {
|
|
22
50
|
}
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
type
|
|
27
|
-
type
|
|
51
|
+
type CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Accessor<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>>;
|
|
52
|
+
type CreateBaseQueryResult<TData = unknown, TError = DefaultError> = QueryObserverResult<TData, TError>;
|
|
53
|
+
type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
|
|
54
|
+
type DefinedCreateBaseQueryResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError>;
|
|
55
|
+
type DefinedCreateQueryResult<TData = unknown, TError = DefaultError> = DefinedCreateBaseQueryResult<TData, TError>;
|
|
28
56
|
interface SolidInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'queryKey' | 'suspense'> {
|
|
29
57
|
queryKey: TQueryKey;
|
|
30
58
|
/**
|
|
@@ -36,25 +64,25 @@ interface SolidInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultErro
|
|
|
36
64
|
deferStream?: boolean;
|
|
37
65
|
/**
|
|
38
66
|
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
|
|
39
|
-
* The `data` property on
|
|
67
|
+
* The `data` property on createInfiniteQuery is a SolidJS resource and will automatically suspend when the data is loading.
|
|
40
68
|
* Setting `suspense` to `false` will be a no-op.
|
|
41
69
|
*/
|
|
42
70
|
suspense?: boolean;
|
|
43
71
|
}
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
type
|
|
72
|
+
type CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = Accessor<SolidInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>>;
|
|
73
|
+
type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverResult<TData, TError>;
|
|
74
|
+
type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = DefinedInfiniteQueryObserverResult<TData, TError>;
|
|
47
75
|
interface SolidMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
|
|
48
76
|
}
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
53
|
-
mutate:
|
|
77
|
+
type CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = Accessor<SolidMutationOptions<TData, TError, TVariables, TContext>>;
|
|
78
|
+
type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
|
|
79
|
+
type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
|
|
80
|
+
type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
|
|
81
|
+
mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
|
|
54
82
|
}> & {
|
|
55
|
-
mutateAsync:
|
|
83
|
+
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
|
|
56
84
|
};
|
|
57
|
-
type
|
|
85
|
+
type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = CreateBaseMutationResult<TData, TError, TVariables, TContext>;
|
|
58
86
|
|
|
59
87
|
type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Accessor<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
60
88
|
initialData?: undefined;
|
|
@@ -69,8 +97,8 @@ declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TDa
|
|
|
69
97
|
queryKey: DataTag<TQueryKey, TQueryFnData>;
|
|
70
98
|
};
|
|
71
99
|
|
|
72
|
-
declare function
|
|
73
|
-
declare function
|
|
100
|
+
declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: () => QueryClient): CreateQueryResult<TData, TError>;
|
|
101
|
+
declare function createQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: () => QueryClient): DefinedCreateQueryResult<TData, TError>;
|
|
74
102
|
|
|
75
103
|
declare const QueryClientContext: solid_js.Context<(() => QueryClient) | undefined>;
|
|
76
104
|
declare const useQueryClient: (queryClient?: QueryClient) => QueryClient;
|
|
@@ -96,10 +124,10 @@ declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData
|
|
|
96
124
|
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
|
|
97
125
|
};
|
|
98
126
|
|
|
99
|
-
declare function
|
|
100
|
-
declare function
|
|
127
|
+
declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: Accessor<QueryClient>): DefinedCreateInfiniteQueryResult<TData, TError>;
|
|
128
|
+
declare function createInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: Accessor<QueryClient>): CreateInfiniteQueryResult<TData, TError>;
|
|
101
129
|
|
|
102
|
-
declare function
|
|
130
|
+
declare function createMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: CreateMutationOptions<TData, TError, TVariables, TContext>, queryClient?: Accessor<QueryClient>): CreateMutationResult<TData, TError, TVariables, TContext>;
|
|
103
131
|
|
|
104
132
|
declare function useIsMutating(filters?: Accessor<MutationFilters>, queryClient?: Accessor<QueryClient>): Accessor<number>;
|
|
105
133
|
|
|
@@ -109,11 +137,11 @@ type MutationStateOptions<TResult = MutationState> = {
|
|
|
109
137
|
};
|
|
110
138
|
declare function useMutationState<TResult = MutationState>(options?: Accessor<MutationStateOptions<TResult>>, queryClient?: Accessor<QueryClient>): Accessor<Array<TResult>>;
|
|
111
139
|
|
|
112
|
-
type
|
|
140
|
+
type CreateQueryOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'placeholderData' | 'suspense'> & {
|
|
113
141
|
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
|
|
114
142
|
/**
|
|
115
143
|
* @deprecated The `suspense` option has been deprecated in v5 and will be removed in the next major version.
|
|
116
|
-
* The `data` property on
|
|
144
|
+
* The `data` property on createQueries is a plain object and not a SolidJS Resource.
|
|
117
145
|
* It will not suspend when the data is loading.
|
|
118
146
|
* Setting `suspense` to `true` will be a no-op.
|
|
119
147
|
*/
|
|
@@ -125,36 +153,36 @@ type GetOptions<T> = T extends {
|
|
|
125
153
|
queryFnData: infer TQueryFnData;
|
|
126
154
|
error?: infer TError;
|
|
127
155
|
data: infer TData;
|
|
128
|
-
} ?
|
|
156
|
+
} ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends {
|
|
129
157
|
queryFnData: infer TQueryFnData;
|
|
130
158
|
error?: infer TError;
|
|
131
|
-
} ?
|
|
159
|
+
} ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError> : T extends {
|
|
132
160
|
data: infer TData;
|
|
133
161
|
error?: infer TError;
|
|
134
|
-
} ?
|
|
162
|
+
} ? CreateQueryOptionsForCreateQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? CreateQueryOptionsForCreateQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? CreateQueryOptionsForCreateQueries<TQueryFnData> : T extends {
|
|
135
163
|
queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipTokenForUseQueries;
|
|
136
164
|
select?: (data: any) => infer TData;
|
|
137
165
|
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
138
|
-
} ?
|
|
166
|
+
} ? CreateQueryOptionsForCreateQueries<TQueryFnData, unknown extends TError ? DefaultError : TError, unknown extends TData ? TQueryFnData : TData, TQueryKey> : CreateQueryOptionsForCreateQueries;
|
|
139
167
|
type GetResults<T> = T extends {
|
|
140
168
|
queryFnData: any;
|
|
141
169
|
error?: infer TError;
|
|
142
170
|
data: infer TData;
|
|
143
|
-
} ?
|
|
171
|
+
} ? CreateQueryResult<TData, TError> : T extends {
|
|
144
172
|
queryFnData: infer TQueryFnData;
|
|
145
173
|
error?: infer TError;
|
|
146
|
-
} ?
|
|
174
|
+
} ? CreateQueryResult<TQueryFnData, TError> : T extends {
|
|
147
175
|
data: infer TData;
|
|
148
176
|
error?: infer TError;
|
|
149
|
-
} ?
|
|
177
|
+
} ? CreateQueryResult<TData, TError> : T extends [any, infer TError, infer TData] ? CreateQueryResult<TData, TError> : T extends [infer TQueryFnData, infer TError] ? CreateQueryResult<TQueryFnData, TError> : T extends [infer TQueryFnData] ? CreateQueryResult<TQueryFnData> : T extends {
|
|
150
178
|
queryFn?: QueryFunction<infer TQueryFnData, any> | SkipTokenForUseQueries;
|
|
151
179
|
select?: (data: any) => infer TData;
|
|
152
180
|
throwOnError?: ThrowOnError<any, infer TError, any, any>;
|
|
153
|
-
} ?
|
|
181
|
+
} ? CreateQueryResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError> : CreateQueryResult;
|
|
154
182
|
/**
|
|
155
183
|
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
156
184
|
*/
|
|
157
|
-
type QueriesOptions<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<
|
|
185
|
+
type QueriesOptions<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[
|
|
158
186
|
...Tail
|
|
159
187
|
], [
|
|
160
188
|
...TResult,
|
|
@@ -162,11 +190,11 @@ type QueriesOptions<T extends Array<any>, TResult extends Array<any> = [], TDept
|
|
|
162
190
|
], [
|
|
163
191
|
...TDepth,
|
|
164
192
|
1
|
|
165
|
-
]> : ReadonlyArray<unknown> extends T ? T : T extends Array<
|
|
193
|
+
]> : ReadonlyArray<unknown> extends T ? T : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<CreateQueryOptionsForCreateQueries>;
|
|
166
194
|
/**
|
|
167
195
|
* QueriesResults reducer recursively maps type param to results
|
|
168
196
|
*/
|
|
169
|
-
type QueriesResults<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<
|
|
197
|
+
type QueriesResults<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[
|
|
170
198
|
...Tail
|
|
171
199
|
], [
|
|
172
200
|
...TResult,
|
|
@@ -177,7 +205,7 @@ type QueriesResults<T extends Array<any>, TResult extends Array<any> = [], TDept
|
|
|
177
205
|
]> : {
|
|
178
206
|
[K in keyof T]: GetResults<T[K]>;
|
|
179
207
|
};
|
|
180
|
-
declare function
|
|
208
|
+
declare function createQueries<T extends Array<any>, TCombinedResult extends QueriesResults<T> = QueriesResults<T>>(queriesOptions: Accessor<{
|
|
181
209
|
queries: readonly [...QueriesOptions<T>] | readonly [...{
|
|
182
210
|
[K in keyof T]: GetOptions<T[K]>;
|
|
183
211
|
}];
|
|
@@ -187,4 +215,4 @@ declare function useQueries<T extends Array<any>, TCombinedResult extends Querie
|
|
|
187
215
|
declare const useIsRestoring: () => Accessor<boolean>;
|
|
188
216
|
declare const IsRestoringProvider: solid_js.ContextProviderComponent<Accessor<boolean>>;
|
|
189
217
|
|
|
190
|
-
export { type
|
|
218
|
+
export { type CreateBaseMutationResult, type CreateBaseQueryOptions, type CreateBaseQueryResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreateMutateAsyncFunction, type CreateMutateFunction, type CreateMutationOptions, type CreateMutationResult, type CreateQueryOptions, type CreateQueryResult, type DefaultOptions, type DefinedCreateBaseQueryResult, type DefinedCreateInfiniteQueryResult, type DefinedCreateQueryResult, type DefinedInitialDataInfiniteOptions, type DefinedInitialDataOptions, type InfiniteQueryObserverOptions, IsRestoringProvider, QueryClient, type QueryClientConfig, QueryClientContext, QueryClientProvider, type QueryClientProviderProps, type QueryObserverOptions, type SolidInfiniteQueryOptions, type SolidMutationOptions, type SolidQueryOptions, type UndefinedInitialDataInfiniteOptions, type UndefinedInitialDataOptions, createInfiniteQuery, createMutation, createQueries, createQuery, infiniteQueryOptions, queryOptions, useIsFetching, useIsMutating, useIsRestoring, useMutationState, useQueryClient };
|
package/build/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, notifyManager, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core';
|
|
1
|
+
import { QueryClient as QueryClient$1, MutationObserver, replaceEqualDeep, QueriesObserver, hydrate, notifyManager, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
3
|
import { createContext, useContext, createRenderEffect, onCleanup, createMemo, createSignal, createComputed, on, createEffect, mergeProps, createResource, batch, onMount } from 'solid-js';
|
|
4
4
|
import { createComponent, isServer } from 'solid-js/web';
|
|
5
5
|
import { createStore, unwrap, reconcile } from 'solid-js/store';
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
+
var QueryClient = class extends QueryClient$1 {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
super(config);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
8
13
|
var QueryClientContext = createContext(void 0);
|
|
9
14
|
var useQueryClient = (queryClient) => {
|
|
10
15
|
if (queryClient) {
|
|
@@ -44,7 +49,7 @@ var IsRestoringContext = createContext(() => false);
|
|
|
44
49
|
var useIsRestoring = () => useContext(IsRestoringContext);
|
|
45
50
|
var IsRestoringProvider = IsRestoringContext.Provider;
|
|
46
51
|
|
|
47
|
-
// src/
|
|
52
|
+
// src/createBaseQuery.ts
|
|
48
53
|
function reconcileFn(store, result, reconcileOption, queryHash) {
|
|
49
54
|
if (reconcileOption === false) return result;
|
|
50
55
|
if (typeof reconcileOption === "function") {
|
|
@@ -81,7 +86,7 @@ var hydratableObserverResult = (query, result) => {
|
|
|
81
86
|
};
|
|
82
87
|
return obj;
|
|
83
88
|
};
|
|
84
|
-
function
|
|
89
|
+
function createBaseQuery(options, Observer, queryClient) {
|
|
85
90
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
86
91
|
const isRestoring = useIsRestoring();
|
|
87
92
|
let unsubscribeQueued = false;
|
|
@@ -287,9 +292,9 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
287
292
|
return new Proxy(state, handler);
|
|
288
293
|
}
|
|
289
294
|
|
|
290
|
-
// src/
|
|
291
|
-
function
|
|
292
|
-
return
|
|
295
|
+
// src/createQuery.ts
|
|
296
|
+
function createQuery(options, queryClient) {
|
|
297
|
+
return createBaseQuery(
|
|
293
298
|
createMemo(() => options()),
|
|
294
299
|
QueryObserver,
|
|
295
300
|
queryClient
|
|
@@ -310,8 +315,8 @@ function useIsFetching(filters, queryClient) {
|
|
|
310
315
|
onCleanup(unsubscribe);
|
|
311
316
|
return fetches;
|
|
312
317
|
}
|
|
313
|
-
function
|
|
314
|
-
return
|
|
318
|
+
function createInfiniteQuery(options, queryClient) {
|
|
319
|
+
return createBaseQuery(
|
|
315
320
|
createMemo(() => options()),
|
|
316
321
|
InfiniteQueryObserver,
|
|
317
322
|
queryClient
|
|
@@ -322,7 +327,7 @@ function useInfiniteQuery(options, queryClient) {
|
|
|
322
327
|
function infiniteQueryOptions(options) {
|
|
323
328
|
return options;
|
|
324
329
|
}
|
|
325
|
-
function
|
|
330
|
+
function createMutation(options, queryClient) {
|
|
326
331
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
327
332
|
const observer = new MutationObserver(
|
|
328
333
|
client(),
|
|
@@ -396,7 +401,7 @@ function useMutationState(options = () => ({}), queryClient) {
|
|
|
396
401
|
});
|
|
397
402
|
return result;
|
|
398
403
|
}
|
|
399
|
-
function
|
|
404
|
+
function createQueries(queriesOptions, queryClient) {
|
|
400
405
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
401
406
|
const isRestoring = useIsRestoring();
|
|
402
407
|
const defaultedQueries = createMemo(
|
|
@@ -514,4 +519,4 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
514
519
|
return proxyState;
|
|
515
520
|
}
|
|
516
521
|
|
|
517
|
-
export { IsRestoringProvider, QueryClientContext, QueryClientProvider,
|
|
522
|
+
export { IsRestoringProvider, QueryClient, QueryClientContext, QueryClientProvider, createInfiniteQuery, createMutation, createQueries, createQuery, infiniteQueryOptions, queryOptions, useIsFetching, useIsMutating, useIsRestoring, useMutationState, useQueryClient };
|
package/package.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { QueryClient as QueryCoreClient } from '@tanstack/query-core'
|
|
2
|
+
import type {
|
|
3
|
+
DefaultOptions as CoreDefaultOptions,
|
|
4
|
+
DefaultError,
|
|
5
|
+
OmitKeyof,
|
|
6
|
+
QueryClientConfig as QueryCoreClientConfig,
|
|
7
|
+
InfiniteQueryObserverOptions as QueryCoreInfiniteQueryObserverOptions,
|
|
8
|
+
QueryObserverOptions as QueryCoreObserverOptions,
|
|
9
|
+
QueryKey,
|
|
10
|
+
} from '@tanstack/query-core'
|
|
11
|
+
|
|
12
|
+
export interface QueryObserverOptions<
|
|
13
|
+
TQueryFnData = unknown,
|
|
14
|
+
TError = DefaultError,
|
|
15
|
+
TData = TQueryFnData,
|
|
16
|
+
TQueryData = TQueryFnData,
|
|
17
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
18
|
+
TPageParam = never,
|
|
19
|
+
> extends OmitKeyof<
|
|
20
|
+
QueryCoreObserverOptions<
|
|
21
|
+
TQueryFnData,
|
|
22
|
+
TError,
|
|
23
|
+
TData,
|
|
24
|
+
TQueryData,
|
|
25
|
+
TQueryKey,
|
|
26
|
+
TPageParam
|
|
27
|
+
>,
|
|
28
|
+
'structuralSharing'
|
|
29
|
+
> {
|
|
30
|
+
/**
|
|
31
|
+
* Set this to a reconciliation key to enable reconciliation between query results.
|
|
32
|
+
* Set this to `false` to disable reconciliation between query results.
|
|
33
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
|
|
34
|
+
* Defaults reconciliation to false.
|
|
35
|
+
*/
|
|
36
|
+
reconcile?:
|
|
37
|
+
| string
|
|
38
|
+
| false
|
|
39
|
+
| ((oldData: TData | undefined, newData: TData) => TData)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface InfiniteQueryObserverOptions<
|
|
43
|
+
TQueryFnData = unknown,
|
|
44
|
+
TError = DefaultError,
|
|
45
|
+
TData = TQueryFnData,
|
|
46
|
+
TQueryData = TQueryFnData,
|
|
47
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
48
|
+
TPageParam = unknown,
|
|
49
|
+
> extends OmitKeyof<
|
|
50
|
+
QueryCoreInfiniteQueryObserverOptions<
|
|
51
|
+
TQueryFnData,
|
|
52
|
+
TError,
|
|
53
|
+
TData,
|
|
54
|
+
TQueryData,
|
|
55
|
+
TQueryKey,
|
|
56
|
+
TPageParam
|
|
57
|
+
>,
|
|
58
|
+
'structuralSharing'
|
|
59
|
+
> {
|
|
60
|
+
/**
|
|
61
|
+
* Set this to a reconciliation key to enable reconciliation between query results.
|
|
62
|
+
* Set this to `false` to disable reconciliation between query results.
|
|
63
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.
|
|
64
|
+
* Defaults reconciliation to false.
|
|
65
|
+
*/
|
|
66
|
+
reconcile?:
|
|
67
|
+
| string
|
|
68
|
+
| false
|
|
69
|
+
| ((oldData: TData | undefined, newData: TData) => TData)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DefaultOptions<TError = DefaultError>
|
|
73
|
+
extends CoreDefaultOptions<TError> {
|
|
74
|
+
queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, 'queryKey'>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface QueryClientConfig extends QueryCoreClientConfig {
|
|
78
|
+
defaultOptions?: DefaultOptions
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export class QueryClient extends QueryCoreClient {
|
|
82
|
+
constructor(config: QueryClientConfig = {}) {
|
|
83
|
+
super(config)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -15,12 +15,11 @@ import { createStore, reconcile, unwrap } from 'solid-js/store'
|
|
|
15
15
|
import { useQueryClient } from './QueryClientProvider'
|
|
16
16
|
import { shouldThrowError } from './utils'
|
|
17
17
|
import { useIsRestoring } from './isRestoring'
|
|
18
|
-
import type {
|
|
18
|
+
import type { CreateBaseQueryOptions } from './types'
|
|
19
19
|
import type { Accessor, Signal } from 'solid-js'
|
|
20
|
-
|
|
20
|
+
import type { QueryClient } from './QueryClient'
|
|
21
21
|
import type {
|
|
22
22
|
Query,
|
|
23
|
-
QueryClient,
|
|
24
23
|
QueryKey,
|
|
25
24
|
QueryObserver,
|
|
26
25
|
QueryObserverResult,
|
|
@@ -102,7 +101,7 @@ const hydratableObserverResult = <
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
// Base Query Function that is used to create the query.
|
|
105
|
-
export function
|
|
104
|
+
export function createBaseQuery<
|
|
106
105
|
TQueryFnData,
|
|
107
106
|
TError,
|
|
108
107
|
TData,
|
|
@@ -110,7 +109,7 @@ export function useBaseQuery<
|
|
|
110
109
|
TQueryKey extends QueryKey,
|
|
111
110
|
>(
|
|
112
111
|
options: Accessor<
|
|
113
|
-
|
|
112
|
+
CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
|
|
114
113
|
>,
|
|
115
114
|
Observer: typeof QueryObserver,
|
|
116
115
|
queryClient?: Accessor<QueryClient>,
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
2
2
|
import { createMemo } from 'solid-js'
|
|
3
|
-
import {
|
|
3
|
+
import { createBaseQuery } from './createBaseQuery'
|
|
4
4
|
import type {
|
|
5
5
|
DefaultError,
|
|
6
6
|
InfiniteData,
|
|
7
|
-
QueryClient,
|
|
8
7
|
QueryKey,
|
|
9
8
|
QueryObserver,
|
|
10
9
|
} from '@tanstack/query-core'
|
|
11
|
-
|
|
10
|
+
import type { QueryClient } from './QueryClient'
|
|
12
11
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
CreateInfiniteQueryOptions,
|
|
13
|
+
CreateInfiniteQueryResult,
|
|
14
|
+
DefinedCreateInfiniteQueryResult,
|
|
16
15
|
} from './types'
|
|
17
16
|
import type { Accessor } from 'solid-js'
|
|
18
17
|
import type {
|
|
@@ -20,7 +19,7 @@ import type {
|
|
|
20
19
|
UndefinedInitialDataInfiniteOptions,
|
|
21
20
|
} from './infiniteQueryOptions'
|
|
22
21
|
|
|
23
|
-
export function
|
|
22
|
+
export function createInfiniteQuery<
|
|
24
23
|
TQueryFnData,
|
|
25
24
|
TError = DefaultError,
|
|
26
25
|
TData = InfiniteData<TQueryFnData>,
|
|
@@ -35,8 +34,8 @@ export function useInfiniteQuery<
|
|
|
35
34
|
TPageParam
|
|
36
35
|
>,
|
|
37
36
|
queryClient?: Accessor<QueryClient>,
|
|
38
|
-
):
|
|
39
|
-
export function
|
|
37
|
+
): DefinedCreateInfiniteQueryResult<TData, TError>
|
|
38
|
+
export function createInfiniteQuery<
|
|
40
39
|
TQueryFnData,
|
|
41
40
|
TError = DefaultError,
|
|
42
41
|
TData = InfiniteData<TQueryFnData>,
|
|
@@ -51,16 +50,16 @@ export function useInfiniteQuery<
|
|
|
51
50
|
TPageParam
|
|
52
51
|
>,
|
|
53
52
|
queryClient?: Accessor<QueryClient>,
|
|
54
|
-
):
|
|
53
|
+
): CreateInfiniteQueryResult<TData, TError>
|
|
55
54
|
|
|
56
|
-
export function
|
|
55
|
+
export function createInfiniteQuery<
|
|
57
56
|
TQueryFnData,
|
|
58
57
|
TError = DefaultError,
|
|
59
58
|
TData = InfiniteData<TQueryFnData>,
|
|
60
59
|
TQueryKey extends QueryKey = QueryKey,
|
|
61
60
|
TPageParam = unknown,
|
|
62
61
|
>(
|
|
63
|
-
options:
|
|
62
|
+
options: CreateInfiniteQueryOptions<
|
|
64
63
|
TQueryFnData,
|
|
65
64
|
TError,
|
|
66
65
|
TData,
|
|
@@ -68,10 +67,10 @@ export function useInfiniteQuery<
|
|
|
68
67
|
TPageParam
|
|
69
68
|
>,
|
|
70
69
|
queryClient?: Accessor<QueryClient>,
|
|
71
|
-
):
|
|
72
|
-
return
|
|
70
|
+
): CreateInfiniteQueryResult<TData, TError> {
|
|
71
|
+
return createBaseQuery(
|
|
73
72
|
createMemo(() => options()),
|
|
74
73
|
InfiniteQueryObserver as typeof QueryObserver,
|
|
75
74
|
queryClient,
|
|
76
|
-
) as
|
|
75
|
+
) as CreateInfiniteQueryResult<TData, TError>
|
|
77
76
|
}
|
|
@@ -3,24 +3,25 @@ import { createComputed, createMemo, on, onCleanup } from 'solid-js'
|
|
|
3
3
|
import { createStore } from 'solid-js/store'
|
|
4
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
5
|
import { noop, shouldThrowError } from './utils'
|
|
6
|
-
import type { DefaultError
|
|
6
|
+
import type { DefaultError } from '@tanstack/query-core'
|
|
7
|
+
import type { QueryClient } from './QueryClient'
|
|
7
8
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
CreateMutateFunction,
|
|
10
|
+
CreateMutationOptions,
|
|
11
|
+
CreateMutationResult,
|
|
11
12
|
} from './types'
|
|
12
13
|
import type { Accessor } from 'solid-js'
|
|
13
14
|
|
|
14
15
|
// HOOK
|
|
15
|
-
export function
|
|
16
|
+
export function createMutation<
|
|
16
17
|
TData = unknown,
|
|
17
18
|
TError = DefaultError,
|
|
18
19
|
TVariables = void,
|
|
19
20
|
TContext = unknown,
|
|
20
21
|
>(
|
|
21
|
-
options:
|
|
22
|
+
options: CreateMutationOptions<TData, TError, TVariables, TContext>,
|
|
22
23
|
queryClient?: Accessor<QueryClient>,
|
|
23
|
-
):
|
|
24
|
+
): CreateMutationResult<TData, TError, TVariables, TContext> {
|
|
24
25
|
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
25
26
|
|
|
26
27
|
const observer = new MutationObserver<TData, TError, TVariables, TContext>(
|
|
@@ -28,7 +29,7 @@ export function useMutation<
|
|
|
28
29
|
options(),
|
|
29
30
|
)
|
|
30
31
|
|
|
31
|
-
const mutate:
|
|
32
|
+
const mutate: CreateMutateFunction<TData, TError, TVariables, TContext> = (
|
|
32
33
|
variables,
|
|
33
34
|
mutateOptions,
|
|
34
35
|
) => {
|
|
@@ -36,7 +37,7 @@ export function useMutation<
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const [state, setState] = createStore<
|
|
39
|
-
|
|
40
|
+
CreateMutationResult<TData, TError, TVariables, TContext>
|
|
40
41
|
>({
|
|
41
42
|
...observer.getCurrentResult(),
|
|
42
43
|
mutate,
|