@trpc/server 11.0.0-next-alpha.133 → 11.0.0-next-alpha.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aws-lambda/index.js +2 -2
- package/dist/adapters/aws-lambda/index.mjs +2 -2
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +3 -3
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/fastify/index.mjs +2 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/next.js +3 -3
- package/dist/adapters/next.mjs +3 -3
- package/dist/adapters/node-http/index.js +3 -3
- package/dist/adapters/node-http/index.mjs +3 -3
- package/dist/adapters/standalone.js +3 -3
- package/dist/adapters/standalone.mjs +3 -3
- package/dist/adapters/ws.js +1 -1
- package/dist/adapters/ws.mjs +1 -1
- package/dist/bundle-analysis.json +73 -72
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/initTRPC.d.ts +16 -41
- package/dist/core/initTRPC.d.ts.map +1 -1
- package/dist/core/internals/procedureBuilder.d.ts +46 -60
- package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
- package/dist/core/internals/utils.d.ts +1 -9
- package/dist/core/internals/utils.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +33 -85
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/router.d.ts +6 -1
- package/dist/core/router.d.ts.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.mjs +2 -2
- package/dist/index.js +12 -3
- package/dist/index.mjs +13 -5
- package/dist/{nodeHTTPRequestHandler-84248270.js → nodeHTTPRequestHandler-3f218e71.js} +1 -1
- package/dist/{nodeHTTPRequestHandler-fb26ba4e.mjs → nodeHTTPRequestHandler-c92e159b.mjs} +1 -1
- package/dist/{nodeHTTPRequestHandler-e24d9576.js → nodeHTTPRequestHandler-f04ea0b8.js} +1 -1
- package/dist/{procedureBuilder-c990500b.js → procedureBuilder-51db231f.js} +13 -21
- package/dist/{procedureBuilder-88b211d2.mjs → procedureBuilder-955ce9bc.mjs} +12 -17
- package/dist/{procedureBuilder-0ee77d9c.js → procedureBuilder-f3a66e27.js} +12 -17
- package/dist/{resolveHTTPResponse-c5c776d4.js → resolveHTTPResponse-62594a39.js} +1 -1
- package/dist/{resolveHTTPResponse-cbea0b76.js → resolveHTTPResponse-e5110d33.js} +1 -1
- package/dist/{resolveHTTPResponse-6ce6731d.mjs → resolveHTTPResponse-fda30ede.mjs} +1 -1
- package/dist/{router-6e6a40b3.js → router-05a567ea.js} +19 -0
- package/dist/{router-2e54d451.js → router-40fcf5e5.js} +19 -1
- package/dist/{router-accbd60f.mjs → router-8564439c.mjs} +19 -1
- package/dist/shared/internal/serialize.d.ts +38 -8
- package/dist/shared/internal/serialize.d.ts.map +1 -1
- package/dist/unstableInternalsExport.js +2 -2
- package/dist/unstableInternalsExport.mjs +2 -2
- package/package.json +2 -2
- package/src/core/index.ts +3 -2
- package/src/core/initTRPC.ts +18 -3
- package/src/core/internals/procedureBuilder.ts +174 -111
- package/src/core/internals/utils.ts +1 -14
- package/src/core/middleware.ts +114 -163
- package/src/core/router.ts +30 -1
- package/src/shared/internal/serialize.ts +58 -23
- package/dist/core/internals/builderTypes.d.ts +0 -14
- package/dist/core/internals/builderTypes.d.ts.map +0 -1
- package/src/core/internals/builderTypes.ts +0 -14
package/src/core/index.ts
CHANGED
|
@@ -4,8 +4,10 @@ export type {
|
|
|
4
4
|
ProcedureRouterRecord,
|
|
5
5
|
CreateRouterInner,
|
|
6
6
|
Router,
|
|
7
|
+
RouterCaller,
|
|
8
|
+
AnyRouterDef,
|
|
7
9
|
} from './router';
|
|
8
|
-
export { callProcedure } from './router';
|
|
10
|
+
export { callProcedure, createCallerFactory } from './router';
|
|
9
11
|
export type {
|
|
10
12
|
Procedure,
|
|
11
13
|
AnyProcedure,
|
|
@@ -15,7 +17,6 @@ export type {
|
|
|
15
17
|
ProcedureArgs,
|
|
16
18
|
ProcedureOptions,
|
|
17
19
|
} from './procedure';
|
|
18
|
-
export type { AnyProcedureBuilderParams } from './internals/builderTypes';
|
|
19
20
|
export type { inferParser } from './parser';
|
|
20
21
|
export {
|
|
21
22
|
createInputMiddleware,
|
package/src/core/initTRPC.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { mergeRouters } from './internals/mergeRouters';
|
|
|
23
23
|
import { createBuilder } from './internals/procedureBuilder';
|
|
24
24
|
import { Overwrite, PickFirstDefined, ValidateShape } from './internals/utils';
|
|
25
25
|
import { createMiddlewareFactory } from './middleware';
|
|
26
|
-
import { createRouterFactory } from './router';
|
|
26
|
+
import { createCallerFactory, createRouterFactory } from './router';
|
|
27
27
|
|
|
28
28
|
type PartialRootConfigTypes = Partial<RootConfigTypes>;
|
|
29
29
|
|
|
@@ -150,22 +150,37 @@ function createTRPCInner<TParams extends PartialRootConfigTypes>() {
|
|
|
150
150
|
_config: config,
|
|
151
151
|
/**
|
|
152
152
|
* Builder object for creating procedures
|
|
153
|
+
* @see https://trpc.io/docs/server/procedures
|
|
153
154
|
*/
|
|
154
|
-
procedure: createBuilder
|
|
155
|
+
procedure: createBuilder<
|
|
156
|
+
$Config['$types']['ctx'],
|
|
157
|
+
$Config['$types']['meta']
|
|
158
|
+
>({
|
|
155
159
|
meta: runtime?.defaultMeta,
|
|
156
160
|
}),
|
|
157
161
|
/**
|
|
158
162
|
* Create reusable middlewares
|
|
163
|
+
* @see https://trpc.io/docs/server/middlewares
|
|
159
164
|
*/
|
|
160
|
-
middleware: createMiddlewareFactory
|
|
165
|
+
middleware: createMiddlewareFactory<
|
|
166
|
+
$Config['$types']['ctx'],
|
|
167
|
+
$Config['$types']['meta']
|
|
168
|
+
>(),
|
|
161
169
|
/**
|
|
162
170
|
* Create a router
|
|
171
|
+
* @see https://trpc.io/docs/server/routers
|
|
163
172
|
*/
|
|
164
173
|
router: createRouterFactory<$Config>(config),
|
|
165
174
|
/**
|
|
166
175
|
* Merge Routers
|
|
176
|
+
* @see https://trpc.io/docs/server/merging-routers
|
|
167
177
|
*/
|
|
168
178
|
mergeRouters,
|
|
179
|
+
/**
|
|
180
|
+
* Create a server-side caller for a router
|
|
181
|
+
* @see https://trpc.io/docs/server/server-side-calls
|
|
182
|
+
*/
|
|
183
|
+
createCallerFactory: createCallerFactory<$Config>(),
|
|
169
184
|
};
|
|
170
185
|
};
|
|
171
186
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getTRPCErrorFromUnknown, TRPCError } from '../../error/TRPCError';
|
|
2
2
|
import { MaybePromise, Simplify } from '../../types';
|
|
3
3
|
import {
|
|
4
|
+
AnyMiddlewareFunction,
|
|
4
5
|
createInputMiddleware,
|
|
5
6
|
createOutputMiddleware,
|
|
6
7
|
MiddlewareBuilder,
|
|
@@ -18,8 +19,6 @@ import {
|
|
|
18
19
|
SubscriptionProcedure,
|
|
19
20
|
} from '../procedure';
|
|
20
21
|
import { ProcedureType } from '../types';
|
|
21
|
-
import { AnyProcedureBuilderParams } from './builderTypes';
|
|
22
|
-
import { AnyRootConfig } from './config';
|
|
23
22
|
import { getParseFn } from './getParseFn';
|
|
24
23
|
import { mergeWithoutOverrides } from './mergeWithoutOverrides';
|
|
25
24
|
import {
|
|
@@ -27,38 +26,22 @@ import {
|
|
|
27
26
|
GetRawInputFn,
|
|
28
27
|
middlewareMarker,
|
|
29
28
|
Overwrite,
|
|
30
|
-
ResolveOptions,
|
|
31
29
|
UnsetMarker,
|
|
32
30
|
} from './utils';
|
|
33
31
|
|
|
34
|
-
type
|
|
35
|
-
TPrev extends AnyProcedureBuilderParams,
|
|
36
|
-
TNext extends AnyProcedureBuilderParams,
|
|
37
|
-
> = ProcedureBuilder<{
|
|
38
|
-
_config: TPrev['_config'];
|
|
39
|
-
_meta: TPrev['_meta'];
|
|
40
|
-
_ctx_out: Overwrite<TPrev['_ctx_out'], TNext['_ctx_out']>;
|
|
41
|
-
_input_in: TPrev['_input_in'];
|
|
42
|
-
_input_out: UnsetMarker extends TNext['_input_out']
|
|
43
|
-
? TPrev['_input_out']
|
|
44
|
-
: Overwrite<TPrev['_input_out'], TNext['_input_out']>;
|
|
45
|
-
_output_in: DefaultValue<TNext['_output_in'], TPrev['_output_in']>;
|
|
46
|
-
_output_out: DefaultValue<TNext['_output_out'], TPrev['_output_out']>;
|
|
47
|
-
}>;
|
|
48
|
-
|
|
49
|
-
type OverwriteIfDefined<TType, TWith> = UnsetMarker extends TType
|
|
32
|
+
type IntersectIfDefined<TType, TWith> = UnsetMarker extends TType
|
|
50
33
|
? TWith
|
|
51
34
|
: Simplify<TType & TWith>;
|
|
52
35
|
|
|
53
36
|
type ErrorMessage<TMessage extends string> = TMessage;
|
|
54
37
|
|
|
55
|
-
export type ProcedureBuilderDef<
|
|
38
|
+
export type ProcedureBuilderDef<TMeta> = {
|
|
56
39
|
procedure: true;
|
|
57
40
|
inputs: Parser[];
|
|
58
41
|
output?: Parser;
|
|
59
|
-
meta?:
|
|
42
|
+
meta?: TMeta;
|
|
60
43
|
resolver?: ProcedureBuilderResolver;
|
|
61
|
-
middlewares:
|
|
44
|
+
middlewares: AnyMiddlewareFunction[];
|
|
62
45
|
mutation?: boolean;
|
|
63
46
|
query?: boolean;
|
|
64
47
|
subscription?: boolean;
|
|
@@ -66,117 +49,191 @@ export type ProcedureBuilderDef<TParams extends AnyProcedureBuilderParams> = {
|
|
|
66
49
|
|
|
67
50
|
export type AnyProcedureBuilderDef = ProcedureBuilderDef<any>;
|
|
68
51
|
|
|
69
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Procedure resolver options
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
interface ResolverOptions<TContext, _TMeta, TContextOverridesIn, TInputOut> {
|
|
57
|
+
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
|
|
58
|
+
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A procedure resolver
|
|
63
|
+
*/
|
|
64
|
+
type ProcedureResolver<
|
|
65
|
+
TContext,
|
|
66
|
+
_TMeta,
|
|
67
|
+
TContextOverrides,
|
|
68
|
+
TInputOut,
|
|
69
|
+
TOutputIn,
|
|
70
|
+
TOutputOut,
|
|
71
|
+
> = (opts: {
|
|
72
|
+
ctx: Simplify<Overwrite<TContext, TContextOverrides>>;
|
|
73
|
+
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
|
|
74
|
+
}) => MaybePromise<DefaultValue<TOutputIn, TOutputOut>>;
|
|
75
|
+
|
|
76
|
+
type AnyResolver = ProcedureResolver<any, any, any, any, any, any>;
|
|
77
|
+
export interface ProcedureBuilder<
|
|
78
|
+
TContext,
|
|
79
|
+
TMeta,
|
|
80
|
+
TContextOverrides,
|
|
81
|
+
TInputIn,
|
|
82
|
+
TInputOut,
|
|
83
|
+
TOutputIn,
|
|
84
|
+
TOutputOut,
|
|
85
|
+
> {
|
|
70
86
|
/**
|
|
71
87
|
* Add an input parser to the procedure.
|
|
88
|
+
* @see https://trpc.io/docs/server/validators
|
|
72
89
|
*/
|
|
73
90
|
input<$Parser extends Parser>(
|
|
74
|
-
schema:
|
|
91
|
+
schema: TInputOut extends UnsetMarker
|
|
75
92
|
? $Parser
|
|
76
93
|
: inferParser<$Parser>['out'] extends Record<string, unknown> | undefined
|
|
77
|
-
?
|
|
94
|
+
? TInputOut extends Record<string, unknown> | undefined
|
|
78
95
|
? undefined extends inferParser<$Parser>['out'] // if current is optional the previous must be too
|
|
79
|
-
? undefined extends
|
|
96
|
+
? undefined extends TInputOut
|
|
80
97
|
? $Parser
|
|
81
98
|
: ErrorMessage<'Cannot chain an optional parser to a required parser'>
|
|
82
99
|
: $Parser
|
|
83
100
|
: ErrorMessage<'All input parsers did not resolve to an object'>
|
|
84
101
|
: ErrorMessage<'All input parsers did not resolve to an object'>,
|
|
85
|
-
): ProcedureBuilder<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
TParams['_input_out'],
|
|
95
|
-
inferParser<$Parser>['out']
|
|
96
|
-
>;
|
|
97
|
-
|
|
98
|
-
_output_in: TParams['_output_in'];
|
|
99
|
-
_output_out: TParams['_output_out'];
|
|
100
|
-
}>;
|
|
102
|
+
): ProcedureBuilder<
|
|
103
|
+
TContext,
|
|
104
|
+
TMeta,
|
|
105
|
+
TContextOverrides,
|
|
106
|
+
IntersectIfDefined<TInputIn, inferParser<$Parser>['in']>,
|
|
107
|
+
IntersectIfDefined<TInputOut, inferParser<$Parser>['out']>,
|
|
108
|
+
TOutputIn,
|
|
109
|
+
TOutputOut
|
|
110
|
+
>;
|
|
101
111
|
/**
|
|
102
112
|
* Add an output parser to the procedure.
|
|
113
|
+
* @see https://trpc.io/docs/server/validators
|
|
103
114
|
*/
|
|
104
115
|
output<$Parser extends Parser>(
|
|
105
116
|
schema: $Parser,
|
|
106
|
-
): ProcedureBuilder<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
): ProcedureBuilder<
|
|
118
|
+
TContext,
|
|
119
|
+
TMeta,
|
|
120
|
+
TContextOverrides,
|
|
121
|
+
TInputIn,
|
|
122
|
+
TInputOut,
|
|
123
|
+
IntersectIfDefined<TOutputIn, inferParser<$Parser>['in']>,
|
|
124
|
+
IntersectIfDefined<TOutputOut, inferParser<$Parser>['out']>
|
|
125
|
+
>;
|
|
115
126
|
/**
|
|
116
127
|
* Add a meta data to the procedure.
|
|
128
|
+
* @see https://trpc.io/docs/server/metadata
|
|
117
129
|
*/
|
|
118
|
-
meta(
|
|
130
|
+
meta(
|
|
131
|
+
meta: TMeta,
|
|
132
|
+
): ProcedureBuilder<
|
|
133
|
+
TContext,
|
|
134
|
+
TMeta,
|
|
135
|
+
TContextOverrides,
|
|
136
|
+
TInputIn,
|
|
137
|
+
TInputOut,
|
|
138
|
+
TOutputIn,
|
|
139
|
+
TOutputOut
|
|
140
|
+
>;
|
|
119
141
|
/**
|
|
120
142
|
* Add a middleware to the procedure.
|
|
143
|
+
* @see https://trpc.io/docs/server/middlewares
|
|
121
144
|
*/
|
|
122
|
-
use<$
|
|
145
|
+
use<$ContextOverridesOut>(
|
|
123
146
|
fn:
|
|
124
|
-
| MiddlewareBuilder<
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
| MiddlewareBuilder<
|
|
148
|
+
Overwrite<TContext, TContextOverrides>,
|
|
149
|
+
TMeta,
|
|
150
|
+
$ContextOverridesOut,
|
|
151
|
+
TInputIn
|
|
152
|
+
>
|
|
153
|
+
| MiddlewareFunction<
|
|
154
|
+
TContext,
|
|
155
|
+
TMeta,
|
|
156
|
+
TContextOverrides,
|
|
157
|
+
$ContextOverridesOut,
|
|
158
|
+
TInputIn
|
|
159
|
+
>,
|
|
160
|
+
): ProcedureBuilder<
|
|
161
|
+
TContext,
|
|
162
|
+
TMeta,
|
|
163
|
+
Overwrite<TContextOverrides, $ContextOverridesOut>,
|
|
164
|
+
TInputIn,
|
|
165
|
+
TInputOut,
|
|
166
|
+
TOutputIn,
|
|
167
|
+
TOutputOut
|
|
168
|
+
>;
|
|
127
169
|
/**
|
|
128
170
|
* Query procedure
|
|
171
|
+
* @see https://trpc.io/docs/concepts#vocabulary
|
|
129
172
|
*/
|
|
130
173
|
query<$Output>(
|
|
131
|
-
resolver:
|
|
132
|
-
|
|
133
|
-
|
|
174
|
+
resolver: ProcedureResolver<
|
|
175
|
+
TContext,
|
|
176
|
+
TMeta,
|
|
177
|
+
TContextOverrides,
|
|
178
|
+
TInputOut,
|
|
179
|
+
TOutputIn,
|
|
180
|
+
$Output
|
|
181
|
+
>,
|
|
134
182
|
): QueryProcedure<{
|
|
135
|
-
input: DefaultValue<
|
|
136
|
-
output: DefaultValue<
|
|
183
|
+
input: DefaultValue<TInputIn, void>;
|
|
184
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
137
185
|
}>;
|
|
138
186
|
|
|
139
187
|
/**
|
|
140
188
|
* Mutation procedure
|
|
189
|
+
* @see https://trpc.io/docs/concepts#vocabulary
|
|
141
190
|
*/
|
|
142
191
|
mutation<$Output>(
|
|
143
|
-
resolver:
|
|
144
|
-
|
|
145
|
-
|
|
192
|
+
resolver: ProcedureResolver<
|
|
193
|
+
TContext,
|
|
194
|
+
TMeta,
|
|
195
|
+
TContextOverrides,
|
|
196
|
+
TInputOut,
|
|
197
|
+
TOutputIn,
|
|
198
|
+
$Output
|
|
199
|
+
>,
|
|
146
200
|
): MutationProcedure<{
|
|
147
|
-
input: DefaultValue<
|
|
148
|
-
output: DefaultValue<
|
|
201
|
+
input: DefaultValue<TInputIn, void>;
|
|
202
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
149
203
|
}>;
|
|
150
204
|
|
|
151
205
|
/**
|
|
152
|
-
*
|
|
206
|
+
* Subscription procedure
|
|
207
|
+
* @see https://trpc.io/docs/concepts#vocabulary
|
|
153
208
|
*/
|
|
154
209
|
subscription<$Output>(
|
|
155
|
-
resolver:
|
|
156
|
-
|
|
157
|
-
|
|
210
|
+
resolver: ProcedureResolver<
|
|
211
|
+
TContext,
|
|
212
|
+
TMeta,
|
|
213
|
+
TContextOverrides,
|
|
214
|
+
TInputOut,
|
|
215
|
+
TOutputIn,
|
|
216
|
+
$Output
|
|
217
|
+
>,
|
|
158
218
|
): SubscriptionProcedure<{
|
|
159
|
-
input: DefaultValue<
|
|
160
|
-
output: DefaultValue<
|
|
219
|
+
input: DefaultValue<TInputIn, void>;
|
|
220
|
+
output: DefaultValue<TOutputOut, $Output>;
|
|
161
221
|
}>;
|
|
162
222
|
/**
|
|
163
223
|
* @internal
|
|
164
224
|
*/
|
|
165
|
-
_def: ProcedureBuilderDef<
|
|
225
|
+
_def: ProcedureBuilderDef<TMeta>;
|
|
166
226
|
}
|
|
167
227
|
|
|
168
|
-
type AnyProcedureBuilder = ProcedureBuilder<any>;
|
|
169
|
-
|
|
170
|
-
export type ProcedureBuilderMiddleware = MiddlewareFunction<any, any>;
|
|
171
|
-
|
|
228
|
+
type AnyProcedureBuilder = ProcedureBuilder<any, any, any, any, any, any, any>;
|
|
172
229
|
export type ProcedureBuilderResolver = (
|
|
173
|
-
opts:
|
|
230
|
+
opts: ResolverOptions<any, any, any, any>,
|
|
174
231
|
) => Promise<unknown>;
|
|
175
232
|
|
|
176
233
|
function createNewBuilder(
|
|
177
234
|
def1: AnyProcedureBuilderDef,
|
|
178
235
|
def2: Partial<AnyProcedureBuilderDef>,
|
|
179
|
-
) {
|
|
236
|
+
): AnyProcedureBuilder {
|
|
180
237
|
const { middlewares = [], inputs, meta, ...rest } = def2;
|
|
181
238
|
|
|
182
239
|
// TODO: maybe have a fn here to warn about calls
|
|
@@ -188,17 +245,17 @@ function createNewBuilder(
|
|
|
188
245
|
});
|
|
189
246
|
}
|
|
190
247
|
|
|
191
|
-
export function createBuilder<
|
|
248
|
+
export function createBuilder<TContext, TMeta>(
|
|
192
249
|
initDef: Partial<AnyProcedureBuilderDef> = {},
|
|
193
|
-
): ProcedureBuilder<
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
250
|
+
): ProcedureBuilder<
|
|
251
|
+
TContext,
|
|
252
|
+
TMeta,
|
|
253
|
+
object,
|
|
254
|
+
UnsetMarker,
|
|
255
|
+
UnsetMarker,
|
|
256
|
+
UnsetMarker,
|
|
257
|
+
UnsetMarker
|
|
258
|
+
> {
|
|
202
259
|
const _def: AnyProcedureBuilderDef = {
|
|
203
260
|
procedure: true,
|
|
204
261
|
inputs: [],
|
|
@@ -206,26 +263,36 @@ export function createBuilder<TConfig extends AnyRootConfig>(
|
|
|
206
263
|
...initDef,
|
|
207
264
|
};
|
|
208
265
|
|
|
209
|
-
|
|
266
|
+
type AnyProcedureBuilder = ProcedureBuilder<
|
|
267
|
+
any,
|
|
268
|
+
any,
|
|
269
|
+
any,
|
|
270
|
+
any,
|
|
271
|
+
any,
|
|
272
|
+
any,
|
|
273
|
+
any
|
|
274
|
+
>;
|
|
275
|
+
|
|
276
|
+
const builder: AnyProcedureBuilder = {
|
|
210
277
|
_def,
|
|
211
278
|
input(input) {
|
|
212
|
-
const parser = getParseFn(input);
|
|
279
|
+
const parser = getParseFn(input as Parser);
|
|
213
280
|
return createNewBuilder(_def, {
|
|
214
|
-
inputs: [input],
|
|
281
|
+
inputs: [input as Parser],
|
|
215
282
|
middlewares: [createInputMiddleware(parser)],
|
|
216
|
-
})
|
|
283
|
+
});
|
|
217
284
|
},
|
|
218
285
|
output(output: Parser) {
|
|
219
|
-
const
|
|
286
|
+
const parser = getParseFn(output);
|
|
220
287
|
return createNewBuilder(_def, {
|
|
221
288
|
output,
|
|
222
|
-
middlewares: [createOutputMiddleware(
|
|
223
|
-
})
|
|
289
|
+
middlewares: [createOutputMiddleware(parser)],
|
|
290
|
+
});
|
|
224
291
|
},
|
|
225
292
|
meta(meta) {
|
|
226
293
|
return createNewBuilder(_def, {
|
|
227
|
-
meta
|
|
228
|
-
})
|
|
294
|
+
meta,
|
|
295
|
+
});
|
|
229
296
|
},
|
|
230
297
|
use(middlewareBuilderOrFn) {
|
|
231
298
|
// Distinguish between a middleware builder and a middleware function
|
|
@@ -235,8 +302,8 @@ export function createBuilder<TConfig extends AnyRootConfig>(
|
|
|
235
302
|
: [middlewareBuilderOrFn];
|
|
236
303
|
|
|
237
304
|
return createNewBuilder(_def, {
|
|
238
|
-
middlewares: middlewares
|
|
239
|
-
})
|
|
305
|
+
middlewares: middlewares,
|
|
306
|
+
});
|
|
240
307
|
},
|
|
241
308
|
query(resolver) {
|
|
242
309
|
return createResolver(
|
|
@@ -257,11 +324,13 @@ export function createBuilder<TConfig extends AnyRootConfig>(
|
|
|
257
324
|
) as AnySubscriptionProcedure;
|
|
258
325
|
},
|
|
259
326
|
};
|
|
327
|
+
|
|
328
|
+
return builder;
|
|
260
329
|
}
|
|
261
330
|
|
|
262
331
|
function createResolver(
|
|
263
332
|
_def: AnyProcedureBuilderDef & { type: ProcedureType },
|
|
264
|
-
resolver:
|
|
333
|
+
resolver: AnyResolver,
|
|
265
334
|
) {
|
|
266
335
|
const finalBuilder = createNewBuilder(_def, {
|
|
267
336
|
resolver,
|
|
@@ -293,14 +362,8 @@ export interface ProcedureCallOptions {
|
|
|
293
362
|
}
|
|
294
363
|
|
|
295
364
|
const codeblock = `
|
|
296
|
-
If you want to call this function on the server, you do the following:
|
|
297
365
|
This is a client-only function.
|
|
298
|
-
|
|
299
|
-
const caller = appRouter.createCaller({
|
|
300
|
-
/* ... your context */
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const result = await caller.call('myProcedure', input);
|
|
366
|
+
If you want to call this function on the server, see https://trpc.io/docs/server/server-side-calls
|
|
304
367
|
`.trim();
|
|
305
368
|
|
|
306
369
|
function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
@@ -311,7 +374,7 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
|
311
374
|
}
|
|
312
375
|
|
|
313
376
|
// run the middlewares recursively with the resolver as the last one
|
|
314
|
-
|
|
377
|
+
async function callRecursive(
|
|
315
378
|
callOpts: {
|
|
316
379
|
ctx: any;
|
|
317
380
|
index: number;
|
|
@@ -321,7 +384,7 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
|
321
384
|
index: 0,
|
|
322
385
|
ctx: opts.ctx,
|
|
323
386
|
},
|
|
324
|
-
): Promise<MiddlewareResult<any>>
|
|
387
|
+
): Promise<MiddlewareResult<any>> {
|
|
325
388
|
try {
|
|
326
389
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
327
390
|
const middleware = _def.middlewares[callOpts.index]!;
|
|
@@ -366,7 +429,7 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
|
|
|
366
429
|
marker: middlewareMarker,
|
|
367
430
|
};
|
|
368
431
|
}
|
|
369
|
-
}
|
|
432
|
+
}
|
|
370
433
|
|
|
371
434
|
// there's always at least one "next" since we wrap this.resolver in a middleware
|
|
372
435
|
const result = await callRecursive();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AnyProcedureBuilderParams } from './builderTypes';
|
|
1
|
+
import { WithoutIndexSignature } from '../../types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @internal
|
|
@@ -54,18 +53,6 @@ export const unsetMarker = Symbol('unsetMarker');
|
|
|
54
53
|
*/
|
|
55
54
|
export type UnsetMarker = typeof unsetMarker;
|
|
56
55
|
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
export interface ResolveOptions<TParams extends AnyProcedureBuilderParams> {
|
|
61
|
-
ctx: Simplify<
|
|
62
|
-
Overwrite<TParams['_config']['$types']['ctx'], TParams['_ctx_out']>
|
|
63
|
-
>;
|
|
64
|
-
input: TParams['_input_out'] extends UnsetMarker
|
|
65
|
-
? undefined
|
|
66
|
-
: TParams['_input_out'];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
56
|
/**
|
|
70
57
|
* @internal
|
|
71
58
|
*/
|