@trpc/tanstack-react-query 0.0.0-alpha.2 → 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 +4 -6
- package/dist/internals/Context.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.d.ts +10 -8
- package/dist/internals/createOptionsProxy.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.js +12 -10
- package/dist/internals/createOptionsProxy.mjs +13 -11
- package/dist/internals/infiniteQueryOptions.d.ts +7 -4
- package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
- package/dist/internals/mutationOptions.d.ts +2 -2
- package/dist/internals/mutationOptions.d.ts.map +1 -1
- package/dist/internals/queryOptions.d.ts +7 -4
- package/dist/internals/queryOptions.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 +9 -8
- package/src/internals/Context.tsx +2 -2
- package/src/internals/createOptionsProxy.ts +36 -18
- package/src/internals/infiniteQueryOptions.ts +3 -3
- package/src/internals/mutationOptions.ts +2 -2
- package/src/internals/queryOptions.ts +3 -3
- 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,16 +1,14 @@
|
|
|
1
1
|
import { type QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
2
|
+
import { type CreateTRPCClient } from '@trpc/client';
|
|
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
|
-
|
|
7
|
-
export declare function createTRPCContext<TRouter extends AnyTRPCRouter>(): {
|
|
6
|
+
export declare function createTRPCContext<TRouter extends AnyRouter>(): {
|
|
8
7
|
TRPCProvider: (props: Readonly<{
|
|
9
8
|
children: React.ReactNode;
|
|
10
9
|
queryClient: QueryClient;
|
|
11
|
-
trpcClient:
|
|
10
|
+
trpcClient: CreateTRPCClient<TRouter>;
|
|
12
11
|
}>) => React.JSX.Element;
|
|
13
12
|
useTRPC: () => TRPCOptionsProxy<TRouter>;
|
|
14
13
|
};
|
|
15
|
-
export {};
|
|
16
14
|
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -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,KAAK,
|
|
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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DataTag } from '@tanstack/react-query';
|
|
1
2
|
import { type QueryClient, type QueryFilters } from '@tanstack/react-query';
|
|
2
3
|
import { TRPCUntypedClient, type CreateTRPCClient } from '@trpc/client';
|
|
3
4
|
import { type AnyProcedure, type inferProcedureInput, type inferRouterContext, type inferTransformedProcedureOutput, type ProcedureType } from '@trpc/server';
|
|
@@ -10,17 +11,17 @@ import { type TRPCSubscriptionOptions } from './subscriptionOptions';
|
|
|
10
11
|
import type { ResolverDef, TRPCMutationKey, TRPCQueryKey } from './types';
|
|
11
12
|
export interface DecorateQueryKeyable {
|
|
12
13
|
/**
|
|
13
|
-
* Calculate the
|
|
14
|
+
* Calculate the TanStack Query Key for a Route
|
|
14
15
|
*
|
|
15
16
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
16
17
|
*/
|
|
17
18
|
queryKey: () => TRPCQueryKey;
|
|
18
19
|
/**
|
|
19
|
-
* Calculate a
|
|
20
|
+
* Calculate a TanStack Query Filter for a Route
|
|
20
21
|
*
|
|
21
22
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
22
23
|
*/
|
|
23
|
-
queryFilter: () => QueryFilters;
|
|
24
|
+
queryFilter: (input?: undefined, filters?: QueryFilters) => QueryFilters;
|
|
24
25
|
}
|
|
25
26
|
export type InferInput<TProcedure extends DecorateQueryProcedure<any> | DecorateMutationProcedure<any>> = TProcedure['~types']['input'];
|
|
26
27
|
export type InferOutput<TProcedure extends DecorateQueryProcedure<any> | DecorateMutationProcedure<any>> = TProcedure['~types']['output'];
|
|
@@ -31,6 +32,7 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
31
32
|
'~types': {
|
|
32
33
|
input: TDef['input'];
|
|
33
34
|
output: TDef['output'];
|
|
35
|
+
errorShape: TDef['errorShape'];
|
|
34
36
|
};
|
|
35
37
|
/**
|
|
36
38
|
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
@@ -41,17 +43,17 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
41
43
|
*/
|
|
42
44
|
infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
|
|
43
45
|
/**
|
|
44
|
-
* Calculate the
|
|
46
|
+
* Calculate the TanStack Query Key for a Query Procedure
|
|
45
47
|
*
|
|
46
48
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
47
49
|
*/
|
|
48
|
-
queryKey: (input?: TDef['input']) => TRPCQueryKey
|
|
50
|
+
queryKey: (input?: TDef['input']) => DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>;
|
|
49
51
|
/**
|
|
50
|
-
* Calculate a
|
|
52
|
+
* Calculate a TanStack Query Filter for a Query Procedure
|
|
51
53
|
*
|
|
52
54
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
53
55
|
*/
|
|
54
|
-
queryFilter: (input?: TDef['input']) => QueryFilters
|
|
56
|
+
queryFilter: (input?: TDef['input'], filters?: QueryFilters<TDef['output'], TDef['errorShape']>) => QueryFilters<TDef['output'], TDef['errorShape'], TDef['output'], DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>>;
|
|
55
57
|
}
|
|
56
58
|
export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
57
59
|
/**
|
|
@@ -66,7 +68,7 @@ export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
|
66
68
|
*/
|
|
67
69
|
mutationOptions: TRPCMutationOptions<TDef>;
|
|
68
70
|
/**
|
|
69
|
-
* Calculate the
|
|
71
|
+
* Calculate the TanStack Mutation Key for a Mutation Procedure
|
|
70
72
|
*/
|
|
71
73
|
mutationKey: () => TRPCMutationKey;
|
|
72
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOptionsProxy.d.ts","sourceRoot":"","sources":["../../src/internals/createOptionsProxy.ts"],"names":[],"mappings":"AAAA,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,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AAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,+BAA+B,CAAC,OAAO,SAAS,SAAS;IACxE,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC,OAAO,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,
|
|
@@ -41,19 +40,22 @@ function createTRPCOptionsProxy(opts) {
|
|
|
41
40
|
];
|
|
42
41
|
const utilName = path.pop();
|
|
43
42
|
const [arg1, arg2] = args;
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
function getQueryKey() {
|
|
44
|
+
const queryType = getQueryType(utilName);
|
|
45
|
+
return utils.getQueryKeyInternal(path, arg1, queryType ?? 'any');
|
|
46
|
+
}
|
|
46
47
|
const contextMap = {
|
|
47
48
|
'~types': undefined,
|
|
48
49
|
mutationKey: ()=>{
|
|
49
50
|
return utils.getMutationKeyInternal(path);
|
|
50
51
|
},
|
|
51
52
|
queryKey: ()=>{
|
|
52
|
-
return
|
|
53
|
+
return getQueryKey();
|
|
53
54
|
},
|
|
54
55
|
queryFilter: ()=>{
|
|
55
56
|
return {
|
|
56
|
-
|
|
57
|
+
...arg2,
|
|
58
|
+
queryKey: getQueryKey()
|
|
57
59
|
};
|
|
58
60
|
},
|
|
59
61
|
infiniteQueryOptions: ()=>{
|
|
@@ -61,7 +63,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
61
63
|
opts: arg2,
|
|
62
64
|
path,
|
|
63
65
|
queryClient: opts.queryClient,
|
|
64
|
-
queryKey:
|
|
66
|
+
queryKey: getQueryKey(),
|
|
65
67
|
query: callIt('query')
|
|
66
68
|
});
|
|
67
69
|
},
|
|
@@ -70,7 +72,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
70
72
|
opts: arg2,
|
|
71
73
|
path,
|
|
72
74
|
queryClient: opts.queryClient,
|
|
73
|
-
queryKey:
|
|
75
|
+
queryKey: getQueryKey(),
|
|
74
76
|
query: callIt('query')
|
|
75
77
|
});
|
|
76
78
|
},
|
|
@@ -87,7 +89,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
87
89
|
return subscriptionOptions.trpcSubscriptionOptions({
|
|
88
90
|
opts: arg2,
|
|
89
91
|
path,
|
|
90
|
-
queryKey:
|
|
92
|
+
queryKey: getQueryKey(),
|
|
91
93
|
subscribe: callIt('subscription')
|
|
92
94
|
});
|
|
93
95
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
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';
|
|
7
6
|
import { trpcSubscriptionOptions } from './subscriptionOptions.mjs';
|
|
8
|
-
import {
|
|
7
|
+
import { getMutationKeyInternal, unwrapLazyArg, getQueryKeyInternal } from './utils.mjs';
|
|
9
8
|
|
|
10
9
|
function getQueryType(method) {
|
|
11
10
|
const map = {
|
|
@@ -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,
|
|
@@ -39,19 +38,22 @@ function createTRPCOptionsProxy(opts) {
|
|
|
39
38
|
];
|
|
40
39
|
const utilName = path.pop();
|
|
41
40
|
const [arg1, arg2] = args;
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
function getQueryKey() {
|
|
42
|
+
const queryType = getQueryType(utilName);
|
|
43
|
+
return getQueryKeyInternal(path, arg1, queryType ?? 'any');
|
|
44
|
+
}
|
|
44
45
|
const contextMap = {
|
|
45
46
|
'~types': undefined,
|
|
46
47
|
mutationKey: ()=>{
|
|
47
48
|
return getMutationKeyInternal(path);
|
|
48
49
|
},
|
|
49
50
|
queryKey: ()=>{
|
|
50
|
-
return
|
|
51
|
+
return getQueryKey();
|
|
51
52
|
},
|
|
52
53
|
queryFilter: ()=>{
|
|
53
54
|
return {
|
|
54
|
-
|
|
55
|
+
...arg2,
|
|
56
|
+
queryKey: getQueryKey()
|
|
55
57
|
};
|
|
56
58
|
},
|
|
57
59
|
infiniteQueryOptions: ()=>{
|
|
@@ -59,7 +61,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
59
61
|
opts: arg2,
|
|
60
62
|
path,
|
|
61
63
|
queryClient: opts.queryClient,
|
|
62
|
-
queryKey:
|
|
64
|
+
queryKey: getQueryKey(),
|
|
63
65
|
query: callIt('query')
|
|
64
66
|
});
|
|
65
67
|
},
|
|
@@ -68,7 +70,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
68
70
|
opts: arg2,
|
|
69
71
|
path,
|
|
70
72
|
queryClient: opts.queryClient,
|
|
71
|
-
queryKey:
|
|
73
|
+
queryKey: getQueryKey(),
|
|
72
74
|
query: callIt('query')
|
|
73
75
|
});
|
|
74
76
|
},
|
|
@@ -85,7 +87,7 @@ function createTRPCOptionsProxy(opts) {
|
|
|
85
87
|
return trpcSubscriptionOptions({
|
|
86
88
|
opts: arg2,
|
|
87
89
|
path,
|
|
88
|
-
queryKey:
|
|
90
|
+
queryKey: getQueryKey(),
|
|
89
91
|
subscribe: callIt('subscription')
|
|
90
92
|
});
|
|
91
93
|
}
|
|
@@ -8,21 +8,21 @@ interface UndefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TErro
|
|
|
8
8
|
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
9
9
|
}
|
|
10
10
|
interface UndefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
|
11
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
11
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
12
12
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
13
13
|
}
|
|
14
14
|
interface DefinedTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, ReservedOptions>, TRPCQueryBaseOptions {
|
|
15
15
|
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
16
16
|
}
|
|
17
17
|
interface DefinedTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
|
18
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
18
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
19
19
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
20
20
|
}
|
|
21
21
|
interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, ReservedOptions>, TRPCQueryBaseOptions {
|
|
22
22
|
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
23
23
|
}
|
|
24
24
|
interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<TInput, TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>, TRPCQueryKey, NonNullable<ExtractCursorType<TInput>> | null>, 'initialPageParam'>, TRPCQueryOptionsResult {
|
|
25
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
25
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
26
26
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
27
27
|
}
|
|
28
28
|
export interface TRPCInfiniteQueryOptions<TDef extends ResolverDef> {
|
|
@@ -39,7 +39,10 @@ export declare function trpcInfiniteQueryOptions(args: {
|
|
|
39
39
|
}): import("@tanstack/react-query").UseInfiniteQueryOptions<unknown, unknown, InfiniteData<unknown, {} | null>, unknown, TRPCQueryKey, {} | null> & {
|
|
40
40
|
initialData?: InfiniteData<unknown, {} | null> | import("@tanstack/react-query").InitialDataFunction<InfiniteData<unknown, {} | null>> | undefined;
|
|
41
41
|
} & {
|
|
42
|
-
queryKey:
|
|
42
|
+
queryKey: TRPCQueryKey & {
|
|
43
|
+
[dataTagSymbol]: InfiniteData<unknown, unknown>;
|
|
44
|
+
[dataTagErrorSymbol]: unknown;
|
|
45
|
+
};
|
|
43
46
|
} & {
|
|
44
47
|
trpc: {
|
|
45
48
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infiniteQueryOptions.d.ts","sourceRoot":"","sources":["../../src/internals/infiniteQueryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iCAAiC,EACjC,YAAY,EAEZ,mCAAmC,EACnC,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAGjB,KAAK,eAAe,GAChB,UAAU,GACV,SAAS,GACT,aAAa,GACb,WAAW,GACX,kBAAkB,CAAC;AAEvB,UAAU,mCAAmC,CAC3C,MAAM,EACN,YAAY,EACZ,KAAK,EACL,MAAM,CACN,SAAQ,gBAAgB,CACpB,mCAAmC,CACjC,YAAY,EACZ,MAAM,EACN,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,EAClE,YAAY,EACZ,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAC9C,EACD,eAAe,CAChB,EACD,oBAAoB;IACtB,aAAa,CAAC,EAAE,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC;CAC/D;AAED,UAAU,oCAAoC,CAC5C,MAAM,EACN,YAAY,EACZ,KAAK,EACL,MAAM,CACN,SAAQ,gBAAgB,CACpB,mCAAmC,CACjC,YAAY,EACZ,MAAM,EACN,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,EAClE,YAAY,EACZ,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAC9C,EACD,kBAAkB,CACnB,EACD,sBAAsB;IACxB,QAAQ,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"infiniteQueryOptions.d.ts","sourceRoot":"","sources":["../../src/internals/infiniteQueryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iCAAiC,EACjC,YAAY,EAEZ,mCAAmC,EACnC,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,m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A,0CAA0C,CAC3C,IAAI,CAAC,OAAO,CAAC,EACb,YAAY,EACZ,KAAK,EACL,mBAAmB,CAAC,IAAI,CAAC,CAC1B,CAAC;IACF,CAAC,YAAY,SAAS,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,YAAY,EACxD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,EAChC,IAAI,CAAC,EAAE,mCAAmC,CACxC,IAAI,CAAC,OAAO,CAAC,EACb,YAAY,EACZ,KAAK,EACL,mBAAmB,CAAC,IAAI,CAAC,CAC1B,GACA,oCAAoC,CACrC,IAAI,CAAC,OAAO,CAAC,EACb,YAAY,EACZ,KAAK,EACL,mBAAmB,CAAC,IAAI,CAAC,CAC1B,CAAC;CACH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,KAAK,EAAE,OAAO,iBAAiB,CAAC,SAAS,CAAC,KAAK,CAAC;IAChD,WAAW,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,CAAC,CAAC;IAC/C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,mCAAmC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC/E;;;;;;;;;;;EAoCA"}
|
|
@@ -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,EAChB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAQjB,KAAK,eAAe,GAAG,aAAa,GAAG,YAAY,CAAC;AAEpD,UAAU,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAC/D,SAAQ,gBAAgB,CACpB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EACrD,eAAe,CAChB,EACD,oBAAoB;CAAG;AAE3B,UAAU,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAChE,SAAQ,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAC3D,sBAAsB;IACxB,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED,MAAM,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AAI,CAAC,QAAQ,CAAC,EACd,QAAQ,CACT,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,CAAC,IAAI,EAAE;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,WAAW,EAAE,WAAW,CAAC;QACzB;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,MAAM,EAAE,OAAO,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC;IACpD,WAAW,EAAE,WAAW,GAAG,CAAC,MAAM,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"}
|
|
@@ -7,17 +7,17 @@ type ReservedOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
|
7
7
|
interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {
|
|
8
8
|
}
|
|
9
9
|
interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UndefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
|
10
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput
|
|
10
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
|
11
11
|
}
|
|
12
12
|
interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {
|
|
13
13
|
}
|
|
14
14
|
interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
|
15
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData
|
|
15
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>, TError>;
|
|
16
16
|
}
|
|
17
17
|
interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TData>, TRPCQueryKey>, ReservedOptions>, TRPCQueryBaseOptions {
|
|
18
18
|
}
|
|
19
19
|
interface UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TOutput, TError> extends UnusedSkipTokenOptions<coerceAsyncIterableToArray<TQueryFnData>, TError, coerceAsyncIterableToArray<TOutput>, TRPCQueryKey>, TRPCQueryOptionsResult {
|
|
20
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput
|
|
20
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
|
21
21
|
}
|
|
22
22
|
export interface TRPCQueryOptions<TDef extends ResolverDef> {
|
|
23
23
|
<TQueryFnData extends TDef['output'], TData = TQueryFnData>(input: TDef['input'] | SkipToken, opts: DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TRPCClientErrorLike<{
|
|
@@ -51,7 +51,10 @@ export declare function trpcQueryOptions(args: {
|
|
|
51
51
|
}): import("@tanstack/react-query").UseQueryOptions<unknown, unknown, unknown, TRPCQueryKey> & {
|
|
52
52
|
initialData?: unknown;
|
|
53
53
|
} & {
|
|
54
|
-
queryKey:
|
|
54
|
+
queryKey: TRPCQueryKey & {
|
|
55
|
+
[dataTagSymbol]: unknown;
|
|
56
|
+
[dataTagErrorSymbol]: unknown;
|
|
57
|
+
};
|
|
55
58
|
} & {
|
|
56
59
|
trpc: {
|
|
57
60
|
path: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryOptions.d.ts","sourceRoot":"","sources":["../../src/internals/queryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,yBAAyB,EACzB,WAAW,EAEX,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EACV,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAQjB,KAAK,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,CAAC;AAE5E,UAAU,2BAA2B,CAAC,YAAY,EAAE,KAAK,EAAE,MAAM,CAC/D,SAAQ,gBAAgB,CACpB,2BAA2B,CACzB,0BAA0B,CAAC,YAAY,CAAC,EACxC,MAAM,EACN,0BAA0B,CAAC,KAAK,CAAC,EACjC,YAAY,CACb,EACD,eAAe,CAChB,EACD,oBAAoB;CAAG;AAE3B,UAAU,4BAA4B,CAAC,YAAY,EAAE,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,EACL,mBAAmB,CAAC;QAClB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACjC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;KAChC,CAAC,CACH,CAAC;CACH;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,KAAK,EAAE,OAAO,iBAAiB,CAAC,SAAS,CAAC,KAAK,CAAC;IAChD,WAAW,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,CAAC,CAAC;IAC/C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,2BAA2B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9D;;;;;;;;;;;EAoCA"}
|
|
@@ -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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Ae,CAAC,OAAO,EAAE,MAAM,EAC7C,IAAI,EAAE,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,GAChD,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,CAuIzC"}
|
|
@@ -55,54 +55,56 @@ function useSubscription(opts) {
|
|
|
55
55
|
if (!opts.enabled) {
|
|
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",
|
|
@@ -39,29 +39,30 @@
|
|
|
39
39
|
"@typescript-eslint/prefer-function-type": "off"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {},
|
|
43
42
|
"peerDependencies": {
|
|
44
|
-
"@tanstack/react-query": "^5.
|
|
43
|
+
"@tanstack/react-query": "^5.62.8",
|
|
45
44
|
"@trpc/client": "10.45.1",
|
|
46
45
|
"@trpc/server": "^10.45.1",
|
|
47
46
|
"react": ">=18.2.0",
|
|
48
47
|
"react-dom": ">=18.2.0",
|
|
49
|
-
"typescript": ">=5.
|
|
48
|
+
"typescript": ">=5.7.2"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@tanstack/react-query": "^5.
|
|
51
|
+
"@tanstack/react-query": "^5.66.0",
|
|
53
52
|
"@trpc/client": "10.45.1",
|
|
54
53
|
"@trpc/server": "^10.45.1",
|
|
55
54
|
"@types/node": "^20.10.0",
|
|
56
55
|
"@types/react": "^18.3.1",
|
|
57
56
|
"eslint": "^8.57.0",
|
|
57
|
+
"event-source-polyfill": "^1.0.31",
|
|
58
58
|
"konn": "^0.7.0",
|
|
59
|
-
"react": "^
|
|
59
|
+
"react": "^19.0.0",
|
|
60
60
|
"react-dom": "^18.3.1",
|
|
61
61
|
"rollup": "^4.9.5",
|
|
62
62
|
"tsx": "^4.0.0",
|
|
63
63
|
"typescript": "^5.6.2",
|
|
64
64
|
"vitest": "^2.0.4",
|
|
65
|
+
"ws": "^8.0.0",
|
|
65
66
|
"zod": "^3.0.0"
|
|
66
67
|
},
|
|
67
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
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DataTag } from '@tanstack/react-query';
|
|
1
2
|
import { type QueryClient, type QueryFilters } from '@tanstack/react-query';
|
|
2
3
|
import {
|
|
3
4
|
getUntypedClient,
|
|
@@ -6,20 +7,22 @@ import {
|
|
|
6
7
|
type TRPCRequestOptions,
|
|
7
8
|
} from '@trpc/client';
|
|
8
9
|
import {
|
|
9
|
-
callProcedure,
|
|
10
10
|
type AnyProcedure,
|
|
11
11
|
type inferProcedureInput,
|
|
12
12
|
type inferRouterContext,
|
|
13
13
|
type inferTransformedProcedureOutput,
|
|
14
14
|
type ProcedureType,
|
|
15
15
|
} from '@trpc/server';
|
|
16
|
-
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
17
16
|
import type {
|
|
18
17
|
AnyRootTypes,
|
|
19
18
|
AnyRouter,
|
|
20
19
|
MaybePromise,
|
|
21
20
|
RouterRecord,
|
|
22
21
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
22
|
+
import {
|
|
23
|
+
callProcedure,
|
|
24
|
+
createRecursiveProxy,
|
|
25
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
23
26
|
import {
|
|
24
27
|
trpcInfiniteQueryOptions,
|
|
25
28
|
type TRPCInfiniteQueryOptions,
|
|
@@ -48,18 +51,18 @@ import {
|
|
|
48
51
|
|
|
49
52
|
export interface DecorateQueryKeyable {
|
|
50
53
|
/**
|
|
51
|
-
* Calculate the
|
|
54
|
+
* Calculate the TanStack Query Key for a Route
|
|
52
55
|
*
|
|
53
56
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
54
57
|
*/
|
|
55
58
|
queryKey: () => TRPCQueryKey;
|
|
56
59
|
|
|
57
60
|
/**
|
|
58
|
-
* Calculate a
|
|
61
|
+
* Calculate a TanStack Query Filter for a Route
|
|
59
62
|
*
|
|
60
63
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
61
64
|
*/
|
|
62
|
-
queryFilter: () => QueryFilters;
|
|
65
|
+
queryFilter: (input?: undefined, filters?: QueryFilters) => QueryFilters;
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
export type InferInput<
|
|
@@ -81,6 +84,7 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
81
84
|
'~types': {
|
|
82
85
|
input: TDef['input'];
|
|
83
86
|
output: TDef['output'];
|
|
87
|
+
errorShape: TDef['errorShape'];
|
|
84
88
|
};
|
|
85
89
|
|
|
86
90
|
/**
|
|
@@ -94,18 +98,28 @@ export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
|
94
98
|
infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
|
|
95
99
|
|
|
96
100
|
/**
|
|
97
|
-
* Calculate the
|
|
101
|
+
* Calculate the TanStack Query Key for a Query Procedure
|
|
98
102
|
*
|
|
99
103
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
100
104
|
*/
|
|
101
|
-
queryKey: (
|
|
105
|
+
queryKey: (
|
|
106
|
+
input?: TDef['input'],
|
|
107
|
+
) => DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>;
|
|
102
108
|
|
|
103
109
|
/**
|
|
104
|
-
* Calculate a
|
|
110
|
+
* Calculate a TanStack Query Filter for a Query Procedure
|
|
105
111
|
*
|
|
106
112
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
107
113
|
*/
|
|
108
|
-
queryFilter: (
|
|
114
|
+
queryFilter: (
|
|
115
|
+
input?: TDef['input'],
|
|
116
|
+
filters?: QueryFilters<TDef['output'], TDef['errorShape']>,
|
|
117
|
+
) => QueryFilters<
|
|
118
|
+
TDef['output'],
|
|
119
|
+
TDef['errorShape'],
|
|
120
|
+
TDef['output'],
|
|
121
|
+
DataTag<TRPCQueryKey, TDef['output'], TDef['errorShape']>
|
|
122
|
+
>;
|
|
109
123
|
}
|
|
110
124
|
|
|
111
125
|
export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
@@ -123,7 +137,7 @@ export interface DecorateMutationProcedure<TDef extends ResolverDef> {
|
|
|
123
137
|
mutationOptions: TRPCMutationOptions<TDef>;
|
|
124
138
|
|
|
125
139
|
/**
|
|
126
|
-
* Calculate the
|
|
140
|
+
* Calculate the TanStack Mutation Key for a Mutation Procedure
|
|
127
141
|
*/
|
|
128
142
|
mutationKey: () => TRPCMutationKey;
|
|
129
143
|
}
|
|
@@ -226,7 +240,7 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
226
240
|
if ('router' in opts) {
|
|
227
241
|
return Promise.resolve(unwrapLazyArg(opts.ctx)).then((ctx) =>
|
|
228
242
|
callProcedure({
|
|
229
|
-
|
|
243
|
+
router: opts.router,
|
|
230
244
|
path: path,
|
|
231
245
|
getRawInput: async () => input,
|
|
232
246
|
ctx: ctx,
|
|
@@ -250,8 +264,11 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
250
264
|
const utilName = path.pop() as UtilsMethods;
|
|
251
265
|
const [arg1, arg2] = args as any[];
|
|
252
266
|
|
|
253
|
-
|
|
254
|
-
|
|
267
|
+
function getQueryKey() {
|
|
268
|
+
const queryType = getQueryType(utilName);
|
|
269
|
+
|
|
270
|
+
return getQueryKeyInternal(path, arg1, queryType ?? 'any');
|
|
271
|
+
}
|
|
255
272
|
|
|
256
273
|
const contextMap: Record<UtilsMethods, () => unknown> = {
|
|
257
274
|
'~types': undefined as any,
|
|
@@ -260,11 +277,12 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
260
277
|
return getMutationKeyInternal(path);
|
|
261
278
|
},
|
|
262
279
|
queryKey: () => {
|
|
263
|
-
return
|
|
280
|
+
return getQueryKey();
|
|
264
281
|
},
|
|
265
282
|
queryFilter: (): QueryFilters => {
|
|
266
283
|
return {
|
|
267
|
-
|
|
284
|
+
...arg2,
|
|
285
|
+
queryKey: getQueryKey(),
|
|
268
286
|
};
|
|
269
287
|
},
|
|
270
288
|
infiniteQueryOptions: () => {
|
|
@@ -272,7 +290,7 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
272
290
|
opts: arg2,
|
|
273
291
|
path,
|
|
274
292
|
queryClient: opts.queryClient,
|
|
275
|
-
queryKey:
|
|
293
|
+
queryKey: getQueryKey(),
|
|
276
294
|
query: callIt('query'),
|
|
277
295
|
});
|
|
278
296
|
},
|
|
@@ -281,7 +299,7 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
281
299
|
opts: arg2,
|
|
282
300
|
path,
|
|
283
301
|
queryClient: opts.queryClient,
|
|
284
|
-
queryKey:
|
|
302
|
+
queryKey: getQueryKey(),
|
|
285
303
|
query: callIt('query'),
|
|
286
304
|
});
|
|
287
305
|
},
|
|
@@ -298,7 +316,7 @@ export function createTRPCOptionsProxy<TRouter extends AnyRouter>(
|
|
|
298
316
|
return trpcSubscriptionOptions({
|
|
299
317
|
opts: arg2,
|
|
300
318
|
path,
|
|
301
|
-
queryKey:
|
|
319
|
+
queryKey: getQueryKey(),
|
|
302
320
|
subscribe: callIt('subscription'),
|
|
303
321
|
});
|
|
304
322
|
},
|
|
@@ -65,7 +65,7 @@ interface UndefinedTRPCInfiniteQueryOptionsOut<
|
|
|
65
65
|
'initialPageParam'
|
|
66
66
|
>,
|
|
67
67
|
TRPCQueryOptionsResult {
|
|
68
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
68
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
69
69
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -100,7 +100,7 @@ interface DefinedTRPCInfiniteQueryOptionsOut<
|
|
|
100
100
|
'initialPageParam'
|
|
101
101
|
>,
|
|
102
102
|
TRPCQueryOptionsResult {
|
|
103
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
103
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
104
104
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -139,7 +139,7 @@ interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
|
|
139
139
|
'initialPageParam'
|
|
140
140
|
>,
|
|
141
141
|
TRPCQueryOptionsResult {
|
|
142
|
-
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
142
|
+
queryKey: DataTag<TRPCQueryKey, TData, TError>;
|
|
143
143
|
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -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;
|
|
@@ -48,7 +48,7 @@ interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError>
|
|
|
48
48
|
TRPCQueryKey
|
|
49
49
|
>,
|
|
50
50
|
TRPCQueryOptionsResult {
|
|
51
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput
|
|
51
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
@@ -71,7 +71,7 @@ interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError>
|
|
|
71
71
|
TRPCQueryKey
|
|
72
72
|
>,
|
|
73
73
|
TRPCQueryOptionsResult {
|
|
74
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData
|
|
74
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>, TError>;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
interface UnusedSkipTokenTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
@@ -94,7 +94,7 @@ interface UnusedSkipTokenTRPCQueryOptionsOut<TQueryFnData, TOutput, TError>
|
|
|
94
94
|
TRPCQueryKey
|
|
95
95
|
>,
|
|
96
96
|
TRPCQueryOptionsResult {
|
|
97
|
-
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput
|
|
97
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>, TError>;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export interface TRPCQueryOptions<TDef extends ResolverDef> {
|
|
@@ -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
|
|