@trpc/react-query 11.0.0-alpha-tmp-react-sideeffects-import.202 → 11.0.0-alpha-tmp-ahmed-rollup-v4.203

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 (44) hide show
  1. package/dist/createTRPCQueryUtils.js +15 -0
  2. package/dist/createTRPCQueryUtils.mjs +13 -0
  3. package/dist/createTRPCReact.js +38 -0
  4. package/dist/createTRPCReact.mjs +35 -0
  5. package/dist/index.js +10 -64
  6. package/dist/index.mjs +3 -40
  7. package/dist/internals/context.d.ts +2 -2
  8. package/dist/internals/context.d.ts.map +1 -1
  9. package/dist/internals/context.js +14 -0
  10. package/dist/internals/context.mjs +11 -0
  11. package/dist/internals/getClientArgs.js +16 -0
  12. package/dist/internals/getClientArgs.mjs +14 -0
  13. package/dist/internals/getQueryKey.js +45 -0
  14. package/dist/internals/getQueryKey.mjs +42 -0
  15. package/dist/internals/useHookResult.js +13 -0
  16. package/dist/internals/useHookResult.mjs +11 -0
  17. package/dist/server/index.js +2 -102
  18. package/dist/server/index.mjs +1 -103
  19. package/dist/server/ssgProxy.js +106 -0
  20. package/dist/server/ssgProxy.mjs +104 -0
  21. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  22. package/dist/{createHooksInternal-5d2fa367.js → shared/hooks/createHooksInternal.js} +33 -207
  23. package/dist/{createHooksInternal-e0b0564e.mjs → shared/hooks/createHooksInternal.mjs} +16 -166
  24. package/dist/shared/index.js +13 -15
  25. package/dist/shared/index.mjs +7 -7
  26. package/dist/shared/proxy/decorationProxy.js +31 -0
  27. package/dist/shared/proxy/decorationProxy.mjs +29 -0
  28. package/dist/shared/proxy/useQueriesProxy.js +25 -0
  29. package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
  30. package/dist/shared/proxy/utilsProxy.js +89 -0
  31. package/dist/{utilsProxy-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +3 -51
  32. package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
  33. package/dist/utils/createUtilityFunctions.js +94 -0
  34. package/dist/utils/createUtilityFunctions.mjs +92 -0
  35. package/package.json +6 -6
  36. package/src/createTRPCReact.tsx +2 -2
  37. package/src/internals/context.tsx +2 -2
  38. package/src/internals/useHookResult.ts +2 -2
  39. package/src/shared/hooks/createHooksInternal.tsx +8 -10
  40. package/dist/createHooksInternal-4285c71a.js +0 -470
  41. package/dist/queryClient-1c8d7d8a.js +0 -8
  42. package/dist/utilsProxy-0b88c1e3.js +0 -161
  43. package/dist/utilsProxy-ff357a62.js +0 -128
  44. /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
@@ -0,0 +1,92 @@
1
+ import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
2
+ import { getClientArgs } from '../internals/getClientArgs.mjs';
3
+
4
+ /**
5
+ * Creates a set of utility functions that can be used to interact with `react-query`
6
+ * @param opts the `TRPCClient` and `QueryClient` to use
7
+ * @returns a set of utility functions that can be used to interact with `react-query`
8
+ * @internal
9
+ */ function createUtilityFunctions(opts) {
10
+ const { client , queryClient } = opts;
11
+ const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
12
+ return {
13
+ fetchQuery: (queryKey, opts)=>{
14
+ return queryClient.fetchQuery({
15
+ ...opts,
16
+ queryKey,
17
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
18
+ });
19
+ },
20
+ fetchInfiniteQuery: (queryKey, opts)=>{
21
+ return queryClient.fetchInfiniteQuery({
22
+ ...opts,
23
+ queryKey,
24
+ queryFn: ({ pageParam })=>{
25
+ return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
26
+ },
27
+ initialPageParam: opts?.initialCursor ?? null
28
+ });
29
+ },
30
+ prefetchQuery: (queryKey, opts)=>{
31
+ return queryClient.prefetchQuery({
32
+ ...opts,
33
+ queryKey,
34
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
35
+ });
36
+ },
37
+ prefetchInfiniteQuery: (queryKey, opts)=>{
38
+ return queryClient.prefetchInfiniteQuery({
39
+ ...opts,
40
+ queryKey,
41
+ queryFn: ({ pageParam })=>{
42
+ return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
43
+ },
44
+ initialPageParam: opts?.initialCursor ?? null
45
+ });
46
+ },
47
+ ensureQueryData: (queryKey, opts)=>{
48
+ return queryClient.ensureQueryData({
49
+ ...opts,
50
+ queryKey,
51
+ queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
52
+ });
53
+ },
54
+ invalidateQueries: (queryKey, filters, options)=>{
55
+ return queryClient.invalidateQueries({
56
+ ...filters,
57
+ queryKey
58
+ }, options);
59
+ },
60
+ resetQueries: (queryKey, filters, options)=>{
61
+ return queryClient.resetQueries({
62
+ ...filters,
63
+ queryKey
64
+ }, options);
65
+ },
66
+ refetchQueries: (queryKey, filters, options)=>{
67
+ return queryClient.refetchQueries({
68
+ ...filters,
69
+ queryKey
70
+ }, options);
71
+ },
72
+ cancelQuery: (queryKey, options)=>{
73
+ return queryClient.cancelQueries({
74
+ queryKey
75
+ }, options);
76
+ },
77
+ setQueryData: (queryKey, updater, options)=>{
78
+ return queryClient.setQueryData(queryKey, updater, options);
79
+ },
80
+ getQueryData: (queryKey)=>{
81
+ return queryClient.getQueryData(queryKey);
82
+ },
83
+ setInfiniteQueryData: (queryKey, updater, options)=>{
84
+ return queryClient.setQueryData(queryKey, updater, options);
85
+ },
86
+ getInfiniteQueryData: (queryKey)=>{
87
+ return queryClient.getQueryData(queryKey);
88
+ }
89
+ };
90
+ }
91
+
92
+ export { createUtilityFunctions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "11.0.0-alpha-tmp-react-sideeffects-import.202+204981c56",
3
+ "version": "11.0.0-alpha-tmp-ahmed-rollup-v4.203+94c04a36f",
4
4
  "description": "The tRPC React library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -57,17 +57,17 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
- "@trpc/core": "11.0.0-alpha-tmp-react-sideeffects-import.202+204981c56"
60
+ "@trpc/core": "11.0.0-alpha-tmp-ahmed-rollup-v4.203+94c04a36f"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "@tanstack/react-query": "^5.0.0",
64
- "@trpc/client": "11.0.0-alpha-tmp-react-sideeffects-import.202+204981c56",
64
+ "@trpc/client": "11.0.0-alpha-tmp-ahmed-rollup-v4.203+94c04a36f",
65
65
  "react": ">=18.2.0",
66
66
  "react-dom": ">=18.2.0"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@tanstack/react-query": "^5.0.0",
70
- "@trpc/client": "11.0.0-alpha-tmp-react-sideeffects-import.202+204981c56",
70
+ "@trpc/client": "11.0.0-alpha-tmp-ahmed-rollup-v4.203+94c04a36f",
71
71
  "@types/express": "^4.17.17",
72
72
  "@types/node": "^20.10.0",
73
73
  "@types/react": "^18.2.33",
@@ -76,7 +76,7 @@
76
76
  "next": "^14.0.1",
77
77
  "react": "^18.2.0",
78
78
  "react-dom": "^18.2.0",
79
- "rollup": "^2.79.1",
79
+ "rollup": "^4.9.5",
80
80
  "tsx": "^4.0.0",
81
81
  "zod": "^3.0.0"
82
82
  },
@@ -86,5 +86,5 @@
86
86
  "funding": [
87
87
  "https://trpc.io/sponsor"
88
88
  ],
89
- "gitHead": "204981c566792cc1dc72be3d0bb94750a6f476dc"
89
+ "gitHead": "94c04a36ff2711c1f4d57ed1f3ab3e65b2cb1fd7"
90
90
  }
