@trpc/server 11.0.0-rc.361 → 11.0.0-rc.362

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 (173) hide show
  1. package/dist/@trpc/server/http.d.ts +7 -5
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/@trpc/server/index.d.ts +1 -2
  4. package/dist/@trpc/server/index.d.ts.map +1 -1
  5. package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
  6. package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
  7. package/dist/adapters/aws-lambda/getPlanner.js +143 -0
  8. package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
  9. package/dist/adapters/aws-lambda/index.d.ts +12 -9
  10. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  11. package/dist/adapters/aws-lambda/index.js +7 -76
  12. package/dist/adapters/aws-lambda/index.mjs +9 -72
  13. package/dist/adapters/express.js +1 -0
  14. package/dist/adapters/express.mjs +1 -0
  15. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
  16. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  17. package/dist/adapters/fastify/fastifyRequestHandler.js +12 -63
  18. package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -64
  19. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
  20. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  21. package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -2
  22. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  23. package/dist/adapters/fetch/fetchRequestHandler.js +28 -85
  24. package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
  25. package/dist/adapters/fetch/types.d.ts +2 -2
  26. package/dist/adapters/fetch/types.d.ts.map +1 -1
  27. package/dist/adapters/next.js +1 -1
  28. package/dist/adapters/next.mjs +1 -1
  29. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
  30. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
  31. package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
  32. package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
  33. package/dist/adapters/node-http/index.d.ts +1 -0
  34. package/dist/adapters/node-http/index.d.ts.map +1 -1
  35. package/dist/adapters/node-http/index.js +2 -0
  36. package/dist/adapters/node-http/index.mjs +1 -0
  37. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
  38. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  39. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +27 -70
  40. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
  41. package/dist/adapters/node-http/types.d.ts +7 -8
  42. package/dist/adapters/node-http/types.d.ts.map +1 -1
  43. package/dist/adapters/ws.js +1 -1
  44. package/dist/adapters/ws.mjs +1 -1
  45. package/dist/bundle-analysis.json +180 -277
  46. package/dist/http.js +4 -2
  47. package/dist/http.mjs +2 -1
  48. package/dist/index.js +2 -4
  49. package/dist/index.mjs +1 -2
  50. package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
  51. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  52. package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
  53. package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
  54. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
  55. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
  56. package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
  57. package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
  58. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
  59. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
  60. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +7 -43
  61. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
  62. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +119 -134
  63. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +119 -134
  64. package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
  65. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  66. package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
  67. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
  68. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  69. package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
  70. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
  71. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -9
  72. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  73. package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
  74. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  75. package/dist/unstable-core-do-not-import/utils.js +2 -0
  76. package/dist/unstable-core-do-not-import/utils.mjs +2 -1
  77. package/dist/unstable-core-do-not-import.d.ts +9 -3
  78. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  79. package/dist/unstable-core-do-not-import.js +11 -7
  80. package/dist/unstable-core-do-not-import.mjs +7 -5
  81. package/package.json +3 -13
  82. package/src/@trpc/server/http.ts +7 -12
  83. package/src/@trpc/server/index.ts +0 -3
  84. package/src/adapters/aws-lambda/getPlanner.ts +191 -0
  85. package/src/adapters/aws-lambda/index.ts +43 -107
  86. package/src/adapters/express.ts +1 -1
  87. package/src/adapters/fastify/fastifyRequestHandler.ts +40 -89
  88. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
  89. package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
  90. package/src/adapters/fetch/types.ts +4 -2
  91. package/src/adapters/next.ts +1 -1
  92. package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
  93. package/src/adapters/node-http/index.ts +1 -0
  94. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -97
  95. package/src/adapters/node-http/types.ts +27 -37
  96. package/src/adapters/standalone.ts +1 -1
  97. package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
  98. package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
  99. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
  100. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +135 -210
  101. package/src/unstable-core-do-not-import/http/types.ts +25 -30
  102. package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
  103. package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
  104. package/src/unstable-core-do-not-import/utils.ts +4 -0
  105. package/src/unstable-core-do-not-import.ts +9 -3
  106. package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
  107. package/adapters/node-http/content-type/form-data/index.js +0 -1
  108. package/adapters/node-http/content-type/json/index.d.ts +0 -1
  109. package/adapters/node-http/content-type/json/index.js +0 -1
  110. package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
  111. package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
  112. package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
  113. package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
  114. package/dist/adapters/aws-lambda/utils.d.ts +0 -31
  115. package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
  116. package/dist/adapters/aws-lambda/utils.js +0 -111
  117. package/dist/adapters/aws-lambda/utils.mjs +0 -103
  118. package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
  119. package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
  120. package/dist/adapters/content-handlers/concurrentCache.js +0 -17
  121. package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
  122. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
  123. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
  124. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
  125. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
  126. package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
  127. package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
  128. package/dist/adapters/fastify/content-type/json/index.js +0 -62
  129. package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
  130. package/dist/adapters/fastify/types.d.ts +0 -11
  131. package/dist/adapters/fastify/types.d.ts.map +0 -1
  132. package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
  133. package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
  134. package/dist/adapters/fetch/content-type/json/index.js +0 -55
  135. package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
  136. package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
  137. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  138. package/dist/adapters/node-http/content-type/form-data/index.js +0 -32
  139. package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
  140. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  141. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  142. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -45
  143. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
  144. package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
  145. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  146. package/dist/adapters/node-http/content-type/json/index.js +0 -68
  147. package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
  148. package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
  149. package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
  150. package/dist/adapters/node-http/content-type/octet/index.js +0 -19
  151. package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
  152. package/dist/adapters/node-http/content-type/types.d.ts +0 -8
  153. package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
  154. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
  155. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
  156. package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
  157. package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
  158. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
  159. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  160. package/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
  161. package/src/adapters/aws-lambda/utils.ts +0 -170
  162. package/src/adapters/content-handlers/concurrentCache.ts +0 -16
  163. package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
  164. package/src/adapters/fastify/content-type/json/index.ts +0 -106
  165. package/src/adapters/fastify/types.ts +0 -22
  166. package/src/adapters/fetch/content-type/json/index.ts +0 -90
  167. package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
  168. package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
  169. package/src/adapters/node-http/content-type/json/index.ts +0 -100
  170. package/src/adapters/node-http/content-type/octet/index.ts +0 -27
  171. package/src/adapters/node-http/content-type/types.ts +0 -19
  172. package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
  173. package/src/unstable-core-do-not-import/http/index.ts +0 -28
