@trpc/tanstack-react-query 0.0.0-alpha.5 → 10.8.0-alpha-tmp-02-12-response-types-idea.853

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 (43) hide show
  1. package/README.md +5 -5
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/internals/Context.d.ts +16 -9
  5. package/dist/internals/Context.d.ts.map +1 -1
  6. package/dist/internals/Context.js +19 -4
  7. package/dist/internals/Context.mjs +19 -4
  8. package/dist/internals/createOptionsProxy.d.ts +104 -40
  9. package/dist/internals/createOptionsProxy.d.ts.map +1 -1
  10. package/dist/internals/createOptionsProxy.js +43 -31
  11. package/dist/internals/createOptionsProxy.mjs +44 -32
  12. package/dist/internals/infiniteQueryOptions.d.ts +37 -28
  13. package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
  14. package/dist/internals/infiniteQueryOptions.js +3 -3
  15. package/dist/internals/infiniteQueryOptions.mjs +4 -4
  16. package/dist/internals/mutationOptions.d.ts +9 -4
  17. package/dist/internals/mutationOptions.d.ts.map +1 -1
  18. package/dist/internals/mutationOptions.js +3 -1
  19. package/dist/internals/mutationOptions.mjs +3 -1
  20. package/dist/internals/queryOptions.d.ts +9 -15
  21. package/dist/internals/queryOptions.d.ts.map +1 -1
  22. package/dist/internals/queryOptions.js +5 -3
  23. package/dist/internals/queryOptions.mjs +6 -4
  24. package/dist/internals/subscriptionOptions.d.ts +14 -18
  25. package/dist/internals/subscriptionOptions.d.ts.map +1 -1
  26. package/dist/internals/subscriptionOptions.js +7 -3
  27. package/dist/internals/subscriptionOptions.mjs +7 -3
  28. package/dist/internals/types.d.ts +44 -2
  29. package/dist/internals/types.d.ts.map +1 -1
  30. package/dist/internals/utils.d.ts +10 -2
  31. package/dist/internals/utils.d.ts.map +1 -1
  32. package/dist/internals/utils.js +10 -4
  33. package/dist/internals/utils.mjs +10 -4
  34. package/package.json +27 -26
  35. package/src/index.ts +4 -3
  36. package/src/internals/Context.tsx +42 -13
  37. package/src/internals/createOptionsProxy.ts +246 -114
  38. package/src/internals/infiniteQueryOptions.ts +53 -27
  39. package/src/internals/mutationOptions.ts +24 -7
  40. package/src/internals/queryOptions.ts +20 -5
  41. package/src/internals/subscriptionOptions.ts +26 -10
  42. package/src/internals/types.ts +48 -1
  43. package/src/internals/utils.ts +15 -4
@@ -1,13 +1,39 @@
1
+ import type { InfiniteData } from '@tanstack/react-query';
1
2
  import type { TRPCRequestOptions } from '@trpc/client';
3
+ /**
4
+ * Turn a set of optional properties into required
5
+ * @internal
6
+ */
7
+ export type WithRequired<TObj, TKey extends keyof TObj> = TObj & {
8
+ [P in TKey]-?: TObj[P];
9
+ };
10
+ /**
11
+ * @internal
12
+ */
2
13
  export type ResolverDef = {
3
14
  input: any;
4
15
  output: any;
5
16
  transformer: boolean;
6
17
  errorShape: any;
7
18
  };
8
- export type ExtractCursorType<TInput> = TInput extends {
19
+ /**
20
+ * @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
21
+ */
22
+ type CursorInput = {
9
23
  cursor?: any;
10
- } ? TInput['cursor'] : unknown;
24
+ };
25
+ export type OptionalCursorInput = CursorInput | void;
26
+ /**
27
+ * @internal
28
+ */
29
+ export type ExtractCursorType<TInput> = TInput extends CursorInput ? TInput['cursor'] : unknown;
30
+ /**
31
+ * @internal
32
+ */
33
+ export type TRPCInfiniteData<TInput, TOutput> = InfiniteData<TOutput, NonNullable<ExtractCursorType<TInput>> | null>;
34
+ /**
35
+ * @public
36
+ */
11
37
  export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signal'> {
12
38
  /**
13
39
  * Opt out of SSR for this query by passing `ssr: false`
@@ -18,18 +44,30 @@ export interface TRPCReactRequestOptions extends Omit<TRPCRequestOptions, 'signa
18
44
  */
19
45
  abortOnUnmount?: boolean;
20
46
  }
47
+ /**
48
+ * @public
49
+ */
21
50
  export interface TRPCQueryBaseOptions {
22
51
  /**
23
52
  * tRPC-related options
24
53
  */
25
54
  trpc?: TRPCReactRequestOptions;
26
55
  }