@@ -13,7 +13,7 @@ import type {
13
13
  ProtectedIntersection,
14
14
  } from '@trpc/core';
15
15
  import { createFlatProxy } from '@trpc/core';
16
- import * as React from 'react';
16
+ import { useMemo } from 'react';
17
17
  import type {
18
18
  TRPCUseQueries,
19
19
  TRPCUseSuspenseQueries,
@@ -288,7 +288,7 @@ export function createHooksInternal<
288
288
  return () => {
289
289
  const context = trpc.useUtils();
290
290
  // create a stable reference of the utils context
291
- return React.useMemo(() => {
291
+ return useMemo(() => {
292
292
  return (createReactQueryUtils as any)(context);
293
293
  }, [context]);
294
294
  };
@@ -20,7 +20,7 @@ import type {
20
20
  TRPCUntypedClient,
21
21
  } from '@trpc/client';
22
22
  import type { AnyRouter, DistributiveOmit } from '@trpc/core';
23
- import * as React from 'react';
23
+ import { createContext } from 'react';
24
24
  import type { ExtractCursorType } from '../shared';
25
25
  import type { TRPCQueryKey } from './getQueryKey';
26
26
 
@@ -226,4 +226,4 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
226
226
  queryKey: TRPCQueryKey,
227
227
  ) => InfiniteData<unknown> | undefined;
228
228
  }
229
- export const TRPCContext = React.createContext?.(null as any);
229
+ export const TRPCContext = createContext(null as any);
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ import { useRef } from 'react';
2
2
 
3
3
  export interface TRPCHookResult {
4
4
  trpc: {
@@ -12,7 +12,7 @@ export interface TRPCHookResult {
12
12
  export function useHookResult(
13
13
  value: TRPCHookResult['trpc'],
14
14
  ): TRPCHookResult['trpc'] {
15
- const ref = React.useRef(value);
15
+ const ref = useRef(value);
16
16
  ref.current.path = value.path;
17
17
  return ref.current;
18
18
  }
@@ -13,7 +13,7 @@ import {
13
13
  import type { TRPCClientErrorLike } from '@trpc/client';
14
14
  import { createTRPCUntypedClient } from '@trpc/client';
15
15
  import type { AnyRouter } from '@trpc/core';
16
- import * as React from 'react';
16
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
17
17
  import type { SSRState, TRPCContextState } from '../../internals/context';
18
18
  import { TRPCContext } from '../../internals/context';
19
19
  import { getClientArgs } from '../../internals/getClientArgs';
@@ -69,11 +69,9 @@ export function createRootHooks<
69
69
 
70
70
  const TRPCProvider: TRPCProvider<TRouter, TSSRContext> = (props) => {
71
71
  const { abortOnUnmount = false, client, queryClient, ssrContext } = props;
72
- const [ssrState, setSSRState] = React.useState<SSRState>(
73
- props.ssrState ?? false,
74
- );
72
+ const [ssrState, setSSRState] = useState<SSRState>(props.ssrState ?? false);
75
73
 
76
- const fns = React.useMemo(
74
+ const fns = useMemo(
77
75
  () =>
78
76
  createUtilityFunctions({
79
77
  client,
@@ -82,7 +80,7 @@ export function createRootHooks<
82
80
  [client, queryClient],
83
81
  );
84
82
 
85
- const contextValue = React.useMemo<ProviderContext>(
83
+ const contextValue = useMemo<ProviderContext>(
86
84
  () => ({
87
85
  abortOnUnmount,
88
86
  queryClient,
@@ -94,7 +92,7 @@ export function createRootHooks<
94
92
  [abortOnUnmount, client, fns, queryClient, ssrContext, ssrState],
95
93
  );
96
94
 
97
- React.useEffect(() => {
95
+ useEffect(() => {
98
96
  // Only updating state to `mounted` if we are using SSR.
99
97
  // This makes it so we don't have an unnecessary re-render when opting out of SSR.
100
98
  setSSRState((state) => (state ? 'mounted' : false));
@@ -277,10 +275,10 @@ export function createRootHooks<
277
275
  const queryKey = hashKey(getQueryKeyInternal(path, input, 'any'));
278
276
  const { client } = useContext();
279
277
 
280
- const optsRef = React.useRef<typeof opts>(opts);
278
+ const optsRef = useRef<typeof opts>(opts);
281
279
  optsRef.current = opts;
282
280
 
283
- React.useEffect(() => {
281
+ useEffect(() => {
284
282
  if (!enabled) {
285
283
  return;
286
284
  }
@@ -494,7 +492,7 @@ export function createRootHooks<
494
492
  client,
495
493
  trpcState,
496
494
  ) => {
497
- const transformed: DehydratedState | undefined = React.useMemo(() => {
495
+ const transformed: DehydratedState | undefined = useMemo(() => {
498
496
  if (!trpcState) {
499
497
  return trpcState;
500
498
  }