@tanstack/vue-query 5.0.0-beta.22 → 5.0.0-beta.24
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/legacy/index.d.cts +2 -2
- package/build/legacy/index.d.ts +2 -2
- package/build/legacy/queryClient.cjs +3 -4
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +3 -4
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +7 -2
- package/build/legacy/types.d.ts +7 -2
- package/build/legacy/useBaseQuery.cjs +8 -4
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +1 -1
- package/build/legacy/useBaseQuery.d.ts +1 -1
- package/build/legacy/useBaseQuery.js +8 -4
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useMutation.cjs +7 -3
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +7 -3
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useQueries.cjs +14 -10
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +1 -1
- package/build/legacy/useQueries.d.ts +1 -1
- package/build/legacy/useQueries.js +14 -10
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/legacy/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +1 -1
- package/build/legacy/useQuery.d.ts +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +2 -0
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +3 -2
- package/build/legacy/vueQueryPlugin.d.ts +3 -2
- package/build/legacy/vueQueryPlugin.js +2 -0
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/index.d.cts +2 -2
- package/build/modern/index.d.ts +2 -2
- package/build/modern/queryClient.cjs +3 -4
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +3 -4
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +7 -2
- package/build/modern/types.d.ts +7 -2
- package/build/modern/useBaseQuery.cjs +8 -4
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +1 -1
- package/build/modern/useBaseQuery.d.ts +1 -1
- package/build/modern/useBaseQuery.js +8 -4
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +1 -1
- package/build/modern/useInfiniteQuery.d.ts +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useMutation.cjs +7 -3
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +7 -3
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useQueries.cjs +14 -10
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +1 -1
- package/build/modern/useQueries.d.ts +1 -1
- package/build/modern/useQueries.js +14 -10
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/modern/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +1 -1
- package/build/modern/useQuery.d.ts +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +1 -0
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +3 -2
- package/build/modern/vueQueryPlugin.d.ts +3 -2
- package/build/modern/vueQueryPlugin.js +1 -0
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/useQuery.test.ts +35 -6
- package/src/queryClient.ts +5 -6
- package/src/types.ts +23 -1
- package/src/useBaseQuery.ts +8 -4
- package/src/useInfiniteQuery.ts +2 -3
- package/src/useMutation.ts +7 -3
- package/src/useQueries.ts +14 -10
- package/src/useQuery.ts +10 -5
- package/src/vueQueryPlugin.ts +3 -2
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { QueryClient } from './queryClient.cjs';
|
|
2
2
|
import { QueryClientConfig } from '@tanstack/query-core';
|
|
3
|
-
import { MaybeRefDeep } from './types.cjs';
|
|
4
3
|
import 'vue-demi';
|
|
4
|
+
import './types.cjs';
|
|
5
5
|
|
|
6
6
|
type ClientPersister = (client: QueryClient) => [() => void, Promise<void>];
|
|
7
7
|
interface CommonOptions {
|
|
8
8
|
queryClientKey?: string;
|
|
9
9
|
clientPersister?: ClientPersister;
|
|
10
|
+
clientPersisterOnSuccess?: (client: QueryClient) => void;
|
|
10
11
|
}
|
|
11
12
|
interface ConfigOptions extends CommonOptions {
|
|
12
|
-
queryClientConfig?:
|
|
13
|
+
queryClientConfig?: QueryClientConfig;
|
|
13
14
|
}
|
|
14
15
|
interface ClientOptions extends CommonOptions {
|
|
15
16
|
queryClient?: QueryClient;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { QueryClient } from './queryClient.js';
|
|
2
2
|
import { QueryClientConfig } from '@tanstack/query-core';
|
|
3
|
-
import { MaybeRefDeep } from './types.js';
|
|
4
3
|
import 'vue-demi';
|
|
4
|
+
import './types.js';
|
|
5
5
|
|
|
6
6
|
type ClientPersister = (client: QueryClient) => [() => void, Promise<void>];
|
|
7
7
|
interface CommonOptions {
|
|
8
8
|
queryClientKey?: string;
|
|
9
9
|
clientPersister?: ClientPersister;
|
|
10
|
+
clientPersisterOnSuccess?: (client: QueryClient) => void;
|
|
10
11
|
}
|
|
11
12
|
interface ConfigOptions extends CommonOptions {
|
|
12
|
-
queryClientConfig?:
|
|
13
|
+
queryClientConfig?: QueryClientConfig;
|
|
13
14
|
}
|
|
14
15
|
interface ClientOptions extends CommonOptions {
|
|
15
16
|
queryClient?: QueryClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\
|
|
1
|
+
{"version":3,"sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport { isServer } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n clientPersister?: ClientPersister\n clientPersisterOnSuccess?: (client: QueryClient) => void\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: QueryClientConfig\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n\n if (!isServer) {\n client.mount()\n }\n\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n options.clientPersisterOnSuccess?.(client)\n })\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAqBvB,IAAM,iBAAiB;AAAA,EAC5B,SAAS,CAAC,KAAU,UAAiC,CAAC,MAAM;AAC1D,UAAM,YAAY,aAAa,QAAQ,cAAc;AACrD,QAAI;AAEJ,QAAI,iBAAiB,WAAW,QAAQ,aAAa;AACnD,eAAS,QAAQ;AAAA,IACnB,OAAO;AACL,YAAM,eACJ,uBAAuB,UAAU,QAAQ,oBAAoB;AAC/D,eAAS,IAAI,YAAY,YAAY;AAAA,IACvC;AAEA,QAAI,CAAC,UAAU;AACb,aAAO,MAAM;AAAA,IACf;AAEA,QAAI,mBAAmB,MAAM;AAAA,IAE7B;AAEA,QAAI,QAAQ,iBAAiB;AAC3B,aAAO,YAAY,QAAQ;AAC3B,YAAM,CAAC,SAAS,OAAO,IAAI,QAAQ,gBAAgB,MAAM;AACzD,yBAAmB;AACnB,cAAQ,KAAK,MAAM;AACjB,eAAO,YAAY,QAAQ;AAC3B,gBAAQ,2BAA2B,MAAM;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,MAAM;AACpB,aAAO,QAAQ;AACf,uBAAiB;AAAA,IACnB;AAEA,QAAI,IAAI,WAAW;AACjB,UAAI,UAAU,OAAO;AAAA,IACvB,OAAO;AACL,YAAM,kBAAkB,IAAI;AAC5B,UAAI,UAAU,SAAS,kBAAkB;AACvC,gBAAQ;AACR,wBAAgB;AAAA,MAClB;AAAA,IACF;AAEA,QAAI,QAAQ;AACV,UAAI,MAAM;AAAA,QACR,eAAe;AAEb,cAAI,CAAC,KAAK,WAAW;AACnB,kBAAM,eAAe,CAAC;AACtB,mBAAO,eAAe,MAAM,aAAa;AAAA,cACvC,KAAK,MAAM;AAAA,cACX,KAAK,CAAC,MAAM,OAAO,OAAO,cAAc,CAAC;AAAA,YAC3C,CAAC;AAAA,UACH;AAEA,eAAK,UAAU,SAAS,IAAI;AAE5B,cAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAI,SAAS,KAAK,OAAO;AACvB,4BAAc,MAAM,MAAM;AAAA,YAC5B;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AACL,UAAI,QAAQ,WAAW,MAAM;AAE7B,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,sBAAc,KAAK,MAAM;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.24",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
|
|
5
5
|
"author": "Damian Osipiuk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@tanstack/match-sorter-utils": "^8.8.4",
|
|
50
50
|
"@vue/devtools-api": "^6.5.0",
|
|
51
51
|
"vue-demi": "^0.14.6",
|
|
52
|
-
"@tanstack/query-core": "5.0.0-beta.
|
|
52
|
+
"@tanstack/query-core": "5.0.0-beta.23"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@vue/composition-api": "1.7.2",
|
|
@@ -138,8 +138,6 @@ describe('useQuery', () => {
|
|
|
138
138
|
})
|
|
139
139
|
|
|
140
140
|
secondKeyRef.value = 'key8'
|
|
141
|
-
await flushPromises()
|
|
142
|
-
|
|
143
141
|
expect(query).toMatchObject({
|
|
144
142
|
status: { value: 'pending' },
|
|
145
143
|
data: { value: undefined },
|
|
@@ -168,9 +166,6 @@ describe('useQuery', () => {
|
|
|
168
166
|
})
|
|
169
167
|
|
|
170
168
|
enabled.value = true
|
|
171
|
-
|
|
172
|
-
await flushPromises()
|
|
173
|
-
|
|
174
169
|
expect(query).toMatchObject({
|
|
175
170
|
fetchStatus: { value: 'fetching' },
|
|
176
171
|
data: { value: undefined },
|
|
@@ -191,16 +186,18 @@ describe('useQuery', () => {
|
|
|
191
186
|
|
|
192
187
|
const enabled = computed(() => !!data.value)
|
|
193
188
|
|
|
189
|
+
const dependentQueryFn = vi.fn().mockImplementation(simpleFetcher)
|
|
194
190
|
const { fetchStatus, status } = useQuery(
|
|
195
191
|
reactive({
|
|
196
192
|
queryKey: ['dependant2'],
|
|
197
|
-
queryFn:
|
|
193
|
+
queryFn: dependentQueryFn,
|
|
198
194
|
enabled,
|
|
199
195
|
}),
|
|
200
196
|
)
|
|
201
197
|
|
|
202
198
|
expect(data.value).toStrictEqual(undefined)
|
|
203
199
|
expect(fetchStatus.value).toStrictEqual('idle')
|
|
200
|
+
expect(dependentQueryFn).not.toHaveBeenCalled()
|
|
204
201
|
|
|
205
202
|
await flushPromises()
|
|
206
203
|
|
|
@@ -211,6 +208,10 @@ describe('useQuery', () => {
|
|
|
211
208
|
|
|
212
209
|
expect(fetchStatus.value).toStrictEqual('idle')
|
|
213
210
|
expect(status.value).toStrictEqual('success')
|
|
211
|
+
expect(dependentQueryFn).toHaveBeenCalledTimes(1)
|
|
212
|
+
expect(dependentQueryFn).toHaveBeenCalledWith(
|
|
213
|
+
expect.objectContaining({ queryKey: ['dependant2'] }),
|
|
214
|
+
)
|
|
214
215
|
})
|
|
215
216
|
|
|
216
217
|
test('should stop listening to changes on onScopeDispose', async () => {
|
|
@@ -235,6 +236,34 @@ describe('useQuery', () => {
|
|
|
235
236
|
expect(status.value).toStrictEqual('pending')
|
|
236
237
|
})
|
|
237
238
|
|
|
239
|
+
test('should use the current value for the queryKey when refetch is called', async () => {
|
|
240
|
+
const fetchFn = vi.fn()
|
|
241
|
+
const keyRef = ref('key11')
|
|
242
|
+
const query = useQuery({
|
|
243
|
+
queryKey: ['key10', keyRef],
|
|
244
|
+
queryFn: fetchFn,
|
|
245
|
+
enabled: false,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(fetchFn).not.toHaveBeenCalled()
|
|
249
|
+
await query.refetch()
|
|
250
|
+
expect(fetchFn).toHaveBeenCalledTimes(1)
|
|
251
|
+
expect(fetchFn).toHaveBeenCalledWith(
|
|
252
|
+
expect.objectContaining({
|
|
253
|
+
queryKey: ['key10', 'key11'],
|
|
254
|
+
}),
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
keyRef.value = 'key12'
|
|
258
|
+
await query.refetch()
|
|
259
|
+
expect(fetchFn).toHaveBeenCalledTimes(2)
|
|
260
|
+
expect(fetchFn).toHaveBeenCalledWith(
|
|
261
|
+
expect.objectContaining({
|
|
262
|
+
queryKey: ['key10', 'key12'],
|
|
263
|
+
}),
|
|
264
|
+
)
|
|
265
|
+
})
|
|
266
|
+
|
|
238
267
|
describe('throwOnError', () => {
|
|
239
268
|
test('should evaluate throwOnError when query is expected to throw', async () => {
|
|
240
269
|
const boundaryFn = vi.fn()
|
package/src/queryClient.ts
CHANGED
|
@@ -29,12 +29,11 @@ import type {
|
|
|
29
29
|
} from '@tanstack/query-core'
|
|
30
30
|
|
|
31
31
|
export class QueryClient extends QC {
|
|
32
|
-
constructor(config:
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
mutationCache: unreffedConfig.mutationCache || new MutationCache(),
|
|
32
|
+
constructor(config: QueryClientConfig = {}) {
|
|
33
|
+
const vueQueryConfig = {
|
|
34
|
+
defaultOptions: config.defaultOptions,
|
|
35
|
+
queryCache: config.queryCache || new QueryCache(),
|
|
36
|
+
mutationCache: config.mutationCache || new MutationCache(),
|
|
38
37
|
}
|
|
39
38
|
super(vueQueryConfig)
|
|
40
39
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import type { Ref } from 'vue-demi'
|
|
1
|
+
import type { Ref, UnwrapRef } from 'vue-demi'
|
|
2
|
+
|
|
3
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null
|
|
4
|
+
type UnwrapLeaf =
|
|
5
|
+
| Primitive
|
|
6
|
+
| Function
|
|
7
|
+
| Date
|
|
8
|
+
| Error
|
|
9
|
+
| RegExp
|
|
10
|
+
| Map<any, any>
|
|
11
|
+
| WeakMap<any, any>
|
|
12
|
+
| Set<any>
|
|
13
|
+
| WeakSet<any>
|
|
2
14
|
|
|
3
15
|
export type MaybeRef<T> = Ref<T> | T
|
|
4
16
|
|
|
@@ -12,6 +24,16 @@ export type MaybeRefDeep<T> = MaybeRef<
|
|
|
12
24
|
: T
|
|
13
25
|
>
|
|
14
26
|
|
|
27
|
+
export type DeepUnwrapRef<T> = T extends UnwrapLeaf
|
|
28
|
+
? T
|
|
29
|
+
: T extends Ref<infer U>
|
|
30
|
+
? DeepUnwrapRef<U>
|
|
31
|
+
: T extends {}
|
|
32
|
+
? {
|
|
33
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>
|
|
34
|
+
}
|
|
35
|
+
: UnwrapRef<T>
|
|
36
|
+
|
|
15
37
|
export type DistributiveOmit<T, K extends keyof any> = T extends any
|
|
16
38
|
? Omit<T, K>
|
|
17
39
|
: never
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -112,10 +112,14 @@ export function useBaseQuery<
|
|
|
112
112
|
{ immediate: true },
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
-
watch(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
watch(
|
|
116
|
+
defaultedOptions,
|
|
117
|
+
() => {
|
|
118
|
+
observer.setOptions(defaultedOptions.value)
|
|
119
|
+
updateState(state, observer.getCurrentResult())
|
|
120
|
+
},
|
|
121
|
+
{ flush: 'sync' },
|
|
122
|
+
)
|
|
119
123
|
|
|
120
124
|
onScopeDispose(() => {
|
|
121
125
|
unsubscribe()
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -12,9 +12,8 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
import type { UseBaseQueryReturnType } from './useBaseQuery'
|
|
14
14
|
|
|
15
|
-
import type { DistributiveOmit, MaybeRefDeep } from './types'
|
|
15
|
+
import type { DeepUnwrapRef, DistributiveOmit, MaybeRefDeep } from './types'
|
|
16
16
|
import type { QueryClient } from './queryClient'
|
|
17
|
-
import type { UnwrapRef } from 'vue-demi'
|
|
18
17
|
|
|
19
18
|
export type UseInfiniteQueryOptions<
|
|
20
19
|
TQueryFnData = unknown,
|
|
@@ -37,7 +36,7 @@ export type UseInfiniteQueryOptions<
|
|
|
37
36
|
TError,
|
|
38
37
|
TData,
|
|
39
38
|
TQueryData,
|
|
40
|
-
|
|
39
|
+
DeepUnwrapRef<TQueryKey>,
|
|
41
40
|
TPageParam
|
|
42
41
|
>[Property]
|
|
43
42
|
: MaybeRefDeep<
|
package/src/useMutation.ts
CHANGED
|
@@ -93,9 +93,13 @@ export function useMutation<
|
|
|
93
93
|
})
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
watch(
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
watch(
|
|
97
|
+
options,
|
|
98
|
+
() => {
|
|
99
|
+
observer.setOptions(options.value)
|
|
100
|
+
},
|
|
101
|
+
{ flush: 'sync' },
|
|
102
|
+
)
|
|
99
103
|
|
|
100
104
|
onScopeDispose(() => {
|
|
101
105
|
unsubscribe()
|
package/src/useQueries.ts
CHANGED
|
@@ -230,16 +230,20 @@ export function useQueries<
|
|
|
230
230
|
{ immediate: true },
|
|
231
231
|
)
|
|
232
232
|
|
|
233
|
-
watch(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
233
|
+
watch(
|
|
234
|
+
defaultedQueries,
|
|
235
|
+
() => {
|
|
236
|
+
observer.setQueries(
|
|
237
|
+
defaultedQueries.value,
|
|
238
|
+
options as QueriesObserverOptions<TCombinedResult>,
|
|
239
|
+
)
|
|
240
|
+
const [, getCombinedResultPersisted] = observer.getOptimisticResult(
|
|
241
|
+
defaultedQueries.value,
|
|
242
|
+
)
|
|
243
|
+
state.value = getCombinedResultPersisted()
|
|
244
|
+
},
|
|
245
|
+
{ flush: 'sync' },
|
|
246
|
+
)
|
|
243
247
|
|
|
244
248
|
onScopeDispose(() => {
|
|
245
249
|
unsubscribe()
|
package/src/useQuery.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryObserver } from '@tanstack/query-core'
|
|
2
2
|
import { useBaseQuery } from './useBaseQuery'
|
|
3
|
-
import type { ToRefs
|
|
3
|
+
import type { ToRefs } from 'vue-demi'
|
|
4
4
|
import type {
|
|
5
5
|
DefaultError,
|
|
6
6
|
DefinedQueryObserverResult,
|
|
@@ -10,7 +10,12 @@ import type {
|
|
|
10
10
|
WithRequired,
|
|
11
11
|
} from '@tanstack/query-core'
|
|
12
12
|
import type { UseBaseQueryReturnType } from './useBaseQuery'
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
DeepUnwrapRef,
|
|
15
|
+
DistributiveOmit,
|
|
16
|
+
MaybeRef,
|
|
17
|
+
MaybeRefDeep,
|
|
18
|
+
} from './types'
|
|
14
19
|
import type { QueryClient } from './queryClient'
|
|
15
20
|
|
|
16
21
|
export type UseQueryOptions<
|
|
@@ -19,7 +24,7 @@ export type UseQueryOptions<
|
|
|
19
24
|
TData = TQueryFnData,
|
|
20
25
|
TQueryData = TQueryFnData,
|
|
21
26
|
TQueryKey extends QueryKey = QueryKey,
|
|
22
|
-
> = {
|
|
27
|
+
> = MaybeRef<{
|
|
23
28
|
[Property in keyof QueryObserverOptions<
|
|
24
29
|
TQueryFnData,
|
|
25
30
|
TError,
|
|
@@ -32,7 +37,7 @@ export type UseQueryOptions<
|
|
|
32
37
|
TError,
|
|
33
38
|
TData,
|
|
34
39
|
TQueryData,
|
|
35
|
-
|
|
40
|
+
DeepUnwrapRef<TQueryKey>
|
|
36
41
|
>[Property]
|
|
37
42
|
: MaybeRefDeep<
|
|
38
43
|
WithRequired<
|
|
@@ -46,7 +51,7 @@ export type UseQueryOptions<
|
|
|
46
51
|
'queryKey'
|
|
47
52
|
>[Property]
|
|
48
53
|
>
|
|
49
|
-
}
|
|
54
|
+
}>
|
|
50
55
|
|
|
51
56
|
export type UseQueryReturnType<TData, TError> = DistributiveOmit<
|
|
52
57
|
UseBaseQueryReturnType<TData, TError>,
|
package/src/vueQueryPlugin.ts
CHANGED
|
@@ -5,17 +5,17 @@ import { QueryClient } from './queryClient'
|
|
|
5
5
|
import { getClientKey } from './utils'
|
|
6
6
|
import { setupDevtools } from './devtools/devtools'
|
|
7
7
|
import type { QueryClientConfig } from '@tanstack/query-core'
|
|
8
|
-
import type { MaybeRefDeep } from './types'
|
|
9
8
|
|
|
10
9
|
type ClientPersister = (client: QueryClient) => [() => void, Promise<void>]
|
|
11
10
|
|
|
12
11
|
interface CommonOptions {
|
|
13
12
|
queryClientKey?: string
|
|
14
13
|
clientPersister?: ClientPersister
|
|
14
|
+
clientPersisterOnSuccess?: (client: QueryClient) => void
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface ConfigOptions extends CommonOptions {
|
|
18
|
-
queryClientConfig?:
|
|
18
|
+
queryClientConfig?: QueryClientConfig
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
interface ClientOptions extends CommonOptions {
|
|
@@ -51,6 +51,7 @@ export const VueQueryPlugin = {
|
|
|
51
51
|
persisterUnmount = unmount
|
|
52
52
|
promise.then(() => {
|
|
53
53
|
client.isRestoring.value = false
|
|
54
|
+
options.clientPersisterOnSuccess?.(client)
|
|
54
55
|
})
|
|
55
56
|
}
|
|
56
57
|
|