@tanstack/solid-query 5.0.0-alpha.5 → 5.0.0-alpha.51
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/index.cjs +33 -0
- package/build/source/QueryClient.js +6 -0
- package/build/source/__tests__/QueryClientProvider.test.jsx +2 -3
- package/build/source/__tests__/createInfiniteQuery.test.jsx +58 -13
- package/build/source/__tests__/createMutation.test.jsx +5 -5
- package/build/source/__tests__/createQueries.test.jsx +6 -77
- package/build/source/__tests__/createQuery.test.jsx +51 -261
- package/build/source/__tests__/createQuery.types.test.jsx +19 -1
- package/build/source/__tests__/suspense.test.jsx +7 -69
- package/build/source/__tests__/transition.test.jsx +1 -1
- package/build/source/__tests__/useIsFetching.test.jsx +1 -1
- package/build/source/__tests__/useIsMutating.test.jsx +5 -7
- package/build/source/__tests__/utils.jsx +1 -1
- package/build/source/createBaseQuery.js +49 -23
- package/build/source/createMutation.js +1 -1
- package/build/source/createQueries.js +13 -7
- package/build/source/createQuery.js +3 -0
- package/build/source/index.js +2 -1
- package/build/types/QueryClient.d.ts +30 -0
- package/build/types/QueryClient.d.ts.map +1 -0
- package/build/types/QueryClientProvider.d.ts +3 -2
- package/build/types/QueryClientProvider.d.ts.map +1 -0
- package/build/types/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/types/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/types/__tests__/createInfiniteQuery.test.d.ts +1 -0
- package/build/types/__tests__/createInfiniteQuery.test.d.ts.map +1 -0
- package/build/types/__tests__/createMutation.test.d.ts +1 -0
- package/build/types/__tests__/createMutation.test.d.ts.map +1 -0
- package/build/types/__tests__/createQueries.test.d.ts +1 -0
- package/build/types/__tests__/createQueries.test.d.ts.map +1 -0
- package/build/types/__tests__/createQuery.test.d.ts +1 -0
- package/build/types/__tests__/createQuery.test.d.ts.map +1 -0
- package/build/types/__tests__/createQuery.types.test.d.ts +3 -2
- package/build/types/__tests__/createQuery.types.test.d.ts.map +1 -0
- package/build/types/__tests__/suspense.test.d.ts +1 -0
- package/build/types/__tests__/suspense.test.d.ts.map +1 -0
- package/build/types/__tests__/transition.test.d.ts +1 -0
- package/build/types/__tests__/transition.test.d.ts.map +1 -0
- package/build/types/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/types/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/types/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/types/__tests__/useIsMutating.test.d.ts.map +1 -0
- package/build/types/__tests__/utils.d.ts +4 -3
- package/build/types/__tests__/utils.d.ts.map +1 -0
- package/build/types/createBaseQuery.d.ts +3 -1
- package/build/types/createBaseQuery.d.ts.map +1 -0
- package/build/types/createInfiniteQuery.d.ts +3 -1
- package/build/types/createInfiniteQuery.d.ts.map +1 -0
- package/build/types/createMutation.d.ts +3 -1
- package/build/types/createMutation.d.ts.map +1 -0
- package/build/types/createQueries.d.ts +12 -9
- package/build/types/createQueries.d.ts.map +1 -0
- package/build/types/createQuery.d.ts +7 -3
- package/build/types/createQuery.d.ts.map +1 -0
- package/build/types/index.d.ts +4 -1
- package/build/types/index.d.ts.map +1 -0
- package/build/types/setBatchUpdatesFn.d.ts +1 -0
- package/build/types/setBatchUpdatesFn.d.ts.map +1 -0
- package/build/types/types.d.ts +17 -15
- package/build/types/types.d.ts.map +1 -0
- package/build/types/useIsFetching.d.ts +3 -1
- package/build/types/useIsFetching.d.ts.map +1 -0
- package/build/types/useIsMutating.d.ts +3 -1
- package/build/types/useIsMutating.d.ts.map +1 -0
- package/build/types/utils.d.ts +1 -0
- package/build/types/utils.d.ts.map +1 -0
- package/package.json +20 -19
- package/src/QueryClient.ts +84 -0
- package/src/QueryClientProvider.tsx +1 -1
- package/src/__tests__/QueryClientProvider.test.tsx +2 -3
- package/src/__tests__/createInfiniteQuery.test.tsx +83 -19
- package/src/__tests__/createMutation.test.tsx +5 -5
- package/src/__tests__/createQueries.test.tsx +6 -78
- package/src/__tests__/createQuery.test.tsx +66 -334
- package/src/__tests__/createQuery.types.test.tsx +21 -1
- package/src/__tests__/suspense.test.tsx +7 -90
- package/src/__tests__/transition.test.tsx +1 -1
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useIsMutating.test.tsx +5 -7
- package/src/__tests__/utils.tsx +1 -1
- package/src/createBaseQuery.ts +73 -28
- package/src/createInfiniteQuery.ts +1 -1
- package/src/createMutation.ts +3 -2
- package/src/createQueries.ts +32 -14
- package/src/createQuery.ts +24 -1
- package/src/index.ts +8 -1
- package/src/types.ts +4 -2
- package/src/useIsFetching.ts +2 -1
- package/src/useIsMutating.ts +2 -1
- package/build/cjs/index.js +0 -300
- package/build/cjs/index.js.map +0 -1
- package/build/esm/index.js +0 -285
- package/build/esm/index.js.map +0 -1
- package/build/umd/index.js +0 -2
- package/build/umd/index.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fireEvent, render, screen, waitFor } from '
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
2
|
|
|
3
3
|
import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js'
|
|
4
4
|
import { createQuery, QueryCache, QueryClientProvider, useIsFetching } from '..'
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { fireEvent, screen, waitFor } from '
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
2
|
import { createMutation, QueryClientProvider, useIsMutating } from '..'
|
|
3
|
-
import { createQueryClient, sleep } from './utils'
|
|
3
|
+
import { createQueryClient, sleep, setActTimeout } from './utils'
|
|
4
4
|
|
|
5
5
|
import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js'
|
|
6
|
-
import
|
|
7
|
-
import * as MutationCacheModule from '../../../query-core/src/mutationCache'
|
|
8
|
-
import { setActTimeout } from './utils'
|
|
6
|
+
import * as QueryCore from '@tanstack/query-core'
|
|
9
7
|
import { vi } from 'vitest'
|
|
10
8
|
|
|
11
9
|
describe('useIsMutating', () => {
|
|
@@ -188,7 +186,7 @@ describe('useIsMutating', () => {
|
|
|
188
186
|
it('should not change state if unmounted', async () => {
|
|
189
187
|
// We have to mock the MutationCache to not unsubscribe
|
|
190
188
|
// the listener when the component is unmounted
|
|
191
|
-
class MutationCacheMock extends
|
|
189
|
+
class MutationCacheMock extends QueryCore.MutationCache {
|
|
192
190
|
subscribe(listener: any) {
|
|
193
191
|
super.subscribe(listener)
|
|
194
192
|
return () => void 0
|
|
@@ -196,7 +194,7 @@ describe('useIsMutating', () => {
|
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
const MutationCacheSpy = vi
|
|
199
|
-
.spyOn(
|
|
197
|
+
.spyOn(QueryCore, 'MutationCache')
|
|
200
198
|
.mockImplementation((fn) => {
|
|
201
199
|
return new MutationCacheMock(fn)
|
|
202
200
|
})
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { QueryClientConfig } from '@tanstack/query-core'
|
|
2
|
-
import { QueryClient } from '
|
|
2
|
+
import { QueryClient } from '../QueryClient'
|
|
3
3
|
import type { ParentProps } from 'solid-js'
|
|
4
4
|
import { createEffect, createSignal, onCleanup, Show } from 'solid-js'
|
|
5
5
|
import { vi } from 'vitest'
|
package/src/createBaseQuery.ts
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
// in solid-js/web package. I'll create a GitHub issue with them to see
|
|
4
4
|
// why that happens.
|
|
5
5
|
import type {
|
|
6
|
-
QueryClient,
|
|
7
6
|
QueryKey,
|
|
8
7
|
QueryObserver,
|
|
9
8
|
QueryObserverResult,
|
|
10
9
|
} from '@tanstack/query-core'
|
|
11
|
-
import {
|
|
12
|
-
import { notifyManager } from '@tanstack/query-core'
|
|
10
|
+
import type { QueryClient } from './QueryClient'
|
|
11
|
+
import { hydrate, notifyManager } from '@tanstack/query-core'
|
|
13
12
|
import type { Accessor } from 'solid-js'
|
|
14
13
|
import { isServer } from 'solid-js/web'
|
|
15
14
|
import {
|
|
@@ -18,13 +17,29 @@ import {
|
|
|
18
17
|
createResource,
|
|
19
18
|
on,
|
|
20
19
|
onCleanup,
|
|
21
|
-
onMount,
|
|
22
20
|
} from 'solid-js'
|
|
23
|
-
import { createStore, unwrap } from 'solid-js/store'
|
|
21
|
+
import { createStore, reconcile, unwrap } from 'solid-js/store'
|
|
24
22
|
import { useQueryClient } from './QueryClientProvider'
|
|
25
23
|
import type { CreateBaseQueryOptions } from './types'
|
|
26
24
|
import { shouldThrowError } from './utils'
|
|
27
25
|
|
|
26
|
+
function reconcileFn<TData, TError>(
|
|
27
|
+
store: QueryObserverResult<TData, TError>,
|
|
28
|
+
result: QueryObserverResult<TData, TError>,
|
|
29
|
+
reconcileOption:
|
|
30
|
+
| string
|
|
31
|
+
| false
|
|
32
|
+
| ((oldData: TData | undefined, newData: TData) => TData),
|
|
33
|
+
): QueryObserverResult<TData, TError> {
|
|
34
|
+
if (reconcileOption === false) return result
|
|
35
|
+
if (typeof reconcileOption === 'function') {
|
|
36
|
+
const newData = reconcileOption(store.data, result.data as TData)
|
|
37
|
+
return { ...result, data: newData } as typeof result
|
|
38
|
+
}
|
|
39
|
+
const newData = reconcile(result.data, { key: reconcileOption })(store.data)
|
|
40
|
+
return { ...result, data: newData } as typeof result
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
// Base Query Function that is used to create the query.
|
|
29
44
|
export function createBaseQuery<
|
|
30
45
|
TQueryFnData,
|
|
@@ -43,9 +58,10 @@ export function createBaseQuery<
|
|
|
43
58
|
|
|
44
59
|
const defaultedOptions = client().defaultQueryOptions(options())
|
|
45
60
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
61
|
+
defaultedOptions.structuralSharing = false
|
|
46
62
|
if (isServer) {
|
|
47
63
|
defaultedOptions.retry = false
|
|
48
|
-
defaultedOptions.
|
|
64
|
+
defaultedOptions.throwOnError = true
|
|
49
65
|
}
|
|
50
66
|
const observer = new Observer(client(), defaultedOptions)
|
|
51
67
|
|
|
@@ -64,7 +80,22 @@ export function createBaseQuery<
|
|
|
64
80
|
) => {
|
|
65
81
|
return observer.subscribe((result) => {
|
|
66
82
|
notifyManager.batchCalls(() => {
|
|
67
|
-
const
|
|
83
|
+
const query = observer.getCurrentQuery()
|
|
84
|
+
const { refetch, ...rest } = unwrap(result)
|
|
85
|
+
const unwrappedResult = {
|
|
86
|
+
...rest,
|
|
87
|
+
|
|
88
|
+
// hydrate() expects a QueryState object, which is similar but not
|
|
89
|
+
// quite the same as a QueryObserverResult object. Thus, for now, we're
|
|
90
|
+
// copying over the missing properties from state in order to support hydration
|
|
91
|
+
dataUpdateCount: query.state.dataUpdateCount,
|
|
92
|
+
fetchFailureCount: query.state.fetchFailureCount,
|
|
93
|
+
// Removing these properties since they might not be serializable
|
|
94
|
+
// fetchFailureReason: query.state.fetchFailureReason,
|
|
95
|
+
// fetchMeta: query.state.fetchMeta,
|
|
96
|
+
isInvalidated: query.state.isInvalidated,
|
|
97
|
+
}
|
|
98
|
+
|
|
68
99
|
if (unwrappedResult.isError) {
|
|
69
100
|
if (process.env['NODE_ENV'] === 'development') {
|
|
70
101
|
console.error(unwrappedResult.error)
|
|
@@ -72,7 +103,9 @@ export function createBaseQuery<
|
|
|
72
103
|
reject(unwrappedResult.error)
|
|
73
104
|
}
|
|
74
105
|
if (unwrappedResult.isSuccess) {
|
|
75
|
-
|
|
106
|
+
// Use of any here is fine
|
|
107
|
+
// We cannot include refetch since it is not serializable
|
|
108
|
+
resolve(unwrappedResult as any)
|
|
76
109
|
}
|
|
77
110
|
})()
|
|
78
111
|
})
|
|
@@ -81,18 +114,28 @@ export function createBaseQuery<
|
|
|
81
114
|
const createClientSubscriber = () => {
|
|
82
115
|
return observer.subscribe((result) => {
|
|
83
116
|
notifyManager.batchCalls(() => {
|
|
84
|
-
|
|
117
|
+
// @ts-expect-error - This will error because the reconcile option does not
|
|
118
|
+
// exist on the query-core QueryObserverResult type
|
|
119
|
+
const reconcileOptions = observer.options.reconcile
|
|
85
120
|
// If the query has data we dont suspend but instead mutate the resource
|
|
86
121
|
// This could happen when placeholderData/initialData is defined
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
if (queryResource()?.data && result.data && !queryResource.loading) {
|
|
123
|
+
setState((store) => {
|
|
124
|
+
return reconcileFn(
|
|
125
|
+
store,
|
|
126
|
+
result,
|
|
127
|
+
reconcileOptions === undefined ? 'id' : reconcileOptions,
|
|
128
|
+
)
|
|
129
|
+
})
|
|
93
130
|
mutate(state)
|
|
94
131
|
} else {
|
|
95
|
-
setState(
|
|
132
|
+
setState((store) => {
|
|
133
|
+
return reconcileFn(
|
|
134
|
+
store,
|
|
135
|
+
result,
|
|
136
|
+
reconcileOptions === undefined ? 'id' : reconcileOptions,
|
|
137
|
+
)
|
|
138
|
+
})
|
|
96
139
|
refetch()
|
|
97
140
|
}
|
|
98
141
|
})()
|
|
@@ -178,13 +221,17 @@ export function createBaseQuery<
|
|
|
178
221
|
}
|
|
179
222
|
})
|
|
180
223
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
224
|
+
createComputed(
|
|
225
|
+
on(
|
|
226
|
+
() => client().defaultQueryOptions(options()),
|
|
227
|
+
() => observer.setOptions(client().defaultQueryOptions(options())),
|
|
228
|
+
{
|
|
229
|
+
// Defer because we don't need to trigger on first render
|
|
230
|
+
// This only cares about changes to options after the observer is created
|
|
231
|
+
defer: true,
|
|
232
|
+
},
|
|
233
|
+
),
|
|
234
|
+
)
|
|
188
235
|
|
|
189
236
|
createComputed(
|
|
190
237
|
on(
|
|
@@ -193,7 +240,7 @@ export function createBaseQuery<
|
|
|
193
240
|
if (
|
|
194
241
|
state.isError &&
|
|
195
242
|
!state.isFetching &&
|
|
196
|
-
shouldThrowError(observer.options.
|
|
243
|
+
shouldThrowError(observer.options.throwOnError, [
|
|
197
244
|
state.error,
|
|
198
245
|
observer.getCurrentQuery(),
|
|
199
246
|
])
|
|
@@ -209,10 +256,8 @@ export function createBaseQuery<
|
|
|
209
256
|
target: QueryObserverResult<TData, TError>,
|
|
210
257
|
prop: keyof QueryObserverResult<TData, TError>,
|
|
211
258
|
): any {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return Reflect.get(target, prop)
|
|
259
|
+
const val = queryResource()?.[prop]
|
|
260
|
+
return val !== undefined ? val : Reflect.get(target, prop)
|
|
216
261
|
},
|
|
217
262
|
}
|
|
218
263
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
QueryObserver,
|
|
3
3
|
QueryKey,
|
|
4
|
-
QueryClient,
|
|
5
4
|
DefaultError,
|
|
6
5
|
InfiniteData,
|
|
7
6
|
} from '@tanstack/query-core'
|
|
7
|
+
import type { QueryClient } from './QueryClient'
|
|
8
8
|
import { InfiniteQueryObserver } from '@tanstack/query-core'
|
|
9
9
|
import type {
|
|
10
10
|
CreateInfiniteQueryOptions,
|
package/src/createMutation.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DefaultError } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import { MutationObserver } from '@tanstack/query-core'
|
|
3
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
4
5
|
import type {
|
|
@@ -53,7 +54,7 @@ export function createMutation<
|
|
|
53
54
|
() => {
|
|
54
55
|
if (
|
|
55
56
|
state.isError &&
|
|
56
|
-
shouldThrowError(observer.options.
|
|
57
|
+
shouldThrowError(observer.options.throwOnError, [state.error])
|
|
57
58
|
) {
|
|
58
59
|
throw state.error
|
|
59
60
|
}
|
package/src/createQueries.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
QueriesPlaceholderDataFunction,
|
|
3
|
-
QueryClient,
|
|
4
3
|
QueryFunction,
|
|
5
4
|
QueryKey,
|
|
6
5
|
DefaultError,
|
|
6
|
+
QueriesObserverOptions,
|
|
7
7
|
} from '@tanstack/query-core'
|
|
8
8
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
9
|
+
import type { QueryClient } from './QueryClient'
|
|
9
10
|
import type { Accessor } from 'solid-js'
|
|
10
|
-
import { createComputed, onCleanup
|
|
11
|
+
import { createComputed, onCleanup } from 'solid-js'
|
|
11
12
|
import { createStore, unwrap } from 'solid-js/store'
|
|
12
13
|
import { useQueryClient } from './QueryClientProvider'
|
|
13
14
|
import type { CreateQueryResult, SolidQueryOptions } from './types'
|
|
@@ -148,12 +149,16 @@ export type QueriesResults<
|
|
|
148
149
|
: // Fallback
|
|
149
150
|
CreateQueryResult[]
|
|
150
151
|
|
|
151
|
-
export function createQueries<
|
|
152
|
+
export function createQueries<
|
|
153
|
+
T extends any[],
|
|
154
|
+
TCombinedResult = QueriesResults<T>,
|
|
155
|
+
>(
|
|
152
156
|
queriesOptions: Accessor<{
|
|
153
157
|
queries: readonly [...QueriesOptions<T>]
|
|
158
|
+
combine?: (result: QueriesResults<T>) => TCombinedResult
|
|
154
159
|
}>,
|
|
155
160
|
queryClient?: Accessor<QueryClient>,
|
|
156
|
-
):
|
|
161
|
+
): TCombinedResult {
|
|
157
162
|
const client = useQueryClient(queryClient?.())
|
|
158
163
|
|
|
159
164
|
const defaultedQueries = queriesOptions().queries.map((options) => {
|
|
@@ -162,32 +167,45 @@ export function createQueries<T extends any[]>(
|
|
|
162
167
|
return defaultedOptions
|
|
163
168
|
})
|
|
164
169
|
|
|
165
|
-
const observer = new QueriesObserver(
|
|
170
|
+
const observer = new QueriesObserver(
|
|
171
|
+
client,
|
|
172
|
+
defaultedQueries,
|
|
173
|
+
queriesOptions().combine
|
|
174
|
+
? ({
|
|
175
|
+
combine: queriesOptions().combine,
|
|
176
|
+
} as QueriesObserverOptions<TCombinedResult>)
|
|
177
|
+
: undefined,
|
|
178
|
+
)
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
180
|
+
// @ts-expect-error - Types issue with solid-js createStore
|
|
181
|
+
const [state, setState] = createStore<TCombinedResult>(
|
|
182
|
+
observer.getOptimisticResult(defaultedQueries)[1](),
|
|
169
183
|
)
|
|
170
184
|
|
|
171
185
|
const unsubscribe = observer.subscribe((result) => {
|
|
172
186
|
notifyManager.batchCalls(() => {
|
|
173
|
-
setState(unwrap(result))
|
|
187
|
+
setState(unwrap(result) as unknown as TCombinedResult)
|
|
174
188
|
})()
|
|
175
189
|
})
|
|
176
190
|
|
|
177
191
|
onCleanup(unsubscribe)
|
|
178
192
|
|
|
179
|
-
onMount(() => {
|
|
180
|
-
observer.setQueries(defaultedQueries, { listeners: false })
|
|
181
|
-
})
|
|
182
|
-
|
|
183
193
|
createComputed(() => {
|
|
184
194
|
const updatedQueries = queriesOptions().queries.map((options) => {
|
|
185
195
|
const defaultedOptions = client.defaultQueryOptions(options)
|
|
186
196
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
187
197
|
return defaultedOptions
|
|
188
198
|
})
|
|
189
|
-
observer.setQueries(
|
|
199
|
+
observer.setQueries(
|
|
200
|
+
updatedQueries,
|
|
201
|
+
queriesOptions().combine
|
|
202
|
+
? ({
|
|
203
|
+
combine: queriesOptions().combine,
|
|
204
|
+
} as QueriesObserverOptions<TCombinedResult>)
|
|
205
|
+
: undefined,
|
|
206
|
+
{ listeners: false },
|
|
207
|
+
)
|
|
190
208
|
})
|
|
191
209
|
|
|
192
|
-
return state
|
|
210
|
+
return state
|
|
193
211
|
}
|
package/src/createQuery.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryKey, DefaultError } from '@tanstack/query-core'
|
|
2
2
|
import { QueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import type { QueryClient } from './QueryClient'
|
|
3
4
|
import type { Accessor } from 'solid-js'
|
|
4
5
|
import { createMemo } from 'solid-js'
|
|
5
6
|
import { createBaseQuery } from './createBaseQuery'
|
|
@@ -33,6 +34,28 @@ type DefinedInitialDataOptions<
|
|
|
33
34
|
}
|
|
34
35
|
>
|
|
35
36
|
|
|
37
|
+
export function queryOptions<
|
|
38
|
+
TQueryFnData = unknown,
|
|
39
|
+
TError = unknown,
|
|
40
|
+
TData = TQueryFnData,
|
|
41
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
42
|
+
>(
|
|
43
|
+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
44
|
+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
45
|
+
|
|
46
|
+
export function queryOptions<
|
|
47
|
+
TQueryFnData = unknown,
|
|
48
|
+
TError = unknown,
|
|
49
|
+
TData = TQueryFnData,
|
|
50
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
51
|
+
>(
|
|
52
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
53
|
+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
54
|
+
|
|
55
|
+
export function queryOptions(options: unknown) {
|
|
56
|
+
return options
|
|
57
|
+
}
|
|
58
|
+
|
|
36
59
|
export function createQuery<
|
|
37
60
|
TQueryFnData = unknown,
|
|
38
61
|
TError = DefaultError,
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,14 @@ export * from '@tanstack/query-core'
|
|
|
8
8
|
|
|
9
9
|
// Solid Query
|
|
10
10
|
export * from './types'
|
|
11
|
-
export {
|
|
11
|
+
export { QueryClient } from './QueryClient'
|
|
12
|
+
export type {
|
|
13
|
+
QueryObserverOptions,
|
|
14
|
+
DefaultOptions,
|
|
15
|
+
QueryClientConfig,
|
|
16
|
+
InfiniteQueryObserverOptions,
|
|
17
|
+
} from './QueryClient'
|
|
18
|
+
export { createQuery, queryOptions } from './createQuery'
|
|
12
19
|
export {
|
|
13
20
|
QueryClientContext,
|
|
14
21
|
QueryClientProvider,
|
package/src/types.ts
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
QueryKey,
|
|
5
|
-
QueryObserverOptions,
|
|
6
5
|
QueryObserverResult,
|
|
7
6
|
MutateFunction,
|
|
8
7
|
MutationObserverOptions,
|
|
9
8
|
MutationObserverResult,
|
|
10
9
|
DefinedQueryObserverResult,
|
|
11
|
-
InfiniteQueryObserverOptions,
|
|
12
10
|
InfiniteQueryObserverResult,
|
|
13
11
|
WithRequired,
|
|
14
12
|
DefaultError,
|
|
15
13
|
} from '@tanstack/query-core'
|
|
14
|
+
import type {
|
|
15
|
+
QueryObserverOptions,
|
|
16
|
+
InfiniteQueryObserverOptions,
|
|
17
|
+
} from './QueryClient'
|
|
16
18
|
|
|
17
19
|
export type FunctionedParams<T> = () => T
|
|
18
20
|
|
package/src/useIsFetching.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryFilters } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import type { Accessor } from 'solid-js'
|
|
3
4
|
import { createMemo, createSignal, onCleanup } from 'solid-js'
|
|
4
5
|
import { useQueryClient } from './QueryClientProvider'
|
package/src/useIsMutating.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { MutationFilters
|
|
1
|
+
import type { MutationFilters } from '@tanstack/query-core'
|
|
2
|
+
import type { QueryClient } from './QueryClient'
|
|
2
3
|
import { useQueryClient } from './QueryClientProvider'
|
|
3
4
|
import type { Accessor } from 'solid-js'
|
|
4
5
|
import { createSignal, onCleanup, createMemo } from 'solid-js'
|