@trpc/server 10.28.2 → 10.29.0

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 (53) hide show
  1. package/dist/adapters/aws-lambda/index.js +1 -1
  2. package/dist/adapters/aws-lambda/index.mjs +1 -1
  3. package/dist/adapters/express.js +5 -4
  4. package/dist/adapters/express.mjs +5 -4
  5. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +1 -1
  6. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  7. package/dist/adapters/fastify/index.js +50 -15
  8. package/dist/adapters/fastify/index.mjs +50 -15
  9. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  10. package/dist/adapters/fetch/index.js +66 -20
  11. package/dist/adapters/fetch/index.mjs +66 -20
  12. package/dist/adapters/next.js +3 -2
  13. package/dist/adapters/next.mjs +3 -2
  14. package/dist/adapters/node-http/content-type/form-data/index.js +19 -46
  15. package/dist/adapters/node-http/content-type/form-data/index.mjs +19 -40
  16. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +7 -3
  17. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
  18. package/dist/adapters/node-http/index.js +5 -4
  19. package/dist/adapters/node-http/index.mjs +5 -4
  20. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  21. package/dist/adapters/standalone.js +5 -4
  22. package/dist/adapters/standalone.mjs +5 -4
  23. package/dist/batchStreamFormatter-2c1405a1.js +31 -0
  24. package/dist/batchStreamFormatter-93cdcdd4.js +32 -0
  25. package/dist/batchStreamFormatter-fc1ffb26.mjs +30 -0
  26. package/dist/http/batchStreamFormatter.d.ts +24 -0
  27. package/dist/http/batchStreamFormatter.d.ts.map +1 -0
  28. package/dist/http/index.d.ts +1 -0
  29. package/dist/http/index.d.ts.map +1 -1
  30. package/dist/http/index.js +3 -1
  31. package/dist/http/index.mjs +2 -1
  32. package/dist/http/internals/types.d.ts +7 -0
  33. package/dist/http/internals/types.d.ts.map +1 -1
  34. package/dist/http/resolveHTTPResponse.d.ts +36 -2
  35. package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
  36. package/dist/{nodeHTTPRequestHandler-bd47641d.js → nodeHTTPRequestHandler-53b9fc2d.js} +44 -12
  37. package/dist/{nodeHTTPRequestHandler-0f979796.mjs → nodeHTTPRequestHandler-bdad2781.mjs} +42 -13
  38. package/dist/{nodeHTTPRequestHandler-5bbf93f1.js → nodeHTTPRequestHandler-e637755a.js} +42 -13
  39. package/dist/resolveHTTPResponse-2bdf2cd7.js +256 -0
  40. package/dist/resolveHTTPResponse-2c307e04.js +284 -0
  41. package/dist/resolveHTTPResponse-a9be3d96.mjs +282 -0
  42. package/package.json +4 -4
  43. package/src/adapters/fastify/fastifyRequestHandler.ts +64 -17
  44. package/src/adapters/fetch/fetchRequestHandler.ts +72 -25
  45. package/src/adapters/node-http/content-type/form-data/streamSlice.ts +19 -21
  46. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +51 -12
  47. package/src/http/batchStreamFormatter.ts +29 -0
  48. package/src/http/index.ts +1 -0
  49. package/src/http/internals/types.ts +8 -0
  50. package/src/http/resolveHTTPResponse.ts +335 -124
  51. package/dist/resolveHTTPResponse-4e576698.mjs +0 -174
  52. package/dist/resolveHTTPResponse-9523b4e3.js +0 -176
  53. package/dist/resolveHTTPResponse-ba557d3e.js +0 -166
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var resolveHTTPResponse = require('./resolveHTTPResponse-9523b4e3.js');
3
+ require('./index-4a823936.js');
4
+ var resolveHTTPResponse = require('./resolveHTTPResponse-2c307e04.js');
5
+ var batchStreamFormatter = require('./batchStreamFormatter-93cdcdd4.js');
4
6
  var adapters_nodeHttp_contentType_json_index = require('./adapters/node-http/content-type/json/index.js');
5
7
 
6
8
  const defaultJSONContentTypeHandler = adapters_nodeHttp_contentType_json_index.nodeHTTPJSONContentTypeHandler();
