@trpc/client 11.0.0-next.92 → 11.0.0-rc.329

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 (159) hide show
  1. package/README.md +4 -4
  2. package/dist/TRPCClientError.d.ts +8 -7
  3. package/dist/TRPCClientError.d.ts.map +1 -1
  4. package/dist/{TRPCClientError-e224e397.js → TRPCClientError.js} +3 -3
  5. package/dist/{TRPCClientError-0de4d231.mjs → TRPCClientError.mjs} +4 -4
  6. package/dist/bundle-analysis.json +126 -155
  7. package/dist/createTRPCClient.d.ts +27 -19
  8. package/dist/createTRPCClient.d.ts.map +1 -1
  9. package/dist/createTRPCClient.js +50 -0
  10. package/dist/createTRPCClient.mjs +45 -0
  11. package/dist/createTRPCUntypedClient.d.ts +3 -2
  12. package/dist/createTRPCUntypedClient.d.ts.map +1 -1
  13. package/dist/createTRPCUntypedClient.js +10 -0
  14. package/dist/createTRPCUntypedClient.mjs +7 -0
  15. package/dist/getFetch.d.ts +1 -1
  16. package/dist/getFetch.d.ts.map +1 -1
  17. package/dist/getFetch.js +17 -0
  18. package/dist/getFetch.mjs +15 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +32 -370
  21. package/dist/index.mjs +9 -354
  22. package/dist/internals/TRPCUntypedClient.d.ts +5 -30
  23. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  24. package/dist/internals/TRPCUntypedClient.js +85 -0
  25. package/dist/internals/TRPCUntypedClient.mjs +83 -0
  26. package/dist/internals/dataLoader.d.ts +1 -1
  27. package/dist/internals/dataLoader.d.ts.map +1 -1
  28. package/dist/{httpBatchLink-204206a5.mjs → internals/dataLoader.js} +2 -117
  29. package/dist/internals/dataLoader.mjs +131 -0
  30. package/dist/internals/getAbortController.d.ts +2 -2
  31. package/dist/internals/getAbortController.d.ts.map +1 -1
  32. package/dist/internals/getAbortController.js +18 -0
  33. package/dist/internals/getAbortController.mjs +16 -0
  34. package/dist/internals/transformer.d.ts +42 -0
  35. package/dist/internals/transformer.d.ts.map +1 -0
  36. package/dist/internals/transformer.js +30 -0
  37. package/dist/internals/transformer.mjs +28 -0
  38. package/dist/internals/types.d.ts +4 -2
  39. package/dist/internals/types.d.ts.map +1 -1
  40. package/dist/links/HTTPBatchLinkOptions.d.ts +6 -5
  41. package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
  42. package/dist/links/httpBatchLink.d.ts +2 -2
  43. package/dist/links/httpBatchLink.d.ts.map +1 -1
  44. package/dist/links/httpBatchLink.js +37 -9
  45. package/dist/links/httpBatchLink.mjs +39 -5
  46. package/dist/links/httpBatchStreamLink.d.ts +6 -5
  47. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  48. package/dist/links/httpBatchStreamLink.js +43 -0
  49. package/dist/links/httpBatchStreamLink.mjs +41 -0
  50. package/dist/links/httpFormDataLink.d.ts +1 -1
  51. package/dist/links/httpFormDataLink.d.ts.map +1 -1
  52. package/dist/links/httpFormDataLink.js +31 -0
  53. package/dist/links/httpFormDataLink.mjs +29 -0
  54. package/dist/links/httpLink.d.ts +8 -8
  55. package/dist/links/httpLink.d.ts.map +1 -1
  56. package/dist/links/httpLink.js +6 -9
  57. package/dist/links/httpLink.mjs +6 -7
  58. package/dist/links/internals/createChain.d.ts +2 -2
  59. package/dist/links/internals/createChain.d.ts.map +1 -1
  60. package/dist/{splitLink-f29e84be.js → links/internals/createChain.js} +0 -22
  61. package/dist/{splitLink-4c75f7be.mjs → links/internals/createChain.mjs} +1 -22
  62. package/dist/links/internals/createHTTPBatchLink.d.ts +6 -6
  63. package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
  64. package/dist/links/internals/createHTTPBatchLink.js +85 -0
  65. package/dist/links/internals/createHTTPBatchLink.mjs +83 -0
  66. package/dist/links/internals/dedupeLink.d.ts +2 -2
  67. package/dist/links/internals/dedupeLink.d.ts.map +1 -1
  68. package/dist/links/internals/getTextDecoder.d.ts +1 -1
  69. package/dist/links/internals/getTextDecoder.d.ts.map +1 -1
  70. package/dist/links/internals/getTextDecoder.js +18 -0
  71. package/dist/links/internals/getTextDecoder.mjs +16 -0
  72. package/dist/links/internals/httpUtils.d.ts +19 -11
  73. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  74. package/dist/{httpUtils-c0e7bf5a.js → links/internals/httpUtils.js} +20 -39
  75. package/dist/{httpUtils-f58ceda1.mjs → links/internals/httpUtils.mjs} +20 -38
  76. package/dist/links/internals/parseJSONStream.d.ts +5 -6
  77. package/dist/links/internals/parseJSONStream.d.ts.map +1 -1
  78. package/dist/links/internals/parseJSONStream.js +118 -0
  79. package/dist/links/internals/parseJSONStream.mjs +115 -0
  80. package/dist/links/internals/retryLink.d.ts +2 -2
  81. package/dist/links/internals/retryLink.d.ts.map +1 -1
  82. package/dist/links/loggerLink.d.ts +4 -4
  83. package/dist/links/loggerLink.d.ts.map +1 -1
  84. package/dist/links/loggerLink.js +6 -4
  85. package/dist/links/loggerLink.mjs +6 -2
  86. package/dist/links/splitLink.d.ts +2 -2
  87. package/dist/links/splitLink.d.ts.map +1 -1
  88. package/dist/links/splitLink.js +23 -6
  89. package/dist/links/splitLink.mjs +25 -2
  90. package/dist/links/types.d.ts +15 -14
  91. package/dist/links/types.d.ts.map +1 -1
  92. package/dist/links/wsLink.d.ts +44 -13
  93. package/dist/links/wsLink.d.ts.map +1 -1
  94. package/dist/links/wsLink.js +64 -24
  95. package/dist/links/wsLink.mjs +64 -22
  96. package/dist/links.d.ts +10 -0
  97. package/dist/links.d.ts.map +1 -0
  98. package/dist/unstable-internals.d.ts +2 -0
  99. package/dist/unstable-internals.d.ts.map +1 -0
  100. package/dist/unstable-internals.js +7 -0
  101. package/dist/unstable-internals.mjs +1 -0
  102. package/package.json +26 -28
  103. package/src/TRPCClientError.ts +24 -13
  104. package/src/createTRPCClient.ts +58 -51
  105. package/src/createTRPCUntypedClient.ts +3 -5
  106. package/src/getFetch.ts +1 -1
  107. package/src/index.ts +2 -0
  108. package/src/internals/TRPCUntypedClient.ts +14 -84
  109. package/src/internals/dataLoader.ts +1 -1
  110. package/src/internals/getAbortController.ts +2 -2
  111. package/src/internals/transformer.ts +76 -0
  112. package/src/internals/types.ts +8 -1
  113. package/src/links/HTTPBatchLinkOptions.ts +17 -15
  114. package/src/links/httpBatchLink.ts +9 -8
  115. package/src/links/httpBatchStreamLink.ts +17 -17
  116. package/src/links/httpFormDataLink.ts +11 -12
  117. package/src/links/httpLink.ts +27 -19
  118. package/src/links/internals/createChain.ts +6 -2
  119. package/src/links/internals/createHTTPBatchLink.ts +24 -16
  120. package/src/links/internals/dedupeLink.ts +4 -3
  121. package/src/links/internals/getTextDecoder.ts +1 -1
  122. package/src/links/internals/httpUtils.ts +42 -21
  123. package/src/links/internals/parseJSONStream.ts +12 -14
  124. package/src/links/internals/retryLink.ts +4 -3
  125. package/src/links/loggerLink.ts +5 -5
  126. package/src/links/splitLink.ts +2 -2
  127. package/src/links/types.ts +27 -22
  128. package/src/links/wsLink.ts +124 -36
  129. package/src/links.ts +14 -0
  130. package/src/unstable-internals.ts +1 -0
  131. package/unstable-internals/index.d.ts +1 -0
  132. package/unstable-internals/index.js +1 -0
  133. package/dist/TRPCClientError-23c8aa93.js +0 -61
  134. package/dist/httpBatchLink-64fceaac.js +0 -251
  135. package/dist/httpBatchLink-92dab48e.js +0 -247
  136. package/dist/httpUtils-35e50476.js +0 -145
  137. package/dist/internals/isObject.d.ts +0 -2
  138. package/dist/internals/isObject.d.ts.map +0 -1
  139. package/dist/internals/retryDelay.d.ts +0 -2
  140. package/dist/internals/retryDelay.d.ts.map +0 -1
  141. package/dist/links/index.d.ts +0 -10
  142. package/dist/links/index.d.ts.map +0 -1
  143. package/dist/shared/index.d.ts +0 -2
  144. package/dist/shared/index.d.ts.map +0 -1
  145. package/dist/shared/index.js +0 -9
  146. package/dist/shared/index.mjs +0 -1
  147. package/dist/shared/transformResult.d.ts +0 -34
  148. package/dist/shared/transformResult.d.ts.map +0 -1
  149. package/dist/splitLink-0df96fdc.js +0 -41
  150. package/dist/transformResult-ace864b8.mjs +0 -58
  151. package/dist/transformResult-c1422cb5.js +0 -60
  152. package/dist/transformResult-dfce8f15.js +0 -61
  153. package/shared/index.d.ts +0 -1
  154. package/shared/index.js +0 -1
  155. package/src/internals/isObject.ts +0 -4
  156. package/src/internals/retryDelay.ts +0 -3
  157. package/src/links/index.ts +0 -14
  158. package/src/shared/index.ts +0 -1
  159. package/src/shared/transformResult.ts +0 -79
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "11.0.0-next.92+06cebb01",
3
+ "version": "11.0.0-rc.329+fdcb4a7d8",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -25,8 +25,8 @@
25
25
  "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
