@trpc/server 11.0.0-next-beta.240 → 11.0.0-next-beta.241
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/bundle-analysis.json +17 -17
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +7 -2
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +43 -51
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +39 -47
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +6 -5
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/unstable-core-do-not-import/error/formatter.ts +7 -7
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +45 -51
- package/src/unstable-core-do-not-import/initTRPC.ts +10 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 34.
|
|
2
|
+
"bundleSize": 102398,
|
|
3
|
+
"bundleOrigSize": 157219,
|
|
4
|
+
"bundleReduction": 34.87,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/adapters/ws.ts",
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
"dependents": [
|
|
15
15
|
"/src/adapters/fastify/fastifyTRPCPlugin.ts"
|
|
16
16
|
],
|
|
17
|
-
"percent": 9.
|
|
17
|
+
"percent": 9.65,
|
|
18
18
|
"reduction": 0
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"id": "/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
|
|
22
|
-
"size":
|
|
23
|
-
"origSize":
|
|
22
|
+
"size": 9259,
|
|
23
|
+
"origSize": 11799,
|
|
24
24
|
"renderedExports": [
|
|
25
25
|
"resolveHTTPResponse"
|
|
26
26
|
],
|
|
27
27
|
"removedExports": [],
|
|
28
28
|
"dependents": [],
|
|
29
|
-
"percent": 9.
|
|
30
|
-
"reduction":
|
|
29
|
+
"percent": 9.04,
|
|
30
|
+
"reduction": 21.53
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"id": "/home/runner/work/trpc/trpc/node_modules/.pnpm/@web3-storage+multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js",
|
|
@@ -216,7 +216,7 @@
|
|
|
216
216
|
{
|
|
217
217
|
"id": "/src/unstable-core-do-not-import/initTRPC.ts",
|
|
218
218
|
"size": 2879,
|
|
219
|
-
"origSize":
|
|
219
|
+
"origSize": 4716,
|
|
220
220
|
"renderedExports": [
|
|
221
221
|
"initTRPC"
|
|
222
222
|
],
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
"/src/unstable-core-do-not-import/index.ts"
|
|
226
226
|
],
|
|
227
227
|
"percent": 2.81,
|
|
228
|
-
"reduction": 38.
|
|
228
|
+
"reduction": 38.95
|
|
229
229
|
},
|
|
230
230
|
{
|
|
231
231
|
"id": "/src/unstable-core-do-not-import/transformer.ts",
|
|
@@ -455,11 +455,11 @@
|
|
|
455
455
|
"dependents": [
|
|
456
456
|
"/src/unstable-core-do-not-import/index.ts",
|
|
457
457
|
"/src/unstable-core-do-not-import/rpc/codes.ts",
|
|
458
|
-
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
459
458
|
"/src/unstable-core-do-not-import/error/TRPCError.ts",
|
|
460
459
|
"/src/unstable-core-do-not-import/middleware.ts",
|
|
461
460
|
"/src/unstable-core-do-not-import/router.ts",
|
|
462
461
|
"/src/unstable-core-do-not-import/transformer.ts",
|
|
462
|
+
"/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
|
|
463
463
|
"/src/unstable-core-do-not-import/procedureBuilder.ts"
|
|
464
464
|
],
|
|
465
465
|
"percent": 0.98,
|
|
@@ -645,7 +645,7 @@
|
|
|
645
645
|
{
|
|
646
646
|
"id": "/src/unstable-core-do-not-import/error/formatter.ts",
|
|
647
647
|
"size": 61,
|
|
648
|
-
"origSize":
|
|
648
|
+
"origSize": 984,
|
|
649
649
|
"renderedExports": [
|
|
650
650
|
"defaultFormatter"
|
|
651
651
|
],
|
|
@@ -655,7 +655,7 @@
|
|
|
655
655
|
"/src/unstable-core-do-not-import/router.ts"
|
|
656
656
|
],
|
|
657
657
|
"percent": 0.06,
|
|
658
|
-
"reduction": 93.
|
|
658
|
+
"reduction": 93.8
|
|
659
659
|
},
|
|
660
660
|
{
|
|
661
661
|
"id": "/src/http.ts",
|
|
@@ -668,9 +668,9 @@
|
|
|
668
668
|
"reduction": 100
|
|
669
669
|
},
|
|
670
670
|
{
|
|
671
|
-
"id": "/src/
|
|
671
|
+
"id": "/src/index.ts",
|
|
672
672
|
"size": 0,
|
|
673
|
-
"origSize":
|
|
673
|
+
"origSize": 32,
|
|
674
674
|
"renderedExports": [],
|
|
675
675
|
"removedExports": [],
|
|
676
676
|
"dependents": [],
|
|
@@ -678,9 +678,9 @@
|
|
|
678
678
|
"reduction": 100
|
|
679
679
|
},
|
|
680
680
|
{
|
|
681
|
-
"id": "/src/
|
|
681
|
+
"id": "/src/rpc.ts",
|
|
682
682
|
"size": 0,
|
|
683
|
-
"origSize":
|
|
683
|
+
"origSize": 36,
|
|
684
684
|
"renderedExports": [],
|
|
685
685
|
"removedExports": [],
|
|
686
686
|
"dependents": [],
|
|
@@ -4,7 +4,7 @@ import type { TRPCError } from './TRPCError';
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (
|
|
7
|
+
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (opts: {
|
|
8
8
|
error: TRPCError;
|
|
9
9
|
type: ProcedureType | 'unknown';
|
|
10
10
|
path: string | undefined;
|
|
@@ -12,14 +12,19 @@ export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (args: {
|
|
|
12
12
|
ctx: TContext | undefined;
|
|
13
13
|
shape: DefaultErrorShape;
|
|
14
14
|
}) => TShape;
|
|
15
|
-
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<any, infer TShape> ? TShape : DefaultErrorShape;
|
|
16
15
|
/**
|
|
17
16
|
* @internal
|
|
18
17
|
*/
|
|
19
18
|
export type DefaultErrorData = {
|
|
20
19
|
code: TRPC_ERROR_CODE_KEY;
|
|
21
20
|
httpStatus: number;
|
|
21
|
+
/**
|
|
22
|
+
* Path to the procedure that threw the error
|
|
23
|
+
*/
|
|
22
24
|
path?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Stack trace of the error (only in development)
|
|
27
|
+
*/
|
|
23
28
|
stack?: string;
|
|
24
29
|
};
|
|
25
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,QAAQ,EAAE,MAAM,SAAS,cAAc,IAAI,CAAC,IAAI,EAAE;IAC3E,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAC;CAC1B,KAAK,MAAM,CAAC;AAEb
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/error/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACf,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,QAAQ,EAAE,MAAM,SAAS,cAAc,IAAI,CAAC,IAAI,EAAE;IAC3E,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,iBAAiB,CAAC;CAC1B,KAAK,MAAM,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc,CAAC,gBAAgB,CAAC;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAErD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EACV,SAAS,EAGV,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,KAAK,EACV,sBAAsB,EAEtB,WAAW,EACX,YAAY,EACZ,kCAAkC,EAClC,aAAa,EAEd,MAAM,SAAS,CAAC;AAoBjB,UAAU,yBAAyB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,CAC5B,SAAQ,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACjD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACzB,kBAAkB,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;OAMG;IACH,eAAe,EAAE,CACf,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,EACxC,WAAW,EAAE,OAAO,KACjB,IAAI,CAAC;IACV;;;;;;;;OAQG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAClD;
|
|
1
|
+
{"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EACV,SAAS,EAGV,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,KAAK,EACV,sBAAsB,EAEtB,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47
|
-
const { opts , ctx , type , input , path } = procedureOpts;
|
|
48
|
-
try {
|
|
49
|
-
const data = await router.callProcedure({
|
|
50
|
-
procedures: opts.router._def.procedures,
|
|
51
|
-
path,
|
|
52
|
-
getRawInput: async ()=>input,
|
|
53
|
-
ctx,
|
|
54
|
-
type
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
result: {
|
|
58
|
-
data
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
} catch (cause) {
|
|
62
|
-
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
63
|
-
opts.onError?.({
|
|
64
|
-
error,
|
|
65
|
-
path,
|
|
66
|
-
input,
|
|
67
|
-
ctx,
|
|
68
|
-
type: type,
|
|
69
|
-
req: opts.req
|
|
70
|
-
});
|
|
71
|
-
return {
|
|
72
|
-
error: getErrorShape.getErrorShape({
|
|
73
|
-
config: opts.router._def._config,
|
|
74
|
-
error,
|
|
75
|
-
type,
|
|
76
|
-
path,
|
|
77
|
-
input,
|
|
78
|
-
ctx
|
|
79
|
-
})
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
46
|
function caughtErrorToData(cause, errorOpts) {
|
|
84
47
|
const { router , req , onError } = errorOpts.opts;
|
|
85
48
|
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
@@ -111,7 +74,7 @@ function caughtErrorToData(cause, errorOpts) {
|
|
|
111
74
|
}
|
|
112
75
|
// implementation
|
|
113
76
|
async function resolveHTTPResponse(opts) {
|
|
114
|
-
const { router , req , unstable_onHead , unstable_onChunk } = opts;
|
|
77
|
+
const { router: router$1 , req , unstable_onHead , unstable_onChunk } = opts;
|
|
115
78
|
if (req.method === 'HEAD') {
|
|
116
79
|
// can be used for lambda warmup
|
|
117
80
|
const headResponse = {
|
|
@@ -153,7 +116,7 @@ async function resolveHTTPResponse(opts) {
|
|
|
153
116
|
const inputs = await contentTypeHandler.getInputs({
|
|
154
117
|
isBatchCall,
|
|
155
118
|
req,
|
|
156
|
-
router,
|
|
119
|
+
router: router$1,
|
|
157
120
|
preprocessedBody: opts.preprocessedBody ?? false
|
|
158
121
|
});
|
|
159
122
|
paths = isBatchCall ? decodeURIComponent(opts.path).split(',') : [
|
|
@@ -170,13 +133,45 @@ async function resolveHTTPResponse(opts) {
|
|
|
170
133
|
ctx = await opts.createContext({
|
|
171
134
|
info
|
|
172
135
|
});
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
136
|
+
const errors = [];
|
|
137
|
+
const promises = paths.map(async (path, index)=>{
|
|
138
|
+
const input = inputs[index];
|
|
139
|
+
try {
|
|
140
|
+
const data = await router.callProcedure({
|
|
141
|
+
procedures: opts.router._def.procedures,
|
|
142
|
+
path,
|
|
143
|
+
getRawInput: async ()=>input,
|
|
144
|
+
ctx,
|
|
145
|
+
type
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
result: {
|
|
149
|
+
data
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
const error = TRPCError.getTRPCErrorFromUnknown(cause);
|
|
154
|
+
errors.push(error);
|
|
155
|
+
opts.onError?.({
|
|
156
|
+
error,
|
|
157
|
+
path,
|
|
158
|
+
input,
|
|
159
|
+
ctx,
|
|
160
|
+
type: type,
|
|
161
|
+
req: opts.req
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
error: getErrorShape.getErrorShape({
|
|
165
|
+
config: opts.router._def._config,
|
|
166
|
+
error,
|
|
167
|
+
type,
|
|
168
|
+
path,
|
|
169
|
+
input,
|
|
170
|
+
ctx
|
|
171
|
+
})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
180
175
|
if (!isStreamCall) {
|
|
181
176
|
/**
|
|
182
177
|
* Non-streaming response:
|
|
@@ -184,9 +179,6 @@ async function resolveHTTPResponse(opts) {
|
|
|
184
179
|
* - create headers with known response body
|
|
185
180
|
* - return a complete HTTPResponse
|
|
186
181
|
*/ const untransformedJSON = await Promise.all(promises);
|
|
187
|
-
const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
|
|
188
|
-
response.error
|
|
189
|
-
] : []);
|
|
190
182
|
const headResponse1 = initResponse({
|
|
191
183
|
ctx,
|
|
192
184
|
paths,
|
|
@@ -198,7 +190,7 @@ async function resolveHTTPResponse(opts) {
|
|
|
198
190
|
unstable_onHead?.(headResponse1, false);
|
|
199
191
|
// return body stuff
|
|
200
192
|
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
|
|
201
|
-
const transformedJSON = transformer.transformTRPCResponse(router._def._config, result);
|
|
193
|
+
const transformedJSON = transformer.transformTRPCResponse(router$1._def._config, result);
|
|
202
194
|
const body = JSON.stringify(transformedJSON);
|
|
203
195
|
unstable_onChunk?.([
|
|
204
196
|
-1,
|
|
@@ -233,7 +225,7 @@ async function resolveHTTPResponse(opts) {
|
|
|
233
225
|
const [index, untransformedJSON1] = await Promise.race(indexedPromises.values());
|
|
234
226
|
indexedPromises.delete(index);
|
|
235
227
|
try {
|
|
236
|
-
const transformedJSON1 = transformer.transformTRPCResponse(router._def._config, untransformedJSON1);
|
|
228
|
+
const transformedJSON1 = transformer.transformTRPCResponse(router$1._def._config, untransformedJSON1);
|
|
237
229
|
const body1 = JSON.stringify(transformedJSON1);
|
|
238
230
|
unstable_onChunk([
|
|
239
231
|
index,
|
|
@@ -41,43 +41,6 @@ function initResponse(initOpts) {
|
|
|
41
41
|
headers
|
|
42
42
|
};
|
|
43
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
|
-
} catch (cause) {
|
|
60
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
61
|
-
opts.onError?.({
|
|
62
|
-
error,
|
|
63
|
-
path,
|
|
64
|
-
input,
|
|
65
|
-
ctx,
|
|
66
|
-
type: type,
|
|
67
|
-
req: opts.req
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
error: getErrorShape({
|
|
71
|
-
config: opts.router._def._config,
|
|
72
|
-
error,
|
|
73
|
-
type,
|
|
74
|
-
path,
|
|
75
|
-
input,
|
|
76
|
-
ctx
|
|
77
|
-
})
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
44
|
function caughtErrorToData(cause, errorOpts) {
|
|
82
45
|
const { router , req , onError } = errorOpts.opts;
|
|
83
46
|
const error = getTRPCErrorFromUnknown(cause);
|
|
@@ -168,13 +131,45 @@ async function resolveHTTPResponse(opts) {
|
|
|
168
131
|
ctx = await opts.createContext({
|
|
169
132
|
info
|
|
170
133
|
});
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
134
|
+
const errors = [];
|
|
135
|
+
const promises = paths.map(async (path, index)=>{
|
|
136
|
+
const input = inputs[index];
|
|
137
|
+
try {
|
|
138
|
+
const data = await callProcedure({
|
|
139
|
+
procedures: opts.router._def.procedures,
|
|
140
|
+
path,
|
|
141
|
+
getRawInput: async ()=>input,
|
|
142
|
+
ctx,
|
|
143
|
+
type
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
result: {
|
|
147
|
+
data
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
} catch (cause) {
|
|
151
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
152
|
+
errors.push(error);
|
|
153
|
+
opts.onError?.({
|
|
154
|
+
error,
|
|
155
|
+
path,
|
|
156
|
+
input,
|
|
157
|
+
ctx,
|
|
158
|
+
type: type,
|
|
159
|
+
req: opts.req
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
error: getErrorShape({
|
|
163
|
+
config: opts.router._def._config,
|
|
164
|
+
error,
|
|
165
|
+
type,
|
|
166
|
+
path,
|
|
167
|
+
input,
|
|
168
|
+
ctx
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
});
|
|
178
173
|
if (!isStreamCall) {
|
|
179
174
|
/**
|
|
180
175
|
* Non-streaming response:
|
|
@@ -182,9 +177,6 @@ async function resolveHTTPResponse(opts) {
|
|
|
182
177
|
* - create headers with known response body
|
|
183
178
|
* - return a complete HTTPResponse
|
|
184
179
|
*/ const untransformedJSON = await Promise.all(promises);
|
|
185
|
-
const errors = untransformedJSON.flatMap((response)=>'error' in response ? [
|
|
186
|
-
response.error
|
|
187
|
-
] : []);
|
|
188
180
|
const headResponse1 = initResponse({
|
|
189
181
|
ctx,
|
|
190
182
|
paths,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type DefaultErrorShape, type ErrorFormatter
|
|
1
|
+
import { type DefaultErrorShape, type ErrorFormatter } from './error/formatter';
|
|
2
2
|
import { type RootConfig } from './rootConfig';
|
|
3
3
|
import { mergeRouters } from './router';
|
|
4
4
|
import type { DataTransformerOptions } from './transformer';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Unwrap, ValidateShape } from './types';
|
|
6
|
+
type inferErrorFormatterShape<TType> = TType extends ErrorFormatter<any, infer TShape> ? TShape : DefaultErrorShape;
|
|
6
7
|
interface RuntimeConfigOptions<TContext extends object, TMeta extends object> extends Partial<Omit<RootConfig<{
|
|
7
8
|
ctx: TContext;
|
|
8
9
|
meta: TMeta;
|
|
@@ -38,7 +39,7 @@ declare class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
38
39
|
_config: RootConfig<{
|
|
39
40
|
ctx: TContext;
|
|
40
41
|
meta: TMeta;
|
|
41
|
-
errorShape:
|
|
42
|
+
errorShape: undefined extends TOptions["errorFormatter"] ? DefaultErrorShape : inferErrorFormatterShape<TOptions["errorFormatter"]>;
|
|
42
43
|
transformer: undefined extends TOptions["transformer"] ? false : true;
|
|
43
44
|
}>;
|
|
44
45
|
/**
|
|
@@ -58,7 +59,7 @@ declare class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
58
59
|
router: <TProcRouterRecord extends import("./router").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("./router").CreateRouterInner<{
|
|
59
60
|
ctx: TContext;
|
|
60
61
|
meta: TMeta;
|
|
61
|
-
errorShape:
|
|
62
|
+
errorShape: undefined extends TOptions["errorFormatter"] ? DefaultErrorShape : inferErrorFormatterShape<TOptions["errorFormatter"]>;
|
|
62
63
|
transformer: undefined extends TOptions["transformer"] ? false : true;
|
|
63
64
|
}, TProcRouterRecord>;
|
|
64
65
|
/**
|
|
@@ -73,7 +74,7 @@ declare class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
73
74
|
createCallerFactory: <TRouter extends import("./router").Router<import("./router").RouterDef<{
|
|
74
75
|
ctx: TContext;
|
|
75
76
|
meta: TMeta;
|
|
76
|
-
errorShape:
|
|
77
|
+
errorShape: undefined extends TOptions["errorFormatter"] ? DefaultErrorShape : inferErrorFormatterShape<TOptions["errorFormatter"]>;
|
|
77
78
|
transformer: undefined extends TOptions["transformer"] ? false : true;
|
|
78
79
|
}, any>>>(router: TRouter) => import("./router").RouterCaller<TRouter["_def"]>;
|
|
79
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initTRPC.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/initTRPC.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,
|
|
1
|
+
{"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AAQ,EAAE,KAAK,CAAC,CAAC,GAC9D,SAAS;QAoDX;;;WAGG;;iBA7CE,QAAQ;kBACP,KAAK;;;;QA8CX;;;WAGG;;QAIH;;;WAGG;;QAEH;;;WAGG;;iBA9DE,QAAQ;kBACP,KAAK;;;;QA+DX;;;WAGG;;QAEH;;;WAGG;;iBAxEE,QAAQ;kBACP,KAAK;;;;;CA2EhB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,6BAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "11.0.0-next-beta.
|
|
3
|
+
"version": "11.0.0-next-beta.241+afd416625",
|
|
4
4
|
"description": "The tRPC server library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -157,5 +157,5 @@
|
|
|
157
157
|
"funding": [
|
|
158
158
|
"https://trpc.io/sponsor"
|
|
159
159
|
],
|
|
160
|
-
"gitHead": "
|
|
160
|
+
"gitHead": "afd4166250f89d213dcdfc3c2fb59ee389e5da6b"
|
|
161
161
|
}
|
|
@@ -9,7 +9,7 @@ import type { TRPCError } from './TRPCError';
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (
|
|
12
|
+
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (opts: {
|
|
13
13
|
error: TRPCError;
|
|
14
14
|
type: ProcedureType | 'unknown';
|
|
15
15
|
path: string | undefined;
|
|
@@ -18,19 +18,19 @@ export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (args: {
|
|
|
18
18
|
shape: DefaultErrorShape;
|
|
19
19
|
}) => TShape;
|
|
20
20
|
|
|
21
|
-
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
22
|
-
any,
|
|
23
|
-
infer TShape
|
|
24
|
-
>
|
|
25
|
-
? TShape
|
|
26
|
-
: DefaultErrorShape;
|
|
27
21
|
/**
|
|
28
22
|
* @internal
|
|
29
23
|
*/
|
|
30
24
|
export type DefaultErrorData = {
|
|
31
25
|
code: TRPC_ERROR_CODE_KEY;
|
|
32
26
|
httpStatus: number;
|
|
27
|
+
/**
|
|
28
|
+
* Path to the procedure that threw the error
|
|
29
|
+
*/
|
|
33
30
|
path?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Stack trace of the error (only in development)
|
|
33
|
+
*/
|
|
34
34
|
stack?: string;
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -132,51 +132,6 @@ function initResponse<
|
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
async function inputToProcedureCall<
|
|
136
|
-
TRouter extends AnyRouter,
|
|
137
|
-
TRequest extends HTTPRequest,
|
|
138
|
-
>(procedureOpts: {
|
|
139
|
-
opts: Pick<
|
|
140
|
-
ResolveHTTPRequestOptions<TRouter, TRequest>,
|
|
141
|
-
'onError' | 'req' | 'router'
|
|
142
|
-
>;
|
|
143
|
-
ctx: inferRouterContext<TRouter> | undefined;
|
|
144
|
-
type: 'mutation' | 'query';
|
|
145
|
-
input: unknown;
|
|
146
|
-
path: string;
|
|
147
|
-
}): Promise<TRPCResponse<unknown, inferRouterError<TRouter>>> {
|
|
148
|
-
const { opts, ctx, type, input, path } = procedureOpts;
|
|
149
|
-
try {
|
|
150
|
-
const data = await callProcedure({
|
|
151
|
-
procedures: opts.router._def.procedures,
|
|
152
|
-
path,
|
|
153
|
-
getRawInput: async () => input,
|
|
154
|
-
ctx,
|
|
155
|
-
type,
|
|
156
|
-
});
|
|
157
|
-
return {
|
|
158
|
-
result: {
|
|
159
|
-
data,
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
} catch (cause) {
|
|
163
|
-
const error = getTRPCErrorFromUnknown(cause);
|
|
164
|
-
|
|
165
|
-
opts.onError?.({ error, path, input, ctx, type: type, req: opts.req });
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
error: getErrorShape({
|
|
169
|
-
config: opts.router._def._config,
|
|
170
|
-
error,
|
|
171
|
-
type,
|
|
172
|
-
path,
|
|
173
|
-
input,
|
|
174
|
-
ctx,
|
|
175
|
-
}),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
135
|
function caughtErrorToData<
|
|
181
136
|
TRouter extends AnyRouter,
|
|
182
137
|
TRequest extends HTTPRequest,
|
|
@@ -331,9 +286,51 @@ export async function resolveHTTPResponse<
|
|
|
331
286
|
})),
|
|
332
287
|
};
|
|
333
288
|
ctx = await opts.createContext({ info });
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
289
|
+
|
|
290
|
+
const errors: TRPCError[] = [];
|
|
291
|
+
|
|
292
|
+
const promises: Promise<
|
|
293
|
+
TRPCResponse<unknown, inferRouterError<TRouter>>
|
|
294
|
+
>[] = paths.map(async (path, index) => {
|
|
295
|
+
const input = inputs[index];
|
|
296
|
+
try {
|
|
297
|
+
const data = await callProcedure({
|
|
298
|
+
procedures: opts.router._def.procedures,
|
|
299
|
+
path,
|
|
300
|
+
getRawInput: async () => input,
|
|
301
|
+
ctx,
|
|
302
|
+
type,
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
result: {
|
|
306
|
+
data,
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
} catch (cause) {
|
|
310
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
311
|
+
errors.push(error);
|
|
312
|
+
|
|
313
|
+
opts.onError?.({
|
|
314
|
+
error,
|
|
315
|
+
path,
|
|
316
|
+
input,
|
|
317
|
+
ctx,
|
|
318
|
+
type: type,
|
|
319
|
+
req: opts.req,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
error: getErrorShape({
|
|
324
|
+
config: opts.router._def._config,
|
|
325
|
+
error,
|
|
326
|
+
type,
|
|
327
|
+
path,
|
|
328
|
+
input,
|
|
329
|
+
ctx,
|
|
330
|
+
}),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
});
|
|
337
334
|
|
|
338
335
|
if (!isStreamCall) {
|
|
339
336
|
/**
|
|
@@ -344,9 +341,6 @@ export async function resolveHTTPResponse<
|
|
|
344
341
|
*/
|
|
345
342
|
|
|
346
343
|
const untransformedJSON = await Promise.all(promises);
|
|
347
|
-
const errors = untransformedJSON.flatMap((response) =>
|
|
348
|
-
'error' in response ? [response.error] : [],
|
|
349
|
-
);
|
|
350
344
|
|
|
351
345
|
const headResponse = initResponse({
|
|
352
346
|
ctx,
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
defaultFormatter,
|
|
4
4
|
type DefaultErrorShape,
|
|
5
5
|
type ErrorFormatter,
|
|
6
|
-
type ErrorFormatterShape,
|
|
7
6
|
} from './error/formatter';
|
|
8
7
|
import { createMiddlewareFactory } from './middleware';
|
|
9
8
|
import { createBuilder } from './procedureBuilder';
|
|
@@ -16,8 +15,14 @@ import {
|
|
|
16
15
|
} from './router';
|
|
17
16
|
import type { DataTransformerOptions } from './transformer';
|
|
18
17
|
import { defaultTransformer, getDataTransformer } from './transformer';
|
|
19
|
-
import type {
|
|
18
|
+
import type { Unwrap, ValidateShape } from './types';
|
|
20
19
|
|
|
20
|
+
type inferErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
21
|
+
any,
|
|
22
|
+
infer TShape
|
|
23
|
+
>
|
|
24
|
+
? TShape
|
|
25
|
+
: DefaultErrorShape;
|
|
21
26
|
interface RuntimeConfigOptions<TContext extends object, TMeta extends object>
|
|
22
27
|
extends Partial<
|
|
23
28
|
Omit<
|
|
@@ -66,12 +71,9 @@ class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
66
71
|
type $Transformer = undefined extends TOptions['transformer']
|
|
67
72
|
? false
|
|
68
73
|
: true;
|
|
69
|
-
type $ErrorShape =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
ErrorFormatter<TContext, DefaultErrorShape>
|
|
73
|
-
>
|
|
74
|
-
>;
|
|
74
|
+
type $ErrorShape = undefined extends TOptions['errorFormatter']
|
|
75
|
+
? DefaultErrorShape
|
|
76
|
+
: inferErrorFormatterShape<TOptions['errorFormatter']>;
|
|
75
77
|
|
|
76
78
|
type $Root = CreateRootTypes<{
|
|
77
79
|
ctx: TContext;
|