@trpc/server 10.0.0-alpha.2 → 10.0.0-alpha.20
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 -4
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +5 -4
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +5 -4
- package/adapters/express/index.d.ts +1 -0
- package/adapters/express/index.js +1 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.d.ts +1 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +109 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.js +7 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +109 -0
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +104 -0
- package/adapters/fastify/index.d.ts +1 -0
- package/adapters/fastify/index.js +1 -0
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +2 -1
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +2 -1
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +2 -1
- package/adapters/next/index.d.ts +1 -0
- package/adapters/next/index.js +1 -0
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +2 -1
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +2 -1
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +2 -1
- package/adapters/node-http/index.d.ts +1 -0
- package/adapters/node-http/index.js +1 -0
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +3 -2
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +3 -2
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +3 -2
- package/adapters/standalone/index.d.ts +1 -0
- package/adapters/standalone/index.js +1 -0
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +5 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +5 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +5 -4
- package/adapters/ws/index.d.ts +1 -0
- package/adapters/ws/index.js +1 -0
- package/dist/{declarations/src/TRPCError.d.ts → TRPCError.d.ts} +10 -18
- package/dist/TRPCError.d.ts.map +1 -0
- package/dist/{declarations/src/adapters → adapters}/express.d.ts +5 -5
- package/dist/adapters/express.d.ts.map +1 -0
- package/dist/adapters/express.js +23 -0
- package/dist/adapters/express.mjs +19 -0
- package/dist/adapters/express.ts.js +1 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +13 -0
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +12 -0
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -0
- package/dist/adapters/fastify/index.d.ts +3 -0
- package/dist/adapters/fastify/index.d.ts.map +1 -0
- package/dist/adapters/fastify/index.js +109 -0
- package/dist/adapters/fastify/index.mjs +104 -0
- package/dist/adapters/fastify/index.ts.js +1 -0
- package/dist/{declarations/src/adapters → adapters}/next.d.ts +5 -5
- package/dist/adapters/next.d.ts.map +1 -0
- package/dist/adapters/next.js +56 -0
- package/dist/adapters/next.mjs +52 -0
- package/dist/adapters/next.ts.js +1 -0
- package/dist/{declarations/src/adapters → adapters}/node-http/index.d.ts +2 -2
- package/dist/adapters/node-http/index.d.ts.map +1 -0
- package/dist/adapters/node-http/index.js +13 -0
- package/dist/adapters/node-http/index.mjs +5 -0
- package/dist/adapters/node-http/index.ts.js +1 -0
- package/dist/{declarations/src/adapters → adapters}/node-http/internals/getPostBody.d.ts +12 -12
- package/dist/adapters/node-http/internals/getPostBody.d.ts.map +1 -0
- package/dist/{declarations/src/adapters → adapters}/node-http/nodeHTTPRequestHandler.d.ts +9 -9
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -0
- package/dist/{declarations/src/adapters → adapters}/node-http/types.d.ts +32 -32
- package/dist/adapters/node-http/types.d.ts.map +1 -0
- package/dist/{declarations/src/adapters → adapters}/standalone.d.ts +13 -13
- package/dist/adapters/standalone.d.ts.map +1 -0
- package/dist/adapters/standalone.js +46 -0
- package/dist/adapters/standalone.mjs +36 -0
- package/dist/adapters/standalone.ts.js +1 -0
- package/dist/{declarations/src/adapters → adapters}/ws.d.ts +16 -16
- package/dist/adapters/ws.d.ts.map +1 -0
- package/dist/adapters/ws.js +347 -0
- package/dist/adapters/ws.mjs +343 -0
- package/dist/adapters/ws.ts.js +1 -0
- package/dist/{declarations/src/assertNotBrowser.d.ts → assertNotBrowser.d.ts} +1 -1
- package/dist/assertNotBrowser.d.ts.map +1 -0
- package/dist/{codes-fe07bf82.esm.js → codes-7a3d4f65.mjs} +0 -0
- package/dist/{codes-33cef953.cjs.dev.js → codes-7f46544e.js} +0 -0
- package/dist/{declarations/src/http → http}/ResponseMeta.d.ts +4 -4
- package/dist/http/ResponseMeta.d.ts.map +1 -0
- package/dist/{declarations/src/http → http}/index.d.ts +2 -2
- package/dist/http/index.d.ts.map +1 -0
- package/dist/{declarations/src/http → http}/internals/getHTTPStatusCode.d.ts +20 -20
- package/dist/http/internals/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/{declarations/src/http → http}/internals/types.d.ts +39 -39
- package/dist/http/internals/types.d.ts.map +1 -0
- package/dist/{declarations/src/http → http}/resolveHTTPResponse.d.ts +12 -12
- package/dist/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/{declarations/src/index.d.ts → index.d.ts} +7 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/{trpc-server.cjs.dev.js → index.js} +45 -62
- package/dist/{trpc-server.esm.js → index.mjs} +41 -54
- package/dist/index.ts.js +1 -0
- package/dist/{declarations/src/internals → internals}/BaseHandlerOptions.d.ts +12 -12
- package/dist/internals/BaseHandlerOptions.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/OnErrorFunction.d.ts +10 -10
- package/dist/internals/OnErrorFunction.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/callProcedure.d.ts +9 -9
- package/dist/internals/callProcedure.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/errors.d.ts +3 -3
- package/dist/internals/errors.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/invert.d.ts +8 -8
- package/dist/internals/invert.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/middlewares.d.ts +33 -33
- package/dist/internals/middlewares.d.ts.map +1 -0
- package/dist/internals/procedure.d.ts +81 -0
- package/dist/internals/procedure.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/transformTRPCResponse.d.ts +6 -6
- package/dist/internals/transformTRPCResponse.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/wrapCallSafe.d.ts +15 -15
- package/dist/internals/wrapCallSafe.d.ts.map +1 -0
- package/dist/nodeHTTPRequestHandler-5fccb3bb.mjs +106 -0
- package/dist/nodeHTTPRequestHandler-7d71ac09.js +108 -0
- package/dist/{nodeHTTPRequestHandler-2e6cc2d7.esm.js → resolveHTTPResponse-3292a84a.mjs} +3 -105
- package/dist/{nodeHTTPRequestHandler-b7ff366e.cjs.dev.js → resolveHTTPResponse-c3777a47.js} +2 -105
- package/dist/{declarations/src/router.d.ts → router.d.ts} +168 -175
- package/dist/router.d.ts.map +1 -0
- package/dist/{declarations/src/rpc → rpc}/codes.d.ts +46 -46
- package/dist/rpc/codes.d.ts.map +1 -0
- package/dist/{declarations/src/rpc → rpc}/envelopes.d.ts +71 -71
- package/dist/rpc/envelopes.d.ts.map +1 -0
- package/dist/{declarations/src/rpc → rpc}/index.d.ts +2 -2
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +10 -0
- package/dist/rpc/index.mjs +1 -0
- package/dist/rpc/index.ts.js +1 -0
- package/dist/{subscription-fbda2888.esm.js → subscription-0d8a48ec.mjs} +2 -2
- package/dist/{subscription-c2e0bfbc.cjs.prod.js → subscription-41611bc2.js} +2 -2
- package/dist/{declarations/src/subscription.d.ts → subscription.d.ts} +57 -57
- package/dist/subscription.d.ts.map +1 -0
- package/dist/{transformTRPCResponse-8248515e.cjs.dev.js → transformTRPCResponse-43a869de.js} +41 -45
- package/dist/{transformTRPCResponse-f73dc4a2.esm.js → transformTRPCResponse-ff424ff4.mjs} +41 -45
- package/dist/{declarations/src/transformer.d.ts → transformer.d.ts} +29 -29
- package/dist/transformer.d.ts.map +1 -0
- package/dist/{declarations/src/types.d.ts → types.d.ts} +32 -40
- package/dist/types.d.ts.map +1 -0
- package/package.json +55 -20
- package/rpc/index.d.ts +1 -0
- package/rpc/index.js +1 -0
- package/src/TRPCError.ts +3 -11
- package/src/adapters/express.ts +3 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +78 -0
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +56 -0
- package/src/adapters/fastify/index.ts +2 -0
- 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 -5
- package/src/adapters/standalone.ts +2 -1
- package/src/adapters/ws.ts +8 -5
- package/src/http/internals/getHTTPStatusCode.ts +1 -1
- package/src/http/internals/types.ts +2 -2
- package/src/http/resolveHTTPResponse.ts +3 -3
- package/src/index.ts +1 -5
- package/src/internals/BaseHandlerOptions.ts +1 -1
- package/src/internals/OnErrorFunction.ts +1 -1
- package/src/internals/middlewares.ts +1 -1
- package/src/internals/procedure.ts +123 -63
- package/src/router.ts +93 -63
- package/src/subscription.ts +1 -1
- package/src/types.ts +0 -9
- package/ws/dist/trpc-server-ws.cjs.dev.js +1 -1
- package/ws/dist/trpc-server-ws.cjs.prod.js +1 -1
- package/ws/dist/trpc-server-ws.esm.js +1 -1
- package/ws/index.d.ts +1 -0
- package/ws/index.js +1 -0
- package/adapters/express/package.json +0 -4
- package/adapters/next/package.json +0 -4
- package/adapters/node-http/package.json +0 -4
- package/adapters/standalone/package.json +0 -4
- package/adapters/ws/package.json +0 -4
- package/dist/codes-e0df67c4.cjs.prod.js +0 -60
- package/dist/declarations/src/TRPCError.d.ts.map +0 -1
- package/dist/declarations/src/adapters/express.d.ts.map +0 -1
- package/dist/declarations/src/adapters/next.d.ts.map +0 -1
- package/dist/declarations/src/adapters/node-http/index.d.ts.map +0 -1
- package/dist/declarations/src/adapters/node-http/internals/getPostBody.d.ts.map +0 -1
- package/dist/declarations/src/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/declarations/src/adapters/node-http/types.d.ts.map +0 -1
- package/dist/declarations/src/adapters/standalone.d.ts.map +0 -1
- package/dist/declarations/src/adapters/ws.d.ts.map +0 -1
- package/dist/declarations/src/assertNotBrowser.d.ts.map +0 -1
- package/dist/declarations/src/deprecated/LegacyRouter.d.ts +0 -3
- package/dist/declarations/src/deprecated/LegacyRouter.d.ts.map +0 -1
- package/dist/declarations/src/deprecated/createHttpServer.d.ts +0 -19
- package/dist/declarations/src/deprecated/createHttpServer.d.ts.map +0 -1
- package/dist/declarations/src/deprecated/requestHandler.d.ts +0 -15
- package/dist/declarations/src/deprecated/requestHandler.d.ts.map +0 -1
- package/dist/declarations/src/http/ResponseMeta.d.ts.map +0 -1
- package/dist/declarations/src/http/index.d.ts.map +0 -1
- package/dist/declarations/src/http/internals/getHTTPStatusCode.d.ts.map +0 -1
- package/dist/declarations/src/http/internals/types.d.ts.map +0 -1
- package/dist/declarations/src/http/resolveHTTPResponse.d.ts.map +0 -1
- package/dist/declarations/src/index.d.ts.map +0 -1
- package/dist/declarations/src/internals/BaseHandlerOptions.d.ts.map +0 -1
- package/dist/declarations/src/internals/OnErrorFunction.d.ts.map +0 -1
- package/dist/declarations/src/internals/callProcedure.d.ts.map +0 -1
- package/dist/declarations/src/internals/errors.d.ts.map +0 -1
- package/dist/declarations/src/internals/invert.d.ts.map +0 -1
- package/dist/declarations/src/internals/middlewares.d.ts.map +0 -1
- package/dist/declarations/src/internals/procedure.d.ts +0 -74
- package/dist/declarations/src/internals/procedure.d.ts.map +0 -1
- package/dist/declarations/src/internals/transformTRPCResponse.d.ts.map +0 -1
- package/dist/declarations/src/internals/wrapCallSafe.d.ts.map +0 -1
- package/dist/declarations/src/router.d.ts.map +0 -1
- package/dist/declarations/src/rpc/codes.d.ts.map +0 -1
- package/dist/declarations/src/rpc/envelopes.d.ts.map +0 -1
- package/dist/declarations/src/rpc/index.d.ts.map +0 -1
- package/dist/declarations/src/subscription.d.ts.map +0 -1
- package/dist/declarations/src/transformer.d.ts.map +0 -1
- package/dist/declarations/src/types.d.ts.map +0 -1
- package/dist/declarations/src/ws/index.d.ts +0 -7
- package/dist/declarations/src/ws/index.d.ts.map +0 -1
- package/dist/nodeHTTPRequestHandler-7325b53f.cjs.prod.js +0 -399
- package/dist/subscription-b8831081.cjs.dev.js +0 -136
- package/dist/transformTRPCResponse-dcbf66c5.cjs.prod.js +0 -114
- package/dist/trpc-server.cjs.d.ts +0 -1
- package/dist/trpc-server.cjs.js +0 -7
- package/dist/trpc-server.cjs.prod.js +0 -528
- package/rpc/package.json +0 -4
- package/src/deprecated/LegacyRouter.ts +0 -3
- package/src/deprecated/createHttpServer.ts +0 -29
- package/src/deprecated/requestHandler.ts +0 -26
- package/src/ws/index.ts +0 -8
- package/ws/package.json +0 -4
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { TRPCError } from '../TRPCError';
|
|
2
3
|
import { assertNotBrowser } from '../assertNotBrowser';
|
|
3
4
|
import { ProcedureType } from '../router';
|
|
4
|
-
import { TRPCError } from '../TRPCError';
|
|
5
5
|
import { getErrorFromUnknown } from './errors';
|
|
6
6
|
import { MiddlewareFunction, middlewareMarker } from './middlewares';
|
|
7
7
|
import { wrapCallSafe } from './wrapCallSafe';
|
|
8
|
+
|
|
8
9
|
assertNotBrowser();
|
|
9
10
|
|
|
10
|
-
export type
|
|
11
|
+
export type ProcedureParserZodEsque<TInput, TOutput> = {
|
|
11
12
|
_input: TInput;
|
|
12
|
-
_output:
|
|
13
|
+
_output: TOutput;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
export type
|
|
16
|
-
parse: (input: any) =>
|
|
16
|
+
export type ProcedureParserMyZodEsque<T> = {
|
|
17
|
+
parse: (input: any) => T;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export type
|
|
20
|
-
create: (input: unknown) =>
|
|
20
|
+
export type ProcedureParserSuperstructEsque<T> = {
|
|
21
|
+
create: (input: unknown) => T;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export type
|
|
24
|
+
export type ProcedureParserCustomValidatorEsque<T> = (
|
|
24
25
|
input: unknown,
|
|
25
|
-
) =>
|
|
26
|
+
) => T | Promise<T>;
|
|
26
27
|
|
|
27
|
-
export type
|
|
28
|
-
validateSync: (input: unknown) =>
|
|
28
|
+
export type ProcedureParserYupEsque<T> = {
|
|
29
|
+
validateSync: (input: unknown) => T;
|
|
29
30
|
};
|
|
30
|
-
export type ProcedureInputParser<TInput> =
|
|
31
|
-
| ProcedureInputParserYupEsque<TInput>
|
|
32
|
-
| ProcedureInputParserSuperstructEsque<TInput>
|
|
33
|
-
| ProcedureInputParserCustomValidatorEsque<TInput>
|
|
34
|
-
| ProcedureInputParserMyZodEsque<TInput>;
|
|
35
31
|
|
|
36
|
-
export type
|
|
37
|
-
|
|
32
|
+
export type ProcedureParserWithInputOutput<TInput, TOutput> =
|
|
33
|
+
ProcedureParserZodEsque<TInput, TOutput>;
|
|
34
|
+
|
|
35
|
+
export type ProcedureParser<T> =
|
|
36
|
+
| ProcedureParserYupEsque<T>
|
|
37
|
+
| ProcedureParserSuperstructEsque<T>
|
|
38
|
+
| ProcedureParserCustomValidatorEsque<T>
|
|
39
|
+
| ProcedureParserMyZodEsque<T>;
|
|
38
40
|
|
|
39
|
-
export type ProcedureResolver<TContext,
|
|
41
|
+
export type ProcedureResolver<TContext, TInput, TOutput> = (opts: {
|
|
40
42
|
ctx: TContext;
|
|
41
|
-
input:
|
|
43
|
+
input: TInput;
|
|
42
44
|
type: ProcedureType;
|
|
43
45
|
}) => Promise<TOutput> | TOutput;
|
|
44
46
|
|
|
45
|
-
interface ProcedureOptions<TContext,
|
|
47
|
+
interface ProcedureOptions<TContext, TInput, TOutput, TParsedOutput> {
|
|
46
48
|
middlewares: Array<MiddlewareFunction<any, any>>;
|
|
47
|
-
resolver: ProcedureResolver<TContext,
|
|
48
|
-
inputParser:
|
|
49
|
+
resolver: ProcedureResolver<TContext, TInput, TOutput>;
|
|
50
|
+
inputParser: ProcedureParser<TInput>;
|
|
51
|
+
outputParser: ProcedureParser<TParsedOutput>;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -58,36 +61,33 @@ export interface ProcedureCallOptions<TContext> {
|
|
|
58
61
|
type: ProcedureType;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
type ParseFn<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
inputParser: ProcedureInputParser<TParsedInput>,
|
|
66
|
-
): ParseFn<TParsedInput> {
|
|
67
|
-
const parser = inputParser as any;
|
|
64
|
+
type ParseFn<T> = (value: unknown) => T | Promise<T>;
|
|
65
|
+
|
|
66
|
+
function getParseFn<T>(procedureParser: ProcedureParser<T>): ParseFn<T> {
|
|
67
|
+
const parser = procedureParser as any;
|
|
68
68
|
|
|
69
69
|
if (typeof parser === 'function') {
|
|
70
|
-
//
|
|
70
|
+
// ProcedureParserCustomValidatorEsque
|
|
71
71
|
return parser;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (typeof parser.parseAsync === 'function') {
|
|
75
|
-
//
|
|
75
|
+
// ProcedureParserZodEsque
|
|
76
76
|
return parser.parseAsync.bind(parser);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (typeof parser.parse === 'function') {
|
|
80
|
-
//
|
|
80
|
+
// ProcedureParserZodEsque
|
|
81
81
|
return parser.parse.bind(parser);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (typeof parser.validateSync === 'function') {
|
|
85
|
-
//
|
|
85
|
+
// ProcedureParserYupEsque
|
|
86
86
|
return parser.validateSync.bind(parser);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
if (typeof parser.create === 'function') {
|
|
90
|
-
//
|
|
90
|
+
// ProcedureParserSuperstructEsque
|
|
91
91
|
return parser.create.bind(parser);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -97,22 +97,36 @@ function getParseFn<TParsedInput>(
|
|
|
97
97
|
/**
|
|
98
98
|
* @internal
|
|
99
99
|
*/
|
|
100
|
-
export class Procedure<
|
|
100
|
+
export class Procedure<
|
|
101
|
+
TInputContext,
|
|
102
|
+
TContext,
|
|
103
|
+
TInput,
|
|
104
|
+
TParsedInput,
|
|
105
|
+
TOutput,
|
|
106
|
+
TParsedOutput,
|
|
107
|
+
TFinalOutput = unknown extends TParsedOutput ? TOutput : TParsedOutput,
|
|
108
|
+
> {
|
|
101
109
|
private middlewares: Readonly<Array<MiddlewareFunction<any, any>>>;
|
|
102
110
|
private resolver: ProcedureResolver<TContext, TParsedInput, TOutput>;
|
|
103
|
-
private readonly inputParser:
|
|
104
|
-
private
|
|
111
|
+
private readonly inputParser: ProcedureParser<TParsedInput>;
|
|
112
|
+
private parseInputFn: ParseFn<TParsedInput>;
|
|
113
|
+
private readonly outputParser: ProcedureParser<TFinalOutput>;
|
|
114
|
+
private parseOutputFn: ParseFn<TFinalOutput>;
|
|
105
115
|
|
|
106
|
-
constructor(
|
|
116
|
+
constructor(
|
|
117
|
+
opts: ProcedureOptions<TContext, TParsedInput, TOutput, TFinalOutput>,
|
|
118
|
+
) {
|
|
107
119
|
this.middlewares = opts.middlewares;
|
|
108
120
|
this.resolver = opts.resolver;
|
|
109
121
|
this.inputParser = opts.inputParser;
|
|
110
|
-
this.
|
|
122
|
+
this.parseInputFn = getParseFn(this.inputParser);
|
|
123
|
+
this.outputParser = opts.outputParser;
|
|
124
|
+
this.parseOutputFn = getParseFn(this.outputParser);
|
|
111
125
|
}
|
|
112
126
|
|
|
113
127
|
private async parseInput(rawInput: unknown): Promise<TParsedInput> {
|
|
114
128
|
try {
|
|
115
|
-
return await this.
|
|
129
|
+
return await this.parseInputFn(rawInput);
|
|
116
130
|
} catch (cause) {
|
|
117
131
|
throw new TRPCError({
|
|
118
132
|
code: 'BAD_REQUEST',
|
|
@@ -121,18 +135,31 @@ export class Procedure<TInputContext, TContext, TInput, TParsedInput, TOutput> {
|
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
137
|
|
|
138
|
+
private async parseOutput(rawOutput: TOutput): Promise<TFinalOutput> {
|
|
139
|
+
try {
|
|
140
|
+
return await this.parseOutputFn(rawOutput);
|
|
141
|
+
} catch (cause) {
|
|
142
|
+
throw new TRPCError({
|
|
143
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
144
|
+
cause,
|
|
145
|
+
message: 'Output validation failed',
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
124
150
|
/**
|
|
125
|
-
* Trigger middlewares in order, parse raw input &
|
|
151
|
+
* Trigger middlewares in order, parse raw input, call resolver & parse raw output
|
|
126
152
|
* @internal
|
|
127
153
|
*/
|
|
128
154
|
public async call(
|
|
129
155
|
opts: ProcedureCallOptions<TInputContext>,
|
|
130
|
-
): Promise<
|
|
156
|
+
): Promise<TFinalOutput> {
|
|
131
157
|
// wrap the actual resolver and treat as the last "middleware"
|
|
132
158
|
const middlewaresWithResolver = this.middlewares.concat([
|
|
133
159
|
async ({ ctx }: { ctx: TContext }) => {
|
|
134
160
|
const input = await this.parseInput(opts.rawInput);
|
|
135
|
-
const
|
|
161
|
+
const rawOutput = await this.resolver({ ...opts, ctx, input });
|
|
162
|
+
const data = await this.parseOutput(rawOutput);
|
|
136
163
|
return {
|
|
137
164
|
marker: middlewareMarker,
|
|
138
165
|
ok: true,
|
|
@@ -178,7 +205,7 @@ export class Procedure<TInputContext, TContext, TInput, TParsedInput, TOutput> {
|
|
|
178
205
|
throw result.error;
|
|
179
206
|
}
|
|
180
207
|
|
|
181
|
-
return result.data as
|
|
208
|
+
return result.data as TFinalOutput;
|
|
182
209
|
}
|
|
183
210
|
|
|
184
211
|
/**
|
|
@@ -189,12 +216,15 @@ export class Procedure<TInputContext, TContext, TInput, TParsedInput, TOutput> {
|
|
|
189
216
|
middlewares: MiddlewareFunction<TInputContext, TContext>[],
|
|
190
217
|
): this {
|
|
191
218
|
const Constructor: {
|
|
192
|
-
new (
|
|
219
|
+
new (
|
|
220
|
+
opts: ProcedureOptions<TContext, TParsedInput, TOutput, TFinalOutput>,
|
|
221
|
+
): Procedure<
|
|
193
222
|
TInputContext,
|
|
194
223
|
TContext,
|
|
195
224
|
TInput,
|
|
196
225
|
TParsedInput,
|
|
197
|
-
TOutput
|
|
226
|
+
TOutput,
|
|
227
|
+
TParsedOutput
|
|
198
228
|
>;
|
|
199
229
|
} = (this as any).constructor;
|
|
200
230
|
|
|
@@ -202,27 +232,35 @@ export class Procedure<TInputContext, TContext, TInput, TParsedInput, TOutput> {
|
|
|
202
232
|
middlewares: [...middlewares, ...this.middlewares],
|
|
203
233
|
resolver: this.resolver,
|
|
204
234
|
inputParser: this.inputParser,
|
|
235
|
+
outputParser: this.outputParser,
|
|
205
236
|
});
|
|
206
237
|
|
|
207
238
|
return instance as any;
|
|
208
239
|
}
|
|
209
240
|
}
|
|
210
241
|
|
|
211
|
-
export type CreateProcedureWithInput<TContext, TInput,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
242
|
+
export type CreateProcedureWithInput<TContext, TInput, TOutput> = {
|
|
243
|
+
input: ProcedureParser<TInput>;
|
|
244
|
+
output?: ProcedureParser<TOutput>;
|
|
245
|
+
resolve: ProcedureResolver<TContext, TInput, TOutput>;
|
|
246
|
+
};
|
|
247
|
+
|
|
216
248
|
export type CreateProcedureWithInputOutputParser<
|
|
217
249
|
TContext,
|
|
218
250
|
TInput,
|
|
219
251
|
TParsedInput,
|
|
220
252
|
TOutput,
|
|
253
|
+
TParsedOutput,
|
|
221
254
|
> = {
|
|
222
|
-
input:
|
|
255
|
+
input: ProcedureParserWithInputOutput<TInput, TParsedInput>;
|
|
256
|
+
output?: ProcedureParserWithInputOutput<TOutput, TParsedOutput>;
|
|
223
257
|
resolve: ProcedureResolver<TContext, TParsedInput, TOutput>;
|
|
224
258
|
};
|
|
225
|
-
|
|
259
|
+
|
|
260
|
+
export type CreateProcedureWithoutInput<TContext, TOutput, TParsedOutput> = {
|
|
261
|
+
output?:
|
|
262
|
+
| ProcedureParserWithInputOutput<TOutput, TParsedOutput>
|
|
263
|
+
| ProcedureParser<TOutput>;
|
|
226
264
|
resolve: ProcedureResolver<TContext, undefined, TOutput>;
|
|
227
265
|
};
|
|
228
266
|
|
|
@@ -231,19 +269,33 @@ export type CreateProcedureOptions<
|
|
|
231
269
|
TInput = undefined,
|
|
232
270
|
TParsedInput = undefined,
|
|
233
271
|
TOutput = undefined,
|
|
272
|
+
TParsedOutput = undefined,
|
|
234
273
|
> =
|
|
235
|
-
| CreateProcedureWithInput<TContext, TInput, TParsedInput, TOutput>
|
|
236
274
|
| CreateProcedureWithInputOutputParser<
|
|
237
275
|
TContext,
|
|
238
276
|
TInput,
|
|
239
277
|
TParsedInput,
|
|
240
|
-
TOutput
|
|
278
|
+
TOutput,
|
|
279
|
+
TParsedOutput
|
|
241
280
|
>
|
|
242
|
-
|
|
|
281
|
+
| CreateProcedureWithInput<TContext, TInput, TOutput>
|
|
282
|
+
| CreateProcedureWithoutInput<TContext, TOutput, TParsedOutput>;
|
|
243
283
|
|
|
244
|
-
export function createProcedure<
|
|
245
|
-
|
|
246
|
-
|
|
284
|
+
export function createProcedure<
|
|
285
|
+
TContext,
|
|
286
|
+
TInput,
|
|
287
|
+
TParsedInput,
|
|
288
|
+
TOutput,
|
|
289
|
+
TParsedOutput,
|
|
290
|
+
>(
|
|
291
|
+
opts: CreateProcedureOptions<
|
|
292
|
+
TContext,
|
|
293
|
+
TInput,
|
|
294
|
+
TParsedInput,
|
|
295
|
+
TOutput,
|
|
296
|
+
TParsedOutput
|
|
297
|
+
>,
|
|
298
|
+
): Procedure<unknown, TContext, TInput, TParsedInput, TOutput, TParsedOutput> {
|
|
247
299
|
const inputParser =
|
|
248
300
|
'input' in opts
|
|
249
301
|
? opts.input
|
|
@@ -257,27 +309,35 @@ export function createProcedure<TContext, TInput, TParsedInput, TOutput>(
|
|
|
257
309
|
return undefined;
|
|
258
310
|
};
|
|
259
311
|
|
|
312
|
+
const outputParser =
|
|
313
|
+
'output' in opts && opts.output
|
|
314
|
+
? opts.output
|
|
315
|
+
: (output: unknown) => output as TOutput;
|
|
316
|
+
|
|
260
317
|
return new Procedure({
|
|
261
318
|
inputParser: inputParser as any,
|
|
262
319
|
resolver: opts.resolve as any,
|
|
263
320
|
middlewares: [],
|
|
321
|
+
outputParser: outputParser as any,
|
|
264
322
|
});
|
|
265
323
|
}
|
|
266
324
|
|
|
267
325
|
export type inferProcedureFromOptions<
|
|
268
326
|
TInputContext,
|
|
269
|
-
TOptions extends CreateProcedureOptions<any, any, any, any>,
|
|
327
|
+
TOptions extends CreateProcedureOptions<any, any, any, any, any>,
|
|
270
328
|
> = TOptions extends CreateProcedureOptions<
|
|
271
329
|
infer TContext,
|
|
272
330
|
infer TInput,
|
|
273
331
|
infer TParsedInput,
|
|
274
|
-
infer TOutput
|
|
332
|
+
infer TOutput,
|
|
333
|
+
infer TParsedOutput
|
|
275
334
|
>
|
|
276
335
|
? Procedure<
|
|
277
336
|
TInputContext,
|
|
278
337
|
TContext,
|
|
279
338
|
unknown extends TInput ? undefined : TInput,
|
|
280
339
|
unknown extends TParsedInput ? undefined : TParsedInput,
|
|
281
|
-
TOutput
|
|
340
|
+
TOutput,
|
|
341
|
+
TParsedOutput
|
|
282
342
|
>
|
|
283
343
|
: never;
|
package/src/router.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
|
|
2
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import { TRPCError } from './TRPCError';
|
|
3
5
|
import { assertNotBrowser } from './assertNotBrowser';
|
|
4
6
|
import { getHTTPStatusCodeFromError } from './http/internals/getHTTPStatusCode';
|
|
5
7
|
import { MiddlewareFunction } from './internals/middlewares';
|
|
6
8
|
import {
|
|
7
|
-
createProcedure,
|
|
8
9
|
CreateProcedureOptions,
|
|
9
10
|
CreateProcedureWithInput,
|
|
10
11
|
CreateProcedureWithInputOutputParser,
|
|
11
12
|
CreateProcedureWithoutInput,
|
|
12
|
-
inferProcedureFromOptions,
|
|
13
13
|
Procedure,
|
|
14
14
|
ProcedureCallOptions,
|
|
15
|
+
createProcedure,
|
|
16
|
+
inferProcedureFromOptions,
|
|
15
17
|
} from './internals/procedure';
|
|
16
18
|
import {
|
|
17
19
|
TRPCErrorShape,
|
|
@@ -21,8 +23,7 @@ import {
|
|
|
21
23
|
} from './rpc';
|
|
22
24
|
import { Subscription } from './subscription';
|
|
23
25
|
import { CombinedDataTransformer, DataTransformerOptions } from './transformer';
|
|
24
|
-
import {
|
|
25
|
-
import { flatten, Prefixer, ThenArg } from './types';
|
|
26
|
+
import { Prefixer, ThenArg, flatten } from './types';
|
|
26
27
|
|
|
27
28
|
assertNotBrowser();
|
|
28
29
|
|
|
@@ -40,17 +41,25 @@ export type ProcedureRecord<
|
|
|
40
41
|
TInput = any,
|
|
41
42
|
TParsedInput = any,
|
|
42
43
|
TOutput = any,
|
|
44
|
+
TParsedOutput = any,
|
|
43
45
|
> = Record<
|
|
44
46
|
string,
|
|
45
|
-
Procedure<
|
|
47
|
+
Procedure<
|
|
48
|
+
TInputContext,
|
|
49
|
+
TContext,
|
|
50
|
+
TInput,
|
|
51
|
+
TParsedInput,
|
|
52
|
+
TOutput,
|
|
53
|
+
TParsedOutput
|
|
54
|
+
>
|
|
46
55
|
>;
|
|
47
56
|
|
|
48
57
|
/**
|
|
49
58
|
* @public
|
|
50
59
|
*/
|
|
51
60
|
export type inferProcedureInput<
|
|
52
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
53
|
-
> = TProcedure extends Procedure<any, any, infer Input, any, any>
|
|
61
|
+
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
62
|
+
> = TProcedure extends Procedure<any, any, infer Input, any, any, any>
|
|
54
63
|
? undefined extends Input
|
|
55
64
|
? Input | null | void // void is necessary to allow procedures with nullish input to be called without an input
|
|
56
65
|
: Input
|
|
@@ -66,7 +75,7 @@ export type inferAsyncReturnType<TFunction extends (...args: any) => any> =
|
|
|
66
75
|
* @public
|
|
67
76
|
*/
|
|
68
77
|
export type inferProcedureOutput<
|
|
69
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
78
|
+
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
70
79
|
> = inferAsyncReturnType<TProcedure['call']>;
|
|
71
80
|
|
|
72
81
|
/**
|
|
@@ -94,8 +103,8 @@ function getDataTransformer(
|
|
|
94
103
|
* @internal
|
|
95
104
|
*/
|
|
96
105
|
export type inferHandlerInput<
|
|
97
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
98
|
-
> = TProcedure extends Procedure<any, any, infer TInput, any, any>
|
|
106
|
+
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
107
|
+
> = TProcedure extends Procedure<any, any, infer TInput, any, any, any>
|
|
99
108
|
? undefined extends TInput // ? is input optional
|
|
100
109
|
? unknown extends TInput // ? is input unset
|
|
101
110
|
? [(null | undefined)?] // -> there is no input
|
|
@@ -205,7 +214,7 @@ const defaultTransformer: CombinedDataTransformer = {
|
|
|
205
214
|
};
|
|
206
215
|
|
|
207
216
|
type SwapProcedureContext<
|
|
208
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
217
|
+
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
209
218
|
TNewContext,
|
|
210
219
|
> = TProcedure extends Procedure<
|
|
211
220
|
infer TInputContext,
|
|
@@ -213,13 +222,21 @@ type SwapProcedureContext<
|
|
|
213
222
|
infer _TOldContext,
|
|
214
223
|
infer TInput,
|
|
215
224
|
infer TParsedInput,
|
|
216
|
-
infer TOutput
|
|
225
|
+
infer TOutput,
|
|
226
|
+
infer TParsedOutput
|
|
217
227
|
>
|
|
218
|
-
? Procedure<
|
|
228
|
+
? Procedure<
|
|
229
|
+
TInputContext,
|
|
230
|
+
TNewContext,
|
|
231
|
+
TInput,
|
|
232
|
+
TParsedInput,
|
|
233
|
+
TOutput,
|
|
234
|
+
TParsedOutput
|
|
235
|
+
>
|
|
219
236
|
: never;
|
|
220
237
|
|
|
221
238
|
type SwapContext<
|
|
222
|
-
TObj extends ProcedureRecord<any, any, any, any>,
|
|
239
|
+
TObj extends ProcedureRecord<any, any, any, any, any, any>,
|
|
223
240
|
TNewContext,
|
|
224
241
|
> = {
|
|
225
242
|
[P in keyof TObj]: SwapProcedureContext<TObj[P], TNewContext>;
|
|
@@ -231,13 +248,22 @@ type SwapContext<
|
|
|
231
248
|
export class Router<
|
|
232
249
|
TInputContext,
|
|
233
250
|
TContext,
|
|
234
|
-
TQueries extends ProcedureRecord<TInputContext, TContext>,
|
|
235
|
-
TMutations extends ProcedureRecord<
|
|
251
|
+
TQueries extends ProcedureRecord<TInputContext, TContext, any, any, any, any>,
|
|
252
|
+
TMutations extends ProcedureRecord<
|
|
253
|
+
TInputContext,
|
|
254
|
+
TContext,
|
|
255
|
+
any,
|
|
256
|
+
any,
|
|
257
|
+
any,
|
|
258
|
+
any
|
|
259
|
+
>,
|
|
236
260
|
TSubscriptions extends ProcedureRecord<
|
|
237
261
|
TInputContext,
|
|
238
262
|
TContext,
|
|
239
263
|
unknown,
|
|
240
|
-
|
|
264
|
+
unknown,
|
|
265
|
+
Subscription<unknown>,
|
|
266
|
+
unknown
|
|
241
267
|
>,
|
|
242
268
|
TErrorShape extends TRPCErrorShape<number>,
|
|
243
269
|
> {
|
|
@@ -279,13 +305,20 @@ export class Router<
|
|
|
279
305
|
return eps as any;
|
|
280
306
|
}
|
|
281
307
|
|
|
282
|
-
public query<
|
|
308
|
+
public query<
|
|
309
|
+
TPath extends string,
|
|
310
|
+
TInput,
|
|
311
|
+
TParsedInput,
|
|
312
|
+
TOutput,
|
|
313
|
+
TParsedOutput,
|
|
314
|
+
>(
|
|
283
315
|
path: TPath,
|
|
284
316
|
procedure: CreateProcedureWithInputOutputParser<
|
|
285
317
|
TContext,
|
|
286
318
|
TInput,
|
|
287
319
|
TParsedInput,
|
|
288
|
-
TOutput
|
|
320
|
+
TOutput,
|
|
321
|
+
TParsedOutput
|
|
289
322
|
>,
|
|
290
323
|
): Router<
|
|
291
324
|
TInputContext,
|
|
@@ -296,9 +329,10 @@ export class Router<
|
|
|
296
329
|
TSubscriptions,
|
|
297
330
|
TErrorShape
|
|
298
331
|
>;
|
|
332
|
+
|
|
299
333
|
public query<TPath extends string, TInput, TOutput>(
|
|
300
334
|
path: TPath,
|
|
301
|
-
procedure: CreateProcedureWithInput<TContext, TInput,
|
|
335
|
+
procedure: CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
302
336
|
): Router<
|
|
303
337
|
TInputContext,
|
|
304
338
|
TContext,
|
|
@@ -309,9 +343,9 @@ export class Router<
|
|
|
309
343
|
TErrorShape
|
|
310
344
|
>;
|
|
311
345
|
|
|
312
|
-
public query<TPath extends string, TOutput>(
|
|
346
|
+
public query<TPath extends string, TOutput, TParsedOutput>(
|
|
313
347
|
path: TPath,
|
|
314
|
-
procedure: CreateProcedureWithoutInput<TContext, TOutput>,
|
|
348
|
+
procedure: CreateProcedureWithoutInput<TContext, TOutput, TParsedOutput>,
|
|
315
349
|
): Router<
|
|
316
350
|
TInputContext,
|
|
317
351
|
TContext,
|
|
@@ -324,7 +358,7 @@ export class Router<
|
|
|
324
358
|
|
|
325
359
|
query(
|
|
326
360
|
path: string,
|
|
327
|
-
procedure: CreateProcedureOptions<TContext, any, any, any>,
|
|
361
|
+
procedure: CreateProcedureOptions<TContext, any, any, any, any>,
|
|
328
362
|
) {
|
|
329
363
|
const router = new Router<TContext, TContext, any, {}, {}, any>({
|
|
330
364
|
queries: safeObject({
|
|
@@ -335,13 +369,20 @@ export class Router<
|
|
|
335
369
|
return this.merge(router);
|
|
336
370
|
}
|
|
337
371
|
|
|
338
|
-
public mutation<
|
|
372
|
+
public mutation<
|
|
373
|
+
TPath extends string,
|
|
374
|
+
TInput,
|
|
375
|
+
TParsedInput,
|
|
376
|
+
TOutput,
|
|
377
|
+
TParsedOutput,
|
|
378
|
+
>(
|
|
339
379
|
path: TPath,
|
|
340
380
|
procedure: CreateProcedureWithInputOutputParser<
|
|
341
381
|
TContext,
|
|
342
382
|
TInput,
|
|
343
383
|
TParsedInput,
|
|
344
|
-
TOutput
|
|
384
|
+
TOutput,
|
|
385
|
+
TParsedOutput
|
|
345
386
|
>,
|
|
346
387
|
): Router<
|
|
347
388
|
TInputContext,
|
|
@@ -352,9 +393,10 @@ export class Router<
|
|
|
352
393
|
TSubscriptions,
|
|
353
394
|
TErrorShape
|
|
354
395
|
>;
|
|
396
|
+
|
|
355
397
|
public mutation<TPath extends string, TInput, TOutput>(
|
|
356
398
|
path: TPath,
|
|
357
|
-
procedure: CreateProcedureWithInput<TContext, TInput,
|
|
399
|
+
procedure: CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
358
400
|
): Router<
|
|
359
401
|
TInputContext,
|
|
360
402
|
TContext,
|
|
@@ -365,9 +407,9 @@ export class Router<
|
|
|
365
407
|
TErrorShape
|
|
366
408
|
>;
|
|
367
409
|
|
|
368
|
-
public mutation<TPath extends string, TOutput>(
|
|
410
|
+
public mutation<TPath extends string, TOutput, TParsedOutput>(
|
|
369
411
|
path: TPath,
|
|
370
|
-
procedure: CreateProcedureWithoutInput<TContext, TOutput>,
|
|
412
|
+
procedure: CreateProcedureWithoutInput<TContext, TOutput, TParsedOutput>,
|
|
371
413
|
): Router<
|
|
372
414
|
TInputContext,
|
|
373
415
|
TContext,
|
|
@@ -380,7 +422,7 @@ export class Router<
|
|
|
380
422
|
|
|
381
423
|
public mutation(
|
|
382
424
|
path: string,
|
|
383
|
-
procedure: CreateProcedureOptions<TContext, any, any, any>,
|
|
425
|
+
procedure: CreateProcedureOptions<TContext, any, any, any, any>,
|
|
384
426
|
) {
|
|
385
427
|
const router = new Router<TContext, TContext, {}, any, {}, any>({
|
|
386
428
|
mutations: safeObject({
|
|
@@ -401,11 +443,15 @@ export class Router<
|
|
|
401
443
|
TOutput extends Subscription<unknown>,
|
|
402
444
|
>(
|
|
403
445
|
path: TPath,
|
|
404
|
-
procedure:
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
446
|
+
procedure: Omit<
|
|
447
|
+
CreateProcedureWithInputOutputParser<
|
|
448
|
+
TContext,
|
|
449
|
+
TInput,
|
|
450
|
+
TParsedInput,
|
|
451
|
+
TOutput,
|
|
452
|
+
unknown
|
|
453
|
+
>,
|
|
454
|
+
'output'
|
|
409
455
|
>,
|
|
410
456
|
): Router<
|
|
411
457
|
TInputContext,
|
|
@@ -426,7 +472,10 @@ export class Router<
|
|
|
426
472
|
TOutput extends Subscription<unknown>,
|
|
427
473
|
>(
|
|
428
474
|
path: TPath,
|
|
429
|
-
procedure:
|
|
475
|
+
procedure: Omit<
|
|
476
|
+
CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
477
|
+
'output'
|
|
478
|
+
>,
|
|
430
479
|
): Router<
|
|
431
480
|
TInputContext,
|
|
432
481
|
TContext,
|
|
@@ -445,7 +494,10 @@ export class Router<
|
|
|
445
494
|
TOutput extends Subscription<unknown>,
|
|
446
495
|
>(
|
|
447
496
|
path: TPath,
|
|
448
|
-
procedure:
|
|
497
|
+
procedure: Omit<
|
|
498
|
+
CreateProcedureWithoutInput<TContext, TOutput, unknown>,
|
|
499
|
+
'output'
|
|
500
|
+
>,
|
|
449
501
|
): Router<
|
|
450
502
|
TInputContext,
|
|
451
503
|
TContext,
|
|
@@ -458,7 +510,10 @@ export class Router<
|
|
|
458
510
|
|
|
459
511
|
public subscription(
|
|
460
512
|
path: string,
|
|
461
|
-
procedure:
|
|
513
|
+
procedure: Omit<
|
|
514
|
+
CreateProcedureOptions<TContext, any, any, any, any>,
|
|
515
|
+
'output'
|
|
516
|
+
>,
|
|
462
517
|
) {
|
|
463
518
|
const router = new Router<TContext, TContext, {}, {}, any, any>({
|
|
464
519
|
subscriptions: safeObject({
|
|
@@ -577,7 +632,7 @@ export class Router<
|
|
|
577
632
|
const defTarget = PROCEDURE_DEFINITION_MAP[type];
|
|
578
633
|
const defs = this._def[defTarget];
|
|
579
634
|
const procedure = defs[path] as
|
|
580
|
-
| Procedure<TInputContext, TContext, any, any, any>
|
|
635
|
+
| Procedure<TInputContext, TContext, any, any, any, any>
|
|
581
636
|
| undefined;
|
|
582
637
|
|
|
583
638
|
if (!procedure) {
|
|
@@ -740,31 +795,6 @@ export class Router<
|
|
|
740
795
|
}
|
|
741
796
|
}
|
|
742
797
|
|
|
743
|
-
/**
|
|
744
|
-
* Subclass of `VNextRouter` with `TInputContext` and `TContext` set to the same type, for backcompat.
|
|
745
|
-
*
|
|
746
|
-
* @deprecated
|
|
747
|
-
*/
|
|
748
|
-
export class LegacyRouter<
|
|
749
|
-
TContext,
|
|
750
|
-
TQueries extends ProcedureRecord<TContext, TContext>,
|
|
751
|
-
TMutations extends ProcedureRecord<TContext, TContext>,
|
|
752
|
-
TSubscriptions extends ProcedureRecord<
|
|
753
|
-
TContext,
|
|
754
|
-
TContext,
|
|
755
|
-
unknown,
|
|
756
|
-
Subscription<unknown>
|
|
757
|
-
>,
|
|
758
|
-
TErrorShape extends TRPCErrorShape<number>,
|
|
759
|
-
> extends Router<
|
|
760
|
-
TContext,
|
|
761
|
-
TContext,
|
|
762
|
-
TQueries,
|
|
763
|
-
TMutations,
|
|
764
|
-
TSubscriptions,
|
|
765
|
-
TErrorShape
|
|
766
|
-
> {}
|
|
767
|
-
|
|
768
798
|
export function router<TContext>() {
|
|
769
799
|
return new Router<TContext, TContext, {}, {}, {}, DefaultErrorShape>();
|
|
770
800
|
}
|
package/src/subscription.ts
CHANGED
|
@@ -147,7 +147,7 @@ export function subscriptionPullFactory<TOutput>(opts: {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
return new Subscription<TOutput>((emit) => {
|
|
150
|
-
_pull(emit);
|
|
150
|
+
_pull(emit).catch((err) => emit.error(getErrorFromUnknown(err)));
|
|
151
151
|
return () => {
|
|
152
152
|
clearTimeout(timer);
|
|
153
153
|
stopped = true;
|