@trpc/tanstack-react-query 0.0.0-alpha.3 → 10.8.0-alpha-tmp-02-12-response-types-idea.853
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/README.md +12 -11
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internals/Context.d.ts +15 -8
- package/dist/internals/Context.d.ts.map +1 -1
- package/dist/internals/Context.js +19 -4
- package/dist/internals/Context.mjs +19 -4
- package/dist/internals/createOptionsProxy.d.ts +105 -41
- package/dist/internals/createOptionsProxy.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.js +43 -32
- package/dist/internals/createOptionsProxy.mjs +45 -34
- package/dist/internals/infiniteQueryOptions.d.ts +37 -28
- package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
- package/dist/internals/infiniteQueryOptions.js +3 -3
- package/dist/internals/infiniteQueryOptions.mjs +4 -4
- package/dist/internals/mutationOptions.d.ts +8 -3
- package/dist/internals/mutationOptions.d.ts.map +1 -1
- package/dist/internals/mutationOptions.js +3 -1
- package/dist/internals/mutationOptions.mjs +3 -1
- package/dist/internals/queryOptions.d.ts +9 -15
- package/dist/internals/queryOptions.d.ts.map +1 -1
- package/dist/internals/queryOptions.js +5 -3
- package/dist/internals/queryOptions.mjs +6 -4
- package/dist/internals/subscriptionOptions.d.ts +13 -17
- package/dist/internals/subscriptionOptions.d.ts.map +1 -1
- package/dist/internals/subscriptionOptions.js +44 -38
- package/dist/internals/subscriptionOptions.mjs +44 -38
- package/dist/internals/types.d.ts +44 -2
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/internals/utils.d.ts +10 -2
- package/dist/internals/utils.d.ts.map +1 -1
- package/dist/internals/utils.js +10 -4
- package/dist/internals/utils.mjs +10 -4
- package/package.json +30 -27
- package/src/index.ts +4 -3
- package/src/internals/Context.tsx +41 -12
- package/src/internals/createOptionsProxy.ts +250 -117
- package/src/internals/infiniteQueryOptions.ts +53 -27
- package/src/internals/mutationOptions.ts +23 -6
- package/src/internals/queryOptions.ts +20 -5
- package/src/internals/subscriptionOptions.ts +62 -46
- package/src/internals/types.ts +48 -1
- package/src/internals/utils.ts +15 -4
|
@@ -23,10 +23,12 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
|
|
24
24
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/ const trpcSubscriptionOptions = (args)=>{
|
|
27
29
|
const { subscribe, path, queryKey, opts } = args;
|
|
28
30
|
const input = queryKey[1]?.input;
|
|
29
|
-
const enabled = opts
|
|
31
|
+
const enabled = 'enabled' in opts ? !!opts.enabled : input !== reactQuery.skipToken;
|
|
30
32
|
const _subscribe = (innerOpts)=>{
|
|
31
33
|
return subscribe(path.join('.'), input ?? undefined, innerOpts);
|
|
32
34
|
};
|
|
@@ -47,7 +49,9 @@ function useSubscription(opts) {
|
|
|
47
49
|
const addTrackedProp = React__namespace.useCallback((key)=>{
|
|
48
50
|
trackedProps.current.add(key);
|
|
49
51
|
}, []);
|
|
50
|
-
const currentSubscriptionRef = React__namespace.useRef()
|
|
52
|
+
const currentSubscriptionRef = React__namespace.useRef(()=>{
|
|
53
|
+
// noop
|
|
54
|
+
});
|
|
51
55
|
const reset = React__namespace.useCallback(()=>{
|
|
52
56
|
// unsubscribe from the previous subscription
|
|
53
57
|
currentSubscriptionRef.current?.();
|
|
@@ -55,54 +59,56 @@ function useSubscription(opts) {
|
|
|
55
59
|
if (!opts.enabled) {
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
|
-
let isStopped = false;
|
|
59
62
|
const subscription = opts.subscribe({
|
|
60
63
|
onStarted: ()=>{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
64
|
+
optsRef.current.onStarted?.();
|
|
65
|
+
updateState((prev)=>({
|
|
66
|
+
...prev,
|
|
67
|
+
status: 'pending',
|
|
68
|
+
error: null
|
|
69
|
+
}));
|
|
69
70
|
},
|
|
70
71
|
onData: (data)=>{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
72
|
+
optsRef.current.onData?.(data);
|
|
73
|
+
updateState((prev)=>({
|
|
74
|
+
...prev,
|
|
75
|
+
status: 'pending',
|
|
76
|
+
data,
|
|
77
|
+
error: null
|
|
78
|
+
}));
|
|
80
79
|
},
|
|
81
80
|
onError: (error)=>{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
81
|
+
optsRef.current.onError?.(error);
|
|
82
|
+
updateState((prev)=>({
|
|
83
|
+
...prev,
|
|
84
|
+
status: 'error',
|
|
85
|
+
error
|
|
86
|
+
}));
|
|
90
87
|
},
|
|
91
88
|
onConnectionStateChange: (result)=>{
|
|
92
|
-
const delta = {
|
|
93
|
-
status: result.state,
|
|
94
|
-
error: result.error
|
|
95
|
-
};
|
|
96
89
|
updateState((prev)=>{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
switch(result.state){
|
|
91
|
+
case 'connecting':
|
|
92
|
+
return {
|
|
93
|
+
...prev,
|
|
94
|
+
status: 'connecting',
|
|
95
|
+
error: result.error
|
|
96
|
+
};
|
|
97
|
+
case 'pending':
|
|
98
|
+
// handled in onStarted
|
|
99
|
+
return prev;
|
|
100
|
+
case 'idle':
|
|
101
|
+
return {
|
|
102
|
+
...prev,
|
|
103
|
+
status: 'idle',
|
|
104
|
+
data: undefined,
|
|
105
|
+
error: null
|
|
106
|
+
};
|
|
107
|
+
}
|
|
101
108
|
});
|
|
102
109
|
}
|
|
103
110
|
});
|
|
104
111
|
currentSubscriptionRef.current = ()=>{
|
|
105
|
-
isStopped = true;
|
|
106
112
|
subscription.unsubscribe();
|
|
107
113
|
};
|
|
108
114
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -2,10 +2,12 @@ import { hashKey, skipToken } from '@tanstack/react-query';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { createTRPCOptionsResult } from './utils.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/ const trpcSubscriptionOptions = (args)=>{
|
|
6
8
|
const { subscribe, path, queryKey, opts } = args;
|
|
7
9
|
const input = queryKey[1]?.input;
|
|
8
|
-
const enabled = opts
|
|
10
|
+
const enabled = 'enabled' in opts ? !!opts.enabled : input !== skipToken;
|
|
9
11
|
const _subscribe = (innerOpts)=>{
|
|
10
12
|
return subscribe(path.join('.'), input ?? undefined, innerOpts);
|
|
11
13
|
};
|
|
@@ -26,7 +28,9 @@ function useSubscription(opts) {
|
|
|
26
28
|
const addTrackedProp = React.useCallback((key)=>{
|
|
27
29
|
trackedProps.current.add(key);
|
|
28
30
|
}, []);
|
|
29
|
-
const currentSubscriptionRef = React.useRef()
|
|
31
|
+
const currentSubscriptionRef = React.useRef(()=>{
|
|
32
|
+
// noop
|
|
33
|
+
});
|
|
30
34
|
const reset = React.useCallback(()=>{
|
|
31
35
|
// unsubscribe from the previous subscription
|
|
32
36
|
currentSubscriptionRef.current?.();
|
|
@@ -34,54 +38,56 @@ function useSubscription(opts) {
|
|
|
34
38
|
if (!opts.enabled) {
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
|
-
let isStopped = false;
|
|
38
41
|
const subscription = opts.subscribe({
|
|
39
42
|
onStarted: ()=>{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
43
|
+
optsRef.current.onStarted?.();
|
|
44
|
+
updateState((prev)=>({
|
|
45
|
+
...prev,
|
|
46
|
+
status: 'pending',
|
|
47
|
+
error: null
|
|
48
|
+
}));
|
|
48
49
|
},
|
|
49
50
|
onData: (data)=>{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
51
|
+
optsRef.current.onData?.(data);
|
|
52
|
+
updateState((prev)=>({
|
|
53
|
+
...prev,
|
|
54
|
+
status: 'pending',
|
|
55
|
+
data,
|
|
56
|
+
error: null
|
|
57
|
+
}));
|
|
59
58
|
},
|
|
60
59
|
onError: (error)=>{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
60
|
+
optsRef.current.onError?.(error);
|
|
61
|
+
updateState((prev)=>({
|
|
62
|
+
...prev,
|
|
63
|
+
status: 'error',
|
|
64
|
+
error
|
|
65
|
+
}));
|
|
69
66
|
},
|
|
70
67
|
onConnectionStateChange: (result)=>{
|
|
71
|
-
const delta = {
|
|
72
|
-
status: result.state,
|
|
73
|
-
error: result.error
|
|
74
|
-
};
|
|
75
68
|
updateState((prev)=>{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
switch(result.state){
|
|
70
|
+
case 'connecting':
|
|
71
|
+
return {
|
|
72
|
+
...prev,
|
|
73
|
+
status: 'connecting',
|
|
74
|
+
error: result.error
|
|
75
|
+
};
|
|
76
|
+
case 'pending':
|
|
77
|
+
// handled in onStarted
|
|
78
|
+
return prev;
|
|
79
|
+
case 'idle':
|
|
80
|
+
return {
|
|
81
|
+
...prev,
|
|
82
|
+
status: 'idle',
|
|
83
|
+
data: undefined,
|
|
84
|
+
error: null
|
|
85
|
+
};
|
|
86
|
+
}
|
|
80
87
|
});
|
|
81
88
|
}
|
|
82
89
|
});
|
|
83
90
|
currentSubscriptionRef.current = ()=>{
|
|
84
|
-
isStopped = true;
|
|
85
91
|
subscription.unsubscribe();
|
|
86
92
|
};
|
|
87
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1,13 +1,39 @@
|
|
|
1
|
+
import type { InfiniteData } from '@tanstack/react-query';
|
|
1
2
|
import type { TRPCRequestOptions } from '@trpc/client';
|
|
3
|
+
/**
|
|
4
|
+
* Turn a set of optional properties into required
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type WithRequired<TObj, TKey extends keyof TObj> = TObj & {
|
|
8
|
+
[P in TKey]-?: TObj[P];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
2
13
|
export type ResolverDef = {
|
|
3
14
|
input: any;
|
|
4
15
|
output: any;
|
|
5
16
|
transformer: boolean;
|
|
6
17
|
errorShape: any;
|
|
7
18
|
};
|
|
8
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
21
|
+
*/
|
|
22
|
+
type CursorInput = {
|
|
9
23
|
cursor?: any;
|
|
10
|
-
}
|
|
24
|
+
};
|
|
25
|
+
export type OptionalCursorInput = CursorInput | void;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
11
37
|
export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
|
|
12
38
|
/**
|
|
13
39
|
* Opt out of SSR for this query by passing `ssr: false`
|
|
@@ -18,18 +44,30 @@ export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signa
|
|
|
18
44
|
*/
|
|
19
45
|
abortOnUnmount?: boolean;
|
|
20
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
21
50
|
export interface TRPCQueryBaseOptions {
|
|
22
51
|
/**
|
|
23
52
|
* tRPC-related options
|
|
24
53
|
*/
|
|
25
54
|
trpc?: TRPCReactRequestOptions;
|
|
26
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
27
59
|
export interface TRPCQueryOptionsResult {
|
|
28
60
|
trpc: {
|
|
29
61
|
path: string;
|
|
30
62
|
};
|
|
31
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
32
67
|
export type QueryType = 'any' | 'infinite' | 'query';
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
33
71
|
export type TRPCQueryKey = [
|
|
34
72
|
readonly string[],
|
|
35
73
|
{
|
|
@@ -37,5 +75,9 @@ export type TRPCQueryKey = [
|
|
|
37
75
|
type?: Exclude<QueryType, 'any'>;
|
|
38
76
|
}?
|
|
39
77
|
];
|
|
78
|
+
/**
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
40
81
|
export type TRPCMutationKey = [readonly string[]];
|
|
82
|
+
export {};
|
|
41
83
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,M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;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,MAAM,EAAE;IACjB;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC"}
|
|
@@ -21,8 +21,16 @@ export declare function buildQueryFromAsyncIterable(asyncIterable: AsyncIterable
|
|
|
21
21
|
* To allow easy interactions with groups of related queries, such as
|
|
22
22
|
* invalidating all queries of a router, we use an array as the path when
|
|
23
23
|
* storing in tanstack query.
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function getQueryKeyInternal(path: readonly string[], input?: unknown, type?: QueryType): TRPCQueryKey;
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
26
31
|
export declare function getMutationKeyInternal(path: readonly string[]): TRPCMutationKey;
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
27
35
|
export declare function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T;
|
|
28
36
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK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CAAC,EAAE,SAAS,GACf,YAAY,CA2Cd;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,eAAe,CAKjB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAE9D"}
|
package/dist/internals/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
19
19
|
if (infiniteParams) {
|
|
20
20
|
input = {
|
|
21
21
|
...input ?? {},
|
|
22
|
-
...infiniteParams.pageParam ? {
|
|
22
|
+
...infiniteParams.pageParam !== undefined ? {
|
|
23
23
|
cursor: infiniteParams.pageParam
|
|
24
24
|
} : {},
|
|
25
25
|
direction: infiniteParams.direction
|
|
@@ -57,7 +57,9 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
57
57
|
* To allow easy interactions with groups of related queries, such as
|
|
58
58
|
* invalidating all queries of a router, we use an array as the path when
|
|
59
59
|
* storing in tanstack query.
|
|
60
|
-
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/ function getQueryKeyInternal(path, input, type) {
|
|
61
63
|
// Construct a query key that is easy to destructure and flexible for
|
|
62
64
|
// partial selecting etc.
|
|
63
65
|
// https://github.com/trpc/trpc/issues/3128
|
|
@@ -93,14 +95,18 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
93
95
|
}
|
|
94
96
|
];
|
|
95
97
|
}
|
|
96
|
-
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/ function getMutationKeyInternal(path) {
|
|
97
101
|
// some parts of the path may be dot-separated, split them up
|
|
98
102
|
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
99
103
|
return splitPath.length ? [
|
|
100
104
|
splitPath
|
|
101
105
|
] : [];
|
|
102
106
|
}
|
|
103
|
-
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
*/ function unwrapLazyArg(valueOrLazy) {
|
|
104
110
|
return unstableCoreDoNotImport.isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
105
111
|
}
|
|
106
112
|
|
package/dist/internals/utils.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
|
|
|
17
17
|
if (infiniteParams) {
|
|
18
18
|
input = {
|
|
19
19
|
...input ?? {},
|
|
20
|
-
...infiniteParams.pageParam ? {
|
|
20
|
+
...infiniteParams.pageParam !== undefined ? {
|
|
21
21
|
cursor: infiniteParams.pageParam
|
|
22
22
|
} : {},
|
|
23
23
|
direction: infiniteParams.direction
|
|
@@ -55,7 +55,9 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
|
|
|
55
55
|
* To allow easy interactions with groups of related queries, such as
|
|
56
56
|
* invalidating all queries of a router, we use an array as the path when
|
|
57
57
|
* storing in tanstack query.
|
|
58
|
-
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/ function getQueryKeyInternal(path, input, type) {
|
|
59
61
|
// Construct a query key that is easy to destructure and flexible for
|
|
60
62
|
// partial selecting etc.
|
|
61
63
|
// https://github.com/trpc/trpc/issues/3128
|
|
@@ -91,14 +93,18 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
|
|
|
91
93
|
}
|
|
92
94
|
];
|
|
93
95
|
}
|
|
94
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @internal
|
|
98
|
+
*/ function getMutationKeyInternal(path) {
|
|
95
99
|
// some parts of the path may be dot-separated, split them up
|
|
96
100
|
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
97
101
|
return splitPath.length ? [
|
|
98
102
|
splitPath
|
|
99
103
|
] : [];
|
|
100
104
|
}
|
|
101
|
-
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
*/ function unwrapLazyArg(valueOrLazy) {
|
|
102
108
|
return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
|
|
103
109
|
}
|
|
104
110
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/tanstack-react-query",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
|
|
4
|
+
"description": "TanStack React Query Integration for tRPC",
|
|
5
5
|
"author": "juliusmarminge",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.mjs",
|
|
9
9
|
"typings": "dist/index.d.ts",
|
|
10
|
-
"homepage": "https://trpc.io",
|
|
10
|
+
"homepage": "https://trpc.io/docs/client/tanstack-react-query/setup",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
14
14
|
"directory": "packages/tanstack-react-query"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
18
|
+
"dev": "pnpm build --watch",
|
|
19
|
+
"codegen-entrypoints": "tsx entrypoints.script.ts",
|
|
20
|
+
"lint": "eslint --cache src",
|
|
21
|
+
"test-run:tsc": "tsc --noEmit --pretty",
|
|
22
|
+
"ts-watch": "tsc --watch"
|
|
23
|
+
},
|
|
16
24
|
"exports": {
|
|
17
25
|
"./package.json": "./package.json",
|
|
18
26
|
".": {
|
|
@@ -40,28 +48,30 @@
|
|
|
40
48
|
}
|
|
41
49
|
},
|
|
42
50
|
"peerDependencies": {
|
|
43
|
-
"@tanstack/react-query": "^5.
|
|
44
|
-
"@trpc/client": "10.
|
|
45
|
-
"@trpc/server": "
|
|
51
|
+
"@tanstack/react-query": "^5.67.1",
|
|
52
|
+
"@trpc/client": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
|
|
53
|
+
"@trpc/server": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
|
|
46
54
|
"react": ">=18.2.0",
|
|
47
55
|
"react-dom": ">=18.2.0",
|
|
48
56
|
"typescript": ">=5.7.2"
|
|
49
57
|
},
|
|
50
58
|
"devDependencies": {
|
|
51
|
-
"@tanstack/react-query": "^5.
|
|
52
|
-
"@trpc/client": "10.
|
|
53
|
-
"@trpc/server": "
|
|
54
|
-
"@types/node": "^
|
|
55
|
-
"@types/react": "^
|
|
56
|
-
"eslint": "^
|
|
59
|
+
"@tanstack/react-query": "^5.67.1",
|
|
60
|
+
"@trpc/client": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
|
|
61
|
+
"@trpc/server": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
|
|
62
|
+
"@types/node": "^22.13.5",
|
|
63
|
+
"@types/react": "^19.0.0",
|
|
64
|
+
"eslint": "^9.21.0",
|
|
65
|
+
"event-source-polyfill": "^1.0.31",
|
|
57
66
|
"konn": "^0.7.0",
|
|
58
67
|
"react": "^19.0.0",
|
|
59
|
-
"react-dom": "^
|
|
60
|
-
"rollup": "^4.
|
|
61
|
-
"tsx": "^4.
|
|
62
|
-
"typescript": "^5.
|
|
63
|
-
"vitest": "^
|
|
64
|
-
"
|
|
68
|
+
"react-dom": "^19.0.0",
|
|
69
|
+
"rollup": "^4.34.8",
|
|
70
|
+
"tsx": "^4.19.3",
|
|
71
|
+
"typescript": "^5.8.2",
|
|
72
|
+
"vitest": "^3.0.6",
|
|
73
|
+
"ws": "^8.0.0",
|
|
74
|
+
"zod": "^3.24.2"
|
|
65
75
|
},
|
|
66
76
|
"publishConfig": {
|
|
67
77
|
"access": "public"
|
|
@@ -69,12 +79,5 @@
|
|
|
69
79
|
"funding": [
|
|
70
80
|
"https://trpc.io/sponsor"
|
|
71
81
|
],
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
"dev": "pnpm build --watch",
|
|
75
|
-
"codegen-entrypoints": "tsx entrypoints.script.ts",
|
|
76
|
-
"lint": "eslint --cache src",
|
|
77
|
-
"test-run:tsc": "tsc --noEmit --pretty",
|
|
78
|
-
"ts-watch": "tsc --watch"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
82
|
+
"gitHead": "be416f215b4b891c4f6382535345ec397a02ae03"
|
|
83
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { createTRPCContext } from './internals/Context';
|
|
2
2
|
export type {
|
|
3
3
|
TRPCOptionsProxy,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
inferInput,
|
|
5
|
+
inferOutput,
|
|
6
6
|
DecorateMutationProcedure,
|
|
7
7
|
DecorateProcedure,
|
|
8
|
-
|
|
8
|
+
DecorateRouterKeyable,
|
|
9
9
|
DecorateQueryProcedure,
|
|
10
10
|
DecorateSubscriptionProcedure,
|
|
11
11
|
} from './internals/createOptionsProxy';
|
|
@@ -23,3 +23,4 @@ export type {
|
|
|
23
23
|
} from './internals/subscriptionOptions';
|
|
24
24
|
export { createTRPCOptionsProxy } from './internals/createOptionsProxy';
|
|
25
25
|
export { useSubscription } from './internals/subscriptionOptions';
|
|
26
|
+
export type * from './internals/types';
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { TRPCClient } from '@trpc/client';
|
|
3
3
|
import type { AnyTRPCRouter } from '@trpc/server';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
type TRPCOptionsProxy,
|
|
8
|
-
} from './createOptionsProxy';
|
|
5
|
+
import type { TRPCOptionsProxy } from './createOptionsProxy';
|
|
6
|
+
import { createTRPCOptionsProxy } from './createOptionsProxy';
|
|
9
7
|
|
|
10
|
-
export
|
|
8
|
+
export interface CreateTRPCContextResult<TRouter extends AnyTRPCRouter> {
|
|
9
|
+
TRPCProvider: React.FC<{
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
queryClient: QueryClient;
|
|
12
|
+
trpcClient: TRPCClient<TRouter>;
|
|
13
|
+
}>;
|
|
14
|
+
useTRPC: () => TRPCOptionsProxy<TRouter>;
|
|
15
|
+
useTRPCClient: () => TRPCClient<TRouter>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a set of type-safe provider-consumers
|
|
19
|
+
*
|
|
20
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider
|
|
21
|
+
*/
|
|
22
|
+
export function createTRPCContext<
|
|
23
|
+
TRouter extends AnyTRPCRouter,
|
|
24
|
+
>(): CreateTRPCContextResult<TRouter> {
|
|
25
|
+
const TRPCClientContext = React.createContext<TRPCClient<TRouter> | null>(
|
|
26
|
+
null,
|
|
27
|
+
);
|
|
11
28
|
const TRPCContext = React.createContext<TRPCOptionsProxy<TRouter> | null>(
|
|
12
29
|
null,
|
|
13
30
|
);
|
|
@@ -16,7 +33,7 @@ export function createTRPCContext<TRouter extends AnyTRPCRouter>() {
|
|
|
16
33
|
props: Readonly<{
|
|
17
34
|
children: React.ReactNode;
|
|
18
35
|
queryClient: QueryClient;
|
|
19
|
-
trpcClient:
|
|
36
|
+
trpcClient: TRPCClient<TRouter>;
|
|
20
37
|
}>,
|
|
21
38
|
) {
|
|
22
39
|
const value = React.useMemo(
|
|
@@ -28,9 +45,11 @@ export function createTRPCContext<TRouter extends AnyTRPCRouter>() {
|
|
|
28
45
|
[props.trpcClient, props.queryClient],
|
|
29
46
|
);
|
|
30
47
|
return (
|
|
31
|
-
<
|
|
32
|
-
{
|
|
33
|
-
|
|
48
|
+
<TRPCClientContext.Provider value={props.trpcClient}>
|
|
49
|
+
<TRPCContext.Provider value={value}>
|
|
50
|
+
{props.children}
|
|
51
|
+
</TRPCContext.Provider>
|
|
52
|
+
</TRPCClientContext.Provider>
|
|
34
53
|
);
|
|
35
54
|
}
|
|
36
55
|
|
|
@@ -42,5 +61,15 @@ export function createTRPCContext<TRouter extends AnyTRPCRouter>() {
|
|
|
42
61
|
return utils;
|
|
43
62
|
}
|
|
44
63
|
|
|
45
|
-
|
|
64
|
+
function useTRPCClient() {
|
|
65
|
+
const client = React.useContext(TRPCClientContext);
|
|
66
|
+
if (!client) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
'useTRPCClient() can only be used inside of a <TRPCProvider>',
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return client;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { TRPCProvider, useTRPC, useTRPCClient };
|
|
46
75
|
}
|