@pyreon/query 0.10.0 → 0.11.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/lib/analysis/index.js.html +1 -1
- package/lib/index.js +164 -2
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +74 -7
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +14 -7
- package/src/index.ts +25 -19
- package/src/query-client.ts +5 -5
- package/src/tests/query.test.tsx +254 -268
- package/src/tests/sse.test.tsx +857 -0
- package/src/tests/subscription.test.tsx +200 -82
- package/src/use-infinite-query.ts +11 -19
- package/src/use-is-fetching.ts +5 -5
- package/src/use-mutation.ts +12 -21
- package/src/use-queries.ts +20 -19
- package/src/use-query-error-reset-boundary.ts +8 -11
- package/src/use-query.ts +10 -17
- package/src/use-sse.ts +266 -0
- package/src/use-subscription.ts +27 -39
- package/src/use-suspense-query.ts +18 -34
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { VNodeChild, VNodeChildAtom } from
|
|
2
|
-
import { onUnmount } from
|
|
3
|
-
import type { Signal } from
|
|
4
|
-
import { batch, effect, signal } from
|
|
1
|
+
import type { VNodeChild, VNodeChildAtom } from "@pyreon/core"
|
|
2
|
+
import { onUnmount } from "@pyreon/core"
|
|
3
|
+
import type { Signal } from "@pyreon/reactivity"
|
|
4
|
+
import { batch, effect, signal } from "@pyreon/reactivity"
|
|
5
5
|
import type {
|
|
6
6
|
DefaultError,
|
|
7
7
|
InfiniteData,
|
|
@@ -10,9 +10,9 @@ import type {
|
|
|
10
10
|
QueryKey,
|
|
11
11
|
QueryObserverOptions,
|
|
12
12
|
QueryObserverResult,
|
|
13
|
-
} from
|
|
14
|
-
import { InfiniteQueryObserver, QueryObserver } from
|
|
15
|
-
import { useQueryClient } from
|
|
13
|
+
} from "@tanstack/query-core"
|
|
14
|
+
import { InfiniteQueryObserver, QueryObserver } from "@tanstack/query-core"
|
|
15
|
+
import { useQueryClient } from "./query-client"
|
|
16
16
|
|
|
17
17
|
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ export interface UseSuspenseQueryResult<TData, TError = DefaultError> {
|
|
|
26
26
|
/** Always TData — never undefined inside a QuerySuspense boundary. */
|
|
27
27
|
data: Signal<TData>
|
|
28
28
|
error: Signal<TError | null>
|
|
29
|
-
status: Signal<
|
|
29
|
+
status: Signal<"pending" | "error" | "success">
|
|
30
30
|
isPending: Signal<boolean>
|
|
31
31
|
isFetching: Signal<boolean>
|
|
32
32
|
isError: Signal<boolean>
|
|
@@ -34,17 +34,12 @@ export interface UseSuspenseQueryResult<TData, TError = DefaultError> {
|
|
|
34
34
|
refetch: () => Promise<QueryObserverResult<TData, TError>>
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export interface UseSuspenseInfiniteQueryResult<
|
|
38
|
-
TQueryFnData
|
|
39
|
-
TError = DefaultError,
|
|
40
|
-
> {
|
|
41
|
-
result: Signal<
|
|
42
|
-
InfiniteQueryObserverResult<InfiniteData<TQueryFnData>, TError>
|
|
43
|
-
>
|
|
37
|
+
export interface UseSuspenseInfiniteQueryResult<TQueryFnData, TError = DefaultError> {
|
|
38
|
+
result: Signal<InfiniteQueryObserverResult<InfiniteData<TQueryFnData>, TError>>
|
|
44
39
|
/** Always InfiniteData<TQueryFnData> — never undefined inside a QuerySuspense boundary. */
|
|
45
40
|
data: Signal<InfiniteData<TQueryFnData>>
|
|
46
41
|
error: Signal<TError | null>
|
|
47
|
-
status: Signal<
|
|
42
|
+
status: Signal<"pending" | "error" | "success">
|
|
48
43
|
isFetching: Signal<boolean>
|
|
49
44
|
isFetchingNextPage: Signal<boolean>
|
|
50
45
|
isFetchingPreviousPage: Signal<boolean>
|
|
@@ -52,15 +47,9 @@ export interface UseSuspenseInfiniteQueryResult<
|
|
|
52
47
|
isSuccess: Signal<boolean>
|
|
53
48
|
hasNextPage: Signal<boolean>
|
|
54
49
|
hasPreviousPage: Signal<boolean>
|
|
55
|
-
fetchNextPage: () => Promise<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
fetchPreviousPage: () => Promise<
|
|
59
|
-
InfiniteQueryObserverResult<InfiniteData<TQueryFnData>, TError>
|
|
60
|
-
>
|
|
61
|
-
refetch: () => Promise<
|
|
62
|
-
QueryObserverResult<InfiniteData<TQueryFnData>, TError>
|
|
63
|
-
>
|
|
50
|
+
fetchNextPage: () => Promise<InfiniteQueryObserverResult<InfiniteData<TQueryFnData>, TError>>
|
|
51
|
+
fetchPreviousPage: () => Promise<InfiniteQueryObserverResult<InfiniteData<TQueryFnData>, TError>>
|
|
52
|
+
refetch: () => Promise<QueryObserverResult<InfiniteData<TQueryFnData>, TError>>
|
|
64
53
|
}
|
|
65
54
|
|
|
66
55
|
// ─── QuerySuspense ──────────────────────────────────────────────────────────
|
|
@@ -120,15 +109,13 @@ export function QuerySuspense(props: QuerySuspenseProps): VNodeChild {
|
|
|
120
109
|
if (queries.some((q) => q.isPending())) {
|
|
121
110
|
const fb = props.fallback
|
|
122
111
|
return (
|
|
123
|
-
typeof fb ===
|
|
112
|
+
typeof fb === "function" ? (fb as () => VNodeChildAtom)() : (fb ?? null)
|
|
124
113
|
) as VNodeChildAtom
|
|
125
114
|
}
|
|
126
115
|
|
|
127
116
|
// All success — render children
|
|
128
117
|
const ch = props.children
|
|
129
|
-
return (
|
|
130
|
-
typeof ch === 'function' ? (ch as () => VNodeChildAtom)() : ch
|
|
131
|
-
) as VNodeChildAtom
|
|
118
|
+
return (typeof ch === "function" ? (ch as () => VNodeChildAtom)() : ch) as VNodeChildAtom
|
|
132
119
|
}
|
|
133
120
|
}
|
|
134
121
|
|
|
@@ -154,16 +141,13 @@ export function useSuspenseQuery<
|
|
|
154
141
|
options: () => QueryObserverOptions<TData, TError, TData, TData, TKey>,
|
|
155
142
|
): UseSuspenseQueryResult<TData, TError> {
|
|
156
143
|
const client = useQueryClient()
|
|
157
|
-
const observer = new QueryObserver<TData, TError, TData, TData, TKey>(
|
|
158
|
-
client,
|
|
159
|
-
options(),
|
|
160
|
-
)
|
|
144
|
+
const observer = new QueryObserver<TData, TError, TData, TData, TKey>(client, options())
|
|
161
145
|
const initial = observer.getCurrentResult()
|
|
162
146
|
|
|
163
147
|
const resultSig = signal<QueryObserverResult<TData, TError>>(initial)
|
|
164
148
|
const dataSig = signal<TData>(initial.data as TData)
|
|
165
149
|
const errorSig = signal<TError | null>(initial.error ?? null)
|
|
166
|
-
const statusSig = signal<
|
|
150
|
+
const statusSig = signal<"pending" | "error" | "success">(initial.status)
|
|
167
151
|
const isPending = signal(initial.isPending)
|
|
168
152
|
const isFetching = signal(initial.isFetching)
|
|
169
153
|
const isError = signal(initial.isError)
|