@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.
- package/dist/@trpc/server/http.d.ts +7 -5
- package/dist/@trpc/server/http.d.ts.map +1 -1
- package/dist/@trpc/server/index.d.ts +1 -2
- package/dist/@trpc/server/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
- package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/getPlanner.js +143 -0
- package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
- package/dist/adapters/aws-lambda/index.d.ts +12 -9
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +7 -76
- package/dist/adapters/aws-lambda/index.mjs +9 -72
- package/dist/adapters/express.js +1 -0
- package/dist/adapters/express.mjs +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +12 -63
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -64
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +28 -85
- package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
- package/dist/adapters/fetch/types.d.ts +2 -2
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.js +1 -1
- package/dist/adapters/next.mjs +1 -1
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
- package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
- package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
- package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
- package/dist/adapters/node-http/index.d.ts +1 -0
- package/dist/adapters/node-http/index.d.ts.map +1 -1
- package/dist/adapters/node-http/index.js +2 -0
- package/dist/adapters/node-http/index.mjs +1 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +27 -70
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
- package/dist/adapters/node-http/types.d.ts +7 -8
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +180 -277
- package/dist/http.js +4 -2
- package/dist/http.mjs +2 -1
- package/dist/index.js +2 -4
- package/dist/index.mjs +1 -2
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
- package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +7 -43
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +119 -134
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +119 -134
- package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -9
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/utils.js +2 -0
- package/dist/unstable-core-do-not-import/utils.mjs +2 -1
- package/dist/unstable-core-do-not-import.d.ts +9 -3
- package/dist/unstable-core-do-not-import.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import.js +11 -7
- package/dist/unstable-core-do-not-import.mjs +7 -5
- package/package.json +3 -13
- package/src/@trpc/server/http.ts +7 -12
- package/src/@trpc/server/index.ts +0 -3
- package/src/adapters/aws-lambda/getPlanner.ts +191 -0
- package/src/adapters/aws-lambda/index.ts +43 -107
- package/src/adapters/express.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +40 -89
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
- package/src/adapters/fetch/types.ts +4 -2
- package/src/adapters/next.ts +1 -1
- package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
- package/src/adapters/node-http/index.ts +1 -0
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -97
- package/src/adapters/node-http/types.ts +27 -37
- package/src/adapters/standalone.ts +1 -1
- package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
- package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +135 -210
- package/src/unstable-core-do-not-import/http/types.ts +25 -30
- package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
- package/src/unstable-core-do-not-import/utils.ts +4 -0
- package/src/unstable-core-do-not-import.ts +9 -3
- package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
- package/adapters/node-http/content-type/form-data/index.js +0 -1
- package/adapters/node-http/content-type/json/index.d.ts +0 -1
- package/adapters/node-http/content-type/json/index.js +0 -1
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
- package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
- package/dist/adapters/aws-lambda/utils.d.ts +0 -31
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -111
- package/dist/adapters/aws-lambda/utils.mjs +0 -103
- package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
- package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
- package/dist/adapters/content-handlers/concurrentCache.js +0 -17
- package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
- package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
- package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fastify/content-type/json/index.js +0 -62
- package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
- package/dist/adapters/fastify/types.d.ts +0 -11
- package/dist/adapters/fastify/types.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/fetch/content-type/json/index.js +0 -55
- package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +0 -32
- package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -45
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
- package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/index.js +0 -68
- package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
- package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/octet/index.js +0 -19
- package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
- package/dist/adapters/node-http/content-type/types.d.ts +0 -8
- package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
- package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
- package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
- package/src/adapters/aws-lambda/utils.ts +0 -170
- package/src/adapters/content-handlers/concurrentCache.ts +0 -16
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
- package/src/adapters/fastify/content-type/json/index.ts +0 -106
- package/src/adapters/fastify/types.ts +0 -22
- package/src/adapters/fetch/content-type/json/index.ts +0 -90
- package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
- package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
- package/src/adapters/node-http/content-type/json/index.ts +0 -100
- package/src/adapters/node-http/content-type/octet/index.ts +0 -27
- package/src/adapters/node-http/content-type/types.ts +0 -19
- package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
- 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 ,
|
|
16
|
+
const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
|
|
15
17
|
let status = untransformedJSON ? getHTTPStatusCode.getHTTPStatusCode(untransformedJSON) : 200;
|
|
16
|
-
const headers =
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
headers
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
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
|
-
|
|
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
|
|
91
|
-
const
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
181
|
+
const errors1 = untransformedJSON.flatMap((response)=>'error' in response ? [
|
|
182
|
+
response.error
|
|
183
|
+
] : []);
|
|
184
|
+
const headResponse = initResponse({
|
|
191
185
|
ctx,
|
|
192
|
-
|
|
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];
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
206
|
+
*/ const headResponse1 = initResponse({
|
|
219
207
|
ctx,
|
|
220
|
-
|
|
208
|
+
info,
|
|
221
209
|
type,
|
|
222
|
-
responseMeta: opts.responseMeta
|
|
210
|
+
responseMeta: opts.responseMeta,
|
|
211
|
+
errors: []
|
|
223
212
|
});
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
262
|
-
|
|
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:
|
|
261
|
+
const { error , untransformedJSON: untransformedJSON1 , body: body1 } = caughtErrorToData(cause, {
|
|
271
262
|
opts,
|
|
272
263
|
ctx,
|
|
273
264
|
type
|
|
274
265
|
});
|
|
275
|
-
const
|
|
266
|
+
const headResponse2 = initResponse({
|
|
276
267
|
ctx,
|
|
277
|
-
|
|
268
|
+
info,
|
|
278
269
|
type,
|
|
279
270
|
responseMeta: opts.responseMeta,
|
|
280
|
-
untransformedJSON:
|
|
271
|
+
untransformedJSON: untransformedJSON1,
|
|
281
272
|
errors: [
|
|
282
273
|
error
|
|
283
274
|
]
|
|
284
275
|
});
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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.
|
|
283
|
+
exports.resolveResponse = resolveResponse;
|