@@ -31,7 +33,37 @@ async function nodeHTTPRequestHandler(opts) {
31
33
  query,
32
34
  body: bodyResult.ok ? bodyResult.data : undefined
33
35
  };
34
- const result = await resolveHTTPResponse.resolveHTTPResponse({
36
+ const onHead = (head)=>{
37
+ if ('status' in head && (!opts.res.statusCode || opts.res.statusCode === 200)) {
38
+ opts.res.statusCode = head.status;
39
+ }
40
+ for (const [key, value] of Object.entries(head.headers ?? {})){
41
+ /* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
42
+ continue;
43
+ }
44
+ opts.res.setHeader(key, value);
45
+ }
46
+ };
47
+ const formatter = batchStreamFormatter.getBatchStreamFormatter();
48
+ let isStream = false;
49
+ const onChunk = ([index, string])=>{
50
+ if (index === -1) {
51
+ /**
52
+ * Full response, no streaming. This can happen
53
+ * - if the response is an error
54
+ * - if response is empty (HEAD request)
55
+ */ opts.res.end(string);
56
+ return;
57
+ }
58
+ if (!isStream) {
59
+ opts.res.setHeader('Transfer-Encoding', 'chunked');
60
+ const vary = opts.res.getHeader('Vary');
61
+ opts.res.setHeader('Vary', vary ? 'trpc-batch-mode, ' + vary : 'trpc-batch-mode');
62
+ isStream = true;
63
+ }
64
+ opts.res.write(formatter(index, string));
65
+ };
66
+ await resolveHTTPResponse.resolveHTTPResponse({
35
67
  batching: opts.batching,
36
68
  responseMeta: opts.responseMeta,
37
69
  path: opts.path,
@@ -46,19 +78,16 @@ async function nodeHTTPRequestHandler(opts) {
46
78
  req: opts.req
47
79
  });
48
80
  },
49
- contentTypeHandler
81
+ contentTypeHandler,
82
+ onHead,
83
+ onChunk
50
84
  });
51
- const { res } = opts;
52
- if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
53
- res.statusCode = result.status;
54
- }
55
- for (const [key, value] of Object.entries(result.headers ?? {})){
56
- if (typeof value === 'undefined') {
57
- continue;
58
- }
59
- res.setHeader(key, value);
85
+ if (!isStream) {
86
+ return opts.res;
60
87
  }
61
- res.end(result.body);
88
+ opts.res.write(formatter.end());
89
+ opts.res.end();
90
+ return opts.res;
62
91
  });
63
92
  }
64
93
 
