@trpc/react-query 11.3.1 → 11.3.2-canary.4

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 (129) hide show
  1. package/dist/getQueryKey-CP8onRYT.cjs +104 -0
  2. package/dist/getQueryKey-Dekty44G.mjs +53 -0
  3. package/dist/getQueryKey-Dekty44G.mjs.map +1 -0
  4. package/dist/getQueryKey.d-C_PnqPni.d.cts +892 -0
  5. package/dist/getQueryKey.d-C_PnqPni.d.cts.map +1 -0
  6. package/dist/getQueryKey.d-CruH3ncI.d.mts +892 -0
  7. package/dist/getQueryKey.d-CruH3ncI.d.mts.map +1 -0
  8. package/dist/index.cjs +47 -0
  9. package/dist/index.d.cts +31 -0
  10. package/dist/index.d.cts.map +1 -0
  11. package/dist/index.d.mts +31 -0
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/index.mjs +40 -4
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/rsc.cjs +69 -0
  16. package/dist/rsc.d.cts +80 -0
  17. package/dist/rsc.d.cts.map +1 -0
  18. package/dist/rsc.d.mts +80 -0
  19. package/dist/rsc.d.mts.map +1 -0
  20. package/dist/rsc.mjs +65 -104
  21. package/dist/rsc.mjs.map +1 -0
  22. package/dist/server/index.cjs +132 -0
  23. package/dist/server/index.d.cts +31 -0
  24. package/dist/server/index.d.cts.map +1 -0
  25. package/dist/server/index.d.mts +31 -0
  26. package/dist/server/index.d.mts.map +1 -0
  27. package/dist/server/index.mjs +133 -1
  28. package/dist/server/index.mjs.map +1 -0
  29. package/dist/shared/index.cjs +13 -0
  30. package/dist/shared/index.d.cts +2 -0
  31. package/dist/shared/index.d.mts +2 -0
  32. package/dist/shared/index.mjs +4 -7
  33. package/dist/shared-CMPBsqju.mjs +784 -0
  34. package/dist/shared-CMPBsqju.mjs.map +1 -0
  35. package/dist/shared-Doe-Gsbv.cjs +846 -0
  36. package/package.json +45 -26
  37. package/rsc/package.json +1 -0
  38. package/server/package.json +1 -0
  39. package/shared/package.json +1 -0
  40. package/dist/createTRPCQueryUtils.d.ts +0 -4
  41. package/dist/createTRPCQueryUtils.d.ts.map +0 -1
  42. package/dist/createTRPCQueryUtils.js +0 -16
  43. package/dist/createTRPCQueryUtils.mjs +0 -14
  44. package/dist/createTRPCReact.d.ts +0 -147
  45. package/dist/createTRPCReact.d.ts.map +0 -1
  46. package/dist/createTRPCReact.js +0 -60
  47. package/dist/createTRPCReact.mjs +0 -38
  48. package/dist/index.d.ts +0 -6
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/index.js +0 -19
  51. package/dist/internals/context.d.ts +0 -157
  52. package/dist/internals/context.d.ts.map +0 -1
  53. package/dist/internals/context.js +0 -33
  54. package/dist/internals/context.mjs +0 -11
  55. package/dist/internals/getClientArgs.d.ts +0 -9
  56. package/dist/internals/getClientArgs.d.ts.map +0 -1
  57. package/dist/internals/getClientArgs.js +0 -24
  58. package/dist/internals/getClientArgs.mjs +0 -22
  59. package/dist/internals/getQueryKey.d.ts +0 -49
  60. package/dist/internals/getQueryKey.d.ts.map +0 -1
  61. package/dist/internals/getQueryKey.js +0 -75
  62. package/dist/internals/getQueryKey.mjs +0 -70
  63. package/dist/internals/trpcResult.d.ts +0 -18
  64. package/dist/internals/trpcResult.d.ts.map +0 -1
  65. package/dist/internals/trpcResult.js +0 -63
  66. package/dist/internals/trpcResult.mjs +0 -40
  67. package/dist/internals/useQueries.d.ts +0 -58
  68. package/dist/internals/useQueries.d.ts.map +0 -1
  69. package/dist/rsc.d.ts +0 -80
  70. package/dist/rsc.d.ts.map +0 -1
  71. package/dist/rsc.js +0 -130
  72. package/dist/server/index.d.ts +0 -2
  73. package/dist/server/index.d.ts.map +0 -1
  74. package/dist/server/index.js +0 -7
  75. package/dist/server/ssgProxy.d.ts +0 -31
  76. package/dist/server/ssgProxy.d.ts.map +0 -1
  77. package/dist/server/ssgProxy.js +0 -141
  78. package/dist/server/ssgProxy.mjs +0 -139
  79. package/dist/shared/hooks/createHooksInternal.d.ts +0 -31
  80. package/dist/shared/hooks/createHooksInternal.d.ts.map +0 -1
  81. package/dist/shared/hooks/createHooksInternal.js +0 -543
  82. package/dist/shared/hooks/createHooksInternal.mjs +0 -522
  83. package/dist/shared/hooks/createRootHooks.d.ts +0 -2
  84. package/dist/shared/hooks/createRootHooks.d.ts.map +0 -1
  85. package/dist/shared/hooks/types.d.ts +0 -157
  86. package/dist/shared/hooks/types.d.ts.map +0 -1
  87. package/dist/shared/index.d.ts +0 -22
  88. package/dist/shared/index.d.ts.map +0 -1
  89. package/dist/shared/index.js +0 -22
  90. package/dist/shared/polymorphism/index.d.ts +0 -5
  91. package/dist/shared/polymorphism/index.d.ts.map +0 -1
  92. package/dist/shared/polymorphism/mutationLike.d.ts +0 -17
  93. package/dist/shared/polymorphism/mutationLike.d.ts.map +0 -1
  94. package/dist/shared/polymorphism/queryLike.d.ts +0 -21
  95. package/dist/shared/polymorphism/queryLike.d.ts.map +0 -1
  96. package/dist/shared/polymorphism/routerLike.d.ts +0 -11
  97. package/dist/shared/polymorphism/routerLike.d.ts.map +0 -1
  98. package/dist/shared/polymorphism/utilsLike.d.ts +0 -7
  99. package/dist/shared/polymorphism/utilsLike.d.ts.map +0 -1
  100. package/dist/shared/proxy/decorationProxy.d.ts +0 -8
  101. package/dist/shared/proxy/decorationProxy.d.ts.map +0 -1
  102. package/dist/shared/proxy/decorationProxy.js +0 -30
  103. package/dist/shared/proxy/decorationProxy.mjs +0 -28
  104. package/dist/shared/proxy/useQueriesProxy.d.ts +0 -25
  105. package/dist/shared/proxy/useQueriesProxy.d.ts.map +0 -1
  106. package/dist/shared/proxy/useQueriesProxy.js +0 -27
  107. package/dist/shared/proxy/useQueriesProxy.mjs +0 -25
  108. package/dist/shared/proxy/utilsProxy.d.ts +0 -141
  109. package/dist/shared/proxy/utilsProxy.d.ts.map +0 -1
  110. package/dist/shared/proxy/utilsProxy.js +0 -106
  111. package/dist/shared/proxy/utilsProxy.mjs +0 -102
  112. package/dist/shared/queryClient.d.ts +0 -17
  113. package/dist/shared/queryClient.d.ts.map +0 -1
  114. package/dist/shared/queryClient.js +0 -9
  115. package/dist/shared/queryClient.mjs +0 -7
  116. package/dist/shared/types.d.ts +0 -98
  117. package/dist/shared/types.d.ts.map +0 -1
  118. package/dist/utils/createUtilityFunctions.d.ts +0 -23
  119. package/dist/utils/createUtilityFunctions.d.ts.map +0 -1
  120. package/dist/utils/createUtilityFunctions.js +0 -196
  121. package/dist/utils/createUtilityFunctions.mjs +0 -194
  122. package/dist/utils/inferReactQueryProcedure.d.ts +0 -25
  123. package/dist/utils/inferReactQueryProcedure.d.ts.map +0 -1
  124. package/rsc/index.d.ts +0 -1
  125. package/rsc/index.js +0 -1
  126. package/server/index.d.ts +0 -1
  127. package/server/index.js +0 -1
  128. package/shared/index.d.ts +0 -1
  129. package/shared/index.js +0 -1
