@trpc/tanstack-react-query 0.0.0-alpha.3 → 0.0.0-alpha.5
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 +8 -7
- package/dist/internals/Context.d.ts +2 -2
- package/dist/internals/Context.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.d.ts +5 -5
- package/dist/internals/createOptionsProxy.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.js +2 -3
- package/dist/internals/createOptionsProxy.mjs +2 -3
- package/dist/internals/mutationOptions.d.ts +2 -2
- package/dist/internals/mutationOptions.d.ts.map +1 -1
- package/dist/internals/subscriptionOptions.d.ts +5 -5
- package/dist/internals/subscriptionOptions.d.ts.map +1 -1
- package/dist/internals/subscriptionOptions.js +37 -35
- package/dist/internals/subscriptionOptions.mjs +37 -35
- package/package.json +7 -5
- package/src/internals/Context.tsx +2 -2
- package/src/internals/createOptionsProxy.ts +10 -9
- package/src/internals/mutationOptions.ts +2 -2
- package/src/internals/subscriptionOptions.ts +41 -41
package/README.md
CHANGED
|
@@ -8,21 +8,22 @@
|
|
|
8
8
|
<strong>End-to-end typesafe APIs made easy</strong>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
|
-
<p align="center">
|
|
12
|
-
<img src="https://assets.trpc.io/www/v10/v10-dark-landscape.gif" alt="Demo" />
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
11
|
# `@trpc/tanstack-react-query`
|
|
16
12
|
|
|
17
|
-
> A tRPC wrapper around
|
|
13
|
+
> A tRPC wrapper around `@tanstack/react-query`.
|
|
14
|
+
|
|
15
|
+
> [!WARNING]
|
|
16
|
+
>
|
|
17
|
+
> 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
|
|
18
|
+
> This package is currently in beta as we stabilize the API. We might do breaking changes without respecting semver.
|
|
18
19
|
|
|
19
20
|
## Documentation
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Full documentation can be found at https://trpc.io/docs/client/tanstack-react-query/introduction.
|
|
22
23
|
|
|
23
24
|
## Installation
|
|
24
25
|
|
|
25
|
-
> Requires `@tanstack/react-query` v5.
|
|
26
|
+
> Requires `@tanstack/react-query` v5.62.8 or higher
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
29
|
# npm
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { type CreateTRPCClient } from '@trpc/client';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { type TRPCOptionsProxy } from './createOptionsProxy';
|
|
6
|
-
export declare function createTRPCContext<TRouter extends
|
|
6
|
+
export declare function createTRPCContext<TRouter extends AnyRouter>(): {
|
|
7
7
|
TRPCProvider: (props: Readonly<{
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
queryClient: QueryClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/internals/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/internals/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS;0BAMhD,QAAQ,CAAC;QACd,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,WAAW,EAAE,WAAW,CAAC;QACzB,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;KACvC,CAAC;;EA0BL"}
|
|
@@ -11,13 +11,13 @@ import { type TRPCSubscriptionOptions } from './subscriptionOptions';
|
|
|
11
11
|
import type { ResolverDef, TRPCMutationKey, TRPCQueryKey } from './types';
|
|
12
12
|
export interface DecorateQueryKeyable {
|
|
13
13
|
/**
|
|
14
|
-
* Calculate the
|
|
14
|
+
* Calculate the TanStack Query Key for a Route
|
|
15
15
|
*
|
|
16
16
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
17
17
|
*/
|
|
18
18
|
queryKey: () => TRPCQueryKey;
|
|
19
19
|
/**
|
|
20
|
-
* Calculate a
|
|
20
|
+
* Calculate a TanStack Query Filter for a Route
|
|
21
21
|
*
|
|
22
22
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
23
23
|
*/
|
|
@@ -43,13 +43,13 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
43
43
|
*/
|
|
44
44
|
infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
|
|
45
45
|
/**
|
|
46
|
-
* Calculate the
|
|
46
|
+
* Calculate the TanStack Query Key for a Query Procedure
|
|
47
47
|
*
|
|
48
48
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
49
49
|
*/
|
|
50
50
|
queryKey: (input?: TDef['input']) => DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>;
|
|
51
51
|
/**
|
|
52
|
-
* Calculate a
|
|
52
|
+
* Calculate a TanStack Query Filter for a Query Procedure
|
|
53
53
|
*
|
|
54
54
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
55
55
|
*/
|
|
@@ -68,7 +68,7 @@ export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
|
68
68
|
*/
|
|
69
69
|
mutationOptions: TRPCMutationOptions<TDef>;
|
|
70
70
|
/**
|
|
71
|
-
* Calculate the
|
|
71
|
+
* Calculate the TanStack Mutation Key for a Mutation Procedure
|
|
72
72
|
*/
|
|
73
73
|
mutationKey: () => TRPCMutationKey;
|
|
74
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOptionsProxy.d.ts","sourceRoot":"","sources":["../../src/internals/createOptionsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAEL,iBAAiB,EACjB,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"createOptionsProxy.d.ts","sourceRoot":"","sources":["../../src/internals/createOptionsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAEL,iBAAiB,EACjB,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,+BAA+B,EACpC,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,YAAY,EACb,MAAM,0CAA0C,CAAC;AAKlD,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAA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AO,CAAC,CAAC;CAChE;AAED,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,SAAS,IAC3D,2BAA2B,GACzB,CACI,+BAA+B,CAAC,OAAO,CAAC,GACxC,+BAA+B,CAAC,OAAO,CAAC,CAC3C,CAAC;AAkBN,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,gBAAgB,CAAC,OAAO,CAAC,CA0F3B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var client = require('@trpc/client');
|
|
4
|
-
var server = require('@trpc/server');
|
|
5
4
|
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
6
5
|
var infiniteQueryOptions = require('./infiniteQueryOptions.js');
|
|
7
6
|
var mutationOptions = require('./mutationOptions.js');
|
|
@@ -22,8 +21,8 @@ function createTRPCOptionsProxy(opts) {
|
|
|
22
21
|
const callIt = (type)=>{
|
|
23
22
|
return (path, input, trpcOpts)=>{
|
|
24
23
|
if ('router' in opts) {
|
|
25
|
-
return Promise.resolve(utils.unwrapLazyArg(opts.ctx)).then((ctx)=>
|
|
26
|
-
|
|
24
|
+
return Promise.resolve(utils.unwrapLazyArg(opts.ctx)).then((ctx)=>unstableCoreDoNotImport.callProcedure({
|
|
25
|
+
router: opts.router,
|
|
27
26
|
path: path,
|
|
28
27
|
getRawInput: async ()=>input,
|
|
29
28
|
ctx: ctx,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
|
|
2
|
-
import { callProcedure } from '@trpc/server';
|
|
3
|
-
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import { createRecursiveProxy, callProcedure } from '@trpc/server/unstable-core-do-not-import';
|
|
4
3
|
import { trpcInfiniteQueryOptions } from './infiniteQueryOptions.mjs';
|
|
5
4
|
import { trpcMutationOptions } from './mutationOptions.mjs';
|
|
6
5
|
import { trpcQueryOptions } from './queryOptions.mjs';
|
|
@@ -21,7 +20,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
21
20
|
return (path, input, trpcOpts)=>{
|
|
22
21
|
if ('router' in opts) {
|
|
23
22
|
return Promise.resolve(unwrapLazyArg(opts.ctx)).then((ctx)=>callProcedure({
|
|
24
|
-
|
|
23
|
+
router: opts.router,
|
|
25
24
|
path: path,
|
|
26
25
|
getRawInput: async ()=>input,
|
|
27
26
|
ctx: ctx,
|
|
@@ -9,7 +9,7 @@ interface TRPCMutationOptionsOut<TInput, TError, TOutput, TContext> extends UseM
|
|
|
9
9
|
mutationKey: TRPCMutationKey;
|
|
10
10
|
}
|
|
11
11
|
export interface TRPCMutationOptions<TDef extends ResolverDef> {
|
|
12
|
-
<TContext = unknown>(opts
|
|
12
|
+
<TContext = unknown>(opts: TRPCMutationOptionsIn<TDef['input'], TRPCClientErrorLike<TDef>, TDef['output'], TContext>): TRPCMutationOptionsOut<TDef['input'], TRPCClientErrorLike<TDef>, TDef['output'], TContext>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
@@ -31,7 +31,7 @@ export declare function trpcMutationOptions(args: {
|
|
|
31
31
|
mutate: typeof TRPCUntypedClient.prototype.mutation;
|
|
32
32
|
queryClient: QueryClient | (() => QueryClient);
|
|
33
33
|
path: readonly string[];
|
|
34
|
-
opts: TRPCMutationOptionsIn<unknown, unknown, unknown, unknown
|
|
34
|
+
opts: TRPCMutationOptionsIn<unknown, unknown, unknown, unknown>;
|
|
35
35
|
overrides: MutationOptionsOverride | undefined;
|
|
36
36
|
}): TRPCMutationOptionsOut<unknown, unknown, unknown, unknown>;
|
|
37
37
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutationOptions.d.ts","sourceRoot":"","sources":["../../src/internals/mutationOptions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW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,WAAW,CAAC,CAAC;IAC/C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,IAAI,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChE,SAAS,EAAE,uBAAuB,GAAG,SAAS,CAAC;CAChD,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAmC7D"}
|
|
@@ -22,8 +22,8 @@ interface TRPCSubscriptionOptionsOut<TOutput, TError> extends UnusedSkipTokenTRP
|
|
|
22
22
|
subscribe: (innerOpts: UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>) => Unsubscribable;
|
|
23
23
|
}
|
|
24
24
|
export interface TRPCSubscriptionOptions<TDef extends ResolverDef> {
|
|
25
|
-
(input: TDef['input'], opts
|
|
26
|
-
(input: TDef['input'] | SkipToken, opts
|
|
25
|
+
(input: TDef['input'], opts: UnusedSkipTokenTRPCSubscriptionOptionsIn<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>): TRPCSubscriptionOptionsOut<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
|
26
|
+
(input: TDef['input'] | SkipToken, opts: BaseTRPCSubscriptionOptionsIn<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>): TRPCSubscriptionOptionsOut<inferAsyncIterableYield<TDef['output']>, TRPCClientErrorLike<TDef>>;
|
|
27
27
|
}
|
|
28
28
|
export type TRPCSubscriptionStatus = 'idle' | 'connecting' | 'pending' | 'error';
|
|
29
29
|
export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
@@ -47,7 +47,7 @@ export interface TRPCSubscriptionConnectingResult<TOutput, TError> extends TRPCS
|
|
|
47
47
|
}
|
|
48
48
|
export interface TRPCSubscriptionPendingResult<TOutput> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
|
49
49
|
status: 'pending';
|
|
50
|
-
data: TOutput;
|
|
50
|
+
data: TOutput | undefined;
|
|
51
51
|
error: null;
|
|
52
52
|
}
|
|
53
53
|
export interface TRPCSubscriptionErrorResult<TOutput, TError> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
@@ -60,7 +60,7 @@ export declare const trpcSubscriptionOptions: (args: {
|
|
|
60
60
|
subscribe: typeof TRPCUntypedClient.prototype.subscription;
|
|
61
61
|
path: readonly string[];
|
|
62
62
|
queryKey: TRPCQueryKey;
|
|
63
|
-
opts: BaseTRPCSubscriptionOptionsIn<unknown, unknown
|
|
63
|
+
opts: BaseTRPCSubscriptionOptionsIn<unknown, unknown>;
|
|
64
64
|
}) => {
|
|
65
65
|
enabled: boolean;
|
|
66
66
|
subscribe: (innerOpts: UnusedSkipTokenTRPCSubscriptionOptionsIn<any, TRPCClientErrorLike<any>>) => Unsubscribable;
|
|
@@ -69,7 +69,7 @@ export declare const trpcSubscriptionOptions: (args: {
|
|
|
69
69
|
path: string;
|
|
70
70
|
};
|
|
71
71
|
onStarted?: () => void;
|
|
72
|
-
onData
|
|
72
|
+
onData: (data: unknown) => void;
|
|
73
73
|
onError?: ((err: unknown) => void) | undefined;
|
|
74
74
|
};
|
|
75
75
|
export declare function useSubscription<TOutput, TError>(opts: TRPCSubscriptionOptionsOut<TOutput, TError>): TRPCSubscriptionResult<TOutput, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptionOptions.d.ts","sourceRoot":"","sources":["../../src/internals/subscriptionOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,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{
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
let isStopped = false;
|
|
59
58
|
const subscription = opts.subscribe({
|
|
60
59
|
onStarted: ()=>{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
60
|
+
optsRef.current.onStarted?.();
|
|
61
|
+
updateState((prev)=>({
|
|
62
|
+
...prev,
|
|
63
|
+
status: 'pending',
|
|
64
|
+
error: null
|
|
65
|
+
}));
|
|
69
66
|
},
|
|
70
67
|
onData: (data)=>{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
68
|
+
optsRef.current.onData?.(data);
|
|
69
|
+
updateState((prev)=>({
|
|
70
|
+
...prev,
|
|
71
|
+
status: 'pending',
|
|
72
|
+
data,
|
|
73
|
+
error: null
|
|
74
|
+
}));
|
|
80
75
|
},
|
|
81
76
|
onError: (error)=>{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
77
|
+
optsRef.current.onError?.(error);
|
|
78
|
+
updateState((prev)=>({
|
|
79
|
+
...prev,
|
|
80
|
+
status: 'error',
|
|
81
|
+
error
|
|
82
|
+
}));
|
|
90
83
|
},
|
|
91
84
|
onConnectionStateChange: (result)=>{
|
|
92
|
-
const delta = {
|
|
93
|
-
status: result.state,
|
|
94
|
-
error: result.error
|
|
95
|
-
};
|
|
96
85
|
updateState((prev)=>{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
switch(result.state){
|
|
87
|
+
case 'connecting':
|
|
88
|
+
return {
|
|
89
|
+
...prev,
|
|
90
|
+
status: 'connecting',
|
|
91
|
+
error: result.error
|
|
92
|
+
};
|
|
93
|
+
case 'pending':
|
|
94
|
+
// handled in onStarted
|
|
95
|
+
return prev;
|
|
96
|
+
case 'idle':
|
|
97
|
+
return {
|
|
98
|
+
...prev,
|
|
99
|
+
status: 'idle',
|
|
100
|
+
data: undefined,
|
|
101
|
+
error: null
|
|
102
|
+
};
|
|
103
|
+
}
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
106
|
});
|
|
104
107
|
currentSubscriptionRef.current = ()=>{
|
|
105
|
-
isStopped = true;
|
|
106
108
|
subscription.unsubscribe();
|
|
107
109
|
};
|
|
108
110
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -34,54 +34,56 @@ function useSubscription(opts) {
|
|
|
34
34
|
if (!opts.enabled) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
let isStopped = false;
|
|
38
37
|
const subscription = opts.subscribe({
|
|
39
38
|
onStarted: ()=>{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
39
|
+
optsRef.current.onStarted?.();
|
|
40
|
+
updateState((prev)=>({
|
|
41
|
+
...prev,
|
|
42
|
+
status: 'pending',
|
|
43
|
+
error: null
|
|
44
|
+
}));
|
|
48
45
|
},
|
|
49
46
|
onData: (data)=>{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
47
|
+
optsRef.current.onData?.(data);
|
|
48
|
+
updateState((prev)=>({
|
|
49
|
+
...prev,
|
|
50
|
+
status: 'pending',
|
|
51
|
+
data,
|
|
52
|
+
error: null
|
|
53
|
+
}));
|
|
59
54
|
},
|
|
60
55
|
onError: (error)=>{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
56
|
+
optsRef.current.onError?.(error);
|
|
57
|
+
updateState((prev)=>({
|
|
58
|
+
...prev,
|
|
59
|
+
status: 'error',
|
|
60
|
+
error
|
|
61
|
+
}));
|
|
69
62
|
},
|
|
70
63
|
onConnectionStateChange: (result)=>{
|
|
71
|
-
const delta = {
|
|
72
|
-
status: result.state,
|
|
73
|
-
error: result.error
|
|
74
|
-
};
|
|
75
64
|
updateState((prev)=>{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
switch(result.state){
|
|
66
|
+
case 'connecting':
|
|
67
|
+
return {
|
|
68
|
+
...prev,
|
|
69
|
+
status: 'connecting',
|
|
70
|
+
error: result.error
|
|
71
|
+
};
|
|
72
|
+
case 'pending':
|
|
73
|
+
// handled in onStarted
|
|
74
|
+
return prev;
|
|
75
|
+
case 'idle':
|
|
76
|
+
return {
|
|
77
|
+
...prev,
|
|
78
|
+
status: 'idle',
|
|
79
|
+
data: undefined,
|
|
80
|
+
error: null
|
|
81
|
+
};
|
|
82
|
+
}
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
currentSubscriptionRef.current = ()=>{
|
|
84
|
-
isStopped = true;
|
|
85
87
|
subscription.unsubscribe();
|
|
86
88
|
};
|
|
87
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/tanstack-react-query",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.0-alpha.5",
|
|
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/introduction",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@tanstack/react-query": "^5.62.
|
|
43
|
+
"@tanstack/react-query": "^5.62.8",
|
|
44
44
|
"@trpc/client": "10.45.1",
|
|
45
45
|
"@trpc/server": "^10.45.1",
|
|
46
46
|
"react": ">=18.2.0",
|
|
@@ -48,12 +48,13 @@
|
|
|
48
48
|
"typescript": ">=5.7.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@tanstack/react-query": "^5.
|
|
51
|
+
"@tanstack/react-query": "^5.66.0",
|
|
52
52
|
"@trpc/client": "10.45.1",
|
|
53
53
|
"@trpc/server": "^10.45.1",
|
|
54
54
|
"@types/node": "^20.10.0",
|
|
55
55
|
"@types/react": "^18.3.1",
|
|
56
56
|
"eslint": "^8.57.0",
|
|
57
|
+
"event-source-polyfill": "^1.0.31",
|
|
57
58
|
"konn": "^0.7.0",
|
|
58
59
|
"react": "^19.0.0",
|
|
59
60
|
"react-dom": "^18.3.1",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"tsx": "^4.0.0",
|
|
62
63
|
"typescript": "^5.6.2",
|
|
63
64
|
"vitest": "^2.0.4",
|
|
65
|
+
"ws": "^8.0.0",
|
|
64
66
|
"zod": "^3.0.0"
|
|
65
67
|
},
|
|
66
68
|
"publishConfig": {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import { type CreateTRPCClient } from '@trpc/client';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import {
|
|
6
6
|
createTRPCOptionsProxy,
|
|
7
7
|
type TRPCOptionsProxy,
|
|
8
8
|
} from './createOptionsProxy';
|
|
9
9
|
|
|
10
|
-
export function createTRPCContext<TRouter extends
|
|
10
|
+
export function createTRPCContext<TRouter extends AnyRouter>() {
|
|
11
11
|
const TRPCContext = React.createContext<TRPCOptionsProxy<TRouter> | null>(
|
|
12
12
|
null,
|
|
13
13
|
);
|
|
@@ -7,20 +7,22 @@ import {
|
|
|
7
7
|
type TRPCRequestOptions,
|
|
8
8
|
} from '@trpc/client';
|
|
9
9
|
import {
|
|
10
|
-
callProcedure,
|
|
11
10
|
type AnyProcedure,
|
|
12
11
|
type inferProcedureInput,
|
|
13
12
|
type inferRouterContext,
|
|
14
13
|
type inferTransformedProcedureOutput,
|
|
15
14
|
type ProcedureType,
|
|
16
15
|
} from '@trpc/server';
|
|
17
|
-
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
18
16
|
import type {
|
|
19
17
|
AnyRootTypes,
|
|
20
18
|
AnyRouter,
|
|
21
19
|
MaybePromise,
|
|
22
20
|
RouterRecord,
|
|
23
21
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
22
|
+
import {
|
|
23
|
+
callProcedure,
|
|
24
|
+
createRecursiveProxy,
|
|
25
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
24
26
|
import {
|
|
25
27
|
trpcInfiniteQueryOptions,
|
|
26
28
|
type TRPCInfiniteQueryOptions,
|
|
@@ -49,14 +51,14 @@ import {
|
|
|
49
51
|
|
|
50
52
|
export interface DecorateQueryKeyable {
|
|
51
53
|
/**
|
|
52
|
-
* Calculate the
|
|
54
|
+
* Calculate the TanStack Query Key for a Route
|
|
53
55
|
*
|
|
54
56
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
55
57
|
*/
|
|
56
58
|
queryKey: () => TRPCQueryKey;
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
|
-
* Calculate a
|
|
61
|
+
* Calculate a TanStack Query Filter for a Route
|
|
60
62
|
*
|
|
61
63
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
62
64
|
*/
|
|
@@ -96,17 +98,16 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
96
98
|
infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
|
|
97
99
|
|
|
98
100
|
/**
|
|
99
|
-
* Calculate the
|
|
101
|
+
* Calculate the TanStack Query Key for a Query Procedure
|
|
100
102
|
*
|
|
101
103
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
102
104
|
*/
|
|
103
105
|
queryKey: (
|
|
104
106
|
input?: TDef['input'],
|
|
105
|
-
// tslint seems to be wrong here, the type is correct
|
|
106
107
|
) => DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>;
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
|
-
* Calculate a
|
|
110
|
+
* Calculate a TanStack Query Filter for a Query Procedure
|
|
110
111
|
*
|
|
111
112
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
112
113
|
*/
|
|
@@ -136,7 +137,7 @@ export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
|
136
137
|
mutationOptions: TRPCMutationOptions<TDef>;
|
|
137
138
|
|
|
138
139
|
/**
|
|
139
|
-
* Calculate the
|
|
140
|
+
* Calculate the TanStack Mutation Key for a Mutation Procedure
|
|
140
141
|
*/
|
|
141
142
|
mutationKey: () => TRPCMutationKey;
|
|
142
143
|
}
|
|
@@ -239,7 +240,7 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
239
240
|
if ('router' in opts) {
|
|
240
241
|
return Promise.resolve(unwrapLazyArg(opts.ctx)).then((ctx) =>
|
|
241
242
|
callProcedure({
|
|
242
|
-
|
|
243
|
+
router: opts.router,
|
|
243
244
|
path: path,
|
|
244
245
|
getRawInput: async () => input,
|
|
245
246
|
ctx: ctx,
|
|
@@ -38,7 +38,7 @@ interface TRPCMutationOptionsOut<TInput, TError, TOutput, TContext>
|
|
|
38
38
|
|
|
39
39
|
export interface TRPCMutationOptions<TDef extends ResolverDef> {
|
|
40
40
|
<TContext = unknown>(
|
|
41
|
-
opts
|
|
41
|
+
opts: TRPCMutationOptionsIn<
|
|
42
42
|
TDef['input'],
|
|
43
43
|
TRPCClientErrorLike<TDef>,
|
|
44
44
|
TDef['output'],
|
|
@@ -73,7 +73,7 @@ export function trpcMutationOptions(args: {
|
|
|
73
73
|
mutate: typeof TRPCUntypedClient.prototype.mutation;
|
|
74
74
|
queryClient: QueryClient | (() => QueryClient);
|
|
75
75
|
path: readonly string[];
|
|
76
|
-
opts: TRPCMutationOptionsIn<unknown, unknown, unknown, unknown
|
|
76
|
+
opts: TRPCMutationOptionsIn<unknown, unknown, unknown, unknown>;
|
|
77
77
|
overrides: MutationOptionsOverride | undefined;
|
|
78
78
|
}): TRPCMutationOptionsOut<unknown, unknown, unknown, unknown> {
|
|
79
79
|
const { mutate, path, opts, overrides } = args;
|
|
@@ -38,7 +38,7 @@ interface TRPCSubscriptionOptionsOut<TOutput, TError>
|
|
|
38
38
|
export interface TRPCSubscriptionOptions<TDef extends ResolverDef> {
|
|
39
39
|
(
|
|
40
40
|
input: TDef['input'],
|
|
41
|
-
opts
|
|
41
|
+
opts: UnusedSkipTokenTRPCSubscriptionOptionsIn<
|
|
42
42
|
inferAsyncIterableYield<TDef['output']>,
|
|
43
43
|
TRPCClientErrorLike<TDef>
|
|
44
44
|
>,
|
|
@@ -48,7 +48,7 @@ export interface TRPCSubscriptionOptions<TDef extends ResolverDef> {
|
|
|
48
48
|
>;
|
|
49
49
|
(
|
|
50
50
|
input: TDef['input'] | SkipToken,
|
|
51
|
-
opts
|
|
51
|
+
opts: BaseTRPCSubscriptionOptionsIn<
|
|
52
52
|
inferAsyncIterableYield<TDef['output']>,
|
|
53
53
|
TRPCClientErrorLike<TDef>
|
|
54
54
|
>,
|
|
@@ -90,7 +90,7 @@ export interface TRPCSubscriptionConnectingResult<TOutput, TError>
|
|
|
90
90
|
export interface TRPCSubscriptionPendingResult<TOutput>
|
|
91
91
|
extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
|
92
92
|
status: 'pending';
|
|
93
|
-
data: TOutput;
|
|
93
|
+
data: TOutput | undefined;
|
|
94
94
|
error: null;
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -111,7 +111,7 @@ export const trpcSubscriptionOptions = (args: {
|
|
|
111
111
|
subscribe: typeof TRPCUntypedClient.prototype.subscription;
|
|
112
112
|
path: readonly string[];
|
|
113
113
|
queryKey: TRPCQueryKey;
|
|
114
|
-
opts: BaseTRPCSubscriptionOptionsIn<unknown, unknown
|
|
114
|
+
opts: BaseTRPCSubscriptionOptionsIn<unknown, unknown>;
|
|
115
115
|
}) => {
|
|
116
116
|
const { subscribe, path, queryKey, opts } = args;
|
|
117
117
|
const input = queryKey[1]?.input;
|
|
@@ -157,57 +157,57 @@ export function useSubscription<TOutput, TError>(
|
|
|
157
157
|
if (!opts.enabled) {
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
|
-
|
|
161
|
-
let isStopped = false;
|
|
162
160
|
const subscription = opts.subscribe({
|
|
163
161
|
onStarted: () => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}));
|
|
171
|
-
}
|
|
162
|
+
optsRef.current.onStarted?.();
|
|
163
|
+
updateState((prev) => ({
|
|
164
|
+
...(prev as any),
|
|
165
|
+
status: 'pending',
|
|
166
|
+
error: null,
|
|
167
|
+
}));
|
|
172
168
|
},
|
|
173
169
|
onData: (data) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
170
|
+
optsRef.current.onData?.(data);
|
|
171
|
+
updateState((prev) => ({
|
|
172
|
+
...(prev as any),
|
|
173
|
+
status: 'pending',
|
|
174
|
+
data,
|
|
175
|
+
error: null,
|
|
176
|
+
}));
|
|
183
177
|
},
|
|
184
178
|
onError: (error) => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
179
|
+
optsRef.current.onError?.(error);
|
|
180
|
+
updateState((prev) => ({
|
|
181
|
+
...(prev as any),
|
|
182
|
+
status: 'error',
|
|
183
|
+
error,
|
|
184
|
+
}));
|
|
193
185
|
},
|
|
194
186
|
onConnectionStateChange: (result) => {
|
|
195
|
-
const delta = {
|
|
196
|
-
status: result.state,
|
|
197
|
-
error: result.error,
|
|
198
|
-
} as $Result;
|
|
199
|
-
|
|
200
187
|
updateState((prev) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
188
|
+
switch (result.state) {
|
|
189
|
+
case 'connecting':
|
|
190
|
+
return {
|
|
191
|
+
...prev,
|
|
192
|
+
status: 'connecting',
|
|
193
|
+
error: result.error,
|
|
194
|
+
};
|
|
195
|
+
case 'pending':
|
|
196
|
+
// handled in onStarted
|
|
197
|
+
return prev;
|
|
198
|
+
case 'idle':
|
|
199
|
+
return {
|
|
200
|
+
...prev,
|
|
201
|
+
status: 'idle',
|
|
202
|
+
data: undefined,
|
|
203
|
+
error: null,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
205
206
|
});
|
|
206
207
|
},
|
|
207
208
|
});
|
|
208
209
|
|
|
209
210
|
currentSubscriptionRef.current = () => {
|
|
210
|
-
isStopped = true;
|
|
211
211
|
subscription.unsubscribe();
|
|
212
212
|
};
|
|
213
213
|
|