@tanstack/solid-query 5.0.0 → 5.2.0
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 +1 -1
- package/build/index.cjs +1 -1
- package/build/index.d.cts +1 -2
- package/build/index.d.ts +1 -2
- package/package.json +3 -3
- package/src/__tests__/QueryClientProvider.test.tsx +1 -2
- package/src/__tests__/createInfiniteQuery.test.tsx +1 -1
- package/src/__tests__/createMutation.test.tsx +1 -2
- package/src/__tests__/createQueries.test.tsx +1 -1
- package/src/__tests__/createQuery.test.tsx +1 -2
- package/src/__tests__/createQuery.types.test.tsx +1 -0
- package/src/__tests__/suspense.test.tsx +1 -1
- package/src/__tests__/transition.test.tsx +1 -1
- package/src/__tests__/useIsFetching.test.tsx +1 -1
- package/src/__tests__/useIsMutating.test.tsx +1 -2
- package/src/__tests__/useMutationState.test.tsx +90 -0
- package/src/__tests__/utils.tsx +3 -1
- package/src/useMutationState.ts +63 -0
package/build/dev.cjs
CHANGED
|
@@ -447,7 +447,7 @@ exports.queryOptions = queryOptions;
|
|
|
447
447
|
exports.useIsFetching = useIsFetching;
|
|
448
448
|
exports.useIsMutating = useIsMutating;
|
|
449
449
|
Object.keys(queryCore).forEach(function (k) {
|
|
450
|
-
if (k !== 'default' && !
|
|
450
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
451
451
|
enumerable: true,
|
|
452
452
|
get: function () { return queryCore[k]; }
|
|
453
453
|
});
|
package/build/index.cjs
CHANGED
|
@@ -447,7 +447,7 @@ exports.queryOptions = queryOptions;
|
|
|
447
447
|
exports.useIsFetching = useIsFetching;
|
|
448
448
|
exports.useIsMutating = useIsMutating;
|
|
449
449
|
Object.keys(queryCore).forEach(function (k) {
|
|
450
|
-
if (k !== 'default' && !
|
|
450
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
451
451
|
enumerable: true,
|
|
452
452
|
get: function () { return queryCore[k]; }
|
|
453
453
|
});
|
package/build/index.d.cts
CHANGED
|
@@ -2,7 +2,6 @@ import { DefaultError, QueryKey, QueryObserverOptions as QueryObserverOptions$1,
|
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
3
|
import * as solid_js from 'solid-js';
|
|
4
4
|
import { JSX, Accessor } from 'solid-js';
|
|
5
|
-
import * as solid_js_types_reactive_signal from 'solid-js/types/reactive/signal';
|
|
6
5
|
|
|
7
6
|
interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> extends Omit<QueryObserverOptions$1<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'structuralSharing'> {
|
|
8
7
|
/**
|
|
@@ -145,6 +144,6 @@ declare function createQueries<T extends Array<any>, TCombinedResult extends Que
|
|
|
145
144
|
}>, queryClient?: Accessor<QueryClient>): TCombinedResult;
|
|
146
145
|
|
|
147
146
|
declare const useIsRestoring: () => Accessor<boolean>;
|
|
148
|
-
declare const IsRestoringProvider:
|
|
147
|
+
declare const IsRestoringProvider: solid_js.ContextProviderComponent<Accessor<boolean>>;
|
|
149
148
|
|
|
150
149
|
export { CreateBaseMutationResult, CreateBaseQueryOptions, CreateBaseQueryResult, CreateInfiniteQueryOptions, CreateInfiniteQueryResult, CreateMutateAsyncFunction, CreateMutateFunction, CreateMutationOptions, CreateMutationResult, CreateQueryOptions, CreateQueryResult, DefaultOptions, DefinedCreateBaseQueryResult, DefinedCreateQueryResult, FunctionedParams, InfiniteQueryObserverOptions, IsRestoringProvider, QueryClient, QueryClientConfig, QueryClientContext, QueryClientProvider, QueryClientProviderProps, QueryObserverOptions, SolidInfiniteQueryOptions, SolidMutationOptions, SolidQueryOptions, createInfiniteQuery, createMutation, createQueries, createQuery, queryOptions, useIsFetching, useIsMutating, useIsRestoring, useQueryClient };
|
package/build/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { DefaultError, QueryKey, QueryObserverOptions as QueryObserverOptions$1,
|
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
3
|
import * as solid_js from 'solid-js';
|
|
4
4
|
import { JSX, Accessor } from 'solid-js';
|
|
5
|
-
import * as solid_js_types_reactive_signal from 'solid-js/types/reactive/signal';
|
|
6
5
|
|
|
7
6
|
interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> extends Omit<QueryObserverOptions$1<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'structuralSharing'> {
|
|
8
7
|
/**
|
|
@@ -145,6 +144,6 @@ declare function createQueries<T extends Array<any>, TCombinedResult extends Que
|
|
|
145
144
|
}>, queryClient?: Accessor<QueryClient>): TCombinedResult;
|
|
146
145
|
|
|
147
146
|
declare const useIsRestoring: () => Accessor<boolean>;
|
|
148
|
-
declare const IsRestoringProvider:
|
|
147
|
+
declare const IsRestoringProvider: solid_js.ContextProviderComponent<Accessor<boolean>>;
|
|
149
148
|
|
|
150
149
|
export { CreateBaseMutationResult, CreateBaseQueryOptions, CreateBaseQueryResult, CreateInfiniteQueryOptions, CreateInfiniteQueryResult, CreateMutateAsyncFunction, CreateMutateFunction, CreateMutationOptions, CreateMutationResult, CreateQueryOptions, CreateQueryResult, DefaultOptions, DefinedCreateBaseQueryResult, DefinedCreateQueryResult, FunctionedParams, InfiniteQueryObserverOptions, IsRestoringProvider, QueryClient, QueryClientConfig, QueryClientContext, QueryClientProvider, QueryClientProviderProps, QueryObserverOptions, SolidInfiniteQueryOptions, SolidMutationOptions, SolidQueryOptions, createInfiniteQuery, createMutation, createQueries, createQuery, queryOptions, useIsFetching, useIsMutating, useIsRestoring, useQueryClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"solid-js": "^1.7.8",
|
|
51
|
-
"@tanstack/query-core": "5.0.
|
|
51
|
+
"@tanstack/query-core": "5.0.5"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"tsup-preset-solid": "^2.0
|
|
54
|
+
"tsup-preset-solid": "^2.1.0",
|
|
55
55
|
"vite-plugin-solid": "^2.7.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
1
2
|
import { render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
|
-
|
|
3
3
|
import { QueryCache } from '@tanstack/query-core'
|
|
4
|
-
import { vi } from 'vitest'
|
|
5
4
|
import { QueryClientProvider, createQuery, useQueryClient } from '..'
|
|
6
5
|
import { createQueryClient, queryKey, sleep } from './utils'
|
|
7
6
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
createSignal,
|
|
11
12
|
on,
|
|
12
13
|
} from 'solid-js'
|
|
13
|
-
import { vi } from 'vitest'
|
|
14
14
|
import {
|
|
15
15
|
QueryCache,
|
|
16
16
|
QueryClientProvider,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import {
|
|
3
3
|
ErrorBoundary,
|
|
4
4
|
createEffect,
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
createSignal,
|
|
7
7
|
} from 'solid-js'
|
|
8
8
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
9
|
-
import { vi } from 'vitest'
|
|
10
9
|
import {
|
|
11
10
|
MutationCache,
|
|
12
11
|
QueryCache,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, it, vi } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
3
|
import * as QueryCore from '@tanstack/query-core'
|
|
3
4
|
|
|
4
5
|
import { createRenderEffect, createSignal } from 'solid-js'
|
|
5
|
-
import { vi } from 'vitest'
|
|
6
6
|
import {
|
|
7
7
|
QueriesObserver,
|
|
8
8
|
QueryCache,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import '
|
|
1
|
+
import { describe, expect, expectTypeOf, it, vi } from 'vitest'
|
|
2
2
|
import {
|
|
3
3
|
ErrorBoundary,
|
|
4
4
|
Match,
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
on,
|
|
11
11
|
} from 'solid-js'
|
|
12
12
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
13
|
-
import { vi } from 'vitest'
|
|
14
13
|
import { reconcile } from 'solid-js/store'
|
|
15
14
|
import {
|
|
16
15
|
QueryCache,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -8,7 +9,6 @@ import {
|
|
|
8
9
|
createSignal,
|
|
9
10
|
on,
|
|
10
11
|
} from 'solid-js'
|
|
11
|
-
import { vi } from 'vitest'
|
|
12
12
|
import {
|
|
13
13
|
QueryCache,
|
|
14
14
|
QueryClientProvider,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { describe, it } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
|
-
|
|
3
3
|
import { Show, Suspense, createSignal, startTransition } from 'solid-js'
|
|
4
4
|
import { QueryCache, QueryClientProvider, createQuery } from '..'
|
|
5
5
|
import { createQueryClient, queryKey, sleep } from './utils'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
|
-
|
|
3
3
|
import { Show, createEffect, createRenderEffect, createSignal } from 'solid-js'
|
|
4
4
|
import { QueryCache, QueryClientProvider, createQuery, useIsFetching } from '..'
|
|
5
5
|
import { createQueryClient, queryKey, setActTimeout, sleep } from './utils'
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
1
2
|
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library'
|
|
2
|
-
|
|
3
3
|
import { Show, createEffect, createRenderEffect, createSignal } from 'solid-js'
|
|
4
4
|
import * as QueryCore from '@tanstack/query-core'
|
|
5
|
-
import { vi } from 'vitest'
|
|
6
5
|
import { QueryClientProvider, createMutation, useIsMutating } from '..'
|
|
7
6
|
import { createQueryClient, setActTimeout, sleep } from './utils'
|
|
8
7
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, it } from 'vitest'
|
|
2
|
+
import { fireEvent, render, waitFor } from '@solidjs/testing-library'
|
|
3
|
+
import { createEffect } from 'solid-js'
|
|
4
|
+
import { useMutationState } from '../useMutationState'
|
|
5
|
+
import { createMutation } from '../createMutation'
|
|
6
|
+
import { QueryClientProvider } from '../QueryClientProvider'
|
|
7
|
+
import { createQueryClient, doNotExecute, sleep } from './utils'
|
|
8
|
+
import type { MutationState, MutationStatus } from '@tanstack/query-core'
|
|
9
|
+
|
|
10
|
+
describe('useMutationState', () => {
|
|
11
|
+
describe('types', () => {
|
|
12
|
+
it('should default to QueryState', () => {
|
|
13
|
+
doNotExecute(() => {
|
|
14
|
+
const result = useMutationState(() => ({
|
|
15
|
+
filters: { status: 'pending' },
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
expectTypeOf<Array<MutationState>>(result())
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
it('should infer with select', () => {
|
|
22
|
+
doNotExecute(() => {
|
|
23
|
+
const result = useMutationState(() => ({
|
|
24
|
+
filters: { status: 'pending' },
|
|
25
|
+
select: (mutation) => mutation.state.status,
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
expectTypeOf<Array<MutationStatus>>(result())
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
it('should return variables after calling mutate', async () => {
|
|
33
|
+
const queryClient = createQueryClient()
|
|
34
|
+
const variables: Array<Array<unknown>> = []
|
|
35
|
+
const mutationKey = ['mutation']
|
|
36
|
+
|
|
37
|
+
function Variables() {
|
|
38
|
+
const states = useMutationState(() => ({
|
|
39
|
+
filters: { mutationKey, status: 'pending' },
|
|
40
|
+
select: (mutation) => mutation.state.variables,
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
createEffect(() => {
|
|
44
|
+
variables.push(states())
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Mutate() {
|
|
51
|
+
const mutation = createMutation(() => ({
|
|
52
|
+
mutationKey,
|
|
53
|
+
mutationFn: async (input: number) => {
|
|
54
|
+
await sleep(150)
|
|
55
|
+
return 'data' + input
|
|
56
|
+
},
|
|
57
|
+
}))
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div>
|
|
61
|
+
data: {mutation.data ?? 'null'}
|
|
62
|
+
<button onClick={() => mutation.mutate(1)}>mutate</button>
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function Page() {
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<Variables />
|
|
71
|
+
<Mutate />
|
|
72
|
+
</div>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const rendered = render(() => (
|
|
77
|
+
<QueryClientProvider client={queryClient}>
|
|
78
|
+
<Page />
|
|
79
|
+
</QueryClientProvider>
|
|
80
|
+
))
|
|
81
|
+
|
|
82
|
+
await waitFor(() => rendered.getByText('data: null'))
|
|
83
|
+
|
|
84
|
+
fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
|
|
85
|
+
|
|
86
|
+
await waitFor(() => rendered.getByText('data: data1'))
|
|
87
|
+
|
|
88
|
+
expect(variables).toEqual([[], [1], []])
|
|
89
|
+
})
|
|
90
|
+
})
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Show, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
2
1
|
import { vi } from 'vitest'
|
|
2
|
+
import { Show, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
3
3
|
import { onlineManager } from '@tanstack/query-core'
|
|
4
4
|
import { QueryClient } from '../QueryClient'
|
|
5
5
|
import type { QueryClientConfig } from '@tanstack/query-core'
|
|
@@ -66,3 +66,5 @@ export function setActTimeout(fn: () => void, ms?: number) {
|
|
|
66
66
|
export function expectTypeNotAny<T>(_: 0 extends 1 & T ? never : T): void {
|
|
67
67
|
return undefined
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
export const doNotExecute = (_func: () => void) => true
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js'
|
|
2
|
+
import { replaceEqualDeep } from '@tanstack/query-core'
|
|
3
|
+
import { useQueryClient } from './QueryClientProvider'
|
|
4
|
+
import type {
|
|
5
|
+
DefaultError,
|
|
6
|
+
Mutation,
|
|
7
|
+
MutationCache,
|
|
8
|
+
MutationFilters,
|
|
9
|
+
MutationState,
|
|
10
|
+
} from '@tanstack/query-core'
|
|
11
|
+
import type { Accessor } from 'solid-js'
|
|
12
|
+
import type { QueryClient } from './QueryClient'
|
|
13
|
+
|
|
14
|
+
type MutationStateOptions<TResult = MutationState> = {
|
|
15
|
+
filters?: MutationFilters
|
|
16
|
+
select?: (
|
|
17
|
+
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
|
|
18
|
+
) => TResult
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getResult<TResult = MutationState>(
|
|
22
|
+
mutationCache: MutationCache,
|
|
23
|
+
options: MutationStateOptions<TResult>,
|
|
24
|
+
): Array<TResult> {
|
|
25
|
+
return mutationCache
|
|
26
|
+
.findAll(options.filters)
|
|
27
|
+
.map(
|
|
28
|
+
(mutation): TResult =>
|
|
29
|
+
(options.select
|
|
30
|
+
? options.select(
|
|
31
|
+
mutation as Mutation<unknown, DefaultError, unknown, unknown>,
|
|
32
|
+
)
|
|
33
|
+
: mutation.state) as TResult,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useMutationState<TResult = MutationState>(
|
|
38
|
+
options: Accessor<MutationStateOptions<TResult>> = () => ({}),
|
|
39
|
+
queryClient?: Accessor<QueryClient>,
|
|
40
|
+
): Accessor<Array<TResult>> {
|
|
41
|
+
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
42
|
+
const mutationCache = createMemo(() => client().getMutationCache())
|
|
43
|
+
|
|
44
|
+
const [result, setResult] = createSignal(
|
|
45
|
+
getResult(mutationCache(), options()),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
createEffect(() => {
|
|
49
|
+
const unsubscribe = mutationCache().subscribe(() => {
|
|
50
|
+
const nextResult = replaceEqualDeep(
|
|
51
|
+
result(),
|
|
52
|
+
getResult(mutationCache(), options()),
|
|
53
|
+
)
|
|
54
|
+
if (result() !== nextResult) {
|
|
55
|
+
setResult(nextResult)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
onCleanup(unsubscribe)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return result
|
|
63
|
+
}
|