26
26
  "dev": "pnpm build --watch",
27
27
  "codegen-entrypoints": "tsx entrypoints.script.ts",
28
- "lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src",
29
- "ts-watch": "tsc --project tsconfig.watch.json --watch"
28
+ "lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore src",
29
+ "ts-watch": "tsc --watch"
30
30
  },
31
31
  "exports": {
32
32
  "./package.json": "./package.json",
@@ -35,35 +35,35 @@
35
35
  "require": "./dist/index.js",
36
36
  "default": "./dist/index.js"
37
37
  },
38
- "./links/httpLink": {
39
- "import": "./dist/links/httpLink.mjs",
40
- "require": "./dist/links/httpLink.js",
41
- "default": "./dist/links/httpLink.js"
42
- },
43
38
  "./links/httpBatchLink": {
44
39
  "import": "./dist/links/httpBatchLink.mjs",
45
40
  "require": "./dist/links/httpBatchLink.js",
46
41
  "default": "./dist/links/httpBatchLink.js"
47
42
  },
48
- "./links/splitLink": {
49
- "import": "./dist/links/splitLink.mjs",
50
- "require": "./dist/links/splitLink.js",
51
- "default": "./dist/links/splitLink.js"
43
+ "./links/httpLink": {
44
+ "import": "./dist/links/httpLink.mjs",
45
+ "require": "./dist/links/httpLink.js",
46
+ "default": "./dist/links/httpLink.js"
52
47
  },
53
48
  "./links/loggerLink": {
54
49
  "import": "./dist/links/loggerLink.mjs",
55
50
  "require": "./dist/links/loggerLink.js",
56
51
  "default": "./dist/links/loggerLink.js"
57
52
  },
53
+ "./links/splitLink": {
54
+ "import": "./dist/links/splitLink.mjs",
55
+ "require": "./dist/links/splitLink.js",
56
+ "default": "./dist/links/splitLink.js"
57
+ },
58
58
  "./links/wsLink": {
59
59
  "import": "./dist/links/wsLink.mjs",
60
60
  "require": "./dist/links/wsLink.js",
61
61
  "default": "./dist/links/wsLink.js"
62
62
  },
63
- "./shared": {
64
- "import": "./dist/shared/index.mjs",
65
- "require": "./dist/shared/index.js",
66
- "default": "./dist/shared/index.js"
63
+ "./unstable-internals": {
64
+ "import": "./dist/unstable-internals.mjs",
65
+ "require": "./dist/unstable-internals.js",
66
+ "default": "./dist/unstable-internals.js"
67
67
  }
68
68
  },
69
69
  "files": [
@@ -72,24 +72,22 @@
72
72
  "README.md",
73
73
  "package.json",
74
74
  "links",
75
- "shared",
75
+ "unstable-internals",
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "11.0.0-next.92+06cebb01"
79
+ "@trpc/server": "11.0.0-rc.329+fdcb4a7d8"
80
80
  },
81
81
  "devDependencies": {
82
- "@testing-library/dom": "^9.0.0",
83
- "@trpc/server": "11.0.0-next.92+06cebb01",
84
- "@types/isomorphic-fetch": "^0.0.38",
85
- "@types/node": "^18.16.16",
86
- "eslint": "^8.40.0",
82
+ "@trpc/server": "11.0.0-rc.329+fdcb4a7d8",
83
+ "@types/isomorphic-fetch": "^0.0.39",
84
+ "@types/node": "^20.10.0",
85
+ "eslint": "^8.56.0",
87
86
  "isomorphic-fetch": "^3.0.0",
88
87
  "node-fetch": "^3.3.0",
89
- "rollup": "^2.79.1",
90
- "tsx": "^3.12.7",
91
- "undici": "^5.14.0",
92
- "vitest": "^0.32.0"
88
+ "rollup": "^4.9.5",
89
+ "tsx": "^4.0.0",
90
+ "undici": "^6.0.1"
93
91
  },
94
92
  "publishConfig": {
95
93
  "access": "public"
@@ -97,5 +95,5 @@
97
95
  "funding": [
98
96
  "https://trpc.io/sponsor"
99
97
  ],
100
- "gitHead": "06cebb015144e438281edace5dc4a5328477e495"
98
+ "gitHead": "fdcb4a7d8168d19f9bcbc816b80db815b06a134c"
101
99
  }
@@ -1,14 +1,23 @@
1
- import { DefaultErrorShape, Maybe } from '@trpc/server';
2
- import { TRPCErrorResponse } from '@trpc/server/rpc';
3
- import { inferErrorShape, TRPCInferrable } from '@trpc/server/shared';
4
- import { isObject } from './internals/isObject';
1
+ import type {
2
+ inferClientTypes,
3
+ InferrableClientTypes,
4
+ Maybe,
5
+ TRPCErrorResponse,
6
+ } from '@trpc/server/unstable-core-do-not-import';
7
+ import {
8
+ getCauseFromUnknown,
9
+ isObject,
10
+ type DefaultErrorShape,
11
+ } from '@trpc/server/unstable-core-do-not-import';
5
12
 
13
+ type inferErrorShape<TInferrable extends InferrableClientTypes> =
14
+ inferClientTypes<TInferrable>['errorShape'];
6
15
  export interface TRPCClientErrorBase<TShape extends DefaultErrorShape> {
7
16
  readonly message: string;
8
17
  readonly shape: Maybe<TShape>;
9
18
  readonly data: Maybe<TShape['data']>;
10
19
  }
11
- export type TRPCClientErrorLike<TInferrable extends TRPCInferrable> =
20
+ export type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> =
12
21
  TRPCClientErrorBase<inferErrorShape<TInferrable>>;
13
22
 
14
23
  function isTRPCClientError(cause: unknown): cause is TRPCClientError<any> {
@@ -25,17 +34,19 @@ function isTRPCClientError(cause: unknown): cause is TRPCClientError<any> {
25
34
  function isTRPCErrorResponse(obj: unknown): obj is TRPCErrorResponse<any> {
26
35
  return (
27
36
  isObject(obj) &&
28
- isObject(obj.error) &&
29
- typeof obj.error.code === 'number' &&
30
- typeof obj.error.message === 'string'
37
+ isObject(obj['error']) &&
38
+ typeof obj['error']['code'] === 'number' &&
39
+ typeof obj['error']['message'] === 'string'
31
40
  );
32
41
  }
33
42
 
34
- export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>
43
+ export class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>
35
44
  extends Error
36
45
  implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>>
37
46
  {
38
- public readonly cause;
47
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
48
+ // @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
49
+ public override readonly cause;
39
50
  public readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;
40
51
  public readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;
41
52
 
@@ -48,7 +59,7 @@ export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>
48
59
  constructor(
49
60
  message: string,
50
61
  opts?: {
51
- result?: Maybe<inferErrorShape<TRouterOrProcedure>>;
62
+ result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>;
52
63
  cause?: Error;
53
64
  meta?: Record<string, unknown>;
54
65
  },
@@ -69,7 +80,7 @@ export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>
69
80
  Object.setPrototypeOf(this, TRPCClientError.prototype);
70
81
  }
71
82
 
72
- public static from<TRouterOrProcedure extends TRPCInferrable>(
83
+ public static from<TRouterOrProcedure extends InferrableClientTypes>(
73
84
  _cause: Error | TRPCErrorResponse<any>,
74
85
  opts: { meta?: Record<string, unknown> } = {},
75
86
  ): TRPCClientError<TRouterOrProcedure> {
@@ -100,7 +111,7 @@ export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>
100
111
 
101
112
  return new TRPCClientError(cause.message, {
102
113
  ...opts,
103
- cause,
114
+ cause: getCauseFromUnknown(cause),
104
115
  });
105
116
  }
106
117
  }
@@ -1,30 +1,27 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import type { Unsubscribable } from '@trpc/server/observable';
2
3
  import type {
3
- AnyMutationProcedure,
4
4
  AnyProcedure,
5
- AnyQueryProcedure,
6
- AnyRootConfig,
7
5
  AnyRouter,
8
- AnySubscriptionProcedure,
6
+ inferClientTypes,
7
+ inferProcedureInput,
8
+ inferTransformedProcedureOutput,
9
9
  IntersectionError,
10
- ProcedureArgs,
11
- ProcedureRouterRecord,
10
+ ProcedureOptions,
12
11
  ProcedureType,
13
- } from '@trpc/server';
14
- import type { Unsubscribable } from '@trpc/server/observable';
12
+ RouterRecord,
13
+ } from '@trpc/server/unstable-core-do-not-import';
15
14
  import {
16
15
  createFlatProxy,
17
16
  createRecursiveProxy,
18
- inferTransformedProcedureOutput,
19
- inferTransformedSubscriptionOutput,
20
- } from '@trpc/server/shared';
21
- import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
22
- import {
17
+ } from '@trpc/server/unstable-core-do-not-import';
18
+ import type { CreateTRPCClientOptions } from './createTRPCUntypedClient';
19
+ import type {
23
20
  TRPCSubscriptionObserver,
24
- TRPCUntypedClient,
25
21
  UntypedClientProperties,
26
22
  } from './internals/TRPCUntypedClient';
27
- import { TRPCClientError } from './TRPCClientError';
23
+ import { TRPCUntypedClient } from './internals/TRPCUntypedClient';
24
+ import type { TRPCClientError } from './TRPCClientError';
28
25
 
29
26
  /**
30
27
  * @public
@@ -32,44 +29,41 @@ import { TRPCClientError } from './TRPCClientError';
32
29
  export type inferRouterClient<TRouter extends AnyRouter> =
33
30
  DecoratedProcedureRecord<TRouter, TRouter['_def']['record']>;
34
31
 
32
+ type ResolverDef = {
33
+ input: any;
34
+ output: any;
35
+ transformer: boolean;
36
+ errorShape: any;
37
+ };
38
+
35
39
  /** @internal */
36
- export type Resolver<
37
- TConfig extends AnyRootConfig,
38
- TProcedure extends AnyProcedure,
39
- > = (
40
- ...args: ProcedureArgs<TProcedure['_def']>
41
- ) => Promise<inferTransformedProcedureOutput<TConfig, TProcedure>>;
40
+ export type Resolver<TDef extends ResolverDef> = (
41
+ input: TDef['input'],
42
+ opts?: ProcedureOptions,
43
+ ) => Promise<TDef['output']>;
42
44
 
43
- type SubscriptionResolver<
44
- TConfig extends AnyRootConfig,
45
- TProcedure extends AnyProcedure,
46
- > = (
47
- ...args: [
48
- input: ProcedureArgs<TProcedure['_def']>[0],
49
- opts: Partial<
50
- TRPCSubscriptionObserver<
51
- inferTransformedSubscriptionOutput<TConfig, TProcedure>,
52
- TRPCClientError<TConfig>
53
- >
54
- > &
55
- ProcedureArgs<TProcedure['_def']>[1],
56
- ]
45
+ type SubscriptionResolver<TDef extends ResolverDef> = (
46
+ input: TDef['input'],
47
+ opts?: Partial<
48
+ TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>
49
+ > &
50
+ ProcedureOptions,
57
51
  ) => Unsubscribable;
58
52
 
59
53
  type DecorateProcedure<
60
- TConfig extends AnyRootConfig,
61
- TProcedure extends AnyProcedure,
62
- > = TProcedure extends AnyQueryProcedure
54
+ TType extends ProcedureType,
55
+ TDef extends ResolverDef,
56
+ > = TType extends 'query'
63
57
  ? {
64
- query: Resolver<TConfig, TProcedure>;
58
+ query: Resolver<TDef>;
65
59
  }
66
- : TProcedure extends AnyMutationProcedure
60
+ : TType extends 'mutation'
67
61
  ? {
68
- mutate: Resolver<TConfig, TProcedure>;
62
+ mutate: Resolver<TDef>;
69
63
  }
70
- : TProcedure extends AnySubscriptionProcedure
64
+ : TType extends 'subscription'
71
65
  ? {
72
- subscribe: SubscriptionResolver<TConfig, TProcedure>;
66
+ subscribe: SubscriptionResolver<TDef>;
73
67
  }
74
68
  : never;
75
69
 
@@ -78,12 +72,25 @@ type DecorateProcedure<
78
72
  */
79
73
  type DecoratedProcedureRecord<
80
74
  TRouter extends AnyRouter,
81
- TProcedures extends ProcedureRouterRecord,
75
+ TRecord extends RouterRecord,
82
76
  > = {
83
- [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
84
- ? DecoratedProcedureRecord<TRouter, TProcedures[TKey]['_def']['record']>
85
- : TProcedures[TKey] extends AnyProcedure
86
- ? DecorateProcedure<TRouter['_def']['_config'], TProcedures[TKey]>
77
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
78
+ ? $Value extends RouterRecord
79
+ ? DecoratedProcedureRecord<TRouter, $Value>
80
+ : $Value extends AnyProcedure
81
+ ? DecorateProcedure<
82
+ $Value['_def']['type'],
83
+ {
84
+ input: inferProcedureInput<$Value>;
85
+ output: inferTransformedProcedureOutput<
86
+ inferClientTypes<TRouter>,
87
+ $Value
88
+ >;
89
+ errorShape: inferClientTypes<TRouter>['errorShape'];
90
+ transformer: inferClientTypes<TRouter>['transformer'];
91
+ }
92
+ >
93
+ : never
87
94
  : never;
88
95
  };
89
96
 
@@ -107,10 +114,10 @@ export const clientCallTypeToProcedureType = (
107
114
  * Creates a proxy client and shows type errors if you have query names that collide with built-in properties
108
115
  */
109
116
  export type CreateTRPCClient<TRouter extends AnyRouter> =
110
- inferRouterClient<TRouter> extends infer $ProcedureRecord
111
- ? UntypedClientProperties & keyof $ProcedureRecord extends never
117
+ inferRouterClient<TRouter> extends infer $Value
118
+ ? UntypedClientProperties & keyof $Value extends never
112
119
  ? inferRouterClient<TRouter>
113
- : IntersectionError<UntypedClientProperties & keyof $ProcedureRecord>
120
+ : IntersectionError<UntypedClientProperties & keyof $Value>
114
121
  : never;
115
122
 
116
123
  /**
@@ -1,8 +1,6 @@
1
- import { AnyRouter } from '@trpc/server';
2
- import {
3
- CreateTRPCClientOptions,
4
- TRPCUntypedClient,
5
- } from './internals/TRPCUntypedClient';
1
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { CreateTRPCClientOptions } from './internals/TRPCUntypedClient';
3
+ import { TRPCUntypedClient } from './internals/TRPCUntypedClient';
6
4
 
7
5
  export function createTRPCUntypedClient<TRouter extends AnyRouter>(
8
6
  opts: CreateTRPCClientOptions<TRouter>,
package/src/getFetch.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FetchEsque, NativeFetchEsque } from './internals/types';
1
+ import type { FetchEsque, NativeFetchEsque } from './internals/types';
2
2
 
3
3
  type AnyFn = (...args: any[]) => unknown;
4
4
 
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // TODO: Be explicit about what we export here
2
+
1
3
  export * from './createTRPCUntypedClient';
2
4
  export * from './createTRPCClient';
3
5
  export * from './getFetch';
@@ -1,18 +1,15 @@
1
- import {
2
- AnyRouter,
3
- ClientDataTransformerOptions,
4
- CombinedDataTransformer,
5
- DataTransformerOptions,
6
- DefaultDataTransformer,
7
- } from '@trpc/server';
8
- import {
1
+ import type {
9
2
  inferObservableValue,
10
- observableToPromise,
11
- share,
12
3
  Unsubscribable,
13
4
  } from '@trpc/server/observable';
5
+ import { observableToPromise, share } from '@trpc/server/observable';
6
+ import type {
7
+ AnyRouter,
8
+ InferrableClientTypes,
9
+ TypeError,
10
+ } from '@trpc/server/unstable-core-do-not-import';
14
11
  import { createChain } from '../links/internals/createChain';
15
- import {
12
+ import type {
16
13
  OperationContext,
17
14
  OperationLink,
18
15
  TRPCClientRuntime,
@@ -20,41 +17,6 @@ import {
20
17
  } from '../links/types';
21
18
  import { TRPCClientError } from '../TRPCClientError';
22
19
 
23
- type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
24
- TRouter['_def']['_config']['transformer'] extends DefaultDataTransformer
25
- ? {
26
- /**
27
- * Data transformer
28
- *
29
- * You must use the same transformer on the backend and frontend
30
- * @link https://trpc.io/docs/data-transformers
31
- **/
32
- transformer?: 'You must set a transformer on the backend router';
33
- }
34
- : TRouter['_def']['_config']['transformer'] extends DataTransformerOptions
35
- ? {
36
- /**
37
- * Data transformer
38
- *
39
- * You must use the same transformer on the backend and frontend
40
- * @link https://trpc.io/docs/data-transformers
41
- **/
42
- transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer
43
- ? DataTransformerOptions
44
- : TRouter['_def']['_config']['transformer'];
45
- }
46
- : {
47
- /**
48
- * Data transformer
49
- *
50
- * You must use the same transformer on the backend and frontend
51
- * @link https://trpc.io/docs/data-transformers
52
- **/
53
- transformer?:
54
- | /** @deprecated **/ ClientDataTransformerOptions
55
- | CombinedDataTransformer;
56
- };
57
-
58
20
  type TRPCType = 'mutation' | 'query' | 'subscription';
59
21
  export interface TRPCRequestOptions {
60
22
  /**
@@ -73,10 +35,10 @@ export interface TRPCSubscriptionObserver<TValue, TError> {
73
35
  }
74
36
 
75
37
  /** @internal */
76
- export type CreateTRPCClientOptions<TRouter extends AnyRouter> =
77
- | CreateTRPCClientBaseOptions<TRouter> & {
78
- links: TRPCLink<TRouter>[];
79
- };
38
+ export type CreateTRPCClientOptions<TRouter extends InferrableClientTypes> = {
39
+ links: TRPCLink<TRouter>[];
40
+ transformer?: TypeError<'The transformer property has moved to httpLink/httpBatchLink/wsLink'>;
41
+ };
80
42
 
81
43
  /** @internal */
82
44
  export type UntypedClientProperties =
@@ -97,39 +59,7 @@ export class TRPCUntypedClient<TRouter extends AnyRouter> {
97
59
  constructor(opts: CreateTRPCClientOptions<TRouter>) {
98
60
  this.requestId = 0;
99
61
 
100
- const combinedTransformer: CombinedDataTransformer = (() => {
101
- const transformer = opts.transformer as
102
- | DataTransformerOptions
103
- | undefined;
104
-
105
- if (!transformer) {
106
- return {
107
- input: {
108
- serialize: (data) => data,
109
- deserialize: (data) => data,
110
- },
111
- output: {
112
- serialize: (data) => data,
113
- deserialize: (data) => data,
114
- },
115
- };
116
- }
117
- if ('input' in transformer) {
118
- return opts.transformer as CombinedDataTransformer;
119
- }
120
- return {
121
- input: transformer,
122
- output: transformer,
123
- };
124
- })();
125
-
126
- this.runtime = {
127
- transformer: {
128
- serialize: (data) => combinedTransformer.input.serialize(data),
129
- deserialize: (data) => combinedTransformer.output.deserialize(data),
130
- },
131
- combinedTransformer,
132
- };
62
+ this.runtime = {};
133
63
 
134
64
  // Initialize the links
135
65
  this.links = opts.links.map((link) => link(this.runtime));
@@ -222,7 +152,7 @@ export class TRPCUntypedClient<TRouter extends AnyRouter> {
222
152
  } else if (envelope.result.type === 'stopped') {
223
153
  opts.onStopped?.();
224
154
  } else {
225
- opts.onData?.((envelope.result as any).data);
155
+ opts.onData?.(envelope.result.data);
226
156
  }
227
157
  },
228
158
  error(err) {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { CancelFn, PromiseAndCancel } from '../links/types';
2
+ import type { CancelFn, PromiseAndCancel } from '../links/types';
3
3
 
4
4
  type BatchItem<TKey, TValue> = {
5
5
  aborted: boolean;
@@ -1,5 +1,5 @@
1
- import { Maybe } from '@trpc/server';
2
- import { AbortControllerEsque } from './types';
1
+ import type { Maybe } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { AbortControllerEsque } from './types';
3
3
 
4
4
  export function getAbortController(
5
5
  customAbortControllerImpl: Maybe<AbortControllerEsque>,
@@ -0,0 +1,76 @@
1
+ import type {
2
+ AnyClientTypes,
3
+ CombinedDataTransformer,
4
+ DataTransformerOptions,
5
+ TypeError,
6
+ } from '@trpc/server/unstable-core-do-not-import';
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export type CoercedTransformerParameters = {
12
+ transformer?: DataTransformerOptions;
13
+ };
14
+
15
+ type TransformerOptionYes = {
16
+ /**
17
+ * Data transformer
18
+ *
19
+ * You must use the same transformer on the backend and frontend
20
+ * @link https://trpc.io/docs/v11/data-transformers
21
+ **/
22
+ transformer: DataTransformerOptions;
23
+ };
24
+ type TransformerOptionNo = {
25
+ /**
26
+ * Data transformer
27
+ *
28
+ * You must use the same transformer on the backend and frontend
29
+ * @link https://trpc.io/docs/v11/data-transformers
30
+ **/
31
+ transformer?: TypeError<'You must define a transformer on your your `initTRPC`-object first'>;
32
+ };
33
+
34
+ /**
35
+ * @internal
36
+ */
37
+ export type TransformerOptions<
38
+ TRoot extends Pick<AnyClientTypes, 'transformer'>,
39
+ > = TRoot['transformer'] extends true
40
+ ? TransformerOptionYes
41
+ : TransformerOptionNo;
42
+ /**
43
+ * @internal
44
+ */
45
+
46
+ /**
47
+ * @internal
48
+ */
49
+ export function getTransformer(
50
+ transformer:
51
+ | TransformerOptions<{ transformer: false }>['transformer']
52
+ | TransformerOptions<{ transformer: true }>['transformer']
53
+ | undefined,
54
+ ): CombinedDataTransformer {
55
+ const _transformer =
56
+ transformer as CoercedTransformerParameters['transformer'];
57
+ if (!_transformer) {
58
+ return {
59
+ input: {
60
+ serialize: (data) => data,
61
+ deserialize: (data) => data,
62
+ },
63
+ output: {
64
+ serialize: (data) => data,
65
+ deserialize: (data) => data,
66
+ },
67
+ };
68
+ }
69
+ if ('input' in _transformer) {
70
+ return _transformer;
71
+ }
72
+ return {
73
+ input: _transformer,
74
+ output: _transformer,
75
+ };
76
+ }
@@ -78,12 +78,19 @@ export type WebReadableStreamEsque = {
78
78
  getReader: () => ReadableStreamDefaultReader<Uint8Array>;
79
79
  };
80
80
 
81
+ export type NodeJSReadableStreamEsque = {
82
+ on(
83
+ eventName: string | symbol,
84
+ listener: (...args: any[]) => void,
85
+ ): NodeJSReadableStreamEsque;
86
+ };
87
+
81
88
  /**
82
89
  * A subset of the standard Response properties needed by tRPC internally.
83
90
  * @see Response from lib.dom.d.ts
84
91
  */
85
92
  export interface ResponseEsque {
86
- readonly body?: NodeJS.ReadableStream | WebReadableStreamEsque | null;
93
+ readonly body?: NodeJSReadableStreamEsque | WebReadableStreamEsque | null;
87
94
  /**
88
95
  * @remarks
89
96
  * The built-in Response::json() method returns Promise<any>, but
@@ -1,16 +1,18 @@
1
- import { NonEmptyArray } from '../internals/types';
2
- import { HTTPLinkBaseOptions } from './internals/httpUtils';
3
- import { HTTPHeaders, Operation } from './types';
1
+ import type { AnyClientTypes } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { NonEmptyArray } from '../internals/types';
3
+ import type { HTTPLinkBaseOptions } from './internals/httpUtils';
4
+ import type { HTTPHeaders, Operation } from './types';
4
5
 
5
- export interface HTTPBatchLinkOptions extends HTTPLinkBaseOptions {
6
- maxURLLength?: number;
7
- /**
8
- * Headers to be set on outgoing requests or a callback that of said headers
9
- * @link http://trpc.io/docs/client/headers
10
- */
11
- headers?:
12
- | HTTPHeaders
13
- | ((opts: {
14
- opList: NonEmptyArray<Operation>;
15
- }) => HTTPHeaders | Promise<HTTPHeaders>);
16
- }
6
+ export type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> =
7
+ HTTPLinkBaseOptions<TRoot> & {
8
+ maxURLLength?: number;
9
+ /**
10
+ * Headers to be set on outgoing requests or a callback that of said headers
11
+ * @link http://trpc.io/docs/client/headers
12
+ */
13
+ headers?:
14
+ | HTTPHeaders
15
+ | ((opts: {
16
+ opList: NonEmptyArray<Operation>;
17
+ }) => HTTPHeaders | Promise<HTTPHeaders>);
18
+ };