@@ -4,6 +4,8 @@ var getErrorShape = require('../error/getErrorShape.js');
4
4
  var TRPCError = require('../error/TRPCError.js');
5
5
  var router = require('../router.js');
6
6
  var transformer = require('../transformer.js');
7
+ var batchStreamFormatter = require('./batchStreamFormatter.js');
8
+ var contentType = require('./contentType.js');
7
9
  var getHTTPStatusCode = require('./getHTTPStatusCode.js');
8
10
 
9
11
  const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
@@ -11,25 +13,45 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
11
13
  POST: 'mutation'
12
14
  };
13
15
  function initResponse(initOpts) {
14
- const { ctx , paths , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
16
+ const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
15
17
  let status = untransformedJSON ? getHTTPStatusCode.getHTTPStatusCode(untransformedJSON) : 200;
16
- const headers = {
17
- 'Content-Type': 'application/json'
18
- };
18
+ const headers = new Headers([
19
+ [
20
+ 'Content-Type',
21
+ 'application/json'
22
+ ]
23
+ ]);
19
24
  const eagerGeneration = !untransformedJSON;
20
25
  const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
21
26
  untransformedJSON
22
27
  ];
23
28
  const meta = responseMeta?.({
24
29
  ctx,
25
- paths,
30
+ info,
31
+ paths: info?.calls.map((call)=>call.path),
26
32
  type,
27
33
  data,
28
34
  errors,
29
35
  eagerGeneration
30
36
  }) ?? {};
31
- for (const [key, value] of Object.entries(meta.headers ?? {})){
32
- headers[key] = value;
37
+ if (meta.headers) {
38
+ if (meta.headers instanceof Headers) {
39
+ for (const [key, value] of meta.headers.entries()){
40
+ headers.append(key, value);
41
+ }
42
+ } else {
43
+ /**
44
+ * @deprecated, delete in v12
45
+ */ for (const [key1, value1] of Object.entries(meta.headers)){
46
+ if (Array.isArray(value1)) {
47
+ for (const v of value1){
48
+ headers.append(key1, v);
49
+ }
50
+ } else if (typeof value1 === 'string') {
51
+ headers.set(key1, value1);
52
+ }
53
+ }
54
+ }
33
55
  }
34
56
  if (meta.status) {
35
57
  status = meta.status;
@@ -68,79 +90,54 @@ function caughtErrorToData(cause, errorOpts) {
68
90
  body
69
91
  };
70
92
  }
71
- // implementation
72
- async function resolveHTTPResponse(opts) {
73
- const { router: router$1 , req , unstable_onHead , unstable_onChunk } = opts;
93
+ async function resolveResponse(opts) {
94
+ const { router: router$1 , req } = opts;
95
+ const url = new URL(req.url);
74
96
  if (req.method === 'HEAD') {
75
97
  // can be used for lambda warmup
76
- const headResponse = {
98
+ return new Response(null, {
77
99
  status: 204
78
- };
79
- unstable_onHead?.(headResponse, false);
80
- unstable_onChunk?.([
81
- -1,
82
- ''
83
- ]);
84
- return headResponse;
100
+ });
85
101
  }
86
102
  const allowBatching = opts.allowBatching ?? opts.batching?.enabled ?? true;
87
- const allowMethodOverride = opts.allowMethodOverride ?? false;
103
+ const allowMethodOverride = (opts.allowMethodOverride ?? false) && req.method === 'POST';
88
104
  const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
89
105
  let ctx = undefined;
90
- let paths;
91
- const isBatchCall = !!req.query.get('batch');
92
- const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
106
+ let info = undefined;
107
+ const isStreamCall = req.headers.get('trpc-batch-mode') === 'stream';
93
108
  try {
94
- if (isBatchCall && !allowBatching) {
109
+ info = contentType.getRequestInfo({
110
+ req,
111
+ path: decodeURIComponent(opts.path),
112
+ config: router$1._def._config,
113
+ searchParams: url.searchParams
114
+ });
115
+ // we create context early so that error handlers may access context information
116
+ ctx = await opts.createContext({
117
+ info
118
+ });
119
+ if (opts.error) {
120
+ throw opts.error;
121
+ }
122
+ if (info.isBatchCall && !allowBatching) {
95
123
  throw new TRPCError.TRPCError({
96
124
  code: 'BAD_REQUEST',
97
125
  message: `Batching is not enabled on the server`
98
126
  });
99
127
  }
100
- /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
101
- throw new TRPCError.TRPCError({
102
- message: 'Subscriptions should use wsLink',
103
- code: 'METHOD_NOT_SUPPORTED'
104
- });
105
- }
106
128
  if (type === 'unknown') {
107
129
  throw new TRPCError.TRPCError({
108
130
  message: `Unexpected request method ${req.method}`,
109
131
  code: 'METHOD_NOT_SUPPORTED'
110
132
  });
111
133
  }
112
- paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
113
- opts.path
114
- ];
115
- const info = {
116
- isBatchCall,
117
- calls: paths.map((path)=>({
118
- path,
119
- type
120
- }))
121
- };
122
- ctx = await opts.createContext({
123
- info
124
- });
125
134
  const errors = [];
126
- const promises = paths.map(async (path, index)=>{
127
- async function getRawInput() {
128
- return await opts.getInput({
129
- isBatchCall,
130
- batch: index
131
- });
132
- }
135
+ const promises = info.calls.map(async (call)=>{
133
136
  try {
134
- if (opts.error) {
135
- // sometimes an error may be generated above this function in the stack
136
- // for instance a 405 error if the method is not supported
137
- // But we need to handle it here to ensure the error is formatted correctly
138
- throw opts.error;
139
- }
140
137
  const data = await router.callProcedure({
141
138
  procedures: opts.router._def.procedures,
142
- path,
143
- getRawInput: getRawInput,
139
+ path: call.path,
140
+ getRawInput: call.getRawInput,
144
141
  ctx,
145
142
  type,
146
143
  allowMethodOverride
@@ -153,16 +150,10 @@ async function resolveHTTPResponse(opts) {
153
150
  } catch (cause) {
154
151
  const error = TRPCError.getTRPCErrorFromUnknown(cause);
155
152
  errors.push(error);
156
- let input;
157
- try {
158
- input = await getRawInput();
159
- } catch (e) {
160
- // if `getRawInput` fails, we can't include the input in the error
161
- input = undefined;
162
- }
153
+ const input = call.result();
163
154
  opts.onError?.({
164
155
  error,
165
- path,
156
+ path: call.path,
166
157
  input,
167
158
  ctx,
168
159
  type: type,
@@ -173,7 +164,7 @@ async function resolveHTTPResponse(opts) {
173
164
  config: opts.router._def._config,
174
165
  error,
175
166
  type,
176
- path,
167
+ path: call.path,
177
168
  input,
178
169
  ctx
179
170
  })
@@ -187,79 +178,79 @@ async function resolveHTTPResponse(opts) {
187
178
  * - create headers with known response body
188
179
  * - return a complete HTTPResponse
189
180
  */ const untransformedJSON = await Promise.all(promises);
190
- const headResponse1 = initResponse({
181
+ const errors1 = untransformedJSON.flatMap((response)=>'error' in response ? [
182
+ response.error
183
+ ] : []);
184
+ const headResponse = initResponse({
191
185
  ctx,
192
- paths,
186
+ info,
193
187
  type,
194
188
  responseMeta: opts.responseMeta,
195
189
  untransformedJSON,
196
- errors
190
+ errors: errors1
197
191
  });
198
- unstable_onHead?.(headResponse1, false);
199
192
  // return body stuff
200
- const result = isBatchCall ? untransformedJSON : untransformedJSON[0]; // eslint-disable-line @typescript-eslint/no-non-null-assertion -- `untransformedJSON` should be the length of `paths` which should be at least 1 otherwise there wouldn't be a request at all
193
+ const result = info.isBatchCall ? untransformedJSON : untransformedJSON[0];
201
194
  const transformedJSON = transformer.transformTRPCResponse(router$1._def._config, result);
202
195
  const body = JSON.stringify(transformedJSON);
203
- unstable_onChunk?.([
204
- -1,
205
- body
206
- ]);
207
- return {
208
- status: headResponse1.status,
209
- headers: headResponse1.headers,
210
- body
211
- };
196
+ return new Response(body, {
197
+ status: headResponse.status,
198
+ headers: headResponse.headers
199
+ });
212
200
  }
213
201
  /**
214
202
  * Streaming response:
215
203
  * - block on none, call `onChunk` as soon as each response is ready
216
204
  * - create headers with minimal data (cannot know the response body in advance)
217
205
  * - return void
218
- */ const headResponse2 = initResponse({
206
+ */ const headResponse1 = initResponse({
219
207
  ctx,
220
- paths,
208
+ info,
221
209
  type,
222
- responseMeta: opts.responseMeta
210
+ responseMeta: opts.responseMeta,
211
+ errors: []
223
212
  });
224
- unstable_onHead(headResponse2, true);
225
- const indexedPromises = new Map(promises.map((promise, index)=>[
226
- index,
227
- promise.then((r)=>[
228
- index,
229
- r
230
- ])
231
- ]));
232
- for (const _ of paths){
233
- const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
234
- indexedPromises.delete(index);
235
- try {
236
- const transformedJSON1 = transformer.transformTRPCResponse(router$1._def._config, untransformedJSON1);
237
- const body1 = JSON.stringify(transformedJSON1);
238
- unstable_onChunk([
213
+ const encoder = new TextEncoderStream();
214
+ const stream = encoder.readable;
215
+ const controller = encoder.writable.getWriter();
216
+ async function exec() {
217
+ const indexedPromises = new Map(promises.map((promise, index)=>[
239
218
  index,
240
- body1
241
- ]);
242
- } catch (cause) {
243
- const path = paths[index];
244
- const input = await opts.getInput({
245
- isBatchCall,
246
- batch: index
247
- });
248
- const { body: body2 } = caughtErrorToData(cause, {
249
- opts,
250
- ctx,
251
- type,
252
- path,
253
- input
254
- });
255
- unstable_onChunk([
256
- index,
257
- body2
258
- ]);
219
+ promise.then((r)=>[
220
+ index,
221
+ r
222
+ ])
223
+ ]));
224
+ const formatter = batchStreamFormatter.getBatchStreamFormatter();
225
+ while(indexedPromises.size > 0){
226
+ const [index, untransformedJSON] = await Promise.race(indexedPromises.values());
227
+ indexedPromises.delete(index);
228
+ try {
229
+ const transformedJSON = transformer.transformTRPCResponse(router$1._def._config, untransformedJSON);
230
+ const body = JSON.stringify(transformedJSON);
231
+ await controller.write(formatter(index, body));
232
+ } catch (cause) {
233
+ const call = info.calls[index];
234
+ const input = call.result();
235
+ const { body: body1 } = caughtErrorToData(cause, {
236
+ opts,
237
+ ctx,
238
+ type,
239
+ path: call.path,
240
+ input
241
+ });
242
+ await controller.write(formatter(index, body1));
243
+ }
259
244
  }
245
+ await controller.write(formatter.end());
246
+ await controller.close();
260
247
  }
261
- return;
262
- } catch (cause1) {
248
+ exec().catch((err)=>controller.abort(err));
249
+ return new Response(stream, {
250
+ headers: headResponse1.headers,
251
+ status: headResponse1.status
252
+ });
253
+ } catch (cause) {
263
254
  // we get here if
264
255
  // - batching is called when it's not enabled
265
256
  // - `createContext()` throws
@@ -267,32 +258,26 @@ async function resolveHTTPResponse(opts) {
267
258
  // - post body is too large
268
259
  // - input deserialization fails
269
260
  // - `errorFormatter` return value is malformed
270
- const { error , untransformedJSON: untransformedJSON2 , body: body3 } = caughtErrorToData(cause1, {
261
+ const { error , untransformedJSON: untransformedJSON1 , body: body1 } = caughtErrorToData(cause, {
271
262
  opts,
272
263
  ctx,
273
264
  type
274
265
  });
275
- const headResponse3 = initResponse({
266
+ const headResponse2 = initResponse({
276
267
  ctx,
277
- paths,
268
+ info,
278
269
  type,
279
270
  responseMeta: opts.responseMeta,
280
- untransformedJSON: untransformedJSON2,
271
+ untransformedJSON: untransformedJSON1,
281
272
  errors: [
282
273
  error
283
274
  ]
284
275
  });
285
- unstable_onHead?.(headResponse3, false);
286
- unstable_onChunk?.([
287
- -1,
288
- body3
289
- ]);
290
- return {
291
- status: headResponse3.status,
292
- headers: headResponse3.headers,
293
- body: body3
294
- };
276
+ return new Response(body1, {
277
+ status: headResponse2.status,
278
+ headers: headResponse2.headers
279
+ });
295
280
  }
296
281
  }
297
282
 
298
- exports.resolveHTTPResponse = resolveHTTPResponse;
283
+ exports.resolveResponse = resolveResponse;