@octanejs/tanstack-query 0.1.52 → 0.1.54
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/LICENSE.upstream +21 -0
- package/UPSTREAM.md +70 -0
- package/package.json +24 -10
- package/src/HydrationBoundary.tsrx +2 -9
- package/src/QueryClientProvider.tsrx +2 -8
- package/src/QueryClientProvider.tsrx.d.ts +1 -4
- package/src/QueryErrorResetBoundary.tsrx +2 -8
- package/src/index.ts +1 -0
- package/src/infiniteQueryOptions.ts +7 -11
- package/src/internal.ts +1 -5
- package/src/isRestoring.ts +1 -1
- package/src/queries-types.ts +1 -1
- package/src/queryOptions.ts +7 -11
- package/src/suspense-queries-types.ts +1 -1
- package/src/types.ts +40 -24
- package/src/useBaseQuery.ts +3 -29
- package/src/useMutationState.ts +15 -7
- package/src/usePrefetch.ts +9 -12
- package/src/useQueries.ts +17 -6
- package/src/useQuery.ts +3 -3
- package/src/useSuspenseQueries.ts +20 -1
- package/src/useSuspenseQuery.ts +9 -1
package/LICENSE.upstream
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/UPSTREAM.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Upstream
|
|
2
|
+
|
|
3
|
+
- Package: `@tanstack/react-query@5.102.8`
|
|
4
|
+
- Repository: https://github.com/TanStack/query
|
|
5
|
+
- Commit: `2969edf32f7e0c48e2a108d84712d6e01edfde21`
|
|
6
|
+
- Source and tests: `packages/react-query/src`, including `src/__tests__`
|
|
7
|
+
- License: MIT; exact upstream text ships as `LICENSE.upstream`.
|
|
8
|
+
|
|
9
|
+
## Source boundary
|
|
10
|
+
|
|
11
|
+
`audit/upstream.lock.json` pins every regular file in the package, the complete
|
|
12
|
+
source/test subtree, and root license. The two monorepo configuration symlinks
|
|
13
|
+
are excluded; neither contains adapter implementation or test registrations.
|
|
14
|
+
`upstream/` is byte-exact, unpublished evidence. `tests/upstream/` is regenerated
|
|
15
|
+
from the lock's import/type rewrites and committed divergence patches.
|
|
16
|
+
|
|
17
|
+
The release's npm declarations are retained in an integrity-verified tarball
|
|
18
|
+
under `upstream-artifact/`. The shared provenance verifier checks that artifact,
|
|
19
|
+
the attribution file, and the four immutable monorepo test utilities plus their
|
|
20
|
+
package manifest. Those utilities come from the same commit under
|
|
21
|
+
`packages/query-test-utils`; they are test-only. Published framework-neutral
|
|
22
|
+
`@tanstack/query-core@5.102.8` supplies caches, observers and all core re-exports.
|
|
23
|
+
React, its testing utilities and the persistence test oracle are dev dependencies.
|
|
24
|
+
|
|
25
|
+
## Supported surface
|
|
26
|
+
|
|
27
|
+
The root entry preserves every published adapter export and re-exports the neutral
|
|
28
|
+
core. `audit/upstream-crosswalk.json` lists all 213 upstream value and type exports
|
|
29
|
+
with public contract evidence. The existing `QueryErrorResetBoundaryValue` type
|
|
30
|
+
remains available for compatibility. The package does not copy the neutral core
|
|
31
|
+
or add convenience subpaths; upstream's `package.json` export describes its own
|
|
32
|
+
package metadata.
|
|
33
|
+
|
|
34
|
+
Query 5.102 removes `experimental_prefetchInRender`, its observer `promise` field,
|
|
35
|
+
and private before/after-query callbacks. Prefetch hooks use the new core query
|
|
36
|
+
execution APIs; their public options reject `skipToken`. Options carry the updated
|
|
37
|
+
query-key data tags, infinite-query defaults and mutation-state inference. Passive
|
|
38
|
+
`useQueries` does not report an optimistic fetch. Suspense infinite queries exclude
|
|
39
|
+
placeholder data, and falsey errors still reach opted-in boundaries. The mixed
|
|
40
|
+
query tuple overloads and component prop declarations match the published API.
|
|
41
|
+
|
|
42
|
+
## Executable evidence
|
|
43
|
+
|
|
44
|
+
The required pristine lane runs all 404 runtime registrations unchanged against
|
|
45
|
+
React. Adapted client and server lanes run the same 404 cases with no omissions.
|
|
46
|
+
Separate strict TypeScript programs cover all 167 pinned type registrations;
|
|
47
|
+
authored source and published imports receive independent strict checks. Public
|
|
48
|
+
probes check all 213 exports, concrete inferred results and invalid inputs. The
|
|
49
|
+
required differential lane compares cached queries, asynchronous queries and
|
|
50
|
+
mutations against the exact React release. Octane conformance covers subscriptions,
|
|
51
|
+
cache identity, error resets, transitions, cleanup and server snapshots.
|
|
52
|
+
|
|
53
|
+
The nine upstream SSR cases compile against Octane's server runtime and inspect
|
|
54
|
+
`RenderResult.html`. All three upstream hydration cases render a real Vite server
|
|
55
|
+
fixture, hydrate its separately compiled client twin, preserve the original text
|
|
56
|
+
node and retain their fetch/error/DOM assertions. Renderer markers are excluded
|
|
57
|
+
from visible-text assertions.
|
|
58
|
+
|
|
59
|
+
Committed patches explain intentional renderer differences: native StrictMode
|
|
60
|
+
behavior, a direct observation queue in place of React's render-stream harness,
|
|
61
|
+
error-boundary callbacks in place of React console argument formatting, visible
|
|
62
|
+
states in place of React replay counts, and query-owned timers in place of global
|
|
63
|
+
scheduler timing. Five type-suite checks of unused component declarations become
|
|
64
|
+
invalid-query negative controls because the authored-source program does not use
|
|
65
|
+
upstream's `noUnusedLocals` lint setting. Public type assertions remain strict.
|
|
66
|
+
|
|
67
|
+
Hook implementations retain compiler-assigned slots and Octane's stable Suspense
|
|
68
|
+
promise replay handling. They do not import React. Hydration uses the native
|
|
69
|
+
provider/component ownership model; the adapter publishes no separate streaming
|
|
70
|
+
server entrypoint.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/tanstack-query",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -31,27 +31,41 @@
|
|
|
31
31
|
"types": "src/index.ts",
|
|
32
32
|
"files": [
|
|
33
33
|
"src",
|
|
34
|
-
"README.md"
|
|
34
|
+
"README.md",
|
|
35
|
+
"UPSTREAM.md",
|
|
36
|
+
"LICENSE.upstream",
|
|
37
|
+
"LICENSE"
|
|
35
38
|
],
|
|
36
39
|
"exports": {
|
|
37
40
|
".": "./src/index.ts"
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-core": "
|
|
43
|
+
"@tanstack/query-core": "5.102.8"
|
|
41
44
|
},
|
|
42
45
|
"peerDependencies": {
|
|
43
|
-
"octane": "^0.1.51 || ^0.2.0"
|
|
46
|
+
"octane": "^0.1.51 || ^0.2.0 || ^0.3.0"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
|
-
"@tanstack/react-query": "
|
|
47
|
-
"@tsrx/react": "^0.
|
|
49
|
+
"@tanstack/react-query": "5.102.8",
|
|
50
|
+
"@tsrx/react": "^0.3.0",
|
|
48
51
|
"esbuild": "^0.28.1",
|
|
49
|
-
"react": "
|
|
50
|
-
"react-dom": "
|
|
52
|
+
"react": "19.2.7",
|
|
53
|
+
"react-dom": "19.2.7",
|
|
51
54
|
"vitest": "^4.1.10",
|
|
52
|
-
"
|
|
55
|
+
"@testing-library/react": "^16.3.2",
|
|
56
|
+
"@testing-library/react-render-stream": "2.0.2",
|
|
57
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
58
|
+
"react-error-boundary": "4.1.2",
|
|
59
|
+
"@types/react": "^19.2.17",
|
|
60
|
+
"@types/react-dom": "^19.2.3",
|
|
61
|
+
"@tanstack/query-persist-client-core": "5.102.8",
|
|
62
|
+
"@octanejs/testing-library": "0.1.52",
|
|
63
|
+
"octane": "0.3.0",
|
|
64
|
+
"@octanejs/react-error-boundary": "0.1.34"
|
|
53
65
|
},
|
|
54
66
|
"scripts": {
|
|
55
|
-
"test": "vitest run"
|
|
67
|
+
"test": "vitest run --root ../.. --project tanstack-query --project tanstack-query-adapted --project tanstack-query-adapted-ssr --project tanstack-query-differential --project tanstack-query-ssr",
|
|
68
|
+
"typecheck": "tsrx-tsc --noEmit -p tsconfig.json",
|
|
69
|
+
"upstream:verify": "node ../../scripts/react-parity/verify-provenance.mjs --package-dir ."
|
|
56
70
|
}
|
|
57
71
|
}
|
|
@@ -14,15 +14,8 @@
|
|
|
14
14
|
import { useRef, useMemo, useEffect } from 'octane';
|
|
15
15
|
import { hydrate } from '@tanstack/query-core';
|
|
16
16
|
import { resolveClient } from './context.ts';
|
|
17
|
-
import type {
|
|
18
|
-
import type {
|
|
19
|
-
|
|
20
|
-
type HydrationBoundaryProps = {
|
|
21
|
-
state?: unknown;
|
|
22
|
-
options?: HydrateOptions;
|
|
23
|
-
queryClient?: QueryClient;
|
|
24
|
-
children?: OctaneNode;
|
|
25
|
-
};
|
|
17
|
+
import type { DehydratedState } from '@tanstack/query-core';
|
|
18
|
+
import type { HydrationBoundaryProps } from './types';
|
|
26
19
|
|
|
27
20
|
export function HydrationBoundary(props: HydrationBoundaryProps) @{
|
|
28
21
|
const client = resolveClient(props.queryClient);
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'octane';
|
|
2
2
|
import { QueryClientContext } from './context.ts';
|
|
3
|
-
import type {
|
|
4
|
-
import type { QueryClient } from '@tanstack/query-core';
|
|
5
|
-
|
|
6
|
-
type QueryClientProviderProps = {
|
|
7
|
-
client: QueryClient;
|
|
8
|
-
children?: OctaneNode;
|
|
9
|
-
};
|
|
3
|
+
import type { QueryClientProviderProps } from './types';
|
|
10
4
|
|
|
11
5
|
// QueryClientProvider — provides the QueryClient via context and mounts/unmounts
|
|
12
6
|
// it with the component. It's authored in .tsrx because it's a COMPONENT that
|
|
@@ -19,5 +13,5 @@ export function QueryClientProvider(props: QueryClientProviderProps) @{
|
|
|
19
13
|
props.client.unmount();
|
|
20
14
|
};
|
|
21
15
|
}, [props.client]);
|
|
22
|
-
<QueryClientContext
|
|
16
|
+
<QueryClientContext value={props.client}>{props.children}</QueryClientContext>
|
|
23
17
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// It's a SPECIFIC module declaration (resolved by relative path), not an ambient
|
|
3
|
-
// `declare module '*.tsrx'` — so it types only this module and doesn't pollute a
|
|
4
|
-
// consumer's own .tsrx imports. The runtime resolves the real compiled .tsrx.
|
|
1
|
+
// Declaration companion for this module only.
|
|
5
2
|
import type { QueryClient } from '@tanstack/query-core';
|
|
6
3
|
|
|
7
4
|
export declare const QueryClientProvider: (props: {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { useState, isChildrenBlock } from 'octane';
|
|
2
2
|
import { QueryErrorResetBoundaryContext, createValue } from './errorResetBoundary.ts';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type QueryErrorResetBoundaryProps = {
|
|
6
|
-
children?: OctaneNode | ((value: ReturnType<typeof createValue>) => OctaneNode);
|
|
7
|
-
};
|
|
3
|
+
import type { QueryErrorResetBoundaryProps } from './types';
|
|
8
4
|
|
|
9
5
|
// QueryErrorResetBoundary — provides a fresh reset coordinator to its subtree.
|
|
10
6
|
// Place it above an error boundary; call `.reset()` from the boundary's retry so
|
|
@@ -20,7 +16,5 @@ export function QueryErrorResetBoundary(props: QueryErrorResetBoundaryProps) @{
|
|
|
20
16
|
typeof props.children === 'function' && !isChildrenBlock(props.children)
|
|
21
17
|
? props.children(value)
|
|
22
18
|
: props.children;
|
|
23
|
-
<QueryErrorResetBoundaryContext
|
|
24
|
-
value={value}
|
|
25
|
-
>{resolved}</QueryErrorResetBoundaryContext.Provider>
|
|
19
|
+
<QueryErrorResetBoundaryContext value={value}>{resolved}</QueryErrorResetBoundaryContext>
|
|
26
20
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
// Verbatim port of @tanstack/react-query's infiniteQueryOptions.ts — a typed identity helper
|
|
2
1
|
import type {
|
|
3
|
-
DataTag,
|
|
4
2
|
DefaultError,
|
|
5
3
|
InfiniteData,
|
|
6
4
|
InitialDataFunction,
|
|
7
5
|
NonUndefinedGuard,
|
|
8
6
|
OmitKeyof,
|
|
9
7
|
QueryKey,
|
|
8
|
+
QueryKeyWithDataTag,
|
|
10
9
|
SkipToken,
|
|
11
10
|
} from '@tanstack/query-core';
|
|
12
11
|
import type { UseInfiniteQueryOptions } from './types';
|
|
@@ -61,9 +60,8 @@ export function infiniteQueryOptions<
|
|
|
61
60
|
TPageParam = unknown,
|
|
62
61
|
>(
|
|
63
62
|
options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
64
|
-
): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
65
|
-
|
|
66
|
-
};
|
|
63
|
+
): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
64
|
+
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
67
65
|
|
|
68
66
|
export function infiniteQueryOptions<
|
|
69
67
|
TQueryFnData,
|
|
@@ -73,9 +71,8 @@ export function infiniteQueryOptions<
|
|
|
73
71
|
TPageParam = unknown,
|
|
74
72
|
>(
|
|
75
73
|
options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
76
|
-
): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
77
|
-
|
|
78
|
-
};
|
|
74
|
+
): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
75
|
+
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
79
76
|
|
|
80
77
|
export function infiniteQueryOptions<
|
|
81
78
|
TQueryFnData,
|
|
@@ -85,9 +82,8 @@ export function infiniteQueryOptions<
|
|
|
85
82
|
TPageParam = unknown,
|
|
86
83
|
>(
|
|
87
84
|
options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
88
|
-
): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
89
|
-
|
|
90
|
-
};
|
|
85
|
+
): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> &
|
|
86
|
+
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
91
87
|
|
|
92
88
|
export function infiniteQueryOptions(options: unknown) {
|
|
93
89
|
return options;
|
package/src/internal.ts
CHANGED
|
@@ -43,7 +43,7 @@ export function ensurePreventErrorBoundaryRetry(
|
|
|
43
43
|
query?.state.error && typeof options.throwOnError === 'function'
|
|
44
44
|
? shouldThrowError(options.throwOnError, [query.state.error, query])
|
|
45
45
|
: options.throwOnError;
|
|
46
|
-
if (options.suspense ||
|
|
46
|
+
if (options.suspense || throwOnError) {
|
|
47
47
|
if (!errorResetBoundary.isReset()) {
|
|
48
48
|
options.retryOnMount = false;
|
|
49
49
|
}
|
|
@@ -53,10 +53,6 @@ export function ensurePreventErrorBoundaryRetry(
|
|
|
53
53
|
export const shouldSuspend = (defaultedOptions: any, result: any): boolean =>
|
|
54
54
|
defaultedOptions?.suspense && result.isPending;
|
|
55
55
|
|
|
56
|
-
// A pending result that will actually fetch (not blocked by persistence restore).
|
|
57
|
-
export const willFetch = (result: any, isRestoring: boolean): boolean =>
|
|
58
|
-
result.isLoading && result.isFetching && !isRestoring;
|
|
59
|
-
|
|
60
56
|
// react-query's suspense fetch: kick the optimistic fetch and — CRUCIALLY — clear
|
|
61
57
|
// the reset boundary on error. Without the clearReset, a boundary reset→retry
|
|
62
58
|
// that fails AGAIN leaves `isReset()` true at replay, `getHasError` returns
|
package/src/isRestoring.ts
CHANGED
package/src/queries-types.ts
CHANGED
|
@@ -32,7 +32,7 @@ type MAXIMUM_DEPTH = 20;
|
|
|
32
32
|
// Widen the type of the symbol to enable type inference even if skipToken is not immutable.
|
|
33
33
|
type SkipTokenForUseQueries = symbol;
|
|
34
34
|
|
|
35
|
-
type GetUseQueryOptionsForUseQueries<T> =
|
|
35
|
+
export type GetUseQueryOptionsForUseQueries<T> =
|
|
36
36
|
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
|
|
37
37
|
T extends {
|
|
38
38
|
queryFnData: infer TQueryFnData;
|
package/src/queryOptions.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
// Verbatim port of @tanstack/react-query's queryOptions.ts — a typed identity helper
|
|
2
1
|
import type {
|
|
3
|
-
DataTag,
|
|
4
2
|
DefaultError,
|
|
5
3
|
InitialDataFunction,
|
|
6
4
|
NonUndefinedGuard,
|
|
7
5
|
OmitKeyof,
|
|
8
6
|
QueryFunction,
|
|
9
7
|
QueryKey,
|
|
8
|
+
QueryKeyWithDataTag,
|
|
10
9
|
SkipToken,
|
|
11
10
|
} from '@tanstack/query-core';
|
|
12
11
|
import type { UseQueryOptions } from './types';
|
|
@@ -52,9 +51,8 @@ export function queryOptions<
|
|
|
52
51
|
TQueryKey extends QueryKey = QueryKey,
|
|
53
52
|
>(
|
|
54
53
|
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
55
|
-
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
56
|
-
|
|
57
|
-
};
|
|
54
|
+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
55
|
+
QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
58
56
|
|
|
59
57
|
export function queryOptions<
|
|
60
58
|
TQueryFnData = unknown,
|
|
@@ -63,9 +61,8 @@ export function queryOptions<
|
|
|
63
61
|
TQueryKey extends QueryKey = QueryKey,
|
|
64
62
|
>(
|
|
65
63
|
options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
66
|
-
): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
67
|
-
|
|
68
|
-
};
|
|
64
|
+
): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
65
|
+
QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
69
66
|
|
|
70
67
|
export function queryOptions<
|
|
71
68
|
TQueryFnData = unknown,
|
|
@@ -74,9 +71,8 @@ export function queryOptions<
|
|
|
74
71
|
TQueryKey extends QueryKey = QueryKey,
|
|
75
72
|
>(
|
|
76
73
|
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
77
|
-
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
78
|
-
|
|
79
|
-
};
|
|
74
|
+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
|
|
75
|
+
QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
80
76
|
|
|
81
77
|
export function queryOptions(options: unknown) {
|
|
82
78
|
return options;
|
|
@@ -10,7 +10,7 @@ type MAXIMUM_DEPTH = 20;
|
|
|
10
10
|
// Widen the type of the symbol to enable type inference even if skipToken is not immutable.
|
|
11
11
|
type SkipTokenForUseQueries = symbol;
|
|
12
12
|
|
|
13
|
-
type GetUseSuspenseQueryOptions<T> =
|
|
13
|
+
export type GetUseSuspenseQueryOptions<T> =
|
|
14
14
|
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
|
|
15
15
|
T extends {
|
|
16
16
|
queryFnData: infer TQueryFnData;
|
package/src/types.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { OctaneNode } from 'octane';
|
|
2
|
+
import type { DehydratedState, HydrateOptions, QueryClient } from '@tanstack/query-core';
|
|
3
|
+
/* istanbul ignore file */
|
|
4
|
+
|
|
5
5
|
import type {
|
|
6
6
|
DefaultError,
|
|
7
7
|
DefinedInfiniteQueryObserverResult,
|
|
8
8
|
DefinedQueryObserverResult,
|
|
9
|
-
DehydratedState,
|
|
10
9
|
DistributiveOmit,
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
InfiniteData,
|
|
11
|
+
InfiniteQueryExecuteOptions,
|
|
13
12
|
InfiniteQueryObserverOptions,
|
|
14
13
|
InfiniteQueryObserverResult,
|
|
15
14
|
MutateFunction,
|
|
@@ -17,7 +16,7 @@ import type {
|
|
|
17
16
|
MutationObserverResult,
|
|
18
17
|
OmitKeyof,
|
|
19
18
|
Override,
|
|
20
|
-
|
|
19
|
+
QueryExecuteOptions,
|
|
21
20
|
QueryKey,
|
|
22
21
|
QueryObserverOptions,
|
|
23
22
|
QueryObserverResult,
|
|
@@ -39,17 +38,37 @@ export interface UseBaseQueryOptions<
|
|
|
39
38
|
subscribed?: boolean;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
export
|
|
41
|
+
export type UsePrefetchQueryOptions<
|
|
43
42
|
TQueryFnData = unknown,
|
|
44
43
|
TError = DefaultError,
|
|
45
44
|
TData = TQueryFnData,
|
|
45
|
+
TQueryData = TQueryFnData,
|
|
46
46
|
TQueryKey extends QueryKey = QueryKey,
|
|
47
|
-
>
|
|
47
|
+
> = DistributiveOmit<
|
|
48
|
+
QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
49
|
+
'queryFn'
|
|
50
|
+
> & {
|
|
48
51
|
queryFn?: Exclude<
|
|
49
|
-
|
|
52
|
+
QueryExecuteOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>['queryFn'],
|
|
50
53
|
SkipToken
|
|
51
54
|
>;
|
|
52
|
-
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type UsePrefetchInfiniteQueryOptions<
|
|
58
|
+
TQueryFnData = unknown,
|
|
59
|
+
TError = DefaultError,
|
|
60
|
+
TData = InfiniteData<TQueryFnData>,
|
|
61
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
62
|
+
TPageParam = unknown,
|
|
63
|
+
> = DistributiveOmit<
|
|
64
|
+
InfiniteQueryExecuteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
65
|
+
'queryFn'
|
|
66
|
+
> & {
|
|
67
|
+
queryFn?: Exclude<
|
|
68
|
+
InfiniteQueryExecuteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>['queryFn'],
|
|
69
|
+
SkipToken
|
|
70
|
+
>;
|
|
71
|
+
};
|
|
53
72
|
|
|
54
73
|
export type AnyUseQueryOptions = UseQueryOptions<any, any, any, any>;
|
|
55
74
|
export interface UseQueryOptions<
|
|
@@ -79,7 +98,7 @@ export type AnyUseInfiniteQueryOptions = UseInfiniteQueryOptions<any, any, any,
|
|
|
79
98
|
export interface UseInfiniteQueryOptions<
|
|
80
99
|
TQueryFnData = unknown,
|
|
81
100
|
TError = DefaultError,
|
|
82
|
-
TData = TQueryFnData
|
|
101
|
+
TData = InfiniteData<TQueryFnData>,
|
|
83
102
|
TQueryKey extends QueryKey = QueryKey,
|
|
84
103
|
TPageParam = unknown,
|
|
85
104
|
> extends OmitKeyof<
|
|
@@ -103,7 +122,7 @@ export type AnyUseSuspenseInfiniteQueryOptions = UseSuspenseInfiniteQueryOptions
|
|
|
103
122
|
export interface UseSuspenseInfiniteQueryOptions<
|
|
104
123
|
TQueryFnData = unknown,
|
|
105
124
|
TError = DefaultError,
|
|
106
|
-
TData = TQueryFnData
|
|
125
|
+
TData = InfiniteData<TQueryFnData>,
|
|
107
126
|
TQueryKey extends QueryKey = QueryKey,
|
|
108
127
|
TPageParam = unknown,
|
|
109
128
|
> extends OmitKeyof<
|
|
@@ -128,8 +147,7 @@ export type UseQueryResult<TData = unknown, TError = DefaultError> = UseBaseQuer
|
|
|
128
147
|
|
|
129
148
|
export type UseSuspenseQueryResult<TData = unknown, TError = DefaultError> = DistributiveOmit<
|
|
130
149
|
DefinedQueryObserverResult<TData, TError>,
|
|
131
|
-
|
|
132
|
-
Extract<'isPlaceholderData' | 'promise', keyof DefinedQueryObserverResult<TData, TError>>
|
|
150
|
+
'isPlaceholderData'
|
|
133
151
|
>;
|
|
134
152
|
|
|
135
153
|
export type DefinedUseQueryResult<
|
|
@@ -149,7 +167,7 @@ export type DefinedUseInfiniteQueryResult<
|
|
|
149
167
|
|
|
150
168
|
export type UseSuspenseInfiniteQueryResult<TData = unknown, TError = DefaultError> = OmitKeyof<
|
|
151
169
|
DefinedInfiniteQueryObserverResult<TData, TError>,
|
|
152
|
-
|
|
170
|
+
'isPlaceholderData'
|
|
153
171
|
>;
|
|
154
172
|
|
|
155
173
|
export type AnyUseMutationOptions = UseMutationOptions<any, any, any, any>;
|
|
@@ -197,14 +215,12 @@ export type UseMutationResult<
|
|
|
197
215
|
> = UseBaseMutationResult<TData, TError, TVariables, TOnMutateResult>;
|
|
198
216
|
|
|
199
217
|
// ---------------------------------------------------------------------------
|
|
200
|
-
// Component
|
|
201
|
-
// upstream's React.ReactNode becomes `unknown`; render-prop children are also
|
|
202
|
-
// accepted where upstream accepts them).
|
|
218
|
+
// Component props and context values use Octane's native renderable type.
|
|
203
219
|
// ---------------------------------------------------------------------------
|
|
204
220
|
|
|
205
221
|
export interface QueryClientProviderProps {
|
|
206
222
|
client: QueryClient;
|
|
207
|
-
children?:
|
|
223
|
+
children?: OctaneNode;
|
|
208
224
|
}
|
|
209
225
|
|
|
210
226
|
export interface HydrationBoundaryProps {
|
|
@@ -212,7 +228,7 @@ export interface HydrationBoundaryProps {
|
|
|
212
228
|
options?: OmitKeyof<HydrateOptions, 'defaultOptions'> & {
|
|
213
229
|
defaultOptions?: OmitKeyof<Exclude<HydrateOptions['defaultOptions'], undefined>, 'mutations'>;
|
|
214
230
|
};
|
|
215
|
-
children?:
|
|
231
|
+
children?: OctaneNode;
|
|
216
232
|
queryClient?: QueryClient;
|
|
217
233
|
}
|
|
218
234
|
|
|
@@ -226,8 +242,8 @@ export interface QueryErrorResetBoundaryValue {
|
|
|
226
242
|
reset: QueryErrorResetFunction;
|
|
227
243
|
}
|
|
228
244
|
|
|
229
|
-
export type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) =>
|
|
245
|
+
export type QueryErrorResetBoundaryFunction = (value: QueryErrorResetBoundaryValue) => OctaneNode;
|
|
230
246
|
|
|
231
247
|
export interface QueryErrorResetBoundaryProps {
|
|
232
|
-
children: QueryErrorResetBoundaryFunction |
|
|
248
|
+
children: QueryErrorResetBoundaryFunction | OctaneNode;
|
|
233
249
|
}
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Bundlers replace this expression; no Node ambient types are required.
|
|
2
|
+
declare const process: { env: { NODE_ENV?: string } };
|
|
1
3
|
// `useBaseQuery` — the shared core of `useQuery` (and friends), reimplemented on
|
|
2
4
|
// octane's hooks. Mirrors @tanstack/react-query's useBaseQuery: it creates a
|
|
3
5
|
// query Observer, subscribes to it via useSyncExternalStore, and pushes option
|
|
@@ -5,7 +7,7 @@
|
|
|
5
7
|
// distinct sub-slots for each internal base hook, the same way the zustand
|
|
6
8
|
// `traditional` binding does.
|
|
7
9
|
import { useState, useCallback, useSyncExternalStore, useEffect } from 'octane';
|
|
8
|
-
import {
|
|
10
|
+
import { noop, notifyManager } from '@tanstack/query-core';
|
|
9
11
|
import { resolveClient } from './context';
|
|
10
12
|
import { useIsRestoring } from './isRestoring';
|
|
11
13
|
import { useQueryErrorResetBoundary } from './errorResetBoundary';
|
|
@@ -17,7 +19,6 @@ import {
|
|
|
17
19
|
shouldSuspend,
|
|
18
20
|
subSlot,
|
|
19
21
|
useSuspensePromise,
|
|
20
|
-
willFetch,
|
|
21
22
|
} from './internal';
|
|
22
23
|
|
|
23
24
|
export function useBaseQuery(
|
|
@@ -40,8 +41,6 @@ export function useBaseQuery(
|
|
|
40
41
|
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
41
42
|
const defaultedOptions = client.defaultQueryOptions(options);
|
|
42
43
|
|
|
43
|
-
(client.getDefaultOptions().queries as any)?._experimental_beforeQuery?.(defaultedOptions);
|
|
44
|
-
|
|
45
44
|
const query = client.getQueryCache().get(defaultedOptions.queryHash);
|
|
46
45
|
|
|
47
46
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -72,9 +71,6 @@ export function useBaseQuery(
|
|
|
72
71
|
oq('clr'),
|
|
73
72
|
);
|
|
74
73
|
|
|
75
|
-
// Probed BEFORE creating the Observer — the constructor can create the entry.
|
|
76
|
-
const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);
|
|
77
|
-
|
|
78
74
|
const [observer] = useState(() => new Observer(client, defaultedOptions), oq('obs'));
|
|
79
75
|
|
|
80
76
|
const result = observer.getOptimisticResult(defaultedOptions);
|
|
@@ -131,27 +127,5 @@ export function useBaseQuery(
|
|
|
131
127
|
throw result.error;
|
|
132
128
|
}
|
|
133
129
|
|
|
134
|
-
(client.getDefaultOptions().queries as any)?._experimental_afterQuery?.(defaultedOptions, result);
|
|
135
|
-
|
|
136
|
-
// Query core before 5.102 supports experimental_prefetchInRender. Start the
|
|
137
|
-
// fetch during render so `result.promise` settles even if the component
|
|
138
|
-
// unmounts, then finalize the observer's thenable when the data lands.
|
|
139
|
-
if (
|
|
140
|
-
'experimental_prefetchInRender' in defaultedOptions &&
|
|
141
|
-
defaultedOptions.experimental_prefetchInRender &&
|
|
142
|
-
!environmentManager.isServer() &&
|
|
143
|
-
willFetch(result, isRestoring)
|
|
144
|
-
) {
|
|
145
|
-
const promise = isNewCacheEntry
|
|
146
|
-
? // Fetch immediately on render so `.promise` resolves even on unmount.
|
|
147
|
-
fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
|
|
148
|
-
: // Subscribe to the cache promise to finalize the current thenable.
|
|
149
|
-
query?.promise;
|
|
150
|
-
|
|
151
|
-
promise?.catch(noop).finally(() => {
|
|
152
|
-
observer.updateResult();
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
130
|
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
157
131
|
}
|
package/src/useMutationState.ts
CHANGED
|
@@ -4,10 +4,18 @@ import { useSyncExternalStore, useCallback, useRef, useEffect } from 'octane';
|
|
|
4
4
|
import { resolveClient } from './context';
|
|
5
5
|
import { splitSlot, subSlot } from './internal';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type MutationTypeFromResult<TResult> = [TResult] extends [
|
|
8
|
+
MutationState<infer TData, infer TError, infer TVariables, infer TOnMutateResult>,
|
|
9
|
+
]
|
|
10
|
+
? Mutation<TData, TError, TVariables, TOnMutateResult>
|
|
11
|
+
: Mutation;
|
|
12
|
+
|
|
13
|
+
type MutationStateOptions<
|
|
14
|
+
TResult = MutationState,
|
|
15
|
+
TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>,
|
|
16
|
+
> = {
|
|
9
17
|
filters?: MutationFilters;
|
|
10
|
-
select?: (mutation:
|
|
18
|
+
select?: (mutation: TMutation) => TResult;
|
|
11
19
|
};
|
|
12
20
|
|
|
13
21
|
function getResult(mutationCache: any, options: any): any[] {
|
|
@@ -17,10 +25,10 @@ function getResult(mutationCache: any, options: any): any[] {
|
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
// Signatures match @tanstack/react-query's useMutationState.ts.
|
|
20
|
-
export function useMutationState<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
): Array<TResult>;
|
|
28
|
+
export function useMutationState<
|
|
29
|
+
TResult = MutationState,
|
|
30
|
+
TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>,
|
|
31
|
+
>(options?: MutationStateOptions<TResult, TMutation>, queryClient?: QueryClient): Array<TResult>;
|
|
24
32
|
|
|
25
33
|
export function useMutationState(...args: any[]): any[] {
|
|
26
34
|
const [user, slot] = splitSlot(args);
|
package/src/usePrefetch.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
FetchInfiniteQueryOptions,
|
|
4
|
-
QueryClient,
|
|
5
|
-
QueryKey,
|
|
6
|
-
} from '@tanstack/query-core';
|
|
1
|
+
import type { DefaultError, InfiniteData, QueryClient, QueryKey } from '@tanstack/query-core';
|
|
2
|
+
import { noop } from '@tanstack/query-core';
|
|
7
3
|
import { resolveClient } from './context';
|
|
8
4
|
import { splitSlot } from './internal';
|
|
9
|
-
import type { UsePrefetchQueryOptions } from './types';
|
|
5
|
+
import type { UsePrefetchQueryOptions, UsePrefetchInfiniteQueryOptions } from './types';
|
|
10
6
|
|
|
11
7
|
// Signatures match @tanstack/react-query's usePrefetchQuery.tsx /
|
|
12
8
|
// usePrefetchInfiniteQuery.tsx.
|
|
@@ -14,9 +10,10 @@ export function usePrefetchQuery<
|
|
|
14
10
|
TQueryFnData = unknown,
|
|
15
11
|
TError = DefaultError,
|
|
16
12
|
TData = TQueryFnData,
|
|
13
|
+
TQueryData = TQueryFnData,
|
|
17
14
|
TQueryKey extends QueryKey = QueryKey,
|
|
18
15
|
>(
|
|
19
|
-
options: UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
16
|
+
options: UsePrefetchQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>,
|
|
20
17
|
queryClient?: QueryClient,
|
|
21
18
|
): void;
|
|
22
19
|
|
|
@@ -24,18 +21,18 @@ export function usePrefetchQuery(options: any, ...rest: any[]): void {
|
|
|
24
21
|
const [user] = splitSlot(rest);
|
|
25
22
|
const client = resolveClient(user[0]);
|
|
26
23
|
if (!client.getQueryState(options.queryKey)) {
|
|
27
|
-
client.
|
|
24
|
+
void client.query(options).catch(noop);
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
export function usePrefetchInfiniteQuery<
|
|
32
29
|
TQueryFnData = unknown,
|
|
33
30
|
TError = DefaultError,
|
|
34
|
-
TData = TQueryFnData
|
|
31
|
+
TData = InfiniteData<TQueryFnData>,
|
|
35
32
|
TQueryKey extends QueryKey = QueryKey,
|
|
36
33
|
TPageParam = unknown,
|
|
37
34
|
>(
|
|
38
|
-
options:
|
|
35
|
+
options: UsePrefetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
39
36
|
queryClient?: QueryClient,
|
|
40
37
|
): void;
|
|
41
38
|
|
|
@@ -43,6 +40,6 @@ export function usePrefetchInfiniteQuery(options: any, ...rest: any[]): void {
|
|
|
43
40
|
const [user] = splitSlot(rest);
|
|
44
41
|
const client = resolveClient(user[0]);
|
|
45
42
|
if (!client.getQueryState(options.queryKey)) {
|
|
46
|
-
client.
|
|
43
|
+
void client.infiniteQuery(options).catch(noop);
|
|
47
44
|
}
|
|
48
45
|
}
|
package/src/useQueries.ts
CHANGED
|
@@ -14,7 +14,11 @@ import {
|
|
|
14
14
|
subSlot,
|
|
15
15
|
useSuspensePromise,
|
|
16
16
|
} from './internal';
|
|
17
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
QueriesOptions,
|
|
19
|
+
QueriesResults,
|
|
20
|
+
GetUseQueryOptionsForUseQueries,
|
|
21
|
+
} from './queries-types';
|
|
18
22
|
|
|
19
23
|
// Signature matches @tanstack/react-query's useQueries.ts — per-entry tuple
|
|
20
24
|
// inference via QueriesOptions/QueriesResults, with `combine` re-typing the
|
|
@@ -22,7 +26,9 @@ import type { QueriesOptions, QueriesResults } from './queries-types';
|
|
|
22
26
|
// compiler-injected trailing slot symbol.
|
|
23
27
|
export function useQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>(
|
|
24
28
|
options: {
|
|
25
|
-
queries:
|
|
29
|
+
queries:
|
|
30
|
+
| readonly [...QueriesOptions<T>]
|
|
31
|
+
| readonly [...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }];
|
|
26
32
|
combine?: (result: QueriesResults<T>) => TCombinedResult;
|
|
27
33
|
subscribed?: boolean;
|
|
28
34
|
},
|
|
@@ -35,16 +41,21 @@ export function useQueries(options: any, ...rest: any[]): any {
|
|
|
35
41
|
const isRestoring = useIsRestoring();
|
|
36
42
|
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
37
43
|
const { queries, ...restOptions } = options;
|
|
44
|
+
const subscribed = options.subscribed !== false;
|
|
38
45
|
const qs = (tag: string) => subSlot(slot, 'qs:' + tag);
|
|
39
46
|
|
|
40
47
|
const defaultedQueries = useMemo(
|
|
41
48
|
() =>
|
|
42
49
|
queries.map((opts: any) => {
|
|
43
50
|
const defaulted = client.defaultQueryOptions(opts);
|
|
44
|
-
defaulted._optimisticResults = isRestoring
|
|
51
|
+
defaulted._optimisticResults = isRestoring
|
|
52
|
+
? 'isRestoring'
|
|
53
|
+
: subscribed
|
|
54
|
+
? 'optimistic'
|
|
55
|
+
: undefined;
|
|
45
56
|
return defaulted;
|
|
46
57
|
}),
|
|
47
|
-
[queries, client, isRestoring],
|
|
58
|
+
[queries, client, isRestoring, subscribed],
|
|
48
59
|
qs('memo'),
|
|
49
60
|
);
|
|
50
61
|
defaultedQueries.forEach((queryOptions: any) => {
|
|
@@ -73,7 +84,7 @@ export function useQueries(options: any, ...rest: any[]): any {
|
|
|
73
84
|
restOptions.combine,
|
|
74
85
|
);
|
|
75
86
|
|
|
76
|
-
const shouldSubscribe = !isRestoring &&
|
|
87
|
+
const shouldSubscribe = !isRestoring && subscribed;
|
|
77
88
|
useSyncExternalStore(
|
|
78
89
|
useCallback(
|
|
79
90
|
(onStoreChange: () => void) =>
|
|
@@ -131,7 +142,7 @@ export function useQueries(options: any, ...rest: any[]): any {
|
|
|
131
142
|
})
|
|
132
143
|
);
|
|
133
144
|
});
|
|
134
|
-
if (firstError
|
|
145
|
+
if (firstError) {
|
|
135
146
|
throw firstError.error;
|
|
136
147
|
}
|
|
137
148
|
|
package/src/useQuery.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function useQuery<
|
|
|
15
15
|
>(
|
|
16
16
|
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
17
17
|
queryClient?: QueryClient,
|
|
18
|
-
): DefinedUseQueryResult<
|
|
18
|
+
): DefinedUseQueryResult<TData, TError>;
|
|
19
19
|
|
|
20
20
|
export function useQuery<
|
|
21
21
|
TQueryFnData = unknown,
|
|
@@ -25,7 +25,7 @@ export function useQuery<
|
|
|
25
25
|
>(
|
|
26
26
|
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
27
27
|
queryClient?: QueryClient,
|
|
28
|
-
): UseQueryResult<
|
|
28
|
+
): UseQueryResult<TData, TError>;
|
|
29
29
|
|
|
30
30
|
export function useQuery<
|
|
31
31
|
TQueryFnData = unknown,
|
|
@@ -35,7 +35,7 @@ export function useQuery<
|
|
|
35
35
|
>(
|
|
36
36
|
options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
37
37
|
queryClient?: QueryClient,
|
|
38
|
-
): UseQueryResult<
|
|
38
|
+
): UseQueryResult<TData, TError>;
|
|
39
39
|
|
|
40
40
|
export function useQuery(options: any, ...rest: any[]): any {
|
|
41
41
|
// `[queryClient?, slot?]` — the slot (symbol) is the compiler-injected trailing
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
// Bundlers replace this expression; no Node ambient types are required.
|
|
2
|
+
declare const process: { env: { NODE_ENV?: string } };
|
|
1
3
|
import { skipToken } from '@tanstack/query-core';
|
|
2
4
|
import type { QueryClient } from '@tanstack/query-core';
|
|
3
5
|
import { defaultThrowOnError } from './internal';
|
|
4
6
|
import { useQueries } from './useQueries';
|
|
5
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
SuspenseQueriesOptions,
|
|
9
|
+
SuspenseQueriesResults,
|
|
10
|
+
GetUseSuspenseQueryOptions,
|
|
11
|
+
} from './suspense-queries-types';
|
|
6
12
|
|
|
7
13
|
// Signature matches @tanstack/react-query's useSuspenseQueries.ts.
|
|
14
|
+
export function useSuspenseQueries<
|
|
15
|
+
T extends Array<any>,
|
|
16
|
+
TCombinedResult = SuspenseQueriesResults<T>,
|
|
17
|
+
>(
|
|
18
|
+
options: {
|
|
19
|
+
queries:
|
|
20
|
+
| readonly [...SuspenseQueriesOptions<T>]
|
|
21
|
+
| readonly [...{ [K in keyof T]: GetUseSuspenseQueryOptions<T[K]> }];
|
|
22
|
+
combine?: (result: SuspenseQueriesResults<T>) => TCombinedResult;
|
|
23
|
+
},
|
|
24
|
+
queryClient?: QueryClient,
|
|
25
|
+
): TCombinedResult;
|
|
26
|
+
|
|
8
27
|
export function useSuspenseQueries<
|
|
9
28
|
T extends Array<any>,
|
|
10
29
|
TCombinedResult = SuspenseQueriesResults<T>,
|
package/src/useSuspenseQuery.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Bundlers replace this expression; no Node ambient types are required.
|
|
2
|
+
declare const process: { env: { NODE_ENV?: string } };
|
|
1
3
|
import { InfiniteQueryObserver, QueryObserver, skipToken } from '@tanstack/query-core';
|
|
2
4
|
import type { DefaultError, InfiniteData, QueryClient, QueryKey } from '@tanstack/query-core';
|
|
3
5
|
import { useBaseQuery } from './useBaseQuery';
|
|
@@ -63,7 +65,13 @@ export function useSuspenseInfiniteQuery(options: any, ...rest: any[]): any {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
return useBaseQuery(
|
|
66
|
-
{
|
|
68
|
+
{
|
|
69
|
+
...options,
|
|
70
|
+
enabled: true,
|
|
71
|
+
suspense: true,
|
|
72
|
+
throwOnError: defaultThrowOnError,
|
|
73
|
+
placeholderData: undefined,
|
|
74
|
+
},
|
|
67
75
|
InfiniteQueryObserver,
|
|
68
76
|
user[0],
|
|
69
77
|
slot,
|