@trpc/react-query 10.0.0-proxy-beta.21

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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/createHooksInternal-b47ee704.mjs +392 -0
  4. package/dist/createHooksInternal-e8214d72.js +400 -0
  5. package/dist/createTRPCReact.d.ts +38 -0
  6. package/dist/createTRPCReact.d.ts.map +1 -0
  7. package/dist/getArrayQueryKey-062214e0.mjs +19 -0
  8. package/dist/getArrayQueryKey-a2092b3c.js +21 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +58 -0
  12. package/dist/index.mjs +47 -0
  13. package/dist/internals/context.d.ts +99 -0
  14. package/dist/internals/context.d.ts.map +1 -0
  15. package/dist/internals/getArrayQueryKey.d.ts +9 -0
  16. package/dist/internals/getArrayQueryKey.d.ts.map +1 -0
  17. package/dist/internals/getQueryKey.d.ts +6 -0
  18. package/dist/internals/getQueryKey.d.ts.map +1 -0
  19. package/dist/interop.d.ts +10 -0
  20. package/dist/interop.d.ts.map +1 -0
  21. package/dist/queryClient-0569f6e0.mjs +7 -0
  22. package/dist/queryClient-83576230.js +9 -0
  23. package/dist/shared/hooks/createHooksInternal.d.ts +115 -0
  24. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -0
  25. package/dist/shared/index.d.ts +6 -0
  26. package/dist/shared/index.d.ts.map +1 -0
  27. package/dist/shared/index.js +18 -0
  28. package/dist/shared/index.mjs +7 -0
  29. package/dist/shared/proxy/decorationProxy.d.ts +8 -0
  30. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -0
  31. package/dist/shared/proxy/utilsProxy.d.ts +80 -0
  32. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -0
  33. package/dist/shared/queryClient.d.ts +16 -0
  34. package/dist/shared/queryClient.d.ts.map +1 -0
  35. package/dist/shared/types.d.ts +26 -0
  36. package/dist/shared/types.d.ts.map +1 -0
  37. package/dist/ssg/index.d.ts +5 -0
  38. package/dist/ssg/index.d.ts.map +1 -0
  39. package/dist/ssg/index.js +126 -0
  40. package/dist/ssg/index.mjs +121 -0
  41. package/dist/ssg/ssg.d.ts +23 -0
  42. package/dist/ssg/ssg.d.ts.map +1 -0
  43. package/dist/ssg/ssgProxy.d.ts +36 -0
  44. package/dist/ssg/ssgProxy.d.ts.map +1 -0
  45. package/package.json +75 -0
  46. package/shared/index.d.ts +1 -0
  47. package/shared/index.js +1 -0
  48. package/src/createTRPCReact.tsx +164 -0
  49. package/src/index.ts +4 -0
  50. package/src/internals/context.tsx +235 -0
  51. package/src/internals/getArrayQueryKey.test.ts +41 -0
  52. package/src/internals/getArrayQueryKey.ts +18 -0
  53. package/src/internals/getQueryKey.ts +10 -0
  54. package/src/interop.ts +25 -0
  55. package/src/shared/hooks/createHooksInternal.tsx +664 -0
  56. package/src/shared/index.ts +8 -0
  57. package/src/shared/proxy/decorationProxy.ts +33 -0
  58. package/src/shared/proxy/utilsProxy.ts +266 -0
  59. package/src/shared/queryClient.ts +20 -0
  60. package/src/shared/types.ts +27 -0
  61. package/src/ssg/index.ts +4 -0
  62. package/src/ssg/ssg.ts +138 -0
  63. package/src/ssg/ssgProxy.ts +105 -0
  64. package/ssg/index.d.ts +1 -0
  65. package/ssg/index.js +1 -0
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var reactQuery = require('@tanstack/react-query');
6
+ var server = require('@trpc/server');
7
+ var getArrayQueryKey = require('../getArrayQueryKey-a2092b3c.js');
8
+ var shared = require('@trpc/server/shared');
9
+ require('react');
10
+ require('@trpc/client');
11
+ var queryClient = require('../queryClient-83576230.js');
12
+
13
+ /**
14
+ * Create functions you can use for server-side rendering / static generation
15
+ * @deprecated use `createProxySSGHelpers` instead
16
+ */ function createSSGHelpers(opts) {
17
+ const { router , transformer , ctx } = opts;
18
+ const queryClient$1 = queryClient.getQueryClient(opts);
19
+ const serialize = transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj;
20
+ const prefetchQuery = async (...pathAndInput)=>{
21
+ return queryClient$1.prefetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
22
+ return server.callProcedure({
23
+ procedures: router._def.procedures,
24
+ path: pathAndInput[0],
25
+ rawInput: pathAndInput[1],
26
+ ctx,
27
+ type: 'query'
28
+ });
29
+ });
30
+ };
31
+ const prefetchInfiniteQuery = async (...pathAndInput)=>{
32
+ return queryClient$1.prefetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
33
+ return server.callProcedure({
34
+ procedures: router._def.procedures,
35
+ path: pathAndInput[0],
36
+ rawInput: pathAndInput[1],
37
+ ctx,
38
+ type: 'query'
39
+ });
40
+ });
41
+ };
42
+ const fetchQuery = async (...pathAndInput)=>{
43
+ return queryClient$1.fetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
44
+ return server.callProcedure({
45
+ procedures: router._def.procedures,
46
+ path: pathAndInput[0],
47
+ rawInput: pathAndInput[1],
48
+ ctx,
49
+ type: 'query'
50
+ });
51
+ });
52
+ };
53
+ const fetchInfiniteQuery = async (...pathAndInput)=>{
54
+ return queryClient$1.fetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
55
+ return server.callProcedure({
56
+ procedures: router._def.procedures,
57
+ path: pathAndInput[0],
58
+ rawInput: pathAndInput[1],
59
+ ctx,
60
+ type: 'query'
61
+ });
62
+ });
63
+ };
64
+ function _dehydrate(opts = {
65
+ shouldDehydrateQuery () {
66
+ // makes sure to serialize errors
67
+ return true;
68
+ }
69
+ }) {
70
+ const before = reactQuery.dehydrate(queryClient$1, opts);
71
+ const after = serialize(before);
72
+ return after;
73
+ }
74
+ return {
75
+ prefetchQuery,
76
+ prefetchInfiniteQuery,
77
+ fetchQuery,
78
+ fetchInfiniteQuery,
79
+ dehydrate: _dehydrate,
80
+ queryClient: queryClient$1
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Create functions you can use for server-side rendering / static generation
86
+ */ function createProxySSGHelpers(opts) {
87
+ const helpers = createSSGHelpers(opts);
88
+ return shared.createFlatProxy((key)=>{
89
+ if (key === 'queryClient') {
90
+ return helpers.queryClient;
91
+ }
92
+ if (key === 'dehydrate') {
93
+ return helpers.dehydrate;
94
+ }
95
+ return shared.createRecursiveProxy((opts)=>{
96
+ const args = opts.args;
97
+ const pathCopy = [
98
+ key,
99
+ ...opts.path
100
+ ];
101
+ const utilName = pathCopy.pop();
102
+ const fullPath = pathCopy.join('.');
103
+ switch(utilName){
104
+ case 'fetch':
105
+ {
106
+ return helpers.fetchQuery(fullPath, ...args);
107
+ }
108
+ case 'fetchInfinite':
109
+ {
110
+ return helpers.fetchInfiniteQuery(fullPath, ...args);
111
+ }
112
+ case 'prefetch':
113
+ {
114
+ return helpers.prefetchQuery(fullPath, ...args);
115
+ }
116
+ case 'prefetchInfinite':
117
+ {
118
+ return helpers.prefetchInfiniteQuery(fullPath, ...args);
119
+ }
120
+ }
121
+ });
122
+ });
123
+ }
124
+
125
+ exports.createProxySSGHelpers = createProxySSGHelpers;
126
+ exports.createSSGHelpers = createSSGHelpers;
@@ -0,0 +1,121 @@
1
+ import { dehydrate } from '@tanstack/react-query';
2
+ import { callProcedure } from '@trpc/server';
3
+ import { g as getArrayQueryKey } from '../getArrayQueryKey-062214e0.mjs';
4
+ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
5
+ import 'react';
6
+ import '@trpc/client';
7
+ import { g as getQueryClient } from '../queryClient-0569f6e0.mjs';
8
+
9
+ /**
10
+ * Create functions you can use for server-side rendering / static generation
11
+ * @deprecated use `createProxySSGHelpers` instead
12
+ */ function createSSGHelpers(opts) {
13
+ const { router , transformer , ctx } = opts;
14
+ const queryClient = getQueryClient(opts);
15
+ const serialize = transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj;
16
+ const prefetchQuery = async (...pathAndInput)=>{
17
+ return queryClient.prefetchQuery(getArrayQueryKey(pathAndInput), ()=>{
18
+ return callProcedure({
19
+ procedures: router._def.procedures,
20
+ path: pathAndInput[0],
21
+ rawInput: pathAndInput[1],
22
+ ctx,
23
+ type: 'query'
24
+ });
25
+ });
26
+ };
27
+ const prefetchInfiniteQuery = async (...pathAndInput)=>{
28
+ return queryClient.prefetchInfiniteQuery(getArrayQueryKey(pathAndInput), ()=>{
29
+ return callProcedure({
30
+ procedures: router._def.procedures,
31
+ path: pathAndInput[0],
32
+ rawInput: pathAndInput[1],
33
+ ctx,
34
+ type: 'query'
35
+ });
36
+ });
37
+ };
38
+ const fetchQuery = async (...pathAndInput)=>{
39
+ return queryClient.fetchQuery(getArrayQueryKey(pathAndInput), ()=>{
40
+ return callProcedure({
41
+ procedures: router._def.procedures,
42
+ path: pathAndInput[0],
43
+ rawInput: pathAndInput[1],
44
+ ctx,
45
+ type: 'query'
46
+ });
47
+ });
48
+ };
49
+ const fetchInfiniteQuery = async (...pathAndInput)=>{
50
+ return queryClient.fetchInfiniteQuery(getArrayQueryKey(pathAndInput), ()=>{
51
+ return callProcedure({
52
+ procedures: router._def.procedures,
53
+ path: pathAndInput[0],
54
+ rawInput: pathAndInput[1],
55
+ ctx,
56
+ type: 'query'
57
+ });
58
+ });
59
+ };
60
+ function _dehydrate(opts = {
61
+ shouldDehydrateQuery () {
62
+ // makes sure to serialize errors
63
+ return true;
64
+ }
65
+ }) {
66
+ const before = dehydrate(queryClient, opts);
67
+ const after = serialize(before);
68
+ return after;
69
+ }
70
+ return {
71
+ prefetchQuery,
72
+ prefetchInfiniteQuery,
73
+ fetchQuery,
74
+ fetchInfiniteQuery,
75
+ dehydrate: _dehydrate,
76
+ queryClient
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Create functions you can use for server-side rendering / static generation
82
+ */ function createProxySSGHelpers(opts) {
83
+ const helpers = createSSGHelpers(opts);
84
+ return createFlatProxy((key)=>{
85
+ if (key === 'queryClient') {
86
+ return helpers.queryClient;
87
+ }
88
+ if (key === 'dehydrate') {
89
+ return helpers.dehydrate;
90
+ }
91
+ return createRecursiveProxy((opts)=>{
92
+ const args = opts.args;
93
+ const pathCopy = [
94
+ key,
95
+ ...opts.path
96
+ ];
97
+ const utilName = pathCopy.pop();
98
+ const fullPath = pathCopy.join('.');
99
+ switch(utilName){
100
+ case 'fetch':
101
+ {
102
+ return helpers.fetchQuery(fullPath, ...args);
103
+ }
104
+ case 'fetchInfinite':
105
+ {
106
+ return helpers.fetchInfiniteQuery(fullPath, ...args);
107
+ }
108
+ case 'prefetch':
109
+ {
110
+ return helpers.prefetchQuery(fullPath, ...args);
111
+ }
112
+ case 'prefetchInfinite':
113
+ {
114
+ return helpers.prefetchInfiniteQuery(fullPath, ...args);
115
+ }
116
+ }
117
+ });
118
+ });
119
+ }
120
+
121
+ export { createProxySSGHelpers, createSSGHelpers };
@@ -0,0 +1,23 @@
1
+ import { DehydrateOptions, DehydratedState, InfiniteData } from '@tanstack/react-query';
2
+ import { AnyRouter, ClientDataTransformerOptions, inferProcedureOutput, inferRouterContext } from '@trpc/server';
3
+ import { CreateTRPCReactQueryClientConfig } from '../shared';
4
+ interface CreateSSGHelpersOptionsBase<TRouter extends AnyRouter> {
5
+ router: TRouter;
6
+ ctx: inferRouterContext<TRouter>;
7
+ transformer?: ClientDataTransformerOptions;
8
+ }
9
+ export declare type CreateSSGHelpersOptions<TRouter extends AnyRouter> = CreateSSGHelpersOptionsBase<TRouter> & CreateTRPCReactQueryClientConfig;
10
+ /**
11
+ * Create functions you can use for server-side rendering / static generation
12
+ * @deprecated use `createProxySSGHelpers` instead
13
+ */
14
+ export declare function createSSGHelpers<TRouter extends AnyRouter>(opts: CreateSSGHelpersOptions<TRouter>): {
15
+ prefetchQuery: <TPath extends keyof TRouter["_def"]["queries"] & string, TProcedure extends TRouter["_def"]["queries"][TPath]>(path: TPath, ...args: import("@trpc/server").ProcedureArgs<import("@trpc/server").inferProcedureParams<TProcedure>>) => Promise<void>;
16
+ prefetchInfiniteQuery: <TPath_1 extends keyof TRouter["_def"]["queries"] & string, TProcedure_1 extends TRouter["_def"]["queries"][TPath_1]>(path: TPath_1, ...args: import("@trpc/server").ProcedureArgs<import("@trpc/server").inferProcedureParams<TProcedure_1>>) => Promise<void>;
17
+ fetchQuery: <TPath_2 extends keyof TRouter["_def"]["queries"] & string, TProcedure_2 extends TRouter["_def"]["queries"][TPath_2], TOutput extends inferProcedureOutput<TProcedure_2>>(path: TPath_2, ...args: import("@trpc/server").ProcedureArgs<import("@trpc/server").inferProcedureParams<TProcedure_2>>) => Promise<TOutput>;
18
+ fetchInfiniteQuery: <TPath_3 extends keyof TRouter["_def"]["queries"] & string, TProcedure_3 extends TRouter["_def"]["queries"][TPath_3], TOutput_1 extends inferProcedureOutput<TProcedure_3>>(path: TPath_3, ...args: import("@trpc/server").ProcedureArgs<import("@trpc/server").inferProcedureParams<TProcedure_3>>) => Promise<InfiniteData<TOutput_1>>;
19
+ dehydrate: (opts?: DehydrateOptions) => DehydratedState;
20
+ queryClient: import("@tanstack/react-query").QueryClient;
21
+ };
22
+ export {};
23
+ //# sourceMappingURL=ssg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssg.d.ts","sourceRoot":"","sources":["../../../../packages/react-query/src/ssg/ssg.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,SAAS,EACT,4BAA4B,EAG5B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gCAAgC,EAAkB,MAAM,WAAW,CAAC;AAE7E,UAAU,2BAA2B,CAAC,OAAO,SAAS,SAAS;IAC7D,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AACD,oBAAY,uBAAuB,CAAC,OAAO,SAAS,SAAS,IAC3D,2BAA2B,CAAC,OAAO,CAAC,GAAG,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;;;;;uBAuF9B,gBAAgB,KAMrB,eAAe;;EAcnB"}
@@ -0,0 +1,36 @@
1
+ import { DehydrateOptions, DehydratedState, InfiniteData, QueryClient } from '@tanstack/react-query';
2
+ import { AnyProcedure, AnyQueryProcedure, AnyRouter, Filter, inferHandlerInput, inferProcedureOutput } from '@trpc/server';
3
+ import { CreateSSGHelpersOptions } from './ssg';
4
+ declare type DecorateProcedure<TProcedure extends AnyProcedure> = {
5
+ /**
6
+ * @link https://react-query.tanstack.com/guides/prefetching
7
+ */
8
+ fetch(...args: inferHandlerInput<TProcedure>): Promise<inferProcedureOutput<TProcedure>>;
9
+ /**
10
+ * @link https://react-query.tanstack.com/guides/prefetching
11
+ */
12
+ fetchInfinite(...args: inferHandlerInput<TProcedure>): Promise<InfiniteData<inferProcedureOutput<TProcedure>>>;
13
+ /**
14
+ * @link https://react-query.tanstack.com/guides/prefetching
15
+ */
16
+ prefetch(...args: inferHandlerInput<TProcedure>): Promise<void>;
17
+ /**
18
+ * @link https://react-query.tanstack.com/guides/prefetching
19
+ */
20
+ prefetchInfinite(...args: inferHandlerInput<TProcedure>): Promise<void>;
21
+ };
22
+ /**
23
+ * @internal
24
+ */
25
+ export declare type DecoratedProcedureSSGRecord<TRouter extends AnyRouter> = {
26
+ [TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? DecoratedProcedureSSGRecord<TRouter['_def']['record'][TKey]> : DecorateProcedure<TRouter['_def']['record'][TKey]>;
27
+ };
28
+ /**
29
+ * Create functions you can use for server-side rendering / static generation
30
+ */
31
+ export declare function createProxySSGHelpers<TRouter extends AnyRouter>(opts: CreateSSGHelpersOptions<TRouter>): {
32
+ queryClient: QueryClient;
33
+ dehydrate: (opts?: DehydrateOptions) => DehydratedState;
34
+ } & DecoratedProcedureSSGRecord<TRouter>;
35
+ export {};
36
+ //# sourceMappingURL=ssgProxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssgProxy.d.ts","sourceRoot":"","sources":["../../../../packages/react-query/src/ssg/ssgProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,MAAM,EACN,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,uBAAuB,EAAoB,MAAM,OAAO,CAAC;AAElE,aAAK,iBAAiB,CAAC,UAAU,SAAS,YAAY,IAAI;IACxD;;OAEG;IACH,KAAK,CACH,GAAG,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GACrC,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;IAE7C;;OAEG;IACH,aAAa,CACX,GAAG,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GACrC,OAAO,CAAC,YAAY,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAE3D;;OAEG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;OAEG;IACH,gBAAgB,CAAC,GAAG,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE,CAAC;AAEF;;GAEG;AACH,oBAAY,2BAA2B,CAAC,OAAO,SAAS,SAAS,IAAI;KAClE,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,SAAS,GAAG,iBAAiB,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAE5D,iBAAiB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;CACvD,CAAC;AAIF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;iBAKvB,WAAW;uBACL,gBAAgB,KAAK,eAAe;yCAoC1D"}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@trpc/react-query",
3
+ "version": "10.0.0-proxy-beta.21",
4
+ "description": "tRPC React lib",
5
+ "author": "KATT",
6
+ "license": "MIT",
7
+ "homepage": "https://trpc.io",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/trpc/trpc.git",
11
+ "directory": "packages/react"
12
+ },
13
+ "scripts": {
14
+ "ts-watch": "tsc --project tsconfig.watch.json"
15
+ },
16
+ "main": "dist/index.js",
17
+ "module": "dist/index.mjs",
18
+ "typings": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.js",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./ssg": {
26
+ "import": "./dist/ssg/index.mjs",
27
+ "require": "./dist/ssg/index.js",
28
+ "default": "./dist/ssg/index.js"
29
+ },
30
+ "./shared": {
31
+ "import": "./dist/shared/index.mjs",
32
+ "require": "./dist/shared/index.js",
33
+ "default": "./dist/shared/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src",
39
+ "README.md",
40
+ "ssg",
41
+ "shared"
42
+ ],
43
+ "eslintConfig": {
44
+ "rules": {
45
+ "react-hooks/exhaustive-deps": "error",
46
+ "no-restricted-imports": [
47
+ "error",
48
+ "@trpc/react-query"
49
+ ]
50
+ }
51
+ },
52
+ "peerDependencies": {
53
+ "@tanstack/react-query": "^4.3.8",
54
+ "@trpc/client": "10.0.0-proxy-beta.21",
55
+ "@trpc/server": "10.0.0-proxy-beta.21",
56
+ "react": ">=16.8.0",
57
+ "react-dom": ">=16.8.0"
58
+ },
59
+ "devDependencies": {
60
+ "@tanstack/react-query": "^4.3.8",
61
+ "@trpc/client": "10.0.0-proxy-beta.21",
62
+ "@trpc/server": "10.0.0-proxy-beta.21",
63
+ "@types/express": "^4.17.12",
64
+ "@types/node": "^18.7.20",
65
+ "express": "^4.17.1",
66
+ "next": "^12.3.1",
67
+ "react": "^18.2.0",
68
+ "react-dom": "^18.2.0",
69
+ "zod": "^3.0.0"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "gitHead": "fe59220aff5619507f2cf1a7bd9fd6a6489cc364"
75
+ }
@@ -0,0 +1 @@
1
+ export * from '../dist/shared';
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/shared');
@@ -0,0 +1,164 @@
1
+ import { TRPCClientErrorLike } from '@trpc/client';
2
+ import {
3
+ AnyMutationProcedure,
4
+ AnyProcedure,
5
+ AnyQueryProcedure,
6
+ AnyRouter,
7
+ AnySubscriptionProcedure,
8
+ ProcedureRouterRecord,
9
+ inferProcedureInput,
10
+ inferProcedureOutput,
11
+ } from '@trpc/server';
12
+ import { inferObservableValue } from '@trpc/server/observable';
13
+ import { createFlatProxy } from '@trpc/server/shared';
14
+ import { useMemo } from 'react';
15
+ import {
16
+ CreateReactUtilsProxy,
17
+ createReactProxyDecoration,
18
+ createReactQueryUtilsProxy,
19
+ } from './shared';
20
+ import {
21
+ CreateClient,
22
+ CreateReactQueryHooks,
23
+ TRPCProvider,
24
+ UseDehydratedState,
25
+ UseTRPCInfiniteQueryOptions,
26
+ UseTRPCInfiniteQueryResult,
27
+ UseTRPCMutationOptions,
28
+ UseTRPCMutationResult,
29
+ UseTRPCQueryOptions,
30
+ UseTRPCQueryResult,
31
+ UseTRPCSubscriptionOptions,
32
+ createHooksInternal,
33
+ } from './shared/hooks/createHooksInternal';
34
+ import { CreateTRPCReactOptions } from './shared/types';
35
+
36
+ /**
37
+ * @internal
38
+ */
39
+ export type DecorateProcedure<
40
+ TProcedure extends AnyProcedure,
41
+ TPath extends string,
42
+ > = TProcedure extends AnyQueryProcedure
43
+ ? {
44
+ useQuery: <
45
+ TQueryFnData = inferProcedureOutput<TProcedure>,
46
+ TData = inferProcedureOutput<TProcedure>,
47
+ >(
48
+ input: inferProcedureInput<TProcedure>,
49
+ opts?: UseTRPCQueryOptions<
50
+ TPath,
51
+ inferProcedureInput<TProcedure>,
52
+ TQueryFnData,
53
+ TData,
54
+ TRPCClientErrorLike<TProcedure>
55
+ >,
56
+ ) => UseTRPCQueryResult<TData, TRPCClientErrorLike<TProcedure>>;
57
+ } & (inferProcedureInput<TProcedure> extends { cursor?: any }
58
+ ? {
59
+ useInfiniteQuery: <
60
+ _TQueryFnData = inferProcedureOutput<TProcedure>,
61
+ TData = inferProcedureOutput<TProcedure>,
62
+ >(
63
+ input: Omit<inferProcedureInput<TProcedure>, 'cursor'>,
64
+ opts?: UseTRPCInfiniteQueryOptions<
65
+ TPath,
66
+ inferProcedureInput<TProcedure>,
67
+ TData,
68
+ TRPCClientErrorLike<TProcedure>
69
+ >,
70
+ ) => UseTRPCInfiniteQueryResult<
71
+ TData,
72
+ TRPCClientErrorLike<TProcedure>
73
+ >;
74
+ }
75
+ : {})
76
+ : TProcedure extends AnyMutationProcedure
77
+ ? {
78
+ useMutation: <TContext = unknown>(
79
+ opts?: UseTRPCMutationOptions<
80
+ inferProcedureInput<TProcedure>,
81
+ TRPCClientErrorLike<TProcedure>,
82
+ inferProcedureOutput<TProcedure>,
83
+ TContext
84
+ >,
85
+ ) => UseTRPCMutationResult<
86
+ inferProcedureOutput<TProcedure>,
87
+ TRPCClientErrorLike<TProcedure>,
88
+ inferProcedureInput<TProcedure>,
89
+ TContext
90
+ >;
91
+ }
92
+ : TProcedure extends AnySubscriptionProcedure
93
+ ? {
94
+ useSubscription: (
95
+ input: inferProcedureInput<TProcedure>,
96
+ opts?: UseTRPCSubscriptionOptions<
97
+ inferObservableValue<inferProcedureOutput<TProcedure>>,
98
+ TRPCClientErrorLike<TProcedure>
99
+ >,
100
+ ) => void;
101
+ }
102
+ : never;
103
+
104
+ /**
105
+ * @internal
106
+ */
107
+ export type DecoratedProcedureRecord<
108
+ TProcedures extends ProcedureRouterRecord,
109
+ TPath extends string = '',
110
+ > = {
111
+ [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
112
+ ? DecoratedProcedureRecord<
113
+ TProcedures[TKey]['_def']['record'],
114
+ `${TPath}${TKey & string}.`
115
+ >
116
+ : TProcedures[TKey] extends AnyProcedure
117
+ ? DecorateProcedure<TProcedures[TKey], `${TPath}${TKey & string}`>
118
+ : never;
119
+ };
120
+
121
+ export type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext> = {
122
+ useContext(): CreateReactUtilsProxy<TRouter, TSSRContext>;
123
+ Provider: TRPCProvider<TRouter, TSSRContext>;
124
+ createClient: CreateClient<TRouter>;
125
+ useDehydratedState: UseDehydratedState<TRouter>;
126
+ } & DecoratedProcedureRecord<TRouter['_def']['record']>;
127
+
128
+ /**
129
+ * @internal
130
+ */
131
+ export function createHooksInternalProxy<
132
+ TRouter extends AnyRouter,
133
+ TSSRContext = unknown,
134
+ >(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {
135
+ type CreateHooksInternalProxy = CreateTRPCReact<TRouter, TSSRContext>;
136
+
137
+ return createFlatProxy<CreateHooksInternalProxy>((key) => {
138
+ if (key === 'useContext') {
139
+ return () => {
140
+ const context = trpc.useContext();
141
+ // create a stable reference of the utils context
142
+ return useMemo(() => {
143
+ return (createReactQueryUtilsProxy as any)(context as any);
144
+ }, [context]);
145
+ };
146
+ }
147
+
148
+ if ((key as string) in trpc) {
149
+ return (trpc as any)[key];
150
+ }
151
+
152
+ return createReactProxyDecoration(key as string, trpc);
153
+ });
154
+ }
155
+
156
+ export function createTRPCReact<
157
+ TRouter extends AnyRouter,
158
+ TSSRContext = unknown,
159
+ >(opts?: CreateTRPCReactOptions<TRouter>) {
160
+ const hooks = createHooksInternal<TRouter, TSSRContext>(opts);
161
+ const proxy = createHooksInternalProxy<TRouter, TSSRContext>(hooks);
162
+
163
+ return proxy;
164
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from '@trpc/client';
2
+
3
+ export { createTRPCReact, type CreateTRPCReact } from './createTRPCReact';
4
+ export { createReactQueryHooks } from './interop';