@@ -0,0 +1,846 @@
1
+ const require_getQueryKey = require('./getQueryKey-CP8onRYT.cjs');
2
+ const __trpc_client = require_getQueryKey.__toESM(require("@trpc/client"));
3
+ const __tanstack_react_query = require_getQueryKey.__toESM(require("@tanstack/react-query"));
4
+ const __trpc_server_unstable_core_do_not_import = require_getQueryKey.__toESM(require("@trpc/server/unstable-core-do-not-import"));
5
+ const react = require_getQueryKey.__toESM(require("react"));
6
+ const react_jsx_runtime = require_getQueryKey.__toESM(require("react/jsx-runtime"));
7
+
8
+ //#region src/shared/proxy/decorationProxy.ts
9
+ /**
10
+ * Create proxy for decorating procedures
11
+ * @internal
12
+ */
13
+ function createReactDecoration(hooks) {
14
+ return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)(({ path, args }) => {
15
+ const pathCopy = [...path];
16
+ const lastArg = pathCopy.pop();
17
+ if (lastArg === "useMutation") return hooks[lastArg](pathCopy, ...args);
18
+ if (lastArg === "_def") return { path: pathCopy };
19
+ const [input, ...rest] = args;
20
+ const opts = rest[0] ?? {};
21
+ return hooks[lastArg](pathCopy, input, opts);
22
+ });
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/internals/context.tsx
27
+ const contextProps = [
28
+ "client",
29
+ "ssrContext",
30
+ "ssrState",
31
+ "abortOnUnmount"
32
+ ];
33
+ const TRPCContext = react.createContext?.(null);
34
+
35
+ //#endregion
36
+ //#region src/shared/proxy/utilsProxy.ts
37
+ const getQueryType = (utilName) => {
38
+ switch (utilName) {
39
+ case "queryOptions":
40
+ case "fetch":
41
+ case "ensureData":
42
+ case "prefetch":
43
+ case "getData":
44
+ case "setData":
45
+ case "setQueriesData": return "query";
46
+ case "infiniteQueryOptions":
47
+ case "fetchInfinite":
48
+ case "prefetchInfinite":
49
+ case "getInfiniteData":
50
+ case "setInfiniteData": return "infinite";
51
+ case "setMutationDefaults":
52
+ case "getMutationDefaults":
53
+ case "isMutating":
54
+ case "cancel":
55
+ case "invalidate":
56
+ case "refetch":
57
+ case "reset": return "any";
58
+ }
59
+ };
60
+ /**
61
+ * @internal
62
+ */
63
+ function createRecursiveUtilsProxy(context) {
64
+ return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((opts) => {
65
+ const path = [...opts.path];
66
+ const utilName = path.pop();
67
+ const args = [...opts.args];
68
+ const input = args.shift();
69
+ const queryType = getQueryType(utilName);
70
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, queryType);
71
+ const contextMap = {
72
+ infiniteQueryOptions: () => context.infiniteQueryOptions(path, queryKey, args[0]),
73
+ queryOptions: () => context.queryOptions(path, queryKey, ...args),
74
+ fetch: () => context.fetchQuery(queryKey, ...args),
75
+ fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
76
+ prefetch: () => context.prefetchQuery(queryKey, ...args),
77
+ prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
78
+ ensureData: () => context.ensureQueryData(queryKey, ...args),
79
+ invalidate: () => context.invalidateQueries(queryKey, ...args),
80
+ reset: () => context.resetQueries(queryKey, ...args),
81
+ refetch: () => context.refetchQueries(queryKey, ...args),
82
+ cancel: () => context.cancelQuery(queryKey, ...args),
83
+ setData: () => {
84
+ context.setQueryData(queryKey, args[0], args[1]);
85
+ },
86
+ setQueriesData: () => context.setQueriesData(queryKey, args[0], args[1], args[2]),
87
+ setInfiniteData: () => {
88
+ context.setInfiniteQueryData(queryKey, args[0], args[1]);
89
+ },
90
+ getData: () => context.getQueryData(queryKey),
91
+ getInfiniteData: () => context.getInfiniteQueryData(queryKey),
92
+ setMutationDefaults: () => context.setMutationDefaults(require_getQueryKey.getMutationKeyInternal(path), input),
93
+ getMutationDefaults: () => context.getMutationDefaults(require_getQueryKey.getMutationKeyInternal(path)),
94
+ isMutating: () => context.isMutating({ mutationKey: require_getQueryKey.getMutationKeyInternal(path) })
95
+ };
96
+ return contextMap[utilName]();
97
+ });
98
+ }
99
+ /**
100
+ * @internal
101
+ */
102
+ function createReactQueryUtils(context) {
103
+ const clientProxy = (0, __trpc_client.createTRPCClientProxy)(context.client);
104
+ const proxy = createRecursiveUtilsProxy(context);
105
+ return (0, __trpc_server_unstable_core_do_not_import.createFlatProxy)((key) => {
106
+ const contextName = key;
107
+ if (contextName === "client") return clientProxy;
108
+ if (contextProps.includes(contextName)) return context[contextName];
109
+ return proxy[key];
110
+ });
111
+ }
112
+ /**
113
+ * @internal
114
+ */
115
+ function createQueryUtilsProxy(context) {
116
+ return createRecursiveUtilsProxy(context);
117
+ }
118
+
119
+ //#endregion
120
+ //#region src/shared/proxy/useQueriesProxy.ts
121
+ /**
122
+ * Create proxy for `useQueries` options
123
+ * @internal
124
+ */
125
+ function createUseQueries(client) {
126
+ const untypedClient = client instanceof __trpc_client.TRPCUntypedClient ? client : (0, __trpc_client.getUntypedClient)(client);
127
+ return (0, __trpc_server_unstable_core_do_not_import.createRecursiveProxy)((opts) => {
128
+ const arrayPath = opts.path;
129
+ const dotPath = arrayPath.join(".");
130
+ const [input, _opts] = opts.args;
131
+ const options = {
132
+ queryKey: require_getQueryKey.getQueryKeyInternal(arrayPath, input, "query"),
133
+ queryFn: () => {
134
+ return untypedClient.query(dotPath, input, _opts?.trpc);
135
+ },
136
+ ..._opts
137
+ };
138
+ return options;
139
+ });
140
+ }
141
+
142
+ //#endregion
143
+ //#region src/internals/getClientArgs.ts
144
+ /**
145
+ * @internal
146
+ */
147
+ function getClientArgs(queryKey, opts, infiniteParams) {
148
+ const path = queryKey[0];
149
+ let input = queryKey[1]?.input;
150
+ if (infiniteParams) input = {
151
+ ...input ?? {},
152
+ ...infiniteParams.pageParam ? { cursor: infiniteParams.pageParam } : {},
153
+ direction: infiniteParams.direction
154
+ };
155
+ return [
156
+ path.join("."),
157
+ input,
158
+ opts?.trpc
159
+ ];
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/internals/trpcResult.ts
164
+ function createTRPCOptionsResult(value) {
165
+ const path = value.path.join(".");
166
+ return { path };
167
+ }
168
+ /**
169
+ * Makes a stable reference of the `trpc` prop
170
+ */
171
+ function useHookResult(value) {
172
+ const result = createTRPCOptionsResult(value);
173
+ return react.useMemo(() => result, [result]);
174
+ }
175
+ /**
176
+ * @internal
177
+ */
178
+ async function buildQueryFromAsyncIterable(asyncIterable, queryClient, queryKey) {
179
+ const queryCache = queryClient.getQueryCache();
180
+ const query = queryCache.build(queryClient, { queryKey });
181
+ query.setState({
182
+ data: [],
183
+ status: "success"
184
+ });
185
+ const aggregate = [];
186
+ for await (const value of asyncIterable) {
187
+ aggregate.push(value);
188
+ query.setState({ data: [...aggregate] });
189
+ }
190
+ return aggregate;
191
+ }
192
+
193
+ //#endregion
194
+ //#region src/utils/createUtilityFunctions.ts
195
+ /**
196
+ * Creates a set of utility functions that can be used to interact with `react-query`
197
+ * @param opts the `TRPCClient` and `QueryClient` to use
198
+ * @returns a set of utility functions that can be used to interact with `react-query`
199
+ * @internal
200
+ */
201
+ function createUtilityFunctions(opts) {
202
+ const { client, queryClient } = opts;
203
+ const untypedClient = client instanceof __trpc_client.TRPCUntypedClient ? client : (0, __trpc_client.getUntypedClient)(client);
204
+ return {
205
+ infiniteQueryOptions: (path, queryKey, opts$1) => {
206
+ const inputIsSkipToken = queryKey[1]?.input === __tanstack_react_query.skipToken;
207
+ const queryFn = async (queryFnContext) => {
208
+ const actualOpts = {
209
+ ...opts$1,
210
+ trpc: {
211
+ ...opts$1?.trpc,
212
+ ...opts$1?.trpc?.abortOnUnmount ? { signal: queryFnContext.signal } : { signal: null }
213
+ }
214
+ };
215
+ const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts, {
216
+ direction: queryFnContext.direction,
217
+ pageParam: queryFnContext.pageParam
218
+ }));
219
+ return result;
220
+ };
221
+ return Object.assign((0, __tanstack_react_query.infiniteQueryOptions)({
222
+ ...opts$1,
223
+ initialData: opts$1?.initialData,
224
+ queryKey,
225
+ queryFn: inputIsSkipToken ? __tanstack_react_query.skipToken : queryFn,
226
+ initialPageParam: opts$1?.initialCursor ?? null
227
+ }), { trpc: createTRPCOptionsResult({ path }) });
228
+ },
229
+ queryOptions: (path, queryKey, opts$1) => {
230
+ const inputIsSkipToken = queryKey[1]?.input === __tanstack_react_query.skipToken;
231
+ const queryFn = async (queryFnContext) => {
232
+ const actualOpts = {
233
+ ...opts$1,
234
+ trpc: {
235
+ ...opts$1?.trpc,
236
+ ...opts$1?.trpc?.abortOnUnmount ? { signal: queryFnContext.signal } : { signal: null }
237
+ }
238
+ };
239
+ const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts));
240
+ if ((0, __trpc_server_unstable_core_do_not_import.isAsyncIterable)(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
241
+ return result;
242
+ };
243
+ return Object.assign((0, __tanstack_react_query.queryOptions)({
244
+ ...opts$1,
245
+ initialData: opts$1?.initialData,
246
+ queryKey,
247
+ queryFn: inputIsSkipToken ? __tanstack_react_query.skipToken : queryFn
248
+ }), { trpc: createTRPCOptionsResult({ path }) });
249
+ },
250
+ fetchQuery: (queryKey, opts$1) => {
251
+ return queryClient.fetchQuery({
252
+ ...opts$1,
253
+ queryKey,
254
+ queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
255
+ });
256
+ },
257
+ fetchInfiniteQuery: (queryKey, opts$1) => {
258
+ return queryClient.fetchInfiniteQuery({
259
+ ...opts$1,
260
+ queryKey,
261
+ queryFn: ({ pageParam, direction }) => {
262
+ return untypedClient.query(...getClientArgs(queryKey, opts$1, {
263
+ pageParam,
264
+ direction
265
+ }));
266
+ },
267
+ initialPageParam: opts$1?.initialCursor ?? null
268
+ });
269
+ },
270
+ prefetchQuery: (queryKey, opts$1) => {
271
+ return queryClient.prefetchQuery({
272
+ ...opts$1,
273
+ queryKey,
274
+ queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
275
+ });
276
+ },
277
+ prefetchInfiniteQuery: (queryKey, opts$1) => {
278
+ return queryClient.prefetchInfiniteQuery({
279
+ ...opts$1,
280
+ queryKey,
281
+ queryFn: ({ pageParam, direction }) => {
282
+ return untypedClient.query(...getClientArgs(queryKey, opts$1, {
283
+ pageParam,
284
+ direction
285
+ }));
286
+ },
287
+ initialPageParam: opts$1?.initialCursor ?? null
288
+ });
289
+ },
290
+ ensureQueryData: (queryKey, opts$1) => {
291
+ return queryClient.ensureQueryData({
292
+ ...opts$1,
293
+ queryKey,
294
+ queryFn: () => untypedClient.query(...getClientArgs(queryKey, opts$1))
295
+ });
296
+ },
297
+ invalidateQueries: (queryKey, filters, options) => {
298
+ return queryClient.invalidateQueries({
299
+ ...filters,
300
+ queryKey
301
+ }, options);
302
+ },
303
+ resetQueries: (queryKey, filters, options) => {
304
+ return queryClient.resetQueries({
305
+ ...filters,
306
+ queryKey
307
+ }, options);
308
+ },
309
+ refetchQueries: (queryKey, filters, options) => {
310
+ return queryClient.refetchQueries({
311
+ ...filters,
312
+ queryKey
313
+ }, options);
314
+ },
315
+ cancelQuery: (queryKey, options) => {
316
+ return queryClient.cancelQueries({ queryKey }, options);
317
+ },
318
+ setQueryData: (queryKey, updater, options) => {
319
+ return queryClient.setQueryData(queryKey, updater, options);
320
+ },
321
+ setQueriesData: (queryKey, filters, updater, options) => {
322
+ return queryClient.setQueriesData({
323
+ ...filters,
324
+ queryKey
325
+ }, updater, options);
326
+ },
327
+ getQueryData: (queryKey) => {
328
+ return queryClient.getQueryData(queryKey);
329
+ },
330
+ setInfiniteQueryData: (queryKey, updater, options) => {
331
+ return queryClient.setQueryData(queryKey, updater, options);
332
+ },
333
+ getInfiniteQueryData: (queryKey) => {
334
+ return queryClient.getQueryData(queryKey);
335
+ },
336
+ setMutationDefaults: (mutationKey, options) => {
337
+ const path = mutationKey[0];
338
+ const canonicalMutationFn = (input) => {
339
+ return untypedClient.mutation(...getClientArgs([path, { input }], opts));
340
+ };
341
+ return queryClient.setMutationDefaults(mutationKey, typeof options === "function" ? options({ canonicalMutationFn }) : options);
342
+ },
343
+ getMutationDefaults: (mutationKey) => {
344
+ return queryClient.getMutationDefaults(mutationKey);
345
+ },
346
+ isMutating: (filters) => {
347
+ return queryClient.isMutating({
348
+ ...filters,
349
+ exact: true
350
+ });
351
+ }
352
+ };
353
+ }
354
+
355
+ //#endregion
356
+ //#region src/shared/hooks/createHooksInternal.tsx
357
+ const trackResult = (result, onTrackResult) => {
358
+ const trackedResult = new Proxy(result, { get(target, prop) {
359
+ onTrackResult(prop);
360
+ return target[prop];
361
+ } });
362
+ return trackedResult;
363
+ };
364
+ /**
365
+ * @internal
366
+ */
367
+ function createRootHooks(config) {
368
+ const mutationSuccessOverride = config?.overrides?.useMutation?.onSuccess ?? ((options) => options.originalFn());
369
+ const Context = config?.context ?? TRPCContext;
370
+ const createClient = __trpc_client.createTRPCClient;
371
+ const TRPCProvider = (props) => {
372
+ const { abortOnUnmount = false, queryClient, ssrContext } = props;
373
+ const [ssrState, setSSRState] = react.useState(props.ssrState ?? false);
374
+ const client = props.client instanceof __trpc_client.TRPCUntypedClient ? props.client : (0, __trpc_client.getUntypedClient)(props.client);
375
+ const fns = react.useMemo(() => createUtilityFunctions({
376
+ client,
377
+ queryClient
378
+ }), [client, queryClient]);
379
+ const contextValue = react.useMemo(() => ({
380
+ abortOnUnmount,
381
+ queryClient,
382
+ client,
383
+ ssrContext: ssrContext ?? null,
384
+ ssrState,
385
+ ...fns
386
+ }), [
387
+ abortOnUnmount,
388
+ client,
389
+ fns,
390
+ queryClient,
391
+ ssrContext,
392
+ ssrState
393
+ ]);
394
+ react.useEffect(() => {
395
+ setSSRState((state) => state ? "mounted" : false);
396
+ }, []);
397
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Context.Provider, {
398
+ value: contextValue,
399
+ children: props.children
400
+ });
401
+ };
402
+ function useContext() {
403
+ const context = react.useContext(Context);
404
+ if (!context) throw new Error("Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?");
405
+ return context;
406
+ }
407
+ /**
408
+ * Hack to make sure errors return `status`='error` when doing SSR
409
+ * @see https://github.com/trpc/trpc/pull/1645
410
+ */
411
+ function useSSRQueryOptionsIfNeeded(queryKey, opts) {
412
+ const { queryClient, ssrState } = useContext();
413
+ return ssrState && ssrState !== "mounted" && queryClient.getQueryCache().find({ queryKey })?.state.status === "error" ? {
414
+ retryOnMount: false,
415
+ ...opts
416
+ } : opts;
417
+ }
418
+ function useQuery(path, input, opts) {
419
+ const context = useContext();
420
+ const { abortOnUnmount, client, ssrState, queryClient, prefetchQuery } = context;
421
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
422
+ const defaultOpts = queryClient.getQueryDefaults(queryKey);
423
+ const isInputSkipToken = input === __tanstack_react_query.skipToken;
424
+ if (typeof window === "undefined" && ssrState === "prepass" && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchQuery(queryKey, opts);
425
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
426
+ ...defaultOpts,
427
+ ...opts
428
+ });
429
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? abortOnUnmount;
430
+ const hook = (0, __tanstack_react_query.useQuery)({
431
+ ...ssrOpts,
432
+ queryKey,
433
+ queryFn: isInputSkipToken ? input : async (queryFunctionContext) => {
434
+ const actualOpts = {
435
+ ...ssrOpts,
436
+ trpc: {
437
+ ...ssrOpts?.trpc,
438
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }
439
+ }
440
+ };
441
+ const result = await client.query(...getClientArgs(queryKey, actualOpts));
442
+ if ((0, __trpc_server_unstable_core_do_not_import.isAsyncIterable)(result)) return buildQueryFromAsyncIterable(result, queryClient, queryKey);
443
+ return result;
444
+ }
445
+ }, queryClient);
446
+ hook.trpc = useHookResult({ path });
447
+ return hook;
448
+ }
449
+ function usePrefetchQuery(path, input, opts) {
450
+ const context = useContext();
451
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
452
+ const isInputSkipToken = input === __tanstack_react_query.skipToken;
453
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? context.abortOnUnmount;
454
+ (0, __tanstack_react_query.usePrefetchQuery)({
455
+ ...opts,
456
+ queryKey,
457
+ queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
458
+ const actualOpts = { trpc: {
459
+ ...opts?.trpc,
460
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}
461
+ } };
462
+ return context.client.query(...getClientArgs(queryKey, actualOpts));
463
+ }
464
+ });
465
+ }
466
+ function useSuspenseQuery(path, input, opts) {
467
+ const context = useContext();
468
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "query");
469
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? context.abortOnUnmount;
470
+ const hook = (0, __tanstack_react_query.useSuspenseQuery)({
471
+ ...opts,
472
+ queryKey,
473
+ queryFn: (queryFunctionContext) => {
474
+ const actualOpts = {
475
+ ...opts,
476
+ trpc: {
477
+ ...opts?.trpc,
478
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }
479
+ }
480
+ };
481
+ return context.client.query(...getClientArgs(queryKey, actualOpts));
482
+ }
483
+ }, context.queryClient);
484
+ hook.trpc = useHookResult({ path });
485
+ return [hook.data, hook];
486
+ }
487
+ function useMutation(path, opts) {
488
+ const { client, queryClient } = useContext();
489
+ const mutationKey = require_getQueryKey.getMutationKeyInternal(path);
490
+ const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
491
+ const hook = (0, __tanstack_react_query.useMutation)({
492
+ ...opts,
493
+ mutationKey,
494
+ mutationFn: (input) => {
495
+ return client.mutation(...getClientArgs([path, { input }], opts));
496
+ },
497
+ onSuccess(...args) {
498
+ const originalFn = () => opts?.onSuccess?.(...args) ?? defaultOpts?.onSuccess?.(...args);
499
+ return mutationSuccessOverride({
500
+ originalFn,
501
+ queryClient,
502
+ meta: opts?.meta ?? defaultOpts?.meta ?? {}
503
+ });
504
+ }
505
+ }, queryClient);
506
+ hook.trpc = useHookResult({ path });
507
+ return hook;
508
+ }
509
+ const initialStateIdle = {
510
+ data: void 0,
511
+ error: null,
512
+ status: "idle"
513
+ };
514
+ const initialStateConnecting = {
515
+ data: void 0,
516
+ error: null,
517
+ status: "connecting"
518
+ };
519
+ /* istanbul ignore next -- @preserve */
520
+ function useSubscription(path, input, opts) {
521
+ const enabled = opts?.enabled ?? input !== __tanstack_react_query.skipToken;
522
+ const queryKey = (0, __tanstack_react_query.hashKey)(require_getQueryKey.getQueryKeyInternal(path, input, "any"));
523
+ const { client } = useContext();
524
+ const optsRef = react.useRef(opts);
525
+ react.useEffect(() => {
526
+ optsRef.current = opts;
527
+ });
528
+ const [trackedProps] = react.useState(new Set([]));
529
+ const addTrackedProp = react.useCallback((key) => {
530
+ trackedProps.add(key);
531
+ }, [trackedProps]);
532
+ const currentSubscriptionRef = react.useRef(null);
533
+ const updateState = react.useCallback((callback) => {
534
+ const prev = resultRef.current;
535
+ const next = resultRef.current = callback(prev);
536
+ let shouldUpdate = false;
537
+ for (const key of trackedProps) if (prev[key] !== next[key]) {
538
+ shouldUpdate = true;
539
+ break;
540
+ }
541
+ if (shouldUpdate) setState(trackResult(next, addTrackedProp));
542
+ }, [addTrackedProp, trackedProps]);
543
+ const reset = react.useCallback(() => {
544
+ currentSubscriptionRef.current?.unsubscribe();
545
+ if (!enabled) {
546
+ updateState(() => ({
547
+ ...initialStateIdle,
548
+ reset
549
+ }));
550
+ return;
551
+ }
552
+ updateState(() => ({
553
+ ...initialStateConnecting,
554
+ reset
555
+ }));
556
+ const subscription = client.subscription(path.join("."), input ?? void 0, {
557
+ onStarted: () => {
558
+ optsRef.current.onStarted?.();
559
+ updateState((prev) => ({
560
+ ...prev,
561
+ status: "pending",
562
+ error: null
563
+ }));
564
+ },
565
+ onData: (data) => {
566
+ optsRef.current.onData?.(data);
567
+ updateState((prev) => ({
568
+ ...prev,
569
+ status: "pending",
570
+ data,
571
+ error: null
572
+ }));
573
+ },
574
+ onError: (error) => {
575
+ optsRef.current.onError?.(error);
576
+ updateState((prev) => ({
577
+ ...prev,
578
+ status: "error",
579
+ error
580
+ }));
581
+ },
582
+ onConnectionStateChange: (result) => {
583
+ updateState((prev) => {
584
+ switch (result.state) {
585
+ case "idle": return {
586
+ ...prev,
587
+ status: result.state,
588
+ error: null,
589
+ data: void 0
590
+ };
591
+ case "connecting": return {
592
+ ...prev,
593
+ error: result.error,
594
+ status: result.state
595
+ };
596
+ case "pending": return prev;
597
+ }
598
+ });
599
+ },
600
+ onComplete: () => {
601
+ optsRef.current.onComplete?.();
602
+ updateState((prev) => ({
603
+ ...prev,
604
+ status: "idle",
605
+ error: null,
606
+ data: void 0
607
+ }));
608
+ }
609
+ });
610
+ currentSubscriptionRef.current = subscription;
611
+ }, [
612
+ client,
613
+ queryKey,
614
+ enabled,
615
+ updateState
616
+ ]);
617
+ react.useEffect(() => {
618
+ reset();
619
+ return () => {
620
+ currentSubscriptionRef.current?.unsubscribe();
621
+ };
622
+ }, [reset]);
623
+ const resultRef = react.useRef(enabled ? {
624
+ ...initialStateConnecting,
625
+ reset
626
+ } : {
627
+ ...initialStateIdle,
628
+ reset
629
+ });
630
+ const [state, setState] = react.useState(trackResult(resultRef.current, addTrackedProp));
631
+ return state;
632
+ }
633
+ function useInfiniteQuery(path, input, opts) {
634
+ const { client, ssrState, prefetchInfiniteQuery, queryClient, abortOnUnmount } = useContext();
635
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
636
+ const defaultOpts = queryClient.getQueryDefaults(queryKey);
637
+ const isInputSkipToken = input === __tanstack_react_query.skipToken;
638
+ if (typeof window === "undefined" && ssrState === "prepass" && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !isInputSkipToken && !queryClient.getQueryCache().find({ queryKey })) prefetchInfiniteQuery(queryKey, {
639
+ ...defaultOpts,
640
+ ...opts
641
+ });
642
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
643
+ ...defaultOpts,
644
+ ...opts
645
+ });
646
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
647
+ const hook = (0, __tanstack_react_query.useInfiniteQuery)({
648
+ ...ssrOpts,
649
+ initialPageParam: opts.initialCursor ?? null,
650
+ persister: opts.persister,
651
+ queryKey,
652
+ queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
653
+ const actualOpts = {
654
+ ...ssrOpts,
655
+ trpc: {
656
+ ...ssrOpts?.trpc,
657
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : { signal: null }
658
+ }
659
+ };
660
+ return client.query(...getClientArgs(queryKey, actualOpts, {
661
+ pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
662
+ direction: queryFunctionContext.direction
663
+ }));
664
+ }
665
+ }, queryClient);
666
+ hook.trpc = useHookResult({ path });
667
+ return hook;
668
+ }
669
+ function usePrefetchInfiniteQuery(path, input, opts) {
670
+ const context = useContext();
671
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
672
+ const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
673
+ const isInputSkipToken = input === __tanstack_react_query.skipToken;
674
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
675
+ ...defaultOpts,
676
+ ...opts
677
+ });
678
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
679
+ (0, __tanstack_react_query.usePrefetchInfiniteQuery)({
680
+ ...opts,
681
+ initialPageParam: opts.initialCursor ?? null,
682
+ queryKey,
683
+ queryFn: isInputSkipToken ? input : (queryFunctionContext) => {
684
+ const actualOpts = {
685
+ ...ssrOpts,
686
+ trpc: {
687
+ ...ssrOpts?.trpc,
688
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}
689
+ }
690
+ };
691
+ return context.client.query(...getClientArgs(queryKey, actualOpts, {
692
+ pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
693
+ direction: queryFunctionContext.direction
694
+ }));
695
+ }
696
+ });
697
+ }
698
+ function useSuspenseInfiniteQuery(path, input, opts) {
699
+ const context = useContext();
700
+ const queryKey = require_getQueryKey.getQueryKeyInternal(path, input, "infinite");
701
+ const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
702
+ const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
703
+ ...defaultOpts,
704
+ ...opts
705
+ });
706
+ const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? context.abortOnUnmount;
707
+ const hook = (0, __tanstack_react_query.useSuspenseInfiniteQuery)({
708
+ ...opts,
709
+ initialPageParam: opts.initialCursor ?? null,
710
+ queryKey,
711
+ queryFn: (queryFunctionContext) => {
712
+ const actualOpts = {
713
+ ...ssrOpts,
714
+ trpc: {
715
+ ...ssrOpts?.trpc,
716
+ ...shouldAbortOnUnmount ? { signal: queryFunctionContext.signal } : {}
717
+ }
718
+ };
719
+ return context.client.query(...getClientArgs(queryKey, actualOpts, {
720
+ pageParam: queryFunctionContext.pageParam ?? opts.initialCursor,
721
+ direction: queryFunctionContext.direction
722
+ }));
723
+ }
724
+ }, context.queryClient);
725
+ hook.trpc = useHookResult({ path });
726
+ return [hook.data, hook];
727
+ }
728
+ const useQueries = (queriesCallback, options) => {
729
+ const { ssrState, queryClient, prefetchQuery, client } = useContext();
730
+ const proxy = createUseQueries(client);
731
+ const queries = queriesCallback(proxy);
732
+ if (typeof window === "undefined" && ssrState === "prepass") for (const query of queries) {
733
+ const queryOption = query;
734
+ if (queryOption.trpc?.ssr !== false && !queryClient.getQueryCache().find({ queryKey: queryOption.queryKey })) prefetchQuery(queryOption.queryKey, queryOption);
735
+ }
736
+ return (0, __tanstack_react_query.useQueries)({
737
+ queries: queries.map((query) => ({
738
+ ...query,
739
+ queryKey: query.queryKey
740
+ })),
741
+ combine: options?.combine
742
+ }, queryClient);
743
+ };
744
+ const useSuspenseQueries = (queriesCallback) => {
745
+ const { queryClient, client } = useContext();
746
+ const proxy = createUseQueries(client);
747
+ const queries = queriesCallback(proxy);
748
+ const hook = (0, __tanstack_react_query.useSuspenseQueries)({ queries: queries.map((query) => ({
749
+ ...query,
750
+ queryFn: query.queryFn,
751
+ queryKey: query.queryKey
752
+ })) }, queryClient);
753
+ return [hook.map((h) => h.data), hook];
754
+ };
755
+ return {
756
+ Provider: TRPCProvider,
757
+ createClient,
758
+ useContext,
759
+ useUtils: useContext,
760
+ useQuery,
761
+ usePrefetchQuery,
762
+ useSuspenseQuery,
763
+ useQueries,
764
+ useSuspenseQueries,
765
+ useMutation,
766
+ useSubscription,
767
+ useInfiniteQuery,
768
+ usePrefetchInfiniteQuery,
769
+ useSuspenseInfiniteQuery
770
+ };
771
+ }
772
+
773
+ //#endregion
774
+ //#region src/shared/queryClient.ts
775
+ /**
776
+ * @internal
777
+ */
778
+ const getQueryClient = (config) => config.queryClient ?? new __tanstack_react_query.QueryClient(config.queryClientConfig);
779
+
780
+ //#endregion
781
+ Object.defineProperty(exports, 'TRPCContext', {
782
+ enumerable: true,
783
+ get: function () {
784
+ return TRPCContext;
785
+ }
786
+ });
787
+ Object.defineProperty(exports, 'contextProps', {
788
+ enumerable: true,
789
+ get: function () {
790
+ return contextProps;
791
+ }
792
+ });
793
+ Object.defineProperty(exports, 'createQueryUtilsProxy', {
794
+ enumerable: true,
795
+ get: function () {
796
+ return createQueryUtilsProxy;
797
+ }
798
+ });
799
+ Object.defineProperty(exports, 'createReactDecoration', {
800
+ enumerable: true,
801
+ get: function () {
802
+ return createReactDecoration;
803
+ }
804
+ });
805
+ Object.defineProperty(exports, 'createReactQueryUtils', {
806
+ enumerable: true,
807
+ get: function () {
808
+ return createReactQueryUtils;
809
+ }
810
+ });
811
+ Object.defineProperty(exports, 'createRootHooks', {
812
+ enumerable: true,
813
+ get: function () {
814
+ return createRootHooks;
815
+ }
816
+ });
817
+ Object.defineProperty(exports, 'createUseQueries', {
818
+ enumerable: true,
819
+ get: function () {
820
+ return createUseQueries;
821
+ }
822
+ });
823
+ Object.defineProperty(exports, 'createUtilityFunctions', {
824
+ enumerable: true,
825
+ get: function () {
826
+ return createUtilityFunctions;
827
+ }
828
+ });
829
+ Object.defineProperty(exports, 'getClientArgs', {
830
+ enumerable: true,
831
+ get: function () {
832
+ return getClientArgs;
833
+ }
834
+ });
835
+ Object.defineProperty(exports, 'getQueryClient', {
836
+ enumerable: true,
837
+ get: function () {
838
+ return getQueryClient;
839
+ }
840
+ });
841
+ Object.defineProperty(exports, 'getQueryType', {
842
+ enumerable: true,
843
+ get: function () {
844
+ return getQueryType;
845
+ }
846
+ });