@@ -0,0 +1,256 @@
1
+ import { b as callProcedure } from './config-54786004.js';
2
+ import { T as TRPCError, a as getTRPCErrorFromUnknown } from './TRPCError-7c3909ea.js';
3
+ import { t as transformTRPCResponse, g as getErrorShape } from './transformTRPCResponse-7fcbe472.js';
4
+ import { g as getJsonContentTypeInputs } from './contentType-7354963c.js';
5
+ import { b as getHTTPStatusCode } from './index-ca9a128e.js';
6
+
7
+ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
8
+ GET: 'query',
9
+ POST: 'mutation',
10
+ };
11
+ const fallbackContentTypeHandler = {
12
+ getInputs: getJsonContentTypeInputs,
13
+ };
14
+ function initResponse(initOpts) {
15
+ const { ctx, paths, type, responseMeta, untransformedJSON, errors = [], } = initOpts;
16
+ let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
17
+ const headers = {
18
+ 'Content-Type': 'application/json',
19
+ };
20
+ const eagerGeneration = !untransformedJSON;
21
+ const data = eagerGeneration
22
+ ? []
23
+ : Array.isArray(untransformedJSON)
24
+ ? untransformedJSON
25
+ : [untransformedJSON];
26
+ const meta = responseMeta?.({
27
+ ctx,
28
+ paths,
29
+ type,
30
+ data,
31
+ errors,
32
+ eagerGeneration,
33
+ }) ?? {};
34
+ for (const [key, value] of Object.entries(meta.headers ?? {})) {
35
+ headers[key] = value;
36
+ }
37
+ if (meta.status) {
38
+ status = meta.status;
39
+ }
40
+ return {
41
+ status,
42
+ headers,
43
+ };
44
+ }
45
+ async function inputToProcedureCall(procedureOpts) {
46
+ const { opts, ctx, type, input, path } = procedureOpts;
47
+ try {
48
+ const data = await callProcedure({
49
+ procedures: opts.router._def.procedures,
50
+ path,
51
+ rawInput: input,
52
+ ctx,
53
+ type,
54
+ });
55
+ return {
56
+ result: {
57
+ data,
58
+ },
59
+ };
60
+ }
61
+ catch (cause) {
62
+ const error = getTRPCErrorFromUnknown(cause);
63
+ opts.onError?.({ error, path, input, ctx, type: type, req: opts.req });
64
+ return {
65
+ error: getErrorShape({
66
+ config: opts.router._def._config,
67
+ error,
68
+ type,
69
+ path,
70
+ input,
71
+ ctx,
72
+ }),
73
+ };
74
+ }
75
+ }
76
+ function caughtErrorToData(cause, errorOpts) {
77
+ const { router, req, onError } = errorOpts.opts;
78
+ const error = getTRPCErrorFromUnknown(cause);
79
+ onError?.({
80
+ error,
81
+ path: errorOpts.path,
82
+ input: errorOpts.input,
83
+ ctx: errorOpts.ctx,
84
+ type: errorOpts.type,
85
+ req,
86
+ });
87
+ const untransformedJSON = {
88
+ error: getErrorShape({
89
+ config: router._def._config,
90
+ error,
91
+ type: errorOpts.type,
92
+ path: errorOpts.path,
93
+ input: errorOpts.input,
94
+ ctx: errorOpts.ctx,
95
+ }),
96
+ };
97
+ const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
98
+ const body = JSON.stringify(transformedJSON);
99
+ return {
100
+ error,
101
+ untransformedJSON,
102
+ body,
103
+ };
104
+ }
105
+ // implementation
106
+ async function resolveHTTPResponse(opts) {
107
+ const { router, req, onHead, onChunk } = opts;
108
+ if (req.method === 'HEAD') {
109
+ // can be used for lambda warmup
110
+ const headResponse = {
111
+ status: 204,
112
+ };
113
+ onHead?.(headResponse);
114
+ onChunk?.([-1, '']);
115
+ return headResponse;
116
+ }
117
+ const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
118
+ const batchingEnabled = opts.batching?.enabled ?? true;
119
+ const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
120
+ let ctx = undefined;
121
+ let paths;
122
+ const isBatchCall = !!req.query.get('batch');
123
+ const isStreamCall = isBatchCall &&
124
+ onHead &&
125
+ onChunk &&
126
+ req.headers['trpc-batch-mode'] === 'stream';
127
+ try {
128
+ if (opts.error) {
129
+ throw opts.error;
130
+ }
131
+ if (isBatchCall && !batchingEnabled) {
132
+ throw new Error(`Batching is not enabled on the server`);
133
+ }
134
+ /* istanbul ignore if -- @preserve */
135
+ if (type === 'subscription') {
136
+ throw new TRPCError({
137
+ message: 'Subscriptions should use wsLink',
138
+ code: 'METHOD_NOT_SUPPORTED',
139
+ });
140
+ }
141
+ if (type === 'unknown') {
142
+ throw new TRPCError({
143
+ message: `Unexpected request method ${req.method}`,
144
+ code: 'METHOD_NOT_SUPPORTED',
145
+ });
146
+ }
147
+ const inputs = await contentTypeHandler.getInputs({
148
+ isBatchCall,
149
+ req,
150
+ router,
151
+ preprocessedBody: opts.preprocessedBody ?? false,
152
+ });
153
+ paths = isBatchCall ? opts.path.split(',') : [opts.path];
154
+ ctx = await opts.createContext();
155
+ const promises = paths.map((path, index) => inputToProcedureCall({ opts, ctx, type, input: inputs[index], path }));
156
+ if (!isStreamCall) {
157
+ /**
158
+ * Non-streaming response:
159
+ * - await all responses in parallel, blocking on the slowest one
160
+ * - create headers with known response body
161
+ * - return a complete HTTPResponse
162
+ */
163
+ const untransformedJSON = await Promise.all(promises);
164
+ const errors = untransformedJSON.flatMap((response) => 'error' in response ? [response.error] : []);
165
+ const headResponse = initResponse({
166
+ ctx,
167
+ paths,
168
+ type,
169
+ responseMeta: opts.responseMeta,
170
+ untransformedJSON,
171
+ errors,
172
+ });
173
+ onHead?.(headResponse);
174
+ // return body stuff
175
+ 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
176
+ const transformedJSON = transformTRPCResponse(router._def._config, result);
177
+ const body = JSON.stringify(transformedJSON);
178
+ onChunk?.([-1, body]);
179
+ return {
180
+ status: headResponse.status,
181
+ headers: headResponse.headers,
182
+ body,
183
+ };
184
+ }
185
+ /**
186
+ * Streaming response:
187
+ * - block on none, call `onChunk` as soon as each response is ready
188
+ * - create headers with minimal data (cannot know the response body in advance)
189
+ * - return void
190
+ */
191
+ const headResponse = initResponse({
192
+ ctx,
193
+ paths,
194
+ type,
195
+ responseMeta: opts.responseMeta,
196
+ });
197
+ onHead(headResponse);
198
+ const indexedPromises = new Map(promises.map((promise, index) => [
199
+ index,
200
+ promise.then((r) => [index, r]),
201
+ ]));
202
+ for (let i = 0; i < paths.length; i++) {
203
+ const [index, untransformedJSON] = await Promise.race(indexedPromises.values());
204
+ indexedPromises.delete(index);
205
+ try {
206
+ const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
207
+ const body = JSON.stringify(transformedJSON);
208
+ onChunk([index, body]);
209
+ }
210
+ catch (cause) {
211
+ const path = paths[index];
212
+ const input = inputs[index];
213
+ const { body } = caughtErrorToData(cause, {
214
+ opts,
215
+ ctx,
216
+ type,
217
+ path,
218
+ input,
219
+ });
220
+ onChunk([index, body]);
221
+ }
222
+ }
223
+ return;
224
+ }
225
+ catch (cause) {
226
+ // we get here if
227
+ // - batching is called when it's not enabled
228
+ // - `createContext()` throws
229
+ // - `router._def._config.transformer.output.serialize()` throws
230
+ // - post body is too large
231
+ // - input deserialization fails
232
+ // - `errorFormatter` return value is malformed
233
+ const { error, untransformedJSON, body } = caughtErrorToData(cause, {
234
+ opts,
235
+ ctx,
236
+ type,
237
+ });
238
+ const headResponse = initResponse({
239
+ ctx,
240
+ paths,
241
+ type,
242
+ responseMeta: opts.responseMeta,
243
+ untransformedJSON,
244
+ errors: [error],
245
+ });
246
+ onHead?.(headResponse);
247
+ onChunk?.([-1, body]);
248
+ return {
249
+ status: headResponse.status,
250
+ headers: headResponse.headers,
251
+ body,
252
+ };
253
+ }
254
+ }
255
+
256
+ export { resolveHTTPResponse as r };
@@ -0,0 +1,284 @@
1
+ 'use strict';
2
+
3
+ var config = require('./config-f3ce0144.js');
4
+ var TRPCError = require('./TRPCError-16b2e52d.js');
5
+ var transformTRPCResponse = require('./transformTRPCResponse-48d70ef6.js');
6
+ var contentType = require('./contentType-8356d528.js');
7
+ var index = require('./index-4a823936.js');
8
+
9
+ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
10
+ GET: 'query',
11
+ POST: 'mutation'
12
+ };
13
+ const fallbackContentTypeHandler = {
14
+ getInputs: contentType.getJsonContentTypeInputs
15
+ };
16
+ function initResponse(initOpts) {
17
+ const { ctx , paths , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
18
+ let status = untransformedJSON ? index.getHTTPStatusCode(untransformedJSON) : 200;
19
+ const headers = {
20
+ 'Content-Type': 'application/json'
21
+ };
22
+ const eagerGeneration = !untransformedJSON;
23
+ const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
24
+ untransformedJSON
25
+ ];
26
+ const meta = responseMeta?.({
27
+ ctx,
28
+ paths,
29
+ type,
30
+ data,
31
+ errors,
32
+ eagerGeneration
33
+ }) ?? {};
34
+ for (const [key, value] of Object.entries(meta.headers ?? {})){
35
+ headers[key] = value;
36
+ }
37
+ if (meta.status) {
38
+ status = meta.status;
39
+ }
40
+ return {
41
+ status,
42
+ headers
43
+ };
44
+ }
45
+ async function inputToProcedureCall(procedureOpts) {
46
+ const { opts , ctx , type , input , path } = procedureOpts;
47
+ try {
48
+ const data = await config.callProcedure({
49
+ procedures: opts.router._def.procedures,
50
+ path,
51
+ rawInput: input,
52
+ ctx,
53
+ type
54
+ });
55
+ return {
56
+ result: {
57
+ data
58
+ }
59
+ };
60
+ } catch (cause) {
61
+ const error = TRPCError.getTRPCErrorFromUnknown(cause);
62
+ opts.onError?.({
63
+ error,
64
+ path,
65
+ input,
66
+ ctx,
67
+ type: type,
68
+ req: opts.req
69
+ });
70
+ return {
71
+ error: transformTRPCResponse.getErrorShape({
72
+ config: opts.router._def._config,
73
+ error,
74
+ type,
75
+ path,
76
+ input,
77
+ ctx
78
+ })
79
+ };
80
+ }
81
+ }
82
+ function caughtErrorToData(cause, errorOpts) {
83
+ const { router , req , onError } = errorOpts.opts;
84
+ const error = TRPCError.getTRPCErrorFromUnknown(cause);
85
+ onError?.({
86
+ error,
87
+ path: errorOpts.path,
88
+ input: errorOpts.input,
89
+ ctx: errorOpts.ctx,
90
+ type: errorOpts.type,
91
+ req
92
+ });
93
+ const untransformedJSON = {
94
+ error: transformTRPCResponse.getErrorShape({
95
+ config: router._def._config,
96
+ error,
97
+ type: errorOpts.type,
98
+ path: errorOpts.path,
99
+ input: errorOpts.input,
100
+ ctx: errorOpts.ctx
101
+ })
102
+ };
103
+ const transformedJSON = transformTRPCResponse.transformTRPCResponse(router._def._config, untransformedJSON);
104
+ const body = JSON.stringify(transformedJSON);
105
+ return {
106
+ error,
107
+ untransformedJSON,
108
+ body
109
+ };
110
+ }
111
+ // implementation
112
+ async function resolveHTTPResponse(opts) {
113
+ const { router , req , onHead , onChunk } = opts;
114
+ if (req.method === 'HEAD') {
115
+ // can be used for lambda warmup
116
+ const headResponse = {
117
+ status: 204
118
+ };
119
+ onHead?.(headResponse);
120
+ onChunk?.([
121
+ -1,
122
+ ''
123
+ ]);
124
+ return headResponse;
125
+ }
126
+ const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
127
+ const batchingEnabled = opts.batching?.enabled ?? true;
128
+ const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
129
+ let ctx = undefined;
130
+ let paths;
131
+ const isBatchCall = !!req.query.get('batch');
132
+ const isStreamCall = isBatchCall && onHead && onChunk && req.headers['trpc-batch-mode'] === 'stream';
133
+ try {
134
+ if (opts.error) {
135
+ throw opts.error;
136
+ }
137
+ if (isBatchCall && !batchingEnabled) {
138
+ throw new Error(`Batching is not enabled on the server`);
139
+ }
140
+ /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
141
+ throw new TRPCError.TRPCError({
142
+ message: 'Subscriptions should use wsLink',
143
+ code: 'METHOD_NOT_SUPPORTED'
144
+ });
145
+ }
146
+ if (type === 'unknown') {
147
+ throw new TRPCError.TRPCError({
148
+ message: `Unexpected request method ${req.method}`,
149
+ code: 'METHOD_NOT_SUPPORTED'
150
+ });
151
+ }
152
+ const inputs = await contentTypeHandler.getInputs({
153
+ isBatchCall,
154
+ req,
155
+ router,
156
+ preprocessedBody: opts.preprocessedBody ?? false
157
+ });
158
+ paths = isBatchCall ? opts.path.split(',') : [
159
+ opts.path
160
+ ];
161
+ ctx = await opts.createContext();
162
+ const promises = paths.map((path, index)=>inputToProcedureCall({
163
+ opts,
164
+ ctx,
165
+ type,
166
+ input: inputs[index],
167
+ path
168
+ }));
169
+ if (!isStreamCall) {
170
+ /**
171
+ * Non-streaming response:
172
+ * - await all responses in parallel, blocking on the slowest one
173
+ * - create headers with known response body
174
+ * - return a complete HTTPResponse
175
+ */ const untransformedJSON = await Promise.all(promises);
176
+ const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
177
+ response.error
178
+ ] : []);
179
+ const headResponse1 = initResponse({
180
+ ctx,
181
+ paths,
182
+ type,
183
+ responseMeta: opts.responseMeta,
184
+ untransformedJSON,
185
+ errors
186
+ });
187
+ onHead?.(headResponse1);
188
+ // return body stuff
189
+ 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
190
+ const transformedJSON = transformTRPCResponse.transformTRPCResponse(router._def._config, result);
191
+ const body = JSON.stringify(transformedJSON);
192
+ onChunk?.([
193
+ -1,
194
+ body
195
+ ]);
196
+ return {
197
+ status: headResponse1.status,
198
+ headers: headResponse1.headers,
199
+ body
200
+ };
201
+ }
202
+ /**
203
+ * Streaming response:
204
+ * - block on none, call `onChunk` as soon as each response is ready
205
+ * - create headers with minimal data (cannot know the response body in advance)
206
+ * - return void
207
+ */ const headResponse2 = initResponse({
208
+ ctx,
209
+ paths,
210
+ type,
211
+ responseMeta: opts.responseMeta
212
+ });
213
+ onHead(headResponse2);
214
+ const indexedPromises = new Map(promises.map((promise, index)=>[
215
+ index,
216
+ promise.then((r)=>[
217
+ index,
218
+ r
219
+ ])
220
+ ]));
221
+ for(let i = 0; i < paths.length; i++){
222
+ const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
223
+ indexedPromises.delete(index);
224
+ try {
225
+ const transformedJSON1 = transformTRPCResponse.transformTRPCResponse(router._def._config, untransformedJSON1);
226
+ const body1 = JSON.stringify(transformedJSON1);
227
+ onChunk([
228
+ index,
229
+ body1
230
+ ]);
231
+ } catch (cause) {
232
+ const path = paths[index];
233
+ const input = inputs[index];
234
+ const { body: body2 } = caughtErrorToData(cause, {
235
+ opts,
236
+ ctx,
237
+ type,
238
+ path,
239
+ input
240
+ });
241
+ onChunk([
242
+ index,
243
+ body2
244
+ ]);
245
+ }
246
+ }
247
+ return;
248
+ } catch (cause1) {
249
+ // we get here if
250
+ // - batching is called when it's not enabled
251
+ // - `createContext()` throws
252
+ // - `router._def._config.transformer.output.serialize()` throws
253
+ // - post body is too large
254
+ // - input deserialization fails
255
+ // - `errorFormatter` return value is malformed
256
+ const { error , untransformedJSON: untransformedJSON2 , body: body3 } = caughtErrorToData(cause1, {
257
+ opts,
258
+ ctx,
259
+ type
260
+ });
261
+ const headResponse3 = initResponse({
262
+ ctx,
263
+ paths,
264
+ type,
265
+ responseMeta: opts.responseMeta,
266
+ untransformedJSON: untransformedJSON2,
267
+ errors: [
268
+ error
269
+ ]
270
+ });
271
+ onHead?.(headResponse3);
272
+ onChunk?.([
273
+ -1,
274
+ body3
275
+ ]);
276
+ return {
277
+ status: headResponse3.status,
278
+ headers: headResponse3.headers,
279
+ body: body3
280
+ };
281
+ }
282
+ }
283
+
284
+ exports.resolveHTTPResponse = resolveHTTPResponse;