@trpc/server 11.0.0-next-beta.240 → 11.0.0-next-beta.242
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/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +2 -0
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +2 -0
- package/dist/adapters/node-http/types.d.ts +3 -3
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/bundle-analysis.json +36 -36
- 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/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +2 -2
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +2 -2
- 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/index.d.ts +1 -1
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +14 -8
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.d.ts +23 -38
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
- package/dist/unstable-core-do-not-import/router.js +3 -3
- package/dist/unstable-core-do-not-import/router.mjs +3 -3
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +1 -1
- 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/adapters/node-http/nodeHTTPRequestHandler.ts +4 -2
- package/src/adapters/node-http/types.ts +3 -3
- package/src/unstable-core-do-not-import/error/formatter.ts +7 -7
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +6 -3
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +45 -51
- package/src/unstable-core-do-not-import/index.ts +0 -2
- package/src/unstable-core-do-not-import/initTRPC.ts +10 -8
- package/src/unstable-core-do-not-import/router.ts +53 -78
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +1 -3
|
@@ -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
|
/**
|
|
@@ -55,10 +56,10 @@ declare class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
55
56
|
* Create a router
|
|
56
57
|
* @link https://trpc.io/docs/v11/server/routers
|
|
57
58
|
*/
|
|
58
|
-
router: <TProcRouterRecord extends import("./router").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("./router").
|
|
59
|
+
router: <TProcRouterRecord extends import("./router").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("./router").BuiltRouter<{
|
|
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
|
/**
|
|
@@ -70,12 +71,17 @@ declare class TRPCBuilder<TContext extends object, TMeta extends object> {
|
|
|
70
71
|
* Create a server-side caller for a router
|
|
71
72
|
* @link https://trpc.io/docs/v11/server/server-side-calls
|
|
72
73
|
*/
|
|
73
|
-
createCallerFactory: <
|
|
74
|
+
createCallerFactory: <TRecord extends import("./router").ProcedureRouterRecord>(router: import("./router").Router<{
|
|
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
|
+
}, TRecord>) => import("./router").RouterCaller<{
|
|
80
|
+
ctx: TContext;
|
|
81
|
+
meta: TMeta;
|
|
82
|
+
errorShape: undefined extends TOptions["errorFormatter"] ? DefaultErrorShape : inferErrorFormatterShape<TOptions["errorFormatter"]>;
|
|
83
|
+
transformer: undefined extends TOptions["transformer"] ? false : true;
|
|
84
|
+
}, TRecord>;
|
|
79
85
|
};
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initTRPC.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/initTRPC.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KA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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;;;;iBADN,QAAQ;kBACP,KAAK;;;;;CA2EhB;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,6BAAoB,CAAC"}
|
|
@@ -7,46 +7,44 @@ export type ProcedureRecord = Record<string, AnyProcedure>;
|
|
|
7
7
|
export interface ProcedureRouterRecord {
|
|
8
8
|
[key: string]: AnyProcedure | AnyRouter;
|
|
9
9
|
}
|
|
10
|
-
export interface RouterDef<TRoot extends AnyRootTypes, TRecord extends ProcedureRouterRecord> {
|
|
11
|
-
_config: RootConfig<TRoot>;
|
|
12
|
-
router: true;
|
|
13
|
-
procedure?: never;
|
|
14
|
-
procedures: TRecord;
|
|
15
|
-
record: TRecord;
|
|
16
|
-
}
|
|
17
|
-
export type AnyRouterDef = RouterDef<any, any>;
|
|
18
10
|
type DecorateProcedure<TProcedure extends AnyProcedure> = (input: inferProcedureInput<TProcedure>) => Promise<TProcedure['_def']['_output_out']>;
|
|
19
11
|
/**
|
|
20
12
|
* @internal
|
|
21
13
|
*/
|
|
22
|
-
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
14
|
+
export type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
23
15
|
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
24
16
|
};
|
|
25
17
|
/**
|
|
26
18
|
* @internal
|
|
27
19
|
*/
|
|
28
|
-
export type RouterCaller<
|
|
20
|
+
export type RouterCaller<TRoot extends AnyRootTypes, TRecord extends ProcedureRouterRecord> = (
|
|
29
21
|
/**
|
|
30
22
|
* @note
|
|
31
23
|
* If passing a function, we recommend it's a cached function
|
|
32
24
|
* e.g. wrapped in `React.cache` to avoid unnecessary computations
|
|
33
25
|
*/
|
|
34
|
-
ctx:
|
|
35
|
-
export interface Router<
|
|
36
|
-
_def:
|
|
26
|
+
ctx: TRoot['ctx'] | (() => MaybePromise<TRoot['ctx']>)) => DecoratedProcedureRecord<TRecord>;
|
|
27
|
+
export interface Router<TRoot extends AnyRootTypes, TRecord extends ProcedureRouterRecord> {
|
|
28
|
+
_def: {
|
|
29
|
+
_config: RootConfig<TRoot>;
|
|
30
|
+
router: true;
|
|
31
|
+
procedure?: never;
|
|
32
|
+
procedures: TRecord;
|
|
33
|
+
record: TRecord;
|
|
34
|
+
};
|
|
37
35
|
/**
|
|
38
36
|
* @deprecated use `t.createCallerFactory(router)` instead
|
|
39
37
|
* @link https://trpc.io/docs/v11/server/server-side-calls
|
|
40
38
|
*/
|
|
41
|
-
createCaller: RouterCaller<
|
|
39
|
+
createCaller: RouterCaller<TRoot, TRecord>;
|
|
42
40
|
}
|
|
43
|
-
export type
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
export type inferRouterContext<TRouter extends AnyRouter> =
|
|
47
|
-
export type inferRouterError<TRouter extends AnyRouter> =
|
|
48
|
-
export type inferRouterMeta<TRouter extends AnyRouter> =
|
|
49
|
-
type GetInferenceHelpers<TType extends 'input' | 'output', TRouter extends AnyRouter> = {
|
|
41
|
+
export type BuiltRouter<TRoot extends AnyRootTypes, TRecord extends ProcedureRouterRecord> = Router<TRoot, TRecord> & TRecord;
|
|
42
|
+
export type AnyRouter = Router<any, any>;
|
|
43
|
+
export type inferRouterRootTypes<TRouter extends AnyRouter> = TRouter['_def']['_config']['$types'];
|
|
44
|
+
export type inferRouterContext<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['ctx'];
|
|
45
|
+
export type inferRouterError<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['errorShape'];
|
|
46
|
+
export type inferRouterMeta<TRouter extends AnyRouter> = inferRouterRootTypes<TRouter>['meta'];
|
|
47
|
+
export type GetInferenceHelpers<TType extends 'input' | 'output', TRouter extends AnyRouter> = {
|
|
50
48
|
[TKey in keyof TRouter['_def']['record']]: TRouter['_def']['record'][TKey] extends infer TRouterOrProcedure ? TRouterOrProcedure extends AnyRouter ? GetInferenceHelpers<TType, TRouterOrProcedure> : TRouterOrProcedure extends AnyProcedure ? TType extends 'input' ? inferProcedureInput<TRouterOrProcedure> : inferTransformedProcedureOutput<TRouter, TRouterOrProcedure> : never : never;
|
|
51
49
|
};
|
|
52
50
|
export type inferRouterInputs<TRouter extends AnyRouter> = GetInferenceHelpers<'input', TRouter>;
|
|
@@ -54,32 +52,19 @@ export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<
|
|
|
54
52
|
/**
|
|
55
53
|
* @internal
|
|
56
54
|
*/
|
|
57
|
-
export
|
|
58
|
-
/**
|
|
59
|
-
* This adds ability to call procedures directly but is primarily used for quick access in type inference
|
|
60
|
-
*/
|
|
61
|
-
TProcRouterRecord;
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
export declare function createRouterFactory<TRoot extends AnyRootTypes>(config: RootConfig<TRoot>): <TProcRouterRecord extends ProcedureRouterRecord>(procedures: TProcRouterRecord) => CreateRouterInner<TRoot, TProcRouterRecord>;
|
|
55
|
+
export declare function createRouterFactory<TRoot extends AnyRootTypes>(config: RootConfig<TRoot>): <TProcRouterRecord extends ProcedureRouterRecord>(procedures: TProcRouterRecord) => BuiltRouter<TRoot, TProcRouterRecord>;
|
|
66
56
|
/**
|
|
67
57
|
* @internal
|
|
68
58
|
*/
|
|
69
59
|
export declare function callProcedure(opts: ProcedureCallOptions & {
|
|
70
60
|
procedures: ProcedureRouterRecord;
|
|
71
61
|
}): Promise<unknown>;
|
|
72
|
-
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <
|
|
62
|
+
export declare function createCallerFactory<TRoot extends AnyRootTypes>(): <TRecord extends ProcedureRouterRecord>(router: Router<TRoot, TRecord>) => RouterCaller<TRoot, TRecord>;
|
|
73
63
|
/** @internal */
|
|
74
|
-
type MergeRouters<TRouters extends AnyRouter[],
|
|
64
|
+
type MergeRouters<TRouters extends AnyRouter[], TRoot extends AnyRootTypes = TRouters[0]['_def']['_config']['$types'], TRecord extends ProcedureRouterRecord = {}> = TRouters extends [
|
|
75
65
|
infer Head extends AnyRouter,
|
|
76
66
|
...infer Tail extends AnyRouter[]
|
|
77
|
-
] ? MergeRouters<Tail,
|
|
78
|
-
_config: TRouterDef['_config'];
|
|
79
|
-
router: true;
|
|
80
|
-
procedures: Head['_def']['procedures'] & TRouterDef['procedures'];
|
|
81
|
-
record: Head['_def']['record'] & TRouterDef['record'];
|
|
82
|
-
}> : Router<TRouterDef> & TRouterDef['record'];
|
|
67
|
+
] ? MergeRouters<Tail, TRoot, Head['_def']['record'] & TRecord> : BuiltRouter<TRoot, TRecord>;
|
|
83
68
|
export declare function mergeRouters<TRouters extends AnyRouter[]>(...routerList: [...TRouters]): MergeRouters<TRouters>;
|
|
84
69
|
export {};
|
|
85
70
|
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/router.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,+BAA+B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C,iBAAiB;AACjB,MA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IAAI,SAAS,SAAS;IAC5B,GAAG,MAAM,IAAI,SAAS,SAAS,EAAE;CAClC,GACG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,GAC3D,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAEhC,wBAAgB,YAAY,CAAC,QAAQ,SAAS,SAAS,EAAE,EACvD,GAAG,UAAU,EAAE,CAAC,GAAG,QAAQ,CAAC,GAC3B,YAAY,CAAC,QAAQ,CAAC,CAoDxB"}
|
|
@@ -142,9 +142,9 @@ function mergeRouters(...routerList) {
|
|
|
142
142
|
const router = createRouterFactory({
|
|
143
143
|
errorFormatter,
|
|
144
144
|
transformer: transformer$1,
|
|
145
|
-
isDev: routerList.
|
|
146
|
-
allowOutsideOfServer: routerList.
|
|
147
|
-
isServer: routerList.
|
|
145
|
+
isDev: routerList.every((r)=>r._def._config.isDev),
|
|
146
|
+
allowOutsideOfServer: routerList.every((r)=>r._def._config.allowOutsideOfServer),
|
|
147
|
+
isServer: routerList.every((r)=>r._def._config.isServer),
|
|
148
148
|
$types: routerList[0]?._def._config.$types
|
|
149
149
|
})(record);
|
|
150
150
|
return router;
|
|
@@ -140,9 +140,9 @@ function mergeRouters(...routerList) {
|
|
|
140
140
|
const router = createRouterFactory({
|
|
141
141
|
errorFormatter,
|
|
142
142
|
transformer,
|
|
143
|
-
isDev: routerList.
|
|
144
|
-
allowOutsideOfServer: routerList.
|
|
145
|
-
isServer: routerList.
|
|
143
|
+
isDev: routerList.every((r)=>r._def._config.isDev),
|
|
144
|
+
allowOutsideOfServer: routerList.every((r)=>r._def._config.allowOutsideOfServer),
|
|
145
|
+
isServer: routerList.every((r)=>r._def._config.isServer),
|
|
146
146
|
$types: routerList[0]?._def._config.$types
|
|
147
147
|
})(record);
|
|
148
148
|
return router;
|
|
@@ -3,7 +3,7 @@ import type { TRPC_ERROR_CODE_NUMBER } from './codes';
|
|
|
3
3
|
/**
|
|
4
4
|
* Error response
|
|
5
5
|
*/
|
|
6
|
-
export interface TRPCErrorShape<TData extends
|
|
6
|
+
export interface TRPCErrorShape<TData extends object = object> {
|
|
7
7
|
code: TRPC_ERROR_CODE_NUMBER;
|
|
8
8
|
message: string;
|
|
9
9
|
data: TData;
|
|
@@ -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,
|
|
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,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC3D,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;GAEG;AACH,yBAAiB,QAAQ,CAAC;IACxB,KAAY,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAE/C;;OAEG;IACH,UAAiB,YAAY;QAC3B,EAAE,CAAC,EAAE,SAAS,CAAC;QACf,OAAO,CAAC,EAAE,KAAK,CAAC;KACjB;IAED,UAAiB,WAAW,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAC1D,SAAQ,YAAY;QACpB,MAAM,EAAE,OAAO,CAAC;KACjB;IAED,UAAiB,OAAO,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAA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G,gCAAgC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACjC,kBAAkB,GAClB,CAAC,QAAQ,CAAC,WAAW,CAAC,mBAAmB,CAAC,GAAG;IAAE,EAAE,EAAE,QAAQ,CAAC,SAAS,CAAA;CAAE,CAAC,CAAC;AAE7E,MAAM,WAAW,iBAAiB,CAAC,KAAK,CACtC,SAAQ,QAAQ,CAAC,cAAc,CAC3B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACjC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CACzC;CAAG;AAEN,MAAM,MAAM,mBAAmB,CAC7B,KAAK,GAAG,OAAO,EACf,MAAM,SAAS,cAAc,GAAG,cAAc,IAC5C;IAAE,EAAE,EAAE,QAAQ,CAAC,SAAS,CAAA;CAAE,GAAG,CAC7B,iBAAiB,CAAC,MAAM,CAAC,GACzB,iBAAiB,CAAC,KAAK,CAAC,CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,yBACf,SAAQ,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC;IACzC,EAAE,EAAE,QAAQ,CAAC,SAAS,CAAC;CACxB;AAED;;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<object>> | 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.242+4377b3cf6",
|
|
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": "4377b3cf6370c6af33064a7ae7c34299c8c00fa1"
|
|
161
161
|
}
|
|
@@ -69,7 +69,8 @@ export async function nodeHTTPRequestHandler<
|
|
|
69
69
|
const contentTypeHandler =
|
|
70
70
|
contentTypeHandlers.find((handler) =>
|
|
71
71
|
handler.isMatch({
|
|
72
|
-
|
|
72
|
+
// FIXME: no typecasting should be needed here
|
|
73
|
+
...(opts as any),
|
|
73
74
|
query,
|
|
74
75
|
}),
|
|
75
76
|
) ??
|
|
@@ -77,7 +78,8 @@ export async function nodeHTTPRequestHandler<
|
|
|
77
78
|
jsonContentTypeHandler;
|
|
78
79
|
|
|
79
80
|
const bodyResult = await contentTypeHandler.getBody({
|
|
80
|
-
|
|
81
|
+
// FIXME: no typecasting should be needed here
|
|
82
|
+
...(opts as any),
|
|
81
83
|
query,
|
|
82
84
|
});
|
|
83
85
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
import type
|
|
10
|
+
import type * as http from 'http';
|
|
11
11
|
// @trpc/server
|
|
12
12
|
import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
|
|
13
13
|
// @trpc/server/http
|
|
@@ -23,11 +23,11 @@ interface ParsedQs {
|
|
|
23
23
|
[key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type NodeHTTPRequest = IncomingMessage & {
|
|
26
|
+
export type NodeHTTPRequest = http.IncomingMessage & {
|
|
27
27
|
query?: ParsedQs;
|
|
28
28
|
body?: unknown;
|
|
29
29
|
};
|
|
30
|
-
export type NodeHTTPResponse = ServerResponse & {
|
|
30
|
+
export type NodeHTTPResponse = http.ServerResponse & {
|
|
31
31
|
/**
|
|
32
32
|
* Force the partially-compressed response to be flushed to the client.
|
|
33
33
|
*
|
|
@@ -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
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DefaultErrorData } from '../error/formatter';
|
|
1
2
|
import type { TRPCError } from '../error/TRPCError';
|
|
2
3
|
import type { TRPC_ERROR_CODES_BY_KEY, TRPCResponse } from '../rpc';
|
|
3
4
|
import { TRPC_ERROR_CODES_BY_NUMBER } from '../rpc';
|
|
@@ -32,9 +33,11 @@ export function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]) {
|
|
|
32
33
|
const httpStatuses = new Set(
|
|
33
34
|
arr.map((res) => {
|
|
34
35
|
if ('error' in res) {
|
|
35
|
-
const data = res.error.data
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const data = res.error.data as
|
|
37
|
+
| Record<string, unknown>
|
|
38
|
+
| DefaultErrorData;
|
|
39
|
+
if (typeof data.httpStatus === 'number') {
|
|
40
|
+
return data.httpStatus;
|
|
38
41
|
}
|
|
39
42
|
const code = TRPC_ERROR_CODES_BY_NUMBER[res.error.code];
|
|
40
43
|
return getStatusCodeFromKey(code);
|
|
@@ -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;
|