@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.215 → 11.0.0-alpha-tmp-export-from-main.211
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-core-unstable-do-not-import-this-please.d.ts +9 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +1 -0
- package/dist/@trpc-server/http.d.ts +1 -1
- package/dist/@trpc-server/http.d.ts.map +1 -1
- package/dist/@trpc-server.d.ts +3 -3
- package/dist/@trpc-server.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.d.ts +1 -1
- package/dist/adapters/aws-lambda/index.js +7 -12
- package/dist/adapters/aws-lambda/index.mjs +3 -8
- package/dist/adapters/aws-lambda/utils.d.ts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +2 -8
- package/dist/adapters/express.mjs +2 -8
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/index.js +4 -12
- package/dist/adapters/fastify/index.mjs +2 -10
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -1
- package/dist/adapters/fetch/index.js +4 -10
- package/dist/adapters/fetch/index.mjs +2 -8
- package/dist/adapters/fetch/types.d.ts +1 -1
- package/dist/adapters/next.d.ts +1 -1
- package/dist/adapters/next.js +5 -11
- package/dist/adapters/next.mjs +3 -9
- package/dist/adapters/node-http/content-type/json/index.js +3 -5
- package/dist/adapters/node-http/content-type/json/index.mjs +1 -3
- package/dist/adapters/node-http/index.js +2 -8
- package/dist/adapters/node-http/index.mjs +2 -8
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/types.d.ts +2 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -1
- package/dist/adapters/standalone.js +2 -8
- package/dist/adapters/standalone.mjs +2 -8
- package/dist/adapters/ws.d.ts +1 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +26 -31
- package/dist/adapters/ws.mjs +1 -6
- package/dist/http.d.ts +6 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +21 -12
- package/dist/http.mjs +1 -7
- package/dist/index.js +41 -15
- package/dist/index.mjs +1 -5
- package/dist/{nodeHTTPRequestHandler-257a3b5f.mjs → nodeHTTPRequestHandler-2d5c8791.mjs} +2 -4
- package/dist/{nodeHTTPRequestHandler-f4b7e374.js → nodeHTTPRequestHandler-55f05150.js} +4 -6
- package/dist/{nodeHTTPRequestHandler-29178135.js → nodeHTTPRequestHandler-7691fc79.js} +1 -3
- package/dist/observable.d.ts +2 -2
- package/dist/observable.d.ts.map +1 -1
- package/dist/observable.js +25 -9
- package/dist/observable.mjs +1 -3
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +13 -5
- package/dist/rpc.mjs +1 -2
- package/dist/shared.js +9 -4
- package/dist/shared.mjs +1 -2
- package/package.json +125 -53
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +9 -0
- package/src/@trpc-server/http.ts +1 -2
- package/src/@trpc-server.ts +3 -3
- package/src/adapters/aws-lambda/index.ts +1 -1
- package/src/adapters/aws-lambda/utils.ts +1 -1
- package/src/adapters/express.ts +2 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
- package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
- package/src/adapters/fetch/types.ts +1 -1
- package/src/adapters/next.ts +1 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
- package/src/adapters/node-http/types.ts +3 -2
- package/src/adapters/standalone.ts +1 -1
- package/src/adapters/ws.ts +10 -9
- package/src/http.ts +6 -6
- package/src/observable.ts +2 -2
- package/src/rpc.ts +2 -2
- package/dist/TRPCError-10da405a.js +0 -61
- package/dist/TRPCError-14edcf88.mjs +0 -63
- package/dist/TRPCError-e2c8eb77.js +0 -67
- package/dist/batchStreamFormatter-1971db27.js +0 -32
- package/dist/batchStreamFormatter-378277dc.mjs +0 -30
- package/dist/batchStreamFormatter-4375dc8b.js +0 -31
- package/dist/bundle-analysis.json +0 -767
- package/dist/contentType-2ed02bef.mjs +0 -52
- package/dist/contentType-3a829011.js +0 -54
- package/dist/contentType-e4a2373e.js +0 -59
- package/dist/createProxy-0306dcaa.mjs +0 -121
- package/dist/createProxy-7e413449.js +0 -127
- package/dist/createProxy-dce0c414.js +0 -116
- package/dist/initTRPC-2cef03ab.js +0 -384
- package/dist/initTRPC-38faa18f.js +0 -371
- package/dist/initTRPC-fa1b3d57.mjs +0 -376
- package/dist/observable-2a5a96d5.js +0 -125
- package/dist/observable-62674916.js +0 -125
- package/dist/observable-6d025a37.mjs +0 -121
- package/dist/operators-0cc4956a.js +0 -99
- package/dist/operators-b08617cb.js +0 -103
- package/dist/operators-d0c3e794.mjs +0 -99
- package/dist/parseTRPCMessage-6e6c204e.js +0 -65
- package/dist/parseTRPCMessage-8eb0bbe9.mjs +0 -62
- package/dist/parseTRPCMessage-ebdfe3ca.js +0 -67
- package/dist/resolveHTTPResponse-833ca2b8.js +0 -265
- package/dist/resolveHTTPResponse-9322334c.mjs +0 -291
- package/dist/resolveHTTPResponse-d64c48e1.js +0 -293
- package/dist/rootConfig-3371c473.js +0 -89
- package/dist/rootConfig-571c9267.js +0 -94
- package/dist/rootConfig-6b04a6b8.mjs +0 -81
- package/dist/router-3344b52a.js +0 -262
- package/dist/router-919c37eb.js +0 -259
- package/dist/router-d6789e4b.mjs +0 -252
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.d.ts +0 -35
- package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/index.js +0 -51
- package/dist/unstable-core-do-not-import/index.mjs +0 -11
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/observable/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/observable.d.ts +0 -13
- package/dist/unstable-core-do-not-import/observable/observable.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/operators.d.ts +0 -8
- package/dist/unstable-core-do-not-import/observable/operators.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/observable/types.d.ts +0 -26
- package/dist/unstable-core-do-not-import/observable/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
- package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/router.d.ts +0 -85
- package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/types.d.ts +0 -98
- package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
- package/dist/unstable-core-do-not-import/utils.d.ts +0 -31
- package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
- package/src/unstable-core-do-not-import/createProxy.ts +0 -59
- package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
- package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
- package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
- package/src/unstable-core-do-not-import/http/index.ts +0 -23
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
- package/src/unstable-core-do-not-import/http/types.ts +0 -111
- package/src/unstable-core-do-not-import/index.ts +0 -108
- package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
- package/src/unstable-core-do-not-import/middleware.ts +0 -233
- package/src/unstable-core-do-not-import/observable/index.ts +0 -10
- package/src/unstable-core-do-not-import/observable/observable.ts +0 -155
- package/src/unstable-core-do-not-import/observable/operators.ts +0 -119
- package/src/unstable-core-do-not-import/observable/types.ts +0 -76
- package/src/unstable-core-do-not-import/parser.ts +0 -94
- package/src/unstable-core-do-not-import/procedure.ts +0 -108
- package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
- package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
- package/src/unstable-core-do-not-import/router.ts +0 -370
- package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
- package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
- package/src/unstable-core-do-not-import/serialize.ts +0 -122
- package/src/unstable-core-do-not-import/transformer.ts +0 -202
- package/src/unstable-core-do-not-import/types.ts +0 -151
- package/src/unstable-core-do-not-import/utils.ts +0 -66
- package/unstable-core-do-not-import/index.d.ts +0 -1
- package/unstable-core-do-not-import/index.js +0 -1
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { g as getHTTPStatusCode, a as getErrorShape } from './createProxy-dce0c414.js';
|
|
2
|
-
import { T as TRPCError, g as getTRPCErrorFromUnknown } from './TRPCError-10da405a.js';
|
|
3
|
-
import { t as transformTRPCResponse, c as callProcedure } from './router-919c37eb.js';
|
|
4
|
-
import { g as getJsonContentTypeInputs } from './contentType-e4a2373e.js';
|
|
5
|
-
|
|
6
|
-
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
7
|
-
GET: 'query',
|
|
8
|
-
POST: 'mutation',
|
|
9
|
-
};
|
|
10
|
-
const fallbackContentTypeHandler = {
|
|
11
|
-
getInputs: getJsonContentTypeInputs,
|
|
12
|
-
};
|
|
13
|
-
function initResponse(initOpts) {
|
|
14
|
-
const { ctx, paths, type, responseMeta, untransformedJSON, errors = [], } = initOpts;
|
|
15
|
-
let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
|
|
16
|
-
const headers = {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
};
|
|
19
|
-
const eagerGeneration = !untransformedJSON;
|
|
20
|
-
const data = eagerGeneration
|
|
21
|
-
? []
|
|
22
|
-
: Array.isArray(untransformedJSON)
|
|
23
|
-
? untransformedJSON
|
|
24
|
-
: [untransformedJSON];
|
|
25
|
-
const meta = responseMeta?.({
|
|
26
|
-
ctx,
|
|
27
|
-
paths,
|
|
28
|
-
type,
|
|
29
|
-
data,
|
|
30
|
-
errors,
|
|
31
|
-
eagerGeneration,
|
|
32
|
-
}) ?? {};
|
|
33
|
-
for (const [key, value] of Object.entries(meta.headers ?? {})) {
|
|
34
|
-
headers[key] = value;
|
|
35
|
-
}
|
|
36
|
-
if (meta.status) {
|
|
37
|
-
status = meta.status;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
status,
|
|
41
|
-
headers,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async function inputToProcedureCall(procedureOpts) {
|
|
45
|
-
const { opts, ctx, type, input, path } = procedureOpts;
|
|
46
|
-
try {
|
|
47
|
-
const data = await callProcedure({
|
|
48
|
-
procedures: opts.router._def.procedures,
|
|
49
|
-
path,
|
|
50
|
-
getRawInput: async () => input,
|
|
51
|
-
ctx,
|
|
52
|
-
type,
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
result: {
|
|
56
|
-
data,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
catch (cause) {
|
|
61
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
62
|
-
opts.onError?.({ error, path, input, ctx, type: type, req: opts.req });
|
|
63
|
-
return {
|
|
64
|
-
error: getErrorShape({
|
|
65
|
-
config: opts.router._def._config,
|
|
66
|
-
error,
|
|
67
|
-
type,
|
|
68
|
-
path,
|
|
69
|
-
input,
|
|
70
|
-
ctx,
|
|
71
|
-
}),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function caughtErrorToData(cause, errorOpts) {
|
|
76
|
-
const { router, req, onError } = errorOpts.opts;
|
|
77
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
78
|
-
onError?.({
|
|
79
|
-
error,
|
|
80
|
-
path: errorOpts.path,
|
|
81
|
-
input: errorOpts.input,
|
|
82
|
-
ctx: errorOpts.ctx,
|
|
83
|
-
type: errorOpts.type,
|
|
84
|
-
req,
|
|
85
|
-
});
|
|
86
|
-
const untransformedJSON = {
|
|
87
|
-
error: getErrorShape({
|
|
88
|
-
config: router._def._config,
|
|
89
|
-
error,
|
|
90
|
-
type: errorOpts.type,
|
|
91
|
-
path: errorOpts.path,
|
|
92
|
-
input: errorOpts.input,
|
|
93
|
-
ctx: errorOpts.ctx,
|
|
94
|
-
}),
|
|
95
|
-
};
|
|
96
|
-
const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
|
|
97
|
-
const body = JSON.stringify(transformedJSON);
|
|
98
|
-
return {
|
|
99
|
-
error,
|
|
100
|
-
untransformedJSON,
|
|
101
|
-
body,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
// implementation
|
|
105
|
-
async function resolveHTTPResponse(opts) {
|
|
106
|
-
const { router, req, unstable_onHead, unstable_onChunk } = opts;
|
|
107
|
-
if (req.method === 'HEAD') {
|
|
108
|
-
// can be used for lambda warmup
|
|
109
|
-
const headResponse = {
|
|
110
|
-
status: 204,
|
|
111
|
-
};
|
|
112
|
-
unstable_onHead?.(headResponse, false);
|
|
113
|
-
unstable_onChunk?.([-1, '']);
|
|
114
|
-
return headResponse;
|
|
115
|
-
}
|
|
116
|
-
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
117
|
-
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
118
|
-
const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
|
|
119
|
-
let ctx = undefined;
|
|
120
|
-
let paths;
|
|
121
|
-
const isBatchCall = !!req.query.get('batch');
|
|
122
|
-
const isStreamCall = isBatchCall &&
|
|
123
|
-
unstable_onHead &&
|
|
124
|
-
unstable_onChunk &&
|
|
125
|
-
req.headers['trpc-batch-mode'] === 'stream';
|
|
126
|
-
try {
|
|
127
|
-
if (opts.error) {
|
|
128
|
-
throw opts.error;
|
|
129
|
-
}
|
|
130
|
-
if (isBatchCall && !batchingEnabled) {
|
|
131
|
-
throw new Error(`Batching is not enabled on the server`);
|
|
132
|
-
}
|
|
133
|
-
/* istanbul ignore if -- @preserve */
|
|
134
|
-
if (type === 'subscription') {
|
|
135
|
-
throw new TRPCError({
|
|
136
|
-
message: 'Subscriptions should use wsLink',
|
|
137
|
-
code: 'METHOD_NOT_SUPPORTED',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
if (type === 'unknown') {
|
|
141
|
-
throw new TRPCError({
|
|
142
|
-
message: `Unexpected request method ${req.method}`,
|
|
143
|
-
code: 'METHOD_NOT_SUPPORTED',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const inputs = await contentTypeHandler.getInputs({
|
|
147
|
-
isBatchCall,
|
|
148
|
-
req,
|
|
149
|
-
router,
|
|
150
|
-
preprocessedBody: opts.preprocessedBody ?? false,
|
|
151
|
-
});
|
|
152
|
-
paths = isBatchCall
|
|
153
|
-
? decodeURIComponent(opts.path).split(',')
|
|
154
|
-
: [opts.path];
|
|
155
|
-
const info = {
|
|
156
|
-
isBatchCall,
|
|
157
|
-
calls: paths.map((path, idx) => ({
|
|
158
|
-
path,
|
|
159
|
-
type,
|
|
160
|
-
input: inputs[idx] ?? undefined,
|
|
161
|
-
})),
|
|
162
|
-
};
|
|
163
|
-
ctx = await opts.createContext({ info });
|
|
164
|
-
const promises = paths.map((path, index) => inputToProcedureCall({ opts, ctx, type, input: inputs[index], path }));
|
|
165
|
-
if (!isStreamCall) {
|
|
166
|
-
/**
|
|
167
|
-
* Non-streaming response:
|
|
168
|
-
* - await all responses in parallel, blocking on the slowest one
|
|
169
|
-
* - create headers with known response body
|
|
170
|
-
* - return a complete HTTPResponse
|
|
171
|
-
*/
|
|
172
|
-
const untransformedJSON = await Promise.all(promises);
|
|
173
|
-
const errors = untransformedJSON.flatMap((response) => 'error' in response ? [response.error] : []);
|
|
174
|
-
const headResponse = initResponse({
|
|
175
|
-
ctx,
|
|
176
|
-
paths,
|
|
177
|
-
type,
|
|
178
|
-
responseMeta: opts.responseMeta,
|
|
179
|
-
untransformedJSON,
|
|
180
|
-
errors,
|
|
181
|
-
});
|
|
182
|
-
unstable_onHead?.(headResponse, false);
|
|
183
|
-
// return body stuff
|
|
184
|
-
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
|
|
185
|
-
const transformedJSON = transformTRPCResponse(router._def._config, result);
|
|
186
|
-
const body = JSON.stringify(transformedJSON);
|
|
187
|
-
unstable_onChunk?.([-1, body]);
|
|
188
|
-
return {
|
|
189
|
-
status: headResponse.status,
|
|
190
|
-
headers: headResponse.headers,
|
|
191
|
-
body,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Streaming response:
|
|
196
|
-
* - block on none, call `onChunk` as soon as each response is ready
|
|
197
|
-
* - create headers with minimal data (cannot know the response body in advance)
|
|
198
|
-
* - return void
|
|
199
|
-
*/
|
|
200
|
-
const headResponse = initResponse({
|
|
201
|
-
ctx,
|
|
202
|
-
paths,
|
|
203
|
-
type,
|
|
204
|
-
responseMeta: opts.responseMeta,
|
|
205
|
-
});
|
|
206
|
-
unstable_onHead(headResponse, true);
|
|
207
|
-
const indexedPromises = new Map(promises.map((promise, index) => [
|
|
208
|
-
index,
|
|
209
|
-
promise.then((r) => [index, r]),
|
|
210
|
-
]));
|
|
211
|
-
for (const _ of paths) {
|
|
212
|
-
const [index, untransformedJSON] = await Promise.race(indexedPromises.values());
|
|
213
|
-
indexedPromises.delete(index);
|
|
214
|
-
try {
|
|
215
|
-
const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
|
|
216
|
-
const body = JSON.stringify(transformedJSON);
|
|
217
|
-
unstable_onChunk([index, body]);
|
|
218
|
-
}
|
|
219
|
-
catch (cause) {
|
|
220
|
-
const path = paths[index];
|
|
221
|
-
const input = inputs[index];
|
|
222
|
-
const { body } = caughtErrorToData(cause, {
|
|
223
|
-
opts,
|
|
224
|
-
ctx,
|
|
225
|
-
type,
|
|
226
|
-
path,
|
|
227
|
-
input,
|
|
228
|
-
});
|
|
229
|
-
unstable_onChunk([index, body]);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
catch (cause) {
|
|
235
|
-
// we get here if
|
|
236
|
-
// - batching is called when it's not enabled
|
|
237
|
-
// - `createContext()` throws
|
|
238
|
-
// - `router._def._config.transformer.output.serialize()` throws
|
|
239
|
-
// - post body is too large
|
|
240
|
-
// - input deserialization fails
|
|
241
|
-
// - `errorFormatter` return value is malformed
|
|
242
|
-
const { error, untransformedJSON, body } = caughtErrorToData(cause, {
|
|
243
|
-
opts,
|
|
244
|
-
ctx,
|
|
245
|
-
type,
|
|
246
|
-
});
|
|
247
|
-
const headResponse = initResponse({
|
|
248
|
-
ctx,
|
|
249
|
-
paths,
|
|
250
|
-
type,
|
|
251
|
-
responseMeta: opts.responseMeta,
|
|
252
|
-
untransformedJSON,
|
|
253
|
-
errors: [error],
|
|
254
|
-
});
|
|
255
|
-
unstable_onHead?.(headResponse, false);
|
|
256
|
-
unstable_onChunk?.([-1, body]);
|
|
257
|
-
return {
|
|
258
|
-
status: headResponse.status,
|
|
259
|
-
headers: headResponse.headers,
|
|
260
|
-
body,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export { resolveHTTPResponse as r };
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { g as getHTTPStatusCode, a as getErrorShape } from './createProxy-0306dcaa.mjs';
|
|
2
|
-
import { T as TRPCError, g as getTRPCErrorFromUnknown } from './TRPCError-14edcf88.mjs';
|
|
3
|
-
import { t as transformTRPCResponse, c as callProcedure } from './router-d6789e4b.mjs';
|
|
4
|
-
import { g as getJsonContentTypeInputs } from './contentType-2ed02bef.mjs';
|
|
5
|
-
|
|
6
|
-
const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
|
|
7
|
-
GET: 'query',
|
|
8
|
-
POST: 'mutation'
|
|
9
|
-
};
|
|
10
|
-
const fallbackContentTypeHandler = {
|
|
11
|
-
getInputs: getJsonContentTypeInputs
|
|
12
|
-
};
|
|
13
|
-
function initResponse(initOpts) {
|
|
14
|
-
const { ctx , paths , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
|
|
15
|
-
let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
|
|
16
|
-
const headers = {
|
|
17
|
-
'Content-Type': 'application/json'
|
|
18
|
-
};
|
|
19
|
-
const eagerGeneration = !untransformedJSON;
|
|
20
|
-
const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
|
|
21
|
-
untransformedJSON
|
|
22
|
-
];
|
|
23
|
-
const meta = responseMeta?.({
|
|
24
|
-
ctx,
|
|
25
|
-
paths,
|
|
26
|
-
type,
|
|
27
|
-
data,
|
|
28
|
-
errors,
|
|
29
|
-
eagerGeneration
|
|
30
|
-
}) ?? {};
|
|
31
|
-
for (const [key, value] of Object.entries(meta.headers ?? {})){
|
|
32
|
-
headers[key] = value;
|
|
33
|
-
}
|
|
34
|
-
if (meta.status) {
|
|
35
|
-
status = meta.status;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
status,
|
|
39
|
-
headers
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function inputToProcedureCall(procedureOpts) {
|
|
43
|
-
const { opts , ctx , type , input , path } = procedureOpts;
|
|
44
|
-
try {
|
|
45
|
-
const data = await callProcedure({
|
|
46
|
-
procedures: opts.router._def.procedures,
|
|
47
|
-
path,
|
|
48
|
-
getRawInput: async ()=>input,
|
|
49
|
-
ctx,
|
|
50
|
-
type
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
result: {
|
|
54
|
-
data
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
} catch (cause) {
|
|
58
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
59
|
-
opts.onError?.({
|
|
60
|
-
error,
|
|
61
|
-
path,
|
|
62
|
-
input,
|
|
63
|
-
ctx,
|
|
64
|
-
type: type,
|
|
65
|
-
req: opts.req
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
error: getErrorShape({
|
|
69
|
-
config: opts.router._def._config,
|
|
70
|
-
error,
|
|
71
|
-
type,
|
|
72
|
-
path,
|
|
73
|
-
input,
|
|
74
|
-
ctx
|
|
75
|
-
})
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function caughtErrorToData(cause, errorOpts) {
|
|
80
|
-
const { router , req , onError } = errorOpts.opts;
|
|
81
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
82
|
-
onError?.({
|
|
83
|
-
error,
|
|
84
|
-
path: errorOpts.path,
|
|
85
|
-
input: errorOpts.input,
|
|
86
|
-
ctx: errorOpts.ctx,
|
|
87
|
-
type: errorOpts.type,
|
|
88
|
-
req
|
|
89
|
-
});
|
|
90
|
-
const untransformedJSON = {
|
|
91
|
-
error: getErrorShape({
|
|
92
|
-
config: router._def._config,
|
|
93
|
-
error,
|
|
94
|
-
type: errorOpts.type,
|
|
95
|
-
path: errorOpts.path,
|
|
96
|
-
input: errorOpts.input,
|
|
97
|
-
ctx: errorOpts.ctx
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
|
|
101
|
-
const body = JSON.stringify(transformedJSON);
|
|
102
|
-
return {
|
|
103
|
-
error,
|
|
104
|
-
untransformedJSON,
|
|
105
|
-
body
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
// implementation
|
|
109
|
-
async function resolveHTTPResponse(opts) {
|
|
110
|
-
const { router , req , unstable_onHead , unstable_onChunk } = opts;
|
|
111
|
-
if (req.method === 'HEAD') {
|
|
112
|
-
// can be used for lambda warmup
|
|
113
|
-
const headResponse = {
|
|
114
|
-
status: 204
|
|
115
|
-
};
|
|
116
|
-
unstable_onHead?.(headResponse, false);
|
|
117
|
-
unstable_onChunk?.([
|
|
118
|
-
-1,
|
|
119
|
-
''
|
|
120
|
-
]);
|
|
121
|
-
return headResponse;
|
|
122
|
-
}
|
|
123
|
-
const contentTypeHandler = opts.contentTypeHandler ?? fallbackContentTypeHandler;
|
|
124
|
-
const batchingEnabled = opts.batching?.enabled ?? true;
|
|
125
|
-
const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
|
|
126
|
-
let ctx = undefined;
|
|
127
|
-
let paths;
|
|
128
|
-
const isBatchCall = !!req.query.get('batch');
|
|
129
|
-
const isStreamCall = isBatchCall && unstable_onHead && unstable_onChunk && req.headers['trpc-batch-mode'] === 'stream';
|
|
130
|
-
try {
|
|
131
|
-
if (opts.error) {
|
|
132
|
-
throw opts.error;
|
|
133
|
-
}
|
|
134
|
-
if (isBatchCall && !batchingEnabled) {
|
|
135
|
-
throw new Error(`Batching is not enabled on the server`);
|
|
136
|
-
}
|
|
137
|
-
/* istanbul ignore if -- @preserve */ if (type === 'subscription') {
|
|
138
|
-
throw new TRPCError({
|
|
139
|
-
message: 'Subscriptions should use wsLink',
|
|
140
|
-
code: 'METHOD_NOT_SUPPORTED'
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
if (type === 'unknown') {
|
|
144
|
-
throw new TRPCError({
|
|
145
|
-
message: `Unexpected request method ${req.method}`,
|
|
146
|
-
code: 'METHOD_NOT_SUPPORTED'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const inputs = await contentTypeHandler.getInputs({
|
|
150
|
-
isBatchCall,
|
|
151
|
-
req,
|
|
152
|
-
router,
|
|
153
|
-
preprocessedBody: opts.preprocessedBody ?? false
|
|
154
|
-
});
|
|
155
|
-
paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
|
|
156
|
-
opts.path
|
|
157
|
-
];
|
|
158
|
-
const info = {
|
|
159
|
-
isBatchCall,
|
|
160
|
-
calls: paths.map((path, idx)=>({
|
|
161
|
-
path,
|
|
162
|
-
type,
|
|
163
|
-
input: inputs[idx] ?? undefined
|
|
164
|
-
}))
|
|
165
|
-
};
|
|
166
|
-
ctx = await opts.createContext({
|
|
167
|
-
info
|
|
168
|
-
});
|
|
169
|
-
const promises = paths.map((path, index)=>inputToProcedureCall({
|
|
170
|
-
opts,
|
|
171
|
-
ctx,
|
|
172
|
-
type,
|
|
173
|
-
input: inputs[index],
|
|
174
|
-
path
|
|
175
|
-
}));
|
|
176
|
-
if (!isStreamCall) {
|
|
177
|
-
/**
|
|
178
|
-
* Non-streaming response:
|
|
179
|
-
* - await all responses in parallel, blocking on the slowest one
|
|
180
|
-
* - create headers with known response body
|
|
181
|
-
* - return a complete HTTPResponse
|
|
182
|
-
*/ const untransformedJSON = await Promise.all(promises);
|
|
183
|
-
const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
|
|
184
|
-
response.error
|
|
185
|
-
] : []);
|
|
186
|
-
const headResponse1 = initResponse({
|
|
187
|
-
ctx,
|
|
188
|
-
paths,
|
|
189
|
-
type,
|
|
190
|
-
responseMeta: opts.responseMeta,
|
|
191
|
-
untransformedJSON,
|
|
192
|
-
errors
|
|
193
|
-
});
|
|
194
|
-
unstable_onHead?.(headResponse1, false);
|
|
195
|
-
// return body stuff
|
|
196
|
-
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
|
|
197
|
-
const transformedJSON = transformTRPCResponse(router._def._config, result);
|
|
198
|
-
const body = JSON.stringify(transformedJSON);
|
|
199
|
-
unstable_onChunk?.([
|
|
200
|
-
-1,
|
|
201
|
-
body
|
|
202
|
-
]);
|
|
203
|
-
return {
|
|
204
|
-
status: headResponse1.status,
|
|
205
|
-
headers: headResponse1.headers,
|
|
206
|
-
body
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Streaming response:
|
|
211
|
-
* - block on none, call `onChunk` as soon as each response is ready
|
|
212
|
-
* - create headers with minimal data (cannot know the response body in advance)
|
|
213
|
-
* - return void
|
|
214
|
-
*/ const headResponse2 = initResponse({
|
|
215
|
-
ctx,
|
|
216
|
-
paths,
|
|
217
|
-
type,
|
|
218
|
-
responseMeta: opts.responseMeta
|
|
219
|
-
});
|
|
220
|
-
unstable_onHead(headResponse2, true);
|
|
221
|
-
const indexedPromises = new Map(promises.map((promise, index)=>[
|
|
222
|
-
index,
|
|
223
|
-
promise.then((r)=>[
|
|
224
|
-
index,
|
|
225
|
-
r
|
|
226
|
-
])
|
|
227
|
-
]));
|
|
228
|
-
for (const _ of paths){
|
|
229
|
-
const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
|
|
230
|
-
indexedPromises.delete(index);
|
|
231
|
-
try {
|
|
232
|
-
const transformedJSON1 = transformTRPCResponse(router._def._config, untransformedJSON1);
|
|
233
|
-
const body1 = JSON.stringify(transformedJSON1);
|
|
234
|
-
unstable_onChunk([
|
|
235
|
-
index,
|
|
236
|
-
body1
|
|
237
|
-
]);
|
|
238
|
-
} catch (cause) {
|
|
239
|
-
const path = paths[index];
|
|
240
|
-
const input = inputs[index];
|
|
241
|
-
const { body: body2 } = caughtErrorToData(cause, {
|
|
242
|
-
opts,
|
|
243
|
-
ctx,
|
|
244
|
-
type,
|
|
245
|
-
path,
|
|
246
|
-
input
|
|
247
|
-
});
|
|
248
|
-
unstable_onChunk([
|
|
249
|
-
index,
|
|
250
|
-
body2
|
|
251
|
-
]);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return;
|
|
255
|
-
} catch (cause1) {
|
|
256
|
-
// we get here if
|
|
257
|
-
// - batching is called when it's not enabled
|
|
258
|
-
// - `createContext()` throws
|
|
259
|
-
// - `router._def._config.transformer.output.serialize()` throws
|
|
260
|
-
// - post body is too large
|
|
261
|
-
// - input deserialization fails
|
|
262
|
-
// - `errorFormatter` return value is malformed
|
|
263
|
-
const { error , untransformedJSON: untransformedJSON2 , body: body3 } = caughtErrorToData(cause1, {
|
|
264
|
-
opts,
|
|
265
|
-
ctx,
|
|
266
|
-
type
|
|
267
|
-
});
|
|
268
|
-
const headResponse3 = initResponse({
|
|
269
|
-
ctx,
|
|
270
|
-
paths,
|
|
271
|
-
type,
|
|
272
|
-
responseMeta: opts.responseMeta,
|
|
273
|
-
untransformedJSON: untransformedJSON2,
|
|
274
|
-
errors: [
|
|
275
|
-
error
|
|
276
|
-
]
|
|
277
|
-
});
|
|
278
|
-
unstable_onHead?.(headResponse3, false);
|
|
279
|
-
unstable_onChunk?.([
|
|
280
|
-
-1,
|
|
281
|
-
body3
|
|
282
|
-
]);
|
|
283
|
-
return {
|
|
284
|
-
status: headResponse3.status,
|
|
285
|
-
headers: headResponse3.headers,
|
|
286
|
-
body: body3
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export { resolveHTTPResponse as r };
|