@trpc/server 11.0.0-next-beta.239 → 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 +38 -38
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +8 -3
- 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/dist/unstable-core-do-not-import/rootConfig.d.ts +3 -6
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +2 -2
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/transformer.d.ts +1 -1
- package/package.json +2 -2
- package/src/unstable-core-do-not-import/error/formatter.ts +8 -12
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +45 -51
- package/src/unstable-core-do-not-import/initTRPC.ts +10 -8
- package/src/unstable-core-do-not-import/rootConfig.ts +3 -7
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +1 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction":
|
|
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",
|
|
@@ -408,8 +408,8 @@
|
|
|
408
408
|
],
|
|
409
409
|
"removedExports": [],
|
|
410
410
|
"dependents": [
|
|
411
|
-
"/src/unstable-core-do-not-import/
|
|
412
|
-
"/src/unstable-core-do-not-import/
|
|
411
|
+
"/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts",
|
|
412
|
+
"/src/unstable-core-do-not-import/error/getErrorShape.ts"
|
|
413
413
|
],
|
|
414
414
|
"percent": 1.21,
|
|
415
415
|
"reduction": 16.62
|
|
@@ -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,
|
|
@@ -574,7 +574,7 @@
|
|
|
574
574
|
{
|
|
575
575
|
"id": "/src/unstable-core-do-not-import/rootConfig.ts",
|
|
576
576
|
"size": 343,
|
|
577
|
-
"origSize":
|
|
577
|
+
"origSize": 2111,
|
|
578
578
|
"renderedExports": [
|
|
579
579
|
"isServerDefault"
|
|
580
580
|
],
|
|
@@ -584,7 +584,7 @@
|
|
|
584
584
|
"/src/unstable-core-do-not-import/initTRPC.ts"
|
|
585
585
|
],
|
|
586
586
|
"percent": 0.33,
|
|
587
|
-
"reduction":
|
|
587
|
+
"reduction": 83.75
|
|
588
588
|
},
|
|
589
589
|
{
|
|
590
590
|
"id": "/src/adapters/express.ts",
|
|
@@ -621,8 +621,8 @@
|
|
|
621
621
|
],
|
|
622
622
|
"removedExports": [],
|
|
623
623
|
"dependents": [
|
|
624
|
-
"/src/adapters/node-http/content-type/
|
|
625
|
-
"/src/adapters/node-http/content-type/
|
|
624
|
+
"/src/adapters/node-http/content-type/form-data/index.ts",
|
|
625
|
+
"/src/adapters/node-http/content-type/json/index.ts"
|
|
626
626
|
],
|
|
627
627
|
"percent": 0.11,
|
|
628
628
|
"reduction": 86.68
|
|
@@ -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,12 +655,12 @@
|
|
|
655
655
|
"/src/unstable-core-do-not-import/router.ts"
|
|
656
656
|
],
|
|
657
657
|
"percent": 0.06,
|
|
658
|
-
"reduction":
|
|
658
|
+
"reduction": 93.8
|
|
659
659
|
},
|
|
660
660
|
{
|
|
661
|
-
"id": "/src/
|
|
661
|
+
"id": "/src/http.ts",
|
|
662
662
|
"size": 0,
|
|
663
|
-
"origSize":
|
|
663
|
+
"origSize": 37,
|
|
664
664
|
"renderedExports": [],
|
|
665
665
|
"removedExports": [],
|
|
666
666
|
"dependents": [],
|
|
@@ -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": [],
|
|
@@ -688,9 +688,9 @@
|
|
|
688
688
|
"reduction": 100
|
|
689
689
|
},
|
|
690
690
|
{
|
|
691
|
-
"id": "/src/
|
|
691
|
+
"id": "/src/shared.ts",
|
|
692
692
|
"size": 0,
|
|
693
|
-
"origSize":
|
|
693
|
+
"origSize": 653,
|
|
694
694
|
"renderedExports": [],
|
|
695
695
|
"removedExports": [],
|
|
696
696
|
"dependents": [],
|
|
@@ -719,6 +719,16 @@
|
|
|
719
719
|
"percent": 0,
|
|
720
720
|
"reduction": 100
|
|
721
721
|
},
|
|
722
|
+
{
|
|
723
|
+
"id": "/src/adapters/fastify/index.ts",
|
|
724
|
+
"size": 0,
|
|
725
|
+
"origSize": 78,
|
|
726
|
+
"renderedExports": [],
|
|
727
|
+
"removedExports": [],
|
|
728
|
+
"dependents": [],
|
|
729
|
+
"percent": 0,
|
|
730
|
+
"reduction": 100
|
|
731
|
+
},
|
|
722
732
|
{
|
|
723
733
|
"id": "/src/adapters/fetch/index.ts",
|
|
724
734
|
"size": 0,
|
|
@@ -736,22 +746,12 @@
|
|
|
736
746
|
"renderedExports": [],
|
|
737
747
|
"removedExports": [],
|
|
738
748
|
"dependents": [
|
|
739
|
-
"/src/adapters/express.ts",
|
|
740
749
|
"/src/adapters/next.ts",
|
|
750
|
+
"/src/adapters/express.ts",
|
|
741
751
|
"/src/adapters/standalone.ts"
|
|
742
752
|
],
|
|
743
753
|
"percent": 0,
|
|
744
754
|
"reduction": 100
|
|
745
|
-
},
|
|
746
|
-
{
|
|
747
|
-
"id": "/src/adapters/fastify/index.ts",
|
|
748
|
-
"size": 0,
|
|
749
|
-
"origSize": 78,
|
|
750
|
-
"renderedExports": [],
|
|
751
|
-
"removedExports": [],
|
|
752
|
-
"dependents": [],
|
|
753
|
-
"percent": 0,
|
|
754
|
-
"reduction": 100
|
|
755
755
|
}
|
|
756
756
|
],
|
|
757
757
|
"moduleCount": 51
|
|
@@ -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,20 +12,25 @@ export type ErrorFormatter<TContext, TShape extends TRPCErrorShape<number>> = (a
|
|
|
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
|
/**
|
|
26
31
|
* @internal
|
|
27
32
|
*/
|
|
28
|
-
export interface DefaultErrorShape extends TRPCErrorShape<
|
|
33
|
+
export interface DefaultErrorShape extends TRPCErrorShape<DefaultErrorData> {
|
|
29
34
|
message: string;
|
|
30
35
|
code: TRPC_ERROR_CODE_NUMBER;
|
|
31
36
|
}
|
|
@@ -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,
|
|
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,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
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
async function inputToProcedureCall(procedureOpts) {
|
|
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":[],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,CAAC,EAC3D,IAAI,CAAC,EACD,aAAa,CAAC,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CombinedDataTransformer } from '.';
|
|
2
|
-
import type { ErrorFormatter } from './error/formatter';
|
|
3
|
-
import type { TRPCErrorShape } from './rpc';
|
|
2
|
+
import type { DefaultErrorShape, ErrorFormatter } from './error/formatter';
|
|
4
3
|
/**
|
|
5
4
|
* The initial generics that are used in the init function
|
|
6
5
|
* @internal
|
|
@@ -8,7 +7,7 @@ import type { TRPCErrorShape } from './rpc';
|
|
|
8
7
|
export interface RootTypes {
|
|
9
8
|
ctx: object;
|
|
10
9
|
meta: object;
|
|
11
|
-
errorShape:
|
|
10
|
+
errorShape: DefaultErrorShape;
|
|
12
11
|
transformer: boolean;
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
@@ -34,9 +33,7 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
34
33
|
* Use custom error formatting
|
|
35
34
|
* @link https://trpc.io/docs/v11/error-formatting
|
|
36
35
|
*/
|
|
37
|
-
errorFormatter: ErrorFormatter<TTypes['ctx'],
|
|
38
|
-
[key: string]: any;
|
|
39
|
-
}>;
|
|
36
|
+
errorFormatter: ErrorFormatter<TTypes['ctx'], TTypes['errorShape']>;
|
|
40
37
|
/**
|
|
41
38
|
* Allow `@trpc/server` to run in non-server environments
|
|
42
39
|
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rootConfig.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/rootConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,GAAG,CAAC;AACjD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"rootConfig.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/rootConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,GAAG,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,iBAAiB,CAAC;IAC9B,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAMmB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,SAAS;IAClD;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,EAAE,uBAAuB,CAAC;IACrC;;;OAGG;IACH,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IACpE;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;CACtE;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,SAAS,IAAI,SAAS,CAAC;AAErE,MAAM,MAAM,YAAY,GAAG,eAAe,CAAC;IACzC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,GAAG,CAAC;IACV,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC,CAAC"}
|
|
@@ -3,8 +3,8 @@ import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
|
3
3
|
/**
|
|
4
4
|
* Error response
|
|
5
5
|
*/
|
|
6
|
-
export interface TRPCErrorShape<
|
|
7
|
-
code:
|
|
6
|
+
export interface TRPCErrorShape<TData extends Record<string, unknown> = Record<string, unknown>> {
|
|
7
|
+
code: TRPC_ERROR_CODE_NUMBER;
|
|
8
8
|
message: string;
|
|
9
9
|
data: TData;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/envelopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,KAAK,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/rpc/envelopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE/D,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;GAEG;AACH,yBAAiB,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;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,GAAG,OAAO,EACjB,MAAM,SAAS,cAAc,GAAG,cAAc,IAC5C,yBAAyB,GAAG,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -63,7 +63,7 @@ export declare const defaultTransformer: CombinedDataTransformer;
|
|
|
63
63
|
/**
|
|
64
64
|
* Takes a unserialized `TRPCResponse` and serializes it with the router's transformers
|
|
65
65
|
**/
|
|
66
|
-
export declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: RootConfig<AnyRootTypes>, itemOrItems: TResponse): import("./rpc").TRPCErrorResponse<import("./rpc").TRPCErrorShape<
|
|
66
|
+
export declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: RootConfig<AnyRootTypes>, itemOrItems: TResponse): import("./rpc").TRPCErrorResponse<import("./rpc").TRPCErrorShape<Record<string, unknown>>> | import("./rpc").TRPCSuccessResponse<unknown> | ({
|
|
67
67
|
id: import("./rpc").JSONRPC2.RequestId;
|
|
68
68
|
} & TRPCResultMessage<unknown>) | (TRPCResponse | TRPCResponseMessage)[];
|
|
69
69
|
/** @internal */
|
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,10 +9,7 @@ import type { TRPCError } from './TRPCError';
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export type ErrorFormatter<
|
|
13
|
-
TContext,
|
|
14
|
-
TShape extends TRPCErrorShape<number>,
|
|
15
|
-
> = (args: {
|
|
12
|
+
export type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (opts: {
|
|
16
13
|
error: TRPCError;
|
|
17
14
|
type: ProcedureType | 'unknown';
|
|
18
15
|
path: string | undefined;
|
|
@@ -21,27 +18,26 @@ export type ErrorFormatter<
|
|
|
21
18
|
shape: DefaultErrorShape;
|
|
22
19
|
}) => TShape;
|
|
23
20
|
|
|
24
|
-
export type ErrorFormatterShape<TType> = TType extends ErrorFormatter<
|
|
25
|
-
any,
|
|
26
|
-
infer TShape
|
|
27
|
-
>
|
|
28
|
-
? TShape
|
|
29
|
-
: DefaultErrorShape;
|
|
30
21
|
/**
|
|
31
22
|
* @internal
|
|
32
23
|
*/
|
|
33
24
|
export type DefaultErrorData = {
|
|
34
25
|
code: TRPC_ERROR_CODE_KEY;
|
|
35
26
|
httpStatus: number;
|
|
27
|
+
/**
|
|
28
|
+
* Path to the procedure that threw the error
|
|
29
|
+
*/
|
|
36
30
|
path?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Stack trace of the error (only in development)
|
|
33
|
+
*/
|
|
37
34
|
stack?: string;
|
|
38
35
|
};
|
|
39
36
|
|
|
40
37
|
/**
|
|
41
38
|
* @internal
|
|
42
39
|
*/
|
|
43
|
-
export interface DefaultErrorShape
|
|
44
|
-
extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, DefaultErrorData> {
|
|
40
|
+
export interface DefaultErrorShape extends TRPCErrorShape<DefaultErrorData> {
|
|
45
41
|
message: string;
|
|
46
42
|
code: TRPC_ERROR_CODE_NUMBER;
|
|
47
43
|
}
|
|
@@ -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;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CombinedDataTransformer } from '.';
|
|
2
|
-
import type { ErrorFormatter } from './error/formatter';
|
|
3
|
-
import type { TRPCErrorShape } from './rpc';
|
|
2
|
+
import type { DefaultErrorShape, ErrorFormatter } from './error/formatter';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* The initial generics that are used in the init function
|
|
@@ -9,7 +8,7 @@ import type { TRPCErrorShape } from './rpc';
|
|
|
9
8
|
export interface RootTypes {
|
|
10
9
|
ctx: object;
|
|
11
10
|
meta: object;
|
|
12
|
-
errorShape:
|
|
11
|
+
errorShape: DefaultErrorShape;
|
|
13
12
|
transformer: boolean;
|
|
14
13
|
}
|
|
15
14
|
|
|
@@ -43,10 +42,7 @@ export interface RootConfig<TTypes extends RootTypes> {
|
|
|
43
42
|
* Use custom error formatting
|
|
44
43
|
* @link https://trpc.io/docs/v11/error-formatting
|
|
45
44
|
*/
|
|
46
|
-
errorFormatter: ErrorFormatter<
|
|
47
|
-
TTypes['ctx'],
|
|
48
|
-
TRPCErrorShape<number> & { [key: string]: any }
|
|
49
|
-
>;
|
|
45
|
+
errorFormatter: ErrorFormatter<TTypes['ctx'], TTypes['errorShape']>;
|
|
50
46
|
/**
|
|
51
47
|
* Allow `@trpc/server` to run in non-server environments
|
|
52
48
|
* @warning **Use with caution**, this should likely mainly be used within testing.
|
|
@@ -6,10 +6,9 @@ import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
|
6
6
|
* Error response
|
|
7
7
|
*/
|
|
8
8
|
export interface TRPCErrorShape<
|
|
9
|
-
TCode extends number = TRPC_ERROR_CODE_NUMBER,
|
|
10
9
|
TData extends Record<string, unknown> = Record<string, unknown>,
|
|
11
10
|
> {
|
|
12
|
-
code:
|
|
11
|
+
code: TRPC_ERROR_CODE_NUMBER;
|
|
13
12
|
message: string;
|
|
14
13
|
data: TData;
|
|
15
14
|
}
|