@trpc/client 11.0.0-next.91 → 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
@@ -1,13 +1,14 @@
1
- import { NonEmptyArray } from '../internals/types';
2
- import { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
3
- import {
4
- createHTTPBatchLink,
5
- RequesterFn,
6
- } from './internals/createHTTPBatchLink';
1
+ import type { AnyRootTypes } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { NonEmptyArray } from '../internals/types';
3
+ import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
4
+ import type { RequesterFn } from './internals/createHTTPBatchLink';
5
+ import { createHTTPBatchLink } from './internals/createHTTPBatchLink';
7
6
  import { jsonHttpRequester } from './internals/httpUtils';
8
- import { Operation } from './types';
7
+ import type { Operation } from './types';
9
8
 
10
- const batchRequester: RequesterFn<HTTPBatchLinkOptions> = (requesterOpts) => {
9
+ const batchRequester: RequesterFn<HTTPBatchLinkOptions<AnyRootTypes>> = (
10
+ requesterOpts,
11
+ ) => {
11
12
  return (batchOps) => {
12
13
  const path = batchOps.map((op) => op.path).join(',');
13
14
  const inputs = batchOps.map((op) => op.input);
@@ -1,24 +1,24 @@
1
- import { NonEmptyArray } from '../internals/types';
2
- import { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
3
- import {
4
- createHTTPBatchLink,
5
- RequesterFn,
6
- } from './internals/createHTTPBatchLink';
1
+ import type { AnyRootTypes } from '@trpc/server/unstable-core-do-not-import';
2
+ import type { NonEmptyArray } from '../internals/types';
3
+ import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
4
+ import type { RequesterFn } from './internals/createHTTPBatchLink';
5
+ import { createHTTPBatchLink } from './internals/createHTTPBatchLink';
7
6
  import { getTextDecoder } from './internals/getTextDecoder';
8
7
  import { streamingJsonHttpRequester } from './internals/parseJSONStream';
9
- import { TextDecoderEsque } from './internals/streamingUtils';
10
- import { Operation } from './types';
8
+ import type { TextDecoderEsque } from './internals/streamingUtils';
9
+ import type { Operation } from './types';
11
10
 
12
- export interface HTTPBatchStreamLinkOptions extends HTTPBatchLinkOptions {
13
- /**
14
- * Will default to the webAPI `TextDecoder`,
15
- * but you can use this option if your client
16
- * runtime doesn't provide it.
17
- */
18
- textDecoder?: TextDecoderEsque;
19
- }
11
+ export type HTTPBatchStreamLinkOptions<TRoot extends AnyRootTypes> =
12
+ HTTPBatchLinkOptions<TRoot> & {
13
+ /**
14
+ * Will default to the webAPI `TextDecoder`,
15
+ * but you can use this option if your client
16
+ * runtime doesn't provide it.
17
+ */
18
+ textDecoder?: TextDecoderEsque;
19
+ };
20
20
 
21
- const streamRequester: RequesterFn<HTTPBatchStreamLinkOptions> = (
21
+ const streamRequester: RequesterFn<HTTPBatchStreamLinkOptions<AnyRootTypes>> = (
22
22
  requesterOpts,
23
23
  ) => {
24
24
  const textDecoder = getTextDecoder(requesterOpts.opts.textDecoder);
@@ -1,15 +1,6 @@
1
1
  import { httpLinkFactory } from './httpLink';
2
- import { GetBody, httpRequest, Requester } from './internals/httpUtils';
3
-
4
- const getBody: GetBody = (opts) => {
5
- if (!('input' in opts)) {
6
- return undefined;
7
- }
8
- if (!(opts.input instanceof FormData)) {
9
- throw new Error('Input is not FormData');
10
- }
11
- return opts.input;
12
- };
2
+ import type { Requester } from './internals/httpUtils';
3
+ import { httpRequest } from './internals/httpUtils';
13
4
 
14
5
  const formDataRequester: Requester = (opts) => {
15
6
  if (opts.type !== 'mutation') {
@@ -21,7 +12,15 @@ const formDataRequester: Requester = (opts) => {
21
12
  getUrl() {
22
13
  return `${opts.url}/${opts.path}`;
23
14
  },
24
- getBody,
15
+ getBody(opts) {
16
+ if (!('input' in opts)) {
17
+ return undefined;
18
+ }
19
+ if (!(opts.input instanceof FormData)) {
20
+ throw new Error('Input is not FormData');
21
+ }
22
+ return opts.input;
23
+ },
25
24
  });
26
25
  };
27
26
 
@@ -1,39 +1,44 @@
1
- import { AnyRouter } from '@trpc/server';
2
1
  import { observable } from '@trpc/server/observable';
3
- import { transformResult } from '../shared/transformResult';
2
+ import type {
3
+ AnyRootTypes,
4
+ AnyRouter,
5
+ } from '@trpc/server/unstable-core-do-not-import';
6
+ import { transformResult } from '@trpc/server/unstable-core-do-not-import';
4
7
  import { TRPCClientError } from '../TRPCClientError';
5
- import {
8
+ import type {
6
9
  HTTPLinkBaseOptions,
7
10
  HTTPResult,
8
- jsonHttpRequester,
9
11
  Requester,
12
+ } from './internals/httpUtils';
13
+ import {
14
+ jsonHttpRequester,
10
15
  resolveHTTPLinkOptions,
11
16
  } from './internals/httpUtils';
12
- import { HTTPHeaders, Operation, TRPCLink } from './types';
17
+ import type { HTTPHeaders, Operation, TRPCLink } from './types';
13
18
 
14
- export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
15
- /**
16
- * Headers to be set on outgoing requests or a callback that of said headers
17
- * @link http://trpc.io/docs/client/headers
18
- */
19
- headers?:
20
- | HTTPHeaders
21
- | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);
22
- }
19
+ export type HTTPLinkOptions<TRoot extends AnyRootTypes> =
20
+ HTTPLinkBaseOptions<TRoot> & {
21
+ /**
22
+ * Headers to be set on outgoing requests or a callback that of said headers
23
+ * @link http://trpc.io/docs/client/headers
24
+ */
25
+ headers?:
26
+ | HTTPHeaders
27
+ | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);
28
+ };
23
29
 
24
30
  export function httpLinkFactory(factoryOpts: { requester: Requester }) {
25
31
  return <TRouter extends AnyRouter>(
26
- opts: HTTPLinkOptions,
32
+ opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,
27
33
  ): TRPCLink<TRouter> => {
28
34
  const resolvedOpts = resolveHTTPLinkOptions(opts);
29
35
 
30
- return (runtime) =>
36
+ return () =>
31
37
  ({ op }) =>
32
38
  observable((observer) => {
33
39
  const { path, input, type } = op;
34
40
  const { promise, cancel } = factoryOpts.requester({
35
41
  ...resolvedOpts,
36
- runtime,
37
42
  type,
38
43
  path,
39
44
  input,
@@ -53,7 +58,10 @@ export function httpLinkFactory(factoryOpts: { requester: Requester }) {
53
58
  promise
54
59
  .then((res) => {
55
60
  meta = res.meta;
56
- const transformed = transformResult(res.json, runtime);
61
+ const transformed = transformResult(
62
+ res.json,
63
+ resolvedOpts.transformer.output,
64
+ );
57
65
 
58
66
  if (!transformed.ok) {
59
67
  observer.error(
@@ -81,6 +89,6 @@ export function httpLinkFactory(factoryOpts: { requester: Requester }) {
81
89
  }
82
90
 
83
91
  /**
84
- * @see https://trpc.io/docs/client/links/httpLink
92
+ * @link https://trpc.io/docs/v11/client/links/httpLink
85
93
  */
86
94
  export const httpLink = httpLinkFactory({ requester: jsonHttpRequester });
@@ -1,6 +1,10 @@
1
- import { AnyRouter } from '@trpc/server';
2
1
  import { observable } from '@trpc/server/observable';
3
- import { Operation, OperationLink, OperationResultObservable } from '../types';
2
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
3
+ import type {
4
+ Operation,
5
+ OperationLink,
6
+ OperationResultObservable,
7
+ } from '../types';
4
8
 
5
9
  /** @internal */
6
10
  export function createChain<
@@ -1,21 +1,27 @@
1
- import { AnyRouter, ProcedureType } from '@trpc/server';
2
1
  import { observable } from '@trpc/server/observable';
2
+ import type {
3
+ AnyRootTypes,
4
+ AnyRouter,
5
+ inferClientTypes,
6
+ ProcedureType,
7
+ } from '@trpc/server/unstable-core-do-not-import';
8
+ import { transformResult } from '@trpc/server/unstable-core-do-not-import';
3
9
  import { dataLoader } from '../../internals/dataLoader';
4
- import { transformResult } from '../../shared/transformResult';
5
10
  import { TRPCClientError } from '../../TRPCClientError';
6
- import { HTTPBatchLinkOptions } from '../HTTPBatchLinkOptions';
7
- import { CancelFn, Operation, TRPCClientRuntime, TRPCLink } from '../types';
8
- import {
9
- getUrl,
10
- HTTPResult,
11
- ResolvedHTTPLinkOptions,
12
- resolveHTTPLinkOptions,
13
- } from './httpUtils';
11
+ import type { HTTPBatchLinkOptions } from '../HTTPBatchLinkOptions';
12
+ import type {
13
+ CancelFn,
14
+ Operation,
15
+ TRPCClientRuntime,
16
+ TRPCLink,
17
+ } from '../types';
18
+ import type { HTTPResult, ResolvedHTTPLinkOptions } from './httpUtils';
19
+ import { getUrl, resolveHTTPLinkOptions } from './httpUtils';
14
20
 
15
21
  /**
16
22
  * @internal
17
23
  */
18
- export type RequesterFn<TOptions extends HTTPBatchLinkOptions> = (
24
+ export type RequesterFn<TOptions extends HTTPBatchLinkOptions<AnyRootTypes>> = (
19
25
  requesterOpts: ResolvedHTTPLinkOptions & {
20
26
  runtime: TRPCClientRuntime;
21
27
  type: ProcedureType;
@@ -32,11 +38,11 @@ export type RequesterFn<TOptions extends HTTPBatchLinkOptions> = (
32
38
  /**
33
39
  * @internal
34
40
  */
35
- export function createHTTPBatchLink<TOptions extends HTTPBatchLinkOptions>(
36
- requester: RequesterFn<TOptions>,
41
+ export function createHTTPBatchLink(
42
+ requester: RequesterFn<HTTPBatchLinkOptions<AnyRootTypes>>,
37
43
  ) {
38
44
  return function httpBatchLink<TRouter extends AnyRouter>(
39
- opts: TOptions,
45
+ opts: HTTPBatchLinkOptions<inferClientTypes<TRouter>>,
40
46
  ): TRPCLink<TRouter> {
41
47
  const resolvedOpts = resolveHTTPLinkOptions(opts);
42
48
  const maxURLLength = opts.maxURLLength ?? Infinity;
@@ -54,7 +60,6 @@ export function createHTTPBatchLink<TOptions extends HTTPBatchLinkOptions>(
54
60
 
55
61
  const url = getUrl({
56
62
  ...resolvedOpts,
57
- runtime,
58
63
  type,
59
64
  path,
60
65
  inputs,
@@ -91,7 +96,10 @@ export function createHTTPBatchLink<TOptions extends HTTPBatchLinkOptions>(
91
96
  promise
92
97
  .then((res) => {
93
98
  _res = res;
94
- const transformed = transformResult(res.json, runtime);
99
+ const transformed = transformResult(
100
+ res.json,
101
+ resolvedOpts.transformer.output,
102
+ );
95
103
 
96
104
  if (!transformed.ok) {
97
105
  observer.error(
@@ -1,8 +1,9 @@
1
1
  /* istanbul ignore file -- @preserve */
2
2
  // We're not actually exporting this link
3
- import { AnyRouter } from '@trpc/server';
4
- import { Observable, observable, share } from '@trpc/server/observable';
5
- import { TRPCLink } from '../types';
3
+ import type { Observable } from '@trpc/server/observable';
4
+ import { observable, share } from '@trpc/server/observable';
5
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
6
+ import type { TRPCLink } from '../types';
6
7
 
7
8
  /**
8
9
  * @internal used for testing
@@ -1,4 +1,4 @@
1
- import { TextDecoderEsque } from './streamingUtils';
1
+ import type { TextDecoderEsque } from './streamingUtils';
2
2
 
3
3
  export function getTextDecoder(
4
4
  customTextDecoder?: TextDecoderEsque,
@@ -1,8 +1,12 @@
1
- import { ProcedureType } from '@trpc/server';
2
- import { TRPCResponse } from '@trpc/server/rpc';
1
+ import type {
2
+ AnyRootTypes,
3
+ CombinedDataTransformer,
4
+ ProcedureType,
5
+ TRPCResponse,
6
+ } from '@trpc/server/unstable-core-do-not-import';
3
7
  import { getFetch } from '../../getFetch';
4
8
  import { getAbortController } from '../../internals/getAbortController';
5
- import {
9
+ import type {
6
10
  AbortControllerEsque,
7
11
  AbortControllerInstanceEsque,
8
12
  FetchEsque,
@@ -10,13 +14,17 @@ import {
10
14
  ResponseEsque,
11
15
  } from '../../internals/types';
12
16
  import { TRPCClientError } from '../../TRPCClientError';
13
- import { TextDecoderEsque } from '../internals/streamingUtils';
14
- import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
17
+ import type { TransformerOptions } from '../../unstable-internals';
18
+ import { getTransformer } from '../../unstable-internals';
19
+ import type { TextDecoderEsque } from '../internals/streamingUtils';
20
+ import type { HTTPHeaders, PromiseAndCancel } from '../types';
15
21
 
16
22
  /**
17
23
  * @internal
18
24
  */
19
- export interface HTTPLinkBaseOptions {
25
+ export type HTTPLinkBaseOptions<
26
+ TRoot extends Pick<AnyRootTypes, 'transformer'>,
27
+ > = {
20
28
  url: string | URL;
21
29
  /**
22
30
  * Add ponyfill for fetch
@@ -26,21 +34,31 @@ export interface HTTPLinkBaseOptions {
26
34
  * Add ponyfill for AbortController
27
35
  */
28
36
  AbortController?: AbortControllerEsque | null;
29
- }
37
+ /**
38
+ * Send all requests `as POST`s requests regardless of the procedure type
39
+ * The HTTP handler must separately allow overriding the method. See:
40
+ * @link https://trpc.io/docs/rpc
41
+ */
42
+ methodOverride?: 'POST';
43
+ } & TransformerOptions<TRoot>;
30
44
 
31
45
  export interface ResolvedHTTPLinkOptions {
32
46
  url: string;
33
47
  fetch?: FetchEsque;
34
48
  AbortController: AbortControllerEsque | null;
49
+ transformer: CombinedDataTransformer;
50
+ methodOverride?: 'POST';
35
51
  }
36
52
 
37
53
  export function resolveHTTPLinkOptions(
38
- opts: HTTPLinkBaseOptions,
54
+ opts: HTTPLinkBaseOptions<AnyRootTypes>,
39
55
  ): ResolvedHTTPLinkOptions {
40
56
  return {
41
57
  url: opts.url.toString().replace(/\/$/, ''), // Remove any trailing slashes
42
58
  fetch: opts.fetch,
43
59
  AbortController: getAbortController(opts.AbortController),
60
+ transformer: getTransformer(opts.transformer),
61
+ methodOverride: opts.methodOverride,
44
62
  };
45
63
  }
46
64
 
@@ -68,14 +86,14 @@ export interface HTTPResult {
68
86
  }
69
87
 
70
88
  type GetInputOptions = {
71
- runtime: TRPCClientRuntime;
89
+ transformer: CombinedDataTransformer;
72
90
  } & ({ input: unknown } | { inputs: unknown[] });
73
91
 
74
92
  function getInput(opts: GetInputOptions) {
75
93
  return 'input' in opts
76
- ? opts.runtime.transformer.serialize(opts.input)
94
+ ? opts.transformer.input.serialize(opts.input)
77
95
  : arrayToDict(
78
- opts.inputs.map((_input) => opts.runtime.transformer.serialize(_input)),
96
+ opts.inputs.map((_input) => opts.transformer.input.serialize(_input)),
79
97
  );
80
98
  }
81
99
 
@@ -85,11 +103,8 @@ export type HTTPBaseRequestOptions = GetInputOptions &
85
103
  path: string;
86
104
  };
87
105
 
88
- export type GetUrl = (opts: HTTPBaseRequestOptions) => string;
89
- export type GetBody = (
90
- opts: HTTPBaseRequestOptions,
91
- ) => RequestInitEsque['body'];
92
-
106
+ type GetUrl = (opts: HTTPBaseRequestOptions) => string;
107
+ type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
93
108
  export type ContentOptions = {
94
109
  batchModeHeader?: 'stream';
95
110
  contentTypeHeader?: string;
@@ -105,7 +120,7 @@ export const getUrl: GetUrl = (opts) => {
105
120
  }
106
121
  if (opts.type === 'query') {
107
122
  const input = getInput(opts);
108
- if (input !== undefined) {
123
+ if (input !== undefined && opts.methodOverride !== 'POST') {
109
124
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
110
125
  }
111
126
  }
@@ -116,7 +131,7 @@ export const getUrl: GetUrl = (opts) => {
116
131
  };
117
132
 
118
133
  export const getBody: GetBody = (opts) => {
119
- if (opts.type === 'query') {
134
+ if (opts.type === 'query' && opts.methodOverride !== 'POST') {
120
135
  return undefined;
121
136
  }
122
137
  const input = getInput(opts);
@@ -151,7 +166,13 @@ export async function fetchHTTPResponse(
151
166
  const url = opts.getUrl(opts);
152
167
  const body = opts.getBody(opts);
153
168
  const { type } = opts;
154
- const resolvedHeaders = await opts.headers();
169
+ const resolvedHeaders = await (async () => {
170
+ const heads = await opts.headers();
171
+ if (Symbol.iterator in heads) {
172
+ return Object.fromEntries(heads);
173
+ }
174
+ return heads;
175
+ })();
155
176
  /* istanbul ignore if -- @preserve */
156
177
  if (type === 'subscription') {
157
178
  throw new Error('Subscriptions should use wsLink');
@@ -167,9 +188,9 @@ export async function fetchHTTPResponse(
167
188
  };
168
189
 
169
190
  return getFetch(opts.fetch)(url, {
170
- method: METHOD[type],
191
+ method: opts.methodOverride ?? METHOD[type],
171
192
  signal: ac?.signal,
172
- body: body,
193
+ body,
173
194
  headers,
174
195
  });
175
196
  }
@@ -1,15 +1,13 @@
1
1
  // Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
2
- import { TRPCResponse } from '@trpc/server/rpc';
3
- import { WebReadableStreamEsque } from '../../internals/types';
4
- import { HTTPHeaders } from '../types';
5
- import {
6
- fetchHTTPResponse,
7
- getBody,
8
- getUrl,
9
- HTTPBaseRequestOptions,
10
- HTTPResult,
11
- } from './httpUtils';
12
- import { TextDecoderEsque } from './streamingUtils';
2
+ import type { TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
3
+ import type {
4
+ NodeJSReadableStreamEsque,
5
+ WebReadableStreamEsque,
6
+ } from '../../internals/types';
7
+ import type { HTTPHeaders } from '../types';
8
+ import type { HTTPBaseRequestOptions, HTTPResult } from './httpUtils';
9
+ import { fetchHTTPResponse, getBody, getUrl } from './httpUtils';
10
+ import type { TextDecoderEsque } from './streamingUtils';
13
11
 
14
12
  /**
15
13
  * @internal
@@ -26,7 +24,7 @@ export async function parseJSONStream<TReturn>(opts: {
26
24
  /**
27
25
  * As given by `(await fetch(url)).body`
28
26
  */
29
- readableStream: NodeJS.ReadableStream | WebReadableStreamEsque;
27
+ readableStream: NodeJSReadableStreamEsque | WebReadableStreamEsque;
30
28
  /**
31
29
  * Called for each line of the stream
32
30
  */
@@ -69,7 +67,7 @@ export async function parseJSONStream<TReturn>(opts: {
69
67
  * @param onLine will be called for every line ('\n' delimited) in the stream
70
68
  */
71
69
  async function readLines(
72
- readableStream: NodeJS.ReadableStream | WebReadableStreamEsque,
70
+ readableStream: NodeJSReadableStreamEsque | WebReadableStreamEsque,
73
71
  onLine: (line: string) => void,
74
72
  textDecoder: TextDecoderEsque,
75
73
  ) {
@@ -106,7 +104,7 @@ async function readLines(
106
104
  * Handle NodeJS stream
107
105
  */
108
106
  function readNodeChunks(
109
- stream: NodeJS.ReadableStream,
107
+ stream: NodeJSReadableStreamEsque,
110
108
  onChunk: (chunk: Uint8Array) => void,
111
109
  ) {
112
110
  return new Promise<void>((resolve) => {
@@ -1,8 +1,9 @@
1
1
  /* istanbul ignore file -- @preserve */
2
2
  // We're not actually exporting this link
3
- import { AnyRouter } from '@trpc/server';
4
- import { observable, Unsubscribable } from '@trpc/server/observable';
5
- import { TRPCLink } from '../types';
3
+ import type { Unsubscribable } from '@trpc/server/observable';
4
+ import { observable } from '@trpc/server/observable';
5
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
6
+ import type { TRPCLink } from '../types';
6
7
 
7
8
  /**
8
9
  * @internal used for testing
@@ -5,10 +5,10 @@
5
5
  // Using triple-slash directive makes sure that it will be available,
6
6
  // even if end-user `tsconfig.json` omits it in the `lib` array.
7
7
 
8
- import { AnyRouter } from '@trpc/server';
9
8
  import { observable, tap } from '@trpc/server/observable';
10
- import { TRPCClientError } from '..';
11
- import { Operation, OperationResultEnvelope, TRPCLink } from './types';
9
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
10
+ import type { TRPCClientError } from '../TRPCClientError';
11
+ import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
12
12
 
13
13
  type ConsoleEsque = {
14
14
  log: (...args: any[]) => void;
@@ -135,7 +135,7 @@ function constructPartsAndArgs(
135
135
 
136
136
  const [light, dark] = palettes.css[type];
137
137
  const css = `
138
- background-color: #${direction === 'up' ? light : dark};
138
+ background-color: #${direction === 'up' ? light : dark};
139
139
  color: ${direction === 'up' ? 'black' : 'white'};
140
140
  padding: 2px;
141
141
  `;
@@ -196,7 +196,7 @@ const defaultLogger =
196
196
  };
197
197
 
198
198
  /**
199
- * @see https://trpc.io/docs/client/links/loggerLink
199
+ * @link https://trpc.io/docs/v11/client/links/loggerLink
200
200
  */
201
201
  export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
202
202
  opts: LoggerLinkOptions<TRouter> = {},
@@ -1,7 +1,7 @@
1
- import { AnyRouter } from '@trpc/server';
2
1
  import { observable } from '@trpc/server/observable';
2
+ import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
3
3
  import { createChain } from './internals/createChain';
4
- import { Operation, TRPCLink } from './types';
4
+ import type { Operation, TRPCLink } from './types';
5
5
 
6
6
  function asArray<TType>(value: TType | TType[]) {
7
7
  return Array.isArray(value) ? value : [value];
@@ -1,12 +1,11 @@
1
- import {
2
- AnyRouter,
3
- CombinedDataTransformer,
4
- DataTransformer,
5
- } from '@trpc/server';
6
- import { Observable, Observer } from '@trpc/server/observable';
7
- import { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/rpc';
8
- import { ResponseEsque } from '../internals/types';
9
- import { TRPCClientError } from '../TRPCClientError';
1
+ import type { Observable, Observer } from '@trpc/server/observable';
2
+ import type {
3
+ InferrableClientTypes,
4
+ TRPCResultMessage,
5
+ TRPCSuccessResponse,
6
+ } from '@trpc/server/unstable-core-do-not-import';
7
+ import type { ResponseEsque } from '../internals/types';
8
+ import type { TRPCClientError } from '../TRPCClientError';
10
9
 
11
10
  /**
12
11
  * @internal
@@ -37,10 +36,16 @@ export type Operation<TInput = unknown> = {
37
36
  context: OperationContext;
38
37
  };
39
38
 
39
+ interface HeadersInitEsque {
40
+ [Symbol.iterator](): IterableIterator<[string, string]>;
41
+ }
42
+
40
43
  /**
41
44
  * @internal
42
45
  */
43
- export type HTTPHeaders = Record<string, string[] | string | undefined>;
46
+ export type HTTPHeaders =
47
+ | HeadersInitEsque
48
+ | Record<string, string[] | string | undefined>;
44
49
 
45
50
  /**
46
51
  * The default `fetch` implementation has an overloaded signature. By convention this library
@@ -52,9 +57,7 @@ export type TRPCFetch = (
52
57
  ) => Promise<ResponseEsque>;
53
58
 
54
59
  export interface TRPCClientRuntime {
55
- transformer: DataTransformer;
56
- // FIXME: we should be able to remove this - added as `withTRPC()` needs it, but we can have it as an extra option on SSR instead
57
- combinedTransformer: CombinedDataTransformer;
60
+ // nothing here anymore
58
61
  }
59
62
 
60
63
  /**
@@ -71,33 +74,35 @@ export interface OperationResultEnvelope<TOutput> {
71
74
  * @internal
72
75
  */
73
76
  export type OperationResultObservable<
74
- TRouter extends AnyRouter,
77
+ TInferrable extends InferrableClientTypes,
75
78
  TOutput,
76
- > = Observable<OperationResultEnvelope<TOutput>, TRPCClientError<TRouter>>;
79
+ > = Observable<OperationResultEnvelope<TOutput>, TRPCClientError<TInferrable>>;
77
80
 
78
81
  /**
79
82
  * @internal
80
83
  */
81
84
  export type OperationResultObserver<
82
- TRouter extends AnyRouter,
85
+ TInferrable extends InferrableClientTypes,
83
86
  TOutput,
84
- > = Observer<OperationResultEnvelope<TOutput>, TRPCClientError<TRouter>>;
87
+ > = Observer<OperationResultEnvelope<TOutput>, TRPCClientError<TInferrable>>;
85
88
 
86
89
  /**
87
90
  * @internal
88
91
  */
89
92
  export type OperationLink<
90
- TRouter extends AnyRouter,
93
+ TInferrable extends InferrableClientTypes,
91
94
  TInput = unknown,
92
95
  TOutput = unknown,
93
96
  > = (opts: {
94
97
  op: Operation<TInput>;
95
- next: (op: Operation<TInput>) => OperationResultObservable<TRouter, TOutput>;
96
- }) => OperationResultObservable<TRouter, TOutput>;
98
+ next: (
99
+ op: Operation<TInput>,
100
+ ) => OperationResultObservable<TInferrable, TOutput>;
101
+ }) => OperationResultObservable<TInferrable, TOutput>;
97
102
 
98
103
  /**
99
104
  * @public
100
105
  */
101
- export type TRPCLink<TRouter extends AnyRouter> = (
106
+ export type TRPCLink<TInferrable extends InferrableClientTypes> = (
102
107
  opts: TRPCClientRuntime,
103
- ) => OperationLink<TRouter>;
108
+ ) => OperationLink<TInferrable>;