56
+ /**
57
+ * @public
58
+ */
27
59
  export interface TRPCQueryOptionsResult {
28
60
  trpc: {
29
61
  path: string;
30
62
  };
31
63
  }
64
+ /**
65
+ * @public
66
+ */
32
67
  export type QueryType = 'any' | 'infinite' | 'query';
68
+ /**
69
+ * @public
70
+ */
33
71
  export type TRPCQueryKey = [
34
72
  readonly string[],
35
73
  {
@@ -37,5 +75,9 @@ export type TRPCQueryKey = [
37
75
  type?: Exclude<QueryType, 'any'>;
38
76
  }?
39
77
  ];
78
+ /**
79
+ * @public
80
+ */
40
81
  export type TRPCMutationKey = [readonly string[]];
82
+ export {};
41
83
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI,MAAM,SAAS;IAAE,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,GACnE,MAAM,CAAC,QAAQ,CAAC,GAChB,OAAO,CAAC;AAEZ,MAAM,WAAW,uBAEf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,MAAM,EAAE;IACjB;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,EAAE,IAAI,SAAS,MAAM,IAAI,IAAI,IAAI,GAAG;KAC9D,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,KAAK,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AACpC,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,MAAM,IAAI,MAAM,SAAS,WAAW,GAC9D,MAAM,CAAC,QAAQ,CAAC,GAChB,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,EAAE,OAAO,IAAI,YAAY,CAC1D,OAAO,EACP,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,uBAEf,SAAQ,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,MAAM,EAAE;IACjB;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;KAAE,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC"}
@@ -21,8 +21,16 @@ export declare function buildQueryFromAsyncIterable(asyncIterable: AsyncIterable
21
21
  * To allow easy interactions with groups of related queries, such as
22
22
  * invalidating all queries of a router, we use an array as the path when
23
23
  * storing in tanstack query.
24
- **/
25
- export declare function getQueryKeyInternal(path: readonly string[], input: unknown, type: QueryType): TRPCQueryKey;
24
+ *
25
+ * @internal
26
+ */
27
+ export declare function getQueryKeyInternal(path: readonly string[], input?: unknown, type?: QueryType): TRPCQueryKey;
28
+ /**
29
+ * @internal
30
+ */
26
31
  export declare function getMutationKeyInternal(path: readonly string[]): TRPCMutationKey;
32
+ /**
33
+ * @internal
34
+ */
27
35
  export declare function unwrapLazyArg<T>(valueOrLazy: T | (() => T)): T;
28
36
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAMjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EACpC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,EACd,cAAc,CAAC,EAAE;IACf,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;CACnC,mCAYF;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,EACrC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,sBAsBvB;AAED;;;;IAII;AACJ,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,SAAS,GACd,YAAY,CA0Cd;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,eAAe,CAKjB;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAE9D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internals/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAC7C,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAMjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EACpC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,QAAQ,EACd,cAAc,CAAC,EAAE;IACf,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC;CACnC,mCAcF;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,EACrC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,YAAY,sBAsBvB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,KAAK,CAAC,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,SAAS,GACf,YAAY,CA2Cd;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,eAAe,CAKjB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAE9D"}
@@ -19,7 +19,7 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
19
19
  if (infiniteParams) {
20
20
  input = {
21
21
  ...input ?? {},
22
- ...infiniteParams.pageParam ? {
22
+ ...infiniteParams.pageParam !== undefined ? {
23
23
  cursor: infiniteParams.pageParam
24
24
  } : {},
25
25
  direction: infiniteParams.direction
@@ -57,7 +57,9 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
57
57
  * To allow easy interactions with groups of related queries, such as
58
58
  * invalidating all queries of a router, we use an array as the path when
59
59
  * storing in tanstack query.
60
- **/ function getQueryKeyInternal(path, input, type) {
60
+ *
61
+ * @internal
62
+ */ function getQueryKeyInternal(path, input, type) {
61
63
  // Construct a query key that is easy to destructure and flexible for
62
64
  // partial selecting etc.
63
65
  // https://github.com/trpc/trpc/issues/3128
@@ -93,14 +95,18 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
93
95
  }
94
96
  ];
95
97
  }
96
- function getMutationKeyInternal(path) {
98
+ /**
99
+ * @internal
100
+ */ function getMutationKeyInternal(path) {
97
101
  // some parts of the path may be dot-separated, split them up
98
102
  const splitPath = path.flatMap((part)=>part.split('.'));
99
103
  return splitPath.length ? [
100
104
  splitPath
101
105
  ] : [];
102
106
  }
103
- function unwrapLazyArg(valueOrLazy) {
107
+ /**
108
+ * @internal
109
+ */ function unwrapLazyArg(valueOrLazy) {
104
110
  return unstableCoreDoNotImport.isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
105
111
  }
106
112
 
@@ -17,7 +17,7 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
17
17
  if (infiniteParams) {
18
18
  input = {
19
19
  ...input ?? {},
20
- ...infiniteParams.pageParam ? {
20
+ ...infiniteParams.pageParam !== undefined ? {
21
21
  cursor: infiniteParams.pageParam
22
22
  } : {},
23
23
  direction: infiniteParams.direction
@@ -55,7 +55,9 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
55
55
  * To allow easy interactions with groups of related queries, such as
56
56
  * invalidating all queries of a router, we use an array as the path when
57
57
  * storing in tanstack query.
58
- **/ function getQueryKeyInternal(path, input, type) {
58
+ *
59
+ * @internal
60
+ */ function getQueryKeyInternal(path, input, type) {
59
61
  // Construct a query key that is easy to destructure and flexible for
60
62
  // partial selecting etc.
61
63
  // https://github.com/trpc/trpc/issues/3128
@@ -91,14 +93,18 @@ import { isObject, isFunction } from '@trpc/server/unstable-core-do-not-import';
91
93
  }
92
94
  ];
93
95
  }
94
- function getMutationKeyInternal(path) {
96
+ /**
97
+ * @internal
98
+ */ function getMutationKeyInternal(path) {
95
99
  // some parts of the path may be dot-separated, split them up
96
100
  const splitPath = path.flatMap((part)=>part.split('.'));
97
101
  return splitPath.length ? [
98
102
  splitPath
99
103
  ] : [];
100
104
  }
101
- function unwrapLazyArg(valueOrLazy) {
105
+ /**
106
+ * @internal
107
+ */ function unwrapLazyArg(valueOrLazy) {
102
108
  return isFunction(valueOrLazy) ? valueOrLazy() : valueOrLazy;
103
109
  }
104
110
 
package/package.json CHANGED
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "name": "@trpc/tanstack-react-query",
3
- "version": "0.0.0-alpha.5",
3
+ "version": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
4
4
  "description": "TanStack React Query Integration for tRPC",
5
5
  "author": "juliusmarminge",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.mjs",
9
9
  "typings": "dist/index.d.ts",
10
- "homepage": "https://trpc.io/docs/client/tanstack-react-query/introduction",
10
+ "homepage": "https://trpc.io/docs/client/tanstack-react-query/setup",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/trpc/trpc.git",
14
14
  "directory": "packages/tanstack-react-query"
15
15
  },
16
+ "scripts": {
17
+ "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
18
+ "dev": "pnpm build --watch",
19
+ "codegen-entrypoints": "tsx entrypoints.script.ts",
20
+ "lint": "eslint --cache src",
21
+ "test-run:tsc": "tsc --noEmit --pretty",
22
+ "ts-watch": "tsc --watch"
23
+ },
16
24
  "exports": {
17
25
  "./package.json": "./package.json",
18
26
  ".": {
@@ -40,30 +48,30 @@
40
48
  }
41
49
  },
42
50
  "peerDependencies": {
43
- "@tanstack/react-query": "^5.62.8",
44
- "@trpc/client": "10.45.1",
45
- "@trpc/server": "^10.45.1",
51
+ "@tanstack/react-query": "^5.67.1",
52
+ "@trpc/client": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
53
+ "@trpc/server": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
46
54
  "react": ">=18.2.0",
47
55
  "react-dom": ">=18.2.0",
48
56
  "typescript": ">=5.7.2"
49
57
  },
50
58
  "devDependencies": {
51
- "@tanstack/react-query": "^5.66.0",
52
- "@trpc/client": "10.45.1",
53
- "@trpc/server": "^10.45.1",
54
- "@types/node": "^20.10.0",
55
- "@types/react": "^18.3.1",
56
- "eslint": "^8.57.0",
59
+ "@tanstack/react-query": "^5.67.1",
60
+ "@trpc/client": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
61
+ "@trpc/server": "10.8.0-alpha-tmp-02-12-response-types-idea.853+be416f215",
62
+ "@types/node": "^22.13.5",
63
+ "@types/react": "^19.0.0",
64
+ "eslint": "^9.21.0",
57
65
  "event-source-polyfill": "^1.0.31",
58
66
  "konn": "^0.7.0",
59
67
  "react": "^19.0.0",
60
- "react-dom": "^18.3.1",
61
- "rollup": "^4.9.5",
62
- "tsx": "^4.0.0",
63
- "typescript": "^5.6.2",
64
- "vitest": "^2.0.4",
68
+ "react-dom": "^19.0.0",
69
+ "rollup": "^4.34.8",
70
+ "tsx": "^4.19.3",
71
+ "typescript": "^5.8.2",
72
+ "vitest": "^3.0.6",
65
73
  "ws": "^8.0.0",
66
- "zod": "^3.0.0"
74
+ "zod": "^3.24.2"
67
75
  },
68
76
  "publishConfig": {
69
77
  "access": "public"
@@ -71,12 +79,5 @@
71
79
  "funding": [
72
80
  "https://trpc.io/sponsor"
73
81
  ],
74
- "scripts": {
75
- "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
76
- "dev": "pnpm build --watch",
77
- "codegen-entrypoints": "tsx entrypoints.script.ts",
78
- "lint": "eslint --cache src",
79
- "test-run:tsc": "tsc --noEmit --pretty",
80
- "ts-watch": "tsc --watch"
81
- }
82
- }
82
+ "gitHead": "be416f215b4b891c4f6382535345ec397a02ae03"
83
+ }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export { createTRPCContext } from './internals/Context';
2
2
  export type {
3
3
  TRPCOptionsProxy,
4
- InferInput,
5
- InferOutput,
4
+ inferInput,
5
+ inferOutput,
6
6
  DecorateMutationProcedure,
7
7
  DecorateProcedure,
8
- DecorateQueryKeyable,
8
+ DecorateRouterKeyable,
9
9
  DecorateQueryProcedure,
10
10
  DecorateSubscriptionProcedure,
11
11
  } from './internals/createOptionsProxy';
@@ -23,3 +23,4 @@ export type {
23
23
  } from './internals/subscriptionOptions';
24
24
  export { createTRPCOptionsProxy } from './internals/createOptionsProxy';
25
25
  export { useSubscription } from './internals/subscriptionOptions';
26
+ export type * from './internals/types';
@@ -1,13 +1,30 @@
1
- import { type QueryClient } from '@tanstack/react-query';
2
- import { type CreateTRPCClient } from '@trpc/client';
3
- import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import type { TRPCClient } from '@trpc/client';
3
+ import type { AnyTRPCRouter } from '@trpc/server';
4
4
  import * as React from 'react';
5
- import {
6
- createTRPCOptionsProxy,
7
- type TRPCOptionsProxy,
8
- } from './createOptionsProxy';
5
+ import type { TRPCOptionsProxy } from './createOptionsProxy';
6
+ import { createTRPCOptionsProxy } from './createOptionsProxy';
9
7
 
10
- export function createTRPCContext<TRouter extends AnyRouter>() {
8
+ export interface CreateTRPCContextResult<TRouter extends AnyTRPCRouter> {
9
+ TRPCProvider: React.FC<{
10
+ children: React.ReactNode;
11
+ queryClient: QueryClient;
12
+ trpcClient: TRPCClient<TRouter>;
13
+ }>;
14
+ useTRPC: () => TRPCOptionsProxy<TRouter>;
15
+ useTRPCClient: () => TRPCClient<TRouter>;
16
+ }
17
+ /**
18
+ * Create a set of type-safe provider-consumers
19
+ *
20
+ * @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider
21
+ */
22
+ export function createTRPCContext<
23
+ TRouter extends AnyTRPCRouter,
24
+ >(): CreateTRPCContextResult<TRouter> {
25
+ const TRPCClientContext = React.createContext<TRPCClient<TRouter> | null>(
26
+ null,
27
+ );
11
28
  const TRPCContext = React.createContext<TRPCOptionsProxy<TRouter> | null>(
12
29
  null,
13
30
  );
@@ -16,7 +33,7 @@ export function createTRPCContext<TRouter extends AnyRouter>() {
16
33
  props: Readonly<{
17
34
  children: React.ReactNode;
18
35
  queryClient: QueryClient;
19
- trpcClient: CreateTRPCClient<TRouter>;
36
+ trpcClient: TRPCClient<TRouter>;
20
37
  }>,
21
38
  ) {
22
39
  const value = React.useMemo(
@@ -28,9 +45,11 @@ export function createTRPCContext<TRouter extends AnyRouter>() {
28
45
  [props.trpcClient, props.queryClient],
29
46
  );
30
47
  return (
31
- <TRPCContext.Provider value={value}>
32
- {props.children}
33
- </TRPCContext.Provider>
48
+ <TRPCClientContext.Provider value={props.trpcClient}>
49
+ <TRPCContext.Provider value={value}>
50
+ {props.children}
51
+ </TRPCContext.Provider>
52
+ </TRPCClientContext.Provider>
34
53
  );
35
54
  }
36
55
 
@@ -42,5 +61,15 @@ export function createTRPCContext<TRouter extends AnyRouter>() {
42
61
  return utils;
43
62
  }
44
63
 
45
- return { TRPCProvider, useTRPC };
64
+ function useTRPCClient() {
65
+ const client = React.useContext(TRPCClientContext);
66
+ if (!client) {
67
+ throw new Error(
68
+ 'useTRPCClient() can only be used inside of a <TRPCProvider>',
69
+ );
70
+ }
71
+ return client;
72
+ }
73
+
74
+ return { TRPCProvider, useTRPC, useTRPCClient };
46
75
  }