@trpc/react-query 10.0.0-rc.1 → 10.0.0-rc.3
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/dist/{createHooksInternal-e8214d72.js → createHooksInternal-6618ba4a.js} +14 -4
- package/dist/{createHooksInternal-b47ee704.mjs → createHooksInternal-92c57b9a.mjs} +14 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/shared/index.mjs +1 -1
- package/dist/shared/types.d.ts +11 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/shared/hooks/createHooksInternal.tsx +11 -4
- package/src/shared/types.ts +11 -0
|
@@ -128,7 +128,8 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
128
128
|
* @internal
|
|
129
129
|
*/ function createHooksInternal(config) {
|
|
130
130
|
const mutationSuccessOverride = config?.unstable_overrides?.useMutation?.onSuccess ?? ((options)=>options.originalFn());
|
|
131
|
-
const Context = TRPCContext;
|
|
131
|
+
const Context = config?.context ?? TRPCContext;
|
|
132
|
+
const ReactQueryContext = config?.reactQueryContext;
|
|
132
133
|
const createClient = (opts)=>{
|
|
133
134
|
return client.createTRPCClient(opts);
|
|
134
135
|
};
|
|
@@ -267,7 +268,10 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
267
268
|
}
|
|
268
269
|
};
|
|
269
270
|
return client.query(...getClientArgs(pathAndInput, actualOpts));
|
|
270
|
-
},
|
|
271
|
+
}, {
|
|
272
|
+
context: ReactQueryContext,
|
|
273
|
+
...ssrOpts
|
|
274
|
+
});
|
|
271
275
|
hook.trpc = useHookResult({
|
|
272
276
|
path: pathAndInput[0]
|
|
273
277
|
});
|
|
@@ -275,7 +279,9 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
275
279
|
}
|
|
276
280
|
function useMutation(path, opts) {
|
|
277
281
|
const { client } = useContext();
|
|
278
|
-
const queryClient = reactQuery.useQueryClient(
|
|
282
|
+
const queryClient = reactQuery.useQueryClient({
|
|
283
|
+
context: ReactQueryContext
|
|
284
|
+
});
|
|
279
285
|
const hook = reactQuery.useMutation((input)=>{
|
|
280
286
|
const actualPath = Array.isArray(path) ? path[0] : path;
|
|
281
287
|
return client.mutation(...getClientArgs([
|
|
@@ -283,6 +289,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
283
289
|
input
|
|
284
290
|
], opts));
|
|
285
291
|
}, {
|
|
292
|
+
context: ReactQueryContext,
|
|
286
293
|
...opts,
|
|
287
294
|
onSuccess (...args) {
|
|
288
295
|
const originalFn = ()=>opts?.onSuccess?.(...args);
|
|
@@ -365,7 +372,10 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
365
372
|
path,
|
|
366
373
|
actualInput
|
|
367
374
|
], actualOpts));
|
|
368
|
-
},
|
|
375
|
+
}, {
|
|
376
|
+
context: ReactQueryContext,
|
|
377
|
+
...ssrOpts
|
|
378
|
+
});
|
|
369
379
|
hook.trpc = useHookResult({
|
|
370
380
|
path
|
|
371
381
|
});
|
|
@@ -122,7 +122,8 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
122
122
|
* @internal
|
|
123
123
|
*/ function createHooksInternal(config) {
|
|
124
124
|
const mutationSuccessOverride = config?.unstable_overrides?.useMutation?.onSuccess ?? ((options)=>options.originalFn());
|
|
125
|
-
const Context = TRPCContext;
|
|
125
|
+
const Context = config?.context ?? TRPCContext;
|
|
126
|
+
const ReactQueryContext = config?.reactQueryContext;
|
|
126
127
|
const createClient = (opts)=>{
|
|
127
128
|
return createTRPCClient(opts);
|
|
128
129
|
};
|
|
@@ -261,7 +262,10 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
261
262
|
}
|
|
262
263
|
};
|
|
263
264
|
return client.query(...getClientArgs(pathAndInput, actualOpts));
|
|
264
|
-
},
|
|
265
|
+
}, {
|
|
266
|
+
context: ReactQueryContext,
|
|
267
|
+
...ssrOpts
|
|
268
|
+
});
|
|
265
269
|
hook.trpc = useHookResult({
|
|
266
270
|
path: pathAndInput[0]
|
|
267
271
|
});
|
|
@@ -269,7 +273,9 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
269
273
|
}
|
|
270
274
|
function useMutation$1(path, opts) {
|
|
271
275
|
const { client } = useContext();
|
|
272
|
-
const queryClient = useQueryClient(
|
|
276
|
+
const queryClient = useQueryClient({
|
|
277
|
+
context: ReactQueryContext
|
|
278
|
+
});
|
|
273
279
|
const hook = useMutation((input)=>{
|
|
274
280
|
const actualPath = Array.isArray(path) ? path[0] : path;
|
|
275
281
|
return client.mutation(...getClientArgs([
|
|
@@ -277,6 +283,7 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
277
283
|
input
|
|
278
284
|
], opts));
|
|
279
285
|
}, {
|
|
286
|
+
context: ReactQueryContext,
|
|
280
287
|
...opts,
|
|
281
288
|
onSuccess (...args) {
|
|
282
289
|
const originalFn = ()=>opts?.onSuccess?.(...args);
|
|
@@ -359,7 +366,10 @@ function getClientArgs(pathAndInput, opts) {
|
|
|
359
366
|
path,
|
|
360
367
|
actualInput
|
|
361
368
|
], actualOpts));
|
|
362
|
-
},
|
|
369
|
+
}, {
|
|
370
|
+
context: ReactQueryContext,
|
|
371
|
+
...ssrOpts
|
|
372
|
+
});
|
|
363
373
|
hook.trpc = useHookResult({
|
|
364
374
|
path
|
|
365
375
|
});
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var client = require('@trpc/client');
|
|
6
6
|
var shared = require('@trpc/server/shared');
|
|
7
7
|
var React = require('react');
|
|
8
|
-
var createHooksInternal = require('./createHooksInternal-
|
|
8
|
+
var createHooksInternal = require('./createHooksInternal-6618ba4a.js');
|
|
9
9
|
require('@tanstack/react-query');
|
|
10
10
|
require('./getArrayQueryKey-a2092b3c.js');
|
|
11
11
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
2
|
import { createFlatProxy } from '@trpc/server/shared';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
|
-
import { c as createHooksInternal, a as createReactQueryUtilsProxy, b as createReactProxyDecoration } from './createHooksInternal-
|
|
4
|
+
import { c as createHooksInternal, a as createReactQueryUtilsProxy, b as createReactProxyDecoration } from './createHooksInternal-92c57b9a.mjs';
|
|
5
5
|
import '@tanstack/react-query';
|
|
6
6
|
import './getArrayQueryKey-062214e0.mjs';
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../../../packages/react-query/src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../../../packages/react-query/src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAEf,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,cAAc,EAMf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAEnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAc,EACZ,SAAS,EAMV,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AAEvE,oBAAY,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG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AC,KAAK,EAAE,MAAM,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,GAC3E,cAAc,CAAC;AAEjB;;GAEG;AACH,oBAAY,0BAA0B,CAAC,KAAK,EAAE,MAAM,IAAI,sBAAsB,CAC5E,KAAK,EACL,MAAM,CACP,GACC,cAAc,CAAC;AAEjB;;GAEG;AACH,oBAAY,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,IACnE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC;AAU1E;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;;;;;;EAoczC;AAED;;;GAGG;AACH,cAAM,OAAO,CAAC,OAAO,SAAS,SAAS,EAAE,WAAW,GAAG,OAAO;IAC5D,EAAE;;;;;;;;;;CAGH;AAED,aAAK,iBAAiB,CAAC,KAAK,IAAI,KAAK,SAAS,CAC5C,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACtB,MAAM,CAAC,GACR,CAAC,GACD,KAAK,CAAC;AACV,aAAK,OAAO,CAAC,OAAO,SAAS,SAAS,EAAE,WAAW,GAAG,OAAO,IAAI,OAAO,CACtE,OAAO,EACP,WAAW,CACZ,CAAC,IAAI,CAAC,CAAC;AAER;;;GAGG;AACH,oBAAY,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,IACnB,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC"}
|
package/dist/shared/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var createHooksInternal = require('../createHooksInternal-
|
|
5
|
+
var createHooksInternal = require('../createHooksInternal-6618ba4a.js');
|
|
6
6
|
var queryClient = require('../queryClient-83576230.js');
|
|
7
7
|
require('@trpc/server/shared');
|
|
8
8
|
require('@tanstack/react-query');
|
package/dist/shared/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as createHooksInternal, b as createReactProxyDecoration, a as createReactQueryUtilsProxy } from '../createHooksInternal-
|
|
1
|
+
export { c as createHooksInternal, b as createReactProxyDecoration, a as createReactQueryUtilsProxy } from '../createHooksInternal-92c57b9a.mjs';
|
|
2
2
|
export { g as getQueryClient } from '../queryClient-0569f6e0.mjs';
|
|
3
3
|
import '@trpc/server/shared';
|
|
4
4
|
import '@tanstack/react-query';
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { AnyRouter, MaybePromise } from '@trpc/server';
|
|
3
4
|
/**
|
|
@@ -22,5 +23,15 @@ export interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
|
|
22
23
|
unstable_overrides?: {
|
|
23
24
|
useMutation?: Partial<UseMutationOverride>;
|
|
24
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Override the default context provider
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
context?: React.Context<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Override the default React Query context
|
|
33
|
+
* @default undefined
|
|
34
|
+
*/
|
|
35
|
+
reactQueryContext?: React.Context<QueryClient | undefined>;
|
|
25
36
|
}
|
|
26
37
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/react-query/src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,QAAQ,SAAS,SAAS;IAChE;;OAEG;IACH,kBAAkB,CAAC,EAAE;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;KAC5C,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/react-query/src/shared/types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,CAAC,IAAI,EAAE;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;QACxC,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,QAAQ,SAAS,SAAS;IAChE;;OAEG;IACH,kBAAkB,CAAC,EAAE;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;KAC5C,CAAC;IAEF;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;CAC5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "10.0.0-rc.
|
|
3
|
+
"version": "10.0.0-rc.3",
|
|
4
4
|
"description": "tRPC React lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@tanstack/react-query": "^4.3.8",
|
|
54
|
-
"@trpc/client": "10.0.0-rc.
|
|
55
|
-
"@trpc/server": "10.0.0-rc.
|
|
54
|
+
"@trpc/client": "10.0.0-rc.3",
|
|
55
|
+
"@trpc/server": "10.0.0-rc.3",
|
|
56
56
|
"react": ">=16.8.0",
|
|
57
57
|
"react-dom": ">=16.8.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@tanstack/react-query": "^4.3.8",
|
|
61
|
-
"@trpc/client": "10.0.0-rc.
|
|
62
|
-
"@trpc/server": "10.0.0-rc.
|
|
61
|
+
"@trpc/client": "10.0.0-rc.3",
|
|
62
|
+
"@trpc/server": "10.0.0-rc.3",
|
|
63
63
|
"@types/express": "^4.17.12",
|
|
64
64
|
"@types/node": "^18.7.20",
|
|
65
65
|
"express": "^4.17.1",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "14aa82ef679172aaa41611eff48ed0cc1199c056"
|
|
75
75
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import {
|
|
3
3
|
DehydratedState,
|
|
4
|
+
QueryClient,
|
|
4
5
|
UseInfiniteQueryOptions,
|
|
5
6
|
UseInfiniteQueryResult,
|
|
6
7
|
UseMutationOptions,
|
|
@@ -202,7 +203,12 @@ export function createHooksInternal<
|
|
|
202
203
|
type TMutationValues = inferProcedures<TMutations>;
|
|
203
204
|
|
|
204
205
|
type ProviderContext = TRPCContextState<TRouter, TSSRContext>;
|
|
205
|
-
|
|
206
|
+
|
|
207
|
+
const Context = (config?.context ??
|
|
208
|
+
TRPCContext) as React.Context<ProviderContext>;
|
|
209
|
+
const ReactQueryContext = config?.reactQueryContext as React.Context<
|
|
210
|
+
QueryClient | undefined
|
|
211
|
+
>;
|
|
206
212
|
|
|
207
213
|
const createClient: CreateClient<TRouter> = (opts) => {
|
|
208
214
|
return createTRPCClient(opts);
|
|
@@ -425,7 +431,7 @@ export function createHooksInternal<
|
|
|
425
431
|
...getClientArgs(pathAndInput, actualOpts),
|
|
426
432
|
);
|
|
427
433
|
},
|
|
428
|
-
ssrOpts,
|
|
434
|
+
{ context: ReactQueryContext, ...ssrOpts },
|
|
429
435
|
) as UseTRPCQueryResult<TData, TError>;
|
|
430
436
|
hook.trpc = useHookResult({
|
|
431
437
|
path: pathAndInput[0],
|
|
@@ -452,7 +458,7 @@ export function createHooksInternal<
|
|
|
452
458
|
TContext
|
|
453
459
|
> {
|
|
454
460
|
const { client } = useContext();
|
|
455
|
-
const queryClient = useQueryClient();
|
|
461
|
+
const queryClient = useQueryClient({ context: ReactQueryContext });
|
|
456
462
|
|
|
457
463
|
const hook = __useMutation(
|
|
458
464
|
(input) => {
|
|
@@ -463,6 +469,7 @@ export function createHooksInternal<
|
|
|
463
469
|
);
|
|
464
470
|
},
|
|
465
471
|
{
|
|
472
|
+
context: ReactQueryContext,
|
|
466
473
|
...opts,
|
|
467
474
|
onSuccess(...args) {
|
|
468
475
|
const originalFn = () => opts?.onSuccess?.(...args);
|
|
@@ -600,7 +607,7 @@ export function createHooksInternal<
|
|
|
600
607
|
...getClientArgs([path, actualInput], actualOpts),
|
|
601
608
|
);
|
|
602
609
|
},
|
|
603
|
-
ssrOpts,
|
|
610
|
+
{ context: ReactQueryContext, ...ssrOpts },
|
|
604
611
|
) as UseTRPCInfiniteQueryResult<TQueryValues[TPath]['output'], TError>;
|
|
605
612
|
|
|
606
613
|
hook.trpc = useHookResult({
|
package/src/shared/types.ts
CHANGED
|
@@ -24,4 +24,15 @@ export interface CreateTRPCReactOptions<_TRouter extends AnyRouter> {
|
|
|
24
24
|
unstable_overrides?: {
|
|
25
25
|
useMutation?: Partial<UseMutationOverride>;
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Override the default context provider
|
|
30
|
+
* @default undefined
|
|
31
|
+
*/
|
|
32
|
+
context?: React.Context<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Override the default React Query context
|
|
35
|
+
* @default undefined
|
|
36
|
+
*/
|
|
37
|
+
reactQueryContext?: React.Context<QueryClient | undefined>;
|
|
27
38
|
}
|