@trpc/server 10.0.0-alpha.19 → 10.0.0-alpha.21
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/adapters/express/dist/trpc-server-adapters-express.cjs.dev.js +5 -5
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +5 -5
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +5 -5
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +16 -9
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +16 -9
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +16 -9
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +3 -3
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +4 -4
- package/dist/TRPCError.d.ts +3 -3
- package/dist/TRPCError.d.ts.map +1 -1
- package/dist/adapters/express.js +6 -7
- package/dist/adapters/express.mjs +6 -7
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +18 -12
- package/dist/adapters/fastify/index.mjs +17 -11
- package/dist/adapters/next.d.ts +1 -1
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +4 -5
- package/dist/adapters/next.mjs +4 -5
- package/dist/adapters/node-http/index.js +4 -5
- package/dist/adapters/node-http/index.mjs +4 -5
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/types.d.ts +3 -3
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +10 -8
- package/dist/adapters/standalone.mjs +10 -7
- package/dist/adapters/ws.d.ts +3 -3
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +5 -5
- package/dist/adapters/ws.mjs +5 -5
- package/dist/assertNotBrowser.d.ts.map +1 -1
- package/dist/{codes-7f46544e.js → codes-4e4d55a9.js} +2 -0
- package/dist/{codes-7a3d4f65.mjs → codes-6c13cf43.mjs} +2 -0
- package/dist/http/internals/getHTTPStatusCode.d.ts +2 -1
- package/dist/http/internals/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/http/internals/types.d.ts +4 -3
- package/dist/http/internals/types.d.ts.map +1 -1
- package/dist/http/resolveHTTPResponse.d.ts +3 -3
- package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/index.js +44 -19
- package/dist/index.mjs +46 -21
- package/dist/internals/BaseHandlerOptions.d.ts +1 -1
- package/dist/internals/BaseHandlerOptions.d.ts.map +1 -1
- package/dist/internals/OnErrorFunction.d.ts +1 -1
- package/dist/internals/OnErrorFunction.d.ts.map +1 -1
- package/dist/internals/errors.d.ts +1 -0
- package/dist/internals/errors.d.ts.map +1 -1
- package/dist/internals/middlewares.d.ts +3 -2
- package/dist/internals/middlewares.d.ts.map +1 -1
- package/dist/internals/procedure.d.ts +44 -32
- package/dist/internals/procedure.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-f9b7cd2d.mjs → nodeHTTPRequestHandler-13c4bded.mjs} +2 -3
- package/dist/{nodeHTTPRequestHandler-e02d6e5d.js → nodeHTTPRequestHandler-745e43e5.js} +3 -4
- package/dist/{resolveHTTPResponse-d4da195d.js → resolveHTTPResponse-b1167b6a.js} +6 -5
- package/dist/{resolveHTTPResponse-ca8bc869.mjs → resolveHTTPResponse-de40fda7.mjs} +6 -5
- package/dist/router.d.ts +33 -29
- package/dist/router.d.ts.map +1 -1
- package/dist/rpc/codes.d.ts +2 -0
- package/dist/rpc/codes.d.ts.map +1 -1
- package/dist/rpc/index.js +1 -1
- package/dist/rpc/index.mjs +1 -1
- package/dist/{subscription-f36af4f8.js → subscription-4b936ba3.js} +2 -2
- package/dist/{subscription-7ec5884e.mjs → subscription-8a85f253.mjs} +2 -2
- package/dist/{transformTRPCResponse-f9337285.mjs → transformTRPCResponse-9fdeecca.mjs} +50 -38
- package/dist/{transformTRPCResponse-eeeb5300.js → transformTRPCResponse-a57d3226.js} +50 -37
- package/package.json +7 -3
- package/src/TRPCError.ts +3 -3
- package/src/adapters/express.ts +2 -2
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -8
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +14 -6
- package/src/adapters/next.ts +6 -2
- package/src/adapters/node-http/internals/getPostBody.test.ts +2 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +5 -6
- package/src/adapters/node-http/types.ts +3 -3
- package/src/adapters/standalone.ts +11 -3
- package/src/adapters/ws.ts +9 -9
- package/src/assertNotBrowser.ts +1 -0
- package/src/http/internals/getHTTPStatusCode.ts +2 -1
- package/src/http/internals/types.ts +6 -7
- package/src/http/resolveHTTPResponse.ts +7 -7
- package/src/internals/BaseHandlerOptions.ts +1 -1
- package/src/internals/OnErrorFunction.ts +1 -1
- package/src/internals/errors.ts +20 -4
- package/src/internals/middlewares.ts +3 -2
- package/src/internals/procedure.ts +175 -68
- package/src/router.ts +165 -49
- package/src/rpc/codes.ts +1 -0
- package/src/subscription.ts +1 -1
- package/ws/dist/trpc-server-ws.cjs.dev.js +2 -2
- package/ws/dist/trpc-server-ws.cjs.prod.js +2 -2
- package/ws/dist/trpc-server-ws.esm.js +2 -2
package/dist/router.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { TRPCError } from './TRPCError';
|
|
1
2
|
import { MiddlewareFunction } from './internals/middlewares';
|
|
2
|
-
import { CreateProcedureWithInput, CreateProcedureWithInputOutputParser, CreateProcedureWithoutInput,
|
|
3
|
+
import { CreateProcedureWithInput, CreateProcedureWithInputOutputParser, CreateProcedureWithoutInput, Procedure, inferProcedureFromOptions } from './internals/procedure';
|
|
3
4
|
import { TRPCErrorShape, TRPC_ERROR_CODE_KEY, TRPC_ERROR_CODE_NUMBER } from './rpc';
|
|
4
5
|
import { Subscription } from './subscription';
|
|
5
6
|
import { CombinedDataTransformer, DataTransformerOptions } from './transformer';
|
|
6
|
-
import {
|
|
7
|
-
import { flatten, Prefixer, ThenArg } from './types';
|
|
7
|
+
import { Prefixer, ThenArg, flatten } from './types';
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
@@ -12,11 +12,11 @@ export declare type ProcedureType = 'query' | 'mutation' | 'subscription';
|
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
|
-
export declare type ProcedureRecord<TInputContext = any, TContext = any, TInput = any, TParsedInput = any, TOutput = any> = Record<string, Procedure<TInputContext, TContext, TInput, TParsedInput, TOutput>>;
|
|
15
|
+
export declare type ProcedureRecord<TInputContext = any, TContext = any, TMeta = any, TInput = any, TParsedInput = any, TOutput = any, TParsedOutput = any> = Record<string, Procedure<TInputContext, TContext, TMeta, TInput, TParsedInput, TOutput, TParsedOutput>>;
|
|
16
16
|
/**
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
|
-
export declare type inferProcedureInput<TProcedure extends Procedure<any, any, any, any, any>> = TProcedure extends Procedure<any, any, infer Input, any, any> ? undefined extends Input ? Input | null | void : Input : undefined;
|
|
19
|
+
export declare type inferProcedureInput<TProcedure extends Procedure<any, any, any, any, any, any, any>> = TProcedure extends Procedure<any, any, any, infer Input, any, any, any> ? undefined extends Input ? Input | null | void : Input : undefined;
|
|
20
20
|
/**
|
|
21
21
|
* @public
|
|
22
22
|
*/
|
|
@@ -24,7 +24,7 @@ export declare type inferAsyncReturnType<TFunction extends (...args: any) => any
|
|
|
24
24
|
/**
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
|
-
export declare type inferProcedureOutput<TProcedure extends Procedure<any, any, any, any, any>> = inferAsyncReturnType<TProcedure['call']>;
|
|
27
|
+
export declare type inferProcedureOutput<TProcedure extends Procedure<any, any, any, any, any, any, any>> = inferAsyncReturnType<TProcedure['call']>;
|
|
28
28
|
/**
|
|
29
29
|
* @public
|
|
30
30
|
* @beta
|
|
@@ -33,16 +33,20 @@ export declare type inferSubscriptionOutput<TRouter extends AnyRouter, TPath ext
|
|
|
33
33
|
/**
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
|
-
export declare type inferHandlerInput<TProcedure extends Procedure<any, any, any, any, any>> = TProcedure extends Procedure<any, any, infer TInput, any, any> ? undefined extends TInput ? unknown extends TInput ? [(null | undefined)?] : [(TInput | null | undefined)?] : [TInput] : [(undefined | null)?];
|
|
36
|
+
export declare type inferHandlerInput<TProcedure extends Procedure<any, any, any, any, any, any, any>> = TProcedure extends Procedure<any, any, any, infer TInput, any, any, any> ? undefined extends TInput ? unknown extends TInput ? [(null | undefined)?] : [(TInput | null | undefined)?] : [TInput] : [(undefined | null)?];
|
|
37
37
|
declare type inferHandlerFn<TProcedures extends ProcedureRecord> = <TProcedure extends TProcedures[TPath], TPath extends keyof TProcedures & string>(path: TPath, ...args: inferHandlerInput<TProcedure>) => Promise<inferProcedureOutput<TProcedures[TPath]>>;
|
|
38
38
|
/**
|
|
39
39
|
* @internal
|
|
40
40
|
*/
|
|
41
41
|
export declare type inferRouterContext<TRouter extends AnyRouter> = Parameters<TRouter['createCaller']>[0];
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare type inferRouterMeta<TRouter extends AnyRouter> = TRouter extends Router<any, any, infer TMeta, any, any, any, any> ? TMeta : {};
|
|
42
46
|
/**
|
|
43
47
|
* @public
|
|
44
48
|
*/
|
|
45
|
-
export declare type AnyRouter<TContext = any> = Router<any, TContext, any, any, any, any>;
|
|
49
|
+
export declare type AnyRouter<TContext = any> = Router<any, TContext, any, any, any, any, any>;
|
|
46
50
|
/**
|
|
47
51
|
* @internal
|
|
48
52
|
*/
|
|
@@ -71,19 +75,19 @@ export interface DefaultErrorShape extends TRPCErrorShape<TRPC_ERROR_CODE_NUMBER
|
|
|
71
75
|
message: string;
|
|
72
76
|
code: TRPC_ERROR_CODE_NUMBER;
|
|
73
77
|
}
|
|
74
|
-
declare type SwapProcedureContext<TProcedure extends Procedure<any, any, any, any, any>, TNewContext> = TProcedure extends Procedure<infer TInputContext, infer _TOldContext, infer TInput, infer TParsedInput, infer TOutput> ? Procedure<TInputContext, TNewContext, TInput, TParsedInput, TOutput> : never;
|
|
75
|
-
declare type SwapContext<TObj extends ProcedureRecord<any, any, any, any>, TNewContext> = {
|
|
78
|
+
declare type SwapProcedureContext<TProcedure extends Procedure<any, any, any, any, any, any, any>, TNewContext> = TProcedure extends Procedure<infer TInputContext, infer _TOldContext, infer TMeta, infer TInput, infer TParsedInput, infer TOutput, infer TParsedOutput> ? Procedure<TInputContext, TNewContext, TMeta, TInput, TParsedInput, TOutput, TParsedOutput> : never;
|
|
79
|
+
declare type SwapContext<TObj extends ProcedureRecord<any, any, any, any, any, any>, TNewContext> = {
|
|
76
80
|
[P in keyof TObj]: SwapProcedureContext<TObj[P], TNewContext>;
|
|
77
81
|
};
|
|
78
82
|
/**
|
|
79
83
|
* @internal The type signature of this class may change without warning.
|
|
80
84
|
*/
|
|
81
|
-
export declare class Router<TInputContext, TContext, TQueries extends ProcedureRecord<TInputContext, TContext>, TMutations extends ProcedureRecord<TInputContext, TContext>, TSubscriptions extends ProcedureRecord<TInputContext, TContext, unknown, Subscription<unknown
|
|
85
|
+
export declare class Router<TInputContext, TContext, TMeta extends Record<string, any>, TQueries extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TMutations extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TSubscriptions extends ProcedureRecord<TInputContext, TContext, unknown, unknown, Subscription<unknown>, unknown, unknown>, TErrorShape extends TRPCErrorShape<number>> {
|
|
82
86
|
readonly _def: {
|
|
83
87
|
queries: TQueries;
|
|
84
88
|
mutations: TMutations;
|
|
85
89
|
subscriptions: TSubscriptions;
|
|
86
|
-
middlewares: MiddlewareFunction<TInputContext, TContext>[];
|
|
90
|
+
middlewares: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
87
91
|
errorFormatter: ErrorFormatter<TContext, TErrorShape>;
|
|
88
92
|
transformer: CombinedDataTransformer;
|
|
89
93
|
};
|
|
@@ -91,40 +95,40 @@ export declare class Router<TInputContext, TContext, TQueries extends ProcedureR
|
|
|
91
95
|
queries?: TQueries;
|
|
92
96
|
mutations?: TMutations;
|
|
93
97
|
subscriptions?: TSubscriptions;
|
|
94
|
-
middlewares?: MiddlewareFunction<TInputContext, TContext>[];
|
|
98
|
+
middlewares?: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
95
99
|
errorFormatter?: ErrorFormatter<TContext, TErrorShape>;
|
|
96
100
|
transformer?: CombinedDataTransformer;
|
|
97
101
|
});
|
|
98
102
|
private static prefixProcedures;
|
|
99
|
-
query<TPath extends string, TInput, TParsedInput, TOutput>(path: TPath, procedure: CreateProcedureWithInputOutputParser<TContext, TInput, TParsedInput, TOutput>): Router<TInputContext, TContext, TQueries & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TMutations, TSubscriptions, TErrorShape>;
|
|
100
|
-
query<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext,
|
|
101
|
-
query<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TInputContext, TContext, TQueries & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TMutations, TSubscriptions, TErrorShape>;
|
|
102
|
-
mutation<TPath extends string, TInput, TParsedInput, TOutput>(path: TPath, procedure: CreateProcedureWithInputOutputParser<TContext, TInput, TParsedInput, TOutput>): Router<TInputContext, TContext, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TSubscriptions, TErrorShape>;
|
|
103
|
-
mutation<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext,
|
|
104
|
-
mutation<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TInputContext, TContext, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TSubscriptions, TErrorShape>;
|
|
103
|
+
query<TPath extends string, TInput, TParsedInput, TOutput, TParsedOutput>(path: TPath, procedure: CreateProcedureWithInputOutputParser<TContext, TMeta, TInput, TParsedInput, TOutput, TParsedOutput>): Router<TInputContext, TContext, TMeta, TQueries & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TMutations, TSubscriptions, TErrorShape>;
|
|
104
|
+
query<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>): Router<TInputContext, TContext, TMeta, TQueries & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TMutations, TSubscriptions, TErrorShape>;
|
|
105
|
+
query<TPath extends string, TOutput, TParsedOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TMeta, TOutput, TParsedOutput>): Router<TInputContext, TContext, TMeta, TQueries & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TMutations, TSubscriptions, TErrorShape>;
|
|
106
|
+
mutation<TPath extends string, TInput, TParsedInput, TOutput, TParsedOutput>(path: TPath, procedure: CreateProcedureWithInputOutputParser<TContext, TMeta, TInput, TParsedInput, TOutput, TParsedOutput>): Router<TInputContext, TContext, TMeta, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TSubscriptions, TErrorShape>;
|
|
107
|
+
mutation<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>): Router<TInputContext, TContext, TMeta, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TSubscriptions, TErrorShape>;
|
|
108
|
+
mutation<TPath extends string, TOutput, TParsedOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TMeta, TOutput, TParsedOutput>): Router<TInputContext, TContext, TMeta, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TSubscriptions, TErrorShape>;
|
|
105
109
|
/**
|
|
106
110
|
* @beta Might change without a major version bump
|
|
107
111
|
*/
|
|
108
|
-
subscription<TPath extends string, TInput, TParsedInput, TOutput extends Subscription<unknown>>(path: TPath, procedure: CreateProcedureWithInputOutputParser<TContext, TInput, TParsedInput, TOutput>): Router<TInputContext, TContext, TQueries, TMutations, TSubscriptions & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TErrorShape>;
|
|
112
|
+
subscription<TPath extends string, TInput, TParsedInput, TOutput extends Subscription<unknown>>(path: TPath, procedure: Omit<CreateProcedureWithInputOutputParser<TContext, TMeta, TInput, TParsedInput, TOutput, unknown>, 'output'>): Router<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TErrorShape>;
|
|
109
113
|
/**
|
|
110
114
|
* @beta Might change without a major version bump
|
|
111
115
|
*/
|
|
112
|
-
subscription<TPath extends string, TInput, TOutput extends Subscription<unknown>>(path: TPath, procedure: CreateProcedureWithInput<TContext,
|
|
116
|
+
subscription<TPath extends string, TInput, TOutput extends Subscription<unknown>>(path: TPath, procedure: Omit<CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>, 'output'>): Router<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TErrorShape>;
|
|
113
117
|
/**
|
|
114
118
|
* @beta Might change without a major version bump
|
|
115
119
|
*/
|
|
116
|
-
subscription<TPath extends string, TOutput extends Subscription<unknown>>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TInputContext, TContext, TQueries, TMutations, TSubscriptions & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TErrorShape>;
|
|
120
|
+
subscription<TPath extends string, TOutput extends Subscription<unknown>>(path: TPath, procedure: Omit<CreateProcedureWithoutInput<TContext, TMeta, TOutput, unknown>, 'output'>): Router<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions & Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>, TErrorShape>;
|
|
117
121
|
/**
|
|
118
122
|
* Merge router with other router
|
|
119
123
|
* @param router
|
|
120
124
|
*/
|
|
121
|
-
merge<TChildRouter extends Router<TContext, any, any, any, any, any>>(router: TChildRouter): Router<TInputContext, inferRouterContext<TChildRouter>, TQueries & TChildRouter['_def']['queries'], TMutations & TChildRouter['_def']['mutations'], TSubscriptions & TChildRouter['_def']['subscriptions'], TErrorShape>;
|
|
125
|
+
merge<TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>>(router: TChildRouter): Router<TInputContext, inferRouterContext<TChildRouter>, TMeta, TQueries & TChildRouter['_def']['queries'], TMutations & TChildRouter['_def']['mutations'], TSubscriptions & TChildRouter['_def']['subscriptions'], TErrorShape>;
|
|
122
126
|
/**
|
|
123
127
|
* Merge router with other router
|
|
124
128
|
* @param prefix Prefix that this router should live under
|
|
125
129
|
* @param router
|
|
126
130
|
*/
|
|
127
|
-
merge<TPath extends string, TChildRouter extends Router<TContext, any, any, any, any, any>>(prefix: TPath, router: TChildRouter): Router<TInputContext, inferRouterContext<TChildRouter>, TQueries & Prefixer<TChildRouter['_def']['queries'], `${TPath}`>, TMutations & Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>, TSubscriptions & Prefixer<TChildRouter['_def']['subscriptions'], `${TPath}`>, TErrorShape>;
|
|
131
|
+
merge<TPath extends string, TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>>(prefix: TPath, router: TChildRouter): Router<TInputContext, inferRouterContext<TChildRouter>, TMeta, TQueries & Prefixer<TChildRouter['_def']['queries'], `${TPath}`>, TMutations & Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>, TSubscriptions & Prefixer<TChildRouter['_def']['subscriptions'], `${TPath}`>, TErrorShape>;
|
|
128
132
|
/**
|
|
129
133
|
* Invoke procedure. Only for internal use within library.
|
|
130
134
|
*/
|
|
@@ -138,12 +142,12 @@ export declare class Router<TInputContext, TContext, TQueries extends ProcedureR
|
|
|
138
142
|
* Function to be called before any procedure is invoked
|
|
139
143
|
* @link https://trpc.io/docs/middlewares
|
|
140
144
|
*/
|
|
141
|
-
middleware<TNewContext>(middleware: MiddlewareFunction<TContext, TNewContext>): Router<TInputContext, TNewContext, SwapContext<TQueries, TNewContext>, SwapContext<TMutations, TNewContext>, SwapContext<TSubscriptions, TNewContext>, TErrorShape>;
|
|
145
|
+
middleware<TNewContext>(middleware: MiddlewareFunction<TContext, TNewContext, TMeta>): Router<TInputContext, TNewContext, TMeta, SwapContext<TQueries, TNewContext>, SwapContext<TMutations, TNewContext>, SwapContext<TSubscriptions, TNewContext>, TErrorShape>;
|
|
142
146
|
/**
|
|
143
147
|
* Format errors
|
|
144
148
|
* @link https://trpc.io/docs/error-formatting
|
|
145
149
|
*/
|
|
146
|
-
formatError<TErrorFormatter extends ErrorFormatter<TContext, TRPCErrorShape<number>>>(errorFormatter: TErrorFormatter): Router<TInputContext, TContext, TQueries, TMutations, TSubscriptions, ReturnType<TErrorFormatter>>;
|
|
150
|
+
formatError<TErrorFormatter extends ErrorFormatter<TContext, TRPCErrorShape<number>>>(errorFormatter: TErrorFormatter): Router<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions, ReturnType<TErrorFormatter>>;
|
|
147
151
|
getErrorShape(opts: {
|
|
148
152
|
error: TRPCError;
|
|
149
153
|
type: ProcedureType | 'unknown';
|
|
@@ -155,15 +159,15 @@ export declare class Router<TInputContext, TContext, TQueries extends ProcedureR
|
|
|
155
159
|
* Add data transformer to serialize/deserialize input args + output
|
|
156
160
|
* @link https://trpc.io/docs/data-transformers
|
|
157
161
|
*/
|
|
158
|
-
transformer(_transformer: DataTransformerOptions): Router<TInputContext, TContext, TQueries, TMutations, TSubscriptions, TErrorShape>;
|
|
162
|
+
transformer(_transformer: DataTransformerOptions): Router<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions, TErrorShape>;
|
|
159
163
|
/**
|
|
160
164
|
* Flattens the generics of TQueries/TMutations/TSubscriptions.
|
|
161
165
|
* ⚠️ Experimental - might disappear. ⚠️
|
|
162
166
|
*
|
|
163
167
|
* @alpha
|
|
164
168
|
*/
|
|
165
|
-
flat(): Router<TInputContext, TContext, flatten<{}, TQueries>, flatten<{}, TMutations>, flatten<{}, TSubscriptions>, TErrorShape>;
|
|
169
|
+
flat(): Router<TInputContext, TContext, TMeta, flatten<{}, TQueries>, flatten<{}, TMutations>, flatten<{}, TSubscriptions>, TErrorShape>;
|
|
166
170
|
}
|
|
167
|
-
export declare function router<TContext>(): Router<TContext, TContext, {}, {}, {}, DefaultErrorShape>;
|
|
171
|
+
export declare function router<TContext, TMeta extends Record<string, any> = {}>(): Router<TContext, TContext, TMeta, {}, {}, {}, DefaultErrorShape>;
|
|
168
172
|
export {};
|
|
169
173
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,wBAAwB,EACxB,oCAAoC,EACpC,2BAA2B,EAC3B,SAAS,EAGT,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIrD;;GAEG;AACH,oBAAY,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,cAAc,CAAC;AAElE;;GAEG;AACH,oBAAY,eAAe,CACzB,aAAa,GAAG,GAAG,EACnB,QAAQ,GAAG,GAAG,EACd,KAAK,GAAG,GAAG,EACX,MAAM,GAAG,GAAG,EACZ,YAAY,GAAG,GAAG,EAClB,OAAO,GAAG,GAAG,EACb,aAAa,GAAG,GAAG,IACjB,MAAM,CACR,MAAM,EACN,SAAS,CACP,aAAa,EACb,QAAQ,EACR,KAAK,EACL,MAAM,EACN,YAAY,EACZ,OAAO,EACP,aAAa,CACd,CACF,CAAC;AAEF;;GAEG;AACH,oBAAY,mBAAmB,CAC7B,UAAU,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC7D,UAAU,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,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a,GAAG,SAAS,CAAC;QAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,EAAE,SAAS,GAAG,QAAQ,CAAC;KAC3B,GAAG,WAAW;IAuBf;;;OAGG;IACH,WAAW,CAAC,YAAY,EAAE,sBAAsB;IAsBhD;;;;;OAKG;IACI,IAAI,IAAI,MAAM,CACnB,aAAa,EACb,QAAQ,EACR,KAAK,EACL,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC,EACrB,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,EACvB,OAAO,CAAC,EAAE,EAAE,cAAc,CAAC,EAC3B,WAAW,CACZ;CAGF;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,sEAEtE"}
|
package/dist/rpc/codes.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const TRPC_ERROR_CODES_BY_KEY: {
|
|
|
23
23
|
readonly NOT_FOUND: -32004;
|
|
24
24
|
readonly METHOD_NOT_SUPPORTED: -32005;
|
|
25
25
|
readonly TIMEOUT: -32008;
|
|
26
|
+
readonly CONFLICT: -32009;
|
|
26
27
|
readonly PRECONDITION_FAILED: -32012;
|
|
27
28
|
readonly PAYLOAD_TOO_LARGE: -32013;
|
|
28
29
|
readonly CLIENT_CLOSED_REQUEST: -32099;
|
|
@@ -36,6 +37,7 @@ export declare const TRPC_ERROR_CODES_BY_NUMBER: {
|
|
|
36
37
|
[-32004]: "NOT_FOUND";
|
|
37
38
|
[-32005]: "METHOD_NOT_SUPPORTED";
|
|
38
39
|
[-32008]: "TIMEOUT";
|
|
40
|
+
[-32009]: "CONFLICT";
|
|
39
41
|
[-32012]: "PRECONDITION_FAILED";
|
|
40
42
|
[-32013]: "PAYLOAD_TOO_LARGE";
|
|
41
43
|
[-32099]: "CLIENT_CLOSED_REQUEST";
|
package/dist/rpc/codes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/rpc/codes.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/rpc/codes.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;;;;;;;;;;CAYK,CAAC;AAEX,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;CAAkC,CAAC;AAC1E,aAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7B,oBAAY,sBAAsB,GAAG,OAAO,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,oBAAY,mBAAmB,GAAG,MAAM,OAAO,uBAAuB,CAAC"}
|
package/dist/rpc/index.js
CHANGED
package/dist/rpc/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { T as TRPC_ERROR_CODES_BY_KEY, a as TRPC_ERROR_CODES_BY_NUMBER } from '../codes-
|
|
1
|
+
export { T as TRPC_ERROR_CODES_BY_KEY, a as TRPC_ERROR_CODES_BY_NUMBER } from '../codes-6c13cf43.mjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var events = require('events');
|
|
4
|
-
var transformTRPCResponse = require('./transformTRPCResponse-
|
|
4
|
+
var transformTRPCResponse = require('./transformTRPCResponse-a57d3226.js');
|
|
5
5
|
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
7
|
class SubscriptionEventEmitter extends events.EventEmitter {}
|
|
@@ -123,7 +123,7 @@ function subscriptionPullFactory(opts) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
return new Subscription(emit => {
|
|
126
|
-
_pull(emit);
|
|
126
|
+
_pull(emit).catch(err => emit.error(transformTRPCResponse.getErrorFromUnknown(err)));
|
|
127
127
|
|
|
128
128
|
return () => {
|
|
129
129
|
clearTimeout(timer);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import {
|
|
2
|
+
import { a as getErrorFromUnknown } from './transformTRPCResponse-9fdeecca.mjs';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
5
|
class SubscriptionEventEmitter extends EventEmitter {}
|
|
@@ -121,7 +121,7 @@ function subscriptionPullFactory(opts) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
return new Subscription(emit => {
|
|
124
|
-
_pull(emit);
|
|
124
|
+
_pull(emit).catch(err => emit.error(getErrorFromUnknown(err)));
|
|
125
125
|
|
|
126
126
|
return () => {
|
|
127
127
|
clearTimeout(timer);
|
|
@@ -1,27 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
input
|
|
6
|
-
} = opts;
|
|
7
|
-
const caller = opts.router.createCaller(opts.ctx);
|
|
1
|
+
function getMessageFromUnkownError(err, fallback) {
|
|
2
|
+
if (typeof err === 'string') {
|
|
3
|
+
return err;
|
|
4
|
+
}
|
|
8
5
|
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
6
|
+
if (err instanceof Error && typeof err.message === 'string') {
|
|
7
|
+
return err.message;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
return fallback;
|
|
11
|
+
}
|
|
12
|
+
function getErrorFromUnknown(cause) {
|
|
13
|
+
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
14
|
+
// ref https://github.com/trpc/trpc/issues/331
|
|
15
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
16
|
+
return cause;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
let errorCause = undefined;
|
|
20
|
+
let stack = undefined;
|
|
21
|
+
|
|
22
|
+
if (cause instanceof Error) {
|
|
23
|
+
errorCause = cause; // take stack trace from cause
|
|
24
|
+
|
|
25
|
+
stack = cause.stack;
|
|
20
26
|
}
|
|
21
|
-
/* istanbul ignore next */
|
|
22
27
|
|
|
28
|
+
const err = new TRPCError({
|
|
29
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
30
|
+
cause: errorCause
|
|
31
|
+
});
|
|
32
|
+
err.stack = stack;
|
|
33
|
+
return err;
|
|
34
|
+
}
|
|
35
|
+
function getCauseFromUnknown(cause) {
|
|
36
|
+
if (cause instanceof Error) {
|
|
37
|
+
return cause;
|
|
38
|
+
}
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
return undefined;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
class TRPCError extends Error {
|
|
@@ -46,34 +62,30 @@ class TRPCError extends Error {
|
|
|
46
62
|
|
|
47
63
|
}
|
|
48
64
|
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
async function callProcedure(opts) {
|
|
66
|
+
const {
|
|
67
|
+
type,
|
|
68
|
+
path,
|
|
69
|
+
input
|
|
70
|
+
} = opts;
|
|
71
|
+
const caller = opts.router.createCaller(opts.ctx);
|
|
53
72
|
|
|
54
|
-
if (
|
|
55
|
-
return
|
|
73
|
+
if (type === 'query') {
|
|
74
|
+
return caller.query(path, input);
|
|
56
75
|
}
|
|
57
76
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function getErrorFromUnknown(cause) {
|
|
61
|
-
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
62
|
-
// ref https://github.com/trpc/trpc/issues/331
|
|
63
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
64
|
-
return cause;
|
|
77
|
+
if (type === 'mutation') {
|
|
78
|
+
return caller.mutation(path, input);
|
|
65
79
|
}
|
|
66
80
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}); // take stack trace from cause
|
|
71
|
-
|
|
72
|
-
if (cause instanceof Error) {
|
|
73
|
-
err.stack = cause.stack;
|
|
81
|
+
if (type === 'subscription') {
|
|
82
|
+
const sub = await caller.subscription(path, input);
|
|
83
|
+
return sub;
|
|
74
84
|
}
|
|
85
|
+
/* istanbul ignore next */
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
|
|
88
|
+
throw new Error(`Unknown procedure type ${type}`);
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
function transformTRPCResponseItem(router, item) {
|
|
@@ -102,4 +114,4 @@ function transformTRPCResponse(router, itemOrItems) {
|
|
|
102
114
|
return Array.isArray(itemOrItems) ? itemOrItems.map(item => transformTRPCResponseItem(router, item)) : transformTRPCResponseItem(router, itemOrItems);
|
|
103
115
|
}
|
|
104
116
|
|
|
105
|
-
export { TRPCError as T, callProcedure as c,
|
|
117
|
+
export { TRPCError as T, getErrorFromUnknown as a, callProcedure as c, getCauseFromUnknown as g, transformTRPCResponse as t };
|
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
input
|
|
8
|
-
} = opts;
|
|
9
|
-
const caller = opts.router.createCaller(opts.ctx);
|
|
3
|
+
function getMessageFromUnkownError(err, fallback) {
|
|
4
|
+
if (typeof err === 'string') {
|
|
5
|
+
return err;
|
|
6
|
+
}
|
|
10
7
|
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
8
|
+
if (err instanceof Error && typeof err.message === 'string') {
|
|
9
|
+
return err.message;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
function getErrorFromUnknown(cause) {
|
|
15
|
+
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
16
|
+
// ref https://github.com/trpc/trpc/issues/331
|
|
17
|
+
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
18
|
+
return cause;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
let errorCause = undefined;
|
|
22
|
+
let stack = undefined;
|
|
23
|
+
|
|
24
|
+
if (cause instanceof Error) {
|
|
25
|
+
errorCause = cause; // take stack trace from cause
|
|
26
|
+
|
|
27
|
+
stack = cause.stack;
|
|
22
28
|
}
|
|
23
|
-
/* istanbul ignore next */
|
|
24
29
|
|
|
30
|
+
const err = new TRPCError({
|
|
31
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
32
|
+
cause: errorCause
|
|
33
|
+
});
|
|
34
|
+
err.stack = stack;
|
|
35
|
+
return err;
|
|
36
|
+
}
|
|
37
|
+
function getCauseFromUnknown(cause) {
|
|
38
|
+
if (cause instanceof Error) {
|
|
39
|
+
return cause;
|
|
40
|
+
}
|
|
25
41
|
|
|
26
|
-
|
|
42
|
+
return undefined;
|
|
27
43
|
}
|
|
28
44
|
|
|
29
45
|
class TRPCError extends Error {
|
|
@@ -48,34 +64,30 @@ class TRPCError extends Error {
|
|
|
48
64
|
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
async function callProcedure(opts) {
|
|
68
|
+
const {
|
|
69
|
+
type,
|
|
70
|
+
path,
|
|
71
|
+
input
|
|
72
|
+
} = opts;
|
|
73
|
+
const caller = opts.router.createCaller(opts.ctx);
|
|
55
74
|
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
75
|
+
if (type === 'query') {
|
|
76
|
+
return caller.query(path, input);
|
|
58
77
|
}
|
|
59
78
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function getErrorFromUnknown(cause) {
|
|
63
|
-
// this should ideally be an `instanceof TRPCError` but for some reason that isn't working
|
|
64
|
-
// ref https://github.com/trpc/trpc/issues/331
|
|
65
|
-
if (cause instanceof Error && cause.name === 'TRPCError') {
|
|
66
|
-
return cause;
|
|
79
|
+
if (type === 'mutation') {
|
|
80
|
+
return caller.mutation(path, input);
|
|
67
81
|
}
|
|
68
82
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}); // take stack trace from cause
|
|
73
|
-
|
|
74
|
-
if (cause instanceof Error) {
|
|
75
|
-
err.stack = cause.stack;
|
|
83
|
+
if (type === 'subscription') {
|
|
84
|
+
const sub = await caller.subscription(path, input);
|
|
85
|
+
return sub;
|
|
76
86
|
}
|
|
87
|
+
/* istanbul ignore next */
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
|
|
90
|
+
throw new Error(`Unknown procedure type ${type}`);
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
function transformTRPCResponseItem(router, item) {
|
|
@@ -106,5 +118,6 @@ function transformTRPCResponse(router, itemOrItems) {
|
|
|
106
118
|
|
|
107
119
|
exports.TRPCError = TRPCError;
|
|
108
120
|
exports.callProcedure = callProcedure;
|
|
121
|
+
exports.getCauseFromUnknown = getCauseFromUnknown;
|
|
109
122
|
exports.getErrorFromUnknown = getErrorFromUnknown;
|
|
110
123
|
exports.transformTRPCResponse = transformTRPCResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.21",
|
|
4
4
|
"description": "tRPC Server",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
},
|
|
13
13
|
"eslintConfig": {
|
|
14
14
|
"rules": {
|
|
15
|
-
"explicit-module-boundary-types": "off"
|
|
15
|
+
"explicit-module-boundary-types": "off",
|
|
16
|
+
"no-restricted-imports": [
|
|
17
|
+
"error",
|
|
18
|
+
"@trpc/server"
|
|
19
|
+
]
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"scripts": {
|
|
@@ -103,5 +107,5 @@
|
|
|
103
107
|
"dependencies": {
|
|
104
108
|
"tslib": "^2.1.0"
|
|
105
109
|
},
|
|
106
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "0db16da18ee5fc1ea4b2149490c316a4a700d2ab"
|
|
107
111
|
}
|
package/src/TRPCError.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { TRPC_ERROR_CODE_KEY } from './rpc/codes';
|
|
2
1
|
import { getMessageFromUnkownError } from './internals/errors';
|
|
2
|
+
import { TRPC_ERROR_CODE_KEY } from './rpc/codes';
|
|
3
3
|
|
|
4
4
|
export class TRPCError extends Error {
|
|
5
|
-
public readonly cause?:
|
|
5
|
+
public readonly cause?: Error | undefined;
|
|
6
6
|
public readonly code;
|
|
7
7
|
|
|
8
8
|
constructor(opts: {
|
|
9
9
|
message?: string;
|
|
10
10
|
code: TRPC_ERROR_CODE_KEY;
|
|
11
|
-
cause?:
|
|
11
|
+
cause?: Error;
|
|
12
12
|
}) {
|
|
13
13
|
const cause = opts.cause;
|
|
14
14
|
const code = opts.code;
|
package/src/adapters/express.ts
CHANGED
|
@@ -15,10 +15,10 @@ export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<
|
|
|
15
15
|
export function createExpressMiddleware<TRouter extends AnyRouter>(
|
|
16
16
|
opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>,
|
|
17
17
|
): express.Handler {
|
|
18
|
-
return (req, res) => {
|
|
18
|
+
return async (req, res) => {
|
|
19
19
|
const endpoint = req.path.slice(1);
|
|
20
20
|
|
|
21
|
-
nodeHTTPRequestHandler({
|
|
21
|
+
await nodeHTTPRequestHandler({
|
|
22
22
|
...opts,
|
|
23
23
|
req,
|
|
24
24
|
res,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { URLSearchParams } from 'url';
|
|
2
1
|
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
2
|
import { assertNotBrowser } from '../../assertNotBrowser';
|
|
4
|
-
import { NodeHTTPCreateContextOption } from '../node-http';
|
|
5
|
-
import { AnyRouter, inferRouterContext } from '../../router';
|
|
6
|
-
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
|
|
7
3
|
import {
|
|
8
4
|
HTTPBaseHandlerOptions,
|
|
9
5
|
HTTPRequest,
|
|
10
6
|
} from '../../http/internals/types';
|
|
7
|
+
import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
|
|
8
|
+
import { AnyRouter, inferRouterContext } from '../../router';
|
|
9
|
+
import { NodeHTTPCreateContextOption } from '../node-http';
|
|
11
10
|
|
|
12
11
|
assertNotBrowser();
|
|
13
12
|
|
|
@@ -67,13 +66,12 @@ export async function fastifyRequestHandler<
|
|
|
67
66
|
if ('status' in result && (!res.statusCode || res.statusCode === 200)) {
|
|
68
67
|
res.statusCode = result.status;
|
|
69
68
|
}
|
|
70
|
-
|
|
71
69
|
for (const [key, value] of Object.entries(result.headers ?? {})) {
|
|
72
70
|
if (typeof value === 'undefined') {
|
|
73
71
|
continue;
|
|
74
72
|
}
|
|
75
|
-
res.header(key, value);
|
|
76
|
-
}
|
|
77
73
|
|
|
78
|
-
|
|
74
|
+
void res.header(key, value);
|
|
75
|
+
}
|
|
76
|
+
await res.send(result.body);
|
|
79
77
|
}
|