@trpc/server 11.0.0-alpha-tmp-export-from-main.218 → 11.0.0-alpha-tmp-export-from-main-nuke-core.239
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/@trpc/server/http.d.ts +7 -0
- package/dist/@trpc/server/http.d.ts.map +1 -0
- package/dist/@trpc/server/index.d.ts +69 -0
- package/dist/@trpc/server/index.d.ts.map +1 -0
- package/dist/@trpc/server/rpc.d.ts +3 -0
- package/dist/@trpc/server/rpc.d.ts.map +1 -0
- package/dist/adapters/aws-lambda/index.d.ts +1 -2
- package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/index.js +6 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -2
- package/dist/adapters/aws-lambda/utils.d.ts +2 -3
- package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
- package/dist/adapters/aws-lambda/utils.js +5 -4
- package/dist/adapters/aws-lambda/utils.mjs +3 -2
- package/dist/adapters/express.d.ts +1 -2
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +6 -3
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +4 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -2
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +1 -2
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +6 -4
- package/dist/adapters/fetch/fetchRequestHandler.mjs +4 -2
- package/dist/adapters/fetch/types.d.ts +2 -3
- package/dist/adapters/fetch/types.d.ts.map +1 -1
- package/dist/adapters/next.d.ts +1 -3
- package/dist/adapters/next.d.ts.map +1 -1
- package/dist/adapters/next.js +6 -4
- package/dist/adapters/next.mjs +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +4 -2
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +3 -1
- package/dist/adapters/node-http/content-type/json/index.js +4 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +3 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +2 -2
- package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -2
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +6 -4
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +4 -2
- package/dist/adapters/node-http/types.d.ts +3 -4
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/adapters/standalone.d.ts +1 -2
- package/dist/adapters/standalone.d.ts.map +1 -1
- package/dist/adapters/standalone.js +1 -0
- package/dist/adapters/standalone.mjs +1 -0
- package/dist/adapters/ws.d.ts +3 -2
- package/dist/adapters/ws.d.ts.map +1 -1
- package/dist/adapters/ws.js +33 -26
- package/dist/adapters/ws.mjs +8 -1
- package/dist/bundle-analysis.json +757 -0
- package/dist/http.d.ts +1 -6
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +11 -21
- package/dist/http.mjs +6 -1
- package/dist/index.d.ts +1 -68
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -41
- package/dist/index.mjs +8 -1
- package/dist/observable/index.d.ts +5 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +13 -0
- package/dist/observable/index.mjs +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/observable.js +126 -0
- package/dist/observable/observable.mjs +122 -0
- package/dist/observable/operators.d.ts +8 -0
- package/dist/observable/operators.d.ts.map +1 -0
- package/dist/observable/operators.js +103 -0
- package/dist/observable/operators.mjs +99 -0
- package/dist/observable/types.d.ts +26 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/rpc.d.ts +1 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +6 -13
- package/dist/rpc.mjs +3 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +6 -9
- package/dist/shared.mjs +4 -1
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +6 -0
- package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts +19 -0
- package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/createProxy.js +52 -0
- package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +13 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.js +67 -0
- package/dist/unstable-core-do-not-import/error/TRPCError.mjs +63 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts +33 -0
- package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
- package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.js +31 -0
- package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +24 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +32 -0
- package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +30 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +29 -0
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
- package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +51 -0
- package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +48 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts +7 -0
- package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +51 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +295 -0
- package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +293 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts +96 -0
- package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.d.ts +37 -0
- package/dist/unstable-core-do-not-import/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/index.js +48 -0
- package/dist/unstable-core-do-not-import/index.mjs +16 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts +96 -0
- package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/initTRPC.js +95 -0
- package/dist/unstable-core-do-not-import/initTRPC.mjs +93 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts +105 -0
- package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/middleware.js +95 -0
- package/dist/unstable-core-do-not-import/middleware.mjs +89 -0
- package/dist/unstable-core-do-not-import/parser.d.ts +30 -0
- package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/parser.js +37 -0
- package/dist/unstable-core-do-not-import/parser.mjs +35 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts +72 -0
- package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedure.js +9 -0
- package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +101 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.js +176 -0
- package/dist/unstable-core-do-not-import/procedureBuilder.mjs +173 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts +75 -0
- package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
- package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
- package/dist/unstable-core-do-not-import/router.d.ts +85 -0
- package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/router.js +156 -0
- package/dist/unstable-core-do-not-import/router.mjs +151 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts +51 -0
- package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/codes.js +38 -0
- package/dist/unstable-core-do-not-import/rpc/codes.mjs +35 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +97 -0
- package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +5 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +59 -0
- package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +57 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts +62 -0
- package/dist/unstable-core-do-not-import/serialize.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts +107 -0
- package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/transformer.js +107 -0
- package/dist/unstable-core-do-not-import/transformer.mjs +102 -0
- package/dist/unstable-core-do-not-import/types.d.ts +98 -0
- package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.d.ts +27 -0
- package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
- package/dist/unstable-core-do-not-import/utils.js +44 -0
- package/dist/unstable-core-do-not-import/utils.mjs +39 -0
- package/package.json +53 -125
- package/src/@trpc/server/http.ts +26 -0
- package/src/@trpc/server/index.ts +105 -0
- package/src/@trpc/server/rpc.ts +26 -0
- package/src/adapters/aws-lambda/index.ts +4 -5
- package/src/adapters/aws-lambda/utils.ts +3 -4
- package/src/adapters/express.ts +1 -3
- package/src/adapters/fastify/fastifyRequestHandler.ts +6 -4
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -2
- package/src/adapters/fetch/fetchRequestHandler.ts +6 -4
- package/src/adapters/fetch/types.ts +2 -3
- package/src/adapters/next.ts +2 -4
- package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
- package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
- package/src/adapters/node-http/content-type/json/index.ts +1 -1
- package/src/adapters/node-http/internals/contentType.ts +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +6 -4
- package/src/adapters/node-http/types.ts +4 -5
- package/src/adapters/standalone.ts +2 -2
- package/src/adapters/ws.ts +14 -13
- package/src/http.ts +1 -26
- package/src/index.ts +1 -105
- package/src/observable/index.ts +10 -0
- package/src/observable/observable.ts +158 -0
- package/src/observable/operators.ts +119 -0
- package/src/observable/types.ts +76 -0
- package/src/rpc.ts +1 -26
- package/src/shared.ts +1 -1
- package/src/unstable-core-do-not-import/TRPCInferrable.ts +9 -0
- package/src/unstable-core-do-not-import/createProxy.ts +59 -0
- package/src/unstable-core-do-not-import/error/TRPCError.ts +82 -0
- package/src/unstable-core-do-not-import/error/formatter.ts +51 -0
- package/src/unstable-core-do-not-import/error/getErrorShape.ts +36 -0
- package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +29 -0
- package/src/unstable-core-do-not-import/http/contentType.ts +99 -0
- package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +57 -0
- package/src/unstable-core-do-not-import/http/index.ts +23 -0
- package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +458 -0
- package/src/unstable-core-do-not-import/http/types.ts +111 -0
- package/src/unstable-core-do-not-import/index.ts +110 -0
- package/src/unstable-core-do-not-import/initTRPC.ts +206 -0
- package/src/unstable-core-do-not-import/middleware.ts +233 -0
- package/src/unstable-core-do-not-import/parser.ts +94 -0
- package/src/unstable-core-do-not-import/procedure.ts +108 -0
- package/src/unstable-core-do-not-import/procedureBuilder.ts +458 -0
- package/src/unstable-core-do-not-import/rootConfig.ts +90 -0
- package/src/unstable-core-do-not-import/router.ts +370 -0
- package/src/unstable-core-do-not-import/rpc/codes.ts +44 -0
- package/src/unstable-core-do-not-import/rpc/envelopes.ts +136 -0
- package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
- package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +85 -0
- package/src/unstable-core-do-not-import/serialize.ts +122 -0
- package/src/unstable-core-do-not-import/transformer.ts +202 -0
- package/src/unstable-core-do-not-import/types.ts +151 -0
- package/src/unstable-core-do-not-import/utils.ts +59 -0
- package/unstable-core-do-not-import/index.d.ts +1 -0
- package/unstable-core-do-not-import/index.js +1 -0
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts +0 -10
- package/dist/@trpc-core-unstable-do-not-import-this-please.d.ts.map +0 -1
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/observable.d.ts +0 -3
- package/dist/observable.d.ts.map +0 -1
- package/dist/observable.js +0 -30
- package/dist/observable.mjs +0 -1
- package/src/@trpc-core-unstable-do-not-import-this-please.ts +0 -146
- package/src/@trpc-server/http.ts +0 -2
- package/src/observable.ts +0 -16
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// zod / @decs/typeschema
|
|
2
|
+
export type ParserZodEsque<TInput, TParsedInput> = {
|
|
3
|
+
_input: TInput;
|
|
4
|
+
_output: TParsedInput;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type ParserMyZodEsque<TInput> = {
|
|
8
|
+
parse: (input: any) => TInput;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ParserSuperstructEsque<TInput> = {
|
|
12
|
+
create: (input: unknown) => TInput;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ParserCustomValidatorEsque<TInput> = (
|
|
16
|
+
input: unknown,
|
|
17
|
+
) => Promise<TInput> | TInput;
|
|
18
|
+
|
|
19
|
+
export type ParserYupEsque<TInput> = {
|
|
20
|
+
validateSync: (input: unknown) => TInput;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ParserScaleEsque<TInput> = {
|
|
24
|
+
assert(value: unknown): asserts value is TInput;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ParserWithoutInput<TInput> =
|
|
28
|
+
| ParserCustomValidatorEsque<TInput>
|
|
29
|
+
| ParserMyZodEsque<TInput>
|
|
30
|
+
| ParserScaleEsque<TInput>
|
|
31
|
+
| ParserSuperstructEsque<TInput>
|
|
32
|
+
| ParserYupEsque<TInput>;
|
|
33
|
+
|
|
34
|
+
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<
|
|
35
|
+
TInput,
|
|
36
|
+
TParsedInput
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
40
|
+
|
|
41
|
+
export type inferParser<TParser extends Parser> =
|
|
42
|
+
TParser extends ParserWithInputOutput<infer $TIn, infer $TOut>
|
|
43
|
+
? {
|
|
44
|
+
in: $TIn;
|
|
45
|
+
out: $TOut;
|
|
46
|
+
}
|
|
47
|
+
: TParser extends ParserWithoutInput<infer $InOut>
|
|
48
|
+
? {
|
|
49
|
+
in: $InOut;
|
|
50
|
+
out: $InOut;
|
|
51
|
+
}
|
|
52
|
+
: never;
|
|
53
|
+
|
|
54
|
+
export type ParseFn<TType> = (value: unknown) => Promise<TType> | TType;
|
|
55
|
+
|
|
56
|
+
export function getParseFn<TType>(procedureParser: Parser): ParseFn<TType> {
|
|
57
|
+
const parser = procedureParser as any;
|
|
58
|
+
|
|
59
|
+
if (typeof parser === 'function') {
|
|
60
|
+
// ParserCustomValidatorEsque
|
|
61
|
+
return parser;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (typeof parser.parseAsync === 'function') {
|
|
65
|
+
// ParserZodEsque
|
|
66
|
+
return parser.parseAsync.bind(parser);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof parser.parse === 'function') {
|
|
70
|
+
// ParserZodEsque
|
|
71
|
+
// ParserValibotEsque (<= v0.12.X)
|
|
72
|
+
return parser.parse.bind(parser);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (typeof parser.validateSync === 'function') {
|
|
76
|
+
// ParserYupEsque
|
|
77
|
+
return parser.validateSync.bind(parser);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof parser.create === 'function') {
|
|
81
|
+
// ParserSuperstructEsque
|
|
82
|
+
return parser.create.bind(parser);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (typeof parser.assert === 'function') {
|
|
86
|
+
// ParserScaleEsque
|
|
87
|
+
return (value) => {
|
|
88
|
+
parser.assert(value);
|
|
89
|
+
return value as TType;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
throw new Error('Could not find a validator fn');
|
|
94
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { inferObservableValue } from '../observable';
|
|
2
|
+
import type { ProcedureCallOptions } from './procedureBuilder';
|
|
3
|
+
import type { Serialize } from './serialize';
|
|
4
|
+
import type { DefaultDataTransformer } from './transformer';
|
|
5
|
+
import type { inferConfig, TRPCInferrable } from './TRPCInferrable';
|
|
6
|
+
|
|
7
|
+
export const procedureTypes = ['query', 'mutation', 'subscription'] as const;
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export type ProcedureType = (typeof procedureTypes)[number];
|
|
12
|
+
|
|
13
|
+
type ClientContext = Record<string, unknown>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export interface ProcedureOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Client-side context
|
|
21
|
+
*/
|
|
22
|
+
context?: ClientContext;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export type ProcedureArgs<TParams extends AnyProcedure['_def']> =
|
|
30
|
+
void extends TParams['_input_in']
|
|
31
|
+
? [input?: undefined | void, opts?: ProcedureOptions]
|
|
32
|
+
: undefined extends TParams['_input_in']
|
|
33
|
+
? [input?: TParams['_input_in'] | void, opts?: ProcedureOptions]
|
|
34
|
+
: [input: TParams['_input_in'], opts?: ProcedureOptions];
|
|
35
|
+
|
|
36
|
+
interface BuiltProcedureDef {
|
|
37
|
+
input: unknown;
|
|
38
|
+
output: unknown;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export interface Procedure<
|
|
45
|
+
TType extends ProcedureType,
|
|
46
|
+
TDef extends BuiltProcedureDef,
|
|
47
|
+
> {
|
|
48
|
+
_def: {
|
|
49
|
+
_input_in: TDef['input'];
|
|
50
|
+
_output_out: TDef['output'];
|
|
51
|
+
procedure: true;
|
|
52
|
+
type: TType;
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
* Meta is not inferrable on individual procedures, only on the router
|
|
56
|
+
*/
|
|
57
|
+
meta: unknown;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
(opts: ProcedureCallOptions): Promise<unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface QueryProcedure<TDef extends BuiltProcedureDef>
|
|
66
|
+
extends Procedure<'query', TDef> {}
|
|
67
|
+
|
|
68
|
+
export interface MutationProcedure<TDef extends BuiltProcedureDef>
|
|
69
|
+
extends Procedure<'mutation', TDef> {}
|
|
70
|
+
|
|
71
|
+
export interface SubscriptionProcedure<TDef extends BuiltProcedureDef>
|
|
72
|
+
extends Procedure<'subscription', TDef> {}
|
|
73
|
+
|
|
74
|
+
export type AnyQueryProcedure = QueryProcedure<any>;
|
|
75
|
+
export type AnyMutationProcedure = MutationProcedure<any>;
|
|
76
|
+
export type AnySubscriptionProcedure = SubscriptionProcedure<any>;
|
|
77
|
+
export type AnyProcedure = Procedure<ProcedureType, any>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export type inferTransformedProcedureOutput<
|
|
83
|
+
TInferrable extends TRPCInferrable,
|
|
84
|
+
TProcedure extends AnyProcedure,
|
|
85
|
+
> = inferConfig<TInferrable>['transformer'] extends DefaultDataTransformer
|
|
86
|
+
? Serialize<TProcedure['_def']['_output_out']>
|
|
87
|
+
: TProcedure['_def']['_output_out'];
|
|
88
|
+
|
|
89
|
+
/** @internal */
|
|
90
|
+
export type inferTransformedSubscriptionOutput<
|
|
91
|
+
TInferrable extends TRPCInferrable,
|
|
92
|
+
TProcedure extends AnyProcedure,
|
|
93
|
+
> = inferConfig<TInferrable>['transformer'] extends DefaultDataTransformer
|
|
94
|
+
? Serialize<inferObservableValue<TProcedure['_def']['_output_out']>>
|
|
95
|
+
: inferObservableValue<TProcedure['_def']['_output_out']>;
|
|
96
|
+
|
|
97
|
+
export type inferHandlerInput<TProcedure extends AnyProcedure> = ProcedureArgs<
|
|
98
|
+
inferProcedureParams<TProcedure>
|
|
99
|
+
>;
|
|
100
|
+
|
|
101
|
+
export type inferProcedureInput<TProcedure extends AnyProcedure> =
|
|
102
|
+
inferProcedureParams<TProcedure>['_input_in'];
|
|
103
|
+
|
|
104
|
+
export type inferProcedureParams<TProcedure> = TProcedure extends AnyProcedure
|
|
105
|
+
? TProcedure['_def']
|
|
106
|
+
: never;
|
|
107
|
+
export type inferProcedureOutput<TProcedure> =
|
|
108
|
+
inferProcedureParams<TProcedure>['_output_out'];
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { getTRPCErrorFromUnknown, TRPCError } from './error/TRPCError';
|
|
2
|
+
import type {
|
|
3
|
+
AnyMiddlewareFunction,
|
|
4
|
+
MiddlewareBuilder,
|
|
5
|
+
MiddlewareFunction,
|
|
6
|
+
MiddlewareResult,
|
|
7
|
+
} from './middleware';
|
|
8
|
+
import {
|
|
9
|
+
createInputMiddleware,
|
|
10
|
+
createOutputMiddleware,
|
|
11
|
+
middlewareMarker,
|
|
12
|
+
} from './middleware';
|
|
13
|
+
import { getParseFn } from './parser';
|
|
14
|
+
import type { inferParser, Parser } from './parser';
|
|
15
|
+
import type {
|
|
16
|
+
AnyMutationProcedure,
|
|
17
|
+
AnyProcedure,
|
|
18
|
+
AnyQueryProcedure,
|
|
19
|
+
AnySubscriptionProcedure,
|
|
20
|
+
MutationProcedure,
|
|
21
|
+
ProcedureType,
|
|
22
|
+
QueryProcedure,
|
|
23
|
+
SubscriptionProcedure,
|
|
24
|
+
} from './procedure';
|
|
25
|
+
import type { GetRawInputFn, MaybePromise, Overwrite, Simplify } from './types';
|
|
26
|
+
import { mergeWithoutOverrides } from './utils';
|
|
27
|
+
|
|
28
|
+
type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker
|
|
29
|
+
? TWith
|
|
30
|
+
: Simplify<TType & TWith>;
|
|
31
|
+
|
|
32
|
+
type ErrorMessage<TMessage extends string> = TMessage;
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
export const unsetMarker = Symbol('unsetMarker');
|
|
36
|
+
type UnsetMarker = typeof unsetMarker;
|
|
37
|
+
type DefaultValue<TValue, TFallback> = TValue extends UnsetMarker
|
|
38
|
+
? TFallback
|
|
39
|
+
: TValue;
|
|
40
|
+
|
|
41
|
+
type ProcedureBuilderDef<TMeta> = {
|
|
42
|
+
procedure: true;
|
|
43
|
+
inputs: Parser[];
|
|
44
|
+
output?: Parser;
|
|
45
|
+
meta?: TMeta;
|
|
46
|
+
resolver?: ProcedureBuilderResolver;
|
|
47
|
+
middlewares: AnyMiddlewareFunction[];
|
|
48
|
+
mutation?: boolean;
|
|
49
|
+
query?: boolean;
|
|
50
|
+
subscription?: boolean;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type AnyProcedureBuilderDef = ProcedureBuilderDef<any>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Procedure resolver options
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
interface ResolverOptions<TContext, _TMeta, TContextOverridesIn, TInputOut> {
|
|
60
|
+
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
|
|
61
|
+
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A procedure resolver
|
|
66
|
+
*/
|
|
67
|
+
type ProcedureResolver<
|
|
68
|
+
TContext,
|
|
69
|
+
_TMeta,
|
|
70
|
+
TContextOverrides,
|
|
71
|
+
TInputOut,
|
|
72
|
+
TOutputIn,
|
|
73
|
+
TOutputOut,
|
|
74
|
+
> = (opts: {
|
|
75
|
+
ctx: Simplify<Overwrite<TContext, TContextOverrides>>;
|
|
76
|
+
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
|
|
77
|
+
}) => MaybePromise<DefaultValue<TOutputIn, TOutputOut>>;
|
|
78
|
+
|
|
79
|
+
type AnyResolver = ProcedureResolver<any, any, any, any, any, any>;
|
|
80
|
+
export interface ProcedureBuilder<
|
|
81
|
+
TContext,
|
|
82
|
+
TMeta,
|
|
83
|
+
TContextOverrides,
|
|
84
|
+
TInputIn,
|
|
85
|
+
TInputOut,
|
|
86
|
+
TOutputIn,
|
|
87
|
+
TOutputOut,
|
|
88
|
+
> {
|
|
89
|
+
/**
|
|
90
|
+
* Add an input parser to the procedure.
|
|
91
|
+
* @link https://trpc.io/docs/v11/server/validators
|
|
92
|
+
*/
|
|
93
|
+
input<$Parser extends Parser>(
|
|
94
|
+
schema: TInputOut extends UnsetMarker
|
|
95
|
+
? $Parser
|
|
96
|
+
: inferParser<$Parser>['out'] extends Record<string, unknown> | undefined
|
|
97
|
+
? TInputOut extends Record<string, unknown> | undefined
|
|
98
|
+
? undefined extends inferParser<$Parser>['out'] // if current is optional the previous must be too
|
|
99
|
+
? undefined extends TInputOut
|
|
100
|
+
? $Parser
|
|
101
|
+
: ErrorMessage<'Cannot chain an optional parser to a required parser'>
|
|
102
|
+
: $Parser
|
|
103
|
+
: ErrorMessage<'All input parsers did not resolve to an object'>
|
|
104
|
+
: ErrorMessage<'All input parsers did not resolve to an object'>,
|
|
105
|
+
): ProcedureBuilder<
|
|
106
|
+
TContext,
|
|
107
|
+
TMeta,
|
|
108
|
+
TContextOverrides,
|
|
109
|
+
IntersectIfDefined<TInputIn, inferParser<$Parser>['in']>,
|
|
110
|
+
IntersectIfDefined<TInputOut, inferParser<$Parser>['out']>,
|
|
111
|
+
TOutputIn,
|
|
112
|
+
TOutputOut
|
|
113
|
+
>;
|
|
114
|
+
/**
|
|
115
|
+
* Add an output parser to the procedure.
|
|
116
|
+
* @link https://trpc.io/docs/v11/server/validators
|
|
117
|
+
*/
|
|
118
|
+
output<$Parser extends Parser>(
|
|
119
|
+
schema: $Parser,
|
|
120
|
+
): ProcedureBuilder<
|
|
121
|
+
TContext,
|
|
122
|
+
TMeta,
|
|
123
|
+
TContextOverrides,
|
|
124
|
+
TInputIn,
|
|
125
|
+
TInputOut,
|
|
126
|
+
IntersectIfDefined<TOutputIn, inferParser<$Parser>['in']>,
|
|
127
|
+
IntersectIfDefined<TOutputOut, inferParser<$Parser>['out']>
|
|
128
|
+
>;
|
|
129
|
+
/**
|
|
130
|
+
* Add a meta data to the procedure.
|
|
131
|
+
* @link https://trpc.io/docs/v11/server/metadata
|
|
132
|
+
*/
|
|
133
|
+
meta(
|
|
134
|
+
meta: TMeta,
|
|
135
|
+
): ProcedureBuilder<
|
|
136
|
+
TContext,
|
|
137
|
+
TMeta,
|
|
138
|
+
TContextOverrides,
|
|
139
|
+
TInputIn,
|
|
140
|
+
TInputOut,
|
|
141
|
+
TOutputIn,
|
|
142
|
+
TOutputOut
|
|
143
|
+
>;
|
|
144
|
+
/**
|
|
145
|
+
* Add a middleware to the procedure.
|
|
146
|
+
* @link https://trpc.io/docs/v11/server/middlewares
|
|
147
|
+
*/
|
|
148
|
+
use<$ContextOverridesOut>(
|
|
149
|
+
fn:
|
|
150
|
+
| MiddlewareBuilder<
|
|
151
|
+
Overwrite<TContext, TContextOverrides>,
|
|
152
|
+
TMeta,
|
|
153
|
+
$ContextOverridesOut,
|
|
154
|
+
TInputIn
|
|
155
|
+
>
|
|
156
|
+
| MiddlewareFunction<
|
|
157
|
+
TContext,
|
|
158
|
+
TMeta,
|
|
159
|
+
TContextOverrides,
|
|
160
|
+
$ContextOverridesOut,
|
|
161
|
+
TInputIn
|
|
162
|
+
>,
|
|
163
|
+
): ProcedureBuilder<
|
|
164
|
+
TContext,
|
|
165
|
+
TMeta,
|
|
166
|
+
Overwrite<TContextOverrides, $ContextOverridesOut>,
|
|
167
|
+
TInputIn,
|
|
168
|
+
TInputOut,
|
|
169
|
+
TOutputIn,
|
|
170
|
+
TOutputOut
|
|
171
|
+
>;
|
|
172
|
+
/**
|
|
173
|
+
* Query procedure
|
|
174
|
+
* @link https://trpc.io/docs/v11/concepts#vocabulary
|
|
175
|
+
*/
|
|
176
|
+
query<$Output>(
|
|
177
|
+
resolver: ProcedureResolver<
|
|
178
|
+
TContext,
|
|
179
|
+
TMeta,
|
|
180
|
+
TContextOverrides,
|
|
181
|
+
TInputOut,
|
|
182
|
+
TOutputIn,
|
|
183
|
+
$Output
|
|
184
|
+
>,
|
|
185
|
+
): QueryProcedure<{
|
|
186
|
+
input: DefaultValue<TInputIn, void>;
|
|
187
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
188
|
+
}>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Mutation procedure
|
|
192
|
+
* @link https://trpc.io/docs/v11/concepts#vocabulary
|
|
193
|
+
*/
|
|
194
|
+
mutation<$Output>(
|
|
195
|
+
resolver: ProcedureResolver<
|
|
196
|
+
TContext,
|
|
197
|
+
TMeta,
|
|
198
|
+
TContextOverrides,
|
|
199
|
+
TInputOut,
|
|
200
|
+
TOutputIn,
|
|
201
|
+
$Output
|
|
202
|
+
>,
|
|
203
|
+
): MutationProcedure<{
|
|
204
|
+
input: DefaultValue<TInputIn, void>;
|
|
205
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
206
|
+
}>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Subscription procedure
|
|
210
|
+
* @link https://trpc.io/docs/v11/concepts#vocabulary
|
|
211
|
+
*/
|
|
212
|
+
subscription<$Output>(
|
|
213
|
+
resolver: ProcedureResolver<
|
|
214
|
+
TContext,
|
|
215
|
+
TMeta,
|
|
216
|
+
TContextOverrides,
|
|
217
|
+
TInputOut,
|
|
218
|
+
TOutputIn,
|
|
219
|
+
$Output
|
|
220
|
+
>,
|
|
221
|
+
): SubscriptionProcedure<{
|
|
222
|
+
input: DefaultValue<TInputIn, void>;
|
|
223
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
224
|
+
}>;
|
|
225
|
+
/**
|
|
226
|
+
* @internal
|
|
227
|
+
*/
|
|
228
|
+
_def: ProcedureBuilderDef<TMeta>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
type AnyProcedureBuilder = ProcedureBuilder<any, any, any, any, any, any, any>;
|
|
232
|
+
type ProcedureBuilderResolver = (
|
|
233
|
+
opts: ResolverOptions<any, any, any, any>,
|
|
234
|
+
) => Promise<unknown>;
|
|
235
|
+
|
|
236
|
+
function createNewBuilder(
|
|
237
|
+
def1: AnyProcedureBuilderDef,
|
|
238
|
+
def2: Partial<AnyProcedureBuilderDef>,
|
|
239
|
+
): AnyProcedureBuilder {
|
|
240
|
+
const { middlewares = [], inputs, meta, ...rest } = def2;
|
|
241
|
+
|
|
242
|
+
// TODO: maybe have a fn here to warn about calls
|
|
243
|
+
return createBuilder({
|
|
244
|
+
...mergeWithoutOverrides(def1, rest),
|
|
245
|
+
inputs: [...def1.inputs, ...(inputs ?? [])],
|
|
246
|
+
middlewares: [...def1.middlewares, ...middlewares],
|
|
247
|
+
meta: def1.meta && meta ? { ...def1.meta, ...meta } : meta ?? def1.meta,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function createBuilder<TContext, TMeta>(
|
|
252
|
+
initDef: Partial<AnyProcedureBuilderDef> = {},
|
|
253
|
+
): ProcedureBuilder<
|
|
254
|
+
TContext,
|
|
255
|
+
TMeta,
|
|
256
|
+
object,
|
|
257
|
+
UnsetMarker,
|
|
258
|
+
UnsetMarker,
|
|
259
|
+
UnsetMarker,
|
|
260
|
+
UnsetMarker
|
|
261
|
+
> {
|
|
262
|
+
const _def: AnyProcedureBuilderDef = {
|
|
263
|
+
procedure: true,
|
|
264
|
+
inputs: [],
|
|
265
|
+
middlewares: [],
|
|
266
|
+
...initDef,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
type AnyProcedureBuilder = ProcedureBuilder<
|
|
270
|
+
any,
|
|
271
|
+
any,
|
|
272
|
+
any,
|
|
273
|
+
any,
|
|
274
|
+
any,
|
|
275
|
+
any,
|
|
276
|
+
any
|
|
277
|
+
>;
|
|
278
|
+
|
|
279
|
+
const builder: AnyProcedureBuilder = {
|
|
280
|
+
_def,
|
|
281
|
+
input(input) {
|
|
282
|
+
const parser = getParseFn(input as Parser);
|
|
283
|
+
return createNewBuilder(_def, {
|
|
284
|
+
inputs: [input as Parser],
|
|
285
|
+
middlewares: [createInputMiddleware(parser)],
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
output(output: Parser) {
|
|
289
|
+
const parser = getParseFn(output);
|
|
290
|
+
return createNewBuilder(_def, {
|
|
291
|
+
output,
|
|
292
|
+
middlewares: [createOutputMiddleware(parser)],
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
meta(meta) {
|
|
296
|
+
return createNewBuilder(_def, {
|
|
297
|
+
meta,
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
use(middlewareBuilderOrFn) {
|
|
301
|
+
// Distinguish between a middleware builder and a middleware function
|
|
302
|
+
const middlewares =
|
|
303
|
+
'_middlewares' in middlewareBuilderOrFn
|
|
304
|
+
? middlewareBuilderOrFn._middlewares
|
|
305
|
+
: [middlewareBuilderOrFn];
|
|
306
|
+
|
|
307
|
+
return createNewBuilder(_def, {
|
|
308
|
+
middlewares: middlewares,
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
query(resolver) {
|
|
312
|
+
return createResolver(
|
|
313
|
+
{ ..._def, type: 'query' },
|
|
314
|
+
resolver,
|
|
315
|
+
) as AnyQueryProcedure;
|
|
316
|
+
},
|
|
317
|
+
mutation(resolver) {
|
|
318
|
+
return createResolver(
|
|
319
|
+
{ ..._def, type: 'mutation' },
|
|
320
|
+
resolver,
|
|
321
|
+
) as AnyMutationProcedure;
|
|
322
|
+
},
|
|
323
|
+
subscription(resolver) {
|
|
324
|
+
return createResolver(
|
|
325
|
+
{ ..._def, type: 'subscription' },
|
|
326
|
+
resolver,
|
|
327
|
+
) as AnySubscriptionProcedure;
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
return builder;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function createResolver(
|
|
335
|
+
_def: AnyProcedureBuilderDef & { type: ProcedureType },
|
|
336
|
+
resolver: AnyResolver,
|
|
337
|
+
) {
|
|
338
|
+
const finalBuilder = createNewBuilder(_def, {
|
|
339
|
+
resolver,
|
|
340
|
+
middlewares: [
|
|
341
|
+
async function resolveMiddleware(opts) {
|
|
342
|
+
const data = await resolver(opts);
|
|
343
|
+
return {
|
|
344
|
+
marker: middlewareMarker,
|
|
345
|
+
ok: true,
|
|
346
|
+
data,
|
|
347
|
+
ctx: opts.ctx,
|
|
348
|
+
} as const;
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
return createProcedureCaller(finalBuilder._def);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
export interface ProcedureCallOptions {
|
|
360
|
+
ctx: unknown;
|
|
361
|
+
getRawInput: GetRawInputFn;
|
|
362
|
+
input?: unknown;
|
|
363
|
+
path: string;
|
|
364
|
+
type: ProcedureType;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const codeblock = `
|
|
368
|
+
This is a client-only function.
|
|
369
|
+
If you want to call this function on the server, see https://trpc.io/docs/v11/server/server-side-calls
|
|
370
|
+
`.trim();
|
|
371
|
+
|
|
372
|
+
function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
373
|
+
async function procedure(opts: ProcedureCallOptions) {
|
|
374
|
+
// is direct server-side call
|
|
375
|
+
if (!opts || !('getRawInput' in opts)) {
|
|
376
|
+
throw new Error(codeblock);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// run the middlewares recursively with the resolver as the last one
|
|
380
|
+
async function callRecursive(
|
|
381
|
+
callOpts: {
|
|
382
|
+
ctx: any;
|
|
383
|
+
index: number;
|
|
384
|
+
input?: unknown;
|
|
385
|
+
getRawInput?: GetRawInputFn;
|
|
386
|
+
} = {
|
|
387
|
+
index: 0,
|
|
388
|
+
ctx: opts.ctx,
|
|
389
|
+
},
|
|
390
|
+
): Promise<MiddlewareResult<any>> {
|
|
391
|
+
try {
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
393
|
+
const middleware = _def.middlewares[callOpts.index]!;
|
|
394
|
+
const result = await middleware({
|
|
395
|
+
ctx: callOpts.ctx,
|
|
396
|
+
type: opts.type,
|
|
397
|
+
path: opts.path,
|
|
398
|
+
getRawInput: callOpts.getRawInput ?? opts.getRawInput,
|
|
399
|
+
meta: _def.meta,
|
|
400
|
+
input: callOpts.input,
|
|
401
|
+
next(_nextOpts?: any) {
|
|
402
|
+
const nextOpts = _nextOpts as
|
|
403
|
+
| {
|
|
404
|
+
ctx?: Record<string, unknown>;
|
|
405
|
+
input?: unknown;
|
|
406
|
+
getRawInput?: GetRawInputFn;
|
|
407
|
+
}
|
|
408
|
+
| undefined;
|
|
409
|
+
|
|
410
|
+
return callRecursive({
|
|
411
|
+
index: callOpts.index + 1,
|
|
412
|
+
ctx:
|
|
413
|
+
nextOpts && 'ctx' in nextOpts
|
|
414
|
+
? { ...callOpts.ctx, ...nextOpts.ctx }
|
|
415
|
+
: callOpts.ctx,
|
|
416
|
+
input:
|
|
417
|
+
nextOpts && 'input' in nextOpts
|
|
418
|
+
? nextOpts.input
|
|
419
|
+
: callOpts.input,
|
|
420
|
+
getRawInput:
|
|
421
|
+
nextOpts && 'getRawInput' in nextOpts
|
|
422
|
+
? nextOpts.getRawInput
|
|
423
|
+
: callOpts.getRawInput,
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
return result;
|
|
428
|
+
} catch (cause) {
|
|
429
|
+
return {
|
|
430
|
+
ok: false,
|
|
431
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
432
|
+
marker: middlewareMarker,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// there's always at least one "next" since we wrap this.resolver in a middleware
|
|
438
|
+
const result = await callRecursive();
|
|
439
|
+
|
|
440
|
+
if (!result) {
|
|
441
|
+
throw new TRPCError({
|
|
442
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
443
|
+
message:
|
|
444
|
+
'No result from middlewares - did you forget to `return next()`?',
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (!result.ok) {
|
|
448
|
+
// re-throw original error
|
|
449
|
+
throw result.error;
|
|
450
|
+
}
|
|
451
|
+
return result.data;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
procedure._def = _def;
|
|
455
|
+
|
|
456
|
+
// FIXME typecast shouldn't be needed - fixittt
|
|
457
|
+
return procedure as unknown as AnyProcedure;
|
|
458
|
+
}
|