@trpc/react-query 11.0.0-alpha-tmp-02-08-tmp.275 → 11.0.0-alpha-tmp-app-router-example.281

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/rsc.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { type QueryClient } from '@tanstack/react-query';
2
+ import { type AnyRouter, type inferProcedureInput, type RouterRecord } from '@trpc/server/unstable-core-do-not-import';
3
+ import type { AnyProcedure, inferProcedureOutput, RouterCaller, TypeError } from '@trpc/server/unstable-core-do-not-import';
4
+ import * as React from 'react';
5
+ type DecorateProcedure<TProcedure extends AnyProcedure> = (input: inferProcedureInput<TProcedure>) => Promise<inferProcedureOutput<TProcedure>>;
6
+ type DecorateRouterRecord<TRecord extends RouterRecord> = {
7
+ [TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure ? DecorateProcedure<TRecord[TKey]> : TRecord[TKey] extends RouterRecord ? DecorateRouterRecord<TRecord[TKey]> : never;
8
+ };
9
+ type Caller<TRouter extends AnyRouter> = ReturnType<RouterCaller<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
10
+ export declare function createHydrationHelpers<TRouter extends AnyRouter>(caller: AnyRouter extends TRouter ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'> : Caller<TRouter>, getQueryClient: () => QueryClient): {
11
+ trpc: DecorateRouterRecord<TRouter["_def"]["record"]>;
12
+ HydrateClient: (props: {
13
+ children: React.ReactNode;
14
+ }) => React.JSX.Element;
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=rsc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../src/rsc.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACV,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,iBAAiB,CAAC,UAAU,SAAS,YAAY,IAAI,CACxD,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,KACnC,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;AAE/C,KAAK,oBAAoB,CAAC,OAAO,SAAS,YAAY,IAAI;KACvD,IAAI,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,YAAY,GACvD,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,SAAS,YAAY,GAClC,oBAAoB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GACnC,KAAK;CACV,CAAC;AAEF,KAAK,MAAM,CAAC,OAAO,SAAS,SAAS,IAAI,UAAU,CACjD,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAC9E,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,MAAM,EAAE,SAAS,SAAS,OAAO,GAC7B,SAAS,CAAC,6DAA6D,CAAC,GACxE,MAAM,CAAC,OAAO,CAAC,EACnB,cAAc,EAAE,MAAM,WAAW;;2BAkBH;QAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;KAAE;EAW5D"}
package/dist/rsc.js ADDED
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var reactQuery = require('@tanstack/react-query');
4
+ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
+ var React = require('react');
6
+ var getQueryKey = require('./internals/getQueryKey.js');
7
+
8
+ function _interopNamespaceDefault(e) {
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
+
27
+ function createHydrationHelpers(caller, getQueryClient) {
28
+ const wrappedProxy = unstableCoreDoNotImport.createRecursiveProxy(async ({ path , args })=>{
29
+ const proc = path.reduce(// @ts-expect-error - ??
30
+ (acc, key)=>acc[key], caller);
31
+ const [input] = args;
32
+ const result = await proc(input);
33
+ const queryKey = getQueryKey.getQueryKeyInternal(path, input, 'query');
34
+ getQueryClient().setQueryData(queryKey, result);
35
+ return result;
36
+ });
37
+ function HydrateClient(props) {
38
+ const dehydratedState = reactQuery.dehydrate(getQueryClient()); // TODO: transform??
39
+ return /*#__PURE__*/ React__namespace.createElement(reactQuery.HydrationBoundary, {
40
+ state: dehydratedState
41
+ }, props.children);
42
+ }
43
+ return {
44
+ trpc: wrappedProxy,
45
+ HydrateClient
46
+ };
47
+ }
48
+
49
+ exports.createHydrationHelpers = createHydrationHelpers;
package/dist/rsc.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
2
+ import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
3
+ import * as React from 'react';
4
+ import { getQueryKeyInternal } from './internals/getQueryKey.mjs';
5
+
6
+ function createHydrationHelpers(caller, getQueryClient) {
7
+ const wrappedProxy = createRecursiveProxy(async ({ path , args })=>{
8
+ const proc = path.reduce(// @ts-expect-error - ??
9
+ (acc, key)=>acc[key], caller);
10
+ const [input] = args;
11
+ const result = await proc(input);
12
+ const queryKey = getQueryKeyInternal(path, input, 'query');
13
+ getQueryClient().setQueryData(queryKey, result);
14
+ return result;
15
+ });
16
+ function HydrateClient(props) {
17
+ const dehydratedState = dehydrate(getQueryClient()); // TODO: transform??
18
+ return /*#__PURE__*/ React.createElement(HydrationBoundary, {
19
+ state: dehydratedState
20
+ }, props.children);
21
+ }
22
+ return {
23
+ trpc: wrappedProxy,
24
+ HydrateClient
25
+ };
26
+ }
27
+
28
+ export { createHydrationHelpers };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "11.0.0-alpha-tmp-02-08-tmp.275+99017b9ae",
3
+ "version": "11.0.0-alpha-tmp-app-router-example.281+1b2ea2dd7",
4
4
  "description": "The tRPC React library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -27,6 +27,11 @@
27
27
  "require": "./dist/index.js",
28
28
  "default": "./dist/index.js"
29
29
  },
30
+ "./rsc": {
31
+ "import": "./dist/rsc.mjs",
32
+ "require": "./dist/rsc.js",
33
+ "default": "./dist/rsc.js"
34
+ },
30
35
  "./server": {
31
36
  "import": "./dist/server/index.mjs",
32
37
  "require": "./dist/server/index.js",
@@ -43,6 +48,7 @@
43
48
  "src",
44
49
  "README.md",
45
50
  "package.json",
51
+ "rsc",
46
52
  "server",
47
53
  "shared",
48
54
  "!**/*.test.*"
@@ -58,15 +64,15 @@
58
64
  },
59
65
  "peerDependencies": {
60
66
  "@tanstack/react-query": "^5.0.0",
61
- "@trpc/client": "11.0.0-alpha-tmp-02-08-tmp.275+99017b9ae",
62
- "@trpc/server": "11.0.0-alpha-tmp-02-08-tmp.275+99017b9ae",
67
+ "@trpc/client": "11.0.0-alpha-tmp-app-router-example.281+1b2ea2dd7",
68
+ "@trpc/server": "11.0.0-alpha-tmp-app-router-example.281+1b2ea2dd7",
63
69
  "react": ">=18.2.0",
64
70
  "react-dom": ">=18.2.0"
65
71
  },
66
72
  "devDependencies": {
67
73
  "@tanstack/react-query": "^5.0.0",
68
- "@trpc/client": "11.0.0-alpha-tmp-02-08-tmp.275+99017b9ae",
69
- "@trpc/server": "11.0.0-alpha-tmp-02-08-tmp.275+99017b9ae",
74
+ "@trpc/client": "11.0.0-alpha-tmp-app-router-example.281+1b2ea2dd7",
75
+ "@trpc/server": "11.0.0-alpha-tmp-app-router-example.281+1b2ea2dd7",
70
76
  "@types/express": "^4.17.17",
71
77
  "@types/node": "^20.10.0",
72
78
  "@types/react": "^18.2.33",
@@ -85,5 +91,5 @@
85
91
  "funding": [
86
92
  "https://trpc.io/sponsor"
87
93
  ],
88
- "gitHead": "99017b9ae645f34e37d0fa9281b27c02657493eb"
94
+ "gitHead": "1b2ea2dd7010e1964cb3b5d7f338179315b2c1be"
89
95
  }
package/rsc/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '../dist/rsc';
package/rsc/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/rsc');
package/src/rsc.tsx ADDED
@@ -0,0 +1,70 @@
1
+ import {
2
+ dehydrate,
3
+ HydrationBoundary,
4
+ type QueryClient,
5
+ } from '@tanstack/react-query';
6
+ import {
7
+ createRecursiveProxy,
8
+ type AnyRouter,
9
+ type inferProcedureInput,
10
+ type RouterRecord,
11
+ } from '@trpc/server/unstable-core-do-not-import';
12
+ import type {
13
+ AnyProcedure,
14
+ inferProcedureOutput,
15
+ RouterCaller,
16
+ TypeError,
17
+ } from '@trpc/server/unstable-core-do-not-import';
18
+ import * as React from 'react';
19
+ import { getQueryKeyInternal } from './internals/getQueryKey';
20
+
21
+ type DecorateProcedure<TProcedure extends AnyProcedure> = (
22
+ input: inferProcedureInput<TProcedure>,
23
+ ) => Promise<inferProcedureOutput<TProcedure>>;
24
+
25
+ type DecorateRouterRecord<TRecord extends RouterRecord> = {
26
+ [TKey in keyof TRecord]: TRecord[TKey] extends AnyProcedure
27
+ ? DecorateProcedure<TRecord[TKey]>
28
+ : TRecord[TKey] extends RouterRecord
29
+ ? DecorateRouterRecord<TRecord[TKey]>
30
+ : never;
31
+ };
32
+
33
+ type Caller<TRouter extends AnyRouter> = ReturnType<
34
+ RouterCaller<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>
35
+ >;
36
+
37
+ export function createHydrationHelpers<TRouter extends AnyRouter>(
38
+ caller: AnyRouter extends TRouter
39
+ ? TypeError<'Generic parameter missing in `createHydrationHelpers<HERE>`'>
40
+ : Caller<TRouter>,
41
+ getQueryClient: () => QueryClient,
42
+ ) {
43
+ const wrappedProxy = createRecursiveProxy(async ({ path, args }) => {
44
+ const proc = path.reduce(
45
+ // @ts-expect-error - ??
46
+ (acc, key) => acc[key],
47
+ caller,
48
+ ) as unknown as DecorateProcedure<AnyProcedure>;
49
+
50
+ const [input] = args;
51
+ const result = await proc(input);
52
+
53
+ const queryKey = getQueryKeyInternal(path, input, 'query');
54
+ getQueryClient().setQueryData(queryKey, result);
55
+
56
+ return result;
57
+ }) as DecorateRouterRecord<TRouter['_def']['record']>;
58
+
59
+ function HydrateClient(props: { children: React.ReactNode }) {
60
+ const dehydratedState = dehydrate(getQueryClient()); // TODO: transform??
61
+
62
+ return (
63
+ <HydrationBoundary state={dehydratedState}>
64
+ {props.children}
65
+ </HydrationBoundary>
66
+ );
67
+ }
68
+
69
+ return { trpc: wrappedProxy, HydrateClient };
70
+ }
@@ -1,240 +0,0 @@
1
- {
2
- "bundleSize": 27242,
3
- "bundleOrigSize": 60201,
4
- "bundleReduction": 54.75,
5
- "modules": [
6
- {
7
- "id": "/src/shared/hooks/createHooksInternal.tsx",
8
- "size": 12372,
9
- "origSize": 14404,
10
- "renderedExports": [
11
- "createRootHooks"
12
- ],
13
- "removedExports": [],
14
- "dependents": [
15
- "/src/createTRPCReact.tsx"
16
- ],
17
- "percent": 45.42,
18
- "reduction": 14.11
19
- },
20
- {
21
- "id": "/src/server/ssgProxy.ts",
22
- "size": 3673,
23
- "origSize": 7403,
24
- "renderedExports": [
25
- "createServerSideHelpers"
26
- ],
27
- "removedExports": [],
28
- "dependents": [
29
- "/src/server/index.ts"
30
- ],
31
- "percent": 13.48,
32
- "reduction": 50.38
33
- },
34
- {
35
- "id": "/src/utils/createUtilityFunctions.ts",
36
- "size": 3334,
37
- "origSize": 3725,
38
- "renderedExports": [
39
- "createUtilityFunctions"
40
- ],
41
- "removedExports": [],
42
- "dependents": [
43
- "/src/createTRPCQueryUtils.tsx",
44
- "/src/shared/hooks/createHooksInternal.tsx"
45
- ],
46
- "percent": 12.24,
47
- "reduction": 10.5
48
- },
49
- {
50
- "id": "/src/shared/proxy/utilsProxy.ts",
51
- "size": 2745,
52
- "origSize": 10534,
53
- "renderedExports": [
54
- "getQueryType",
55
- "createReactQueryUtils",
56
- "createQueryUtilsProxy"
57
- ],
58
- "removedExports": [],
59
- "dependents": [
60
- "/src/shared/index.ts"
61
- ],
62
- "percent": 10.08,
63
- "reduction": 73.94
64
- },
65
- {
66
- "id": "/src/internals/getQueryKey.ts",
67
- "size": 1894,
68
- "origSize": 3254,
69
- "renderedExports": [
70
- "getQueryKeyInternal",
71
- "getQueryKey"
72
- ],
73
- "removedExports": [],
74
- "dependents": [
75
- "/src/index.ts",
76
- "/src/server/ssgProxy.ts",
77
- "/src/shared/proxy/utilsProxy.ts",
78
- "/src/shared/proxy/useQueriesProxy.ts",
79
- "/src/shared/hooks/createHooksInternal.tsx"
80
- ],
81
- "percent": 6.95,
82
- "reduction": 41.79
83
- },
84
- {
85
- "id": "/src/createTRPCReact.tsx",
86
- "size": 850,
87
- "origSize": 7749,
88
- "renderedExports": [
89
- "createHooksInternal",
90
- "createTRPCReact"
91
- ],
92
- "removedExports": [],
93
- "dependents": [
94
- "/src/index.ts"
95
- ],
96
- "percent": 3.12,
97
- "reduction": 89.03
98
- },
99
- {
100
- "id": "/src/shared/proxy/decorationProxy.ts",
101
- "size": 806,
102
- "origSize": 1049,
103
- "renderedExports": [
104
- "createReactDecoration"
105
- ],
106
- "removedExports": [],
107
- "dependents": [
108
- "/src/shared/index.ts"
109
- ],
110
- "percent": 2.96,
111
- "reduction": 23.16
112
- },
113
- {
114
- "id": "/src/shared/proxy/useQueriesProxy.ts",
115
- "size": 569,
116
- "origSize": 3167,
117
- "renderedExports": [
118
- "createUseQueries"
119
- ],
120
- "removedExports": [],
121
- "dependents": [
122
- "/src/shared/index.ts",
123
- "/src/shared/hooks/createHooksInternal.tsx"
124
- ],
125
- "percent": 2.09,
126
- "reduction": 82.03
127
- },
128
- {
129
- "id": "/src/internals/getClientArgs.ts",
130
- "size": 332,
131
- "origSize": 402,
132
- "renderedExports": [
133
- "getClientArgs"
134
- ],
135
- "removedExports": [],
136
- "dependents": [
137
- "/src/shared/index.ts",
138
- "/src/shared/hooks/createHooksInternal.tsx",
139
- "/src/utils/createUtilityFunctions.ts"
140
- ],
141
- "percent": 1.22,
142
- "reduction": 17.41
143
- },
144
- {
145
- "id": "/src/internals/useHookResult.ts",
146
- "size": 222,
147
- "origSize": 348,
148
- "renderedExports": [
149
- "useHookResult"
150
- ],
151
- "removedExports": [],
152
- "dependents": [
153
- "/src/shared/hooks/createHooksInternal.tsx"
154
- ],
155
- "percent": 0.81,
156
- "reduction": 36.21
157
- },
158
- {
159
- "id": "/src/createTRPCQueryUtils.tsx",
160
- "size": 162,
161
- "origSize": 485,
162
- "renderedExports": [
163
- "createTRPCQueryUtils"
164
- ],
165
- "removedExports": [],
166
- "dependents": [
167
- "/src/index.ts"
168
- ],
169
- "percent": 0.59,
170
- "reduction": 66.6
171
- },
172
- {
173
- "id": "/src/internals/context.tsx",
174
- "size": 154,
175
- "origSize": 6094,
176
- "renderedExports": [
177
- "contextProps",
178
- "TRPCContext"
179
- ],
180
- "removedExports": [],
181
- "dependents": [
182
- "/src/shared/index.ts",
183
- "/src/shared/index.ts",
184
- "/src/shared/proxy/utilsProxy.ts",
185
- "/src/shared/hooks/createHooksInternal.tsx"
186
- ],
187
- "percent": 0.57,
188
- "reduction": 97.47
189
- },
190
- {
191
- "id": "/src/shared/queryClient.ts",
192
- "size": 129,
193
- "origSize": 514,
194
- "renderedExports": [
195
- "getQueryClient"
196
- ],
197
- "removedExports": [],
198
- "dependents": [
199
- "/src/shared/index.ts"
200
- ],
201
- "percent": 0.47,
202
- "reduction": 74.9
203
- },
204
- {
205
- "id": "/src/index.ts",
206
- "size": 0,
207
- "origSize": 313,
208
- "renderedExports": [],
209
- "removedExports": [],
210
- "dependents": [],
211
- "percent": 0,
212
- "reduction": 100
213
- },
214
- {
215
- "id": "/src/server/index.ts",
216
- "size": 0,
217
- "origSize": 54,
218
- "renderedExports": [],
219
- "removedExports": [],
220
- "dependents": [],
221
- "percent": 0,
222
- "reduction": 100
223
- },
224
- {
225
- "id": "/src/shared/index.ts",
226
- "size": 0,
227
- "origSize": 706,
228
- "renderedExports": [],
229
- "removedExports": [],
230
- "dependents": [
231
- "/src/createTRPCReact.tsx",
232
- "/src/createTRPCQueryUtils.tsx",
233
- "/src/server/ssgProxy.ts"
234
- ],
235
- "percent": 0,
236
- "reduction": 100
237
- }
238
- ],
239
- "moduleCount": 16
240
- }